diff --git a/.appveyor.yml b/.appveyor.yml index 4507078614..1ce1965e63 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -66,7 +66,7 @@ init: install: # Update environment variables - ps: $env:R2_VERSION = ( python sys\\version.py ) - - ps: $env:DIST_FOLDER = "radare2-$env:builder-$env:R2_VERSION" + - ps: $env:DIST_FOLDER = "rizin-$env:builder-$env:R2_VERSION" - ps: $env:ARTIFACT_ZIP = "$env:DIST_FOLDER.zip" # Download required packages - cmd: if defined BUILD_DIR ( %PYTHON%\python.exe -m pip install meson ) @@ -74,7 +74,7 @@ install: # Build scripts build_script: - - appveyor AddMessage "Compiling radare2 %R2_VERSION% (%builder%)" + - appveyor AddMessage "Compiling rizin %R2_VERSION% (%builder%)" - cmd: if %builder% == vs2017_64 ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2017%" x64 && python sys\meson.py --backend vs2017 --release --xp --install --prefix="%DIST_FOLDER%" --webui --options static_runtime=true && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) @@ -94,27 +94,27 @@ for: test_script: - set PATH=%APPVEYOR_BUILD_FOLDER%\%DIST_FOLDER%\bin;C:\Python38-x64;C:\msys64\mingw64\bin;%PATH% - echo %PATH% - - where radare2 - - radare2 -v + - where rizin + - rizin -v - copy C:\Python38-x64\python.exe C:\Python38-x64\python3.exe - - python3 -m pip install "git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python" + - python3 -m pip install "git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python" - cd test - - git clone -q --depth 1 https://github.com/radareorg/radare2-testbins bins - - r2r -L db + - git clone -q --depth 1 https://github.com/rizinorg/rizin-testbins bins + - rz-test -L db - cd .. after_test: - - git clone --depth 1 https://github.com/radare/radare2-win-installer + - git clone --depth 1 https://github.com/radare/rizin-win-installer - set PATH=%PATH%;%INNO_SETUP% - - iscc radare2-win-installer/radare2.iss /DRadare2Location=..\%DIST_FOLDER%\* /DLicenseLocation=..\COPYING.LESSER /DIcoLocation=radare2.ico /DMyAppVersion=%R2_VERSION% - - move radare2-win-installer\Output\radare2.exe radare2_installer-%builder%.exe + - iscc rizin-win-installer/rizin.iss /DRadare2Location=..\%DIST_FOLDER%\* /DLicenseLocation=..\COPYING.LESSER /DIcoLocation=rizin.ico /DMyAppVersion=%R2_VERSION% + - move rizin-win-installer\Output\rizin.exe rizin_installer-%builder%.exe # Artifacts artifacts: # Binaries - path: "%ARTIFACT_ZIP%" # Inno Setup files - - path: radare2_installer-%builder%.exe + - path: rizin_installer-%builder%.exe # Upload builds to the CI release at GitHub deploy: diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml index dc4e59f712..7a2d18fce9 100644 --- a/.builds/freebsd.yml +++ b/.builds/freebsd.yml @@ -11,30 +11,30 @@ environment: CC: clang HOST_CC: clang sources: - - https://github.com/radareorg/radare2 - - https://github.com/radareorg/radare2-testbins + - https://github.com/rizinorg/rizin + - https://github.com/rizinorg/rizin-testbins tasks: - - r2pipe: | + - rzpipe: | sudo python3 -m ensurepip - sudo python3 -m pip install 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' + sudo python3 -m pip install 'git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python' - build: | - cd radare2 + cd rizin ./configure --prefix=${HOME} gmake - install: | - cd radare2 + cd rizin export PATH=${HOME}/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${PKG_CONFIG_PATH} gmake install - test: | - cd radare2 + cd rizin export PATH=${HOME}/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${PKG_CONFIG_PATH} # Workaround until the feature request is solved # https://todo.sr.ht/~sircmpwn/builds.sr.ht/274 - ln -s ${HOME}/radare2-testbins test/bins + ln -s ${HOME}/rizin-testbins test/bins # Running the test suite cd test && gmake -k all diff --git a/.builds/openbsd.yml b/.builds/openbsd.yml index 690664048e..bb3fc67b05 100644 --- a/.builds/openbsd.yml +++ b/.builds/openbsd.yml @@ -9,24 +9,24 @@ environment: CXX: clang++ CC: clang sources: - - https://github.com/radareorg/radare2 - - https://github.com/radareorg/radare2-testbins + - https://github.com/rizinorg/rizin + - https://github.com/rizinorg/rizin-testbins tasks: - - r2pipe: | + - rzpipe: | /usr/local/bin/python3 -m ensurepip --user - /usr/local/bin/python3 -m pip install --user 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' + /usr/local/bin/python3 -m pip install --user 'git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python' - build: | - cd radare2 + cd rizin ./configure --prefix=${HOME} gmake - install: | - cd radare2 + cd rizin export PATH=${HOME}/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${PKG_CONFIG_PATH} gmake install - test: | - cd radare2 + cd rizin export PATH=${HOME}/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${PKG_CONFIG_PATH} @@ -35,7 +35,7 @@ tasks: ln -s /usr/local/bin/python3 ${HOME}/bin/python3 # Workaround until the feature request is solved # https://todo.sr.ht/~sircmpwn/builds.sr.ht/274 - ln -s ${HOME}/radare2-testbins test/bins + ln -s ${HOME}/rizin-testbins test/bins # Running the test suite cd test && gmake -k all diff --git a/.gitattributes b/.gitattributes index 60a5d204ee..0d14fbdebb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ -shlr/radare2-shell-parser/src/grammar.json linguist-generated=true -shlr/radare2-shell-parser/src/node-types.json linguist-generated=true -shlr/radare2-shell-parser/src/parser.c linguist-generated=true +shlr/rizin-shell-parser/src/grammar.json linguist-generated=true +shlr/rizin-shell-parser/src/node-types.json linguist-generated=true +shlr/rizin-shell-parser/src/parser.c linguist-generated=true diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 861da1b699..6e20105ca0 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -6,7 +6,7 @@ about: Create a report to help us improve # This template is meant for bug reports, if you have a feature request, please be as descriptive as possible and delete the template -Make sure you are testing using the latest git version of radare2 before submitting any issue. +Make sure you are testing using the latest git version of rizin before submitting any issue. *If you would like to report a bug, please fill the template below* @@ -17,7 +17,7 @@ Make sure you are testing using the latest git version of radare2 before submitt | OS/arch/bits (mandatory) | Debian arm 64, Ubuntu x86 32 | File format of the file you reverse (mandatory) | PE, ELF etc. | Architecture/bits of the file (mandatory) | PPC, x86/32, x86/64 etc. -| r2 -v full output, **not truncated** (mandatory) | radare2 2.4.0-git 17284 @ darwin-x86-64 git.2.2.0-476-gf8cf84e06 commit: f8cf84e0653642d9ad34e760e0e56dd81860e799 build: 2018-02-17__11:08:27 +| r2 -v full output, **not truncated** (mandatory) | rizin 2.4.0-git 17284 @ darwin-x86-64 git.2.2.0-476-gf8cf84e06 commit: f8cf84e0653642d9ad34e760e0e56dd81860e799 build: 2018-02-17__11:08:27 ### Expected behavior diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3ce31adcc7..f5bf24b176 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,10 @@ **Your checklist for this pull request** -- [ ] I've read the [guidelines for contributing](https://github.com/radareorg/radare2/blob/master/DEVELOPERS.md) to this repository -- [ ] I made sure to follow the project's [coding style](https://github.com/radareorg/radare2/blob/master/DEVELOPERS.md#code-style) +- [ ] I've read the [guidelines for contributing](https://github.com/rizinorg/rizin/blob/master/DEVELOPERS.md) to this repository +- [ ] I made sure to follow the project's [coding style](https://github.com/rizinorg/rizin/blob/master/DEVELOPERS.md#code-style) - [ ] I've added tests that prove my fix is effective or that my feature works (if possible) -- [ ] I've updated the documentation and the [radare2 book](https://github.com/radareorg/radare2book) with the relevant information (if needed) +- [ ] I've updated the documentation and the [rizin book](https://github.com/rizinorg/rizinbook) with the relevant information (if needed) **Detailed description** diff --git a/.github/labeler.yml b/.github/labeler.yml index 89414d215b..f883175fcc 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,127 +1,127 @@ -radare2: - - binr/radare2/* - - libr/main/radare2.c +rizin: + - binrz/rizin/* + - librz/main/rizin.c -rabin2: - - binr/rabin2/* - - libr/main/rabin2.c +rz_bin: + - binrz/rz_bin/* + - librz/main/rz_bin.c -radiff2: - - binr/radiff2/* - - libr/main/radiff2.c +rz_diff: + - binrz/rz_diff/* + - librz/main/rz_diff.c -rafind2: - - binr/rafind2/* - - libr/main/rafind2.c +rz_find: + - binrz/rz_find/* + - librz/main/rz_find.c -ragg2: - - binr/ragg2/* - - libr/main/ragg2.c +rz_gg: + - binrz/rz_gg/* + - librz/main/rz_gg.c -rahash2: - - binr/rahash2/* - - libr/main/rahash2.c +rz_hash: + - binrz/rz_hash/* + - librz/main/rz_hash.c -rarun2: - - binr/rarun2/* - - libr/main/rarun2.c +rz_run: + - binrz/rz_run/* + - librz/main/rz_run.c -rasm2: - - binr/rasm2/* - - libr/main/rasm2.c +rz_asm: + - binrz/rz_asm/* + - librz/main/rz_asm.c -rax2: - - binr/rax2/* - - libr/main/rax2.c +rz_ax: + - binrz/rz_ax/* + - librz/main/rz_ax.c RAnal: - - libr/anal/**/* + - librz/anal/**/* RAsm-Assembler: - - libr/asm/**/*ass* - - libr/asm/asm_x86_nz.c + - librz/asm/**/*ass* + - librz/asm/asm_x86_nz.c RAsm-Disassembler: - - libr/asm/**/*dis* + - librz/asm/**/*dis* RBin: - - libr/bin/**/* + - librz/bin/**/* RBreakpoint: - - libr/bp/**/* + - librz/bp/**/* RConfig: - - libr/config/**/* + - librz/config/**/* RCons: - - libr/cons/**/* + - librz/cons/**/* RCore: - - libr/core/**/* + - librz/core/**/* RCrypto: - - libr/crypto/**/* + - librz/crypto/**/* RDebug: - - libr/debug/**/* + - librz/debug/**/* REgg: - - libr/egg/**/* + - librz/egg/**/* RFlag: - - libr/flag/**/* + - librz/flag/**/* RFS: - - libr/fs/**/* + - librz/fs/**/* RHash: - - libr/hash/**/* + - librz/hash/**/* RIO: - - libr/io/**/* + - librz/io/**/* RLang: - - libr/lang/**/* + - librz/lang/**/* RMagic: - - libr/magic/**/* + - librz/magic/**/* RParse: - - libr/parse/**/* + - librz/parse/**/* RReg: - - libr/reg/**/* + - librz/reg/**/* RSearch: - - libr/search/**/* + - librz/search/**/* RSocket: - - libr/socket/**/* + - librz/socket/**/* RSyscall: - - libr/syscall/**/* + - librz/syscall/**/* RUtil: - - libr/util/**/* + - librz/util/**/* API: - - libr/include/**/* + - librz/include/**/* buildsystem: - sys/**/* command: - - libr/core/cmd* + - librz/core/cmd* documentation: - doc/**/* ESIL: - - libr/anal/esil* + - librz/anal/esil* gdb: - shlr/gdb/**/* - - libr/io/p/io_gdb.c + - librz/io/p/io_gdb.c infrastructure: - .appveyor.yml @@ -130,8 +130,8 @@ infrastructure: - .builds/**/* - .github/workflows/* -r2r: - - binr/r2r/* +rz_test: + - binrz/rz_test/* - test/**/* java: @@ -139,13 +139,13 @@ java: WinDbg: - shlr/winkd/**/* - - libr/io/p/io_winkd.c + - librz/io/p/io_winkd.c webui: - shlr/www/**/* visual: - - libr/core/visual.c + - librz/core/visual.c panel: - - libr/core/panels.c + - librz/core/panels.c diff --git a/.github/stale.yml b/.github/stale.yml index 63b4be8cff..5ff25688f9 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -34,7 +34,7 @@ markComment: > This issue has been automatically marked as stale because it has not had recent activity. Considering a lot has changed since its creation, we kindly ask you to check again if the issue you reported is still relevant in the - current version of radare2. If it is, update this issue with a comment, + current version of rizin. If it is, update this issue with a comment, otherwise it will be automatically closed if no further activity occurs. Thank you for your contributions. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba5dd6a35f..421282249b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,15 @@ name: CI on: push: branches: - - '*' + - 'master' + - 'dev' + - 'stable' schedule: - cron: '0 18 * * 1,3,5' # Three-weekly at 18:00 UTC on Monday, Wednesday, and Friday pull_request: branches: - master + - dev - 'release-*' jobs: @@ -18,51 +21,49 @@ jobs: build-and-test: name: ${{ matrix.name }} runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.ignore_error }} + # continue-on-error: ${{ matrix.ignore_error }} timeout-minutes: ${{ matrix.timeout }} strategy: fail-fast: false matrix: - name: [linux-acr-gcc-tests, linux-acr-clang-build, linux-acr-clang-tests, linux-meson-gcc-build, linux-meson-gcc-tests, linux-meson-gcc-newshell-tests, macos-clang-tests, linux-gcc-tests-asan, capstone-v3, capstone-v5] - ignore_error: [false] + # name: [linux-acr-gcc-tests, linux-acr-clang-build, linux-acr-clang-tests, linux-meson-gcc-build, linux-meson-gcc-tests, linux-meson-gcc-newshell-tests, macos-clang-tests, linux-gcc-tests-asan, capstone-v3, capstone-v5] + name: [linux-acr-gcc-tests, linux-meson-gcc-newshell-tests, macos-clang-tests] + # ignore_error: [false] include: - name: linux-acr-gcc-tests os: ubuntu-latest build_system: acr compiler: gcc run_tests: true - enabled: false # TODO: temporarily disabled - timeout: 45 - - name: linux-acr-clang-tests - os: ubuntu-latest - build_system: acr - compiler: clang - run_tests: true - # enabled: ${{ github.event_name != 'pull_request' }} - enabled: false # TODO: temporarily disabled - timeout: 45 - - name: linux-meson-gcc-tests - os: ubuntu-latest - build_system: meson - compiler: gcc - run_tests: true - meson_options: -Duse_webui=true - enabled: ${{ github.event_name != 'pull_request' }} - timeout: 45 - - name: linux-acr-clang-build - os: ubuntu-latest - build_system: acr - compiler: clang - # enabled: ${{ github.event_name == 'pull_request' }} - enabled: false # TODO: temporarily disabled - timeout: 45 - - name: linux-meson-gcc-build - os: ubuntu-latest - build_system: meson - compiler: gcc - # enabled: ${{ github.event_name == 'pull_request' }} - enabled: false # TODO: temporarily disabled + enabled: true timeout: 45 + # - name: linux-acr-clang-tests + # os: ubuntu-latest + # build_system: acr + # compiler: clang + # run_tests: true + # enabled: ${{ github.event_name != 'pull_request' }} + # timeout: 45 + # - name: linux-meson-gcc-tests + # os: ubuntu-latest + # build_system: meson + # compiler: gcc + # run_tests: true + # meson_options: -Duse_webui=true + # enabled: ${{ github.event_name != 'pull_request' }} + # timeout: 45 + # - name: linux-acr-clang-build + # os: ubuntu-latest + # build_system: acr + # compiler: clang + # enabled: ${{ github.event_name == 'pull_request' }} + # timeout: 45 + # - name: linux-meson-gcc-build + # os: ubuntu-latest + # build_system: meson + # compiler: gcc + # enabled: ${{ github.event_name == 'pull_request' }} + # timeout: 45 - name: linux-meson-gcc-newshell-tests os: ubuntu-latest build_system: meson @@ -80,38 +81,35 @@ jobs: run_tests: true enabled: true timeout: 60 - - name: linux-gcc-tests-asan - os: ubuntu-20.04 - build_system: meson - compiler: gcc - cflags: '-DR2_ASSERT_STDOUT=1' - meson_options: -Db_sanitize=address,undefined -Duse_webui=true - asan: true - asan_options: 'detect_leaks=0,detect_odr_violation=0,allocator_may_return_null=1' - run_tests: true - # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'asan') }} - enabled: false # TODO: temporarily disabled - timeout: 100 - # NOTE: asan errors ignored for release- branch for now, because there are too many issues that would block the release - ignore_error: ${{ github.event_name == 'push' && contains(github.ref, 'release-') }} - - name: capstone-v3 - os: ubuntu-latest - build_system: meson - compiler: gcc - meson_options: -Duse_capstone_version=v3 - run_tests: false - # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'capstone') }} - enabled: false # TODO: temporarily disabled - timeout: 45 - - name: capstone-v5 - os: ubuntu-latest - build_system: meson - compiler: gcc - meson_options: -Duse_capstone_version=v5 - run_tests: false - # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'capstone') }} - enabled: false # TODO: temporarily disabled - timeout: 45 + # - name: linux-gcc-tests-asan + # os: ubuntu-20.04 + # build_system: meson + # compiler: gcc + # cflags: '-DR2_ASSERT_STDOUT=1' + # meson_options: -Db_sanitize=address,undefined -Duse_webui=true + # asan: true + # asan_options: 'detect_leaks=0,detect_odr_violation=0,allocator_may_return_null=1' + # run_tests: true + # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'asan') }} + # timeout: 100 + # # NOTE: asan errors ignored for release- branch for now, because there are too many issues that would block the release + # ignore_error: ${{ github.event_name == 'push' && contains(github.ref, 'release-') }} + # - name: capstone-v3 + # os: ubuntu-latest + # build_system: meson + # compiler: gcc + # meson_options: -Duse_capstone_version=v3 + # run_tests: false + # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'capstone') }} + # timeout: 45 + # - name: capstone-v5 + # os: ubuntu-latest + # build_system: meson + # compiler: gcc + # meson_options: -Duse_capstone_version=v5 + # run_tests: false + # enabled: ${{ github.event_name != 'pull_request' || contains(github.head_ref, 'capstone') }} + # timeout: 45 steps: - uses: actions/checkout@v2 @@ -125,9 +123,16 @@ jobs: - name: Install meson and ninja if: matrix.build_system == 'meson' && matrix.enabled run: pip3 install --user meson==0.52.0 ninja==1.10.0 + - name: Checkout rzpipe + if: matrix.enabled + uses: actions/checkout@v2 + with: + repository: rizinorg/rz-pipe + token: ${{ secrets.RIZIN_TOKEN }} # TODO: remove when the repo is public + path: test/rz-pipe - name: Install test dependencies if: matrix.run_tests && matrix.enabled - run: pip3 install --user 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' + run: pip3 install --user "file://$GITHUB_WORKSPACE/test/rz-pipe#egg=rzpipe&subdirectory=python" - name: Install clang if: matrix.compiler == 'clang' && matrix.os == 'ubuntu-latest' && matrix.enabled run: sudo apt-get --assume-yes install clang @@ -166,7 +171,7 @@ jobs: - name: Install with make if: matrix.build_system == 'acr' && matrix.enabled run: | - # Install the radare2 + # Install the rizin export PATH=${HOME}/bin:${HOME}/.local/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib/$(uname -m)-linux-gnu:${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${HOME}/lib/$(uname -m)-linux-gnu/pkgconfig:${PKG_CONFIG_PATH} @@ -174,7 +179,7 @@ jobs: - name: Install with meson if: matrix.build_system == 'meson' && matrix.enabled run: | - # Install the radare2 + # Install the rizin export PATH=${HOME}/bin:${HOME}/.local/bin:${PATH} export LD_LIBRARY_PATH=${HOME}/lib/$(uname -m)-linux-gnu:${HOME}/lib:${HOME}/lib64:${LD_LIBRARY_PATH} export PKG_CONFIG_PATH=${HOME}/lib/pkgconfig:${HOME}/lib/$(uname -m)-linux-gnu/pkgconfig:${PKG_CONFIG_PATH} @@ -193,7 +198,7 @@ jobs: export ASAN=1 fi cd test - radare2 -N -Qc 'e cfg.newshell' - + rizin -N -Qc 'e cfg.newshell' - make env: NEWSHELL: ${{ matrix.newshell }} @@ -228,18 +233,18 @@ jobs: - name: Checkout r2 run: | git clone https://github.com/${{ github.repository }} - cd radare2 + cd rizin git fetch origin ${{ github.ref }} git checkout -b local_branch FETCH_HEAD - name: Configure with ACR and build run: ./configure --prefix=/usr && make CS_RELEASE=1 - working-directory: radare2 + working-directory: rizin - name: Install with make run: make install - working-directory: radare2 + working-directory: rizin - name: Run tests run: cd test/unit && make - working-directory: radare2 + working-directory: rizin env: # `make install` installs, for some unknown reasons, pkgconfig files in # /usr/lib and not in /usr/lib64, thus pkg-config cannot find the right @@ -281,23 +286,23 @@ jobs: - name: Checkout r2 run: | git clone https://github.com/${{ github.repository }} - cd radare2 + cd rizin git fetch origin ${{ github.ref }} git checkout -b local_branch FETCH_HEAD - name: Checkout our Testsuite Binaries - run: git clone https://github.com/radareorg/radare2-testbins test/bins + run: git clone https://github.com/rizinorg/rizin-testbins test/bins - name: Configure with ACR and build run: ./configure --prefix=/usr && make - working-directory: radare2 + working-directory: rizin - name: Install with make run: make install - working-directory: radare2 + working-directory: rizin - name: Install test dependencies - run: python3 -m pip install --user 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' + run: python3 -m pip install --user 'git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python' - name: Run tests # FIXME: debug tests fail on debian for now, let's ignore all tests for the moment run: cd test && make || exit 0 - working-directory: radare2 + working-directory: rizin env: PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig @@ -312,7 +317,7 @@ jobs: - name: Checkout our Testsuite Binaries uses: actions/checkout@v2 with: - repository: radareorg/radare2-testbins + repository: rizinorg/rizin-testbins path: test/bins - name: Install static run: | @@ -321,7 +326,7 @@ jobs: - name: Run tests run: | r2 -v - r2r -v + rz-test -v cd test make @@ -346,13 +351,13 @@ jobs: - name: Create archive run: | cd .. - cp -r radare2 radare2-${{ steps.extract_version.outputs.branch}} - tar cvzf radare2-src.tar.gz radare2-${{ steps.extract_version.outputs.branch}} - mv radare2-src.tar.gz radare2/ + cp -r rizin rizin-${{ steps.extract_version.outputs.branch}} + tar cvzf rizin-src.tar.gz rizin-${{ steps.extract_version.outputs.branch}} + mv rizin-src.tar.gz rizin/ - uses: actions/upload-artifact@v2 with: - name: radare2-src - path: radare2-src.tar.gz + name: rizin-src + path: rizin-src.tar.gz build-deb: name: Build deb package for ${{ matrix.container }} @@ -375,25 +380,25 @@ jobs: - name: Checkout r2 run: | git clone https://github.com/${{ github.repository }} - cd radare2 + cd rizin git fetch origin ${{ github.ref }} git checkout -b local_branch FETCH_HEAD - name: Preparing the deb package run: | sys/debian.sh - mv radare2_*_amd64.deb radare2_amd64.deb - mv radare2-dev_*_amd64.deb radare2-dev_amd64.deb - working-directory: radare2 + mv rizin_*_amd64.deb rizin_amd64.deb + mv rizin-dev_*_amd64.deb rizin-dev_amd64.deb + working-directory: rizin - name: Upload deb file uses: actions/upload-artifact@v2 with: - name: radare2-${{ matrix.name }}-deb - path: radare2/radare2_amd64.deb + name: rizin-${{ matrix.name }}-deb + path: rizin/rizin_amd64.deb - name: Upload -dev deb file uses: actions/upload-artifact@v2 with: - name: radare2-dev-${{ matrix.name }}-deb - path: radare2/radare2-dev_amd64.deb + name: rizin-dev-${{ matrix.name }}-deb + path: rizin/rizin-dev_amd64.deb build-osx-pkg: name: Build OSX package @@ -407,17 +412,18 @@ jobs: - name: Create OSX package run: | ./sys/osx-pkg.sh - mv sys/osx-pkg/radare2-*.pkg sys/osx-pkg/radare2.pkg + mv sys/osx-pkg/rizin-*.pkg sys/osx-pkg/rizin.pkg - name: Upload .pkg file uses: actions/upload-artifact@v2 with: - name: radare2.pkg - path: sys/osx-pkg/radare2.pkg + name: rizin.pkg + path: sys/osx-pkg/rizin.pkg build-windows: name: Build Windows zip/installer ${{ matrix.name }} runs-on: windows-latest - if: contains(github.head_ref, 'windows') || (github.event_name == 'push' && contains(github.ref, 'release-')) + # if: contains(github.head_ref, 'windows') || (github.event_name == 'push' && contains(github.ref, 'release-')) + if: contains(github.head_ref, 'windows') || (github.event_name == 'push' && contains(github.ref, 'dev')) needs: [build-and-test] strategy: fail-fast: false @@ -445,27 +451,27 @@ jobs: shell: pwsh run: | .github\vsdevenv.ps1 - meson --buildtype=release --prefix=$PWD\radare2-install build ${{ matrix.meson_options }} + meson --buildtype=release --prefix=$PWD\rizin-install build ${{ matrix.meson_options }} ninja -C build ninja -C build install - name: Create zip artifact shell: pwsh - run: 7z a radare2-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip $PWD\radare2-install + run: 7z a rizin-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip $PWD\rizin-install - uses: actions/upload-artifact@v2 with: - name: radare2-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip - path: .\radare2-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip + name: rizin-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip + path: .\rizin-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }}.zip - uses: actions/checkout@v2 with: - repository: radareorg/radare2-win-installer - path: ./radare2-win-installer + repository: rizinorg/rizin-win-installer + path: ./rizin-win-installer - name: Create installer shell: pwsh - run: iscc radare2-win-installer\radare2.iss /DRadare2Location=..\radare2-install\* /DLicenseLocation=..\COPYING.LESSER /DIcoLocation=radare2.ico /DMyAppVersion=${{ steps.extract_version.outputs.branch }} + run: iscc rizin-win-installer\rizin.iss /DRadare2Location=..\rizin-install\* /DLicenseLocation=..\COPYING.LESSER /DIcoLocation=rizin.ico /DMyAppVersion=${{ steps.extract_version.outputs.branch }} - uses: actions/upload-artifact@v2 with: - name: radare2_installer-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }} - path: radare2-win-installer\Output\radare2.exe + name: rizin_installer-${{ matrix.name }}-${{ steps.extract_version.outputs.branch }} + path: rizin-win-installer\Output\rizin.exe build-ios-cydia: name: Build iOS Cydia packages @@ -486,14 +492,14 @@ jobs: run: ls -lahR ./sys/cydia - uses: actions/upload-artifact@v2 with: - name: radare2-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm - path: ./sys/cydia/radare2/radare2-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + name: rizin-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm + path: ./sys/cydia/rizin/rizin-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb - name: Create cydia package run: ./sys/ios-cydia.sh - uses: actions/upload-artifact@v2 with: - name: radare2_${{ steps.extract_version.outputs.branch }}_iphoneos-arm - path: ./sys/cydia/radare2/radare2_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + name: rizin_${{ steps.extract_version.outputs.branch }}_iphoneos-arm + path: ./sys/cydia/rizin/rizin_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb build-android: name: Build Android ${{ matrix.name }} package @@ -513,55 +519,55 @@ jobs: export PATH=${HOME}/.local/bin:${PATH} CFLAGS="-static" LDFLAGS="-static" meson --buildtype release --default-library static --prefix=/tmp/android-dir -Dblob=true build --cross-file .github/meson-android-${{ matrix.name }}.ini ninja -C build && ninja -C build install - - name: Create radare2-android-${{ matrix.name }}.tar.gz + - name: Create rizin-android-${{ matrix.name }}.tar.gz run: | cd /tmp rm -rf android-dir/include android-dir/lib - tar --transform 's/android-dir/data\/data\/org.radareorg.radare2installer/g' -cvf radare2-android-${{ matrix.name }}.tar.gz android-dir/ + tar --transform 's/android-dir/data\/data\/org.rizinorg.rizininstaller/g' -cvf rizin-android-${{ matrix.name }}.tar.gz android-dir/ - uses: actions/upload-artifact@v2 with: - name: radare2-android-${{ matrix.name }} - path: /tmp/radare2-android-${{ matrix.name }}.tar.gz + name: rizin-android-${{ matrix.name }} + path: /tmp/rizin-android-${{ matrix.name }}.tar.gz build-extras: - name: Build radare2 extras and r2pipe + name: Build rizin extras and rzpipe if: contains(github.head_ref, 'extras') || contains(github.ref, 'release-') || github.event_name == 'schedule' needs: [create-tarball] runs-on: ubuntu-latest env: TESTS: 'armthumb baleful bcl ba2 blackfin blessr2 keystone-lib keystone lang-duktape mc6809 microblaze msil pcap ppcdisasm psosvm swf unicorn-lib unicorn vc4 x86udis x86bea x86tab x86olly x86zyan z80-nc' - R2PIPE_TESTS: 'r2pipe-go r2pipe-js r2pipe-py' + R2PIPE_TESTS: 'rzpipe-go rzpipe-js rzpipe-py' steps: - uses: actions/download-artifact@v2 with: - name: radare2-src + name: rizin-src path: ./ - name: Extract source tarball - run: mkdir radare2 && tar -C radare2 --strip-components=1 -xvf radare2-src.tar.gz + run: mkdir rizin && tar -C rizin --strip-components=1 -xvf rizin-src.tar.gz - name: Install dependencies run: sudo apt-get --assume-yes install wget unzip python3-wheel python3-setuptools build-essential python3-pip && sudo pip3 install meson ninja - - name: Install radare2 + - name: Install rizin run: | export PATH=$PATH:/usr/local/bin meson --prefix=/usr --buildtype=release build && ninja -C build && sudo ninja -C build install - sudo ln -s radare2 /usr/bin/r2 - working-directory: radare2 - - name: Init r2pm - run: r2pm init && r2pm update + sudo ln -s rizin /usr/bin/r2 + working-directory: rizin + - name: Init rz-pm + run: rz-pm init && rz-pm update - name: Compile and install plugins run: | set -e for p in $TESTS ; do echo $p - r2pm -i $p + rz-pm -i $p done set +e - - name: Compile and install r2pipe + - name: Compile and install rzpipe run: | set -e for p in $R2PIPE_TESTS ; do echo $p - r2pm -i $p + rz-pm -i $p done set +e @@ -584,16 +590,16 @@ jobs: run: apt-get update && apt-get install --yes gcc pkg-config - uses: actions/download-artifact@v2 with: - name: radare2-${{ matrix.name }}-deb + name: rizin-${{ matrix.name }}-deb path: ./ - uses: actions/download-artifact@v2 with: - name: radare2-dev-${{ matrix.name }}-deb + name: rizin-dev-${{ matrix.name }}-deb path: ./ - - name: Install radare2 debs - run: apt-get update && apt-get install ./radare2*.deb - - name: Check that installed radare2 runs - run: radare2 -qcq /bin/ls + - name: Install rizin debs + run: apt-get update && apt-get install ./rizin*.deb + - name: Check that installed rizin runs + run: rizin -qcq /bin/ls - name: Check that libraries can be used shell: bash run: | @@ -610,12 +616,12 @@ jobs: run: brew install pkg-config - uses: actions/download-artifact@v2 with: - name: radare2.pkg + name: rizin.pkg path: ./ - - name: Install radare2.pkg - run: sudo installer -pkg ./radare2.pkg -target / - - name: Check that installed radare2 runs - run: radare2 -qcq /bin/ls + - name: Install rizin.pkg + run: sudo installer -pkg ./rizin.pkg -target / + - name: Check that installed rizin runs + run: rizin -qcq /bin/ls - name: Check that libraries can be used run: | echo -e "#include \nint main(int argc, char **argv) { return r_str_newf (\"%s\", argv[0]) != NULL? 0: 1; }" > test.c @@ -638,24 +644,24 @@ jobs: id: extract_version - uses: actions/download-artifact@v2 with: - name: radare2_installer-clang_cl-${{ steps.extract_version.outputs.branch }} + name: rizin_installer-clang_cl-${{ steps.extract_version.outputs.branch }} path: ./ - name: Install radare.exe shell: pwsh - run: Start-Process -Wait -FilePath .\radare2.exe -ArgumentList "/SP- /SILENT" -PassThru - - name: Check that installed radare2 runs + run: Start-Process -Wait -FilePath .\rizin.exe -ArgumentList "/SP- /SILENT" -PassThru + - name: Check that installed rizin runs shell: pwsh - run: ~\AppData\Local\Programs\radare2\bin\radare2.exe -qcq .\radare2.exe + run: ~\AppData\Local\Programs\rizin\bin\rizin.exe -qcq .\rizin.exe - name: Check that libraries can be used shell: pwsh run: | .github\vsdevenv.ps1 - $env:PATH = "$env:PATH;C:$env:HOMEPATH\AppData\Local\Programs\radare2\bin" - $env:PKG_CONFIG_PATH = "C:$env:HOMEPATH\AppData\Local\Programs\radare2\lib\pkgconfig" + $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:PKG_CONFIG_PATH pkg-config --list-all echo "#include `nint main(int argc, char **argv) { return r_str_newf (`"%s`", argv[0]) != NULL? 0: 1; }" > test.c - cl -IC:$env:HOMEPATH\AppData\Local\Programs\radare2\include\libr -IC:$env:HOMEPATH\AppData\Local\Programs\radare2\include\libr\sdb /Fetest.exe test.c /link /libpath:C:$env:HOMEPATH\AppData\Local\Programs\radare2\lib r_util.lib + cl -IC:$env:HOMEPATH\AppData\Local\Programs\rizin\include\librz -IC:$env:HOMEPATH\AppData\Local\Programs\rizin\include\librz\sdb /Fetest.exe test.c /link /libpath:C:$env:HOMEPATH\AppData\Local\Programs\rizin\lib r_util.lib .\test.exe create-release: @@ -693,122 +699,122 @@ jobs: - uses: actions/download-artifact@v2 - name: Display structure of downloaded files run: ls -R - - name: Upload radare2 src tarball + - name: Upload rizin src tarball uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-src/radare2-src.tar.gz - asset_name: radare2-src-${{ steps.extract_version.outputs.branch }}.tar.gz + asset_path: ./rizin-src/rizin-src.tar.gz + asset_name: rizin-src-${{ steps.extract_version.outputs.branch }}.tar.gz asset_content_type: application/zip - - name: Upload radare2 debian:buster package + - name: Upload rizin debian:buster package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-debian-buster-deb/radare2_amd64.deb - asset_name: radare2-debian-buster_${{ steps.extract_version.outputs.branch }}_amd64.deb + asset_path: ./rizin-debian-buster-deb/rizin_amd64.deb + asset_name: rizin-debian-buster_${{ steps.extract_version.outputs.branch }}_amd64.deb asset_content_type: application/zip - - name: Upload radare2-dev debian:buster package + - name: Upload rizin-dev debian:buster package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-dev-debian-buster-deb/radare2-dev_amd64.deb - asset_name: radare2-dev-debian-buster_${{ steps.extract_version.outputs.branch }}_amd64.deb + asset_path: ./rizin-dev-debian-buster-deb/rizin-dev_amd64.deb + asset_name: rizin-dev-debian-buster_${{ steps.extract_version.outputs.branch }}_amd64.deb asset_content_type: application/zip - - name: Upload radare2 ubuntu:18.04 package + - name: Upload rizin ubuntu:18.04 package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-ubuntu-1804-deb/radare2_amd64.deb - asset_name: radare2-ubuntu-1804_${{ steps.extract_version.outputs.branch }}_amd64.deb + asset_path: ./rizin-ubuntu-1804-deb/rizin_amd64.deb + asset_name: rizin-ubuntu-1804_${{ steps.extract_version.outputs.branch }}_amd64.deb asset_content_type: application/zip - - name: Upload radare2-dev ubuntu:18.04 package + - name: Upload rizin-dev ubuntu:18.04 package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-dev-ubuntu-1804-deb/radare2-dev_amd64.deb - asset_name: radare2-dev-ubuntu-1804_${{ steps.extract_version.outputs.branch }}_amd64.deb + asset_path: ./rizin-dev-ubuntu-1804-deb/rizin-dev_amd64.deb + asset_name: rizin-dev-ubuntu-1804_${{ steps.extract_version.outputs.branch }}_amd64.deb asset_content_type: application/zip - - name: Upload radare2 android x86_64 tar.gz + - name: Upload rizin android x86_64 tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-android-x86_64/radare2-android-x86_64.tar.gz - asset_name: radare2-${{ steps.extract_version.outputs.branch }}-android-x86_64.tar.gz + asset_path: ./rizin-android-x86_64/rizin-android-x86_64.tar.gz + asset_name: rizin-${{ steps.extract_version.outputs.branch }}-android-x86_64.tar.gz asset_content_type: application/zip - - name: Upload radare2 android arm tar.gz + - name: Upload rizin android arm tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-android-arm/radare2-android-arm.tar.gz - asset_name: radare2-${{ steps.extract_version.outputs.branch }}-android-arm.tar.gz + asset_path: ./rizin-android-arm/rizin-android-arm.tar.gz + asset_name: rizin-${{ steps.extract_version.outputs.branch }}-android-arm.tar.gz asset_content_type: application/zip - - name: Upload radare2 android aarch64 tar.gz + - name: Upload rizin android aarch64 tar.gz uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-android-aarch64/radare2-android-aarch64.tar.gz - asset_name: radare2-${{ steps.extract_version.outputs.branch }}-android-aarch64.tar.gz + asset_path: ./rizin-android-aarch64/rizin-android-aarch64.tar.gz + asset_name: rizin-${{ steps.extract_version.outputs.branch }}-android-aarch64.tar.gz asset_content_type: application/zip - - name: Upload radare2 OSX pkg + - name: Upload rizin OSX pkg uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2.pkg/radare2.pkg - asset_name: radare2-macos-${{ steps.extract_version.outputs.branch }}.pkg + asset_path: ./rizin.pkg/rizin.pkg + asset_name: rizin-macos-${{ steps.extract_version.outputs.branch }}.pkg asset_content_type: application/zip - - name: Upload radare2 windows archive + - name: Upload rizin windows archive uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-vs2019_static-${{ steps.extract_version.outputs.branch }}.zip/radare2-vs2019_static-${{ steps.extract_version.outputs.branch }}.zip - asset_name: radare2-windows-static-${{ steps.extract_version.outputs.branch }}.zip + asset_path: ./rizin-vs2019_static-${{ steps.extract_version.outputs.branch }}.zip/rizin-vs2019_static-${{ steps.extract_version.outputs.branch }}.zip + asset_name: rizin-windows-static-${{ steps.extract_version.outputs.branch }}.zip asset_content_type: application/zip - - name: Upload radare2 windows installer + - name: Upload rizin windows installer uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2_installer-clang_cl-${{ steps.extract_version.outputs.branch }}/radare2.exe - asset_name: radare2_installer-${{ steps.extract_version.outputs.branch }}.exe + asset_path: ./rizin_installer-clang_cl-${{ steps.extract_version.outputs.branch }}/rizin.exe + asset_name: rizin_installer-${{ steps.extract_version.outputs.branch }}.exe asset_content_type: application/zip - - name: Upload radare2 iOS arm32 cydia package + - name: Upload rizin iOS arm32 cydia package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm/radare2-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb - asset_name: radare2-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + asset_path: ./rizin-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm/rizin-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + asset_name: rizin-arm32_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb asset_content_type: application/zip - - name: Upload radare2 iOS aarch64 cydia package + - name: Upload rizin iOS aarch64 cydia package uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./radare2_${{ steps.extract_version.outputs.branch }}_iphoneos-arm/radare2_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb - asset_name: radare2-aarch64_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + asset_path: ./rizin_${{ steps.extract_version.outputs.branch }}_iphoneos-arm/rizin_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb + asset_name: rizin-aarch64_${{ steps.extract_version.outputs.branch }}_iphoneos-arm.deb asset_content_type: application/zip publish-docker-image: @@ -821,7 +827,7 @@ jobs: - name: Publish to Registry uses: docker/build-push-action@v1 with: - repository: ${{ secrets.DOCKER_USERNAME }}/radare2 + repository: ${{ secrets.DOCKER_USERNAME }}/rizin tag_with_ref: true username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} diff --git a/.github/workflows/continuous.yml b/.github/workflows/continuous.yml index 0fe60a6d8a..c31be4bf94 100644 --- a/.github/workflows/continuous.yml +++ b/.github/workflows/continuous.yml @@ -15,28 +15,28 @@ jobs: - name: Checkout r2 run: | git clone https://github.com/${{ github.repository }} - cd radare2 + cd rizin git fetch origin ${{ github.ref }} git checkout -b local_branch FETCH_HEAD - name: Extract r2 version shell: bash run: echo "##[set-output name=branch;]$(python sys/version.py)" id: extract_version - working-directory: radare2 + working-directory: rizin - name: Preparing the deb package run: | sys/debian.sh - working-directory: radare2 + working-directory: rizin - name: Upload deb file uses: actions/upload-artifact@v2 with: - name: radare2_${{ steps.extract_version.outputs.branch }}_amd64.deb - path: radare2/radare2_${{ steps.extract_version.outputs.branch }}_amd64.deb + name: rizin_${{ steps.extract_version.outputs.branch }}_amd64.deb + path: rizin/rizin_${{ steps.extract_version.outputs.branch }}_amd64.deb - name: Upload -dev deb file uses: actions/upload-artifact@v2 with: - name: radare2-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb - path: radare2/radare2-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb + name: rizin-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb + path: rizin/rizin-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb create-release: name: Create/Update pre-release Continuous build @@ -53,7 +53,7 @@ jobs: run: ls -R - name: Upload files shell: bash - run: .github/upload.sh ./radare2_${{ steps.extract_version.outputs.branch }}_amd64.deb/radare2_${{ steps.extract_version.outputs.branch }}_amd64.deb ./radare2-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb/radare2-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb + run: .github/upload.sh ./rizin_${{ steps.extract_version.outputs.branch }}_amd64.deb/rizin_${{ steps.extract_version.outputs.branch }}_amd64.deb ./rizin-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb/rizin-dev_${{ steps.extract_version.outputs.branch }}_amd64.deb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} UPLOADTOOL_BODY: Continuous build ${{ github.sha }} diff --git a/.github/workflows/coverity-scan.yml b/.github/workflows/coverity-scan.yml index 2347d9008f..977428abe8 100644 --- a/.github/workflows/coverity-scan.yml +++ b/.github/workflows/coverity-scan.yml @@ -14,41 +14,41 @@ jobs: - uses: actions/checkout@v2 - name: Download Coverity Build Tool run: | - wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=radare2" -O cov-analysis-linux64.tar.gz + wget -q https://scan.coverity.com/download/cxx/linux64 --post-data "token=$TOKEN&project=rizin" -O cov-analysis-linux64.tar.gz mkdir cov-analysis-linux64 tar xzf cov-analysis-linux64.tar.gz --strip 1 -C cov-analysis-linux64 env: TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} - if: steps.determine-repo.outputs.repo == 'radareorg/radare2' + if: steps.determine-repo.outputs.repo == 'rizinorg/rizin' - name: Fixed world writable dirs run: | chmod go-w $HOME sudo chmod -R go-w /usr/share - if: steps.determine-repo.outputs.repo == 'radareorg/radare2' + if: steps.determine-repo.outputs.repo == 'rizinorg/rizin' - name: Configure run: ./configure - if: steps.determine-repo.outputs.repo == 'radareorg/radare2' + if: steps.determine-repo.outputs.repo == 'rizinorg/rizin' - name: Build with cov-build run: | export PATH=`pwd`/cov-analysis-linux64/bin:$PATH cov-build --dir cov-int make - if: steps.determine-repo.outputs.repo == 'radareorg/radare2' + if: steps.determine-repo.outputs.repo == 'rizinorg/rizin' # TODO: Make it GitHub Action instead - name: Submit the result to Coverity Scan run: | - tar czvf radare2.tgz cov-int + tar czvf rizin.tgz cov-int curl \ - --form project=radare2 \ + --form project=rizin \ --form token=$TOKEN \ --form email=noreply@radare.org \ - --form file=@radare2.tgz \ + --form file=@rizin.tgz \ --form version=trunk \ - --form description="radare2" \ - https://scan.coverity.com/builds?project=radare2 + --form description="rizin" \ + https://scan.coverity.com/builds?project=rizin env: TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} - if: steps.determine-repo.outputs.repo == 'radareorg/radare2' + if: steps.determine-repo.outputs.repo == 'rizinorg/rizin' diff --git a/.github/workflows/newshell-treesitter-tests.yml b/.github/workflows/newshell-treesitter-tests.yml index 4a9e339c63..163adce23c 100644 --- a/.github/workflows/newshell-treesitter-tests.yml +++ b/.github/workflows/newshell-treesitter-tests.yml @@ -6,24 +6,24 @@ on: - 'shlr/tree-sitter/*' - 'shlr/tree-sitter/lib/*' - 'shlr/tree-sitter/lib/**/*' - - 'shlr/radare2-shell-parser/*' - - 'shlr/radare2-shell-parser/**/*' + - 'shlr/rizin-shell-parser/*' + - 'shlr/rizin-shell-parser/**/*' branches: - master jobs: build: - name: radare2-shell-parser-tests + name: rizin-shell-parser-tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: '12.x' - - run: cd shlr/radare2-shell-parser/ && npm install + - run: cd shlr/rizin-shell-parser/ && npm install - name: Run tests run: | - cd shlr/radare2-shell-parser + cd shlr/rizin-shell-parser export PATH=${PATH}:./node_modules/.bin tree-sitter generate tree-sitter test diff --git a/.github/workflows/tcc.yml b/.github/workflows/tcc.yml index 64443de678..1bdcac4336 100644 --- a/.github/workflows/tcc.yml +++ b/.github/workflows/tcc.yml @@ -27,7 +27,7 @@ jobs: - name: Checkout our Testsuite Binaries uses: actions/checkout@v2 with: - repository: radareorg/radare2-testbins + repository: rizinorg/rizin-testbins path: test/bins - name: Configure, build and install @@ -39,10 +39,10 @@ jobs: sudo make install - name: Install test dependencies - run: python3 -m pip install --user 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' + run: python3 -m pip install --user 'git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python' - name: Run tests run: cd test && make - working-directory: radare2 + working-directory: rizin env: PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig diff --git a/.gitignore b/.gitignore index 4d1bd5591d..db1b4f52ef 100644 --- a/.gitignore +++ b/.gitignore @@ -25,39 +25,39 @@ langs.cfg *.pdb *.lib *.ilk -binr/r2agent/r2agent -binr/r2agent/r2agent.exe -binr/r2r/r2r -binr/r2r/r2r.exe -binr/rabin2/rabin2 -binr/rabin2/rabin2.exe -binr/radare2/radare2 -binr/radare2/radare2.exe -binr/radiff2/radiff2 -binr/radiff2/radiff2.exe -binr/rafind2/rafind2 -binr/rafind2/rafind2.exe -binr/ragg2/ragg2 -binr/ragg2/ragg2.exe -binr/rahash2/rahash2 -binr/rahash2/rahash2.exe -binr/ranal2/ranal2 -binr/ranal2/ranal2.exe -binr/rarun2/rarun2 -binr/rarun2/rarun2.exe -binr/rasm2/rasm2 -binr/rasm2/rasm2.exe -binr/rax2/rax2 -binr/rax2/rax2.exe -binr/*/_CodeSignature/* +binrz/rz_agent/rz-agent +binrz/rz_agent/rz-agent.exe +binrz/rz_test/rz-test +binrz/rz_test/rz-test.exe +binrz/rz_bin/rz-bin +binrz/rz_bin/rz-bin.exe +binrz/rizin/rizin +binrz/rizin/rizin.exe +binrz/rz_diff/rz-diff +binrz/rz_diff/rz-diff.exe +binrz/rz_find/rz-find +binrz/rz_find/rz-find.exe +binrz/rz_gg/rz-gg +binrz/rz_gg/rz-gg.exe +binrz/rz_hash/rz-hash +binrz/rz_hash/rz-hash.exe +binrz/ranal2/ranal2 +binrz/ranal2/ranal2.exe +binrz/rz_run/rz-run +binrz/rz_run/rz-run.exe +binrz/rz_asm/rz-asm +binrz/rz_asm/rz-asm.exe +binrz/rz_ax/rz-ax +binrz/rz_ax/rz-ax.exe +binrz/*/_CodeSignature/* build build_sdb config-user.mk -libr/bin/d/dll/dll -libr/config.h -libr/include/r_userconf.h -libr/include/r_version.h -libr/include/r_version.h.tmp +librz/bin/d/dll/dll +librz/config.h +librz/include/r_userconf.h +librz/include/r_version.h +librz/include/r_version.h.tmp shlr/capstone/ shlr/java/out shlr/java/out.exe @@ -76,10 +76,10 @@ sys/travis/*.txt sys/.mark_python-deps sys/.mark_swig sys/_work -radare2-bindings -radare2-regressions -radare2-w32-* -radare2-w64-* +rizin-bindings +rizin-regressions +rizin-w32-* +rizin-w64-* tags **/GPATH **/GRTAGS @@ -91,7 +91,7 @@ tags .ycm_extra_conf.pyc .kdev4/* *.kdev4 -radare2-*.zip +rizin-*.zip # Ignore meson related files ./bin ninja.exe @@ -100,10 +100,10 @@ infer_out infer-out/ cscope.out r2-static/* -binr/rasign2/rasign2 -binr/rasign2/rasign2.exe +binrz/rz_sign/rz_sign +binrz/rz_sign/rz_sign.exe compile_commands.json -libr/flag/d/tags.r2 +librz/flag/d/tags.r2 # CLion .idea/ # VSCode @@ -125,4 +125,4 @@ __pycache__ .docker_alpine .ccls-cache/ vgcore.* -libr/include/sdb +librz/include/sdb diff --git a/.travis.yml b/.travis.yml index 09c658799c..ef1c05c982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -# travis.yml for testing radare2. +# travis.yml for testing rizin. # Initially written in 2014-2016 # by jn__. Updated 2018 by damo22 # xvilka, pancake, ret2libc in 2020 @@ -106,7 +106,7 @@ before_install: if [ "${FUZZIT}" == "1" ]; then docker pull gcr.io/fuzzit-public/builders:llvm9.v1 elif [ "$TRAVIS_OS_NAME" != "osx" ] && [ "$NODOCKER" != "1" ]; then - docker pull radareorg/r2-travis:latest || docker build -t radareorg/r2-travis:latest -f Dockerfile.travis . + docker pull rizinorg/r2-travis:latest || docker build -t rizinorg/r2-travis:latest -f Dockerfile.travis . fi script: @@ -119,7 +119,7 @@ script: if [ "${FUZZIT}" == "1" ] ; then docker run -v /home/travis/.ccache:/root/.ccache -v "${TRAVIS_BUILD_DIR}":"${TRAVIS_BUILD_DIR}" --entrypoint "/bin/bash" gcr.io/fuzzit-public/builders:llvm9.v1 -c "cd ${TRAVIS_BUILD_DIR}; . docker-env.sh; bash travis-script" elif [ "$TRAVIS_OS_NAME" != "osx" ] && [ "$NODOCKER" != "1" ] ; then - docker run -v /home/travis/.ccache:/root/.ccache -v "${TRAVIS_BUILD_DIR}":"${TRAVIS_BUILD_DIR}" --entrypoint "/bin/bash" radareorg/r2-travis:latest -c "cd ${TRAVIS_BUILD_DIR}; . docker-env.sh; bash travis-script" + docker run -v /home/travis/.ccache:/root/.ccache -v "${TRAVIS_BUILD_DIR}":"${TRAVIS_BUILD_DIR}" --entrypoint "/bin/bash" rizinorg/r2-travis:latest -c "cd ${TRAVIS_BUILD_DIR}; . docker-env.sh; bash travis-script" else $SHELL travis-script fi diff --git a/AUTHORS.md b/AUTHORS.md index 945d61dcce..d328db88fa 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -4,7 +4,7 @@ Authors Main developer (author and maintainer) -------------------------------------- -The author of radare and radare2 is the main contributor and designer of the tool, apis, bindings, etc. +The author of radare and rizin is the main contributor and designer of the tool, apis, bindings, etc. - pancake @@ -23,7 +23,7 @@ Most active in community, setting up CI servers, regression tests, esil, coverit Honoric Contributors -------------------- -Special mention for showing great interest and helping the project in fuzzing, bug fixing, the new web ui, r2pipe, PDB, windows support (console, debugger, windbg), .. +Special mention for showing great interest and helping the project in fuzzing, bug fixing, the new web ui, rzpipe, PDB, windows support (console, debugger, windbg), .. - Alvaro Felipe - NighterMan diff --git a/CODEOWNERS b/CODEOWNERS index 67c94ecaff..ed070ec5a1 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,36 +1,36 @@ * @trufae *.js @trufae CODEOWNERS @trufae @XVilka @kazarmy @thestr4ng3r @ret2libc -libr/anal/ @thestr4ng3r -libr/anal/esil* @trufae @condret -libr/anal/xrefs.c @ret2libc -libr/arch/gb/ @condret -libr/asm/ @wargio @trufae -libr/asm/p/x86_* @ret2libc -libr/asm/p/arm_* @trufae -libr/bin/ @ret2libc @trufae -libr/bin/format/elf/ @ret2libc @kazarmy -libr/bin/format/mach0/ @trufae -libr/bin/format/objc/ @trufae -libr/bin/format/wasm/ @wargio -libr/config/ @trufae @ret2libc -libr/cons/ @thestr4ng3r @trufae -libr/core/cmd.c @ret2libc @trufae -libr/debug/ @yossizap @trufae -libr/egg/ @trufae -libr/flag/ @ret2libc @trufae -libr/fs/ @trufae -libr/io/ @condret @trufae @ret2libc -libr/lang/ @thestr4ng3r @trufae @ret2libc -libr/magic/ @trufae -libr/parse/ @ret2libc @trufae -libr/reg/ @XVilka @trufae -libr/socket/ @XVilka @yossizap -libr/syscall/ @ret2libc @trufae -libr/util/ @ret2libc @thestr4ng3r +librz/anal/ @thestr4ng3r +librz/anal/esil* @trufae @condret +librz/anal/xrefs.c @ret2libc +librz/arch/gb/ @condret +librz/asm/ @wargio @trufae +librz/asm/p/x86_* @ret2libc +librz/asm/p/arm_* @trufae +librz/bin/ @ret2libc @trufae +librz/bin/format/elf/ @ret2libc @kazarmy +librz/bin/format/mach0/ @trufae +librz/bin/format/objc/ @trufae +librz/bin/format/wasm/ @wargio +librz/config/ @trufae @ret2libc +librz/cons/ @thestr4ng3r @trufae +librz/core/cmd.c @ret2libc @trufae +librz/debug/ @yossizap @trufae +librz/egg/ @trufae +librz/flag/ @ret2libc @trufae +librz/fs/ @trufae +librz/io/ @condret @trufae @ret2libc +librz/lang/ @thestr4ng3r @trufae @ret2libc +librz/magic/ @trufae +librz/parse/ @ret2libc @trufae +librz/reg/ @XVilka @trufae +librz/socket/ @XVilka @yossizap +librz/syscall/ @ret2libc @trufae +librz/util/ @ret2libc @thestr4ng3r shlr/gdb/ @yossizap shlr/ptrace-wrap/ @thestr4ng3r -shlr/radare2-shell-parser/ @ret2libc +shlr/rizin-shell-parser/ @ret2libc shlr/tcc/ @XVilka @trufae shlr/w32dbg_wrap/ @yossizap shlr/winkd/ @yossizap diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cddd6b595f..7a3f4ec6f1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ # How to report issues Before reporting an issue with GitHub, be sure that: -* you are using the git version of radare2 +* you are using the git version of rizin * you are using a clean installation * the issue was not already reported @@ -35,15 +35,15 @@ try to keep the codebase consistent and clean. Every so often, your PR will lag behind `master` and get conflicts. To "update" your branch `my-awesome-feature`, you *rebase* it onto -the latest `radareorg/master`, and *force-push* the result into your fork. +the latest `rizinorg/master`, and *force-push* the result into your fork. #### Step 1: Switch to `master` branch. $ git checkout master -#### Step 2: Pull new commits published to radareorg repo. +#### Step 2: Pull new commits published to rizinorg repo. - $ git pull https://github.com/radareorg/radare2 + $ git pull https://github.com/rizinorg/rizin #### Step 3: Switch back to `my-awesome-feature` branch. @@ -111,11 +111,11 @@ rules to make the git history more readable and consistent: * ##projects - saving/loading state * ##refactor - improve code quality * ##remote - r2 over tcp, http, rap, serial .. including collaboration -* ##search - rafind2, / command, .. +* ##search - rz_find, / command, .. * ##shell - commandline, newshell, .. * ##signatures-searching/generating them * ##test - testing infrastructure fixes/changes -* ##tools - r2pm, rarun2, rax2 ... that don't fit in other categories +* ##tools - rz-pm, rz_run, rz_ax ... that don't fit in other categories * ##util - core apis * ##visual - visual ui, including panels @@ -124,8 +124,8 @@ rules to make the git history more readable and consistent: * [README.md][] * [DEVELOPERS.md][] -[README.md]: https://github.com/radareorg/radare2/blob/master/README.md -[DEVELOPERS.md]: https://github.com/radareorg/radare2/blob/master/DEVELOPERS.md +[README.md]: https://github.com/rizinorg/rizin/blob/master/README.md +[DEVELOPERS.md]: https://github.com/rizinorg/rizin/blob/master/DEVELOPERS.md If you need more confidence in your git skills, check out this quick guide: diff --git a/DEVELOPERS.md b/DEVELOPERS.md index 934e4e8842..836f85eaec 100644 --- a/DEVELOPERS.md +++ b/DEVELOPERS.md @@ -1,7 +1,7 @@ # DEVELOPERS This file aims to describe an introduction for developers to work -on the code base of radare2 project. +on the code base of rizin project. ## Documentation There is support for Doxygen document generation in this repo. @@ -238,7 +238,7 @@ r_core_wrap.cxx:32103:61: error: assigning to 'RDebugReasonType' from incompatib * Do not use bashisms `[[`, `$'...'` etc. -* Use our [shellcheck.sh](https://github.com/radareorg/radare2/blob/master/sys/shellcheck.sh) script to check for problems and for bashisms +* Use our [shellcheck.sh](https://github.com/rizinorg/rizin/blob/master/sys/shellcheck.sh) script to check for problems and for bashisms # Manage Endianness @@ -310,7 +310,7 @@ setl cino=:0,+0,(2,J0,{1,}0,>4,)1,m2 Emacs: ```elisp -(c-add-style "radare2" +(c-add-style "rizin" '((c-basic-offset . 4) (tab-width . 4) (indent-tabs-mode . t) @@ -326,14 +326,14 @@ Emacs: You may use directory-local variables by putting ```elisp -((c-mode . ((c-file-style . "radare2")))) +((c-mode . ((c-file-style . "rizin")))) ``` into `.dir-locals.el`. ## Packed structures -Due to the various differences between platforms and compilers radare2 +Due to the various differences between platforms and compilers rizin has a special helper macro - `R_PACKED()`. Instead of non-portable `#pragma pack` or `__attribute__((packed))` it is advised to use this macro instead. To wrap the code inside of it you just need to write: @@ -353,8 +353,8 @@ R_PACKED (typedef structmystruct { ## Modules -The radare2 code base is modularized into different libraries that are -found in libr/ directory. The binr/ directory contains the programs +The rizin code base is modularized into different libraries that are +found in librz/ directory. The binrz/ directory contains the programs which use the libraries. It is possible to generate PIC/nonPIC builds of the libraries and also @@ -370,9 +370,9 @@ The following presentation gives a good overview of the libraries: As mentioned in README.md, the API itself is maintained in a different repository. The API function definitions in C header files are derived -from and documented in the radare2-bindings repository, found at: +from and documented in the rizin-bindings repository, found at: ```sh - git clone git://github.com/radareorg/radare2-bindings + git clone git://github.com/rizinorg/rizin-bindings ``` Currently the process of updating the header files from changed API @@ -386,7 +386,7 @@ very welcome. ## Dependencies -radare2 can be built without any special dependency. It just requires +rizin can be built without any special dependency. It just requires a C compiler, a GNU make and a unix-like system. ## Cross compilation @@ -404,11 +404,11 @@ linux-arm and others, but the procedure is like this: ## Source repository -The source of radare2 can be found in the following GitHub repository. +The source of rizin can be found in the following GitHub repository. ```sh - git clone git://github.com/radareorg/radare2 + git clone git://github.com/rizinorg/rizin ``` -Other packages radare2 depends on, such as Capstone, are pulled from +Other packages rizin depends on, such as Capstone, are pulled from their git repository as required. To get an up-to-date copy of the repository, you should perform the @@ -446,7 +446,7 @@ you should use ccache in this way: Developers use to modify the code, type make and then try. -radare2 has a specific makefile target that allows you to install +rizin has a specific makefile target that allows you to install system wide but using symlinks instead of hard copies. ```sh sudo make symstall @@ -459,11 +459,11 @@ in the code for various reasons. ## Regression testing -The source of the radare2 regression test suite can be found in the +The source of the rizin regression test suite can be found in the `test/` directory, while binaries for this test are located in the following GitHub repository. ```sh - git clone git://github.com/radareorg/radare2-testbins + git clone git://github.com/rizinorg/rizin-testbins ``` See the `README.md` file in that repository for further information. @@ -478,7 +478,7 @@ don't know how to do something which is supposed to be covered by this framework. You should report it into the GitHub issues page. - https://github.com/radareorg/radare2/issues + https://github.com/rizinorg/rizin/issues Otherwise, if you are looking for some more feedback, I will encourage you to send an email to any of the emails enumerated @@ -509,6 +509,6 @@ to contribute. - `make` - `make dist` - - Update the [paths on the website](https://github.com/radareorg/radareorg/blob/master/source/download_paths.rst) + - Update the [paths on the website](https://github.com/rizinorg/rizinorg/blob/master/source/download_paths.rst) --pancake diff --git a/Dockerfile b/Dockerfile index a37f6aa13e..73b4a4830a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,12 +46,12 @@ RUN echo -e "Building versions:\n\ R2_VERSION=$R2_VERSION\n\ R2_PIPE_PY_VERSION=${R2_PIPE_PY_VERSION}" -# Build radare2 in a volume to minimize space used by build +# Build rizin in a volume to minimize space used by build VOLUME ["/mnt"] # Install all build dependencies # Install bindings -# Build and install radare2 on master branch +# Build and install rizin on master branch # Remove all build dependencies # Cleanup RUN DEBIAN_FRONTEND=noninteractive dpkg --add-architecture i386 && \ @@ -70,10 +70,10 @@ RUN DEBIAN_FRONTEND=noninteractive dpkg --add-architecture i386 && \ libstdc++6:i386 \ gnupg2 \ python-pip && \ - pip install r2pipe=="$R2_PIPE_PY_VERSION" && \ + pip install rzpipe=="$R2_PIPE_PY_VERSION" && \ cd /mnt && \ - git clone -b "$R2_VERSION" -q --depth 1 https://github.com/radareorg/radare2.git && \ - cd radare2 && \ + git clone -b "$R2_VERSION" -q --depth 1 https://github.com/rizinorg/rizin.git && \ + cd rizin && \ ./configure && \ make && \ make install && \ @@ -95,9 +95,9 @@ USER r2 WORKDIR /home/r2 ENV HOME /home/r2 -# Setup r2pm -RUN r2pm init && \ - r2pm update && \ +# Setup rz-pm +RUN rz-pm init && \ + rz-pm update && \ chown -R r2:r2 /home/r2/.config # Base command for container diff --git a/Dockerfile.travis b/Dockerfile.travis index dcd3d8ae06..84638e482c 100644 --- a/Dockerfile.travis +++ b/Dockerfile.travis @@ -34,6 +34,6 @@ RUN apt-get install -y \ RUN pip3 install meson RUN pip3 install ninja -RUN pip3 install 'git+https://github.com/radareorg/radare2-r2pipe#egg=r2pipe&subdirectory=python' +RUN pip3 install 'git+https://github.com/rizinorg/rizin-rzpipe#egg=rzpipe&subdirectory=python' CMD [] diff --git a/Makefile b/Makefile index 20910976fc..e2ca4d3836 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,13 @@ L=$(DESTDIR)$(LIBDIR) MESON?=meson PYTHON?=python R2R=test -R2BINS=$(shell cd binr ; echo r*2 r2agent r2pm r2-indent r2r) +R2BINS=$(shell cd binrz ; echo r*2 rz_agent rz-pm r2-indent rz_test) ifdef SOURCE_DATE_EPOCH BUILDSEC=$(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "+__%H:%M:%S" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "+__%H:%M:%S" 2>/dev/null || date -u "+__%H:%M:%S") else BUILDSEC=$(shell date "+__%H:%M:%S") endif -DATADIRS=libr/cons/d libr/flag/d libr/bin/d libr/asm/d libr/syscall/d libr/magic/d libr/anal/d +DATADIRS=librz/cons/d librz/flag/d librz/bin/d librz/asm/d librz/syscall/d librz/magic/d librz/anal/d USE_ZIP=YES ZIP=zip @@ -52,16 +52,16 @@ endif endif endif -all: plugins.cfg libr/include/r_version.h +all: plugins.cfg librz/include/rz_version.h ${MAKE} -C shlr sdbs ${MAKE} -C shlr/zip - ${MAKE} -C libr/util - ${MAKE} -C libr/socket + ${MAKE} -C librz/util + ${MAKE} -C librz/socket ${MAKE} -C shlr - ${MAKE} -C libr - ${MAKE} -C binr + ${MAKE} -C librz + ${MAKE} -C binrz -#.PHONY: libr/include/r_version.h +#.PHONY: librz/include/rz_version.h GIT_TAP=$(shell git describe --tags --match "[0-9]*" 2>/dev/null || echo $(VERSION)) GIT_TIP=$(shell git rev-parse HEAD 2>/dev/null || echo HEAD) R2_VER=$(shell grep VERSION configure.acr | head -n1 | awk '{print $$2}') @@ -71,8 +71,8 @@ else GIT_NOW=$(shell date "+%Y-%m-%d") endif -libr/include/r_version.h: - @echo Generating r_version.h file +librz/include/rz_version.h: + @echo Generating rz_version.h file @echo $(Q)#ifndef R_VERSION_H$(Q) > $@.tmp @echo $(Q)#define R_VERSION_H 1$(Q) >> $@.tmp @echo $(Q)#define R2_VERSION_COMMIT $(R2VC)$(Q) >> $@.tmp @@ -97,7 +97,7 @@ w32: sys/mingw32.sh depgraph.png: - cd libr ; perl depgraph.pl dot | dot -Tpng -o../depgraph.png + cd librz ; perl depgraph.pl dot | dot -Tpng -o../depgraph.png android: @if [ -z "$(NDK_ARCH)" ]; then echo "Set NDK_ARCH=[arm|arm64|mips|x86]" ; false; fi @@ -110,17 +110,17 @@ w64dist: ${MAKE} windist WINBITS=w64 WINDIST=${WINBITS}dist -ZIPNAME?=radare2-${WINBITS}-${VERSION}.zip +ZIPNAME?=rizin-${WINBITS}-${VERSION}.zip C=$(shell printf "\033[32m") R=$(shell printf "\033[0m") windist: @echo "${C}[WINDIST] Installing binaries and libraries${R}" [ -n "${WINBITS}" ] || exit 1 - rm -rf "radare2-${WINBITS}-${VERSION}" "${WINDIST}" + rm -rf "rizin-${WINBITS}-${VERSION}" "${WINDIST}" mkdir "${WINDIST}" - for FILE in `find libr | grep -e dll$$`; do cp "$$FILE" "${WINDIST}" ; done - for FILE in `find binr | grep -e exe$$`; do cp "$$FILE" "${WINDIST}" ; done + for FILE in `find librz | grep -e dll$$`; do cp "$$FILE" "${WINDIST}" ; done + for FILE in `find binrz | grep -e exe$$`; do cp "$$FILE" "${WINDIST}" ; done rm -f "${WINDIST}/plugin.dll" @echo "${C}[WINDIST] Picking plugins from libraries${R}" mkdir -p "${WINDIST}/libs" @@ -134,65 +134,65 @@ windist: @echo "${C}[WINDIST] Copying web interface${R}" mkdir -p "${WINDIST}/www" cp -rf shlr/www/* "${WINDIST}/www" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/magic" - cp -f libr/magic/d/default/* "${WINDIST}/share/radare2/${VERSION}/magic" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/syscall" - cp -f libr/syscall/d/*.sdb "${WINDIST}/share/radare2/${VERSION}/syscall" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/sysregs" - cp -f libr/sysregs/d/*.sdb "${WINDIST}/share/radare2/${VERSION}/sysregs" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/fcnsign" - cp -f libr/anal/d/*.sdb "${WINDIST}/share/radare2/${VERSION}/fcnsign" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/opcodes" - cp -f libr/asm/d/*.sdb "${WINDIST}/share/radare2/${VERSION}/opcodes" - mkdir -p "${WINDIST}/share/radare2/${VERSION}/flag" - cp -f libr/flag/d/*.r2 "${WINDIST}/share/radare2/${VERSION}/flag" - mkdir -p "${WINDIST}/share/doc/radare2" - mkdir -p "${WINDIST}/include/libr/sdb" - mkdir -p "${WINDIST}/include/libr/r_util" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/magic" + cp -f librz/magic/d/default/* "${WINDIST}/share/rizin/${VERSION}/magic" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/syscall" + cp -f librz/syscall/d/*.sdb "${WINDIST}/share/rizin/${VERSION}/syscall" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/sysregs" + cp -f librz/sysregs/d/*.sdb "${WINDIST}/share/rizin/${VERSION}/sysregs" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/fcnsign" + cp -f librz/anal/d/*.sdb "${WINDIST}/share/rizin/${VERSION}/fcnsign" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/opcodes" + cp -f librz/asm/d/*.sdb "${WINDIST}/share/rizin/${VERSION}/opcodes" + mkdir -p "${WINDIST}/share/rizin/${VERSION}/flag" + cp -f librz/flag/d/*.r2 "${WINDIST}/share/rizin/${VERSION}/flag" + mkdir -p "${WINDIST}/share/doc/rizin" + mkdir -p "${WINDIST}/include/librz/sdb" + mkdir -p "${WINDIST}/include/librz/rz_util" @echo "${C}[WINDIST] Copying development files${R}" - cp -f shlr/sdb/src/*.h "${WINDIST}/include/libr/sdb/" - cp -f libr/include/r_util/*.h "${WINDIST}/include/libr/r_util/" - cp -f libr/include/*.h "${WINDIST}/include/libr" - #mkdir -p "${WINDIST}/include/libr/sflib" - @cp -f doc/fortunes.* "${WINDIST}/share/doc/radare2" - @mkdir -p "${WINDIST}/share/radare2/${VERSION}/format/dll" - @cp -f libr/bin/d/elf32 "${WINDIST}/share/radare2/${VERSION}/format" - @cp -f libr/bin/d/elf64 "${WINDIST}/share/radare2/${VERSION}/format" - @cp -f libr/bin/d/elf_enums "${WINDIST}/share/radare2/${VERSION}/format" - @cp -f libr/bin/d/pe32 "${WINDIST}/share/radare2/${VERSION}/format" - @cp -f libr/bin/d/trx "${WINDIST}/share/radare2/${VERSION}/format" - @cp -f libr/bin/d/dll/*.sdb "${WINDIST}/share/radare2/${VERSION}/format/dll" - @mkdir -p "${WINDIST}/share/radare2/${VERSION}/cons" - @cp -PRpf libr/cons/d/* "${WINDIST}/share/radare2/${VERSION}/cons" - @mkdir -p "${WINDIST}/share/radare2/${VERSION}/hud" - @cp -f doc/hud "${WINDIST}/share/radare2/${VERSION}/hud/main" - @mv "${WINDIST}" "radare2-${WINBITS}-${VERSION}" - @rm -f "radare2-${WINBITS}-${VERSION}.zip" + cp -f shlr/sdb/src/*.h "${WINDIST}/include/librz/sdb/" + cp -f librz/include/rz_util/*.h "${WINDIST}/include/librz/rz_util/" + cp -f librz/include/*.h "${WINDIST}/include/librz" + #mkdir -p "${WINDIST}/include/librz/sflib" + @cp -f doc/fortunes.* "${WINDIST}/share/doc/rizin" + @mkdir -p "${WINDIST}/share/rizin/${VERSION}/format/dll" + @cp -f librz/bin/d/elf32 "${WINDIST}/share/rizin/${VERSION}/format" + @cp -f librz/bin/d/elf64 "${WINDIST}/share/rizin/${VERSION}/format" + @cp -f librz/bin/d/elf_enums "${WINDIST}/share/rizin/${VERSION}/format" + @cp -f librz/bin/d/pe32 "${WINDIST}/share/rizin/${VERSION}/format" + @cp -f librz/bin/d/trx "${WINDIST}/share/rizin/${VERSION}/format" + @cp -f librz/bin/d/dll/*.sdb "${WINDIST}/share/rizin/${VERSION}/format/dll" + @mkdir -p "${WINDIST}/share/rizin/${VERSION}/cons" + @cp -PRpf librz/cons/d/* "${WINDIST}/share/rizin/${VERSION}/cons" + @mkdir -p "${WINDIST}/share/rizin/${VERSION}/hud" + @cp -f doc/hud "${WINDIST}/share/rizin/${VERSION}/hud/main" + @mv "${WINDIST}" "rizin-${WINBITS}-${VERSION}" + @rm -f "rizin-${WINBITS}-${VERSION}.zip" ifneq ($(USE_ZIP),NO) - $(ZIP) -r "${ZIPNAME}" "radare2-${WINBITS}-${VERSION}" + $(ZIP) -r "${ZIPNAME}" "rizin-${WINBITS}-${VERSION}" endif clean: - rm -f libr/libr.a libr/libr.dylib libr/include/r_version.h - rm -rf libr/.libr - for DIR in shlr libr binr ; do $(MAKE) -C "$$DIR" clean ; done + rm -f librz/librz.a librz/librz.dylib librz/include/rz_version.h + rm -rf librz/.librz + for DIR in shlr librz binrz ; do $(MAKE) -C "$$DIR" clean ; done -rm -f `find . -type f -name '*.d'` rm -f `find . -type f -name '*.o'` - rm -f config-user.mk plugins.cfg libr/config.h - rm -f libr/include/r_userconf.h libr/config.mk + rm -f config-user.mk plugins.cfg librz/config.h + rm -f librz/include/rz_userconf.h librz/config.mk rm -f pkgcfg/*.pc distclean mrproper: clean rm -f `find . -type f -iname '*.d'` pkgcfg: - cd libr && ${MAKE} pkgcfg + cd librz && ${MAKE} pkgcfg install-man: mkdir -p "${DESTDIR}${MANDIR}/man1" mkdir -p "${DESTDIR}${MANDIR}/man7" for FILE in man/*.1 ; do ${INSTALL_MAN} "$$FILE" "${DESTDIR}${MANDIR}/man1" ; done - cd "${DESTDIR}${MANDIR}/man1" && ln -fs radare2.1 r2.1 + cd "${DESTDIR}${MANDIR}/man1" && ln -fs rizin.1 r2.1 for FILE in man/*.7 ; do ${INSTALL_MAN} "$$FILE" "${DESTDIR}${MANDIR}/man7" ; done install-man-symlink: @@ -200,7 +200,7 @@ install-man-symlink: mkdir -p "${DESTDIR}${MANDIR}/man7" for FILE in $(shell cd man && ls *.1) ; do \ ln -fs "${PWD}/man/$$FILE" "${DESTDIR}${MANDIR}/man1/$$FILE" ; done - cd "${DESTDIR}${MANDIR}/man1" && ln -fs radare2.1 r2.1 + cd "${DESTDIR}${MANDIR}/man1" && ln -fs rizin.1 r2.1 for FILE in *.7 ; do \ ln -fs "${PWD}/man/$$FILE" "${DESTDIR}${MANDIR}/man7/$$FILE" ; done @@ -219,33 +219,33 @@ install-doc-symlink: ln -fs "$(PWD)/doc/$$FILE" "${DESTDIR}${DOCDIR}" ; done install love: install-doc install-man install-www install-pkgconfig - cd libr && ${MAKE} install - cd binr && ${MAKE} install + cd librz && ${MAKE} install + cd binrz && ${MAKE} install cd shlr && ${MAKE} install for DIR in ${DATADIRS} ; do $(MAKE) -C "$$DIR" install ; done - cd "$(DESTDIR)$(LIBDIR)/radare2/" ;\ + cd "$(DESTDIR)$(LIBDIR)/rizin/" ;\ rm -f last ; ln -fs $(VERSION) last - cd "$(DESTDIR)$(DATADIR)/radare2/" ;\ + cd "$(DESTDIR)$(DATADIR)/rizin/" ;\ rm -f last ; ln -fs $(VERSION) last - rm -rf "${DESTDIR}${DATADIR}/radare2/${VERSION}/hud" - mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/hud" + rm -rf "${DESTDIR}${DATADIR}/rizin/${VERSION}/hud" + mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/hud" mkdir -p "${DESTDIR}${BINDIR}" #${INSTALL_SCRIPT} "${PWD}/sys/indent.sh" "${DESTDIR}${BINDIR}/r2-indent" - #${INSTALL_SCRIPT} "${PWD}/sys/r1-docker.sh" "${DESTDIR}${BINDIR}/r2-docker" - cp -f doc/hud "${DESTDIR}${DATADIR}/radare2/${VERSION}/hud/main" - mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/" + #${INSTALL_SCRIPT} "${PWD}/sys/r1-docker.sh" "${DESTDIR}${BINDIR}/rz-docker" + cp -f doc/hud "${DESTDIR}${DATADIR}/rizin/${VERSION}/hud/main" + mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/" $(SHELL) sys/ldconfig.sh - $(SHELL) ./configure-plugins --rm-static $(DESTDIR)$(LIBDIR)/radare2/last/ + $(SHELL) ./configure-plugins --rm-static $(DESTDIR)$(LIBDIR)/rizin/last/ install-www: rm -rf "${DESTDIR}${WWWROOT}" - rm -rf "${DESTDIR}${LIBDIR}/radare2/${VERSION}/www" # old dir + rm -rf "${DESTDIR}${LIBDIR}/rizin/${VERSION}/www" # old dir mkdir -p "${DESTDIR}${WWWROOT}" cp -rf shlr/www/* "${DESTDIR}${WWWROOT}" symstall-www: rm -rf "${DESTDIR}${WWWROOT}" - rm -rf "${DESTDIR}${LIBDIR}/radare2/${VERSION}/www" # old dir + rm -rf "${DESTDIR}${LIBDIR}/rizin/${VERSION}/www" # old dir mkdir -p "${DESTDIR}${WWWROOT}" for FILE in $(shell cd shlr/www ; ls) ; do \ ln -fs "$(PWD)/shlr/www/$$FILE" "$(DESTDIR)$(WWWROOT)" ; done @@ -269,32 +269,32 @@ symstall-sdb: done symstall install-symlink: install-man-symlink install-doc-symlink install-pkgconfig-symlink symstall-www symstall-sdb - cd libr && ${MAKE} install-symlink - cd binr && ${MAKE} install-symlink + cd librz && ${MAKE} install-symlink + cd binrz && ${MAKE} install-symlink cd shlr && ${MAKE} install-symlink mkdir -p "${DESTDIR}${BINDIR}" ln -fs "${PWD}/sys/indent.sh" "${DESTDIR}${BINDIR}/r2-indent" - ln -fs "${PWD}/sys/r2-docker.sh" "${DESTDIR}${BINDIR}/r2-docker" - mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/hud" - ln -fs "${PWD}/doc/hud" "${DESTDIR}${DATADIR}/radare2/${VERSION}/hud/main" - #mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/flag" - #ln -fs $(PWD)/libr/flag/d/tags.r2 "${DESTDIR}${DATADIR}/radare2/${VERSION}/flag/tags.r2" - cd "$(DESTDIR)$(LIBDIR)/radare2/" ;\ + ln -fs "${PWD}/sys/rz-docker.sh" "${DESTDIR}${BINDIR}/rz-docker" + mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/hud" + ln -fs "${PWD}/doc/hud" "${DESTDIR}${DATADIR}/rizin/${VERSION}/hud/main" + #mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/flag" + #ln -fs $(PWD)/librz/flag/d/tags.r2 "${DESTDIR}${DATADIR}/rizin/${VERSION}/flag/tags.r2" + cd "$(DESTDIR)$(LIBDIR)/rizin/" ;\ rm -f last ; ln -fs $(VERSION) last - cd "$(DESTDIR)$(DATADIR)/radare2/" ;\ + cd "$(DESTDIR)$(DATADIR)/rizin/" ;\ rm -f last ; ln -fs $(VERSION) last - mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/" + mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/" $(SHELL) sys/ldconfig.sh - $(SHELL) ./configure-plugins --rm-static $(DESTDIR)/$(LIBDIR)/radare2/last/ + $(SHELL) ./configure-plugins --rm-static $(DESTDIR)/$(LIBDIR)/rizin/last/ deinstall uninstall: rm -f $(DESTDIR)$(BINDIR)/r2-indent - rm -f $(DESTDIR)$(BINDIR)/r2-docker - cd libr && ${MAKE} uninstall - cd binr && ${MAKE} uninstall + rm -f $(DESTDIR)$(BINDIR)/rz-docker + cd librz && ${MAKE} uninstall + cd binrz && ${MAKE} uninstall cd shlr && ${MAKE} uninstall - cd libr/syscall/d && ${MAKE} uninstall - cd libr/anal/d && ${MAKE} uninstall + cd librz/syscall/d && ${MAKE} uninstall + cd librz/anal/d && ${MAKE} uninstall @echo @echo "Run 'make purge' to also remove installed files from previous versions of r2" @echo @@ -311,7 +311,7 @@ user-wrap=echo "\#!/bin/sh" > ~/bin/"$1" \ user-install: mkdir -p ~/bin $(foreach mod,$(R2BINS),$(call user-wrap,$(mod))) - cd ~/bin ; ln -fs radare2 r2 + cd ~/bin ; ln -fs rizin r2 user-uninstall: $(foreach mod,$(R2BINS),rm -f ~/bin/"$(mod)") @@ -319,36 +319,36 @@ user-uninstall: -rmdir ~/bin purge-dev: - rm -f "${DESTDIR}${LIBDIR}/libr_"*".${EXT_AR}" - rm -f "${DESTDIR}${LIBDIR}/pkgconfig/r_"*.pc - rm -rf "${DESTDIR}${INCLUDEDIR}/libr" - rm -f "${DESTDIR}${LIBDIR}/radare2/${VERSION}/-"* + rm -f "${DESTDIR}${LIBDIR}/librz_"*".${EXT_AR}" + rm -f "${DESTDIR}${LIBDIR}/pkgconfig/rz_"*.pc + rm -rf "${DESTDIR}${INCLUDEDIR}/librz" + rm -f "${DESTDIR}${LIBDIR}/rizin/${VERSION}/-"* # required for EXT_SO -include libr/config.mk +include librz/config.mk strip: #-for FILE in ${R2BINS} ; do ${STRIP} -s "${DESTDIR}${BINDIR}/$$FILE" 2> /dev/null ; done ifeq ($(HOST_OS),darwin) - -${STRIP} -STxX "${DESTDIR}${LIBDIR}/libr_"*".${EXT_SO}" + -${STRIP} -STxX "${DESTDIR}${LIBDIR}/librz_"*".${EXT_SO}" else - -${STRIP} -s "${DESTDIR}${LIBDIR}/libr_"*".${EXT_SO}" + -${STRIP} -s "${DESTDIR}${LIBDIR}/librz_"*".${EXT_SO}" endif purge: purge-doc purge-dev user-uninstall for FILE in ${R2BINS} ; do rm -f "${DESTDIR}${BINDIR}/$$FILE" ; done - rm -f "${DESTDIR}${BINDIR}/ragg2-cc" + rm -f "${DESTDIR}${BINDIR}/rz_gg-cc" rm -f "${DESTDIR}${BINDIR}/r2" - rm -f "${DESTDIR}${LIBDIR}/libr_"* - rm -f "${DESTDIR}${LIBDIR}/libr2"*".${EXT_SO}" - rm -rf "${DESTDIR}${LIBDIR}/radare2" - rm -rf "${DESTDIR}${INCLUDEDIR}/libr" - rm -rf "${DESTDIR}${DATADIR}/radare2" + rm -f "${DESTDIR}${LIBDIR}/librz_"* + rm -f "${DESTDIR}${LIBDIR}/librz"*".${EXT_SO}" + rm -rf "${DESTDIR}${LIBDIR}/rizin" + rm -rf "${DESTDIR}${INCLUDEDIR}/librz" + rm -rf "${DESTDIR}${DATADIR}/rizin" system-purge: purge sys/purge.sh -R2V=radare2-${VERSION} +R2V=rizin-${VERSION} v ver version: @echo CURRENT=${VERSION} @@ -362,8 +362,8 @@ dist: $(MAKE) -C $(R2V)/shlr capstone-sync FILES=`cd $(R2V); git ls-files | sed -e "s,^,$(R2V)/,"` ; \ CS_FILES=`cd $(R2V)/shlr/capstone ; git ls-files | grep -v pdf | grep -v xcode | grep -v msvc | grep -v suite | grep -v bindings | grep -v tests | sed -e "s,^,$(R2V)/shlr/capstone/,"` ; \ - ${TAR} "radare2-${VERSION}.tar" $${FILES} $${CS_FILES} "$(R2V)/ChangeLog" ; \ - ${CZ} "radare2-${VERSION}.tar" + ${TAR} "rizin-${VERSION}.tar" $${FILES} $${CS_FILES} "$(R2V)/ChangeLog" ; \ + ${CZ} "rizin-${VERSION}.tar" olddist: -[ configure -nt config-user.mk ] && ./configure "--prefix=${PREFIX}" @@ -372,31 +372,31 @@ olddist: cd shlr && ${MAKE} capstone-sync $(MAKE) -R capstone.ps DIR=`basename "$$PWD"` ; \ - FILES=`git ls-files | sed -e "s,^,radare2-${VERSION}/,"` ; \ - CS_FILES=`cd shlr/capstone ; git ls-files | grep -v pdf | grep -v xcode | grep -v msvc | grep -v suite | grep -v bindings | grep -v tests | sed -e "s,^,radare2-${VERSION}/shlr/capstone/,"` ; \ - cd .. && mv "$${DIR}" "radare2-${VERSION}" && \ - ${TAR} "radare2-${VERSION}.tar" $${FILES} $${CS_FILES} "radare2-${VERSION}/ChangeLog" ; \ - ${CZ} "radare2-${VERSION}.tar" ; \ - mv "radare2-${VERSION}" "$${DIR}" + FILES=`git ls-files | sed -e "s,^,rizin-${VERSION}/,"` ; \ + CS_FILES=`cd shlr/capstone ; git ls-files | grep -v pdf | grep -v xcode | grep -v msvc | grep -v suite | grep -v bindings | grep -v tests | sed -e "s,^,rizin-${VERSION}/shlr/capstone/,"` ; \ + cd .. && mv "$${DIR}" "rizin-${VERSION}" && \ + ${TAR} "rizin-${VERSION}.tar" $${FILES} $${CS_FILES} "rizin-${VERSION}/ChangeLog" ; \ + ${CZ} "rizin-${VERSION}.tar" ; \ + mv "rizin-${VERSION}" "$${DIR}" shot: DATE=`date '+%Y%m%d'` ; \ - FILES=`git ls-files | sed -e "s,^,radare2-${DATE}/,"` ; \ - cd .. && mv radare2 "radare2-$${DATE}" && \ - ${TAR} "radare2-$${DATE}.tar" $${FILES} ;\ - ${CZ} "radare2-$${DATE}.tar" ;\ - mv "radare2-$${DATE}" radare2 && \ - scp "radare2-$${DATE}.${TAREXT}" \ - radare.org:/srv/http/radareorg/get/shot + FILES=`git ls-files | sed -e "s,^,rizin-${DATE}/,"` ; \ + cd .. && mv rizin "rizin-$${DATE}" && \ + ${TAR} "rizin-$${DATE}.tar" $${FILES} ;\ + ${CZ} "rizin-$${DATE}.tar" ;\ + mv "rizin-$${DATE}" rizin && \ + scp "rizin-$${DATE}.${TAREXT}" \ + radare.org:/srv/http/rizinorg/get/shot tests: $(MAKE) -C $(R2R) macos-sign: - $(MAKE) -C binr/radare2 macos-sign + $(MAKE) -C binrz/rizin macos-sign macos-sign-libs: - $(MAKE) -C binr/radare2 macos-sign-libs + $(MAKE) -C binrz/rizin macos-sign-libs osx-pkg: sys/osx-pkg.sh $(VERSION) @@ -416,33 +416,33 @@ meson-install: meson-symstall: symstall-sdb @echo "[ Meson symstall (not stable) ]" - ln -fs $(PWD)/binr/r2pm/r2pm ${B}/r2pm - ln -fs $(PWD)/build/binr/rasm2/rasm2 ${B}/rasm2 - ln -fs $(PWD)/build/binr/rarun2/rarun2 ${B}/rarun2 - ln -fs $(PWD)/build/binr/radare2/radare2 ${B}/radare2 - ln -fs $(PWD)/build/binr/rahash2/rahash2 ${B}/rahash2 - ln -fs $(PWD)/build/binr/rabin2/rabin2 ${B}/rabin2 - ln -fs $(PWD)/build/binr/radare2/radare2 ${B}/radare2 - ln -fs $(PWD)/build/binr/ragg2/ragg2 ${B}/ragg2 - cd $(B) && ln -fs radare2 r2 - ln -fs $(PWD)/build/libr/util/libr_util.$(EXT_SO) ${L}/libr_util.$(EXT_SO) - ln -fs $(PWD)/build/libr/bp/libr_bp.$(EXT_SO) ${L}/libr_bp.$(EXT_SO) - ln -fs $(PWD)/build/libr/syscall/libr_syscall.$(EXT_SO) ${L}/libr_syscall.$(EXT_SO) - ln -fs $(PWD)/build/libr/cons/libr_cons.$(EXT_SO) ${L}/libr_cons.$(EXT_SO) - ln -fs $(PWD)/build/libr/search/libr_search.$(EXT_SO) ${L}/libr_search.$(EXT_SO) - ln -fs $(PWD)/build/libr/magic/libr_magic.$(EXT_SO) ${L}/libr_magic.$(EXT_SO) - ln -fs $(PWD)/build/libr/flag/libr_flag.$(EXT_SO) ${L}/libr_flag.$(EXT_SO) - ln -fs $(PWD)/build/libr/reg/libr_reg.$(EXT_SO) ${L}/libr_reg.$(EXT_SO) - ln -fs $(PWD)/build/libr/bin/libr_bin.$(EXT_SO) ${L}/libr_bin.$(EXT_SO) - ln -fs $(PWD)/build/libr/config/libr_config.$(EXT_SO) ${L}/libr_config.$(EXT_SO) - ln -fs $(PWD)/build/libr/parse/libr_parse.$(EXT_SO) ${L}/libr_parse.$(EXT_SO) - ln -fs $(PWD)/build/libr/lang/libr_lang.$(EXT_SO) ${L}/libr_lang.$(EXT_SO) - ln -fs $(PWD)/build/libr/asm/libr_asm.$(EXT_SO) ${L}/libr_asm.$(EXT_SO) - ln -fs $(PWD)/build/libr/anal/libr_anal.$(EXT_SO) ${L}/libr_anal.$(EXT_SO) - ln -fs $(PWD)/build/libr/egg/libr_egg.$(EXT_SO) ${L}/libr_egg.$(EXT_SO) - ln -fs $(PWD)/build/libr/fs/libr_fs.$(EXT_SO) ${L}/libr_fs.$(EXT_SO) - ln -fs $(PWD)/build/libr/debug/libr_debug.$(EXT_SO) ${L}/libr_debug.$(EXT_SO) - ln -fs $(PWD)/build/libr/core/libr_core.$(EXT_SO) ${L}/libr_core.$(EXT_SO) + ln -fs $(PWD)/binrz/rz_pm/rz-pm ${B}/rz-pm + ln -fs $(PWD)/build/binrz/rz_asm/rz_asm ${B}/rz_asm + ln -fs $(PWD)/build/binrz/rz_run/rz_run ${B}/rz_run + ln -fs $(PWD)/build/binrz/rizin/rizin ${B}/rizin + ln -fs $(PWD)/build/binrz/rz_hash/rz_hash ${B}/rz_hash + ln -fs $(PWD)/build/binrz/rz_bin/rz_bin ${B}/rz_bin + ln -fs $(PWD)/build/binrz/rizin/rizin ${B}/rizin + ln -fs $(PWD)/build/binrz/rz_gg/rz_gg ${B}/rz_gg + cd $(B) && ln -fs rizin r2 + ln -fs $(PWD)/build/librz/util/librz_util.$(EXT_SO) ${L}/librz_util.$(EXT_SO) + ln -fs $(PWD)/build/librz/bp/librz_bp.$(EXT_SO) ${L}/librz_bp.$(EXT_SO) + ln -fs $(PWD)/build/librz/syscall/librz_syscall.$(EXT_SO) ${L}/librz_syscall.$(EXT_SO) + ln -fs $(PWD)/build/librz/cons/librz_cons.$(EXT_SO) ${L}/librz_cons.$(EXT_SO) + ln -fs $(PWD)/build/librz/search/librz_search.$(EXT_SO) ${L}/librz_search.$(EXT_SO) + ln -fs $(PWD)/build/librz/magic/librz_magic.$(EXT_SO) ${L}/librz_magic.$(EXT_SO) + ln -fs $(PWD)/build/librz/flag/librz_flag.$(EXT_SO) ${L}/librz_flag.$(EXT_SO) + ln -fs $(PWD)/build/librz/reg/librz_reg.$(EXT_SO) ${L}/librz_reg.$(EXT_SO) + ln -fs $(PWD)/build/librz/bin/librz_bin.$(EXT_SO) ${L}/librz_bin.$(EXT_SO) + ln -fs $(PWD)/build/librz/config/librz_config.$(EXT_SO) ${L}/librz_config.$(EXT_SO) + ln -fs $(PWD)/build/librz/parse/librz_parse.$(EXT_SO) ${L}/librz_parse.$(EXT_SO) + ln -fs $(PWD)/build/librz/lang/librz_lang.$(EXT_SO) ${L}/librz_lang.$(EXT_SO) + ln -fs $(PWD)/build/librz/asm/librz_asm.$(EXT_SO) ${L}/librz_asm.$(EXT_SO) + ln -fs $(PWD)/build/librz/anal/librz_anal.$(EXT_SO) ${L}/librz_anal.$(EXT_SO) + ln -fs $(PWD)/build/librz/egg/librz_egg.$(EXT_SO) ${L}/librz_egg.$(EXT_SO) + ln -fs $(PWD)/build/librz/fs/librz_fs.$(EXT_SO) ${L}/librz_fs.$(EXT_SO) + ln -fs $(PWD)/build/librz/debug/librz_debug.$(EXT_SO) ${L}/librz_debug.$(EXT_SO) + ln -fs $(PWD)/build/librz/core/librz_core.$(EXT_SO) ${L}/librz_core.$(EXT_SO) meson-uninstall: ninja -C build uninstall @@ -452,7 +452,7 @@ meson-clean: rm -rf build rm -rf build_sdb -MESON_FILES=$(shell find build/libr build/binr -type f | grep -v @) +MESON_FILES=$(shell find build/librz build/binrz -type f | grep -v @) meson-symstall-experimental: for a in $(MESON_FILES) ; do echo ln -fs "$(PWD)/$$a" "$(PWD)/$$(echo $$a|sed -e s,build/,,)" ; done $(MAKE) symstall @@ -465,6 +465,6 @@ shlr/capstone: include ${MKPLUGINS} .PHONY: all clean install symstall uninstall deinstall strip -.PHONY: libr binr install-man w32dist tests dist shot pkgcfg depgraph.png love +.PHONY: librz binrz install-man w32dist tests dist shot pkgcfg depgraph.png love .PHONY: purge system-purge .PHONY: shlr/capstone diff --git a/README.md b/README.md index 69d1e8e067..f1c6157f6e 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,18 @@ | Service | Badge | |----------|---------------------------------------------------------------------| -| **GithubCI** | [![Tests Status](https://github.com/radareorg/radare2/workflows/Radare2%20CI/badge.svg)](https://github.com/radareorg/radare2/actions?query=workflow%3A%22Radare2+CI%22)| -| **TravisCI** | [![Build Status](https://travis-ci.com/radareorg/radare2.svg?branch=master)](https://travis-ci.com/radareorg/radare2)| -| **AppVeyor** | [![Build status](https://ci.appveyor.com/api/projects/status/9cgkgxkc3203fm1o/branch/master?svg=true)](https://ci.appveyor.com/project/radareorg/radare2/branch/master)| -| **FreeBSD (sr.ht)** | [![builds.sr.ht status](https://builds.sr.ht/~xvilka/radare2/commits/freebsd.yml.svg)](https://builds.sr.ht/~xvilka/radare2/commits/freebsd.yml?)| -| **OpenBSD (sr.ht)** | [![builds.sr.ht status](https://builds.sr.ht/~xvilka/radare2/commits/openbsd.yml.svg)](https://builds.sr.ht/~xvilka/radare2/commits/openbsd.yml?)| +| **GithubCI** | [![Tests Status](https://github.com/rizinorg/rizin/workflows/Radare2%20CI/badge.svg)](https://github.com/rizinorg/rizin/actions?query=workflow%3A%22Radare2+CI%22)| +| **TravisCI** | [![Build Status](https://travis-ci.com/rizinorg/rizin.svg?branch=master)](https://travis-ci.com/rizinorg/rizin)| +| **AppVeyor** | [![Build status](https://ci.appveyor.com/api/projects/status/9cgkgxkc3203fm1o/branch/master?svg=true)](https://ci.appveyor.com/project/rizinorg/rizin/branch/master)| +| **FreeBSD (sr.ht)** | [![builds.sr.ht status](https://builds.sr.ht/~xvilka/rizin/commits/freebsd.yml.svg)](https://builds.sr.ht/~xvilka/rizin/commits/freebsd.yml?)| +| **OpenBSD (sr.ht)** | [![builds.sr.ht status](https://builds.sr.ht/~xvilka/rizin/commits/openbsd.yml.svg)](https://builds.sr.ht/~xvilka/rizin/commits/openbsd.yml?)| | **Coverity** | [![Build Status](https://scan.coverity.com/projects/416/badge.svg)](https://scan.coverity.com/projects/416) | -| **LGTM** | [![Total alerts](https://img.shields.io/lgtm/alerts/g/radareorg/radare2.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/radareorg/radare2/alerts/) +| **LGTM** | [![Total alerts](https://img.shields.io/lgtm/alerts/g/rizinorg/rizin.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/rizinorg/rizin/alerts/) | **Infrastructure** | [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/741/badge)](https://bestpractices.coreinfrastructure.org/projects/741) | -| **Codecov** | [![codecov](https://codecov.io/gh/radareorg/radare2/branch/master/graph/badge.svg)](https://codecov.io/gh/radareorg/radare2) +| **Codecov** | [![codecov](https://codecov.io/gh/rizinorg/rizin/branch/master/graph/badge.svg)](https://codecov.io/gh/rizinorg/rizin) | **Fuzzit** | [![fuzzit](https://app.fuzzit.dev/badge?org_id=2zv5qI33roZkRm0oO2Mi&target_id=YVkkS6RPVpKhSixyFWcT&branch=master)](https://app.fuzzit.dev/admin/2zv5qI33roZkRm0oO2Mi/target) - -Packaging status + +Packaging status # Introduction @@ -35,9 +35,9 @@ command-line hexadecimal editor able to open disk files, but later added support for analyzing binaries, disassembling code, debugging programs, attaching to remote gdb servers... -radare2 is portable. +rizin is portable. -To learn more on radare2 you may want to read the [official radare2 book](https://book.rada.re). +To learn more on rizin you may want to read the [official rizin book](https://book.rada.re). You can also use [r2lrn](https://github.com/0ki/r2lrn) or r2golf for a hands-on learning experience. @@ -67,7 +67,7 @@ Game Boy (Advance), Nintendo DS ROMs and Nintendo 3DS FIRMs, various filesystems ## Scripting Native bindings are supported but the recommended way to interact with r2 -from other languages is by using [r2pipe](https://github.com/radareorg/radare2-r2pipe) +from other languages is by using [rzpipe](https://github.com/rizinorg/rizin-rzpipe) Python, Ruby, JavaScript, Lua, Perl, PHP, Go, Rust, Swift, C#, Java, Shell, OCaml, Haskell, Scheme (Guile), Common Lisp, Clojure, Erlang, D, @@ -75,7 +75,7 @@ Vala/Genie, Prolog, Nim, Newlisp... # Install / Update -The recommended way to install or update radare2 from git for single-user systems: +The recommended way to install or update rizin from git for single-user systems: $ sys/install.sh @@ -107,25 +107,25 @@ To remove all stuff including libraries, use ## Package Manager -Radare2 has its own package manager - r2pm. Its packages -repository is on [GitHub too](https://github.com/radareorg/radare2-pm). +Radare2 has its own package manager - rz-pm. Its packages +repository is on [GitHub too](https://github.com/rizinorg/rizin-pm). To start to using it for the first time, you need to initialize packages: - $ r2pm init + $ rz-pm init Refresh the packages database before installing any package: - $ r2pm update + $ rz-pm update To install a package, use the following command: - $ r2pm install [package name] + $ rz-pm install [package name] # Development ## Coding Style -Look at [CONTRIBUTING.md](https://github.com/radareorg/radare2/blob/master/CONTRIBUTING.md). +Look at [CONTRIBUTING.md](https://github.com/rizinorg/rizin/blob/master/CONTRIBUTING.md). ## Tests @@ -142,6 +142,6 @@ Website: [https://www.radare.org/](https://www.radare.org/) Telegram: [https://t.me/radare](https://t.me/radare) -Twitter: [@radareorg](https://twitter.com/radareorg) +Twitter: [@rizinorg](https://twitter.com/rizinorg) IRC: irc.freenode.net #radare diff --git a/Vagrantfile.sh b/Vagrantfile.sh index f346b8877c..ee31dc3f7c 100644 --- a/Vagrantfile.sh +++ b/Vagrantfile.sh @@ -3,5 +3,5 @@ # Updates sudo pacman -Syu -git clone --depth=1 https://github.com/radareorg/radare2 -cd radare2 && ./sys/install.sh +git clone --depth=1 https://github.com/rizinorg/rizin +cd rizin && ./sys/install.sh diff --git a/autogen.sh b/autogen.sh index e8db5f6d33..faf6e029eb 100755 --- a/autogen.sh +++ b/autogen.sh @@ -6,14 +6,14 @@ # # -- pancake -r2pm -h >/dev/null 2>&1 +rz-pm -h >/dev/null 2>&1 if [ $? = 0 ]; then echo "Installing the last version of 'acr'..." - r2pm -i acr > /dev/null - r2pm -r acr -h > /dev/null 2>&1 + rz-pm -i acr > /dev/null + rz-pm -r acr -h > /dev/null 2>&1 if [ $? = 0 ]; then echo "Running 'acr -p'..." - r2pm -r acr -p + rz-pm -r acr -p else echo "Cannot find 'acr' in PATH" fi diff --git a/binr/Makefile b/binr/Makefile deleted file mode 100644 index 5ccdb2e6f3..0000000000 --- a/binr/Makefile +++ /dev/null @@ -1,78 +0,0 @@ -include ../global.mk -include ../libr/config.mk - -DESTDIR:=$(DESTDIR) -BTOP=$(shell pwd) - -.PHONY: all clean install install-symlink deinstall uninstall mrproper preload - -BINS=rax2 rasm2 rabin2 rahash2 radiff2 radare2 rafind2 rarun2 ragg2 r2agent rasign2 - -ifeq ($(WANT_R2R),1) - BINS+=r2r -endif - -LIBR2=$(call libname-version,libr2.$(EXT_SO),${LIBVERSION}) - -all: preload - @for BINARY in $(BINS) ; do $(MAKE) -C $${BINARY} all || exit 1; done -ifeq ($(COMPILER),ios-sdk) - $(MAKE) ios-sign -endif - -preload: -ifeq ($(WITHPIC),1) - $(MAKE) -C preload -endif - -install: - mkdir -p "${DESTDIR}${BINDIR}" - for BINARY in ${BINS} ; do \ - rm -f "${DESTDIR}${BINDIR}/$$BINARY" ; \ - ${INSTALL_PROGRAM} "$$BINARY/$$BINARY" "${DESTDIR}${BINDIR}/$$BINARY" ; \ - done - ${INSTALL_SCRIPT} "$(BTOP)/r2pm/r2pm" "${DESTDIR}${BINDIR}/r2pm" - rm -rf "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm" - #mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm" - #cp -rf r2pm/d/* "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm" - -cd "${DESTDIR}${BINDIR}" && rm -f r2 ; ln -fs radare2 r2 ; ln -fs radare2 r2p -ifeq ($(WITHPIC),1) - ${INSTALL_LIB} "preload/libr2.$(EXT_SO)" "${DESTDIR}${LIBDIR}" - -cd "${DESTDIR}${LIBDIR}" && \ - mv libr2.$(EXT_SO) $(LIBR2) && \ - ln -fs $(LIBR2) libr2.$(EXT_SO) -endif - -ios_sign ios-sign ios-sdk-sign: - -for a in $(BINS) ; do xcrun --sdk iphoneos codesign -s- --entitlements radare2/radare2_ios.xml $$a ; done - -for a in ../libr/*/*.${EXT_SO} ; do xcrun --sdk iphoneos codesign -s- --entitlements radare2/radare2_ios.xml $$a ; done - -for a in ../libr/*/p/*.${EXT_SO} ; do xcrun --sdk iphoneos codesign -s- --entitlements radare2/radare2_ios.xml $$a ; done - -symstall install-symlink: - cd .. && \ - mkdir -p "${DESTDIR}${BINDIR}" && \ - for BINARY in ${BINS} ; do ln -fs "${BTOP}/$$BINARY/$$BINARY" "${DESTDIR}${BINDIR}/$$BINARY" ; done - cd .. && ln -fs "${BTOP}/r2pm/r2pm" "${DESTDIR}${BINDIR}/r2pm" - cd .. && rm -rf "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm" - cd .. && mkdir -p "${DESTDIR}${DATADIR}/radare2/${VERSION}/" - #ln -fs "$(BTOP)/r2pm/d" "${DESTDIR}${DATADIR}/radare2/${VERSION}/r2pm" - -cd .. && ln -fs "${DESTDIR}${BINDIR}/radare2" "${DESTDIR}${BINDIR}/r2" - -cd .. && ln -fs "${DESTDIR}${BINDIR}/radare2" "${DESTDIR}${BINDIR}/r2p" - -cd .. && ln -fs "${BTOP}/preload/libr2.$(EXT_SO)" "${DESTDIR}${LIBDIR}/libr2.$(EXT_SO)" - -cd .. && cd "${DESTDIR}${LIBDIR}" && \ - mv libr2.$(EXT_SO) $(LIBR2) && \ - ln -fs $(LIBR2) libr2.$(EXT_SO) - -deinstall uninstall: - -cd .. ; \ - for BINARY in ${BINS} ; do rm -f "${DESTDIR}${BINDIR}/$$BINARY" ; done ; \ - rm -f "${DESTDIR}${BINDIR}/r2pm" ; \ - rm -f "${DESTDIR}${BINDIR}/r2p" - rm -f "${DESTDIR}${BINDIR}/r2" - -clean: - @for DIR in preload ${BINS} ; do ${MAKE} -C $$DIR clean; done - -mrproper: - @for DIR in preload ${BINS} ; do ${MAKE} -C $$DIR mrproper; done - diff --git a/binr/blob/Makefile b/binr/blob/Makefile deleted file mode 100644 index a86c77eb07..0000000000 --- a/binr/blob/Makefile +++ /dev/null @@ -1,106 +0,0 @@ -PREFIX?=/usr -DESTDIR?=/ - -BINS=rabin2 rarun2 rasm2 ragg2 rahash2 rax2 rafind2 radiff2 -BINS2=radare2 ${BINS} - -SOURCES= main.c rabin2.c radare2.c radiff2.c rafind2.c -SOURCES+=rahash2.c rarun2.c rasm2.c rax2.c ragg2.c - -include ../../config-user.mk - -SHLR=../../shlr - -ifeq (${ANDROID},1) -LDFLAGS+=-lm -else -ifneq (${OSTYPE},linux) -LDFLAGS+=-lpthread -LDFLAGS+=-ldl -endif -endif -ifeq ($(USE_LTO),1) -LDFLAGS+=-flto -endif - -CFLAGS+=-I../../libr/include/ -CFLAGS+=-I$(SHLR)/spp - -LDFLAGS+=-L../../libr/main -lr_main -LDFLAGS+=-L../../libr/io -lr_io -LDFLAGS+=-L../../libr/bp -lr_bp -LDFLAGS+=-L../../libr/socket -lr_socket -LDFLAGS+=-L../../libr/bin -lr_bin -LDFLAGS+=-L../../libr/reg -lr_reg -LDFLAGS+=-L../../libr/asm -lr_asm -LDFLAGS+=-L../../libr/lang -lr_lang -LDFLAGS+=-L../../libr/egg -lr_egg -LDFLAGS+=-L../../libr/core -lr_core -LDFLAGS+=-L../../libr/anal -lr_anal -LDFLAGS+=-L../../libr/crypto -lr_crypto -LDFLAGS+=-L../../libr/flag -lr_flag -LDFLAGS+=-L../../libr/parse -lr_parse -LDFLAGS+=-L../../libr/fs -lr_fs -LDFLAGS+=-L../../libr/magic -lr_magic -LDFLAGS+=-L../../libr/syscall -lr_syscall -LDFLAGS+=-L../../libr/util -lr_util -LDFLAGS+=-L../../libr/cons -lr_cons -LDFLAGS+=-L../../libr/hash -lr_hash -LDFLAGS+=-L../../libr/debug -lr_debug -LDFLAGS+=-L../../libr/search -lr_search -LDFLAGS+=-L../../libr/config -lr_config -LDFLAGS+=${LINK} - -include ../../libr/config.mk -include ../../libr/socket/deps.mk -include ../../libr/magic/deps.mk -include ../../libr/main/deps.mk -include ../../shlr/sdb.mk -include ../../shlr/zip/deps.mk -include ../../shlr/gdb/deps.mk -include ../../shlr/java/deps.mk -include ../../shlr/bochs/deps.mk -include ../../shlr/grub/deps.mk -include ../../shlr/qnx/deps.mk -include ../../shlr/ar/deps.mk -include ../../shlr/sdb.mk -include ../../shlr/capstone.mk -include ../../shlr/radare2-shell-parser-deps.mk - -all: symlinks - -symlinks: build - for FILE in r2 ${BINS} ; do \ - ln -fs radare2 $$FILE ; \ - done - -clean: - mv main.c main.k - rm -f *.[ch] - mv main.k main.c - rm -f ${BINS2} r2 - -build: - mv main.c main.k - rm -f *.[ch] - mv main.k main.c - for FILE in ${BINS2} ; do cp ../$$FILE/*.[ch] . ; done - rm -f rwx.c xorhex.c rsc2.c - for FILE in ${BINS2} ; do \ - mv $${FILE}.c _$${FILE}.c ;\ - sed -e "s,^int main,int $${FILE}_main,g" _$${FILE}.c > $${FILE}.c ; \ - rm -f _$${FILE} ; \ - done - rm -f _* - ${CC} -o radare2 ${SOURCES} ${CFLAGS} ${LDFLAGS} - mv main.c main.k - rm -f *.[ch] - mv main.k main.c - -install: - mkdir -p "${DESTDIR}${BINDIR}" - for FILE in r2 ${BINS2} ; do \ - rm -f "${DESTDIR}${BINDIR}/$$FILE" ; \ - cp -PRpf "$$FILE" "${DESTDIR}${BINDIR}/$$FILE" ; \ - done - diff --git a/binr/blob/main.c b/binr/blob/main.c deleted file mode 100644 index e229466571..0000000000 --- a/binr/blob/main.c +++ /dev/null @@ -1,15 +0,0 @@ -/* radare - LGPL - Copyright 2012-2020 - pancake */ - -#include -#include - -int main(int argc, char **argv) { - int rc = 1; - const char *prog_name = r_file_basename (argv[0]); - RMain *m = r_main_new (prog_name); - if (m) { - rc = r_main_run (m, argc, argv); - r_main_free (m); - } - return rc; -} diff --git a/binr/r2agent/r2agent.c b/binr/r2agent/r2agent.c deleted file mode 100644 index ed73660ddc..0000000000 --- a/binr/r2agent/r2agent.c +++ /dev/null @@ -1,7 +0,0 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ - -#include - -int main(int argc, const char **argv) { - return r_main_r2agent (argc, argv); -} diff --git a/binr/r2bb/Makefile b/binr/r2bb/Makefile deleted file mode 100644 index 9f3365c5a8..0000000000 --- a/binr/r2bb/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -all: - $(CC) -o r2bb r2bb.c -L../../libr/util -lr_util -I../../libr/include diff --git a/binr/r2pm/meson.build b/binr/r2pm/meson.build deleted file mode 100644 index b09721af86..0000000000 --- a/binr/r2pm/meson.build +++ /dev/null @@ -1 +0,0 @@ -install_data('r2pm', install_dir: get_option('bindir')) diff --git a/binr/r2r/r2r.h b/binr/r2r/r2r.h deleted file mode 100644 index a69430fb67..0000000000 --- a/binr/r2r/r2r.h +++ /dev/null @@ -1,215 +0,0 @@ -/* radare - LGPL - Copyright 2020 - thestr4ng3r */ - -#ifndef RADARE2_R2R_H -#define RADARE2_R2R_H - -#include - -#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) -#define R2R_OS "freebsd" -#elif defined(__linux__) -#define R2R_OS "linux" -#elif defined(__APPLE__) -#define R2R_OS "darwin" -#elif __WINDOWS__ -#define R2R_OS "windows" -#else -#define R2R_OS "unknown" -#endif - -#if __i386__ -#define R2R_ARCH "x86" -#elif __x86_64__ -#define R2R_ARCH "x64" -#else -#define R2R_ARCH "unknown" -#endif - -#define R2R_ARCH_OS R2R_OS"-"R2R_ARCH - -typedef struct r2r_cmd_test_string_record { - char *value; - ut64 line_begin; // inclusive - ut64 line_end; // exclusive -} R2RCmdTestStringRecord; - -typedef struct r2r_cmd_test_bool_record { - bool value; - ut64 line; // bools are always oneliners (e.g. BROKEN=1) - bool set; -} R2RCmdTestBoolRecord; - -typedef struct r2r_cmd_test_num_record { - ut64 value; - ut64 line; // nums are always oneliners (e.g. TIMEOUT=10) - bool set; -} R2RCmdTestNumRecord; - -typedef struct r2r_cmd_test_t { - R2RCmdTestStringRecord name; - R2RCmdTestStringRecord file; - R2RCmdTestStringRecord args; - R2RCmdTestStringRecord source; - R2RCmdTestStringRecord cmds; - R2RCmdTestStringRecord expect; - R2RCmdTestStringRecord expect_err; - R2RCmdTestBoolRecord broken; - R2RCmdTestNumRecord timeout; - ut64 run_line; - bool load_plugins; -} R2RCmdTest; - -#define R2R_CMD_TEST_FOREACH_RECORD_NOP(name, field) -#define R2R_CMD_TEST_FOREACH_RECORD(macro_str, macro_bool, macro_int) \ - macro_str ("NAME", name) \ - macro_str ("FILE", file) \ - macro_str ("ARGS", args) \ - macro_int ("TIMEOUT", timeout) \ - macro_str ("SOURCE", source) \ - macro_str ("CMDS", cmds) \ - macro_str ("EXPECT", expect) \ - macro_str ("EXPECT_ERR", expect_err) \ - macro_bool ("BROKEN", broken) - -typedef enum r2r_asm_test_mode_t { - R2R_ASM_TEST_MODE_ASSEMBLE = 1, - R2R_ASM_TEST_MODE_DISASSEMBLE = (1 << 1), - R2R_ASM_TEST_MODE_BIG_ENDIAN = (1 << 2), - R2R_ASM_TEST_MODE_BROKEN = (1 << 3) -} R2RAsmTestMode; - -typedef struct r2r_asm_test_t { - ut64 line; - const char *arch; - const char *cpu; - int bits; - int mode; - ut64 offset; - char *disasm; - ut8 *bytes; - size_t bytes_size; -} R2RAsmTest; - -typedef struct r2r_json_test_t { - ut64 line; - char *cmd; - bool broken; - bool load_plugins; -} R2RJsonTest; - -typedef struct r2r_fuzz_test_t { - char *file; -} R2RFuzzTest; - -typedef enum r2r_test_type_t { - R2R_TEST_TYPE_CMD, - R2R_TEST_TYPE_ASM, - R2R_TEST_TYPE_JSON, - R2R_TEST_TYPE_FUZZ -} R2RTestType; - -typedef struct r2r_test_t { - const char *path; - R2RTestType type; - union { - R2RCmdTest *cmd_test; - R2RAsmTest *asm_test; - R2RJsonTest *json_test; - R2RFuzzTest *fuzz_test; - }; -} R2RTest; - -typedef struct r2r_test_database_t { - RPVector tests; - RStrConstPool strpool; -} R2RTestDatabase; - -typedef struct r2r_run_config_t { - const char *r2_cmd; - const char *rasm2_cmd; - const char *json_test_file; - ut64 timeout_ms; -} R2RRunConfig; - -typedef struct r2r_process_output_t { - char *out; // stdout - char *err; // stderr - int ret; // exit code of the process - bool timeout; -} R2RProcessOutput; - -typedef struct r2r_asm_test_output_t { - char *disasm; - ut8 *bytes; - size_t bytes_size; - bool as_timeout; - bool disas_timeout; -} R2RAsmTestOutput; - -typedef enum r2r_test_result_t { - R2R_TEST_RESULT_OK, - R2R_TEST_RESULT_FAILED, - R2R_TEST_RESULT_BROKEN, - R2R_TEST_RESULT_FIXED -} R2RTestResult; - -typedef struct r2r_test_result_info_t { - R2RTest *test; - R2RTestResult result; - bool timeout; - bool run_failed; // something went seriously wrong (e.g. r2 not found) - union { - R2RProcessOutput *proc_out; // for test->type == R2R_TEST_TYPE_CMD, R2R_TEST_TYPE_JSON or R2R_TEST_TYPE_FUZZ - R2RAsmTestOutput *asm_out; // for test->type == R2R_TEST_TYPE_ASM - }; -} R2RTestResultInfo; - -R_API R2RCmdTest *r2r_cmd_test_new(void); -R_API void r2r_cmd_test_free(R2RCmdTest *test); -R_API RPVector *r2r_load_cmd_test_file(const char *file); - -R_API R2RAsmTest *r2r_asm_test_new(void); -R_API void r2r_asm_test_free(R2RAsmTest *test); -R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file); - -R_API R2RJsonTest *r2r_json_test_new(void); -R_API void r2r_json_test_free(R2RJsonTest *test); -R_API RPVector *r2r_load_json_test_file(const char *file); - -R_API R2RTestDatabase *r2r_test_database_new(void); -R_API void r2r_test_database_free(R2RTestDatabase *db); -R_API bool r2r_test_database_load(R2RTestDatabase *db, const char *path); -R_API bool r2r_test_database_load_fuzz(R2RTestDatabase *db, const char *path); - -typedef struct r2r_subprocess_t R2RSubprocess; - -R_API bool r2r_subprocess_init(void); -R_API void r2r_subprocess_fini(void); -R_API R2RSubprocess *r2r_subprocess_start( - const char *file, const char *args[], size_t args_size, - const char *envvars[], const char *envvals[], size_t env_size); -R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms); -R_API void r2r_subprocess_free(R2RSubprocess *proc); - -typedef R2RProcessOutput *(*R2RCmdRunner)(const char *file, const char *args[], size_t args_size, - const char *envvars[], const char *envvals[], size_t env_size, ut64 timeout_ms, void *user); - -R_API void r2r_process_output_free(R2RProcessOutput *out); -R_API R2RProcessOutput *r2r_run_cmd_test(R2RRunConfig *config, R2RCmdTest *test, R2RCmdRunner runner, void *user); -R_API bool r2r_check_cmd_test(R2RProcessOutput *out, R2RCmdTest *test); -R_API bool r2r_check_jq_available(void); -R_API R2RProcessOutput *r2r_run_json_test(R2RRunConfig *config, R2RJsonTest *test, R2RCmdRunner runner, void *user); -R_API bool r2r_check_json_test(R2RProcessOutput *out, R2RJsonTest *test); -R_API R2RAsmTestOutput *r2r_run_asm_test(R2RRunConfig *config, R2RAsmTest *test); -R_API bool r2r_check_asm_test(R2RAsmTestOutput *out, R2RAsmTest *test); -R_API void r2r_asm_test_output_free(R2RAsmTestOutput *out); -R_API R2RProcessOutput *r2r_run_fuzz_test(R2RRunConfig *config, R2RFuzzTest *test, R2RCmdRunner runner, void *user); -R_API bool r2r_check_fuzz_test(R2RProcessOutput *out); - -R_API void r2r_test_free(R2RTest *test); -R_API char *r2r_test_name(R2RTest *test); -R_API bool r2r_test_broken(R2RTest *test); -R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test); -R_API void r2r_test_result_info_free(R2RTestResultInfo *result); - -#endif //RADARE2_R2R_H diff --git a/binr/rabin2/Makefile b/binr/rabin2/Makefile deleted file mode 100644 index 33219020b6..0000000000 --- a/binr/rabin2/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -BIN=rabin2 -BINDEPS=r_magic r_core r_bin r_egg r_cons r_main -BINDEPS+=r_config r_io r_flag r_asm -BINDEPS+=r_debug r_hash r_lang r_anal r_parse r_bp r_reg -BINDEPS+=r_search r_syscall r_socket r_fs r_magic r_crypto r_util - -include ../rules.mk - -include ../../libr/socket/deps.mk -include ../../libr/main/deps.mk -include ../../shlr/zip/deps.mk -include ../../shlr/gdb/deps.mk -include ../../shlr/java/deps.mk -include ../../shlr/grub/deps.mk -include ../../shlr/bochs/deps.mk -include ../../shlr/qnx/deps.mk -include ../../shlr/ar/deps.mk -include ../../shlr/capstone.mk - -LDFLAGS+=$(LINK) diff --git a/binr/rabin2/meson.build b/binr/rabin2/meson.build deleted file mode 100644 index 8e907fc881..0000000000 --- a/binr/rabin2/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -executable('rabin2', 'rabin2.c', - include_directories: [platform_inc], - dependencies: [ - r_util_dep, - r_cons_dep, - r_main_dep, - r_config_dep, - r_hash_dep, - r_io_dep, - r_crypto_dep, - r_core_dep, - r_magic_dep, - r_bin_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binr/radare2/meson.build b/binr/radare2/meson.build deleted file mode 100644 index 72361dd718..0000000000 --- a/binr/radare2/meson.build +++ /dev/null @@ -1,30 +0,0 @@ -executable('radare2', 'radare2.c', - include_directories: [platform_inc], - dependencies: [ - r_util_dep, - r_main_dep, - r_socket_dep, - r_core_dep, - r_io_dep, - r_fs_dep, - r_bin_dep, - r_flag_dep, - r_cons_dep, - r_asm_dep, - r_debug_dep, - r_config_dep, - r_bp_dep, - r_reg_dep, - r_syscall_dep, - r_anal_dep, - r_parse_dep, - r_egg_dep, - r_search_dep, - r_hash_dep, - r_crypto_dep, - r_magic_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binr/radiff2/Makefile b/binr/radiff2/Makefile deleted file mode 100644 index 61ae8b5119..0000000000 --- a/binr/radiff2/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -BIN=radiff2 - -BINDEPS=r_core r_config r_cons r_search r_anal -BINDEPS+=r_bin r_debug r_io r_asm r_hash r_fs r_crypto -BINDEPS+=r_socket r_flag r_lang r_reg r_bp r_parse -BINDEPS+=r_syscall r_magic r_util r_parse r_egg r_main - -include ../rules.mk - -ifeq ($(OSTYPE),android) -LDFLAGS+=${DL_LIBS} -lm -endif - -include ../../libr/socket/deps.mk -include ../../libr/main/deps.mk -include ../../shlr/zip/deps.mk -include ../../shlr/gdb/deps.mk -include ../../shlr/bochs/deps.mk -include ../../shlr/qnx/deps.mk -include ../../shlr/ar/deps.mk - -LDFLAGS+=$(LINK) diff --git a/binr/radiff2/meson.build b/binr/radiff2/meson.build deleted file mode 100644 index 05c0bc9613..0000000000 --- a/binr/radiff2/meson.build +++ /dev/null @@ -1,19 +0,0 @@ -executable('radiff2', 'radiff2.c', - include_directories: [platform_inc], - dependencies: [ - r_util_dep, - r_main_dep, - r_io_dep, - r_search_dep, - r_cons_dep, - r_core_dep, - r_bin_dep, - r_anal_dep, - r_asm_dep, - r_hash_dep, - r_config_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binr/rafind2/Makefile b/binr/rafind2/Makefile deleted file mode 100644 index d9966fb24b..0000000000 --- a/binr/rafind2/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -BIN=rafind2 - -BINDEPS=r_search r_io r_asm r_anal r_reg r_cons r_lang r_crypto -BINDEPS+=r_socket r_parse r_util r_syscall r_flag r_hash r_main - -include ../rules.mk - -include ../../libr/socket/deps.mk -include ../../libr/main/deps.mk -include ../../shlr/zip/deps.mk -include ../../shlr/gdb/deps.mk -include ../../shlr/bochs/deps.mk -include ../../shlr/qnx/deps.mk -include ../../shlr/ar/deps.mk -LDFLAGS+=$(LINK) diff --git a/binr/rafind2/meson.build b/binr/rafind2/meson.build deleted file mode 100644 index ed04f2ab11..0000000000 --- a/binr/rafind2/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -executable('rafind2', 'rafind2.c', - include_directories: [platform_inc], - dependencies: [ - r_main_dep, - r_util_dep, - r_search_dep, - r_crypto_dep, - r_io_dep, - r_main_dep, - r_cons_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binr/ragg2/Makefile b/binr/ragg2/Makefile deleted file mode 100644 index 722517643f..0000000000 --- a/binr/ragg2/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -BIN=ragg2 -BINDEPS=r_egg r_syscall r_asm -BINDEPS+=r_core r_hash r_debug r_fs r_config r_bp r_crypto r_cons -BINDEPS+=r_lang r_parse r_anal r_reg r_flag r_crypto -BINDEPS+=r_bin r_search r_io r_socket -BINDEPS+=r_magic r_util r_main - -include ../rules.mk -include ../../libr/main/deps.mk -include ../../shlr/ar/deps.mk -include ../../libr/socket/deps.mk -include ../../shlr/bochs/deps.mk -include ../../shlr/gdb/deps.mk -include ../../shlr/grub/deps.mk -include ../../shlr/java/deps.mk -include ../../shlr/capstone.mk -include ../../shlr/qnx/deps.mk - -LDFLAGS+=$(LINK) diff --git a/binr/ragg2/meson.build b/binr/ragg2/meson.build deleted file mode 100644 index 3043d10c0d..0000000000 --- a/binr/ragg2/meson.build +++ /dev/null @@ -1,19 +0,0 @@ -executable('ragg2', 'ragg2.c', - include_directories: [platform_inc], - dependencies: [ - r_util_dep, - r_main_dep, - r_egg_dep, - r_bin_dep, - r_core_dep, - r_hash_dep, - r_debug_dep, - r_fs_dep, - r_config_dep, - r_bp_dep, - r_crypto_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binr/rarun2/Makefile b/binr/rarun2/Makefile deleted file mode 100644 index 67de057911..0000000000 --- a/binr/rarun2/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -BIN=rarun2 -BINDEPS=r_socket r_util r_main - -include ../rules.mk -include ../../libr/main/deps.mk -include ../../shlr/zip/deps.mk -include ../../libr/socket/deps.mk -LDFLAGS+=$(LINK) diff --git a/binr/rarun2/rarun2.c b/binr/rarun2/rarun2.c deleted file mode 100644 index 6a2d51ef67..0000000000 --- a/binr/rarun2/rarun2.c +++ /dev/null @@ -1,7 +0,0 @@ -/* radare2 - Copyleft 2011-2019 - pancake */ - -#include - -int main(int argc, const char **argv) { - return r_main_rarun2 (argc, argv); -} diff --git a/binr/rasign2/Makefile b/binr/rasign2/Makefile deleted file mode 100644 index b4d45a8b88..0000000000 --- a/binr/rasign2/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -BIN=rasign2 -BINDEPS=r_anal r_util r_core r_search r_main -LDFLAGS+=$(LINK) - -include ../../libr/main/deps.mk -include ../rules.mk diff --git a/binr/rasm2/meson.build b/binr/rasm2/meson.build deleted file mode 100644 index 52c3808c0a..0000000000 --- a/binr/rasm2/meson.build +++ /dev/null @@ -1,15 +0,0 @@ -executable('rasm2', 'rasm2.c', - include_directories: [platform_inc], - dependencies: [ - r_main_dep, - r_util_dep, - r_asm_dep, - r_anal_dep, - r_crypto_dep, - r_syscall_dep, - r_hash_dep - ], - install: true, - install_rpath: rpath_exe, - implicit_include_directories: false -) diff --git a/binrz/Makefile b/binrz/Makefile new file mode 100644 index 0000000000..62e5b7cc6f --- /dev/null +++ b/binrz/Makefile @@ -0,0 +1,75 @@ +include ../global.mk +include ../librz/config.mk + +DESTDIR:=$(DESTDIR) +BTOP=$(shell pwd) + +.PHONY: all clean install install-symlink deinstall uninstall mrproper preload + +BINS=rz-ax rz-asm rz-bin rz-hash rz-diff rizin rz-find rz-run rz-gg rz-agent rz-sign + +ifeq ($(WANT_R2R),1) + BINS+=rz-test +endif + +LIBR2=$(call libname-version,librz.$(EXT_SO),${LIBVERSION}) + +all: preload + @for BINARY in $(BINS) ; do $(MAKE) -C $${BINARY} all || exit 1; done +ifeq ($(COMPILER),ios-sdk) + $(MAKE) ios-sign +endif + +preload: +ifeq ($(WITHPIC),1) + $(MAKE) -C preload +endif + +install: + mkdir -p "${DESTDIR}${BINDIR}" + for BINARY in ${BINS} ; do \ + rm -f "${DESTDIR}${BINDIR}/$$BINARY" ; \ + ${INSTALL_PROGRAM} "$$BINARY/$$BINARY" "${DESTDIR}${BINDIR}/$$BINARY" ; \ + done + ${INSTALL_SCRIPT} "$(BTOP)/rz-pm/rz-pm" "${DESTDIR}${BINDIR}/rz-pm" + rm -rf "${DESTDIR}${DATADIR}/rizin/${VERSION}/rz-pm" + -cd "${DESTDIR}${BINDIR}" && rm -f r2 ; ln -fs rizin r2 ; ln -fs rizin r2p +ifeq ($(WITHPIC),1) + ${INSTALL_LIB} "preload/librz.$(EXT_SO)" "${DESTDIR}${LIBDIR}" + -cd "${DESTDIR}${LIBDIR}" && \ + mv librz.$(EXT_SO) $(LIBR2) && \ + ln -fs $(LIBR2) librz.$(EXT_SO) +endif + +ios_sign ios-sign ios-sdk-sign: + -for a in $(BINS) ; do xcrun --sdk iphoneos codesign -s- --entitlements rizin/rizin_ios.xml $$a ; done + -for a in ../librz/*/*.${EXT_SO} ; do xcrun --sdk iphoneos codesign -s- --entitlements rizin/rizin_ios.xml $$a ; done + -for a in ../librz/*/p/*.${EXT_SO} ; do xcrun --sdk iphoneos codesign -s- --entitlements rizin/rizin_ios.xml $$a ; done + +symstall install-symlink: + cd .. && \ + mkdir -p "${DESTDIR}${BINDIR}" && \ + for BINARY in ${BINS} ; do ln -fs "${BTOP}/$$BINARY/$$BINARY" "${DESTDIR}${BINDIR}/$$BINARY" ; done + cd .. && ln -fs "${BTOP}/rz-pm/rz-pm" "${DESTDIR}${BINDIR}/rz-pm" + cd .. && rm -rf "${DESTDIR}${DATADIR}/rizin/${VERSION}/rz-pm" + cd .. && mkdir -p "${DESTDIR}${DATADIR}/rizin/${VERSION}/" + -cd .. && ln -fs "${DESTDIR}${BINDIR}/rizin" "${DESTDIR}${BINDIR}/r2" + -cd .. && ln -fs "${DESTDIR}${BINDIR}/rizin" "${DESTDIR}${BINDIR}/r2p" + -cd .. && ln -fs "${BTOP}/preload/librz.$(EXT_SO)" "${DESTDIR}${LIBDIR}/librz.$(EXT_SO)" + -cd .. && cd "${DESTDIR}${LIBDIR}" && \ + mv librz.$(EXT_SO) $(LIBR2) && \ + ln -fs $(LIBR2) librz.$(EXT_SO) + +deinstall uninstall: + -cd .. ; \ + for BINARY in ${BINS} ; do rm -f "${DESTDIR}${BINDIR}/$$BINARY" ; done ; \ + rm -f "${DESTDIR}${BINDIR}/rz-pm" ; \ + rm -f "${DESTDIR}${BINDIR}/r2p" + rm -f "${DESTDIR}${BINDIR}/r2" + +clean: + @for DIR in preload ${BINS} ; do ${MAKE} -C $$DIR clean; done + +mrproper: + @for DIR in preload ${BINS} ; do ${MAKE} -C $$DIR mrproper; done + diff --git a/binrz/blob/Makefile b/binrz/blob/Makefile new file mode 100644 index 0000000000..0c2f86b20e --- /dev/null +++ b/binrz/blob/Makefile @@ -0,0 +1,106 @@ +PREFIX?=/usr +DESTDIR?=/ + +BINS=rz-bin rz-run rz-asm rz-gg rz-hash rz-ax rz-find rz-diff +BINS2=rizin ${BINS} + +SOURCES= main.c rz-bin.c rizin.c rz-diff.c rz-find.c +SOURCES+=rz-hash.c rz-run.c rz-asm.c rz-ax.c rz-gg.c + +include ../../config-user.mk + +SHLR=../../shlr + +ifeq (${ANDROID},1) +LDFLAGS+=-lm +else +ifneq (${OSTYPE},linux) +LDFLAGS+=-lpthread +LDFLAGS+=-ldl +endif +endif +ifeq ($(USE_LTO),1) +LDFLAGS+=-flto +endif + +CFLAGS+=-I../../librz/include/ +CFLAGS+=-I$(SHLR)/spp + +LDFLAGS+=-L../../librz/main -lrz_main +LDFLAGS+=-L../../librz/io -lrz_io +LDFLAGS+=-L../../librz/bp -lrz_bp +LDFLAGS+=-L../../librz/socket -lrz_socket +LDFLAGS+=-L../../librz/bin -lrz_bin +LDFLAGS+=-L../../librz/reg -lrz_reg +LDFLAGS+=-L../../librz/asm -lrz_asm +LDFLAGS+=-L../../librz/lang -lrz_lang +LDFLAGS+=-L../../librz/egg -lrz_egg +LDFLAGS+=-L../../librz/core -lrz_core +LDFLAGS+=-L../../librz/anal -lrz_anal +LDFLAGS+=-L../../librz/crypto -lrz_crypto +LDFLAGS+=-L../../librz/flag -lrz_flag +LDFLAGS+=-L../../librz/parse -lrz_parse +LDFLAGS+=-L../../librz/fs -lrz_fs +LDFLAGS+=-L../../librz/magic -lrz_magic +LDFLAGS+=-L../../librz/syscall -lrz_syscall +LDFLAGS+=-L../../librz/util -lrz_util +LDFLAGS+=-L../../librz/cons -lrz_cons +LDFLAGS+=-L../../librz/hash -lrz_hash +LDFLAGS+=-L../../librz/debug -lrz_debug +LDFLAGS+=-L../../librz/search -lrz_search +LDFLAGS+=-L../../librz/config -lrz_config +LDFLAGS+=${LINK} + +include ../../librz/config.mk +include ../../librz/socket/deps.mk +include ../../librz/magic/deps.mk +include ../../librz/main/deps.mk +include ../../shlr/sdb.mk +include ../../shlr/zip/deps.mk +include ../../shlr/gdb/deps.mk +include ../../shlr/java/deps.mk +include ../../shlr/bochs/deps.mk +include ../../shlr/grub/deps.mk +include ../../shlr/qnx/deps.mk +include ../../shlr/ar/deps.mk +include ../../shlr/sdb.mk +include ../../shlr/capstone.mk +include ../../shlr/rizin-shell-parser-deps.mk + +all: symlinks + +symlinks: build + for FILE in r2 ${BINS} ; do \ + ln -fs rizin $$FILE ; \ + done + +clean: + mv main.c main.k + rm -f *.[ch] + mv main.k main.c + rm -f ${BINS2} r2 + +build: + mv main.c main.k + rm -f *.[ch] + mv main.k main.c + for FILE in ${BINS2} ; do cp ../$$FILE/*.[ch] . ; done + rm -f rwx.c xorhex.c rsc2.c + for FILE in ${BINS2} ; do \ + mv $${FILE}.c _$${FILE}.c ;\ + sed -e "s,^int main,int $${FILE}_main,g" _$${FILE}.c > $${FILE}.c ; \ + rm -f _$${FILE} ; \ + done + rm -f _* + ${CC} -o rizin ${SOURCES} ${CFLAGS} ${LDFLAGS} + mv main.c main.k + rm -f *.[ch] + mv main.k main.c + +install: + mkdir -p "${DESTDIR}${BINDIR}" + for FILE in r2 ${BINS2} ; do \ + rm -f "${DESTDIR}${BINDIR}/$$FILE" ; \ + cp -PRpf "$$FILE" "${DESTDIR}${BINDIR}/$$FILE" ; \ + done + diff --git a/binrz/blob/main.c b/binrz/blob/main.c new file mode 100644 index 0000000000..51cf190ccf --- /dev/null +++ b/binrz/blob/main.c @@ -0,0 +1,15 @@ +/* radare - LGPL - Copyright 2012-2020 - pancake */ + +#include +#include + +int main(int argc, char **argv) { + int rc = 1; + const char *prog_name = rz_file_basename (argv[0]); + RzMain *m = rz_main_new (prog_name); + if (m) { + rc = rz_main_run (m, argc, argv); + rz_main_free (m); + } + return rc; +} diff --git a/binr/blob/meson.build b/binrz/blob/meson.build similarity index 75% rename from binr/blob/meson.build rename to binrz/blob/meson.build index 76e15e71aa..b8d8c83d74 100644 --- a/binr/blob/meson.build +++ b/binrz/blob/meson.build @@ -1,8 +1,8 @@ -executable('radare2', 'main.c', +executable('rizin', 'main.c', include_directories: [platform_inc], dependencies: [ - r_main_dep, - r_util_dep, + rz_main_dep, + rz_util_dep, ], install: true, install_rpath: rpath_exe, diff --git a/binr/blob/meson_install_links.sh b/binrz/blob/meson_install_links.sh similarity index 56% rename from binr/blob/meson_install_links.sh rename to binrz/blob/meson_install_links.sh index 59559915b6..958e6469f0 100644 --- a/binr/blob/meson_install_links.sh +++ b/binrz/blob/meson_install_links.sh @@ -4,8 +4,8 @@ set -e mkdir -p "${DESTDIR}/${MESON_INSTALL_PREFIX}/bin" cd "${DESTDIR}/${MESON_INSTALL_PREFIX}/bin" -TOOLS="rahash2 rarun2 rasm2 rabin2 ragg2 r2agent radiff2 rafind2 rassign2 rax2 r2" +TOOLS="rz_hash rz_run rz_asm rz_bin rz_gg rz_agent rz_diff rz_find rassign2 rz_ax r2" for TOOL in $TOOLS ; do - ln -sf radare2 $TOOL ; + ln -sf rizin $TOOL ; done diff --git a/binr/preload/Makefile b/binrz/preload/Makefile similarity index 54% rename from binr/preload/Makefile rename to binrz/preload/Makefile index 4db89a0deb..f8e2834b59 100644 --- a/binr/preload/Makefile +++ b/binrz/preload/Makefile @@ -1,12 +1,12 @@ ISPPC=$(shell uname -m | grep Power) ifeq ($(ISPPC),) -BIN=libr2 +BIN=librz ISLIB=1 -BINDEPS=r_core r_parse r_search r_cons r_config -BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io -BINDEPS+=r_lang r_asm r_syscall r_hash r_crypto -BINDEPS+=r_magic r_socket r_flag r_util r_egg r_fs +BINDEPS=rz_core rz_parse rz_search rz_cons rz_config +BINDEPS+=rz_bin rz_debug rz_anal rz_reg rz_bp rz_io +BINDEPS+=rz_lang rz_asm rz_syscall rz_hash rz_crypto +BINDEPS+=rz_magic rz_socket rz_flag rz_util rz_egg rz_fs include ../rules.mk @@ -14,15 +14,15 @@ ifeq ($(OSTYPE),android) LDFLAGS+=${DL_LIBS} -lm endif ifeq ($(OSTYPE),gnulinux) -LDFLAGS+=-Wl,-soname,libr2.${EXT_SO}.${LIBVERSION} +LDFLAGS+=-Wl,-soname,librz.${EXT_SO}.${LIBVERSION} endif -include ../../libr/socket/deps.mk +include ../../librz/socket/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/gdb/deps.mk include ../../shlr/bochs/deps.mk include ../../shlr/qnx/deps.mk include ../../shlr/ar/deps.mk -include ../../shlr/radare2-shell-parser-deps.mk +include ../../shlr/rizin-shell-parser-deps.mk clean:: rm -f $(BIN).$(EXT_SO) $(BIN).o diff --git a/binr/preload/alloc.c b/binrz/preload/alloc.c similarity index 89% rename from binr/preload/alloc.c rename to binrz/preload/alloc.c index 49f98bc660..3eeedae3fc 100644 --- a/binr/preload/alloc.c +++ b/binrz/preload/alloc.c @@ -1,4 +1,4 @@ -#define R_API +#define RZ_API #define R_ALLOC_USE_MMAP 1 #define USE_MALLOC 0 @@ -10,14 +10,14 @@ #include #if USE_MALLOC -R_API void r_initmem(char *p, size_t s) { +RZ_API void rz_initmem(char *p, size_t s) { } -R_API void* r_malloc(size_t s) { +RZ_API void* rz_malloc(size_t s) { return malloc (s); } -R_API void r_free(void *p) { +RZ_API void rz_free(void *p) { free (s); } #else @@ -47,7 +47,7 @@ void InitMem(char *ptr, int size_in_bytes) { /* This function is complete :-) */ } -R_API void *r_malloc(int elem_size) { +RZ_API void *rz_malloc(int elem_size) { /* check whether any chunk (allocated before) is free first */ MCB_P p_mcb; int flag = NO_MCB; @@ -86,7 +86,7 @@ R_API void *r_malloc(int elem_size) { return NULL; } -void r_free(void *p) { +void rz_free(void *p) { /* Mark in MCB that this chunk is free */ MCB_P ptr = (MCB_P)p; ptr--; @@ -119,17 +119,17 @@ int main() { InitMem (B, R_MALLOC_MAX); - char *a = r_malloc (10); + char *a = rz_malloc (10); if (!a) { printf ("can't malloc\n"); return 1; } strcpy (a, "hello"); - char *b = r_malloc (10); + char *b = rz_malloc (10); strcpy (b, "world"); printf ("%p: %s\n%p: %s\n", a, a, b, b); - r_free (b); - r_free (a); + rz_free (b); + rz_free (a); return 0; } #endif diff --git a/binr/preload/demo.c b/binrz/preload/demo.c similarity index 83% rename from binr/preload/demo.c rename to binrz/preload/demo.c index 3f4c3ba9bf..e4dfaf2b67 100644 --- a/binr/preload/demo.c +++ b/binrz/preload/demo.c @@ -3,7 +3,7 @@ int main(int argc, char **argv) { void *a = dlopen(NULL, RTLD_LAZY); - void *m = dlsym (a, "r_main_radare2"); + void *m = dlsym (a, "rz_main_rizin"); if (m) { int (*r2main)(int argc, char **argv) = m; return r2main (argc, argv); diff --git a/binr/preload/libr2.c b/binrz/preload/librz2.c similarity index 62% rename from binr/preload/libr2.c rename to binrz/preload/librz2.c index 991d049e82..ab69cdb58f 100644 --- a/binr/preload/libr2.c +++ b/binrz/preload/librz2.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2014-2020 - pancake */ -#include +#include #if __WINDOWS__ #include #endif -static RCore *core = NULL; +static RzCore *core = NULL; #if __UNIX__ // XXX check if its already opened -static RCoreFile *openself(void) { - RCoreFile *fd = NULL; - char *out = r_core_cmd_str (core, "o"); +static RzCoreFile *openself(void) { + RzCoreFile *fd = NULL; + char *out = rz_core_cmd_str (core, "o"); if (out) { if (!strstr (out, "self://")) { - fd = r_core_file_open (core, "self://", R_PERM_RW, 0); + fd = rz_core_file_open (core, "self://", R_PERM_RW, 0); } free (out); } @@ -24,30 +24,30 @@ static RCoreFile *openself(void) { } static void sigusr1(int s) { - RCoreFile *fd = openself (); - r_core_prompt_loop (core); - r_core_file_close (core, fd); + RzCoreFile *fd = openself (); + rz_core_prompt_loop (core); + rz_core_file_close (core, fd); } static void sigusr2(int s) { (void)openself (); - r_core_cmd0 (core, "=H&"); + rz_core_cmd0 (core, "=H&"); } static void _libwrap_init() __attribute__ ((constructor)); static void _libwrap_init(void) { char *web; - r_sys_signal (SIGUSR1, sigusr1); - r_sys_signal (SIGUSR2, sigusr2); - printf ("libr2 initialized. send SIGUSR1 to %d in order to reach the r2 prompt\n", getpid ()); + rz_sys_signal (SIGUSR1, sigusr1); + rz_sys_signal (SIGUSR2, sigusr2); + printf ("librz initialized. send SIGUSR1 to %d in order to reach the r2 prompt\n", getpid ()); printf ("kill -USR1 %d\n", getpid ()); fflush (stdout); - web = r_sys_getenv ("RARUN2_WEB"); - core = r_core_new (); - r_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL); + web = rz_sys_getenv ("RARUN2_WEB"); + core = rz_core_new (); + rz_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL); if (web) { - r_core_cmd0 (core, "=H&"); - r_sys_setenv ("RARUN2_WEB", NULL); + rz_core_cmd0 (core, "=H&"); + rz_sys_setenv ("RARUN2_WEB", NULL); free (web); } // TODO: maybe reopen every time a signal is spawned to reload memory regions information @@ -71,18 +71,18 @@ void alloc_console(void) { freopen ("conout$", "w", stderr); } -static void start_r2(void) { - core = r_core_new (); - r_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL); - RCoreFile *fd = r_core_file_open (core, "self://", R_PERM_RW, 0); - r_core_prompt_loop (core); - r_core_file_close (core, fd); +static void start_rz(void) { + core = rz_core_new (); + rz_core_loadlibs (core, R_CORE_LOADLIBS_ALL, NULL); + RzCoreFile *fd = rz_core_file_open (core, "self://", R_PERM_RW, 0); + rz_core_prompt_loop (core); + rz_core_file_close (core, fd); } /** * Neat little helper function to later enable injecting without * a .exe - * simply call: rundll32.exe libr2.dll,rundll_inject 0,0,0,0 + * simply call: rundll32.exe librz.dll,rundll_inject 0,0,0,0 * TODO: implement all injecting methods */ void rundll_inject(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) { @@ -95,7 +95,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD result, LPVOID lpReserved) { break; case DLL_PROCESS_ATTACH: alloc_console (); - start_r2 (); + start_rz (); break; } return 1; diff --git a/binr/preload/trap-darwin-x86-32.asm b/binrz/preload/trap-darwin-x86-32.asm similarity index 100% rename from binr/preload/trap-darwin-x86-32.asm rename to binrz/preload/trap-darwin-x86-32.asm diff --git a/binr/preload/trap-darwin-x86-64.asm b/binrz/preload/trap-darwin-x86-64.asm similarity index 100% rename from binr/preload/trap-darwin-x86-64.asm rename to binrz/preload/trap-darwin-x86-64.asm diff --git a/binr/preload/trap-linux-x86-32.asm b/binrz/preload/trap-linux-x86-32.asm similarity index 100% rename from binr/preload/trap-linux-x86-32.asm rename to binrz/preload/trap-linux-x86-32.asm diff --git a/binr/preload/trap-linux-x86-64.asm b/binrz/preload/trap-linux-x86-64.asm similarity index 100% rename from binr/preload/trap-linux-x86-64.asm rename to binrz/preload/trap-linux-x86-64.asm diff --git a/binr/radare2/Info.plist b/binrz/rizin/Info.plist similarity index 89% rename from binr/radare2/Info.plist rename to binrz/rizin/Info.plist index 3f63107a36..96cced2c4c 100644 --- a/binr/radare2/Info.plist +++ b/binrz/rizin/Info.plist @@ -5,11 +5,11 @@ CFBundleDevelopmentRegion English CFBundleIdentifier - org.radare.radare2 + org.radare.rizin CFBundleInfoDictionaryVersion 6.0 CFBundleName - radare2 + rizin CFBundleVersion 1.0 SecTaskAccess diff --git a/binr/radare2/Makefile b/binrz/rizin/Makefile similarity index 56% rename from binr/radare2/Makefile rename to binrz/rizin/Makefile index 0eb0dd50f3..9f9eed79c7 100644 --- a/binr/radare2/Makefile +++ b/binrz/rizin/Makefile @@ -1,17 +1,17 @@ -BIN=radare2 -BINDEPS=r_core r_parse r_search r_cons r_config -BINDEPS+=r_bin r_debug r_anal r_reg r_bp r_io r_fs -BINDEPS+=r_lang r_asm r_syscall r_hash r_main -BINDEPS+=r_magic r_socket r_flag r_egg r_crypto r_util +BIN=rizin +BINDEPS=rz_core rz_parse rz_search rz_cons rz_config +BINDEPS+=rz_bin rz_debug rz_anal rz_reg rz_bp rz_io rz_fs +BINDEPS+=rz_lang rz_asm rz_syscall rz_hash rz_main +BINDEPS+=rz_magic rz_socket rz_flag rz_egg rz_crypto rz_util include ../../config-user.mk # Apple Sign # -CERTID?=org.radare.radare2 -BUNDLE=org.radare.radare2 +CERTID?=org.radare.rizin +BUNDLE=org.radare.rizin MACSDK=macosx10.10 -ENTITL=radare2.xcent -#ENTITL=radare2_ios.xml +ENTITL=rizin.xcent +#ENTITL=rizin_ios.xml #CFLAGS+=-flto #LDFLAGS+=-flto @@ -30,16 +30,16 @@ CFLAGS+=-s ABORTING_MALLOC=0 #CFLAGS+=-Oz --memory-init-file 0 endif -FOOD_LIBS=$(addprefix ../../libr/,$(subst r_,,$(BINDEPS))) -SIGN_LIBS=$(addsuffix /libr_*.dylib,$(FOOD_LIBS)) +FOOD_LIBS=$(addprefix ../../librz/,$(subst rz_,,$(BINDEPS))) +SIGN_LIBS=$(addsuffix /librz_*.dylib,$(FOOD_LIBS)) include ../rules.mk -#IOS_CERTID?=org.radare.radare2 +#IOS_CERTID?=org.radare.rizin ios: - $(MAKE) -C ../../libr/io - $(MAKE) -C ../../libr/debug - rm -f radare2 + $(MAKE) -C ../../librz/io + $(MAKE) -C ../../librz/debug + rm -f rizin $(MAKE) $(MAKE) ios-sign @@ -51,44 +51,44 @@ endif ios-sign iossign: xcrun --sdk iphoneos codesign \ - -s- --entitlements radare2_ios.xml radare2 - # -f -s "$$IOS_CERTID" --entitlements radare2_ios.xml radare2 - #ldid -Sradare2_ios.xml radare2 + -s- --entitlements rizin_ios.xml rizin + # -f -s "$$IOS_CERTID" --entitlements rizin_ios.xml rizin + #ldid -Srizin_ios.xml rizin ios_sdk_sign: - -codesign -s- --entitlements radare2_ios.xml radare2 + -codesign -s- --entitlements rizin_ios.xml rizin macos-sign macossign: - rm -f radare2 - ${CC} radare2.c ${CFLAGS_INCLUDES} ${CFLAGS} ${LDFLAGS} ${LINK} -o radare2 \ + rm -f rizin + ${CC} rizin.c ${CFLAGS_INCLUDES} ${CFLAGS} ${LDFLAGS} ${LINK} -o rizin \ -sectcreate __TEXT __info_plist Info.plist \ -framework Security -framework CoreFoundation - #xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} --entitlements radare2_macos.xml radare2 - codesign -dvvv --deep -f -s ${CERTID} -i ${BUNDLE} --entitlements radare2_macos.xml radare2 - #sudo chown root:_developer radare2 -# sudo chown root:procmod radare2 - #sudo chmod g+s radare2 -# sudo chmod 4755 radare2 + #xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} --entitlements rizin_macos.xml rizin + codesign -dvvv --deep -f -s ${CERTID} -i ${BUNDLE} --entitlements rizin_macos.xml rizin + #sudo chown root:_developer rizin +# sudo chown root:procmod rizin + #sudo chmod g+s rizin +# sudo chmod 4755 rizin macos-sign-libs: for LIB in ${SIGN_LIBS} ; do \ echo Signing $$LIB ; \ codesign -f -s ${CERTID} $$LIB ; \ done -# xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} --entitlements $(ENTITL) radare2 -# xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} radare2 -# codesign -dvvv -s $(XNUCERT) ./radare2 -# sudo chown root:procmod radare2 -# sudo chmod g+s radare2 +# xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} --entitlements $(ENTITL) rizin +# xcrun --sdk $(MACSDK) codesign -f -s ${CERTID} rizin +# codesign -dvvv -s $(XNUCERT) ./rizin +# sudo chown root:procmod rizin +# sudo chmod g+s rizin ifeq ($(OSTYPE),android) LDFLAGS+=${DL_LIBS} -lm LDFLAGS+=../../shlr/capstone/libcapstone.a endif -include ../../libr/socket/deps.mk -include ../../libr/magic/deps.mk -include ../../libr/main/deps.mk +include ../../librz/socket/deps.mk +include ../../librz/magic/deps.mk +include ../../librz/main/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/gdb/deps.mk include ../../shlr/java/deps.mk diff --git a/binrz/rizin/meson.build b/binrz/rizin/meson.build new file mode 100644 index 0000000000..7185f985e3 --- /dev/null +++ b/binrz/rizin/meson.build @@ -0,0 +1,30 @@ +executable('rizin', 'rizin.c', + include_directories: [platform_inc], + dependencies: [ + rz_util_dep, + rz_main_dep, + rz_socket_dep, + rz_core_dep, + rz_io_dep, + rz_fs_dep, + rz_bin_dep, + rz_flag_dep, + rz_cons_dep, + rz_asm_dep, + rz_debug_dep, + rz_config_dep, + rz_bp_dep, + rz_reg_dep, + rz_syscall_dep, + rz_anal_dep, + rz_parse_dep, + rz_egg_dep, + rz_search_dep, + rz_hash_dep, + rz_crypto_dep, + rz_magic_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/radare2/radare2.c b/binrz/rizin/rizin.c similarity index 73% rename from binr/radare2/radare2.c rename to binrz/rizin/rizin.c index 037702a9be..1ed0107552 100644 --- a/binr/radare2/radare2.c +++ b/binrz/rizin/rizin.c @@ -1,41 +1,41 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #if EMSCRIPTEN__TODO #include -static RCore *core = NULL; +static RzCore *core = NULL; void *r2_asmjs_new(const char *cmd) { - return r_core_new (); + return rz_core_new (); } void r2_asmjs_free(void *core) { - r_core_free (core); + rz_core_free (core); } char *r2_asmjs_cmd(void *kore, const char *cmd) { if (kore) { if (!cmd) { - r_core_free (kore); + rz_core_free (kore); } } else { if (core) { kore = core; } else { - kore = core = r_core_new (); + kore = core = rz_core_new (); } } - return r_core_cmd_str (kore, cmd); + return rz_core_cmd_str (kore, cmd); } static void wget_cb(const char *f) { - r_core_cmdf (core, "o %s", f); + rz_core_cmdf (core, "o %s", f); } void r2_asmjs_openurl(void *kore, const char *url) { - const char *file = r_str_lchr (url, '/'); + const char *file = rz_str_lchr (url, '/'); if (kore) { core = kore; } @@ -69,10 +69,10 @@ static void r2cmd(int in, int out, const char *cmd) { write (1, "\n", 1); } -static int r_main_r2pipe(int argc, const char **argv) { +static int rz_main_rzpipe(int argc, const char **argv) { int i, rc = 0; - char *_in = r_sys_getenv ("R2PIPE_IN"); - char *_out = r_sys_getenv ("R2PIPE_OUT"); + char *_in = rz_sys_getenv ("R2PIPE_IN"); + char *_out = rz_sys_getenv ("R2PIPE_OUT"); if (_in && _out) { int in = atoi (_in); int out = atoi (_out); @@ -81,7 +81,7 @@ static int r_main_r2pipe(int argc, const char **argv) { } } else { eprintf ("Error: R2PIPE_(IN|OUT) environment not set\n"); - eprintf ("Usage: r2 -c '!*r2p x' # run commands via r2pipe\n"); + eprintf ("Usage: r2 -c '!*r2p x' # run commands via rzpipe\n"); rc = 1; } free (_in); @@ -91,9 +91,9 @@ static int r_main_r2pipe(int argc, const char **argv) { int main(int argc, const char **argv) { if (argc > 0 && strstr (argv[0], "r2p")) { - return r_main_r2pipe (argc, argv); + return rz_main_rzpipe (argc, argv); } - return r_main_radare2 (argc, argv); + return rz_main_rizin (argc, argv); } #endif diff --git a/binr/radare2/radare2_ios.xml b/binrz/rizin/rizin_ios.xml similarity index 95% rename from binr/radare2/radare2_ios.xml rename to binrz/rizin/rizin_ios.xml index 7a36570a65..01cf976c95 100644 --- a/binr/radare2/radare2_ios.xml +++ b/binrz/rizin/rizin_ios.xml @@ -31,5 +31,5 @@ diff --git a/binr/radare2/radare2_macos.xml b/binrz/rizin/rizin_macos.xml similarity index 100% rename from binr/radare2/radare2_macos.xml rename to binrz/rizin/rizin_macos.xml diff --git a/binr/rules.mk b/binrz/rules.mk similarity index 81% rename from binr/rules.mk rename to binrz/rules.mk index dff226a7e6..33bbe79ef3 100644 --- a/binr/rules.mk +++ b/binrz/rules.mk @@ -1,5 +1,5 @@ BINR_PROGRAM=1 -include ../../libr/config.mk +include ../../librz/config.mk include ../../shlr/zip/deps.mk include ../../shlr/sdb.mk @@ -9,7 +9,7 @@ endif CFLAGS+=-I$(LTOP)/include ifeq (${COMPILER},emscripten) -LINK+=$(SHLR)/libr_shlr.a +LINK+=$(SHLR)/librz_shlr.a LINK+=$(SHLR)/sdb/src/libsdb.a include $(SHLR)/capstone.mk CFLAGS+= -s SIDE_MODULE=1 @@ -61,13 +61,13 @@ all: ${BEXE} ${BINS} ifeq ($(WITH_LIBR),1) ${BINS}: ${OBJS} - ${CC} ${CFLAGS} $@.c ${OBJS} ../../libr/libr.a -o $@ $(LDFLAGS) + ${CC} ${CFLAGS} $@.c ${OBJS} ../../librz/librz.a -o $@ $(LDFLAGS) ${BEXE}: ${OBJ} ${SHARED_OBJ} ifeq ($(CC),emcc) - emcc $(BIN).c ../../shlr/libr_shlr.a ../../shlr/capstone/libcapstone.a ../../libr/libr.a ../../shlr/gdb/lib/libgdbr.a ../../shlr/zip/librz.a -I ../../libr/include -o $(BIN).js + emcc $(BIN).c ../../shlr/librz_shlr.a ../../shlr/capstone/libcapstone.a ../../librz/librz.a ../../shlr/gdb/lib/libgdbr.a ../../shlr/zip/librz.a -I ../../librz/include -o $(BIN).js else - ${CC} ${CFLAGS} $+ -L.. -o $@ ../../libr/libr.a $(LDFLAGS) + ${CC} ${CFLAGS} $+ -L.. -o $@ ../../librz/librz.a $(LDFLAGS) endif else diff --git a/binr/r2agent/Makefile b/binrz/rz-agent/Makefile similarity index 58% rename from binr/r2agent/Makefile rename to binrz/rz-agent/Makefile index aa5032e1dc..788b8d4deb 100644 --- a/binr/r2agent/Makefile +++ b/binrz/rz-agent/Makefile @@ -1,11 +1,11 @@ include ../../config-user.mk -BIN=r2agent -BINDEPS=r_socket r_cons r_util r_main +BIN=rz-agent +BINDEPS=rz_socket rz_cons rz_util rz_main ifeq ($(OSTYPE),android) LDFLAGS+=${DL_LIBS} -lm endif -include ../../libr/main/deps.mk +include ../../librz/main/deps.mk include ../rules.mk diff --git a/binr/r2agent/meson.build b/binrz/rz-agent/meson.build similarity index 58% rename from binr/r2agent/meson.build rename to binrz/rz-agent/meson.build index 6e083bf9d1..60fc9ae677 100644 --- a/binr/r2agent/meson.build +++ b/binrz/rz-agent/meson.build @@ -1,10 +1,10 @@ -executable('r2agent', 'r2agent.c', +executable('rz-agent', 'rz-agent.c', include_directories: [platform_inc], dependencies: [ - r_util_dep, - r_main_dep, - r_socket_dep, - r_cons_dep + rz_util_dep, + rz_main_dep, + rz_socket_dep, + rz_cons_dep ], install: true, install_rpath: rpath_exe, diff --git a/binrz/rz-agent/rz-agent.c b/binrz/rz-agent/rz-agent.c new file mode 100644 index 0000000000..caecd642bc --- /dev/null +++ b/binrz/rz-agent/rz-agent.c @@ -0,0 +1,7 @@ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ + +#include + +int main(int argc, const char **argv) { + return rz_main_rz_agent (argc, argv); +} diff --git a/binr/rasm2/Makefile b/binrz/rz-asm/Makefile similarity index 72% rename from binr/rasm2/Makefile rename to binrz/rz-asm/Makefile index 74928cfb3f..7a84c92d52 100644 --- a/binr/rasm2/Makefile +++ b/binrz/rz-asm/Makefile @@ -1,8 +1,8 @@ -BIN=rasm2 -BINDEPS=r_main +BIN=rz-asm +BINDEPS=rz_main include ../../config-user.mk -include ../../libr/main/deps.mk +include ../../librz/main/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/java/deps.mk include ../../shlr/capstone.mk diff --git a/binrz/rz-asm/meson.build b/binrz/rz-asm/meson.build new file mode 100644 index 0000000000..a909106ef8 --- /dev/null +++ b/binrz/rz-asm/meson.build @@ -0,0 +1,15 @@ +executable('rz-asm', 'rz-asm.c', + include_directories: [platform_inc], + dependencies: [ + rz_main_dep, + rz_util_dep, + rz_asm_dep, + rz_anal_dep, + rz_crypto_dep, + rz_syscall_dep, + rz_hash_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/rax2/rax2.c b/binrz/rz-asm/rz-asm.c similarity index 62% rename from binr/rax2/rax2.c rename to binrz/rz-asm/rz-asm.c index 108eb871d6..6ccc71670f 100644 --- a/binr/rax2/rax2.c +++ b/binrz/rz-asm/rz-asm.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main (int argc, const char *argv[]) { - return r_main_rax2 (argc, argv); + return rz_main_rz_asm (argc, argv); } diff --git a/binr/rax2/Makefile b/binrz/rz-ax/Makefile similarity index 66% rename from binr/rax2/Makefile rename to binrz/rz-ax/Makefile index e8e243d1ff..5f7e26aef9 100644 --- a/binr/rax2/Makefile +++ b/binrz/rz-ax/Makefile @@ -1,8 +1,8 @@ -BIN=rax2 -BINDEPS=r_util r_main +BIN=rz-ax +BINDEPS=rz_util rz_main include ../rules.mk -include ../../libr/main/deps.mk +include ../../librz/main/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/java/deps.mk include ../../shlr/gdb/deps.mk diff --git a/binr/rax2/meson.build b/binrz/rz-ax/meson.build similarity index 62% rename from binr/rax2/meson.build rename to binrz/rz-ax/meson.build index 26c5bb859d..5bc17494bb 100644 --- a/binr/rax2/meson.build +++ b/binrz/rz-ax/meson.build @@ -1,6 +1,6 @@ -executable('rax2', 'rax2.c', +executable('rz-ax', 'rz-ax.c', include_directories: [platform_inc], - dependencies: [r_util_dep, r_main_dep], + dependencies: [rz_util_dep, rz_main_dep], install: true, install_rpath: rpath_exe, implicit_include_directories: false diff --git a/binr/rasm2/rasm2.c b/binrz/rz-ax/rz-ax.c similarity index 63% rename from binr/rasm2/rasm2.c rename to binrz/rz-ax/rz-ax.c index caaf6981ae..cc9995b230 100644 --- a/binr/rasm2/rasm2.c +++ b/binrz/rz-ax/rz-ax.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main (int argc, const char *argv[]) { - return r_main_rasm2 (argc, argv); + return rz_main_rz_ax (argc, argv); } diff --git a/binrz/rz-bb/Makefile b/binrz/rz-bb/Makefile new file mode 100644 index 0000000000..7de4451c35 --- /dev/null +++ b/binrz/rz-bb/Makefile @@ -0,0 +1,2 @@ +all: + $(CC) -o rz-bb rz-bb.c -L../../librz/util -lrz_util -I../../librz/include diff --git a/binr/r2bb/r2bb.c b/binrz/rz-bb/rz-bb.c similarity index 86% rename from binr/r2bb/r2bb.c rename to binrz/rz-bb/rz-bb.c index c6409c99f0..edb4fbd030 100644 --- a/binr/r2bb/r2bb.c +++ b/binrz/rz-bb/rz-bb.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2017 - pancake */ +/* rizin - LGPL - Copyright 2017 - pancake */ -#include +#include typedef char* (*CommandCallback)(const char *args); @@ -10,8 +10,8 @@ typedef struct { } BbCommands; static BbCommands bbcmds[] = { - { "cat", r_syscmd_cat }, - { "ls", r_syscmd_ls }, + { "cat", rz_syscmd_cat }, + { "ls", rz_syscmd_ls }, NULL }; diff --git a/binrz/rz-bin/Makefile b/binrz/rz-bin/Makefile new file mode 100644 index 0000000000..c5172c1865 --- /dev/null +++ b/binrz/rz-bin/Makefile @@ -0,0 +1,20 @@ +BIN=rz-bin +BINDEPS=rz_magic rz_core rz_bin rz_egg rz_cons rz_main +BINDEPS+=rz_config rz_io rz_flag rz_asm +BINDEPS+=rz_debug rz_hash rz_lang rz_anal rz_parse rz_bp rz_reg +BINDEPS+=rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto rz_util + +include ../rules.mk + +include ../../librz/socket/deps.mk +include ../../librz/main/deps.mk +include ../../shlr/zip/deps.mk +include ../../shlr/gdb/deps.mk +include ../../shlr/java/deps.mk +include ../../shlr/grub/deps.mk +include ../../shlr/bochs/deps.mk +include ../../shlr/qnx/deps.mk +include ../../shlr/ar/deps.mk +include ../../shlr/capstone.mk + +LDFLAGS+=$(LINK) diff --git a/binrz/rz-bin/meson.build b/binrz/rz-bin/meson.build new file mode 100644 index 0000000000..e48685b4d3 --- /dev/null +++ b/binrz/rz-bin/meson.build @@ -0,0 +1,18 @@ +executable('rz-bin', 'rz-bin.c', + include_directories: [platform_inc], + dependencies: [ + rz_util_dep, + rz_cons_dep, + rz_main_dep, + rz_config_dep, + rz_hash_dep, + rz_io_dep, + rz_crypto_dep, + rz_core_dep, + rz_magic_dep, + rz_bin_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/rabin2/patch.txt b/binrz/rz-bin/patch.txt similarity index 100% rename from binr/rabin2/patch.txt rename to binrz/rz-bin/patch.txt diff --git a/binr/rabin2/rabin2.c b/binrz/rz-bin/rz-bin.c similarity index 62% rename from binr/rabin2/rabin2.c rename to binrz/rz-bin/rz-bin.c index 29597bb0a6..f690cc9d8e 100644 --- a/binr/rabin2/rabin2.c +++ b/binrz/rz-bin/rz-bin.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main(int argc, const char **argv) { - return r_main_rabin2 (argc, argv); + return rz_main_rz_bin (argc, argv); } diff --git a/binrz/rz-diff/Makefile b/binrz/rz-diff/Makefile new file mode 100644 index 0000000000..5c9d9170cf --- /dev/null +++ b/binrz/rz-diff/Makefile @@ -0,0 +1,22 @@ +BIN=rz-diff + +BINDEPS=rz_core rz_config rz_cons rz_search rz_anal +BINDEPS+=rz_bin rz_debug rz_io rz_asm rz_hash rz_fs rz_crypto +BINDEPS+=rz_socket rz_flag rz_lang rz_reg rz_bp rz_parse +BINDEPS+=rz_syscall rz_magic rz_util rz_parse rz_egg rz_main + +include ../rules.mk + +ifeq ($(OSTYPE),android) +LDFLAGS+=${DL_LIBS} -lm +endif + +include ../../librz/socket/deps.mk +include ../../librz/main/deps.mk +include ../../shlr/zip/deps.mk +include ../../shlr/gdb/deps.mk +include ../../shlr/bochs/deps.mk +include ../../shlr/qnx/deps.mk +include ../../shlr/ar/deps.mk + +LDFLAGS+=$(LINK) diff --git a/binrz/rz-diff/meson.build b/binrz/rz-diff/meson.build new file mode 100644 index 0000000000..a910c7b765 --- /dev/null +++ b/binrz/rz-diff/meson.build @@ -0,0 +1,19 @@ +executable('rz-diff', 'rz-diff.c', + include_directories: [platform_inc], + dependencies: [ + rz_util_dep, + rz_main_dep, + rz_io_dep, + rz_search_dep, + rz_cons_dep, + rz_core_dep, + rz_bin_dep, + rz_anal_dep, + rz_asm_dep, + rz_hash_dep, + rz_config_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/radiff2/radiff2.c b/binrz/rz-diff/rz-diff.c similarity index 62% rename from binr/radiff2/radiff2.c rename to binrz/rz-diff/rz-diff.c index fa360f3f52..210eba2514 100644 --- a/binr/radiff2/radiff2.c +++ b/binrz/rz-diff/rz-diff.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include int main (int argc, const char *argv[]) { - return r_main_radiff2 (argc, argv); + return rz_main_rz_diff (argc, argv); } diff --git a/binrz/rz-find/Makefile b/binrz/rz-find/Makefile new file mode 100644 index 0000000000..303d97d9ba --- /dev/null +++ b/binrz/rz-find/Makefile @@ -0,0 +1,15 @@ +BIN=rz-find + +BINDEPS=rz_search rz_io rz_asm rz_anal rz_reg rz_cons rz_lang rz_crypto +BINDEPS+=rz_socket rz_parse rz_util rz_syscall rz_flag rz_hash rz_main + +include ../rules.mk + +include ../../librz/socket/deps.mk +include ../../librz/main/deps.mk +include ../../shlr/zip/deps.mk +include ../../shlr/gdb/deps.mk +include ../../shlr/bochs/deps.mk +include ../../shlr/qnx/deps.mk +include ../../shlr/ar/deps.mk +LDFLAGS+=$(LINK) diff --git a/binrz/rz-find/meson.build b/binrz/rz-find/meson.build new file mode 100644 index 0000000000..caf791143f --- /dev/null +++ b/binrz/rz-find/meson.build @@ -0,0 +1,15 @@ +executable('rz-find', 'rz-find.c', + include_directories: [platform_inc], + dependencies: [ + rz_main_dep, + rz_util_dep, + rz_search_dep, + rz_crypto_dep, + rz_io_dep, + rz_main_dep, + rz_cons_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/rafind2/rafind2.c b/binrz/rz-find/rz-find.c similarity index 62% rename from binr/rafind2/rafind2.c rename to binrz/rz-find/rz-find.c index b44690a82b..1c76a24237 100644 --- a/binr/rafind2/rafind2.c +++ b/binrz/rz-find/rz-find.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main(int argc, const char **argv) { - return r_main_rafind2 (argc, argv); + return rz_main_rz_find (argc, argv); } diff --git a/binrz/rz-gg/Makefile b/binrz/rz-gg/Makefile new file mode 100644 index 0000000000..64d647231d --- /dev/null +++ b/binrz/rz-gg/Makefile @@ -0,0 +1,19 @@ +BIN=rz-gg +BINDEPS=rz_egg rz_syscall rz_asm +BINDEPS+=rz_core rz_hash rz_debug rz_fs rz_config rz_bp rz_crypto rz_cons +BINDEPS+=rz_lang rz_parse rz_anal rz_reg rz_flag rz_crypto +BINDEPS+=rz_bin rz_search rz_io rz_socket +BINDEPS+=rz_magic rz_util rz_main + +include ../rules.mk +include ../../librz/main/deps.mk +include ../../shlr/ar/deps.mk +include ../../librz/socket/deps.mk +include ../../shlr/bochs/deps.mk +include ../../shlr/gdb/deps.mk +include ../../shlr/grub/deps.mk +include ../../shlr/java/deps.mk +include ../../shlr/capstone.mk +include ../../shlr/qnx/deps.mk + +LDFLAGS+=$(LINK) diff --git a/binrz/rz-gg/meson.build b/binrz/rz-gg/meson.build new file mode 100644 index 0000000000..472a20bb03 --- /dev/null +++ b/binrz/rz-gg/meson.build @@ -0,0 +1,19 @@ +executable('rz-gg', 'rz-gg.c', + include_directories: [platform_inc], + dependencies: [ + rz_util_dep, + rz_main_dep, + rz_egg_dep, + rz_bin_dep, + rz_core_dep, + rz_hash_dep, + rz_debug_dep, + rz_fs_dep, + rz_config_dep, + rz_bp_dep, + rz_crypto_dep + ], + install: true, + install_rpath: rpath_exe, + implicit_include_directories: false +) diff --git a/binr/ragg2/ragg2.c b/binrz/rz-gg/rz-gg.c similarity index 62% rename from binr/ragg2/ragg2.c rename to binrz/rz-gg/rz-gg.c index 12cb731278..fd4a749a32 100644 --- a/binr/ragg2/ragg2.c +++ b/binrz/rz-gg/rz-gg.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2007-2019 - pancake */ -#include +#include int main(int argc, const char **argv) { - return r_main_ragg2 (argc, argv); + return rz_main_rz_gg (argc, argv); } diff --git a/binr/ragg2/shellcodes.c.src b/binrz/rz-gg/shellcodes.c.src similarity index 100% rename from binr/ragg2/shellcodes.c.src rename to binrz/rz-gg/shellcodes.c.src diff --git a/binr/ragg2/syscall.r b/binrz/rz-gg/syscall.r similarity index 100% rename from binr/ragg2/syscall.r rename to binrz/rz-gg/syscall.r diff --git a/binr/ragg2/xorencoder.asm b/binrz/rz-gg/xorencoder.asm similarity index 85% rename from binr/ragg2/xorencoder.asm rename to binrz/rz-gg/xorencoder.asm index e35eb0c103..877045e5e5 100755 --- a/binr/ragg2/xorencoder.asm +++ b/binrz/rz-gg/xorencoder.asm @@ -1,6 +1,6 @@ -#!/usr/bin/rasm2 -a x86 -b 64 -f +#!/usr/bin/rz_asm -a x86 -b 64 -f # - pancake xor encoder egg engine # -# rasm2 -a x86.nasm -f xorencoder.asm +# rz_asm -a x86.nasm -f xorencoder.asm .equ CODESIZE,22 .equ BASE,0x29 diff --git a/binr/rahash2/Makefile b/binrz/rz-hash/Makefile similarity index 73% rename from binr/rahash2/Makefile rename to binrz/rz-hash/Makefile index 022829fc9e..eb426ffeac 100644 --- a/binr/rahash2/Makefile +++ b/binrz/rz-hash/Makefile @@ -1,6 +1,6 @@ -BIN=rahash2 +BIN=rz-hash -BINDEPS=r_main +BINDEPS=rz_main include ../rules.mk @@ -8,8 +8,8 @@ ifeq ($(OSTYPE),android) LDFLAGS+=-lm endif -include ../../libr/socket/deps.mk -include ../../libr/main/deps.mk +include ../../librz/socket/deps.mk +include ../../librz/main/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/gdb/deps.mk include ../../shlr/bochs/deps.mk diff --git a/binr/rahash2/meson.build b/binrz/rz-hash/meson.build similarity index 51% rename from binr/rahash2/meson.build rename to binrz/rz-hash/meson.build index 1b8ca18de0..a22fb0a078 100644 --- a/binr/rahash2/meson.build +++ b/binrz/rz-hash/meson.build @@ -1,12 +1,12 @@ -executable('rahash2', 'rahash2.c', +executable('rz-hash', 'rz-hash.c', include_directories: [platform_inc], dependencies: [ - r_util_dep, - r_main_dep, - r_hash_dep, - r_io_dep, - r_crypto_dep, - r_socket_dep + rz_util_dep, + rz_main_dep, + rz_hash_dep, + rz_io_dep, + rz_crypto_dep, + rz_socket_dep ], install: true, install_rpath: rpath_exe, diff --git a/binr/rahash2/rahash2.c b/binrz/rz-hash/rz-hash.c similarity index 62% rename from binr/rahash2/rahash2.c rename to binrz/rz-hash/rz-hash.c index ed84f266f7..97e5074985 100644 --- a/binr/rahash2/rahash2.c +++ b/binrz/rz-hash/rz-hash.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main(int argc, const char **argv) { - return r_main_rahash2(argc, argv); + return rz_main_rz_hash(argc, argv); } diff --git a/binrz/rz-pm/meson.build b/binrz/rz-pm/meson.build new file mode 100644 index 0000000000..ab3546e3a8 --- /dev/null +++ b/binrz/rz-pm/meson.build @@ -0,0 +1 @@ +install_data('rz-pm', install_dir: get_option('bindir')) diff --git a/binr/r2pm/r2pm b/binrz/rz-pm/rz-pm similarity index 83% rename from binr/r2pm/r2pm rename to binrz/rz-pm/rz-pm index f4f1eabd4d..11df5c14f7 100755 --- a/binr/r2pm/r2pm +++ b/binrz/rz-pm/rz-pm @@ -1,6 +1,6 @@ #!/bin/sh -# r2pm +# rz-pm # Honor user environment [ -z "${SUDO}" ] && SUDO=sudo [ -z "${WGET}" ] && WGET=wget @@ -19,7 +19,7 @@ gmake --help >/dev/null 2>&1 export MAKE export GLOBAL=0 export R2PM_JOBS=4 -export R2PMCACHE="$HOME/.r2pm.cache" +export R2PMCACHE="$HOME/.rz-pm.cache" # Set R2_* Vars eval $(r2 -H) @@ -27,15 +27,15 @@ export R2_VERSION R2PM=$0 R2PMCACHE_LOADED=0 -if [ -f ~/.r2pm.cache ]; then - . ~/.r2pm.cache +if [ -f ~/.rz-pm.cache ]; then + . ~/.rz-pm.cache export LIBEXT="$LIBEXT" LIBDIR="$LIBDIR" export R2CONFIGHOME="$R2CONFIGHOME" export R2DATAHOME="$R2DATAHOME" PREFIX="$PREFIX" if [ -z "${LIBEXT}" -o -z "${LIBDIR}" -o -z "${R2CONFIGHOME}" -o -z "${R2DATAHOME}" -o -z "${PREFIX}" ]; then - echo "[r2pm] corrupted cache, please run r2pm cache" + echo "[rz-pm] corrupted cache, please run rz-pm cache" else R2PMCACHE_LOADED=1 fi @@ -96,21 +96,21 @@ fi TRAVIS_TYPE=XX TRAVIS_JOB=86948888 IS_SYSPKG=0 -[ -z "$R2PM_USRDIR" ] && R2PM_USRDIR="${R2DATAHOME}/r2pm" -R2PM_ETCD="${R2CONFIGHOME}/radare2rc.d" +[ -z "$R2PM_USRDIR" ] && R2PM_USRDIR="${R2DATAHOME}/rz-pm" +R2PM_ETCD="${R2CONFIGHOME}/rizinrc.d" -# TODO. support system plugin installs R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/radare2/last" +# TODO. support system plugin installs R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/rizin/last" if [ -z "${R2PM_GITDIR}" ]; then R2PM_GITDIR="${R2PM_USRDIR}/git" fi if [ -z "${R2PM_DBDIR}" ]; then - if [ -d "${R2DATAHOME}/r2pm/db" ]; then - R2PM_DBDIR="${R2DATAHOME}/r2pm/db" + if [ -d "${R2DATAHOME}/rz-pm/db" ]; then + R2PM_DBDIR="${R2DATAHOME}/rz-pm/db" fi fi if [ -z "${R2PM_DBDIR}" ]; then - if [ -d "${PREFIX}/share/radare2/last/r2pm" ]; then - R2PM_DBDIR="${PREFIX}/share/radare2/last/r2pm/" + if [ -d "${PREFIX}/share/rizin/last/rz-pm" ]; then + R2PM_DBDIR="${PREFIX}/share/rizin/last/rz-pm/" fi fi if [ -f "d/baleful" ]; then @@ -128,15 +128,15 @@ confirm() { purgeR2() { P="$1" - BINS="r2 radare2 rabin2 rafind2 r2pm " + BINS="r2 rizin rz_bin rz_find rz-pm " cd "$P/bin" && rm -f ${BINS} cd "$P/lib" && rm -f libr_* - cd "$P/lib" && rm -rf radare2 + cd "$P/lib" && rm -rf rizin cd "$P/lib64" && rm -f libr_* - cd "$P/lib64" && rm -rf radare2 - cd "$P/share" && rm -rf radare2 + cd "$P/lib64" && rm -rf rizin + cd "$P/share" && rm -rf rizin cd "$P/share/man" && rm -rf man1/r*2.1 - cd "$P/share/doc" && rm -rf radare2 + cd "$P/share/doc" && rm -rf rizin } countDown() { @@ -161,10 +161,10 @@ commitSuicide() { confirm "> Delete $RHOMEDIR" && ( rm -rf "$RHOMEDIR" ) - R2PATHS="${PREFIX}:/usr:/usr/local:/opt/radare2:${RHOMEDIR}/prefix:/" + R2PATHS="${PREFIX}:/usr:/usr/local:/opt/rizin:${RHOMEDIR}/prefix:/" IFS=: for a in $R2PATHS ; do - if [ -x "${a}/bin/radare2" ]; then + if [ -x "${a}/bin/rizin" ]; then confirm "> Delete r2 from ${a}" && ( purgeR2 "$a" ) @@ -179,14 +179,14 @@ init|up|update) mkdir -p "${R2PM_GITDIR}" mkdir -p "${HOME}/.config" cd "${R2PM_GITDIR}" - if [ -d radare2-pm ]; then - cd radare2-pm + if [ -d rizin-pm ]; then + cd rizin-pm git reset --hard @^^ git pull else - echo git clone https://github.com/radareorg/radare2-pm - git clone --depth=3 --recursive https://github.com/radareorg/radare2-pm - cd radare2-pm + echo git clone https://github.com/rizinorg/rizin-pm + git clone --depth=3 --recursive https://github.com/rizinorg/rizin-pm + cd rizin-pm pwd fi for a in "${R2PM_DBDIR}" "${R2PM_USRDIR}"/db2/*/db ; do @@ -205,16 +205,16 @@ init|up|update) rm -f "${R2PM_DBDIR}" fi - ln -fs "${R2PM_GITDIR}/radare2-pm/db" "${R2PM_DBDIR}" + ln -fs "${R2PM_GITDIR}/rizin-pm/db" "${R2PM_DBDIR}" if [ "$1" = "init" ]; then - echo "r2pm database initialized. Use 'r2pm update' to update later today." + echo "rz-pm database initialized. Use 'rz-pm update' to update later today." fi exit 0 ;; esac if [ ! -d "${R2PM_DBDIR}" ]; then echo '$R2PM_DBDIR: No such file or directory.' - echo "Run 'r2pm init' to initialize the package repository" + echo "Run 'rz-pm init' to initialize the package repository" exit 1 fi @@ -378,7 +378,7 @@ R2PM_Info() { cd "${R2PM_USRDIR}/pkg" echo "# Installed:" printf "# %s Packages\n# " "$(ls | wc -l)" >&2 - du -hs "${HOME}/.config/radare2" >&2 + du -hs "${HOME}/.config/rizin" >&2 } R2PM_REGISTER() { @@ -401,13 +401,13 @@ R2PM_DEPS() { fi for a in "$@" ; do echo "DEPENDS: $a" - r2pm -w "$a" + rz-pm -w "$a" doInstall=$? if [ "${R2PM_UPGRADE}" ]; then doInstall=1 fi if [ $doInstall = 1 ]; then - r2pm -i "$a" + rz-pm -i "$a" fi done } @@ -421,9 +421,9 @@ pkgFilePath() { done } -r2pm_doc() { +rz-pm_doc() { if [ -z "$2" ]; then - echo "Usage: r2pm -d [package] # show docs on [package]" + echo "Usage: rz-pm -d [package] # show docs on [package]" exit 1 else FILE="$(pkgFilePath "$1")" @@ -434,7 +434,7 @@ r2pm_doc() { fi } -r2pm_install() { +rz-pm_install() { FILE="$(pkgFilePath "$2")" if [ -f "${FILE}" ]; then NAME="$2" @@ -449,9 +449,9 @@ r2pm_install() { fi } -r2pm_uninstall() { +rz-pm_uninstall() { if [ -z "$2" ]; then - echo "Usage: r2pm -u [package] # uninstall [package]" + echo "Usage: rz-pm -u [package] # uninstall [package]" exit 1 else FILE="`pkgFilePath $2`" @@ -480,11 +480,11 @@ case "$1" in ;; -i|install) if [ -z "$2" ]; then - echo "Usage: r2pm -i [package] # install [package]" + echo "Usage: rz-pm -i [package] # install [package]" exit 1 elif [ "$2" = "all" ]; then for a in `cd ${R2PM_DBDIR} && ls` ; do - r2pm_install "$a" + rz-pm_install "$a" if [ "$?" != 0 ]; then printf "\033[31mERROR: Installation failed for $a\033[0m\n" fi @@ -492,7 +492,7 @@ case "$1" in else A1="$1" while [ -n "$2" ] ; do - r2pm_install $A1 "$2" + rz-pm_install $A1 "$2" shift done fi @@ -503,14 +503,14 @@ case "$1" in rm -f "${FILE}" ;; -u|uninstall) - r2pm_uninstall "$@" + rz-pm_uninstall "$@" ;; -t|test) [ -n "$2" ] && TRAVIS_TYPE="$2" if [ -n "$3" ]; then TRAVIS_JOB="$3" else - TRAVIS_JOB=`${CURL} -s https://api.travis-ci.com/repos?slug=radare%2Fradare2| jq .[0].last_build_id` + TRAVIS_JOB=`${CURL} -s https://api.travis-ci.com/repos?slug=radare%2Frizin| jq .[0].last_build_id` TRAVIS_JOB=$(($TRAVIS_JOB+1)) fi echo $TRAVIS_JOB >&2 @@ -532,30 +532,30 @@ case "$1" in PATH="${R2PM_BINDIR}:${PATH}" "$@" ;; -v|version) - echo "r2pm ${R2_VERSION}" + echo "rz-pm ${R2_VERSION}" ;; -gi|global-install) GLOBAL=1 R2PM_PREFIX="${R2PM_SYSPREFIX}" - #R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/radare2/${R2_VERSION}/" + #R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/rizin/${R2_VERSION}/" R2PM_PLUGDIR="${R2PM_SYSPLUGIN_DIR}" R2PM_BINDIR="${R2PM_SYSBINDIR}" R2PM_WWWROOT="${R2PM_SYSWWWROOT}" - #TODO set R2PM_ETCD= to a "global" radare2rc.d + #TODO set R2PM_ETCD= to a "global" rizinrc.d if [ ! -d "${R2PM_PLUGDIR}" ]; then mkdir -p "${R2PM_PLUGDIR}" fi - r2pm_install "$@" + rz-pm_install "$@" ;; -gu|global-uninstall) GLOBAL=1 R2PM_PREFIX="${R2PM_SYSPREFIX}" - #R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/radare2/${R2_VERSION}/" + #R2PM_PLUGDIR="${R2PM_SYSLIBDIR}/rizin/${R2_VERSION}/" R2PM_PLUGDIR="${R2PM_SYSPLUGIN_DIR}" R2PM_BINDIR="${R2PM_SYSBINDIR}" R2PM_WWWROOT="${R2PM_SYSWWWROOT}" - #TODO set R2PM_ETCD= to a "global" radare2rc.d - r2pm_uninstall "$@" + #TODO set R2PM_ETCD= to a "global" rizinrc.d + rz-pm_uninstall "$@" ;; -cp) if [ -n "${R2PM_PLUGDIR}" ]; then @@ -595,14 +595,14 @@ case "$1" in done exit $RC else - R2PM_List radare2 | grep radare2 + R2PM_List rizin | grep rizin if [ $? != 0 ]; then echo "Press enter to remove the GITDIR or ^C to cancel operation" read A rm -rf "${R2PM_GITDIR}" mkdir -p "${R2PM_GITDIR}" else - echo "r2 is installed with r2pm, do not clean the cache to avoid autodestruction" + echo "r2 is installed with rz-pm, do not clean the cache to avoid autodestruction" echo "do not disassemble do not disassemble do not disassemble do not disassemble" exit 1 fi @@ -621,11 +621,11 @@ cd) cd "${R2PM_GITDIR}/$2" export R2PM_LEVEL=$((${R2PM_LEVEL}+1)) echo "Entering into ${SHELL} level ${R2PM_LEVEL}." - PS1="r2pm:${R2PM_LEVEL}:\W\$ " ${SHELL} + PS1="rz-pm:${R2PM_LEVEL}:\W\$ " ${SHELL} echo "Exiting level ${R2PM_LEVEL}." exit 0 else - echo "Missing argument. See r2pm ls" + echo "Missing argument. See rz-pm ls" exit 1 fi ;; @@ -643,15 +643,15 @@ cache) echo "export R2CONFIGHOME=\"${R2CONFIGHOME}\"" >> "${R2PMCACHE}" echo "export R2DATAHOME=\"${R2DATAHOME}\"" >> "${R2PMCACHE}" echo "export PREFIX=\"${PREFIX}\"" >> "${R2PMCACHE}" - echo "[r2pm] r2 environment cached in ${R2PMCACHE}" + echo "[rz-pm] r2 environment cached in ${R2PMCACHE}" ;; -a|add) if [ "$2" = "help" ]; then printf '%s\n' \ - "Usage: r2pm -a [url] ([name]) # manage package repositories" \ - " $ r2pm -a https://github.com/foo/bar # register bar repo" \ - " $ r2pm -a # list all repos" \ - " $ r2pm -a - bar # delete 'foo' repo" + "Usage: rz-pm -a [url] ([name]) # manage package repositories" \ + " $ rz-pm -a https://github.com/foo/bar # register bar repo" \ + " $ rz-pm -a # list all repos" \ + " $ rz-pm -a - bar # delete 'foo' repo" exit 1 fi cd "${R2PM_DBDIR}" @@ -681,7 +681,7 @@ cache) git clone --recursive --depth=2 "$URL" "$NAME" fi if [ ! -d "$NAME/db" ]; then - echo "This is not an r2pm repository" + echo "This is not an rz-pm repository" rm -rf "$NAME" exit 1 fi @@ -693,7 +693,7 @@ cache) ;; -H) if [ -z "$2" ]; then - echo "Usage: r2pm -H [VARNAME]" + echo "Usage: rz-pm -H [VARNAME]" echo "Variables: R2PM_PLUGDIR R2PM_BINDIR R2PM_DBDIR R2PM_GITDIR" exit 1 fi @@ -703,17 +703,17 @@ suicide) commitSuicide ;; -d|doc|--doc) - r2pm_doc "$2" + rz-pm_doc "$2" ;; *|help|-h) cat < install or update package in your home (pkgname=all) -gi,global-install install or update package system-wide -gu,global-uninstall uninstall pkg from systemdir - -u,uninstall r2pm -u baleful (-uu to force) + -u,uninstall rz-pm -u baleful (-uu to force) -l,list list installed pkgs -r,run [cmd ...args] run shell command with R2PM_BINDIR in PATH -s,search [] search in database @@ -727,10 +727,10 @@ Commands: -d,doc [pkgname] show documentation for given package -w what/where is installed init | update .. initialize/update database - cd [git/dir] cd into given git (see 'r2pm ls') + cd [git/dir] cd into given git (see 'rz-pm ls') ls ls all cloned git repos in GITDIR suicide self remove all (home + system) installations of r2 - cache cache contents of r2 -H to make r2pm r2-independent + cache cache contents of r2 -H to make rz-pm r2-independent Environment: SUDO=sudo use this tool as sudo R2PM_PLUGDIR=${R2PM_PLUGDIR} diff --git a/binrz/rz-run/Makefile b/binrz/rz-run/Makefile new file mode 100644 index 0000000000..9acd294b84 --- /dev/null +++ b/binrz/rz-run/Makefile @@ -0,0 +1,8 @@ +BIN=rz-run +BINDEPS=rz_socket rz_util rz_main + +include ../rules.mk +include ../../librz/main/deps.mk +include ../../shlr/zip/deps.mk +include ../../librz/socket/deps.mk +LDFLAGS+=$(LINK) diff --git a/binr/rarun2/meson.build b/binrz/rz-run/meson.build similarity index 63% rename from binr/rarun2/meson.build rename to binrz/rz-run/meson.build index 616e30b657..a2a5444a5a 100644 --- a/binr/rarun2/meson.build +++ b/binrz/rz-run/meson.build @@ -1,9 +1,9 @@ -executable('rarun2', 'rarun2.c', +executable('rz-run', 'rz-run.c', include_directories: [platform_inc], dependencies: [ - r_main_dep, - r_util_dep, - r_socket_dep + rz_main_dep, + rz_util_dep, + rz_socket_dep ], install: true, install_rpath: rpath_exe, diff --git a/binrz/rz-run/rz-run.c b/binrz/rz-run/rz-run.c new file mode 100644 index 0000000000..b450945b19 --- /dev/null +++ b/binrz/rz-run/rz-run.c @@ -0,0 +1,7 @@ +/* rizin - Copyleft 2011-2019 - pancake */ + +#include + +int main(int argc, const char **argv) { + return rz_main_rz_run (argc, argv); +} diff --git a/binrz/rz-sign/Makefile b/binrz/rz-sign/Makefile new file mode 100644 index 0000000000..3c6e274546 --- /dev/null +++ b/binrz/rz-sign/Makefile @@ -0,0 +1,6 @@ +BIN=rz-sign +BINDEPS=rz_anal rz_util rz_core rz_search rz_main +LDFLAGS+=$(LINK) + +include ../../librz/main/deps.mk +include ../rules.mk diff --git a/binr/rasign2/meson.build b/binrz/rz-sign/meson.build similarity index 54% rename from binr/rasign2/meson.build rename to binrz/rz-sign/meson.build index f148092ee0..0479de136e 100644 --- a/binr/rasign2/meson.build +++ b/binrz/rz-sign/meson.build @@ -1,11 +1,11 @@ -executable('rasign2', 'rasign2.c', +executable('rz-sign', 'rz-sign.c', include_directories: [platform_inc], dependencies: [ - r_util_dep, - r_main_dep, - r_search_dep, - r_core_dep, - r_bin_dep, + rz_util_dep, + rz_main_dep, + rz_search_dep, + rz_core_dep, + rz_bin_dep, ], install: true, install_rpath: rpath_exe, diff --git a/binr/rasign2/rasign2.c b/binrz/rz-sign/rz-sign.c similarity index 61% rename from binr/rasign2/rasign2.c rename to binrz/rz-sign/rz-sign.c index 08a7755ddc..a20c763fa8 100644 --- a/binr/rasign2/rasign2.c +++ b/binrz/rz-sign/rz-sign.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include int main(int argc, const char **argv) { - return r_main_rasign2 (argc, argv); + return rz_main_rz_sign (argc, argv); } diff --git a/binr/r2r/Makefile b/binrz/rz-test/Makefile similarity index 74% rename from binr/r2r/Makefile rename to binrz/rz-test/Makefile index dc2333bfce..5d79311f52 100644 --- a/binr/r2r/Makefile +++ b/binrz/rz-test/Makefile @@ -1,5 +1,5 @@ -BIN=r2r -BINDEPS=r_util +BIN=rz-test +BINDEPS=rz_util OBJ=load.o run.o include ../rules.mk diff --git a/binr/r2r/load.c b/binrz/rz-test/load.c similarity index 75% rename from binr/r2r/load.c rename to binrz/rz-test/load.c index 7bb04af3a7..c038686dee 100644 --- a/binr/r2r/load.c +++ b/binrz/rz-test/load.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2020 - thestr4ng3r */ -#include "r2r.h" +#include "rz_test.h" #include #define LINEFMT "%s, line %"PFMT64u": " -R_API R2RCmdTest *r2r_cmd_test_new(void) { - return R_NEW0 (R2RCmdTest); +RZ_API R2RzCmdTest *rz_test_cmd_test_new(void) { + return R_NEW0 (R2RzCmdTest); } -R_API void r2r_cmd_test_free(R2RCmdTest *test) { +RZ_API void rz_test_cmd_test_free(R2RzCmdTest *test) { if (!test) { return; } @@ -70,7 +70,7 @@ static char *read_string_val(char **nextline, const char *val, ut64 *linenum) { eprintf ("Error: End token must be \"EOF\", got \"%s\" instead.", endtoken); return NULL; } - RStrBuf *buf = r_strbuf_new (""); + RStrBuf *buf = rz_strbuf_new (""); char *line = *nextline; size_t linesz = 0; do { @@ -86,37 +86,37 @@ static char *read_string_val(char **nextline, const char *val, ut64 *linenum) { if (end) { *end = '\0'; } - r_strbuf_append (buf, line); + rz_strbuf_append (buf, line); if (end) { - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } else { - r_strbuf_append (buf, "\n"); + rz_strbuf_append (buf, "\n"); } } while ((line = *nextline)); eprintf ("Error: Missing closing end token %s\n", endtoken); - r_strbuf_free (buf); + rz_strbuf_free (buf); return NULL; } return strdup (val); } -R_API RPVector *r2r_load_cmd_test_file(const char *file) { - char *contents = r_file_slurp (file, NULL); +RZ_API RPVector *rz_test_load_cmd_test_file(const char *file) { + char *contents = rz_file_slurp (file, NULL); if (!contents) { eprintf ("Failed to open file \"%s\"\n", file); return NULL; } - RPVector *ret = r_pvector_new (NULL); + RPVector *ret = rz_pvector_new (NULL); if (!ret) { free (contents); return NULL; } - R2RCmdTest *test = r2r_cmd_test_new (); + R2RzCmdTest *test = rz_test_cmd_test_new (); if (!test) { free (contents); - r_pvector_free (ret); + rz_pvector_free (ret); return NULL; } @@ -151,8 +151,8 @@ R_API RPVector *r2r_load_cmd_test_file(const char *file) { " (did you forget an EOF?)\n", file, linenum); goto fail; } - r_pvector_push (ret, test); - test = r2r_cmd_test_new (); + rz_pvector_push (ret, test); + test = rz_test_cmd_test_new (); if (!test) { goto beach; } @@ -244,21 +244,21 @@ beach: if (test && (test->name.value || test->cmds.value || test->expect.value)) { eprintf ("Warning: found test tokens at the end of \"%s\" without RUN.\n", file); } - r2r_cmd_test_free (test); + rz_test_cmd_test_free (test); return ret; fail: - r2r_cmd_test_free (test); + rz_test_cmd_test_free (test); test = NULL; - r_pvector_free (ret); + rz_pvector_free (ret); ret = NULL; goto beach; } -R_API R2RAsmTest *r2r_asm_test_new(void) { - return R_NEW0 (R2RAsmTest); +RZ_API R2RzAsmTest *rz_test_asm_test_new(void) { + return R_NEW0 (R2RzAsmTest); } -R_API void r2r_asm_test_free(R2RAsmTest *test) { +RZ_API void rz_test_asm_test_free(R2RzAsmTest *test) { if (!test) { return; } @@ -268,9 +268,9 @@ R_API void r2r_asm_test_free(R2RAsmTest *test) { } static bool parse_asm_path(const char *path, RStrConstPool *strpool, const char **arch_out, const char **cpuout, int *bitsout) { - RList *file_tokens = r_str_split_duplist (path, R_SYS_DIR, true); - if (!file_tokens || r_list_empty (file_tokens)) { - r_list_free (file_tokens); + RzList *file_tokens = rz_str_split_duplist (path, R_SYS_DIR, true); + if (!file_tokens || rz_list_empty (file_tokens)) { + rz_list_free (file_tokens); return false; } @@ -279,9 +279,9 @@ static bool parse_asm_path(const char *path, RStrConstPool *strpool, const char // arm_32 // arm_cortex_32 - char *arch = r_list_last (file_tokens); + char *arch = rz_list_last (file_tokens); if (!*arch) { - r_list_free (file_tokens); + rz_list_free (file_tokens); return false; } char *second = strchr (arch, '_'); @@ -292,7 +292,7 @@ static bool parse_asm_path(const char *path, RStrConstPool *strpool, const char if (third) { *third = '\0'; third++; - *cpuout = r_str_constpool_get (strpool, second); + *cpuout = rz_str_constpool_get (strpool, second); *bitsout = atoi (third); } else { *cpuout = NULL; @@ -302,12 +302,12 @@ static bool parse_asm_path(const char *path, RStrConstPool *strpool, const char *cpuout = NULL; *bitsout = 0; } - *arch_out = r_str_constpool_get (strpool, arch); - r_list_free (file_tokens); + *arch_out = rz_str_constpool_get (strpool, arch); + rz_list_free (file_tokens); return true; } -R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) { +RZ_API RPVector *rz_test_load_asm_test_file(RStrConstPool *strpool, const char *file) { const char *arch; const char *cpu; int bits; @@ -316,13 +316,13 @@ R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) return NULL; } - char *contents = r_file_slurp (file, NULL); + char *contents = rz_file_slurp (file, NULL); if (!contents) { eprintf ("Failed to open file \"%s\"\n", file); return NULL; } - RPVector *ret = r_pvector_new (NULL); + RPVector *ret = rz_pvector_new (NULL); if (!ret) { return NULL; } @@ -380,7 +380,7 @@ R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) } *hex = '\0'; hex++; - r_str_trim (disasm); + rz_str_trim (disasm); while (*hex && *hex == ' ') { hex++; @@ -401,7 +401,7 @@ R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) if (!bytes) { break; } - int bytesz = r_hex_str2bin (hex, bytes); + int bytesz = rz_hex_str2bin (hex, bytes); if (bytesz == 0) { eprintf (LINEFMT "Error: Expected hex chars.\n", file, linenum); goto fail; @@ -411,7 +411,7 @@ R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) goto fail; } - R2RAsmTest *test = r2r_asm_test_new (); + R2RzAsmTest *test = rz_test_asm_test_new (); if (!test) { free (bytes); goto fail; @@ -425,23 +425,23 @@ R_API RPVector *r2r_load_asm_test_file(RStrConstPool *strpool, const char *file) test->disasm = strdup (disasm); test->bytes = bytes; test->bytes_size = (size_t)bytesz; - r_pvector_push (ret, test); + rz_pvector_push (ret, test); } while ((line = nextline)); beach: free (contents); return ret; fail: - r_pvector_free (ret); + rz_pvector_free (ret); ret = NULL; goto beach; } -R_API R2RJsonTest *r2r_json_test_new(void) { +RZ_API R2RJsonTest *rz_test_json_test_new(void) { return R_NEW0 (R2RJsonTest); } -R_API void r2r_json_test_free(R2RJsonTest *test) { +RZ_API void rz_test_json_test_free(R2RJsonTest *test) { if (!test) { return; } @@ -449,14 +449,14 @@ R_API void r2r_json_test_free(R2RJsonTest *test) { free (test); } -R_API RPVector *r2r_load_json_test_file(const char *file) { - char *contents = r_file_slurp (file, NULL); +RZ_API RPVector *rz_test_load_json_test_file(const char *file) { + char *contents = rz_file_slurp (file, NULL); if (!contents) { eprintf ("Failed to open file \"%s\"\n", file); return NULL; } - RPVector *ret = r_pvector_new (NULL); + RPVector *ret = rz_pvector_new (NULL); if (!ret) { free (contents); return NULL; @@ -481,31 +481,31 @@ R_API RPVector *r2r_load_json_test_file(const char *file) { *broken_token = '\0'; } - r_str_trim (line); + rz_str_trim (line); if (!*line) { // empty line continue; } - R2RJsonTest *test = r2r_json_test_new (); + R2RJsonTest *test = rz_test_json_test_new (); if (!test) { break; } test->line = linenum; test->cmd = strdup (line); if (!test->cmd) { - r2r_json_test_free (test); + rz_test_json_test_free (test); break; } test->broken = broken_token ? true : false; - r_pvector_push (ret, test); + rz_pvector_push (ret, test); } while ((line = nextline)); free (contents); return ret; } -R_API void r2r_fuzz_test_free(R2RFuzzTest *test) { +RZ_API void rz_test_fuzz_test_free(R2RFuzzTest *test) { if (!test) { return; } @@ -513,60 +513,60 @@ R_API void r2r_fuzz_test_free(R2RFuzzTest *test) { free (test); } -R_API void r2r_test_free(R2RTest *test) { +RZ_API void rz_test_test_free(R2RTest *test) { if (!test) { return; } switch (test->type) { case R2R_TEST_TYPE_CMD: - r2r_cmd_test_free (test->cmd_test); + rz_test_cmd_test_free (test->cmd_test); break; case R2R_TEST_TYPE_ASM: - r2r_asm_test_free (test->asm_test); + rz_test_asm_test_free (test->asm_test); break; case R2R_TEST_TYPE_JSON: - r2r_json_test_free (test->json_test); + rz_test_json_test_free (test->json_test); break; case R2R_TEST_TYPE_FUZZ: - r2r_fuzz_test_free (test->fuzz_test); + rz_test_fuzz_test_free (test->fuzz_test); break; } free (test); } -R_API R2RTestDatabase *r2r_test_database_new(void) { +RZ_API R2RTestDatabase *rz_test_test_database_new(void) { R2RTestDatabase *db = R_NEW (R2RTestDatabase); if (!db) { return NULL; } - r_pvector_init (&db->tests, (RPVectorFree)r2r_test_free); - r_str_constpool_init (&db->strpool); + rz_pvector_init (&db->tests, (RPVectorFree)rz_test_test_free); + rz_str_constpool_init (&db->strpool); return db; } -R_API void r2r_test_database_free(R2RTestDatabase *db) { +RZ_API void rz_test_test_database_free(R2RTestDatabase *db) { if (!db) { return; } - r_pvector_clear (&db->tests); - r_str_constpool_fini (&db->strpool); + rz_pvector_clear (&db->tests); + rz_str_constpool_fini (&db->strpool); free (db); } static R2RTestType test_type_for_path(const char *path, bool *load_plugins) { R2RTestType ret = R2R_TEST_TYPE_CMD; char *pathdup = strdup (path); - RList *tokens = r_str_split_list (pathdup, R_SYS_DIR, 0); + RzList *tokens = rz_str_split_list (pathdup, R_SYS_DIR, 0); if (!tokens) { return ret; } - if (!r_list_empty (tokens)) { - r_list_pop (tokens); + if (!rz_list_empty (tokens)) { + rz_list_pop (tokens); } - RListIter *it; + RzListIter *it; char *token; *load_plugins = false; - r_list_foreach (tokens, it, token) { + rz_list_foreach (tokens, it, token) { if (!strcmp (token, "asm")) { ret = R2R_TEST_TYPE_ASM; continue; @@ -579,7 +579,7 @@ static R2RTestType test_type_for_path(const char *path, bool *load_plugins) { *load_plugins = true; } } - r_list_free (tokens); + rz_list_free (tokens); free (pathdup); return ret; } @@ -589,17 +589,17 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { eprintf ("Directories for loading tests too deep: %s\n", path); return false; } - if (r_file_is_directory (path)) { - RList *dir = r_sys_dir (path); + if (rz_file_is_directory (path)) { + RzList *dir = rz_sys_dir (path); if (!dir) { return false; } - RListIter *it; + RzListIter *it; const char *subname; RStrBuf subpath; - r_strbuf_init (&subpath); + rz_strbuf_init (&subpath); bool ret = true; - r_list_foreach (dir, it, subname) { + rz_list_foreach (dir, it, subname) { if (*subname == '.') { continue; } @@ -608,39 +608,39 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { eprintf ("Skipping %s"R_SYS_DIR"%s because it requires additional dependencies.\n", path, subname); continue; } - if ((!strcmp (path, "archos") || r_str_endswith (path, R_SYS_DIR"archos")) + if ((!strcmp (path, "archos") || rz_str_endswith (path, R_SYS_DIR"archos")) && strcmp (subname, R2R_ARCH_OS)) { eprintf ("Skipping %s"R_SYS_DIR"%s because it does not match the current platform.\n", path, subname); continue; } - r_strbuf_setf (&subpath, "%s%s%s", path, R_SYS_DIR, subname); - if (!database_load (db, r_strbuf_get (&subpath), depth - 1)) { + rz_strbuf_setf (&subpath, "%s%s%s", path, R_SYS_DIR, subname); + if (!database_load (db, rz_strbuf_get (&subpath), depth - 1)) { ret = false; break; } } - r_strbuf_fini (&subpath); - r_list_free (dir); + rz_strbuf_fini (&subpath); + rz_list_free (dir); return ret; } - if (!r_file_exists (path)) { + if (!rz_file_exists (path)) { eprintf ("Path \"%s\" does not exist\n", path); return false; } // Not a directory but exists, load a file - const char *pooled_path = r_str_constpool_get (&db->strpool, path); + const char *pooled_path = rz_str_constpool_get (&db->strpool, path); bool load_plugins = false; R2RTestType test_type = test_type_for_path (path, &load_plugins); switch (test_type) { case R2R_TEST_TYPE_CMD: { - RPVector *cmd_tests = r2r_load_cmd_test_file (path); + RPVector *cmd_tests = rz_test_load_cmd_test_file (path); if (!cmd_tests) { return false; } void **it; - r_pvector_foreach (cmd_tests, it) { + rz_pvector_foreach (cmd_tests, it) { R2RTest *test = R_NEW (R2RTest); if (!test) { continue; @@ -649,18 +649,18 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { test->path = pooled_path; test->cmd_test = *it; test->cmd_test->load_plugins = load_plugins; - r_pvector_push (&db->tests, test); + rz_pvector_push (&db->tests, test); } - r_pvector_free (cmd_tests); + rz_pvector_free (cmd_tests); break; } case R2R_TEST_TYPE_ASM: { - RPVector *asm_tests = r2r_load_asm_test_file (&db->strpool, path); + RPVector *asm_tests = rz_test_load_asm_test_file (&db->strpool, path); if (!asm_tests) { return false; } void **it; - r_pvector_foreach (asm_tests, it) { + rz_pvector_foreach (asm_tests, it) { R2RTest *test = R_NEW (R2RTest); if (!test) { continue; @@ -668,18 +668,18 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { test->type = R2R_TEST_TYPE_ASM; test->path = pooled_path; test->asm_test = *it; - r_pvector_push (&db->tests, test); + rz_pvector_push (&db->tests, test); } - r_pvector_free (asm_tests); + rz_pvector_free (asm_tests); break; } case R2R_TEST_TYPE_JSON: { - RPVector *json_tests = r2r_load_json_test_file (path); + RPVector *json_tests = rz_test_load_json_test_file (path); if (!json_tests) { return false; } void **it; - r_pvector_foreach (json_tests, it) { + rz_pvector_foreach (json_tests, it) { R2RTest *test = R_NEW (R2RTest); if (!test) { continue; @@ -688,9 +688,9 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { test->path = pooled_path; test->json_test = *it; test->json_test->load_plugins = load_plugins; - r_pvector_push (&db->tests, test); + rz_pvector_push (&db->tests, test); } - r_pvector_free (json_tests); + rz_pvector_free (json_tests); break; } case R2R_TEST_TYPE_FUZZ: @@ -701,7 +701,7 @@ static bool database_load(R2RTestDatabase *db, const char *path, int depth) { return true; } -R_API bool r2r_test_database_load(R2RTestDatabase *db, const char *path) { +RZ_API bool rz_test_test_database_load(R2RTestDatabase *db, const char *path) { return database_load (db, path, 4); } @@ -723,38 +723,38 @@ static void database_load_fuzz_file(R2RTestDatabase *db, const char *path, const } test->type = R2R_TEST_TYPE_FUZZ; test->fuzz_test = fuzz_test; - test->path = r_str_constpool_get (&db->strpool, path); - r_pvector_push (&db->tests, test); + test->path = rz_str_constpool_get (&db->strpool, path); + rz_pvector_push (&db->tests, test); } -R_API bool r2r_test_database_load_fuzz(R2RTestDatabase *db, const char *path) { - if (r_file_is_directory (path)) { - RList *dir = r_sys_dir (path); +RZ_API bool rz_test_test_database_load_fuzz(R2RTestDatabase *db, const char *path) { + if (rz_file_is_directory (path)) { + RzList *dir = rz_sys_dir (path); if (!dir) { return false; } - RListIter *it; + RzListIter *it; const char *subname; RStrBuf subpath; - r_strbuf_init (&subpath); + rz_strbuf_init (&subpath); bool ret = true; - r_list_foreach (dir, it, subname) { + rz_list_foreach (dir, it, subname) { if (*subname == '.') { continue; } - r_strbuf_setf (&subpath, "%s%s%s", path, R_SYS_DIR, subname); - if (r_file_is_directory (r_strbuf_get (&subpath))) { + rz_strbuf_setf (&subpath, "%s%s%s", path, R_SYS_DIR, subname); + if (rz_file_is_directory (rz_strbuf_get (&subpath))) { // only load 1 level deep continue; } - database_load_fuzz_file (db, path, r_strbuf_get (&subpath)); + database_load_fuzz_file (db, path, rz_strbuf_get (&subpath)); } - r_strbuf_fini (&subpath); - r_list_free (dir); + rz_strbuf_fini (&subpath); + rz_list_free (dir); return ret; } - if (!r_file_exists (path)) { + if (!rz_file_exists (path)) { eprintf ("Path \"%s\" does not exist\n", path); return false; } diff --git a/binr/r2r/meson.build b/binrz/rz-test/meson.build similarity index 62% rename from binr/r2r/meson.build rename to binrz/rz-test/meson.build index ec8b81bfc8..fb01c07180 100644 --- a/binr/r2r/meson.build +++ b/binrz/rz-test/meson.build @@ -1,9 +1,9 @@ -if get_option('enable_r2r') - executable('r2r', ['r2r.c', 'load.c', 'run.c'], +if get_option('enable_rz_test') + executable('rz-test', ['rz-test.c', 'load.c', 'run.c'], include_directories: [platform_inc], dependencies: [ - r_util_dep, + rz_util_dep, lrt, ], install: true, diff --git a/binr/r2r/run.c b/binrz/rz-test/run.c similarity index 66% rename from binr/r2r/run.c rename to binrz/rz-test/run.c index af81a65341..1a914c7b2b 100644 --- a/binr/r2r/run.c +++ b/binrz/rz-test/run.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2020 - thestr4ng3r */ -#include "r2r.h" +#include "rz_test.h" #if __WINDOWS__ -struct r2r_subprocess_t { +struct rz_test_subprocess_t { HANDLE stdin_write; HANDLE stdout_read; HANDLE stderr_read; @@ -21,7 +21,7 @@ static bool create_pipe_overlap(HANDLE *pipe_read, HANDLE *pipe_write, LPSECURIT sz = 4096; } char name[MAX_PATH]; - snprintf (name, sizeof (name), "\\\\.\\pipe\\r2r-subproc.%d.%ld", (int)GetCurrentProcessId (), (long)InterlockedIncrement (&pipe_id)); + snprintf (name, sizeof (name), "\\\\.\\pipe\\rz_test-subproc.%d.%ld", (int)GetCurrentProcessId (), (long)InterlockedIncrement (&pipe_id)); *pipe_read = CreateNamedPipeA (name, PIPE_ACCESS_INBOUND | read_mode, PIPE_TYPE_BYTE | PIPE_WAIT, 1, sz, sz, 120 * 1000, attrs); if (!*pipe_read) { return FALSE; @@ -34,8 +34,8 @@ static bool create_pipe_overlap(HANDLE *pipe_read, HANDLE *pipe_write, LPSECURIT return true; } -R_API bool r2r_subprocess_init(void) { return true; } -R_API void r2r_subprocess_fini(void) {} +RZ_API bool rz_test_subprocess_init(void) { return true; } +RZ_API void rz_test_subprocess_fini(void) {} // Create an env block that inherits the current vars but overrides the given ones static LPWCH override_env(const char *envvars[], const char *envvals[], size_t env_size) { @@ -50,15 +50,15 @@ static LPWCH override_env(const char *envvars[], const char *envvals[], size_t e } for (i = 0; i < env_size; i++) { - wenvvars[i] = r_utf8_to_utf16 (envvars[i]); - wenvvals[i] = r_utf8_to_utf16 (envvals[i]); + wenvvars[i] = rz_utf8_to_utf16 (envvars[i]); + wenvvals[i] = rz_utf8_to_utf16 (envvals[i]); if (!wenvvars[i] || !wenvvals[i]) { goto error; } } - RVector buf; - r_vector_init (&buf, sizeof (wchar_t), NULL, NULL); + RzVector buf; + rz_vector_init (&buf, sizeof (wchar_t), NULL, NULL); LPWCH cur = parent_env; while (true) { LPWCH var_begin = cur; @@ -86,7 +86,7 @@ static LPWCH override_env(const char *envvars[], const char *envvals[], size_t e cur++; } if (!overridden) { - r_vector_insert_range (&buf, buf.len, var_begin, cur - var_begin + 1); + rz_vector_insert_range (&buf, buf.len, var_begin, cur - var_begin + 1); } cur++; if (!*cur) { @@ -97,15 +97,15 @@ static LPWCH override_env(const char *envvars[], const char *envvals[], size_t e wchar_t c; for (i = 0; i < env_size; i++) { - r_vector_insert_range (&buf, buf.len, wenvvars[i], lstrlenW (wenvvars[i])); + rz_vector_insert_range (&buf, buf.len, wenvvars[i], lstrlenW (wenvvars[i])); c = L'='; - r_vector_push (&buf, &c); - r_vector_insert_range (&buf, buf.len, wenvvals[i], lstrlenW (wenvvals[i])); + rz_vector_push (&buf, &c); + rz_vector_insert_range (&buf, buf.len, wenvvals[i], lstrlenW (wenvvals[i])); c = L'\0'; - r_vector_push (&buf, &c); + rz_vector_push (&buf, &c); } c = '\0'; - r_vector_push (&buf, &c); + rz_vector_push (&buf, &c); ret = buf.a; error: @@ -125,7 +125,7 @@ error: return ret; } -R_API R2RSubprocess *r2r_subprocess_start( +RZ_API R2RSubprocess *rz_test_subprocess_start( const char *file, const char *args[], size_t args_size, const char *envvars[], const char *envvals[], size_t env_size) { R2RSubprocess *proc = NULL; @@ -141,7 +141,7 @@ R_API R2RSubprocess *r2r_subprocess_start( if (args_size) { memcpy (argv + 1, args, sizeof (char *) * args_size); } - char *cmdline = r_str_format_msvc_argv (args_size + 1, argv); + char *cmdline = rz_str_format_msvc_argv (args_size + 1, argv); free (argv); if (!cmdline) { return NULL; @@ -230,7 +230,7 @@ error: goto beach; } -R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { +RZ_API bool rz_test_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { OVERLAPPED stdout_overlapped = { 0 }; stdout_overlapped.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); if (!stdout_overlapped.hEvent) { @@ -245,7 +245,7 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { ut64 timeout_us_abs = UT64_MAX; if (timeout_ms != UT64_MAX) { - timeout_us_abs = r_time_now_mono () + timeout_ms * R_USEC_PER_MSEC; + timeout_us_abs = rz_time_now_mono () + timeout_ms * R_USEC_PER_MSEC; } ut8 stdout_buf[0x500]; @@ -265,29 +265,29 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { DO_READ (stdout) DO_READ (stderr) - RVector handles; - r_vector_init (&handles, sizeof (HANDLE), NULL, NULL); + RzVector handles; + rz_vector_init (&handles, sizeof (HANDLE), NULL, NULL); while (true) { - r_vector_clear (&handles); + rz_vector_clear (&handles); size_t stdout_index = 0; size_t stderr_index = 0; size_t proc_index = 0; if (!stdout_eof) { stdout_index = handles.len; - r_vector_push (&handles, &stdout_overlapped.hEvent); + rz_vector_push (&handles, &stdout_overlapped.hEvent); } if (!stderr_eof) { stderr_index = handles.len; - r_vector_push (&handles, &stderr_overlapped.hEvent); + rz_vector_push (&handles, &stderr_overlapped.hEvent); } if (!child_dead) { proc_index = handles.len; - r_vector_push (&handles, &proc->proc); + rz_vector_push (&handles, &proc->proc); } DWORD timeout = INFINITE; if (timeout_us_abs != UT64_MAX) { - ut64 now = r_time_now_mono (); + ut64 now = rz_time_now_mono (); if (now >= timeout_us_abs) { return false; } @@ -302,8 +302,8 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { continue; } stdout_buf[r] = '\0'; - r_str_remove_char (stdout_buf, '\r'); - r_strbuf_append (&proc->out, (const char *)stdout_buf); + rz_str_remove_char (stdout_buf, '\r'); + rz_strbuf_append (&proc->out, (const char *)stdout_buf); ResetEvent (stdout_overlapped.hEvent); DO_READ (stdout) continue; @@ -316,8 +316,8 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { continue; } stderr_buf[read] = '\0'; - r_str_remove_char (stderr_buf, '\r'); - r_strbuf_append (&proc->err, (const char *)stderr_buf); + rz_str_remove_char (stderr_buf, '\r'); + rz_strbuf_append (&proc->err, (const char *)stderr_buf); ResetEvent (stderr_overlapped.hEvent); DO_READ (stderr); continue; @@ -332,34 +332,34 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { } break; } - r_vector_clear (&handles); + rz_vector_clear (&handles); CloseHandle (stdout_overlapped.hEvent); CloseHandle (stderr_overlapped.hEvent); return stdout_eof && stderr_eof && child_dead; } -R_API void r2r_subprocess_kill(R2RSubprocess *proc) { +RZ_API void rz_test_subprocess_kill(R2RSubprocess *proc) { TerminateProcess (proc->proc, 255); } -R_API void r2r_subprocess_stdin_write(R2RSubprocess *proc, const ut8 *buf, size_t buf_size) { +RZ_API void rz_test_subprocess_stdin_write(R2RSubprocess *proc, const ut8 *buf, size_t buf_size) { DWORD read; WriteFile (proc->stdin_write, buf, buf_size, &read, NULL); } -R_API R2RProcessOutput *r2r_subprocess_drain(R2RSubprocess *proc) { +RZ_API R2RProcessOutput *rz_test_subprocess_drain(R2RSubprocess *proc) { R2RProcessOutput *out = R_NEW (R2RProcessOutput); if (!out) { return NULL; } - out->out = r_strbuf_drain_nofree (&proc->out); - out->err = r_strbuf_drain_nofree (&proc->err); + out->out = rz_strbuf_drain_nofree (&proc->out); + out->err = rz_strbuf_drain_nofree (&proc->err); out->ret = proc->ret; return out; } -R_API void r2r_subprocess_free(R2RSubprocess *proc) { +RZ_API void rz_test_subprocess_free(R2RSubprocess *proc) { if (!proc) { return; } @@ -374,7 +374,7 @@ R_API void r2r_subprocess_free(R2RSubprocess *proc) { #include #include -struct r2r_subprocess_t { +struct rz_test_subprocess_t { pid_t pid; int stdin_fd; int stdout_fd; @@ -386,16 +386,16 @@ struct r2r_subprocess_t { }; static RPVector subprocs; -static RThreadLock *subprocs_mutex; +static RzThreadLock *subprocs_mutex; static int sigchld_pipe[2]; -static RThread *sigchld_thread; +static RzThread *sigchld_thread; static void handle_sigchld(int sig) { ut8 b = 1; write (sigchld_pipe[1], &b, 1); } -static RThreadFunctionRet sigchld_th(RThread *th) { +static RzThreadFunctionRet sigchld_th(RzThread *th) { while (true) { ut8 b; ssize_t rd = read (sigchld_pipe[0], &b, 1); @@ -417,10 +417,10 @@ static RThreadFunctionRet sigchld_th(RThread *th) { if (pid <= 0) break; - r_th_lock_enter (subprocs_mutex); + rz_th_lock_enter (subprocs_mutex); void **it; R2RSubprocess *proc = NULL; - r_pvector_foreach (&subprocs, it) { + rz_pvector_foreach (&subprocs, it) { R2RSubprocess *p = *it; if (p->pid == pid) { proc = p; @@ -428,7 +428,7 @@ static RThreadFunctionRet sigchld_th(RThread *th) { } } if (!proc) { - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); continue; } @@ -439,52 +439,52 @@ static RThreadFunctionRet sigchld_th(RThread *th) { } ut8 r = 0; write (proc->killpipe[1], &r, 1); - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); } } return R_TH_STOP; } -R_API bool r2r_subprocess_init(void) { - r_pvector_init(&subprocs, NULL); - subprocs_mutex = r_th_lock_new (false); +RZ_API bool rz_test_subprocess_init(void) { + rz_pvector_init(&subprocs, NULL); + subprocs_mutex = rz_th_lock_new (false); if (!subprocs_mutex) { return false; } if (pipe (sigchld_pipe) == -1) { perror ("pipe"); - r_th_lock_free (subprocs_mutex); + rz_th_lock_free (subprocs_mutex); return false; } - sigchld_thread = r_th_new (sigchld_th, NULL, 0); + sigchld_thread = rz_th_new (sigchld_th, NULL, 0); if (!sigchld_thread) { close (sigchld_pipe [0]); close (sigchld_pipe [1]); - r_th_lock_free (subprocs_mutex); + rz_th_lock_free (subprocs_mutex); return false; } - if (r_sys_signal (SIGCHLD, handle_sigchld) < 0) { + if (rz_sys_signal (SIGCHLD, handle_sigchld) < 0) { close (sigchld_pipe [0]); close (sigchld_pipe [1]); - r_th_lock_free (subprocs_mutex); + rz_th_lock_free (subprocs_mutex); return false; } return true; } -R_API void r2r_subprocess_fini(void) { - r_sys_signal (SIGCHLD, SIG_IGN); +RZ_API void rz_test_subprocess_fini(void) { + rz_sys_signal (SIGCHLD, SIG_IGN); ut8 b = 0; write (sigchld_pipe[1], &b, 1); close (sigchld_pipe [1]); - r_th_wait (sigchld_thread); + rz_th_wait (sigchld_thread); close (sigchld_pipe [0]); - r_th_free (sigchld_thread); - r_pvector_clear (&subprocs); - r_th_lock_free (subprocs_mutex); + rz_th_free (sigchld_thread); + rz_pvector_clear (&subprocs); + rz_th_lock_free (subprocs_mutex); } -R_API R2RSubprocess *r2r_subprocess_start( +RZ_API R2RSubprocess *rz_test_subprocess_start( const char *file, const char *args[], size_t args_size, const char *envvars[], const char *envvals[], size_t env_size) { char **argv = calloc (args_size + 2, sizeof (char *)); @@ -496,15 +496,15 @@ R_API R2RSubprocess *r2r_subprocess_start( memcpy (argv + 1, args, sizeof (char *) * args_size); } // done by calloc: argv[args_size + 1] = NULL; - r_th_lock_enter (subprocs_mutex); + rz_th_lock_enter (subprocs_mutex); R2RSubprocess *proc = R_NEW0 (R2RSubprocess); if (!proc) { goto error; } proc->killpipe[0] = proc->killpipe[1] = -1; proc->ret = -1; - r_strbuf_init (&proc->out); - r_strbuf_init (&proc->err); + rz_strbuf_init (&proc->out); + rz_strbuf_init (&proc->err); if (pipe (proc->killpipe) == -1) { perror ("pipe"); @@ -544,10 +544,10 @@ R_API R2RSubprocess *r2r_subprocess_start( } proc->stderr_fd = stderr_pipe[0]; - proc->pid = r_sys_fork (); + proc->pid = rz_sys_fork (); if (proc->pid == -1) { // fail - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); perror ("fork"); free (proc); free (argv); @@ -570,7 +570,7 @@ R_API R2RSubprocess *r2r_subprocess_start( } execvp (file, argv); perror ("exec"); - r_sys_exit (-1, true); + rz_sys_exit (-1, true); } free (argv); @@ -579,9 +579,9 @@ R_API R2RSubprocess *r2r_subprocess_start( close (stdout_pipe[1]); close (stderr_pipe[1]); - r_pvector_push (&subprocs, proc); + rz_pvector_push (&subprocs, proc); - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); return proc; error: @@ -611,14 +611,14 @@ error: if (stdin_pipe[1] == -1) { close (stdin_pipe[1]); } - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); return NULL; } -R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { +RZ_API bool rz_test_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { ut64 timeout_abs; if (timeout_ms != UT64_MAX) { - timeout_abs = r_time_now_mono () + timeout_ms * R_USEC_PER_MSEC; + timeout_abs = rz_time_now_mono () + timeout_ms * R_USEC_PER_MSEC; } int r = 0; @@ -652,11 +652,11 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { struct timeval timeout_s; struct timeval *timeout = NULL; if (timeout_ms != UT64_MAX) { - ut64 now = r_time_now_mono (); + ut64 now = rz_time_now_mono (); if (now >= timeout_abs) { break; } - ut64 usec_diff = timeout_abs - r_time_now_mono (); + ut64 usec_diff = timeout_abs - rz_time_now_mono (); timeout_s.tv_sec = usec_diff / R_USEC_PER_SEC; timeout_s.tv_usec = usec_diff % R_USEC_PER_SEC; timeout = &timeout_s; @@ -679,7 +679,7 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { } else if (sz == 0) { stdout_eof = true; } else { - r_strbuf_append_n (&proc->out, buf, (int)sz); + rz_strbuf_append_n (&proc->out, buf, (int)sz); } } if (FD_ISSET (proc->stderr_fd, &rfds)) { @@ -692,7 +692,7 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { } else if (sz == 0) { stderr_eof = true; } else { - r_strbuf_append_n (&proc->err, buf, (int)sz); + rz_strbuf_append_n (&proc->err, buf, (int)sz); } } if (FD_ISSET (proc->killpipe[0], &rfds)) { @@ -709,38 +709,38 @@ R_API bool r2r_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms) { return child_dead; } -R_API void r2r_subprocess_kill(R2RSubprocess *proc) { +RZ_API void rz_test_subprocess_kill(R2RSubprocess *proc) { kill (proc->pid, SIGKILL); } -R_API void r2r_subprocess_stdin_write(R2RSubprocess *proc, const ut8 *buf, size_t buf_size) { +RZ_API void rz_test_subprocess_stdin_write(R2RSubprocess *proc, const ut8 *buf, size_t buf_size) { write (proc->stdin_fd, buf, buf_size); close (proc->stdin_fd); proc->stdin_fd = -1; } -R_API R2RProcessOutput *r2r_subprocess_drain(R2RSubprocess *proc) { - r_th_lock_enter (subprocs_mutex); +RZ_API R2RProcessOutput *rz_test_subprocess_drain(R2RSubprocess *proc) { + rz_th_lock_enter (subprocs_mutex); R2RProcessOutput *out = R_NEW (R2RProcessOutput); if (out) { - out->out = r_strbuf_drain_nofree (&proc->out); - out->err = r_strbuf_drain_nofree (&proc->err); + out->out = rz_strbuf_drain_nofree (&proc->out); + out->err = rz_strbuf_drain_nofree (&proc->err); out->ret = proc->ret; out->timeout = false; } - r_th_lock_leave (subprocs_mutex); + rz_th_lock_leave (subprocs_mutex); return out; } -R_API void r2r_subprocess_free(R2RSubprocess *proc) { +RZ_API void rz_test_subprocess_free(R2RSubprocess *proc) { if (!proc) { return; } - r_th_lock_enter (subprocs_mutex); - r_pvector_remove_data (&subprocs, proc); - r_th_lock_leave (subprocs_mutex); - r_strbuf_fini (&proc->out); - r_strbuf_fini (&proc->err); + rz_th_lock_enter (subprocs_mutex); + rz_pvector_remove_data (&subprocs, proc); + rz_th_lock_leave (subprocs_mutex); + rz_strbuf_fini (&proc->out); + rz_strbuf_fini (&proc->err); close (proc->killpipe[0]); close (proc->killpipe[1]); if (proc->stdin_fd != -1) { @@ -752,7 +752,7 @@ R_API void r2r_subprocess_free(R2RSubprocess *proc) { } #endif -R_API void r2r_process_output_free(R2RProcessOutput *out) { +RZ_API void rz_test_process_output_free(R2RProcessOutput *out) { if (!out) { return; } @@ -763,19 +763,19 @@ R_API void r2r_process_output_free(R2RProcessOutput *out) { static R2RProcessOutput *subprocess_runner(const char *file, const char *args[], size_t args_size, const char *envvars[], const char *envvals[], size_t env_size, ut64 timeout_ms, void *user) { - R2RSubprocess *proc = r2r_subprocess_start (file, args, args_size, envvars, envvals, env_size); + R2RSubprocess *proc = rz_test_subprocess_start (file, args, args_size, envvars, envvals, env_size); if (!proc) { return NULL; } - bool timeout = !r2r_subprocess_wait (proc, timeout_ms); + bool timeout = !rz_test_subprocess_wait (proc, timeout_ms); if (timeout) { - r2r_subprocess_kill (proc); + rz_test_subprocess_kill (proc); } - R2RProcessOutput *out = r2r_subprocess_drain (proc); + R2RProcessOutput *out = rz_test_subprocess_drain (proc); if (out) { out->timeout = timeout; } - r2r_subprocess_free (proc); + rz_test_subprocess_free (proc); return out; } @@ -841,31 +841,31 @@ static char *convert_win_cmds(const char *cmds) { p += llen; } *p = '\0'; - return r_str_replace (r, "/dev/null", "nul", true); + return rz_str_replace (r, "/dev/null", "nul", true); } #endif -static R2RProcessOutput *run_r2_test(R2RRunConfig *config, ut64 timeout_ms, const char *cmds, RList *files, RList *extra_args, bool load_plugins, R2RCmdRunner runner, void *user) { +static R2RProcessOutput *run_rz_test(R2RRunConfig *config, ut64 timeout_ms, const char *cmds, RzList *files, RzList *extra_args, bool load_plugins, R2RzCmdRunner runner, void *user) { RPVector args; - r_pvector_init (&args, NULL); - r_pvector_push (&args, "-escr.utf8=0"); - r_pvector_push (&args, "-escr.color=0"); - r_pvector_push (&args, "-escr.interactive=0"); - r_pvector_push (&args, "-N"); - RListIter *it; + rz_pvector_init (&args, NULL); + rz_pvector_push (&args, "-escr.utf8=0"); + rz_pvector_push (&args, "-escr.color=0"); + rz_pvector_push (&args, "-escr.interactive=0"); + rz_pvector_push (&args, "-N"); + RzListIter *it; void *extra_arg, *file_arg; - r_list_foreach (extra_args, it, extra_arg) { - r_pvector_push (&args, extra_arg); + rz_list_foreach (extra_args, it, extra_arg) { + rz_pvector_push (&args, extra_arg); } - r_pvector_push (&args, "-Qc"); + rz_pvector_push (&args, "-Qc"); #if __WINDOWS__ char *wcmds = convert_win_cmds (cmds); - r_pvector_push (&args, wcmds); + rz_pvector_push (&args, wcmds); #else - r_pvector_push (&args, (void *)cmds); + rz_pvector_push (&args, (void *)cmds); #endif - r_list_foreach (files, it, file_arg) { - r_pvector_push (&args, file_arg); + rz_list_foreach (files, it, file_arg) { + rz_pvector_push (&args, file_arg); } const char *envvars[] = { @@ -885,46 +885,46 @@ static R2RProcessOutput *run_r2_test(R2RRunConfig *config, ut64 timeout_ms, cons #else size_t env_size = load_plugins ? 0 : 1; #endif - R2RProcessOutput *out = runner (config->r2_cmd, args.v.a, r_pvector_len (&args), envvars, envvals, env_size, timeout_ms, user); - r_pvector_clear (&args); + R2RProcessOutput *out = runner (config->r2_cmd, args.v.a, rz_pvector_len (&args), envvars, envvals, env_size, timeout_ms, user); + rz_pvector_clear (&args); #if __WINDOWS__ free (wcmds); #endif return out; } -R_API R2RProcessOutput *r2r_run_cmd_test(R2RRunConfig *config, R2RCmdTest *test, R2RCmdRunner runner, void *user) { - RList *extra_args = test->args.value ? r_str_split_duplist (test->args.value, " ", true) : NULL; - RList *files = r_str_split_duplist (test->file.value, "\n", true); - RListIter *it; - RListIter *tmpit; +RZ_API R2RProcessOutput *rz_test_run_cmd_test(R2RRunConfig *config, R2RzCmdTest *test, R2RzCmdRunner runner, void *user) { + RzList *extra_args = test->args.value ? rz_str_split_duplist (test->args.value, " ", true) : NULL; + RzList *files = rz_str_split_duplist (test->file.value, "\n", true); + RzListIter *it; + RzListIter *tmpit; char *token; - r_list_foreach_safe (extra_args, it, tmpit, token) { + rz_list_foreach_safe (extra_args, it, tmpit, token) { if (!*token) { - r_list_delete (extra_args, it); + rz_list_delete (extra_args, it); } } - r_list_foreach_safe (files, it, tmpit, token) { + rz_list_foreach_safe (files, it, tmpit, token) { if (!*token) { - r_list_delete (files, it); + rz_list_delete (files, it); } } - if (r_list_empty (files)) { + if (rz_list_empty (files)) { if (!files) { - files = r_list_new (); + files = rz_list_new (); } else { files->free = NULL; } - r_list_push (files, "-"); + rz_list_push (files, "-"); } ut64 timeout_ms = test->timeout.set? test->timeout.value * 1000: config->timeout_ms; - R2RProcessOutput *out = run_r2_test (config, timeout_ms, test->cmds.value, files, extra_args, test->load_plugins, runner, user); - r_list_free (extra_args); - r_list_free (files); + R2RProcessOutput *out = run_rz_test (config, timeout_ms, test->cmds.value, files, extra_args, test->load_plugins, runner, user); + rz_list_free (extra_args); + rz_list_free (files); return out; } -R_API bool r2r_check_cmd_test(R2RProcessOutput *out, R2RCmdTest *test) { +RZ_API bool rz_test_check_cmd_test(R2RProcessOutput *out, R2RzCmdTest *test) { if (!out || out->ret != 0 || !out->out || !out->err || out->timeout) { return false; } @@ -941,107 +941,107 @@ R_API bool r2r_check_cmd_test(R2RProcessOutput *out, R2RCmdTest *test) { #define JQ_CMD "jq" -R_API bool r2r_check_jq_available(void) { +RZ_API bool rz_test_check_jq_available(void) { const char *args[] = {"."}; const char *invalid_json = "this is not json lol"; - R2RSubprocess *proc = r2r_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); + R2RSubprocess *proc = rz_test_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); if (proc) { - r2r_subprocess_stdin_write (proc, (const ut8 *)invalid_json, strlen (invalid_json)); - r2r_subprocess_wait (proc, UT64_MAX); + rz_test_subprocess_stdin_write (proc, (const ut8 *)invalid_json, strlen (invalid_json)); + rz_test_subprocess_wait (proc, UT64_MAX); } bool invalid_detected = proc && proc->ret != 0; - r2r_subprocess_free (proc); + rz_test_subprocess_free (proc); const char *valid_json = "{\"this is\":\"valid json\",\"lol\":true}"; - proc = r2r_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); + proc = rz_test_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); if (proc) { - r2r_subprocess_stdin_write (proc, (const ut8 *)valid_json, strlen (valid_json)); - r2r_subprocess_wait (proc, UT64_MAX); + rz_test_subprocess_stdin_write (proc, (const ut8 *)valid_json, strlen (valid_json)); + rz_test_subprocess_wait (proc, UT64_MAX); } bool valid_detected = proc && proc->ret == 0; - r2r_subprocess_free (proc); + rz_test_subprocess_free (proc); return invalid_detected && valid_detected; } -R_API R2RProcessOutput *r2r_run_json_test(R2RRunConfig *config, R2RJsonTest *test, R2RCmdRunner runner, void *user) { - RList *files = r_list_new (); - r_list_push (files, (void *)config->json_test_file); - R2RProcessOutput *ret = run_r2_test (config, config->timeout_ms, test->cmd, files, NULL, test->load_plugins, runner, user); - r_list_free (files); +RZ_API R2RProcessOutput *rz_test_run_json_test(R2RRunConfig *config, R2RJsonTest *test, R2RzCmdRunner runner, void *user) { + RzList *files = rz_list_new (); + rz_list_push (files, (void *)config->json_test_file); + R2RProcessOutput *ret = run_rz_test (config, config->timeout_ms, test->cmd, files, NULL, test->load_plugins, runner, user); + rz_list_free (files); return ret; } -R_API bool r2r_check_json_test(R2RProcessOutput *out, R2RJsonTest *test) { +RZ_API bool rz_test_check_json_test(R2RProcessOutput *out, R2RJsonTest *test) { if (!out || out->ret != 0 || !out->out || !out->err || out->timeout) { return false; } const char *args[] = {"."}; - R2RSubprocess *proc = r2r_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); - r2r_subprocess_stdin_write (proc, (const ut8 *)out->out, strlen (out->out)); - r2r_subprocess_wait (proc, UT64_MAX); + R2RSubprocess *proc = rz_test_subprocess_start (JQ_CMD, args, 1, NULL, NULL, 0); + rz_test_subprocess_stdin_write (proc, (const ut8 *)out->out, strlen (out->out)); + rz_test_subprocess_wait (proc, UT64_MAX); bool ret = proc->ret == 0; - r2r_subprocess_free (proc); + rz_test_subprocess_free (proc); return ret; } -R_API R2RAsmTestOutput *r2r_run_asm_test(R2RRunConfig *config, R2RAsmTest *test) { - R2RAsmTestOutput *out = R_NEW0 (R2RAsmTestOutput); +RZ_API R2RzAsmTestOutput *rz_test_run_asm_test(R2RRunConfig *config, R2RzAsmTest *test) { + R2RzAsmTestOutput *out = R_NEW0 (R2RzAsmTestOutput); if (!out) { return NULL; } RPVector args; - r_pvector_init (&args, NULL); + rz_pvector_init (&args, NULL); if (test->arch) { - r_pvector_push (&args, "-a"); - r_pvector_push (&args, (void *)test->arch); + rz_pvector_push (&args, "-a"); + rz_pvector_push (&args, (void *)test->arch); } if (test->cpu) { - r_pvector_push (&args, "-c"); - r_pvector_push (&args, (void *)test->cpu); + rz_pvector_push (&args, "-c"); + rz_pvector_push (&args, (void *)test->cpu); } char bits[0x20]; if (test->bits) { snprintf (bits, sizeof (bits), "%d", test->bits); - r_pvector_push (&args, "-b"); - r_pvector_push (&args, bits); + rz_pvector_push (&args, "-b"); + rz_pvector_push (&args, bits); } if (test->mode & R2R_ASM_TEST_MODE_BIG_ENDIAN) { - r_pvector_push (&args, "-e"); + rz_pvector_push (&args, "-e"); } char offset[0x20]; if (test->offset) { - r_snprintf (offset, sizeof (offset), "0x%"PFMT64x, test->offset); - r_pvector_push (&args, "-o"); - r_pvector_push (&args, offset); + rz_snprintf (offset, sizeof (offset), "0x%"PFMT64x, test->offset); + rz_pvector_push (&args, "-o"); + rz_pvector_push (&args, offset); } RStrBuf cmd_buf; - r_strbuf_init (&cmd_buf); + rz_strbuf_init (&cmd_buf); if (test->mode & R2R_ASM_TEST_MODE_ASSEMBLE) { - r_pvector_push (&args, test->disasm); - R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_len (&args), NULL, NULL, 0); - if (!r2r_subprocess_wait (proc, config->timeout_ms)) { - r2r_subprocess_kill (proc); + rz_pvector_push (&args, test->disasm); + R2RSubprocess *proc = rz_test_subprocess_start (config->rz_asm_cmd, args.v.a, rz_pvector_len (&args), NULL, NULL, 0); + if (!rz_test_subprocess_wait (proc, config->timeout_ms)) { + rz_test_subprocess_kill (proc); out->as_timeout = true; goto rip; } if (proc->ret != 0) { goto rip; } - char *hex = r_strbuf_get (&proc->out); + char *hex = rz_strbuf_get (&proc->out); size_t hexlen = strlen (hex); if (!hexlen) { goto rip; } ut8 *bytes = malloc (hexlen); - int byteslen = r_hex_str2bin (hex, bytes); + int byteslen = rz_hex_str2bin (hex, bytes); if (byteslen <= 0) { free (bytes); goto rip; @@ -1049,19 +1049,19 @@ R_API R2RAsmTestOutput *r2r_run_asm_test(R2RRunConfig *config, R2RAsmTest *test) out->bytes = bytes; out->bytes_size = (size_t)byteslen; rip: - r_pvector_pop (&args); - r2r_subprocess_free (proc); + rz_pvector_pop (&args); + rz_test_subprocess_free (proc); } if (test->mode & R2R_ASM_TEST_MODE_DISASSEMBLE) { - char *hex = r_hex_bin2strdup (test->bytes, test->bytes_size); + char *hex = rz_hex_bin2strdup (test->bytes, test->bytes_size); if (!hex) { goto beach; } - r_pvector_push (&args, "-d"); - r_pvector_push (&args, hex); - R2RSubprocess *proc = r2r_subprocess_start (config->rasm2_cmd, args.v.a, r_pvector_len (&args), NULL, NULL, 0); - if (!r2r_subprocess_wait (proc, config->timeout_ms)) { - r2r_subprocess_kill (proc); + rz_pvector_push (&args, "-d"); + rz_pvector_push (&args, hex); + R2RSubprocess *proc = rz_test_subprocess_start (config->rz_asm_cmd, args.v.a, rz_pvector_len (&args), NULL, NULL, 0); + if (!rz_test_subprocess_wait (proc, config->timeout_ms)) { + rz_test_subprocess_kill (proc); out->disas_timeout = true; goto ship; } @@ -1069,22 +1069,22 @@ rip: goto ship; } free (hex); - char *disasm = r_strbuf_drain_nofree (&proc->out); - r_str_trim (disasm); + char *disasm = rz_strbuf_drain_nofree (&proc->out); + rz_str_trim (disasm); out->disasm = disasm; ship: - r_pvector_pop (&args); - r_pvector_pop (&args); - r2r_subprocess_free (proc); + rz_pvector_pop (&args); + rz_pvector_pop (&args); + rz_test_subprocess_free (proc); } beach: - r_pvector_clear (&args); - r_strbuf_fini (&cmd_buf); + rz_pvector_clear (&args); + rz_strbuf_fini (&cmd_buf); return out; } -R_API bool r2r_check_asm_test(R2RAsmTestOutput *out, R2RAsmTest *test) { +RZ_API bool rz_test_check_asm_test(R2RzAsmTestOutput *out, R2RzAsmTest *test) { if (!out) { return false; } @@ -1107,7 +1107,7 @@ R_API bool r2r_check_asm_test(R2RAsmTestOutput *out, R2RAsmTest *test) { return true; } -R_API void r2r_asm_test_output_free(R2RAsmTestOutput *out) { +RZ_API void rz_test_asm_test_output_free(R2RzAsmTestOutput *out) { if (!out) { return; } @@ -1116,19 +1116,19 @@ R_API void r2r_asm_test_output_free(R2RAsmTestOutput *out) { free (out); } -R_API R2RProcessOutput *r2r_run_fuzz_test(R2RRunConfig *config, R2RFuzzTest *test, R2RCmdRunner runner, void *user) { - RList *files = r_list_new (); - r_list_push (files, test->file); - R2RProcessOutput *ret = run_r2_test (config, config->timeout_ms, "aaa", files, NULL, false, runner, user); - r_list_free (files); +RZ_API R2RProcessOutput *rz_test_run_fuzz_test(R2RRunConfig *config, R2RFuzzTest *test, R2RzCmdRunner runner, void *user) { + RzList *files = rz_list_new (); + rz_list_push (files, test->file); + R2RProcessOutput *ret = run_rz_test (config, config->timeout_ms, "aaa", files, NULL, false, runner, user); + rz_list_free (files); return ret; } -R_API bool r2r_check_fuzz_test(R2RProcessOutput *out) { +RZ_API bool rz_test_check_fuzz_test(R2RProcessOutput *out) { return out && out->ret == 0 && out->out && out->err && !out->timeout; } -R_API char *r2r_test_name(R2RTest *test) { +RZ_API char *rz_test_test_name(R2RTest *test) { switch (test->type) { case R2R_TEST_TYPE_CMD: if (test->cmd_test->name.value) { @@ -1136,16 +1136,16 @@ R_API char *r2r_test_name(R2RTest *test) { } return strdup (""); case R2R_TEST_TYPE_ASM: - return r_str_newf (" %s", test->asm_test->disasm ? test->asm_test->disasm : ""); + return rz_str_newf (" %s", test->asm_test->disasm ? test->asm_test->disasm : ""); case R2R_TEST_TYPE_JSON: - return r_str_newf (" %s", test->json_test->cmd ? test->json_test->cmd: ""); + return rz_str_newf (" %s", test->json_test->cmd ? test->json_test->cmd: ""); case R2R_TEST_TYPE_FUZZ: - return r_str_newf (" %s", test->fuzz_test->file); + return rz_str_newf (" %s", test->fuzz_test->file); } return NULL; } -R_API bool r2r_test_broken(R2RTest *test) { +RZ_API bool rz_test_test_broken(R2RTest *test) { switch (test->type) { case R2R_TEST_TYPE_CMD: return test->cmd_test->broken.value; @@ -1159,7 +1159,7 @@ R_API bool r2r_test_broken(R2RTest *test) { return false; } -R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test) { +RZ_API R2RTestResultInfo *rz_test_run_test(R2RRunConfig *config, R2RTest *test) { R2RTestResultInfo *ret = R_NEW0 (R2RTestResultInfo); if (!ret) { return NULL; @@ -1168,18 +1168,18 @@ R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test) { bool success = false; switch (test->type) { case R2R_TEST_TYPE_CMD: { - R2RCmdTest *cmd_test = test->cmd_test; - R2RProcessOutput *out = r2r_run_cmd_test (config, cmd_test, subprocess_runner, NULL); - success = r2r_check_cmd_test (out, cmd_test); + R2RzCmdTest *cmd_test = test->cmd_test; + R2RProcessOutput *out = rz_test_run_cmd_test (config, cmd_test, subprocess_runner, NULL); + success = rz_test_check_cmd_test (out, cmd_test); ret->proc_out = out; ret->timeout = out && out->timeout; ret->run_failed = !out; break; } case R2R_TEST_TYPE_ASM: { - R2RAsmTest *asm_test = test->asm_test; - R2RAsmTestOutput *out = r2r_run_asm_test (config, asm_test); - success = r2r_check_asm_test (out, asm_test); + R2RzAsmTest *asm_test = test->asm_test; + R2RzAsmTestOutput *out = rz_test_run_asm_test (config, asm_test); + success = rz_test_check_asm_test (out, asm_test); ret->asm_out = out; ret->timeout = out->as_timeout || out->disas_timeout; ret->run_failed = !out; @@ -1187,8 +1187,8 @@ R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test) { } case R2R_TEST_TYPE_JSON: { R2RJsonTest *json_test = test->json_test; - R2RProcessOutput *out = r2r_run_json_test (config, json_test, subprocess_runner, NULL); - success = r2r_check_json_test (out, json_test); + R2RProcessOutput *out = rz_test_run_json_test (config, json_test, subprocess_runner, NULL); + success = rz_test_check_json_test (out, json_test); ret->proc_out = out; ret->timeout = out->timeout; ret->run_failed = !out; @@ -1196,14 +1196,14 @@ R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test) { } case R2R_TEST_TYPE_FUZZ: { R2RFuzzTest *fuzz_test = test->fuzz_test; - R2RProcessOutput *out = r2r_run_fuzz_test (config, fuzz_test, subprocess_runner, NULL); - success = r2r_check_fuzz_test (out); + R2RProcessOutput *out = rz_test_run_fuzz_test (config, fuzz_test, subprocess_runner, NULL); + success = rz_test_check_fuzz_test (out); ret->proc_out = out; ret->timeout = out->timeout; ret->run_failed = !out; } } - bool broken = r2r_test_broken (test); + bool broken = rz_test_test_broken (test); #if ASAN # if !R2_ASSERT_STDOUT # error R2_ASSERT_STDOUT undefined or 0 @@ -1225,7 +1225,7 @@ R_API R2RTestResultInfo *r2r_run_test(R2RRunConfig *config, R2RTest *test) { return ret; } -R_API void r2r_test_result_info_free(R2RTestResultInfo *result) { +RZ_API void rz_test_test_result_info_free(R2RTestResultInfo *result) { if (!result) { return; } @@ -1234,10 +1234,10 @@ R_API void r2r_test_result_info_free(R2RTestResultInfo *result) { case R2R_TEST_TYPE_CMD: case R2R_TEST_TYPE_JSON: case R2R_TEST_TYPE_FUZZ: - r2r_process_output_free (result->proc_out); + rz_test_process_output_free (result->proc_out); break; case R2R_TEST_TYPE_ASM: - r2r_asm_test_output_free (result->asm_out); + rz_test_asm_test_output_free (result->asm_out); break; } } diff --git a/binr/r2r/r2r.c b/binrz/rz-test/rz-test.c similarity index 72% rename from binr/r2r/r2r.c rename to binrz/rz-test/rz-test.c index 7e3ecc80ee..b89f81b17f 100644 --- a/binr/r2r/r2r.c +++ b/binrz/rz-test/rz-test.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2020 - thestr4ng3r */ -#include "r2r.h" +#include "rz_test.h" #include #define WORKERS_DEFAULT 8 -#define RADARE2_CMD_DEFAULT "radare2" -#define RASM2_CMD_DEFAULT "rasm2" +#define RADARE2_CMD_DEFAULT "rizin" +#define RASM2_CMD_DEFAULT "rz-asm" #define JSON_TEST_FILE_DEFAULT "bins/elf/crackme0x00b" #define TIMEOUT_DEFAULT 960 @@ -14,13 +14,13 @@ #define WORKERS_DEFAULT_STR STR(WORKERS_DEFAULT) #define TIMEOUT_DEFAULT_STR STR(TIMEOUT_DEFAULT) -typedef struct r2r_state_t { +typedef struct rz_test_state_t { R2RRunConfig run_config; bool verbose; R2RTestDatabase *db; - RThreadCond *cond; // signaled from workers to main thread to update status - RThreadLock *lock; // protects everything below + RzThreadCond *cond; // signaled from workers to main thread to update status + RzThreadLock *lock; // protects everything below HtPP *path_left; // char * (path to test file) => ut64 * (count of remaining tests) RPVector completed_paths; ut64 ok_count; @@ -31,7 +31,7 @@ typedef struct r2r_state_t { RPVector results; } R2RState; -static RThreadFunctionRet worker_th(RThread *th); +static RzThreadFunctionRet worker_th(RzThread *th); static void print_state(R2RState *state, ut64 prev_completed); static void print_log(R2RState *state, ut64 prev_completed, ut64 prev_paths_completed); static void interact(R2RState *state); @@ -41,7 +41,7 @@ static void interact_commands(R2RTestResultInfo *result, RPVector *fixup_results static void interact_diffchar(R2RTestResultInfo *result); static int help(bool verbose) { - printf ("Usage: r2r [-qvVnL] [-j threads] [test file/dir | @test-type]\n"); + printf ("Usage: rz-test [-qvVnL] [-j threads] [test file/dir | @test-type]\n"); if (verbose) { printf ( " -h print this help\n" @@ -53,10 +53,10 @@ static int help(bool verbose) { " -L log mode (better printing for CI, logfiles, etc.)\n" " -F [dir] run fuzz tests (open and default analysis) on all files in the given dir\n" " -j [threads] how many threads to use for running tests concurrently (default is "WORKERS_DEFAULT_STR")\n" - " -r [radare2] path to radare2 executable (default is "RADARE2_CMD_DEFAULT")\n" - " -m [rasm2] path to rasm2 executable (default is "RASM2_CMD_DEFAULT")\n" + " -r [rizin] path to rizin executable (default is "RADARE2_CMD_DEFAULT")\n" + " -m [rz-asm] path to rz-asm executable (default is "RASM2_CMD_DEFAULT")\n" " -f [file] file to use for json tests (default is "JSON_TEST_FILE_DEFAULT")\n" - " -C [dir] chdir before running r2r (default follows executable symlink + test/new\n" + " -C [dir] chdir before running rz_test (default follows executable symlink + test/new\n" " -t [seconds] timeout per test (default is "TIMEOUT_DEFAULT_STR")\n" "\n" "Supported test types: @json @unit @fuzz @cmds\n" @@ -69,20 +69,20 @@ static void path_left_free_kv(HtPPKv *kv) { free (kv->value); } -static bool r2r_chdir(const char *argv0) { +static bool rz_test_chdir(const char *argv0) { #if __UNIX__ - if (r_file_is_directory ("db")) { + if (rz_file_is_directory ("db")) { return true; } char src_path[PATH_MAX]; - char *r2r_path = r_file_path (argv0); + char *rz_test_path = rz_file_path (argv0); bool found = false; - if (readlink (r2r_path, src_path, sizeof (src_path)) != -1) { - char *p = strstr (src_path, R_SYS_DIR "binr"R_SYS_DIR"r2r"R_SYS_DIR"r2r"); + if (readlink (rz_test_path, src_path, sizeof (src_path)) != -1) { + char *p = strstr (src_path, R_SYS_DIR "binrz"R_SYS_DIR"rz_test"R_SYS_DIR"rz_test"); if (p) { *p = 0; strcat (src_path, R_SYS_DIR"test"R_SYS_DIR); - if (r_file_is_directory (src_path)) { + if (rz_file_is_directory (src_path)) { if (chdir (src_path) != -1) { eprintf ("Running from %s\n", src_path); found = true; @@ -92,24 +92,24 @@ static bool r2r_chdir(const char *argv0) { } } } - free (r2r_path); + free (rz_test_path); return found; #else return false; #endif } -static bool r2r_test_run_unit(void) { - return r_sandbox_system ("make -C unit all run", 1) == 0; +static bool rz_test_test_run_unit(void) { + return rz_sandbox_system ("make -C unit all run", 1) == 0; } -static bool r2r_chdir_fromtest(const char *test_path) { +static bool rz_test_chdir_fromtest(const char *test_path) { if (*test_path == '@') { test_path = ""; } - char *abs_test_path = r_file_abspath (test_path); - if (!r_file_is_directory (abs_test_path)) { - char *last_slash = (char *)r_str_lchr (abs_test_path, R_SYS_DIR[0]); + char *abs_test_path = rz_file_abspath (test_path); + if (!rz_file_is_directory (abs_test_path)) { + char *last_slash = (char *)rz_str_lchr (abs_test_path, R_SYS_DIR[0]); if (last_slash) { *last_slash = 0; } @@ -123,20 +123,20 @@ static bool r2r_chdir_fromtest(const char *test_path) { char *cwd = NULL; char *old_cwd = NULL; while (true) { - cwd = r_sys_getdir (); + cwd = rz_sys_getdir (); if (old_cwd && !strcmp (old_cwd, cwd)) { break; } - if (r_file_is_directory ("test")) { - r_sys_chdir ("test"); - if (r_file_is_directory ("db")) { + if (rz_file_is_directory ("test")) { + rz_sys_chdir ("test"); + if (rz_file_is_directory ("db")) { found = true; eprintf ("Running from %s\n", cwd); break; } - r_sys_chdir (".."); + rz_sys_chdir (".."); } - if (r_file_is_directory ("db")) { + if (rz_file_is_directory ("db")) { found = true; eprintf ("Running from %s\n", cwd); break; @@ -160,11 +160,11 @@ int main(int argc, char **argv) { bool quiet = false; bool log_mode = false; bool interactive = false; - char *radare2_cmd = NULL; - char *rasm2_cmd = NULL; + char *rizin_cmd = NULL; + char *rz_asm_cmd = NULL; char *json_test_file = NULL; char *fuzz_dir = NULL; - const char *r2r_dir = NULL; + const char *rz_test_dir = NULL; ut64 timeout_sec = TIMEOUT_DEFAULT; int ret = 0; @@ -182,11 +182,11 @@ int main(int argc, char **argv) { } #endif - RGetopt opt; - r_getopt_init (&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:i"); + RzGetopt opt; + rz_getopt_init (&opt, argc, (const char **)argv, "hqvj:r:m:f:C:LnVt:F:i"); int c; - while ((c = r_getopt_next (&opt)) != -1) { + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'h': ret = help (true); @@ -198,7 +198,7 @@ int main(int argc, char **argv) { if (quiet) { printf (R2_VERSION "\n"); } else { - char *s = r_str_version ("r2r"); + char *s = rz_str_version ("rz_test"); printf ("%s\n", s); free (s); } @@ -225,18 +225,18 @@ int main(int argc, char **argv) { } break; case 'r': - free (radare2_cmd); - radare2_cmd = strdup (opt.arg); + free (rizin_cmd); + rizin_cmd = strdup (opt.arg); break; case 'C': - r2r_dir = opt.arg; + rz_test_dir = opt.arg; break; case 'n': nothing = true; break; case 'm': - free (rasm2_cmd); - rasm2_cmd = strdup (opt.arg); + free (rz_asm_cmd); + rz_asm_cmd = strdup (opt.arg); break; case 'f': free (json_test_file); @@ -254,16 +254,16 @@ int main(int argc, char **argv) { } } - char *cwd = r_sys_getdir (); - if (r2r_dir) { - if (chdir (r2r_dir) == -1) { - eprintf ("Cannot find %s directory.\n", r2r_dir); + char *cwd = rz_sys_getdir (); + if (rz_test_dir) { + if (chdir (rz_test_dir) == -1) { + eprintf ("Cannot find %s directory.\n", rz_test_dir); return -1; } } else { bool dir_found = (opt.ind < argc && argv[opt.ind][0] != '.') - ? r2r_chdir_fromtest (argv[opt.ind]) - : r2r_chdir (argv[0]); + ? rz_test_chdir_fromtest (argv[opt.ind]) + : rz_test_chdir (argv[0]); if (!dir_found) { eprintf ("Cannot find db/ directory related to the given test.\n"); return -1; @@ -272,35 +272,35 @@ int main(int argc, char **argv) { if (fuzz_dir) { char *tmp = fuzz_dir; - fuzz_dir = r_file_abspath_rel (cwd, fuzz_dir); + fuzz_dir = rz_file_abspath_rel (cwd, fuzz_dir); free (tmp); } - if (!r2r_subprocess_init ()) { + if (!rz_test_subprocess_init ()) { eprintf ("Subprocess init failed\n"); return -1; } - atexit (r2r_subprocess_fini); + atexit (rz_test_subprocess_fini); - ut64 time_start = r_time_now_mono (); + ut64 time_start = rz_time_now_mono (); R2RState state = {{0}}; - state.run_config.r2_cmd = radare2_cmd ? radare2_cmd : RADARE2_CMD_DEFAULT; - state.run_config.rasm2_cmd = rasm2_cmd ? rasm2_cmd : RASM2_CMD_DEFAULT; + state.run_config.r2_cmd = rizin_cmd ? rizin_cmd : RADARE2_CMD_DEFAULT; + state.run_config.rz_asm_cmd = rz_asm_cmd ? rz_asm_cmd : RASM2_CMD_DEFAULT; state.run_config.json_test_file = json_test_file ? json_test_file : JSON_TEST_FILE_DEFAULT; state.run_config.timeout_ms = timeout_sec > UT64_MAX / 1000 ? UT64_MAX : timeout_sec * 1000; state.verbose = verbose; - state.db = r2r_test_database_new (); + state.db = rz_test_test_database_new (); if (!state.db) { return -1; } - r_pvector_init (&state.queue, NULL); - r_pvector_init (&state.results, (RPVectorFree)r2r_test_result_info_free); - r_pvector_init (&state.completed_paths, NULL); - state.lock = r_th_lock_new (false); + rz_pvector_init (&state.queue, NULL); + rz_pvector_init (&state.results, (RPVectorFree)rz_test_test_result_info_free); + rz_pvector_init (&state.completed_paths, NULL); + state.lock = rz_th_lock_new (false); if (!state.lock) { return -1; } - state.cond = r_th_cond_new (); + state.cond = rz_th_cond_new (); if (!state.cond) { return -1; } @@ -314,7 +314,7 @@ int main(int argc, char **argv) { arg++; eprintf ("Category: %s\n", arg); if (!strcmp (arg, "unit")) { - if (!r2r_test_run_unit ()) { + if (!rz_test_test_run_unit ()) { return -1; } continue; @@ -323,7 +323,7 @@ int main(int argc, char **argv) { eprintf ("No fuzz dir given. Use -F [dir]\n"); return -1; } - if (!r2r_test_database_load_fuzz (state.db, fuzz_dir)) { + if (!rz_test_test_database_load_fuzz (state.db, fuzz_dir)) { eprintf ("Failed to load fuzz tests from \"%s\"\n", fuzz_dir); } continue; @@ -334,13 +334,13 @@ int main(int argc, char **argv) { } else if (!strcmp (arg, "cmds")) { arg = "db"; } else { - arg = r_str_newf ("db/%s", arg + 1); + arg = rz_str_newf ("db/%s", arg + 1); } } - char *tf = r_file_abspath_rel (cwd, arg); - if (!tf || !r2r_test_database_load (state.db, tf)) { + char *tf = rz_file_abspath_rel (cwd, arg); + if (!tf || !rz_test_test_database_load (state.db, tf)) { eprintf ("Failed to load tests from \"%s\"\n", tf); - r2r_test_database_free (state.db); + rz_test_test_database_free (state.db); free (tf); return -1; } @@ -348,39 +348,39 @@ int main(int argc, char **argv) { } } else { // Default db path - if (!r2r_test_database_load (state.db, "db")) { + if (!rz_test_test_database_load (state.db, "db")) { eprintf ("Failed to load tests from ./db\n"); - r2r_test_database_free (state.db); + rz_test_test_database_free (state.db); return -1; } - if (fuzz_dir && !r2r_test_database_load_fuzz (state.db, fuzz_dir)) { + if (fuzz_dir && !rz_test_test_database_load_fuzz (state.db, fuzz_dir)) { eprintf ("Failed to load fuzz tests from \"%s\"\n", fuzz_dir); } } R_FREE (cwd); - uint32_t loaded_tests = r_pvector_len (&state.db->tests); + uint32_t loaded_tests = rz_pvector_len (&state.db->tests); printf ("Loaded %u tests.\n", loaded_tests); if (nothing) { goto coast; } - bool jq_available = r2r_check_jq_available (); + bool jq_available = rz_test_check_jq_available (); if (!jq_available) { eprintf ("Skipping json tests because jq is not available.\n"); size_t i; - for (i = 0; i < r_pvector_len (&state.db->tests);) { - R2RTest *test = r_pvector_at (&state.db->tests, i); + for (i = 0; i < rz_pvector_len (&state.db->tests);) { + R2RTest *test = rz_pvector_at (&state.db->tests, i); if (test->type == R2R_TEST_TYPE_JSON) { - r2r_test_free (test); - r_pvector_remove_at (&state.db->tests, i); + rz_test_test_free (test); + rz_pvector_remove_at (&state.db->tests, i); continue; } i++; } } - r_pvector_insert_range (&state.queue, 0, state.db->tests.v.a, r_pvector_len (&state.db->tests)); + rz_pvector_insert_range (&state.queue, 0, state.db->tests.v.a, rz_pvector_len (&state.db->tests)); if (log_mode) { // Log mode prints the state after every completed file. @@ -388,7 +388,7 @@ int main(int argc, char **argv) { state.path_left = ht_pp_new (NULL, path_left_free_kv, NULL); if (state.path_left) { void **it; - r_pvector_foreach (&state.queue, it) { + rz_pvector_foreach (&state.queue, it) { R2RTest *test = *it; ut64 *count = ht_pp_find (state.path_left, test->path, NULL); if (!count) { @@ -401,50 +401,50 @@ int main(int argc, char **argv) { } } - r_th_lock_enter (state.lock); + rz_th_lock_enter (state.lock); RPVector workers; - r_pvector_init (&workers, NULL); + rz_pvector_init (&workers, NULL); int i; for (i = 0; i < workers_count; i++) { - RThread *th = r_th_new (worker_th, &state, 0); + RzThread *th = rz_th_new (worker_th, &state, 0); if (!th) { eprintf ("Failed to start thread.\n"); exit (-1); } - r_pvector_push (&workers, th); + rz_pvector_push (&workers, th); } ut64 prev_completed = UT64_MAX; ut64 prev_paths_completed = 0; while (true) { - ut64 completed = (ut64)r_pvector_len (&state.results); + ut64 completed = (ut64)rz_pvector_len (&state.results); if (log_mode) { print_log (&state, prev_completed, prev_paths_completed); } else if (completed != prev_completed) { print_state (&state, prev_completed); } prev_completed = completed; - prev_paths_completed = (ut64)r_pvector_len (&state.completed_paths); - if (completed == r_pvector_len (&state.db->tests)) { + prev_paths_completed = (ut64)rz_pvector_len (&state.completed_paths); + if (completed == rz_pvector_len (&state.db->tests)) { break; } - r_th_cond_wait (state.cond, state.lock); + rz_th_cond_wait (state.cond, state.lock); } - r_th_lock_leave (state.lock); + rz_th_lock_leave (state.lock); printf ("\n"); void **it; - r_pvector_foreach (&workers, it) { - RThread *th = *it; - r_th_wait (th); - r_th_free (th); + rz_pvector_foreach (&workers, it) { + RzThread *th = *it; + rz_th_wait (th); + rz_th_free (th); } - r_pvector_clear (&workers); + rz_pvector_clear (&workers); - ut64 seconds = (r_time_now_mono () - time_start) / 1000000; + ut64 seconds = (rz_time_now_mono () - time_start) / 1000000; printf ("Finished in"); if (seconds > 60) { ut64 minutes = seconds / 60; @@ -462,41 +462,41 @@ int main(int argc, char **argv) { } coast: - r_pvector_clear (&state.queue); - r_pvector_clear (&state.results); - r_pvector_clear (&state.completed_paths); - r2r_test_database_free (state.db); - r_th_lock_free (state.lock); - r_th_cond_free (state.cond); + rz_pvector_clear (&state.queue); + rz_pvector_clear (&state.results); + rz_pvector_clear (&state.completed_paths); + rz_test_test_database_free (state.db); + rz_th_lock_free (state.lock); + rz_th_cond_free (state.cond); beach: - free (radare2_cmd); - free (rasm2_cmd); + free (rizin_cmd); + free (rz_asm_cmd); free (json_test_file); free (fuzz_dir); #if __WINDOWS__ if (old_cp) { (void)SetConsoleOutputCP (old_cp); // chcp doesn't pick up the code page switch for some reason - (void)r_sys_cmdf ("chcp %u > NUL", old_cp); + (void)rz_sys_cmdf ("chcp %u > NUL", old_cp); } #endif return ret; } -static RThreadFunctionRet worker_th(RThread *th) { +static RzThreadFunctionRet worker_th(RzThread *th) { R2RState *state = th->user; - r_th_lock_enter (state->lock); + rz_th_lock_enter (state->lock); while (true) { - if (r_pvector_empty (&state->queue)) { + if (rz_pvector_empty (&state->queue)) { break; } - R2RTest *test = r_pvector_pop (&state->queue); - r_th_lock_leave (state->lock); + R2RTest *test = rz_pvector_pop (&state->queue); + rz_th_lock_leave (state->lock); - R2RTestResultInfo *result = r2r_run_test (&state->run_config, test); + R2RTestResultInfo *result = rz_test_run_test (&state->run_config, test); - r_th_lock_enter (state->lock); - r_pvector_push (&state->results, result); + rz_th_lock_enter (state->lock); + rz_pvector_push (&state->results, result); switch (result->result) { case R2R_TEST_RESULT_OK: state->ok_count++; @@ -516,46 +516,46 @@ static RThreadFunctionRet worker_th(RThread *th) { if (count) { (*count)--; if (!*count) { - r_pvector_push (&state->completed_paths, (void *)test->path); + rz_pvector_push (&state->completed_paths, (void *)test->path); } } } - r_th_cond_signal (state->cond); + rz_th_cond_signal (state->cond); } - r_th_lock_leave (state->lock); + rz_th_lock_leave (state->lock); return R_TH_STOP; } static void print_diff(const char *actual, const char *expected, bool diffchar) { - RDiff *d = r_diff_new (); + RzDiff *d = rz_diff_new (); #ifdef __WINDOWS__ d->diff_cmd = "git diff --no-index"; #endif if (diffchar) { - RDiffChar *diff = r_diffchar_new ((const ut8 *)expected, (const ut8 *)actual); + RzDiffChar *diff = rz_diffchar_new ((const ut8 *)expected, (const ut8 *)actual); if (diff) { - r_diffchar_print (diff); - r_diffchar_free (diff); + rz_diffchar_print (diff); + rz_diffchar_free (diff); return; } d->diff_cmd = "git diff --no-index --word-diff=porcelain --word-diff-regex=."; } - char *uni = r_diff_buffers_to_string (d, (const ut8 *)expected, (int)strlen (expected), + char *uni = rz_diff_buffers_to_string (d, (const ut8 *)expected, (int)strlen (expected), (const ut8 *)actual, (int)strlen (actual)); - r_diff_free (d); + rz_diff_free (d); - RList *lines = r_str_split_duplist (uni, "\n", false); - RListIter *it; + RzList *lines = rz_str_split_duplist (uni, "\n", false); + RzListIter *it; char *line; bool header_found = false; - r_list_foreach (lines, it, line) { + rz_list_foreach (lines, it, line) { if (!header_found) { - if (r_str_startswith (line, "+++ ")) { + if (rz_str_startswith (line, "+++ ")) { header_found = true; } continue; } - if (r_str_startswith (line, "@@ ") && r_str_endswith (line, " @@")) { + if (rz_str_startswith (line, "@@ ") && rz_str_endswith (line, " @@")) { printf ("%s%s%s\n", Color_CYAN, line, Color_RESET); continue; } @@ -584,7 +584,7 @@ static void print_diff(const char *actual, const char *expected, bool diffchar) printf ("%s", Color_RESET); } } - r_list_free (lines); + rz_list_free (lines); free (uni); printf ("\n"); } @@ -610,12 +610,12 @@ static R2RProcessOutput *print_runner(const char *file, const char *args[], size static void print_result_diff(R2RRunConfig *config, R2RTestResultInfo *result) { if (result->run_failed) { - printf (Color_RED "RUN FAILED (e.g. wrong radare2 path)" Color_RESET "\n"); + printf (Color_RED "RUN FAILED (e.g. wrong rizin path)" Color_RESET "\n"); return; } switch (result->test->type) { case R2R_TEST_TYPE_CMD: { - r2r_run_cmd_test (config, result->test->cmd_test, print_runner, NULL); + rz_test_run_cmd_test (config, result->test->cmd_test, print_runner, NULL); const char *expect = result->test->cmd_test->expect.value; if (expect && strcmp (result->proc_out->out, expect)) { printf ("-- stdout\n"); @@ -640,7 +640,7 @@ static void print_result_diff(R2RRunConfig *config, R2RTestResultInfo *result) { case R2R_TEST_TYPE_JSON: break; case R2R_TEST_TYPE_FUZZ: - r2r_run_fuzz_test (config, result->test->fuzz_test, print_runner, NULL); + rz_test_run_fuzz_test (config, result->test->fuzz_test, print_runner, NULL); printf ("-- stdout\n%s\n", result->proc_out->out); printf ("-- stderr\n%s\n", result->proc_out->err); printf ("-- exit status: "Color_RED"%d"Color_RESET"\n", result->proc_out->ret); @@ -650,14 +650,14 @@ static void print_result_diff(R2RRunConfig *config, R2RTestResultInfo *result) { static void print_new_results(R2RState *state, ut64 prev_completed) { // Detailed test result (with diff if necessary) - ut64 completed = (ut64)r_pvector_len (&state->results); + ut64 completed = (ut64)rz_pvector_len (&state->results); ut64 i; for (i = prev_completed; i < completed; i++) { - R2RTestResultInfo *result = r_pvector_at (&state->results, (size_t)i); + R2RTestResultInfo *result = rz_pvector_at (&state->results, (size_t)i); if (!state->verbose && (result->result == R2R_TEST_RESULT_OK || result->result == R2R_TEST_RESULT_FIXED || result->result == R2R_TEST_RESULT_BROKEN)) { continue; } - char *name = r2r_test_name (result->test); + char *name = rz_test_test_name (result->test); if (!name) { continue; } @@ -700,7 +700,7 @@ static void print_state(R2RState *state, ut64 prev_completed) { // [x/x] OK 42 BR 0 ... printf (R_CONS_CLEAR_LINE); - int w = printf ("[%"PFMT64u"/%"PFMT64u"]", (ut64)r_pvector_len (&state->results), (ut64)r_pvector_len (&state->db->tests)); + int w = printf ("[%"PFMT64u"/%"PFMT64u"]", (ut64)rz_pvector_len (&state->results), (ut64)rz_pvector_len (&state->db->tests)); while (w >= 0 && w < 20) { printf (" "); w++; @@ -715,9 +715,9 @@ static void print_state(R2RState *state, ut64 prev_completed) { static void print_log(R2RState *state, ut64 prev_completed, ut64 prev_paths_completed) { print_new_results (state, prev_completed); - ut64 paths_completed = r_pvector_len (&state->completed_paths); + ut64 paths_completed = rz_pvector_len (&state->completed_paths); for (; prev_paths_completed < paths_completed; prev_paths_completed++) { - printf ("[**] %50s ", (const char *)r_pvector_at (&state->completed_paths, prev_paths_completed)); + printf ("[**] %50s ", (const char *)rz_pvector_at (&state->completed_paths, prev_paths_completed)); print_state_counts (state); printf ("\n"); } @@ -726,14 +726,14 @@ static void print_log(R2RState *state, ut64 prev_completed, ut64 prev_paths_comp static void interact(R2RState *state) { void **it; RPVector failed_results; - r_pvector_init (&failed_results, NULL); - r_pvector_foreach (&state->results, it) { + rz_pvector_init (&failed_results, NULL); + rz_pvector_foreach (&state->results, it) { R2RTestResultInfo *result = *it; if (result->result == R2R_TEST_RESULT_FAILED) { - r_pvector_push (&failed_results, result); + rz_pvector_push (&failed_results, result); } } - if (r_pvector_empty (&failed_results)) { + if (rz_pvector_empty (&failed_results)) { goto beach; } @@ -743,9 +743,9 @@ static void interact(R2RState *state) { printf ("\n"); printf ("#####################\n"); printf (" %"PFMT64u" failed test(s) "UTF8_POLICE_CARS_REVOLVING_LIGHT"\n", - (ut64)r_pvector_len (&failed_results)); + (ut64)rz_pvector_len (&failed_results)); - r_pvector_foreach (&failed_results, it) { + rz_pvector_foreach (&failed_results, it) { R2RTestResultInfo *result = *it; if (result->test->type != R2R_TEST_TYPE_CMD) { // TODO: other types of tests @@ -797,19 +797,19 @@ menu: } beach: - r_pvector_clear (&failed_results); + rz_pvector_clear (&failed_results); } static char *format_cmd_kv(const char *key, const char *val) { RStrBuf buf; - r_strbuf_init (&buf); - r_strbuf_appendf (&buf, "%s=", key); + rz_strbuf_init (&buf); + rz_strbuf_appendf (&buf, "%s=", key); if (strchr (val, '\n')) { - r_strbuf_appendf (&buf, "<test->type != R2R_TEST_TYPE_CMD) { continue; @@ -859,7 +859,7 @@ static void fixup_tests(RPVector *results, const char *edited_file, ut64 start_l if (result->test->path != edited_file) { // this works because all the paths come from the string pool continue; } - R2RCmdTest *test = result->test->cmd_test; + R2RzCmdTest *test = result->test->cmd_test; test->run_line += delta; #define DO_KEY_STR(key, field) \ @@ -894,7 +894,7 @@ static char *replace_cmd_kv(const char *path, const char *content, size_t line_b if (!kv) { return NULL; } - size_t kv_lines = r_str_char_count (kv, '\n') + 1; + size_t kv_lines = rz_str_char_count (kv, '\n') + 1; char *newc = replace_lines (content, line_begin, line_end, kv); free (kv); if (!newc) { @@ -910,7 +910,7 @@ static char *replace_cmd_kv(const char *path, const char *content, size_t line_b } static void replace_cmd_kv_file(const char *path, ut64 line_begin, ut64 line_end, const char *key, const char *value, RPVector *fixup_results) { - char *content = r_file_slurp (path, NULL); + char *content = rz_file_slurp (path, NULL); if (!content) { eprintf ("Failed to read file \"%s\"\n", path); return; @@ -920,7 +920,7 @@ static void replace_cmd_kv_file(const char *path, ut64 line_begin, ut64 line_end if (!newc) { return; } - if (r_file_dump (path, (const ut8 *)newc, -1, false)) { + if (rz_file_dump (path, (const ut8 *)newc, -1, false)) { #if __UNIX__ sync (); #endif @@ -932,7 +932,7 @@ static void replace_cmd_kv_file(const char *path, ut64 line_begin, ut64 line_end static void interact_fix(R2RTestResultInfo *result, RPVector *fixup_results) { assert (result->test->type == R2R_TEST_TYPE_CMD); - R2RCmdTest *test = result->test->cmd_test; + R2RzCmdTest *test = result->test->cmd_test; R2RProcessOutput *out = result->proc_out; if (test->expect.value && out->out) { replace_cmd_kv_file (result->test->path, test->expect.line_begin, test->expect.line_end, "EXPECT", out->out, fixup_results); @@ -944,7 +944,7 @@ static void interact_fix(R2RTestResultInfo *result, RPVector *fixup_results) { static void interact_break(R2RTestResultInfo *result, RPVector *fixup_results) { assert (result->test->type == R2R_TEST_TYPE_CMD); - R2RCmdTest *test = result->test->cmd_test; + R2RzCmdTest *test = result->test->cmd_test; ut64 line_begin; ut64 line_end; if (test->broken.set) { @@ -958,12 +958,12 @@ static void interact_break(R2RTestResultInfo *result, RPVector *fixup_results) { static void interact_commands(R2RTestResultInfo *result, RPVector *fixup_results) { assert (result->test->type == R2R_TEST_TYPE_CMD); - R2RCmdTest *test = result->test->cmd_test; + R2RzCmdTest *test = result->test->cmd_test; if (!test->cmds.value) { return; } char *name = NULL; - int fd = r_file_mkstemp ("r2r-cmds", &name); + int fd = rz_file_mkstemp ("rz_test-cmds", &name); if (fd == -1) { free (name); eprintf ("Failed to open tmp file\n"); @@ -978,7 +978,7 @@ static void interact_commands(R2RTestResultInfo *result, RPVector *fixup_results } close (fd); - char *editor = r_sys_getenv ("EDITOR"); + char *editor = rz_sys_getenv ("EDITOR"); if (!editor || !*editor) { free (editor); editor = strdup ("vim"); @@ -987,21 +987,21 @@ static void interact_commands(R2RTestResultInfo *result, RPVector *fixup_results return; } } - r_sys_cmdf ("%s '%s'", editor, name); + rz_sys_cmdf ("%s '%s'", editor, name); free (editor); - char *newcmds = r_file_slurp (name, NULL); + char *newcmds = rz_file_slurp (name, NULL); if (!newcmds) { eprintf ("Failed to read edited command file\n"); free (name); return; } - r_str_trim (newcmds); + rz_str_trim (newcmds); // if it's multiline we want exactly one trailing newline if (strchr (newcmds, '\n')) { char *tmp = newcmds; - newcmds = r_str_newf ("%s\n", newcmds); + newcmds = rz_str_newf ("%s\n", newcmds); free (tmp); if (!newcmds) { free (name); diff --git a/binrz/rz-test/rz_test.h b/binrz/rz-test/rz_test.h new file mode 100644 index 0000000000..d06d3ef50f --- /dev/null +++ b/binrz/rz-test/rz_test.h @@ -0,0 +1,215 @@ +/* radare - LGPL - Copyright 2020 - thestr4ng3r */ + +#ifndef RADARE2_R2R_H +#define RADARE2_R2R_H + +#include + +#if defined (__FreeBSD__) || defined (__FreeBSD_kernel__) +#define R2R_OS "freebsd" +#elif defined(__linux__) +#define R2R_OS "linux" +#elif defined(__APPLE__) +#define R2R_OS "darwin" +#elif __WINDOWS__ +#define R2R_OS "windows" +#else +#define R2R_OS "unknown" +#endif + +#if __i386__ +#define R2R_ARCH "x86" +#elif __x86_64__ +#define R2R_ARCH "x64" +#else +#define R2R_ARCH "unknown" +#endif + +#define R2R_ARCH_OS R2R_OS"-"R2R_ARCH + +typedef struct rz_test_cmd_test_string_record { + char *value; + ut64 line_begin; // inclusive + ut64 line_end; // exclusive +} R2RzCmdTestStringRecord; + +typedef struct rz_test_cmd_test_bool_record { + bool value; + ut64 line; // bools are always oneliners (e.g. BROKEN=1) + bool set; +} R2RzCmdTestBoolRecord; + +typedef struct rz_test_cmd_test_num_record { + ut64 value; + ut64 line; // nums are always oneliners (e.g. TIMEOUT=10) + bool set; +} R2RzCmdTestNumRecord; + +typedef struct rz_test_cmd_test_t { + R2RzCmdTestStringRecord name; + R2RzCmdTestStringRecord file; + R2RzCmdTestStringRecord args; + R2RzCmdTestStringRecord source; + R2RzCmdTestStringRecord cmds; + R2RzCmdTestStringRecord expect; + R2RzCmdTestStringRecord expect_err; + R2RzCmdTestBoolRecord broken; + R2RzCmdTestNumRecord timeout; + ut64 run_line; + bool load_plugins; +} R2RzCmdTest; + +#define R2R_CMD_TEST_FOREACH_RECORD_NOP(name, field) +#define R2R_CMD_TEST_FOREACH_RECORD(macro_str, macro_bool, macro_int) \ + macro_str ("NAME", name) \ + macro_str ("FILE", file) \ + macro_str ("ARGS", args) \ + macro_int ("TIMEOUT", timeout) \ + macro_str ("SOURCE", source) \ + macro_str ("CMDS", cmds) \ + macro_str ("EXPECT", expect) \ + macro_str ("EXPECT_ERR", expect_err) \ + macro_bool ("BROKEN", broken) + +typedef enum rz_test_asm_test_mode_t { + R2R_ASM_TEST_MODE_ASSEMBLE = 1, + R2R_ASM_TEST_MODE_DISASSEMBLE = (1 << 1), + R2R_ASM_TEST_MODE_BIG_ENDIAN = (1 << 2), + R2R_ASM_TEST_MODE_BROKEN = (1 << 3) +} R2RzAsmTestMode; + +typedef struct rz_test_asm_test_t { + ut64 line; + const char *arch; + const char *cpu; + int bits; + int mode; + ut64 offset; + char *disasm; + ut8 *bytes; + size_t bytes_size; +} R2RzAsmTest; + +typedef struct rz_test_json_test_t { + ut64 line; + char *cmd; + bool broken; + bool load_plugins; +} R2RJsonTest; + +typedef struct rz_test_fuzz_test_t { + char *file; +} R2RFuzzTest; + +typedef enum rz_test_test_type_t { + R2R_TEST_TYPE_CMD, + R2R_TEST_TYPE_ASM, + R2R_TEST_TYPE_JSON, + R2R_TEST_TYPE_FUZZ +} R2RTestType; + +typedef struct rz_test_test_t { + const char *path; + R2RTestType type; + union { + R2RzCmdTest *cmd_test; + R2RzAsmTest *asm_test; + R2RJsonTest *json_test; + R2RFuzzTest *fuzz_test; + }; +} R2RTest; + +typedef struct rz_test_test_database_t { + RPVector tests; + RStrConstPool strpool; +} R2RTestDatabase; + +typedef struct rz_test_run_config_t { + const char *r2_cmd; + const char *rz_asm_cmd; + const char *json_test_file; + ut64 timeout_ms; +} R2RRunConfig; + +typedef struct rz_test_process_output_t { + char *out; // stdout + char *err; // stderr + int ret; // exit code of the process + bool timeout; +} R2RProcessOutput; + +typedef struct rz_test_asm_test_output_t { + char *disasm; + ut8 *bytes; + size_t bytes_size; + bool as_timeout; + bool disas_timeout; +} R2RzAsmTestOutput; + +typedef enum rz_test_test_result_t { + R2R_TEST_RESULT_OK, + R2R_TEST_RESULT_FAILED, + R2R_TEST_RESULT_BROKEN, + R2R_TEST_RESULT_FIXED +} R2RTestResult; + +typedef struct rz_test_test_result_info_t { + R2RTest *test; + R2RTestResult result; + bool timeout; + bool run_failed; // something went seriously wrong (e.g. r2 not found) + union { + R2RProcessOutput *proc_out; // for test->type == R2R_TEST_TYPE_CMD, R2R_TEST_TYPE_JSON or R2R_TEST_TYPE_FUZZ + R2RzAsmTestOutput *asm_out; // for test->type == R2R_TEST_TYPE_ASM + }; +} R2RTestResultInfo; + +RZ_API R2RzCmdTest *rz_test_cmd_test_new(void); +RZ_API void rz_test_cmd_test_free(R2RzCmdTest *test); +RZ_API RPVector *rz_test_load_cmd_test_file(const char *file); + +RZ_API R2RzAsmTest *rz_test_asm_test_new(void); +RZ_API void rz_test_asm_test_free(R2RzAsmTest *test); +RZ_API RPVector *rz_test_load_asm_test_file(RStrConstPool *strpool, const char *file); + +RZ_API R2RJsonTest *rz_test_json_test_new(void); +RZ_API void rz_test_json_test_free(R2RJsonTest *test); +RZ_API RPVector *rz_test_load_json_test_file(const char *file); + +RZ_API R2RTestDatabase *rz_test_test_database_new(void); +RZ_API void rz_test_test_database_free(R2RTestDatabase *db); +RZ_API bool rz_test_test_database_load(R2RTestDatabase *db, const char *path); +RZ_API bool rz_test_test_database_load_fuzz(R2RTestDatabase *db, const char *path); + +typedef struct rz_test_subprocess_t R2RSubprocess; + +RZ_API bool rz_test_subprocess_init(void); +RZ_API void rz_test_subprocess_fini(void); +RZ_API R2RSubprocess *rz_test_subprocess_start( + const char *file, const char *args[], size_t args_size, + const char *envvars[], const char *envvals[], size_t env_size); +RZ_API bool rz_test_subprocess_wait(R2RSubprocess *proc, ut64 timeout_ms); +RZ_API void rz_test_subprocess_free(R2RSubprocess *proc); + +typedef R2RProcessOutput *(*R2RzCmdRunner)(const char *file, const char *args[], size_t args_size, + const char *envvars[], const char *envvals[], size_t env_size, ut64 timeout_ms, void *user); + +RZ_API void rz_test_process_output_free(R2RProcessOutput *out); +RZ_API R2RProcessOutput *rz_test_run_cmd_test(R2RRunConfig *config, R2RzCmdTest *test, R2RzCmdRunner runner, void *user); +RZ_API bool rz_test_check_cmd_test(R2RProcessOutput *out, R2RzCmdTest *test); +RZ_API bool rz_test_check_jq_available(void); +RZ_API R2RProcessOutput *rz_test_run_json_test(R2RRunConfig *config, R2RJsonTest *test, R2RzCmdRunner runner, void *user); +RZ_API bool rz_test_check_json_test(R2RProcessOutput *out, R2RJsonTest *test); +RZ_API R2RzAsmTestOutput *rz_test_run_asm_test(R2RRunConfig *config, R2RzAsmTest *test); +RZ_API bool rz_test_check_asm_test(R2RzAsmTestOutput *out, R2RzAsmTest *test); +RZ_API void rz_test_asm_test_output_free(R2RzAsmTestOutput *out); +RZ_API R2RProcessOutput *rz_test_run_fuzz_test(R2RRunConfig *config, R2RFuzzTest *test, R2RzCmdRunner runner, void *user); +RZ_API bool rz_test_check_fuzz_test(R2RProcessOutput *out); + +RZ_API void rz_test_test_free(R2RTest *test); +RZ_API char *rz_test_test_name(R2RTest *test); +RZ_API bool rz_test_test_broken(R2RTest *test); +RZ_API R2RTestResultInfo *rz_test_run_test(R2RRunConfig *config, R2RTest *test); +RZ_API void rz_test_test_result_info_free(R2RTestResultInfo *result); + +#endif //RADARE2_R2R_H diff --git a/configure b/configure index 039973c3b3..b7b6285b19 100755 --- a/configure +++ b/configure @@ -111,7 +111,7 @@ create_environ() { : ${DATADIR:="${SPREFIX}/share"} : ${INFODIR:="${DATADIR}/info"} : ${MANDIR:="${DATADIR}/man"} -: ${DOCDIR:="${DATADIR}/doc/radare2"} +: ${DOCDIR:="${DATADIR}/doc/rizin"} : ${LOCALSTATEDIR:="${SPREFIX}/var"} for A in `echo ${PATH} | sed -e 's,:, ,g'` ; do [ -e "$A"/ginstall ] && : ${INSTALL:="$A"/ginstall} && break @@ -124,12 +124,12 @@ done : ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s} : ${INSTALL_MAN:=${INSTALL} -m 444} : ${INSTALL_LIB:=${INSTALL} -m 755 -c} - PKGNAME='radare2' ; VERSION='4.6.0-git' ; VERSION_MAJOR=4; VERSION_MINOR=6; VERSION_PATCH=0; VERSION_NUMBER=40600; CONTACT_MAIL="pancake@nopcode.org" ; CONTACT_NAME="pancake" ; CONTACT="pancake " ; + PKGNAME='rizin' ; VERSION='4.6.0-git' ; VERSION_MAJOR=4; VERSION_MINOR=6; VERSION_PATCH=0; VERSION_NUMBER=40600; CONTACT_MAIL="pancake@nopcode.org" ; CONTACT_NAME="pancake" ; CONTACT="pancake " ; } show_usage() { cat <." exit 0 @@ -236,13 +236,13 @@ case $flag in -V|-version|--version) show_version ; ;; -r|--r|--report) -echo "PKGNAME: radare2" +echo "PKGNAME: rizin" echo "VERSION: 4.6.0-git" echo "LANGS: c" echo "REQUIRED: libdl" echo "OPTIONAL: libmagic libz libzip libxxhash libssl liblibuv>=1.0.0" echo "PKG-CONFIG: capstone openssl libuv" -echo "FLAGS: --disable-debugger --with-sysmagic --with-capstone5 --disable-loadlibs --without-dylink --without-fork --without-ptrace-wrap --with-libr --with-syscapstone --with-syszip --with-sysxxhash --without-gpl --with-openssl --without-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --without-r2r --with-checks-level=2" +echo "FLAGS: --disable-debugger --with-sysmagic --with-capstone5 --disable-loadlibs --without-dylink --without-fork --without-ptrace-wrap --with-librz --with-syscapstone --with-syszip --with-sysxxhash --without-gpl --with-openssl --without-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --without-rz-test --with-checks-level=2" exit 0 ;; --cache-file) @@ -295,7 +295,7 @@ echo "FLAGS: --disable-debugger --with-sysmagic --with-capstone5 --disable-l "--without-dylink") WANT_DYLINK="0"; ;; "--without-fork") HAVE_FORK="0"; ;; "--without-ptrace-wrap") WANT_PTRACE_WRAP="0"; ;; -"--with-libr") WITH_LIBR="1"; ;; +"--with-librz") WITH_LIBR="1"; ;; "--with-syscapstone") WITH_CAPSTONE="1"; ;; "--with-syszip") USE_ZIP="1"; ;; "--with-sysxxhash") USE_XXHASH="1"; ;; @@ -307,7 +307,7 @@ echo "FLAGS: --disable-debugger --with-sysmagic --with-capstone5 --disable-l --with-ostype) if [ -z "${value}" ]; then USEROSTYPE="auto"; else USEROSTYPE="${value}" ; fi ;; --with-libversion) if [ -z "${value}" ]; then LIBVERSION="xxx"; else LIBVERSION="${value}" ; fi ;; "--without-jemalloc") HAVE_JEMALLOC="0"; ;; -"--without-r2r") WANT_R2R="0"; ;; +"--without-rz-test") WANT_R2R="0"; ;; --with-checks-level) if [ -z "${value}" ]; then R_CHECKS_LEVEL="2"; else R_CHECKS_LEVEL="${value}" ; fi ;; *) if [ "$value" ]; then eval "`echo $flag2=$value`" ; else echo ; echo "WARNING: Unknown flag '$flag'." >&2 ; echo ; fi ;; @@ -704,7 +704,7 @@ for A in ${ENVWORDS} ; do SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;" done SEDFLAGS="${SEDFLAGS}'" -for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/r_io.pc pkgcfg/r_magic.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_anal.pc pkgcfg/r_hash.pc pkgcfg/r_cons.pc pkgcfg/r_core.pc pkgcfg/r_lang.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_config.pc pkgcfg/r_flag.pc pkgcfg/r_syscall.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_bp.pc pkgcfg/r_parse.pc pkgcfg/r_fs.pc pkgcfg/r_egg.pc pkgcfg/r_crypto.pc ; do # SUBDIRS +for A in ./config-user.mk librz/include/rz_userconf.h pkgcfg/rz_io.pc pkgcfg/rz_magic.pc pkgcfg/rz_asm.pc pkgcfg/rz_bin.pc pkgcfg/rz_anal.pc pkgcfg/rz_hash.pc pkgcfg/rz_cons.pc pkgcfg/rz_core.pc pkgcfg/rz_lang.pc pkgcfg/rz_socket.pc pkgcfg/rz_debug.pc pkgcfg/rz_reg.pc pkgcfg/rz_config.pc pkgcfg/rz_flag.pc pkgcfg/rz_syscall.pc pkgcfg/rz_util.pc pkgcfg/rz_search.pc pkgcfg/rz_bp.pc pkgcfg/rz_parse.pc pkgcfg/rz_fs.pc pkgcfg/rz_egg.pc pkgcfg/rz_crypto.pc ; do # SUBDIRS if [ -f "${VPATH}/${A}.acr" ]; then SD_TARGET=${A} else diff --git a/configure-plugins b/configure-plugins index 568bcc63c6..b78af0b310 100755 --- a/configure-plugins +++ b/configure-plugins @@ -70,7 +70,7 @@ generate_configh () { echo "#define R_${uclib}_STATIC_PLUGINS \\" plugins="${plugins} __${uclib}" fi - echo " &r_${lib}_plugin_${plg}, \\" + echo " &rz_${lib}_plugin_${plg}, \\" done [ -n "$oldlib" ] && echo " 0" @@ -132,16 +132,16 @@ generate_configmk () { } generate () { - echo "configure-plugins: Generating libr/config.h .." - cat libr/config.h.head > libr/config.h - echo "#define R2_LOADLIBS ${LOADLIBS}" >> libr/config.h - generate_configh >> libr/config.h - cat libr/config.h.tail >> libr/config.h + echo "configure-plugins: Generating librz/config.h .." + cat librz/config.h.head > librz/config.h + echo "#define R2_LOADLIBS ${LOADLIBS}" >> librz/config.h + generate_configh >> librz/config.h + cat librz/config.h.tail >> librz/config.h - echo "configure-plugins: Generating libr/config.mk .." - cat libr/config.mk.head > libr/config.mk - generate_configmk >> libr/config.mk - cat libr/config.mk.tail >> libr/config.mk + echo "configure-plugins: Generating librz/config.mk .." + cat librz/config.mk.head > librz/config.mk + generate_configmk >> librz/config.mk + cat librz/config.mk.tail >> librz/config.mk return } diff --git a/configure.acr b/configure.acr index bef837f84d..6e8414fc34 100644 --- a/configure.acr +++ b/configure.acr @@ -1,4 +1,4 @@ -PKGNAME radare2 +PKGNAME rizin VERSION 4.6.0-git CONTACT pancake ; pancake@nopcode.org @@ -30,7 +30,7 @@ ARG_WITHOUT WANT_DYLINK dylink disable support for dynamic loading of plugins ; ARG_WITHOUT HAVE_FORK fork disable fork ; ARG_WITHOUT WANT_PTRACE_WRAP ptrace-wrap disable ptrace-wrap build ; -ARG_WITH WITH_LIBR libr build libr.a and libr.dylib ; +ARG_WITH WITH_LIBR librz build librz.a and librz.dylib ; ARG_WITH WITH_CAPSTONE syscapstone force to use system-wide capstone ; IF WITH_CAPSTONE { @@ -238,7 +238,7 @@ IFEQ WANT_PTRACE_WRAP 0 ; { USE_PTRACE_WRAP = 0 ; } -ARG_WITHOUT WANT_R2R r2r build without r2r for regression testing ; +ARG_WITHOUT WANT_R2R rz-test build without rz-test for regression testing ; ARG_WITH R_CHECKS_LEVEL=2 checks-level value between 0 and 3 to enable different level of assert (see R_CHECKS_LEVEL) ; @@ -248,27 +248,27 @@ REPORT R_CHECKS_LEVEL WANT_R2R PREFIX HAVE_LIB_GMP HAVE_OPENSSL HAVE_LIBUV USE_C (( TODO: Add the rest of .pc files here.. add a rule for acr? )) SUBDIRS ./config-user.mk - libr/include/r_userconf.h - pkgcfg/r_io.pc - pkgcfg/r_magic.pc - pkgcfg/r_asm.pc - pkgcfg/r_bin.pc - pkgcfg/r_anal.pc - pkgcfg/r_hash.pc - pkgcfg/r_cons.pc - pkgcfg/r_core.pc - pkgcfg/r_lang.pc - pkgcfg/r_socket.pc - pkgcfg/r_debug.pc - pkgcfg/r_reg.pc - pkgcfg/r_config.pc - pkgcfg/r_flag.pc - pkgcfg/r_syscall.pc - pkgcfg/r_util.pc - pkgcfg/r_search.pc - pkgcfg/r_bp.pc - pkgcfg/r_parse.pc - pkgcfg/r_fs.pc - pkgcfg/r_egg.pc - pkgcfg/r_crypto.pc + librz/include/rz_userconf.h + pkgcfg/rz_io.pc + pkgcfg/rz_magic.pc + pkgcfg/rz_asm.pc + pkgcfg/rz_bin.pc + pkgcfg/rz_anal.pc + pkgcfg/rz_hash.pc + pkgcfg/rz_cons.pc + pkgcfg/rz_core.pc + pkgcfg/rz_lang.pc + pkgcfg/rz_socket.pc + pkgcfg/rz_debug.pc + pkgcfg/rz_reg.pc + pkgcfg/rz_config.pc + pkgcfg/rz_flag.pc + pkgcfg/rz_syscall.pc + pkgcfg/rz_util.pc + pkgcfg/rz_search.pc + pkgcfg/rz_bp.pc + pkgcfg/rz_parse.pc + pkgcfg/rz_fs.pc + pkgcfg/rz_egg.pc + pkgcfg/rz_crypto.pc ; diff --git a/doc/3D/3D-logo.r2 b/doc/3D/3D-logo.rz similarity index 100% rename from doc/3D/3D-logo.r2 rename to doc/3D/3D-logo.rz diff --git a/doc/3D/3D-pyramid.r2 b/doc/3D/3D-pyramid.rz similarity index 100% rename from doc/3D/3D-pyramid.r2 rename to doc/3D/3D-pyramid.rz diff --git a/doc/3D/3D-square.r2 b/doc/3D/3D-square.rz similarity index 100% rename from doc/3D/3D-square.r2 rename to doc/3D/3D-square.rz diff --git a/doc/all68k.r2 b/doc/all68k.rz similarity index 100% rename from doc/all68k.r2 rename to doc/all68k.rz diff --git a/doc/android.md b/doc/android.md index 156c660d79..2eff6b506c 100644 --- a/doc/android.md +++ b/doc/android.md @@ -12,7 +12,7 @@ To build r2 for android you need to install the NDK: Edit `~/.r2androidrc` to setup the paths to your ndk sys/android-shell.sh - ./configure --with-compiler=android --with-ostype=android --prefix=/data/radare2 --without-pic --with-nonpic + ./configure --with-compiler=android --with-ostype=android --prefix=/data/rizin --without-pic --with-nonpic make -j 4 To compile for android-x86 diff --git a/doc/avr.md b/doc/avr.md index 49733f4235..c23b7e0c2f 100644 --- a/doc/avr.md +++ b/doc/avr.md @@ -12,11 +12,11 @@ Install SDK from Arduino: Install avarice, the gdbserver <-> jtag: - r2pm -i avarice + rz_pm -i avarice Run the proxy: - r2pm -r avarice --jtag /dev/tty.wch* --mkI :4242 + rz_pm -r avarice --jtag /dev/tty.wch* --mkI :4242 Using GDB: diff --git a/doc/bash_autocompletion.sh b/doc/bash_autocompletion.sh index f9a22220ff..11468a2bb3 100644 --- a/doc/bash_autocompletion.sh +++ b/doc/bash_autocompletion.sh @@ -5,14 +5,14 @@ if [ -z "$BASH" ]; then bashcompinit fi -_r2 () { +_rz () { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prv=${COMP_WORDS[COMP_CWORD-1]} case "$prv" in -a) - COMPREPLY=( $(compgen -W "$(rasm2 -qL)" -- $cur)) + COMPREPLY=( $(compgen -W "$(rz_asm -qL)" -- $cur)) return 0 ;; -b) @@ -28,7 +28,7 @@ _r2 () { return 0 ;; -F) - COMPREPLY=( $(compgen -W "$(rabin2 -qL)" -- $cur )) + COMPREPLY=( $(compgen -W "$(rz_bin -qL)" -- $cur )) return 0 ;; -H) @@ -57,17 +57,17 @@ _r2 () { return 0 } -complete -F _r2 -o filenames r2 -complete -F _r2 -o filenames radare2 +complete -F _rz -o filenames r2 +complete -F _rz -o filenames rizin -_rasm2 () { +_rz_asm () { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prv=${COMP_WORDS[COMP_CWORD-1]} case "$prv" in -a) - COMPREPLY=( $(compgen -W "$(rasm2 -qL)" -- $cur)) + COMPREPLY=( $(compgen -W "$(rz_asm -qL)" -- $cur)) return 0 ;; -b) @@ -83,7 +83,7 @@ _rasm2 () { return 0 ;; -s) - COMPREPLY=( $(compgen -W "$(rasm2 -s?)" -- $cur )) + COMPREPLY=( $(compgen -W "$(rz_asm -s?)" -- $cur )) return 0 ;; esac @@ -100,16 +100,16 @@ _rasm2 () { return 0 } -complete -F _rasm2 -o filenames rasm2 +complete -F _rz_asm -o filenames rz_asm -_rabin2 () { +_rz_bin () { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prv=${COMP_WORDS[COMP_CWORD-1]} case "$prv" in -a) - COMPREPLY=( $(compgen -W "$(rasm2 -qL)" -- $cur)) + COMPREPLY=( $(compgen -W "$(rz_asm -qL)" -- $cur)) return 0 ;; -b) @@ -142,9 +142,9 @@ _rabin2 () { return 0 } -complete -F _rabin2 -o filenames rabin2 +complete -F _rz_bin -o filenames rz_bin -_rafind2 () { +_rz_find () { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} @@ -160,16 +160,16 @@ _rafind2 () { return 0 } -complete -F _rafind2 -o filenames rafind2 +complete -F _rz_find -o filenames rz_find -_radiff2() { +_rz_diff() { local cur COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prv=${COMP_WORDS[COMP_CWORD-1]} case "$prv" in -a) - COMPREPLY=( $(compgen -W "$(rasm2 -qL)" -- $cur)) + COMPREPLY=( $(compgen -W "$(rz_asm -qL)" -- $cur)) return 0 ;; -b) @@ -189,4 +189,4 @@ _radiff2() { return 0 } -complete -F _radiff2 -o filenames radiff2 +complete -F _rz_diff -o filenames rz_diff diff --git a/doc/calling-conventions.md b/doc/calling-conventions.md index 140b5a4311..b7eaafdb22 100644 --- a/doc/calling-conventions.md +++ b/doc/calling-conventions.md @@ -32,8 +32,8 @@ File Path In order to integrate the calling convention profile you created with the r2 source, few set of conventions should be followed: -- Store the unparsed sdb file in `path-to-radare2-source/libr/anal/d`. +- Store the unparsed sdb file in `path-to-rizin-source/librz/anal/d`. - If you want the sdb to be loaded for specific architecture the file name should follow this convention `cc-arch-bits`, for example to create profile that loads automatically for x86 arch with 16 bits call the file `cc-x86-16` -- In the file `path-to-radare2-source/libr/anal/d/makefile` add entry `F+= cc-arch-bits` with desired arch and bits and you should be ready to go. +- In the file `path-to-rizin-source/librz/anal/d/makefile` add entry `F+= cc-arch-bits` with desired arch and bits and you should be ready to go. diff --git a/doc/capstone.md b/doc/capstone.md index 3d01a29d37..878749c77c 100644 --- a/doc/capstone.md +++ b/doc/capstone.md @@ -1,7 +1,7 @@ Capstone ======== -Capstone Engine is the disassembler engine used by radare2 by default for +Capstone Engine is the disassembler engine used by rizin by default for some architectures. R2 supports capstone 3, 4 and 5. diff --git a/doc/crosscompile b/doc/crosscompile index d1419ce03a..fe3e815470 100644 --- a/doc/crosscompile +++ b/doc/crosscompile @@ -34,5 +34,5 @@ $ dockcross make Here is some more context and references: -https://github.com/radareorg/radare2/pull/5060 +https://github.com/rizinorg/rizin/pull/5060 http://blogs.nopcode.org/brainstorm/2016/07/26/cross-compiling-with-docker diff --git a/doc/debug-internals.md b/doc/debug-internals.md index 131471ae22..9b0e444778 100644 --- a/doc/debug-internals.md +++ b/doc/debug-internals.md @@ -8,20 +8,20 @@ The bulk of the debugger functionality within radare core is split between the the tree follows. -## libr/include/r_debug.h +## librz/include/r_debug.h This is the main header file for the debugger. It defines all the relevant structures and top-level functions, APIs, etc. The debugger plug-in API is also defined in here. -## libr/io/p/io_debug.c +## librz/io/p/io_debug.c In order to interface with radare IO, a plug-in is provided. This handles, for example, spawning processes under a debugger. -## libr/reg +## librz/reg The "reg" module provides functionality for reading and writing registers as well as setting up profiles. (??profiles??) @@ -29,18 +29,18 @@ well as setting up profiles. (??profiles??) The functionality lives in the following files: (?? why so many files? can this be simplified??) - libr/reg/arena.c // ?? used by anal and debugger - libr/reg/cond.c // condition registers - libr/reg/double.c // support for double-precision floating point numbers - libr/reg/profile.c // ?? used by anal and debugger - libr/reg/reg.c // top-level register specific code (all of r2) - libr/reg/value.c // dealing with register values - libr/reg/t/p.c // test code for printing general-purpose registers - libr/reg/t/regdiff.c // ?? test code for? - libr/reg/t/test.c // test code for register handling + librz/reg/arena.c // ?? used by anal and debugger + librz/reg/cond.c // condition registers + librz/reg/double.c // support for double-precision floating point numbers + librz/reg/profile.c // ?? used by anal and debugger + librz/reg/reg.c // top-level register specific code (all of r2) + librz/reg/value.c // dealing with register values + librz/reg/t/p.c // test code for printing general-purpose registers + librz/reg/t/regdiff.c // ?? test code for? + librz/reg/t/test.c // test code for register handling -## libr/bp +## librz/bp The "bp" subsystem of radare implements all the necessary details for dealing with breakpoints on any given architecture. It handles managing the list of @@ -49,46 +49,46 @@ breakpoints and more. Radare supports a multitude of different types of breakpoints. (`??` is there a list? sw, hw, and trace? anything else??) - libr/bp/bp.c // main breakpoint management code - libr/bp/io.c // setting and resetting(??) breakpoints - libr/bp/parser.h // header for breakpoint parser (??) - libr/bp/parser.c // code for breakpoint parser (??) - libr/bp/plugin.c // breakpoint plugin management - libr/bp/traptrace.c // traptrace (??) - libr/bp/watch.c // watch points (mostly not implemented) + librz/bp/bp.c // main breakpoint management code + librz/bp/io.c // setting and resetting(??) breakpoints + librz/bp/parser.h // header for breakpoint parser (??) + librz/bp/parser.c // code for breakpoint parser (??) + librz/bp/plugin.c // breakpoint plugin management + librz/bp/traptrace.c // traptrace (??) + librz/bp/watch.c // watch points (mostly not implemented) For architecture specific-handling, "bp" delegates various functionality to plugins. The interface for these plugins is much simpler than other plugins used in the radare debugger -- they only define which byte sequences represent valid breakpoints for a given architecture. - libr/bp/p/bp_arm.c // ARM64, ARM, Thumb, Thumb-2 (big/little endians) - libr/bp/p/bp_bf.c // Brainfuck! - libr/bp/p/bp_mips.c // MIPS, big/little endian - libr/bp/p/bp_ppc.c // PowerPC, big/little endian - libr/bp/p/bp_sh.c // SuperH - libr/bp/p/bp_x86.c // int3... + librz/bp/p/bp_arm.c // ARM64, ARM, Thumb, Thumb-2 (big/little endians) + librz/bp/p/bp_bf.c // Brainfuck! + librz/bp/p/bp_mips.c // MIPS, big/little endian + librz/bp/p/bp_ppc.c // PowerPC, big/little endian + librz/bp/p/bp_sh.c // SuperH + librz/bp/p/bp_x86.c // int3... -## libr/debug/debug.c +## librz/debug/debug.c The main top-level debugger functionality lives here. It aims to abstract away the common code flow and integration into radare while delegating more nuanced system interactions to plug-ins. - libr/debug/arg.c // used by the anal engine (??) - libr/debug/desc.c // code for handling file descriptors inside an inferior - libr/debug/esil.c // ESIL related debugging code (??) - libr/debug/map.c // top-level API for dealing with memory maps - libr/debug/pid.c // top-level API for dealing with processes - libr/debug/plugin.c // top-level debugger plugin API handling - libr/debug/reg.c // top-level code for register r/w and display - libr/debug/signal.c // top-level functions for signals - libr/debug/snap.c // code for saving, restoring, showing memory snapshots - libr/debug/trace.c // top-level tracing API (counting insn hits, etc) - libr/debug/t/main.c // test code for the debugger API + librz/debug/arg.c // used by the anal engine (??) + librz/debug/desc.c // code for handling file descriptors inside an inferior + librz/debug/esil.c // ESIL related debugging code (??) + librz/debug/map.c // top-level API for dealing with memory maps + librz/debug/pid.c // top-level API for dealing with processes + librz/debug/plugin.c // top-level debugger plugin API handling + librz/debug/reg.c // top-level code for register r/w and display + librz/debug/signal.c // top-level functions for signals + librz/debug/snap.c // code for saving, restoring, showing memory snapshots + librz/debug/trace.c // top-level tracing API (counting insn hits, etc) + librz/debug/t/main.c // test code for the debugger API -## libr/core/cmd_debug.c +## librz/core/cmd_debug.c Most of the time a debugger is used by a human to try to understand subtle problems with software and/or hardware. That task would be very difficult @@ -101,34 +101,34 @@ user manual or try "d?" to get a crash course. As mentioned before, the platform specific debugger functionality is delegated to back-end plugins that implement the necessary interactions, protocols, or -otherwise to get the job done. These plug-ins implement the radare2 debugger +otherwise to get the job done. These plug-ins implement the rizin debugger plug-in API defined in r_debug.h. -### libr/debug/p/debug_bf.c +### librz/debug/p/debug_bf.c A debugger plug-in capable of debugging brainfuck code! - libr/debug/p/bfvm.c // Brainfuck VM implementation - libr/debug/p/bfvm.h + librz/debug/p/bfvm.c // Brainfuck VM implementation + librz/debug/p/bfvm.h -### libr/debug/p/debug_bochs.c +### librz/debug/p/debug_bochs.c A debugger plug-in that utilizes bochs emulator to control execution. -### libr/debug/p/debug_esil.c +### librz/debug/p/debug_esil.c This debugger plug-in enables debugging and tracing radare own intermediate language, Evaluable Strings Intermediate Language (ESIL). -### libr/debug/p/debug_gdb.c +### librz/debug/p/debug_gdb.c A radare debugger plug-in that uses a remote GDB server/stub as its backend. The protocol parsing itself is located at shlr/gdb. And corresponding IO plugin is -located in libr/io/p/io_gdb.c +located in librz/io/p/io_gdb.c -### libr/debug/p/debug_native.c +### librz/debug/p/debug_native.c The "native" debugger plug-in is a bit of a doozy. It implements functionality for debugging on the most common platforms available: Windows, OSX, Linux, and @@ -138,80 +138,80 @@ shared are implemented by platform-specific functions that are provided in the following files: // architecture-specific debugger code - libr/debug/p/native/arm.c // unused? + librz/debug/p/native/arm.c // unused? // code for handling backtracing - libr/debug/p/native/bt.c - libr/debug/p/native/bt/fuzzy-all.c - libr/debug/p/native/bt/generic-x64.c - libr/debug/p/native/bt/generic-x86.c + librz/debug/p/native/bt.c + librz/debug/p/native/bt/fuzzy-all.c + librz/debug/p/native/bt/generic-x64.c + librz/debug/p/native/bt/generic-x86.c // architecture-specific register handling - libr/debug/p/native/drx.c // x86-specific debug registers - libr/debug/p/native/reg.c // cute include of the files below - libr/debug/p/native/reg/kfbsd-x64.h - libr/debug/p/native/reg/kfbsd-x86.h - libr/debug/p/native/reg/netbsd-x64.h - libr/debug/p/native/reg/netbsd-x86.h - libr/debug/p/native/reg/windows-x64.h - libr/debug/p/native/reg/windows-x86.h + librz/debug/p/native/drx.c // x86-specific debug registers + librz/debug/p/native/reg.c // cute include of the files below + librz/debug/p/native/reg/kfbsd-x64.h + librz/debug/p/native/reg/kfbsd-x86.h + librz/debug/p/native/reg/netbsd-x64.h + librz/debug/p/native/reg/netbsd-x86.h + librz/debug/p/native/reg/windows-x64.h + librz/debug/p/native/reg/windows-x86.h // platform-specific debugger code on Linux - libr/debug/p/native/linux/linux_debug.c // main linux-specific debugging code - libr/debug/p/native/linux/linux_debug.h // including cute penguin ascii art + librz/debug/p/native/linux/linux_debug.c // main linux-specific debugging code + librz/debug/p/native/linux/linux_debug.h // including cute penguin ascii art // architecture-specific register handling on Linux (?? what is this format??) - libr/debug/p/native/linux/reg/linux-arm.h - libr/debug/p/native/linux/reg/linux-arm64.h - libr/debug/p/native/linux/reg/linux-mips.h - libr/debug/p/native/linux/reg/linux-ppc.h - libr/debug/p/native/linux/reg/linux-x64.h - libr/debug/p/native/linux/reg/linux-x64-32.h - libr/debug/p/native/linux/reg/linux-x86.h + librz/debug/p/native/linux/reg/linux-arm.h + librz/debug/p/native/linux/reg/linux-arm64.h + librz/debug/p/native/linux/reg/linux-mips.h + librz/debug/p/native/linux/reg/linux-ppc.h + librz/debug/p/native/linux/reg/linux-x64.h + librz/debug/p/native/linux/reg/linux-x64-32.h + librz/debug/p/native/linux/reg/linux-x86.h // platform-specific debugger code on Windows - libr/debug/p/native/w32.c // !! not used by anything else - libr/debug/p/native/maps/windows.c // platform-specific memory map handling - libr/debug/p/native/windows/windows_debug.c // main code for win32 debugger plugin - libr/debug/p/native/windows/windows_debug.h // including cute windows ascii art + librz/debug/p/native/w32.c // !! not used by anything else + librz/debug/p/native/maps/windows.c // platform-specific memory map handling + librz/debug/p/native/windows/windows_debug.c // main code for win32 debugger plugin + librz/debug/p/native/windows/windows_debug.h // including cute windows ascii art // platform-specific debugger code on XNU (OSX/iOS/etc) - libr/debug/p/native/darwin.c // !! not used by anything else - libr/debug/p/native/maps/darwin.c // platform-specific memory map handling - libr/debug/p/native/xnu/xnu_debug.c // main XNU-specific debugging code - libr/debug/p/native/xnu/xnu_debug.h // including cute apple ascii art - libr/debug/p/native/xnu/trap_arm.c // ARM family hardware bps (??) - libr/debug/p/native/xnu/trap_x86.c // x86 family hardware bps (??) - libr/debug/p/native/xnu/xnu_excthreads.c // additional XNU thread handling - libr/debug/p/native/xnu/xnu_threads.c // XNU thread and register handling - libr/debug/p/native/xnu/xnu_threads.h + librz/debug/p/native/darwin.c // !! not used by anything else + librz/debug/p/native/maps/darwin.c // platform-specific memory map handling + librz/debug/p/native/xnu/xnu_debug.c // main XNU-specific debugging code + librz/debug/p/native/xnu/xnu_debug.h // including cute apple ascii art + librz/debug/p/native/xnu/trap_arm.c // ARM family hardware bps (??) + librz/debug/p/native/xnu/trap_x86.c // x86 family hardware bps (??) + librz/debug/p/native/xnu/xnu_excthreads.c // additional XNU thread handling + librz/debug/p/native/xnu/xnu_threads.c // XNU thread and register handling + librz/debug/p/native/xnu/xnu_threads.h // architecture-specific register handling on XNU (?? what is this format??) - libr/debug/p/native/xnu/reg/darwin-x86.h - libr/debug/p/native/xnu/reg/darwin-arm.h - libr/debug/p/native/xnu/reg/darwin-ppc.h - libr/debug/p/native/xnu/reg/darwin-arm64.h - libr/debug/p/native/xnu/reg/darwin-x64.h + librz/debug/p/native/xnu/reg/darwin-x86.h + librz/debug/p/native/xnu/reg/darwin-arm.h + librz/debug/p/native/xnu/reg/darwin-ppc.h + librz/debug/p/native/xnu/reg/darwin-arm64.h + librz/debug/p/native/xnu/reg/darwin-x64.h // platform-specific debugger code on BSD - libr/debug/p/native/bsd/bsd_debug.c // main BSD debugging code - libr/debug/p/native/bsd/bsd_debug.h + librz/debug/p/native/bsd/bsd_debug.c // main BSD debugging code + librz/debug/p/native/bsd/bsd_debug.h -### libr/debug/p/debug_qnx.c +### librz/debug/p/debug_qnx.c A debugger plug-in that enables debugging code natively on QNX systems. Corresponding -IO plugin is located in libr/io/p/io_qnx.c +IO plugin is located in librz/io/p/io_qnx.c See doc/qnx -### libr/debug/p/debug_rap.c +### librz/debug/p/debug_rap.c See doc/rap -### libr/debug/p/debug_winkd.c +### librz/debug/p/debug_winkd.c A debugger plugin that enables debugging code remotely via WinDbg protocol. WinDbg protocol -parser is located in shlr/winkd. Corresponding IO plugin located in libr/io/p/io_winkd.c +parser is located in shlr/winkd. Corresponding IO plugin located in librz/io/p/io_winkd.c See doc/winkd ## Conclusion diff --git a/doc/emscripten.md b/doc/emscripten.md index 8e07c87ea3..398bd5464b 100644 --- a/doc/emscripten.md +++ b/doc/emscripten.md @@ -21,15 +21,15 @@ export CC="emcc --ignore-dynamic-linking" ./configure --prefix=/usr --disable-shared --enable-static --disable-debugger --with-compiler=emscripten --without-pic --with-nonpic emmake make -j4 -cd binr/radare2 - emcc ../../libr/*/*.o radare2.c -I ../../libr/include/ -DR2_BIRTH=\"pop\" -DR2_GITTIP=\"123\" ../../libr/db/sdb/src/*.o +cd binrz/rizin + emcc ../../librz/*/*.o rizin.c -I ../../librz/include/ -DR2_BIRTH=\"pop\" -DR2_GITTIP=\"123\" ../../librz/db/sdb/src/*.o -binr/rax2/rax2.js: +binrz/rz_ax/rz_ax.js: -emcc -O2 rax2.o ../../libr/util/libr_util.a -o rax2.js +emcc -O2 rz_ax.o ../../librz/util/librz_util.a -o rz_ax.js -binr/rasm2/rasm2.js: +binrz/rz_asm/rz_asm.js: -emcc -O2 -L.. -o rasm2.js ../../shlr/sdb/src/libsdb.a ../../libr/fs/p/grub/libgrubfs.a -lm $A/util/libr_util.a $A/asm/libr_asm.a rasm2.o ../../libr/util/libr_util.a ../../libr/parse/libr_parse.a ../../libr/db/libr_db.a ../../libr/syscall/libr_syscall.a ../../libr/asm/libr_asm.a ../../libr/lib/libr_lib.a ../../libr/db/libr_db.a ../../shlr/sdb/src/libsdb.a ../../libr/util/libr_util.a +emcc -O2 -L.. -o rz_asm.js ../../shlr/sdb/src/libsdb.a ../../librz/fs/p/grub/libgrubfs.a -lm $A/util/librz_util.a $A/asm/librz_asm.a rz_asm.o ../../librz/util/librz_util.a ../../librz/parse/librz_parse.a ../../librz/db/libr_db.a ../../librz/syscall/librz_syscall.a ../../librz/asm/librz_asm.a ../../librz/lib/libr_lib.a ../../librz/db/libr_db.a ../../shlr/sdb/src/libsdb.a ../../librz/util/librz_util.a --> diff --git a/doc/esil.md b/doc/esil.md index e210f18eea..d5bbaf6e51 100644 --- a/doc/esil.md +++ b/doc/esil.md @@ -238,7 +238,7 @@ Radare anal ESIL code example ============================== As an example implementation of ESIL analysis for the AVR family of -microcontrollers there is a `avr_op` function in `/libr/anal/p/anal_avr.c` +microcontrollers there is a `avr_op` function in `/librz/anal/p/anal_avr.c` which contains information on how the instructions are expressed in ESIL and other opcode information such as cycle counts per instruction: diff --git a/doc/fortunes.fun b/doc/fortunes.fun index 5a43649f9b..90624912c5 100644 --- a/doc/fortunes.fun +++ b/doc/fortunes.fun @@ -1,25 +1,25 @@ No disassemble!!! -Deltify your life with radare2 -In soviet russia, radare2 debugs you! +Deltify your life with rizin +In soviet russia, rizin debugs you! What do you want to debug today? I love the smell of bugs in the morning. I'm in your source securing your bits. -radare2 contributes to the One Byte Per Child foundation. +rizin contributes to the One Byte Per Child foundation. 3nl4r9e y0\/r r4d4r3 I did it for the pwnz. If you send the program you are debugging to 15 friends in 143 minutes and then step three times on the same opcode you will get the name of the person who loves you. To remove this message, put `dbxenv suppress_startup_message 7.5' in your .dbxrc Heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it. -radare2 is for lulzhats +rizin is for lulzhats Microloft Visual Radare.NET 2008. Now OOXML Powered! A C program is like a fast dance on a newly waxed dance floor by people carrying razors - Waldi Ravens -radare2 is like windows 7 but even better. +rizin is like windows 7 but even better. We are surrounded by the enemy. - Excellent, we can attack in any direction! -radare2-built farm beats the facebook one. -Thank you for using radare2. Have a nice night! +rizin-built farm beats the facebook one. +Thank you for using rizin. Have a nice night! Your r2 was built 20h ago. TOO OLD! -Use radare2! Lemons included! -rax2 -s 20e296b20ae296b220e296b20a +Use rizin! Lemons included! +rz_ax -s 20e296b20ae296b220e296b20a Connection lost with the license server, your r2 session will terminate in 30 minutes. This is amazing ... I love gradients. @@ -30,15 +30,15 @@ Default scripting languages are NodeJS and Python. -bash: r2: command not found Press any key to continue ... Ilo ni li pona li pali e lipu. mi wile e ni: sina kama jo e musi -radare2 for FideOS, now with extra potato +rizin for FideOS, now with extra potato Your project name should contain an uppercase letter, 8 vowels, some numbers, and the first 5 characters of your private bitcoin key. This computer has gone to sleep. -Have you ever ordered a pizza using radare2? +Have you ever ordered a pizza using rizin? I thought we were friends. :_ Welcome back, lazy human! Yo dawg! ---8<--------------------8<------------------8<-----------------8<------ -I accidentally the kernel with radare2. +I accidentally the kernel with rizin. I endians swap. This page intentionally left blank. Here be dragons. @@ -60,8 +60,8 @@ It's not you, it's me. This software comes with no brain included. Please use your own. rm: /: Permission denied. That's embarrassing. -In soviet Afghanistan, you debug radare2! -Wow, my cat knows radare2 hotkeys better than me! +In soviet Afghanistan, you debug rizin! +Wow, my cat knows rizin hotkeys better than me! Documentation is for weak people. PEBCAK ERROR: Documentation not found. License server overloaded (ETOOMUCHCASH) @@ -93,7 +93,7 @@ May the segfault be with you. I script in C, because I can. EXPLICIT CONTENT Bindings are mostly powered by tears. -In Soviet Russia, radare2 has documentation. +In Soviet Russia, rizin has documentation. Initial frame selected; you cannot go up. Unk, unk, unk, unk Experts agree, security holes suck, and we fixed some of them! @@ -149,7 +149,7 @@ Mess with the best, Die like the rest Sarah Connor? Log On. Hack In. Go Anywhere. Get Everything. phrack, better than java in the browser -- jvoisin -Did you know that radare2 can decompile to assembly? +Did you know that rizin can decompile to assembly? Are you still there? Follow the white rabbit Do not try to sploit that binary - that's impossible. Instead, only try to realize the truth: there is no binary. @@ -160,11 +160,11 @@ What about taking a break? Here, have this nice 0xCC. r2 is meant to be read by machines. Prove you are a robot to continue ... This is fine. -Using radare2 to generate intelligence ... +Using rizin to generate intelligence ... Taking the file and moving it somewhere else -It's the year of desktop on radare2 +It's the year of desktop on rizin 💺 -It's the year of radare2 on the desktop +It's the year of rizin on the desktop SSAbotage from ISIL "a collection of garbage" -- an r2 pro user A git pull a day keeps the segfault away @@ -172,8 +172,8 @@ Are you a wizard? Learn pancake as if you were radare! r2 is a great OS, but a terrible hex editor THE CAKE IS A PIE -radare2 0.9.7 is so old, my grandfarther was using it with his enigma in WWII -Have you seen the latest radare2 TV spot? +rizin 0.9.7 is so old, my grandfarther was using it with his enigma in WWII +Have you seen the latest rizin TV spot? scp ~/.idapro/ida.key radare.org:/var/www/radare.org/pub/losers/ Too bad there is no gif support in r2. Yet. -- @r2gif Almost 5am, maybe you should go to bed. @@ -183,11 +183,11 @@ Mind that the 'g' in radare is silent Hang in there, Baby! Run a command with unspecified long sequence of 'a', pancake will be summoned and do the analysis for you. In r2land usability is treated as a bug -radare2 is WYSIWYF - what you see is what you fix +rizin is WYSIWYF - what you see is what you fix Your endian swaps *(ut64*)buffer ought to be illegal How about Global Thermonuclear War? -There is no F5 key in radare2 yet +There is no F5 key in rizin yet Did you know that r2 is 10 years old? Beer in mind. r2 -- leading options since 2006 @@ -199,11 +199,11 @@ Now i'm like an evil engineer. MUAHAHAH We only have bugs, features are an unintended side-effect There are 5 minutes from WTF to FIX in r2land Quantum dissasemble: it's there as long as you don't observe it -Ceci n'est pas une r2pipe +Ceci n'est pas une rzpipe Buy a mac (gdb) ^D ((fn [f s n] (str (f f s n) "dare2")) (fn [f s n] (pr s) (if (> n 0) (f f (str s "ra") (dec n)) s)) "" (/ 1.0 0)) -There's no way you could crash radare2. No. Way. +There's no way you could crash rizin. No. Way. When in doubt, try 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; pd;' .-. .- -.. .- .-. . ..--- Disassemble?! No Disassemble Johnny No. 5!!! @@ -228,7 +228,7 @@ Buy a Mac You have been designated for disassembly Helping siol merge? No way, that would be like.. way too much not lazy. - vifino What is the most complex r2 command? q - then you have to deal with real life /o\ -If you're having fun using radare2, odds are that you're doing something wrong. +If you're having fun using rizin, odds are that you're doing something wrong. Don't trust what can't be compiled Coffee time! Can you you challenge a perfect immortal machine? @@ -266,17 +266,17 @@ This shell has been seized by the Internet's Police. OpenBSD might pledge r2 but r2 unveils OpenBSD. Error: There's a missing space before the opening parenthesis '(' WARNING: r_list_length: assertion 'list' failed (line 55) -This accessory is not supported by this version of radare2. -When can we have an official anime mascot for radare2? +This accessory is not supported by this version of rizin. +When can we have an official anime mascot for rizin? Iaito became Cutter the same way Iai-giri became Cut. -Sorry, radare2 has experienced an internal error. +Sorry, rizin has experienced an internal error. Segmentation fault (core dumped) -Use rabin2 to discover the real TRUTH +Use rz_bin to discover the real TRUTH ==1337== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) **** COMMODORE 64 RADARE V2 **** 64K RAM SYSTEM 38911 DISASM BYTES FREE READY. Most likely your core dump fell into a blackhole, can't see it. Long time no C -radare2 is power, France is pancake. +rizin is power, France is pancake. Come to C me! Unable to locate package gdb You C it, you fix it! @@ -286,7 +286,7 @@ You will soon have an out of memory experience. This binary no good. Try another. BSOD! Mind the trap. -For a full documentation see `r2 -qc iz /lib/libr_core.so` +For a full documentation see `r2 -qc iz /lib/librz_core.so` 99 bugs, take one down pass it around. 100 bugs... I like my binary stripped. Now 8-bit clean with better ASCII! diff --git a/doc/fortunes.nsfw b/doc/fortunes.nsfw index 8c5da01b44..540b0647f4 100644 --- a/doc/fortunes.nsfw +++ b/doc/fortunes.nsfw @@ -1,9 +1,9 @@ RADARE CUMS WITH ABSOLUTELY NO WARRANTY Please remove pregnant women, pregnant children, and pregnant pets from the monitor. -Everytime you run radare2, a random file is removed +Everytime you run rizin, a random file is removed I like to suck nibbles and make hex. Enjoy the 'two girls one backup' viral video. -Enlarge your radare2. +Enlarge your rizin. Better than an eel in the ass. Are you fucking coding me? I swear i didn't knew she had only 8bits! @@ -23,7 +23,7 @@ Fuck you, fuck you in the mouth, with a chair! Git histories, allowing us to recover profanity because fuck you The problem with C++ is that all of your friends can see your private parts Best retards -"Our exploits production increased for 24% annually after our switch to radare2" -- An unnamed agency +"Our exploits production increased for 24% annually after our switch to rizin" -- An unnamed agency Nice! Well, less shitty. less stupid than putting CO2 in your ass. Puritans, ruining everything since the 16th century. @@ -39,7 +39,7 @@ I live for this shit You gotta be fucking kidding me Stop using anal as a variable! Wherever I look I see anal this and anal that! -radare2 is a hex toy +rizin is a hex toy Showing how the sausage is made... in vivid, gory detail fuck u Do you want to see my internals? [Y/n] diff --git a/doc/fortunes.tips b/doc/fortunes.tips index 15124d7f6b..3b2a91d145 100644 --- a/doc/fortunes.tips +++ b/doc/fortunes.tips @@ -1,8 +1,8 @@ Tweak the disassembly output with `e asm.` -Add custom Have you setup your ~/.radare2rc today? +Add custom Have you setup your ~/.rizinrc today? In visual mode press 'c' to toggle the cursor mode. Use tab to navigate You can mark an offset in visual mode with the cursor and the ',' key. Later press '.' to go back -You can debug a program from the graph view ('ag') using standard radare2 commands +You can debug a program from the graph view ('ag') using standard rizin commands Use the '[' and ']' keys in visual mode to adjust the screen width Select your architecture with: 'e asm.arch=' or r2 -a from the shell Move between your search hits in visual mode using the 'f' and 'F' keys @@ -13,7 +13,7 @@ Check your IO plugins with 'r2 -L' Change the size of the file with the 'r' (resize) command Calculate checksums for the current block with the commands starting with '#' (#md5, #crc32, #all, ..) Use +,-,*,/ to change the size of the block -Change the block size with 'b '. In visual mode you can also enter radare2 command pressing the ':' key (like vi does) +Change the block size with 'b '. In visual mode you can also enter rizin command pressing the ':' key (like vi does) If you want to open the file in read-write mode, invoke r2 with '-w' Print the contents of the current block with the 'p' command Command layout is: @. For example: 3x20@0x33 will show 3 hexdumps of 20 bytes at 0x33 @@ -24,14 +24,14 @@ Move around the bytes with h,j,k,l! Arrow keys are neither portable nor efficien Seek at relative offsets with 's +' or 's -' Invert the block bytes using the 'I' key in visual mode Switch between print modes using the 'p' and 'P' keys in visual mode -Add comments using the ';' key in visual mode or the 'CC' command from the radare2 shell +Add comments using the ';' key in visual mode or the 'CC' command from the rizin shell Assemble opcodes with the 'a' and 'A' keys in visual mode, which are bindings to the 'wa' and 'wA' commands Find expanded AES keys in memory with '/ca' Find wide-char strings with the '/w ' command Enable ascii-art jump lines in disassembly by setting 'e asm.lines=true'. asm.lines.out and asm.linestyle may interest you as well Control the signal handlers of the child process with the 'dk' command -Get a free shell with 'ragg2 -i exec -x' -Interpret radare2 scripts with '. '. Similar to the bash source alias command. +Get a free shell with 'rz_gg -i exec -x' +Interpret rizin scripts with '. '. Similar to the bash source alias command. Most of commands accept '?' as a suffix. Use it to understand how they work :) Find hexpairs with '/x a0 cc 33' Step through your seek history with the commands 'u' (undo) and 'U' (redo) @@ -42,8 +42,8 @@ Add colors to your screen with 'e scr.color=X' where 1 is 16 colors, 2 is 256 co Move the comments to the right changing their margin with asm.cmt.margin Execute a command on the visual prompt with cmd.vprompt Reduce the delta where flag resolving by address is used with cfg.delta -Disable these messages with 'e cfg.fortunes = false' in your ~/.radare2rc -Change your fortune types with 'e cfg.fortunes.type = fun,tips,nsfw' in your ~/.radare2rc +Disable these messages with 'e cfg.fortunes = false' in your ~/.rizinrc +Change your fortune types with 'e cfg.fortunes.type = fun,tips,nsfw' in your ~/.rizinrc Show offsets in graphs with 'e graph.offset = true' Execute a command every time a breakpoint is hit with 'e cmd.bp = !my-program' Disassemble in intel syntax with 'e asm.syntax = intel'. @@ -51,17 +51,17 @@ Change the UID of the debugged process with child.uid (requires root) Enhance your graphs by increasing the size of the block and graph.depth eval variable. Control the height of the terminal on serial consoles with e scr.height Emulate the base address of a file with e file.baddr. -Bindiff two files with '$ radiff2 /bin/true /bin/false' +Bindiff two files with '$ rz_diff /bin/true /bin/false' Execute commands on a temporary offset by appending '@ offset' to your command. Temporally drop the verbosity prefixing the commands with ':' Change the graph block definition with graph.callblocks, graph.jmpblocks, graph.flagblocks Use scr.accel to browse the file faster! Use the 'id' command to see the source line related to the current seek -Analyze socket connections with the socket plugin: 'radare2 socket://www.foo.com:80'. Use 'w' to send data +Analyze socket connections with the socket plugin: 'rizin socket://www.foo.com:80'. Use 'w' to send data Setup dbg.fpregs to true to visualize the fpu registers in the debugger view. To debug a program, you can call r2 with 'dbg://' or '-d ' Use 'e' and 't' in Visual mode to edit configuration and track flags. -Use 'rabin2 -ris' to get the import/export symbols of any binary. +Use 'rz_bin -ris' to get the import/export symbols of any binary. Remember to maintain your ~/.radare_history Enable the PAGER with 'e scr.pager=less -R' Use 'e asm.offset=true' to show offsets in 16bit segment addressing mode. @@ -69,14 +69,14 @@ The '?' command can be used to evaluate math expressions. Like this: '? (0x34+22 Set 'e bin.dbginfo=true' to load debug information at startup. Rename a function using the 'afr @ ' command. You can redefine descriptive commands in the hud file and using the 'V_' command. -Pass '-j' to rabin2 to get the information of the binary in JSON format. -Use rarun2 to launch your programs with a predefined environment. +Pass '-j' to rz_bin to get the information of the binary in JSON format. +Use rz_run to launch your programs with a predefined environment. You are probably using an old version of r2, go checkout the git! Run your own r2 scripts in awk using the r2awk program. Use '-e bin.strings=false' to disable automatic string search when loading the binary. The unix-like reverse engineering framework. This code was intentionally left blank, try 'e asm.arch = ws' -Thanks for using radare2! +Thanks for using rizin! give | and > a try piping and redirection Run .dmm* to load the flags of the symbols of all modules loaded in the debugger Use V! to enter into the visual panels mode (dwm style) diff --git a/doc/freebsd.md b/doc/freebsd.md index 3ccc2ef83a..9f8b6aa01a 100644 --- a/doc/freebsd.md +++ b/doc/freebsd.md @@ -13,8 +13,8 @@ Radare2 Dependencies: sudo pkg install git gcc gmake patch pkgconf - git clone https://github.com/radareorg/radare2 - cd radare2 + git clone https://github.com/rizinorg/rizin + cd rizin sys/install.sh /usr/local Python Swig Bindings Dependencies: @@ -30,8 +30,8 @@ Python Swig Bindings Dependencies: Building Python Swig Bindings: ------------------------------ - git clone https://github.com/radareorg/radare2-bindings - cd radare2-bindings + git clone https://github.com/rizinorg/rizin-bindings + cd rizin-bindings export CC=cc export CXX=c++ export SWIG=swig3.0 diff --git a/doc/gprobe.md b/doc/gprobe.md index aed92b2410..ba7b49b81e 100644 --- a/doc/gprobe.md +++ b/doc/gprobe.md @@ -5,7 +5,7 @@ Genesis/STMicro/MegaChips that are mostly used in video chipsets. These chips have an integrated Turbo186 core. With GProbe you can read and write RAM, reset the CPU, execute code in RAM, ... -There is a proprietary Windows tool to do this, but radare2 offers much more +There is a proprietary Windows tool to do this, but rizin offers much more functionality. Gprobe got some public attention with the @@ -30,7 +30,7 @@ TODOs What is tested? --------------- - building with sys/user.sh and sys/mingw32.sh on linux -- running radare2 on Linux and Windows +- running rizin on Linux and Windows - communication via FTDI USB serial adaptor - communication via DDC2Bi3 - controlling a MegaChips RD1-4320 DisplayPort 1.2a splitter reference board @@ -38,12 +38,12 @@ What is tested? How to use for dummies? ----------------------- -radare2 -n -w gprobe:///dev/ttyUSB0 +rizin -n -w gprobe:///dev/ttyUSB0 - "/dev/ttyUSB0" is the serial connection, use something like "COM3" on Windows - "-n" is important to avoid an initial 32k read to identify the binary type - "-w" if you want to allow writing to RAM -radare2 -n -w gprobe://i2c-4 +rizin -n -w gprobe://i2c-4 - i2c-4 is the i2c bus where the GProbe device is connected - find the appropriate bus with "ddcutil detect" - make sure the i2c-dev kernel module is loaded diff --git a/doc/haiku.md b/doc/haiku.md index 8c55d9b19a..923d5c9894 100644 --- a/doc/haiku.md +++ b/doc/haiku.md @@ -3,17 +3,17 @@ r2 for Haiku To compile for Haiku run configure in this way: - HOST_CC=gcc-x86 CC=gcc-x86 ./configure --with-ostype=haiku --prefix=/boot/home/Apps/radare2 + HOST_CC=gcc-x86 CC=gcc-x86 ./configure --with-ostype=haiku --prefix=/boot/home/Apps/rizin And then.. HOST_CC=gcc-x86 make make install - mv /boot/home/Apps/radare2/bin/* /boot/home/Apps/radare2/ - rmdir /boot/home/Apps/radare2/bin/ + mv /boot/home/Apps/rizin/bin/* /boot/home/Apps/rizin/ + rmdir /boot/home/Apps/rizin/bin/ To install r2-bindings you will need to install r2, valac, valabind and swig -and copy/link libs to radare2/lib +and copy/link libs to rizin/lib TODO diff --git a/doc/ida.md b/doc/ida.md index c9c2305972..0538ecbaf0 100644 --- a/doc/ida.md +++ b/doc/ida.md @@ -1,7 +1,7 @@ IDA ====== -You can find conversion scripts to work between radare2 and IDA files (IDC, IDB...) here: +You can find conversion scripts to work between rizin and IDA files (IDC, IDB...) here: -* https://github.com/radareorg/radare2-extras/tree/master/r2ida +* https://github.com/rizinorg/rizin-extras/tree/master/r2ida diff --git a/doc/images/keepr2.svg b/doc/images/keeprz.svg similarity index 100% rename from doc/images/keepr2.svg rename to doc/images/keeprz.svg diff --git a/doc/images/r2.svg b/doc/images/rz.svg similarity index 100% rename from doc/images/r2.svg rename to doc/images/rz.svg diff --git a/doc/images/r2big.png b/doc/images/rzbig.png similarity index 100% rename from doc/images/r2big.png rename to doc/images/rzbig.png diff --git a/doc/images/r2bigger.png b/doc/images/rzbigger.png similarity index 100% rename from doc/images/r2bigger.png rename to doc/images/rzbigger.png diff --git a/doc/images/r2cloud.svg b/doc/images/rzcloud.svg similarity index 100% rename from doc/images/r2cloud.svg rename to doc/images/rzcloud.svg diff --git a/doc/images/r2cs.svg b/doc/images/rzcs.svg similarity index 99% rename from doc/images/r2cs.svg rename to doc/images/rzcs.svg index c793b245c8..d45df0377f 100644 --- a/doc/images/r2cs.svg +++ b/doc/images/rzcs.svg @@ -3944,7 +3944,7 @@ id="tspan3886" x="324.50549" y="42.798641" - style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:TitilliumText25L;-inkscape-font-specification:TitilliumText25L Semi-Bold">radare2 periodic table + style="font-style:normal;font-variant:normal;font-weight:600;font-stretch:normal;font-family:TitilliumText25L;-inkscape-font-specification:TitilliumText25L Semi-Bold">rizin periodic table +#include -typedef struct r_core_rtr_host_t2 { +typedef struct rz_core_rtr_host_t2 { int proto; int port; char host[512]; char file[1024]; - RSocket *fd; -} RCoreRtrHost2; + RzSocket *fd; +} RzCoreRtrHost2; static const char *help_msg_aa[] = { "Usage:", "aa[0*?]", " # see also 'af' and 'afna'", @@ -18,18 +18,18 @@ static const char *help_msg_aa[] = { }; static int cmpaddr(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; return a->addr - b->addr; } int main(int argc, char **argv) { - r_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); + rz_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); switch (*input) { case '\0': // "aft" seek = core->offset; - r_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); - r_core_anal_type_match (core, fcn); - r_core_seek (core, seek, true); + rz_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); + rz_core_anal_type_match (core, fcn); + rz_core_seek (core, seek, true); break; case '0': { @@ -43,7 +43,7 @@ int main(int argc, char **argv) { case 'b': case '?': default: - r_core_cmd_help (core, help_msg_aft); + rz_core_cmd_help (core, help_msg_aft); break; } return 0; diff --git a/doc/intro.md b/doc/intro.md index 79edb408ab..c224e3f51c 100644 --- a/doc/intro.md +++ b/doc/intro.md @@ -26,7 +26,7 @@ e =: Change property value e? help about a configuration property e? cmd.stack ``` -You will want to set your favourite options in `~/.radare2rc` since every line there will be interpreted at the beginning of each session. Mine for reference: +You will want to set your favourite options in `~/.rizinrc` since every line there will be interpreted at the beginning of each session. Mine for reference: ``` # Show comments at right of disassembly if they fit in screen @@ -51,7 +51,7 @@ Command syntax: `[.][times][cmd][~grep][@[@iter]addr!size][|>pipe]` * `!` Run shell commands: `!cat /etc/passwd` * `!!` Escapes to shell, run command and pass output to radare buffer * Note: The double exclamation mark tells radare to skip the plugin list to find an IO plugin handling this command to launch it directly to the shell. A single one will walk through the io plugin list. -* `` ` `` Radare commands: `` wx `!ragg2 -i exec` `` +* `` ` `` Radare commands: `` wx `!rz_gg -i exec` `` * `~` grep * `~!` grep -v * `~[n]` grep by columns `afl~[0]` @@ -303,7 +303,7 @@ gG: Begin or end of file HUD _ Show HUD backspace: Exits HUD - We can add new commands to HUD in: radare2/shlr/hud/main + We can add new commands to HUD in: rizin/shlr/hud/main ;[-]cmt: Add/remove comment m: Define a bookmark ': Go to previously defined bookmark @@ -445,7 +445,7 @@ dot -Tpng -o /tmp/b.png b.dot Generate graph for file: ``` -radiff2 -g main crackme.bin crackme.bin > /tmp/a +rz_diff -g main crackme.bin crackme.bin > /tmp/a xdot /tmp/a ``` @@ -460,12 +460,12 @@ ptrace://pid (debug backend does not notice, only access to mapped memory) To pass arguments: ``` -r2 -d rarun2 program=pwn1 arg1=$(python exploit.py) +r2 -d rz_run program=pwn1 arg1=$(python exploit.py) ``` To pass stdin: ``` -r2 -d rarun2 program=/bin/ls stdin=$(python exploit.py) +r2 -d rz_run program=/bin/ls stdin=$(python exploit.py) ``` Commands @@ -523,7 +523,7 @@ continue with F9 # Radare2 suite commands All suite commands include a `-r` flag to generate instructions for r2 -## rax2 - Base conversion +## rz_ax - Base conversion ``` -e: Change endian -K: random ASCII art to represent a number/hash. Similar to how SSH represents keys @@ -531,7 +531,7 @@ All suite commands include a `-r` flag to generate instructions for r2 -S: raw -> hexstr ``` -## rahash2 - Entropy, hashes and checksums +## rz_hash - Entropy, hashes and checksums ``` -a: Specify the algorithm -b XXX: Block size @@ -539,7 +539,7 @@ All suite commands include a `-r` flag to generate instructions for r2 -a entropy: Show file entropy or entropy per block (-B -b 512 -a entropy) ``` -## radiff2 - File diffing +## rz_diff - File diffing ``` -s: Calculate text distance from two files. -d: Delta diffing (For files with different sizes. Its not byte per byte) @@ -549,37 +549,37 @@ Examples: ``` Diff original and patched on x86_32, using graphdiff algorithm - radiff2 -a x86 -b32 -C original patched + rz_diff -a x86 -b32 -C original patched Show differences between original and patched on x86_32 - radiff2 -a x86 -b32 original patched : + rz_diff -a x86 -b32 original patched : ``` -## rasm2 - Assembly/Disassembly +## rz_asm - Assembly/Disassembly ``` -L: Supported architectures -a arch instruction: Sets architecture - rasm2 -a x86 'mov eax,30' => b81e000000 + rz_asm -a x86 'mov eax,30' => b81e000000 -b tam: Sets block size -d: Disassembly - rasm2 -d b81e000000 => mov eax, 0x1e + rz_asm -d b81e000000 => mov eax, 0x1e -C: Assembly in C output - rasm2 -C 'mov eax,30' => "\xb8\x1e\x00\x00\x00" + rz_asm -C 'mov eax,30' => "\xb8\x1e\x00\x00\x00" -D: Disassemble showing hexpair and opcode - rasm2 -D b81e0000 => 0x00000000 5 b81e000000 mov eax, 0x1e + rz_asm -D b81e0000 => 0x00000000 5 b81e000000 mov eax, 0x1e -f: Read data from file instead of ARG. -O filename: Write data to file ``` -## rafind2 - Search +## rz_find - Search ``` -Z: Look for Zero terminated strings -s str: Look for specific string ``` -## ragg2 - Shellcode generator, C/opcode compiler +## rz_gg - Shellcode generator, C/opcode compiler ``` -P: Generate De Bruijn patterns - ragg2 -P 300 -r + rz_gg -P 300 -r -a arch: Configure architecture -b bits: Specify architecture bits (32/64) -i shellcode: Specify shellcode to generate @@ -588,10 +588,10 @@ Show differences between original and patched on x86_32 Example: ``` Generate a x86, 32 bits exec shellcode - ragg2 -a x86 -b 32 -i exec + rz_gg -a x86 -b 32 -i exec ``` -## rabin2 - Executable analysis: symbols, imports, strings ... +## rz_bin - Executable analysis: symbols, imports, strings ... ``` -I: Executable information -c: Returns classes. Useful to list Java Classes @@ -600,11 +600,11 @@ Generate a x86, 32 bits exec shellcode -z: Strings ``` -## rarun2 - Launcher to run programs with different environments, args, stdin, permissions, fds +## rz_run - Launcher to run programs with different environments, args, stdin, permissions, fds Examples: ``` -r2 -b 32 -d rarun2 program=pwn1 arg1=$(ragg2 -P 300 -r) : runs pwn1 with a De Bruijn Pattern as first argument, inside radare2's debugger, and force 32 bits -r2 -d rarun2 program=/bin/ls stdin=$(python exploit.py) : runs /bin/ls with the output of exploit.py directed to stdin +r2 -b 32 -d rz_run program=pwn1 arg1=$(rz_gg -P 300 -r) : runs pwn1 with a De Bruijn Pattern as first argument, inside rizin's debugger, and force 32 bits +r2 -d rz_run program=/bin/ls stdin=$(python exploit.py) : runs /bin/ls with the output of exploit.py directed to stdin ``` diff --git a/doc/io-fixing.md b/doc/io-fixing.md index f6f701f97f..29d0ae3bf7 100644 --- a/doc/io-fixing.md +++ b/doc/io-fixing.md @@ -27,15 +27,15 @@ Documentation: There is no need for a huge documentation!!! But code with fundamental importance often needs a few lines on what it should do, its concept and sometimes a few lines of the code itself need some kind of 'justification' or -explanation. libr/io/vio.c is a hardcore example for this RIO-code has +explanation. librz/io/vio.c is a hardcore example for this RIO-code has fundamental importance, because everything will fail if io does not work correctly. This is needed to make bug-fixing easier, faster and better. Need review: ------------ - libr/io/io.c - libr/core/file.c + librz/io/io.c + librz/core/file.c Tasks: ------ diff --git a/doc/ios.md b/doc/ios.md index ab82bab18e..ca25b72b0e 100644 --- a/doc/ios.md +++ b/doc/ios.md @@ -25,7 +25,7 @@ Signing Codesigning on iOS can be done by using the following command: - $ make -C binr/radare2 ios-sign + $ make -C binrz/rizin ios-sign Note that iOS signing is done by embedding an `entitlements` PLIST file instead of the `Info.plist` as required in OSX. This file describes all the specific fine-grained permissions that the application will need. It is also important to note that if you add an entitlement to an OSX binary it will be forbidden to run. @@ -41,16 +41,16 @@ Installation The Cydia packages can be installed by copying the binary: $ ssh root@192.168.0.13 - # rm -f radare2 - $ scp binr/radare2 root@192.168.0.13:. + # rm -f rizin + $ scp binrz/rizin root@192.168.0.13:. Note that it is important to remove the previous executable from the filesystem because `ldone` signing is associated with the filesystem inode, and it will fail to run if you overwrite the contents of the executable without removing it first. Installing the `cydia.radare.org` repository. # apt-get update - # apt-install radare2 + # apt-install rizin Or just doing it from the command line: - # dpkg -i radare2-*.deb + # dpkg -i rizin-*.deb diff --git a/doc/iphone.md b/doc/iphone.md index 4a499b98ac..3c541f7077 100644 --- a/doc/iphone.md +++ b/doc/iphone.md @@ -57,7 +57,7 @@ Compilation Usage ----- - export R2DIR=/private/var/radare2 + export R2DIR=/private/var/rizin export PATH=${R2DIR}/bin:$PATH export DYLD_LIBRARY_PATH=${R2DIR}/lib r2 ... @@ -102,7 +102,7 @@ Make a fake install in a temporary directory: Clone the cydia repo from radare's github git clone https://github.com/radare/cydia - cd cydia/radare2* + cd cydia/rizin* mkdir root tar xzvf r2.tgz -C root vim CONFIG # bump version @@ -110,8 +110,8 @@ Clone the cydia repo from radare's github Signing ------- -In order to enable debugger capabilities to the radare2 +In order to enable debugger capabilities to the rizin executable you will need to sign it using the following command: - cd binr/radare2 + cd binrz/rizin make sign diff --git a/doc/license.md b/doc/license.md index ecdb70d730..b5def58a9d 100644 --- a/doc/license.md +++ b/doc/license.md @@ -5,7 +5,7 @@ Before you try to statically link r2, you should know about the licenses that go http://stackoverflow.com/questions/10130143/gpl-lgpl-and-static-linking -Also this stackoverflow page explains the legal case of using it via r2pipe, +Also this stackoverflow page explains the legal case of using it via rzpipe, http://stackoverflow.com/questions/1394623/can-i-dynamically-call-a-lgpl-gpl-software-in-my-closed-source-application @@ -13,18 +13,18 @@ LGPLv3 keeps the freedom to the user to switch to a different version of the r2 r2 is licensed under the LGPL license, which permits statically linking, but forces you to liberate the object files and a way to allow users to link them. -r2pipe or scripting/plugins can be used from r2 without any kind of legal issue, only if you modify r2 to make it work with your tools, you should make those changes public, this way we ensure the users always have the freedom to change or upgrade the r2 libraries that come along with r2. +rzpipe or scripting/plugins can be used from r2 without any kind of legal issue, only if you modify r2 to make it work with your tools, you should make those changes public, this way we ensure the users always have the freedom to change or upgrade the r2 libraries that come along with r2. Some parts of r2 are under the GPL license, here's a list of them: -* C++ demangler (libr/bin) +* C++ demangler (librz/bin) * Some exotic disassemblers -* GNU binutils disassemblers (libr/asm) -* GRUB filesystems (libr/fs) +* GNU binutils disassemblers (librz/asm) +* GRUB filesystems (librz/fs) If you are going to use r2 in your proprietary product bear in mind to build it without those parts, which may infect your program. Please refer to the FSF or GNU sites to understand how licenses work. -As long as r2pipe, or webui access is done via a textual interface which requires no reverse engineering or linking for integration other programs will not be affected by the license rules. +As long as rzpipe, or webui access is done via a textual interface which requires no reverse engineering or linking for integration other programs will not be affected by the license rules. If you have any other question about how to use, build, link and distribute r2 with your own tools drop me an email (pancake@nopcode.org) or just talk to the Free Software Foundation in order to clarify that. diff --git a/doc/macos.md b/doc/macos.md index 332ae059b2..3d618be12a 100644 --- a/doc/macos.md +++ b/doc/macos.md @@ -1,7 +1,7 @@ macOS === -macOS Users need to follow some extra steps to get the radare2 program signed and ready to debug other applications without running it as root. Same happens for iOS users, read `doc/ios` for more information. +macOS Users need to follow some extra steps to get the rizin program signed and ready to debug other applications without running it as root. Same happens for iOS users, read `doc/ios` for more information. Installation ------------ @@ -16,7 +16,7 @@ By default it is installed in /usr/local, you can specify a different prefix lik To install bindings you will need to install r2, valac, valabind and swig. The whole process can be automated by using scripts under sys/ - $ r2pm -s python + $ rz_pm -s python Code Signing ------------ @@ -30,40 +30,40 @@ After Mac OS X 10.6, binaries that need permissions to debug require to be signe 1. Select the following menu item: 1. Keychain Access->Certificate Assistant->Create a Certificate... 1. Set the following settings -1. Name = org.radare.radare2 +1. Name = org.radare.rizin 1. Identity Type = Self Signed Root 1. Certificate Type = Code Signing 1. Click Create 1. Click Continue 1. Click Done 1. Click on the "My Certificates" -1. Double click on your new org.radare.radare2 certificate +1. Double click on your new org.radare.rizin certificate 1. Turn down the "Trust" disclosure triangle, scroll to the "Code Signing" trust pulldown menu and select "Always Trust" and authenticate as needed using your username and password. -1. Drag the new "org.radare.radare2" code signing certificate (not the public or private keys of the same name) from the "login" keychain to the "System" keychain in the Keychains pane on the left hand side of the main Keychain Access window. This will move this certificate to the "System" keychain. You'll have to authorize a few more times, set it to be "Always trusted" when asked. -1. In the Keychain Access GUI, click and drag "org.radare.radare2" in the "System" keychain onto the desktop. The drag will create a "~/Desktop/org.radare.radare2.cer" file used in the next step. +1. Drag the new "org.radare.rizin" code signing certificate (not the public or private keys of the same name) from the "login" keychain to the "System" keychain in the Keychains pane on the left hand side of the main Keychain Access window. This will move this certificate to the "System" keychain. You'll have to authorize a few more times, set it to be "Always trusted" when asked. +1. In the Keychain Access GUI, click and drag "org.radare.rizin" in the "System" keychain onto the desktop. The drag will create a "~/Desktop/org.radare.rizin.cer" file used in the next step. 1. Switch to Terminal, and run the following: -1. $ sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/org.radare.radare2.cer -1. $ rm -f ~/Desktop/org.radare.radare2.cer +1. $ sudo security add-trust -d -r trustRoot -p basic -p codeSign -k /Library/Keychains/System.keychain ~/Desktop/org.radare.rizin.cer +1. $ rm -f ~/Desktop/org.radare.rizin.cer 1. Quit Keychain Access 1. Reboot -1. Run sys/install.sh (or follow the next steps if you want to install and sign radare2 manually) +1. Run sys/install.sh (or follow the next steps if you want to install and sign rizin manually) -As said before, the signing process can also be done manually following the next process. First, you will need to sign the radare2 binary: +As said before, the signing process can also be done manually following the next process. First, you will need to sign the rizin binary: - $ make -C binr/radare2 macossign + $ make -C binrz/rizin macossign -But this is not enough. As long as r2 code is split into several libraries, you should sign every single dependency (libr*). +But this is not enough. As long as r2 code is split into several libraries, you should sign every single dependency (librz*). - $ make -C binr/radare2 macos-sign-libs + $ make -C binrz/rizin macos-sign-libs Another alternative is to build a static version of r2 and just sign it. $ sys/static.sh - $ make -C binr/radare2 macossign + $ make -C binrz/rizin macossign You can verify that the binary is properly signed and verified by using the code signing utility: - $ codesign -dv binr/radare2/radare2 + $ codesign -dv binrz/rizin/rizin Additionally, you can run the following command to add the non-privileged user (username) to the Developer Tools group in macOS, avoiding the related Xcode prompts: @@ -89,5 +89,5 @@ Uninstall To uninstall the .pkg downloaded from the r2 website or the one you have generated with `sys/osx-pkg.sh`, run the following as root: - $ pkgutil --only-files --files org.radare.radare2 | sed 's/^/\//' | tr '\n' '\0' | xargs -o -n 1 -0 rm -i + $ pkgutil --only-files --files org.radare.rizin | sed 's/^/\//' | tr '\n' '\0' | xargs -o -n 1 -0 rm -i diff --git a/doc/macros b/doc/macros index 6705bcd26b..d2bd67a53e 100644 --- a/doc/macros +++ b/doc/macros @@ -1,6 +1,6 @@ Examples of Macros -------------------- -NOTE: in radare2, do not add a space between the "," and the next +NOTE: in rizin, do not add a space between the "," and the next command otherwise you are in for pain... 1.) Hello, world diff --git a/doc/maemo.md b/doc/maemo.md index 6e73fa0bd6..ec7cb98917 100644 --- a/doc/maemo.md +++ b/doc/maemo.md @@ -24,4 +24,4 @@ Build for maemo6 (Harmattan) N9 - N950 5. Install the package - dpkg -i radare2-*.deb + dpkg -i rizin-*.deb diff --git a/doc/node.js/README.md b/doc/node.js/README.md index 76b83f93ad..afc590e25d 100644 --- a/doc/node.js/README.md +++ b/doc/node.js/README.md @@ -9,7 +9,7 @@ Description ----------- This is the nodejs implementation of a websever -for radare2. This script can be executed from +for rizin. This script can be executed from inside r2 by using the following command: > #!pipe node . diff --git a/doc/node.js/index.js b/doc/node.js/index.js index c64710e9fc..ab2f0153ce 100644 --- a/doc/node.js/index.js +++ b/doc/node.js/index.js @@ -15,7 +15,7 @@ Or from the shell: */ -var r2p = require ("r2pipe") +var r2p = require ("rzpipe") var http = require('http'); var express = require('express'); diff --git a/doc/node.js/package.json b/doc/node.js/package.json index 776cc86178..45f55f69d4 100644 --- a/doc/node.js/package.json +++ b/doc/node.js/package.json @@ -1,11 +1,11 @@ { "name": "r2-express.js", "version": "0.0.1", - "description": "Express-based webserver for radare2", + "description": "Express-based webserver for rizin", "author": "pancake ", "dependencies": { "express": "*", - "r2pipe": "*" + "rzpipe": "*" }, "license": "MIT" } diff --git a/doc/objc.pl b/doc/objc.pl index a7fa20a9f1..a85580d452 100755 --- a/doc/objc.pl +++ b/doc/objc.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Extract OBJC class information into a radare2 script +# Extract OBJC class information into a rizin script # author: pancake 2014-2015 my $file = $ARGV[0] or die ("Usage: objc.pl [file] ([baddr])\n"); diff --git a/doc/oo.md b/doc/oo.md index ecad156afb..8fd30eff74 100644 --- a/doc/oo.md +++ b/doc/oo.md @@ -1,7 +1,7 @@ Radare OO ========= -I do realize that Object Orientation sucks, so I tried to do libr API +I do realize that Object Orientation sucks, so I tried to do librz API following some sane and basic OO concepts. - No inheritance @@ -41,5 +41,5 @@ Class Library plugins --------------- - They are stored in the p/ directory of each library under the libr directory. + They are stored in the p/ directory of each library under the librz directory. diff --git a/doc/openbsd.md b/doc/openbsd.md index 59857664a3..dc75f2442d 100644 --- a/doc/openbsd.md +++ b/doc/openbsd.md @@ -13,8 +13,8 @@ Radare2 Dependencies: doas pkg_add git gcc gmake pkgconf - git clone https://github.com/radareorg/radare2 - cd radare2 + git clone https://github.com/rizinorg/rizin + cd rizin sys/install.sh /usr/local Python Swig Bindings Dependencies: @@ -30,8 +30,8 @@ Python Swig Bindings Dependencies: Building Python Swig Bindings: ------------------------------ - git clone https://github.com/radareorg/radare2-bindings - cd radare2-bindings + git clone https://github.com/rizinorg/rizin-bindings + cd rizin-bindings export CC=cc export CXX=c++ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig diff --git a/doc/pdb/index.js b/doc/pdb/index.js index d03be9b77a..f7825d9acf 100644 --- a/doc/pdb/index.js +++ b/doc/pdb/index.js @@ -13,7 +13,7 @@ const GUID = 'guid'; const DBG_FNAME = 'dbg_file'; const CURL = 'curl'; const CABEXTRACTOR = (os.platform() != 'win32') ? 'cabextract' : 'expand'; -const RABIN = 'rabin2' +const RABIN = 'rz_bin' var IN_FOLDER = ''; var OUT_FOLDER = ''; const EOL = os.EOL; @@ -119,19 +119,19 @@ var downloader = function (currentValue, index, array) { var saved_guid_and_dbg_fname = []; var spawn = require('child_process').spawn; - rabin2_cmd = spawn(RABIN, ['-I', currentValue]); + rz_bin_cmd = spawn(RABIN, ['-I', currentValue]); // skip pdb files if (currentValue.indexOf('pdb') != -1) { return; } - rabin2_cmd.stdout.on('error', function (err) { + rz_bin_cmd.stdout.on('error', function (err) { console.log('check if rabin is installed'); process.exit(1); }); - rabin2_cmd.stdout.on('data', function (data) { + rz_bin_cmd.stdout.on('data', function (data) { data.toString().split(EOL).map(function (str) { var parts = str.split(' '); @@ -143,7 +143,7 @@ var downloader = function (currentValue, index, array) { curl_start(curr_guid, curr_dbg_fname); } else { console.log('there is no guid and debug file information in binary'); - console.log('check version of rabin2 or maybe this is not PE binary'); + console.log('check version of rz_bin or maybe this is not PE binary'); process.exit(1); } } diff --git a/doc/pdb/package.json b/doc/pdb/package.json index 73845d13a4..8bb444a893 100644 --- a/doc/pdb/package.json +++ b/doc/pdb/package.json @@ -5,7 +5,7 @@ "main": "index.js", "repository": { "type": "git", - "url": "https://github.com/radareorg/radare2.git" + "url": "https://github.com/rizinorg/rizin.git" }, "dependencies": { "node-curl": "*" @@ -15,7 +15,7 @@ ], "keywords": [ "radare", - "radare2", + "rizin", "pdb", "r2", "reversing", @@ -31,7 +31,7 @@ }, "license": "LGPLv3", "bugs": { - "url": "https://github.com/radareorg/radare2/issues" + "url": "https://github.com/rizinorg/rizin/issues" }, "homepage": "http://www.radare.org" } diff --git a/doc/pdb/pdb_usage.md b/doc/pdb/pdb_usage.md index 0bf606f674..b9cd83346f 100644 --- a/doc/pdb/pdb_usage.md +++ b/doc/pdb/pdb_usage.md @@ -3,9 +3,9 @@ PDB usage - To get information about functions, structures, unions, enumerates etc: ```` -rabin2 -P some_pdb_file +rz_bin -P some_pdb_file For example: -rabin2 -P Project1.pdb +rz_bin -P Project1.pdb ... TEST_STRUCT: size 0x8 0x0: a type:(member) long @@ -30,14 +30,14 @@ TEST_STRUCT: size 0x8 - To display all mentioned above information in json format: ```` -rabin2 -Pj some_pdb_file +rz_bin -Pj some_pdb_file ```` - To export information about types, functions: ```` -rabin2 -Pr some_pdb_file +rz_bin -Pr some_pdb_file For example: -rabin2 -P Project1.pdb +rz_bin -P Project1.pdb ... pf TEST_STRUCT ii a b "td enum TEST_ENUM eENUM1=00000010,eENUM2=00000020,eENUM_MAX=00000021 };" @@ -54,9 +54,9 @@ Check out this post for more information about pf: http://radare.today/types/ - To download PDB file for some binary (.exe, .dll): ```` -rabin2 -PP path_to_binary +rz_bin -PP path_to_binary For example: -rabin2 -PP ~/Downloads/libs/user32.dll +rz_bin -PP ~/Downloads/libs/user32.dll % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 336k 100 336k 0 0 34388 0 0:00:10 0:00:10 --:--:-- 38385 Extracting cabinet: /home/inisider/Downloads/libs/user32.pd_ diff --git a/doc/plugins.md b/doc/plugins.md index 683f788a34..40dc6a6be6 100644 --- a/doc/plugins.md +++ b/doc/plugins.md @@ -16,8 +16,8 @@ Plugins can be: - compiled as shared - compiled as static (inside the related library) - libr/plugins/shared - libr/plugins/static + librz/plugins/shared + librz/plugins/static the configure-plugins script will regenerate the required Makefiles to build this stuff as defined. diff --git a/doc/portscan.r2 b/doc/portscan.rz similarity index 100% rename from doc/portscan.r2 rename to doc/portscan.rz diff --git a/doc/qnx.md b/doc/qnx.md index 08724a6ac1..e4828b6b45 100644 --- a/doc/qnx.md +++ b/doc/qnx.md @@ -3,9 +3,9 @@ r2 on android ``` . ./bbndk-env.sh -cd ~/radare2 +cd ~/rizin rm -f plugins.cfg -./configure --with-compiler=qnx --with-ostype=qnx --prefix=/accounts/devuser/radare2 --without-pic --with-nonpic +./configure --with-compiler=qnx --with-ostype=qnx --prefix=/accounts/devuser/rizin --without-pic --with-nonpic make -j 4 ``` diff --git a/doc/rap.md b/doc/rap.md index 9eac43f929..f46bae5540 100644 --- a/doc/rap.md +++ b/doc/rap.md @@ -89,9 +89,9 @@ Examples Python: - See radare2-bindings/python/remote.py and test-rap-*.py + See rizin-bindings/python/remote.py and test-rap-*.py C: - Server: libr/socket/rap_server.c - Client: libr/io/p/io_rap.c + Server: librz/socket/rap_server.c + Client: librz/io/p/io_rap.c diff --git a/doc/releases.md b/doc/releases.md index c598c7b830..143ba31492 100644 --- a/doc/releases.md +++ b/doc/releases.md @@ -28,7 +28,7 @@ Before any release we have to: If available, it would be good to have some unit tests to check nothing is broken. Maybe Vala is the way to go when writing tests, because this way - we ensure that pkg-config, libr and vapis works in a shot. + we ensure that pkg-config, librz and vapis works in a shot. - Test build on different platforms @@ -44,7 +44,7 @@ Before any release we have to: while refactoring code or re-doing-it from scratch. This code, should be reviewed and removed if necessary. - $ grep -r -e TODO -e XXX -e FIX libr + $ grep -r -e TODO -e XXX -e FIX librz - Graph per symbol-module dependency graph to identify unused/dupped/- simplificable use cases of the API for every module. diff --git a/doc/repo b/doc/repo index 26c884ba8a..2ac99a2419 100755 --- a/doc/repo +++ b/doc/repo @@ -1,7 +1,7 @@ #!/bin/sh -R2=https://github.com/radareorg/radare2 +R2=https://github.com/rizinorg/rizin IRED=https://github.com/radare/ired -EXTRAS=https://github.com/radareorg/radare2-extras -CAPSTONE=https://github.com/radare/radare2-capstone -BINDINGS=https://github.com/radareorg/radare2-bindings +EXTRAS=https://github.com/rizinorg/rizin-extras +CAPSTONE=https://github.com/radare/rizin-capstone +BINDINGS=https://github.com/rizinorg/rizin-bindings [ -z "$1" ] && grep -h $0 | grep -v grep || eval echo \$$1 diff --git a/doc/rgraph.md b/doc/rgraph.md index 82bed61f8c..6c695ae52a 100644 --- a/doc/rgraph.md +++ b/doc/rgraph.md @@ -1,4 +1,4 @@ -Not-much-updated graph of relationships between the libr APIs +Not-much-updated graph of relationships between the librz APIs ============================================================= ``` diff --git a/doc/r2ascii.txt b/doc/rzascii.txt similarity index 100% rename from doc/r2ascii.txt rename to doc/rzascii.txt diff --git a/doc/r2pipe.html b/doc/rzpipe.html similarity index 100% rename from doc/r2pipe.html rename to doc/rzpipe.html diff --git a/doc/sandbox/Makefile b/doc/sandbox/Makefile index cb288dd63f..eba85df3d8 100644 --- a/doc/sandbox/Makefile +++ b/doc/sandbox/Makefile @@ -1,5 +1,5 @@ all: # must succeess - sandbox-exec -f radare2.sb /usr/bin/r2 /bin/ls + sandbox-exec -f rizin.sb /usr/bin/r2 /bin/ls # must fail - sandbox-exec -f radare2.sb /usr/bin/r2 /bin/md5 + sandbox-exec -f rizin.sb /usr/bin/r2 /bin/md5 diff --git a/doc/sandbox/README.md b/doc/sandbox/README.md index 2e14d84429..30ffd0e3cb 100644 --- a/doc/sandbox/README.md +++ b/doc/sandbox/README.md @@ -1,7 +1,7 @@ Sandboxing r2 ============= -radare2 supports sandboxing natively by wrapping all attempts +rizin supports sandboxing natively by wrapping all attempts to access the filesystem, network or run programs. But for some platforms, the kernel provides a native sandboxing @@ -14,7 +14,7 @@ OSX OSX Seatbelt implements a system-level sandbox for applications, the rules are described in a lispy .sb file: - $ sandbox-exec -f radare2.sb r2 -S /bin/ls + $ sandbox-exec -f rizin.sb r2 -S /bin/ls **NOTE**: r2 -S is an alias for -e cfg.sandbox=true diff --git a/doc/sandbox/radare2.sb b/doc/sandbox/rizin.sb similarity index 72% rename from doc/sandbox/radare2.sb rename to doc/sandbox/rizin.sb index dbfff5ce53..ec54e91fd0 100644 --- a/doc/sandbox/radare2.sb +++ b/doc/sandbox/rizin.sb @@ -1,4 +1,4 @@ -; Seatbelt script to sandbox radare2 in OSX +; Seatbelt script to sandbox rizin in OSX ; ========================================= ; --pancake ; @@ -29,12 +29,12 @@ (allow file-read* (regex - #"^/Users/[^.]+/.config/radare2/$" - #"^/Users/[^.]+/*/radare2/" - #"^/usr/share/radare2/*" + #"^/Users/[^.]+/.config/rizin/$" + #"^/Users/[^.]+/*/rizin/" + #"^/usr/share/rizin/*" #"^/usr/lib/system/*" - #"^/usr/bin/radare2" - #"^/usr/lib/libr*" + #"^/usr/bin/rizin" + #"^/usr/lib/librz*" #"^/usr/bin/r2" #"^/bin/ls" ) diff --git a/doc/sandbox/rabin2.sb b/doc/sandbox/rz_bin.sb similarity index 75% rename from doc/sandbox/rabin2.sb rename to doc/sandbox/rz_bin.sb index 86ed10463f..f3a0370d70 100644 --- a/doc/sandbox/rabin2.sb +++ b/doc/sandbox/rz_bin.sb @@ -1,4 +1,4 @@ -; Seatbelt script to sandbox radare2 in OSX +; Seatbelt script to sandbox rizin in OSX ; ========================================= ; --pancake ; @@ -29,11 +29,11 @@ (allow file-read* (regex - #"^/Users/[^.]+/*/radare2/" - #"^/usr/share/radare2/*" + #"^/Users/[^.]+/*/rizin/" + #"^/usr/share/rizin/*" #"^/usr/lib/system/*" - #"^/usr/lib/libr*" - #"^/usr/bin/rabin2" + #"^/usr/lib/librz*" + #"^/usr/bin/rz_bin" ) ) (deny default) diff --git a/doc/sdb_ordinal.md b/doc/sdb_ordinal.md index c0803f8ed0..09b480fe17 100644 --- a/doc/sdb_ordinal.md +++ b/doc/sdb_ordinal.md @@ -1,6 +1,6 @@ # Cannot find R2PATH/format/dll/DLLNAME.sdb -1. Execute `rabin2 -rs DLLNAME.dll | grep -i DLLNAME | grep -v Ordi |grep ^k| cut -d / -f 4- > DLLNAME.sdb.txt` -2. Upload file `DLLNAME.sdb.txt` in https://github.com/radareorg/radare2/tree/master/libr/bin/d/dll -3. Change the following [Makefile](https://github.com/radareorg/radare2/blob/master/libr/bin/d/Makefile#L14) +1. Execute `rz_bin -rs DLLNAME.dll | grep -i DLLNAME | grep -v Ordi |grep ^k| cut -d / -f 4- > DLLNAME.sdb.txt` +2. Upload file `DLLNAME.sdb.txt` in https://github.com/rizinorg/rizin/tree/master/librz/bin/d/dll +3. Change the following [Makefile](https://github.com/rizinorg/rizin/blob/master/librz/bin/d/Makefile#L14) 4. Create a Pull Request to Master diff --git a/doc/snap.md b/doc/snap.md index 800fc42576..3c1f26efb5 100644 --- a/doc/snap.md +++ b/doc/snap.md @@ -1,46 +1,46 @@ -Installing the snap package of radare2 +Installing the snap package of rizin ====================================== -radare2 is also available as a snap package and can be installed on a system that supports snap packages. See [Installing snapd](https://snapcraft.io/docs/installing-snapd) to setup your system to support snap packages. +rizin is also available as a snap package and can be installed on a system that supports snap packages. See [Installing snapd](https://snapcraft.io/docs/installing-snapd) to setup your system to support snap packages. Status of snap package support ------------------------------ -Currently, radare2 is available as a _beta_ snap package that works in _devmode_ security confinement (developer mode). Refer back to this section for updated instructions when radare2 is out of _beta/devmode_. +Currently, rizin is available as a _beta_ snap package that works in _devmode_ security confinement (developer mode). Refer back to this section for updated instructions when rizin is out of _beta/devmode_. -Currently, you need to prepend `radare2.` to each command you want to run. For example, use `radare2.rabin2` to run `rabin2`. +Currently, you need to prepend `rizin.` to each command you want to run. For example, use `rizin.rz_bin` to run `rz_bin`. -Snap packages that work in _devmode_ security confinement do not appear in search results, when you search for them in the Snap Store. To find information about this snap package, run `snap info radare2`. See the section below on this. +Snap packages that work in _devmode_ security confinement do not appear in search results, when you search for them in the Snap Store. To find information about this snap package, run `snap info rizin`. See the section below on this. -Installing radare2 +Installing rizin ----------------- -This command installs the `radare2` snap package from the _beta_ channel, using the _devmode_ (developer mode) security confinement type. The _devmode_ security confinement disables any restrictions that are applied to typical snap packages. _devmode_ makes a package to work similar to APT and RPM packages. +This command installs the `rizin` snap package from the _beta_ channel, using the _devmode_ (developer mode) security confinement type. The _devmode_ security confinement disables any restrictions that are applied to typical snap packages. _devmode_ makes a package to work similar to APT and RPM packages. - $ sudo snap install radare2 --channel=beta --devmode + $ sudo snap install rizin --channel=beta --devmode Running commands ---------------- -Currently, the radare2 commands can be invoked with the following names: +Currently, the rizin commands can be invoked with the following names: -- `radare2` or `radare2.radare2`: The `r2`/`radare2` command. -- `radare2.r2pm` : The `r2pm` command. -- `radare2.r2agent` : The `r2agent` command. -- `radare2.rafind2` : The `rafind2` command. -- `radare2.rahash2` : The `rahash2` command. -- `radare2.rasm2` : The `rasm2` command. -- `radare2.rabin2` : The `rabin2` command. -- `radare2.radiff2` : The `radiff2` command. -- `radare2.ragg2` : The `ragg2` command. -- `radare2.rarun2` : The `rarun2` command. -- `radare2.rax2` : The `rax2` command. -- `radare2.rasign2` : The `rasign2` command. +- `rizin` or `rizin.rizin`: The `r2`/`rizin` command. +- `rizin.rz_pm` : The `rz_pm` command. +- `rizin.rz_agent` : The `rz_agent` command. +- `rizin.rz_find` : The `rz_find` command. +- `rizin.rz_hash` : The `rz_hash` command. +- `rizin.rz_asm` : The `rz_asm` command. +- `rizin.rz_bin` : The `rz_bin` command. +- `rizin.rz_diff` : The `rz_diff` command. +- `rizin.rz_gg` : The `rz_gg` command. +- `rizin.rz_run` : The `rz_run` command. +- `rizin.rz_ax` : The `rz_ax` command. +- `rizin.rz_sign` : The `rz_sign` command. -Getting info about the radare2 snap package +Getting info about the rizin snap package ------------------------------------------- -Run the following command to get info about the radare2 snap package. You can see the list of available commands and how to invoke them. There are packages in the `beta` and `edge` channels, currently with radare2 4.5.0. The build number in this example is 5, and is an ascending number that characterises each new build. We have installed radare 4.5.0 from build 5, using the _devmode_ security confinement. We are _tracking_ the `beta` channel. Since the installed build number is the same as the build number in the channel that we are tracking, we are already running the latest available version. +Run the following command to get info about the rizin snap package. You can see the list of available commands and how to invoke them. There are packages in the `beta` and `edge` channels, currently with rizin 4.5.0. The build number in this example is 5, and is an ascending number that characterises each new build. We have installed radare 4.5.0 from build 5, using the _devmode_ security confinement. We are _tracking_ the `beta` channel. Since the installed build number is the same as the build number in the channel that we are tracking, we are already running the latest available version. ``` -$ snap info radare2 +$ snap info rizin ... description: | Radare2 (also known as r2) is a complete framework for reverse-engineering @@ -52,18 +52,18 @@ description: | and operating systems. commands: - - radare2.r2agent - - radare2.r2pm - - radare2.rabin2 - - radare2.radare2 - - radare2.radiff2 - - radare2.rafind2 - - radare2.ragg2 - - radare2.rahash2 - - radare2.rarun2 - - radare2.rasign2 - - radare2.rasm2 - - radare2.rax2 + - rizin.rz_agent + - rizin.rz_pm + - rizin.rz_bin + - rizin.rizin + - rizin.rz_diff + - rizin.rz_find + - rizin.rz_gg + - rizin.rz_hash + - rizin.rz_run + - rizin.rz_sign + - rizin.rz_asm + - rizin.rz_ax snap-id: ceuTRkmV5T8oTHt2psXxLRma25xfBrfS tracking: latest/beta refresh-date: today at 12:51 EEST @@ -75,25 +75,25 @@ channels: installed: 4.5.0 (5) 15MB devmode ``` -Updating radare2 +Updating rizin ---------------- The snap packages that are installed in _devmode_ are not updated automatically. You can update manually: - $ sudo snap refresh radare2 + $ sudo snap refresh rizin -See the section above on how to get info about the radare2 snap package and how to determine whether there is an updated version available. +See the section above on how to get info about the rizin snap package and how to determine whether there is an updated version available. -Uninstalling radare2 +Uninstalling rizin -------------------- -Run the following command to uninstall the snap package of radare2: +Run the following command to uninstall the snap package of rizin: - $ sudo snap remove radare2 + $ sudo snap remove rizin Supported architectures ======================= -The radare2 snap package is currently available for the following architectures: +The rizin snap package is currently available for the following architectures: 1. `amd64` 1. `i386` @@ -105,8 +105,8 @@ The radare2 snap package is currently available for the following architectures: Troubleshooting --------------- -- _error: snap "radare2" is not available on stable_: When installing the snap package of radare2, you currently need to specify the _beta_ channel. Append `--channel=beta` on the installation command line. -- _error: The publisher of snap "radare2" has indicated that they do not consider this revision to be of production quality_: When installing the snap package of radare2, you currently need to specify the _devmode_ confinement. Append `--devmode` on the installation command line. -- _How can I download the snap package for offline use?_: Use the command `snap download radare2 --channel=beta`. You can then run `sudo snap install` to install the `.snap` package that was just downloaded. +- _error: snap "rizin" is not available on stable_: When installing the snap package of rizin, you currently need to specify the _beta_ channel. Append `--channel=beta` on the installation command line. +- _error: The publisher of snap "rizin" has indicated that they do not consider this revision to be of production quality_: When installing the snap package of rizin, you currently need to specify the _devmode_ confinement. Append `--devmode` on the installation command line. +- _How can I download the snap package for offline use?_: Use the command `snap download rizin --channel=beta`. You can then run `sudo snap install` to install the `.snap` package that was just downloaded. - _Do I need to use "sudo" with snap commands?_: You need to prepend `sudo` when you run most snap commands that perform privileged actions. However, if you log in into the Snap Store using `sudo snap login`, then you do not need anymore to prepend `sudo`. diff --git a/doc/static-plugins b/doc/static-plugins index 5fe861212d..edb76e4dc1 100644 --- a/doc/static-plugins +++ b/doc/static-plugins @@ -1,10 +1,10 @@ -Edit libr/config.h and libr/config.mk +Edit librz/config.h and librz/config.mk -In libr/config.mk set a list of static asm plugins... +In librz/config.mk set a list of static asm plugins... STATIC_ASM_PLUGINS=p/java.mk p/mips.mk -In libr/config.h define the list of struct plugins +In librz/config.h define the list of struct plugins #define R_ASM_STATIC_PLUGINS \ &r_asm_plugin_java, 0 diff --git a/doc/strings.md b/doc/strings.md index 246f47a304..c68792ebcf 100644 --- a/doc/strings.md +++ b/doc/strings.md @@ -13,8 +13,8 @@ bin.rawstr = [false] - load strings from unknown rbin Program args ------------ ``` -rabin2 -z # list strings -rabin2 -zz # list strings from raw binary (unknown rbin type) +rz_bin -z # list strings +rz_bin -zz # list strings from raw binary (unknown rbin type) ``` Examples diff --git a/doc/termux.md b/doc/termux.md index 5c7c6452be..49b60635c7 100644 --- a/doc/termux.md +++ b/doc/termux.md @@ -8,12 +8,12 @@ Android devices for x86, arm and arm64. Installation ------------ -The Termux maintainer of the radare2 package updates the package really fast after every release +The Termux maintainer of the rizin package updates the package really fast after every release which happens every 6 weeks. So in this case, as long as it's supposed to run on embedded devices it is ok to just install the package from Termux unless you really want to track git master or develop for this platform. - sudo apt install radare2 + sudo apt install rizin Building from git ----------------- @@ -24,8 +24,8 @@ The packages required to build are: Now you can clone the repo and build: - git clone --depth 1 https://github.com/radareorg/radare2 - cd radare2 + git clone --depth 1 https://github.com/rizinorg/rizin + cd rizin sys/termux.sh Building with meson @@ -35,7 +35,7 @@ If you want to build with meson: sudo apt install python sudo pip install meson - sudo r2pm -i ninja + sudo rz_pm -i ninja And then you can run the build: diff --git a/doc/vim2r2.js b/doc/vim2rz.js similarity index 99% rename from doc/vim2r2.js rename to doc/vim2rz.js index 98781012eb..02b9600d54 100644 --- a/doc/vim2r2.js +++ b/doc/vim2rz.js @@ -1,6 +1,6 @@ /* # author: pancake -# description: Duktape/NodeJS script to convert VIM colorschemes for radare2 +# description: Duktape/NodeJS script to convert VIM colorschemes for rizin # copyright: 2015 LGPLv3 # # Using NodeJS diff --git a/doc/windbg.md b/doc/windbg.md index 366625c85c..7c054e598d 100644 --- a/doc/windbg.md +++ b/doc/windbg.md @@ -51,7 +51,7 @@ we should specify the x86-32 too. (32 and 64 bit debugging is supported) On Windows you should run the following line: - $ radare2 -D winkd winkd://\\.\pipe\com_1 + $ rizin -D winkd winkd://\\.\pipe\com_1 At this point, we will get stuck here: diff --git a/doc/windows.md b/doc/windows.md index 5da5a785f2..f95f58ceb7 100644 --- a/doc/windows.md +++ b/doc/windows.md @@ -1,7 +1,7 @@ How to Build for Windows ======================== -You can follow the [r2book](https://radare.gitbooks.io/radare2book/content/first_steps/windows_compilation.html) for a more complete guide. +You can follow the [r2book](https://radare.gitbooks.io/rizinbook/content/first_steps/windows_compilation.html) for a more complete guide. Native --------------- @@ -15,19 +15,19 @@ You will need: First, call `vcvarsall.bat` with your architecture (x86, x64, arm) to setup the compilation environment. - cd radare2 - python3 sys\meson.py --release --backend vs2019 --shared --install --prefix="%cd%\radare2_dist" --webui + cd rizin + python3 sys\meson.py --release --backend vs2019 --shared --install --prefix="%cd%\rizin_dist" --webui You can change `--backend` to your VS version (`vs2015`, `vs2017`), `ninja` buildsystem is also supported. For XP support, append `--xp` to the command (not compatible with VS2019). -You can then add `radare2_dist` to your PATH to make radare2 accessible from everywhere. +You can then add `rizin_dist` to your PATH to make rizin accessible from everywhere. Crosscompilation ---------------- -As building with mingw is no longer officially supported in radare2, crosscompilation isn't (easily) possible. +As building with mingw is no longer officially supported in rizin, crosscompilation isn't (easily) possible. You can check the official [Meson documentation](https://mesonbuild.com/Cross-compilation.html). diff --git a/doc/yara.md b/doc/yara.md index 37c4fc97ac..4fdb00348d 100644 --- a/doc/yara.md +++ b/doc/yara.md @@ -17,14 +17,14 @@ Requirements ------------ You can either install libyara with your preferred package manager, or you -can execute `r2pm -i yara` in order to retrieve latest source, compile, +can execute `rz_pm -i yara` in order to retrieve latest source, compile, and install the library via the r2 package manager. You will also need `yara-r2` to execute the yara utility from the r2 shell. -Yara in radare2 +Yara in rizin ---------- -radare2 provides several commands, allowing the user, to add or remove rules, +rizin provides several commands, allowing the user, to add or remove rules, scan a file, and list or use rules tags. You can list the yara commands with the following r2 command `yara [help]`. @@ -32,9 +32,9 @@ You can list the yara commands with the following r2 command `yara [help]`. Rules ----- -By default, radare2 ships with some common crypto and packers rules that you -can find in `/usr/local/share/radare2/last/yara/` if you installed it r2 or -`radare2/shlr/yara/` in the git repo. +By default, rizin ships with some common crypto and packers rules that you +can find in `/usr/local/share/rizin/last/yara/` if you installed it r2 or +`rizin/shlr/yara/` in the git repo. They are loaded as soon as you start using the yara plugin. So you can issue `yara scan` and automatically see if your binary is packed with a known packer. @@ -50,7 +50,7 @@ yara scan Yara versions ------------- -Because radare2 has support for both yara versions currently, +Because rizin has support for both yara versions currently, depending from the version/plugin you've loaded, you need to use the proper versioned command. E.g. `yara` or `yara`. For example `yara scan`. diff --git a/doc/zsh/_rax2 b/doc/zsh/_rax2 deleted file mode 100644 index fbf023aea6..0000000000 --- a/doc/zsh/_rax2 +++ /dev/null @@ -1,43 +0,0 @@ -#compdef rax2 -local context state state_descr line - -_rax2() { - local -a options=( - '-b[bin -> str ; rax2 -b 01000101 01110110]' - '-B[str -> bin ; rax2 -B hello]' - '-d[force integer ; rax2 -d 3 -> 3 instead of 0x3]' - '-e[swap endianness ; rax2 -e 0x33]' - '-D[base64 decode ;]' - '-E[base64 encode ;]' - '-f[floating point ; rax2 -f 6.3+2.1]' - '-F[stdin slurp C hex ; rax2 -F < shellcode.c]' - '-h[help ; rax2 -h]' - '-i[dump as C array ; rax2 -i < bytes]' - '-k[keep base ; rax2 -k 33+3 -> 36]' - '-K[randomart ; rax2 -K 0x34 1020304050]' - '-L[bin -> hex ; rax2 -L 1111111]' - '-n[binary number ; rax2 -n 0x1234 # 34120000]' - '-N[binary number ; rax2 -N 0x1234 # \x34\x12\x00\x00]' - '-r[r2 style output ; rax2 -r 0x1234]' - '-s[hexstr -> raw ; rax2 -s 43 4a 50]' - '-S[raw -> hexstr ; rax2 -S < /bin/ls > ls.hex]' - '-t[tstamp -> str ; rax2 -t 1234567890]' - '-x[hash string ; rax2 -x linux osx]' - '-u[units ; rax2 -u 389289238 # 317.0M]' - '-w[signed word ; rax2 -w 16 0xffff]' - '-v[version ; rax2 -v]' - ) - - _arguments -S -s : $options '*:expr' -} - -_rax2 "$@" - -# Local Variables: -# mode: shell-script -# coding: utf-8-unix -# indent-tabs-mode: nil -# sh-indentation: 2 -# sh-basic-offset: 2 -# End: -# vim: ft=zsh sw=2 sts=2 et diff --git a/doc/zsh/_r2 b/doc/zsh/_rz similarity index 91% rename from doc/zsh/_r2 rename to doc/zsh/_rz index 5ad2bf416e..90d70a93b6 100644 --- a/doc/zsh/_r2 +++ b/doc/zsh/_rz @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_r2() { +_rz() { local -a options=( '-\=[perform !=! command to run all commands remotely]' '-0[print \x00 after init and every command]' @@ -39,14 +39,14 @@ _r2() { '(-q -Q)-Q[quiet mode (no prompt) and quit faster (quietLeak=true)]' '-p+[use project, list if no arg, load if no file]: :->project' '-P+[apply rapatch file and quit]:rapatch:_files' - '-r+[specify rarun2 profile to load (same as -e dbg.profile=X)]:dbg.profile' - '-R+[specify custom rarun2 directive]:rr2rule' + '-r+[specify rz_run profile to load (same as -e dbg.profile=X)]:dbg.profile' + '-R+[specify custom rz_run directive]:rrz_testule' '-s+[initial seek]:addr' '-S[start r2 in sandbox mode]' - '-t[load rabin2 info in thread]' + '-t[load rz_bin info in thread]' '-u[set bin.filter=false to get raw sym/sec/cls names]' - '(-v -V)-v[show radare2 version]' - '(-v -V)-V[show radare2 and lib versions)]' + '(-v -V)-v[show rizin version]' + '(-v -V)-V[show rizin and lib versions)]' '-w[open file in write mode]' '-x[open without exec-flag, see io.exec]' '(-z -zz)-z[do not load strings]' @@ -77,7 +77,7 @@ _r2() { return ret } -_r2 "$@" +_rz "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_rasm2 b/doc/zsh/_rz_asm similarity index 88% rename from doc/zsh/_rasm2 rename to doc/zsh/_rz_asm index 57c7ba7c0f..c0cb4b82b4 100644 --- a/doc/zsh/_rasm2 +++ b/doc/zsh/_rz_asm @@ -1,4 +1,4 @@ -#compdef rasm2 +#compdef rz_asm local context state state_descr line local -i ret=1 @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_rasm2() { +_rz_asm() { local -a options=( '-a+[Set architecture to assemble/disassemble (see -L)]: :->arch' '-A[Show Analysis information from given hexpairs]' @@ -25,7 +25,7 @@ _rasm2() { '-l+[Input/Output length]:len' '-L[List Asm plugins: (a=asm, d=disasm, A=analyze, e=ESIL)]' '-o+[Set start address for code (default 0)]:offset' - '-O+[Output file name (rasm2 -Bf a.asm -O a)]: :_files' + '-O+[Output file name (rz_asm -Bf a.asm -O a)]: :_files' '-p[Run SPP over input for assembly]' '(-j -r)-r[output in radare commands]' '-s+[Select syntax (intel, att)]: :->syntax' @@ -39,20 +39,20 @@ _rasm2() { case $state in arch) - local -a sub=(${(f)"$(rasm2 -L | cut -c 18-28 | tr -d ' ')"}) + local -a sub=(${(f)"$(rz_asm -L | cut -c 18-28 | tr -d ' ')"}) _values 'arch' $sub && ret=0 ;; asm.os) _values 'asm.os' $(r2_qc 'e asm.os=?') && ret=0 ;; syntax) - _values 'syntax' $(rasm2 '-s?') && ret=0 + _values 'syntax' $(rz_asm '-s?') && ret=0 ;; esac return ret } -_rasm2 "$@" +_rz_asm "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_rz_ax b/doc/zsh/_rz_ax new file mode 100644 index 0000000000..f968c2f730 --- /dev/null +++ b/doc/zsh/_rz_ax @@ -0,0 +1,43 @@ +#compdef rz_ax +local context state state_descr line + +_rz_ax() { + local -a options=( + '-b[bin -> str ; rz_ax -b 01000101 01110110]' + '-B[str -> bin ; rz_ax -B hello]' + '-d[force integer ; rz_ax -d 3 -> 3 instead of 0x3]' + '-e[swap endianness ; rz_ax -e 0x33]' + '-D[base64 decode ;]' + '-E[base64 encode ;]' + '-f[floating point ; rz_ax -f 6.3+2.1]' + '-F[stdin slurp C hex ; rz_ax -F < shellcode.c]' + '-h[help ; rz_ax -h]' + '-i[dump as C array ; rz_ax -i < bytes]' + '-k[keep base ; rz_ax -k 33+3 -> 36]' + '-K[randomart ; rz_ax -K 0x34 1020304050]' + '-L[bin -> hex ; rz_ax -L 1111111]' + '-n[binary number ; rz_ax -n 0x1234 # 34120000]' + '-N[binary number ; rz_ax -N 0x1234 # \x34\x12\x00\x00]' + '-r[r2 style output ; rz_ax -r 0x1234]' + '-s[hexstr -> raw ; rz_ax -s 43 4a 50]' + '-S[raw -> hexstr ; rz_ax -S < /bin/ls > ls.hex]' + '-t[tstamp -> str ; rz_ax -t 1234567890]' + '-x[hash string ; rz_ax -x linux osx]' + '-u[units ; rz_ax -u 389289238 # 317.0M]' + '-w[signed word ; rz_ax -w 16 0xffff]' + '-v[version ; rz_ax -v]' + ) + + _arguments -S -s : $options '*:expr' +} + +_rz_ax "$@" + +# Local Variables: +# mode: shell-script +# coding: utf-8-unix +# indent-tabs-mode: nil +# sh-indentation: 2 +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 sts=2 et diff --git a/doc/zsh/_rabin2 b/doc/zsh/_rz_bin similarity index 96% rename from doc/zsh/_rabin2 rename to doc/zsh/_rz_bin index d5f4c0180f..3f0dad62fe 100644 --- a/doc/zsh/_rabin2 +++ b/doc/zsh/_rz_bin @@ -1,4 +1,4 @@ -#compdef rabin2 +#compdef rz_bin local context state state_descr line local -i ret=1 @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_rabin2() { +_rz_bin() { local -a options=( '-@+[show section, symbol or import at addr]:addr' '-A[list sub-binaries and their arch-bits pairs]' @@ -71,14 +71,14 @@ _rabin2() { _values 'checksum' all $(r2_qc 'ph?') && ret=0 ;; plugin) - local -a sub=(${(f)"$(rabin2 -L | grep '^bin ' | sed -E 's/bin +([^ ]+) +(.*)/\1[\2]/')"}) + local -a sub=(${(f)"$(rz_bin -L | grep '^bin ' | sed -E 's/bin +([^ ]+) +(.*)/\1[\2]/')"}) _values 'plugin' $sub && ret=0 ;; esac return ret } -_rabin2 "$@" +_rz_bin "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_radiff2 b/doc/zsh/_rz_diff similarity index 97% rename from doc/zsh/_radiff2 rename to doc/zsh/_rz_diff index d8e74b88b8..1b3bee0872 100644 --- a/doc/zsh/_radiff2 +++ b/doc/zsh/_rz_diff @@ -1,4 +1,4 @@ -#compdef radiff2 +#compdef rz_diff local context state state_descr line local -i ret=1 @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_radiff2() { +_rz_diff() { local -a options=( '-a[specify architecture plugin to use (x86, arm, ..)]: :->arch' '(-A -AA)-A[run aaa after loading each binary (see -C)]' @@ -49,7 +49,7 @@ _radiff2() { return ret } -_radiff2 "$@" +_rz_diff "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_rafind2 b/doc/zsh/_rz_find similarity index 96% rename from doc/zsh/_rafind2 rename to doc/zsh/_rz_find index 23bf8dd7d8..efd9618b1e 100644 --- a/doc/zsh/_rafind2 +++ b/doc/zsh/_rz_find @@ -1,7 +1,7 @@ -#compdef rafind2 +#compdef rz_find local context state state_descr line -_rafind2() { +_rz_find() { local -a options=( '-a+[only accept aligned hits]:align' '-b+[set block size]:size' @@ -27,7 +27,7 @@ _rafind2() { _arguments -S -s : $options '*:file:_files' } -_rafind2 "$@" +_rz_find "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_ragg2 b/doc/zsh/_rz_gg similarity index 97% rename from doc/zsh/_ragg2 rename to doc/zsh/_rz_gg index 410818d91a..d715d71cc8 100644 --- a/doc/zsh/_ragg2 +++ b/doc/zsh/_rz_gg @@ -1,4 +1,4 @@ -#compdef ragg2 +#compdef rz_gg local context state state_descr line local -i ret=1 @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_ragg2() { +_rz_gg() { local -a options=( '-a+[select architecture (x86, mips, arm)]: :->arch' '-b+[register size (32, 64, ..)]:bits:(32 64)' @@ -52,7 +52,7 @@ _ragg2() { return ret } -_ragg2 "$@" +_rz_gg "$@" # Local Variables: # mode: shell-script diff --git a/doc/zsh/_rahash2 b/doc/zsh/_rz_hash similarity index 97% rename from doc/zsh/_rahash2 rename to doc/zsh/_rz_hash index d60480b294..8f669b9bad 100644 --- a/doc/zsh/_rahash2 +++ b/doc/zsh/_rz_hash @@ -1,4 +1,4 @@ -#compdef rahash2 +#compdef rz_hash local context state state_descr line local -i ret=1 @@ -6,7 +6,7 @@ r2_qc() { r2 -qc $1 -- } -_rahash2() { +_rz_hash() { local -a options=( "-a+[comma separated list of algorithms (default is 'sha256')]: :->algo" '-b+[specify the size of the block (instead of full file)]:bsize' @@ -44,7 +44,7 @@ _rahash2() { return ret } -_rahash2 "$@" +_rz_hash "$@" # Local Variables: # mode: shell-script diff --git a/env.sh b/env.sh index 85a621f53b..73576a8014 100755 --- a/env.sh +++ b/env.sh @@ -24,7 +24,7 @@ fi new_env=' R2_ENV_IS_SET=1 -R2_LIBR_PLUGINS=${pfx}/lib/radare2 +R2_LIBR_PLUGINS=${pfx}/lib/rizin PATH=$pfx/bin:${PATH} LD_LIBRARY_PATH=$pfx/lib:$LD_LIBRARY_PATH DYLD_LIBRARY_PATH=$pfx/lib:$DYLD_LIBRARY_PATH @@ -40,7 +40,7 @@ fi if [ -z "$*" ]; then echo - echo "==> Entering radare2 environment shell..." + echo "==> Entering rizin environment shell..." echo echo $new_env $* \ | sed -e 's, ,\n,g' \ diff --git a/global.mk b/global.mk index 8699e216d9..8de46a9873 100644 --- a/global.mk +++ b/global.mk @@ -4,9 +4,9 @@ DESTDIR= COMPILER?=gcc TOP:=$(dir $(lastword $(MAKEFILE_LIST))) -LTOP:=$(TOP)/libr +LTOP:=$(TOP)/librz STOP:=$(TOP)/shlr -BTOP:=$(TOP)/binr +BTOP:=$(TOP)/binrz ifeq ($(MAKEFLAGS),s) SILENT=1 @@ -41,5 +41,5 @@ endif -include $(TOP)/mk/platform.mk -include $(TOP)/mk/${COMPILER}.mk -WWWROOT=${DATADIR}/radare2/${VERSION}/www +WWWROOT=${DATADIR}/rizin/${VERSION}/www endif diff --git a/libr/anal/arch/gb/meta_gb_cmt.c b/libr/anal/arch/gb/meta_gb_cmt.c deleted file mode 100644 index 3534bd62ae..0000000000 --- a/libr/anal/arch/gb/meta_gb_cmt.c +++ /dev/null @@ -1,11 +0,0 @@ -/* radare - LGPL - Copyright 2013 - condret */ - -#include -#include - -void meta_gb_bankswitch_cmt(RAnal *a, ut64 addr, ut16 ldarg) { - if(0x1fff ldarg && ldarg > 0x3fff) - r_meta_set_string(a, R_META_TYPE_COMMENT, addr, "Ramswitch"); -} diff --git a/libr/anal/arch/hexagon/hexagon_anal.h b/libr/anal/arch/hexagon/hexagon_anal.h deleted file mode 100644 index 35fd49b4f5..0000000000 --- a/libr/anal/arch/hexagon/hexagon_anal.h +++ /dev/null @@ -1,2 +0,0 @@ -int hexagon_anal_instruction(HexInsn *hi, RAnalOp *op); - diff --git a/libr/anal/cc.c b/libr/anal/cc.c deleted file mode 100644 index f4db5cc201..0000000000 --- a/libr/anal/cc.c +++ /dev/null @@ -1,204 +0,0 @@ -/* radare - LGPL - Copyright 2011-2020 - pancake, Oddcoder */ - -/* Universal calling convention implementation based on sdb */ - -#include -#define DB anal->sdb_cc - -R_API void r_anal_cc_del(RAnal *anal, const char *name) { - size_t i; - RStrBuf sb; - sdb_unset (DB, r_strbuf_initf (&sb, "%s", name), 0); - sdb_unset (DB, r_strbuf_setf (&sb, "cc.%s.ret", name), 0); - sdb_unset (DB, r_strbuf_setf (&sb, "cc.%s.argn", name), 0); - for (i = 0; i < R_ANAL_CC_MAXARG; i++) { - sdb_unset (DB, r_strbuf_setf (&sb, "cc.%s.arg%d", name, i), 0); - } - sdb_unset (DB, r_strbuf_setf (&sb, "cc.%s.self", name), 0); - sdb_unset (DB, r_strbuf_setf (&sb, "cc.%s.error", name), 0); - r_strbuf_fini (&sb); -} - -R_API bool r_anal_cc_set(RAnal *anal, const char *expr) { - char *e = strdup (expr); - char *p = strchr (e, '('); - if (!p) { - free (e); - return false; - } - *p++ = 0; - char *args = strdup (p); - r_str_trim (p); - char *end = strchr (args, ')'); - if (!end) { - free (args); - free (e); - return false; - } - *end++ = 0; - r_str_trim (p); - r_str_trim (e); - char *ccname = strchr (e, ' '); - if (ccname) { - *ccname++ = 0; - r_str_trim (ccname); - } else { - free (args); - free (e); - return false; - } - sdb_set (DB, ccname, "cc", 0); - sdb_set (DB, sdb_fmt ("cc.%s.ret", ccname), e, 0); - - RList *ccArgs = r_str_split_list (args, ",", 0); - RListIter *iter; - const char *arg; - int n = 0; - r_list_foreach (ccArgs, iter, arg) { - if (!strcmp (arg, "stack")) { - sdb_set (DB, sdb_fmt ("cc.%s.argn", ccname), arg, 0); - } else { - sdb_set (DB, sdb_fmt ("cc.%s.arg%d", ccname, n), arg, 0); - n++; - } - } - r_list_free (ccArgs); - free (e); - free (args); - return true; -} - -R_API char *r_anal_cc_get(RAnal *anal, const char *name) { - int i; - // get cc by name and print the expr - if (r_str_cmp (sdb_const_get (DB, name, 0), "cc", -1)) { - eprintf ("This is not a valid calling convention name\n"); - return NULL; - } - const char *ret = sdb_const_get (DB, sdb_fmt ("cc.%s.ret", name), 0); - if (!ret) { - eprintf ("Cannot find return key\n"); - return NULL; - } - RStrBuf *sb = r_strbuf_new (NULL); - const char *self = r_anal_cc_self (anal, name); - r_strbuf_appendf (sb, "%s %s%s%s (", ret, self? self: "", self? ".": "", name); - bool isFirst = true; - for (i = 0; i < R_ANAL_CC_MAXARG; i++) { - const char *k = sdb_fmt ("cc.%s.arg%d", name, i); - const char *arg = sdb_const_get (DB, k, 0); - if (!arg) { - break; - } - r_strbuf_appendf (sb, "%s%s", isFirst? "": ", ", arg); - isFirst = false; - } - const char *argn = sdb_const_get (DB, sdb_fmt ("cc.%s.argn", name), 0); - if (argn) { - r_strbuf_appendf (sb, "%s%s", isFirst? "": ", ", argn); - } - r_strbuf_append (sb, ")"); - - const char *error = r_anal_cc_error (anal, name); - if (error) { - r_strbuf_appendf (sb, " %s", error); - } - - r_strbuf_append (sb, ";"); - return r_strbuf_drain (sb); -} - -R_API bool r_anal_cc_exist(RAnal *anal, const char *convention) { - r_return_val_if_fail (anal && convention, false); - const char *x = sdb_const_get (DB, convention, 0); - return x && *x && !strcmp (x, "cc"); -} - -R_API const char *r_anal_cc_arg(RAnal *anal, const char *convention, int n) { - r_return_val_if_fail (anal, NULL); - r_return_val_if_fail (n >= 0, NULL); - if (!convention) { - return NULL; - } - - const char *query = sdb_fmt ("cc.%s.arg%d", convention, n); - const char *ret = sdb_const_get (DB, query, 0); - if (!ret) { - query = sdb_fmt ("cc.%s.argn", convention); - ret = sdb_const_get (DB, query, 0); - } - return ret? r_str_constpool_get (&anal->constpool, ret): NULL; -} - -R_API const char *r_anal_cc_self(RAnal *anal, const char *convention) { - r_return_val_if_fail (anal && convention, NULL); - const char *query = sdb_fmt ("cc.%s.self", convention); - const char *self = sdb_const_get (DB, query, 0); - return self? r_str_constpool_get (&anal->constpool, self): NULL; -} - -R_API void r_anal_cc_set_self(RAnal *anal, const char *convention, const char *self) { - if (!r_anal_cc_exist (anal, convention)) { - return; - } - RStrBuf sb; - sdb_set (anal->sdb_cc, r_strbuf_initf (&sb, "cc.%s.self", convention), self, 0); - r_strbuf_fini (&sb); -} - -R_API const char *r_anal_cc_error(RAnal *anal, const char *convention) { - r_return_val_if_fail (anal && convention, NULL); - const char *query = sdb_fmt ("cc.%s.error", convention); - const char *error = sdb_const_get (DB, query, 0); - return error? r_str_constpool_get (&anal->constpool, error): NULL; -} - -R_API void r_anal_cc_set_error(RAnal *anal, const char *convention, const char *error) { - if (!r_anal_cc_exist (anal, convention)) { - return; - } - RStrBuf sb; - sdb_set (anal->sdb_cc, r_strbuf_initf (&sb, "cc.%s.error", convention), error, 0); - r_strbuf_fini (&sb); -} - -R_API int r_anal_cc_max_arg(RAnal *anal, const char *cc) { - int i = 0; - r_return_val_if_fail (anal && DB && cc, 0); - static void *oldDB = NULL; - static char *oldCC = NULL; - static int oldArg = 0; - if (oldDB == DB && !strcmp (cc, oldCC)) { - return oldArg; - } - oldDB = DB; - free (oldCC); - oldCC = strdup (cc); - for (i = 0; i < R_ANAL_CC_MAXARG; i++) { - const char *query = sdb_fmt ("cc.%s.arg%d", cc, i); - const char *res = sdb_const_get (DB, query, 0); - if (!res) { - break; - } - } - oldArg = i; - return i; -} - -R_API const char *r_anal_cc_ret(RAnal *anal, const char *convention) { - r_return_val_if_fail (anal && convention, NULL); - char *query = sdb_fmt ("cc.%s.ret", convention); - return sdb_const_get (DB, query, 0); -} - -R_API const char *r_anal_cc_default(RAnal *anal) { - r_return_val_if_fail (anal, NULL); - return sdb_const_get (DB, "default.cc", 0); -} - -R_API const char *r_anal_cc_func(RAnal *anal, const char *func_name) { - r_return_val_if_fail (anal && func_name, NULL); - const char *query = sdb_fmt ("func.%s.cc", func_name); - const char *cc = sdb_const_get (anal->sdb_types, query, 0); - return cc ? cc : r_anal_cc_default (anal); -} diff --git a/libr/anal/cycles.c b/libr/anal/cycles.c deleted file mode 100644 index 76f4a948a6..0000000000 --- a/libr/anal/cycles.c +++ /dev/null @@ -1,23 +0,0 @@ -/* radare - LGPL - Copyright 2014-2020 - condret */ - -#include -#include -#include - -R_API RAnalCycleFrame *r_anal_cycle_frame_new(void) { - RAnalCycleFrame *cf = R_NEW0 (RAnalCycleFrame); - if (cf) { - if (!(cf->hooks = r_list_new ())) { - R_FREE (cf); - } - } - return cf; -} - -R_API void r_anal_cycle_frame_free(RAnalCycleFrame *cf) { - if (!cf) { - return; - } - r_list_free (cf->hooks); - free (cf); -} diff --git a/libr/anal/esil2reil.c b/libr/anal/esil2reil.c deleted file mode 100644 index 36bd2ad1c4..0000000000 --- a/libr/anal/esil2reil.c +++ /dev/null @@ -1,1263 +0,0 @@ -/* - * Convert from ESIL to REIL (Reverse Engineering Intermediate Language) - * Contributor: sushant94 - */ - -#include - -#define REIL_TEMP_PREFIX "V" -#define REIL_REG_PREFIX "R_" -#define REGBUFSZ 32 - -void reil_flag_spew_inst(RAnalEsil *esil, const char *flag); -static const char *ops[] = { FOREACHOP(REIL_OP_STRING) }; - -// Get size of a register. -static ut8 esil_internal_sizeof_reg(RAnalEsil *esil, const char *r) { - if (!esil || !esil->anal || !esil->anal->reg || !r) { - return false; - } - RRegItem *i = r_reg_get(esil->anal->reg, r, -1); - return i ? (ut8)i->size : 0; -} - -RAnalReilArgType reil_get_arg_type(RAnalEsil *esil, char *s) { - if (!strncmp (s, REIL_TEMP_PREFIX, strlen (REIL_TEMP_PREFIX))) { - return ARG_TEMP; - } - int type = r_anal_esil_get_parm_type(esil, s); - switch (type) { - case R_ANAL_ESIL_PARM_REG: - return ARG_REG; - case R_ANAL_ESIL_PARM_NUM: - return ARG_CONST; - default: - return ARG_NONE; - } -} - -// Marshall the struct into a string -void reil_push_arg(RAnalEsil *esil, RAnalReilArg *op) { - char *s = r_str_newf ("%s:%d", op->name, op->size); - r_anal_esil_push (esil, s); - free (s); -} - -// Unmarshall the string in stack to the struct. -RAnalReilArg *reil_pop_arg(RAnalEsil *esil) { - RAnalReilArg *op; - int i, j = 0, flag = 0, len; - char tmp_buf[REGBUFSZ]; - char *buf = r_anal_esil_pop(esil); - if (!buf) { - return NULL; - } - len = strlen (buf); - op = R_NEW0(RAnalReilArg); - for (i = 0; i < len; i++) { - if (buf[i] == ':') { - tmp_buf[j] = '\0'; - r_str_ncpy (op->name, tmp_buf, sizeof (op->name)); - memset (tmp_buf, 0, sizeof (tmp_buf)); - j = 0; - flag = 1; - continue; - } - // Strip all spaces - if (buf[i] == ' ') { - continue; - } - tmp_buf[j] = buf[i]; - j++; - } - tmp_buf[j] = '\0'; - - // If we have not encountered a ':' we don't know the size yet. - if (!flag) { - r_str_ncpy (op->name, tmp_buf, sizeof (op->name)); - op->type = reil_get_arg_type (esil, op->name); - if (op->type == ARG_REG) { - op->size = esil_internal_sizeof_reg(esil, op->name); - } else if (op->type == ARG_CONST) { - op->size = esil->anal->bits; - } - free(buf); - return op; - } - - op->size = strtoll(tmp_buf, NULL, 10); - op->type = reil_get_arg_type(esil, op->name); - free(buf); - return op; -} - -// Get the next available temp register. -void get_next_temp_reg(RAnalEsil *esil, char *buf) { - r_snprintf (buf, REGBUFSZ, REIL_TEMP_PREFIX"_%02"PFMT64u, - esil->Reil->reilNextTemp); - esil->Reil->reilNextTemp++; -} - -void reil_make_arg(RAnalEsil *esil, RAnalReilArg *arg, char *name) { - if (!arg) { - return; - } - RAnalReilArgType type = reil_get_arg_type (esil, name); - arg->size = 0; - arg->type = type; - r_str_ncpy (arg->name, name, sizeof (arg->name) - 1); -} - -// Free ins and all its arguments -void reil_free_inst(RAnalReilInst *ins) { - if (!ins) { - return; - } - if (ins->arg[0]) { R_FREE (ins->arg[0]); } - if (ins->arg[1]) { R_FREE (ins->arg[1]); } - if (ins->arg[2]) { R_FREE (ins->arg[2]); } - R_FREE(ins); -} - -// Automatically increments the seq_num of the instruction. -void reil_print_inst(RAnalEsil *esil, RAnalReilInst *ins) { - int i; - - if (!ins || !esil) { - return; - } - esil->anal->cb_printf("%04"PFMT64x".%02"PFMT64x": %8s", - esil->Reil->addr, esil->Reil->seq_num++, ops[ins->opcode]); - for (i = 0; i < 3; i++) { - if (i > 0) { - esil->anal->cb_printf (" ,"); - } - if (!ins->arg[i]) { - continue; - } - if (ins->arg[i]->type == ARG_NONE) { - esil->anal->cb_printf ("%10s ", ins->arg[i]->name); - continue; - } - if (ins->arg[i]->type == ARG_REG) { - char *tmp_buf = r_str_newf ("%s%s", REIL_REG_PREFIX, ins->arg[i]->name); - esil->anal->cb_printf ("%10s:%02d", tmp_buf, ins->arg[i]->size); - free (tmp_buf); - continue; - } - esil->anal->cb_printf ("%10s:%02d", ins->arg[i]->name, ins->arg[i]->size); - } - esil->anal->cb_printf("\n"); -} - -// Used to cast sizes during assignment. OR is used for casting. -// Pushes the new *casted* src onto stack. Warning: Frees the original src! -void reil_cast_size(RAnalEsil *esil, RAnalReilArg *src, RAnalReilArg *dst) { - char tmp_buf[REGBUFSZ]; - RAnalReilInst *ins; - - if (!src || !dst) { - return; - } - // No need to case sizes if dst and src are of same size. - if (src->size == dst->size) { - reil_push_arg(esil, src); - return; - } - snprintf (tmp_buf, REGBUFSZ-1, "0:%d", dst->size); - r_anal_esil_push (esil, tmp_buf); - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - return; - } - ins->opcode = REIL_OR; - ins->arg[0] = src; - ins->arg[1] = reil_pop_arg (esil); - ins->arg[2] = R_NEW0(RAnalReilArg); - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - if (ins->arg[2]) { - ins->arg[2]->size = dst->size; - } - reil_print_inst (esil, ins); - if (ins->arg[2]) { - reil_push_arg (esil, ins->arg[2]); - } - reil_free_inst (ins); -} - -// Here start translation functions! -static bool reil_eq(RAnalEsil *esil) { - RAnalReilInst *ins; - char tmp_buf[REGBUFSZ]; - RAnalReilArgType src_type, dst_type; - RAnalReilArg *dst, *src; - - dst = reil_pop_arg (esil); - if (!dst) { - return false; - } - src = reil_pop_arg (esil); - if (!src) { - R_FREE (dst); - return false; - } - - src_type = src->type; - // Check if the src is an internal var. If it is, we need to resolve it. - if (src_type == ARG_ESIL_INTERNAL) { - reil_flag_spew_inst (esil, src->name + 1); - R_FREE (src); - src = reil_pop_arg (esil); - } else if (src_type == ARG_REG) { - // No direct register to register transfer. - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - free (src); - free (dst); - return false; - } - ins->opcode = REIL_STR; - ins->arg[0] = src; - ins->arg[1] = R_NEW0 (RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0(RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - reil_make_arg (esil, ins->arg[1], " "); - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = ins->arg[0]->size; - reil_print_inst (esil, ins); - reil_push_arg( esil, ins->arg[2]); - reil_free_inst (ins); - src = reil_pop_arg (esil); - } - - // First, make a copy of the dst. We will need this to set the flags later on. - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (dst); - R_FREE (src); - return false; - } - dst_type = dst->type; - if (src_type != ARG_ESIL_INTERNAL && dst_type == ARG_REG) { - ins->opcode = REIL_STR; - ins->arg[0] = dst; - ins->arg[1] = R_NEW0 (RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - R_FREE (src); - return false; - } - ins->arg[2] = R_NEW0 (RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - R_FREE (src); - return false; - } - reil_make_arg (esil, ins->arg[1], " "); - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = ins->arg[0]->size; - reil_print_inst (esil, ins); - - // Used for setting the flags - r_snprintf (esil->Reil->old, sizeof (esil->Reil->old) - 1, "%s:%d", - ins->arg[2]->name, ins->arg[2]->size); - r_snprintf (esil->Reil->cur, sizeof (esil->Reil->cur) - 1, "%s:%d", dst->name, - dst->size); - esil->Reil->lastsz = dst->size; - - R_FREE (ins->arg[1]); - R_FREE (ins->arg[2]); - } - - // If we are modifying the Instruction Pointer, then we need to emit JCC instead. - if (!strcmp(esil->Reil->pc, dst->name)) { - ins->opcode = REIL_JCC; - r_anal_esil_push (esil, "1:1"); - ins->arg[0] = reil_pop_arg (esil); - ins->arg[1] = R_NEW0 (RAnalReilArg); - reil_make_arg (esil, ins->arg[1], " "); - ins->arg[2] = src; - reil_print_inst (esil, ins); - reil_free_inst (ins); - R_FREE (dst); - return true; - } - - reil_cast_size (esil, src, dst); - ins->opcode = REIL_STR; - ins->arg[0] = reil_pop_arg (esil); - if (!ins->arg[0]) { - R_FREE (dst); - reil_free_inst (ins); - return false; - } - - ins->arg[2] = dst; - ins->arg[1] = R_NEW0 (RAnalReilArg); - reil_make_arg (esil, ins->arg[1], " "); - reil_print_inst (esil, ins); - reil_free_inst (ins); - return true; -} - -// General function for operations that take 2 operands -static int reil_binop(RAnalEsil *esil, RAnalReilOpcode opcode) { - RAnalReilInst *ins; - char tmp_buf[REGBUFSZ]; - ut8 dst_size; - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg(esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg(esil); - if (!op1) { - R_FREE (op2); - return false; - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op1); - R_FREE (op2); - return false; - } - ins->opcode = opcode; - ins->arg[0] = op2; - ins->arg[1] = op1; - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0(RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - get_next_temp_reg(esil, tmp_buf); - reil_make_arg(esil, ins->arg[2], tmp_buf); - // Choose the larger of the two sizes as the size of dst - dst_size = ins->arg[0]->size; - if (dst_size < ins->arg[1]->size) { - dst_size = ins->arg[1]->size; - } - // REIL_LT has a dst_size of 1. - if (opcode == REIL_LT) { - dst_size = 1; - } - ins->arg[2]->size = dst_size; - reil_print_inst(esil, ins); - reil_push_arg(esil, ins->arg[2]); - reil_free_inst(ins); - return true; -} - -// General function for operations which re-assign to dst. Example, addeq. -static int reil_bineqop(RAnalEsil *esil, RAnalReilOpcode opcode) { - int ret = 1; - RAnalReilArg *op = reil_pop_arg(esil); - if (!op) { - return false; - } - - reil_push_arg(esil, op); - ret &= reil_binop(esil, opcode); - reil_push_arg(esil, op); - ret &= reil_eq(esil); - R_FREE(op); - return ret; -} - -static bool reil_add(RAnalEsil *esil) { return reil_binop (esil, REIL_ADD); } -static bool reil_addeq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_ADD); } -static bool reil_mul(RAnalEsil *esil) { return reil_binop (esil, REIL_MUL); } -static bool reil_muleq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_MUL); } -static bool reil_sub(RAnalEsil *esil) { return reil_binop (esil, REIL_SUB); } -static bool reil_subeq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_SUB); } -static bool reil_div(RAnalEsil *esil) { return reil_binop (esil, REIL_DIV); } -static bool reil_diveq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_DIV); } -static bool reil_xor(RAnalEsil *esil) { return reil_binop (esil, REIL_XOR); } -static bool reil_xoreq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_XOR); } -static bool reil_and(RAnalEsil *esil) { return reil_binop (esil, REIL_AND); } -static bool reil_andeq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_AND); } -static bool reil_or(RAnalEsil *esil) { return reil_binop (esil, REIL_OR); } -static bool reil_oreq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_OR); } -static bool reil_lsl(RAnalEsil *esil) { return reil_binop (esil, REIL_SHL); } -static bool reil_lsleq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_SHL); } -static bool reil_lsr(RAnalEsil *esil) { return reil_binop (esil, REIL_SHR); } -static bool reil_lsreq(RAnalEsil *esil) { return reil_bineqop (esil, REIL_SHR); } -static bool reil_smaller(RAnalEsil *esil) { return reil_binop (esil, REIL_LT); } - -static bool reil_cmp(RAnalEsil *esil) { - RAnalReilInst *ins; - char tmp_buf[REGBUFSZ]; - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg (esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg (esil); - if (!op1) { - R_FREE (op2); - return false; - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op1); - R_FREE (op2); - return false; - } - ins->opcode = REIL_EQ; - ins->arg[0] = op2; - ins->arg[1] = op1; - ins->arg[2] = R_NEW0 (RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = 1; - reil_print_inst (esil, ins); - // Set vars needed to determine flags. - r_snprintf (esil->Reil->cur, sizeof (esil->Reil->old) - 1, "%s:%d", - ins->arg[2]->name, ins->arg[2]->size); - r_snprintf (esil->Reil->old, sizeof (esil->Reil->cur) - 1, "%s:%d", - op2->name, op2->size); - if (r_reg_get (esil->anal->reg, op2->name, -1)) { - esil->Reil->lastsz = op2->size; - } else if (r_reg_get (esil->anal->reg, op1->name, -1)) { - esil->Reil->lastsz = op1->size; - } - reil_push_arg (esil, ins->arg[2]); - reil_free_inst (ins); - return true; -} - -static bool reil_smaller_equal(RAnalEsil *esil) { - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg(esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg(esil); - if (!op1) { - R_FREE (op2); - return false; - } - - reil_push_arg(esil, op1); - reil_push_arg(esil, op2); - reil_smaller(esil); - reil_push_arg(esil, op1); - reil_push_arg(esil, op2); - reil_cmp(esil); - reil_or(esil); - - R_FREE(op1); - R_FREE(op2); - return true; -} - -static bool reil_larger(RAnalEsil *esil) { - RAnalReilArg *op2 = reil_pop_arg(esil); - if (!op2) { - return false; - } - RAnalReilArg *op1 = reil_pop_arg(esil); - if (!op1) { - R_FREE (op2); - return false; - } - reil_push_arg (esil, op2); - reil_push_arg (esil, op1); - reil_smaller (esil); - R_FREE (op1); - R_FREE (op2); - return true; -} - -static bool reil_larger_equal(RAnalEsil *esil) { - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg(esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg(esil); - if (!op1) { - R_FREE (op2); - return false; - } - - reil_push_arg (esil, op2); - reil_push_arg (esil, op1); - reil_smaller_equal (esil); - R_FREE (op1); - R_FREE (op2); - return true; -} - -static bool reil_dec(RAnalEsil *esil) { - RAnalReilArg *op = reil_pop_arg(esil); - if (!op) { - return false; - } - r_anal_esil_pushnum (esil, 1); - reil_push_arg (esil, op); - reil_sub (esil); - R_FREE (op); - return true; -} - -static bool reil_deceq(RAnalEsil *esil) { - RAnalReilArg *op1 = reil_pop_arg(esil); - if (!op1) { - return false; - } - reil_push_arg (esil, op1); - reil_dec (esil); - reil_push_arg (esil, op1); - reil_eq (esil); - R_FREE (op1); - return true; -} - -static bool reil_inc(RAnalEsil *esil) { - RAnalReilArg *op = reil_pop_arg(esil); - if (!op) { - return false; - } - - r_anal_esil_pushnum(esil, 1); - reil_push_arg(esil, op); - reil_add(esil); - R_FREE(op); - return true; -} - -static bool reil_inceq(RAnalEsil *esil) { - RAnalReilArg *op = reil_pop_arg(esil); - if (!op) { - return false; - } - reil_push_arg (esil, op); - reil_inc (esil); - reil_push_arg (esil, op); - reil_eq (esil); - R_FREE (op); - return true; -} - -static bool reil_neg(RAnalEsil *esil) { - char tmp_buf[REGBUFSZ]; - RAnalReilInst *ins; - RAnalReilArg *op = reil_pop_arg (esil); - if (!op) { - return false; - } - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op); - return false; - } - ins->opcode = REIL_EQ; - ins->arg[0] = op; - r_anal_esil_pushnum (esil, 0); - ins->arg[1] = reil_pop_arg(esil); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0 (RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - get_next_temp_reg (esil, tmp_buf); - reil_make_arg(esil, ins->arg[2], tmp_buf); - if (ins->arg[0]->size < ins->arg[1]->size) { - ins->arg[1]->size = ins->arg[0]->size; - } - - ins->arg[2]->size = 1; - reil_print_inst (esil, ins); - reil_push_arg (esil, ins->arg[2]); - reil_free_inst (ins); - return true; -} - -static bool reil_negeq(RAnalEsil *esil) { - RAnalReilArg *op = reil_pop_arg(esil); - if (!op) { - return false; - } - reil_push_arg (esil, op); - reil_neg (esil); - reil_push_arg (esil, op); - reil_eq (esil); - free (op); - return true; -} - -static bool reil_not(RAnalEsil *esil) { - char tmp_buf[REGBUFSZ]; - RAnalReilInst *ins; - RAnalReilArg *op = reil_pop_arg (esil); - if (!op) { - return false; - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op); - return false; - } - ins->opcode = REIL_NOT; - ins->arg[0] = op; - ins->arg[1] = R_NEW0 (RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0 (RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - reil_make_arg (esil, ins->arg[1], " "); - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = ins->arg[0]->size; - reil_print_inst (esil, ins); - reil_push_arg (esil, ins->arg[2]); - reil_free_inst (ins); - return true; -} - -static bool reil_if(RAnalEsil *esil) { - RAnalReilInst *ins; - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg (esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg (esil); - if (!op1) { - R_FREE (op2); - return false; - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op2); - R_FREE (op1); - return false; - } - ins->opcode = REIL_JCC; - ins->arg[0] = op1; - ins->arg[2] = op2; - ins->arg[1] = R_NEW0 (RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - reil_make_arg (esil, ins->arg[1], " "); - reil_print_inst (esil, ins); - reil_free_inst (ins); - return true; -} - -static bool reil_if_end(RAnalEsil *esil) { return true; } - -static bool reil_peek(RAnalEsil *esil) { - RAnalReilInst *ins; - char tmp_buf[REGBUFSZ]; - RAnalReilArg *op1 = reil_pop_arg(esil); - if (!op1) { - return false; - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op1); - return false; - } - ins->opcode = REIL_LDM; - ins->arg[0] = op1; - ins->arg[1] = R_NEW0(RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0(RAnalReilArg); - if (!ins->arg[2]) { - reil_free_inst (ins); - return false; - } - reil_make_arg(esil, ins->arg[1], " "); - get_next_temp_reg(esil, tmp_buf); - reil_make_arg(esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = ins->arg[0]->size; - reil_print_inst(esil, ins); - reil_push_arg(esil, ins->arg[2]); - reil_free_inst(ins); - return true; -} - -// n = 8, 4, 2, 1 -static bool reil_peekn(RAnalEsil *esil, ut8 n) { - RAnalReilArg *op2; - RAnalReilArg *op1 = reil_pop_arg (esil); - if (!op1) { - return false; - } - - reil_push_arg (esil, op1); - reil_peek (esil); - // No need to cast if n = 0 - if (n == 0) { - R_FREE (op1); - return true; - } - - R_FREE (op1); - op1 = reil_pop_arg (esil); - if (!op1) { - return false; - } - - op2 = R_NEW0 (RAnalReilArg); - if (!op2) { - R_FREE (op1); - return false; - } - op2->size = n * 8; - op2->type = ARG_TEMP; - get_next_temp_reg (esil, op2->name); - reil_cast_size (esil, op1, op2); - esil->Reil->lastsz = 8 * n; - - R_FREE (op2); - return true; -} - -static bool reil_peek1(RAnalEsil *esil) { return reil_peekn(esil, 1); } -static bool reil_peek2(RAnalEsil *esil) { return reil_peekn(esil, 2); } -static bool reil_peek4(RAnalEsil *esil) { return reil_peekn(esil, 4); } -static bool reil_peek8(RAnalEsil *esil) { return reil_peekn(esil, 8); } - -// n = 8, 4, 2, 1 -static bool reil_poken(RAnalEsil *esil, ut8 n) { - char tmp_buf[REGBUFSZ]; - RAnalReilInst *ins; - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg (esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg (esil); - if (!op1) { - R_FREE (op2); - return false; - } - - if (op1->type != ARG_ESIL_INTERNAL) { - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - R_FREE (op2); - R_FREE (op1); - return false; - } - ins->opcode = REIL_LDM; - ins->arg[0] = op2; - ins->arg[1] = R_NEW0(RAnalReilArg); - if (!ins->arg[1]) { - R_FREE (op1); - reil_free_inst (ins); - return false; - } - ins->arg[2] = R_NEW0(RAnalReilArg); - if (!ins->arg[2]) { - R_FREE (op1); - reil_free_inst (ins); - return false; - } - reil_make_arg (esil, ins->arg[1], " "); - get_next_temp_reg (esil, tmp_buf); - reil_make_arg (esil, ins->arg[2], tmp_buf); - ins->arg[2]->size = ins->arg[0]->size; - reil_print_inst (esil, ins); - r_snprintf (esil->Reil->old, sizeof (esil->Reil->old) - 1, "%s:%d", - ins->arg[2]->name, ins->arg[2]->size); - r_snprintf (esil->Reil->cur, sizeof (esil->Reil->cur) - 1, "%s:%d", - op2->name, op2->size); - esil->lastsz = n * 8; - reil_push_arg (esil, op1); - reil_push_arg (esil, op2); - R_FREE (op1); - reil_free_inst (ins); - } else { - reil_flag_spew_inst (esil, op1->name + 1); - R_FREE (op1); - op1 = reil_pop_arg (esil); - reil_push_arg (esil, op2); - reil_push_arg (esil, op1); - R_FREE (op2); - R_FREE (op1); - } - - ins = R_NEW0 (RAnalReilInst); - if (!ins) { - return false; - } - ins->opcode = REIL_STM; - ins->arg[2] = reil_pop_arg (esil); - ins->arg[0] = reil_pop_arg (esil); - ins->arg[1] = R_NEW0 (RAnalReilArg); - if (!ins->arg[1]) { - reil_free_inst (ins); - return false; - } - reil_make_arg(esil, ins->arg[1], " "); - reil_print_inst(esil, ins); - reil_free_inst(ins); - return true; -} - -static bool reil_poke(RAnalEsil *esil) { - return reil_poken (esil, esil->anal->bits / 8); -} - -static bool reil_poke1(RAnalEsil *esil) { return reil_poken(esil, 1); } -static bool reil_poke2(RAnalEsil *esil) { return reil_poken(esil, 2); } -static bool reil_poke4(RAnalEsil *esil) { return reil_poken(esil, 4); } -static bool reil_poke8(RAnalEsil *esil) { return reil_poken(esil, 8); } - -// Generic function to handle all mem_*eq_n functions. Example, mem_oreq_n -static bool reil_mem_bineq_n(RAnalEsil *esil, RAnalReilOpcode opcode, ut8 size) { - int ret = 1; - RAnalReilArg *op2, *op1; - - op2 = reil_pop_arg (esil); - if (!op2) { - return false; - } - op1 = reil_pop_arg (esil); - if (!op1) { - R_FREE (op2); - return false; - } - - reil_push_arg(esil, op2); - ret &= reil_peekn(esil, size); - reil_push_arg(esil, op1); - ret &= reil_binop(esil, opcode); - reil_push_arg(esil, op2); - ret &= reil_poken(esil, size); - - free (op2); - free (op1); - return ret; -} - -static bool reil_mem_oreq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, esil->anal->bits / 8); } -static bool reil_mem_oreq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 1); } -static bool reil_mem_oreq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 2); } -static bool reil_mem_oreq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 4); } -static bool reil_mem_oreq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 8); } - -static bool reil_mem_andeq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, esil->anal->bits / 8); } -static bool reil_mem_andeq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 1); } -static bool reil_mem_andeq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 2); } -static bool reil_mem_andeq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 4); } -static bool reil_mem_andeq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 8); } - -static bool reil_mem_xoreq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, esil->anal->bits / 8); } -static bool reil_mem_xoreq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 1); } -static bool reil_mem_xoreq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 2); } -static bool reil_mem_xoreq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 4); } -static bool reil_mem_xoreq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 8); } - -static bool reil_mem_addeq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, esil->anal->bits / 8); } -static bool reil_mem_addeq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 1); } -static bool reil_mem_addeq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 2); } -static bool reil_mem_addeq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 4); } -static bool reil_mem_addeq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 8); } - -static bool reil_mem_subeq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, esil->anal->bits / 8); } -static bool reil_mem_subeq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 1); } -static bool reil_mem_subeq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 2); } -static bool reil_mem_subeq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 4); } -static bool reil_mem_subeq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 8); } - -static bool reil_mem_muleq(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, esil->anal->bits / 8); } -static bool reil_mem_muleq1(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 1); } -static bool reil_mem_muleq2(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 2); } -static bool reil_mem_muleq4(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 4); } -static bool reil_mem_muleq8(RAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 8); } - -static bool reil_mem_inceq_n(RAnalEsil *esil, ut8 size) { - int ret = 1; - RAnalReilArg *op1 = reil_pop_arg(esil); - if (!op1) { - return false; - } - - r_anal_esil_pushnum(esil, 1); - reil_push_arg(esil, op1); - ret &= reil_mem_bineq_n(esil, REIL_ADD, size); - - free (op1); - return ret; -} - -static bool reil_mem_inceq(RAnalEsil *esil) { - return reil_mem_inceq_n(esil, esil->anal->bits / 8); -} -static bool reil_mem_inceq1(RAnalEsil *esil) { return reil_mem_inceq_n(esil, 1); } -static bool reil_mem_inceq2(RAnalEsil *esil) { return reil_mem_inceq_n(esil, 2); } -static bool reil_mem_inceq4(RAnalEsil *esil) { return reil_mem_inceq_n(esil, 4); } -static bool reil_mem_inceq8(RAnalEsil *esil) { return reil_mem_inceq_n(esil, 8); } - -static int reil_mem_deceq_n(RAnalEsil *esil, ut8 size) { - int ret = 1; - RAnalReilArg *op1 = reil_pop_arg(esil); - if (!op1) { - return false; - } - - r_anal_esil_pushnum(esil, 1); - reil_push_arg(esil, op1); - ret &= reil_mem_bineq_n(esil, REIL_SUB, size); - - free (op1); - return ret; -} - -static bool reil_mem_deceq(RAnalEsil *esil) { - return reil_mem_deceq_n(esil, esil->anal->bits / 8); -} -static bool reil_mem_deceq1(RAnalEsil *esil) { return reil_mem_deceq_n(esil, 1); } -static bool reil_mem_deceq2(RAnalEsil *esil) { return reil_mem_deceq_n(esil, 2); } -static bool reil_mem_deceq4(RAnalEsil *esil) { return reil_mem_deceq_n(esil, 4); } -static bool reil_mem_deceq8(RAnalEsil *esil) { return reil_mem_deceq_n(esil, 8); } - -// Functions to resolve internal vars. -// performs (2 << op) - 1 -void reil_generate_mask(RAnalEsil *esil) { - r_anal_esil_pushnum(esil, 2); - reil_lsl(esil); - reil_dec(esil); -} - -void reil_generate_borrow_flag(RAnalEsil *esil, ut8 bit) { - RAnalReilArg *op1; - - r_anal_esil_pushnum(esil, bit); - r_anal_esil_pushnum(esil, 0x3f); - reil_and(esil); - r_anal_esil_pushnum(esil, 0x3f); - reil_add(esil); - r_anal_esil_pushnum(esil, 0x3f); - reil_and(esil); - // Generate the mask. 2 << bits - 1 - reil_generate_mask(esil); - op1 = reil_pop_arg(esil); - // old & mask - r_anal_esil_push(esil, esil->Reil->old); - reil_push_arg(esil, op1); - reil_and(esil); - // cur & mask - r_anal_esil_push(esil, esil->Reil->cur); - reil_push_arg(esil, op1); - reil_and(esil); - // Check - reil_larger(esil); - - free (op1); -} - -void reil_generate_carry_flag(RAnalEsil *esil, ut8 bit) { - RAnalReilArg *op1; - - r_anal_esil_pushnum(esil, bit); - r_anal_esil_pushnum(esil, 0x3f); - reil_and(esil); - // Generate the mask. 2 << bits - 1 - reil_generate_mask(esil); - op1 = reil_pop_arg(esil); - // old & mask - r_anal_esil_push(esil, esil->Reil->old); - reil_push_arg(esil, op1); - reil_and(esil); - // cur & mask - r_anal_esil_push(esil, esil->Reil->cur); - reil_push_arg(esil, op1); - reil_and(esil); - // Check - reil_smaller(esil); - - free (op1); -} - -void reil_generate_partity_flag(RAnalEsil *esil) { - // Generation of parity flag taken from openreil README example. - RAnalReilArg *op; - r_anal_esil_push(esil, esil->Reil->cur); - r_anal_esil_pushnum(esil, 0xff); - reil_and(esil); - op = reil_pop_arg(esil); - if (!op) { - return; - } - - r_anal_esil_pushnum(esil, 7); - reil_push_arg(esil, op); - reil_lsr(esil); - r_anal_esil_pushnum(esil, 6); - reil_push_arg(esil, op); - reil_lsr(esil); - reil_xor(esil); - r_anal_esil_pushnum(esil, 5); - reil_push_arg(esil, op); - reil_lsr(esil); - r_anal_esil_pushnum(esil, 4); - reil_push_arg(esil, op); - reil_lsr(esil); - reil_xor(esil); - reil_xor(esil); - r_anal_esil_pushnum(esil, 3); - reil_push_arg(esil, op); - reil_lsr(esil); - r_anal_esil_pushnum(esil, 2); - reil_push_arg(esil, op); - reil_lsr(esil); - reil_xor(esil); - r_anal_esil_pushnum(esil, 1); - reil_push_arg(esil, op); - reil_lsr(esil); - reil_push_arg(esil, op); - reil_xor(esil); - reil_xor(esil); - reil_xor(esil); - r_anal_esil_pushnum(esil, 1); - reil_and(esil); - reil_not(esil); - - free (op); -} - -void reil_generate_signature(RAnalEsil *esil) { - if (!esil->Reil->lastsz || esil->Reil->lastsz == 0) { - r_anal_esil_pushnum(esil, 0); - return; - } - - RAnalReilArg *op; - - r_anal_esil_pushnum(esil, esil->Reil->lastsz - 1); - r_anal_esil_pushnum(esil, 1); - reil_lsl(esil); - r_anal_esil_push(esil, esil->Reil->cur); - reil_and(esil); - - op = reil_pop_arg(esil); - if (!op) { - return; - } - - r_anal_esil_pushnum(esil, esil->Reil->lastsz - 1); - reil_push_arg(esil, op); - reil_lsr(esil); - - free (op); -} - -void reil_generate_overflow_flag(RAnalEsil *esil) { - if (esil->Reil->lastsz < 2) { - r_anal_esil_pushnum (esil, 0); - } - - reil_generate_borrow_flag(esil, esil->Reil->lastsz); - reil_generate_carry_flag(esil, esil->Reil->lastsz - 2); - reil_xor(esil); -} - -void reil_flag_spew_inst(RAnalEsil *esil, const char *flag) { - ut8 bit; - switch (flag[0]) { - case 'z': // zero-flag - r_anal_esil_push(esil, esil->Reil->cur); - break; - case 'b': - bit = (ut8)r_num_get(NULL, &flag[1]); - reil_generate_borrow_flag(esil, bit); - break; - case 'c': - bit = (ut8)r_num_get(NULL, &flag[1]); - reil_generate_carry_flag(esil, bit); - break; - case 'o': - reil_generate_overflow_flag(esil); - break; - case 'p': - reil_generate_partity_flag(esil); - break; - case 'r': - r_anal_esil_pushnum(esil, esil->anal->bits / 8); - break; - case 's': - reil_generate_signature(esil); - break; - default: - return; - } - - return; -} - -/* Callback hook for command_hook */ -static int setup_reil_ins(RAnalEsil *esil, const char *op) { - esil->Reil->addr++; // Increment the address location. - esil->Reil->seq_num = 0; // Reset the sequencing. - return 0; -} - -R_API int r_anal_esil_to_reil_setup(RAnalEsil *esil, RAnal *anal, int romem, - int stats) { - if (!esil) { - return false; - } - esil->verbose = 2; - esil->anal = anal; - esil->trap = 0; - esil->trap_code = 0; - - /* Set up a callback for hook_command */ - esil->cb.hook_command = setup_reil_ins; - - esil->Reil = R_NEW0(RAnalReil); - if (!esil->Reil) { - return false; - } - esil->Reil->reilNextTemp = 0; - esil->Reil->addr = -1; - esil->Reil->seq_num = 0; - esil->Reil->skip = 0; - - // Store the pc - const char *name = r_reg_get_name (esil->anal->reg, r_reg_get_name_idx ("PC")); - strncpy (esil->Reil->pc, name, sizeof (esil->Reil->pc) - 1); - - r_anal_esil_mem_ro(esil, romem); - -#define OT_UNK R_ANAL_ESIL_OP_TYPE_UNKNOWN -#define OT_CTR R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW -#define OT_MATH R_ANAL_ESIL_OP_TYPE_MATH -#define OT_REGW R_ANAL_ESIL_OP_TYPE_REG_WRITE -#define OT_MEMW R_ANAL_ESIL_OP_TYPE_MEM_WRITE -#define OT_MEMR R_ANAL_ESIL_OP_TYPE_MEM_READ - - r_anal_esil_set_op(esil, "=", reil_eq, 0, 2, OT_REGW); - r_anal_esil_set_op(esil, ":=", reil_eq, 0, 2, OT_REGW); - r_anal_esil_set_op(esil, "+", reil_add, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "+=", reil_addeq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "-", reil_sub, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "-=", reil_subeq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "*", reil_mul, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "*=", reil_muleq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "/", reil_div, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "/=", reil_diveq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "^", reil_xor, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "^=", reil_xoreq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "|", reil_or, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "|=", reil_oreq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "&", reil_and, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "&=", reil_andeq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "<<", reil_lsl, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "<<=", reil_lsleq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, ">>", reil_lsr, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, ">>=", reil_lsreq, 0, 2, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "++=", reil_inceq, 0, 1, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "++", reil_inc, 1, 1, OT_MATH); - r_anal_esil_set_op(esil, "--=", reil_deceq, 0, 1, OT_MATH | OT_REGW); - r_anal_esil_set_op(esil, "--", reil_dec, 1, 1, OT_MATH); - r_anal_esil_set_op(esil, "!", reil_neg, 1, 1, OT_MATH); - r_anal_esil_set_op(esil, "!=", reil_negeq, 0, 1, OT_MATH); - r_anal_esil_set_op(esil, "==", reil_cmp, 0, 2, OT_MATH); - r_anal_esil_set_op(esil, "<", reil_smaller, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, ">", reil_larger, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "<=", reil_smaller_equal, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, ">=", reil_larger_equal, 1, 2, OT_MATH); - r_anal_esil_set_op(esil, "[]", reil_peek, 1, 1, OT_MEMR); - r_anal_esil_set_op(esil, "=[]", reil_poke, 0, 2, OT_MEMW); - r_anal_esil_set_op(esil, "|=[]", reil_mem_oreq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "^=[]", reil_mem_xoreq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "&=[]", reil_mem_andeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "+=[]", reil_mem_addeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "-=[]", reil_mem_subeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "*=[]", reil_mem_muleq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "++=[]", reil_mem_inceq, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "--=[]", reil_mem_deceq, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "=[1]", reil_poke1, 0, 2, OT_MEMW); - r_anal_esil_set_op(esil, "=[2]", reil_poke2, 0, 2, OT_MEMW); - r_anal_esil_set_op(esil, "=[4]", reil_poke4, 0, 2, OT_MEMW); - r_anal_esil_set_op(esil, "=[8]", reil_poke8, 0, 2, OT_MEMW); - r_anal_esil_set_op(esil, "[1]", reil_peek1, 1, 1, OT_MEMR); - r_anal_esil_set_op(esil, "[2]", reil_peek2, 1, 1, OT_MEMR); - r_anal_esil_set_op(esil, "[4]", reil_peek4, 1, 1, OT_MEMR); - r_anal_esil_set_op(esil, "[8]", reil_peek8, 1, 1, OT_MEMR); - r_anal_esil_set_op(esil, "|=[1]", reil_mem_oreq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "|=[2]", reil_mem_oreq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "|=[4]", reil_mem_oreq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "|=[8]", reil_mem_oreq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "^=[1]", reil_mem_xoreq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "^=[2]", reil_mem_xoreq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "^=[4]", reil_mem_xoreq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "^=[8]", reil_mem_xoreq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "&=[1]", reil_mem_andeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "&=[2]", reil_mem_andeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "&=[4]", reil_mem_andeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "&=[8]", reil_mem_andeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "+=[1]", reil_mem_addeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "+=[2]", reil_mem_addeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "+=[4]", reil_mem_addeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "+=[8]", reil_mem_addeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "-=[1]", reil_mem_subeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "-=[2]", reil_mem_subeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "-=[4]", reil_mem_subeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "-=[8]", reil_mem_subeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "*=[1]", reil_mem_muleq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "*=[2]", reil_mem_muleq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "*=[4]", reil_mem_muleq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "*=[8]", reil_mem_muleq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "++=[1]", reil_mem_inceq1, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "++=[2]", reil_mem_inceq2, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "++=[4]", reil_mem_inceq4, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "++=[8]", reil_mem_inceq8, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "--=[1]", reil_mem_deceq1, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "--=[2]", reil_mem_deceq2, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "--=[4]", reil_mem_deceq4, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "--=[8]", reil_mem_deceq8, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); - r_anal_esil_set_op(esil, "?{", reil_if, 0, 1, OT_CTR); - r_anal_esil_set_op(esil, "}", reil_if_end, 0, 0, OT_CTR); - - return true; -} diff --git a/libr/anal/esil_dfg.c b/libr/anal/esil_dfg.c deleted file mode 100644 index 413e4a1939..0000000000 --- a/libr/anal/esil_dfg.c +++ /dev/null @@ -1,1100 +0,0 @@ -/* radare - LGPL - Copyright 2019 - condret */ - -//#include -#include -//#include -//#include - -typedef struct esil_dfg_reg_var_t { - ut32 from; - ut32 to; - RGraphNode *node; -} EsilDFGRegVar; - -typedef struct r_anal_esil_dfg_filter_t { - RAnalEsilDFG *dfg; - RContRBTree *tree; - Sdb *results; -} RAnalEsilDFGFilter; - -// TODO: simple const propagation - use node->type of srcs to propagate consts of pushed vars - -R_API RAnalEsilDFGNode *r_anal_esil_dfg_node_new(RAnalEsilDFG *edf, const char *c) { - RAnalEsilDFGNode *ret = R_NEW0 (RAnalEsilDFGNode); - ret->content = r_strbuf_new (c); - ret->idx = edf->idx++; - return ret; -} - -static void _dfg_node_free (RAnalEsilDFGNode *free_me) { - if (free_me) { - r_strbuf_free (free_me->content); - free (free_me); - } -} - -static int _rv_del_alloc_cmp (void *incoming, void *in, void *user) { - EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; - EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; - RAnalEsilDFG *dfg = (RAnalEsilDFG *)user; - - if (dfg->malloc_failed) { - return -1; - } - - // first handle the simple cases without intersection - if (rv_incoming->to < rv_in->from) { - return -1; - } - if (rv_in->to < rv_incoming->from) { - return 1; - } - if (rv_in->from == rv_incoming->from && rv_in->to == rv_incoming->to) { - return 0; - } - - /* - the following cases are about intersection, here some ascii-art, so you understand what I do - - =incoming= - =========in========= - - split in into 2 and reinsert the second half (in2) - shrink first half (in1) - - =incoming= - =in1= =in2= - */ - - if (rv_in->from < rv_incoming->from && rv_incoming->to < rv_in->to) { - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_in[0]; - rv_in->to = rv_incoming->from - 1; - rv->from = rv_incoming->to + 1; - dfg->insert = rv; - return 1; - } - - /* - =incoming= - =in= - - enqueue the non-intersecting ends in the todo-queue - */ - - if (rv_incoming->from < rv_in->from && rv_in->to < rv_incoming->to) { - // lower part - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->to = rv_in->from - 1; - r_queue_enqueue (dfg->todo, rv); - // upper part - rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->from = rv_in->to + 1; - r_queue_enqueue (dfg->todo, rv); - return 0; - } - - /* - =incoming= - =in= - - similar to the previous case, but this time only enqueue 1 half - */ - - if (rv_incoming->from == rv_in->from && rv_in->to < rv_incoming->to) { - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->from = rv_in->to + 1; - r_queue_enqueue (dfg->todo, rv); - return 0; - } - - /* - =incoming= - =in= - */ - - if (rv_incoming->from < rv_in->from && rv_in->to == rv_incoming->to) { - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->to = rv_in->from - 1; - r_queue_enqueue (dfg->todo, rv); - return 0; - } - - /* - =incoming= - ===in=== - - shrink in - - =incoming= - =in= - */ - - if (rv_in->to <= rv_incoming->to) { - rv_in->to = rv_incoming->from - 1; - return 1; - } - - /* - =incoming= - ===in=== - - up-shrink in - - =incoming= - ==in== - */ - - rv_in->from = rv_incoming->to + 1; - return -1; -} - -static int _rv_ins_cmp (void *incoming, void *in, void *user) { - EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; - EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; - return rv_incoming->from - rv_in->from; -} - -static bool _edf_reg_set (RAnalEsilDFG *dfg, const char *reg, RGraphNode *node) { - r_return_val_if_fail (dfg && !dfg->malloc_failed && reg, false); - const ut32 _reg_strlen = 4 + strlen (reg); - char *_reg = R_NEWS0 (char, _reg_strlen + 1); - if (!_reg) { - // no need for assert here, it's not a bug if malloc fails - return false; - } - strncat (_reg, "reg.", _reg_strlen); - strncat (_reg, reg, _reg_strlen); - if (!sdb_num_exists (dfg->regs, _reg)) { - //no assert to prevent memleaks - free (_reg); - return false; - } - EsilDFGRegVar *rv = R_NEW0 (EsilDFGRegVar); - if (!rv) { - free (_reg); - return false; - } - - const ut64 v = sdb_num_get (dfg->regs, _reg, NULL); - free (_reg); - rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; - rv->to = v & UT32_MAX; - r_queue_enqueue (dfg->todo, rv); - while (!r_queue_is_empty (dfg->todo) && !dfg->malloc_failed) { - // rbtree api does sadly not allow deleting multiple items at once :( - rv = r_queue_dequeue (dfg->todo); - r_rbtree_cont_delete (dfg->reg_vars, rv, _rv_del_alloc_cmp, dfg); - if (dfg->insert && !dfg->malloc_failed) { - r_rbtree_cont_insert (dfg->reg_vars, dfg->insert, _rv_ins_cmp, NULL); - dfg->insert = NULL; - } - free (rv); - } - if (dfg->malloc_failed) { - while (!r_queue_is_empty (dfg->todo)) { - free (r_queue_dequeue (dfg->todo)); - } - return false; - } - rv = R_NEW0 (EsilDFGRegVar); - rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; - rv->to = v & UT32_MAX; - rv->node = node; - r_rbtree_cont_insert (dfg->reg_vars, rv, _rv_ins_cmp, NULL); - return true; -} - -static int _rv_find_cmp (void *incoming, void *in, void *user) { - EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; - EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; - - RAnalEsilDFG *dfg = (RAnalEsilDFG *)user; - if (dfg->malloc_failed) { - return -1; - } - - // first handle the simple cases without intersection - if (rv_incoming->to < rv_in->from) { - return -1; - } - if (rv_in->to < rv_incoming->from) { - return 1; - } - - /* - =incoming= - =========in========= - */ - if (rv_in->from <= rv_incoming->from && rv_incoming->to <= rv_in->to) { - return 0; - } - - /* - =incoming= - =in= - - enqueue the non-intersecting ends in the todo-queue - */ - if (rv_incoming->from < rv_in->from && rv_in->to < rv_incoming->to) { - // lower part - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->to = rv_in->from - 1; - r_queue_enqueue (dfg->todo, rv); - // upper part - rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->from = rv_in->to + 1; - r_queue_enqueue (dfg->todo, rv); - return 0; - } - - /* - =incoming= - =in= - - similar to the previous case, but this time only enqueue 1 half - */ - if (rv_in->from <= rv_incoming->from && rv_in->to < rv_incoming->to) { - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->from = rv_in->to + 1; - r_queue_enqueue (dfg->todo, rv); - return 0; - } - - /* - =incoming= - =in= - */ - EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); - if (!rv) { - dfg->malloc_failed = true; - return -1; - } - rv[0] = rv_incoming[0]; - rv->to = rv_in->from - 1; - r_queue_enqueue (dfg->todo, rv); - return 0; -} - -static RGraphNode *_edf_origin_reg_get(RAnalEsilDFG *dfg, const char *reg) { - r_return_val_if_fail (dfg && reg, NULL); - const ut32 _reg_strlen = 4 + strlen (reg); - char *_reg = R_NEWS0 (char, _reg_strlen + 1); - if (!_reg) { - return NULL; - } - strncat (_reg, "reg.", _reg_strlen); - strncat (_reg, reg, _reg_strlen); - if (!sdb_num_exists (dfg->regs, _reg)) { - free (_reg); - return NULL; - } - free (_reg); - const ut32 origin_reg_strlen = 4 + strlen (reg); - char *origin_reg = R_NEWS0 (char, origin_reg_strlen + 1); - if (!origin_reg) { - return NULL; - } - strncat (origin_reg, "ori.", origin_reg_strlen); - strncat (origin_reg, reg, origin_reg_strlen); - RGraphNode *origin_reg_node = sdb_ptr_get (dfg->regs, origin_reg, 0); - if (origin_reg_node) { - free (origin_reg); - return origin_reg_node; - } - RGraphNode *reg_node = r_graph_add_node (dfg->flow, r_anal_esil_dfg_node_new (dfg, reg)); - RAnalEsilDFGNode *_origin_reg_node = r_anal_esil_dfg_node_new (dfg, reg); - r_strbuf_appendf (_origin_reg_node->content, ":var_%d", dfg->idx++); - _origin_reg_node->type = R_ANAL_ESIL_DFG_BLOCK_VAR; - origin_reg_node = r_graph_add_node (dfg->flow, _origin_reg_node); - r_graph_add_edge (dfg->flow, reg_node, origin_reg_node); - sdb_ptr_set (dfg->regs, origin_reg, origin_reg_node, 0); - free (origin_reg); - return origin_reg_node; -} - - -static RGraphNode *_edf_reg_get(RAnalEsilDFG *dfg, const char *reg) { - r_return_val_if_fail (dfg && reg, NULL); - const ut32 _reg_strlen = 4 + strlen (reg); - char *_reg = R_NEWS0 (char, _reg_strlen + 1); - if (!_reg) { - return NULL; - } - strncat (_reg, "reg.", _reg_strlen); - strncat (_reg, reg, _reg_strlen); - if (!sdb_num_exists (dfg->regs, _reg)) { - free (_reg); - return NULL; - } - EsilDFGRegVar *rv = R_NEW0 (EsilDFGRegVar); - if (!rv) { - free (_reg); - return NULL; - } - const ut64 v = sdb_num_get (dfg->regs, _reg, NULL); - free (_reg); - rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; - rv->to = v & UT32_MAX; - RQueue *parts = r_queue_new (8); - if (!parts) { - free (rv); - return NULL; - } - r_queue_enqueue (dfg->todo, rv); - - // log2((search_rv.to + 1) - search_rv.from) maybe better? - // wat du if this fails? - - RGraphNode *reg_node = NULL; - while (!r_queue_is_empty (dfg->todo)) { - rv = r_queue_dequeue (dfg->todo); - EsilDFGRegVar *part_rv = r_rbtree_cont_find (dfg->reg_vars, rv, _rv_find_cmp, dfg); - if (part_rv) { - r_queue_enqueue (parts, part_rv->node); - } else if (!reg_node) { - reg_node = _edf_origin_reg_get (dfg, reg); - //insert in the gap - part_rv = R_NEW (EsilDFGRegVar); - if (!part_rv) { - R_FREE (rv); - dfg->malloc_failed = true; - break; - } - part_rv[0] = rv[0]; - part_rv->node = reg_node; - r_rbtree_cont_insert (dfg->reg_vars, part_rv, _rv_ins_cmp, NULL); - //enqueue for later merge - r_queue_enqueue (parts, reg_node); - } else { - //initial regnode was already created - //only need to insert in the tree - part_rv = R_NEW (EsilDFGRegVar); - if (!part_rv) { - R_FREE (part_rv); - dfg->malloc_failed = true; - break; - } - part_rv[0] = rv[0]; - part_rv->node = reg_node; - r_rbtree_cont_insert (dfg->reg_vars, part_rv, _rv_ins_cmp, NULL); - } - free (rv); - } - reg_node = NULL; // is this needed? - if (dfg->malloc_failed) { - while (!r_queue_is_empty(dfg->todo)) { - free (r_queue_dequeue (dfg->todo)); - goto beach; - } - } - switch (parts->size) { - case 0: - break; - case 1: - reg_node = r_queue_dequeue (parts); - break; - default: - { - RAnalEsilDFGNode *_reg_node = r_anal_esil_dfg_node_new (dfg, "merge to "); - if (!_reg_node) { - while (!r_queue_is_empty (dfg->todo)) { - free (r_queue_dequeue (dfg->todo)); - } - dfg->malloc_failed = true; - goto beach; - } - - r_strbuf_appendf (_reg_node->content, "%s:var_%d", reg, dfg->idx++); - reg_node = r_graph_add_node (dfg->flow, _reg_node); - if (!reg_node) { - _dfg_node_free (_reg_node); - while (!r_queue_is_empty (dfg->todo)) { - free (r_queue_dequeue (dfg->todo)); - } - dfg->malloc_failed = true; - goto beach; - } - } - do { - r_graph_add_edge (dfg->flow, r_queue_dequeue(parts), reg_node); - } while (!r_queue_is_empty (parts)); - break; - } -beach: - r_queue_free (parts); - return reg_node; -} - - -static bool _edf_var_set (RAnalEsilDFG *dfg, const char *var, RGraphNode *node) { - r_return_val_if_fail (dfg && var, false); - const ut32 _var_strlen = 4 + strlen (var); - char *_var = R_NEWS0 (char, _var_strlen + 1); - if (!_var) { - return false; - } - strncat (_var, "var.", _var_strlen); - strncat (_var, var, _var_strlen); - const bool ret = !sdb_ptr_set (dfg->regs, _var, node, 0); - free (_var); - return ret; -} - - -static RGraphNode *_edf_var_get (RAnalEsilDFG *dfg, const char *var) { - r_return_val_if_fail (dfg && var, NULL); - const ut32 _var_strlen = 4 + strlen (var); - char *_var = R_NEWS0 (char, _var_strlen + 1); - if (!_var) { - return NULL; - } - strncat (_var, "var.", _var_strlen); - strncat (_var, var, _var_strlen); - RGraphNode *ret = sdb_ptr_get (dfg->regs, _var, NULL); - free (_var); - return ret; -} - -static bool edf_consume_2_set_reg(RAnalEsil *esil); -static bool edf_consume_2_push_1(RAnalEsil *esil); -static bool edf_consume_1_push_1(RAnalEsil *esil); -typedef void (*AddConstraintStringUseNewCB) (RStrBuf *result, const char *new_node_str); -static bool edf_use_new_push_1(RAnalEsil *esil, const char *op_string, AddConstraintStringUseNewCB cb); -typedef void (*AddConstraintStringConsume1UseOldNewCB) (RStrBuf *result, const char *consume_str, const char *old_node_str, const char *new_node_str); -static bool edf_consume_1_use_old_new_push_1(RAnalEsil *esil, const char *op_string, AddConstraintStringConsume1UseOldNewCB cb); - -static bool edf_eq_weak(RAnalEsil *esil) { - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - RGraphNode *o_old = edf->old; //node for esil->old - RGraphNode *o_new = edf->cur; //node for esil->cur - if (!edf_consume_2_set_reg (esil)) { - return false; - } - //work-around - edf->old = o_old ? o_old : NULL; - edf->cur = o_new ? o_new : NULL; - return true; -} - -static void edf_zf_constraint(RStrBuf *result, const char *new_node_str) { - r_strbuf_appendf (result, ":(%s==0)", new_node_str); -} - -static bool edf_zf(RAnalEsil *esil) { - return edf_use_new_push_1 (esil, "$z", edf_zf_constraint); -} - -static void edf_pf_constraint(RStrBuf *result, const char *new_node_str) { - r_strbuf_appendf (result, ":parity_of(%s)", new_node_str); -} - -static bool edf_pf(RAnalEsil *esil) { - return edf_use_new_push_1 (esil, "$p", edf_pf_constraint); -} - -static void edf_cf_constraint(RStrBuf *result, const char *consume, const char *o, const char *n) { - r_strbuf_appendf (result, ":((%s&mask(%s&0x3f))<(%s&mask(%s&0x3f)))", - n, consume, o, consume); -} - -static bool edf_cf(RAnalEsil *esil) { - return edf_consume_1_use_old_new_push_1 (esil, "$c", edf_cf_constraint); -} - -static void edf_bf_constraint(RStrBuf *result, const char *consume, const char *o, const char *n) { - r_strbuf_appendf (result, ":((%s&mask((%s+0x3f)&0x3f))<(%s& mask((%s+0x3f)&0x3f)))", - o, consume, n, consume); -} - -static bool edf_bf(RAnalEsil *esil) { - return edf_consume_1_use_old_new_push_1 (esil, "$b", edf_bf_constraint); -} - -static bool _edf_consume_2_set_reg(RAnalEsil *esil, const bool use_origin) { - const char *op_string = esil->current_opstr; - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - - if (!src || !dst) { - free (dst); - free (src); - return false; - } - - int dst_type = r_anal_esil_get_parm_type (esil, dst); - if (dst_type == R_ANAL_ESIL_PARM_INVALID) { - free (dst); - free (src); - return false; - } - - const int src_type = r_anal_esil_get_parm_type (esil, src); - RGraphNode *src_node = NULL; - if (src_type == R_ANAL_ESIL_PARM_REG) { - src_node = _edf_reg_get (edf, src); - } else if (src_type == R_ANAL_ESIL_PARM_NUM) { - RGraphNode *n_value = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, src)); - RAnalEsilDFGNode *ec_node = r_anal_esil_dfg_node_new (edf, src); - ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; - r_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); - src_node = r_graph_add_node (edf->flow, ec_node); - r_graph_add_edge (edf->flow, n_value, src_node); - } else { - src_node = _edf_var_get (edf, src); - } - - RGraphNode *dst_node = use_origin ? _edf_origin_reg_get (edf, dst) : _edf_reg_get (edf, dst); - RGraphNode *old_dst_node = dst_node; - - if (!src_node || !dst_node) { - free (src); - free (dst); - return false; - } - - RAnalEsilDFGNode *eop_node = r_anal_esil_dfg_node_new (edf, src); - r_strbuf_appendf (eop_node->content, ",%s,%s", dst, op_string); - eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; - free (src); - - RGraphNode *op_node = r_graph_add_node (edf->flow, eop_node); - r_graph_add_edge (edf->flow, dst_node, op_node); - r_graph_add_edge (edf->flow, src_node, op_node); - edf->old = old_dst_node; - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, dst); - result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_VAR; - - r_strbuf_appendf (result->content, ":var_%d", edf->idx++); - dst_node = r_graph_add_node (edf->flow, result); - r_graph_add_edge (edf->flow, op_node, dst_node); - _edf_reg_set (edf, dst, dst_node); - edf->cur = dst_node; - free (dst); - return true; -} - -static bool edf_consume_2_use_set_reg(RAnalEsil *esil) { - return _edf_consume_2_set_reg (esil, false); -} - -static bool edf_consume_2_set_reg(RAnalEsil *esil) { - return _edf_consume_2_set_reg (esil, true); -} - -static bool edf_consume_2_push_1(RAnalEsil *esil) { - const char *op_string = esil->current_opstr; - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - char *src[2] = { r_anal_esil_pop (esil), r_anal_esil_pop (esil) }; - - if (!src[0] || !src[1]) { - free (src[0]); - free (src[1]); - return false; - } - RAnalEsilDFGNode *eop_node = r_anal_esil_dfg_node_new (edf, src[1]); - r_strbuf_appendf (eop_node->content, ",%s,%s", src[0], op_string); - eop_node->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; - RGraphNode *op_node = r_graph_add_node (edf->flow, eop_node); - RGraphNode *src_node[2]; - ut32 i; - for (i = 0; i < 2; i++) { - const int src_type = r_anal_esil_get_parm_type (esil, src[i]); - if (src_type == R_ANAL_ESIL_PARM_REG) { - src_node[i] = _edf_reg_get (edf, src[i]); - } else if (src_type == R_ANAL_ESIL_PARM_NUM) { - RGraphNode *n_value = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, src[i])); - RAnalEsilDFGNode *ec_node = r_anal_esil_dfg_node_new (edf, src[i]); - ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; - r_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); - src_node[i] = r_graph_add_node (edf->flow, ec_node); - r_graph_add_edge (edf->flow, n_value, src_node[i]); - } else { - src_node[i] = _edf_var_get (edf, src[i]); - } - r_graph_add_edge (edf->flow, src_node[i], op_node); - } - - free (src[0]); - free (src[1]); - - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, "result_"); - result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; - r_strbuf_appendf (result->content, "%d", edf->idx++); - RGraphNode *result_node = r_graph_add_node (edf->flow, result); - r_graph_add_edge (edf->flow, op_node, result_node); - _edf_var_set (edf, r_strbuf_get (result->content), result_node); - r_anal_esil_push (esil, r_strbuf_get (result->content)); - return true; -} - -static bool edf_consume_1_push_1(RAnalEsil *esil) { - const char *op_string = esil->current_opstr; - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - char *src = r_anal_esil_pop (esil); - if (!src) { - return false; - } - RAnalEsilDFGNode *eop_node = r_anal_esil_dfg_node_new (edf, src); - r_strbuf_appendf (eop_node->content, ",%s", op_string); - eop_node->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; - RGraphNode *op_node = r_graph_add_node (edf->flow, eop_node); - const int src_type = r_anal_esil_get_parm_type (esil, src); - RGraphNode *src_node = NULL; - if (src_type == R_ANAL_ESIL_PARM_REG) { - src_node = _edf_reg_get (edf, src); - } else if (src_type == R_ANAL_ESIL_PARM_NUM) { - RGraphNode *n_value = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, src)); - RAnalEsilDFGNode *ec_node = r_anal_esil_dfg_node_new (edf, src); - ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; - r_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); - src_node = r_graph_add_node (edf->flow, ec_node); - r_graph_add_edge (edf->flow, n_value, src_node); - } else { - src_node = _edf_var_get (edf, src); - } - - free (src); - - r_graph_add_edge (edf->flow, src_node, op_node); - - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, "result_"); - result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; //TODO: propgate type from src here - r_strbuf_appendf (result->content, "%d", edf->idx++); - RGraphNode *result_node = r_graph_add_node (edf->flow, result); - r_graph_add_edge (edf->flow, op_node, result_node); - _edf_var_set (edf, r_strbuf_get (result->content), result_node); - r_anal_esil_push (esil, r_strbuf_get (result->content)); - return true; -} - -static bool edf_consume_2_set_mem(RAnalEsil *esil) { - const char *op_string = esil->current_opstr; - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - - if (!src || !dst) { - free (dst); - free (src); - return 0; - } - - int dst_type = r_anal_esil_get_parm_type (esil, dst); - - const int src_type = r_anal_esil_get_parm_type (esil, src); - RGraphNode *src_node = NULL; - if (src_type == R_ANAL_ESIL_PARM_REG) { - src_node = _edf_reg_get (edf, src); - } else if (src_type == R_ANAL_ESIL_PARM_NUM) { - RGraphNode *n_value = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, src)); - RAnalEsilDFGNode *ec_node = r_anal_esil_dfg_node_new (edf, src); - ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; - r_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); - src_node = r_graph_add_node (edf->flow, ec_node); - r_graph_add_edge (edf->flow, n_value, src_node); - } else { - src_node = _edf_var_get (edf, src); - } - - RGraphNode *dst_node = _edf_reg_get (edf, dst); - if (!dst_node) { - dst_node = _edf_var_get (edf, dst); - } -//probably dead code - if (!dst_node) { - if (dst_type == R_ANAL_ESIL_PARM_REG) { - RGraphNode *n_reg = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, dst)); - RAnalEsilDFGNode *ev_node = r_anal_esil_dfg_node_new (edf, dst); - ev_node->type = R_ANAL_ESIL_DFG_BLOCK_VAR | R_ANAL_ESIL_DFG_BLOCK_PTR; - r_strbuf_appendf (ev_node->content, ":var_ptr_%d", edf->idx++); - dst_node = r_graph_add_node (edf->flow, ev_node); - // _edf_reg_set (edf, dst, ev_node); - r_graph_add_edge (edf->flow, n_reg, dst_node); - } - // TODO: const pointers - } - - if (!src_node || !dst_node) { - free (src); - free (dst); - return false; - } - - RAnalEsilDFGNode *eop_node = r_anal_esil_dfg_node_new (edf, src); - r_strbuf_appendf (eop_node->content, ",%s,%s", dst, op_string); - eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; - free (src); - - RGraphNode *op_node = r_graph_add_node (edf->flow, eop_node); - r_graph_add_edge (edf->flow, dst_node, op_node); - r_graph_add_edge (edf->flow, src_node, op_node); - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, dst); - // result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; - result->type = R_ANAL_ESIL_DFG_BLOCK_VAR; - r_strbuf_appendf (result->content, ":var_mem_%d", edf->idx++); - dst_node = r_graph_add_node (edf->flow, result); - r_graph_add_edge (edf->flow, op_node, dst_node); - free (dst); - return true; -} - -static bool edf_use_new_push_1(RAnalEsil *esil, const char *op_string, AddConstraintStringUseNewCB cb) { - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - RGraphNode *op_node = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, op_string)); - RGraphNode *latest_new = edf->cur; - if (!latest_new) { - return 0; - } - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, "result_"); - result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; // is this generative? - r_strbuf_appendf (result->content, "%d", edf->idx++); - if (cb) { - RAnalEsilDFGNode *e_new_node = (RAnalEsilDFGNode *)latest_new->data; - cb (result->content, r_strbuf_get (e_new_node->content)); - } - RGraphNode *result_node = r_graph_add_node (edf->flow, result); - _edf_var_set (edf, r_strbuf_get (result->content), result_node); - r_graph_add_edge (edf->flow, latest_new, op_node); - r_graph_add_edge (edf->flow, op_node, result_node); - return r_anal_esil_push (esil, r_strbuf_get (result->content)); -} - -static bool edf_consume_1_use_old_new_push_1(RAnalEsil *esil, const char *op_string, AddConstraintStringConsume1UseOldNewCB cb) { - RAnalEsilDFG *edf = (RAnalEsilDFG *)esil->user; - char *src = r_anal_esil_pop (esil); - - if (!src) { - return false; - } - RAnalEsilDFGNode *eop_node = r_anal_esil_dfg_node_new (edf, src); -#if 0 - eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; -#endif - r_strbuf_appendf (eop_node->content, ",%s", op_string); - RGraphNode *op_node = r_graph_add_node (edf->flow, eop_node); - const int src_type = r_anal_esil_get_parm_type (esil, src); - RGraphNode *src_node = NULL; - if (src_type == R_ANAL_ESIL_PARM_REG) { - src_node = _edf_reg_get (edf, src); - } else if (src_type == R_ANAL_ESIL_PARM_NUM) { - RGraphNode *n_value = r_graph_add_node (edf->flow, r_anal_esil_dfg_node_new (edf, src)); - RAnalEsilDFGNode *ec_node = r_anal_esil_dfg_node_new (edf, src); - ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; - r_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); - src_node = r_graph_add_node (edf->flow, ec_node); - r_graph_add_edge (edf->flow, n_value, src_node); - } else { - src_node = _edf_var_get (edf, src); - } - free (src); - - r_graph_add_edge (edf->flow, src_node, op_node); - - RGraphNode *latest_new = edf->cur; - RGraphNode *latest_old = edf->old; - RAnalEsilDFGNode *result = r_anal_esil_dfg_node_new (edf, "result_"); - result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; // propagate type here - r_strbuf_appendf (result->content, "%d", edf->idx++); - if (cb) { - RAnalEsilDFGNode *e_src_node = (RAnalEsilDFGNode *)src_node->data; - RAnalEsilDFGNode *e_new_node = (RAnalEsilDFGNode *)latest_new->data; - RAnalEsilDFGNode *e_old_node = (RAnalEsilDFGNode *)latest_old->data; - cb (result->content, r_strbuf_get (e_src_node->content), - r_strbuf_get (e_new_node->content), r_strbuf_get (e_old_node->content)); - } - RGraphNode *result_node = r_graph_add_node (edf->flow, result); - _edf_var_set (edf, r_strbuf_get (result->content), result_node); - r_graph_add_edge (edf->flow, latest_new, op_node); - r_graph_add_edge (edf->flow, latest_old, op_node); - r_graph_add_edge (edf->flow, op_node, result_node); - return r_anal_esil_push (esil, r_strbuf_get (result->content)); -} - -R_API RAnalEsilDFG *r_anal_esil_dfg_new(RReg *regs) { - if (!regs) { - return NULL; - } - RAnalEsilDFG *dfg = R_NEW0 (RAnalEsilDFG); - if (!dfg) { - return NULL; - } - dfg->flow = r_graph_new (); - if (!dfg->flow) { - free (dfg); - return NULL; - } - dfg->regs = sdb_new0 (); - if (!dfg->regs) { - r_graph_free (dfg->flow); - free (dfg); - return NULL; - } - // rax, eax, ax, ah, al => 8 should be enough - dfg->todo = r_queue_new (8); - if (!dfg->todo) { - sdb_free (dfg->regs); - r_graph_free (dfg->flow); - free (dfg); - return NULL; - } - dfg->reg_vars = r_rbtree_cont_newf (free); - if (!dfg->reg_vars) { - r_queue_free (dfg->todo); - sdb_free (dfg->regs); - r_graph_free (dfg->flow); - free (dfg); - return NULL; - } - -// this is not exactly necessary -// could use RReg-API directly in the dfg gen, -// but sdb as transition table is probably faster - RRegItem *ri; - RListIter *ator; - r_list_foreach (regs->allregs, ator, ri) { - const ut32 from = ri->offset; - const ut32 to = from + ri->size - 1; // closed intervals because of FUCK YOU - const ut64 v = to | (((ut64)from) << 32); - const ut32 reg_strlen = 4 + strlen (ri->name) + 1; - char *reg = R_NEWS0 (char, reg_strlen); - strncat (reg, "reg.", reg_strlen); - strncat (reg, ri->name, reg_strlen); - sdb_num_set (dfg->regs, reg, v, 0); - free (reg); - } - return dfg; -} - -R_API void r_anal_esil_dfg_free(RAnalEsilDFG *dfg) { - if (dfg) { - if (dfg->flow) { - RGraphNode *n; - RListIter *iter; - r_list_foreach (r_graph_get_nodes (dfg->flow), iter, n) { - n->free = (RListFree)_dfg_node_free; - } - r_graph_free (dfg->flow); - } - sdb_free (dfg->regs); - r_rbtree_cont_free (dfg->reg_vars); - r_queue_free (dfg->todo); - free (dfg); - } -} - -R_API RAnalEsilDFG *r_anal_esil_dfg_expr(RAnal *anal, RAnalEsilDFG *dfg, const char *expr) { - if (!expr) { - return NULL; - } - RAnalEsil *esil = r_anal_esil_new (4096, 0, 1); - if (!esil) { - return NULL; - } - esil->anal = anal; - - RAnalEsilDFG *edf = dfg ? dfg : r_anal_esil_dfg_new (anal->reg); - if (!edf) { - r_anal_esil_free (esil); - return NULL; - } - - r_anal_esil_set_op (esil, "=", edf_consume_2_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, ":=", edf_eq_weak, 0, 2, R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "$z", edf_zf, 1, 0, R_ANAL_ESIL_OP_TYPE_UNKNOWN); - r_anal_esil_set_op (esil, "$p", edf_pf, 1, 0, R_ANAL_ESIL_OP_TYPE_UNKNOWN); - r_anal_esil_set_op (esil, "$c", edf_cf, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); - r_anal_esil_set_op (esil, "$b", edf_bf, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); - r_anal_esil_set_op (esil, "^=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "-=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "+=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "*=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "/=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "&=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "|=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "^=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); - r_anal_esil_set_op (esil, "+", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "-", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "&", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "|", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "^", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "%", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "*", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "/", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, ">>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "<<", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, ">>>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, ">>>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "!", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MATH); - r_anal_esil_set_op (esil, "[1]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); - r_anal_esil_set_op (esil, "[2]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); - r_anal_esil_set_op (esil, "[4]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); - r_anal_esil_set_op (esil, "[8]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); - r_anal_esil_set_op (esil, "[16]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); - r_anal_esil_set_op (esil, "=[1]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); - r_anal_esil_set_op (esil, "=[2]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); - r_anal_esil_set_op (esil, "=[4]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); - r_anal_esil_set_op (esil, "=[8]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); - - esil->user = edf; - - r_anal_esil_parse (esil, expr); - r_anal_esil_free (esil); - return edf; -} - -static int _dfg_node_filter_insert_cmp(void *incoming, void *in, void *user) { - RAnalEsilDFGNode *incoming_node = (RAnalEsilDFGNode *)incoming; - RAnalEsilDFGNode *in_node = (RAnalEsilDFGNode *)in; - return incoming_node->idx - in_node->idx; -} - -static void _dfg_rev_dfs_cb(RGraphNode *n, RGraphVisitor *vi) { - RAnalEsilDFGNode *node = (RAnalEsilDFGNode *)n->data; - RAnalEsilDFGFilter *filter = (RAnalEsilDFGFilter *)vi->data; - switch (node->type) { - case R_ANAL_ESIL_DFG_BLOCK_CONST: - case R_ANAL_ESIL_DFG_BLOCK_VAR: - case R_ANAL_ESIL_DFG_BLOCK_PTR: - break; - case R_ANAL_ESIL_DFG_BLOCK_GENERATIVE: - r_rbtree_cont_insert (filter->tree, node, _dfg_node_filter_insert_cmp, NULL); - break; - case R_ANAL_ESIL_DFG_BLOCK_RESULT: // outnode must be result generator here - { - RGraphNode *previous = (RGraphNode *)r_list_get_top (n->in_nodes); - if (previous) { - sdb_ptr_set (filter->results, r_strbuf_get (node->content), previous, 0); - } - } break; - } -} - -static char *condrets_strtok(char *str, const char tok) { - if (!str) { - return NULL; - } - ut32 i = 0; - while (1 == 1) { - if (!str[i]) { - break; - } - if (str[i] == tok) { - str[i] = '\0'; - return &str[i + 1]; - } - i++; - } - return NULL; -} - -static RStrBuf *get_resolved_expr(RAnalEsilDFGFilter *filter, RAnalEsilDFGNode *node) { - char *expr = strdup (r_strbuf_get (node->content)); - RStrBuf *res = r_strbuf_new (""); - if (!expr) { //empty expressions. can this happen? - return res; - } - char *p, *q; - // we can do this bc every generative node MUST end with an operator - for (p = expr; (q = condrets_strtok (p, ',')); p = q) { - RGraphNode *gn = sdb_ptr_get (filter->results, p, 0); - if (!gn) { - r_strbuf_appendf (res, ",%s,", p); - } else { - RStrBuf *r = get_resolved_expr (filter, (RAnalEsilDFGNode *)gn->data); - r_strbuf_appendf (res, ",%s,", r_strbuf_get (r)); - r_strbuf_free (r); - } - } - r_strbuf_appendf (res, "%s", p); - free (expr); - return res; -} - -R_API RStrBuf *r_anal_esil_dfg_filter(RAnalEsilDFG *dfg, const char *reg) { - if (!dfg || !reg) { - return NULL; - } - RGraphNode *resolve_me = _edf_reg_get (dfg, reg); - if (!resolve_me) { - return NULL; - } - - // allocate stuff - RAnalEsilDFGFilter filter = { dfg, r_rbtree_cont_new (), sdb_new0 () }; - RStrBuf *filtered = r_strbuf_new (""); - RGraphVisitor vi = { _dfg_rev_dfs_cb, NULL, NULL, NULL, NULL, &filter }; - - // dfs the graph starting at node of esp-register - r_graph_dfs_node_reverse (dfg->flow, resolve_me, &vi); - - RBIter ator; - RAnalEsilDFGNode *node; - r_rbtree_cont_foreach (filter.tree, ator, node) { - // resolve results to opstr here - RStrBuf *resolved = get_resolved_expr (&filter, node); - r_strbuf_append (filtered, r_strbuf_get (resolved)); - r_strbuf_free (resolved); - } - { - char *sanitized = r_str_replace (r_str_replace (strdup (r_strbuf_get (filtered)), ",,", ",", 1), ",,", ",", 1); - r_strbuf_set (filtered, (sanitized[0] == ',') ? &sanitized[1] : sanitized); - free (sanitized); - } - r_rbtree_cont_free (filter.tree); - sdb_free (filter.results); - return filtered; -} - -R_API RStrBuf *r_anal_esil_dfg_filter_expr(RAnal *anal, const char *expr, const char *reg) { - if (!reg) { - return NULL; - } - RAnalEsilDFG *dfg = r_anal_esil_dfg_expr (anal, NULL, expr); - if (!dfg) { - return NULL; - } - RStrBuf *filtered = r_anal_esil_dfg_filter (dfg, reg); - r_anal_esil_dfg_free (dfg); - return filtered; -} diff --git a/libr/anal/esil_interrupt.c b/libr/anal/esil_interrupt.c deleted file mode 100644 index 59745be418..0000000000 --- a/libr/anal/esil_interrupt.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#include - -static void _interrupt_free_cb(void *user) { - RAnalEsilInterrupt *intr = (RAnalEsilInterrupt *)user; - if (intr && intr->handler && intr->handler->fini) { - intr->handler->fini (intr->user); - } - free (intr); -} - -static bool _set_interrupt(RAnalEsil *esil, RAnalEsilInterrupt *intr) { - return intr->handler->num ? - dict_set (esil->interrupts, intr->handler->num, intr->handler->num, intr) : - (esil->intr0 = intr, true); -} - -static RAnalEsilInterrupt *_get_interrupt(RAnalEsil *esil, ut32 intr_num) { - return intr_num ? - (RAnalEsilInterrupt *)dict_getu(esil->interrupts, intr_num) : - esil->intr0; -} - -static void _del_interrupt(RAnalEsil *esil, ut32 intr_num) { - if (intr_num) { - dict_del (esil->interrupts, intr_num); - } else { - esil->intr0 = NULL; - } -} - -R_API void r_anal_esil_interrupts_init(RAnalEsil *esil) { - r_return_if_fail (esil); - esil->interrupts = dict_new (sizeof (ut32), NULL); - esil->intr0 = NULL; // is this needed? -} - -R_API RAnalEsilInterrupt *r_anal_esil_interrupt_new(RAnalEsil *esil, ut32 src_id, RAnalEsilInterruptHandler *ih) { - r_return_val_if_fail (esil && ih && ih->cb, NULL); - RAnalEsilInterrupt *intr = R_NEW0 (RAnalEsilInterrupt); - if (!intr) { - return NULL; - } - intr->handler = ih; - if (ih->init && ih->fini) { - intr->user = ih->init (esil); - } - intr->src_id = src_id; - r_anal_esil_claim_source (esil, src_id); - return intr; -} - -R_API void r_anal_esil_interrupt_free(RAnalEsil *esil, RAnalEsilInterrupt *intr) { - if (intr && esil) { - _del_interrupt (esil, intr->handler->num); - } - if (intr) { - if (intr->user) { - intr->handler->fini (intr->user); //fini must exist when user is !NULL - } - r_anal_esil_release_source (esil, intr->src_id); - } - free (intr); -} - -R_API bool r_anal_esil_set_interrupt(RAnalEsil *esil, RAnalEsilInterrupt *intr) { - r_return_val_if_fail (esil && esil->interrupts && intr && intr->handler && intr->handler->cb, false); - // check if interrupt is already set - RAnalEsilInterrupt *o_intr = _get_interrupt(esil, intr->handler->num); - if (o_intr) { - r_anal_esil_interrupt_free (esil, o_intr); - } - //set the new interrupt - return _set_interrupt(esil, intr); -} - -R_API int r_anal_esil_fire_interrupt(RAnalEsil *esil, ut32 intr_num) { - r_return_val_if_fail (esil, false); - - if (esil->cmd && esil->cmd (esil, esil->cmd_intr, intr_num, 0)) { //compatibility - return true; - } - - if (!esil->interrupts) { - eprintf ("no interrupts initialized\n"); - return false; - } - RAnalEsilInterrupt *intr = _get_interrupt (esil, intr_num); -#if 0 - // we don't want this warning - if (!intr) { - eprintf ("Warning no interrupt handler registered for 0x%x\n", intr_num); - } -#endif - return (intr && intr->handler && intr->handler->cb) ? - intr->handler->cb (esil, intr_num, intr->user) : false; -} - -R_API bool r_anal_esil_load_interrupts (RAnalEsil *esil, RAnalEsilInterruptHandler *handlers[], ut32 src_id) { - RAnalEsilInterrupt *intr; - ut32 i = 0; - - r_return_val_if_fail (esil && esil->interrupts && handlers, false); - - while (handlers[i]) { - intr = _get_interrupt (esil, handlers[i]->num); - if (intr) { - //first free, then load the new handler or stuff might break in the handlers - r_anal_esil_interrupt_free (esil, intr); - } - intr = r_anal_esil_interrupt_new (esil, src_id, handlers[i]); - if (!intr) { - return false; - } - r_anal_esil_set_interrupt (esil, intr); - i++; - } - - return true; -} - -R_API bool r_anal_esil_load_interrupts_from_lib(RAnalEsil *esil, const char *path) { - r_return_val_if_fail (esil, false); - ut32 src_id = r_anal_esil_load_source (esil, path); - if (!src_id) { // why id=0 is invalid? - return false; - } - RAnalEsilInterruptHandler **handlers = (RAnalEsilInterruptHandler **)\ - r_lib_dl_sym (r_anal_esil_get_source (esil, src_id), "interrupts"); - if (!handlers) { - r_anal_esil_release_source (esil, src_id); //unload - return false; - } - return r_anal_esil_load_interrupts (esil, handlers, src_id); -} - -R_API void r_anal_esil_interrupts_fini(RAnalEsil *esil) { - if (esil && esil->interrupts) { - _interrupt_free_cb (esil->intr0); - esil->intr0 = NULL; - esil->interrupts->f = _interrupt_free_cb; - dict_free (esil->interrupts); - esil->interrupts = NULL; - } -} diff --git a/libr/anal/esil_sources.c b/libr/anal/esil_sources.c deleted file mode 100644 index 26e60a460e..0000000000 --- a/libr/anal/esil_sources.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include - -R_API void r_anal_esil_sources_init (RAnalEsil *esil) { - if (esil && !esil->sources) { - esil->sources =r_id_storage_new (1, 0xffffffff); //0 is reserved for stuff from plugins - } -} - -R_API ut32 r_anal_esil_load_source(RAnalEsil *esil, const char *path) { - RAnalEsilSource *src; - - if (!esil) { - eprintf ("no esil?\n"); - return 0; - } - - src = R_NEW0 (RAnalEsilSource); - src->content = r_lib_dl_open(path); - if (!src->content) { - eprintf ("no content\n"); - free (src); - return 0; - } - - r_anal_esil_sources_init (esil); - if (!r_id_storage_add(esil->sources, src, &src->id)) { - eprintf ("cannot add to storage\n"); - r_lib_dl_close (src->content); - free (src); - return 0; - } - - return src->id; -} - -static RAnalEsilSource *_get_source(RAnalEsil *esil, ut32 src_id) { - if (!esil || !esil->sources) { - return NULL; - } - return (RAnalEsilSource *)r_id_storage_get (esil->sources, src_id); -} - -R_API void *r_anal_esil_get_source(RAnalEsil *esil, ut32 src_id) { - RAnalEsilSource *src = _get_source(esil, src_id); - - return src ? src->content : NULL; -} - -R_API bool r_anal_esil_claim_source(RAnalEsil *esil, ut32 src_id) { - RAnalEsilSource *src = _get_source(esil, src_id); - - if (src) { - src->claimed++; - return true; - } - return false; -} - -R_API void r_anal_esil_release_source(RAnalEsil *esil, ut32 src_id) { - RAnalEsilSource *src = _get_source(esil, src_id); - - if (!src) { - return; - } - if (src->claimed <= 1) { - r_id_storage_delete (esil->sources, src_id); - r_lib_dl_close (src->content); - free (src); - } else { - src->claimed--; - } -} - -static bool _free_source_cb(void *user, void *data, ut32 id) { - RAnalEsilSource *src = (RAnalEsilSource *)data; - - if (src) { - r_lib_dl_close (src->content); - } - free (src); - return true; -} - -R_API void r_anal_esil_sources_fini(RAnalEsil *esil) { - if (esil) { - r_id_storage_foreach(esil->sources, _free_source_cb, NULL); - r_id_storage_free(esil->sources); - } -} diff --git a/libr/anal/rtti.c b/libr/anal/rtti.c deleted file mode 100644 index fa7c1f5445..0000000000 --- a/libr/anal/rtti.c +++ /dev/null @@ -1,99 +0,0 @@ -/* radare - LGPL - Copyright 2009-2018 - pancake, maijin, thestr4ng3r */ - -#include "r_anal.h" - -R_API char *r_anal_rtti_demangle_class_name(RAnal *anal, const char *name) { - RVTableContext context; - r_anal_vtable_begin (anal, &context); - if (context.abi == R_ANAL_CPP_ABI_MSVC) { - return r_anal_rtti_msvc_demangle_class_name (&context, name); - } - return r_anal_rtti_itanium_demangle_class_name (&context, name); -} - -R_API void r_anal_rtti_print_at_vtable(RAnal *anal, ut64 addr, int mode) { - bool use_json = mode == 'j'; - if (use_json) { - r_cons_print ("["); - } - - RVTableContext context; - r_anal_vtable_begin (anal, &context); - if (context.abi == R_ANAL_CPP_ABI_MSVC) { - r_anal_rtti_msvc_print_at_vtable (&context, addr, mode, false); - } else { - r_anal_rtti_itanium_print_at_vtable (&context, addr, mode); - } - - if (use_json) { - r_cons_print ("]\n"); - } -} - -R_API void r_anal_rtti_print_all(RAnal *anal, int mode) { - RVTableContext context; - r_anal_vtable_begin (anal, &context); - - bool use_json = mode == 'j'; - if (use_json) { - r_cons_print ("["); - } - - r_cons_break_push (NULL, NULL); - RList *vtables = r_anal_vtable_search (&context); - RListIter *vtableIter; - RVTableInfo *table; - - if (vtables) { - bool comma = false; - bool success = false; - r_list_foreach (vtables, vtableIter, table) { - if (r_cons_is_breaked ()) { - break; - } - if (use_json && success) { - r_cons_print (","); - comma = true; - } - if (context.abi == R_ANAL_CPP_ABI_MSVC) { - success = r_anal_rtti_msvc_print_at_vtable (&context, table->saddr, mode, true); - } else { - success = r_anal_rtti_itanium_print_at_vtable (&context, table->saddr, mode); - } - if (success) { - comma = false; - if (!use_json) { - r_cons_print ("\n"); - } - } - } - if (use_json && !success && comma) { - // drop last comma if necessary - r_cons_drop (1); - } - } - r_list_free (vtables); - - if (use_json) { - r_cons_print ("]\n"); - } - - r_cons_break_pop (); -} - -R_API void r_anal_rtti_recover_all(RAnal *anal) { - RVTableContext context; - r_anal_vtable_begin (anal, &context); - - r_cons_break_push (NULL, NULL); - RList *vtables = r_anal_vtable_search (&context); - if (vtables) { - if (context.abi == R_ANAL_CPP_ABI_MSVC) { - r_anal_rtti_msvc_recover_all (&context, vtables); - } else { - r_anal_rtti_itanium_recover_all (&context, vtables); - } - } - r_list_free (vtables); - r_cons_break_pop (); -} diff --git a/libr/anal/switch.c b/libr/anal/switch.c deleted file mode 100644 index 2d98ace9df..0000000000 --- a/libr/anal/switch.c +++ /dev/null @@ -1,54 +0,0 @@ -/* radare - LGPL - Copyright 2014-2019 - pancake, dso */ - -#include - -static RAnalSwitchOp *__switch_op_new(void) { - RAnalSwitchOp * swop = R_NEW0 (RAnalSwitchOp); - if (swop) { - swop->cases = r_list_new (); - if (!swop->cases) { - free (swop); - return NULL; - } - swop->cases->free = (void *)free; - swop->min_val = swop->def_val = swop->max_val = 0; - } - return swop; -} - -R_API RAnalSwitchOp *r_anal_switch_op_new(ut64 addr, ut64 min_val, ut64 max_val, ut64 def_val) { - RAnalSwitchOp *swop = __switch_op_new (); - if (swop) { - swop->addr = addr; - swop->min_val = min_val; - swop->def_val = def_val; - swop->max_val = max_val; - } - return swop; -} - -R_API RAnalCaseOp * r_anal_case_op_new(ut64 addr, ut64 val, ut64 jump) { - RAnalCaseOp *c = R_NEW0 (RAnalCaseOp); - if (c) { - c->addr = addr; - c->value = val; - c->jump = jump; - } - return c; -} - -R_API void r_anal_switch_op_free(RAnalSwitchOp * swop) { - if (swop) { - r_list_free (swop->cases); - free (swop); - } -} - -R_API RAnalCaseOp* r_anal_switch_op_add_case(RAnalSwitchOp * swop, ut64 addr, ut64 value, ut64 jump) { - r_return_val_if_fail (swop && addr != UT64_MAX, NULL); - RAnalCaseOp * caseop = r_anal_case_op_new (addr, value, jump); - if (caseop) { - r_list_append (swop->cases, caseop); - } - return caseop; -} diff --git a/libr/anal/value.c b/libr/anal/value.c deleted file mode 100644 index 7f27c7cd44..0000000000 --- a/libr/anal/value.c +++ /dev/null @@ -1,125 +0,0 @@ -/* radare - LGPL - Copyright 2010-2020 - pancake */ - -#include - -R_API RAnalValue *r_anal_value_new(void) { //macro for this ? - return R_NEW0 (RAnalValue); -} - -R_API RAnalValue *r_anal_value_new_from_string(const char *str) { - /* TODO */ - return NULL; -} - -R_API RAnalValue *r_anal_value_copy(RAnalValue *ov) { - r_return_val_if_fail (ov, NULL); - - RAnalValue *v = R_NEW0 (RAnalValue); - if (!v) { - return NULL; - } - - memcpy (v, ov, sizeof (RAnalValue)); - // reference to reg and regdelta should be kept - return v; -} - -// TODO: move into .h as #define free -R_API void r_anal_value_free(RAnalValue *value) { - free (value); -#if 0 - ut64 pval = (ut64)(size_t)value; - if (pval && pval != UT64_MAX) { - /* TODO: free RRegItem objects? */ - free (value); - } -#endif -} - -// mul*value+regbase+regidx+delta -R_API ut64 r_anal_value_to_ut64(RAnal *anal, RAnalValue *val) { - ut64 num; - if (!val) { - return 0LL; - } - num = val->base + (val->delta*(val->mul?val->mul:1)); - if (val->reg) { - num += r_reg_get_value (anal->reg, val->reg); - } - if (val->regdelta) { - num += r_reg_get_value (anal->reg, val->regdelta); - } - switch (val->memref) { - case 1: - case 2: - case 4: - case 8: - //anal->bio ... - eprintf ("TODO: memref for to_ut64 not supported\n"); - break; - } - return num; -} - -R_API int r_anal_value_set_ut64(RAnal *anal, RAnalValue *val, ut64 num) { - if (val->memref) { - if (anal->iob.io) { - ut8 data[8]; - ut64 addr = r_anal_value_to_ut64 (anal, val); - r_mem_set_num (data, val->memref, num); - anal->iob.write_at (anal->iob.io, addr, data, val->memref); - } else { - eprintf ("No IO binded to r_anal\n"); - } - } else { - if (val->reg) { - r_reg_set_value (anal->reg, val->reg, num); - } - } - return false; //is this necessary -} - -R_API char *r_anal_value_to_string (RAnalValue *value) { - char *out = NULL; - if (value) { - out = r_str_new (""); - if (!value->base && !value->reg) { - if (value->imm != -1LL) { - out = r_str_appendf (out, "0x%"PFMT64x, value->imm); - } else { - out = r_str_append (out, "-1"); - } - } else { - if (value->memref) { - switch (value->memref) { - case 1: out = r_str_append (out, "(char)"); break; - case 2: out = r_str_append (out, "(short)"); break; - case 4: out = r_str_append (out, "(word)"); break; - case 8: out = r_str_append (out, "(dword)"); break; - } - out = r_str_append (out, "["); - } - if (value->mul) { - out = r_str_appendf (out, "%d*", value->mul); - } - if (value->reg) { - out = r_str_appendf (out, "%s", value->reg->name); - } - if (value->regdelta) { - out = r_str_appendf (out, "+%s", value->regdelta->name); - } - if (value->base != 0) { - out = r_str_appendf (out, "0x%" PFMT64x, value->base); - } - if (value->delta > 0) { - out = r_str_appendf (out, "+0x%" PFMT64x, value->delta); - } else if (value->delta < 0) { - out = r_str_appendf (out, "-0x%" PFMT64x, -value->delta); - } - if (value->memref) { - out = r_str_append (out, "]"); - } - } - } - return out; -} diff --git a/libr/asm/acode.c b/libr/asm/acode.c deleted file mode 100644 index 460a247f6f..0000000000 --- a/libr/asm/acode.c +++ /dev/null @@ -1,74 +0,0 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ - -#include -#include - -R_API RAsmCode *r_asm_code_new(void) { - return R_NEW0 (RAsmCode); -} - -R_API void* r_asm_code_free(RAsmCode *acode) { - if (acode) { - r_list_free (acode->equs); - free (acode->bytes); - free (acode->assembly); - free (acode); - } - return NULL; -} - -R_API void r_asm_equ_item_free(RAsmEqu *equ) { - if (equ) { - free (equ->key); - free (equ->value); - free (equ); - } -} - -static RAsmEqu *__asm_equ_new(const char *key, const char *value) { - RAsmEqu *equ = R_NEW0 (RAsmEqu); - if (equ) { - equ->key = strdup (key); - equ->value = strdup (value); - } - return equ; -} - -R_API bool r_asm_code_set_equ (RAsmCode *code, const char *key, const char *value) { - r_return_val_if_fail (code && key && value, false); - - if (code->equs) { - RAsmEqu *equ; - RListIter *iter; - r_list_foreach (code->equs, iter, equ) { - if (!strcmp (equ->key, key)) { - free (equ->value); - equ->value = strdup (value); - return true; - } - } - } else { - code->equs = r_list_newf ((RListFree)r_asm_equ_item_free); - } - r_list_append (code->equs, __asm_equ_new (key, value)); - return true; -} - -R_API char *r_asm_code_equ_replace (RAsmCode *code, char *str) { - r_return_val_if_fail (code && str, NULL); - RAsmEqu *equ; - RListIter *iter; - r_list_foreach (code->equs, iter, equ) { - str = r_str_replace (str, equ->key, equ->value, true); - } - return str; -} - -R_API char* r_asm_code_get_hex(RAsmCode *acode) { - r_return_val_if_fail (acode, NULL); - char* str = calloc (acode->len + 1, 2); - if (str) { - r_hex_bin2str (acode->bytes, acode->len, str); - } - return str; -} \ No newline at end of file diff --git a/libr/asm/aop.c b/libr/asm/aop.c deleted file mode 100644 index 0296d32667..0000000000 --- a/libr/asm/aop.c +++ /dev/null @@ -1,86 +0,0 @@ -/* radare - LGPL - Copyright 2018-2020 - pancake */ - -#include - -R_API RAsmOp *r_asm_op_new(void) { - return R_NEW0 (RAsmOp); -} - -R_API void r_asm_op_free(RAsmOp *op) { - r_asm_op_fini (op); - free (op); -} - -R_API void r_asm_op_init(RAsmOp *op) { - if (op) { - memset (op, 0, sizeof (*op)); - } -} - -R_API void r_asm_op_fini(RAsmOp *op) { - r_strbuf_fini (&op->buf); - r_strbuf_fini (&op->buf_asm); - r_buf_fini (op->buf_inc); -} - -// accessors -R_API char *r_asm_op_get_hex(RAsmOp *op) { - r_return_val_if_fail (op, NULL); - int size = r_strbuf_length (&op->buf); - char* str = calloc (size + 1, 2); - r_return_val_if_fail (str, NULL); - r_hex_bin2str ((const ut8*) r_strbuf_get (&op->buf), size, str); - return str; -} - -R_API char *r_asm_op_get_asm(RAsmOp *op) { - r_return_val_if_fail (op, NULL); - return r_strbuf_get (&op->buf_asm); -} - -R_API ut8 *r_asm_op_get_buf(RAsmOp *op) { - r_return_val_if_fail (op, NULL); - return (ut8*)r_strbuf_get (&op->buf); -} - -R_API int r_asm_op_get_size(RAsmOp *op) { - r_return_val_if_fail (op, 1); - const int len = op->size - op->payload; - return R_MAX (1, len); -} - -R_API void r_asm_op_set_asm(RAsmOp *op, const char *str) { - r_return_if_fail (op && str); - r_strbuf_set (&op->buf_asm, str); -} - -R_API int r_asm_op_set_hex(RAsmOp *op, const char *str) { - ut8 *bin = (ut8*)strdup (str); - if (bin) { - int len = r_hex_str2bin (str, bin); - if (len > 0) { - r_strbuf_setbin (&op->buf, bin, len); - } - free (bin); - return len; - } - return 0; -} - -R_API int r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len) { - r_return_val_if_fail (op && buf && len >= 0, 0); - char *hex = malloc (len * 4 + 1); - if (hex) { - (void)r_hex_bin2str (buf, len, hex); - int olen = r_asm_op_set_hex (op, hex); - free (hex); - return olen; - } - return 0; -} - -R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *buf, int len) { - r_return_if_fail (op && buf && len >= 0); - r_strbuf_setbin (&op->buf, buf, len); - r_asm_op_set_hexbuf (op, buf, len); -} diff --git a/libr/asm/arch/8051/8051_ass.h b/libr/asm/arch/8051/8051_ass.h deleted file mode 100644 index 33e06e3429..0000000000 --- a/libr/asm/arch/8051/8051_ass.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef _8051_ASS_H -#define _8051_ASS_H - -#include -int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm); - -#endif diff --git a/libr/asm/arch/arm/Makefile b/libr/asm/arch/arm/Makefile deleted file mode 100644 index b97b79503e..0000000000 --- a/libr/asm/arch/arm/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -all: - gcc -I../../../include armass.c -DMAIN -lr_util - ./a.out diff --git a/libr/asm/arch/pic/pic_pic18.h b/libr/asm/arch/pic/pic_pic18.h deleted file mode 100644 index 88dbb05b13..0000000000 --- a/libr/asm/arch/pic/pic_pic18.h +++ /dev/null @@ -1,10 +0,0 @@ -/* radare2 - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r */ - -#ifndef PIC_PIC18_H -#define PIC_PIC18_H - -#include - -int pic_pic18_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l); - -#endif //PIC_PIC18_H diff --git a/libr/asm/p/asm_rsp.c b/libr/asm/p/asm_rsp.c deleted file mode 100644 index 9dcb0385c2..0000000000 --- a/libr/asm/p/asm_rsp.c +++ /dev/null @@ -1,107 +0,0 @@ -/* radare - LGPL - Copyright 2016 - bobby.smiles32@gmail.com */ -// TODO: add assembler - -#include -#include -#include -#include - -#include -#include - -#include "rsp_idec.h" - - -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - rsp_instruction r_instr; - int i; - - /* all instructions are 32bit words */ - if (len < 4) { - op->size = 0; - return 0; - } - op->size = 4; - - ut32 iw = r_read_ble32 (buf, a->big_endian); - r_instr = rsp_instruction_decode (a->pc, iw); - - r_strbuf_append (&op->buf_asm, r_instr.mnemonic); - for (i = 0; i < r_instr.noperands; i++) { - r_strbuf_append (&op->buf_asm, (i == 0) ? " " : ", "); - - switch (r_instr.operands[i].type) { - case RSP_OPND_GP_REG: - r_strbuf_append (&op->buf_asm, rsp_gp_reg_soft_names[r_instr.operands[i].u]); - break; - case RSP_OPND_OFFSET: - case RSP_OPND_TARGET: - r_strbuf_appendf (&op->buf_asm, "0x%08"PFMT64x, r_instr.operands[i].u); - break; - case RSP_OPND_ZIMM: - { - int shift = (r_instr.operands[i].u & ~0xffff) ? 16 : 0; - r_strbuf_appendf (&op->buf_asm, "0x%04"PFMT64x, - r_instr.operands[i].u >> shift); - } - break; - case RSP_OPND_SIMM: - r_strbuf_appendf (&op->buf_asm, "%s0x%04"PFMT64x, - (r_instr.operands[i].s<0)?"-":"", - (r_instr.operands[i].s<0)?-r_instr.operands[i].s:r_instr.operands[i].s); - break; - case RSP_OPND_SHIFT_AMOUNT: - r_strbuf_appendf (&op->buf_asm, "%"PFMT64u, r_instr.operands[i].u); - break; - case RSP_OPND_BASE_OFFSET: - r_strbuf_appendf (&op->buf_asm, "%s0x%04x(%s)", - (r_instr.operands[i].s<0)?"-":"", - (ut32)((r_instr.operands[i].s<0)?-r_instr.operands[i].s:r_instr.operands[i].s), - rsp_gp_reg_soft_names[r_instr.operands[i].u]); - break; - case RSP_OPND_C0_REG: - r_strbuf_append (&op->buf_asm, rsp_c0_reg_soft_names[r_instr.operands[i].u]); - break; - case RSP_OPND_C2_CREG: - r_strbuf_append (&op->buf_asm, rsp_c2_creg_names[r_instr.operands[i].u]); - break; - case RSP_OPND_C2_ACCU: - r_strbuf_append (&op->buf_asm, rsp_c2_accu_names[r_instr.operands[i].u]); - break; - case RSP_OPND_C2_VREG: - r_strbuf_append (&op->buf_asm, rsp_c2_vreg_names[r_instr.operands[i].u]); - break; - case RSP_OPND_C2_VREG_BYTE: - case RSP_OPND_C2_VREG_SCALAR: - r_strbuf_appendf (&op->buf_asm, "%s[%u]", rsp_c2_vreg_names[r_instr.operands[i].u], - (ut32)r_instr.operands[i].s); - break; - case RSP_OPND_C2_VREG_ELEMENT: - r_strbuf_appendf (&op->buf_asm, "%s%s", rsp_c2_vreg_names[r_instr.operands[i].u], rsp_c2_vreg_element_names[r_instr.operands[i].s]); - break; - default: /* should not happend */ - r_strbuf_append (&op->buf_asm, "???"); - break; - } - } - - return op->size; -} - -RAsmPlugin r_asm_plugin_rsp = { - .name = "rsp", - .desc = "Reality Signal Processor", - .arch = "rsp", - .bits = 32, - .endian = R_SYS_ENDIAN_BI, /* For conveniance, we don't force BIG endian but allow both to be used */ - .license = "LGPL3", - .disassemble = &disassemble -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_rsp, - .version = R2_VERSION -}; -#endif diff --git a/libr/bin/bin_write.c b/libr/bin/bin_write.c deleted file mode 100644 index 3c0060b618..0000000000 --- a/libr/bin/bin_write.c +++ /dev/null @@ -1,62 +0,0 @@ -/* radare2 - LGPL - Copyright 2009-2019 - pancake, nibble */ - -#include -#include -#include - -/* XXX Implement r__bin_wr_scn_{ set, del } instead */ -R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size) { - RBinFile *bf = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); - if (plugin && plugin->write && plugin->write->scn_resize) { - return plugin->write->scn_resize (bf, name, size); - } - return false; -} - -R_API bool r_bin_wr_scn_perms(RBin *bin, const char *name, int perms) { - RBinFile *bf = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); - if (plugin && plugin->write && plugin->write->scn_perms) { - return plugin->write->scn_perms (bf, name, perms); - } - return false; -} - -R_API bool r_bin_wr_rpath_del(RBin *bin) { - RBinFile *bf = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); - if (plugin && plugin->write && plugin->write->rpath_del) { - return plugin->write->rpath_del (bf); - } - return false; -} - -R_API bool r_bin_wr_output(RBin *bin, const char *filename) { - r_return_val_if_fail (bin && filename, false); - RBinFile *bf = r_bin_cur (bin); - if (!bf || !bf->buf) { - return false; - } - ut64 tmpsz; - const ut8 *tmp = r_buf_data (bf->buf, &tmpsz); - return r_file_dump (filename, tmp, tmpsz, 0); -} - -R_API bool r_bin_wr_entry(RBin *bin, ut64 addr) { - RBinFile *bf = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); - if (plugin && plugin->write && plugin->write->entry) { - return plugin->write->entry (bf, addr); - } - return false; -} - -R_API bool r_bin_wr_addlib(RBin *bin, const char *lib) { - RBinFile *bf = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); - if (plugin && plugin->write && plugin->write->addlib) { - return plugin->write->addlib (bin->cur, lib); - } - return false; -} diff --git a/libr/bin/d/dll/makefile b/libr/bin/d/dll/makefile deleted file mode 100644 index 37521850aa..0000000000 --- a/libr/bin/d/dll/makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: - #rabin2 -rs /tmp/ws2_32.dll | grep ^k| cut -d / -f 4- > ___WS2_32.sdb.txt - #rabin2 -rs /tmp/oleaut32.dll | grep ^k| cut -d / -f 4- > ___OLEAUT32.sdb.txt - #rabin2 -rs /tmp/wsock32.dll | grep ^k| cut -d / -f 4- > WSOCK32.sdb.txt - #rabin2 -rs /tmp/msi.dll | grep ^k| cut -d / -f 4- > MSI.sdb.txt - rabin2 -rs /tmp/csncdapi.dll | grep ^k| cut -d / -f 4- > CSNCDAPI.sdb.txt - rabin2 -rs /tmp/csmtpapi.dll | grep ^k| cut -d / -f 4- > CSMTPAPI.sdb.txt - rabin2 -rs /tmp/csftpapi.dll | grep ^k| cut -d / -f 4- > CSMFPAPI.sdb.txt diff --git a/libr/bin/format/elf/elf.h b/libr/bin/format/elf/elf.h deleted file mode 100644 index 28c1455aa9..0000000000 --- a/libr/bin/format/elf/elf.h +++ /dev/null @@ -1,221 +0,0 @@ -#include -#include -#include -#include - -#include "elf_specs.h" - -#ifndef _INCLUDE_ELF_H_ -#define _INCLUDE_ELF_H_ - -#define R_BIN_ELF_SCN_IS_EXECUTABLE(x) x & SHF_EXECINSTR -#define R_BIN_ELF_SCN_IS_READABLE(x) x & SHF_ALLOC -#define R_BIN_ELF_SCN_IS_WRITABLE(x) x & SHF_WRITE - -#define R_BIN_ELF_SYMTAB_SYMBOLS 1 << 0 -#define R_BIN_ELF_DYNSYM_SYMBOLS 1 << 1 -#define R_BIN_ELF_IMPORT_SYMBOLS (1 << 2 | (bin->ehdr.e_type == ET_REL ? R_BIN_ELF_SYMTAB_SYMBOLS : R_BIN_ELF_DYNSYM_SYMBOLS)) -#define R_BIN_ELF_ALL_SYMBOLS (R_BIN_ELF_SYMTAB_SYMBOLS | R_BIN_ELF_DYNSYM_SYMBOLS) -#define ELFOBJ struct Elf_(r_bin_elf_obj_t) - -#if R_BIN_ELF64 -#define R_BIN_ELF_WORDSIZE 0x8 -#define R_BIN_ELF_WORD_MAX UT64_MAX -#define R_BIN_ELF_READWORD(x, i) READ64 (x, i) -#define R_BIN_ELF_BREADWORD(x, i) BREAD64 (x, i) -#define R_BIN_ELF_ADDR_MAX UT64_MAX -#define R_BIN_ELF_XWORD_MAX UT64_MAX -#else -#define R_BIN_ELF_WORDSIZE 0x4 -#define R_BIN_ELF_WORD_MAX UT32_MAX -#define R_BIN_ELF_READWORD(x, i) READ32 (x, i) -#define R_BIN_ELF_BREADWORD(x, i) BREAD32 (x, i) -#define R_BIN_ELF_ADDR_MAX UT32_MAX -#define R_BIN_ELF_XWORD_MAX UT64_MAX -#endif - - -typedef struct r_bin_elf_section_t { - ut64 offset; - ut64 rva; - ut64 size; - ut64 align; - ut32 flags; - ut32 link; - ut32 info; - char name[ELF_STRING_LENGTH]; - int last; - int type; -} RBinElfSection; - -typedef struct r_bin_elf_symbol_t { - ut64 offset; - ut64 size; - ut32 ordinal; - const char *bind; - const char *type; - char name[ELF_STRING_LENGTH]; - char libname[ELF_STRING_LENGTH]; - int last; - bool in_shdr; - bool is_sht_null; - bool is_vaddr; /* when true, offset is virtual address, otherwise it's physical */ - bool is_imported; -} RBinElfSymbol; - -typedef struct r_bin_elf_reloc_t { - int sym; - int type; - Elf_(Xword) rel_mode; - st64 addend; - ut64 offset; - ut64 rva; - ut16 section; - int last; - ut64 sto; -} RBinElfReloc; - -typedef struct r_bin_elf_field_t { - ut64 offset; - char name[ELF_STRING_LENGTH]; - int last; -} RBinElfField; - -typedef struct r_bin_elf_string_t { - ut64 offset; - ut64 size; - char type; - char string[ELF_STRING_LENGTH]; - int last; -} RBinElfString; - -typedef struct Elf_(r_bin_elf_dynamic_info) { - Elf_(Xword) dt_pltrelsz; - Elf_(Addr) dt_pltgot; - Elf_(Addr) dt_hash; - Elf_(Addr) dt_strtab; - Elf_(Addr) dt_symtab; - Elf_(Addr) dt_rela; - Elf_(Xword) dt_relasz; - Elf_(Xword) dt_relaent; - Elf_(Xword) dt_strsz; - Elf_(Xword) dt_syment; - Elf_(Addr) dt_fini; - Elf_(Addr) dt_rel; - Elf_(Xword) dt_relsz; - Elf_(Xword) dt_relent; - Elf_(Xword) dt_pltrel; - Elf_(Addr) dt_jmprel; - Elf_(Addr) dt_mips_pltgot; - bool dt_bind_now; - Elf_(Xword) dt_flags; - Elf_(Xword) dt_flags_1; - Elf_(Xword) dt_rpath; - Elf_(Xword) dt_runpath; - RVector dt_needed; -} RBinElfDynamicInfo; - -typedef struct r_bin_elf_lib_t { - char name[ELF_STRING_LENGTH]; - int last; -} RBinElfLib; - -struct Elf_(r_bin_elf_obj_t) { - Elf_(Ehdr) ehdr; - Elf_(Phdr) *phdr; - Elf_(Shdr) *shdr; - - Elf_(Shdr) *strtab_section; - ut64 strtab_size; - char *strtab; - - Elf_(Shdr) *shstrtab_section; - ut64 shstrtab_size; - char *shstrtab; - - RBinElfDynamicInfo dyn_info; - - ut64 version_info[DT_VERSIONTAGNUM]; - - char *dynstr; - ut32 dynstr_size; - - RBinImport **imports_by_ord; - size_t imports_by_ord_size; - RBinSymbol **symbols_by_ord; - size_t symbols_by_ord_size; - - int bss; - ut64 size; - ut64 baddr; - ut64 boffset; - int endian; - bool verbose; - const char* file; - RBuffer *b; - Sdb *kv; - /*cache purpose*/ - RBinElfSection *g_sections; - RBinElfSymbol *g_symbols; - RBinElfSymbol *g_imports; - RBinElfReloc *g_relocs; - ut32 g_reloc_num; - RBinElfSymbol *phdr_symbols; - RBinElfSymbol *phdr_imports; - HtUP *rel_cache; -}; - -int Elf_(r_bin_elf_has_va)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_get_section_addr)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name); -ut64 Elf_(r_bin_elf_get_section_offset)(struct Elf_(r_bin_elf_obj_t) *bin, const char *section_name); -ut64 Elf_(r_bin_elf_get_baddr)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_p2v)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 paddr); -ut64 Elf_(r_bin_elf_v2p)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 vaddr); -ut64 Elf_(r_bin_elf_p2v_new)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 paddr); -ut64 Elf_(r_bin_elf_v2p_new)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 vaddr); -ut64 Elf_(r_bin_elf_get_boffset)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_get_entry_offset)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_get_main_offset)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_get_init_offset)(struct Elf_(r_bin_elf_obj_t) *bin); -ut64 Elf_(r_bin_elf_get_fini_offset)(struct Elf_(r_bin_elf_obj_t) *bin); -char *Elf_(r_bin_elf_intrp)(struct Elf_(r_bin_elf_obj_t) *bin); -char *Elf_(r_bin_elf_compiler)(ELFOBJ *bin); -bool Elf_(r_bin_elf_get_stripped)(struct Elf_(r_bin_elf_obj_t) *bin); -bool Elf_(r_bin_elf_is_static)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_data_encoding)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_arch)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_machine_name)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_head_flag)(ELFOBJ *bin); //yin -char* Elf_(r_bin_elf_get_abi)(ELFOBJ *bin); -char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *bin); -char* Elf_(r_bin_elf_get_file_type)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_elf_class)(struct Elf_(r_bin_elf_obj_t) *bin); -int Elf_(r_bin_elf_get_bits)(struct Elf_(r_bin_elf_obj_t) *bin); -char* Elf_(r_bin_elf_get_osabi_name)(struct Elf_(r_bin_elf_obj_t) *bin); -int Elf_(r_bin_elf_is_big_endian)(struct Elf_(r_bin_elf_obj_t) *bin); -RBinElfReloc* Elf_(r_bin_elf_get_relocs)(struct Elf_(r_bin_elf_obj_t) *bin); -RBinElfLib* Elf_(r_bin_elf_get_libs)(struct Elf_(r_bin_elf_obj_t) *bin); -RBinElfSection* Elf_(r_bin_elf_get_sections)(struct Elf_(r_bin_elf_obj_t) *bin); -RBinElfSymbol* Elf_(r_bin_elf_get_symbols)(struct Elf_(r_bin_elf_obj_t) *bin); -RBinElfSymbol* Elf_(r_bin_elf_get_imports)(struct Elf_(r_bin_elf_obj_t) *bin); -struct r_bin_elf_field_t* Elf_(r_bin_elf_get_fields)(struct Elf_(r_bin_elf_obj_t) *bin); -char *Elf_(r_bin_elf_get_rpath)(struct Elf_(r_bin_elf_obj_t) *bin); - -struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new)(const char* file, bool verbose); -struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new_buf)(RBuffer *buf, bool verbose); -void Elf_(r_bin_elf_free)(struct Elf_(r_bin_elf_obj_t)* bin); - -ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size); -bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms); -bool Elf_(r_bin_elf_entry_write)(RBinFile *bf, ut64 addr); -bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf); - -bool Elf_(r_bin_elf_is_executable)(ELFOBJ *bin); -int Elf_(r_bin_elf_has_relro)(struct Elf_(r_bin_elf_obj_t) *bin); -int Elf_(r_bin_elf_has_nx)(struct Elf_(r_bin_elf_obj_t) *bin); -ut8 *Elf_(r_bin_elf_grab_regstate)(struct Elf_(r_bin_elf_obj_t) *bin, int *len); -RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *bin); -RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin, - struct r_bin_elf_symbol_t *symbol, - const char *namefmt); -#endif diff --git a/libr/bin/format/le/le.h b/libr/bin/format/le/le.h deleted file mode 100644 index 0209f0f826..0000000000 --- a/libr/bin/format/le/le.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef LE_H -#define LE_H -#include -#include "le_specs.h" - -typedef struct r_bin_le_obj_s { - LE_image_header *header; - bool is_le; /* Used for differences between LE and LX */ - char *filename; - const char *type; - const char *cpu; - const char *os; - const char *arch; - ut32 headerOff; /* File offset to start of LE/LX header */ - LE_object_entry *objtbl; - void *buf; /* Pointer to RBuffer of file */ -} r_bin_le_obj_t; - -r_bin_le_obj_t *r_bin_le_new_buf(RBuffer *buf); -void r_bin_le_free(r_bin_le_obj_t *bin); -RList *r_bin_le_get_entrypoints(r_bin_le_obj_t *bin); -RList *r_bin_le_get_sections(r_bin_le_obj_t *bin); -RList *r_bin_le_get_symbols(r_bin_le_obj_t *bin); -RList *r_bin_le_get_imports(r_bin_le_obj_t *bin); -RList *r_bin_le_get_libs(r_bin_le_obj_t *bin); -RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin); -#endif diff --git a/libr/bin/format/mach0/coresymbolication.h b/libr/bin/format/mach0/coresymbolication.h deleted file mode 100644 index 28a1545951..0000000000 --- a/libr/bin/format/mach0/coresymbolication.h +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include - -#ifndef _INCLUDE_R_BIN_CORESYMBOLICATION_H -#define _INCLUDE_R_BIN_CORESYMBOLICATION_H - -typedef struct r_coresym_cache_element_hdr_t { - ut32 version; - ut32 size; - ut32 n_segments; - ut32 n_sections; - ut32 n_symbols; - ut32 n_lined_symbols; - ut32 n_line_info; - ut32 f; - ut32 g; - ut32 h; - ut32 file_name_off; - ut32 version_off; - ut32 k; - ut8 uuid[16]; - ut32 cputype; - ut32 cpusubtype; - ut32 o; - ut32 strings_off; - ut32 p; -} RCoreSymCacheElementHdr; - -typedef struct r_coresym_cache_element_segment_t { - ut64 paddr; - ut64 vaddr; - ut64 size; - ut64 vsize; - char *name; -} RCoreSymCacheElementSegment; - -typedef struct r_coresym_cache_element_section_t { - ut64 paddr; - ut64 vaddr; - ut64 size; - char *name; -} RCoreSymCacheElementSection; - -typedef struct r_coresym_cache_element_flc_t { - char *file; - ut32 line; - ut32 col; -} RCoreSymCacheElementFLC; - -typedef struct r_coresym_cache_element_line_info_t { - ut32 paddr; - ut32 size; - RCoreSymCacheElementFLC flc; -} RCoreSymCacheElementLineInfo; - -typedef struct r_coresym_cache_element_symbol_t { - ut32 paddr; - ut32 size; - ut32 unk1; - char *name; - char *mangled_name; - st32 unk2; -} RCoreSymCacheElementSymbol; - -typedef struct r_coresym_cache_element_lined_symbol_t { - RCoreSymCacheElementSymbol sym; - RCoreSymCacheElementFLC flc; -} RCoreSymCacheElementLinedSymbol; - -typedef struct r_coresym_cache_element_t { - RCoreSymCacheElementHdr *hdr; - char *file_name; - char *binary_version; - RCoreSymCacheElementSegment *segments; - RCoreSymCacheElementSection *sections; - RCoreSymCacheElementSymbol *symbols; - RCoreSymCacheElementLinedSymbol *lined_symbols; - RCoreSymCacheElementLineInfo *line_info; -} RCoreSymCacheElement; - -R_API RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut64 off, int bits); -R_API void r_coresym_cache_element_free(RCoreSymCacheElement *element); -R_API ut64 r_coresym_cache_element_pa2va(RCoreSymCacheElement *element, ut64 pa); - -#endif diff --git a/libr/bin/format/mach0/fatmach0.c b/libr/bin/format/mach0/fatmach0.c deleted file mode 100644 index 8e6c57a027..0000000000 --- a/libr/bin/format/mach0/fatmach0.c +++ /dev/null @@ -1,142 +0,0 @@ -/* radare - LGPL - Copyright 2010-2013 - nibble */ - -#include -#include -#include -#include "fatmach0.h" - -static int r_bin_fatmach0_init(struct r_bin_fatmach0_obj_t* bin) { - ut32 size; - ut32 i; - ut8 hdrbytes[sizeof (struct fat_header)] = {0}; - int len = r_buf_read_at (bin->b, 0, &hdrbytes[0], sizeof (struct fat_header)); - if (len != sizeof (struct fat_header)) { - perror ("read (fat_header)"); - return false; - } - bin->hdr.magic = r_read_be32 (&hdrbytes[0]); - bin->hdr.nfat_arch = r_read_be32 (&hdrbytes[4]); - bin->nfat_arch = bin->hdr.nfat_arch; - if (sizeof (struct fat_header) + bin->nfat_arch * - sizeof (struct fat_arch) > bin->size) { - return false; - } - if (bin->hdr.magic != FAT_MAGIC || !bin->nfat_arch || bin->nfat_arch < 1) { - eprintf ("Endian FAT_MAGIC failed (?)\n"); - return false; - } - size = bin->nfat_arch * sizeof (struct fat_arch); - if (size < bin->nfat_arch) { - return false; - } - if (!(bin->archs = malloc (size))) { - perror ("malloc (fat_arch)"); - return false; - } - for (i = 0; i < bin->nfat_arch; i++) { - ut8 archbytes[sizeof (struct fat_arch)] = {0}; - len = r_buf_read_at (bin->b, 8 + i * sizeof (struct fat_arch), &archbytes[0], sizeof (struct fat_arch)); - if (len != sizeof (struct fat_arch)) { - perror ("read (fat_arch)"); - R_FREE (bin->archs); - return false; - } - bin->archs[i].cputype = r_read_be32 (&archbytes[0]); - bin->archs[i].cpusubtype = r_read_be32 (&archbytes[4]); - bin->archs[i].offset = r_read_be32 (&archbytes[8]); - bin->archs[i].size = r_read_be32 (&archbytes[12]); - bin->archs[i].align = r_read_be32 (&archbytes[16]); - } - return true; -} - -struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin, int idx, int *narch) { - if (!bin || (idx < 0) || (idx > bin->nfat_arch)) { - return NULL; - } - if (bin->archs[idx].offset > bin->size || - bin->archs[idx].offset + bin->archs[idx].size > bin->size) { - return NULL; - } - if (narch) { - *narch = bin->nfat_arch; - } - struct r_bin_fatmach0_arch_t *ret = R_NEW0 (struct r_bin_fatmach0_arch_t); - if (ret) { - ret->size = bin->archs[idx].size; - if (!ret->size || ret->size > bin->size) { - eprintf ("Skipping corrupted sub-bin %d arch %d\n", idx, bin->archs[idx].size); - free (ret); - return NULL; - } - ret->offset = bin->archs[idx].offset; - ret->b = r_buf_new_slice (bin->b, ret->offset, ret->size); - } - return ret; -} - -void* r_bin_fatmach0_free(struct r_bin_fatmach0_obj_t* bin) { - if (!bin) { - return NULL; - } - free (bin->archs); - r_buf_free (bin->b); - R_FREE (bin); - return NULL; -} - -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_new(const char* file) { - struct r_bin_fatmach0_obj_t *bin = R_NEW0 (struct r_bin_fatmach0_obj_t); - if (!bin) { - return NULL; - } - bin->file = file; - size_t binsz; - ut8 *buf = (ut8 *)r_file_slurp (file, &binsz); - bin->size = binsz; - if (!buf) { - return r_bin_fatmach0_free (bin); - } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { - free (buf); - return r_bin_fatmach0_free (bin); - } - free (buf); - if (!r_bin_fatmach0_init (bin)) { - return r_bin_fatmach0_free (bin); - } - return bin; -} - -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_from_buffer_new(RBuffer *b) { - r_return_val_if_fail (b, NULL); - struct r_bin_fatmach0_obj_t *bo = R_NEW0 (struct r_bin_fatmach0_obj_t); - if (bo) { - bo->b = r_buf_ref (b); - bo->size = r_buf_size (bo->b); // XXX implicit in bo->b - if (!r_bin_fatmach0_init (bo)) { - return r_bin_fatmach0_free (bo); - } - } - return bo; -} - -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_from_bytes_new(const ut8* buf, ut64 size) { - struct r_bin_fatmach0_obj_t *bin = R_NEW0 (struct r_bin_fatmach0_obj_t); - if (!bin) { - return NULL; - } - if (!buf) { - return r_bin_fatmach0_free (bin); - } - bin->b = r_buf_new (); - bin->size = size; - if (!r_buf_set_bytes (bin->b, buf, size)) { - return r_bin_fatmach0_free (bin); - } - if (!r_bin_fatmach0_init (bin)) { - return r_bin_fatmach0_free (bin); - } - return bin; -} diff --git a/libr/bin/format/mach0/fatmach0.h b/libr/bin/format/mach0/fatmach0.h deleted file mode 100644 index 4fda39ec3e..0000000000 --- a/libr/bin/format/mach0/fatmach0.h +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include "mach0_specs.h" - -#ifndef _INCLUDE_R_BIN_FATMACH0_H_ -#define _INCLUDE_R_BIN_FATMACH0_H_ - -struct r_bin_fatmach0_obj_t { - const char *file; - int size; - int nfat_arch; - struct fat_header hdr; - struct fat_arch *archs; - RBuffer* b; -}; - -struct r_bin_fatmach0_arch_t { - int size; - int offset; - RBuffer *b; - int last; -}; - -struct r_bin_fatmach0_arch_t *r_bin_fatmach0_extract(struct r_bin_fatmach0_obj_t* bin, int idx, int *narch); -void* r_bin_fatmach0_free(struct r_bin_fatmach0_obj_t* bin); -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_new(const char* file); -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_from_bytes_new(const ut8* buf, ut64 size); -struct r_bin_fatmach0_obj_t* r_bin_fatmach0_from_buffer_new(RBuffer *b); -#endif diff --git a/libr/bin/format/mdmp/mdmp.h b/libr/bin/format/mdmp/mdmp.h deleted file mode 100644 index 0208e1e44a..0000000000 --- a/libr/bin/format/mdmp/mdmp.h +++ /dev/null @@ -1,65 +0,0 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ - -#ifndef MDMP_H -#define MDMP_H - -#include -#include -#include -#include - -#include "mdmp_specs.h" -#include "mdmp_pe.h" -#include "mdmp_pe64.h" - -struct r_bin_mdmp_obj { - struct minidump_header *hdr; - - /* Encountered streams */ - struct minidump_streams { - ut8 *comments_a; - ut8 *comments_w; - - struct minidump_exception_stream *exception; - struct minidump_function_table_stream *function_table; - struct minidump_handle_data_stream *handle_data; - struct minidump_system_info *system_info; - - union { - struct minidump_misc_info *misc_info_1; - struct minidump_misc_info_2 *misc_info_2; - } misc_info; - - /* Lists */ - RList *ex_threads; - RList *memories; - RList *memory_infos; - RList *modules; - RList *operations; - RList *thread_infos; - RList *threads; - RList *token_infos; - RList *unloaded_modules; - struct { - rva64_t base_rva; - RList *memories; - } memories64; - } streams; - - /* Binary memory objects */ - RList *pe32_bins; - RList *pe64_bins; - - RBuffer *b; - size_t size; - ut8 endian; - Sdb *kv; -}; - -struct r_bin_mdmp_obj *r_bin_mdmp_new_buf(RBuffer *buf); -void r_bin_mdmp_free(struct r_bin_mdmp_obj *obj); -ut64 r_bin_mdmp_get_paddr(struct r_bin_mdmp_obj *obj, ut64 vaddr); -ut32 r_bin_mdmp_get_perm(struct r_bin_mdmp_obj *obj, ut64 vaddr); -struct minidump_memory_info *r_bin_mdmp_get_mem_info(struct r_bin_mdmp_obj *obj, ut64 vaddr); - -#endif /* MDMP_H */ diff --git a/libr/bin/format/mdmp/mdmp_pe.h b/libr/bin/format/mdmp/mdmp_pe.h deleted file mode 100644 index 386f26c519..0000000000 --- a/libr/bin/format/mdmp/mdmp_pe.h +++ /dev/null @@ -1,27 +0,0 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ - -#ifndef MDMP_PE_H -#define MDMP_PE_H - -#include -#include -#include -#include - -#include "pe/pe.h" - -#include "mdmp_specs.h" - -struct PE_(r_bin_mdmp_pe_bin) { - ut64 vaddr; - ut64 paddr; - struct PE_(r_bin_pe_obj_t) *bin; -}; - - -RList *PE_(r_bin_mdmp_pe_get_entrypoint)(struct PE_(r_bin_mdmp_pe_bin) *pe_bin); -RList *PE_(r_bin_mdmp_pe_get_imports)(struct PE_(r_bin_mdmp_pe_bin) *pe_bin); -RList *PE_(r_bin_mdmp_pe_get_sections)(struct PE_(r_bin_mdmp_pe_bin) *pe_bin); -RList *PE_(r_bin_mdmp_pe_get_symbols)(RBin *rbin, struct PE_(r_bin_mdmp_pe_bin) *pe_bin); - -#endif /* MDMP_PE_H */ diff --git a/libr/bin/format/mdmp/mdmp_pe64.c b/libr/bin/format/mdmp/mdmp_pe64.c deleted file mode 100644 index b9d7696501..0000000000 --- a/libr/bin/format/mdmp/mdmp_pe64.c +++ /dev/null @@ -1,4 +0,0 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ - -#define R_BIN_PE64 1 -#include "mdmp_pe.c" diff --git a/libr/bin/format/mz/mz.h b/libr/bin/format/mz/mz.h deleted file mode 100644 index 230fb0685d..0000000000 --- a/libr/bin/format/mz/mz.h +++ /dev/null @@ -1,48 +0,0 @@ -/* radare - LGPL - Copyright 2015 nodepad */ - -#ifndef MZ_H -#define MZ_H - -#include -#include -#include -#include -#include "mz_specs.h" - -struct r_bin_mz_segment_t { - ut64 paddr; - ut64 vaddr; - ut64 size; - int last; -}; - -struct r_bin_mz_reloc_t { - ut64 paddr; - ut64 vaddr; - int last; -}; - -struct r_bin_mz_obj_t { - const MZ_image_dos_header *dos_header; - const void *dos_extended_header; - MZ_image_relocation_entry *relocation_entries; - - int dos_extended_header_size; - - int size; - int dos_file_size; /* Size of dos file from dos executable header */ - int load_module_size; /* Size of load module: dos_file_size - header size */ - const char *file; - RBuffer *b; - Sdb *kv; -}; - -RBinAddr *r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin); -RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin); -struct r_bin_mz_reloc_t *r_bin_mz_get_relocs (const struct r_bin_mz_obj_t *bin); -void *r_bin_mz_free (struct r_bin_mz_obj_t *bin); -struct r_bin_mz_obj_t *r_bin_mz_new (const char *file); -struct r_bin_mz_obj_t *r_bin_mz_new_buf(RBuffer *buf); -RBinAddr *r_bin_mz_get_main_vaddr (struct r_bin_mz_obj_t *bin); - -#endif diff --git a/libr/bin/format/ne/ne.h b/libr/bin/format/ne/ne.h deleted file mode 100644 index c7837f18c0..0000000000 --- a/libr/bin/format/ne/ne.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef NE_H -#define NE_H -#include -#include -#include -#include -#include "ne_specs.h" - -typedef struct { - char *name; - ut32 offset; - ut32 size; -} r_ne_resource_entry; - -typedef struct { - char *name; - RList /**/ *entry; -} r_ne_resource; - -typedef struct { - NE_image_header *ne_header; - ut16 header_offset; - ut16 alignment; - NE_image_segment_entry *segment_entries; - ut8 *entry_table; - ut8 *resident_name_table; - RBuffer *buf; - RList *segments; - RList *entries; - RList *resources; - RList *imports; - RList *symbols; - char *os; -} r_bin_ne_obj_t; - -void r_bin_ne_free(r_bin_ne_obj_t *bin); -r_bin_ne_obj_t *r_bin_ne_new_buf(RBuffer *buf, bool verbose); -RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin); -RList *r_bin_ne_get_imports(r_bin_ne_obj_t *bin); -RList *r_bin_ne_get_symbols(r_bin_ne_obj_t *bin); -RList *r_bin_ne_get_segments(r_bin_ne_obj_t *bin); -RList *r_bin_ne_get_entrypoints(r_bin_ne_obj_t *bin); - -#endif diff --git a/libr/bin/format/objc/mach0_classes.h b/libr/bin/format/objc/mach0_classes.h deleted file mode 100644 index 029ee1a30d..0000000000 --- a/libr/bin/format/objc/mach0_classes.h +++ /dev/null @@ -1,24 +0,0 @@ -#include - -#include "mach0/mach0_specs.h" -#include "mach0/mach0.h" - -#undef mach0_ut -#undef r_bin_plugin_mach - -#ifdef R_BIN_MACH064 -#define mach0_ut ut64 -#define r_bin_plugin_mach r_bin_plugin_mach064 -#else -#define mach0_ut ut32 -#define r_bin_plugin_mach r_bin_plugin_mach0 -#endif - -#ifndef MACH0_CLASSES_H -#define MACH0_CLASSES_H - -R_API RList *MACH0_(parse_classes)(RBinFile *bf); -R_API void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, RSkipList *relocs); -R_API void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipList *relocs); - -#endif // MACH0_CLASSES_H diff --git a/libr/bin/format/pe/pe.h b/libr/bin/format/pe/pe.h deleted file mode 100644 index 723cf0c9f3..0000000000 --- a/libr/bin/format/pe/pe.h +++ /dev/null @@ -1,174 +0,0 @@ -/* radare - LGPL - Copyright 2008 nibble<.ds@gmail.com> */ - -#include -#include -#include -#include - -#include "pe_specs.h" - -#ifndef _INCLUDE_R_BIN_PE_H_ -#define _INCLUDE_R_BIN_PE_H_ - -#define R_BIN_PE_SCN_IS_SHAREABLE(x) x & PE_IMAGE_SCN_MEM_SHARED -#define R_BIN_PE_SCN_IS_EXECUTABLE(x) x & PE_IMAGE_SCN_MEM_EXECUTE -#define R_BIN_PE_SCN_IS_READABLE(x) x & PE_IMAGE_SCN_MEM_READ -#define R_BIN_PE_SCN_IS_WRITABLE(x) x & PE_IMAGE_SCN_MEM_WRITE - -struct r_bin_pe_addr_t { - ut64 vaddr; - ut64 paddr; - ut64 haddr; -}; - -struct r_bin_pe_section_t { - ut8 name[PE_IMAGE_SIZEOF_SHORT_NAME * 3]; - ut64 size; - ut64 vsize; - ut64 vaddr; - ut64 paddr; - ut64 perm; - int last; -}; - -struct r_bin_pe_import_t { - ut8 name[PE_NAME_LENGTH + 1]; - ut8 libname[PE_NAME_LENGTH + 1]; - ut64 vaddr; - ut64 paddr; - ut64 hint; - ut64 ordinal; - int last; -}; - -struct r_bin_pe_export_t { - ut8 name[PE_NAME_LENGTH + 1]; - ut8 libname[PE_NAME_LENGTH + 1]; - ut8 forwarder[PE_NAME_LENGTH + 1]; - ut64 vaddr; - ut64 paddr; - ut64 ordinal; - int last; -}; - -struct r_bin_pe_string_t { - char string[PE_STRING_LENGTH]; - ut64 vaddr; - ut64 paddr; - ut64 size; - char type; - int last; -}; - -struct r_bin_pe_lib_t { - char name[PE_STRING_LENGTH]; - int last; -}; - - -typedef struct _PE_RESOURCE { - char *timestr; - char *type; - char *language; - char *name; - Pe_image_resource_data_entry *data; -} r_pe_resource; - -#define GUIDSTR_LEN 41 -#define DBG_FILE_NAME_LEN 255 - -typedef struct SDebugInfo { - char guidstr[GUIDSTR_LEN]; - char file_name[DBG_FILE_NAME_LEN]; -} SDebugInfo; - -#endif - -struct PE_(r_bin_pe_obj_t) { - // these pointers contain a copy of the headers and sections! - PE_(image_dos_header) * dos_header; - PE_(image_nt_headers) * nt_headers; - PE_(image_optional_header) * optional_header; //not free this just pointer into nt_headers - PE_(image_data_directory) * data_directory; //not free this just pointer into nt_headers - PE_(image_section_header) * section_header; - PE_(image_export_directory) * export_directory; - PE_(image_import_directory) * import_directory; - PE_(image_tls_directory) * tls_directory; - Pe_image_resource_directory* resource_directory; - PE_(image_delay_import_directory) * delay_import_directory; - Pe_image_security_directory * security_directory; - - // these pointers pertain to the .net relevant sections - PE_(image_clr_header) * clr_hdr; - PE_(image_metadata_header) * metadata_header; - PE_(image_metadata_stream) * *streams; - - /* store the section information for future use */ - struct r_bin_pe_section_t *sections; - - // these values define the real offset into the untouched binary - ut64 rich_header_offset; - ut64 nt_header_offset; - ut64 section_header_offset; - ut64 import_directory_offset; - ut64 export_directory_offset; - ut64 resource_directory_offset; - ut64 delay_import_directory_offset; - - int import_directory_size; - int size; - int num_sections; - int endian; - bool verbose; - int big_endian; - RList* rich_entries; - RList* relocs; - RList* resources; //RList of r_pe_resources - const char* file; - RBuffer* b; - Sdb *kv; - RCMS* cms; - SpcIndirectDataContent *spcinfo; - char *authentihash; - bool is_authhash_valid; - bool is_signed; -}; - -void PE_(r_bin_store_all_resource_version_info)(struct PE_(r_bin_pe_obj_t)* bin); -char* PE_(r_bin_pe_get_arch)(struct PE_(r_bin_pe_obj_t)* bin); -char *PE_(r_bin_pe_get_cc)(struct PE_(r_bin_pe_obj_t)* bin); -struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)* bin); -struct r_bin_pe_addr_t* PE_(r_bin_pe_get_main_vaddr)(struct PE_(r_bin_pe_obj_t)* bin); -struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* bin); // TODO -int PE_(r_bin_pe_get_file_alignment)(struct PE_(r_bin_pe_obj_t)* bin); -ut64 PE_(r_bin_pe_get_image_base)(struct PE_(r_bin_pe_obj_t)* bin); -struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* bin); // TODO -struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_get_image_size)(struct PE_(r_bin_pe_obj_t)* bin); -char* PE_(r_bin_pe_get_machine)(struct PE_(r_bin_pe_obj_t)* bin); -char* PE_(r_bin_pe_get_os)(struct PE_(r_bin_pe_obj_t)* bin); -char* PE_(r_bin_pe_get_class)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_get_bits)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_get_section_alignment)(struct PE_(r_bin_pe_obj_t)* bin); -char* PE_(r_bin_pe_get_subsystem)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_dll)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_big_endian)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_stripped_relocs)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_stripped_line_nums)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_stripped_local_syms)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(r_bin_pe_is_stripped_debug)(struct PE_(r_bin_pe_obj_t)* bin); -void* PE_(r_bin_pe_free)(struct PE_(r_bin_pe_obj_t)* bin); -struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new)(const char* file, bool verbose); -struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new_buf)(RBuffer* buf, bool verbose); -int PE_(r_bin_pe_get_debug_data)(struct PE_(r_bin_pe_obj_t)* bin, struct SDebugInfo* res); -int PE_(bin_pe_get_claimed_checksum)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin); -const char* PE_(bin_pe_compute_authentihash)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(bin_pe_is_authhash_valid)(struct PE_(r_bin_pe_obj_t)* bin); -int PE_(bin_pe_get_overlay)(struct PE_(r_bin_pe_obj_t)* bin, ut64* size); -void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_pe_section_t** sects); -struct r_bin_pe_addr_t *PE_(check_unknow) (struct PE_(r_bin_pe_obj_t) *bin); -struct r_bin_pe_addr_t *PE_(check_msvcseh) (struct PE_(r_bin_pe_obj_t) *bin); -struct r_bin_pe_addr_t *PE_(check_mingw) (struct PE_(r_bin_pe_obj_t) *bin); -bool PE_(r_bin_pe_section_perms)(RBinFile *bf, const char *name, int perms); -R_API void PE_(bin_pe_parse_resource) (struct PE_(r_bin_pe_obj_t) *bin); diff --git a/libr/bin/format/pe/pemixed.h b/libr/bin/format/pe/pemixed.h deleted file mode 100644 index a80c30f38e..0000000000 --- a/libr/bin/format/pe/pemixed.h +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include "pe.h" - -#define SUB_BIN_DOS 0 -#define SUB_BIN_NATIVE 1 -#define SUB_BIN_NET 2 - -#ifndef _INCLUDE_R_BIN_PEMIXED_H_ -#define _INCLUDE_R_BIN_PEMIXED_H_ - -struct r_bin_pemixed_obj_t { - const char* file; - int size; - struct PE_(r_bin_pe_obj_t)* sub_bin_dos; - struct PE_(r_bin_pe_obj_t)* sub_bin_native; - struct PE_(r_bin_pe_obj_t)* sub_bin_net; - - RBuffer* b; -}; - -// static int r_bin_pemixed_init(struct r_bin_pemixed_obj_t* bin, struct PE_(r_bin_pe_obj_t)* pe_bin); -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_dos(struct PE_(r_bin_pe_obj_t)* pe_bin); -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_native(struct PE_(r_bin_pe_obj_t)* pe_bin); -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_extract(struct r_bin_pemixed_obj_t* bin, int sub_bin); -// static bool check_il_only(ut32 flags); -void* r_bin_pemixed_free(struct r_bin_pemixed_obj_t* bin); -struct r_bin_pemixed_obj_t * r_bin_pemixed_from_bytes_new(const ut8* buf, ut64 size); - -#endif diff --git a/libr/bin/format/pyc/pyc.h b/libr/bin/format/pyc/pyc.h deleted file mode 100644 index ea69624ae8..0000000000 --- a/libr/bin/format/pyc/pyc.h +++ /dev/null @@ -1,16 +0,0 @@ -/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */ - -#ifndef PYC_H -#define PYC_H - -#include -#include -#include -#include -#include "pyc_magic.h" -#include "marshal.h" - -bool pyc_get_sections_symbols(RList *sections, RList *symbols, RList *mem, RBuffer *buf, ut32 magic); -bool pyc_is_code(ut8 b, ut32 magic); - -#endif diff --git a/libr/bin/format/te/te.h b/libr/bin/format/te/te.h deleted file mode 100644 index 64c9ca355f..0000000000 --- a/libr/bin/format/te/te.h +++ /dev/null @@ -1,60 +0,0 @@ -/* radare - LGPL - Copyright 2013 xvilka */ - -#include -#include -#include -#include -#include - -#ifndef _INCLUDE_R_BIN_TE_H_ -#define _INCLUDE_R_BIN_TE_H_ - -#define R_BIN_TE_SCN_IS_SHAREABLE(x) x & TE_IMAGE_SCN_MEM_SHARED -#define R_BIN_TE_SCN_IS_EXECUTABLE(x) x & TE_IMAGE_SCN_MEM_EXECUTE -#define R_BIN_TE_SCN_IS_READABLE(x) x & TE_IMAGE_SCN_MEM_READ -#define R_BIN_TE_SCN_IS_WRITABLE(x) x & TE_IMAGE_SCN_MEM_WRITE - -struct r_bin_te_section_t { - ut8 name[TE_IMAGE_SIZEOF_NAME]; - ut64 size; - ut64 vsize; - ut64 vaddr; - ut64 paddr; - ut64 flags; - int last; -}; - -struct r_bin_te_string_t { - char string[TE_STRING_LENGTH]; - ut64 vaddr; - ut64 paddr; - ut64 size; - char type; - int last; -}; - -struct r_bin_te_obj_t { - TE_image_file_header *header; - TE_image_section_header *section_header; - int size; - int endian; - const char* file; - RBuffer* b; - Sdb *kv; -}; - -char* r_bin_te_get_arch(struct r_bin_te_obj_t* bin); -RBinAddr* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin); -ut64 r_bin_te_get_main_paddr(struct r_bin_te_obj_t *bin); -ut64 r_bin_te_get_image_base(struct r_bin_te_obj_t* bin); -int r_bin_te_get_image_size(struct r_bin_te_obj_t* bin); -char* r_bin_te_get_machine(struct r_bin_te_obj_t* bin); -int r_bin_te_get_bits(struct r_bin_te_obj_t* bin); -char* r_bin_te_get_os(struct r_bin_te_obj_t* bin); -struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin); -char* r_bin_te_get_subsystem(struct r_bin_te_obj_t* bin); -void* r_bin_te_free(struct r_bin_te_obj_t* bin); -struct r_bin_te_obj_t* r_bin_te_new(const char* file); -struct r_bin_te_obj_t* r_bin_te_new_buf(RBuffer *buf); - -#endif diff --git a/libr/bin/format/zimg/zimg.c b/libr/bin/format/zimg/zimg.c deleted file mode 100644 index 5b827faa6d..0000000000 --- a/libr/bin/format/zimg/zimg.c +++ /dev/null @@ -1,28 +0,0 @@ -/* radare - LGPL - Copyright 2009-2015 - ninjahacker */ - -#include -#include -#include "zimg.h" - - -struct r_bin_zimg_obj_t* r_bin_zimg_new_buf(RBuffer *buf) { - struct r_bin_zimg_obj_t *bin = R_NEW0 (struct r_bin_zimg_obj_t); - if (!bin) { - goto fail; - } - bin->size = r_buf_size (buf); - bin->b = r_buf_ref (buf); - if (r_buf_size (bin->b) < sizeof (struct zimg_header_t)) { - goto fail; - } - r_buf_read_at (bin->b, 0, (ut8 *)&bin->header, sizeof (bin->header)); - return bin; - -fail: - if (bin) { - r_buf_free (bin->b); - free (bin); - } - return NULL; -} - diff --git a/libr/bin/i/private.h b/libr/bin/i/private.h deleted file mode 100644 index 0e7d5e74d3..0000000000 --- a/libr/bin/i/private.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef R_BIN_PRIVATE_H_ -#define R_BIN_PRIVATE_H_ - -#include -#include -#include - -R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr); -R_IPI RBinObject *r_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id); -R_IPI RList *r_bin_file_get_strings(RBinFile *a, int min, int dump, int raw); -R_IPI RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id); -R_IPI RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 binfile_id); -R_IPI RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx); -R_IPI bool r_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj); -R_IPI RBinFile *r_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr); -R_IPI bool r_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr); - -R_IPI RBinPlugin *r_bin_get_binplugin_any(RBin *bin); -R_IPI RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name); -R_IPI RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name); - -R_IPI void r_bin_section_free(RBinSection *bs); - -R_IPI void r_bin_object_free(void /*RBinObject*/ *o_); -R_IPI ut64 r_bin_object_get_baddr(RBinObject *o); -R_IPI void r_bin_object_filter_strings(RBinObject *bo); -R_IPI RBinObject *r_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz); -R_IPI RBinObject *r_bin_object_get_cur(RBin *bin); -R_IPI RBinObject *r_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name); -R_IPI RBNode *r_bin_object_patch_relocs(RBin *bin, RBinObject *o); - -R_IPI const char *r_bin_lang_tostring(int lang); -R_IPI int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym); -R_IPI bool r_bin_lang_swift(RBinFile *binfile); - -R_IPI void r_bin_class_free(RBinClass *c); -R_IPI RBinSymbol *r_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs); -R_IPI void r_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name); - -R_IPI RBinFile *r_bin_file_xtr_load_buffer(RBin *bin, RBinXtrPlugin *xtr, const char *filename, RBuffer *buf, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr); -R_IPI RBinFile *r_bin_file_new_from_buffer(RBin *bin, const char *file, RBuffer *buf, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname); -#endif diff --git a/libr/config/callback.c b/libr/config/callback.c deleted file mode 100644 index 355c4de7c0..0000000000 --- a/libr/config/callback.c +++ /dev/null @@ -1,56 +0,0 @@ -/* radare - LGPL - Copyright 2006-2019 - pancake */ - -#include "r_config.h" - -static bool r_config_setter_q(void *data) { - RConfigNode *node = data; - *(node->cb_ptr_q) = node->i_value; - return true; -} - -static bool r_config_setter_i(void *data) { - RConfigNode *node = data; - *(node->cb_ptr_i) = node->i_value; - return true; -} - -static bool r_config_setter_s(void *data) { - RConfigNode *node = data; - if (!node->value || !*node->value) { - free (*node->cb_ptr_s); - *node->cb_ptr_s = NULL; - } else { - *node->cb_ptr_s = r_str_dup (*node->cb_ptr_s, node->value); - } - return true; -} - -R_API bool r_config_set_setter_q(RConfig *cfg, const char *name, ut64 *ptr) { - RConfigNode *node = r_config_node_get (cfg, name); - if (node) { - node->cb_ptr_q = ptr; - node->setter = (void *) &r_config_setter_q; - return true; - } - return false; -} - -R_API bool r_config_set_setter_i(RConfig *cfg, const char *name, int *ptr) { - RConfigNode *node = r_config_node_get (cfg, name); - if (node) { - node->cb_ptr_i = ptr; - node->setter = (void *) &r_config_setter_i; - return true; - } - return false; -} - -R_API bool r_config_set_setter_s(RConfig *cfg, const char *name, char * *ptr) { - RConfigNode *node = r_config_node_get (cfg, name); - if (node) { - node->cb_ptr_s = ptr; - node->setter = (void *) &r_config_setter_s; - return true; - } - return false; -} diff --git a/libr/cons/line.c b/libr/cons/line.c deleted file mode 100644 index d17a51a43a..0000000000 --- a/libr/cons/line.c +++ /dev/null @@ -1,107 +0,0 @@ -/* radare - LGPL - Copyright 2007-2019 - pancake */ - -#include -#include - -static RLine r_line_instance; -#define I r_line_instance - -R_API RLine *r_line_singleton(void) { - return &r_line_instance; -} - -R_API RLine *r_line_new(void) { - I.hist_up = NULL; - I.hist_down = NULL; - I.prompt = strdup ("> "); - I.contents = NULL; - I.enable_vi_mode = false; - I.clipboard = NULL; - I.kill_ring = r_list_newf (NULL); - I.kill_ring_ptr = -1; -#if __WINDOWS__ - I.vtmode = r_cons_is_vtcompat (); -#else - I.vtmode = 2; -#endif - if (!r_line_dietline_init ()) { - eprintf ("error: r_line_dietline_init\n"); - } - r_line_completion_init (&I.completion, 4096); - return &I; -} - -R_API void r_line_free(void) { - // XXX: prompt out of the heap? - free ((void *)I.prompt); - I.prompt = NULL; - r_line_hist_free (); - r_line_completion_fini (&I.completion); -} - -R_API void r_line_clipboard_push (const char *str) { - I.kill_ring_ptr += 1; - r_list_insert (I.kill_ring, I.kill_ring_ptr, strdup (str)); -} - -// handle const or dynamic prompts? -R_API void r_line_set_prompt(const char *prompt) { - free (I.prompt); - I.prompt = strdup (prompt); - RCons *cons = r_cons_singleton (); - I.cb_fkey = cons->cb_fkey; -} - -// handle const or dynamic prompts? -R_API char *r_line_get_prompt(void) { - return strdup (I.prompt); -} - -R_API void r_line_completion_init(RLineCompletion *completion, size_t args_limit) { - completion->run = NULL; - completion->run_user = NULL; - completion->args_limit = args_limit; - r_pvector_init (&completion->args, free); -} - -R_API void r_line_completion_fini(RLineCompletion *completion) { - r_line_completion_clear (completion); -} - -R_API void r_line_completion_push(RLineCompletion *completion, const char *str) { - r_return_if_fail (completion && str); - if (completion->quit) { - return; - } - if (r_pvector_len (&completion->args) < completion->args_limit) { - char *s = strdup (str); - if (s) { - r_pvector_push (&completion->args, (void *)s); - } - } else { - completion->quit = true; - eprintf ("WARNING: Maximum completion capacity reached, increase scr.maxtab"); - } -} - -R_API void r_line_completion_set(RLineCompletion *completion, int argc, const char **argv) { - r_return_if_fail (completion && (argc >= 0)); - r_line_completion_clear (completion); - if (argc > completion->args_limit) { - eprintf ("WARNING: Maximum completion capacity reached, increase scr.maxtab"); - } - size_t count = R_MIN (argc, completion->args_limit); - r_pvector_reserve (&completion->args, count); - int i; - for (i = 0; i < count; i++) { - r_line_completion_push (completion, argv[i]); - } -} - -R_API void r_line_completion_clear(RLineCompletion *completion) { - r_return_if_fail (completion); - completion->quit = false; - r_pvector_clear (&completion->args); -} - -#include "dietline.c" diff --git a/libr/cons/pager_private.h b/libr/cons/pager_private.h deleted file mode 100644 index ed9cee1ed5..0000000000 --- a/libr/cons/pager_private.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef PAGER_PRIVATE_H -#define PAGER_PRIVATE_H - -R_IPI void pager_color_line(const char *line, RStrpool *p, RList *ml); -R_IPI void pager_printpage(const char *line, int *index, RList **mla, int from, int to, int w); -R_IPI int pager_next_match(int from, RList **mla, int lcount); -R_IPI int pager_prev_match(int from, RList **mla); -R_IPI bool pager_all_matches(const char *s, RRegex *rx, RList **mla, int *lines, int lcount); -R_IPI int *pager_splitlines(char *s, int *lines_count); - -#endif diff --git a/libr/core/cfile.c b/libr/core/cfile.c deleted file mode 100644 index 2e4d520d22..0000000000 --- a/libr/core/cfile.c +++ /dev/null @@ -1,1303 +0,0 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ - -#include -#include -#include - -#define UPDATE_TIME(a) (r->times->file_open_time = r_time_now_mono () - (a)) - -static int r_core_file_do_load_for_debug(RCore *r, ut64 loadaddr, const char *filenameuri); -static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loadaddr); - -static bool __isMips (RAsm *a) { - return a && a->cur && a->cur->arch && strstr (a->cur->arch, "mips"); -} - -static void loadGP(RCore *core) { - if (__isMips (core->rasm)) { - ut64 gp = r_num_math (core->num, "loc._gp"); - if (!gp || gp == UT64_MAX) { - r_config_set (core->config, "anal.roregs", "zero"); - r_core_cmd0 (core, "10aes@entry0"); - r_config_set (core->config, "anal.roregs", "zero,gp"); - gp = r_reg_getv (core->anal->reg, "gp"); - } - // eprintf ("[mips] gp: 0x%08"PFMT64x"\n", gp); - r_config_set_i (core->config, "anal.gp", gp); - } -} - - -R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int loadbin) { - int isdebug = r_config_get_i (core->config, "cfg.debug"); - char *path; - ut64 laddr = r_config_get_i (core->config, "bin.laddr"); - RCoreFile *file = NULL; - RCoreFile *ofile = core->file; - RBinFile *bf = ofile ? r_bin_file_find_by_fd (core->bin, ofile->fd) - : NULL; - RIODesc *odesc = (core->io && ofile) ? r_io_desc_get (core->io, ofile->fd) : NULL; - char *ofilepath = NULL, *obinfilepath = (bf && bf->file)? strdup (bf->file): NULL; - int ret = false; - ut64 origoff = core->offset; - if (odesc) { - if (odesc->referer) { - ofilepath = odesc->referer; - } else if (odesc->uri) { - ofilepath = odesc->uri; - } - } - - ut64 new_baddr = UT64_MAX; - if (args) { - new_baddr = r_num_math (core->num, args); - if (new_baddr && new_baddr != UT64_MAX) { - r_config_set_i (core->config, "bin.baddr", new_baddr); - } else { - new_baddr = UT64_MAX; - } - } - if (new_baddr == UT64_MAX) { - new_baddr = r_config_get_i (core->config, "bin.baddr"); - } - - if (r_sandbox_enable (0)) { - eprintf ("Cannot reopen in sandbox\n"); - free (obinfilepath); - return false; - } - if (!core->file) { - eprintf ("No file opened to reopen\n"); - free (ofilepath); - free (obinfilepath); - return false; - } - int newpid = odesc? odesc->fd: -1; - - if (isdebug) { - r_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, 9); // SIGKILL - do { - r_debug_continue (core->dbg); - } while (!r_debug_is_dead (core->dbg)); - r_debug_detach (core->dbg, core->dbg->pid); - perm = 7; - } else { - if (!perm) { - perm = 4; //R_PERM_R; - } - } - if (!ofilepath) { - eprintf ("Unknown file path"); - free (obinfilepath); - return false; - } - - // HACK: move last mapped address to higher place - // XXX - why does this hack work? - // when the new memory maps are created. - path = strdup (ofilepath); - free (obinfilepath); - obinfilepath = strdup (ofilepath); - - // r_str_trim (path); - file = r_core_file_open (core, path, perm, laddr); - - if (isdebug) { - int newtid = newpid; - // XXX - select the right backend - if (core->file) { - newpid = r_io_fd_get_pid (core->io, core->file->fd); - newtid = r_io_fd_get_tid (core->io, core->file->fd); -#if __linux__ - core->dbg->main_pid = newpid; - newtid = newpid; -#endif - } - // Reset previous pid and tid - core->dbg->pid = -1; - core->dbg->tid = -1; - core->dbg->recoil_mode = R_DBG_RECOIL_NONE; - memset (&core->dbg->reason, 0, sizeof (core->dbg->reason)); - // Reopen and attach - r_core_setup_debugger (core, "native", true); - r_debug_select (core->dbg, newpid, newtid); - } - - if (file) { - bool had_rbin_info = false; - - if (ofile && bf) { - if (r_bin_file_delete (core->bin, bf->id)) { - had_rbin_info = true; - } - } - r_core_file_close (core, ofile); - r_core_file_set_by_file (core, file); - ofile = NULL; - odesc = NULL; - // core->file = file; - eprintf ("File %s reopened in %s mode\n", path, - (perm & R_PERM_W)? "read-write": "read-only"); - - if (loadbin && (loadbin == 2 || had_rbin_info)) { - ut64 baddr; - if (isdebug) { - baddr = r_debug_get_baddr (core->dbg, path); - } else if (new_baddr != UT64_MAX) { - baddr = new_baddr; - } else { - baddr = r_config_get_i (core->config, "bin.baddr"); - } - ret = r_core_bin_load (core, obinfilepath, baddr); - r_core_bin_update_arch_bits (core); - if (!ret) { - eprintf ("Error: Failed to reload rbin for: %s", path); - } - origoff = r_num_math (core->num, "entry0"); - } - - if (core->bin->cur && core->io && r_io_desc_get (core->io, file->fd) && !loadbin) { - //force here NULL because is causing uaf look this better in future XXX @alvarofe - core->bin->cur = NULL; - } - // close old file - } else if (ofile) { - eprintf ("r_core_file_reopen: Cannot reopen file: %s with perms 0x%x," - " attempting to open read-only.\n", path, perm); - // lower it down back - //ofile = r_core_file_open (core, path, R_PERM_R, addr); - r_core_file_set_by_file (core, ofile); - } else { - eprintf ("Cannot reopen\n"); - } - if (core->file) { - r_io_use_fd (core->io, core->file->fd); - core->switch_file_view = 1; - r_core_block_read (core); -#if 0 - else { - const char *name = (cf && cf->desc)? cf->desc->name: "ERROR"; - eprintf ("Error: Unable to switch the view to file: %s\n", name); - } -#endif - } - r_core_seek (core, origoff, true); - if (isdebug) { - r_core_cmd0 (core, ".dm*"); - r_core_cmd0 (core, ".dr*"); - r_core_cmd0 (core, "sr PC"); - } else { - loadGP (core); - } - // update anal io bind - r_io_bind (core->io, &(core->anal->iob)); - if (core->file && core->file->fd >= 0) { - r_core_cmd0 (core, "o-!"); - } - r_core_file_close_all_but (core); - // This is done to ensure that the file is correctly - // loaded into the view - free (obinfilepath); - //free (ofilepath); - free (path); - return ret; -} - -R_API void r_core_sysenv_end(RCore *core, const char *cmd) { - // TODO: remove tmpfilez - if (strstr (cmd, "R2_BLOCK")) { - // remove temporary BLOCK file - char *f = r_sys_getenv ("R2_BLOCK"); - if (f) { - r_file_rm (f); - r_sys_setenv ("R2_BLOCK", NULL); - free (f); - } - } - r_sys_setenv ("R2_FILE", NULL); - r_sys_setenv ("R2_BYTES", NULL); - r_sys_setenv ("R2_OFFSET", NULL); - - // remove temporary R2_CONFIG file - char *r2_config = r_sys_getenv ("R2_CONFIG"); - if (r2_config) { - r_file_rm (r2_config); - r_sys_setenv ("R2_CONFIG", NULL); - free (r2_config); - } -} - -#if DISCUSS -EDITOR r_sys_setenv ("EDITOR", r_config_get (core->config, "cfg.editor")); -CURSOR cursor position (offset from curseek) -VERBOSE cfg.verbose -#endif - -R_API char *r_core_sysenv_begin(RCore * core, const char *cmd) { - char *f, *ret = cmd? strdup (cmd): NULL; - RIODesc *desc = core->file ? r_io_desc_get (core->io, core->file->fd) : NULL; - if (cmd && strstr (cmd, "R2_BYTES")) { - char *s = r_hex_bin2strdup (core->block, core->blocksize); - r_sys_setenv ("R2_BYTES", s); - free (s); - } - r_sys_setenv ("RABIN2_PDBSERVER", r_config_get (core->config, "pdb.server")); - if (desc && desc->name) { - r_sys_setenv ("R2_FILE", desc->name); - r_sys_setenv ("R2_SIZE", sdb_fmt ("%"PFMT64d, r_io_desc_size (desc))); - if (cmd && strstr (cmd, "R2_BLOCK")) { - // replace BLOCK in RET string - if ((f = r_file_temp ("r2block"))) { - if (r_file_dump (f, core->block, core->blocksize, 0)) { - r_sys_setenv ("R2_BLOCK", f); - } - free (f); - } - } - } - r_sys_setenv ("R2_OFFSET", sdb_fmt ("%"PFMT64d, core->offset)); - r_sys_setenv ("R2_XOFFSET", sdb_fmt ("0x%08"PFMT64x, core->offset)); - r_sys_setenv ("R2_ENDIAN", core->rasm->big_endian? "big": "little"); - r_sys_setenv ("R2_BSIZE", sdb_fmt ("%d", core->blocksize)); - - // dump current config file so other r2 tools can use the same options - char *config_sdb_path = NULL; - int config_sdb_fd = r_file_mkstemp (NULL, &config_sdb_path); - if (config_sdb_fd >= 0) { - close (config_sdb_fd); - } - - Sdb *config_sdb = sdb_new (NULL, config_sdb_path, 0); - r_config_serialize (core->config, config_sdb); - sdb_sync (config_sdb); - sdb_free (config_sdb); - r_sys_setenv ("R2_CONFIG", config_sdb_path); - - r_sys_setenv ("RABIN2_LANG", r_config_get (core->config, "bin.lang")); - r_sys_setenv ("RABIN2_DEMANGLE", r_config_get (core->config, "bin.demangle")); - r_sys_setenv ("R2_ARCH", r_config_get (core->config, "asm.arch")); - r_sys_setenv ("R2_BITS", sdb_fmt ("%d", r_config_get_i (core->config, "asm.bits"))); - r_sys_setenv ("R2_COLOR", r_config_get_i (core->config, "scr.color")? "1": "0"); - r_sys_setenv ("R2_DEBUG", r_config_get_i (core->config, "cfg.debug")? "1": "0"); - r_sys_setenv ("R2_IOVA", r_config_get_i (core->config, "io.va")? "1": "0"); - free (config_sdb_path); - return ret; -} - -#if !__linux__ && !__WINDOWS__ -static ut64 get_base_from_maps(RCore *core, const char *file) { - RDebugMap *map; - RListIter *iter; - ut64 b = 0LL; - - r_debug_map_sync (core->dbg); // update process memory maps - r_list_foreach (core->dbg->maps, iter, map) { - if ((map->perm & 5) == 5) { - // TODO: make this more flexible - // XXX - why "copy/" here? - if (map->name && strstr (map->name, "copy/")) { - return map->addr; - } - if (map->file && !strcmp (map->file, file)) { - return map->addr; - } - if (map->name && !strcmp (map->name, file)) { - return map->addr; - } - // XXX - Commented out, as this could unexpected results - //b = map->addr; - } - } - // fallback resolution copied from cmd_debug.c:r_debug_get_baddr - r_list_foreach (core->dbg->maps, iter, map) { - if (map->perm == 5) { // r-x - return map->addr; - } - } - - return b; -} -#endif - -#if __linux__ || __APPLE__ -static bool setbpint(RCore *r, const char *mode, const char *sym) { - RBreakpointItem *bp; - RFlagItem *fi = r_flag_get (r->flags, sym); - if (!fi) { - return false; - } - bp = r_bp_add_sw (r->dbg->bp, fi->offset, 1, R_BP_PROT_EXEC); - if (bp) { - bp->internal = true; -#if __linux__ - bp->data = r_str_newf ("?e %s: %s", mode, sym); -#else - bp->data = r_str_newf ("?e %s: %s;ps@rdi", mode, sym); -#endif - return true; - } - eprintf ("Cannot set breakpoint at %s\n", sym); - return false; -} -#endif - -// XXX - need to handle index selection during debugging -static int r_core_file_do_load_for_debug(RCore *r, ut64 baseaddr, const char *filenameuri) { - RCoreFile *cf = r_core_file_cur (r); - RIODesc *desc = cf ? r_io_desc_get (r->io, cf->fd) : NULL; - RBinFile *binfile = NULL; - RBinPlugin *plugin; - int xtr_idx = 0; // if 0, load all if xtr is used - - // TODO : Honor file.path eval var too? - if (!strncmp ("dbg://", filenameuri, 6)) { - filenameuri += 6; - } - if (!desc) { - return false; - } - if (cf) { - r_debug_select (r->dbg, r_io_fd_get_pid (r->io, cf->fd), - r_io_fd_get_tid (r->io, cf->fd)); - } -#if !__linux__ -#if !__WINDOWS__ - baseaddr = get_base_from_maps (r, filenameuri); -#endif - if (baseaddr != UT64_MAX) { - r_config_set_i (r->config, "bin.baddr", baseaddr); - } -#endif - int fd = cf? cf->fd: -1; - RBinOptions opt; - r_bin_options_init (&opt, fd, baseaddr, UT64_MAX, false); - opt.xtr_idx = xtr_idx; - if (!r_bin_open (r->bin, filenameuri, &opt)) { - eprintf ("RBinLoad: Cannot open %s\n", filenameuri); - if (r_config_get_i (r->config, "bin.rawstr")) { - r_bin_options_init (&opt, fd, baseaddr, UT64_MAX, true); - opt.xtr_idx = xtr_idx; - if (!r_bin_open (r->bin, filenameuri, &opt)) { - return false; - } - } - } - - if (*r_config_get (r->config, "dbg.libs")) { - r_core_cmd0 (r, ".dmm*"); -#if __linux__ - setbpint (r, "dbg.libs", "sym.imp.dlopen"); - setbpint (r, "dbg.libs", "sym.imp.dlmopen"); - setbpint (r, "dbg.unlibs", "sym.imp.dlclose"); -#elif __APPLE__ - setbpint (r, "dbg.libs", "sym._dlopen"); - setbpint (r, "dbg.libs", "sym._dlclose"); -#endif - } - binfile = r_bin_cur (r->bin); - r_core_bin_set_env (r, binfile); - plugin = r_bin_file_cur_plugin (binfile); - if (plugin && !strncmp (plugin->name, "any", 5)) { - // set use of raw strings - // r_config_set_i (r->config, "io.va", false); - //\\ r_config_set (r->config, "bin.rawstr", "true"); - // get bin.minstr - r->bin->minstrlen = r_config_get_i (r->config, "bin.minstr"); - r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf"); - } else if (binfile) { - RBinObject *obj = r_bin_cur_object (r->bin); - RBinInfo *info = obj? obj->info: NULL; - if (plugin && strcmp (plugin->name, "any") && info) { - r_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); - } - } - - if (plugin && !strcmp (plugin->name, "dex")) { - r_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ; wx `ph adler32 $s-12 @12` @8)\"\n"); - } - - return true; -} - -static int r_core_file_do_load_for_io_plugin(RCore *r, ut64 baseaddr, ut64 loadaddr) { - RCoreFile *cf = r_core_file_cur (r); - int fd = cf ? cf->fd : -1; - RBinFile *binfile = NULL; - int xtr_idx = 0; // if 0, load all if xtr is used - RBinPlugin *plugin; - - if (fd < 0) { - return false; - } - r_io_use_fd (r->io, fd); - RBinOptions opt; - r_bin_options_init (&opt, fd, baseaddr, loadaddr, r->bin->rawstr); - opt.xtr_idx = xtr_idx; - if (!r_bin_open_io (r->bin, &opt)) { - //eprintf ("Failed to load the bin with an IO Plugin.\n"); - return false; - } - binfile = r_bin_cur (r->bin); - if (r_core_bin_set_env (r, binfile)) { - if (!r->anal->sdb_cc->path) { - R_LOG_WARN ("No calling convention defined for this file, analysis may be inaccurate.\n"); - } - } - plugin = r_bin_file_cur_plugin (binfile); - if (plugin && !strcmp (plugin->name, "any")) { - RBinObject *obj = r_bin_cur_object (r->bin); - RBinInfo *info = obj? obj->info: NULL; - if (!info) { - return false; - } - // set use of raw strings - r_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); - // r_config_set_i (r->config, "io.va", false); - // r_config_set (r->config, "bin.rawstr", "true"); - // get bin.minstr - r->bin->minstrlen = r_config_get_i (r->config, "bin.minstr"); - r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf"); - } else if (binfile) { - RBinObject *obj = r_bin_cur_object (r->bin); - RBinInfo *info = obj? obj->info: NULL; - if (!info) { - return false; - } - if (plugin && strcmp (plugin->name, "any") && info) { - r_core_bin_set_arch_bits (r, binfile->file, - info->arch, info->bits); - } - } - - if (plugin && !strcmp (plugin->name, "dex")) { - r_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ; wx `ph adler32 $s-12 @12` @8)\"\n"); - } - return true; -} - -static bool try_loadlib(RCore *core, const char *lib, ut64 addr) { - if (r_core_file_open (core, lib, 0, addr) != NULL) { - r_core_bin_load (core, lib, addr); - return true; - } - return false; -} - -R_API bool r_core_file_loadlib(RCore *core, const char *lib, ut64 libaddr) { - const char *dirlibs = r_config_get (core->config, "dir.libs"); - bool free_libdir = true; -#ifdef __WINDOWS__ - char *libdir = r_str_r2_prefix (R2_LIBDIR); -#else - char *libdir = strdup (R2_LIBDIR); -#endif - if (!libdir) { - libdir = R2_LIBDIR; - free_libdir = false; - } - if (!dirlibs || !*dirlibs) { - dirlibs = "." R_SYS_DIR; - } - const char *ldlibrarypath[] = { - dirlibs, - libdir, -#ifndef __WINDOWS__ - "/usr/local/lib", - "/usr/lib", - "/lib", -#endif - "." R_SYS_DIR, - NULL - }; - const char * *libpath = (const char * *) &ldlibrarypath; - - bool ret = false; -#ifdef __WINDOWS__ - if (strlen (lib) >= 3 && lib[1] == ':' && lib[2] == '\\') { -#else - if (*lib == '/') { -#endif - if (try_loadlib (core, lib, libaddr)) { - ret = true; - } - } else { - while (*libpath) { - char *s = r_str_newf ("%s" R_SYS_DIR "%s", *libpath, lib); - if (try_loadlib (core, s, libaddr)) { - ret = true; - } - free (s); - if (ret) { - break; - } - libpath++; - } - } - if (free_libdir) { - free (libdir); - } - return ret; -} - -R_API int r_core_bin_rebase(RCore *core, ut64 baddr) { - if (!core || !core->bin || !core->bin->cur) { - return 0; - } - if (baddr == UT64_MAX) { - return 0; - } - RBinFile *bf = core->bin->cur; - bf->o->baddr = baddr; - bf->o->loadaddr = baddr; - r_bin_object_set_items (bf, bf->o); - return 1; -} - -static void load_scripts_for(RCore *core, const char *name) { - // TODO: - char *file; - RListIter *iter; - char *hdir = r_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name); - char *path = r_str_home (hdir); - RList *files = r_sys_dir (path); - if (!r_list_empty (files)) { - eprintf ("[binrc] path: %s\n", path); - } - r_list_foreach (files, iter, file) { - if (*file && *file != '.') { - eprintf ("[binrc] loading %s\n", file); - r_core_cmdf (core, ". %s/%s", path, file); - } - } - r_list_free (files); - free (path); - free (hdir); -} - -typedef struct { - const char *name; - bool found; -} RCoreFileData; - -static bool filecb(void *user, void *data, ut32 id) { - RCoreFileData *fd = user; - RIODesc *desc = (RIODesc *)data; - if (!strcmp (desc->name, fd->name)) { - fd->found = true; - } - return true; -} - -typedef struct { - const char *name; - ut64 addr; - RBin *bin; -} RCoreLinkData; - -static bool linkcb(void *user, void *data, ut32 id) { - RCoreLinkData *ld = user; - RIODesc *desc = (RIODesc *)data; - - RBinFile *bf = r_bin_file_find_by_fd (ld->bin, desc->fd); - if (bf) { - RListIter *iter; - RBinSymbol *sym; - RList *symbols = r_bin_file_get_symbols (bf); - r_list_foreach (symbols, iter, sym) { - if (!strcmp (sym->name, ld->name)) { - ld->addr = sym->vaddr; - return false; - } - } - } - return true; -} - - -R_API bool r_core_bin_load(RCore *r, const char *filenameuri, ut64 baddr) { - RCoreFile *cf = r_core_file_cur (r); - RIODesc *desc = cf ? r_io_desc_get (r->io, cf->fd) : NULL; - ut64 laddr = r_config_get_i (r->config, "bin.laddr"); - RBinFile *binfile = NULL; - RBinPlugin *plugin = NULL; - bool is_io_load; - const char *cmd_load; - if (!cf) { - return false; - } - // NULL deref guard - if (desc) { - is_io_load = desc && desc->plugin; - if (!filenameuri || !*filenameuri) { - filenameuri = desc->name; - } - } else { - is_io_load = false; - } - - if (!filenameuri) { - eprintf ("r_core_bin_load: no file specified\n"); - return false; - } - - r->bin->minstrlen = r_config_get_i (r->config, "bin.minstr"); - r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf"); - if (is_io_load) { - // TODO? necessary to restore the desc back? - // Fix to select pid before trying to load the binary - if ((desc->plugin && desc->plugin->isdbg) || r_config_get_i (r->config, "cfg.debug")) { - r_core_file_do_load_for_debug (r, baddr, filenameuri); - } else { - r_core_file_do_load_for_io_plugin (r, baddr, 0LL); - } - r_io_use_fd (r->io, desc->fd); - // Restore original desc - } - if (cf && binfile && desc) { - binfile->fd = desc->fd; - } - binfile = r_bin_cur (r->bin); - if (r->bin->cur && r->bin->cur->o && r->bin->cur->o->plugin && r->bin->cur->o->plugin->strfilter) { - char msg[2]; - msg[0] = r->bin->cur->o->plugin->strfilter; - msg[1] = 0; - r_config_set (r->config, "bin.str.filter", msg); - } - //r_core_bin_set_env (r, binfile); - plugin = r_bin_file_cur_plugin (binfile); - if (plugin && plugin->name) { - load_scripts_for (r, plugin->name); - } - cmd_load = r_config_get (r->config, "cmd.load"); - if (cmd_load && *cmd_load) { - r_core_cmd (r, cmd_load, 0); - } - - if (plugin && plugin->name) { - if (!strcmp (plugin->name, "any")) { - if (r_str_startswith (desc->name, "rap") && strstr (desc->name, "://")) { - r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, UT64_MAX); - } else { - r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc)); - } - // set use of raw strings - //r_config_set (r->config, "bin.rawstr", "true"); - // r_config_set_i (r->config, "io.va", false); - // get bin.minstr - r->bin->minstrlen = r_config_get_i (r->config, "bin.minstr"); - r->bin->maxstrbuf = r_config_get_i (r->config, "bin.maxstrbuf"); - } else if (binfile) { - RBinObject *obj = r_bin_cur_object (r->bin); - if (obj) { - bool va = obj->info ? obj->info->has_va : 0; - if (!va) { - r_config_set_i (r->config, "io.va", 0); - } - //workaround to map correctly malloc:// and raw binaries - if (r_io_desc_is_dbg (desc) || (!obj->sections || !va)) { - r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc)); - } - RBinInfo *info = obj->info; - if (info) { - r_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); - } else { - r_core_bin_set_arch_bits (r, binfile->file, - r_config_get (r->config, "asm.arch"), - r_config_get_i (r->config, "asm.bits")); - } - } - } - } else { - if (desc) { - r_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, r_io_desc_size (desc)); - } - if (binfile) { - r_core_bin_set_arch_bits (r, binfile->file, - r_config_get (r->config, "asm.arch"), - r_config_get_i (r->config, "asm.bits")); - } - } - if (desc && r_config_get_i (r->config, "io.exec")) { - desc->perm |= R_PERM_X; - } - if (plugin && plugin->name && !strcmp (plugin->name, "dex")) { - r_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ;" - " wx `ph adler32 $s-12 @12` @8)\"\n"); - } - if (!r_config_get_i (r->config, "cfg.debug")) { - loadGP (r); - } - if (r_config_get_i (r->config, "bin.libs")) { - const char *lib; - RListIter *iter; - RList *libs = r_bin_get_libs (r->bin); - r_list_foreach (libs, iter, lib) { - eprintf ("[bin.libs] Opening %s\n", lib); - RCoreFileData filedata = {lib, false}; - r_id_storage_foreach (r->io->files, filecb, &filedata); - if (filedata.found) { - eprintf ("Already opened\n"); - continue; - } - ut64 baddr = r_io_map_location (r->io, 0x200000); - if (baddr != UT64_MAX) { - r_core_file_loadlib (r, lib, baddr); - } - } - r_core_cmd0 (r, "obb 0;s entry0"); - r_config_set_i (r->config, "bin.at", true); - eprintf ("[bin.libs] Linking imports...\n"); - RBinImport *imp; - RList *imports = r_bin_get_imports (r->bin); - r_list_foreach (imports, iter, imp) { - // PLT finding - RFlagItem *impsym = r_flag_get (r->flags, sdb_fmt ("sym.imp.%s", imp->name)); - if (!impsym) { - //eprintf ("Cannot find '%s' import in the PLT\n", imp->name); - continue; - } - ut64 imp_addr = impsym->offset; - eprintf ("Resolving %s... ", imp->name); - RCoreLinkData linkdata = {imp->name, UT64_MAX, r->bin}; - r_id_storage_foreach (r->io->files, linkcb, &linkdata); - if (linkdata.addr != UT64_MAX) { - eprintf ("0x%08"PFMT64x"\n", linkdata.addr); - ut64 a = linkdata.addr; - ut64 b = imp_addr; - r_core_cmdf (r, "ax 0x%08"PFMT64x" 0x%08"PFMT64x, a, b); - } else { - eprintf ("NO\n"); - } - } - } - - //If type == R_BIN_TYPE_CORE, we need to create all the maps - if (plugin && binfile && plugin->file_type - && plugin->file_type (binfile) == R_BIN_TYPE_CORE) { - ut64 sp_addr = (ut64)-1; - RIOMap *stack_map = NULL; - - // Setting the right arch and bits, so regstate will be shown correctly - if (plugin->info) { - RBinInfo *inf = plugin->info (binfile); - eprintf ("Setting up coredump arch-bits to: %s-%d\n", inf->arch, inf->bits); - r_config_set (r->config, "asm.arch", inf->arch); - r_config_set_i (r->config, "asm.bits", inf->bits); - r_bin_info_free (inf); - } - if (binfile->o->regstate) { - if (r_reg_arena_set_bytes (r->anal->reg, binfile->o->regstate)) { - eprintf ("Setting up coredump: Problem while setting the registers\n"); - } else { - eprintf ("Setting up coredump: Registers have been set\n"); - const char *regname = r_reg_get_name (r->anal->reg, R_REG_NAME_SP); - if (regname) { - RRegItem *reg = r_reg_get (r->anal->reg, regname, -1); - if (reg) { - sp_addr = r_reg_get_value (r->anal->reg, reg); - stack_map = r_io_map_get (r->io, sp_addr); - } - } - regname = r_reg_get_name (r->anal->reg, R_REG_NAME_PC); - if (regname) { - RRegItem *reg = r_reg_get (r->anal->reg, regname, -1); - if (reg) { - ut64 seek = r_reg_get_value (r->anal->reg, reg); - r_core_seek (r, seek, true); - } - } - } - } - - RBinObject *o = binfile->o; - int map = 0; - if (o && o->maps) { - RList *maps = o->maps; - RListIter *iter; - RBinMap *mapcore; - - r_list_foreach (maps, iter, mapcore) { - RIOMap *iomap = r_io_map_get (r->io, mapcore->addr); - if (iomap && (mapcore->file || stack_map == iomap)) { - r_io_map_set_name (iomap, mapcore->file ? mapcore->file : "[stack]"); - } - map++; - } - r_list_free (maps); - o->maps = NULL; - } - eprintf ("Setting up coredump: %d maps have been found and created\n", map); - goto beach; - } -beach: - return true; -} - -R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int perm, ut64 loadaddr) { - const bool openmany = r_config_get_i (r->config, "file.openmany"); - int opened_count = 0; - RListIter *fd_iter, *iter2; - RIODesc *fd; - - RList *list_fds = r_io_open_many (r->io, file, perm, 0644); - - if (!list_fds || r_list_length (list_fds) == 0) { - r_list_free (list_fds); - return NULL; - } - - r_list_foreach_safe (list_fds, fd_iter, iter2, fd) { - opened_count++; - if (openmany && opened_count > 1) { - // XXX - Open Many should limit the number of files - // loaded in io plugin area this needs to be more premptive - // like down in the io plugin layer. - // start closing down descriptors - r_list_delete (list_fds, fd_iter); - continue; - } - RCoreFile *fh = R_NEW0 (RCoreFile); - if (fh) { - fh->alive = 1; - fh->core = r; - fh->fd = fd->fd; - r->file = fh; - r_bin_bind (r->bin, &(fh->binb)); - r_list_append (r->files, fh); - r_core_bin_load (r, fd->name, loadaddr); - } - } - return NULL; -} - -/* loadaddr is r2 -m (mapaddr) */ -R_API RCoreFile *r_core_file_open(RCore *r, const char *file, int flags, ut64 loadaddr) { - r_return_val_if_fail (r && file, NULL); - ut64 prev = r_time_now_mono (); - const bool openmany = r_config_get_i (r->config, "file.openmany"); - RCoreFile *fh = NULL; - - if (!strcmp (file, "-")) { - file = "malloc://512"; - } - //if not flags was passed open it with -r-- - if (!flags) { - flags = R_PERM_R; - } - r->io->bits = r->rasm->bits; // TODO: we need an api for this - RIODesc *fd = r_io_open_nomap (r->io, file, flags, 0644); - if (r_cons_is_breaked()) { - goto beach; - } - if (!fd && openmany) { - // XXX - make this an actual option somewhere? - fh = r_core_file_open_many (r, file, flags, loadaddr); - if (fh) { - goto beach; - } - } - if (!fd) { - if (flags & R_PERM_W) { - // flags |= R_IO_CREAT; - if (!(fd = r_io_open_nomap (r->io, file, flags, 0644))) { - goto beach; - } - } else { - goto beach; - } - } - if (r_io_is_listener (r->io)) { - r_core_serve (r, fd); - r_io_desc_free (fd); - goto beach; - } - - fh = R_NEW0 (RCoreFile); - if (!fh) { - eprintf ("core/file.c: r_core_open failed to allocate RCoreFile.\n"); - goto beach; - } - fh->alive = 1; - fh->core = r; - fh->fd = fd->fd; - { - const char *cp = r_config_get (r->config, "cmd.open"); - if (cp && *cp) { - r_core_cmd (r, cp, 0); - } - char *absfile = r_file_abspath (file); - r_config_set (r->config, "file.path", absfile); - free (absfile); - } - // check load addr to make sure its still valid - r_bin_bind (r->bin, &(fh->binb)); - - if (!r->files) { - r->files = r_list_newf ((RListFree)r_core_file_free); - } - - r->file = fh; - r_io_use_fd (r->io, fd->fd); - - r_list_append (r->files, fh); - if (r_config_get_i (r->config, "cfg.debug")) { - bool swstep = true; - if (r->dbg->h && r->dbg->h->canstep) { - swstep = false; - } - r_config_set_i (r->config, "dbg.swstep", swstep); - // Set the correct debug handle - if (fd->plugin && fd->plugin->isdbg) { - char *dh = r_str_ndup (file, (strstr (file, "://") - file)); - if (dh) { - r_debug_use (r->dbg, dh); - free (dh); - } - } - } - //used by r_core_bin_load otherwise won't load correctly - //this should be argument of r_core_bin_load - if (loadaddr != UT64_MAX) { - r_config_set_i (r->config, "bin.laddr", loadaddr); - } - r_core_cmd0 (r, "=!"); -beach: - r->times->file_open_time = r_time_now_mono () - prev; - return fh; -} - -R_API void r_core_file_free(RCoreFile *cf) { - int res = 1; - - r_return_if_fail (cf); - - if (!cf->core) { - free (cf); - return; - } - res = r_list_delete_data (cf->core->files, cf); - if (res && cf->alive) { - // double free libr/io/io.c:70 performs free - RIO *io = cf->core->io; - if (io) { - RBin *bin = cf->binb.bin; - RBinFile *bf = r_bin_cur (bin); - if (bf) { - r_bin_file_deref (bin, bf); - } - r_io_fd_close (io, cf->fd); - free (cf); - } - } -} - -R_API int r_core_file_close(RCore *r, RCoreFile *fh) { - int ret; - RIODesc *desc = fh && r ? r_io_desc_get (r->io, fh->fd) : NULL; - RCoreFile *prev_cf = r && r->file != fh? r->file: NULL; - - // TODO: This is not correctly done. because map and iodesc are - // still referenced // we need to fully clear all R_IO structs - // related to a file as well as the ones needed for RBin. - // - // XXX -these checks are intended to *try* and catch - // stale objects. Unfortunately, if the file handle - // (fh) is stale and freed, and there is more than 1 - // fh in the r->files list, we are hosed. (design flaw) - // TODO maybe using sdb to keep track of the allocated and - // deallocated files might be a good solutions - if (!r || !desc || r_list_empty (r->files)) { - return false; - } - - if (fh == r->file) { - r->file = NULL; - } - - r_core_file_set_by_fd (r, fh->fd); - r_core_bin_set_by_fd (r, fh->fd); - - /* delete filedescriptor from io descs here */ - // r_io_desc_del (r->io, fh->fd); - - // AVOID DOUBLE FREE HERE - r->files->free = NULL; - - ret = r_list_delete_data (r->files, fh); - if (ret) { - if (!prev_cf && r_list_length (r->files) > 0) { - prev_cf = (RCoreFile *) r_list_get_n (r->files, 0); - } - - if (prev_cf) { - RIODesc *desc = prev_cf && r ? r_io_desc_get (r->io, prev_cf->fd) : NULL; - if (!desc) { - eprintf ("Error: RCoreFile's found with out a supporting RIODesc.\n"); - } - ret = r_core_file_set_by_file (r, prev_cf); - } - } - r_io_desc_close (desc); - r_core_file_free (fh); - return ret; -} - -R_API RCoreFile *r_core_file_get_by_fd(RCore *core, int fd) { - RCoreFile *file; - RListIter *iter; - r_list_foreach (core->files, iter, file) { - if (file->fd == fd) { - return file; - } - } - return NULL; -} - -R_API int r_core_file_list(RCore *core, int mode) { - int count = 0; - RCoreFile *f; - RIODesc *desc; - ut64 from; - RListIter *it; - RBinFile *bf; - RListIter *iter; - if (mode == 'j') { - r_cons_printf ("["); - } - r_list_foreach (core->files, iter, f) { - desc = r_io_desc_get (core->io, f->fd); - if (!desc) { - // cannot find desc for this fd, RCoreFile inconsistency!!!1 - continue; - } - from = 0LL; - switch (mode) { - case 'j': - r_cons_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%" - PFMT64d ",\"writable\":%s,\"size\":%d}%s", - r_str_bool (core->io->desc->fd == f->fd), - (int) f->fd, desc->uri, (ut64) from, - r_str_bool (desc->perm & R_PERM_W), - (int) r_io_desc_size (desc), - iter->n? ",": ""); - break; - case '*': - case 'r': - // TODO: use a getter - { - bool fileHaveBin = false; - char *absfile = r_file_abspath (desc->uri); - r_list_foreach (core->bin->binfiles, it, bf) { - if (bf->fd == f->fd) { - r_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from); - fileHaveBin = true; - } - } - if (!fileHaveBin && !strstr (absfile, "://")) { - r_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from); - } - free (absfile); - } - break; - case 'n': - { - bool header_loaded = false; - r_list_foreach (core->bin->binfiles, it, bf) { - if (bf->fd == f->fd) { - header_loaded = true; - break; - } - } - if (!header_loaded) { - RList* maps = r_io_map_get_for_fd (core->io, f->fd); - RListIter *iter; - RIOMap* current_map; - char *absfile = r_file_abspath (desc->uri); - r_list_foreach (maps, iter, current_map) { - if (current_map) { - r_cons_printf ("on %s 0x%"PFMT64x "\n", absfile, current_map->itv.addr); - } - } - r_list_free (maps); - free(absfile); - - } - } - break; - default: - { - ut64 sz = r_io_desc_size (desc); - const char *fmt; - if (sz == UT64_MAX) { - fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64d "\n"; - } else { - fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64u "\n"; - } - r_cons_printf (fmt, - core->io->desc->fd == f->fd ? '*': '-', - count, - (int) f->fd, desc->uri, (ut64) from, - desc->perm & R_PERM_W? "rw": "r", - r_io_desc_size (desc)); - } - break; - } - count++; - } - if (mode == 'j') { - r_cons_printf ("]\n"); - } - return count; -} - -// XXX - needs to account for binfile index and bin object index -R_API bool r_core_file_bin_raise(RCore *core, ut32 bfid) { - RBin *bin = core->bin; - RBinFile *bf = r_list_get_n (bin->binfiles, bfid); - bool res = false; - if (bf) { - res = r_bin_file_set_cur_binfile (bin, bf); - if (res) { - r_io_use_fd (core->io, bf->fd); - } - res = res? r_core_file_set_by_fd (core, bf->fd): res; - if (res) { - core->switch_file_view = 1; - } - } - return res; -} - -R_API int r_core_file_binlist(RCore *core) { - int count = 0; - RListIter *iter; - RCoreFile *cur_cf = core->file, *cf = NULL; - RBinFile *binfile = NULL; - RIODesc *desc; - RBin *bin = core->bin; - const RList *binfiles = bin? bin->binfiles: NULL; - - if (!binfiles) { - return false; - } - r_list_foreach (binfiles, iter, binfile) { - int fd = binfile->fd; - cf = r_core_file_get_by_fd (core, fd); - desc = r_io_desc_get (core->io, fd); - if (cf) { - r_cons_printf ("%c %d %s ; %s\n", - core->io->desc == desc ? '*': '-', - fd, desc->uri, desc->perm & R_PERM_W? "rw": "r"); - } - } - r_core_file_set_by_file (core, cur_cf); - //r_core_bin_bind (core, cur_bf); - return count; -} - -static bool close_but_cb(void *user, void *data, ut32 id) { - RCore *core = (RCore *)user; - RIODesc *desc = (RIODesc *)data; - if (core && desc && core->file) { - if (desc->fd != core->file->fd) { - // TODO: use the API - r_core_cmdf (core, "o-%d", desc->fd); - } - } - return true; -} - -R_API bool r_core_file_close_all_but(RCore *core) { - r_id_storage_foreach (core->io->files, close_but_cb, core); - return true; -} - -R_API bool r_core_file_close_fd(RCore *core, int fd) { - RCoreFile *file; - RListIter *iter; - if (fd == -1) { - // FIXME: Only closes files known to the core! - r_list_free (core->files); - core->files = NULL; - core->file = NULL; - return true; - } - r_list_foreach (core->files, iter, file) { - if (file->fd == fd) { - r_core_file_close (core, file); - if (file == core->file) { - core->file = NULL; // deref - } - return true; - } - } - return r_io_fd_close (core->io, fd); -} - -R_API RCoreFile *r_core_file_find_by_fd(RCore *core, ut64 fd) { - RListIter *iter; - RCoreFile *cf = NULL; - r_list_foreach (core->files, iter, cf) { - if (cf && cf->fd == fd) { - break; - } - cf = NULL; - } - return cf; -} - -R_API RCoreFile *r_core_file_find_by_name(RCore *core, const char *name) { - RListIter *iter; - RCoreFile *cf = NULL; - RIODesc *desc; - - if (!core) { - return NULL; - } - - r_list_foreach (core->files, iter, cf) { - desc = r_io_desc_get (core->io, cf->fd); - if (desc && !strcmp (desc->name, name)) { - break; - } - cf = NULL; - } - return cf; -} - -R_API int r_core_file_set_by_fd(RCore *core, ut64 fd) { - if (core) { - r_io_use_fd (core->io, fd); - r_core_bin_set_by_fd (core, fd); - return true; - } - return false; -} - -R_API int r_core_file_set_by_name(RCore *core, const char *name) { - RCoreFile *cf = r_core_file_find_by_name (core, name); - return r_core_file_set_by_file (core, cf); -} - -R_API int r_core_file_set_by_file(RCore *core, RCoreFile *cf) { - if (core && cf) { - if (!r_core_file_set_by_fd (core, cf->fd)) { - return false; - } - core->file = cf; - return true; - } - return false; -} - -R_API ut32 r_core_file_cur_fd(RCore *core) { - if (core && core->file) { - return core->file->fd; - } - return UT32_MAX; -} - -R_API RCoreFile *r_core_file_cur(RCore *r) { - // Add any locks here - return r->file; -} diff --git a/libr/core/cmd_helps.h b/libr/core/cmd_helps.h deleted file mode 100644 index 759e1f0255..0000000000 --- a/libr/core/cmd_helps.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef R_CMD_HELPS_H_ -#define R_CMD_HELPS_H_ - -#include - -extern const RCmdDescHelp system_help; -extern const RCmdDescHelp underscore_help; -extern const RCmdDescHelp hash_help; -extern const RCmdDescHelp alias_help; -extern const RCmdDescHelp env_help; -extern const RCmdDescHelp tasks_help; -extern const RCmdDescHelp macro_help; -extern const RCmdDescHelp pointer_help; -extern const RCmdDescHelp stdin_help; -extern const RCmdDescHelp interpret_help; -extern const RCmdDescHelp search_help; -extern const RCmdDescHelp rap_help; -extern const RCmdDescHelp help_help; -extern const RCmdDescHelp rap_run_help; -extern const RCmdDescHelp zero_help; -extern const RCmdDescHelp anal_help; -extern const RCmdDescHelp b_help; -extern const RCmdDescHelp c_help; -extern const RCmdDescHelp C_help; -extern const RCmdDescHelp d_help; -extern const RCmdDescHelp e_help; -extern const RCmdDescHelp f_help; -extern const RCmdDescHelp g_help; -extern const RCmdDescHelp i_help; -extern const RCmdDescHelp k_help; -extern const RCmdDescHelp l_help; -extern const RCmdDescHelp j_help; -extern const RCmdDescHelp h_help; -extern const RCmdDescHelp L_help; -extern const RCmdDescHelp m_help; -extern const RCmdDescHelp o_help; -extern const RCmdDescHelp p_help; -extern const RCmdDescHelp P_help; -extern const RCmdDescHelp q_help; -extern const RCmdDescHelp Q_help; -extern const RCmdDescHelp colon_help; -extern const RCmdDescHelp r_help; -extern const RCmdDescHelp s_help; -extern const RCmdDescHelp t_help; -extern const RCmdDescHelp T_help; -extern const RCmdDescHelp u_help; -extern const RCmdDescHelp pipein_help; -extern const RCmdDescHelp V_help; -extern const RCmdDescHelp v_help; -extern const RCmdDescHelp w_help; -extern const RCmdDescHelp w_group_help; -extern const RCmdDescHelp x_help; -extern const RCmdDescHelp y_help; -extern const RCmdDescHelp z_help; - -// w0 helps - -extern const RCmdDescHelp w0_help; - -// w[1248][+-] helps - -extern const RCmdDescHelp w_incdec_help; -extern const RCmdDescHelp w1_incdec_help; -extern const RCmdDescHelp w1_inc_help; -extern const RCmdDescHelp w1_dec_help; -extern const RCmdDescHelp w2_incdec_help; -extern const RCmdDescHelp w2_inc_help; -extern const RCmdDescHelp w2_dec_help; -extern const RCmdDescHelp w4_incdec_help; -extern const RCmdDescHelp w4_inc_help; -extern const RCmdDescHelp w4_dec_help; -extern const RCmdDescHelp w8_incdec_help; -extern const RCmdDescHelp w8_inc_help; -extern const RCmdDescHelp w8_dec_help; - -// wB helps - -extern const RCmdDescHelp wB_group_help; -extern const RCmdDescHelp wB_help; -extern const RCmdDescHelp wB_minus_help; - -// wv helps - -extern const RCmdDescHelp wv_group_help; -extern const RCmdDescHelp wv_help; -extern const RCmdDescHelp wv1_help; -extern const RCmdDescHelp wv2_help; -extern const RCmdDescHelp wv4_help; -extern const RCmdDescHelp wv8_help; - -extern const RCmdDescHelp w6_help; -extern const RCmdDescHelp wh_help; -extern const RCmdDescHelp we_help; -extern const RCmdDescHelp wp_help; -extern const RCmdDescHelp wu_help; -extern const RCmdDescHelp wr_help; -extern const RCmdDescHelp wA_help; -extern const RCmdDescHelp wc_help; -extern const RCmdDescHelp wz_help; -extern const RCmdDescHelp wt_help; -extern const RCmdDescHelp wf_help; -extern const RCmdDescHelp ww_help; -extern const RCmdDescHelp wx_help; -extern const RCmdDescHelp wa_help; -extern const RCmdDescHelp wb_help; -extern const RCmdDescHelp wm_help; -extern const RCmdDescHelp wo_help; -extern const RCmdDescHelp wd_help; -extern const RCmdDescHelp ws_help; -#endif diff --git a/libr/core/cplugin.c b/libr/core/cplugin.c deleted file mode 100644 index 299c79f34f..0000000000 --- a/libr/core/cplugin.c +++ /dev/null @@ -1,61 +0,0 @@ -/* radare - LGPL - Copyright 2010-2018 - pancake */ - -/* covardly copied from r_cmd */ - -#include -#include -#include -#include -#include - -static RCorePlugin *cmd_static_plugins[] = { - R_CORE_STATIC_PLUGINS -}; - -R_API int r_core_plugin_fini(RCmd *cmd) { - RListIter *iter; - RCorePlugin *plugin; - if (!cmd->plist) { - return false; - } - r_list_foreach (cmd->plist, iter, plugin) { - if (plugin && plugin->fini) { - plugin->fini (cmd, NULL); - } - } - /* empty the list */ - r_list_free (cmd->plist); - cmd->plist = NULL; - return true; -} - -R_API int r_core_plugin_add(RCmd *cmd, RCorePlugin *plugin) { - if (!cmd || (plugin && plugin->init && !plugin->init (cmd, NULL))) { - return false; - } - r_list_append (cmd->plist, plugin); - return true; -} - -R_API int r_core_plugin_init(RCmd *cmd) { - int i; - cmd->plist = r_list_newf (NULL); // memleak or dblfree - for (i = 0; cmd_static_plugins[i]; i++) { - if (!r_core_plugin_add (cmd, cmd_static_plugins[i])) { - eprintf ("Error loading cmd plugin\n"); - return false; - } - } - return true; -} - -R_API int r_core_plugin_check(RCmd *cmd, const char *a0) { - RListIter *iter; - RCorePlugin *cp; - r_list_foreach (cmd->plist, iter, cp) { - if (cp->call (NULL, a0)) { - return true; - } - } - return false; -} diff --git a/libr/core/cundo.c b/libr/core/cundo.c deleted file mode 100644 index 86cbcb23cb..0000000000 --- a/libr/core/cundo.c +++ /dev/null @@ -1,76 +0,0 @@ -/* radare2 - LGPL - Copyright 2018-2019 - pancake */ - -#include - -#if 0 - -TODO: - -- add more methods to "undo according to some conditions" -- undo all comments in current offfset -#endif - -R_API RCoreUndo *r_core_undo_new(ut64 offset, const char *action, const char *revert) { - RCoreUndo *cu = R_NEW (RCoreUndo); - if (cu) { - cu->action = strdup (action); - cu->revert = strdup (revert); - cu->tstamp = r_time_now (); - cu->offset = offset; - } - return cu; -} - -R_API void r_core_undo_free(RCoreUndo *cu) { - if (cu) { - free (cu->action); - free (cu->revert); - } - free (cu); -} - -R_API void r_core_undo_push(RCore *core, RCoreUndo *cu) { - r_list_append (core->undos, cu); -} - -R_API void r_core_undo_pop(RCore *core) { - RCoreUndo *undo = r_list_pop (core->undos); - if (undo) { - r_core_cmd0 (core, undo->revert); - r_core_undo_free (undo); - } -} - -R_API bool r_core_undo_condition(RCoreUndo *cu, RCoreUndoCondition *cond) { - if (!cond) { - return true; - } - bool mustPrint = false; - if (cond->addr != UT64_MAX) { - mustPrint = (cu->offset == cond->addr); - } - if (cond->minstamp) { - mustPrint = (cu->tstamp >= cond->minstamp); - } - if (cond->glob) { - mustPrint = r_str_glob (cu->action, cond->glob); - } - return mustPrint; -} - -R_API void r_core_undo_print(RCore *core, int mode, RCoreUndoCondition *cond) { - RCoreUndo *cu; - RListIter *iter; - if (mode) { - r_list_foreach (core->undos, iter, cu) { - if (r_core_undo_condition (cu, cond)) { - r_cons_printf ("%s @ 0x%"PFMT64x"\n", cu->revert, cu->offset); - } - } - } else { - r_list_foreach (core->undos, iter, cu) { - r_cons_printf ("0x%08"PFMT64x" %"PFMT64d" %s (revert: %s)\n", - cu->offset, cu->tstamp, cu->action, cu->revert); - } - } -} diff --git a/libr/core/libs.c b/libr/core/libs.c deleted file mode 100644 index abc94267c1..0000000000 --- a/libr/core/libs.c +++ /dev/null @@ -1,148 +0,0 @@ -/* radare - LGPL - Copyright 2009-2020 - pancake */ - -#include "r_core.h" -#include "config.h" - -#define CB(x, y)\ - static int __lib_ ## x ## _cb (RLibPlugin * pl, void *user, void *data) {\ - struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data;\ - RCore *core = (RCore *) user;\ - pl->free = NULL; \ - r_ ## x ## _add (core->y, hand);\ - return true;\ - }\ - static int __lib_ ## x ## _dt (RLibPlugin * pl, void *p, void *u) { return true; } - -#define CB_COPY(x, y)\ - static int __lib_ ## x ## _cb (RLibPlugin * pl, void *user, void *data) {\ - struct r_ ## x ## _plugin_t *hand = (struct r_ ## x ## _plugin_t *)data;\ - struct r_ ## x ## _plugin_t *instance;\ - RCore *core = (RCore *) user;\ - instance = R_NEW (struct r_ ## x ## _plugin_t);\ - memcpy (instance, hand, sizeof (struct r_ ## x ## _plugin_t));\ - r_ ## x ## _add (core->y, instance);\ - return true;\ - }\ - static int __lib_ ## x ## _dt (RLibPlugin * pl, void *p, void *u) { return true; } - -// XXX api consistency issues -#define r_io_add r_io_plugin_add -CB_COPY (io, io) -#define r_core_add r_core_plugin_add -CB (core, rcmd) -#define r_debug_add r_debug_plugin_add -CB (debug, dbg) -#define r_bp_add r_bp_plugin_add -CB (bp, dbg->bp) -CB (lang, lang) -CB (anal, anal) -CB (asm, rasm) -CB (parse, parser) -CB (bin, bin) -CB (egg, egg) -CB (fs, fs) - -static void __openPluginsAt(RCore *core, const char *arg, const char *user_path) { - if (arg && *arg) { - if (user_path) { - if (r_str_endswith (user_path, arg)) { - return; - } - } - char *pdir = r_str_r2_prefix (arg); - if (pdir) { - r_lib_opendir (core->lib, pdir); - free (pdir); - } - } -} - -static void __loadSystemPlugins(RCore *core, int where, const char *path) { -#if R2_LOADLIBS - if (!where) { - where = -1; - } - if (path) { - r_lib_opendir (core->lib, path); - } - const char *dir_plugins = r_config_get (core->config, "dir.plugins"); - if (where & R_CORE_LOADLIBS_CONFIG) { - r_lib_opendir (core->lib, dir_plugins); - } - if (where & R_CORE_LOADLIBS_ENV) { - char *p = r_sys_getenv (R_LIB_ENV); - if (p && *p) { - r_lib_opendir (core->lib, p); - } - free (p); - } - if (where & R_CORE_LOADLIBS_HOME) { - char *hpd = r_str_home (R2_HOME_PLUGINS); - if (hpd) { - r_lib_opendir (core->lib, hpd); - free (hpd); - } - } - if (where & R_CORE_LOADLIBS_SYSTEM) { - __openPluginsAt (core, R2_PLUGINS, dir_plugins); - __openPluginsAt (core, R2_EXTRAS, dir_plugins); - __openPluginsAt (core, R2_BINDINGS, dir_plugins); - } -#endif -} - -R_API void r_core_loadlibs_init(RCore *core) { - ut64 prev = r_time_now_mono (); -#define DF(x, y, z) r_lib_add_handler (core->lib, R_LIB_TYPE_ ## x, y, &__lib_ ## z ## _cb, &__lib_ ## z ## _dt, core); - core->lib = r_lib_new (NULL, NULL); - DF (IO, "io plugins", io); - DF (CORE, "core plugins", core); - DF (DBG, "debugger plugins", debug); - DF (BP, "debugger breakpoint plugins", bp); - DF (LANG, "language plugins", lang); - DF (ANAL, "analysis plugins", anal); - DF (ASM, "(dis)assembler plugins", asm); - DF (PARSE, "parsing plugins", parse); - DF (BIN, "bin plugins", bin); - DF (EGG, "egg plugins", egg); - DF (FS, "fs plugins", fs); - core->times->loadlibs_init_time = r_time_now_mono () - prev; -} - -static bool __isScriptFilename(const char *name) { - const char *ext = r_str_lchr (name, '.'); - if (ext) { - ext++; - if (!strcmp (ext, "py") - || !strcmp (ext, "js") - || !strcmp (ext, "lua")) { - return true; - } - } - return false; -} - -R_API int r_core_loadlibs(RCore *core, int where, const char *path) { - ut64 prev = r_time_now_mono (); - __loadSystemPlugins (core, where, path); - /* TODO: all those default plugin paths should be defined in r_lib */ - if (!r_config_get_i (core->config, "cfg.plugins")) { - core->times->loadlibs_time = 0; - return false; - } - // load script plugins - char *homeplugindir = r_str_home (R2_HOME_PLUGINS); - RList *files = r_sys_dir (homeplugindir); - RListIter *iter; - char *file; - r_list_foreach (files, iter, file) { - if (__isScriptFilename (file)) { - r_core_cmdf (core, ". %s/%s", homeplugindir, file); - } - } - - free (homeplugindir); - core->times->loadlibs_time = r_time_now_mono () - prev; - r_list_free (files); - return true; -} diff --git a/libr/core/p/core_java.c b/libr/core/p/core_java.c deleted file mode 100644 index 7fc4b1cf82..0000000000 --- a/libr/core/p/core_java.c +++ /dev/null @@ -1,1976 +0,0 @@ -/* radare - Apache - Copyright 2014-2019 - dso, pancake */ - -#include -#include -#include -#include -#include -#include -#include - -#include "../../../shlr/java/ops.h" -#include "../../../shlr/java/class.h" -#include "../../../shlr/java/code.h" -#include "../../../shlr/java/dsojson.h" - -#define DO_THE_DBG 0 -#undef IFDBG -#define IFDBG if (DO_THE_DBG) - - -typedef struct found_idx_t { - ut16 idx; - ut64 addr; - const RBinJavaCPTypeObj *obj; -} RCmdJavaCPResult; - -typedef int (*RCMDJavaCmdHandler) (RCore *core, const char *cmd); - -static const char * r_cmd_java_strtok (const char *str1, const char b, size_t len); -static const char * r_cmd_java_consumetok (const char *str1, const char b, size_t len); -static int r_cmd_java_reload_bin_from_buf (RCore *core, RBinJavaObj *obj, ut8* buffer, ut64 len); - -static int r_cmd_java_print_json_definitions( RBinJavaObj *obj ); -static int r_cmd_java_print_all_definitions( RAnal *anal ); -static int r_cmd_java_print_class_definitions( RBinJavaObj *obj ); -static int r_cmd_java_print_field_definitions( RBinJavaObj *obj ); -static int r_cmd_java_print_method_definitions( RBinJavaObj *obj ); -static int r_cmd_java_print_import_definitions( RBinJavaObj *obj ); - -static int r_cmd_java_resolve_cp_idx (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_resolve_cp_type (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_resolve_cp_idx_b64 (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_resolve_cp_address (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_resolve_cp_to_key (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_resolve_cp_summary (RBinJavaObj *obj, ut16 idx); - -static int r_cmd_java_print_class_access_flags_value( const char * flags ); -static int r_cmd_java_print_field_access_flags_value( const char * flags ); -static int r_cmd_java_print_method_access_flags_value( const char * flags ); -static int r_cmd_java_get_all_access_flags_value (const char *cmd); - -static int r_cmd_java_set_acc_flags (RCore *core, ut64 addr, ut16 num_acc_flag); - -#define _(x) UNUSED_FUNCTION(x) -static int r_cmd_java_print_field_summary (RBinJavaObj *obj, ut16 idx); -static int _(r_cmd_java_print_field_count) (RBinJavaObj *obj); -static int r_cmd_java_print_field_name (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_print_field_num_name (RBinJavaObj *obj); -static int r_cmd_java_print_method_summary (RBinJavaObj *obj, ut16 idx); -static int _(r_cmd_java_print_method_count) (RBinJavaObj *obj); -static int r_cmd_java_print_method_name (RBinJavaObj *obj, ut16 idx); -static int r_cmd_java_print_method_num_name (RBinJavaObj *obj); - -static RBinJavaObj * r_cmd_java_get_bin_obj(RAnal *anal); -static RList * r_cmd_java_get_bin_obj_list(RAnal *anal); -static ut64 r_cmd_java_get_input_num_value(RCore *core, const char *input_value); -static int r_cmd_java_is_valid_input_num_value(RCore *core, const char *input_value); - - -static int r_cmd_java_call(void *user, const char *input); -static int r_cmd_java_handle_help(RCore * core, const char * input); -static int r_cmd_java_handle_set_flags(RCore *core, const char *cmd); -static int r_cmd_java_handle_prototypes(RCore *core, const char *cmd); -static int r_cmd_java_handle_resolve_cp(RCore *core, const char *cmd); -static int r_cmd_java_handle_calc_flags(RCore *core, const char *cmd); -static int r_cmd_java_handle_flags_str(RCore *core, const char *cmd); -static int r_cmd_java_handle_flags_str_at(RCore *core, const char *cmd); -static int r_cmd_java_handle_field_info(RCore *core, const char *cmd); -static int r_cmd_java_handle_method_info(RCore *core, const char *cmd); - -static int r_cmd_java_handle_find_cp_const(RCore *core, const char *cmd); - -static RList *cpfind_float(RBinJavaObj *obj, const char *cmd); -static RList *cpfind_double(RBinJavaObj *obj, const char *cmd); -static RList *cpfind_long(RCore *core, RBinJavaObj *obj, const char *cmd); -static RList *cpfind_int(RCore *core, RBinJavaObj *obj, const char *cmd); -static RList *cpfind_str(RBinJavaObj *obj, const char *cmd); - -static int cpfind(RCore *core, const char *cmd); - -static int r_cmd_java_get_cp_bytes_and_write(RCore *core, RBinJavaObj *obj, ut16 idx, ut64 addr, const ut8 *buf, const ut64 len); -static int r_cmd_java_handle_replace_cp_value_float(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); -static int r_cmd_java_handle_replace_cp_value_double(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); -static int r_cmd_java_handle_replace_cp_value_long(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); -static int r_cmd_java_handle_replace_cp_value_int(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); -static int r_cmd_java_handle_replace_cp_value_str(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); -static int r_cmd_java_handle_replace_cp_value(RCore *core, const char *cmd); - -static int r_cmd_java_handle_replace_classname_value(RCore *core, const char *cmd); -static char *r_cmd_replace_name_def(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len); -static char *r_cmd_replace_name(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len); -static int r_cmd_is_object_descriptor(const char *name, ut32 name_len); -static ut32 r_cmd_get_num_classname_str_occ(const char *str, const char *match_me); -static const char *r_cmd_get_next_classname_str(const char *str, const char *match_me); - -static int r_cmd_java_handle_summary_info(RCore *core, const char *cmd); -static int r_cmd_java_handle_reload_bin(RCore *core, const char *cmd); - -static int r_cmd_java_handle_print_exceptions(RCore *core, const char *input); -static int r_cmd_java_handle_insert_method_ref(RCore *core, const char *input); -static int r_cmd_java_handle_yara_code_extraction_refs(RCore *core, const char *input); - -static int r_cmd_java_handle_isvalid(RCore *core, const char *cmd); -static int r_cmd_java_handle_calc_class_sz(RCore *core, const char *cmd); - -typedef struct r_cmd_java_cms_t { - const char *name; - const char *args; - const char *desc; - const ut32 name_len; - RCMDJavaCmdHandler handler; -} RCmdJavaCmd; - -/* XXX : Most of those command arguments are absurd, must be reviewed + changed */ - -#define CALC_SZ "calc_sz" -#define CALC_SZ_ARGS " " -#define CALC_SZ_DESC "calculate class file size at location" -#define CALC_SZ_LEN 7 - -#define ISVALID "is_valid" -#define ISVALID_ARGS " " -#define ISVALID_DESC "check buffer to see if it is a valid class file" -#define ISVALID_LEN 8 - -#define SET_ACC_FLAGS "set_flags" -#define SET_ACC_FLAGS_ARGS " [addr cmf ]" //[ ] | [ < c | m | f> ]" -#define SET_ACC_FLAGS_DESC "set the access flags attributes for a field or method" -#define SET_ACC_FLAGS_LEN 9 - -#define PROTOTYPES "prototypes" -#define PROTOTYPES_ARGS " " // < j | a | i | c | m | f> -#define PROTOTYPES_DESC "show in JSON, or All,Imports,Class,Methods,Fields" -#define PROTOTYPES_LEN 10 - -#define RESOLVE_CP "resolve_cp" -#define RESOLVE_CP_ARGS " [ idx]" -#define RESOLVE_CP_DESC "cp type or value @ idx. Summary,Type,b64Encode,Const,Addr,Dump,Gsumarize" -//d = dump all, g = summarize all, s = summary, a = address, t = type, c = get value, e = base64 enode the result" -#define RESOLVE_CP_LEN 10 - -#define CALC_FLAGS "calc_flags" -#define CALC_FLAGS_ARGS " [visib.]" -//[ > | | | ]" -#define CALC_FLAGS_DESC "value from access flags: ListAll, flags, Class, Field, Method" -#define CALC_FLAGS_LEN 10 - -#define FLAGS_STR_AT "flags_str_at" -#define FLAGS_STR_AT_ARGS " [addr]" -#define FLAGS_STR_AT_DESC "string value from access flags @ addr: Class, Field, Method" -#define FLAGS_STR_AT_LEN 12 - -#define FLAGS_STR "flags_str" -#define FLAGS_STR_ARGS " [ ]" //acc_flags_value>]" -#define FLAGS_STR_DESC "string value for the flags number: Class, Field, Method" -#define FLAGS_STR_LEN 9 - -#define METHOD_INFO "m_info" -#define METHOD_INFO_ARGS " [ | ]" -//#define METHOD_INFO_DESC "method index info: c = dump methods and ord , s = dump of all meta-data, n = method" -#define METHOD_INFO_DESC "method information at index (c:method+ord, s:metadata)" -#define METHOD_INFO_LEN 6 - -#define FIELD_INFO "f_info" -#define FIELD_INFO_ARGS " [ | #idx]" -#define FIELD_INFO_DESC "field information at index (c:field+ord, s:metadata)" -// : c = dump field and ord , s = dump of all meta-data, n = method" -#define FIELD_INFO_LEN 6 - -#define HELP "help" -#define HELP_DESC "displays this message" -#define HELP_ARGS "" -#define HELP_LEN 4 - -#define FIND_CP_CONST "find_cp_const" -#define FIND_CP_CONST_ARGS " [a|#idx]" -#define FIND_CP_CONST_DESC "find references to constant CP Object in code: AllReferences" -#define FIND_CP_CONST_LEN 13 - -#define FIND_CP_VALUE "find_cp_value" -#define FIND_CP_VALUE_ARGS " [ V]" -#define FIND_CP_VALUE_DESC "find references to CP constants by value" -#define FIND_CP_VALUE_LEN 13 - -#define REPLACE_CP_VALUE "replace_cp_value" -#define REPLACE_CP_VALUE_ARGS " [ V]" -#define REPLACE_CP_VALUE_DESC "replace CP constants with value if the no resizing is required" -#define REPLACE_CP_VALUE_LEN 16 - -#define REPLACE_CLASS_NAME "replace_classname_value" -#define REPLACE_CLASS_NAME_ARGS " " -#define REPLACE_CLASS_NAME_DESC "rename class name" //"replace CP constants with value if no resize needed" -#define REPLACE_CLASS_NAME_LEN 23 - -#define RELOAD_BIN "reload_bin" -#define RELOAD_BIN_ARGS " addr [size]" -#define RELOAD_BIN_DESC "reload and reanalyze the Java class file starting at address" -#define RELOAD_BIN_LEN 10 - -#define SUMMARY_INFO "summary" -#define SUMMARY_INFO_ARGS "" -#define SUMMARY_INFO_DESC "print summary information for the current java class file" -#define SUMMARY_INFO_LEN 7 - -#define LIST_CODE_REFS "lcr" -#define LIST_CODE_REFS_ARGS " [addr]" -#define LIST_CODE_REFS_DESC "list all references to fields and methods in code sections" -#define LIST_CODE_REFS_LEN 3 - -#define PRINT_EXC "exc" -#define PRINT_EXC_ARGS " []" -#define PRINT_EXC_DESC "list all exceptions to fields and methods in code sections" -#define PRINT_EXC_LEN 3 - -#define YARA_CODE_REFS "yc_w_refs" -#define YARA_CODE_REFS_ARGS " [name] [start] [count]" -#define YARA_CODE_REFS_DESC "yara code bytes extraction with a name starting at to " -#define YARA_CODE_REFS_LEN 9 - -#define INSERT_MREF "i_mref" -#define INSERT_MREF_ARGS " C M S" // " //descriptor in form of (Lpref;)Lref;" -#define INSERT_MREF_DESC "add Method to Class with given method signature" //append a method reference CP object to the end of the CP object array (creates all requisite objects)" -#define INSERT_MREF_LEN 6 - -static RCmdJavaCmd JAVA_CMDS[] = { - { HELP, HELP_ARGS, HELP_DESC, HELP_LEN, r_cmd_java_handle_help }, - { SET_ACC_FLAGS, SET_ACC_FLAGS_ARGS, SET_ACC_FLAGS_DESC, SET_ACC_FLAGS_LEN, r_cmd_java_handle_set_flags }, - { PROTOTYPES, PROTOTYPES_ARGS, PROTOTYPES_DESC, PROTOTYPES_LEN, r_cmd_java_handle_prototypes }, - { RESOLVE_CP, RESOLVE_CP_ARGS, RESOLVE_CP_DESC, RESOLVE_CP_LEN, r_cmd_java_handle_resolve_cp }, - { CALC_FLAGS, CALC_FLAGS_ARGS, CALC_FLAGS_DESC, CALC_FLAGS_LEN, r_cmd_java_handle_calc_flags }, - { FLAGS_STR_AT, FLAGS_STR_AT_ARGS, FLAGS_STR_AT_DESC, FLAGS_STR_AT_LEN, r_cmd_java_handle_flags_str_at }, - { FLAGS_STR, FLAGS_STR_ARGS, FLAGS_STR_DESC, FLAGS_STR_LEN, r_cmd_java_handle_flags_str }, - { METHOD_INFO, METHOD_INFO_ARGS, METHOD_INFO_DESC, METHOD_INFO_LEN, r_cmd_java_handle_method_info }, - { FIELD_INFO, FIELD_INFO_ARGS, FIELD_INFO_DESC, FIELD_INFO_LEN, r_cmd_java_handle_field_info }, - { FIND_CP_CONST, FIND_CP_CONST_ARGS, FIND_CP_CONST_DESC, FIND_CP_CONST_LEN, r_cmd_java_handle_find_cp_const }, - { FIND_CP_VALUE, FIND_CP_VALUE_ARGS, FIND_CP_VALUE_DESC, FIND_CP_VALUE_LEN, cpfind }, - { REPLACE_CP_VALUE, REPLACE_CP_VALUE_ARGS, REPLACE_CP_VALUE_DESC, REPLACE_CP_VALUE_LEN, r_cmd_java_handle_replace_cp_value }, - { REPLACE_CLASS_NAME, REPLACE_CLASS_NAME_ARGS, REPLACE_CLASS_NAME_DESC, REPLACE_CLASS_NAME_LEN, r_cmd_java_handle_replace_classname_value }, - { RELOAD_BIN, RELOAD_BIN_ARGS, RELOAD_BIN_DESC, RELOAD_BIN_LEN, r_cmd_java_handle_reload_bin }, - { SUMMARY_INFO, SUMMARY_INFO_ARGS, SUMMARY_INFO_DESC, SUMMARY_INFO_LEN, r_cmd_java_handle_summary_info }, - { PRINT_EXC, PRINT_EXC_ARGS, PRINT_EXC_DESC, PRINT_EXC_LEN, r_cmd_java_handle_print_exceptions }, - { YARA_CODE_REFS, YARA_CODE_REFS_ARGS, YARA_CODE_REFS_DESC, YARA_CODE_REFS_LEN, r_cmd_java_handle_yara_code_extraction_refs }, - { INSERT_MREF, INSERT_MREF_ARGS, INSERT_MREF_DESC, INSERT_MREF_LEN, r_cmd_java_handle_insert_method_ref }, - { CALC_SZ, CALC_SZ_ARGS, CALC_SZ_DESC, CALC_SZ_LEN, r_cmd_java_handle_calc_class_sz }, - { ISVALID, ISVALID_ARGS, ISVALID_DESC, ISVALID_LEN, r_cmd_java_handle_isvalid }, -}; - -enum { - HELP_IDX = 0, - SET_ACC_FLAGS_IDX = 1, - PROTOTYPES_IDX = 2, - RESOLVE_CP_IDX = 3, - CALC_FLAGS_IDX = 4, - FLAGS_STR_AT_IDX = 5, - FLAGS_STR_IDX = 6, - METHOD_INFO_IDX = 7, - FIELD_INFO_IDX = 8, - FIND_CP_CONST_IDX = 9, - FIND_CP_VALUE_IDX = 10, - REPLACE_CP_VALUE_IDX = 11, - REPLACE_CLASS_NAME_IDX = 12, - RELOAD_BIN_IDX = 13, - SUMMARY_INFO_IDX = 14, - LIST_CODE_REFS_IDX = 15, - PRINT_EXC_IDX = 16, - YARA_CODE_REFS_IDX = 17, - INSERT_MREF_IDX = 18, - CALC_SZ_IDX = 19, - ISVALID_IDX = 20, - END_CMDS = 21, -}; - -static ut8 _(r_cmd_java_obj_ref)(const char *name, const char *class_name, ut32 len) { - if (!name || !class_name) { - return false; - } - if (strncmp (class_name, name, len)) { - return false; - } - if (*(name - 1) == 'L' && *(name + len) == ';') { - return true; - } - if (!strncmp (class_name, name, len) && !*(name + len)) { - return true; - } - return false; -} - -static const char *r_cmd_get_next_classname_str(const char *str, const char *match_me) { - const char *result = NULL; - ut32 len = match_me && *match_me? strlen (match_me): 0; - if (len && str && *str) { - result = str; - while (result && *result && (result - str < len)) { - result = strstr (result, match_me); - if (result) { - break; - } - } - } - return result; -} - -static ut32 r_cmd_get_num_classname_str_occ(const char *str, const char *match_me) { - const char *result = NULL; - ut32 len = match_me && *match_me? strlen (match_me): 0; - ut32 occ = 0; - - if (len == 0 || !str || !*str) { - return 0; - } - result = str; - while (result && *result && (result - str < len)) { - result = strstr (result, match_me); - if (result) { - IFDBG eprintf ("result: %s\n", result); - result += len; - occ++; - } - } - return occ; -} - -static const char *r_cmd_java_consumetok(const char *str1, const char b, size_t len) { - const char *p = str1; - size_t i = 0; - if (!p) { - return p; - } - if (len == (size_t)-1) { - len = strlen (str1); - } - for (; i < len; i++, p++) { - if (*p != b) { - break; - } - } - return p; -} - -static const char *r_cmd_java_strtok(const char *str1, const char b, size_t len) { - const char *p = str1; - size_t i = 0; - if (!p || !*p) { - return p; - } - if (len == (size_t)-1) { - len = strlen (str1); - } - IFDBG r_cons_printf ("Looking for char (%c) in (%s) up to %d\n", b, p, len); - for (; i < len; i++, p++) { - if (*p == b) { - IFDBG r_cons_printf ("Found? for char (%c) @ %d: (%s)\n", b, i, p); - break; - } - } - if (i == len) { - p = NULL; - } - IFDBG r_cons_printf ("Found? for char (%c) @ %d: (%s)\n", b, len, p); - return p; -} - -static RAnal *get_anal(RCore *core) { - return core? core->anal: NULL; -} - -static void r_cmd_java_print_cmd_help(RCmdJavaCmd *cmd) { - eprintf ("[*] %s %s\n[+] %s\n\n", cmd->name, cmd->args, cmd->desc); -} - -static int r_cmd_java_handle_help(RCore *core, const char *input) { - ut32 i = 0; - const char **help_msg = (const char **)malloc (sizeof (char *) * END_CMDS * 4); - help_msg[0] = "Usage:"; - help_msg[1] = "java [cmd] [arg..] "; - help_msg[2] = r_core_plugin_java.desc; - for (i = 0; i < END_CMDS; i++) { - RCmdJavaCmd *cmd = &JAVA_CMDS[i]; - help_msg[3 + (i * 3) + 0] = cmd->name; - help_msg[3 + (i * 3) + 1] = cmd->args; - help_msg[3 + (i * 3) + 2] = cmd->desc; - } - help_msg[3 + (i * 3)] = NULL; - r_core_cmd_help (core, help_msg); - free (help_msg); - return true; -} - -static int r_cmd_java_handle_prototypes(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } - - switch (*(cmd)) { - case 'm': return r_cmd_java_print_method_definitions (obj); - case 'f': return r_cmd_java_print_field_definitions (obj); - case 'i': return r_cmd_java_print_import_definitions (obj); - case 'c': return r_cmd_java_print_class_definitions (obj); - case 'a': return r_cmd_java_print_all_definitions (anal); - case 'j': return r_cmd_java_print_json_definitions (obj); - } - return false; -} - -static int r_cmd_java_handle_summary_info(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } - - r_cons_printf ("Summary for %s:\n", obj->file); - r_cons_printf (" Size 0x%" PFMT64x ":\n", obj->size); - r_cons_printf (" Constants size: 0x%" PFMT64x " count: %d:\n", obj->cp_size, obj->cp_count); - r_cons_printf (" Methods size: 0x%" PFMT64x " count: %d:\n", obj->methods_size, obj->methods_count); - r_cons_printf (" Fields size: 0x%" PFMT64x " count: %d:\n", obj->fields_size, obj->fields_count); - r_cons_printf (" Attributes size: 0x%" PFMT64x " count: %d:\n", obj->attrs_size, obj->attrs_count); - r_cons_printf (" Interfaces size: 0x%" PFMT64x " count: %d:\n", obj->interfaces_size, obj->interfaces_count); - - return true; -} - -static int _(r_cmd_java_check_op_idx)(const ut8 *op_bytes, ut16 idx) { - return R_BIN_JAVA_USHORT (op_bytes, 0) == idx; -} - -/* Find stuff in the constant pool */ -static RList *cpfind_double(RBinJavaObj *obj, const char *cmd) { - double value = cmd && *cmd? strtod (cmd, NULL): 0.0; - if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) { - return r_list_new (); - } - return r_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 8, R_BIN_JAVA_CP_DOUBLE); -} - -static RList *cpfind_float(RBinJavaObj *obj, const char *cmd) { - float value = cmd && *cmd? atof (cmd): 0.0; - if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) { - return r_list_new (); - } - return r_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 4, R_BIN_JAVA_CP_FLOAT); -} - -static RList *cpfind_long(RCore *core, RBinJavaObj *obj, const char *cmd) { - ut64 value = r_cmd_java_get_input_num_value (core, cmd); - if (!r_cmd_java_is_valid_input_num_value (core, cmd)) { - return r_list_new (); - } - return r_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 8, R_BIN_JAVA_CP_LONG); -} - -static RList *cpfind_int(RCore *core, RBinJavaObj *obj, const char *cmd) { - ut32 value = (ut32)r_cmd_java_get_input_num_value (core, cmd); - if (!r_cmd_java_is_valid_input_num_value (core, cmd)) { - return r_list_new (); - } - return r_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 4, R_BIN_JAVA_CP_INTEGER); -} - -static RList *cpfind_str(RBinJavaObj *obj, const char *cmd) { - if (!cmd) { - return r_list_new (); - } - IFDBG r_cons_printf ("Looking for str: %s (%d)\n", cmd, strlen (cmd)); - return r_bin_java_find_cp_const_by_val (obj, (const ut8 *)cmd, strlen (cmd), R_BIN_JAVA_CP_UTF8); -} - -static int cpfind(RCore *core, const char *cmd) { - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (get_anal (core)); - const char *p = cmd; - char f_type = 0; - RList *find_list = NULL; - RListIter *iter; - ut32 *idx; - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } - IFDBG r_cons_printf ("Function call made: %s\n", p); - if (p && *p) { - p = r_cmd_java_consumetok (cmd, ' ', -1); - f_type = *p; - p += 2; - } - IFDBG r_cons_printf ("Function call made: %s\n", p); - switch (f_type) { - case 's': find_list = cpfind_str (obj, p); break; - case 'i': find_list = cpfind_int (core, obj, r_cmd_java_consumetok (p, ' ', -1)); break; - case 'l': find_list = cpfind_long (core, obj, r_cmd_java_consumetok (p, ' ', -1)); break; - case 'f': find_list = cpfind_float (obj, r_cmd_java_consumetok (p, ' ', -1)); break; - case 'd': find_list = cpfind_double (obj, r_cmd_java_consumetok (p, ' ', -1)); break; - default: - eprintf ("[-] r_cmd_java: invalid java type to search for.\n"); - return true; - } - - r_list_foreach (find_list, iter, idx) { - ut64 addr = r_bin_java_resolve_cp_idx_address (obj, (ut16)*idx); - r_cons_printf ("Offset: 0x%" PFMT64x " idx: %d\n", addr, *idx); - } - r_list_free (find_list); - return true; -} - -static int r_cmd_java_reload_bin_from_buf(RCore *core, RBinJavaObj *obj, ut8 *buffer, ut64 len) { - if (!buffer || len < 10) { - return false; - } - int res = r_bin_java_load_bin (obj, buffer, len); - - if (res == true) { - //RBinPlugin *cp = NULL; - RBinPlugin *tmp; - RListIter *iter; - r_list_foreach (core->bin->plugins, iter, tmp) { - if (!strncmp ("java", tmp->name, 4)) { - //cp = tmp; - break; - } - } - // XXX - this API is no longer valid. - // need a function that will re-read bin bytes - // and parse the file - //if (cp) r_bin_update_items (core->bin, cp); - } - return res; -} - -static int r_cmd_java_get_cp_bytes_and_write(RCore *core, RBinJavaObj *obj, ut16 idx, ut64 addr, const ut8 *buf, const ut64 len) { - int res = false; - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (obj, idx); - ut64 c_file_sz = r_io_size (core->io); - ut32 n_sz = 0, c_sz = obj? r_bin_java_cp_get_size (obj, idx): (ut32)-1; - ut8 *bytes = NULL; - - if (c_sz == (ut32)-1) { - return res; - } - - bytes = r_bin_java_cp_get_bytes (cp_obj->tag, &n_sz, buf, len); - - if (n_sz < c_sz) { - res = r_core_shift_block (core, addr + c_sz, 0, (int)n_sz - (int)c_sz) && - r_io_resize (core->io, c_file_sz + (int)n_sz - (int)c_sz); - } else if (n_sz > c_sz) { - res = r_core_extend_at (core, addr, (int)n_sz - (int)c_sz); - } else { - eprintf ("[X] r_cmd_java_get_cp_bytes_and_write: Failed to resize the file correctly aborting.\n"); - return res; - } - - if (n_sz > 0 && bytes) { - res = r_core_write_at (core, addr, (const ut8 *)bytes, n_sz) && r_core_seek (core, addr, true); - } - - if (res == false) { - eprintf ("[X] r_cmd_java_get_cp_bytes_and_write: Failed to write the bytes to the file correctly aborting.\n"); - return res; - } - - R_FREE (bytes); - - if (res == true) { - ut64 n_file_sz = 0; - ut8 *bin_buffer = NULL; - res = r_io_use_fd (core->io, core->file->fd); - n_file_sz = r_io_size (core->io); - bin_buffer = n_file_sz > 0? malloc (n_file_sz): NULL; - if (bin_buffer) { - memset (bin_buffer, 0, n_file_sz); - res = n_file_sz == r_io_read_at (core->io, obj->loadaddr, bin_buffer, n_file_sz)? true: false; - if (res == true) { - res = r_cmd_java_reload_bin_from_buf ( - core, obj, bin_buffer, n_file_sz); - } else { - eprintf ("[X] r_cmd_java_get_cp_bytes_and_write: Failed to read the file in aborted, bin reload.\n"); - } - free (bin_buffer); - } - } - return res; -} - -static int r_cmd_java_handle_replace_cp_value_float(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { - float value = cmd && *cmd? atof (cmd): 0.0; - int res = false; - res = r_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 4); - return res; -} - -static int r_cmd_java_handle_replace_cp_value_double(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { - double value = cmd && *cmd? strtod (cmd, NULL): 0.0; - int res = false; - res = r_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 8); - return res; -} - -static int r_cmd_java_handle_replace_cp_value_long(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { - ut64 value = r_cmd_java_get_input_num_value (core, cmd); - int res = false; - res = r_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 8); - return res; -} - -static int r_cmd_java_handle_replace_cp_value_int(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { - ut32 value = (ut32)r_cmd_java_get_input_num_value (core, cmd); - int res = false; - res = r_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 4); - return res; -} - -static int r_cmd_java_handle_replace_cp_value_str(RCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { - int res = false; - ut32 len = cmd && *cmd? strlen (cmd): 0; - if (len > 0 && cmd && *cmd == '"') { - cmd++; - len = cmd && *cmd? strlen (cmd): 0; - } - if (cmd && len > 0) { - res = r_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)cmd, len); - } - return res; -} - -static int r_cmd_java_handle_replace_cp_value(RCore *core, const char *cmd) { - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (get_anal (core)); - ut16 idx = -1; - ut64 addr = 0; - const char *p = cmd; - char cp_type = 0; - IFDBG r_cons_printf ("Function call made: %s\n", p); - if (p && *p) { - p = r_cmd_java_consumetok (cmd, ' ', -1); - if (r_cmd_java_is_valid_input_num_value (core, p)) { - idx = r_cmd_java_get_input_num_value (core, p); - p = r_cmd_java_strtok (p, ' ', strlen (p)); - } - } - if (idx == (ut16)-1) { - eprintf ("[-] r_cmd_java: Invalid index value.\n"); - } else if (!obj) { - eprintf ("[-] r_cmd_java: The current binary is not a Java Bin Object.\n"); - } else if (!p || (p && !*p)) { - r_cmd_java_print_cmd_help (JAVA_CMDS + REPLACE_CP_VALUE_IDX); - return true; - } else { - cp_type = r_bin_java_resolve_cp_idx_tag (obj, idx); - addr = r_bin_java_resolve_cp_idx_address (obj, idx); - IFDBG r_cons_printf ("Function call made: %s\n", p); - switch (cp_type) { - case R_BIN_JAVA_CP_UTF8: return r_cmd_java_handle_replace_cp_value_str ( - core, obj, r_cmd_java_consumetok (p, ' ', -1), idx, addr); - case R_BIN_JAVA_CP_INTEGER: return r_cmd_java_handle_replace_cp_value_int ( - core, obj, r_cmd_java_consumetok (p, ' ', -1), idx, addr); - case R_BIN_JAVA_CP_LONG: return r_cmd_java_handle_replace_cp_value_long ( - core, obj, r_cmd_java_consumetok (p, ' ', -1), idx, addr); - case R_BIN_JAVA_CP_FLOAT: return r_cmd_java_handle_replace_cp_value_float ( - core, obj, r_cmd_java_consumetok (p, ' ', -1), idx, addr); - case R_BIN_JAVA_CP_DOUBLE: return r_cmd_java_handle_replace_cp_value_double ( - core, obj, r_cmd_java_consumetok (p, ' ', -1), idx, addr); - default: - eprintf ("[-] r_cmd_java: invalid java type to search for.\n"); - return false; - } - return true; - } - return false; -} - -static char *r_cmd_replace_name_def(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len) { - const char *fmt = "L%s;"; - char *s_new_ref = s_new && replace_len > 0? malloc (3 + replace_len): NULL; - char *s_old_ref = s_old && match_len > 0? malloc (3 + match_len): NULL; - char *result = NULL; - *res_len = 0; - if (s_new_ref && s_old_ref) { - snprintf (s_new_ref, replace_len + 3, fmt, s_new); - snprintf (s_old_ref, match_len + 3, fmt, s_old); - result = r_cmd_replace_name (s_new_ref, replace_len + 2, s_old_ref, match_len + 2, buffer, buf_len, res_len); - } - free (s_new_ref); - free (s_old_ref); - return result; -} - -static int r_cmd_is_object_descriptor(const char *name, ut32 name_len) { - int found_L = false, found_Semi = false; - ut32 idx = 0, L_pos = 0, Semi_pos = 0; - const char *p_name = name; - - for (idx = 0, L_pos = 0; idx < name_len; idx++, p_name++) { - if (*p_name == 'L') { - found_L = true; - L_pos = idx; - break; - } - } - - for (idx = 0, Semi_pos = 0; idx < name_len; idx++, p_name++) { - if (*p_name == ';') { - found_Semi = true; - Semi_pos = idx; - break; - } - } - - return true? found_L == found_Semi && found_L == true && L_pos < Semi_pos: false; -} - -static char *r_cmd_replace_name(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len) { - ut32 num_occurrences = 0, i = 0; - char *result = NULL, *p_result = NULL; - - num_occurrences = r_cmd_get_num_classname_str_occ (buffer, s_old); - *res_len = 0; - if (num_occurrences > 0 && replace_len > 0 && s_old) { - ut32 consumed = 0; - const char *next = r_cmd_get_next_classname_str (buffer + consumed, s_old); - IFDBG r_cons_printf ("Replacing \"%s\" with \"%s\" in: %s\n", s_old, s_new, buffer); - result = malloc (num_occurrences * replace_len + buf_len); - memset (result, 0, num_occurrences * replace_len + buf_len); - p_result = result; - while (next && consumed < buf_len) { - // replace up to next - IFDBG r_cons_printf ("next: \"%s\", len to: %d\n", next, next - buffer); - for (; buffer + consumed < next && consumed < buf_len; consumed++, p_result++) { - *p_result = *(buffer + consumed); - (*res_len)++; - } - - for (i = 0; i < replace_len; i++, p_result++) { - *p_result = *(s_new + i); - (*res_len)++; - } - consumed += match_len; - next = r_cmd_get_next_classname_str (buffer + consumed, s_old); - } - IFDBG r_cons_printf ("Found last occurrence of: \"%s\", remaining: %s\n", s_old, buffer + consumed); - IFDBG r_cons_printf ("result is: \"%s\"\n", result); - for (; consumed < buf_len; consumed++, p_result++, (*res_len)++) { - *p_result = *(buffer + consumed); - } - IFDBG r_cons_printf ("Old: %s\nNew: %s\n", buffer, result); - } - return result; -} - -static int r_cmd_java_get_class_names_from_input(const char *input, char **class_name, ut32 *class_name_len, char **new_class_name, ut32 *new_class_name_len) { - const char *p = input; - - ut32 cmd_sz = input && *input? strlen (input): 0; - int res = false; - - if (!class_name || *class_name) { - return res; - } else if (!new_class_name || *new_class_name) { - return res; - } else if (!new_class_name_len || !class_name_len) { - return res; - } - - *new_class_name = NULL; - *class_name_len = 0; - - if (p && *p && cmd_sz > 1) { - const char *end; - p = r_cmd_java_consumetok (p, ' ', cmd_sz); - end = p && *p? r_cmd_java_strtok (p, ' ', -1): NULL; - - if (p && end && p != end) { - *class_name_len = end - p + 1; - *class_name = malloc (*class_name_len); - snprintf (*class_name, *class_name_len, "%s", p); - cmd_sz = *class_name_len - 1 < cmd_sz? cmd_sz - *class_name_len: 0; - } - - if (*class_name && cmd_sz > 0) { - p = r_cmd_java_consumetok (end + 1, ' ', cmd_sz); - end = p && *p? r_cmd_java_strtok (p, ' ', -1): NULL; - - if (!end && p && *p) { - end = p + cmd_sz; - } - - if (p && end && p != end) { - *new_class_name_len = end - p + 1; - *new_class_name = malloc (*new_class_name_len); - snprintf (*new_class_name, *new_class_name_len, "%s", p); - res = true; - } - } - } - return res; -} - -static int r_cmd_java_handle_replace_classname_value(RCore *core, const char *cmd) { - RBinJavaObj *obj; - char *class_name = NULL, *new_class_name = NULL; - ut32 class_name_len = 0, new_class_name_len = 0; - RAnal *anal = get_anal (core); - const char *p = cmd; - int res = false; - ut32 idx = -1; - - if (!core || !anal || !cmd) { - return false; - } - IFDBG r_cons_printf ("Function call made: %s\n", p); - obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - if (!obj) { - eprintf ("The current binary is not a Java Bin Object.\n"); - return true; - } - res = r_cmd_java_get_class_names_from_input (cmd, &class_name, - &class_name_len, &new_class_name, &new_class_name_len); - - if (!res || !class_name || !new_class_name) { - r_cmd_java_print_cmd_help (JAVA_CMDS + REPLACE_CLASS_NAME_IDX); - free (class_name); - free (new_class_name); - return true; - } - for (idx = 1; idx <= obj->cp_count; idx++) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (obj, idx); - char *name = NULL; - ut8 *buffer = NULL; - ut32 buffer_sz = 0; - ut16 len = 0; - if (cp_obj && cp_obj->tag == R_BIN_JAVA_CP_UTF8 && - cp_obj->info.cp_utf8.length && cp_obj->info.cp_utf8.length >= class_name_len - 1) { - ut32 num_occurrences = 0; - ut64 addr = cp_obj->file_offset + cp_obj->loadaddr; - buffer = r_bin_java_cp_get_idx_bytes (obj, idx, &buffer_sz); - - if (!buffer) { - continue; - } - len = R_BIN_JAVA_USHORT (buffer, 1); - name = malloc (len + 3); - memcpy (name, buffer + 3, len); - name[len] = 0; - - num_occurrences = r_cmd_get_num_classname_str_occ (name, class_name); - - if (num_occurrences > 0) { - // perform inplace replacement - ut32 res_len = 0; - char *result = NULL; - - if (r_cmd_is_object_descriptor (name, len) == true) { - result = r_cmd_replace_name_def (new_class_name, - new_class_name_len - 1, class_name, - class_name_len - 1, name, len, &res_len); - } else { - result = r_cmd_replace_name (new_class_name, - new_class_name_len - 1, class_name, - class_name_len - 1, name, len, &res_len); - } - if (result) { - res = r_cmd_java_get_cp_bytes_and_write ( - core, obj, idx, addr, - (const ut8 *)result, res_len); - if (res == false) { - eprintf ("ERROR: r_cmd_java: Failed to write bytes or reload the binary.\n"); - } - } - free (result); - } - free (buffer); - free (name); - } - } - free (class_name); - free (new_class_name); - return true; -} - -static int r_cmd_java_handle_reload_bin(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - const char *p = cmd; - ut64 addr = 0LL; //cur_offset = core->offset, addr = 0; - ut64 buf_size = 0; - ut8 *buf = NULL; - int res = false; - - if (*cmd == ' ') { - p = r_cmd_java_consumetok (p, ' ', -1); - } - if (!*cmd) { - r_cmd_java_print_cmd_help (JAVA_CMDS + RELOAD_BIN_IDX); - return true; - } - - addr = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut32)-1; - if (*cmd == ' ') { - p = r_cmd_java_consumetok (p, ' ', -1); - } - buf_size = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut32)-1; - - // XXX this may cause problems cause the file we are looking at may not be the bin we want. - // lets pretend it is for now - if (buf_size == 0) { - res = r_io_use_fd (core->io, core->file->fd); - buf_size = r_io_size (core->io); - buf = malloc (buf_size); - memset (buf, 0, buf_size); - r_io_read_at (core->io, addr, buf, buf_size); - } - if (buf && obj) { - res = r_cmd_java_reload_bin_from_buf (core, obj, buf, buf_size); - } - free (buf); - return res; -} - -static int r_cmd_java_handle_find_cp_const(RCore *core, const char *cmd) { - const char *p = (cmd && *cmd == ' ')? r_cmd_java_consumetok (cmd, ' ', -1): NULL; - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (get_anal (core)); - RAnalFunction *fcn = NULL; - RAnalBlock *bb = NULL; - RListIter *bb_iter, *fn_iter, *iter; - RCmdJavaCPResult *cp_res = NULL; - ut16 idx = -1; - RList *find_list; - - if (p && *p == 'a') { - idx = -1; - } else { - idx = r_cmd_java_get_input_num_value (core, p); - } - - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } - if (!cmd || !*cmd) { - eprintf ("[-] r_cmd_java: invalid command syntax.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + FIND_CP_CONST_IDX); - return true; - } - if (idx == 0) { - eprintf ("[-] r_cmd_java: invalid CP Obj Index Supplied.\n"); - return true; - } - find_list = r_list_new (); - find_list->free = free; - // XXX - this will break once RAnal moves to sdb - r_list_foreach (core->anal->fcns, fn_iter, fcn) { - r_list_foreach (fcn->bbs, bb_iter, bb) { - char op = bb->op_bytes[0]; - cp_res = NULL; - switch (op) { - case 0x12: - cp_res = (idx == (ut16)-1) || (bb->op_bytes[1] == idx)? R_NEW0 (RCmdJavaCPResult): NULL; - if (cp_res) { - cp_res->idx = bb->op_bytes[1]; - } - break; - case 0x13: - case 0x14: - cp_res = (idx == (ut16)-1) || (R_BIN_JAVA_USHORT (bb->op_bytes, 1) == idx)? R_NEW0 (RCmdJavaCPResult): NULL; - if (cp_res) { - cp_res->idx = R_BIN_JAVA_USHORT (bb->op_bytes, 1); - } - break; - } - if (cp_res) { - cp_res->addr = bb->addr; - cp_res->obj = r_bin_java_get_item_from_cp (obj, cp_res->idx); - r_list_append (find_list, cp_res); - } - } - } - if (idx == (ut16)-1) { - r_list_foreach (find_list, iter, cp_res) { - const char *t = ((RBinJavaCPTypeMetas *)cp_res->obj->metas->type_info)->name; - r_cons_printf ("@0x%" PFMT64x " idx = %d Type = %s\n", cp_res->addr, cp_res->idx, t); - } - - } else { - r_list_foreach (find_list, iter, cp_res) { - r_cons_printf ("@0x%" PFMT64x "\n", cp_res->addr); - } - } - r_list_free (find_list); - return true; -} - -static int r_cmd_java_handle_field_info(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - ut16 idx = -1; - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } else if (!cmd || !*cmd) { - eprintf ("[-] r_cmd_java: invalid command syntax.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + FIELD_INFO_IDX); - return true; - } - - if (*(cmd) == 's' || *(cmd) == 'n') { - idx = r_cmd_java_get_input_num_value (core, cmd + 1); - } - - switch (*(cmd)) { - case 'c': return r_cmd_java_print_field_num_name (obj); - case 's': return r_cmd_java_print_field_summary (obj, idx); - case 'n': return r_cmd_java_print_field_name (obj, idx); - } - IFDBG r_cons_printf ("Command is (%s)\n", cmd); - eprintf ("[-] r_cmd_java: invalid command syntax.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + FIELD_INFO_IDX); - return false; -} - -static int r_cmd_java_handle_method_info(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - RBinJavaObj *obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - IFDBG r_cons_printf ("Command is (%s)\n", cmd); - ut16 idx = -1; - - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - return true; - } else if (!cmd || !*cmd) { - eprintf ("[-] r_cmd_java: invalid command syntax.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + METHOD_INFO_IDX); - return false; - } - - if (*(cmd) == 's' || *(cmd) == 'n') { - idx = r_cmd_java_get_input_num_value (core, cmd + 1); - } - - switch (*(cmd)) { - case 'c': return r_cmd_java_print_method_num_name (obj); - case 's': return r_cmd_java_print_method_summary (obj, idx); - case 'n': return r_cmd_java_print_method_name (obj, idx); - } - - IFDBG r_cons_printf ("Command is (%s)\n", cmd); - eprintf ("[-] r_cmd_java: invalid command syntax.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + METHOD_INFO_IDX); - return false; -} - -static int r_cmd_java_handle_calc_class_sz(RCore *core, const char *cmd) { - int res = false; - ut64 sz = UT64_MAX; - ut64 addr = UT64_MAX; - ut64 res_size = UT64_MAX, - cur_fsz = r_io_fd_size (core->io, r_core_file_cur (core)->fd); - ut8 *tbuf, *buf = NULL; - ut32 init_size = (1 << 16); - const char *p = cmd? r_cmd_java_consumetok (cmd, ' ', -1): NULL; - addr = p && *p && r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): UT64_MAX; - - // TODO add a size parameter to the command to skip the guessing part. - - if (addr != UT64_MAX && sz == UT64_MAX) { - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - IFDBG r_cons_printf ("Attempting to calculate class file size @ : 0x%" PFMT64x ".\n", addr); - sz = cur_fsz < init_size? cur_fsz: init_size; - while (sz <= cur_fsz) { - tbuf = realloc (buf, sz); - if (!tbuf) { - eprintf ("Memory allocation failed.\n"); - free (buf); - break; - } - buf = tbuf; - ut64 r_sz = r_io_read_at (core->io, addr, buf, sz)? sz: 0LL; - // check the return read on the read - if (r_sz == 0) { - break; - } - res_size = r_bin_java_calc_class_size (buf, sz); - // if the data buffer contains a class starting - // at address, then the res_size will be the size - // if the r_sz is less than the sz, then we are near - // the end of the core buffer, and there is no need - // to continue trying to find the class size. - if (res_size != UT64_MAX || - r_sz < sz) { - res = r_sz < sz? false: true; - free (buf); - break; - } else { - sz += (1 << 16); - } - } - if (res) { - r_cons_printf ("%" PFMT64d, res_size); - } else { - r_cons_printf ("-1\n"); - } - - //snprintf (cmd_buf, 50, fmt, num_acc_flag, addr); - //res = r_core_cmd0(core, y); - } else { - r_cmd_java_print_cmd_help (JAVA_CMDS + CALC_SZ_IDX); - } - return true; -} - -static int r_cmd_java_handle_isvalid(RCore *core, const char *cmd) { - int res = false; - ut64 res_size = UT64_MAX; - ut8 *tbuf, *buf = NULL; - ut32 cur_fsz = r_io_fd_size (core->io, r_core_file_cur (core)->fd); - ut64 sz = UT64_MAX; - const char *p = cmd? r_cmd_java_consumetok (cmd, ' ', -1): NULL; - ut64 addr = UT64_MAX; - addr = p && *p && r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): UT64_MAX; - - // TODO add a size parameter to the command to skip the guessing part. - - if (addr != UT64_MAX && sz == UT64_MAX) { - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - IFDBG r_cons_printf ("Attempting to calculate class file size @ : 0x%" PFMT64x ".\n", addr); - - while (sz <= cur_fsz) { - tbuf = realloc (buf, sz); - if (!tbuf) { - eprintf ("Memory allocation failed.\n"); - free (buf); - break; - } - buf = tbuf; - ut64 r_sz = r_io_read_at (core->io, addr, buf, sz)? sz: 0LL; - // check the return read on the read - if (r_sz == 0) { - break; - } - res_size = r_bin_java_calc_class_size (buf, sz); - // if the data buffer contains a class starting - // at address, then the res_size will be the size - // if the r_sz is less than the sz, then we are near - // the end of the core buffer, and there is no need - // to continue trying to find the class size. - if (res_size != UT64_MAX || - r_sz < sz) { - res = r_sz < sz? false: true; - free (buf); - break; - } else { - sz <<= 1; - } - } - r_cons_printf ("%s\n", r_str_bool (res)); - } else { - r_cmd_java_print_cmd_help (JAVA_CMDS + ISVALID_IDX); - } - return true; -} - -static int r_cmd_java_handle_resolve_cp(RCore *core, const char *cmd) { - RAnal *anal = get_anal (core); - char c_type = cmd && *cmd? *cmd: 0; - RBinJavaObj *obj = r_cmd_java_get_bin_obj (anal); - ut32 idx = r_cmd_java_get_input_num_value (core, cmd + 2); - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - IFDBG r_cons_printf ("Ctype: %d (%c) RBinJavaObj points to: %p and the idx is (%s): %d\n", c_type, c_type, obj, cmd + 2, idx); - int res = false; - if (idx > 0 && obj) { - switch (c_type) { - case 't': return r_cmd_java_resolve_cp_type (obj, idx); - case 'c': return r_cmd_java_resolve_cp_idx (obj, idx); - case 'e': return r_cmd_java_resolve_cp_idx_b64 (obj, idx); - case 'a': return r_cmd_java_resolve_cp_address (obj, idx); - case 's': return r_cmd_java_resolve_cp_summary (obj, idx); - case 'k': return r_cmd_java_resolve_cp_to_key (obj, idx); - } - } else if (obj && c_type == 'g') { - for (idx = 1; idx <= obj->cp_count; idx++) { - ut64 addr = r_bin_java_resolve_cp_idx_address (obj, idx); - char *str = r_bin_java_resolve_cp_idx_type (obj, idx); - r_cons_printf ("CP_OBJ Type %d = %s @ 0x%" PFMT64x "\n", idx, str, addr); - free (str); - } - res = true; - } else if (obj && c_type == 'd') { - for (idx = 1; idx <= obj->cp_count; idx++) { - r_cmd_java_resolve_cp_summary (obj, idx); - } - res = true; - } else { - if (!obj) { - eprintf ("[-] r_cmd_java: no valid java bins found.\n"); - } else { - eprintf ("[-] r_cmd_java: invalid cp index given, must idx > 1.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + RESOLVE_CP_IDX); - } - res = true; - } - return res; -} - -static int r_cmd_java_get_all_access_flags_value(const char *cmd) { - RList *the_list = NULL; - RListIter *iter = NULL; - char *str = NULL; - - switch (*(cmd)) { - case 'f': the_list = retrieve_all_field_access_string_and_value (); break; - case 'm': the_list = retrieve_all_method_access_string_and_value (); break; - case 'c': the_list = retrieve_all_class_access_string_and_value (); break; - } - if (!the_list) { - eprintf ("[-] r_cmd_java: incorrect syntax for the flags calculation.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + CALC_FLAGS_IDX); - return false; - } - switch (*(cmd)) { - case 'f': r_cons_printf ("[=] Fields Access Flags List\n"); break; - case 'm': r_cons_printf ("[=] Methods Access Flags List\n"); break; - case 'c': - r_cons_printf ("[=] Class Access Flags List\n"); - ; - break; - } - - r_list_foreach (the_list, iter, str) { - r_cons_println (str); - } - r_list_free (the_list); - return true; -} - -static int r_cmd_java_handle_calc_flags(RCore *core, const char *cmd) { - IFDBG r_cons_printf ("Function call made: %s\n", cmd); - int res = false; - - switch (*(cmd)) { - case 'f': return r_cmd_java_print_field_access_flags_value (cmd + 2); - case 'm': return r_cmd_java_print_method_access_flags_value (cmd + 2); - case 'c': return r_cmd_java_print_class_access_flags_value (cmd + 2); - } - - if (*(cmd) == 'l') { - const char *lcmd = *cmd + 1 == ' '? cmd + 2: cmd + 1; - IFDBG eprintf ("Seeing %s and accepting %s\n", cmd, lcmd); - switch (*(lcmd)) { - case 'f': - case 'm': - case 'c': res = r_cmd_java_get_all_access_flags_value (lcmd); break; - } - // Just print them all out - if (res == false) { - r_cmd_java_get_all_access_flags_value ("c"); - r_cmd_java_get_all_access_flags_value ("m"); - res = r_cmd_java_get_all_access_flags_value ("f"); - } - } - if (res == false) { - eprintf ("[-] r_cmd_java: incorrect syntax for the flags calculation.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + CALC_FLAGS_IDX); - res = true; - } - return res; -} - -static int r_cmd_java_handle_flags_str(RCore *core, const char *cmd) { - - int res = false; - ut32 flag_value = -1; - const char f_type = cmd? *cmd: 0; - const char *p = cmd? cmd + 2: NULL; - char *flags_str = NULL; - - IFDBG r_cons_printf ("r_cmd_java_handle_flags_str: ftype = %c, idx = %s\n", f_type, p); - if (p) { - flag_value = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut32)-1; - } - - if (p && f_type) { - switch (f_type) { - case 'm': flags_str = retrieve_method_access_string ((ut16)flag_value); break; - case 'f': flags_str = retrieve_field_access_string ((ut16)flag_value); break; - case 'c': flags_str = retrieve_class_method_access_string ((ut16)flag_value); break; - default: flags_str = NULL; - } - } - - if (flags_str) { - switch (f_type) { - case 'm': r_cons_printf ("Method Access Flags String: "); break; - case 'f': r_cons_printf ("Field Access Flags String: "); break; - case 'c': r_cons_printf ("Class Access Flags String: "); break; - } - r_cons_println (flags_str); - free (flags_str); - res = true; - } - if (res == false) { - eprintf ("[-] r_cmd_java: incorrect syntax for the flags calculation.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + FLAGS_STR_IDX); - res = true; - } - return res; -} - -static int r_cmd_java_handle_flags_str_at(RCore *core, const char *cmd) { - - int res = false; - ut64 flag_value_addr = -1; - ut32 flag_value = -1; - const char f_type = cmd? *r_cmd_java_consumetok (cmd, ' ', -1): 0; - const char *p = cmd? cmd + 2: NULL; - char *flags_str = NULL; - - IFDBG r_cons_printf ("r_cmd_java_handle_flags_str_at: ftype = 0x%02x, idx = %s\n", f_type, p); - if (p) { - flag_value = 0; - ut64 cur_offset = core->offset; - flag_value_addr = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut32)-1; - r_io_read_at (core->io, flag_value_addr, (ut8 *)&flag_value, 2); - IFDBG r_cons_printf ("r_cmd_java_handle_flags_str_at: read = 0x%04x\n", flag_value); - if (cur_offset != core->offset) { - r_core_seek (core, cur_offset - 2, true); - } - flag_value = R_BIN_JAVA_USHORT (((ut8 *)&flag_value), 0); - } - - if (p && f_type) { - switch (f_type) { - case 'm': flags_str = retrieve_method_access_string ((ut16)flag_value); break; - case 'f': flags_str = retrieve_field_access_string ((ut16)flag_value); break; - case 'c': flags_str = retrieve_class_method_access_string ((ut16)flag_value); break; - default: flags_str = NULL; - } - } - - if (flags_str) { - switch (f_type) { - case 'm': r_cons_printf ("Method Access Flags String: "); break; - case 'f': r_cons_printf ("Field Access Flags String: "); break; - case 'c': r_cons_printf ("Class Access Flags String: "); break; - } - r_cons_println (flags_str); - free (flags_str); - res = true; - } - if (res == false) { - eprintf ("[-] r_cmd_java: incorrect syntax for the flags calculation.\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + FLAGS_STR_IDX); - res = true; - } - return res; -} - -static char r_cmd_java_is_valid_java_mcf(char b) { - char c = 0; - switch (b) { - case 'c': - case 'f': - case 'm': c = b; - } - return c; -} - -static int r_cmd_java_handle_set_flags(RCore *core, const char *input) { - //#define SET_ACC_FLAGS_ARGS "< c | m | f> >" - const char *p = r_cmd_java_consumetok (input, ' ', -1); - ut64 addr = p && r_cmd_java_is_valid_input_num_value (core, p) - ? r_cmd_java_get_input_num_value (core, p) - : (ut64)-1; - p = r_cmd_java_strtok (p + 1, ' ', -1); - if (!p || !*p) { - r_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); - return true; - } - const char f_type = p && *p? r_cmd_java_is_valid_java_mcf (*(++p)): '?'; - - int flag_value = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): -1; - - if (flag_value == 16 && f_type == 'f') { - flag_value = -1; - } - IFDBG r_cons_printf ("Converting %s to flags\n", p); - - if (p) { - p += 2; - } - if (flag_value == -1) { - flag_value = r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): -1; - } - bool res = false; - if (!input) { - eprintf ("[-] r_cmd_java: no address provided .\n"); - res = true; - } else if (addr == (ut64)-1) { - eprintf ("[-] r_cmd_java: no address provided .\n"); - res = true; - } else if (f_type == '?' && flag_value == -1) { - eprintf ("[-] r_cmd_java: no flag type provided .\n"); - res = true; - } - - if (res) { - r_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); - return res; - } - - IFDBG r_cons_printf ("Writing ftype '%c' to 0x%" PFMT64x ", %s.\n", f_type, addr, p); - - // handling string based access flags (otherwise skip ahead) - IFDBG r_cons_printf ("Converting %s to flags\n", p); - if (f_type && flag_value != -1) { - switch (f_type) { - case 'f': flag_value = r_bin_java_calculate_field_access_value (p); break; - case 'm': flag_value = r_bin_java_calculate_method_access_value (p); break; - case 'c': flag_value = r_bin_java_calculate_class_access_value (p); break; - default: flag_value = -1; - } - } - IFDBG r_cons_printf ("Current args: (flag_value: 0x%04x addr: 0x%" PFMT64x ")\n.", flag_value, addr, res); - if (flag_value != -1) { - res = r_cmd_java_set_acc_flags (core, addr, ((ut16)flag_value) & 0xffff); - IFDBG r_cons_printf ("Writing 0x%04x to 0x%" PFMT64x ": %d.", flag_value, addr, res); - } else { - eprintf ("[-] r_cmd_java: invalid flag value or type provided .\n"); - r_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); - res = true; - } - return res; -} - -static int r_cmd_java_call(void *user, const char *input) { - RCore *core = (RCore *)user; - int res = false; - ut32 i = 0; - if (strncmp (input, "java", 4)) { - return false; - } - if (input[4] != ' ') { - return r_cmd_java_handle_help (core, input); - } - for (; i < END_CMDS - 1; i++) { - //IFDBG r_cons_printf ("Checking cmd: %s %d %s\n", JAVA_CMDS[i].name, JAVA_CMDS[i].name_len, p); - IFDBG r_cons_printf ("Checking cmd: %s %d\n", JAVA_CMDS[i].name, - strncmp (input + 5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len)); - if (!strncmp (input + 5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len)) { - const char *cmd = input + 5 + JAVA_CMDS[i].name_len; - if (*cmd && *cmd == ' ') { - cmd++; - } - //IFDBG r_cons_printf ("Executing cmd: %s (%s)\n", JAVA_CMDS[i].name, cmd+5+JAVA_CMDS[i].name_len ); - res = JAVA_CMDS[i].handler (core, cmd); - break; - } - } - if (!res) { - return r_cmd_java_handle_help (core, input); - } - return true; -} - -static int r_cmd_java_print_method_definitions(RBinJavaObj *obj) { - RList *the_list = r_bin_java_get_method_definitions (obj), - *off_list = r_bin_java_get_method_offsets (obj); - char *str = NULL; - ut32 idx = 0, end = r_list_length (the_list); - - while (idx < end) { - ut64 *addr = r_list_get_n (off_list, idx); - str = r_list_get_n (the_list, idx); - r_cons_printf ("%s; // @0x%04" PFMT64x "\n", str, *addr); - idx++; - } - - r_list_free (the_list); - r_list_free (off_list); - return true; -} - -static int r_cmd_java_print_field_definitions(RBinJavaObj *obj) { - RList *the_list = r_bin_java_get_field_definitions (obj), - *off_list = r_bin_java_get_field_offsets (obj); - char *str = NULL; - ut32 idx = 0, end = r_list_length (the_list); - - while (idx < end) { - ut64 *addr = r_list_get_n (off_list, idx); - str = r_list_get_n (the_list, idx); - r_cons_printf ("%s; // @0x%04" PFMT64x "\n", str, *addr); - idx++; - } - - r_list_free (the_list); - r_list_free (off_list); - return true; -} - -static int r_cmd_java_print_import_definitions(RBinJavaObj *obj) { - RList *the_list = r_bin_java_get_import_definitions (obj); - char *str = NULL; - RListIter *iter; - r_list_foreach (the_list, iter, str) { - r_cons_printf ("import %s;\n", str); - } - r_list_free (the_list); - return true; -} - -static int r_cmd_java_print_all_definitions(RAnal *anal) { - RList *obj_list = r_cmd_java_get_bin_obj_list (anal); - RListIter *iter; - RBinJavaObj *obj; - - if (!obj_list) { - return 1; - } - r_list_foreach (obj_list, iter, obj) { - r_cmd_java_print_class_definitions (obj); - } - return true; -} - -static int r_cmd_java_print_json_definitions(RBinJavaObj *obj) { - DsoJsonObj *json_obj = r_bin_java_get_bin_obj_json (obj); - char *str = dso_json_obj_to_str (json_obj); - dso_json_obj_del (json_obj); // XXX memleak - r_cons_println (str); - return true; -} - -static int r_cmd_java_print_class_definitions(RBinJavaObj *obj) { - RList *the_fields = r_bin_java_get_field_definitions (obj), - *the_methods = r_bin_java_get_method_definitions (obj), - *the_imports = r_bin_java_get_import_definitions (obj), - *the_moffsets = r_bin_java_get_method_offsets (obj), - *the_foffsets = r_bin_java_get_field_offsets (obj); - - char *class_name = r_bin_java_get_this_class_name (obj); - char *str = NULL; - - r_cmd_java_print_import_definitions (obj); - r_cons_printf ("\nclass %s { // @0x%04" PFMT64x "\n", class_name, obj->loadaddr); - - if (the_fields && the_foffsets && r_list_length (the_fields) > 0) { - r_cons_printf ("\n // Fields defined in the class\n"); - ut32 idx = 0, end = r_list_length (the_fields); - - while (idx < end) { - ut64 *addr = r_list_get_n (the_foffsets, idx); - str = r_list_get_n (the_fields, idx); - r_cons_printf (" %s; // @0x%04" PFMT64x "\n", str, *addr); - idx++; - } - } - - if (the_methods && the_moffsets && r_list_length (the_methods) > 0) { - r_cons_printf ("\n // Methods defined in the class\n"); - ut32 idx = 0, end = r_list_length (the_methods); - - while (idx < end) { - ut64 *addr = r_list_get_n (the_moffsets, idx); - str = r_list_get_n (the_methods, idx); - r_cons_printf (" %s; // @0x%04" PFMT64x "\n", str, *addr); - idx++; - } - } - r_cons_printf ("}\n"); - - r_list_free (the_imports); - r_list_free (the_fields); - r_list_free (the_methods); - r_list_free (the_foffsets); - r_list_free (the_moffsets); - - free (class_name); - return true; -} - -static RList *r_cmd_java_get_bin_obj_list(RAnal *anal) { - RBinJavaObj *bin_obj = (RBinJavaObj *)r_cmd_java_get_bin_obj (anal); - // See libr/bin/p/bin_java.c to see what is happening here. The original intention - // was to use a shared global db variable from shlr/java/class.c, but the - // BIN_OBJS_ADDRS variable kept getting corrupted on Mac, so I (deeso) switched the - // way the access to the db was taking place by using the bin_obj as a proxy back - // to the BIN_OBJS_ADDRS which is instantiated in libr/bin/p/bin_java.c - // not the easiest way to make sausage, but its getting made. - return r_bin_java_get_bin_obj_list_thru_obj (bin_obj); -} - -static RBinJavaObj *r_cmd_java_get_bin_obj(RAnal *anal) { - RBin *b; - int is_java; - RBinPlugin *plugin; - if (!anal || !anal->binb.bin) { - return NULL; - } - b = anal->binb.bin; - if (!b->cur || !b->cur->o) { - return NULL; - } - plugin = b->cur->o->plugin; - is_java = (plugin && strcmp (plugin->name, "java") == 0)? 1: 0; - return is_java? b->cur->o->bin_obj: NULL; -} - -static int r_cmd_java_resolve_cp_idx(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - char *str = r_bin_java_resolve_without_space (obj, idx); - r_cons_println (str); - free (str); - } - return true; -} - -static int r_cmd_java_resolve_cp_type(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - char *str = r_bin_java_resolve_cp_idx_type (obj, idx); - r_cons_println (str); - free (str); - } - return true; -} - -static int r_cmd_java_resolve_cp_idx_b64(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - char *str = r_bin_java_resolve_b64_encode (obj, idx); - r_cons_println (str); - free (str); - } - return true; -} - -static int r_cmd_java_resolve_cp_address(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - ut64 addr = r_bin_java_resolve_cp_idx_address (obj, idx); - if (addr == (ut64)-1) { - r_cons_printf ("Unable to resolve CP Object @ index: 0x%04x\n", idx); - } else { - r_cons_printf ("0x%" PFMT64x "\n", addr); - } - } - return true; -} - -static int r_cmd_java_resolve_cp_to_key(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - char *str = r_bin_java_resolve_cp_idx_to_string (obj, idx); - r_cons_println (str); - free (str); - } - return true; -} -static int r_cmd_java_resolve_cp_summary(RBinJavaObj *obj, ut16 idx) { - if (obj && idx) { - r_bin_java_resolve_cp_idx_print_summary (obj, idx); - } - return true; -} - -static int r_cmd_java_is_valid_input_num_value(RCore *core, const char *input_value) { - ut64 value = input_value? r_num_math (core->num, input_value): 0; - return !(value == 0 && input_value && *input_value == '0'); -} - -static ut64 r_cmd_java_get_input_num_value(RCore *core, const char *input_value) { - ut64 value = input_value? r_num_math (core->num, input_value): 0; - return value; -} - -static int r_cmd_java_print_class_access_flags_value(const char *flags) { - ut16 result = r_bin_java_calculate_class_access_value (flags); - r_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); - return true; -} -static int r_cmd_java_print_field_access_flags_value(const char *flags) { - ut16 result = r_bin_java_calculate_field_access_value (flags); - r_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); - return true; -} -static int r_cmd_java_print_method_access_flags_value(const char *flags) { - ut16 result = r_bin_java_calculate_method_access_value (flags); - r_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); - return true; -} - -static int r_cmd_java_set_acc_flags(RCore *core, ut64 addr, ut16 num_acc_flag) { - char cmd_buf[50]; - - int res = false; - num_acc_flag = R_BIN_JAVA_USHORT (((ut8 *)&num_acc_flag), 0); - res = r_core_write_at (core, addr, (const ut8 *)&num_acc_flag, 2); - if (!res) { - eprintf ("[X] r_cmd_java_set_acc_flags: Failed to write.\n"); - return res; - } - res = true; - IFDBG r_cons_printf ("Executed cmd: %s == %d\n", cmd_buf, res); - return res; -} -static int r_cmd_java_print_field_num_name(RBinJavaObj *obj) { - RList *the_list = r_bin_java_get_field_num_name (obj); - char *str; - RListIter *iter = NULL; - r_list_foreach (the_list, iter, str) { - r_cons_println (str); - } - r_list_free (the_list); - return true; -} - -static int r_cmd_java_print_method_num_name(RBinJavaObj *obj) { - RList *the_list = r_bin_java_get_method_num_name (obj); - char *str; - RListIter *iter = NULL; - r_list_foreach (the_list, iter, str) { - r_cons_println (str); - } - r_list_free (the_list); - return true; -} - -static int r_cmd_java_print_field_summary(RBinJavaObj *obj, ut16 idx) { - int res = r_bin_java_print_field_idx_summary (obj, idx); - if (res == false) { - eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); - res = true; - } - return res; -} - -static int UNUSED_FUNCTION(r_cmd_java_print_field_count)(RBinJavaObj *obj) { - ut32 res = r_bin_java_get_field_count (obj); - r_cons_printf ("%d\n", res); - r_cons_flush (); - return true; -} - -static int r_cmd_java_print_field_name(RBinJavaObj *obj, ut16 idx) { - char *res = r_bin_java_get_field_name (obj, idx); - if (res) { - r_cons_println (res); - } else { - eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); - } - free (res); - return true; -} - -static int r_cmd_java_print_method_summary(RBinJavaObj *obj, ut16 idx) { - int res = r_bin_java_print_method_idx_summary (obj, idx); - if (res == false) { - eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); - res = true; - } - return res; -} - -static int _(r_cmd_java_print_method_count)(RBinJavaObj *obj) { - ut32 res = r_bin_java_get_method_count (obj); - r_cons_printf ("%d\n", res); - r_cons_flush (); - return true; -} - -static int r_cmd_java_print_method_name(RBinJavaObj *obj, ut16 idx) { - char *res = r_bin_java_get_method_name (obj, idx); - if (res) { - r_cons_println (res); - } else { - eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); - } - free (res); - return true; -} - -static int r_cmd_java_handle_yara_code_extraction_refs(RCore *core, const char *input) { - RAnal *anal = get_anal (core); - RBinJavaObj *bin = anal? (RBinJavaObj *)r_cmd_java_get_bin_obj (anal): NULL; - const char *p = input? r_cmd_java_consumetok (input, ' ', -1): NULL, *n = NULL; - char *name = NULL; - ut64 addr = -1, count = -1; - int res = false; - - if (!bin) { - return res; - } else if (!anal || !anal->fcns || r_list_length (anal->fcns) == 0) { - eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n"); - return true; - } - - if (!p) { - return res; - } - - n = *p? r_cmd_java_strtok (p, ' ', -1): NULL; - name = n && p && p != n? malloc (n - p + 2): NULL; - - if (!name) { - return res; - } - - memset (name, 0, n - p); - memcpy (name, p, n - p); - - p = r_cmd_java_strtok (p, ' ', -1); - addr = p && *p && r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut64)-1; - - p = r_cmd_java_strtok (p, ' ', -1); - count = p && *p && r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): (ut64)-1; - - if (name && count != (ut64)-1 && addr != (ut64)-1) { - // find function at addr - - // find the start basic block - - // read the bytes - - // hexlify the bytes - - // set the name = bytes - - // print t - } - free (name); - return res; -} - -static int r_cmd_java_handle_insert_method_ref(RCore *core, const char *input) { - RAnal *anal = get_anal (core); - RBinJavaObj *bin = anal? (RBinJavaObj *)r_cmd_java_get_bin_obj (anal): NULL; - const char *p = input? r_cmd_java_consumetok (input, ' ', -1): NULL, *n = NULL; - char *classname = NULL, *name = NULL, *descriptor = NULL; - ut32 cn_sz = 0, n_sz = 0, d_sz = 0; - int res = false; - - if (!bin) { - return res; - } - if (!anal || !anal->fcns || r_list_length (anal->fcns) == 0) { - eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n"); - return true; - } - if (!p) { - return res; - } - - n = p && *p? r_cmd_java_strtok (p, ' ', -1): NULL; - classname = n && p && p != n? malloc (n - p + 1): NULL; - cn_sz = n && p? n - p + 1: 0; - if (!classname) { - return res; - } - - snprintf (classname, cn_sz, "%s", p); - p = n + 1; - n = p && *p? r_cmd_java_strtok (p, ' ', -1): NULL; - name = n && p && p != n? malloc (n - p + 1): NULL; - n_sz = n && p? n - p + 1: 0; - if (!name) { - free (classname); - return res; - } - snprintf (name, n_sz, "%s", p); - - p = n + 1; - n = p && *p? r_cmd_java_strtok (p, ' ', -1): NULL; - if (n) { - descriptor = n && p && p != n? malloc (n - p + 1): NULL; - d_sz = n - p + 1; - } else if (p && *p) { - d_sz = strlen (p) + 1; - descriptor = d_sz > 1? malloc (d_sz): NULL; - } - - if (!descriptor) { - free (classname); - free (name); - return res; - } - snprintf (descriptor, d_sz, "%s", p); - - r_cons_printf ("Would be adding class name:%s, name: %s, descriptor: %s\n", classname, name, descriptor); - free (classname); - free (name); - free (descriptor); - res = true; - return res; -} - -static int r_cmd_java_handle_print_exceptions(RCore *core, const char *input) { - RAnal *anal = get_anal (core); - RBinJavaObj *bin = (RBinJavaObj *) r_cmd_java_get_bin_obj (anal); - RListIter *exc_iter = NULL, *methods_iter=NULL; - RBinJavaField *method; - ut64 func_addr = -1; - RBinJavaExceptionEntry *exc_entry; - - const char *p = input? r_cmd_java_consumetok (input, ' ', -1): NULL; - func_addr = p && *p && r_cmd_java_is_valid_input_num_value (core, p)? r_cmd_java_get_input_num_value (core, p): -1; - - if (!bin) { - return false; - } - - r_list_foreach (bin->methods_list, methods_iter, method) { - ut64 start = r_bin_java_get_method_start (bin, method), - end = r_bin_java_get_method_end (bin, method); - ut8 do_this_one = start <= func_addr && func_addr <= end; - RList *exc_table = NULL; - do_this_one = func_addr == (ut64)-1? 1: do_this_one; - if (!do_this_one) { - continue; - } - exc_table = r_bin_java_get_method_exception_table_with_addr (bin, start); - - if (r_list_length (exc_table) == 0){ - r_cons_printf (" Exception table for %s @ 0x%"PFMT64x":\n", method->name, start); - r_cons_printf (" [ NONE ]\n"); - } else { - r_cons_printf (" Exception table for %s (%d entries) @ 0x%"PFMT64x":\n", method->name, - r_list_length (exc_table) , start); - } - r_list_foreach (exc_table, exc_iter, exc_entry) { - char *class_info = r_bin_java_resolve_without_space (bin, exc_entry->catch_type); - r_cons_printf (" Catch Type: %d, %s @ 0x%"PFMT64x"\n", exc_entry->catch_type, - class_info, exc_entry->file_offset+6); - r_cons_printf (" Start PC: (0x%"PFMT64x") 0x%"PFMT64x" @ 0x%"PFMT64x"\n", - exc_entry->start_pc, exc_entry->start_pc+start, exc_entry->file_offset); - r_cons_printf (" End PC: (0x%"PFMT64x") 0x%"PFMT64x" 0x%"PFMT64x"\n", - exc_entry->end_pc, exc_entry->end_pc+start, exc_entry->file_offset + 2); - r_cons_printf (" Handler PC: (0x%"PFMT64x") 0x%"PFMT64x" 0x%"PFMT64x"\n", - exc_entry->handler_pc, exc_entry->handler_pc+start, exc_entry->file_offset+4); - free (class_info); - } - } - return true; -} - -// PLUGIN Definition Info -RCorePlugin r_core_plugin_java = { - .name = "java", - .desc = "Suite of java commands, java help for more info", - .license = "Apache", - .call = r_cmd_java_call, -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_CORE, - .data = &r_core_plugin_java, - .version = R2_VERSION -}; -#endif diff --git a/libr/core/p/core_test.c b/libr/core/p/core_test.c deleted file mode 100644 index 16e91af0f6..0000000000 --- a/libr/core/p/core_test.c +++ /dev/null @@ -1,39 +0,0 @@ -/* radare - LGPL - Copyright 2014 - pancake */ -#if 0 -gcc -o core_test.so -fPIC `pkg-config --cflags --libs r_core` core_test.c -shared -mkdir -p ~/.config/radare2/plugins -mv core_test.so ~/.config/radare2/plugins -#endif - -#include -#include -#include -#include -#include -#include -#include - -#undef R_API -#define R_API static -#undef R_IPI -#define R_IPI static - -static int r_cmd_test_call(void) { - eprintf ("Dummy!\n"); - return false; -} - -RCorePlugin r_core_plugin_test = { - .name = "test", - .desc = "lalallala", - .license = "MIT", - .call = r_cmd_test_call, -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_CORE, - .data = &r_core_plugin_test, - .version = R2_VERSION -}; -#endif diff --git a/libr/core/project.c b/libr/core/project.c deleted file mode 100644 index 1e928dea5e..0000000000 --- a/libr/core/project.c +++ /dev/null @@ -1,939 +0,0 @@ -/* radare - LGPL - Copyright 2010-2020 - pancake, maijin */ - -#include -#include -#include -#include -#define USE_R2 1 -#include - -static bool is_valid_project_name(const char *name) { - int i; - if (r_str_endswith (name, ".zip")) { - return false; - } - for (i = 0; name[i]; i++) { - switch (name[i]) { - case '\\': // for w32 - case '.': - case '_': - case ':': - case '-': - continue; - } - if (name[i] >= 'a' && name[i] <= 'z') { - continue; - } - if (name[i] >= 'A' && name[i] <= 'Z') { - continue; - } - if (IS_DIGIT (name[i])) { - continue; - } - return false; - } - return true; -} - -static char *get_project_script_path(RCore *core, const char *file) { - const char *magic = "# r2 rdb project file"; - char *data, *prjfile; - if (r_file_is_abspath (file)) { - prjfile = strdup (file); - } else { - if (!is_valid_project_name (file)) { - return NULL; - } - prjfile = r_file_abspath (r_config_get (core->config, "dir.projects")); - prjfile = r_str_append (prjfile, R_SYS_DIR); - prjfile = r_str_append (prjfile, file); - if (!r_file_exists (prjfile) || r_file_is_directory (prjfile)) { - prjfile = r_str_append (prjfile, R_SYS_DIR "rc"); - } - } - data = r_file_slurp (prjfile, NULL); - if (data) { - if (strncmp (data, magic, strlen (magic))) { - R_FREE (prjfile); - } - } - free (data); - return prjfile; -} - -static int make_projects_directory(RCore *core) { - char *prjdir = r_file_abspath (r_config_get (core->config, "dir.projects")); - int ret = r_sys_mkdirp (prjdir); - if (!ret) { - eprintf ("Cannot mkdir dir.projects\n"); - } - free (prjdir); - return ret; -} - -R_API bool r_core_is_project(RCore *core, const char *name) { - bool ret = false; - if (name && *name && *name != '.') { - char *path = get_project_script_path (core, name); - if (!path) { - return false; - } - if (r_str_endswith (path, R_SYS_DIR "rc") && r_file_exists (path)) { - ret = true; - } else { - path = r_str_append (path, ".d"); - if (r_file_is_directory (path)) { - ret = true; - } - } - free (path); - } - return ret; -} - -R_API int r_core_project_cat(RCore *core, const char *name) { - char *path = get_project_script_path (core, name); - if (path) { - char *data = r_file_slurp (path, NULL); - if (data) { - r_cons_println (data); - free (data); - } - } - free (path); - return 0; -} - -R_API int r_core_project_list(RCore *core, int mode) { - PJ *pj = NULL; - RListIter *iter; - RList *list; - - char *foo, *path = r_file_abspath (r_config_get (core->config, "dir.projects")); - if (!path) { - return 0; - } - list = r_sys_dir (path); - switch (mode) { - case 'j': - pj = pj_new (); - if (!pj) { - break; - } - pj_a (pj); - r_list_foreach (list, iter, foo) { - // todo. escape string - if (r_core_is_project (core, foo)) { - pj_s (pj, foo); - } - } - pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); - pj_free (pj); - break; - default: - r_list_foreach (list, iter, foo) { - if (r_core_is_project (core, foo)) { - r_cons_println (foo); - } - } - break; - } - r_list_free (list); - free (path); - return 0; -} - -static inline void remove_project_file(char * path) { - if (r_file_exists (path)) { - r_file_rm (path); - eprintf ("rm %s\n", path); - } -} - -static inline void remove_notes_file(char *prjDir) { - char *notes_txt = r_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "notes.txt"); - if (r_file_exists (notes_txt)) { - r_file_rm (notes_txt); - eprintf ("rm %s\n", notes_txt); - } - free(notes_txt); -} - -static inline void remove_rop_directory(char *prjDir) { - char *rop_d = r_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "rop.d"); - - if (r_file_is_directory (rop_d)) { - char *f; - RListIter *iter; - RList *files = r_sys_dir (rop_d); - r_list_foreach (files, iter, f) { - char *filepath = r_str_append (strdup (rop_d), R_SYS_DIR); - filepath = r_str_append (filepath, f); - if (!r_file_is_directory (filepath)) { - eprintf ("rm %s\n", filepath); - r_file_rm (filepath); - } - - free (filepath); - } - - r_file_rm (rop_d); - eprintf ("rm %s\n", rop_d); - r_list_free (files); - } - - free (rop_d); -} -R_API int r_core_project_delete(RCore *core, const char *prjfile) { - if (r_sandbox_enable (0)) { - eprintf ("Cannot delete project in sandbox mode\n"); - return 0; - } - char *path = get_project_script_path (core, prjfile); - if (!path) { - eprintf ("Invalid project name '%s'\n", prjfile); - return false; - } - if (r_core_is_project (core, prjfile)) { - char *prjDir = r_file_dirname (path); - if (!prjDir) { - eprintf ("Cannot resolve directory\n"); - free (path); - return false; - } - remove_project_file (path); - remove_notes_file (prjDir); - remove_rop_directory (prjDir); - // remove directory only if it's empty - r_file_rm (prjDir); - free (prjDir); - } - free (path); - return 0; -} - -static bool load_project_rop(RCore *core, const char *prjfile) { - char *path, *db = NULL, *path_ns; - bool found = 0; - SdbListIter *it; - SdbNs *ns; - - if (!prjfile || !*prjfile) { - return false; - } - - Sdb *rop_db = sdb_ns (core->sdb, "rop", false); - Sdb *nop_db = sdb_ns (rop_db, "nop", false); - Sdb *mov_db = sdb_ns (rop_db, "mov", false); - Sdb *const_db = sdb_ns (rop_db, "const", false); - Sdb *arithm_db = sdb_ns (rop_db, "arithm", false); - Sdb *arithmct_db = sdb_ns (rop_db, "arithm_ct", false); - - char *rcPath = get_project_script_path (core, prjfile); - char *prjDir = r_file_dirname (rcPath); - - if (r_str_endswith (prjfile, R_SYS_DIR "rc")) { - // XXX - eprintf ("ENDS WITH\n"); - path = strdup (prjfile); - path[strlen (path) - 3] = 0; - } else if (r_file_fexists ("%s" R_SYS_DIR "rc", prjDir, prjfile)) { - path = r_str_newf ("%s" R_SYS_DIR, prjDir, prjfile); - } else { - if (*prjfile == R_SYS_DIR[0]) { - db = r_str_newf ("%s.d", prjfile); - if (!db) { - free (prjDir); - free (rcPath); - return false; - } - path = strdup (db); - } else { - db = r_str_newf ("%s" R_SYS_DIR "%s.d", prjDir, prjfile); - if (!db) { - free (prjDir); - free (rcPath); - return false; - } - path = r_file_abspath (db); - } - } - if (!path) { - free (db); - free (prjDir); - free (rcPath); - return false; - } - if (rop_db) { - ls_foreach (core->sdb->ns, it, ns){ - if (ns->sdb == rop_db) { - ls_delete (core->sdb->ns, it); - found = true; - break; - } - } - } - if (!found) { - sdb_free (rop_db); - } - rop_db = sdb_new (path, "rop", 0); - if (!rop_db) { - free (db); - free (path); - free (prjDir); - free (rcPath); - return false; - } - sdb_ns_set (core->sdb, "rop", rop_db); - - path_ns = r_str_newf ("%s" R_SYS_DIR "rop", prjDir); - if (!r_file_exists (path_ns)) { - path_ns = r_str_append (path_ns, ".sdb"); - } - nop_db = sdb_new (path_ns, "nop", 0); - sdb_ns_set (rop_db, "nop", nop_db); - - mov_db = sdb_new (path_ns, "mov", 0); - sdb_ns_set (rop_db, "mov", mov_db); - - const_db = sdb_new (path_ns, "const", 0); - sdb_ns_set (rop_db, "const", const_db); - - arithm_db = sdb_new (path_ns, "arithm", 0); - sdb_ns_set (rop_db, "arithm", arithm_db); - - arithmct_db = sdb_new (path_ns, "arithm_ct", 0); - sdb_ns_set (rop_db, "arithm_ct", arithmct_db); - - free (path); - free (path_ns); - free (db); - free (prjDir); - free (rcPath); - return true; -} - -R_API void r_core_project_execute_cmds(RCore *core, const char *prjfile) { - char *str = r_core_project_notes_file (core, prjfile); - char *data = r_file_slurp (str, NULL); - if (!data) { - free (str); - return; - } - Output out; - out.fout = NULL; - out.cout = r_strbuf_new (NULL); - r_strbuf_init (out.cout); - struct Proc proc; - spp_proc_set (&proc, "spp", 1); - spp_eval (data, &out); - free (data); - data = strdup (r_strbuf_get (out.cout)); - char *bol = strtok (data, "\n"); - while (bol) { - if (bol[0] == ':') { - r_core_cmd0 (core, bol + 1); - } - bol = strtok (NULL, "\n"); - } - free (data); - free (str); -} - -/*** vvv thready ***/ - -typedef struct { - RCore *core; - char *prjName; - char *rcPath; -} ProjectState; - -static RThreadFunctionRet project_load_background(RThread *th) { - ProjectState *ps = th->user; - r_core_project_load (ps->core, ps->prjName, ps->rcPath); - free (ps->prjName); - free (ps->rcPath); - free (ps); - return R_TH_STOP; -} - -R_API RThread *r_core_project_load_bg(RCore *core, const char *prjName, const char *rcPath) { - ProjectState *ps = R_NEW (ProjectState); - ps->core = core; - ps->prjName = strdup (prjName); - ps->rcPath = strdup (rcPath); - RThread *th = r_th_new (project_load_background, ps, false); - if (th) { - r_th_start (th, true); - char thname[16] = {0}; - size_t thlen = R_MIN (strlen(prjName), sizeof(thname) - 1); - strncpy (thname, prjName, thlen); - thname[15] = 0; - r_th_setname (th, thname); - } - return th; -} - -/*** ^^^ thready ***/ - -static ut64 getProjectLaddr(RCore *core, const char *prjfile) { - ut64 laddr = 0; - char *buf = r_file_slurp (prjfile, NULL); - char *pos; - if (buf) { - if ((pos = strstr(buf, "\"e bin.laddr = "))) { - laddr = r_num_math (NULL, pos + 15); - } - free (buf); - } - return laddr; -} - -R_API bool r_core_project_open(RCore *core, const char *prjfile, bool thready) { - bool askuser = true; - int ret, close_current_session = 1; - char *oldbin; - const char *newbin; - ut64 mapaddr = 0; - if (!prjfile || !*prjfile) { - return false; - } - if (thready) { - eprintf ("Loading projects in a thread has been deprecated. Use tasks\n"); - return false; - } - char *prj = get_project_script_path (core, prjfile); - if (!prj) { - eprintf ("Invalid project name '%s'\n", prjfile); - return false; - } - char *filepath = r_core_project_info (core, prj); - // eprintf ("OPENING (%s) from %s\n", prj, r_config_get (core->config, "file.path")); - /* if it is not an URI */ - if (!filepath) { - eprintf ("Cannot retrieve information for project '%s'\n", prj); - free (prj); - return false; - } - - if (!filepath[0]) { - goto cookiefactory; - } - if (!strstr (filepath, "://")) { - /* check if path exists */ - if (!r_file_exists (filepath)) { - eprintf ("Cannot find file '%s'\n", filepath); - free (prj); - free (filepath); - return false; - } - } - cookiefactory: - ; - const char *file_path = r_config_get (core->config, "file.path"); - if (!file_path || !*file_path) { - file_path = r_config_get (core->config, "file.lastpath"); - } - oldbin = strdup (file_path); - if (!strcmp (prjfile, r_config_get (core->config, "prj.name"))) { - // eprintf ("Reloading project\n"); - askuser = false; -#if 0 - free (prj); - free (filepath); - return false; -#endif - } - if (askuser) { - if (r_cons_is_interactive ()) { - close_current_session = r_cons_yesno ('y', "Close current session? (Y/n)"); - } - } - if (close_current_session) { - // delete - r_core_file_close_fd (core, -1); - r_io_close_all (core->io); - r_anal_purge (core->anal); - r_flag_unset_all (core->flags); - r_bin_file_delete_all (core->bin); - // open new file - // TODO: handle read/read-write mode - if (filepath[0]) { - /* Old-style project without embedded on commands to open all files. */ - if (!r_core_file_open (core, filepath, 0, UT64_MAX)) { - eprintf ("Cannot open file '%s'\n", filepath); - ret = false; - goto beach; - } - } - } - mapaddr = getProjectLaddr (core, prj); - if (mapaddr) { - r_config_set_i (core->config, "bin.laddr", mapaddr); - } - if (filepath[0] && close_current_session && r_config_get_i (core->config, "file.info")) { - mapaddr = r_config_get_i (core->config, "file.offset"); - (void)r_core_bin_load (core, filepath, mapaddr? mapaddr: UT64_MAX); - } - /* load sdb stuff in here */ - ret = r_core_project_load (core, prjfile, prj); - if (filepath[0]) { - newbin = r_config_get (core->config, "file.path"); - if (!newbin || !*newbin) { - newbin = r_config_get (core->config, "file.lastpath"); - } - if (strcmp (oldbin, newbin)) { - eprintf ("WARNING: file.path changed: %s => %s\n", oldbin, newbin); - } - } -beach: - free (oldbin); - free (filepath); - free (prj); - return ret; -} - -R_API char *r_core_project_info(RCore *core, const char *prjfile) { - FILE *fd; - char buf[256], *file = NULL; - char *prj = get_project_script_path (core, prjfile); - if (!prj) { - eprintf ("Invalid project name '%s'\n", prjfile); - return NULL; - } - fd = r_sandbox_fopen (prj, "r"); - if (fd) { - for (;;) { - if (!fgets (buf, sizeof (buf), fd)) { - break; - } - if (feof (fd)) { - break; - } - if (!strncmp (buf, "\"e file.path = ", 15)) { - buf[strlen (buf) - 2] = 0; - file = r_str_new (buf + 15); - break; - } - if (!strncmp (buf, "\"e file.lastpath = ", 19)) { - buf[strlen (buf) - 2] = 0; - file = r_str_new (buf + 19); - break; - } - // TODO: deprecate before 1.0 - if (!strncmp (buf, "e file.path = ", 14)) { - buf[strlen (buf) - 1] = 0; - file = r_str_new (buf + 14); - break; - } - } - fclose (fd); - } else { - eprintf ("Cannot open project info (%s)\n", prj); - } -#if 0 - if (file) { - r_cons_printf ("Project: %s\n", prj); - r_cons_printf ("FilePath: %s\n", file); - } -#endif - free (prj); - return file; -} - -static int fdc; //this is a ugly, remove it, when we have $fd - -static bool store_files_and_maps (RCore *core, RIODesc *desc, ut32 id) { - RList *maps = NULL; - RListIter *iter; - RIOMap *map; - if (desc) { - // reload bin info - r_cons_printf ("\"obf %s\"\n", desc->uri); - r_cons_printf ("\"ofs \\\"%s\\\" %s\"\n", desc->uri, r_str_rwx_i (desc->perm)); - if ((maps = r_io_map_get_for_fd (core->io, id))) { - r_list_foreach (maps, iter, map) { - r_cons_printf ("om %d 0x%"PFMT64x" 0x%"PFMT64x" 0x%"PFMT64x" %s%s%s\n", fdc, - map->itv.addr, map->itv.size, map->delta, r_str_rwx_i (map->perm), - map->name ? " " : "", map->name ? map->name : ""); - } - r_list_free (maps); - } - fdc++; - } - return true; -} - -static bool simple_project_save_script(RCore *core, const char *file, int opts) { - char *filename, *hl, *ohl = NULL; - int fd, fdold; - - if (!file || * file == '\0') { - return false; - } - - filename = r_str_word_get_first (file); - fd = r_sandbox_open (file, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - free (filename); - return false; - } - - hl = r_cons_singleton ()->highlight; - if (hl) { - ohl = strdup (hl); - r_cons_highlight (NULL); - } - - fdold = r_cons_singleton ()->fdout; - r_cons_singleton ()->fdout = fd; - r_cons_singleton ()->context->is_interactive = false; // NOES must use api - - r_str_write (fd, "# r2 rdb project file\n"); - - if (opts & R_CORE_PRJ_EVAL) { - r_str_write (fd, "# eval\n"); - r_config_list (core->config, NULL, true); - r_cons_flush (); - } - - if (opts & R_CORE_PRJ_FCNS) { - r_str_write (fd, "# functions\n"); - r_str_write (fd, "fs functions\n"); - r_core_cmd (core, "afl*", 0); - r_cons_flush (); - } - - if (opts & R_CORE_PRJ_FLAGS) { - r_str_write (fd, "# flags\n"); - r_core_cmd (core, "f.**", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_META) { - r_str_write (fd, "# meta\n"); - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1); - r_cons_flush (); - r_core_cmd (core, "fV*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_XREFS) { - r_str_write (fd, "# xrefs\n"); - r_core_cmd (core, "ax*", 0); - r_cons_flush (); - } - - - r_cons_singleton ()->fdout = fdold; - r_cons_singleton ()->context->is_interactive = true; - - if (ohl) { - r_cons_highlight (ohl); - free (ohl); - } - - close (fd); - free (filename); - - return true; -} - -static bool project_save_script(RCore *core, const char *file, int opts) { - char *filename, *hl, *ohl = NULL; - int fd, fdold; - - if (!file || *file == '\0') { - return false; - } - - filename = r_str_word_get_first (file); - fd = r_sandbox_open (file, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0644); - if (fd == -1) { - free (filename); - return false; - } - - hl = r_cons_singleton ()->highlight; - if (hl) { - ohl = strdup (hl); - r_cons_highlight (NULL); - } - fdold = r_cons_singleton ()->fdout; - r_cons_singleton ()->fdout = fd; - r_cons_singleton ()->context->is_interactive = false; - r_str_write (fd, "# r2 rdb project file\n"); - if (!core->bin->is_debugger && !r_config_get_i (core->config, "asm.emu")) { - if (core->bin->file) { - char *fpath = r_file_abspath (core->bin->file); - if (fpath) { - char *reopen = r_str_newf ("\"o %s\"\n", fpath); - if (reopen) { - r_str_write (fd, reopen); - free (reopen); - free (fpath); - } - } - } - - } - // Set file.path and file.lastpath to empty string to signal - // new behaviour to project load routine (see io maps below). - r_config_set (core->config, "file.path", ""); - r_config_set (core->config, "file.lastpath", ""); - if (opts & R_CORE_PRJ_EVAL) { - r_str_write (fd, "# eval\n"); - r_config_list (core->config, NULL, true); - r_cons_flush (); - } - - if (opts & R_CORE_PRJ_FCNS) { - r_str_write (fd, "# functions\n"); - r_str_write (fd, "fs functions\n"); - r_core_cmd (core, "afl*", 0); - r_cons_flush (); - } - - if (opts & R_CORE_PRJ_FLAGS) { - r_str_write (fd, "# flags\n"); - r_flag_space_push (core->flags, NULL); - r_flag_list (core->flags, true, NULL); - r_flag_space_pop (core->flags); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_IO_MAPS && core->io && core->io->files) { - fdc = 3; - r_id_storage_foreach (core->io->files, (RIDStorageForeachCb)store_files_and_maps, core); - r_cons_flush (); - } - { - r_core_cmd (core, "fz*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_META) { - r_str_write (fd, "# meta\n"); - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1); - r_cons_flush (); - r_core_cmd (core, "fV*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_XREFS) { - r_core_cmd (core, "ax*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_FLAGS) { - r_core_cmd (core, "f.**", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_DBG_BREAK) { - r_core_cmd (core, "db*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_ANAL_HINTS) { - r_core_cmd (core, "ah*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_ANAL_TYPES) { - r_str_write (fd, "# types\n"); - r_core_cmd (core, "t*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_ANAL_MACROS) { - r_str_write (fd, "# macros\n"); - r_core_cmd (core, "(*", 0); - r_str_write (fd, "# aliases\n"); - r_core_cmd (core, "$*", 0); - r_cons_flush (); - } - if (opts & R_CORE_PRJ_ANAL_SEEK) { - r_cons_printf ("# seek\n" - "s 0x%08"PFMT64x "\n", core->offset); - r_cons_flush (); - } - - r_cons_singleton ()->fdout = fdold; - r_cons_singleton ()->context->is_interactive = true; - - if (ohl) { - r_cons_highlight (ohl); - free (ohl); - } - - close (fd); - free (filename); - - return true; -} - -// TODO: rename to r_core_project_save_script -R_API bool r_core_project_save_script(RCore *core, const char *file, int opts) { - return project_save_script (core, file, opts); -} - -#define TRANSITION 1 - -R_API bool r_core_project_save(RCore *core, const char *prjName) { - bool scr_null = false; - bool ret = true; - char *scriptPath, *prjDir; - SdbListIter *it; - SdbNs *ns; - char *oldPrjName = NULL; - - if (!prjName || !*prjName) { - return false; - } - scriptPath = get_project_script_path (core, prjName); - if (!scriptPath) { - eprintf ("Invalid project name '%s'\n", prjName); - return false; - } - if (r_str_endswith (scriptPath, R_SYS_DIR "rc")) { - /* new project format */ - prjDir = r_file_dirname (scriptPath); - } else { - prjDir = r_str_newf ("%s.d", scriptPath); - } - if (r_file_exists (scriptPath)) { - if (r_file_is_directory (scriptPath)) { - eprintf ("WTF. rc is a directory?\n"); - } - if (r_str_endswith (prjDir, ".d")) { - eprintf ("Upgrading project...\n"); -#if TRANSITION - r_file_rm (scriptPath); - r_sys_mkdirp (prjDir); - eprintf ("Please remove: rm -rf %s %s.d\n", prjName, prjName); - char *rc = r_str_newf ("%s" R_SYS_DIR "rc", prjDir); - if (!rc) { - free (prjDir); - free (scriptPath); - return false; - } - free (scriptPath); - scriptPath = rc; - free (prjDir); - prjDir = r_file_dirname (scriptPath); -#endif - } - } - if (!prjDir) { - prjDir = strdup (prjName); - } - if (!r_file_exists (prjDir)) { - r_sys_mkdirp (prjDir); - } - if (r_config_get_i (core->config, "scr.null")) { - r_config_set_i (core->config, "scr.null", false); - scr_null = true; - } - make_projects_directory (core); - - Sdb *rop_db = sdb_ns (core->sdb, "rop", false); - if (rop_db) { - /* set filepath for all the rop sub-dbs */ - ls_foreach (rop_db->ns, it, ns) { - char *rop_path = r_str_newf ("%s" R_SYS_DIR "rop.d" R_SYS_DIR "%s", prjDir, ns->name); - sdb_file (ns->sdb, rop_path); - sdb_sync (ns->sdb); - free (rop_path); - } - } - - const char *oldPrjNameC = r_config_get (core->config, "prj.name"); - if (oldPrjNameC) { - oldPrjName = strdup (oldPrjNameC); - } - r_config_set (core->config, "prj.name", prjName); - if (r_config_get_i (core->config, "prj.simple")) { - if (!simple_project_save_script (core, scriptPath, R_CORE_PRJ_ALL)) { - eprintf ("Cannot open '%s' for writing\n", prjName); - ret = false; - } - } else { - if (!project_save_script (core, scriptPath, R_CORE_PRJ_ALL)) { - eprintf ("Cannot open '%s' for writing\n", prjName); - ret = false; - } - } - - if (r_config_get_i (core->config, "prj.files")) { - eprintf ("TODO: prj.files: support copying more than one file into the project directory\n"); - char *binFile = r_core_project_info (core, prjName); - const char *binFileName = r_file_basename (binFile); - char *prjBinDir = r_str_newf ("%s" R_SYS_DIR "bin", prjDir); - char *prjBinFile = r_str_newf ("%s" R_SYS_DIR "%s", prjBinDir, binFileName); - r_sys_mkdirp (prjBinDir); - if (!r_file_copy (binFile, prjBinFile)) { - eprintf ("Warning: Cannot copy '%s' into '%s'\n", binFile, prjBinFile); - } - free (prjBinFile); - free (prjBinDir); - free (binFile); - } - if (r_config_get_i (core->config, "prj.git")) { - char *cwd = r_sys_getdir (); - char *gitDir = r_str_newf ("%s" R_SYS_DIR ".git", prjDir); - if (r_sys_chdir (prjDir)) { - if (!r_file_is_directory (gitDir)) { - r_sys_cmd ("git init"); - } - r_sys_cmd ("git add * ; git commit -a"); - } else { - eprintf ("Cannot chdir %s\n", prjDir); - } - r_sys_chdir (cwd); - free (gitDir); - free (cwd); - } - if (r_config_get_i (core->config, "prj.zip")) { - char *cwd = r_sys_getdir (); - const char *prjName = r_file_basename (prjDir); - if (r_sys_chdir (prjDir)) { - if (!strchr (prjName, '\'')) { - r_sys_chdir (".."); - r_sys_cmdf ("rm -f '%s.zip'; zip -r '%s'.zip '%s'", - prjName, prjName, prjName); - } else { - eprintf ("Command injection attempt?\n"); - } - } else { - eprintf ("Cannot chdir %s\n", prjDir); - } - r_sys_chdir (cwd); - free (cwd); - } - // LEAK : not always in heap free (prjName); - free (prjDir); - if (scr_null) { - r_config_set_i (core->config, "scr.null", true); - } - if (!ret && oldPrjName) { - // reset prj.name on fail - r_config_set (core->config, "prj.name", oldPrjName); - } - free (scriptPath); - free (oldPrjName); - return ret; -} - -R_API char *r_core_project_notes_file(RCore *core, const char *prjName) { - char *notes_txt; - const char *prjdir = r_config_get (core->config, "dir.projects"); - char *prjpath = r_file_abspath (prjdir); - notes_txt = r_str_newf ("%s"R_SYS_DIR "%s"R_SYS_DIR "notes.txt", prjpath, prjName); - free (prjpath); - return notes_txt; -} - -R_API bool r_core_project_load(RCore *core, const char *prjName, const char *rcpath) { - const bool cfg_fortunes = r_config_get_i (core->config, "cfg.fortunes"); - const bool scr_interactive = r_cons_is_interactive (); - const bool scr_prompt = r_config_get_i (core->config, "scr.prompt"); - (void) load_project_rop (core, prjName); - bool ret = r_core_cmd_file (core, rcpath); - r_config_set_i (core->config, "cfg.fortunes", cfg_fortunes); - r_config_set_i (core->config, "scr.interactive", scr_interactive); - r_config_set_i (core->config, "scr.prompt", scr_prompt); - r_config_bump (core->config, "asm.arch"); - return ret; -} diff --git a/libr/core/vasm.c b/libr/core/vasm.c deleted file mode 100644 index fc44d295e2..0000000000 --- a/libr/core/vasm.c +++ /dev/null @@ -1,97 +0,0 @@ -/* radare - LGPL - Copyright 2009-2018 - pancake */ - -#include - -#define R_VISUAL_ASM_BUFSIZE 1024 - -typedef struct { - RCore *core; - char blockbuf[R_VISUAL_ASM_BUFSIZE]; - char codebuf[R_VISUAL_ASM_BUFSIZE]; - int oplen; - ut8 buf[128]; - RAsmCode *acode; - int blocklen; - ut64 off; -} RCoreVisualAsm; - -static int readline_callback(void *_a, const char *str) { - RCoreVisualAsm *a = _a; - RCore *core = a->core; - r_cons_clear00 (); - r_cons_printf ("Write some %s-%d assembly...\n\n", - r_config_get (a->core->config, "asm.arch"), - r_config_get_i (a->core->config, "asm.bits")); - if (*str == '?') { - r_cons_printf ("0> ?\n\n" - "Visual assembler help:\n\n" - " assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n" - " press enter to quit (prompt if there are bytes to be written)\n" - " this assembler supports various directives like .hex ...\n"); - } else { - r_asm_code_free (a->acode); - r_asm_set_pc (a->core->rasm, a->off); - a->acode = r_asm_massemble (a->core->rasm, str); - if (a->acode) { - char* hex = r_asm_code_get_hex (a->acode); - r_cons_printf ("[VA:%d]> %s\n", a->acode? a->acode->len: 0, str); - if (a->acode && a->acode->len) { - r_cons_printf ("* %s\n\n", hex); - } else { - r_cons_print ("\n\n"); - } - int xlen = R_MIN (strlen (hex), R_VISUAL_ASM_BUFSIZE - 2); - strcpy (a->codebuf, a->blockbuf); - memcpy (a->codebuf, hex, xlen); - if (xlen >= strlen (a->blockbuf)) { - a->codebuf[xlen] = '\0'; - } - free (hex); - } else { - r_cons_printf ("[VA:0]> %s\n* ?\n\n", str); - } - { - int rows = 0; - int cols = r_cons_get_size (&rows); - core->print->cur_enabled = 1; - core->print->ocur = 0; - core->print->cur = (a->acode && a->acode->len) ? a->acode->len - 1: 0; - char *cmd = r_str_newf ("pd %d @x:%s @0x%"PFMT64x, rows - 11, a->codebuf, a->off); - char *res = r_core_cmd_str (a->core, cmd); - char *msg = r_str_ansi_crop (res, 0,0, cols - 2, rows - 5); - r_cons_printf ("%s\n", msg); - free (msg); - free (res); - free (cmd); - } - } - r_cons_flush (); - return 1; -} - -R_API void r_core_visual_asm(RCore *core, ut64 off) { - RCoreVisualAsm cva = { - .core = core, - .off = off - }; - r_io_read_at (core->io, off, cva.buf, sizeof (cva.buf)); - cva.blocklen = r_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf); - - r_line_readline_cb (readline_callback, &cva); - - if (cva.acode && cva.acode->len > 0) { - if (r_cons_yesno ('y', "Save changes? (Y/n)")) { - if (!r_io_write_at (core->io, off, cva.acode->bytes, cva.acode->len)) { - eprintf ("ERROR: Cannot write in here, check map permissions or reopen the file with oo+\n"); - r_cons_any_key (NULL); - } - // r_core_cmdf (core, "wx %s @ 0x%"PFMT64x, cva.acode->buf_hex, off); - } -#if 0 - } else if (!cva.acode || cva.acode->len == 0) { - eprintf ("ERROR: Cannot assemble those instructions\n"); -// r_cons_any_key (NULL); -#endif - } - r_asm_code_free (cva.acode); -} diff --git a/libr/core/visual_tabs.inc b/libr/core/visual_tabs.inc deleted file mode 100644 index a6dbf5ea4e..0000000000 --- a/libr/core/visual_tabs.inc +++ /dev/null @@ -1,222 +0,0 @@ - -static void r_core_visual_tab_free (RCoreVisualTab *tab) { - free (tab); -} - -static int __core_visual_tab_count (RCore *core) { - return core->visual.tabs? r_list_length (core->visual.tabs): 0; -} - -static char *__core_visual_tab_string(RCore *core, const char *kolor) { - int hex_cols = r_config_get_i (core->config, "hex.cols"); - int scr_color = r_config_get_i (core->config, "scr.color"); - if (hex_cols < 4) { - return strdup (""); - } - int i = 0; - char *str = NULL; - int tabs = r_list_length (core->visual.tabs); - if (scr_color > 0) { - // TODO: use theme - if (tabs > 0) { - str = r_str_appendf (str, "%s-+__", kolor); - } - for (i = 0; i < tabs;i++) { - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, i); - const char *name = (tab && *tab->name)? tab->name: NULL; - if (i == core->visual.tab) { - str = r_str_appendf (str, Color_WHITE"_/ %s \\_%s", name? name: "t=", kolor); - } else { - str = r_str_appendf (str, "_%s(%d)_", name?name: "", i+ 1); - } - } - } else { - if (tabs > 0) { - str = r_str_append (str, "___"); - } - for (i = 0;i < tabs; i++) { - const char *name = NULL; - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, i); - if (tab && *tab->name) { - name = tab->name; - } - if (i==core->visual.tab) { - str = r_str_appendf (str, "_/ %d:%s \\_", i + 1, name? name: "'="); - } else { - str = r_str_appendf (str, "_(t%d%s%s)__", i + 1, name?":":"", name?name: ""); - } - } - } - if (str) { - int n = 79 - r_str_ansi_len (str); - if (n > 0) { - str = r_str_append (str, r_str_pad ('_', n)); - } - str = r_str_append (str, "\n"Color_RESET); - } - return str; -} - -static void visual_tabset(RCore *core, RCoreVisualTab *tab) { - r_return_if_fail (core && tab); - - r_core_seek (core, tab->offset, true); - core->printidx = tab->printidx; - core->print->cur_enabled = tab->cur_enabled; - core->print->cur = tab->cur; - core->print->ocur = tab->ocur; - disMode = tab->disMode; - hexMode = tab->hexMode; - printMode = tab->printMode; - current3format = tab->current3format; - current4format = tab->current4format; - current5format = tab->current5format; - r_core_visual_applyDisMode (core, disMode); - r_core_visual_applyHexMode (core, hexMode); - r_config_set_i (core->config, "asm.offset", tab->asm_offset); - r_config_set_i (core->config, "asm.instr", tab->asm_instr); - r_config_set_i (core->config, "asm.bytes", tab->asm_bytes); - r_config_set_i (core->config, "asm.indent", tab->asm_indent); - r_config_set_i (core->config, "asm.cmt.col", tab->asm_cmt_col); - r_config_set_i (core->config, "hex.cols", tab->cols); - r_config_set_i (core->config, "scr.dumpcols", tab->dumpCols); - printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; - printfmtSingle[2] = print3Formats[R_ABS(current3format) % PRINT_3_FORMATS]; - printfmtSingle[3] = print4Formats[R_ABS(current4format) % PRINT_4_FORMATS]; - printfmtSingle[4] = print5Formats[R_ABS(current5format) % PRINT_5_FORMATS]; -} - -static void visual_tabget(RCore *core, RCoreVisualTab *tab) { - r_return_if_fail (core && tab); - - tab->offset = core->offset; - tab->printidx = core->printidx; - tab->asm_offset = r_config_get_i (core->config, "asm.offset"); - tab->asm_instr = r_config_get_i (core->config, "asm.instr"); - tab->asm_indent = r_config_get_i (core->config, "asm.indent"); - tab->asm_bytes = r_config_get_i (core->config, "asm.bytes"); - tab->asm_cmt_col = r_config_get_i (core->config, "asm.cmt.col"); - tab->cur_enabled = core->print->cur_enabled; - tab->cur = core->print->cur; - tab->ocur = core->print->ocur; - tab->cols = r_config_get_i (core->config, "hex.cols"); - tab->dumpCols = r_config_get_i (core->config, "scr.dumpcols"); - tab->disMode = disMode; - tab->hexMode = hexMode; - tab->printMode = printMode; - tab->current3format = current3format; - tab->current4format = current4format; - tab->current5format = current5format; - // tab->cols = core->print->cols; -} - -static RCoreVisualTab *r_core_visual_tab_new(RCore *core) { - RCoreVisualTab *tab = R_NEW0 (RCoreVisualTab); - if (tab) { - visual_tabget (core, tab); - } - return tab; -} - -static void r_core_visual_tab_update(RCore *core) { - if (!core->visual.tabs) { - return; - } - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - visual_tabget (core, tab); - } -} - -static RCoreVisualTab *visual_newtab (RCore *core) { - if (!core->visual.tabs) { - core->visual.tabs = r_list_newf ((RListFree)r_core_visual_tab_free); - if (!core->visual.tabs) { - return NULL; - } - core->visual.tab = -1; - visual_newtab (core); - } - core->visual.tab++; - RCoreVisualTab *tab = r_core_visual_tab_new (core); - if (tab) { - r_list_append (core->visual.tabs, tab); - visual_tabset (core, tab); - } - return tab; -} - -static void visual_nthtab (RCore *core, int n) { - if (!core->visual.tabs || n < 0 || n >= r_list_length (core->visual.tabs)) { - return; - } - core->visual.tab = n; - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - visual_tabset (core, tab); - } -} - -static void visual_tabname (RCore *core) { - if (!core->visual.tabs) { - return; - } - char name[32]={0}; - prompt_read ("tab name: ", name, sizeof (name)); - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - strcpy (tab->name, name); - } -} - -static void visual_nexttab (RCore *core) { - if (!core->visual.tabs) { - return; - } - if (core->visual.tab >= r_list_length (core->visual.tabs) - 1) { - core->visual.tab = -1; - } - core->visual.tab++; - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - visual_tabset (core, tab); - } -} - -static void visual_prevtab (RCore *core) { - if (!core->visual.tabs) { - return; - } - if (core->visual.tab < 1) { - core->visual.tab = r_list_length (core->visual.tabs) - 1; - } else { - core->visual.tab--; - } - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - visual_tabset (core, tab); - } -} - -static void visual_closetab (RCore *core) { - if (!core->visual.tabs) { - return; - } - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - r_list_delete_data (core->visual.tabs, tab); - const int tabsCount = r_list_length (core->visual.tabs); - if (tabsCount > 0) { - if (core->visual.tab > 0) { - core->visual.tab--; - } - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); - if (tab) { - visual_tabset(core, tab); - } - } else { - r_list_free (core->visual.tabs); - core->visual.tabs = NULL; - } - } -} diff --git a/libr/core/vmarks.c b/libr/core/vmarks.c deleted file mode 100644 index f72752be8b..0000000000 --- a/libr/core/vmarks.c +++ /dev/null @@ -1,58 +0,0 @@ -/* radare - LGPL - Copyright 2009-2020 - pancake */ - -#include - - -R_API void r_core_visual_mark_reset(RCore *core) { - size_t i; - for (i = 0; i < UT8_MAX; i++) { - core->marks[i] = UT64_MAX; - } - core->marks_init = true; -} - -R_API bool r_core_visual_mark_dump(RCore *core) { - size_t i; - if (!core->marks_init) { - return false; - } - bool res = false; - for (i = 0; i < UT8_MAX; i++) { - if (core->marks[i] != UT64_MAX) { - if (i > ASCII_MAX) { - r_cons_printf ("fV %d 0x%"PFMT64x"\n", i - ASCII_MAX - 1, core->marks[i]); - } else { - r_cons_printf ("fV %c 0x%"PFMT64x"\n", i, core->marks[i]); - } - res = true; - } - } - return res; -} - -R_API void r_core_visual_mark_set(RCore *core, ut8 ch, ut64 addr) { - if (!core->marks_init) { - r_core_visual_mark_reset (core); - } - core->marks[ch] = addr; -} - -R_API void r_core_visual_mark_del(RCore *core, ut8 ch) { - if (!core->marks_init) { - return; - } - core->marks[ch] = UT64_MAX; -} - -R_API void r_core_visual_mark(RCore *core, ut8 ch) { - if (IS_DIGIT (ch)) { - ch += ASCII_MAX + 1; - } - r_core_visual_mark_set (core, ch, core->offset); -} - -R_API void r_core_visual_mark_seek(RCore *core, ut8 ch) { - if (core->marks_init && core->marks[ch] != UT64_MAX) { - r_core_seek (core, core->marks[ch], true); - } -} diff --git a/libr/core/vmenus_graph.c b/libr/core/vmenus_graph.c deleted file mode 100644 index 9bd525b592..0000000000 --- a/libr/core/vmenus_graph.c +++ /dev/null @@ -1,425 +0,0 @@ -/* radare - LGPL - Copyright 2019 - pancake */ - -#include -#define SORT_ADDRESS 0 -#define SORT_NAME 1 - -// find a better name and move to r_util or r_cons? -R_API char *r_str_widget_list(void *user, RList *list, int rows, int cur, PrintItemCallback cb) { - void *item; - RStrBuf *sb = r_strbuf_new (""); - RListIter *iter; - int count = 0; - int skip = 0; - if (cur > (rows / 2)) { - skip = cur - (rows / 2); - } - r_list_foreach (list, iter, item) { - if (rows >= 0) { - if (skip > 0) { - skip--; - } else { - char *line = cb (user, item, cur == count); - if (line) { - r_strbuf_appendf (sb, "%s", line); - free (line); - } - rows--; - if (rows == 0) { - break; - } - } - } - count++; - } - return r_strbuf_drain (sb); -} - -typedef struct { - ut64 addr; - RAnalFunction *fcn; - int cur; // current row selected - int cur_sort; // holds current sort - RCore *core; - RList *mainCol; - RList *xrefsCol; - RList *refsCol; -} RCoreVisualViewGraph; - -typedef struct { - ut64 addr; - const char *name; - RAnalFunction *fcn; -} RCoreVisualViewGraphItem; - -static char *print_item(void *_core, void *_item, bool selected) { - RCoreVisualViewGraphItem *item = _item; - if (item->name && *item->name) { - if (false && item->fcn && item->addr > item->fcn->addr) { - st64 delta = item->addr - item->fcn->addr; - return r_str_newf ("%c %s+0x%"PFMT64x"\n", selected?'>':' ', item->name, delta); - } else { - return r_str_newf ("%c %s\n", selected?'>':' ', item->name); - } - } - return r_str_newf ("%c 0x%08"PFMT64x"\n", selected?'>':' ', item->addr); -} - -static RList *__xrefs(RCore *core, ut64 addr) { - RList *r = r_list_newf (free); - RListIter *iter; - RAnalRef *ref; - RList *xrefs = r_anal_xrefs_get (core->anal, addr); - r_list_foreach (xrefs, iter, ref) { - if (ref->type != 'C') { - continue; - } - RCoreVisualViewGraphItem *item = R_NEW0 (RCoreVisualViewGraphItem); - RFlagItem *f = r_flag_get_at (core->flags, ref->addr, 0); - item->addr = ref->addr; - item->name = f? f->name: NULL; - RAnalFunction *rf = r_anal_get_fcn_in (core->anal, ref->addr, 0); - item->fcn = rf; - if (rf) { - item->name = rf->name; - } - r_list_append (r, item); - } - return r; -} - -static RList *__refs(RCore *core, ut64 addr) { - RList *r = r_list_newf (free); - RListIter *iter; - RAnalRef *ref; - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); - if (!fcn) { - return r; - } - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { - if (ref->type != 'C') { - continue; - } - RCoreVisualViewGraphItem *item = R_NEW0 (RCoreVisualViewGraphItem); - RFlagItem *f = r_flag_get_at (core->flags, ref->addr, 0); - item->addr = ref->addr; - item->name = f? f->name: NULL; - RAnalFunction *rf = r_anal_get_fcn_in (core->anal, ref->addr, 0); - if (rf) { - item->name = rf->name; - item->fcn = rf; - } - r_list_append (r, item); - } - return r; -} - -static RList *__fcns(RCore *core) { - RList *r = r_list_newf (free); - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (core->anal->fcns, iter, fcn) { - RCoreVisualViewGraphItem *item = R_NEW0 (RCoreVisualViewGraphItem); - item->addr = fcn->addr; - item->name = fcn->name; - item->fcn = fcn; - r_list_append (r, item); - } - return r; // core->anal->fcns; -} - -static void __seek_cursor(RCoreVisualViewGraph *status) { - ut64 target = 0; - if (status->fcn) { - target = status->fcn->addr; - } else { - target = status->addr; - } - - RListIter *iter; - RCoreVisualViewGraphItem *item; - int cur = 0; - r_list_foreach (status->mainCol, iter, item) { - if (target == item->addr) { - status->cur = cur; - } - cur++; - } - return; -} - -static int cmpaddr (const void *_a, const void *_b) { - const RCoreVisualViewGraphItem *a = _a, *b = _b; - return a->addr - b->addr; -} - -static int cmpname (const void *_a, const void *_b) { - const RCoreVisualViewGraphItem *a = _a, *b = _b; - if (!a || !b || !a->name || !b->name) { - return 0; - } - return (int)strcmp (a->name, b->name); -} - -static void __sort (RCoreVisualViewGraph *status, RList *list) { - r_return_if_fail (status && list); - RListComparator cmp = (status->cur_sort == SORT_ADDRESS)? cmpaddr: cmpname; - list->sorted = false; - r_list_sort (list, cmp); -} - -static void __toggleSort (RCoreVisualViewGraph *status) { - r_return_if_fail (status); - status->cur_sort = (status->cur_sort == SORT_ADDRESS)? SORT_NAME: SORT_ADDRESS; - __sort (status, status->mainCol); - __sort (status, status->refsCol); - __sort (status, status->xrefsCol); - __seek_cursor (status); -} - -static void __reset_status(RCoreVisualViewGraph *status) { - status->addr = status->core->offset; - status->fcn = r_anal_get_function_at (status->core->anal, status->addr); - - status->mainCol = __fcns (status->core); - __sort (status, status->mainCol); - __seek_cursor (status); - - return; -} - -static void __sync_status_with_cursor(RCoreVisualViewGraph *status) { - RCoreVisualViewGraphItem *item = r_list_get_n (status->mainCol, status->cur); - if (!item) { - r_list_free (status->mainCol); - __reset_status (status); - return; - } - - status->addr = item->addr; - status->fcn = item->fcn; - - // Update xrefs and refs columns based on selected element in fcns column - if (status->fcn && status->fcn->addr) { - status->xrefsCol = __xrefs (status->core, status->fcn->addr); - status->refsCol = __refs (status->core, status->fcn->addr); - } else { - status->xrefsCol = __xrefs (status->core, status->addr); - status->refsCol = r_list_newf (free); - } - __sort (status, status->xrefsCol); - __sort (status, status->refsCol); -} - -R_API int __core_visual_view_graph_update(RCore *core, RCoreVisualViewGraph *status) { - int h, w = r_cons_get_size (&h); - const int colw = w / 4; - const int colh = h / 2; - const int colx = w / 3; - r_cons_clear00 (); - - char *xrefsColstr = r_str_widget_list (core, status->xrefsCol, colh, 0, print_item); - char *mainColstr = r_str_widget_list (core, status->mainCol, colh, status->cur, print_item); - char *refsColstr = r_str_widget_list (core, status->refsCol, colh, 0, print_item); - - /* if (r_list_empty (status->xrefsCol) && r_list_empty (status->refsCol)) { */ - /* // We've found ourselves in a bad state, reset the view */ - /* r_list_free (status->mainCol); */ - /* __reset_status (status); */ - /* } */ - - char *title = r_str_newf ("[r2-visual-browser] addr=0x%08"PFMT64x" faddr=0x%08"PFMT64x"", status->addr, status->fcn ? status->fcn->addr : 0); - if (title) { - r_cons_strcat_at (title, 0, 0, w - 1, 2); - free (title); - } - r_cons_strcat_at (xrefsColstr, 0, 2, colw, colh); - r_cons_strcat_at (mainColstr, colx, 2, colw*2, colh); - r_cons_strcat_at (refsColstr, colx * 2, 2, colw, colh); - - char *output = r_core_cmd_strf (core, "pd %d @e:asm.flags=0@ 0x%08"PFMT64x"; pds 256 @ 0x%08"PFMT64x"\n", - 32, status->addr, status->addr); - int disy = colh + 2; - r_cons_strcat_at (output, 10, disy, w, h - disy); - free (output); - r_cons_flush(); - - free (xrefsColstr); - free (mainColstr); - free (refsColstr); - return 0; -} - -R_API int r_core_visual_view_graph(RCore *core) { - RCoreVisualViewGraph status = {0}; - status.core = core; - status.cur_sort = SORT_NAME; - __reset_status (&status); - __sync_status_with_cursor (&status); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, status.addr, 0); - if (fcn) { - status.addr = fcn->addr; - status.fcn = fcn; - } - while (true) { - __core_visual_view_graph_update (core, &status); - int ch = r_cons_readchar (); - if (ch == -1 || ch == 4) { - return true; - } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char - switch (ch) { - case 'h': - if (!r_list_empty (status.xrefsCol)) { - status.cur = 0; - r_list_free (status.mainCol); - r_list_free (status.refsCol); - status.mainCol = status.xrefsCol; - - __sync_status_with_cursor (&status); - } - break; - case 'l': - if (!r_list_empty (status.refsCol)) { - status.cur = 0; - r_list_free (status.mainCol); - r_list_free (status.xrefsCol); - status.mainCol = status.refsCol; - - __sync_status_with_cursor (&status); - } - break; - case 'J': - { - status.cur += 10; - int length = r_list_length (status.mainCol); - if (status.cur >= length) { - status.cur = length-1; - } - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __sync_status_with_cursor (&status); - } - break; - case 'K': - if (status.cur > 10) { - status.cur -= 10; - } else { - status.cur = 0; - } - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __sync_status_with_cursor (&status); - break; - case '.': - // reset view and seek status->cur to current function - r_list_free (status.mainCol); - __reset_status (&status); - break; - case 9: - case ' ': - case '\r': - case '\n': - { - RCoreVisualViewGraphItem *item = r_list_get_n (status.mainCol, status.cur); - r_core_seek (core, item->addr, true); - } - return true; - break; - case '_': - r_core_visual_hudstuff (core); - r_list_free (status.mainCol); - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __reset_status (&status); - __sync_status_with_cursor (&status); - break; - case 'r': - r_list_free (status.mainCol); - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __reset_status (&status); - __sync_status_with_cursor (&status); - break; - case 'j': - { - status.cur++; - int length = r_list_length (status.mainCol); - if (status.cur >= length) { - status.cur = length-1; - } - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __sync_status_with_cursor (&status); - } - break; - case 'k': - if (status.cur > 0) { - status.cur--; - } else { - status.cur = 0; - } - r_list_free (status.xrefsCol); - r_list_free (status.refsCol); - __sync_status_with_cursor (&status); - break; - case '?': - r_cons_clear00 (); - r_cons_printf ( - "vbg: Visual Browser (Code) Graph:\n\n" - " jkJK - scroll up/down\n" - " hl - move to the left/right panel\n" - " q - quit this visual mode\n" - " _ - enter the hud\n" - " . - go back to the initial function list view\n" - " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); - break; - case '/': - { - char cmd[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); - cmd[0]='\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { - cmd[0] = '\0'; - } - r_config_set (core->config, "scr.highlight", cmd); - //r_core_cmd_task_sync (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); - r_cons_clear (); - } - break; - case 'q': - return false; - case ':': // TODO: move this into a separate helper function - { - char cmd[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); - cmd[0]='\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { - cmd[0] = '\0'; - } - r_core_cmd0 (core, cmd); - //r_core_cmd_task_sync (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); - if (cmd[0]) { - r_cons_any_key (NULL); - } - r_cons_clear (); - } - break; - case '!': { - __toggleSort (&status); - } break; - } - } - return false; -} diff --git a/libr/crypto/p/crypto_punycode.c b/libr/crypto/p/crypto_punycode.c deleted file mode 100644 index aed63ef041..0000000000 --- a/libr/crypto/p/crypto_punycode.c +++ /dev/null @@ -1,54 +0,0 @@ -/* radare - LGPL - Copyright 2009-2016 - pancake */ - -#include -#include -#include - -static int flag = 0; - -static bool punycode_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { - flag = direction; - return true; -} - -static int punycode_get_key_size(RCrypto *cry) { - return 0; -} - -static bool punycode_use(const char *algo) { - return !strcmp (algo, "punycode"); -} - -static bool update(RCrypto *cry, const ut8 *buf, int len) { - char *obuf; - int olen; - if (flag) { - obuf = r_punycode_decode ((const char *)buf, len, &olen); - } else { - obuf = r_punycode_encode (buf, len, &olen); - } - r_crypto_append (cry, (ut8*)obuf, olen); - free (obuf); - return true; -} - -static bool final(RCrypto *cry, const ut8* buf, int len) { - return update (cry, buf, len); -} - -RCryptoPlugin r_crypto_plugin_punycode = { - .name = "punycode", - .set_key = punycode_set_key, - .get_key_size = punycode_get_key_size, - .use = punycode_use, - .update = update, - .final = final -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_punycode, - .version = R2_VERSION -}; -#endif diff --git a/libr/debug/p/native/bsd/bsd_debug.h b/libr/debug/p/native/bsd/bsd_debug.h deleted file mode 100644 index 2503e6d60d..0000000000 --- a/libr/debug/p/native/bsd/bsd_debug.h +++ /dev/null @@ -1,16 +0,0 @@ -/* radare - LGPL - Copyright 2009-2019 - pancake */ - -#ifndef _BSD_DEBUG_H -#define _BSD_DEBUG_H -#include -#include -#define R_DEBUG_REG_T struct reg - -int bsd_handle_signals(RDebug *dbg); -int bsd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size); -RDebugInfo *bsd_info(RDebug *dbg, const char *arg); -RList *bsd_pid_list(RDebug *dbg, RList *list); -RList *bsd_native_sysctl_map(RDebug *dbg); -RList *bsd_desc_list(int pid); -RList *bsd_thread_list(RDebug *dbg, int pid, RList *list); -#endif diff --git a/libr/debug/p/native/maps/windows_maps.h b/libr/debug/p/native/maps/windows_maps.h deleted file mode 100644 index e1232e88e2..0000000000 --- a/libr/debug/p/native/maps/windows_maps.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WINDOWS_MAPS_H -#define WINDOWS_MAPS_H -#include - -R_API RList *r_w32_dbg_modules(RDebug *dbg); -R_API RList *r_w32_dbg_maps(RDebug *dbg); - -#endif \ No newline at end of file diff --git a/libr/debug/p/native/windows/windows_message.h b/libr/debug/p/native/windows/windows_message.h deleted file mode 100644 index 83683210e2..0000000000 --- a/libr/debug/p/native/windows/windows_message.h +++ /dev/null @@ -1,13 +0,0 @@ -#include - -typedef struct _window { - DWORD pid; - DWORD tid; - HANDLE h; - char *name; - ut64 proc; -} window; - -R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input); -R_API void r_w32_identify_window(void); -R_API void r_w32_print_windows(RDebug *dbg); diff --git a/libr/do-ar-sh b/libr/do-ar-sh deleted file mode 100644 index da3fdbfb7f..0000000000 --- a/libr/do-ar-sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -LIBS="libr/cons/libr_cons.a libr/util/libr_util.a libr/bin/libr_bin.a libr/anal/libr_anal.a libr/bp/libr_bp.a libr/hash/libr_hash.a libr/debug/libr_debug.a shlr/sdb/src/libsdb.a libr/core/libr_core.a libr/main/libr_main.a libr/fs/libr_fs.a libr/syscall/libr_syscall.a shlr/java/libr_java.a shlr/zip/librz.a libr/socket/libr_socket.a libr/anal/libr_anal.a libr/flag/libr_flag.a libr/search/libr_search.a libr/reg/libr_reg.a libr/config/libr_config.a libr/io/libr_io.a libr/parse/libr_parse.a libr/bp/libr_bp.a libr/asm/libr_asm.a libr/bp/libr_bp.a libr/egg/libr_egg.a libr/anal/libr_anal.a libr/magic/libr_magic.a libr/lang/libr_lang.a libr/fs/libr_fs.a shlr/grub/libgrubfs.a shlr/capstone/libcapstone.a shlr/gdb/lib/libgdbr.a shlr/tree-sitter/libtree-sitter.a shlr/radare2-shell-parser/libshell-parser.a" -cd .. - -LIB=libr.a -TMP=.ar.tmp - -IOSVER=1 -if [ -n "${IOSVER}" ]; then - RANLIB="xcrun --sdk iphoneos ranlib" - AR="xcrun --sdk iphoneos ar" -else - RANLIB=ranlib - AR=ar -fi - -rm -rf ${TMP} -mkdir -p ${TMP} -for a in ${LIBS} ; do - ${RANLIB} $a - file "$a" | grep -q universal - if [ $? = 0 ]; then - ARCHS=`lipo -info $a | cut -d : -f 3-` - else - ARCHS="" - fi - if [ -n "${ARCHS}" ]; then - for b in ${ARCHS} ; do - mkdir -p "$TMP/$a/$b" - ORIG="$PWD/$a.$b" - lipo -thin $b -output $a.$b $a - echo "cd $TMP/$a/$b : ${AR} -x $ORIG" - ( cd $TMP/$a/$b ; ${AR} -x $ORIG ) - rm -f $a.$b - done - else - mkdir -p "${TMP}/${a}" - ORIG="$PWD/$a" - ( cd $TMP/$a ; ${AR} -x $ORIG ) - echo $a - fi -done - -cd ${TMP} -OBJS=`find * -iname *.o` -if [ -z "${OBJS}" ]; then - echo - echo "Cannot find any object" - echo - exit 1 -else - rm -f "${LIB}" - ${AR} -qv "${LIB}" ${OBJS} - ${RANLIB} "${LIB}" -fi diff --git a/libr/egg/egg.c b/libr/egg/egg.c deleted file mode 100644 index bd23ba200b..0000000000 --- a/libr/egg/egg.c +++ /dev/null @@ -1,565 +0,0 @@ -/* radare - LGPL - Copyright 2011-2018 - pancake */ - -#include -#include - -R_LIB_VERSION (r_egg); - -// TODO: must be plugins -extern REggEmit emit_x86; -extern REggEmit emit_x64; -extern REggEmit emit_arm; -extern REggEmit emit_trace; - -static REggPlugin *egg_static_plugins[] = - { R_EGG_STATIC_PLUGINS }; - -struct egg_patch_t { - RBuffer *b; - int off; -}; - -void egg_patch_free (void *p) { - struct egg_patch_t *ep = (struct egg_patch_t *)p; - r_buf_free (ep->b); - free (ep); -} - -R_API REgg *r_egg_new(void) { - int i; - REgg *egg = R_NEW0 (REgg); - if (!egg) { - return NULL; - } - egg->src = r_buf_new (); - if (!egg->src) { - goto beach; - } - egg->buf = r_buf_new (); - if (!egg->buf) { - goto beach; - } - egg->bin = r_buf_new (); - if (!egg->bin) { - goto beach; - } - egg->remit = &emit_x86; - egg->syscall = r_syscall_new (); - if (!egg->syscall) { - goto beach; - } - egg->rasm = r_asm_new (); - if (!egg->rasm) { - goto beach; - } - egg->bits = 0; - egg->endian = 0; - egg->db = sdb_new (NULL, NULL, 0); - if (!egg->db) { - goto beach; - } - egg->patches = r_list_newf (egg_patch_free); - if (!egg->patches) { - goto beach; - } - egg->plugins = r_list_new (); - for (i=0; egg_static_plugins[i]; i++) { - r_egg_add (egg, egg_static_plugins[i]); - } - return egg; - -beach: - r_egg_free (egg); - return NULL; -} - -R_API int r_egg_add(REgg *a, REggPlugin *foo) { - RListIter *iter; - RAsmPlugin *h; - // TODO: cache foo->name length and use memcmp instead of strcmp - if (!foo->name) { - return false; - } - r_list_foreach (a->plugins, iter, h) { - if (!strcmp (h->name, foo->name)) { - return false; - } - } - r_list_append (a->plugins, foo); - return true; -} - -R_API char *r_egg_to_string(REgg *egg) { - return r_buf_to_string (egg->buf); -} - -R_API void r_egg_free(REgg *egg) { - if (egg) { - r_buf_free (egg->src); - r_buf_free (egg->buf); - r_buf_free (egg->bin); - r_list_free (egg->list); - r_asm_free (egg->rasm); - r_syscall_free (egg->syscall); - sdb_free (egg->db); - r_list_free (egg->plugins); - r_list_free (egg->patches); - r_egg_lang_free (egg); - free (egg); - } -} - -R_API void r_egg_reset(REgg *egg) { - r_egg_lang_include_init (egg); - // TODO: use r_list_purge instead of free/new here - r_buf_free (egg->src); - r_buf_free (egg->buf); - r_buf_free (egg->bin); - egg->src = r_buf_new (); - egg->buf = r_buf_new (); - egg->bin = r_buf_new (); - r_list_purge (egg->patches); -} - -R_API int r_egg_setup(REgg *egg, const char *arch, int bits, int endian, const char *os) { - const char *asmcpu = NULL; // TODO - egg->remit = NULL; - - egg->os = os? r_str_hash (os): R_EGG_OS_DEFAULT; - //eprintf ("%s -> %x (linux=%x) (darwin=%x)\n", os, egg->os, R_EGG_OS_LINUX, R_EGG_OS_DARWIN); - // TODO: setup egg->arch for all archs - if (!strcmp (arch, "x86")) { - egg->arch = R_SYS_ARCH_X86; - switch (bits) { - case 32: - r_syscall_setup (egg->syscall, arch, bits, asmcpu, os); - egg->remit = &emit_x86; - egg->bits = bits; - break; - case 64: - r_syscall_setup (egg->syscall, arch, bits, asmcpu, os); - egg->remit = &emit_x64; - egg->bits = bits; - break; - } - } else if (!strcmp (arch, "arm")) { - egg->arch = R_SYS_ARCH_ARM; - switch (bits) { - case 16: - case 32: - r_syscall_setup (egg->syscall, arch, bits, asmcpu, os); - egg->remit = &emit_arm; - egg->bits = bits; - egg->endian = endian; - break; - } - } else if (!strcmp (arch, "trace")) { - //r_syscall_setup (egg->syscall, arch, os, bits); - egg->remit = &emit_trace; - egg->bits = bits; - egg->endian = endian; - } - return 0; -} - -R_API int r_egg_include(REgg *egg, const char *file, int format) { - size_t sz; - const ut8 *foo = (const ut8 *)r_file_slurp (file, &sz); - if (!foo) { - return 0; - } - // XXX: format breaks compiler layers - switch (format) { - case 'r': // raw - r_egg_raw (egg, foo, (int)sz); - break; - case 'a': // assembly - r_buf_append_bytes (egg->buf, foo, (ut64)sz); - break; - default: - r_buf_append_bytes (egg->src, foo, (ut64)sz); - } - free ((void *)foo); - return 1; -} - -R_API void r_egg_load(REgg *egg, const char *code, int format) { - switch (format) { - case 'a': // assembly - r_buf_append_bytes (egg->buf, (const ut8 *)code, strlen (code)); - break; - default: - r_buf_append_bytes (egg->src, (const ut8 *)code, strlen (code)); - break; - } -} - -R_API void r_egg_syscall(REgg *egg, const char *arg, ...) { - RSyscallItem *item = r_syscall_get (egg->syscall, - r_syscall_get_num (egg->syscall, arg), -1); - if (!strcmp (arg, "close")) { - //egg->remit->syscall_args (); - } - if (!item) { - return; - } - egg->remit->syscall (egg, item->num); -} - -R_API void r_egg_alloc(REgg *egg, int n) { - // add esp, n -} - -R_API void r_egg_label(REgg *egg, const char *name) { - r_egg_printf (egg, "%s:\n", name); -} - -R_API void r_egg_math(REgg *egg) { //, char eq, const char *vs, char type, const char *sr - // TODO - //e->mathop (egg, op, type, eq, p); -} - -R_API int r_egg_raw(REgg *egg, const ut8 *b, int len) { - int outlen = len * 2; // two hexadecimal digits per byte - char *out = malloc (outlen + 1); - if (!out) { - return false; - } - (void)r_hex_bin2str (b, len, out); - r_buf_append_bytes (egg->buf, (const ut8 *)".hex ", 5); - r_buf_append_bytes (egg->buf, (const ut8 *)out, outlen); - r_buf_append_bytes (egg->buf, (const ut8 *)"\n", 1); - free (out); - return true; -} - -static int r_egg_raw_prepend(REgg *egg, const ut8 *b, int len) { - int outlen = len * 2; // two hexadecimal digits per byte - char *out = malloc (outlen + 1); - if (!out) { - return false; - } - r_hex_bin2str (b, len, out); - r_buf_prepend_bytes (egg->buf, (const ut8 *)"\n", 1); - r_buf_prepend_bytes (egg->buf, (const ut8 *)out, outlen); - r_buf_prepend_bytes (egg->buf, (const ut8 *)".hex ", 5); - free (out); - return true; -} - -static int r_egg_prepend_bytes(REgg *egg, const ut8 *b, int len) { - if (!r_egg_raw_prepend (egg, b, len)) { - return false; - } - if (!r_buf_prepend_bytes (egg->bin, b, len)) { - return false; - } - return true; -} - -static int r_egg_append_bytes(REgg *egg, const ut8 *b, int len) { - if (!r_egg_raw (egg, b, len)) { - return false; - } - - if (!r_buf_append_bytes (egg->bin, b, len)) { - return false; - } - - return true; -} - -// r_egg_block (egg, FRAME | IF | ELSE | ENDIF | FOR | WHILE, sz) -R_API void r_egg_if(REgg *egg, const char *reg, char cmp, int v) { - // egg->depth++; -} - -R_API void r_egg_printf(REgg *egg, const char *fmt, ...) { - va_list ap; - int len; - char buf[1024]; - va_start (ap, fmt); - len = vsnprintf (buf, sizeof (buf), fmt, ap); - r_buf_append_bytes (egg->buf, (const ut8 *)buf, len); - va_end (ap); -} - -R_API bool r_egg_assemble_asm(REgg *egg, char **asm_list) { - RAsmCode *asmcode = NULL; - char *code = NULL; - char *asm_name = NULL; - - if (asm_list) { - char **asm_; - - for (asm_ = asm_list; *asm_; asm_ += 2) { - if (!strcmp (egg->remit->arch, asm_[0])) { - asm_name = asm_[1]; - break; - } - } - } - if (!asm_name) { - if (egg->remit == &emit_x86 || egg->remit == &emit_x64) { - asm_name = "x86.nz"; - } else if (egg->remit == &emit_arm) { - asm_name = "arm"; - } - } - if (asm_name) { - r_asm_use (egg->rasm, asm_name); - r_asm_set_bits (egg->rasm, egg->bits); - r_asm_set_big_endian (egg->rasm, egg->endian); - r_asm_set_syntax (egg->rasm, R_ASM_SYNTAX_INTEL); - code = r_buf_to_string (egg->buf); - asmcode = r_asm_massemble (egg->rasm, code); - if (asmcode) { - if (asmcode->len > 0) { - r_buf_append_bytes (egg->bin, asmcode->bytes, asmcode->len); - } - // LEAK r_asm_code_free (asmcode); - } else { - eprintf ("fail assembling\n"); - } - } - free (code); - bool ret = (asmcode != NULL); - r_asm_code_free (asmcode); - return ret; -} - -R_API bool r_egg_assemble(REgg *egg) { - return r_egg_assemble_asm (egg, NULL); -} - -R_API int r_egg_compile(REgg *egg) { - r_buf_seek (egg->src, 0, R_BUF_SET); - char b; - int r = r_buf_read (egg->src, (ut8 *)&b, sizeof (b)); - if (r != sizeof (b) || !egg->remit) { - return true; - } - // only emit begin if code is found - r_egg_lang_init (egg); - for (; b; ) { - r_egg_lang_parsechar (egg, b); - if (egg->lang.elem_n >= sizeof (egg->lang.elem)) { - eprintf ("ERROR: elem too large.\n"); - break; - } - int r = r_buf_read (egg->src, (ut8 *)&b, sizeof (b)); - if (r != sizeof (b)) { - break; - } - // XXX: some parse fail errors are false positives :( - } - if (egg->context>0) { - eprintf ("ERROR: expected '}' at the end of the file. %d left\n", egg->context); - return false; - } - // TODO: handle errors here - return true; -} - -R_API RBuffer *r_egg_get_bin(REgg *egg) { - // TODO increment reference - return egg->bin; -} - -//R_API int r_egg_dump (REgg *egg, const char *file) { } - -R_API char *r_egg_get_source(REgg *egg) { - return r_buf_to_string (egg->src); -} - -R_API char *r_egg_get_assembly(REgg *egg) { - return r_buf_to_string (egg->buf); -} - -R_API void r_egg_append(REgg *egg, const char *src) { - r_buf_append_bytes (egg->src, (const ut8*)src, strlen (src)); -} - -/* JIT : TODO: accept arguments here */ -R_API int r_egg_run(REgg *egg) { - ut64 tmpsz; - const ut8 *tmp = r_buf_data (egg->bin, &tmpsz); - bool res = r_sys_run (tmp, tmpsz); - return res; -} - -R_API int r_egg_run_rop(REgg *egg) { - ut64 sz; - const ut8 *tmp = r_buf_data (egg->bin, &sz); - return r_sys_run_rop (tmp, sz); -} - -#define R_EGG_FILL_TYPE_TRAP -#define R_EGG_FILL_TYPE_NOP -#define R_EGG_FILL_TYPE_CHAR -#define R_EGG_FILL_TYPE_SEQ -#define R_EGG_FILL_TYPE_SEQ - -static inline char *eon(char *n) { - while (*n && (*n >= '0' && *n <= '9')) { - n++; - } - return n; -} - -/* padding looks like: - ([snatSNAT][0-9]+)* -*/ -R_API int r_egg_padding(REgg *egg, const char *pad) { - int number; - ut8 *buf, padding_byte; - char *p, *o = strdup (pad); - - for (p = o; *p;) { // parse pad string - const char f = *p++; - number = strtol (p, NULL, 10); - - if (number < 1) { - eprintf ("Invalid padding length at %d\n", number); - free (o); - return false; - } - p = eon(p); - - switch (f) { - case 's': case 'S': padding_byte = 0; break; - case 'n': case 'N': padding_byte = 0x90; break; - case 'a': - case 'A': padding_byte = 'A'; break; - case 't': - case 'T': padding_byte = 0xcc; break; - default: - eprintf ("Invalid padding format (%c)\n", *p); - eprintf ("Valid ones are:\n"); - eprintf (" s S : NULL byte"); - eprintf (" n N : nop"); - eprintf (" a A : 0x41"); - eprintf (" t T : trap (0xcc)"); - free (o); - return false; - } - - buf = malloc (number); - if (!buf) { - free (o); - return false; - } - - memset (buf, padding_byte, number); - if (f >= 'a' && f <= 'z') { - r_egg_prepend_bytes(egg, buf, number); - } else { - r_egg_append_bytes(egg, buf, number); - } - free (buf); - } - free (o); - return true; -} - -R_API void r_egg_fill(REgg *egg, int pos, int type, int argc, int length) { - // TODO -} - -R_API void r_egg_option_set(REgg *egg, const char *key, const char *val) { - sdb_set (egg->db, key, val, 0); -} - -R_API char *r_egg_option_get(REgg *egg, const char *key) { - return sdb_get (egg->db, key, NULL); -} - -R_API int r_egg_shellcode(REgg *egg, const char *name) { - REggPlugin *p; - RListIter *iter; - RBuffer *b; - r_list_foreach (egg->plugins, iter, p) { - if (p->type == R_EGG_PLUGIN_SHELLCODE && !strcmp (name, p->name)) { - b = p->build (egg); - if (!b) { - eprintf ("%s Shellcode has failed\n", p->name); - return false; - } - ut64 tmpsz; - const ut8 *tmp = r_buf_data (b, &tmpsz); - r_egg_raw (egg, tmp, tmpsz); - return true; - } - } - return false; -} - -R_API int r_egg_encode(REgg *egg, const char *name) { - REggPlugin *p; - RListIter *iter; - RBuffer *b; - r_list_foreach (egg->plugins, iter, p) { - if (p->type == R_EGG_PLUGIN_ENCODER && !strcmp (name, p->name)) { - b = p->build (egg); - if (!b) { - return false; - } - r_buf_free (egg->bin); - egg->bin = b; - return true; - } - } - return false; -} - -R_API int r_egg_patch(REgg *egg, int off, const ut8 *buf, int len) { - struct egg_patch_t *ep = R_NEW (struct egg_patch_t); - if (!ep) { - return false; - } - ep->b = r_buf_new_with_bytes (buf, len); - if (!ep->b) { - egg_patch_free (ep); - return false; - } - ep->off = off; - r_list_append (egg->patches, ep); - return true; -} - -R_API void r_egg_finalize(REgg *egg) { - struct egg_patch_t *ep; - RListIter *iter; - if (!egg->bin) { - r_buf_free (egg->bin); - egg->bin = r_buf_new (); - } - r_list_foreach (egg->patches, iter, ep) { - if (ep->off < 0) { - ut64 sz; - const ut8 *buf = r_buf_data (ep->b, &sz); - r_egg_append_bytes (egg, buf, sz); - } else if (ep->off < r_buf_size (egg->bin)) { - ut64 sz; - const ut8 *buf = r_buf_data (ep->b, &sz); - int r = r_buf_write_at (egg->bin, ep->off, buf, sz); - if (r < sz) { - eprintf ("Error during patch\n"); - return; - } - } else { - eprintf ("Cannot patch outside\n"); - return; - } - } -} - -R_API void r_egg_pattern(REgg *egg, int size) { - char *ret = r_debruijn_pattern ((int)size, 0, NULL); - if (ret) { - r_egg_prepend_bytes (egg, (const ut8*)ret, strlen(ret)); - free (ret); - } else { - eprintf ("Invalid debruijn pattern length.\n"); - } -} diff --git a/libr/egg/emit_x64.c b/libr/egg/emit_x64.c deleted file mode 100644 index 3b872fc5b2..0000000000 --- a/libr/egg/emit_x64.c +++ /dev/null @@ -1,4 +0,0 @@ -/* pancake // nopcode.org 2010-2011 -- emit module for radare2/r_egg */ - -#define ARCH_X86_64 1 -#include "emit_x86.c" diff --git a/libr/flag/tags.c b/libr/flag/tags.c deleted file mode 100644 index b354afbfca..0000000000 --- a/libr/flag/tags.c +++ /dev/null @@ -1,71 +0,0 @@ -/* radare - LGPL - Copyright 2018 - pancake */ - -#include - -R_API RList *r_flag_tags_set(RFlag *f, const char *name, const char *words) { - r_return_val_if_fail (f && name && words, NULL); - const char *k = sdb_fmt ("tag.%s", name); - sdb_set (f->tags, k, words, -1); - return NULL; -} - -R_API RList *r_flag_tags_list(RFlag *f, const char *name) { - r_return_val_if_fail (f, NULL); - if (name) { - const char *k = sdb_fmt ("tag.%s", name); - char *words = sdb_get (f->tags, k, NULL); - return r_str_split_list (words, " ", 0); - } - RList *res = r_list_newf (free); - SdbList *o = sdb_foreach_list (f->tags, false); - SdbListIter *iter; - SdbKv *kv; - ls_foreach (o, iter, kv) { - const char *tag = sdbkv_key (kv); - if (strlen (tag) < 5) { - continue; - } - r_list_append (res, (void *)strdup (tag + 4)); - } - ls_free (o); - return res; -} - -R_API void r_flag_tags_reset(RFlag *f, const char *name) { - // TODO: use name - r_return_if_fail (f); - sdb_reset (f->tags); -} - -struct iter_glob_flag_t { - RList *res; - RList *words; -}; - -static bool iter_glob_flag(RFlagItem *fi, void *user) { - struct iter_glob_flag_t *u = (struct iter_glob_flag_t *)user; - RListIter *iter; - const char *word; - - r_list_foreach (u->words, iter, word) { - if (r_str_glob (fi->name, word)) { - r_list_append (u->res, fi); - } - } - return true; -} - -R_API RList *r_flag_tags_get(RFlag *f, const char *name) { - r_return_val_if_fail (f && name, NULL); - const char *k = sdb_fmt ("tag.%s", name); - RList *res = r_list_newf (NULL); - char *words = sdb_get (f->tags, k, NULL); - if (words) { - RList *list = r_str_split_list (words, " ", 0); - struct iter_glob_flag_t u = { .res = res, .words = list }; - r_flag_foreach (f, iter_glob_flag, &u); - r_list_free (list); - free (words); - } - return res; -} diff --git a/libr/fs/p/r2.mk b/libr/fs/p/r2.mk deleted file mode 100644 index 2d94b11815..0000000000 --- a/libr/fs/p/r2.mk +++ /dev/null @@ -1,9 +0,0 @@ -OBJ_R2=fs_r2.o - -STATIC_OBJ+=${OBJ_R2} -TARGET_R2=fs_r2.${EXT_SO} - -ALL_TARGETS+=${TARGET_R2} - -${TARGET_R2}: ${OBJ_R2} - ${CC} $(call libname,fs_r2) ${LDFLAGS} ${CFLAGS} -o ${TARGET_R2} ${OBJ_R2} ${EXTRA} diff --git a/libr/fs/p/reiserfs.mk b/libr/fs/p/reiserfs.mk deleted file mode 100644 index 3f31210455..0000000000 --- a/libr/fs/p/reiserfs.mk +++ /dev/null @@ -1,12 +0,0 @@ -OBJ_REISERFS=fs_reiserfs.o -EXTRA=$(GRUB) -CFLAGS+=-Igrub/include - -STATIC_OBJ+=${OBJ_REISERFS} -#STATIC_OBJ+=${EXTRA} -TARGET_REISERFS=fs_reiserfs.${EXT_SO} - -ALL_TARGETS+=${TARGET_REISERFS} - -${TARGET_REISERFS}: ${OBJ_REISERFS} - ${CC} $(call libname,fs_reiserfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_REISERFS} ${OBJ_REISERFS} ${EXTRA} diff --git a/libr/include/r_agraph.h b/libr/include/r_agraph.h deleted file mode 100644 index 1729e2e771..0000000000 --- a/libr/include/r_agraph.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef R2_AGRAPH_H -#define R2_AGRAPH_H - -#include -#include -#include - -typedef struct r_ascii_node_t { - RGraphNode *gnode; - char *title; - char *body; - - int x; - int y; - int w; - int h; - - int layer; - int layer_height; - int layer_width; - int pos_in_layer; - int is_dummy; - int is_reversed; - int klass; - int difftype; - bool is_mini; -} RANode; - -typedef struct r_core_graph_hits_t { - char *old_word ; - RVector word_list; - int word_nth; -} RAGraphHits; - - -#define R_AGRAPH_MODE_NORMAL 0 -#define R_AGRAPH_MODE_OFFSET 1 -#define R_AGRAPH_MODE_MINI 2 -#define R_AGRAPH_MODE_TINY 3 -#define R_AGRAPH_MODE_SUMMARY 4 -#define R_AGRAPH_MODE_COMMENTS 5 -#define R_AGRAPH_MODE_MAX 6 - -typedef void (*RANodeCallback)(RANode *n, void *user); -typedef void (*RAEdgeCallback)(RANode *from, RANode *to, void *user); - -typedef struct r_ascii_graph_t { - RConsCanvas *can; - RGraph *graph; - const RGraphNode *curnode; - char *title; - Sdb *db; - Sdb *nodes; // Sdb with title(key)=RANode*(value) - - int layout; - int is_instep; - bool is_tiny; - bool is_dis; - int edgemode; - int mode; - bool is_callgraph; - bool is_interactive; - int zoom; - int movspeed; - bool hints; - - RANode *update_seek_on; - bool need_reload_nodes; - bool need_set_layout; - int need_update_dim; - int force_update_seek; - - /* events */ - RANodeCallback on_curnode_change; - void *on_curnode_change_data; - bool dummy; // enable the dummy nodes for better layouting - bool show_node_titles; - bool show_node_body; - bool show_node_bubble; - - int x, y; - int w, h; - - /* layout algorithm info */ - RList *back_edges; - RList *long_edges; - struct layer_t *layers; - int n_layers; - RList *dists; /* RList */ - RList *edges; /* RList */ - RAGraphHits ghits; -} RAGraph; - -#ifdef R_API -R_API RAGraph *r_agraph_new(RConsCanvas *can); -R_API void r_agraph_free(RAGraph *g); -R_API void r_agraph_reset(RAGraph *g); -R_API void r_agraph_set_title(RAGraph *g, const char *title); -R_API RANode *r_agraph_get_first_node(const RAGraph *g); -R_API RANode *r_agraph_get_node(const RAGraph *g, const char *title); -R_API RANode *r_agraph_add_node(const RAGraph *g, const char *title, const char *body); -R_API RANode *r_agraph_add_node_with_color(const RAGraph *g, const char *title, const char *body, int color); -R_API bool r_agraph_del_node(const RAGraph *g, const char *title); -R_API void r_agraph_add_edge(const RAGraph *g, RANode *a, RANode *b); -R_API void r_agraph_add_edge_at(const RAGraph *g, RANode *a, RANode *b, int nth); -R_API void r_agraph_del_edge(const RAGraph *g, RANode *a, RANode *b); -R_API void r_agraph_print(RAGraph *g); -R_API void r_agraph_print_json(RAGraph *g, PJ *pj); -R_API Sdb *r_agraph_get_sdb(RAGraph *g); -R_API void r_agraph_foreach(RAGraph *g, RANodeCallback cb, void *user); -R_API void r_agraph_foreach_edge(RAGraph *g, RAEdgeCallback cb, void *user); -R_API void r_agraph_set_curnode(RAGraph *g, RANode *node); -R_API RAGraph *create_agraph_from_graph(const RGraph/**/ *graph); -#endif - -#endif diff --git a/libr/include/r_anal.h b/libr/include/r_anal.h deleted file mode 100644 index f6e5ad18b7..0000000000 --- a/libr/include/r_anal.h +++ /dev/null @@ -1,2191 +0,0 @@ -/* radare2 - LGPL - Copyright 2009-2020 - nibble, pancake, xvilka */ - -#ifndef R2_ANAL_H -#define R2_ANAL_H - -/* use old refs and function storage */ -// still required by core in lot of places -#define USE_VARSUBS 0 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_anal); - -/* dwarf processing context */ -typedef struct r_anal_dwarf_context { - const RBinDwarfDebugInfo *info; - HtUP/**/ *loc; - // const RBinDwarfCfa *cfa; TODO -} RAnalDwarfContext; - -// TODO: save memory2 : fingerprints must be pointers to a buffer -// containing a dupped file in memory - -/* save memory: - bb_has_ops=1 -> 600M - bb_has_ops=0 -> 350MB - */ - -typedef struct { - struct r_anal_t *anal; - int type; - int rad; - SdbForeachCallback cb; - void *user; - int count; - struct r_anal_function_t *fcn; - PJ *pj; -} RAnalMetaUserItem; - -typedef struct r_anal_range_t { - ut64 from; - ut64 to; - int bits; - ut64 rb_max_addr; - RBNode rb; -} RAnalRange; - -#define R_ANAL_GET_OFFSET(x,y,z) \ - (x && x->binb.bin && x->binb.get_offset)? \ - x->binb.get_offset (x->binb.bin, y, z): -1 -enum { - R_ANAL_DATA_TYPE_NULL = 0, - R_ANAL_DATA_TYPE_UNKNOWN = 1, - R_ANAL_DATA_TYPE_STRING = 2, - R_ANAL_DATA_TYPE_WIDE_STRING = 3, - R_ANAL_DATA_TYPE_POINTER = 4, - R_ANAL_DATA_TYPE_NUMBER = 5, - R_ANAL_DATA_TYPE_INVALID = 6, - R_ANAL_DATA_TYPE_HEADER = 7, - R_ANAL_DATA_TYPE_SEQUENCE = 8, - R_ANAL_DATA_TYPE_PATTERN = 9, -}; - -// used from core/anal.c -#define R_ANAL_ADDR_TYPE_EXEC 1 -#define R_ANAL_ADDR_TYPE_READ 1 << 1 -#define R_ANAL_ADDR_TYPE_WRITE 1 << 2 -#define R_ANAL_ADDR_TYPE_FLAG 1 << 3 -#define R_ANAL_ADDR_TYPE_FUNC 1 << 4 -#define R_ANAL_ADDR_TYPE_HEAP 1 << 5 -#define R_ANAL_ADDR_TYPE_STACK 1 << 6 -#define R_ANAL_ADDR_TYPE_REG 1 << 7 -#define R_ANAL_ADDR_TYPE_PROGRAM 1 << 8 -#define R_ANAL_ADDR_TYPE_LIBRARY 1 << 9 -#define R_ANAL_ADDR_TYPE_ASCII 1 << 10 -#define R_ANAL_ADDR_TYPE_SEQUENCE 1 << 11 - -#define R_ANAL_ARCHINFO_MIN_OP_SIZE 0 -#define R_ANAL_ARCHINFO_MAX_OP_SIZE 1 -#define R_ANAL_ARCHINFO_ALIGN 2 -#define R_ANAL_ARCHINFO_DATA_ALIGN 4 - -/* copypaste from r_asm.h */ - -#define R_ANAL_GET_OFFSET(x,y,z) \ - (x && x->binb.bin && x->binb.get_offset)? \ - x->binb.get_offset (x->binb.bin, y, z): -1 - -#define R_ANAL_GET_NAME(x,y,z) \ - (x && x->binb.bin && x->binb.get_name)? \ - x->binb.get_name (x->binb.bin, y, z): NULL - -/* type = (R_ANAL_VAR_TYPE_BYTE & R_ANAL_VAR_TYPE_SIZE_MASK) | - * ( RANAL_VAR_TYPE_SIGNED & RANAL_VAR_TYPE_SIGN_MASK) | - * ( RANAL_VAR_TYPE_CONST & RANAL_VAR_TYPE_MODIFIER_MASK) - */ -typedef struct r_anal_type_var_t { - char *name; - int index; - int scope; - ut16 type; // contain (type || signedness || modifier) - ut8 size; - union { - ut8 v8; - ut16 v16; - ut32 v32; - ut64 v64; - } value; -} RAnalTypeVar; - -typedef struct r_anal_type_ptr_t { - char *name; - ut16 type; // contain (type || signedness || modifier) - ut8 size; - union { - ut8 v8; - ut16 v16; - ut32 v32; - ut64 v64; - } value; -} RAnalTypePtr; - -typedef struct r_anal_type_array_t { - char *name; - ut16 type; // contain (type || signedness || modifier) - ut8 size; - ut64 count; - union { - ut8 *v8; - ut16 *v16; - ut32 *v32; - ut64 *v64; - } value; -} RAnalTypeArray; - -typedef struct r_anal_type_struct_t RAnalTypeStruct; -typedef struct r_anal_type_t RAnalType; - -struct r_anal_type_struct_t { - char *name; - ut8 type; - ut32 size; - void *parent; - RAnalType *items; -}; - -typedef struct r_anal_type_union_t { - char *name; - ut8 type; - ut32 size; - void *parent; - RAnalType *items; -} RAnalTypeUnion; - -typedef struct r_anal_type_alloca_t { - long address; - long size; - void *parent; - RAnalType *items; -} RAnalTypeAlloca; - -enum { - R_ANAL_FQUALIFIER_NONE = 0, - R_ANAL_FQUALIFIER_STATIC = 1, - R_ANAL_FQUALIFIER_VOLATILE = 2, - R_ANAL_FQUALIFIER_INLINE = 3, - R_ANAL_FQUALIFIER_NAKED = 4, - R_ANAL_FQUALIFIER_VIRTUAL = 5, -}; - -/*--------------------Function Conventions-----------*/ -//XXX don't use them in the future -#define R_ANAL_CC_TYPE_STDCALL 0 -#define R_ANAL_CC_TYPE_PASCAL 1 -#define R_ANAL_CC_TYPE_FASTCALL 'A' // syscall -#define R_ANAL_CC_TYPE_SYSV 8 -#define R_ANAL_CC_MAXARG 16 - -enum { - R_ANAL_FCN_TYPE_NULL = 0, - R_ANAL_FCN_TYPE_FCN = 1 << 0, - R_ANAL_FCN_TYPE_LOC = 1 << 1, - R_ANAL_FCN_TYPE_SYM = 1 << 2, - R_ANAL_FCN_TYPE_IMP = 1 << 3, - R_ANAL_FCN_TYPE_INT = 1 << 4, /* privileged function - ends with iret/reti/.. */ - R_ANAL_FCN_TYPE_ROOT = 1 << 5, /* matching flag */ - R_ANAL_FCN_TYPE_ANY = -1 /* all the bits set */ -}; - -#define RAnalBlock struct r_anal_bb_t - -enum { - R_ANAL_DIFF_TYPE_NULL = 0, - R_ANAL_DIFF_TYPE_MATCH = 'm', - R_ANAL_DIFF_TYPE_UNMATCH = 'u' -}; - -typedef struct r_anal_enum_case_t { - char *name; - int val; -} RAnalEnumCase; - -typedef struct r_anal_struct_member_t { - char *name; - char *type; - size_t offset; // in bytes - size_t size; // in bits? -} RAnalStructMember; - -typedef struct r_anal_union_member_t { - char *name; - char *type; - size_t offset; // in bytes - size_t size; // in bits? -} RAnalUnionMember; - -typedef enum { - R_ANAL_BASE_TYPE_KIND_STRUCT, - R_ANAL_BASE_TYPE_KIND_UNION, - R_ANAL_BASE_TYPE_KIND_ENUM, - R_ANAL_BASE_TYPE_KIND_TYPEDEF, // probably temporary addition, dev purposes - R_ANAL_BASE_TYPE_KIND_ATOMIC, // For real atomic base types -} RAnalBaseTypeKind; - -typedef struct r_anal_base_type_struct_t { - RVector/**/ members; -} RAnalBaseTypeStruct; - -typedef struct r_anal_base_type_union_t { - RVector/**/ members; -} RAnalBaseTypeUnion; - -typedef struct r_anal_base_type_enum_t { - RVector/* bits 0) (set-bits bits)) - int type; - const char *cc; // calling convention, should come from RAnal.constpool - ut64 addr; - HtUP/**/ *labels; - HtPP/**/ *label_addrs; - RPVector vars; - HtUP/*>*/ *inst_vars; // offset of instructions => the variables they access - ut64 reg_save_area; // size of stack area pre-reserved for saving registers - st64 bp_off; // offset of bp inside owned stack frame - st64 stack; // stack frame size - int maxstack; - int ninstr; - bool folded; - bool is_pure; - bool is_variadic; - bool has_changed; // true if function may have changed since last anaysis TODO: set this attribute where necessary - bool bp_frame; - bool is_noreturn; // true if function does not return - ut8 *fingerprint; // TODO: make is fuzzy and smarter - size_t fingerprint_size; - RAnalDiff *diff; - RList *bbs; // TODO: should be RPVector - RAnalFcnMeta meta; - RList *imports; // maybe bound to class? - struct r_anal_t *anal; // this function is associated with this instance -} RAnalFunction; - -typedef struct r_anal_func_arg_t { - const char *name; - const char *fmt; - const char *cc_source; - char *orig_c_type; - char *c_type; - ut64 size; - ut64 src; //Function-call argument value or pointer to it -} RAnalFuncArg; - -struct r_anal_type_t { - char *name; - ut32 type; - ut32 size; - RList *content; -}; - -typedef enum { - R_META_TYPE_ANY = -1, - R_META_TYPE_DATA = 'd', - R_META_TYPE_CODE = 'c', - R_META_TYPE_STRING = 's', - R_META_TYPE_FORMAT = 'f', - R_META_TYPE_MAGIC = 'm', - R_META_TYPE_HIDE = 'h', - R_META_TYPE_COMMENT = 'C', - R_META_TYPE_RUN = 'r', - R_META_TYPE_HIGHLIGHT = 'H', - R_META_TYPE_VARTYPE = 't', -} RAnalMetaType; - -/* meta */ -typedef struct r_anal_meta_item_t { - RAnalMetaType type; - int subtype; - char *str; - const RSpace *space; -} RAnalMetaItem; - -// anal -typedef enum { - R_ANAL_OP_FAMILY_UNKNOWN = -1, - R_ANAL_OP_FAMILY_CPU = 0, /* normal cpu instruction */ - R_ANAL_OP_FAMILY_FPU, /* fpu (floating point) */ - R_ANAL_OP_FAMILY_MMX, /* multimedia instruction (packed data) */ - R_ANAL_OP_FAMILY_SSE, /* extended multimedia instruction (packed data) */ - R_ANAL_OP_FAMILY_PRIV, /* privileged instruction */ - R_ANAL_OP_FAMILY_CRYPTO, /* cryptographic instructions */ - R_ANAL_OP_FAMILY_THREAD, /* thread/lock/sync instructions */ - R_ANAL_OP_FAMILY_VIRT, /* virtualization instructions */ - R_ANAL_OP_FAMILY_SECURITY, /* security instructions */ - R_ANAL_OP_FAMILY_IO, /* IO instructions (i.e. IN/OUT) */ - R_ANAL_OP_FAMILY_LAST -} RAnalOpFamily; - -#if 0 -On x86 according to Wikipedia - - Prefix group 1 - 0xF0: LOCK prefix - 0xF2: REPNE/REPNZ prefix - 0xF3: REP or REPE/REPZ prefix - Prefix group 2 - 0x2E: CS segment override - 0x36: SS segment override - 0x3E: DS segment override - 0x26: ES segment override - 0x64: FS segment override - 0x65: GS segment override - 0x2E: Branch not taken (hinting) - 0x3E: Branch taken - Prefix group 3 - 0x66: Operand-size override prefix - Prefix group 4 - 0x67: Address-size override prefix -#endif - typedef enum { - R_ANAL_OP_PREFIX_COND = 1, - R_ANAL_OP_PREFIX_REP = 1<<1, - R_ANAL_OP_PREFIX_REPNE = 1<<2, - R_ANAL_OP_PREFIX_LOCK = 1<<3, - R_ANAL_OP_PREFIX_LIKELY = 1<<4, - R_ANAL_OP_PREFIX_UNLIKELY = 1<<5 - /* TODO: add segment override typemods? */ - } RAnalOpPrefix; - -// XXX: this definition is plain wrong. use enum or empower bits -#define R_ANAL_OP_TYPE_MASK 0x8000ffff -#define R_ANAL_OP_HINT_MASK 0xf0000000 -typedef enum { - R_ANAL_OP_TYPE_COND = 0x80000000, // TODO must be moved to prefix? - //TODO: MOVE TO PREFIX .. it is used by anal_java.. must be updated - R_ANAL_OP_TYPE_REP = 0x40000000, /* repeats next instruction N times */ - R_ANAL_OP_TYPE_MEM = 0x20000000, // TODO must be moved to prefix? - R_ANAL_OP_TYPE_REG = 0x10000000, // operand is a register - R_ANAL_OP_TYPE_IND = 0x08000000, // operand is indirect - R_ANAL_OP_TYPE_NULL = 0, - R_ANAL_OP_TYPE_JMP = 1, /* mandatory jump */ - R_ANAL_OP_TYPE_UJMP = 2, /* unknown jump (register or so) */ - R_ANAL_OP_TYPE_RJMP = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UJMP, - R_ANAL_OP_TYPE_IJMP = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_UJMP, - R_ANAL_OP_TYPE_IRJMP = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UJMP, - R_ANAL_OP_TYPE_CJMP = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_JMP, /* conditional jump */ - R_ANAL_OP_TYPE_RCJMP = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_CJMP, /* conditional jump register */ - R_ANAL_OP_TYPE_MJMP = R_ANAL_OP_TYPE_MEM | R_ANAL_OP_TYPE_JMP, /* memory jump */ - R_ANAL_OP_TYPE_MCJMP = R_ANAL_OP_TYPE_MEM | R_ANAL_OP_TYPE_CJMP, /* memory conditional jump */ - R_ANAL_OP_TYPE_UCJMP = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_UJMP, /* conditional unknown jump */ - R_ANAL_OP_TYPE_CALL = 3, /* call to subroutine (branch+link) */ - R_ANAL_OP_TYPE_UCALL = 4, /* unknown call (register or so) */ - R_ANAL_OP_TYPE_RCALL = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UCALL, - R_ANAL_OP_TYPE_ICALL = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_UCALL, - R_ANAL_OP_TYPE_IRCALL= R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UCALL, - R_ANAL_OP_TYPE_CCALL = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_CALL, /* conditional call to subroutine */ - R_ANAL_OP_TYPE_UCCALL= R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_UCALL, /* conditional unknown call */ - R_ANAL_OP_TYPE_RET = 5, /* returns from subroutine */ - R_ANAL_OP_TYPE_CRET = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_RET, /* conditional return from subroutine */ - R_ANAL_OP_TYPE_ILL = 6, /* illegal instruction // trap */ - R_ANAL_OP_TYPE_UNK = 7, /* unknown opcode type */ - R_ANAL_OP_TYPE_NOP = 8, /* does nothing */ - R_ANAL_OP_TYPE_MOV = 9, /* register move */ - R_ANAL_OP_TYPE_CMOV = 9 | R_ANAL_OP_TYPE_COND, /* conditional move */ - R_ANAL_OP_TYPE_TRAP = 10, /* it's a trap! */ - R_ANAL_OP_TYPE_SWI = 11, /* syscall, software interrupt */ - R_ANAL_OP_TYPE_CSWI = 11 | R_ANAL_OP_TYPE_COND, /* syscall, software interrupt */ - R_ANAL_OP_TYPE_UPUSH = 12, /* unknown push of data into stack */ - R_ANAL_OP_TYPE_RPUSH = R_ANAL_OP_TYPE_UPUSH | R_ANAL_OP_TYPE_REG, /* push register */ - R_ANAL_OP_TYPE_PUSH = 13, /* push value into stack */ - R_ANAL_OP_TYPE_POP = 14, /* pop value from stack to register */ - R_ANAL_OP_TYPE_CMP = 15, /* compare something */ - R_ANAL_OP_TYPE_ACMP = 16, /* compare via and */ - R_ANAL_OP_TYPE_ADD = 17, - R_ANAL_OP_TYPE_SUB = 18, - R_ANAL_OP_TYPE_IO = 19, - R_ANAL_OP_TYPE_MUL = 20, - R_ANAL_OP_TYPE_DIV = 21, - R_ANAL_OP_TYPE_SHR = 22, - R_ANAL_OP_TYPE_SHL = 23, - R_ANAL_OP_TYPE_SAL = 24, - R_ANAL_OP_TYPE_SAR = 25, - R_ANAL_OP_TYPE_OR = 26, - R_ANAL_OP_TYPE_AND = 27, - R_ANAL_OP_TYPE_XOR = 28, - R_ANAL_OP_TYPE_NOR = 29, - R_ANAL_OP_TYPE_NOT = 30, - R_ANAL_OP_TYPE_STORE = 31, /* store from register to memory */ - R_ANAL_OP_TYPE_LOAD = 32, /* load from memory to register */ - R_ANAL_OP_TYPE_LEA = 33, /* TODO add ulea */ - R_ANAL_OP_TYPE_LEAVE = 34, - R_ANAL_OP_TYPE_ROR = 35, - R_ANAL_OP_TYPE_ROL = 36, - R_ANAL_OP_TYPE_XCHG = 37, - R_ANAL_OP_TYPE_MOD = 38, - R_ANAL_OP_TYPE_SWITCH = 39, - R_ANAL_OP_TYPE_CASE = 40, - R_ANAL_OP_TYPE_LENGTH = 41, - R_ANAL_OP_TYPE_CAST = 42, - R_ANAL_OP_TYPE_NEW = 43, - R_ANAL_OP_TYPE_ABS = 44, - R_ANAL_OP_TYPE_CPL = 45, /* complement */ - R_ANAL_OP_TYPE_CRYPTO = 46, - R_ANAL_OP_TYPE_SYNC = 47, - //R_ANAL_OP_TYPE_DEBUG = 43, // monitor/trace/breakpoint -#if 0 - R_ANAL_OP_TYPE_PRIV = 40, /* privileged instruction */ - R_ANAL_OP_TYPE_FPU = 41, /* floating point stuff */ -#endif -} _RAnalOpType; - -typedef enum { - R_ANAL_OP_MASK_BASIC = 0, // Just fills basic op info , it's fast - R_ANAL_OP_MASK_ESIL = 1, // It fills RAnalop->esil info - R_ANAL_OP_MASK_VAL = 2, // It fills RAnalop->dst/src info - R_ANAL_OP_MASK_HINT = 4, // It calls r_anal_op_hint to override anal options - R_ANAL_OP_MASK_OPEX = 8, // It fills RAnalop->opex info - R_ANAL_OP_MASK_DISASM = 16, // It fills RAnalop->mnemonic // should be RAnalOp->disasm // only from r_core_anal_op() - R_ANAL_OP_MASK_ALL = 1 | 2 | 4 | 8 | 16 -} RAnalOpMask; - -/* TODO: what to do with signed/unsigned conditionals? */ -typedef enum { - R_ANAL_COND_AL = 0, // Always executed (no condition) - R_ANAL_COND_EQ, // Equal - R_ANAL_COND_NE, // Not equal - R_ANAL_COND_GE, // Greater or equal - R_ANAL_COND_GT, // Greater than - R_ANAL_COND_LE, // Less or equal - R_ANAL_COND_LT, // Less than - R_ANAL_COND_NV, // Never executed must be a nop? :D - R_ANAL_COND_HS, // Carry set >, ==, or unordered - R_ANAL_COND_LO, // Carry clear Less than - R_ANAL_COND_MI, // Minus, negative Less than - R_ANAL_COND_PL, // Plus, positive or zero >, ==, or unordered - R_ANAL_COND_VS, // Overflow Unordered - R_ANAL_COND_VC, // No overflow Not unordered - R_ANAL_COND_HI, // Unsigned higher Greater than, or unordered - R_ANAL_COND_LS // Unsigned lower or same Less than or equal -} _RAnalCond; - -typedef enum { - R_ANAL_VAR_SCOPE_LOCAL = 0x01 -} _RAnalVarScope; - -typedef enum { - R_ANAL_STACK_NULL = 0, - R_ANAL_STACK_NOP, - R_ANAL_STACK_INC, - R_ANAL_STACK_GET, - R_ANAL_STACK_SET, - R_ANAL_STACK_RESET, - R_ANAL_STACK_ALIGN, -} RAnalStackOp; - -enum { - R_ANAL_REFLINE_TYPE_UTF8 = 1, - R_ANAL_REFLINE_TYPE_WIDE = 2, /* reflines have a space between them */ - R_ANAL_REFLINE_TYPE_MIDDLE_BEFORE = 4, /* do not consider starts/ends of - * reflines (used for comment lines before disasm) */ - R_ANAL_REFLINE_TYPE_MIDDLE_AFTER = 8 /* as above but for lines after disasm */ -}; - -enum { - R_ANAL_RET_NOP = 0, - R_ANAL_RET_ERROR = -1, - R_ANAL_RET_DUP = -2, - R_ANAL_RET_NEW = -3, - R_ANAL_RET_END = -4 -}; - -typedef struct r_anal_case_obj_t { - ut64 addr; - ut64 jump; - ut64 value; -} RAnalCaseOp; - -typedef struct r_anal_switch_obj_t { - ut64 addr; - ut64 min_val; - ut64 def_val; - ut64 max_val; - RList/**/ *cases; -} RAnalSwitchOp; - -struct r_anal_t; -struct r_anal_bb_t; -typedef struct r_anal_callbacks_t { - int (*on_fcn_new) (struct r_anal_t *, void *user, RAnalFunction *fcn); - int (*on_fcn_delete) (struct r_anal_t *, void *user, RAnalFunction *fcn); - int (*on_fcn_rename) (struct r_anal_t *, void *user, RAnalFunction *fcn, const char *oldname); - int (*on_fcn_bb_new) (struct r_anal_t *, void *user, RAnalFunction *fcn, struct r_anal_bb_t *bb); -} RAnalCallbacks; - -#define R_ANAL_ESIL_GOTO_LIMIT 4096 - -typedef struct r_anal_options_t { - int depth; - int graph_depth; - bool vars; //analyze local var and arguments - bool varname_stack; // name vars based on their offset in the stack - int cjmpref; - int jmpref; - int jmpabove; - bool ijmp; - bool jmpmid; // continue analysis after jmp into middle of insn - bool loads; - bool ignbithints; - int followdatarefs; - int searchstringrefs; - int followbrokenfcnsrefs; - int bb_max_size; - bool trycatch; - bool norevisit; - int afterjmp; // continue analysis after jmp eax or forward jmp // option - int recont; // continue on recurse analysis mode - int noncode; - int nopskip; // skip nops at the beginning of functions - int hpskip; // skip `mov reg,reg` and `lea reg,[reg]` - int jmptbl; // analyze jump tables - int nonull; - bool pushret; // analyze push+ret as jmp - bool armthumb; // - bool endsize; // chop function size which is known to be buggy but goodie too - bool delay; - int tailcall; - bool retpoline; -} RAnalOptions; - -typedef enum { - R_ANAL_CPP_ABI_ITANIUM = 0, - R_ANAL_CPP_ABI_MSVC -} RAnalCPPABI; - -typedef struct r_anal_hint_cb_t { - //add more cbs as needed - void (*on_bits) (struct r_anal_t *a, ut64 addr, int bits, bool set); -} RHintCb; - -typedef struct r_anal_t { - char *cpu; // anal.cpu - char *os; // asm.os - int bits; // asm.bits - int lineswidth; // asm.lines.width - int big_endian; // cfg.bigendian - int sleep; // anal.sleep, sleep some usecs before analyzing more (avoid 100% cpu usages) - RAnalCPPABI cpp_abi; // anal.cpp.abi - void *user; - ut64 gp; // anal.gp, global pointer. used for mips. but can be used by other arches too in the future - RBTree bb_tree; // all basic blocks by address. They can overlap each other, but must never start at the same address. - RList *fcns; - HtUP *ht_addr_fun; // address => function - HtPP *ht_name_fun; // name => function - RReg *reg; - ut8 *last_disasm_reg; - RSyscall *syscall; - int diff_ops; - double diff_thbb; - double diff_thfcn; - RIOBind iob; - RFlagBind flb; - RFlagSet flg_class_set; - RFlagGet flg_class_get; - RFlagSet flg_fcn_set; - RBinBind binb; // Set only from core when an analysis plugin is called. - RCoreBind coreb; - int maxreflines; // asm.lines.maxref - int esil_goto_limit; // esil.gotolimit - int pcalign; // asm.pcalign - struct r_anal_esil_t *esil; - struct r_anal_plugin_t *cur; - RAnalRange *limit; // anal.from, anal.to - RList *plugins; - Sdb *sdb_types; - Sdb *sdb_fmts; - Sdb *sdb_zigns; - HtUP *dict_refs; - HtUP *dict_xrefs; - bool recursive_noreturn; // anal.rnr - RSpaces zign_spaces; - char *zign_path; // dir.zigns - PrintfCallback cb_printf; - //moved from RAnalFcn - Sdb *sdb; // root - Sdb *sdb_pins; - HtUP/*>*/ *addr_hints; // all hints that correspond to a single address - RBTree/**/ arch_hints; - RBTree/**/ bits_hints; - RHintCb hint_cbs; - RIntervalTree meta; - RSpaces meta_spaces; - Sdb *sdb_cc; // calling conventions - Sdb *sdb_classes; - Sdb *sdb_classes_attrs; - RAnalCallbacks cb; - RAnalOptions opt; - RList *reflines; - //RList *noreturn; - RListComparator columnSort; - int stackptr; - bool (*log)(struct r_anal_t *anal, const char *msg); - bool (*read_at)(struct r_anal_t *anal, ut64 addr, ut8 *buf, int len); - bool verbose; - int seggrn; - RFlagGetAtAddr flag_get; - REvent *ev; - RList/**/ *imports; // global imports - SetU *visited; - RStrConstPool constpool; - RList *leaddrs; -} RAnal; - -typedef enum r_anal_addr_hint_type_t { - R_ANAL_ADDR_HINT_TYPE_IMMBASE, - R_ANAL_ADDR_HINT_TYPE_JUMP, - R_ANAL_ADDR_HINT_TYPE_FAIL, - R_ANAL_ADDR_HINT_TYPE_STACKFRAME, - R_ANAL_ADDR_HINT_TYPE_PTR, - R_ANAL_ADDR_HINT_TYPE_NWORD, - R_ANAL_ADDR_HINT_TYPE_RET, - R_ANAL_ADDR_HINT_TYPE_NEW_BITS, - R_ANAL_ADDR_HINT_TYPE_SIZE, - R_ANAL_ADDR_HINT_TYPE_SYNTAX, - R_ANAL_ADDR_HINT_TYPE_OPTYPE, - R_ANAL_ADDR_HINT_TYPE_OPCODE, - R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET, - R_ANAL_ADDR_HINT_TYPE_ESIL, - R_ANAL_ADDR_HINT_TYPE_HIGH, - R_ANAL_ADDR_HINT_TYPE_VAL -} RAnalAddrHintType; - -typedef struct r_anal_addr_hint_record_t { - RAnalAddrHintType type; - union { - char *type_offset; - int nword; - ut64 jump; - ut64 fail; - int newbits; - int immbase; - ut64 ptr; - ut64 retval; - char *syntax; - char *opcode; - char *esil; - int optype; - ut64 size; - ut64 stackframe; - ut64 val; - }; -} RAnalAddrHintRecord; - -typedef struct r_anal_hint_t { - ut64 addr; - ut64 ptr; - ut64 val; // used to hint jmp rax - ut64 jump; - ut64 fail; - ut64 ret; // hint for function ret values - char *arch; - char *opcode; - char *syntax; - char *esil; - char *offset; - ut32 type; - ut64 size; - int bits; - int new_bits; // change asm.bits after evaluating this instruction - int immbase; - bool high; // highlight hint - int nword; - ut64 stackframe; -} RAnalHint; - -typedef RAnalFunction *(* RAnalGetFcnIn)(RAnal *anal, ut64 addr, int type); -typedef RAnalHint *(* RAnalGetHint)(RAnal *anal, ut64 addr); - -typedef struct r_anal_bind_t { - RAnal *anal; - RAnalGetFcnIn get_fcn_in; - RAnalGetHint get_hint; -} RAnalBind; - -typedef const char *(*RAnalLabelAt) (RAnalFunction *fcn, ut64); - -typedef enum { - R_ANAL_VAR_KIND_REG = 'r', - R_ANAL_VAR_KIND_BPV = 'b', - R_ANAL_VAR_KIND_SPV = 's' -} RAnalVarKind; - -#define VARPREFIX "var" -#define ARGPREFIX "arg" - -typedef enum { - R_ANAL_VAR_ACCESS_TYPE_READ = (1 << 0), - R_ANAL_VAR_ACCESS_TYPE_WRITE = (1 << 1) -} RAnalVarAccessType; - -typedef struct r_anal_var_access_t { - const char *reg; // register used for access - st64 offset; // relative to the function's entrypoint - st64 stackptr; // delta added to register to get the var, e.g. [rbp - 0x10] - ut8 type; // RAnalVarAccessType bits -} RAnalVarAccess; - -typedef struct r_anal_var_constraint_t { - _RAnalCond cond; - ut64 val; -} RAnalVarConstraint; - -// generic for args and locals -typedef struct r_anal_var_t { - RAnalFunction *fcn; - char *name; // name of the variable - char *type; // cparse type of the variable - RAnalVarKind kind; - bool isarg; - int delta; /* delta offset inside stack frame */ - char *regname; // name of the register - RVector/**/ accesses; // ordered by offset, touch this only through API or expect uaf - char *comment; - RVector/**/ constraints; - - // below members are just for caching, TODO: remove them and do it better - int argnum; -} RAnalVar; - -// Refers to a variable or a struct field inside a variable, only for varsub -R_DEPRECATE typedef struct r_anal_var_field_t { - char *name; - st64 delta; - bool field; -} RAnalVarField; - -typedef enum { - R_ANAL_ACC_UNKNOWN = 0, - R_ANAL_ACC_R = (1 << 0), - R_ANAL_ACC_W = (1 << 1), -} RAnalValueAccess; - -typedef enum { - R_ANAL_VAL_REG, - R_ANAL_VAL_MEM, - R_ANAL_VAL_IMM, -} RAnalValueType; - -// base+reg+regdelta*mul+delta -typedef struct r_anal_value_t { - RAnalValueType type; - RAnalValueAccess access; - int absolute; // if true, unsigned cast is used - int memref; // is memory reference? which size? 1, 2 ,4, 8 - ut64 base ; // numeric address - st64 delta; // numeric delta - st64 imm; // immediate value - int mul; // multiplier (reg*4+base) - RRegItem *seg; // segment selector register - RRegItem *reg; // register / register base used (-1 if no reg) - RRegItem *regdelta; // register index used (-1 if no reg) -} RAnalValue; - -typedef enum { - R_ANAL_OP_DIR_READ = 1, - R_ANAL_OP_DIR_WRITE = 2, - R_ANAL_OP_DIR_EXEC = 4, - R_ANAL_OP_DIR_REF = 8, -} RAnalOpDirection; - -typedef enum r_anal_data_type_t { - R_ANAL_DATATYPE_NULL = 0, - R_ANAL_DATATYPE_ARRAY, - R_ANAL_DATATYPE_OBJECT, // instance - R_ANAL_DATATYPE_STRING, - R_ANAL_DATATYPE_CLASS, - R_ANAL_DATATYPE_BOOLEAN, - R_ANAL_DATATYPE_INT16, - R_ANAL_DATATYPE_INT32, - R_ANAL_DATATYPE_INT64, - R_ANAL_DATATYPE_FLOAT, -} RAnalDataType; - -typedef struct r_anal_op_t { - char *mnemonic; /* mnemonic.. it actually contains the args too, we should replace rasm with this */ - ut64 addr; /* address */ - ut32 type; /* type of opcode */ - RAnalOpPrefix prefix; /* type of opcode prefix (rep,lock,..) */ - ut32 type2; /* used by java */ - RAnalStackOp stackop; /* operation on stack? */ - _RAnalCond cond; /* condition type */ - int size; /* size in bytes of opcode */ - int nopcode; /* number of bytes representing the opcode (not the arguments) TODO: find better name */ - int cycles; /* cpu-cycles taken by instruction */ - int failcycles; /* conditional cpu-cycles */ - RAnalOpFamily family; /* family of opcode */ - int id; /* instruction id */ - bool eob; /* end of block (boolean) */ - bool sign; /* operates on signed values, false by default */ - /* Run N instructions before executing the current one */ - int delay; /* delay N slots (mips, ..)*/ - ut64 jump; /* true jmp */ - ut64 fail; /* false jmp */ - RAnalOpDirection direction; - st64 ptr; /* reference to memory */ /* XXX signed? */ - ut64 val; /* reference to value */ /* XXX signed? */ - int ptrsize; /* f.ex: zero extends for 8, 16 or 32 bits only */ - st64 stackptr; /* stack pointer */ - int refptr; /* if (0) ptr = "reference" else ptr = "load memory of refptr bytes" */ - RAnalValue *src[3]; - RAnalValue *dst; - RList *access; /* RAnalValue access information */ - RStrBuf esil; - RStrBuf opex; - const char *reg; /* destination register */ - const char *ireg; /* register used for indirect memory computation*/ - int scale; - ut64 disp; - RAnalSwitchOp *switch_op; - RAnalHint hint; - RAnalDataType datatype; -} RAnalOp; - -#define R_ANAL_COND_SINGLE(x) (!x->arg[1] || x->arg[0]==x->arg[1]) - -typedef struct r_anal_cond_t { - int type; // filled by CJMP opcode - RAnalValue *arg[2]; // filled by CMP opcode -} RAnalCond; - -typedef struct r_anal_bb_t { - RBNode _rb; // private, node in the RBTree - ut64 _max_end; // private, augmented value for RBTree - - ut64 addr; - ut64 size; - ut64 jump; - ut64 fail; - bool traced; - bool folded; - ut32 colorize; - ut8 *fingerprint; - RAnalDiff *diff; - RAnalCond *cond; - RAnalSwitchOp *switch_op; - ut16 *op_pos; // offsets of instructions in this block, count is ninstr - 1 (first is always 0) - ut8 *op_bytes; - ut8 *parent_reg_arena; - int op_pos_size; // size of the op_pos array - int ninstr; - int stackptr; - int parent_stackptr; - ut64 cmpval; - const char *cmpreg; - - RList *fcns; - RAnal *anal; - int ref; -#undef RAnalBlock -} RAnalBlock; - -typedef enum { - R_ANAL_REF_TYPE_NULL = 0, - R_ANAL_REF_TYPE_CODE = 'c', // code ref - R_ANAL_REF_TYPE_CALL = 'C', // code ref (call) - R_ANAL_REF_TYPE_DATA = 'd', // mem ref - R_ANAL_REF_TYPE_STRING='s' // string ref -} RAnalRefType; - -typedef struct r_anal_ref_t { - ut64 addr; - ut64 at; - RAnalRefType type; -} RAnalRef; -R_API const char *r_anal_ref_type_tostring(RAnalRefType t); - -/* represents a reference line from one address (from) to another (to) */ -typedef struct r_anal_refline_t { - ut64 from; - ut64 to; - int index; - int level; - int type; - int direction; -} RAnalRefline; - -typedef struct r_anal_cycle_frame_t { - ut64 naddr; //next addr - RList *hooks; - struct r_anal_cycle_frame_t *prev; -} RAnalCycleFrame; - -typedef struct r_anal_cycle_hook_t { //rename ? - ut64 addr; - int cycles; -} RAnalCycleHook; - -typedef struct r_anal_esil_word_t { - int type; - const char *str; -} RAnalEsilWord; - -// only flags that affect control flow -enum { - R_ANAL_ESIL_FLAG_ZERO = 1, - R_ANAL_ESIL_FLAG_CARRY = 2, - R_ANAL_ESIL_FLAG_OVERFLOW = 4, - R_ANAL_ESIL_FLAG_PARITY = 8, - R_ANAL_ESIL_FLAG_SIGN = 16, - // ... -}; - -enum { - R_ANAL_TRAP_NONE = 0, - R_ANAL_TRAP_UNHANDLED = 1, - R_ANAL_TRAP_BREAKPOINT = 2, - R_ANAL_TRAP_DIVBYZERO = 3, - R_ANAL_TRAP_WRITE_ERR = 4, - R_ANAL_TRAP_READ_ERR = 5, - R_ANAL_TRAP_EXEC_ERR = 6, - R_ANAL_TRAP_INVALID = 7, - R_ANAL_TRAP_UNALIGNED = 8, - R_ANAL_TRAP_TODO = 9, - R_ANAL_TRAP_HALT = 10, -}; - -enum { - R_ANAL_ESIL_PARM_INVALID = 0, - R_ANAL_ESIL_PARM_REG, - R_ANAL_ESIL_PARM_NUM, -}; - -/* Constructs to convert from ESIL to REIL */ -#define FOREACHOP(GENERATE) \ -/* No Operation */ GENERATE(NOP) \ -/* Unknown/Undefined */ GENERATE(UNK) \ -/* Conditional Jump */ GENERATE(JCC) \ -/* Store Value to register */ GENERATE(STR) \ -/* Store value to memory */ GENERATE(STM) \ -/* Load value from memory */ GENERATE(LDM) \ -/* Addition */ GENERATE(ADD) \ -/* Subtraction */ GENERATE(SUB) \ -/* Negation */ GENERATE(NEG) \ -/* Multiplication */ GENERATE(MUL) \ -/* Division */ GENERATE(DIV) \ -/* Modulo */ GENERATE(MOD) \ -/* Signed Multiplication */ GENERATE(SMUL) \ -/* Sugned Division */ GENERATE(SDIV) \ -/* Signed Modulus */ GENERATE(SMOD) \ -/* Shift Left */ GENERATE(SHL) \ -/* Shift Right */ GENERATE(SHR) \ -/* Binary and */ GENERATE(AND) \ -/* Binary or */ GENERATE(OR) \ -/* Binary xor */ GENERATE(XOR) \ -/* Binary not */ GENERATE(NOT) \ -/* Equation */ GENERATE(EQ) \ -/* Less Than */ GENERATE(LT) - -#define MAKE_ENUM(OP) REIL_##OP, -#define REIL_OP_STRING(STRING) #STRING, - -typedef enum { - FOREACHOP(MAKE_ENUM) -} RAnalReilOpcode; - -typedef enum { - ARG_REG, // CPU Register - ARG_TEMP, // Temporary register used by REIL - ARG_CONST, // Constant value - ARG_ESIL_INTERNAL, // Used to resolve ESIL internal flags - ARG_NONE // Operand not used by the instruction -} RAnalReilArgType; - -// Arguments to a REIL instruction. -typedef struct r_anal_reil_arg { - RAnalReilArgType type; // Type of the argument - ut8 size; // Size of the argument in bytes - char name[32]; // Name of the argument -} RAnalReilArg; - -typedef struct r_anal_ref_char { - char *str; - char *cols; -} RAnalRefStr; - -// Instruction arg1, arg2, arg3 -typedef struct r_anal_reil_inst { - RAnalReilOpcode opcode; - RAnalReilArg *arg[3]; -} RAnalReilInst; - -typedef struct r_anal_reil { - char old[32]; // Used to compute flags. - char cur[32]; - ut8 lastsz; - ut64 reilNextTemp; // Used to store the index of the next REIL temp register to be used. - ut64 addr; // Used for instruction sequencing. Check esil2reil.c for details. - ut8 seq_num; // Incremented and used when noInc is set to 1. - int skip; - int cmd_count; - char if_buf[64]; - char pc[8]; -} RAnalReil; - -// must be a char -#define ESIL_INTERNAL_PREFIX '$' -#define ESIL_STACK_NAME "esil.ram" -#define ESIL struct r_anal_esil_t - -typedef struct r_anal_esil_source_t { - ut32 id; - ut32 claimed; - void *content; -} RAnalEsilSource; - -R_API void r_anal_esil_sources_init(ESIL *esil); -R_API ut32 r_anal_esil_load_source(ESIL *esil, const char *path); -R_API void *r_anal_esil_get_source(ESIL *esil, ut32 src_id); -R_API bool r_anal_esil_claim_source(ESIL *esil, ut32 src_id); -R_API void r_anal_esil_release_source(ESIL *esil, ut32 src_id); -R_API void r_anal_esil_sources_fini(ESIL *esil); - -typedef bool (*RAnalEsilInterruptCB)(ESIL *esil, ut32 interrupt, void *user); - -typedef struct r_anal_esil_interrupt_handler_t { - const ut32 num; - const char* name; - void *(*init)(ESIL *esil); - RAnalEsilInterruptCB cb; - void (*fini)(void *user); -} RAnalEsilInterruptHandler; - -typedef struct r_anal_esil_interrupt_t { - RAnalEsilInterruptHandler *handler; - void *user; - ut32 src_id; -} RAnalEsilInterrupt; - -typedef struct r_anal_esil_change_reg_t { - int idx; - ut64 data; -} RAnalEsilRegChange; - -typedef struct r_anal_esil_change_mem_t { - int idx; - ut8 data; -} RAnalEsilMemChange; - -typedef struct r_anal_esil_trace_t { - int idx; - int end_idx; - HtUP *registers; - HtUP *memory; - RRegArena *arena[R_REG_TYPE_LAST]; - ut64 stack_addr; - ut64 stack_size; - ut8 *stack_data; - //TODO remove `db` and reuse info above - Sdb *db; -} RAnalEsilTrace; - -typedef int (*RAnalEsilHookRegWriteCB)(ESIL *esil, const char *name, ut64 *val); - -typedef struct r_anal_esil_callbacks_t { - void *user; - /* callbacks */ - int (*hook_flag_read)(ESIL *esil, const char *flag, ut64 *num); - int (*hook_command)(ESIL *esil, const char *op); - int (*hook_mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len); - int (*mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len); - int (*hook_mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len); - int (*mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len); - int (*hook_reg_read)(ESIL *esil, const char *name, ut64 *res, int *size); - int (*reg_read)(ESIL *esil, const char *name, ut64 *res, int *size); - RAnalEsilHookRegWriteCB hook_reg_write; - int (*reg_write)(ESIL *esil, const char *name, ut64 val); -} RAnalEsilCallbacks; - -typedef struct r_anal_esil_t { - RAnal *anal; - char **stack; - ut64 addrmask; - int stacksize; - int stackptr; - ut32 skip; - int nowrite; - int iotrap; - int exectrap; - int repeat; - int parse_stop; - int parse_goto; - int parse_goto_count; - int verbose; - ut64 flags; - ut64 address; - ut64 stack_addr; - ut32 stack_size; - int delay; // mapped to $ds in ESIL - ut64 jump_target; // mapped to $jt in ESIL - int jump_target_set; // mapped to $js in ESIL - int trap; - ut32 trap_code; // extend into a struct to store more exception info? - // parity flag? done with cur - ut64 old; //used for carry-flagging and borrow-flagging - ut64 cur; //used for carry-flagging and borrow-flagging - ut8 lastsz; //in bits //used for signature-flag - /* native ops and custom ops */ - HtPP *ops; - char *current_opstr; - RIDStorage *sources; - SdbMini *interrupts; - //this is a disgusting workaround, because we have no ht-like storage without magic keys, that you cannot use, with int-keys - RAnalEsilInterrupt *intr0; - /* deep esil parsing fills this */ - Sdb *stats; - RAnalEsilTrace *trace; - RAnalEsilCallbacks cb; - RAnalReil *Reil; - // this is so cursed, can we please remove external commands from esil internals. - // Function pointers are fine, but not commands - char *cmd_step; // r2 (external) command to run before a step is performed - char *cmd_step_out; // r2 (external) command to run after a step is performed - char *cmd_intr; // r2 (external) command to run when an interrupt occurs - char *cmd_trap; // r2 (external) command to run when a trap occurs - char *cmd_mdev; // r2 (external) command to run when an memory mapped device address is used - char *cmd_todo; // r2 (external) command to run when esil expr contains TODO - char *cmd_ioer; // r2 (external) command to run when esil fails to IO - char *mdev_range; // string containing the r_str_range to match for read/write accesses - bool (*cmd)(ESIL *esil, const char *name, ut64 a0, ut64 a1); - void *user; - int stack_fd; // ahem, let's not do this -} RAnalEsil; - -#undef ESIL - - -enum { - R_ANAL_ESIL_OP_TYPE_UNKNOWN = 0x1, - R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW, - R_ANAL_ESIL_OP_TYPE_MEM_READ = 0x4, - R_ANAL_ESIL_OP_TYPE_MEM_WRITE = 0x8, - R_ANAL_ESIL_OP_TYPE_REG_WRITE = 0x10, - R_ANAL_ESIL_OP_TYPE_MATH = 0x20, - R_ANAL_ESIL_OP_TYPE_CUSTOM = 0x40 -}; - - -typedef bool (*RAnalEsilOpCb)(RAnalEsil *esil); - -typedef struct r_anal_esil_operation_t { - RAnalEsilOpCb code; - ut32 push; // amount of operands pushed - ut32 pop; // amount of operands popped - ut32 type; -} RAnalEsilOp; - - -// this is 80-bit offsets so we can address every piece of esil in an instruction -typedef struct r_anal_esil_expr_offset_t { - ut64 off; - ut16 idx; -} RAnalEsilEOffset; - -typedef enum { - R_ANAL_ESIL_BLOCK_ENTER_NORMAL = 0, - R_ANAL_ESIL_BLOCK_ENTER_TRUE, - R_ANAL_ESIL_BLOCK_ENTER_FALSE, - R_ANAL_ESIL_BLOCK_ENTER_GLUE, -} RAnalEsilBlockEnterType; - -typedef struct r_anal_esil_basic_block_t { - RAnalEsilEOffset first; - RAnalEsilEOffset last; - char *expr; //synthesized esil-expression for this block - RAnalEsilBlockEnterType enter; //maybe more type is needed here -} RAnalEsilBB; - -typedef struct r_anal_esil_cfg_t { - RGraphNode *start; - RGraphNode *end; - RGraph *g; -} RAnalEsilCFG; - -typedef enum { - R_ANAL_ESIL_DFG_BLOCK_CONST = 1, - R_ANAL_ESIL_DFG_BLOCK_VAR = 2, - R_ANAL_ESIL_DFG_BLOCK_PTR = 4, - R_ANAL_ESIL_DFG_BLOCK_RESULT = 8, - R_ANAL_ESIL_DFG_BLOCK_GENERATIVE = 16, -} RAnalEsilDFGBlockType; - -typedef struct r_anal_esil_dfg_t { - ut32 idx; - Sdb *regs; //resolves regnames to intervals - RContRBTree *reg_vars; //vars represented in regs - RQueue *todo; //todo-queue allocated in this struct for perf - void *insert; //needed for setting regs in dfg - RGraph *flow; - RGraphNode *cur; - RGraphNode *old; - bool malloc_failed; -} RAnalEsilDFG; - -typedef struct r_anal_esil_dfg_node_t { - // add more info here - ut32 idx; - RStrBuf *content; - RAnalEsilDFGBlockType type; -} RAnalEsilDFGNode; - -typedef int (*RAnalCmdExt)(/* Rcore */RAnal *anal, const char* input); - -// TODO: rm data + len -typedef int (*RAnalOpCallback)(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask); - -typedef bool (*RAnalRegProfCallback)(RAnal *a); -typedef char*(*RAnalRegProfGetCallback)(RAnal *a); -typedef int (*RAnalFPBBCallback)(RAnal *a, RAnalBlock *bb); -typedef int (*RAnalFPFcnCallback)(RAnal *a, RAnalFunction *fcn); -typedef int (*RAnalDiffBBCallback)(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2); -typedef int (*RAnalDiffFcnCallback)(RAnal *anal, RList *fcns, RList *fcns2); -typedef int (*RAnalDiffEvalCallback)(RAnal *anal); - -typedef int (*RAnalEsilCB)(RAnalEsil *esil); -typedef int (*RAnalEsilLoopCB)(RAnalEsil *esil, RAnalOp *op); -typedef int (*RAnalEsilTrapCB)(RAnalEsil *esil, int trap_type, int trap_code); - -typedef struct r_anal_plugin_t { - char *name; - char *desc; - char *license; - char *arch; - char *author; - char *version; - int bits; - int esil; // can do esil or not - int fileformat_type; - int (*init)(void *user); - int (*fini)(void *user); - //int (*reset_counter) (RAnal *anal, ut64 start_addr); - int (*archinfo)(RAnal *anal, int query); - ut8* (*anal_mask)(RAnal *anal, int size, const ut8 *data, ut64 at); - RList* (*preludes)(RAnal *anal); - - // legacy r_anal_functions - RAnalOpCallback op; - - // command extension to directly call any analysis functions - RAnalCmdExt cmd_ext; - - RAnalRegProfCallback set_reg_profile; - RAnalRegProfGetCallback get_reg_profile; - RAnalFPBBCallback fingerprint_bb; - RAnalFPFcnCallback fingerprint_fcn; - RAnalDiffBBCallback diff_bb; - RAnalDiffFcnCallback diff_fcn; - RAnalDiffEvalCallback diff_eval; - - RAnalEsilCB esil_init; // initialize esil-related stuff - RAnalEsilLoopCB esil_post_loop; //cycle-counting, firing interrupts, ... - RAnalEsilTrapCB esil_trap; // traps / exceptions - RAnalEsilCB esil_fini; // deinitialize -} RAnalPlugin; - -/*----------------------------------------------------------------------------------------------*/ -int * (r_anal_compare) (RAnalFunction , RAnalFunction ); -/*----------------------------------------------------------------------------------------------*/ - -#ifdef R_API -/* --------- */ /* REFACTOR */ /* ---------- */ -R_API RListRange* r_listrange_new (void); -R_API void r_listrange_free(RListRange *s); -R_API void r_listrange_add(RListRange *s, RAnalFunction *f); -R_API void r_listrange_del(RListRange *s, RAnalFunction *f); -R_API void r_listrange_resize(RListRange *s, RAnalFunction *f, int newsize); -R_API RAnalFunction *r_listrange_find_in_range(RListRange* s, ut64 addr); -R_API RAnalFunction *r_listrange_find_root(RListRange* s, ut64 addr); -/* --------- */ /* REFACTOR */ /* ---------- */ -/* type.c */ -R_API RAnalType *r_anal_type_new(void); -R_API void r_anal_type_add(RAnal *l, RAnalType *t); -R_API RAnalType *r_anal_type_find(RAnal *a, const char* name); -R_API void r_anal_type_list(RAnal *a, short category, short enabled); -R_API const char *r_anal_datatype_to_string(RAnalDataType t); -R_API RAnalType *r_anal_str_to_type(RAnal *a, const char* s); -R_API bool r_anal_op_nonlinear(int t); -R_API bool r_anal_op_ismemref(int t); -R_API const char *r_anal_optype_to_string(int t); -R_API int r_anal_optype_from_string(const char *type); -R_API const char *r_anal_op_family_to_string (int n); -R_API int r_anal_op_family_from_string(const char *f); -R_API int r_anal_op_hint(RAnalOp *op, RAnalHint *hint); -R_API RAnalType *r_anal_type_free(RAnalType *t); -R_API RAnalType *r_anal_type_loadfile(RAnal *a, const char *path); - -/* block.c */ -typedef bool (*RAnalBlockCb)(RAnalBlock *block, void *user); -typedef bool (*RAnalAddrCb)(ut64 addr, void *user); - -// lifetime -R_API void r_anal_block_ref(RAnalBlock *bb); -R_API void r_anal_block_unref(RAnalBlock *bb); - -// Create one block covering the given range. -// This will fail if the range overlaps any existing blocks. -R_API RAnalBlock *r_anal_create_block(RAnal *anal, ut64 addr, ut64 size); - -static inline bool r_anal_block_contains(RAnalBlock *bb, ut64 addr) { - return addr >= bb->addr && addr < bb->addr + bb->size; -} - -// Split the block at the given address into two blocks. -// bb will stay the first block, the second block will be returned (or NULL on failure) -// The returned block will always be refd, i.e. it is necessary to always call r_anal_block_unref() on the return value! -R_API RAnalBlock *r_anal_block_split(RAnalBlock *bb, ut64 addr); - -static inline bool r_anal_block_is_contiguous(RAnalBlock *a, RAnalBlock *b) { - return (a->addr + a->size) == b->addr; -} - -// Merge block b into a. -// b will be FREED (not just unrefd) and is NOT VALID anymore if this function is successful! -// This only works if b follows directly after a and their function lists are identical. -// returns true iff the blocks could be merged -R_API bool r_anal_block_merge(RAnalBlock *a, RAnalBlock *b); - -// Manually delete a block and remove it from all its functions -// If there are more references to it than from its functions only, it will not be removed immediately! -R_API void r_anal_delete_block(RAnalBlock *bb); - -R_API void r_anal_block_set_size(RAnalBlock *block, ut64 size); - -// Set the address and size of the block. -// This can fail (and return false) if there is already another block at the new address -R_API bool r_anal_block_relocate(RAnalBlock *block, ut64 addr, ut64 size); - -R_API RAnalBlock *r_anal_get_block_at(RAnal *anal, ut64 addr); -R_API bool r_anal_blocks_foreach_in(RAnal *anal, ut64 addr, RAnalBlockCb cb, void *user); -R_API RList *r_anal_get_blocks_in(RAnal *anal, ut64 addr); // values from r_anal_blocks_foreach_in as a list -R_API void r_anal_blocks_foreach_intersect(RAnal *anal, ut64 addr, ut64 size, RAnalBlockCb cb, void *user); -R_API RList *r_anal_get_blocks_intersect(RAnal *anal, ut64 addr, ut64 size); // values from r_anal_blocks_foreach_intersect as a list - -// Call cb on every direct successor address of block -// returns false if the loop was breaked by cb -R_API bool r_anal_block_successor_addrs_foreach(RAnalBlock *block, RAnalAddrCb cb, void *user); - -// Call cb on block and every (recursive) successor of it -// returns false if the loop was breaked by cb -R_API bool r_anal_block_recurse(RAnalBlock *block, RAnalBlockCb cb, void *user); - -// Call cb on block and every (recursive) successor of it -// If cb returns false, recursion stops only for that block -// returns false if the loop was breaked by cb -R_API bool r_anal_block_recurse_followthrough(RAnalBlock *block, RAnalBlockCb cb, void *user); - -// Call cb on block and every (recursive) successor of it -// Call on_exit on block that doesn't have non-visited successors -// returns false if the loop was breaked by cb -R_API bool r_anal_block_recurse_depth_first(RAnalBlock *block, RAnalBlockCb cb, R_NULLABLE RAnalBlockCb on_exit, void *user); - -// same as r_anal_block_recurse, but returns the blocks as a list -R_API RList *r_anal_block_recurse_list(RAnalBlock *block); - -// return one shortest path from block to dst or NULL if none exists. -R_API R_NULLABLE RList/**/ *r_anal_block_shortest_path(RAnalBlock *block, ut64 dst); - -// Add a case to the block's switch_op. -// If block->switch_op is NULL, it will be created with the given switch_addr. -R_API void r_anal_block_add_switch_case(RAnalBlock *block, ut64 switch_addr, ut64 case_value, ut64 case_addr); - -// Chop off the block at the specified address and remove all destinations. -// Blocks that have become unreachable after this operation will be automatically removed from all functions of block. -// addr must be the address directly AFTER the noreturn call! -// After the chopping, an r_anal_block_automerge() is performed on the touched blocks. -// IMPORTANT: The automerge might also FREE block! This function returns block iff it is still valid afterwards. -// If this function returns NULL, the pointer to block MUST not be touched anymore! -R_API RAnalBlock *r_anal_block_chop_noreturn(RAnalBlock *block, ut64 addr); - -// Merge every block in blocks with their contiguous predecessor, if possible. -// IMPORTANT: Merged blocks will be FREED! The blocks list will be updated to contain only the survived blocks. -R_API void r_anal_block_automerge(RList *blocks); - -// return true iff an instruction in the given basic block starts at the given address -R_API bool r_anal_block_op_starts_at(RAnalBlock *block, ut64 addr); - -// --------------------------------------- - -/* function.c */ - -R_API RAnalFunction *r_anal_function_new(RAnal *anal); -R_API void r_anal_function_free(void *fcn); - -// Add a function created with r_anal_function_new() to anal -R_API bool r_anal_add_function(RAnal *anal, RAnalFunction *fcn); - -// Create a new function and add it to anal (r_anal_function_new() + set members + r_anal_add_function()) -R_API RAnalFunction *r_anal_create_function(RAnal *anal, const char *name, ut64 addr, int type, RAnalDiff *diff); - -// returns all functions that have a basic block containing the given address -R_API RList *r_anal_get_functions_in(RAnal *anal, ut64 addr); - -// returns the function that has its entrypoint at addr or NULL -R_API RAnalFunction *r_anal_get_function_at(RAnal *anal, ut64 addr); - -R_API bool r_anal_function_delete(RAnalFunction *fcn); - -// rhange the entrypoint of fcn -// This can fail (and return false) if there is already another function at the new address -R_API bool r_anal_function_relocate(RAnalFunction *fcn, ut64 addr); - -// rename the given function -// This can fail (and return false) if there is another function with the name given -R_API bool r_anal_function_rename(RAnalFunction *fcn, const char *name); - -R_API void r_anal_function_add_block(RAnalFunction *fcn, RAnalBlock *bb); -R_API void r_anal_function_remove_block(RAnalFunction *fcn, RAnalBlock *bb); - - -// size of the entire range that the function spans, including holes. -// this is exactly r_anal_function_max_addr() - r_anal_function_min_addr() -R_API ut64 r_anal_function_linear_size(RAnalFunction *fcn); - -// lowest address covered by the function -R_API ut64 r_anal_function_min_addr(RAnalFunction *fcn); - -// first address directly after the function -R_API ut64 r_anal_function_max_addr(RAnalFunction *fcn); - -// size from the function entrypoint (fcn->addr) to the end of the function (r_anal_function_max_addr) -R_API ut64 r_anal_function_size_from_entry(RAnalFunction *fcn); - -// the "real" size of the function, that is the sum of the size of the -// basicblocks this function is composed of -R_API ut64 r_anal_function_realsize(const RAnalFunction *fcn); - -// returns whether the function contains a basic block that contains addr -// This is completely independent of fcn->addr, which is only the entrypoint! -R_API bool r_anal_function_contains(RAnalFunction *fcn, ut64 addr); - -/* anal.c */ -R_API RAnal *r_anal_new(void); -R_API void r_anal_purge(RAnal *anal); -R_API RAnal *r_anal_free(RAnal *r); -R_API void r_anal_set_user_ptr(RAnal *anal, void *user); -R_API void r_anal_plugin_free (RAnalPlugin *p); -R_API int r_anal_add(RAnal *anal, RAnalPlugin *foo); -R_API int r_anal_archinfo(RAnal *anal, int query); -R_API bool r_anal_use(RAnal *anal, const char *name); -R_API bool r_anal_set_reg_profile(RAnal *anal); -R_API char *r_anal_get_reg_profile(RAnal *anal); -R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr); -R_API bool r_anal_set_bits(RAnal *anal, int bits); -R_API bool r_anal_set_os(RAnal *anal, const char *os); -R_API void r_anal_set_cpu(RAnal *anal, const char *cpu); -R_API int r_anal_set_big_endian(RAnal *anal, int boolean); -R_API ut8 *r_anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at); -R_API void r_anal_trace_bb(RAnal *anal, ut64 addr); -R_API const char *r_anal_fcntype_tostring(int type); -R_API int r_anal_fcn_bb (RAnal *anal, RAnalFunction *fcn, ut64 addr, int depth); -R_API void r_anal_bind(RAnal *b, RAnalBind *bnd); -R_API bool r_anal_set_triplet(RAnal *anal, const char *os, const char *arch, int bits); -R_API void r_anal_add_import(RAnal *anal, const char *imp); -R_API void r_anal_remove_import(RAnal *anal, const char *imp); -R_API void r_anal_purge_imports(RAnal *anal); - -/* bb.c */ -R_API RAnalBlock *r_anal_bb_from_offset(RAnal *anal, ut64 off); -R_API bool r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v); -R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i); -R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i); -R_API ut64 r_anal_bb_opaddr_at(RAnalBlock *bb, ut64 addr); -R_API ut64 r_anal_bb_size_i(RAnalBlock *bb, int i); - -/* op.c */ -R_API const char *r_anal_stackop_tostring(int s); -R_API RAnalOp *r_anal_op_new(void); -R_API void r_anal_op_free(void *op); -R_API void r_anal_op_init(RAnalOp *op); -R_API bool r_anal_op_fini(RAnalOp *op); -R_API int r_anal_op_reg_delta(RAnal *anal, ut64 addr, const char *name); -R_API bool r_anal_op_is_eob(RAnalOp *op); -R_API RList *r_anal_op_list_new(void); -R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask); -R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr, const char *hexstr); -R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op); - -R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize); -R_API bool r_anal_esil_set_pc(RAnalEsil *esil, ut64 addr); -R_API bool r_anal_esil_setup(RAnalEsil *esil, RAnal *anal, int romem, int stats, int nonull); -R_API void r_anal_esil_free(RAnalEsil *esil); -R_API bool r_anal_esil_runword(RAnalEsil *esil, const char *word); -R_API bool r_anal_esil_parse(RAnalEsil *esil, const char *str); -R_API bool r_anal_esil_dumpstack(RAnalEsil *esil); -R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len); -R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len); -R_API int r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size); -R_API int r_anal_esil_reg_write(RAnalEsil *esil, const char *dst, ut64 num); -R_API bool r_anal_esil_pushnum(RAnalEsil *esil, ut64 num); -R_API bool r_anal_esil_push(RAnalEsil *esil, const char *str); -R_API char *r_anal_esil_pop(RAnalEsil *esil); -R_API bool r_anal_esil_set_op(RAnalEsil *esil, const char *op, RAnalEsilOpCb code, ut32 push, ut32 pop, ut32 type); -R_API void r_anal_esil_stack_free(RAnalEsil *esil); -R_API int r_anal_esil_get_parm_type(RAnalEsil *esil, const char *str); -R_API int r_anal_esil_get_parm(RAnalEsil *esil, const char *str, ut64 *num); -R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str); - -// esil_interrupt.c -R_API void r_anal_esil_interrupts_init(RAnalEsil *esil); -R_API RAnalEsilInterrupt *r_anal_esil_interrupt_new(RAnalEsil *esil, ut32 src_id, RAnalEsilInterruptHandler *ih); -R_API void r_anal_esil_interrupt_free(RAnalEsil *esil, RAnalEsilInterrupt *intr); -R_API bool r_anal_esil_set_interrupt(RAnalEsil *esil, RAnalEsilInterrupt *intr); -R_API int r_anal_esil_fire_interrupt(RAnalEsil *esil, ut32 intr_num); -R_API bool r_anal_esil_load_interrupts(RAnalEsil *esil, RAnalEsilInterruptHandler **handlers, ut32 src_id); -R_API bool r_anal_esil_load_interrupts_from_lib(RAnalEsil *esil, const char *path); -R_API void r_anal_esil_interrupts_fini(RAnalEsil *esil); - -R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly); -R_API void r_anal_esil_stats(RAnalEsil *esil, int enable); - -/* trace */ -R_API RAnalEsilTrace *r_anal_esil_trace_new(RAnalEsil *esil); -R_API void r_anal_esil_trace_free(RAnalEsilTrace *trace); -R_API void r_anal_esil_trace_op(RAnalEsil *esil, RAnalOp *op); -R_API void r_anal_esil_trace_list(RAnalEsil *esil); -R_API void r_anal_esil_trace_show(RAnalEsil *esil, int idx); -R_API void r_anal_esil_trace_restore(RAnalEsil *esil, int idx); - -/* pin */ -R_API void r_anal_pin_init(RAnal *a); -R_API void r_anal_pin_fini(RAnal *a); -R_API void r_anal_pin(RAnal *a, ut64 addr, const char *name); -R_API void r_anal_pin_unset(RAnal *a, ut64 addr); -R_API const char *r_anal_pin_call(RAnal *a, ut64 addr); -R_API void r_anal_pin_list(RAnal *a); - -/* fcn.c */ -R_API ut32 r_anal_function_cost(RAnalFunction *fcn); -R_API int r_anal_function_count_edges(const RAnalFunction *fcn, R_NULLABLE int *ebbs); - -// Use r_anal_get_functions_in¿() instead -R_DEPRECATE R_API RAnalFunction *r_anal_get_fcn_in(RAnal *anal, ut64 addr, int type); -R_DEPRECATE R_API RAnalFunction *r_anal_get_fcn_in_bounds(RAnal *anal, ut64 addr, int type); - -R_API RAnalFunction *r_anal_get_function_byname(RAnal *anal, const char *name); - -R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int reftype); -R_API int r_anal_fcn_del(RAnal *anal, ut64 addr); -R_API int r_anal_fcn_del_locs(RAnal *anal, ut64 addr); -R_API bool r_anal_fcn_add_bb(RAnal *anal, RAnalFunction *fcn, - ut64 addr, ut64 size, - ut64 jump, ut64 fail, R_BORROW RAnalDiff *diff); -R_API bool r_anal_check_fcn(RAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 low, ut64 high); -R_API void r_anal_fcn_invalidate_read_ahead_cache(void); - -R_API void r_anal_function_check_bp_use(RAnalFunction *fcn); - - -#define R_ANAL_FCN_VARKIND_LOCAL 'v' - - -R_API int r_anal_fcn_var_del_byindex (RAnal *a, ut64 fna, const char kind, int scope, ut32 idx); -/* args */ -R_API int r_anal_var_count(RAnal *a, RAnalFunction *fcn, int kind, int type); - -/* vars // globals. not here */ -R_API bool r_anal_var_display(RAnal *anal, RAnalVar *var); - -R_API int r_anal_function_complexity(RAnalFunction *fcn); -R_API int r_anal_function_loops(RAnalFunction *fcn); -R_API void r_anal_trim_jmprefs(RAnal *anal, RAnalFunction *fcn); -R_API void r_anal_del_jmprefs(RAnal *anal, RAnalFunction *fcn); -R_API char *r_anal_function_get_json(RAnalFunction *function); -R_API RAnalFunction *r_anal_fcn_next(RAnal *anal, ut64 addr); -R_API char *r_anal_function_get_signature(RAnalFunction *function); -R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *_str); -R_API int r_anal_fcn_count (RAnal *a, ut64 from, ut64 to); -R_API RAnalBlock *r_anal_fcn_bbget_in(const RAnal *anal, RAnalFunction *fcn, ut64 addr); -R_API RAnalBlock *r_anal_fcn_bbget_at(RAnal *anal, RAnalFunction *fcn, ut64 addr); -R_API bool r_anal_fcn_bbadd(RAnalFunction *fcn, RAnalBlock *bb); -R_API int r_anal_function_resize(RAnalFunction *fcn, int newsize); -R_API bool r_anal_function_purity(RAnalFunction *fcn); - -typedef bool (* RAnalRefCmp)(RAnalRef *ref, void *data); -R_API RList *r_anal_ref_list_new(void); -R_API ut64 r_anal_xrefs_count(RAnal *anal); -R_API const char *r_anal_xrefs_type_tostring(RAnalRefType type); -R_API RAnalRefType r_anal_xrefs_type(char ch); -R_API RList *r_anal_xrefs_get(RAnal *anal, ut64 to); -R_API RList *r_anal_refs_get(RAnal *anal, ut64 to); -R_API RList *r_anal_xrefs_get_from(RAnal *anal, ut64 from); -R_API void r_anal_xrefs_list(RAnal *anal, int rad); -R_API RList *r_anal_function_get_refs(RAnalFunction *fcn); -R_API RList *r_anal_function_get_xrefs(RAnalFunction *fcn); -R_API int r_anal_xrefs_from(RAnal *anal, RList *list, const char *kind, const RAnalRefType type, ut64 addr); -R_API int r_anal_xrefs_set(RAnal *anal, ut64 from, ut64 to, const RAnalRefType type); -R_API int r_anal_xrefs_deln(RAnal *anal, ut64 from, ut64 to, const RAnalRefType type); -R_API int r_anal_xref_del(RAnal *anal, ut64 at, ut64 addr); - -R_API RList *r_anal_get_fcns(RAnal *anal); - -/* type.c */ -R_API void r_anal_remove_parsed_type(RAnal *anal, const char *name); -R_API void r_anal_save_parsed_type(RAnal *anal, const char *parsed); - -/* var.c */ -R_API R_OWN char *r_anal_function_autoname_var(RAnalFunction *fcn, char kind, const char *pfx, int ptr); -R_API R_BORROW RAnalVar *r_anal_function_set_var(RAnalFunction *fcn, int delta, char kind, R_NULLABLE const char *type, int size, bool isarg, R_NONNULL const char *name); -R_API R_BORROW RAnalVar *r_anal_function_get_var(RAnalFunction *fcn, char kind, int delta); -R_API R_BORROW RAnalVar *r_anal_function_get_var_byname(RAnalFunction *fcn, const char *name); -R_API void r_anal_function_delete_vars_by_kind(RAnalFunction *fcn, RAnalVarKind kind); -R_API void r_anal_function_delete_all_vars(RAnalFunction *fcn); -R_API void r_anal_function_delete_var(RAnalFunction *fcn, RAnalVar *var); -R_API bool r_anal_function_rebase_vars(RAnal *a, RAnalFunction *fcn); -R_API st64 r_anal_function_get_var_stackptr_at(RAnalFunction *fcn, st64 delta, ut64 addr); -R_API const char *r_anal_function_get_var_reg_at(RAnalFunction *fcn, st64 delta, ut64 addr); -R_API R_BORROW RPVector *r_anal_function_get_vars_used_at(RAnalFunction *fcn, ut64 op_addr); - -// There could be multiple vars used in multiple functions. Use r_anal_get_functions_in()+r_anal_function_get_vars_used_at() instead. -R_API R_DEPRECATE RAnalVar *r_anal_get_used_function_var(RAnal *anal, ut64 addr); - -R_API bool r_anal_var_rename(RAnalVar *var, const char *new_name, bool verbose); -R_API void r_anal_var_set_type(RAnalVar *var, const char *type); -R_API void r_anal_var_delete(RAnalVar *var); -R_API ut64 r_anal_var_addr(RAnalVar *var); -R_API void r_anal_var_set_access(RAnalVar *var, const char *reg, ut64 access_addr, int access_type, st64 stackptr); -R_API void r_anal_var_remove_access_at(RAnalVar *var, ut64 address); -R_API void r_anal_var_clear_accesses(RAnalVar *var); -R_API void r_anal_var_add_constraint(RAnalVar *var, R_BORROW RAnalVarConstraint *constraint); -R_API char *r_anal_var_get_constraints_readable(RAnalVar *var); - -// Get the access to var at exactly addr if there is one -R_API RAnalVarAccess *r_anal_var_get_access_at(RAnalVar *var, ut64 addr); - -R_API int r_anal_var_get_argnum(RAnalVar *var); - -R_API void r_anal_extract_vars(RAnal *anal, RAnalFunction *fcn, RAnalOp *op); -R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int *reg_set, int *count); - -// Get the variable that var is written to at one of its accesses -// Useful for cases where a register-based argument is written away into a stack variable, -// so if var is the reg arg then this will return the stack var. -R_API RAnalVar *r_anal_var_get_dst_var(RAnalVar *var); - -typedef struct r_anal_fcn_vars_cache { - RList *bvars; - RList *rvars; - RList *svars; -} RAnalFcnVarsCache; -R_API void r_anal_fcn_vars_cache_init(RAnal *anal, RAnalFcnVarsCache *cache, RAnalFunction *fcn); -R_API void r_anal_fcn_vars_cache_fini(RAnalFcnVarsCache *cache); - -R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction *fcn, R_NULLABLE char *fcn_name, - R_NULLABLE RAnalFcnVarsCache *reuse_cache, R_NULLABLE const char *fcn_name_pre, R_NULLABLE const char *fcn_name_post); - - -/* project */ -R_API bool r_anal_xrefs_init (RAnal *anal); - -#define R_ANAL_THRESHOLDFCN 0.7F -#define R_ANAL_THRESHOLDBB 0.7F - -/* diff.c */ -R_API RAnalDiff *r_anal_diff_new(void); -R_API void r_anal_diff_setup(RAnal *anal, int doops, double thbb, double thfcn); -R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn); -R_API void* r_anal_diff_free(RAnalDiff *diff); -R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb); -R_API size_t r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn); -R_API bool r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2); -R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2); -R_API int r_anal_diff_eval(RAnal *anal); - -/* value.c */ -R_API RAnalValue *r_anal_value_new(void); -R_API RAnalValue *r_anal_value_copy (RAnalValue *ov); -R_API RAnalValue *r_anal_value_new_from_string(const char *str); -R_API st64 r_anal_value_eval(RAnalValue *value); -R_API char *r_anal_value_to_string (RAnalValue *value); -R_API ut64 r_anal_value_to_ut64(RAnal *anal, RAnalValue *val); -R_API int r_anal_value_set_ut64(RAnal *anal, RAnalValue *val, ut64 num); -R_API void r_anal_value_free(RAnalValue *value); - -R_API RAnalCond *r_anal_cond_new(void); -R_API RAnalCond *r_anal_cond_new_from_op(RAnalOp *op); -R_API void r_anal_cond_fini(RAnalCond *c); -R_API void r_anal_cond_free(RAnalCond *c); -R_API char *r_anal_cond_to_string(RAnalCond *cond); -R_API int r_anal_cond_eval(RAnal *anal, RAnalCond *cond); -R_API RAnalCond *r_anal_cond_new_from_string(const char *str); -R_API const char *r_anal_cond_tostring(int cc); - -/* jmptbl */ -R_API bool r_anal_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, ut64 jmpaddr, ut64 table, ut64 tablesize, ut64 default_addr); - -// TODO: should be renamed -R_API bool try_get_delta_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 jmp_addr, ut64 lea_addr, ut64 *table_size, ut64 *default_case); -R_API bool try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0); -R_API bool try_walkthrough_casetbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 casetbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0); -R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnalBlock *my_bb, ut64 *table_size, ut64 *default_case); -R_API int walkthrough_arm_jmptbl_style(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 sz, ut64 jmptbl_size, ut64 default_case, int ret0); - -/* reflines.c */ -R_API RList* /**/ r_anal_reflines_get(RAnal *anal, - ut64 addr, const ut8 *buf, ut64 len, int nlines, int linesout, int linescall); -R_API int r_anal_reflines_middle(RAnal *anal, RList *list, ut64 addr, int len); -R_API RAnalRefStr *r_anal_reflines_str(void *core, ut64 addr, int opts); -R_API void r_anal_reflines_str_free(RAnalRefStr *refstr); -/* TODO move to r_core */ -R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int mode, PJ* pj); -R_API RList *r_anal_var_list(RAnal *anal, RAnalFunction *fcn, int kind); -R_API R_DEPRECATE RList/**/ *r_anal_var_all_list(RAnal *anal, RAnalFunction *fcn); -R_API R_DEPRECATE RList/**/ *r_anal_function_get_var_fields(RAnalFunction *fcn, int kind); - -// calling conventions API -R_API bool r_anal_cc_exist(RAnal *anal, const char *convention); -R_API void r_anal_cc_del(RAnal *anal, const char *name); -R_API bool r_anal_cc_set(RAnal *anal, const char *expr); -R_API char *r_anal_cc_get(RAnal *anal, const char *name); -R_API const char *r_anal_cc_arg(RAnal *anal, const char *convention, int n); -R_API const char *r_anal_cc_self(RAnal *anal, const char *convention); -R_API void r_anal_cc_set_self(RAnal *anal, const char *convention, const char *self); -R_API const char *r_anal_cc_error(RAnal *anal, const char *convention); -R_API void r_anal_cc_set_error(RAnal *anal, const char *convention, const char *error); -R_API int r_anal_cc_max_arg(RAnal *anal, const char *cc); -R_API const char *r_anal_cc_ret(RAnal *anal, const char *convention); -R_API const char *r_anal_cc_default(RAnal *anal); -R_API const char *r_anal_cc_func(RAnal *anal, const char *func_name); -R_API bool r_anal_noreturn_at(RAnal *anal, ut64 addr); - -typedef struct r_anal_data_t { - ut64 addr; - int type; - ut64 ptr; - char *str; - int len; - ut8 *buf; - ut8 sbuf[8]; -} RAnalData; - -R_API RAnalData *r_anal_data (RAnal *anal, ut64 addr, const ut8 *buf, int size, int wordsize); -R_API const char *r_anal_data_kind (RAnal *anal, ut64 addr, const ut8 *buf, int len); -R_API RAnalData *r_anal_data_new_string (ut64 addr, const char *p, int size, int wide); -R_API RAnalData *r_anal_data_new (ut64 addr, int type, ut64 n, const ut8 *buf, int len); -R_API void r_anal_data_free (RAnalData *d); -#include -R_API char *r_anal_data_to_string(RAnalData *d, RConsPrintablePalette *pal); - -/* meta - * - * Meta uses Condret's Klemmbaustein Priciple, i.e. intervals are defined inclusive/inclusive. - * A meta item from 0x42 to 0x42 has a size of 1. Items with size 0 do not exist. - * Meta items are allowed to overlap and the internal data structure allows for multiple meta items - * starting at the same address. - * Meta items are saved in an RIntervalTree. To access the interval of an item, use the members of RIntervalNode. - */ - -static inline ut64 r_meta_item_size(ut64 start, ut64 end) { - // meta items use inclusive/inclusive intervals - return end - start + 1; -} - -static inline ut64 r_meta_node_size(RIntervalNode *node) { - return r_meta_item_size (node->start, node->end); -} - -// Set a meta item at addr with the given contents in the current space. -// If there already exists an item with this type and space at addr (regardless of its size) it will be overwritten. -R_API bool r_meta_set(RAnal *a, RAnalMetaType type, ut64 addr, ut64 size, const char *str); - -// Same as r_meta_set() but also sets the subtype. -R_API bool r_meta_set_with_subtype(RAnal *m, RAnalMetaType type, int subtype, ut64 addr, ut64 size, const char *str); - -// Delete all meta items in the current space that intersect with the given interval. -// If size == UT64_MAX, everything in the current space will be deleted. -R_API void r_meta_del(RAnal *a, RAnalMetaType type, ut64 addr, ut64 size); - -// Same as r_meta_set() with a size of 1. -R_API bool r_meta_set_string(RAnal *a, RAnalMetaType type, ut64 addr, const char *s); - -// Convenience function to get the str content of the item at addr with given type in the current space. -R_API const char *r_meta_get_string(RAnal *a, RAnalMetaType type, ut64 addr); - -// Convenience function to add an R_META_TYPE_DATA item at the given addr in the current space. -R_API void r_meta_set_data_at(RAnal *a, ut64 addr, ut64 wordsz); - -// Returns the item with given type that starts at addr in the current space or NULL. The size of this item optionally returned through size. -R_API RAnalMetaItem *r_meta_get_at(RAnal *a, ut64 addr, RAnalMetaType type, R_OUT R_NULLABLE ut64 *size); - -// Returns the node for one meta item with the given type that contains addr in the current space or NULL. -// To get all the nodes, use r_meta_get_all_in(). -R_API RIntervalNode *r_meta_get_in(RAnal *a, ut64 addr, RAnalMetaType type); - -// Returns all nodes for items starting at the given address in the current space. -R_API RPVector/* *>*/ *r_meta_get_all_at(RAnal *a, ut64 at); - -// Returns all nodes for items with the given type containing the given address in the current space. -R_API RPVector/* *>*/ *r_meta_get_all_in(RAnal *a, ut64 at, RAnalMetaType type); - -// Returns all nodes for items with the given type intersecting the given interval in the current space. -R_API RPVector/* *>*/ *r_meta_get_all_intersect(RAnal *a, ut64 start, ut64 size, RAnalMetaType type); - -// Delete all meta items in the given space -R_API void r_meta_space_unset_for(RAnal *a, const RSpace *space); - -// Returns the number of meta items in the given space -R_API int r_meta_space_count_for(RAnal *a, const RSpace *space); - -// Shift all meta items by the given delta, for rebasing between different memory layouts. -R_API void r_meta_rebase(RAnal *anal, ut64 diff); - -// Calculate the total size covered by meta items of the given type. -R_API ut64 r_meta_get_size(RAnal *a, RAnalMetaType type); - -R_API const char *r_meta_type_to_string(int type); -R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full); -R_API void r_meta_print_list_all(RAnal *a, int type, int rad); -R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad); -R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr); - -/* hints */ - -R_API void r_anal_hint_del(RAnal *anal, ut64 addr, ut64 size); // delete all hints that are contained within the given range, if size > 1, this operation is quite heavy! -R_API void r_anal_hint_clear (RAnal *a); -R_API void r_anal_hint_free (RAnalHint *h); -R_API void r_anal_hint_set_syntax (RAnal *a, ut64 addr, const char *syn); -R_API void r_anal_hint_set_type(RAnal *a, ut64 addr, int type); -R_API void r_anal_hint_set_jump(RAnal *a, ut64 addr, ut64 jump); -R_API void r_anal_hint_set_fail(RAnal *a, ut64 addr, ut64 fail); -R_API void r_anal_hint_set_newbits(RAnal *a, ut64 addr, int bits); -R_API void r_anal_hint_set_nword(RAnal *a, ut64 addr, int nword); -R_API void r_anal_hint_set_offset(RAnal *a, ut64 addr, const char *typeoff); -R_API void r_anal_hint_set_immbase(RAnal *a, ut64 addr, int base); -R_API void r_anal_hint_set_size(RAnal *a, ut64 addr, ut64 size); -R_API void r_anal_hint_set_opcode(RAnal *a, ut64 addr, const char *str); -R_API void r_anal_hint_set_esil(RAnal *a, ut64 addr, const char *str); -R_API void r_anal_hint_set_pointer(RAnal *a, ut64 addr, ut64 ptr); -R_API void r_anal_hint_set_ret(RAnal *a, ut64 addr, ut64 val); -R_API void r_anal_hint_set_high(RAnal *a, ut64 addr); -R_API void r_anal_hint_set_stackframe(RAnal *a, ut64 addr, ut64 size); -R_API void r_anal_hint_set_val(RAnal *a, ut64 addr, ut64 v); -R_API void r_anal_hint_set_arch(RAnal *a, ut64 addr, R_NULLABLE const char *arch); // arch == NULL => use global default -R_API void r_anal_hint_set_bits(RAnal *a, ut64 addr, int bits); // bits == NULL => use global default -R_API void r_anal_hint_unset_val (RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_high(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_immbase(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_nword(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_size(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_type(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_esil(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_opcode(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_syntax(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_pointer(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_ret(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_offset(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_jump(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_fail(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_newbits(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_stackframe(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_arch(RAnal *a, ut64 addr); -R_API void r_anal_hint_unset_bits(RAnal *a, ut64 addr); -R_API R_NULLABLE const RVector/**/ *r_anal_addr_hints_at(RAnal *anal, ut64 addr); -typedef bool (*RAnalAddrHintRecordsCb)(ut64 addr, const RVector/**/ *records, void *user); -R_API void r_anal_addr_hints_foreach(RAnal *anal, RAnalAddrHintRecordsCb cb, void *user); -typedef bool (*RAnalArchHintCb)(ut64 addr, R_NULLABLE const char *arch, void *user); -R_API void r_anal_arch_hints_foreach(RAnal *anal, RAnalArchHintCb cb, void *user); -typedef bool (*RAnalBitsHintCb)(ut64 addr, int bits, void *user); -R_API void r_anal_bits_hints_foreach(RAnal *anal, RAnalBitsHintCb cb, void *user); - -// get the hint-specified arch value to be considered at addr -// hint_addr will optionally be set to the address where the hint that specifies this arch is placed or UT64_MAX -// if there is no hint affecting addr. -R_API R_NULLABLE R_BORROW const char *r_anal_hint_arch_at(RAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr); - -// get the hint-specified bits value to be considered at addr -// hint_addr will optionally be set to the address where the hint that specifies this arch is placed or UT64_MAX -// if there is no hint affecting addr. -R_API int r_anal_hint_bits_at(RAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr); - -R_API RAnalHint *r_anal_hint_get(RAnal *anal, ut64 addr); // accumulate all available hints affecting the given address - -/* switch.c APIs */ -R_API RAnalSwitchOp *r_anal_switch_op_new(ut64 addr, ut64 min_val, ut64 max_val, ut64 def_val); -R_API void r_anal_switch_op_free(RAnalSwitchOp * swop); -R_API RAnalCaseOp* r_anal_switch_op_add_case(RAnalSwitchOp * swop, ut64 addr, ut64 value, ut64 jump); - -/* cycles.c */ -R_API RAnalCycleFrame* r_anal_cycle_frame_new (void); -R_API void r_anal_cycle_frame_free (RAnalCycleFrame *cf); - -/* labels */ -R_API ut64 r_anal_function_get_label(RAnalFunction *fcn, const char *name); -R_API const char *r_anal_function_get_label_at(RAnalFunction *fcn, ut64 addr); -R_API bool r_anal_function_set_label(RAnalFunction *fcn, const char *name, ut64 addr); -R_API bool r_anal_function_delete_label(RAnalFunction *fcn, const char *name); -R_API bool r_anal_function_delete_label_at(RAnalFunction *fcn, ut64 addr); - -/* limits */ -R_API void r_anal_set_limits(RAnal *anal, ut64 from, ut64 to); -R_API void r_anal_unset_limits(RAnal *anal); - -/* ESIL to REIL */ -R_API int r_anal_esil_to_reil_setup (RAnalEsil *esil, RAnal *anal, int romem, int stats); - -/* no-return stuff */ -R_API void r_anal_noreturn_list(RAnal *anal, int mode); -R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr); -R_API bool r_anal_noreturn_drop(RAnal *anal, const char *expr); -R_API bool r_anal_noreturn_at_addr(RAnal *anal, ut64 addr); - -/* zign spaces */ -R_API int r_sign_space_count_for(RAnal *a, const RSpace *space); -R_API void r_sign_space_unset_for(RAnal *a, const RSpace *space); -R_API void r_sign_space_rename_for(RAnal *a, const RSpace *space, const char *oname, const char *nname); - -/* vtables */ -typedef struct { - RAnal *anal; - RAnalCPPABI abi; - ut8 word_size; - bool (*read_addr) (RAnal *anal, ut64 addr, ut64 *buf); -} RVTableContext; - -typedef struct vtable_info_t { - ut64 saddr; //starting address - RVector methods; -} RVTableInfo; - -typedef struct vtable_method_info_t { - ut64 addr; // addr of the function - ut64 vtable_offset; // offset inside the vtable -} RVTableMethodInfo; - -R_API void r_anal_vtable_info_free(RVTableInfo *vtable); -R_API ut64 r_anal_vtable_info_get_size(RVTableContext *context, RVTableInfo *vtable); -R_API bool r_anal_vtable_begin(RAnal *anal, RVTableContext *context); -R_API RVTableInfo *r_anal_vtable_parse_at(RVTableContext *context, ut64 addr); -R_API RList *r_anal_vtable_search(RVTableContext *context); -R_API void r_anal_list_vtables(RAnal *anal, int rad); - -/* rtti */ -R_API char *r_anal_rtti_msvc_demangle_class_name(RVTableContext *context, const char *name); -R_API void r_anal_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode); -R_API bool r_anal_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict); -R_API void r_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RList *vtables); - -R_API char *r_anal_rtti_itanium_demangle_class_name(RVTableContext *context, const char *name); -R_API void r_anal_rtti_itanium_print_class_type_info(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_itanium_print_si_class_type_info(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_itanium_print_vmi_class_type_info(RVTableContext *context, ut64 addr, int mode); -R_API bool r_anal_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode); -R_API void r_anal_rtti_itanium_recover_all(RVTableContext *vt_context, RList *vtables); - -R_API char *r_anal_rtti_demangle_class_name(RAnal *anal, const char *name); -R_API void r_anal_rtti_print_at_vtable(RAnal *anal, ut64 addr, int mode); -R_API void r_anal_rtti_print_all(RAnal *anal, int mode); -R_API void r_anal_rtti_recover_all(RAnal *anal); - -R_API void r_anal_colorize_bb(RAnal *anal, ut64 addr, ut32 color); - -R_API RList *r_anal_preludes(RAnal *anal); -R_API bool r_anal_is_prelude(RAnal *anal, const ut8 *data, int len); - -/* classes */ -typedef struct r_anal_method_t { - char *name; - ut64 addr; - st64 vtable_offset; // >= 0 if method is virtual, else -1 -} RAnalMethod; - -typedef struct r_anal_base_class_t { - char *id; // id to identify the class attr - ut64 offset; // offset of the base class inside the derived class - char *class_name; -} RAnalBaseClass; - -typedef struct r_anal_vtable_t { - char *id; // id to identify the class attr - ut64 offset; // offset inside the class - ut64 addr; // where the content of the vtable is - ut64 size; // size (in bytes) of the vtable -} RAnalVTable; - -typedef enum { - R_ANAL_CLASS_ERR_SUCCESS = 0, - R_ANAL_CLASS_ERR_CLASH, - R_ANAL_CLASS_ERR_NONEXISTENT_ATTR, - R_ANAL_CLASS_ERR_NONEXISTENT_CLASS, - R_ANAL_CLASS_ERR_OTHER -} RAnalClassErr; - -R_API void r_anal_class_create(RAnal *anal, const char *name); -R_API void r_anal_class_delete(RAnal *anal, const char *name); -R_API bool r_anal_class_exists(RAnal *anal, const char *name); -R_API SdbList *r_anal_class_get_all(RAnal *anal, bool sorted); -R_API void r_anal_class_foreach(RAnal *anal, SdbForeachCallback cb, void *user); -R_API RAnalClassErr r_anal_class_rename(RAnal *anal, const char *old_name, const char *new_name); - -R_API void r_anal_class_method_fini(RAnalMethod *meth); -R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, const char *meth_name, RAnalMethod *meth); -R_API RVector/**/ *r_anal_class_method_get_all(RAnal *anal, const char *class_name); -R_API RAnalClassErr r_anal_class_method_set(RAnal *anal, const char *class_name, RAnalMethod *meth); -R_API RAnalClassErr r_anal_class_method_rename(RAnal *anal, const char *class_name, const char *old_meth_name, const char *new_meth_name); -R_API RAnalClassErr r_anal_class_method_delete(RAnal *anal, const char *class_name, const char *meth_name); - -R_API void r_anal_class_base_fini(RAnalBaseClass *base); -R_API RAnalClassErr r_anal_class_base_get(RAnal *anal, const char *class_name, const char *base_id, RAnalBaseClass *base); -R_API RVector/**/ *r_anal_class_base_get_all(RAnal *anal, const char *class_name); -R_API RAnalClassErr r_anal_class_base_set(RAnal *anal, const char *class_name, RAnalBaseClass *base); -R_API RAnalClassErr r_anal_class_base_delete(RAnal *anal, const char *class_name, const char *base_id); - -R_API void r_anal_class_vtable_fini(RAnalVTable *vtable); -R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, const char *vtable_id, RAnalVTable *vtable); -R_API RVector/**/ *r_anal_class_vtable_get_all(RAnal *anal, const char *class_name); -R_API RAnalClassErr r_anal_class_vtable_set(RAnal *anal, const char *class_name, RAnalVTable *vtable); -R_API RAnalClassErr r_anal_class_vtable_delete(RAnal *anal, const char *class_name, const char *vtable_id); - -R_API void r_anal_class_print(RAnal *anal, const char *class_name, bool detailed); -R_API void r_anal_class_json(RAnal *anal, PJ *j, const char *class_name); -R_API void r_anal_class_list(RAnal *anal, int mode); -R_API void r_anal_class_list_bases(RAnal *anal, const char *class_name); -R_API void r_anal_class_list_vtables(RAnal *anal, const char *class_name); -R_API void r_anal_class_list_vtable_offset_functions(RAnal *anal, const char *class_name, ut64 offset); -R_API RGraph/**/ *r_anal_class_get_inheritance_graph(RAnal *anal); - -R_API RAnalEsilCFG *r_anal_esil_cfg_expr(RAnalEsilCFG *cfg, RAnal *anal, const ut64 off, char *expr); -R_API RAnalEsilCFG *r_anal_esil_cfg_op(RAnalEsilCFG *cfg, RAnal *anal, RAnalOp *op); -R_API void r_anal_esil_cfg_merge_blocks(RAnalEsilCFG *cfg); -R_API void r_anal_esil_cfg_free(RAnalEsilCFG *cfg); - -R_API RAnalEsilDFGNode *r_anal_esil_dfg_node_new (RAnalEsilDFG *edf, const char *c); -R_API RAnalEsilDFG *r_anal_esil_dfg_new(RReg *regs); -R_API void r_anal_esil_dfg_free(RAnalEsilDFG *dfg); -R_API RAnalEsilDFG *r_anal_esil_dfg_expr(RAnal *anal, RAnalEsilDFG *dfg, const char *expr); -R_API RStrBuf *r_anal_esil_dfg_filter(RAnalEsilDFG *dfg, const char *reg); -R_API RStrBuf *r_anal_esil_dfg_filter_expr(RAnal *anal, const char *expr, const char *reg); -R_API RList *r_anal_types_from_fcn(RAnal *anal, RAnalFunction *fcn); - -R_API RAnalBaseType *r_anal_get_base_type(RAnal *anal, const char *name); -R_API void r_parse_pdb_types(const RAnal *anal, const RPdb *pdb); -R_API void r_anal_save_base_type(const RAnal *anal, const RAnalBaseType *type); -R_API void r_anal_base_type_free(RAnalBaseType *type); -R_API RAnalBaseType *r_anal_base_type_new(RAnalBaseTypeKind kind); -R_API void r_anal_dwarf_process_info(const RAnal *anal, RAnalDwarfContext *ctx); -R_API void r_anal_dwarf_integrate_functions(RAnal *anal, RFlag *flags, Sdb *dwarf_sdb); -/* plugin pointers */ -extern RAnalPlugin r_anal_plugin_null; -extern RAnalPlugin r_anal_plugin_6502; -extern RAnalPlugin r_anal_plugin_6502_cs; -extern RAnalPlugin r_anal_plugin_8051; -extern RAnalPlugin r_anal_plugin_amd29k; -extern RAnalPlugin r_anal_plugin_arc; -extern RAnalPlugin r_anal_plugin_arm_cs; -extern RAnalPlugin r_anal_plugin_arm_gnu; -extern RAnalPlugin r_anal_plugin_avr; -extern RAnalPlugin r_anal_plugin_bf; -extern RAnalPlugin r_anal_plugin_chip8; -extern RAnalPlugin r_anal_plugin_cr16; -extern RAnalPlugin r_anal_plugin_cris; -extern RAnalPlugin r_anal_plugin_dalvik; -extern RAnalPlugin r_anal_plugin_ebc; -extern RAnalPlugin r_anal_plugin_gb; -extern RAnalPlugin r_anal_plugin_h8300; -extern RAnalPlugin r_anal_plugin_hexagon; -extern RAnalPlugin r_anal_plugin_i4004; -extern RAnalPlugin r_anal_plugin_i8080; -extern RAnalPlugin r_anal_plugin_java; -extern RAnalPlugin r_anal_plugin_m68k_cs; -extern RAnalPlugin r_anal_plugin_m680x_cs; -extern RAnalPlugin r_anal_plugin_malbolge; -extern RAnalPlugin r_anal_plugin_mcore; -extern RAnalPlugin r_anal_plugin_mips_cs; -extern RAnalPlugin r_anal_plugin_mips_gnu; -extern RAnalPlugin r_anal_plugin_msp430; -extern RAnalPlugin r_anal_plugin_nios2; -extern RAnalPlugin r_anal_plugin_or1k; -extern RAnalPlugin r_anal_plugin_pic; -extern RAnalPlugin r_anal_plugin_ppc_cs; -extern RAnalPlugin r_anal_plugin_ppc_gnu; -extern RAnalPlugin r_anal_plugin_propeller; -extern RAnalPlugin r_anal_plugin_riscv; -extern RAnalPlugin r_anal_plugin_riscv_cs; -extern RAnalPlugin r_anal_plugin_rsp; -extern RAnalPlugin r_anal_plugin_sh; -extern RAnalPlugin r_anal_plugin_snes; -extern RAnalPlugin r_anal_plugin_sparc_cs; -extern RAnalPlugin r_anal_plugin_sparc_gnu; -extern RAnalPlugin r_anal_plugin_sysz; -extern RAnalPlugin r_anal_plugin_tms320; -extern RAnalPlugin r_anal_plugin_tms320c64x; -extern RAnalPlugin r_anal_plugin_tricore; -extern RAnalPlugin r_anal_plugin_v810; -extern RAnalPlugin r_anal_plugin_v850; -extern RAnalPlugin r_anal_plugin_vax; -extern RAnalPlugin r_anal_plugin_wasm; -extern RAnalPlugin r_anal_plugin_ws; -extern RAnalPlugin r_anal_plugin_x86; -extern RAnalPlugin r_anal_plugin_x86_cs; -extern RAnalPlugin r_anal_plugin_x86_im; -extern RAnalPlugin r_anal_plugin_x86_simple; -extern RAnalPlugin r_anal_plugin_x86_udis; -extern RAnalPlugin r_anal_plugin_xap; -extern RAnalPlugin r_anal_plugin_xcore_cs; -extern RAnalPlugin r_anal_plugin_xtensa; -extern RAnalPlugin r_anal_plugin_z80; -extern RAnalPlugin r_anal_plugin_pyc; -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/libr/include/r_asm.h b/libr/include/r_asm.h deleted file mode 100644 index 488da15161..0000000000 --- a/libr/include/r_asm.h +++ /dev/null @@ -1,278 +0,0 @@ -/* radare - LGPL - Copyright 2009-2020 - nibble, pancake */ - -#ifndef R2_ASM_H -#define R2_ASM_H - -#include -#include // only for binding, no hard dep required -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_asm); - -/* backward compatibility */ -#define R_ASM_ARCH_NONE R_SYS_ARCH_NONE -#define R_ASM_ARCH_X86 R_SYS_ARCH_X86 -#define R_ASM_ARCH_ARM R_SYS_ARCH_ARM -#define R_ASM_ARCH_PPC R_SYS_ARCH_PPC -#define R_ASM_ARCH_M68K R_SYS_ARCH_M68K -#define R_ASM_ARCH_JAVA R_SYS_ARCH_JAVA -#define R_ASM_ARCH_LM32 R_SYS_ARCH_LM32 -#define R_ASM_ARCH_MIPS R_SYS_ARCH_MIPS -#define R_ASM_ARCH_SPARC R_SYS_ARCH_SPARC -#define R_ASM_ARCH_XAP R_SYS_ARCH_XAP -#define R_ASM_ARCH_MSIL R_SYS_ARCH_MSIL -#define R_ASM_ARCH_OBJD R_SYS_ARCH_OBJD -#define R_ASM_ARCH_BF R_SYS_ARCH_BF -#define R_ASM_ARCH_SH R_SYS_ARCH_SH -#define R_ASM_ARCH_Z80 R_SYS_ARCH_Z80 -#define R_ASM_ARCH_I8080 R_SYS_ARCH_I8080 -#define R_ASM_ARCH_ARC R_SYS_ARCH_ARC -#define R_ASM_ARCH_HPPA R_SYS_ARCH_HPPA - -#define R_ASM_GET_OFFSET(x,y,z) \ - (x && x->binb.bin && x->binb.get_offset)? \ - x->binb.get_offset (x->binb.bin, y, z): -1 - -#define R_ASM_GET_NAME(x,y,z) \ - (x && x->binb.bin && x->binb.get_name)? \ - x->binb.get_name (x->binb.bin, y, z, x->pseudo): NULL - -enum { - R_ASM_SYNTAX_NONE = 0, - R_ASM_SYNTAX_INTEL, - R_ASM_SYNTAX_ATT, - R_ASM_SYNTAX_MASM, - R_ASM_SYNTAX_REGNUM, // alias for capstone's NOREGNAME - R_ASM_SYNTAX_JZ, // hack to use jz instead of je on x86 -}; - -enum { - R_ASM_MOD_RAWVALUE = 'r', - R_ASM_MOD_VALUE = 'v', - R_ASM_MOD_DSTREG = 'd', - R_ASM_MOD_SRCREG0 = '0', - R_ASM_MOD_SRCREG1 = '1', - R_ASM_MOD_SRCREG2 = '2' -}; - -typedef struct r_asm_op_t { - int size; // instruction size (must be deprecated. just use buf.len - int bitsize; // instruction size in bits (or 0 if fits in 8bit bytes) // wtf why dupe this field? :D - int payload; // size of payload (opsize = (size-payload)) - // But this is pretty slow..so maybe we should add some accessors - RStrBuf buf; - RStrBuf buf_asm; - RBuffer *buf_inc; // must die -} RAsmOp; - -typedef struct r_asm_code_t { -#if 1 - int len; - ut8 *bytes; - char *assembly; -#else - RAsmOp op; // we have those fields already inside RAsmOp -#endif - RList *equs; // TODO: must be a hash - ut64 code_offset; - ut64 data_offset; - int code_align; -} RAsmCode; - -// TODO: Must use Hashtable instead of this hack -typedef struct { - char *key; - char *value; -} RAsmEqu; - -#define _RAsmPlugin struct r_asm_plugin_t -typedef struct r_asm_t { - char *cpu; - int bits; - int big_endian; - int syntax; - ut64 pc; - void *user; - _RAsmPlugin *cur; - _RAsmPlugin *acur; - RList *plugins; - RBinBind binb; - RParse *ifilter; - RParse *ofilter; - Sdb *pair; - RSyscall *syscall; - RNum *num; - char *features; - int invhex; // invalid instructions displayed in hex - int pcalign; - int dataalign; - int bitshift; - bool immdisp; // Display immediates with # symbol (for arm stuff). - HtPP *flags; - int seggrn; - bool pseudo; -} RAsm; - -typedef bool (*RAsmModifyCallback)(RAsm *a, ut8 *buf, int field, ut64 val); - -typedef struct r_asm_plugin_t { - const char *name; - const char *arch; - const char *author; - const char *version; - const char *cpus; - const char *desc; - const char *license; - void *user; // user data pointer - int bits; - int endian; - bool (*init)(void *user); - bool (*fini)(void *user); - int (*disassemble)(RAsm *a, RAsmOp *op, const ut8 *buf, int len); - int (*assemble)(RAsm *a, RAsmOp *op, const char *buf); - RAsmModifyCallback modify; - char *(*mnemonics)(RAsm *a, int id, bool json); - const char *features; -} RAsmPlugin; - -#ifdef R_API -/* asm.c */ -R_API RAsm *r_asm_new(void); -R_API void r_asm_free(RAsm *a); -R_API bool r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val); -R_API char *r_asm_mnemonics(RAsm *a, int id, bool json); -R_API int r_asm_mnemonics_byname(RAsm *a, const char *name); -R_API void r_asm_set_user_ptr(RAsm *a, void *user); -R_API bool r_asm_add(RAsm *a, RAsmPlugin *foo); -R_API bool r_asm_setup(RAsm *a, const char *arch, int bits, int big_endian); -R_API bool r_asm_is_valid(RAsm *a, const char *name); -R_API bool r_asm_use(RAsm *a, const char *name); -R_API bool r_asm_use_assembler(RAsm *a, const char *name); -R_API bool r_asm_set_arch(RAsm *a, const char *name, int bits); -R_API int r_asm_set_bits(RAsm *a, int bits); -R_API void r_asm_set_cpu(RAsm *a, const char *cpu); -R_API bool r_asm_set_big_endian(RAsm *a, bool big_endian); -R_API bool r_asm_set_syntax(RAsm *a, int syntax); -R_API int r_asm_syntax_from_string(const char *name); -R_API int r_asm_set_pc(RAsm *a, ut64 pc); -R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len); -R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf); -R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len); -R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, RParse *p, const char *hexstr); -R_API RAsmCode* r_asm_massemble(RAsm *a, const char *buf); -R_API RAsmCode* r_asm_rasm_assemble(RAsm *a, const char *buf, bool use_spp); -R_API char *r_asm_to_string(RAsm *a, ut64 addr, const ut8 *b, int l); -/* to ease the use of the native bindings (not used in r2) */ -R_API ut8 *r_asm_from_string(RAsm *a, ut64 addr, const char *b, int *l); -R_API int r_asm_filter_input(RAsm *a, const char *f); -R_API int r_asm_filter_output(RAsm *a, const char *f); -R_API char *r_asm_describe(RAsm *a, const char* str); -R_API RList* r_asm_get_plugins(RAsm *a); -R_API void r_asm_list_directives(void); - -/* code.c */ -R_API RAsmCode *r_asm_code_new(void); -R_API void* r_asm_code_free(RAsmCode *acode); -R_API void r_asm_equ_item_free(RAsmEqu *equ); -R_API bool r_asm_code_set_equ(RAsmCode *code, const char *key, const char *value); -R_API char *r_asm_code_equ_replace(RAsmCode *code, char *str); -R_API char* r_asm_code_get_hex(RAsmCode *acode); - -/* op.c */ -R_API RAsmOp *r_asm_op_new(void); -R_API void r_asm_op_init(RAsmOp *op); -R_API void r_asm_op_free(RAsmOp *op); -R_API void r_asm_op_fini(RAsmOp *op); -R_API char *r_asm_op_get_hex(RAsmOp *op); -R_API char *r_asm_op_get_asm(RAsmOp *op); -R_API int r_asm_op_get_size(RAsmOp *op); -R_API void r_asm_op_set_asm(RAsmOp *op, const char *str); -R_API int r_asm_op_set_hex(RAsmOp *op, const char *str); -R_API int r_asm_op_set_hexbuf(RAsmOp *op, const ut8 *buf, int len); -R_API void r_asm_op_set_buf(RAsmOp *op, const ut8 *str, int len); -R_API ut8 *r_asm_op_get_buf(RAsmOp *op); - -/* plugin pointers */ -extern RAsmPlugin r_asm_plugin_6502; -extern RAsmPlugin r_asm_plugin_6502_cs; -extern RAsmPlugin r_asm_plugin_8051; -extern RAsmPlugin r_asm_plugin_amd29k; -extern RAsmPlugin r_asm_plugin_arc; -extern RAsmPlugin r_asm_plugin_arm_as; -extern RAsmPlugin r_asm_plugin_arm_cs; -extern RAsmPlugin r_asm_plugin_arm_gnu; -extern RAsmPlugin r_asm_plugin_arm_winedbg; -extern RAsmPlugin r_asm_plugin_avr; -extern RAsmPlugin r_asm_plugin_bf; -extern RAsmPlugin r_asm_plugin_null; -extern RAsmPlugin r_asm_plugin_chip8; -extern RAsmPlugin r_asm_plugin_cr16; -extern RAsmPlugin r_asm_plugin_cris_gnu; -extern RAsmPlugin r_asm_plugin_dalvik; -extern RAsmPlugin r_asm_plugin_dcpu16; -extern RAsmPlugin r_asm_plugin_ebc; -extern RAsmPlugin r_asm_plugin_gb; -extern RAsmPlugin r_asm_plugin_h8300; -extern RAsmPlugin r_asm_plugin_hexagon; -extern RAsmPlugin r_asm_plugin_hexagon_gnu; -extern RAsmPlugin r_asm_plugin_hppa_gnu; -extern RAsmPlugin r_asm_plugin_i4004; -extern RAsmPlugin r_asm_plugin_i8080; -extern RAsmPlugin r_asm_plugin_java; -extern RAsmPlugin r_asm_plugin_lanai_gnu; -extern RAsmPlugin r_asm_plugin_lh5801; -extern RAsmPlugin r_asm_plugin_lm32; -extern RAsmPlugin r_asm_plugin_m68k_cs; -extern RAsmPlugin r_asm_plugin_m680x_cs; -extern RAsmPlugin r_asm_plugin_malbolge; -extern RAsmPlugin r_asm_plugin_mcore; -extern RAsmPlugin r_asm_plugin_mcs96; -extern RAsmPlugin r_asm_plugin_mips_cs; -extern RAsmPlugin r_asm_plugin_mips_gnu; -extern RAsmPlugin r_asm_plugin_msp430; -extern RAsmPlugin r_asm_plugin_nios2; -extern RAsmPlugin r_asm_plugin_or1k; -extern RAsmPlugin r_asm_plugin_pic; -extern RAsmPlugin r_asm_plugin_ppc_cs; -extern RAsmPlugin r_asm_plugin_ppc_gnu; -extern RAsmPlugin r_asm_plugin_propeller; -extern RAsmPlugin r_asm_plugin_riscv; -extern RAsmPlugin r_asm_plugin_riscv_cs; -extern RAsmPlugin r_asm_plugin_rsp; -extern RAsmPlugin r_asm_plugin_sh; -extern RAsmPlugin r_asm_plugin_snes; -extern RAsmPlugin r_asm_plugin_sparc_cs; -extern RAsmPlugin r_asm_plugin_sparc_gnu; -extern RAsmPlugin r_asm_plugin_spc700; -extern RAsmPlugin r_asm_plugin_sysz; -extern RAsmPlugin r_asm_plugin_tms320; -extern RAsmPlugin r_asm_plugin_tms320c64x; -extern RAsmPlugin r_asm_plugin_tricore; -extern RAsmPlugin r_asm_plugin_v810; -extern RAsmPlugin r_asm_plugin_v850; -extern RAsmPlugin r_asm_plugin_vax; -extern RAsmPlugin r_asm_plugin_wasm; -extern RAsmPlugin r_asm_plugin_ws; -extern RAsmPlugin r_asm_plugin_x86_as; -extern RAsmPlugin r_asm_plugin_x86_cs; -extern RAsmPlugin r_asm_plugin_x86_nasm; -extern RAsmPlugin r_asm_plugin_x86_nz; -extern RAsmPlugin r_asm_plugin_xap; -extern RAsmPlugin r_asm_plugin_xcore_cs; -extern RAsmPlugin r_asm_plugin_xtensa; -extern RAsmPlugin r_asm_plugin_z80; -extern RAsmPlugin r_asm_plugin_pyc; - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_bin.h b/libr/include/r_bin.h deleted file mode 100644 index 91c3c2d6ba..0000000000 --- a/libr/include/r_bin.h +++ /dev/null @@ -1,889 +0,0 @@ -#ifndef R2_BIN_H -#define R2_BIN_H - -#include -#include -#include -#include -#include - -typedef struct r_bin_t RBin; - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER (r_bin); - -#define R_BIN_DBG_STRIPPED 0x01 -#define R_BIN_DBG_STATIC 0x02 -#define R_BIN_DBG_LINENUMS 0x04 -#define R_BIN_DBG_SYMS 0x08 -#define R_BIN_DBG_RELOCS 0x10 - -#define R_BIN_ENTRY_TYPE_PROGRAM 0 -#define R_BIN_ENTRY_TYPE_MAIN 1 -#define R_BIN_ENTRY_TYPE_INIT 2 -#define R_BIN_ENTRY_TYPE_FINI 3 -#define R_BIN_ENTRY_TYPE_TLS 4 -#define R_BIN_ENTRY_TYPE_PREINIT 5 - -#define R_BIN_SIZEOF_STRINGS 512 -#define R_BIN_MAX_ARCH 1024 - -#define R_BIN_REQ_ALL UT64_MAX -#define R_BIN_REQ_UNK 0x000000 -#define R_BIN_REQ_ENTRIES 0x000001 -#define R_BIN_REQ_IMPORTS 0x000002 -#define R_BIN_REQ_SYMBOLS 0x000004 -#define R_BIN_REQ_SECTIONS 0x000008 -#define R_BIN_REQ_INFO 0x000010 -#define R_BIN_REQ_OPERATION 0x000020 -#define R_BIN_REQ_HELP 0x000040 -#define R_BIN_REQ_STRINGS 0x000080 -#define R_BIN_REQ_FIELDS 0x000100 -#define R_BIN_REQ_LIBS 0x000200 -#define R_BIN_REQ_SRCLINE 0x000400 -#define R_BIN_REQ_MAIN 0x000800 -#define R_BIN_REQ_EXTRACT 0x001000 -#define R_BIN_REQ_RELOCS 0x002000 -#define R_BIN_REQ_LISTARCHS 0x004000 -#define R_BIN_REQ_CREATE 0x008000 -#define R_BIN_REQ_CLASSES 0x010000 -#define R_BIN_REQ_DWARF 0x020000 -#define R_BIN_REQ_SIZE 0x040000 -#define R_BIN_REQ_PDB 0x080000 -#define R_BIN_REQ_PDB_DWNLD 0x100000 -#define R_BIN_REQ_DLOPEN 0x200000 -#define R_BIN_REQ_EXPORTS 0x400000 -#define R_BIN_REQ_VERSIONINFO 0x800000 -#define R_BIN_REQ_PACKAGE 0x1000000 -#define R_BIN_REQ_HEADER 0x2000000 -#define R_BIN_REQ_LISTPLUGINS 0x4000000 -#define R_BIN_REQ_RESOURCES 0x8000000 -#define R_BIN_REQ_INITFINI 0x10000000 -#define R_BIN_REQ_SEGMENTS 0x20000000 -#define R_BIN_REQ_HASHES 0x40000000 -#define R_BIN_REQ_SIGNATURE 0x80000000 -#define R_BIN_REQ_TRYCATCH 0x100000000 -#define R_BIN_REQ_SECTIONS_MAPPING 0x200000000 - -/* RBinSymbol->method_flags : */ -#define R_BIN_METH_CLASS 0x0000000000000001L -#define R_BIN_METH_STATIC 0x0000000000000002L -#define R_BIN_METH_PUBLIC 0x0000000000000004L -#define R_BIN_METH_PRIVATE 0x0000000000000008L -#define R_BIN_METH_PROTECTED 0x0000000000000010L -#define R_BIN_METH_INTERNAL 0x0000000000000020L -#define R_BIN_METH_OPEN 0x0000000000000040L -#define R_BIN_METH_FILEPRIVATE 0x0000000000000080L -#define R_BIN_METH_FINAL 0x0000000000000100L -#define R_BIN_METH_VIRTUAL 0x0000000000000200L -#define R_BIN_METH_CONST 0x0000000000000400L -#define R_BIN_METH_MUTATING 0x0000000000000800L -#define R_BIN_METH_ABSTRACT 0x0000000000001000L -#define R_BIN_METH_SYNCHRONIZED 0x0000000000002000L -#define R_BIN_METH_NATIVE 0x0000000000004000L -#define R_BIN_METH_BRIDGE 0x0000000000008000L -#define R_BIN_METH_VARARGS 0x0000000000010000L -#define R_BIN_METH_SYNTHETIC 0x0000000000020000L -#define R_BIN_METH_STRICT 0x0000000000040000L -#define R_BIN_METH_MIRANDA 0x0000000000080000L -#define R_BIN_METH_CONSTRUCTOR 0x0000000000100000L -#define R_BIN_METH_DECLARED_SYNCHRONIZED 0x0000000000200000L - -#define R_BIN_BIND_LOCAL_STR "LOCAL" -#define R_BIN_BIND_GLOBAL_STR "GLOBAL" -#define R_BIN_BIND_WEAK_STR "WEAK" -#define R_BIN_BIND_NUM_STR "NUM" -#define R_BIN_BIND_LOOS_STR "LOOS" -#define R_BIN_BIND_HIOS_STR "HIOS" -#define R_BIN_BIND_LOPROC_STR "LOPROC" -#define R_BIN_BIND_HIPROC_STR "HIPROC" -#define R_BIN_BIND_UNKNOWN_STR "UNKNOWN" - -#define R_BIN_TYPE_NOTYPE_STR "NOTYPE" -#define R_BIN_TYPE_OBJECT_STR "OBJ" -#define R_BIN_TYPE_FUNC_STR "FUNC" -#define R_BIN_TYPE_METH_STR "METH" -#define R_BIN_TYPE_STATIC_STR "STATIC" -#define R_BIN_TYPE_SECTION_STR "SECT" -#define R_BIN_TYPE_FILE_STR "FILE" -#define R_BIN_TYPE_COMMON_STR "COMMON" -#define R_BIN_TYPE_TLS_STR "TLS" -#define R_BIN_TYPE_NUM_STR "NUM" -#define R_BIN_TYPE_LOOS_STR "LOOS" -#define R_BIN_TYPE_HIOS_STR "HIOS" -#define R_BIN_TYPE_LOPROC_STR "LOPROC" -#define R_BIN_TYPE_HIPROC_STR "HIPROC" -#define R_BIN_TYPE_SPECIAL_SYM_STR "SPCL" -#define R_BIN_TYPE_UNKNOWN_STR "UNK" - -enum { - R_BIN_SYM_ENTRY, - R_BIN_SYM_INIT, - R_BIN_SYM_MAIN, - R_BIN_SYM_FINI, - R_BIN_SYM_LAST -}; - -// name mangling types -// TODO: Rename to R_BIN_LANG_ -enum { - R_BIN_NM_NONE = 0, - R_BIN_NM_JAVA = 1, - R_BIN_NM_C = 1<<1, - R_BIN_NM_GO = 1<<2, - R_BIN_NM_CXX = 1<<3, - R_BIN_NM_OBJC = 1<<4, - R_BIN_NM_SWIFT = 1<<5, - R_BIN_NM_DLANG = 1<<6, - R_BIN_NM_MSVC = 1<<7, - R_BIN_NM_RUST = 1<<8, - R_BIN_NM_KOTLIN = 1<<9, - R_BIN_NM_BLOCKS = 1<<31, - R_BIN_NM_ANY = -1, -}; - -enum { - R_STRING_TYPE_DETECT = '?', - R_STRING_TYPE_ASCII = 'a', - R_STRING_TYPE_UTF8 = 'u', - R_STRING_TYPE_WIDE = 'w', // utf16 / widechar string - R_STRING_TYPE_WIDE32 = 'W', // utf32 - R_STRING_TYPE_BASE64 = 'b', -}; - -enum { - R_BIN_CLASS_PRIVATE, - R_BIN_CLASS_PUBLIC, - R_BIN_CLASS_FRIENDLY, - R_BIN_CLASS_PROTECTED, -}; - -enum { - R_BIN_RELOC_8 = 8, - R_BIN_RELOC_16 = 16, - R_BIN_RELOC_32 = 32, - R_BIN_RELOC_64 = 64 -}; - -enum { - R_BIN_TYPE_DEFAULT = 0, - R_BIN_TYPE_CORE = 1 -}; - -typedef struct r_bin_addr_t { - ut64 vaddr; - ut64 paddr; - ut64 hvaddr; - ut64 hpaddr; - int type; - int bits; -} RBinAddr; - -typedef struct r_bin_hash_t { - const char *type; - ut64 addr; - int len; - ut64 from; - ut64 to; - ut8 buf[32]; - const char *cmd; -} RBinHash; - -typedef struct r_bin_file_hash_t { - const char *type; - const char *hex; -} RBinFileHash; - -typedef struct r_bin_info_t { - char *file; - char *type; - char *bclass; - char *rclass; - char *arch; - char *cpu; - char *machine; - char *head_flag; - char *features; - char *os; - char *subsystem; - char *rpath; - char *guid; - char *debug_file_name; - const char *lang; - char *default_cc; - RList/**/ *file_hashes; - int bits; - int has_va; - int has_pi; // pic/pie - int has_canary; - int has_retguard; - int has_sanitizers; - int has_crypto; - int has_nx; - int big_endian; - bool has_lit; - char *actual_checksum; - char *claimed_checksum; - int pe_overlay; - bool signature; - ut64 dbg_info; - RBinHash sum[3]; - ut64 baddr; - char *intrp; - char *compiler; -} RBinInfo; - -typedef struct r_bin_object_t { - ut64 baddr; - st64 baddr_shift; - ut64 loadaddr; - ut64 boffset; - ut64 size; - ut64 obj_size; - RList/**/ *sections; - RList/**/ *imports; - RList/**/ *symbols; - RList/**/ *entries; - RList/**/ *fields; - RList/**/ *libs; - RBNode/**/ *relocs; - RList/**/ *strings; - RList/**/ *classes; - HtPP *classes_ht; - HtPP *methods_ht; - RList/**/ *lines; - HtUP *strings_db; - RList/**/ *mem; //RBinMem maybe? - RList/*plugin -typedef struct r_bin_file_t { - char *file; - int fd; - int size; - int rawstr; - int strmode; - ut32 id; - RBuffer *buf; - ut64 offset; - RBinObject *o; - void *xtr_obj; - ut64 loadaddr; - /* values used when searching the strings */ - int minstrlen; - int maxstrlen; - int narch; - struct r_bin_xtr_plugin_t *curxtr; - // struct r_bin_plugin_t *curplugin; // use o->plugin - RList *xtr_data; - Sdb *sdb; - Sdb *sdb_info; - Sdb *sdb_addrinfo; - struct r_bin_t *rbin; -} RBinFile; - -typedef struct r_bin_file_options_t { - int rawstr; - ut64 baddr; // base address - ut64 laddr; // load address - ut64 paddr; // offset - const char *plugname; // force a plugin? why do i need this? - // const char *xtrname; -} RBinFileOptions; - -struct r_bin_t { - const char *file; - RBinFile *cur; // TODO: deprecate - int narch; - void *user; - /* preconfigured values */ - int debase64; - int minstrlen; - int maxstrlen; - ut64 maxstrbuf; - int rawstr; - Sdb *sdb; - RIDStorage *ids; - RList/**/ *plugins; - RList/**/ *binxtrs; - RList/**/ *binldrs; - RList/**/ *binfiles; - PrintfCallback cb_printf; - int loadany; - RIOBind iob; - RConsBind consb; - char *force; - int is_debugger; - bool want_dbginfo; - int filter; // symbol filtering - char strfilter; // string filtering - char *strpurge; // purge false positive strings - char *srcdir; // dir.source - char *prefix; // bin.prefix - char *strenc; - ut64 filter_rules; - bool demanglercmd; - bool verbose; - bool use_xtr; // use extract plugins when loading a file? - bool use_ldr; // use loader plugins when loading a file? - RStrConstPool constpool; - bool is_reloc_patched; // used to indicate whether relocations were patched or not -}; - -typedef struct r_bin_xtr_metadata_t { - char *arch; - int bits; - char *libname; - char *machine; - char *type; - const char *xtr_type; -} RBinXtrMetadata; - -typedef int (*FREE_XTR)(void *xtr_obj); -typedef struct r_bin_xtr_extract_t { - char *file; - RBuffer *buf; - ut64 size; - ut64 offset; - ut64 baddr; - ut64 laddr; - int file_count; - int loaded; - RBinXtrMetadata *metadata; -} RBinXtrData; - -R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata); -R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data); - -typedef struct r_bin_xtr_plugin_t { - char *name; - char *desc; - char *license; - int (*init)(void *user); - int (*fini)(void *user); - bool (*check_buffer)(RBuffer *b); - - RBinXtrData *(*extract_from_bytes)(RBin *bin, const ut8 *buf, ut64 size, int idx); - RBinXtrData *(*extract_from_buffer)(RBin *bin, RBuffer *buf, int idx); - RList *(*extractall_from_bytes)(RBin *bin, const ut8 *buf, ut64 size); - RList *(*extractall_from_buffer)(RBin *bin, RBuffer *buf); - RBinXtrData *(*extract)(RBin *bin, int idx); - RList *(*extractall)(RBin *bin); - - bool (*load)(RBin *bin); - int (*size)(RBin *bin); - void (*destroy)(RBin *bin); - void (*free_xtr)(void *xtr_obj); -} RBinXtrPlugin; - -typedef struct r_bin_ldr_plugin_t { - char *name; - char *desc; - char *license; - int (*init)(void *user); - int (*fini)(void *user); - bool (*load)(RBin *bin); -} RBinLdrPlugin; - -typedef struct r_bin_arch_options_t { - const char *arch; - int bits; -} RBinArchOptions; - -typedef struct r_bin_trycatch_t { - ut64 source; - ut64 from; - ut64 to; - ut64 handler; - ut64 filter; - // TODO: add type/name of exception -} RBinTrycatch; - -R_API RBinTrycatch *r_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter); -R_API void r_bin_trycatch_free(RBinTrycatch *tc); - -typedef struct r_bin_plugin_t { - char *name; - char *desc; - char *author; - char *version; - char *license; - int (*init)(void *user); - int (*fini)(void *user); - Sdb * (*get_sdb)(RBinFile *obj); - bool (*load_buffer)(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb); - ut64 (*size)(RBinFile *bin); // return ut64 maybe? meh - void (*destroy)(RBinFile *bf); - bool (*check_bytes)(const ut8 *buf, ut64 length); - bool (*check_buffer)(RBuffer *buf); - ut64 (*baddr)(RBinFile *bf); - ut64 (*boffset)(RBinFile *bf); - RBinAddr* (*binsym)(RBinFile *bf, int num); - RList/**/* (*entries)(RBinFile *bf); - RList/**/* (*sections)(RBinFile *bf); - R_BORROW RList/**/* (*lines)(RBinFile *bf); - RList/**/* (*symbols)(RBinFile *bf); - RList/**/* (*imports)(RBinFile *bf); - RList/**/* (*strings)(RBinFile *bf); - RBinInfo/**/* (*info)(RBinFile *bf); - RList/**/* (*fields)(RBinFile *bf); - RList/**/* (*libs)(RBinFile *bf); - RList/**/* (*relocs)(RBinFile *bf); - RList/**/* (*trycatch)(RBinFile *bf); - RList/**/* (*classes)(RBinFile *bf); - RList/**/* (*mem)(RBinFile *bf); - RList/**/* (*patch_relocs)(RBin *bin); - RList/**/* (*maps)(RBinFile *bf); - RList/**/* (*hashes)(RBinFile *bf); - void (*header)(RBinFile *bf); - char* (*signature)(RBinFile *bf, bool json); - int (*demangle_type)(const char *str); - struct r_bin_dbginfo_t *dbginfo; - struct r_bin_write_t *write; - int (*get_offset)(RBinFile *bf, int type, int idx); - char* (*get_name)(RBinFile *bf, int type, int idx, bool simplified); - ut64 (*get_vaddr)(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr); - RBuffer* (*create)(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt); - char* (*demangle)(const char *str); - char* (*regstate)(RBinFile *bf); - int (*file_type)(RBinFile *bf); - /* default value if not specified by user */ - int minstrlen; - char strfilter; - void *user; -} RBinPlugin; - -typedef void (*RBinSymbollCallback)(RBinObject *obj, void *symbol); - -typedef struct r_bin_section_t { - char *name; - ut64 size; - ut64 vsize; - ut64 vaddr; - ut64 paddr; - ut32 perm; - // per section platform info - const char *arch; - char *format; - int bits; - bool has_strings; - bool add; // indicates when you want to add the section to io `S` command - bool is_data; - bool is_segment; -} RBinSection; - -typedef struct r_bin_class_t { - char *name; - // TODO: char *module; - char *super; - char *visibility_str; // XXX only used by java - int index; - ut64 addr; - RList *methods; // - RList *fields; // - // RList *interfaces; // - int visibility; -} RBinClass; - -#define RBinSectionName r_offsetof(RBinSection, name) -#define RBinSectionOffset r_offsetof(RBinSection, offset) - -#define REBASE_PADDR(o, l, type_t)\ - do { \ - RListIter *_it;\ - type_t *_el;\ - r_list_foreach ((l), _it, _el) { \ - _el->paddr += (o)->loadaddr;\ - }\ - } while (0) - - -typedef struct r_bin_symbol_t { - /* heap-allocated */ - char *name; - char *dname; - char *libname; - char *classname; - /* const-unique-strings */ - const char *forwarder; - const char *bind; - const char *type; - const char *rtype; - bool is_imported; - /* only used by java */ - const char *visibility_str; - // ---------------- - //char descriptor[R_BIN_SIZEOF_STRINGS+1]; - ut64 vaddr; - ut64 paddr; - ut32 size; - ut32 ordinal; - ut32 visibility; - int bits; - /* see R_BIN_METH_* constants */ - ut64 method_flags; - int dup_count; -} RBinSymbol; - -typedef struct r_bin_import_t { - char *name; - char *libname; - const char *bind; - const char *type; - char *classname; - char *descriptor; - ut32 ordinal; - ut32 visibility; -} RBinImport; - -typedef struct r_bin_reloc_t { - ut8 type; - ut8 additive; - RBinSymbol *symbol; - RBinImport *import; - st64 addend; - ut64 vaddr; - ut64 paddr; - ut32 visibility; - /* is_ifunc: indirect function, `addend` points to a resolver function - * that returns the actual relocation value, e.g. chooses - * an optimized version depending on the CPU. - * cf. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html - */ - bool is_ifunc; - RBNode vrb; -} RBinReloc; - -typedef struct r_bin_string_t { - // TODO: rename string->name (avoid colisions) - char *string; - ut64 vaddr; - ut64 paddr; - ut32 ordinal; - ut32 size; // size of buffer containing the string in bytes - ut32 length; // length of string in chars - char type; // Ascii Wide cp850 utf8 base64 ... -} RBinString; - -typedef struct r_bin_field_t { - ut64 vaddr; - ut64 paddr; - int size; - int offset; - ut32 visibility; - char *name; - char *type; - char *comment; - char *format; - bool format_named; // whether format is the name of a format or a raw pf format string - ut64 flags; -} RBinField; - -R_API RBinField *r_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named); -R_API void r_bin_field_free(void *); - -typedef struct r_bin_mem_t { - char *name; - ut64 addr; - int size; - int perms; - RList *mirrors; //for mirror access; stuff here should only create new maps not new fds -} RBinMem; - -typedef struct r_bin_map_t { - ut64 addr; - ut64 offset; - int size; - int perms; - char *file; -} RBinMap; - -typedef struct r_bin_dbginfo_t { - bool (*get_line)(RBinFile *arch, ut64 addr, char *file, int len, int *line); -} RBinDbgInfo; - -typedef struct r_bin_write_t { - ut64 (*scn_resize)(RBinFile *bf, const char *name, ut64 size); - bool (*scn_perms)(RBinFile *bf, const char *name, int perms); - int (*rpath_del)(RBinFile *bf); - bool (*entry)(RBinFile *bf, ut64 addr); - bool (*addlib)(RBinFile *bf, const char *lib); -} RBinWrite; - -// TODO: deprecate r_bin_is_big_endian -// TODO: has_dbg_syms... maybe flags? - -typedef int (*RBinGetOffset)(RBin *bin, int type, int idx); -typedef const char *(*RBinGetName)(RBin *bin, int type, int idx, bool sd); -typedef RList *(*RBinGetSections)(RBin *bin); -typedef RBinSection *(*RBinGetSectionAt)(RBin *bin, ut64 addr); -typedef char *(*RBinDemangle)(RBinFile *bf, const char *def, const char *str, ut64 vaddr, bool libs); - -typedef struct r_bin_bind_t { - RBin *bin; - RBinGetOffset get_offset; - RBinGetName get_name; - RBinGetSections get_sections; - RBinGetSectionAt get_vsect_at; - RBinDemangle demangle; - ut32 visibility; -} RBinBind; - -R_IPI RBinSection *r_bin_section_new(const char *name); -R_IPI void r_bin_section_free(RBinSection *bs); -R_API void r_bin_info_free(RBinInfo *rb); -R_API void r_bin_import_free(void *_imp); -R_API void r_bin_symbol_free(void *_sym); -R_API RBinSymbol *r_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr); -R_API void r_bin_string_free(void *_str); - -#ifdef R_API - -typedef struct r_bin_options_t { - const char *pluginname; - ut64 baseaddr; // where the linker maps the binary in memory - ut64 loadaddr; // starting physical address to read from the target file - ut64 sz; - int xtr_idx; // load Nth binary - int rawstr; - int fd; - const char *filename; -} RBinOptions; - -R_API RBinImport *r_bin_import_clone(RBinImport *o); -R_API const char *r_bin_symbol_name(RBinSymbol *s); -typedef void (*RBinSymbolCallback)(RBinObject *obj, RBinSymbol *symbol); - -// options functions -R_API void r_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, int rawstr); -R_API void r_bin_arch_options_init(RBinArchOptions *opt, const char *arch, int bits); - -// open/close/reload functions -R_API RBin *r_bin_new(void); -R_API void r_bin_free(RBin *bin); -R_API bool r_bin_open(RBin *bin, const char *file, RBinOptions *opt); -R_API bool r_bin_open_io(RBin *bin, RBinOptions *opt); -R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt); -R_API bool r_bin_reload(RBin *bin, ut32 bf_id, ut64 baseaddr); - -// plugins/bind functions -R_API void r_bin_bind(RBin *b, RBinBind *bnd); -R_API bool r_bin_add(RBin *bin, RBinPlugin *foo); -R_API bool r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo); -R_API bool r_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo); -R_API void r_bin_list(RBin *bin, int format); -R_API bool r_bin_list_plugin(RBin *bin, const char *name, int json); -R_API RBinPlugin *r_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz); -R_API RBinPlugin *r_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf); -R_API void r_bin_force_plugin(RBin *bin, const char *pname); - -// get/set various bin information -R_API ut64 r_bin_get_baddr(RBin *bin); -R_API ut64 r_bin_file_get_baddr(RBinFile *bf); -R_API void r_bin_set_user_ptr(RBin *bin, void *user); -R_API RBinInfo *r_bin_get_info(RBin *bin); -R_API void r_bin_set_baddr(RBin *bin, ut64 baddr); -R_API ut64 r_bin_get_laddr(RBin *bin); -R_API ut64 r_bin_get_size(RBin *bin); -R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym); -R_API RList *r_bin_raw_strings(RBinFile *a, int min); -R_API RList *r_bin_dump_strings(RBinFile *a, int min, int raw); - -// use RBinFile instead -R_API RList *r_bin_get_entries(RBin *bin); -R_API RList *r_bin_get_fields(RBin *bin); -R_API RList *r_bin_get_imports(RBin *bin); -R_API RList *r_bin_get_libs(RBin *bin); -R_API RBNode *r_bin_patch_relocs(RBin *bin); -R_API RList *r_bin_patch_relocs_list(RBin *bin); -R_API RBNode *r_bin_get_relocs(RBin *bin); -R_API RList *r_bin_get_relocs_list(RBin *bin); -R_API RList *r_bin_get_sections(RBin *bin); -R_API RList *r_bin_get_classes(RBin *bin); -R_API RList *r_bin_get_strings(RBin *bin); -R_API RList *r_bin_file_get_trycatch(RBinFile *bf); -R_API RList *r_bin_get_symbols(RBin *bin); -R_API RList *r_bin_reset_strings(RBin *bin); -R_API int r_bin_is_string(RBin *bin, ut64 va); -R_API int r_bin_is_big_endian(RBin *bin); -R_API int r_bin_is_static(RBin *bin); -R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr); -R_API ut64 r_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr); -R_API ut64 r_bin_a2b(RBin *bin, ut64 addr); - -R_API int r_bin_load_languages(RBinFile *binfile); -R_API RBinFile *r_bin_cur(RBin *bin); -R_API RBinObject *r_bin_cur_object(RBin *bin); - -// select/list binfiles functions -R_API bool r_bin_select(RBin *bin, const char *arch, int bits, const char *name); -R_API bool r_bin_select_bfid(RBin *bin, ut32 bf_id); -R_API bool r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name); -R_API void r_bin_list_archs(RBin *bin, int mode); -R_API RBuffer *r_bin_create(RBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt); -R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files); - -R_API const char *r_bin_string_type(int type); -R_API const char *r_bin_entry_type_string(int etype); - -R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data); - - -// RBinFile lifecycle -// R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr); -R_API bool r_bin_file_close(RBin *bin, int bd); -R_API void r_bin_file_free(void /*RBinFile*/ *bf_); -// RBinFile.get -R_API RBinFile *r_bin_file_at(RBin *bin, ut64 addr); -R_API RBinFile *r_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id); -R_API RList *r_bin_file_get_symbols(RBinFile *bf); -// -R_API ut64 r_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr); -// RBinFile.add -R_API RBinClass *r_bin_file_add_class(RBinFile *binfile, const char *name, const char *super, int view); -R_API RBinSymbol *r_bin_file_add_method(RBinFile *bf, const char *classname, const char *name, int nargs); -R_API RBinField *r_bin_file_add_field(RBinFile *binfile, const char *classname, const char *name); -// RBinFile.find -R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits); -R_API RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 bin_id); -R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd); -R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name); - -R_API bool r_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf); -R_API bool r_bin_file_set_cur_by_name(RBin *bin, const char *name); -R_API bool r_bin_file_deref(RBin *bin, RBinFile *a); -R_API bool r_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd); -R_API bool r_bin_file_set_cur_by_id(RBin *bin, ut32 bin_id); -R_API bool r_bin_file_set_cur_by_name(RBin *bin, const char *name); -R_API ut64 r_bin_file_delete_all(RBin *bin); -R_API bool r_bin_file_delete(RBin *bin, ut32 bin_id); -R_API RList *r_bin_file_compute_hashes(RBin *bin, ut64 limit); -R_API RList *r_bin_file_set_hashes(RBin *bin, RList *new_hashes); -R_API RBinPlugin *r_bin_file_cur_plugin(RBinFile *binfile); -R_API void r_bin_file_hash_free(RBinFileHash *fhash); - -// binobject functions -R_API int r_bin_object_set_items(RBinFile *binfile, RBinObject *o); -R_API bool r_bin_object_delete(RBin *bin, ut32 binfile_id); -R_API void r_bin_mem_free(void *data); - -// demangle functions -R_API char *r_bin_demangle(RBinFile *binfile, const char *lang, const char *str, ut64 vaddr, bool libs); -R_API char *r_bin_demangle_java(const char *str); -R_API char *r_bin_demangle_cxx(RBinFile *binfile, const char *str, ut64 vaddr); -R_API char *r_bin_demangle_msvc(const char *str); -R_API char *r_bin_demangle_swift(const char *s, bool syscmd); -R_API char *r_bin_demangle_objc(RBinFile *binfile, const char *sym); -R_API char *r_bin_demangle_rust(RBinFile *binfile, const char *str, ut64 vaddr); -R_API int r_bin_demangle_type(const char *str); -R_API void r_bin_demangle_list(RBin *bin); -R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str); -R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact); - -R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va); - -/* dbginfo.c */ -R_API bool r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line); -R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin); -R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr); -/* bin_write.c */ -R_API bool r_bin_wr_addlib(RBin *bin, const char *lib); -R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size); -R_API bool r_bin_wr_scn_perms(RBin *bin, const char *name, int perms); -R_API bool r_bin_wr_rpath_del(RBin *bin); -R_API bool r_bin_wr_entry(RBin *bin, ut64 addr); -R_API bool r_bin_wr_output(RBin *bin, const char *filename); - -R_API RList *r_bin_get_mem(RBin *bin); - -/* filter.c */ -R_API void r_bin_load_filter(RBin *bin, ut64 rules); -R_API void r_bin_filter_symbols(RBinFile *bf, RList *list); -R_API void r_bin_filter_sections(RBinFile *bf, RList *list); -R_API char *r_bin_filter_name(RBinFile *bf, Sdb *db, ut64 addr, char *name); -R_API void r_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym); -R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 addr); -R_API bool r_bin_string_filter(RBin *bin, const char *str, ut64 addr); - -/* plugin pointers */ -extern RBinPlugin r_bin_plugin_any; -extern RBinPlugin r_bin_plugin_fs; -extern RBinPlugin r_bin_plugin_cgc; -extern RBinPlugin r_bin_plugin_elf; -extern RBinPlugin r_bin_plugin_elf64; -extern RBinPlugin r_bin_plugin_p9; -extern RBinPlugin r_bin_plugin_ne; -extern RBinPlugin r_bin_plugin_le; -extern RBinPlugin r_bin_plugin_pe; -extern RBinPlugin r_bin_plugin_mz; -extern RBinPlugin r_bin_plugin_pe64; -extern RBinPlugin r_bin_plugin_pebble; -extern RBinPlugin r_bin_plugin_bios; -extern RBinPlugin r_bin_plugin_bf; -extern RBinPlugin r_bin_plugin_te; -extern RBinPlugin r_bin_plugin_symbols; -extern RBinPlugin r_bin_plugin_mach0; -extern RBinPlugin r_bin_plugin_mach064; -extern RBinPlugin r_bin_plugin_mdmp; -extern RBinPlugin r_bin_plugin_java; -extern RBinPlugin r_bin_plugin_dex; -extern RBinPlugin r_bin_plugin_coff; -extern RBinPlugin r_bin_plugin_ningb; -extern RBinPlugin r_bin_plugin_ningba; -extern RBinPlugin r_bin_plugin_ninds; -extern RBinPlugin r_bin_plugin_nin3ds; -extern RBinPlugin r_bin_plugin_xbe; -extern RBinPlugin r_bin_plugin_bflt; -extern RBinXtrPlugin r_bin_xtr_plugin_xtr_fatmach0; -extern RBinXtrPlugin r_bin_xtr_plugin_xtr_dyldcache; -extern RBinXtrPlugin r_bin_xtr_plugin_xtr_pemixed; -extern RBinXtrPlugin r_bin_xtr_plugin_xtr_sep64; -extern RBinLdrPlugin r_bin_ldr_plugin_ldr_linux; -extern RBinPlugin r_bin_plugin_zimg; -extern RBinPlugin r_bin_plugin_omf; -extern RBinPlugin r_bin_plugin_art; -extern RBinPlugin r_bin_plugin_bootimg; -extern RBinPlugin r_bin_plugin_dol; -extern RBinPlugin r_bin_plugin_nes; -extern RBinPlugin r_bin_plugin_qnx; -extern RBinPlugin r_bin_plugin_mbn; -extern RBinPlugin r_bin_plugin_smd; -extern RBinPlugin r_bin_plugin_sms; -extern RBinPlugin r_bin_plugin_psxexe; -extern RBinPlugin r_bin_plugin_spc700; -extern RBinPlugin r_bin_plugin_vsf; -extern RBinPlugin r_bin_plugin_dyldcache; -extern RBinPlugin r_bin_plugin_xnu_kernelcache; -extern RBinPlugin r_bin_plugin_avr; -extern RBinPlugin r_bin_plugin_menuet; -extern RBinPlugin r_bin_plugin_wasm; -extern RBinPlugin r_bin_plugin_nro; -extern RBinPlugin r_bin_plugin_nso; -extern RBinPlugin r_bin_plugin_sfc; -extern RBinPlugin r_bin_plugin_z64; -extern RBinPlugin r_bin_plugin_prg; -extern RBinPlugin r_bin_plugin_dmp64; -extern RBinPlugin r_bin_plugin_pyc; - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/libr/include/r_bind.h b/libr/include/r_bind.h deleted file mode 100644 index 519f5213dd..0000000000 --- a/libr/include/r_bind.h +++ /dev/null @@ -1,46 +0,0 @@ -/* radare2 - LGPL - Copyright 2015-2020 - pancake */ - -#ifndef R2_BIND_H -#define R2_BIND_H - -// TODO: move riobind here too? -// TODO: move rprint here too - -typedef int (*RCoreCmd)(void *core, const char *cmd); -typedef int (*RCoreCmdF)(void *user, const char *fmt, ...); -typedef int (*RCoreDebugBpHit)(void *core, void *bp); -typedef void (*RCoreDebugSyscallHit)(void *core); -typedef char* (*RCoreCmdStr)(void *core, const char *cmd); -typedef char* (*RCoreCmdStrF)(void *core, const char *cmd, ...); -typedef void (*RCorePuts)(const char *cmd); -typedef void (*RCoreSetArchBits)(void *core, const char *arch, int bits); -typedef bool (*RCoreIsMapped)(void *core, ut64 addr, int perm); -typedef bool (*RCoreDebugMapsSync)(void *core); -typedef const char *(*RCoreGetName)(void *core, ut64 off); -typedef char *(*RCoreGetNameDelta)(void *core, ut64 off); -typedef void (*RCoreSeekArchBits)(void *core, ut64 addr); -typedef int (*RCoreConfigGetI)(void *core, const char *key); -typedef const char *(*RCoreConfigGet)(void *core, const char *key); -typedef ut64 (*RCoreNumGet)(void *core, const char *str); - -typedef struct r_core_bind_t { - void *core; - RCoreCmd cmd; - RCoreCmdF cmdf; - RCoreCmdStr cmdstr; - RCoreCmdStrF cmdstrf; - RCorePuts puts; - RCoreDebugBpHit bphit; - RCoreDebugSyscallHit syshit; - RCoreSetArchBits setab; - RCoreGetName getName; - RCoreGetNameDelta getNameDelta; - RCoreSeekArchBits archbits; - RCoreConfigGetI cfggeti; - RCoreConfigGet cfgGet; - RCoreNumGet numGet; - RCoreIsMapped isMapped; - RCoreDebugMapsSync syncDebugMaps; -} RCoreBind; - -#endif diff --git a/libr/include/r_binheap.h b/libr/include/r_binheap.h deleted file mode 100644 index 6d4c545b05..0000000000 --- a/libr/include/r_binheap.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef R2_BINHEAP_H -#define R2_BINHEAP_H - -#include "r_vector.h" -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_binheap_t { - RPVector a; - RPVectorComparator cmp; -} RBinHeap; - -R_API void r_binheap_clear(RBinHeap *h); -#define r_binheap_empty(h) (r_pvector_empty (&(h)->a)) -R_API void r_binheap_init(RBinHeap *h, RPVectorComparator cmp); -R_API RBinHeap *r_binheap_new(RPVectorComparator cmp); -R_API void r_binheap_free(RBinHeap *h); -R_API bool r_binheap_push(RBinHeap *h, void *x); -R_API void *r_binheap_pop(RBinHeap *h); -#define r_binheap_top(h) (r_pvector_at(&((h)->a), 0)) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_bp.h b/libr/include/r_bp.h deleted file mode 100644 index 825c02b397..0000000000 --- a/libr/include/r_bp.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef R2_BP_H -#define R2_BP_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_bp); - -#define R_BP_MAXPIDS 10 -#define R_BP_CONT_NORMAL 0 -#define R_BP_CONT_NORMAL 0 - -typedef struct r_bp_arch_t { - int bits; - int length; - int endian; - const ut8 *bytes; -} RBreakpointArch; - -enum { - R_BP_TYPE_SW, - R_BP_TYPE_HW, - R_BP_TYPE_COND, - R_BP_TYPE_FAULT, - R_BP_TYPE_DELETE, -}; - -typedef struct r_bp_plugin_t { - char *name; - char *arch; - int type; // R_BP_TYPE_SW - int nbps; - RBreakpointArch *bps; -} RBreakpointPlugin; - -typedef struct r_bp_item_t { - char *name; - char *module_name; /*module where you get the base address*/ - st64 module_delta; /*delta to apply to module */ - ut64 addr; - ut64 delta; - int size; /* size of breakpoint area */ - int recoil; /* recoil */ - bool swstep; /* is this breakpoint from a swstep? */ - int perm; - int hw; - int trace; - int internal; /* used for internal purposes */ - int enabled; - int togglehits; /* counter that toggles breakpoint on reaching 0 */ - int hits; - ut8 *obytes; /* original bytes */ - ut8 *bbytes; /* breakpoint bytes */ - int pids[R_BP_MAXPIDS]; - char *data; - char *cond; /* used for conditional breakpoints */ - char *expr; /* to be used for named breakpoints (see r_debug_bp_update) */ -} RBreakpointItem; - -struct r_bp_t; -typedef int (*RBreakpointCallback)(struct r_bp_t *bp, RBreakpointItem *b, bool set); - -typedef struct r_bp_t { - void *user; - int stepcont; - int endian; - int bits; - bool bpinmaps; /* Only enable breakpoints inside a valid map */ - RCoreBind corebind; - RIOBind iob; // compile time dependency - RBreakpointPlugin *cur; - RList *traces; // XXX - RList *plugins; - PrintfCallback cb_printf; - RBreakpointCallback breakpoint; - /* storage of breakpoints */ - int nbps; - int nhwbps; - RList *bps; // list of breakpoints - RBreakpointItem **bps_idx; - int bps_idx_count; - st64 delta; - ut64 baddr; -} RBreakpoint; - -// DEPRECATED: USE R_PERM -enum { - R_BP_PROT_EXEC = 1, - R_BP_PROT_WRITE = 2, - R_BP_PROT_READ = 4, - R_BP_PROT_ACCESS = 8, -}; - -typedef struct r_bp_trace_t { - ut64 addr; - ut64 addr_end; - ut8 *traps; - ut8 *buffer; - ut8 *bits; - int length; - int bitlen; -} RBreakpointTrace; - -#ifdef R_API -R_API RBreakpoint *r_bp_new(void); -R_API RBreakpoint *r_bp_free(RBreakpoint *bp); - -R_API int r_bp_del(RBreakpoint *bp, ut64 addr); -R_API int r_bp_del_all(RBreakpoint *bp); - -R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo); -R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits); -R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name); -R_API void r_bp_plugin_list(RBreakpoint *bp); - -R_API int r_bp_in(RBreakpoint *bp, ut64 addr, int perm); -// deprecate? -R_API int r_bp_list(RBreakpoint *bp, int rad); -R_API int r_bp_size(RBreakpoint *bp); - -/* bp item attribs setters */ -R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx); -R_API int r_bp_set_trace(RBreakpoint *bp, ut64 addr, int set); -R_API int r_bp_set_trace_all(RBreakpoint *bp, int set); -R_API RBreakpointItem *r_bp_enable(RBreakpoint *bp, ut64 addr, int set, int count); -R_API int r_bp_enable_all(RBreakpoint *bp, int set); - -/* index api */ -R_API int r_bp_del_index(RBreakpoint *bp, int idx); -R_API RBreakpointItem *r_bp_get_index(RBreakpoint *bp, int idx); -R_API int r_bp_get_index_at (RBreakpoint *bp, ut64 addr); -R_API RBreakpointItem *r_bp_item_new (RBreakpoint *bp); - -R_API RBreakpointItem *r_bp_get_at (RBreakpoint *bp, ut64 addr); -R_API RBreakpointItem *r_bp_get_in (RBreakpoint *bp, ut64 addr, int perm); - -R_API bool r_bp_is_valid(RBreakpoint *bp, RBreakpointItem *b); - -R_API int r_bp_add_cond(RBreakpoint *bp, const char *cond); -R_API int r_bp_del_cond(RBreakpoint *bp, int idx); -R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm); - -R_API RBreakpointItem *r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm); -R_API RBreakpointItem *r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm); -R_API void r_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set); -R_API int r_bp_restore(RBreakpoint *bp, bool set); -R_API bool r_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr); - -/* traptrace */ -R_API void r_bp_traptrace_free(void *ptr); -R_API void r_bp_traptrace_enable(RBreakpoint *bp, int enable); -R_API void r_bp_traptrace_reset(RBreakpoint *bp, int hard); -R_API ut64 r_bp_traptrace_next(RBreakpoint *bp, ut64 addr); -R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to); -R_API int r_bp_traptrace_free_at(RBreakpoint *bp, ut64 from); -R_API void r_bp_traptrace_list(RBreakpoint *bp); -R_API int r_bp_traptrace_at(RBreakpoint *bp, ut64 from, int len); -R_API RList *r_bp_traptrace_new(void); -R_API void r_bp_traptrace_enable(RBreakpoint *bp, int enable); - -/* watchpoint */ -R_API RBreakpointItem *r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int rw); - -/* plugin pointers */ -extern RBreakpointPlugin r_bp_plugin_x86; -extern RBreakpointPlugin r_bp_plugin_arm; -extern RBreakpointPlugin r_bp_plugin_mips; -extern RBreakpointPlugin r_bp_plugin_ppc; -extern RBreakpointPlugin r_bp_plugin_sh; -extern RBreakpointPlugin r_bp_plugin_bf; -#endif -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_cmd.h b/libr/include/r_cmd.h deleted file mode 100644 index 4e955ffb4d..0000000000 --- a/libr/include/r_cmd.h +++ /dev/null @@ -1,314 +0,0 @@ -#ifndef R2_CMD_H -#define R2_CMD_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_core_t RCore; - -//R_LIB_VERSION_HEADER (r_cmd); - -#define MACRO_LIMIT 1024 -#define MACRO_LABELS 20 -#define R_CMD_MAXLEN 4096 - -typedef enum r_cmd_status_t { - R_CMD_STATUS_OK = 0, // command handler exited in the right way - R_CMD_STATUS_WRONG_ARGS, // command handler could not handle the arguments passed to it - R_CMD_STATUS_ERROR, // command handler had issues while running (e.g. allocation error, etc.) - R_CMD_STATUS_INVALID, // command could not be executed (e.g. shell level error, not existing command, bad expression, etc.) - R_CMD_STATUS_EXIT, // command handler asks to exit the prompt loop -} RCmdStatus; - -typedef int (*RCmdCb) (void *user, const char *input); -typedef RCmdStatus (*RCmdArgvCb) (RCore *core, int argc, const char **argv); -typedef int (*RCmdNullCb) (void *user); - -typedef struct r_cmd_parsed_args_t { - int argc; - char **argv; - bool has_space_after_cmd; -} RCmdParsedArgs; - -typedef struct r_cmd_macro_label_t { - char name[80]; - char *ptr; -} RCmdMacroLabel; - -typedef struct r_cmd_macro_item_t { - char *name; - char *args; - char *code; - int codelen; - int nargs; -} RCmdMacroItem; - -typedef struct r_cmd_macro_t { - int counter; - ut64 *brk_value; - ut64 _brk_value; - int brk; -// int (*cmd)(void *user, const char *cmd); - RCoreCmd cmd; - PrintfCallback cb_printf; - void *user; - RNum *num; - int labels_n; - RCmdMacroLabel labels[MACRO_LABELS]; - RList *macros; -} RCmdMacro; - -typedef struct r_cmd_item_t { - char cmd[64]; - RCmdCb callback; -} RCmdItem; - -typedef struct r_cmd_alias_t { - int count; - char **keys; - char **values; - int *remote; -} RCmdAlias; - -typedef struct r_cmd_desc_example_t { - const char *example; - const char *comment; -} RCmdDescExample; - -/** - * Define how the command looks like in the help. - */ -typedef struct r_cmd_desc_help_t { - /** - * Short-sentence explaining what the command does. - * This is shown, for example, when the list of sub-commands is printed - * and each sub-command has a very short description on the right, - * explaining what it does. - */ - const char *summary; - /** - * Long description of what the command does. It can be as long as you - * want and it should explain well how the command behaves. - * This is shown, for example, when `??` is appended on command or `?` - * is appended and the command has no children to show. In that case, - * the short summary is extended with this longer description. - * - * Optional. - */ - const char *description; - /** - * String used to identify the arguments. This usually comes together - * with the summary. - * TODO: explain how to differentiate between required and optional arguments - */ - const char *args_str; - /** - * String that overrides the name+args_str usually used to describe the - * command. - * - * Optional. - */ - const char *usage; - /** - * String to use as sub-commands suggestions instead of the - * auto-generated one (e.g. [abcd] or [?] that you can see near command - * names when doing `w?`). If not provided, the options will be - * auto-generated. - * - * Optional. - */ - const char *options; - /** - * List of examples used to better explain how to use the command. This - * is shown together with the long description. - * - * Optional. - */ - const RCmdDescExample *examples; -} RCmdDescHelp; - -typedef enum { - // for old handlers that parse their own input and accept a single string - R_CMD_DESC_TYPE_OLDINPUT = 0, - // for handlers that accept argc/argv - R_CMD_DESC_TYPE_ARGV, - // for cmd descriptors that are just used to group together related - // sub-commands. Do not use this if the command can be used by itself or - // if it's necessary to show its help, because this descriptor is not - // stored in the hashtable and cannot be retrieved except by listing the - // children of its parent. - R_CMD_DESC_TYPE_INNER, - // for cmd descriptors that are parent of other sub-commands but that - // may also have a sub-command with the same name. For example, `wc` is - // both the parent of `wci`, `wc*`, etc. but there is also `wc` as a - // sub-command. - R_CMD_DESC_TYPE_GROUP, -} RCmdDescType; - -typedef struct r_cmd_desc_t { - RCmdDescType type; - char *name; - struct r_cmd_desc_t *parent; - int n_children; - RPVector children; - const RCmdDescHelp *help; - - union { - struct { - RCmdCb cb; - } oldinput_data; - struct { - RCmdArgvCb cb; - } argv_data; - struct { - struct r_cmd_desc_t *exec_cd; - } group_data; - } d; -} RCmdDesc; - -typedef struct r_cmd_t { - void *data; - RCmdNullCb nullcallback; - RCmdItem *cmds[UT8_MAX]; - RCmdMacro macro; - RList *lcmds; - RList *plist; - RCmdAlias aliases; - void *language; // used to store TSLanguage * - HtUP *ts_symbols_ht; - RCmdDesc *root_cmd_desc; - HtPP *ht_cmds; -} RCmd; - -// TODO: remove this once transitioned to RCmdDesc -typedef struct r_cmd_descriptor_t { - const char *cmd; - const char **help_msg; - const char **help_detail; - const char **help_detail2; - struct r_cmd_descriptor_t *sub[127]; -} RCmdDescriptor; - -// TODO: move into r_core.h -typedef struct r_core_plugin_t { - const char *name; - const char *desc; - const char *license; - const char *author; - const char *version; - RCmdCb call; // returns true if command was handled, false otherwise. - RCmdCb init; - RCmdCb fini; -} RCorePlugin; - -#define DEFINE_CMD_ARGV_DESC_DETAIL(core, name, c_name, parent, handler, help) \ - RCmdDesc *c_name##_cd = r_cmd_desc_argv_new (core->rcmd, parent, #name, handler, help); \ - r_warn_if_fail (c_name##_cd) -#define DEFINE_CMD_ARGV_DESC_SPECIAL(core, name, c_name, parent) \ - DEFINE_CMD_ARGV_DESC_DETAIL (core, name, c_name, parent, c_name##_handler, &c_name##_help) -#define DEFINE_CMD_ARGV_DESC_INNER(core, name, c_name, parent) \ - RCmdDesc *c_name##_cd = r_cmd_desc_inner_new (core->rcmd, parent, #name, &c_name##_help); \ - r_warn_if_fail (c_name##_cd) -#define DEFINE_CMD_ARGV_GROUP_WITH_CHILD(core, name, parent) \ - RCmdDesc *name##_cd = r_cmd_desc_group_new (core->rcmd, parent, #name, name##_handler, &name##_help, &name##_group_help); \ - r_warn_if_fail (name##_cd) -#define DEFINE_CMD_ARGV_DESC(core, name, parent) \ - DEFINE_CMD_ARGV_DESC_SPECIAL (core, name, name, parent) -#define DEFINE_CMD_OLDINPUT_DESC(core, name, parent) \ - RCmdDesc *name##_cd = r_cmd_desc_oldinput_new (core->rcmd, parent, #name, name##_handler_old, &name##_help); \ - r_warn_if_fail (name##_cd) - -#ifdef R_API -R_API int r_core_plugin_init(RCmd *cmd); -R_API int r_core_plugin_add(RCmd *cmd, RCorePlugin *plugin); -R_API int r_core_plugin_check(RCmd *cmd, const char *a0); -R_API int r_core_plugin_fini(RCmd *cmd); - -R_API RCmd *r_cmd_new(void); -R_API RCmd *r_cmd_free(RCmd *cmd); -R_API int r_cmd_set_data(RCmd *cmd, void *data); -R_API int r_cmd_add(RCmd *cmd, const char *command, RCmdCb callback); -R_API int r_core_del(RCmd *cmd, const char *command); -R_API int r_cmd_call(RCmd *cmd, const char *command); -R_API RCmdStatus r_cmd_call_parsed_args(RCmd *cmd, RCmdParsedArgs *args); -R_API RCmdDesc *r_cmd_get_root(RCmd *cmd); -R_API RCmdDesc *r_cmd_get_desc(RCmd *cmd, const char *cmd_identifier); -R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color); - -static inline RCmdStatus r_cmd_int2status(int v) { - if (v == -2) { - return R_CMD_STATUS_EXIT; - } else if (v < 0) { - return R_CMD_STATUS_ERROR; - } else { - return R_CMD_STATUS_OK; - } -} - -static inline int r_cmd_status2int(RCmdStatus s) { - switch (s) { - case R_CMD_STATUS_OK: - return 0; - case R_CMD_STATUS_ERROR: - case R_CMD_STATUS_WRONG_ARGS: - case R_CMD_STATUS_INVALID: - return -1; - case R_CMD_STATUS_EXIT: - default: - return -2; - } -} - -/* RCmdDescriptor */ -R_API RCmdDesc *r_cmd_desc_argv_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArgvCb cb, const RCmdDescHelp *help); -R_API RCmdDesc *r_cmd_desc_inner_new(RCmd *cmd, RCmdDesc *parent, const char *name, const RCmdDescHelp *help); -R_API RCmdDesc *r_cmd_desc_group_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArgvCb cb, const RCmdDescHelp *help, const RCmdDescHelp *group_help); -R_API RCmdDesc *r_cmd_desc_oldinput_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdCb cb, const RCmdDescHelp *help); -R_API RCmdDesc *r_cmd_desc_parent(RCmdDesc *cd); -R_API bool r_cmd_desc_has_handler(RCmdDesc *cd); -R_API bool r_cmd_desc_remove(RCmd *cmd, RCmdDesc *cd); - -#define r_cmd_desc_children_foreach(root, it_cd) r_pvector_foreach (&root->children, it_cd) - -/* RCmdParsedArgs */ -R_API RCmdParsedArgs *r_cmd_parsed_args_new(const char *cmd, int n_args, char **args); -R_API RCmdParsedArgs *r_cmd_parsed_args_newcmd(const char *cmd); -R_API RCmdParsedArgs *r_cmd_parsed_args_newargs(int n_args, char **args); -R_API void r_cmd_parsed_args_free(RCmdParsedArgs *args); -R_API bool r_cmd_parsed_args_setargs(RCmdParsedArgs *arg, int n_args, char **args); -R_API bool r_cmd_parsed_args_setcmd(RCmdParsedArgs *arg, const char *cmd); -R_API char *r_cmd_parsed_args_argstr(RCmdParsedArgs *arg); -R_API char *r_cmd_parsed_args_execstr(RCmdParsedArgs *arg); -R_API const char *r_cmd_parsed_args_cmd(RCmdParsedArgs *arg); - -#define r_cmd_parsed_args_foreach_arg(args, i, arg) for ((i) = 1; (i) < (args->argc) && ((arg) = (args)->argv[i]); (i)++) - -/* r_cmd_macro */ -R_API RCmdMacroItem *r_cmd_macro_item_new(void); -R_API void r_cmd_macro_item_free(RCmdMacroItem *item); -R_API void r_cmd_macro_init(RCmdMacro *mac); -R_API int r_cmd_macro_add(RCmdMacro *mac, const char *name); -R_API int r_cmd_macro_rm(RCmdMacro *mac, const char *_name); -R_API void r_cmd_macro_list(RCmdMacro *mac); -R_API void r_cmd_macro_meta(RCmdMacro *mac); -R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name); -R_API int r_cmd_macro_break(RCmdMacro *mac, const char *value); - -R_API bool r_cmd_alias_del(RCmd *cmd, const char *k); -R_API char **r_cmd_alias_keys(RCmd *cmd, int *sz); -R_API int r_cmd_alias_set(RCmd *cmd, const char *k, const char *v, int remote); -R_API char *r_cmd_alias_get(RCmd *cmd, const char *k, int remote); -R_API void r_cmd_alias_free(RCmd *cmd); -R_API void r_cmd_macro_fini(RCmdMacro *mac); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/libr/include/r_config.h b/libr/include/r_config.h deleted file mode 100644 index 8d6c3720ad..0000000000 --- a/libr/include/r_config.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef R2_CONFIG_H -#define R2_CONFIG_H - -#include "r_types.h" -#include "r_util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_config); - -#define CN_BOOL 0x000001 -#define CN_INT 0x000002 -// NOTE: removed because this is redundant and it does not add any value -// compared to CN_INT. Use that instead for consistency -// #define CN_OFFT 0x000004 -#define CN_STR 0x000008 -#define CN_RO 0x000010 -#define CN_RW 0x000020 - -typedef bool (*RConfigCallback)(void *user, void *data); - -typedef struct r_config_node_t { - char *name; - int flags; - char *value; - ut64 i_value; - ut64 *cb_ptr_q; - int *cb_ptr_i; - char **cb_ptr_s; - RConfigCallback getter; - RConfigCallback setter; - char *desc; - RList *options; -} RConfigNode; - -R_API const char *r_config_node_type(RConfigNode *node); - -typedef struct r_config_t { - int lock; - void *user; - RNum *num; - PrintfCallback cb_printf; - RList *nodes; - HtPP *ht; -} RConfig; - -typedef struct r_config_hold_num_t { - char *key; - ut64 value; -} RConfigHoldNum; - -typedef struct r_config_hold_char_t { - char *key; - char *value; -} RConfigHoldChar; - -typedef struct r_config_hold_t { - RConfig *cfg; - RList *list_num; //list of RConfigHoldNum to hold numeric values - RList *list_char; //list of RConfigHoldChar to hold char values -} RConfigHold; - -#ifdef R_API -R_API RConfigHold* r_config_hold_new(RConfig *cfg); -R_API void r_config_hold_free(RConfigHold *h); - -R_API bool r_config_hold_i(RConfigHold *h, ...); -R_API bool r_config_hold_s(RConfigHold *h, ...); - -R_API void r_config_hold_restore(RConfigHold *h); - -R_API RConfig *r_config_new(void *user); -R_API RConfig *r_config_clone (RConfig *cfg); -R_API void r_config_free(RConfig *cfg); -R_API void r_config_lock(RConfig *cfg, int l); -R_API bool r_config_eval(RConfig *cfg, const char *str, bool many); -R_API void r_config_bump(RConfig *cfg, const char *key); -R_API RConfigNode *r_config_set_i(RConfig *cfg, const char *name, const ut64 i); -R_API RConfigNode *r_config_set_cb(RConfig *cfg, const char *name, const char *value, bool (*callback)(void *user, void *data)); -R_API RConfigNode *r_config_set_i_cb(RConfig *cfg, const char *name, int ivalue, bool (*callback)(void *user, void *data)); -R_API RConfigNode *r_config_set(RConfig *cfg, const char *name, const char *value); -R_API bool r_config_rm(RConfig *cfg, const char *name); -R_API ut64 r_config_get_i(RConfig *cfg, const char *name); -R_API const char *r_config_get(RConfig *cfg, const char *name); -R_API const char *r_config_desc(RConfig *cfg, const char *name, const char *desc); -R_API const char *r_config_node_desc(RConfigNode *node, const char *desc); -R_API void r_config_list(RConfig *cfg, const char *str, int rad); -R_API RConfigNode *r_config_node_get(RConfig *cfg, const char *name); -R_API RConfigNode *r_config_node_new(const char *name, const char *value); -R_API void r_config_node_free(void *n); -R_API void r_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i, R_NULLABLE RConfigNode *node); -R_API bool r_config_toggle(RConfig *cfg, const char *name); -R_API bool r_config_readonly (RConfig *cfg, const char *key); - -R_API void r_config_set_sort_column (char *column); -R_API bool r_config_set_setter (RConfig *cfg, const char *key, RConfigCallback cb); -R_API bool r_config_set_getter (RConfig *cfg, const char *key, RConfigCallback cb); - -R_API void r_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db); -R_API bool r_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err); - -static inline bool r_config_node_is_bool(RConfigNode *node) { - return node->flags & CN_BOOL; -} -static inline bool r_config_node_is_int(RConfigNode *node) { - return node->flags & CN_INT; -} -static inline bool r_config_node_is_ro(RConfigNode *node) { - return node->flags & CN_RO; -} -static inline bool r_config_node_is_str(RConfigNode *node) { - return node->flags & CN_STR; -} -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_core.h b/libr/include/r_core.h deleted file mode 100644 index 5dbc829b9e..0000000000 --- a/libr/include/r_core.h +++ /dev/null @@ -1,971 +0,0 @@ -/* radare - LGPL - Copyright 2009-2020 - pancake */ - -#ifndef R2_CORE_H -#define R2_CORE_H - -#include -#include "r_socket.h" -#include "r_types.h" -#include "r_magic.h" -#include "r_agraph.h" -#include "r_io.h" -#include "r_fs.h" -#include "r_lib.h" -#include "r_diff.h" -#include "r_egg.h" -#include "r_lang.h" -#include "r_asm.h" -#include "r_parse.h" -#include "r_anal.h" -#include "r_cmd.h" -#include "r_cons.h" -#include "r_search.h" -#include "r_sign.h" -#include "r_debug.h" -#include "r_flag.h" -#include "r_config.h" -#include "r_bin.h" -#include "r_hash.h" -#include "r_util.h" -#include "r_util/r_print.h" -#include "r_crypto.h" -#include "r_bind.h" -#include "r_util/r_annotated_code.h" - -#ifdef __cplusplus -extern "C" { -#endif -R_LIB_VERSION_HEADER(r_core); - -#define R_CORE_CMD_OK 0 -#define R_CORE_CMD_INVALID -1 -#define R_CORE_CMD_EXIT -2 - -#define R_CORE_BLOCKSIZE 0x100 -#define R_CORE_BLOCKSIZE_MAX 0x3200000 /* 32MB */ - -#define R_CORE_ANAL_GRAPHLINES 1 -#define R_CORE_ANAL_GRAPHBODY 2 -#define R_CORE_ANAL_GRAPHDIFF 4 -#define R_CORE_ANAL_JSON 8 -#define R_CORE_ANAL_KEYVALUE 16 -#define R_CORE_ANAL_JSON_FORMAT_DISASM 32 -#define R_CORE_ANAL_STAR 64 - -#define R_FLAGS_FS_CLASSES "classes" -#define R_FLAGS_FS_FUNCTIONS "functions" -#define R_FLAGS_FS_IMPORTS "imports" -#define R_FLAGS_FS_RELOCS "relocs" -#define R_FLAGS_FS_RESOURCES "resources" -#define R_FLAGS_FS_SECTIONS "sections" -#define R_FLAGS_FS_SEGMENTS "segments" -#define R_FLAGS_FS_SIGNS "sign" -#define R_FLAGS_FS_STRINGS "strings" -#define R_FLAGS_FS_SYMBOLS "symbols" -#define R_FLAGS_FS_SYMBOLS_SECTIONS "symbols.sections" -#define R_FLAGS_FS_SYSCALLS "syscalls" - -#define R_GRAPH_FORMAT_NO 0 -#define R_GRAPH_FORMAT_GMLFCN 1 -#define R_GRAPH_FORMAT_JSON 2 -#define R_GRAPH_FORMAT_GML 3 -#define R_GRAPH_FORMAT_DOT 4 -#define R_GRAPH_FORMAT_CMD 5 - -/// -#define R_CONS_COLOR_DEF(x, def) ((core->cons && core->cons->context->pal.x)? core->cons->context->pal.x: def) -#define R_CONS_COLOR(x) R_CONS_COLOR_DEF (x, "") - -/* rtr */ -#define RTR_PROTOCOL_RAP 0 -#define RTR_PROTOCOL_TCP 1 -#define RTR_PROTOCOL_UDP 2 -#define RTR_PROTOCOL_HTTP 3 -#define RTR_PROTOCOL_UNIX 4 - -#define RTR_MAX_HOSTS 255 - -/* visual mode */ -typedef enum { - R_CORE_VISUAL_MODE_PX = 0, - R_CORE_VISUAL_MODE_PD = 1, - R_CORE_VISUAL_MODE_DB = 2, - R_CORE_VISUAL_MODE_OV = 3, - R_CORE_VISUAL_MODE_CD = 4 -} RCoreVisualMode; - -/* -#define R_CORE_VISUAL_MODE_PC 4 -#define R_CORE_VISUAL_MODE_PXA 5 -#define R_CORE_VISUAL_MODE_PSS 6 -#define R_CORE_VISUAL_MODE_PRC 7 -#define R_CORE_VISUAL_MODE_PXa 8 -#define R_CORE_VISUAL_MODE_PXR 9 -*/ - -typedef struct r_core_rtr_host_t { - int proto; - char host[512]; - int port; - char file[1024]; - RSocket *fd; -} RCoreRtrHost; - -typedef struct r_core_undo_t { - char *action; - char *revert; - ut64 tstamp; - ut64 offset; -} RCoreUndo; - -typedef enum { - AUTOCOMPLETE_DEFAULT, - AUTOCOMPLETE_MS -} RAutocompleteType; - -typedef struct { - ut64 addr; - const char *glob; - ut64 minstamp; -} RCoreUndoCondition; - -typedef struct r_core_log_t { - int first; - int last; - RStrpool *sp; -} RCoreLog; - -typedef struct r_core_file_t { - int dbg; - int fd; - RBinBind binb; - const struct r_core_t *core; - ut8 alive; -} RCoreFile; - - -typedef struct r_core_times_t { - ut64 loadlibs_init_time; - ut64 loadlibs_time; - ut64 file_open_time; -} RCoreTimes; - -#define R_CORE_ASMQJMPS_NUM 10 -#define R_CORE_ASMQJMPS_LETTERS 26 -#define R_CORE_ASMQJMPS_MAX_LETTERS (26 * 26 * 26 * 26 * 26) -#define R_CORE_ASMQJMPS_LEN_LETTERS 5 - -typedef enum r_core_autocomplete_types_t { - R_CORE_AUTOCMPLT_DFLT = 0, - R_CORE_AUTOCMPLT_FLAG, - R_CORE_AUTOCMPLT_FLSP, - R_CORE_AUTOCMPLT_SEEK, - R_CORE_AUTOCMPLT_FCN, - R_CORE_AUTOCMPLT_ZIGN, - R_CORE_AUTOCMPLT_EVAL, - R_CORE_AUTOCMPLT_PRJT, - R_CORE_AUTOCMPLT_MINS, - R_CORE_AUTOCMPLT_BRKP, - R_CORE_AUTOCMPLT_MACR, - R_CORE_AUTOCMPLT_FILE, - R_CORE_AUTOCMPLT_THME, - R_CORE_AUTOCMPLT_OPTN, - R_CORE_AUTOCMPLT_MS, - R_CORE_AUTOCMPLT_SDB, -// --- left as last always - R_CORE_AUTOCMPLT_END, -} RCoreAutocompleteType; - -typedef struct r_core_autocomplete_t { - const char* cmd; - int length; - int n_subcmds; - bool locked; - int type; - struct r_core_autocomplete_t** subcmds; -} RCoreAutocomplete; - -typedef struct r_core_visual_tab_t { - int printidx; - ut64 offset; - bool cur_enabled; - int cur; - int ocur; - int cols; - int disMode; - int hexMode; - int asm_offset; - int asm_instr; - int asm_indent; - int asm_bytes; - int asm_cmt_col; - int printMode; - int current3format; - int current4format; - int current5format; - int dumpCols; - char name[32]; // XXX leak because no r_core_visual_tab_free - // TODO: cursor and such -} RCoreVisualTab; -// #define RCoreVisualTab Tab - -typedef struct r_core_visual_t { - RList *tabs; - int tab; -} RCoreVisual; -// #define RCoreVisual Visual - -typedef struct { - int x; - int y; - int w; - int h; - char *cmd; -} RCoreGadget; - -R_API void r_core_gadget_free (RCoreGadget *g); - -typedef struct r_core_tasks_t { - int task_id_next; - RList *tasks; - RList *tasks_queue; - RList *oneshot_queue; - int oneshots_enqueued; - struct r_core_task_t *current_task; - struct r_core_task_t *main_task; - RThreadLock *lock; - int tasks_running; - bool oneshot_running; -} RCoreTaskScheduler; - -struct r_core_t { - RBin *bin; - RConfig *config; - ut64 offset; // current seek - ut64 prompt_offset; // temporarily set to offset to have $$ in expressions always stay the same during temp seeks - ut32 blocksize; - ut32 blocksize_max; - ut8 *block; - RBuffer *yank_buf; - ut64 yank_addr; - bool tmpseek; - bool vmode; - int interrupted; // XXX IS THIS DUPPED SOMEWHERE? - /* files */ - RCons *cons; - RIO *io; - RCoreFile *file; - RList *files; - RNum *num; - ut64 rc; // command's return code .. related to num->value; - RLib *lib; - RCmd *rcmd; - RCmdDescriptor root_cmd_descriptor; - RList/**/ *cmd_descriptors; - RAnal *anal; - RAsm *rasm; - /* ^^ */ - RCoreTimes *times; - RParse *parser; - RPrint *print; - RLang *lang; - RDebug *dbg; - RFlag *flags; - RSearch *search; - RFS *fs; - RFSShell *rfs; - REgg *egg; - RCoreLog *log; - RAGraph *graph; - RPanelsRoot *panels_root; - RPanels* panels; - char *cmdqueue; - char *lastcmd; - char *cmdlog; - bool cfglog; // cfg.corelog - int cmdrepeat; // cmd.repeat - const char *cmdtimes; // cmd.times - R_DEPRECATE bool cmd_in_backticks; // whether currently executing a cmd out of backticks - int rtr_n; - RCoreRtrHost rtr_host[RTR_MAX_HOSTS]; - ut64 *asmqjmps; - int asmqjmps_count; - int asmqjmps_size; - bool is_asmqjmps_letter; - bool keep_asmqjmps; - RCoreVisual visual; - // visual // TODO: move them into RCoreVisual - int http_up; - int gdbserver_up; - RCoreVisualMode printidx; - char *stkcmd; - bool in_search; - RList *watchers; - RList *scriptstack; - RCoreTaskScheduler tasks; - int max_cmd_depth; - ut8 switch_file_view; - Sdb *sdb; - int incomment; - int curtab; // current tab - int seltab; // selected tab - char *cmdremote; - char *lastsearch; - char *cmdfilter; - bool break_loop; - RList *undos; - bool binat; - bool fixedbits; // will be true when using @b: - bool fixedarch; // will be true when using @a: - bool fixedblock; - char *table_query; - int sync_index; // used for http.sync and T= - struct r_core_t *c2; - RCoreAutocomplete *autocomplete; - int autocomplete_type; - int maxtab; - REvent *ev; - RList *gadgets; - bool scr_gadgets; - bool log_events; // core.c:cb_event_handler : log actions from events if cfg.log.events is set - RList *ropchain; - bool use_tree_sitter_r2cmd; - - bool marks_init; - ut64 marks[UT8_MAX + 1]; - - RMainCallback r_main_radare2; - // int (*r_main_radare2)(int argc, char **argv); - int (*r_main_rafind2)(int argc, const char **argv); - int (*r_main_radiff2)(int argc, const char **argv); - int (*r_main_rabin2)(int argc, const char **argv); - int (*r_main_rarun2)(int argc, const char **argv); - int (*r_main_ragg2)(int argc, const char **argv); - int (*r_main_rasm2)(int argc, const char **argv); - int (*r_main_rax2)(int argc, const char **argv); -}; - -// maybe move into RAnal -typedef struct r_core_item_t { - const char *type; - ut64 addr; - ut64 next; - ut64 prev; - int size; - int perm; - char *data; - char *comment; - char *sectname; - char *fcnname; -} RCoreItem; - - -R_API RCoreItem *r_core_item_at (RCore *core, ut64 addr); -R_API void r_core_item_free (RCoreItem *ci); - -R_API int r_core_bind(RCore *core, RCoreBind *bnd); - -typedef struct r_core_cmpwatch_t { - ut64 addr; - int size; - char cmd[32]; - ut8 *odata; - ut8 *ndata; -} RCoreCmpWatcher; - -typedef int (*RCoreSearchCallback)(RCore *core, ut64 from, ut8 *buf, int len); - -#ifdef R_API -//#define r_core_ncast(x) (RCore*)(size_t)(x) -R_API RList *r_core_list_themes(RCore *core); -R_API char *r_core_get_theme(void); -R_API const char *r_core_get_section_name(RCore *core, ut64 addr); -R_API RCons *r_core_get_cons(RCore *core); -R_API RBin *r_core_get_bin(RCore *core); -R_API RConfig *r_core_get_config (RCore *core); -R_API bool r_core_init(RCore *core); -R_API void r_core_bind_cons(RCore *core); // to restore pointers in cons -R_API RCore *r_core_new(void); -R_API void r_core_free(RCore *core); -R_API void r_core_fini(RCore *c); -R_API void r_core_wait(RCore *core); -R_API RCore *r_core_ncast(ut64 p); -R_API RCore *r_core_cast(void *p); -R_API bool r_core_bin_load_structs(RCore *core, const char *file); -R_API int r_core_config_init(RCore *core); -R_API void r_core_config_update(RCore *core); -R_API void r_core_parse_radare2rc(RCore *r); -R_API int r_core_prompt(RCore *core, int sync); -R_API int r_core_prompt_exec(RCore *core); -R_API int r_core_lines_initcache (RCore *core, ut64 start_addr, ut64 end_addr); -R_API int r_core_lines_currline (RCore *core); -R_API void r_core_prompt_loop(RCore *core); -R_API ut64 r_core_pava(RCore *core, ut64 addr); -R_API int r_core_cmd(RCore *core, const char *cmd, int log); -R_API int r_core_cmd_task_sync(RCore *core, const char *cmd, bool log); -R_API char *r_core_editor(const RCore *core, const char *file, const char *str); -R_API int r_core_fgets(char *buf, int len); -R_API RFlagItem *r_core_flag_get_by_spaces(RFlag *f, ut64 off); -R_API int r_core_cmdf(RCore *core, const char *fmt, ...); -R_API int r_core_flush(RCore *core, const char *cmd); -R_API int r_core_cmd0(RCore *core, const char *cmd); -R_API void r_core_cmd_init(RCore *core); -R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd); -R_API char *r_core_cmd_str(RCore *core, const char *cmd); -R_API char *r_core_cmd_strf(RCore *core, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API char *r_core_cmd_str_pipe(RCore *core, const char *cmd); -R_API int r_core_cmd_file(RCore *core, const char *file); -R_API int r_core_cmd_lines(RCore *core, const char *lines); -R_API int r_core_cmd_command(RCore *core, const char *command); -R_API bool r_core_run_script (RCore *core, const char *file); -R_API bool r_core_seek(RCore *core, ut64 addr, bool rb); -R_API bool r_core_visual_bit_editor(RCore *core); -R_API int r_core_seek_base (RCore *core, const char *hex); -R_API void r_core_seek_previous (RCore *core, const char *type); -R_API void r_core_seek_next (RCore *core, const char *type); -R_API int r_core_seek_align(RCore *core, ut64 align, int count); -R_API void r_core_arch_bits_at(RCore *core, ut64 addr, R_OUT R_NULLABLE int *bits, R_OUT R_BORROW R_NULLABLE const char **arch); -R_API void r_core_seek_arch_bits(RCore *core, ut64 addr); -R_API int r_core_block_read(RCore *core); -R_API int r_core_block_size(RCore *core, int bsize); -R_API int r_core_seek_size(RCore *core, ut64 addr, int bsize); -R_API int r_core_is_valid_offset (RCore *core, ut64 offset); -R_API int r_core_shift_block(RCore *core, ut64 addr, ut64 b_size, st64 dist); -R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type); -R_API void r_core_print_scrollbar(RCore *core); -R_API void r_core_print_scrollbar_bottom(RCore *core); -R_API void r_core_visual_prompt_input (RCore *core); -R_API void r_core_visual_toggle_decompiler_disasm(RCore *core, bool for_graph, bool reset); -R_API void r_core_visual_applyDisMode(RCore *core, int disMode); -R_API void r_core_visual_applyHexMode(RCore *core, int hexMode); -R_API int r_core_visual_refs(RCore *core, bool xref, bool fcnInsteadOfAddr); -R_API void r_core_visual_append_help(RStrBuf *p, const char *title, const char **help); -R_API bool r_core_prevop_addr(RCore* core, ut64 start_addr, int numinstrs, ut64* prev_addr); -R_API ut64 r_core_prevop_addr_force(RCore *core, ut64 start_addr, int numinstrs); -R_API bool r_core_visual_hudstuff(RCore *core); -R_API int r_core_visual_classes(RCore *core); -R_API int r_core_visual_anal_classes(RCore *core); -R_API int r_core_visual_types(RCore *core); -R_API int r_core_visual(RCore *core, const char *input); -R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int is_interactive); -R_API bool r_core_visual_panels_root(RCore *core, RPanelsRoot *panels_root); -R_API void r_core_visual_browse(RCore *core, const char *arg); -R_API int r_core_visual_cmd(RCore *core, const char *arg); -R_API void r_core_visual_seek_animation (RCore *core, ut64 addr); -R_API void r_core_visual_asm(RCore *core, ut64 addr); -R_API void r_core_visual_colors(RCore *core); -R_API int r_core_visual_xrefs_x(RCore *core); -R_API int r_core_visual_xrefs_X(RCore *core); -R_API void r_core_visual_showcursor(RCore *core, int x); -R_API void r_core_visual_offset(RCore *core); -R_API int r_core_visual_hud(RCore *core); -R_API void r_core_visual_jump(RCore *core, ut8 ch); -R_API void r_core_visual_disasm_up(RCore *core, int *cols); -R_API void r_core_visual_disasm_down(RCore *core, RAsmOp *op, int *cols); -R_API RBinReloc *r_core_getreloc(RCore *core, ut64 addr, int size); -R_API ut64 r_core_get_asmqjmps(RCore *core, const char *str); -R_API void r_core_set_asmqjmps(RCore *core, char *str, size_t len, int i); -R_API char* r_core_add_asmqjmp(RCore *core, ut64 addr); - -R_API void r_core_anal_type_init(RCore *core); -R_API void r_core_link_stroff(RCore *core, RAnalFunction *fcn); -R_API void r_core_anal_inflags (RCore *core, const char *glob); -R_API bool cmd_anal_objc (RCore *core, const char *input, bool auto_anal); -R_API void r_core_anal_cc_init(RCore *core); -R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json); -R_API void r_core_anal_esil_graph(RCore *core, const char *expr); - -R_API void r_core_list_io(RCore *core); -R_API RListInfo *r_listinfo_new (const char *name, RInterval pitv, RInterval vitv, int perm, const char *extra); -R_API void r_listinfo_free (RListInfo *info); -/* visual marks */ -R_API void r_core_visual_mark_seek(RCore *core, ut8 ch); -R_API void r_core_visual_mark(RCore *core, ut8 ch); -R_API void r_core_visual_mark_set(RCore *core, ut8 ch, ut64 addr); -R_API void r_core_visual_mark_del(RCore *core, ut8 ch); -R_API bool r_core_visual_mark_dump(RCore *core); -R_API void r_core_visual_mark_reset(RCore *core); - -R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb); -R_API bool r_core_serve(RCore *core, RIODesc *fd); -R_API int r_core_file_reopen(RCore *core, const char *args, int perm, int binload); -R_API void r_core_file_reopen_debug(RCore *core, const char *args); -R_API void r_core_file_reopen_remote_debug(RCore *core, char *uri, ut64 addr); -R_API RCoreFile * r_core_file_find_by_fd(RCore* core, ut64 fd); -R_API RCoreFile * r_core_file_find_by_name (RCore * core, const char * name); -R_API RCoreFile * r_core_file_cur (RCore *r); -R_API int r_core_file_set_by_fd(RCore *core, ut64 fd); -R_API int r_core_file_set_by_name(RCore *core, const char * name); -R_API int r_core_file_set_by_file (RCore * core, RCoreFile *cf); -R_API int r_core_setup_debugger (RCore *r, const char *debugbackend, bool attach); - -R_API void r_core_file_free(RCoreFile *cf); -R_API RCoreFile *r_core_file_open(RCore *core, const char *file, int flags, ut64 loadaddr); -R_API RCoreFile *r_core_file_open_many(RCore *r, const char *file, int flags, ut64 loadaddr); -R_API RCoreFile *r_core_file_get_by_fd(RCore *core, int fd); -R_API int r_core_file_close(RCore *core, RCoreFile *fh); -R_API bool r_core_file_close_fd(RCore *core, int fd); -R_API bool r_core_file_close_all_but(RCore *core); -R_API int r_core_file_list(RCore *core, int mode); -R_API int r_core_file_binlist(RCore *core); -R_API bool r_core_file_bin_raise(RCore *core, ut32 num); -R_API int r_core_seek_delta(RCore *core, st64 addr); -R_API bool r_core_extend_at(RCore *core, ut64 addr, int size); -R_API bool r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size); -R_API int r_core_write_op(RCore *core, const char *arg, char op); -R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op); -R_API int r_core_set_file_by_fd (RCore * core, ut64 bin_fd); -R_API int r_core_set_file_by_name (RBin * bin, const char * name); -R_API ut32 r_core_file_cur_fd (RCore *core); - -R_API void r_core_debug_rr (RCore *core, RReg *reg, int mode); - -/* fortune */ -R_API void r_core_fortune_list_types(void); -R_API void r_core_fortune_list(RCore *core); -R_API void r_core_fortune_print_random(RCore *core); - -/* project */ -R_API bool r_core_project_load(RCore *core, const char *prjfile, const char *rcfile); -R_API RThread *r_core_project_load_bg(RCore *core, const char *prjfile, const char *rcfile); -R_API void r_core_project_execute_cmds(RCore *core, const char *prjfile); - -#define R_CORE_FOREIGN_ADDR -1 -R_API int r_core_yank(RCore *core, ut64 addr, int len); -R_API int r_core_yank_string(RCore *core, ut64 addr, int maxlen); -R_API bool r_core_yank_hexpair(RCore *core, const char *input); -R_API int r_core_yank_paste(RCore *core, ut64 addr, int len); -R_API int r_core_yank_set (RCore *core, ut64 addr, const ut8 *buf, ut32 len); // set yank buffer bytes -R_API int r_core_yank_set_str (RCore *core, ut64 addr, const char *buf, ut32 len); // Null terminate the bytes -R_API int r_core_yank_to(RCore *core, const char *arg); -R_API bool r_core_yank_dump (RCore *core, ut64 pos, int format); -R_API int r_core_yank_hexdump (RCore *core, ut64 pos); -R_API int r_core_yank_cat (RCore *core, ut64 pos); -R_API int r_core_yank_cat_string (RCore *core, ut64 pos); -R_API int r_core_yank_hud_file (RCore *core, const char *input); -R_API int r_core_yank_hud_path (RCore *core, const char *input, int dir); -R_API bool r_core_yank_file_ex (RCore *core, const char *input); -R_API int r_core_yank_file_all (RCore *core, const char *input); - -#define R_CORE_LOADLIBS_ENV 1 -#define R_CORE_LOADLIBS_HOME 2 -#define R_CORE_LOADLIBS_SYSTEM 4 -#define R_CORE_LOADLIBS_CONFIG 8 -#define R_CORE_LOADLIBS_ALL UT32_MAX - -R_API void r_core_loadlibs_init(RCore *core); -R_API int r_core_loadlibs(RCore *core, int where, const char *path); -R_API int r_core_cmd_buffer(RCore *core, const char *buf); -R_API int r_core_cmdf(RCore *core, const char *fmt, ...); -R_API int r_core_cmd0(RCore *core, const char *cmd); -R_API char *r_core_cmd_str(RCore *core, const char *cmd); -R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each); -R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each); -R_API char *r_core_op_str(RCore *core, ut64 addr); -R_API RAnalOp *r_core_op_anal(RCore *core, ut64 addr, RAnalOpMask mask); -R_API char *r_core_disassemble_instr(RCore *core, ut64 addr, int l); -R_API char *r_core_disassemble_bytes(RCore *core, ut64 addr, int b); - -/* carg.c */ -R_API RList *r_core_get_func_args(RCore *core, const char *func_name); -R_API void r_core_print_func_args(RCore *core); -R_API char *resolve_fcn_name(RAnal *anal, const char * func_name); -R_API int r_core_get_stacksz(RCore *core, ut64 from, ut64 to); - -/* anal.c */ -R_API RAnalOp* r_core_anal_op(RCore *core, ut64 addr, int mask); -R_API void r_core_anal_esil(RCore *core, const char *str, const char *addr); -R_API void r_core_anal_fcn_merge (RCore *core, ut64 addr, ut64 addr2); -R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbose); -R_API ut64 r_core_anal_address (RCore *core, ut64 addr); -R_API void r_core_anal_undefine (RCore *core, ut64 off); -R_API void r_core_anal_hint_print (RAnal* a, ut64 addr, int mode); -R_API void r_core_anal_hint_list (RAnal *a, int mode); -R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode); -R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad); -R_API int r_core_anal_data (RCore *core, ut64 addr, int count, int depth, int wordsize); -R_API void r_core_anal_datarefs(RCore *core, ut64 addr); -R_API void r_core_anal_coderefs(RCore *core, ut64 addr); -R_API void r_core_anal_codexrefs(RCore *core, ut64 addr); -R_API void r_core_anal_importxrefs(RCore *core); -R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt); -R_API int r_core_anal_refs(RCore *core, const char *input); -R_API void r_core_agraph_print(RCore *core, int use_utf, const char *input); -R_API bool r_core_esil_cmd(RAnalEsil *esil, const char *cmd, ut64 a1, ut64 a2); -R_API int r_core_esil_step(RCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver); -R_API int r_core_esil_step_back(RCore *core); -R_API ut64 r_core_anal_get_bbaddr(RCore *core, ut64 addr); -R_API bool r_core_anal_bb_seek(RCore *core, ut64 addr); -R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth); -R_API char *r_core_anal_fcn_autoname(RCore *core, ut64 addr, int dump, int mode); -R_API void r_core_anal_autoname_all_fcns(RCore *core); -R_API void r_core_anal_autoname_all_golang_fcns(RCore *core); -R_API int r_core_anal_fcn_list(RCore *core, const char *input, const char *rad); -R_API char *r_core_anal_fcn_name(RCore *core, RAnalFunction *fcn); -R_API ut64 r_core_anal_fcn_list_size(RCore *core); -R_API void r_core_anal_fcn_labels(RCore *core, RAnalFunction *fcn, int rad); -R_API int r_core_anal_fcn_clean(RCore *core, ut64 addr); -R_API int r_core_print_bb_custom(RCore *core, RAnalFunction *fcn); -R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn); -R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts); -R_API int r_core_anal_graph_fcn(RCore *core, char *input, int opts); -R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n); -R_API int r_core_anal_ref_list(RCore *core, int rad); -R_API int r_core_anal_all(RCore *core); -R_API RList* r_core_anal_cycles (RCore *core, int ccl); -R_API RList *r_core_anal_fcn_get_calls (RCore *core, RAnalFunction *fcn); // get all calls from a function - -/*tp.c*/ -R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn); - -/* asm.c */ -#define R_MIDFLAGS_SHOW 1 -#define R_MIDFLAGS_REALIGN 2 -#define R_MIDFLAGS_SYMALIGN 3 - -typedef struct r_core_asm_hit { - char *code; - int len; - ut64 addr; - ut8 valid; -} RCoreAsmHit; - -R_API RBuffer *r_core_syscall (RCore *core, const char *name, const char *args); -R_API RBuffer *r_core_syscallf (RCore *core, const char *name, const char *fmt, ...) R_PRINTF_CHECK(3, 4); -R_API RCoreAsmHit *r_core_asm_hit_new(void); -R_API RList *r_core_asm_hit_list_new(void); -R_API void r_core_asm_hit_free(void *_hit); -R_API void r_core_set_asm_configs(RCore *core, char *arch, ut32 bits, int segoff); -R_API char* r_core_asm_search(RCore *core, const char *input); -R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode); -R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len); -R_API RList *r_core_asm_back_disassemble_instr (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding); -R_API RList *r_core_asm_back_disassemble_byte (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding); -R_API ut32 r_core_asm_bwdis_len (RCore* core, int* len, ut64* start_addr, ut32 l); -R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, int lines, int invbreak, int nbytes, bool json, PJ *pj, RAnalFunction *pdf); -R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int len, int lines, PJ *pj); -R_API int r_core_print_disasm_instructions_with_buf(RCore *core, ut64 address, ut8 *buf, int nb_bytes, int nb_opcodes); -R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opcodes); -R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mode); -R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 nb_opcodes, ut32 nb_bytes, int fmt); -R_API int r_core_disasm_pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt); -R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode); -R_API int r_core_print_fcn_disasm(RPrint *p, RCore *core, ut64 addr, int l, int invbreak, int cbytes); -R_API int r_core_get_prc_cols(RCore *core); -R_API int r_core_flag_in_middle(RCore *core, ut64 at, int oplen, int *midflags); -R_API int r_core_bb_starts_in_middle(RCore *core, ut64 at, int oplen); - -R_API bool r_core_bin_raise (RCore *core, ut32 bfid); - -R_API int r_core_bin_set_env (RCore *r, RBinFile *binfile); -R_API int r_core_bin_set_by_fd (RCore *core, ut64 bin_fd); -R_API int r_core_bin_set_by_name (RCore *core, const char *name); -R_API int r_core_bin_reload(RCore *core, const char *file, ut64 baseaddr); -R_API bool r_core_bin_load(RCore *core, const char *file, ut64 baseaddr); -R_API int r_core_bin_rebase(RCore *core, ut64 baddr); -R_API void r_core_bin_export_info(RCore *core, int mode); -R_API int r_core_bin_list(RCore *core, int mode); -R_API bool r_core_bin_delete (RCore *core, ut32 binfile_idx); -R_API ut64 r_core_bin_impaddr(RBin *bin, int va, const char *name); - -// XXX - this is kinda hacky, maybe there should be a way to -// refresh the bin environment without specific calls? -R_API int r_core_pseudo_code (RCore *core, const char *input); - -/* gdiff.c */ -R_API int r_core_zdiff(RCore *c, RCore *c2); -R_API int r_core_gdiff(RCore *core1, RCore *core2); -R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2); - -R_API bool r_core_project_open(RCore *core, const char *file, bool thready); -R_API int r_core_project_cat(RCore *core, const char *name); -R_API int r_core_project_delete(RCore *core, const char *prjfile); -R_API int r_core_project_list(RCore *core, int mode); -R_API bool r_core_project_save_script(RCore *core, const char *file, int opts); -R_API bool r_core_project_save(RCore *core, const char *file); -R_API char *r_core_project_info(RCore *core, const char *file); -R_API char *r_core_project_notes_file (RCore *core, const char *file); - -R_API char *r_core_sysenv_begin(RCore *core, const char *cmd); -R_API void r_core_sysenv_end(RCore *core, const char *cmd); - -R_API void r_core_recover_vars(RCore *core, RAnalFunction *fcn, bool argonly); -// XXX dupe from r_bin.h -/* bin.c */ -#define R_CORE_BIN_ACC_STRINGS 0x001 -#define R_CORE_BIN_ACC_INFO 0x002 -#define R_CORE_BIN_ACC_MAIN 0x004 -#define R_CORE_BIN_ACC_ENTRIES 0x008 -#define R_CORE_BIN_ACC_RELOCS 0x010 -#define R_CORE_BIN_ACC_IMPORTS 0x020 -#define R_CORE_BIN_ACC_SYMBOLS 0x040 -#define R_CORE_BIN_ACC_SECTIONS 0x080 -#define R_CORE_BIN_ACC_FIELDS 0x100 -#define R_CORE_BIN_ACC_LIBS 0x200 -#define R_CORE_BIN_ACC_CLASSES 0x400 -#define R_CORE_BIN_ACC_DWARF 0x800 -#define R_CORE_BIN_ACC_SIZE 0x1000 -#define R_CORE_BIN_ACC_PDB 0x2000 -#define R_CORE_BIN_ACC_MEM 0x4000 -#define R_CORE_BIN_ACC_EXPORTS 0x8000 -#define R_CORE_BIN_ACC_VERSIONINFO 0x10000 -#define R_CORE_BIN_ACC_SIGNATURE 0x20000 -#define R_CORE_BIN_ACC_RAW_STRINGS 0x40000 -#define R_CORE_BIN_ACC_HEADER 0x80000 -#define R_CORE_BIN_ACC_RESOURCES 0x100000 -#define R_CORE_BIN_ACC_INITFINI 0x200000 -#define R_CORE_BIN_ACC_SEGMENTS 0x400000 -#define R_CORE_BIN_ACC_SOURCE 0x800000 -#define R_CORE_BIN_ACC_HASHES 0x10000000 -#define R_CORE_BIN_ACC_TRYCATCH 0x20000000 -#define R_CORE_BIN_ACC_SECTIONS_MAPPING 0x40000000 -#define R_CORE_BIN_ACC_ALL 0x504FFF - -#define R_CORE_PRJ_FLAGS 0x0001 -#define R_CORE_PRJ_EVAL 0x0002 -#define R_CORE_PRJ_IO_MAPS 0x0004 -#define R_CORE_PRJ_SECTIONS 0x0008 -#define R_CORE_PRJ_META 0x0010 -#define R_CORE_PRJ_XREFS 0x0020 -#define R_CORE_PRJ_FCNS 0x0040 -#define R_CORE_PRJ_ANAL_HINTS 0x0080 -#define R_CORE_PRJ_ANAL_TYPES 0x0100 -#define R_CORE_PRJ_ANAL_MACROS 0x0200 -#define R_CORE_PRJ_ANAL_SEEK 0x0400 -#define R_CORE_PRJ_DBG_BREAK 0x0800 -#define R_CORE_PRJ_ALL 0xFFFF - -typedef struct r_core_bin_filter_t { - ut64 offset; - const char *name; -} RCoreBinFilter; - -R_API int r_core_bin_info (RCore *core, int action, int mode, int va, RCoreBinFilter *filter, const char *chksum); -R_API int r_core_bin_set_arch_bits (RCore *r, const char *name, const char * arch, ut16 bits); -R_API int r_core_bin_update_arch_bits (RCore *r); -R_API char *r_core_bin_method_flags_str(ut64 flags, int mode); -R_API bool r_core_pdb_info(RCore *core, const char *file, int mode); - -/* rtr */ -R_API int r_core_rtr_cmds (RCore *core, const char *port); -R_API char *r_core_rtr_cmds_query (RCore *core, const char *host, const char *port, const char *cmd); -R_API void r_core_rtr_help(RCore *core); -R_API void r_core_rtr_pushout(RCore *core, const char *input); -R_API void r_core_rtr_list(RCore *core); -R_API void r_core_rtr_add(RCore *core, const char *input); -R_API void r_core_rtr_remove(RCore *core, const char *input); -R_API void r_core_rtr_session(RCore *core, const char *input); -R_API void r_core_rtr_cmd(RCore *core, const char *input); -R_API int r_core_rtr_http(RCore *core, int launch, int browse, const char *path); -R_API int r_core_rtr_http_stop(RCore *u); -R_API int r_core_rtr_gdb(RCore *core, int launch, const char *path); - -R_API int r_core_visual_prevopsz(RCore *core, ut64 addr); -R_API void r_core_visual_config(RCore *core); -R_API void r_core_visual_mounts(RCore *core); -R_API void r_core_visual_anal(RCore *core, const char *input); -R_API void r_core_visual_debugtraces(RCore *core, const char *input); -R_API void r_core_seek_next(RCore *core, const char *type); -R_API void r_core_seek_previous(RCore *core, const char *type); -R_API void r_core_visual_define(RCore *core, const char *arg, int distance); -R_API int r_core_visual_trackflags(RCore *core); -R_API int r_core_visual_view_graph(RCore *core); -R_API int r_core_visual_view_zigns(RCore *core); -R_API int r_core_visual_view_rop(RCore *core); -R_API int r_core_visual_comments(RCore *core); -R_API int r_core_visual_prompt(RCore *core); -R_API bool r_core_visual_esil (RCore *core); -R_API int r_core_search_preludes(RCore *core, bool log); -R_API int r_core_search_prelude(RCore *core, ut64 from, ut64 to, const ut8 *buf, int blen, const ut8 *mask, int mlen); -R_API RList* /**/ r_core_get_boundaries_prot (RCore *core, int protection, const char *mode, const char *prefix); - -R_API int r_core_patch (RCore *core, const char *patch); - -R_API void r_core_hack_help(const RCore *core); -R_API int r_core_hack(RCore *core, const char *op); -R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append); -R_API void r_core_diff_show(RCore *core, RCore *core2); -R_API void r_core_clippy(RCore *core, const char *msg); - -/* watchers */ -R_API void r_core_cmpwatch_free (RCoreCmpWatcher *w); -R_API RCoreCmpWatcher *r_core_cmpwatch_get (RCore *core, ut64 addr); -R_API int r_core_cmpwatch_add (RCore *core, ut64 addr, int size, const char *cmd); -R_API int r_core_cmpwatch_del (RCore *core, ut64 addr); -R_API int r_core_cmpwatch_update (RCore *core, ut64 addr); -R_API int r_core_cmpwatch_show (RCore *core, ut64 addr, int mode); -R_API int r_core_cmpwatch_revert (RCore *core, ut64 addr); - -/* undo */ -R_API RCoreUndo *r_core_undo_new(ut64 offset, const char *action, const char *revert); -R_API void r_core_undo_print(RCore *core, int mode, RCoreUndoCondition *cond); -R_API void r_core_undo_free(RCoreUndo *cu); -R_API void r_core_undo_push(RCore *core, RCoreUndo *cu); -R_API void r_core_undo_pop(RCore *core); - -/* logs */ -typedef int (*RCoreLogCallback)(RCore *core, int count, const char *message); -R_API void r_core_log_free(RCoreLog *log); -R_API void r_core_log_init (RCoreLog *log); -R_API char *r_core_log_get(RCore *core, int index); -R_API RCoreLog *r_core_log_new (void); -R_API bool r_core_log_run(RCore *core, const char *buf, RCoreLogCallback cb); -R_API int r_core_log_list(RCore *core, int n, int count, char fmt); -R_API void r_core_log_add(RCore *core, const char *msg); -R_API void r_core_log_del(RCore *core, int n); - -// TODO MOVE SOMEWHERE ELSE -typedef char *(*PrintItemCallback)(void *user, void *p, bool selected); -R_API char *r_str_widget_list(void *user, RList *list, int rows, int cur, PrintItemCallback cb); -/* help */ -R_API void r_core_cmd_help(const RCore *core, const char * help[]); - -/* anal stats */ - -typedef struct { - ut32 youarehere; - ut32 flags; - ut32 comments; - ut32 functions; - ut32 blocks; - ut32 in_functions; - ut32 symbols; - ut32 strings; - ut32 perm; -} RCoreAnalStatsItem; -typedef struct { - RCoreAnalStatsItem *block; -} RCoreAnalStats; - -R_API bool core_anal_bbs(RCore *core, const char* input); -R_API bool core_anal_bbs_range (RCore *core, const char* input); -R_API char *r_core_anal_hasrefs(RCore *core, ut64 value, bool verbose); -R_API char *r_core_anal_get_comments(RCore *core, ut64 addr); -R_API RCoreAnalStats* r_core_anal_get_stats (RCore *a, ut64 from, ut64 to, ut64 step); -R_API void r_core_anal_stats_free (RCoreAnalStats *s); - -R_API void r_core_syscmd_ls(const char *input); -R_API void r_core_syscmd_cat(const char *file); -R_API void r_core_syscmd_mkdir(const char *dir); - -R_API int r_line_hist_offset_up(RLine *line); -R_API int r_line_hist_offset_down(RLine *line); - -// TODO : move into debug or syscall++ -R_API char *cmd_syscall_dostr(RCore *core, st64 num, ut64 addr); - -/* tasks */ - -typedef void (*RCoreTaskCallback)(void *user, char *out); - -typedef enum { - R_CORE_TASK_STATE_BEFORE_START, - R_CORE_TASK_STATE_RUNNING, - R_CORE_TASK_STATE_SLEEPING, - R_CORE_TASK_STATE_DONE -} RTaskState; - -typedef struct r_core_task_t { - int id; - RTaskState state; - bool transient; // delete when finished - int refcount; - RThreadSemaphore *running_sem; - void *user; - RCore *core; - bool dispatched; - RThreadCond *dispatch_cond; - RThreadLock *dispatch_lock; - RThread *thread; - char *cmd; - char *res; - bool cmd_log; - RConsContext *cons_context; - RCoreTaskCallback cb; -} RCoreTask; - -typedef void (*RCoreTaskOneShot)(void *); - -R_API void r_core_echo(RCore *core, const char *msg); -R_API RTable *r_core_table(RCore *core); - -R_API void r_core_task_scheduler_init (RCoreTaskScheduler *tasks, RCore *core); -R_API void r_core_task_scheduler_fini (RCoreTaskScheduler *tasks); -R_API RCoreTask *r_core_task_get(RCoreTaskScheduler *scheduler, int id); -R_API RCoreTask *r_core_task_get_incref(RCoreTaskScheduler *scheduler, int id); -R_API void r_core_task_print(RCore *core, RCoreTask *task, int mode); -R_API void r_core_task_list(RCore *core, int mode); -R_API int r_core_task_running_tasks_count(RCoreTaskScheduler *scheduler); -R_API const char *r_core_task_status(RCoreTask *task); -R_API RCoreTask *r_core_task_new(RCore *core, bool create_cons, const char *cmd, RCoreTaskCallback cb, void *user); -R_API void r_core_task_incref(RCoreTask *task); -R_API void r_core_task_decref(RCoreTask *task); -R_API void r_core_task_enqueue(RCoreTaskScheduler *scheduler, RCoreTask *task); -R_API void r_core_task_enqueue_oneshot(RCoreTaskScheduler *scheduler, RCoreTaskOneShot func, void *user); -R_API int r_core_task_run_sync(RCoreTaskScheduler *scheduler, RCoreTask *task); -R_API void r_core_task_sync_begin(RCoreTaskScheduler *scheduler); -R_API void r_core_task_sync_end(RCoreTaskScheduler *scheduler); -R_API void r_core_task_yield(RCoreTaskScheduler *scheduler); -R_API void r_core_task_sleep_begin(RCoreTask *task); -R_API void r_core_task_sleep_end(RCoreTask *task); -R_API void r_core_task_break(RCoreTaskScheduler *scheduler, int id); -R_API void r_core_task_break_all(RCoreTaskScheduler *scheduler); -R_API int r_core_task_del(RCoreTaskScheduler *scheduler, int id); -R_API void r_core_task_del_all_done(RCoreTaskScheduler *scheduler); -R_API RCoreTask *r_core_task_self(RCoreTaskScheduler *scheduler); -R_API void r_core_task_join(RCoreTaskScheduler *scheduler, RCoreTask *current, int id); -typedef void (*inRangeCb) (RCore *core, ut64 from, ut64 to, int vsize, - int count, void *cb_user); -R_API int r_core_search_value_in_range (RCore *core, RInterval search_itv, - ut64 vmin, ut64 vmax, int vsize, inRangeCb cb, void *cb_user); - -R_API RCoreAutocomplete *r_core_autocomplete_add(RCoreAutocomplete *parent, const char* cmd, int type, bool lock); -R_API void r_core_autocomplete_free(RCoreAutocomplete *obj); -R_API void r_core_autocomplete_reload (RCore *core); -R_API RCoreAutocomplete *r_core_autocomplete_find(RCoreAutocomplete *parent, const char* cmd, bool exact); -R_API bool r_core_autocomplete_remove(RCoreAutocomplete *parent, const char* cmd); -R_API void r_core_anal_propagate_noreturn(RCore *core, ut64 addr); - -/* PLUGINS */ -extern RCorePlugin r_core_plugin_java; -extern RCorePlugin r_core_plugin_a2f; - -/* DECOMPILER PRINTING FUNCTIONS */ -/** - * @brief Prints the data contained in the specified RAnnotatedCode in JSON format. - * - * The function will print the output in console using the function r_cons_printf(); - * - * @param code Pointer to a RAnnotatedCode. - */ -R_API void r_core_annotated_code_print_json(RAnnotatedCode *code); -/** - * @brief Prints the decompiled code from the specified RAnnotatedCode. - * - * This function is used for printing the output of commands pdg and pdgo. - * It can print the decompiled code with or without offsets. If line_offsets is a null pointer, - * the output will be printed without offsets (pdg), otherwise, the output will be - * printed with offsets. - * This function will print the output in console using the function r_cons_printf(); - * - * @param code Pointer to a RAnnotatedCode. - * @param line_offsets Pointer to a @ref RVector that contains offsets for the decompiled code. - */ -R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offsets); -/** - * @brief Prints the decompiled code as comments - * - * This function is used for the output of command pdg* - * Output will be printed in console using the function r_cons_printf(); - * - * @param code Pointer to a RAnnotatedCode. - */ -R_API void r_core_annotated_code_print_comment_cmds(RAnnotatedCode *code); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_crypto.h b/libr/include/r_crypto.h deleted file mode 100644 index 9dacfb933f..0000000000 --- a/libr/include/r_crypto.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef R2_CRYPTO_H -#define R2_CRYPTO_H - -#include "r_types.h" -#include "r_list.h" -#include "r_crypto/r_des.h" - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_crypto); - -enum { - R_CRYPTO_MODE_ECB, - R_CRYPTO_MODE_CBC, - R_CRYPTO_MODE_OFB, - R_CRYPTO_MODE_CFB, -}; - -enum { - R_CRYPTO_DIR_CIPHER, - R_CRYPTO_DIR_DECIPHER, -}; - -typedef struct r_crypto_t { - struct r_crypto_plugin_t* h; - ut8 *key; - ut8 *iv; - int key_len; - ut8 *output; - int output_len; - int output_size; - int dir; - void *user; - RList *plugins; -} RCrypto; - -typedef struct r_crypto_plugin_t { - const char *name; - const char *license; - int (*get_key_size)(RCrypto *cry); - bool (*set_iv)(RCrypto *cry, const ut8 *iv, int ivlen); - bool (*set_key)(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction); - bool (*update)(RCrypto *cry, const ut8 *buf, int len); - bool (*final)(RCrypto *cry, const ut8 *buf, int len); - bool (*use)(const char *algo); - int (*fini)(RCrypto *cry); -} RCryptoPlugin; - -typedef ut64 RCryptoSelector; - -#ifdef R_API -R_API RCrypto *r_crypto_init(RCrypto *cry, int hard); -R_API RCrypto *r_crypto_as_new(RCrypto *cry); -R_API int r_crypto_add(RCrypto *cry, RCryptoPlugin *h); -R_API RCrypto *r_crypto_new(void); -R_API RCrypto *r_crypto_free(RCrypto *cry); -R_API bool r_crypto_use(RCrypto *cry, const char *algo); -R_API bool r_crypto_set_key(RCrypto *cry, const ut8* key, int keylen, int mode, int direction); -R_API bool r_crypto_set_iv(RCrypto *cry, const ut8 *iv, int ivlen); -R_API int r_crypto_update(RCrypto *cry, const ut8 *buf, int len); -R_API int r_crypto_final(RCrypto *cry, const ut8 *buf, int len); -R_API int r_crypto_append(RCrypto *cry, const ut8 *buf, int len); -R_API ut8 *r_crypto_get_output(RCrypto *cry, int *size); -R_API const char *r_crypto_name(const RCryptoSelector bit); -R_API const char *r_crypto_codec_name(const RCryptoSelector bit); -#endif - -/* plugin pointers */ -extern RCryptoPlugin r_crypto_plugin_aes; -extern RCryptoPlugin r_crypto_plugin_des; -extern RCryptoPlugin r_crypto_plugin_rc4; -extern RCryptoPlugin r_crypto_plugin_xor; -extern RCryptoPlugin r_crypto_plugin_blowfish; -extern RCryptoPlugin r_crypto_plugin_rc2; -extern RCryptoPlugin r_crypto_plugin_rot; -extern RCryptoPlugin r_crypto_plugin_rol; -extern RCryptoPlugin r_crypto_plugin_ror; -extern RCryptoPlugin r_crypto_plugin_base64; -extern RCryptoPlugin r_crypto_plugin_base91; -extern RCryptoPlugin r_crypto_plugin_aes_cbc; -extern RCryptoPlugin r_crypto_plugin_punycode; -extern RCryptoPlugin r_crypto_plugin_rc6; -extern RCryptoPlugin r_crypto_plugin_cps2; -extern RCryptoPlugin r_crypto_plugin_serpent; - -#define R_CRYPTO_NONE 0ULL -#define R_CRYPTO_RC2 1ULL -#define R_CRYPTO_RC4 1ULL<<1 -#define R_CRYPTO_RC6 1ULL<<2 -#define R_CRYPTO_AES_ECB 1ULL<<3 -#define R_CRYPTO_AES_CBC 1ULL<<4 -#define R_CRYPTO_ROR 1ULL<<5 -#define R_CRYPTO_ROL 1ULL<<6 -#define R_CRYPTO_ROT 1ULL<<7 -#define R_CRYPTO_BLOWFISH 1ULL<<8 -#define R_CRYPTO_CPS2 1ULL<<9 -#define R_CRYPTO_DES_ECB 1ULL<<10 -#define R_CRYPTO_XOR 1ULL<<11 -#define R_CRYPTO_SERPENT 1ULL<<12 -#define R_CRYPTO_ALL 0xFFFF - -#define R_CODEC_NONE 0ULL -#define R_CODEC_B64 1ULL -#define R_CODEC_B91 1ULL<<1 -#define R_CODEC_PUNYCODE 1ULL<<2 -#define R_CODEC_ALL 0xFFFF - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_crypto/r_des.h b/libr/include/r_crypto/r_des.h deleted file mode 100644 index 5194afe18b..0000000000 --- a/libr/include/r_crypto/r_des.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef R_DES_H -#define R_DES_H - -#define DES_KEY_SIZE 8 -#define DES_BLOCK_SIZE 8 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct des_context_t { - ut32 round_key_lo[16]; // round key low - ut32 round_key_hi[16]; // round key hi - int round; -} RDESContext; - -R_API void r_des_permute_key (ut32 *keylo, ut32 *keyhi); -R_API void r_des_permute_block0 (ut32 *blocklo, ut32 *blockhi); -R_API void r_des_permute_block1 (ut32 *blocklo, ut32 *blockhi); -R_API void r_des_round_key (int i, ut32 *keylo, ut32 *keyhi, ut32 *deskeylo, ut32 *deskeyhi); -R_API void r_des_round (ut32 *buflo, ut32 *bufhi, ut32 *roundkeylo, ut32 *roundkeyhi); - -#ifdef __cplusplus -} -#endif - -#endif // R_DES_H diff --git a/libr/include/r_debug.h b/libr/include/r_debug.h deleted file mode 100644 index 0535546b79..0000000000 --- a/libr/include/r_debug.h +++ /dev/null @@ -1,655 +0,0 @@ -#ifndef R2_DEBUG_H -#define R2_DEBUG_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "r_bind.h" -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_debug); - -/* hack to fix compilation of debugger on BSD systems */ -/* This needs some testing (netbsd, freebsd, openbsd, kfreebsd) */ -#if __BSD__ -#include - -/* hakish hack to hack the openbsd/sparc64 hack */ -#undef reg -#undef fpreg -#undef fpstate -#undef trapframe -#undef rwindow - -#ifdef PTRACE_SYSCALL -/* on freebsd does not have the same meaning */ -#undef PTRACE_SYSCALL -#endif - -#define PTRACE_PEEKTEXT PT_READ_I -#define PTRACE_POKETEXT PT_WRITE_I -#define PTRACE_PEEKDATA PT_READ_D -#define PTRACE_POKEDATA PT_WRITE_D -#define PTRACE_ATTACH PT_ATTACH -#define PTRACE_DETACH PT_DETACH -#define PTRACE_SINGLESTEP PT_STEP -#define PTRACE_CONT PT_CONTINUE -#define PTRACE_GETREGS PT_GETREGS -#define PTRACE_SETREGS PT_SETREGS -#define PTRACE_SYSCALL PT_STEP -#endif - -#define SNAP_PAGE_SIZE 4096 -#define CHECK_POINT_LIMIT 0x100000 //TODO: take the benchmark -/* - * states that a process can be in - */ -typedef enum { - R_DBG_PROC_STOP = 's', - R_DBG_PROC_RUN = 'r', - R_DBG_PROC_SLEEP = 'S', - R_DBG_PROC_ZOMBIE = 'z', - R_DBG_PROC_DEAD = 'd', - R_DBG_PROC_RAISED = 'R' // has produced a signal, breakpoint, etc.. -} RDebugPidState; - - -// signal handling must support application and debugger level options -typedef enum { - R_DBG_SIGNAL_IGNORE = 0, // ignore signal handler - R_DBG_SIGNAL_CONT = 1, // pass signal to chlidren and continue execution - R_DBG_SIGNAL_SKIP = 2, // - //.. -} RDebugSignalMode; - - -/* - * when a user wants to resume from a breakpoint, we need to know how they want - * to proceed. these values indicate their intention. - */ -typedef enum { - R_DBG_RECOIL_NONE = 0, - R_DBG_RECOIL_STEP, - R_DBG_RECOIL_CONTINUE -} RDebugRecoilMode; - -/* - * List of reasons that an inferior might have stopped - */ -typedef enum { - R_DEBUG_REASON_DEAD = -1, - R_DEBUG_REASON_NONE = 0, - R_DEBUG_REASON_SIGNAL, - R_DEBUG_REASON_SEGFAULT, - R_DEBUG_REASON_BREAKPOINT, - R_DEBUG_REASON_TRACEPOINT, - R_DEBUG_REASON_COND, - R_DEBUG_REASON_READERR, - R_DEBUG_REASON_STEP, - R_DEBUG_REASON_ABORT, - R_DEBUG_REASON_WRITERR, - R_DEBUG_REASON_DIVBYZERO, - R_DEBUG_REASON_ILLEGAL, - R_DEBUG_REASON_UNKNOWN, - R_DEBUG_REASON_ERROR, - R_DEBUG_REASON_NEW_PID, - R_DEBUG_REASON_NEW_TID, - R_DEBUG_REASON_NEW_LIB, - R_DEBUG_REASON_EXIT_PID, - R_DEBUG_REASON_EXIT_TID, - R_DEBUG_REASON_EXIT_LIB, - R_DEBUG_REASON_TRAP, - R_DEBUG_REASON_SWI, - R_DEBUG_REASON_INT, - R_DEBUG_REASON_FPU, - R_DEBUG_REASON_USERSUSP, -} RDebugReasonType; - - -/* TODO: move to r_anal */ -typedef struct r_debug_frame_t { - ut64 addr; - int size; - ut64 sp; - ut64 bp; -} RDebugFrame; - -typedef struct r_debug_reason_t { - int /*RDebugReasonType*/ type; - int tid; - int signum; - ut64 bp_addr; - ut64 timestamp; - ut64 addr; - ut64 ptr; -} RDebugReason; - -typedef struct r_debug_map_t { - char *name; - ut64 addr; - ut64 addr_end; - ut64 size; - ut64 offset; - char *file; - int perm; - int user; - bool shared; -} RDebugMap; - -typedef struct r_debug_signal_t { - int type; - int num; - ut64 handler; -} RDebugSignal; - -typedef struct r_debug_desc_t { - int fd; - char *path; - int perm; - int type; - ut64 off; -} RDebugDesc; - -typedef struct r_debug_snap_t { - char *name; - ut64 addr; - ut64 addr_end; - ut32 size; - ut8 *data; - int perm; - int user; - bool shared; -} RDebugSnap; - -typedef struct { - int cnum; - ut64 data; -} RDebugChangeReg; - -typedef struct { - int cnum; - ut8 data; -} RDebugChangeMem; - -typedef struct r_debug_checkpoint_t { - int cnum; - RRegArena *arena[R_REG_TYPE_LAST]; - RList *snaps; // -} RDebugCheckpoint; - -typedef struct r_debug_session_t { - ut32 cnum; - ut32 maxcnum; - RDebugCheckpoint *cur_chkpt; - RVector *checkpoints; /* RVector */ - HtUP *memory; /* RVector */ - HtUP *registers; /* RVector */ - int reasontype /*RDebugReasonType*/; - RBreakpointItem *bp; -} RDebugSession; - -/* Session file format */ -typedef struct r_session_header { - ut64 addr; - ut32 id; - ut32 difflist_len; -} RSessionHeader; - -typedef struct r_diff_entry { - ut32 base_idx; - ut32 pages_len; -} RDiffEntry; - -typedef struct r_snap_entry { - ut64 addr; - ut32 size; - ut64 timestamp; - int perm; -} RSnapEntry; - -typedef struct r_debug_trace_t { - RList *traces; - int count; - int enabled; - //int changed; - int tag; - int dup; - char *addresses; - // TODO: add range here - HtPP *ht; -} RDebugTrace; - -typedef struct r_debug_tracepoint_t { - ut64 addr; - ut64 tags; // XXX - int tag; // XXX - int size; - int count; - int times; - ut64 stamp; -} RDebugTracepoint; - -typedef struct r_debug_t { - char *arch; - int bits; /// XXX: MUST SET /// - int hitinfo; - - int main_pid; - int pid; /* selected process id */ - int tid; /* selected thread id */ - int forked_pid; /* last pid created by fork */ - int n_threads; - RList *threads; /* NOTE: list contents are platform-specific */ - - char *malloc; /*choose malloc parser: 0 = glibc, 1 = jemalloc*/ - - /* dbg.* config options (see e?dbg) - * NOTE: some settings are checked inline instead of tracked here. - */ - int bpsize; /* size of a breakpoint */ - char *btalgo; /* select backtrace algorithm */ - int btdepth; /* backtrace depth */ - int regcols; /* display columns */ - int swstep; /* steps with software traps */ - int stop_all_threads; /* stop all threads at any stop */ - int trace_forks; /* stop on new children */ - int trace_execs; /* stop on new execs */ - int trace_aftersyscall; /* stop after the syscall (before if disabled) */ - int trace_clone; /* stop on new threads */ - int follow_child; /* On fork, trace the child */ - char *glob_libs; /* stop on lib load */ - char *glob_unlibs; /* stop on lib unload */ - bool consbreak; /* SIGINT handle for attached processes */ - bool continue_all_threads; - - /* tracking debugger state */ - int steps; /* counter of steps done */ - RDebugReason reason; /* stop reason */ - RDebugRecoilMode recoil_mode; /* what did the user want to do? */ - ut64 stopaddr; /* stop address */ - - /* tracing vars */ - RDebugTrace *trace; - Sdb *tracenodes; - RTree *tree; - RList *call_frames; - - RReg *reg; - RList *q_regs; - const char *creg; // current register value - RBreakpoint *bp; - void *user; // XXX(jjd): unused?? meant for caller's use?? - char *snap_path; - - /* io */ - PrintfCallback cb_printf; - RIOBind iob; - - struct r_debug_plugin_t *h; - RList *plugins; - - bool pc_at_bp; /* after a breakpoint, is the pc at the bp? */ - bool pc_at_bp_set; /* is the pc_at_bp variable set already? */ - - REvent *ev; - - RAnal *anal; - RList *maps; // - RList *maps_user; // - - bool trace_continue; - RAnalOp *cur_op; - RDebugSession *session; - - Sdb *sgnls; - RCoreBind corebind; - // internal use only - int _mode; - RNum *num; - REgg *egg; - bool verbose; - bool main_arena_resolved; /* is the main_arena resolved already? */ - int glibc_version; -} RDebug; - -typedef struct r_debug_desc_plugin_t { - int (*open)(const char *path); - int (*close)(int fd); - int (*read)(int fd, ut64 addr, int len); - int (*write)(int fd, ut64 addr, int len); - int (*seek)(int fd, ut64 addr); - int (*dup)(int fd, int newfd); - RList* (*list)(int pid); -} RDebugDescPlugin; - -typedef struct r_debug_info_t { - int pid; - int tid; - int uid; - int gid; - char *usr; - char *exe; - char *cmdline; - char *libname; - char *cwd; - int status; // zombie, running, sleeping, ... - int signum; - void * lib; - void * thread; - char *kernel_stack; - // retrieve mem/fd/core limits? - // list of threads ? hasthreads? counter? - // environment? - // /proc/pid/syscall ??? -} RDebugInfo; - -/* TODO: pass dbg and user data pointer everywhere */ -typedef struct r_debug_plugin_t { - const char *name; - const char *license; - const char *author; - const char *version; - //const char **archs; // MUST BE DEPRECATED!!!! - ut32 bits; - const char *arch; - int canstep; - int keepio; - /* life */ - RDebugInfo* (*info)(RDebug *dbg, const char *arg); - int (*startv)(int argc, char **argv); - int (*attach)(RDebug *dbg, int pid); - int (*detach)(RDebug *dbg, int pid); - int (*select)(RDebug *dbg, int pid, int tid); - RList *(*threads)(RDebug *dbg, int pid); - RList *(*pids)(RDebug *dbg, int pid); - RList *(*tids)(RDebug *dbg, int pid); - RFList (*backtrace)(RDebug *dbg, int count); - /* flow */ - int (*stop)(RDebug *dbg); - int (*step)(RDebug *dbg); - int (*step_over)(RDebug *dbg); - int (*cont)(RDebug *dbg, int pid, int tid, int sig); - int (*wait)(RDebug *dbg, int pid); - bool (*gcore)(RDebug *dbg, RBuffer *dest); - bool (*kill)(RDebug *dbg, int pid, int tid, int sig); - RList* (*kill_list)(RDebug *dbg); - int (*contsc)(RDebug *dbg, int pid, int sc); - RList* (*frames)(RDebug *dbg, ut64 at); - RBreakpointCallback breakpoint; -// XXX: specify, pid, tid, or RDebug ? - int (*reg_read)(RDebug *dbg, int type, ut8 *buf, int size); - int (*reg_write)(RDebug *dbg, int type, const ut8 *buf, int size); //XXX struct r_regset_t regs); - char* (*reg_profile)(RDebug *dbg); - int (*set_reg_profile)(const char *str); - /* memory */ - RList *(*map_get)(RDebug *dbg); - RList *(*modules_get)(RDebug *dbg); - RDebugMap* (*map_alloc)(RDebug *dbg, ut64 addr, int size, bool thp); - int (*map_dealloc)(RDebug *dbg, ut64 addr, int size); - int (*map_protect)(RDebug *dbg, ut64 addr, int size, int perms); - int (*init)(RDebug *dbg); - int (*drx)(RDebug *dbg, int n, ut64 addr, int size, int rwx, int g, int api_type); - RDebugDescPlugin desc; - // TODO: use RList here -} RDebugPlugin; - -// TODO: rename to r_debug_process_t ? maybe a thread too ? -typedef struct r_debug_pid_t { - int pid; - int ppid; - char status; /* stopped, running, zombie, sleeping ,... */ - int runnable; /* when using 'run', 'continue', .. this proc will be runnable */ - bool signalled; - char *path; - int uid; - int gid; - ut64 pc; -} RDebugPid; - -/* - * Radare's debugger has both an external and internal API. - * - * TODO(jjd): reconcile external API and extend it for better funcitonality - * when using R2 as a library. - */ -#ifdef R_API -R_API RDebug *r_debug_new(int hard); -R_API RDebug *r_debug_free(RDebug *dbg); - -R_API int r_debug_attach(RDebug *dbg, int pid); -R_API int r_debug_detach(RDebug *dbg, int pid); -R_API int r_debug_startv(RDebug *dbg, int argc, char **argv); -R_API int r_debug_start(RDebug *dbg, const char *cmd); - -/* reason we stopped */ -R_API RDebugReasonType r_debug_stop_reason(RDebug *dbg); -R_API const char *r_debug_reason_to_string(int type); - -/* wait for another event */ -R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp); - -/* continuations */ -R_API int r_debug_step(RDebug *dbg, int steps); -R_API int r_debug_step_over(RDebug *dbg, int steps); -R_API int r_debug_continue_until(RDebug *dbg, ut64 addr); -R_API int r_debug_continue_until_nonblock(RDebug *dbg, ut64 addr); -R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over); -R_API int r_debug_continue_until_nontraced(RDebug *dbg); -R_API int r_debug_continue_syscall(RDebug *dbg, int sc); -R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc); -R_API int r_debug_continue(RDebug *dbg); -R_API int r_debug_continue_kill(RDebug *dbg, int signal); -#if __WINDOWS__ -R_API int r_debug_continue_pass_exception(RDebug *dbg); -#endif - -/* process/thread handling */ -R_API bool r_debug_select(RDebug *dbg, int pid, int tid); -//R_API int r_debug_pid_add(RDebug *dbg); -//R_API int r_debug_pid_add_thread(RDebug *dbg); -//R_API int r_debug_pid_del(RDebug *dbg); -//R_API int r_debug_pid_del_thread(RDebug *dbg); -R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt); -R_API RDebugPid *r_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc); -R_API RDebugPid *r_debug_pid_free(RDebugPid *pid); -R_API RList *r_debug_pids(RDebug *dbg, int pid); - -R_API bool r_debug_set_arch(RDebug *dbg, const char *arch, int bits); -R_API bool r_debug_use(RDebug *dbg, const char *str); - -R_API RDebugInfo *r_debug_info(RDebug *dbg, const char *arg); -R_API void r_debug_info_free (RDebugInfo *rdi); - -R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file); - -/* send signals */ -R_API void r_debug_signal_init(RDebug *dbg); -R_API int r_debug_signal_send(RDebug *dbg, int num); -R_API int r_debug_signal_what(RDebug *dbg, int num); -R_API int r_debug_signal_resolve(RDebug *dbg, const char *signame); -R_API const char *r_debug_signal_resolve_i(RDebug *dbg, int signum); -R_API void r_debug_signal_setup(RDebug *dbg, int num, int opt); -R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr); -R_API void r_debug_signal_list(RDebug *dbg, int mode); -R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig); -R_API RList *r_debug_kill_list(RDebug *dbg); -// XXX: must be uint64 action -R_API int r_debug_kill_setup(RDebug *dbg, int sig, int action); - -/* handle.c */ -R_API void r_debug_plugin_init(RDebug *dbg); -R_API int r_debug_plugin_set(RDebug *dbg, const char *str); -R_API int r_debug_plugin_list(RDebug *dbg, int mode); -R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo); -R_API bool r_debug_plugin_set_reg_profile(RDebug *dbg, const char *str); - -/* memory */ -R_API RList *r_debug_modules_list(RDebug*); -R_API RDebugMap *r_debug_map_alloc(RDebug *dbg, ut64 addr, int size, bool thp); -R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map); -R_API RList *r_debug_map_list_new(void); -R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr); -R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user); -R_API void r_debug_map_free(RDebugMap *map); -R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input); -R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, const char *input, int colors); - -/* descriptors */ -R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int off); -R_API void r_debug_desc_free (RDebugDesc *p); -R_API int r_debug_desc_open(RDebug *dbg, const char *path); -R_API int r_debug_desc_close(RDebug *dbg, int fd); -R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd); -R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len); -R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr); // TODO: whence? -R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len); -R_API int r_debug_desc_list(RDebug *dbg, int rad); - -/* registers */ -R_API int r_debug_reg_sync(RDebug *dbg, int type, int write); -R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char *use_color); -R_API int r_debug_reg_set(RDebug *dbg, const char *name, ut64 num); -R_API ut64 r_debug_reg_get(RDebug *dbg, const char *name); -R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *value); - -R_API ut64 r_debug_execute(RDebug *dbg, const ut8 *buf, int len, int restore); -R_API bool r_debug_map_sync(RDebug *dbg); - -R_API int r_debug_stop(RDebug *dbg); - -/* backtrace */ -R_API RList *r_debug_frames(RDebug *dbg, ut64 at); - -R_API bool r_debug_is_dead(RDebug *dbg); -R_API int r_debug_map_protect(RDebug *dbg, ut64 addr, int size, int perms); -/* args XXX: weird food */ -R_API ut64 r_debug_arg_get(RDebug *dbg, int fast, int num); -R_API bool r_debug_arg_set(RDebug *dbg, int fast, int num, ut64 value); - -/* breakpoints (most in r_bp, this calls those) */ -R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch, int rw, char *module, st64 m_delta); -R_API void r_debug_bp_rebase(RDebug *dbg, ut64 old_base, ut64 new_base); -R_API void r_debug_bp_update(RDebug *dbg); - -/* pid */ -R_API int r_debug_thread_list(RDebug *dbg, int pid, char fmt); - -R_API void r_debug_tracenodes_reset(RDebug *dbg); - -R_API void r_debug_trace_reset(RDebug *dbg); -R_API int r_debug_trace_pc(RDebug *dbg, ut64 pc); -R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op); -R_API void r_debug_trace_at(RDebug *dbg, const char *str); -R_API RDebugTracepoint *r_debug_trace_get(RDebug *dbg, ut64 addr); -R_API void r_debug_trace_list(RDebug *dbg, int mode, ut64 offset); -R_API RDebugTracepoint *r_debug_trace_add(RDebug *dbg, ut64 addr, int size); -R_API RDebugTrace *r_debug_trace_new(void); -R_API void r_debug_trace_free(RDebugTrace *dbg); -R_API int r_debug_trace_tag(RDebug *dbg, int tag); -R_API int r_debug_child_fork(RDebug *dbg); -R_API int r_debug_child_clone(RDebug *dbg); - -R_API void r_debug_drx_list(RDebug *dbg); -R_API int r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g); -R_API int r_debug_drx_unset(RDebug *dbg, int idx); - -/* esil */ -R_API ut64 r_debug_num_callback(RNum *userptr, const char *str, int *ok); -R_API int r_debug_esil_stepi(RDebug *dbg); -R_API ut64 r_debug_esil_step(RDebug *dbg, ut32 count); -R_API ut64 r_debug_esil_continue(RDebug *dbg); -R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr); -R_API void r_debug_esil_watch_reset(RDebug *dbg); -R_API void r_debug_esil_watch_list(RDebug *dbg); -R_API int r_debug_esil_watch_empty(RDebug *dbg); -R_API void r_debug_esil_prestep (RDebug *d, int p); - -/* record & replay */ -// R_API ut8 r_debug_get_byte(RDebug *dbg, ut32 cnum, ut64 addr); -R_API bool r_debug_add_checkpoint(RDebug *dbg); -R_API bool r_debug_session_add_reg_change(RDebugSession *session, int arena, ut64 offset, ut64 data); -R_API bool r_debug_session_add_mem_change(RDebugSession *session, ut64 addr, ut8 data); -R_API void r_debug_session_restore_reg_mem(RDebug *dbg, ut32 cnum); -R_API void r_debug_session_list_memory(RDebug *dbg); -R_API void r_debug_session_serialize(RDebugSession *session, Sdb *db); -R_API void r_debug_session_deserialize(RDebugSession *session, Sdb *db); -R_API bool r_debug_session_save(RDebugSession *session, const char *file); -R_API bool r_debug_session_load(RDebug *dbg, const char *file); -R_API bool r_debug_trace_ins_before(RDebug *dbg); -R_API bool r_debug_trace_ins_after(RDebug *dbg); - -R_API RDebugSession *r_debug_session_new(void); -R_API void r_debug_session_free(RDebugSession *session); - -R_API RDebugSnap *r_debug_snap_map(RDebug *dbg, RDebugMap *map); -R_API bool r_debug_snap_contains(RDebugSnap *snap, ut64 addr); -R_API ut8 *r_debug_snap_get_hash(RDebugSnap *snap); -R_API bool r_debug_snap_is_equal(RDebugSnap *a, RDebugSnap *b); -R_API void r_debug_snap_free(RDebugSnap *snap); - -R_API int r_debug_step_back(RDebug *dbg, int steps); -R_API bool r_debug_goto_cnum(RDebug *dbg, ut32 cnum); -R_API int r_debug_step_cnum(RDebug *dbg, int steps); -R_API bool r_debug_continue_back(RDebug *dbg); - -/* ptrace */ -#if HAVE_PTRACE -static inline long r_debug_ptrace(RDebug *dbg, r_ptrace_request_t request, pid_t pid, void *addr, r_ptrace_data_t data) { - return dbg->iob.ptrace (dbg->iob.io, request, pid, addr, data); -} - -static inline void *r_debug_ptrace_func(RDebug *dbg, void *(*func)(void *), void *user) { - return dbg->iob.ptrace_func (dbg->iob.io, func, user); -} -#endif - -/* plugin pointers */ -extern RDebugPlugin r_debug_plugin_native; -extern RDebugPlugin r_debug_plugin_esil; -extern RDebugPlugin r_debug_plugin_rap; -extern RDebugPlugin r_debug_plugin_gdb; -extern RDebugPlugin r_debug_plugin_bf; -extern RDebugPlugin r_debug_plugin_io; -extern RDebugPlugin r_debug_plugin_winkd; -extern RDebugPlugin r_debug_plugin_windbg; -extern RDebugPlugin r_debug_plugin_bochs; -extern RDebugPlugin r_debug_plugin_qnx; -extern RDebugPlugin r_debug_plugin_null; -#endif - -#ifdef __cplusplus -} -#endif - -#endif - -/* regset */ -//R_API struct r_regset_t* r_regset_diff(struct r_regset_t *a, struct r_regset_t *b); -//R_API int r_regset_set(struct r_regset_t *r, int idx, const char *name, ut64 value); -//R_API struct r_regset_t *r_regset_new(int size); -//R_API void r_regset_free(struct r_regset_t *r); - -#if 0 -Missing callbacks -================= - - alloc - - dealloc - - list maps (memory regions) - - change memory protections - - touchtrace - - filedescriptor set/get/mod.. - - get/set signals - - get regs, set regs - -#endif diff --git a/libr/include/r_diff.h b/libr/include/r_diff.h deleted file mode 100644 index e9cae660e0..0000000000 --- a/libr/include/r_diff.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef R2_DIFF_H -#define R2_DIFF_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_diff); - -#define Color_INSERT Color_BGREEN -#define Color_DELETE Color_BRED -#define Color_BGINSERT "\x1b[48;5;22m" -#define Color_BGDELETE "\x1b[48;5;52m" -#define Color_HLINSERT Color_BGINSERT Color_INSERT -#define Color_HLDELETE Color_BGDELETE Color_DELETE - -typedef struct r_diff_op_t { - /* file A */ - ut64 a_off; - const ut8 *a_buf; - ut32 a_len; - - /* file B */ - ut64 b_off; - const ut8 *b_buf; - ut32 b_len; -} RDiffOp; - -//typedef struct r_diff_t RDiff; - -typedef struct r_diff_t { - ut64 off_a; - ut64 off_b; - int delta; - void *user; - bool verbose; - int type; - const char *diff_cmd; - int (*callback)(struct r_diff_t *diff, void *user, RDiffOp *op); -} RDiff; - -typedef int (*RDiffCallback)(RDiff *diff, void *user, RDiffOp *op); - -typedef struct r_diffchar_t { - const ut8 *align_a; - const ut8 *align_b; - size_t len_buf; - size_t start_align; -} RDiffChar; - -/* XXX: this api needs to be reviewed , constructor with offa+offb?? */ -#ifdef R_API -R_API RDiff *r_diff_new(void); -R_API RDiff *r_diff_new_from(ut64 off_a, ut64 off_b); -R_API RDiff *r_diff_free(RDiff *d); - -R_API int r_diff_buffers(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb); -R_API int r_diff_buffers_static(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb); -R_API int r_diff_buffers_radiff(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb); -R_API int r_diff_buffers_delta(RDiff *diff, const ut8 *sa, int la, const ut8 *sb, int lb); -R_API int r_diff_buffers(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb); -R_API char *r_diff_buffers_to_string(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb); -R_API int r_diff_set_callback(RDiff *d, RDiffCallback callback, void *user); -R_API bool r_diff_buffers_distance(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); -R_API bool r_diff_buffers_distance_myers(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); -R_API bool r_diff_buffers_distance_levenstein(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); -R_API char *r_diff_buffers_unified(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb); -/* static method !??! */ -R_API int r_diff_lines(const char *file1, const char *sa, int la, const char *file2, const char *sb, int lb); -R_API int r_diff_set_delta(RDiff *d, int delta); -R_API int r_diff_gdiff(const char *file1, const char *file2, int rad, int va); - -R_API RDiffChar *r_diffchar_new(const ut8 *a, const ut8 *b); -R_API void r_diffchar_print(RDiffChar *diffchar); -R_API void r_diffchar_free(RDiffChar *diffchar); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_egg.h b/libr/include/r_egg.h deleted file mode 100644 index 3f118fbfdc..0000000000 --- a/libr/include/r_egg.h +++ /dev/null @@ -1,240 +0,0 @@ -#ifndef R2_EGG_H -#define R2_EGG_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_egg); - -#define R_EGG_INCDIR_ENV "EGG_INCDIR" -#define R_EGG_INCDIR_PATH "/lib/radare2/" R2_VERSION "/egg" - -// rename to REggShellcode -#define R_EGG_PLUGIN_SHELLCODE 0 -#define R_EGG_PLUGIN_ENCODER 1 - -typedef struct r_egg_plugin_t { - const char *name; - const char *desc; - int type; - RBuffer* (*build) (void *egg); -} REggPlugin; - -typedef struct r_egg_lang_t { - int pushargs; - int nalias; - int nsyscalls; - char *conditionstr; - char *syscallbody; - char *includefile; - char *setenviron; - char *mathline; - // used for confusing mathop - int commentmode; - int varsize; - int varxs; - int lastctxdelta; - int nargs; - int docall; - int nfunctions; - int nbrackets; - int slurpin; - int slurp; - int line; - char elem[1024]; - int attsyntax; - int elem_n; - char *callname; - char *endframe; - char *ctxpush[32]; - char *file; - char *dstvar; - char *dstval; - char *includedir; - char *ifelse_table[32][32]; - // used to solve if-else problem in a not so ugly way - int ndstval; - int skipline;// BOOL - int quoteline; - int quotelinevar; - int stackframe; - int stackfixed; - int oc; - int mode; - int inlinectr; - struct { - char *name; - char *body; - // int fastcall; /* TODO: NOT YET USED */ - } inlines[256]; - int ninlines; - struct { - char *name; - char *arg; - } syscalls[256]; - struct { - char *name; - char *content; - } aliases[256]; - char *nested[32]; - char *nested_callname[32]; - // char *nestede[32] = {0}; - // seems nestede are not used any more - // (only one place that gives nestede[] value, where could be replaced) - int nestedi[32]; -} REggLang; - -typedef struct r_egg_t { - RBuffer *src; - RBuffer *buf; - RBuffer *bin; - RList *list; - //RList *shellcodes; // XXX is plugins nao? - RAsm *rasm; - RSyscall *syscall; - REggLang lang; - Sdb *db; - RList *plugins; - RList *patches; // - struct r_egg_emit_t *remit; - int arch; - int endian; - int bits; - ut32 os; - int context; -} REgg; - -/* XXX: this may fail in different arches */ -#if 0 -r2 -q - <plugins -R_API void r_egg_option_set (REgg *egg, const char *k, const char *v); -R_API char *r_egg_option_get (REgg *egg, const char *k); -R_API void r_egg_if(REgg *egg, const char *reg, char cmp, int v); -R_API void r_egg_printf(REgg *egg, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API int r_egg_compile(REgg *egg); -R_API int r_egg_padding (REgg *egg, const char *pad); -R_API bool r_egg_assemble(REgg *egg); -R_API bool r_egg_assemble_asm(REgg *egg, char **asm_list); -R_API void r_egg_pattern(REgg *egg, int size); -R_API RBuffer *r_egg_get_bin(REgg *egg); -//R_API int r_egg_dump (REgg *egg, const char *file) { } -R_API char *r_egg_get_source(REgg *egg); -R_API RBuffer *r_egg_get_bin(REgg *egg); -R_API char *r_egg_get_assembly(REgg *egg); -R_API void r_egg_append(REgg *egg, const char *src); -R_API int r_egg_run(REgg *egg); -R_API int r_egg_run_rop(REgg *egg); -R_API int r_egg_patch(REgg *egg, int off, const ut8 *b, int l); -R_API void r_egg_finalize(REgg *egg); - -/* r_egg_Cfile.c */ -R_API char* r_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits); - -/* lang.c */ -R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta); -R_API int r_egg_lang_parsechar(REgg *egg, char c); -R_API void r_egg_lang_include_path (REgg *egg, const char *path); -R_API void r_egg_lang_include_init (REgg *egg); - -/* plugin pointers */ -extern REggPlugin r_egg_plugin_xor; -extern REggPlugin r_egg_plugin_shya; -extern REggPlugin r_egg_plugin_exec; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_endian.h b/libr/include/r_endian.h deleted file mode 100644 index c47945049d..0000000000 --- a/libr/include/r_endian.h +++ /dev/null @@ -1,556 +0,0 @@ -#ifndef R_ENDIAN_H -#define R_ENDIAN_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Endian agnostic functions working on single byte. */ - -static inline ut8 r_read_ble8(const void *src) { - if (!src) { - return UT8_MAX; - } - return *(const ut8 *)src; -} - -static inline ut8 r_read_at_ble8(const void *src, size_t offset) { - return r_read_ble8 (((const ut8*)src) + offset); -} - -static inline void r_write_ble8(void *dest, ut8 val) { - *(ut8 *)dest = val; -} - -static inline void r_write_at_ble8(void *dest, ut8 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_ble8 (d, val); -} - -/* Big Endian functions. */ - -static inline ut8 r_read_be8(const void *src) { - return r_read_ble8 (src); -} - -static inline ut8 r_read_at_be8(const void *src, size_t offset) { - return r_read_at_ble8 (src, offset); -} - -static inline void r_write_be8(void *dest, ut8 val) { - r_write_ble8 (dest, val); -} - -static inline void r_write_at_be8(void *dest, ut8 val, size_t offset) { - r_write_at_ble8 (dest, val, offset); -} - -static inline ut16 r_read_be16(const void *src) { - const ut8 *s = (const ut8*)src; - return (((ut16)s[0]) << 8) | (((ut16)s[1]) << 0); -} - -static inline ut16 r_read_at_be16(const void *src, size_t offset) { - const ut8 *s = (const ut8*)src + offset; - return r_read_be16 (s); -} - -static inline void r_write_be16(void *dest, ut16 val) { - r_write_be8 (dest, val >> 8); - r_write_at_be8 (dest, (ut8)val, sizeof (ut8)); -} - -static inline void r_write_at_be16(void *dest, ut16 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_be16 (d, val); -} - -static inline ut32 r_read_be32(const void *src) { - const ut8 *s = (const ut8*)src; - return (((ut32)s[0]) << 24) | (((ut32)s[1]) << 16) | - (((ut32)s[2]) << 8) | (((ut32)s[3]) << 0); -} - -static inline ut32 r_read_at_be32(const void *src, size_t offset) { - const ut8 *s = (const ut8*)src + offset; - return r_read_be32 (s); -} - -static inline void r_write_be32(void *dest, ut32 val) { - r_write_be16 (dest, val >> 16); - r_write_at_be16 (dest, val, sizeof (ut16)); -} - -static inline void r_write_be24(void *_dest, ut32 val) { - ut8 *dest = (ut8*)_dest; - r_write_be8 (dest++, val >> 16); - r_write_be8 (dest++, val >> 8); - r_write_be8 (dest, val); -} - -static inline void r_write_at_be32(void *dest, ut32 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_be32 (d, val); -} - -static inline ut64 r_read_be64(const void *src) { - ut64 val = ((ut64)(r_read_be32 (src))) << 32; - val |= r_read_at_be32 (src, sizeof (ut32)); - return val; -} - -static inline ut64 r_read_at_be64(const void *src, size_t offset) { - const ut8 *s = (const ut8*)src + offset; - return r_read_be64 (s); -} - -static inline void r_write_be64(void *dest, ut64 val) { - r_write_be32 (dest, val >> 32); - r_write_at_be32 (dest, (ut32)val, sizeof (ut32)); -} - -static inline void r_write_at_be64(void *dest, ut64 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_be64 (d, val); -} - -/* Little Endian functions. */ - -static inline ut8 r_read_le8(const void *src) { - if (!src) { - return UT8_MAX; - } - return r_read_ble8 (src); -} - -static inline ut8 r_read_at_le8(const void *src, size_t offset) { - return r_read_at_ble8 (src, offset); -} - -static inline void r_write_le8(void *dest, ut8 val) { - r_write_ble8 (dest, val); -} - -static inline void r_write_at_le8(void *dest, ut8 val, size_t offset) { - r_write_at_ble8 (dest, val, offset); -} - -static inline ut16 r_read_le16(const void *src) { - if (!src) { - return UT16_MAX; - } - const ut8 *s = (const ut8*)src; - return (((ut16)s[1]) << 8) | (((ut16)s[0]) << 0); -} - -static inline ut16 r_read_at_le16(const void *src, size_t offset) { - if (!src) { - return UT16_MAX; - } - const ut8 *s = (const ut8*)src + offset; - return r_read_le16 (s); -} - -static inline void r_write_le16(void *dest, ut16 val) { - r_write_le8 (dest, (ut8)val); - r_write_at_le8 (dest, val >> 8, sizeof (ut8)); -} - -static inline void r_write_at_le16(void *dest, ut16 val, size_t offset) { - ut8 *d = (ut8 *)dest + offset; - r_write_le16 (d, val); -} - -static inline void r_write_le24(void *_dest, ut32 val) { - ut8* dest = (ut8*)_dest; - r_write_le8 (dest++, val); - r_write_le8 (dest++, val >> 8); - r_write_le8 (dest, val >> 16); -} - -static inline ut32 r_read_le32(const void *src) { - if (!src) { - return UT32_MAX; - } - const ut8 *s = (const ut8*)src; - return (((ut32)s[3]) << 24) | (((ut32)s[2]) << 16) | - (((ut32)s[1]) << 8) | (((ut32)s[0]) << 0); -} - -static inline ut32 r_read_at_le32(const void *src, size_t offset) { - if (!src) { - return UT32_MAX; - } - const ut8 *s = (const ut8*)src + offset; - return r_read_le32 (s); -} - -static inline void r_write_le32(void *dest, ut32 val) { - r_write_le16 (dest, val); - r_write_at_le16 (dest, val >> 16, sizeof (ut16)); -} - -static inline void r_write_at_le32(void *dest, ut32 val, size_t offset) { - ut8 *d = ((ut8*)dest) + offset; - r_write_le32 (d, val); -} - -static inline ut64 r_read_le64(const void *src) { - ut64 val = ((ut64)(r_read_at_le32 (src, sizeof (ut32)))) << 32; - val |= r_read_le32 (src); - return val; -} - -static inline ut64 r_read_at_le64(const void *src, size_t offset) { - const ut8 *s = ((const ut8*)src) + offset; - return r_read_le64 (s); -} - -static inline void r_write_le64(void *dest, ut64 val) { - r_write_le32 (dest, (ut32)val); - r_write_at_le32 (dest, val >> 32, sizeof (ut32)); -} - -static inline void r_write_at_le64(void *dest, ut64 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_le64 (d, val); -} - -/* Middle Endian functions. */ - -static inline ut8 r_read_me8(const void *src) { - return src ? r_read_ble8 (src): UT8_MAX; -} - -static inline ut8 r_read_at_me8(const void *src, size_t offset) { - return r_read_at_ble8 (src, offset); -} - -static inline void r_write_me8(void *dest, ut8 val) { - r_write_ble8 (dest, val); -} - -static inline void r_write_at_me8(void *dest, ut8 val, size_t offset) { - r_write_at_ble8 (dest, val, offset); -} - -static inline ut16 r_read_me16(const void *src) { - if (!src) { - return UT16_MAX; - } - const ut8 *s = (const ut8*)src; - return (((ut16)s[0]) << 8) | (((ut16)s[1]) << 0); -} - -static inline ut16 r_read_at_me16(const void *src, size_t offset) { - if (!src) { - return UT16_MAX; - } - const ut8 *s = (const ut8*)src + offset; - return r_read_me16 (s); -} - -static inline void r_write_me16(void *dest, ut16 val) { - r_write_me8 (dest, val >> 8); - r_write_at_me8 (dest, (ut8)val, sizeof (ut8)); -} - -static inline void r_write_at_me16(void *dest, ut16 val, size_t offset) { - ut8 *d = (ut8 *)dest + offset; - r_write_me16 (d, val); -} - -static inline ut32 r_read_me32(const void *src) { - if (!src) { - return UT32_MAX; - } - const ut8 *s = (const ut8*)src; - return (((ut32)s[2]) << 24) | (((ut32)s[1]) << 16) | - (((ut32)s[0]) << 8) | (((ut32)s[1]) << 0); -} - -static inline ut32 r_read_at_me32(const void *src, size_t offset) { - if (!src) { - return UT32_MAX; - } - const ut8 *s = (const ut8*)src + offset; - return r_read_me32 (s); -} - -static inline void r_write_me32(void *dest, ut32 val) { - r_write_me16 (dest, val); - r_write_at_me16 (dest, val >> 16, sizeof (ut16)); -} - -static inline void r_write_at_me32(void *dest, ut32 val, size_t offset) { - ut8 *d = ((ut8*)dest) + offset; - r_write_me32 (d, val); -} - -static inline ut64 r_read_me64(const void *src) { - ut64 val = ((ut64)(r_read_at_me32 (src, sizeof (ut32)))) << 32; - val |= r_read_me32 (src); - return val; -} - -static inline ut64 r_read_at_me64(const void *src, size_t offset) { - const ut8 *s = ((const ut8*)src) + offset; - return r_read_me64 (s); -} - -static inline void r_write_me64(void *dest, ut64 val) { - r_write_me32 (dest, (ut32)val); - r_write_at_me32 (dest, val >> 32, sizeof (ut32)); -} - -static inline void r_write_at_me64(void *dest, ut64 val, size_t offset) { - ut8 *d = (ut8*)dest + offset; - r_write_me64 (d, val); -} - -/* Helper functions */ - -static inline ut16 r_read_ble16(const void *src, bool big_endian) { - return big_endian? r_read_be16 (src): r_read_le16 (src); -} - -static inline ut32 r_read_ble32(const void *src, bool big_endian) { - return big_endian? r_read_be32 (src): r_read_le32 (src); -} - -static inline ut64 r_read_ble64(const void *src, bool big_endian) { - return big_endian? r_read_be64 (src): r_read_le64 (src); -} - -static inline ut16 r_read_at_ble16(const void *src, size_t offset, bool big_endian) { - return big_endian ? r_read_at_be16 (src, offset) : r_read_at_le16 (src, offset); -} - -static inline ut32 r_read_at_ble32(const void *src, size_t offset, bool big_endian) { - return big_endian ? r_read_at_be32 (src, offset) : r_read_at_le32 (src, offset); -} - -static inline ut64 r_read_at_ble64(const void *src, size_t offset, bool big_endian) { - return big_endian ? r_read_at_be64 (src, offset) : r_read_at_le64 (src, offset); -} - -static inline ut64 r_read_ble(const void *src, bool big_endian, int size) { - switch (size) { - case 8: - return (ut64) ((const ut8*)src)[0]; - case 16: - return r_read_ble16 (src, big_endian); - case 32: - return r_read_ble32 (src, big_endian); - case 64: - return r_read_ble64 (src, big_endian); - default: - return UT64_MAX; - } -} - -static inline void r_write_ble16(void *dest, ut16 val, bool big_endian) { - big_endian? r_write_be16 (dest, val): r_write_le16 (dest, val); -} - -static inline void r_write_ble24(void *dest, ut32 val, bool big_endian) { - big_endian? r_write_be24 (dest, val): r_write_le24 (dest, val); -} - -static inline void r_write_ble32(void *dest, ut32 val, bool big_endian) { - big_endian? r_write_be32 (dest, val): r_write_le32 (dest, val); -} - -static inline void r_write_ble64(void *dest, ut64 val, bool big_endian) { - big_endian? r_write_be64 (dest, val): r_write_le64 (dest, val); -} - -static inline void r_write_ble(void *dst, ut64 val, bool big_endian, int size) { - switch (size) { - case 8: - ((ut8*)dst)[0] = (ut8) val; - break; - case 16: - r_write_ble16 (dst, (ut16) val, big_endian); - break; - case 24: - r_write_ble24 (dst, (ut32) val, big_endian); - break; - case 32: - r_write_ble32 (dst, (ut32) val, big_endian); - break; - case 64: - r_write_ble64 (dst, val, big_endian); - break; - default: - break; - } -} - -// TODO: find better names and write vapis -#define ut8p_b(x) ((x)[0]) -#define ut8p_bw(x) ((x)[0]|((x)[1]<<8)) -#define ut8p_bd(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)) -#define ut8p_bq(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)|((x)[4]<<32)|((x)[5]<<40)|((x)[6]<<48)|((x)[7]<<56)) -#define ut8p_lw(x) ((x)[1]|((x)[0]<<8)) -#define ut8p_ld(x) ((x)[3]|((x)[2]<<8)|((x)[1]<<16)|((x)[0]<<24)) -#define ut8p_lq(x) ((x)[7]|((x)[6]<<8)|((x)[5]<<16)|((x)[4]<<24)|((x)[3]<<32)|((x)[2]<<40)|((x)[1]<<48)|((x)[0]<<56)) - -/*swap*/ -static inline ut16 r_swap_ut16(ut16 val) { - return (val << 8) | (val >> 8 ); -} - -static inline st16 r_swap_st16(st16 val) { - val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); - return (val << 16) | (val >> 16); -} - -static inline ut32 r_swap_ut32(ut32 val) { - val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); - return (val << 16) | (val >> 16); -} - -static inline st32 r_swap_st32(st32 val) { - val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF ); - return (val << 16) | ((val >> 16) & 0xFFFF); -} - -static inline ut64 r_swap_ut64(ut64 val) { - val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); - val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); - return (val << 32) | (val >> 32); -} - -static inline st64 r_swap_st64(st64 val) { - val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); - val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); - return (val << 32) | ((val >> 32) & 0xFFFFFFFFULL); -} - -/* Some "secured" functions, to do basic operation (mul, sub, add...) on integers */ -static inline int UT64_ADD(ut64 *r, ut64 a, ut64 b) { - if (UT64_MAX - a < b) { - return 0; - } - if (r) { - *r = a + b; - } - return 1; -} - -static inline int UT64_MUL(ut64 *r, ut64 a, ut64 b) { - if (a && UT64_MAX / a < b) { - return 0; - } - if (r) { - *r = a * b; - } - return 1; -} - -static inline int UT64_SUB(ut64 *r, ut64 a, ut64 b) { - if (b > a) { - return 0; - } - if (r) { - *r = a - b; - } - return 1; -} - -static inline int UT32_ADD(ut32 *r, ut32 a, ut32 b) { - if (UT32_MAX - a < b) { - return 0; - } - if (r) { - *r = a + b; - } - return 1; -} - -static inline int UT32_MUL(ut32 *r, ut32 a, ut32 b) { - if (a && UT32_MAX / a < b) { - return 0; - } - if (r) { - *r = a * b; - } - return 1; -} - -static inline int UT32_SUB(ut32 *r, ut32 a, ut32 b) { - if (b > a) { - return 0; - } - if (r) { - *r = a - b; - } - return 1; -} - -static inline int UT16_ADD(ut16 *r, ut16 a, ut16 b) { - if (UT16_MAX - a < b) { - return 0; - } - if (r) { - *r = a + b; - } - return 1; -} - -static inline int UT16_MUL(ut16 *r, ut16 a, ut16 b) { - if (a && UT16_MAX / a < b) { - return 0; - } - if (r) { - *r = a * b; - } - return 1; -} - -static inline int UT16_SUB(ut16 *r, ut16 a, ut16 b) { - if (b > a) { - return 0; - } - if (r) { - *r = a - b; - } - return 1; -} - -static inline int UT8_ADD(ut8 *r, ut8 a, ut8 b) { - if (UT8_MAX - a < b) { - return 0; - } - if (r) { - *r = a + b; - } - return 1; -} - -static inline int UT8_MUL(ut8 *r, ut8 a, ut8 b) { - if (a && UT8_MAX / a < b) { - return 0; - } - if (r) { - *r = a * b; - } - return 1; -} - -static inline int UT8_SUB(ut8 *r, ut8 a, ut8 b) { - if (b > a) { - return 0; - } - if (r) { - *r = a - b; - } - return 1; -} - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_flag.h b/libr/include/r_flag.h deleted file mode 100644 index b7c020189b..0000000000 --- a/libr/include/r_flag.h +++ /dev/null @@ -1,205 +0,0 @@ -#ifndef R2_FLAGS_H -#define R2_FLAGS_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// TODO: rename to r_flag_XXX api -R_LIB_VERSION_HEADER(r_flag); - -#define R_FLAG_NAME_SIZE 512 - -/* zones.c */ - -#define R_FLAG_ZONE_USE_SDB 0 - -typedef struct r_flag_zone_item_t { - ut64 from; - ut64 to; -#if R_FLAG_ZONE_USE_SDB - const char *name; -#else - char *name; -#endif -} RFlagZoneItem; - -/* flag.c */ - -typedef struct r_flags_at_offset_t { - ut64 off; - RList *flags; /* list of RFlagItem at offset */ -} RFlagsAtOffset; - -typedef struct r_flag_item_t { - char *name; /* unique name, escaped to avoid issues with r2 shell */ - char *realname; /* real name, without any escaping */ - bool demangled; /* real name from demangling? */ - ut64 offset; /* offset flagged by this item */ - ut64 size; /* size of the flag item */ - RSpace *space; /* flag space this item belongs to */ - char *color; /* item color */ - char *comment; /* item comment */ - char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */ -} RFlagItem; - -typedef struct r_flag_t { - RSpaces spaces; /* handle flag spaces */ - st64 base; /* base address for all flag items */ - bool realnames; - Sdb *tags; - RNum *num; - RSkipList *by_off; /* flags sorted by offset, value=RFlagsAtOffset */ - HtPP *ht_name; /* hashmap key=item name, value=RFlagItem * */ - PrintfCallback cb_printf; -#if R_FLAG_ZONE_USE_SDB - Sdb *zones; -#else - RList *zones; -#endif -} RFlag; - -/* compile time dependency */ - -typedef bool (*RFlagExistAt)(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off); -typedef RFlagItem* (*RFlagGet)(RFlag *f, const char *name); -typedef RFlagItem* (*RFlagGetAtAddr) (RFlag *f, ut64); -typedef RFlagItem* (*RFlagGetAt)(RFlag *f, ut64 addr, bool closest); -typedef const RList* (*RFlagGetList)(RFlag *f, ut64 addr); -typedef RFlagItem* (*RFlagSet)(RFlag *f, const char *name, ut64 addr, ut32 size); -typedef bool (*RFlagUnset)(RFlag *f, RFlagItem *item); -typedef bool (*RFlagUnsetName)(RFlag *f, const char *name); -typedef bool (*RFlagUnsetOff)(RFlag *f, ut64 addr); -typedef RSpace *(*RFlagSetSpace)(RFlag *f, const char *name); -typedef bool (*RFlagPopSpace)(RFlag *f); -typedef bool (*RFlagPushSpace)(RFlag *f, const char *name); - -typedef bool (*RFlagItemCb)(RFlagItem *fi, void *user); - -typedef struct r_flag_bind_t { - int init; - RFlag *f; - RFlagExistAt exist_at; - RFlagGet get; - RFlagGetAt get_at; - RFlagGetList get_list; - RFlagSet set; - RFlagUnset unset; - RFlagUnsetName unset_name; - RFlagUnsetOff unset_off; - RFlagSetSpace set_fs; - RFlagPushSpace push_fs; - RFlagPopSpace pop_fs; -} RFlagBind; - -#define r_flag_bind_init(x) memset(&x,0,sizeof(x)) -R_API void r_flag_bind(RFlag *io, RFlagBind *bnd); - -#ifdef R_API -R_API RFlag * r_flag_new(void); -R_API RFlag * r_flag_free(RFlag *f); -R_API void r_flag_list(RFlag *f, int rad, const char *pfx); -R_API bool r_flag_exist_at(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off); -R_API RFlagItem *r_flag_get(RFlag *f, const char *name); -R_API RFlagItem *r_flag_get_i(RFlag *f, ut64 off); -R_API RFlagItem *r_flag_get_by_spaces(RFlag *f, ut64 off, ...); -R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest); -R_API RList *r_flag_all_list(RFlag *f, bool by_space); -R_API const RList* /**/ r_flag_get_list(RFlag *f, ut64 off); -R_API char *r_flag_get_liststr(RFlag *f, ut64 off); -R_API bool r_flag_unset(RFlag *f, RFlagItem *item); -R_API bool r_flag_unset_name(RFlag *f, const char *name); -R_API bool r_flag_unset_off(RFlag *f, ut64 addr); -R_API void r_flag_unset_all (RFlag *f); -R_API RFlagItem *r_flag_set(RFlag *fo, const char *name, ut64 addr, ut32 size); -R_API RFlagItem *r_flag_set_next(RFlag *fo, const char *name, ut64 addr, ut32 size); -R_API void r_flag_item_set_alias(RFlagItem *item, const char *alias); -R_API void r_flag_item_free (RFlagItem *item); -R_API void r_flag_item_set_comment(RFlagItem *item, const char *comment); -R_API void r_flag_item_set_realname(RFlagItem *item, const char *realname); -R_API const char *r_flag_item_set_color(RFlagItem *item, const char *color); -R_API RFlagItem *r_flag_item_clone(RFlagItem *item); -R_API int r_flag_unset_glob(RFlag *f, const char *name); -R_API int r_flag_rename(RFlag *f, RFlagItem *item, const char *name); -R_API int r_flag_relocate(RFlag *f, ut64 off, ut64 off_mask, ut64 to); -R_API bool r_flag_move (RFlag *f, ut64 at, ut64 to); -R_API const char *r_flag_color(RFlag *f, RFlagItem *it, const char *color); -R_API int r_flag_count(RFlag *f, const char *glob); -R_API void r_flag_foreach(RFlag *f, RFlagItemCb cb, void *user); -R_API void r_flag_foreach_prefix(RFlag *f, const char *pfx, int pfx_len, RFlagItemCb cb, void *user); -R_API void r_flag_foreach_range(RFlag *f, ut64 from, ut64 to, RFlagItemCb cb, void *user); -R_API void r_flag_foreach_glob(RFlag *f, const char *glob, RFlagItemCb cb, void *user); -R_API void r_flag_foreach_space(RFlag *f, const RSpace *space, RFlagItemCb cb, void *user); -R_API void r_flag_foreach_space_glob(RFlag *f, const char *glob, const RSpace *space, RFlagItemCb cb, void *user); - -/* spaces */ -static inline RSpace *r_flag_space_get(RFlag *f, const char *name) { - return r_spaces_get (&f->spaces, name); -} - -static inline RSpace *r_flag_space_cur(RFlag *f) { - return r_spaces_current (&f->spaces); -} - -static inline const char *r_flag_space_cur_name(RFlag *f) { - return r_spaces_current_name (&f->spaces); -} - -static inline RSpace *r_flag_space_set(RFlag *f, const char *name) { - return r_spaces_set (&f->spaces, name); -} - -static inline bool r_flag_space_unset(RFlag *f, const char *name) { - return r_spaces_unset (&f->spaces, name); -} - -static inline bool r_flag_space_rename(RFlag *f, const char *oname, const char *nname) { - return r_spaces_rename (&f->spaces, oname, nname); -} - -static inline bool r_flag_space_push(RFlag *f, const char *name) { - return r_spaces_push (&f->spaces, name); -} - -static inline bool r_flag_space_pop(RFlag *f) { - return r_spaces_pop (&f->spaces); -} - -static inline int r_flag_space_count(RFlag *f, const char *name) { - return r_spaces_count (&f->spaces, name); -} - -static inline bool r_flag_space_is_empty(RFlag *f) { - return r_spaces_is_empty (&f->spaces); -} - -#define r_flag_space_foreach(f, it, s) r_spaces_foreach (&(f)->spaces, (it), (s)) - -/* tags */ -R_API RList *r_flag_tags_list(RFlag *f, const char *name); -R_API RList *r_flag_tags_set(RFlag *f, const char *name, const char *words); -R_API void r_flag_tags_reset(RFlag *f, const char *name); -R_API RList *r_flag_tags_get(RFlag *f, const char *name); - -/* zones */ - -R_API void r_flag_zone_item_free(void *a); -R_API bool r_flag_zone_add(RFlag *fz, const char *name, ut64 addr); -R_API bool r_flag_zone_del(RFlag *fz, const char *name); -R_API bool r_flag_zone_around(RFlag *fz, ut64 addr, const char **prev, const char **next); -R_API bool r_flag_zone_list(RFlag *fz, int mode); -R_API bool r_flag_zone_reset(RFlag *f); -R_API RList *r_flag_zone_barlist(RFlag *f, ut64 from, ut64 bsize, int rows); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_flist.h b/libr/include/r_flist.h deleted file mode 100644 index 5268cc17cf..0000000000 --- a/libr/include/r_flist.h +++ /dev/null @@ -1,88 +0,0 @@ -/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */ - -#ifndef R2_FLIST_H -#define R2_FLIST_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -//#include - -#define r_flist_t void** -#define RFList void** - -#ifdef R_API -R_API void **r_flist_resize(void **it, int n); -#define r_flist_rewind(it) while(it!=*it) it--; it++; -#define r_flist_next(it) *it!=0 -#define r_flist_get(it) *(it++) -#define r_flist_unref(x) x - -#define r_flist_iterator(x) x -/* -static inline void **r_flist_iterator(void **it) { - r_flist_iterator(it); - return it; -} -*/ - -static inline void **r_flist_init(void **it, int n) { - *it = it; - memset (++it, 0, (n+1) * sizeof (void*)); - return it; -} - -static inline void **r_flist_new(int n) { - void **it; - if (((n + 2) * sizeof(void*)) < sizeof(void*)) return NULL; - if (!(it = (void **)calloc ((n + 2), sizeof (void*)))) { - return NULL; - } - return r_flist_init (it, n); -} - -static inline void **r_flist_prev(void **it) { - void **p = it--; - return (it==*it)?p:it; -} - -static inline void r_flist_set(void **it, int idx, void *data) { - r_flist_rewind (it); - it[idx] = data; -} - -static inline void r_flist_delete(void **it, int idx) { - r_flist_rewind (it); - free (it[idx]); - for(it += idx; *it; it++) *it = *(it+1); -} - -#define r_flist_foreach(it, pos) \ - r_flist_rewind(it); \ - while (r_flist_next (it) && (pos = r_flist_get (it))) - -static inline void r_flist_free(void **it) { - void *pos; - r_flist_foreach (it, pos) - free (pos); - r_flist_rewind (it); - free (--it); -} - -static inline int r_flist_length (void **it) { - void *pos; - int len = 0; - r_flist_foreach (it, pos) - len++; - return len; -} -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_fs.h b/libr/include/r_fs.h deleted file mode 100644 index 2ab41769fb..0000000000 --- a/libr/include/r_fs.h +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef R2_FS_H -#define R2_FS_H - -#include -#include -#include // RCoreBind -#include // RIOBind -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER (r_fs); - -struct r_fs_plugin_t; -struct r_fs_root_t; -struct r_fs_t; - -typedef struct r_fs_t { - RIOBind iob; - RCoreBind cob; - RConsBind csb; - RList /**/ *plugins; - RList /**/ *roots; - int view; - void *ptr; -} RFS; - -typedef struct r_fs_partition_plugin_t { - const char *name; -} RFSPartitionPlugin; - -typedef struct r_fs_file_t { - char *name; - char *path; - ut64 off; - ut32 size; - ut8 *data; - void *ctx; - char type; - ut64 time; - struct r_fs_plugin_t *p; - struct r_fs_root_t *root; - void *ptr; // internal pointer -} RFSFile; - -typedef struct r_fs_root_t { - char *path; - ut64 delta; - struct r_fs_plugin_t *p; - void *ptr; - // TODO: deprecate - RIOBind iob; - RCoreBind cob; -} RFSRoot; - -typedef struct r_fs_plugin_t { - const char *name; - const char *desc; - const char *license; - RFSFile* (*slurp)(RFSRoot *root, const char *path); - RFSFile* (*open)(RFSRoot *root, const char *path, bool create); - bool (*unlink)(RFSRoot *root, const char *path); - bool (*write)(RFSFile *fs, ut64 addr, const ut8 *data, int len); - bool (*read)(RFSFile *fs, ut64 addr, int len); - void (*close)(RFSFile *fs); - RList *(*dir)(RFSRoot *root, const char *path, int view); - void (*init)(void); - void (*fini)(void); - int (*mount)(RFSRoot *root); - void (*umount)(RFSRoot *root); -} RFSPlugin; - -typedef struct r_fs_partition_t { - int number; - ut64 start; - ut64 length; - int index; - int type; -} RFSPartition; - -typedef struct r_fs_shell_t { - char **cwd; - void (*set_prompt)(const char *prompt); - const char* (*readline)(void); - int (*hist_add)(const char *line); -} RFSShell; - -#define R_FS_FILE_TYPE_MOUNTPOINT 'm' -#define R_FS_FILE_TYPE_DIRECTORY 'd' -#define R_FS_FILE_TYPE_REGULAR 'r' -#define R_FS_FILE_TYPE_DELETED 'x' -#define R_FS_FILE_TYPE_SPECIAL 's' -#define R_FS_FILE_TYPE_MOUNT 'm' - -typedef int (*RFSPartitionIterator)(void *disk, void *ptr, void *user); -typedef struct r_fs_partition_type_t { - const char *name; - void *ptr; // grub_msdos_partition_map - RFSPartitionIterator iterate; - //RFSPartitionIterator parhook; -} RFSPartitionType; -#define R_FS_PARTITIONS_LENGTH (int)(sizeof (partitions)/sizeof(RFSPartitionType)-1) - -enum { - R_FS_VIEW_NORMAL = 0, - R_FS_VIEW_DELETED = 1, - R_FS_VIEW_SPECIAL = 2, - R_FS_VIEW_ALL = 0xff, -}; - -#ifdef R_API -R_API RFS *r_fs_new(void); -R_API void r_fs_view(RFS* fs, int view); -R_API void r_fs_free(RFS* fs); -R_API void r_fs_add(RFS *fs, RFSPlugin *p); -R_API void r_fs_del(RFS *fs, RFSPlugin *p); -R_API RFSRoot *r_fs_mount(RFS* fs, const char *fstype, const char *path, ut64 delta); -R_API bool r_fs_umount(RFS* fs, const char *path); -R_API RList *r_fs_root(RFS *fs, const char *path); -R_API RFSFile *r_fs_open(RFS* fs, const char *path, bool create); -R_API void r_fs_close(RFS* fs, RFSFile *file); -R_API int r_fs_read(RFS* fs, RFSFile *file, ut64 addr, int len); -R_API int r_fs_write(RFS* fs, RFSFile* file, ut64 addr, const ut8 *data, int len); -R_API RFSFile *r_fs_slurp(RFS* fs, const char *path); -R_API RList *r_fs_dir(RFS* fs, const char *path); -R_API int r_fs_dir_dump(RFS* fs, const char *path, const char *name); -R_API RList *r_fs_find_name(RFS* fs, const char *name, const char *glob); -R_API RList *r_fs_find_off(RFS* fs, const char *name, ut64 off); -R_API RList *r_fs_partitions(RFS* fs, const char *ptype, ut64 delta); -R_API char *r_fs_name(RFS *fs, ut64 offset); -R_API int r_fs_prompt(RFS *fs, const char *root); -R_API bool r_fs_check(RFS *fs, const char *p); -R_API int r_fs_shell_prompt(RFSShell *shell, RFS *fs, const char *root); - -/* file.c */ -R_API RFSFile *r_fs_file_new(RFSRoot *root, const char *path); -R_API void r_fs_file_free(RFSFile *file); -R_API char* r_fs_file_copy_abs_path(RFSFile* file); -R_API RFSRoot *r_fs_root_new(const char *path, ut64 delta); -R_API void r_fs_root_free(RFSRoot *root); -R_API RFSPartition *r_fs_partition_new(int num, ut64 start, ut64 length); -R_API void r_fs_partition_free(RFSPartition *p); -R_API const char *r_fs_partition_type(const char *part, int type); -R_API const char *r_fs_partition_type_get(int n); -R_API int r_fs_partition_get_size(void); // WTF. wrong function name - -/* plugins */ -extern RFSPlugin r_fs_plugin_io; -extern RFSPlugin r_fs_plugin_r2; -extern RFSPlugin r_fs_plugin_ext2; -extern RFSPlugin r_fs_plugin_fat; -extern RFSPlugin r_fs_plugin_ntfs; -extern RFSPlugin r_fs_plugin_hfs; -extern RFSPlugin r_fs_plugin_hfsplus; -extern RFSPlugin r_fs_plugin_reiserfs; -extern RFSPlugin r_fs_plugin_tar; -extern RFSPlugin r_fs_plugin_iso9660; -extern RFSPlugin r_fs_plugin_udf; -extern RFSPlugin r_fs_plugin_ufs; -extern RFSPlugin r_fs_plugin_ufs2; -extern RFSPlugin r_fs_plugin_sfs; -extern RFSPlugin r_fs_plugin_tar; -extern RFSPlugin r_fs_plugin_btrfs; -extern RFSPlugin r_fs_plugin_jfs; -extern RFSPlugin r_fs_plugin_afs; -extern RFSPlugin r_fs_plugin_affs; -extern RFSPlugin r_fs_plugin_cpio; -extern RFSPlugin r_fs_plugin_xfs; -extern RFSPlugin r_fs_plugin_fb; -extern RFSPlugin r_fs_plugin_minix; -extern RFSPlugin r_fs_plugin_posix; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_getopt.h b/libr/include/r_getopt.h deleted file mode 100644 index 6fb3ae621d..0000000000 --- a/libr/include/r_getopt.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef R_GETOPT_H -#define R_GETOPT_H 1 - -#include - -typedef struct r_getopt_t { - int err; - int ind; - int opt; - int reset; - const char *arg; - // ... - int argc; - const char **argv; - const char *ostr; -} RGetopt; - -R_API void r_getopt_init(RGetopt *go, int argc, const char **argv, const char *ostr); -R_API int r_getopt_next(RGetopt *opt); - -#endif diff --git a/libr/include/r_io.h b/libr/include/r_io.h deleted file mode 100644 index 7101b4675d..0000000000 --- a/libr/include/r_io.h +++ /dev/null @@ -1,513 +0,0 @@ -/* radare2 - LGPL - Copyright 2017-2020 - condret, pancake, alvaro */ - -#ifndef R2_IO_H -#define R2_IO_H - -#include "r_list.h" -#include -#include "r_socket.h" -#include "r_vector.h" - -#define R_IO_SEEK_SET 0 -#define R_IO_SEEK_CUR 1 -#define R_IO_SEEK_END 2 - -#define R_IO_UNDOS 64 - -#if HAVE_PTRACE - -#if __sun -#include -#else -#if DEBUGGER && HAVE_PTRACE -#include -#endif -#endif - -#if (defined(__GLIBC__) && defined(__linux__)) -typedef enum __ptrace_request r_ptrace_request_t; -typedef void * r_ptrace_data_t; -#define R_PTRACE_NODATA NULL -#else -#if __ANDROID__ -typedef int r_ptrace_request_t; -typedef void * r_ptrace_data_t; -#define R_PTRACE_NODATA NULL -#else -typedef int r_ptrace_request_t; -typedef int r_ptrace_data_t; -#define R_PTRACE_NODATA 0 -#endif -#endif -#endif - -#if __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_io); - -typedef struct r_io_undos_t { - ut64 off; - int cursor; -} RIOUndos; - -typedef struct r_io_undo_t { - int s_enable; - int w_enable; - /* write stuff */ - RList *w_list; - int w_init; - /* seek stuff */ - int idx; - int undos; /* available undos */ - int redos; /* available redos */ - RIOUndos seek[R_IO_UNDOS]; - /*int fd[R_IO_UNDOS]; // XXX: Must be RIODesc* */ -} RIOUndo; - -typedef struct r_io_undo_w_t { - int set; - ut64 off; - ut8 *o; /* old data */ - ut8 *n; /* new data */ - int len; /* length */ -} RIOUndoWrite; - -typedef struct r_io_t { - struct r_io_desc_t *desc; // XXX deprecate... we should use only the fd integer, not hold a weak pointer - ut64 off; - int bits; - int va; //all of this config stuff must be in 1 int - int ff; - int Oxff; - size_t addrbytes; - int aslr; - int autofd; - int cached; - bool cachemode; // write in cache all the read operations (EXPERIMENTAL) - int p_cache; - RIDPool *map_ids; - RPVector maps; //from tail backwards maps with higher priority are found - RPVector map_skyline; // map parts that are not covered by others - RIDStorage *files; - RCache *buffer; - RList *cache; //sdblist? - RBNode cacheTree; - ut8 *write_mask; - int write_mask_len; - RIOUndo undo; - SdbList *plugins; - char *runprofile; - char *envprofile; -#if USE_PTRACE_WRAP - struct ptrace_wrap_instance_t *ptrace_wrap; -#endif -#if __WINDOWS__ - struct w32dbg_wrap_instance_t *w32dbg_wrap; -#endif - char *args; - PrintfCallback cb_printf; - RCoreBind corebind; -} RIO; - -typedef struct r_io_desc_t { - int fd; - int perm; - char *uri; - char *name; - char *referer; - HtUP/**/ *cache; - void *data; - struct r_io_plugin_t *plugin; - RIO *io; -} RIODesc; - -typedef struct { - ut32 magic; - int pid; - int tid; - void *data; -} RIODescData; - -// Move somewhere else? -typedef struct { - RSocket *fd; - RSocket *client; - bool listener; -} RIORap; - -typedef struct r_io_plugin_t { - const char *name; - const char *desc; - const char *version; - const char *author; - const char *license; - void *widget; - const char *uris; - int (*listener)(RIODesc *io); - int (*init)(void); - RIOUndo undo; - bool isdbg; - // int (*is_file_opened)(RIO *io, RIODesc *fd, const char *); - char *(*system)(RIO *io, RIODesc *fd, const char *); - RIODesc* (*open)(RIO *io, const char *, int perm, int mode); - RList* /*RIODesc* */ (*open_many)(RIO *io, const char *, int perm, int mode); - int (*read)(RIO *io, RIODesc *fd, ut8 *buf, int count); - ut64 (*lseek)(RIO *io, RIODesc *fd, ut64 offset, int whence); - int (*write)(RIO *io, RIODesc *fd, const ut8 *buf, int count); - int (*close)(RIODesc *desc); - bool (*is_blockdevice)(RIODesc *desc); - bool (*is_chardevice)(RIODesc *desc); - int (*getpid)(RIODesc *desc); - int (*gettid)(RIODesc *desc); - bool (*getbase)(RIODesc *desc, ut64 *base); - bool (*resize)(RIO *io, RIODesc *fd, ut64 size); - int (*extend)(RIO *io, RIODesc *fd, ut64 size); - bool (*accept)(RIO *io, RIODesc *desc, int fd); - int (*create)(RIO *io, const char *file, int mode, int type); - bool (*check)(RIO *io, const char *, bool many); -} RIOPlugin; - -typedef struct r_io_map_t { - int fd; - int perm; - ut32 id; - RInterval itv; - ut64 delta; // paddr = itv.addr + delta - char *name; -} RIOMap; - -typedef struct r_io_map_skyline_t { - RIOMap *map; - RInterval itv; -} RIOMapSkyline; - -typedef struct r_io_cache_t { - RInterval itv; - ut8 *data; - ut8 *odata; - int written; -} RIOCache; - -#define R_IO_DESC_CACHE_SIZE (sizeof(ut64) * 8) -typedef struct r_io_desc_cache_t { - ut64 cached; - ut8 cdata[R_IO_DESC_CACHE_SIZE]; -} RIODescCache; - -struct r_io_bind_t; - -typedef bool (*RIODescUse) (RIO *io, int fd); -typedef RIODesc *(*RIODescGet) (RIO *io, int fd); -typedef ut64 (*RIODescSize) (RIODesc *desc); -typedef RIODesc *(*RIOOpen) (RIO *io, const char *uri, int flags, int mode); -typedef RIODesc *(*RIOOpenAt) (RIO *io, const char *uri, int flags, int mode, ut64 at); -typedef bool (*RIOClose) (RIO *io, int fd); -typedef bool (*RIOReadAt) (RIO *io, ut64 addr, ut8 *buf, int len); -typedef bool (*RIOWriteAt) (RIO *io, ut64 addr, const ut8 *buf, int len); -typedef char *(*RIOSystem) (RIO *io, const char* cmd); -typedef int (*RIOFdOpen) (RIO *io, const char *uri, int flags, int mode); -typedef bool (*RIOFdClose) (RIO *io, int fd); -typedef ut64 (*RIOFdSeek) (RIO *io, int fd, ut64 addr, int whence); -typedef ut64 (*RIOFdSize) (RIO *io, int fd); -typedef bool (*RIOFdResize) (RIO *io, int fd, ut64 newsize); -typedef ut64 (*RIOP2V) (RIO *io, ut64 pa); -typedef ut64 (*RIOV2P) (RIO *io, ut64 va); -typedef int (*RIOFdRead) (RIO *io, int fd, ut8 *buf, int len); -typedef int (*RIOFdWrite) (RIO *io, int fd, const ut8 *buf, int len); -typedef int (*RIOFdReadAt) (RIO *io, int fd, ut64 addr, ut8 *buf, int len); -typedef int (*RIOFdWriteAt) (RIO *io, int fd, ut64 addr, const ut8 *buf, int len); -typedef bool (*RIOFdIsDbg) (RIO *io, int fd); -typedef const char *(*RIOFdGetName) (RIO *io, int fd); -typedef RList *(*RIOFdGetMap) (RIO *io, int fd); -typedef bool (*RIOFdRemap) (RIO *io, int fd, ut64 addr); -typedef bool (*RIOIsValidOff) (RIO *io, ut64 addr, int hasperm); -typedef RIOMap *(*RIOMapGet) (RIO *io, ut64 addr); -typedef RIOMap *(*RIOMapGetPaddr) (RIO *io, ut64 paddr); -typedef bool (*RIOAddrIsMapped) (RIO *io, ut64 addr); -typedef RIOMap *(*RIOMapAdd) (RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); -#if HAVE_PTRACE -typedef long (*RIOPtraceFn) (RIO *io, r_ptrace_request_t request, pid_t pid, void *addr, r_ptrace_data_t data); -typedef void *(*RIOPtraceFuncFn) (RIO *io, void *(*func)(void *), void *user); -#endif - -typedef struct r_io_bind_t { - int init; - RIO *io; - RIODescUse desc_use; - RIODescGet desc_get; - RIODescSize desc_size; - RIOOpen open; - RIOOpenAt open_at; - RIOClose close; - RIOReadAt read_at; - RIOWriteAt write_at; - RIOSystem system; - RIOFdOpen fd_open; - RIOFdClose fd_close; - RIOFdSeek fd_seek; //needed for esil - RIOFdSize fd_size; - RIOFdResize fd_resize; - RIOFdRead fd_read; //needed for esil - RIOFdWrite fd_write; //needed for esil - RIOFdReadAt fd_read_at; - RIOFdWriteAt fd_write_at; - RIOFdIsDbg fd_is_dbg; - RIOFdGetName fd_get_name; - RIOFdGetMap fd_get_map; - RIOFdRemap fd_remap; - RIOIsValidOff is_valid_offset; - RIOAddrIsMapped addr_is_mapped; - RIOMapGet map_get; - RIOMapGetPaddr map_get_paddr; - RIOMapAdd map_add; - RIOV2P v2p; - RIOP2V p2v; -#if HAVE_PTRACE - RIOPtraceFn ptrace; - RIOPtraceFuncFn ptrace_func; -#endif -} RIOBind; - -//map.c -R_API RIOMap *r_io_map_new(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); -R_API void r_io_map_init (RIO *io); -R_API bool r_io_map_remap (RIO *io, ut32 id, ut64 addr); -R_API bool r_io_map_remap_fd (RIO *io, int fd, ut64 addr); -R_API ut64 r_io_map_location(RIO *io, ut64 size); -R_API bool r_io_map_exists (RIO *io, RIOMap *map); -R_API bool r_io_map_exists_for_id (RIO *io, ut32 id); -R_API RIOMap *r_io_map_resolve (RIO *io, ut32 id); -R_API RIOMap *r_io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); -// same as r_io_map_add but used when many maps need to be added. Call r_io_update when all maps have been added. -R_API RIOMap *r_io_map_add_batch(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); -R_API RIOMap *r_io_map_get(RIO *io, ut64 addr); //returns the map at vaddr with the highest priority -// update the internal state of RIO after a series of _batch operations -R_API void r_io_update(RIO *io); -R_API bool r_io_map_is_mapped(RIO* io, ut64 addr); -R_API RIOMap *r_io_map_get_paddr(RIO *io, ut64 paddr); //returns the map at paddr with the highest priority -R_API void r_io_map_reset(RIO* io); -R_API bool r_io_map_del(RIO *io, ut32 id); -R_API bool r_io_map_del_for_fd(RIO *io, int fd); -R_API bool r_io_map_depriorize(RIO* io, ut32 id); -R_API bool r_io_map_priorize (RIO *io, ut32 id); -R_API bool r_io_map_priorize_for_fd (RIO *io, int fd); -R_API void r_io_map_cleanup (RIO *io); -R_API void r_io_map_fini (RIO *io); -R_API bool r_io_map_is_in_range (RIOMap *map, ut64 from, ut64 to); -R_API void r_io_map_set_name (RIOMap *map, const char *name); -R_API void r_io_map_del_name (RIOMap *map); -R_API RList* r_io_map_get_for_fd(RIO *io, int fd); -R_API bool r_io_map_resize(RIO *io, ut32 id, ut64 newsize); - -// next free address to place a map.. maybe just unify -R_API ut64 r_io_map_next_available(RIO* io, ut64 addr, ut64 size, ut64 load_align); -R_API ut64 r_io_map_next_address(RIO* io, ut64 addr); - -// p2v/v2p - -R_API ut64 r_io_p2v(RIO *io, ut64 pa); -R_API ut64 r_io_v2p(RIO *io, ut64 va); - -//io.c -R_API RIO *r_io_new (void); -R_API RIO *r_io_init (RIO *io); -R_API RIODesc *r_io_open_nomap (RIO *io, const char *uri, int flags, int mode); //should return int -R_API RIODesc *r_io_open (RIO *io, const char *uri, int flags, int mode); -R_API RIODesc *r_io_open_at (RIO *io, const char *uri, int flags, int mode, ut64 at); -R_API RList *r_io_open_many (RIO *io, const char *uri, int flags, int mode); -R_API RIODesc* r_io_open_buffer (RIO *io, RBuffer *b, int flags, int mode); -R_API bool r_io_close (RIO *io); -R_API bool r_io_reopen (RIO *io, int fd, int flags, int mode); -R_API int r_io_close_all (RIO *io); -R_API int r_io_pread_at (RIO *io, ut64 paddr, ut8 *buf, int len); -R_API int r_io_pwrite_at (RIO *io, ut64 paddr, const ut8 *buf, int len); -R_API bool r_io_vread_at_mapped(RIO* io, ut64 vaddr, ut8* buf, int len); -R_API bool r_io_read_at (RIO *io, ut64 addr, ut8 *buf, int len); -R_API bool r_io_read_at_mapped(RIO *io, ut64 addr, ut8 *buf, int len); -R_API int r_io_nread_at (RIO *io, ut64 addr, ut8 *buf, int len); -R_API void r_io_alprint(RList *ls); -R_API bool r_io_write_at (RIO *io, ut64 addr, const ut8 *buf, int len); -R_API bool r_io_read (RIO *io, ut8 *buf, int len); -R_API bool r_io_write (RIO *io, ut8 *buf, int len); -R_API ut64 r_io_size (RIO *io); -R_API bool r_io_is_listener (RIO *io); -R_API char *r_io_system (RIO *io, const char* cmd); -R_API bool r_io_resize (RIO *io, ut64 newsize); -R_API int r_io_extend_at (RIO *io, ut64 addr, ut64 size); -R_API bool r_io_set_write_mask (RIO *io, const ut8 *mask, int len); -R_API void r_io_bind(RIO *io, RIOBind *bnd); -R_API bool r_io_shift (RIO *io, ut64 start, ut64 end, st64 move); -R_API ut64 r_io_seek (RIO *io, ut64 offset, int whence); -R_API int r_io_fini (RIO *io); -R_API void r_io_free (RIO *io); -#define r_io_bind_init(x) memset(&x,0,sizeof(x)) - -R_API bool r_io_plugin_init(RIO *io); -R_API int r_io_plugin_open(RIO *io, int fd, RIOPlugin *plugin); -R_API int r_io_plugin_close(RIO *io, int fd, RIOPlugin *plugin); -R_API int r_io_plugin_generate(RIO *io); -R_API bool r_io_plugin_add(RIO *io, RIOPlugin *plugin); -R_API int r_io_plugin_list(RIO *io); -R_API int r_io_plugin_list_json(RIO *io); -R_API int r_io_plugin_read(RIODesc *desc, ut8 *buf, int len); -R_API int r_io_plugin_write(RIODesc *desc, const ut8 *buf, int len); -R_API int r_io_plugin_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len); -R_API int r_io_plugin_write_at(RIODesc *desc, ut64 addr, const ut8 *buf, int len); -R_API RIOPlugin *r_io_plugin_resolve(RIO *io, const char *filename, bool many); -R_API RIOPlugin *r_io_plugin_resolve_fd(RIO *io, int fd); -R_API RIOPlugin *r_io_plugin_get_default(RIO *io, const char *filename, bool many); - -/* undo api */ -// track seeks and writes -// TODO: needs cleanup..kinda big? -R_API int r_io_undo_init(RIO *io); -R_API void r_io_undo_enable(RIO *io, int seek, int write); -/* seek undo */ -R_API RIOUndos *r_io_sundo(RIO *io, ut64 offset); -R_API RIOUndos *r_io_sundo_redo(RIO *io); -R_API void r_io_sundo_push(RIO *io, ut64 off, int cursor); -R_API void r_io_sundo_reset(RIO *io); -R_API RList *r_io_sundo_list(RIO *io, int mode); -/* write undo */ -R_API void r_io_wundo_new(RIO *io, ut64 off, const ut8 *data, int len); -R_API void r_io_wundo_apply_all(RIO *io, int set); -R_API int r_io_wundo_apply(RIO *io, struct r_io_undo_w_t *u, int set); -R_API void r_io_wundo_clear(RIO *io); -R_API int r_io_wundo_size(RIO *io); -R_API void r_io_wundo_list(RIO *io); -R_API int r_io_wundo_set_t(RIO *io, RIOUndoWrite *u, int set) ; -R_API void r_io_wundo_set_all(RIO *io, int set); -R_API int r_io_wundo_set(RIO *io, int n, int set); - -//desc.c -R_API RIODesc *r_io_desc_new (RIO *io, RIOPlugin *plugin, const char *uri, int flags, int mode, void *data); -R_API RIODesc *r_io_desc_open (RIO *io, const char *uri, int flags, int mode); -R_API RIODesc *r_io_desc_open_plugin (RIO *io, RIOPlugin *plugin, const char *uri, int flags, int mode); -R_API bool r_io_desc_close (RIODesc *desc); -R_API int r_io_desc_read (RIODesc *desc, ut8 *buf, int count); -R_API int r_io_desc_write (RIODesc *desc, const ut8 *buf, int count); -R_API void r_io_desc_free (RIODesc *desc); -R_API bool r_io_desc_add (RIO *io, RIODesc *desc); -R_API bool r_io_desc_del (RIO *io, int fd); -R_API RIODesc *r_io_desc_get (RIO *io, int fd); -R_API ut64 r_io_desc_seek (RIODesc *desc, ut64 offset, int whence); -R_API bool r_io_desc_resize (RIODesc *desc, ut64 newsize); -R_API ut64 r_io_desc_size (RIODesc *desc); -R_API bool r_io_desc_is_blockdevice (RIODesc *desc); -R_API bool r_io_desc_is_chardevice (RIODesc *desc); -R_API bool r_io_desc_exchange (RIO *io, int fd, int fdx); //this should get 2 descs -R_API bool r_io_desc_is_dbg (RIODesc *desc); -R_API int r_io_desc_get_pid (RIODesc *desc); -R_API int r_io_desc_get_tid (RIODesc *desc); -R_API bool r_io_desc_get_base (RIODesc *desc, ut64 *base); -R_API int r_io_desc_read_at (RIODesc *desc, ut64 addr, ut8 *buf, int len); -R_API int r_io_desc_write_at (RIODesc *desc, ut64 addr, const ut8 *buf, int len); - -/* lifecycle */ -R_IPI bool r_io_desc_init (RIO *io); -R_IPI bool r_io_desc_fini (RIO *io); - -/* io/cache.c */ -R_API int r_io_cache_invalidate(RIO *io, ut64 from, ut64 to); -R_API bool r_io_cache_at(RIO *io, ut64 addr); -R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to); -R_API void r_io_cache_init(RIO *io); -R_API void r_io_cache_fini (RIO *io); -R_API int r_io_cache_list(RIO *io, int rad); -R_API void r_io_cache_reset(RIO *io, int set); -R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len); -R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len); - -/* io/p_cache.c */ -R_API bool r_io_desc_cache_init(RIODesc *desc); -R_API int r_io_desc_cache_write(RIODesc *desc, ut64 paddr, const ut8 *buf, int len); -R_API int r_io_desc_cache_read(RIODesc *desc, ut64 paddr, ut8 *buf, int len); -R_API bool r_io_desc_cache_commit(RIODesc *desc); -R_API void r_io_desc_cache_cleanup(RIODesc *desc); -R_API void r_io_desc_cache_fini(RIODesc *desc); -R_API void r_io_desc_cache_fini_all(RIO *io); -R_API RList *r_io_desc_cache_list(RIODesc *desc); -R_API int r_io_desc_extend(RIODesc *desc, ut64 size); - -/* io/buffer.c */ -R_API int r_io_buffer_read (RIO* io, ut64 addr, ut8* buf, int len); -R_API int r_io_buffer_load (RIO* io, ut64 addr, int len); -R_API void r_io_buffer_close (RIO* io); - -/* io/fd.c */ -R_API int r_io_fd_open (RIO *io, const char *uri, int flags, int mode); -R_API bool r_io_fd_close (RIO *io, int fd); -R_API int r_io_fd_read (RIO *io, int fd, ut8 *buf, int len); -R_API int r_io_fd_write (RIO *io, int fd, const ut8 *buf, int len); -R_API ut64 r_io_fd_seek (RIO *io, int fd, ut64 addr, int whence); -R_API ut64 r_io_fd_size (RIO *io, int fd); -R_API bool r_io_fd_resize (RIO *io, int fd, ut64 newsize); -R_API bool r_io_fd_is_blockdevice (RIO *io, int fd); -R_API bool r_io_fd_is_chardevice (RIO *io, int fd); -R_API int r_io_fd_read_at (RIO *io, int fd, ut64 addr, ut8 *buf, int len); -R_API int r_io_fd_write_at (RIO *io, int fd, ut64 addr, const ut8 *buf, int len); -R_API bool r_io_fd_is_dbg (RIO *io, int fd); -R_API int r_io_fd_get_pid (RIO *io, int fd); -R_API int r_io_fd_get_tid (RIO *io, int fd); -R_API bool r_io_fd_get_base (RIO *io, int fd, ut64 *base); -R_API const char *r_io_fd_get_name (RIO *io, int fd); -R_API int r_io_fd_get_current(RIO *io); -R_API bool r_io_use_fd (RIO *io, int fd); - - -#define r_io_range_new() R_NEW0(RIORange) -#define r_io_range_free(x) free(x) - -/* io/ioutils.c */ -R_API bool r_io_is_valid_offset (RIO *io, ut64 offset, int hasperm); -R_API bool r_io_addr_is_mapped(RIO *io, ut64 vaddr); -R_API bool r_io_read_i (RIO* io, ut64 addr, ut64 *val, int size, bool endian); -R_API bool r_io_write_i (RIO* io, ut64 addr, ut64 *val, int size, bool endian); - -#if HAVE_PTRACE -R_API long r_io_ptrace(RIO *io, r_ptrace_request_t request, pid_t pid, void *addr, r_ptrace_data_t data); -R_API pid_t r_io_ptrace_fork(RIO *io, void (*child_callback)(void *), void *child_callback_user); -R_API void *r_io_ptrace_func(RIO *io, void *(*func)(void *), void *user); -#endif - -extern RIOPlugin r_io_plugin_procpid; -extern RIOPlugin r_io_plugin_malloc; -extern RIOPlugin r_io_plugin_sparse; -extern RIOPlugin r_io_plugin_ptrace; -extern RIOPlugin r_io_plugin_w32dbg; -extern RIOPlugin r_io_plugin_windbg; -extern RIOPlugin r_io_plugin_mach; -extern RIOPlugin r_io_plugin_debug; -extern RIOPlugin r_io_plugin_shm; -extern RIOPlugin r_io_plugin_gdb; -extern RIOPlugin r_io_plugin_rap; -extern RIOPlugin r_io_plugin_http; -extern RIOPlugin r_io_plugin_bfdbg; -extern RIOPlugin r_io_plugin_w32; -extern RIOPlugin r_io_plugin_zip; -extern RIOPlugin r_io_plugin_mmap; -extern RIOPlugin r_io_plugin_default; -extern RIOPlugin r_io_plugin_ihex; -extern RIOPlugin r_io_plugin_self; -extern RIOPlugin r_io_plugin_gzip; -extern RIOPlugin r_io_plugin_winkd; -extern RIOPlugin r_io_plugin_r2pipe; -extern RIOPlugin r_io_plugin_r2web; -extern RIOPlugin r_io_plugin_qnx; -extern RIOPlugin r_io_plugin_r2k; -extern RIOPlugin r_io_plugin_tcp; -extern RIOPlugin r_io_plugin_bochs; -extern RIOPlugin r_io_plugin_null; -extern RIOPlugin r_io_plugin_ar; -extern RIOPlugin r_io_plugin_rbuf; -extern RIOPlugin r_io_plugin_winedbg; -extern RIOPlugin r_io_plugin_gprobe; -extern RIOPlugin r_io_plugin_fd; - -#if __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_lang.h b/libr/include/r_lang.h deleted file mode 100644 index f29ab5ff14..0000000000 --- a/libr/include/r_lang.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef R2_LANG_H -#define R2_LANG_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_lang); - -typedef char* (*RCoreCmdStrCallback)(void* core, const char *s); -typedef int (*RCoreCmdfCallback)(void* core, const char *s, ...); - -typedef struct r_lang_t { - struct r_lang_plugin_t *cur; - void *user; - RList *defs; - RList *langs; - PrintfCallback cb_printf; - RCoreCmdStrCallback cmd_str; - RCoreCmdfCallback cmdf; -} RLang; - -typedef struct r_lang_plugin_t { - const char *name; - const char *alias; - const char *desc; - const char *license; - const char **help; - const char *ext; - int (*init)(RLang *user); - bool (*setup)(RLang *user); - int (*fini)(RLang *user); - int (*prompt)(RLang *user); - int (*run)(RLang *user, const char *code, int len); - int (*run_file)(RLang *user, const char *file); - int (*set_argv)(RLang *user, int argc, char **argv); -} RLangPlugin; - -typedef struct r_lang_def_t { - char *name; - char *type; - void *value; -} RLangDef; - -#ifdef R_API -R_API RLang *r_lang_new(void); -R_API void r_lang_free(RLang *lang); -R_API bool r_lang_setup(RLang *lang); -R_API bool r_lang_add(RLang *lang, RLangPlugin *foo); -R_API bool r_lang_list(RLang *lang); -R_API bool r_lang_use(RLang *lang, const char *name); -R_API int r_lang_run(RLang *lang, const char *code, int len); -R_API int r_lang_run_string(RLang *lang, const char *code); -/* TODO: user_ptr must be deprecated */ -R_API void r_lang_set_user_ptr(RLang *lang, void *user); -R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv); -R_API int r_lang_run(RLang *lang, const char *code, int len); -R_API int r_lang_run_file(RLang *lang, const char *file); -R_API int r_lang_prompt(RLang *lang); -R_API void r_lang_plugin_free(RLangPlugin *p); // XXX -R_API RLangPlugin *r_lang_get_by_name(RLang *lang, const char *name); -R_API RLangPlugin *r_lang_get_by_extension(RLang *lang, const char *ext); -// TODO: rename r_Lang_add for r_lang_plugin_add - -R_API bool r_lang_define(RLang *lang, const char *type, const char *name, void *value); -R_API void r_lang_undef(RLang *lang, const char *name); -R_API void r_lang_def_free(RLangDef *def); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_lib.h b/libr/include/r_lib.h deleted file mode 100644 index 4ab554cc5e..0000000000 --- a/libr/include/r_lib.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef R2_LIB_H -#define R2_LIB_H - -#include "r_types.h" -#include "r_list.h" - -#if __UNIX__ -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER (r_lib); - -// rename to '.' ?? -#define R_LIB_SEPARATOR "." -#define R_LIB_SYMNAME "radare_plugin" -#define R_LIB_SYMFUNC "radare_plugin_function" - -#define R_LIB_ENV "R2_LIBR_PLUGINS" - -/* TODO: This must depend on HOST_OS, and maybe move into r_types */ -#if __WINDOWS__ -#include -#define R_LIB_EXT "dll" -#elif __APPLE__ -#define R_LIB_EXT "dylib" -#else -#define R_LIB_EXT "so" -#endif - -/* store list of loaded plugins */ -typedef struct r_lib_plugin_t { - int type; - char *file; - void *data; /* user pointer */ - struct r_lib_handler_t *handler; - void *dl_handler; // DL HANDLER - char *author; - char *version; - void (*free)(void *data); -} RLibPlugin; - -/* store list of initialized plugin handlers */ -typedef struct r_lib_handler_t { - int type; - char desc[128]; // TODO: use char * - void *user; /* user pointer */ - int (*constructor)(RLibPlugin *, void *user, void *data); - int (*destructor)(RLibPlugin *, void *user, void *data); -} RLibHandler; - -/* this structure should be pointed by the 'radare_plugin' symbol - found in the loaded .so */ -typedef struct r_lib_struct_t { - int type; - void *data; /* pointer to data handled by plugin handler */ - const char *version; /* r2 version */ - void (*free)(void *data); - const char *pkgname; /* pkgname associated to this plugin */ -} RLibStruct; - -typedef RLibStruct* (*RLibStructFunc) (void); - -// order matters because of libr/util/lib.c -enum { - R_LIB_TYPE_IO, /* io layer */ - R_LIB_TYPE_DBG, /* debugger */ - R_LIB_TYPE_LANG, /* language */ - R_LIB_TYPE_ASM, /* assembler */ - R_LIB_TYPE_ANAL, /* analysis */ - R_LIB_TYPE_PARSE, /* parsers */ - R_LIB_TYPE_BIN, /* bin headers */ - R_LIB_TYPE_BIN_XTR, /* bin extractors */ - R_LIB_TYPE_BIN_LDR, /* bin loaders */ - R_LIB_TYPE_BP, /* breakpoint */ - R_LIB_TYPE_SYSCALL, /* syscall */ - R_LIB_TYPE_FASTCALL,/* fastcall */ - R_LIB_TYPE_CRYPTO, /* cryptography */ - R_LIB_TYPE_CORE, /* RCore commands */ - R_LIB_TYPE_EGG, /* r_egg plugin */ - R_LIB_TYPE_FS, /* r_fs plugin */ - R_LIB_TYPE_LAST -}; - -typedef struct r_lib_t { - /* linked list with all the plugin handler */ - /* only one handler per handler-id allowed */ - /* this is checked in add_handler function */ - char *symname; - char *symnamefunc; - RList /*RLibPlugin*/ *plugins; - RList /*RLibHandler*/ *handlers; -} RLib; - -#ifdef R_API -/* low level api */ -R_API void *r_lib_dl_open(const char *libname); - -R_API void *r_lib_dl_sym(void *handler, const char *name); -R_API int r_lib_dl_close(void *handler); - -/* high level api */ -typedef int (*RLibCallback)(RLibPlugin *, void *, void *); -R_API RLib *r_lib_new(const char *symname, const char *symnamefunc); -R_API void r_lib_free(RLib *lib); -R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol); -R_API RLibHandler *r_lib_get_handler(RLib *lib, int type); -R_API int r_lib_open(RLib *lib, const char *file); -R_API bool r_lib_opendir(RLib *lib, const char *path); -R_API int r_lib_open_ptr (RLib *lib, const char *file, void *handler, RLibStruct *stru); -R_API char *r_lib_path(const char *libname); -R_API void r_lib_list(RLib *lib); -R_API bool r_lib_add_handler(RLib *lib, int type, const char *desc, RLibCallback ct, RLibCallback dt, void *user); -R_API bool r_lib_del_handler(RLib *lib, int type); -R_API int r_lib_close(RLib *lib, const char *file); - -R_API const char *r_lib_types_get(int idx); -R_API int r_lib_types_get_i(const char *str); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_list.h b/libr/include/r_list.h deleted file mode 100644 index aa6e748639..0000000000 --- a/libr/include/r_list.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef R2_LIST_H -#define R2_LIST_H - -#include -#include -#include -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _INCLUDE_R_LIST_HEAD_H_ -#define _INCLUDE_R_LIST_HEAD_H_ -typedef void (*RListFree)(void *ptr); - -typedef struct r_list_iter_t { - void *data; - struct r_list_iter_t *n, *p; -} RListIter; - -typedef struct r_list_t { - RListIter *head; - RListIter *tail; - RListFree free; - int length; - bool sorted; -} RList; - -typedef struct r_list_range_t { - HtPP *h; - RList *l; - //RListComparator c; -} RListRange; - -// RListComparator should return -1, 0, 1 to indicate "ab". -typedef int (*RListComparator)(const void *a, const void *b); - -#define ROFList_Parent RList -typedef struct r_oflist_t { - ROFList_Parent super; // super class - RFList *array; // statical readonly cache of linked list as a pointer array -} ROFList; -#endif - -#ifdef R_API -// #define R_LIST_NEW(x,y) x = r_list_new (); x->free = (RListFree)y -#define r_list_foreach(list, it, pos)\ - if (list)\ - for (it = list->head; it && (pos = it->data, 1); it = it->n) -#define r_list_foreach_iter(list, it)\ - if (list)\ - for (it = list->head; it; it = it->n) -/* Safe when calling r_list_delete() while iterating over the list. */ -#define r_list_foreach_safe(list, it, tmp, pos)\ - if (list)\ - for (it = list->head; it && (pos = it->data, tmp = it->n, 1); it = tmp) -#define r_list_foreach_prev(list, it, pos)\ - if (list)\ - for (it = list->tail; it && (pos = it->data, 1); it = it->p) -#define r_list_foreach_prev_safe(list, it, tmp, pos) \ - for (it = list->tail; it && (pos = it->data, tmp = it->p, 1); it = tmp) -#ifndef _R_LIST_C_ -#define r_list_push(x, y) r_list_append (x, y) -#define r_list_iterator(x) (x)? (x)->head: NULL -// #define r_list_empty(x) (!x || (!(x->head) && !(x->tail))) -#define r_list_empty(x) (!(x) || !(x)->length) -#define r_list_head(x) ((x)? (x)->head: NULL) -#define r_list_tail(x) ((x)? (x)->tail: NULL) - -#define r_list_iter_get(x)\ - x->data;\ - x = x->n -#define r_list_iter_next(x) (x? 1: 0) - -#define r_list_iter_cur(x) x->p -#define r_list_iter_free(x) x -#endif -R_API RList *r_list_new(void); -R_API RList *r_list_newf(RListFree f); -R_API RListIter *r_list_iter_get_next(RListIter *list); -R_API int r_list_set_n(RList *list, int n, void *p); -R_API void *r_list_iter_get_data(RListIter *list); -R_API RListIter *r_list_append(RList *list, void *data); -R_API RListIter *r_list_prepend(RList *list, void *data); -R_API RListIter *r_list_insert(RList *list, int n, void *data); -R_API int r_list_length(const RList *list); -R_API void *r_list_first(const RList *list); -R_API void *r_list_last(const RList *list); -R_API RListIter *r_list_add_sorted(RList *list, void *data, RListComparator cmp); -R_API void r_list_sort(RList *list, RListComparator cmp); -R_API void r_list_merge_sort(RList *list, RListComparator cmp); -R_API void r_list_insertion_sort(RList *list, RListComparator cmp); -R_API RList *r_list_uniq(const RList *list, RListComparator cmp); -R_API void r_list_init(RList *list); -R_API void r_list_delete(RList *list, RListIter *iter); -R_API bool r_list_delete_data(RList *list, void *ptr); -R_API void r_list_iter_init(RListIter *iter, RList *list); -R_API void r_list_purge(RList *list); -R_API void r_list_free(RList *list); -R_API RListIter *r_list_item_new(void *data); -R_API void r_list_split(RList *list, void *ptr); -R_API void r_list_split_iter(RList *list, RListIter *iter); -R_API int r_list_join(RList *list1, RList *list2); -R_API void *r_list_get_n(const RList *list, int n); -R_API int r_list_del_n(RList *list, int n); -R_API void *r_list_get_top(const RList *list); -R_API void *r_list_get_bottom(const RList *list); -R_API void *r_list_pop(RList *list); -R_API void *r_list_pop_head(RList *list); -R_API void r_list_reverse(RList *list); -R_API RList *r_list_clone(const RList *list); -R_API char *r_list_to_str(RList *list, char ch); - -/* hashlike api */ -R_API RListIter *r_list_contains(const RList *list, const void *p); -R_API RListIter *r_list_find(const RList *list, const void *p, RListComparator cmp); - -/* rlistflist */ -// TODO: rename to init or so.. #define r_oflist_new() R_NEW(ROFList);memset -#define r_oflist_length(x, y) r_list_length (x, y) -#define r_oflist_destroy(x) r_oflist_deserialize (x) -#define r_oflist_free(x) r_oflist_deserialize (x), r_list_free (x) -#define r_oflist_append(x, y) r_oflist_deserialize (x), r_list_append (x, y) -#define r_oflist_prepend(x, y) r_oflist_deserialize (x), r_list_prepend (x, y) -#define r_oflist_delete(x, y) r_oflist_deserialize (x), r_list_delete (x, y) -#define r_oflist_array(x) x->array? x->array: (x->array = r_oflist_serialize (x)), x->array -#define r_oflist_deserialize(x)\ - free (x->array - 1), x->array = 0 -#define r_oflist_serialize(x)\ - x->array = r_flist_new (r_list_length (x)), { \ - int idx = 0;\ - void *ptr;\ - RListIter *iter;\ - r_list_foreach (x, iter, ptr) r_flist_set (x->array, idx++, ptr);\ - }\ - x->array; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_main.h b/libr/include/r_main.h deleted file mode 100644 index a7555c37bd..0000000000 --- a/libr/include/r_main.h +++ /dev/null @@ -1,36 +0,0 @@ -/* radare - LGPL - Copyright 2008-2020 - pancake */ - -#ifndef R2_MAIN_H -#define R2_MAIN_H - -#include -#include - -R_LIB_VERSION_HEADER(r_main); - -typedef struct r_main_t { - const char *name; - int (*main)(int argc, const char **argv); - // stdin/stdout -} RMain; - -typedef int (*RMainCallback)(int argc, const char **argv); - -R_API RMain *r_main_new(const char *name); -R_API void r_main_free(RMain *m); -R_API int r_main_run(RMain *m, int argc, const char **argv); - -R_API int r_main_version_print(const char *program); -R_API int r_main_rax2(int argc, const char **argv); -R_API int r_main_rarun2(int argc, const char **argv); -R_API int r_main_rahash2(int argc, const char **argv); -R_API int r_main_rabin2(int argc, const char **argv); -R_API int r_main_radare2(int argc, const char **argv); -R_API int r_main_rasm2(int argc, const char **argv); -R_API int r_main_r2agent(int argc, const char **argv); -R_API int r_main_rafind2(int argc, const char **argv); -R_API int r_main_radiff2(int argc, const char **argv); -R_API int r_main_ragg2(int argc, const char **argv); -R_API int r_main_rasign2(int argc, const char **argv); - -#endif diff --git a/libr/include/r_parse.h b/libr/include/r_parse.h deleted file mode 100644 index 0dcd4e92b1..0000000000 --- a/libr/include/r_parse.h +++ /dev/null @@ -1,145 +0,0 @@ -/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */ - -#ifndef R2_PARSE_H -#define R2_PARSE_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_parse); - -typedef RList* (*RAnalVarList)(RAnalFunction *fcn, int kind); - -typedef struct r_parse_t { - void *user; - RSpace *flagspace; - RSpace *notin_flagspace; - bool pseudo; - bool subreg; // replace registers with their respective alias/role name (rdi=A0, ...) - bool subrel; // replace rip relative expressions in instruction - bool subtail; // replace any immediate relative to current address with .. prefix syntax - bool localvar_only; // if true use only the local variable name (e.g. [local_10h] instead of [ebp + local10h]) - ut64 subrel_addr; - int maxflagnamelen; - int minval; - char *retleave_asm; - struct r_parse_plugin_t *cur; - // RAnal *anal; // weak anal ref XXX do not use. use analb.anal - RList *parsers; - RAnalVarList varlist; - st64 (*get_ptr_at)(RAnalFunction *fcn, st64 delta, ut64 addr); - const char *(*get_reg_at)(RAnalFunction *fcn, st64 delta, ut64 addr); - char* (*get_op_ireg)(void *user, ut64 addr); - RAnalBind analb; - RFlagGetAtAddr flag_get; // XXX - RAnalLabelAt label_get; -} RParse; - -typedef struct r_parse_plugin_t { - char *name; - char *desc; - bool (*init)(RParse *p, void *user); - int (*fini)(RParse *p, void *user); - int (*parse)(RParse *p, const char *data, char *str); - bool (*assemble)(RParse *p, char *data, char *str); - int (*filter)(RParse *p, ut64 addr, RFlag *f, char *data, char *str, int len, bool big_endian); - bool (*subvar)(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); - int (*replace)(int argc, const char *argv[], char *newstr); -} RParsePlugin; - -#ifdef R_API - -/* lifecycle */ -R_API struct r_parse_t *r_parse_new(void); -R_API void r_parse_free(RParse *p); - -/* plugins */ -R_API void r_parse_set_user_ptr(RParse *p, void *user); -R_API bool r_parse_add(RParse *p, RParsePlugin *foo); -R_API bool r_parse_use(RParse *p, const char *name); - -/* action */ -R_API bool r_parse_parse(RParse *p, const char *data, char *str); -R_API bool r_parse_assemble(RParse *p, char *data, char *str); // XXX deprecate, unused and probably useless, related to write-hack -R_API bool r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian); -R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); -R_API char *r_parse_immtrim(char *opstr); - -/* c */ -// why we have anal scoped things in rparse -R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg); -R_API char *r_parse_c_file(RAnal *anal, const char *path, const char *dir, char **error_msg); -R_API void r_parse_c_reset(RParse *p); - -/* ctype */ -// Parses strings like "const char * [0x42] const * [23]" to RParseCTypeType - -typedef struct r_parse_ctype_t RParseCType; - -typedef enum { - R_PARSE_CTYPE_TYPE_KIND_IDENTIFIER, - R_PARSE_CTYPE_TYPE_KIND_POINTER, - R_PARSE_CTYPE_TYPE_KIND_ARRAY -} RParseCTypeTypeKind; - -typedef enum { - R_PARSE_CTYPE_IDENTIFIER_KIND_UNSPECIFIED, - R_PARSE_CTYPE_IDENTIFIER_KIND_STRUCT, - R_PARSE_CTYPE_IDENTIFIER_KIND_UNION, - R_PARSE_CTYPE_IDENTIFIER_KIND_ENUM -} RParseCTypeTypeIdentifierKind; - -typedef struct r_parse_ctype_type_t RParseCTypeType; -struct r_parse_ctype_type_t { - RParseCTypeTypeKind kind; - union { - struct { - RParseCTypeTypeIdentifierKind kind; - char *name; - bool is_const; - } identifier; - struct { - RParseCTypeType *type; - bool is_const; - } pointer; - struct { - RParseCTypeType *type; - ut64 count; - } array; - }; -}; - -R_API RParseCType *r_parse_ctype_new(void); -R_API void r_parse_ctype_free(RParseCType *ctype); -R_API RParseCTypeType *r_parse_ctype_parse(RParseCType *ctype, const char *str, char **error); -R_API void r_parse_ctype_type_free(RParseCTypeType *type); - -/* plugin pointers */ -extern RParsePlugin r_parse_plugin_6502_pseudo; -extern RParsePlugin r_parse_plugin_arm_pseudo; -extern RParsePlugin r_parse_plugin_att2intel; -extern RParsePlugin r_parse_plugin_avr_pseudo; -extern RParsePlugin r_parse_plugin_chip8_pseudo; -extern RParsePlugin r_parse_plugin_dalvik_pseudo; -extern RParsePlugin r_parse_plugin_dummy; -extern RParsePlugin r_parse_plugin_m68k_pseudo; -extern RParsePlugin r_parse_plugin_mips_pseudo; -extern RParsePlugin r_parse_plugin_ppc_pseudo; -extern RParsePlugin r_parse_plugin_sh_pseudo; -extern RParsePlugin r_parse_plugin_wasm_pseudo; -extern RParsePlugin r_parse_plugin_x86_pseudo; -extern RParsePlugin r_parse_plugin_z80_pseudo; -extern RParsePlugin r_parse_plugin_tms320_pseudo; -extern RParsePlugin r_parse_plugin_v850_pseudo; -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_pdb.h b/libr/include/r_pdb.h deleted file mode 100644 index 254da9a8df..0000000000 --- a/libr/include/r_pdb.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef R2_PDB_H -#define R2_PDB_H - -#define _R_LIST_C -#include "r_util.h" -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define FILE_NAME_LEN 256 - -struct R_PDB7_ROOT_STREAM; - -typedef struct r_pdb_t { - bool (*pdb_parse)(struct r_pdb_t *pdb); - void (*finish_pdb_parse)(struct r_pdb_t *pdb); - void (*print_types)(const struct r_pdb_t *pdb, PJ *pj, int mode); -// FILE *fp; - PrintfCallback cb_printf; - struct R_PDB7_ROOT_STREAM *root_stream; - void *stream_map; - RList *pdb_streams; - RList *pdb_streams2; - RBuffer *buf; // mmap of file -// int curr; - - void (*print_gvars)(struct r_pdb_t *pdb, ut64 img_base, PJ *pj, int format); -} RPdb; - -R_API bool init_pdb_parser(RPdb *pdb, const char *filename); -R_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer *buf); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_reg.h b/libr/include/r_reg.h deleted file mode 100644 index 7a85fc9575..0000000000 --- a/libr/include/r_reg.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef R2_REG_H -#define R2_REG_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER (r_reg); - -/* - * various CPUs have registers within various types/classes - * this enum aims to cover them all. - */ -typedef enum { - R_REG_TYPE_GPR, - R_REG_TYPE_DRX, - R_REG_TYPE_FPU, - R_REG_TYPE_MMX, - R_REG_TYPE_XMM, - R_REG_TYPE_YMM, - R_REG_TYPE_FLG, - R_REG_TYPE_SEG, - R_REG_TYPE_LAST, - R_REG_TYPE_ALL = -1, // TODO; rename to ANY -} RRegisterType; - -/* - * pretty much all CPUs share some common registers - * this enum aims to create an abstraction to ease cross-arch handling. - */ -typedef enum { - R_REG_NAME_PC, // program counter - R_REG_NAME_SP, // stack pointer - R_REG_NAME_SR, // status register - R_REG_NAME_BP, // base pointer - R_REG_NAME_LR, // link register - /* args */ - R_REG_NAME_A0, // arguments - R_REG_NAME_A1, - R_REG_NAME_A2, - R_REG_NAME_A3, - R_REG_NAME_A4, - R_REG_NAME_A5, - R_REG_NAME_A6, - R_REG_NAME_A7, - R_REG_NAME_A8, - R_REG_NAME_A9, - /* retval */ - R_REG_NAME_R0, // return registers - R_REG_NAME_R1, - R_REG_NAME_R2, - R_REG_NAME_R3, - /* flags */ - R_REG_NAME_ZF, - R_REG_NAME_SF, - R_REG_NAME_CF, - R_REG_NAME_OF, - /* syscall number (orig_eax,rax,r0,x0) */ - R_REG_NAME_SN, - R_REG_NAME_LAST, -} RRegisterId; - -// TODO: use enum here? -#define R_REG_COND_EQ 0 -#define R_REG_COND_NE 1 -#define R_REG_COND_CF 2 -#define R_REG_COND_CARRY 2 -#define R_REG_COND_NEG 3 -#define R_REG_COND_NEGATIVE 3 -#define R_REG_COND_OF 4 -#define R_REG_COND_OVERFLOW 4 -// unsigned -#define R_REG_COND_HI 5 -#define R_REG_COND_HE 6 -#define R_REG_COND_LO 7 -#define R_REG_COND_LOE 8 -// signed -#define R_REG_COND_GE 9 -#define R_REG_COND_GT 10 -#define R_REG_COND_LT 11 -#define R_REG_COND_LE 12 -#define R_REG_COND_LAST 13 - -typedef struct r_reg_item_t { - char *name; - int /*RRegisterType*/ type; - int size; /* 8,16,32,64 ... 128/256 ??? */ - int offset; /* offset in data structure */ - int packed_size; /* 0 means no packed register, 1byte pack, 2b pack... */ - bool is_float; - char *flags; - char *comment; - int index; - int arena; /* in which arena is this reg living */ -} RRegItem; - -typedef struct r_reg_arena_t { - ut8 *bytes; - int size; -} RRegArena; - -typedef struct r_reg_set_t { - RRegArena *arena; - RList *pool; /* RRegArena */ - RList *regs; /* RRegItem */ - HtPP *ht_regs; /* name:RRegItem */ - RListIter *cur; - int maskregstype; /* which type of regs have this reg set (logic mask with RRegisterType R_REG_TYPE_XXX) */ -} RRegSet; - -typedef struct r_reg_t { - char *profile; - char *reg_profile_cmt; - char *reg_profile_str; - char *name[R_REG_NAME_LAST]; // aliases - RRegSet regset[R_REG_TYPE_LAST]; - RList *allregs; - RList *roregs; - int iters; - int arch; - int bits; - int size; - bool is_thumb; - bool big_endian; -} RReg; - -typedef struct r_reg_flags_t { - bool s; // sign, negative number (msb) - bool z; // zero - bool a; // half-carry adjust (if carry happens at nibble level) - bool c; // carry - bool o; // overflow - bool p; // parity (lsb) -} RRegFlags; - -#ifdef R_API -R_API void r_reg_free(RReg *reg); -R_API void r_reg_free_internal(RReg *reg, bool init); -R_API RReg *r_reg_new(void); -R_API bool r_reg_set_name(RReg *reg, int role, const char *name); -R_API bool r_reg_set_profile_string(RReg *reg, const char *profile); -R_API char* r_reg_profile_to_cc(RReg *reg); -R_API bool r_reg_set_profile(RReg *reg, const char *profile); -R_API char *r_reg_parse_gdb_profile(const char *profile); -R_API bool r_reg_is_readonly(RReg *reg, RRegItem *item); - -R_API RRegSet *r_reg_regset_get(RReg *r, int type); -R_API ut64 r_reg_getv(RReg *reg, const char *name); -R_API ut64 r_reg_setv(RReg *reg, const char *name, ut64 val); -R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32); -R_API const char *r_reg_64_to_32(RReg *reg, const char *rreg64); -R_API const char *r_reg_get_name_by_type(RReg *reg, const char *name); -R_API const char *r_reg_get_type(int idx); -R_API const char *r_reg_get_name(RReg *reg, int kind); -R_API const char *r_reg_get_role(int role); -R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type); -R_API RList *r_reg_get_list(RReg *reg, int type); -R_API RRegItem *r_reg_get_at(RReg *reg, int type, int regsize, int delta); -R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8 *buf, int buflen, RRegItem *prev_ri, int regsize); - -R_API void r_reg_reindex(RReg *reg); -R_API RRegItem *r_reg_index_get(RReg *reg, int idx); - -/* Item */ -R_API void r_reg_item_free(RRegItem *item); - -/* XXX: dupped ?? */ -R_API int r_reg_type_by_name(const char *str); -R_API int r_reg_get_name_idx(const char *type); - -R_API RRegItem *r_reg_cond_get(RReg *reg, const char *name); -R_API void r_reg_cond_apply(RReg *r, RRegFlags *f); -R_API bool r_reg_cond_set(RReg *reg, const char *name, bool val); -R_API int r_reg_cond_get_value(RReg *r, const char *name); -R_API bool r_reg_cond_bits_set(RReg *r, int type, RRegFlags *f, bool v); -R_API int r_reg_cond_bits(RReg *r, int type, RRegFlags *f); -R_API RRegFlags *r_reg_cond_retrieve(RReg *r, RRegFlags *); -R_API int r_reg_cond(RReg *r, int type); - -/* integer value 8-64 bits */ -R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item); -R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val); -R_API ut64 r_reg_get_value_by_role(RReg *reg, RRegisterId role); -R_API bool r_reg_set_value(RReg *reg, RRegItem *item, ut64 value); -R_API bool r_reg_set_value_by_role(RReg *reg, RRegisterId role, ut64 value); - -/* float */ -R_API float r_reg_get_float(RReg *reg, RRegItem *item); -R_API bool r_reg_set_float(RReg *reg, RRegItem *item, float value); - -/* double */ -R_API double r_reg_get_double(RReg *reg, RRegItem *item); -R_API bool r_reg_set_double(RReg *reg, RRegItem *item, double value); - -/* long double */ -R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item); -R_API bool r_reg_set_longdouble(RReg *reg, RRegItem *item, long double value); - -/* boolean */ -R_API char *r_reg_get_bvalue(RReg *reg, RRegItem *item); -R_API ut64 r_reg_set_bvalue(RReg *reg, RRegItem *item, const char *str); - -/* packed registers */ -R_API int r_reg_set_pack(RReg *reg, RRegItem *item, int packidx, int packbits, ut64 val); -R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits); - -/* byte arena */ -R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size); -R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8 *buf, const int len); -R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len); -R_API int r_reg_arena_set_bytes(RReg *reg, const char *str); -R_API RRegArena *r_reg_arena_new(int size); -R_API void r_reg_arena_free(RRegArena *ra); -R_API int r_reg_fit_arena(RReg *reg); -R_API void r_reg_arena_swap(RReg *reg, int copy); -R_API int r_reg_arena_push(RReg *reg); -R_API void r_reg_arena_pop(RReg *reg); -R_API void r_reg_arena_zero(RReg *reg); - -R_API ut8 *r_reg_arena_peek(RReg *reg); -R_API void r_reg_arena_poke(RReg *reg, const ut8 *buf); -R_API ut8 *r_reg_arena_dup(RReg *reg, const ut8 *source); -R_API const char *r_reg_cond_to_string(int n); -R_API int r_reg_cond_from_string(const char *str); -R_API void r_reg_arena_shrink(RReg *reg); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/libr/include/r_search.h b/libr/include/r_search.h deleted file mode 100644 index a4e002d863..0000000000 --- a/libr/include/r_search.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef R2_SEARCH_H -#define R2_SEARCH_H - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_search); - -enum { - R_SEARCH_ESIL, - R_SEARCH_KEYWORD, - R_SEARCH_REGEXP, - R_SEARCH_PATTERN, - R_SEARCH_STRING, - R_SEARCH_XREFS, - R_SEARCH_AES, - R_SEARCH_PRIV_KEY, - R_SEARCH_DELTAKEY, - R_SEARCH_MAGIC, - R_SEARCH_LAST -}; - -#define R_SEARCH_DISTANCE_MAX 10 - -#define R_SEARCH_KEYWORD_TYPE_BINARY 'i' -#define R_SEARCH_KEYWORD_TYPE_STRING 's' - -typedef struct r_search_keyword_t { - ut8 *bin_keyword; - ut8 *bin_binmask; - ut32 keyword_length; - ut32 binmask_length; - void *data; - int count; - int kwidx; - int icase; // ignore case - int type; - ut64 last; // last hit hint -} RSearchKeyword; - -typedef struct r_search_hit_t { - RSearchKeyword *kw; - ut64 addr; -} RSearchHit; - -typedef int (*RSearchCallback)(RSearchKeyword *kw, void *user, ut64 where); - -typedef struct r_search_t { - int n_kws; // hit${n_kws}_${count} - int mode; - ut32 pattern_size; - ut32 string_min; // max length of strings for R_SEARCH_STRING - ut32 string_max; // min length of strings for R_SEARCH_STRING - void *data; // data used by search algorithm - void *user; // user data passed to callback - RSearchCallback callback; - ut64 nhits; - ut64 maxhits; // search.maxhits - RList *hits; - int distance; - int inverse; - bool overlap; // whether two matches can overlap - int contiguous; - int align; - int (*update)(struct r_search_t *s, ut64 from, const ut8 *buf, int len); - RList *kws; // TODO: Use r_search_kw_new () - RIOBind iob; - char bckwrds; -} RSearch; - -#ifdef R_API - -#define R_SEARCH_AES_BOX_SIZE 31 - -R_API RSearch *r_search_new(int mode); -R_API int r_search_set_mode(RSearch *s, int mode); -R_API RSearch *r_search_free(RSearch *s); - -/* keyword management */ -R_API RList *r_search_find(RSearch *s, ut64 addr, const ut8 *buf, int len); -R_API int r_search_update(RSearch *s, ut64 from, const ut8 *buf, long len); -R_API int r_search_update_i(RSearch *s, ut64 from, const ut8 *buf, long len); - -R_API void r_search_keyword_free (RSearchKeyword *kw); -R_API RSearchKeyword* r_search_keyword_new(const ut8 *kw, int kwlen, const ut8 *bm, int bmlen, const char *data); -R_API RSearchKeyword* r_search_keyword_new_str(const char *kw, const char *bm, const char *data, int icase); -R_API RSearchKeyword* r_search_keyword_new_wide(const char *kw, const char *bm, const char *data, int icase); -R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data); -R_API RSearchKeyword* r_search_keyword_new_hexmask(const char *kwstr, const char *data); -R_API RSearchKeyword *r_search_keyword_new_regexp (const char *str, const char *data); - -R_API int r_search_kw_add(RSearch *s, RSearchKeyword *kw); -R_API void r_search_reset(RSearch *s, int mode); -R_API void r_search_kw_reset(RSearch *s); -R_API void r_search_string_prepare_backward(RSearch *s); -R_API void r_search_kw_reset(RSearch *s); - -R_API int r_search_range_add(RSearch *s, ut64 from, ut64 to); -R_API int r_search_range_set(RSearch *s, ut64 from, ut64 to); -R_API int r_search_range_reset(RSearch *s); -R_API int r_search_set_blocksize(RSearch *s, ut32 bsize); - -R_API int r_search_bmh(const RSearchKeyword *kw, const ut64 from, const ut8 *buf, const int len, ut64 *out); - -// TODO: is this an internal API? -R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_privkey_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_magic_update(RSearch *_s, ut64 from, const ut8 *buf, int len); -R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_strings_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len); -R_API int r_search_xrefs_update(RSearch *s, ut64 from, const ut8 *buf, int len); -// Returns 2 if search.maxhits is reached, 0 on error, otherwise 1 -R_API int r_search_hit_new(RSearch *s, RSearchKeyword *kw, ut64 addr); -R_API void r_search_set_distance(RSearch *s, int dist); -R_API int r_search_strings(RSearch *s, ut32 min, ut32 max); -R_API int r_search_set_string_limits(RSearch *s, ut32 min, ut32 max); // WTF dupped? -//R_API int r_search_set_callback(RSearch *s, int (*callback)(struct r_search_kw_t *, void *, ut64), void *user); -R_API void r_search_set_callback(RSearch *s, RSearchCallback(callback), void *user); -R_API int r_search_begin(RSearch *s); - -/* pattern search */ -R_API void r_search_pattern_size(RSearch *s, int size); -R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/libr/include/r_sign.h b/libr/include/r_sign.h deleted file mode 100644 index 503047f0a1..0000000000 --- a/libr/include/r_sign.h +++ /dev/null @@ -1,166 +0,0 @@ -#ifndef R2_SIGN_H -#define R2_SIGN_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_sign); - -// XXX those limits should go away -#define R_SIGN_KEY_MAXSZ 1024 -#define R_SIGN_VAL_MAXSZ 10240 - -#define ZIGN_HASH "sha256" -#define R_ZIGN_HASH R_HASH_SHA256 - -typedef enum { - R_SIGN_BYTES = 'b', // bytes pattern - R_SIGN_BYTES_MASK= 'm', // bytes pattern - R_SIGN_BYTES_SIZE= 's', // bytes pattern - R_SIGN_ANAL = 'a', // bytes pattern (anal mask) // wtf ? - R_SIGN_COMMENT = 'c', // comment - R_SIGN_GRAPH = 'g', // graph metrics - R_SIGN_OFFSET = 'o', // addr - R_SIGN_NAME = 'n', // real name - R_SIGN_REFS = 'r', // references - R_SIGN_XREFS = 'x', // xrefs - R_SIGN_VARS = 'v', // variables - R_SIGN_TYPES = 't', // types - R_SIGN_BBHASH = 'h', // basic block hash -} RSignType; - -typedef struct r_sign_graph_t { - int cc; - int nbbs; - int edges; - int ebbs; - int bbsum; -} RSignGraph; - -typedef struct r_sign_bytes_t { - int size; - ut8 *bytes; - ut8 *mask; -} RSignBytes; - -typedef struct r_sign_hash_t { - char *bbhash; -} RSignHash; - -typedef struct r_sign_item_t { - char *name; - char *realname; - char *comment; - const RSpace *space; - - RSignBytes *bytes; - RSignGraph *graph; - ut64 addr; - RList *refs; - RList *xrefs; - RList *vars; - RList *types; - RSignHash *hash; -} RSignItem; - -typedef int (*RSignForeachCallback)(RSignItem *it, void *user); -typedef int (*RSignSearchCallback)(RSignItem *it, RSearchKeyword *kw, ut64 addr, void *user); -typedef int (*RSignGraphMatchCallback)(RSignItem *it, RAnalFunction *fcn, void *user); -typedef int (*RSignOffsetMatchCallback)(RSignItem *it, RAnalFunction *fcn, void *user); -typedef int (*RSignHashMatchCallback)(RSignItem *it, RAnalFunction *fcn, void *user); -typedef int (*RSignRefsMatchCallback)(RSignItem *it, RAnalFunction *fcn, void *user); -typedef int (*RSignVarsMatchCallback)(RSignItem *it, RAnalFunction *fcn, void *user); - -typedef struct r_sign_search_t { - RSearch *search; - RList *items; - RSignSearchCallback cb; - void *user; -} RSignSearch; - -typedef struct r_sign_options_t { - double bytes_diff_threshold; - double graph_diff_threshold; -} RSignOptions; - -typedef struct { - double score; - double bscore; - double gscore; - RSignItem *item; -} RSignCloseMatch; - -#ifdef R_API -R_API bool r_sign_add_bytes(RAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask); -R_API bool r_sign_add_anal(RAnal *a, const char *name, ut64 size, const ut8 *bytes, ut64 at); -R_API bool r_sign_add_graph(RAnal *a, const char *name, RSignGraph graph); -R_API bool r_sign_addto_item(RAnal *a, RSignItem *it, RAnalFunction *fcn, RSignType type); -R_API bool r_sign_add_addr(RAnal *a, const char *name, ut64 addr); -R_API bool r_sign_add_name(RAnal *a, const char *name, const char *realname); -R_API bool r_sign_add_comment(RAnal *a, const char *name, const char *comment); -R_API bool r_sign_add_refs(RAnal *a, const char *name, RList *refs); -R_API bool r_sign_add_xrefs(RAnal *a, const char *name, RList *xrefs); -R_API bool r_sign_add_vars(RAnal *a, const char *name, RList *vars); -R_API bool r_sign_add_types(RAnal *a, const char *name, RList *vars); -R_API bool r_sign_delete(RAnal *a, const char *name); -R_API void r_sign_list(RAnal *a, int format); -R_API RList *r_sign_get_list(RAnal *a); -R_API bool r_sign_add_hash(RAnal *a, const char *name, int type, const char *val, int len); -R_API bool r_sign_add_bb_hash(RAnal *a, RAnalFunction *fcn, const char *name); -R_API char *r_sign_calc_bbhash(RAnal *a, RAnalFunction *fcn); -R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char *v); -R_API RSignItem *r_sign_get_item(RAnal *a, const char *name); -R_API bool r_sign_add_item(RAnal *a, RSignItem *it); - -R_API bool r_sign_foreach(RAnal *a, RSignForeachCallback cb, void *user); - -R_API RSignSearch *r_sign_search_new(void); -R_API void r_sign_search_free(RSignSearch *ss); -R_API void r_sign_search_init(RAnal *a, RSignSearch *ss, int minsz, RSignSearchCallback cb, void *user); -R_API int r_sign_search_update(RAnal *a, RSignSearch *ss, ut64 *at, const ut8 *buf, int len); -R_API bool r_sign_match_graph(RAnal *a, RAnalFunction *fcn, int mincc, RSignGraphMatchCallback cb, void *user); -R_API bool r_sign_match_addr(RAnal *a, RAnalFunction *fcn, RSignOffsetMatchCallback cb, void *user); -R_API bool r_sign_match_hash(RAnal *a, RAnalFunction *fcn, RSignHashMatchCallback cb, void *user); -R_API bool r_sign_match_refs(RAnal *a, RAnalFunction *fcn, RSignRefsMatchCallback cb, void *user); -R_API bool r_sign_match_vars(RAnal *a, RAnalFunction *fcn, RSignRefsMatchCallback cb, void *user); -R_API bool r_sign_match_types(RAnal *a, RAnalFunction *fcn, RSignRefsMatchCallback cb, void *user); - -R_API bool r_sign_load(RAnal *a, const char *file); -R_API bool r_sign_load_gz(RAnal *a, const char *filename); -R_API char *r_sign_path(RAnal *a, const char *file); -R_API bool r_sign_save(RAnal *a, const char *file); - -R_API RSignItem *r_sign_item_new(void); -R_API void r_sign_item_free(RSignItem *item); -R_API void r_sign_graph_free(RSignGraph *graph); -R_API void r_sign_bytes_free(RSignBytes *bytes); - -R_API RList *r_sign_fcn_refs(RAnal *a, RAnalFunction *fcn); -R_API RList *r_sign_fcn_xrefs(RAnal *a, RAnalFunction *fcn); -R_API RList *r_sign_fcn_vars(RAnal *a, RAnalFunction *fcn); -R_API RList *r_sign_fcn_types(RAnal *a, RAnalFunction *fcn); - -R_API int r_sign_is_flirt(RBuffer *buf); -R_API void r_sign_flirt_dump(const RAnal *anal, const char *flirt_file); -R_API void r_sign_flirt_scan(RAnal *anal, const char *flirt_file); - -R_API RList *r_sign_find_closest_sig(RAnal *a, RSignItem *it, int count, double score_threshold); -R_API RList *r_sign_find_closest_fcn(RAnal *a, RSignItem *it, int count, double score_threshold); -R_API void r_sign_close_match_free(RSignCloseMatch *match); -R_API bool r_sign_diff(RAnal *a, RSignOptions *options, const char *other_space_name); -R_API bool r_sign_diff_by_name(RAnal *a, RSignOptions *options, const char *other_space_name, bool not_matching); - -R_API RSignOptions *r_sign_options_new(const char *bytes_thresh, const char *graph_thresh); -R_API void r_sign_options_free(RSignOptions *options); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_skiplist.h b/libr/include/r_skiplist.h deleted file mode 100644 index 9a2003a21a..0000000000 --- a/libr/include/r_skiplist.h +++ /dev/null @@ -1,57 +0,0 @@ -// (c) 2016 Jeffrey Crowell -// BSD 3 Clause License -// radare2 - -// Skiplists are a probabilistic datastructure than can be used as a k-v store -// with average case O(lg n) lookup time, and worst case O(n). - -// https://en.wikipedia.org/wiki/Skip_list - -#ifndef R2_SKIP_LIST_H -#define R2_SKIP_LIST_H - -#include - -typedef struct r_skiplist_node_t { - void *data; // pointer to the value - struct r_skiplist_node_t **forward; // forward pointer -} RSkipListNode; - -typedef struct r_skiplist_t { - RSkipListNode *head; // list header - int list_level; // current level of the list. - int size; - RListFree freefn; - RListComparator compare; -} RSkipList; - -R_API RSkipList* r_skiplist_new(RListFree freefn, RListComparator comparefn); -R_API void r_skiplist_free(RSkipList *list); -R_API void r_skiplist_purge(RSkipList *list); -R_API RSkipListNode* r_skiplist_insert(RSkipList* list, void* data); -R_API bool r_skiplist_delete(RSkipList* list, void* data); -R_API bool r_skiplist_delete_node(RSkipList *list, RSkipListNode *node); -R_API RSkipListNode* r_skiplist_find(RSkipList* list, void* data); -R_API RSkipListNode* r_skiplist_find_geq(RSkipList* list, void* data); -R_API RSkipListNode* r_skiplist_find_leq(RSkipList* list, void* data); -R_API void r_skiplist_join(RSkipList *l1, RSkipList *l2); -R_API void *r_skiplist_get_first(RSkipList *list); -R_API void *r_skiplist_get_n(RSkipList *list, int n); -R_API void* r_skiplist_get_geq(RSkipList* list, void* data); -R_API void* r_skiplist_get_leq(RSkipList* list, void* data); -R_API bool r_skiplist_empty(RSkipList *list); -R_API RList *r_skiplist_to_list(RSkipList *list); - -#define r_skiplist_islast(list, el) (el->forward[0] == list->head) - -#define r_skiplist_length(list) (list->size) - -#define r_skiplist_foreach(list, it, pos)\ - if (list)\ - for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1); it = it->forward[0]) - -#define r_skiplist_foreach_safe(list, it, tmp, pos)\ - if (list)\ - for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1) && ((tmp = it->forward[0]) || 1); it = tmp) - -#endif // R2_SKIP_LIST_H diff --git a/libr/include/r_socket.h b/libr/include/r_socket.h deleted file mode 100644 index 697869401c..0000000000 --- a/libr/include/r_socket.h +++ /dev/null @@ -1,288 +0,0 @@ -#ifndef R2_SOCKET_H -#define R2_SOCKET_H - -#include "r_types.h" -#include "r_bind.h" -#include "r_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER (r_socket); - -#if __UNIX__ -#include -#include -#include -#include -#include -#include -#include -#endif - -#if HAVE_LIB_SSL -#include -#include -#endif - -#if __UNIX__ -#include -#endif - -/* For the Mingw-W64 toolchain */ -#ifndef MSG_DONTWAIT -#define MSG_DONTWAIT 0 -#endif -#ifndef SD_BOTH -#define SD_RECEIVE 0 -#define SD_SEND 1 -#define SD_BOTH 2 -#endif - -#if _MSC_VER -#define R_INVALID_SOCKET INVALID_SOCKET -#else -#define R_INVALID_SOCKET -1 -#endif - -typedef struct { - int child; -#if __WINDOWS__ - HANDLE pipe; -#else - int input[2]; - int output[2]; -#endif - RCoreBind coreb; -} R2Pipe; - -typedef struct r_socket_t { -#ifdef _MSC_VER - SOCKET fd; -#else - int fd; -#endif - bool is_ssl; - int proto; - int local; // TODO: merge ssl with local -> flags/options - int port; - struct sockaddr_in sa; -#if HAVE_LIB_SSL - SSL_CTX *ctx; - SSL *sfd; - BIO *bio; -#endif -} RSocket; - -typedef struct r_socket_http_options { - RList *authtokens; - bool accept_timeout; - int timeout; - bool httpauth; -} RSocketHTTPOptions; - -#define R_SOCKET_PROTO_TCP IPPROTO_TCP -#define R_SOCKET_PROTO_UDP IPPROTO_UDP -#define R_SOCKET_PROTO_UNIX 0x1337 -#define R_SOCKET_PROTO_NONE 0 -#define R_SOCKET_PROTO_DEFAULT R_SOCKET_PROTO_TCP - -#ifdef R_API -R_API RSocket *r_socket_new_from_fd(int fd); -R_API RSocket *r_socket_new(bool is_ssl); -R_API bool r_socket_spawn(RSocket *s, const char *cmd, unsigned int timeout); -R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int proto, unsigned int timeout); -R_API int r_socket_connect_serial(RSocket *sock, const char *path, int speed, int parity); -#define r_socket_connect_tcp(a, b, c, d) r_socket_connect (a, b, c, R_SOCKET_PROTO_TCP, d) -#define r_socket_connect_udp(a, b, c, d) r_socket_connect (a, b, c, R_SOCKET_PROTO_UDP, d) -#if __UNIX__ -#define r_socket_connect_unix(a, b) r_socket_connect (a, b, b, R_SOCKET_PROTO_UNIX, 0) -#else -#define r_socket_connect_unix(a, b) (false) -#endif -R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile); -R_API int r_socket_port_by_name(const char *name); -R_API int r_socket_close_fd(RSocket *s); -R_API int r_socket_close(RSocket *s); -R_API int r_socket_free(RSocket *s); -R_API RSocket *r_socket_accept(RSocket *s); -R_API RSocket *r_socket_accept_timeout(RSocket *s, unsigned int timeout); -R_API bool r_socket_block_time(RSocket *s, bool block, int sec, int usec); -R_API int r_socket_flush(RSocket *s); -R_API int r_socket_ready(RSocket *s, int secs, int usecs); -R_API char *r_socket_to_string(RSocket *s); -R_API int r_socket_write(RSocket *s, void *buf, int len); -R_API int r_socket_puts(RSocket *s, char *buf); -R_API void r_socket_printf(RSocket *s, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API int r_socket_read(RSocket *s, ut8 *read, int len); -R_API int r_socket_read_block(RSocket *s, unsigned char *buf, int len); -R_API int r_socket_gets(RSocket *s, char *buf, int size); -R_API ut8 *r_socket_slurp(RSocket *s, int *len); -R_API bool r_socket_is_connected(RSocket *); - -/* process */ -typedef struct r_socket_proc_t { - int fd0[2]; - int fd1[2]; - int pid; -} RSocketProc; - -R_API RSocketProc *r_socket_proc_open(char *const argv[]); -R_API int r_socket_proc_close(RSocketProc *sp); -R_API int r_socket_proc_read(RSocketProc *sp, unsigned char *buf, int len); -R_API int r_socket_proc_gets(RSocketProc *sp, char *buf, int size); -R_API int r_socket_proc_write(RSocketProc *sp, void *buf, int len); -R_API void r_socket_proc_printf(RSocketProc *sp, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API int r_socket_proc_ready(RSocketProc *sp, int secs, int usecs); - -/* HTTP */ -R_API char *r_socket_http_get(const char *url, int *code, int *rlen); -R_API char *r_socket_http_post(const char *url, const char *data, int *code, int *rlen); -R_API void r_socket_http_server_set_breaked(bool *b); - -typedef struct r_socket_http_request { - RSocket *s; - char *path; - char *host; - char *agent; - char *method; - char *referer; - ut8 *data; - int data_length; - bool auth; -} RSocketHTTPRequest; - -R_API RSocketHTTPRequest *r_socket_http_accept(RSocket *s, RSocketHTTPOptions *so); -R_API void r_socket_http_response(RSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers); -R_API void r_socket_http_close(RSocketHTTPRequest *rs); -R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *olen); - -typedef int (*rap_server_open)(void *user, const char *file, int flg, int mode); -typedef int (*rap_server_seek)(void *user, ut64 offset, int whence); -typedef int (*rap_server_read)(void *user, ut8 *buf, int len); -typedef int (*rap_server_write)(void *user, ut8 *buf, int len); -typedef char *(*rap_server_cmd)(void *user, const char *command); -typedef int (*rap_server_close)(void *user, int fd); - -enum { - RAP_PACKET_OPEN = 1, - RAP_PACKET_READ = 2, - RAP_PACKET_WRITE = 3, - RAP_PACKET_SEEK = 4, - RAP_PACKET_CLOSE = 5, - // system was deprecated in slot 6, - RAP_PACKET_CMD = 7, - RAP_PACKET_REPLY = 0x80, - RAP_PACKET_MAX = 4096 -}; - -typedef struct r_socket_rap_server_t { - RSocket *fd; - char *port; - ut8 buf[RAP_PACKET_MAX + 32]; // This should be used as a static buffer for everything done by the server - rap_server_open open; - rap_server_seek seek; - rap_server_read read; - rap_server_write write; - rap_server_cmd system; - rap_server_cmd cmd; - rap_server_close close; - void *user; // Always first arg for callbacks -} RSocketRapServer; - -R_API RSocketRapServer *r_socket_rap_server_new(bool is_ssl, const char *port); -R_API RSocketRapServer *r_socket_rap_server_create(const char *pathname); -R_API void r_socket_rap_server_free(RSocketRapServer *rap_s); -R_API bool r_socket_rap_server_listen(RSocketRapServer *rap_s, const char *certfile); -R_API RSocket *r_socket_rap_server_accept(RSocketRapServer *rap_s); -R_API bool r_socket_rap_server_continue(RSocketRapServer *rap_s); - -/* rap client */ -R_API int r_socket_rap_client_open(RSocket *s, const char *file, int rw); -R_API char *r_socket_rap_client_command(RSocket *s, const char *cmd, RCoreBind *c); -R_API int r_socket_rap_client_write(RSocket *s, const ut8 *buf, int count); -R_API int r_socket_rap_client_read(RSocket *s, ut8 *buf, int count); -R_API int r_socket_rap_client_seek(RSocket *s, ut64 offset, int whence); - -/* run.c */ -#define R_RUN_PROFILE_NARGS 512 -typedef struct r_run_profile_t { - char *_args[R_RUN_PROFILE_NARGS]; - int _argc; - bool _daemon; - char *_system; - char *_program; - char *_runlib; - char *_runlib_fcn; - char *_stdio; - char *_stdin; - char *_stdout; - char *_stderr; - char *_chgdir; - char *_chroot; - char *_libpath; - char *_preload; - int _bits; - int _pid; - char *_pidfile; - int _r2preload; - int _docore; - int _dofork; - int _dodebug; - int _aslr; - int _maxstack; - int _maxproc; - int _maxfd; - int _r2sleep; - int _execve; - char *_setuid; - char *_seteuid; - char *_setgid; - char *_setegid; - char *_input; - char *_connect; - char *_listen; - int _pty; - int _timeout; - int _timeout_sig; - int _nice; -} RRunProfile; - -R_API RRunProfile *r_run_new(const char *str); -R_API bool r_run_parse(RRunProfile *pf, const char *profile); -R_API void r_run_free(RRunProfile *r); -R_API bool r_run_parseline(RRunProfile *p, const char *b); -R_API const char *r_run_help(void); -R_API int r_run_config_env(RRunProfile *p); -R_API int r_run_start(RRunProfile *p); -R_API void r_run_reset(RRunProfile *p); -R_API bool r_run_parsefile(RRunProfile *p, const char *b); -R_API char *r_run_get_environ_profile(char **env); - -/* rapipe */ -R_API R2Pipe *rap_open(const char *cmd); -R_API R2Pipe *rap_open_corebind(RCoreBind *coreb); -R_API int rap_close(R2Pipe *rap); - -R_API char *rap_cmd(R2Pipe *rap, const char *str); -R_API char *rap_cmdf(R2Pipe *rap, const char *fmt, ...) R_PRINTF_CHECK(2, 3); - -R_API int rap_write(R2Pipe *rap, const char *str); -R_API char *rap_read(R2Pipe *rap); - -R_API int r2pipe_write(R2Pipe *r2pipe, const char *str); -R_API char *r2pipe_read(R2Pipe *r2pipe); -R_API int r2pipe_close(R2Pipe *r2pipe); -R_API R2Pipe *r2pipe_open_corebind(RCoreBind *coreb); -R_API R2Pipe *r2pipe_open(const char *cmd); -R_API R2Pipe *r2pipe_open_dl(const char *file); -R_API char *r2pipe_cmd(R2Pipe *r2pipe, const char *str); -R_API char *r2pipe_cmdf(R2Pipe *r2pipe, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_syscall.h b/libr/include/r_syscall.h deleted file mode 100644 index 48c5016873..0000000000 --- a/libr/include/r_syscall.h +++ /dev/null @@ -1,108 +0,0 @@ -/* radare - LGPL - Copyright 2009-2018 - pancake */ - -#ifndef R2_SYSCALL_H -#define R2_SYSCALL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -R_LIB_VERSION_HEADER (r_syscall); - -#define R_SYSCALL_ARGS 7 - -typedef struct r_syscall_item_t { - char *name; - int swi; - int num; - int args; - char *sargs; -} RSyscallItem; - -typedef struct r_syscall_port_t { - int port; - const char *name; -} RSyscallPort; - -typedef struct r_syscall_t { - FILE *fd; - // memoization - char *arch; - char *os; - int bits; - char *cpu; - // database - RSyscallItem *sysptr; - RSyscallPort *sysport; - Sdb *db; - Sdb *srdb; - int refs; -} RSyscall; - -#if 0 -// todo: add the ability to describe particular bits -typedef struct r_sysregs_item_t { - ut64 address; - ut64 size; - int type; - const char *name; - const char *description; -} RSysregsItem; - -typedef struct r_sysregs_t { - FILE *fd; - char *arch; - char *cpu; - RSysregsItem *sysregs; - Sdb *db; -} RSysregs; -#endif - -/* plugin struct */ -typedef struct r_syscall_plugin_t { - char *name; - char *arch; - char *os; - char *desc; - int bits; - int nargs; - struct r_syscall_args_t *args; -} RSyscallPlugin; - -typedef struct r_syscall_arch_plugin_t { - char *name; - char *arch; - char *desc; - int *bits; - int nargs; - struct r_syscall_args_t **args; -} RSyscallArchPlugin; - -#ifdef R_API -R_API RSyscallItem *r_syscall_item_new_from_string(const char *name, const char *s); -R_API void r_syscall_item_free(RSyscallItem *si); - -R_API RSyscall *r_syscall_new(void); -R_API void r_syscall_free(RSyscall *ctx); -R_API RSyscall* r_syscall_ref(RSyscall *sc); -R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char *cpu, const char *os); -R_API RSyscallItem *r_syscall_get(RSyscall *ctx, int num, int swi); -R_API int r_syscall_get_num(RSyscall *ctx, const char *str); -R_API const char *r_syscall_get_i(RSyscall *ctx, int num, int swi); -R_API const char* r_syscall_sysreg(RSyscall *s, const char *type, ut64 num); -R_API RList *r_syscall_list(RSyscall *ctx); -R_API int r_syscall_get_swi(RSyscall *s); - -/* io */ -R_API const char *r_syscall_get_io(RSyscall *s, int ioport); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_th.h b/libr/include/r_th.h deleted file mode 100644 index 8c18bb57c8..0000000000 --- a/libr/include/r_th.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef R2_TH_H -#define R2_TH_H - -#ifdef _GNU_SOURCE -#undef _GNU_SOURCE -#endif -#define _GNU_SOURCE -#include "r_types.h" - -#define HAVE_PTHREAD 1 - -#if __WINDOWS__ -#undef HAVE_PTHREAD -#define HAVE_PTHREAD 0 -#define R_TH_TID HANDLE -#define R_TH_LOCK_T CRITICAL_SECTION -#define R_TH_COND_T CONDITION_VARIABLE -#define R_TH_SEM_T HANDLE -//HANDLE - -#elif HAVE_PTHREAD -#define __GNU -#include -#include -#if __linux__ -#include -#endif -#if __linux__ && __GLIBC_MINOR < 12 -#define HAVE_PTHREAD_NP 0 -#else -#define HAVE_PTHREAD_NP 1 -#endif -#if __APPLE__ -#include -#endif -#if __FreeBSD__ || __OpenBSD__ || __DragonFly__ -#if __FreeBSD__ -#include -#endif -#include -#endif -#define R_TH_TID pthread_t -#define R_TH_LOCK_T pthread_mutex_t -#define R_TH_COND_T pthread_cond_t -#define R_TH_SEM_T sem_t * - -#else -#error Threading library only supported for pthread and w32 -#endif - -typedef enum { R_TH_FREED = -1, R_TH_STOP = 0, R_TH_REPEAT = 1 } RThreadFunctionRet; -#define R_TH_FUNCTION(x) RThreadFunctionRet (*x)(struct r_th_t *) - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_th_sem_t { - R_TH_SEM_T sem; -} RThreadSemaphore; - -typedef struct r_th_lock_t { - R_TH_LOCK_T lock; -} RThreadLock; - -typedef struct r_th_cond_t { - R_TH_COND_T cond; -} RThreadCond; - -typedef struct r_th_t { - R_TH_TID tid; - RThreadLock *lock; - R_TH_FUNCTION(fun); - void *user; // user pointer - int running; - int breaked; // thread aims to be interrupted - int delay; // delay the startup of the thread N seconds - int ready; // thread is properly setup -} RThread; - -typedef struct r_th_pool_t { - int size; - RThread **threads; -} RThreadPool; - -#ifdef R_API -R_API RThread *r_th_new(R_TH_FUNCTION(fun), void *user, int delay); -R_API bool r_th_start(RThread *th, int enable); -R_API int r_th_wait(RThread *th); -R_API int r_th_wait_async(RThread *th); -R_API void r_th_break(RThread *th); -R_API void *r_th_free(RThread *th); -R_API void *r_th_kill_free(RThread *th); -R_API bool r_th_kill(RThread *th, bool force); -R_API R_TH_TID r_th_self(void); -R_API bool r_th_setname(RThread *th, const char *name); -R_API bool r_th_getname(RThread *th, char *name, size_t len); -R_API bool r_th_setaffinity(RThread *th, int cpuid); - -R_API RThreadSemaphore *r_th_sem_new(unsigned int initial); -R_API void r_th_sem_free(RThreadSemaphore *sem); -R_API void r_th_sem_post(RThreadSemaphore *sem); -R_API void r_th_sem_wait(RThreadSemaphore *sem); - -R_API RThreadLock *r_th_lock_new(bool recursive); -R_API int r_th_lock_wait(RThreadLock *th); -R_API int r_th_lock_tryenter(RThreadLock *thl); -R_API int r_th_lock_enter(RThreadLock *thl); -R_API int r_th_lock_leave(RThreadLock *thl); -R_API void *r_th_lock_free(RThreadLock *thl); - -R_API RThreadCond *r_th_cond_new(void); -R_API void r_th_cond_signal(RThreadCond *cond); -R_API void r_th_cond_signal_all(RThreadCond *cond); -R_API void r_th_cond_wait(RThreadCond *cond, RThreadLock *lock); -R_API void r_th_cond_free(RThreadCond *cond); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util.h b/libr/include/r_util.h deleted file mode 100644 index cea140776d..0000000000 --- a/libr/include/r_util.h +++ /dev/null @@ -1,92 +0,0 @@ -/* radare - LGPL - Copyright 2008-2016 - pancake */ - -#ifndef R2_UTIL_H -#define R2_UTIL_H - -#include -#include -#include -#include -#include // radare linked list -#include // skiplist -#include // radare fixed pointer array iterators -#include -#include -#if !__WINDOWS__ -#include -#include -#endif -#ifdef HAVE_LIB_GMP -#include -#endif -#if HAVE_LIB_SSL -#include -#endif -#ifdef _MSC_VER -#include -int gettimeofday (struct timeval* p, void* tz); -#endif -#include "r_util/r_event.h" -#include "r_util/r_assert.h" -#include "r_util/r_itv.h" -#include "r_util/r_signal.h" -#include "r_util/r_alloc.h" -#include "r_util/r_rbtree.h" -#include "r_util/r_intervaltree.h" -#include "r_util/r_big.h" -#include "r_util/r_base64.h" -#include "r_util/r_base91.h" -#include "r_util/r_buf.h" -#include "r_util/r_bitmap.h" -#include "r_util/r_time.h" -#include "r_util/r_debruijn.h" -#include "r_util/r_cache.h" -#include "r_util/r_ctypes.h" -#include "r_util/r_file.h" -#include "r_util/r_hex.h" -#include "r_util/r_log.h" -#include "r_util/r_mem.h" -#include "r_util/r_name.h" -#include "r_util/r_num.h" -#include "r_util/r_table.h" -#include "r_util/r_graph.h" -#include "r_util/r_panels.h" -#include "r_util/r_pool.h" -#include "r_util/r_punycode.h" -#include "r_util/r_queue.h" -#include "r_util/r_range.h" -#include "r_util/r_sandbox.h" -#include "r_util/r_signal.h" -#include "r_util/r_spaces.h" -#include "r_util/r_stack.h" -#include "r_util/r_str.h" -#include "r_util/r_ascii_table.h" -#include "r_util/r_strbuf.h" -#include "r_util/r_strpool.h" -#include "r_util/r_str_constpool.h" -#include "r_util/r_sys.h" -#include "r_util/r_tree.h" -#include "r_util/r_uleb128.h" -#include "r_util/r_utf8.h" -#include "r_util/r_utf16.h" -#include "r_util/r_utf32.h" -#include "r_util/r_idpool.h" -#include "r_util/r_asn1.h" -#include "r_util/pj.h" -#include "r_util/r_x509.h" -#include "r_util/r_pkcs7.h" -#include "r_util/r_protobuf.h" -#include "r_util/r_big.h" -// requires io, core, ... #include "r_util/r_print.h" - -#ifdef __cplusplus -extern "C" { -#endif - -R_LIB_VERSION_HEADER(r_util); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util/pj.h b/libr/include/r_util/pj.h deleted file mode 100644 index 23d3db0213..0000000000 --- a/libr/include/r_util/pj.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef R_PJ_H -#define R_PJ_H 1 -#define R_PRINT_JSON_DEPTH_LIMIT 128 - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct pj_t { - RStrBuf sb; - bool is_first; - bool is_key; - char braces[R_PRINT_JSON_DEPTH_LIMIT]; - int level; -} PJ; - -/* lifecycle */ -R_API PJ *pj_new(void); -R_API void pj_free(PJ *j); -R_API void pj_reset(PJ *j); // clear the pj contents, but keep the buffer allocated to re-use it -R_API char *pj_drain(PJ *j); -R_API const char *pj_string(PJ *pj); -// R_API void pj_print(PJ *j, PrintfCallback cb); - -/* nesting */ -//R_API PJ *pj_begin(char type, PrintfCallback cb); -R_API PJ *pj_end(PJ *j); -R_API char *pj_fmt(PrintfCallback p, const char *fmt, ...); -/* object, array */ -R_API PJ *pj_o(PJ *j); -R_API PJ *pj_a(PJ *j); -/* keys, values */ -R_API PJ *pj_k(PJ *j, const char *k); -R_API PJ *pj_knull(PJ *j, const char *k); -R_API PJ *pj_kn(PJ *j, const char *k, ut64 n); -R_API PJ *pj_kN(PJ *j, const char *k, st64 n); -R_API PJ *pj_ks(PJ *j, const char *k, const char *v); -R_API PJ *pj_ka(PJ *j, const char *k); -R_API PJ *pj_ko(PJ *j, const char *k); -R_API PJ *pj_ki(PJ *j, const char *k, int d); -R_API PJ *pj_kd(PJ *j, const char *k, double d); -R_API PJ *pj_kf(PJ *j, const char *k, float d); -R_API PJ *pj_kb(PJ *j, const char *k, bool v); -R_API PJ *pj_null(PJ *j); -R_API PJ *pj_r(PJ *j, const unsigned char *v, size_t v_len); -R_API PJ *pj_kr(PJ *j, const char *k, const unsigned char *v, size_t v_len); -R_API PJ *pj_b(PJ *j, bool v); -R_API PJ *pj_s(PJ *j, const char *k); -R_API PJ *pj_n(PJ *j, ut64 n); -R_API PJ *pj_N(PJ *j, st64 n); -R_API PJ *pj_d(PJ *j, double d); -R_API PJ *pj_f(PJ *j, float d); -R_API PJ *pj_i(PJ *j, int d); -R_API PJ *pj_j(PJ *j, const char *k); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/libr/include/r_util/r_alloc.h b/libr/include/r_util/r_alloc.h deleted file mode 100644 index d71c1b913f..0000000000 --- a/libr/include/r_util/r_alloc.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef _R_UTIL_ALLOC_H_ -#define _R_UTIL_ALLOC_H_ 1 - -#include -#include -#include - -#define R_MALLOC_WRAPPER 0 -#define R_MALLOC_GLOBAL 0 - -typedef void *(RMalloc)(size_t); -typedef void *(RCalloc)(size_t, size_t); -typedef void *(RRealloc)(void *, size_t); -typedef void (RFree)(void *); - -R_API void* r_malloc_aligned(size_t size, size_t alignment); -R_API void r_free_aligned(void *p); - -#if R_MALLOC_WRAPPER - -R_API void r_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f); - -#if R_MALLOC_GLOBAL -R_API RMalloc *r_malloc; -R_API RCalloc *r_calloc; -R_API RRealloc *r_realloc; -R_API RFree *r_free; -#define _r_malloc r_malloc -#define _r_calloc r_calloc -#define _r_free r_free -#define _r_realloc r_realloc -#else -R_API void *r_malloc(size_t sz); -R_API void *r_calloc(size_t count, size_t sz); -R_API void *r_realloc(void *p, size_t sz); -R_API void r_free(void *p); -#endif - -#else - -#define r_malloc(x) malloc((x)) -#define r_calloc(x,y) calloc((x),(y)) -#define r_realloc(x,y) realloc((x),(y)) -#define r_free(x) free((x)) - -#define _r_malloc r_malloc -#define _r_calloc r_calloc -#define _r_free r_free -#define _r_realloc r_realloc - -#endif - -#endif diff --git a/libr/include/r_util/r_base64.h b/libr/include/r_util/r_base64.h deleted file mode 100644 index eca2037b1e..0000000000 --- a/libr/include/r_util/r_base64.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef R_BASE64_H -#define R_BASE64_H - -#ifdef __cplusplus -extern "C" { -#endif - -R_API int r_base64_encode(char *bout, const ut8 *bin, int len); -R_API int r_base64_decode(ut8 *bout, const char *bin, int len); -R_API ut8 *r_base64_decode_dyn(const char *in, int len); -R_API char *r_base64_encode_dyn(const char *str, int len); -#ifdef __cplusplus -} -#endif - -#endif // R_BASE64_H diff --git a/libr/include/r_util/r_base91.h b/libr/include/r_util/r_base91.h deleted file mode 100644 index 940bcc9459..0000000000 --- a/libr/include/r_util/r_base91.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef R_BASE91_H -#define R_BASE91_H - -#ifdef __cplusplus -extern "C" { -#endif - -R_API int r_base91_encode(char *bout, const ut8 *bin, int len); -R_API int r_base91_decode(ut8 *bout, const char *bin, int len); - -#ifdef __cplusplus -} -#endif - -#endif // R_BASE91_H diff --git a/libr/include/r_util/r_big.h b/libr/include/r_util/r_big.h deleted file mode 100644 index 1e8ff78586..0000000000 --- a/libr/include/r_util/r_big.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef R_BIG_H -#define R_BIG_H - -#include "../r_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#if HAVE_LIB_GMP -/* Use GMP's data struct */ -#define RNumBig mpz_t -#elif HAVE_LIB_SSL -#define RNumBig BIGNUM -#else -/* Use default impl */ -#define R_BIG_WORD_SIZE 4 -/* Let's support 4096-bit big number */ -#define R_BIG_ARRAY_SIZE (512 / R_BIG_WORD_SIZE) -/* R_BIG_WORD_SIZE == 4, 32 bits long */ -#define R_BIG_DTYPE ut32 -#define R_BIG_DTYPE_TMP ut64 -#define R_BIG_SPRINTF_FORMAT_STR "%.08x" -#define R_BIG_FORMAT_STR_LEN 9 -#define R_BIG_SSCANF_FORMAT_STR "%8x" -#define R_BIG_MAX_VAL (R_BIG_DTYPE_TMP) UT32_MAX - -typedef struct r_num_big_t { - R_BIG_DTYPE array[R_BIG_ARRAY_SIZE]; - int sign; -} RNumBig; -#endif - -R_API RNumBig *r_big_new(void); -R_API void r_big_free(RNumBig *b); -R_API void r_big_init(RNumBig *b); -R_API void r_big_fini(RNumBig *b); - -/* Assignment operations */ -R_API void r_big_from_int(RNumBig *b, st64 v); -R_API st64 r_big_to_int(RNumBig *b); -R_API void r_big_from_hexstr(RNumBig *b, const char *str); -R_API char *r_big_to_hexstr(RNumBig *b); -R_API void r_big_assign(RNumBig *dst, RNumBig *src); - -/* Basic arithmetic operations */ -R_API void r_big_add(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a + b */ -R_API void r_big_sub(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a - b */ -R_API void r_big_mul(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a * b */ -R_API void r_big_div(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a / b */ -R_API void r_big_mod(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a % b */ -R_API void r_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b); /* c = a/b, d = a%b */ - -/* Bitwise operations(for >= 0) */ -R_API void r_big_and(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a & b */ -R_API void r_big_or(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a | b */ -R_API void r_big_xor(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a ^ b */ -R_API void r_big_lshift(RNumBig *c, RNumBig *a, size_t nbits); /* c = a << nbits */ -R_API void r_big_rshift(RNumBig *c, RNumBig *a, size_t nbits); /* c = a >> nbits */ - -/* Special operators and comparison */ -R_API int r_big_cmp(RNumBig *a, RNumBig *b); /* Return 1 if a>b, -1 if a 1024 */ -R_API void r_big_isqrt(RNumBig *c, RNumBig *a); /* Integer square root -- e.g. isqrt(5) => 2*/ - -#ifdef __cplusplus -} -#endif - -#endif // R_BIG_H diff --git a/libr/include/r_util/r_bitmap.h b/libr/include/r_util/r_bitmap.h deleted file mode 100644 index d926698837..0000000000 --- a/libr/include/r_util/r_bitmap.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef R_BITMAP_H -#define R_BITMAP_H - -#if R_SYS_BITS == 4 -#define BITWORD_BITS_SHIFT 5 -#define RBitword ut32 -#else -#define BITWORD_BITS_SHIFT 6 -#define RBitword ut64 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_bitmap_t { - int length; - RBitword *bitmap; -} RBitmap; - -R_API RBitmap *r_bitmap_new(size_t len); -R_API void r_bitmap_set_bytes(RBitmap *b, const ut8 *buf, int len); -R_API void r_bitmap_free(RBitmap *b); -R_API void r_bitmap_set(RBitmap *b, size_t bit); -R_API void r_bitmap_unset(RBitmap *b, size_t bit); -R_API int r_bitmap_test(RBitmap *b, size_t bit); - -#ifdef __cplusplus -} -#endif - -#endif // R_BITMAP_H diff --git a/libr/include/r_util/r_buf.h b/libr/include/r_util/r_buf.h deleted file mode 100644 index fce6fe43e2..0000000000 --- a/libr/include/r_util/r_buf.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef R_BUF_H -#define R_BUF_H -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// TODO: choose whether the _at operations should preserve the current seek or not - -#define R_BUF_SET 0 -#define R_BUF_CUR 1 -#define R_BUF_END 2 - -typedef struct r_buf_t RBuffer; - -typedef bool (*RBufferInit)(RBuffer *b, const void *user); -typedef bool (*RBufferFini)(RBuffer *b); -typedef st64 (*RBufferRead)(RBuffer *b, ut8 *buf, ut64 len); -typedef st64 (*RBufferWrite)(RBuffer *b, const ut8 *buf, ut64 len); -typedef ut64 (*RBufferGetSize)(RBuffer *b); -typedef bool (*RBufferResize)(RBuffer *b, ut64 newsize); -typedef st64 (*RBufferSeek)(RBuffer *b, st64 addr, int whence); -typedef ut8 *(*RBufferGetWholeBuf)(RBuffer *b, ut64 *sz); -typedef void (*RBufferFreeWholeBuf)(RBuffer *b); -typedef RList *(*RBufferNonEmptyList)(RBuffer *b); - -typedef struct r_buffer_methods_t { - RBufferInit init; - RBufferFini fini; - RBufferRead read; - RBufferWrite write; - RBufferGetSize get_size; - RBufferResize resize; - RBufferSeek seek; - RBufferGetWholeBuf get_whole_buf; - RBufferFreeWholeBuf free_whole_buf; - RBufferNonEmptyList nonempty_list; -} RBufferMethods; - -struct r_buf_t { - const RBufferMethods *methods; - void *priv; - ut8 *whole_buf; - bool readonly; - int Oxff_priv; - int refctr; -}; - -// XXX: this should not be public -typedef struct r_buf_cache_t { - ut64 from; - ut64 to; - int size; - ut8 *data; - int written; -} RBufferSparse; - -/* constructors */ -R_API RBuffer *r_buf_new(void); -R_API RBuffer *r_buf_new_with_io(void *iob, int fd); -R_API RBuffer *r_buf_new_with_bytes(const ut8* bytes, ut64 len); -R_API RBuffer *r_buf_new_with_string(const char *msg); -R_API RBuffer *r_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal); -R_API RBuffer *r_buf_new_file(const char *file, int perm, int mode); -R_API RBuffer *r_buf_new_with_buf(RBuffer *b); -R_API RBuffer *r_buf_new_slurp(const char *file); -R_API RBuffer *r_buf_new_slice(RBuffer *b, ut64 offset, ut64 size); -R_API RBuffer *r_buf_new_empty(ut64 len); -R_API RBuffer *r_buf_new_mmap(const char *file, int flags); -R_API RBuffer *r_buf_new_sparse(ut8 Oxff); - -/* methods */ -R_API bool r_buf_dump(RBuffer *buf, const char *file); -R_API bool r_buf_set_bytes(RBuffer *b, const ut8 *buf, ut64 length); -R_API st64 r_buf_append_string(RBuffer *b, const char *str); -R_API bool r_buf_append_buf(RBuffer *b, RBuffer *a); -R_API bool r_buf_append_bytes(RBuffer *b, const ut8 *buf, ut64 length); -R_API bool r_buf_append_nbytes(RBuffer *b, ut64 length); -R_API bool r_buf_append_ut16(RBuffer *b, ut16 n); -R_API bool r_buf_append_buf_slice(RBuffer *b, RBuffer *a, ut64 offset, ut64 size); -R_API bool r_buf_append_ut32(RBuffer *b, ut32 n); -R_API bool r_buf_append_ut64(RBuffer *b, ut64 n); -R_API bool r_buf_prepend_bytes(RBuffer *b, const ut8 *buf, ut64 length); -R_API st64 r_buf_insert_bytes(RBuffer *b, ut64 addr, const ut8 *buf, ut64 length); -R_API char *r_buf_to_string(RBuffer *b); -R_API char *r_buf_get_string(RBuffer *b, ut64 addr); -R_API st64 r_buf_read(RBuffer *b, ut8 *buf, ut64 len); -R_API ut8 r_buf_read8(RBuffer *b); -R_API st64 r_buf_fread(RBuffer *b, ut8 *buf, const char *fmt, int n); -R_API st64 r_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len); -R_API ut8 r_buf_read8_at(RBuffer *b, ut64 addr); -R_API ut64 r_buf_tell(RBuffer *b); -R_API st64 r_buf_seek(RBuffer *b, st64 addr, int whence); -R_API st64 r_buf_fread_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n); -R_API st64 r_buf_write(RBuffer *b, const ut8 *buf, ut64 len); -R_API st64 r_buf_fwrite(RBuffer *b, const ut8 *buf, const char *fmt, int n); -R_API st64 r_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, ut64 len); -R_API st64 r_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fmt, int n); -// WARNING: this function should be used with care because it may allocate the -// entire buffer in memory. Consider using the r_buf_read* APIs instead and read -// only the chunks you need. -R_DEPRECATE R_API const ut8 *r_buf_data(RBuffer *b, ut64 *size); -R_API ut64 r_buf_size(RBuffer *b); -R_API bool r_buf_resize(RBuffer *b, ut64 newsize); -R_API RBuffer *r_buf_ref(RBuffer *b); -R_API void r_buf_free(RBuffer *b); -R_API bool r_buf_fini(RBuffer *b); -R_API RList *r_buf_nonempty_list(RBuffer *b); - -static inline ut16 r_buf_read_be16(RBuffer *b) { - ut8 buf[sizeof (ut16)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be16 (buf): UT16_MAX; -} - -static inline ut16 r_buf_read_be16_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut16)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be16 (buf): UT16_MAX; -} - -static inline ut32 r_buf_read_be32(RBuffer *b) { - ut8 buf[sizeof (ut32)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be32 (buf): UT32_MAX; -} - -static inline ut32 r_buf_read_be32_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut32)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be32 (buf): UT32_MAX; -} - -static inline ut64 r_buf_read_be64(RBuffer *b) { - ut8 buf[sizeof (ut64)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be64 (buf): UT64_MAX; -} - -static inline ut64 r_buf_read_be64_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut64)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_be64 (buf): UT64_MAX; -} - -static inline ut16 r_buf_read_le16(RBuffer *b) { - ut8 buf[sizeof (ut16)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le16 (buf): UT16_MAX; -} - -static inline ut16 r_buf_read_le16_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut16)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le16 (buf): UT16_MAX; -} - -static inline ut32 r_buf_read_le32(RBuffer *b) { - ut8 buf[sizeof (ut32)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le32 (buf): UT32_MAX; -} - -static inline ut32 r_buf_read_le32_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut32)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le32 (buf): UT32_MAX; -} - -static inline ut64 r_buf_read_le64(RBuffer *b) { - ut8 buf[sizeof (ut64)]; - int r = (int) r_buf_read (b, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le64 (buf): UT64_MAX; -} - -static inline ut64 r_buf_read_le64_at(RBuffer *b, ut64 addr) { - ut8 buf[sizeof (ut64)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_le64 (buf): UT64_MAX; -} - -static inline ut16 r_buf_read_ble16_at(RBuffer *b, ut64 addr, bool big_endian) { - ut8 buf[sizeof (ut16)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_ble16 (buf, big_endian): UT16_MAX; -} - -static inline ut32 r_buf_read_ble32_at(RBuffer *b, ut64 addr, bool big_endian) { - ut8 buf[sizeof (ut32)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_ble32 (buf, big_endian): UT32_MAX; -} - -static inline ut64 r_buf_read_ble64_at(RBuffer *b, ut64 addr, bool big_endian) { - ut8 buf[sizeof (ut64)]; - int r = (int) r_buf_read_at (b, addr, buf, sizeof (buf)); - return r == sizeof (buf)? r_read_ble64 (buf, big_endian): UT64_MAX; -} - -R_API st64 r_buf_uleb128(RBuffer *b, ut64 *v); -R_API st64 r_buf_sleb128(RBuffer *b, st64 *v); - -static inline st64 r_buf_uleb128_at(RBuffer *b, ut64 addr, ut64 *v) { - r_buf_seek (b, addr, R_BUF_SET); - return r_buf_uleb128 (b, v); -} -static inline st64 r_buf_sleb128_at(RBuffer *b, ut64 addr, st64 *v) { - r_buf_seek (b, addr, R_BUF_SET); - return r_buf_sleb128 (b, v); -} - -#ifdef __cplusplus -} -#endif - -#endif // R_BUF_H diff --git a/libr/include/r_util/r_cache.h b/libr/include/r_util/r_cache.h deleted file mode 100644 index 3cb69daa0a..0000000000 --- a/libr/include/r_util/r_cache.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef R_CACHE_H -#define R_CACHE_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_cache_t { - ut64 base; - ut8 *buf; - ut64 len; -} RCache; - -typedef struct r_prof_t { - struct timeval begin; - double result; -} RProfile; - -R_API RCache* r_cache_new(void); -R_API void r_cache_free(RCache *c); -R_API const ut8* r_cache_get(RCache *c, ut64 addr, int *len); -R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len); -R_API void r_cache_flush(RCache *c); -R_API void r_prof_start(RProfile *p); -R_API double r_prof_end(RProfile *p); - -#ifdef __cplusplus -} -#endif -#endif // R_CACHE_H diff --git a/libr/include/r_util/r_ctypes.h b/libr/include/r_util/r_ctypes.h deleted file mode 100644 index ab72f5c2f7..0000000000 --- a/libr/include/r_util/r_ctypes.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef R_CTYPES_H -#define R_CTYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_type_enum { - const char *name; - const char *val; -}RTypeEnum; - -enum RTypeKind { - R_TYPE_BASIC = 0, - R_TYPE_ENUM = 1, - R_TYPE_STRUCT = 2, - R_TYPE_UNION = 3, - R_TYPE_TYPEDEF = 4 -}; - -R_API int r_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val); -R_API void r_type_del(Sdb *TDB, const char *name); -R_API int r_type_kind(Sdb *TDB, const char *name); -R_API char *r_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val); -R_API char *r_type_enum_getbitfield(Sdb *TDB, const char *name, ut64 val); -R_API RList* r_type_get_enum (Sdb *TDB, const char *name); -R_API ut64 r_type_get_bitsize (Sdb *TDB, const char *type); -R_API RList* r_type_get_by_offset(Sdb *TDB, ut64 offset); -R_API char *r_type_get_struct_memb(Sdb *TDB, const char *type, int offset); -R_API char *r_type_link_at (Sdb *TDB, ut64 addr); -R_API int r_type_set_link (Sdb *TDB, const char *val, ut64 addr); -R_API int r_type_unlink(Sdb *TDB, ut64 addr); -R_API int r_type_link_offset (Sdb *TDB, const char *val, ut64 addr); -R_API char *r_type_format(Sdb *TDB, const char *t); - -// Function prototypes api -R_API int r_type_func_exist(Sdb *TDB, const char *func_name); -R_API const char *r_type_func_cc(Sdb *TDB, const char *func_name); -R_API const char *r_type_func_ret(Sdb *TDB, const char *func_name); -R_API int r_type_func_args_count(Sdb *TDB, R_NONNULL const char *func_name); -R_API R_OWN char *r_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i); -R_API const char *r_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i); -R_API R_OWN char *r_type_func_guess(Sdb *TDB, R_NONNULL char *func_name); - -#ifdef __cplusplus -} -#endif - -#endif // R_CTYPES_H - diff --git a/libr/include/r_util/r_file.h b/libr/include/r_util/r_file.h deleted file mode 100644 index a230c55670..0000000000 --- a/libr/include/r_util/r_file.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef R_FILE_H -#define R_FILE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* is */ -R_API bool r_file_is_abspath(const char *file); -R_API bool r_file_is_c(const char *file); -R_API bool r_file_is_directory(const char *str); -R_API bool r_file_is_regular(const char *str); - -R_API bool r_file_truncate(const char *filename, ut64 newsize); -R_API ut64 r_file_size(const char *str); -R_API char *r_file_root(const char *root, const char *path); -R_API RMmap *r_file_mmap(const char *file, bool rw, ut64 base); -R_API int r_file_mmap_read(const char *file, ut64 addr, ut8 *buf, int len); -R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len); -R_API void r_file_mmap_free(RMmap *m); -R_API bool r_file_chmod(const char *file, const char *mod, int recursive); -R_API char *r_file_temp(const char *prefix); -R_API char *r_file_path(const char *bin); -R_API const char *r_file_basename(const char *path); -R_API char *r_file_dirname(const char *path); -R_API char *r_file_abspath_rel(const char *cwd, const char *file); -R_API char *r_file_abspath(const char *file); -R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen); -R_API ut8 *r_file_gzslurp(const char *str, int *outlen, int origonfail); -R_API char *r_stdin_slurp(int *sz); -R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz); -//R_API char *r_file_slurp_range(const char *str, ut64 off, ut64 sz); -R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz); -R_API char *r_file_slurp_random_line(const char *file); -R_API char *r_file_slurp_random_line_count(const char *file, int *linecount); -R_API ut8 *r_file_slurp_hexpairs(const char *str, int *usz); -R_API bool r_file_dump(const char *file, const ut8 *buf, int len, bool append); -R_API bool r_file_touch(const char *file); -R_API bool r_file_hexdump(const char *file, const ut8 *buf, int len, int append); -R_API bool r_file_rm(const char *file); -R_API bool r_file_exists(const char *str); -R_API bool r_file_fexists(const char *fmt, ...); -R_API char *r_file_slurp_line(const char *file, int line, int context); -R_API char *r_file_slurp_lines(const char *file, int line, int count); -R_API char *r_file_slurp_lines_from_bottom(const char *file, int line); -R_API int r_file_mkstemp(const char *prefix, char **oname); -R_API char *r_file_tmpdir(void); -R_API char *r_file_readlink(const char *path); -R_API bool r_file_copy (const char *src, const char *dst); -R_API RList* r_file_globsearch (const char *globbed_path, int maxdepth); -R_API RMmap *r_file_mmap_arch (RMmap *map, const char *filename, int fd); - -#ifdef __cplusplus -} -#endif - -#endif // R_FILE_H diff --git a/libr/include/r_util/r_graph.h b/libr/include/r_util/r_graph.h deleted file mode 100644 index 45cadd9600..0000000000 --- a/libr/include/r_util/r_graph.h +++ /dev/null @@ -1,83 +0,0 @@ -#ifndef R_GRAPH_H -#define R_GRAPH_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Generic graph node info - */ -typedef struct r_anal_graph_node_info_t { - char *title; - char *body; - ut64 offset; -} RGraphNodeInfo; - -typedef struct r_graph_node_t { - unsigned int idx; - void *data; - RList *out_nodes; - RList *in_nodes; - RList *all_neighbours; - RListFree free; -} RGraphNode; - -typedef struct r_graph_edge_t { - RGraphNode *from; - RGraphNode *to; - int nth; -} RGraphEdge; - -typedef struct r_graph_t { - unsigned int n_nodes; - unsigned int n_edges; - int last_index; - RList *nodes; /* RGraphNode */ -} RGraph; - -typedef struct r_graph_visitor_t { - void (*discover_node)(RGraphNode *n, struct r_graph_visitor_t *vis); - void (*finish_node)(RGraphNode *n, struct r_graph_visitor_t *vis); - void (*tree_edge)(const RGraphEdge *e, struct r_graph_visitor_t *vis); - void (*back_edge)(const RGraphEdge *e, struct r_graph_visitor_t *vis); - void (*fcross_edge)(const RGraphEdge *e, struct r_graph_visitor_t *vis); - void *data; -} RGraphVisitor; -typedef void (*RGraphNodeCallback)(RGraphNode *n, RGraphVisitor *vis); -typedef void (*RGraphEdgeCallback)(const RGraphEdge *e, RGraphVisitor *vis); - -// Contrructs a new RGraph, returns heap-allocated graph. -R_API RGraph *r_graph_new(void); -// Destroys the graph and all nodes. -R_API void r_graph_free(RGraph* g); -// Gets the data of a node by index. -R_API RGraphNode *r_graph_get_node(const RGraph *g, unsigned int idx); -R_API RListIter *r_graph_node_iter(const RGraph *g, unsigned int idx); -R_API void r_graph_reset(RGraph *g); -R_API RGraphNode *r_graph_add_node(RGraph *g, void *data); -// XXX 'n' is destroyed after calling this function. -R_API void r_graph_del_node(RGraph *g, RGraphNode *n); -R_API void r_graph_add_edge(RGraph *g, RGraphNode *from, RGraphNode *to); -R_API void r_graph_add_edge_at(RGraph *g, RGraphNode *from, RGraphNode *to, int nth); -R_API RGraphNode *r_graph_node_split_forward(RGraph *g, RGraphNode *split_me, void *data); -R_API void r_graph_del_edge(RGraph *g, RGraphNode *from, RGraphNode *to); -R_API const RList *r_graph_get_neighbours(const RGraph *g, const RGraphNode *n); -R_API RGraphNode *r_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, int nth); -R_API const RList *r_graph_innodes(const RGraph *g, const RGraphNode *n); -R_API const RList *r_graph_all_neighbours(const RGraph *g, const RGraphNode *n); -R_API const RList *r_graph_get_nodes(const RGraph *g); -R_API bool r_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to); -R_API void r_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis); -R_API void r_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis); -R_API void r_graph_dfs(RGraph *g, RGraphVisitor *vis); -R_API void r_graph_free_node_info(void *ptr); -R_API RGraphNodeInfo *r_graph_create_node_info(char *title, char *body, ut64 offset); - -#ifdef __cplusplus -} -#endif - -#endif // R_GRAPH_H diff --git a/libr/include/r_util/r_hex.h b/libr/include/r_util/r_hex.h deleted file mode 100644 index 892e6d08ff..0000000000 --- a/libr/include/r_util/r_hex.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef R_HEX_H -#define R_HEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -R_API int r_hex_pair2bin(const char *arg); -R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask); -R_API int r_hex_str2bin(const char *in, ut8 *out); -R_API int r_hex_bin2str(const ut8 *in, int len, char *out); -R_API char *r_hex_bin2strdup(const ut8 *in, int len); -R_API bool r_hex_to_byte(ut8 *val, ut8 c); -R_API int r_hex_str_is_valid(const char *s); -R_API st64 r_hex_bin_truncate(ut64 in, int n); -R_API char *r_hex_from_c(const char *code); -R_API char *r_hex_from_py(const char *code); -R_API char *r_hex_from_code(const char *code); -R_API char *r_hex_no_code(const char *code); -R_API char *r_hex_from_py_str(char *out, const char *code); -R_API char *r_hex_from_py_array(char *out, const char *code); -R_API char *r_hex_from_c_str(char *out, const char **code); -R_API char *r_hex_from_c_array(char *out, const char *code); -#ifdef __cplusplus -} -#endif - -#endif // R_HEX_H diff --git a/libr/include/r_util/r_idpool.h b/libr/include/r_util/r_idpool.h deleted file mode 100644 index 3d9662bca0..0000000000 --- a/libr/include/r_util/r_idpool.h +++ /dev/null @@ -1,79 +0,0 @@ -/* radare2 - LGPL - Copyright 2017-2018 - condret */ - -#ifndef R_ID_STORAGE_H -#define R_ID_STORAGE_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_id_pool_t { - ut32 start_id; - ut32 last_id; - ut32 next_id; - RQueue *freed_ids; -} RIDPool; - -R_API RIDPool *r_id_pool_new(ut32 start_id, ut32 last_id); -R_API bool r_id_pool_grab_id(RIDPool *pool, ut32 *grabber); -R_API bool r_id_pool_kick_id(RIDPool *pool, ut32 kick); -R_API void r_id_pool_free(RIDPool *pool); - -typedef struct r_id_storage_t { - RIDPool *pool; - void **data; - ut32 top_id; - ut32 size; -} RIDStorage; - -typedef bool (*RIDStorageForeachCb)(void *user, void *data, ut32 id); -typedef bool (*ROIDStorageCompareCb)(void *in, void *incoming, void *user, int *cmp_res); - -R_API RIDStorage *r_id_storage_new(ut32 start_id, ut32 last_id); -R_API bool r_id_storage_set(RIDStorage *storage, void *data, ut32 id); -R_API bool r_id_storage_add(RIDStorage *storage, void *data, ut32 *id); -R_API void *r_id_storage_get(RIDStorage *storage, ut32 id); -R_API void r_id_storage_delete(RIDStorage *storage, ut32 id); -R_API void *r_id_storage_take(RIDStorage *storage, ut32 id); -R_API bool r_id_storage_foreach(RIDStorage *storage, RIDStorageForeachCb cb, void *user); -R_API void r_id_storage_free(RIDStorage *storage); -R_API RList *r_id_storage_list(RIDStorage *s); - -typedef struct r_ordered_id_storage_t { - ut32 *permutation; - ut32 psize; - ut32 ptop; - RIDStorage *data; - ROIDStorageCompareCb cmp; -} ROIDStorage; - -R_API ROIDStorage *r_oids_new(ut32 start_id, ut32 last_id); -R_API void *r_oids_get(ROIDStorage *storage, ut32 id); -R_API void *r_oids_oget(ROIDStorage *storage, ut32 od); -R_API bool r_oids_get_id(ROIDStorage *storage, ut32 od, ut32 *id); -R_API bool r_oids_get_od(ROIDStorage *storage, ut32 id, ut32 *od); -R_API bool r_oids_to_front(ROIDStorage *storage, const ut32 id); -R_API bool r_oids_to_rear(ROIDStorage *storage, const ut32 id); -R_API void r_oids_delete(ROIDStorage *storage, ut32 id); -R_API void r_oids_odelete(ROIDStorage *st, ut32 od); -R_API void r_oids_free(ROIDStorage *storage); -R_API bool r_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od); -R_API void *r_oids_take(ROIDStorage *storage, ut32 id); -R_API void *r_oids_otake(ROIDStorage *st, ut32 od); -R_API bool r_oids_foreach(ROIDStorage* storage, RIDStorageForeachCb cb, void* user); -R_API bool r_oids_foreach_prev(ROIDStorage* storage, RIDStorageForeachCb cb, void* user); -R_API bool r_oids_insert(ROIDStorage *storage, void *data, ut32 *id, ut32 *od, void *user); -R_API bool r_oids_sort(ROIDStorage *storage, void *user); -R_API ut32 r_oids_find (ROIDStorage *storage, void *incoming, void *user); -R_API void *r_oids_last(ROIDStorage *storage); -R_API void *r_oids_first(ROIDStorage *storage); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util/r_mem.h b/libr/include/r_util/r_mem.h deleted file mode 100644 index 1c3a045f1b..0000000000 --- a/libr/include/r_util/r_mem.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef R_MEM_H -#define R_MEM_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_mmap_t { - ut8 *buf; - ut64 base; - int len; - int fd; - int rw; - char *filename; -#if __WINDOWS__ - HANDLE fh; - HANDLE fm; -#endif -} RMmap; - -typedef struct r_mem_pool_t { - ut8 **nodes; - int ncount; - int npool; - // - int nodesize; - int poolsize; - int poolcount; -} RMemoryPool; - -R_API ut64 r_mem_get_num(const ut8 *b, int size); - -/* MEMORY POOL */ -R_API RMemoryPool* r_mem_pool_deinit(RMemoryPool *pool); -R_API RMemoryPool *r_mem_pool_new(int nodesize, int poolsize, int poolcount); -R_API RMemoryPool *r_mem_pool_free(RMemoryPool *pool); -R_API void* r_mem_pool_alloc(RMemoryPool *pool); -R_API void *r_mem_dup(const void *s, int l); -R_API void *r_mem_alloc(int sz); -R_API void r_mem_free(void *); -R_API void r_mem_memzero(void *, size_t); -R_API void r_mem_reverse(ut8 *b, int l); -R_API int r_mem_protect(void *ptr, int size, const char *prot); -R_API int r_mem_set_num(ut8 *dest, int dest_size, ut64 num); -R_API int r_mem_eq(ut8 *a, ut8 *b, int len); -R_API void r_mem_copybits(ut8 *dst, const ut8 *src, int bits); -R_API void r_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits); -R_API void r_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize); -R_API void r_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian); -R_API void r_mem_swapendian(ut8 *dest, const ut8 *orig, int size); -R_API int r_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len); -R_API const ut8 *r_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int nlen); -R_API const ut8 *r_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align); -R_API int r_mem_count(const ut8 **addr); -R_API bool r_mem_is_printable (const ut8 *a, int la); -R_API bool r_mem_is_zero(const ut8 *b, int l); -R_API void *r_mem_mmap_resize(RMmap *m, ut64 newsize); - -#ifdef __cplusplus -} -#endif -#endif // R_MEM_H diff --git a/libr/include/r_util/r_name.h b/libr/include/r_util/r_name.h deleted file mode 100644 index bdb2c79198..0000000000 --- a/libr/include/r_util/r_name.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef R_NAME_H -#define R_NAME_H - -#ifdef __cplusplus -extern "C" { -#endif - -R_API bool r_name_check(const char *name); -R_API bool r_name_filter(char *name, int len); -R_API char *r_name_filter2(const char *name); -R_API bool r_name_validate_char(const char ch); - -#ifdef __cplusplus -} -#endif - -#endif // R_NAME_H diff --git a/libr/include/r_util/r_num.h b/libr/include/r_util/r_num.h deleted file mode 100644 index eab6c012c2..0000000000 --- a/libr/include/r_util/r_num.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef R_NUM_H -#define R_NUM_H - -#define R_NUMCALC_STRSZ 1024 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - double d; - ut64 n; -} RNumCalcValue; - -typedef enum { - RNCNAME, RNCNUMBER, RNCEND, RNCINC, RNCDEC, - RNCPLUS='+', RNCMINUS='-', RNCMUL='*', RNCDIV='/', RNCMOD='%', - //RNCXOR='^', RNCOR='|', RNCAND='&', - RNCNEG='~', RNCAND='&', RNCORR='|', RNCXOR='^', - RNCPRINT=';', RNCASSIGN='=', RNCLEFTP='(', RNCRIGHTP=')', - RNCSHL='<', RNCSHR = '>', RNCROL = '#', RNCROR = '$' -} RNumCalcToken; - -typedef struct r_num_calc_t { - RNumCalcToken curr_tok; - RNumCalcValue number_value; - char string_value[R_NUMCALC_STRSZ]; - int errors; - char oc; - const char *calc_err; - int calc_i; - const char *calc_buf; - int calc_len; - bool under_calc; -} RNumCalc; - -typedef struct r_num_t { - ut64 (*callback)(struct r_num_t *userptr, const char *str, int *ok); - const char *(*cb_from_value)(struct r_num_t *userptr, ut64 value, int *ok); -// RNumCallback callback; - ut64 value; - double fvalue; - void *userptr; - int dbz; /// division by zero happened - RNumCalc nc; -} RNum; - -typedef ut64 (*RNumCallback)(struct r_num_t *self, const char *str, int *ok); -typedef const char *(*RNumCallback2)(struct r_num_t *self, ut64, int *ok); - -R_API RNum *r_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr); -R_API void r_num_free(RNum *num); -R_API char *r_num_units(char *buf, size_t len, ut64 number); -R_API int r_num_conditional(RNum *num, const char *str); -R_API ut64 r_num_calc(RNum *num, const char *str, const char **err); -R_API const char *r_num_calc_index(RNum *num, const char *p); -R_API ut64 r_num_chs(int cylinder, int head, int sector, int sectorsize); -R_API int r_num_is_valid_input(RNum *num, const char *input_value); -R_API ut64 r_num_get_input_value(RNum *num, const char *input_value); -R_API const char *r_num_get_name(RNum *num, ut64 n); -R_API char* r_num_as_string(RNum *___, ut64 n, bool printable_only); -R_API ut64 r_num_tail(RNum *num, ut64 addr, const char *hex); -R_API ut64 r_num_tail_base(RNum *num, ut64 addr, ut64 off); -R_API void r_num_minmax_swap(ut64 *a, ut64 *b); -R_API void r_num_minmax_swap_i(int *a, int *b); // XXX this can be a cpp macro :?? -R_API ut64 r_num_math(RNum *num, const char *str); -R_API ut64 r_num_get(RNum *num, const char *str); -R_API int r_num_to_bits(char *out, ut64 num); -R_API int r_num_to_trits(char *out, ut64 num); //Rename this please -R_API int r_num_rand(int max); -R_API void r_num_irand(void); -R_API ut16 r_num_ntohs(ut16 foo); -R_API ut64 r_get_input_num_value(RNum *num, const char *input_value); -R_API bool r_is_valid_input_num_value(RNum *num, const char *input_value); -R_API int r_num_between(RNum *num, const char *input_value); -R_API bool r_num_is_op(const char c); -R_API int r_num_str_len(const char *str); -R_API int r_num_str_split(char *str); -R_API RList *r_num_str_split_list(char *str); -R_API void *r_num_dup(ut64 n); -R_API double r_num_cos(double a); -R_API double r_num_sin(double a); -R_API double r_num_get_float(RNum *num, const char *str); - -static inline st64 r_num_abs(st64 num) { - return num < 0 ? -num : num; -} - -#ifdef __cplusplus -} -#endif - -#endif // R_NUM_H diff --git a/libr/include/r_util/r_pool.h b/libr/include/r_util/r_pool.h deleted file mode 100644 index f884c31fb6..0000000000 --- a/libr/include/r_util/r_pool.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef R_POOL_H -#define R_POOL_H -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_mem_pool_factory_t { - int limit; - RMemoryPool **pools; -} RPoolFactory; - -R_API RPoolFactory *r_poolfactory_instance(void); -R_API void r_poolfactory_init (int limit); -R_API RPoolFactory* r_poolfactory_new(int limit); -R_API void *r_poolfactory_alloc(RPoolFactory *pf, int nodesize); -R_API void r_poolfactory_stats(RPoolFactory *pf); -R_API void r_poolfactory_free(RPoolFactory *pf); - -#ifdef __cplusplus -} -#endif - -#endif // R_POOL_H diff --git a/libr/include/r_util/r_print.h b/libr/include/r_util/r_print.h deleted file mode 100644 index bbf9388144..0000000000 --- a/libr/include/r_util/r_print.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef R2_PRINT_H -#define R2_PRINT_H - -#include "r_types.h" -#include "r_cons.h" -#include "r_bind.h" -#include "r_io.h" -#include "r_reg.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define R_PRINT_FLAGS_COLOR 0x00000001 -#define R_PRINT_FLAGS_ADDRMOD 0x00000002 -#define R_PRINT_FLAGS_CURSOR 0x00000004 -#define R_PRINT_FLAGS_HEADER 0x00000008 -#define R_PRINT_FLAGS_SPARSE 0x00000010 -#define R_PRINT_FLAGS_SEGOFF 0x00000020 -#define R_PRINT_FLAGS_OFFSET 0x00000040 -#define R_PRINT_FLAGS_REFS 0x00000080 -#define R_PRINT_FLAGS_DIFFOUT 0x00000100 /* only show different rows in `cc` hexdiffing */ -#define R_PRINT_FLAGS_ADDRDEC 0x00000200 -#define R_PRINT_FLAGS_COMMENT 0x00000400 -#define R_PRINT_FLAGS_COMPACT 0x00000800 -#define R_PRINT_FLAGS_NONHEX 0x00001000 -#define R_PRINT_FLAGS_SECSUB 0x00002000 -#define R_PRINT_FLAGS_RAINBOW 0x00004000 -#define R_PRINT_FLAGS_HDROFF 0x00008000 -#define R_PRINT_FLAGS_STYLE 0x00010000 -#define R_PRINT_FLAGS_NONASCII 0x00020000 -#define R_PRINT_FLAGS_ALIGN 0x00040000 -#define R_PRINT_FLAGS_UNALLOC 0x00080000 -#define R_PRINT_FLAGS_BGFILL 0x00100000 -#define R_PRINT_FLAGS_SECTION 0x00200000 - -typedef int (*RPrintZoomCallback)(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size); -typedef const char *(*RPrintNameCallback)(void *user, ut64 addr); -typedef int (*RPrintSizeCallback)(void *user, ut64 addr); -typedef char *(*RPrintCommentCallback)(void *user, ut64 addr); -typedef const char *(*RPrintSectionGet)(void *user, ut64 addr); -typedef const char *(*RPrintColorFor)(void *user, ut64 addr, bool verbose); -typedef char *(*RPrintHasRefs)(void *user, ut64 addr, bool verbose); - -typedef struct r_print_zoom_t { - ut8 *buf; - ut64 from; - ut64 to; - int size; - int mode; -} RPrintZoom; - -typedef struct r_print_t { - void *user; - RIOBind iob; - bool pava; - RCoreBind coreb; - const char *cfmt; - char datefmt[32]; - int datezone; - int (*write)(const unsigned char *buf, int len); - PrintfCallback cb_printf; - PrintfCallback cb_eprintf; - char *(*cb_color)(int idx, int last, bool bg); - bool scr_prompt; - int (*disasm)(void *p, ut64 addr); - PrintfCallback oprintf; - int big_endian; - int width; - int limit; - int bits; - bool histblock; - // true if the cursor is enabled, false otherwise - bool cur_enabled; - // offset of the selected byte from the first displayed one - int cur; - // offset of the selected byte from the first displayed one, when a - // range of bytes is selected. -1 is used if no bytes are selected. - int ocur; - int cols; - int flags; - int seggrn; - bool use_comments; - int addrmod; - int col; - int stride; - int bytespace; - int pairs; - bool resetbg; - RPrintZoom *zoom; - RPrintNameCallback offname; - RPrintSizeCallback offsize; - RPrintColorFor colorfor; - RPrintHasRefs hasrefs; - RPrintCommentCallback get_comments; - RPrintSectionGet get_section_name; - Sdb *formats; - Sdb *sdb_types; - RCons *cons; - RConsBind consbind; - RNum *num; - RReg *reg; - RRegItem* (*get_register)(RReg *reg, const char *name, int type); - ut64 (*get_register_value)(RReg *reg, RRegItem *item); - bool (*exists_var)(struct r_print_t *print, ut64 func_addr, char *str); - ut64* lines_cache; - int lines_cache_sz; - int lines_abs; - bool esc_bslash; - bool wide_offsets; - const char *strconv_mode; - RList *vars; - char io_unalloc_ch; - bool show_offset; - - // when true it uses row_offsets - bool calc_row_offsets; - // offset of the first byte of each printed row. - // Last elements is marked with a UT32_MAX. - ut32 *row_offsets; - // size of row_offsets - int row_offsets_sz; - // when true it makes visual mode flush the buffer to screen - bool vflush; - // represents the first not-visible offset on the screen - // (only when in visual disasm mode) - ut64 screen_bounds; -} RPrint; - -#ifdef R_API - -/* RConsBreak handlers */ -typedef bool (*RPrintIsInterruptedCallback)(); - -R_API bool r_print_is_interrupted(void); -R_API void r_print_set_is_interrupted_cb(RPrintIsInterruptedCallback cb); - -/* ... */ -R_API char *r_print_hexpair(RPrint *p, const char *str, int idx); -R_API void r_print_hex_from_bin(RPrint *p, char *bin_str); -R_API RPrint *r_print_new(void); -R_API RPrint *r_print_free(RPrint *p); -R_API bool r_print_mute(RPrint *p, int x); -R_API void r_print_set_flags(RPrint *p, int _flags); -R_API void r_print_unset_flags(RPrint *p, int flags); -R_API void r_print_addr(RPrint *p, ut64 addr); -R_API void r_print_section(RPrint *p, ut64 at); -R_API void r_print_columns(RPrint *p, const ut8 *buf, int len, int height); -R_API void r_print_hexii(RPrint *p, ut64 addr, const ut8 *buf, int len, int step); -R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step, size_t zoomsz); -R_API void r_print_hexdump_simple(const ut8 *buf, int len); -R_API int r_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize); -R_API void r_print_hexpairs(RPrint *p, ut64 addr, const ut8 *buf, int len); -R_API void r_print_hexdiff(RPrint *p, ut64 aa, const ut8* a, ut64 ba, const ut8 *b, int len, int scndcol); -R_API void r_print_bytes(RPrint *p, const ut8* buf, int len, const char *fmt); -R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step); -R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch); -R_API const char *r_print_byte_color(RPrint *p, int ch); -R_API void r_print_c(RPrint *p, const ut8 *str, int len); -R_API void r_print_raw(RPrint *p, ut64 addr, const ut8* buf, int len, int offlines); -R_API bool r_print_have_cursor(RPrint *p, int cur, int len); -R_API bool r_print_cursor_pointer(RPrint *p, int cur, int len); -R_API void r_print_cursor(RPrint *p, int cur, int len, int set); -R_API void r_print_cursor_range(RPrint *p, int cur, int to, int set); -R_API int r_print_get_cursor(RPrint *p); -R_API void r_print_set_cursor(RPrint *p, int curset, int ocursor, int cursor); -R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang); -#define SEEFLAG -2 -#define JSONOUTPUT -3 - -/* mode values for r_print_format_* API */ -#define R_PRINT_MUSTSEE (1) // enable printing of data in specified fmt -#define R_PRINT_ISFIELD (1 << 1) -#define R_PRINT_SEEFLAGS (1 << 2) -#define R_PRINT_JSON (1 << 3) -#define R_PRINT_MUSTSET (1 << 4) -#define R_PRINT_UNIONMODE (1 << 5) -#define R_PRINT_VALUE (1 << 6) -#define R_PRINT_DOT (1 << 7) -#define R_PRINT_QUIET (1 << 8) -#define R_PRINT_STRUCT (1 << 9) -R_API int r_print_format_struct_size(RPrint *p, const char *format, int mode, int n); -R_API int r_print_format(RPrint *p, ut64 seek, const ut8* buf, const int len, const char *fmt, int elem, const char *setval, char *field); -R_API const char *r_print_format_byname(RPrint *p, const char *name); -R_API void r_print_offset(RPrint *p, ut64 off, int invert, int opt, int dec, int delta, const char *label); -R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label); -#define R_PRINT_STRING_WIDE 1 -#define R_PRINT_STRING_ZEROEND 2 -#define R_PRINT_STRING_URLENCODE 4 -#define R_PRINT_STRING_WRAP 8 -#define R_PRINT_STRING_WIDE32 16 -#define R_PRINT_STRING_ESC_NL 32 -R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *str, int len, int options); -R_API int r_print_date_dos(RPrint *p, const ut8 *buf, int len); -R_API int r_print_date_hfs(RPrint *p, const ut8 *buf, int len); -R_API int r_print_date_w32(RPrint *p, const ut8 *buf, int len); -R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len); -R_API int r_print_date_get_now(RPrint *p, char *str); -R_API void r_print_zoom(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen); -R_API void r_print_zoom_buf(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen); -R_API void r_print_progressbar(RPrint *pr, int pc, int _cols); -R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions); -R_API void r_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 max, int cols); -R_API char * r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr); -R_API void r_print_2bpp_row(RPrint *p, ut8 *buf); -R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles); -R_API char * r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr); -R_API const char * r_print_color_op_type(RPrint *p, ut32 anal_type); -R_API void r_print_set_interrupted(int i); -R_API void r_print_init_rowoffsets(RPrint *p); -R_API ut32 r_print_rowoff(RPrint *p, int i); -R_API void r_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite); -R_API int r_print_row_at_off(RPrint *p, ut32 offset); -R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size); - -R_API const char* r_print_rowlog(RPrint *print, const char *str); -R_API void r_print_rowlog_done(RPrint *print, const char *str); - -// WIP -R_API int r_print_unpack7bit(const char *src, char *dest); -R_API int r_print_pack7bit(const char *src, char *dest); -R_API char *r_print_stereogram_bytes(const ut8 *buf, int len); -R_API char *r_print_stereogram(const char *bump, int w, int h); -R_API void r_print_stereogram_print(RPrint *p, const char *buf); -R_API void r_print_set_screenbounds(RPrint *p, ut64 addr); -R_API int r_util_lines_getline(ut64 *lines_cache, int lines_cache_sz, ut64 off); -R_API char* r_print_json_indent(const char* s, bool color, const char *tab, const char **colors); -R_API char* r_print_json_human(const char* s); -R_API char* r_print_json_path(const char* s, int pos); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util/r_punycode.h b/libr/include/r_util/r_punycode.h deleted file mode 100644 index f29c6d6a98..0000000000 --- a/libr/include/r_util/r_punycode.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef R_PUNYCODE_H -#define R_PUNYCODE_H - -#ifdef __cplusplus -extern "C" { -#endif - -R_API char *r_punycode_encode(const ut8 *src, int srclen, int *dstlen); -R_API char *r_punycode_decode(const char *src, int srclen, int *dstlen); - -#ifdef __cplusplus -} -#endif - -#endif // R_PUNYCODE_H diff --git a/libr/include/r_util/r_queue.h b/libr/include/r_util/r_queue.h deleted file mode 100644 index f6b2dea380..0000000000 --- a/libr/include/r_util/r_queue.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef R_QUEUE_H -#define R_QUEUE_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct r_queue_t { - void **elems; - unsigned int capacity; - unsigned int front; - int rear; - unsigned int size; -} RQueue; - -R_API RQueue *r_queue_new(int n); -R_API void r_queue_free(RQueue *q); -R_API int r_queue_enqueue(RQueue *q, void *el); -R_API void *r_queue_dequeue(RQueue *q); -R_API int r_queue_is_empty(RQueue *q); - -#ifdef __cplusplus -} -#endif - -#endif // R_QUEUE_H diff --git a/libr/include/r_util/r_range.h b/libr/include/r_util/r_range.h deleted file mode 100644 index a845f932c5..0000000000 --- a/libr/include/r_util/r_range.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef R_RANGE_H -#define R_RANGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* range.c */ - -typedef struct r_range_item_t { - ut64 fr; - ut64 to; - ut8 *data; - int datalen; -} RRangeItem; - -typedef struct r_range_t { - int count; - int changed; - RList *ranges; -} RRange; - -R_API RRange *r_range_new(void); -R_API RRange *r_range_new_from_string(const char *string); -R_API RRange *r_range_free(RRange *r); -R_API RRangeItem *r_range_item_get(RRange *r, ut64 addr); -R_API ut64 r_range_size(RRange *r); -R_API int r_range_add_from_string(RRange *rgs, const char *string); -R_API RRangeItem *r_range_add(RRange *rgs, ut64 from, ut64 to, int rw); -R_API int r_range_sub(RRange *rgs, ut64 from, ut64 to); -R_API void r_range_merge(RRange *rgs, RRange *r); -R_API int r_range_contains(RRange *rgs, ut64 addr); -R_API int r_range_sort(RRange *rgs); -R_API void r_range_percent(RRange *rgs); -R_API int r_range_list(RRange *rgs, int rad); -R_API int r_range_get_n(RRange *rgs, int n, ut64 *from, ut64 *to); -R_API RRange *r_range_inverse(RRange *rgs, ut64 from, ut64 to, int flags); -R_API int r_range_overlap(ut64 a0, ut64 a1, ut64 b0, ut64 b1, int *d); - -#ifdef __cplusplus -} -#endif - -#endif // R_RANGE_H diff --git a/libr/include/r_util/r_rbtree.h b/libr/include/r_util/r_rbtree.h deleted file mode 100644 index 761af6ade4..0000000000 --- a/libr/include/r_util/r_rbtree.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef R2_RBTREE_H -#define R2_RBTREE_H - -#include -#include -#include - -#include "r_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// max height <= 2 * floor(log2(n + 1)) -// We use `int` for size, so <= 2 * 31 -#define R_RBTREE_MAX_HEIGHT 62 - -// Singleton can be zero initialized -typedef struct r_rb_node_t { - struct r_rb_node_t *child[2]; - bool red; -} RBNode; - -typedef RBNode* RBTree; - -// incoming < in_tree => return < 0 -// incoming == in_tree => return == 0 -// incoming > in_tree => return > 0 -typedef int (*RBComparator)(const void *incoming, const RBNode *in_tree, void *user); - -typedef void (*RBNodeFree)(RBNode *node, void *user); -typedef void (*RBNodeSum)(RBNode *node); - -typedef struct r_rb_iter_t { - // current depth - // if len == 0, the iterator is at the end/empty - // else path[len-1] is the current node - int len; - - // current path from root to the current node - // excluding nodes into whose right (or left, for reverse iteration) branch the iterator has descended - // (these nodes are before the current) - RBNode *path[R_RBTREE_MAX_HEIGHT]; -} RBIter; - -typedef int (*RContRBCmp)(void *incoming, void *in, void *user); -typedef void (*RContRBFree)(void *); -typedef struct r_containing_rb_node_t { - RBNode node; - void *data; -} RContRBNode; - -typedef struct r_containing_rb_tree_t { - RContRBNode *root; - RContRBFree free; -} RContRBTree; - -// Routines for augmented red-black trees. The user should provide an aggregation (monoid sum) callback `sum` -// to calculate extra information such as size, sum, ... -R_API bool r_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user, RBNodeSum sum); -R_API bool r_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum); -R_API bool r_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum); - -R_API bool r_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user); -R_API RBNode *r_rbtree_find(RBNode *root, void *data, RBComparator cmp, void *user); -R_API void r_rbtree_free(RBNode *root, RBNodeFree freefn, void *user); -R_API void r_rbtree_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *user); -// Return the smallest node that is greater than or equal to `data` -R_API RBNode *r_rbtree_lower_bound(RBNode *root, void *data, RBComparator cmp, void *user); -// Return the greatest node that is less than or equal to `data` -R_API RBNode *r_rbtree_upper_bound(RBNode *root, void *data, RBComparator cmp, void *user); - -// Create a forward iterator starting from the leftmost node -R_API RBIter r_rbtree_first(RBNode *root); -// Create a backward iterator starting from the rightmost node -R_API RBIter r_rbtree_last(RBNode *root); - -// Iterate [lower_bound, end] forward, used with r_rbtree_iter_next -R_API RBIter r_rbtree_lower_bound_forward(RBNode *root, void *data, RBComparator cmp, void *user); -// Iterate [begin, upper_bound] backward, used with r_rbtree_iter_prev -R_API RBIter r_rbtree_upper_bound_backward(RBNode *root, void *data, RBComparator cmp, void *user); - -// struct Node { int key; RBNode rb; }; -// r_rbtree_iter_get (it, struct Node, rb) -#define r_rbtree_iter_get(it, struc, rb) (container_of ((it)->path[(it)->len-1], struc, rb)) -// If the iterator still contains elements, including the current -#define r_rbtree_iter_has(it) ((it)->len) -// Move forward -R_API void r_rbtree_iter_next(RBIter *it); -// Move backward -R_API void r_rbtree_iter_prev(RBIter *it); - -// Iterate all elements of the forward iterator -#define r_rbtree_iter_while(it, data, struc, rb) \ - for (; r_rbtree_iter_has(&it) && (data = r_rbtree_iter_get (&it, struc, rb)); r_rbtree_iter_next (&(it))) - -// Iterate all elements of the backward iterator -#define r_rbtree_iter_while_prev(it, data, struc, rb) \ - for (; r_rbtree_iter_has(&it) && (data = r_rbtree_iter_get (&it, struc, rb)); r_rbtree_iter_prev (&(it))) - -#define r_rbtree_foreach(root, it, data, struc, rb) \ - for ((it) = r_rbtree_first (root); r_rbtree_iter_has(&it) && (data = r_rbtree_iter_get (&it, struc, rb)); r_rbtree_iter_next (&(it))) - -#define r_rbtree_foreach_prev(root, it, data, struc, rb) \ - for ((it) = r_rbtree_last (root); r_rbtree_iter_has(&it) && (data = r_rbtree_iter_get (&it, struc, rb)); r_rbtree_iter_prev (&(it))) - - -R_API RContRBTree *r_rbtree_cont_new(void); -R_API RContRBTree *r_rbtree_cont_newf(RContRBFree f); -R_API bool r_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); -R_API bool r_rbtree_cont_delete(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); -R_API void *r_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); - -#define r_rbtree_cont_foreach(tree, it, dat) \ - for ((it) = r_rbtree_first (&tree->root->node); r_rbtree_iter_has(&it) && (dat = r_rbtree_iter_get (&it, RContRBNode, node)->data); r_rbtree_iter_next (&(it))) - -#define r_rbtree_cont_foreach_prev(tree, it, dat) \ - for ((it) = r_rbtree_last (&tree->root->node); r_rbtree_iter_has(&it) && (dat = r_rbtree_iter_get (&it, RContRBNode, node)->data); r_rbtree_iter_prev (&(it))) - -R_API void r_rbtree_cont_free(RContRBTree *tree); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util/r_sandbox.h b/libr/include/r_util/r_sandbox.h deleted file mode 100644 index d127ef71df..0000000000 --- a/libr/include/r_util/r_sandbox.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef R_SANDBOX_H -#define R_SANDBOX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __FreeBSD__ -#include - -#if __FreeBSD_version >= 1000000 -#define HAVE_CAPSICUM 1 -#else -#define HAVE_CAPSICUM 0 -#endif -#else -#define HAVE_CAPSICUM 0 -#endif -/** - * This function verifies that the given path is allowed. Paths are allowed only if they don't - * contain .. components (which would indicate directory traversal) and they are relative. - * Paths pointing into the webroot are an exception: For reaching the webroot, .. and absolute - * path are ok. - */ -#if __WINDOWS__ -R_API HANDLE r_sandbox_opendir(const char *path, WIN32_FIND_DATAW *entry); -#else -R_API DIR* r_sandbox_opendir(const char *path); -#endif -R_API int r_sandbox_truncate(int fd, ut64 length); -R_API int r_sandbox_lseek(int fd, ut64 addr, int mode); -R_API int r_sandbox_close(int fd); -R_API int r_sandbox_read(int fd, ut8 *buf, int len); -R_API int r_sandbox_write(int fd, const ut8 *buf, int len); -R_API bool r_sandbox_enable(bool e); -R_API bool r_sandbox_disable(bool e); -R_API int r_sandbox_system(const char *x, int fork); -R_API bool r_sandbox_creat(const char *path, int mode); -R_API int r_sandbox_open(const char *path, int mode, int perm); -R_API FILE *r_sandbox_fopen(const char *path, const char *mode); -R_API int r_sandbox_chdir(const char *path); -R_API bool r_sandbox_check_path(const char *path); -R_API int r_sandbox_kill(int pid, int sig); - -#ifdef __cplusplus -} -#endif - -#endif // R_SANDBOX_H diff --git a/libr/include/r_util/r_stack.h b/libr/include/r_util/r_stack.h deleted file mode 100644 index 6caed3aa13..0000000000 --- a/libr/include/r_util/r_stack.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef R_STACK_H -#define R_STACK_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*RStackFree)(void *ptr); - -typedef struct r_stack_t { - void **elems; - unsigned int n_elems; - int top; - RStackFree free; -} RStack; - -R_API RStack *r_stack_new(ut32 n); -R_API void r_stack_free(RStack *s); -R_API bool r_stack_is_empty(RStack *s); -R_API RStack *r_stack_newf(ut32 n, RStackFree f); -R_API bool r_stack_push(RStack *s, void *el); -R_API void *r_stack_pop(RStack *s); -R_API size_t r_stack_size(RStack *s); -R_API void *r_stack_peek(RStack *s); - -#ifdef __cplusplus -} -#endif - -#endif // R_STACK_H diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h deleted file mode 100644 index 081652a904..0000000000 --- a/libr/include/r_util/r_str.h +++ /dev/null @@ -1,209 +0,0 @@ -#ifndef R_STR_H -#define R_STR_H - -#include -#include "r_str_util.h" -#include "r_list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - R_STRING_ENC_LATIN1 = 'a', - R_STRING_ENC_UTF8 = '8', - R_STRING_ENC_UTF16LE = 'u', - R_STRING_ENC_UTF32LE = 'U', - R_STRING_ENC_UTF16BE = 'b', - R_STRING_ENC_UTF32BE = 'B', - R_STRING_ENC_GUESS = 'g', -} RStrEnc; - -typedef int (*RStrRangeCallback) (void *, int); - -#define R_STR_ISEMPTY(x) (!(x) || !*(x)) -#define R_STR_ISNOTEMPTY(x) ((x) && *(x)) -#define R_STR_DUP(x) ((x) ? strdup ((x)) : NULL) -#define r_str_array(x,y) ((y>=0 && y<(sizeof(x)/sizeof(*x)))?x[y]:"") -R_API char *r_str_repeat(const char *ch, int sz); -R_API const char *r_str_pad(const char ch, int len); -R_API const char *r_str_rstr(const char *base, const char *p); -R_API const char *r_strstr_ansi (const char *a, const char *b); -R_API const char *r_str_rchr(const char *base, const char *p, int ch); -R_API const char *r_str_closer_chr(const char *b, const char *s); -R_API int r_str_bounds(const char *str, int *h); -R_API char *r_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2); -R_API char *r_str_scale(const char *r, int w, int h); -R_API bool r_str_range_in(const char *r, ut64 addr); -R_API size_t r_str_len_utf8(const char *s); -R_API size_t r_str_len_utf8_ansi(const char *str); -R_API size_t r_str_len_utf8char(const char *s, int left); -R_API size_t r_str_utf8_charsize(const char *str); -R_API size_t r_str_utf8_charsize_prev(const char *str, int prev_len); -R_API size_t r_str_utf8_charsize_last(const char *str); -R_API void r_str_filter_zeroline(char *str, int len); -R_API size_t r_str_utf8_codepoint(const char *s, size_t left); -R_API bool r_str_char_fullwidth(const char *s, size_t left); -R_API int r_str_write(int fd, const char *b); -R_API void r_str_ncpy(char *dst, const char *src, size_t n); -R_API void r_str_sanitize(char *c); -R_API char *r_str_sanitize_sdb_key(const char *s); -R_API const char *r_str_casestr(const char *a, const char *b); -R_API const char *r_str_firstbut(const char *s, char ch, const char *but); -R_API const char *r_str_lastbut(const char *s, char ch, const char *but); -R_API int r_str_split(char *str, char ch); -R_API RList *r_str_split_list(char *str, const char *c, int n); -R_API RList *r_str_split_duplist(const char *str, const char *c, bool trim); -R_API size_t *r_str_split_lines(char *str, size_t *count); -R_API char* r_str_replace(char *str, const char *key, const char *val, int g); -R_API char *r_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case); -R_API char *r_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g); -#define r_str_cpy(x,y) memmove ((x), (y), strlen (y) + 1); -#define r_str_cat(x,y) memmove ((x) + strlen (x), (y), strlen (y) + 1); -R_API int r_str_bits(char *strout, const ut8 *buf, int len, const char *bitz); -R_API int r_str_bits64(char *strout, ut64 in); -R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz); -R_API int r_str_rwx(const char *str); -R_API int r_str_replace_ch(char *s, char a, char b, bool g); -R_API int r_str_replace_char(char *s, int a, int b); -R_API int r_str_replace_char_once(char *s, int a, int b); -R_API void r_str_remove_char(char *str, char c); -R_API const char *r_str_rwx_i(int rwx); -R_API int r_str_fmtargs(const char *fmt); -R_API char *r_str_arg_escape(const char *arg); -R_API int r_str_arg_unescape(char *arg); -R_API char **r_str_argv(const char *str, int *_argc); -R_API void r_str_argv_free(char **argv); -R_API char *r_str_new(const char *str); -R_API int r_snprintf (char *string, int len, const char *fmt, ...)R_PRINTF_CHECK(3, 4); -R_API bool r_str_is_ascii(const char *str); -R_API char *r_str_nextword(char *s, char ch); -R_API bool r_str_is_printable(const char *str); -R_API bool r_str_is_printable_limited(const char *str, int size); -R_API bool r_str_is_printable_incl_newlines(const char *str); -R_API char *r_str_appendlen(char *ptr, const char *string, int slen); -R_API char *r_str_newf(const char *fmt, ...); -R_API char *r_str_newlen(const char *str, int len); -R_API const char *r_str_sysbits(const int v); -R_API char *r_str_trunc_ellipsis(const char *str, int len); -R_API const char *r_str_bool(int b); -R_API bool r_str_is_true(const char *s); -R_API bool r_str_is_false(const char *s); -R_API bool r_str_is_bool(const char *val); -R_API const char *r_str_ansi_chrn(const char *str, size_t n); -R_API size_t r_str_ansi_len(const char *str); -R_API size_t r_str_ansi_nlen(const char *str, size_t len); -R_API int r_str_ansi_trim(char *str, int str_len, int n); -R_API int r_str_ansi_filter(char *str, char **out, int **cposs, int len); -R_API char *r_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2); -R_API int r_str_word_count(const char *string); -R_API int r_str_char_count(const char *string, char ch); -R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen); -R_API int r_str_word_set0(char *str); -R_API int r_str_word_set0_stack(char *str); -R_API const char *r_str_word_get0(const char *str, int idx); -R_API char *r_str_word_get_first(const char *string); -R_API void r_str_trim(char *str); -R_API char *r_str_trim_dup(const char *str); -R_API char *r_str_trim_lines(char *str); -R_API void r_str_trim_head(char *str); -R_API const char *r_str_trim_head_ro(const char *str); -R_API const char *r_str_trim_head_wp(const char *str); -R_API void r_str_trim_tail(char *str); -R_API ut32 r_str_hash(const char *str); -R_API ut64 r_str_hash64(const char *str); -R_API char *r_str_trim_nc(char *str); -R_API const char *r_str_nstr(const char *from, const char *to, int size); -R_API const char *r_str_lchr(const char *str, char chr); -R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr); -R_API const char *r_sub_str_rchr(const char *str, int start, int end, char chr); -R_API char *r_str_ichr(char *str, char chr); -R_API bool r_str_ccmp(const char *dst, const char *orig, int ch); -R_API bool r_str_cmp_list(const char *list, const char *item, char sep); -R_API int r_str_cmp(const char *dst, const char *orig, int len); -R_API int r_str_casecmp(const char *dst, const char *orig); -R_API int r_str_ncasecmp(const char *dst, const char *orig, size_t n); -R_API int r_str_ccpy(char *dst, char *orig, int ch); -R_API const char *r_str_get(const char *str); -R_API const char *r_str_get2(const char *str); -R_API char *r_str_ndup(const char *ptr, int len); -R_API char *r_str_dup(char *ptr, const char *string); -R_API int r_str_inject(char *begin, char *end, char *str, int maxlen); -R_API int r_str_delta(char *p, char a, char b); -R_API void r_str_filter(char *str, int len); -R_API const char * r_str_tok(const char *str1, const char b, size_t len); -R_API wchar_t *r_str_mb_to_wc(const char *buf); -R_API char *r_str_wc_to_mb(const wchar_t *buf); -R_API wchar_t *r_str_mb_to_wc_l(const char *buf, int len); -R_API char *r_str_wc_to_mb_l(const wchar_t *buf, int len); -R_API const char *r_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y); - -typedef void(*str_operation)(char *c); - -R_API int r_str_do_until_token(str_operation op, char *str, const char tok); - -R_API void r_str_reverse(char *str); -R_API int r_str_re_match(const char *str, const char *reg); -R_API int r_str_re_replace(const char *str, const char *reg, const char *sub); -R_API int r_str_path_unescape(char *path); -R_API char *r_str_path_escape(const char *path); -R_API int r_str_unescape(char *buf); -R_API char *r_str_escape(const char *buf); -R_API char *r_str_escape_sh(const char *buf); -R_API char *r_str_escape_dot(const char *buf); -R_API char *r_str_escape_latin1(const char *buf, bool show_asciidot, bool esc_bslash, bool colors); -R_API char *r_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bslash); -R_API char *r_str_escape_utf8_keep_printable(const char *buf, bool show_asciidot, bool esc_bslash); // like escape_utf8 but leaves valid \uXXXX chars directly in utf-8 -R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); -R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); -R_API char *r_str_escape_utf16be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); -R_API char *r_str_escape_utf32be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); -R_API void r_str_byte_escape(const char *p, char **dst, int dot_nl, bool default_dot, bool esc_bslash); -R_API char *r_str_format_msvc_argv(size_t argc, const char **argv); -R_API void r_str_uri_decode(char *buf); -R_API char *r_str_uri_encode(const char *buf); -R_API char *r_str_utf16_decode(const ut8 *s, int len); -R_API int r_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, int little_endian); -R_API char *r_str_utf16_encode(const char *s, int len); -R_API char *r_str_escape_utf8_for_json(const char *s, int len); -R_API char *r_str_home(const char *str); -R_API char *r_str_r2_prefix(const char *str); -R_API size_t r_str_nlen(const char *s, int n); -R_API size_t r_str_nlen_w(const char *s, int n); -R_API size_t r_wstr_clen(const char *s); -R_API char *r_str_prepend(char *ptr, const char *string); -R_API char *r_str_prefix_all(const char *s, const char *pfx); -R_API char *r_str_append(char *ptr, const char *string); -R_API char *r_str_append_owned(char *ptr, char *string); -R_API char *r_str_appendf(char *ptr, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API char *r_str_appendch(char *x, char y); -R_API void r_str_case(char *str, bool up); -R_API void r_str_trim_path(char *s); -R_API ut8 r_str_contains_macro(const char *input_value); -R_API void r_str_truncate_cmd(char *string); -R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, - const char *key, const char *val, int g); -R_API bool r_str_glob(const char *str, const char *glob); -R_API int r_str_binstr2bin(const char *str, ut8 *out, int outlen); -R_API char *r_str_between(const char *str, const char *prefix, const char *suffix); -R_API bool r_str_startswith(const char *str, const char *needle); -R_API bool r_str_endswith(const char *str, const char *needle); -R_API bool r_str_isnumber (const char *str); -R_API const char *r_str_last (const char *in, const char *ch); -R_API char* r_str_highlight(char *str, const char *word, const char *color, const char *color_reset); -R_API char *r_qrcode_gen(const ut8 *text, int len, bool utf8, bool inverted); -R_API char *r_str_from_ut64(ut64 val); -R_API void r_str_stripLine(char *str, const char *key); -R_API char *r_str_list_join(RList *str, const char *sep); -R_API char *r_str_array_join(const char **a, size_t n, const char *sep); - -R_API const char *r_str_sep(const char *base, const char *sep); -R_API const char *r_str_rsep(const char *base, const char *p, const char *sep); -R_API char *r_str_donut(int size); -R_API char *r_str_version(const char *program); - -#ifdef __cplusplus -} -#endif - -#endif // R_STR_H diff --git a/libr/include/r_util/r_strbuf.h b/libr/include/r_util/r_strbuf.h deleted file mode 100644 index b9f4eb032e..0000000000 --- a/libr/include/r_util/r_strbuf.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef R_STRBUF_H -#define R_STRBUF_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - char buf[32]; - size_t len; // string length in chars or binary buffer size - char *ptr; // ptr replacing buf in case strlen > sizeof(buf) - size_t ptrlen; // string length + 1 or binary buffer size - bool weakref; // ptr is not owned -} RStrBuf; - -#define R_STRBUF_SAFEGET(sb) (r_strbuf_get (sb) ? r_strbuf_get (sb) : "") -R_API RStrBuf *r_strbuf_new(const char *s); -R_API const char *r_strbuf_set(RStrBuf *sb, const char *s); // return = the string or NULL on fail -R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len); -R_API bool r_strbuf_setbin(RStrBuf *sb, const ut8 *s, size_t len); -R_API ut8* r_strbuf_getbin(RStrBuf *sb, int *len); -R_API const char *r_strbuf_setf(RStrBuf *sb, const char *fmt, ...); // return = the string or NULL on fail -R_API const char *r_strbuf_vsetf(RStrBuf *sb, const char *fmt, va_list ap); // return = the string or NULL on fail -R_API bool r_strbuf_append(RStrBuf *sb, const char *s); -R_API bool r_strbuf_append_n(RStrBuf *sb, const char *s, size_t l); -R_API bool r_strbuf_prepend(RStrBuf *sb, const char *s); -R_API bool r_strbuf_appendf(RStrBuf *sb, const char *fmt, ...); -R_API bool r_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap); -R_API char *r_strbuf_get(RStrBuf *sb); -R_API char *r_strbuf_drain(RStrBuf *sb); -R_API char *r_strbuf_drain_nofree(RStrBuf *sb); -R_API int r_strbuf_length(RStrBuf *sb); -R_API int r_strbuf_size(RStrBuf *sb); -R_API void r_strbuf_free(RStrBuf *sb); -R_API void r_strbuf_fini(RStrBuf *sb); -R_API void r_strbuf_init(RStrBuf *sb); -R_API const char *r_strbuf_initf(RStrBuf *sb, const char *fmt, ...); // same as init + setf for convenience -R_API bool r_strbuf_copy(RStrBuf *dst, RStrBuf *src); -R_API bool r_strbuf_equals(RStrBuf *sa, RStrBuf *sb); -R_API bool r_strbuf_reserve(RStrBuf *sb, size_t len); -R_API bool r_strbuf_is_empty(RStrBuf *sb); -R_API bool r_strbuf_setptr(RStrBuf *sb, char *p, int l); - -#ifdef __cplusplus -} -#endif - -#endif // R_STRBUF_H diff --git a/libr/include/r_util/r_strpool.h b/libr/include/r_util/r_strpool.h deleted file mode 100644 index 0c281429a0..0000000000 --- a/libr/include/r_util/r_strpool.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef R_STRPOOL_H -#define R_STRPOOL_H - -#define R_STRPOOL_INC 1024 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - char *str; - int len; - int size; -} RStrpool; - -R_API RStrpool* r_strpool_new(int sz); -R_API char *r_strpool_alloc(RStrpool *p, int l); -R_API int r_strpool_memcat(RStrpool *p, const char *s, int len); -R_API int r_strpool_ansi_chop(RStrpool *p, int n); -R_API int r_strpool_append(RStrpool *p, const char *s); -R_API void r_strpool_free(RStrpool *p); -R_API int r_strpool_fit(RStrpool *p); -R_API char *r_strpool_get(RStrpool *p, int index); -R_API char *r_strpool_get_i(RStrpool *p, int index); -R_API int r_strpool_get_index(RStrpool *p, const char *s); -R_API char *r_strpool_next(RStrpool *p, int index); -R_API char *r_strpool_slice(RStrpool *p, int index); -R_API char *r_strpool_empty(RStrpool *p); - -#ifdef __cplusplus -} -#endif - -#endif // R_STRPOOL_H diff --git a/libr/include/r_util/r_sys.h b/libr/include/r_util/r_sys.h deleted file mode 100644 index 6235456cf2..0000000000 --- a/libr/include/r_util/r_sys.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef R_SYS_H -#define R_SYS_H - -#include - -#if __WINDOWS__ -#define R_SYS_DEVNULL "nul" -#else -#define R_SYS_DEVNULL "/dev/null" -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -enum { - R_SYS_BITS_8 = 1, - R_SYS_BITS_16 = 2, - R_SYS_BITS_32 = 4, - R_SYS_BITS_64 = 8, -}; - -typedef struct { - char *sysname; - char *nodename; - char *release; - char *version; - char *machine; -} RSysInfo; - -R_API RSysInfo *r_sys_info(void); -R_API void r_sys_info_free(RSysInfo *si); - -R_API int r_sys_sigaction(int *sig, void (*handler) (int)); -R_API int r_sys_signal(int sig, void (*handler) (int)); -R_API void r_sys_env_init(void); -R_API char **r_sys_get_environ(void); -R_API void r_sys_set_environ(char **e); - -R_API int r_sys_fork(void); -// nocleanup = false => exit(); true => _exit() -R_API void r_sys_exit(int status, bool nocleanup); -R_API bool r_is_heap (void *p); -R_API bool r_sys_stop(void); -R_API char *r_sys_pid_to_path(int pid); -R_API int r_sys_run(const ut8 *buf, int len); -R_API int r_sys_run_rop(const ut8 *buf, int len); -R_API int r_sys_getpid(void); -R_API int r_sys_crash_handler(const char *cmd); -R_API const char *r_sys_arch_str(int arch); -R_API int r_sys_arch_id(const char *arch); -R_API bool r_sys_arch_match(const char *archstr, const char *arch); -R_API RList *r_sys_dir(const char *path); -R_API void r_sys_perror_str(const char *fun); -#if __WINDOWS__ -#define r_sys_mkdir_failed() (GetLastError () != ERROR_ALREADY_EXISTS) -#else -#define r_sys_mkdir_failed() (errno != EEXIST) -#endif -R_API const char *r_sys_prefix(const char *pfx); -R_API bool r_sys_mkdir(const char *dir); -R_API bool r_sys_mkdirp(const char *dir); -R_API int r_sys_sleep(int secs); -R_API int r_sys_usleep(int usecs); -R_API char *r_sys_getenv(const char *key); -R_API bool r_sys_getenv_asbool(const char *key); -R_API int r_sys_setenv(const char *key, const char *value); -R_API int r_sys_clearenv(void); -R_API char *r_sys_whoami(char *buf); -R_API char *r_sys_getdir(void); -R_API int r_sys_chdir(const char *s); -R_API bool r_sys_aslr(int val); -R_API int r_sys_thp_mode(void); -R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr); -#if __WINDOWS__ -#if UNICODE -#define W32_TCHAR_FSTR "%S" -#define W32_TCALL(name) name"W" -#define r_sys_conv_utf8_to_win(buf) r_utf8_to_utf16 (buf) -#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_utf16_l (buf, len) -#define r_sys_conv_win_to_utf8(buf) r_utf16_to_utf8 (buf) -#define r_sys_conv_win_to_utf8_l(buf, len) r_utf16_to_utf8_l ((wchar_t *)buf, len) -#else -#define W32_TCHAR_FSTR "%s" -#define W32_TCALL(name) name"A" -#define r_sys_conv_utf8_to_win(buf) r_utf8_to_acp (buf) -#define r_sys_conv_utf8_to_win_l(buf, len) r_utf8_to_acp_l (buf, len) -#define r_sys_conv_win_to_utf8(buf) r_acp_to_utf8 (buf) -#define r_sys_conv_win_to_utf8_l(buf, len) r_acp_to_utf8_l (buf, len) -#endif -R_API char *r_sys_get_src_dir_w32(void); -R_API bool r_sys_cmd_str_full_w32(const char *cmd, const char *input, char **output, int *outlen, char **sterr); -R_API bool r_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE out, HANDLE err); -#endif -R_API int r_sys_truncate(const char *file, int sz); -R_API int r_sys_cmd(const char *cmd); -R_API int r_sys_cmdbg(const char *cmd); -R_API int r_sys_cmdf(const char *fmt, ...) R_PRINTF_CHECK(1, 2); -R_API char *r_sys_cmd_str(const char *cmd, const char *input, int *len); -R_API char *r_sys_cmd_strf(const char *cmd, ...) R_PRINTF_CHECK(1, 2); -//#define r_sys_cmd_str(cmd, input, len) r_sys_cmd_str_full(cmd, input, len, 0) -R_API void r_sys_backtrace(void); -R_API bool r_sys_tts(const char *txt, bool bg); - -#if __WINDOWS__ -# define r_sys_breakpoint() { __debugbreak (); } -#else -#if __GNUC__ -# define r_sys_breakpoint() __builtin_trap() -#elif __i386__ || __x86_64__ -# define r_sys_breakpoint() __asm__ volatile ("int3"); -#elif __arm64__ || __aarch64__ -# define r_sys_breakpoint() __asm__ volatile ("brk 0"); -// #define r_sys_breakpoint() __asm__ volatile ("brk #1"); -#elif (__arm__ || __thumb__) -# if __ARM_ARCH > 5 -# define r_sys_breakpoint() __asm__ volatile ("bkpt $0"); -# else -# define r_sys_breakpoint() __asm__ volatile ("svc $1"); -# endif -#elif __mips__ -# define r_sys_breakpoint() __asm__ volatile ("break"); -// # define r_sys_breakpoint() __asm__ volatile ("teq $0, $0"); -#elif __EMSCRIPTEN__ -// TODO: cannot find a better way to breakpoint in wasm/asm.js -# define r_sys_breakpoint() { char *a = NULL; *a = 0; } -#else -# warning r_sys_breakpoint not implemented for this platform -# define r_sys_trap() __asm__ __volatile__ (".word 0"); -# define r_sys_breakpoint() { char *a = NULL; *a = 0; } -#endif -#endif - -/* syscmd */ -R_API char *r_syscmd_ls(const char *input); -R_API char *r_syscmd_cat(const char *file); -R_API char *r_syscmd_mkdir(const char *dir); -R_API bool r_syscmd_mv(const char *input); -R_API char *r_syscmd_uniq(const char *file); -R_API char *r_syscmd_head(const char *file, int count); -R_API char *r_syscmd_tail(const char *file, int count); -R_API char *r_syscmd_join(const char *file1, const char *file2); -R_API char *r_syscmd_sort(const char *file); - -#ifdef __cplusplus -} -#endif - -#endif // R_SYS_H diff --git a/libr/include/r_util/r_table.h b/libr/include/r_util/r_table.h deleted file mode 100644 index ee8f62e108..0000000000 --- a/libr/include/r_util/r_table.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef R_UTIL_TABLE_H -#define R_UTIL_TABLE_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char *name; - RListComparator cmp; -} RTableColumnType; - -typedef struct { - char *name; - RTableColumnType *type; - int align; // left, right, center (TODO: unused) - int width; // computed - int maxWidth; - bool forceUppercase; - int total; -} RTableColumn; - -typedef struct { - char *name; - RInterval pitv; - RInterval vitv; - int perm; - char *extra; -} RListInfo; - -enum { - R_TABLE_ALIGN_LEFT, - R_TABLE_ALIGN_RIGHT, - R_TABLE_ALIGN_CENTER -}; - -typedef struct { - // TODO: use RVector - RList *items; -} RTableRow; - -typedef struct { - RList *rows; - RList *cols; - int totalCols; - bool showHeader; - bool showFancy; - bool showJSON; - bool showCSV; - bool showSum; - bool adjustedCols; - void *cons; -} RTable; - -typedef void (*RTableSelector)(RTableRow *acc, RTableRow *new_row, int nth); - -R_API void r_table_row_free(void *_row); -R_API void r_table_column_free(void *_col); -R_API RTableColumn *r_table_column_clone(RTableColumn *col); -R_API RTableColumnType *r_table_type(const char *name); -R_API RTable *r_table_new(void); -R_API void r_table_free(RTable *t); -R_API int r_table_column_nth(RTable *t, const char *name); -R_API void r_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxWidth); -R_API void r_table_set_columnsf(RTable *t, const char *fmt, ...); -R_API RTableRow *r_table_row_new(RList *items); -R_API void r_table_add_row(RTable *t, const char *name, ...); -R_API void r_table_add_rowf(RTable *t, const char *fmt, ...); -R_API void r_table_add_row_list(RTable *t, RList *items); -R_API char *r_table_tofancystring(RTable *t); -R_API char *r_table_tosimplestring(RTable *t); -R_API char *r_table_tostring(RTable *t); -R_API char *r_table_tocsv(RTable *t); -R_API char *r_table_tojson(RTable *t); -R_API void r_table_filter(RTable *t, int nth, int op, const char *un); -R_API void r_table_sort(RTable *t, int nth, bool inc); -R_API void r_table_uniq(RTable *t); -R_API void r_table_group(RTable *t, int nth, RTableSelector fcn); -R_API bool r_table_query(RTable *t, const char *q); -R_API void r_table_hide_header(RTable *t); -R_API bool r_table_align(RTable *t, int nth, int align); -R_API void r_table_visual_list(RTable *table, RList* list, ut64 seek, ut64 len, int width, bool va); -R_API RTable *r_table_clone(RTable *t); -R_API RTable *r_table_push(RTable *t); -R_API RTable *r_table_pop(RTable *t); -R_API void r_table_fromjson(RTable *t, const char *csv); -R_API void r_table_fromcsv(RTable *t, const char *csv); -R_API char *r_table_tohtml(RTable *t); -R_API void r_table_transpose(RTable *t); -R_API void r_table_format(RTable *t, int nth, RTableColumnType *type); -R_API ut64 r_table_reduce(RTable *t, int nth); -R_API void r_table_columns(RTable *t, RList *cols); // const char *name, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/include/r_util/r_tree.h b/libr/include/r_util/r_tree.h deleted file mode 100644 index 44a6e28d06..0000000000 --- a/libr/include/r_util/r_tree.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef R_TREE_H -#define R_TREE_H -#include -#include - -struct r_tree_t; - -typedef struct r_tree_node_t { - struct r_tree_node_t *parent; - struct r_tree_t *tree; - RList *children; // - unsigned int n_children; - int depth; - RListFree free; - void *data; -} RTreeNode; - -typedef struct r_tree_t { - RTreeNode *root; -} RTree; - -typedef struct r_tree_visitor_t { - void (*pre_visit)(RTreeNode *, struct r_tree_visitor_t *); - void (*post_visit)(RTreeNode *, struct r_tree_visitor_t *); - void (*discover_child)(RTreeNode *, struct r_tree_visitor_t *); - void *data; -} RTreeVisitor; -typedef void (*RTreeNodeVisitCb)(RTreeNode *n, RTreeVisitor *vis); - -R_API RTree *r_tree_new(void); -R_API RTreeNode *r_tree_add_node(RTree *t, RTreeNode *node, void *child_data); -R_API void r_tree_reset(RTree *t); -R_API void r_tree_free(RTree *t); -R_API void r_tree_dfs(RTree *t, RTreeVisitor *vis); -R_API void r_tree_bfs(RTree *t, RTreeVisitor *vis); -#endif // R_TREE_H diff --git a/libr/include/r_util/r_uleb128.h b/libr/include/r_util/r_uleb128.h deleted file mode 100644 index 6520bf5968..0000000000 --- a/libr/include/r_util/r_uleb128.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef R_ULEB128_H -#define R_ULEB128_H - -// LEB128 or Little Endian Base 128 is a form of variable-length code -// compression used to store an arbitrarily large integer in a small number of -// bytes. LEB128 is used in the DWARF debug file format. - -R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v, const char **error); -R_API const ut8 *r_uleb128_decode(const ut8 *data, int *datalen, ut64 *v); -R_API int r_uleb128_len(const ut8 *data, int size); -R_API ut8 *r_uleb128_encode(const ut64 s, int *len); -R_API const ut8 *r_leb128(const ut8 *data, int datalen, st64 *v); -R_API st64 r_sleb128(const ut8 **data, const ut8 *end); -R_API size_t read_u32_leb128(const ut8 *p, const ut8 *max, ut32 *out_val); -R_API size_t read_i32_leb128(const ut8 *p, const ut8 *max, st32 *out_val); -R_API size_t read_u64_leb128(const ut8 *p, const ut8 *max, ut64 *out_val); -R_API size_t read_i64_leb128(const ut8 *p, const ut8 *max, st64 *out_val); -#endif // R_ULEB128_H diff --git a/libr/include/r_util/r_utf16.h b/libr/include/r_util/r_utf16.h deleted file mode 100644 index 1912348210..0000000000 --- a/libr/include/r_util/r_utf16.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef R_UTF16_H -#define R_UTF16_H - -/* For RRune definition */ -#include "r_utf8.h" - -R_API int r_utf16_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian); -R_API int r_utf16le_decode(const ut8 *ptr, int ptrlen, RRune *ch); -R_API int r_utf16be_decode(const ut8 *ptr, int ptrlen, RRune *ch); -R_API int r_utf16le_encode(ut8 *ptr, RRune ch); - -#endif // R_UTF16_H diff --git a/libr/include/r_util/r_utf32.h b/libr/include/r_util/r_utf32.h deleted file mode 100644 index 077d336d10..0000000000 --- a/libr/include/r_util/r_utf32.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef R_UTF32_H -#define R_UTF32_H - -/* For RRune definition */ -#include "r_utf8.h" - -R_API int r_utf32_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian); -R_API int r_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch); -R_API int r_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch); - -#endif // R_UTF32_H diff --git a/libr/include/r_util/r_utf8.h b/libr/include/r_util/r_utf8.h deleted file mode 100644 index bf2287039a..0000000000 --- a/libr/include/r_util/r_utf8.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef R_UTF8_H -#define R_UTF8_H - -/* For RStrEnc definition */ -#include "r_str.h" - -typedef struct { ut32 from, to; const char *name; } RUtfBlock; -// extern const RUtfBlock r_utf_blocks[]; - -typedef ut32 RRune; -R_API int r_utf8_encode(ut8 *ptr, const RRune ch); -R_API int r_utf8_decode(const ut8 *ptr, int ptrlen, RRune *ch); -R_API int r_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length); -R_API int r_utf8_size(const ut8 *ptr); -R_API int r_utf8_strlen(const ut8 *str); -R_API int r_isprint(const RRune c); -R_API char *r_utf16_to_utf8_l(const wchar_t *wc, int len); -R_API const char *r_utf_block_name(int idx); -R_API wchar_t *r_utf8_to_utf16_l(const char *cstring, int len); -R_API int r_utf_block_idx (RRune ch); -R_API int *r_utf_block_list (const ut8 *str, int len, int **freq_list); -R_API RStrEnc r_utf_bom_encoding(const ut8 *ptr, int ptrlen); -#define r_utf16_to_utf8(wc) r_utf16_to_utf8_l ((wchar_t *)wc, -1) -#define r_utf8_to_utf16(cstring) r_utf8_to_utf16_l ((char *)cstring, -1) -#if __WINDOWS__ -R_API char *r_acp_to_utf8_l(const char *str, int len); -R_API char *r_utf8_to_acp_l(const char *str, int len); -#define r_acp_to_utf8(str) r_acp_to_utf8_l ((char *)str, -1) -#define r_utf8_to_acp(cstring) r_utf8_to_acp_l ((char *)cstring, -1) -#endif // __WINDOWS__ - -#endif // R_UTF8_H diff --git a/libr/include/r_vector.h b/libr/include/r_vector.h deleted file mode 100644 index 3821b77c90..0000000000 --- a/libr/include/r_vector.h +++ /dev/null @@ -1,313 +0,0 @@ -#ifndef R2_VECTOR_H -#define R2_VECTOR_H - -#include -#include -#ifdef __cplusplus -extern "C" { -#endif - -/* - * RVector can contain arbitrarily sized elements. - * RPVector uses RVector internally and always contains void *s - * - * Thus, for storing pointers it is highly encouraged to always use RPVector - * as it is specifically made for this purpose and is more consistent with RList, - * while RVector can be used as, for example, a flat array of a struct. - * - * Notable differences between RVector and RPVector: - * ------------------------------------------------- - * When RVector expects an element to be inserted, for example in r_vector_push(..., void *x), - * this void * value is interpreted as a pointer to the actual data for the element. - * => If you use RVector as a dynamic replacement for (struct SomeStruct)[], you will - * pass a struct SomeStruct * to these functions. - * - * Because RPVector only handles pointers, the given void * is directly interpreted as the - * actual pointer to be inserted. - * => If you use RPVector as a dynamic replacement for (SomeType *)[], you will pass - * SomeType * directly to these functions. - * - * The same differentiation goes for the free functions: - * - The element parameter in RVectorFree is a pointer to the element inside the array. - * - The element parameter in RPVectorFree is the actual pointer stored in the array. - * - * General Hint: - * ------------- - * remove/pop functions do not reduce the capacity. - * Call r_(p)vector_shrink explicitly if desired. - */ - -typedef int (*RPVectorComparator)(const void *a, const void *b); -typedef void (*RVectorFree)(void *e, void *user); -typedef void (*RPVectorFree)(void *e); - -typedef struct r_vector_t { - void *a; - size_t len; - size_t capacity; - size_t elem_size; - RVectorFree free; - void *free_user; -} RVector; - -// RPVector directly wraps RVector for type safety -typedef struct r_pvector_t { RVector v; } RPVector; - - -// RVector - -R_API void r_vector_init(RVector *vec, size_t elem_size, RVectorFree free, void *free_user); - -R_API RVector *r_vector_new(size_t elem_size, RVectorFree free, void *free_user); - -// clears the vector and calls vec->free on every element if set. -R_API void r_vector_fini(RVector *vec); - -// frees the vector and calls vec->free on every element if set. -R_API void r_vector_free(RVector *vec); - -// the returned vector will have the same capacity as vec. -R_API RVector *r_vector_clone(RVector *vec); - -static inline bool r_vector_empty(const RVector *vec) { - r_return_val_if_fail (vec, false); - return vec->len == 0; -} - -R_API void r_vector_clear(RVector *vec); - -// returns a pointer to the offset inside the array where the element of the index lies. -static inline void *r_vector_index_ptr(RVector *vec, size_t index) { - r_return_val_if_fail (vec && index < vec->capacity, NULL); - return (char *)vec->a + vec->elem_size * index; -} - -// helper function to assign an element of size vec->elem_size from elem to p. -// elem is a pointer to the actual data to assign! -R_API void r_vector_assign(RVector *vec, void *p, void *elem); - -// assign the value of size vec->elem_size at elem to vec at the given index. -// elem is a pointer to the actual data to assign! -R_API void *r_vector_assign_at(RVector *vec, size_t index, void *elem); - -// remove the element at the given index and write the content to into. -// It is the caller's responsibility to free potential resources associated with the element. -R_API void r_vector_remove_at(RVector *vec, size_t index, void *into); - -// insert the value of size vec->elem_size at x at the given index. -// x is a pointer to the actual data to assign! -R_API void *r_vector_insert(RVector *vec, size_t index, void *x); - -// insert count values of size vec->elem_size into vec starting at the given index. -R_API void *r_vector_insert_range(RVector *vec, size_t index, void *first, size_t count); - -// like r_vector_remove_at for the last element -R_API void r_vector_pop(RVector *vec, void *into); - -// like r_vector_remove_at for the first element -R_API void r_vector_pop_front(RVector *vec, void *into); - -// like r_vector_insert for the end of vec -R_API void *r_vector_push(RVector *vec, void *x); - -// like r_vector_insert for the beginning of vec -R_API void *r_vector_push_front(RVector *vec, void *x); - -// make sure the capacity is at least capacity. -R_API void *r_vector_reserve(RVector *vec, size_t capacity); - -// shrink capacity to len. -R_API void *r_vector_shrink(RVector *vec); - -/* - * example: - * - * RVector *v = ...; // - * MyStruct *it; - * r_vector_foreach (v, it) { - * // Do something with it - * } - */ -#define r_vector_foreach(vec, it) \ - if (!r_vector_empty (vec)) \ - for (it = (void *)(vec)->a; (char *)it != (char *)(vec)->a + ((vec)->len * (vec)->elem_size); it = (void *)((char *)it + (vec)->elem_size)) - -#define r_vector_foreach_prev(vec, it) \ - if (!r_vector_empty (vec)) \ - for (it = (void *)((char *)(vec)->a + (((vec)->len - 1)* (vec)->elem_size)); (char *)it != (char *)(vec)->a; it = (void *)((char *)it - (vec)->elem_size)) - -#define r_vector_enumerate(vec, it, i) \ - if (!r_vector_empty (vec)) \ - for (it = (void *)(vec)->a, i = 0; i < (vec)->len; it = (void *)((char *)it + (vec)->elem_size), i++) - -/* - * example: - * - * RVector *v = ...; // contains {(st64)0, (st64)2, (st64)4, (st64)6, (st64)8}; - * size_t l; - * #define CMP(x, y) x - (*(st64 *)y) - * r_vector_lower_bound (v, 3, l, CMP); - * // l == 2 - */ -#define r_vector_lower_bound(vec, x, i, cmp) \ - do { \ - size_t h = (vec)->len, m; \ - for (i = 0; i < h; ) { \ - m = i + ((h - i) >> 1); \ - if ((cmp (x, ((char *)(vec)->a + (vec)->elem_size * m))) > 0) { \ - i = m + 1; \ - } else { \ - h = m; \ - } \ - } \ - } while (0) \ - -#define r_vector_upper_bound(vec, x, i, cmp) \ - do { \ - size_t h = (vec)->len, m; \ - for (i = 0; i < h; ) { \ - m = i + ((h - i) >> 1); \ - if ((cmp (x, ((char *)(vec)->a + (vec)->elem_size * m))) < 0) { \ - h = m; \ - } else { \ - i = m + 1; \ - } \ - } \ - } while (0) \ - -// RPVector - -R_API void r_pvector_init(RPVector *vec, RPVectorFree free); -R_API void r_pvector_fini(RPVector *vec); - -R_API RPVector *r_pvector_new(RPVectorFree free); - -R_API RPVector *r_pvector_new_with_len(RPVectorFree free, size_t length); - -// clear the vector and call vec->v.free on every element. -R_API void r_pvector_clear(RPVector *vec); - -// free the vector and call vec->v.free on every element. -R_API void r_pvector_free(RPVector *vec); - -static inline size_t r_pvector_len(const RPVector *vec) { - r_return_val_if_fail (vec, 0); - return vec->v.len; -} - -static inline void *r_pvector_at(const RPVector *vec, size_t index) { - r_return_val_if_fail (vec && index < vec->v.len, NULL); - return ((void **)vec->v.a)[index]; -} - -static inline void r_pvector_set(RPVector *vec, size_t index, void *e) { - r_return_if_fail (vec && index < vec->v.len); - ((void **)vec->v.a)[index] = e; -} - -static inline bool r_pvector_empty(RPVector *vec) { - return r_pvector_len (vec) == 0; -} - -// returns a pointer to the offset inside the array where the element of the index lies. -static inline void **r_pvector_index_ptr(RPVector *vec, size_t index) { - r_return_val_if_fail (vec && index < vec->v.capacity, NULL); - return ((void **)vec->v.a) + index; -} - -// same as r_pvector_index_ptr(, 0) -static inline void **r_pvector_data(RPVector *vec) { - r_return_val_if_fail (vec, NULL); - return (void **)vec->v.a; -} - -// returns the respective pointer inside the vector if x is found or NULL otherwise. -R_API void **r_pvector_contains(RPVector *vec, void *x); - -// removes and returns the pointer at the given index. Does not call free. -R_API void *r_pvector_remove_at(RPVector *vec, size_t index); - -// removes the element x, if present. Does not call free. -R_API void r_pvector_remove_data(RPVector *vec, void *x); - -// like r_vector_insert, but the pointer x is the actual data to be inserted. -static inline void **r_pvector_insert(RPVector *vec, size_t index, void *x) { - return (void **)r_vector_insert (&vec->v, index, &x); -} - -// like r_vector_insert_range. -static inline void **r_pvector_insert_range(RPVector *vec, size_t index, void **first, size_t count) { - return (void **)r_vector_insert_range (&vec->v, index, first, count); -} - -// like r_vector_pop, but returns the pointer directly. -R_API void *r_pvector_pop(RPVector *vec); - -// like r_vector_pop_front, but returns the pointer directly. -R_API void *r_pvector_pop_front(RPVector *vec); - -// like r_vector_push, but the pointer x is the actual data to be inserted. -static inline void **r_pvector_push(RPVector *vec, void *x) { - return (void **)r_vector_push (&vec->v, &x); -} - -// like r_vector_push_front, but the pointer x is the actual data to be inserted. -static inline void **r_pvector_push_front(RPVector *vec, void *x) { - return (void **)r_vector_push_front (&vec->v, &x); -} - -// sort vec using quick sort. -R_API void r_pvector_sort(RPVector *vec, RPVectorComparator cmp); - -static inline void **r_pvector_reserve(RPVector *vec, size_t capacity) { - return (void **)r_vector_reserve (&vec->v, capacity); -} - -static inline void **r_pvector_shrink(RPVector *vec) { - return (void **)r_vector_shrink (&vec->v); -} - -/* - * example: - * - * RVector *v = ...; - * void **it; - * r_pvector_foreach (v, it) { - * void *p = *it; - * // Do something with p - * } - */ -#define r_pvector_foreach(vec, it) \ - for (it = (void **)(vec)->v.a; it != (void **)(vec)->v.a + (vec)->v.len; it++) - -// like r_pvector_foreach() but inverse -#define r_pvector_foreach_prev(vec, it) \ - for (it = ((vec)->v.len == 0 ? NULL : (void **)(vec)->v.a + (vec)->v.len - 1); it != NULL && it != (void **)(vec)->v.a - 1; it--) - -/* - * example: - * - * RPVector *v = ...; // contains {(void*)0, (void*)2, (void*)4, (void*)6, (void*)8}; - * size_t index; - * #define CMP(x, y) x - y - * r_pvector_lower_bound (v, (void *)3, index, CMP); - * // index == 2 - */ -#define r_pvector_lower_bound(vec, x, i, cmp) \ - do { \ - size_t h = (vec)->v.len, m; \ - for (i = 0; i < h; ) { \ - m = i + ((h - i) >> 1); \ - if ((cmp ((x), ((void **)(vec)->v.a)[m])) > 0) { \ - i = m + 1; \ - } else { \ - h = m; \ - } \ - } \ - } while (0) \ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libr/io/io_desc.c b/libr/io/io_desc.c deleted file mode 100644 index 866c402b4e..0000000000 --- a/libr/io/io_desc.c +++ /dev/null @@ -1,356 +0,0 @@ -/* radare2 - LGPL - Copyright 2017-2019 - condret, pancake, alvaro */ - -#include -#include -#include - -//shall be used by plugins for creating descs -//XXX kill mode -R_API RIODesc* r_io_desc_new(RIO* io, RIOPlugin* plugin, const char* uri, int perm, int mode, void* data) { - ut32 fd32 = 0; - // this is required for emscripten builds to work, but should assert - if (!io || !plugin || !uri) { - return NULL; - } - if (io->files) { - if (!r_id_pool_grab_id (io->files->pool, &fd32)) { - return NULL; - } - } - RIODesc* desc = R_NEW0 (RIODesc); - if (desc) { - desc->fd = fd32; - desc->io = io; - desc->plugin = plugin; - desc->data = data; - desc->perm = perm; - //because the uri-arg may live on the stack - desc->uri = strdup (uri); - } - return desc; -} - -R_API void r_io_desc_free(RIODesc* desc) { - if (desc) { - free (desc->uri); - free (desc->referer); - free (desc->name); - r_io_desc_cache_fini (desc); - if (desc->io && desc->io->files) { - r_id_storage_delete (desc->io->files, desc->fd); - } -// free (desc->plugin); - } - free (desc); -} - -R_API bool r_io_desc_add(RIO* io, RIODesc* desc) { - r_return_val_if_fail (io && desc && desc->io, false); - if (!r_id_storage_set (io->files, desc, desc->fd)) { - // TODO: use assert here - eprintf ("You are using this API incorrectly\n"); - eprintf ("fd %d was probably not generated by this RIO-instance\n", desc->fd); - r_sys_backtrace (); - return false; - } - return true; -} - -R_API bool r_io_desc_del(RIO* io, int fd) { //can we pass this a riodesc and check if it belongs to the desc->io ? - r_return_val_if_fail (io && io->files, false); - RIODesc* desc = r_id_storage_get (io->files, fd); - r_io_desc_free (desc); - if (desc == io->desc) { - io->desc = NULL; - } - // remove all dead maps - r_io_map_cleanup (io); - return true; -} - -R_API RIODesc* r_io_desc_get(RIO* io, int fd) { - r_return_val_if_fail (io && io->files, NULL); - return (RIODesc*) r_id_storage_get (io->files, fd); -} - -R_API RIODesc *r_io_desc_open(RIO *io, const char *uri, int perm, int mode) { - r_return_val_if_fail (io && uri, NULL); - RIOPlugin *plugin = r_io_plugin_resolve (io, uri, 0); - if (!plugin || !plugin->open) { - return NULL; - } - RIODesc *desc = plugin->open (io, uri, perm, mode); - if (!desc) { - return NULL; - } - // for none static callbacks, those that cannot use r_io_desc_new - if (!desc->name) { - desc->name = strdup (uri); - } - if (!desc->uri) { - desc->uri = strdup (uri); - } - if (!desc->plugin) { - desc->plugin = plugin; - } - if (!r_io_desc_add (io, desc)) { - r_io_desc_free (desc); - return NULL; - } - return desc; -} - -R_API RIODesc *r_io_desc_open_plugin(RIO *io, RIOPlugin *plugin, const char *uri, int perm, int mode) { - r_return_val_if_fail (io && io->files && uri, NULL); - if (!plugin || !plugin->open || !plugin->check || !plugin->check (io, uri, false)) { - return NULL; - } - RIODesc *desc = plugin->open (io, uri, perm, mode); - if (!desc) { - return NULL; - } - // for none static callbacks, those that cannot use r_io_desc_new - if (!desc->plugin) { - desc->plugin = plugin; - } - if (!desc->uri) { - desc->uri = strdup (uri); - } - if (!desc->name) { - desc->name = strdup (uri); - } - if (!r_io_desc_add (io, desc)) { - r_io_desc_free (desc); - return NULL; - } - return desc; -} - - -R_API bool r_io_desc_close(RIODesc *desc) { - RIO *io; - if (!desc || !desc->io || !desc->plugin) { - return false; - } - if (desc->plugin->close && desc->plugin->close (desc)) { - return false; - } - io = desc->io; - // remove entry from idstorage and free the desc-struct - r_io_desc_del (io, desc->fd); - // remove all dead maps - r_io_map_cleanup (io); - return true; -} - -//returns length of written bytes -R_API int r_io_desc_write(RIODesc *desc, const ut8* buf, int len) { - r_return_val_if_fail (desc && buf, -1); - if (len < 0) { - return -1; - } - //check pointers and pcache - if (desc->io && (desc->io->p_cache & 2)) { - return r_io_desc_cache_write (desc, - r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR), buf, len); - } - return r_io_plugin_write (desc, buf, len); -} - -// returns length of read bytes -R_API int r_io_desc_read(RIODesc *desc, ut8 *buf, int len) { - // check pointers and permissions - if (!buf || !desc || !desc->plugin || !(desc->perm & R_PERM_R)) { - return -1; - } - ut64 seek = r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); - if (desc->io->cachemode) { - if (seek != UT64_MAX && r_io_cache_at (desc->io, seek)) { - return r_io_cache_read (desc->io, seek, buf, len); - } - } - int ret = r_io_plugin_read (desc, buf, len); - if (ret > 0 && desc->io->cachemode) { - r_io_cache_write (desc->io, seek, buf, len); - } else if ((ret > 0) && desc->io && (desc->io->p_cache & 1)) { - ret = r_io_desc_cache_read (desc, seek, buf, ret); - } - return ret; -} - -R_API ut64 r_io_desc_seek(RIODesc* desc, ut64 offset, int whence) { - if (!desc || !desc->plugin || !desc->plugin->lseek) { - return (ut64) -1; - } - return desc->plugin->lseek (desc->io, desc, offset, whence); -} - -R_API ut64 r_io_desc_size(RIODesc* desc) { - if (!desc || !desc->plugin || !desc->plugin->lseek) { - return 0LL; - } - ut64 off = r_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); - ut64 ret = r_io_desc_seek (desc, 0LL, R_IO_SEEK_END); - // what to do if that seek fails? - r_io_desc_seek (desc, off, R_IO_SEEK_SET); - return ret; -} - -R_API bool r_io_desc_resize(RIODesc *desc, ut64 newsize) { - if (desc && desc->plugin && desc->plugin->resize) { - bool ret = desc->plugin->resize (desc->io, desc, newsize); - if (desc->io && desc->io->p_cache) { - r_io_desc_cache_cleanup (desc); - } - return ret; - } - return false; -} - -R_API bool r_io_desc_is_blockdevice(RIODesc *desc) { - if (!desc || !desc->plugin || !desc->plugin->is_blockdevice) { - return false; - } - return desc->plugin->is_blockdevice (desc); -} - -R_API bool r_io_desc_is_chardevice(RIODesc *desc) { - if (!desc || !desc->plugin || !desc->plugin->is_chardevice) { - return false; - } - return desc->plugin->is_chardevice (desc); -} - -R_API bool r_io_desc_exchange(RIO* io, int fd, int fdx) { - RIODesc* desc, * descx; - if (!(desc = r_io_desc_get (io, fd)) || !(descx = r_io_desc_get (io, fdx))) { - return false; - } - desc->fd = fdx; - descx->fd = fd; - r_id_storage_set (io->files, desc, fdx); - r_id_storage_set (io->files, descx, fd); - if (io->p_cache) { - Sdb* cache = desc->cache; - desc->cache = descx->cache; - descx->cache = cache; - r_io_desc_cache_cleanup (desc); - r_io_desc_cache_cleanup (descx); - } - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; - if (map->fd == fdx) { - map->perm &= (desc->perm | R_PERM_X); - } else if (map->fd == fd) { - map->perm &= (descx->perm | R_PERM_X); - } - } - return true; -} - -R_API bool r_io_desc_is_dbg(RIODesc *desc) { - if (desc && desc->plugin) { - return desc->plugin->isdbg; - } - return false; -} - -R_API int r_io_desc_get_pid(RIODesc *desc) { - //-1 and -2 are reserved - if (!desc) { - return -3; - } - if (!desc->plugin) { - return -4; - } - if (!desc->plugin->isdbg) { - return -5; - } - if (!desc->plugin->getpid) { - return -6; - } - return desc->plugin->getpid (desc); -} - -R_API int r_io_desc_get_tid(RIODesc *desc) { - //-1 and -2 are reserved - if (!desc) { - return -3; - } - if (!desc->plugin) { - return -4; - } - if (!desc->plugin->isdbg) { - return -5; - } - if (!desc->plugin->gettid) { - return -6; - } - return desc->plugin->gettid (desc); -} - -R_API bool r_io_desc_get_base (RIODesc *desc, ut64 *base) { - if (!base || !desc || !desc->plugin || !desc->plugin->isdbg || !desc->plugin->getbase) { - return false; - } - return desc->plugin->getbase (desc, base); -} - -R_API int r_io_desc_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len) { - if (desc && buf && (r_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { - return r_io_desc_read (desc, buf, len); - } - return 0; -} - -R_API int r_io_desc_write_at(RIODesc *desc, ut64 addr, const ut8 *buf, int len) { - if (desc && buf && (r_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { - return r_io_desc_write (desc, buf, len); - } - return 0; -} - -R_API int r_io_desc_extend(RIODesc *desc, ut64 size) { - if (desc && desc->plugin && desc->plugin->extend) { - return desc->plugin->extend (desc->io, desc, size); - } - return 0; -} - -/* lifecycle */ - -// TODO: move into io.c : r_io_init -R_IPI bool r_io_desc_init(RIO* io) { - r_return_val_if_fail (io, false); - r_io_desc_fini (io); - // TODO: it leaks if called twice - //fd is signed - io->files = r_id_storage_new (3, 0x80000000); - if (!io->files) { - return false; - } - return true; -} - -static bool desc_fini_cb(void* user, void* data, ut32 id) { - RIODesc* desc = (RIODesc*) data; - if (desc->plugin && desc->plugin->close) { - desc->plugin->close (desc); - } - r_io_desc_free (desc); - return true; -} - -//closes all descs and frees all descs and io->files -R_IPI bool r_io_desc_fini(RIO* io) { - r_return_val_if_fail (io, NULL); - if (io->files) { - r_id_storage_foreach (io->files, desc_fini_cb, io); - r_id_storage_free (io->files); - io->files = NULL; - } - //no map-cleanup here, to keep it modular useable - io->desc = NULL; - return true; -} diff --git a/libr/io/io_fd.c b/libr/io/io_fd.c deleted file mode 100644 index 6167b88e17..0000000000 --- a/libr/io/io_fd.c +++ /dev/null @@ -1,128 +0,0 @@ -/* radare2 - LGPL - Copyright 2017 - condret */ - -#include - -R_API int r_io_fd_open(RIO *io, const char *uri, int flags, int mode) { - RIODesc *desc = r_io_desc_open (io, uri, flags, mode); - return desc ? desc->fd : -1; -} - -R_API bool r_io_fd_close(RIO *io, int fd) { - return r_io_desc_close (r_io_desc_get (io, fd)); -} - -//returns length of read bytes -R_API int r_io_fd_read(RIO *io, int fd, ut8 *buf, int len) { - r_return_val_if_fail (io && buf, -1); - if (len < 0) { - return -1; - } - RIODesc *desc = r_io_desc_get (io, fd); - return desc? r_io_desc_read (desc, buf, len): -1; -} - -//returns length of written bytes -R_API int r_io_fd_write(RIO *io, int fd, const ut8 *buf, int len) { - r_return_val_if_fail (io && buf, -1); - if (len < 0) { - return -1; - } - RIODesc *desc = r_io_desc_get (io, fd); - return desc? r_io_desc_write (desc, buf, len): -1; -} - -R_API ut64 r_io_fd_seek(RIO *io, int fd, ut64 addr, int whence) { - if (!io) { - return (ut64)-2; - } - return r_io_desc_seek (r_io_desc_get (io, fd), addr, whence); -} - -R_API ut64 r_io_fd_size(RIO *io, int fd) { - return r_io_desc_size (r_io_desc_get (io, fd)); -} - -R_API bool r_io_fd_resize(RIO *io, int fd, ut64 newsize) { - return r_io_desc_resize (r_io_desc_get (io, fd), newsize); -} - -R_API bool r_io_fd_is_blockdevice(RIO *io, int fd) { - return r_io_desc_is_blockdevice (r_io_desc_get (io, fd)); -} - -R_API bool r_io_fd_is_chardevice(RIO *io, int fd) { - return r_io_desc_is_chardevice (r_io_desc_get (io, fd)); -} - -//returns length of read bytes -R_API int r_io_fd_read_at(RIO *io, int fd, ut64 addr, ut8 *buf, int len) { - RIODesc *desc; - if (!io || !buf || (len < 1) || !(desc = r_io_desc_get (io, fd))) { - return 0; - } - return r_io_desc_read_at (desc, addr, buf, len); -} - -//returns length of written bytes -R_API int r_io_fd_write_at(RIO *io, int fd, ut64 addr, const ut8 *buf, int len) { - r_return_val_if_fail (io && buf, false); - RIODesc *desc = r_io_desc_get (io, fd); - return desc? r_io_desc_write_at (desc, addr, buf, len): -1; -} - -R_API bool r_io_fd_is_dbg(RIO *io, int fd) { - r_return_val_if_fail (io && io->files, false); - RIODesc *desc = r_io_desc_get (io, fd); - return desc? r_io_desc_is_dbg (desc): false; -} - -R_API int r_io_fd_get_pid(RIO *io, int fd) { - if (!io || !io->files) { - return -2; - } - RIODesc *desc = r_io_desc_get (io, fd); - return r_io_desc_get_pid (desc); -} - -R_API int r_io_fd_get_tid(RIO *io, int fd) { - r_return_val_if_fail (io && io->files, -2); - RIODesc *desc = r_io_desc_get (io, fd); - return r_io_desc_get_tid (desc); -} - -R_API bool r_io_fd_get_base (RIO *io, int fd, ut64 *base) { - r_return_val_if_fail (io && io->files && base, false); - RIODesc *desc = r_io_desc_get (io, fd); - return r_io_desc_get_base (desc, base); -} - -R_API const char *r_io_fd_get_name(RIO *io, int fd) { - r_return_val_if_fail (io && io->files, NULL); - RIODesc *desc = r_io_desc_get (io, fd); - return desc? desc->name: NULL; -} - -R_API bool r_io_use_fd(RIO* io, int fd) { - r_return_val_if_fail (io, false); - if (!io->desc) { - io->desc = r_io_desc_get (io, fd); - return io->desc != NULL; - } - if (io->desc->fd != fd) { - RIODesc* desc; - //update io->desc if fd is not the same - if (!(desc = r_io_desc_get (io, fd))) { - return false; - } - io->desc = desc; - } - return true; -} - -R_API int r_io_fd_get_current(RIO *io) { - r_return_val_if_fail (io, -1); - if (io->desc) { - return io->desc->fd; - } - return -1; -} diff --git a/libr/io/io_map.c b/libr/io/io_map.c deleted file mode 100644 index 4bfd0a7df6..0000000000 --- a/libr/io/io_map.c +++ /dev/null @@ -1,480 +0,0 @@ -/* radare2 - LGPL - Copyright 2017-2019 - condret, MaskRay */ - -#include -#include -#include -#include "r_binheap.h" -#include "r_util.h" -#include "r_vector.h" - -#define END_OF_MAP_IDS UT32_MAX - -#define CMP_END_GTE(addr, itv) \ - (((addr) < r_itv_end (*(RInterval *)(itv))) ? -1 : 1) - -#define CMP_END_GTE_PART(addr, part) \ - (((addr) < (r_itv_end (((RIOMapSkyline *)(part))->itv)) || !r_itv_end (((RIOMapSkyline *)(part))->itv)) ? -1 : 1) - -#define CMP_BEGIN_GTE_PART(addr, part) \ - (((addr) > (r_itv_begin (((RIOMapSkyline *)(part))->itv))) - ((addr) < (r_itv_begin (((RIOMapSkyline *)(part))->itv)))) - -static bool add_map_to_skyline(RIO *io, RIOMap *map) { - size_t slot; - RPVector *skyline = &io->map_skyline; - - RIOMapSkyline *new_part = R_NEW (RIOMapSkyline); - new_part->map = map; - new_part->itv = map->itv; - const ut64 new_part_end = r_itv_end (new_part->itv); - - // `part` is the first RIOMapSkyline with part->itv.addr >= new_part->itv.addr - r_pvector_lower_bound (skyline, new_part->itv.addr, slot, CMP_BEGIN_GTE_PART); - RIOMapSkyline *part = slot < r_pvector_len (skyline) ? r_pvector_at (skyline, slot) : NULL; - if (slot) { - RIOMapSkyline *prev_part = r_pvector_at (skyline, slot - 1); - const ut64 prev_part_end = r_itv_end (prev_part->itv); - if (prev_part_end > r_itv_begin (new_part->itv)) { - if (prev_part_end > new_part_end) { - RIOMapSkyline *tail = R_NEW (RIOMapSkyline); - tail->map = prev_part->map; - tail->itv.addr = new_part_end; - tail->itv.size = prev_part_end - r_itv_begin (tail->itv); - if (slot < r_pvector_len (skyline)) { - r_pvector_insert (skyline, slot, tail); - } else { - r_pvector_push (skyline, tail); - } - } - prev_part->itv.size = r_itv_begin (new_part->itv) - r_itv_begin (prev_part->itv); - } - } - if (part) { - while (part && r_itv_include (new_part->itv, part->itv)) { - // Remove `part` that fits in `new_part` - r_pvector_remove_at (skyline, slot); - part = slot < r_pvector_len (skyline) ? r_pvector_at (skyline, slot) : NULL; - } - if (part && r_itv_overlap (new_part->itv, part->itv)) { - // Chop start of last `part` that intersects `new_part` - const ut64 oaddr = r_itv_begin (part->itv); - part->itv.addr = new_part_end; - part->itv.size -= r_itv_begin (part->itv) - oaddr; - } - } - if (slot < r_pvector_len (skyline)) { - r_pvector_insert (skyline, slot, new_part); - } else { - r_pvector_push (skyline, new_part); - } - return true; -} - -// Store map parts that are not covered by others into io->map_skyline -void io_map_calculate_skyline(RIO *io) { - r_pvector_clear (&io->map_skyline); - // Last map has highest priority (it shadows previous maps) - void **it; - r_pvector_foreach (&io->maps, it) { - add_map_to_skyline (io, (RIOMap *)*it); - } -} - -RIOMap* io_map_new(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { - if (!size || !io || !io->map_ids) { - return NULL; - } - RIOMap* map = R_NEW0 (RIOMap); - if (!map || !io->map_ids || !r_id_pool_grab_id (io->map_ids, &map->id)) { - free (map); - return NULL; - } - map->fd = fd; - map->delta = delta; - if ((UT64_MAX - size + 1) < addr) { - /// XXX: this is leaking a map!!! - io_map_new (io, fd, perm, delta - addr, 0LL, size + addr); - size = -(st64)addr; - } - // RIOMap describes an interval of addresses (map->from; map->to) - map->itv = (RInterval){ addr, size }; - map->perm = perm; - map->delta = delta; - // new map lives on the top, being top the list's tail - r_pvector_push (&io->maps, map); - add_map_to_skyline (io, map); - return map; -} - -R_API RIOMap *r_io_map_new(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { - return io_map_new (io, fd, perm, delta, addr, size); -} - -R_API bool r_io_map_remap(RIO *io, ut32 id, ut64 addr) { - RIOMap *map = r_io_map_resolve (io, id); - if (map) { - ut64 size = map->itv.size; - map->itv.addr = addr; - if (UT64_MAX - size + 1 < addr) { - map->itv.size = -addr; - r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, size + addr); - } - io_map_calculate_skyline (io); - return true; - } - return false; -} - -R_API bool r_io_map_remap_fd(RIO *io, int fd, ut64 addr) { - RIOMap *map; - bool retval = false; - RList *maps = r_io_map_get_for_fd (io, fd); - if (maps) { - map = r_list_get_n (maps, 0); - if (map) { - retval = r_io_map_remap (io, map->id, addr); - } - r_list_free (maps); - } - return retval; -} - -static void _map_free(void* p) { - RIOMap* map = (RIOMap*) p; - if (map) { - free (map->name); - free (map); - } -} - -R_API void r_io_map_init(RIO* io) { - r_return_if_fail (io); - r_pvector_init (&io->maps, _map_free); - if (io->map_ids) { - r_id_pool_free (io->map_ids); - } - io->map_ids = r_id_pool_new (1, END_OF_MAP_IDS); -} - -// check if a map with exact the same properties exists -R_API bool r_io_map_exists(RIO *io, RIOMap *map) { - r_return_val_if_fail (io && map, false); - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *m = *it; - if (!memcmp (m, map, sizeof (RIOMap))) { - return true; - } - } - return false; -} - -// check if a map with specified id exists -R_API bool r_io_map_exists_for_id(RIO* io, ut32 id) { - return r_io_map_resolve (io, id) != NULL; -} - -R_API RIOMap* r_io_map_resolve(RIO *io, ut32 id) { - r_return_val_if_fail (io && id, false); - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; - if (map->id == id) { - return map; - } - } - return NULL; -} - -RIOMap* io_map_add(RIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { - //check if desc exists - RIODesc* desc = r_io_desc_get (io, fd); - if (desc) { - //a map cannot have higher permissions than the desc belonging to it - return io_map_new (io, fd, (perm & desc->perm) | (perm & R_PERM_X), - delta, addr, size); - } - return NULL; -} - -R_API RIOMap *r_io_map_add(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { - return io_map_add (io, fd, perm, delta, addr, size); -} - -R_API RIOMap *r_io_map_add_batch(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { - return io_map_add (io, fd, perm, delta, addr, size); -} - -R_API void r_io_update(RIO *io) { - io_map_calculate_skyline (io); -} - -R_API RIOMap* r_io_map_get_paddr(RIO* io, ut64 paddr) { - r_return_val_if_fail (io, NULL); - void **it; - r_pvector_foreach_prev (&io->maps, it) { - RIOMap *map = *it; - if (map->delta <= paddr && paddr <= map->delta + map->itv.size - 1) { - return map; - } - } - return NULL; -} - -// gets first map where addr fits in -R_API RIOMap *r_io_map_get(RIO* io, ut64 addr) { - r_return_val_if_fail (io, NULL); - const RPVector *skyline = &io->map_skyline; - size_t i, len = r_pvector_len (skyline); - r_pvector_lower_bound (skyline, addr, i, CMP_END_GTE_PART); - if (i == len) { - return NULL; - } - const RIOMapSkyline *sky = r_pvector_at (skyline, i); - return sky->itv.addr <= addr ? sky->map : NULL; -} - -R_API bool r_io_map_is_mapped(RIO* io, ut64 addr) { - r_return_val_if_fail (io, false); - return (bool)r_io_map_get (io, addr); -} - -R_API void r_io_map_reset(RIO* io) { - r_io_map_fini (io); - r_io_map_init (io); - io_map_calculate_skyline (io); -} - -R_API bool r_io_map_del(RIO *io, ut32 id) { - r_return_val_if_fail (io, false); - size_t i; - for (i = 0; i < r_pvector_len (&io->maps); i++) { - RIOMap *map = r_pvector_at (&io->maps, i); - if (map->id == id) { - r_pvector_remove_at (&io->maps, i); - _map_free (map); - r_id_pool_kick_id (io->map_ids, id); - io_map_calculate_skyline (io); - return true; - } - } - return false; -} - -//delete all maps with specified fd -R_API bool r_io_map_del_for_fd(RIO* io, int fd) { - r_return_val_if_fail (io, false); - bool ret = false; - size_t i; - for (i = 0; i < r_pvector_len (&io->maps);) { - RIOMap *map = r_pvector_at (&io->maps, i); - if (!map) { - r_pvector_remove_at (&io->maps, i); - } else if (map->fd == fd) { - r_id_pool_kick_id (io->map_ids, map->id); - //delete iter and map - r_pvector_remove_at (&io->maps, i); - _map_free (map); - ret = true; - } else { - i++; - } - } - if (ret) { - io_map_calculate_skyline (io); - } - return ret; -} - -//brings map with specified id to the tail of of the list -//return a boolean denoting whether is was possible to priorized -R_API bool r_io_map_priorize(RIO* io, ut32 id) { - r_return_val_if_fail (io, false); - size_t i; - for (i = 0; i < r_pvector_len (&io->maps); i++) { - RIOMap *map = r_pvector_at (&io->maps, i); - // search for iter with the correct map - if (map->id == id) { - r_pvector_remove_at (&io->maps, i); - r_pvector_push (&io->maps, map); - io_map_calculate_skyline (io); - return true; - } - } - return false; -} - -R_API bool r_io_map_depriorize(RIO* io, ut32 id) { - r_return_val_if_fail (io, false); - size_t i; - for (i = 0; i < r_pvector_len (&io->maps); i++) { - RIOMap *map = r_pvector_at (&io->maps, i); - // search for iter with the correct map - if (map->id == id) { - r_pvector_remove_at (&io->maps, i); - r_pvector_push_front (&io->maps, map); - io_map_calculate_skyline (io); - return true; - } - } - return false; -} - -R_API bool r_io_map_priorize_for_fd(RIO *io, int fd) { - r_return_val_if_fail (io, false); - //we need a clean list for this, or this becomes a segfault-field - r_io_map_cleanup (io); - RPVector temp; - r_pvector_init (&temp, NULL); - size_t i; - for (i = 0; i < r_pvector_len (&io->maps);) { - RIOMap *map = r_pvector_at (&io->maps, i); - if (map->fd == fd) { - r_pvector_push (&temp, map); - r_pvector_remove_at (&io->maps, i); - continue; - } - i++; - } - r_pvector_insert_range (&io->maps, r_pvector_len (&io->maps), temp.v.a, r_pvector_len (&temp)); - r_pvector_clear (&temp); - io_map_calculate_skyline (io); - return true; -} - -//may fix some inconsistencies in io->maps -R_API void r_io_map_cleanup(RIO* io) { - r_return_if_fail (io); - //remove all maps if no descs exist - if (!io->files) { - r_io_map_fini (io); - r_io_map_init (io); - return; - } - bool del = false; - size_t i; - for (i = 0; i < r_pvector_len (&io->maps);) { - RIOMap *map = r_pvector_at (&io->maps, i); - if (!map) { - // remove iter if the map is a null-ptr, this may fix some segfaults. This should never happen. - r_warn_if_reached (); - r_pvector_remove_at (&io->maps, i); - del = true; - } else if (!r_io_desc_get (io, map->fd)) { - //delete map and iter if no desc exists for map->fd in io->files - r_id_pool_kick_id (io->map_ids, map->id); - map = r_pvector_remove_at (&io->maps, i); - _map_free (map); - del = true; - } else { - i++; - } - } - if (del) { - io_map_calculate_skyline (io); - } -} - -R_API void r_io_map_fini(RIO* io) { - r_return_if_fail (io); - r_pvector_clear (&io->maps); - r_id_pool_free (io->map_ids); - io->map_ids = NULL; - r_pvector_clear (&io->map_skyline); -} - -R_API void r_io_map_set_name(RIOMap* map, const char* name) { - if (!map || !name) { - return; - } - free (map->name); - map->name = strdup (name); -} - -R_API void r_io_map_del_name(RIOMap* map) { - if (map) { - R_FREE (map->name); - } -} - -// TODO: very similar to r_io_map_next_address, decide which one to use -R_API ut64 r_io_map_next_available(RIO* io, ut64 addr, ut64 size, ut64 load_align) { - if (load_align == 0) { - load_align = 1; - } - ut64 next_addr = addr, - end_addr = next_addr + size; - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; - ut64 to = r_itv_end (map->itv); - next_addr = R_MAX (next_addr, to + (load_align - (to % load_align)) % load_align); - // XXX - This does not handle when file overflow 0xFFFFFFFF000 -> 0x00000FFF - // adding the check for the map's fd to see if this removes contention for - // memory mapping with multiple files. infinite loop ahead? - if ((map->itv.addr <= next_addr && next_addr < to) || r_itv_contain (map->itv, end_addr)) { - next_addr = to + (load_align - (to % load_align)) % load_align; - return r_io_map_next_available (io, next_addr, size, load_align); - } - break; - } - return next_addr; -} - -// TODO: very similar to r_io_map_next_available. decide which one to use -R_API ut64 r_io_map_next_address(RIO* io, ut64 addr) { - ut64 lowest = UT64_MAX; - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; - ut64 from = r_itv_begin (map->itv); - if (from > addr && addr < lowest) { - lowest = from; - } - ut64 to = r_itv_end (map->itv); - if (to > addr && to < lowest) { - lowest = to; - } - } - return lowest; -} - -R_API RList* r_io_map_get_for_fd(RIO* io, int fd) { - RList* map_list = r_list_newf (NULL); - if (!map_list) { - return NULL; - } - void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; - if (map && map->fd == fd) { - r_list_append (map_list, map); - } - } - return map_list; -} - -R_API bool r_io_map_resize(RIO *io, ut32 id, ut64 newsize) { - RIOMap *map; - if (!newsize || !(map = r_io_map_resolve (io, id))) { - return false; - } - ut64 addr = map->itv.addr; - if (UT64_MAX - newsize + 1 < addr) { - map->itv.size = -addr; - r_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, newsize + addr); - return true; - } - map->itv.size = newsize; - io_map_calculate_skyline (io); - return true; -} - -// find a location that can hold enough bytes without overlapping -// XXX this function is buggy and doesnt works as expected, but i need it for a PoC for now -R_API ut64 r_io_map_location(RIO *io, ut64 size) { - ut64 base = (io->bits == 64)? 0x60000000000LL: 0x60000000; - while (r_io_map_get (io, base)) { - base += 0x200000; - } - return base; -} diff --git a/libr/io/io_private.h b/libr/io/io_private.h deleted file mode 100644 index 95f6ca9320..0000000000 --- a/libr/io/io_private.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _IO_PRIVATE_H_ -#define _IO_PRIVATE_H_ - -RIOMap *io_map_new(RIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size); -RIOMap *io_map_add(RIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline); -void io_map_calculate_skyline(RIO *io); - -#endif diff --git a/libr/io/p/io_default.c b/libr/io/p/io_default.c deleted file mode 100644 index a6d9268686..0000000000 --- a/libr/io/p/io_default.c +++ /dev/null @@ -1,343 +0,0 @@ -/* radare - LGPL - Copyright 2008-2020 - pancake */ - -#include -#include -#include -#include - -typedef struct r_io_mmo_t { - char * filename; - int mode; - int perm; - int fd; - int opened; - bool nocache; - ut8 modified; - RBuffer *buf; - RIO * io_backref; - bool rawio; -} RIOMMapFileObj; - -static int __io_posix_open(const char *file, int perm, int mode) { - int fd; - if (r_str_startswith (file, "file://")) { - file += strlen ("file://"); - } - if (r_file_is_directory (file)) { - return -1; - } -#if __WINDOWS__ - // probably unnecessary to have this ifdef nowadays windows is posix enough - if (perm & R_PERM_W) { - fd = r_sandbox_open (file, O_RDWR, 0); - if (fd == -1 && (perm & R_PERM_CREAT)) { - r_sandbox_creat (file, 0644); - fd = r_sandbox_open (file, O_RDWR | O_CREAT, 0); - } - } else { - fd = r_sandbox_open (file, O_RDONLY | O_BINARY, 0); - } -#else - const size_t posixFlags = (perm & R_PERM_W) ? (perm & R_PERM_CREAT) - ? (O_RDWR | O_CREAT) : O_RDWR : O_RDONLY; - fd = r_sandbox_open (file, posixFlags, mode); -#endif - return fd; -} - -static ut64 r_io_def_mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int whence) { - if (!mmo) { - return UT64_MAX; - } - if (mmo->rawio) { - io->off = lseek (mmo->fd, offset, whence); - return io->off; - } - if (!mmo->buf) { - return UT64_MAX; - } - io->off = r_buf_seek (mmo->buf, offset, whence); - return io->off; -} - -static int r_io_def_mmap_refresh_def_mmap_buf(RIOMMapFileObj *mmo) { - RIO* io = mmo->io_backref; - ut64 cur; - if (mmo->buf) { - cur = r_buf_tell (mmo->buf); - r_buf_free (mmo->buf); - mmo->buf = NULL; - } else { - cur = 0; - } - st64 sz = r_file_size (mmo->filename); - if (sz > ST32_MAX) { - // Do not use mmap if the file is huge - mmo->rawio = true; - } - if (mmo->rawio) { - mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode); - if (mmo->nocache) { -#ifdef F_NOCACHE - fcntl (mmo->fd, F_NOCACHE, 1); -#endif - } - return mmo->fd != -1; - } - mmo->buf = r_buf_new_mmap (mmo->filename, mmo->perm); - if (mmo->buf) { - r_io_def_mmap_seek (io, mmo, cur, SEEK_SET); - return true; - } else { - mmo->rawio = true; - mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode); - if (mmo->nocache) { -#ifdef F_NOCACHE - fcntl (mmo->fd, F_NOCACHE, 1); -#endif - } - return mmo->fd != -1; - } - return false; -} - -static void r_io_def_mmap_free (RIOMMapFileObj *mmo) { - if (mmo) { - free (mmo->filename); - r_buf_free (mmo->buf); - close (mmo->fd); - free (mmo); - } -} - -RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO *io, const char *filename, int perm, int mode) { - r_return_val_if_fail (io && filename, NULL); - RIOMMapFileObj *mmo = R_NEW0 (RIOMMapFileObj); - if (!mmo) { - return NULL; - } - if (r_str_startswith (filename, "file://")) { - filename += strlen ("file://"); - } - mmo->nocache = r_str_startswith (filename, "nocache://"); - if (mmo->nocache) { - filename += strlen ("nocache://"); - } - mmo->filename = strdup (filename); - mmo->perm = perm; - mmo->mode = mode; - mmo->io_backref = io; - const int posixFlags = (perm & R_PERM_W) - ?( - (perm & R_PERM_CREAT) - ? (O_RDWR | O_CREAT) - : O_RDWR - ): O_RDONLY; - mmo->fd = r_sandbox_open (filename, posixFlags, mode); - if (mmo->fd == -1) { - free (mmo->filename); - free (mmo); - return NULL; - } - if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) { - mmo->rawio = true; - if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) { - r_io_def_mmap_free (mmo); - mmo = NULL; - } - } - return mmo; -} - -static int r_io_def_mmap_close(RIODesc *fd) { - r_return_val_if_fail (fd && fd->data, -1); - r_io_def_mmap_free ((RIOMMapFileObj *) fd->data); - fd->data = NULL; - return 0; -} - -static bool r_io_def_mmap_check_default (const char *filename) { - r_return_val_if_fail (filename && *filename, false); - if (r_str_startswith (filename, "file://")) { - filename += strlen ("file://"); - } - const char * peekaboo = (!strncmp (filename, "nocache://", 10)) - ? NULL : strstr (filename, "://"); - return (!peekaboo || (peekaboo - filename) > 10); -} - -static int r_io_def_mmap_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - r_return_val_if_fail (fd && fd->data && buf, -1); - if (io->off == UT64_MAX) { - memset (buf, 0xff, count); - return count; - } - // TODO : unbox magic - RIOMMapFileObj *mmo = fd->data; - if (!mmo) { - return -1; - } - if (mmo->rawio) { - if (lseek (mmo->fd, io->off, SEEK_SET) < 0) { - return -1; - } - return read (mmo->fd, buf, count); - } - if (r_buf_size (mmo->buf) < io->off) { - io->off = r_buf_size (mmo->buf); - } - int r = r_buf_read_at (mmo->buf, io->off, buf, count); - if (r < 0) { - return r; - } - r_buf_seek (mmo->buf, r, R_BUF_CUR); - io->off += r; - return r; -} - -static int r_io_def_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - r_return_val_if_fail (io && fd && fd->data && buf, -1); - - int len = -1; - ut64 addr = io->off; - RIOMMapFileObj *mmo = fd->data; - if (mmo->rawio) { - if (lseek (mmo->fd, addr, 0) < 0) { - return -1; - } - len = write (mmo->fd, buf, count); - return len; - } - - if (mmo && mmo->buf) { - if (!(mmo->perm & R_PERM_W)) { - return -1; - } - if ( (count + addr > r_buf_size (mmo->buf)) || r_buf_size (mmo->buf) == 0) { - ut64 sz = count + addr; - r_file_truncate (mmo->filename, sz); - } - } - - len = r_file_mmap_write (mmo->filename, io->off, buf, count); - if (len != count) { - // aim to hack some corner cases? - if (lseek (fd->fd, addr, 0) < 0) { - return -1; - } - len = write (fd->fd, buf, count); - } - if (!r_io_def_mmap_refresh_def_mmap_buf (mmo) ) { - eprintf ("io_def_mmap: failed to refresh the def_mmap backed buffer.\n"); - // XXX - not sure what needs to be done here (error handling). - } - return len; -} - -static RIODesc *r_io_def_mmap_open(RIO *io, const char *file, int perm, int mode) { - r_return_val_if_fail (io && file, NULL); - RIOMMapFileObj *mmo = r_io_def_mmap_create_new_file (io, file, perm, mode); - if (!mmo) { - return NULL; - } - RIODesc *d = r_io_desc_new (io, &r_io_plugin_default, mmo->filename, perm, mode, mmo); - if (!d->name) { - d->name = strdup (file); - } - if (r_str_startswith (d->name, "file://")) { - char *oldname = d->name; - d->name = strdup (oldname + strlen ("file://")); - free (oldname); - } - return d; -} - -static ut64 r_io_def_mmap_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - r_return_val_if_fail (fd && fd->data, UT64_MAX); - return r_io_def_mmap_seek (io, (RIOMMapFileObj *)fd->data, offset, whence); -} - -static int r_io_def_mmap_truncate(RIOMMapFileObj *mmo, ut64 size) { - bool res = r_file_truncate (mmo->filename, size); - if (res && !r_io_def_mmap_refresh_def_mmap_buf (mmo) ) { - eprintf ("r_io_def_mmap_truncate: Error trying to refresh the def_mmap'ed file."); - res = false; - } else if (!res) { - eprintf ("r_io_def_mmap_truncate: Error trying to resize the file."); - } - return res; -} - -static bool __plugin_open_default(RIO *io, const char *file, bool many) { - return r_io_def_mmap_check_default (file); -} - -// default open should permit opening -static RIODesc *__open_default(RIO *io, const char *file, int perm, int mode) { - if (r_io_def_mmap_check_default (file)) { - return r_io_def_mmap_open (io, file, perm, mode); - } - return NULL; -} - -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { - return r_io_def_mmap_read (io, fd, buf, len); -} - -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { - return r_io_def_mmap_write(io, fd, buf, len); -} - -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - return r_io_def_mmap_lseek (io, fd, offset, whence); -} - -static int __close(RIODesc *fd) { - return r_io_def_mmap_close (fd); -} - -static bool __resize(RIO *io, RIODesc *fd, ut64 size) { - r_return_val_if_fail (io && fd && fd->data, false); - RIOMMapFileObj *mmo = fd->data; - if (!(mmo->perm & R_PERM_W)) { - return false; - } - return r_io_def_mmap_truncate (mmo, size); -} - -#if __UNIX__ -static bool __is_blockdevice (RIODesc *desc) { - r_return_val_if_fail (desc && desc->data, false); - RIOMMapFileObj *mmo = desc->data; - struct stat buf; - if (fstat (mmo->fd, &buf) == -1) { - return false; - } - return ((buf.st_mode & S_IFBLK) == S_IFBLK); -} -#endif - -RIOPlugin r_io_plugin_default = { - .name = "default", - .desc = "Open local files", - .license = "LGPL3", - .uris = "file://,nocache://", - .open = __open_default, - .close = __close, - .read = __read, - .check = __plugin_open_default, - .lseek = __lseek, - .write = __write, - .resize = __resize, -#if __UNIX__ - .is_blockdevice = __is_blockdevice, -#endif -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_default, - .version = R2_VERSION -}; -#endif diff --git a/libr/io/p/io_mmap.c b/libr/io/p/io_mmap.c deleted file mode 100644 index 8d9b82ad92..0000000000 --- a/libr/io/p/io_mmap.c +++ /dev/null @@ -1,216 +0,0 @@ -/* radare - LGPL - Copyright 2013-2016 - pancake */ - -#include -#include -#include - -typedef struct r_io_mmo_t { - char * filename; - int mode; - int flags; - int fd; - int opened; - ut8 modified; - RBuffer *buf; - RIO * io_backref; -} RIOMMapFileObj; - -static ut64 r_io_mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int whence) { - ut64 seek_val = r_buf_tell (mmo->buf); - switch (whence) { - case SEEK_SET: - seek_val = (r_buf_size (mmo->buf) < offset)? r_buf_size (mmo->buf): offset; - r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); - return seek_val; - case SEEK_CUR: - seek_val = (r_buf_size (mmo->buf) < (offset + r_buf_tell (mmo->buf)))? r_buf_size (mmo->buf): offset + r_buf_tell (mmo->buf); - r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); - return seek_val; - case SEEK_END: - seek_val = r_buf_size (mmo->buf); - r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); - return seek_val; - } - return seek_val; -} - -static bool r_io_mmap_refresh_buf(RIOMMapFileObj *mmo) { - RIO* io = mmo->io_backref; - ut64 cur = mmo->buf? r_buf_tell (mmo->buf): 0; - if (mmo->buf) { - r_buf_free (mmo->buf); - mmo->buf = NULL; - } - mmo->buf = r_buf_new_mmap (mmo->filename, mmo->flags); - if (mmo->buf) { - r_io_mmap_seek (io, mmo, cur, SEEK_SET); - } - return mmo->buf != NULL; -} - -static void r_io_mmap_free(RIOMMapFileObj *mmo) { - free (mmo->filename); - r_buf_free (mmo->buf); - memset (mmo, 0, sizeof (RIOMMapFileObj)); - free (mmo); -} - -RIOMMapFileObj *r_io_mmap_create_new_file(RIO *io, const char *filename, int mode, int flags) { - RIOMMapFileObj *mmo; - if (!io) { - return NULL; - } - mmo = R_NEW0 (RIOMMapFileObj); - if (!mmo) { - return NULL; - } - mmo->filename = strdup (filename); - mmo->fd = r_num_rand (0xFFFF); // XXX: Use r_io_fd api - mmo->mode = mode; - mmo->flags = flags; - mmo->io_backref = io; - if (!r_io_mmap_refresh_buf (mmo)) { - r_io_mmap_free (mmo); - mmo = NULL; - } - return mmo; -} - -static int r_io_mmap_close(RIODesc *fd) { - if (!fd || !fd->data) { - return -1; - } - r_io_mmap_free ((RIOMMapFileObj *) fd->data); - fd->data = NULL; - return 0; -} - -static int r_io_mmap_check (const char *filename) { - return (filename && !strncmp (filename, "mmap://", 7) && *(filename + 7)); -} - -static int r_io_mmap_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - RIOMMapFileObj *mmo = NULL; - if (!fd || !fd->data || !buf) { - return -1; - } - mmo = fd->data; - if (r_buf_size (mmo->buf) < io->off) { - io->off = r_buf_size (mmo->buf); - } - int r = r_buf_read_at (mmo->buf, io->off, buf, count); - if (r >= 0) { - r_buf_seek (mmo->buf, r, R_BUF_CUR); - } - return r; -} - -static int r_io_mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - RIOMMapFileObj *mmo; - int len = count; - ut64 addr; - - if (!io || !fd || !fd->data || !buf) { - return -1; - } - mmo = fd->data; - addr = io->off; - if ( !(mmo->flags & R_PERM_W)) { - return -1; - } - if ( (count + addr > r_buf_size (mmo->buf)) || r_buf_size (mmo->buf) == 0) { - ut64 sz = count + addr; - r_file_truncate (mmo->filename, sz); - } - len = r_file_mmap_write (mmo->filename, io->off, buf, len); - if (!r_io_mmap_refresh_buf (mmo) ) { - eprintf ("io_mmap: failed to refresh the mmap backed buffer.\n"); - // XXX - not sure what needs to be done here (error handling). - } - return len; -} - -static RIODesc *r_io_mmap_open(RIO *io, const char *file, int flags, int mode) { - if (!strncmp (file, "mmap://", 7)) { - file += 7; - } - RIOMMapFileObj *mmo = r_io_mmap_create_new_file (io, file, mode, flags); - return mmo? r_io_desc_new (io, &r_io_plugin_mmap, mmo->filename, flags, mode, mmo): NULL; -} - -static ut64 r_io_mmap_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - RIOMMapFileObj *mmo; - if (!fd || !fd->data) { - return -1; - } - mmo = fd->data; - return r_io_mmap_seek (io, mmo, offset, whence); -} - -static bool r_io_mmap_truncate(RIOMMapFileObj *mmo, ut64 size) { - int res = r_file_truncate (mmo->filename, size); - if (res && !r_io_mmap_refresh_buf (mmo)) { - eprintf ("r_io_mmap_truncate: Error trying to refresh the mmap'ed file."); - res = false; - } else if (res) { - eprintf ("r_io_mmap_truncate: Error trying to resize the file."); - } - return res; -} - - -static bool __plugin_open(RIO *io, const char *file, bool many) { - return r_io_mmap_check (file); -} - -static RIODesc *__open(RIO *io, const char *file, int flags, int mode) { - if (!r_io_mmap_check (file)) { - return NULL; - } - return r_io_mmap_open (io, file, flags, mode); -} - -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { - return r_io_mmap_read (io, fd, buf, len); -} - -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { - return r_io_mmap_write(io, fd, buf, len); -} - -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - return r_io_mmap_lseek (io, fd, offset, whence); -} - -static int __close(RIODesc *fd) { - return r_io_mmap_close (fd); -} - -static bool __resize(RIO *io, RIODesc *fd, ut64 size) { - if (!fd || !fd->data) { - return false; - } - return r_io_mmap_truncate ((RIOMMapFileObj*)fd->data, size); -} - -struct r_io_plugin_t r_io_plugin_mmap = { - .name = "mmap", - .desc = "Open files using mmap", - .uris = "mmap://", - .license = "LGPL3", - .open = __open, - .close = __close, - .read = __read, - .check = __plugin_open, - .lseek = __lseek, - .write = __write, - .resize = __resize, -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_mmap, - .version = R2_VERSION -}; -#endif diff --git a/libr/io/p/io_r2k.c b/libr/io/p/io_r2k.c deleted file mode 100644 index 422230daf9..0000000000 --- a/libr/io/p/io_r2k.c +++ /dev/null @@ -1,156 +0,0 @@ -/* io_r2k - radare2 - LGPL - Copyright 2016-2018 - SkUaTeR + panda */ - -#include -#include -#include -#include -#include - -#if __WINDOWS__ -#include "io_r2k_windows.h" -#elif defined (__linux__) && !defined (__GNU__) -#include "io_r2k_linux.h" -struct io_r2k_linux r2k_struct; //TODO: move this into desc->data -#endif - -int r2k__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { -#if __WINDOWS__ - //eprintf("writing to: 0x%"PFMT64x" len: %x\n",io->off, count); - return WriteKernelMemory (io->off, buf, count); -#elif defined (__linux__) && !defined (__GNU__) - switch (r2k_struct.beid) { - case 0: - return WriteMemory (io, fd, IOCTL_WRITE_KERNEL_MEMORY, r2k_struct.pid, io->off, buf, count); - case 1: - return WriteMemory (io, fd, IOCTL_WRITE_PROCESS_ADDR, r2k_struct.pid, io->off, buf, count); - case 2: - return WriteMemory (io, fd, IOCTL_WRITE_PHYSICAL_ADDR, r2k_struct.pid, io->off, buf, count); - default: - io->cb_printf ("ERROR: Undefined beid in r2k__write.\n"); - return -1; - } -#else - io->cb_printf ("TODO: r2k not implemented for this plataform.\n"); - return -1; -#endif -} - -static int r2k__read(RIO *io, RIODesc *fd, ut8 *buf, int count) { -#if __WINDOWS__ - return ReadKernelMemory (io->off, buf, count); -#elif defined (__linux__) && !defined (__GNU__) - switch (r2k_struct.beid) { - case 0: - return ReadMemory (io, fd, IOCTL_READ_KERNEL_MEMORY, r2k_struct.pid, io->off, buf, count); - case 1: - return ReadMemory (io, fd, IOCTL_READ_PROCESS_ADDR, r2k_struct.pid, io->off, buf, count); - case 2: - return ReadMemory (io, fd, IOCTL_READ_PHYSICAL_ADDR, r2k_struct.pid, io->off, buf, count); - default: - io->cb_printf ("ERROR: Undefined beid in r2k__read.\n"); - memset (buf, 0xff, count); - return count; - } -#else - io->cb_printf ("TODO: r2k not implemented for this plataform.\n"); - memset (buf, 0xff, count); - return count; -#endif -} - -static int r2k__close(RIODesc *fd) { -#if __WINDOWS__ - if (gHandleDriver) { - CloseHandle (gHandleDriver); - StartStopService (TEXT ("r2k"),TRUE); - } -#elif defined (__linux__) && !defined (__GNU__) - if (fd) { - close ((int)(size_t)fd->data); - } -#else - eprintf ("TODO: r2k not implemented for this plataform.\n"); -#endif - return 0; -} - -static ut64 r2k__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - return (!whence) ? offset : whence == 1 - ? io->off + offset : UT64_MAX; -} - -static bool r2k__plugin_open(RIO *io, const char *pathname, bool many) { - return (!strncmp (pathname, "r2k://", 6)); -} - -static char *r2k__system(RIO *io, RIODesc *fd, const char *cmd) { - if (!strcmp (cmd, "")) { - return NULL; - } - if (!strncmp (cmd, "mod", 3)) { -#if __WINDOWS__ - GetSystemModules (io); -#endif - } else { -#if defined (__linux__) && !defined (__GNU__) - (void)run_ioctl_command (io, fd, cmd); - return NULL; -#else - eprintf ("Try: '=!mod'\n '.=!mod'\n"); -#endif - } - return NULL; -} - -static RIODesc *r2k__open(RIO *io, const char *pathname, int rw, int mode) { - if (!strncmp (pathname, "r2k://", 6)) { - rw |= R_PERM_WX; -#if __WINDOWS__ - RIOW32 *w32 = R_NEW0 (RIOW32); - if (Init (&pathname[6]) == FALSE) { - eprintf ("r2k__open: Error cant init driver: %s\n", &pathname[6]); - free (w32); - return NULL; - } - //return r_io_desc_new (&r_io_plugin_r2k, -1, pathname, rw, mode, w32); - return r_io_desc_new (io, &r_io_plugin_r2k, pathname, rw, mode, w32); -#elif defined (__linux__) && !defined (__GNU__) - int fd = open ("/dev/r2k", O_RDONLY); - if (fd == -1) { - io->cb_printf ("r2k__open: Error in opening /dev/r2k."); - return NULL; - } - - r2k_struct.beid = 0; - r2k_struct.pid = 0; - r2k_struct.wp = 1; - return r_io_desc_new (io, &r_io_plugin_r2k, pathname, rw, mode, (void *)(size_t)fd); -#else - io->cb_printf ("Not supported on this platform\n"); -#endif - } - return NULL; -} - -RIOPlugin r_io_plugin_r2k = { - .name = "r2k", - .desc = "Kernel access API io", - .uris = "r2k://", - .license = "LGPL3", - .open = r2k__open, - .close = r2k__close, - .read = r2k__read, - .check = r2k__plugin_open, - .lseek = r2k__lseek, - .system = r2k__system, - .write = r2k__write, -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_r2k, - .version = R2_VERSION -}; -#endif - diff --git a/libr/io/p/io_rbuf.c b/libr/io/p/io_rbuf.c deleted file mode 100644 index a913885264..0000000000 --- a/libr/io/p/io_rbuf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* radare2 - LGPL - Copyright 2017 - pancake, condret */ - -#include "r_io.h" -#include "r_lib.h" -#include -#include -#include -#include - -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - if (!fd || !buf || count < 0 || !fd->data) { - return -1; - } - RBuffer *b = fd->data; - return r_buf_write (b, buf, count); -} - -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - RBuffer *b = fd->data; - return r_buf_read (b, buf, count); -} - -static int __close(RIODesc *fd) { - RBuffer *b = fd->data; - r_buf_free (b); - return 0; -} - -static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) { - RBuffer *buf = fd->data; - return r_buf_seek (buf, offset, whence); -} - -static bool __check(RIO *io, const char *pathname, bool many) { - return (!strncmp (pathname, "rbuf://", 7)); -} - -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { - RIODesc *desc; - RBuffer *buf = r_buf_new (); - if (buf && (desc = r_io_desc_new (io, &r_io_plugin_rbuf, pathname, 7, 0, buf))) { - return desc; - } - r_buf_free (buf); - return NULL; -} - -RIOPlugin r_io_plugin_rbuf = { - .name = "rbuf", - .desc = "RBuffer IO plugin", - .uris = "rbuf://", - .license = "LGPL", - .open = __open, - .close = __close, - .read = __read, - .lseek = __lseek, - .write = __write, - .check = __check -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_rbuf, - .version = R2_VERSION -}; -#endif diff --git a/libr/io/p/io_sparse.c b/libr/io/p/io_sparse.c deleted file mode 100644 index 37211f77f5..0000000000 --- a/libr/io/p/io_sparse.c +++ /dev/null @@ -1,129 +0,0 @@ -/* radare - LGPL - Copyright 2015-2016 - pancake */ - -#include "r_io.h" -#include "r_lib.h" -#include "r_util.h" -#include -#include -#include - -typedef struct { - int fd; - RBuffer *buf; - ut64 offset; -} RIOSparse; - -#define RIOSPARSE_FD(x) (((RIOSparse*)(x)->data)->fd) -#define RIOSPARSE_BUF(x) (((RIOSparse*)(x)->data)->buf) -#define RIOSPARSE_OFF(x) (((RIOSparse*)(x)->data)->offset) - -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - ut64 o; - RBuffer *b; - if (!fd || !fd->data) { - return -1; - } - b = RIOSPARSE_BUF(fd); - o = RIOSPARSE_OFF(fd); - int r = r_buf_write_at (b, o, buf, count); - if (r >= 0) { - r_buf_seek (b, r, R_BUF_CUR); - } - return r; -} - -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - ut64 o; - RBuffer *b; - if (!fd || !fd->data) { - return -1; - } - b = RIOSPARSE_BUF(fd); - o = RIOSPARSE_OFF(fd); - int r = r_buf_read_at (b, o, buf, count); - if (r >= 0) { - r_buf_seek (b, count, R_BUF_CUR); - } - return count; -} - -static int __close(RIODesc *fd) { - RIOSparse *riom; - if (!fd || !fd->data) { - return -1; - } - riom = fd->data; - R_FREE (riom->buf); - R_FREE (fd->data); - return 0; -} - -static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) { - RBuffer *b; - ut64 r_offset = offset; - if (!fd->data) { - return offset; - } - b = RIOSPARSE_BUF(fd); - r_offset = r_buf_seek (b, offset, whence); - //if (r_offset != UT64_MAX) - RIOSPARSE_OFF (fd) = r_offset; - return r_offset; -} - -static bool __plugin_open(struct r_io_t *io, const char *pathname, bool many) { - return (!strncmp (pathname, "sparse://", 9)); -} - -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { - if (__plugin_open (io, pathname,0)) { - RIOSparse *mal = R_NEW0 (RIOSparse); - int size = (int)r_num_math (NULL, pathname + 9); - mal->buf = r_buf_new_sparse (io->Oxff); - if (!mal->buf) { - free (mal); - return NULL; - } - if (size > 0) { - ut8 *data = malloc (size); - if (!data) { - eprintf ("Cannot allocate (%s) %d byte(s)\n", - pathname+9, size); - mal->offset = 0; - } else { - memset (data, 0x00, size); - r_buf_write_at (mal->buf, 0, data, size); - free (data); - } - } - if (mal->buf) { - return r_io_desc_new (io, &r_io_plugin_sparse, - pathname, rw, mode, mal); - } - r_buf_free (mal->buf); - free (mal); - } - return NULL; -} - -RIOPlugin r_io_plugin_sparse = { - .name = "sparse", - .desc = "Sparse buffer allocation plugin", - .uris = "sparse://", - .license = "LGPL3", - .open = __open, - .close = __close, - .read = __read, - .check = __plugin_open, - .lseek = __lseek, - .write = __write, - .resize = NULL, -}; - -#ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_sparse, - .version = R2_VERSION -}; -#endif diff --git a/libr/io/p/r2k.mk b/libr/io/p/r2k.mk deleted file mode 100644 index 7d2bd378f8..0000000000 --- a/libr/io/p/r2k.mk +++ /dev/null @@ -1,22 +0,0 @@ -OBJ_R2K = io_r2k.o -ifeq ($(OSTYPE),$(filter $(OSTYPE),gnulinux android)) -OBJ_R2K += io_r2k_linux.o -endif -ifeq (${OSTYPE},$(filter $(OSTYPE),windows mingw32 mingw64 cygwin)) -OBJ_R2K += io_r2k_windows.o -endif - -STATIC_OBJ+=${OBJ_R2K} -TARGET_R2K=io_r2k.${EXT_SO} -ALL_TARGETS+=${TARGET_R2K} - -ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a -else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io -endif - -${TARGET_R2K}: ${OBJ_R2K} - ${CC} $(call libname,io_r2k) ${CFLAGS} -o ${TARGET_R2K} ${OBJ_R2K} ${LINKFLAGS} diff --git a/libr/io/p/r2pipe.mk b/libr/io/p/r2pipe.mk deleted file mode 100644 index bd660950bf..0000000000 --- a/libr/io/p/r2pipe.mk +++ /dev/null @@ -1,19 +0,0 @@ -OBJ_R2PIPE=io_r2pipe.o - -STATIC_OBJ+=${OBJ_R2PIPE} -TARGET_R2PIPE=io_r2pipe.${EXT_SO} -ALL_TARGETS+=${TARGET_R2PIPE} - -ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a -LINKFLAGS+=../../io/libr_socket.a -else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../socket -lr_socket -LINKFLAGS+=-L.. -lr_io -endif - -${TARGET_R2PIPE}: ${OBJ_R2PIPE} - ${CC_LIB} $(call libname,io_r2pipe) ${CFLAGS} \ - -o ${TARGET_R2PIPE} ${OBJ_R2PIPE} ${LINKFLAGS} diff --git a/libr/io/p/r2web.mk b/libr/io/p/r2web.mk deleted file mode 100644 index ac64210b0d..0000000000 --- a/libr/io/p/r2web.mk +++ /dev/null @@ -1,18 +0,0 @@ -OBJ_R2WEB=io_r2web.o - -STATIC_OBJ+=${OBJ_R2WEB} -TARGET_R2WEB=io_r2web.${EXT_SO} -ALL_TARGETS+=${TARGET_R2WEB} - -ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a -LINKFLAGS+=../../io/libr_socket.a -else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../socket -lr_socket -LINKFLAGS+=-L.. -lr_io -endif - -${TARGET_R2WEB}: ${OBJ_R2WEB} - ${CC_LIB} $(call libname,io_r2web) ${CFLAGS} -o ${TARGET_R2WEB} ${OBJ_R2WEB} ${LINKFLAGS} diff --git a/libr/io/p/rap.mk b/libr/io/p/rap.mk deleted file mode 100644 index 99262a25fe..0000000000 --- a/libr/io/p/rap.mk +++ /dev/null @@ -1,13 +0,0 @@ -OBJ_RAP=io_rap.o - -STATIC_OBJ+=${OBJ_RAP} -TARGET_RAP=io_rap.${EXT_SO} -ALL_TARGETS+=${TARGET_RAP} - -${TARGET_RAP}: ${OBJ_RAP} - ${CC} ${CFLAGS} -o ${TARGET_RAP} ${OBJ_RAP} \ - $(call libname,io_rap) \ - ${LDFLAGS_LINKPATH}../../socket -L../../socket -lr_socket \ - ${LDFLAGS_LINKPATH}../../util -L../../util -lr_util \ - ${LDFLAGS_LINKPATH}../../cons -L../../cons -lr_cons \ - ${LDFLAGS_LINKPATH}.. -L.. -lr_io diff --git a/libr/io/p/winkd.mk b/libr/io/p/winkd.mk deleted file mode 100644 index a848f83872..0000000000 --- a/libr/io/p/winkd.mk +++ /dev/null @@ -1,27 +0,0 @@ -OBJ_WINKD=io_winkd.o - -STATIC_OBJ+=${OBJ_WINKD} -TARGET_WINKD=io_winkd.${EXT_SO} -ALL_TARGETS+=${TARGET_WINKD} - -LIB_PATH=$(SHLR)/winkd -CFLAGS+=-I$(SHLR)/winkd -LDFLAGS+=$(SHLR)/winkd/libr_winkd.$(EXT_AR) - -ifeq (${WITHPIC},0) -LINKFLAGS=../../util/libr_util.a -LINKFLAGS+= ../../util/libr_socket.a -LINKFLAGS+= ../../util/libr_hash.a -LINKFLAGS+=../../util/libr_crypto.a -LINKFLAGS+=../../io/libr_io.a -else -LINKFLAGS=-L../../util -lr_util -LINKFLAGS+=-L../../socket -lr_socket -LINKFLAGS+=-L../../hash -lr_hash -LINKFLAGS+=-L../../crypto -lr_crypto -LINKFLAGS+=-L.. -lr_io -endif - -${TARGET_WINKD}: ${OBJ_WINKD} - ${CC} $(call libname,io_winkd) ${OBJ_WINKD} ${CFLAGS} \ - ${LINKFLAGS} ${LDFLAGS_LIB} $(LDFLAGS) diff --git a/libr/lang/p/lib.c b/libr/lang/p/lib.c deleted file mode 100644 index 1646c7b440..0000000000 --- a/libr/lang/p/lib.c +++ /dev/null @@ -1,52 +0,0 @@ -/* radare - LPGL - Copyright 2017 condret */ - -#include -#include -#include - -static int lang_lib_init (RLang *user) { - return true; -} - -static int lang_lib_file_run (RLang *user, const char *file) { - char *libpath; - void *lib; - if (!(libpath = r_str_new (file))) { - return -1; - } - if (!r_str_startswith (libpath, "/") && !r_str_startswith (libpath, "./")) { - libpath = r_str_prepend (libpath, "./"); - } - if (!r_file_exists (libpath)) { - if (!r_str_endswith (libpath, R_LIB_EXT)) { - libpath = r_str_appendf (libpath, ".%s", R_LIB_EXT); - } - } - if (!r_file_exists (libpath)) { - free (libpath); - return -1; - } - - lib = r_lib_dl_open (libpath); - if (lib) { - void (*fcn)(RCore *); - fcn = r_lib_dl_sym (lib, "entry"); - if (fcn) { - fcn (user->user); - } else { - eprintf ("Cannot find 'entry' symbol in library\n"); - } - r_lib_dl_close (lib); - } - free (libpath); - return 0; -} - -static RLangPlugin r_lang_plugin_lib = { - .name = "lib", - .ext = R_LIB_EXT, - .desc = "Load libs directly into r2", - .license = "LGPL", - .init = lang_lib_init, - .run_file = lang_lib_file_run, -}; diff --git a/libr/lang/p/spp.c b/libr/lang/p/spp.c deleted file mode 100644 index c59bcfbc84..0000000000 --- a/libr/lang/p/spp.c +++ /dev/null @@ -1,51 +0,0 @@ -/* radare - LGPL - Copyright 2020 pancake */ - -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" -#define USE_R2 1 - -static RLang *Glang = NULL; -#include -#include "spp_r2.inc" - -static int lang_spp_init(RLang *l) { - Glang = l; - return true; -} - -static int lang_spp_run(RLang *lang, const char *code, int len) { - Output out; - out.fout = NULL; - out.cout = r_strbuf_new (NULL); - r_strbuf_init (out.cout); - spp_proc_set (&spp_r2_proc, NULL, 0); - char *c = strdup (code); - spp_eval (c, &out); - free (c); - char *data = r_strbuf_drain (out.cout); - r_cons_printf ("%s\n", data); - free (data); - return true; -} - -static int lang_spp_file(RLang *lang, const char *file) { - size_t len; - char *code = r_file_slurp (file, &len); - if (code) { - int res = lang_spp_run (lang, code, len); - free (code); - return res; - } - return 0; -} - -static RLangPlugin r_lang_plugin_spp = { - .name = "spp", - .ext = "spp", - .license = "MIT", - .desc = "SPP template programs", - .run = lang_spp_run, - .init = (void*)lang_spp_init, - .run_file = (void*)lang_spp_file, -}; diff --git a/libr/main/Makefile b/libr/main/Makefile deleted file mode 100644 index ddef711fc5..0000000000 --- a/libr/main/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include ../config.mk - -NAME=r_main - -OBJS+=main.o -OBJS+=rax2.o -OBJS+=rasm2.o -OBJS+=ragg2.o -OBJS+=rarun2.o -OBJS+=rabin2.o -OBJS+=rasign2.o -OBJS+=rafind2.o -OBJS+=r2agent.o -OBJS+=radiff2.o -OBJS+=radare2.o -OBJS+=rahash2.o - -# See MAIN_LINK_ALL -include deps.mk - -include ../rules.mk diff --git a/libr/main/deps.mk b/libr/main/deps.mk deleted file mode 100644 index 17a57f3689..0000000000 --- a/libr/main/deps.mk +++ /dev/null @@ -1,11 +0,0 @@ -MAIN_LINK_ALL=1 - -ifeq ($(MAIN_LINK_ALL),1) -R2DEPS=r_config r_cons r_io r_util r_flag r_asm r_core -R2DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_bp r_egg -R2DEPS+=r_reg r_search r_syscall r_socket r_fs r_magic r_crypto -else -# only works -WITH_LIBS=0 -WITH_LIBR=1 -endif diff --git a/libr/main/main.c b/libr/main/main.c deleted file mode 100644 index 9e35569b67..0000000000 --- a/libr/main/main.c +++ /dev/null @@ -1,53 +0,0 @@ -/* radare - LGPL - Copyright 2012-2020 - pancake */ - -#include -#include -#include -#include - -R_LIB_VERSION(r_main); - -static RMain foo[] = { - { "r2", r_main_radare2 }, - { "rax2", r_main_rax2 }, - { "radiff2", r_main_radiff2 }, - { "rafind2", r_main_rafind2 }, - { "rarun2", r_main_rarun2 }, - { "rasm2", r_main_rasm2 }, - { "ragg2", r_main_ragg2 }, - { "rabin2", r_main_rabin2 }, - { "radare2", r_main_radare2 }, - { NULL, NULL } -}; - -R_API RMain *r_main_new (const char *name) { - int i = 0; - while (foo[i].name) { - if (!strcmp (name, foo[i].name)) { - RMain *m = R_NEW0 (RMain); - if (m) { - m->name = strdup (foo[i].name); - m->main = foo[i].main; - } - return m; - } - i++; - } - return NULL; -} - -R_API void r_main_free(RMain *m) { - free (m); -} - -R_API int r_main_run(RMain *m, int argc, const char **argv) { - r_return_val_if_fail (m && m->main, -1); - return m->main (argc, argv); -} - -R_API int r_main_version_print(const char *progname) { - char *s = r_str_version (progname); - printf ("%s\n", s); - free (s); - return 0; -} diff --git a/libr/main/meson.build b/libr/main/meson.build deleted file mode 100644 index f061b8361d..0000000000 --- a/libr/main/meson.build +++ /dev/null @@ -1,68 +0,0 @@ -r_main_sources = [ - 'main.c', - 'r2agent.c', - 'rabin2.c', - 'radare2.c', - 'radiff2.c', - 'rafind2.c', - 'ragg2.c', - 'rahash2.c', - 'rarun2.c', - 'rasign2.c', - 'rasm2.c', - 'rax2.c' -] - -r_main_deps = [ - r_config_dep, - r_cons_dep, - r_io_dep, - r_util_dep, - r_flag_dep, - r_asm_dep, - r_core_dep, - r_debug_dep, - r_hash_dep, - r_bin_dep, - r_lang_dep, - r_io_dep, - r_anal_dep, - r_parse_dep, - r_bp_dep, - r_egg_dep, - r_reg_dep, - r_search_dep, - r_syscall_dep, - r_socket_dep, - r_fs_dep, - r_magic_dep, - r_crypto_dep -] - -r_main = library('r_main', r_main_sources, - include_directories: [platform_inc], - c_args: library_cflags, - dependencies: r_main_deps, - install: true, - implicit_include_directories: false, - install_rpath: rpath_lib, - soversion: r2_libversion -) - -r_main_dep = declare_dependency(link_with: r_main, - include_directories: [platform_inc], - dependencies: r_main_deps) - -pkgconfig_mod.generate(r_main, - subdirs: 'libr', - version: r2_version, - name: 'r_main', - libraries: pkgcfg_sanitize_libs, - filebase: 'r_main', - requires: [ - 'r_core', - 'r_asm', - 'r_syscall' - ], - description: 'radare foundation libraries' -) diff --git a/libr/socket/socket_rap_server.c b/libr/socket/socket_rap_server.c deleted file mode 100644 index f0179aecc2..0000000000 --- a/libr/socket/socket_rap_server.c +++ /dev/null @@ -1,140 +0,0 @@ -/* radare - LGPL - Copyright 2014-2019 - pancake, condret */ - -#include -#include - -R_API RSocketRapServer *r_socket_rap_server_new(bool use_ssl, const char *port) { - r_return_val_if_fail (port, NULL); - RSocketRapServer *s = R_NEW0 (RSocketRapServer); - if (s) { - s->port = strdup (port); - s->fd = r_socket_new (use_ssl); - if (s->fd) { - return s; - } - r_socket_free (s->fd); - free (s); - } - return NULL; -} - -R_API RSocketRapServer *r_socket_rap_server_create(const char *pathname) { - r_return_val_if_fail (pathname, NULL); - if (strlen (pathname) < 11) { - return NULL; - } - if (strncmp (pathname, "rap", 3)) { - return NULL; - } - bool is_ssl = (pathname[3] == 's'); - const char *port = &pathname[7 + is_ssl]; - return r_socket_rap_server_new (is_ssl, port); -} - -R_API void r_socket_rap_server_free(RSocketRapServer *s) { - if (s) { - r_socket_free (s->fd); - free (s); - } -} - -R_API bool r_socket_rap_server_listen(RSocketRapServer *s, const char *certfile) { - r_return_val_if_fail (s && s->port && *s->port, false); - return r_socket_listen (s->fd, s->port, certfile); -} - -R_API RSocket* r_socket_rap_server_accept(RSocketRapServer *s) { - r_return_val_if_fail (s && s->fd, NULL); - return r_socket_accept (s->fd); -} - -R_API bool r_socket_rap_server_continue(RSocketRapServer *s) { - r_return_val_if_fail (s && s->fd, false); - - int i; - char *ptr = NULL; - - if (!r_socket_is_connected (s->fd)) { - return false; - } - r_socket_read_block (s->fd, s->buf, 1); - switch (s->buf[0]) { - case RAP_PACKET_OPEN: - r_socket_read_block (s->fd, &s->buf[1], 2); - r_socket_read_block (s->fd, &s->buf[3], (int)s->buf[2]); - { - int fd = s->open (s->user, (const char *)&s->buf[3], (int)s->buf[1], 0); - s->buf[0] = RAP_PACKET_OPEN | RAP_PACKET_REPLY; - eprintf ("REPLY BACK %d\n", fd); - r_write_be32 (s->buf + 1, fd); - } - r_socket_write (s->fd, s->buf, 5); - r_socket_flush (s->fd); - break; - case RAP_PACKET_READ: - r_socket_read_block (s->fd, &s->buf[1], 4); - i = r_read_be32 (&s->buf[1]); - if (i > RAP_PACKET_MAX || i < 0) { - i = RAP_PACKET_MAX; - } - s->read (s->user, &s->buf[5], i); - s->buf[0] = RAP_PACKET_READ | RAP_PACKET_REPLY; - r_socket_write (s->fd, s->buf, i + 5); - r_socket_flush (s->fd); - break; - case RAP_PACKET_WRITE: - r_socket_read_block (s->fd, s->buf + 1, 4); - i = r_read_be32 (s->buf + 1); - if (i > RAP_PACKET_MAX || i < 0) { - i = RAP_PACKET_MAX; - } - r_socket_read_block (s->fd, s->buf + 5, i); - r_write_be32 (s->buf + 1, s->write (s->user, s->buf + 5, i)); - s->buf[0] = RAP_PACKET_WRITE | RAP_PACKET_REPLY; - r_socket_write (s->fd, s->buf, 5); - r_socket_flush (s->fd); - break; - case RAP_PACKET_SEEK: - { - r_socket_read_block (s->fd, &s->buf[1], 9); - int whence = s->buf[0]; - ut64 offset = r_read_be64 (s->buf + 1); - offset = s->seek (s->user, offset, whence); - /* prepare reply */ - s->buf[0] = RAP_PACKET_SEEK | RAP_PACKET_REPLY; - r_write_be64 (s->buf + 1, offset); - r_socket_write (s->fd, s->buf, 9); - r_socket_flush (s->fd); - } - break; - case RAP_PACKET_CMD: - r_socket_read_block (s->fd, &s->buf[1], 4); - i = r_read_be32 (&s->buf[1]); - if (r_socket_read_block (s->fd, &s->buf[5], i) > 0) { - ptr = s->cmd (s->user, (const char *)s->buf + 5); - i = (ptr)? strlen (ptr) + 1: 0; - r_write_be32 (&s->buf[1], i); - s->buf[0] = RAP_PACKET_CMD | RAP_PACKET_REPLY; - r_socket_write (s->fd, s->buf, 5); - if (i) { - r_socket_write (s->fd, ptr, i); - } - r_socket_flush (s->fd); - R_FREE (ptr); - } - break; - case RAP_PACKET_CLOSE: - r_socket_read_block (s->fd, &s->buf[1], 4); - i = r_read_be32 (&s->buf[1]); - s->close (s->user, i); - s->buf[0] = RAP_PACKET_CLOSE | RAP_PACKET_REPLY; - r_socket_write (s->fd, s->buf, 5); - r_socket_flush (s->fd); - break; - default: - eprintf ("unknown command 0x%02x\n", (ut8)(s->buf[0] & 0xff)); - r_socket_close (s->fd); - return false; - } - return true; -} diff --git a/libr/util/alloc.c b/libr/util/alloc.c deleted file mode 100644 index 00699e974d..0000000000 --- a/libr/util/alloc.c +++ /dev/null @@ -1,74 +0,0 @@ -/* radare - LGPL - Copyright 2019-2020 - pancake */ - -#include -#include - -R_API void r_alloc_init (void) { -#if R_MALLOC_WRAPPER - r_alloc_hooks (malloc, calloc, realloc, free); -#endif -} - -#if R_MALLOC_WRAPPER - -#if R_MALLOC_GLOBAL -R_API RMalloc *r_malloc = malloc; -R_API RCalloc *r_calloc = calloc; -R_API RRealloc *r_realloc = realloc; -R_API RFree *r_free = free; - -R_API void r_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f) { - r_return_if_fail (m && c && r && f); - r_malloc = m; - r_calloc = c; - r_realloc = r; - r_free = f; -} - -#else - -static RMalloc *_r_malloc = malloc; -static RCalloc *_r_calloc = calloc; -static RRealloc *_r_realloc = realloc; -static RFree *_r_free = free; - -R_API void r_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f) { - r_return_if_fail (m && c && r && f); - _r_malloc = m; - _r_calloc = c; - _r_realloc = r; - _r_free = f; -} - -R_API void *r_malloc(size_t sz) { - return _r_malloc (sz); -} - -R_API void *r_calloc(size_t count, size_t sz) { - return _r_calloc (count, sz); -} - -R_API void *r_realloc(void *p, size_t sz) { - return _r_realloc (p, sz); -} - -R_API void r_free(void *p) { - return _r_free (p); -} -#endif -#endif - -R_API void* r_malloc_aligned(size_t size, size_t alignment) { - int offset = alignment - 1 + sizeof (void*); - void* p1 = _r_malloc (size + offset); - if (!p1) { - return NULL; - } - void **p2 = (void**)(((size_t)(p1) + offset) & ~(alignment - 1)); - p2[-1] = p1; - return p2; -} - -R_API void r_free_aligned(void *p) { - _r_free (((void**)p)[-1]); -} diff --git a/libr/util/big-gmp.c b/libr/util/big-gmp.c deleted file mode 100644 index d8b64bc740..0000000000 --- a/libr/util/big-gmp.c +++ /dev/null @@ -1,136 +0,0 @@ -#include - -R_API RNumBig *r_big_new(void) { - RNumBig *n = R_NEW (RNumBig); - if (n) { - mpz_init (*n); - } - return n; -} - -R_API void r_big_free(RNumBig *b) { - mpz_clear (*b); - free (b); -} - -R_API void r_big_init(RNumBig *b) { - mpz_init (*b); -} - -R_API void r_big_fini(RNumBig *b) { - mpz_clear (*b); -} - -R_API void r_big_from_int(RNumBig *b, st64 v) { - mpz_set_si (*b, v); -} - -R_API st64 r_big_to_int(RNumBig *b) { - return mpz_get_si (*b); -} - -R_API void r_big_from_hexstr(RNumBig *b, const char *str) { - if (r_str_startswith (str, "0x")) { - str += 2; - mpz_set_str (*b, str, 16); - } else if (r_str_startswith (str, "-0x")) { - str += 3; - mpz_set_str (*b, str, 16); - mpz_mul_si (*b, *b, -1); - } -} - -R_API char *r_big_to_hexstr(RNumBig *b) { - char *tmp = mpz_get_str (NULL, 16, *b); - char *res; - if (tmp[0] == '-') { - res = r_str_newf ("-0x%s", &tmp[1]); - } else { - res = r_str_newf ("0x%s", tmp); - } - free (tmp); - return res; -} - -R_API void r_big_assign(RNumBig *dst, RNumBig *src) { - mpz_set (*dst, *src); -} - -R_API void r_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_add (*c, *a, *b); -} - -R_API void r_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_sub (*c, *a, *b); -} - -R_API void r_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_mul (*c, *a, *b); -} - -R_API void r_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_tdiv_q (*c, *a, *b); -} - -R_API void r_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_mod (*c, *a, *b); -} - -R_API void r_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { - mpz_tdiv_qr (*c, *d, *a, *b); -} - -R_API void r_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_and (*c, *a, *b); -} - -R_API void r_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_ior (*c, *a, *b); -} - -R_API void r_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { - mpz_xor (*c, *a, *b); -} - -R_API void r_big_lshift(RNumBig *c, RNumBig *a, size_t nbits) { - mpz_mul_2exp (*c, *a, nbits); -} - -R_API void r_big_rshift(RNumBig *c, RNumBig *a, size_t nbits) { - mpz_tdiv_q_2exp (*c, *a, nbits); -} - -R_API int r_big_cmp(RNumBig *a, RNumBig *b) { - int res = mpz_cmp (*a, *b); - if (res > 0) { - return 1; - } else if (res < 0) { - return -1; - } else { - return 0; - } -} - -R_API int r_big_is_zero(RNumBig *a) { - return mpz_cmp_ui (*a, 0) == 0; -} - -R_API void r_big_inc(RNumBig *a) { - RNumBig tmp; - mpz_init_set_si (tmp, 1); - mpz_add (*a, *a, tmp); -} - -R_API void r_big_dec(RNumBig *a) { - RNumBig tmp; - mpz_init_set_si (tmp, 1); - mpz_sub (*a, *a, tmp); -} - -R_API void r_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { - mpz_powm (*c, *a, *b, *m); -} - -R_API void r_big_isqrt(RNumBig *c, RNumBig *a) { - mpz_sqrt (*c, *a); -} diff --git a/libr/util/big-ssl.c b/libr/util/big-ssl.c deleted file mode 100644 index 114b4f60b8..0000000000 --- a/libr/util/big-ssl.c +++ /dev/null @@ -1,257 +0,0 @@ -#include - -R_API RNumBig *r_big_new(void) { - return BN_new (); -} - -R_API void r_big_free(RNumBig *b) { - BN_free (b); -} - -R_API void r_big_init(RNumBig *b) { - BN_zero (b); -} - -R_API void r_big_fini(RNumBig *b) { - BN_clear (b); -} - -R_API void r_big_from_int(RNumBig *b, st64 v) { - if (v < 0) { - BN_set_word (b, -v); - BN_set_negative (b, v); - } else { - BN_set_word (b, v); - } -} - -R_API st64 r_big_to_int(RNumBig *b) { - BN_ULONG maxx = 0; - maxx = ~maxx; - BN_ULONG res = BN_get_word (b); - if (res == maxx) { - RNumBig *B = r_big_new (); - r_big_assign (B, b); - BN_mask_bits (B, BN_BYTES * 8 - 1); - res = BN_get_word (B); - r_big_free (B); - } - res *= (BN_is_negative (b)? -1: 1); - return res; -} - -R_API void r_big_from_hexstr(RNumBig *b, const char *str) { - if (r_str_startswith (str, "0x")) { - str += 2; - BN_hex2bn (&b, str); - } else if (r_str_startswith (str, "-0x")) { - str += 3; - BN_hex2bn (&b, str); - BN_set_negative (b, -1); - } -} - -R_API char *r_big_to_hexstr(RNumBig *b) { - char *tmp = BN_bn2hex (b); - char *res; - if (tmp[0] == '-') { - res = r_str_newf ("-0x%s", &tmp[1]); - } else { - res = r_str_newf ("0x%s", tmp); - } - OPENSSL_free (tmp); - for (size_t i = 0; res[i]; i++) { - res[i] = tolower (res[i]); - } - return res; -} - -R_API void r_big_assign(RNumBig *dst, RNumBig *src) { - BN_copy (dst, src); -} - -R_API void r_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { - BN_add (c, a, b); -} - -R_API void r_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { - BN_sub (c, a, b); -} - -R_API void r_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { - BN_CTX *bn_ctx = BN_CTX_new (); - BN_mul (c, a, b, bn_ctx); - BN_CTX_free (bn_ctx); -} - -R_API void r_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { - BN_CTX *bn_ctx = BN_CTX_new (); - BN_div (c, NULL, a, b, bn_ctx); - BN_CTX_free (bn_ctx); -} - -R_API void r_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { - BN_CTX *bn_ctx = BN_CTX_new (); - BN_mod (c, a, b, bn_ctx); - BN_CTX_free (bn_ctx); -} - -R_API void r_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { - BN_CTX *bn_ctx = BN_CTX_new (); - BN_div (c, d, a, b, bn_ctx); - BN_CTX_free (bn_ctx); -} - -R_API void r_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { - RNumBig *A = r_big_new (); - RNumBig *B = r_big_new (); - RNumBig *C = r_big_new (); - RNumBig *addition = r_big_new (); - - size_t step = 4 * 8, move = 0; - ut32 tmp = 0; - r_big_assign (A, a); - r_big_assign (B, b); - - while (!r_big_is_zero (A) || !r_big_is_zero (B)) { - tmp = r_big_to_int (A); - tmp &= r_big_to_int (B); - r_big_rshift (A, A, step); - r_big_rshift (B, B, step); - r_big_from_int (addition, tmp); - r_big_lshift (addition, addition, move); - r_big_add (C, C, addition); - - move += step; - } - - r_big_assign (c, C); - - r_big_free (A); - r_big_free (B); - r_big_free (C); - r_big_free (addition); -} - -R_API void r_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { - RNumBig *A = r_big_new (); - RNumBig *B = r_big_new (); - RNumBig *C = r_big_new (); - RNumBig *addition = r_big_new (); - - size_t step = 4 * 8, move = 0; - ut32 tmp = 0; - r_big_assign (A, a); - r_big_assign (B, b); - - while (!r_big_is_zero (A) || !r_big_is_zero (B)) { - tmp = r_big_to_int (A); - tmp |= r_big_to_int (B); - r_big_rshift (A, A, step); - r_big_rshift (B, B, step); - r_big_from_int (addition, tmp); - r_big_lshift (addition, addition, move); - r_big_add (C, C, addition); - - move += step; - } - - r_big_assign (c, C); - - r_big_free (A); - r_big_free (B); - r_big_free (C); - r_big_free (addition); -} - -R_API void r_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { - RNumBig *A = r_big_new (); - RNumBig *B = r_big_new (); - RNumBig *C = r_big_new (); - RNumBig *addition = r_big_new (); - - size_t step = 4 * 8, move = 0; - ut32 tmp = 0; - r_big_assign (A, a); - r_big_assign (B, b); - - while (!r_big_is_zero (A) || !r_big_is_zero (B)) { - tmp = r_big_to_int (A); - tmp ^= r_big_to_int (B); - r_big_rshift (A, A, step); - r_big_rshift (B, B, step); - r_big_from_int (addition, tmp); - r_big_lshift (addition, addition, move); - r_big_add (C, C, addition); - - move += step; - } - - r_big_assign (c, C); - - r_big_free (A); - r_big_free (B); - r_big_free (C); - r_big_free (addition); -} - -R_API void r_big_lshift(RNumBig *c, RNumBig *a, size_t nbits) { - BN_lshift (c, a, nbits); -} - -R_API void r_big_rshift(RNumBig *c, RNumBig *a, size_t nbits) { - BN_rshift (c, a, nbits); -} - -R_API int r_big_cmp(RNumBig *a, RNumBig *b) { - return BN_cmp (a, b); -} - -R_API int r_big_is_zero(RNumBig *a) { - return BN_is_zero (a); -} - -R_API void r_big_inc(RNumBig *a) { - BN_add_word (a, 1); -} - -R_API void r_big_dec(RNumBig *a) { - BN_sub_word (a, 1); -} - -R_API void r_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { - BN_CTX *bn_ctx = BN_CTX_new (); - BN_mod_exp (c, a, b, m, bn_ctx); - BN_CTX_free (bn_ctx); -} - -R_API void r_big_isqrt(RNumBig *b, RNumBig *a) { - RNumBig *tmp = r_big_new (); - RNumBig *low = r_big_new (); - RNumBig *high = r_big_new (); - RNumBig *mid = r_big_new (); - - r_big_assign (high, a); - r_big_rshift (mid, high, 1); - r_big_inc (mid); - - while (r_big_cmp (high, low) > 0) { - r_big_mul (tmp, mid, mid); - if (r_big_cmp (tmp, a) > 0) { - r_big_assign (high, mid); - r_big_dec (high); - } else { - r_big_assign (low, mid); - } - r_big_sub (mid, high, low); - r_big_rshift (mid, mid, 1); - r_big_add (mid, mid, low); - r_big_inc (mid); - } - r_big_assign (b, low); - - r_big_free (tmp); - r_big_free (low); - r_big_free (high); - r_big_free (mid); -} diff --git a/libr/util/binheap.c b/libr/util/binheap.c deleted file mode 100644 index ed3af94f8d..0000000000 --- a/libr/util/binheap.c +++ /dev/null @@ -1,65 +0,0 @@ -/* radare2 - LGPL - Copyright 2017-2018 - maskray */ - -#include "r_binheap.h" - -static inline void _heap_down(RBinHeap *h, size_t i, void *x) { - size_t j; - for (; j = i * 2 + 1, j < h->a.v.len; i = j) { - if (j + 1 < h->a.v.len && h->cmp (r_pvector_at (&h->a, j+1), r_pvector_at (&h->a, j)) < 0) { - j++; - } - if (h->cmp (r_pvector_at (&h->a, j), x) >= 0) { - break; - } - r_pvector_set (&h->a, i, r_pvector_at (&h->a, j)); - } - if (i < h->a.v.len) { - r_pvector_set (&h->a, i, x); - } -} - -static inline void _heap_up(RBinHeap *h, size_t i, void *x) { - size_t j; - for (; i && (j = (i-1) >> 1, h->cmp (x, r_pvector_at (&h->a, j)) < 0); i = j) { - r_pvector_set (&h->a, i, r_pvector_at (&h->a, j)); - } - r_pvector_set (&h->a, i, x); -} - -R_API void r_binheap_clear(RBinHeap *h) { - r_pvector_clear (&h->a); -} - -R_API void r_binheap_init(RBinHeap *h, RPVectorComparator cmp) { - r_pvector_init (&h->a, NULL); - h->cmp = cmp; -} - -R_API void r_binheap_free(RBinHeap *h) { - r_binheap_clear (h); - free (h); -} - -R_API RBinHeap *r_binheap_new(RPVectorComparator cmp) { - RBinHeap *h = R_NEW (RBinHeap); - if (!h) { - return NULL; - } - r_pvector_init (&h->a, NULL); - h->cmp = cmp; - return h; -} - -R_API void *r_binheap_pop(RBinHeap *h) { - void *ret = r_pvector_at (&h->a, 0); - _heap_down (h, 0, r_pvector_pop (&h->a)); - return ret; -} - -R_API bool r_binheap_push(RBinHeap *h, void *x) { - if (!r_pvector_push (&h->a, NULL)) { - return false; - } - _heap_up (h, h->a.v.len - 1, x); - return true; -} diff --git a/libr/util/flist.c b/libr/util/flist.c deleted file mode 100644 index 876ed8bd8e..0000000000 --- a/libr/util/flist.c +++ /dev/null @@ -1,86 +0,0 @@ -/* radare - LGPL - Copyright 2010-2013 - pancake */ -// XXX. this is dupped inside the r_flist.h for optimizations - -int r_flist_iterator(void **x) { - return *x!=0; -} -void** r_flist_next(void **x) { - return x; -} -void** r_flist_get(void **x) { - return *(x++); -} -// XXX: forced free?? We need RFlist struct here -#include -//#include -// NOTE: reimplemnetation of r_flist in C (if no R_API defined) - -#if 1 -#define r_flist_t void** -#define RFList void** -#define r_flist_rewind(it) for (; (it)!=*(it); (it)--) {} (it)++ -#define r_flist_next(it) *(it)!=0 -#define r_flist_get(it) *((it)++) -#define r_flist_iterator(x) x -#define r_flist_unref(x) x -#endif - -R_API void **r_flist_new(int n) { - void **it; - if (!(it = (void **)calloc (n + 2, sizeof (void*)))) { - return NULL; - } - *it = it; - memset (++it, 0, (n + 1) * sizeof (void*)); - return it; -} - -// XXX. this is wrong :? -R_API void **r_flist_resize(void **it, int n) { - r_flist_rewind (it); - it--; - it = realloc (it, ((n+2) * sizeof (void*))); - *it = it; - return it+1; -} - -R_API void **r_flist_prev(void **it) { - void **p = it--; - return (it==*it)?p:it; -} - -R_API void r_flist_set(void **it, int idx, void *data) { - r_flist_rewind (it); - it[idx] = data; -} - -R_API void r_flist_delete(void **it, int idx) { - r_flist_rewind (it); - free (it[idx]); - it[idx] = NULL; - for (it += idx; *it; it++) { - *it = *(it + 1); - } -} - -#define r_flist_foreach(it, pos) \ - r_flist_rewind(it); \ - while (r_flist_next (it) && ((pos) = r_flist_get (it))) - -R_API void r_flist_free(void **it) { - void *pos; - r_flist_foreach (it, pos) { - free (pos); - } - r_flist_rewind (it); - free (--it); -} - -R_API int r_flist_length (void **it) { - void *pos; - int len = 0; - r_flist_foreach (it, pos) { - len++; - } - return len; -} diff --git a/libr/util/graph.c b/libr/util/graph.c deleted file mode 100644 index 69878e17f5..0000000000 --- a/libr/util/graph.c +++ /dev/null @@ -1,321 +0,0 @@ -/* radare - LGPL - Copyright 2007-2020 - pancake, ret2libc */ - -#include - -enum { - WHITE_COLOR = 0, - GRAY_COLOR, - BLACK_COLOR -}; - -static RGraphNode *r_graph_node_new (void *data) { - RGraphNode *p = R_NEW0 (RGraphNode); - if (p) { - p->data = data; - p->free = NULL; - p->out_nodes = r_list_new (); - p->in_nodes = r_list_new (); - p->all_neighbours = r_list_new (); - } - return p; -} - -static void r_graph_node_free (RGraphNode *n) { - if (!n) { - return; - } - if (n->free) { - n->free (n->data); - } - r_list_free (n->out_nodes); - r_list_free (n->in_nodes); - r_list_free (n->all_neighbours); - free (n); -} - -static int node_cmp (unsigned int idx, RGraphNode *b) { - return idx == b->idx ? 0 : -1; -} - -// direction == true => forwards -static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[], const bool direction) { - if (!n) { - return; - } - RStack *s = r_stack_new (2 * g->n_edges + 1); - if (!s) { - return; - } - RGraphEdge *edg = R_NEW0 (RGraphEdge); - if (!edg) { - r_stack_free (s); - return; - } - edg->from = NULL; - edg->to = n; - r_stack_push (s, edg); - while (!r_stack_is_empty (s)) { - RGraphEdge *cur_edge = (RGraphEdge *)r_stack_pop (s); - RGraphNode *v, *cur = cur_edge->to, *from = cur_edge->from; - RListIter *it; - int i; - - if (from && cur) { - if (color[cur->idx] == WHITE_COLOR && vis->tree_edge) { - vis->tree_edge (cur_edge, vis); - } else if (color[cur->idx] == GRAY_COLOR && vis->back_edge) { - vis->back_edge (cur_edge, vis); - } else if (color[cur->idx] == BLACK_COLOR && vis->fcross_edge) { - vis->fcross_edge (cur_edge, vis); - } - } else if (!cur && from) { - if (color[from->idx] != BLACK_COLOR && vis->finish_node) { - vis->finish_node (from, vis); - } - color[from->idx] = BLACK_COLOR; - } - free (cur_edge); - if (!cur || color[cur->idx] != WHITE_COLOR) { - continue; - } - if (color[cur->idx] == WHITE_COLOR && vis->discover_node) { - vis->discover_node (cur, vis); - } - color[cur->idx] = GRAY_COLOR; - - edg = R_NEW0 (RGraphEdge); - if (!edg) { - break; - } - edg->from = cur; - r_stack_push (s, edg); - - i = 0; - const RList *neighbours = direction ? cur->out_nodes : cur->in_nodes; - r_list_foreach (neighbours, it, v) { - edg = R_NEW (RGraphEdge); - edg->from = cur; - edg->to = v; - edg->nth = i++; - r_stack_push (s, edg); - } - } - r_stack_free (s); -} - -R_API RGraph *r_graph_new(void) { - RGraph *t = R_NEW0 (RGraph); - if (!t) { - return NULL; - } - t->nodes = r_list_new (); - if (!t->nodes) { - r_graph_free(t); - return NULL; - } - t->nodes->free = (RListFree)r_graph_node_free; - t->n_nodes = 0; - t->last_index = 0; - return t; -} - -R_API void r_graph_free(RGraph* t) { - r_list_free (t->nodes); - free (t); -} - -R_API RGraphNode *r_graph_get_node(const RGraph *t, unsigned int idx) { - RListIter *it = r_list_find (t->nodes, (void *)(size_t)idx, (RListComparator)node_cmp); - if (!it) { - return NULL; - } - return (RGraphNode *)it->data; -} - -R_API RListIter *r_graph_node_iter(const RGraph *t, unsigned int idx) { - return r_list_find (t->nodes, (void *)(size_t)idx, (RListComparator)node_cmp); -} - -R_API void r_graph_reset (RGraph *t) { - r_list_free (t->nodes); - t->nodes = r_list_new (); - if (!t->nodes) { - return; - } - t->nodes->free = (RListFree)r_graph_node_free; - t->n_nodes = 0; - t->n_edges = 0; - t->last_index = 0; -} - -R_API RGraphNode *r_graph_add_node(RGraph *t, void *data) { - if (!t) { - return NULL; - } - RGraphNode *n = r_graph_node_new (data); - if (!n) { - return NULL; - } - n->idx = t->last_index++; - r_list_append (t->nodes, n); - t->n_nodes++; - return n; -} - -/* remove the node from the graph and free the node */ -/* users of this function should be aware they can't access n anymore */ -R_API void r_graph_del_node(RGraph *t, RGraphNode *n) { - RGraphNode *gn; - RListIter *it; - if (!n) { - return; - } - r_list_foreach (n->in_nodes, it, gn) { - r_list_delete_data (gn->out_nodes, n); - r_list_delete_data (gn->all_neighbours, n); - t->n_edges--; - } - - r_list_foreach (n->out_nodes, it, gn) { - r_list_delete_data (gn->in_nodes, n); - r_list_delete_data (gn->all_neighbours, n); - t->n_edges--; - } - - r_list_delete_data (t->nodes, n); - t->n_nodes--; -} - -R_API void r_graph_add_edge(RGraph *t, RGraphNode *from, RGraphNode *to) { - r_graph_add_edge_at (t, from, to, -1); -} - -R_API void r_graph_add_edge_at (RGraph *t, RGraphNode *from, RGraphNode *to, int nth) { - if (from && to) { - r_list_insert (from->out_nodes, nth, to); - r_list_append (from->all_neighbours, to); - r_list_append (to->in_nodes, from); - r_list_append (to->all_neighbours, from); - t->n_edges++; - } -} - -// splits the "split_me", so that new node has it's outnodes -R_API RGraphNode *r_graph_node_split_forward(RGraph *g, RGraphNode *split_me, void *data) { - RGraphNode *front = r_graph_add_node(g, data); - RList *tmp = front->out_nodes; - front->out_nodes = split_me->out_nodes; - split_me->out_nodes = tmp; - RListIter *iter; - RGraphNode *n; - r_list_foreach (front->out_nodes, iter, n) { - r_list_delete_data (n->in_nodes, split_me); // optimize me - r_list_delete_data (n->all_neighbours, split_me); // boy this all_neighbours is so retarding perf here - r_list_delete_data (split_me->all_neighbours, n); - r_list_append (n->all_neighbours, front); - r_list_append (n->in_nodes, front); - r_list_append (front->all_neighbours, n); - } - return front; -} - - -R_API void r_graph_del_edge(RGraph *t, RGraphNode *from, RGraphNode *to) { - if (!from || !to || !r_graph_adjacent (t, from, to)) { - return; - } - r_list_delete_data (from->out_nodes, to); - r_list_delete_data (from->all_neighbours, to); - r_list_delete_data (to->in_nodes, from); - r_list_delete_data (to->all_neighbours, from); - t->n_edges--; -} - -// XXX remove comments and static inline all this crap -/* returns the list of nodes reachable from `n` */ -R_API const RList *r_graph_get_neighbours(const RGraph *g, const RGraphNode *n) { - return n? n->out_nodes: NULL; -} - -/* returns the n-th nodes reachable from the give node `n`. - * This, of course, depends on the order of the nodes. */ -R_API RGraphNode *r_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, int nth) { - return n? (RGraphNode *)r_list_get_n (n->out_nodes, nth): NULL; -} - -/* returns the list of nodes that can reach `n` */ -R_API const RList *r_graph_innodes(const RGraph *g, const RGraphNode *n) { - return n? n->in_nodes: NULL; -} - -/* returns the list of nodes reachable from `n` and that can reach `n`. */ -R_API const RList *r_graph_all_neighbours(const RGraph *g, const RGraphNode *n) { - return n? n->all_neighbours: NULL; -} - -R_API const RList *r_graph_get_nodes(const RGraph *g) { - return g? g->nodes: NULL; -} - -/* true if there is an edge from the node `from` to the node `to` */ -R_API bool r_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to) { - if (!g || !from) { - return false; - } - return r_list_contains (from->out_nodes, to); -} - -R_API void r_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis) { - if (!g || !n || !vis) { - return; - } - int *color = R_NEWS0 (int, g->last_index); - if (color) { - dfs_node (g, n, vis, color, true); - free (color); - } -} - -R_API void r_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis) { - if (!g || !n || !vis) { - return; - } - int *color = R_NEWS0 (int, g->last_index); - if (color) { - dfs_node (g, n, vis, color, false); - free (color); - } -} - -R_API void r_graph_dfs(RGraph *g, RGraphVisitor *vis) { - r_return_if_fail (g && vis); - RGraphNode *n; - RListIter *it; - - int *color = R_NEWS0 (int, g->last_index); - if (color) { - r_list_foreach (g->nodes, it, n) { - if (color[n->idx] == WHITE_COLOR) { - dfs_node (g, n, vis, color, true); - } - } - free (color); - } -} - -R_API void r_graph_free_node_info(void *ptr) { - RGraphNodeInfo *info = ptr; - free (info->body); - free (info->title); - free (info); -} - -R_API RGraphNodeInfo *r_graph_create_node_info(char *title, char *body, ut64 offset) { - RGraphNodeInfo *data = R_NEW0 (RGraphNodeInfo); - if (data) { - data->title = title; - data->body = body; - data->offset = offset; - } - return data; -} \ No newline at end of file diff --git a/libr/util/regex/test.c b/libr/util/regex/test.c deleted file mode 100644 index 8785e441ef..0000000000 --- a/libr/util/regex/test.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include - -int _main(void) { - RRegex rx; - int rc = r_regex_comp (&rx, "^hi", R_REGEX_NOSUB); - if (rc) { - printf ("error\n"); - - } else { - rc = r_regex_exec (&rx, "patata", 0, 0, 0); - printf ("out = %d\n", rc); - - rc = r_regex_exec (&rx, "hillow", 0, 0, 0); - printf ("out = %d\n", rc); - } - r_regex_free (&rx); - return 0; -} - -static void test_or(void) { - RRegex *rx = r_regex_new ("(eax|ebx)", "e"); - printf ("result (%s) = %d\n", "mov eax", r_regex_match("(eax|ebx)", "e", "mov eax")); - printf ("result (%s) = %d\n", "mov ebx", r_regex_match("(eax|ebx)", "e", "mov ebx")); - printf ("result (%s) = %d\n", "mov eax", r_regex_match("(eax|ebx)", "e", "mov ecx")); - printf ("result (%s) = %d\n", "mov ebx", r_regex_match("(eax|ecx)", "e", "mov ebx")); - printf ("result (%s) = %d\n", "mov eax", r_regex_check(rx, "mov eax")); - printf ("result (%s) = %d\n", "mov ebx", r_regex_check(rx, "mov ebx")); - printf ("result (%s) = %d\n", "mov eax", r_regex_exec(rx, "mov eax", 0, 0, 1)); - printf ("result (%s) = %d\n", "mov ebx", r_regex_exec(rx, "mov ebx", 0, 0, 1)); - r_regex_free (rx); -} - -int main(int argc, char **argv) { - const char *needle = "^hi"; - const char *haystack_1 = "patata"; - const char *haystack_2 = "hillow"; - if (argc>3) { - needle = argv[1]; - haystack_1 = argv[2]; - haystack_2 = argv[3]; - } else printf ("Using default values\n"); - RRegex *rx = r_regex_new (needle, ""); - if (rx) { - int res = r_regex_exec (rx, haystack_1, 0, 0, 0); - printf ("result (%s) = %d\n", haystack_1, res); - res = r_regex_exec (rx, haystack_2, 0, 0, 0); - printf ("result (%s) = %d\n", haystack_2, res); - r_regex_free (rx); - } else printf ("oops, cannot compile regexp\n"); - test_or(); - return 0; -} diff --git a/libr/util/spaces.c b/libr/util/spaces.c deleted file mode 100644 index 5a928b208e..0000000000 --- a/libr/util/spaces.c +++ /dev/null @@ -1,227 +0,0 @@ -/* radare - LGPL - Copyright 2019 - pancake, ret2libc */ - -#include "r_util/r_spaces.h" - -R_API RSpaces *r_spaces_new(const char *name) { - RSpaces *sp = R_NEW0 (RSpaces); - if (!sp || !r_spaces_init (sp, name)) { - free (sp); - return NULL; - } - return sp; -} - -R_API bool r_spaces_init(RSpaces *sp, const char *name) { - r_return_val_if_fail (sp && name, false); - sp->name = strdup (name); - if (!sp->name) { - goto fail; - } - - sp->spaces = NULL; - sp->current = NULL; - sp->spacestack = r_list_new (); - if (!sp->spacestack) { - goto fail; - } - - sp->event = r_event_new (sp); - if (!sp->event) { - goto fail; - } - - return true; - -fail: - r_spaces_fini (sp); - return false; -} - -R_API void r_spaces_free(RSpaces *sp) { - r_spaces_fini (sp); - free (sp); -} - -static inline void space_free(RSpace *s) { - if (s) { - free (s->name); - free (s); - } -} - -static void space_node_free(RBNode *n, void *user) { - RSpace *s = container_of (n, RSpace, rb); - space_free (s); -} - -R_API void r_spaces_fini(RSpaces *sp) { - r_list_free (sp->spacestack); - sp->spacestack = NULL; - r_rbtree_free (sp->spaces, space_node_free, NULL); - sp->spaces = NULL; - r_event_free (sp->event); - sp->event = NULL; - sp->current = NULL; - R_FREE (sp->name); -} - -R_API void r_spaces_purge(RSpaces *sp) { - sp->current = NULL; - r_list_purge (sp->spacestack); - r_rbtree_free (sp->spaces, space_node_free, NULL); - sp->spaces = NULL; -} - -static int name_space_cmp(const void *incoming, const RBNode *rb, void *user) { - const RSpace *s = container_of (rb, const RSpace, rb); - return strcmp (incoming, s->name); -} - -R_API RSpace *r_spaces_get(RSpaces *sp, const char *name) { - if (!name) { - return NULL; - } - RBNode *n = r_rbtree_find (sp->spaces, (void *)name, name_space_cmp, NULL); - return n? container_of (n, RSpace, rb): NULL; -} - -static int space_cmp(const void *incoming, const RBNode *rb, void *user) { - const RSpace *a = (const RSpace *)incoming; - const RSpace *b = container_of (rb, const RSpace, rb); - return strcmp (a->name, b->name); -} - -R_API RSpace *r_spaces_add(RSpaces *sp, const char *name) { - r_return_val_if_fail (sp, NULL); - if (!name || !*name || *name == '*') { - return NULL; - } - - RSpace *s = r_spaces_get (sp, name); - if (s) { - return s; - } - - s = R_NEW0 (RSpace); - if (!s) { - return NULL; - } - - s->name = strdup (name); - if (!s->name) { - free (s); - return NULL; - } - - r_rbtree_insert (&sp->spaces, s, &s->rb, space_cmp, NULL); - return s; -} - -R_API RSpace *r_spaces_set(RSpaces *sp, const char *name) { - sp->current = r_spaces_add (sp, name); - return sp->current; -} - -static inline bool spaces_unset_single(RSpaces *sp, const char *name) { - RSpace *space = r_spaces_get (sp, name); - if (!space) { - return false; - } - - RSpaceEvent ev = { .data.unset.space = space }; - r_event_send (sp->event, R_SPACE_EVENT_UNSET, &ev); - if (sp->current == space) { - sp->current = NULL; - } - return r_rbtree_delete (&sp->spaces, (void *)name, name_space_cmp, NULL, space_node_free, NULL); -} - -R_API bool r_spaces_unset(RSpaces *sp, const char *name) { - if (name) { - return spaces_unset_single (sp, name); - } - - RList *names = r_list_newf ((RListFree)free); - if (!names) { - return false; - } - - RBIter it; - RSpace *s; - r_spaces_foreach (sp, it, s) { - r_list_append (names, strdup (s->name)); - } - - RListIter *lit; - const char *n; - bool res = false; - r_list_foreach (names, lit, n) { - res |= spaces_unset_single (sp, n); - } - r_list_free (names); - return res; -} - -R_API int r_spaces_count(RSpaces *sp, const char *name) { - RSpace *s = r_spaces_get (sp, name); - if (!s) { - return 0; - } - RSpaceEvent ev = { .data.count.space = s, .res = 0 }; - r_event_send (sp->event, R_SPACE_EVENT_COUNT, &ev); - return ev.res; -} - -R_API bool r_spaces_push(RSpaces *sp, const char *name) { - r_return_val_if_fail (sp, false); - - r_list_push (sp->spacestack, sp->current? sp->current->name: "*"); - r_spaces_set (sp, name); - return true; -} - -R_API bool r_spaces_pop(RSpaces *sp) { - char *name = r_list_pop (sp->spacestack); - if (!name) { - return false; - } - - RSpace *s = r_spaces_get (sp, name); - r_spaces_set (sp, s? s->name: NULL); - return true; -} - -R_API bool r_spaces_rename(RSpaces *sp, const char *oname, const char *nname) { - if (!oname && !sp->current) { - return false; - } - - RSpace *s; - if (oname) { - s = r_spaces_get (sp, oname); - if (!s) { - return false; - } - } else { - s = sp->current; - } - - RSpace *sn = r_spaces_get (sp, nname); - if (sn) { - return false; - } - - RSpaceEvent ev = { - .data.rename.oldname = s->name, - .data.rename.newname = nname, - .data.rename.space = s - }; - r_event_send (sp->event, R_SPACE_EVENT_RENAME, &ev); - - r_rbtree_delete (&sp->spaces, (void *)s->name, name_space_cmp, NULL, NULL, NULL); - free (s->name); - s->name = strdup (nname); - r_rbtree_insert (&sp->spaces, s, &s->rb, space_cmp, NULL); - - return true; -} diff --git a/libr/util/vector.c b/libr/util/vector.c deleted file mode 100644 index eed5b2c19e..0000000000 --- a/libr/util/vector.c +++ /dev/null @@ -1,336 +0,0 @@ -/* radare - LGPL - Copyright 2017-2020 - maskray, thestr4ng3r */ - -#include "r_vector.h" - -// Optimize memory usage on glibc -#if __WORDSIZE == 32 -// Chunk size 24, minus 4 (chunk header), minus 8 for capacity and len, 12 bytes remaining for 3 void * -#define INITIAL_VECTOR_LEN 3 -#else -// For __WORDSIZE == 64 -// Chunk size 48, minus 8 (chunk header), minus 8 for capacity and len, 32 bytes remaining for 4 void * -#define INITIAL_VECTOR_LEN 4 -#endif - -#define NEXT_VECTOR_CAPACITY (vec->capacity < INITIAL_VECTOR_LEN \ - ? INITIAL_VECTOR_LEN \ - : vec->capacity <= 12 ? vec->capacity * 2 \ - : vec->capacity + (vec->capacity >> 1)) - -#define RESIZE_OR_RETURN_NULL(next_capacity) do { \ - size_t new_capacity = next_capacity; \ - void **new_a = realloc (vec->a, vec->elem_size * new_capacity); \ - if (!new_a) { \ - return NULL; \ - } \ - vec->a = new_a; \ - vec->capacity = new_capacity; \ - } while (0) - -R_API void r_vector_init(RVector *vec, size_t elem_size, RVectorFree free, void *free_user) { - r_return_if_fail (vec); - vec->a = NULL; - vec->capacity = vec->len = 0; - vec->elem_size = elem_size; - vec->free = free; - vec->free_user = free_user; -} - -R_API RVector *r_vector_new(size_t elem_size, RVectorFree free, void *free_user) { - RVector *vec = R_NEW (RVector); - if (!vec) { - return NULL; - } - r_vector_init (vec, elem_size, free, free_user); - return vec; -} - -static void vector_free_elems(RVector *vec) { - if (vec->free) { - while (vec->len > 0) { - vec->free (r_vector_index_ptr (vec, --vec->len), vec->free_user); - } - } else { - vec->len = 0; - } -} - -R_API void r_vector_fini(RVector *vec) { - r_return_if_fail (vec); - r_vector_clear (vec); - vec->free = NULL; - vec->free_user = NULL; -} - -R_API void r_vector_clear(RVector *vec) { - r_return_if_fail (vec); - vector_free_elems (vec); - R_FREE (vec->a); - vec->capacity = 0; -} - -R_API void r_vector_free(RVector *vec) { - if (vec) { - r_vector_fini (vec); - free (vec); - } -} - -static bool vector_clone(RVector *dst, RVector *src) { - r_return_val_if_fail (dst && src, false); - dst->capacity = src->capacity; - dst->len = src->len; - dst->elem_size = src->elem_size; - dst->free = src->free; - dst->free_user = src->free_user; - if (!dst->len) { - dst->a = NULL; - } else { - dst->a = malloc (src->elem_size * src->capacity); - if (!dst->a) { - return false; - } - memcpy (dst->a, src->a, src->elem_size * src->len); - } - return true; -} - -R_API RVector *r_vector_clone(RVector *vec) { - r_return_val_if_fail (vec, NULL); - RVector *ret = R_NEW (RVector); - if (!ret) { - return NULL; - } - if (!vector_clone (ret, vec)) { - free (ret); - return NULL; - } - return ret; -} - -R_API void r_vector_assign(RVector *vec, void *p, void *elem) { - r_return_if_fail (vec && p && elem); - memcpy (p, elem, vec->elem_size); -} - -R_API void *r_vector_assign_at(RVector *vec, size_t index, void *elem) { - void *p = r_vector_index_ptr (vec, index); - if (elem) { - r_vector_assign (vec, p, elem); - } - return p; -} - -R_API void r_vector_remove_at(RVector *vec, size_t index, void *into) { - r_return_if_fail (vec); - void *p = r_vector_index_ptr (vec, index); - if (into) { - r_vector_assign (vec, into, p); - } - vec->len--; - if (index < vec->len) { - memmove (p, (char *)p + vec->elem_size, vec->elem_size * (vec->len - index)); - } -} - -R_API void *r_vector_insert(RVector *vec, size_t index, void *x) { - r_return_val_if_fail (vec && index <= vec->len, NULL); - if (vec->len >= vec->capacity) { - RESIZE_OR_RETURN_NULL (NEXT_VECTOR_CAPACITY); - } - void *p = r_vector_index_ptr (vec, index); - if (index < vec->len) { - memmove ((char *)p + vec->elem_size, p, vec->elem_size * (vec->len - index)); - } - vec->len++; - if (x) { - r_vector_assign (vec, p, x); - } - return p; -} - -R_API void *r_vector_insert_range(RVector *vec, size_t index, void *first, size_t count) { - r_return_val_if_fail (vec && index <= vec->len, NULL); - if (vec->len + count > vec->capacity) { - RESIZE_OR_RETURN_NULL (R_MAX (NEXT_VECTOR_CAPACITY, vec->len + count)); - } - size_t sz = count * vec->elem_size; - void *p = r_vector_index_ptr (vec, index); - if (index < vec->len) { - memmove ((char *)p + sz, p, vec->elem_size * (vec->len - index)); - } - vec->len += count; - if (first) { - memcpy (p, first, sz); - } - return p; -} - -R_API void r_vector_pop(RVector *vec, void *into) { - r_return_if_fail (vec); - if (into) { - r_vector_assign (vec, into, r_vector_index_ptr (vec, vec->len - 1)); - } - vec->len--; -} - -R_API void r_vector_pop_front(RVector *vec, void *into) { - r_return_if_fail (vec); - r_vector_remove_at (vec, 0, into); -} - -R_API void *r_vector_push(RVector *vec, void *x) { - r_return_val_if_fail (vec, NULL); - if (vec->len >= vec->capacity) { - RESIZE_OR_RETURN_NULL (NEXT_VECTOR_CAPACITY); - } - void *p = r_vector_index_ptr (vec, vec->len++); - if (x) { - r_vector_assign (vec, p, x); - } - return p; -} - -R_API void *r_vector_push_front(RVector *vec, void *x) { - r_return_val_if_fail (vec, NULL); - return r_vector_insert (vec, 0, x); -} - -R_API void *r_vector_reserve(RVector *vec, size_t capacity) { - r_return_val_if_fail (vec, NULL); - if (vec->capacity < capacity) { - RESIZE_OR_RETURN_NULL (capacity); - } - return vec->a; -} - -R_API void *r_vector_shrink(RVector *vec) { - r_return_val_if_fail (vec, NULL); - if (vec->len < vec->capacity) { - RESIZE_OR_RETURN_NULL (vec->len); - } - return vec->a; -} - -// pvector - -static void pvector_free_elem(void *e, void *user) { - void *p = *((void **)e); - RPVectorFree elem_free = (RPVectorFree)user; - elem_free (p); -} - -R_API void r_pvector_init(RPVector *vec, RPVectorFree free) { - r_vector_init (&vec->v, sizeof (void *), free ? pvector_free_elem : NULL, free); -} - -R_API RPVector *r_pvector_new(RPVectorFree free) { - RPVector *v = R_NEW (RPVector); - if (!v) { - return NULL; - } - r_pvector_init (v, free); - return v; -} - -R_API RPVector *r_pvector_new_with_len(RPVectorFree free, size_t length) { - RPVector *v = r_pvector_new (free); - if (!v) { - return NULL; - } - void** p = r_pvector_reserve (v, length); - if (!p) { - r_pvector_free (v); - return NULL; - } - memset (p, 0, v->v.elem_size * v->v.capacity); - v->v.len = length; - return v; -} - -R_API void r_pvector_clear(RPVector *vec) { - r_return_if_fail (vec); - r_vector_clear (&vec->v); -} - -R_API void r_pvector_fini(RPVector *vec) { - r_return_if_fail (vec); - r_vector_fini (&vec->v); -} - -R_API void r_pvector_free(RPVector *vec) { - if (!vec) { - return; - } - r_vector_fini (&vec->v); - free (vec); -} - -R_API void **r_pvector_contains(RPVector *vec, void *x) { - r_return_val_if_fail (vec, NULL); - size_t i; - for (i = 0; i < vec->v.len; i++) { - if (((void **)vec->v.a)[i] == x) { - return &((void **)vec->v.a)[i]; - } - } - return NULL; -} - -R_API void *r_pvector_remove_at(RPVector *vec, size_t index) { - r_return_val_if_fail (vec, NULL); - void *r = r_pvector_at (vec, index); - r_vector_remove_at (&vec->v, index, NULL); - return r; -} - -R_API void r_pvector_remove_data(RPVector *vec, void *x) { - void **el = r_pvector_contains (vec, x); - if (!el) { - return; - } - - size_t index = el - (void **)vec->v.a; - r_vector_remove_at (&vec->v, index, NULL); -} - -R_API void *r_pvector_pop(RPVector *vec) { - r_return_val_if_fail (vec, NULL); - void *r = r_pvector_at (vec, vec->v.len - 1); - r_vector_pop (&vec->v, NULL); - return r; -} - -R_API void *r_pvector_pop_front(RPVector *vec) { - r_return_val_if_fail (vec, NULL); - void *r = r_pvector_at (vec, 0); - r_vector_pop_front (&vec->v, NULL); - return r; -} - -// CLRS Quicksort. It is slow, but simple. -static void quick_sort(void **a, size_t n, RPVectorComparator cmp) { - if (n <= 1) { - return; - } - size_t i = rand() % n, j = 0; - void *t, *pivot = a[i]; - a[i] = a[n - 1]; - for (i = 0; i < n - 1; i++) { - if (cmp (a[i], pivot) < 0) { - t = a[i]; - a[i] = a[j]; - a[j] = t; - j++; - } - } - a[n - 1] = a[j]; - a[j] = pivot; - quick_sort (a, j, cmp); - quick_sort (a + j + 1, n - j - 1, cmp); -} - -R_API void r_pvector_sort(RPVector *vec, RPVectorComparator cmp) { - r_return_if_fail (vec && cmp); - quick_sort (vec->v.a, vec->v.len, cmp); -} diff --git a/libr/util/x509.h b/libr/util/x509.h deleted file mode 100644 index e2c2ea7eb8..0000000000 --- a/libr/util/x509.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef R_X509_INTERNAL_H -#define R_X509_INTERNAL_H - -R_API bool r_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object * object); -R_API void r_x509_free_algorithmidentifier(RX509AlgorithmIdentifier * ai); - -R_API bool r_x509_parse_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki, RASN1Object *object); -R_API void r_x509_free_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki); - -R_API bool r_x509_parse_name(RX509Name *name, RASN1Object * object); -R_API void r_x509_free_name(RX509Name * name); - -R_API bool r_x509_parse_extension(RX509Extension *ext, RASN1Object * object); -R_API void r_x509_free_extension(RX509Extension * ex); - -R_API bool r_x509_parse_extensions(RX509Extensions *ext, RASN1Object * object); -R_API void r_x509_free_extensions(RX509Extensions* ex); - -R_API bool r_x509_parse_tbscertificate(RX509TBSCertificate *tbsc, RASN1Object * object); -R_API void r_x509_free_tbscertificate(RX509TBSCertificate * tbsc); - -R_API RX509CRLEntry *r_x509_parse_crlentry(RASN1Object *object); -R_API void r_x509_name_dump(RX509Name* name, const char* pad, RStrBuf *sb); - -#endif /* R_X509_INTERNAL_H */ - diff --git a/libr/Makefile b/librz/Makefile similarity index 50% rename from libr/Makefile rename to librz/Makefile index 361d217865..5706b265d8 100644 --- a/libr/Makefile +++ b/librz/Makefile @@ -46,8 +46,8 @@ ifneq ($(LIBS8),) $(MAKE) $(LIBS8) endif ifeq ($(WITH_LIBR),1) - $(MAKE) libr.${EXT_AR} - $(MAKE) libr.${EXT_SO} + $(MAKE) librz.${EXT_AR} + $(MAKE) librz.${EXT_SO} endif ifeq ($(WITH_LIBR),1) @@ -56,10 +56,10 @@ ifeq ($(CC),emcc) MLFLAGS= else ifeq ($(OSTYPE),darwin) -MLFLAGS+=-install_name @rpath/libr2.dylib +MLFLAGS+=-install_name @rpath/librz.dylib endif ifeq ($(OSTYPE),ios) -MLFLAGS+=-install_name @rpath/libr2.dylib +MLFLAGS+=-install_name @rpath/librz.dylib MLFLAGS+=-fembed-bitcode endif endif @@ -70,53 +70,53 @@ LDFLAGS+=${SSL_LDFLAGS} #endif # from env: ALFLAGS+=$(ALFLAGS) -# ${PARTIALLD} $(ALFLAGS) $(MLFLAGS) $(PLFLAGS) -o .libr/$$(basename $${LIB}.a).o $${LIB} -.libr: $(wildcard */libr_*.${EXT_AR}) ../shlr/libr_shlr.${EXT_AR} - rm -rf .libr - mkdir -p .libr +# ${PARTIALLD} $(ALFLAGS) $(MLFLAGS) $(PLFLAGS) -o .librz/$$(basename $${LIB}.a).o $${LIB} +.librz: $(wildcard */librz_*.${EXT_AR}) ../shlr/librz_shlr.${EXT_AR} + rm -rf .librz + mkdir -p .librz for LIB in $^ ; do \ - ${PARTIALLD} $(ALFLAGS) $(MLFLAGS) $(PLFLAGS) -o .libr/$$(basename $${LIB}.a).o $${LIB} ; \ + ${PARTIALLD} $(ALFLAGS) $(MLFLAGS) $(PLFLAGS) -o .librz/$$(basename $${LIB}.a).o $${LIB} ; \ done ifeq ($(OSTYPE),linux) - for LIB in .libr/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done + for LIB in .librz/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done endif ifeq ($(OSTYPE),gnulinux) - for LIB in .libr/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done + for LIB in .librz/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done endif ifeq ($(OSTYPE),android) - for LIB in .libr/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done + for LIB in .librz/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done endif ifeq ($(OSTYPE),bsd) - for LIB in .libr/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done + for LIB in .librz/* ; do $(OBJCOPY) --localize-hidden $$LIB ; done endif -_libr.${EXT_AR}: .libr - -${AR} -rs $@ .libr/*.o +_libr.${EXT_AR}: .librz + -${AR} -rs $@ .librz/*.o # this code should be in do-ar-sh not inlined here.. -.libr2: $(wildcard */libr_*.${EXT_AR}) ../shlr/libr_shlr.${EXT_AR} - rm -rf .libr2 - mkdir -p .libr2 +.librz: $(wildcard */librz_*.${EXT_AR}) ../shlr/librz_shlr.${EXT_AR} + rm -rf .librz + mkdir -p .librz -for LIB in $^ ; do \ BN=`basename $$LIB` ; \ - mkdir -p .libr2/$$BN ; \ - echo "( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB )" ; \ - ( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB ) ; \ + mkdir -p .librz/$$BN ; \ + echo "( cd .librz/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB )" ; \ + ( cd .librz/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} -x ../../$$LIB ) ; \ done -libr.${EXT_AR}: .libr2 - -${AR} -rs $@ .libr2/*/*.o +librz.${EXT_AR}: .librz + -${AR} -rs $@ .librz/*/*.o ifeq (1,$(WITH_GPL)) E+=../shlr/grub/libgrubfs.${EXT_AR} endif E+=../shlr/yxml/libyxml.${EXT_AR} -E+=../shlr/ar/libr_ar.${EXT_AR} -E+=../shlr/winkd/libr_winkd.${EXT_AR} +E+=../shlr/ar/librz_ar.${EXT_AR} +E+=../shlr/winkd/librz_winkd.${EXT_AR} E+=../shlr/qnx/lib/libqnxr.${EXT_AR} E+=../shlr/bochs/lib/libbochs.${EXT_AR} -E+=../shlr/radare2-shell-parser/libshell-parser.${EXT_AR} +E+=../shlr/rizin-shell-parser/libshell-parser.${EXT_AR} E+=../shlr/tree-sitter/libtree-sitter.${EXT_AR} #ifeq ($(COMPILER),ios-sdk) #E+=../shlr/sdb/src/libsdb.${EXT_AR} @@ -132,35 +132,35 @@ E+=../shlr/capstone/libcapstone.${EXT_AR} endif ifeq ($(OSTYPE),darwin) -libr_LDFLAGS=-dynamiclib -shared +librz_LDFLAGS=-dynamiclib -shared else -libr_LDFLAGS=-shared +librz_LDFLAGS=-shared endif -libr.${EXT_SO}: .libr2 +librz.${EXT_SO}: .librz ifeq (${COMPILER},emscripten) echo nothing to do here else - $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} $(libr_LDFLAGS) -o libr.${EXT_SO} \ - .libr2/*/*.o \ - ../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/libr_java.${EXT_AR} \ - ../shlr/libr_shlr.${EXT_AR} ../shlr/mpc/libmpc.${EXT_AR} $(E) \ - ../libr/util/libr_util.${EXT_AR} + $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} $(librz_LDFLAGS) -o librz.${EXT_SO} \ + .librz/*/*.o \ + ../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/librz_java.${EXT_AR} \ + ../shlr/librz_shlr.${EXT_AR} ../shlr/mpc/libmpc.${EXT_AR} $(E) \ + ../librz/util/librz_util.${EXT_AR} endif else # WITH_LIBR=0 -libr.${EXT_SO}: - $(MAKE) libr.${EXT_SO} WITH_LIBR=1 +librz.${EXT_SO}: + $(MAKE) librz.${EXT_SO} WITH_LIBR=1 -libr.${EXT_AR}: - $(MAKE) libr.${EXT_AR} WITH_LIBR=1 +librz.${EXT_AR}: + $(MAKE) librz.${EXT_AR} WITH_LIBR=1 endif -../shlr/libr_shlr.${EXT_AR}: - $(MAKE) -C ../shlr libr_shlr.${EXT_AR} +../shlr/librz_shlr.${EXT_AR}: + $(MAKE) -C ../shlr librz_shlr.${EXT_AR} $(LIBS): @echo "DIR $@" @@ -168,8 +168,8 @@ $(LIBS): pkgcfg: @for lib in ${LIBS}; do $(MAKE) -C $${lib} pkgcfg; done - $(MAKE) -C asm pkgcfg NAME=libr R2DEPS="r_`echo ${LIBS}|sed -e 's, , r_,g'`" - # TODO: Magically generate libr.pc.acr here using LIBS and so :) + $(MAKE) -C asm pkgcfg NAME=librz R2DEPS="rz_`echo ${LIBS}|sed -e 's, , rz_,g'`" + # TODO: Magically generate librz.pc.acr here using LIBS and so :) install-pkgconfig: ${INSTALL_DIR} "${DESTDIR}${LIBDIR}/pkgconfig" @@ -178,71 +178,71 @@ install-pkgconfig: ${INSTALL_DATA} $$FILE "${DESTDIR}${LIBDIR}/pkgconfig" ; done install-includes: - @-rm -f "${DESTDIR}${INCLUDEDIR}/libr/sflib" - @-rm -f "${DESTDIR}${INCLUDEDIR}/libr" - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr" - (cd include && for FILE in *.h ; do ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr" ; done) - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/sflib" + @-rm -f "${DESTDIR}${INCLUDEDIR}/librz/sflib" + @-rm -f "${DESTDIR}${INCLUDEDIR}/librz" + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz" + (cd include && for FILE in *.h ; do ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/librz" ; done) + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz/sflib" (cd include/sflib && for DIR in * ; do \ - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/sflib/$$DIR" ; \ + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz/sflib/$$DIR" ; \ for FILE in $$DIR/*.h ; do \ - ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/sflib/$$FILE" ; \ + ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/librz/sflib/$$FILE" ; \ done ; \ done) - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/sdb" + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz/sdb" (cd ../shlr/sdb/src && for FILE in *.h ; do \ - ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/sdb/$$FILE" ; \ + ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/librz/sdb/$$FILE" ; \ done) - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/r_util" - (cd include/r_util && for FILE in * ; do \ - ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/r_util/$$FILE" ; done) - ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/libr/r_crypto" - (cd include/r_crypto && for FILE in * ; do \ - ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/libr/r_crypto/$$FILE" ; done) + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz/rz_util" + (cd include/rz_util && for FILE in * ; do \ + ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/librz/rz_util/$$FILE" ; done) + ${INSTALL_DIR} "${DESTDIR}${INCLUDEDIR}/librz/rz_crypto" + (cd include/rz_crypto && for FILE in * ; do \ + ${INSTALL_DATA} $$FILE "${DESTDIR}${INCLUDEDIR}/librz/rz_crypto/$$FILE" ; done) symstall install-symlink: @cd .. && \ mkdir -p "${DESTDIR}${BINDIR}" \ "${DESTDIR}${INCLUDEDIR}" \ "${DESTDIR}${LIBDIR}/pkgconfig" \ - "${DESTDIR}${LIBDIR}/radare2/${VERSION}" ; \ - rm -rf "${DESTDIR}${INCLUDEDIR}/libr" && ln -fs "${PWD}/include" "${DESTDIR}${INCLUDEDIR}/libr" ; \ - rm -rf "${DESTDIR}${INCLUDEDIR}/libr/sdb" && ln -fs "${PWD}/../shlr/sdb/src" "${DESTDIR}${INCLUDEDIR}/libr/sdb" ; \ + "${DESTDIR}${LIBDIR}/rizin/${VERSION}" ; \ + rm -rf "${DESTDIR}${INCLUDEDIR}/librz" && ln -fs "${PWD}/include" "${DESTDIR}${INCLUDEDIR}/librz" ; \ + rm -rf "${DESTDIR}${INCLUDEDIR}/librz/sdb" && ln -fs "${PWD}/../shlr/sdb/src" "${DESTDIR}${INCLUDEDIR}/librz/sdb" ; \ $(MAKE) install-pkgconfig-symlink ; \ $(foreach lib,${LIBS}, \ - ln -fs "${PWD}/$(lib)/libr_$(lib).${EXT_SO}" \ - "${DESTDIR}${LIBDIR}/libr_$(lib).${EXT_SO}" ; \ - ln -fs "${PWD}/$(lib)/libr_$(lib).${EXT_SO}" \ - "${DESTDIR}${LIBDIR}/$(call libname-version,libr_$(lib).${EXT_SO},${LIBVERSION})" ; \ - ln -fs "${PWD}/$(lib)/libr_$(lib).${EXT_AR}" "${DESTDIR}${LIBDIR}/libr_$(lib).${EXT_AR}" ; \ + ln -fs "${PWD}/$(lib)/librz_$(lib).${EXT_SO}" \ + "${DESTDIR}${LIBDIR}/librz_$(lib).${EXT_SO}" ; \ + ln -fs "${PWD}/$(lib)/librz_$(lib).${EXT_SO}" \ + "${DESTDIR}${LIBDIR}/$(call libname-version,librz_$(lib).${EXT_SO},${LIBVERSION})" ; \ + ln -fs "${PWD}/$(lib)/librz_$(lib).${EXT_AR}" "${DESTDIR}${LIBDIR}/librz_$(lib).${EXT_AR}" ; \ $(foreach module,$(wildcard $(lib)/p/*.${EXT_SO}), \ - ln -fs "${PWD}/$(module)" "${DESTDIR}${LIBDIR}/radare2/${VERSION}/" ; \ + ln -fs "${PWD}/$(module)" "${DESTDIR}${LIBDIR}/rizin/${VERSION}/" ; \ ) \ ) \ - cd "${DESTDIR}${LIBDIR}/radare2" ; rm -f last ; ln -fs "${VERSION}" last + cd "${DESTDIR}${LIBDIR}/rizin" ; rm -f last ; ln -fs "${VERSION}" last install: install-includes install-pkgconfig # TODO :Use INSTALL_DATA_DIR instead of mkdir # libraries @${INSTALL_DIR} "${DESTDIR}${LIBDIR}" - @$(foreach lib,$(shell find * -type f -iname "*.${EXT_SO}" | grep -vE '^libr\.${EXT_SO}$$' | grep -v '(lib|parse)/t/' | grep lib | grep -v /bin/ | grep -v /p/), \ + @$(foreach lib,$(shell find * -type f -iname "*.${EXT_SO}" | grep -vE '^librz\.${EXT_SO}$$' | grep -v '(lib|parse)/t/' | grep lib | grep -v /bin/ | grep -v /p/), \ echo " ${DESTDIR}${LIBDIR}/$(call libpath-to-name-version,$(lib),${LIBVERSION})"; \ rm -f "${DESTDIR}${LIBDIR}/$(call libpath-to-name-version,$(lib),${LIBVERSION})"; \ ${INSTALL_LIB} "$(lib)" "${DESTDIR}${LIBDIR}/$(call libpath-to-name-version,$(lib),${LIBVERSION})"; \ ( cd "${DESTDIR}${LIBDIR}" ; ln -fs "$(call libpath-to-name-version,$(lib),${LIBVERSION})" "$(call libpath-to-name,$(lib))" ) ; \ ) - lib=libr.$(EXT_SO) ; if [ -f "$$lib" ]; then \ + lib=librz.$(EXT_SO) ; if [ -f "$$lib" ]; then \ ${INSTALL_LIB} "$$lib" "${DESTDIR}${LIBDIR}/$$lib"; \ fi # object archives @for FILE in `find * -type f -iname "*.${EXT_AR}" | grep -v fs/p` ; do \ echo " ${DESTDIR}${LIBDIR}/$$FILE"; ${INSTALL_DATA} $$FILE "${DESTDIR}${LIBDIR}" ; done || true # plugins - @${INSTALL_DIR} "${DESTDIR}${LIBDIR}/radare2/${VERSION}" + @${INSTALL_DIR} "${DESTDIR}${LIBDIR}/rizin/${VERSION}" @for FILE in `find */p -perm -u+x -type f | grep -v exe | grep -v dll | grep ${EXT_SO}`; \ - do echo " ${DESTDIR}${LIBDIR}/radare2/${VERSION}/$$FILE"; \ - ${INSTALL_LIB} "$$FILE" "${DESTDIR}${LIBDIR}/radare2/${VERSION}" ; done - cd "${DESTDIR}${LIBDIR}/radare2" ; ln -fs "${VERSION}" last + do echo " ${DESTDIR}${LIBDIR}/rizin/${VERSION}/$$FILE"; \ + ${INSTALL_LIB} "$$FILE" "${DESTDIR}${LIBDIR}/rizin/${VERSION}" ; done + cd "${DESTDIR}${LIBDIR}/rizin" ; ln -fs "${VERSION}" last deinstall uninstall: # libraries @@ -254,10 +254,10 @@ deinstall uninstall: FILE=`echo $$FILE | awk -F / '{ print $$NF; }'`; \ echo "${DESTDIR}${LIBDIR}/$$FILE" ; rm -f "${DESTDIR}${LIBDIR}/$$FILE" ; done # includes - -if [ -h "${DESTDIR}${INCLUDEDIR}/libr" ]; then \ - rm -f "${DESTDIR}${INCLUDEDIR}/libr" ; \ + -if [ -h "${DESTDIR}${INCLUDEDIR}/librz" ]; then \ + rm -f "${DESTDIR}${INCLUDEDIR}/librz" ; \ else \ - (cd include && for FILE in * ; do rm -f "${DESTDIR}${INCLUDEDIR}/libr/$$FILE" ; done) ; \ + (cd include && for FILE in * ; do rm -f "${DESTDIR}${INCLUDEDIR}/librz/$$FILE" ; done) ; \ fi # programs -@for FILE in `find */t -perm -u+x -type f | grep 2`; do \ @@ -265,33 +265,33 @@ deinstall uninstall: echo "${DESTDIR}${BINDIR}/$$FILE" ; rm -f "${DESTDIR}${BINDIR}/$$FILE" ; done # plugins -@for FILE in `find */p -perm -u+x -type f`; do \ - FILE="${DESTDIR}${LIBDIR}/radare2/${VERSION}/`echo $$FILE|awk -F / '{ print $$NF; }'`"; \ + FILE="${DESTDIR}${LIBDIR}/rizin/${VERSION}/`echo $$FILE|awk -F / '{ print $$NF; }'`"; \ echo $$FILE ; rm -f $$FILE ; done - rm -rf "${DESTDIR}${LIBDIR}/radare2/${VERSION}" - rm -f "${DESTDIR}${LIBDIR}/pkgconfig/libr.pc" - rm -f "${DESTDIR}${LIBDIR}/pkgconfig/r_"*.pc + rm -rf "${DESTDIR}${LIBDIR}/rizin/${VERSION}" + rm -f "${DESTDIR}${LIBDIR}/pkgconfig/librz.pc" + rm -f "${DESTDIR}${LIBDIR}/pkgconfig/rz_"*.pc # test programs - rm -rf "${DESTDIR}${BINDIR}/libr-test" - # TODO: use for FILE in LIBS (like in binr/Makefile) - rm -rf "${DESTDIR}${INCLUDEDIR}/libr" - rm -rf "${DESTDIR}${LIBDIR}/libr_*.so.${LIBVERSION}" - rm -rf "${DESTDIR}${LIBDIR}/libr_*.so.0" - rm -rf "${DESTDIR}${LIBDIR}/libr_*.so" - rm -rf "${DESTDIR}${LIBDIR}/libr_*.${EXT_AR}" - rm -rf "${DESTDIR}${LIBDIR}/libr2.so"* - rm -rf "${DESTDIR}${LIBDIR}/libr2.${EXT_AR}" - rm -rf "${DESTDIR}${LIBDIR}/libr.so"* - rm -rf "${DESTDIR}${LIBDIR}/libr.${EXT_AR}" - rm -rf "${DESTDIR}${DATADIR}/doc/radare2" - @echo libr aka radare2 has been uninstalled from PREFIX=${DESTDIR}${PREFIX} + rm -rf "${DESTDIR}${BINDIR}/librz-test" + # TODO: use for FILE in LIBS (like in binrz/Makefile) + rm -rf "${DESTDIR}${INCLUDEDIR}/librz" + rm -rf "${DESTDIR}${LIBDIR}/librz_*.so.${LIBVERSION}" + rm -rf "${DESTDIR}${LIBDIR}/librz_*.so.0" + rm -rf "${DESTDIR}${LIBDIR}/librz_*.so" + rm -rf "${DESTDIR}${LIBDIR}/librz_*.${EXT_AR}" + rm -rf "${DESTDIR}${LIBDIR}/librz.so"* + rm -rf "${DESTDIR}${LIBDIR}/librz.${EXT_AR}" + rm -rf "${DESTDIR}${LIBDIR}/librz.so"* + rm -rf "${DESTDIR}${LIBDIR}/librz.${EXT_AR}" + rm -rf "${DESTDIR}${DATADIR}/doc/rizin" + @echo librz aka rizin has been uninstalled from PREFIX=${DESTDIR}${PREFIX} clean: for LIB in ${LIBS}; do ( cd $${LIB} && $(MAKE) clean ); done - rm -rf .libr libr.${LIB_SO} libr.${LIB_AR} + rm -rf .librz librz.${LIB_SO} librz.${LIB_AR} mrproper: - rm -rf .libr libr.${LIB_SO} libr.${LIB_AR} + rm -rf .librz librz.${LIB_SO} librz.${LIB_AR} for LIB in ${LIBS}; do ( cd $${LIB} && $(MAKE) mrproper ); done -.PHONY: sloc mrproper clean pkgcfg install deinstall uninstall libr +.PHONY: sloc mrproper clean pkgcfg install deinstall uninstall librz .PHONY: install-includes install-pkgconfig install-symlink all diff --git a/libr/anal/Makefile b/librz/anal/Makefile similarity index 92% rename from libr/anal/Makefile rename to librz/anal/Makefile index d70f7a4656..42cd4f8952 100644 --- a/libr/anal/Makefile +++ b/librz/anal/Makefile @@ -4,8 +4,8 @@ EXTRA_TARGETS+=do EXTRA_CLEAN=doclean CFLAGS+=-I.. -NAME=r_anal -R2DEPS=r_util r_reg r_syscall r_search r_cons r_flag r_hash r_crypto r_parse +NAME=rz_anal +R2DEPS=rz_util rz_reg rz_syscall rz_search rz_cons rz_flag rz_hash rz_crypto rz_parse CFLAGS+=-DR2_PLUGIN_INCORE -Iarch -I$(TOP)/shlr CFLAGS+=-I$(LTOP)/asm/arch/include diff --git a/libr/anal/anal.c b/librz/anal/anal.c similarity index 57% rename from libr/anal/anal.c rename to librz/anal/anal.c index 75ff324139..5865257251 100644 --- a/libr/anal/anal.c +++ b/librz/anal/anal.c @@ -1,88 +1,88 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble */ -#include -#include -#include -#include +#include +#include +#include +#include #include -R_LIB_VERSION(r_anal); +R_LIB_VERSION(rz_anal); -static RAnalPlugin *anal_static_plugins[] = { +static RzAnalPlugin *anal_static_plugins[] = { R_ANAL_STATIC_PLUGINS }; -R_API void r_anal_set_limits(RAnal *anal, ut64 from, ut64 to) { +RZ_API void rz_anal_set_limits(RzAnal *anal, ut64 from, ut64 to) { free (anal->limit); - anal->limit = R_NEW0 (RAnalRange); + anal->limit = R_NEW0 (RzAnalRange); if (anal->limit) { anal->limit->from = from; anal->limit->to = to; } } -R_API void r_anal_unset_limits(RAnal *anal) { +RZ_API void rz_anal_unset_limits(RzAnal *anal) { R_FREE (anal->limit); } static void meta_unset_for(REvent *ev, int type, void *user, void *data) { RSpaces *s = (RSpaces *)ev->user; - RAnal *anal = container_of (s, RAnal, meta_spaces); + RzAnal *anal = container_of (s, RzAnal, meta_spaces); RSpaceEvent *se = (RSpaceEvent *)data; - r_meta_space_unset_for (anal, se->data.unset.space); + rz_meta_space_unset_for (anal, se->data.unset.space); } static void meta_count_for(REvent *ev, int type, void *user, void *data) { RSpaces *s = (RSpaces *)ev->user; - RAnal *anal = container_of (s, RAnal, meta_spaces); + RzAnal *anal = container_of (s, RzAnal, meta_spaces); RSpaceEvent *se = (RSpaceEvent *)data; - se->res = r_meta_space_count_for (anal, se->data.count.space); + se->res = rz_meta_space_count_for (anal, se->data.count.space); } static void zign_unset_for(REvent *ev, int type, void *user, void *data) { RSpaces *s = (RSpaces *)ev->user; - RAnal *anal = container_of (s, RAnal, zign_spaces); + RzAnal *anal = container_of (s, RzAnal, zign_spaces); RSpaceEvent *se = (RSpaceEvent *)data; - r_sign_space_unset_for (anal, se->data.unset.space); + rz_sign_space_unset_for (anal, se->data.unset.space); } static void zign_count_for(REvent *ev, int type, void *user, void *data) { RSpaces *s = (RSpaces *)ev->user; - RAnal *anal = container_of (s, RAnal, zign_spaces); + RzAnal *anal = container_of (s, RzAnal, zign_spaces); RSpaceEvent *se = (RSpaceEvent *)data; - se->res = r_sign_space_count_for (anal, se->data.count.space); + se->res = rz_sign_space_count_for (anal, se->data.count.space); } static void zign_rename_for(REvent *ev, int type, void *user, void *data) { RSpaces *s = (RSpaces *)ev->user; - RAnal *anal = container_of (s, RAnal, zign_spaces); + RzAnal *anal = container_of (s, RzAnal, zign_spaces); RSpaceEvent *se = (RSpaceEvent *)data; - r_sign_space_rename_for (anal, se->data.rename.space, + rz_sign_space_rename_for (anal, se->data.rename.space, se->data.rename.oldname, se->data.rename.newname); } -void r_anal_hint_storage_init(RAnal *a); -void r_anal_hint_storage_fini(RAnal *a); +void rz_anal_hint_storage_init(RzAnal *a); +void rz_anal_hint_storage_fini(RzAnal *a); -static void r_meta_item_fini(RAnalMetaItem *item) { +static void rz_meta_item_fini(RzAnalMetaItem *item) { free (item->str); } -static void r_meta_item_free(void *_item) { +static void rz_meta_item_free(void *_item) { if (_item) { - RAnalMetaItem *item = _item; - r_meta_item_fini (item); + RzAnalMetaItem *item = _item; + rz_meta_item_fini (item); free (item); } } -R_API RAnal *r_anal_new(void) { +RZ_API RzAnal *rz_anal_new(void) { int i; - RAnal *anal = R_NEW0 (RAnal); + RzAnal *anal = R_NEW0 (RzAnal); if (!anal) { return NULL; } - if (!r_str_constpool_init (&anal->constpool)) { + if (!rz_str_constpool_init (&anal->constpool)) { free (anal); return NULL; } @@ -98,16 +98,16 @@ R_API RAnal *r_anal_new(void) { anal->cpp_abi = R_ANAL_CPP_ABI_ITANIUM; anal->opt.depth = 32; anal->opt.noncode = false; // do not analyze data by default - r_spaces_init (&anal->meta_spaces, "CS"); - r_event_hook (anal->meta_spaces.event, R_SPACE_EVENT_UNSET, meta_unset_for, NULL); - r_event_hook (anal->meta_spaces.event, R_SPACE_EVENT_COUNT, meta_count_for, NULL); + rz_spaces_init (&anal->meta_spaces, "CS"); + rz_event_hook (anal->meta_spaces.event, R_SPACE_EVENT_UNSET, meta_unset_for, NULL); + rz_event_hook (anal->meta_spaces.event, R_SPACE_EVENT_COUNT, meta_count_for, NULL); - r_spaces_init (&anal->zign_spaces, "zs"); - r_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_UNSET, zign_unset_for, NULL); - r_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_COUNT, zign_count_for, NULL); - r_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_RENAME, zign_rename_for, NULL); - r_anal_hint_storage_init (anal); - r_interval_tree_init (&anal->meta, r_meta_item_free); + rz_spaces_init (&anal->zign_spaces, "zs"); + rz_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_UNSET, zign_unset_for, NULL); + rz_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_COUNT, zign_count_for, NULL); + rz_event_hook (anal->zign_spaces.event, R_SPACE_EVENT_RENAME, zign_rename_for, NULL); + rz_anal_hint_storage_init (anal); + rz_interval_tree_init (&anal->meta, rz_meta_item_free); anal->sdb_types = sdb_ns (anal->sdb, "types", 1); anal->sdb_fmts = sdb_ns (anal->sdb, "spec", 1); anal->sdb_cc = sdb_ns (anal->sdb, "cc", 1); @@ -116,31 +116,31 @@ R_API RAnal *r_anal_new(void) { anal->sdb_classes_attrs = sdb_ns (anal->sdb_classes, "attrs", 1); anal->zign_path = strdup (""); anal->cb_printf = (PrintfCallback) printf; - (void)r_anal_pin_init (anal); - (void)r_anal_xrefs_init (anal); + (void)rz_anal_pin_init (anal); + (void)rz_anal_xrefs_init (anal); anal->diff_thbb = R_ANAL_THRESHOLDBB; anal->diff_thfcn = R_ANAL_THRESHOLDFCN; - anal->syscall = r_syscall_new (); - r_io_bind_init (anal->iob); - r_flag_bind_init (anal->flb); - anal->reg = r_reg_new (); + anal->syscall = rz_syscall_new (); + rz_io_bind_init (anal->iob); + rz_flag_bind_init (anal->flb); + anal->reg = rz_reg_new (); anal->last_disasm_reg = NULL; anal->stackptr = 0; anal->lineswidth = 0; - anal->fcns = r_list_newf (r_anal_function_free); + anal->fcns = rz_list_newf (rz_anal_function_free); anal->leaddrs = NULL; - anal->imports = r_list_newf (free); - r_anal_set_bits (anal, 32); - anal->plugins = r_list_newf ((RListFree) r_anal_plugin_free); + anal->imports = rz_list_newf (free); + rz_anal_set_bits (anal, 32); + anal->plugins = rz_list_newf ((RzListFree) rz_anal_plugin_free); if (anal->plugins) { for (i = 0; anal_static_plugins[i]; i++) { - r_anal_add (anal, anal_static_plugins[i]); + rz_anal_add (anal, anal_static_plugins[i]); } } return anal; } -R_API void r_anal_plugin_free (RAnalPlugin *p) { +RZ_API void rz_anal_plugin_free (RzAnalPlugin *p) { if (p && p->fini) { p->fini (NULL); } @@ -148,60 +148,60 @@ R_API void r_anal_plugin_free (RAnalPlugin *p) { void __block_free_rb(RBNode *node, void *user); -R_API RAnal *r_anal_free(RAnal *a) { +RZ_API RzAnal *rz_anal_free(RzAnal *a) { if (!a) { return NULL; } /* TODO: Free anals here */ - r_list_free (a->fcns); + rz_list_free (a->fcns); ht_up_free (a->ht_addr_fun); ht_pp_free (a->ht_name_fun); set_u_free (a->visited); - r_anal_hint_storage_fini (a); - r_interval_tree_fini (&a->meta); + rz_anal_hint_storage_fini (a); + rz_interval_tree_fini (&a->meta); free (a->cpu); free (a->os); free (a->zign_path); - r_list_free (a->plugins); - r_rbtree_free (a->bb_tree, __block_free_rb, NULL); - r_spaces_fini (&a->meta_spaces); - r_spaces_fini (&a->zign_spaces); - r_anal_pin_fini (a); - r_syscall_free (a->syscall); - r_reg_free (a->reg); + rz_list_free (a->plugins); + rz_rbtree_free (a->bb_tree, __block_free_rb, NULL); + rz_spaces_fini (&a->meta_spaces); + rz_spaces_fini (&a->zign_spaces); + rz_anal_pin_fini (a); + rz_syscall_free (a->syscall); + rz_reg_free (a->reg); ht_up_free (a->dict_refs); ht_up_free (a->dict_xrefs); - r_list_free (a->leaddrs); + rz_list_free (a->leaddrs); sdb_free (a->sdb); if (a->esil) { - r_anal_esil_free (a->esil); + rz_anal_esil_free (a->esil); a->esil = NULL; } free (a->last_disasm_reg); - r_list_free (a->imports); - r_str_constpool_fini (&a->constpool); + rz_list_free (a->imports); + rz_str_constpool_fini (&a->constpool); free (a); return NULL; } -R_API void r_anal_set_user_ptr(RAnal *anal, void *user) { +RZ_API void rz_anal_set_user_ptr(RzAnal *anal, void *user) { anal->user = user; } -R_API int r_anal_add(RAnal *anal, RAnalPlugin *foo) { +RZ_API int rz_anal_add(RzAnal *anal, RzAnalPlugin *foo) { if (foo->init) { foo->init (anal->user); } - r_list_append (anal->plugins, foo); + rz_list_append (anal->plugins, foo); return true; } -R_API bool r_anal_use(RAnal *anal, const char *name) { - RListIter *it; - RAnalPlugin *h; +RZ_API bool rz_anal_use(RzAnal *anal, const char *name) { + RzListIter *it; + RzAnalPlugin *h; if (anal) { - r_list_foreach (anal->plugins, it, h) { + rz_list_foreach (anal->plugins, it, h) { if (!h->name || strcmp (h->name, name)) { continue; } @@ -212,27 +212,27 @@ R_API bool r_anal_use(RAnal *anal, const char *name) { } #endif anal->cur = h; - r_anal_set_reg_profile (anal); + rz_anal_set_reg_profile (anal); return true; } } return false; } -R_API char *r_anal_get_reg_profile(RAnal *anal) { +RZ_API char *rz_anal_get_reg_profile(RzAnal *anal) { return (anal && anal->cur && anal->cur->get_reg_profile) ? anal->cur->get_reg_profile (anal) : NULL; } // deprecate.. or at least reuse get_reg_profile... -R_API bool r_anal_set_reg_profile(RAnal *anal) { +RZ_API bool rz_anal_set_reg_profile(RzAnal *anal) { bool ret = false; if (anal && anal->cur && anal->cur->set_reg_profile) { ret = anal->cur->set_reg_profile (anal); } else { - char *p = r_anal_get_reg_profile (anal); + char *p = rz_anal_get_reg_profile (anal); if (p && *p) { - r_reg_set_profile_string (anal->reg, p); + rz_reg_set_profile_string (anal->reg, p); ret = true; } free (p); @@ -240,8 +240,8 @@ R_API bool r_anal_set_reg_profile(RAnal *anal) { return ret; } -R_API bool r_anal_set_triplet(RAnal *anal, const char *os, const char *arch, int bits) { - r_return_val_if_fail (anal, false); +RZ_API bool rz_anal_set_triplet(RzAnal *anal, const char *os, const char *arch, int bits) { + rz_return_val_if_fail (anal, false); if (!os || !*os) { os = R_SYS_OS; } @@ -253,8 +253,8 @@ R_API bool r_anal_set_triplet(RAnal *anal, const char *os, const char *arch, int } free (anal->os); anal->os = strdup (os); - r_anal_set_bits (anal, bits); - return r_anal_use (anal, arch); + rz_anal_set_bits (anal, bits); + return rz_anal_use (anal, arch); } // copypasta from core/cbin.c @@ -265,18 +265,18 @@ static void sdb_concat_by_path(Sdb *s, const char *path) { sdb_free (db); } -R_API bool r_anal_set_os(RAnal *anal, const char *os) { +RZ_API bool rz_anal_set_os(RzAnal *anal, const char *os) { Sdb *types = anal->sdb_types; - const char *dir_prefix = r_sys_prefix (NULL); + const char *dir_prefix = rz_sys_prefix (NULL); const char *dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s.sdb"), dir_prefix, os); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } - return r_anal_set_triplet (anal, os, NULL, -1); + return rz_anal_set_triplet (anal, os, NULL, -1); } -R_API bool r_anal_set_bits(RAnal *anal, int bits) { +RZ_API bool rz_anal_set_bits(RzAnal *anal, int bits) { switch (bits) { case 8: case 16: @@ -285,30 +285,30 @@ R_API bool r_anal_set_bits(RAnal *anal, int bits) { case 64: if (anal->bits != bits) { anal->bits = bits; - r_anal_set_reg_profile (anal); + rz_anal_set_reg_profile (anal); } return true; } return false; } -R_API void r_anal_set_cpu(RAnal *anal, const char *cpu) { +RZ_API void rz_anal_set_cpu(RzAnal *anal, const char *cpu) { free (anal->cpu); anal->cpu = cpu ? strdup (cpu) : NULL; - int v = r_anal_archinfo (anal, R_ANAL_ARCHINFO_ALIGN); + int v = rz_anal_archinfo (anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { anal->pcalign = v; } } -R_API int r_anal_set_big_endian(RAnal *anal, int bigend) { +RZ_API int rz_anal_set_big_endian(RzAnal *anal, int bigend) { anal->big_endian = bigend; anal->reg->big_endian = bigend; return true; } -R_API ut8 *r_anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { - RAnalOp *op = NULL; +RZ_API ut8 *rz_anal_mask(RzAnal *anal, int size, const ut8 *data, ut64 at) { + RzAnalOp *op = NULL; ut8 *ret = NULL; int oplen, idx = 0; @@ -320,19 +320,19 @@ R_API ut8 *r_anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { return anal->cur->anal_mask (anal, size, data, at); } - if (!(op = r_anal_op_new ())) { + if (!(op = rz_anal_op_new ())) { return NULL; } if (!(ret = malloc (size))) { - r_anal_op_free (op); + rz_anal_op_free (op); return NULL; } memset (ret, 0xff, size); while (idx < size) { - if ((oplen = r_anal_op (anal, op, at, data + idx, size - idx, R_ANAL_OP_MASK_BASIC)) < 1) { + if ((oplen = rz_anal_op (anal, op, at, data + idx, size - idx, R_ANAL_OP_MASK_BASIC)) < 1) { break; } if ((op->ptr != UT64_MAX || op->jump != UT64_MAX) && op->nopcode != 0) { @@ -342,18 +342,18 @@ R_API ut8 *r_anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { at += oplen; } - r_anal_op_free (op); + rz_anal_op_free (op); return ret; } -R_API void r_anal_trace_bb(RAnal *anal, ut64 addr) { - RAnalBlock *bbi; - RAnalFunction *fcni; - RListIter *iter2; - fcni = r_anal_get_fcn_in (anal, addr, 0); +RZ_API void rz_anal_trace_bb(RzAnal *anal, ut64 addr) { + RzAnalBlock *bbi; + RzAnalFunction *fcni; + RzListIter *iter2; + fcni = rz_anal_get_fcn_in (anal, addr, 0); if (fcni) { - r_list_foreach (fcni->bbs, iter2, bbi) { + rz_list_foreach (fcni->bbs, iter2, bbi) { if (addr >= bbi->addr && addr < (bbi->addr + bbi->size)) { bbi->traced = true; break; @@ -362,22 +362,22 @@ R_API void r_anal_trace_bb(RAnal *anal, ut64 addr) { } } -R_API void r_anal_colorize_bb(RAnal *anal, ut64 addr, ut32 color) { - RAnalBlock *bbi; - bbi = r_anal_bb_from_offset (anal, addr); +RZ_API void rz_anal_colorize_bb(RzAnal *anal, ut64 addr, ut32 color) { + RzAnalBlock *bbi; + bbi = rz_anal_bb_from_offset (anal, addr); if (bbi) { bbi->colorize = color; } } -R_API RList* r_anal_get_fcns (RAnal *anal) { +RZ_API RzList* rz_anal_get_fcns (RzAnal *anal) { // avoid received to free this thing anal->fcns->free = NULL; return anal->fcns; } -R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr, const char *str) { - RAnalOp *op = R_NEW0 (RAnalOp); +RZ_API RzAnalOp *rz_anal_op_hexstr(RzAnal *anal, ut64 addr, const char *str) { + RzAnalOp *op = R_NEW0 (RzAnalOp); if (!op) { return NULL; } @@ -386,13 +386,13 @@ R_API RAnalOp *r_anal_op_hexstr(RAnal *anal, ut64 addr, const char *str) { free (op); return NULL; } - int len = r_hex_str2bin (str, buf); - r_anal_op (anal, op, addr, buf, len, R_ANAL_OP_MASK_BASIC); + int len = rz_hex_str2bin (str, buf); + rz_anal_op (anal, op, addr, buf, len, R_ANAL_OP_MASK_BASIC); free (buf); return op; } -R_API bool r_anal_op_is_eob(RAnalOp *op) { +RZ_API bool rz_anal_op_is_eob(RzAnalOp *op) { if (op->eob) { return true; } @@ -411,24 +411,24 @@ R_API bool r_anal_op_is_eob(RAnalOp *op) { } } -R_API void r_anal_purge(RAnal *anal) { - r_anal_hint_clear (anal); - r_interval_tree_fini (&anal->meta); - r_interval_tree_init (&anal->meta, r_meta_item_free); +RZ_API void rz_anal_purge(RzAnal *anal) { + rz_anal_hint_clear (anal); + rz_interval_tree_fini (&anal->meta); + rz_interval_tree_init (&anal->meta, rz_meta_item_free); sdb_reset (anal->sdb_types); sdb_reset (anal->sdb_zigns); sdb_reset (anal->sdb_classes); sdb_reset (anal->sdb_classes_attrs); - r_anal_pin_fini (anal); - r_anal_pin_init (anal); + rz_anal_pin_fini (anal); + rz_anal_pin_init (anal); sdb_reset (anal->sdb_cc); - r_list_free (anal->fcns); - anal->fcns = r_list_newf (r_anal_function_free); - r_anal_purge_imports (anal); + rz_list_free (anal->fcns); + anal->fcns = rz_list_newf (rz_anal_function_free); + rz_anal_purge_imports (anal); } -R_API int r_anal_archinfo(RAnal *anal, int query) { - r_return_val_if_fail (anal, -1); +RZ_API int rz_anal_archinfo(RzAnal *anal, int query) { + rz_return_val_if_fail (anal, -1); switch (query) { case R_ANAL_ARCHINFO_MIN_OP_SIZE: case R_ANAL_ARCHINFO_MAX_OP_SIZE: @@ -442,7 +442,7 @@ R_API int r_anal_archinfo(RAnal *anal, int query) { } static bool __nonreturn_print_commands(void *p, const char *k, const char *v) { - RAnal *anal = (RAnal *)p; + RzAnal *anal = (RzAnal *)p; if (!strncmp (v, "func", strlen ("func") + 1)) { char *query = sdb_fmt ("func.%s.noreturn", k); if (sdb_bool_get (anal->sdb_types, query, NULL)) { @@ -456,7 +456,7 @@ static bool __nonreturn_print_commands(void *p, const char *k, const char *v) { } static bool __nonreturn_print(void *p, const char *k, const char *v) { - RAnal *anal = (RAnal *)p; + RzAnal *anal = (RzAnal *)p; if (!strncmp (k, "func.", 5) && strstr (k, ".noreturn")) { char *s = strdup (k + 5); char *d = strchr (s, '.'); @@ -481,7 +481,7 @@ static bool __nonreturn_print(void *p, const char *k, const char *v) { return true; } -R_API void r_anal_noreturn_list(RAnal *anal, int mode) { +RZ_API void rz_anal_noreturn_list(RzAnal *anal, int mode) { switch (mode) { case 1: case '*': @@ -497,13 +497,13 @@ R_API void r_anal_noreturn_list(RAnal *anal, int mode) { #define K_NORET_ADDR(x) sdb_fmt ("addr.%"PFMT64x".noreturn", x) #define K_NORET_FUNC(x) sdb_fmt ("func.%s.noreturn", x) -R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr) { +RZ_API bool rz_anal_noreturn_add(RzAnal *anal, const char *name, ut64 addr) { const char *tmp_name = NULL; Sdb *TDB = anal->sdb_types; char *fnl_name = NULL; if (addr != UT64_MAX) { if (sdb_bool_set (TDB, K_NORET_ADDR (addr), true, 0)) { - RAnalFunction *fcn = r_anal_get_function_at (anal, addr); + RzAnalFunction *fcn = rz_anal_get_function_at (anal, addr); if (fcn) { fcn->is_noreturn = true; } @@ -513,8 +513,8 @@ R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr) { if (name && *name) { tmp_name = name; } else { - RAnalFunction *fcn = r_anal_get_fcn_in (anal, addr, -1); - RFlagItem *fi = anal->flb.get_at (anal->flb.f, addr, false); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, addr, -1); + RzFlagItem *fi = anal->flb.get_at (anal->flb.f, addr, false); if (!fcn && !fi) { eprintf ("Can't find Function at given address\n"); return false; @@ -524,9 +524,9 @@ R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr) { fcn->is_noreturn = true; } } - if (r_type_func_exist (TDB, tmp_name)) { + if (rz_type_func_exist (TDB, tmp_name)) { fnl_name = strdup (tmp_name); - } else if (!(fnl_name = r_type_func_guess (TDB, (char *)tmp_name))) { + } else if (!(fnl_name = rz_type_func_guess (TDB, (char *)tmp_name))) { if (addr == UT64_MAX) { if (name) { sdb_bool_set (TDB, K_NORET_FUNC (name), true, 0); @@ -545,14 +545,14 @@ R_API bool r_anal_noreturn_add(RAnal *anal, const char *name, ut64 addr) { return true; } -R_API bool r_anal_noreturn_drop(RAnal *anal, const char *expr) { +RZ_API bool rz_anal_noreturn_drop(RzAnal *anal, const char *expr) { Sdb *TDB = anal->sdb_types; - expr = r_str_trim_head_ro (expr); + expr = rz_str_trim_head_ro (expr); const char *fcnname = NULL; if (!strncmp (expr, "0x", 2)) { - ut64 n = r_num_math (NULL, expr); + ut64 n = rz_num_math (NULL, expr); sdb_unset (TDB, K_NORET_ADDR (n), 0); - RAnalFunction *fcn = r_anal_get_fcn_in (anal, n, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, n, -1); if (!fcn) { // eprintf ("can't find function at 0x%"PFMT64x"\n", n); return false; @@ -565,10 +565,10 @@ R_API bool r_anal_noreturn_drop(RAnal *anal, const char *expr) { #if 0 char *tmp; // unnsecessary checks, imho the noreturn db should be pretty simple to allow forward and custom declarations without having to define the function prototype before - if (r_type_func_exist (TDB, fcnname)) { + if (rz_type_func_exist (TDB, fcnname)) { sdb_unset (TDB, K_NORET_FUNC (fcnname), 0); return true; - } else if ((tmp = r_type_func_guess (TDB, (char *)fcnname))) { + } else if ((tmp = rz_type_func_guess (TDB, (char *)fcnname))) { sdb_unset (TDB, K_NORET_FUNC (fcnname), 0); free (tmp); return true; @@ -578,11 +578,11 @@ R_API bool r_anal_noreturn_drop(RAnal *anal, const char *expr) { return false; } -static bool r_anal_noreturn_at_name(RAnal *anal, const char *name) { +static bool rz_anal_noreturn_at_name(RzAnal *anal, const char *name) { if (sdb_bool_get (anal->sdb_types, K_NORET_FUNC(name), NULL)) { return true; } - char *tmp = r_type_func_guess (anal->sdb_types, (char *)name); + char *tmp = rz_type_func_guess (anal->sdb_types, (char *)name); if (tmp) { if (sdb_bool_get (anal->sdb_types, K_NORET_FUNC (tmp), NULL)) { free (tmp); @@ -590,25 +590,25 @@ static bool r_anal_noreturn_at_name(RAnal *anal, const char *name) { } free (tmp); } - if (r_str_startswith (name, "reloc.")) { - return r_anal_noreturn_at_name (anal, name + 6); + if (rz_str_startswith (name, "reloc.")) { + return rz_anal_noreturn_at_name (anal, name + 6); } return false; } -R_API bool r_anal_noreturn_at_addr(RAnal *anal, ut64 addr) { +RZ_API bool rz_anal_noreturn_at_addr(RzAnal *anal, ut64 addr) { return sdb_bool_get (anal->sdb_types, K_NORET_ADDR (addr), NULL); } -static bool noreturn_recurse(RAnal *anal, ut64 addr) { - RAnalOp op = {0}; +static bool noreturn_recurse(RzAnal *anal, ut64 addr) { + RzAnalOp op = {0}; ut8 bbuf[0x10] = {0}; ut64 recurse_addr = UT64_MAX; if (!anal->iob.read_at (anal->iob.io, addr, bbuf, sizeof (bbuf))) { eprintf ("Couldn't read buffer\n"); return false; } - if (r_anal_op (anal, &op, addr, bbuf, sizeof (bbuf), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL) < 1) { + if (rz_anal_op (anal, &op, addr, bbuf, sizeof (bbuf), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL) < 1) { return false; } switch (op.type & R_ANAL_OP_TYPE_MASK) { @@ -633,26 +633,26 @@ static bool noreturn_recurse(RAnal *anal, ut64 addr) { if (recurse_addr == UT64_MAX || recurse_addr == addr) { return false; } - return r_anal_noreturn_at (anal, recurse_addr); + return rz_anal_noreturn_at (anal, recurse_addr); } -R_API bool r_anal_noreturn_at(RAnal *anal, ut64 addr) { +RZ_API bool rz_anal_noreturn_at(RzAnal *anal, ut64 addr) { if (!addr || addr == UT64_MAX) { return false; } - if (r_anal_noreturn_at_addr (anal, addr)) { + if (rz_anal_noreturn_at_addr (anal, addr)) { return true; } /* XXX this is very slow */ - RAnalFunction *f = r_anal_get_function_at (anal, addr); + RzAnalFunction *f = rz_anal_get_function_at (anal, addr); if (f) { - if (r_anal_noreturn_at_name (anal, f->name)) { + if (rz_anal_noreturn_at_name (anal, f->name)) { return true; } } - RFlagItem *fi = anal->flag_get (anal->flb.f, addr); + RzFlagItem *fi = anal->flag_get (anal->flb.f, addr); if (fi) { - if (r_anal_noreturn_at_name (anal, fi->realname ? fi->realname : fi->name)) { + if (rz_anal_noreturn_at_name (anal, fi->realname ? fi->realname : fi->name)) { return true; } } @@ -662,42 +662,42 @@ R_API bool r_anal_noreturn_at(RAnal *anal, ut64 addr) { return false; } -R_API void r_anal_bind(RAnal *anal, RAnalBind *b) { +RZ_API void rz_anal_bind(RzAnal *anal, RzAnalBind *b) { if (b) { b->anal = anal; - b->get_fcn_in = r_anal_get_fcn_in; - b->get_hint = r_anal_hint_get; + b->get_fcn_in = rz_anal_get_fcn_in; + b->get_hint = rz_anal_hint_get; } } -R_API RList *r_anal_preludes(RAnal *anal) { +RZ_API RzList *rz_anal_preludes(RzAnal *anal) { if (anal->cur && anal->cur->preludes ) { return anal->cur->preludes (anal); } return NULL; } -R_API bool r_anal_is_prelude(RAnal *anal, const ut8 *data, int len) { - RList *l = r_anal_preludes (anal); +RZ_API bool rz_anal_is_prelude(RzAnal *anal, const ut8 *data, int len) { + RzList *l = rz_anal_preludes (anal); if (l) { - RSearchKeyword *kw; - RListIter *iter; - r_list_foreach (l, iter, kw) { + RzSearchKeyword *kw; + RzListIter *iter; + rz_list_foreach (l, iter, kw) { int ks = kw->keyword_length; if (len >= ks && !memcmp (data, kw->bin_keyword, ks)) { - r_list_free (l); + rz_list_free (l); return true; } } - r_list_free (l); + rz_list_free (l); } return false; } -R_API void r_anal_add_import(RAnal *anal, const char *imp) { - RListIter *it; +RZ_API void rz_anal_add_import(RzAnal *anal, const char *imp) { + RzListIter *it; const char *eimp; - r_list_foreach (anal->imports, it, eimp) { + rz_list_foreach (anal->imports, it, eimp) { if (!strcmp (eimp, imp)) { return; } @@ -706,20 +706,20 @@ R_API void r_anal_add_import(RAnal *anal, const char *imp) { if (!cimp) { return; } - r_list_push (anal->imports, cimp); + rz_list_push (anal->imports, cimp); } -R_API void r_anal_remove_import(RAnal *anal, const char *imp) { - RListIter *it; +RZ_API void rz_anal_remove_import(RzAnal *anal, const char *imp) { + RzListIter *it; const char *eimp; - r_list_foreach (anal->imports, it, eimp) { + rz_list_foreach (anal->imports, it, eimp) { if (!strcmp (eimp, imp)) { - r_list_delete (anal->imports, it); + rz_list_delete (anal->imports, it); return; } } } -R_API void r_anal_purge_imports(RAnal *anal) { - r_list_purge (anal->imports); +RZ_API void rz_anal_purge_imports(RzAnal *anal) { + rz_list_purge (anal->imports); } diff --git a/libr/anal/arch/gb/gb.h b/librz/anal/arch/gb/gb.h similarity index 97% rename from libr/anal/arch/gb/gb.h rename to librz/anal/arch/gb/gb.h index f3fa3a41e2..f7539d88ab 100644 --- a/libr/anal/arch/gb/gb.h +++ b/librz/anal/arch/gb/gb.h @@ -1,6 +1,6 @@ #ifndef GB_H #define GB_H -#include +#include typedef struct gb_user_t { ut8 mbc_id; diff --git a/libr/anal/arch/gb/gb_makros.h b/librz/anal/arch/gb/gb_makros.h similarity index 95% rename from libr/anal/arch/gb/gb_makros.h rename to librz/anal/arch/gb/gb_makros.h index a4ac203581..9e14c94f10 100644 --- a/libr/anal/arch/gb/gb_makros.h +++ b/librz/anal/arch/gb/gb_makros.h @@ -1,4 +1,4 @@ -#include +#include #define GB_IS_VIRTUAL(x) (x/0x10000) #define GB_R_MBC_ADDR(x) (x%0x10000) diff --git a/librz/anal/arch/gb/meta_gb_cmt.c b/librz/anal/arch/gb/meta_gb_cmt.c new file mode 100644 index 0000000000..ffe1e4e1e7 --- /dev/null +++ b/librz/anal/arch/gb/meta_gb_cmt.c @@ -0,0 +1,11 @@ +/* radare - LGPL - Copyright 2013 - condret */ + +#include +#include + +void meta_gb_bankswitch_cmt(RzAnal *a, ut64 addr, ut16 ldarg) { + if(0x1fff ldarg && ldarg > 0x3fff) + rz_meta_set_string(a, R_META_TYPE_COMMENT, addr, "Ramswitch"); +} diff --git a/libr/anal/arch/hexagon/hexagon_anal.c b/librz/anal/arch/hexagon/hexagon_anal.c similarity index 99% rename from libr/anal/arch/hexagon/hexagon_anal.c rename to librz/anal/arch/hexagon/hexagon_anal.c index 358279b6aa..33bb193efb 100644 --- a/libr/anal/arch/hexagon/hexagon_anal.c +++ b/librz/anal/arch/hexagon/hexagon_anal.c @@ -1,13 +1,13 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "hexagon.h" #include "hexagon_insn.h" -int hexagon_anal_instruction(HexInsn *hi, RAnalOp *op) { +int hexagon_anal_instruction(HexInsn *hi, RzAnalOp *op) { switch (hi->instruction) { case HEX_INS_CALL__R22_2: { // call #r22:2 diff --git a/librz/anal/arch/hexagon/hexagon_anal.h b/librz/anal/arch/hexagon/hexagon_anal.h new file mode 100644 index 0000000000..c0cb241a8f --- /dev/null +++ b/librz/anal/arch/hexagon/hexagon_anal.h @@ -0,0 +1,2 @@ +int hexagon_anal_instruction(HexInsn *hi, RzAnalOp *op); + diff --git a/libr/anal/base_types.h b/librz/anal/base_types.h similarity index 93% rename from libr/anal/base_types.h rename to librz/anal/base_types.h index 41663abcbf..2b92604311 100644 --- a/libr/anal/base_types.h +++ b/librz/anal/base_types.h @@ -1,7 +1,7 @@ #ifndef R_BASE_TYPES_H #define R_BASE_TYPES_H -#include "r_util.h" +#include "rz_util.h" #ifdef __cplusplus extern "C" { diff --git a/libr/anal/bb.c b/librz/anal/bb.c similarity index 66% rename from libr/anal/bb.c rename to librz/anal/bb.c index 55e999f703..f2a7400ee1 100644 --- a/libr/anal/bb.c +++ b/librz/anal/bb.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2010-2019 - pancake, nibble */ -#include -#include -#include +#include +#include +#include #include typedef struct { ut64 addr; - RAnalBlock *ret; + RzAnalBlock *ret; } BBFromOffsetJmpmidCtx; -static bool bb_from_offset_jmpmid_cb(RAnalBlock *block, void *user) { +static bool bb_from_offset_jmpmid_cb(RzAnalBlock *block, void *user) { BBFromOffsetJmpmidCtx *ctx = user; // If an instruction starts exactly at the search addr, return that block immediately - if (r_anal_block_op_starts_at (block, ctx->addr)) { + if (rz_anal_block_op_starts_at (block, ctx->addr)) { ctx->ret = block; return false; } @@ -24,28 +24,28 @@ static bool bb_from_offset_jmpmid_cb(RAnalBlock *block, void *user) { return true; } -static bool bb_from_offset_first_cb(RAnalBlock *block, void *user) { - RAnalBlock **ret = user; +static bool bb_from_offset_first_cb(RzAnalBlock *block, void *user) { + RzAnalBlock **ret = user; *ret = block; return false; } -R_API RAnalBlock *r_anal_bb_from_offset(RAnal *anal, ut64 off) { +RZ_API RzAnalBlock *rz_anal_bb_from_offset(RzAnal *anal, ut64 off) { const bool x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86"); if (anal->opt.jmpmid && x86) { BBFromOffsetJmpmidCtx ctx = { off, NULL }; - r_anal_blocks_foreach_in (anal, off, bb_from_offset_jmpmid_cb, &ctx); + rz_anal_blocks_foreach_in (anal, off, bb_from_offset_jmpmid_cb, &ctx); return ctx.ret; } - RAnalBlock *ret = NULL; - r_anal_blocks_foreach_in (anal, off, bb_from_offset_first_cb, &ret); + RzAnalBlock *ret = NULL; + rz_anal_blocks_foreach_in (anal, off, bb_from_offset_first_cb, &ret); return ret; } /* return the offset of the i-th instruction in the basicblock bb. * If the index of the instruction is not valid, it returns UT16_MAX */ -R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i) { +RZ_API ut16 rz_anal_bb_offset_inst(RzAnalBlock *bb, int i) { if (i < 0 || i >= bb->ninstr) { return UT16_MAX; } @@ -54,8 +54,8 @@ R_API ut16 r_anal_bb_offset_inst(RAnalBlock *bb, int i) { /* return the address of the i-th instruction in the basicblock bb. * If the index of the instruction is not valid, it returns UT64_MAX */ -R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i) { - ut16 offset = r_anal_bb_offset_inst (bb, i); +RZ_API ut64 rz_anal_bb_opaddr_i(RzAnalBlock *bb, int i) { + ut16 offset = rz_anal_bb_offset_inst (bb, i); if (offset == UT16_MAX) { return UT64_MAX; } @@ -63,7 +63,7 @@ R_API ut64 r_anal_bb_opaddr_i(RAnalBlock *bb, int i) { } /* set the offset of the i-th instruction in the basicblock bb */ -R_API bool r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v) { +RZ_API bool rz_anal_bb_set_offset(RzAnalBlock *bb, int i, ut16 v) { // the offset 0 of the instruction 0 is not stored because always 0 if (i > 0 && v > 0) { if (i >= bb->op_pos_size) { @@ -83,17 +83,17 @@ R_API bool r_anal_bb_set_offset(RAnalBlock *bb, int i, ut16 v) { /* return the address of the instruction that occupy a given offset. * If the offset is not part of the given basicblock, UT64_MAX is returned. */ -R_API ut64 r_anal_bb_opaddr_at(RAnalBlock *bb, ut64 off) { +RZ_API ut64 rz_anal_bb_opaddr_at(RzAnalBlock *bb, ut64 off) { ut16 delta, delta_off, last_delta; int i; - if (!r_anal_block_contains (bb, off)) { + if (!rz_anal_block_contains (bb, off)) { return UT64_MAX; } last_delta = 0; delta_off = off - bb->addr; for (i = 0; i < bb->ninstr; i++) { - delta = r_anal_bb_offset_inst (bb, i); + delta = rz_anal_bb_offset_inst (bb, i); if (delta > delta_off) { return bb->addr + last_delta; } @@ -103,18 +103,18 @@ R_API ut64 r_anal_bb_opaddr_at(RAnalBlock *bb, ut64 off) { } // returns the size of the i-th instruction in a basic block -R_API ut64 r_anal_bb_size_i(RAnalBlock *bb, int i) { +RZ_API ut64 rz_anal_bb_size_i(RzAnalBlock *bb, int i) { if (i < 0 || i >= bb->ninstr) { return UT64_MAX; } - ut16 idx_cur = r_anal_bb_offset_inst (bb, i); - ut16 idx_next = r_anal_bb_offset_inst (bb, i + 1); + ut16 idx_cur = rz_anal_bb_offset_inst (bb, i); + ut16 idx_next = rz_anal_bb_offset_inst (bb, i + 1); return idx_next != UT16_MAX? idx_next - idx_cur: bb->size - idx_cur; } /* returns the address of the basic block that contains addr or UT64_MAX if * there is no such basic block */ -R_API ut64 r_anal_get_bbaddr(RAnal *anal, ut64 addr) { - RAnalBlock *bb = r_anal_bb_from_offset (anal, addr); +RZ_API ut64 rz_anal_get_bbaddr(RzAnal *anal, ut64 addr) { + RzAnalBlock *bb = rz_anal_bb_from_offset (anal, addr); return bb? bb->addr: UT64_MAX; } diff --git a/libr/anal/block.c b/librz/anal/block.c similarity index 55% rename from libr/anal/block.c rename to librz/anal/block.c index b2e7c80e95..dab0c1b575 100644 --- a/libr/anal/block.c +++ b/librz/anal/block.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2019-2020 - pancake, thestr4ng3r */ -#include +#include #include #include -#define unwrap(rbnode) container_of (rbnode, RAnalBlock, _rb) +#define unwrap(rbnode) container_of (rbnode, RzAnalBlock, _rb) static void __max_end(RBNode *node) { - RAnalBlock *block = unwrap (node); + RzAnalBlock *block = unwrap (node); block->_max_end = block->addr + block->size; int i; for (i = 0; i < 2; i++) { @@ -23,7 +23,7 @@ static void __max_end(RBNode *node) { static int __bb_addr_cmp(const void *incoming, const RBNode *in_tree, void *user) { ut64 incoming_addr = *(ut64 *)incoming; - const RAnalBlock *in_tree_block = container_of (in_tree, const RAnalBlock, _rb); + const RzAnalBlock *in_tree_block = container_of (in_tree, const RzAnalBlock, _rb); if (incoming_addr < in_tree_block->addr) { return -1; } @@ -35,15 +35,15 @@ static int __bb_addr_cmp(const void *incoming, const RBNode *in_tree, void *user #define D if (anal && anal->verbose) -R_API void r_anal_block_ref(RAnalBlock *bb) { +RZ_API void rz_anal_block_ref(RzAnalBlock *bb) { assert (bb->ref > 0); // 0-refd must already be freed. bb->ref++; } #define DFLT_NINSTR 3 -static RAnalBlock *block_new(RAnal *a, ut64 addr, ut64 size) { - RAnalBlock *block = R_NEW0 (RAnalBlock); +static RzAnalBlock *block_new(RzAnal *a, ut64 addr, ut64 size) { + RzAnalBlock *block = R_NEW0 (RzAnalBlock); if (!block) { return NULL; } @@ -58,37 +58,37 @@ static RAnalBlock *block_new(RAnal *a, ut64 addr, ut64 size) { block->stackptr = 0; block->parent_stackptr = INT_MAX; block->cmpval = UT64_MAX; - block->fcns = r_list_new (); + block->fcns = rz_list_new (); return block; } -static void block_free(RAnalBlock *block) { +static void block_free(RzAnalBlock *block) { if (!block) { return; } - r_anal_cond_free (block->cond); + rz_anal_cond_free (block->cond); free (block->fingerprint); - r_anal_diff_free (block->diff); + rz_anal_diff_free (block->diff); free (block->op_bytes); - r_anal_switch_op_free (block->switch_op); - r_list_free (block->fcns); + rz_anal_switch_op_free (block->switch_op); + rz_list_free (block->fcns); free (block->op_pos); free (block->parent_reg_arena); free (block); } void __block_free_rb(RBNode *node, void *user) { - RAnalBlock *block = unwrap (node); + RzAnalBlock *block = unwrap (node); block_free (block); } -R_API RAnalBlock *r_anal_get_block_at(RAnal *anal, ut64 addr) { - RBNode *node = r_rbtree_find (anal->bb_tree, &addr, __bb_addr_cmp, NULL); +RZ_API RzAnalBlock *rz_anal_get_block_at(RzAnal *anal, ut64 addr) { + RBNode *node = rz_rbtree_find (anal->bb_tree, &addr, __bb_addr_cmp, NULL); return node? unwrap (node): NULL; } -// This is a special case of what r_interval_node_all_in() does -static bool all_in(RAnalBlock *node, ut64 addr, RAnalBlockCb cb, void *user) { +// This is a special case of what rz_interval_node_all_in() does +static bool all_in(RzAnalBlock *node, ut64 addr, RzAnalBlockCb cb, void *user) { while (node && addr < node->addr) { // less than the current node, but might still be contained further down node = unwrap (node->_rb.child[0]); @@ -114,26 +114,26 @@ static bool all_in(RAnalBlock *node, ut64 addr, RAnalBlockCb cb, void *user) { return true; } -R_API bool r_anal_blocks_foreach_in(RAnal *anal, ut64 addr, RAnalBlockCb cb, void *user) { +RZ_API bool rz_anal_blocks_foreach_in(RzAnal *anal, ut64 addr, RzAnalBlockCb cb, void *user) { return all_in (anal->bb_tree ? unwrap (anal->bb_tree) : NULL, addr, cb, user); } -static bool block_list_cb(RAnalBlock *block, void *user) { - RList *list = user; - r_anal_block_ref (block); - r_list_push (list, block); +static bool block_list_cb(RzAnalBlock *block, void *user) { + RzList *list = user; + rz_anal_block_ref (block); + rz_list_push (list, block); return true; } -R_API RList *r_anal_get_blocks_in(RAnal *anal, ut64 addr) { - RList *list = r_list_newf ((RListFree)r_anal_block_unref); +RZ_API RzList *rz_anal_get_blocks_in(RzAnal *anal, ut64 addr) { + RzList *list = rz_list_newf ((RzListFree)rz_anal_block_unref); if (list) { - r_anal_blocks_foreach_in (anal, addr, block_list_cb, list); + rz_anal_blocks_foreach_in (anal, addr, block_list_cb, list); } return list; } -static void all_intersect(RAnalBlock *node, ut64 addr, ut64 size, RAnalBlockCb cb, void *user) { +static void all_intersect(RzAnalBlock *node, ut64 addr, ut64 size, RzAnalBlockCb cb, void *user) { ut64 end = addr + size; while (node && end <= node->addr) { // less than the current node, but might still be contained further down @@ -153,48 +153,48 @@ static void all_intersect(RAnalBlock *node, ut64 addr, ut64 size, RAnalBlockCb c all_intersect (unwrap (node->_rb.child[1]), addr, size, cb, user); } -R_API void r_anal_blocks_foreach_intersect(RAnal *anal, ut64 addr, ut64 size, RAnalBlockCb cb, void *user) { +RZ_API void rz_anal_blocks_foreach_intersect(RzAnal *anal, ut64 addr, ut64 size, RzAnalBlockCb cb, void *user) { all_intersect (anal->bb_tree ? unwrap (anal->bb_tree) : NULL, addr, size, cb, user); } -R_API RList *r_anal_get_blocks_intersect(RAnal *anal, ut64 addr, ut64 size) { - RList *list = r_list_newf ((RListFree)r_anal_block_unref); +RZ_API RzList *rz_anal_get_blocks_intersect(RzAnal *anal, ut64 addr, ut64 size) { + RzList *list = rz_list_newf ((RzListFree)rz_anal_block_unref); if (!list) { return NULL; } - r_anal_blocks_foreach_intersect (anal, addr, size, block_list_cb, list); + rz_anal_blocks_foreach_intersect (anal, addr, size, block_list_cb, list); return list; } -R_API RAnalBlock *r_anal_create_block(RAnal *anal, ut64 addr, ut64 size) { - if (r_anal_get_block_at (anal, addr)) { +RZ_API RzAnalBlock *rz_anal_create_block(RzAnal *anal, ut64 addr, ut64 size) { + if (rz_anal_get_block_at (anal, addr)) { return NULL; } - RAnalBlock *block = block_new (anal, addr, size); + RzAnalBlock *block = block_new (anal, addr, size); if (!block) { return NULL; } - r_rbtree_aug_insert (&anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); + rz_rbtree_aug_insert (&anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); return block; } -R_API void r_anal_delete_block(RAnalBlock *bb) { - r_anal_block_ref (bb); - while (!r_list_empty (bb->fcns)) { - r_anal_function_remove_block (r_list_first (bb->fcns), bb); +RZ_API void rz_anal_delete_block(RzAnalBlock *bb) { + rz_anal_block_ref (bb); + while (!rz_list_empty (bb->fcns)) { + rz_anal_function_remove_block (rz_list_first (bb->fcns), bb); } - r_anal_block_unref (bb); + rz_anal_block_unref (bb); } -R_API void r_anal_block_set_size(RAnalBlock *block, ut64 size) { +RZ_API void rz_anal_block_set_size(RzAnalBlock *block, ut64 size) { if (block->size == size) { return; } // Update the block's function's cached ranges - RAnalFunction *fcn; - RListIter *iter; - r_list_foreach (block->fcns, iter, fcn) { + RzAnalFunction *fcn; + RzListIter *iter; + rz_list_foreach (block->fcns, iter, fcn) { if (fcn->meta._min != UT64_MAX && fcn->meta._max == block->addr + block->size) { fcn->meta._max = block->addr + size; } @@ -202,23 +202,23 @@ R_API void r_anal_block_set_size(RAnalBlock *block, ut64 size) { // Do the actual resize block->size = size; - r_rbtree_aug_update_sum (block->anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); + rz_rbtree_aug_update_sum (block->anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); } -R_API bool r_anal_block_relocate(RAnalBlock *block, ut64 addr, ut64 size) { +RZ_API bool rz_anal_block_relocate(RzAnalBlock *block, ut64 addr, ut64 size) { if (block->addr == addr) { - r_anal_block_set_size (block, size); + rz_anal_block_set_size (block, size); return true; } - if (r_anal_get_block_at (block->anal, addr)) { + if (rz_anal_get_block_at (block->anal, addr)) { // Two blocks at the same addr is illegle you know... return false; } // Update the block's function's cached ranges - RAnalFunction *fcn; - RListIter *iter; - r_list_foreach (block->fcns, iter, fcn) { + RzAnalFunction *fcn; + RzListIter *iter; + rz_list_foreach (block->fcns, iter, fcn) { if (fcn->meta._min != UT64_MAX) { if (addr + size > fcn->meta._max) { // we extend after the maximum, so we are the maximum afterwards. @@ -238,28 +238,28 @@ R_API bool r_anal_block_relocate(RAnalBlock *block, ut64 addr, ut64 size) { } } - r_rbtree_aug_delete (&block->anal->bb_tree, &block->addr, __bb_addr_cmp, NULL, NULL, NULL, __max_end); + rz_rbtree_aug_delete (&block->anal->bb_tree, &block->addr, __bb_addr_cmp, NULL, NULL, NULL, __max_end); block->addr = addr; block->size = size; - r_rbtree_aug_insert (&block->anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); + rz_rbtree_aug_insert (&block->anal->bb_tree, &block->addr, &block->_rb, __bb_addr_cmp, NULL, __max_end); return true; } -R_API RAnalBlock *r_anal_block_split(RAnalBlock *bbi, ut64 addr) { - RAnal *anal = bbi->anal; - r_return_val_if_fail (bbi && addr >= bbi->addr && addr < bbi->addr + bbi->size && addr != UT64_MAX, 0); +RZ_API RzAnalBlock *rz_anal_block_split(RzAnalBlock *bbi, ut64 addr) { + RzAnal *anal = bbi->anal; + rz_return_val_if_fail (bbi && addr >= bbi->addr && addr < bbi->addr + bbi->size && addr != UT64_MAX, 0); if (addr == bbi->addr) { - r_anal_block_ref (bbi); // ref to be consistent with splitted return refcount + rz_anal_block_ref (bbi); // ref to be consistent with splitted return refcount return bbi; } - if (r_anal_get_block_at (bbi->anal, addr)) { + if (rz_anal_get_block_at (bbi->anal, addr)) { // can't have two bbs at the same addr return NULL; } // create the second block - RAnalBlock *bb = block_new (anal, addr, bbi->addr + bbi->size - addr); + RzAnalBlock *bb = block_new (anal, addr, bbi->addr + bbi->size - addr); if (!bb) { return NULL; } @@ -268,35 +268,35 @@ R_API RAnalBlock *r_anal_block_split(RAnalBlock *bbi, ut64 addr) { bb->parent_stackptr = bbi->stackptr; // resize the first block - r_anal_block_set_size (bbi, addr - bbi->addr); + rz_anal_block_set_size (bbi, addr - bbi->addr); bbi->jump = addr; bbi->fail = UT64_MAX; // insert the second block into the tree - r_rbtree_aug_insert (&anal->bb_tree, &bb->addr, &bb->_rb, __bb_addr_cmp, NULL, __max_end); + rz_rbtree_aug_insert (&anal->bb_tree, &bb->addr, &bb->_rb, __bb_addr_cmp, NULL, __max_end); // insert the second block into all functions of the first - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (bbi->fcns, iter, fcn) { - r_anal_function_add_block (fcn, bb); + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (bbi->fcns, iter, fcn) { + rz_anal_function_add_block (fcn, bb); } // recalculate offset of instructions in both bb and bbi int i; i = 0; - while (i < bbi->ninstr && r_anal_bb_offset_inst (bbi, i) < bbi->size) { + while (i < bbi->ninstr && rz_anal_bb_offset_inst (bbi, i) < bbi->size) { i++; } int new_bbi_instr = i; - if (bb->addr - bbi->addr == r_anal_bb_offset_inst (bbi, i)) { + if (bb->addr - bbi->addr == rz_anal_bb_offset_inst (bbi, i)) { bb->ninstr = 0; while (i < bbi->ninstr) { - ut16 off_op = r_anal_bb_offset_inst (bbi, i); + ut16 off_op = rz_anal_bb_offset_inst (bbi, i); if (off_op >= bbi->size + bb->size) { break; } - r_anal_bb_set_offset (bb, bb->ninstr, off_op - bbi->size); + rz_anal_bb_set_offset (bb, bb->ninstr, off_op - bbi->size); bb->ninstr++; i++; } @@ -305,33 +305,33 @@ R_API RAnalBlock *r_anal_block_split(RAnalBlock *bbi, ut64 addr) { return bb; } -R_API bool r_anal_block_merge(RAnalBlock *a, RAnalBlock *b) { - if (!r_anal_block_is_contiguous (a, b)) { +RZ_API bool rz_anal_block_merge(RzAnalBlock *a, RzAnalBlock *b) { + if (!rz_anal_block_is_contiguous (a, b)) { return false; } // check if function lists are identical - if (r_list_length (a->fcns) != r_list_length (b->fcns)) { + if (rz_list_length (a->fcns) != rz_list_length (b->fcns)) { return false; } - RAnalFunction *fcn; - RListIter *iter; - r_list_foreach (a->fcns, iter, fcn) { - if (!r_list_contains (b->fcns, fcn)) { + RzAnalFunction *fcn; + RzListIter *iter; + rz_list_foreach (a->fcns, iter, fcn) { + if (!rz_list_contains (b->fcns, fcn)) { return false; } } // Keep a ref to b, but remove all references of b from its functions - r_anal_block_ref (b); - while (!r_list_empty (b->fcns)) { - r_anal_function_remove_block (r_list_first (b->fcns), b); + rz_anal_block_ref (b); + while (!rz_list_empty (b->fcns)) { + rz_anal_function_remove_block (rz_list_first (b->fcns), b); } // merge ops from b into a size_t i; for (i = 0; i < b->ninstr; i++) { - r_anal_bb_set_offset (a, a->ninstr++, a->size + r_anal_bb_offset_inst (b, i)); + rz_anal_bb_set_offset (a, a->ninstr++, a->size + rz_anal_bb_offset_inst (b, i)); } // merge everything else into a @@ -340,31 +340,31 @@ R_API bool r_anal_block_merge(RAnalBlock *a, RAnalBlock *b) { a->fail = b->fail; // kill b completely - r_rbtree_aug_delete (&a->anal->bb_tree, &b->addr, __bb_addr_cmp, NULL, __block_free_rb, NULL, __max_end); + rz_rbtree_aug_delete (&a->anal->bb_tree, &b->addr, __bb_addr_cmp, NULL, __block_free_rb, NULL, __max_end); // invalidate ranges of a's functions - r_list_foreach (a->fcns, iter, fcn) { + rz_list_foreach (a->fcns, iter, fcn) { fcn->meta._min = UT64_MAX; } return true; } -R_API void r_anal_block_unref(RAnalBlock *bb) { +RZ_API void rz_anal_block_unref(RzAnalBlock *bb) { if (!bb) { return; } assert (bb->ref > 0); bb->ref--; - assert (bb->ref >= r_list_length (bb->fcns)); // all of the block's functions must hold a reference to it + assert (bb->ref >= rz_list_length (bb->fcns)); // all of the block's functions must hold a reference to it if (bb->ref < 1) { - RAnal *anal = bb->anal; - assert (!bb->fcns || r_list_empty (bb->fcns)); - r_rbtree_aug_delete (&anal->bb_tree, &bb->addr, __bb_addr_cmp, NULL, __block_free_rb, NULL, __max_end); + RzAnal *anal = bb->anal; + assert (!bb->fcns || rz_list_empty (bb->fcns)); + rz_rbtree_aug_delete (&anal->bb_tree, &bb->addr, __bb_addr_cmp, NULL, __block_free_rb, NULL, __max_end); } } -R_API bool r_anal_block_successor_addrs_foreach(RAnalBlock *block, RAnalAddrCb cb, void *user) { +RZ_API bool rz_anal_block_successor_addrs_foreach(RzAnalBlock *block, RzAnalAddrCb cb, void *user) { #define CB_ADDR(addr) do { \ if (addr == UT64_MAX) { \ break; \ @@ -377,9 +377,9 @@ R_API bool r_anal_block_successor_addrs_foreach(RAnalBlock *block, RAnalAddrCb c CB_ADDR (block->jump); CB_ADDR (block->fail); if (block->switch_op && block->switch_op->cases) { - RListIter *iter; - RAnalCaseOp *caseop; - r_list_foreach (block->switch_op->cases, iter, caseop) { + RzListIter *iter; + RzAnalCaseOp *caseop; + rz_list_foreach (block->switch_op->cases, iter, caseop) { CB_ADDR (caseop->jump); } } @@ -388,132 +388,132 @@ R_API bool r_anal_block_successor_addrs_foreach(RAnalBlock *block, RAnalAddrCb c #undef CB_ADDR } -typedef struct r_anal_block_recurse_context_t { - RAnal *anal; - RPVector/**/ to_visit; +typedef struct rz_anal_block_recurse_context_t { + RzAnal *anal; + RPVector/**/ to_visit; HtUP *visited; -} RAnalBlockRecurseContext; +} RzAnalBlockRecurseContext; static bool block_recurse_successor_cb(ut64 addr, void *user) { - RAnalBlockRecurseContext *ctx = user; + RzAnalBlockRecurseContext *ctx = user; if (ht_up_find_kv (ctx->visited, addr, NULL)) { // already visited return true; } ht_up_insert (ctx->visited, addr, NULL); - RAnalBlock *block = r_anal_get_block_at (ctx->anal, addr); + RzAnalBlock *block = rz_anal_get_block_at (ctx->anal, addr); if (!block) { return true; } - r_pvector_push (&ctx->to_visit, block); + rz_pvector_push (&ctx->to_visit, block); return true; } -R_API bool r_anal_block_recurse(RAnalBlock *block, RAnalBlockCb cb, void *user) { +RZ_API bool rz_anal_block_recurse(RzAnalBlock *block, RzAnalBlockCb cb, void *user) { bool breaked = false; - RAnalBlockRecurseContext ctx; + RzAnalBlockRecurseContext ctx; ctx.anal = block->anal; - r_pvector_init (&ctx.to_visit, NULL); + rz_pvector_init (&ctx.to_visit, NULL); ctx.visited = ht_up_new0 (); if (!ctx.visited) { goto beach; } ht_up_insert (ctx.visited, block->addr, NULL); - r_pvector_push (&ctx.to_visit, block); + rz_pvector_push (&ctx.to_visit, block); - while (!r_pvector_empty (&ctx.to_visit)) { - RAnalBlock *cur = r_pvector_pop (&ctx.to_visit); + while (!rz_pvector_empty (&ctx.to_visit)) { + RzAnalBlock *cur = rz_pvector_pop (&ctx.to_visit); breaked = !cb (cur, user); if (breaked) { break; } - r_anal_block_successor_addrs_foreach (cur, block_recurse_successor_cb, &ctx); + rz_anal_block_successor_addrs_foreach (cur, block_recurse_successor_cb, &ctx); } beach: ht_up_free (ctx.visited); - r_pvector_clear (&ctx.to_visit); + rz_pvector_clear (&ctx.to_visit); return !breaked; } -R_API bool r_anal_block_recurse_followthrough(RAnalBlock *block, RAnalBlockCb cb, void *user) { +RZ_API bool rz_anal_block_recurse_followthrough(RzAnalBlock *block, RzAnalBlockCb cb, void *user) { bool breaked = false; - RAnalBlockRecurseContext ctx; + RzAnalBlockRecurseContext ctx; ctx.anal = block->anal; - r_pvector_init (&ctx.to_visit, NULL); + rz_pvector_init (&ctx.to_visit, NULL); ctx.visited = ht_up_new0 (); if (!ctx.visited) { goto beach; } ht_up_insert (ctx.visited, block->addr, NULL); - r_pvector_push (&ctx.to_visit, block); + rz_pvector_push (&ctx.to_visit, block); - while (!r_pvector_empty (&ctx.to_visit)) { - RAnalBlock *cur = r_pvector_pop (&ctx.to_visit); + while (!rz_pvector_empty (&ctx.to_visit)) { + RzAnalBlock *cur = rz_pvector_pop (&ctx.to_visit); bool b = !cb (cur, user); if (b) { breaked = true; } else { - r_anal_block_successor_addrs_foreach (cur, block_recurse_successor_cb, &ctx); + rz_anal_block_successor_addrs_foreach (cur, block_recurse_successor_cb, &ctx); } } beach: ht_up_free (ctx.visited); - r_pvector_clear (&ctx.to_visit); + rz_pvector_clear (&ctx.to_visit); return !breaked; } typedef struct { - RAnalBlock *bb; - RListIter *switch_it; + RzAnalBlock *bb; + RzListIter *switch_it; } RecurseDepthFirstCtx; -R_API bool r_anal_block_recurse_depth_first(RAnalBlock *block, RAnalBlockCb cb, R_NULLABLE RAnalBlockCb on_exit, void *user) { +RZ_API bool rz_anal_block_recurse_depth_first(RzAnalBlock *block, RzAnalBlockCb cb, R_NULLABLE RzAnalBlockCb on_exit, void *user) { bool breaked = false; HtUP *visited = ht_up_new0 (); if (!visited) { goto beach; } - RAnal *anal = block->anal; - RVector path; - r_vector_init (&path, sizeof (RecurseDepthFirstCtx), NULL, NULL); - RAnalBlock *cur_bb = block; + RzAnal *anal = block->anal; + RzVector path; + rz_vector_init (&path, sizeof (RecurseDepthFirstCtx), NULL, NULL); + RzAnalBlock *cur_bb = block; RecurseDepthFirstCtx ctx = { cur_bb, NULL }; - r_vector_push (&path, &ctx); + rz_vector_push (&path, &ctx); ht_up_insert (visited, cur_bb->addr, NULL); breaked = !cb (cur_bb, user); if (breaked) { goto beach; } do { - RecurseDepthFirstCtx *cur_ctx = r_vector_index_ptr (&path, path.len - 1); + RecurseDepthFirstCtx *cur_ctx = rz_vector_index_ptr (&path, path.len - 1); cur_bb = cur_ctx->bb; if (cur_bb->jump != UT64_MAX && !ht_up_find_kv (visited, cur_bb->jump, NULL)) { - cur_bb = r_anal_get_block_at (anal, cur_bb->jump); + cur_bb = rz_anal_get_block_at (anal, cur_bb->jump); } else if (cur_bb->fail != UT64_MAX && !ht_up_find_kv (visited, cur_bb->fail, NULL)) { - cur_bb = r_anal_get_block_at (anal, cur_bb->fail); + cur_bb = rz_anal_get_block_at (anal, cur_bb->fail); } else { - RAnalCaseOp *cop = NULL; + RzAnalCaseOp *cop = NULL; if (cur_bb->switch_op && !cur_ctx->switch_it) { cur_ctx->switch_it = cur_bb->switch_op->cases->head; - cop = r_list_first (cur_bb->switch_op->cases); + cop = rz_list_first (cur_bb->switch_op->cases); } else if (cur_ctx->switch_it) { - while ((cur_ctx->switch_it = r_list_iter_get_next (cur_ctx->switch_it))) { - cop = r_list_iter_get_data (cur_ctx->switch_it); + while ((cur_ctx->switch_it = rz_list_iter_get_next (cur_ctx->switch_it))) { + cop = rz_list_iter_get_data (cur_ctx->switch_it); if (!ht_up_find_kv (visited, cop->jump, NULL)) { break; } cop = NULL; } } - cur_bb = cop ? r_anal_get_block_at (anal, cop->jump) : NULL; + cur_bb = cop ? rz_anal_get_block_at (anal, cop->jump) : NULL; } if (cur_bb) { RecurseDepthFirstCtx ctx = { cur_bb, NULL }; - r_vector_push (&path, &ctx); + rz_vector_push (&path, &ctx); ht_up_insert (visited, cur_bb->addr, NULL); bool breaked = !cb (cur_bb, user); if (breaked) { @@ -523,40 +523,40 @@ R_API bool r_anal_block_recurse_depth_first(RAnalBlock *block, RAnalBlockCb cb, if (on_exit) { on_exit (cur_ctx->bb, user); } - r_vector_pop (&path, NULL); + rz_vector_pop (&path, NULL); } - } while (!r_vector_empty (&path)); + } while (!rz_vector_empty (&path)); beach: ht_up_free (visited); - r_vector_clear (&path); + rz_vector_clear (&path); return !breaked; } -static bool recurse_list_cb(RAnalBlock *block, void *user) { - RList *list = user; - r_anal_block_ref (block); - r_list_push (list, block); +static bool recurse_list_cb(RzAnalBlock *block, void *user) { + RzList *list = user; + rz_anal_block_ref (block); + rz_list_push (list, block); return true; } -R_API RList *r_anal_block_recurse_list(RAnalBlock *block) { - RList *ret = r_list_newf ((RListFree)r_anal_block_unref); +RZ_API RzList *rz_anal_block_recurse_list(RzAnalBlock *block) { + RzList *ret = rz_list_newf ((RzListFree)rz_anal_block_unref); if (ret) { - r_anal_block_recurse (block, recurse_list_cb, ret); + rz_anal_block_recurse (block, recurse_list_cb, ret); } return ret; } -R_API void r_anal_block_add_switch_case(RAnalBlock *block, ut64 switch_addr, ut64 case_value, ut64 case_addr) { +RZ_API void rz_anal_block_add_switch_case(RzAnalBlock *block, ut64 switch_addr, ut64 case_value, ut64 case_addr) { if (!block->switch_op) { - block->switch_op = r_anal_switch_op_new (switch_addr, 0, 0, 0); + block->switch_op = rz_anal_switch_op_new (switch_addr, 0, 0, 0); } - r_anal_switch_op_add_case (block->switch_op, case_addr, case_value, case_addr); + rz_anal_switch_op_add_case (block->switch_op, case_addr, case_value, case_addr); } -R_API bool r_anal_block_op_starts_at(RAnalBlock *bb, ut64 addr) { - if (!r_anal_block_contains (bb, addr)) { +RZ_API bool rz_anal_block_op_starts_at(RzAnalBlock *bb, ut64 addr) { + if (!rz_anal_block_contains (bb, addr)) { return false; } ut64 off = addr - bb->addr; @@ -565,7 +565,7 @@ R_API bool r_anal_block_op_starts_at(RAnalBlock *bb, ut64 addr) { } size_t i; for (i = 0; i < bb->ninstr; i++) { - ut16 inst_off = r_anal_bb_offset_inst (bb, i); + ut16 inst_off = rz_anal_bb_offset_inst (bb, i); if (off == inst_off) { return true; } @@ -574,11 +574,11 @@ R_API bool r_anal_block_op_starts_at(RAnalBlock *bb, ut64 addr) { } typedef struct { - RAnal *anal; - RAnalBlock *cur_parent; + RzAnal *anal; + RzAnalBlock *cur_parent; ut64 dst; - RPVector/**/ *next_visit; // accumulate block of the next level in the tree - HtUP/**/ *visited; // maps addrs to their previous block (or NULL for entry) + RPVector/**/ *next_visit; // accumulate block of the next level in the tree + HtUP/**/ *visited; // maps addrs to their previous block (or NULL for entry) } PathContext; static bool shortest_path_successor_cb(ut64 addr, void *user) { @@ -588,25 +588,25 @@ static bool shortest_path_successor_cb(ut64 addr, void *user) { return true; } ht_up_insert (ctx->visited, addr, ctx->cur_parent); - RAnalBlock *block = r_anal_get_block_at (ctx->anal, addr); + RzAnalBlock *block = rz_anal_get_block_at (ctx->anal, addr); if (block) { - r_pvector_push (ctx->next_visit, block); + rz_pvector_push (ctx->next_visit, block); } return addr != ctx->dst; // break if we found our destination } -R_API R_NULLABLE RList/**/ *r_anal_block_shortest_path(RAnalBlock *block, ut64 dst) { - RList *ret = NULL; +RZ_API R_NULLABLE RzList/**/ *rz_anal_block_shortest_path(RzAnalBlock *block, ut64 dst) { + RzList *ret = NULL; PathContext ctx; ctx.anal = block->anal; ctx.dst = dst; // two vectors to swap cur_visit/next_visit RPVector visit_a; - r_pvector_init (&visit_a, NULL); + rz_pvector_init (&visit_a, NULL); RPVector visit_b; - r_pvector_init (&visit_b, NULL); + rz_pvector_init (&visit_b, NULL); ctx.next_visit = &visit_a; RPVector *cur_visit = &visit_b; // cur visit is the current level in the tree @@ -616,69 +616,69 @@ R_API R_NULLABLE RList/**/ *r_anal_block_shortest_path(RAnalBlock } ht_up_insert (ctx.visited, block->addr, NULL); - r_pvector_push (cur_visit, block); + rz_pvector_push (cur_visit, block); // BFS - while (!r_pvector_empty (cur_visit)) { + while (!rz_pvector_empty (cur_visit)) { void **it; - r_pvector_foreach (cur_visit, it) { - RAnalBlock *cur = *it; + rz_pvector_foreach (cur_visit, it) { + RzAnalBlock *cur = *it; ctx.cur_parent = cur; - r_anal_block_successor_addrs_foreach (cur, shortest_path_successor_cb, &ctx); + rz_anal_block_successor_addrs_foreach (cur, shortest_path_successor_cb, &ctx); } RPVector *tmp = cur_visit; cur_visit = ctx.next_visit; ctx.next_visit = tmp; - r_pvector_clear (ctx.next_visit); + rz_pvector_clear (ctx.next_visit); } // reconstruct the path bool found = false; - RAnalBlock *prev = ht_up_find (ctx.visited, dst, &found); - RAnalBlock *dst_block = r_anal_get_block_at (block->anal, dst); + RzAnalBlock *prev = ht_up_find (ctx.visited, dst, &found); + RzAnalBlock *dst_block = rz_anal_get_block_at (block->anal, dst); if (found && dst_block) { - ret = r_list_newf ((RListFree)r_anal_block_unref); - r_anal_block_ref (dst_block); - r_list_prepend (ret, dst_block); + ret = rz_list_newf ((RzListFree)rz_anal_block_unref); + rz_anal_block_ref (dst_block); + rz_list_prepend (ret, dst_block); while (prev) { - r_anal_block_ref (prev); - r_list_prepend (ret, prev); + rz_anal_block_ref (prev); + rz_list_prepend (ret, prev); prev = ht_up_find (ctx.visited, prev->addr, NULL); } } beach: ht_up_free (ctx.visited); - r_pvector_clear (&visit_a); - r_pvector_clear (&visit_b); + rz_pvector_clear (&visit_a); + rz_pvector_clear (&visit_b); return ret; } typedef struct { - RAnalBlock *block; + RzAnalBlock *block; bool reachable; } NoreturnSuccessor; static void noreturn_successor_free(HtUPKv *kv) { NoreturnSuccessor *succ = kv->value; - r_anal_block_unref (succ->block); + rz_anal_block_unref (succ->block); free (succ); } -static bool noreturn_successors_cb(RAnalBlock *block, void *user) { +static bool noreturn_successors_cb(RzAnalBlock *block, void *user) { HtUP *succs = user; NoreturnSuccessor *succ = R_NEW0 (NoreturnSuccessor); if (!succ) { return false; } - r_anal_block_ref (block); + rz_anal_block_ref (block); succ->block = block; succ->reachable = false; // reset for first iteration ht_up_insert (succs, block->addr, succ); return true; } -static bool noreturn_successors_reachable_cb(RAnalBlock *block, void *user) { +static bool noreturn_successors_reachable_cb(RzAnalBlock *block, void *user) { HtUP *succs = user; NoreturnSuccessor *succ = ht_up_find (succs, block->addr, NULL); if (succ) { @@ -688,29 +688,29 @@ static bool noreturn_successors_reachable_cb(RAnalBlock *block, void *user) { } static bool noreturn_remove_unreachable_cb(void *user, const ut64 k, const void *v) { - RAnalFunction *fcn = user; + RzAnalFunction *fcn = user; NoreturnSuccessor *succ = (NoreturnSuccessor *)v; - if (!succ->reachable && r_list_contains (succ->block->fcns, fcn)) { - r_anal_function_remove_block (fcn, succ->block); + if (!succ->reachable && rz_list_contains (succ->block->fcns, fcn)) { + rz_anal_function_remove_block (fcn, succ->block); } succ->reachable = false; // reset for next iteration return true; } static bool noreturn_get_blocks_cb(void *user, const ut64 k, const void *v) { - RList *blocks = user; + RzList *blocks = user; NoreturnSuccessor *succ = (NoreturnSuccessor *)v; - r_anal_block_ref (succ->block); - r_list_push (blocks, succ->block); + rz_anal_block_ref (succ->block); + rz_list_push (blocks, succ->block); return true; } -R_API RAnalBlock *r_anal_block_chop_noreturn(RAnalBlock *block, ut64 addr) { - r_return_val_if_fail (block, NULL); - if (!r_anal_block_contains (block, addr) || addr == block->addr) { +RZ_API RzAnalBlock *rz_anal_block_chop_noreturn(RzAnalBlock *block, ut64 addr) { + rz_return_val_if_fail (block, NULL); + if (!rz_anal_block_contains (block, addr) || addr == block->addr) { return block; } - r_anal_block_ref (block); + rz_anal_block_ref (block); // Cache all recursive successors of block here. // These are the candidates that we might have to remove from functions later. @@ -718,48 +718,48 @@ R_API RAnalBlock *r_anal_block_chop_noreturn(RAnalBlock *block, ut64 addr) { if (!succs) { return block; } - r_anal_block_recurse (block, noreturn_successors_cb, succs); + rz_anal_block_recurse (block, noreturn_successors_cb, succs); // Chop the block. Resize and remove all destination addrs - r_anal_block_set_size (block, addr - block->addr); + rz_anal_block_set_size (block, addr - block->addr); block->jump = UT64_MAX; block->fail = UT64_MAX; - r_anal_switch_op_free (block->switch_op); + rz_anal_switch_op_free (block->switch_op); block->switch_op = NULL; // Now, for each fcn, check which of our successors are still reachable in the function remove and the ones that are not. - RListIter *it; - RAnalFunction *fcn; + RzListIter *it; + RzAnalFunction *fcn; // We need to clone the list because block->fcns will get modified in the loop - RList *fcns_cpy = r_list_clone (block->fcns); - r_list_foreach (fcns_cpy, it, fcn) { - RAnalBlock *entry = r_anal_get_block_at (block->anal, fcn->addr); - if (entry && r_list_contains (entry->fcns, fcn)) { - r_anal_block_recurse (entry, noreturn_successors_reachable_cb, succs); + RzList *fcns_cpy = rz_list_clone (block->fcns); + rz_list_foreach (fcns_cpy, it, fcn) { + RzAnalBlock *entry = rz_anal_get_block_at (block->anal, fcn->addr); + if (entry && rz_list_contains (entry->fcns, fcn)) { + rz_anal_block_recurse (entry, noreturn_successors_reachable_cb, succs); } ht_up_foreach (succs, noreturn_remove_unreachable_cb, fcn); } - r_list_free (fcns_cpy); + rz_list_free (fcns_cpy); // This last step isn't really critical, but nice to have. // Prepare to merge blocks with their predecessors if possible - RList merge_blocks; - r_list_init (&merge_blocks); - merge_blocks.free = (RListFree)r_anal_block_unref; + RzList merge_blocks; + rz_list_init (&merge_blocks); + merge_blocks.free = (RzListFree)rz_anal_block_unref; ht_up_foreach (succs, noreturn_get_blocks_cb, &merge_blocks); // Free/unref BEFORE doing the merge! // Some of the blocks might not be valid anymore later! - r_anal_block_unref (block); + rz_anal_block_unref (block); ht_up_free (succs); ut64 block_addr = block->addr; // save the addr to identify the block. the automerge might free it so we must not use the pointer! // Do the actual merge - r_anal_block_automerge (&merge_blocks); + rz_anal_block_automerge (&merge_blocks); // No try to recover the pointer to the block if it still exists - RAnalBlock *ret = NULL; + RzAnalBlock *ret = NULL; for (it = merge_blocks.head; it && (block = it->data, 1); it = it->n) { if (block->addr == block_addr) { // block is still there @@ -768,29 +768,29 @@ R_API RAnalBlock *r_anal_block_chop_noreturn(RAnalBlock *block, ut64 addr) { } } - r_list_purge (&merge_blocks); + rz_list_purge (&merge_blocks); return ret; } typedef struct { HtUP *predecessors; // maps a block to its predecessor if it has exactly one, or NULL if there are multiple or the predecessor has multiple successors HtUP *visited_blocks; // during predecessor search, mark blocks whose successors we already checked. Value is void *-casted count of successors - HtUP *blocks; // adresses of the blocks we might want to merge with their predecessors => RAnalBlock * + HtUP *blocks; // adresses of the blocks we might want to merge with their predecessors => RzAnalBlock * - RAnalBlock *cur_pred; + RzAnalBlock *cur_pred; size_t cur_succ_count; } AutomergeCtx; static bool automerge_predecessor_successor_cb(ut64 addr, void *user) { AutomergeCtx *ctx = user; ctx->cur_succ_count++; - RAnalBlock *block = ht_up_find (ctx->blocks, addr, NULL); + RzAnalBlock *block = ht_up_find (ctx->blocks, addr, NULL); if (!block) { // we shouldn't merge this one so GL_DONT_CARE return true; } bool found; - RAnalBlock *pred = ht_up_find (ctx->predecessors, (ut64)block, &found); + RzAnalBlock *pred = ht_up_find (ctx->predecessors, (ut64)block, &found); if (found) { if (pred) { // only one predecessor found so far, but we are the second so there are multiple now @@ -805,10 +805,10 @@ static bool automerge_predecessor_successor_cb(ut64 addr, void *user) { static bool automerge_get_predecessors_cb(void *user, const ut64 k, const void *v) { AutomergeCtx *ctx = user; - const RAnalFunction *fcn = (const RAnalFunction *)k; - RListIter *it; - RAnalBlock *block; - r_list_foreach (fcn->bbs, it, block) { + const RzAnalFunction *fcn = (const RzAnalFunction *)k; + RzListIter *it; + RzAnalBlock *block; + rz_list_foreach (fcn->bbs, it, block) { bool already_visited; ht_up_find (ctx->visited_blocks, (ut64)block, &already_visited); if (already_visited) { @@ -816,7 +816,7 @@ static bool automerge_get_predecessors_cb(void *user, const ut64 k, const void * } ctx->cur_pred = block; ctx->cur_succ_count = 0; - r_anal_block_successor_addrs_foreach (block, automerge_predecessor_successor_cb, ctx); + rz_anal_block_successor_addrs_foreach (block, automerge_predecessor_successor_cb, ctx); ht_up_insert (ctx->visited_blocks, (ut64)block, (void *)ctx->cur_succ_count); } return true; @@ -824,8 +824,8 @@ static bool automerge_get_predecessors_cb(void *user, const ut64 k, const void * // Try to find the contiguous predecessors of all given blocks and merge them if possible, // i.e. if there are no other blocks that have this block as one of their successors -R_API void r_anal_block_automerge(RList *blocks) { - r_return_if_fail (blocks); +RZ_API void rz_anal_block_automerge(RzList *blocks) { + rz_return_if_fail (blocks); AutomergeCtx ctx = { .predecessors = ht_up_new0 (), .visited_blocks = ht_up_new0 (), @@ -833,18 +833,18 @@ R_API void r_anal_block_automerge(RList *blocks) { }; HtUP *relevant_fcns = ht_up_new0 (); // all the functions that contain some of our blocks (ht abused as a set) - RList *fixup_candidates = r_list_new (); // used further down + RzList *fixup_candidates = rz_list_new (); // used further down if (!ctx.predecessors || !ctx.visited_blocks || !ctx.blocks || !relevant_fcns || !fixup_candidates) { goto beach; } // Get all the functions and prepare ctx.blocks - RListIter *it; - RAnalBlock *block; - r_list_foreach (blocks, it, block) { - RListIter *fit; - RAnalFunction *fcn; - r_list_foreach (block->fcns, fit, fcn) { + RzListIter *it; + RzAnalBlock *block; + rz_list_foreach (blocks, it, block) { + RzListIter *fit; + RzAnalFunction *fcn; + rz_list_foreach (block->fcns, fit, fcn) { ht_up_insert (relevant_fcns, (ut64)fcn, NULL); } ht_up_insert (ctx.blocks, block->addr, block); @@ -854,9 +854,9 @@ R_API void r_anal_block_automerge(RList *blocks) { ht_up_foreach (relevant_fcns, automerge_get_predecessors_cb, &ctx); // Now finally do the merging - RListIter *tmp; - r_list_foreach_safe (blocks, it, tmp, block) { - RAnalBlock *predecessor = ht_up_find (ctx.predecessors, (ut64)block, NULL); + RzListIter *tmp; + rz_list_foreach_safe (blocks, it, tmp, block) { + RzAnalBlock *predecessor = ht_up_find (ctx.predecessors, (ut64)block, NULL); if (!predecessor) { continue; } @@ -869,27 +869,27 @@ R_API void r_anal_block_automerge(RList *blocks) { // We are about to merge block into predecessor // However if there are other blocks that have block as the predecessor, // we would uaf after the merge since block will be freed. - RListIter *bit; - RAnalBlock *clock; + RzListIter *bit; + RzAnalBlock *clock; for (bit = it->n; bit && (clock = bit->data, 1); bit = bit->n) { - RAnalBlock *fixup_pred = ht_up_find (ctx.predecessors, (ut64)clock, NULL); + RzAnalBlock *fixup_pred = ht_up_find (ctx.predecessors, (ut64)clock, NULL); if (fixup_pred == block) { - r_list_push (fixup_candidates, clock); + rz_list_push (fixup_candidates, clock); } } - if (r_anal_block_merge (predecessor, block)) { // r_anal_block_merge() does checks like contiguous, to that's fine + if (rz_anal_block_merge (predecessor, block)) { // rz_anal_block_merge() does checks like contiguous, to that's fine // block was merged into predecessor, it is now freed! - r_list_foreach (fixup_candidates, bit, clock) { + rz_list_foreach (fixup_candidates, bit, clock) { // Make sure all previous pointers to block now go to predecessor ht_up_update (ctx.predecessors, (ut64)clock, predecessor); } // Remove it from the list - r_list_split_iter (blocks, it); + rz_list_split_iter (blocks, it); free (it); } - r_list_purge (fixup_candidates); + rz_list_purge (fixup_candidates); } beach: @@ -897,5 +897,5 @@ beach: ht_up_free (ctx.visited_blocks); ht_up_free (ctx.blocks); ht_up_free (relevant_fcns); - r_list_free (fixup_candidates); + rz_list_free (fixup_candidates); } diff --git a/librz/anal/cc.c b/librz/anal/cc.c new file mode 100644 index 0000000000..d0d2ee79cd --- /dev/null +++ b/librz/anal/cc.c @@ -0,0 +1,204 @@ +/* radare - LGPL - Copyright 2011-2020 - pancake, Oddcoder */ + +/* Universal calling convention implementation based on sdb */ + +#include +#define DB anal->sdb_cc + +RZ_API void rz_anal_cc_del(RzAnal *anal, const char *name) { + size_t i; + RStrBuf sb; + sdb_unset (DB, rz_strbuf_initf (&sb, "%s", name), 0); + sdb_unset (DB, rz_strbuf_setf (&sb, "cc.%s.ret", name), 0); + sdb_unset (DB, rz_strbuf_setf (&sb, "cc.%s.argn", name), 0); + for (i = 0; i < R_ANAL_CC_MAXARG; i++) { + sdb_unset (DB, rz_strbuf_setf (&sb, "cc.%s.arg%d", name, i), 0); + } + sdb_unset (DB, rz_strbuf_setf (&sb, "cc.%s.self", name), 0); + sdb_unset (DB, rz_strbuf_setf (&sb, "cc.%s.error", name), 0); + rz_strbuf_fini (&sb); +} + +RZ_API bool rz_anal_cc_set(RzAnal *anal, const char *expr) { + char *e = strdup (expr); + char *p = strchr (e, '('); + if (!p) { + free (e); + return false; + } + *p++ = 0; + char *args = strdup (p); + rz_str_trim (p); + char *end = strchr (args, ')'); + if (!end) { + free (args); + free (e); + return false; + } + *end++ = 0; + rz_str_trim (p); + rz_str_trim (e); + char *ccname = strchr (e, ' '); + if (ccname) { + *ccname++ = 0; + rz_str_trim (ccname); + } else { + free (args); + free (e); + return false; + } + sdb_set (DB, ccname, "cc", 0); + sdb_set (DB, sdb_fmt ("cc.%s.ret", ccname), e, 0); + + RzList *ccArgs = rz_str_split_list (args, ",", 0); + RzListIter *iter; + const char *arg; + int n = 0; + rz_list_foreach (ccArgs, iter, arg) { + if (!strcmp (arg, "stack")) { + sdb_set (DB, sdb_fmt ("cc.%s.argn", ccname), arg, 0); + } else { + sdb_set (DB, sdb_fmt ("cc.%s.arg%d", ccname, n), arg, 0); + n++; + } + } + rz_list_free (ccArgs); + free (e); + free (args); + return true; +} + +RZ_API char *rz_anal_cc_get(RzAnal *anal, const char *name) { + int i; + // get cc by name and print the expr + if (rz_str_cmp (sdb_const_get (DB, name, 0), "cc", -1)) { + eprintf ("This is not a valid calling convention name\n"); + return NULL; + } + const char *ret = sdb_const_get (DB, sdb_fmt ("cc.%s.ret", name), 0); + if (!ret) { + eprintf ("Cannot find return key\n"); + return NULL; + } + RStrBuf *sb = rz_strbuf_new (NULL); + const char *self = rz_anal_cc_self (anal, name); + rz_strbuf_appendf (sb, "%s %s%s%s (", ret, self? self: "", self? ".": "", name); + bool isFirst = true; + for (i = 0; i < R_ANAL_CC_MAXARG; i++) { + const char *k = sdb_fmt ("cc.%s.arg%d", name, i); + const char *arg = sdb_const_get (DB, k, 0); + if (!arg) { + break; + } + rz_strbuf_appendf (sb, "%s%s", isFirst? "": ", ", arg); + isFirst = false; + } + const char *argn = sdb_const_get (DB, sdb_fmt ("cc.%s.argn", name), 0); + if (argn) { + rz_strbuf_appendf (sb, "%s%s", isFirst? "": ", ", argn); + } + rz_strbuf_append (sb, ")"); + + const char *error = rz_anal_cc_error (anal, name); + if (error) { + rz_strbuf_appendf (sb, " %s", error); + } + + rz_strbuf_append (sb, ";"); + return rz_strbuf_drain (sb); +} + +RZ_API bool rz_anal_cc_exist(RzAnal *anal, const char *convention) { + rz_return_val_if_fail (anal && convention, false); + const char *x = sdb_const_get (DB, convention, 0); + return x && *x && !strcmp (x, "cc"); +} + +RZ_API const char *rz_anal_cc_arg(RzAnal *anal, const char *convention, int n) { + rz_return_val_if_fail (anal, NULL); + rz_return_val_if_fail (n >= 0, NULL); + if (!convention) { + return NULL; + } + + const char *query = sdb_fmt ("cc.%s.arg%d", convention, n); + const char *ret = sdb_const_get (DB, query, 0); + if (!ret) { + query = sdb_fmt ("cc.%s.argn", convention); + ret = sdb_const_get (DB, query, 0); + } + return ret? rz_str_constpool_get (&anal->constpool, ret): NULL; +} + +RZ_API const char *rz_anal_cc_self(RzAnal *anal, const char *convention) { + rz_return_val_if_fail (anal && convention, NULL); + const char *query = sdb_fmt ("cc.%s.self", convention); + const char *self = sdb_const_get (DB, query, 0); + return self? rz_str_constpool_get (&anal->constpool, self): NULL; +} + +RZ_API void rz_anal_cc_set_self(RzAnal *anal, const char *convention, const char *self) { + if (!rz_anal_cc_exist (anal, convention)) { + return; + } + RStrBuf sb; + sdb_set (anal->sdb_cc, rz_strbuf_initf (&sb, "cc.%s.self", convention), self, 0); + rz_strbuf_fini (&sb); +} + +RZ_API const char *rz_anal_cc_error(RzAnal *anal, const char *convention) { + rz_return_val_if_fail (anal && convention, NULL); + const char *query = sdb_fmt ("cc.%s.error", convention); + const char *error = sdb_const_get (DB, query, 0); + return error? rz_str_constpool_get (&anal->constpool, error): NULL; +} + +RZ_API void rz_anal_cc_set_error(RzAnal *anal, const char *convention, const char *error) { + if (!rz_anal_cc_exist (anal, convention)) { + return; + } + RStrBuf sb; + sdb_set (anal->sdb_cc, rz_strbuf_initf (&sb, "cc.%s.error", convention), error, 0); + rz_strbuf_fini (&sb); +} + +RZ_API int rz_anal_cc_max_arg(RzAnal *anal, const char *cc) { + int i = 0; + rz_return_val_if_fail (anal && DB && cc, 0); + static void *oldDB = NULL; + static char *oldCC = NULL; + static int oldArg = 0; + if (oldDB == DB && !strcmp (cc, oldCC)) { + return oldArg; + } + oldDB = DB; + free (oldCC); + oldCC = strdup (cc); + for (i = 0; i < R_ANAL_CC_MAXARG; i++) { + const char *query = sdb_fmt ("cc.%s.arg%d", cc, i); + const char *res = sdb_const_get (DB, query, 0); + if (!res) { + break; + } + } + oldArg = i; + return i; +} + +RZ_API const char *rz_anal_cc_ret(RzAnal *anal, const char *convention) { + rz_return_val_if_fail (anal && convention, NULL); + char *query = sdb_fmt ("cc.%s.ret", convention); + return sdb_const_get (DB, query, 0); +} + +RZ_API const char *rz_anal_cc_default(RzAnal *anal) { + rz_return_val_if_fail (anal, NULL); + return sdb_const_get (DB, "default.cc", 0); +} + +RZ_API const char *rz_anal_cc_func(RzAnal *anal, const char *func_name) { + rz_return_val_if_fail (anal && func_name, NULL); + const char *query = sdb_fmt ("func.%s.cc", func_name); + const char *cc = sdb_const_get (anal->sdb_types, query, 0); + return cc ? cc : rz_anal_cc_default (anal); +} diff --git a/libr/anal/class.c b/librz/anal/class.c similarity index 51% rename from libr/anal/class.c rename to librz/anal/class.c index 41ef00050e..369465c529 100644 --- a/libr/anal/class.c +++ b/librz/anal/class.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2018 - thestr4ng3r */ -#include -#include -#include "../include/r_anal.h" -#include "../include/r_util/r_graph.h" +#include +#include +#include "../include/rz_anal.h" +#include "../include/rz_util/rz_graph.h" -static void r_anal_class_base_delete_class(RAnal *anal, const char *class_name); -static void r_anal_class_method_delete_class(RAnal *anal, const char *class_name); -static void r_anal_class_vtable_delete_class(RAnal *anal, const char *class_name); -static void r_anal_class_base_rename_class(RAnal *anal, const char *class_name_old, const char *class_name_new); -static void r_anal_class_method_rename_class(RAnal *anal, const char *old_class_name, const char *new_class_name); -static void r_anal_class_vtable_rename_class(RAnal *anal, const char *old_class_name, const char *new_class_name); +static void rz_anal_class_base_delete_class(RzAnal *anal, const char *class_name); +static void rz_anal_class_method_delete_class(RzAnal *anal, const char *class_name); +static void rz_anal_class_vtable_delete_class(RzAnal *anal, const char *class_name); +static void rz_anal_class_base_rename_class(RzAnal *anal, const char *class_name_old, const char *class_name_new); +static void rz_anal_class_method_rename_class(RzAnal *anal, const char *old_class_name, const char *new_class_name); +static void rz_anal_class_vtable_rename_class(RzAnal *anal, const char *old_class_name, const char *new_class_name); static const char *key_class(const char *name) { return name; @@ -36,9 +36,9 @@ typedef enum { R_ANAL_CLASS_ATTR_TYPE_METHOD, R_ANAL_CLASS_ATTR_TYPE_VTABLE, R_ANAL_CLASS_ATTR_TYPE_BASE -} RAnalClassAttrType; +} RzAnalClassAttrType; -static const char *attr_type_id(RAnalClassAttrType attr_type) { +static const char *attr_type_id(RzAnalClassAttrType attr_type) { switch (attr_type) { case R_ANAL_CLASS_ATTR_TYPE_METHOD: return "method"; @@ -51,8 +51,8 @@ static const char *attr_type_id(RAnalClassAttrType attr_type) { } } -R_API void r_anal_class_create(RAnal *anal, const char *name) { - char *name_sanitized = r_str_sanitize_sdb_key (name); +RZ_API void rz_anal_class_create(RzAnal *anal, const char *name) { + char *name_sanitized = rz_str_sanitize_sdb_key (name); if (!name_sanitized) { return; } @@ -62,21 +62,21 @@ R_API void r_anal_class_create(RAnal *anal, const char *name) { } REventClass event = { .name = name_sanitized }; - r_event_send (anal->ev, R_EVENT_CLASS_NEW, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_NEW, &event); free (name_sanitized); } -R_API void r_anal_class_delete(RAnal *anal, const char *name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (name); +RZ_API void rz_anal_class_delete(RzAnal *anal, const char *name) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (name); if (!class_name_sanitized) { return; } - r_anal_class_base_delete_class (anal, class_name_sanitized); - r_anal_class_method_delete_class (anal, class_name_sanitized); - r_anal_class_vtable_delete_class (anal, class_name_sanitized); + rz_anal_class_base_delete_class (anal, class_name_sanitized); + rz_anal_class_method_delete_class (anal, class_name_sanitized); + rz_anal_class_vtable_delete_class (anal, class_name_sanitized); if (!sdb_remove (anal->sdb_classes, key_class (class_name_sanitized), 0)) { free (class_name_sanitized); @@ -109,30 +109,30 @@ R_API void r_anal_class_delete(RAnal *anal, const char *name) { sdb_remove (anal->sdb_classes_attrs, key_attr_types (class_name_sanitized), 0); REventClass event = { .name = class_name_sanitized }; - r_event_send (anal->ev, R_EVENT_CLASS_DEL, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_DEL, &event); free (class_name_sanitized); } -static bool r_anal_class_exists_raw(RAnal *anal, const char *name) { +static bool rz_anal_class_exists_raw(RzAnal *anal, const char *name) { return sdb_exists (anal->sdb_classes, key_class (name)); } -R_API bool r_anal_class_exists(RAnal *anal, const char *name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (name); +RZ_API bool rz_anal_class_exists(RzAnal *anal, const char *name) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (name); if (!class_name_sanitized) { return false; } - bool r = r_anal_class_exists_raw (anal, class_name_sanitized); + bool r = rz_anal_class_exists_raw (anal, class_name_sanitized); free (class_name_sanitized); return r; } -R_API SdbList *r_anal_class_get_all(RAnal *anal, bool sorted) { +RZ_API SdbList *rz_anal_class_get_all(RzAnal *anal, bool sorted) { return sdb_foreach_list (anal->sdb_classes, sorted); } -R_API void r_anal_class_foreach(RAnal *anal, SdbForeachCallback cb, void *user) { +RZ_API void rz_anal_class_foreach(RzAnal *anal, SdbForeachCallback cb, void *user) { sdb_foreach (anal->sdb_classes, cb, user); } @@ -147,26 +147,26 @@ static bool rename_key(Sdb *sdb, const char *key_old, const char *key_new) { return true; } -R_API RAnalClassErr r_anal_class_rename(RAnal *anal, const char *old_name, const char *new_name) { - if (r_anal_class_exists (anal, new_name)) { +RZ_API RzAnalClassErr rz_anal_class_rename(RzAnal *anal, const char *old_name, const char *new_name) { + if (rz_anal_class_exists (anal, new_name)) { return R_ANAL_CLASS_ERR_CLASH; } - char *old_name_sanitized = r_str_sanitize_sdb_key (old_name); + char *old_name_sanitized = rz_str_sanitize_sdb_key (old_name); if (!old_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *new_name_sanitized = r_str_sanitize_sdb_key (new_name); + char *new_name_sanitized = rz_str_sanitize_sdb_key (new_name); if (!new_name_sanitized) { free (old_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; + RzAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; - r_anal_class_base_rename_class (anal, old_name, new_name); - r_anal_class_method_rename_class (anal, old_name, new_name); - r_anal_class_vtable_rename_class (anal, old_name, new_name); + rz_anal_class_base_rename_class (anal, old_name, new_name); + rz_anal_class_method_rename_class (anal, old_name, new_name); + rz_anal_class_vtable_rename_class (anal, old_name, new_name); if (!rename_key (anal->sdb_classes, key_class (old_name_sanitized), key_class (new_name_sanitized))) { err = R_ANAL_CLASS_ERR_NONEXISTENT_CLASS; @@ -198,7 +198,7 @@ R_API RAnalClassErr r_anal_class_rename(RAnal *anal, const char *old_name, const .name_old = old_name_sanitized, .name_new = new_name_sanitized }; - r_event_send (anal->ev, R_EVENT_CLASS_RENAME, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_RENAME, &event); beach: free (old_name_sanitized); @@ -207,7 +207,7 @@ beach: } // all ids must be sanitized -static char *r_anal_class_get_attr_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id, bool specific) { +static char *rz_anal_class_get_attr_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id, bool specific) { const char *attr_type_str = attr_type_id (attr_type); char *key = specific ? key_attr_content_specific (class_name, attr_type_str, attr_id) @@ -217,18 +217,18 @@ static char *r_anal_class_get_attr_raw(RAnal *anal, const char *class_name, RAna } // ids will be sanitized automatically -static char *r_anal_class_get_attr(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id, bool specific) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +static char *rz_anal_class_get_attr(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id, bool specific) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return false; } - char *attr_id_sanitized = r_str_sanitize_sdb_key (attr_id); + char *attr_id_sanitized = rz_str_sanitize_sdb_key (attr_id); if (!attr_id_sanitized) { free (class_name_sanitized); return false; } - char *ret = r_anal_class_get_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized, specific); + char *ret = rz_anal_class_get_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized, specific); free (class_name_sanitized); free (attr_id_sanitized); @@ -237,10 +237,10 @@ static char *r_anal_class_get_attr(RAnal *anal, const char *class_name, RAnalCla } // all ids must be sanitized -static RAnalClassErr r_anal_class_set_attr_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id, const char *content) { +static RzAnalClassErr rz_anal_class_set_attr_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id, const char *content) { const char *attr_type_str = attr_type_id (attr_type); - if (!r_anal_class_exists_raw (anal, class_name)) { + if (!rz_anal_class_exists_raw (anal, class_name)) { return R_ANAL_CLASS_ERR_NONEXISTENT_CLASS; } @@ -256,25 +256,25 @@ static RAnalClassErr r_anal_class_set_attr_raw(RAnal *anal, const char *class_na }, .content = content }; - r_event_send (anal->ev, R_EVENT_CLASS_ATTR_SET, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_ATTR_SET, &event); return R_ANAL_CLASS_ERR_SUCCESS; } // ids will be sanitized automatically -static RAnalClassErr r_anal_class_set_attr(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id, const char *content) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +static RzAnalClassErr rz_anal_class_set_attr(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id, const char *content) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *attr_id_sanitized = r_str_sanitize_sdb_key (attr_id); + char *attr_id_sanitized = rz_str_sanitize_sdb_key (attr_id); if (!attr_id_sanitized) { free (class_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_set_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized, content); + RzAnalClassErr err = rz_anal_class_set_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized, content); free (class_name_sanitized); free (attr_id_sanitized); @@ -282,7 +282,7 @@ static RAnalClassErr r_anal_class_set_attr(RAnal *anal, const char *class_name, return err; } -static RAnalClassErr r_anal_class_delete_attr_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id) { +static RzAnalClassErr rz_anal_class_delete_attr_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id) { const char *attr_type_str = attr_type_id (attr_type); char *key = key_attr_content (class_name, attr_type_str, attr_id); @@ -301,31 +301,31 @@ static RAnalClassErr r_anal_class_delete_attr_raw(RAnal *anal, const char *class .attr_type = attr_type, .attr_id = attr_id }; - r_event_send (anal->ev, R_EVENT_CLASS_ATTR_DEL, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_ATTR_DEL, &event); return R_ANAL_CLASS_ERR_SUCCESS; } -static RAnalClassErr r_anal_class_delete_attr(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +static RzAnalClassErr rz_anal_class_delete_attr(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *attr_id_sanitized = r_str_sanitize_sdb_key (attr_id); + char *attr_id_sanitized = rz_str_sanitize_sdb_key (attr_id); if (!attr_id_sanitized) { free (class_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_delete_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized); + RzAnalClassErr err = rz_anal_class_delete_attr_raw (anal, class_name_sanitized, attr_type, attr_id_sanitized); free (class_name_sanitized); free (attr_id_sanitized); return err; } -static RAnalClassErr r_anal_class_rename_attr_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id_old, const char *attr_id_new) { +static RzAnalClassErr rz_anal_class_rename_attr_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id_old, const char *attr_id_new) { const char *attr_type_str = attr_type_id (attr_type); char *key = key_attr_type_attrs (class_name, attr_type_str); @@ -365,35 +365,35 @@ static RAnalClassErr r_anal_class_rename_attr_raw(RAnal *anal, const char *class }, .attr_id_new = attr_id_new }; - r_event_send (anal->ev, R_EVENT_CLASS_ATTR_RENAME, &event); + rz_event_send (anal->ev, R_EVENT_CLASS_ATTR_RENAME, &event); return R_ANAL_CLASS_ERR_SUCCESS; } -static RAnalClassErr r_anal_class_rename_attr(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *attr_id_old, const char *attr_id_new) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +static RzAnalClassErr rz_anal_class_rename_attr(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *attr_id_old, const char *attr_id_new) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *attr_id_old_sanitized = r_str_sanitize_sdb_key (attr_id_old); + char *attr_id_old_sanitized = rz_str_sanitize_sdb_key (attr_id_old); if (!attr_id_old_sanitized) { free (class_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - char *attr_id_new_sanitized = r_str_sanitize_sdb_key (attr_id_new); + char *attr_id_new_sanitized = rz_str_sanitize_sdb_key (attr_id_new); if (!attr_id_new_sanitized) { free (class_name_sanitized); free (attr_id_old_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr ret = r_anal_class_rename_attr_raw (anal, class_name_sanitized, attr_type, attr_id_old_sanitized, attr_id_new_sanitized); + RzAnalClassErr ret = rz_anal_class_rename_attr_raw (anal, class_name_sanitized, attr_type, attr_id_old_sanitized, attr_id_new_sanitized); free (class_name_sanitized); free (attr_id_old_sanitized); free (attr_id_new_sanitized); return ret; } -static void r_anal_class_unique_attr_id_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, char *out, size_t out_size) { +static void rz_anal_class_unique_attr_id_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, char *out, size_t out_size) { ut64 id = 0; char *key = key_attr_type_attrs (class_name, attr_type_id (attr_type)); do { @@ -403,11 +403,11 @@ static void r_anal_class_unique_attr_id_raw(RAnal *anal, const char *class_name, } static char *flagname_attr(const char *attr_type, const char *class_name, const char *attr_id) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return NULL; } - char *attr_id_sanitized = r_str_sanitize_sdb_key (attr_id); + char *attr_id_sanitized = rz_str_sanitize_sdb_key (attr_id); if (!attr_id_sanitized) { free (class_name_sanitized); return NULL; @@ -418,14 +418,14 @@ static char *flagname_attr(const char *attr_type, const char *class_name, const return r; } -static void r_anal_class_set_flag(RAnal *anal, const char *name, ut64 addr, ut32 size) { +static void rz_anal_class_set_flag(RzAnal *anal, const char *name, ut64 addr, ut32 size) { if (!name || !anal->flg_class_set) { return; } anal->flg_class_set (anal->flb.f, name, addr, size); } -static void r_anal_class_unset_flag(RAnal *anal, const char *name) { +static void rz_anal_class_unset_flag(RzAnal *anal, const char *name) { if (!name || !anal->flb.unset_name || !anal->flg_class_get) { return; } @@ -434,11 +434,11 @@ static void r_anal_class_unset_flag(RAnal *anal, const char *name) { } } -static void r_anal_class_rename_flag(RAnal *anal, const char *old_name, const char *new_name) { +static void rz_anal_class_rename_flag(RzAnal *anal, const char *old_name, const char *new_name) { if (!old_name || !new_name || !anal->flb.unset || !anal->flg_class_get || !anal->flg_class_set) { return; } - RFlagItem *flag = anal->flg_class_get (anal->flb.f, old_name); + RzFlagItem *flag = anal->flg_class_get (anal->flb.f, old_name); if (!flag) { return; } @@ -447,29 +447,29 @@ static void r_anal_class_rename_flag(RAnal *anal, const char *old_name, const ch anal->flg_class_set (anal->flb.f, new_name, addr, 0); } -static RAnalClassErr r_anal_class_add_attr_unique_raw(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *content, char *attr_id_out, size_t attr_id_out_size) { +static RzAnalClassErr rz_anal_class_add_attr_unique_raw(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *content, char *attr_id_out, size_t attr_id_out_size) { char attr_id[16]; - r_anal_class_unique_attr_id_raw (anal, class_name, attr_type, attr_id, sizeof(attr_id)); + rz_anal_class_unique_attr_id_raw (anal, class_name, attr_type, attr_id, sizeof(attr_id)); - RAnalClassErr err = r_anal_class_set_attr (anal, class_name, attr_type, attr_id, content); + RzAnalClassErr err = rz_anal_class_set_attr (anal, class_name, attr_type, attr_id, content); if (err != R_ANAL_CLASS_ERR_SUCCESS) { return err; } if (attr_id_out) { - r_str_ncpy (attr_id_out, attr_id, attr_id_out_size); + rz_str_ncpy (attr_id_out, attr_id, attr_id_out_size); } return R_ANAL_CLASS_ERR_SUCCESS; } -static RAnalClassErr r_anal_class_add_attr_unique(RAnal *anal, const char *class_name, RAnalClassAttrType attr_type, const char *content, char *attr_id_out, size_t attr_id_out_size) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +static RzAnalClassErr rz_anal_class_add_attr_unique(RzAnal *anal, const char *class_name, RzAnalClassAttrType attr_type, const char *content, char *attr_id_out, size_t attr_id_out_size) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_add_attr_unique_raw (anal, class_name_sanitized, attr_type, content, attr_id_out, attr_id_out_size); + RzAnalClassErr err = rz_anal_class_add_attr_unique_raw (anal, class_name_sanitized, attr_type, content, attr_id_out, attr_id_out_size); free (class_name_sanitized); return err; @@ -483,14 +483,14 @@ static char *flagname_method(const char *class_name, const char *meth_name) { return flagname_attr ("method", class_name, meth_name); } -R_API void r_anal_class_method_fini(RAnalMethod *meth) { +RZ_API void rz_anal_class_method_fini(RzAnalMethod *meth) { free (meth->name); } // if the method exists: store it in *meth and return R_ANAL_CLASS_ERR_SUCCESS // else return the error, contents of *meth are undefined -R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, const char *meth_name, RAnalMethod *meth) { - char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth_name, false); +RZ_API RzAnalClassErr rz_anal_class_method_get(RzAnal *anal, const char *class_name, const char *meth_name, RzAnalMethod *meth) { + char *content = rz_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth_name, false); if (!content) { return R_ANAL_CLASS_ERR_NONEXISTENT_ATTR; } @@ -499,7 +499,7 @@ R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, char *next; sdb_anext (cur, &next); - meth->addr = r_num_math (NULL, cur); + meth->addr = rz_num_math (NULL, cur); cur = next; if (!cur) { @@ -512,7 +512,7 @@ R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, free (content); - meth->name = r_str_sanitize_sdb_key (meth_name); + meth->name = rz_str_sanitize_sdb_key (meth_name); if (!meth->name) { return R_ANAL_CLASS_ERR_OTHER; } @@ -520,32 +520,32 @@ R_API RAnalClassErr r_anal_class_method_get(RAnal *anal, const char *class_name, return R_ANAL_CLASS_ERR_SUCCESS; } -static void r_anal_class_method_fini_proxy(void *e, void *user) { +static void rz_anal_class_method_fini_proxy(void *e, void *user) { (void)user; - RAnalMethod *meth = e; - r_anal_class_method_fini (meth); + RzAnalMethod *meth = e; + rz_anal_class_method_fini (meth); } -R_API RVector/**/ *r_anal_class_method_get_all(RAnal *anal, const char *class_name) { - RVector *vec = r_vector_new (sizeof(RAnalMethod), r_anal_class_method_fini_proxy, NULL); +RZ_API RzVector/**/ *rz_anal_class_method_get_all(RzAnal *anal, const char *class_name) { + RzVector *vec = rz_vector_new (sizeof(RzAnalMethod), rz_anal_class_method_fini_proxy, NULL); if (!vec) { return NULL; } - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { - r_vector_free (vec); + rz_vector_free (vec); return NULL; } char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (class_name_sanitized, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_METHOD)), 0); free (class_name_sanitized); - r_vector_reserve (vec, (size_t) sdb_alen (array)); + rz_vector_reserve (vec, (size_t) sdb_alen (array)); char *cur; sdb_aforeach (cur, array) { - RAnalMethod meth; - if (r_anal_class_method_get (anal, class_name, cur, &meth) == R_ANAL_CLASS_ERR_SUCCESS) { - r_vector_push (vec, &meth); + RzAnalMethod meth; + if (rz_anal_class_method_get (anal, class_name, cur, &meth) == R_ANAL_CLASS_ERR_SUCCESS) { + rz_vector_push (vec, &meth); } sdb_aforeach_next (cur); } @@ -554,35 +554,35 @@ R_API RVector/**/ *r_anal_class_method_get_all(RAnal *anal, const c return vec; } -R_API RAnalClassErr r_anal_class_method_set(RAnal *anal, const char *class_name, RAnalMethod *meth) { +RZ_API RzAnalClassErr rz_anal_class_method_set(RzAnal *anal, const char *class_name, RzAnalMethod *meth) { char *content = sdb_fmt ("%"PFMT64u"%c%d", meth->addr, SDB_RS, meth->vtable_offset); - RAnalClassErr err = r_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth->name, content); + RzAnalClassErr err = rz_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth->name, content); if (err != R_ANAL_CLASS_ERR_SUCCESS) { return err; } - r_anal_class_set_flag (anal, flagname_method (class_name, meth->name), meth->addr, 0); + rz_anal_class_set_flag (anal, flagname_method (class_name, meth->name), meth->addr, 0); return R_ANAL_CLASS_ERR_SUCCESS; } -R_API RAnalClassErr r_anal_class_method_rename(RAnal *anal, const char *class_name, const char *old_meth_name, const char *new_meth_name) { - RAnalClassErr err = r_anal_class_rename_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, old_meth_name, new_meth_name); +RZ_API RzAnalClassErr rz_anal_class_method_rename(RzAnal *anal, const char *class_name, const char *old_meth_name, const char *new_meth_name) { + RzAnalClassErr err = rz_anal_class_rename_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_METHOD, old_meth_name, new_meth_name); if (err != R_ANAL_CLASS_ERR_SUCCESS) { return err; } - r_anal_class_rename_flag (anal, + rz_anal_class_rename_flag (anal, flagname_method (class_name, old_meth_name), flagname_method (class_name, new_meth_name)); return R_ANAL_CLASS_ERR_SUCCESS; } -static void r_anal_class_method_rename_class(RAnal *anal, const char *old_class_name, const char *new_class_name) { +static void rz_anal_class_method_rename_class(RzAnal *anal, const char *old_class_name, const char *new_class_name) { char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (old_class_name, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_METHOD)), 0); if (!array) { return; } char *cur; sdb_aforeach (cur, array) { - r_anal_class_rename_flag (anal, + rz_anal_class_rename_flag (anal, flagname_method (old_class_name, cur), flagname_method (new_class_name, cur)); sdb_aforeach_next (cur); @@ -590,32 +590,32 @@ static void r_anal_class_method_rename_class(RAnal *anal, const char *old_class_ free (array); } -static void r_anal_class_method_delete_class(RAnal *anal, const char *class_name) { +static void rz_anal_class_method_delete_class(RzAnal *anal, const char *class_name) { char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (class_name, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_METHOD)), 0); if (!array) { return; } char *cur; sdb_aforeach (cur, array) { - r_anal_class_unset_flag (anal, flagname_method (class_name, cur)); + rz_anal_class_unset_flag (anal, flagname_method (class_name, cur)); sdb_aforeach_next (cur); } free (array); } -R_API RAnalClassErr r_anal_class_method_delete(RAnal *anal, const char *class_name, const char *meth_name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +RZ_API RzAnalClassErr rz_anal_class_method_delete(RzAnal *anal, const char *class_name, const char *meth_name) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *meth_name_sanitized = r_str_sanitize_sdb_key (meth_name); + char *meth_name_sanitized = rz_str_sanitize_sdb_key (meth_name); if (!meth_name_sanitized) { free (class_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_delete_attr_raw (anal, class_name_sanitized, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth_name_sanitized); + RzAnalClassErr err = rz_anal_class_delete_attr_raw (anal, class_name_sanitized, R_ANAL_CLASS_ATTR_TYPE_METHOD, meth_name_sanitized); if (err == R_ANAL_CLASS_ERR_SUCCESS) { - r_anal_class_unset_flag (anal, flagname_method (class_name_sanitized, meth_name_sanitized)); + rz_anal_class_unset_flag (anal, flagname_method (class_name_sanitized, meth_name_sanitized)); } free (class_name_sanitized); free (meth_name_sanitized); @@ -625,13 +625,13 @@ R_API RAnalClassErr r_anal_class_method_delete(RAnal *anal, const char *class_na // ---- BASE ---- -R_API void r_anal_class_base_fini(RAnalBaseClass *base) { +RZ_API void rz_anal_class_base_fini(RzAnalBaseClass *base) { free (base->id); free (base->class_name); } -R_API RAnalClassErr r_anal_class_base_get(RAnal *anal, const char *class_name, const char *base_id, RAnalBaseClass *base) { - char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base_id, false); +RZ_API RzAnalClassErr rz_anal_class_base_get(RzAnal *anal, const char *class_name, const char *base_id, RzAnalBaseClass *base) { + char *content = rz_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base_id, false); if (!content) { return R_ANAL_CLASS_ERR_NONEXISTENT_ATTR; } @@ -654,11 +654,11 @@ R_API RAnalClassErr r_anal_class_base_get(RAnal *anal, const char *class_name, c } sdb_anext (cur, NULL); - base->offset = r_num_math (NULL, cur); + base->offset = rz_num_math (NULL, cur); free (content); - base->id = r_str_sanitize_sdb_key (base_id); + base->id = rz_str_sanitize_sdb_key (base_id); if (!base->id) { free (base->class_name); return R_ANAL_CLASS_ERR_OTHER; @@ -667,32 +667,32 @@ R_API RAnalClassErr r_anal_class_base_get(RAnal *anal, const char *class_name, c return R_ANAL_CLASS_ERR_SUCCESS; } -static void r_anal_class_base_fini_proxy(void *e, void *user) { +static void rz_anal_class_base_fini_proxy(void *e, void *user) { (void)user; - RAnalBaseClass *base = e; - r_anal_class_base_fini (base); + RzAnalBaseClass *base = e; + rz_anal_class_base_fini (base); } -R_API RVector/**/ *r_anal_class_base_get_all(RAnal *anal, const char *class_name) { - RVector *vec = r_vector_new (sizeof(RAnalBaseClass), r_anal_class_base_fini_proxy, NULL); +RZ_API RzVector/**/ *rz_anal_class_base_get_all(RzAnal *anal, const char *class_name) { + RzVector *vec = rz_vector_new (sizeof(RzAnalBaseClass), rz_anal_class_base_fini_proxy, NULL); if (!vec) { return NULL; } - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { - r_vector_free (vec); + rz_vector_free (vec); return NULL; } char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (class_name_sanitized, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_BASE)), 0); free (class_name_sanitized); - r_vector_reserve (vec, (size_t) sdb_alen (array)); + rz_vector_reserve (vec, (size_t) sdb_alen (array)); char *cur; sdb_aforeach (cur, array) { - RAnalBaseClass base; - if (r_anal_class_base_get (anal, class_name, cur, &base) == R_ANAL_CLASS_ERR_SUCCESS) { - r_vector_push (vec, &base); + RzAnalBaseClass base; + if (rz_anal_class_base_get (anal, class_name, cur, &base) == R_ANAL_CLASS_ERR_SUCCESS) { + rz_vector_push (vec, &base); } sdb_aforeach_next (cur); } @@ -701,15 +701,15 @@ R_API RVector/**/ *r_anal_class_base_get_all(RAnal *anal, const return vec; } -static RAnalClassErr r_anal_class_base_set_raw(RAnal *anal, const char *class_name, RAnalBaseClass *base, const char *base_class_name_sanitized) { +static RzAnalClassErr rz_anal_class_base_set_raw(RzAnal *anal, const char *class_name, RzAnalBaseClass *base, const char *base_class_name_sanitized) { char *content = sdb_fmt ("%s" SDB_SS "%"PFMT64u, base_class_name_sanitized, base->offset); - RAnalClassErr err; + RzAnalClassErr err; if (base->id) { - err = r_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base->id, content); + err = rz_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base->id, content); } else { base->id = malloc(16); if (base->id) { - err = r_anal_class_add_attr_unique (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, content, base->id, 16); + err = rz_anal_class_add_attr_unique (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, content, base->id, 16); } else { err = R_ANAL_CLASS_ERR_OTHER; } @@ -717,84 +717,84 @@ static RAnalClassErr r_anal_class_base_set_raw(RAnal *anal, const char *class_na return err; } -R_API RAnalClassErr r_anal_class_base_set(RAnal *anal, const char *class_name, RAnalBaseClass *base) { - char *base_class_name_sanitized = r_str_sanitize_sdb_key (base->class_name); +RZ_API RzAnalClassErr rz_anal_class_base_set(RzAnal *anal, const char *class_name, RzAnalBaseClass *base) { + char *base_class_name_sanitized = rz_str_sanitize_sdb_key (base->class_name); if (!base_class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - if (!r_anal_class_exists_raw (anal, base_class_name_sanitized)) { + if (!rz_anal_class_exists_raw (anal, base_class_name_sanitized)) { free (base_class_name_sanitized); return R_ANAL_CLASS_ERR_NONEXISTENT_CLASS; } - RVector /**/ *bases = r_anal_class_base_get_all (anal, class_name); + RzVector /**/ *bases = rz_anal_class_base_get_all (anal, class_name); if (bases) { - RAnalBaseClass *existing_base; - r_vector_foreach (bases, existing_base) { + RzAnalBaseClass *existing_base; + rz_vector_foreach (bases, existing_base) { if (!strcmp (existing_base->class_name, base->class_name)) { free (base_class_name_sanitized); - r_vector_free (bases); + rz_vector_free (bases); return R_ANAL_CLASS_ERR_OTHER; } } } - RAnalClassErr err = r_anal_class_base_set_raw (anal, class_name, base, base_class_name_sanitized); + RzAnalClassErr err = rz_anal_class_base_set_raw (anal, class_name, base, base_class_name_sanitized); free (base_class_name_sanitized); - r_vector_free (bases); + rz_vector_free (bases); return err; } -R_API RAnalClassErr r_anal_class_base_delete(RAnal *anal, const char *class_name, const char *base_id) { - return r_anal_class_delete_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base_id); +RZ_API RzAnalClassErr rz_anal_class_base_delete(RzAnal *anal, const char *class_name, const char *base_id) { + return rz_anal_class_delete_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_BASE, base_id); } typedef struct { - RAnal *anal; + RzAnal *anal; const char *class_name; } DeleteClassCtx; -static bool r_anal_class_base_delete_class_cb(void *user, const char *k, const char *v) { +static bool rz_anal_class_base_delete_class_cb(void *user, const char *k, const char *v) { (void)v; DeleteClassCtx *ctx = user; - RVector *bases = r_anal_class_base_get_all (ctx->anal, k); - RAnalBaseClass *base; - r_vector_foreach (bases, base) { + RzVector *bases = rz_anal_class_base_get_all (ctx->anal, k); + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { if (base->class_name && strcmp (base->class_name, ctx->class_name) == 0) { - r_anal_class_base_delete (ctx->anal, k, base->id); + rz_anal_class_base_delete (ctx->anal, k, base->id); } } - r_vector_free (bases); + rz_vector_free (bases); return true; } -static void r_anal_class_base_delete_class(RAnal *anal, const char *class_name) { +static void rz_anal_class_base_delete_class(RzAnal *anal, const char *class_name) { DeleteClassCtx ctx = { anal, class_name }; - r_anal_class_foreach (anal, r_anal_class_base_delete_class_cb, &ctx); + rz_anal_class_foreach (anal, rz_anal_class_base_delete_class_cb, &ctx); } typedef struct { - RAnal *anal; + RzAnal *anal; const char *class_name_old; const char *class_name_new; } RenameClassCtx; -static bool r_anal_class_base_rename_class_cb(void *user, const char *k, const char *v) { +static bool rz_anal_class_base_rename_class_cb(void *user, const char *k, const char *v) { (void)v; RenameClassCtx *ctx = user; - RVector *bases = r_anal_class_base_get_all (ctx->anal, k); - RAnalBaseClass *base; - r_vector_foreach (bases, base) { + RzVector *bases = rz_anal_class_base_get_all (ctx->anal, k); + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { if (base->class_name && strcmp (base->class_name, ctx->class_name_old) == 0) { - r_anal_class_base_set_raw (ctx->anal, k, base, ctx->class_name_new); + rz_anal_class_base_set_raw (ctx->anal, k, base, ctx->class_name_new); } } - r_vector_free (bases); + rz_vector_free (bases); return 1; } -static void r_anal_class_base_rename_class(RAnal *anal, const char *class_name_old, const char *class_name_new) { +static void rz_anal_class_base_rename_class(RzAnal *anal, const char *class_name_old, const char *class_name_new) { RenameClassCtx ctx = { anal, class_name_old, class_name_new }; - r_anal_class_foreach (anal, r_anal_class_base_rename_class_cb, &ctx); + rz_anal_class_foreach (anal, rz_anal_class_base_rename_class_cb, &ctx); } // ---- VTABLE ---- @@ -803,12 +803,12 @@ static char *flagname_vtable(const char *class_name, const char *vtable_id) { return flagname_attr ("vtable", class_name, vtable_id); } -R_API void r_anal_class_vtable_fini(RAnalVTable *vtable) { +RZ_API void rz_anal_class_vtable_fini(RzAnalVTable *vtable) { free (vtable->id); } -R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, const char *vtable_id, RAnalVTable *vtable) { - char *content = r_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable_id, false); +RZ_API RzAnalClassErr rz_anal_class_vtable_get(RzAnal *anal, const char *class_name, const char *vtable_id, RzAnalVTable *vtable) { + char *content = rz_anal_class_get_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable_id, false); if (!content) { return R_ANAL_CLASS_ERR_NONEXISTENT_ATTR; } @@ -817,7 +817,7 @@ R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, char *next; sdb_anext (cur, &next); - vtable->addr = r_num_math (NULL, cur); + vtable->addr = rz_num_math (NULL, cur); cur = next; if (!cur) { @@ -826,19 +826,19 @@ R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, } sdb_anext (cur, &next); - vtable->offset = r_num_math (NULL, cur); + vtable->offset = rz_num_math (NULL, cur); if (next) { cur = next; sdb_anext (cur, NULL); - vtable->size = r_num_get (NULL, cur); + vtable->size = rz_num_get (NULL, cur); } else { vtable->size = 0; } free (content); - vtable->id = r_str_sanitize_sdb_key (vtable_id); + vtable->id = rz_str_sanitize_sdb_key (vtable_id); if (!vtable->id) { return R_ANAL_CLASS_ERR_OTHER; } @@ -846,32 +846,32 @@ R_API RAnalClassErr r_anal_class_vtable_get(RAnal *anal, const char *class_name, return R_ANAL_CLASS_ERR_SUCCESS; } -static void r_anal_class_vtable_fini_proxy(void *e, void *user) { +static void rz_anal_class_vtable_fini_proxy(void *e, void *user) { (void)user; - RAnalVTable *vtable = e; - r_anal_class_vtable_fini (vtable); + RzAnalVTable *vtable = e; + rz_anal_class_vtable_fini (vtable); } -R_API RVector/**/ *r_anal_class_vtable_get_all(RAnal *anal, const char *class_name) { - RVector *vec = r_vector_new (sizeof(RAnalVTable), r_anal_class_vtable_fini_proxy, NULL); +RZ_API RzVector/**/ *rz_anal_class_vtable_get_all(RzAnal *anal, const char *class_name) { + RzVector *vec = rz_vector_new (sizeof(RzAnalVTable), rz_anal_class_vtable_fini_proxy, NULL); if (!vec) { return NULL; } - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { - r_vector_free (vec); + rz_vector_free (vec); return NULL; } char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (class_name_sanitized, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_VTABLE)), 0); free (class_name_sanitized); - r_vector_reserve (vec, (size_t) sdb_alen (array)); + rz_vector_reserve (vec, (size_t) sdb_alen (array)); char *cur; sdb_aforeach (cur, array) { - RAnalVTable vtable; - if (r_anal_class_vtable_get (anal, class_name, cur, &vtable) == R_ANAL_CLASS_ERR_SUCCESS) { - r_vector_push (vec, &vtable); + RzAnalVTable vtable; + if (rz_anal_class_vtable_get (anal, class_name, cur, &vtable) == R_ANAL_CLASS_ERR_SUCCESS) { + rz_vector_push (vec, &vtable); } sdb_aforeach_next (cur); } @@ -880,33 +880,33 @@ R_API RVector/**/ *r_anal_class_vtable_get_all(RAnal *anal, const c return vec; } -R_API RAnalClassErr r_anal_class_vtable_set(RAnal *anal, const char *class_name, RAnalVTable *vtable) { +RZ_API RzAnalClassErr rz_anal_class_vtable_set(RzAnal *anal, const char *class_name, RzAnalVTable *vtable) { char *content = sdb_fmt ("0x%"PFMT64x SDB_SS "%"PFMT64u SDB_SS "%"PFMT64u, vtable->addr, vtable->offset, vtable->size); if (vtable->id) { - return r_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable->id, content); + return rz_anal_class_set_attr (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable->id, content); } vtable->id = malloc(16); if (!vtable->id) { return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_add_attr_unique (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, content, vtable->id, 16); + RzAnalClassErr err = rz_anal_class_add_attr_unique (anal, class_name, R_ANAL_CLASS_ATTR_TYPE_VTABLE, content, vtable->id, 16); if (err != R_ANAL_CLASS_ERR_SUCCESS) { return err; } - r_anal_class_set_flag (anal, flagname_vtable (class_name, vtable->id), vtable->addr, vtable->size); + rz_anal_class_set_flag (anal, flagname_vtable (class_name, vtable->id), vtable->addr, vtable->size); return R_ANAL_CLASS_ERR_SUCCESS; } -static void r_anal_class_vtable_rename_class(RAnal *anal, const char *old_class_name, const char *new_class_name) { +static void rz_anal_class_vtable_rename_class(RzAnal *anal, const char *old_class_name, const char *new_class_name) { char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (old_class_name, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_VTABLE)), 0); if (!array) { return; } char *cur; sdb_aforeach (cur, array) { - r_anal_class_rename_flag (anal, + rz_anal_class_rename_flag (anal, flagname_vtable (old_class_name, cur), flagname_vtable (new_class_name, cur)); sdb_aforeach_next (cur); @@ -914,32 +914,32 @@ static void r_anal_class_vtable_rename_class(RAnal *anal, const char *old_class_ free (array); } -static void r_anal_class_vtable_delete_class(RAnal *anal, const char *class_name) { +static void rz_anal_class_vtable_delete_class(RzAnal *anal, const char *class_name) { char *array = sdb_get (anal->sdb_classes_attrs, key_attr_type_attrs (class_name, attr_type_id (R_ANAL_CLASS_ATTR_TYPE_VTABLE)), 0); if (!array) { return; } char *cur; sdb_aforeach (cur, array) { - r_anal_class_unset_flag (anal, flagname_vtable (class_name, cur)); + rz_anal_class_unset_flag (anal, flagname_vtable (class_name, cur)); sdb_aforeach_next (cur); } free (array); } -R_API RAnalClassErr r_anal_class_vtable_delete(RAnal *anal, const char *class_name, const char *vtable_id) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +RZ_API RzAnalClassErr rz_anal_class_vtable_delete(RzAnal *anal, const char *class_name, const char *vtable_id) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return R_ANAL_CLASS_ERR_OTHER; } - char *vtable_id_sanitized = r_str_sanitize_sdb_key (vtable_id); + char *vtable_id_sanitized = rz_str_sanitize_sdb_key (vtable_id); if (!vtable_id_sanitized) { free (class_name_sanitized); return R_ANAL_CLASS_ERR_OTHER; } - RAnalClassErr err = r_anal_class_delete_attr_raw (anal, class_name_sanitized, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable_id_sanitized); + RzAnalClassErr err = rz_anal_class_delete_attr_raw (anal, class_name_sanitized, R_ANAL_CLASS_ATTR_TYPE_VTABLE, vtable_id_sanitized); if (err == R_ANAL_CLASS_ERR_SUCCESS) { - r_anal_class_unset_flag (anal, flagname_vtable (class_name_sanitized, vtable_id_sanitized)); + rz_anal_class_unset_flag (anal, flagname_vtable (class_name_sanitized, vtable_id_sanitized)); } free (class_name_sanitized); free (vtable_id_sanitized); @@ -950,114 +950,114 @@ R_API RAnalClassErr r_anal_class_vtable_delete(RAnal *anal, const char *class_na // ---- PRINT ---- -R_API void r_anal_class_print(RAnal *anal, const char *class_name, bool detailed) { - r_cons_print (class_name); +RZ_API void rz_anal_class_print(RzAnal *anal, const char *class_name, bool detailed) { + rz_cons_print (class_name); - RVector *bases = r_anal_class_base_get_all (anal, class_name); + RzVector *bases = rz_anal_class_base_get_all (anal, class_name); if (bases) { - RAnalBaseClass *base; + RzAnalBaseClass *base; bool first = true; - r_vector_foreach (bases, base) { + rz_vector_foreach (bases, base) { if (first) { - r_cons_print (": "); + rz_cons_print (": "); first = false; } else { - r_cons_print (", "); + rz_cons_print (", "); } - r_cons_print (base->class_name); + rz_cons_print (base->class_name); } - r_vector_free (bases); + rz_vector_free (bases); } - r_cons_print ("\n"); + rz_cons_print ("\n"); if (detailed) { - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); if (vtables) { - RAnalVTable *vtable; - r_vector_foreach (vtables, vtable) { - r_cons_printf (" (vtable at 0x%"PFMT64x, vtable->addr); + RzAnalVTable *vtable; + rz_vector_foreach (vtables, vtable) { + rz_cons_printf (" (vtable at 0x%"PFMT64x, vtable->addr); if (vtable->offset > 0) { - r_cons_printf (" in class at +0x%"PFMT64x")\n", vtable->offset); + rz_cons_printf (" in class at +0x%"PFMT64x")\n", vtable->offset); } else { - r_cons_print (")\n"); + rz_cons_print (")\n"); } } - r_vector_free (vtables); + rz_vector_free (vtables); } - RVector *methods = r_anal_class_method_get_all (anal, class_name); + RzVector *methods = rz_anal_class_method_get_all (anal, class_name); if (methods) { - RAnalMethod *meth; - r_vector_foreach (methods, meth) { - r_cons_printf (" %s @ 0x%"PFMT64x, meth->name, meth->addr); + RzAnalMethod *meth; + rz_vector_foreach (methods, meth) { + rz_cons_printf (" %s @ 0x%"PFMT64x, meth->name, meth->addr); if (meth->vtable_offset >= 0) { - r_cons_printf (" (vtable + 0x%"PFMT64x")\n", (ut64)meth->vtable_offset); + rz_cons_printf (" (vtable + 0x%"PFMT64x")\n", (ut64)meth->vtable_offset); } else { - r_cons_print ("\n"); + rz_cons_print ("\n"); } } - r_vector_free (methods); + rz_vector_free (methods); } } } -static void r_anal_class_print_cmd(RAnal *anal, const char *class_name) { - RVector *bases = r_anal_class_base_get_all (anal, class_name); +static void rz_anal_class_print_cmd(RzAnal *anal, const char *class_name) { + RzVector *bases = rz_anal_class_base_get_all (anal, class_name); if (bases) { - RAnalBaseClass *base; - r_vector_foreach (bases, base) { - r_cons_printf ("acb %s %s %"PFMT64u"\n", class_name, base->class_name, base->offset); + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { + rz_cons_printf ("acb %s %s %"PFMT64u"\n", class_name, base->class_name, base->offset); } - r_vector_free (bases); + rz_vector_free (bases); } - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); if (vtables) { - RAnalVTable *vtable; - r_vector_foreach (vtables, vtable) { - r_cons_printf ("acv %s 0x%"PFMT64x" %"PFMT64u"\n", class_name, vtable->addr, vtable->offset); + RzAnalVTable *vtable; + rz_vector_foreach (vtables, vtable) { + rz_cons_printf ("acv %s 0x%"PFMT64x" %"PFMT64u"\n", class_name, vtable->addr, vtable->offset); } - r_vector_free (vtables); + rz_vector_free (vtables); } - RVector *methods = r_anal_class_method_get_all (anal, class_name); + RzVector *methods = rz_anal_class_method_get_all (anal, class_name); if (methods) { - RAnalMethod *meth; - r_vector_foreach (methods, meth) { - r_cons_printf ("acm %s %s 0x%"PFMT64x" %"PFMT64d"\n", class_name, meth->name, meth->addr, meth->vtable_offset); + RzAnalMethod *meth; + rz_vector_foreach (methods, meth) { + rz_cons_printf ("acm %s %s 0x%"PFMT64x" %"PFMT64d"\n", class_name, meth->name, meth->addr, meth->vtable_offset); } - r_vector_free (methods); + rz_vector_free (methods); } } -R_API void r_anal_class_json(RAnal *anal, PJ *j, const char *class_name) { +RZ_API void rz_anal_class_json(RzAnal *anal, PJ *j, const char *class_name) { pj_o (j); pj_ks (j, "name", class_name); pj_k (j, "bases"); pj_a (j); - RVector *bases = r_anal_class_base_get_all (anal, class_name); + RzVector *bases = rz_anal_class_base_get_all (anal, class_name); if (bases) { - RAnalBaseClass *base; - r_vector_foreach (bases, base) { + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { pj_o (j); pj_ks (j, "id", base->id); pj_ks (j, "name", base->class_name); pj_kn (j, "offset", base->offset); pj_end (j); } - r_vector_free (bases); + rz_vector_free (bases); } pj_end (j); pj_k (j, "vtables"); pj_a (j); - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); if (vtables) { - RAnalVTable *vtable; - r_vector_foreach (vtables, vtable) { + RzAnalVTable *vtable; + rz_vector_foreach (vtables, vtable) { pj_o (j); pj_ks (j, "id", vtable->id); pj_kn (j, "addr", vtable->addr); @@ -1069,10 +1069,10 @@ R_API void r_anal_class_json(RAnal *anal, PJ *j, const char *class_name) { pj_k (j, "methods"); pj_a (j); - RVector *methods = r_anal_class_method_get_all (anal, class_name); + RzVector *methods = rz_anal_class_method_get_all (anal, class_name); if (methods) { - RAnalMethod *meth; - r_vector_foreach (methods, meth) { + RzAnalMethod *meth; + rz_vector_foreach (methods, meth) { pj_o (j); pj_ks (j, "name", meth->name); pj_kn (j, "addr", meth->addr); @@ -1081,7 +1081,7 @@ R_API void r_anal_class_json(RAnal *anal, PJ *j, const char *class_name) { } pj_end (j); } - r_vector_free (methods); + rz_vector_free (methods); } pj_end (j); @@ -1089,17 +1089,17 @@ R_API void r_anal_class_json(RAnal *anal, PJ *j, const char *class_name) { } typedef struct { - RAnal *anal; + RzAnal *anal; PJ *j; } ListJsonCtx; -static bool r_anal_class_list_json_cb(void *user, const char *k, const char *v) { +static bool rz_anal_class_list_json_cb(void *user, const char *k, const char *v) { ListJsonCtx *ctx = user; - r_anal_class_json (ctx->anal, ctx->j, k); + rz_anal_class_json (ctx->anal, ctx->j, k); return true; } -static void r_anal_class_list_json(RAnal *anal) { +static void rz_anal_class_list_json(RzAnal *anal) { PJ *j = pj_new (); if (!j) { return; @@ -1109,111 +1109,111 @@ static void r_anal_class_list_json(RAnal *anal) { ListJsonCtx ctx; ctx.anal = anal; ctx.j = j; - r_anal_class_foreach (anal, r_anal_class_list_json_cb, &ctx); + rz_anal_class_foreach (anal, rz_anal_class_list_json_cb, &ctx); pj_end (j); - r_cons_printf ("%s\n", pj_string (j)); + rz_cons_printf ("%s\n", pj_string (j)); pj_free (j); } -R_API void r_anal_class_list(RAnal *anal, int mode) { +RZ_API void rz_anal_class_list(RzAnal *anal, int mode) { if (mode == 'j') { - r_anal_class_list_json (anal); + rz_anal_class_list_json (anal); return; } - SdbList *classes = r_anal_class_get_all (anal, mode != '*'); + SdbList *classes = rz_anal_class_get_all (anal, mode != '*'); SdbListIter *iter; SdbKv *kv; if (mode == '*') { ls_foreach (classes, iter, kv) { // need to create all classes first, so they can be referenced - r_cons_printf ("ac %s\n", sdbkv_key (kv)); + rz_cons_printf ("ac %s\n", sdbkv_key (kv)); } ls_foreach (classes, iter, kv) { - r_anal_class_print_cmd(anal, sdbkv_key (kv)); + rz_anal_class_print_cmd(anal, sdbkv_key (kv)); } } else { ls_foreach (classes, iter, kv) { - r_anal_class_print (anal, sdbkv_key (kv), mode == 'l'); + rz_anal_class_print (anal, sdbkv_key (kv), mode == 'l'); } } ls_free (classes); } -R_API void r_anal_class_list_bases(RAnal *anal, const char *class_name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +RZ_API void rz_anal_class_list_bases(RzAnal *anal, const char *class_name) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return; } - if (!r_anal_class_exists_raw (anal, class_name_sanitized)) { + if (!rz_anal_class_exists_raw (anal, class_name_sanitized)) { free (class_name_sanitized); return; } - r_cons_printf ("%s:\n", class_name_sanitized); + rz_cons_printf ("%s:\n", class_name_sanitized); free (class_name_sanitized); - RVector *bases = r_anal_class_base_get_all (anal, class_name); - RAnalBaseClass *base; - r_vector_foreach (bases, base) { - r_cons_printf (" %4s %s @ +0x%"PFMT64x"\n", base->id, base->class_name, base->offset); + RzVector *bases = rz_anal_class_base_get_all (anal, class_name); + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { + rz_cons_printf (" %4s %s @ +0x%"PFMT64x"\n", base->id, base->class_name, base->offset); } - r_vector_free (bases); + rz_vector_free (bases); } -R_API void r_anal_class_list_vtables(RAnal *anal, const char *class_name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); +RZ_API void rz_anal_class_list_vtables(RzAnal *anal, const char *class_name) { + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return; } - if (!r_anal_class_exists_raw (anal, class_name_sanitized)) { + if (!rz_anal_class_exists_raw (anal, class_name_sanitized)) { free (class_name_sanitized); return; } - r_cons_printf ("%s:\n", class_name_sanitized); + rz_cons_printf ("%s:\n", class_name_sanitized); free (class_name_sanitized); - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); if (vtables) { - RAnalVTable *vtable; - r_vector_foreach (vtables, vtable) { - r_cons_printf (" %4s vtable 0x%"PFMT64x" @ +0x%"PFMT64x" size:+0x%"PFMT64x"\n", vtable->id, vtable->addr, vtable->offset, vtable->size); + RzAnalVTable *vtable; + rz_vector_foreach (vtables, vtable) { + rz_cons_printf (" %4s vtable 0x%"PFMT64x" @ +0x%"PFMT64x" size:+0x%"PFMT64x"\n", vtable->id, vtable->addr, vtable->offset, vtable->size); } - r_vector_free (vtables); + rz_vector_free (vtables); } } -static void list_all_functions_at_vtable_offset(RAnal *anal, const char *class_name, ut64 offset) { +static void list_all_functions_at_vtable_offset(RzAnal *anal, const char *class_name, ut64 offset) { RVTableContext vtableContext; - r_anal_vtable_begin (anal, &vtableContext); + rz_anal_vtable_begin (anal, &vtableContext); ut8 function_ptr_size = vtableContext.word_size; ut64 func_address; - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); - RAnalVTable *vtable; + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); + RzAnalVTable *vtable; if (!vtables) { return; } - r_vector_foreach (vtables, vtable) { + rz_vector_foreach (vtables, vtable) { if (vtable->size < offset + function_ptr_size) { continue; } if (vtableContext.read_addr(anal, vtable->addr+offset, &func_address)) - r_cons_printf ("Function address: 0x%08"PFMT64x", in %s vtable %s\n", func_address, class_name, vtable->id); + rz_cons_printf ("Function address: 0x%08"PFMT64x", in %s vtable %s\n", func_address, class_name, vtable->id); } - r_vector_free (vtables); + rz_vector_free (vtables); } -R_API void r_anal_class_list_vtable_offset_functions(RAnal *anal, const char *class_name, ut64 offset) { +RZ_API void rz_anal_class_list_vtable_offset_functions(RzAnal *anal, const char *class_name, ut64 offset) { if (class_name) { - char *class_name_sanitized = r_str_sanitize_sdb_key (class_name); + char *class_name_sanitized = rz_str_sanitize_sdb_key (class_name); if (!class_name_sanitized) { return; } - if (!r_anal_class_exists_raw (anal, class_name_sanitized)) { + if (!rz_anal_class_exists_raw (anal, class_name_sanitized)) { free (class_name_sanitized); return; } @@ -1221,7 +1221,7 @@ R_API void r_anal_class_list_vtable_offset_functions(RAnal *anal, const char *cl list_all_functions_at_vtable_offset (anal, class_name, offset); } else { - SdbList *classes = r_anal_class_get_all (anal, true); + SdbList *classes = rz_anal_class_get_all (anal, true); SdbListIter *iter; SdbKv *kv; ls_foreach (classes, iter, kv) { @@ -1239,20 +1239,20 @@ R_API void r_anal_class_list_vtable_offset_functions(RAnal *anal, const char *cl * @param anal * @return RGraph* NULL if failure */ -R_API RGraph *r_anal_class_get_inheritance_graph(RAnal *anal) { - r_return_val_if_fail (anal, NULL); - RGraph *class_graph = r_graph_new (); +RZ_API RGraph *rz_anal_class_get_inheritance_graph(RzAnal *anal) { + rz_return_val_if_fail (anal, NULL); + RGraph *class_graph = rz_graph_new (); if (!class_graph) { return NULL; } - SdbList *classes = r_anal_class_get_all (anal, true); + SdbList *classes = rz_anal_class_get_all (anal, true); if (!classes) { - r_graph_free (class_graph); + rz_graph_free (class_graph); return NULL; } HtPP /**/ *hashmap = ht_pp_new0 (); if (!hashmap) { - r_graph_free (class_graph); + rz_graph_free (class_graph); ls_free (classes); return NULL; } @@ -1264,39 +1264,39 @@ R_API RGraph *r_anal_class_get_inheritance_graph(RAnal *anal) { // create nodes RGraphNode *curr_node = ht_pp_find (hashmap, name, NULL); if (!curr_node) { - RGraphNodeInfo *data = r_graph_create_node_info (strdup (name), NULL, 0); + RGraphNodeInfo *data = rz_graph_create_node_info (strdup (name), NULL, 0); if (!data) { goto failure; } - curr_node = r_graph_add_node (class_graph, data); + curr_node = rz_graph_add_node (class_graph, data); if (!curr_node) { goto failure; } - curr_node->free = r_graph_free_node_info; + curr_node->free = rz_graph_free_node_info; ht_pp_insert (hashmap, name, curr_node); } // create edges between node and it's parents - RVector *bases = r_anal_class_base_get_all (anal, name); - RAnalBaseClass *base; - r_vector_foreach (bases, base) { + RzVector *bases = rz_anal_class_base_get_all (anal, name); + RzAnalBaseClass *base; + rz_vector_foreach (bases, base) { bool base_found = false; RGraphNode *base_node = ht_pp_find (hashmap, base->class_name, &base_found); // If base isn't processed, do it now if (!base_found) { - RGraphNodeInfo *data = r_graph_create_node_info (strdup (base->class_name), NULL, 0); + RGraphNodeInfo *data = rz_graph_create_node_info (strdup (base->class_name), NULL, 0); if (!data) { goto failure; } - base_node = r_graph_add_node (class_graph, data); + base_node = rz_graph_add_node (class_graph, data); if (!base_node) { goto failure; } - base_node->free = r_graph_free_node_info; + base_node->free = rz_graph_free_node_info; ht_pp_insert (hashmap, base->class_name, base_node); } - r_graph_add_edge (class_graph, base_node, curr_node); + rz_graph_add_edge (class_graph, base_node, curr_node); } - r_vector_free (bases); + rz_vector_free (bases); } ls_free (classes); ht_pp_free (hashmap); @@ -1305,6 +1305,6 @@ R_API RGraph *r_anal_class_get_inheritance_graph(RAnal *anal) { failure: ls_free (classes); ht_pp_free (hashmap); - r_graph_free (class_graph); + rz_graph_free (class_graph); return NULL; } \ No newline at end of file diff --git a/libr/anal/cond.c b/librz/anal/cond.c similarity index 70% rename from libr/anal/cond.c rename to librz/anal/cond.c index 0e935640ce..cb9e081685 100644 --- a/libr/anal/cond.c +++ b/librz/anal/cond.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2010-2016 - pancake */ -#include +#include -R_API const char *r_anal_cond_tostring(int cc) { +RZ_API const char *rz_anal_cond_tostring(int cc) { switch (cc) { case R_ANAL_COND_EQ: return "eq"; case R_ANAL_COND_NV: return "nv"; @@ -24,38 +24,38 @@ R_API const char *r_anal_cond_tostring(int cc) { return "??"; } -R_API RAnalCond *r_anal_cond_new(void) { - return R_NEW0 (RAnalCond); +RZ_API RzAnalCond *rz_anal_cond_new(void) { + return R_NEW0 (RzAnalCond); } -R_API void r_anal_cond_fini (RAnalCond *c) { +RZ_API void rz_anal_cond_fini (RzAnalCond *c) { if (!c) { return; } - r_anal_value_free (c->arg[0]); - r_anal_value_free (c->arg[1]); + rz_anal_value_free (c->arg[0]); + rz_anal_value_free (c->arg[1]); c->arg[0] = c->arg[1] = NULL; } -R_API void r_anal_cond_free (RAnalCond *c) { +RZ_API void rz_anal_cond_free (RzAnalCond *c) { if (!c) { return; } - r_anal_cond_fini (c); + rz_anal_cond_fini (c); free (c); } // XXX? -R_API RAnalCond *r_anal_cond_clone(RAnalCond *cond) { - RAnalCond *c = R_NEW (RAnalCond); +RZ_API RzAnalCond *rz_anal_cond_clone(RzAnalCond *cond) { + RzAnalCond *c = R_NEW (RzAnalCond); if (!c) { return NULL; } - memcpy (c, cond, sizeof (RAnalCond)); + memcpy (c, cond, sizeof (RzAnalCond)); return c; } -static inline const char *condstring(RAnalCond *cond) { +static inline const char *condstring(RzAnalCond *cond) { const char *condstr_single[] = { "!", "", "0<", "0<=", "0>", "0>=" }; const char *condstr[] = { "==", "!=", ">=", ">", "<=", "<" }; if (cond) { @@ -68,11 +68,11 @@ static inline const char *condstring(RAnalCond *cond) { return ""; } -R_API int r_anal_cond_eval(RAnal *anal, RAnalCond *cond) { +RZ_API int rz_anal_cond_eval(RzAnal *anal, RzAnalCond *cond) { // XXX: sign issue here? - st64 arg0 = (st64) r_anal_value_to_ut64 (anal, cond->arg[0]); + st64 arg0 = (st64) rz_anal_value_to_ut64 (anal, cond->arg[0]); if (cond->arg[1]) { - st64 arg1 = (st64) r_anal_value_to_ut64 (anal, cond->arg[1]); + st64 arg1 = (st64) rz_anal_value_to_ut64 (anal, cond->arg[1]); switch (cond->type) { case R_ANAL_COND_EQ: return arg0 == arg1; case R_ANAL_COND_NE: return arg0 != arg1; @@ -95,15 +95,15 @@ R_API int r_anal_cond_eval(RAnal *anal, RAnalCond *cond) { } // XXX conflict naming with tostring() -R_API char *r_anal_cond_to_string(RAnalCond *cond) { +RZ_API char *rz_anal_cond_to_string(RzAnalCond *cond) { char *val0, *val1, *out = NULL; const char *cnd; if (!cond) { return NULL; } cnd = condstring (cond); - val0 = r_anal_value_to_string (cond->arg[0]); - val1 = r_anal_value_to_string (cond->arg[1]); + val0 = rz_anal_value_to_string (cond->arg[0]); + val1 = rz_anal_value_to_string (cond->arg[1]); if (val0) { if (R_ANAL_COND_SINGLE (cond)) { int val0len = strlen (val0) + 10; @@ -124,9 +124,9 @@ R_API char *r_anal_cond_to_string(RAnalCond *cond) { return out? out: strdup ("?"); } -R_API RAnalCond *r_anal_cond_new_from_op(RAnalOp *op) { - RAnalCond *cond; - if (!(cond = r_anal_cond_new ())) { +RZ_API RzAnalCond *rz_anal_cond_new_from_op(RzAnalOp *op) { + RzAnalCond *cond; + if (!(cond = rz_anal_cond_new ())) { return NULL; } //v->reg[0] = op->src[0]; @@ -140,8 +140,8 @@ R_API RAnalCond *r_anal_cond_new_from_op(RAnalOp *op) { return cond; } -R_API RAnalCond *r_anal_cond_new_from_string(const char *str) { - RAnalCond *cond = R_NEW (RAnalCond); +RZ_API RzAnalCond *rz_anal_cond_new_from_string(const char *str) { + RzAnalCond *cond = R_NEW (RzAnalCond); // TODO: find '<','=','>','!'... return cond; } diff --git a/librz/anal/cycles.c b/librz/anal/cycles.c new file mode 100644 index 0000000000..bc228ba71e --- /dev/null +++ b/librz/anal/cycles.c @@ -0,0 +1,23 @@ +/* radare - LGPL - Copyright 2014-2020 - condret */ + +#include +#include +#include + +RZ_API RzAnalCycleFrame *rz_anal_cycle_frame_new(void) { + RzAnalCycleFrame *cf = R_NEW0 (RzAnalCycleFrame); + if (cf) { + if (!(cf->hooks = rz_list_new ())) { + R_FREE (cf); + } + } + return cf; +} + +RZ_API void rz_anal_cycle_frame_free(RzAnalCycleFrame *cf) { + if (!cf) { + return; + } + rz_list_free (cf->hooks); + free (cf); +} diff --git a/libr/anal/d/Makefile b/librz/anal/d/Makefile similarity index 94% rename from libr/anal/d/Makefile rename to librz/anal/d/Makefile index 5a08f7fb68..fedb1dcffa 100755 --- a/libr/anal/d/Makefile +++ b/librz/anal/d/Makefile @@ -80,7 +80,7 @@ BUILD_EXT_EXE= endif SDB=$(SDBPATH)/sdb${BUILD_EXT_EXE} -FCNSIGNPATH=$(DESTDIR)$(DATADIR)/radare2/$(VERSION)/fcnsign +FCNSIGNPATH=$(DESTDIR)$(DATADIR)/rizin/$(VERSION)/fcnsign all: ${SDB} @$(MAKE) compile @@ -120,7 +120,7 @@ install: ${F_SDB} CWD=$(shell pwd) symstall install-symlink: ${F_SDB} cd ../../.. && mkdir -p "${FCNSIGNPATH}" && \ - for FILE in $(shell cd $(TOP)/libr/anal/d ; ls *.sdb); do \ + for FILE in $(shell cd $(TOP)/librz/anal/d ; ls *.sdb); do \ ln -fs "$(CWD)/$$FILE" "$(FCNSIGNPATH)/$$FILE" ; \ done diff --git a/libr/anal/d/cc-arm-16.sdb.txt b/librz/anal/d/cc-arm-16.sdb.txt similarity index 100% rename from libr/anal/d/cc-arm-16.sdb.txt rename to librz/anal/d/cc-arm-16.sdb.txt diff --git a/libr/anal/d/cc-arm-32.sdb.txt b/librz/anal/d/cc-arm-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-arm-32.sdb.txt rename to librz/anal/d/cc-arm-32.sdb.txt diff --git a/libr/anal/d/cc-arm-64.sdb.txt b/librz/anal/d/cc-arm-64.sdb.txt similarity index 100% rename from libr/anal/d/cc-arm-64.sdb.txt rename to librz/anal/d/cc-arm-64.sdb.txt diff --git a/libr/anal/d/cc-avr-8.sdb.txt b/librz/anal/d/cc-avr-8.sdb.txt similarity index 100% rename from libr/anal/d/cc-avr-8.sdb.txt rename to librz/anal/d/cc-avr-8.sdb.txt diff --git a/libr/anal/d/cc-hexagon-32.sdb.txt b/librz/anal/d/cc-hexagon-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-hexagon-32.sdb.txt rename to librz/anal/d/cc-hexagon-32.sdb.txt diff --git a/libr/anal/d/cc-m68k-32.sdb.txt b/librz/anal/d/cc-m68k-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-m68k-32.sdb.txt rename to librz/anal/d/cc-m68k-32.sdb.txt diff --git a/libr/anal/d/cc-mips-32.sdb.txt b/librz/anal/d/cc-mips-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-mips-32.sdb.txt rename to librz/anal/d/cc-mips-32.sdb.txt diff --git a/libr/anal/d/cc-mips-64.sdb.txt b/librz/anal/d/cc-mips-64.sdb.txt similarity index 100% rename from libr/anal/d/cc-mips-64.sdb.txt rename to librz/anal/d/cc-mips-64.sdb.txt diff --git a/libr/anal/d/cc-ppc-32.sdb.txt b/librz/anal/d/cc-ppc-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-ppc-32.sdb.txt rename to librz/anal/d/cc-ppc-32.sdb.txt diff --git a/libr/anal/d/cc-ppc-64.sdb.txt b/librz/anal/d/cc-ppc-64.sdb.txt similarity index 100% rename from libr/anal/d/cc-ppc-64.sdb.txt rename to librz/anal/d/cc-ppc-64.sdb.txt diff --git a/libr/anal/d/cc-riscv-64.sdb.txt b/librz/anal/d/cc-riscv-64.sdb.txt similarity index 100% rename from libr/anal/d/cc-riscv-64.sdb.txt rename to librz/anal/d/cc-riscv-64.sdb.txt diff --git a/libr/anal/d/cc-sh-32.sdb.txt b/librz/anal/d/cc-sh-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-sh-32.sdb.txt rename to librz/anal/d/cc-sh-32.sdb.txt diff --git a/libr/anal/d/cc-sparc-32.sdb.txt b/librz/anal/d/cc-sparc-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-sparc-32.sdb.txt rename to librz/anal/d/cc-sparc-32.sdb.txt diff --git a/libr/anal/d/cc-x86-16.sdb.txt b/librz/anal/d/cc-x86-16.sdb.txt similarity index 100% rename from libr/anal/d/cc-x86-16.sdb.txt rename to librz/anal/d/cc-x86-16.sdb.txt diff --git a/libr/anal/d/cc-x86-32.sdb.txt b/librz/anal/d/cc-x86-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-x86-32.sdb.txt rename to librz/anal/d/cc-x86-32.sdb.txt diff --git a/libr/anal/d/cc-x86-64.sdb.txt b/librz/anal/d/cc-x86-64.sdb.txt similarity index 100% rename from libr/anal/d/cc-x86-64.sdb.txt rename to librz/anal/d/cc-x86-64.sdb.txt diff --git a/libr/anal/d/cc-xtensa-32.sdb.txt b/librz/anal/d/cc-xtensa-32.sdb.txt similarity index 100% rename from libr/anal/d/cc-xtensa-32.sdb.txt rename to librz/anal/d/cc-xtensa-32.sdb.txt diff --git a/libr/anal/d/meson.build b/librz/anal/d/meson.build similarity index 100% rename from libr/anal/d/meson.build rename to librz/anal/d/meson.build diff --git a/libr/anal/d/spec.sdb.txt b/librz/anal/d/spec.sdb.txt similarity index 100% rename from libr/anal/d/spec.sdb.txt rename to librz/anal/d/spec.sdb.txt diff --git a/libr/anal/d/types-16.sdb.txt b/librz/anal/d/types-16.sdb.txt similarity index 100% rename from libr/anal/d/types-16.sdb.txt rename to librz/anal/d/types-16.sdb.txt diff --git a/libr/anal/d/types-32.sdb.txt b/librz/anal/d/types-32.sdb.txt similarity index 100% rename from libr/anal/d/types-32.sdb.txt rename to librz/anal/d/types-32.sdb.txt diff --git a/libr/anal/d/types-64.sdb.txt b/librz/anal/d/types-64.sdb.txt similarity index 100% rename from libr/anal/d/types-64.sdb.txt rename to librz/anal/d/types-64.sdb.txt diff --git a/libr/anal/d/types-android.sdb.txt b/librz/anal/d/types-android.sdb.txt similarity index 100% rename from libr/anal/d/types-android.sdb.txt rename to librz/anal/d/types-android.sdb.txt diff --git a/libr/anal/d/types-arm-ios-16.sdb.txt b/librz/anal/d/types-arm-ios-16.sdb.txt similarity index 100% rename from libr/anal/d/types-arm-ios-16.sdb.txt rename to librz/anal/d/types-arm-ios-16.sdb.txt diff --git a/libr/anal/d/types-arm-ios-32.sdb.txt b/librz/anal/d/types-arm-ios-32.sdb.txt similarity index 100% rename from libr/anal/d/types-arm-ios-32.sdb.txt rename to librz/anal/d/types-arm-ios-32.sdb.txt diff --git a/libr/anal/d/types-arm-ios-64.sdb.txt b/librz/anal/d/types-arm-ios-64.sdb.txt similarity index 100% rename from libr/anal/d/types-arm-ios-64.sdb.txt rename to librz/anal/d/types-arm-ios-64.sdb.txt diff --git a/libr/anal/d/types-darwin.sdb.txt b/librz/anal/d/types-darwin.sdb.txt similarity index 100% rename from libr/anal/d/types-darwin.sdb.txt rename to librz/anal/d/types-darwin.sdb.txt diff --git a/libr/anal/d/types-linux.sdb.txt b/librz/anal/d/types-linux.sdb.txt similarity index 100% rename from libr/anal/d/types-linux.sdb.txt rename to librz/anal/d/types-linux.sdb.txt diff --git a/libr/anal/d/types-windows.sdb.txt b/librz/anal/d/types-windows.sdb.txt similarity index 100% rename from libr/anal/d/types-windows.sdb.txt rename to librz/anal/d/types-windows.sdb.txt diff --git a/libr/anal/d/types-windows_bcrypt.sdb.txt b/librz/anal/d/types-windows_bcrypt.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_bcrypt.sdb.txt rename to librz/anal/d/types-windows_bcrypt.sdb.txt diff --git a/libr/anal/d/types-windows_cfgmgr32.sdb.txt b/librz/anal/d/types-windows_cfgmgr32.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_cfgmgr32.sdb.txt rename to librz/anal/d/types-windows_cfgmgr32.sdb.txt diff --git a/libr/anal/d/types-windows_combaseapi.sdb.txt b/librz/anal/d/types-windows_combaseapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_combaseapi.sdb.txt rename to librz/anal/d/types-windows_combaseapi.sdb.txt diff --git a/libr/anal/d/types-windows_commctrl.sdb.txt b/librz/anal/d/types-windows_commctrl.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_commctrl.sdb.txt rename to librz/anal/d/types-windows_commctrl.sdb.txt diff --git a/libr/anal/d/types-windows_consoleapi2.sdb.txt b/librz/anal/d/types-windows_consoleapi2.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_consoleapi2.sdb.txt rename to librz/anal/d/types-windows_consoleapi2.sdb.txt diff --git a/libr/anal/d/types-windows_dbghelp.sdb.txt b/librz/anal/d/types-windows_dbghelp.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_dbghelp.sdb.txt rename to librz/anal/d/types-windows_dbghelp.sdb.txt diff --git a/libr/anal/d/types-windows_evntrace.sdb.txt b/librz/anal/d/types-windows_evntrace.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_evntrace.sdb.txt rename to librz/anal/d/types-windows_evntrace.sdb.txt diff --git a/libr/anal/d/types-windows_fileapi.sdb.txt b/librz/anal/d/types-windows_fileapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_fileapi.sdb.txt rename to librz/anal/d/types-windows_fileapi.sdb.txt diff --git a/libr/anal/d/types-windows_libloaderapi.sdb.txt b/librz/anal/d/types-windows_libloaderapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_libloaderapi.sdb.txt rename to librz/anal/d/types-windows_libloaderapi.sdb.txt diff --git a/libr/anal/d/types-windows_memoryapi.sdb.txt b/librz/anal/d/types-windows_memoryapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_memoryapi.sdb.txt rename to librz/anal/d/types-windows_memoryapi.sdb.txt diff --git a/libr/anal/d/types-windows_ncrypt.sdb.txt b/librz/anal/d/types-windows_ncrypt.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_ncrypt.sdb.txt rename to librz/anal/d/types-windows_ncrypt.sdb.txt diff --git a/libr/anal/d/types-windows_objbase.sdb.txt b/librz/anal/d/types-windows_objbase.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_objbase.sdb.txt rename to librz/anal/d/types-windows_objbase.sdb.txt diff --git a/libr/anal/d/types-windows_oleauto.sdb.txt b/librz/anal/d/types-windows_oleauto.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_oleauto.sdb.txt rename to librz/anal/d/types-windows_oleauto.sdb.txt diff --git a/libr/anal/d/types-windows_processthreadsapi.sdb.txt b/librz/anal/d/types-windows_processthreadsapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_processthreadsapi.sdb.txt rename to librz/anal/d/types-windows_processthreadsapi.sdb.txt diff --git a/libr/anal/d/types-windows_psapi.sdb.txt b/librz/anal/d/types-windows_psapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_psapi.sdb.txt rename to librz/anal/d/types-windows_psapi.sdb.txt diff --git a/libr/anal/d/types-windows_securitybaseapi.sdb.txt b/librz/anal/d/types-windows_securitybaseapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_securitybaseapi.sdb.txt rename to librz/anal/d/types-windows_securitybaseapi.sdb.txt diff --git a/libr/anal/d/types-windows_shellapi.sdb.txt b/librz/anal/d/types-windows_shellapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_shellapi.sdb.txt rename to librz/anal/d/types-windows_shellapi.sdb.txt diff --git a/libr/anal/d/types-windows_shlwapi.sdb.txt b/librz/anal/d/types-windows_shlwapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_shlwapi.sdb.txt rename to librz/anal/d/types-windows_shlwapi.sdb.txt diff --git a/libr/anal/d/types-windows_synchapi.sdb.txt b/librz/anal/d/types-windows_synchapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_synchapi.sdb.txt rename to librz/anal/d/types-windows_synchapi.sdb.txt diff --git a/libr/anal/d/types-windows_sysinfoapi.sdb.txt b/librz/anal/d/types-windows_sysinfoapi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_sysinfoapi.sdb.txt rename to librz/anal/d/types-windows_sysinfoapi.sdb.txt diff --git a/libr/anal/d/types-windows_threadpoolapiset.sdb.txt b/librz/anal/d/types-windows_threadpoolapiset.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_threadpoolapiset.sdb.txt rename to librz/anal/d/types-windows_threadpoolapiset.sdb.txt diff --git a/libr/anal/d/types-windows_userenv.sdb.txt b/librz/anal/d/types-windows_userenv.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_userenv.sdb.txt rename to librz/anal/d/types-windows_userenv.sdb.txt diff --git a/libr/anal/d/types-windows_winbase.sdb.txt b/librz/anal/d/types-windows_winbase.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winbase.sdb.txt rename to librz/anal/d/types-windows_winbase.sdb.txt diff --git a/libr/anal/d/types-windows_wincred.sdb.txt b/librz/anal/d/types-windows_wincred.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_wincred.sdb.txt rename to librz/anal/d/types-windows_wincred.sdb.txt diff --git a/libr/anal/d/types-windows_wincrypt.sdb.txt b/librz/anal/d/types-windows_wincrypt.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_wincrypt.sdb.txt rename to librz/anal/d/types-windows_wincrypt.sdb.txt diff --git a/libr/anal/d/types-windows_winhttp.sdb.txt b/librz/anal/d/types-windows_winhttp.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winhttp.sdb.txt rename to librz/anal/d/types-windows_winhttp.sdb.txt diff --git a/libr/anal/d/types-windows_winldap.sdb.txt b/librz/anal/d/types-windows_winldap.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winldap.sdb.txt rename to librz/anal/d/types-windows_winldap.sdb.txt diff --git a/libr/anal/d/types-windows_winnls.sdb.txt b/librz/anal/d/types-windows_winnls.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winnls.sdb.txt rename to librz/anal/d/types-windows_winnls.sdb.txt diff --git a/libr/anal/d/types-windows_winreg.sdb.txt b/librz/anal/d/types-windows_winreg.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winreg.sdb.txt rename to librz/anal/d/types-windows_winreg.sdb.txt diff --git a/libr/anal/d/types-windows_winsock2.sdb.txt b/librz/anal/d/types-windows_winsock2.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winsock2.sdb.txt rename to librz/anal/d/types-windows_winsock2.sdb.txt diff --git a/libr/anal/d/types-windows_winsvc.sdb.txt b/librz/anal/d/types-windows_winsvc.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winsvc.sdb.txt rename to librz/anal/d/types-windows_winsvc.sdb.txt diff --git a/libr/anal/d/types-windows_winuser.sdb.txt b/librz/anal/d/types-windows_winuser.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_winuser.sdb.txt rename to librz/anal/d/types-windows_winuser.sdb.txt diff --git a/libr/anal/d/types-windows_ws2spi.sdb.txt b/librz/anal/d/types-windows_ws2spi.sdb.txt similarity index 100% rename from libr/anal/d/types-windows_ws2spi.sdb.txt rename to librz/anal/d/types-windows_ws2spi.sdb.txt diff --git a/libr/anal/d/types-x86-macos-64.sdb.txt b/librz/anal/d/types-x86-macos-64.sdb.txt similarity index 100% rename from libr/anal/d/types-x86-macos-64.sdb.txt rename to librz/anal/d/types-x86-macos-64.sdb.txt diff --git a/libr/anal/d/types-x86-windows-32.sdb.txt b/librz/anal/d/types-x86-windows-32.sdb.txt similarity index 100% rename from libr/anal/d/types-x86-windows-32.sdb.txt rename to librz/anal/d/types-x86-windows-32.sdb.txt diff --git a/libr/anal/d/types-x86-windows-64.sdb.txt b/librz/anal/d/types-x86-windows-64.sdb.txt similarity index 100% rename from libr/anal/d/types-x86-windows-64.sdb.txt rename to librz/anal/d/types-x86-windows-64.sdb.txt diff --git a/libr/anal/d/types.sdb.txt b/librz/anal/d/types.sdb.txt similarity index 100% rename from libr/anal/d/types.sdb.txt rename to librz/anal/d/types.sdb.txt diff --git a/libr/anal/data.c b/librz/anal/data.c similarity index 67% rename from libr/anal/data.c rename to librz/anal/data.c index 89ffb7a6ec..3fa112c17d 100644 --- a/libr/anal/data.c +++ b/librz/anal/data.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2012-2017 - pancake */ -#include +#include #define MINLEN 1 static int is_string(const ut8 *buf, int size, int *len) { @@ -34,7 +34,7 @@ static int is_string(const ut8 *buf, int size, int *len) { } static int is_number(const ut8 *buf, int size) { - ut64 n = r_mem_get_num (buf, size); + ut64 n = rz_mem_get_num (buf, size); return (n < UT32_MAX)? (int)n: 0; } @@ -54,14 +54,14 @@ static int is_invalid(const ut8 *buf, int size) { } #define USE_IS_VALID_OFFSET 1 -static ut64 is_pointer(RAnal *anal, const ut8 *buf, int size) { +static ut64 is_pointer(RzAnal *anal, const ut8 *buf, int size) { ut64 n; ut8 buf2[32]; - RIOBind *iob = &anal->iob; + RzIOBind *iob = &anal->iob; if (size > sizeof (buf2)) { size = sizeof (buf2); } - n = r_mem_get_num (buf, size); + n = rz_mem_get_num (buf, size); if (!n) { return 1; // null pointer } @@ -97,7 +97,7 @@ static bool is_bin(const ut8 *buf, int size) { // TODO: add is_flag, is comment? -R_API char *r_anal_data_to_string(RAnalData *d, RConsPrintablePalette *pal) { +RZ_API char *rz_anal_data_to_string(RzAnalData *d, RzConsPrintablePalette *pal) { int i, len, mallocsz = 1024; ut32 n32; @@ -105,100 +105,100 @@ R_API char *r_anal_data_to_string(RAnalData *d, RConsPrintablePalette *pal) { return NULL; } - RStrBuf *sb = r_strbuf_new (NULL); - if (!sb || !r_strbuf_reserve (sb, mallocsz)) { + RStrBuf *sb = rz_strbuf_new (NULL); + if (!sb || !rz_strbuf_reserve (sb, mallocsz)) { eprintf ("Cannot allocate %d byte(s)\n", mallocsz); return NULL; } if (pal) { const char *k = pal->offset; - r_strbuf_appendf (sb, "%s0x%08" PFMT64x Color_RESET" ", k, d->addr); + rz_strbuf_appendf (sb, "%s0x%08" PFMT64x Color_RESET" ", k, d->addr); } else { - r_strbuf_appendf (sb, "0x%08" PFMT64x " ", d->addr); + rz_strbuf_appendf (sb, "0x%08" PFMT64x " ", d->addr); } n32 = (ut32)d->ptr; len = R_MIN (d->len, 8); for (i = 0; i < len; i++) { - r_strbuf_appendf (sb, "%02x", d->buf[i]); + rz_strbuf_appendf (sb, "%02x", d->buf[i]); } if (i > 0 && d->len > len) { - r_strbuf_append (sb, ".."); + rz_strbuf_append (sb, ".."); } - r_strbuf_append (sb, " "); + rz_strbuf_append (sb, " "); switch (d->type) { case R_ANAL_DATA_TYPE_STRING: if (pal) { - r_strbuf_appendf (sb, "%sstring \"%s\""Color_RESET, pal->comment, d->str); + rz_strbuf_appendf (sb, "%sstring \"%s\""Color_RESET, pal->comment, d->str); } else { - r_strbuf_appendf (sb, "string \"%s\"", d->str); + rz_strbuf_appendf (sb, "string \"%s\"", d->str); } break; case R_ANAL_DATA_TYPE_WIDE_STRING: - r_strbuf_append (sb, "wide string"); + rz_strbuf_append (sb, "wide string"); break; case R_ANAL_DATA_TYPE_NUMBER: if (pal) { const char *k = pal->num; if (n32 == d->ptr) { - r_strbuf_appendf (sb, "%snumber %d (0x%x)"Color_RESET, k, n32, n32); + rz_strbuf_appendf (sb, "%snumber %d (0x%x)"Color_RESET, k, n32, n32); } else { - r_strbuf_appendf (sb, "%snumber %" PFMT64d " (0x%" PFMT64x ")"Color_RESET, + rz_strbuf_appendf (sb, "%snumber %" PFMT64d " (0x%" PFMT64x ")"Color_RESET, k, d->ptr, d->ptr); } } else { if (n32 == d->ptr) { - r_strbuf_appendf (sb, "number %d 0x%x", n32, n32); + rz_strbuf_appendf (sb, "number %d 0x%x", n32, n32); } else { - r_strbuf_appendf (sb, "number %" PFMT64d " 0x%" PFMT64x, + rz_strbuf_appendf (sb, "number %" PFMT64d " 0x%" PFMT64x, d->ptr, d->ptr); } } break; case R_ANAL_DATA_TYPE_POINTER: - r_strbuf_append (sb, "pointer "); + rz_strbuf_append (sb, "pointer "); if (pal) { const char *k = pal->offset; - r_strbuf_appendf (sb, " %s0x%08" PFMT64x, k, d->ptr); + rz_strbuf_appendf (sb, " %s0x%08" PFMT64x, k, d->ptr); } else { - r_strbuf_appendf (sb, " 0x%08" PFMT64x, d->ptr); + rz_strbuf_appendf (sb, " 0x%08" PFMT64x, d->ptr); } break; case R_ANAL_DATA_TYPE_INVALID: if (pal) { - r_strbuf_appendf (sb, "%sinvalid"Color_RESET, pal->invalid); + rz_strbuf_appendf (sb, "%sinvalid"Color_RESET, pal->invalid); } else { - r_strbuf_append (sb, "invalid"); + rz_strbuf_append (sb, "invalid"); } break; case R_ANAL_DATA_TYPE_HEADER: - r_strbuf_append (sb, "header"); + rz_strbuf_append (sb, "header"); break; case R_ANAL_DATA_TYPE_SEQUENCE: - r_strbuf_append (sb, "sequence"); + rz_strbuf_append (sb, "sequence"); break; case R_ANAL_DATA_TYPE_PATTERN: - r_strbuf_append (sb, "pattern"); + rz_strbuf_append (sb, "pattern"); break; case R_ANAL_DATA_TYPE_UNKNOWN: if (pal) { - r_strbuf_appendf (sb, "%sunknown"Color_RESET, pal->invalid); + rz_strbuf_appendf (sb, "%sunknown"Color_RESET, pal->invalid); } else { - r_strbuf_append (sb, "unknown"); + rz_strbuf_append (sb, "unknown"); } break; default: if (pal) { - r_strbuf_appendf (sb, "%s(null)"Color_RESET, pal->b0x00); + rz_strbuf_appendf (sb, "%s(null)"Color_RESET, pal->b0x00); } else { - r_strbuf_append (sb, "(null)"); + rz_strbuf_append (sb, "(null)"); } break; } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int type) { - RAnalData *ad = R_NEW0 (RAnalData); +RZ_API RzAnalData *rz_anal_data_new_string(ut64 addr, const char *p, int len, int type) { + RzAnalData *ad = R_NEW0 (RzAnalData); if (!ad) { return NULL; } @@ -214,14 +214,14 @@ R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int t } else { ad->str = malloc (len + 1); if (!ad->str) { - r_anal_data_free (ad); + rz_anal_data_free (ad); return NULL; } memcpy (ad->str, p, len); ad->str[len] = 0; ad->buf = malloc (len + 1); if (!ad->buf) { - r_anal_data_free (ad); + rz_anal_data_free (ad); eprintf ("Cannot allocate %d byte(s)\n", len + 1); return NULL; } @@ -232,8 +232,8 @@ R_API RAnalData *r_anal_data_new_string(ut64 addr, const char *p, int len, int t return ad; } -R_API RAnalData *r_anal_data_new(ut64 addr, int type, ut64 n, const ut8 *buf, int len) { - RAnalData *ad = R_NEW0 (RAnalData); +RZ_API RzAnalData *rz_anal_data_new(ut64 addr, int type, ut64 n, const ut8 *buf, int len) { + RzAnalData *ad = R_NEW0 (RzAnalData); int l = R_MIN (len, 8); if (!ad) { return NULL; @@ -241,7 +241,7 @@ R_API RAnalData *r_anal_data_new(ut64 addr, int type, ut64 n, const ut8 *buf, in ad->buf = (ut8 *)&(ad->sbuf); memset (ad->buf, 0, 8); if (l < 1) { - r_anal_data_free (ad); + rz_anal_data_free (ad); return NULL; } if (buf) { @@ -262,7 +262,7 @@ R_API RAnalData *r_anal_data_new(ut64 addr, int type, ut64 n, const ut8 *buf, in return ad; } -R_API void r_anal_data_free(RAnalData *d) { +RZ_API void rz_anal_data_free(RzAnalData *d) { if (d) { if (d->buf != (ut8 *)&(d->sbuf)) { free (d->buf); @@ -272,7 +272,7 @@ R_API void r_anal_data_free(RAnalData *d) { } } -R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size, int wordsize) { +RZ_API RzAnalData *rz_anal_data(RzAnal *anal, ut64 addr, const ut8 *buf, int size, int wordsize) { ut64 dst = 0; int n, nsize = 0; int bits = anal->bits; @@ -282,7 +282,7 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size, i return NULL; } if (size >= word && is_invalid (buf, word)) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_INVALID, -1, buf, word); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_INVALID, -1, buf, word); } { int i, len = R_MIN (size, 64); @@ -302,52 +302,52 @@ R_API RAnalData *r_anal_data(RAnal *anal, ut64 addr, const ut8 *buf, int size, i } } if (is_sequence > len - 2) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_SEQUENCE, -1, + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_SEQUENCE, -1, buf, is_sequence); } if (is_pattern > len - 2) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_PATTERN, -1, + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_PATTERN, -1, buf, is_pattern); } } if (size >= word && is_null (buf, word)) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NULL, -1, buf, word); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_NULL, -1, buf, word); } if (is_bin (buf, size)) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_HEADER, -1, buf, word); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_HEADER, -1, buf, word); } if (size >= word) { dst = is_pointer (anal, buf, word); if (dst) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_POINTER, dst, buf, word); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_POINTER, dst, buf, word); } } switch (is_string (buf, size, &nsize)) { - case 1: return r_anal_data_new_string (addr, (const char *)buf, nsize, R_ANAL_DATA_TYPE_STRING); - case 2: return r_anal_data_new_string (addr, (const char *)buf, nsize, R_ANAL_DATA_TYPE_WIDE_STRING); + case 1: return rz_anal_data_new_string (addr, (const char *)buf, nsize, R_ANAL_DATA_TYPE_STRING); + case 2: return rz_anal_data_new_string (addr, (const char *)buf, nsize, R_ANAL_DATA_TYPE_WIDE_STRING); } if (size >= word) { n = is_number (buf, word); if (n) { - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER, n, buf, word); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_NUMBER, n, buf, word); } } - return r_anal_data_new (addr, R_ANAL_DATA_TYPE_UNKNOWN, dst, buf, R_MIN (word, size)); + return rz_anal_data_new (addr, R_ANAL_DATA_TYPE_UNKNOWN, dst, buf, R_MIN (word, size)); } -R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len) { +RZ_API const char *rz_anal_data_kind(RzAnal *a, ut64 addr, const ut8 *buf, int len) { int inv = 0; int unk = 0; int str = 0; int num = 0; int i, j; - RAnalData *data; + RzAnalData *data; int word = a->bits / 8; for (i = j = 0; i < len; j++) { if (str && !buf[i]) { str++; } - data = r_anal_data (a, addr + i, buf + i, len - i, 0); + data = rz_anal_data (a, addr + i, buf + i, len - i, 0); if (!data) { i += word; continue; @@ -378,7 +378,7 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len) default: i += word; } - r_anal_data_free (data); + rz_anal_data_free (data); } if (j < 1) { return "unknown"; @@ -398,7 +398,7 @@ R_API const char *r_anal_data_kind(RAnal *a, ut64 addr, const ut8 *buf, int len) return "data"; } -R_API const char *r_anal_datatype_to_string(RAnalDataType t) { +RZ_API const char *rz_anal_datatype_to_string(RzAnalDataType t) { switch (t) { case R_ANAL_DATATYPE_NULL: return NULL; diff --git a/libr/anal/diff.c b/librz/anal/diff.c similarity index 73% rename from libr/anal/diff.c rename to librz/anal/diff.c index e6a8226784..0e6a0839d2 100644 --- a/libr/anal/diff.c +++ b/librz/anal/diff.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2010-2020 - nibble, pancake */ -#include -#include -#include +#include +#include +#include -R_API RAnalDiff *r_anal_diff_new(void) { - RAnalDiff *diff = R_NEW0 (RAnalDiff); +RZ_API RzAnalDiff *rz_anal_diff_new(void) { + RzAnalDiff *diff = R_NEW0 (RzAnalDiff); if (diff) { diff->type = R_ANAL_DIFF_TYPE_NULL; diff->addr = UT64_MAX; @@ -16,7 +16,7 @@ R_API RAnalDiff *r_anal_diff_new(void) { return diff; } -R_API void* r_anal_diff_free(RAnalDiff *diff) { +RZ_API void* rz_anal_diff_free(RzAnalDiff *diff) { if (diff && diff->name) { R_FREE (diff->name); } @@ -25,7 +25,7 @@ R_API void* r_anal_diff_free(RAnalDiff *diff) { } /* 0-1 */ -R_API void r_anal_diff_setup(RAnal *anal, int doops, double thbb, double thfcn) { +RZ_API void rz_anal_diff_setup(RzAnal *anal, int doops, double thbb, double thfcn) { if (doops >= 0) { anal->diff_ops = doops; } @@ -34,7 +34,7 @@ R_API void r_anal_diff_setup(RAnal *anal, int doops, double thbb, double thfcn) } /* 0-100 */ -R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn) { +RZ_API void rz_anal_diff_setup_i(RzAnal *anal, int doops, int thbb, int thfcn) { if (doops >= 0) { anal->diff_ops = doops; } @@ -43,8 +43,8 @@ R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn) { } // Fingerprint function basic block -R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) { - RAnalOp *op; +RZ_API int rz_anal_diff_fingerprint_bb(RzAnal *anal, RzAnalBlock *bb) { + RzAnalOp *op; ut8 *buf; int oplen, idx = 0; @@ -64,13 +64,13 @@ R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) { if (anal->iob.read_at (anal->iob.io, bb->addr, buf, bb->size)) { memcpy (bb->fingerprint, buf, bb->size); if (anal->diff_ops) { // diff using only the opcode - if (!(op = r_anal_op_new ())) { + if (!(op = rz_anal_op_new ())) { free (bb->fingerprint); free (buf); return false; } while (idx < bb->size) { - if ((oplen = r_anal_op (anal, op, 0, buf+idx, bb->size-idx, R_ANAL_OP_MASK_BASIC)) < 1) { + if ((oplen = rz_anal_op (anal, op, 0, buf+idx, bb->size-idx, R_ANAL_OP_MASK_BASIC)) < 1) { break; } if (op->nopcode != 0) { @@ -85,9 +85,9 @@ R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) { return bb->size; } -R_API size_t r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *iter; +RZ_API size_t rz_anal_diff_fingerprint_fcn(RzAnal *anal, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *iter; if (anal && anal->cur && anal->cur->fingerprint_fcn) { return (anal->cur->fingerprint_fcn (anal, fcn)); @@ -95,7 +95,7 @@ R_API size_t r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn) { fcn->fingerprint = NULL; fcn->fingerprint_size = 0; - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { fcn->fingerprint_size += bb->size; fcn->fingerprint = realloc (fcn->fingerprint, fcn->fingerprint_size + 1); if (!fcn->fingerprint) { @@ -106,9 +106,9 @@ R_API size_t r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn) { return fcn->fingerprint_size; } -R_API bool r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2) { - RAnalBlock *bb, *bb2, *mbb, *mbb2; - RListIter *iter, *iter2; +RZ_API bool rz_anal_diff_bb(RzAnal *anal, RzAnalFunction *fcn, RzAnalFunction *fcn2) { + RzAnalBlock *bb, *bb2, *mbb, *mbb2; + RzListIter *iter, *iter2; double t, ot; if (!anal || !fcn || !fcn2) { @@ -118,15 +118,15 @@ R_API bool r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2) return (anal->cur->diff_bb (anal, fcn, fcn2)); } fcn->diff->type = fcn2->diff->type = R_ANAL_DIFF_TYPE_MATCH; - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->diff && bb->diff->type != R_ANAL_DIFF_TYPE_NULL) { continue; } ot = 0; mbb = mbb2 = NULL; - r_list_foreach (fcn2->bbs, iter2, bb2) { + rz_list_foreach (fcn2->bbs, iter2, bb2) { if (!bb2->diff || bb2->diff->type == R_ANAL_DIFF_TYPE_NULL) { - r_diff_buffers_distance (NULL, bb->fingerprint, bb->size, + rz_diff_buffers_distance (NULL, bb->fingerprint, bb->size, bb2->fingerprint, bb2->size, NULL, &t); if (t > anal->diff_thbb && t > ot) { ot = t; @@ -140,10 +140,10 @@ R_API bool r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2) } if (mbb && mbb2) { if (!mbb->diff) { - mbb->diff = r_anal_diff_new(); + mbb->diff = rz_anal_diff_new(); } if (!mbb2->diff) { - mbb2->diff = r_anal_diff_new(); + mbb2->diff = rz_anal_diff_new(); } if (!mbb->diff || !mbb2->diff) { return false; @@ -170,9 +170,9 @@ R_API bool r_anal_diff_bb(RAnal *anal, RAnalFunction *fcn, RAnalFunction *fcn2) return true; } -R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { - RAnalFunction *fcn, *fcn2, *mfcn, *mfcn2; - RListIter *iter, *iter2; +RZ_API int rz_anal_diff_fcn(RzAnal *anal, RzList *fcns, RzList *fcns2) { + RzAnalFunction *fcn, *fcn2, *mfcn, *mfcn2; + RzListIter *iter, *iter2; ut64 maxsize, minsize; double t, ot; @@ -184,12 +184,12 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { } /* Compare functions with the same name */ if (fcns) { - r_list_foreach (fcns, iter, fcn) { - r_list_foreach (fcns2, iter2, fcn2) { + rz_list_foreach (fcns, iter, fcn) { + rz_list_foreach (fcns2, iter2, fcn2) { if (fcn->name && fcn2->name && strcmp (fcn->name, fcn2->name)) { continue; } - r_diff_buffers_distance (NULL, fcn->fingerprint, fcn->fingerprint_size, + rz_diff_buffers_distance (NULL, fcn->fingerprint, fcn->fingerprint_size, fcn2->fingerprint, fcn2->fingerprint_size, NULL, &t); /* Set flag in matched functions */ @@ -201,8 +201,8 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { R_FREE (fcn2->fingerprint); fcn->diff->addr = fcn2->addr; fcn2->diff->addr = fcn->addr; - fcn->diff->size = r_anal_function_linear_size (fcn2); - fcn2->diff->size = r_anal_function_linear_size (fcn); + fcn->diff->size = rz_anal_function_linear_size (fcn2); + fcn2->diff->size = rz_anal_function_linear_size (fcn); R_FREE (fcn->diff->name); if (fcn2->name) { fcn->diff->name = strdup (fcn2->name); @@ -211,13 +211,13 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { if (fcn->name) { fcn2->diff->name = strdup (fcn->name); } - r_anal_diff_bb (anal, fcn, fcn2); + rz_anal_diff_bb (anal, fcn, fcn2); break; } } } /* Compare remaining functions */ - r_list_foreach (fcns, iter, fcn) { + rz_list_foreach (fcns, iter, fcn) { /* if ((fcn->type != R_ANAL_FCN_TYPE_FCN && fcn->type != R_ANAL_FCN_TYPE_SYM) || @@ -230,9 +230,9 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { } ot = 0; mfcn = mfcn2 = NULL; - r_list_foreach (fcns2, iter2, fcn2) { - ut64 fcn_size = r_anal_function_linear_size (fcn); - ut64 fcn2_size = r_anal_function_linear_size (fcn2); + rz_list_foreach (fcns2, iter2, fcn2) { + ut64 fcn_size = rz_anal_function_linear_size (fcn); + ut64 fcn2_size = rz_anal_function_linear_size (fcn2); if (fcn_size > fcn2_size) { maxsize = fcn_size; minsize = fcn2_size; @@ -252,7 +252,7 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { eprintf ("Function %s type not supported\n", fcn2->name); continue; } - r_diff_buffers_distance (NULL, fcn->fingerprint, fcn->fingerprint_size, fcn2->fingerprint, fcn2->fingerprint_size, NULL, &t); + rz_diff_buffers_distance (NULL, fcn->fingerprint, fcn->fingerprint_size, fcn2->fingerprint, fcn2->fingerprint_size, NULL, &t); fcn->diff->dist = fcn2->diff->dist = t; if (t > anal->diff_thfcn && t > ot) { ot = t; @@ -272,8 +272,8 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { R_FREE (mfcn2->fingerprint); mfcn->diff->addr = mfcn2->addr; mfcn2->diff->addr = mfcn->addr; - mfcn->diff->size = r_anal_function_linear_size (mfcn2); - mfcn2->diff->size = r_anal_function_linear_size (mfcn); + mfcn->diff->size = rz_anal_function_linear_size (mfcn2); + mfcn2->diff->size = rz_anal_function_linear_size (mfcn); R_FREE (mfcn->diff->name); if (mfcn2->name) { mfcn->diff->name = strdup (mfcn2->name); @@ -282,13 +282,13 @@ R_API int r_anal_diff_fcn(RAnal *anal, RList *fcns, RList *fcns2) { if (mfcn->name) { mfcn2->diff->name = strdup (mfcn->name); } - r_anal_diff_bb (anal, mfcn, mfcn2); + rz_anal_diff_bb (anal, mfcn, mfcn2); } } return true; } -R_API int r_anal_diff_eval(RAnal *anal) { +RZ_API int rz_anal_diff_eval(RzAnal *anal) { if (anal && anal->cur && anal->cur->diff_eval) { return (anal->cur->diff_eval (anal)); } diff --git a/libr/anal/dwarf_process.c b/librz/anal/dwarf_process.c similarity index 83% rename from libr/anal/dwarf_process.c rename to librz/anal/dwarf_process.c index bfba28c9f5..61e8de8a9a 100644 --- a/libr/anal/dwarf_process.c +++ b/librz/anal/dwarf_process.c @@ -2,12 +2,12 @@ #include "base_types.h" #include -#include -#include +#include +#include #include typedef struct dwarf_parse_context_t { - const RAnal *anal; + const RzAnal *anal; const RBinDwarfDie *all_dies; const ut64 count; Sdb *sdb; @@ -60,7 +60,7 @@ static void variable_free(Variable *var) { /* return -1 if attr isn't found */ static inline st32 find_attr_idx(const RBinDwarfDie *die, st32 attr_name) { st32 i; - r_return_val_if_fail (die, -1); + rz_return_val_if_fail (die, -1); for (i = 0; i < die->count; i++) { if (die->attr_values[i].attr_name == attr_name) { return i; @@ -72,7 +72,7 @@ static inline st32 find_attr_idx(const RBinDwarfDie *die, st32 attr_name) { /* return NULL if attr isn't found */ static RBinDwarfAttrValue *find_attr(const RBinDwarfDie *die, st32 attr_name) { st32 i; - r_return_val_if_fail (die, NULL); + rz_return_val_if_fail (die, NULL); for (i = 0; i < die->count; i++) { if (die->attr_values[i].attr_name == attr_name) { return &die->attr_values[i]; @@ -82,7 +82,7 @@ static RBinDwarfAttrValue *find_attr(const RBinDwarfDie *die, st32 attr_name) { } /** - * @brief Pasted from r_strbuf_* + * @brief Pasted from rz_strbuf_* * Prepends string before a last occurence of character c * Used to replicate proper C declaration for function pointers * @param sb @@ -90,7 +90,7 @@ static RBinDwarfAttrValue *find_attr(const RBinDwarfDie *die, st32 attr_name) { * @param c */ static bool strbuf_rev_prepend_char(RStrBuf *sb, const char *s, int c) { - r_return_val_if_fail (sb && s, false); + rz_return_val_if_fail (sb && s, false); size_t l = strlen (s); // fast path if no chars to append if (l == 0) { @@ -110,13 +110,13 @@ static bool strbuf_rev_prepend_char(RStrBuf *sb, const char *s, int c) { memcpy (ns + idx, s, l); memcpy (ns + idx + l, sb_str + idx, sb->len - idx); ns[newlen] = 0; - ret = r_strbuf_set (sb, ns) != NULL; + ret = rz_strbuf_set (sb, ns) != NULL; free (ns); } return ret; } /** - * @brief Pasted from r_strbuf_* + * @brief Pasted from rz_strbuf_* * Appends string after a first occurence of character c * Used to replicate proper C declaration for function pointers * @param sb @@ -124,7 +124,7 @@ static bool strbuf_rev_prepend_char(RStrBuf *sb, const char *s, int c) { * @param needle */ static bool strbuf_rev_append_char(RStrBuf *sb, const char *s, const char *needle) { - r_return_val_if_fail (sb && s, false); + rz_return_val_if_fail (sb && s, false); size_t l = strlen (s); // fast path if no chars to append if (l == 0) { @@ -145,14 +145,14 @@ static bool strbuf_rev_append_char(RStrBuf *sb, const char *s, const char *needl memcpy (ns + idx, s, l); memcpy (ns + idx + l, sb_str + idx, sb->len - idx); ns[newlen] = 0; - ret = r_strbuf_set (sb, ns) != NULL; + ret = rz_strbuf_set (sb, ns) != NULL; free (ns); } return ret; } static inline char *create_type_name_from_offset(ut64 offset) { - return r_str_newf ("type_0x%" PFMT64x, offset); + return rz_str_newf ("type_0x%" PFMT64x, offset); } /** @@ -221,7 +221,7 @@ static st32 parse_array_type(Context *ctx, ut64 idx, RStrBuf *strbuf) { switch (value->attr_name) { case DW_AT_upper_bound: case DW_AT_count: - r_strbuf_appendf (strbuf, "[%d]", value->uconstant + 1); + rz_strbuf_appendf (strbuf, "[%d]", value->uconstant + 1); break; default: @@ -255,7 +255,7 @@ static st32 parse_array_type(Context *ctx, ut64 idx, RStrBuf *strbuf) { * multiple times which means it's parsed multiple times instead of once */ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 *size) { - r_return_val_if_fail (strbuf, -1); + rz_return_val_if_fail (strbuf, -1); RBinDwarfDie *die = ht_up_find (ctx->die_map, offset, NULL); if (!die) { return -1; @@ -273,8 +273,8 @@ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 * case DW_TAG_pointer_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx == -1) { - r_strbuf_append (strbuf, "void"); - r_strbuf_append (strbuf, " *"); + rz_strbuf_append (strbuf, "void"); + rz_strbuf_append (strbuf, " *"); } else { tag = parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); if (tag == DW_TAG_subroutine_type) { @@ -284,7 +284,7 @@ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 * strbuf_rev_prepend_char (strbuf, "*", '*'); } } else { - r_strbuf_append (strbuf, " *"); + rz_strbuf_append (strbuf, " *"); } } break; @@ -297,20 +297,20 @@ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 * case DW_TAG_union_type: case DW_TAG_class_type: name = get_die_name (die); - r_strbuf_append (strbuf, name); + rz_strbuf_append (strbuf, name); free (name); break; case DW_TAG_subroutine_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx == -1) { - r_strbuf_append (strbuf, "void"); + rz_strbuf_append (strbuf, "void"); } else { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " ("); + rz_strbuf_append (strbuf, " ("); if (die->has_children) { // has parameters } - r_strbuf_append (strbuf, ")"); + rz_strbuf_append (strbuf, ")"); break; case DW_TAG_array_type: type_idx = find_attr_idx (die, DW_AT_type); @@ -324,35 +324,35 @@ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 * if (type_idx != -1) { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " const"); + rz_strbuf_append (strbuf, " const"); break; case DW_TAG_volatile_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx != -1) { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " volatile"); + rz_strbuf_append (strbuf, " volatile"); break; case DW_TAG_restrict_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx != -1) { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " restrict"); + rz_strbuf_append (strbuf, " restrict"); break; case DW_TAG_rvalue_reference_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx != -1) { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " &&"); + rz_strbuf_append (strbuf, " &&"); break; case DW_TAG_reference_type: type_idx = find_attr_idx (die, DW_AT_type); if (type_idx != -1) { parse_type (ctx, die->attr_values[type_idx].reference, strbuf, size); } - r_strbuf_append (strbuf, " &"); + rz_strbuf_append (strbuf, " &"); break; default: break; @@ -361,16 +361,16 @@ static st32 parse_type (Context *ctx, const ut64 offset, RStrBuf *strbuf, ut64 * } /** - * @brief Parses structured entry into *result RAnalStructMember + * @brief Parses structured entry into *result RzAnalStructMember * http://www.dwarfstd.org/doc/DWARF4.pdf#page=102&zoom=100,0,0 * * @param ctx * @param idx index of the current entry * @param result ptr to result member to fill up - * @return RAnalStructMember* ptr to parsed Member + * @return RzAnalStructMember* ptr to parsed Member */ -static RAnalStructMember *parse_struct_member (Context *ctx, ut64 idx, RAnalStructMember *result) { - r_return_val_if_fail (result, NULL); +static RzAnalStructMember *parse_struct_member (Context *ctx, ut64 idx, RzAnalStructMember *result) { + rz_return_val_if_fail (result, NULL); const RBinDwarfDie *die = &ctx->all_dies[idx]; char *name = NULL; @@ -378,7 +378,7 @@ static RAnalStructMember *parse_struct_member (Context *ctx, ut64 idx, RAnalStru ut64 offset = 0; ut64 size = 0; RStrBuf strbuf; - r_strbuf_init (&strbuf); + rz_strbuf_init (&strbuf); size_t i; for (i = 0; i < die->count; i++) { RBinDwarfAttrValue *value = &die->attr_values[i]; @@ -391,7 +391,7 @@ static RAnalStructMember *parse_struct_member (Context *ctx, ut64 idx, RAnalStru break; case DW_AT_type: parse_type (ctx, value->reference, &strbuf, &size); - type = r_strbuf_drain_nofree (&strbuf); + type = rz_strbuf_drain_nofree (&strbuf); if (!type || !*type) { goto cleanup; } @@ -440,15 +440,15 @@ cleanup: } /** - * @brief Parses enum entry into *result RAnalEnumCase + * @brief Parses enum entry into *result RzAnalEnumCase * http://www.dwarfstd.org/doc/DWARF4.pdf#page=110&zoom=100,0,0 * * @param ctx * @param idx index of the current entry * @param result ptr to result case to fill up - * @return RAnalEnumCase* Ptr to parsed enum case + * @return RzAnalEnumCase* Ptr to parsed enum case */ -static RAnalEnumCase *parse_enumerator(Context *ctx, ut64 idx, RAnalEnumCase *result) { +static RzAnalEnumCase *parse_enumerator(Context *ctx, ut64 idx, RzAnalEnumCase *result) { const RBinDwarfDie *die = &ctx->all_dies[idx]; char *name = NULL; @@ -484,7 +484,7 @@ cleanup: /** * @brief Parses a structured entry (structs, classes, unions) into - * RAnalBaseType and saves it using r_anal_save_base_type () + * RzAnalBaseType and saves it using rz_anal_save_base_type () * * @param ctx * @param idx index of the current entry @@ -493,14 +493,14 @@ cleanup: static void parse_structure_type(Context *ctx, ut64 idx) { const RBinDwarfDie *die = &ctx->all_dies[idx]; - RAnalBaseTypeKind kind; + RzAnalBaseTypeKind kind; if (die->tag == DW_TAG_union_type) { kind = R_ANAL_BASE_TYPE_KIND_UNION; } else { kind = R_ANAL_BASE_TYPE_KIND_STRUCT; } - RAnalBaseType *base_type = r_anal_base_type_new (kind); + RzAnalBaseType *base_type = rz_anal_base_type_new (kind); if (!base_type) { return; } @@ -526,7 +526,7 @@ static void parse_structure_type(Context *ctx, ut64 idx) { base_type->size = get_die_size (die); - RAnalStructMember member = { 0 }; + RzAnalStructMember member = { 0 }; // Parse out all members, can this in someway be extracted to a function? if (die->has_children) { int child_depth = 1; // Direct children of the node @@ -537,11 +537,11 @@ static void parse_structure_type(Context *ctx, ut64 idx) { // we take only direct descendats of the structure // can be also DW_TAG_suprogram for class methods or tag for templates if (child_depth == 1 && child_die->tag == DW_TAG_member) { - RAnalStructMember *result = parse_struct_member (ctx, j, &member); + RzAnalStructMember *result = parse_struct_member (ctx, j, &member); if (!result) { goto cleanup; } else { - void *element = r_vector_push (&base_type->struct_data.members, &member); + void *element = rz_vector_push (&base_type->struct_data.members, &member); if (!element) { goto cleanup; } @@ -555,14 +555,14 @@ static void parse_structure_type(Context *ctx, ut64 idx) { } } } - r_anal_save_base_type (ctx->anal, base_type); + rz_anal_save_base_type (ctx->anal, base_type); cleanup: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); } /** - * @brief Parses a enum entry into RAnalBaseType and saves it - * int Sdb using r_anal_save_base_type () + * @brief Parses a enum entry into RzAnalBaseType and saves it + * int Sdb using rz_anal_save_base_type () * * @param ctx * @param idx index of the current entry @@ -570,7 +570,7 @@ cleanup: static void parse_enum_type(Context *ctx, ut64 idx) { const RBinDwarfDie *die = &ctx->all_dies[idx]; - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); if (!base_type) { return; } @@ -584,12 +584,12 @@ static void parse_enum_type(Context *ctx, ut64 idx) { st32 type_attr_idx = find_attr_idx (die, DW_AT_type); if (type_attr_idx != -1) { RStrBuf strbuf; - r_strbuf_init (&strbuf); + rz_strbuf_init (&strbuf); parse_type (ctx, die->attr_values[type_attr_idx].reference, &strbuf, &base_type->size); - base_type->type = r_strbuf_drain_nofree (&strbuf); + base_type->type = rz_strbuf_drain_nofree (&strbuf); } - RAnalEnumCase cas; + RzAnalEnumCase cas; if (die->has_children) { int child_depth = 1; // Direct children of the node size_t j; @@ -598,11 +598,11 @@ static void parse_enum_type(Context *ctx, ut64 idx) { const RBinDwarfDie *child_die = &ctx->all_dies[j]; // we take only direct descendats of the structure if (child_depth == 1 && child_die->tag == DW_TAG_enumerator) { - RAnalEnumCase *result = parse_enumerator (ctx, j, &cas); + RzAnalEnumCase *result = parse_enumerator (ctx, j, &cas); if (!result) { goto cleanup; } else { - void *element = r_vector_push (&base_type->enum_data.cases, &cas); + void *element = rz_vector_push (&base_type->enum_data.cases, &cas); if (!element) { enum_type_case_free (result, NULL); goto cleanup; @@ -618,14 +618,14 @@ static void parse_enum_type(Context *ctx, ut64 idx) { } } } - r_anal_save_base_type (ctx->anal, base_type); + rz_anal_save_base_type (ctx->anal, base_type); cleanup: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); } /** - * @brief Parses a typedef entry into RAnalBaseType and saves it - * using r_anal_save_base_type () + * @brief Parses a typedef entry into RzAnalBaseType and saves it + * using rz_anal_save_base_type () * * http://www.dwarfstd.org/doc/DWARF4.pdf#page=96&zoom=100,0,0 * @@ -639,7 +639,7 @@ static void parse_typedef(Context *ctx, ut64 idx) { char *type = NULL; ut64 size = 0; RStrBuf strbuf; - r_strbuf_init (&strbuf); + rz_strbuf_init (&strbuf); size_t i; for (i = 0; i < die->count; i++) { @@ -653,7 +653,7 @@ static void parse_typedef(Context *ctx, ut64 idx) { break; case DW_AT_type: parse_type (ctx, value->reference, &strbuf, &size); - type = r_strbuf_drain_nofree (&strbuf); + type = rz_strbuf_drain_nofree (&strbuf); if (!type) { goto cleanup; } @@ -665,20 +665,20 @@ static void parse_typedef(Context *ctx, ut64 idx) { if (!name) { // type has to have a name for now goto cleanup; } - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_TYPEDEF); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_TYPEDEF); if (!base_type) { goto cleanup; } base_type->name = name; base_type->type = type; - r_anal_save_base_type (ctx->anal, base_type); - r_anal_base_type_free (base_type); - r_strbuf_fini (&strbuf); + rz_anal_save_base_type (ctx->anal, base_type); + rz_anal_base_type_free (base_type); + rz_strbuf_fini (&strbuf); return; cleanup: free (name); free (type); - r_strbuf_fini (&strbuf); + rz_strbuf_fini (&strbuf); } static void parse_atomic_type(Context *ctx, ut64 idx) { @@ -715,14 +715,14 @@ static void parse_atomic_type(Context *ctx, ut64 idx) { if (!name) { // type has to have a name for now return; } - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ATOMIC); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ATOMIC); if (!base_type) { return; } base_type->name = name; base_type->size = size; - r_anal_save_base_type (ctx->anal, base_type); - r_anal_base_type_free (base_type); + rz_anal_save_base_type (ctx->anal, base_type); + rz_anal_base_type_free (base_type); } static const char *get_specification_die_name(const RBinDwarfDie *die) { @@ -849,7 +849,7 @@ static const char *map_dwarf_reg_to_x86_reg(ut64 reg_num, VariableLocationKind * case 27: return "xmm6"; case 28: return "xmm7"; default: - r_warn_if_reached (); + rz_warn_if_reached (); *kind = LOCATION_UNKNOWN; return "unsupported_reg"; } @@ -894,7 +894,7 @@ static const char *map_dwarf_reg_to_ppc64_reg(ut64 reg_num, VariableLocationKind case 30: return "r30"; case 31: return "r31"; default: - r_warn_if_reached (); + rz_warn_if_reached (); *kind = LOCATION_UNKNOWN; return "unsupported_reg"; } @@ -918,12 +918,12 @@ static const char *get_dwarf_reg_name(char *arch, int reg_num, VariableLocationK return "unsupported_reg"; } -static RBinDwarfLocRange *find_largest_loc_range (RList *loc_list) { +static RBinDwarfLocRange *find_largest_loc_range (RzList *loc_list) { RBinDwarfLocRange *largest = NULL; ut64 max_range_size = 0; - RListIter *iter; + RzListIter *iter; RBinDwarfLocRange *range; - r_list_foreach (loc_list, iter, range) { + rz_list_foreach (loc_list, iter, range) { ut64 diff = range->end - range->start; if (diff > max_range_size) { max_range_size = diff ; @@ -979,7 +979,7 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr return NULL; } const ut8 *dump = &block.data[++i]; - offset = r_sleb128 (&dump, &block.data[loc->block.length]); + offset = rz_sleb128 (&dump, &block.data[loc->block.length]); if (frame_base) { /* recursive parsing, but frame_base should be only one, but someone could make malicious resource exhaustion attack, so a depth counter might be cool? */ @@ -1070,7 +1070,7 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr signed LEB128 offset from the specified register. */ reg_num = block.data[i] - DW_OP_breg0; // get the reg number const ut8 *buffer = &block.data[++i]; - offset = r_sleb128 (&buffer, &block.data[block.length]); + offset = rz_sleb128 (&buffer, &block.data[block.length]); /* TODO do a proper expression parsing, move by the amount of bytes sleb reads */ i += buffer - &block.data[0]; reg_name = get_dwarf_reg_name (ctx->anal->cpu, reg_num, &kind, ctx->anal->bits); @@ -1083,11 +1083,11 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr /* I need to find binaries that uses this so I can test it out*/ const ut8 *buffer = &block.data[++i]; const ut8 *buf_end = &block.data[block.length]; - buffer = r_uleb128 (buffer, buf_end - buffer, ®_num, NULL); + buffer = rz_uleb128 (buffer, buf_end - buffer, ®_num, NULL); if (buffer == buf_end) { return NULL; } - offset = r_sleb128 (&buffer, buf_end); + offset = rz_sleb128 (&buffer, buf_end); reg_name = get_dwarf_reg_name (ctx->anal->cpu, reg_num, &kind, ctx->anal->bits); } break; case DW_OP_addr: { @@ -1101,19 +1101,19 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr } switch (addr_size) { case 1: - address = r_read_ble8 (dump); + address = rz_read_ble8 (dump); break; case 2: - address = r_read_ble16 (dump, ctx->anal->big_endian); + address = rz_read_ble16 (dump, ctx->anal->big_endian); break; case 4: - address = r_read_ble32 (dump, ctx->anal->big_endian); + address = rz_read_ble32 (dump, ctx->anal->big_endian); break; case 8: - address = r_read_ble64 (dump, ctx->anal->big_endian); + address = rz_read_ble64 (dump, ctx->anal->big_endian); break; default: - r_warn_if_reached (); /* weird addr_size */ + rz_warn_if_reached (); /* weird addr_size */ return NULL; } kind = LOCATION_GLOBAL; // address @@ -1141,7 +1141,7 @@ static VariableLocation *parse_dwarf_location (Context *ctx, const RBinDwarfAttr return location; } -static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, RList/**/ *variables) { +static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, RzList/**/ *variables) { const RBinDwarfDie *die = &ctx->all_dies[idx]; if (die->has_children) { @@ -1155,7 +1155,7 @@ static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, for (j = idx; child_depth > 0 && j < ctx->count; j++) { child_die = &ctx->all_dies[j]; RStrBuf type; - r_strbuf_init (&type); + rz_strbuf_init (&type); const char *name = NULL; if (child_die->tag == DW_TAG_formal_parameter || child_die->tag == DW_TAG_variable) { Variable *var = R_NEW0 (Variable); @@ -1191,13 +1191,13 @@ static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, /* arguments sometimes have only type, create generic argX */ if (type.len) { if (!name) { - var->name = r_str_newf ("arg%d", argNumber); + var->name = rz_str_newf ("arg%d", argNumber); } else { var->name = strdup (name); } - r_strbuf_appendf (args, "%s %s,", r_strbuf_get (&type), var->name); - var->type = strdup (r_strbuf_get (&type)); - r_list_append (variables, var); + rz_strbuf_appendf (args, "%s %s,", rz_strbuf_get (&type), var->name); + var->type = strdup (rz_strbuf_get (&type)); + rz_list_append (variables, var); } else { variable_free (var); } @@ -1205,15 +1205,15 @@ static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, } else { /* DW_TAG_variable */ if (name && type.len) { var->name = strdup (name); - var->type = strdup (r_strbuf_get (&type)); - r_list_append (variables, var); + var->type = strdup (rz_strbuf_get (&type)); + rz_list_append (variables, var); } else { variable_free (var); } - r_strbuf_fini (&type); + rz_strbuf_fini (&type); } } else if (child_depth == 1 && child_die->tag == DW_TAG_unspecified_parameters) { - r_strbuf_appendf (args, "va_args ...,"); + rz_strbuf_appendf (args, "va_args ...,"); } if (child_die->has_children) { child_depth++; @@ -1221,41 +1221,41 @@ static st32 parse_function_args_and_vars(Context *ctx, ut64 idx, RStrBuf *args, if (child_die->abbrev_code == 0) { /* sibling list is terminated by null entry */ child_depth--; } - r_strbuf_fini (&type); + rz_strbuf_fini (&type); } if (args->len > 0) { - r_strbuf_slice (args, 0, args->len - 1); + rz_strbuf_slice (args, 0, args->len - 1); } } return 0; } -static void sdb_save_dwarf_function(Function *dwarf_fcn, RList/**/ *variables, Sdb *sdb) { - char *sname = r_str_sanitize_sdb_key (dwarf_fcn->name); +static void sdb_save_dwarf_function(Function *dwarf_fcn, RzList/**/ *variables, Sdb *sdb) { + char *sname = rz_str_sanitize_sdb_key (dwarf_fcn->name); sdb_set (sdb, sname, "fcn", 0); - char *addr_key = r_str_newf ("fcn.%s.addr", sname); - char *addr_val = r_str_newf ("0x%" PFMT64x "", dwarf_fcn->addr); + char *addr_key = rz_str_newf ("fcn.%s.addr", sname); + char *addr_val = rz_str_newf ("0x%" PFMT64x "", dwarf_fcn->addr); sdb_set (sdb, addr_key, addr_val, 0); free (addr_key); free (addr_val); /* so we can have name without sanitization */ - char *name_key = r_str_newf ("fcn.%s.name", sname); - char *name_val = r_str_newf ("%s", dwarf_fcn->name); + char *name_key = rz_str_newf ("fcn.%s.name", sname); + char *name_val = rz_str_newf ("%s", dwarf_fcn->name); sdb_set (sdb, name_key, name_val, 0); free (name_key); free (name_val); - char *signature_key = r_str_newf ("fcn.%s.sig", sname); + char *signature_key = rz_str_newf ("fcn.%s.sig", sname); sdb_set (sdb, signature_key, dwarf_fcn->signature, 0); free (signature_key); RStrBuf vars; - r_strbuf_init (&vars); - RListIter *iter; + rz_strbuf_init (&vars); + RzListIter *iter; Variable *var; - r_list_foreach (variables, iter, var) { + rz_list_foreach (variables, iter, var) { if (!var->location) { /* NULL location probably means optimized out, maybe put a comment there */ continue; @@ -1266,33 +1266,33 @@ static void sdb_save_dwarf_function(Function *dwarf_fcn, RList/**/ *v case LOCATION_BP: { /* value = "type, storage, additional info based on storage (offset)" */ - r_strbuf_appendf (&vars, "%s,", var->name); - key = r_str_newf ("fcn.%s.var.%s", sname, var->name); - val = r_str_newf ("%s,%" PFMT64d ",%s", "b", var->location->offset, var->type); + rz_strbuf_appendf (&vars, "%s,", var->name); + key = rz_str_newf ("fcn.%s.var.%s", sname, var->name); + val = rz_str_newf ("%s,%" PFMT64d ",%s", "b", var->location->offset, var->type); sdb_set (sdb, key, val, 0); } break; case LOCATION_SP: { /* value = "type, storage, additional info based on storage (offset)" */ - r_strbuf_appendf (&vars, "%s,", var->name); - key = r_str_newf ("fcn.%s.var.%s", sname, var->name); - val = r_str_newf ("%s,%" PFMT64d ",%s", "s", var->location->offset, var->type); + rz_strbuf_appendf (&vars, "%s,", var->name); + key = rz_str_newf ("fcn.%s.var.%s", sname, var->name); + val = rz_str_newf ("%s,%" PFMT64d ",%s", "s", var->location->offset, var->type); sdb_set (sdb, key, val, 0); } break; case LOCATION_GLOBAL: { /* value = "type, storage, additional info based on storage (address)" */ - r_strbuf_appendf (&vars, "%s,", var->name); - key = r_str_newf ("fcn.%s.var.%s", sname, var->name); - val = r_str_newf ("%s,%" PFMT64u ",%s", "g", var->location->address, var->type); + rz_strbuf_appendf (&vars, "%s,", var->name); + key = rz_str_newf ("fcn.%s.var.%s", sname, var->name); + val = rz_str_newf ("%s,%" PFMT64u ",%s", "g", var->location->address, var->type); sdb_set (sdb, key, val, 0); } break; case LOCATION_REGISTER: { /* value = "type, storage, additional info based on storage (register name)" */ - r_strbuf_appendf (&vars, "%s,", var->name); - key = r_str_newf ("fcn.%s.var.%s", sname, var->name); - val = r_str_newf ("%s,%s,%s", "r", var->location->reg_name, var->type); + rz_strbuf_appendf (&vars, "%s,", var->name); + key = rz_str_newf ("fcn.%s.var.%s", sname, var->name); + val = rz_str_newf ("%s,%s,%s", "r", var->location->reg_name, var->type); sdb_set (sdb, key, val, 0); } break; @@ -1304,14 +1304,14 @@ static void sdb_save_dwarf_function(Function *dwarf_fcn, RList/**/ *v free (val); } if (vars.len > 0) { /* remove the extra , */ - r_strbuf_slice (&vars, 0, vars.len - 1); /* leaks? */ + rz_strbuf_slice (&vars, 0, vars.len - 1); /* leaks? */ } - char *vars_key = r_str_newf ("fcn.%s.vars", sname); - char *vars_val = r_str_newf ("%s", r_strbuf_get (&vars)); + char *vars_key = rz_str_newf ("fcn.%s.vars", sname); + char *vars_val = rz_str_newf ("%s", rz_strbuf_get (&vars)); sdb_set (sdb, vars_key, vars_val, 0); free (vars_key); free (vars_val); - r_strbuf_fini (&vars); + rz_strbuf_fini (&vars); free (sname); } @@ -1329,7 +1329,7 @@ static void parse_function(Context *ctx, ut64 idx) { bool has_linkage_name = false; bool get_linkage_name = prefer_linkage_name (ctx->lang); RStrBuf ret_type; - r_strbuf_init (&ret_type); + rz_strbuf_init (&ret_type); if (find_attr_idx (die, DW_AT_declaration) != -1) { return; /* just declaration skip */ } @@ -1394,32 +1394,32 @@ static void parse_function(Context *ctx, ut64 idx) { goto cleanup; } RStrBuf args; - r_strbuf_init (&args); + rz_strbuf_init (&args); /* TODO do the same for arguments in future so we can use their location */ - RList/**/ *variables = r_list_new (); + RzList/**/ *variables = rz_list_new (); parse_function_args_and_vars (ctx, idx, &args, variables); if (ret_type.len == 0) { /* DW_AT_type is omitted in case of `void` ret type */ - r_strbuf_append (&ret_type, "void"); + rz_strbuf_append (&ret_type, "void"); } - r_warn_if_fail (ctx->lang); + rz_warn_if_fail (ctx->lang); char *new_name = ctx->anal->binb.demangle (NULL, ctx->lang, fcn.name, fcn.addr, false); fcn.name = new_name ? new_name : strdup (fcn.name); - fcn.signature = r_str_newf ("%s %s(%s);", r_strbuf_get (&ret_type), fcn.name, r_strbuf_get (&args)); + fcn.signature = rz_str_newf ("%s %s(%s);", rz_strbuf_get (&ret_type), fcn.name, rz_strbuf_get (&args)); sdb_save_dwarf_function (&fcn, variables, ctx->sdb); free ((char *)fcn.signature); free ((char *)fcn.name); - RListIter *iter; + RzListIter *iter; Variable *var; - r_list_foreach (variables, iter, var) { + rz_list_foreach (variables, iter, var) { variable_free (var); } - r_list_free (variables); - r_strbuf_fini (&args); + rz_list_free (variables); + rz_strbuf_fini (&args); cleanup: - r_strbuf_fini (&ret_type); + rz_strbuf_fini (&ret_type); } /** @@ -1429,7 +1429,7 @@ cleanup: * @return char* string literal language represantation for demangling BinDemangle */ static char *parse_comp_unit_lang(const RBinDwarfDie *die) { - r_return_val_if_fail (die, NULL); + rz_return_val_if_fail (die, NULL); int idx = find_attr_idx (die, DW_AT_language); char *lang = "cxx"; // default fallback @@ -1438,7 +1438,7 @@ static char *parse_comp_unit_lang(const RBinDwarfDie *die) { return lang; } const RBinDwarfAttrValue *val = &die->attr_values[idx]; - r_warn_if_fail (val->kind == DW_AT_KIND_CONSTANT); + rz_warn_if_fail (val->kind == DW_AT_KIND_CONSTANT); switch (val->uconstant) { @@ -1489,7 +1489,7 @@ static char *parse_comp_unit_lang(const RBinDwarfDie *die) { * @param idx index of the current entry */ static void parse_type_entry(Context *ctx, ut64 idx) { - r_return_if_fail (ctx); + rz_return_if_fail (ctx); const RBinDwarfDie *die = &ctx->all_dies[idx]; switch (die->tag) { @@ -1525,8 +1525,8 @@ static void parse_type_entry(Context *ctx, ut64 idx) { * @param anal * @param ctx */ -R_API void r_anal_dwarf_process_info(const RAnal *anal, RAnalDwarfContext *ctx) { - r_return_if_fail (ctx && anal); +RZ_API void rz_anal_dwarf_process_info(const RzAnal *anal, RzAnalDwarfContext *ctx) { + rz_return_if_fail (ctx && anal); Sdb *dwarf_sdb = sdb_ns (anal->sdb, "dwarf", 1); size_t i, j; const RBinDwarfDebugInfo *info = ctx->info; @@ -1560,8 +1560,8 @@ bool filter_sdb_function_names(void *user, const char *k, const char *v) { * @param anal * @param dwarf_sdb */ -R_API void r_anal_dwarf_integrate_functions(RAnal *anal, RFlag *flags, Sdb *dwarf_sdb) { - r_return_if_fail (anal && dwarf_sdb); +RZ_API void rz_anal_dwarf_integrate_functions(RzAnal *anal, RzFlag *flags, Sdb *dwarf_sdb) { + rz_return_if_fail (anal && dwarf_sdb); /* get all entries with value == func */ SdbList *sdb_list = sdb_foreach_list_filter (dwarf_sdb, filter_sdb_function_names, false); @@ -1571,36 +1571,36 @@ R_API void r_anal_dwarf_integrate_functions(RAnal *anal, RFlag *flags, Sdb *dwar ls_foreach (sdb_list, it, kv) { char *func_sname = kv->base.key; - char *addr_key = r_str_newf ("fcn.%s.addr", func_sname); + char *addr_key = rz_str_newf ("fcn.%s.addr", func_sname); ut64 faddr = sdb_num_get (dwarf_sdb, addr_key, 0); free (addr_key); /* if the function is analyzed so we can edit */ - RAnalFunction *fcn = r_anal_get_function_at (anal, faddr); + RzAnalFunction *fcn = rz_anal_get_function_at (anal, faddr); if (fcn) { /* prepend dwarf debug info stuff with dbg. */ - char *real_name_key = r_str_newf ("fcn.%s.name", func_sname); + char *real_name_key = rz_str_newf ("fcn.%s.name", func_sname); char *real_name = sdb_get (dwarf_sdb, real_name_key, 0); free (real_name_key); - char *dwf_name = r_str_newf ("dbg.%s", real_name); + char *dwf_name = rz_str_newf ("dbg.%s", real_name); free (real_name); - r_anal_function_rename (fcn, dwf_name); + rz_anal_function_rename (fcn, dwf_name); free (dwf_name); - char *tmp = r_str_newf ("fcn.%s.sig", func_sname); + char *tmp = rz_str_newf ("fcn.%s.sig", func_sname); char *fcnstr = sdb_get (dwarf_sdb, tmp, 0); free (tmp); /* Apply signature as a comment at a function address */ - r_meta_set_string (anal, R_META_TYPE_COMMENT, faddr, fcnstr); + rz_meta_set_string (anal, R_META_TYPE_COMMENT, faddr, fcnstr); free (fcnstr); } - char *var_names_key = r_str_newf ("fcn.%s.vars", func_sname); + char *var_names_key = rz_str_newf ("fcn.%s.vars", func_sname); char *vars = sdb_get (dwarf_sdb, var_names_key, NULL); char *var_name; sdb_aforeach (var_name, vars) { - char *var_key = r_str_newf ("fcn.%s.var.%s", func_sname, var_name); + char *var_key = rz_str_newf ("fcn.%s.var.%s", func_sname, var_name); char *var_data = sdb_get (dwarf_sdb, var_key, NULL); if (!var_data) { goto loop_end; @@ -1614,20 +1614,20 @@ R_API void r_anal_dwarf_integrate_functions(RAnal *anal, RFlag *flags, Sdb *dwar offset = strtol (extra, NULL, 10); } if (*kind == 'g') { /* global, fixed addr TODO add size to variables? */ - char *global_name = r_str_newf ("global_%s", var_name); - r_flag_unset_off (flags, offset); - r_flag_set_next (flags, global_name, offset, 4); + char *global_name = rz_str_newf ("global_%s", var_name); + rz_flag_unset_off (flags, offset); + rz_flag_set_next (flags, global_name, offset, 4); free (global_name); } else if (*kind == 's' && fcn) { - r_anal_function_set_var (fcn, offset - fcn->maxstack, *kind, type, 4, false, var_name); + rz_anal_function_set_var (fcn, offset - fcn->maxstack, *kind, type, 4, false, var_name); } else if (*kind == 'r' && fcn) { - RRegItem *i = r_reg_get (anal->reg, extra, -1); + RzRegItem *i = rz_reg_get (anal->reg, extra, -1); if (!i) { goto loop_end; } - r_anal_function_set_var (fcn, i->index, *kind, type, 4, false, var_name); + rz_anal_function_set_var (fcn, i->index, *kind, type, 4, false, var_name); } else if (fcn) { /* kind == 'b' */ - r_anal_function_set_var (fcn, offset - fcn->bp_off, *kind, type, 4, false, var_name); + rz_anal_function_set_var (fcn, offset - fcn->bp_off, *kind, type, 4, false, var_name); } free (var_key); free (var_data); diff --git a/libr/anal/esil.c b/librz/anal/esil.c similarity index 63% rename from libr/anal/esil.c rename to librz/anal/esil.c index 2ae930aee2..bbf9298ff6 100644 --- a/libr/anal/esil.c +++ b/librz/anal/esil.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2014-2020 - pancake, condret */ -#include -#include -#include -#include +#include +#include +#include +#include #define IFDBG if (esil && esil->verbose > 1) #define IFVBS if (esil && esil->verbose > 0) @@ -31,13 +31,13 @@ static inline ut64 genmask(int bits) { #define ERR(x) if (esil->verbose) { eprintf ("%s\n", x); } -static bool isnum(RAnalEsil *esil, const char *str, ut64 *num) { +static bool isnum(RzAnalEsil *esil, const char *str, ut64 *num) { if (!esil || !str) { return false; } if (IS_DIGIT (*str)) { if (num) { - *num = r_num_get (NULL, str); + *num = rz_num_get (NULL, str); } return true; } @@ -47,13 +47,13 @@ static bool isnum(RAnalEsil *esil, const char *str, ut64 *num) { return false; } -static bool ispackedreg(RAnalEsil *esil, const char *str) { - RRegItem *ri = r_reg_get (esil->anal->reg, str, -1); +static bool ispackedreg(RzAnalEsil *esil, const char *str) { + RzRegItem *ri = rz_reg_get (esil->anal->reg, str, -1); return ri? ri->packed_size > 0: false; } -static bool isregornum(RAnalEsil *esil, const char *str, ut64 *num) { - if (!r_anal_esil_reg_read (esil, str, num, NULL)) { +static bool isregornum(RzAnalEsil *esil, const char *str, ut64 *num) { + if (!rz_anal_esil_reg_read (esil, str, num, NULL)) { if (!isnum (esil, str, num)) { return false; } @@ -62,8 +62,8 @@ static bool isregornum(RAnalEsil *esil, const char *str, ut64 *num) { } /* pop Register or Number */ -static bool popRN(RAnalEsil *esil, ut64 *n) { - char *str = r_anal_esil_pop (esil); +static bool popRN(RzAnalEsil *esil, ut64 *n) { + char *str = rz_anal_esil_pop (esil); if (str) { bool ret = isregornum (esil, str, n); free (str); @@ -79,8 +79,8 @@ static void esil_ops_free(HtPPKv *kv) { free (kv->value); } -R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize) { - RAnalEsil *esil = R_NEW0 (RAnalEsil); +RZ_API RzAnalEsil *rz_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize) { + RzAnalEsil *esil = R_NEW0 (RzAnalEsil); if (!esil) { return NULL; } @@ -97,17 +97,17 @@ R_API RAnalEsil *r_anal_esil_new(int stacksize, int iotrap, unsigned int addrsiz esil->parse_goto_count = R_ANAL_ESIL_GOTO_LIMIT; esil->ops = ht_pp_new (NULL, esil_ops_free, NULL); esil->iotrap = iotrap; - r_anal_esil_sources_init (esil); - r_anal_esil_interrupts_init (esil); + rz_anal_esil_sources_init (esil); + rz_anal_esil_interrupts_init (esil); esil->addrmask = genmask (addrsize - 1); return esil; } -R_API bool r_anal_esil_set_op(RAnalEsil *esil, const char *op, RAnalEsilOpCb code, ut32 push, ut32 pop, ut32 type) { - r_return_val_if_fail (code && R_STR_ISNOTEMPTY (op) && esil && esil->ops, false); - RAnalEsilOp *eop = ht_pp_find (esil->ops, op, NULL); +RZ_API bool rz_anal_esil_set_op(RzAnalEsil *esil, const char *op, RzAnalEsilOpCb code, ut32 push, ut32 pop, ut32 type) { + rz_return_val_if_fail (code && R_STR_ISNOTEMPTY (op) && esil && esil->ops, false); + RzAnalEsilOp *eop = ht_pp_find (esil->ops, op, NULL); if (!eop) { - eop = R_NEW (RAnalEsilOp); + eop = R_NEW (RzAnalEsilOp); if (!eop) { eprintf ("Cannot allocate esil-operation %s\n", op); return false; @@ -125,15 +125,15 @@ R_API bool r_anal_esil_set_op(RAnalEsil *esil, const char *op, RAnalEsilOpCb cod return true; } -static bool r_anal_esil_fire_trap(RAnalEsil *esil, int trap_type, int trap_code) { - r_return_val_if_fail (esil, false); +static bool rz_anal_esil_fire_trap(RzAnalEsil *esil, int trap_type, int trap_code) { + rz_return_val_if_fail (esil, false); if (esil->cmd) { if (esil->cmd (esil, esil->cmd_trap, trap_type, trap_code)) { return true; } } if (esil->anal) { - RAnalPlugin *ap = esil->anal->cur; + RzAnalPlugin *ap = esil->anal->cur; if (ap && ap->esil_trap) { if (ap->esil_trap (esil, trap_type, trap_code)) { return true; @@ -141,14 +141,14 @@ static bool r_anal_esil_fire_trap(RAnalEsil *esil, int trap_type, int trap_code) } } #if 0 - RAnalEsilTrapCB icb; - icb = (RAnalEsilTrapCB)sdb_ptr_get (esil->traps, i, 0); + RzAnalEsilTrapCB icb; + icb = (RzAnalEsilTrapCB)sdb_ptr_get (esil->traps, i, 0); return icb (esil, trap_type, trap_code); #endif return false; } -R_API bool r_anal_esil_set_pc(RAnalEsil *esil, ut64 addr) { +RZ_API bool rz_anal_esil_set_pc(RzAnalEsil *esil, ut64 addr) { if (esil) { esil->address = addr; return true; @@ -156,7 +156,7 @@ R_API bool r_anal_esil_set_pc(RAnalEsil *esil, ut64 addr) { return false; } -R_API void r_anal_esil_free(RAnalEsil *esil) { +RZ_API void rz_anal_esil_free(RzAnalEsil *esil) { if (!esil) { return; } @@ -165,16 +165,16 @@ R_API void r_anal_esil_free(RAnalEsil *esil) { } ht_pp_free (esil->ops); esil->ops = NULL; - r_anal_esil_interrupts_fini (esil); - r_anal_esil_sources_fini (esil); + rz_anal_esil_interrupts_fini (esil); + rz_anal_esil_sources_fini (esil); sdb_free (esil->stats); esil->stats = NULL; - r_anal_esil_stack_free (esil); + rz_anal_esil_stack_free (esil); free (esil->stack); if (esil->anal && esil->anal->cur && esil->anal->cur->esil_fini) { esil->anal->cur->esil_fini (esil); } - r_anal_esil_trace_free (esil->trace); + rz_anal_esil_trace_free (esil->trace); esil->trace = NULL; free (esil->cmd_intr); free (esil->cmd_trap); @@ -186,19 +186,19 @@ R_API void r_anal_esil_free(RAnalEsil *esil) { free (esil); } -static ut8 esil_internal_sizeof_reg(RAnalEsil *esil, const char *r) { - r_return_val_if_fail (esil && esil->anal && esil->anal->reg && r, 0); - RRegItem *ri = r_reg_get (esil->anal->reg, r, -1); +static ut8 esil_internal_sizeof_reg(RzAnalEsil *esil, const char *r) { + rz_return_val_if_fail (esil && esil->anal && esil->anal->reg && r, 0); + RzRegItem *ri = rz_reg_get (esil->anal->reg, r, -1); return ri? ri->size: 0; } -static bool alignCheck(RAnalEsil *esil, ut64 addr) { - int dataAlign = r_anal_archinfo (esil->anal, R_ANAL_ARCHINFO_DATA_ALIGN); +static bool alignCheck(RzAnalEsil *esil, ut64 addr) { + int dataAlign = rz_anal_archinfo (esil->anal, R_ANAL_ARCHINFO_DATA_ALIGN); return !(dataAlign > 0 && addr % dataAlign); } -static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { - r_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0); +static int internal_esil_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { + rz_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0); addr &= esil->addrmask; if (!alignCheck (esil, addr)) { @@ -207,7 +207,7 @@ static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) return false; } if (esil->cmd_mdev && esil->mdev_range) { - if (r_str_range_in (esil->mdev_range, addr)) { + if (rz_str_range_in (esil->mdev_range, addr)) { if (esil->cmd (esil, esil->cmd_mdev, addr, 0)) { return true; } @@ -229,8 +229,8 @@ static int internal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) return len; } -static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { - r_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0); +static int internal_esil_mem_read_no_null(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { + rz_return_val_if_fail (esil && esil->anal && esil->anal->iob.io, 0); addr &= esil->addrmask; if (!alignCheck (esil, addr)) { @@ -251,9 +251,9 @@ static int internal_esil_mem_read_no_null(RAnalEsil *esil, ut64 addr, ut8 *buf, return len; } -R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +RZ_API int rz_anal_esil_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { int i, ret = 0; - r_return_val_if_fail (buf && esil, 0); + rz_return_val_if_fail (buf && esil, 0); addr &= esil->addrmask; if (esil->cb.hook_mem_read) { ret = esil->cb.hook_mem_read (esil, addr, buf, len); @@ -282,7 +282,7 @@ R_API int r_anal_esil_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { return ret; } -static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int internal_esil_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { int ret = 0; if (!esil || !esil->anal || !esil->anal->iob.io || esil->nowrite) { return 0; @@ -294,7 +294,7 @@ static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, i return false; } if (esil->cmd_mdev && esil->mdev_range) { - if (r_str_range_in (esil->mdev_range, addr)) { + if (rz_str_range_in (esil->mdev_range, addr)) { if (esil->cmd (esil, esil->cmd_mdev, addr, 1)) { return true; } @@ -317,7 +317,7 @@ static int internal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, i return ret; } -static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int internal_esil_mem_write_no_null(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { int ret = 0; if (!esil || !esil->anal || !esil->anal->iob.io || !addr) { return 0; @@ -340,7 +340,7 @@ static int internal_esil_mem_write_no_null(RAnalEsil *esil, ut64 addr, const ut8 return ret; } -R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +RZ_API int rz_anal_esil_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { int i, ret = 0; if (!buf || !esil) { return 0; @@ -362,25 +362,25 @@ R_API int r_anal_esil_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int return ret; } -static int internal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) { - RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1); +static int internal_esil_reg_read(RzAnalEsil *esil, const char *regname, ut64 *num, int *size) { + RzRegItem *reg = rz_reg_get (esil->anal->reg, regname, -1); if (reg) { if (size) { *size = reg->size; } if (num) { - *num = r_reg_get_value (esil->anal->reg, reg); + *num = rz_reg_get_value (esil->anal->reg, reg); } return true; } return false; } -static int internal_esil_reg_write(RAnalEsil *esil, const char *regname, ut64 num) { +static int internal_esil_reg_write(RzAnalEsil *esil, const char *regname, ut64 num) { if (esil && esil->anal) { - RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1); + RzRegItem *reg = rz_reg_get (esil->anal->reg, regname, -1); if (reg) { - r_reg_set_value (esil->anal->reg, reg, num); + rz_reg_set_value (esil->anal->reg, reg, num); return true; } } @@ -391,40 +391,40 @@ static int internal_esil_reg_write(RAnalEsil *esil, const char *regname, ut64 nu //Are you really trying to prevent the analyzed binary from doing anything that would cause it to segfault irl? //WHY? // - condret -static int internal_esil_reg_write_no_null (RAnalEsil *esil, const char *regname, ut64 num) { - r_return_val_if_fail (esil && esil->anal && esil->anal->reg, false); +static int internal_esil_reg_write_no_null (RzAnalEsil *esil, const char *regname, ut64 num) { + rz_return_val_if_fail (esil && esil->anal && esil->anal->reg, false); - RRegItem *reg = r_reg_get (esil->anal->reg, regname, -1); - const char *pc = r_reg_get_name (esil->anal->reg, R_REG_NAME_PC); - const char *sp = r_reg_get_name (esil->anal->reg, R_REG_NAME_SP); - const char *bp = r_reg_get_name (esil->anal->reg, R_REG_NAME_BP); + RzRegItem *reg = rz_reg_get (esil->anal->reg, regname, -1); + const char *pc = rz_reg_get_name (esil->anal->reg, R_REG_NAME_PC); + const char *sp = rz_reg_get_name (esil->anal->reg, R_REG_NAME_SP); + const char *bp = rz_reg_get_name (esil->anal->reg, R_REG_NAME_BP); if (!pc) { - eprintf ("Warning: RReg profile does not contain PC register\n"); + eprintf ("Warning: RzReg profile does not contain PC register\n"); return false; } if (!sp) { - eprintf ("Warning: RReg profile does not contain SP register\n"); + eprintf ("Warning: RzReg profile does not contain SP register\n"); return false; } if (!bp) { - eprintf ("Warning: RReg profile does not contain BP register\n"); + eprintf ("Warning: RzReg profile does not contain BP register\n"); return false; } if (reg && reg->name && ((strcmp (reg->name , pc) && strcmp (reg->name, sp) && strcmp(reg->name, bp)) || num)) { //I trust k-maps - r_reg_set_value (esil->anal->reg, reg, num); + rz_reg_set_value (esil->anal->reg, reg, num); return true; } return false; } -R_API bool r_anal_esil_pushnum(RAnalEsil *esil, ut64 num) { +RZ_API bool rz_anal_esil_pushnum(RzAnalEsil *esil, ut64 num) { char str[64]; snprintf (str, sizeof (str) - 1, "0x%" PFMT64x, num); - return r_anal_esil_push (esil, str); + return rz_anal_esil_push (esil, str); } -R_API bool r_anal_esil_push(RAnalEsil *esil, const char *str) { +RZ_API bool rz_anal_esil_push(RzAnalEsil *esil, const char *str) { if (!str || !esil || !*str || esil->stackptr > (esil->stacksize - 1)) { return false; } @@ -432,15 +432,15 @@ R_API bool r_anal_esil_push(RAnalEsil *esil, const char *str) { return true; } -R_API char *r_anal_esil_pop(RAnalEsil *esil) { - r_return_val_if_fail (esil, NULL); +RZ_API char *rz_anal_esil_pop(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, NULL); if (esil->stackptr < 1) { return NULL; } return esil->stack[--esil->stackptr]; } -R_API int r_anal_esil_get_parm_type(RAnalEsil *esil, const char *str) { +RZ_API int rz_anal_esil_get_parm_type(RzAnalEsil *esil, const char *str) { int len, i; if (!str || !(len = strlen (str))) { @@ -459,29 +459,29 @@ R_API int r_anal_esil_get_parm_type(RAnalEsil *esil, const char *str) { } return R_ANAL_ESIL_PARM_NUM; not_a_number: - if (r_reg_get (esil->anal->reg, str, -1)) { + if (rz_reg_get (esil->anal->reg, str, -1)) { return R_ANAL_ESIL_PARM_REG; } return R_ANAL_ESIL_PARM_INVALID; } -R_API int r_anal_esil_get_parm_size(RAnalEsil *esil, const char *str, ut64 *num, int *size) { +RZ_API int rz_anal_esil_get_parm_size(RzAnalEsil *esil, const char *str, ut64 *num, int *size) { if (!str || !*str) { return false; } - int parm_type = r_anal_esil_get_parm_type (esil, str); + int parm_type = rz_anal_esil_get_parm_type (esil, str); if (!num || !esil) { return false; } switch (parm_type) { case R_ANAL_ESIL_PARM_NUM: - *num = r_num_get (NULL, str); + *num = rz_num_get (NULL, str); if (size) { *size = esil->anal->bits; } return true; case R_ANAL_ESIL_PARM_REG: - if (!r_anal_esil_reg_read (esil, str, num, size)) { + if (!rz_anal_esil_reg_read (esil, str, num, size)) { break; } return true; @@ -495,11 +495,11 @@ R_API int r_anal_esil_get_parm_size(RAnalEsil *esil, const char *str, ut64 *num, return false; } -R_API int r_anal_esil_get_parm(RAnalEsil *esil, const char *str, ut64 *num) { - return r_anal_esil_get_parm_size (esil, str, num, NULL); +RZ_API int rz_anal_esil_get_parm(RzAnalEsil *esil, const char *str, ut64 *num) { + return rz_anal_esil_get_parm_size (esil, str, num, NULL); } -R_API int r_anal_esil_reg_write(RAnalEsil *esil, const char *dst, ut64 num) { +RZ_API int rz_anal_esil_reg_write(RzAnalEsil *esil, const char *dst, ut64 num) { int ret = 0; IFDBG { eprintf ("%s=0x%" PFMT64x "\n", dst, num); } if (esil && esil->cb.hook_reg_write) { @@ -511,16 +511,16 @@ R_API int r_anal_esil_reg_write(RAnalEsil *esil, const char *dst, ut64 num) { return ret; } -R_API int r_anal_esil_reg_read_nocallback(RAnalEsil *esil, const char *regname, ut64 *num, int *size) { +RZ_API int rz_anal_esil_reg_read_nocallback(RzAnalEsil *esil, const char *regname, ut64 *num, int *size) { int ret; void *old_hook_reg_read = (void *) esil->cb.hook_reg_read; esil->cb.hook_reg_read = NULL; - ret = r_anal_esil_reg_read (esil, regname, num, size); + ret = rz_anal_esil_reg_read (esil, regname, num, size); esil->cb.hook_reg_read = old_hook_reg_read; return ret; } -R_API int r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) { +RZ_API int rz_anal_esil_reg_read(RzAnalEsil *esil, const char *regname, ut64 *num, int *size) { bool ret = false; ut64 localnum; // XXX why is this necessary? if (!esil || !regname) { @@ -546,15 +546,15 @@ R_API int r_anal_esil_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, // and other instructions involving signed values, extends n bit value to 64 bit value // example : >"ae 8,0x81,~" ( ,,~ ) // output : 0xffffffffffffff81 -static bool esil_signext(RAnalEsil *esil) { +static bool esil_signext(RzAnalEsil *esil) { ut64 src, dst; - char *p_src = r_anal_esil_pop (esil); + char *p_src = rz_anal_esil_pop (esil); if (!p_src) { return false; } - if (!r_anal_esil_get_parm (esil, p_src, &src)) { + if (!rz_anal_esil_get_parm (esil, p_src, &src)) { ERR ("esil_of: empty stack"); free (p_src); return false; @@ -562,12 +562,12 @@ static bool esil_signext(RAnalEsil *esil) { free (p_src); } - char *p_dst = r_anal_esil_pop (esil); + char *p_dst = rz_anal_esil_pop (esil); if (!p_dst) { return false; } - if (!r_anal_esil_get_parm (esil, p_dst, &dst)) { + if (!rz_anal_esil_get_parm (esil, p_dst, &dst)) { ERR ("esil_of: empty stack"); free (p_dst); return false; @@ -584,22 +584,22 @@ static bool esil_signext(RAnalEsil *esil) { } // dst = (dst & ((1U << src_bit) - 1)); // clear upper bits - return r_anal_esil_pushnum (esil, ((src ^ m) - m)); + return rz_anal_esil_pushnum (esil, ((src ^ m) - m)); } -static bool esil_zf(RAnalEsil *esil) { - return r_anal_esil_pushnum (esil, !(esil->cur & genmask (esil->lastsz - 1))); +static bool esil_zf(RzAnalEsil *esil) { + return rz_anal_esil_pushnum (esil, !(esil->cur & genmask (esil->lastsz - 1))); } // checks if there was a carry from bit x (x,$c) -static bool esil_cf(RAnalEsil *esil) { - char *src = r_anal_esil_pop (esil); +static bool esil_cf(RzAnalEsil *esil) { + char *src = rz_anal_esil_pop (esil); if (!src) { return false; } - if (r_anal_esil_get_parm_type (esil, src) != R_ANAL_ESIL_PARM_NUM) { + if (rz_anal_esil_get_parm_type (esil, src) != R_ANAL_ESIL_PARM_NUM) { //I'd wish we could enforce consts here //I can't say why, but I feel like "al,$c" would be cancer af // - condret @@ -607,30 +607,30 @@ static bool esil_cf(RAnalEsil *esil) { return false; } ut64 bit; - r_anal_esil_get_parm (esil, src, &bit); + rz_anal_esil_get_parm (esil, src, &bit); free (src); //carry from bit //range of src goes from 0 to 63 // //implements bit mod 64 const ut64 mask = genmask (bit & 0x3f); - return r_anal_esil_pushnum (esil, (esil->cur & mask) < (esil->old & mask)); + return rz_anal_esil_pushnum (esil, (esil->cur & mask) < (esil->old & mask)); } // checks if there was a borrow from bit x (x,$b) -static bool esil_bf(RAnalEsil *esil) { - char *src = r_anal_esil_pop (esil); +static bool esil_bf(RzAnalEsil *esil) { + char *src = rz_anal_esil_pop (esil); if (!src) { return false; } - if (r_anal_esil_get_parm_type (esil, src) != R_ANAL_ESIL_PARM_NUM) { + if (rz_anal_esil_get_parm_type (esil, src) != R_ANAL_ESIL_PARM_NUM) { free (src); return false; } ut64 bit; - r_anal_esil_get_parm (esil, src, &bit); + rz_anal_esil_get_parm (esil, src, &bit); free (src); //borrow from bit //range of src goes from 1 to 64 @@ -638,10 +638,10 @@ static bool esil_bf(RAnalEsil *esil) { // //implements (bit - 1) mod 64 const ut64 mask = genmask ((bit + 0x3f) & 0x3f); - return r_anal_esil_pushnum (esil, (esil->old & mask) < (esil->cur & mask)); + return rz_anal_esil_pushnum (esil, (esil->old & mask) < (esil->cur & mask)); } -static bool esil_pf(RAnalEsil *esil) { +static bool esil_pf(RzAnalEsil *esil) { // Set if the number of set bits in the least significant _byte_ is a multiple of 2. // - Taken from: https://graphics.stanford.edu/~seander/bithacks.html#ParityWith64Bits const ut64 c1 = 0x0101010101010101ULL; @@ -649,26 +649,26 @@ static bool esil_pf(RAnalEsil *esil) { const ut64 c3 = 0x1FF; // Take only the least significant byte. ut64 lsb = esil->cur & 0xff; - return r_anal_esil_pushnum (esil, !((((lsb * c1) & c2) % c3) & 1)); + return rz_anal_esil_pushnum (esil, !((((lsb * c1) & c2) % c3) & 1)); } // like carry // checks overflow from bit x (x,$o) // x,$o ===> x,$c,x-1,$c,^ -static bool esil_of(RAnalEsil *esil) { - char *p_bit = r_anal_esil_pop (esil); +static bool esil_of(RzAnalEsil *esil) { + char *p_bit = rz_anal_esil_pop (esil); if (!p_bit) { return false; } - if (r_anal_esil_get_parm_type (esil, p_bit) != R_ANAL_ESIL_PARM_NUM) { + if (rz_anal_esil_get_parm_type (esil, p_bit) != R_ANAL_ESIL_PARM_NUM) { free (p_bit); return false; } ut64 bit; - if (!r_anal_esil_get_parm (esil, p_bit, &bit)) { + if (!rz_anal_esil_get_parm (esil, p_bit, &bit)) { ERR ("esil_of: empty stack"); free (p_bit); return false; @@ -677,23 +677,23 @@ static bool esil_of(RAnalEsil *esil) { const ut64 m[2] = {genmask (bit & 0x3f), genmask ((bit + 0x3f) & 0x3f)}; const ut64 result = ((esil->cur & m[0]) < (esil->old & m[0])) ^ ((esil->cur & m[1]) < (esil->old & m[1])); - ut64 res = r_anal_esil_pushnum (esil, result); + ut64 res = rz_anal_esil_pushnum (esil, result); return res; } //checks sign bit at x (x,$s) -static bool esil_sf(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); +static bool esil_sf(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); - char *p_size = r_anal_esil_pop (esil); - r_return_val_if_fail (p_size, false); + char *p_size = rz_anal_esil_pop (esil); + rz_return_val_if_fail (p_size, false); - if (r_anal_esil_get_parm_type (esil, p_size) != R_ANAL_ESIL_PARM_NUM) { + if (rz_anal_esil_get_parm_type (esil, p_size) != R_ANAL_ESIL_PARM_NUM) { free (p_size); return false; } ut64 size, num; - r_anal_esil_get_parm (esil, p_size, &size); + rz_anal_esil_get_parm (esil, p_size, &size); free (p_size); if (size > 63) { @@ -701,23 +701,23 @@ static bool esil_sf(RAnalEsil *esil) { } else { num = (esil->cur >> size) & 1; } - ut64 res = r_anal_esil_pushnum (esil, num); + ut64 res = rz_anal_esil_pushnum (esil, num); return res; } -static bool esil_ds(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); - return r_anal_esil_pushnum (esil, esil->delay); +static bool esil_ds(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); + return rz_anal_esil_pushnum (esil, esil->delay); } -static bool esil_jt(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); - return r_anal_esil_pushnum (esil, esil->jump_target); +static bool esil_jt(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); + return rz_anal_esil_pushnum (esil, esil->jump_target); } -static bool esil_js(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); - return r_anal_esil_pushnum (esil, esil->jump_target_set); +static bool esil_js(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); + return rz_anal_esil_pushnum (esil, esil->jump_target_set); } //regsize @@ -725,34 +725,34 @@ static bool esil_js(RAnalEsil *esil) { //plugins should know regsize, and since this is a const even users should know this: ?´e anal.bits´/8 // - condret // YES PLS KILL IT -static bool esil_rs(RAnalEsil *esil) { - r_return_val_if_fail (esil && esil->anal, false); - return r_anal_esil_pushnum (esil, esil->anal->bits >> 3); +static bool esil_rs(RzAnalEsil *esil) { + rz_return_val_if_fail (esil && esil->anal, false); + return rz_anal_esil_pushnum (esil, esil->anal->bits >> 3); } //can we please deprecate this, plugins should know their current address //even if they don't know it, $$ should be equal to PC register at the begin of each expression // - condret // YES PLS KILL IT -static bool esil_address(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); - return r_anal_esil_pushnum (esil, esil->address); +static bool esil_address(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); + return rz_anal_esil_pushnum (esil, esil->address); } -static bool esil_weak_eq(RAnalEsil *esil) { - r_return_val_if_fail (esil && esil->anal, false); - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); +static bool esil_weak_eq(RzAnalEsil *esil) { + rz_return_val_if_fail (esil && esil->anal, false); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); - if (!(dst && src && (r_anal_esil_get_parm_type(esil, dst) == R_ANAL_ESIL_PARM_REG))) { + if (!(dst && src && (rz_anal_esil_get_parm_type(esil, dst) == R_ANAL_ESIL_PARM_REG))) { free (dst); free (src); return false; } ut64 src_num; - if (r_anal_esil_get_parm (esil, src, &src_num)) { - (void)r_anal_esil_reg_write (esil, dst, src_num); + if (rz_anal_esil_get_parm (esil, src, &src_num)) { + (void)rz_anal_esil_reg_write (esil, dst, src_num); free (src); free (dst); return true; @@ -763,11 +763,11 @@ static bool esil_weak_eq(RAnalEsil *esil) { return false; } -static bool esil_eq(RAnalEsil *esil) { +static bool esil_eq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); if (!src || !dst) { if (esil->verbose) { eprintf ("Missing elements in the esil stack for '=' at 0x%08"PFMT64x"\n", esil->address); @@ -775,19 +775,19 @@ static bool esil_eq(RAnalEsil *esil) { return false; } if (ispackedreg (esil, dst)) { - char *src2 = r_anal_esil_pop (esil); - char *newreg = r_str_newf ("%sl", dst); - if (r_anal_esil_get_parm (esil, src2, &num2)) { - ret = r_anal_esil_reg_write (esil, newreg, num2); + char *src2 = rz_anal_esil_pop (esil); + char *newreg = rz_str_newf ("%sl", dst); + if (rz_anal_esil_get_parm (esil, src2, &num2)) { + ret = rz_anal_esil_reg_write (esil, newreg, num2); } free (newreg); free (src2); goto beach; } - if (src && dst && r_anal_esil_reg_read_nocallback (esil, dst, &num, NULL)) { - if (r_anal_esil_get_parm (esil, src, &num2)) { - ret = r_anal_esil_reg_write (esil, dst, num2); + if (src && dst && rz_anal_esil_reg_read_nocallback (esil, dst, &num, NULL)) { + if (rz_anal_esil_get_parm (esil, src, &num2)) { + ret = rz_anal_esil_reg_write (esil, dst, num2); esil->cur = num2; esil->old = num; esil->lastsz = esil_internal_sizeof_reg (esil, dst); @@ -804,18 +804,18 @@ beach: return ret; } -static bool esil_neg(RAnalEsil *esil) { +static bool esil_neg(RzAnalEsil *esil) { bool ret = false; - char *src = r_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); if (src) { ut64 num; - if (r_anal_esil_get_parm (esil, src, &num)) { - r_anal_esil_pushnum (esil, !num); + if (rz_anal_esil_get_parm (esil, src, &num)) { + rz_anal_esil_pushnum (esil, !num); ret = true; } else { if (isregornum (esil, src, &num)) { ret = true; - r_anal_esil_pushnum (esil, !num); + rz_anal_esil_pushnum (esil, !num); } else { eprintf ("0x%08"PFMT64x" esil_neg: unknown reg %s\n", esil->address, src); } @@ -827,37 +827,37 @@ static bool esil_neg(RAnalEsil *esil) { return ret; } -static bool esil_negeq(RAnalEsil *esil) { +static bool esil_negeq(RzAnalEsil *esil) { bool ret = false; ut64 num; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_reg_read (esil, src, &num, NULL)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_reg_read (esil, src, &num, NULL)) { num = !num; - r_anal_esil_reg_write (esil, src, num); + rz_anal_esil_reg_write (esil, src, num); ret = true; } else { ERR ("esil_negeq: empty stack"); } free (src); - //r_anal_esil_pushnum (esil, ret); + //rz_anal_esil_pushnum (esil, ret); return ret; } -static bool esil_nop(RAnalEsil *esil) { +static bool esil_nop(RzAnalEsil *esil) { return true; } -static bool esil_andeq(RAnalEsil *esil) { +static bool esil_andeq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_reg_read (esil, dst, &num, NULL)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_reg_read (esil, dst, &num, NULL)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num & num2; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - r_anal_esil_reg_write (esil, dst, num & num2); + rz_anal_esil_reg_write (esil, dst, num & num2); ret = true; } else { ERR ("esil_andeq: empty stack"); @@ -868,17 +868,17 @@ static bool esil_andeq(RAnalEsil *esil) { return ret; } -static bool esil_oreq(RAnalEsil *esil) { +static bool esil_oreq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_reg_read (esil, dst, &num, NULL)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_reg_read (esil, dst, &num, NULL)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num | num2; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - ret = r_anal_esil_reg_write (esil, dst, num | num2); + ret = rz_anal_esil_reg_write (esil, dst, num | num2); } else { ERR ("esil_ordeq: empty stack"); } @@ -888,17 +888,17 @@ static bool esil_oreq(RAnalEsil *esil) { return ret; } -static bool esil_xoreq(RAnalEsil *esil) { +static bool esil_xoreq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_reg_read (esil, dst, &num, NULL)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_reg_read (esil, dst, &num, NULL)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num ^ num2; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - ret = r_anal_esil_reg_write (esil, dst, num ^ num2); + ret = rz_anal_esil_reg_write (esil, dst, num ^ num2); } else { ERR ("esil_xoreq: empty stack"); } @@ -909,11 +909,11 @@ static bool esil_xoreq(RAnalEsil *esil) { } #if 0 -static int esil_interrupt_linux_i386(RAnalEsil *esil) { //move this into a plugin +static int esil_interrupt_linux_i386(RzAnalEsil *esil) { //move this into a plugin ut32 sn, ret = 0; - char *usn = r_anal_esil_pop (esil); + char *usn = rz_anal_esil_pop (esil); if (usn) { - sn = (ut32) r_num_get (NULL, usn); + sn = (ut32) rz_num_get (NULL, usn); } else sn = 0x80; if (sn == 3) { @@ -930,9 +930,9 @@ static int esil_interrupt_linux_i386(RAnalEsil *esil) { //move this into a plu return -1; } #undef r -#define r(x) r_reg_getv (esil->anal->reg, "##x##") +#define r(x) rz_reg_getv (esil->anal->reg, "##x##") #undef rs -#define rs(x, y) r_reg_setv (esil->anal->reg, "##x##", y) +#define rs(x, y) rz_reg_setv (esil->anal->reg, "##x##", y) switch (r(eax)) { case 1: printf ("exit(%d)\n", (int)r(ebx)); @@ -964,18 +964,18 @@ static int esil_interrupt_linux_i386(RAnalEsil *esil) { //move this into a plu } #endif -static bool esil_trap(RAnalEsil *esil) { +static bool esil_trap(RzAnalEsil *esil) { ut64 s, d; if (popRN (esil, &s) && popRN (esil, &d)) { esil->trap = s; esil->trap_code = d; - return r_anal_esil_fire_trap (esil, (int)s, (int)d); + return rz_anal_esil_fire_trap (esil, (int)s, (int)d); } ERR ("esil_trap: missing parameters in stack"); return false; } -static bool esil_bits(RAnalEsil *esil) { +static bool esil_bits(RzAnalEsil *esil) { ut64 s; if (popRN (esil, &s)) { if (esil->anal && esil->anal->coreb.setab) { @@ -987,28 +987,28 @@ static bool esil_bits(RAnalEsil *esil) { return false; } -static bool esil_interrupt(RAnalEsil *esil) { +static bool esil_interrupt(RzAnalEsil *esil) { ut64 interrupt; if (popRN (esil, &interrupt)) { - return r_anal_esil_fire_interrupt (esil, (ut32)interrupt); + return rz_anal_esil_fire_interrupt (esil, (ut32)interrupt); } return false; } // This function also sets internal vars which is used in flag calculations. -static bool esil_cmp(RAnalEsil *esil) { +static bool esil_cmp(RzAnalEsil *esil) { ut64 num, num2; bool ret = false; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num - num2; ret = true; - if (r_reg_get (esil->anal->reg, dst, -1)) { + if (rz_reg_get (esil->anal->reg, dst, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, dst); - } else if (r_reg_get (esil->anal->reg, src, -1)) { + } else if (rz_reg_get (esil->anal->reg, src, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, src); } else { // default size is set to 64 as internally operands are ut64 @@ -1045,33 +1045,33 @@ JBE: CF = 1 || ZF = 1 /* * Expects a string in the stack. Each char of the string represents a CPU flag. * Those relations are associated by the CPU itself and are used to move values - * from the internal ESIL into the RReg instance. + * from the internal ESIL into the RzReg instance. * * For example: * zco,?= # update zf, cf and of * * If we want to update the esil value of a specific flag we use the =? command * - * zf,z,=? # esil[zf] = r_reg[zf] + * zf,z,=? # esil[zf] = rz_reg[zf] * * Defining new cpu flags */ #if 0 -static int esil_ifset(RAnalEsil *esil) { - char *s, *src = r_anal_esil_pop (esil); +static int esil_ifset(RzAnalEsil *esil) { + char *s, *src = rz_anal_esil_pop (esil); for (s=src; *s; s++) { switch (*s) { case 'z': - r_anal_esil_reg_write (esil, "zf", R_BIT_CHK(&esil->flags, FLG(ZERO))); + rz_anal_esil_reg_write (esil, "zf", R_BIT_CHK(&esil->flags, FLG(ZERO))); break; case 'c': - r_anal_esil_reg_write (esil, "cf", R_BIT_CHK(&esil->flags, FLG(CARRY))); + rz_anal_esil_reg_write (esil, "cf", R_BIT_CHK(&esil->flags, FLG(CARRY))); break; case 'o': - r_anal_esil_reg_write (esil, "of", R_BIT_CHK(&esil->flags, FLG(OVERFLOW))); + rz_anal_esil_reg_write (esil, "of", R_BIT_CHK(&esil->flags, FLG(OVERFLOW))); break; case 'p': - r_anal_esil_reg_write (esil, "pf", R_BIT_CHK(&esil->flags, FLG(PARITY))); + rz_anal_esil_reg_write (esil, "pf", R_BIT_CHK(&esil->flags, FLG(PARITY))); break; } } @@ -1080,14 +1080,14 @@ static int esil_ifset(RAnalEsil *esil) { } #endif -static bool esil_if(RAnalEsil *esil) { +static bool esil_if(RzAnalEsil *esil) { ut64 num = 0LL; if (esil->skip) { esil->skip++; return true; } - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &num)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &num)) { // condition not matching, skipping until if (!num) { esil->skip++; @@ -1098,20 +1098,20 @@ static bool esil_if(RAnalEsil *esil) { return false; } -static bool esil_lsl(RAnalEsil *esil) { +static bool esil_lsl(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { if (num2 > sizeof (ut64) * 8) { ERR ("esil_lsl: shift is too big"); } else { if (num2 > 63) { - r_anal_esil_pushnum (esil, 0); + rz_anal_esil_pushnum (esil, 0); } else { - r_anal_esil_pushnum (esil, num << num2); + rz_anal_esil_pushnum (esil, num << num2); } ret = true; } @@ -1124,13 +1124,13 @@ static bool esil_lsl(RAnalEsil *esil) { return ret; } -static bool esil_lsleq(RAnalEsil *esil) { +static bool esil_lsleq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_reg_read (esil, dst, &num, NULL)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_reg_read (esil, dst, &num, NULL)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { if (num2 > sizeof (ut64) * 8) { ERR ("esil_lsleq: shift is too big"); } else { @@ -1142,7 +1142,7 @@ static bool esil_lsleq(RAnalEsil *esil) { } esil->cur = num; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - r_anal_esil_reg_write (esil, dst, num); + rz_anal_esil_reg_write (esil, dst, num); ret = true; } } else { @@ -1154,15 +1154,15 @@ static bool esil_lsleq(RAnalEsil *esil) { return ret; } -static bool esil_lsr(RAnalEsil *esil) { +static bool esil_lsr(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { ut64 res = num >> R_MIN (num2, 63); - r_anal_esil_pushnum (esil, res); + rz_anal_esil_pushnum (esil, res); ret = true; } else { ERR ("esil_lsr: empty stack"); @@ -1173,13 +1173,13 @@ static bool esil_lsr(RAnalEsil *esil) { return ret; } -static bool esil_lsreq(RAnalEsil *esil) { +static bool esil_lsreq(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_reg_read (esil, dst, &num, NULL)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_reg_read (esil, dst, &num, NULL)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { if (num2 > 63) { if (esil->verbose) { eprintf ("Invalid shift at 0x%08"PFMT64x"\n", esil->address); @@ -1190,7 +1190,7 @@ static bool esil_lsreq(RAnalEsil *esil) { num >>= num2; esil->cur = num; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - r_anal_esil_reg_write (esil, dst, num); + rz_anal_esil_reg_write (esil, dst, num); ret = true; } else { ERR ("esil_lsreq: empty stack"); @@ -1201,14 +1201,14 @@ static bool esil_lsreq(RAnalEsil *esil) { return ret; } -static bool esil_asreq(RAnalEsil *esil) { +static bool esil_asreq(RzAnalEsil *esil) { bool ret = false; int regsize = 0; ut64 op_num, param_num; - char *op = r_anal_esil_pop (esil); - char *param = r_anal_esil_pop (esil); - if (op && r_anal_esil_get_parm_size (esil, op, &op_num, ®size)) { - if (param && r_anal_esil_get_parm (esil, param, ¶m_num)) { + char *op = rz_anal_esil_pop (esil); + char *param = rz_anal_esil_pop (esil); + if (op && rz_anal_esil_get_parm_size (esil, op, &op_num, ®size)) { + if (param && rz_anal_esil_get_parm (esil, param, ¶m_num)) { ut64 mask = (regsize - 1); param_num &= mask; bool isNegative; @@ -1263,8 +1263,8 @@ static bool esil_asreq(RAnalEsil *esil) { ut64 res = op_num; esil->cur = res; esil->lastsz = esil_internal_sizeof_reg (esil, op); - r_anal_esil_reg_write (esil, op, res); - // r_anal_esil_pushnum (esil, res); + rz_anal_esil_reg_write (esil, op, res); + // rz_anal_esil_pushnum (esil, res); ret = true; } else { if (esil->verbose) { @@ -1277,14 +1277,14 @@ static bool esil_asreq(RAnalEsil *esil) { return ret; } -static bool esil_asr(RAnalEsil *esil) { +static bool esil_asr(RzAnalEsil *esil) { bool ret = false; int regsize = 0; ut64 op_num = 0, param_num = 0; - char *op = r_anal_esil_pop (esil); - char *param = r_anal_esil_pop (esil); - if (op && r_anal_esil_get_parm_size (esil, op, &op_num, ®size)) { - if (param && r_anal_esil_get_parm (esil, param, ¶m_num)) { + char *op = rz_anal_esil_pop (esil); + char *param = rz_anal_esil_pop (esil); + if (op && rz_anal_esil_get_parm_size (esil, op, &op_num, ®size)) { + if (param && rz_anal_esil_get_parm (esil, param, ¶m_num)) { if (param_num > regsize - 1) { // capstone bug? if (esil->verbose) { @@ -1313,7 +1313,7 @@ static bool esil_asr(RAnalEsil *esil) { op_num >>= param_num; } ut64 res = op_num; - r_anal_esil_pushnum (esil, res); + rz_anal_esil_pushnum (esil, res); ret = true; } else { ERR ("esil_asr: empty stack"); @@ -1324,18 +1324,18 @@ static bool esil_asr(RAnalEsil *esil) { return ret; } -static bool esil_ror(RAnalEsil *esil) { +static bool esil_ror(RzAnalEsil *esil) { bool ret = 0; int regsize; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm_size (esil, dst, &num, ®size)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm_size (esil, dst, &num, ®size)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { ut64 mask = (regsize - 1); num2 &= mask; ut64 res = (num >> num2) | (num << ((-(st64)num2) & mask)); - r_anal_esil_pushnum (esil, res); + rz_anal_esil_pushnum (esil, res); ret = true; } else { ERR ("esil_ror: empty stack"); @@ -1346,18 +1346,18 @@ static bool esil_ror(RAnalEsil *esil) { return ret; } -static bool esil_rol(RAnalEsil *esil) { +static bool esil_rol(RzAnalEsil *esil) { bool ret = 0; int regsize; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm_size (esil, dst, &num, ®size)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm_size (esil, dst, &num, ®size)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { ut64 mask = (regsize - 1); num2 &= mask; ut64 res = (num << num2) | (num >> ((-(st64)num2) & mask)); - r_anal_esil_pushnum (esil, res); + rz_anal_esil_pushnum (esil, res); ret = true; } else { ERR ("esil_rol: empty stack"); @@ -1368,15 +1368,15 @@ static bool esil_rol(RAnalEsil *esil) { return ret; } -static bool esil_and(RAnalEsil *esil) { +static bool esil_and(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { num &= num2; - r_anal_esil_pushnum (esil, num); + rz_anal_esil_pushnum (esil, num); ret = true; } else { ERR ("esil_and: empty stack"); @@ -1387,15 +1387,15 @@ static bool esil_and(RAnalEsil *esil) { return ret; } -static bool esil_xor(RAnalEsil *esil) { +static bool esil_xor(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { num ^= num2; - r_anal_esil_pushnum (esil, num); + rz_anal_esil_pushnum (esil, num); ret = true; } else { ERR ("esil_xor: empty stack"); @@ -1406,15 +1406,15 @@ static bool esil_xor(RAnalEsil *esil) { return ret; } -static bool esil_or(RAnalEsil *esil) { +static bool esil_or(RzAnalEsil *esil) { bool ret = false; ut64 num, num2; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { num |= num2; - r_anal_esil_pushnum (esil, num); + rz_anal_esil_pushnum (esil, num); ret = true; } else { ERR ("esil_xor: empty stack"); @@ -1425,7 +1425,7 @@ static bool esil_or(RAnalEsil *esil) { return ret; } -R_API const char *r_anal_esil_trapstr(int type) { +RZ_API const char *rz_anal_esil_trapstr(int type) { switch (type) { case R_ANAL_TRAP_READ_ERR: return "read-err"; @@ -1448,13 +1448,13 @@ R_API const char *r_anal_esil_trapstr(int type) { } } -R_API bool r_anal_esil_dumpstack(RAnalEsil *esil) { - r_return_val_if_fail (esil, false); +RZ_API bool rz_anal_esil_dumpstack(RzAnalEsil *esil) { + rz_return_val_if_fail (esil, false); int i; if (esil->trap) { eprintf ("ESIL TRAP type %d code 0x%08x %s\n", esil->trap, esil->trap_code, - r_anal_esil_trapstr (esil->trap)); + rz_anal_esil_trapstr (esil->trap)); } if (esil->stackptr < 1) { return false; @@ -1465,42 +1465,42 @@ R_API bool r_anal_esil_dumpstack(RAnalEsil *esil) { return true; } -static bool esil_break(RAnalEsil *esil) { +static bool esil_break(RzAnalEsil *esil) { esil->parse_stop = 1; return 1; } -static bool esil_clear(RAnalEsil *esil) { +static bool esil_clear(RzAnalEsil *esil) { char *r; - while ((r = r_anal_esil_pop (esil))) { + while ((r = rz_anal_esil_pop (esil))) { free (r); } return 1; } -static bool esil_todo(RAnalEsil *esil) { +static bool esil_todo(RzAnalEsil *esil) { esil->parse_stop = 2; return 1; } -static bool esil_goto(RAnalEsil *esil) { +static bool esil_goto(RzAnalEsil *esil) { ut64 num = 0; - char *src = r_anal_esil_pop (esil); - if (src && *src && r_anal_esil_get_parm (esil, src, &num)) { + char *src = rz_anal_esil_pop (esil); + if (src && *src && rz_anal_esil_get_parm (esil, src, &num)) { esil->parse_goto = num; } free (src); return 1; } -static bool esil_repeat(RAnalEsil *esil) { - char *dst = r_anal_esil_pop (esil); // destaintion of the goto - char *src = r_anal_esil_pop (esil); // value of the counter +static bool esil_repeat(RzAnalEsil *esil) { + char *dst = rz_anal_esil_pop (esil); // destaintion of the goto + char *src = rz_anal_esil_pop (esil); // value of the counter ut64 n, num = 0; - if (r_anal_esil_get_parm (esil, src, &n) && r_anal_esil_get_parm (esil, dst, &num)) { + if (rz_anal_esil_get_parm (esil, src, &n) && rz_anal_esil_get_parm (esil, dst, &num)) { if (n > 1) { esil->parse_goto = num; - r_anal_esil_pushnum (esil, n - 1); + rz_anal_esil_pushnum (esil, n - 1); } } free (dst); @@ -1508,19 +1508,19 @@ static bool esil_repeat(RAnalEsil *esil) { return 1; } -static bool esil_pop(RAnalEsil *esil) { - char *dst = r_anal_esil_pop (esil); +static bool esil_pop(RzAnalEsil *esil) { + char *dst = rz_anal_esil_pop (esil); free (dst); return 1; } -static bool esil_mod(RAnalEsil *esil) { +static bool esil_mod(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_get_parm (esil, dst, &d)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_get_parm (esil, dst, &d)) { if (s == 0) { if (esil->verbose > 0) { eprintf ("0x%08"PFMT64x" esil_mod: Division by zero!\n", esil->address); @@ -1528,7 +1528,7 @@ static bool esil_mod(RAnalEsil *esil) { esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_pushnum (esil, d % s); + rz_anal_esil_pushnum (esil, d % s); } ret = true; } @@ -1540,13 +1540,13 @@ static bool esil_mod(RAnalEsil *esil) { return ret; } -static bool esil_signed_mod(RAnalEsil *esil) { +static bool esil_signed_mod(RzAnalEsil *esil) { bool ret = false; st64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, (ut64 *)&s)) { - if (dst && r_anal_esil_get_parm (esil, dst, (ut64 *)&d)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, (ut64 *)&s)) { + if (dst && rz_anal_esil_get_parm (esil, dst, (ut64 *)&d)) { if (s == 0) { if (esil->verbose > 0) { eprintf ("0x%08"PFMT64x" esil_mod: Division by zero!\n", esil->address); @@ -1554,7 +1554,7 @@ static bool esil_signed_mod(RAnalEsil *esil) { esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_pushnum (esil, d % s); + rz_anal_esil_pushnum (esil, d % s); } ret = true; } @@ -1566,18 +1566,18 @@ static bool esil_signed_mod(RAnalEsil *esil) { return ret; } -static bool esil_modeq(RAnalEsil *esil) { +static bool esil_modeq(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_reg_read (esil, dst, &d, NULL)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_reg_read (esil, dst, &d, NULL)) { if (s) { esil->old = d; esil->cur = d % s; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - r_anal_esil_reg_write (esil, dst, d % s); + rz_anal_esil_reg_write (esil, dst, d % s); } else { ERR ("esil_modeq: Division by zero!"); esil->trap = R_ANAL_TRAP_DIVBYZERO; @@ -1595,19 +1595,19 @@ static bool esil_modeq(RAnalEsil *esil) { return ret; } -static bool esil_div(RAnalEsil *esil) { +static bool esil_div(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_get_parm (esil, dst, &d)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_get_parm (esil, dst, &d)) { if (s == 0) { ERR ("esil_div: Division by zero!"); esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_pushnum (esil, d / s); + rz_anal_esil_pushnum (esil, d / s); } ret = true; } @@ -1619,19 +1619,19 @@ static bool esil_div(RAnalEsil *esil) { return ret; } -static bool esil_signed_div(RAnalEsil *esil) { +static bool esil_signed_div(RzAnalEsil *esil) { bool ret = false; st64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, (ut64 *)&s)) { - if (dst && r_anal_esil_get_parm (esil, dst, (ut64 *)&d)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, (ut64 *)&s)) { + if (dst && rz_anal_esil_get_parm (esil, dst, (ut64 *)&d)) { if (s == 0) { ERR ("esil_div: Division by zero!"); esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_pushnum (esil, d / s); + rz_anal_esil_pushnum (esil, d / s); } ret = true; } @@ -1643,18 +1643,18 @@ static bool esil_signed_div(RAnalEsil *esil) { return ret; } -static bool esil_diveq(RAnalEsil *esil) { +static bool esil_diveq(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_reg_read (esil, dst, &d, NULL)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_reg_read (esil, dst, &d, NULL)) { if (s) { esil->old = d; esil->cur = d / s; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - r_anal_esil_reg_write (esil, dst, d / s); + rz_anal_esil_reg_write (esil, dst, d / s); } else { // eprintf ("0x%08"PFMT64x" esil_diveq: Division by zero!\n", esil->address); esil->trap = R_ANAL_TRAP_DIVBYZERO; @@ -1672,14 +1672,14 @@ static bool esil_diveq(RAnalEsil *esil) { return ret; } -static bool esil_mul(RAnalEsil *esil) { +static bool esil_mul(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_get_parm (esil, dst, &d)) { - r_anal_esil_pushnum (esil, d * s); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_get_parm (esil, dst, &d)) { + rz_anal_esil_pushnum (esil, d * s); ret = true; } else { ERR ("esil_mul: empty stack"); @@ -1692,17 +1692,17 @@ static bool esil_mul(RAnalEsil *esil) { return ret; } -static bool esil_muleq(RAnalEsil *esil) { +static bool esil_muleq(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_reg_read (esil, dst, &d, NULL)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_reg_read (esil, dst, &d, NULL)) { esil->old = d; esil->cur = d * s; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - ret = r_anal_esil_reg_write (esil, dst, s * d); + ret = rz_anal_esil_reg_write (esil, dst, s * d); } else { ERR ("esil_muleq: empty stack"); } @@ -1714,13 +1714,13 @@ static bool esil_muleq(RAnalEsil *esil) { return ret; } -static bool esil_add(RAnalEsil *esil) { +static bool esil_add(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if ((src && r_anal_esil_get_parm (esil, src, &s)) && (dst && r_anal_esil_get_parm (esil, dst, &d))) { - r_anal_esil_pushnum (esil, s + d); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if ((src && rz_anal_esil_get_parm (esil, src, &s)) && (dst && rz_anal_esil_get_parm (esil, dst, &d))) { + rz_anal_esil_pushnum (esil, s + d); ret = true; } else { ERR ("esil_add: invalid parameters"); @@ -1730,17 +1730,17 @@ static bool esil_add(RAnalEsil *esil) { return ret; } -static bool esil_addeq(RAnalEsil *esil) { +static bool esil_addeq(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_reg_read (esil, dst, &d, NULL)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_reg_read (esil, dst, &d, NULL)) { esil->old = d; esil->cur = d + s; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - ret = r_anal_esil_reg_write (esil, dst, s + d); + ret = rz_anal_esil_reg_write (esil, dst, s + d); } } else { ERR ("esil_addeq: invalid parameters"); @@ -1750,13 +1750,13 @@ static bool esil_addeq(RAnalEsil *esil) { return ret; } -static bool esil_inc(RAnalEsil *esil) { +static bool esil_inc(RzAnalEsil *esil) { bool ret = false; ut64 s; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { s++; - ret = r_anal_esil_pushnum (esil, s); + ret = rz_anal_esil_pushnum (esil, s); } else { ERR ("esil_inc: invalid parameters"); } @@ -1764,15 +1764,15 @@ static bool esil_inc(RAnalEsil *esil) { return ret; } -static bool esil_inceq(RAnalEsil *esil) { +static bool esil_inceq(RzAnalEsil *esil) { bool ret = false; ut64 sd; - char *src_dst = r_anal_esil_pop (esil); - if (src_dst && (r_anal_esil_get_parm_type (esil, src_dst) == R_ANAL_ESIL_PARM_REG) && r_anal_esil_get_parm (esil, src_dst, &sd)) { + char *src_dst = rz_anal_esil_pop (esil); + if (src_dst && (rz_anal_esil_get_parm_type (esil, src_dst) == R_ANAL_ESIL_PARM_REG) && rz_anal_esil_get_parm (esil, src_dst, &sd)) { // inc rax esil->old = sd++; esil->cur = sd; - r_anal_esil_reg_write (esil, src_dst, sd); + rz_anal_esil_reg_write (esil, src_dst, sd); esil->lastsz = esil_internal_sizeof_reg (esil, src_dst); ret = true; } else { @@ -1782,13 +1782,13 @@ static bool esil_inceq(RAnalEsil *esil) { return ret; } -static bool esil_sub(RAnalEsil *esil) { +static bool esil_sub(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if ((src && r_anal_esil_get_parm (esil, src, &s)) && (dst && r_anal_esil_get_parm (esil, dst, &d))) { - ret = r_anal_esil_pushnum (esil, d - s); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if ((src && rz_anal_esil_get_parm (esil, src, &s)) && (dst && rz_anal_esil_get_parm (esil, dst, &d))) { + ret = rz_anal_esil_pushnum (esil, d - s); } else { ERR ("esil_sub: invalid parameters"); } @@ -1797,17 +1797,17 @@ static bool esil_sub(RAnalEsil *esil) { return ret; } -static bool esil_subeq(RAnalEsil *esil) { +static bool esil_subeq(RzAnalEsil *esil) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { - if (dst && r_anal_esil_reg_read (esil, dst, &d, NULL)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { + if (dst && rz_anal_esil_reg_read (esil, dst, &d, NULL)) { esil->old = d; esil->cur = d - s; esil->lastsz = esil_internal_sizeof_reg (esil, dst); - ret = r_anal_esil_reg_write (esil, dst, d - s); + ret = rz_anal_esil_reg_write (esil, dst, d - s); } } else { ERR ("esil_subeq: invalid parameters"); @@ -1817,13 +1817,13 @@ static bool esil_subeq(RAnalEsil *esil) { return ret; } -static bool esil_dec(RAnalEsil *esil) { +static bool esil_dec(RzAnalEsil *esil) { bool ret = false; ut64 s; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { s--; - ret = r_anal_esil_pushnum (esil, s); + ret = rz_anal_esil_pushnum (esil, s); } else { ERR ("esil_dec: invalid parameters"); } @@ -1831,15 +1831,15 @@ static bool esil_dec(RAnalEsil *esil) { return ret; } -static bool esil_deceq(RAnalEsil *esil) { +static bool esil_deceq(RzAnalEsil *esil) { bool ret = false; ut64 sd; - char *src_dst = r_anal_esil_pop (esil); - if (src_dst && (r_anal_esil_get_parm_type (esil, src_dst) == R_ANAL_ESIL_PARM_REG) && r_anal_esil_get_parm (esil, src_dst, &sd)) { + char *src_dst = rz_anal_esil_pop (esil); + if (src_dst && (rz_anal_esil_get_parm_type (esil, src_dst) == R_ANAL_ESIL_PARM_REG) && rz_anal_esil_get_parm (esil, src_dst, &sd)) { esil->old = sd; sd--; esil->cur = sd; - r_anal_esil_reg_write (esil, src_dst, sd); + rz_anal_esil_reg_write (esil, src_dst, sd); esil->lastsz = esil_internal_sizeof_reg (esil, src_dst); ret = true; } else { @@ -1850,13 +1850,13 @@ static bool esil_deceq(RAnalEsil *esil) { } /* POKE */ -static bool esil_poke_n(RAnalEsil *esil, int bits) { +static bool esil_poke_n(RzAnalEsil *esil, int bits) { ut64 bitmask = genmask (bits - 1); ut64 num, num2, addr; ut8 b[8] = {0}; ut64 n; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); int bytes = R_MIN (sizeof (b), bits / 8); if (bits % 8) { free (src); @@ -1866,16 +1866,16 @@ static bool esil_poke_n(RAnalEsil *esil, int bits) { bool ret = false; //eprintf ("GONA POKE %d src:%s dst:%s\n", bits, src, dst); char *src2 = NULL; - if (src && r_anal_esil_get_parm (esil, src, &num)) { - if (dst && r_anal_esil_get_parm (esil, dst, &addr)) { + if (src && rz_anal_esil_get_parm (esil, src, &num)) { + if (dst && rz_anal_esil_get_parm (esil, dst, &addr)) { if (bits == 128) { - src2 = r_anal_esil_pop (esil); - if (src2 && r_anal_esil_get_parm (esil, src2, &num2)) { - r_write_ble (b, num, esil->anal->big_endian, 64); - ret = r_anal_esil_mem_write (esil, addr, b, bytes); + src2 = rz_anal_esil_pop (esil); + if (src2 && rz_anal_esil_get_parm (esil, src2, &num2)) { + rz_write_ble (b, num, esil->anal->big_endian, 64); + ret = rz_anal_esil_mem_write (esil, addr, b, bytes); if (ret == 0) { - r_write_ble (b, num2, esil->anal->big_endian, 64); - ret = r_anal_esil_mem_write (esil, addr + 8, b, bytes); + rz_write_ble (b, num2, esil->anal->big_endian, 64); + ret = rz_anal_esil_mem_write (esil, addr + 8, b, bytes); } goto out; } @@ -1886,15 +1886,15 @@ static bool esil_poke_n(RAnalEsil *esil, int bits) { // we disable hooks to avoid run hooks on internal peeks void * oldhook = (void*)esil->cb.hook_mem_read; esil->cb.hook_mem_read = NULL; - r_anal_esil_mem_read (esil, addr, b, bytes); + rz_anal_esil_mem_read (esil, addr, b, bytes); esil->cb.hook_mem_read = oldhook; - n = r_read_ble64 (b, esil->anal->big_endian); + n = rz_read_ble64 (b, esil->anal->big_endian); esil->old = n; esil->cur = num; esil->lastsz = bits; num = num & bitmask; - r_write_ble (b, num, esil->anal->big_endian, bits); - ret = r_anal_esil_mem_write (esil, addr, b, bytes); + rz_write_ble (b, num, esil->anal->big_endian, bits); + ret = rz_anal_esil_mem_write (esil, addr, b, bytes); } } out: @@ -1904,62 +1904,62 @@ out: return ret; } -static bool esil_poke1(RAnalEsil *esil) { +static bool esil_poke1(RzAnalEsil *esil) { return esil_poke_n (esil, 8); } -static bool esil_poke2(RAnalEsil *esil) { +static bool esil_poke2(RzAnalEsil *esil) { return esil_poke_n (esil, 16); } -static bool esil_poke3(RAnalEsil *esil) { +static bool esil_poke3(RzAnalEsil *esil) { return esil_poke_n (esil, 24); } -static bool esil_poke4(RAnalEsil *esil) { +static bool esil_poke4(RzAnalEsil *esil) { return esil_poke_n (esil, 32); } -static bool esil_poke8(RAnalEsil *esil) { +static bool esil_poke8(RzAnalEsil *esil) { return esil_poke_n (esil, 64); } -static bool esil_poke16(RAnalEsil *esil) { +static bool esil_poke16(RzAnalEsil *esil) { return esil_poke_n (esil, 128); } -static bool esil_poke(RAnalEsil *esil) { +static bool esil_poke(RzAnalEsil *esil) { return esil_poke_n (esil, esil->anal->bits); } -static bool esil_poke_some(RAnalEsil *esil) { +static bool esil_poke_some(RzAnalEsil *esil) { bool ret = false; int i, regsize; ut64 ptr, regs = 0, tmp; - char *count, *dst = r_anal_esil_pop (esil); + char *count, *dst = rz_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm_size (esil, dst, &tmp, ®size)) { + if (dst && rz_anal_esil_get_parm_size (esil, dst, &tmp, ®size)) { // reg isregornum (esil, dst, &ptr); - count = r_anal_esil_pop (esil); + count = rz_anal_esil_pop (esil); if (count) { isregornum (esil, count, ®s); if (regs > 0) { ut8 b[8] = {0}; ut64 num64; for (i = 0; i < regs; i++) { - char *foo = r_anal_esil_pop (esil); + char *foo = rz_anal_esil_pop (esil); if (!foo) { // avoid looping out of stack free (dst); free (count); return true; } - r_anal_esil_get_parm_size (esil, foo, &tmp, ®size); + rz_anal_esil_get_parm_size (esil, foo, &tmp, ®size); isregornum (esil, foo, &num64); - r_write_ble (b, num64, esil->anal->big_endian, regsize); + rz_write_ble (b, num64, esil->anal->big_endian, regsize); const int size_bytes = regsize / 8; - const ut32 written = r_anal_esil_mem_write (esil, ptr, b, size_bytes); + const ut32 written = rz_anal_esil_mem_write (esil, ptr, b, size_bytes); if (written != size_bytes) { //eprintf ("Cannot write at 0x%08" PFMT64x "\n", ptr); esil->trap = 1; @@ -1979,7 +1979,7 @@ static bool esil_poke_some(RAnalEsil *esil) { /* PEEK */ -static bool esil_peek_n(RAnalEsil *esil, int bits) { +static bool esil_peek_n(RzAnalEsil *esil, int bits) { if (bits & 7) { return false; } @@ -1987,7 +1987,7 @@ static bool esil_peek_n(RAnalEsil *esil, int bits) { char res[32]; ut64 addr; ut32 bytes = bits / 8; - char *dst = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); if (!dst) { eprintf ("ESIL-ERROR at 0x%08"PFMT64x": Cannot peek memory without specifying an address\n", esil->address); return false; @@ -1996,84 +1996,84 @@ static bool esil_peek_n(RAnalEsil *esil, int bits) { if (dst && isregornum (esil, dst, &addr)) { if (bits == 128) { ut8 a[sizeof(ut64) * 2] = {0}; - ret = r_anal_esil_mem_read (esil, addr, a, bytes); - ut64 b = r_read_ble64 (&a, 0); //esil->anal->big_endian); - ut64 c = r_read_ble64 (&a[8], 0); //esil->anal->big_endian); + ret = rz_anal_esil_mem_read (esil, addr, a, bytes); + ut64 b = rz_read_ble64 (&a, 0); //esil->anal->big_endian); + ut64 c = rz_read_ble64 (&a[8], 0); //esil->anal->big_endian); snprintf (res, sizeof (res), "0x%" PFMT64x, b); - r_anal_esil_push (esil, res); + rz_anal_esil_push (esil, res); snprintf (res, sizeof (res), "0x%" PFMT64x, c); - r_anal_esil_push (esil, res); + rz_anal_esil_push (esil, res); free (dst); return ret; } ut64 bitmask = genmask (bits - 1); ut8 a[sizeof(ut64)] = {0}; - ret = !!r_anal_esil_mem_read (esil, addr, a, bytes); - ut64 b = r_read_ble64 (a, 0); //esil->anal->big_endian); + ret = !!rz_anal_esil_mem_read (esil, addr, a, bytes); + ut64 b = rz_read_ble64 (a, 0); //esil->anal->big_endian); if (esil->anal->big_endian) { - r_mem_swapendian ((ut8*)&b, (const ut8*)&b, bytes); + rz_mem_swapendian ((ut8*)&b, (const ut8*)&b, bytes); } snprintf (res, sizeof (res), "0x%" PFMT64x, b & bitmask); - r_anal_esil_push (esil, res); + rz_anal_esil_push (esil, res); esil->lastsz = bits; } free (dst); return ret; } -static bool esil_peek1(RAnalEsil *esil) { +static bool esil_peek1(RzAnalEsil *esil) { return esil_peek_n (esil, 8); } -static bool esil_peek2(RAnalEsil *esil) { +static bool esil_peek2(RzAnalEsil *esil) { return esil_peek_n (esil, 16); } -static bool esil_peek3(RAnalEsil *esil) { +static bool esil_peek3(RzAnalEsil *esil) { return esil_peek_n (esil, 24); } -static bool esil_peek4(RAnalEsil *esil) { +static bool esil_peek4(RzAnalEsil *esil) { return esil_peek_n (esil, 32); } -static bool esil_peek8(RAnalEsil *esil) { +static bool esil_peek8(RzAnalEsil *esil) { return esil_peek_n (esil, 64); } -static bool esil_peek16(RAnalEsil *esil) { +static bool esil_peek16(RzAnalEsil *esil) { // packed only return esil_peek_n (esil, 128); } -static bool esil_peek(RAnalEsil *esil) { +static bool esil_peek(RzAnalEsil *esil) { return esil_peek_n (esil, esil->anal->bits); }; -static bool esil_peek_some(RAnalEsil *esil) { +static bool esil_peek_some(RzAnalEsil *esil) { int i; ut64 ptr, regs; // pop ptr - char *count, *dst = r_anal_esil_pop (esil); + char *count, *dst = rz_anal_esil_pop (esil); if (dst) { // reg isregornum (esil, dst, &ptr); - count = r_anal_esil_pop (esil); + count = rz_anal_esil_pop (esil); if (count) { isregornum (esil, count, ®s); if (regs > 0) { ut32 num32; ut8 a[4]; for (i = 0; i < regs; i++) { - char *foo = r_anal_esil_pop (esil); + char *foo = rz_anal_esil_pop (esil); if (!foo) { ERR ("Cannot pop in peek"); return 0; } - const ut32 read = r_anal_esil_mem_read (esil, ptr, a, 4); + const ut32 read = rz_anal_esil_mem_read (esil, ptr, a, 4); if (read == 4) { //this is highly questionabla - num32 = r_read_ble32 (a, esil->anal->big_endian); - r_anal_esil_reg_write (esil, foo, num32); + num32 = rz_read_ble32 (a, esil->anal->big_endian); + rz_anal_esil_reg_write (esil, foo, num32); } else { if (esil->verbose) { eprintf ("Cannot peek from 0x%08" PFMT64x "\n", ptr); @@ -2094,20 +2094,20 @@ static bool esil_peek_some(RAnalEsil *esil) { /* OREQ */ -static bool esil_mem_oreq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_oreq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); //save the dst-addr - char *src0 = r_anal_esil_pop (esil); //get the src + char *dst = rz_anal_esil_pop (esil); //save the dst-addr + char *src0 = rz_anal_esil_pop (esil); //get the src char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { //get the src - r_anal_esil_push (esil, dst); //push the dst-addr + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { //get the src + rz_anal_esil_push (esil, dst); //push the dst-addr ret = (!!esil_peek_n (esil, bits)); //read - src1 = r_anal_esil_pop (esil); //get the old dst-value - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { //get the old dst-value + src1 = rz_anal_esil_pop (esil); //get the old dst-value + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { //get the old dst-value d |= s; //calculate the new dst-value - r_anal_esil_pushnum (esil, d); //push the new dst-value - r_anal_esil_push (esil, dst); //push the dst-addr + rz_anal_esil_pushnum (esil, d); //push the new dst-value + rz_anal_esil_push (esil, dst); //push the dst-addr ret &= (!!esil_poke_n (esil, bits)); //write } else { ret = false; @@ -2122,38 +2122,38 @@ static bool esil_mem_oreq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_oreq1(RAnalEsil *esil) { +static bool esil_mem_oreq1(RzAnalEsil *esil) { return esil_mem_oreq_n (esil, 8); } -static bool esil_mem_oreq2(RAnalEsil *esil) { +static bool esil_mem_oreq2(RzAnalEsil *esil) { return esil_mem_oreq_n (esil, 16); } -static bool esil_mem_oreq4(RAnalEsil *esil) { +static bool esil_mem_oreq4(RzAnalEsil *esil) { return esil_mem_oreq_n (esil, 32); } -static bool esil_mem_oreq8(RAnalEsil *esil) { +static bool esil_mem_oreq8(RzAnalEsil *esil) { return esil_mem_oreq_n (esil, 64); } -static bool esil_mem_oreq(RAnalEsil *esil) { +static bool esil_mem_oreq(RzAnalEsil *esil) { return esil_mem_oreq_n (esil, esil->anal->bits); } /* XOREQ */ -static bool esil_mem_xoreq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_xoreq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d ^= s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2168,38 +2168,38 @@ static bool esil_mem_xoreq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_xoreq1(RAnalEsil *esil) { +static bool esil_mem_xoreq1(RzAnalEsil *esil) { return esil_mem_xoreq_n (esil, 8); } -static bool esil_mem_xoreq2(RAnalEsil *esil) { +static bool esil_mem_xoreq2(RzAnalEsil *esil) { return esil_mem_xoreq_n (esil, 16); } -static bool esil_mem_xoreq4(RAnalEsil *esil) { +static bool esil_mem_xoreq4(RzAnalEsil *esil) { return esil_mem_xoreq_n (esil, 32); } -static bool esil_mem_xoreq8(RAnalEsil *esil) { +static bool esil_mem_xoreq8(RzAnalEsil *esil) { return esil_mem_xoreq_n (esil, 64); } -static bool esil_mem_xoreq(RAnalEsil *esil) { +static bool esil_mem_xoreq(RzAnalEsil *esil) { return esil_mem_xoreq_n (esil, esil->anal->bits); } /* ANDEQ */ -static bool esil_mem_andeq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_andeq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d &= s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2214,38 +2214,38 @@ static bool esil_mem_andeq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_andeq1(RAnalEsil *esil) { +static bool esil_mem_andeq1(RzAnalEsil *esil) { return esil_mem_andeq_n (esil, 8); } -static bool esil_mem_andeq2(RAnalEsil *esil) { +static bool esil_mem_andeq2(RzAnalEsil *esil) { return esil_mem_andeq_n (esil, 16); } -static bool esil_mem_andeq4(RAnalEsil *esil) { +static bool esil_mem_andeq4(RzAnalEsil *esil) { return esil_mem_andeq_n (esil, 32); } -static bool esil_mem_andeq8(RAnalEsil *esil) { +static bool esil_mem_andeq8(RzAnalEsil *esil) { return esil_mem_andeq_n (esil, 64); } -static bool esil_mem_andeq(RAnalEsil *esil) { +static bool esil_mem_andeq(RzAnalEsil *esil) { return esil_mem_andeq_n (esil, esil->anal->bits); } /* ADDEQ */ -static bool esil_mem_addeq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_addeq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d += s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2260,38 +2260,38 @@ static bool esil_mem_addeq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_addeq1(RAnalEsil *esil) { +static bool esil_mem_addeq1(RzAnalEsil *esil) { return esil_mem_addeq_n (esil, 8); } -static bool esil_mem_addeq2(RAnalEsil *esil) { +static bool esil_mem_addeq2(RzAnalEsil *esil) { return esil_mem_addeq_n (esil, 16); } -static bool esil_mem_addeq4(RAnalEsil *esil) { +static bool esil_mem_addeq4(RzAnalEsil *esil) { return esil_mem_addeq_n (esil, 32); } -static bool esil_mem_addeq8(RAnalEsil *esil) { +static bool esil_mem_addeq8(RzAnalEsil *esil) { return esil_mem_addeq_n (esil, 64); } -static bool esil_mem_addeq(RAnalEsil *esil) { +static bool esil_mem_addeq(RzAnalEsil *esil) { return esil_mem_addeq_n (esil, esil->anal->bits); } /* SUBEQ */ -static bool esil_mem_subeq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_subeq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d -= s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2306,44 +2306,44 @@ static bool esil_mem_subeq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_subeq1(RAnalEsil *esil) { +static bool esil_mem_subeq1(RzAnalEsil *esil) { return esil_mem_subeq_n (esil, 8); } -static bool esil_mem_subeq2(RAnalEsil *esil) { +static bool esil_mem_subeq2(RzAnalEsil *esil) { return esil_mem_subeq_n (esil, 16); } -static bool esil_mem_subeq4(RAnalEsil *esil) { +static bool esil_mem_subeq4(RzAnalEsil *esil) { return esil_mem_subeq_n (esil, 32); } -static bool esil_mem_subeq8(RAnalEsil *esil) { +static bool esil_mem_subeq8(RzAnalEsil *esil) { return esil_mem_subeq_n (esil, 64); } -static bool esil_mem_subeq(RAnalEsil *esil) { +static bool esil_mem_subeq(RzAnalEsil *esil) { return esil_mem_subeq_n (esil, esil->anal->bits); } /* MODEQ */ -static bool esil_mem_modeq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_modeq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { if (s == 0) { ERR ("esil_mem_modeq4: Division by zero!"); esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_push (esil, dst); + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d) && s >= 1) { - r_anal_esil_pushnum (esil, d % s); + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d) && s >= 1) { + rz_anal_esil_pushnum (esil, d % s); d = d % s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2359,43 +2359,43 @@ static bool esil_mem_modeq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_modeq1(RAnalEsil *esil) { +static bool esil_mem_modeq1(RzAnalEsil *esil) { return esil_mem_modeq_n (esil, 8); } -static bool esil_mem_modeq2(RAnalEsil *esil) { +static bool esil_mem_modeq2(RzAnalEsil *esil) { return esil_mem_modeq_n (esil, 16); } -static bool esil_mem_modeq4(RAnalEsil *esil) { +static bool esil_mem_modeq4(RzAnalEsil *esil) { return esil_mem_modeq_n (esil, 32); } -static bool esil_mem_modeq8(RAnalEsil *esil) { +static bool esil_mem_modeq8(RzAnalEsil *esil) { return esil_mem_modeq_n (esil, 64); } -static bool esil_mem_modeq(RAnalEsil *esil) { +static bool esil_mem_modeq(RzAnalEsil *esil) { return esil_mem_modeq_n (esil, esil->anal->bits); } /* DIVEQ */ -static bool esil_mem_diveq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_diveq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { if (s == 0) { ERR ("esil_mem_diveq8: Division by zero!"); esil->trap = R_ANAL_TRAP_DIVBYZERO; esil->trap_code = 0; } else { - r_anal_esil_push (esil, dst); + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d = d / s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2411,38 +2411,38 @@ static bool esil_mem_diveq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_diveq1(RAnalEsil *esil) { +static bool esil_mem_diveq1(RzAnalEsil *esil) { return esil_mem_diveq_n (esil, 8); } -static bool esil_mem_diveq2(RAnalEsil *esil) { +static bool esil_mem_diveq2(RzAnalEsil *esil) { return esil_mem_diveq_n (esil, 16); } -static bool esil_mem_diveq4(RAnalEsil *esil) { +static bool esil_mem_diveq4(RzAnalEsil *esil) { return esil_mem_diveq_n (esil, 32); } -static bool esil_mem_diveq8(RAnalEsil *esil) { +static bool esil_mem_diveq8(RzAnalEsil *esil) { return esil_mem_diveq_n (esil, 64); } -static bool esil_mem_diveq(RAnalEsil *esil) { +static bool esil_mem_diveq(RzAnalEsil *esil) { return esil_mem_diveq_n (esil, esil->anal->bits); } /* MULEQ */ -static bool esil_mem_muleq_n(RAnalEsil *esil, int bits, ut64 bitmask) { +static bool esil_mem_muleq_n(RzAnalEsil *esil, int bits, ut64 bitmask) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d *= s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2457,20 +2457,20 @@ static bool esil_mem_muleq_n(RAnalEsil *esil, int bits, ut64 bitmask) { return ret; } -static bool esil_mem_muleq1(RAnalEsil *esil) { +static bool esil_mem_muleq1(RzAnalEsil *esil) { return esil_mem_muleq_n (esil, 8, UT8_MAX); } -static bool esil_mem_muleq2(RAnalEsil *esil) { +static bool esil_mem_muleq2(RzAnalEsil *esil) { return esil_mem_muleq_n (esil, 16, UT16_MAX); } -static bool esil_mem_muleq4(RAnalEsil *esil) { +static bool esil_mem_muleq4(RzAnalEsil *esil) { return esil_mem_muleq_n (esil, 32, UT32_MAX); } -static bool esil_mem_muleq8(RAnalEsil *esil) { +static bool esil_mem_muleq8(RzAnalEsil *esil) { return esil_mem_muleq_n (esil, 64, UT64_MAX); } -static bool esil_mem_muleq(RAnalEsil *esil) { +static bool esil_mem_muleq(RzAnalEsil *esil) { switch (esil->anal->bits) { case 64: return esil_mem_muleq8 (esil); case 32: return esil_mem_muleq4 (esil); @@ -2482,22 +2482,22 @@ static bool esil_mem_muleq(RAnalEsil *esil) { /* INCEQ */ -static bool esil_mem_inceq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_inceq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s; - char *off = r_anal_esil_pop (esil); + char *off = rz_anal_esil_pop (esil); char *src = NULL; if (off) { - r_anal_esil_push (esil, off); + rz_anal_esil_push (esil, off); ret = (!!esil_peek_n (esil, bits)); - src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { esil->old = s; s++; esil->cur = s; esil->lastsz = bits; - r_anal_esil_pushnum (esil, s); - r_anal_esil_push (esil, off); + rz_anal_esil_pushnum (esil, s); + rz_anal_esil_push (esil, off); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2511,37 +2511,37 @@ static bool esil_mem_inceq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_inceq1(RAnalEsil *esil) { +static bool esil_mem_inceq1(RzAnalEsil *esil) { return esil_mem_inceq_n (esil, 8); } -static bool esil_mem_inceq2(RAnalEsil *esil) { +static bool esil_mem_inceq2(RzAnalEsil *esil) { return esil_mem_inceq_n (esil, 16); } -static bool esil_mem_inceq4(RAnalEsil *esil) { +static bool esil_mem_inceq4(RzAnalEsil *esil) { return esil_mem_inceq_n (esil, 32); } -static bool esil_mem_inceq8(RAnalEsil *esil) { +static bool esil_mem_inceq8(RzAnalEsil *esil) { return esil_mem_inceq_n (esil, 64); } -static bool esil_mem_inceq(RAnalEsil *esil) { +static bool esil_mem_inceq(RzAnalEsil *esil) { return esil_mem_inceq_n (esil, esil->anal->bits); } /* DECEQ */ -static bool esil_mem_deceq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_deceq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s; - char *off = r_anal_esil_pop (esil); + char *off = rz_anal_esil_pop (esil); char *src = NULL; if (off) { - r_anal_esil_push (esil, off); + rz_anal_esil_push (esil, off); ret = (!!esil_peek_n (esil, bits)); - src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { s--; - r_anal_esil_pushnum (esil, s); - r_anal_esil_push (esil, off); + rz_anal_esil_pushnum (esil, s); + rz_anal_esil_push (esil, off); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2555,45 +2555,45 @@ static bool esil_mem_deceq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_deceq1(RAnalEsil *esil) { +static bool esil_mem_deceq1(RzAnalEsil *esil) { return esil_mem_deceq_n (esil, 8); } -static bool esil_mem_deceq2(RAnalEsil *esil) { +static bool esil_mem_deceq2(RzAnalEsil *esil) { return esil_mem_deceq_n (esil, 16); } -static bool esil_mem_deceq4(RAnalEsil *esil) { +static bool esil_mem_deceq4(RzAnalEsil *esil) { return esil_mem_deceq_n (esil, 32); } -static bool esil_mem_deceq8(RAnalEsil *esil) { +static bool esil_mem_deceq8(RzAnalEsil *esil) { return esil_mem_deceq_n (esil, 64); } -static bool esil_mem_deceq(RAnalEsil *esil) { +static bool esil_mem_deceq(RzAnalEsil *esil) { return esil_mem_deceq_n (esil, esil->anal->bits); } /* LSLEQ */ -static bool esil_mem_lsleq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_lsleq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { if (s > sizeof (ut64) * 8) { ERR ("esil_mem_lsleq_n: shift is too big"); } else { - r_anal_esil_push (esil, dst); + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { if (s > 63) { d = 0; } else { d <<= s; } - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2609,38 +2609,38 @@ static bool esil_mem_lsleq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_lsleq1(RAnalEsil *esil) { +static bool esil_mem_lsleq1(RzAnalEsil *esil) { return esil_mem_lsleq_n (esil, 8); } -static bool esil_mem_lsleq2(RAnalEsil *esil) { +static bool esil_mem_lsleq2(RzAnalEsil *esil) { return esil_mem_lsleq_n (esil, 16); } -static bool esil_mem_lsleq4(RAnalEsil *esil) { +static bool esil_mem_lsleq4(RzAnalEsil *esil) { return esil_mem_lsleq_n (esil, 32); } -static bool esil_mem_lsleq8(RAnalEsil *esil) { +static bool esil_mem_lsleq8(RzAnalEsil *esil) { return esil_mem_lsleq_n (esil, 64); } -static bool esil_mem_lsleq(RAnalEsil *esil) { +static bool esil_mem_lsleq(RzAnalEsil *esil) { return esil_mem_lsleq_n (esil, esil->anal->bits); } /* LSREQ */ -static bool esil_mem_lsreq_n(RAnalEsil *esil, int bits) { +static bool esil_mem_lsreq_n(RzAnalEsil *esil, int bits) { bool ret = false; ut64 s, d; - char *dst = r_anal_esil_pop (esil); - char *src0 = r_anal_esil_pop (esil); + char *dst = rz_anal_esil_pop (esil); + char *src0 = rz_anal_esil_pop (esil); char *src1 = NULL; - if (src0 && r_anal_esil_get_parm (esil, src0, &s)) { - r_anal_esil_push (esil, dst); + if (src0 && rz_anal_esil_get_parm (esil, src0, &s)) { + rz_anal_esil_push (esil, dst); ret = (!!esil_peek_n (esil, bits)); - src1 = r_anal_esil_pop (esil); - if (src1 && r_anal_esil_get_parm (esil, src1, &d)) { + src1 = rz_anal_esil_pop (esil); + if (src1 && rz_anal_esil_get_parm (esil, src1, &d)) { d >>= s; - r_anal_esil_pushnum (esil, d); - r_anal_esil_push (esil, dst); + rz_anal_esil_pushnum (esil, d); + rz_anal_esil_push (esil, dst); ret &= (!!esil_poke_n (esil, bits)); } else { ret = false; @@ -2655,49 +2655,49 @@ static bool esil_mem_lsreq_n(RAnalEsil *esil, int bits) { return ret; } -static bool esil_mem_lsreq1(RAnalEsil *esil) { +static bool esil_mem_lsreq1(RzAnalEsil *esil) { return esil_mem_lsreq_n (esil, 8); } -static bool esil_mem_lsreq2(RAnalEsil *esil) { +static bool esil_mem_lsreq2(RzAnalEsil *esil) { return esil_mem_lsreq_n (esil, 16); } -static bool esil_mem_lsreq4(RAnalEsil *esil) { +static bool esil_mem_lsreq4(RzAnalEsil *esil) { return esil_mem_lsreq_n (esil, 32); } -static bool esil_mem_lsreq8(RAnalEsil *esil) { +static bool esil_mem_lsreq8(RzAnalEsil *esil) { return esil_mem_lsreq_n (esil, 64); } -static bool esil_mem_lsreq(RAnalEsil *esil) { +static bool esil_mem_lsreq(RzAnalEsil *esil) { return esil_mem_lsreq_n (esil, esil->anal->bits); } /* get value of register or memory reference and push the value */ -static bool esil_num(RAnalEsil *esil) { +static bool esil_num(RzAnalEsil *esil) { char *dup_me; ut64 dup; if (!esil) { return false; } - if (!(dup_me = r_anal_esil_pop (esil))) { + if (!(dup_me = rz_anal_esil_pop (esil))) { return false; } - if (!r_anal_esil_get_parm (esil, dup_me, &dup)) { + if (!rz_anal_esil_get_parm (esil, dup_me, &dup)) { free (dup_me); return false; } free (dup_me); - return r_anal_esil_pushnum (esil, dup); + return rz_anal_esil_pushnum (esil, dup); } /* duplicate the last element in the stack */ -static bool esil_dup(RAnalEsil *esil) { +static bool esil_dup(RzAnalEsil *esil) { if (!esil || !esil->stack || esil->stackptr < 1 || esil->stackptr > (esil->stacksize - 1)) { return false; } - return r_anal_esil_push (esil, esil->stack[esil->stackptr-1]); + return rz_anal_esil_push (esil, esil->stack[esil->stackptr-1]); } -static bool esil_swap(RAnalEsil *esil) { +static bool esil_swap(RzAnalEsil *esil) { char *tmp; if (!esil || !esil->stack || esil->stackptr < 2) { return false; @@ -2736,25 +2736,25 @@ static int signed_compare_gt(ut64 a, ut64 b, ut64 size) { return result; } -static bool esil_smaller(RAnalEsil *esil) { // 'dst < src' => 'src,dst,<' +static bool esil_smaller(RzAnalEsil *esil) { // 'dst < src' => 'src,dst,<' ut64 num, num2; bool ret = false; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num - num2; ret = true; - if (r_reg_get (esil->anal->reg, dst, -1)) { + if (rz_reg_get (esil->anal->reg, dst, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, dst); - } else if (r_reg_get (esil->anal->reg, src, -1)) { + } else if (rz_reg_get (esil->anal->reg, src, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, src); } else { // default size is set to 64 as internally operands are ut64 esil->lastsz = 64; } - r_anal_esil_pushnum (esil, (num != num2) & + rz_anal_esil_pushnum (esil, (num != num2) & !signed_compare_gt (num, num2, esil->lastsz)); } } @@ -2763,25 +2763,25 @@ static bool esil_smaller(RAnalEsil *esil) { // 'dst < src' => 'src,dst,<' return ret; } -static bool esil_bigger(RAnalEsil *esil) { // 'dst > src' => 'src,dst,>' +static bool esil_bigger(RzAnalEsil *esil) { // 'dst > src' => 'src,dst,>' ut64 num, num2; bool ret = false; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num - num2; ret = true; - if (r_reg_get (esil->anal->reg, dst, -1)) { + if (rz_reg_get (esil->anal->reg, dst, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, dst); - } else if (r_reg_get (esil->anal->reg, src, -1)) { + } else if (rz_reg_get (esil->anal->reg, src, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, src); } else { // default size is set to 64 as internally operands are ut64 esil->lastsz = 64; } - r_anal_esil_pushnum (esil, signed_compare_gt (num, num2, esil->lastsz)); + rz_anal_esil_pushnum (esil, signed_compare_gt (num, num2, esil->lastsz)); } } free (dst); @@ -2789,25 +2789,25 @@ static bool esil_bigger(RAnalEsil *esil) { // 'dst > src' => 'src,dst,>' return ret; } -static bool esil_smaller_equal(RAnalEsil *esil) { // 'dst <= src' => 'src,dst,<=' +static bool esil_smaller_equal(RzAnalEsil *esil) { // 'dst <= src' => 'src,dst,<=' ut64 num, num2; bool ret = false; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num - num2; ret = true; - if (r_reg_get (esil->anal->reg, dst, -1)) { + if (rz_reg_get (esil->anal->reg, dst, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, dst); - } else if (r_reg_get (esil->anal->reg, src, -1)) { + } else if (rz_reg_get (esil->anal->reg, src, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, src); } else { // default size is set to 64 as internally operands are ut64 esil->lastsz = 64; } - r_anal_esil_pushnum (esil, !signed_compare_gt (num, num2, esil->lastsz)); + rz_anal_esil_pushnum (esil, !signed_compare_gt (num, num2, esil->lastsz)); } } free (dst); @@ -2815,25 +2815,25 @@ static bool esil_smaller_equal(RAnalEsil *esil) { // 'dst <= src' => 'src,dst,<= return ret; } -static bool esil_bigger_equal(RAnalEsil *esil) { // 'dst >= src' => 'src,dst,>=' +static bool esil_bigger_equal(RzAnalEsil *esil) { // 'dst >= src' => 'src,dst,>=' ut64 num, num2; bool ret = false; - char *dst = r_anal_esil_pop (esil); - char *src = r_anal_esil_pop (esil); - if (dst && r_anal_esil_get_parm (esil, dst, &num)) { - if (src && r_anal_esil_get_parm (esil, src, &num2)) { + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + if (dst && rz_anal_esil_get_parm (esil, dst, &num)) { + if (src && rz_anal_esil_get_parm (esil, src, &num2)) { esil->old = num; esil->cur = num - num2; ret = true; - if (r_reg_get (esil->anal->reg, dst, -1)) { + if (rz_reg_get (esil->anal->reg, dst, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, dst); - } else if (r_reg_get (esil->anal->reg, src, -1)) { + } else if (rz_reg_get (esil->anal->reg, src, -1)) { esil->lastsz = esil_internal_sizeof_reg (esil, src); } else { // default size is set to 64 as internally operands are ut64 esil->lastsz = 64; } - r_anal_esil_pushnum (esil, (num == num2) | + rz_anal_esil_pushnum (esil, (num == num2) | signed_compare_gt (num, num2, esil->lastsz)); } } @@ -2842,11 +2842,11 @@ static bool esil_bigger_equal(RAnalEsil *esil) { // 'dst >= src' => 'src,dst,>=' return ret; } -static bool esil_set_jump_target(RAnalEsil *esil) { +static bool esil_set_jump_target(RzAnalEsil *esil) { bool ret = false; ut64 s; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { esil->jump_target = s; esil->jump_target_set = 1; ret = true; @@ -2858,11 +2858,11 @@ static bool esil_set_jump_target(RAnalEsil *esil) { return ret; } -static bool esil_set_jump_target_set(RAnalEsil *esil) { +static bool esil_set_jump_target_set(RzAnalEsil *esil) { bool ret = false; ut64 s; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { esil->jump_target_set = s; ret = true; } else { @@ -2873,11 +2873,11 @@ static bool esil_set_jump_target_set(RAnalEsil *esil) { return ret; } -static bool esil_set_delay_slot(RAnalEsil *esil) { +static bool esil_set_delay_slot(RzAnalEsil *esil) { bool ret = false; ut64 s; - char *src = r_anal_esil_pop (esil); - if (src && r_anal_esil_get_parm (esil, src, &s)) { + char *src = rz_anal_esil_pop (esil); + if (src && rz_anal_esil_get_parm (esil, src, &s)) { esil->delay = s; ret = true; } else { @@ -2888,8 +2888,8 @@ static bool esil_set_delay_slot(RAnalEsil *esil) { return ret; } -static bool iscommand(RAnalEsil *esil, const char *word, RAnalEsilOp **op) { - RAnalEsilOp *eop = ht_pp_find (esil->ops, word, NULL); +static bool iscommand(RzAnalEsil *esil, const char *word, RzAnalEsilOp **op) { + RzAnalEsilOp *eop = ht_pp_find (esil->ops, word, NULL); if (eop) { *op = eop; return true; @@ -2897,8 +2897,8 @@ static bool iscommand(RAnalEsil *esil, const char *word, RAnalEsilOp **op) { return false; } -static bool runword(RAnalEsil *esil, const char *word) { - RAnalEsilOp *op = NULL; +static bool runword(RzAnalEsil *esil, const char *word) { + RzAnalEsilOp *op = NULL; if (!word) { return false; } @@ -2924,8 +2924,8 @@ static bool runword(RAnalEsil *esil, const char *word) { strncat (if_buf, word, sizeof (esil->Reil->if_buf) - strlen (if_buf) - 1); strncat (if_buf, ",", sizeof (esil->Reil->if_buf) - strlen (if_buf) - 1); if (!strcmp (word, "}")) { - r_anal_esil_pushnum (esil, esil->Reil->addr + esil->Reil->cmd_count + 1); - r_anal_esil_parse (esil, esil->Reil->if_buf); + rz_anal_esil_pushnum (esil, esil->Reil->addr + esil->Reil->cmd_count + 1); + rz_anal_esil_parse (esil, esil->Reil->if_buf); } else if (iscommand (esil, word, &op)) { esil->Reil->cmd_count++; } @@ -2979,7 +2979,7 @@ static bool runword(RAnalEsil *esil, const char *word) { } // push value - if (!r_anal_esil_push (esil, word)) { + if (!rz_anal_esil_push (esil, word)) { ERR ("ESIL stack is full"); esil->trap = 1; esil->trap_code = 1; @@ -3010,8 +3010,8 @@ static const char *gotoWord(const char *str, int n) { * 2: continue in loop * 3: normal continuation */ -static int evalWord(RAnalEsil *esil, const char *ostr, const char **str) { - r_return_val_if_fail (esil && str, 0); +static int evalWord(RzAnalEsil *esil, const char *ostr, const char **str) { + rz_return_val_if_fail (esil && str, 0); if (!*str) { return 0; } @@ -3042,7 +3042,7 @@ static int evalWord(RAnalEsil *esil, const char *ostr, const char **str) { return 3; } -static bool __stepOut(RAnalEsil *esil, const char *cmd) { +static bool __stepOut(RzAnalEsil *esil, const char *cmd) { static bool inCmdStep = false; if (cmd && esil && esil->cmd && !inCmdStep) { inCmdStep = true; @@ -3056,12 +3056,12 @@ static bool __stepOut(RAnalEsil *esil, const char *cmd) { return false; } -R_API bool r_anal_esil_parse(RAnalEsil *esil, const char *str) { +RZ_API bool rz_anal_esil_parse(RzAnalEsil *esil, const char *str) { int wordi = 0; int dorunword; char word[64]; const char *ostr = str; - r_return_val_if_fail (esil && R_STR_ISNOTEMPTY (str), 0); + rz_return_val_if_fail (esil && R_STR_ISNOTEMPTY (str), 0); if (__stepOut (esil, esil->cmd_step)) { (void)__stepOut (esil, esil->cmd_step_out); @@ -3080,7 +3080,7 @@ loop: esil->parse_goto = -1; esil->parse_stop = 0; // memleak or failing aetr test. wat du -// r_anal_esil_stack_free (esil); +// rz_anal_esil_stack_free (esil); esil->parse_goto_count = esil->anal? esil->anal->esil_goto_limit: R_ANAL_ESIL_GOTO_LIMIT; str = ostr; repeat: @@ -3152,7 +3152,7 @@ repeat: return 1; } -R_API bool r_anal_esil_runword(RAnalEsil *esil, const char *word) { +RZ_API bool rz_anal_esil_runword(RzAnalEsil *esil, const char *word) { const char *str = NULL; (void)runword (esil, word); if (*word) { @@ -3161,14 +3161,14 @@ R_API bool r_anal_esil_runword(RAnalEsil *esil, const char *word) { } int ew = evalWord (esil, word, &str); eprintf ("ew %d\n", ew); - eprintf ("--> %s\n", r_str_get (str)); + eprintf ("--> %s\n", rz_str_get (str)); } return true; } //frees all elements from the stack, not the stack itself //rename to stack_empty() ? -R_API void r_anal_esil_stack_free(RAnalEsil *esil) { +RZ_API void rz_anal_esil_stack_free(RzAnalEsil *esil) { int i; if (esil) { for (i = 0; i < esil->stackptr; i++) { @@ -3178,7 +3178,7 @@ R_API void r_anal_esil_stack_free(RAnalEsil *esil) { } } -R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str) { +RZ_API int rz_anal_esil_condition(RzAnalEsil *esil, const char *str) { char *popped; int ret; if (!esil) { @@ -3187,8 +3187,8 @@ R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str) { while (*str == ' ') { str++; // use proper string chop? } - (void) r_anal_esil_parse (esil, str); - popped = r_anal_esil_pop (esil); + (void) rz_anal_esil_parse (esil, str); + popped = rz_anal_esil_pop (esil); if (popped) { ut64 num; if (isregornum (esil, popped, &num)) { @@ -3204,8 +3204,8 @@ R_API int r_anal_esil_condition(RAnalEsil *esil, const char *str) { return ret; } -static void r_anal_esil_setup_ops(RAnalEsil *esil) { -#define OP(v, w, x, y, z) r_anal_esil_set_op (esil, v, w, x, y, z) +static void rz_anal_esil_setup_ops(RzAnalEsil *esil) { +#define OP(v, w, x, y, z) rz_anal_esil_set_op (esil, v, w, x, y, z) #define OT_UNK R_ANAL_ESIL_OP_TYPE_UNKNOWN #define OT_CTR R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW #define OT_MATH R_ANAL_ESIL_OP_TYPE_MATH @@ -3344,7 +3344,7 @@ static void r_anal_esil_setup_ops(RAnalEsil *esil) { OP ("[4]", esil_peek4, 1, 1, OT_MEMR); OP ("[8]", esil_peek8, 1, 1, OT_MEMR); OP ("[16]", esil_peek16, 1, 1, OT_MEMR); - OP ("STACK", r_anal_esil_dumpstack, 0, 0, OT_UNK); + OP ("STACK", rz_anal_esil_dumpstack, 0, 0, OT_UNK); OP ("REPEAT", esil_repeat, 0, 2, OT_CTR); OP ("POP", esil_pop, 0, 1, OT_UNK); OP ("TODO", esil_todo, 0, 0, OT_UNK); @@ -3362,8 +3362,8 @@ static void r_anal_esil_setup_ops(RAnalEsil *esil) { } /* register callbacks using this anal module. */ -R_API bool r_anal_esil_setup(RAnalEsil *esil, RAnal *anal, int romem, int stats, int nonull) { - r_return_val_if_fail (esil, false); +RZ_API bool rz_anal_esil_setup(RzAnalEsil *esil, RzAnal *anal, int romem, int stats, int nonull) { + rz_return_val_if_fail (esil, false); //esil->debug = 0; esil->anal = anal; esil->parse_goto_count = anal->esil_goto_limit; @@ -3386,9 +3386,9 @@ R_API bool r_anal_esil_setup(RAnalEsil *esil, RAnal *anal, int romem, int stats, esil->cb.mem_read = internal_esil_mem_read; esil->cb.mem_write = internal_esil_mem_write; } - r_anal_esil_mem_ro (esil, romem); - r_anal_esil_stats (esil, stats); - r_anal_esil_setup_ops (esil); + rz_anal_esil_mem_ro (esil, romem); + rz_anal_esil_stats (esil, stats); + rz_anal_esil_setup_ops (esil); return (anal->cur && anal->cur->esil_init) ? anal->cur->esil_init (esil): true; diff --git a/librz/anal/esil2reil.c b/librz/anal/esil2reil.c new file mode 100644 index 0000000000..575d7675ef --- /dev/null +++ b/librz/anal/esil2reil.c @@ -0,0 +1,1263 @@ +/* + * Convert from ESIL to REIL (Reverse Engineering Intermediate Language) + * Contributor: sushant94 + */ + +#include + +#define REIL_TEMP_PREFIX "V" +#define REIL_REG_PREFIX "R_" +#define REGBUFSZ 32 + +void reil_flag_spew_inst(RzAnalEsil *esil, const char *flag); +static const char *ops[] = { FOREACHOP(REIL_OP_STRING) }; + +// Get size of a register. +static ut8 esil_internal_sizeof_reg(RzAnalEsil *esil, const char *r) { + if (!esil || !esil->anal || !esil->anal->reg || !r) { + return false; + } + RzRegItem *i = rz_reg_get(esil->anal->reg, r, -1); + return i ? (ut8)i->size : 0; +} + +RzAnalReilArgType reil_get_arg_type(RzAnalEsil *esil, char *s) { + if (!strncmp (s, REIL_TEMP_PREFIX, strlen (REIL_TEMP_PREFIX))) { + return ARG_TEMP; + } + int type = rz_anal_esil_get_parm_type(esil, s); + switch (type) { + case R_ANAL_ESIL_PARM_REG: + return ARG_REG; + case R_ANAL_ESIL_PARM_NUM: + return ARG_CONST; + default: + return ARG_NONE; + } +} + +// Marshall the struct into a string +void reil_push_arg(RzAnalEsil *esil, RzAnalReilArg *op) { + char *s = rz_str_newf ("%s:%d", op->name, op->size); + rz_anal_esil_push (esil, s); + free (s); +} + +// Unmarshall the string in stack to the struct. +RzAnalReilArg *reil_pop_arg(RzAnalEsil *esil) { + RzAnalReilArg *op; + int i, j = 0, flag = 0, len; + char tmp_buf[REGBUFSZ]; + char *buf = rz_anal_esil_pop(esil); + if (!buf) { + return NULL; + } + len = strlen (buf); + op = R_NEW0(RzAnalReilArg); + for (i = 0; i < len; i++) { + if (buf[i] == ':') { + tmp_buf[j] = '\0'; + rz_str_ncpy (op->name, tmp_buf, sizeof (op->name)); + memset (tmp_buf, 0, sizeof (tmp_buf)); + j = 0; + flag = 1; + continue; + } + // Strip all spaces + if (buf[i] == ' ') { + continue; + } + tmp_buf[j] = buf[i]; + j++; + } + tmp_buf[j] = '\0'; + + // If we have not encountered a ':' we don't know the size yet. + if (!flag) { + rz_str_ncpy (op->name, tmp_buf, sizeof (op->name)); + op->type = reil_get_arg_type (esil, op->name); + if (op->type == ARG_REG) { + op->size = esil_internal_sizeof_reg(esil, op->name); + } else if (op->type == ARG_CONST) { + op->size = esil->anal->bits; + } + free(buf); + return op; + } + + op->size = strtoll(tmp_buf, NULL, 10); + op->type = reil_get_arg_type(esil, op->name); + free(buf); + return op; +} + +// Get the next available temp register. +void get_next_temp_reg(RzAnalEsil *esil, char *buf) { + rz_snprintf (buf, REGBUFSZ, REIL_TEMP_PREFIX"_%02"PFMT64u, + esil->Reil->reilNextTemp); + esil->Reil->reilNextTemp++; +} + +void reil_make_arg(RzAnalEsil *esil, RzAnalReilArg *arg, char *name) { + if (!arg) { + return; + } + RzAnalReilArgType type = reil_get_arg_type (esil, name); + arg->size = 0; + arg->type = type; + rz_str_ncpy (arg->name, name, sizeof (arg->name) - 1); +} + +// Free ins and all its arguments +void reil_free_inst(RzAnalReilInst *ins) { + if (!ins) { + return; + } + if (ins->arg[0]) { R_FREE (ins->arg[0]); } + if (ins->arg[1]) { R_FREE (ins->arg[1]); } + if (ins->arg[2]) { R_FREE (ins->arg[2]); } + R_FREE(ins); +} + +// Automatically increments the seq_num of the instruction. +void reil_print_inst(RzAnalEsil *esil, RzAnalReilInst *ins) { + int i; + + if (!ins || !esil) { + return; + } + esil->anal->cb_printf("%04"PFMT64x".%02"PFMT64x": %8s", + esil->Reil->addr, esil->Reil->seq_num++, ops[ins->opcode]); + for (i = 0; i < 3; i++) { + if (i > 0) { + esil->anal->cb_printf (" ,"); + } + if (!ins->arg[i]) { + continue; + } + if (ins->arg[i]->type == ARG_NONE) { + esil->anal->cb_printf ("%10s ", ins->arg[i]->name); + continue; + } + if (ins->arg[i]->type == ARG_REG) { + char *tmp_buf = rz_str_newf ("%s%s", REIL_REG_PREFIX, ins->arg[i]->name); + esil->anal->cb_printf ("%10s:%02d", tmp_buf, ins->arg[i]->size); + free (tmp_buf); + continue; + } + esil->anal->cb_printf ("%10s:%02d", ins->arg[i]->name, ins->arg[i]->size); + } + esil->anal->cb_printf("\n"); +} + +// Used to cast sizes during assignment. OR is used for casting. +// Pushes the new *casted* src onto stack. Warning: Frees the original src! +void reil_cast_size(RzAnalEsil *esil, RzAnalReilArg *src, RzAnalReilArg *dst) { + char tmp_buf[REGBUFSZ]; + RzAnalReilInst *ins; + + if (!src || !dst) { + return; + } + // No need to case sizes if dst and src are of same size. + if (src->size == dst->size) { + reil_push_arg(esil, src); + return; + } + snprintf (tmp_buf, REGBUFSZ-1, "0:%d", dst->size); + rz_anal_esil_push (esil, tmp_buf); + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + return; + } + ins->opcode = REIL_OR; + ins->arg[0] = src; + ins->arg[1] = reil_pop_arg (esil); + ins->arg[2] = R_NEW0(RzAnalReilArg); + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + if (ins->arg[2]) { + ins->arg[2]->size = dst->size; + } + reil_print_inst (esil, ins); + if (ins->arg[2]) { + reil_push_arg (esil, ins->arg[2]); + } + reil_free_inst (ins); +} + +// Here start translation functions! +static bool reil_eq(RzAnalEsil *esil) { + RzAnalReilInst *ins; + char tmp_buf[REGBUFSZ]; + RzAnalReilArgType src_type, dst_type; + RzAnalReilArg *dst, *src; + + dst = reil_pop_arg (esil); + if (!dst) { + return false; + } + src = reil_pop_arg (esil); + if (!src) { + R_FREE (dst); + return false; + } + + src_type = src->type; + // Check if the src is an internal var. If it is, we need to resolve it. + if (src_type == ARG_ESIL_INTERNAL) { + reil_flag_spew_inst (esil, src->name + 1); + R_FREE (src); + src = reil_pop_arg (esil); + } else if (src_type == ARG_REG) { + // No direct register to register transfer. + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + free (src); + free (dst); + return false; + } + ins->opcode = REIL_STR; + ins->arg[0] = src; + ins->arg[1] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0(RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + reil_make_arg (esil, ins->arg[1], " "); + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = ins->arg[0]->size; + reil_print_inst (esil, ins); + reil_push_arg( esil, ins->arg[2]); + reil_free_inst (ins); + src = reil_pop_arg (esil); + } + + // First, make a copy of the dst. We will need this to set the flags later on. + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (dst); + R_FREE (src); + return false; + } + dst_type = dst->type; + if (src_type != ARG_ESIL_INTERNAL && dst_type == ARG_REG) { + ins->opcode = REIL_STR; + ins->arg[0] = dst; + ins->arg[1] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + R_FREE (src); + return false; + } + ins->arg[2] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + R_FREE (src); + return false; + } + reil_make_arg (esil, ins->arg[1], " "); + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = ins->arg[0]->size; + reil_print_inst (esil, ins); + + // Used for setting the flags + rz_snprintf (esil->Reil->old, sizeof (esil->Reil->old) - 1, "%s:%d", + ins->arg[2]->name, ins->arg[2]->size); + rz_snprintf (esil->Reil->cur, sizeof (esil->Reil->cur) - 1, "%s:%d", dst->name, + dst->size); + esil->Reil->lastsz = dst->size; + + R_FREE (ins->arg[1]); + R_FREE (ins->arg[2]); + } + + // If we are modifying the Instruction Pointer, then we need to emit JCC instead. + if (!strcmp(esil->Reil->pc, dst->name)) { + ins->opcode = REIL_JCC; + rz_anal_esil_push (esil, "1:1"); + ins->arg[0] = reil_pop_arg (esil); + ins->arg[1] = R_NEW0 (RzAnalReilArg); + reil_make_arg (esil, ins->arg[1], " "); + ins->arg[2] = src; + reil_print_inst (esil, ins); + reil_free_inst (ins); + R_FREE (dst); + return true; + } + + reil_cast_size (esil, src, dst); + ins->opcode = REIL_STR; + ins->arg[0] = reil_pop_arg (esil); + if (!ins->arg[0]) { + R_FREE (dst); + reil_free_inst (ins); + return false; + } + + ins->arg[2] = dst; + ins->arg[1] = R_NEW0 (RzAnalReilArg); + reil_make_arg (esil, ins->arg[1], " "); + reil_print_inst (esil, ins); + reil_free_inst (ins); + return true; +} + +// General function for operations that take 2 operands +static int reil_binop(RzAnalEsil *esil, RzAnalReilOpcode opcode) { + RzAnalReilInst *ins; + char tmp_buf[REGBUFSZ]; + ut8 dst_size; + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg(esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg(esil); + if (!op1) { + R_FREE (op2); + return false; + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op1); + R_FREE (op2); + return false; + } + ins->opcode = opcode; + ins->arg[0] = op2; + ins->arg[1] = op1; + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0(RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + get_next_temp_reg(esil, tmp_buf); + reil_make_arg(esil, ins->arg[2], tmp_buf); + // Choose the larger of the two sizes as the size of dst + dst_size = ins->arg[0]->size; + if (dst_size < ins->arg[1]->size) { + dst_size = ins->arg[1]->size; + } + // REIL_LT has a dst_size of 1. + if (opcode == REIL_LT) { + dst_size = 1; + } + ins->arg[2]->size = dst_size; + reil_print_inst(esil, ins); + reil_push_arg(esil, ins->arg[2]); + reil_free_inst(ins); + return true; +} + +// General function for operations which re-assign to dst. Example, addeq. +static int reil_bineqop(RzAnalEsil *esil, RzAnalReilOpcode opcode) { + int ret = 1; + RzAnalReilArg *op = reil_pop_arg(esil); + if (!op) { + return false; + } + + reil_push_arg(esil, op); + ret &= reil_binop(esil, opcode); + reil_push_arg(esil, op); + ret &= reil_eq(esil); + R_FREE(op); + return ret; +} + +static bool reil_add(RzAnalEsil *esil) { return reil_binop (esil, REIL_ADD); } +static bool reil_addeq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_ADD); } +static bool reil_mul(RzAnalEsil *esil) { return reil_binop (esil, REIL_MUL); } +static bool reil_muleq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_MUL); } +static bool reil_sub(RzAnalEsil *esil) { return reil_binop (esil, REIL_SUB); } +static bool reil_subeq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_SUB); } +static bool reil_div(RzAnalEsil *esil) { return reil_binop (esil, REIL_DIV); } +static bool reil_diveq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_DIV); } +static bool reil_xor(RzAnalEsil *esil) { return reil_binop (esil, REIL_XOR); } +static bool reil_xoreq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_XOR); } +static bool reil_and(RzAnalEsil *esil) { return reil_binop (esil, REIL_AND); } +static bool reil_andeq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_AND); } +static bool reil_or(RzAnalEsil *esil) { return reil_binop (esil, REIL_OR); } +static bool reil_oreq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_OR); } +static bool reil_lsl(RzAnalEsil *esil) { return reil_binop (esil, REIL_SHL); } +static bool reil_lsleq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_SHL); } +static bool reil_lsr(RzAnalEsil *esil) { return reil_binop (esil, REIL_SHR); } +static bool reil_lsreq(RzAnalEsil *esil) { return reil_bineqop (esil, REIL_SHR); } +static bool reil_smaller(RzAnalEsil *esil) { return reil_binop (esil, REIL_LT); } + +static bool reil_cmp(RzAnalEsil *esil) { + RzAnalReilInst *ins; + char tmp_buf[REGBUFSZ]; + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg (esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg (esil); + if (!op1) { + R_FREE (op2); + return false; + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op1); + R_FREE (op2); + return false; + } + ins->opcode = REIL_EQ; + ins->arg[0] = op2; + ins->arg[1] = op1; + ins->arg[2] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = 1; + reil_print_inst (esil, ins); + // Set vars needed to determine flags. + rz_snprintf (esil->Reil->cur, sizeof (esil->Reil->old) - 1, "%s:%d", + ins->arg[2]->name, ins->arg[2]->size); + rz_snprintf (esil->Reil->old, sizeof (esil->Reil->cur) - 1, "%s:%d", + op2->name, op2->size); + if (rz_reg_get (esil->anal->reg, op2->name, -1)) { + esil->Reil->lastsz = op2->size; + } else if (rz_reg_get (esil->anal->reg, op1->name, -1)) { + esil->Reil->lastsz = op1->size; + } + reil_push_arg (esil, ins->arg[2]); + reil_free_inst (ins); + return true; +} + +static bool reil_smaller_equal(RzAnalEsil *esil) { + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg(esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg(esil); + if (!op1) { + R_FREE (op2); + return false; + } + + reil_push_arg(esil, op1); + reil_push_arg(esil, op2); + reil_smaller(esil); + reil_push_arg(esil, op1); + reil_push_arg(esil, op2); + reil_cmp(esil); + reil_or(esil); + + R_FREE(op1); + R_FREE(op2); + return true; +} + +static bool reil_larger(RzAnalEsil *esil) { + RzAnalReilArg *op2 = reil_pop_arg(esil); + if (!op2) { + return false; + } + RzAnalReilArg *op1 = reil_pop_arg(esil); + if (!op1) { + R_FREE (op2); + return false; + } + reil_push_arg (esil, op2); + reil_push_arg (esil, op1); + reil_smaller (esil); + R_FREE (op1); + R_FREE (op2); + return true; +} + +static bool reil_larger_equal(RzAnalEsil *esil) { + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg(esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg(esil); + if (!op1) { + R_FREE (op2); + return false; + } + + reil_push_arg (esil, op2); + reil_push_arg (esil, op1); + reil_smaller_equal (esil); + R_FREE (op1); + R_FREE (op2); + return true; +} + +static bool reil_dec(RzAnalEsil *esil) { + RzAnalReilArg *op = reil_pop_arg(esil); + if (!op) { + return false; + } + rz_anal_esil_pushnum (esil, 1); + reil_push_arg (esil, op); + reil_sub (esil); + R_FREE (op); + return true; +} + +static bool reil_deceq(RzAnalEsil *esil) { + RzAnalReilArg *op1 = reil_pop_arg(esil); + if (!op1) { + return false; + } + reil_push_arg (esil, op1); + reil_dec (esil); + reil_push_arg (esil, op1); + reil_eq (esil); + R_FREE (op1); + return true; +} + +static bool reil_inc(RzAnalEsil *esil) { + RzAnalReilArg *op = reil_pop_arg(esil); + if (!op) { + return false; + } + + rz_anal_esil_pushnum(esil, 1); + reil_push_arg(esil, op); + reil_add(esil); + R_FREE(op); + return true; +} + +static bool reil_inceq(RzAnalEsil *esil) { + RzAnalReilArg *op = reil_pop_arg(esil); + if (!op) { + return false; + } + reil_push_arg (esil, op); + reil_inc (esil); + reil_push_arg (esil, op); + reil_eq (esil); + R_FREE (op); + return true; +} + +static bool reil_neg(RzAnalEsil *esil) { + char tmp_buf[REGBUFSZ]; + RzAnalReilInst *ins; + RzAnalReilArg *op = reil_pop_arg (esil); + if (!op) { + return false; + } + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op); + return false; + } + ins->opcode = REIL_EQ; + ins->arg[0] = op; + rz_anal_esil_pushnum (esil, 0); + ins->arg[1] = reil_pop_arg(esil); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + get_next_temp_reg (esil, tmp_buf); + reil_make_arg(esil, ins->arg[2], tmp_buf); + if (ins->arg[0]->size < ins->arg[1]->size) { + ins->arg[1]->size = ins->arg[0]->size; + } + + ins->arg[2]->size = 1; + reil_print_inst (esil, ins); + reil_push_arg (esil, ins->arg[2]); + reil_free_inst (ins); + return true; +} + +static bool reil_negeq(RzAnalEsil *esil) { + RzAnalReilArg *op = reil_pop_arg(esil); + if (!op) { + return false; + } + reil_push_arg (esil, op); + reil_neg (esil); + reil_push_arg (esil, op); + reil_eq (esil); + free (op); + return true; +} + +static bool reil_not(RzAnalEsil *esil) { + char tmp_buf[REGBUFSZ]; + RzAnalReilInst *ins; + RzAnalReilArg *op = reil_pop_arg (esil); + if (!op) { + return false; + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op); + return false; + } + ins->opcode = REIL_NOT; + ins->arg[0] = op; + ins->arg[1] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + reil_make_arg (esil, ins->arg[1], " "); + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = ins->arg[0]->size; + reil_print_inst (esil, ins); + reil_push_arg (esil, ins->arg[2]); + reil_free_inst (ins); + return true; +} + +static bool reil_if(RzAnalEsil *esil) { + RzAnalReilInst *ins; + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg (esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg (esil); + if (!op1) { + R_FREE (op2); + return false; + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op2); + R_FREE (op1); + return false; + } + ins->opcode = REIL_JCC; + ins->arg[0] = op1; + ins->arg[2] = op2; + ins->arg[1] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + reil_make_arg (esil, ins->arg[1], " "); + reil_print_inst (esil, ins); + reil_free_inst (ins); + return true; +} + +static bool reil_if_end(RzAnalEsil *esil) { return true; } + +static bool reil_peek(RzAnalEsil *esil) { + RzAnalReilInst *ins; + char tmp_buf[REGBUFSZ]; + RzAnalReilArg *op1 = reil_pop_arg(esil); + if (!op1) { + return false; + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op1); + return false; + } + ins->opcode = REIL_LDM; + ins->arg[0] = op1; + ins->arg[1] = R_NEW0(RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0(RzAnalReilArg); + if (!ins->arg[2]) { + reil_free_inst (ins); + return false; + } + reil_make_arg(esil, ins->arg[1], " "); + get_next_temp_reg(esil, tmp_buf); + reil_make_arg(esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = ins->arg[0]->size; + reil_print_inst(esil, ins); + reil_push_arg(esil, ins->arg[2]); + reil_free_inst(ins); + return true; +} + +// n = 8, 4, 2, 1 +static bool reil_peekn(RzAnalEsil *esil, ut8 n) { + RzAnalReilArg *op2; + RzAnalReilArg *op1 = reil_pop_arg (esil); + if (!op1) { + return false; + } + + reil_push_arg (esil, op1); + reil_peek (esil); + // No need to cast if n = 0 + if (n == 0) { + R_FREE (op1); + return true; + } + + R_FREE (op1); + op1 = reil_pop_arg (esil); + if (!op1) { + return false; + } + + op2 = R_NEW0 (RzAnalReilArg); + if (!op2) { + R_FREE (op1); + return false; + } + op2->size = n * 8; + op2->type = ARG_TEMP; + get_next_temp_reg (esil, op2->name); + reil_cast_size (esil, op1, op2); + esil->Reil->lastsz = 8 * n; + + R_FREE (op2); + return true; +} + +static bool reil_peek1(RzAnalEsil *esil) { return reil_peekn(esil, 1); } +static bool reil_peek2(RzAnalEsil *esil) { return reil_peekn(esil, 2); } +static bool reil_peek4(RzAnalEsil *esil) { return reil_peekn(esil, 4); } +static bool reil_peek8(RzAnalEsil *esil) { return reil_peekn(esil, 8); } + +// n = 8, 4, 2, 1 +static bool reil_poken(RzAnalEsil *esil, ut8 n) { + char tmp_buf[REGBUFSZ]; + RzAnalReilInst *ins; + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg (esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg (esil); + if (!op1) { + R_FREE (op2); + return false; + } + + if (op1->type != ARG_ESIL_INTERNAL) { + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + R_FREE (op2); + R_FREE (op1); + return false; + } + ins->opcode = REIL_LDM; + ins->arg[0] = op2; + ins->arg[1] = R_NEW0(RzAnalReilArg); + if (!ins->arg[1]) { + R_FREE (op1); + reil_free_inst (ins); + return false; + } + ins->arg[2] = R_NEW0(RzAnalReilArg); + if (!ins->arg[2]) { + R_FREE (op1); + reil_free_inst (ins); + return false; + } + reil_make_arg (esil, ins->arg[1], " "); + get_next_temp_reg (esil, tmp_buf); + reil_make_arg (esil, ins->arg[2], tmp_buf); + ins->arg[2]->size = ins->arg[0]->size; + reil_print_inst (esil, ins); + rz_snprintf (esil->Reil->old, sizeof (esil->Reil->old) - 1, "%s:%d", + ins->arg[2]->name, ins->arg[2]->size); + rz_snprintf (esil->Reil->cur, sizeof (esil->Reil->cur) - 1, "%s:%d", + op2->name, op2->size); + esil->lastsz = n * 8; + reil_push_arg (esil, op1); + reil_push_arg (esil, op2); + R_FREE (op1); + reil_free_inst (ins); + } else { + reil_flag_spew_inst (esil, op1->name + 1); + R_FREE (op1); + op1 = reil_pop_arg (esil); + reil_push_arg (esil, op2); + reil_push_arg (esil, op1); + R_FREE (op2); + R_FREE (op1); + } + + ins = R_NEW0 (RzAnalReilInst); + if (!ins) { + return false; + } + ins->opcode = REIL_STM; + ins->arg[2] = reil_pop_arg (esil); + ins->arg[0] = reil_pop_arg (esil); + ins->arg[1] = R_NEW0 (RzAnalReilArg); + if (!ins->arg[1]) { + reil_free_inst (ins); + return false; + } + reil_make_arg(esil, ins->arg[1], " "); + reil_print_inst(esil, ins); + reil_free_inst(ins); + return true; +} + +static bool reil_poke(RzAnalEsil *esil) { + return reil_poken (esil, esil->anal->bits / 8); +} + +static bool reil_poke1(RzAnalEsil *esil) { return reil_poken(esil, 1); } +static bool reil_poke2(RzAnalEsil *esil) { return reil_poken(esil, 2); } +static bool reil_poke4(RzAnalEsil *esil) { return reil_poken(esil, 4); } +static bool reil_poke8(RzAnalEsil *esil) { return reil_poken(esil, 8); } + +// Generic function to handle all mem_*eq_n functions. Example, mem_oreq_n +static bool reil_mem_bineq_n(RzAnalEsil *esil, RzAnalReilOpcode opcode, ut8 size) { + int ret = 1; + RzAnalReilArg *op2, *op1; + + op2 = reil_pop_arg (esil); + if (!op2) { + return false; + } + op1 = reil_pop_arg (esil); + if (!op1) { + R_FREE (op2); + return false; + } + + reil_push_arg(esil, op2); + ret &= reil_peekn(esil, size); + reil_push_arg(esil, op1); + ret &= reil_binop(esil, opcode); + reil_push_arg(esil, op2); + ret &= reil_poken(esil, size); + + free (op2); + free (op1); + return ret; +} + +static bool reil_mem_oreq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, esil->anal->bits / 8); } +static bool reil_mem_oreq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 1); } +static bool reil_mem_oreq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 2); } +static bool reil_mem_oreq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 4); } +static bool reil_mem_oreq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_OR, 8); } + +static bool reil_mem_andeq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, esil->anal->bits / 8); } +static bool reil_mem_andeq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 1); } +static bool reil_mem_andeq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 2); } +static bool reil_mem_andeq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 4); } +static bool reil_mem_andeq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_AND, 8); } + +static bool reil_mem_xoreq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, esil->anal->bits / 8); } +static bool reil_mem_xoreq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 1); } +static bool reil_mem_xoreq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 2); } +static bool reil_mem_xoreq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 4); } +static bool reil_mem_xoreq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_XOR, 8); } + +static bool reil_mem_addeq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, esil->anal->bits / 8); } +static bool reil_mem_addeq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 1); } +static bool reil_mem_addeq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 2); } +static bool reil_mem_addeq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 4); } +static bool reil_mem_addeq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_ADD, 8); } + +static bool reil_mem_subeq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, esil->anal->bits / 8); } +static bool reil_mem_subeq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 1); } +static bool reil_mem_subeq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 2); } +static bool reil_mem_subeq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 4); } +static bool reil_mem_subeq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_SUB, 8); } + +static bool reil_mem_muleq(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, esil->anal->bits / 8); } +static bool reil_mem_muleq1(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 1); } +static bool reil_mem_muleq2(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 2); } +static bool reil_mem_muleq4(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 4); } +static bool reil_mem_muleq8(RzAnalEsil *esil) { return reil_mem_bineq_n(esil, REIL_MUL, 8); } + +static bool reil_mem_inceq_n(RzAnalEsil *esil, ut8 size) { + int ret = 1; + RzAnalReilArg *op1 = reil_pop_arg(esil); + if (!op1) { + return false; + } + + rz_anal_esil_pushnum(esil, 1); + reil_push_arg(esil, op1); + ret &= reil_mem_bineq_n(esil, REIL_ADD, size); + + free (op1); + return ret; +} + +static bool reil_mem_inceq(RzAnalEsil *esil) { + return reil_mem_inceq_n(esil, esil->anal->bits / 8); +} +static bool reil_mem_inceq1(RzAnalEsil *esil) { return reil_mem_inceq_n(esil, 1); } +static bool reil_mem_inceq2(RzAnalEsil *esil) { return reil_mem_inceq_n(esil, 2); } +static bool reil_mem_inceq4(RzAnalEsil *esil) { return reil_mem_inceq_n(esil, 4); } +static bool reil_mem_inceq8(RzAnalEsil *esil) { return reil_mem_inceq_n(esil, 8); } + +static int reil_mem_deceq_n(RzAnalEsil *esil, ut8 size) { + int ret = 1; + RzAnalReilArg *op1 = reil_pop_arg(esil); + if (!op1) { + return false; + } + + rz_anal_esil_pushnum(esil, 1); + reil_push_arg(esil, op1); + ret &= reil_mem_bineq_n(esil, REIL_SUB, size); + + free (op1); + return ret; +} + +static bool reil_mem_deceq(RzAnalEsil *esil) { + return reil_mem_deceq_n(esil, esil->anal->bits / 8); +} +static bool reil_mem_deceq1(RzAnalEsil *esil) { return reil_mem_deceq_n(esil, 1); } +static bool reil_mem_deceq2(RzAnalEsil *esil) { return reil_mem_deceq_n(esil, 2); } +static bool reil_mem_deceq4(RzAnalEsil *esil) { return reil_mem_deceq_n(esil, 4); } +static bool reil_mem_deceq8(RzAnalEsil *esil) { return reil_mem_deceq_n(esil, 8); } + +// Functions to resolve internal vars. +// performs (2 << op) - 1 +void reil_generate_mask(RzAnalEsil *esil) { + rz_anal_esil_pushnum(esil, 2); + reil_lsl(esil); + reil_dec(esil); +} + +void reil_generate_borrow_flag(RzAnalEsil *esil, ut8 bit) { + RzAnalReilArg *op1; + + rz_anal_esil_pushnum(esil, bit); + rz_anal_esil_pushnum(esil, 0x3f); + reil_and(esil); + rz_anal_esil_pushnum(esil, 0x3f); + reil_add(esil); + rz_anal_esil_pushnum(esil, 0x3f); + reil_and(esil); + // Generate the mask. 2 << bits - 1 + reil_generate_mask(esil); + op1 = reil_pop_arg(esil); + // old & mask + rz_anal_esil_push(esil, esil->Reil->old); + reil_push_arg(esil, op1); + reil_and(esil); + // cur & mask + rz_anal_esil_push(esil, esil->Reil->cur); + reil_push_arg(esil, op1); + reil_and(esil); + // Check + reil_larger(esil); + + free (op1); +} + +void reil_generate_carry_flag(RzAnalEsil *esil, ut8 bit) { + RzAnalReilArg *op1; + + rz_anal_esil_pushnum(esil, bit); + rz_anal_esil_pushnum(esil, 0x3f); + reil_and(esil); + // Generate the mask. 2 << bits - 1 + reil_generate_mask(esil); + op1 = reil_pop_arg(esil); + // old & mask + rz_anal_esil_push(esil, esil->Reil->old); + reil_push_arg(esil, op1); + reil_and(esil); + // cur & mask + rz_anal_esil_push(esil, esil->Reil->cur); + reil_push_arg(esil, op1); + reil_and(esil); + // Check + reil_smaller(esil); + + free (op1); +} + +void reil_generate_partity_flag(RzAnalEsil *esil) { + // Generation of parity flag taken from openreil README example. + RzAnalReilArg *op; + rz_anal_esil_push(esil, esil->Reil->cur); + rz_anal_esil_pushnum(esil, 0xff); + reil_and(esil); + op = reil_pop_arg(esil); + if (!op) { + return; + } + + rz_anal_esil_pushnum(esil, 7); + reil_push_arg(esil, op); + reil_lsr(esil); + rz_anal_esil_pushnum(esil, 6); + reil_push_arg(esil, op); + reil_lsr(esil); + reil_xor(esil); + rz_anal_esil_pushnum(esil, 5); + reil_push_arg(esil, op); + reil_lsr(esil); + rz_anal_esil_pushnum(esil, 4); + reil_push_arg(esil, op); + reil_lsr(esil); + reil_xor(esil); + reil_xor(esil); + rz_anal_esil_pushnum(esil, 3); + reil_push_arg(esil, op); + reil_lsr(esil); + rz_anal_esil_pushnum(esil, 2); + reil_push_arg(esil, op); + reil_lsr(esil); + reil_xor(esil); + rz_anal_esil_pushnum(esil, 1); + reil_push_arg(esil, op); + reil_lsr(esil); + reil_push_arg(esil, op); + reil_xor(esil); + reil_xor(esil); + reil_xor(esil); + rz_anal_esil_pushnum(esil, 1); + reil_and(esil); + reil_not(esil); + + free (op); +} + +void reil_generate_signature(RzAnalEsil *esil) { + if (!esil->Reil->lastsz || esil->Reil->lastsz == 0) { + rz_anal_esil_pushnum(esil, 0); + return; + } + + RzAnalReilArg *op; + + rz_anal_esil_pushnum(esil, esil->Reil->lastsz - 1); + rz_anal_esil_pushnum(esil, 1); + reil_lsl(esil); + rz_anal_esil_push(esil, esil->Reil->cur); + reil_and(esil); + + op = reil_pop_arg(esil); + if (!op) { + return; + } + + rz_anal_esil_pushnum(esil, esil->Reil->lastsz - 1); + reil_push_arg(esil, op); + reil_lsr(esil); + + free (op); +} + +void reil_generate_overflow_flag(RzAnalEsil *esil) { + if (esil->Reil->lastsz < 2) { + rz_anal_esil_pushnum (esil, 0); + } + + reil_generate_borrow_flag(esil, esil->Reil->lastsz); + reil_generate_carry_flag(esil, esil->Reil->lastsz - 2); + reil_xor(esil); +} + +void reil_flag_spew_inst(RzAnalEsil *esil, const char *flag) { + ut8 bit; + switch (flag[0]) { + case 'z': // zero-flag + rz_anal_esil_push(esil, esil->Reil->cur); + break; + case 'b': + bit = (ut8)rz_num_get(NULL, &flag[1]); + reil_generate_borrow_flag(esil, bit); + break; + case 'c': + bit = (ut8)rz_num_get(NULL, &flag[1]); + reil_generate_carry_flag(esil, bit); + break; + case 'o': + reil_generate_overflow_flag(esil); + break; + case 'p': + reil_generate_partity_flag(esil); + break; + case 'r': + rz_anal_esil_pushnum(esil, esil->anal->bits / 8); + break; + case 's': + reil_generate_signature(esil); + break; + default: + return; + } + + return; +} + +/* Callback hook for command_hook */ +static int setup_reil_ins(RzAnalEsil *esil, const char *op) { + esil->Reil->addr++; // Increment the address location. + esil->Reil->seq_num = 0; // Reset the sequencing. + return 0; +} + +RZ_API int rz_anal_esil_to_reil_setup(RzAnalEsil *esil, RzAnal *anal, int romem, + int stats) { + if (!esil) { + return false; + } + esil->verbose = 2; + esil->anal = anal; + esil->trap = 0; + esil->trap_code = 0; + + /* Set up a callback for hook_command */ + esil->cb.hook_command = setup_reil_ins; + + esil->Reil = R_NEW0(RzAnalReil); + if (!esil->Reil) { + return false; + } + esil->Reil->reilNextTemp = 0; + esil->Reil->addr = -1; + esil->Reil->seq_num = 0; + esil->Reil->skip = 0; + + // Store the pc + const char *name = rz_reg_get_name (esil->anal->reg, rz_reg_get_name_idx ("PC")); + strncpy (esil->Reil->pc, name, sizeof (esil->Reil->pc) - 1); + + rz_anal_esil_mem_ro(esil, romem); + +#define OT_UNK R_ANAL_ESIL_OP_TYPE_UNKNOWN +#define OT_CTR R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW +#define OT_MATH R_ANAL_ESIL_OP_TYPE_MATH +#define OT_REGW R_ANAL_ESIL_OP_TYPE_REG_WRITE +#define OT_MEMW R_ANAL_ESIL_OP_TYPE_MEM_WRITE +#define OT_MEMR R_ANAL_ESIL_OP_TYPE_MEM_READ + + rz_anal_esil_set_op(esil, "=", reil_eq, 0, 2, OT_REGW); + rz_anal_esil_set_op(esil, ":=", reil_eq, 0, 2, OT_REGW); + rz_anal_esil_set_op(esil, "+", reil_add, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "+=", reil_addeq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "-", reil_sub, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "-=", reil_subeq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "*", reil_mul, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "*=", reil_muleq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "/", reil_div, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "/=", reil_diveq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "^", reil_xor, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "^=", reil_xoreq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "|", reil_or, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "|=", reil_oreq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "&", reil_and, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "&=", reil_andeq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "<<", reil_lsl, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "<<=", reil_lsleq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, ">>", reil_lsr, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, ">>=", reil_lsreq, 0, 2, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "++=", reil_inceq, 0, 1, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "++", reil_inc, 1, 1, OT_MATH); + rz_anal_esil_set_op(esil, "--=", reil_deceq, 0, 1, OT_MATH | OT_REGW); + rz_anal_esil_set_op(esil, "--", reil_dec, 1, 1, OT_MATH); + rz_anal_esil_set_op(esil, "!", reil_neg, 1, 1, OT_MATH); + rz_anal_esil_set_op(esil, "!=", reil_negeq, 0, 1, OT_MATH); + rz_anal_esil_set_op(esil, "==", reil_cmp, 0, 2, OT_MATH); + rz_anal_esil_set_op(esil, "<", reil_smaller, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, ">", reil_larger, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "<=", reil_smaller_equal, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, ">=", reil_larger_equal, 1, 2, OT_MATH); + rz_anal_esil_set_op(esil, "[]", reil_peek, 1, 1, OT_MEMR); + rz_anal_esil_set_op(esil, "=[]", reil_poke, 0, 2, OT_MEMW); + rz_anal_esil_set_op(esil, "|=[]", reil_mem_oreq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "^=[]", reil_mem_xoreq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "&=[]", reil_mem_andeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "+=[]", reil_mem_addeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "-=[]", reil_mem_subeq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "*=[]", reil_mem_muleq, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "++=[]", reil_mem_inceq, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "--=[]", reil_mem_deceq, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "=[1]", reil_poke1, 0, 2, OT_MEMW); + rz_anal_esil_set_op(esil, "=[2]", reil_poke2, 0, 2, OT_MEMW); + rz_anal_esil_set_op(esil, "=[4]", reil_poke4, 0, 2, OT_MEMW); + rz_anal_esil_set_op(esil, "=[8]", reil_poke8, 0, 2, OT_MEMW); + rz_anal_esil_set_op(esil, "[1]", reil_peek1, 1, 1, OT_MEMR); + rz_anal_esil_set_op(esil, "[2]", reil_peek2, 1, 1, OT_MEMR); + rz_anal_esil_set_op(esil, "[4]", reil_peek4, 1, 1, OT_MEMR); + rz_anal_esil_set_op(esil, "[8]", reil_peek8, 1, 1, OT_MEMR); + rz_anal_esil_set_op(esil, "|=[1]", reil_mem_oreq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "|=[2]", reil_mem_oreq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "|=[4]", reil_mem_oreq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "|=[8]", reil_mem_oreq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "^=[1]", reil_mem_xoreq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "^=[2]", reil_mem_xoreq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "^=[4]", reil_mem_xoreq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "^=[8]", reil_mem_xoreq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "&=[1]", reil_mem_andeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "&=[2]", reil_mem_andeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "&=[4]", reil_mem_andeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "&=[8]", reil_mem_andeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "+=[1]", reil_mem_addeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "+=[2]", reil_mem_addeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "+=[4]", reil_mem_addeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "+=[8]", reil_mem_addeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "-=[1]", reil_mem_subeq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "-=[2]", reil_mem_subeq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "-=[4]", reil_mem_subeq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "-=[8]", reil_mem_subeq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "*=[1]", reil_mem_muleq1, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "*=[2]", reil_mem_muleq2, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "*=[4]", reil_mem_muleq4, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "*=[8]", reil_mem_muleq8, 0, 2, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "++=[1]", reil_mem_inceq1, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "++=[2]", reil_mem_inceq2, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "++=[4]", reil_mem_inceq4, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "++=[8]", reil_mem_inceq8, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "--=[1]", reil_mem_deceq1, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "--=[2]", reil_mem_deceq2, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "--=[4]", reil_mem_deceq4, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "--=[8]", reil_mem_deceq8, 0, 1, OT_MATH | OT_MEMR | OT_MEMW); + rz_anal_esil_set_op(esil, "?{", reil_if, 0, 1, OT_CTR); + rz_anal_esil_set_op(esil, "}", reil_if_end, 0, 0, OT_CTR); + + return true; +} diff --git a/libr/anal/esil_cfg.c b/librz/anal/esil_cfg.c similarity index 61% rename from libr/anal/esil_cfg.c rename to librz/anal/esil_cfg.c index ae17dd6912..1b25483bc7 100644 --- a/libr/anal/esil_cfg.c +++ b/librz/anal/esil_cfg.c @@ -1,11 +1,11 @@ -#include -#include -#include +#include +#include +#include /* shared internal state of the subgraph generating functions */ typedef struct esil_cfg_generator_t { - RAnalEsil *esil; + RzAnalEsil *esil; union { RStack *ifelse; RStack *vals; @@ -13,13 +13,13 @@ typedef struct esil_cfg_generator_t { // union for semantic purposes RContRBTree *blocks; // consider moving this to cfg? well, yes and no. - // making Graph nodes fast available in RAnalEsilCFG is great idea + // making Graph nodes fast available in RzAnalEsilCFG is great idea // A balanced tree is only best solution, if we want to store and lookup intervals // We need to look for intervals, so that we can resolve goto destinations INSIDE of a cpu-instruction // After an instruction got graphed, we only need their entry node (nodes with first == {xxx, 0 }) // So after graphing an instruction, the blocks-tree should be cleared (don't free the content) // and nodes with first == {xxx, 0} should be stored in an sdb or similar in cfg, with xxx as key - RAnalEsilCFG *cfg; + RzAnalEsilCFG *cfg; RGraphNode *cur; // current graph-node, so that I don't have to abuse cfg->start RIDStorage *atoms; @@ -70,8 +70,8 @@ static char *condrets_strtok(char *str, const char tok) { return NULL; } -RAnalEsilOp *esil_get_op (RAnalEsil *esil, const char *op) { - r_return_val_if_fail (R_STR_ISNOTEMPTY (op) && esil && esil->ops, NULL); +RzAnalEsilOp *esil_get_op (RzAnalEsil *esil, const char *op) { + rz_return_val_if_fail (R_STR_ISNOTEMPTY (op) && esil && esil->ops, NULL); return ht_pp_find (esil->ops, op, NULL); } @@ -79,28 +79,28 @@ RAnalEsilOp *esil_get_op (RAnalEsil *esil, const char *op) { static void esil_expr_atomize(RIDStorage *atoms, char *expr) { ut32 forget_me; for ( - ; !!expr && r_id_storage_add (atoms, expr, &forget_me); + ; !!expr && rz_id_storage_add (atoms, expr, &forget_me); expr = condrets_strtok (expr, ',')) { } } static void _free_bb_cb(void *data) { - RAnalEsilBB *bb = (RAnalEsilBB *)data; + RzAnalEsilBB *bb = (RzAnalEsilBB *)data; free (bb->expr); free (bb); } // REMINDER: generating the block content needs to prepend setting the program counter -// r_anal_esil_cfg_op does this ^, use it whenever generating cfg from op +// rz_anal_esil_cfg_op does this ^, use it whenever generating cfg from op -// this nasty function is an insert-compare for RGraphNodes that contain RAnalEsilBB +// this nasty function is an insert-compare for RGraphNodes that contain RzAnalEsilBB static int _graphnode_esilbb_insert_cmp(void *incoming, void *in, void *user) { RGraphNode *incoming_gnode = (RGraphNode *)incoming; RGraphNode *in_gnode = (RGraphNode *)in; - RAnalEsilBB *incoming_bb = (RAnalEsilBB *)incoming_gnode->data; - RAnalEsilBB *in_bb = (RAnalEsilBB *)in_gnode->data; + RzAnalEsilBB *incoming_bb = (RzAnalEsilBB *)incoming_gnode->data; + RzAnalEsilBB *in_bb = (RzAnalEsilBB *)in_gnode->data; - // RAnalEsilBBs have the nice property, that they cannot intersect, + // RzAnalEsilBBs have the nice property, that they cannot intersect, // so just comparing first and first should be fine for inserting #if 0 return incoming_bb->first - in_bb->first; @@ -118,9 +118,9 @@ static int _graphnode_esilbb_insert_cmp(void *incoming, void *in, void *user) { } static int _graphnode_esilbb_find_cmp(void *incoming, void *in, void *user) { - RAnalEsilEOffset *find_me = (RAnalEsilEOffset *)incoming; + RzAnalEsilEOffset *find_me = (RzAnalEsilEOffset *)incoming; RGraphNode *in_gnode = (RGraphNode *)in; - RAnalEsilBB *in_bb = (RAnalEsilBB *)in_gnode->data; + RzAnalEsilBB *in_bb = (RzAnalEsilBB *)in_gnode->data; // not sure if this is needed that way if (find_me->off < in_bb->first.off) { return -1; @@ -140,11 +140,11 @@ static int _graphnode_esilbb_find_cmp(void *incoming, void *in, void *user) { static int _graphnode_delete_always_0_cmp(void *incoming, void *in, void *user) { EsilCfgGen *gen = (EsilCfgGen *)user; RGraphNode *delete_me = (RGraphNode *)in; - RAnalEsilBB *delete_me_bb = (RAnalEsilBB *)delete_me->data; - r_graph_del_node (gen->cfg->g, delete_me); + RzAnalEsilBB *delete_me_bb = (RzAnalEsilBB *)delete_me->data; + rz_graph_del_node (gen->cfg->g, delete_me); ut32 id; for (id = delete_me_bb->first.idx; id <= delete_me_bb->last.idx; id++) { - r_id_storage_delete (gen->atoms, id); + rz_id_storage_delete (gen->atoms, id); } return 0; } @@ -157,55 +157,55 @@ void _handle_if_enter (EsilCfgGen *gen, ut32 id, const bool has_next) { EsilCfgScopeCookie *cookie = R_NEW0 (EsilCfgScopeCookie); // get current bb - // RAnalEsilBB *bb = (RAnalEsilBB *)gen->cur->data; + // RzAnalEsilBB *bb = (RzAnalEsilBB *)gen->cur->data; // create if-enter-bb - RAnalEsilBB *entered_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *entered_bb = R_NEW0 (RzAnalEsilBB); entered_bb->first.off = entered_bb->last.off = gen->off; entered_bb->first.idx = entered_bb->last.idx = id + 1; entered_bb->enter = R_ANAL_ESIL_BLOCK_ENTER_TRUE; // create if-entered-graph-node - RGraphNode *entered_node = r_graph_add_node (gen->cfg->g, entered_bb); + RGraphNode *entered_node = rz_graph_add_node (gen->cfg->g, entered_bb); entered_node->free = _free_bb_cb; - r_rbtree_cont_insert (gen->blocks, entered_node, _graphnode_esilbb_insert_cmp, NULL); + rz_rbtree_cont_insert (gen->blocks, entered_node, _graphnode_esilbb_insert_cmp, NULL); // add edge from entering node to entered node - r_graph_add_edge (gen->cfg->g, gen->cur, entered_node); + rz_graph_add_edge (gen->cfg->g, gen->cur, entered_node); // push scope-cookie cookie->if_block = entered_node; cookie->else_block = gen->cur; - r_stack_push (gen->ifelse, cookie); + rz_stack_push (gen->ifelse, cookie); gen->cur = entered_node; } void _handle_else_enter (EsilCfgGen *gen, ut32 id, const bool has_next) { - if (!has_next || r_stack_is_empty (gen->ifelse)) { + if (!has_next || rz_stack_is_empty (gen->ifelse)) { // no cookie no todo return; } - EsilCfgScopeCookie *cookie = (EsilCfgScopeCookie *)r_stack_peek (gen->ifelse); + EsilCfgScopeCookie *cookie = (EsilCfgScopeCookie *)rz_stack_peek (gen->ifelse); // create if-enter-bb - RAnalEsilBB *entered_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *entered_bb = R_NEW0 (RzAnalEsilBB); entered_bb->first.off = entered_bb->last.off = gen->off; entered_bb->first.idx = entered_bb->last.idx = id + 1; // create if-entered-graph-node - RGraphNode *entered_node = r_graph_add_node (gen->cfg->g, entered_bb); + RGraphNode *entered_node = rz_graph_add_node (gen->cfg->g, entered_bb); entered_node->free = _free_bb_cb; - r_rbtree_cont_insert (gen->blocks, entered_node, _graphnode_esilbb_insert_cmp, NULL); + rz_rbtree_cont_insert (gen->blocks, entered_node, _graphnode_esilbb_insert_cmp, NULL); if (cookie->is_else) { entered_bb->enter = R_ANAL_ESIL_BLOCK_ENTER_TRUE; - r_graph_add_edge (gen->cfg->g, cookie->if_block, entered_node); + rz_graph_add_edge (gen->cfg->g, cookie->if_block, entered_node); cookie->if_block = entered_node; cookie->else_block = gen->cur; cookie->is_else = false; } else { entered_bb->enter = R_ANAL_ESIL_BLOCK_ENTER_FALSE; - r_graph_add_edge (gen->cfg->g, cookie->else_block, entered_node); + rz_graph_add_edge (gen->cfg->g, cookie->else_block, entered_node); cookie->else_block = entered_node; cookie->if_block = gen->cur; cookie->is_else = true; @@ -214,28 +214,28 @@ void _handle_else_enter (EsilCfgGen *gen, ut32 id, const bool has_next) { } void _handle_fi_leave (EsilCfgGen *gen, ut32 id, const bool has_next) { - EsilCfgScopeCookie *cookie = r_stack_pop (gen->ifelse); + EsilCfgScopeCookie *cookie = rz_stack_pop (gen->ifelse); if (!cookie) { // no if, no fi todo return; } - RAnalEsilBB *cur_bb = (RAnalEsilBB *)gen->cur->data; + RzAnalEsilBB *cur_bb = (RzAnalEsilBB *)gen->cur->data; // this block is not executed when the if or else block is empty - if (memcmp (&cur_bb->first, &cur_bb->last, sizeof (RAnalEsilEOffset))) { + if (memcmp (&cur_bb->first, &cur_bb->last, sizeof (RzAnalEsilEOffset))) { // TODO: add some thoughts in comments here cur_bb->last.idx--; - RAnalEsilBB *leaving_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *leaving_bb = R_NEW0 (RzAnalEsilBB); leaving_bb->first.off = leaving_bb->last.off = gen->off; leaving_bb->first.idx = leaving_bb->last.idx = id; - RGraphNode *leaving_node = r_graph_add_node (gen->cfg->g, leaving_bb); + RGraphNode *leaving_node = rz_graph_add_node (gen->cfg->g, leaving_bb); leaving_node->free = _free_bb_cb; - r_graph_add_edge (gen->cfg->g, gen->cur, leaving_node); - r_rbtree_cont_insert (gen->blocks, leaving_node, _graphnode_esilbb_insert_cmp, NULL); + rz_graph_add_edge (gen->cfg->g, gen->cur, leaving_node); + rz_rbtree_cont_insert (gen->blocks, leaving_node, _graphnode_esilbb_insert_cmp, NULL); gen->cur = leaving_node; cur_bb = leaving_bb; } - r_graph_add_edge (gen->cfg->g, cookie->is_else ? cookie->if_block : cookie->else_block, gen->cur); + rz_graph_add_edge (gen->cfg->g, cookie->is_else ? cookie->if_block : cookie->else_block, gen->cur); free (cookie); } @@ -245,15 +245,15 @@ void _handle_control_flow_ifelsefi (EsilCfgGen *gen, char *atom, ut32 id) { // we're probably going to see more ?{ and }, than }{ // so checking against ?{ and } befor }{ is therefor better for perf (lololol) if (!strcmp (atom, "?{")) { - _handle_if_enter (gen, id, !!r_id_storage_get (gen->atoms, id + 1)); + _handle_if_enter (gen, id, !!rz_id_storage_get (gen->atoms, id + 1)); return; } if (!strcmp (atom, "}")) { - _handle_fi_leave (gen, id, !!r_id_storage_get (gen->atoms, id + 1)); + _handle_fi_leave (gen, id, !!rz_id_storage_get (gen->atoms, id + 1)); return; } if (!strcmp (atom, "}{")) { - _handle_else_enter (gen, id, !!r_id_storage_get (gen->atoms, id + 1)); + _handle_else_enter (gen, id, !!rz_id_storage_get (gen->atoms, id + 1)); } } @@ -262,8 +262,8 @@ void _handle_control_flow_ifelsefi (EsilCfgGen *gen, char *atom, ut32 id) { bool _round_0_cb (void *user, void *data, ut32 id) { EsilCfgGen *gen = (EsilCfgGen *)user; char *atom = (char *)data; - RAnalEsilBB *bb = (RAnalEsilBB *)gen->cur->data; - RAnalEsilOp *op = esil_get_op (gen->esil, atom); + RzAnalEsilBB *bb = (RzAnalEsilBB *)gen->cur->data; + RzAnalEsilOp *op = esil_get_op (gen->esil, atom); bb->last.idx = (ut16)id; if (op && op->type == R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW) { _handle_control_flow_ifelsefi (gen, atom, id); @@ -272,38 +272,38 @@ bool _round_0_cb (void *user, void *data, ut32 id) { } RGraphNode *_common_break_goto (EsilCfgGen *gen, ut32 id) { - RAnalEsilEOffset off = { gen->off, (ut16)id }; - RGraphNode *gnode = r_rbtree_cont_find (gen->blocks, &off, _graphnode_esilbb_find_cmp, NULL); - RAnalEsilBB *bb = (RAnalEsilBB *)gnode->data; + RzAnalEsilEOffset off = { gen->off, (ut16)id }; + RGraphNode *gnode = rz_rbtree_cont_find (gen->blocks, &off, _graphnode_esilbb_find_cmp, NULL); + RzAnalEsilBB *bb = (RzAnalEsilBB *)gnode->data; if (id != bb->last.idx) { - RAnalEsilBB *next_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *next_bb = R_NEW0 (RzAnalEsilBB); // split blocks next_bb->first.off = gen->off; next_bb->first.idx = id + 1; next_bb->last = bb->last; bb->last.idx = id; - RGraphNode *next_gnode = r_graph_node_split_forward (gen->cfg->g, gnode, next_bb); + RGraphNode *next_gnode = rz_graph_node_split_forward (gen->cfg->g, gnode, next_bb); // TODO: implement node_split in graph api - r_rbtree_cont_insert (gen->blocks, next_gnode, _graphnode_esilbb_insert_cmp, NULL); + rz_rbtree_cont_insert (gen->blocks, next_gnode, _graphnode_esilbb_insert_cmp, NULL); } else { - RListIter *iter, *ator; + RzListIter *iter, *ator; RGraphNode *node; // TODO: improve perf here - r_list_foreach_safe (gnode->out_nodes, iter, ator, node) { - r_graph_del_edge (gen->cfg->g, gnode, node); + rz_list_foreach_safe (gnode->out_nodes, iter, ator, node) { + rz_graph_del_edge (gen->cfg->g, gnode, node); } } return gnode; - // r_graph_add_edge(gen->cfg->g, gnode, gen->cfg->end); + // rz_graph_add_edge(gen->cfg->g, gnode, gen->cfg->end); } void _handle_break (EsilCfgGen *gen, ut32 id) { - r_graph_add_edge (gen->cfg->g, _common_break_goto (gen, id), gen->cfg->end); + rz_graph_add_edge (gen->cfg->g, _common_break_goto (gen, id), gen->cfg->end); } void _handle_goto (EsilCfgGen *gen, ut32 idx) { RGraphNode *gnode = _common_break_goto (gen, idx); - RAnalEsilBB *bb = (RAnalEsilBB *)gnode->data; + RzAnalEsilBB *bb = (RzAnalEsilBB *)gnode->data; // so what we're doing here is emulating this block with a certain degree of abstraction: // no reg-access // no io-access @@ -318,30 +318,30 @@ void _handle_goto (EsilCfgGen *gen, ut32 idx) { ut16 id; // bb->last.idx is the GOTO operation itself, we do not reach this in the loop for (id = bb->first.idx; id < bb->last.idx; id++) { - char *atom = (char *)r_id_storage_get (gen->atoms, (ut32)id); - RAnalEsilOp *op = esil_get_op (gen->esil, atom); + char *atom = (char *)rz_id_storage_get (gen->atoms, (ut32)id); + RzAnalEsilOp *op = esil_get_op (gen->esil, atom); if (op) { ut32 j; for (j = 0; j < op->pop; j++) { - free (r_stack_pop (gen->vals)); + free (rz_stack_pop (gen->vals)); } for (j = 0; j < op->push; j++) { EsilVal *val = R_NEW (EsilVal); val->type = ESIL_VAL_RESULT; - r_stack_push (gen->vals, val); + rz_stack_push (gen->vals, val); } } else { EsilVal *val = R_NEW (EsilVal); - if (r_reg_get (gen->esil->anal->reg, atom, -1)) { + if (rz_reg_get (gen->esil->anal->reg, atom, -1)) { val->type = ESIL_VAL_REG; } else { val->type = ESIL_VAL_CONST; - val->val = r_num_get (NULL, atom); + val->val = rz_num_get (NULL, atom); } - r_stack_push (gen->vals, val); + rz_stack_push (gen->vals, val); } } - EsilVal *v = r_stack_pop (gen->vals); + EsilVal *v = rz_stack_pop (gen->vals); if (!v || v->type != ESIL_VAL_CONST) { free (v); eprintf ("Cannot resolve GOTO dst :(\n"); @@ -349,36 +349,36 @@ void _handle_goto (EsilCfgGen *gen, ut32 idx) { } // get the node to the corresponding GOTO destination - RAnalEsilEOffset dst_off = { gen->off, (ut16)v->val }; - RGraphNode *dst_node = r_rbtree_cont_find (gen->blocks, &dst_off, _graphnode_esilbb_find_cmp, NULL); + RzAnalEsilEOffset dst_off = { gen->off, (ut16)v->val }; + RGraphNode *dst_node = rz_rbtree_cont_find (gen->blocks, &dst_off, _graphnode_esilbb_find_cmp, NULL); if (!dst_node) { // out-of-bounds // check if this works dst_node = gen->cfg->end; } else { - RAnalEsilBB *dst_bb = (RAnalEsilBB *)dst_node->data; + RzAnalEsilBB *dst_bb = (RzAnalEsilBB *)dst_node->data; if (dst_bb->first.idx != v->val) { - RAnalEsilBB *split_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *split_bb = R_NEW0 (RzAnalEsilBB); split_bb[0] = dst_bb[0]; dst_bb->last.idx = v->val - 1; split_bb->first.idx = v->val; - RGraphNode *split = r_graph_node_split_forward (gen->cfg->g, dst_node, split_bb); - r_graph_add_edge (gen->cfg->g, dst_node, split); + RGraphNode *split = rz_graph_node_split_forward (gen->cfg->g, dst_node, split_bb); + rz_graph_add_edge (gen->cfg->g, dst_node, split); dst_node = split; } } - r_graph_add_edge (gen->cfg->g, gnode, dst_node); + rz_graph_add_edge (gen->cfg->g, gnode, dst_node); beach: - while (!r_stack_is_empty (gen->vals)) { - free (r_stack_pop (gen->vals)); + while (!rz_stack_is_empty (gen->vals)) { + free (rz_stack_pop (gen->vals)); } } bool _round_1_cb (void *user, void *data, ut32 id) { EsilCfgGen *gen = (EsilCfgGen *)user; char *atom = (char *)data; - RAnalEsilOp *op = esil_get_op (gen->esil, atom); + RzAnalEsilOp *op = esil_get_op (gen->esil, atom); if (op && op->type == R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW) { if (!strcmp ("BREAK", atom)) { _handle_break (gen, id); @@ -391,24 +391,24 @@ bool _round_1_cb (void *user, void *data, ut32 id) { } void _round_2_cb (RGraphNode *n, RGraphVisitor *vi) { - RAnalEsilBB *bb = (RAnalEsilBB *)n->data; + RzAnalEsilBB *bb = (RzAnalEsilBB *)n->data; EsilCfgGen *gen = (EsilCfgGen *)vi->data; - RStrBuf *buf = r_strbuf_new ((char *)r_id_storage_get (gen->atoms, bb->first.idx)); - r_strbuf_append (buf, ","); + RStrBuf *buf = rz_strbuf_new ((char *)rz_id_storage_get (gen->atoms, bb->first.idx)); + rz_strbuf_append (buf, ","); ut32 id; for (id = bb->first.idx + 1; id <= bb->last.idx; id++) { - // use r_id_storage_take here to start fini for the atoms - r_strbuf_appendf (buf, "%s,", (char *)r_id_storage_take (gen->atoms, id)); + // use rz_id_storage_take here to start fini for the atoms + rz_strbuf_appendf (buf, "%s,", (char *)rz_id_storage_take (gen->atoms, id)); } - bb->expr = strdup (r_strbuf_get (buf)); - r_strbuf_free (buf); - r_rbtree_cont_delete (gen->blocks, n, _graphnode_esilbb_insert_cmp, NULL); + bb->expr = strdup (rz_strbuf_get (buf)); + rz_strbuf_free (buf); + rz_rbtree_cont_delete (gen->blocks, n, _graphnode_esilbb_insert_cmp, NULL); } // this function takes a cfg, an offset and an esil expression // concatinates to already existing graph. // Also expects RIDStorage atoms and RContRBTree to be allocate in prior of the call -static RAnalEsilCFG *esil_cfg_gen(RAnalEsilCFG *cfg, RAnal *anal, RIDStorage *atoms, RContRBTree *blocks, RStack *stack, ut64 off, char *expr) { +static RzAnalEsilCFG *esil_cfg_gen(RzAnalEsilCFG *cfg, RzAnal *anal, RIDStorage *atoms, RContRBTree *blocks, RStack *stack, ut64 off, char *expr) { // consider expr as RStrBuf, so that we can sanitze broken esil // (ex: "b,a,+=,$z,zf,:=,7,$c,cf,:=,zf,?{,1,b,+=,cf,?{,3,a,-=" => // "b,a,+=,$z,zf,:=,7,$c,cf,:=,zf,?{,1,b,+=,cf,?{,3,a,-=,},}") @@ -418,12 +418,12 @@ static RAnalEsilCFG *esil_cfg_gen(RAnalEsilCFG *cfg, RAnal *anal, RIDStorage *at if (!_expr) { return cfg; //NULL? } - RAnalEsilBB *end_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *end_bb = R_NEW0 (RzAnalEsilBB); if (!end_bb) { free (_expr); return cfg; } - RGraphNode *start, *end = r_graph_add_node (cfg->g, end_bb); + RGraphNode *start, *end = rz_graph_add_node (cfg->g, end_bb); if (!end) { free (end_bb); free (_expr); @@ -442,7 +442,7 @@ static RAnalEsilCFG *esil_cfg_gen(RAnalEsilCFG *cfg, RAnal *anal, RIDStorage *at // // without information about the outside cfg, we CANNOT merge cpu-instructions - RAnalEsilBB *bb = (RAnalEsilBB *)cfg->end->data; + RzAnalEsilBB *bb = (RzAnalEsilBB *)cfg->end->data; end_bb->expr = bb->expr; // FIXME: use end_bb here @@ -461,26 +461,26 @@ static RAnalEsilCFG *esil_cfg_gen(RAnalEsilCFG *cfg, RAnal *anal, RIDStorage *at // of the subgraph, that we are going to add to the existing graph. // The post-dominator of the previous added subgraph is the starting node here. // We add this to the block-tree - r_rbtree_cont_insert (blocks, gen.cur, _graphnode_esilbb_insert_cmp, NULL); + rz_rbtree_cont_insert (blocks, gen.cur, _graphnode_esilbb_insert_cmp, NULL); // end of the initial setup, next generate blocks and insert them in the tree // round 0 adds a subgraph from if, else and fi - r_id_storage_foreach (atoms, _round_0_cb, &gen); + rz_id_storage_foreach (atoms, _round_0_cb, &gen); // make cfg->end effective post-dominator - r_graph_add_edge (cfg->g, gen.cur, cfg->end); + rz_graph_add_edge (cfg->g, gen.cur, cfg->end); { // stack unwinding EsilCfgScopeCookie *cookie; - while ((cookie = r_stack_pop (stack))) { - r_graph_add_edge (cfg->g, + while ((cookie = rz_stack_pop (stack))) { + rz_graph_add_edge (cfg->g, cookie->is_else ? cookie->if_block : cookie->else_block, cfg->end); free (cookie); } } // next do round 1: split blocks from GOTOs and BREAKs - r_id_storage_foreach (atoms, _round_1_cb, &gen); + rz_id_storage_foreach (atoms, _round_1_cb, &gen); // next do dfs: // - remove each node from blocks-tree, that can be reached by a dfs path @@ -488,20 +488,20 @@ static RAnalEsilCFG *esil_cfg_gen(RAnalEsilCFG *cfg, RAnal *anal, RIDStorage *at { // dfs walk removes used atoms RGraphVisitor vi = { _round_2_cb, NULL, NULL, NULL, NULL, &gen }; - r_graph_dfs_node (cfg->g, start, &vi); + rz_graph_dfs_node (cfg->g, start, &vi); } // this loop removes unused atoms do { - } while (blocks->root && r_rbtree_cont_delete (blocks, NULL, _graphnode_delete_always_0_cmp, &gen)); + } while (blocks->root && rz_rbtree_cont_delete (blocks, NULL, _graphnode_delete_always_0_cmp, &gen)); free (_expr); return cfg; } -R_API RAnalEsilCFG *r_anal_esil_cfg_new(void) { - RAnalEsilCFG *cf = R_NEW0 (RAnalEsilCFG); +RZ_API RzAnalEsilCFG *rz_anal_esil_cfg_new(void) { + RzAnalEsilCFG *cf = R_NEW0 (RzAnalEsilCFG); if (cf) { - RAnalEsilBB *p = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *p = R_NEW0 (RzAnalEsilBB); if (!p) { free (cf); return NULL; @@ -512,20 +512,20 @@ R_API RAnalEsilCFG *r_anal_esil_cfg_new(void) { free (cf); return NULL; } - cf->g = r_graph_new (); + cf->g = rz_graph_new (); if (!cf->g) { free (p->expr); free (p); free (cf); return NULL; } - cf->start = cf->end = r_graph_add_node (cf->g, p); + cf->start = cf->end = rz_graph_add_node (cf->g, p); // end node is always needed as post-dominator // idea here is to split the initial one node graph in the node if (!cf->end) { free (p->expr); free (p); - r_graph_free (cf->g); + rz_graph_free (cf->g); free (cf); return NULL; } @@ -538,58 +538,58 @@ R_API RAnalEsilCFG *r_anal_esil_cfg_new(void) { // this little function takes a cfg, an offset and an esil expression // concatinates to already existing graph -R_API RAnalEsilCFG *r_anal_esil_cfg_expr(RAnalEsilCFG *cfg, RAnal *anal, const ut64 off, char *expr) { +RZ_API RzAnalEsilCFG *rz_anal_esil_cfg_expr(RzAnalEsilCFG *cfg, RzAnal *anal, const ut64 off, char *expr) { if (!anal || !anal->esil) { return NULL; } - RStack *stack = r_stack_new (4); + RStack *stack = rz_stack_new (4); if (!stack) { return NULL; } - RContRBTree *blocks = r_rbtree_cont_new (); + RContRBTree *blocks = rz_rbtree_cont_new (); if (!blocks) { - r_stack_free (stack); + rz_stack_free (stack); return NULL; } - RIDStorage *atoms = r_id_storage_new (0, 0xfffe); + RIDStorage *atoms = rz_id_storage_new (0, 0xfffe); if (!atoms) { - r_stack_free (stack); - r_rbtree_cont_free (blocks); + rz_stack_free (stack); + rz_rbtree_cont_free (blocks); return NULL; } - RAnalEsilCFG *cf = cfg ? cfg : r_anal_esil_cfg_new (); + RzAnalEsilCFG *cf = cfg ? cfg : rz_anal_esil_cfg_new (); if (!cf) { - r_stack_free (stack); - r_id_storage_free (atoms); - r_rbtree_cont_free (blocks); + rz_stack_free (stack); + rz_id_storage_free (atoms); + rz_rbtree_cont_free (blocks); return NULL; } - RAnalEsilCFG *ret = esil_cfg_gen (cf, anal, atoms, blocks, stack, off, expr); - r_stack_free (stack); - r_id_storage_free (atoms); - r_rbtree_cont_free (blocks); + RzAnalEsilCFG *ret = esil_cfg_gen (cf, anal, atoms, blocks, stack, off, expr); + rz_stack_free (stack); + rz_id_storage_free (atoms); + rz_rbtree_cont_free (blocks); return ret; } -R_API RAnalEsilCFG *r_anal_esil_cfg_op(RAnalEsilCFG *cfg, RAnal *anal, RAnalOp *op) { +RZ_API RzAnalEsilCFG *rz_anal_esil_cfg_op(RzAnalEsilCFG *cfg, RzAnal *anal, RzAnalOp *op) { if (!op || !anal || !anal->reg || !anal->esil) { return NULL; } - RAnalEsilBB *glue_bb = R_NEW0 (RAnalEsilBB); + RzAnalEsilBB *glue_bb = R_NEW0 (RzAnalEsilBB); if (!glue_bb) { eprintf ("Couldn't allocate glue_bb\n"); return NULL; } - RStrBuf *glue = r_strbuf_new (""); + RStrBuf *glue = rz_strbuf_new (""); if (!glue) { free (glue_bb); eprintf ("Couldn't allocate glue\n"); return NULL; } - const char *pc = r_reg_get_name (anal->reg, R_REG_NAME_PC); - r_strbuf_setf (glue, "0x%" PFMT64x ",%s,:=,", op->addr + op->size, pc); - glue_bb->expr = strdup (r_strbuf_get (glue)); - r_strbuf_free (glue); + const char *pc = rz_reg_get_name (anal->reg, R_REG_NAME_PC); + rz_strbuf_setf (glue, "0x%" PFMT64x ",%s,:=,", op->addr + op->size, pc); + glue_bb->expr = strdup (rz_strbuf_get (glue)); + rz_strbuf_free (glue); if (!glue_bb->expr) { free (glue_bb); eprintf ("Couldn't strdup\n"); @@ -599,72 +599,72 @@ R_API RAnalEsilCFG *r_anal_esil_cfg_op(RAnalEsilCFG *cfg, RAnal *anal, RAnalOp * glue_bb->first.off = glue_bb->last.off = op->addr; glue_bb->first.idx = glue_bb->last.idx = 0; - RAnalEsilCFG *ret; + RzAnalEsilCFG *ret; if (!cfg) { - ret = r_anal_esil_cfg_expr (cfg, anal, op->addr, r_strbuf_get (&op->esil)); - RGraphNode *glue_node = r_graph_add_node (ret->g, glue_bb); + ret = rz_anal_esil_cfg_expr (cfg, anal, op->addr, rz_strbuf_get (&op->esil)); + RGraphNode *glue_node = rz_graph_add_node (ret->g, glue_bb); glue_node->free = _free_bb_cb; - r_graph_add_edge (ret->g, glue_node, ret->start); + rz_graph_add_edge (ret->g, glue_node, ret->start); ret->start = glue_node; } else { - RGraphNode *glue_node = r_graph_add_node (cfg->g, glue_bb); + RGraphNode *glue_node = rz_graph_add_node (cfg->g, glue_bb); glue_node->free = _free_bb_cb; - r_graph_add_edge (cfg->g, cfg->end, glue_node); + rz_graph_add_edge (cfg->g, cfg->end, glue_node); void *foo = cfg->end->data; cfg->end->data = glue_node->data; glue_node->data = foo; cfg->end = glue_node; - ret = r_anal_esil_cfg_expr (cfg, anal, op->addr, r_strbuf_get (&op->esil)); + ret = rz_anal_esil_cfg_expr (cfg, anal, op->addr, rz_strbuf_get (&op->esil)); } return ret; } -static void merge_2_blocks(RAnalEsilCFG *cfg, RGraphNode *node, RGraphNode *block) { +static void merge_2_blocks(RzAnalEsilCFG *cfg, RGraphNode *node, RGraphNode *block) { // merge node and block, block dies in this // block----->node ===> node if (node == cfg->end) { // do not merge the post-dominator return; } - RListIter *iter; + RzListIter *iter; RGraphNode *n; - r_list_foreach (block->in_nodes, iter, n) { - r_graph_add_edge (cfg->g, n, node); + rz_list_foreach (block->in_nodes, iter, n) { + rz_graph_add_edge (cfg->g, n, node); } - RAnalEsilBB *block_bb, *node_bb = (RAnalEsilBB *)node->data; - block_bb = (RAnalEsilBB *)block->data; + RzAnalEsilBB *block_bb, *node_bb = (RzAnalEsilBB *)node->data; + block_bb = (RzAnalEsilBB *)block->data; if ((block_bb->enter == R_ANAL_ESIL_BLOCK_ENTER_TRUE) || (block_bb->enter == R_ANAL_ESIL_BLOCK_ENTER_FALSE)) { node_bb->enter = block_bb->enter; } else { node_bb->enter = R_ANAL_ESIL_BLOCK_ENTER_NORMAL; } - RStrBuf *buf = r_strbuf_new (block_bb->expr); + RStrBuf *buf = rz_strbuf_new (block_bb->expr); node_bb->first = block_bb->first; - r_graph_del_node (cfg->g, block); - r_strbuf_appendf (buf, "\n%s", node_bb->expr); + rz_graph_del_node (cfg->g, block); + rz_strbuf_appendf (buf, "\n%s", node_bb->expr); free (node_bb->expr); - node_bb->expr = strdup (r_strbuf_get (buf)); + node_bb->expr = strdup (rz_strbuf_get (buf)); if (block == cfg->start) { cfg->start = node; } } // this shit is slow af, bc of foolish graph api -R_API void r_anal_esil_cfg_merge_blocks(RAnalEsilCFG *cfg) { +RZ_API void rz_anal_esil_cfg_merge_blocks(RzAnalEsilCFG *cfg) { if (!cfg || !cfg->g || !cfg->g->nodes) { return; } - RListIter *iter, *ator; + RzListIter *iter, *ator; RGraphNode *node; - r_list_foreach_safe (cfg->g->nodes, iter, ator, node) { - if (r_list_length (node->in_nodes) == 1) { - RAnalEsilBB *bb = (RAnalEsilBB *)node->data; - RGraphNode *top = (RGraphNode *)r_list_get_top (node->out_nodes); + rz_list_foreach_safe (cfg->g->nodes, iter, ator, node) { + if (rz_list_length (node->in_nodes) == 1) { + RzAnalEsilBB *bb = (RzAnalEsilBB *)node->data; + RGraphNode *top = (RGraphNode *)rz_list_get_top (node->out_nodes); // segfaults here ? - if (!(top && bb->enter == R_ANAL_ESIL_BLOCK_ENTER_GLUE && (r_list_length (top->in_nodes) > 1))) { - RGraphNode *block = (RGraphNode *)r_list_get_top (node->in_nodes); - if (r_list_length (block->out_nodes) == 1) { + if (!(top && bb->enter == R_ANAL_ESIL_BLOCK_ENTER_GLUE && (rz_list_length (top->in_nodes) > 1))) { + RGraphNode *block = (RGraphNode *)rz_list_get_top (node->in_nodes); + if (rz_list_length (block->out_nodes) == 1) { merge_2_blocks (cfg, node, block); } } @@ -672,9 +672,9 @@ R_API void r_anal_esil_cfg_merge_blocks(RAnalEsilCFG *cfg) { } } -R_API void r_anal_esil_cfg_free(RAnalEsilCFG *cfg) { +RZ_API void rz_anal_esil_cfg_free(RzAnalEsilCFG *cfg) { if (cfg && cfg->g) { - r_graph_free (cfg->g); + rz_graph_free (cfg->g); } free (cfg); } diff --git a/librz/anal/esil_dfg.c b/librz/anal/esil_dfg.c new file mode 100644 index 0000000000..7ba043451d --- /dev/null +++ b/librz/anal/esil_dfg.c @@ -0,0 +1,1100 @@ +/* radare - LGPL - Copyright 2019 - condret */ + +//#include +#include +//#include +//#include + +typedef struct esil_dfg_reg_var_t { + ut32 from; + ut32 to; + RGraphNode *node; +} EsilDFGRegVar; + +typedef struct rz_anal_esil_dfg_filter_t { + RzAnalEsilDFG *dfg; + RContRBTree *tree; + Sdb *results; +} RzAnalEsilDFGFilter; + +// TODO: simple const propagation - use node->type of srcs to propagate consts of pushed vars + +RZ_API RzAnalEsilDFGNode *rz_anal_esil_dfg_node_new(RzAnalEsilDFG *edf, const char *c) { + RzAnalEsilDFGNode *ret = R_NEW0 (RzAnalEsilDFGNode); + ret->content = rz_strbuf_new (c); + ret->idx = edf->idx++; + return ret; +} + +static void _dfg_node_free (RzAnalEsilDFGNode *free_me) { + if (free_me) { + rz_strbuf_free (free_me->content); + free (free_me); + } +} + +static int _rv_del_alloc_cmp (void *incoming, void *in, void *user) { + EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; + EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; + RzAnalEsilDFG *dfg = (RzAnalEsilDFG *)user; + + if (dfg->malloc_failed) { + return -1; + } + + // first handle the simple cases without intersection + if (rv_incoming->to < rv_in->from) { + return -1; + } + if (rv_in->to < rv_incoming->from) { + return 1; + } + if (rv_in->from == rv_incoming->from && rv_in->to == rv_incoming->to) { + return 0; + } + + /* + the following cases are about intersection, here some ascii-art, so you understand what I do + + =incoming= + =========in========= + + split in into 2 and reinsert the second half (in2) + shrink first half (in1) + + =incoming= + =in1= =in2= + */ + + if (rv_in->from < rv_incoming->from && rv_incoming->to < rv_in->to) { + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_in[0]; + rv_in->to = rv_incoming->from - 1; + rv->from = rv_incoming->to + 1; + dfg->insert = rv; + return 1; + } + + /* + =incoming= + =in= + + enqueue the non-intersecting ends in the todo-queue + */ + + if (rv_incoming->from < rv_in->from && rv_in->to < rv_incoming->to) { + // lower part + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->to = rv_in->from - 1; + rz_queue_enqueue (dfg->todo, rv); + // upper part + rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->from = rv_in->to + 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; + } + + /* + =incoming= + =in= + + similar to the previous case, but this time only enqueue 1 half + */ + + if (rv_incoming->from == rv_in->from && rv_in->to < rv_incoming->to) { + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->from = rv_in->to + 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; + } + + /* + =incoming= + =in= + */ + + if (rv_incoming->from < rv_in->from && rv_in->to == rv_incoming->to) { + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->to = rv_in->from - 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; + } + + /* + =incoming= + ===in=== + + shrink in + + =incoming= + =in= + */ + + if (rv_in->to <= rv_incoming->to) { + rv_in->to = rv_incoming->from - 1; + return 1; + } + + /* + =incoming= + ===in=== + + up-shrink in + + =incoming= + ==in== + */ + + rv_in->from = rv_incoming->to + 1; + return -1; +} + +static int _rv_ins_cmp (void *incoming, void *in, void *user) { + EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; + EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; + return rv_incoming->from - rv_in->from; +} + +static bool _edf_reg_set (RzAnalEsilDFG *dfg, const char *reg, RGraphNode *node) { + rz_return_val_if_fail (dfg && !dfg->malloc_failed && reg, false); + const ut32 _reg_strlen = 4 + strlen (reg); + char *_reg = R_NEWS0 (char, _reg_strlen + 1); + if (!_reg) { + // no need for assert here, it's not a bug if malloc fails + return false; + } + strncat (_reg, "reg.", _reg_strlen); + strncat (_reg, reg, _reg_strlen); + if (!sdb_num_exists (dfg->regs, _reg)) { + //no assert to prevent memleaks + free (_reg); + return false; + } + EsilDFGRegVar *rv = R_NEW0 (EsilDFGRegVar); + if (!rv) { + free (_reg); + return false; + } + + const ut64 v = sdb_num_get (dfg->regs, _reg, NULL); + free (_reg); + rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; + rv->to = v & UT32_MAX; + rz_queue_enqueue (dfg->todo, rv); + while (!rz_queue_is_empty (dfg->todo) && !dfg->malloc_failed) { + // rbtree api does sadly not allow deleting multiple items at once :( + rv = rz_queue_dequeue (dfg->todo); + rz_rbtree_cont_delete (dfg->reg_vars, rv, _rv_del_alloc_cmp, dfg); + if (dfg->insert && !dfg->malloc_failed) { + rz_rbtree_cont_insert (dfg->reg_vars, dfg->insert, _rv_ins_cmp, NULL); + dfg->insert = NULL; + } + free (rv); + } + if (dfg->malloc_failed) { + while (!rz_queue_is_empty (dfg->todo)) { + free (rz_queue_dequeue (dfg->todo)); + } + return false; + } + rv = R_NEW0 (EsilDFGRegVar); + rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; + rv->to = v & UT32_MAX; + rv->node = node; + rz_rbtree_cont_insert (dfg->reg_vars, rv, _rv_ins_cmp, NULL); + return true; +} + +static int _rv_find_cmp (void *incoming, void *in, void *user) { + EsilDFGRegVar *rv_incoming = (EsilDFGRegVar *)incoming; + EsilDFGRegVar *rv_in = (EsilDFGRegVar *)in; + + RzAnalEsilDFG *dfg = (RzAnalEsilDFG *)user; + if (dfg->malloc_failed) { + return -1; + } + + // first handle the simple cases without intersection + if (rv_incoming->to < rv_in->from) { + return -1; + } + if (rv_in->to < rv_incoming->from) { + return 1; + } + + /* + =incoming= + =========in========= + */ + if (rv_in->from <= rv_incoming->from && rv_incoming->to <= rv_in->to) { + return 0; + } + + /* + =incoming= + =in= + + enqueue the non-intersecting ends in the todo-queue + */ + if (rv_incoming->from < rv_in->from && rv_in->to < rv_incoming->to) { + // lower part + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->to = rv_in->from - 1; + rz_queue_enqueue (dfg->todo, rv); + // upper part + rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->from = rv_in->to + 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; + } + + /* + =incoming= + =in= + + similar to the previous case, but this time only enqueue 1 half + */ + if (rv_in->from <= rv_incoming->from && rv_in->to < rv_incoming->to) { + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->from = rv_in->to + 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; + } + + /* + =incoming= + =in= + */ + EsilDFGRegVar *rv = R_NEW (EsilDFGRegVar); + if (!rv) { + dfg->malloc_failed = true; + return -1; + } + rv[0] = rv_incoming[0]; + rv->to = rv_in->from - 1; + rz_queue_enqueue (dfg->todo, rv); + return 0; +} + +static RGraphNode *_edf_origin_reg_get(RzAnalEsilDFG *dfg, const char *reg) { + rz_return_val_if_fail (dfg && reg, NULL); + const ut32 _reg_strlen = 4 + strlen (reg); + char *_reg = R_NEWS0 (char, _reg_strlen + 1); + if (!_reg) { + return NULL; + } + strncat (_reg, "reg.", _reg_strlen); + strncat (_reg, reg, _reg_strlen); + if (!sdb_num_exists (dfg->regs, _reg)) { + free (_reg); + return NULL; + } + free (_reg); + const ut32 origin_reg_strlen = 4 + strlen (reg); + char *origin_reg = R_NEWS0 (char, origin_reg_strlen + 1); + if (!origin_reg) { + return NULL; + } + strncat (origin_reg, "ori.", origin_reg_strlen); + strncat (origin_reg, reg, origin_reg_strlen); + RGraphNode *origin_reg_node = sdb_ptr_get (dfg->regs, origin_reg, 0); + if (origin_reg_node) { + free (origin_reg); + return origin_reg_node; + } + RGraphNode *reg_node = rz_graph_add_node (dfg->flow, rz_anal_esil_dfg_node_new (dfg, reg)); + RzAnalEsilDFGNode *_origin_reg_node = rz_anal_esil_dfg_node_new (dfg, reg); + rz_strbuf_appendf (_origin_reg_node->content, ":var_%d", dfg->idx++); + _origin_reg_node->type = R_ANAL_ESIL_DFG_BLOCK_VAR; + origin_reg_node = rz_graph_add_node (dfg->flow, _origin_reg_node); + rz_graph_add_edge (dfg->flow, reg_node, origin_reg_node); + sdb_ptr_set (dfg->regs, origin_reg, origin_reg_node, 0); + free (origin_reg); + return origin_reg_node; +} + + +static RGraphNode *_edf_reg_get(RzAnalEsilDFG *dfg, const char *reg) { + rz_return_val_if_fail (dfg && reg, NULL); + const ut32 _reg_strlen = 4 + strlen (reg); + char *_reg = R_NEWS0 (char, _reg_strlen + 1); + if (!_reg) { + return NULL; + } + strncat (_reg, "reg.", _reg_strlen); + strncat (_reg, reg, _reg_strlen); + if (!sdb_num_exists (dfg->regs, _reg)) { + free (_reg); + return NULL; + } + EsilDFGRegVar *rv = R_NEW0 (EsilDFGRegVar); + if (!rv) { + free (_reg); + return NULL; + } + const ut64 v = sdb_num_get (dfg->regs, _reg, NULL); + free (_reg); + rv->from = (v & (UT64_MAX ^ UT32_MAX)) >> 32; + rv->to = v & UT32_MAX; + RQueue *parts = rz_queue_new (8); + if (!parts) { + free (rv); + return NULL; + } + rz_queue_enqueue (dfg->todo, rv); + + // log2((search_rv.to + 1) - search_rv.from) maybe better? + // wat du if this fails? + + RGraphNode *reg_node = NULL; + while (!rz_queue_is_empty (dfg->todo)) { + rv = rz_queue_dequeue (dfg->todo); + EsilDFGRegVar *part_rv = rz_rbtree_cont_find (dfg->reg_vars, rv, _rv_find_cmp, dfg); + if (part_rv) { + rz_queue_enqueue (parts, part_rv->node); + } else if (!reg_node) { + reg_node = _edf_origin_reg_get (dfg, reg); + //insert in the gap + part_rv = R_NEW (EsilDFGRegVar); + if (!part_rv) { + R_FREE (rv); + dfg->malloc_failed = true; + break; + } + part_rv[0] = rv[0]; + part_rv->node = reg_node; + rz_rbtree_cont_insert (dfg->reg_vars, part_rv, _rv_ins_cmp, NULL); + //enqueue for later merge + rz_queue_enqueue (parts, reg_node); + } else { + //initial regnode was already created + //only need to insert in the tree + part_rv = R_NEW (EsilDFGRegVar); + if (!part_rv) { + R_FREE (part_rv); + dfg->malloc_failed = true; + break; + } + part_rv[0] = rv[0]; + part_rv->node = reg_node; + rz_rbtree_cont_insert (dfg->reg_vars, part_rv, _rv_ins_cmp, NULL); + } + free (rv); + } + reg_node = NULL; // is this needed? + if (dfg->malloc_failed) { + while (!rz_queue_is_empty(dfg->todo)) { + free (rz_queue_dequeue (dfg->todo)); + goto beach; + } + } + switch (parts->size) { + case 0: + break; + case 1: + reg_node = rz_queue_dequeue (parts); + break; + default: + { + RzAnalEsilDFGNode *_reg_node = rz_anal_esil_dfg_node_new (dfg, "merge to "); + if (!_reg_node) { + while (!rz_queue_is_empty (dfg->todo)) { + free (rz_queue_dequeue (dfg->todo)); + } + dfg->malloc_failed = true; + goto beach; + } + + rz_strbuf_appendf (_reg_node->content, "%s:var_%d", reg, dfg->idx++); + reg_node = rz_graph_add_node (dfg->flow, _reg_node); + if (!reg_node) { + _dfg_node_free (_reg_node); + while (!rz_queue_is_empty (dfg->todo)) { + free (rz_queue_dequeue (dfg->todo)); + } + dfg->malloc_failed = true; + goto beach; + } + } + do { + rz_graph_add_edge (dfg->flow, rz_queue_dequeue(parts), reg_node); + } while (!rz_queue_is_empty (parts)); + break; + } +beach: + rz_queue_free (parts); + return reg_node; +} + + +static bool _edf_var_set (RzAnalEsilDFG *dfg, const char *var, RGraphNode *node) { + rz_return_val_if_fail (dfg && var, false); + const ut32 _var_strlen = 4 + strlen (var); + char *_var = R_NEWS0 (char, _var_strlen + 1); + if (!_var) { + return false; + } + strncat (_var, "var.", _var_strlen); + strncat (_var, var, _var_strlen); + const bool ret = !sdb_ptr_set (dfg->regs, _var, node, 0); + free (_var); + return ret; +} + + +static RGraphNode *_edf_var_get (RzAnalEsilDFG *dfg, const char *var) { + rz_return_val_if_fail (dfg && var, NULL); + const ut32 _var_strlen = 4 + strlen (var); + char *_var = R_NEWS0 (char, _var_strlen + 1); + if (!_var) { + return NULL; + } + strncat (_var, "var.", _var_strlen); + strncat (_var, var, _var_strlen); + RGraphNode *ret = sdb_ptr_get (dfg->regs, _var, NULL); + free (_var); + return ret; +} + +static bool edf_consume_2_set_reg(RzAnalEsil *esil); +static bool edf_consume_2_push_1(RzAnalEsil *esil); +static bool edf_consume_1_push_1(RzAnalEsil *esil); +typedef void (*AddConstraintStringUseNewCB) (RStrBuf *result, const char *new_node_str); +static bool edf_use_new_push_1(RzAnalEsil *esil, const char *op_string, AddConstraintStringUseNewCB cb); +typedef void (*AddConstraintStringConsume1UseOldNewCB) (RStrBuf *result, const char *consume_str, const char *old_node_str, const char *new_node_str); +static bool edf_consume_1_use_old_new_push_1(RzAnalEsil *esil, const char *op_string, AddConstraintStringConsume1UseOldNewCB cb); + +static bool edf_eq_weak(RzAnalEsil *esil) { + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + RGraphNode *o_old = edf->old; //node for esil->old + RGraphNode *o_new = edf->cur; //node for esil->cur + if (!edf_consume_2_set_reg (esil)) { + return false; + } + //work-around + edf->old = o_old ? o_old : NULL; + edf->cur = o_new ? o_new : NULL; + return true; +} + +static void edf_zf_constraint(RStrBuf *result, const char *new_node_str) { + rz_strbuf_appendf (result, ":(%s==0)", new_node_str); +} + +static bool edf_zf(RzAnalEsil *esil) { + return edf_use_new_push_1 (esil, "$z", edf_zf_constraint); +} + +static void edf_pf_constraint(RStrBuf *result, const char *new_node_str) { + rz_strbuf_appendf (result, ":parity_of(%s)", new_node_str); +} + +static bool edf_pf(RzAnalEsil *esil) { + return edf_use_new_push_1 (esil, "$p", edf_pf_constraint); +} + +static void edf_cf_constraint(RStrBuf *result, const char *consume, const char *o, const char *n) { + rz_strbuf_appendf (result, ":((%s&mask(%s&0x3f))<(%s&mask(%s&0x3f)))", + n, consume, o, consume); +} + +static bool edf_cf(RzAnalEsil *esil) { + return edf_consume_1_use_old_new_push_1 (esil, "$c", edf_cf_constraint); +} + +static void edf_bf_constraint(RStrBuf *result, const char *consume, const char *o, const char *n) { + rz_strbuf_appendf (result, ":((%s&mask((%s+0x3f)&0x3f))<(%s& mask((%s+0x3f)&0x3f)))", + o, consume, n, consume); +} + +static bool edf_bf(RzAnalEsil *esil) { + return edf_consume_1_use_old_new_push_1 (esil, "$b", edf_bf_constraint); +} + +static bool _edf_consume_2_set_reg(RzAnalEsil *esil, const bool use_origin) { + const char *op_string = esil->current_opstr; + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + + if (!src || !dst) { + free (dst); + free (src); + return false; + } + + int dst_type = rz_anal_esil_get_parm_type (esil, dst); + if (dst_type == R_ANAL_ESIL_PARM_INVALID) { + free (dst); + free (src); + return false; + } + + const int src_type = rz_anal_esil_get_parm_type (esil, src); + RGraphNode *src_node = NULL; + if (src_type == R_ANAL_ESIL_PARM_REG) { + src_node = _edf_reg_get (edf, src); + } else if (src_type == R_ANAL_ESIL_PARM_NUM) { + RGraphNode *n_value = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, src)); + RzAnalEsilDFGNode *ec_node = rz_anal_esil_dfg_node_new (edf, src); + ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; + rz_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); + src_node = rz_graph_add_node (edf->flow, ec_node); + rz_graph_add_edge (edf->flow, n_value, src_node); + } else { + src_node = _edf_var_get (edf, src); + } + + RGraphNode *dst_node = use_origin ? _edf_origin_reg_get (edf, dst) : _edf_reg_get (edf, dst); + RGraphNode *old_dst_node = dst_node; + + if (!src_node || !dst_node) { + free (src); + free (dst); + return false; + } + + RzAnalEsilDFGNode *eop_node = rz_anal_esil_dfg_node_new (edf, src); + rz_strbuf_appendf (eop_node->content, ",%s,%s", dst, op_string); + eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; + free (src); + + RGraphNode *op_node = rz_graph_add_node (edf->flow, eop_node); + rz_graph_add_edge (edf->flow, dst_node, op_node); + rz_graph_add_edge (edf->flow, src_node, op_node); + edf->old = old_dst_node; + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, dst); + result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_VAR; + + rz_strbuf_appendf (result->content, ":var_%d", edf->idx++); + dst_node = rz_graph_add_node (edf->flow, result); + rz_graph_add_edge (edf->flow, op_node, dst_node); + _edf_reg_set (edf, dst, dst_node); + edf->cur = dst_node; + free (dst); + return true; +} + +static bool edf_consume_2_use_set_reg(RzAnalEsil *esil) { + return _edf_consume_2_set_reg (esil, false); +} + +static bool edf_consume_2_set_reg(RzAnalEsil *esil) { + return _edf_consume_2_set_reg (esil, true); +} + +static bool edf_consume_2_push_1(RzAnalEsil *esil) { + const char *op_string = esil->current_opstr; + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + char *src[2] = { rz_anal_esil_pop (esil), rz_anal_esil_pop (esil) }; + + if (!src[0] || !src[1]) { + free (src[0]); + free (src[1]); + return false; + } + RzAnalEsilDFGNode *eop_node = rz_anal_esil_dfg_node_new (edf, src[1]); + rz_strbuf_appendf (eop_node->content, ",%s,%s", src[0], op_string); + eop_node->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; + RGraphNode *op_node = rz_graph_add_node (edf->flow, eop_node); + RGraphNode *src_node[2]; + ut32 i; + for (i = 0; i < 2; i++) { + const int src_type = rz_anal_esil_get_parm_type (esil, src[i]); + if (src_type == R_ANAL_ESIL_PARM_REG) { + src_node[i] = _edf_reg_get (edf, src[i]); + } else if (src_type == R_ANAL_ESIL_PARM_NUM) { + RGraphNode *n_value = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, src[i])); + RzAnalEsilDFGNode *ec_node = rz_anal_esil_dfg_node_new (edf, src[i]); + ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; + rz_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); + src_node[i] = rz_graph_add_node (edf->flow, ec_node); + rz_graph_add_edge (edf->flow, n_value, src_node[i]); + } else { + src_node[i] = _edf_var_get (edf, src[i]); + } + rz_graph_add_edge (edf->flow, src_node[i], op_node); + } + + free (src[0]); + free (src[1]); + + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, "result_"); + result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; + rz_strbuf_appendf (result->content, "%d", edf->idx++); + RGraphNode *result_node = rz_graph_add_node (edf->flow, result); + rz_graph_add_edge (edf->flow, op_node, result_node); + _edf_var_set (edf, rz_strbuf_get (result->content), result_node); + rz_anal_esil_push (esil, rz_strbuf_get (result->content)); + return true; +} + +static bool edf_consume_1_push_1(RzAnalEsil *esil) { + const char *op_string = esil->current_opstr; + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + char *src = rz_anal_esil_pop (esil); + if (!src) { + return false; + } + RzAnalEsilDFGNode *eop_node = rz_anal_esil_dfg_node_new (edf, src); + rz_strbuf_appendf (eop_node->content, ",%s", op_string); + eop_node->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; + RGraphNode *op_node = rz_graph_add_node (edf->flow, eop_node); + const int src_type = rz_anal_esil_get_parm_type (esil, src); + RGraphNode *src_node = NULL; + if (src_type == R_ANAL_ESIL_PARM_REG) { + src_node = _edf_reg_get (edf, src); + } else if (src_type == R_ANAL_ESIL_PARM_NUM) { + RGraphNode *n_value = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, src)); + RzAnalEsilDFGNode *ec_node = rz_anal_esil_dfg_node_new (edf, src); + ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; + rz_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); + src_node = rz_graph_add_node (edf->flow, ec_node); + rz_graph_add_edge (edf->flow, n_value, src_node); + } else { + src_node = _edf_var_get (edf, src); + } + + free (src); + + rz_graph_add_edge (edf->flow, src_node, op_node); + + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, "result_"); + result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; //TODO: propgate type from src here + rz_strbuf_appendf (result->content, "%d", edf->idx++); + RGraphNode *result_node = rz_graph_add_node (edf->flow, result); + rz_graph_add_edge (edf->flow, op_node, result_node); + _edf_var_set (edf, rz_strbuf_get (result->content), result_node); + rz_anal_esil_push (esil, rz_strbuf_get (result->content)); + return true; +} + +static bool edf_consume_2_set_mem(RzAnalEsil *esil) { + const char *op_string = esil->current_opstr; + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + char *dst = rz_anal_esil_pop (esil); + char *src = rz_anal_esil_pop (esil); + + if (!src || !dst) { + free (dst); + free (src); + return 0; + } + + int dst_type = rz_anal_esil_get_parm_type (esil, dst); + + const int src_type = rz_anal_esil_get_parm_type (esil, src); + RGraphNode *src_node = NULL; + if (src_type == R_ANAL_ESIL_PARM_REG) { + src_node = _edf_reg_get (edf, src); + } else if (src_type == R_ANAL_ESIL_PARM_NUM) { + RGraphNode *n_value = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, src)); + RzAnalEsilDFGNode *ec_node = rz_anal_esil_dfg_node_new (edf, src); + ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; + rz_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); + src_node = rz_graph_add_node (edf->flow, ec_node); + rz_graph_add_edge (edf->flow, n_value, src_node); + } else { + src_node = _edf_var_get (edf, src); + } + + RGraphNode *dst_node = _edf_reg_get (edf, dst); + if (!dst_node) { + dst_node = _edf_var_get (edf, dst); + } +//probably dead code + if (!dst_node) { + if (dst_type == R_ANAL_ESIL_PARM_REG) { + RGraphNode *n_reg = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, dst)); + RzAnalEsilDFGNode *ev_node = rz_anal_esil_dfg_node_new (edf, dst); + ev_node->type = R_ANAL_ESIL_DFG_BLOCK_VAR | R_ANAL_ESIL_DFG_BLOCK_PTR; + rz_strbuf_appendf (ev_node->content, ":var_ptr_%d", edf->idx++); + dst_node = rz_graph_add_node (edf->flow, ev_node); + // _edf_reg_set (edf, dst, ev_node); + rz_graph_add_edge (edf->flow, n_reg, dst_node); + } + // TODO: const pointers + } + + if (!src_node || !dst_node) { + free (src); + free (dst); + return false; + } + + RzAnalEsilDFGNode *eop_node = rz_anal_esil_dfg_node_new (edf, src); + rz_strbuf_appendf (eop_node->content, ",%s,%s", dst, op_string); + eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; + free (src); + + RGraphNode *op_node = rz_graph_add_node (edf->flow, eop_node); + rz_graph_add_edge (edf->flow, dst_node, op_node); + rz_graph_add_edge (edf->flow, src_node, op_node); + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, dst); + // result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT | R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; + result->type = R_ANAL_ESIL_DFG_BLOCK_VAR; + rz_strbuf_appendf (result->content, ":var_mem_%d", edf->idx++); + dst_node = rz_graph_add_node (edf->flow, result); + rz_graph_add_edge (edf->flow, op_node, dst_node); + free (dst); + return true; +} + +static bool edf_use_new_push_1(RzAnalEsil *esil, const char *op_string, AddConstraintStringUseNewCB cb) { + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + RGraphNode *op_node = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, op_string)); + RGraphNode *latest_new = edf->cur; + if (!latest_new) { + return 0; + } + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, "result_"); + result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; // is this generative? + rz_strbuf_appendf (result->content, "%d", edf->idx++); + if (cb) { + RzAnalEsilDFGNode *e_new_node = (RzAnalEsilDFGNode *)latest_new->data; + cb (result->content, rz_strbuf_get (e_new_node->content)); + } + RGraphNode *result_node = rz_graph_add_node (edf->flow, result); + _edf_var_set (edf, rz_strbuf_get (result->content), result_node); + rz_graph_add_edge (edf->flow, latest_new, op_node); + rz_graph_add_edge (edf->flow, op_node, result_node); + return rz_anal_esil_push (esil, rz_strbuf_get (result->content)); +} + +static bool edf_consume_1_use_old_new_push_1(RzAnalEsil *esil, const char *op_string, AddConstraintStringConsume1UseOldNewCB cb) { + RzAnalEsilDFG *edf = (RzAnalEsilDFG *)esil->user; + char *src = rz_anal_esil_pop (esil); + + if (!src) { + return false; + } + RzAnalEsilDFGNode *eop_node = rz_anal_esil_dfg_node_new (edf, src); +#if 0 + eop_node->type = R_ANAL_ESIL_DFG_BLOCK_GENERATIVE; +#endif + rz_strbuf_appendf (eop_node->content, ",%s", op_string); + RGraphNode *op_node = rz_graph_add_node (edf->flow, eop_node); + const int src_type = rz_anal_esil_get_parm_type (esil, src); + RGraphNode *src_node = NULL; + if (src_type == R_ANAL_ESIL_PARM_REG) { + src_node = _edf_reg_get (edf, src); + } else if (src_type == R_ANAL_ESIL_PARM_NUM) { + RGraphNode *n_value = rz_graph_add_node (edf->flow, rz_anal_esil_dfg_node_new (edf, src)); + RzAnalEsilDFGNode *ec_node = rz_anal_esil_dfg_node_new (edf, src); + ec_node->type = R_ANAL_ESIL_DFG_BLOCK_CONST; + rz_strbuf_appendf (ec_node->content, ":const_%d", edf->idx++); + src_node = rz_graph_add_node (edf->flow, ec_node); + rz_graph_add_edge (edf->flow, n_value, src_node); + } else { + src_node = _edf_var_get (edf, src); + } + free (src); + + rz_graph_add_edge (edf->flow, src_node, op_node); + + RGraphNode *latest_new = edf->cur; + RGraphNode *latest_old = edf->old; + RzAnalEsilDFGNode *result = rz_anal_esil_dfg_node_new (edf, "result_"); + result->type = R_ANAL_ESIL_DFG_BLOCK_RESULT; // propagate type here + rz_strbuf_appendf (result->content, "%d", edf->idx++); + if (cb) { + RzAnalEsilDFGNode *e_src_node = (RzAnalEsilDFGNode *)src_node->data; + RzAnalEsilDFGNode *e_new_node = (RzAnalEsilDFGNode *)latest_new->data; + RzAnalEsilDFGNode *e_old_node = (RzAnalEsilDFGNode *)latest_old->data; + cb (result->content, rz_strbuf_get (e_src_node->content), + rz_strbuf_get (e_new_node->content), rz_strbuf_get (e_old_node->content)); + } + RGraphNode *result_node = rz_graph_add_node (edf->flow, result); + _edf_var_set (edf, rz_strbuf_get (result->content), result_node); + rz_graph_add_edge (edf->flow, latest_new, op_node); + rz_graph_add_edge (edf->flow, latest_old, op_node); + rz_graph_add_edge (edf->flow, op_node, result_node); + return rz_anal_esil_push (esil, rz_strbuf_get (result->content)); +} + +RZ_API RzAnalEsilDFG *rz_anal_esil_dfg_new(RzReg *regs) { + if (!regs) { + return NULL; + } + RzAnalEsilDFG *dfg = R_NEW0 (RzAnalEsilDFG); + if (!dfg) { + return NULL; + } + dfg->flow = rz_graph_new (); + if (!dfg->flow) { + free (dfg); + return NULL; + } + dfg->regs = sdb_new0 (); + if (!dfg->regs) { + rz_graph_free (dfg->flow); + free (dfg); + return NULL; + } + // rax, eax, ax, ah, al => 8 should be enough + dfg->todo = rz_queue_new (8); + if (!dfg->todo) { + sdb_free (dfg->regs); + rz_graph_free (dfg->flow); + free (dfg); + return NULL; + } + dfg->reg_vars = rz_rbtree_cont_newf (free); + if (!dfg->reg_vars) { + rz_queue_free (dfg->todo); + sdb_free (dfg->regs); + rz_graph_free (dfg->flow); + free (dfg); + return NULL; + } + +// this is not exactly necessary +// could use RzReg-API directly in the dfg gen, +// but sdb as transition table is probably faster + RzRegItem *ri; + RzListIter *ator; + rz_list_foreach (regs->allregs, ator, ri) { + const ut32 from = ri->offset; + const ut32 to = from + ri->size - 1; // closed intervals because of FUCK YOU + const ut64 v = to | (((ut64)from) << 32); + const ut32 reg_strlen = 4 + strlen (ri->name) + 1; + char *reg = R_NEWS0 (char, reg_strlen); + strncat (reg, "reg.", reg_strlen); + strncat (reg, ri->name, reg_strlen); + sdb_num_set (dfg->regs, reg, v, 0); + free (reg); + } + return dfg; +} + +RZ_API void rz_anal_esil_dfg_free(RzAnalEsilDFG *dfg) { + if (dfg) { + if (dfg->flow) { + RGraphNode *n; + RzListIter *iter; + rz_list_foreach (rz_graph_get_nodes (dfg->flow), iter, n) { + n->free = (RzListFree)_dfg_node_free; + } + rz_graph_free (dfg->flow); + } + sdb_free (dfg->regs); + rz_rbtree_cont_free (dfg->reg_vars); + rz_queue_free (dfg->todo); + free (dfg); + } +} + +RZ_API RzAnalEsilDFG *rz_anal_esil_dfg_expr(RzAnal *anal, RzAnalEsilDFG *dfg, const char *expr) { + if (!expr) { + return NULL; + } + RzAnalEsil *esil = rz_anal_esil_new (4096, 0, 1); + if (!esil) { + return NULL; + } + esil->anal = anal; + + RzAnalEsilDFG *edf = dfg ? dfg : rz_anal_esil_dfg_new (anal->reg); + if (!edf) { + rz_anal_esil_free (esil); + return NULL; + } + + rz_anal_esil_set_op (esil, "=", edf_consume_2_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, ":=", edf_eq_weak, 0, 2, R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "$z", edf_zf, 1, 0, R_ANAL_ESIL_OP_TYPE_UNKNOWN); + rz_anal_esil_set_op (esil, "$p", edf_pf, 1, 0, R_ANAL_ESIL_OP_TYPE_UNKNOWN); + rz_anal_esil_set_op (esil, "$c", edf_cf, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); + rz_anal_esil_set_op (esil, "$b", edf_bf, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); + rz_anal_esil_set_op (esil, "^=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "-=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "+=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "*=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "/=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "&=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "|=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "^=", edf_consume_2_use_set_reg, 0, 2, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_REG_WRITE); + rz_anal_esil_set_op (esil, "+", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "-", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "&", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "|", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "^", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "%", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "*", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "/", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, ">>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "<<", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, ">>>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, ">>>", edf_consume_2_push_1, 1, 2, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "!", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MATH); + rz_anal_esil_set_op (esil, "[1]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); + rz_anal_esil_set_op (esil, "[2]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); + rz_anal_esil_set_op (esil, "[4]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); + rz_anal_esil_set_op (esil, "[8]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); + rz_anal_esil_set_op (esil, "[16]", edf_consume_1_push_1, 1, 1, R_ANAL_ESIL_OP_TYPE_MEM_READ); + rz_anal_esil_set_op (esil, "=[1]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); + rz_anal_esil_set_op (esil, "=[2]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); + rz_anal_esil_set_op (esil, "=[4]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); + rz_anal_esil_set_op (esil, "=[8]", edf_consume_2_set_mem, 0, 2, R_ANAL_ESIL_OP_TYPE_MEM_WRITE); + + esil->user = edf; + + rz_anal_esil_parse (esil, expr); + rz_anal_esil_free (esil); + return edf; +} + +static int _dfg_node_filter_insert_cmp(void *incoming, void *in, void *user) { + RzAnalEsilDFGNode *incoming_node = (RzAnalEsilDFGNode *)incoming; + RzAnalEsilDFGNode *in_node = (RzAnalEsilDFGNode *)in; + return incoming_node->idx - in_node->idx; +} + +static void _dfg_rev_dfs_cb(RGraphNode *n, RGraphVisitor *vi) { + RzAnalEsilDFGNode *node = (RzAnalEsilDFGNode *)n->data; + RzAnalEsilDFGFilter *filter = (RzAnalEsilDFGFilter *)vi->data; + switch (node->type) { + case R_ANAL_ESIL_DFG_BLOCK_CONST: + case R_ANAL_ESIL_DFG_BLOCK_VAR: + case R_ANAL_ESIL_DFG_BLOCK_PTR: + break; + case R_ANAL_ESIL_DFG_BLOCK_GENERATIVE: + rz_rbtree_cont_insert (filter->tree, node, _dfg_node_filter_insert_cmp, NULL); + break; + case R_ANAL_ESIL_DFG_BLOCK_RESULT: // outnode must be result generator here + { + RGraphNode *previous = (RGraphNode *)rz_list_get_top (n->in_nodes); + if (previous) { + sdb_ptr_set (filter->results, rz_strbuf_get (node->content), previous, 0); + } + } break; + } +} + +static char *condrets_strtok(char *str, const char tok) { + if (!str) { + return NULL; + } + ut32 i = 0; + while (1 == 1) { + if (!str[i]) { + break; + } + if (str[i] == tok) { + str[i] = '\0'; + return &str[i + 1]; + } + i++; + } + return NULL; +} + +static RStrBuf *get_resolved_expr(RzAnalEsilDFGFilter *filter, RzAnalEsilDFGNode *node) { + char *expr = strdup (rz_strbuf_get (node->content)); + RStrBuf *res = rz_strbuf_new (""); + if (!expr) { //empty expressions. can this happen? + return res; + } + char *p, *q; + // we can do this bc every generative node MUST end with an operator + for (p = expr; (q = condrets_strtok (p, ',')); p = q) { + RGraphNode *gn = sdb_ptr_get (filter->results, p, 0); + if (!gn) { + rz_strbuf_appendf (res, ",%s,", p); + } else { + RStrBuf *r = get_resolved_expr (filter, (RzAnalEsilDFGNode *)gn->data); + rz_strbuf_appendf (res, ",%s,", rz_strbuf_get (r)); + rz_strbuf_free (r); + } + } + rz_strbuf_appendf (res, "%s", p); + free (expr); + return res; +} + +RZ_API RStrBuf *rz_anal_esil_dfg_filter(RzAnalEsilDFG *dfg, const char *reg) { + if (!dfg || !reg) { + return NULL; + } + RGraphNode *resolve_me = _edf_reg_get (dfg, reg); + if (!resolve_me) { + return NULL; + } + + // allocate stuff + RzAnalEsilDFGFilter filter = { dfg, rz_rbtree_cont_new (), sdb_new0 () }; + RStrBuf *filtered = rz_strbuf_new (""); + RGraphVisitor vi = { _dfg_rev_dfs_cb, NULL, NULL, NULL, NULL, &filter }; + + // dfs the graph starting at node of esp-register + rz_graph_dfs_node_reverse (dfg->flow, resolve_me, &vi); + + RBIter ator; + RzAnalEsilDFGNode *node; + rz_rbtree_cont_foreach (filter.tree, ator, node) { + // resolve results to opstr here + RStrBuf *resolved = get_resolved_expr (&filter, node); + rz_strbuf_append (filtered, rz_strbuf_get (resolved)); + rz_strbuf_free (resolved); + } + { + char *sanitized = rz_str_replace (rz_str_replace (strdup (rz_strbuf_get (filtered)), ",,", ",", 1), ",,", ",", 1); + rz_strbuf_set (filtered, (sanitized[0] == ',') ? &sanitized[1] : sanitized); + free (sanitized); + } + rz_rbtree_cont_free (filter.tree); + sdb_free (filter.results); + return filtered; +} + +RZ_API RStrBuf *rz_anal_esil_dfg_filter_expr(RzAnal *anal, const char *expr, const char *reg) { + if (!reg) { + return NULL; + } + RzAnalEsilDFG *dfg = rz_anal_esil_dfg_expr (anal, NULL, expr); + if (!dfg) { + return NULL; + } + RStrBuf *filtered = rz_anal_esil_dfg_filter (dfg, reg); + rz_anal_esil_dfg_free (dfg); + return filtered; +} diff --git a/librz/anal/esil_interrupt.c b/librz/anal/esil_interrupt.c new file mode 100644 index 0000000000..8a15c40294 --- /dev/null +++ b/librz/anal/esil_interrupt.c @@ -0,0 +1,147 @@ +#include +#include +#include +#include + +static void _interrupt_free_cb(void *user) { + RzAnalEsilInterrupt *intr = (RzAnalEsilInterrupt *)user; + if (intr && intr->handler && intr->handler->fini) { + intr->handler->fini (intr->user); + } + free (intr); +} + +static bool _set_interrupt(RzAnalEsil *esil, RzAnalEsilInterrupt *intr) { + return intr->handler->num ? + dict_set (esil->interrupts, intr->handler->num, intr->handler->num, intr) : + (esil->intr0 = intr, true); +} + +static RzAnalEsilInterrupt *_get_interrupt(RzAnalEsil *esil, ut32 intr_num) { + return intr_num ? + (RzAnalEsilInterrupt *)dict_getu(esil->interrupts, intr_num) : + esil->intr0; +} + +static void _del_interrupt(RzAnalEsil *esil, ut32 intr_num) { + if (intr_num) { + dict_del (esil->interrupts, intr_num); + } else { + esil->intr0 = NULL; + } +} + +RZ_API void rz_anal_esil_interrupts_init(RzAnalEsil *esil) { + rz_return_if_fail (esil); + esil->interrupts = dict_new (sizeof (ut32), NULL); + esil->intr0 = NULL; // is this needed? +} + +RZ_API RzAnalEsilInterrupt *rz_anal_esil_interrupt_new(RzAnalEsil *esil, ut32 src_id, RzAnalEsilInterruptHandler *ih) { + rz_return_val_if_fail (esil && ih && ih->cb, NULL); + RzAnalEsilInterrupt *intr = R_NEW0 (RzAnalEsilInterrupt); + if (!intr) { + return NULL; + } + intr->handler = ih; + if (ih->init && ih->fini) { + intr->user = ih->init (esil); + } + intr->src_id = src_id; + rz_anal_esil_claim_source (esil, src_id); + return intr; +} + +RZ_API void rz_anal_esil_interrupt_free(RzAnalEsil *esil, RzAnalEsilInterrupt *intr) { + if (intr && esil) { + _del_interrupt (esil, intr->handler->num); + } + if (intr) { + if (intr->user) { + intr->handler->fini (intr->user); //fini must exist when user is !NULL + } + rz_anal_esil_release_source (esil, intr->src_id); + } + free (intr); +} + +RZ_API bool rz_anal_esil_set_interrupt(RzAnalEsil *esil, RzAnalEsilInterrupt *intr) { + rz_return_val_if_fail (esil && esil->interrupts && intr && intr->handler && intr->handler->cb, false); + // check if interrupt is already set + RzAnalEsilInterrupt *o_intr = _get_interrupt(esil, intr->handler->num); + if (o_intr) { + rz_anal_esil_interrupt_free (esil, o_intr); + } + //set the new interrupt + return _set_interrupt(esil, intr); +} + +RZ_API int rz_anal_esil_fire_interrupt(RzAnalEsil *esil, ut32 intr_num) { + rz_return_val_if_fail (esil, false); + + if (esil->cmd && esil->cmd (esil, esil->cmd_intr, intr_num, 0)) { //compatibility + return true; + } + + if (!esil->interrupts) { + eprintf ("no interrupts initialized\n"); + return false; + } + RzAnalEsilInterrupt *intr = _get_interrupt (esil, intr_num); +#if 0 + // we don't want this warning + if (!intr) { + eprintf ("Warning no interrupt handler registered for 0x%x\n", intr_num); + } +#endif + return (intr && intr->handler && intr->handler->cb) ? + intr->handler->cb (esil, intr_num, intr->user) : false; +} + +RZ_API bool rz_anal_esil_load_interrupts (RzAnalEsil *esil, RzAnalEsilInterruptHandler *handlers[], ut32 src_id) { + RzAnalEsilInterrupt *intr; + ut32 i = 0; + + rz_return_val_if_fail (esil && esil->interrupts && handlers, false); + + while (handlers[i]) { + intr = _get_interrupt (esil, handlers[i]->num); + if (intr) { + //first free, then load the new handler or stuff might break in the handlers + rz_anal_esil_interrupt_free (esil, intr); + } + intr = rz_anal_esil_interrupt_new (esil, src_id, handlers[i]); + if (!intr) { + return false; + } + rz_anal_esil_set_interrupt (esil, intr); + i++; + } + + return true; +} + +RZ_API bool rz_anal_esil_load_interrupts_from_lib(RzAnalEsil *esil, const char *path) { + rz_return_val_if_fail (esil, false); + ut32 src_id = rz_anal_esil_load_source (esil, path); + if (!src_id) { // why id=0 is invalid? + return false; + } + RzAnalEsilInterruptHandler **handlers = (RzAnalEsilInterruptHandler **)\ + rz_lib_dl_sym (rz_anal_esil_get_source (esil, src_id), "interrupts"); + if (!handlers) { + rz_anal_esil_release_source (esil, src_id); //unload + return false; + } + return rz_anal_esil_load_interrupts (esil, handlers, src_id); +} + +RZ_API void rz_anal_esil_interrupts_fini(RzAnalEsil *esil) { + if (esil && esil->interrupts) { + _interrupt_free_cb (esil->intr0); + esil->intr0 = NULL; + esil->interrupts->f = _interrupt_free_cb; + dict_free (esil->interrupts); + esil->interrupts = NULL; + } +} diff --git a/librz/anal/esil_sources.c b/librz/anal/esil_sources.c new file mode 100644 index 0000000000..a79aaf21db --- /dev/null +++ b/librz/anal/esil_sources.c @@ -0,0 +1,91 @@ +#include +#include +#include + +RZ_API void rz_anal_esil_sources_init (RzAnalEsil *esil) { + if (esil && !esil->sources) { + esil->sources =rz_id_storage_new (1, 0xffffffff); //0 is reserved for stuff from plugins + } +} + +RZ_API ut32 rz_anal_esil_load_source(RzAnalEsil *esil, const char *path) { + RzAnalEsilSource *src; + + if (!esil) { + eprintf ("no esil?\n"); + return 0; + } + + src = R_NEW0 (RzAnalEsilSource); + src->content = rz_lib_dl_open(path); + if (!src->content) { + eprintf ("no content\n"); + free (src); + return 0; + } + + rz_anal_esil_sources_init (esil); + if (!rz_id_storage_add(esil->sources, src, &src->id)) { + eprintf ("cannot add to storage\n"); + rz_lib_dl_close (src->content); + free (src); + return 0; + } + + return src->id; +} + +static RzAnalEsilSource *_get_source(RzAnalEsil *esil, ut32 src_id) { + if (!esil || !esil->sources) { + return NULL; + } + return (RzAnalEsilSource *)rz_id_storage_get (esil->sources, src_id); +} + +RZ_API void *rz_anal_esil_get_source(RzAnalEsil *esil, ut32 src_id) { + RzAnalEsilSource *src = _get_source(esil, src_id); + + return src ? src->content : NULL; +} + +RZ_API bool rz_anal_esil_claim_source(RzAnalEsil *esil, ut32 src_id) { + RzAnalEsilSource *src = _get_source(esil, src_id); + + if (src) { + src->claimed++; + return true; + } + return false; +} + +RZ_API void rz_anal_esil_release_source(RzAnalEsil *esil, ut32 src_id) { + RzAnalEsilSource *src = _get_source(esil, src_id); + + if (!src) { + return; + } + if (src->claimed <= 1) { + rz_id_storage_delete (esil->sources, src_id); + rz_lib_dl_close (src->content); + free (src); + } else { + src->claimed--; + } +} + +static bool _free_source_cb(void *user, void *data, ut32 id) { + RzAnalEsilSource *src = (RzAnalEsilSource *)data; + + if (src) { + rz_lib_dl_close (src->content); + } + free (src); + return true; +} + +RZ_API void rz_anal_esil_sources_fini(RzAnalEsil *esil) { + if (esil) { + rz_id_storage_foreach(esil->sources, _free_source_cb, NULL); + rz_id_storage_free(esil->sources); + } +} diff --git a/libr/anal/esil_stats.c b/librz/anal/esil_stats.c similarity index 64% rename from libr/anal/esil_stats.c rename to librz/anal/esil_stats.c index 3b8bb34c95..c8d2b0ea9e 100644 --- a/libr/anal/esil_stats.c +++ b/librz/anal/esil_stats.c @@ -1,44 +1,44 @@ /* radare - LGPL - Copyright 2014 - pancake */ -#include +#include -static int hook_flag_read(RAnalEsil *esil, const char *flag, ut64 *num) { +static int hook_flag_read(RzAnalEsil *esil, const char *flag, ut64 *num) { sdb_array_add (esil->stats, "flg.read", flag, 0); return 0; } -static int hook_command(RAnalEsil *esil, const char *op) { +static int hook_command(RzAnalEsil *esil, const char *op) { sdb_array_add (esil->stats, "ops.list", op, 0); return 0; } -static int hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +static int hook_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { sdb_array_add_num (esil->stats, "mem.read", addr, 0); return 0; } -static int hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int hook_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { sdb_array_add_num (esil->stats, "mem.write", addr, 0); return 0; } -static int hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) { +static int hook_reg_read(RzAnalEsil *esil, const char *name, ut64 *res, int *size) { const char *key = (*name>='0' && *name<='9')? "num.load": "reg.read"; sdb_array_add (esil->stats, key, name, 0); return 0; } -static int hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { +static int hook_reg_write(RzAnalEsil *esil, const char *name, ut64 *val) { sdb_array_add (esil->stats, "reg.write", name, 0); return 0; } -static int hook_NOP_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int hook_NOP_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { eprintf ("NOP WRITE AT 0x%08"PFMT64x"\n", addr); return 1; // override } -R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly) { +RZ_API void rz_anal_esil_mem_ro(RzAnalEsil *esil, int mem_readonly) { if (mem_readonly) { esil->cb.hook_mem_write = hook_NOP_mem_write; } else { @@ -46,7 +46,7 @@ R_API void r_anal_esil_mem_ro(RAnalEsil *esil, int mem_readonly) { } } -R_API void r_anal_esil_stats(RAnalEsil *esil, int enable) { +RZ_API void rz_anal_esil_stats(RzAnalEsil *esil, int enable) { if (enable) { if (esil->stats) { sdb_reset (esil->stats); diff --git a/libr/anal/esil_trace.c b/librz/anal/esil_trace.c similarity index 71% rename from libr/anal/esil_trace.c rename to librz/anal/esil_trace.c index 8181314155..a944278718 100644 --- a/libr/anal/esil_trace.c +++ b/librz/anal/esil_trace.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2015-2020 - pancake, rkx1209 */ -#include +#include #define DB esil->trace->db #define KEY(x) sdb_fmt ("%d."x, esil->trace->idx) #define KEYAT(x,y) sdb_fmt ("%d."x".0x%"PFMT64x, esil->trace->idx, y) #define KEYREG(x,y) sdb_fmt ("%d."x".%s", esil->trace->idx, y) -#define CMP_REG_CHANGE(x, y) ((x) - ((RAnalEsilRegChange *)y)->idx) -#define CMP_MEM_CHANGE(x, y) ((x) - ((RAnalEsilMemChange *)y)->idx) +#define CMP_REG_CHANGE(x, y) ((x) - ((RzAnalEsilRegChange *)y)->idx) +#define CMP_MEM_CHANGE(x, y) ((x) - ((RzAnalEsilMemChange *)y)->idx) static int ocbs_set = false; -static RAnalEsilCallbacks ocbs = {0}; +static RzAnalEsilCallbacks ocbs = {0}; static void htup_vector_free(HtUPKv *kv) { - r_vector_free (kv->value); + rz_vector_free (kv->value); } -R_API RAnalEsilTrace *r_anal_esil_trace_new(RAnalEsil *esil) { - r_return_val_if_fail (esil && esil->stack_addr && esil->stack_size, NULL); +RZ_API RzAnalEsilTrace *rz_anal_esil_trace_new(RzAnalEsil *esil) { + rz_return_val_if_fail (esil && esil->stack_addr && esil->stack_size, NULL); size_t i; - RAnalEsilTrace *trace = R_NEW0 (RAnalEsilTrace); + RzAnalEsilTrace *trace = R_NEW0 (RzAnalEsilTrace); if (!trace) { return NULL; } @@ -46,8 +46,8 @@ R_API RAnalEsilTrace *r_anal_esil_trace_new(RAnalEsil *esil) { trace->stack_data, trace->stack_size); // Save initial registers arenas for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = esil->anal->reg->regset[i].arena; - RRegArena *b = r_reg_arena_new (a->size); + RzRegArena *a = esil->anal->reg->regset[i].arena; + RzRegArena *b = rz_reg_arena_new (a->size); if (!b) { goto error; } @@ -57,17 +57,17 @@ R_API RAnalEsilTrace *r_anal_esil_trace_new(RAnalEsil *esil) { return trace; error: eprintf ("error\n"); - r_anal_esil_trace_free (trace); + rz_anal_esil_trace_free (trace); return NULL; } -R_API void r_anal_esil_trace_free(RAnalEsilTrace *trace) { +RZ_API void rz_anal_esil_trace_free(RzAnalEsilTrace *trace) { size_t i; if (trace) { ht_up_free (trace->registers); ht_up_free (trace->memory); for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_reg_arena_free (trace->arena[i]); + rz_reg_arena_free (trace->arena[i]); } free (trace->stack_data); sdb_free (trace->db); @@ -75,43 +75,43 @@ R_API void r_anal_esil_trace_free(RAnalEsilTrace *trace) { } } -static void add_reg_change(RAnalEsilTrace *trace, int idx, RRegItem *ri, ut64 data) { +static void add_reg_change(RzAnalEsilTrace *trace, int idx, RzRegItem *ri, ut64 data) { ut64 addr = ri->offset | (ri->arena << 16); - RVector *vreg = ht_up_find (trace->registers, addr, NULL); + RzVector *vreg = ht_up_find (trace->registers, addr, NULL); if (!vreg) { - vreg = r_vector_new (sizeof (RAnalEsilRegChange), NULL, NULL); + vreg = rz_vector_new (sizeof (RzAnalEsilRegChange), NULL, NULL); if (!vreg) { eprintf ("Error: creating a register vector.\n"); return; } ht_up_insert (trace->registers, addr, vreg); } - RAnalEsilRegChange reg = { idx, data }; - r_vector_push (vreg, ®); + RzAnalEsilRegChange reg = { idx, data }; + rz_vector_push (vreg, ®); } -static void add_mem_change(RAnalEsilTrace *trace, int idx, ut64 addr, ut8 data) { - RVector *vmem = ht_up_find (trace->memory, addr, NULL); +static void add_mem_change(RzAnalEsilTrace *trace, int idx, ut64 addr, ut8 data) { + RzVector *vmem = ht_up_find (trace->memory, addr, NULL); if (!vmem) { - vmem = r_vector_new (sizeof (RAnalEsilMemChange), NULL, NULL); + vmem = rz_vector_new (sizeof (RzAnalEsilMemChange), NULL, NULL); if (!vmem) { eprintf ("Error: creating a memory vector.\n"); return; } ht_up_insert (trace->memory, addr, vmem); } - RAnalEsilMemChange mem = { idx, data }; - r_vector_push (vmem, &mem); + RzAnalEsilMemChange mem = { idx, data }; + rz_vector_push (vmem, &mem); } -static int trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) { +static int trace_hook_reg_read(RzAnalEsil *esil, const char *name, ut64 *res, int *size) { int ret = 0; if (*name == '0') { //eprintf ("Register not found in profile\n"); return 0; } if (ocbs.hook_reg_read) { - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; esil->cb = ocbs; ret = ocbs.hook_reg_read (esil, name, res, size); esil->cb = cbs; @@ -130,15 +130,15 @@ static int trace_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int return ret; } -static int trace_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { +static int trace_hook_reg_write(RzAnalEsil *esil, const char *name, ut64 *val) { int ret = 0; //eprintf ("[ESIL] REG WRITE %s 0x%08"PFMT64x"\n", name, *val); sdb_array_add (DB, KEY ("reg.write"), name, 0); sdb_num_set (DB, KEYREG ("reg.write", name), *val, 0); - RRegItem *ri = r_reg_get (esil->anal->reg, name, -1); + RzRegItem *ri = rz_reg_get (esil->anal->reg, name, -1); add_reg_change (esil->trace, esil->trace->idx + 1, ri, *val); if (ocbs.hook_reg_write) { - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; esil->cb = ocbs; ret = ocbs.hook_reg_write (esil, name, val); esil->cb = cbs; @@ -146,20 +146,20 @@ static int trace_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { return ret; } -static int trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +static int trace_hook_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { char *hexbuf = calloc ((1 + len), 4); int ret = 0; if (esil->cb.mem_read) { ret = esil->cb.mem_read (esil, addr, buf, len); } sdb_array_add_num (DB, KEY ("mem.read"), addr, 0); - r_hex_bin2str (buf, len, hexbuf); + rz_hex_bin2str (buf, len, hexbuf); sdb_set (DB, KEYAT ("mem.read.data", addr), hexbuf, 0); //eprintf ("[ESIL] MEM READ 0x%08"PFMT64x" %s\n", addr, hexbuf); free (hexbuf); if (ocbs.hook_mem_read) { - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; esil->cb = ocbs; ret = ocbs.hook_mem_read (esil, addr, buf, len); esil->cb = cbs; @@ -167,12 +167,12 @@ static int trace_hook_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { return ret; } -static int trace_hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int trace_hook_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { size_t i; int ret = 0; char *hexbuf = malloc ((1+len)*3); sdb_array_add_num (DB, KEY ("mem.write"), addr, 0); - r_hex_bin2str (buf, len, hexbuf); + rz_hex_bin2str (buf, len, hexbuf); sdb_set (DB, KEYAT ("mem.write.data", addr), hexbuf, 0); //eprintf ("[ESIL] MEM WRITE 0x%08"PFMT64x" %s\n", addr, hexbuf); free (hexbuf); @@ -181,7 +181,7 @@ static int trace_hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int } if (ocbs.hook_mem_write) { - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; esil->cb = ocbs; ret = ocbs.hook_mem_write (esil, addr, buf, len); esil->cb = cbs; @@ -189,22 +189,22 @@ static int trace_hook_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int return ret; } -R_API void r_anal_esil_trace_op(RAnalEsil *esil, RAnalOp *op) { - r_return_if_fail (esil && op); - const char *expr = r_strbuf_get (&op->esil); +RZ_API void rz_anal_esil_trace_op(RzAnalEsil *esil, RzAnalOp *op) { + rz_return_if_fail (esil && op); + const char *expr = rz_strbuf_get (&op->esil); if (R_STR_ISEMPTY (expr)) { // do nothing return; } if (!esil->trace) { - esil->trace = r_anal_esil_trace_new (esil); + esil->trace = rz_anal_esil_trace_new (esil); if (!esil->trace) { return; } } /* restore from trace when `idx` is not at the end */ if (esil->trace->idx != esil->trace->end_idx) { - r_anal_esil_trace_restore (esil, esil->trace->idx + 1); + rz_anal_esil_trace_restore (esil, esil->trace->idx + 1); return; } /* save old callbacks */ @@ -216,7 +216,7 @@ R_API void r_anal_esil_trace_op(RAnalEsil *esil, RAnalOp *op) { ocbs_set = true; sdb_num_set (DB, "idx", esil->trace->idx, 0); sdb_num_set (DB, KEY ("addr"), op->addr, 0); - RRegItem *pc_ri = r_reg_get (esil->anal->reg, "PC", -1); + RzRegItem *pc_ri = rz_reg_get (esil->anal->reg, "PC", -1); add_reg_change (esil->trace, esil->trace->idx, pc_ri, op->addr); // sdb_set (DB, KEY ("opcode"), op->mnemonic, 0); // sdb_set (DB, KEY ("addr"), expr, 0); @@ -230,8 +230,8 @@ R_API void r_anal_esil_trace_op(RAnalEsil *esil, RAnalOp *op) { esil->cb.hook_mem_read = trace_hook_mem_read; esil->cb.hook_mem_write = trace_hook_mem_write; /* evaluate esil expression */ - r_anal_esil_parse (esil, expr); - r_anal_esil_stack_free (esil); + rz_anal_esil_parse (esil, expr); + rz_anal_esil_stack_free (esil); /* restore hooks */ esil->cb = ocbs; ocbs_set = false; @@ -244,39 +244,39 @@ R_API void r_anal_esil_trace_op(RAnalEsil *esil, RAnalOp *op) { static bool restore_memory_cb(void *user, const ut64 key, const void *value) { size_t index; - RAnalEsil *esil = user; - RVector *vmem = (RVector *)value; + RzAnalEsil *esil = user; + RzVector *vmem = (RzVector *)value; - r_vector_upper_bound (vmem, esil->trace->idx, index, CMP_MEM_CHANGE); + rz_vector_upper_bound (vmem, esil->trace->idx, index, CMP_MEM_CHANGE); if (index > 0 && index <= vmem->len) { - RAnalEsilMemChange *c = r_vector_index_ptr (vmem, index - 1); + RzAnalEsilMemChange *c = rz_vector_index_ptr (vmem, index - 1); esil->anal->iob.write_at (esil->anal->iob.io, key, &c->data, 1); } return true; } -static bool restore_register(RAnalEsil *esil, RRegItem *ri, int idx) { +static bool restore_register(RzAnalEsil *esil, RzRegItem *ri, int idx) { size_t index; - RVector *vreg = ht_up_find (esil->trace->registers, ri->offset | (ri->arena << 16), NULL); + RzVector *vreg = ht_up_find (esil->trace->registers, ri->offset | (ri->arena << 16), NULL); if (vreg) { - r_vector_upper_bound (vreg, idx, index, CMP_REG_CHANGE); + rz_vector_upper_bound (vreg, idx, index, CMP_REG_CHANGE); if (index > 0 && index <= vreg->len) { - RAnalEsilRegChange *c = r_vector_index_ptr (vreg, index - 1); - r_reg_set_value (esil->anal->reg, ri, c->data); + RzAnalEsilRegChange *c = rz_vector_index_ptr (vreg, index - 1); + rz_reg_set_value (esil->anal->reg, ri, c->data); } } return true; } -R_API void r_anal_esil_trace_restore(RAnalEsil *esil, int idx) { +RZ_API void rz_anal_esil_trace_restore(RzAnalEsil *esil, int idx) { size_t i; - RAnalEsilTrace *trace = esil->trace; + RzAnalEsilTrace *trace = esil->trace; // Restore initial state when going backward if (idx < esil->trace->idx) { // Restore initial registers value for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = esil->anal->reg->regset[i].arena; - RRegArena *b = trace->arena[i]; + RzRegArena *a = esil->anal->reg->regset[i].arena; + RzRegArena *b = trace->arena[i]; if (a && b) { memcpy (a->bytes, b->bytes, a->size); } @@ -287,9 +287,9 @@ R_API void r_anal_esil_trace_restore(RAnalEsil *esil, int idx) { } // Apply latest changes to registers and memory esil->trace->idx = idx; - RListIter *iter; - RRegItem *ri; - r_list_foreach (esil->anal->reg->allregs, iter, ri) { + RzListIter *iter; + RzRegItem *ri; + rz_list_foreach (esil->anal->reg->allregs, iter, ri) { restore_register (esil, ri, idx); } ht_up_foreach (trace->memory, restore_memory_cb, esil); @@ -347,7 +347,7 @@ static int cmp_strings_by_leading_number(void *data1, void *data2) { return 0; } -R_API void r_anal_esil_trace_list (RAnalEsil *esil) { +RZ_API void rz_anal_esil_trace_list (RzAnalEsil *esil) { PrintfCallback p = esil->anal->cb_printf; SdbKv *kv; SdbListIter *iter; @@ -359,7 +359,7 @@ R_API void r_anal_esil_trace_list (RAnalEsil *esil) { ls_free (list); } -R_API void r_anal_esil_trace_show(RAnalEsil *esil, int idx) { +RZ_API void rz_anal_esil_trace_show(RzAnalEsil *esil, int idx) { PrintfCallback p = esil->anal->cb_printf; const char *str2; const char *str; @@ -405,7 +405,7 @@ R_API void r_anal_esil_trace_show(RAnalEsil *esil, int idx) { memcpy (addr, ptr, len); addr[len] = 0; str2 = sdb_const_get (DB, KEYAT ("mem.read.data", - r_num_get (NULL, addr)), 0); + rz_num_get (NULL, addr)), 0); p ("wx %s @ %s\n", str2, addr); } else { eprintf ("Invalid entry in reg.read\n"); diff --git a/libr/anal/fcn.c b/librz/anal/fcn.c similarity index 72% rename from libr/anal/fcn.c rename to librz/anal/fcn.c index 4685f8f0d1..621c2c3478 100644 --- a/libr/anal/fcn.c +++ b/librz/anal/fcn.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2010-2020 - nibble, alvaro, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #define READ_AHEAD 1 #define SDB_KEY_BB "bb.0x%"PFMT64x ".0x%"PFMT64x @@ -37,7 +37,7 @@ typedef struct fcn_tree_iter_t { RBNode *path[R_RBTREE_MAX_HEIGHT]; } FcnTreeIter; -R_API const char *r_anal_fcntype_tostring(int type) { +RZ_API const char *rz_anal_fcntype_tostring(int type) { switch (type) { case R_ANAL_FCN_TYPE_NULL: return "null"; case R_ANAL_FCN_TYPE_FCN: return "fcn"; @@ -54,7 +54,7 @@ R_API const char *r_anal_fcntype_tostring(int type) { static ut64 cache_addr = UT64_MAX; // TODO: move into io :? -static int read_ahead(RAnal *anal, ut64 addr, ut8 *buf, int len) { +static int read_ahead(RzAnal *anal, ut64 addr, ut8 *buf, int len) { static ut8 cache[1024]; const int cache_len = sizeof (cache); @@ -81,28 +81,28 @@ static int read_ahead(RAnal *anal, ut64 addr, ut8 *buf, int len) { return len; } #else -static int read_ahead(RAnal *anal, ut64 addr, ut8 *buf, int len) { +static int read_ahead(RzAnal *anal, ut64 addr, ut8 *buf, int len) { return anal->iob.read_at (anal->iob.io, addr, buf, len); } #endif -R_API void r_anal_fcn_invalidate_read_ahead_cache(void) { +RZ_API void rz_anal_fcn_invalidate_read_ahead_cache(void) { #if READ_AHEAD cache_addr = UT64_MAX; #endif } static int cmpaddr(const void *_a, const void *_b) { - const RAnalBlock *a = _a, *b = _b; + const RzAnalBlock *a = _a, *b = _b; return a->addr > b->addr ? 1 : (a->addr < b->addr ? -1 : 0); } -R_API int r_anal_function_resize(RAnalFunction *fcn, int newsize) { - RAnal *anal = fcn->anal; - RAnalBlock *bb; - RListIter *iter, *iter2; +RZ_API int rz_anal_function_resize(RzAnalFunction *fcn, int newsize) { + RzAnal *anal = fcn->anal; + RzAnalBlock *bb; + RzListIter *iter, *iter2; - r_return_val_if_fail (fcn, false); + rz_return_val_if_fail (fcn, false); if (newsize < 1) { return false; @@ -115,13 +115,13 @@ R_API int r_anal_function_resize(RAnalFunction *fcn, int newsize) { } ut64 eof = fcn->addr + newsize; - r_list_foreach_safe (fcn->bbs, iter, iter2, bb) { + rz_list_foreach_safe (fcn->bbs, iter, iter2, bb) { if (bb->addr >= eof) { - r_anal_function_remove_block (fcn, bb); + rz_anal_function_remove_block (fcn, bb); continue; } if (bb->addr + bb->size >= eof) { - r_anal_block_set_size (bb, eof - bb->addr); + rz_anal_block_set_size (bb, eof - bb->addr); } if (bb->jump != UT64_MAX && bb->jump >= eof) { bb->jump = UT64_MAX; @@ -134,12 +134,12 @@ R_API int r_anal_function_resize(RAnalFunction *fcn, int newsize) { } // Create a new 0-sized basic block inside the function -static RAnalBlock *fcn_append_basic_block(RAnal *anal, RAnalFunction *fcn, ut64 addr) { - RAnalBlock *bb = r_anal_create_block (anal, addr, 0); +static RzAnalBlock *fcn_append_basic_block(RzAnal *anal, RzAnalFunction *fcn, ut64 addr) { + RzAnalBlock *bb = rz_anal_create_block (anal, addr, 0); if (!bb) { return NULL; } - r_anal_function_add_block (fcn, bb); + rz_anal_function_add_block (fcn, bb); bb->stackptr = fcn->stack; bb->parent_stackptr = fcn->stack; return bb; @@ -147,7 +147,7 @@ static RAnalBlock *fcn_append_basic_block(RAnal *anal, RAnalFunction *fcn, ut64 #define gotoBeach(x) ret = x; goto beach; -static bool isInvalidMemory(RAnal *anal, const ut8 *buf, int len) { +static bool isInvalidMemory(RzAnal *anal, const ut8 *buf, int len) { if (anal->opt.nonull > 0) { int i; const int count = R_MIN (len, anal->opt.nonull); @@ -163,31 +163,31 @@ static bool isInvalidMemory(RAnal *anal, const ut8 *buf, int len) { return !memcmp (buf, "\xff\xff\xff\xff", R_MIN (len, 4)); } -static bool isSymbolNextInstruction(RAnal *anal, RAnalOp *op) { - r_return_val_if_fail (anal && op && anal->flb.get_at, false); +static bool isSymbolNextInstruction(RzAnal *anal, RzAnalOp *op) { + rz_return_val_if_fail (anal && op && anal->flb.get_at, false); - RFlagItem *fi = anal->flb.get_at (anal->flb.f, op->addr + op->size, false); + RzFlagItem *fi = anal->flb.get_at (anal->flb.f, op->addr + op->size, false); return (fi && fi->name && (strstr (fi->name, "imp.") || strstr (fi->name, "sym.") || strstr (fi->name, "entry") || strstr (fi->name, "main"))); } -static bool is_delta_pointer_table(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 lea_ptr, ut64 *jmptbl_addr, ut64 *casetbl_addr, RAnalOp *jmp_aop) { +static bool is_delta_pointer_table(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, ut64 lea_ptr, ut64 *jmptbl_addr, ut64 *casetbl_addr, RzAnalOp *jmp_aop) { int i; ut64 dst; st32 jmptbl[64] = {0}; /* check if current instruction is followed by an ujmp */ ut8 buf[JMPTBL_LEA_SEARCH_SZ]; - RAnalOp *aop = jmp_aop; - RAnalOp omov_aop, mov_aop = { 0 }; - RAnalOp add_aop = {0}; - RRegItem *reg_src, *o_reg_dst = NULL; - RAnalValue cur_scr, cur_dst = { 0 }; + RzAnalOp *aop = jmp_aop; + RzAnalOp omov_aop, mov_aop = { 0 }; + RzAnalOp add_aop = {0}; + RzRegItem *reg_src, *o_reg_dst = NULL; + RzAnalValue cur_scr, cur_dst = { 0 }; read_ahead (anal, addr, (ut8*)buf, sizeof (buf)); bool isValid = false; for (i = 0; i + 8 < JMPTBL_LEA_SEARCH_SZ; i++) { ut64 at = addr + i; int left = JMPTBL_LEA_SEARCH_SZ - i; - int len = r_anal_op (anal, aop, at, buf + i, left, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_VAL); + int len = rz_anal_op (anal, aop, at, buf + i, left, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_VAL); if (len < 1) { len = 1; } @@ -210,7 +210,7 @@ static bool is_delta_pointer_table(RAnal *anal, RAnalFunction *fcn, ut64 addr, u if (aop->type == R_ANAL_OP_TYPE_ADD) { add_aop = *aop; } - r_anal_op_fini (aop); + rz_anal_op_fini (aop); i += len - 1; } if (!isValid) { @@ -247,7 +247,7 @@ static bool is_delta_pointer_table(RAnal *anal, RAnalFunction *fcn, ut64 addr, u /* check if jump table contains valid deltas */ read_ahead (anal, *jmptbl_addr, (ut8 *)&jmptbl, 64); for (i = 0; i < 3; i++) { - dst = lea_ptr + (st32)r_read_le32 (jmptbl); + dst = lea_ptr + (st32)rz_read_le32 (jmptbl); if (!anal->iob.is_valid_offset (anal->iob.io, dst, 0)) { return false; } @@ -261,11 +261,11 @@ static bool is_delta_pointer_table(RAnal *anal, RAnalFunction *fcn, ut64 addr, u return true; } -static ut64 try_get_cmpval_from_parents(RAnal * anal, RAnalFunction *fcn, RAnalBlock *my_bb, const char * cmp_reg) { - r_return_val_if_fail (fcn && fcn->bbs && cmp_reg, UT64_MAX); - RListIter *iter; - RAnalBlock *tmp_bb; - r_list_foreach (fcn->bbs, iter, tmp_bb) { +static ut64 try_get_cmpval_from_parents(RzAnal * anal, RzAnalFunction *fcn, RzAnalBlock *my_bb, const char * cmp_reg) { + rz_return_val_if_fail (fcn && fcn->bbs && cmp_reg, UT64_MAX); + RzListIter *iter; + RzAnalBlock *tmp_bb; + rz_list_foreach (fcn->bbs, iter, tmp_bb) { if (tmp_bb->jump == my_bb->addr || tmp_bb->fail == my_bb->addr) { if (tmp_bb->cmpreg == cmp_reg) { if (tmp_bb->cond) { @@ -280,13 +280,13 @@ static ut64 try_get_cmpval_from_parents(RAnal * anal, RAnalFunction *fcn, RAnalB return UT64_MAX; } -static bool regs_exist(RAnalValue *src, RAnalValue *dst) { - r_return_val_if_fail (src && dst, false); +static bool regs_exist(RzAnalValue *src, RzAnalValue *dst) { + rz_return_val_if_fail (src && dst, false); return src->reg && dst->reg && src->reg->name && dst->reg->name; } // 0 if not skipped; 1 if skipped; 2 if skipped before -static int skip_hp(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, RAnalBlock *bb, ut64 addr, +static int skip_hp(RzAnal *anal, RzAnalFunction *fcn, RzAnalOp *op, RzAnalBlock *bb, ut64 addr, char *tmp_buf, int oplen, int un_idx, int *idx) { // this step is required in order to prevent infinite recursion in some cases if ((addr + un_idx - oplen) == fcn->addr) { @@ -295,7 +295,7 @@ static int skip_hp(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, RAnalBlock *bb, snprintf (tmp_buf + 5, MAX_FLG_NAME_SIZE - 6, "%"PFMT64u, addr); anal->flb.set (anal->flb.f, tmp_buf, addr, oplen); fcn->addr += oplen; - r_anal_block_relocate (bb, bb->addr + oplen, bb->size - oplen); + rz_anal_block_relocate (bb, bb->addr + oplen, bb->size - oplen); *idx = un_idx; return 1; } @@ -304,7 +304,7 @@ static int skip_hp(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, RAnalBlock *bb, return 0; } -static bool purity_checked(HtUP *ht, RAnalFunction *fcn) { +static bool purity_checked(HtUP *ht, RzAnalFunction *fcn) { bool checked; ht_up_find (ht, fcn->addr, &checked); return checked; @@ -317,15 +317,15 @@ static bool purity_checked(HtUP *ht, RAnalFunction *fcn) { * Probably worth changing it in the future, so that it marks fcn 'impure' only when it * (or any function called by fcn) MODIFIES external data. */ -static void check_purity(HtUP *ht, RAnalFunction *fcn) { - RListIter *iter; - RList *refs = r_anal_function_get_refs (fcn); - RAnalRef *ref; +static void check_purity(HtUP *ht, RzAnalFunction *fcn) { + RzListIter *iter; + RzList *refs = rz_anal_function_get_refs (fcn); + RzAnalRef *ref; ht_up_insert (ht, fcn->addr, NULL); fcn->is_pure = true; - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { if (ref->type == R_ANAL_REF_TYPE_CALL || ref->type == R_ANAL_REF_TYPE_CODE) { - RAnalFunction *called_fcn = r_anal_get_fcn_in (fcn->anal, ref->addr, 0); + RzAnalFunction *called_fcn = rz_anal_get_fcn_in (fcn->anal, ref->addr, 0); if (!called_fcn) { continue; } @@ -342,7 +342,7 @@ static void check_purity(HtUP *ht, RAnalFunction *fcn) { break; } } - r_list_free (refs); + rz_list_free (refs); } typedef struct { @@ -350,17 +350,17 @@ typedef struct { ut64 leaddr; } leaddr_pair; -static RAnalBlock *bbget(RAnal *anal, ut64 addr, bool jumpmid) { - RList *intersecting = r_anal_get_blocks_in (anal, addr); - RListIter *iter; - RAnalBlock *bb; +static RzAnalBlock *bbget(RzAnal *anal, ut64 addr, bool jumpmid) { + RzList *intersecting = rz_anal_get_blocks_in (anal, addr); + RzListIter *iter; + RzAnalBlock *bb; - RAnalBlock *ret = NULL; - r_list_foreach (intersecting, iter, bb) { + RzAnalBlock *ret = NULL; + rz_list_foreach (intersecting, iter, bb) { ut64 eaddr = bb->addr + bb->size; if (((bb->addr >= eaddr && addr == bb->addr) - || r_anal_block_contains (bb, addr)) - && (!jumpmid || r_anal_block_op_starts_at (bb, addr))) { + || rz_anal_block_contains (bb, addr)) + && (!jumpmid || rz_anal_block_op_starts_at (bb, addr))) { if (anal->opt.delay) { ut8 *buf = malloc (bb->size); if (anal->iob.read_at (anal->iob.io, bb->addr, buf, bb->size)) { @@ -368,21 +368,21 @@ static RAnalBlock *bbget(RAnal *anal, ut64 addr, bool jumpmid) { bool in_delay_slot = false; int i; for (i = last_instr_idx; i >= 0; i--) { - const ut64 off = r_anal_bb_offset_inst (bb, i); + const ut64 off = rz_anal_bb_offset_inst (bb, i); const ut64 at = bb->addr + off; if (addr <= at || off >= bb->size) { continue; } - RAnalOp op; - int size = r_anal_op (anal, &op, at, buf + off, bb->size - off, R_ANAL_OP_MASK_BASIC); + RzAnalOp op; + int size = rz_anal_op (anal, &op, at, buf + off, bb->size - off, R_ANAL_OP_MASK_BASIC); if (size > 0 && op.delay) { if (op.delay >= last_instr_idx - i) { in_delay_slot = true; } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); break; } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } if (in_delay_slot) { free (buf); @@ -395,76 +395,76 @@ static RAnalBlock *bbget(RAnal *anal, ut64 addr, bool jumpmid) { break; } } - r_list_free (intersecting); + rz_list_free (intersecting); return ret; } typedef struct { - RAnalFunction *fcn; + RzAnalFunction *fcn; const int stack_diff; } BlockTakeoverCtx; -static bool fcn_takeover_block_recursive_followthrough_cb(RAnalBlock *block, void *user) { +static bool fcn_takeover_block_recursive_followthrough_cb(RzAnalBlock *block, void *user) { BlockTakeoverCtx *ctx = user; - RAnalFunction *our_fcn = ctx->fcn; - r_anal_block_ref (block); - while (!r_list_empty (block->fcns)) { - RAnalFunction *other_fcn = r_list_first (block->fcns); + RzAnalFunction *our_fcn = ctx->fcn; + rz_anal_block_ref (block); + while (!rz_list_empty (block->fcns)) { + RzAnalFunction *other_fcn = rz_list_first (block->fcns); if (other_fcn->addr == block->addr) { return false; } // Steal vars from this block size_t i; for (i = 0; i + 1 < block->ninstr; i++) { - const ut64 addr = r_anal_bb_opaddr_i (block, i); - RPVector *vars_used = r_anal_function_get_vars_used_at (other_fcn, addr); + const ut64 addr = rz_anal_bb_opaddr_i (block, i); + RPVector *vars_used = rz_anal_function_get_vars_used_at (other_fcn, addr); if (!vars_used) { continue; } - // vars_used will get modified if r_anal_var_remove_access_at gets called - RPVector *cloned_vars_used = (RPVector *)r_vector_clone ((RVector *)vars_used); + // vars_used will get modified if rz_anal_var_remove_access_at gets called + RPVector *cloned_vars_used = (RPVector *)rz_vector_clone ((RzVector *)vars_used); void **it; - r_pvector_foreach (cloned_vars_used, it) { - RAnalVar *other_var = *it; + rz_pvector_foreach (cloned_vars_used, it) { + RzAnalVar *other_var = *it; const int actual_delta = other_var->kind == R_ANAL_VAR_KIND_SPV ? other_var->delta + ctx->stack_diff : other_var->delta + (other_fcn->bp_off - our_fcn->bp_off); - RAnalVar *our_var = r_anal_function_get_var (our_fcn, other_var->kind, actual_delta); + RzAnalVar *our_var = rz_anal_function_get_var (our_fcn, other_var->kind, actual_delta); if (!our_var) { - our_var = r_anal_function_set_var (our_fcn, actual_delta, other_var->kind, other_var->type, 0, other_var->isarg, other_var->name); + our_var = rz_anal_function_set_var (our_fcn, actual_delta, other_var->kind, other_var->type, 0, other_var->isarg, other_var->name); } if (our_var) { - RAnalVarAccess *acc = r_anal_var_get_access_at (other_var, addr); - r_anal_var_set_access (our_var, acc->reg, addr, acc->type, acc->stackptr); + RzAnalVarAccess *acc = rz_anal_var_get_access_at (other_var, addr); + rz_anal_var_set_access (our_var, acc->reg, addr, acc->type, acc->stackptr); } - r_anal_var_remove_access_at (other_var, addr); - if (r_vector_empty (&other_var->accesses)) { - r_anal_function_delete_var (other_fcn, other_var); + rz_anal_var_remove_access_at (other_var, addr); + if (rz_vector_empty (&other_var->accesses)) { + rz_anal_function_delete_var (other_fcn, other_var); } } - r_pvector_free (cloned_vars_used); + rz_pvector_free (cloned_vars_used); } // TODO: remove block->ninstr from other_fcn considering delay slots - r_anal_function_remove_block (other_fcn, block); + rz_anal_function_remove_block (other_fcn, block); } block->stackptr -= ctx->stack_diff; block->parent_stackptr -= ctx->stack_diff; - r_anal_function_add_block (our_fcn, block); + rz_anal_function_add_block (our_fcn, block); // TODO: add block->ninstr from our_fcn considering delay slots our_fcn += block->ninstr; - r_anal_block_unref (block); + rz_anal_block_unref (block); return true; } // Remove block and all of its recursive successors from all its functions and add them only to fcn -static void fcn_takeover_block_recursive(RAnalFunction *fcn, RAnalBlock *start_block) { +static void fcn_takeover_block_recursive(RzAnalFunction *fcn, RzAnalBlock *start_block) { BlockTakeoverCtx ctx = { fcn, start_block->parent_stackptr - fcn->stack}; - r_anal_block_recurse_followthrough (start_block, fcn_takeover_block_recursive_followthrough_cb, &ctx); + rz_anal_block_recurse_followthrough (start_block, fcn_takeover_block_recursive_followthrough_cb, &ctx); } -static const char *retpoline_reg(RAnal *anal, ut64 addr) { - RFlagItem *flag = anal->flag_get (anal->flb.f, addr); +static const char *retpoline_reg(RzAnal *anal, ut64 addr) { + RzFlagItem *flag = anal->flag_get (anal->flb.f, addr); if (flag) { const char *token = "x86_indirect_thunk_"; const char *thunk = strstr (flag->name, token); @@ -490,7 +490,7 @@ static const char *retpoline_reg(RAnal *anal, ut64 addr) { return NULL; } -static void analyze_retpoline(RAnal *anal, RAnalOp *op) { +static void analyze_retpoline(RzAnal *anal, RzAnalOp *op) { if (anal->opt.retpoline) { const char *rr = retpoline_reg (anal, op->jump); if (rr) { @@ -500,7 +500,7 @@ static void analyze_retpoline(RAnal *anal, RAnalOp *op) { } } -static inline bool op_is_set_bp(RAnalOp *op, const char *bp_reg, const char *sp_reg) { +static inline bool op_is_set_bp(RzAnalOp *op, const char *bp_reg, const char *sp_reg) { bool has_dst_reg = op->dst && op->dst->reg && op->dst->reg->name; bool has_src_reg = op->src[0] && op->src[0]->reg && op->src[0]->reg->name; if (has_dst_reg && has_src_reg) { @@ -513,15 +513,15 @@ static inline bool does_arch_destroys_dst(const char *arch) { return arch && (!strncmp (arch, "arm", 3) || !strcmp (arch, "riscv") || !strcmp (arch, "ppc")); } -static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int depth) { +static int fcn_recurse(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, ut64 len, int depth) { const int continue_after_jump = anal->opt.afterjmp; const int addrbytes = anal->iob.io ? anal->iob.io->addrbytes : 1; char *last_reg_mov_lea_name = NULL; - RAnalBlock *bb = NULL; - RAnalBlock *bbg = NULL; + RzAnalBlock *bb = NULL; + RzAnalBlock *bbg = NULL; int ret = R_ANAL_RET_END, skip_ret = 0; bool overlapped = false; - RAnalOp op = {0}; + RzAnalOp op = {0}; int oplen, idx = 0; static ut64 cmpval = UT64_MAX; // inherited across functions, otherwise it breaks :? bool varset = false; @@ -541,17 +541,17 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int bool is_x86 = is_arm ? false: anal->cur->arch && !strncmp (anal->cur->arch, "x86", 3); bool is_amd64 = is_x86 ? fcn->cc && !strcmp (fcn->cc, "amd64") : false; bool is_dalvik = is_x86? false: anal->cur->arch && !strncmp (anal->cur->arch, "dalvik", 6); - RRegItem *variadic_reg = NULL; + RzRegItem *variadic_reg = NULL; if (is_amd64) { - variadic_reg = r_reg_get (anal->reg, "rax", R_REG_TYPE_GPR); + variadic_reg = rz_reg_get (anal->reg, "rax", R_REG_TYPE_GPR); } bool has_variadic_reg = !!variadic_reg; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { return R_ANAL_RET_END; } if (anal->sleep) { - r_sys_usleep (anal->sleep); + rz_sys_usleep (anal->sleep); } if (depth < 1) { @@ -571,15 +571,15 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int return R_ANAL_RET_ERROR; // MUST BE TOO DEEP } - RAnalFunction *fcn_at_addr = r_anal_get_function_at (anal, addr); + RzAnalFunction *fcn_at_addr = rz_anal_get_function_at (anal, addr); if (fcn_at_addr && fcn_at_addr != fcn) { return R_ANAL_RET_ERROR; // MUST BE NOT FOUND } - RAnalBlock *existing_bb = bbget (anal, addr, anal->opt.jmpmid && is_x86); + RzAnalBlock *existing_bb = bbget (anal, addr, anal->opt.jmpmid && is_x86); if (existing_bb) { - bool existing_in_fcn = r_list_contains (existing_bb->fcns, fcn); - existing_bb = r_anal_block_split (existing_bb, addr); + bool existing_in_fcn = rz_list_contains (existing_bb->fcns, fcn); + existing_bb = rz_anal_block_split (existing_bb, addr); if (!existing_in_fcn && existing_bb) { if (existing_bb->addr == fcn->addr) { // our function starts directly there, so we steal what is ours! @@ -587,23 +587,23 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int } } if (existing_bb) { - r_anal_block_unref (existing_bb); + rz_anal_block_unref (existing_bb); } if (anal->opt.recont) { return R_ANAL_RET_END; } if (anal->verbose) { - eprintf ("r_anal_fcn_bb() fails at 0x%"PFMT64x ".\n", addr); + eprintf ("rz_anal_fcn_bb() fails at 0x%"PFMT64x ".\n", addr); } return R_ANAL_RET_ERROR; // MUST BE NOT DUP } bb = fcn_append_basic_block (anal, fcn, addr); // we checked before whether there is a bb at addr, so the create should have succeeded - r_return_val_if_fail (bb, R_ANAL_RET_ERROR); + rz_return_val_if_fail (bb, R_ANAL_RET_ERROR); if (!anal->leaddrs) { - anal->leaddrs = r_list_newf (free); + anal->leaddrs = rz_list_newf (free); if (!anal->leaddrs) { eprintf ("Cannot create leaddr list\n"); gotoBeach (R_ANAL_RET_ERROR); @@ -618,14 +618,14 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int if (anal->limit && addr + idx < anal->limit->from) { gotoBeach (R_ANAL_RET_END); } - RAnalFunction *tmp_fcn = r_anal_get_fcn_in (anal, addr, 0); + RzAnalFunction *tmp_fcn = rz_anal_get_fcn_in (anal, addr, 0); if (tmp_fcn) { // Checks if var is already analyzed at given addr - RList *list = r_anal_var_all_list (anal, tmp_fcn); - if (!r_list_empty (list)) { + RzList *list = rz_anal_var_all_list (anal, tmp_fcn); + if (!rz_list_empty (list)) { varset = true; } - r_list_free (list); + rz_list_free (list); } ut64 movdisp = UT64_MAX; // used by jmptbl when coded as "mov reg,[R*4+B]" ut8 buf[32]; // 32 bytes is enough to hold any instruction. @@ -660,7 +660,7 @@ static int fcn_recurse(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int break; } repeat: - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } ut32 at_delta = addrbytes * idx; @@ -678,8 +678,8 @@ repeat: } gotoBeach (R_ANAL_RET_ERROR) } - r_anal_op_fini (&op); - if ((oplen = r_anal_op (anal, &op, at, buf, bytes_read, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) < 1) { + rz_anal_op_fini (&op); + if ((oplen = rz_anal_op (anal, &op, at, buf, bytes_read, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) < 1) { if (anal->verbose) { eprintf ("Invalid instruction at 0x%"PFMT64x" with %d bits\n", at, anal->bits); } @@ -692,10 +692,10 @@ repeat: bool has_stack_regs = bp_reg && sp_reg; if (anal->opt.nopskip && fcn->addr == at) { - RFlagItem *fi = anal->flb.get_at (anal->flb.f, addr, false); + RzFlagItem *fi = anal->flb.get_at (anal->flb.f, addr, false); if (!fi || strncmp (fi->name, "sym.", 4)) { if ((addr + delay.un_idx - oplen) == fcn->addr) { - if (r_anal_block_relocate (bb, bb->addr + oplen, bb->size - oplen)) { + if (rz_anal_block_relocate (bb, bb->addr + oplen, bb->size - oplen)) { fcn->addr += oplen; idx = delay.un_idx; goto repeat; @@ -706,7 +706,7 @@ repeat: case R_ANAL_OP_TYPE_TRAP: case R_ANAL_OP_TYPE_ILL: case R_ANAL_OP_TYPE_NOP: - if (r_anal_block_relocate (bb, at + op.size, bb->size)) { + if (rz_anal_block_relocate (bb, at + op.size, bb->size)) { addr = at + op.size; fcn->addr = addr; goto repeat; @@ -714,7 +714,7 @@ repeat: } } if (op.hint.new_bits) { - r_anal_hint_set_bits (anal, op.jump, op.hint.new_bits); + rz_anal_hint_set_bits (anal, op.jump, op.hint.new_bits); } if (idx > 0 && !overlapped) { bbg = bbget (anal, at, anal->opt.jmpmid && is_x86); @@ -724,8 +724,8 @@ repeat: // This happens when we purposefully walked over another block and overlapped it // and now we hit an offset where the instructions match again. // So we need to split the overwalked block. - RAnalBlock *split = r_anal_block_split (bbg, at); - r_anal_block_unref (split); + RzAnalBlock *split = rz_anal_block_split (bbg, at); + rz_anal_block_unref (split); } overlapped = true; if (anal->verbose) { @@ -738,28 +738,28 @@ repeat: if (newbbsize > MAX_FCN_SIZE) { gotoBeach (R_ANAL_RET_ERROR); } - r_anal_bb_set_offset (bb, bb->ninstr++, at - bb->addr); - r_anal_block_set_size (bb, newbbsize); + rz_anal_bb_set_offset (bb, bb->ninstr++, at - bb->addr); + rz_anal_block_set_size (bb, newbbsize); fcn->ninstr++; } if (anal->opt.trycatch) { const char *name = anal->coreb.getName (anal->coreb.core, at); if (name) { - if (r_str_startswith (name, "try.") && r_str_endswith (name, ".from")) { + if (rz_str_startswith (name, "try.") && rz_str_endswith (name, ".from")) { char *handle = strdup (name); - // handle = r_str_replace (handle, ".from", ".to", 0); + // handle = rz_str_replace (handle, ".from", ".to", 0); ut64 from_addr = anal->coreb.numGet (anal->coreb.core, handle); - handle = r_str_replace (handle, ".from", ".catch", 0); + handle = rz_str_replace (handle, ".from", ".catch", 0); ut64 handle_addr = anal->coreb.numGet (anal->coreb.core, handle); bb->jump = at + oplen; if (from_addr != bb->addr) { bb->fail = handle_addr; - ret = r_anal_fcn_bb (anal, fcn, handle_addr, depth); + ret = rz_anal_fcn_bb (anal, fcn, handle_addr, depth); eprintf ("(%s) 0x%08"PFMT64x"\n", handle, handle_addr); if (bb->size == 0) { - r_anal_function_remove_block (fcn, bb); + rz_anal_function_remove_block (fcn, bb); } - r_anal_block_unref (bb); + rz_anal_block_unref (bb); bb = fcn_append_basic_block (anal, fcn, addr); if (!bb) { gotoBeach (R_ANAL_RET_ERROR); @@ -810,11 +810,11 @@ repeat: // But we also already counted this instruction in the // size of the current basic block, so we need to fix that if (delay.adjust) { - r_anal_block_set_size (bb, (ut64)addrbytes * (ut64)delay.after); + rz_anal_block_set_size (bb, (ut64)addrbytes * (ut64)delay.after); fcn->ninstr--; if (anal->verbose) { eprintf ("Correct for branch delay @ %08"PFMT64x " bb.addr=%08"PFMT64x " corrected.bb=%"PFMT64u" f.uncorr=%"PFMT64u"\n", - addr + idx - oplen, bb->addr, bb->size, r_anal_function_linear_size (fcn)); + addr + idx - oplen, bb->addr, bb->size, rz_anal_function_linear_size (fcn)); } } // Next time, we go to the opcode after the delay count @@ -842,7 +842,7 @@ repeat: } if (op.ptr && op.ptr != UT64_MAX && op.ptr != UT32_MAX) { // swapped parameters wtf - r_anal_xrefs_set (anal, op.addr, op.ptr, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (anal, op.addr, op.ptr, R_ANAL_REF_TYPE_DATA); } analyze_retpoline (anal, &op); switch (op.type & R_ANAL_OP_TYPE_MASK) { @@ -850,8 +850,8 @@ repeat: case R_ANAL_OP_TYPE_MOV: last_is_reg_mov_lea = false; if (is_arm) { // mov lr, pc - const char *esil = r_strbuf_get (&op.esil); - if (!r_str_cmp (esil, "pc,lr,=", -1)) { + const char *esil = rz_strbuf_get (&op.esil); + if (!rz_str_cmp (esil, "pc,lr,=", -1)) { last_is_mov_lr_pc = true; } } @@ -897,7 +897,7 @@ repeat: } pair->op_addr = op.addr; pair->leaddr = op.ptr; // XXX movdisp is dupped but seems to be trashed sometimes(?), better track leaddr separately - r_list_append (anal->leaddrs, pair); + rz_list_append (anal->leaddrs, pair); } if (has_stack_regs && op_is_set_bp (&op, bp_reg, sp_reg)) { fcn->bp_off = fcn->stack - op.src[0]->delta; @@ -922,7 +922,7 @@ repeat: } } if (anal->opt.jmptbl) { - RAnalOp jmp_aop = {0}; + RzAnalOp jmp_aop = {0}; ut64 jmptbl_addr = op.ptr; ut64 casetbl_addr = op.ptr; if (is_delta_pointer_table (anal, fcn, op.addr, op.ptr, &jmptbl_addr, &casetbl_addr, &jmp_aop)) { @@ -943,13 +943,13 @@ repeat: } } } - r_anal_op_fini (&jmp_aop); + rz_anal_op_fini (&jmp_aop); } break; case R_ANAL_OP_TYPE_LOAD: if (anal->opt.loads) { if (anal->iob.is_valid_offset (anal->iob.io, op.ptr, 0)) { - r_meta_set (anal, R_META_TYPE_DATA, op.ptr, 4, ""); + rz_meta_set (anal, R_META_TYPE_DATA, op.ptr, 4, ""); } } break; @@ -957,7 +957,7 @@ repeat: case R_ANAL_OP_TYPE_ADD: if (anal->opt.ijmp) { if ((op.size + 4 <= bytes_read) && !memcmp (buf + op.size, "\x00\x00\x00\x00", 4)) { - r_anal_block_set_size (bb, bb->size - oplen); + rz_anal_block_set_size (bb, bb->size - oplen); op.type = R_ANAL_OP_TYPE_RET; gotoBeach (R_ANAL_RET_END); } @@ -975,26 +975,26 @@ repeat: gotoBeach (R_ANAL_RET_END); } { - RFlagItem *fi = anal->flb.get_at (anal->flb.f, op.jump, false); + RzFlagItem *fi = anal->flb.get_at (anal->flb.f, op.jump, false); if (fi && strstr (fi->name, "imp.")) { gotoBeach (R_ANAL_RET_END); } } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { gotoBeach (R_ANAL_RET_END); } if (anal->opt.jmpref) { - (void) r_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CODE); + (void) rz_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CODE); } if (!anal->opt.jmpabove && (op.jump < fcn->addr)) { gotoBeach (R_ANAL_RET_END); } - if (r_anal_noreturn_at (anal, op.jump)) { + if (rz_anal_noreturn_at (anal, op.jump)) { gotoBeach (R_ANAL_RET_END); } { bool must_eob = true; - RIOMap *map = anal->iob.map_get (anal->iob.io, addr); + RzIOMap *map = anal->iob.map_get (anal->iob.io, addr); if (map) { must_eob = (op.jump < map->itv.addr || op.jump >= map->itv.addr + map->itv.size); } @@ -1013,7 +1013,7 @@ repeat: bb->jump = op.jump; bb->fail = UT64_MAX; } - ret = r_anal_fcn_bb (anal, fcn, op.jump, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.jump, depth); int tc = anal->opt.tailcall; if (tc) { // eprintf ("TAIL CALL AT 0x%llx\n", op.addr); @@ -1021,11 +1021,11 @@ repeat: if (tc < 0) { ut8 buf[32]; (void)anal->iob.read_at (anal->iob.io, op.jump, (ut8 *) buf, sizeof (buf)); - if (r_anal_is_prelude (anal, buf, sizeof (buf))) { + if (rz_anal_is_prelude (anal, buf, sizeof (buf))) { fcn_recurse (anal, fcn, op.jump, anal->opt.bb_max_size, depth - 1); } } else if (R_ABS (diff) > tc) { - (void) r_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CALL); + (void) rz_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CALL); fcn_recurse (anal, fcn, op.jump, anal->opt.bb_max_size, depth - 1); gotoBeach (R_ANAL_RET_END); } @@ -1045,7 +1045,7 @@ repeat: cmpval = val; bb->cmpval = cmpval; bb->cmpreg = op.reg; - bb->cond = r_anal_cond_new_from_op (&op); + bb->cond = rz_anal_cond_new_from_op (&op); } } break; @@ -1054,7 +1054,7 @@ repeat: case R_ANAL_OP_TYPE_RCJMP: case R_ANAL_OP_TYPE_UCJMP: if (anal->opt.cjmpref) { - (void) r_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CODE); + (void) rz_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CODE); } if (!overlapped) { bb->jump = op.jump; @@ -1087,14 +1087,14 @@ repeat: } int saved_stack = fcn->stack; if (continue_after_jump) { - r_anal_fcn_bb (anal, fcn, op.jump, depth); + rz_anal_fcn_bb (anal, fcn, op.jump, depth); fcn->stack = saved_stack; - ret = r_anal_fcn_bb (anal, fcn, op.fail, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.fail, depth); fcn->stack = saved_stack; } else { - ret = r_anal_fcn_bb (anal, fcn, op.jump, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.jump, depth); fcn->stack = saved_stack; - ret = r_anal_fcn_bb (anal, fcn, op.fail, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.fail, depth); fcn->stack = saved_stack; if (op.jump < fcn->addr) { if (!overlapped) { @@ -1119,10 +1119,10 @@ repeat: case R_ANAL_OP_TYPE_IRCALL: /* call [dst] */ // XXX: this is TYPE_MCALL or indirect-call - (void) r_anal_xrefs_set (anal, op.addr, op.ptr, R_ANAL_REF_TYPE_CALL); + (void) rz_anal_xrefs_set (anal, op.addr, op.ptr, R_ANAL_REF_TYPE_CALL); - if (r_anal_noreturn_at (anal, op.ptr)) { - RAnalFunction *f = r_anal_get_function_at (anal, op.ptr); + if (rz_anal_noreturn_at (anal, op.ptr)) { + RzAnalFunction *f = rz_anal_get_function_at (anal, op.ptr); if (f) { f->is_noreturn = true; } @@ -1132,10 +1132,10 @@ repeat: case R_ANAL_OP_TYPE_CCALL: case R_ANAL_OP_TYPE_CALL: /* call dst */ - (void) r_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CALL); + (void) rz_anal_xrefs_set (anal, op.addr, op.jump, R_ANAL_REF_TYPE_CALL); - if (r_anal_noreturn_at (anal, op.jump)) { - RAnalFunction *f = r_anal_get_function_at (anal, op.jump); + if (rz_anal_noreturn_at (anal, op.jump)) { + RzAnalFunction *f = rz_anal_get_function_at (anal, op.jump); if (f) { f->is_noreturn = true; } @@ -1163,9 +1163,9 @@ repeat: ut64 table_size, default_case; if (try_get_jmptbl_info (anal, fcn, op.addr, bb, &table_size, &default_case)) { bool case_table = false; - RAnalOp prev_op; + RzAnalOp prev_op; anal->iob.read_at (anal->iob.io, op.addr - op.size, buf, sizeof (buf)); - if (r_anal_op (anal, &prev_op, op.addr - op.size, buf, sizeof (buf), R_ANAL_OP_MASK_VAL) > 0) { + if (rz_anal_op (anal, &prev_op, op.addr - op.size, buf, sizeof (buf), R_ANAL_OP_MASK_VAL) > 0) { bool prev_op_has_dst_name = prev_op.dst && prev_op.dst->reg && prev_op.dst->reg->name; bool op_has_src_name = op.src[0] && op.src[0]->reg && op.src[0]->reg->name; bool same_reg = (op.ireg && prev_op_has_dst_name && !strcmp (op.ireg, prev_op.dst->reg->name)) @@ -1178,7 +1178,7 @@ repeat: } } } - r_anal_op_fini (&prev_op); + rz_anal_op_fini (&prev_op); if (!case_table) { ret = try_walkthrough_jmptbl (anal, fcn, bb, depth, op.addr, op.ptr, op.ptr, anal->bits >> 3, table_size, default_case, ret); } @@ -1191,11 +1191,11 @@ repeat: } else if (movdisp == 0) { ut64 jmptbl_base = UT64_MAX; ut64 lea_op_off = UT64_MAX; - RListIter *lea_op_iter = NULL; - RListIter *iter; + RzListIter *lea_op_iter = NULL; + RzListIter *iter; leaddr_pair *pair; // find nearest candidate leaddr before op.addr - r_list_foreach (anal->leaddrs, iter, pair) { + rz_list_foreach (anal->leaddrs, iter, pair) { if (pair->op_addr >= op.addr) { continue; } @@ -1206,7 +1206,7 @@ repeat: } } if (lea_op_iter) { - r_list_delete (anal->leaddrs, lea_op_iter); + rz_list_delete (anal->leaddrs, lea_op_iter); } ut64 table_size = cmpval + 1; ret = try_walkthrough_jmptbl (anal, fcn, bb, depth, op.addr, jmptbl_base, jmptbl_base, 4, table_size, -1, ret); @@ -1253,13 +1253,13 @@ repeat: } if (anal->opt.ijmp) { if (continue_after_jump) { - r_anal_fcn_bb (anal, fcn, op.jump, depth); - ret = r_anal_fcn_bb (anal, fcn, op.fail, depth); + rz_anal_fcn_bb (anal, fcn, op.jump, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.fail, depth); if (overlapped) { goto analopfinish; } } - if (r_anal_noreturn_at (anal, op.jump) || op.eob) { + if (rz_anal_noreturn_at (anal, op.jump) || op.eob) { goto analopfinish; } } else { @@ -1276,7 +1276,7 @@ analopfinish: last_is_push = true; last_push_addr = op.val; if (anal->iob.is_valid_offset (anal->iob.io, last_push_addr, 1)) { - (void) r_anal_xrefs_set (anal, op.addr, last_push_addr, R_ANAL_REF_TYPE_DATA); + (void) rz_anal_xrefs_set (anal, op.addr, last_push_addr, R_ANAL_REF_TYPE_DATA); } break; case R_ANAL_OP_TYPE_UPUSH: @@ -1285,7 +1285,7 @@ analopfinish: last_is_push = true; last_push_addr = last_reg_mov_lea_val; if (anal->iob.is_valid_offset (anal->iob.io, last_push_addr, 1)) { - (void) r_anal_xrefs_set (anal, op.addr, last_push_addr, R_ANAL_REF_TYPE_DATA); + (void) rz_anal_xrefs_set (anal, op.addr, last_push_addr, R_ANAL_REF_TYPE_DATA); } } break; @@ -1297,14 +1297,14 @@ analopfinish: op.type = R_ANAL_OP_TYPE_JMP; op.jump = last_push_addr; bb->jump = op.jump; - ret = r_anal_fcn_bb (anal, fcn, op.jump, depth); + ret = rz_anal_fcn_bb (anal, fcn, op.jump, depth); goto beach; } if (!op.cond) { if (anal->verbose) { eprintf ("RET 0x%08"PFMT64x ". overlap=%s %"PFMT64u" %"PFMT64u"\n", - addr + delay.un_idx - oplen, r_str_bool (overlapped), - bb->size, r_anal_function_linear_size (fcn)); + addr + delay.un_idx - oplen, rz_str_bool (overlapped), + bb->size, rz_anal_function_linear_size (fcn)); } gotoBeach (R_ANAL_RET_END); } @@ -1323,7 +1323,7 @@ analopfinish: } } if (anal->opt.vars && !varset) { - r_anal_extract_vars (anal, fcn, &op); + rz_anal_extract_vars (anal, fcn, &op); } if (op.type != R_ANAL_OP_TYPE_MOV && op.type != R_ANAL_OP_TYPE_CMOV && op.type != R_ANAL_OP_TYPE_LEA) { last_is_reg_mov_lea = false; @@ -1335,7 +1335,7 @@ analopfinish: last_is_mov_lr_pc = false; } if (has_variadic_reg && !fcn->is_variadic) { - variadic_reg = r_reg_get (anal->reg, "rax", R_REG_TYPE_GPR); + variadic_reg = rz_reg_get (anal->reg, "rax", R_REG_TYPE_GPR); bool dst_is_variadic = op.dst && op.dst->reg && variadic_reg && op.dst->reg->offset == variadic_reg->offset; bool op_is_cmp = (op.type == R_ANAL_OP_TYPE_CMP) || op.type == R_ANAL_OP_TYPE_ACMP; @@ -1349,30 +1349,30 @@ analopfinish: } } beach: - r_anal_op_fini (&op); + rz_anal_op_fini (&op); R_FREE (last_reg_mov_lea_name); if (bb && bb->size == 0) { - r_anal_function_remove_block (fcn, bb); + rz_anal_function_remove_block (fcn, bb); } - r_anal_block_unref (bb); + rz_anal_block_unref (bb); return ret; } -R_API int r_anal_fcn_bb(RAnal *anal, RAnalFunction *fcn, ut64 addr, int depth) { +RZ_API int rz_anal_fcn_bb(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, int depth) { return fcn_recurse (anal, fcn, addr, anal->opt.bb_max_size, depth - 1); } -R_API bool r_anal_check_fcn(RAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 low, ut64 high) { - RAnalOp op = { +RZ_API bool rz_anal_check_fcn(RzAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 low, ut64 high) { + RzAnalOp op = { 0 }; int i, oplen, opcnt = 0, pushcnt = 0, movcnt = 0, brcnt = 0; - if (r_anal_is_prelude (anal, buf, bufsz)) { + if (rz_anal_is_prelude (anal, buf, bufsz)) { return true; } for (i = 0; i < bufsz && opcnt < 10; i += oplen, opcnt++) { - r_anal_op_fini (&op); - if ((oplen = r_anal_op (anal, &op, addr + i, buf + i, bufsz - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT)) < 1) { + rz_anal_op_fini (&op); + if ((oplen = rz_anal_op (anal, &op, addr + i, buf + i, bufsz - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT)) < 1) { return false; } switch (op.type) { @@ -1402,57 +1402,57 @@ R_API bool r_anal_check_fcn(RAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 l return (pushcnt + movcnt + brcnt > 5); } -R_API void r_anal_trim_jmprefs(RAnal *anal, RAnalFunction *fcn) { - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); - RListIter *iter; +RZ_API void rz_anal_trim_jmprefs(RzAnal *anal, RzAnalFunction *fcn) { + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); + RzListIter *iter; const bool is_x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86"); // HACK - r_list_foreach (refs, iter, ref) { - if (ref->type == R_ANAL_REF_TYPE_CODE && r_anal_function_contains (fcn, ref->addr) - && (!is_x86 || !r_anal_function_contains (fcn, ref->at))) { - r_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type); + rz_list_foreach (refs, iter, ref) { + if (ref->type == R_ANAL_REF_TYPE_CODE && rz_anal_function_contains (fcn, ref->addr) + && (!is_x86 || !rz_anal_function_contains (fcn, ref->at))) { + rz_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type); } } - r_list_free (refs); + rz_list_free (refs); } -R_API void r_anal_del_jmprefs(RAnal *anal, RAnalFunction *fcn) { - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); - RListIter *iter; +RZ_API void rz_anal_del_jmprefs(RzAnal *anal, RzAnalFunction *fcn) { + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); + RzListIter *iter; - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { if (ref->type == R_ANAL_REF_TYPE_CODE) { - r_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type); + rz_anal_xrefs_deln (anal, ref->at, ref->addr, ref->type); } } - r_list_free (refs); + rz_list_free (refs); } /* Does NOT invalidate read-ahead cache. */ -R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int reftype) { - RPVector *metas = r_meta_get_all_in(anal, addr, R_META_TYPE_ANY); +RZ_API int rz_anal_fcn(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, ut64 len, int reftype) { + RPVector *metas = rz_meta_get_all_in(anal, addr, R_META_TYPE_ANY); void **it; - r_pvector_foreach (metas, it) { - RAnalMetaItem *meta = ((RIntervalNode *)*it)->data; + rz_pvector_foreach (metas, it) { + RzAnalMetaItem *meta = ((RIntervalNode *)*it)->data; switch (meta->type) { case R_META_TYPE_DATA: case R_META_TYPE_STRING: case R_META_TYPE_FORMAT: - r_pvector_free (metas); + rz_pvector_free (metas); return 0; default: break; } } - r_pvector_free (metas); + rz_pvector_free (metas); if (anal->opt.norevisit) { if (!anal->visited) { anal->visited = set_u_new (); } if (set_u_contains (anal->visited, addr)) { - eprintf ("r_anal_fcn: anal.norevisit at 0x%08"PFMT64x" %c\n", addr, reftype); + eprintf ("rz_anal_fcn: anal.norevisit at 0x%08"PFMT64x" %c\n", addr, reftype); return R_ANAL_RET_END; } set_u_add (anal->visited, addr); @@ -1473,21 +1473,21 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int r const int shadow_store = 0x28; // First 4 args + retaddr fcn->stack = fcn->maxstack = fcn->reg_save_area = shadow_store; } - int ret = r_anal_fcn_bb (anal, fcn, addr, anal->opt.depth); + int ret = rz_anal_fcn_bb (anal, fcn, addr, anal->opt.depth); if (ret < 0) { if (anal->verbose) { eprintf ("Failed to analyze basic block at 0x%"PFMT64x"\n", addr); } } - if (anal->opt.endsize && ret == R_ANAL_RET_END && r_anal_function_realsize (fcn)) { // cfg analysis completed - RListIter *iter; - RAnalBlock *bb; + if (anal->opt.endsize && ret == R_ANAL_RET_END && rz_anal_function_realsize (fcn)) { // cfg analysis completed + RzListIter *iter; + RzAnalBlock *bb; ut64 endaddr = fcn->addr; const bool is_x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86"); // set function size as length of continuous sequence of bbs - r_list_sort (fcn->bbs, &cmpaddr); - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_sort (fcn->bbs, &cmpaddr); + rz_list_foreach (fcn->bbs, iter, bb) { if (endaddr == bb->addr) { endaddr += bb->size; } else if ((endaddr < bb->addr && bb->addr - endaddr < BB_ALIGN) @@ -1500,79 +1500,79 @@ R_API int r_anal_fcn(RAnal *anal, RAnalFunction *fcn, ut64 addr, ut64 len, int r } #if JAYRO_04 // fcn is not yet in anal => pass NULL - r_anal_function_resize (fcn, endaddr - fcn->addr); + rz_anal_function_resize (fcn, endaddr - fcn->addr); #endif - r_anal_trim_jmprefs (anal, fcn); + rz_anal_trim_jmprefs (anal, fcn); } return ret; } // XXX deprecate -R_API int r_anal_fcn_del_locs(RAnal *anal, ut64 addr) { - RListIter *iter, *iter2; - RAnalFunction *fcn, *f = r_anal_get_fcn_in (anal, addr, R_ANAL_FCN_TYPE_ROOT); +RZ_API int rz_anal_fcn_del_locs(RzAnal *anal, ut64 addr) { + RzListIter *iter, *iter2; + RzAnalFunction *fcn, *f = rz_anal_get_fcn_in (anal, addr, R_ANAL_FCN_TYPE_ROOT); if (!f) { return false; } - r_list_foreach_safe (anal->fcns, iter, iter2, fcn) { + rz_list_foreach_safe (anal->fcns, iter, iter2, fcn) { if (fcn->type != R_ANAL_FCN_TYPE_LOC) { continue; } - if (r_anal_function_contains (fcn, addr)) { - r_anal_function_delete (fcn); + if (rz_anal_function_contains (fcn, addr)) { + rz_anal_function_delete (fcn); } } - r_anal_fcn_del (anal, addr); + rz_anal_fcn_del (anal, addr); return true; } -R_API int r_anal_fcn_del(RAnal *a, ut64 addr) { - RAnalFunction *fcn; - RListIter *iter, *iter_tmp; - r_list_foreach_safe (a->fcns, iter, iter_tmp, fcn) { +RZ_API int rz_anal_fcn_del(RzAnal *a, ut64 addr) { + RzAnalFunction *fcn; + RzListIter *iter, *iter_tmp; + rz_list_foreach_safe (a->fcns, iter, iter_tmp, fcn) { D eprintf ("fcn at %llx %llx\n", fcn->addr, addr); if (fcn->addr == addr) { - r_anal_function_delete (fcn); + rz_anal_function_delete (fcn); } } return true; } -R_API RAnalFunction *r_anal_get_fcn_in(RAnal *anal, ut64 addr, int type) { - RList *list = r_anal_get_functions_in (anal, addr); - RAnalFunction *ret = NULL; - if (list && !r_list_empty (list)) { +RZ_API RzAnalFunction *rz_anal_get_fcn_in(RzAnal *anal, ut64 addr, int type) { + RzList *list = rz_anal_get_functions_in (anal, addr); + RzAnalFunction *ret = NULL; + if (list && !rz_list_empty (list)) { if (type == R_ANAL_FCN_TYPE_ROOT) { - RAnalFunction *fcn; - RListIter *iter; - r_list_foreach (list, iter, fcn) { + RzAnalFunction *fcn; + RzListIter *iter; + rz_list_foreach (list, iter, fcn) { if (fcn->addr == addr) { ret = fcn; break; } } } else { - ret = r_list_first (list); + ret = rz_list_first (list); } } - r_list_free (list); + rz_list_free (list); return ret; } -R_API RAnalFunction *r_anal_get_fcn_in_bounds(RAnal *anal, ut64 addr, int type) { - RAnalFunction *fcn, *ret = NULL; - RListIter *iter; +RZ_API RzAnalFunction *rz_anal_get_fcn_in_bounds(RzAnal *anal, ut64 addr, int type) { + RzAnalFunction *fcn, *ret = NULL; + RzListIter *iter; if (type == R_ANAL_FCN_TYPE_ROOT) { - r_list_foreach (anal->fcns, iter, fcn) { + rz_list_foreach (anal->fcns, iter, fcn) { if (addr == fcn->addr) { return fcn; } } return NULL; } - r_list_foreach (anal->fcns, iter, fcn) { + rz_list_foreach (anal->fcns, iter, fcn) { if (!type || (fcn && fcn->type & type)) { - if (r_anal_function_contains (fcn, addr)) { + if (rz_anal_function_contains (fcn, addr)) { return fcn; } } @@ -1580,61 +1580,61 @@ R_API RAnalFunction *r_anal_get_fcn_in_bounds(RAnal *anal, ut64 addr, int type) return ret; } -R_API RAnalFunction *r_anal_get_function_byname(RAnal *a, const char *name) { +RZ_API RzAnalFunction *rz_anal_get_function_byname(RzAnal *a, const char *name) { bool found = false; - RAnalFunction *f = ht_pp_find (a->ht_name_fun, name, &found); + RzAnalFunction *f = ht_pp_find (a->ht_name_fun, name, &found); if (f && found) { return f; } return NULL; } -/* rename RAnalFunctionBB.add() */ -R_API bool r_anal_fcn_add_bb(RAnal *a, RAnalFunction *fcn, ut64 addr, ut64 size, ut64 jump, ut64 fail, R_BORROW RAnalDiff *diff) { +/* rename RzAnalFunctionBB.add() */ +RZ_API bool rz_anal_fcn_add_bb(RzAnal *a, RzAnalFunction *fcn, ut64 addr, ut64 size, ut64 jump, ut64 fail, R_BORROW RzAnalDiff *diff) { D eprintf ("Add bb\n"); if (size == 0) { // empty basic blocks allowed? eprintf ("Warning: empty basic block at 0x%08"PFMT64x" is not allowed. pending discussion.\n", addr); - r_warn_if_reached (); + rz_warn_if_reached (); return false; } if (size > a->opt.bb_max_size) { eprintf ("Warning: can't allocate such big bb of %"PFMT64d" bytes at 0x%08"PFMT64x"\n", (st64)size, addr); - r_warn_if_reached (); + rz_warn_if_reached (); return false; } - RAnalBlock *block = r_anal_get_block_at (a, addr); + RzAnalBlock *block = rz_anal_get_block_at (a, addr); if (block) { - r_anal_delete_block (block); + rz_anal_delete_block (block); block = NULL; } const bool is_x86 = a->cur->arch && !strcmp (a->cur->arch, "x86"); // TODO fix this x86-ism if (is_x86) { - r_anal_fcn_invalidate_read_ahead_cache (); + rz_anal_fcn_invalidate_read_ahead_cache (); fcn_recurse (a, fcn, addr, size, 1); - block = r_anal_get_block_at (a, addr); + block = rz_anal_get_block_at (a, addr); if (block) { - r_anal_block_set_size (block, size); + rz_anal_block_set_size (block, size); } } else { - block = r_anal_create_block (a, addr, size); + block = rz_anal_create_block (a, addr, size); } if (!block) { - D eprintf ("Warning: r_anal_fcn_add_bb failed in fcn 0x%08"PFMT64x" at 0x%08"PFMT64x"\n", fcn->addr, addr); + D eprintf ("Warning: rz_anal_fcn_add_bb failed in fcn 0x%08"PFMT64x" at 0x%08"PFMT64x"\n", fcn->addr, addr); return false; } - r_anal_function_add_block (fcn, block); + rz_anal_function_add_block (fcn, block); block->jump = jump; block->fail = fail; block->fail = fail; if (diff) { if (!block->diff) { - block->diff = r_anal_diff_new (); + block->diff = rz_anal_diff_new (); } if (block->diff) { block->diff->type = diff->type; @@ -1648,11 +1648,11 @@ R_API bool r_anal_fcn_add_bb(RAnal *a, RAnalFunction *fcn, ut64 addr, ut64 size, return true; } -R_API int r_anal_function_loops(RAnalFunction *fcn) { - RListIter *iter; - RAnalBlock *bb; +RZ_API int rz_anal_function_loops(RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalBlock *bb; ut32 loops = 0; - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->jump != UT64_MAX && bb->jump < bb->addr) { loops ++; } @@ -1663,19 +1663,19 @@ R_API int r_anal_function_loops(RAnalFunction *fcn) { return loops; } -R_API int r_anal_function_complexity(RAnalFunction *fcn) { +RZ_API int rz_anal_function_complexity(RzAnalFunction *fcn) { /* CC = E - N + 2P E = the number of edges of the graph. N = the number of nodes of the graph. P = the number of connected components (exit nodes). */ - RAnal *anal = fcn->anal; + RzAnal *anal = fcn->anal; int E = 0, N = 0, P = 0; - RListIter *iter; - RAnalBlock *bb; + RzListIter *iter; + RzAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { N++; // nodes if ((!anal || anal->verbose) && bb->jump == UT64_MAX && bb->fail != UT64_MAX) { eprintf ("Warning: invalid bb jump/fail pair at 0x%08"PFMT64x" (fcn 0x%08"PFMT64x"\n", bb->addr, fcn->addr); @@ -1689,7 +1689,7 @@ R_API int r_anal_function_complexity(RAnalFunction *fcn) { } } if (bb->switch_op && bb->switch_op->cases) { - E += r_list_length (bb->switch_op->cases); + E += rz_list_length (bb->switch_op->cases); } } @@ -1697,18 +1697,18 @@ R_API int r_anal_function_complexity(RAnalFunction *fcn) { if (result < 1 && (!anal || anal->verbose)) { eprintf ("Warning: CC = E(%d) - N(%d) + (2 * P(%d)) < 1 at 0x%08"PFMT64x"\n", E, N, P, fcn->addr); } - // r_return_val_if_fail (result > 0, 0); + // rz_return_val_if_fail (result > 0, 0); return result; } // tfj and afsj call this function -R_API char *r_anal_function_get_json(RAnalFunction *function) { +RZ_API char *rz_anal_function_get_json(RzAnalFunction *function) { PJ *pj = pj_new (); - RAnal *a = function->anal; + RzAnal *a = function->anal; char *args = strdup (""); - char *sdb_ret = r_str_newf ("func.%s.ret", function->name); - char *sdb_args = r_str_newf ("func.%s.args", function->name); - // RList *args_list = r_list_newf ((RListFree) free); + char *sdb_ret = rz_str_newf ("func.%s.ret", function->name); + char *sdb_args = rz_str_newf ("func.%s.args", function->name); + // RzList *args_list = rz_list_newf ((RzListFree) free); unsigned int i; const char *ret_type = sdb_const_get (a->sdb_types, sdb_ret, 0); const char *argc_str = sdb_const_get (a->sdb_types, sdb_args, 0); @@ -1717,7 +1717,7 @@ R_API char *r_anal_function_get_json(RAnalFunction *function) { pj_o (pj); pj_ks (pj, "name", function->name); - const bool no_return = r_anal_noreturn_at_addr (a, function->addr); + const bool no_return = rz_anal_noreturn_at_addr (a, function->addr); pj_kb (pj, "noreturn", no_return); pj_ks (pj, "ret", ret_type?ret_type: "void"); if (function->cc) { @@ -1727,14 +1727,14 @@ R_API char *r_anal_function_get_json(RAnalFunction *function) { pj_a (pj); for (i = 0; i < argc; i++) { pj_o (pj); - char *sdb_arg_i = r_str_newf ("func.%s.arg.%d", function->name, i); + char *sdb_arg_i = rz_str_newf ("func.%s.arg.%d", function->name, i); char *arg_i = sdb_get (a->sdb_types, sdb_arg_i, 0); char *comma = strchr (arg_i, ','); if (comma) { *comma = 0; pj_ks (pj, "name", comma + 1); pj_ks (pj, "type", arg_i); - const char *cc_arg = r_reg_get_name (a->reg, r_reg_get_name_idx (sdb_fmt ("A%d", i))); + const char *cc_arg = rz_reg_get_name (a->reg, rz_reg_get_name_idx (sdb_fmt ("A%d", i))); if (cc_arg) { pj_ks (pj, "cc", cc_arg); } @@ -1751,15 +1751,15 @@ R_API char *r_anal_function_get_json(RAnalFunction *function) { return pj_drain (pj); } -R_API char *r_anal_function_get_signature(RAnalFunction *function) { - RAnal *a = function->anal; +RZ_API char *rz_anal_function_get_signature(RzAnalFunction *function) { + RzAnal *a = function->anal; const char *realname = NULL, *import_substring = NULL; - RFlagItem *flag = a->flag_get (a->flb.f, function->addr); - // Can't access R_FLAGS_FS_IMPORTS, since it is defined in r_core.h + RzFlagItem *flag = a->flag_get (a->flb.f, function->addr); + // Can't access R_FLAGS_FS_IMPORTS, since it is defined in rz_core.h if (flag && flag->space && !strcmp (flag->space->name, "imports")) { // Get substring after last dot - import_substring = r_str_rchr (function->name, NULL, '.'); + import_substring = rz_str_rchr (function->name, NULL, '.'); if (import_substring) { realname = import_substring + 1; } @@ -1768,9 +1768,9 @@ R_API char *r_anal_function_get_signature(RAnalFunction *function) { } char *ret = NULL, *args = strdup (""); - char *sdb_ret = r_str_newf ("func.%s.ret", realname); - char *sdb_args = r_str_newf ("func.%s.args", realname); - // RList *args_list = r_list_newf ((RListFree) free); + char *sdb_ret = rz_str_newf ("func.%s.ret", realname); + char *sdb_args = rz_str_newf ("func.%s.args", realname); + // RzList *args_list = rz_list_newf ((RzListFree) free); unsigned int i, j; const char *ret_type = sdb_const_get (a->sdb_types, sdb_ret, 0); const char *argc_str = sdb_const_get (a->sdb_types, sdb_args, 0); @@ -1778,7 +1778,7 @@ R_API char *r_anal_function_get_signature(RAnalFunction *function) { int argc = argc_str? atoi (argc_str): 0; for (i = 0; i < argc; i++) { - char *sdb_arg_i = r_str_newf ("func.%s.arg.%d", realname, i); + char *sdb_arg_i = rz_str_newf ("func.%s.arg.%d", realname, i); char *arg_i = sdb_get (a->sdb_types, sdb_arg_i, 0); // parse commas int arg_i_len = strlen (arg_i); @@ -1793,15 +1793,15 @@ R_API char *r_anal_function_get_signature(RAnalFunction *function) { } } char *new_args = (i + 1 == argc) - ? r_str_newf ("%s%s", args, arg_i) - : r_str_newf ("%s%s, ", args, arg_i); + ? rz_str_newf ("%s%s", args, arg_i) + : rz_str_newf ("%s%s, ", args, arg_i); free (args); args = new_args; free (arg_i); free (sdb_arg_i); } - ret = r_str_newf ("%s %s (%s);", ret_type? ret_type: "void", realname, args); + ret = rz_str_newf ("%s %s (%s);", ret_type? ret_type: "void", realname, args); free (sdb_args); free (sdb_ret); @@ -1810,12 +1810,12 @@ R_API char *r_anal_function_get_signature(RAnalFunction *function) { } /* set function signature from string */ -R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *sig) { - r_return_val_if_fail (a || f || sig, false); +RZ_API int rz_anal_str_to_fcn(RzAnal *a, RzAnalFunction *f, const char *sig) { + rz_return_val_if_fail (a || f || sig, false); char *error_msg = NULL; - const char *out = r_parse_c_string (a, sig, &error_msg); + const char *out = rz_parse_c_string (a, sig, &error_msg); if (out) { - r_anal_save_parsed_type (a, out); + rz_anal_save_parsed_type (a, out); } if (error_msg) { eprintf ("%s", error_msg); @@ -1825,11 +1825,11 @@ R_API int r_anal_str_to_fcn(RAnal *a, RAnalFunction *f, const char *sig) { return true; } -R_API RAnalFunction *r_anal_fcn_next(RAnal *anal, ut64 addr) { - RAnalFunction *fcni; - RListIter *iter; - RAnalFunction *closer = NULL; - r_list_foreach (anal->fcns, iter, fcni) { +RZ_API RzAnalFunction *rz_anal_fcn_next(RzAnal *anal, ut64 addr) { + RzAnalFunction *fcni; + RzListIter *iter; + RzAnalFunction *closer = NULL; + rz_list_foreach (anal->fcns, iter, fcni) { // if (fcni->addr == addr) if (fcni->addr > addr && (!closer || fcni->addr < closer->addr)) { closer = fcni; @@ -1838,11 +1838,11 @@ R_API RAnalFunction *r_anal_fcn_next(RAnal *anal, ut64 addr) { return closer; } -R_API int r_anal_fcn_count(RAnal *anal, ut64 from, ut64 to) { +RZ_API int rz_anal_fcn_count(RzAnal *anal, ut64 from, ut64 to) { int n = 0; - RAnalFunction *fcni; - RListIter *iter; - r_list_foreach (anal->fcns, iter, fcni) { + RzAnalFunction *fcni; + RzListIter *iter; + rz_list_foreach (anal->fcns, iter, fcni) { if (fcni->addr >= from && fcni->addr < to) { n++; } @@ -1852,32 +1852,32 @@ R_API int r_anal_fcn_count(RAnal *anal, ut64 from, ut64 to) { /* return the basic block in fcn found at the given address. * NULL is returned if such basic block doesn't exist. */ -R_API RAnalBlock *r_anal_fcn_bbget_in(const RAnal *anal, RAnalFunction *fcn, ut64 addr) { - r_return_val_if_fail (anal && fcn, NULL); +RZ_API RzAnalBlock *rz_anal_fcn_bbget_in(const RzAnal *anal, RzAnalFunction *fcn, ut64 addr) { + rz_return_val_if_fail (anal && fcn, NULL); if (addr == UT64_MAX) { return NULL; } const bool is_x86 = anal->cur->arch && !strcmp (anal->cur->arch, "x86"); - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (addr >= bb->addr && addr < (bb->addr + bb->size) - && (!anal->opt.jmpmid || !is_x86 || r_anal_block_op_starts_at (bb, addr))) { + && (!anal->opt.jmpmid || !is_x86 || rz_anal_block_op_starts_at (bb, addr))) { return bb; } } return NULL; } -R_API RAnalBlock *r_anal_fcn_bbget_at(RAnal *anal, RAnalFunction *fcn, ut64 addr) { - r_return_val_if_fail (fcn && addr != UT64_MAX, NULL); - RAnalBlock *b = r_anal_get_block_at (anal, addr); +RZ_API RzAnalBlock *rz_anal_fcn_bbget_at(RzAnal *anal, RzAnalFunction *fcn, ut64 addr) { + rz_return_val_if_fail (fcn && addr != UT64_MAX, NULL); + RzAnalBlock *b = rz_anal_get_block_at (anal, addr); if (b) { return b; } - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (addr == bb->addr) { return bb; } @@ -1886,16 +1886,16 @@ R_API RAnalBlock *r_anal_fcn_bbget_at(RAnal *anal, RAnalFunction *fcn, ut64 addr } // compute the cyclomatic cost -R_API ut32 r_anal_function_cost(RAnalFunction *fcn) { - RListIter *iter; - RAnalBlock *bb; +RZ_API ut32 rz_anal_function_cost(RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalBlock *bb; ut32 totalCycles = 0; if (!fcn) { return 0; } - RAnal *anal = fcn->anal; - r_list_foreach (fcn->bbs, iter, bb) { - RAnalOp op; + RzAnal *anal = fcn->anal; + rz_list_foreach (fcn->bbs, iter, bb) { + RzAnalOp op; ut64 at, end = bb->addr + bb->size; ut8 *buf = malloc (bb->size); if (!buf) { @@ -1905,29 +1905,29 @@ R_API ut32 r_anal_function_cost(RAnalFunction *fcn) { int idx = 0; for (at = bb->addr; at < end;) { memset (&op, 0, sizeof (op)); - (void) r_anal_op (anal, &op, at, buf + idx, bb->size - idx, R_ANAL_OP_MASK_BASIC); + (void) rz_anal_op (anal, &op, at, buf + idx, bb->size - idx, R_ANAL_OP_MASK_BASIC); if (op.size < 1) { op.size = 1; } idx += op.size; at += op.size; totalCycles += op.cycles; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } free (buf); } return totalCycles; } -R_API int r_anal_function_count_edges(const RAnalFunction *fcn, R_NULLABLE int *ebbs) { - r_return_val_if_fail (fcn, 0); - RListIter *iter; - RAnalBlock *bb; +RZ_API int rz_anal_function_count_edges(const RzAnalFunction *fcn, R_NULLABLE int *ebbs) { + rz_return_val_if_fail (fcn, 0); + RzListIter *iter; + RzAnalBlock *bb; int edges = 0; if (ebbs) { *ebbs = 0; } - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (ebbs && bb->jump == UT64_MAX && bb->fail == UT64_MAX) { *ebbs = *ebbs + 1; } else { @@ -1942,7 +1942,7 @@ R_API int r_anal_function_count_edges(const RAnalFunction *fcn, R_NULLABLE int * return edges; } -R_API bool r_anal_function_purity(RAnalFunction *fcn) { +RZ_API bool rz_anal_function_purity(RzAnalFunction *fcn) { if (fcn->has_changed) { HtUP *ht = ht_up_new (NULL, NULL, NULL); if (ht) { @@ -1953,9 +1953,9 @@ R_API bool r_anal_function_purity(RAnalFunction *fcn) { return fcn->is_pure; } -static bool can_affect_bp(RAnal *anal, RAnalOp* op) { - RAnalValue *dst = op->dst; - RAnalValue *src = op->src[0]; +static bool can_affect_bp(RzAnal *anal, RzAnalOp* op) { + RzAnalValue *dst = op->dst; + RzAnalValue *src = op->src[0]; const char *opdreg = (dst && dst->reg) ? dst->reg->name : NULL; const char *opsreg = (src && src->reg) ? src->reg->name : NULL; const char *bp_name = anal->reg->name[R_REG_NAME_BP]; @@ -1971,17 +1971,17 @@ static bool can_affect_bp(RAnal *anal, RAnalOp* op) { * This function checks whether any operation in a given function may change bp (excluding "mov bp, sp" * and "pop bp" at the end). */ -static void __anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn) { - RListIter *iter; - RAnalBlock *bb; +static void __anal_fcn_check_bp_use(RzAnal *anal, RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalBlock *bb; char str_to_find[40] = "\"type\":\"reg\",\"value\":\""; char *pos; strncat (str_to_find, anal->reg->name[R_REG_NAME_BP], 39); if (!fcn) { return; } - r_list_foreach (fcn->bbs, iter, bb) { - RAnalOp op; + rz_list_foreach (fcn->bbs, iter, bb) { + RzAnalOp op; ut64 at, end = bb->addr + bb->size; ut8 *buf = malloc (bb->size); if (!buf) { @@ -1990,7 +1990,7 @@ static void __anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn) { (void)anal->iob.read_at (anal->iob.io, bb->addr, (ut8 *) buf, bb->size); int idx = 0; for (at = bb->addr; at < end;) { - r_anal_op (anal, &op, at, buf + idx, bb->size - idx, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_OPEX); + rz_anal_op (anal, &op, at, buf + idx, bb->size - idx, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_OPEX); if (op.size < 1) { op.size = 1; } @@ -2000,7 +2000,7 @@ static void __anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn) { if (can_affect_bp (anal, &op) && op.src[0] && op.src[0]->reg && op.src[0]->reg->name && strcmp (op.src[0]->reg->name, anal->reg->name[R_REG_NAME_SP])) { fcn->bp_frame = false; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); return; } break; @@ -2021,14 +2021,14 @@ static void __anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn) { pos = op.opex.ptr ? strstr (op.opex.ptr, str_to_find) : NULL; if (pos && pos - op.opex.ptr < 60) { fcn->bp_frame = false; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); return; } break; case R_ANAL_OP_TYPE_XCHG: if (op.opex.ptr && strstr (op.opex.ptr, str_to_find)) { fcn->bp_frame = false; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); return; } break; @@ -2039,13 +2039,13 @@ static void __anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn) { } idx += op.size; at += op.size; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } free (buf); } } -R_API void r_anal_function_check_bp_use(RAnalFunction *fcn) { - r_return_if_fail (fcn); +RZ_API void rz_anal_function_check_bp_use(RzAnalFunction *fcn) { + rz_return_if_fail (fcn); __anal_fcn_check_bp_use (fcn->anal, fcn); } diff --git a/libr/anal/flirt.c b/librz/anal/flirt.c similarity index 85% rename from libr/anal/flirt.c rename to librz/anal/flirt.c index ac9c74cf9d..ef69b47165 100644 --- a/libr/anal/flirt.c +++ b/librz/anal/flirt.c @@ -97,9 +97,9 @@ They appear as "(REF XXXX: NAME)" in dumpsig output */ -#include -#include -#include +#include +#include +#include #include #define DEBUG 0 @@ -282,7 +282,7 @@ static int header_size = 0; // XXX need more infos on compression of version 5 sigs -// r_inflate doesn't work with them +// rz_inflate doesn't work with them #define R_FLIRT_NAME_MAX 1024 @@ -305,14 +305,14 @@ typedef struct RFlirtModule { // until but not including the first variant byte // this is a custom crc16 ut16 length; // total length of the module, should < 0x8000 - RList *public_functions; - RList *tail_bytes; - RList *referenced_functions; + RzList *public_functions; + RzList *tail_bytes; + RzList *referenced_functions; } RFlirtModule; typedef struct RFlirtNode { - RList *child_list; - RList *module_list; + RzList *child_list; + RzList *module_list; ut32 length; // length of the pattern ut64 variant_mask; // this is the mask that will define variant bytes in ut8 *pattern_bytes ut8 *pattern_bytes; // holds the pattern bytes of the signature @@ -361,7 +361,7 @@ static ut8 read_byte(RBuffer *b) { if (buf_eof || buf_err) { return 0; } - if ((length = r_buf_read (b, &r, 1)) != 1) { + if ((length = rz_buf_read (b, &r, 1)) != 1) { if (length == -1) { buf_err = true; } @@ -413,16 +413,16 @@ static void module_free(RFlirtModule *module) { return; } if (module->public_functions) { - module->public_functions->free = (RListFree) free; - r_list_free (module->public_functions); + module->public_functions->free = (RzListFree) free; + rz_list_free (module->public_functions); } if (module->tail_bytes) { - module->tail_bytes->free = (RListFree) free; - r_list_free (module->tail_bytes); + module->tail_bytes->free = (RzListFree) free; + rz_list_free (module->tail_bytes); } if (module->referenced_functions) { - module->referenced_functions->free = (RListFree) free; - r_list_free (module->referenced_functions); + module->referenced_functions->free = (RzListFree) free; + rz_list_free (module->referenced_functions); } free (module); } @@ -434,23 +434,23 @@ static void node_free(RFlirtNode *node) { free (node->variant_bool_array); free (node->pattern_bytes); if (node->module_list) { - node->module_list->free = (RListFree)module_free; - r_list_free (node->module_list); + node->module_list->free = (RzListFree)module_free; + rz_list_free (node->module_list); } if (node->child_list) { - node->child_list->free = (RListFree) node_free; - r_list_free (node->child_list); + node->child_list->free = (RzListFree) node_free; + rz_list_free (node->child_list); } free (node); } -static void print_module(const RAnal *anal, const RFlirtModule *module) { - RListIter *pub_func_it, *ref_func_it, *tail_byte_it; +static void print_module(const RzAnal *anal, const RFlirtModule *module) { + RzListIter *pub_func_it, *ref_func_it, *tail_byte_it; RFlirtFunction *func, *ref_func; RFlirtTailByte *tail_byte; anal->cb_printf ("%02X %04X %04X ", module->crc_length, module->crc16, module->length); - r_list_foreach (module->public_functions, pub_func_it, func) { + rz_list_foreach (module->public_functions, pub_func_it, func) { if (func->is_local || func->is_collision) { anal->cb_printf ("("); if (func->is_local) { @@ -467,13 +467,13 @@ static void print_module(const RAnal *anal, const RFlirtModule *module) { } } if (module->tail_bytes) { - r_list_foreach (module->tail_bytes, tail_byte_it, tail_byte) { + rz_list_foreach (module->tail_bytes, tail_byte_it, tail_byte) { anal->cb_printf (" (%04X: %02X)", tail_byte->offset, tail_byte->value); } } if (module->referenced_functions) { anal->cb_printf (" (REF "); - r_list_foreach (module->referenced_functions, ref_func_it, ref_func) { + rz_list_foreach (module->referenced_functions, ref_func_it, ref_func) { anal->cb_printf ("%04X: %s", ref_func->offset, ref_func->name); if (ref_func_it->n) { anal->cb_printf (" "); @@ -485,7 +485,7 @@ static void print_module(const RAnal *anal, const RFlirtModule *module) { } -static void print_node_pattern(const RAnal *anal, const RFlirtNode *node) { +static void print_node_pattern(const RzAnal *anal, const RFlirtNode *node) { int i; for (i = 0; i < node->length; i++) { if (node->variant_bool_array[i]) { @@ -497,14 +497,14 @@ static void print_node_pattern(const RAnal *anal, const RFlirtNode *node) { anal->cb_printf (":\n"); } -static void print_indentation(const RAnal *anal, int indent) { - anal->cb_printf ("%s", r_str_pad (' ', indent)); +static void print_indentation(const RzAnal *anal, int indent) { + anal->cb_printf ("%s", rz_str_pad (' ', indent)); } -static void print_node(const RAnal *anal, const RFlirtNode *node, int indent) { +static void print_node(const RzAnal *anal, const RFlirtNode *node, int indent) { /*Prints a signature node. The output is similar to dumpsig*/ int i; - RListIter *child_it, *module_it; + RzListIter *child_it, *module_it; RFlirtNode *child; RFlirtModule *module; @@ -513,12 +513,12 @@ static void print_node(const RAnal *anal, const RFlirtNode *node, int indent) { print_node_pattern (anal, node); } if (node->child_list) { - r_list_foreach (node->child_list, child_it, child) { + rz_list_foreach (node->child_list, child_it, child) { print_node (anal, child, indent + 1); } } else if (node->module_list) { i = 0; - r_list_foreach (node->module_list, module_it, module) { + rz_list_foreach (node->module_list, module_it, module) { print_indentation (anal, indent + 1); anal->cb_printf ("%d. ", i); print_module (anal, module); @@ -527,14 +527,14 @@ static void print_node(const RAnal *anal, const RFlirtNode *node, int indent) { } } -static int module_match_buffer(RAnal *anal, const RFlirtModule *module, +static int module_match_buffer(RzAnal *anal, const RFlirtModule *module, ut8 *b, ut64 address, ut32 buf_size) { /* Returns true if module matches b, according to the signatures infos. * Return false otherwise. * The buffer starts from the first byte after the pattern */ RFlirtFunction *flirt_func; - RAnalFunction *next_module_function; - RListIter *tail_byte_it, *flirt_func_it; + RzAnalFunction *next_module_function; + RzListIter *tail_byte_it, *flirt_func_it; RFlirtTailByte *tail_byte; if (32 + module->crc_length < buf_size && @@ -542,7 +542,7 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, return false; } if (module->tail_bytes) { - r_list_foreach (module->tail_bytes, tail_byte_it, tail_byte) { + rz_list_foreach (module->tail_bytes, tail_byte_it, tail_byte) { if (32 + module->crc_length + tail_byte->offset < buf_size && b[32 + module->crc_length + tail_byte->offset] != tail_byte->value) { return false; @@ -552,11 +552,11 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, // TODO referenced functions - r_list_foreach (module->public_functions, flirt_func_it, flirt_func) { + rz_list_foreach (module->public_functions, flirt_func_it, flirt_func) { // Once the first module function is found, we need to go through the module->public_functions // list to identify the others. See flirt doc for more information - next_module_function = r_anal_get_function_at ((RAnal *) anal, address + flirt_func->offset); + next_module_function = rz_anal_get_function_at ((RzAnal *) anal, address + flirt_func->offset); if (next_module_function) { char *name; int name_offs = 0; @@ -565,7 +565,7 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, // get function size from flirt signature ut64 flirt_fcn_size = module->length - flirt_func->offset; RFlirtFunction *next_flirt_func; - RListIter *next_flirt_func_it = flirt_func_it->n; + RzListIter *next_flirt_func_it = flirt_func_it->n; while (next_flirt_func_it) { next_flirt_func = next_flirt_func_it->data; if (!next_flirt_func->is_local && !next_flirt_func->negative_offset) { @@ -575,27 +575,27 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, next_flirt_func_it = next_flirt_func_it->n; } // resize function if needed - next_module_function_size = r_anal_function_linear_size (next_module_function); + next_module_function_size = rz_anal_function_linear_size (next_module_function); if (next_module_function_size < flirt_fcn_size) { - RListIter *iter; - RListIter *iter_tmp; - RAnalFunction *fcn; - r_list_foreach_safe (anal->fcns, iter, iter_tmp, fcn) { + RzListIter *iter; + RzListIter *iter_tmp; + RzAnalFunction *fcn; + rz_list_foreach_safe (anal->fcns, iter, iter_tmp, fcn) { if (fcn != next_module_function && fcn->addr >= next_module_function->addr + next_module_function_size && fcn->addr < next_module_function->addr + flirt_fcn_size) { - RListIter *iter_bb; - RAnalBlock *block; - r_list_foreach (fcn->bbs, iter_bb, block) { - r_anal_function_add_block (next_module_function, block); + RzListIter *iter_bb; + RzAnalBlock *block; + rz_list_foreach (fcn->bbs, iter_bb, block) { + rz_anal_function_add_block (next_module_function, block); } next_module_function->ninstr += fcn->ninstr; - r_anal_function_delete (fcn); + rz_anal_function_delete (fcn); } } - r_anal_function_resize (next_module_function, flirt_fcn_size); - next_module_function_size = r_anal_function_linear_size (next_module_function); - r_anal_trim_jmprefs ((RAnal *)anal, next_module_function); + rz_anal_function_resize (next_module_function, flirt_fcn_size); + next_module_function_size = rz_anal_function_linear_size (next_module_function); + rz_anal_trim_jmprefs ((RzAnal *)anal, next_module_function); } @@ -605,9 +605,9 @@ static int module_match_buffer(RAnal *anal, const RFlirtModule *module, if (!flirt_func->name[name_offs]) { continue; } - name = r_name_filter2 (flirt_func->name + name_offs); + name = rz_name_filter2 (flirt_func->name + name_offs); free (next_module_function->name); - next_module_function->name = r_str_newf ("flirt.%s", name); + next_module_function->name = rz_str_newf ("flirt.%s", name); anal->flb.set (anal->flb.f, next_module_function->name, next_module_function->addr, next_module_function_size); anal->cb_printf ("Found %s\n", next_module_function->name); @@ -634,20 +634,20 @@ static int node_pattern_match(const RFlirtNode *node, ut8 *b, int buf_size) { return true; } -static int node_match_buffer(RAnal *anal, const RFlirtNode *node, ut8 *b, ut64 address, ut32 buf_size, ut32 buf_idx) { - RListIter *node_child_it, *module_it; +static int node_match_buffer(RzAnal *anal, const RFlirtNode *node, ut8 *b, ut64 address, ut32 buf_size, ut32 buf_idx) { + RzListIter *node_child_it, *module_it; RFlirtNode *child; RFlirtModule *module; if (node_pattern_match (node, b + buf_idx, buf_size - buf_idx)) { if (node->child_list) { - r_list_foreach (node->child_list, node_child_it, child) { + rz_list_foreach (node->child_list, node_child_it, child) { if (node_match_buffer (anal, child, b, address, buf_size, buf_idx + node->length)) { return true; } } } else if (node->module_list) { - r_list_foreach (node->module_list, module_it, module) { + rz_list_foreach (node->module_list, module_it, module) { if (module_match_buffer (anal, module, b, address, buf_size)) { return true; } @@ -658,25 +658,25 @@ static int node_match_buffer(RAnal *anal, const RFlirtNode *node, ut8 *b, ut64 a return false; } -static int node_match_functions(RAnal *anal, const RFlirtNode *root_node) { +static int node_match_functions(RzAnal *anal, const RFlirtNode *root_node) { /* Tries to find matching functions between the signature infos in root_node * and the analyzed functions in anal * Returns false on error. */ - if (r_list_length (anal->fcns) == 0) { + if (rz_list_length (anal->fcns) == 0) { anal->cb_printf ("There are no analyzed functions. Have you run 'aa'?\n"); return true; } anal->flb.push_fs (anal->flb.f, "flirt"); - RListIter *it_func; - RAnalFunction *func; - r_list_foreach (anal->fcns, it_func, func) { + RzListIter *it_func; + RzAnalFunction *func; + rz_list_foreach (anal->fcns, it_func, func) { if (func->type != R_ANAL_FCN_TYPE_FCN && func->type != R_ANAL_FCN_TYPE_LOC) { // scan only for unknown functions continue; } - ut64 func_size = r_anal_function_linear_size (func); + ut64 func_size = rz_anal_function_linear_size (func); ut8 *func_buf = malloc (func_size); if (!func_buf) { continue; @@ -686,9 +686,9 @@ static int node_match_functions(RAnal *anal, const RFlirtNode *root_node) { free (func_buf); continue; } - RListIter *node_child_it; + RzListIter *node_child_it; RFlirtNode *child; - r_list_foreach (root_node->child_list, node_child_it, child) { + rz_list_foreach (root_node->child_list, node_child_it, child) { if (node_match_buffer (anal, child, func_buf, func->addr, func_size, 0)) { break; } @@ -706,7 +706,7 @@ static ut8 read_module_tail_bytes(RFlirtModule *module, RBuffer *b) { int i; ut8 number_of_tail_bytes; RFlirtTailByte *tail_byte = NULL; - if (!(module->tail_bytes = r_list_newf ((RListFree) free))) { + if (!(module->tail_bytes = rz_list_newf ((RzListFree) free))) { goto err_exit; } @@ -739,7 +739,7 @@ static ut8 read_module_tail_bytes(RFlirtModule *module, RBuffer *b) { if (buf_eof || buf_err) { goto err_exit; } - r_list_append (module->tail_bytes, tail_byte); + rz_list_append (module->tail_bytes, tail_byte); #if DEBUG eprintf ("READ TAIL BYTE: %04X: %02X\n", tail_byte->offset, tail_byte->value); #endif @@ -749,7 +749,7 @@ static ut8 read_module_tail_bytes(RFlirtModule *module, RBuffer *b) { err_exit: free (tail_byte); - r_list_free (module->tail_bytes); + rz_list_free (module->tail_bytes); return false; } @@ -761,7 +761,7 @@ static ut8 read_module_referenced_functions(RFlirtModule *module, RBuffer *b) { ut32 ref_function_name_length; RFlirtFunction *ref_function = NULL; - module->referenced_functions = r_list_new (); + module->referenced_functions = rz_list_new (); if (version >= 8) { // this counter was introduced in version 8 number_of_referenced_functions = read_byte (b); // XXX are we sure it's not read_multiple_bytes? @@ -814,7 +814,7 @@ static ut8 read_module_referenced_functions(RFlirtModule *module, RBuffer *b) { } else { ref_function->name[ref_function_name_length] = '\0'; } - r_list_append (module->referenced_functions, ref_function); + rz_list_append (module->referenced_functions, ref_function); #if DEBUG eprintf ("(REF: %04X: %s)\n", ref_function->offset, ref_function->name); #endif @@ -835,7 +835,7 @@ static ut8 read_module_public_functions(RFlirtModule *module, RBuffer *b, ut8 *f ut8 current_byte; RFlirtFunction *function = NULL; - module->public_functions = r_list_new (); + module->public_functions = rz_list_new (); do { function = R_NEW0 (RFlirtFunction); @@ -868,7 +868,7 @@ static ut8 read_module_public_functions(RFlirtModule *module, RBuffer *b, ut8 *f #if DEBUG // XXX investigate eprintf ("INVESTIGATE PUBLIC NAME FLAG: %02X @ %04X\n", current_byte, - r_buf_tell (b) + header_size); + rz_buf_tell (b) + header_size); #endif } current_byte = read_byte (b); @@ -896,7 +896,7 @@ static ut8 read_module_public_functions(RFlirtModule *module, RBuffer *b, ut8 *f eprintf ("%04X:%s ", function->offset, function->name); #endif *flags = current_byte; - r_list_append (module->public_functions, function); + rz_list_append (module->public_functions, function); } while (*flags & IDASIG__PARSE__MORE_PUBLIC_NAMES); #if DEBUG eprintf ("\n"); @@ -909,14 +909,14 @@ err_exit: return false; } -static ut8 parse_leaf(const RAnal *anal, RBuffer *b, RFlirtNode *node) { +static ut8 parse_leaf(const RzAnal *anal, RBuffer *b, RFlirtNode *node) { /*parses a signature leaf: modules with same leading pattern*/ /*returns false on parsing error*/ ut8 flags, crc_length; ut16 crc16; RFlirtModule *module = NULL; - node->module_list = r_list_new (); + node->module_list = rz_list_new (); do { // loop for all modules having the same prefix crc_length = read_byte (b); if (buf_eof || buf_err) { @@ -928,7 +928,7 @@ static ut8 parse_leaf(const RAnal *anal, RBuffer *b, RFlirtNode *node) { #if DEBUG if (crc_length == 0x00 && crc16 != 0x0000) { eprintf ("WARNING non zero crc of zero length @ %04X\n", - r_buf_tell (b) + header_size); + rz_buf_tell (b) + header_size); } eprintf ("crc_len: %02X crc16: %04X\n", crc_length, crc16); #endif @@ -973,7 +973,7 @@ static ut8 parse_leaf(const RAnal *anal, RBuffer *b, RFlirtNode *node) { } } - r_list_append (node->module_list, module); + rz_list_append (node->module_list, module); } while (flags & IDASIG__PARSE__MORE_MODULES_WITH_SAME_CRC); } while (flags & IDASIG__PARSE__MORE_MODULES); // same prefix but different crc @@ -1048,7 +1048,7 @@ static bool read_node_bytes(RFlirtNode *node, RBuffer *b) { return true; } -static ut8 parse_tree(const RAnal *anal, RBuffer *b, RFlirtNode *root_node) { +static ut8 parse_tree(const RzAnal *anal, RBuffer *b, RFlirtNode *root_node) { /*parse a signature pattern tree or sub-tree*/ /*returns false on parsing error*/ RFlirtNode *node = NULL; @@ -1059,7 +1059,7 @@ static ut8 parse_tree(const RAnal *anal, RBuffer *b, RFlirtNode *root_node) { if (tree_nodes == 0) { // if there's no tree nodes remaining, that means we are on the leaf return parse_leaf (anal, b, root_node); } - root_node->child_list = r_list_new (); + root_node->child_list = rz_list_new (); for (i = 0; i < tree_nodes; i++) { if (!(node = R_NEW0 (RFlirtNode))) { @@ -1074,7 +1074,7 @@ static ut8 parse_tree(const RAnal *anal, RBuffer *b, RFlirtNode *root_node) { if (!read_node_bytes (node, b)) { goto err_exit; } - r_list_append (root_node->child_list, node); + rz_list_append (root_node->child_list, node); if (!parse_tree (anal, b, node)) { goto err_exit; // parse child nodes } @@ -1225,41 +1225,41 @@ static void print_header(idasig_v5_t *header) { #endif static int parse_header(RBuffer *buf, idasig_v5_t *header) { - r_buf_seek (buf, 0, R_BUF_SET); - if (r_buf_read (buf, header->magic, sizeof(header->magic)) != sizeof(header->magic)) { + rz_buf_seek (buf, 0, R_BUF_SET); + if (rz_buf_read (buf, header->magic, sizeof(header->magic)) != sizeof(header->magic)) { return false; } - if (r_buf_read (buf, &header->version, sizeof(header->version)) != sizeof(header->version)) { + if (rz_buf_read (buf, &header->version, sizeof(header->version)) != sizeof(header->version)) { return false; } - if (r_buf_read (buf, &header->arch, sizeof(header->arch)) != sizeof(header->arch)) { + if (rz_buf_read (buf, &header->arch, sizeof(header->arch)) != sizeof(header->arch)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->file_types, sizeof(header->file_types)) != sizeof(header->file_types)) { + if (rz_buf_read (buf, (unsigned char *)&header->file_types, sizeof(header->file_types)) != sizeof(header->file_types)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->os_types, sizeof(header->os_types)) != sizeof(header->os_types)) { + if (rz_buf_read (buf, (unsigned char *)&header->os_types, sizeof(header->os_types)) != sizeof(header->os_types)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->app_types, sizeof(header->app_types)) != sizeof(header->app_types)) { + if (rz_buf_read (buf, (unsigned char *)&header->app_types, sizeof(header->app_types)) != sizeof(header->app_types)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->features, sizeof(header->features)) != sizeof(header->features)) { + if (rz_buf_read (buf, (unsigned char *)&header->features, sizeof(header->features)) != sizeof(header->features)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->old_n_functions, sizeof(header->old_n_functions)) != sizeof(header->old_n_functions)) { + if (rz_buf_read (buf, (unsigned char *)&header->old_n_functions, sizeof(header->old_n_functions)) != sizeof(header->old_n_functions)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->crc16, sizeof(header->crc16)) != sizeof(header->crc16)) { + if (rz_buf_read (buf, (unsigned char *)&header->crc16, sizeof(header->crc16)) != sizeof(header->crc16)) { return false; } - if (r_buf_read (buf, header->ctype, sizeof(header->ctype)) != sizeof(header->ctype)) { + if (rz_buf_read (buf, header->ctype, sizeof(header->ctype)) != sizeof(header->ctype)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->library_name_len, sizeof(header->library_name_len)) != sizeof(header->library_name_len)) { + if (rz_buf_read (buf, (unsigned char *)&header->library_name_len, sizeof(header->library_name_len)) != sizeof(header->library_name_len)) { return false; } - if (r_buf_read (buf, (unsigned char *)&header->ctypes_crc16, sizeof(header->ctypes_crc16)) != sizeof(header->ctypes_crc16)) { + if (rz_buf_read (buf, (unsigned char *)&header->ctypes_crc16, sizeof(header->ctypes_crc16)) != sizeof(header->ctypes_crc16)) { return false; } @@ -1267,7 +1267,7 @@ static int parse_header(RBuffer *buf, idasig_v5_t *header) { } static int parse_v6_v7_header(RBuffer *buf, idasig_v6_v7_t *header) { - if (r_buf_read (buf, (unsigned char *)&header->n_functions, sizeof (header->n_functions)) != sizeof (header->n_functions)) { + if (rz_buf_read (buf, (unsigned char *)&header->n_functions, sizeof (header->n_functions)) != sizeof (header->n_functions)) { return false; } @@ -1275,7 +1275,7 @@ static int parse_v6_v7_header(RBuffer *buf, idasig_v6_v7_t *header) { } static int parse_v8_v9_header(RBuffer *buf, idasig_v8_v9_t *header) { - if (r_buf_read (buf, (unsigned char *)&header->pattern_size, sizeof (header->pattern_size)) != sizeof (header->pattern_size)) { + if (rz_buf_read (buf, (unsigned char *)&header->pattern_size, sizeof (header->pattern_size)) != sizeof (header->pattern_size)) { return false; } @@ -1283,17 +1283,17 @@ static int parse_v8_v9_header(RBuffer *buf, idasig_v8_v9_t *header) { } static int parse_v10_header(RBuffer *buf, idasig_v10_t *header) { - if (r_buf_read (buf, (unsigned char *)&header->unknown, sizeof (header->unknown)) != sizeof (header->unknown)) { + if (rz_buf_read (buf, (unsigned char *)&header->unknown, sizeof (header->unknown)) != sizeof (header->unknown)) { return false; } return true; } -static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { +static RFlirtNode *flirt_parse(const RzAnal *anal, RBuffer *flirt_buf) { ut8 *name = NULL; ut8 *buf = NULL, *decompressed_buf = NULL; - RBuffer *r_buf = NULL; + RBuffer *rz_buf = NULL; int size, decompressed_size; RFlirtNode *node = NULL; RFlirtNode *ret = NULL; @@ -1305,7 +1305,7 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { buf_eof = false; buf_err = false; - if (!(version = r_sign_is_flirt (flirt_buf))) { + if (!(version = rz_sign_is_flirt (flirt_buf))) { goto exit; } @@ -1352,7 +1352,7 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { goto exit; } - if (r_buf_read (flirt_buf, name, header->library_name_len) != header->library_name_len) { + if (rz_buf_read (flirt_buf, name, header->library_name_len) != header->library_name_len) { goto exit; } @@ -1361,12 +1361,12 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { // anal->cb_printf ("Loading: %s\n", name); #if DEBUG print_header (header); - header_size = r_buf_tell (flirt_buf); + header_size = rz_buf_tell (flirt_buf); #endif - size = r_buf_size (flirt_buf) - r_buf_tell (flirt_buf); + size = rz_buf_size (flirt_buf) - rz_buf_tell (flirt_buf); buf = malloc (size); - if (r_buf_read (flirt_buf, buf, size) != size) { + if (rz_buf_read (flirt_buf, buf, size) != size) { goto exit; } @@ -1375,7 +1375,7 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { eprintf ("Sorry we do not support the signatures version 5 compression.\n"); goto exit; } - if (!(decompressed_buf = r_inflate (buf, size, NULL, &decompressed_size))) { + if (!(decompressed_buf = rz_inflate (buf, size, NULL, &decompressed_size))) { eprintf ("Decompressing failed.\n"); goto exit; } @@ -1388,18 +1388,18 @@ static RFlirtNode *flirt_parse(const RAnal *anal, RBuffer *flirt_buf) { if (!(node = R_NEW0 (RFlirtNode))) { goto exit; } - r_buf = r_buf_new_with_pointers (buf, size, false); + rz_buf = rz_buf_new_with_pointers (buf, size, false); #if DEBUG - r_file_dump ("sig_dump", r_buf->buf, r_buf_size (r_buf)); + rz_file_dump ("sig_dump", rz_buf->buf, rz_buf_size (rz_buf)); #endif - if (parse_tree (anal, r_buf, node)) { + if (parse_tree (anal, rz_buf, node)) { ret = node; } else { free (node); } exit: free (buf); - r_buf_free (r_buf); + rz_buf_free (rz_buf); free (header); free (v6_v7); free (v8_v9); @@ -1408,12 +1408,12 @@ exit: return ret; } -R_API int r_sign_is_flirt(RBuffer *buf) { +RZ_API int rz_sign_is_flirt(RBuffer *buf) { /*if buf is a flirt signature, returns signature version, otherwise returns false*/ int ret = false; idasig_v5_t *header = R_NEW0 (idasig_v5_t); - if (r_buf_read (buf, header->magic, sizeof(header->magic)) != sizeof(header->magic)) { + if (rz_buf_read (buf, header->magic, sizeof(header->magic)) != sizeof(header->magic)) { goto exit; } @@ -1421,7 +1421,7 @@ R_API int r_sign_is_flirt(RBuffer *buf) { goto exit; } - if (r_buf_read (buf, &header->version, sizeof(header->version)) != sizeof(header->version)) { + if (rz_buf_read (buf, &header->version, sizeof(header->version)) != sizeof(header->version)) { goto exit; } @@ -1433,18 +1433,18 @@ exit: return ret; } -R_API void r_sign_flirt_dump(const RAnal *anal, const char *flirt_file) { +RZ_API void rz_sign_flirt_dump(const RzAnal *anal, const char *flirt_file) { /*dump a flirt signature content on screen.*/ RBuffer *flirt_buf; RFlirtNode *node; - if (!(flirt_buf = r_buf_new_slurp (flirt_file))) { + if (!(flirt_buf = rz_buf_new_slurp (flirt_file))) { eprintf ("Can't open %s\n", flirt_file); return; } node = flirt_parse (anal, flirt_buf); - r_buf_free (flirt_buf); + rz_buf_free (flirt_buf); if (node) { print_node (anal, node, -1); node_free (node); @@ -1455,18 +1455,18 @@ R_API void r_sign_flirt_dump(const RAnal *anal, const char *flirt_file) { } } -R_API void r_sign_flirt_scan(RAnal *anal, const char *flirt_file) { +RZ_API void rz_sign_flirt_scan(RzAnal *anal, const char *flirt_file) { /*parses a flirt signature file and scan the currently opened file against it.*/ RBuffer *flirt_buf; RFlirtNode *node; - if (!(flirt_buf = r_buf_new_slurp (flirt_file))) { + if (!(flirt_buf = rz_buf_new_slurp (flirt_file))) { eprintf ("Can't open %s\n", flirt_file); return; } node = flirt_parse (anal, flirt_buf); - r_buf_free (flirt_buf); + rz_buf_free (flirt_buf); if (node) { if (!node_match_functions (anal, node)) { eprintf ("Error while scanning the file %s\n", flirt_file); diff --git a/libr/anal/function.c b/librz/anal/function.c similarity index 59% rename from libr/anal/function.c rename to librz/anal/function.c index a25a2237a3..18d5c3f8a8 100644 --- a/libr/anal/function.c +++ b/librz/anal/function.c @@ -1,32 +1,32 @@ /* radare - LGPL - Copyright 2019 - pancake, thestr4ng3r */ -#include +#include #define D if (anal->verbose) -static bool get_functions_block_cb(RAnalBlock *block, void *user) { - RList *list = user; - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (block->fcns, iter, fcn) { - if (r_list_contains (list, fcn)) { +static bool get_functions_block_cb(RzAnalBlock *block, void *user) { + RzList *list = user; + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (block->fcns, iter, fcn) { + if (rz_list_contains (list, fcn)) { continue; } - r_list_push (list, fcn); + rz_list_push (list, fcn); } return true; } -R_API RList *r_anal_get_functions_in(RAnal *anal, ut64 addr) { - RList *list = r_list_new (); +RZ_API RzList *rz_anal_get_functions_in(RzAnal *anal, ut64 addr) { + RzList *list = rz_list_new (); if (!list) { return NULL; } - r_anal_blocks_foreach_in (anal, addr, get_functions_block_cb, list); + rz_anal_blocks_foreach_in (anal, addr, get_functions_block_cb, list); return list; } -static bool __fcn_exists(RAnal *anal, const char *name, ut64 addr) { +static bool __fcn_exists(RzAnal *anal, const char *name, ut64 addr) { // check if name is already registered bool found = false; if (addr == UT64_MAX) { @@ -37,7 +37,7 @@ static bool __fcn_exists(RAnal *anal, const char *name, ut64 addr) { eprintf ("TODO: Empty function name, we must auto generate one\n"); return true; } - RAnalFunction *f = ht_pp_find (anal->ht_name_fun, name, &found); + RzAnalFunction *f = ht_pp_find (anal->ht_name_fun, name, &found); if (f && found) { eprintf ("Invalid function name '%s' at 0x%08"PFMT64x"\n", name, addr); return true; @@ -52,10 +52,10 @@ static bool __fcn_exists(RAnal *anal, const char *name, ut64 addr) { return false; } -R_IPI void r_anal_var_free(RAnalVar *av); +R_IPI void rz_anal_var_free(RzAnalVar *av); static void inst_vars_kv_free(HtUPKv *kv) { - r_pvector_free (kv->value); + rz_pvector_free (kv->value); } static void labels_kv_free(HtUPKv *kv) { @@ -67,43 +67,43 @@ static void label_addrs_kv_free(HtPPKv *kv) { free (kv->value); } -R_API RAnalFunction *r_anal_function_new(RAnal *anal) { - RAnalFunction *fcn = R_NEW0 (RAnalFunction); +RZ_API RzAnalFunction *rz_anal_function_new(RzAnal *anal) { + RzAnalFunction *fcn = R_NEW0 (RzAnalFunction); if (!fcn) { return NULL; } fcn->anal = anal; fcn->addr = UT64_MAX; - fcn->cc = r_str_constpool_get (&anal->constpool, r_anal_cc_default (anal)); + fcn->cc = rz_str_constpool_get (&anal->constpool, rz_anal_cc_default (anal)); fcn->bits = anal->bits; - fcn->bbs = r_list_new (); - fcn->diff = r_anal_diff_new (); + fcn->bbs = rz_list_new (); + fcn->diff = rz_anal_diff_new (); fcn->has_changed = true; fcn->bp_frame = true; fcn->is_noreturn = false; fcn->meta._min = UT64_MAX; - r_pvector_init (&fcn->vars, NULL); + rz_pvector_init (&fcn->vars, NULL); fcn->inst_vars = ht_up_new (NULL, inst_vars_kv_free, NULL); fcn->labels = ht_up_new (NULL, labels_kv_free, NULL); fcn->label_addrs = ht_pp_new (NULL, label_addrs_kv_free, NULL); return fcn; } -R_API void r_anal_function_free(void *_fcn) { - RAnalFunction *fcn = _fcn; +RZ_API void rz_anal_function_free(void *_fcn) { + RzAnalFunction *fcn = _fcn; if (!_fcn) { return; } - RAnalBlock *block; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, block) { - r_list_delete_data (block->fcns, fcn); - r_anal_block_unref (block); + RzAnalBlock *block; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, block) { + rz_list_delete_data (block->fcns, fcn); + rz_anal_block_unref (block); } - r_list_free (fcn->bbs); + rz_list_free (fcn->bbs); - RAnal *anal = fcn->anal; + RzAnal *anal = fcn->anal; if (ht_up_find (anal->ht_addr_fun, fcn->addr, NULL) == _fcn) { ht_up_delete (anal->ht_addr_fun, fcn->addr); } @@ -113,7 +113,7 @@ R_API void r_anal_function_free(void *_fcn) { ht_up_free (fcn->inst_vars); fcn->inst_vars = NULL; - r_anal_function_delete_all_vars (fcn); + rz_anal_function_delete_all_vars (fcn); ht_up_free (fcn->labels); ht_pp_free (fcn->label_addrs); @@ -121,12 +121,12 @@ R_API void r_anal_function_free(void *_fcn) { free (fcn->name); fcn->bbs = NULL; free (fcn->fingerprint); - r_anal_diff_free (fcn->diff); - r_list_free (fcn->imports); + rz_anal_diff_free (fcn->diff); + rz_list_free (fcn->imports); free (fcn); } -R_API bool r_anal_add_function(RAnal *anal, RAnalFunction *fcn) { +RZ_API bool rz_anal_add_function(RzAnal *anal, RzAnalFunction *fcn) { if (__fcn_exists (anal, fcn->name, fcn->addr)) { return false; } @@ -134,23 +134,23 @@ R_API bool r_anal_add_function(RAnal *anal, RAnalFunction *fcn) { anal->cb.on_fcn_new (anal, anal->user, fcn); } if (anal->flg_fcn_set) { - anal->flg_fcn_set (anal->flb.f, fcn->name, fcn->addr, r_anal_function_size_from_entry (fcn)); + anal->flg_fcn_set (anal->flb.f, fcn->name, fcn->addr, rz_anal_function_size_from_entry (fcn)); } - fcn->is_noreturn = r_anal_noreturn_at_addr (anal, fcn->addr); - r_list_append (anal->fcns, fcn); + fcn->is_noreturn = rz_anal_noreturn_at_addr (anal, fcn->addr); + rz_list_append (anal->fcns, fcn); ht_pp_insert (anal->ht_name_fun, fcn->name, fcn); ht_up_insert (anal->ht_addr_fun, fcn->addr, fcn); return true; } -R_API RAnalFunction *r_anal_create_function(RAnal *anal, const char *name, ut64 addr, int type, RAnalDiff *diff) { - RAnalFunction *fcn = r_anal_function_new (anal); +RZ_API RzAnalFunction *rz_anal_create_function(RzAnal *anal, const char *name, ut64 addr, int type, RzAnalDiff *diff) { + RzAnalFunction *fcn = rz_anal_function_new (anal); if (!fcn) { return NULL; } fcn->addr = addr; fcn->type = type; - fcn->cc = r_str_constpool_get (&anal->constpool, r_anal_cc_default (anal)); + fcn->cc = rz_str_constpool_get (&anal->constpool, rz_anal_cc_default (anal)); fcn->bits = anal->bits; if (name) { free (fcn->name); @@ -160,7 +160,7 @@ R_API RAnalFunction *r_anal_create_function(RAnal *anal, const char *name, ut64 if (!fcnprefix) { fcnprefix = "fcn"; } - fcn->name = r_str_newf ("%s.%08"PFMT64x, fcnprefix, fcn->addr); + fcn->name = rz_str_newf ("%s.%08"PFMT64x, fcnprefix, fcn->addr); } if (diff) { fcn->diff->type = diff->type; @@ -170,20 +170,20 @@ R_API RAnalFunction *r_anal_create_function(RAnal *anal, const char *name, ut64 fcn->diff->name = strdup (diff->name); } } - if (!r_anal_add_function (anal, fcn)) { - r_anal_function_free (fcn); + if (!rz_anal_add_function (anal, fcn)) { + rz_anal_function_free (fcn); return NULL; } return fcn; } -R_API bool r_anal_function_delete(RAnalFunction *fcn) { - return r_list_delete_data (fcn->anal->fcns, fcn); +RZ_API bool rz_anal_function_delete(RzAnalFunction *fcn) { + return rz_list_delete_data (fcn->anal->fcns, fcn); } -R_API RAnalFunction *r_anal_get_function_at(RAnal *anal, ut64 addr) { +RZ_API RzAnalFunction *rz_anal_get_function_at(RzAnal *anal, ut64 addr) { bool found = false; - RAnalFunction *f = ht_up_find (anal->ht_addr_fun, addr, &found); + RzAnalFunction *f = ht_up_find (anal->ht_addr_fun, addr, &found); if (f && found) { return f; } @@ -201,11 +201,11 @@ static bool inst_vars_relocate_cb(void *user, const ut64 k, const void *v) { return true; } -R_API bool r_anal_function_relocate(RAnalFunction *fcn, ut64 addr) { +RZ_API bool rz_anal_function_relocate(RzAnalFunction *fcn, ut64 addr) { if (fcn->addr == addr) { return true; } - if (r_anal_get_function_at (fcn->anal, addr)) { + if (rz_anal_get_function_at (fcn->anal, addr)) { return false; } ht_up_delete (fcn->anal->ht_addr_fun, fcn->addr); @@ -213,10 +213,10 @@ R_API bool r_anal_function_relocate(RAnalFunction *fcn, ut64 addr) { // relocate the var accesses (their addrs are relative to the function addr) st64 delta = (st64)addr - (st64)fcn->addr; void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; - RAnalVarAccess *acc; - r_vector_foreach (&var->accesses, acc) { + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; + RzAnalVarAccess *acc; + rz_vector_foreach (&var->accesses, acc) { acc->offset -= delta; } } @@ -237,9 +237,9 @@ R_API bool r_anal_function_relocate(RAnalFunction *fcn, ut64 addr) { return true; } -R_API bool r_anal_function_rename(RAnalFunction *fcn, const char *name) { - RAnal *anal = fcn->anal; - RAnalFunction *existing = ht_pp_find (anal->ht_name_fun, name, NULL); +RZ_API bool rz_anal_function_rename(RzAnalFunction *fcn, const char *name) { + RzAnal *anal = fcn->anal; + RzAnalFunction *existing = ht_pp_find (anal->ht_name_fun, name, NULL); if (existing) { if (existing == fcn) { // fcn->name == name, nothing to do @@ -261,13 +261,13 @@ R_API bool r_anal_function_rename(RAnalFunction *fcn, const char *name) { return true; } -R_API void r_anal_function_add_block(RAnalFunction *fcn, RAnalBlock *bb) { - if (r_list_contains (bb->fcns, fcn)) { +RZ_API void rz_anal_function_add_block(RzAnalFunction *fcn, RzAnalBlock *bb) { + if (rz_list_contains (bb->fcns, fcn)) { return; } - r_list_append (bb->fcns, fcn); // associate the given fcn with this bb - r_anal_block_ref (bb); - r_list_append (fcn->bbs, bb); + rz_list_append (bb->fcns, fcn); // associate the given fcn with this bb + rz_anal_block_ref (bb); + rz_list_append (fcn->bbs, bb); if (fcn->meta._min != UT64_MAX) { if (bb->addr + bb->size > fcn->meta._max) { @@ -283,8 +283,8 @@ R_API void r_anal_function_add_block(RAnalFunction *fcn, RAnalBlock *bb) { } } -R_API void r_anal_function_remove_block(RAnalFunction *fcn, RAnalBlock *bb) { - r_list_delete_data (bb->fcns, fcn); +RZ_API void rz_anal_function_remove_block(RzAnalFunction *fcn, RzAnalBlock *bb) { + rz_list_delete_data (bb->fcns, fcn); if (fcn->meta._min != UT64_MAX && (fcn->meta._min == bb->addr || fcn->meta._max == bb->addr + bb->size)) { @@ -292,19 +292,19 @@ R_API void r_anal_function_remove_block(RAnalFunction *fcn, RAnalBlock *bb) { fcn->meta._min = UT64_MAX; } - r_list_delete_data (fcn->bbs, bb); - r_anal_block_unref (bb); + rz_list_delete_data (fcn->bbs, bb); + rz_anal_block_unref (bb); } -static void ensure_fcn_range(RAnalFunction *fcn) { +static void ensure_fcn_range(RzAnalFunction *fcn) { if (fcn->meta._min != UT64_MAX) { // recalculate only if invalid return; } ut64 minval = UT64_MAX; ut64 maxval = UT64_MIN; - RAnalBlock *block; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, block) { + RzAnalBlock *block; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, block) { if (block->addr < minval) { minval = block->addr; } @@ -316,42 +316,42 @@ static void ensure_fcn_range(RAnalFunction *fcn) { fcn->meta._max = minval == UT64_MAX ? UT64_MAX : maxval; } -R_API ut64 r_anal_function_linear_size(RAnalFunction *fcn) { +RZ_API ut64 rz_anal_function_linear_size(RzAnalFunction *fcn) { ensure_fcn_range (fcn); return fcn->meta._max - fcn->meta._min; } -R_API ut64 r_anal_function_min_addr(RAnalFunction *fcn) { +RZ_API ut64 rz_anal_function_min_addr(RzAnalFunction *fcn) { ensure_fcn_range (fcn); return fcn->meta._min; } -R_API ut64 r_anal_function_max_addr(RAnalFunction *fcn) { +RZ_API ut64 rz_anal_function_max_addr(RzAnalFunction *fcn) { ensure_fcn_range (fcn); return fcn->meta._max; } -R_API ut64 r_anal_function_size_from_entry(RAnalFunction *fcn) { +RZ_API ut64 rz_anal_function_size_from_entry(RzAnalFunction *fcn) { ensure_fcn_range (fcn); return fcn->meta._min == UT64_MAX ? 0 : fcn->meta._max - fcn->addr; } -R_API ut64 r_anal_function_realsize(const RAnalFunction *fcn) { - RListIter *iter; - RAnalBlock *bb; +RZ_API ut64 rz_anal_function_realsize(const RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalBlock *bb; ut64 sz = 0; if (!sz) { - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { sz += bb->size; } } return sz; } -static bool fcn_in_cb(RAnalBlock *block, void *user) { - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (block->fcns, iter, fcn) { +static bool fcn_in_cb(RzAnalBlock *block, void *user) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (block->fcns, iter, fcn) { if (fcn == user) { return false; } @@ -359,7 +359,7 @@ static bool fcn_in_cb(RAnalBlock *block, void *user) { return true; } -R_API bool r_anal_function_contains(RAnalFunction *fcn, ut64 addr) { +RZ_API bool rz_anal_function_contains(RzAnalFunction *fcn, ut64 addr) { // fcn_in_cb breaks with false if it finds the fcn - return !r_anal_blocks_foreach_in (fcn->anal, addr, fcn_in_cb, fcn); + return !rz_anal_blocks_foreach_in (fcn->anal, addr, fcn_in_cb, fcn); } diff --git a/libr/anal/hint.c b/librz/anal/hint.c similarity index 52% rename from libr/anal/hint.c rename to librz/anal/hint.c index 3a15190a96..44ef153f4d 100644 --- a/libr/anal/hint.c +++ b/librz/anal/hint.c @@ -1,29 +1,29 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include +#include // Common base-struct for hints which affect an entire range as opposed to only one single address // They are saved in a RBTree per hint type. // Each ranged record in a tree affects every address address greater or equal to its specified address until // the next record or the end of the address space. -typedef struct r_anal_ranged_hint_record_base_t { +typedef struct rz_anal_ranged_hint_record_base_t { RBNode rb; ut64 addr; -} RAnalRangedHintRecordBase; +} RzAnalRangedHintRecordBase; -typedef struct r_anal_arch_hint_record_t { - RAnalRangedHintRecordBase base; // MUST be the first member! +typedef struct rz_anal_arch_hint_record_t { + RzAnalRangedHintRecordBase base; // MUST be the first member! char *arch; // NULL => reset to global -} RAnalArchHintRecord; +} RzAnalArchHintRecord; -typedef struct r_anal_bits_hint_record_t { - RAnalRangedHintRecordBase base; // MUST be the first member! +typedef struct rz_anal_bits_hint_record_t { + RzAnalRangedHintRecordBase base; // MUST be the first member! int bits; // 0 => reset to global -} RAnalBitsHintRecord; +} RzAnalBitsHintRecord; static int ranged_hint_record_cmp(const void *incoming, const RBNode *in_tree, void *user) { ut64 addr = *(const ut64 *)incoming; - const RAnalRangedHintRecordBase *in_tree_record = container_of (in_tree, const RAnalRangedHintRecordBase, rb); + const RzAnalRangedHintRecordBase *in_tree_record = container_of (in_tree, const RzAnalRangedHintRecordBase, rb); if (addr < in_tree_record->addr) { return -1; } else if (addr > in_tree_record->addr) { @@ -34,7 +34,7 @@ static int ranged_hint_record_cmp(const void *incoming, const RBNode *in_tree, v static void addr_hint_record_fini(void *element, void *user) { (void)user; - RAnalAddrHintRecord *record = element; + RzAnalAddrHintRecord *record = element; switch (record->type) { case R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET: free (record->type_offset); @@ -54,36 +54,36 @@ static void addr_hint_record_fini(void *element, void *user) { } static void addr_hint_record_ht_free(HtUPKv *kv) { - r_vector_free (kv->value); + rz_vector_free (kv->value); } static void bits_hint_record_free_rb(RBNode *node, void *user) { - free (container_of (node, RAnalRangedHintRecordBase, rb)); + free (container_of (node, RzAnalRangedHintRecordBase, rb)); } static void arch_hint_record_free_rb(RBNode *node, void *user) { - RAnalArchHintRecord *record = (RAnalArchHintRecord *)container_of (node, RAnalRangedHintRecordBase, rb); + RzAnalArchHintRecord *record = (RzAnalArchHintRecord *)container_of (node, RzAnalRangedHintRecordBase, rb); free (record->arch); free (record); } // used in anal.c, but no API needed -void r_anal_hint_storage_init(RAnal *a) { +void rz_anal_hint_storage_init(RzAnal *a) { a->addr_hints = ht_up_new (NULL, addr_hint_record_ht_free, NULL); a->arch_hints = NULL; a->bits_hints = NULL; } // used in anal.c, but no API needed -void r_anal_hint_storage_fini(RAnal *a) { +void rz_anal_hint_storage_fini(RzAnal *a) { ht_up_free (a->addr_hints); - r_rbtree_free (a->arch_hints, arch_hint_record_free_rb, NULL); - r_rbtree_free (a->bits_hints, bits_hint_record_free_rb, NULL); + rz_rbtree_free (a->arch_hints, arch_hint_record_free_rb, NULL); + rz_rbtree_free (a->bits_hints, bits_hint_record_free_rb, NULL); } -R_API void r_anal_hint_clear(RAnal *a) { - r_anal_hint_storage_fini (a); - r_anal_hint_storage_init (a); +RZ_API void rz_anal_hint_clear(RzAnal *a) { + rz_anal_hint_storage_fini (a); + rz_anal_hint_storage_init (a); } typedef struct { @@ -101,131 +101,131 @@ static bool addr_hint_range_delete_cb(void *user, const ut64 key, const void *va return true; } -R_API void r_anal_hint_del(RAnal *a, ut64 addr, ut64 size) { +RZ_API void rz_anal_hint_del(RzAnal *a, ut64 addr, ut64 size) { if (size <= 1) { // only single address ht_up_delete (a->addr_hints, addr); - r_anal_hint_unset_arch (a, addr); - r_anal_hint_unset_bits (a, addr); + rz_anal_hint_unset_arch (a, addr); + rz_anal_hint_unset_bits (a, addr); return; } // ranged delete DeleteRangeCtx ctx = { a->addr_hints, addr, size }; ht_up_foreach (a->addr_hints, addr_hint_range_delete_cb, &ctx); while (true) { // arch - RBNode *node = r_rbtree_lower_bound (a->arch_hints, &addr, ranged_hint_record_cmp, NULL); + RBNode *node = rz_rbtree_lower_bound (a->arch_hints, &addr, ranged_hint_record_cmp, NULL); if (!node) { return; } - RAnalRangedHintRecordBase *base = container_of (node, RAnalRangedHintRecordBase, rb); + RzAnalRangedHintRecordBase *base = container_of (node, RzAnalRangedHintRecordBase, rb); if (base->addr >= addr + size) { break; } - r_anal_hint_unset_arch (a, base->addr); + rz_anal_hint_unset_arch (a, base->addr); } while (true) { // bits - RBNode *node = r_rbtree_lower_bound (a->bits_hints, &addr, ranged_hint_record_cmp, NULL); + RBNode *node = rz_rbtree_lower_bound (a->bits_hints, &addr, ranged_hint_record_cmp, NULL); if (!node) { return; } - RAnalRangedHintRecordBase *base = container_of (node, RAnalRangedHintRecordBase, rb); + RzAnalRangedHintRecordBase *base = container_of (node, RzAnalRangedHintRecordBase, rb); if (base->addr >= addr + size) { break; } - r_anal_hint_unset_bits (a, base->addr); + rz_anal_hint_unset_bits (a, base->addr); } } -static void unset_addr_hint_record(RAnal *anal, RAnalAddrHintType type, ut64 addr) { - RVector *records = ht_up_find (anal->addr_hints, addr, NULL); +static void unset_addr_hint_record(RzAnal *anal, RzAnalAddrHintType type, ut64 addr) { + RzVector *records = ht_up_find (anal->addr_hints, addr, NULL); if (!records) { return; } size_t i; for (i = 0; i < records->len; i++) { - RAnalAddrHintRecord *record = r_vector_index_ptr (records, i); + RzAnalAddrHintRecord *record = rz_vector_index_ptr (records, i); if (record->type == type) { addr_hint_record_fini (record, NULL); - r_vector_remove_at (records, i, NULL); + rz_vector_remove_at (records, i, NULL); return; } } } // create or return the existing addr hint record of the given type at addr -static RAnalAddrHintRecord *ensure_addr_hint_record(RAnal *anal, RAnalAddrHintType type, ut64 addr) { - RVector *records = ht_up_find (anal->addr_hints, addr, NULL); +static RzAnalAddrHintRecord *ensure_addr_hint_record(RzAnal *anal, RzAnalAddrHintType type, ut64 addr) { + RzVector *records = ht_up_find (anal->addr_hints, addr, NULL); if (!records) { - records = r_vector_new (sizeof (RAnalAddrHintRecord), addr_hint_record_fini, NULL); + records = rz_vector_new (sizeof (RzAnalAddrHintRecord), addr_hint_record_fini, NULL); if (!records) { return NULL; } ht_up_insert (anal->addr_hints, addr, records); } void *pos; - r_vector_foreach (records, pos) { - RAnalAddrHintRecord *record = pos; + rz_vector_foreach (records, pos) { + RzAnalAddrHintRecord *record = pos; if (record->type == type) { return record; } } - RAnalAddrHintRecord *record = r_vector_push (records, NULL); + RzAnalAddrHintRecord *record = rz_vector_push (records, NULL); memset (record, 0, sizeof (*record)); record->type = type; return record; } #define SET_HINT(type, setcode) do { \ - RAnalAddrHintRecord *r = ensure_addr_hint_record (a, type, addr); \ + RzAnalAddrHintRecord *r = ensure_addr_hint_record (a, type, addr); \ if (!r) { \ break; \ } \ setcode \ } while(0) -static RAnalRangedHintRecordBase *ensure_ranged_hint_record(RBTree *tree, ut64 addr, size_t sz) { - RBNode *node = r_rbtree_find (*tree, &addr, ranged_hint_record_cmp, NULL); +static RzAnalRangedHintRecordBase *ensure_ranged_hint_record(RBTree *tree, ut64 addr, size_t sz) { + RBNode *node = rz_rbtree_find (*tree, &addr, ranged_hint_record_cmp, NULL); if (node) { - return container_of (node, RAnalRangedHintRecordBase, rb); + return container_of (node, RzAnalRangedHintRecordBase, rb); } - RAnalRangedHintRecordBase *record = malloc (sz); + RzAnalRangedHintRecordBase *record = malloc (sz); memset (record, 0, sz); if (!record) { return NULL; } record->addr = addr; - r_rbtree_insert (tree, &addr, &record->rb, ranged_hint_record_cmp, NULL); + rz_rbtree_insert (tree, &addr, &record->rb, ranged_hint_record_cmp, NULL); return record; } -R_API void r_anal_hint_set_offset(RAnal *a, ut64 addr, const char *typeoff) { +RZ_API void rz_anal_hint_set_offset(RzAnal *a, ut64 addr, const char *typeoff) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET, free (r->type_offset); r->type_offset = strdup (typeoff); ); } -R_API void r_anal_hint_set_nword(RAnal *a, ut64 addr, int nword) { +RZ_API void rz_anal_hint_set_nword(RzAnal *a, ut64 addr, int nword) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_NWORD, r->nword = nword;); } -R_API void r_anal_hint_set_jump(RAnal *a, ut64 addr, ut64 jump) { +RZ_API void rz_anal_hint_set_jump(RzAnal *a, ut64 addr, ut64 jump) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_JUMP, r->jump = jump;); } -R_API void r_anal_hint_set_fail(RAnal *a, ut64 addr, ut64 fail) { +RZ_API void rz_anal_hint_set_fail(RzAnal *a, ut64 addr, ut64 fail) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_FAIL, r->fail = fail;); } -R_API void r_anal_hint_set_newbits(RAnal *a, ut64 addr, int bits) { +RZ_API void rz_anal_hint_set_newbits(RzAnal *a, ut64 addr, int bits) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_NEW_BITS, r->newbits = bits;); } -R_API void r_anal_hint_set_high(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_set_high(RzAnal *a, ut64 addr) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_HIGH,); } -R_API void r_anal_hint_set_immbase(RAnal *a, ut64 addr, int base) { +RZ_API void rz_anal_hint_set_immbase(RzAnal *a, ut64 addr, int base) { if (base) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_IMMBASE, r->immbase = base;); } else { @@ -233,53 +233,53 @@ R_API void r_anal_hint_set_immbase(RAnal *a, ut64 addr, int base) { } } -R_API void r_anal_hint_set_pointer(RAnal *a, ut64 addr, ut64 ptr) { +RZ_API void rz_anal_hint_set_pointer(RzAnal *a, ut64 addr, ut64 ptr) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_PTR, r->ptr = ptr;); } -R_API void r_anal_hint_set_ret(RAnal *a, ut64 addr, ut64 val) { +RZ_API void rz_anal_hint_set_ret(RzAnal *a, ut64 addr, ut64 val) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_RET, r->retval = val;); } -R_API void r_anal_hint_set_syntax(RAnal *a, ut64 addr, const char *syn) { +RZ_API void rz_anal_hint_set_syntax(RzAnal *a, ut64 addr, const char *syn) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_SYNTAX, free (r->syntax); r->syntax = strdup (syn); ); } -R_API void r_anal_hint_set_opcode(RAnal *a, ut64 addr, const char *opcode) { +RZ_API void rz_anal_hint_set_opcode(RzAnal *a, ut64 addr, const char *opcode) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_OPCODE, free (r->opcode); r->opcode = strdup (opcode); ); } -R_API void r_anal_hint_set_esil(RAnal *a, ut64 addr, const char *esil) { +RZ_API void rz_anal_hint_set_esil(RzAnal *a, ut64 addr, const char *esil) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_ESIL, free (r->esil); r->esil = strdup (esil); ); } -R_API void r_anal_hint_set_type (RAnal *a, ut64 addr, int type) { +RZ_API void rz_anal_hint_set_type (RzAnal *a, ut64 addr, int type) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_OPTYPE, r->optype = type;); } -R_API void r_anal_hint_set_size(RAnal *a, ut64 addr, ut64 size) { +RZ_API void rz_anal_hint_set_size(RzAnal *a, ut64 addr, ut64 size) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_SIZE, r->size = size;); } -R_API void r_anal_hint_set_stackframe(RAnal *a, ut64 addr, ut64 size) { +RZ_API void rz_anal_hint_set_stackframe(RzAnal *a, ut64 addr, ut64 size) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_STACKFRAME, r->stackframe = size;); } -R_API void r_anal_hint_set_val(RAnal *a, ut64 addr, ut64 v) { +RZ_API void rz_anal_hint_set_val(RzAnal *a, ut64 addr, ut64 v) { SET_HINT (R_ANAL_ADDR_HINT_TYPE_VAL, r->val = v;); } -R_API void r_anal_hint_set_arch(RAnal *a, ut64 addr, const char *arch) { - RAnalArchHintRecord *record = (RAnalArchHintRecord *)ensure_ranged_hint_record (&a->arch_hints, addr, sizeof (RAnalArchHintRecord)); +RZ_API void rz_anal_hint_set_arch(RzAnal *a, ut64 addr, const char *arch) { + RzAnalArchHintRecord *record = (RzAnalArchHintRecord *)ensure_ranged_hint_record (&a->arch_hints, addr, sizeof (RzAnalArchHintRecord)); if (!record) { return; } @@ -287,8 +287,8 @@ R_API void r_anal_hint_set_arch(RAnal *a, ut64 addr, const char *arch) { record->arch = arch ? strdup (arch) : NULL; } -R_API void r_anal_hint_set_bits(RAnal *a, ut64 addr, int bits) { - RAnalBitsHintRecord *record = (RAnalBitsHintRecord *)ensure_ranged_hint_record (&a->bits_hints, addr, sizeof (RAnalBitsHintRecord)); +RZ_API void rz_anal_hint_set_bits(RzAnal *a, ut64 addr, int bits) { + RzAnalBitsHintRecord *record = (RzAnalBitsHintRecord *)ensure_ranged_hint_record (&a->bits_hints, addr, sizeof (RzAnalBitsHintRecord)); if (!record) { return; } @@ -298,79 +298,79 @@ R_API void r_anal_hint_set_bits(RAnal *a, ut64 addr, int bits) { } } -R_API void r_anal_hint_unset_size(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_size(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_SIZE, addr); } -R_API void r_anal_hint_unset_esil(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_esil(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_ESIL, addr); } -R_API void r_anal_hint_unset_opcode(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_opcode(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_OPCODE, addr); } -R_API void r_anal_hint_unset_high(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_high(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_HIGH, addr); } -R_API void r_anal_hint_unset_immbase(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_immbase(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_IMMBASE, addr); } -R_API void r_anal_hint_unset_nword(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_nword(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_NWORD, addr); } -R_API void r_anal_hint_unset_syntax(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_syntax(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_SYNTAX, addr); } -R_API void r_anal_hint_unset_pointer(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_pointer(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_PTR, addr); } -R_API void r_anal_hint_unset_ret(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_ret(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_RET, addr); } -R_API void r_anal_hint_unset_offset(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_offset(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET, addr); } -R_API void r_anal_hint_unset_jump(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_jump(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_JUMP, addr); } -R_API void r_anal_hint_unset_fail(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_fail(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_FAIL, addr); } -R_API void r_anal_hint_unset_newbits(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_newbits(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_NEW_BITS, addr); } -R_API void r_anal_hint_unset_val (RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_val (RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_VAL, addr); } -R_API void r_anal_hint_unset_type (RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_type (RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_OPTYPE, addr); } -R_API void r_anal_hint_unset_stackframe(RAnal *a, ut64 addr) { +RZ_API void rz_anal_hint_unset_stackframe(RzAnal *a, ut64 addr) { unset_addr_hint_record (a, R_ANAL_ADDR_HINT_TYPE_STACKFRAME, addr); } -R_API void r_anal_hint_unset_arch(RAnal *a, ut64 addr) { - r_rbtree_delete (&a->arch_hints, &addr, ranged_hint_record_cmp, NULL, arch_hint_record_free_rb, NULL); +RZ_API void rz_anal_hint_unset_arch(RzAnal *a, ut64 addr) { + rz_rbtree_delete (&a->arch_hints, &addr, ranged_hint_record_cmp, NULL, arch_hint_record_free_rb, NULL); } -R_API void r_anal_hint_unset_bits(RAnal *a, ut64 addr) { - r_rbtree_delete (&a->bits_hints, &addr, ranged_hint_record_cmp, NULL, bits_hint_record_free_rb, NULL); +RZ_API void rz_anal_hint_unset_bits(RzAnal *a, ut64 addr) { + rz_rbtree_delete (&a->bits_hints, &addr, ranged_hint_record_cmp, NULL, bits_hint_record_free_rb, NULL); } -R_API void r_anal_hint_free(RAnalHint *h) { +RZ_API void rz_anal_hint_free(RzAnalHint *h) { if (h) { free (h->arch); free (h->esil); @@ -381,42 +381,42 @@ R_API void r_anal_hint_free(RAnalHint *h) { } } -R_API R_NULLABLE R_BORROW const char *r_anal_hint_arch_at(RAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr) { - RBNode *node = r_rbtree_upper_bound (anal->arch_hints, &addr, ranged_hint_record_cmp, NULL); +RZ_API R_NULLABLE R_BORROW const char *rz_anal_hint_arch_at(RzAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr) { + RBNode *node = rz_rbtree_upper_bound (anal->arch_hints, &addr, ranged_hint_record_cmp, NULL); if (!node) { if (hint_addr) { *hint_addr = UT64_MAX; } return NULL; } - RAnalArchHintRecord *record = (RAnalArchHintRecord *)container_of (node, RAnalRangedHintRecordBase, rb); + RzAnalArchHintRecord *record = (RzAnalArchHintRecord *)container_of (node, RzAnalRangedHintRecordBase, rb); if (hint_addr) { *hint_addr = record->base.addr; } return record->arch; } -R_API int r_anal_hint_bits_at(RAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr) { - RBNode *node = r_rbtree_upper_bound (anal->bits_hints, &addr, ranged_hint_record_cmp, NULL); +RZ_API int rz_anal_hint_bits_at(RzAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr) { + RBNode *node = rz_rbtree_upper_bound (anal->bits_hints, &addr, ranged_hint_record_cmp, NULL); if (!node) { if (hint_addr) { *hint_addr = UT64_MAX; } return 0; } - RAnalBitsHintRecord *record = (RAnalBitsHintRecord *)container_of (node, RAnalRangedHintRecordBase, rb); + RzAnalBitsHintRecord *record = (RzAnalBitsHintRecord *)container_of (node, RzAnalRangedHintRecordBase, rb); if (hint_addr) { *hint_addr = record->base.addr; } return record->bits; } -R_API R_NULLABLE const RVector/**/ *r_anal_addr_hints_at(RAnal *anal, ut64 addr) { +RZ_API R_NULLABLE const RzVector/**/ *rz_anal_addr_hints_at(RzAnal *anal, ut64 addr) { return ht_up_find (anal->addr_hints, addr, NULL); } typedef struct { - RAnalAddrHintRecordsCb cb; + RzAnalAddrHintRecordsCb cb; void *user; } AddrHintForeachCtx; @@ -425,34 +425,34 @@ static bool addr_hint_foreach_cb(void *user, const ut64 key, const void *value) return ctx->cb (key, value, ctx->user); } -R_API void r_anal_addr_hints_foreach(RAnal *anal, RAnalAddrHintRecordsCb cb, void *user) { +RZ_API void rz_anal_addr_hints_foreach(RzAnal *anal, RzAnalAddrHintRecordsCb cb, void *user) { AddrHintForeachCtx ctx = { cb, user }; ht_up_foreach (anal->addr_hints, addr_hint_foreach_cb, &ctx); } -R_API void r_anal_arch_hints_foreach(RAnal *anal, RAnalArchHintCb cb, void *user) { +RZ_API void rz_anal_arch_hints_foreach(RzAnal *anal, RzAnalArchHintCb cb, void *user) { RBIter iter; - RAnalRangedHintRecordBase *record; - r_rbtree_foreach (anal->arch_hints, iter, record, RAnalRangedHintRecordBase, rb) { - bool cont = cb (record->addr, ((RAnalArchHintRecord *)record)->arch, user); + RzAnalRangedHintRecordBase *record; + rz_rbtree_foreach (anal->arch_hints, iter, record, RzAnalRangedHintRecordBase, rb) { + bool cont = cb (record->addr, ((RzAnalArchHintRecord *)record)->arch, user); if (!cont) { break; } } } -R_API void r_anal_bits_hints_foreach(RAnal *anal, RAnalBitsHintCb cb, void *user) { +RZ_API void rz_anal_bits_hints_foreach(RzAnal *anal, RzAnalBitsHintCb cb, void *user) { RBIter iter; - RAnalRangedHintRecordBase *record; - r_rbtree_foreach (anal->bits_hints, iter, record, RAnalRangedHintRecordBase, rb) { - bool cont = cb (record->addr, ((RAnalBitsHintRecord *)record)->bits, user); + RzAnalRangedHintRecordBase *record; + rz_rbtree_foreach (anal->bits_hints, iter, record, RzAnalRangedHintRecordBase, rb) { + bool cont = cb (record->addr, ((RzAnalBitsHintRecord *)record)->bits, user); if (!cont) { break; } } } -static void hint_merge(RAnalHint *hint, RAnalAddrHintRecord *record) { +static void hint_merge(RzAnalHint *hint, RzAnalAddrHintRecord *record) { switch (record->type) { case R_ANAL_ADDR_HINT_TYPE_IMMBASE: hint->immbase = record->immbase; @@ -505,8 +505,8 @@ static void hint_merge(RAnalHint *hint, RAnalAddrHintRecord *record) { } } -R_API RAnalHint *r_anal_hint_get(RAnal *a, ut64 addr) { - RAnalHint *hint = R_NEW0 (RAnalHint); +RZ_API RzAnalHint *rz_anal_hint_get(RzAnal *a, ut64 addr) { + RzAnalHint *hint = R_NEW0 (RzAnalHint); if (!hint) { return NULL; } @@ -516,17 +516,17 @@ R_API RAnalHint *r_anal_hint_get(RAnal *a, ut64 addr) { hint->ret = UT64_MAX; hint->val = UT64_MAX; hint->stackframe = UT64_MAX; - const RVector *records = r_anal_addr_hints_at (a, addr); + const RzVector *records = rz_anal_addr_hints_at (a, addr); if (records) { - RAnalAddrHintRecord *record; - r_vector_foreach (records, record) { + RzAnalAddrHintRecord *record; + rz_vector_foreach (records, record) { hint_merge (hint, record); } } - const char *arch = r_anal_hint_arch_at (a, addr, NULL); + const char *arch = rz_anal_hint_arch_at (a, addr, NULL); hint->arch = arch ? strdup (arch) : NULL; - hint->bits = r_anal_hint_bits_at (a, addr, NULL); - if ((!records || r_vector_empty (records)) && !hint->arch && !hint->bits) { + hint->bits = rz_anal_hint_bits_at (a, addr, NULL); + if ((!records || rz_vector_empty (records)) && !hint->arch && !hint->bits) { // no hints found free (hint); return NULL; diff --git a/libr/anal/jmptbl.c b/librz/anal/jmptbl.c similarity index 77% rename from libr/anal/jmptbl.c rename to librz/anal/jmptbl.c index 386535b9d1..8168faec8c 100644 --- a/libr/anal/jmptbl.c +++ b/librz/anal/jmptbl.c @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2010-2019 - nibble, alvaro, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #define aprintf(format, ...) if (anal->verbose) eprintf (format, __VA_ARGS__) #define JMPTBL_MAXSZ 512 -static void apply_case(RAnal *anal, RAnalBlock *block, ut64 switch_addr, ut64 offset_sz, ut64 case_addr, ut64 id, ut64 case_addr_loc) { +static void apply_case(RzAnal *anal, RzAnalBlock *block, ut64 switch_addr, ut64 offset_sz, ut64 case_addr, ut64 id, ut64 case_addr_loc) { // eprintf ("** apply_case: 0x%"PFMT64x " from 0x%"PFMT64x "\n", case_addr, case_addr_loc); - r_meta_set_data_at (anal, case_addr_loc, offset_sz); - r_anal_hint_set_immbase (anal, case_addr_loc, 10); - r_anal_xrefs_set (anal, switch_addr, case_addr, R_ANAL_REF_TYPE_CODE); + rz_meta_set_data_at (anal, case_addr_loc, offset_sz); + rz_anal_hint_set_immbase (anal, case_addr_loc, 10); + rz_anal_xrefs_set (anal, switch_addr, case_addr, R_ANAL_REF_TYPE_CODE); if (block) { - r_anal_block_add_switch_case (block, switch_addr, id, case_addr); + rz_anal_block_add_switch_case (block, switch_addr, id, case_addr); } if (anal->flb.set) { char flagname[0x30]; @@ -24,28 +24,28 @@ static void apply_case(RAnal *anal, RAnalBlock *block, ut64 switch_addr, ut64 of } } -static void apply_switch(RAnal *anal, ut64 switch_addr, ut64 jmptbl_addr, ut64 cases_count, ut64 default_case_addr) { +static void apply_switch(RzAnal *anal, ut64 switch_addr, ut64 jmptbl_addr, ut64 cases_count, ut64 default_case_addr) { char tmp[0x30]; snprintf (tmp, sizeof (tmp), "switch table (%"PFMT64u" cases) at 0x%"PFMT64x, cases_count, jmptbl_addr); - r_meta_set_string (anal, R_META_TYPE_COMMENT, switch_addr, tmp); + rz_meta_set_string (anal, R_META_TYPE_COMMENT, switch_addr, tmp); if (anal->flb.set) { snprintf (tmp, sizeof (tmp), "switch.0x%08"PFMT64x, switch_addr); anal->flb.set (anal->flb.f, tmp, switch_addr, 1); if (default_case_addr != UT64_MAX) { - r_anal_xrefs_set (anal, switch_addr, default_case_addr, R_ANAL_REF_TYPE_CODE); + rz_anal_xrefs_set (anal, switch_addr, default_case_addr, R_ANAL_REF_TYPE_CODE); snprintf (tmp, sizeof (tmp), "case.default.0x%"PFMT64x, switch_addr); anal->flb.set (anal->flb.f, tmp, default_case_addr, 1); } } } -// analyze a jmptablle inside a function // maybe rename to r_anal_fcn_jmptbl() ? -R_API bool r_anal_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, ut64 jmpaddr, ut64 table, ut64 tablesize, ut64 default_addr) { +// analyze a jmptablle inside a function // maybe rename to rz_anal_fcn_jmptbl() ? +RZ_API bool rz_anal_jmptbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, ut64 jmpaddr, ut64 table, ut64 tablesize, ut64 default_addr) { const int depth = 50; return try_walkthrough_jmptbl (anal, fcn, block, depth, jmpaddr, table, table, tablesize, tablesize, default_addr, false); } -R_API bool try_walkthrough_casetbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 casetbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0) { +RZ_API bool try_walkthrough_casetbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 casetbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0) { bool ret = ret0; if (jmptbl_size == 0) { jmptbl_size = JMPTBL_MAXSZ; @@ -84,16 +84,16 @@ R_API bool try_walkthrough_casetbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock * switch (sz) { case 1: - jmpptr = r_read_le8 (jmptbl + jmpptr_idx); + jmpptr = rz_read_le8 (jmptbl + jmpptr_idx); break; case 2: - jmpptr = r_read_le16 (jmptbl + jmpptr_idx * 2); + jmpptr = rz_read_le16 (jmptbl + jmpptr_idx * 2); break; case 4: - jmpptr = r_read_le32 (jmptbl + jmpptr_idx * 4); + jmpptr = rz_read_le32 (jmptbl + jmpptr_idx * 4); break; default: - jmpptr = r_read_le64 (jmptbl + jmpptr_idx * 8); + jmpptr = rz_read_le64 (jmptbl + jmpptr_idx * 8); break; } if (jmpptr == 0 || jmpptr == UT32_MAX || jmpptr == UT64_MAX) { @@ -114,11 +114,11 @@ R_API bool try_walkthrough_casetbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock * } const ut64 jmpptr_idx_off = casetbl_loc + case_idx; - r_meta_set_data_at (anal, jmpptr_idx_off, 1); - r_anal_hint_set_immbase (anal, jmpptr_idx_off, 10); + rz_meta_set_data_at (anal, jmpptr_idx_off, 1); + rz_anal_hint_set_immbase (anal, jmpptr_idx_off, 10); apply_case (anal, block, ip, sz, jmpptr, case_idx, jmptbl_loc + jmpptr_idx * sz); - (void)r_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); + (void)rz_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); } if (case_idx > 0) { @@ -133,7 +133,7 @@ R_API bool try_walkthrough_casetbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock * return ret; } -R_API bool try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0) { +RZ_API bool try_walkthrough_jmptbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0) { bool ret = ret0; // jmptbl_size can not always be determined if (jmptbl_size == 0) { @@ -158,19 +158,19 @@ R_API bool try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *b for (offs = 0; offs + sz - 1 < jmptbl_size * sz; offs += sz) { switch (sz) { case 1: - jmpptr = (ut64)(ut8)r_read_le8 (jmptbl + offs); + jmpptr = (ut64)(ut8)rz_read_le8 (jmptbl + offs); break; case 2: - jmpptr = (ut64)r_read_le16 (jmptbl + offs); + jmpptr = (ut64)rz_read_le16 (jmptbl + offs); break; case 4: - jmpptr = r_read_le32 (jmptbl + offs); + jmpptr = rz_read_le32 (jmptbl + offs); break; case 8: - jmpptr = r_read_le64 (jmptbl + offs); + jmpptr = rz_read_le64 (jmptbl + offs); break; // XXX default: - jmpptr = r_read_le64 (jmptbl + offs); + jmpptr = rz_read_le64 (jmptbl + offs); break; } // eprintf ("WALKING %llx\n", jmpptr); @@ -198,7 +198,7 @@ R_API bool try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *b } } apply_case (anal, block, ip, sz, jmpptr, offs / sz, jmptbl_loc + offs); - (void)r_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); + (void)rz_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); } if (offs > 0) { @@ -213,12 +213,12 @@ R_API bool try_walkthrough_jmptbl(RAnal *anal, RAnalFunction *fcn, RAnalBlock *b } // TODO: RENAME -R_API bool try_get_delta_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 jmp_addr, ut64 lea_addr, ut64 *table_size, ut64 *default_case) { +RZ_API bool try_get_delta_jmptbl_info(RzAnal *anal, RzAnalFunction *fcn, ut64 jmp_addr, ut64 lea_addr, ut64 *table_size, ut64 *default_case) { bool isValid = false; bool foundCmp = false; int i; - RAnalOp tmp_aop = {0}; + RzAnalOp tmp_aop = {0}; if (lea_addr > jmp_addr) { return false; } @@ -231,7 +231,7 @@ R_API bool try_get_delta_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 jmp_a anal->iob.read_at (anal->iob.io, lea_addr, (ut8 *)buf, search_sz); for (i = 0; i + 8 < search_sz; i++) { - int len = r_anal_op (anal, &tmp_aop, lea_addr + i, buf + i, search_sz - i, R_ANAL_OP_MASK_BASIC); + int len = rz_anal_op (anal, &tmp_aop, lea_addr + i, buf + i, search_sz - i, R_ANAL_OP_MASK_BASIC); if (len < 1) { len = 1; } @@ -273,7 +273,7 @@ R_API bool try_get_delta_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 jmp_a } // TODO: find a better function name -R_API int walkthrough_arm_jmptbl_style(RAnal *anal, RAnalFunction *fcn, RAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 sz, ut64 jmptbl_size, ut64 default_case, int ret0) { +RZ_API int walkthrough_arm_jmptbl_style(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 sz, ut64 jmptbl_size, ut64 default_case, int ret0) { /* * Example about arm jump table * @@ -303,7 +303,7 @@ R_API int walkthrough_arm_jmptbl_style(RAnal *anal, RAnalFunction *fcn, RAnalBlo for (offs = 0; offs + sz - 1 < jmptbl_size * sz; offs += sz) { jmpptr = jmptbl_loc + offs; apply_case (anal, block, ip, sz, jmpptr, offs / sz, jmptbl_loc + offs); - (void)r_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); + (void)rz_anal_fcn_bb (anal, fcn, jmpptr, depth - 1); } if (offs > 0) { @@ -315,11 +315,11 @@ R_API int walkthrough_arm_jmptbl_style(RAnal *anal, RAnalFunction *fcn, RAnalBlo return ret; } -R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnalBlock *my_bb, ut64 *table_size, ut64 *default_case) { +RZ_API bool try_get_jmptbl_info(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, RzAnalBlock *my_bb, ut64 *table_size, ut64 *default_case) { bool isValid = false; int i; - RListIter *iter; - RAnalBlock *tmp_bb, *prev_bb; + RzListIter *iter; + RzAnalBlock *tmp_bb, *prev_bb; prev_bb = 0; if (!fcn->bbs) { return false; @@ -339,7 +339,7 @@ R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnal } // search for the predecessor bb - r_list_foreach (fcn->bbs, iter, tmp_bb) { + rz_list_foreach (fcn->bbs, iter, tmp_bb) { if (tmp_bb->jump == my_bb->addr || tmp_bb->fail == my_bb->addr) { prev_bb = tmp_bb; break; @@ -354,7 +354,7 @@ R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnal // default case is the jump target of the unconditional jump *default_case = prev_bb->jump == my_bb->addr ? prev_bb->fail : prev_bb->jump; - RAnalOp tmp_aop = {0}; + RzAnalOp tmp_aop = {0}; ut8 *bb_buf = calloc (1, prev_bb->size); if (!bb_buf) { return false; @@ -363,10 +363,10 @@ R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnal anal->iob.read_at (anal->iob.io, prev_bb->addr, (ut8 *) bb_buf, prev_bb->size); isValid = false; - RAnalHint *hint = r_anal_hint_get (anal, addr); + RzAnalHint *hint = rz_anal_hint_get (anal, addr); if (hint) { ut64 val = hint->val; - r_anal_hint_free (hint); + rz_anal_hint_free (hint); if (val != UT64_MAX) { *table_size = val; return true; @@ -380,12 +380,12 @@ R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnal continue; } int buflen = prev_bb->size - prev_pos; - int len = r_anal_op (anal, &tmp_aop, op_addr, + int len = rz_anal_op (anal, &tmp_aop, op_addr, bb_buf + prev_pos, buflen, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); ut32 type = tmp_aop.type & R_ANAL_OP_TYPE_MASK; if (len < 1 || type != R_ANAL_OP_TYPE_CMP) { - r_anal_op_fini (&tmp_aop); + rz_anal_op_fini (&tmp_aop); continue; } // get the value of the cmp @@ -404,7 +404,7 @@ R_API bool try_get_jmptbl_info(RAnal *anal, RAnalFunction *fcn, ut64 addr, RAnal isValid = tmp_aop.refptr < 0x200; *table_size = tmp_aop.refptr + 1; } - r_anal_op_fini (&tmp_aop); + rz_anal_op_fini (&tmp_aop); // TODO: check the jmp for whether val is included in valid range or not (ja vs jae) break; } diff --git a/libr/anal/labels.c b/librz/anal/labels.c similarity index 57% rename from libr/anal/labels.c rename to librz/anal/labels.c index b2176ac91b..7afda02b5e 100644 --- a/libr/anal/labels.c +++ b/librz/anal/labels.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2014-2020 - pancake, thestr4ng3r */ -#include +#include HEAPTYPE (ut64); -R_API ut64 r_anal_function_get_label(RAnalFunction *fcn, const char *name) { - r_return_val_if_fail (fcn, UT64_MAX); +RZ_API ut64 rz_anal_function_get_label(RzAnalFunction *fcn, const char *name) { + rz_return_val_if_fail (fcn, UT64_MAX); ut64 *addr = ht_pp_find (fcn->label_addrs, name, NULL); return addr? *addr: UT64_MAX; } -R_API const char *r_anal_function_get_label_at(RAnalFunction *fcn, ut64 addr) { - r_return_val_if_fail (fcn, NULL); +RZ_API const char *rz_anal_function_get_label_at(RzAnalFunction *fcn, ut64 addr) { + rz_return_val_if_fail (fcn, NULL); return ht_up_find (fcn->labels, addr, NULL); } -R_API bool r_anal_function_set_label(RAnalFunction *fcn, const char *name, ut64 addr) { - r_return_val_if_fail (fcn && name, false); +RZ_API bool rz_anal_function_set_label(RzAnalFunction *fcn, const char *name, ut64 addr) { + rz_return_val_if_fail (fcn && name, false); if (ht_pp_find (fcn->label_addrs, name, NULL)) { return false; } @@ -29,8 +29,8 @@ R_API bool r_anal_function_set_label(RAnalFunction *fcn, const char *name, ut64 return true; } -R_API bool r_anal_function_delete_label(RAnalFunction *fcn, const char *name) { - r_return_val_if_fail (fcn && name, false); +RZ_API bool rz_anal_function_delete_label(RzAnalFunction *fcn, const char *name) { + rz_return_val_if_fail (fcn && name, false); ut64 *addr = ht_pp_find (fcn->label_addrs, name, NULL); if (!addr) { return false; @@ -40,8 +40,8 @@ R_API bool r_anal_function_delete_label(RAnalFunction *fcn, const char *name) { return true; } -R_API bool r_anal_function_delete_label_at(RAnalFunction *fcn, ut64 addr) { - r_return_val_if_fail (fcn, false); +RZ_API bool rz_anal_function_delete_label_at(RzAnalFunction *fcn, ut64 addr) { + rz_return_val_if_fail (fcn, false); char *name = ht_up_find (fcn->labels, addr, NULL); if (!name) { return false; diff --git a/libr/anal/meson.build b/librz/anal/meson.build similarity index 86% rename from libr/anal/meson.build rename to librz/anal/meson.build index 0f1be996d4..9e68fb35fe 100644 --- a/libr/anal/meson.build +++ b/librz/anal/meson.build @@ -1,4 +1,4 @@ -r_anal_sources = [ +rz_anal_sources = [ 'anal.c', 'bb.c', 'block.c', @@ -157,7 +157,7 @@ r_anal_sources = [ '../asm/arch/pyc/pyc_dis.c' ] -r_anal_inc = [ +rz_anal_inc = [ platform_inc, include_directories( 'arch/gb', @@ -165,20 +165,20 @@ r_anal_inc = [ ) ] -r_anal = library('r_anal', r_anal_sources, - include_directories: r_anal_inc, +rz_anal = library('rz_anal', rz_anal_sources, + include_directories: rz_anal_inc, c_args: library_cflags, dependencies: [ - r_util_dep, - r_reg_dep, - r_asm_dep, - r_crypto_dep, - r_search_dep, - r_cons_dep, - r_parse_dep, - r_syscall_dep, - r_flag_dep, - r_hash_dep, + rz_util_dep, + rz_reg_dep, + rz_asm_dep, + rz_crypto_dep, + rz_search_dep, + rz_cons_dep, + rz_parse_dep, + rz_syscall_dep, + rz_flag_dep, + rz_hash_dep, java_dep, capstone_dep ], @@ -188,25 +188,25 @@ r_anal = library('r_anal', r_anal_sources, soversion: r2_libversion ) -r_anal_dep = declare_dependency(link_with: r_anal, - include_directories: r_anal_inc) +rz_anal_dep = declare_dependency(link_with: rz_anal, + include_directories: rz_anal_inc) -pkgconfig_mod.generate(r_anal, - subdirs: 'libr', +pkgconfig_mod.generate(rz_anal, + subdirs: 'librz', version: r2_version, - name: 'r_anal', - filebase: 'r_anal', + name: 'rz_anal', + filebase: 'rz_anal', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_reg', - 'r_asm', - 'r_crypto', - 'r_parse', - 'r_syscall', - 'r_search', - 'r_cons', - 'r_flag' + 'rz_util', + 'rz_reg', + 'rz_asm', + 'rz_crypto', + 'rz_parse', + 'rz_syscall', + 'rz_search', + 'rz_cons', + 'rz_flag' ], description: 'radare foundation libraries' ) diff --git a/libr/anal/meta.c b/librz/anal/meta.c similarity index 55% rename from libr/anal/meta.c rename to librz/anal/meta.c index f6b0bc91d8..94965a7248 100644 --- a/libr/anal/meta.c +++ b/librz/anal/meta.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2008-2020 - nibble, pancake, thestr4ng3r */ -#include -#include +#include +#include -static bool item_matches_filter(RAnalMetaItem *item, RAnalMetaType type, R_NULLABLE const RSpace *space) { +static bool item_matches_filter(RzAnalMetaItem *item, RzAnalMetaType type, R_NULLABLE const RSpace *space) { return (type == R_META_TYPE_ANY || item->type == type) && (!space || item->space == space); } typedef struct { - RAnalMetaType type; + RzAnalMetaType type; const RSpace *space; RIntervalNode *node; @@ -24,28 +24,28 @@ static bool find_node_cb(RIntervalNode *node, void *user) { return true; } -static RIntervalNode *find_node_at(RAnal *anal, RAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { +static RIntervalNode *find_node_at(RzAnal *anal, RzAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { FindCtx ctx = { .type = type, .space = space, .node = NULL }; - r_interval_tree_all_at (&anal->meta, addr, find_node_cb, &ctx); + rz_interval_tree_all_at (&anal->meta, addr, find_node_cb, &ctx); return ctx.node; } -static RIntervalNode *find_node_in(RAnal *anal, RAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { +static RIntervalNode *find_node_in(RzAnal *anal, RzAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { FindCtx ctx = { .type = type, .space = space, .node = NULL }; - r_interval_tree_all_in (&anal->meta, addr, true, find_node_cb, &ctx); + rz_interval_tree_all_in (&anal->meta, addr, true, find_node_cb, &ctx); return ctx.node; } typedef struct { - RAnalMetaType type; + RzAnalMetaType type; const RSpace *space; RPVector/*RIntervalNode*/ *result; @@ -54,57 +54,57 @@ typedef struct { static bool collect_nodes_cb(RIntervalNode *node, void *user) { CollectCtx *ctx = user; if (item_matches_filter (node->data, ctx->type, ctx->space)) { - r_pvector_push (ctx->result, node); + rz_pvector_push (ctx->result, node); } return true; } -static RPVector *collect_nodes_at(RAnal *anal, RAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { +static RPVector *collect_nodes_at(RzAnal *anal, RzAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { CollectCtx ctx = { .type = type, .space = space, - .result = r_pvector_new (NULL) + .result = rz_pvector_new (NULL) }; if (!ctx.result) { return NULL; } - r_interval_tree_all_at (&anal->meta, addr, collect_nodes_cb, &ctx); + rz_interval_tree_all_at (&anal->meta, addr, collect_nodes_cb, &ctx); return ctx.result; } -static RPVector *collect_nodes_in(RAnal *anal, RAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { +static RPVector *collect_nodes_in(RzAnal *anal, RzAnalMetaType type, R_NULLABLE const RSpace *space, ut64 addr) { CollectCtx ctx = { .type = type, .space = space, - .result = r_pvector_new (NULL) + .result = rz_pvector_new (NULL) }; if (!ctx.result) { return NULL; } - r_interval_tree_all_in (&anal->meta, addr, true, collect_nodes_cb, &ctx); + rz_interval_tree_all_in (&anal->meta, addr, true, collect_nodes_cb, &ctx); return ctx.result; } -static RPVector *collect_nodes_intersect(RAnal *anal, RAnalMetaType type, R_NULLABLE const RSpace *space, ut64 start, ut64 end) { +static RPVector *collect_nodes_intersect(RzAnal *anal, RzAnalMetaType type, R_NULLABLE const RSpace *space, ut64 start, ut64 end) { CollectCtx ctx = { .type = type, .space = space, - .result = r_pvector_new (NULL) + .result = rz_pvector_new (NULL) }; if (!ctx.result) { return NULL; } - r_interval_tree_all_intersect (&anal->meta, start, end, true, collect_nodes_cb, &ctx); + rz_interval_tree_all_intersect (&anal->meta, start, end, true, collect_nodes_cb, &ctx); return ctx.result; } -static bool meta_set(RAnal *a, RAnalMetaType type, int subtype, ut64 from, ut64 to, const char *str) { +static bool meta_set(RzAnal *a, RzAnalMetaType type, int subtype, ut64 from, ut64 to, const char *str) { if (to < from) { return false; } - RSpace *space = r_spaces_current (&a->meta_spaces); + RSpace *space = rz_spaces_current (&a->meta_spaces); RIntervalNode *node = find_node_at (a, type, space, from); - RAnalMetaItem *item = node ? node->data : R_NEW0 (RAnalMetaItem); + RzAnalMetaItem *item = node ? node->data : R_NEW0 (RzAnalMetaItem); if (!item) { return false; } @@ -120,40 +120,40 @@ static bool meta_set(RAnal *a, RAnalMetaType type, int subtype, ut64 from, ut64 return false; } if (!node) { - r_interval_tree_insert (&a->meta, from, to, item); + rz_interval_tree_insert (&a->meta, from, to, item); } else if (node->end != to) { - r_interval_tree_resize (&a->meta, node, from, to); + rz_interval_tree_resize (&a->meta, node, from, to); } return true; } -R_API bool r_meta_set_string(RAnal *a, RAnalMetaType type, ut64 addr, const char *s) { +RZ_API bool rz_meta_set_string(RzAnal *a, RzAnalMetaType type, ut64 addr, const char *s) { return meta_set (a, type, 0, addr, addr, s); } -R_API const char *r_meta_get_string(RAnal *a, RAnalMetaType type, ut64 addr) { - RIntervalNode *node = find_node_at (a, type, r_spaces_current (&a->meta_spaces), addr); +RZ_API const char *rz_meta_get_string(RzAnal *a, RzAnalMetaType type, ut64 addr) { + RIntervalNode *node = find_node_at (a, type, rz_spaces_current (&a->meta_spaces), addr); if (!node) { return NULL; } - RAnalMetaItem *item = node->data; + RzAnalMetaItem *item = node->data; return item->str; } -static void del(RAnal *a, RAnalMetaType type, const RSpace *space, ut64 addr, ut64 size) { +static void del(RzAnal *a, RzAnalMetaType type, const RSpace *space, ut64 addr, ut64 size) { RPVector *victims = NULL; if (size == UT64_MAX) { // delete everything - victims = r_pvector_new (NULL); + victims = rz_pvector_new (NULL); if (!victims) { return; } RIntervalTreeIter it; - RAnalMetaItem *item; - r_interval_tree_foreach (&a->meta, it, item) { + RzAnalMetaItem *item; + rz_interval_tree_foreach (&a->meta, it, item) { if (item_matches_filter (item, type, space)) { - r_pvector_push (victims, r_interval_tree_iter_get (&it)); + rz_pvector_push (victims, rz_interval_tree_iter_get (&it)); } } } else { @@ -167,22 +167,22 @@ static void del(RAnal *a, RAnalMetaType type, const RSpace *space, ut64 addr, ut } } void **it; - r_pvector_foreach (victims, it) { - r_interval_tree_delete (&a->meta, *it, true); + rz_pvector_foreach (victims, it) { + rz_interval_tree_delete (&a->meta, *it, true); } - r_pvector_free (victims); + rz_pvector_free (victims); } -R_API void r_meta_del(RAnal *a, RAnalMetaType type, ut64 addr, ut64 size) { - del (a, type, r_spaces_current (&a->meta_spaces), addr, size); +RZ_API void rz_meta_del(RzAnal *a, RzAnalMetaType type, ut64 addr, ut64 size) { + del (a, type, rz_spaces_current (&a->meta_spaces), addr, size); } -R_API bool r_meta_set(RAnal *a, RAnalMetaType type, ut64 addr, ut64 size, const char *str) { - return r_meta_set_with_subtype (a, type, 0, addr, size, str); +RZ_API bool rz_meta_set(RzAnal *a, RzAnalMetaType type, ut64 addr, ut64 size, const char *str) { + return rz_meta_set_with_subtype (a, type, 0, addr, size, str); } -R_API bool r_meta_set_with_subtype(RAnal *m, RAnalMetaType type, int subtype, ut64 addr, ut64 size, const char *str) { - r_return_val_if_fail (m && size, false); +RZ_API bool rz_meta_set_with_subtype(RzAnal *m, RzAnalMetaType type, int subtype, ut64 addr, ut64 size, const char *str) { + rz_return_val_if_fail (m && size, false); ut64 end = addr + size - 1; if (end < addr) { end = UT64_MAX; @@ -190,36 +190,36 @@ R_API bool r_meta_set_with_subtype(RAnal *m, RAnalMetaType type, int subtype, ut return meta_set (m, type, subtype, addr, end, str); } -R_API RAnalMetaItem *r_meta_get_at(RAnal *a, ut64 addr, RAnalMetaType type, R_OUT R_NULLABLE ut64 *size) { - RIntervalNode *node = find_node_at (a, type, r_spaces_current (&a->meta_spaces), addr); +RZ_API RzAnalMetaItem *rz_meta_get_at(RzAnal *a, ut64 addr, RzAnalMetaType type, R_OUT R_NULLABLE ut64 *size) { + RIntervalNode *node = find_node_at (a, type, rz_spaces_current (&a->meta_spaces), addr); if (node && size) { - *size = r_meta_item_size (node->start, node->end); + *size = rz_meta_item_size (node->start, node->end); } return node ? node->data : NULL; } -R_API RIntervalNode *r_meta_get_in(RAnal *a, ut64 addr, RAnalMetaType type) { - return find_node_in (a, type, r_spaces_current (&a->meta_spaces), addr); +RZ_API RIntervalNode *rz_meta_get_in(RzAnal *a, ut64 addr, RzAnalMetaType type) { + return find_node_in (a, type, rz_spaces_current (&a->meta_spaces), addr); } -R_API RPVector/* *>*/ *r_meta_get_all_at(RAnal *a, ut64 at) { - return collect_nodes_at (a, R_META_TYPE_ANY, r_spaces_current (&a->meta_spaces), at); +RZ_API RPVector/* *>*/ *rz_meta_get_all_at(RzAnal *a, ut64 at) { + return collect_nodes_at (a, R_META_TYPE_ANY, rz_spaces_current (&a->meta_spaces), at); } -R_API RPVector *r_meta_get_all_in(RAnal *a, ut64 at, RAnalMetaType type) { - return collect_nodes_in (a, type, r_spaces_current (&a->meta_spaces), at); +RZ_API RPVector *rz_meta_get_all_in(RzAnal *a, ut64 at, RzAnalMetaType type) { + return collect_nodes_in (a, type, rz_spaces_current (&a->meta_spaces), at); } -R_API RPVector *r_meta_get_all_intersect(RAnal *a, ut64 start, ut64 size, RAnalMetaType type) { - r_return_val_if_fail (size, NULL); +RZ_API RPVector *rz_meta_get_all_intersect(RzAnal *a, ut64 start, ut64 size, RzAnalMetaType type) { + rz_return_val_if_fail (size, NULL); ut64 end = start + size - 1; if (end < start) { end = UT64_MAX; } - return collect_nodes_intersect (a, type, r_spaces_current (&a->meta_spaces), start, end); + return collect_nodes_intersect (a, type, rz_spaces_current (&a->meta_spaces), start, end); } -R_API const char *r_meta_type_to_string(int type) { +RZ_API const char *rz_meta_type_to_string(int type) { // XXX: use type as '%c' switch (type) { case R_META_TYPE_DATA: return "Cd"; @@ -236,28 +236,28 @@ R_API const char *r_meta_type_to_string(int type) { return "# unknown meta # "; } -R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { - r_return_if_fail (!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL +RZ_API void rz_meta_print(RzAnal *a, RzAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { + rz_return_if_fail (!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL char *pstr, *base64_str; - RCore *core = a->coreb.core; + RzCore *core = a->coreb.core; bool esc_bslash = core ? core->print->esc_bslash : false; - if (r_spaces_current (&a->meta_spaces) && - r_spaces_current (&a->meta_spaces) != d->space) { + if (rz_spaces_current (&a->meta_spaces) && + rz_spaces_current (&a->meta_spaces) != d->space) { return; } char *str = NULL; if (d->str) { if (d->type == R_META_TYPE_STRING) { if (d->subtype == R_STRING_ENC_UTF8) { - str = r_str_escape_utf8 (d->str, false, esc_bslash); + str = rz_str_escape_utf8 (d->str, false, esc_bslash); } else { if (!d->subtype) { /* temporary legacy workaround */ esc_bslash = false; } - str = r_str_escape_latin1 (d->str, false, esc_bslash, false); + str = rz_str_escape_latin1 (d->str, false, esc_bslash, false); } } else { - str = r_str_escape (d->str); + str = rz_str_escape (d->str); } } if (str || d->type == R_META_TYPE_DATA) { @@ -275,29 +275,29 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r // Sanitize (don't escape) Ct comments so we can see "char *", etc. free (str); str = strdup (d->str); - r_str_sanitize (str); + rz_str_sanitize (str); pstr = str; } else if (d->type != 'C') { - r_name_filter (str, 0); + rz_name_filter (str, 0); pstr = str; } else { pstr = d->str; } -// r_str_sanitize (str); +// rz_str_sanitize (str); switch (rad) { case 'j': pj_o (pj); pj_kn (pj, "offset", start); - pj_ks (pj, "type", r_meta_type_to_string (d->type)); + pj_ks (pj, "type", rz_meta_type_to_string (d->type)); if (d->type == 'H') { pj_k (pj, "color"); ut8 r = 0, g = 0, b = 0, A = 0; const char *esc = strchr (d->str, '\x1b'); if (esc) { - r_cons_rgb_parse (esc, &r, &g, &b, &A); - char *rgb_str = r_cons_rgb_tostring (r, g, b); - base64_str = r_base64_encode_dyn (rgb_str, -1); + rz_cons_rgb_parse (esc, &r, &g, &b, &A); + char *rgb_str = rz_cons_rgb_tostring (r, g, b); + base64_str = rz_base64_encode_dyn (rgb_str, -1); if (d->type == 's' && base64_str) { pj_s (pj, base64_str); free (base64_str); @@ -310,7 +310,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r } } else { pj_k (pj, "name"); - if (d->type == 's' && (base64_str = r_base64_encode_dyn (d->str, -1))) { + if (d->type == 's' && (base64_str = rz_base64_encode_dyn (d->str, -1))) { pj_s (pj, base64_str); } else { pj_s (pj, str); @@ -331,7 +331,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r enc = "latin1"; } pj_ks (pj, "enc", enc); - pj_kb (pj, "ascii", r_str_is_ascii (d->str)); + pj_kb (pj, "ascii", rz_str_is_ascii (d->str)); } pj_end (pj); @@ -343,7 +343,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r switch (d->type) { case R_META_TYPE_COMMENT: { - const char *type = r_meta_type_to_string (d->type); + const char *type = rz_meta_type_to_string (d->type); char *s = sdb_encode ((const ut8*)pstr, -1); if (!s) { s = strdup (pstr); @@ -358,7 +358,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r } } else { if (!strcmp (type, "CCu")) { - char *mys = r_str_escape (pstr); + char *mys = rz_str_escape (pstr); a->cb_printf ("0x%08"PFMT64x" %s \"%s\"\n", start, type, mys); free (mys); @@ -390,7 +390,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r enc = "utf8"; break; default: - enc = r_str_is_ascii (d->str) ? "ascii" : "latin1"; + enc = rz_str_is_ascii (d->str) ? "ascii" : "latin1"; } if (show_full) { a->cb_printf ("0x%08"PFMT64x" %s[%"PFMT64u"] \"%s\"\n", @@ -405,14 +405,14 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r case R_META_TYPE_DATA: if (rad) { a->cb_printf ("%s %"PFMT64u" @ 0x%08"PFMT64x"\n", - r_meta_type_to_string (d->type), + rz_meta_type_to_string (d->type), size, start); } else { if (show_full) { const char *dtype = d->type == 'h' ? "hidden" : "data"; a->cb_printf ("0x%08" PFMT64x " %s %s %"PFMT64u"\n", start, dtype, - r_meta_type_to_string (d->type), size); + rz_meta_type_to_string (d->type), size); } else { a->cb_printf ("%"PFMT64u"\n", size); } @@ -422,7 +422,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r case R_META_TYPE_FORMAT: if (rad) { a->cb_printf ("%s %"PFMT64u" %s @ 0x%08"PFMT64x"\n", - r_meta_type_to_string (d->type), + rz_meta_type_to_string (d->type), size, pstr, start); } else { if (show_full) { @@ -437,7 +437,7 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r case R_META_TYPE_VARTYPE: if (rad) { a->cb_printf ("%s %s @ 0x%08"PFMT64x"\n", - r_meta_type_to_string (d->type), pstr, start); + rz_meta_type_to_string (d->type), pstr, start); } else { a->cb_printf ("0x%08"PFMT64x" %s\n", start, pstr); } @@ -446,22 +446,22 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r { ut8 r = 0, g = 0, b = 0, A = 0; const char *esc = strchr (d->str, '\x1b'); - r_cons_rgb_parse (esc, &r, &g, &b, &A); + rz_cons_rgb_parse (esc, &r, &g, &b, &A); a->cb_printf ("%s rgb:%02x%02x%02x @ 0x%08"PFMT64x"\n", - r_meta_type_to_string (d->type), r, g, b, start); + rz_meta_type_to_string (d->type), r, g, b, start); // TODO: d->size } break; default: if (rad) { a->cb_printf ("%s %"PFMT64u" 0x%08"PFMT64x" # %s\n", - r_meta_type_to_string (d->type), + rz_meta_type_to_string (d->type), size, start, pstr); } else { // TODO: use b64 here a->cb_printf ("0x%08"PFMT64x" array[%"PFMT64u"] %s %s\n", start, size, - r_meta_type_to_string (d->type), pstr); + rz_meta_type_to_string (d->type), pstr); } break; } @@ -473,20 +473,20 @@ R_API void r_meta_print(RAnal *a, RAnalMetaItem *d, ut64 start, ut64 size, int r } } -R_API void r_meta_print_list_at(RAnal *a, ut64 addr, int rad) { - RPVector *nodes = collect_nodes_at (a, R_META_TYPE_ANY, r_spaces_current (&a->meta_spaces), addr); +RZ_API void rz_meta_print_list_at(RzAnal *a, ut64 addr, int rad) { + RPVector *nodes = collect_nodes_at (a, R_META_TYPE_ANY, rz_spaces_current (&a->meta_spaces), addr); if (!nodes) { return; } void **it; - r_pvector_foreach (nodes, it) { + rz_pvector_foreach (nodes, it) { RIntervalNode *node = *it; - r_meta_print (a, node->data, node->start, r_meta_node_size (node), rad, NULL, true); + rz_meta_print (a, node->data, node->start, rz_meta_node_size (node), rad, NULL, true); } - r_pvector_free (nodes); + rz_pvector_free (nodes); } -static void print_meta_list(RAnal *a, int type, int rad, ut64 addr) { +static void print_meta_list(RzAnal *a, int type, int rad, ut64 addr) { PJ *pj = NULL; if (rad == 'j') { pj = pj_new (); @@ -496,53 +496,53 @@ static void print_meta_list(RAnal *a, int type, int rad, ut64 addr) { pj_a (pj); } - RAnalFunction *fcn = NULL; + RzAnalFunction *fcn = NULL; if (addr != UT64_MAX) { - fcn = r_anal_get_fcn_in (a, addr, 0); + fcn = rz_anal_get_fcn_in (a, addr, 0); if (!fcn) { goto beach; } } RIntervalTreeIter it; - RAnalMetaItem *item; - r_interval_tree_foreach (&a->meta, it, item) { - RIntervalNode *node = r_interval_tree_iter_get (&it); + RzAnalMetaItem *item; + rz_interval_tree_foreach (&a->meta, it, item) { + RIntervalNode *node = rz_interval_tree_iter_get (&it); if (type != R_META_TYPE_ANY && item->type != type) { continue; } - if (fcn && !r_anal_function_contains (fcn, node->start)) { + if (fcn && !rz_anal_function_contains (fcn, node->start)) { continue; } - r_meta_print (a, item, node->start, r_meta_node_size (node), rad, pj, true); + rz_meta_print (a, item, node->start, rz_meta_node_size (node), rad, pj, true); } beach: if (pj) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } -R_API void r_meta_print_list_all(RAnal *a, int type, int rad) { +RZ_API void rz_meta_print_list_all(RzAnal *a, int type, int rad) { print_meta_list (a, type, rad, UT64_MAX); } -R_API void r_meta_print_list_in_function(RAnal *a, int type, int rad, ut64 addr) { +RZ_API void rz_meta_print_list_in_function(RzAnal *a, int type, int rad, ut64 addr) { print_meta_list (a, type, rad, addr); } -R_API void r_meta_rebase(RAnal *anal, ut64 diff) { +RZ_API void rz_meta_rebase(RzAnal *anal, ut64 diff) { if (!diff) { return; } RIntervalTree old = anal->meta; - r_interval_tree_init (&anal->meta, old.free); + rz_interval_tree_init (&anal->meta, old.free); RIntervalTreeIter it; - RAnalMetaItem *item; - r_interval_tree_foreach (&old, it, item) { - RIntervalNode *node = r_interval_tree_iter_get (&it); + RzAnalMetaItem *item; + rz_interval_tree_foreach (&old, it, item) { + RIntervalNode *node = rz_interval_tree_iter_get (&it); ut64 newstart = node->start + diff; ut64 newend = node->end + diff; if (newend < newstart) { @@ -550,23 +550,23 @@ R_API void r_meta_rebase(RAnal *anal, ut64 diff) { newstart = node->start; newend = node->end; } - r_interval_tree_insert (&anal->meta, newstart, newend, item); + rz_interval_tree_insert (&anal->meta, newstart, newend, item); } old.free = NULL; - r_interval_tree_fini (&old); + rz_interval_tree_fini (&old); } -R_API void r_meta_space_unset_for(RAnal *a, const RSpace *space) { +RZ_API void rz_meta_space_unset_for(RzAnal *a, const RSpace *space) { del (a, R_META_TYPE_ANY, space, 0, UT64_MAX); } -R_API ut64 r_meta_get_size(RAnal *a, RAnalMetaType type) { +RZ_API ut64 rz_meta_get_size(RzAnal *a, RzAnalMetaType type) { ut64 sum = 0; RIntervalTreeIter it; - RAnalMetaItem *item; + RzAnalMetaItem *item; RIntervalNode *prev = NULL; - r_interval_tree_foreach (&a->meta, it, item) { - RIntervalNode *node = r_interval_tree_iter_get (&it); + rz_interval_tree_foreach (&a->meta, it, item) { + RIntervalNode *node = rz_interval_tree_iter_get (&it); if (type != R_META_TYPE_ANY && item->type != type) { continue; } @@ -577,11 +577,11 @@ R_API ut64 r_meta_get_size(RAnal *a, RAnalMetaType type) { return sum; } -R_API int r_meta_space_count_for(RAnal *a, const RSpace *space) { +RZ_API int rz_meta_space_count_for(RzAnal *a, const RSpace *space) { int r = 0; RIntervalTreeIter it; - RAnalMetaItem *item; - r_interval_tree_foreach (&a->meta, it, item) { + RzAnalMetaItem *item; + rz_interval_tree_foreach (&a->meta, it, item) { if (item->space == space) { r++; } @@ -589,7 +589,7 @@ R_API int r_meta_space_count_for(RAnal *a, const RSpace *space) { return r; } -R_API void r_meta_set_data_at(RAnal *a, ut64 addr, ut64 wordsz) { - r_return_if_fail (wordsz); - r_meta_set (a, R_META_TYPE_DATA, addr, wordsz, NULL); +RZ_API void rz_meta_set_data_at(RzAnal *a, ut64 addr, ut64 wordsz) { + rz_return_if_fail (wordsz); + rz_meta_set (a, R_META_TYPE_DATA, addr, wordsz, NULL); } diff --git a/libr/anal/op.c b/librz/anal/op.c similarity index 83% rename from libr/anal/op.c rename to librz/anal/op.c index dae67122e4..9e954c0c07 100644 --- a/libr/anal/op.c +++ b/librz/anal/op.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2010-2020 - pancake, nibble */ -#include -#include -#include +#include +#include +#include -R_API RAnalOp *r_anal_op_new(void) { - RAnalOp *op = R_NEW (RAnalOp); - r_anal_op_init (op); +RZ_API RzAnalOp *rz_anal_op_new(void) { + RzAnalOp *op = R_NEW (RzAnalOp); + rz_anal_op_init (op); return op; } -R_API RList *r_anal_op_list_new(void) { - RList *list = r_list_new (); +RZ_API RzList *rz_anal_op_list_new(void) { + RzList *list = rz_list_new (); if (list) { - list->free = &r_anal_op_free; + list->free = &rz_anal_op_free; } return list; } -R_API void r_anal_op_init(RAnalOp *op) { +RZ_API void rz_anal_op_init(RzAnalOp *op) { if (op) { memset (op, 0, sizeof (*op)); op->addr = UT64_MAX; @@ -31,38 +31,38 @@ R_API void r_anal_op_init(RAnalOp *op) { } } -R_API bool r_anal_op_fini(RAnalOp *op) { +RZ_API bool rz_anal_op_fini(RzAnalOp *op) { if (!op) { return false; } - r_anal_value_free (op->src[0]); - r_anal_value_free (op->src[1]); - r_anal_value_free (op->src[2]); + rz_anal_value_free (op->src[0]); + rz_anal_value_free (op->src[1]); + rz_anal_value_free (op->src[2]); op->src[0] = NULL; op->src[1] = NULL; op->src[2] = NULL; - r_anal_value_free (op->dst); + rz_anal_value_free (op->dst); op->dst = NULL; - r_list_free (op->access); + rz_list_free (op->access); op->access = NULL; - r_strbuf_fini (&op->opex); - r_strbuf_fini (&op->esil); - r_anal_switch_op_free (op->switch_op); + rz_strbuf_fini (&op->opex); + rz_strbuf_fini (&op->esil); + rz_anal_switch_op_free (op->switch_op); op->switch_op = NULL; R_FREE (op->mnemonic); return true; } -R_API void r_anal_op_free(void *_op) { +RZ_API void rz_anal_op_free(void *_op) { if (!_op) { return; } - r_anal_op_fini (_op); - memset (_op, 0, sizeof (RAnalOp)); + rz_anal_op_fini (_op); + memset (_op, 0, sizeof (RzAnalOp)); free (_op); } -static int defaultCycles(RAnalOp *op) { +static int defaultCycles(RzAnalOp *op) { switch (op->type) { case R_ANAL_OP_TYPE_PUSH: case R_ANAL_OP_TYPE_POP: @@ -88,9 +88,9 @@ static int defaultCycles(RAnalOp *op) { } } -R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { - r_anal_op_init (op); - r_return_val_if_fail (anal && op && len > 0, -1); +RZ_API int rz_anal_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { + rz_anal_op_init (op); + rz_return_val_if_fail (anal && op && len > 0, -1); int ret = R_MIN (2, len); if (len > 0 && anal->cur && anal->cur->op) { @@ -125,21 +125,21 @@ R_API int r_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le } if (!op->mnemonic && (mask & R_ANAL_OP_MASK_DISASM)) { if (anal->verbose) { - eprintf ("Warning: unhandled R_ANAL_OP_MASK_DISASM in r_anal_op\n"); + eprintf ("Warning: unhandled R_ANAL_OP_MASK_DISASM in rz_anal_op\n"); } } if (mask & R_ANAL_OP_MASK_HINT) { - RAnalHint *hint = r_anal_hint_get (anal, addr); + RzAnalHint *hint = rz_anal_hint_get (anal, addr); if (hint) { - r_anal_op_hint (op, hint); - r_anal_hint_free (hint); + rz_anal_op_hint (op, hint); + rz_anal_hint_free (hint); } } return ret; } -R_API RAnalOp *r_anal_op_copy(RAnalOp *op) { - RAnalOp *nop = R_NEW0 (RAnalOp); +RZ_API RzAnalOp *rz_anal_op_copy(RzAnalOp *op) { + RzAnalOp *nop = R_NEW0 (RzAnalOp); if (!nop) { return NULL; } @@ -153,25 +153,25 @@ R_API RAnalOp *r_anal_op_copy(RAnalOp *op) { } else { nop->mnemonic = NULL; } - nop->src[0] = r_anal_value_copy (op->src[0]); - nop->src[1] = r_anal_value_copy (op->src[1]); - nop->src[2] = r_anal_value_copy (op->src[2]); - nop->dst = r_anal_value_copy (op->dst); + nop->src[0] = rz_anal_value_copy (op->src[0]); + nop->src[1] = rz_anal_value_copy (op->src[1]); + nop->src[2] = rz_anal_value_copy (op->src[2]); + nop->dst = rz_anal_value_copy (op->dst); if (op->access) { - RListIter *it; - RAnalValue *val; - RList *naccess = r_list_newf ((RListFree)r_anal_value_free); - r_list_foreach (op->access, it, val) { - r_list_append (naccess, r_anal_value_copy (val)); + RzListIter *it; + RzAnalValue *val; + RzList *naccess = rz_list_newf ((RzListFree)rz_anal_value_free); + rz_list_foreach (op->access, it, val) { + rz_list_append (naccess, rz_anal_value_copy (val)); } nop->access = naccess; } - r_strbuf_init (&nop->esil); - r_strbuf_copy (&nop->esil, &op->esil); + rz_strbuf_init (&nop->esil); + rz_strbuf_copy (&nop->esil, &op->esil); return nop; } -R_API bool r_anal_op_nonlinear(int t) { +RZ_API bool rz_anal_op_nonlinear(int t) { t &= R_ANAL_OP_TYPE_MASK; switch (t) { //call @@ -202,7 +202,7 @@ R_API bool r_anal_op_nonlinear(int t) { } } -R_API bool r_anal_op_ismemref(int t) { +RZ_API bool rz_anal_op_ismemref(int t) { t &= R_ANAL_OP_TYPE_MASK; switch (t) { case R_ANAL_OP_TYPE_LOAD: @@ -284,7 +284,7 @@ static struct optype { {0,NULL} }; -R_API int r_anal_optype_from_string(const char *type) { +RZ_API int rz_anal_optype_from_string(const char *type) { int i; for (i = 0; optypes[i].name;i++) { if (!strcmp (optypes[i].name, type)) { @@ -294,7 +294,7 @@ R_API int r_anal_optype_from_string(const char *type) { return -1; } -R_API const char *r_anal_optype_to_string(int t) { +RZ_API const char *rz_anal_optype_to_string(int t) { bool once = true; repeat: // TODO: delete @@ -369,18 +369,18 @@ repeat: return "undefined"; } -R_API const char *r_anal_op_to_esil_string(RAnal *anal, RAnalOp *op) { - return r_strbuf_get (&op->esil); +RZ_API const char *rz_anal_op_to_esil_string(RzAnal *anal, RzAnalOp *op) { + return rz_strbuf_get (&op->esil); } // TODO: use esil here? -R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { - RAnalBlock *bb; - RAnalFunction *f; +RZ_API char *rz_anal_op_to_string(RzAnal *anal, RzAnalOp *op) { + RzAnalBlock *bb; + RzAnalFunction *f; char *cstr, ret[128]; - char *r0 = r_anal_value_to_string (op->dst); - char *a0 = r_anal_value_to_string (op->src[0]); - char *a1 = r_anal_value_to_string (op->src[1]); + char *r0 = rz_anal_value_to_string (op->dst); + char *a0 = rz_anal_value_to_string (op->src[0]); + char *a1 = rz_anal_value_to_string (op->src[1]); if (!r0) { r0 = strdup ("?"); } @@ -396,8 +396,8 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { snprintf (ret, sizeof (ret), "%s = %s", r0, a0); break; case R_ANAL_OP_TYPE_CJMP: - if ((bb = r_anal_bb_from_offset (anal, op->addr))) { - cstr = r_anal_cond_to_string (bb->cond); + if ((bb = rz_anal_bb_from_offset (anal, op->addr))) { + cstr = rz_anal_cond_to_string (bb->cond); snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, cstr, op->jump); free (cstr); } else { @@ -428,7 +428,7 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { snprintf (ret, sizeof (ret), "%s()", r0); break; case R_ANAL_OP_TYPE_CALL: - f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); + f = rz_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); if (f) { snprintf (ret, sizeof (ret), "%s()", f->name); } else { @@ -436,9 +436,9 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { } break; case R_ANAL_OP_TYPE_CCALL: - f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); - if ((bb = r_anal_bb_from_offset (anal, op->addr))) { - cstr = r_anal_cond_to_string (bb->cond); + f = rz_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL); + if ((bb = rz_anal_bb_from_offset (anal, op->addr))) { + cstr = rz_anal_cond_to_string (bb->cond); if (f) { snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name); } else { @@ -515,8 +515,8 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { memcpy (ret, "ret", 4); break; case R_ANAL_OP_TYPE_CRET: - if ((bb = r_anal_bb_from_offset (anal, op->addr))) { - cstr = r_anal_cond_to_string (bb->cond); + if ((bb = rz_anal_bb_from_offset (anal, op->addr))) { + cstr = rz_anal_cond_to_string (bb->cond); snprintf (ret, sizeof (ret), "if (%s) ret", cstr); free (cstr); } else { @@ -561,7 +561,7 @@ R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) { return strdup (ret); } -R_API const char *r_anal_stackop_tostring(int s) { +RZ_API const char *rz_anal_stackop_tostring(int s) { switch (s) { case R_ANAL_STACK_NULL: return "null"; @@ -579,7 +579,7 @@ R_API const char *r_anal_stackop_tostring(int s) { return "unk"; } -R_API const char *r_anal_op_family_to_string(int n) { +RZ_API const char *rz_anal_op_family_to_string(int n) { switch (n) { case R_ANAL_OP_FAMILY_UNKNOWN: return "unk"; case R_ANAL_OP_FAMILY_CPU: return "cpu"; @@ -596,7 +596,7 @@ R_API const char *r_anal_op_family_to_string(int n) { return NULL; } -R_API int r_anal_op_family_from_string(const char *f) { +RZ_API int rz_anal_op_family_from_string(const char *f) { struct op_family { const char *name; int id; @@ -624,7 +624,7 @@ R_API int r_anal_op_family_from_string(const char *f) { } /* apply hint to op, return the number of hints applied */ -R_API int r_anal_op_hint(RAnalOp *op, RAnalHint *hint) { +RZ_API int rz_anal_op_hint(RzAnalOp *op, RzAnalHint *hint) { int changes = 0; if (hint) { if (hint->val != UT64_MAX) { @@ -650,7 +650,7 @@ R_API int r_anal_op_hint(RAnalOp *op, RAnalHint *hint) { changes++; } if (hint->esil) { - r_strbuf_set (&op->esil, hint->esil); + rz_strbuf_set (&op->esil, hint->esil); changes++; } if (hint->size) { @@ -664,11 +664,11 @@ R_API int r_anal_op_hint(RAnalOp *op, RAnalHint *hint) { // returns the '33' in 'rax + 33' // returns value for the given register name in specific address / range // imho this should not iterate, should be just a helper to get that value -R_API int r_anal_op_reg_delta(RAnal *anal, ut64 addr, const char *name) { +RZ_API int rz_anal_op_reg_delta(RzAnal *anal, ut64 addr, const char *name) { ut8 buf[32]; anal->iob.read_at (anal->iob.io, addr, buf, sizeof (buf)); - RAnalOp op = { 0 }; - if (r_anal_op (anal, &op, addr, buf, sizeof (buf), R_ANAL_OP_MASK_ALL) > 0) { + RzAnalOp op = { 0 }; + if (rz_anal_op (anal, &op, addr, buf, sizeof (buf), R_ANAL_OP_MASK_ALL) > 0) { if (op.dst && op.dst->reg && op.dst->reg->name && (!name || !strcmp (op.dst->reg->name, name))) { if (op.src[0]) { return op.src[0]->delta; diff --git a/libr/anal/p/6502.mk b/librz/anal/p/6502.mk similarity index 100% rename from libr/anal/p/6502.mk rename to librz/anal/p/6502.mk diff --git a/libr/anal/p/6502_cs.mk b/librz/anal/p/6502_cs.mk similarity index 100% rename from libr/anal/p/6502_cs.mk rename to librz/anal/p/6502_cs.mk diff --git a/libr/anal/p/8051.mk b/librz/anal/p/8051.mk similarity index 100% rename from libr/anal/p/8051.mk rename to librz/anal/p/8051.mk diff --git a/libr/anal/p/Makefile b/librz/anal/p/Makefile similarity index 87% rename from libr/anal/p/Makefile rename to librz/anal/p/Makefile index 9104c6b9d5..21454e20af 100644 --- a/libr/anal/p/Makefile +++ b/librz/anal/p/Makefile @@ -2,7 +2,7 @@ include ../../config.mk include ../../../mk/platform.mk CFLAGS+=-I../../include -I../arch -Wall -shared $(PIC_CFLAGS) ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}.. -CFLAGS+=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg -L../../crypto -lr_crypto +CFLAGS+=-L../../util -lrz_util -L../../anal -lrz_anal -L../../reg -lrz_reg -L../../crypto -lrz_crypto LDFLAGS+=${LINK} CURDIR= diff --git a/libr/anal/p/amd29k.mk b/librz/anal/p/amd29k.mk similarity index 100% rename from libr/anal/p/amd29k.mk rename to librz/anal/p/amd29k.mk diff --git a/libr/anal/p/anal_6502.c b/librz/anal/p/anal_6502.c similarity index 79% rename from libr/anal/p/anal_6502.c rename to librz/anal/p/anal_6502.c index ce6e748720..47d6d81fa1 100644 --- a/libr/anal/p/anal_6502.c +++ b/librz/anal/p/anal_6502.c @@ -9,10 +9,10 @@ */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/snes/snes_op_table.h" enum { @@ -26,24 +26,24 @@ enum { _6502_FLAGS_BNZ = (_6502_FLAGS_B | _6502_FLAGS_Z | _6502_FLAGS_N), }; -static void _6502_anal_update_flags(RAnalOp *op, int flags) { +static void _6502_anal_update_flags(RzAnalOp *op, int flags) { /* FIXME: 9,$b instead of 8,$b to prevent the bug triggered by: A = 0 - 0xff - 1 */ if (flags & _6502_FLAGS_B) { - r_strbuf_append (&op->esil, ",9,$b,C,:="); + rz_strbuf_append (&op->esil, ",9,$b,C,:="); } if (flags & _6502_FLAGS_C) { - r_strbuf_append (&op->esil, ",7,$c,C,:="); + rz_strbuf_append (&op->esil, ",7,$c,C,:="); } if (flags & _6502_FLAGS_Z) { - r_strbuf_append (&op->esil, ",$z,Z,:="); + rz_strbuf_append (&op->esil, ",$z,Z,:="); } if (flags & _6502_FLAGS_N) { - r_strbuf_append (&op->esil, ",7,$s,N,:="); + rz_strbuf_append (&op->esil, ",7,$s,N,:="); } } /* ORA, AND, EOR, ADC, STA, LDA, CMP and SBC share this pattern */ -static void _6502_anal_esil_get_addr_pattern1(RAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize) { +static void _6502_anal_esil_get_addr_pattern1(RzAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize) { if (len < 1) { return; } @@ -88,7 +88,7 @@ static void _6502_anal_esil_get_addr_pattern1(RAnalOp *op, const ut8* data, int } /* ASL, ROL, LSR, ROR, STX, LDX, DEC and INC share this pattern */ -static void _6502_anal_esil_get_addr_pattern2(RAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize, char reg) { +static void _6502_anal_esil_get_addr_pattern2(RzAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize, char reg) { // turn off bits 5, 6 and 7 if (len < 1) { return; @@ -122,7 +122,7 @@ static void _6502_anal_esil_get_addr_pattern2(RAnalOp *op, const ut8* data, int } /* BIT, JMP, JMP(), STY, LDY, CPY, and CPX share this pattern */ -static void _6502_anal_esil_get_addr_pattern3(RAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize, char reg) { +static void _6502_anal_esil_get_addr_pattern3(RzAnalOp *op, const ut8* data, int len, char* addrbuf, int addrsize, char reg) { // turn off bits 5, 6 and 7 if (len < 1) { return; @@ -155,7 +155,7 @@ static void _6502_anal_esil_get_addr_pattern3(RAnalOp *op, const ut8* data, int } } -static void _6502_anal_esil_ccall(RAnalOp *op, ut8 data0) { +static void _6502_anal_esil_ccall(RzAnalOp *op, ut8 data0) { char *flag; switch (data0) { case 0x10: // bpl $ffff @@ -187,11 +187,11 @@ static void _6502_anal_esil_ccall(RAnalOp *op, ut8 data0) { flag = "unk"; break; } - r_strbuf_setf (&op->esil, "%s,?{,0x%04x,pc,=,}", flag, (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "%s,?{,0x%04x,pc,=,}", flag, (op->jump & 0xffff)); } // inc register -static void _6502_anal_esil_inc_reg(RAnalOp *op, ut8 data0, char* sign) { +static void _6502_anal_esil_inc_reg(RzAnalOp *op, ut8 data0, char* sign) { char* reg = NULL; switch(data0) { @@ -204,11 +204,11 @@ static void _6502_anal_esil_inc_reg(RAnalOp *op, ut8 data0, char* sign) { reg = "y"; break; } - r_strbuf_setf (&op->esil, "%s,%s%s=", reg, sign, sign); + rz_strbuf_setf (&op->esil, "%s,%s%s=", reg, sign, sign); _6502_anal_update_flags (op, _6502_FLAGS_NZ); } -static void _6502_anal_esil_mov(RAnalOp *op, ut8 data0) { +static void _6502_anal_esil_mov(RzAnalOp *op, ut8 data0) { const char* src="unk"; const char* dst="unk"; switch(data0) { @@ -240,7 +240,7 @@ static void _6502_anal_esil_mov(RAnalOp *op, ut8 data0) { // FIXME: should not happen break; } - r_strbuf_setf (&op->esil, "%s,%s,=",src,dst); + rz_strbuf_setf (&op->esil, "%s,%s,=",src,dst); // don't update NZ on txs if (data0 != 0x9a) { @@ -248,27 +248,27 @@ static void _6502_anal_esil_mov(RAnalOp *op, ut8 data0) { } } -static void _6502_anal_esil_push(RAnalOp *op, ut8 data0) { +static void _6502_anal_esil_push(RzAnalOp *op, ut8 data0) { // case 0x08: // php // case 0x48: // pha char *reg = (data0==0x08) ? "flags" : "a"; // stack is on page one: sp + 0x100 - r_strbuf_setf (&op->esil, "%s,sp,0x100,+,=[1],sp,--=", reg); + rz_strbuf_setf (&op->esil, "%s,sp,0x100,+,=[1],sp,--=", reg); } -static void _6502_anal_esil_pop(RAnalOp *op, ut8 data0) { +static void _6502_anal_esil_pop(RzAnalOp *op, ut8 data0) { // case 0x28: // plp // case 0x68: // pla char *reg = (data0==0x28) ? "flags" : "a"; // stack is on page one: sp + 0x100 - r_strbuf_setf (&op->esil, "sp,++=,sp,0x100,+,[1],%s,=", reg); + rz_strbuf_setf (&op->esil, "sp,++=,sp,0x100,+,[1],%s,=", reg); if (data0 == 0x68) { _6502_anal_update_flags (op, _6502_FLAGS_NZ); } } -static void _6502_anal_esil_flags(RAnalOp *op, ut8 data0) { +static void _6502_anal_esil_flags(RzAnalOp *op, ut8 data0) { int enabled=0; char flag ='u'; switch(data0) { @@ -302,10 +302,10 @@ static void _6502_anal_esil_flags(RAnalOp *op, ut8 data0) { break; break; } - r_strbuf_setf (&op->esil, "%d,%c,=", enabled, flag); + rz_strbuf_setf (&op->esil, "%d,%c,=", enabled, flag); } -static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int _6502_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { char addrbuf[64]; const int buffsize = sizeof (addrbuf) - 1; if (len < 1) { @@ -316,7 +316,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->addr = addr; op->type = R_ANAL_OP_TYPE_UNK; op->id = data[0]; - r_strbuf_init (&op->esil); + rz_strbuf_init (&op->esil); switch (data[0]) { case 0x02: case 0x03: @@ -438,7 +438,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le // PC + 2 to Stack, P to Stack B=1 D=0 I=1. "B" is not a flag. Only its bit is pushed on the stack // PC was already incremented by one at this point. Needs to incremented once more // New PC is Interrupt Vector: $fffe. (FIXME: Confirm this is valid for all 6502) - r_strbuf_set (&op->esil, ",1,I,=,0,D,=,flags,0x10,|,0x100,sp,+,=[1],pc,1,+,0xfe,sp,+,=[2],3,sp,-=,0xfffe,[2],pc,="); + rz_strbuf_set (&op->esil, ",1,I,=,0,D,=,flags,0x10,|,0x100,sp,+,=[1],pc,1,+,0xfe,sp,+,=[2],3,sp,-=,0xfffe,[2],pc,="); break; // FLAGS @@ -459,7 +459,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x2c: // bit $ffff op->type = R_ANAL_OP_TYPE_MOV; _6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 0); - r_strbuf_setf (&op->esil, "%s,[1],0x80,&,!,!,N,=,%s,[1],0x40,&,!,!,V,=,a,%s,[1],&,0xff,&,!,Z,=", addrbuf, addrbuf, addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],0x80,&,!,!,N,=,%s,[1],0x40,&,!,!,V,=,a,%s,[1],&,0xff,&,!,Z,=", addrbuf, addrbuf, addrbuf); break; // ADC case 0x69: // adc #$ff @@ -475,13 +475,13 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_ADD; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0x69) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,+=,7,$c,C,a,+=,7,$c,|,C,:=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); // fix Z - r_strbuf_append (&op->esil, ",a,a,=,$z,Z,:="); + rz_strbuf_append (&op->esil, ",a,a,=,$z,Z,:="); break; // SBC case 0xe9: // sbc #$ff @@ -497,13 +497,13 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_SUB; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0xe9) { // immediate mode - r_strbuf_setf (&op->esil, "C,!,%s,+,a,-=", addrbuf); + rz_strbuf_setf (&op->esil, "C,!,%s,+,a,-=", addrbuf); } else { - r_strbuf_setf (&op->esil, "C,!,%s,[1],+,a,-=", addrbuf); + rz_strbuf_setf (&op->esil, "C,!,%s,[1],+,a,-=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_BNZ); // fix Z and revert C - r_strbuf_append (&op->esil, ",a,a,=,$z,Z,:=,C,!="); + rz_strbuf_append (&op->esil, ",a,a,=,$z,Z,:=,C,!="); break; // ORA case 0x09: // ora #$ff @@ -517,9 +517,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_OR; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0x09) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,|=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,|=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,|=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,|=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -535,9 +535,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_AND; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0x29) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,&=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,&=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,&=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,&=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -553,9 +553,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_XOR; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0x49) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,^=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,^=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,^=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,^=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -567,10 +567,10 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x1e: // asl $ffff,x op->type = R_ANAL_OP_TYPE_SHL; if (data[0] == 0x0a) { - r_strbuf_set (&op->esil, "1,a,<<=,7,$c,C,:=,a,a,="); + rz_strbuf_set (&op->esil, "1,a,<<=,7,$c,C,:=,a,a,="); } else { _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "1,%s,[1],<<,%s,=[1],7,$c,C,:=", addrbuf, addrbuf); + rz_strbuf_setf (&op->esil, "1,%s,[1],<<,%s,=[1],7,$c,C,:=", addrbuf, addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -582,10 +582,10 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x5e: // lsr $ffff,x op->type = R_ANAL_OP_TYPE_SHR; if (data[0] == 0x4a) { - r_strbuf_set (&op->esil, "1,a,&,C,=,1,a,>>="); + rz_strbuf_set (&op->esil, "1,a,&,C,=,1,a,>>="); } else { _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "1,%s,[1],&,C,=,1,%s,[1],>>,%s,=[1]", addrbuf, addrbuf, addrbuf); + rz_strbuf_setf (&op->esil, "1,%s,[1],&,C,=,1,%s,[1],>>,%s,=[1]", addrbuf, addrbuf, addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -597,10 +597,10 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x3e: // rol $ffff,x op->type = R_ANAL_OP_TYPE_ROL; if (data[0] == 0x2a) { - r_strbuf_set (&op->esil, "1,a,<<,C,|,a,=,7,$c,C,:=,a,a,="); + rz_strbuf_set (&op->esil, "1,a,<<,C,|,a,=,7,$c,C,:=,a,a,="); } else { _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "1,%s,[1],<<,C,|,%s,=[1],7,$c,C,:=", addrbuf, addrbuf); + rz_strbuf_setf (&op->esil, "1,%s,[1],<<,C,|,%s,=[1],7,$c,C,:=", addrbuf, addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -614,10 +614,10 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le // it is not temporary since in all ROR ops, N will have the value of C op->type = R_ANAL_OP_TYPE_ROR; if (data[0] == 0x6a) { - r_strbuf_set (&op->esil, "C,N,=,1,a,&,C,=,1,a,>>,7,N,<<,|,a,="); + rz_strbuf_set (&op->esil, "C,N,=,1,a,&,C,=,1,a,>>,7,N,<<,|,a,="); } else { _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "C,N,=,1,%s,[1],&,C,=,1,%s,[1],>>,7,N,<<,|,%s,=[1]", addrbuf, addrbuf, addrbuf); + rz_strbuf_setf (&op->esil, "C,N,=,1,%s,[1],&,C,=,1,%s,[1],>>,7,N,<<,|,%s,=[1]", addrbuf, addrbuf, addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -628,7 +628,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0xfe: // inc $ffff,x op->type = R_ANAL_OP_TYPE_STORE; _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "%s,++=[1]", addrbuf); + rz_strbuf_setf (&op->esil, "%s,++=[1]", addrbuf); _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; // DEC @@ -638,7 +638,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0xde: // dec $ffff,x op->type = R_ANAL_OP_TYPE_STORE; _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "%s,--=[1]", addrbuf); + rz_strbuf_setf (&op->esil, "%s,--=[1]", addrbuf); _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; // INX, INY @@ -667,13 +667,13 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_CMP; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0xc9) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,==", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,==", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_BNZ); // invert C, since C=1 when A-M >= 0 - r_strbuf_append (&op->esil, ",C,!,C,="); + rz_strbuf_append (&op->esil, ",C,!,C,="); break; // CPX case 0xe0: // cpx #$ff @@ -682,13 +682,13 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_CMP; _6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 0); if (data[0] == 0xe0) { // immediate mode - r_strbuf_setf (&op->esil, "%s,x,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,x,==", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],x,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],x,==", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_BNZ); // invert C, since C=1 when A-M >= 0 - r_strbuf_append (&op->esil, ",C,!,C,="); + rz_strbuf_append (&op->esil, ",C,!,C,="); break; // CPY case 0xc0: // cpy #$ff @@ -697,13 +697,13 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_CMP; _6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 0); if (data[0] == 0xc0) { // immediate mode - r_strbuf_setf (&op->esil, "%s,y,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,y,==", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],y,==", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],y,==", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_BNZ); // invert C, since C=1 when A-M >= 0 - r_strbuf_append (&op->esil, ",C,!,C,="); + rz_strbuf_append (&op->esil, ",C,!,C,="); break; // BRANCHES case 0x10: // bpl $ffff @@ -743,21 +743,21 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le // JSR pushes the address-1 of the next operation on to the stack before transferring program // control to the following address // stack is on page one and sp is an 8-bit reg: operations must be done like: sp + 0x100 - r_strbuf_setf (&op->esil, "1,pc,-,0xff,sp,+,=[2],0x%04x,pc,=,2,sp,-=", op->jump); + rz_strbuf_setf (&op->esil, "1,pc,-,0xff,sp,+,=[2],0x%04x,pc,=,2,sp,-=", op->jump); break; // JMP case 0x4c: // jmp $ffff op->cycles = 3; op->type = R_ANAL_OP_TYPE_JMP; op->jump = (len > 2)? data[1] | data[2] << 8: 0; - r_strbuf_setf (&op->esil, "0x%04x,pc,=", op->jump); + rz_strbuf_setf (&op->esil, "0x%04x,pc,=", op->jump); break; case 0x6c: // jmp ($ffff) op->cycles = 5; op->type = R_ANAL_OP_TYPE_UJMP; // FIXME: how to read memory? // op->jump = data[1] | data[2] << 8; - r_strbuf_setf (&op->esil, "0x%04x,[2],pc,=", len > 2? data[1] | data[2] << 8: 0); + rz_strbuf_setf (&op->esil, "0x%04x,[2],pc,=", len > 2? data[1] | data[2] << 8: 0); break; // RTS case 0x60: // rts @@ -768,7 +768,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->stackptr = -2; // Operation: PC from Stack, PC + 1 -> PC // stack is on page one and sp is an 8-bit reg: operations must be done like: sp + 0x100 - r_strbuf_set (&op->esil, "0x101,sp,+,[2],pc,=,pc,++=,2,sp,+="); + rz_strbuf_set (&op->esil, "0x101,sp,+,[2],pc,=,pc,++=,2,sp,+="); break; // RTI case 0x40: // rti @@ -779,7 +779,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->stackptr = -3; // Operation: P from Stack, PC from Stack // stack is on page one and sp is an 8-bit reg: operations must be done like: sp + 0x100 - r_strbuf_set (&op->esil, "0x101,sp,+,[1],flags,=,0x102,sp,+,[2],pc,=,3,sp,+="); + rz_strbuf_set (&op->esil, "0x101,sp,+,[1],flags,=,0x102,sp,+,[2],pc,=,3,sp,+="); break; // NOP case 0xea: // nop @@ -798,9 +798,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_LOAD; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); if (data[0] == 0xa9) { // immediate mode - r_strbuf_setf (&op->esil, "%s,a,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,a,=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],a,=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -813,9 +813,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_LOAD; _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'y'); if (data[0] == 0xa2) { // immediate mode - r_strbuf_setf (&op->esil, "%s,x,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,x,=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],x,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],x,=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -828,9 +828,9 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_LOAD; _6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 'x'); if (data[0] == 0xa0) { // immediate mode - r_strbuf_setf (&op->esil, "%s,y,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,y,=", addrbuf); } else { - r_strbuf_setf (&op->esil, "%s,[1],y,=", addrbuf); + rz_strbuf_setf (&op->esil, "%s,[1],y,=", addrbuf); } _6502_anal_update_flags (op, _6502_FLAGS_NZ); break; @@ -844,7 +844,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x91: // sta ($ff),y op->type = R_ANAL_OP_TYPE_STORE; _6502_anal_esil_get_addr_pattern1 (op, data, len, addrbuf, buffsize); - r_strbuf_setf (&op->esil, "a,%s,=[1]", addrbuf); + rz_strbuf_setf (&op->esil, "a,%s,=[1]", addrbuf); break; // STX case 0x86: // stx $ff @@ -852,7 +852,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x8e: // stx $ffff op->type = R_ANAL_OP_TYPE_STORE; _6502_anal_esil_get_addr_pattern2 (op, data, len, addrbuf, buffsize, 'y'); - r_strbuf_setf (&op->esil, "x,%s,=[1]", addrbuf); + rz_strbuf_setf (&op->esil, "x,%s,=[1]", addrbuf); break; // STY case 0x84: // sty $ff @@ -860,7 +860,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case 0x8c: // sty $ffff op->type = R_ANAL_OP_TYPE_STORE; _6502_anal_esil_get_addr_pattern3 (op, data, len, addrbuf, buffsize, 'x'); - r_strbuf_setf (&op->esil, "y,%s,=[1]", addrbuf); + rz_strbuf_setf (&op->esil, "y,%s,=[1]", addrbuf); break; // PHP/PHA case 0x08: // php @@ -907,7 +907,7 @@ static int _6502_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { char *p = "=PC pc\n" "=SP sp\n" @@ -927,26 +927,26 @@ static bool set_reg_profile(RAnal *anal) { "gpr N .1 .31 0\n" "gpr sp .8 4 0\n" "gpr pc .16 5 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int esil_6502_init (RAnalEsil *esil) { +static int esil_6502_init (RzAnalEsil *esil) { if (esil->anal && esil->anal->reg) { //initial values - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "pc", -1), 0x0000); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "sp", -1), 0xff); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "a", -1), 0x00); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "x", -1), 0x00); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "y", -1), 0x00); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "flags", -1), 0x00); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "pc", -1), 0x0000); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "sp", -1), 0xff); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "a", -1), 0x00); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "x", -1), 0x00); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "y", -1), 0x00); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "flags", -1), 0x00); } return true; } -static int esil_6502_fini (RAnalEsil *esil) { +static int esil_6502_fini (RzAnalEsil *esil) { return true; } -RAnalPlugin r_anal_plugin_6502 = { +RzAnalPlugin rz_anal_plugin_6502 = { .name = "6502", .desc = "6502/NES analysis plugin", .license = "LGPL3", @@ -960,9 +960,9 @@ RAnalPlugin r_anal_plugin_6502 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_6502, + .data = &rz_anal_plugin_6502, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_6502_cs.c b/librz/anal/p/anal_6502_cs.c similarity index 89% rename from libr/anal/p/anal_6502_cs.c rename to librz/anal/p/anal_6502_cs.c index f38d61139e..13db8b01e4 100644 --- a/libr/anal/p/anal_6502_cs.c +++ b/librz/anal/p/anal_6502_cs.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2018 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include #if CS_API_MAJOR >= 4 && CS_API_MINOR >= 1 @@ -18,9 +18,9 @@ static csh handle = 0; -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static int omode = 0; -#if USE_ITER_API +#if USE_ITERZ_API static #endif cs_insn *insn = NULL; @@ -42,7 +42,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn op->cycles = 1; // aprox cs_option (handle, CS_OPT_DETAIL, CS_OPT_ON); // capstone-next -#if USE_ITER_API +#if USE_ITERZ_API { ut64 naddr = addr; size_t size = len; @@ -161,14 +161,14 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn break; } } -#if !USE_ITER_API +#if !USE_ITERZ_API cs_free (insn, n); #endif //cs_close (&handle); return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { char *p = "=PC pc\n" "=SP sp\n" @@ -188,10 +188,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr N .1 .31 0\n" "gpr sp .8 4 0\n" "gpr pc .16 5 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_6502_cs = { +RzAnalPlugin rz_anal_plugin_6502_cs = { .name = "6502.cs", .desc = "Capstone mos65xx analysis plugin", .license = "LGPL3", @@ -202,15 +202,15 @@ RAnalPlugin r_anal_plugin_6502_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_6502_cs, + .data = &rz_anal_plugin_6502_cs, .version = R2_VERSION }; #endif #else // empty plugin -RAnalPlugin r_anal_plugin_6502_cs = { +RzAnalPlugin rz_anal_plugin_6502_cs = { .name = "6502.cs", .desc = "Capstone mos65xx analysis plugin (not supported)", .license = "LGPL3", @@ -219,7 +219,7 @@ RAnalPlugin r_anal_plugin_6502_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, .version = R2_VERSION }; diff --git a/libr/anal/p/anal_8051.c b/librz/anal/p/anal_8051.c similarity index 84% rename from libr/anal/p/anal_8051.c rename to librz/anal/p/anal_8051.c index 89846d836e..e59d48730c 100644 --- a/libr/anal/p/anal_8051.c +++ b/librz/anal/p/anal_8051.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2013-2019 - pancake, dkreuter, astuder */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include <8051_ops.h> #include "../asm/arch/8051/8051_disas.c" @@ -43,29 +43,29 @@ static i8051_cpu_model cpu_models[] = { static bool i8051_is_init = false; static const i8051_cpu_model *cpu_curr_model = NULL; -static bool i8051_reg_write (RReg *reg, const char *regname, ut32 num) { +static bool i8051_reg_write (RzReg *reg, const char *regname, ut32 num) { if (reg) { - RRegItem *item = r_reg_get (reg, regname, R_REG_TYPE_GPR); + RzRegItem *item = rz_reg_get (reg, regname, R_REG_TYPE_GPR); if (item) { - r_reg_set_value (reg, item, num); + rz_reg_set_value (reg, item, num); return true; } } return false; } -static ut32 i8051_reg_read (RReg *reg, const char *regname) { +static ut32 i8051_reg_read (RzReg *reg, const char *regname) { if (reg) { - RRegItem *item = r_reg_get (reg, regname, R_REG_TYPE_GPR); + RzRegItem *item = rz_reg_get (reg, regname, R_REG_TYPE_GPR); if (item) { - return r_reg_get_value (reg, item); + return rz_reg_get_value (reg, item); } } return 0; } typedef struct { - RIODesc *desc; + RzIODesc *desc; ut32 addr; const char *name; } i8051_map_entry; @@ -80,8 +80,8 @@ static i8051_map_entry mem_map[3] = { { NULL, UT32_MAX, "xdata" } }; -static void map_cpu_memory (RAnal *anal, int entry, ut32 addr, ut32 size, bool force) { - RIODesc *desc = mem_map[entry].desc; +static void map_cpu_memory (RzAnal *anal, int entry, ut32 addr, ut32 size, bool force) { + RzIODesc *desc = mem_map[entry].desc; if (desc && anal->iob.fd_get_name (anal->iob.io, desc->fd)) { if (force || addr != mem_map[entry].addr) { // reallocate mapped memory if address changed @@ -89,27 +89,27 @@ static void map_cpu_memory (RAnal *anal, int entry, ut32 addr, ut32 size, bool f } } else { // allocate memory for address space - char *mstr = r_str_newf ("malloc://%d", size); + char *mstr = rz_str_newf ("malloc://%d", size); desc = anal->iob.open_at (anal->iob.io, mstr, R_PERM_RW, 0, addr); free (mstr); // set 8051 address space as name of mapped memory if (desc && anal->iob.fd_get_name (anal->iob.io, desc->fd)) { - RList *maps = anal->iob.fd_get_map (anal->iob.io, desc->fd); - RIOMap *current_map; - RListIter *iter; - r_list_foreach (maps, iter, current_map) { - char *cmdstr = r_str_newf ("omni %d %s", current_map->id, mem_map[entry].name); + RzList *maps = anal->iob.fd_get_map (anal->iob.io, desc->fd); + RzIOMap *current_map; + RzListIter *iter; + rz_list_foreach (maps, iter, current_map) { + char *cmdstr = rz_str_newf ("omni %d %s", current_map->id, mem_map[entry].name); anal->coreb.cmd (anal->coreb.core, cmdstr); free (cmdstr); } - r_list_free (maps); + rz_list_free (maps); } } mem_map[entry].desc = desc; mem_map[entry].addr = addr; } -static void set_cpu_model(RAnal *anal, bool force) { +static void set_cpu_model(RzAnal *anal, bool force) { ut32 addr_idata, addr_sfr, addr_xdata; if (!anal->reg) { @@ -122,10 +122,10 @@ static void set_cpu_model(RAnal *anal, bool force) { } // if cpu model changed, reinitialize emulation - if (force || !cpu_curr_model || r_str_casecmp (cpu, cpu_curr_model->name)) { + if (force || !cpu_curr_model || rz_str_casecmp (cpu, cpu_curr_model->name)) { // find model by name int i = 0; - while (cpu_models[i].name && r_str_casecmp (cpu, cpu_models[i].name)) { + while (cpu_models[i].name && rz_str_casecmp (cpu, cpu_models[i].name)) { i++; } if (!cpu_models[i].name) { @@ -213,8 +213,8 @@ static RI8051Reg registers[] = { }; #endif -#define e(frag) r_strbuf_append(&op->esil, frag) -#define ef(frag, ...) r_strbuf_appendf(&op->esil, frag, __VA_ARGS__) +#define e(frag) rz_strbuf_append(&op->esil, frag) +#define ef(frag, ...) rz_strbuf_appendf(&op->esil, frag, __VA_ARGS__) #define flag_c "7,$c,c,:=," #define flag_b "8,$b,c,:=," @@ -240,11 +240,11 @@ static RI8051Reg registers[] = { #define ev_sp2 0 #define ev_sp1 0 -static void exr_a(RAnalOp *op, ut8 dummy) { +static void exr_a(RzAnalOp *op, ut8 dummy) { e ("a,"); } -static void exr_dir1(RAnalOp *op, ut8 addr) { +static void exr_dir1(RzAnalOp *op, ut8 addr) { if (addr < 0x80) { ef ("_idata,%d,+,[1],", addr); } else { @@ -252,58 +252,58 @@ static void exr_dir1(RAnalOp *op, ut8 addr) { } } -static void exr_bit(RAnalOp *op, ut8 addr) { +static void exr_bit(RzAnalOp *op, ut8 addr) { exr_dir1 (op, addr); } -static void exr_dpx (RAnalOp *op, ut8 dummy) { +static void exr_dpx (RzAnalOp *op, ut8 dummy) { e ("_xdata,dptr,+,[1],"); } -static void exr_imm1(RAnalOp *op, ut8 val) { +static void exr_imm1(RzAnalOp *op, ut8 val) { ef ("%d,", val); } -static void exr_imm2(RAnalOp *op, ut8 val) { +static void exr_imm2(RzAnalOp *op, ut8 val) { ef ("%d,", val); } -static void exr_imm16(RAnalOp *op, ut16 val) { +static void exr_imm16(RzAnalOp *op, ut16 val) { ef ("%d,", val); } -static void exr_ri(RAnalOp *op, ut8 reg) { +static void exr_ri(RzAnalOp *op, ut8 reg) { ef ("_idata,r%d,+,[1],", reg); } -static void exr_rix(RAnalOp *op, ut8 reg) { +static void exr_rix(RzAnalOp *op, ut8 reg) { ef ("8,0xff,_pdata,&,<<,_xdata,+,r%d,+,[1],", reg); } -static void exr_rn(RAnalOp *op, ut8 reg) { +static void exr_rn(RzAnalOp *op, ut8 reg) { ef ("r%d,", reg); } -static void exr_sp1(RAnalOp *op, ut8 dummy) { +static void exr_sp1(RzAnalOp *op, ut8 dummy) { e ("_idata,sp,+,[1],"); e ("1,sp,-=,"); } -static void exr_sp2(RAnalOp *op, ut8 dummy) { +static void exr_sp2(RzAnalOp *op, ut8 dummy) { e ("1,sp,-=,"); e ("_idata,sp,+,[2],"); e ("1,sp,-=,"); } -static void exw_a(RAnalOp *op, ut8 dummy) { +static void exw_a(RzAnalOp *op, ut8 dummy) { e ("a,=,"); } -static void exw_c(RAnalOp *op, ut8 dummy) { +static void exw_c(RzAnalOp *op, ut8 dummy) { e ("c,=,"); } -static void exw_dir1(RAnalOp *op, ut8 addr) { +static void exw_dir1(RzAnalOp *op, ut8 addr) { if (addr < 0x80) { ef ("_idata,%d,+,=[1],", addr); } else { @@ -311,58 +311,58 @@ static void exw_dir1(RAnalOp *op, ut8 addr) { } } -static void exw_dir2(RAnalOp *op, ut8 addr) { +static void exw_dir2(RzAnalOp *op, ut8 addr) { exw_dir1 (op, addr); } -static void exw_bit(RAnalOp *op, ut8 addr) { +static void exw_bit(RzAnalOp *op, ut8 addr) { exw_dir1 (op, addr); } -static void exw_dp (RAnalOp *op, ut8 dummy) { +static void exw_dp (RzAnalOp *op, ut8 dummy) { e ("dptr,=,"); } -static void exw_dpx (RAnalOp *op, ut8 dummy) { +static void exw_dpx (RzAnalOp *op, ut8 dummy) { e ("_xdata,dptr,+,=[1],"); } -static void exw_ri(RAnalOp *op, ut8 reg) { +static void exw_ri(RzAnalOp *op, ut8 reg) { ef ("_idata,r%d,+,=[1],", reg); } -static void exw_rix(RAnalOp *op, ut8 reg) { +static void exw_rix(RzAnalOp *op, ut8 reg) { ef ("8,0xff,_pdata,&,<<,_xdata,+,r%d,+,=[1],", reg); } -static void exw_rn(RAnalOp *op, ut8 reg) { +static void exw_rn(RzAnalOp *op, ut8 reg) { ef ("r%d,=,", reg); } -static void exw_sp1(RAnalOp *op, ut8 dummy) { +static void exw_sp1(RzAnalOp *op, ut8 dummy) { e ("1,sp,+=,"); e ("_idata,sp,+,=[1],"); } -static void exw_sp2(RAnalOp *op, ut8 dummy) { +static void exw_sp2(RzAnalOp *op, ut8 dummy) { e ("1,sp,+=,"); e ("_idata,sp,+,=[2],"); e ("1,sp,+=,"); } -static void exi_a(RAnalOp *op, ut8 dummy, const char* operation) { +static void exi_a(RzAnalOp *op, ut8 dummy, const char* operation) { ef ("a,%s=,", operation); } -static void exi_c(RAnalOp *op, ut8 dummy, const char* operation) { +static void exi_c(RzAnalOp *op, ut8 dummy, const char* operation) { ef ("c,%s=,", operation); } -static void exi_dp (RAnalOp *op, ut8 dummy, const char *operation) { +static void exi_dp (RzAnalOp *op, ut8 dummy, const char *operation) { ef ("dptr,%s=,", operation); } -static void exi_dir1 (RAnalOp *op, ut8 addr, const char *operation) { +static void exi_dir1 (RzAnalOp *op, ut8 addr, const char *operation) { if (addr < 0x80) { ef ("_idata,%d,+,%s=[1],", addr, operation); } else { @@ -370,15 +370,15 @@ static void exi_dir1 (RAnalOp *op, ut8 addr, const char *operation) { } } -static void exi_bit (RAnalOp *op, ut8 addr, const char *operation) { +static void exi_bit (RzAnalOp *op, ut8 addr, const char *operation) { exi_dir1 (op, addr, operation); } -static void exi_ri(RAnalOp *op, ut8 reg, const char *operation) { +static void exi_ri(RzAnalOp *op, ut8 reg, const char *operation) { ef ("_idata,r%d,+,%s=[1],", reg, operation); } -static void exi_rn(RAnalOp *op, ut8 reg, const char *operation) { +static void exi_rn(RzAnalOp *op, ut8 reg, const char *operation) { ef ("r%d,%s=,", reg, operation); } @@ -433,9 +433,9 @@ static void exi_rn(RAnalOp *op, ut8 reg, const char *operation) { case base + 0xE: case base + 0xF: \ alu_op (rn, aluop, flags); break; -static void analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); +static void analop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf) { + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); switch (buf[0]) { // Irregulars sorted by lower nibble @@ -715,11 +715,11 @@ static void analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static RAnalEsilCallbacks ocbs = {0}; +static RzAnalEsilCallbacks ocbs = {0}; #if 0 // custom reg read/write temporarily disabled - see r2 issue #9242 -static int i8051_hook_reg_read(RAnalEsil *, const char *, ut64 *, int *); +static int i8051_hook_reg_read(RzAnalEsil *, const char *, ut64 *, int *); static int i8051_reg_compare(const void *name, const void *reg) { return strcmp ((const char*)name, ((RI8051Reg*)reg)->name); @@ -733,7 +733,7 @@ static RI8051Reg *i8051_reg_find(const char *name) { i8051_reg_compare); } -static int i8051_reg_get_offset(RAnalEsil *esil, RI8051Reg *ri) { +static int i8051_reg_get_offset(RzAnalEsil *esil, RI8051Reg *ri) { ut8 offset = ri->offset; if (ri->banked) { ut64 psw = 0LL; @@ -743,20 +743,20 @@ static int i8051_reg_get_offset(RAnalEsil *esil, RI8051Reg *ri) { return offset; } -// dkreuter: It would be nice if we could attach hooks to RRegItems directly. +// dkreuter: It would be nice if we could attach hooks to RzRegItems directly. // That way we could avoid doing a string lookup on register names -// as r_reg_get already does this. Also, the anal esil callbacks -// approach interferes with r_reg_arena_swap. +// as rz_reg_get already does this. Also, the anal esil callbacks +// approach interferes with rz_reg_arena_swap. -static int i8051_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int *size) { +static int i8051_hook_reg_read(RzAnalEsil *esil, const char *name, ut64 *res, int *size) { int ret = 0; ut64 val = 0LL; RI8051Reg *ri; - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; if ((ri = i8051_reg_find (name))) { ut8 offset = i8051_reg_get_offset(esil, ri); - ret = r_anal_esil_mem_read (esil, IRAM_BASE + offset, (ut8*)res, ri->num_bytes); + ret = rz_anal_esil_mem_read (esil, IRAM_BASE + offset, (ut8*)res, ri->num_bytes); } esil->cb = ocbs; if (!ret && ocbs.hook_reg_read) { @@ -770,13 +770,13 @@ static int i8051_hook_reg_read(RAnalEsil *esil, const char *name, ut64 *res, int return ret; } -static int i8051_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { +static int i8051_hook_reg_write(RzAnalEsil *esil, const char *name, ut64 *val) { int ret = 0; RI8051Reg *ri; - RAnalEsilCallbacks cbs = esil->cb; + RzAnalEsilCallbacks cbs = esil->cb; if ((ri = i8051_reg_find (name))) { ut8 offset = i8051_reg_get_offset(esil, ri); - ret = r_anal_esil_mem_write (esil, IRAM_BASE + offset, (ut8*)val, ri->num_bytes); + ret = rz_anal_esil_mem_write (esil, IRAM_BASE + offset, (ut8*)val, ri->num_bytes); } esil->cb = ocbs; if (!ret && ocbs.hook_reg_write) { @@ -787,7 +787,7 @@ static int i8051_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { } #endif -static int esil_i8051_init (RAnalEsil *esil) { +static int esil_i8051_init (RzAnalEsil *esil) { if (esil->cb.user) { return true; } @@ -802,7 +802,7 @@ static int esil_i8051_init (RAnalEsil *esil) { return true; } -static int esil_i8051_fini (RAnalEsil *esil) { +static int esil_i8051_fini (RzAnalEsil *esil) { if (!i8051_is_init) { return false; } @@ -811,7 +811,7 @@ static int esil_i8051_fini (RAnalEsil *esil) { return true; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP sp\n" @@ -861,7 +861,7 @@ static bool set_reg_profile(RAnal *anal) { "gpr _xdata .32 32 0\n" "gpr _pdata .32 36 0\n"; - int retval = r_reg_set_profile_string (anal->reg, p); + int retval = rz_reg_set_profile_string (anal->reg, p); if (retval) { // reset emulation control registers based on cpu set_cpu_model (anal, true); @@ -870,7 +870,7 @@ static bool set_reg_profile(RAnal *anal) { return retval; } -static ut32 map_direct_addr(RAnal *anal, ut8 addr) { +static ut32 map_direct_addr(RzAnal *anal, ut8 addr) { if (addr < 0x80) { return addr + i8051_reg_read (anal->reg, "_idata"); } else { @@ -878,7 +878,7 @@ static ut32 map_direct_addr(RAnal *anal, ut8 addr) { } } -static int i8051_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int i8051_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { set_cpu_model (anal, false); int i = 0; @@ -1021,7 +1021,7 @@ static int i8051_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len } int olen = 0; - op->mnemonic = r_8051_disas (addr, buf, len, &olen); + op->mnemonic = rz_8051_disas (addr, buf, len, &olen); op->size = olen; if (mask & R_ANAL_OP_MASK_HINT) { @@ -1031,7 +1031,7 @@ static int i8051_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len return op->size; } -RAnalPlugin r_anal_plugin_8051 = { +RzAnalPlugin rz_anal_plugin_8051 = { .name = "8051", .arch = "8051", .esil = true, @@ -1045,9 +1045,9 @@ RAnalPlugin r_anal_plugin_8051 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_8051, + .data = &rz_anal_plugin_8051, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_amd29k.c b/librz/anal/p/anal_amd29k.c similarity index 95% rename from libr/anal/p/anal_amd29k.c rename to librz/anal/p/anal_amd29k.c index 7fc43983db..771b8afdc8 100644 --- a/libr/anal/p/anal_amd29k.c +++ b/librz/anal/p/anal_amd29k.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2013-2020 - pancake */ +/* rizin - LGPL - Copyright 2013-2020 - pancake */ -#include -#include +#include +#include #include "../../asm/arch/amd29k/amd29k.h" -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP gp1\n" @@ -275,14 +275,14 @@ static bool set_reg_profile(RAnal *anal) { "gpr lr126 .32 2024 0\n" "gpr lr127 .32 2032 0\n" "gpr lr128 .32 2040 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *a, int q) { +static int archinfo(RzAnal *a, int q) { return 4; } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { op->size = 4; op->eob = false; @@ -321,7 +321,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -RAnalPlugin r_anal_plugin_amd29k = { +RzAnalPlugin rz_anal_plugin_amd29k = { .name = "amd29k", .desc = "AMD 29k analysis", .license = "BSD", @@ -334,9 +334,9 @@ RAnalPlugin r_anal_plugin_amd29k = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_amd29k, + .data = &rz_anal_plugin_amd29k, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_arc.c b/librz/anal/p/anal_arc.c similarity index 96% rename from libr/anal/p/anal_arc.c rename to librz/anal/p/anal_arc.c index 4ee78a3a8c..683ec63d88 100644 --- a/libr/anal/p/anal_arc.c +++ b/librz/anal/p/anal_arc.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2012-2016 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include #define ARC_REG_ILINK1 0x1d #define ARC_REG_ILINK2 0x1e @@ -41,7 +41,7 @@ static void arccompact_dump_fields(ut64 addr, ut32 words[2], arc_fields *f) { /* For (arguably valid) reasons, the ARCompact CPU uses "middle endian" encoding on Little-Endian systems */ -static inline ut32 r_read_me32_arc(const void *src) { +static inline ut32 rz_read_me32_arc(const void *src) { const ut8 *s = src; return (((ut32)s[1]) << 24) | (((ut32)s[0]) << 16) | (((ut32)s[3]) << 8) | (((ut32)s[2]) << 0); } @@ -95,22 +95,22 @@ static int map_cond2radare(ut8 cond) { return -1; } -static void arcompact_jump(RAnalOp *op, ut64 addr, ut64 jump, ut8 delay) { +static void arcompact_jump(RzAnalOp *op, ut64 addr, ut64 jump, ut8 delay) { op->jump = jump; op->fail = addr + op->size; op->delay = delay; } -static void arcompact_jump_cond(RAnalOp *op, ut64 addr, ut64 jump, ut8 delay, ut8 cond) { +static void arcompact_jump_cond(RzAnalOp *op, ut64 addr, ut64 jump, ut8 delay, ut8 cond) { arcompact_jump (op, addr, jump, delay); op->cond = map_cond2radare (cond); } -static void arcompact_branch(RAnalOp *op, ut64 addr, st64 offset, ut8 delay) { +static void arcompact_branch(RzAnalOp *op, ut64 addr, st64 offset, ut8 delay) { arcompact_jump (op, addr, (addr & ~3) + offset, delay); } -static void map_zz2refptr(RAnalOp *op, ut8 mode_zz) { +static void map_zz2refptr(RzAnalOp *op, ut8 mode_zz) { switch (mode_zz) { case 0: op->refptr = 4; break; case 1: op->refptr = 1; break; @@ -121,7 +121,7 @@ static void map_zz2refptr(RAnalOp *op, ut8 mode_zz) { } } -static int arcompact_genops_jmp(RAnalOp *op, ut64 addr, arc_fields *f, ut64 basic_type) { +static int arcompact_genops_jmp(RzAnalOp *op, ut64 addr, arc_fields *f, ut64 basic_type) { ut64 type_ujmp; ut64 type_cjmp; ut64 type_ucjmp; @@ -200,7 +200,7 @@ static int arcompact_genops_jmp(RAnalOp *op, ut64 addr, arc_fields *f, ut64 basi return 0; } -static int arcompact_genops(RAnalOp *op, ut64 addr, ut32 words[2]) { +static int arcompact_genops(RzAnalOp *op, ut64 addr, ut32 words[2]) { arc_fields fields = {0}; fields.format = (words[0] & 0x00c00000) >> 22; @@ -445,7 +445,7 @@ static int arcompact_genops(RAnalOp *op, ut64 addr, ut32 words[2]) { return op->size; } -static int arcompact_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { +static int arcompact_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len) { ut32 words[2]; /* storage for the de-swizled opcode data */ arc_fields fields; @@ -459,7 +459,7 @@ static int arcompact_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, in return 0; } if (len < 8) { - //when r_read_me32_arc/be32 oob read + //when rz_read_me32_arc/be32 oob read return 0; } @@ -472,11 +472,11 @@ static int arcompact_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, in op->delay = 0; if (anal->big_endian) { - words[0] = r_read_be32 (&data[0]); - words[1] = r_read_be32 (&data[4]); + words[0] = rz_read_be32 (&data[0]); + words[1] = rz_read_be32 (&data[4]); } else { - words[0] = r_read_me32_arc (&data[0]); - words[1] = r_read_me32_arc (&data[4]); + words[0] = rz_read_me32_arc (&data[0]); + words[1] = rz_read_me32_arc (&data[4]); } fields.opcode = (words[0] & 0xf8000000) >> 27; @@ -1013,7 +1013,7 @@ static int arcompact_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, in return op->size; } -static int arc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int arc_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { const ut8 *b = (ut8 *)data; if (anal->bits == 16) { @@ -1029,7 +1029,7 @@ static int arc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, case 0x05: /* Branch with Link */ case 0x06: /* Loop */ op->type = R_ANAL_OP_TYPE_CJMP; - op->jump = addr + 4 + ((r_read_le32 (&data[0]) & 0x07ffff80) >> (7 - 2)); + op->jump = addr + 4 + ((rz_read_le32 (&data[0]) & 0x07ffff80) >> (7 - 2)); break; case 0x07: /* Conditional Jump and Jump with Link */ op->type = R_ANAL_OP_TYPE_CJMP; @@ -1065,7 +1065,7 @@ static int arc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, return op->size; } -static int archinfo(RAnal *anal, int query) { +static int archinfo(RzAnal *anal, int query) { if (anal->bits != 16) { return -1; } @@ -1082,7 +1082,7 @@ static int archinfo(RAnal *anal, int query) { } } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { if (anal->bits != 16) { return false; } @@ -1134,10 +1134,10 @@ static bool set_reg_profile(RAnal *anal) { /* TODO: */ /* Should I add the Auxiliary Register Set? */ /* it contains the flag bits, amongst other things */ - return r_reg_set_profile_string (anal->reg, p16); + return rz_reg_set_profile_string (anal->reg, p16); } -RAnalPlugin r_anal_plugin_arc = { +RzAnalPlugin rz_anal_plugin_arc = { .name = "arc", .arch = "arc", .license = "LGPL3", @@ -1149,9 +1149,9 @@ RAnalPlugin r_anal_plugin_arc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_arc, + .data = &rz_anal_plugin_arc, .version = R2_VERSION, }; #endif diff --git a/libr/anal/p/anal_arm_cs.c b/librz/anal/p/anal_arm_cs.c similarity index 74% rename from libr/anal/p/anal_arm_cs.c rename to librz/anal/p/anal_arm_cs.c index d93df3ded8..21a4b0c3ca 100644 --- a/libr/anal/p/anal_arm_cs.c +++ b/librz/anal/p/anal_arm_cs.c @@ -1,36 +1,36 @@ -/* radare2 - LGPL - Copyright 2013-2020 - pancake */ +/* rizin - LGPL - Copyright 2013-2020 - pancake */ -#include -#include +#include +#include #include #include #include #include -#include +#include #include "./anal_arm_hacks.inc" -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) /* arm64 */ #define IMM64(x) (ut64)(insn->detail->arm64.operands[x].imm) #define INSOP64(x) insn->detail->arm64.operands[x] /* arm32 */ -#define REG(x) r_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].reg)) -#define REG64(x) r_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].reg)) +#define REG(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].reg)) +#define REG64(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].reg)) #define REGID64(x) insn->detail->arm64.operands[x].reg #define REGID(x) insn->detail->arm.operands[x].reg #define IMM(x) (ut32)(insn->detail->arm.operands[x].imm) #define INSOP(x) insn->detail->arm.operands[x] -#define MEMBASE(x) r_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].mem.base)) -#define MEMBASE64(x) r_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].mem.base)) +#define MEMBASE(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].mem.base)) +#define MEMBASE64(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].mem.base)) #define REGBASE(x) insn->detail->arm.operands[x].mem.base #define REGBASE64(x) insn->detail->arm64.operands[x].mem.base // s/index/base|reg/ -#define MEMINDEX(x) r_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].mem.index)) +#define MEMINDEX(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm.operands[x].mem.index)) #define HASMEMINDEX(x) (insn->detail->arm.operands[x].mem.index != ARM_REG_INVALID) -#define MEMINDEX64(x) r_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].mem.index)) +#define MEMINDEX64(x) rz_str_get (cs_reg_name (*handle, insn->detail->arm64.operands[x].mem.index)) #define HASMEMINDEX64(x) (insn->detail->arm64.operands[x].mem.index != ARM64_REG_INVALID) #define MEMDISP(x) insn->detail->arm.operands[x].mem.disp #define MEMDISP64(x) (ut64)insn->detail->arm64.operands[x].mem.disp @@ -63,8 +63,8 @@ #define ISPREINDEX64() ((OPCOUNT64() == 3) && (ISMEM64(2)) && (ISWRITEBACK64())) #define ISPOSTINDEX64() ((OPCOUNT64() == 4) && (ISIMM64(3)) && (ISWRITEBACK64())) -static RRegItem base_regs[4]; -static RRegItem regdelta_regs[4]; +static RzRegItem base_regs[4]; +static RzRegItem regdelta_regs[4]; static HtUU *ht_itblock = NULL; static HtUU *ht_it = NULL; @@ -227,131 +227,131 @@ static const char *cc_name(arm_cc cc) { static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_arm *x = &insn->detail->arm; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_arm_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case ARM_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case ARM_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); break; case ARM_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != ARM_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } if (op->mem.index != ARM_REG_INVALID) { - r_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); + rz_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); } - r_strbuf_appendf (buf, ",\"scale\":%d", op->mem.scale); - r_strbuf_appendf (buf, ",\"disp\":%d", op->mem.disp); + rz_strbuf_appendf (buf, ",\"scale\":%d", op->mem.scale); + rz_strbuf_appendf (buf, ",\"disp\":%d", op->mem.disp); break; case ARM_OP_FP: - r_strbuf_append (buf, "\"type\":\"fp\""); - r_strbuf_appendf (buf, ",\"value\":%lf", op->fp); + rz_strbuf_append (buf, "\"type\":\"fp\""); + rz_strbuf_appendf (buf, ",\"value\":%lf", op->fp); break; case ARM_OP_CIMM: - r_strbuf_append (buf, "\"type\":\"cimm\""); - r_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); + rz_strbuf_append (buf, "\"type\":\"cimm\""); + rz_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); break; case ARM_OP_PIMM: - r_strbuf_append (buf, "\"type\":\"pimm\""); - r_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); + rz_strbuf_append (buf, "\"type\":\"pimm\""); + rz_strbuf_appendf (buf, ",\"value\":%d", (st32)op->imm); break; case ARM_OP_SETEND: - r_strbuf_append (buf, "\"type\":\"setend\""); + rz_strbuf_append (buf, "\"type\":\"setend\""); switch (op->setend) { case ARM_SETEND_BE: - r_strbuf_append (buf, ",\"value\":\"be\""); + rz_strbuf_append (buf, ",\"value\":\"be\""); break; case ARM_SETEND_LE: - r_strbuf_append (buf, ",\"value\":\"le\""); + rz_strbuf_append (buf, ",\"value\":\"le\""); break; default: - r_strbuf_append (buf, ",\"value\":\"invalid\""); + rz_strbuf_append (buf, ",\"value\":\"invalid\""); break; } break; case ARM_OP_SYSREG: - r_strbuf_append (buf, "\"type\":\"sysreg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"sysreg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; default: - r_strbuf_append (buf, ",\"type\":\"invalid\""); + rz_strbuf_append (buf, ",\"type\":\"invalid\""); break; } if (op->shift.type != ARM_SFT_INVALID) { - r_strbuf_append (buf, ",\"shift\":{"); + rz_strbuf_append (buf, ",\"shift\":{"); switch (op->shift.type) { case ARM_SFT_ASR: case ARM_SFT_LSL: case ARM_SFT_LSR: case ARM_SFT_ROR: case ARM_SFT_RRX: - r_strbuf_appendf (buf, "\"type\":\"%s\"", shift_type_name (op->shift.type)); - r_strbuf_appendf (buf, ",\"value\":\"%u\"", op->shift.value); + rz_strbuf_appendf (buf, "\"type\":\"%s\"", shift_type_name (op->shift.type)); + rz_strbuf_appendf (buf, ",\"value\":\"%u\"", op->shift.value); break; case ARM_SFT_ASR_REG: case ARM_SFT_LSL_REG: case ARM_SFT_LSR_REG: case ARM_SFT_ROR_REG: case ARM_SFT_RRX_REG: - r_strbuf_appendf (buf, "\"type\":\"%s\"", shift_type_name (op->shift.type)); - r_strbuf_appendf (buf, ",\"value\":\"%d\"", cs_reg_name (handle, op->shift.value)); + rz_strbuf_appendf (buf, "\"type\":\"%s\"", shift_type_name (op->shift.type)); + rz_strbuf_appendf (buf, ",\"value\":\"%d\"", cs_reg_name (handle, op->shift.value)); break; default: break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } if (op->vector_index != -1) { - r_strbuf_appendf (buf, ",\"vector_index\":\"%d\"", op->vector_index); + rz_strbuf_appendf (buf, ",\"vector_index\":\"%d\"", op->vector_index); } if (op->subtracted) { - r_strbuf_append (buf, ",\"subtracted\":true"); + rz_strbuf_append (buf, ",\"subtracted\":true"); } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "]"); if (x->usermode) { - r_strbuf_append (buf, ",\"usermode\":true"); + rz_strbuf_append (buf, ",\"usermode\":true"); } if (x->update_flags) { - r_strbuf_append (buf, ",\"update_flags\":true"); + rz_strbuf_append (buf, ",\"update_flags\":true"); } if (x->writeback) { - r_strbuf_append (buf, ",\"writeback\":true"); + rz_strbuf_append (buf, ",\"writeback\":true"); } if (x->vector_size) { - r_strbuf_appendf (buf, ",\"vector_size\":%d", x->vector_size); + rz_strbuf_appendf (buf, ",\"vector_size\":%d", x->vector_size); } if (x->vector_data != ARM_VECTORDATA_INVALID) { - r_strbuf_appendf (buf, ",\"vector_data\":\"%s\"", vector_data_type_name (x->vector_data)); + rz_strbuf_appendf (buf, ",\"vector_data\":\"%s\"", vector_data_type_name (x->vector_data)); } if (x->cps_mode != ARM_CPSMODE_INVALID) { - r_strbuf_appendf (buf, ",\"cps_mode\":%d", x->cps_mode); + rz_strbuf_appendf (buf, ",\"cps_mode\":%d", x->cps_mode); } if (x->cps_flag != ARM_CPSFLAG_INVALID) { - r_strbuf_appendf (buf, ",\"cps_flag\":%d", x->cps_flag); + rz_strbuf_appendf (buf, ",\"cps_flag\":%d", x->cps_flag); } if (x->cc != ARM_CC_INVALID && x->cc != ARM_CC_AL) { - r_strbuf_appendf (buf, ",\"cc\":\"%s\"", cc_name (x->cc)); + rz_strbuf_appendf (buf, ",\"cc\":\"%s\"", cc_name (x->cc)); } if (x->mem_barrier != ARM_MB_INVALID) { - r_strbuf_appendf (buf, ",\"mem_barrier\":%d", x->mem_barrier - 1); + rz_strbuf_appendf (buf, ",\"mem_barrier\":%d", x->mem_barrier - 1); } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } static int arm64_reg_width(int reg) { @@ -509,134 +509,134 @@ static const char *vess_name(arm64_vess vess) { static void opex64(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_arm64 *x = &insn->detail->arm64; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_arm64_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case ARM64_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case ARM64_OP_REG_MRS: - r_strbuf_append (buf, "\"type\":\"reg_mrs\""); + rz_strbuf_append (buf, "\"type\":\"reg_mrs\""); // TODO value break; case ARM64_OP_REG_MSR: - r_strbuf_append (buf, "\"type\":\"reg_msr\""); + rz_strbuf_append (buf, "\"type\":\"reg_msr\""); // TODO value break; case ARM64_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case ARM64_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != ARM64_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } if (op->mem.index != ARM64_REG_INVALID) { - r_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); + rz_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); } - r_strbuf_appendf (buf, ",\"disp\":%d", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%d", op->mem.disp); break; case ARM64_OP_FP: - r_strbuf_append (buf, "\"type\":\"fp\""); - r_strbuf_appendf (buf, ",\"value\":%lf", op->fp); + rz_strbuf_append (buf, "\"type\":\"fp\""); + rz_strbuf_appendf (buf, ",\"value\":%lf", op->fp); break; case ARM64_OP_CIMM: - r_strbuf_append (buf, "\"type\":\"cimm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"cimm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case ARM64_OP_PSTATE: - r_strbuf_append (buf, "\"type\":\"pstate\""); + rz_strbuf_append (buf, "\"type\":\"pstate\""); switch (op->pstate) { case ARM64_PSTATE_SPSEL: - r_strbuf_append (buf, ",\"value\":\"spsel\""); + rz_strbuf_append (buf, ",\"value\":\"spsel\""); break; case ARM64_PSTATE_DAIFSET: - r_strbuf_append (buf, ",\"value\":\"daifset\""); + rz_strbuf_append (buf, ",\"value\":\"daifset\""); break; case ARM64_PSTATE_DAIFCLR: - r_strbuf_append (buf, ",\"value\":\"daifclr\""); + rz_strbuf_append (buf, ",\"value\":\"daifclr\""); break; default: - r_strbuf_appendf (buf, ",\"value\":%d", op->pstate); + rz_strbuf_appendf (buf, ",\"value\":%d", op->pstate); } break; case ARM64_OP_SYS: - r_strbuf_append (buf, "\"type\":\"sys\""); - r_strbuf_appendf (buf, ",\"value\":%u", op->sys); + rz_strbuf_append (buf, "\"type\":\"sys\""); + rz_strbuf_appendf (buf, ",\"value\":%u", op->sys); break; case ARM64_OP_PREFETCH: - r_strbuf_append (buf, "\"type\":\"prefetch\""); - r_strbuf_appendf (buf, ",\"value\":%d", op->prefetch - 1); + rz_strbuf_append (buf, "\"type\":\"prefetch\""); + rz_strbuf_appendf (buf, ",\"value\":%d", op->prefetch - 1); break; case ARM64_OP_BARRIER: - r_strbuf_append (buf, "\"type\":\"prefetch\""); - r_strbuf_appendf (buf, ",\"value\":%d", op->barrier - 1); + rz_strbuf_append (buf, "\"type\":\"prefetch\""); + rz_strbuf_appendf (buf, ",\"value\":%d", op->barrier - 1); break; default: - r_strbuf_append (buf, ",\"type\":\"invalid\""); + rz_strbuf_append (buf, ",\"type\":\"invalid\""); break; } if (op->shift.type != ARM64_SFT_INVALID) { - r_strbuf_append (buf, ",\"shift\":{"); + rz_strbuf_append (buf, ",\"shift\":{"); switch (op->shift.type) { case ARM64_SFT_LSL: - r_strbuf_append (buf, "\"type\":\"lsl\""); + rz_strbuf_append (buf, "\"type\":\"lsl\""); break; case ARM64_SFT_MSL: - r_strbuf_append (buf, "\"type\":\"msl\""); + rz_strbuf_append (buf, "\"type\":\"msl\""); break; case ARM64_SFT_LSR: - r_strbuf_append (buf, "\"type\":\"lsr\""); + rz_strbuf_append (buf, "\"type\":\"lsr\""); break; case ARM64_SFT_ASR: - r_strbuf_append (buf, "\"type\":\"asr\""); + rz_strbuf_append (buf, "\"type\":\"asr\""); break; case ARM64_SFT_ROR: - r_strbuf_append (buf, "\"type\":\"ror\""); + rz_strbuf_append (buf, "\"type\":\"ror\""); break; default: break; } - r_strbuf_appendf (buf, ",\"value\":\"%u\"", op->shift.value); - r_strbuf_append (buf, "}"); + rz_strbuf_appendf (buf, ",\"value\":\"%u\"", op->shift.value); + rz_strbuf_append (buf, "}"); } if (op->ext != ARM64_EXT_INVALID) { - r_strbuf_appendf (buf, ",\"ext\":\"%s\"", extender_name (op->ext)); + rz_strbuf_appendf (buf, ",\"ext\":\"%s\"", extender_name (op->ext)); } if (op->vector_index != -1) { - r_strbuf_appendf (buf, ",\"vector_index\":\"%d\"", op->vector_index); + rz_strbuf_appendf (buf, ",\"vector_index\":\"%d\"", op->vector_index); } if (op->vas != ARM64_VAS_INVALID) { - r_strbuf_appendf (buf, ",\"vas\":\"%s\"", vas_name (op->vas)); + rz_strbuf_appendf (buf, ",\"vas\":\"%s\"", vas_name (op->vas)); } #if CS_API_MAJOR == 4 if (op->vess != ARM64_VESS_INVALID) { - r_strbuf_appendf (buf, ",\"vess\":\"%s\"", vess_name (op->vess)); + rz_strbuf_appendf (buf, ",\"vess\":\"%s\"", vess_name (op->vess)); } #endif - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "]"); if (x->update_flags) { - r_strbuf_append (buf, ",\"update_flags\":true"); + rz_strbuf_append (buf, ",\"update_flags\":true"); } if (x->writeback) { - r_strbuf_append (buf, ",\"writeback\":true"); + rz_strbuf_append (buf, ",\"writeback\":true"); } if (x->cc != ARM64_CC_INVALID && x->cc != ARM64_CC_AL && x->cc != ARM64_CC_NV) { - r_strbuf_appendf (buf, ",\"cc\":\"%s\"", cc_name64 (x->cc)); + rz_strbuf_appendf (buf, ",\"cc\":\"%s\"", cc_name64 (x->cc)); } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } static int decode_sign_ext(arm64_extender extender) { @@ -721,7 +721,7 @@ static const char *decode_shift_64(arm64_shifter shift) { #define DECODE_SHIFT64(x) decode_shift_64(insn->detail->arm64.operands[x].shift.type) static unsigned int regsize32(cs_insn *insn, int n) { - r_return_val_if_fail(n >= 0 && n < insn->detail->arm.op_count, 0); + rz_return_val_if_fail(n >= 0 && n < insn->detail->arm.op_count, 0); unsigned int reg = insn->detail->arm.operands[n].reg; if (reg >= ARM_REG_D0 && reg <= ARM_REG_D31) { return 8; @@ -755,7 +755,7 @@ static int regsize64(cs_insn *insn, int n) { #define REGSIZE32(x) regsize32 (insn, x) // return postfix -const char* arm_prefix_cond(RAnalOp *op, int cond_type) { +const char* arm_prefix_cond(RzAnalOp *op, int cond_type) { const char *close_cond[2]; close_cond[0] = "\0"; close_cond[1] = ",}\0"; @@ -763,61 +763,61 @@ const char* arm_prefix_cond(RAnalOp *op, int cond_type) { switch (cond_type) { case ARM_CC_EQ: close_type = 1; - r_strbuf_setf (&op->esil, "zf,?{,"); + rz_strbuf_setf (&op->esil, "zf,?{,"); break; case ARM_CC_NE: close_type = 1; - r_strbuf_setf (&op->esil, "zf,!,?{,"); + rz_strbuf_setf (&op->esil, "zf,!,?{,"); break; case ARM_CC_HS: close_type = 1; - r_strbuf_setf (&op->esil, "cf,?{,"); + rz_strbuf_setf (&op->esil, "cf,?{,"); break; case ARM_CC_LO: close_type = 1; - r_strbuf_setf (&op->esil, "cf,!,?{,"); + rz_strbuf_setf (&op->esil, "cf,!,?{,"); break; case ARM_CC_MI: close_type = 1; - r_strbuf_setf (&op->esil, "nf,?{,"); + rz_strbuf_setf (&op->esil, "nf,?{,"); break; case ARM_CC_PL: close_type = 1; - r_strbuf_setf (&op->esil, "nf,!,?{,"); + rz_strbuf_setf (&op->esil, "nf,!,?{,"); break; case ARM_CC_VS: close_type = 1; - r_strbuf_setf (&op->esil, "vf,?{,"); + rz_strbuf_setf (&op->esil, "vf,?{,"); break; case ARM_CC_VC: close_type = 1; - r_strbuf_setf (&op->esil, "vf,!,?{,"); + rz_strbuf_setf (&op->esil, "vf,!,?{,"); break; case ARM_CC_HI: close_type = 1; - r_strbuf_setf (&op->esil, "cf,zf,!,&,?{,"); + rz_strbuf_setf (&op->esil, "cf,zf,!,&,?{,"); break; case ARM_CC_LS: close_type = 1; - r_strbuf_setf (&op->esil, "cf,!,zf,|,?{,"); + rz_strbuf_setf (&op->esil, "cf,!,zf,|,?{,"); break; case ARM_CC_GE: close_type = 1; - r_strbuf_setf (&op->esil, "nf,vf,^,!,?{,"); + rz_strbuf_setf (&op->esil, "nf,vf,^,!,?{,"); break; case ARM_CC_LT: close_type = 1; - r_strbuf_setf (&op->esil, "nf,vf,^,?{,"); + rz_strbuf_setf (&op->esil, "nf,vf,^,?{,"); break; case ARM_CC_GT: // zf == 0 && nf == vf close_type = 1; - r_strbuf_setf (&op->esil, "zf,!,nf,vf,^,!,&,?{,"); + rz_strbuf_setf (&op->esil, "zf,!,nf,vf,^,!,&,?{,"); break; case ARM_CC_LE: // zf == 1 || nf != vf close_type = 1; - r_strbuf_setf (&op->esil, "zf,nf,vf,^,|,?{,"); + rz_strbuf_setf (&op->esil, "zf,nf,vf,^,|,?{,"); break; case ARM_CC_AL: // always executed @@ -830,19 +830,19 @@ const char* arm_prefix_cond(RAnalOp *op, int cond_type) { /* arm64 */ -static const char *arg(RAnal *a, csh *handle, cs_insn *insn, char *buf, int n) { +static const char *arg(RzAnal *a, csh *handle, cs_insn *insn, char *buf, int n) { buf[0] = 0; switch (insn->detail->arm.operands[n].type) { case ARM_OP_REG: if (ISSHIFTED (n)) { sprintf (buf, "%u,%s,%s", LSHIFT2 (n), - r_str_get (cs_reg_name (*handle, + rz_str_get (cs_reg_name (*handle, insn->detail->arm.operands[n].reg)), DECODE_SHIFT (n)); } else { sprintf (buf, "%s", - r_str_get (cs_reg_name (*handle, + rz_str_get (cs_reg_name (*handle, insn->detail->arm.operands[n].reg))); } break; @@ -887,10 +887,10 @@ static void shifted_reg64_append(RStrBuf *sb, csh *handle, cs_insn *insn, int n) if (LSHIFT2_64(n)) { if (insn->detail->arm64.operands[n].shift.type != ARM64_SFT_ASR) { if (signext) { - r_strbuf_appendf (sb, "%d,%d,%s,~,%s", LSHIFT2_64(n), signext, rn, DECODE_SHIFT64(n)); + rz_strbuf_appendf (sb, "%d,%d,%s,~,%s", LSHIFT2_64(n), signext, rn, DECODE_SHIFT64(n)); } else { - r_strbuf_appendf (sb, "%d,%s,%s", LSHIFT2_64(n), rn, DECODE_SHIFT64(n)); + rz_strbuf_appendf (sb, "%d,%s,%s", LSHIFT2_64(n), rn, DECODE_SHIFT64(n)); } } else { /* ASR: add the missing ones if negative */ @@ -900,20 +900,20 @@ static void shifted_reg64_append(RStrBuf *sb, csh *handle, cs_insn *insn, int n) } ut64 missing_ones = bitmask_by_width[index] << (REGSIZE64(n)*8 - LSHIFT2_64(n)); if (signext) { - r_strbuf_appendf (sb, "%d,%d,%s,~,%s,1,%d,%s,~,<<<,1,&,?{,%"PFMT64u",}{,0,},|", + rz_strbuf_appendf (sb, "%d,%d,%s,~,%s,1,%d,%s,~,<<<,1,&,?{,%"PFMT64u",}{,0,},|", LSHIFT2_64(n), signext, rn, DECODE_SHIFT64(n), signext, REG64(n), (ut64)missing_ones); } else { - r_strbuf_appendf (sb, "%d,%s,%s,1,%s,<<<,1,&,?{,%"PFMT64u",}{,0,},|", + rz_strbuf_appendf (sb, "%d,%s,%s,1,%s,<<<,1,&,?{,%"PFMT64u",}{,0,},|", LSHIFT2_64(n), rn, DECODE_SHIFT64(n), rn, (ut64)missing_ones); } } } else if (signext) { - r_strbuf_appendf (sb, "%d,%s,~", signext, rn); + rz_strbuf_appendf (sb, "%d,%s,~", signext, rn); } else { - r_strbuf_appendf (sb, "%s", rn); + rz_strbuf_appendf (sb, "%s", rn); } } @@ -922,7 +922,7 @@ static void shifted_reg64_append(RStrBuf *sb, csh *handle, cs_insn *insn, int n) // got rid of the opchar= pattern here because it caused missing operators to fail silently // and makes things more complicated with very little benefit -static void arm64math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, const char *opchar, int negate) { +static void arm64math(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, const char *opchar, int negate) { const char *r0 = REG64(0); const char *r1 = REG64(1); @@ -930,34 +930,34 @@ static void arm64math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, if (LSHIFT2_64 (2) || EXT64(2)) { SHIFTED_REG64_APPEND(&op->esil, 2); if (negate) { - r_strbuf_appendf (&op->esil, ",-1,^"); + rz_strbuf_appendf (&op->esil, ",-1,^"); } - r_strbuf_appendf (&op->esil, ",%s,%s,%s,=", r1, opchar, r0); + rz_strbuf_appendf (&op->esil, ",%s,%s,%s,=", r1, opchar, r0); } else { const char *r2 = REG64(2); if (negate) { - r_strbuf_setf (&op->esil, "%s,-1,^,%s,%s,%s,=", r2, r1, opchar, r0); + rz_strbuf_setf (&op->esil, "%s,-1,^,%s,%s,%s,=", r2, r1, opchar, r0); } else { - r_strbuf_setf (&op->esil, "%s,%s,%s,%s,=", r2, r1, opchar, r0); + rz_strbuf_setf (&op->esil, "%s,%s,%s,%s,=", r2, r1, opchar, r0); } } } else { ut64 i2 = IMM64(2) << LSHIFT2_64 (2); if (negate) { - r_strbuf_setf (&op->esil, "%"PFMT64d",-1,^,%s,%s,%s,=", i2, r1, opchar, r0); + rz_strbuf_setf (&op->esil, "%"PFMT64d",-1,^,%s,%s,%s,=", i2, r1, opchar, r0); } else { - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,%s,%s,=", i2, r1, opchar, r0); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,%s,%s,=", i2, r1, opchar, r0); } } } -static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { +static int analop64_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { const char *postfix = NULL; - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); postfix = arm_prefix_cond (op, insn->detail->arm64.cc); @@ -970,7 +970,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l const char *r1 = REG64(1); int size = REGSIZE64(1); #if 0 - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "0,%s,=," // dst = 0 "%d," // initial counter = size "DUP," // counter: size -> 0 (repeat here) @@ -982,7 +982,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l r0, size, r1, size, r0); #endif if (size == 8) { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "56,0xff,%s,&,<<,tmp,=," "48,0xff,8,%s,>>,&,<<,tmp,|=," "40,0xff,16,%s,>>,&,<<,tmp,|=," @@ -994,7 +994,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l r1, r1, r1, r1, r1, r1, r1, r1, r0); } else { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "24,0xff,%s,&,<<,tmp,=," "16,0xff,8,%s,>>,&,<<,tmp,|=," "8,0xff,16,%s,>>,&,<<,tmp,|=," @@ -1007,7 +1007,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l { const char *r0 = REG64(0); const char *r1 = REG64(1); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "24,0x000000ff000000ff,%s,&,<<,tmp,=," "16,0x000000ff000000ff,8,%s,>>,&,<<,tmp,|=," "8,0x000000ff000000ff,16,%s,>>,&,<<,tmp,|=," @@ -1019,7 +1019,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l { const char *r0 = REG64(0); const char *r1 = REG64(1); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "8,0xff00ff00ff00ff00,%s,&,>>,tmp,=," "8,0x00ff00ff00ff00ff,%s,&,<<,tmp,|=,tmp,%s,=", r1, r1, r0); @@ -1027,28 +1027,28 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } case ARM64_INS_ADR: // TODO: must be 21bit signed - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,=", IMM64(1), REG64(0)); break; case ARM64_INS_SMADDL: { int size = REGSIZE64(1)*8; - r_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,*,%s,+,%s,=", + rz_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,*,%s,+,%s,=", size, REG64 (2), size, REG64 (1), REG64 (3), REG64 (0)); break; } case ARM64_INS_UMADDL: case ARM64_INS_FMADD: case ARM64_INS_MADD: - r_strbuf_setf (&op->esil, "%s,%s,*,%s,+,%s,=", + rz_strbuf_setf (&op->esil, "%s,%s,*,%s,+,%s,=", REG64 (2), REG64 (1), REG64 (3), REG64 (0)); break; case ARM64_INS_MSUB: - r_strbuf_setf (&op->esil, "%s,%s,*,%s,-,%s,=", + rz_strbuf_setf (&op->esil, "%s,%s,*,%s,-,%s,=", REG64 (2), REG64 (1), REG64 (3), REG64 (0)); break; case ARM64_INS_MNEG: - r_strbuf_setf (&op->esil, "%s,%s,*,0,-,%s,=", + rz_strbuf_setf (&op->esil, "%s,%s,*,0,-,%s,=", REG64 (2), REG64 (1), REG64 (0)); break; case ARM64_INS_ADD: @@ -1061,13 +1061,13 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l break; case ARM64_INS_SBC: // TODO have to check this more, VEX does not work - r_strbuf_setf (&op->esil, "%s,cf,+,%s,-,%s,=", + rz_strbuf_setf (&op->esil, "%s,cf,+,%s,-,%s,=", REG64 (2), REG64 (1), REG64 (0)); break; case ARM64_INS_SMULL: { int size = REGSIZE64(1)*8; - r_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,*,%s,=", + rz_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,*,%s,=", size, REG64 (2), size, REG64 (1), REG64 (0)); break; } @@ -1098,14 +1098,14 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISREG64(2)) { if (LSHIFT2_64 (2) || EXT64(2)) { SHIFTED_REG64_APPEND(&op->esil, 2); - r_strbuf_appendf (&op->esil, ",%d,%%,%s,>>,%s,=", size, r1, r0); + rz_strbuf_appendf (&op->esil, ",%d,%%,%s,>>,%s,=", size, r1, r0); } else { const char *r2 = REG64(2); - r_strbuf_setf (&op->esil, "%d,%s,%%,%s,>>,%s,=", size, r2, r1, r0); + rz_strbuf_setf (&op->esil, "%d,%s,%%,%s,>>,%s,=", size, r2, r1, r0); } } else { ut64 i2 = IMM64(2); - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,>>,%s,=", i2 % (ut64)size, r1, r0); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,>>,%s,=", i2 % (ut64)size, r1, r0); } break; } @@ -1118,14 +1118,14 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISREG64(2)) { if (LSHIFT2_64 (2) || EXT64(2)) { SHIFTED_REG64_APPEND(&op->esil, 2); - r_strbuf_appendf (&op->esil, ",%d,%%,%s,<<,%s,=", size, r1, r0); + rz_strbuf_appendf (&op->esil, ",%d,%%,%s,<<,%s,=", size, r1, r0); } else { const char *r2 = REG64(2); - r_strbuf_setf (&op->esil, "%d,%s,%%,%s,<<,%s,=", size, r2, r1, r0); + rz_strbuf_setf (&op->esil, "%d,%s,%%,%s,<<,%s,=", size, r2, r1, r0); } } else { ut64 i2 = IMM64(2); - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,<<,%s,=", i2 % (ut64)size, r1, r0); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,<<,%s,=", i2 % (ut64)size, r1, r0); } break; } @@ -1133,7 +1133,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l OPCALL(">>>"); break; case ARM64_INS_NOP: - r_strbuf_setf (&op->esil, ","); + rz_strbuf_setf (&op->esil, ","); break; case ARM64_INS_FDIV: break; @@ -1142,40 +1142,40 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l /* TODO: support WZR XZR to specify 32, 64bit op */ int size = REGSIZE64(1)*8; if (ISREG64(2)) { - r_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,~/,%s,=", size, REG64 (2), size, REG64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,~/,%s,=", size, REG64 (2), size, REG64 (1), REG64 (0)); } else { - r_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,~/,%s,=", size, REG64 (1), size, REG64 (0), REG64 (0)); + rz_strbuf_setf (&op->esil, "%d,%s,~,%d,%s,~,~/,%s,=", size, REG64 (1), size, REG64 (0), REG64 (0)); } break; } case ARM64_INS_UDIV: /* TODO: support WZR XZR to specify 32, 64bit op */ if ISREG64(2) { - r_strbuf_setf (&op->esil, "%s,%s,/,%s,=", REG(2), REG64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%s,%s,/,%s,=", REG(2), REG64 (1), REG64 (0)); } else { - r_strbuf_setf (&op->esil, "%s,%s,/=", REG64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%s,%s,/=", REG64 (1), REG64 (0)); } break; case ARM64_INS_BR: - r_strbuf_setf (&op->esil, "%s,pc,=", REG64(0)); + rz_strbuf_setf (&op->esil, "%s,pc,=", REG64(0)); break; case ARM64_INS_B: /* capstone precompute resulting address, using PC + IMM */ - r_strbuf_appendf (&op->esil, "%"PFMT64d",pc,=", IMM64 (0)); + rz_strbuf_appendf (&op->esil, "%"PFMT64d",pc,=", IMM64 (0)); break; case ARM64_INS_BL: - r_strbuf_setf (&op->esil, "pc,lr,=,%"PFMT64d",pc,=", IMM64 (0)); + rz_strbuf_setf (&op->esil, "pc,lr,=,%"PFMT64d",pc,=", IMM64 (0)); break; case ARM64_INS_BLR: - r_strbuf_setf (&op->esil, "pc,lr,=,%s,pc,=", REG64 (0)); + rz_strbuf_setf (&op->esil, "pc,lr,=,%s,pc,=", REG64 (0)); break; case ARM64_INS_CLZ:; int size = 8*REGSIZE64(0); // expression is much more concise with GOTO, but GOTOs should be minimized - // r_strbuf_setf (&op->esil, "%s,%s,=,0,DUP,%d,1,<<,%s,&,%d,>,&,?{,%s,=,}{,1,%s,<<=,1,+,4,GOTO,}", + // rz_strbuf_setf (&op->esil, "%s,%s,=,0,DUP,%d,1,<<,%s,&,%d,>,&,?{,%s,=,}{,1,%s,<<=,1,+,4,GOTO,}", // REG64 (1), REG64 (0), size*8 - 1, REG64 (0), REG64 (0), REG64 (0)); /* @@ -1195,7 +1195,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l const char *r1 = REG64 (1); if (size == 32) { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%s,tmp,=,0," "tmp,0xffff0000,&,!,?{,16,tmp,<<=,16,+,}," "tmp,0xff000000,&,!,?{,8,tmp,<<=,8,+,}," @@ -1206,7 +1206,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l r1, r1, r0, r0); } else { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%s,tmp,=,0," "tmp,0xffffffff00000000,&,!,?{,32,tmp,<<=,32,+,}," "tmp,0xffff000000000000,&,!,?{,16,tmp,<<=,16,+,}," @@ -1267,35 +1267,35 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (HASMEMINDEX64(1)) { if (LSHIFT2_64(1) || EXT64(1)) { SHIFTED_REG64_APPEND(&op->esil, 1); - r_strbuf_appendf (&op->esil, ",%s,+,[%d],%s,=", MEMBASE64(1), size, REG64(0)); + rz_strbuf_appendf (&op->esil, ",%s,+,[%d],%s,=", MEMBASE64(1), size, REG64(0)); } else { - r_strbuf_appendf (&op->esil, "%s,%s,+,[%d],%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,+,[%d],%s,=", MEMBASE64(1), MEMINDEX64(1), size, REG64(0)); } } else { // I really don't like the DUP / tmp approach but its better than doubling the calculation if (LSHIFT2_64(1)) { - r_strbuf_appendf (&op->esil, "%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],%s,=", + rz_strbuf_appendf (&op->esil, "%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],%s,=", MEMBASE64(1), LSHIFT2_64(1), MEMDISP64(1), DECODE_SHIFT64(1), size, REG64(0)); } else if ((int)MEMDISP64(1) < 0){ - r_strbuf_appendf (&op->esil, "%"PFMT64d",%s,-,DUP,tmp,=,[%d],%s,=", + rz_strbuf_appendf (&op->esil, "%"PFMT64d",%s,-,DUP,tmp,=,[%d],%s,=", -(int)MEMDISP64(1), MEMBASE64(1), size, REG64(0)); } else { - r_strbuf_appendf (&op->esil, "%"PFMT64d",%s,+,DUP,tmp,=,[%d],%s,=", + rz_strbuf_appendf (&op->esil, "%"PFMT64d",%s,+,DUP,tmp,=,[%d],%s,=", MEMDISP64(1), MEMBASE64(1), size, REG64(0)); } // I assume the DUPs here previously were to handle preindexing // but it was never finished? if (ISPREINDEX32()) { - r_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); } else if (ISPOSTINDEX32()) { if (ISREG64(2)) { // not sure if register valued post indexing exists? - r_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); } else { - r_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); } } } @@ -1303,7 +1303,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } else { if (ISREG64(1)) { if (OPCOUNT64() == 2) { - r_strbuf_setf (&op->esil, "%s,[%d],%s,=", + rz_strbuf_setf (&op->esil, "%s,[%d],%s,=", REG64(1), size, REG64(0)); } else if (OPCOUNT64() == 3) { /* @@ -1315,12 +1315,12 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l fall in this case instead. */ if (ISREG64(2)) { - r_strbuf_setf (&op->esil, "%s,%s,+,[%d],%s,=", + rz_strbuf_setf (&op->esil, "%s,%s,+,[%d],%s,=", REG64(1), REG64(2), size, REG64(0)); } } } else { - r_strbuf_setf (&op->esil, "%"PFMT64d",[%d],%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64d",[%d],%s,=", IMM64(1), size, REG64(0)); } } @@ -1355,36 +1355,36 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISMEM64(1)) { if (HASMEMINDEX64(1)) { if (LSHIFT2_64(1) || EXT64(1)) { - r_strbuf_appendf (&op->esil, "%d,%s,", size*8, MEMBASE64(1)); + rz_strbuf_appendf (&op->esil, "%d,%s,", size*8, MEMBASE64(1)); SHIFTED_REG64_APPEND(&op->esil, 1); - r_strbuf_appendf (&op->esil, ",+,[%d],~,%s,=", size, REG64(0)); + rz_strbuf_appendf (&op->esil, ",+,[%d],~,%s,=", size, REG64(0)); } else { - r_strbuf_appendf (&op->esil, "%d,%s,%s,+,[%d],~,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,%s,+,[%d],~,%s,=", size*8, MEMBASE64(1), MEMINDEX64(1), size, REG64(0)); } } else { if (LSHIFT2_64(1)) { - r_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],~,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],~,%s,=", size*8, MEMBASE64(1), LSHIFT2_64(1), MEMDISP64(1), DECODE_SHIFT64(1), size, REG64(0)); } else if ((int)MEMDISP64(1) < 0){ - r_strbuf_appendf (&op->esil, "%d,%"PFMT64d",%s,-,DUP,tmp,=,[%d],~,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%"PFMT64d",%s,-,DUP,tmp,=,[%d],~,%s,=", size*8, -(int)MEMDISP64(1), MEMBASE64(1), size, REG64(0)); } else { - r_strbuf_appendf (&op->esil, "%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],~,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%"PFMT64d",%s,+,DUP,tmp,=,[%d],~,%s,=", size*8, MEMDISP64(1), MEMBASE64(1), size, REG64(0)); } // I assume the DUPs here previously were to handle preindexing // but it was never finished? if (ISPREINDEX32()) { - r_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); } else if (ISPOSTINDEX32()) { if (ISREG64(2)) { // not sure if register valued post indexing exists? - r_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); } else { - r_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); } } } @@ -1392,7 +1392,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } else { if (ISREG64(1)) { if (OPCOUNT64() == 2) { - r_strbuf_setf (&op->esil, "%d,%s,[%d],~,%s,=", + rz_strbuf_setf (&op->esil, "%d,%s,[%d],~,%s,=", size*8, REG64(1), size, REG64(0)); } else if (OPCOUNT64() == 3) { /* @@ -1404,12 +1404,12 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l fall in this case instead. */ if (ISREG64(2)) { - r_strbuf_setf (&op->esil, "%d,%s,%s,+,[%d],~,%s,=", + rz_strbuf_setf (&op->esil, "%d,%s,%s,+,[%d],~,%s,=", size*8, REG64(1), REG64(2), size, REG64(0)); } } } else { - r_strbuf_setf (&op->esil, "%d,%"PFMT64d",[%d],~,%s,=", + rz_strbuf_setf (&op->esil, "%d,%"PFMT64d",[%d],~,%s,=", size*8, IMM64(1), size, REG64(0)); } } @@ -1425,29 +1425,29 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l // update esil, cpu flags int bits = arm64_reg_width(REGID64(0)); if (ISIMM64(1)) { - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=", IMM64(1) << LSHIFT2_64(1), REG64(0), bits - 1, bits, bits - 1); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=", IMM64(1) << LSHIFT2_64(1), REG64(0), bits - 1, bits, bits - 1); } else { // cmp w10, w11 SHIFTED_REG64_APPEND(&op->esil, 1); - r_strbuf_appendf (&op->esil, ",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=", REG64(0), bits - 1, bits, bits -1); + rz_strbuf_appendf (&op->esil, ",%s,==,$z,zf,:=,%d,$s,nf,:=,%d,$b,!,cf,:=,%d,$o,vf,:=", REG64(0), bits - 1, bits, bits -1); } break; } case ARM64_INS_FCSEL: case ARM64_INS_CSEL: // csel Wd, Wn, Wm --> Wd := (cond) ? Wn : Wm - r_strbuf_appendf (&op->esil, "%s,}{,%s,},%s,=", REG64(1), REG64(2), REG64(0)); + rz_strbuf_appendf (&op->esil, "%s,}{,%s,},%s,=", REG64(1), REG64(2), REG64(0)); postfix = ""; break; case ARM64_INS_CSET: // cset Wd --> Wd := (cond) ? 1 : 0 - r_strbuf_appendf (&op->esil, "1,}{,0,},%s,=", REG64(0)); + rz_strbuf_appendf (&op->esil, "1,}{,0,},%s,=", REG64(0)); postfix = ""; break; case ARM64_INS_CINC: // cinc Wd, Wn --> Wd := (cond) ? (Wn+1) : Wn - r_strbuf_appendf (&op->esil, "1,%s,+,}{,%s,},%s,=", REG64(1), REG64(1), REG64(0)); + rz_strbuf_appendf (&op->esil, "1,%s,+,}{,%s,},%s,=", REG64(1), REG64(1), REG64(0)); postfix = ""; break; case ARM64_INS_CSINC: // csinc Wd, Wn, Wm --> Wd := (cond) ? Wn : (Wm+1) - r_strbuf_appendf (&op->esil, "%s,}{,1,%s,+,},%s,=", REG64(1), REG64(2), REG64(0)); + rz_strbuf_appendf (&op->esil, "%s,}{,1,%s,+,},%s,=", REG64(1), REG64(2), REG64(0)); postfix = ""; break; case ARM64_INS_STXRB: @@ -1460,7 +1460,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } else if (insn->id == ARM64_INS_STXRH) { size = 2; } - r_strbuf_setf (&op->esil, "0,%s,=,%s,%s,%"PFMT64d",+,=[%d]", + rz_strbuf_setf (&op->esil, "0,%s,=,%s,%s,%"PFMT64d",+,=[%d]", REG64(0), REG64(1), MEMBASE64(1), MEMDISP64(1), size); break; } @@ -1480,36 +1480,36 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISMEM64(1)) { if (HASMEMINDEX64(1)) { if (LSHIFT2_64(1) || EXT64(1)) { - r_strbuf_appendf (&op->esil, "%s,%s,", REG64(0), MEMBASE64(1)); + rz_strbuf_appendf (&op->esil, "%s,%s,", REG64(0), MEMBASE64(1)); SHIFTED_REG64_APPEND(&op->esil, 1); - r_strbuf_appendf (&op->esil, ",+,=[%d]", size); + rz_strbuf_appendf (&op->esil, ",+,=[%d]", size); } else { - r_strbuf_appendf (&op->esil, "%s,%s,%s,+,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%s,+,=[%d]", REG64(0), MEMBASE64(1), MEMINDEX64(1), size); } } else { if (LSHIFT2_64(1)) { - r_strbuf_appendf (&op->esil, "%s,%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%"PFMT64d",%s,+,DUP,tmp,=,=[%d]", REG64(0), MEMBASE64(1), LSHIFT2_64(1), MEMDISP64(1), DECODE_SHIFT64(1), size); } else if ((int)MEMDISP64(1) < 0){ - r_strbuf_appendf (&op->esil, "%s,%"PFMT64d",%s,-,DUP,tmp,=,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%"PFMT64d",%s,-,DUP,tmp,=,=[%d]", REG64(0), -(int)MEMDISP64(1), MEMBASE64(1), size); } else { - r_strbuf_appendf (&op->esil, "%s,%"PFMT64d",%s,+,DUP,tmp,=,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%"PFMT64d",%s,+,DUP,tmp,=,=[%d]", REG64(0), MEMDISP64(1), MEMBASE64(1), size); } // I assume the DUPs here previously were to handle preindexing // but it was never finished? if (ISPREINDEX32()) { - r_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,=", REG64(1)); } else if (ISPOSTINDEX32()) { if (ISREG64(2)) { // not sure if register valued post indexing exists? - r_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%s,+,%s,=", REG64(2), REG64(1)); } else { - r_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); + rz_strbuf_appendf (&op->esil, ",tmp,%"PFMT64d",+,%s,=", IMM64(2), REG64(1)); } } } @@ -1517,7 +1517,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } else { if (ISREG64(1)) { if (OPCOUNT64() == 2) { - r_strbuf_setf (&op->esil, "%s,%s,=[%d]", + rz_strbuf_setf (&op->esil, "%s,%s,=[%d]", REG64(0), REG64(1), size); } else if (OPCOUNT64() == 3) { /* @@ -1529,12 +1529,12 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l fall in this case instead. */ if (ISREG64(2)) { - r_strbuf_setf (&op->esil, "%s,%s,%s,+,=[%d]", + rz_strbuf_setf (&op->esil, "%s,%s,%s,+,=[%d]", REG64(0), REG64(1), REG64(2), size); } } } else { - r_strbuf_setf (&op->esil, "%s,%"PFMT64d",=[%d]", + rz_strbuf_setf (&op->esil, "%s,%"PFMT64d",=[%d]", REG64(0), IMM64(1), size); } } @@ -1543,36 +1543,36 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l case ARM64_INS_BIC: if (OPCOUNT64 () == 2) { if (REGSIZE64(0) == 4) { - r_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&=", REG64 (1), REG64 (0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&=", REG64 (1), REG64 (0)); } else { - r_strbuf_appendf (&op->esil, "%s,0xffffffffffffffff,^,%s,&=", REG64 (1), REG64 (0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffffffffffff,^,%s,&=", REG64 (1), REG64 (0)); } } else { if (REGSIZE64(0) == 4) { - r_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&,%s,=", REG64 (2), REG64 (1), REG64 (0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&,%s,=", REG64 (2), REG64 (1), REG64 (0)); } else { - r_strbuf_appendf (&op->esil, "%s,0xffffffffffffffff,^,%s,&,%s,=", REG64 (2), REG64 (1), REG64 (0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffffffffffff,^,%s,&,%s,=", REG64 (2), REG64 (1), REG64 (0)); } } break; case ARM64_INS_CBZ: - r_strbuf_setf (&op->esil, "%s,!,?{,%"PFMT64d",pc,=,}", + rz_strbuf_setf (&op->esil, "%s,!,?{,%"PFMT64d",pc,=,}", REG64(0), IMM64(1)); break; case ARM64_INS_CBNZ: - r_strbuf_setf (&op->esil, "%s,?{,%"PFMT64d",pc,=,}", + rz_strbuf_setf (&op->esil, "%s,?{,%"PFMT64d",pc,=,}", REG64(0), IMM64(1)); break; case ARM64_INS_TBZ: // tbnz x0, 4, label // if ((1<<4) & x0) goto label; - r_strbuf_setf (&op->esil, "%d,1,<<,%s,&,!,?{,%"PFMT64d",pc,=,}", + rz_strbuf_setf (&op->esil, "%d,1,<<,%s,&,!,?{,%"PFMT64d",pc,=,}", IMM64(1), REG64(0), IMM64(2)); break; case ARM64_INS_TBNZ: // tbnz x0, 4, label // if ((1<<4) & x0) goto label; - r_strbuf_setf (&op->esil, "%d,1,<<,%s,&,?{,%"PFMT64d",pc,=,}", + rz_strbuf_setf (&op->esil, "%d,1,<<,%s,&,?{,%"PFMT64d",pc,=,}", IMM64(1), REG64(0), IMM64(2)); break; case ARM64_INS_STNP: @@ -1586,7 +1586,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISPREINDEX64()) { // "stp x2, x3, [x8, 0x20]! // "32,x8,+=,x2,x8,=[8],x3,x8,8,+,=[8]", - r_strbuf_setf(&op->esil, + rz_strbuf_setf(&op->esil, "%"PFMT64d",%s,%c=,%s,%s,=[%d],%s,%s,%d,+,=[%d]", abs, MEMBASE64(2), sign, REG64(0), MEMBASE64(2), size, @@ -1598,14 +1598,14 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l abs = val>=0? val: -val; // "stp x4, x5, [x8], 0x10" // "x4,x8,=[],x5,x8,8,+,=[],16,x8,+=" - r_strbuf_setf(&op->esil, + rz_strbuf_setf(&op->esil, "%s,%s,=[%d],%s,%s,%d,+,=[%d],%d,%s,%c=", REG64(0), MEMBASE64(2), size, REG64(1), MEMBASE64(2), size, size, abs, MEMBASE64(2), sign); // Everything else } else { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%s,%s,%"PFMT64d",%c,=[%d]," "%s,%s,%"PFMT64d",%c,%d,+,=[%d]", REG64(0), MEMBASE64(2), abs, sign, size, @@ -1624,7 +1624,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISPREINDEX64()) { // "ldp x0, x1, [x8, -0x10]!" // 16,x8,-=,x8,[8],x0,=,x8,8,+,[8],x1,= - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,%c=," "%s,[%d],%s,=," "%s,%d,+,[%d],%s,=", @@ -1638,7 +1638,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l abs = val>=0? val: -val; // ldp x4, x5, [x8], -0x10 // x8,[8],x4,=,x8,8,+,[8],x5,=,16,x8,+= - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%s,[%d],%s,=," "%s,%d,+,[%d],%s,=," "%d,%s,%c=", @@ -1646,7 +1646,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l MEMBASE64(2), size, size, REG64(1), abs, MEMBASE64(2), sign); } else { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "%s,%"PFMT64d",%c,[%d],%s,=," "%s,%"PFMT64d",%c,%d,%c,[%d],%s,=", MEMBASE64(2), abs, sign, size, REG64(0), @@ -1655,14 +1655,14 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l } break; case ARM64_INS_ADRP: - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,=", IMM64 (1), REG64 (0)); break; case ARM64_INS_MOV: if (ISREG64(1)) { - r_strbuf_setf (&op->esil, "%s,%s,=", REG64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%s,%s,=", REG64 (1), REG64 (0)); } else { - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,=", IMM64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,=", IMM64 (1), REG64 (0)); } break; case ARM64_INS_EXTR: @@ -1675,21 +1675,21 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l 05 | t3 = Or64(t5,t4) 06 | PUT(x4) = t3 */ - r_strbuf_setf (&op->esil, "%d,%s,>>,%d,%s,<<,|,%s,=", + rz_strbuf_setf (&op->esil, "%d,%s,>>,%d,%s,<<,|,%s,=", IMM64(3), REG64(2), IMM64(3), REG64(1), REG64(0)); break; case ARM64_INS_RBIT: // this expression reverses the bits. it does. do not scroll right. // Derived from VEX - r_strbuf_setf (&op->esil, "0xffffffff00000000,0x20,0xffff0000ffff0000,0x10,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x10,0xffff0000ffff0000,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x20,0xffffffff00000000,0xffff0000ffff0000,0x10,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x10,0xffff0000ffff0000,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,%2$s,=", + rz_strbuf_setf (&op->esil, "0xffffffff00000000,0x20,0xffff0000ffff0000,0x10,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x10,0xffff0000ffff0000,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x20,0xffffffff00000000,0xffff0000ffff0000,0x10,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,<<,&,0x10,0xffff0000ffff0000,0xff00ff00ff00ff00,0x8,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,<<,&,0x8,0xff00ff00ff00ff00,0xf0f0f0f0f0f0f0f0,0x4,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,<<,&,0x4,0xf0f0f0f0f0f0f0f0,0xcccccccccccccccc,0x2,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,<<,&,0x2,0xcccccccccccccccc,0xaaaaaaaaaaaaaaaa,0x1,%1$s,<<,&,0x1,0xaaaaaaaaaaaaaaaa,%1$s,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,&,>>,|,%2$s,=", REG64(1), REG64(0)); break; case ARM64_INS_MVN: case ARM64_INS_MOVN: if (ISREG64(1)) { - r_strbuf_setf (&op->esil, "%d,%s,-1,^,<<,%s,=", LSHIFT2_64 (1), REG64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%d,%s,-1,^,<<,%s,=", LSHIFT2_64 (1), REG64 (1), REG64 (0)); } else { - r_strbuf_setf (&op->esil, "%d,%"PFMT64d",<<,-1,^,%s,=", LSHIFT2_64 (1), IMM64 (1), REG64 (0)); + rz_strbuf_setf (&op->esil, "%d,%"PFMT64d",<<,-1,^,%s,=", LSHIFT2_64 (1), IMM64 (1), REG64 (0)); } break; case ARM64_INS_MOVK: // movk w8, 0x1290 @@ -1703,7 +1703,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l ut64 shifted_imm = IMM64(1) << shift; ut64 mask = ~(0xffffLL << shift); - r_strbuf_setf (&op->esil, "0x%"PFMT64x",%s,&,%"PFMT64u",|,%s,=", + rz_strbuf_setf (&op->esil, "0x%"PFMT64x",%s,&,%"PFMT64u",|,%s,=", mask, REG64(0), shifted_imm, @@ -1712,7 +1712,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l break; } case ARM64_INS_MOVZ: - r_strbuf_setf (&op->esil, "%"PFMT64u",%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64u",%s,=", IMM64(1) << LSHIFT2_64(1), REG64 (0)); break; @@ -1727,53 +1727,53 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (ISREG64(2)) { if (LSHIFT2_64 (2)) { SHIFTED_REG64_APPEND(&op->esil, 2); - r_strbuf_appendf (&op->esil, ",%d,%%,%s,>>>>,%s,=", size, r1, r0); + rz_strbuf_appendf (&op->esil, ",%d,%%,%s,>>>>,%s,=", size, r1, r0); } else { const char *r2 = REG64(2); - r_strbuf_setf (&op->esil, "%d,%s,%%,%s,>>>>,%s,=", size, r2, r1, r0); + rz_strbuf_setf (&op->esil, "%d,%s,%%,%s,>>>>,%s,=", size, r2, r1, r0); } } else { ut64 i2 = IMM64(2); - r_strbuf_setf (&op->esil, "%"PFMT64d",%s,>>>>,%s,=", i2 % (ut64)size, r1, r0); + rz_strbuf_setf (&op->esil, "%"PFMT64d",%s,>>>>,%s,=", i2 % (ut64)size, r1, r0); } break; } case ARM64_INS_SXTB: if (arm64_reg_width(REGID64(0)) == 32) { - r_strbuf_setf (&op->esil, "0xffffffff,8,0xff,%s,&,~,&,%s,=", + rz_strbuf_setf (&op->esil, "0xffffffff,8,0xff,%s,&,~,&,%s,=", REG64(1), REG64(0)); } else { - r_strbuf_setf (&op->esil, "8,0xff,%s,&,~,%s,=", + rz_strbuf_setf (&op->esil, "8,0xff,%s,&,~,%s,=", REG64(1), REG64(0)); } break; case ARM64_INS_SXTH: /* halfword */ if (arm64_reg_width(REGID64(0)) == 32) { - r_strbuf_setf (&op->esil, "0xffffffff,16,0xffff,%s,&,~,&,%s,=", + rz_strbuf_setf (&op->esil, "0xffffffff,16,0xffff,%s,&,~,&,%s,=", REG64(1), REG64(0)); } else { - r_strbuf_setf (&op->esil, "16,0xffff,%s,&,~,%s,=", + rz_strbuf_setf (&op->esil, "16,0xffff,%s,&,~,%s,=", REG64(1), REG64(0)); } break; case ARM64_INS_SXTW: /* word */ - r_strbuf_setf (&op->esil, "32,0xffffffff,%s,&,~,%s,=", + rz_strbuf_setf (&op->esil, "32,0xffffffff,%s,&,~,%s,=", REG64(1), REG64(0)); break; case ARM64_INS_UXTB: - r_strbuf_setf (&op->esil, "%s,0xff,&,%s,=", REG64(1), REG64(0)); + rz_strbuf_setf (&op->esil, "%s,0xff,&,%s,=", REG64(1), REG64(0)); break; case ARM64_INS_UMULL: - r_strbuf_setf (&op->esil, "%s,%s,*,%s,=", REG64(1),REG64(2),REG64(0)); + rz_strbuf_setf (&op->esil, "%s,%s,*,%s,=", REG64(1),REG64(2),REG64(0)); break; case ARM64_INS_UXTH: - r_strbuf_setf (&op->esil, "%s,0xffff,&,%s,=", REG64(1), REG64(0)); + rz_strbuf_setf (&op->esil, "%s,0xffff,&,%s,=", REG64(1), REG64(0)); break; case ARM64_INS_RET: - r_strbuf_setf (&op->esil, "lr,pc,="); + rz_strbuf_setf (&op->esil, "lr,pc,="); break; case ARM64_INS_ERET: - r_strbuf_setf (&op->esil, "lr,pc,="); + rz_strbuf_setf (&op->esil, "lr,pc,="); break; case ARM64_INS_BFI: // bfi w8, w8, 2, 1 case ARM64_INS_BFXIL: @@ -1783,32 +1783,32 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l ut64 shift = IMM64 (2); ut64 notmask = ~(mask << shift); // notmask,dst,&,lsb,mask,src,&,<<,|,dst,= - r_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,%"PFMT64u",%"PFMT64u",%s,&,<<,|,%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,%"PFMT64u",%"PFMT64u",%s,&,<<,|,%s,=", notmask, REG64 (0), shift, mask, REG64 (1), REG64 (0)); } break; } case ARM64_INS_SBFIZ: if (IMM64 (3) > 0 && IMM64 (3) <= 64 - IMM64 (2)) { - r_strbuf_appendf (&op->esil, "%d,%d,%s,%"PFMT64u",&,~,<<,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%d,%s,%"PFMT64u",&,~,<<,%s,=", IMM64 (2), IMM64 (3), REG64(1), (ut64)bitmask_by_width[IMM64 (3) - 1], REG64(0)); } break; case ARM64_INS_UBFIZ: if (IMM64 (3) > 0 && IMM64 (3) <= 64 - IMM64 (2)) { - r_strbuf_appendf (&op->esil, "%d,%s,%"PFMT64u",&,<<,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,%"PFMT64u",&,<<,%s,=", IMM64 (2), REG64(1), (ut64)bitmask_by_width[IMM64 (3) - 1], REG64(0)); } break; case ARM64_INS_SBFX: if (IMM64 (3) > 0 && IMM64 (3) <= 64 - IMM64 (2)) { - r_strbuf_appendf (&op->esil, "%d,%d,%s,%d,%"PFMT64u",<<,&,>>,~,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%d,%s,%d,%"PFMT64u",<<,&,>>,~,%s,=", IMM64 (3), IMM64 (2), REG64 (1), IMM64 (2) , (ut64)bitmask_by_width[IMM64 (3) - 1], REG64 (0)); } break; case ARM64_INS_UBFX: if (IMM64 (3) > 0 && IMM64 (3) <= 64 - IMM64 (2)) { - r_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64u",<<,&,>>,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64u",<<,&,>>,%s,=", IMM64 (2), REG64 (1), IMM64 (2) , (ut64)bitmask_by_width[IMM64 (3) - 1], REG64 (0)); } break; @@ -1819,16 +1819,16 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l if (LSHIFT2_64 (1)) { SHIFTED_REG64_APPEND (&op->esil, 1); } else { - r_strbuf_appendf (&op->esil, "%s", REG64 (1)); + rz_strbuf_appendf (&op->esil, "%s", REG64 (1)); } - r_strbuf_appendf (&op->esil, ",0,-,%s,=", REG64 (0)); + rz_strbuf_appendf (&op->esil, ",0,-,%s,=", REG64 (0)); break; case ARM64_INS_SVC: - r_strbuf_setf (&op->esil, "%u,$", IMM64 (0)); + rz_strbuf_setf (&op->esil, "%u,$", IMM64 (0)); break; } - r_strbuf_append (&op->esil, postfix); + rz_strbuf_append (&op->esil, postfix); return 0; } @@ -1837,7 +1837,7 @@ static int analop64_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l #define MATH32_NEG(opchar) arm32math(a, op, addr, buf, len, handle, insn, pcdelta, str, opchar, 1) #define MATH32AS(opchar) arm32mathaddsub(a, op, addr, buf, len, handle, insn, pcdelta, str, opchar) -static void arm32math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char (*str)[32], const char *opchar, int negate) { +static void arm32math(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char (*str)[32], const char *opchar, int negate) { const char *dest = ARG(0); const char *op1; const char *op2; @@ -1851,54 +1851,54 @@ static void arm32math(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, } // right operand if (rotate_imm) { - r_strbuf_appendf (&op->esil, "%s,", ARG(3)); + rz_strbuf_appendf (&op->esil, "%s,", ARG(3)); } if (!strcmp (op2, "pc")) { - r_strbuf_appendf (&op->esil, "%d,$$,+", pcdelta); + rz_strbuf_appendf (&op->esil, "%d,$$,+", pcdelta); } else { - r_strbuf_appendf (&op->esil, "%s", op2); + rz_strbuf_appendf (&op->esil, "%s", op2); } if (rotate_imm) { - r_strbuf_appendf (&op->esil, ",>>>"); + rz_strbuf_appendf (&op->esil, ",>>>"); } if (negate) { - r_strbuf_appendf (&op->esil, ",-1,^"); + rz_strbuf_appendf (&op->esil, ",-1,^"); } if (!strcmp (op1, "pc")) { - r_strbuf_appendf (&op->esil, ",%d,$$,+,%s,0xffffffff,&,%s,=", pcdelta, opchar, dest); + rz_strbuf_appendf (&op->esil, ",%d,$$,+,%s,0xffffffff,&,%s,=", pcdelta, opchar, dest); } else { if (ISSHIFTED(1)) { - r_strbuf_appendf (&op->esil, ",0xffffffff,&,%s,=", dest); + rz_strbuf_appendf (&op->esil, ",0xffffffff,&,%s,=", dest); } else { - r_strbuf_appendf (&op->esil, ",%s,%s,0xffffffff,&,%s,=", op1, opchar, dest); + rz_strbuf_appendf (&op->esil, ",%s,%s,0xffffffff,&,%s,=", op1, opchar, dest); } } } -static void arm32mathaddsub(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char(*str)[32], const char *opchar) { +static void arm32mathaddsub(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, int pcdelta, char(*str)[32], const char *opchar) { const char *dst = ARG (0); const char *src; bool noflags = false; if (!strcmp (dst, "pc")) { //this is because strbuf_prepend doesn't exist and E_TOO_LAZY - // r_strbuf_append (&op->esil, "$$,pc,=,"); + // rz_strbuf_append (&op->esil, "$$,pc,=,"); noflags = true; } if (OPCOUNT () == 3) { - r_strbuf_appendf (&op->esil, "%s,0xffffffff,&,%s,=,", ARG (1), dst); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,&,%s,=,", ARG (1), dst); src = ARG (2); } else { // src = (!strcmp (ARG(1), "pc"))? "$$": ARG(1); src = ARG (1); } - r_strbuf_appendf (&op->esil, "%s,%s,%s,0xffffffff,&,%s,=", src, dst, opchar, dst); + rz_strbuf_appendf (&op->esil, "%s,%s,%s,0xffffffff,&,%s,=", src, dst, opchar, dst); if (noflags) { return; } - r_strbuf_appendf (&op->esil, ",$z,zf,:=,%s,cf,:=,vf,=,0,nf,=", + rz_strbuf_appendf (&op->esil, ",$z,zf,:=,%s,cf,:=,vf,=,0,nf,=", (!strcmp (opchar, "+")? "30,$c,31,$c,^,31,$c": "30,$c,31,$c,^,32,$b")); } -static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, bool thumb) { +static int analop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn, bool thumb) { int i; const char *postfix = NULL; char str[32][32]; @@ -1908,42 +1908,42 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len int str_ldr_bytes = 4; unsigned int width = 0; - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); postfix = arm_prefix_cond (op, insn->detail->arm.cc); switch (insn->id) { case ARM_INS_CLZ: - r_strbuf_appendf (&op->esil, "%s,!,?{,32,%s,=,BREAK,},0,%s,=,%s,%s,<<,0x80000000,&,!,?{,1,%s,+=,11,GOTO,}", REG (1), REG (0), REG (0), REG (0), REG (1), REG (0)); + rz_strbuf_appendf (&op->esil, "%s,!,?{,32,%s,=,BREAK,},0,%s,=,%s,%s,<<,0x80000000,&,!,?{,1,%s,+=,11,GOTO,}", REG (1), REG (0), REG (0), REG (0), REG (1), REG (0)); break; case ARM_INS_IT: - r_strbuf_appendf (&op->esil, "2,$$,+,pc,="); + rz_strbuf_appendf (&op->esil, "2,$$,+,pc,="); break; case ARM_INS_BKPT: - r_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0)); + rz_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0)); break; case ARM_INS_NOP: - r_strbuf_setf (&op->esil, ","); + rz_strbuf_setf (&op->esil, ","); break; case ARM_INS_BL: case ARM_INS_BLX: - r_strbuf_appendf (&op->esil, "pc,%d,+,lr,=,", thumb); + rz_strbuf_appendf (&op->esil, "pc,%d,+,lr,=,", thumb); /* fallthrough */ case ARM_INS_BX: case ARM_INS_BXJ: case ARM_INS_B: if (ISREG (0) && REGID (0) == ARM_REG_PC) { - r_strbuf_appendf (&op->esil, "0x%" PFMT64x ",pc,=", (addr & ~3LL) + pcdelta); + rz_strbuf_appendf (&op->esil, "0x%" PFMT64x ",pc,=", (addr & ~3LL) + pcdelta); } else { if (ISIMM (0)) { - r_strbuf_appendf (&op->esil, "%s,pc,=", ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,pc,=", ARG (0)); } else { - r_strbuf_appendf (&op->esil, "%d,%s,-,pc,=", thumb, ARG (0)); + rz_strbuf_appendf (&op->esil, "%d,%s,-,pc,=", thumb, ARG (0)); } } break; case ARM_INS_UDF: - r_strbuf_setf (&op->esil, "%s,TRAP", ARG (0)); + rz_strbuf_setf (&op->esil, "%s,TRAP", ARG (0)); break; case ARM_INS_SADD16: case ARM_INS_SADD8: @@ -1955,9 +1955,9 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len break; case ARM_INS_ADC: if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "cf,%s,+=,%s,%s,+=", ARG (0), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "cf,%s,+=,%s,%s,+=", ARG (0), ARG (1), ARG (0)); } else { - r_strbuf_appendf (&op->esil, "cf,%s,+=,%s,%s,+,%s,+=", ARG (0), ARG (2), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "cf,%s,+=,%s,%s,+,%s,+=", ARG (0), ARG (2), ARG (1), ARG (0)); } break; case ARM_INS_SSUB16: @@ -1970,9 +1970,9 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len break; case ARM_INS_SBC: if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "cf,%s,-=,%s,%s,-=", ARG (0), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "cf,%s,-=,%s,%s,-=", ARG (0), ARG (1), ARG (0)); } else { - r_strbuf_appendf (&op->esil, "cf,%s,-=,%s,%s,+,%s,-=", ARG (0), ARG (2), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "cf,%s,-=,%s,%s,+,%s,-=", ARG (0), ARG (2), ARG (1), ARG (0)); } break; case ARM_INS_MUL: @@ -1993,9 +1993,9 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case ARM_INS_LSR: if (insn->detail->arm.update_flags) { if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (1), ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (1), ARG (0), ARG (1)); } else { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (2), ARG (1), ARG (2)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (2), ARG (1), ARG (2)); } } MATH32 (">>"); @@ -2003,15 +2003,15 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case ARM_INS_LSL: if (insn->detail->arm.update_flags) { if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,32,-,%s,>>,cf,:=,},", ARG (1), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,32,-,%s,>>,cf,:=,},", ARG (1), ARG (1), ARG (0)); } else { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,32,-,%s,>>,cf,:=,},", ARG (2), ARG (2), ARG (1)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,32,-,%s,>>,cf,:=,},", ARG (2), ARG (2), ARG (1)); } } MATH32 ("<<"); break; case ARM_INS_SVC: - r_strbuf_setf (&op->esil, "%s,$", ARG (0)); + rz_strbuf_setf (&op->esil, "%s,$", ARG (0)); break; case ARM_INS_PUSH: #if 0 @@ -2024,90 +2024,90 @@ PUSH { r4, r5, r6, r7, lr } 20,sp,-=,lr,r7,r6,r5,r4,5,sp,=[*] #endif - r_strbuf_appendf (&op->esil, "%d,sp,-=,", + rz_strbuf_appendf (&op->esil, "%d,sp,-=,", 4 * insn->detail->arm.op_count); for (i = insn->detail->arm.op_count; i > 0; i--) { - r_strbuf_appendf (&op->esil, "%s,", REG (i - 1)); + rz_strbuf_appendf (&op->esil, "%s,", REG (i - 1)); } - r_strbuf_appendf (&op->esil, "%d,sp,=[*]", + rz_strbuf_appendf (&op->esil, "%d,sp,=[*]", insn->detail->arm.op_count); break; case ARM_INS_STM: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); for (i = 1; i < insn->detail->arm.op_count; i++) { - r_strbuf_appendf (&op->esil, "%s,%s,%d,%c,=[4],", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%c,=[4],", REG (i), ARG (0), R_ABS ((i - 1) * 4), i > 0? '+': '-'); } if (insn->detail->arm.writeback == true) { //writeback, reg should be incremented - r_strbuf_appendf (&op->esil, "%d,%s,+=,", + rz_strbuf_appendf (&op->esil, "%d,%s,+=,", (insn->detail->arm.op_count - 1) * 4, ARG (0)); } break; case ARM_INS_VSTMIA: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); width = 0; for (i = 1; i < insn->detail->arm.op_count; i++) { - r_strbuf_appendf (&op->esil, "%s,%d,%s,+,=[%d],", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,+,=[%d],", REG (i), width, ARG (0), REGSIZE32(i)); width += REGSIZE32(i); } // increment if writeback if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, "%d,%s,+=,", width, ARG (0)); + rz_strbuf_appendf (&op->esil, "%d,%s,+=,", width, ARG (0)); } break; case ARM_INS_VSTMDB: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); width = 0; for (i = insn->detail->arm.op_count - 1; i > 0; i--) { width += REGSIZE32(i); - r_strbuf_appendf (&op->esil, "%s,%d,%s,-,=[%d],", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,-,=[%d],", REG (i), width, ARG (0), REGSIZE32(i)); } // decrement writeback is mandatory for VSTMDB - r_strbuf_appendf (&op->esil, "%d,%s,-=,", width, ARG (0)); + rz_strbuf_appendf (&op->esil, "%d,%s,-=,", width, ARG (0)); break; case ARM_INS_VLDMIA: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); width = 0; for (i = 1; i < insn->detail->arm.op_count; i++) { - r_strbuf_appendf (&op->esil, "%d,%s,+,[%d],%s,=,", + rz_strbuf_appendf (&op->esil, "%d,%s,+,[%d],%s,=,", width, ARG (0), REGSIZE32(i), REG (i)); width += REGSIZE32(i); } // increment if writeback if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, "%d,%s,+=,", width, ARG (0)); + rz_strbuf_appendf (&op->esil, "%d,%s,+=,", width, ARG (0)); } break; case ARM_INS_VLDMDB: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); width = 0; for (i = insn->detail->arm.op_count - 1; i > 0; i--) { width += REGSIZE32(i); - r_strbuf_appendf (&op->esil, "%d,%s,-,[%d],%s,=,", + rz_strbuf_appendf (&op->esil, "%d,%s,-,[%d],%s,=,", width, ARG (0), REGSIZE32(i), REG (i)); } // decrement writeback is mandatory for VLDMDB - r_strbuf_appendf (&op->esil, "%d,%s,-=,", width, ARG (0)); + rz_strbuf_appendf (&op->esil, "%d,%s,-=,", width, ARG (0)); break; case ARM_INS_ASR: // suffix 'S' forces conditional flag to be updated if (insn->detail->arm.update_flags) { if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (1), ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (1), ARG (0), ARG (1)); } else if (OPCOUNT () == 3) { - r_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (2), ARG (1), ARG (2)); + rz_strbuf_appendf (&op->esil, "%s,!,!,?{,%s,1,%s,-,0x1,<<,&,!,!,cf,:=,},", ARG (2), ARG (1), ARG (2)); } } if (OPCOUNT () == 2) { if (ISSHIFTED (1)) { - r_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), ARG (0)); } else { - r_strbuf_appendf (&op->esil, "%s,%s,>>>>,%s,=", ARG (1), ARG (0), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,>>>>,%s,=", ARG (1), ARG (0), ARG (0)); } } else if (OPCOUNT () == 3) { - r_strbuf_appendf (&op->esil, "%s,%s,>>>>,%s,=", ARG (2), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,>>>>,%s,=", ARG (2), ARG (1), ARG (0)); } break; case ARM_INS_POP: @@ -2116,46 +2116,46 @@ POP { r4,r5, r6} r6,r5,r4,3,sp,[*],12,sp,+= #endif for (i = insn->detail->arm.op_count; i > 0; i--) { - r_strbuf_appendf (&op->esil, "%s,", REG (i - 1)); + rz_strbuf_appendf (&op->esil, "%s,", REG (i - 1)); } - r_strbuf_appendf (&op->esil, "%d,sp,[*],", + rz_strbuf_appendf (&op->esil, "%d,sp,[*],", insn->detail->arm.op_count); - r_strbuf_appendf (&op->esil, "%d,sp,+=", + rz_strbuf_appendf (&op->esil, "%d,sp,+=", 4 * insn->detail->arm.op_count); break; case ARM_INS_LDM: for (i = 1; i < insn->detail->arm.op_count; i++) { - r_strbuf_appendf (&op->esil, "%s,%d,+,[4],%s,=,", ARG (0), (i - 1) * 4, REG (i)); + rz_strbuf_appendf (&op->esil, "%s,%d,+,[4],%s,=,", ARG (0), (i - 1) * 4, REG (i)); } if (insn->detail->arm.writeback) { //writeback, reg should be incremented - r_strbuf_appendf (&op->esil, "%d,%s,+=,", + rz_strbuf_appendf (&op->esil, "%d,%s,+=,", (insn->detail->arm.op_count - 1) * 4, ARG (0)); } break; case ARM_INS_CMP: - r_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0)); break; case ARM_INS_CMN: - r_strbuf_appendf (&op->esil, "%s,%s,^,!,!,zf,=", ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,^,!,!,zf,=", ARG (1), ARG (0)); break; case ARM_INS_MOVT: - r_strbuf_appendf (&op->esil, "16,%s,<<,%s,|=", ARG (1), REG (0)); + rz_strbuf_appendf (&op->esil, "16,%s,<<,%s,|=", ARG (1), REG (0)); break; case ARM_INS_ADR: - r_strbuf_appendf (&op->esil, "%d,$$,+,%s,+,0xfffffffc,&,%s,=", + rz_strbuf_appendf (&op->esil, "%d,$$,+,%s,+,0xfffffffc,&,%s,=", pcdelta, ARG (1), REG (0)); break; case ARM_INS_MOV: case ARM_INS_VMOV: case ARM_INS_MOVW: - r_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0)); break; case ARM_INS_CBZ: - r_strbuf_appendf (&op->esil, "%s,!,?{,%" PFMT32u ",pc,=,}", + rz_strbuf_appendf (&op->esil, "%s,!,?{,%" PFMT32u ",pc,=,}", REG (0), IMM (1)); break; case ARM_INS_CBNZ: - r_strbuf_appendf (&op->esil, "%s,?{,%" PFMT32u ",pc,=,}", + rz_strbuf_appendf (&op->esil, "%s,?{,%" PFMT32u ",pc,=,}", REG (0), IMM (1)); break; // Encapsulated STR/H/B into a code section @@ -2187,10 +2187,10 @@ r6,r5,r4,3,sp,[*],12,sp,+= int disp = MEMDISP(1); char sign = disp>=0?'+':'-'; disp = disp>=0?disp:-disp; - r_strbuf_appendf (&op->esil, "%s,0x%x,%s,%c,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,0x%x,%s,%c,0xffffffff,&,=[%d]", REG(0), disp, MEMBASE(1), sign, str_ldr_bytes); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%d,%s,%c,%s,=", + rz_strbuf_appendf (&op->esil, ",%d,%s,%c,%s,=", disp, MEMBASE(1), sign, MEMBASE(1)); } } @@ -2198,34 +2198,34 @@ r6,r5,r4,3,sp,[*],12,sp,+= if (ISSHIFTED(1)) { // e.g. 'str r2, [r3, r1, lsl 4]' switch (SHIFTTYPE(1)) { case ARM_SFT_LSL: - r_strbuf_appendf (&op->esil, "%s,%s,%d,%s,<<,+,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%s,<<,+,0xffffffff,&,=[%d]", REG(0), MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), str_ldr_bytes); if (insn->detail->arm.writeback) { // e.g. 'str r2, [r3, r1, lsl 4]!' - r_strbuf_appendf (&op->esil, ",%s,%d,%s,<<,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,%s,<<,+,%s,=", MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), MEMBASE(1)); } break; case ARM_SFT_LSR: - r_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>,+,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>,+,0xffffffff,&,=[%d]", REG(0), MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), str_ldr_bytes); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%s,%d,%s,>>,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,%s,>>,+,%s,=", MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), MEMBASE(1)); } break; case ARM_SFT_ASR: - r_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>>>,+,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>>>,+,0xffffffff,&,=[%d]", REG(0), MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), str_ldr_bytes); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%s,%d,%s,>>>>,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,%s,>>>>,+,%s,=", MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), MEMBASE(1)); } break; case ARM_SFT_ROR: - r_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>>,+,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%d,%s,>>>,+,0xffffffff,&,=[%d]", REG(0), MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), str_ldr_bytes); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%s,%d,%s,>>>,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,%s,>>>,+,%s,=", MEMBASE(1), SHIFTVALUE(1), MEMINDEX(1), MEMBASE(1)); } break; @@ -2237,10 +2237,10 @@ r6,r5,r4,3,sp,[*],12,sp,+= break; } } else { // No shift - r_strbuf_appendf (&op->esil, "%s,%s,%s,+,0xffffffff,&,=[%d]", + rz_strbuf_appendf (&op->esil, "%s,%s,%s,+,0xffffffff,&,=[%d]", REG(0), MEMINDEX(1), MEMBASE(1), str_ldr_bytes); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%s,%s,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%s,+,%s,=", MEMINDEX(1), MEMBASE(1), MEMBASE(1)); } } @@ -2248,26 +2248,26 @@ r6,r5,r4,3,sp,[*],12,sp,+= } if (OPCOUNT() == 3) { // e.g. 'str r2, [r3], 4 if (ISIMM(2)) { // e.g. 'str r2, [r3], 4 - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%d,%s,+=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%d,%s,+=", REG(0), MEMBASE(1), str_ldr_bytes, IMM(2), MEMBASE(1)); } if (ISREG(2)) { // e.g. 'str r2, [r3], r1 if (ISSHIFTED(2)) { // e.g. 'str r2, [r3], r1, lsl 4' switch (SHIFTTYPE(2)) { case ARM_SFT_LSL: - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,<<,+,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,<<,+,%s,=", REG(0), MEMBASE(1), str_ldr_bytes, MEMBASE(1), SHIFTVALUE(2), REG(2), MEMBASE(1)); break; case ARM_SFT_LSR: - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>,+,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>,+,%s,=", REG(0), MEMBASE(1), str_ldr_bytes, MEMBASE(1), SHIFTVALUE(2), REG(2), MEMBASE(1)); break; case ARM_SFT_ASR: - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>>>,+,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>>>,+,%s,=", REG(0), MEMBASE(1), str_ldr_bytes, MEMBASE(1), SHIFTVALUE(2), REG(2), MEMBASE(1)); break; case ARM_SFT_ROR: - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>>,+,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%d,%s,>>>,+,%s,=", REG(0), MEMBASE(1), str_ldr_bytes, MEMBASE(1), SHIFTVALUE(2), REG(2), MEMBASE(1)); break; case ARM_SFT_RRX: @@ -2278,7 +2278,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= break; } } else { // No shift - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%s,+=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,%s,+=", REG(0), MEMBASE(1), str_ldr_bytes, REG(2), MEMBASE(1)); } } @@ -2287,20 +2287,20 @@ r6,r5,r4,3,sp,[*],12,sp,+= int disp = MEMDISP(2); char sign = disp>=0?'+':'-'; disp = disp>=0?disp:-disp; - r_strbuf_appendf (&op->esil, "%s,%d,%s,%c,0xffffffff,&,=[4],%s,4,%d,+,%s,%c,0xffffffff,&,=[4]", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,%c,0xffffffff,&,=[4],%s,4,%d,+,%s,%c,0xffffffff,&,=[4]", REG(0), disp, MEMBASE(2), sign, REG(1), disp, MEMBASE(2), sign); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%d,%s,%c,%s,=", + rz_strbuf_appendf (&op->esil, ",%d,%s,%c,%s,=", disp, MEMBASE(2), sign, MEMBASE(2)); } } else { if (ISSHIFTED(2)) { // it seems strd does not support SHIFT which is good, but have a check nonetheless } else { - r_strbuf_appendf (&op->esil, "%s,%s,%s,+,0xffffffff,&,=[4],%s,4,%s,+,%s,+,0xffffffff,&,=[4]", + rz_strbuf_appendf (&op->esil, "%s,%s,%s,+,0xffffffff,&,=[4],%s,4,%s,+,%s,+,0xffffffff,&,=[4]", REG(0), MEMINDEX(2), MEMBASE(2), REG(1), MEMINDEX(2), MEMBASE(2)); if (insn->detail->arm.writeback) { - r_strbuf_appendf (&op->esil, ",%s,%s,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%s,+,%s,=", MEMINDEX(2), MEMBASE(2), MEMBASE(2)); } } @@ -2309,51 +2309,51 @@ r6,r5,r4,3,sp,[*],12,sp,+= } if (OPCOUNT() == 4) { // e.g. 'strd r2, r3, [r4], 4' or 'strd r2, r3, [r4], r5' if (ISIMM(3)) { // e.g. 'strd r2, r3, [r4], 4' - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,4,%s,+,0xffffffff,&,=[%d],%d,%s,+=,", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,4,%s,+,0xffffffff,&,=[%d],%d,%s,+=,", REG(0), MEMBASE(2), str_ldr_bytes, REG(1), MEMBASE(2), str_ldr_bytes, IMM(3), MEMBASE(2)); } if (ISREG(3)) { // e.g. 'strd r2, r3, [r4], r5' if (ISSHIFTED(3)) { // same as above } else { - r_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,4,%s,+,0xffffffff,&,=[%d],%s,%s,+=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffffffff,&,=[%d],%s,4,%s,+,0xffffffff,&,=[%d],%s,%s,+=", REG(0), MEMBASE(2), str_ldr_bytes, REG(1), MEMBASE(2), str_ldr_bytes, REG(3), MEMBASE(2)); } } } break; case ARM_INS_TST: - r_strbuf_appendf (&op->esil, "%s,%s,==,$z,zf,:=", ARG(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,%s,==,$z,zf,:=", ARG(1), ARG(0)); break; case ARM_INS_LDRD: case ARM_INS_LDRB: if (ISMEM(1) && LSHIFT2(1)) { - r_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[1],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[1],0x%x,&,%s,=", MEMBASE (1), LSHIFT2 (1), MEMINDEX (1), mask, REG (0)); } else if (HASMEMINDEX (1)) { - r_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,[1],%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,[1],%s,=", MEMINDEX (1), MEMBASE (1), REG (0)); } else { - r_strbuf_appendf (&op->esil, "%s,%d,+,[1],%s,=", + rz_strbuf_appendf (&op->esil, "%s,%d,+,[1],%s,=", MEMBASE (1), MEMDISP (1), REG (0)); } if (insn->detail->arm.writeback) { if (ISIMM(2)) { - r_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", MEMBASE (1), IMM (2), MEMBASE (1)); } else { - r_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", MEMBASE (1), MEMDISP (1), MEMBASE (1)); } } break; case ARM_INS_SXTH: - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "15,%s,>>,1,&,?{,15,-1,<<,%s,0xffff,&,|,%s,:=,}{,%s,0xffff,%s,:=,}", REG (1), REG (1), REG (0), REG (1), REG (0)); break; case ARM_INS_SXTB: - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "7,%s,>>,1,&,?{,7,-1,<<,%s,0xff,&,|,%s,:=,}{,%s,0xff,&,%s,:=,}", REG (1), REG (1), REG (0), REG (1), REG (0)); break; @@ -2389,16 +2389,16 @@ r6,r5,r4,3,sp,[*],12,sp,+= if (REGBASE(1) == ARM_REG_PC) { op->refptr = 4; op->ptr = addr + pcdelta + MEMDISP(1); - r_strbuf_appendf (&op->esil, "0x%"PFMT64x",2,2,%s,>>,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "0x%"PFMT64x",2,2,%s,>>,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", (ut64)MEMDISP(1), pc, mask, REG(0)); } else { int disp = MEMDISP(1); // not refptr, because we can't grab the reg value statically op->refptr = 4; if (disp < 0) { - r_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,-,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,-,0xffffffff,&,[4],0x%x,&,%s,=", (ut64)-disp, MEMBASE(1), mask, REG(0)); } else { - r_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,+,0xffffffff,&,[4],0x%x,&,%s,=", (ut64)disp, MEMBASE(1), mask, REG(0)); } } @@ -2408,34 +2408,34 @@ r6,r5,r4,3,sp,[*],12,sp,+= op->refptr = 4; op->ptr = addr + pcdelta + MEMDISP(1); if (ISMEM(1) && LSHIFT2(1)) { - r_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%d,%s,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%d,%s,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", pcdelta, pc, LSHIFT2(1), MEMINDEX(1), mask, REG(0)); } else { if (ISREG(1)) { - r_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", pcdelta, pc, MEMINDEX(1), mask, REG(0)); } else { - r_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%d,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "2,2,%d,%s,+,>>,<<,%d,+,0xffffffff,&,[4],0x%x,&,%s,=", pcdelta, pc, MEMDISP(1), mask, REG(0)); } } } else { if (ISMEM(1) && LSHIFT2(1)) { - r_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[4],0x%x,&,%s,=", MEMBASE (1), LSHIFT2 (1), MEMINDEX (1), mask, REG (0)); } else if (HASMEMINDEX(1)) { // e.g. `ldr r2, [r3, r1]` - r_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", MEMINDEX (1), MEMBASE (1), mask, REG (0)); } else { - r_strbuf_appendf (&op->esil, "%d,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,+,0xffffffff,&,[4],0x%x,&,%s,=", MEMDISP (1), MEMBASE (1), mask, REG (0)); } if (insn->detail->arm.writeback) { if (ISIMM (2)) { - r_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", MEMBASE (1), IMM (2), MEMBASE (1)); } else { - r_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", + rz_strbuf_appendf (&op->esil, ",%s,%d,+,%s,=", MEMBASE (1), MEMDISP (1), MEMBASE (1)); } } @@ -2447,66 +2447,66 @@ r6,r5,r4,3,sp,[*],12,sp,+= break; case ARM_INS_MSR: msr_flags = insn->detail->arm.operands[0].reg >> 4; - r_strbuf_appendf (&op->esil, "0,", REG(1)); + rz_strbuf_appendf (&op->esil, "0,", REG(1)); if (msr_flags & 1) { - r_strbuf_appendf (&op->esil, "0xFF,|,"); + rz_strbuf_appendf (&op->esil, "0xFF,|,"); } if (msr_flags & 2) { - r_strbuf_appendf (&op->esil, "0xFF00,|,"); + rz_strbuf_appendf (&op->esil, "0xFF00,|,"); } if (msr_flags & 4) { - r_strbuf_appendf (&op->esil, "0xFF0000,|,"); + rz_strbuf_appendf (&op->esil, "0xFF0000,|,"); } if (msr_flags & 8) { - r_strbuf_appendf (&op->esil, "0xFF000000,|,"); + rz_strbuf_appendf (&op->esil, "0xFF000000,|,"); } - r_strbuf_appendf (&op->esil, "DUP,!,SWAP,&,%s,SWAP,cpsr,&,|,cpsr,=", REG(1)); + rz_strbuf_appendf (&op->esil, "DUP,!,SWAP,&,%s,SWAP,cpsr,&,|,cpsr,=", REG(1)); break; case ARM_INS_UBFX: if (IMM(3)>0 && IMM(3)<=32-IMM(2)) { - r_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64u",<<,&,>>,%s,=", + rz_strbuf_appendf (&op->esil, "%d,%s,%d,%"PFMT64u",<<,&,>>,%s,=", IMM(2), REG(1), IMM(2),(ut64)bitmask_by_width[IMM(3)-1], REG(0)); } break; case ARM_INS_UXTB: - r_strbuf_appendf (&op->esil, "%s,0xff,&,%s,=", ARG(1), REG(0)); + rz_strbuf_appendf (&op->esil, "%s,0xff,&,%s,=", ARG(1), REG(0)); break; case ARM_INS_RSB: if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "%s,%s,-=", ARG(0), ARG(1)); + rz_strbuf_appendf (&op->esil, "%s,%s,-=", ARG(0), ARG(1)); } else if (OPCOUNT () == 3) { - r_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", ARG(1), ARG(2), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", ARG(1), ARG(2), ARG(0)); } break; case ARM_INS_BIC: if (OPCOUNT () == 2) { - r_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&=", ARG(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&=", ARG(1), ARG(0)); } else { - r_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&,%s,=", ARG(2), ARG(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,&,%s,=", ARG(2), ARG(1), ARG(0)); } break; case ARM_INS_SMMLA: - r_strbuf_appendf (&op->esil, "32,%s,%s,*,>>,%s,+,0xffffffff,&,%s,=", + rz_strbuf_appendf (&op->esil, "32,%s,%s,*,>>,%s,+,0xffffffff,&,%s,=", REG(1), REG(2), REG(3), REG(0)); break; case ARM_INS_SMMLAR: - r_strbuf_appendf (&op->esil, "32,0x80000000,%s,%s,*,+,>>,%s,+,0xffffffff,&,%s,=", + rz_strbuf_appendf (&op->esil, "32,0x80000000,%s,%s,*,+,>>,%s,+,0xffffffff,&,%s,=", REG(1), REG(2), REG(3), REG(0)); break; case ARM_INS_UMULL: - r_strbuf_appendf (&op->esil, "32,%s,%s,*,DUP,0xffffffff,&,%s,=,>>,%s,=", + rz_strbuf_appendf (&op->esil, "32,%s,%s,*,DUP,0xffffffff,&,%s,=,>>,%s,=", REG(2), REG(3), REG(0), REG(1)); break; case ARM_INS_MLS: - r_strbuf_appendf (&op->esil, "%s,%s,*,%s,-,0xffffffff,&,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,*,%s,-,0xffffffff,&,%s,=", REG(1), REG(2), REG(3), REG(0)); break; case ARM_INS_MLA: - r_strbuf_appendf (&op->esil, "%s,%s,*,%s,+,0xffffffff,&,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,*,%s,+,0xffffffff,&,%s,=", REG(1), REG(2), REG(3), REG(0)); break; case ARM_INS_MVN: - r_strbuf_appendf (&op->esil, "-1,%s,^,0xffffffff,&,%s,=", + rz_strbuf_appendf (&op->esil, "-1,%s,^,0xffffffff,&,%s,=", ARG(1), REG(0)); break; case ARM_INS_BFI: @@ -2516,7 +2516,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= ut64 shift = IMM(2); ut64 notmask = ~(mask << shift); // notmask,dst,&,lsb,mask,src,&,<<,|,dst,= - r_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,%"PFMT64u",%"PFMT64u",%s,&,<<,|,0xffffffff,&,%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,%"PFMT64u",%"PFMT64u",%s,&,<<,|,0xffffffff,&,%s,=", notmask, REG(0), shift, mask, REG(1), REG(0)); } break; @@ -2528,7 +2528,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= ut64 shift = IMM(1); ut64 notmask = ~(mask << shift); // notmask,dst,&,dst,= - r_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,0xffffffff,&,%s,=", + rz_strbuf_setf (&op->esil, "%"PFMT64u",%s,&,0xffffffff,&,%s,=", notmask, REG(0), REG(0)); } break; @@ -2537,7 +2537,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= { const char *r0 = REG(0); const char *r1 = REG(1); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "24,0xff,%s,&,<<,%s,=," "16,0xff,8,%s,>>,&,<<,%s,|=," "8,0xff,16,%s,>>,&,<<,%s,|=," @@ -2549,7 +2549,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= { const char *r0 = REG(0); const char *r1 = REG(1); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "8,0xff00ff00,%s,&,>>,%s,=," "8,0x00ff00ff,%s,&,<<,%s,|=,", r1, r0, r1, r0); @@ -2559,7 +2559,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= { const char *r0 = REG(0); const char *r1 = REG(1); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "8,0xff00,%s,&,>>,%s,=," "8,0x00ff,%s,&,<<,%s,|=," "0x8000,%s,&,?{," @@ -2569,11 +2569,11 @@ r6,r5,r4,3,sp,[*],12,sp,+= break; } case ARM_INS_TBB: - r_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,DUP,[1],1,SWAP,<<,+,pc,+=", + rz_strbuf_appendf (&op->esil, "%s,%s,+,0xffffffff,&,DUP,[1],1,SWAP,<<,+,pc,+=", MEMBASE (0), MEMINDEX (0)); break; case ARM_INS_TBH: - r_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[2],1,SWAP,<<,pc,+=", + rz_strbuf_appendf (&op->esil, "%s,%d,%s,<<,+,0xffffffff,&,[2],1,SWAP,<<,pc,+=", MEMBASE (0), LSHIFT2 (0), MEMINDEX (0)); break; default: @@ -2584,7 +2584,7 @@ r6,r5,r4,3,sp,[*],12,sp,+= if (insn->detail->arm.update_flags) { switch(insn->id) { case ARM_INS_CMP: - r_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:=,32,$b,!,cf,:=,31,$o,vf,:="); + rz_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:=,32,$b,!,cf,:=,31,$o,vf,:="); break; case ARM_INS_ADD: case ARM_INS_RSB: @@ -2592,14 +2592,14 @@ r6,r5,r4,3,sp,[*],12,sp,+= case ARM_INS_SBC: case ARM_INS_ADC: case ARM_INS_CMN: - r_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:=,31,$c,cf,:=,31,$o,vf,:="); + rz_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:=,31,$c,cf,:=,31,$o,vf,:="); break; default: - r_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:="); + rz_strbuf_appendf (&op->esil, ",$z,zf,:=,31,$s,nf,:="); } } - r_strbuf_append (&op->esil, postfix); + rz_strbuf_append (&op->esil, postfix); return 0; } @@ -2628,7 +2628,7 @@ static int cond_cs2r2(int cc) { return cc; } -static void anop64(csh handle, RAnalOp *op, cs_insn *insn) { +static void anop64(csh handle, RzAnalOp *op, cs_insn *insn) { ut64 addr = op->addr; /* grab family */ @@ -3031,7 +3031,7 @@ static void anop64(csh handle, RAnalOp *op, cs_insn *insn) { } static void anal_itblock(cs_insn *insn) { - size_t i, size = r_str_nlen (insn->mnemonic, 5); + size_t i, size = rz_str_nlen (insn->mnemonic, 5); ht_uu_update (ht_itblock, insn->address, size); for (i = 1; i < size; i++) { switch (insn->mnemonic[i]) { @@ -3060,7 +3060,7 @@ static void check_itblock(cs_insn *insn) { } } -static void anop32(RAnal *a, csh handle, RAnalOp *op, cs_insn *insn, bool thumb, const ut8 *buf, int len) { +static void anop32(RzAnal *a, csh handle, RzAnalOp *op, cs_insn *insn, bool thumb, const ut8 *buf, int len) { const ut64 addr = op->addr; const int pcdelta = thumb? 4: 8; int i; @@ -3112,13 +3112,13 @@ jmp $$ + 4 + ( [delta] * 2 ) op->type = R_ANAL_OP_TYPE_UJMP; op->cycles = 2; op->ptrsize = 2; - op->ireg = r_str_get (cs_reg_name (handle, INSOP (0).mem.index)); + op->ireg = rz_str_get (cs_reg_name (handle, INSOP (0).mem.index)); break; case ARM_INS_TBB: // byte jump table op->type = R_ANAL_OP_TYPE_UJMP; op->cycles = 2; op->ptrsize = 1; - op->ireg = r_str_get (cs_reg_name (handle, INSOP (0).mem.index)); + op->ireg = rz_str_get (cs_reg_name (handle, INSOP (0).mem.index)); break; case ARM_INS_PLD: op->type = R_ANAL_OP_TYPE_LEA; // not really a lea, just a prefetch @@ -3199,7 +3199,7 @@ jmp $$ + 4 + ( [delta] * 2 ) op->jump = ((addr & ~3LL) + (thumb? 4: 8) + MEMDISP(1)) & UT64_MAX; op->ptr = (addr & ~3LL) + (thumb? 4: 8) + MEMDISP(1); op->refptr = 4; - op->reg = r_str_get (cs_reg_name (handle, INSOP (2).reg)); + op->reg = rz_str_get (cs_reg_name (handle, INSOP (2).reg)); break; } } @@ -3290,7 +3290,7 @@ jmp $$ + 4 + ( [delta] * 2 ) if (ISIMM(1)) { op->ptr = IMM(1); } - op->reg = r_str_get (cs_reg_name (handle, INSOP (0).reg)); + op->reg = rz_str_get (cs_reg_name (handle, INSOP (0).reg)); /* fall-thru */ case ARM_INS_VCMP: op->type = R_ANAL_OP_TYPE_CMP; @@ -3398,7 +3398,7 @@ jmp $$ + 4 + ( [delta] * 2 ) op->type = R_ANAL_OP_TYPE_UCJMP; op->fail = addr+op->size; op->jump = ((addr & ~3LL) + (thumb? 4: 8) + MEMDISP(1)) & UT64_MAX; - op->ireg = r_str_get (cs_reg_name (handle, INSOP (1).mem.index)); + op->ireg = rz_str_get (cs_reg_name (handle, INSOP (1).mem.index)); break; } } @@ -3420,7 +3420,7 @@ jmp $$ + 4 + ( [delta] * 2 ) op->fail = addr + op->size; op->hint.new_bits = (a->bits == 32)? 16 : 32; //switch instruction set always with blx label - // r_anal_hint_set_bits (a, op->jump, a->bits == 32? 16 : 32); + // rz_anal_hint_set_bits (a, op->jump, a->bits == 32? 16 : 32); } break; case ARM_INS_BL: @@ -3519,8 +3519,8 @@ jmp $$ + 4 + ( [delta] * 2 ) if (found) { insn->detail->arm.cc = itcond; insn->detail->arm.update_flags = 0; - op->mnemonic = r_str_newf ("%s%s%s%s", - r_anal_optype_to_string (op->type), + op->mnemonic = rz_str_newf ("%s%s%s%s", + rz_anal_optype_to_string (op->type), cc_name (itcond), insn->op_str[0]?" ":"", insn->op_str); @@ -3532,7 +3532,7 @@ static bool is_valid(arm_reg reg) { return reg != ARM_REG_INVALID; } -static int parse_reg_name(RRegItem *reg_base, RRegItem *reg_delta, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg_base, RzRegItem *reg_delta, csh handle, cs_insn *insn, int reg_num) { cs_arm_op armop = INSOP (reg_num); switch (armop.type) { case ARM_OP_REG: @@ -3568,7 +3568,7 @@ static char *reg_list[] = { "x30" }; -static int parse_reg64_name(RRegItem *reg_base, RRegItem *reg_delta, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg64_name(RzRegItem *reg_base, RzRegItem *reg_delta, csh handle, cs_insn *insn, int reg_num) { cs_arm64_op armop = INSOP64 (reg_num); switch (armop.type) { case ARM64_OP_REG: @@ -3593,7 +3593,7 @@ static int parse_reg64_name(RRegItem *reg_base, RRegItem *reg_delta, csh handle, return 0; } -static void set_opdir(RAnalOp *op) { +static void set_opdir(RzAnalOp *op) { switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: op->direction = R_ANAL_OP_DIR_READ; @@ -3615,7 +3615,7 @@ static void set_opdir(RAnalOp *op) { } } -static void set_src_dst(RAnalValue *val, csh *handle, cs_insn *insn, int x, int bits) { +static void set_src_dst(RzAnalValue *val, csh *handle, cs_insn *insn, int x, int bits) { cs_arm_op armop = INSOP (x); cs_arm64_op arm64op = INSOP64 (x); if (bits == 64) { @@ -3648,11 +3648,11 @@ static void set_src_dst(RAnalValue *val, csh *handle, cs_insn *insn, int x, int val->reg = &base_regs[x]; } -static void create_src_dst(RAnalOp *op) { - op->src[0] = r_anal_value_new (); - op->src[1] = r_anal_value_new (); - op->src[2] = r_anal_value_new (); - op->dst = r_anal_value_new (); +static void create_src_dst(RzAnalOp *op) { + op->src[0] = rz_anal_value_new (); + op->src[1] = rz_anal_value_new (); + op->src[2] = rz_anal_value_new (); + op->dst = rz_anal_value_new (); ZERO_FILL (base_regs[0]); ZERO_FILL (base_regs[1]); ZERO_FILL (base_regs[2]); @@ -3663,7 +3663,7 @@ static void create_src_dst(RAnalOp *op) { ZERO_FILL (regdelta_regs[3]); } -static void op_fillval(RAnalOp *op , csh handle, cs_insn *insn, int bits) { +static void op_fillval(RzAnalOp *op , csh handle, cs_insn *insn, int bits) { create_src_dst (op); switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_MOV: @@ -3699,14 +3699,14 @@ static void op_fillval(RAnalOp *op , csh handle, cs_insn *insn, int bits) { break; } if ((bits == 64) && HASMEMINDEX64 (1)) { - op->ireg = r_str_get (cs_reg_name (handle, INSOP64 (1).mem.index)); + op->ireg = rz_str_get (cs_reg_name (handle, INSOP64 (1).mem.index)); } else if (HASMEMINDEX (1)) { - op->ireg = r_str_get (cs_reg_name (handle, INSOP (1).mem.index)); + op->ireg = rz_str_get (cs_reg_name (handle, INSOP (1).mem.index)); op->scale = INSOP (1).mem.scale; } } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static csh handle = 0; static int omode = -1; static int obits = 32; @@ -3749,7 +3749,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn } } else { if (mask & R_ANAL_OP_MASK_DISASM) { - op->mnemonic = r_str_newf ("%s%s%s", + op->mnemonic = rz_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]?" ":"", insn->op_str); @@ -3785,7 +3785,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p; if (anal->bits == 64) { p = \ @@ -4172,7 +4172,7 @@ static char *get_reg_profile(RAnal *anal) { return strdup (p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { if (q == R_ANAL_ARCHINFO_DATA_ALIGN) { return 4; } @@ -4194,22 +4194,22 @@ static int archinfo(RAnal *anal, int q) { return 4; // XXX } -static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { - RAnalOp *op = NULL; +static ut8 *anal_mask(RzAnal *anal, int size, const ut8 *data, ut64 at) { + RzAnalOp *op = NULL; ut8 *ret = NULL; int oplen, idx = 0, obits = anal->bits; - RAnalHint *hint = NULL; + RzAnalHint *hint = NULL; if (!data) { return NULL; } - op = r_anal_op_new (); + op = rz_anal_op_new (); ret = malloc (size); memset (ret, 0xff, size); while (idx < size) { - hint = r_anal_hint_get (anal, at + idx); + hint = rz_anal_hint_get (anal, at + idx); if (hint) { if (hint->bits != 0) { anal->bits = hint->bits; @@ -4224,7 +4224,7 @@ static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { if ((oplen * 8) > size - idx) { break; } - ut32 opcode = r_read_ble (data + idx, anal->big_endian, oplen * 8); + ut32 opcode = rz_read_ble (data + idx, anal->big_endian, oplen * 8); switch (oplen) { case 2: memcpy (ret + idx, "\xf0\x00", 2); @@ -4256,7 +4256,7 @@ static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { case ARM64_INS_STXR: case ARM64_INS_STXRB: case ARM64_INS_STXRH: - r_write_ble (ret + idx, 0xffffffff, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xffffffff, anal->big_endian, 32); break; case ARM64_INS_STRB: case ARM64_INS_STURB: @@ -4275,9 +4275,9 @@ static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { case ARM64_INS_LDRSH: { bool is_literal = (opcode & 0x38000000) == 0x18000000; if (is_literal) { - r_write_ble (ret + idx, 0xff000000, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xff000000, anal->big_endian, 32); } else { - r_write_ble (ret + idx, 0xffffffff, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xffffffff, anal->big_endian, 32); } break; } @@ -4286,24 +4286,24 @@ static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { case ARM64_INS_CBZ: case ARM64_INS_CBNZ: if (op->type == R_ANAL_OP_TYPE_CJMP) { - r_write_ble (ret + idx, 0xff00001f, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xff00001f, anal->big_endian, 32); } else { - r_write_ble (ret + idx, 0xfc000000, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xfc000000, anal->big_endian, 32); } break; case ARM64_INS_TBZ: case ARM64_INS_TBNZ: - r_write_ble (ret + idx, 0xfff8001f, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xfff8001f, anal->big_endian, 32); break; case ARM64_INS_ADR: case ARM64_INS_ADRP: - r_write_ble (ret + idx, 0xff00001f, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xff00001f, anal->big_endian, 32); break; default: - r_write_ble (ret + idx, 0xfff00000, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xfff00000, anal->big_endian, 32); } } else { - r_write_ble (ret + idx, 0xfff00000, anal->big_endian, 32); + rz_write_ble (ret + idx, 0xfff00000, anal->big_endian, 32); } break; } @@ -4312,14 +4312,14 @@ static ut8 *anal_mask(RAnal *anal, int size, const ut8 *data, ut64 at) { } anal->bits = obits; - r_anal_op_free (op); + rz_anal_op_free (op); return ret; } -static RList *anal_preludes(RAnal *anal) { -#define KW(d,ds,m,ms) r_list_append (l, r_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) - RList *l = r_list_newf ((RListFree)r_search_keyword_free); +static RzList *anal_preludes(RzAnal *anal) { +#define KW(d,ds,m,ms) rz_list_append (l, rz_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) + RzList *l = rz_list_newf ((RzListFree)rz_search_keyword_free); switch (anal->bits) { case 16: KW ("\x00\xb5", 2, "\x0f\xff", 2); @@ -4334,7 +4334,7 @@ static RList *anal_preludes(RAnal *anal) { KW ("\x7f\x23\x03\xd5\xff", 5, NULL, 0); break; default: - r_list_free (l); + rz_list_free (l); l = NULL; } return l; @@ -4358,7 +4358,7 @@ static int fini(void* user) { return 0; } -RAnalPlugin r_anal_plugin_arm_cs = { +RzAnalPlugin rz_anal_plugin_arm_cs = { .name = "arm", .desc = "Capstone ARM analyzer", .license = "BSD", @@ -4375,9 +4375,9 @@ RAnalPlugin r_anal_plugin_arm_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_arm_cs, + .data = &rz_anal_plugin_arm_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_arm_gnu.c b/librz/anal/p/anal_arm_gnu.c similarity index 94% rename from libr/anal/p/anal_arm_gnu.c rename to librz/anal/p/anal_arm_gnu.c index 23f5bd5c90..18ef981ea4 100644 --- a/libr/anal/p/anal_arm_gnu.c +++ b/librz/anal/p/anal_arm_gnu.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2007-2013 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include /* DEPRECATE ?? */ #include "wine-arm.h" @@ -32,7 +32,7 @@ static unsigned int disarm_branch_offset(unsigned int pc, unsigned int insoff) { #define API static -static int op_thumb(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { +static int op_thumb(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len) { int op_code; ut16 *_ins = (ut16 *) data; ut16 ins = *_ins; @@ -165,7 +165,7 @@ static int op_cond(const ut8 *data) { return iconds[b]; } -static int arm_op32(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { +static int arm_op32(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len) { const ut8 *b = (ut8 *) data; ut8 ndata[4]; ut32 branch_dst_addr, i = 0; @@ -352,7 +352,7 @@ static ut64 getaddr(ut64 addr, const ut8 *d) { return addr + (4 * (d[0] + (d[1] << 8) + (d[2] << 16))); } -static int arm_op64(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *d, int len) { +static int arm_op64(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *d, int len) { if (d[3] == 0) { return -1; // invalid } @@ -401,14 +401,14 @@ static int arm_op64(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *d, int len) return op->size; } -static int arm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int arm_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { if (anal->bits == 64) { return arm_op64 (anal, op, addr, data, len); } return arm_op32 (anal, op, addr, data, len); } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { // TODO: support 64bit profile const char *p32 = "=PC r15\n" @@ -440,10 +440,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n" "gpr cpsr .32 72 0\n"; - return r_reg_set_profile_string (anal->reg, p32); + return rz_reg_set_profile_string (anal->reg, p32); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { if (q == R_ANAL_ARCHINFO_ALIGN) { if (anal && anal->bits == 16) { return 2; @@ -462,7 +462,7 @@ static int archinfo(RAnal *anal, int q) { return 4; // XXX } -RAnalPlugin r_anal_plugin_arm_gnu = { +RzAnalPlugin rz_anal_plugin_arm_gnu = { .name = "arm.gnu", .arch = "arm", .license = "LGPL3", @@ -474,9 +474,9 @@ RAnalPlugin r_anal_plugin_arm_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_arm_gnu, + .data = &rz_anal_plugin_arm_gnu, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_arm_hacks.inc b/librz/anal/p/anal_arm_hacks.inc similarity index 92% rename from libr/anal/p/anal_arm_hacks.inc rename to librz/anal/p/anal_arm_hacks.inc index ee259c3935..9fc3022352 100644 --- a/libr/anal/p/anal_arm_hacks.inc +++ b/librz/anal/p/anal_arm_hacks.inc @@ -1,5 +1,5 @@ -#include "r_anal.h" -static int hack_handle_dp_reg(ut32 insn, RAnalOp *op) { +#include "rz_anal.h" +static int hack_handle_dp_reg(ut32 insn, RzAnalOp *op) { const bool op0 = (insn >> 30) & 0x1; const bool op1 = (insn >> 28) & 0x1; const ut8 op2 = (insn >> 21) & 0xf; @@ -34,7 +34,7 @@ static int hack_handle_dp_reg(ut32 insn, RAnalOp *op) { return -1; } -static int hack_handle_ldst(ut32 insn, RAnalOp *op) { +static int hack_handle_ldst(ut32 insn, RzAnalOp *op) { const ut8 op0 = (insn >> 28) & 0xf; const bool op1 = (insn >> 26) & 0x1; ut8 op2 = (insn >> 23) & 0x3; @@ -97,7 +97,7 @@ static int hack_handle_ldst(ut32 insn, RAnalOp *op) { return -1; } -static int hack_handle_dp_imm(ut32 insn, RAnalOp *op) { +static int hack_handle_dp_imm(ut32 insn, RzAnalOp *op) { const ut8 op0 = (insn >> 23) & 0x7; // Add/subtract (immediate, with tags) @@ -120,7 +120,7 @@ static int hack_handle_dp_imm(ut32 insn, RAnalOp *op) { return -1; } -static int hack_handle_br_exc_sys(ut32 insn, RAnalOp *op) { +static int hack_handle_br_exc_sys(ut32 insn, RzAnalOp *op) { const ut8 op0 = (insn >> 29) & 0x7; const ut16 op1 = (insn >> 12) & 0x3fff; ut8 op2 = insn & 0x1f; @@ -143,7 +143,7 @@ static int hack_handle_br_exc_sys(ut32 insn, RAnalOp *op) { return -1; } -static inline int hackyArmAnal(RAnal *a, RAnalOp *op, const ut8 *buf, int len) { +static inline int hackyArmAnal(RzAnal *a, RzAnalOp *op, const ut8 *buf, int len) { int ret = -1; // Hacky support for ARMv8.3 and ARMv8.5 if (a->bits == 64 && len >= 4) { diff --git a/libr/anal/p/anal_avr.c b/librz/anal/p/anal_avr.c similarity index 91% rename from libr/anal/p/anal_avr.c rename to librz/anal/p/anal_avr.c index 9ebe3480d8..0616d13da6 100644 --- a/libr/anal/p/anal_avr.c +++ b/librz/anal/p/anal_avr.c @@ -6,12 +6,12 @@ https://en.wikipedia.org/wiki/Atmel_AVR_instruction_set #endif #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include static RDESContext desctx; @@ -34,7 +34,7 @@ typedef struct _cpu_model_tag { CPU_CONST *consts[10]; } CPU_MODEL; -typedef void (*inst_handler_t) (RAnal *anal, RAnalOp *op, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu); +typedef void (*inst_handler_t) (RzAnal *anal, RzAnalOp *op, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu); typedef struct _opcodes_tag_ { const char *const name; @@ -46,7 +46,7 @@ typedef struct _opcodes_tag_ { ut64 type; } OPCODE_DESC; -static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu); +static OPCODE_DESC* avr_op_analyze(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu); #define CPU_MODEL_DECL(model, pc, consts) \ { \ @@ -58,7 +58,7 @@ static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut #define CPU_PC_MASK(cpu) MASK((cpu)->pc) #define CPU_PC_SIZE(cpu) ((((cpu)->pc) >> 3) + ((((cpu)->pc) & 0x07) ? 1 : 0)) -#define INST_HANDLER(OPCODE_NAME) static void _inst__ ## OPCODE_NAME (RAnal *anal, RAnalOp *op, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu) +#define INST_HANDLER(OPCODE_NAME) static void _inst__ ## OPCODE_NAME (RzAnal *anal, RzAnalOp *op, const ut8 *buf, int len, int *fail, CPU_MODEL *cpu) #define INST_DECL(OP, M, SL, C, SZ, T) { #OP, (M), (SL), _inst__ ## OP, (C), (SZ), R_ANAL_OP_TYPE_ ## T } #define INST_LAST { "unknown", 0, 0, (void *) 0, 2, 1, R_ANAL_OP_TYPE_UNK } @@ -66,9 +66,9 @@ static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut #define INST_INVALID { *fail = 1; return; } #define INST_ASSERT(x) { if (!(x)) { INST_INVALID; } } -#define ESIL_A(e, ...) r_strbuf_appendf (&op->esil, e, ##__VA_ARGS__) +#define ESIL_A(e, ...) rz_strbuf_appendf (&op->esil, e, ##__VA_ARGS__) -#define STR_BEGINS(in, s) r_str_ncasecmp (in, s, strlen (s)) +#define STR_BEGINS(in, s) rz_str_ncasecmp (in, s, strlen (s)) // Following IO definitions are valid for: // ATmega8 @@ -157,7 +157,7 @@ static CPU_MODEL *__get_cpu_model_recursive(char *model) { CPU_MODEL *cpu = NULL; for (cpu = cpu_models; cpu < cpu_models + ((sizeof (cpu_models) / sizeof (CPU_MODEL))) - 1; cpu++) { - if (!r_str_casecmp (model, cpu->model)) { + if (!rz_str_casecmp (model, cpu->model)) { break; } } @@ -176,7 +176,7 @@ static CPU_MODEL *__get_cpu_model_recursive(char *model) { static CPU_MODEL *get_cpu_model(char *model) { static CPU_MODEL *cpu = NULL; // cached value? - if (cpu && !r_str_casecmp (model, cpu->model)) { + if (cpu && !rz_str_casecmp (model, cpu->model)) { return cpu; } // do the real search @@ -207,9 +207,9 @@ static CPU_CONST *const_by_name(CPU_MODEL *cpu, int type, char *c) { return NULL; } -static int __esil_pop_argument(RAnalEsil *esil, ut64 *v) { - char *t = r_anal_esil_pop (esil); - if (!t || !r_anal_esil_get_parm (esil, t, v)) { +static int __esil_pop_argument(RzAnalEsil *esil, ut64 *v) { + char *t = rz_anal_esil_pop (esil); + if (!t || !rz_anal_esil_get_parm (esil, t, v)) { free (t); return false; } @@ -235,21 +235,21 @@ static CPU_CONST *const_by_value(CPU_MODEL *cpu, int type, ut32 v) { } static RStrBuf *__generic_io_dest(ut8 port, int write, CPU_MODEL *cpu) { - RStrBuf *r = r_strbuf_new (""); + RStrBuf *r = rz_strbuf_new (""); CPU_CONST *c = const_by_value (cpu, CPU_CONST_REG, port); if (c != NULL) { - r_strbuf_set (r, c->key); + rz_strbuf_set (r, c->key); if (write) { - r_strbuf_append (r, ",="); + rz_strbuf_append (r, ",="); } } else { - r_strbuf_setf (r, "_io,%d,+,%s[1]", port, write ? "=" : ""); + rz_strbuf_setf (r, "_io,%d,+,%s[1]", port, write ? "=" : ""); } return r; } -static void __generic_ld_st(RAnalOp *op, char *mem, char ireg, int use_ramp, int prepostdec, int offset, int st) { +static void __generic_ld_st(RzAnalOp *op, char *mem, char ireg, int use_ramp, int prepostdec, int offset, int st) { if (ireg) { // preincrement index register if (prepostdec < 0) { @@ -277,7 +277,7 @@ static void __generic_ld_st(RAnalOp *op, char *mem, char ireg, int use_ramp, int } } -static void __generic_pop(RAnalOp *op, int sz) { +static void __generic_pop(RzAnalOp *op, int sz) { if (sz > 1) { ESIL_A ("1,sp,+,_ram,+,"); // calc SRAM(sp+1) ESIL_A ("[%d],", sz); // read value @@ -288,7 +288,7 @@ static void __generic_pop(RAnalOp *op, int sz) { } } -static void __generic_push(RAnalOp *op, int sz) { +static void __generic_push(RzAnalOp *op, int sz) { ESIL_A ("sp,_ram,+,"); // calc pointer SRAM(sp) if (sz > 1) { ESIL_A ("-%d,+,", sz - 1); // dec SP by 'sz' @@ -501,12 +501,12 @@ INST_HANDLER (cbi) { // CBI A, b // read port a and clear bit b io_port = __generic_io_dest (a, 0, cpu); ESIL_A ("0xff,%d,1,<<,^,%s,&,", b, io_port); - r_strbuf_free (io_port); + rz_strbuf_free (io_port); // write result to port a io_port = __generic_io_dest (a, 1, cpu); - ESIL_A ("%s,", r_strbuf_get (io_port)); - r_strbuf_free (io_port); + ESIL_A ("%s,", rz_strbuf_get (io_port)); + rz_strbuf_free (io_port); } INST_HANDLER (com) { // COM Rd @@ -571,7 +571,7 @@ INST_HANDLER (cpse) { // CPSE Rd, Rr } int r = (buf[0] & 0xf) | ((buf[1] & 0x2) << 3); int d = ((buf[0] >> 4) & 0xf) | ((buf[1] & 0x1) << 4); - RAnalOp next_op = {0}; + RzAnalOp next_op = {0}; // calculate next instruction size (call recursively avr_op_analyze) // and free next_op's esil string (we dont need it now) @@ -579,7 +579,7 @@ INST_HANDLER (cpse) { // CPSE Rd, Rr &next_op, op->addr + op->size, buf + op->size, len - op->size, cpu); - r_strbuf_fini (&next_op.esil); + rz_strbuf_fini (&next_op.esil); op->jump = op->addr + next_op.size + 2; op->fail = op->addr + 2; @@ -610,15 +610,15 @@ INST_HANDLER (des) { // DES k if (desctx.round < 16) { //DES op->type = R_ANAL_OP_TYPE_CRYPTO; op->cycles = 1; //redo this - r_strbuf_setf (&op->esil, "%d,des", desctx.round); + rz_strbuf_setf (&op->esil, "%d,des", desctx.round); } } INST_HANDLER (eijmp) { // EIJMP ut64 z, eind; // read z and eind for calculating jump address on runtime - r_anal_esil_reg_read (anal->esil, "z", &z, NULL); - r_anal_esil_reg_read (anal->esil, "eind", &eind, NULL); + rz_anal_esil_reg_read (anal->esil, "z", &z, NULL); + rz_anal_esil_reg_read (anal->esil, "eind", &eind, NULL); // real target address may change during execution, so this value will // be changing all the time op->jump = ((eind << 16) + z) << 1; @@ -713,7 +713,7 @@ INST_HANDLER (fmulsu) { // FMULSU Rd, Rr INST_HANDLER (ijmp) { // IJMP k ut64 z; // read z for calculating jump address on runtime - r_anal_esil_reg_read (anal->esil, "z", &z, NULL); + rz_anal_esil_reg_read (anal->esil, "z", &z, NULL); // real target address may change during execution, so this value will // be changing all the time op->jump = z << 1; @@ -745,8 +745,8 @@ INST_HANDLER (in) { // IN Rd, A op->type2 = 0; op->val = a; op->family = R_ANAL_OP_FAMILY_IO; - ESIL_A ("%s,r%d,=,", r_strbuf_get (io_src), r); - r_strbuf_free (io_src); + ESIL_A ("%s,r%d,=,", rz_strbuf_get (io_src), r); + rz_strbuf_free (io_src); } INST_HANDLER (inc) { // INC Rd @@ -1093,8 +1093,8 @@ INST_HANDLER (out) { // OUT A, Rr op->type2 = 1; op->val = a; op->family = R_ANAL_OP_FAMILY_IO; - ESIL_A ("r%d,%s,", r, r_strbuf_get (io_dst)); - r_strbuf_free (io_dst); + ESIL_A ("r%d,%s,", r, rz_strbuf_get (io_dst)); + rz_strbuf_free (io_dst); } INST_HANDLER (pop) { // POP Rd @@ -1136,7 +1136,7 @@ INST_HANDLER (rcall) { // RCALL k __generic_push (op, CPU_PC_SIZE (cpu)); // push @ret addr ESIL_A ("%"PFMT64d",pc,=,", op->jump); // jump! // cycles - if (!r_str_ncasecmp (cpu->model, "ATtiny", 6)) { + if (!rz_str_ncasecmp (cpu->model, "ATtiny", 6)) { op->cycles = 4; // ATtiny is always slow } else { // PC size decides required runtime! @@ -1276,12 +1276,12 @@ INST_HANDLER (sbi) { // SBI A, b // read port a and clear bit b io_port = __generic_io_dest (a, 0, cpu); ESIL_A ("0xff,%d,1,<<,|,%s,&,", b, io_port); - r_strbuf_free (io_port); + rz_strbuf_free (io_port); // write result to port a io_port = __generic_io_dest (a, 1, cpu); - ESIL_A ("%s,", r_strbuf_get (io_port)); - r_strbuf_free (io_port); + ESIL_A ("%s,", rz_strbuf_get (io_port)); + rz_strbuf_free (io_port); } INST_HANDLER (sbix) { // SBIC A, b @@ -1291,7 +1291,7 @@ INST_HANDLER (sbix) { // SBIC A, b } int a = (buf[0] >> 3) & 0x1f; int b = buf[0] & 0x07; - RAnalOp next_op = { 0 }; + RzAnalOp next_op = { 0 }; RStrBuf *io_port; op->type2 = 0; @@ -1305,7 +1305,7 @@ INST_HANDLER (sbix) { // SBIC A, b op->addr + op->size, buf + op->size, len - op->size, cpu); - r_strbuf_fini (&next_op.esil); + rz_strbuf_fini (&next_op.esil); op->jump = op->addr + next_op.size + 2; op->fail = op->addr + op->size; @@ -1323,7 +1323,7 @@ INST_HANDLER (sbix) { // SBIC A, b ? "!," // SBIC => branch if 0 : "!,!,"); // SBIS => branch if 1 ESIL_A ("?{,%"PFMT64d",pc,=,},", op->jump); // ?true => jmp - r_strbuf_free (io_port); + rz_strbuf_free (io_port); } INST_HANDLER (sbiw) { // SBIW Rd+1:Rd, K @@ -1348,7 +1348,7 @@ INST_HANDLER (sbrx) { // SBRC Rr, b } int b = buf[0] & 0x7; int r = ((buf[0] >> 4) & 0xf) | ((buf[1] & 0x01) << 4); - RAnalOp next_op = {0}; + RzAnalOp next_op = {0}; // calculate next instruction size (call recursively avr_op_analyze) // and free next_op's esil string (we dont need it now) @@ -1356,7 +1356,7 @@ INST_HANDLER (sbrx) { // SBRC Rr, b &next_op, op->addr + op->size, buf + op->size, len - op->size, cpu); - r_strbuf_fini (&next_op.esil); + rz_strbuf_fini (&next_op.esil); op->jump = op->addr + next_op.size + 2; op->fail = op->addr + 2; @@ -1381,7 +1381,7 @@ INST_HANDLER (spm) { // SPM Z+ ut64 spmcsr; // read SPM Control Register (SPMCR) - r_anal_esil_reg_read (anal->esil, "spmcsr", &spmcsr, NULL); + rz_anal_esil_reg_read (anal->esil, "spmcsr", &spmcsr, NULL); // clear SPMCSR ESIL_A ("0x7c,spmcsr,&=,"); @@ -1595,7 +1595,7 @@ OPCODE_DESC opcodes[] = { INST_LAST }; -static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu) { +static OPCODE_DESC* avr_op_analyze(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, CPU_MODEL *cpu) { OPCODE_DESC *opcode_desc; if (len < 2) { return NULL; @@ -1619,7 +1619,7 @@ static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut op->addr = addr; // start void esil expression - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); // handle opcode opcode_desc->handler (anal, op, buf, len, &fail, cpu); @@ -1633,7 +1633,7 @@ static OPCODE_DESC* avr_op_analyze(RAnal *anal, RAnalOp *op, ut64 addr, const ut op->nopcode = (op->type == R_ANAL_OP_TYPE_UNK); // remove trailing coma (COMETE LA COMA) - t = r_strbuf_get (&op->esil); + t = rz_strbuf_get (&op->esil); if (t && strlen (t) > 1) { t += strlen (t) - 1; if (*t == ',') { @@ -1661,12 +1661,12 @@ INVALID_OP: op->size = 2; // launch esil trap (for communicating upper layers about this weird // and stinky situation - r_strbuf_set (&op->esil, "1,$"); + rz_strbuf_set (&op->esil, "1,$"); return NULL; } -static int avr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int avr_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { CPU_MODEL *cpu; ut64 offset; @@ -1681,19 +1681,19 @@ static int avr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, // set memory layout registers if (anal->esil) { offset = 0; - r_anal_esil_reg_write (anal->esil, "_prog", offset); + rz_anal_esil_reg_write (anal->esil, "_prog", offset); offset += (1 << cpu->pc); - r_anal_esil_reg_write (anal->esil, "_io", offset); + rz_anal_esil_reg_write (anal->esil, "_io", offset); offset += const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "sram_start")); - r_anal_esil_reg_write (anal->esil, "_sram", offset); + rz_anal_esil_reg_write (anal->esil, "_sram", offset); offset += const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "sram_size")); - r_anal_esil_reg_write (anal->esil, "_eeprom", offset); + rz_anal_esil_reg_write (anal->esil, "_eeprom", offset); offset += const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "eeprom_size")); - r_anal_esil_reg_write (anal->esil, "_page", offset); + rz_anal_esil_reg_write (anal->esil, "_page", offset); } // process opcode avr_op_analyze (anal, op, addr, buf, len, cpu); @@ -1701,7 +1701,7 @@ static int avr_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, return op->size; } -static bool avr_custom_des (RAnalEsil *esil) { +static bool avr_custom_des (RzAnalEsil *esil) { ut64 key, encrypt, text,des_round; ut32 key_lo, key_hi, buf_lo, buf_hi; if (!esil || !esil->anal || !esil->anal->reg) { @@ -1710,9 +1710,9 @@ static bool avr_custom_des (RAnalEsil *esil) { if (!__esil_pop_argument (esil, &des_round)) { return false; } - r_anal_esil_reg_read (esil, "hf", &encrypt, NULL); - r_anal_esil_reg_read (esil, "deskey", &key, NULL); - r_anal_esil_reg_read (esil, "text", &text, NULL); + rz_anal_esil_reg_read (esil, "hf", &encrypt, NULL); + rz_anal_esil_reg_read (esil, "deskey", &key, NULL); + rz_anal_esil_reg_read (esil, "text", &text, NULL); key_lo = key & UT32_MAX; key_hi = key >> 32; @@ -1726,32 +1726,32 @@ static bool avr_custom_des (RAnalEsil *esil) { if (!desctx.round) { int i; //generating all round keys - r_des_permute_key (&key_lo, &key_hi); + rz_des_permute_key (&key_lo, &key_hi); for (i = 0; i < 16; i++) { - r_des_round_key (i, &desctx.round_key_lo[i], &desctx.round_key_hi[i], &key_lo, &key_hi); + rz_des_round_key (i, &desctx.round_key_lo[i], &desctx.round_key_hi[i], &key_lo, &key_hi); } - r_des_permute_block0 (&buf_lo, &buf_hi); + rz_des_permute_block0 (&buf_lo, &buf_hi); } if (encrypt) { - r_des_round (&buf_lo, &buf_hi, &desctx.round_key_lo[desctx.round], &desctx.round_key_hi[desctx.round]); + rz_des_round (&buf_lo, &buf_hi, &desctx.round_key_lo[desctx.round], &desctx.round_key_hi[desctx.round]); } else { - r_des_round (&buf_lo, &buf_hi, &desctx.round_key_lo[15 - desctx.round], &desctx.round_key_hi[15 - desctx.round]); + rz_des_round (&buf_lo, &buf_hi, &desctx.round_key_lo[15 - desctx.round], &desctx.round_key_hi[15 - desctx.round]); } if (desctx.round == 15) { - r_des_permute_block1 (&buf_hi, &buf_lo); + rz_des_permute_block1 (&buf_hi, &buf_lo); desctx.round = 0; } else { desctx.round++; } - r_anal_esil_reg_write (esil, "text", text); + rz_anal_esil_reg_write (esil, "text", text); return true; } // ESIL operation SPM_PAGE_ERASE -static bool avr_custom_spm_page_erase(RAnalEsil *esil) { +static bool avr_custom_spm_page_erase(RzAnalEsil *esil) { CPU_MODEL *cpu; ut8 c; ut64 addr, page_size_bits, i; @@ -1777,7 +1777,7 @@ static bool avr_custom_spm_page_erase(RAnalEsil *esil) { //eprintf ("SPM_PAGE_ERASE %ld bytes @ 0x%08" PFMT64x ".\n", page_size, addr); c = 0xff; for (i = 0; i < (1ULL << page_size_bits); i++) { - r_anal_esil_mem_write ( + rz_anal_esil_mem_write ( esil, (addr + i) & CPU_PC_MASK (cpu), &c, 1); } @@ -1785,7 +1785,7 @@ static bool avr_custom_spm_page_erase(RAnalEsil *esil) { } // ESIL operation SPM_PAGE_FILL -static bool avr_custom_spm_page_fill(RAnalEsil *esil) { +static bool avr_custom_spm_page_fill(RzAnalEsil *esil) { CPU_MODEL *cpu; ut64 addr, page_size_bits, i; ut8 r0, r1; @@ -1819,14 +1819,14 @@ static bool avr_custom_spm_page_fill(RAnalEsil *esil) { // perform write to temporary page //eprintf ("SPM_PAGE_FILL bytes (%02x, %02x) @ 0x%08" PFMT64x ".\n", r1, r0, addr); - r_anal_esil_mem_write (esil, addr++, &r0, 1); - r_anal_esil_mem_write (esil, addr++, &r1, 1); + rz_anal_esil_mem_write (esil, addr++, &r0, 1); + rz_anal_esil_mem_write (esil, addr++, &r1, 1); return true; } // ESIL operation SPM_PAGE_WRITE -static bool avr_custom_spm_page_write(RAnalEsil *esil) { +static bool avr_custom_spm_page_write(RzAnalEsil *esil) { CPU_MODEL *cpu; char *t = NULL; ut64 addr, page_size_bits, tmp_page; @@ -1845,7 +1845,7 @@ static bool avr_custom_spm_page_write(RAnalEsil *esil) { // of the internal temporary page cpu = get_cpu_model (esil->anal->cpu); page_size_bits = const_get_value (const_by_name (cpu, CPU_CONST_PARAM, "page_size")); - r_anal_esil_reg_read (esil, "_page", &tmp_page, NULL); + rz_anal_esil_reg_read (esil, "_page", &tmp_page, NULL); // align base address to page_size_bits addr &= (~(MASK (page_size_bits)) & CPU_PC_MASK (cpu)); @@ -1856,13 +1856,13 @@ static bool avr_custom_spm_page_write(RAnalEsil *esil) { eprintf ("Cannot alloc a buffer for copying the temporary page.\n"); return false; } - r_anal_esil_mem_read (esil, tmp_page, (ut8 *) t, 1 << page_size_bits); - r_anal_esil_mem_write (esil, addr, (ut8 *) t, 1 << page_size_bits); + rz_anal_esil_mem_read (esil, tmp_page, (ut8 *) t, 1 << page_size_bits); + rz_anal_esil_mem_write (esil, addr, (ut8 *) t, 1 << page_size_bits); return true; } -static int esil_avr_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { +static int esil_avr_hook_reg_write(RzAnalEsil *esil, const char *name, ut64 *val) { CPU_MODEL *cpu; if (!esil || !esil->anal) { @@ -1888,25 +1888,25 @@ static int esil_avr_hook_reg_write(RAnalEsil *esil, const char *name, ut64 *val) return 0; } -static int esil_avr_init(RAnalEsil *esil) { +static int esil_avr_init(RzAnalEsil *esil) { if (!esil) { return false; } desctx.round = 0; - r_anal_esil_set_op (esil, "des", avr_custom_des, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); //better meta info plz - r_anal_esil_set_op (esil, "SPM_PAGE_ERASE", avr_custom_spm_page_erase, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); - r_anal_esil_set_op (esil, "SPM_PAGE_FILL", avr_custom_spm_page_fill, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); - r_anal_esil_set_op (esil, "SPM_PAGE_WRITE", avr_custom_spm_page_write, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); + rz_anal_esil_set_op (esil, "des", avr_custom_des, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); //better meta info plz + rz_anal_esil_set_op (esil, "SPM_PAGE_ERASE", avr_custom_spm_page_erase, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); + rz_anal_esil_set_op (esil, "SPM_PAGE_FILL", avr_custom_spm_page_fill, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); + rz_anal_esil_set_op (esil, "SPM_PAGE_WRITE", avr_custom_spm_page_write, 0, 0, R_ANAL_ESIL_OP_TYPE_CUSTOM); esil->cb.hook_reg_write = esil_avr_hook_reg_write; return true; } -static int esil_avr_fini(RAnalEsil *esil) { +static int esil_avr_fini(RzAnalEsil *esil) { return true; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pcl\n" "=SP sp\n" @@ -1964,11 +1964,11 @@ RAMPX, RAMPY, RAMPZ, RAMPD and EIND: "gpr r1_r0 .16 0 0\n" //this is a hack for mul "gpr r17_r16 .16 16 0\n" "gpr r19_r18 .16 18 0\n" - "gpr r21_r20 .16 20 0\n" - "gpr r23_r22 .16 22 0\n" - "gpr r25_r24 .16 24 0\n" - "gpr r27_r26 .16 26 0\n" - "gpr r29_r28 .16 28 0\n" + "gpr r21_rz0 .16 20 0\n" + "gpr r23_rz2 .16 22 0\n" + "gpr r25_rz4 .16 24 0\n" + "gpr r27_rz6 .16 26 0\n" + "gpr r29_rz8 .16 28 0\n" "gpr r31_r30 .16 30 0\n" // 16 bit overlapped registers for memory addressing @@ -2029,10 +2029,10 @@ RAMPX, RAMPY, RAMPZ, RAMPD and EIND: "gpr spmcsr .8 64 0\n" ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { if (q == R_ANAL_ARCHINFO_ALIGN) { return 2; } @@ -2045,17 +2045,17 @@ static int archinfo(RAnal *anal, int q) { return 2; // XXX } -static ut8 *anal_mask_avr(RAnal *anal, int size, const ut8 *data, ut64 at) { - RAnalOp *op = NULL; +static ut8 *anal_mask_avr(RzAnal *anal, int size, const ut8 *data, ut64 at) { + RzAnalOp *op = NULL; ut8 *ret = NULL; int idx; - if (!(op = r_anal_op_new ())) { + if (!(op = rz_anal_op_new ())) { return NULL; } if (!(ret = malloc (size))) { - r_anal_op_free (op); + rz_anal_op_free (op); return NULL; } @@ -2087,12 +2087,12 @@ static ut8 *anal_mask_avr(RAnal *anal, int size, const ut8 *data, ut64 at) { } } - r_anal_op_free (op); + rz_anal_op_free (op); return ret; } -RAnalPlugin r_anal_plugin_avr = { +RzAnalPlugin rz_anal_plugin_avr = { .name = "avr", .desc = "AVR code analysis plugin", .license = "LGPL3", @@ -2108,9 +2108,9 @@ RAnalPlugin r_anal_plugin_avr = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_avr, + .data = &rz_anal_plugin_avr, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_bf.c b/librz/anal/p/anal_bf.c similarity index 70% rename from libr/anal/p/anal_bf.c rename to librz/anal/p/anal_bf.c index 15aef0bfb1..502d8bba40 100644 --- a/libr/anal/p/anal_bf.c +++ b/librz/anal/p/anal_bf.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2011-2016 - pancake */ +/* rizin - LGPL - Copyright 2011-2016 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include static size_t countChar(const ut8 *buf, int len, char ch) { int i; @@ -23,21 +23,21 @@ static int getid (char ch) { } #define BUFSIZE_INC 32 -static int bf_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int bf_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { ut64 dst = 0LL; if (!op) { return 1; } - /* Ayeeee! What's inside op? Do we have an initialized RAnalOp? Are we going to have a leak here? :-( */ - memset (op, 0, sizeof (RAnalOp)); /* We need to refactorize this. Something like r_anal_op_init would be more appropriate */ - r_strbuf_init (&op->esil); + /* Ayeeee! What's inside op? Do we have an initialized RzAnalOp? Are we going to have a leak here? :-( */ + memset (op, 0, sizeof (RzAnalOp)); /* We need to refactorize this. Something like rz_anal_op_init would be more appropriate */ + rz_strbuf_init (&op->esil); op->size = 1; op->id = getid (buf[0]); switch (buf[0]) { case '[': op->type = R_ANAL_OP_TYPE_CJMP; op->fail = addr+1; - buf = r_mem_dup ((void *)buf, len); + buf = rz_mem_dup ((void *)buf, len); if (!buf) { break; } @@ -55,7 +55,7 @@ static int bf_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, R dst = addr + (size_t)(p-buf); dst ++; op->jump = dst; - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "$$,brk,=[1],brk,++=," "ptr,[1],!,?{,0x%"PFMT64x",pc,=,brk,--=,}", dst); goto beach; @@ -85,36 +85,36 @@ beach: break; case ']': op->type = R_ANAL_OP_TYPE_UJMP; // XXX This is wrong esil - r_strbuf_set (&op->esil, "brk,--=,brk,[1],pc,="); + rz_strbuf_set (&op->esil, "brk,--=,brk,[1],pc,="); break; case '>': op->type = R_ANAL_OP_TYPE_ADD; op->size = countChar (buf, len, '>'); - r_strbuf_setf (&op->esil, "%d,ptr,+=", op->size); + rz_strbuf_setf (&op->esil, "%d,ptr,+=", op->size); break; case '<': op->type = R_ANAL_OP_TYPE_SUB; op->size = countChar (buf, len, '<'); - r_strbuf_setf (&op->esil, "%d,ptr,-=", op->size); + rz_strbuf_setf (&op->esil, "%d,ptr,-=", op->size); break; case '+': op->size = countChar (buf, len, '+'); op->type = R_ANAL_OP_TYPE_ADD; - r_strbuf_setf (&op->esil, "%d,ptr,+=[1]", op->size); + rz_strbuf_setf (&op->esil, "%d,ptr,+=[1]", op->size); break; case '-': op->type = R_ANAL_OP_TYPE_SUB; op->size = countChar (buf, len, '-'); - r_strbuf_setf (&op->esil, "%d,ptr,-=[1]", op->size); + rz_strbuf_setf (&op->esil, "%d,ptr,-=[1]", op->size); break; case '.': // print element in stack to screen op->type = R_ANAL_OP_TYPE_STORE; - r_strbuf_set (&op->esil, "ptr,[1],scr,=[1],scr,++="); + rz_strbuf_set (&op->esil, "ptr,[1],scr,=[1],scr,++="); break; case ',': op->type = R_ANAL_OP_TYPE_LOAD; - r_strbuf_set (&op->esil, "kbd,[1],ptr,=[1],kbd,++="); + rz_strbuf_set (&op->esil, "kbd,[1],ptr,=[1],kbd,++="); break; case 0x00: case 0xff: @@ -122,13 +122,13 @@ beach: break; default: op->type = R_ANAL_OP_TYPE_NOP; - r_strbuf_set (&op->esil, ","); + rz_strbuf_set (&op->esil, ","); break; } return op->size; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { return strdup ( "=PC pc\n" "=BP brk\n" @@ -145,7 +145,7 @@ static char *get_reg_profile(RAnal *anal) { ); } -RAnalPlugin r_anal_plugin_bf = { +RzAnalPlugin rz_anal_plugin_bf = { .name = "bf", .desc = "brainfuck code analysis plugin", .license = "LGPL3", @@ -157,9 +157,9 @@ RAnalPlugin r_anal_plugin_bf = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_bf, + .data = &rz_anal_plugin_bf, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_chip8.c b/librz/anal/p/anal_chip8.c similarity index 86% rename from libr/anal/p/anal_chip8.c rename to librz/anal/p/anal_chip8.c index 9b68625a8d..ee253f600a 100644 --- a/libr/anal/p/anal_chip8.c +++ b/librz/anal/p/anal_chip8.c @@ -1,13 +1,13 @@ /* radare - LGPL3 - Copyright 2017 - maijin */ #include -#include -#include -#include -#include +#include +#include +#include +#include -static int chip8_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { - ut16 opcode = r_read_be16 (data); +static int chip8_anop(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { + ut16 opcode = rz_read_be16 (data); // uint8_t x = (opcode >> 8) & 0x0F; // uint8_t y = (opcode >> 4) & 0x0F; uint8_t nibble = opcode & 0x0F; @@ -99,7 +99,7 @@ static int chip8_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int break; case 0xE000: if (kk == 0x9E || kk == 0xA1) { - r_meta_set_string (anal, R_META_TYPE_COMMENT, addr, "KEYPAD"); + rz_meta_set_string (anal, R_META_TYPE_COMMENT, addr, "KEYPAD"); op->type = R_ANAL_OP_TYPE_CJMP; op->jump = addr + op->size * 2; op->fail = addr + op->size; @@ -111,7 +111,7 @@ static int chip8_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int op->type = R_ANAL_OP_TYPE_MOV; break; case 0x0A: - r_meta_set_string (anal, R_META_TYPE_COMMENT, addr, "KEYPAD"); + rz_meta_set_string (anal, R_META_TYPE_COMMENT, addr, "KEYPAD"); op->type = R_ANAL_OP_TYPE_MOV; break; case 0x15: @@ -150,7 +150,7 @@ static int chip8_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int return op->size; } -RAnalPlugin r_anal_plugin_chip8 = { +RzAnalPlugin rz_anal_plugin_chip8 = { .name = "chip8", .desc = "CHIP8 analysis plugin", .license = "LGPL3", @@ -160,9 +160,9 @@ RAnalPlugin r_anal_plugin_chip8 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_chip8, + .data = &rz_anal_plugin_chip8, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_cr16.c b/librz/anal/p/anal_cr16.c similarity index 88% rename from libr/anal/p/anal_cr16.c rename to librz/anal/p/anal_cr16.c index e6b19a3a51..faac6b329c 100644 --- a/libr/anal/p/anal_cr16.c +++ b/librz/anal/p/anal_cr16.c @@ -2,16 +2,16 @@ 2014 - Fedor Sakharov */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -static int cr16_op(RAnal *anal, RAnalOp *op, ut64 addr, - const ut8 *buf, int len, RAnalOpMask mask) +static int cr16_op(RzAnal *anal, RzAnalOp *op, ut64 addr, + const ut8 *buf, int len, RzAnalOpMask mask) { int ret; struct cr16_cmd cmd; @@ -119,7 +119,7 @@ static int cr16_op(RAnal *anal, RAnalOp *op, ut64 addr, return ret; } -RAnalPlugin r_anal_plugin_cr16 = { +RzAnalPlugin rz_anal_plugin_cr16 = { .name = "cr16", .desc = "CR16 code analysis plugin", .license = "LGPL3", @@ -129,9 +129,9 @@ RAnalPlugin r_anal_plugin_cr16 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_cr16, + .data = &rz_anal_plugin_cr16, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_cris.c b/librz/anal/p/anal_cris.c similarity index 92% rename from libr/anal/p/anal_cris.c rename to librz/anal/p/anal_cris.c index 2b95c37e04..5c0ed789fd 100644 --- a/libr/anal/p/anal_cris.c +++ b/librz/anal/p/anal_cris.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2014-2015 - pancake */ +/* rizin - LGPL - Copyright 2014-2015 - pancake */ -#include -#include +#include +#include -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int opsize = -1; op->type = -1; opsize = 2; @@ -237,7 +237,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return opsize; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP r14\n" // XXX @@ -271,10 +271,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr r15 .32 60 0\n" // ADD P REGISTERS ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_cris = { +RzAnalPlugin rz_anal_plugin_cris = { .name = "cris", .desc = "Axis Communications 32-bit embedded processor", .license = "LGPL3", @@ -286,9 +286,9 @@ RAnalPlugin r_anal_plugin_cris = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_cris, + .data = &rz_anal_plugin_cris, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_dalvik.c b/librz/anal/p/anal_dalvik.c similarity index 97% rename from libr/anal/p/anal_dalvik.c rename to librz/anal/p/anal_dalvik.c index 56e441cbee..7e3971f9d8 100644 --- a/libr/anal/p/anal_dalvik.c +++ b/librz/anal/p/anal_dalvik.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2010-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/dalvik/opcode.h" #include "../../bin/format/dex/dex.h" @@ -44,7 +44,7 @@ static const char *getCondz(ut8 cond) { return ""; } -static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int dalvik_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { int sz = dalvik_opcodes[data[0]].len; if (!op || sz >= len) { if (op && (mask & R_ANAL_OP_MASK_DISASM)) { @@ -79,7 +79,7 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l op->type = R_ANAL_OP_TYPE_MOV; ut32 vB = (data[1] & 0x0f); ut32 vA = (data[1] & 0xf0) >> 4; - ut32 vC = (len > 4)? r_read_le32 (data + 2): 0x22; + ut32 vC = (len > 4)? rz_read_le32 (data + 2): 0x22; // op->stackop = R_ANAL_STACK_SET; // op->ptr = vC; // why ut32 val = vC?vC:vA; @@ -703,7 +703,7 @@ static int dalvik_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int l return sz; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC ip\n" "=SP sp\n" @@ -752,10 +752,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr sp .32 120 0\n" "gpr bp .32 124 0\n" ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_dalvik = { +RzAnalPlugin rz_anal_plugin_dalvik = { .name = "dalvik", .arch = "dalvik", .set_reg_profile = &set_reg_profile, @@ -766,9 +766,9 @@ RAnalPlugin r_anal_plugin_dalvik = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_dalvik, + .data = &rz_anal_plugin_dalvik, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_ebc.c b/librz/anal/p/anal_ebc.c similarity index 85% rename from libr/anal/p/anal_ebc.c rename to librz/anal/p/anal_ebc.c index 69affedea6..e6cf95d62f 100644 --- a/libr/anal/p/anal_ebc.c +++ b/librz/anal/p/anal_ebc.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2012-2013 - pancake, fedor.sakharov */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include -static void ebc_anal_jmp8(RAnalOp *op, ut64 addr, const ut8 *buf) { +static void ebc_anal_jmp8(RzAnalOp *op, ut64 addr, const ut8 *buf) { int jmpadr = (int8_t)buf[1]; op->jump = addr + 2 + (jmpadr * 2); op->addr = addr; @@ -21,7 +21,7 @@ static void ebc_anal_jmp8(RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static void ebc_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { +static void ebc_anal_jmp(RzAnalOp *op, ut64 addr, const ut8 *buf) { op->fail = addr + 6; op->jump = (ut64)*(int32_t*)(buf + 2); if (TEST_BIT (buf[1], 4)) { @@ -38,7 +38,7 @@ static void ebc_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static void ebc_anal_call(RAnalOp *op, ut64 addr, const ut8 *buf) { +static void ebc_anal_call(RzAnalOp *op, ut64 addr, const ut8 *buf) { int32_t addr_call; op->fail = addr + 6; @@ -57,7 +57,7 @@ static void ebc_anal_call(RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int ebc_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int ret; ebc_command_t cmd; ut8 opcode = buf[0] & EBC_OPCODE_MASK; @@ -161,7 +161,7 @@ static int ebc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, return ret; } -RAnalPlugin r_anal_plugin_ebc = { +RzAnalPlugin rz_anal_plugin_ebc = { .name = "ebc", .desc = "EBC code analysis plugin", .license = "LGPL3", @@ -171,9 +171,9 @@ RAnalPlugin r_anal_plugin_ebc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_ebc, + .data = &rz_anal_plugin_ebc, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_gb.c b/librz/anal/p/anal_gb.c similarity index 56% rename from libr/anal/p/anal_gb.c rename to librz/anal/p/anal_gb.c index 6e7d3b6052..88e98edfd8 100644 --- a/libr/anal/p/anal_gb.c +++ b/librz/anal/p/anal_gb.c @@ -4,11 +4,11 @@ this file was based on anal_i8080.c */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define GB_DIS_LEN_ONLY #include "../../asm/arch/gb/gbdis.c" #include "../arch/gb/gb_makros.h" @@ -22,11 +22,11 @@ static const char *regs_x[] = { "b", "c", "d", "e", "h", "l", "hl", "a"}; static const char *regs_16[] = { "bc", "de", "hl", "sp"}; static const char *regs_16_alt[] = { "bc", "de", "hl", "af" }; -static ut8 gb_op_calljump(RAnal *a, RAnalOp *op, const ut8 *data, ut64 addr) +static ut8 gb_op_calljump(RzAnal *a, RzAnalOp *op, const ut8 *data, ut64 addr) { if (GB_IS_RAM_DST (data[1],data[2])) { op->jump = GB_SOFTCAST (data[1], data[2]); - r_meta_set_string (a, R_META_TYPE_COMMENT, addr, "--> unpredictable"); + rz_meta_set_string (a, R_META_TYPE_COMMENT, addr, "--> unpredictable"); return false; } if (!GB_IS_VBANK_DST (data[1], data[2])) { @@ -38,27 +38,27 @@ static ut8 gb_op_calljump(RAnal *a, RAnalOp *op, const ut8 *data, ut64 addr) } #if 0 -static inline int gb_anal_esil_banksw (RAnalOp *op) //remove that +static inline int gb_anal_esil_banksw (RzAnalOp *op) //remove that { ut64 base = op->dst->base; if (op->addr < 0x4000 && 0x1fff < base && base < 0x4000) { - r_strbuf_set (&op->esil, "mbcrom=0,?a%0x20,mbcrom=a-1"); //if a is a multiple of 0x20 mbcrom is 0, else it gets its value from a + rz_strbuf_set (&op->esil, "mbcrom=0,?a%0x20,mbcrom=a-1"); //if a is a multiple of 0x20 mbcrom is 0, else it gets its value from a return true; } if (base < 0x6000 && 0x3fff < base) { - r_strbuf_set (&op->esil, "mbcram=a"); + rz_strbuf_set (&op->esil, "mbcram=a"); return true; } return false; } #endif -static void gb_anal_esil_call (RAnalOp *op) +static void gb_anal_esil_call (RzAnalOp *op) { - r_strbuf_setf (&op->esil, "2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,:=", (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,:=", (op->jump & 0xffff)); } -static inline void gb_anal_esil_ccall (RAnalOp *op, const ut8 data) +static inline void gb_anal_esil_ccall (RzAnalOp *op, const ut8 data) { char cond; switch (data) { @@ -70,18 +70,18 @@ static inline void gb_anal_esil_ccall (RAnalOp *op, const ut8 data) cond = 'C'; } if (op->cond == R_ANAL_COND_EQ) { - r_strbuf_setf (&op->esil, "%c,?{,2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,:=,}", cond, (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "%c,?{,2,sp,-=,pc,sp,=[2],%"PFMT64d",pc,:=,}", cond, (op->jump & 0xffff)); } else { - r_strbuf_setf (&op->esil, "%c,!,?{,2,sp,-=,pc,sp,=[2],%" PFMT64d ",pc,:=,}", cond, (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "%c,!,?{,2,sp,-=,pc,sp,=[2],%" PFMT64d ",pc,:=,}", cond, (op->jump & 0xffff)); } } -static inline void gb_anal_esil_ret (RAnalOp *op) +static inline void gb_anal_esil_ret (RzAnalOp *op) { - r_strbuf_append (&op->esil, "sp,[2],pc,:=,2,sp,+="); + rz_strbuf_append (&op->esil, "sp,[2],pc,:=,2,sp,+="); } -static inline void gb_anal_esil_cret (RAnalOp *op, const ut8 data) +static inline void gb_anal_esil_cret (RzAnalOp *op, const ut8 data) { char cond; if ((data & 0xd0) == 0xd0) { @@ -90,13 +90,13 @@ static inline void gb_anal_esil_cret (RAnalOp *op, const ut8 data) cond = 'Z'; } if (op->cond == R_ANAL_COND_EQ) { - r_strbuf_setf (&op->esil, "%c,?{,sp,[2],pc,:=,2,sp,+=,}", cond); + rz_strbuf_setf (&op->esil, "%c,?{,sp,[2],pc,:=,2,sp,+=,}", cond); } else { - r_strbuf_setf (&op->esil, "%c,!,?{,sp,[2],pc,:=,2,sp,+=,}", cond); + rz_strbuf_setf (&op->esil, "%c,!,?{,sp,[2],pc,:=,2,sp,+=,}", cond); } } -static inline void gb_anal_esil_cjmp (RAnalOp *op, const ut8 data) +static inline void gb_anal_esil_cjmp (RzAnalOp *op, const ut8 data) { char cond; switch (data) { @@ -110,164 +110,164 @@ static inline void gb_anal_esil_cjmp (RAnalOp *op, const ut8 data) cond = 'C'; } if (op->cond == R_ANAL_COND_EQ) { - r_strbuf_setf (&op->esil, "%c,?{,0x%"PFMT64x",pc,:=,}", cond, (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "%c,?{,0x%"PFMT64x",pc,:=,}", cond, (op->jump & 0xffff)); } else { - r_strbuf_setf (&op->esil, "%c,!,?{,0x%"PFMT64x",pc,:=,}", cond, (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "%c,!,?{,0x%"PFMT64x",pc,:=,}", cond, (op->jump & 0xffff)); } } -static inline void gb_anal_esil_jmp (RAnalOp *op) +static inline void gb_anal_esil_jmp (RzAnalOp *op) { - r_strbuf_setf (&op->esil, "0x%"PFMT64x",pc,:=", (op->jump & 0xffff)); + rz_strbuf_setf (&op->esil, "0x%"PFMT64x",pc,:=", (op->jump & 0xffff)); } -static inline void gb_anal_jmp_hl (RReg *reg, RAnalOp *op) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "pc", R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, "hl", R_REG_TYPE_GPR); - r_strbuf_set (&op->esil, "hl,pc,:="); +static inline void gb_anal_jmp_hl (RzReg *reg, RzAnalOp *op) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "pc", R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, "hl", R_REG_TYPE_GPR); + rz_strbuf_set (&op->esil, "hl,pc,:="); } -static inline void gb_anal_id (RAnal *anal, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_id (RzAnal *anal, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; op->src[0]->absolute = true; if (data == 0x34 || data == 0x35) { op->dst->memref = 1; - op->dst->reg = r_reg_get (anal->reg, "hl", R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (anal->reg, "hl", R_REG_TYPE_GPR); if (op->type == R_ANAL_OP_TYPE_ADD) { - r_strbuf_set (&op->esil, "1,hl,[1],+,hl,=[1],3,$c,H,:=,$z,Z,:=,0,N,:="); + rz_strbuf_set (&op->esil, "1,hl,[1],+,hl,=[1],3,$c,H,:=,$z,Z,:=,0,N,:="); } else { - r_strbuf_set (&op->esil, "1,hl,[1],-,hl,=[1],4,$b,H,:=,$z,Z,:=,1,N,:="); + rz_strbuf_set (&op->esil, "1,hl,[1],-,hl,=[1],4,$b,H,:=,$z,Z,:=,1,N,:="); } } else { if (!(data & (1<<2))) { - op->dst->reg = r_reg_get (anal->reg, regs_16[data>>4], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (anal->reg, regs_16[data>>4], R_REG_TYPE_GPR); if (op->type == R_ANAL_OP_TYPE_ADD) { - r_strbuf_setf (&op->esil, "1,%s,+=", regs_16[data>>4]); + rz_strbuf_setf (&op->esil, "1,%s,+=", regs_16[data>>4]); } else { - r_strbuf_setf (&op->esil, "1,%s,-=", regs_16[data >> 4]); + rz_strbuf_setf (&op->esil, "1,%s,-=", regs_16[data >> 4]); } } else { - op->dst->reg = r_reg_get (anal->reg, regs_8[data>>3], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (anal->reg, regs_8[data>>3], R_REG_TYPE_GPR); if (op->type == R_ANAL_OP_TYPE_ADD) { - r_strbuf_setf (&op->esil, "1,%s,+=,3,$c,H,:=,$z,Z,:=,0,N,:=", regs_8[data>>3]); + rz_strbuf_setf (&op->esil, "1,%s,+=,3,$c,H,:=,$z,Z,:=,0,N,:=", regs_8[data>>3]); } else { - r_strbuf_setf (&op->esil, "1,%s,-=,4,$b,H,:=,$z,Z,:=,1,N,:=", regs_8[data >> 3]); + rz_strbuf_setf (&op->esil, "1,%s,-=,4,$b,H,:=,$z,Z,:=,1,N,:=", regs_8[data >> 3]); } } } } -static inline void gb_anal_add_hl (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "hl", R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, regs_16[((data & 0xf0)>>4)], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "%s,hl,+=,0,N,:=", regs_16[((data & 0xf0)>>4)]); //hl+=,N=0 +static inline void gb_anal_add_hl (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "hl", R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, regs_16[((data & 0xf0)>>4)], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "%s,hl,+=,0,N,:=", regs_16[((data & 0xf0)>>4)]); //hl+=,N=0 } -static inline void gb_anal_add_sp (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "sp", R_REG_TYPE_GPR); +static inline void gb_anal_add_sp (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "sp", R_REG_TYPE_GPR); op->src[0]->imm = (st8)data; if (data < 128) { - r_strbuf_setf (&op->esil, "0x%02x,sp,+=", data); + rz_strbuf_setf (&op->esil, "0x%02x,sp,+=", data); } else { - r_strbuf_setf (&op->esil, "0x%02x,sp,-=", 0 - (st8)data); + rz_strbuf_setf (&op->esil, "0x%02x,sp,-=", 0 - (st8)data); } - r_strbuf_append (&op->esil, ",0,Z,=,0,N,:="); + rz_strbuf_append (&op->esil, ",0,Z,=,0,N,:="); } -static void gb_anal_mov_imm (RReg *reg, RAnalOp *op, const ut8 *data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static void gb_anal_mov_imm (RzReg *reg, RzAnalOp *op, const ut8 *data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); if (data[0] & 1) { - op->dst->reg = r_reg_get (reg, regs_16[data[0]>>4], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_16[data[0]>>4], R_REG_TYPE_GPR); op->src[0]->imm = GB_SOFTCAST (data[1], data[2]); - r_strbuf_setf (&op->esil, "0x%04x,%s,=", op->src[0]->imm, regs_16[data[0]>>4]); + rz_strbuf_setf (&op->esil, "0x%04x,%s,=", op->src[0]->imm, regs_16[data[0]>>4]); } else { - op->dst->reg = r_reg_get (reg, regs_8[data[0]>>3], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_8[data[0]>>3], R_REG_TYPE_GPR); op->src[0]->imm = data[1]; - r_strbuf_setf (&op->esil, "0x%02x,%s,=", op->src[0]->imm, regs_8[data[0]>>3]); + rz_strbuf_setf (&op->esil, "0x%02x,%s,=", op->src[0]->imm, regs_8[data[0]>>3]); } op->src[0]->absolute = true; op->val = op->src[0]->imm; } -static inline void gb_anal_mov_sp_hl (RReg *reg, RAnalOp *op) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "sp", R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, "hl", R_REG_TYPE_GPR); - r_strbuf_set (&op->esil, "hl,sp,="); +static inline void gb_anal_mov_sp_hl (RzReg *reg, RzAnalOp *op) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "sp", R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, "hl", R_REG_TYPE_GPR); + rz_strbuf_set (&op->esil, "hl,sp,="); } -static inline void gb_anal_mov_hl_sp (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->src[1] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, regs_16[2], R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, regs_16[3], R_REG_TYPE_GPR); +static inline void gb_anal_mov_hl_sp (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->src[1] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, regs_16[2], R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, regs_16[3], R_REG_TYPE_GPR); op->src[1]->imm = (st8)data; if (data < 128) { - r_strbuf_setf (&op->esil, "0x%02x,sp,+,hl,=", data); + rz_strbuf_setf (&op->esil, "0x%02x,sp,+,hl,=", data); } else { - r_strbuf_setf (&op->esil, "0x%02x,sp,-,hl,=", 0 - (st8)data); + rz_strbuf_setf (&op->esil, "0x%02x,sp,-,hl,=", 0 - (st8)data); } - r_strbuf_append (&op->esil, ",0,Z,=,0,N,:="); + rz_strbuf_append (&op->esil, ",0,Z,=,0,N,:="); } -static void gb_anal_mov_reg (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, regs_8[(data/8) - 8], R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, regs_8[data & 7], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "%s,%s,=", regs_8[data & 7], regs_8[(data/8) - 8]); +static void gb_anal_mov_reg (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, regs_8[(data/8) - 8], R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, regs_8[data & 7], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "%s,%s,=", regs_8[data & 7], regs_8[(data/8) - 8]); } -static inline void gb_anal_mov_ime (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "ime", R_REG_TYPE_GPR); +static inline void gb_anal_mov_ime (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "ime", R_REG_TYPE_GPR); op->src[0]->absolute = true; op->src[0]->imm = (data != 0xf3); - r_strbuf_setf (&op->esil, "%d,ime,=", (int)op->src[0]->imm); + rz_strbuf_setf (&op->esil, "%d,ime,=", (int)op->src[0]->imm); if (data == 0xd9) { - r_strbuf_append (&op->esil, ","); + rz_strbuf_append (&op->esil, ","); } } -static inline void gb_anal_mov_scf (RReg *reg, RAnalOp *op) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); +static inline void gb_anal_mov_scf (RzReg *reg, RzAnalOp *op) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); op->src[0]->imm = 1; - r_strbuf_set (&op->esil, "1,C,:="); + rz_strbuf_set (&op->esil, "1,C,:="); } -static inline void gb_anal_xor_cpl (RReg *reg, RAnalOp *op) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, regs_8[7], R_REG_TYPE_GPR); +static inline void gb_anal_xor_cpl (RzReg *reg, RzAnalOp *op) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, regs_8[7], R_REG_TYPE_GPR); op->src[0]->imm = 0xff; - r_strbuf_set (&op->esil, "0xff,a,^=,1,N,:=,1,H,:="); + rz_strbuf_set (&op->esil, "0xff,a,^=,1,N,:=,1,H,:="); } -static inline void gb_anal_xor_ccf (RReg *reg, RAnalOp *op) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); +static inline void gb_anal_xor_ccf (RzReg *reg, RzAnalOp *op) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); op->src[0]->imm = 1; - r_strbuf_set (&op->esil, "C,!="); + rz_strbuf_set (&op->esil, "C,!="); } -static inline void gb_anal_cond (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_cond (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; if (data & 0x8) { op->cond = R_ANAL_COND_EQ; @@ -283,136 +283,136 @@ static inline void gb_anal_cond (RReg *reg, RAnalOp *op, const ut8 data) { case 0xc8: case 0xca: case 0xcc: - op->dst->reg = r_reg_get (reg, regs_1[0], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_1[0], R_REG_TYPE_GPR); break; default: - op->dst->reg = r_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_1[3], R_REG_TYPE_GPR); } } -static inline void gb_anal_pp (RReg *reg, RAnalOp *op, const ut8 data) //push , pop +static inline void gb_anal_pp (RzReg *reg, RzAnalOp *op, const ut8 data) //push , pop { - RAnalValue *val = r_anal_value_new (); - val->reg = r_reg_get (reg, regs_16_alt[(data>>4) - 12], R_REG_TYPE_GPR); + RzAnalValue *val = rz_anal_value_new (); + val->reg = rz_reg_get (reg, regs_16_alt[(data>>4) - 12], R_REG_TYPE_GPR); if ((data & 0xf) == 1) { op->dst = val; - r_strbuf_setf (&op->esil, "sp,[2],%s,=,2,sp,+=", regs_16_alt[(data>>4) - 12]); //pop + rz_strbuf_setf (&op->esil, "sp,[2],%s,=,2,sp,+=", regs_16_alt[(data>>4) - 12]); //pop } else { op->src[0] = val; - r_strbuf_setf (&op->esil, "2,sp,-=,%s,sp,=[2]", regs_16_alt[(data>>4) - 12]); //push + rz_strbuf_setf (&op->esil, "2,sp,-=,%s,sp,=[2]", regs_16_alt[(data>>4) - 12]); //push } } -static inline void gb_anal_and_res (RAnal *anal, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_and_res (RzAnal *anal, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = ((~(0x1 << ((data >> 3) & 7))) & 0xff); op->dst->memref = ((data & 7) == 6); - op->dst->reg = r_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "0x%02x,%s,[1],&,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "0x%02x,%s,[1],&,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "0x%02x,%s,&=", op->src[0]->imm, regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "0x%02x,%s,&=", op->src[0]->imm, regs_x[data & 7]); } } -static inline void gb_anal_and_bit (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_and_bit (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1<<((data>>3) & 7); op->dst->memref = ((data & 7) == 6); - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "%i,%s,[1],&,0,==,$z,Z,:=,0,N,:=,1,H,:=", op->src[0]->imm, regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "%i,%s,[1],&,0,==,$z,Z,:=,0,N,:=,1,H,:=", op->src[0]->imm, regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "%i,%s,&,0,==,$z,Z,:=,0,N,:=,1,H,:=", op->src[0]->imm, regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "%i,%s,&,0,==,$z,Z,:=,0,N,:=,1,H,:=", op->src[0]->imm, regs_x[data & 7]); } } -static inline void gb_anal_or_set (RAnal *anal, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_or_set (RzAnal *anal, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = (data>>3) & 7; op->dst->memref = ((data & 7) == 6); - op->dst->reg = r_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (anal->reg, regs_x[data & 7], R_REG_TYPE_GPR); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "0x%02x,%s,[1],|,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7], op->src[0]->imm); + rz_strbuf_setf (&op->esil, "0x%02x,%s,[1],|,%s,=[1]", op->src[0]->imm, regs_x[data & 7], regs_x[data & 7], op->src[0]->imm); } else { - r_strbuf_setf (&op->esil, "0x%02x,%s,|=", op->src[0]->imm, regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "0x%02x,%s,|=", op->src[0]->imm, regs_x[data & 7]); } } -static void gb_anal_xoaasc (RReg *reg, RAnalOp *op, const ut8 *data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "a", R_REG_TYPE_GPR); - op->src[0]->reg = r_reg_get (reg, regs_x[data[0] & 7], R_REG_TYPE_GPR); +static void gb_anal_xoaasc (RzReg *reg, RzAnalOp *op, const ut8 *data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "a", R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, regs_x[data[0] & 7], R_REG_TYPE_GPR); op->src[0]->memref = ((data[0] & 7) == 6); switch (op->type) { case R_ANAL_OP_TYPE_XOR: if (op->src[0]->memref) { - r_strbuf_setf (&op->esil, "%s,[1],a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); } break; case R_ANAL_OP_TYPE_OR: if (op->src[0]->memref) { - r_strbuf_setf (&op->esil, "%s,[1],a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] &7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] &7]); } else { - r_strbuf_setf (&op->esil, "%s,a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", regs_x[data[0] & 7]); } break; case R_ANAL_OP_TYPE_AND: if (op->src[0]->memref) { - r_strbuf_setf (&op->esil, "%s,[1],a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", regs_x[data[0] & 7]); } break; case R_ANAL_OP_TYPE_ADD: if (op->src[0]->memref) { if (data[0] > 0x87) { - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_setf ( &op->esil, "C,%s,[1],+,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_setf ( &op->esil, "C,%s,[1],+,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); } } else { if (data[0] > 0x87) { - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "C,%s,+,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "C,%s,+,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,+=,$z,Z,:=,3,$c,H,:=,7,$c,C,:=,0,N,:=", regs_x[data[0] & 7]); } } break; case R_ANAL_OP_TYPE_SUB: if (op->src[0]->memref) { if (data[0] > 0x97) { - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "C,%s,[1],+,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "C,%s,[1],+,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,[1],a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } } else { if (data[0] > 0x97) { - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "C,%s,+,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "C,%s,+,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,-=,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } } break; case R_ANAL_OP_TYPE_CMP: if (op->src[0]->memref) { - r_strbuf_setf (&op->esil, "%s,[1],a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,[1],a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } else { - r_strbuf_setf (&op->esil, "%s,a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); + rz_strbuf_setf (&op->esil, "%s,a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", regs_x[data[0] & 7]); } break; default: @@ -421,80 +421,80 @@ static void gb_anal_xoaasc (RReg *reg, RAnalOp *op, const ut8 *data) { } } -static void gb_anal_xoaasc_imm (RReg *reg, RAnalOp *op, const ut8 *data) //xor , or, and, add, adc, sub, sbc, cp +static void gb_anal_xoaasc_imm (RzReg *reg, RzAnalOp *op, const ut8 *data) //xor , or, and, add, adc, sub, sbc, cp { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "a", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "a", R_REG_TYPE_GPR); op->src[0]->absolute = true; op->src[0]->imm = data[1]; switch (op->type) { case R_ANAL_OP_TYPE_XOR: - r_strbuf_setf (&op->esil, "0x%02x,a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,a,^=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", data[1]); break; case R_ANAL_OP_TYPE_OR: - r_strbuf_setf (&op->esil, "0x%02x,a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,a,|=,$z,Z,:=,0,N,:=,0,H,:=,0,C,:=", data[1]); break; case R_ANAL_OP_TYPE_AND: - r_strbuf_setf (&op->esil, "0x%02x,a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,a,&=,$z,Z,:=,0,N,:=,1,H,:=,0,C,:=", data[1]); break; case R_ANAL_OP_TYPE_ADD: - r_strbuf_setf (&op->esil, "0x%02x,", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,", data[1]); if (data[0] == 0xce) { //adc - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_append (&op->esil, "a,+=,C,NUM,7,$c,C,:=,3,$c,H,:=,a,+=,7,$c,C,|,C,:=,3,$c,H,|=,a,a,=,$z,Z,:=,0,N,:="); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_append (&op->esil, "a,+=,C,NUM,7,$c,C,:=,3,$c,H,:=,a,+=,7,$c,C,|,C,:=,3,$c,H,|=,a,a,=,$z,Z,:=,0,N,:="); } else { - r_strbuf_append (&op->esil, "a,+=,3,$c,H,:=,7,$c,C,:=,0,N,:=,a,a,=,$z,Z,:="); + rz_strbuf_append (&op->esil, "a,+=,3,$c,H,:=,7,$c,C,:=,0,N,:=,a,a,=,$z,Z,:="); } break; case R_ANAL_OP_TYPE_SUB: - r_strbuf_setf (&op->esil, "0x%02x,", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,", data[1]); if (data[0] == 0xde) { //sbc - op->src[1] = r_anal_value_new (); - op->src[1]->reg = r_reg_get (reg, "C", R_REG_TYPE_GPR); - r_strbuf_append (&op->esil, "a,-=,C,NUM,8,$b,C,:=,4,$b,H,:=,a,-=,8,$b,C,|,C,=,4,$b,H,|,H,=,a,a,=,$z,Z,:=,1,N,:="); + op->src[1] = rz_anal_value_new (); + op->src[1]->reg = rz_reg_get (reg, "C", R_REG_TYPE_GPR); + rz_strbuf_append (&op->esil, "a,-=,C,NUM,8,$b,C,:=,4,$b,H,:=,a,-=,8,$b,C,|,C,=,4,$b,H,|,H,=,a,a,=,$z,Z,:=,1,N,:="); } else { - r_strbuf_append (&op->esil, "a,-=,4,$b,H,:=,8,$b,C,:=,1,N,:=,a,a,=,$z,Z,:="); + rz_strbuf_append (&op->esil, "a,-=,4,$b,H,:=,8,$b,C,:=,1,N,:=,a,a,=,$z,Z,:="); } break; case R_ANAL_OP_TYPE_CMP: - r_strbuf_setf (&op->esil, "%d,a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", data[1]); + rz_strbuf_setf (&op->esil, "%d,a,==,$z,Z,:=,4,$b,H,:=,8,$b,C,:=,1,N,:=", data[1]); break; } } -static inline void gb_anal_load_hl (RReg *reg, RAnalOp *op, const ut8 data) //load with [hl] as memref +static inline void gb_anal_load_hl (RzReg *reg, RzAnalOp *op, const ut8 data) //load with [hl] as memref { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->src[0]->reg = r_reg_get (reg, "hl", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->src[0]->reg = rz_reg_get (reg, "hl", R_REG_TYPE_GPR); op->src[0]->memref = 1; op->src[0]->absolute = true; - op->dst->reg = r_reg_get (reg, regs_8[((data & 0x38)>>3)], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "hl,[1],%s,=", regs_8[((data & 0x38)>>3)]); + op->dst->reg = rz_reg_get (reg, regs_8[((data & 0x38)>>3)], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "hl,[1],%s,=", regs_8[((data & 0x38)>>3)]); if (data == 0x3a) { - r_strbuf_append (&op->esil, ",1,hl,-="); + rz_strbuf_append (&op->esil, ",1,hl,-="); } if (data == 0x2a) { - r_strbuf_set (&op->esil, "hl,[1],a,=,1,hl,+="); //hack in concept + rz_strbuf_set (&op->esil, "hl,[1],a,=,1,hl,+="); //hack in concept } } -static inline void gb_anal_load (RReg *reg, RAnalOp *op, const ut8 *data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "a", R_REG_TYPE_GPR); +static inline void gb_anal_load (RzReg *reg, RzAnalOp *op, const ut8 *data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "a", R_REG_TYPE_GPR); op->src[0]->memref = 1; switch (data[0]) { case 0xf0: op->src[0]->base = 0xff00 + data[1]; - r_strbuf_setf (&op->esil, "0x%04x,[1],a,=", op->src[0]->base); + rz_strbuf_setf (&op->esil, "0x%04x,[1],a,=", op->src[0]->base); break; case 0xf2: op->src[0]->base = 0xff00; - op->src[0]->regdelta = r_reg_get (reg, "c", R_REG_TYPE_GPR); - r_strbuf_set (&op->esil, "0xff00,c,+,[1],a,="); + op->src[0]->regdelta = rz_reg_get (reg, "c", R_REG_TYPE_GPR); + rz_strbuf_set (&op->esil, "0xff00,c,+,[1],a,="); break; case 0xfa: op->src[0]->base = GB_SOFTCAST (data[1], data[2]); @@ -505,194 +505,194 @@ static inline void gb_anal_load (RReg *reg, RAnalOp *op, const ut8 *data) { op->ptr = op->src[0]->base + (op->addr & 0xffffffffffff0000LL); } } - r_strbuf_setf (&op->esil, "0x%04x,[1],a,=", op->src[0]->base); + rz_strbuf_setf (&op->esil, "0x%04x,[1],a,=", op->src[0]->base); break; default: - op->src[0]->reg = r_reg_get (reg, regs_16[(data[0] & 0xf0) >> 4], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "%s,[1],a,=", regs_16[(data[0] & 0xf0) >> 4]); + op->src[0]->reg = rz_reg_get (reg, regs_16[(data[0] & 0xf0) >> 4], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "%s,[1],a,=", regs_16[(data[0] & 0xf0) >> 4]); break; } } -static inline void gb_anal_store_hl (RReg *reg, RAnalOp *op, const ut8 *data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); - op->dst->reg = r_reg_get (reg, "hl", R_REG_TYPE_GPR); +static inline void gb_anal_store_hl (RzReg *reg, RzAnalOp *op, const ut8 *data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); + op->dst->reg = rz_reg_get (reg, "hl", R_REG_TYPE_GPR); op->dst->memref = 1; op->src[0]->absolute = true; if (data[0] == 0x36) { op->src[0]->imm = data[1]; - r_strbuf_setf (&op->esil, "0x%02x,hl,=[1]", data[1]); + rz_strbuf_setf (&op->esil, "0x%02x,hl,=[1]", data[1]); } else { - op->src[0]->reg = r_reg_get (reg, regs_8[data[0] & 0x07], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "%s,hl,=[1]", regs_8[data[0] & 0x07]); + op->src[0]->reg = rz_reg_get (reg, regs_8[data[0] & 0x07], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "%s,hl,=[1]", regs_8[data[0] & 0x07]); } if (data[0] == 0x32) { - r_strbuf_set (&op->esil, "a,hl,=[1],1,hl,-="); + rz_strbuf_set (&op->esil, "a,hl,=[1],1,hl,-="); } if (data[0] == 0x22) { - r_strbuf_set (&op->esil, "a,hl,=[1],1,hl,+="); + rz_strbuf_set (&op->esil, "a,hl,=[1],1,hl,+="); } } -static void gb_anal_store (RReg *reg, RAnalOp *op, const ut8 *data) +static void gb_anal_store (RzReg *reg, RzAnalOp *op, const ut8 *data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->dst->memref = 1; - op->src[0]->reg = r_reg_get (reg, "a", R_REG_TYPE_GPR); + op->src[0]->reg = rz_reg_get (reg, "a", R_REG_TYPE_GPR); switch (data[0]) { case 0x08: op->dst->memref = 2; op->dst->base = GB_SOFTCAST (data[1], data[2]); - op->src[0]->reg = r_reg_get (reg, "sp", R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil, "sp,0x%04x,=[2]", op->dst->base); + op->src[0]->reg = rz_reg_get (reg, "sp", R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil, "sp,0x%04x,=[2]", op->dst->base); break; case 0xe0: op->dst->base = 0xff00 + data[1]; - r_strbuf_setf (&op->esil, "a,0x%04x,=[1]", op->dst->base); + rz_strbuf_setf (&op->esil, "a,0x%04x,=[1]", op->dst->base); break; case 0xe2: op->dst->base = 0xff00; - op->dst->regdelta = r_reg_get (reg, "c", R_REG_TYPE_GPR); - r_strbuf_set (&op->esil, "a,0xff00,c,+,=[1]"); + op->dst->regdelta = rz_reg_get (reg, "c", R_REG_TYPE_GPR); + rz_strbuf_set (&op->esil, "a,0xff00,c,+,=[1]"); break; case 0xea: op->dst->base = GB_SOFTCAST (data[1], data[2]); - r_strbuf_setf (&op->esil, "a,0x%04x,=[1]", op->dst->base); + rz_strbuf_setf (&op->esil, "a,0x%04x,=[1]", op->dst->base); break; default: - op->dst->reg = r_reg_get (reg, regs_16[(data[0] & 0xf0)>>4], R_REG_TYPE_GPR); - r_strbuf_setf (&op->esil , "a,%s,=[1]", regs_16[(data[0] & 0xf0)>>4]); + op->dst->reg = rz_reg_get (reg, regs_16[(data[0] & 0xf0)>>4], R_REG_TYPE_GPR); + rz_strbuf_setf (&op->esil , "a,%s,=[1]", regs_16[(data[0] & 0xf0)>>4]); } } -static inline void gb_anal_cb_swap (RReg *reg, RAnalOp* op, const ut8 data) +static inline void gb_anal_cb_swap (RzReg *reg, RzAnalOp* op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 4; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); if ((data & 7) == 6) { op->dst->memref = 1; - r_strbuf_setf (&op->esil, "4,%s,[1],>>,4,%s,[1],<<,|,%s,=[1],$z,Z,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "4,%s,[1],>>,4,%s,[1],<<,|,%s,=[1],$z,Z,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "4,%s,>>,4,%s,<<,|,%s,=,$z,Z,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "4,%s,>>,4,%s,<<,|,%s,=,$z,Z,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } } -static inline void gb_anal_cb_rlc (RReg *reg, RAnalOp *op, const ut8 data) +static inline void gb_anal_cb_rlc (RzReg *reg, RzAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); if ((data & 7) == 6) { op->dst->memref = 1; - r_strbuf_setf (&op->esil, "7,%s,[1],>>,1,&,C,:=,1,%s,[1],<<,C,|,%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "7,%s,[1],>>,1,&,C,:=,1,%s,[1],<<,C,|,%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,<<=,7,$c,C,:=,C,%s,|=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,<<=,7,$c,C,:=,C,%s,|=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); } } -static inline void gb_anal_cb_rl (RReg *reg, RAnalOp *op, const ut8 data) +static inline void gb_anal_cb_rl (RzReg *reg, RzAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); if ((data & 7) == 6) { op->dst->memref = 1; - r_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=[1],7,$c,C,:=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=[1],7,$c,C,:=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=,7,$c,C,:=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,<<,C,|,%s,=,7,$c,C,:=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7]); } } -static inline void gb_anal_cb_rrc (RReg *reg, RAnalOp *op, const ut8 data) +static inline void gb_anal_cb_rrc (RzReg *reg, RzAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get(reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get(reg, regs_x[data & 7], R_REG_TYPE_GPR); if ((data &7) == 6) { op->dst->memref = 1; - r_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,1,%s,[1],>>,7,C,<<,|,%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,1,%s,[1],>>,7,C,<<,|,%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,&,C,:=,1,%s,>>,7,C,<<,|,%s,=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,&,C,:=,1,%s,>>,7,C,<<,|,%s,=,$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } } -static inline void gb_anal_cb_rr (RReg *reg, RAnalOp *op, const ut8 data) +static inline void gb_anal_cb_rr (RzReg *reg, RzAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); if ((data & 7) == 6) { op->dst->memref = 1; - r_strbuf_setf (&op->esil, "1,%s,[1],&,H,:=,1,%s,[1],>>,7,C,<<,|,%s,=[1],H,C,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,[1],&,H,:=,1,%s,[1],>>,7,C,<<,|,%s,=[1],H,C,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,&,H,:=,1,%s,>>,7,C,<<,|,%s,=,H,C,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //HACK + rz_strbuf_setf (&op->esil, "1,%s,&,H,:=,1,%s,>>,7,C,<<,|,%s,=,H,C,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //HACK } } -static inline void gb_anal_cb_sla (RReg *reg, RAnalOp *op, const ut8 data) //sra+sla+srl in one function, like xoaasc +static inline void gb_anal_cb_sla (RzReg *reg, RzAnalOp *op, const ut8 data) //sra+sla+srl in one function, like xoaasc { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); op->dst->memref = ((data & 7) == 6); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "1,%s,[1],<<,%s,=[1],7,$c,C,:=,%s,[1],%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,[1],<<,%s,=[1],7,$c,C,:=,%s,[1],%s,=[1],$z,Z,:=,0,H,:=,0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,<<=,7,$c,C,:=,%s,%s,=,$z,Z,:=,0,H,:=0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); // %s,%s,= is a HACK for $z + rz_strbuf_setf (&op->esil, "1,%s,<<=,7,$c,C,:=,%s,%s,=,$z,Z,:=,0,H,:=0,N,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); // %s,%s,= is a HACK for $z } } -static inline void gb_anal_cb_sra (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_cb_sra (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); op->dst->memref = ((data & 7) == 6); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,0x80,%s,[1],&,1,%s,[1],>>,|,%s,=[1],$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //spaguesil + rz_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,0x80,%s,[1],&,1,%s,[1],>>,|,%s,=[1],$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); //spaguesil } else { - r_strbuf_setf (&op->esil, "1,%s,&,C,:=,0x80,%s,&,1,%s,>>,|,%s,=,$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,&,C,:=,0x80,%s,&,1,%s,>>,|,%s,=,$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } } -static inline void gb_anal_cb_srl (RReg *reg, RAnalOp *op, const ut8 data) { - op->dst = r_anal_value_new (); - op->src[0] = r_anal_value_new (); +static inline void gb_anal_cb_srl (RzReg *reg, RzAnalOp *op, const ut8 data) { + op->dst = rz_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->imm = 1; - op->dst->reg = r_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); + op->dst->reg = rz_reg_get (reg, regs_x[data & 7], R_REG_TYPE_GPR); op->dst->memref = ((data & 7) == 6); if (op->dst->memref) { - r_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,1,%s,[1],>>,%s,=[1],$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,[1],&,C,:=,1,%s,[1],>>,%s,=[1],$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7], regs_x[data & 7]); } else { - r_strbuf_setf (&op->esil, "1,%s,&,C,:=,1,%s,>>=,$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7]); + rz_strbuf_setf (&op->esil, "1,%s,&,C,:=,1,%s,>>=,$z,Z,:=,0,N,:=,0,H,:=", regs_x[data & 7], regs_x[data & 7]); } } -static bool gb_custom_daa (RAnalEsil *esil) { +static bool gb_custom_daa (RzAnalEsil *esil) { if (!esil || !esil->anal || !esil->anal->reg) { return false; } - char *v = r_anal_esil_pop(esil); + char *v = rz_anal_esil_pop(esil); ut64 n; - if (!v || !r_anal_esil_get_parm(esil, v, &n)) { + if (!v || !rz_anal_esil_get_parm(esil, v, &n)) { return false; } R_FREE (v); ut8 val = (ut8)n; - r_anal_esil_reg_read (esil, "H", &n, NULL); + rz_anal_esil_reg_read (esil, "H", &n, NULL); const ut8 H = (ut8)n; - r_anal_esil_reg_read (esil, "C", &n, NULL); + rz_anal_esil_reg_read (esil, "C", &n, NULL); const ut8 C = (ut8)n; - r_anal_esil_reg_read (esil, "N", &n, NULL); + rz_anal_esil_reg_read (esil, "N", &n, NULL); if (n) { if (C) { val = (val - 0x60) & 0xff; @@ -708,10 +708,10 @@ static bool gb_custom_daa (RAnalEsil *esil) { val += 0x06; }; } - return r_anal_esil_pushnum(esil, val); + return rz_anal_esil_pushnum(esil, val); } -static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int gb_anop(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { int ilen = gbOpLength (gb_op[data[0]].type); if (ilen > len) { op->type = R_ANAL_OP_TYPE_ILL; @@ -1348,11 +1348,11 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len case 0x27: //daa op->cycles = 4; op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_set (&op->esil, "a,daa,a,=,$z,Z,:=,3,$c,H,:=,7,$c,C,:="); + rz_strbuf_set (&op->esil, "a,daa,a,=,$z,Z,:=,3,$c,H,:=,7,$c,C,:="); break; case 0x10: //stop op->type = R_ANAL_OP_TYPE_NULL; - r_strbuf_set (&op->esil, "TODO,stop"); + rz_strbuf_set (&op->esil, "TODO,stop"); break; case 0xcb: op->nopcode = 2; @@ -1495,7 +1495,7 @@ static int gb_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len the mbc can be seen as a register but it isn't. For the Gameboy the mbc is invisble. */ -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC mpc\n" "=SP sp\n" @@ -1534,25 +1534,25 @@ static bool set_reg_profile(RAnal *anal) { "gpr mbcram .16 16 0\n" "gpr ime .1 18 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int esil_gb_init (RAnalEsil *esil) { +static int esil_gb_init (RzAnalEsil *esil) { GBUser *user = R_NEW0 (GBUser); - r_anal_esil_set_op (esil, "daa", gb_custom_daa, 1, 1, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_CUSTOM); + rz_anal_esil_set_op (esil, "daa", gb_custom_daa, 1, 1, R_ANAL_ESIL_OP_TYPE_MATH | R_ANAL_ESIL_OP_TYPE_CUSTOM); if (user) { if (esil->anal) { esil->anal->iob.read_at (esil->anal->iob.io, 0x147, &user->mbc_id, 1); esil->anal->iob.read_at (esil->anal->iob.io, 0x148, &user->romsz_id, 1); esil->anal->iob.read_at (esil->anal->iob.io, 0x149, &user->ramsz_id, 1); if (esil->anal->reg) { //initial values - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "mpc", -1), 0x100); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "sp", -1), 0xfffe); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "af", -1), 0x01b0); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "bc", -1), 0x0013); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "de", -1), 0x00d8); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "hl", -1), 0x014d); - r_reg_set_value (esil->anal->reg, r_reg_get (esil->anal->reg, "ime", -1), true); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "mpc", -1), 0x100); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "sp", -1), 0xfffe); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "af", -1), 0x01b0); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "bc", -1), 0x0013); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "de", -1), 0x00d8); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "hl", -1), 0x014d); + rz_reg_set_value (esil->anal->reg, rz_reg_get (esil->anal->reg, "ime", -1), true); } } esil->cb.user = user; @@ -1560,12 +1560,12 @@ static int esil_gb_init (RAnalEsil *esil) { return true; } -static int esil_gb_fini (RAnalEsil *esil) { +static int esil_gb_fini (RzAnalEsil *esil) { R_FREE (esil->cb.user); return true; } -RAnalPlugin r_anal_plugin_gb = { +RzAnalPlugin rz_anal_plugin_gb = { .name = "gb", .desc = "Gameboy CPU code analysis plugin", .license = "LGPL3", @@ -1579,9 +1579,9 @@ RAnalPlugin r_anal_plugin_gb = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_gb, + .data = &rz_anal_plugin_gb, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_h8300.c b/librz/anal/p/anal_h8300.c similarity index 66% rename from libr/anal/p/anal_h8300.c rename to librz/anal/p/anal_h8300.c index b6896dc452..f9a8a44174 100644 --- a/libr/anal/p/anal_h8300.c +++ b/librz/anal/p/anal_h8300.c @@ -1,28 +1,28 @@ /* radare - LGPL - Copyright 2012-2015 pancake, Fedor Sakharov, Bhootravi */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#define emit(frag) r_strbuf_appendf(&op->esil, frag) -#define emitf(...) r_strbuf_appendf(&op->esil, __VA_ARGS__) +#define emit(frag) rz_strbuf_appendf(&op->esil, frag) +#define emitf(...) rz_strbuf_appendf(&op->esil, __VA_ARGS__) //setting the appropriate flags, NOTE: semicolon included -#define setZ r_strbuf_appendf(&op->esil, ",$z,Z,:=") //zero flag -#define setN r_strbuf_appendf(&op->esil, ",15,$s,N,=") //negative(sign) flag -#define setV(val) r_strbuf_appendf(&op->esil, ",%s,V,=", val) //overflow flag -#define setC_B r_strbuf_appendf(&op->esil, ",7,$c,C,:=") //carry flag for byte op -#define setC_W r_strbuf_appendf(&op->esil, ",15,$c,C,:=") //carryflag for word op -#define setCb_B r_strbuf_appendf(&op->esil, ",7,$b,C,:=") //borrow flag for byte -#define setCb_W r_strbuf_appendf(&op->esil, ",15,$b,C,:=") //borrow flag for word -#define setH_B r_strbuf_appendf(&op->esil, ",3,$c,H,:=") //half carry(byte)-bcd -#define setH_W r_strbuf_appendf(&op->esil, ",11,$c,H,:=") //half carry(word)-bcd -#define setHb_B r_strbuf_appendf(&op->esil, ",3,$b,H,:=") //half borrow(byte)-bcd -#define setHb_W r_strbuf_appendf(&op->esil, ",11,$b,H,:=") //halfborrow(word)-bcd +#define setZ rz_strbuf_appendf(&op->esil, ",$z,Z,:=") //zero flag +#define setN rz_strbuf_appendf(&op->esil, ",15,$s,N,=") //negative(sign) flag +#define setV(val) rz_strbuf_appendf(&op->esil, ",%s,V,=", val) //overflow flag +#define setC_B rz_strbuf_appendf(&op->esil, ",7,$c,C,:=") //carry flag for byte op +#define setC_W rz_strbuf_appendf(&op->esil, ",15,$c,C,:=") //carryflag for word op +#define setCb_B rz_strbuf_appendf(&op->esil, ",7,$b,C,:=") //borrow flag for byte +#define setCb_W rz_strbuf_appendf(&op->esil, ",15,$b,C,:=") //borrow flag for word +#define setH_B rz_strbuf_appendf(&op->esil, ",3,$c,H,:=") //half carry(byte)-bcd +#define setH_W rz_strbuf_appendf(&op->esil, ",11,$c,H,:=") //half carry(word)-bcd +#define setHb_B rz_strbuf_appendf(&op->esil, ",3,$b,H,:=") //half borrow(byte)-bcd +#define setHb_W rz_strbuf_appendf(&op->esil, ",11,$b,H,:=") //halfborrow(word)-bcd //get reg. from opcodes #define rs() (buf[1]&0x70)>>4 //upper nibble used as source generally @@ -33,8 +33,8 @@ //work around for z flag //internally r=0xff on incr. stored as 0x100, which doesn't raise the z flag //NOTE - use the mask and setZ at last, mask will affect other flags -#define mask() r_strbuf_appendf(&op->esil, ",0xffff,r%u,&=",rd()); -#define maskB(a) r_strbuf_appendf(&op->esil, ",0xff,r%u%c,&=",rdB(a)); +#define mask() rz_strbuf_appendf(&op->esil, ",0xffff,r%u,&=",rd()); +#define maskB(a) rz_strbuf_appendf(&op->esil, ",0xff,r%u%c,&=",rdB(a)); //immediate values are always 2nd byte #define imm buf[1] @@ -44,7 +44,7 @@ https://www.classes.cs.uchicago.edu/archive/2006/winter/23000-1/docs/h8300.pdf */ -static void h8300_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { +static void h8300_anal_jmp(RzAnalOp *op, ut64 addr, const ut8 *buf) { ut16 ad; switch (buf[0]) { @@ -53,7 +53,7 @@ static void h8300_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { break; case H8300_JMP_2: op->type = R_ANAL_OP_TYPE_JMP; - r_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16)); + rz_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16)); op->jump = ad; break; case H8300_JMP_3: @@ -63,7 +63,7 @@ static void h8300_anal_jmp(RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static void h8300_anal_jsr(RAnalOp *op, ut64 addr, const ut8 *buf) { +static void h8300_anal_jsr(RzAnalOp *op, ut64 addr, const ut8 *buf) { ut16 ad; switch (buf[0]) { @@ -72,7 +72,7 @@ static void h8300_anal_jsr(RAnalOp *op, ut64 addr, const ut8 *buf) { break; case H8300_JSR_2: op->type = R_ANAL_OP_TYPE_CALL; - r_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16)); + rz_mem_swapendian ((ut8*)&ad, buf + 2, sizeof (ut16)); op->jump = ad; op->fail = addr + 4; break; @@ -83,18 +83,18 @@ static void h8300_anal_jsr(RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { +static int analop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf) { int ret = -1; ut8 opcode = buf[0]; if (!op) { return 2; } - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); switch (opcode >> 4) { case H8300_CMP_4BIT: //acc. to manual this is how it's done, could use == in esil - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,-", imm, rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,-", imm, rdB(0)); //setZ setV("%o"); setN; @@ -104,7 +104,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_OR_4BIT: - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,|=", imm, rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,|=", imm, rdB(0)); //setZ setV("0"); setN; @@ -112,7 +112,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_XOR_4BIT: - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,^=", imm, rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,^=", imm, rdB(0)); //setZ setN; setV("0"); @@ -120,7 +120,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_AND_4BIT: - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,&=", imm, rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,&=", imm, rdB(0)); //setZ setN; setV("0"); @@ -128,7 +128,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_ADD_4BIT: - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,+=", imm, rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,+=", imm, rdB(0)); //setZ setV("%o"); setN; @@ -138,7 +138,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_ADDX_4BIT: - r_strbuf_appendf(&op->esil, "0x%02x,C,+,r%u%c,+= ", imm, + rz_strbuf_appendf(&op->esil, "0x%02x,C,+,r%u%c,+= ", imm, rdB(0), rdB(0)); //setZ setV("%o"); @@ -150,7 +150,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return 0; case H8300_SUBX_4BIT: //Rd – imm – C → Rd - r_strbuf_appendf(&op->esil, "0x%02x,r%u%c,-=,C,r%u%c,-=", imm, rdB(0), rdB(0)); + rz_strbuf_appendf(&op->esil, "0x%02x,r%u%c,-=,C,r%u%c,-=", imm, rdB(0), rdB(0)); //setZ setV("%o"); setN; @@ -169,30 +169,30 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { switch (opcode) { case H8300_NOP: - r_strbuf_set (&op->esil, ","); + rz_strbuf_set (&op->esil, ","); return 0; case H8300_SLEEP: /* TODO */ return 0; case H8300_STC: - r_strbuf_appendf(&op->esil, "ccr,r%u%c,=", rdB(1)); + rz_strbuf_appendf(&op->esil, "ccr,r%u%c,=", rdB(1)); return 0; case H8300_LDC: - r_strbuf_appendf(&op->esil, "r%u%c,ccr,=", rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,ccr,=", rdB(1)); return 0; case H8300_ORC: - r_strbuf_appendf(&op->esil, "0x%02x,ccr,|=", imm); + rz_strbuf_appendf(&op->esil, "0x%02x,ccr,|=", imm); return 0; case H8300_XORC: - r_strbuf_appendf(&op->esil, "0x%02x,ccr,^=", imm); + rz_strbuf_appendf(&op->esil, "0x%02x,ccr,^=", imm); return 0; case H8300_ANDC: - r_strbuf_appendf(&op->esil, "0x%02x,ccr,&=", imm); + rz_strbuf_appendf(&op->esil, "0x%02x,ccr,&=", imm); return 0; case H8300_LDC_2: - r_strbuf_appendf(&op->esil, "0x%02x,ccr,=", imm); + rz_strbuf_appendf(&op->esil, "0x%02x,ccr,=", imm); return 0; case H8300_ADDB_DIRECT: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,+=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,+=", rsB(), rdB(1)); setH_B; setV("%o"); setC_B ; @@ -202,7 +202,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_ADDW_DIRECT: - r_strbuf_appendf (&op->esil, "r%u,r%u,+=", rs(), rd()); + rz_strbuf_appendf (&op->esil, "r%u,r%u,+=", rs(), rd()); setH_W; setV("%o"); setC_W; @@ -211,7 +211,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_INC: - r_strbuf_appendf(&op->esil, "1,r%u%c,+=", rdB(1)); + rz_strbuf_appendf(&op->esil, "1,r%u%c,+=", rdB(1)); //setZ setV("%o") ; setN; @@ -219,19 +219,19 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_ADDS: - r_strbuf_appendf (&op->esil, "%d,r%u,+=", + rz_strbuf_appendf (&op->esil, "%d,r%u,+=", ((buf[1] & 0xf0) == 0x80) ? 2 : 1, rd()); return 0; case H8300_MOV_1: /*TODO check if flags are set internally or not*/ - r_strbuf_appendf (&op->esil, "r%u%c,r%u%c,=", rsB(), rdB(1)); + rz_strbuf_appendf (&op->esil, "r%u%c,r%u%c,=", rsB(), rdB(1)); //setZ setN; maskB(1); setZ; return 0; case H8300_MOV_2: - r_strbuf_appendf(&op->esil, "r%u,r%u,=", rs(), rd()); + rz_strbuf_appendf(&op->esil, "r%u,r%u,=", rs(), rd()); //setZ setN; mask(); @@ -239,7 +239,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return 0; case H8300_ADDX: //Rd + (Rs) + C → Rd - r_strbuf_appendf (&op->esil, "r%u%c,C,+,r%u%c,+=", + rz_strbuf_appendf (&op->esil, "r%u%c,C,+,r%u%c,+=", rsB(), rdB(1), rdB(1)); //setZ setV("%o"); @@ -260,7 +260,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { case H8300_ROTR: /*TODO*/ return 0; case H8300_OR: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,|=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,|=", rsB(), rdB(1)); //setZ setV("0"); setN; @@ -268,7 +268,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_XOR: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,^=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,^=", rsB(), rdB(1)); //setZ setV("0") ; setN; @@ -276,7 +276,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_AND: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,&=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,&=", rsB(), rdB(1)); //setZ setV("0"); setN; @@ -285,7 +285,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return 0; case H8300_NOT_NEG: if ((buf[1] & 0xf0) == 0x80) { //NEG - r_strbuf_appendf(&op->esil, "r%u%c,0,-,r%u%c,=", rdB(1), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,0,-,r%u%c,=", rdB(1), rdB(1)); //setZ setHb_B; setV("%o") ; @@ -294,7 +294,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { maskB(1); setZ; } else if ((buf[1] & 0xf0) == 0x00) { //NOT - r_strbuf_appendf(&op->esil, "r%u%c,!=", rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,!=", rdB(1)); //setZ setV("0"); setN; @@ -303,7 +303,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { } return 0; case H8300_SUB_1: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-=", rsB(), rdB(1)); //setZ setHb_B; setV("%o"); @@ -313,7 +313,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_SUBW: - r_strbuf_appendf (&op->esil, "r%u,r%u,-=", rs(), rd()); + rz_strbuf_appendf (&op->esil, "r%u,r%u,-=", rs(), rd()); setHb_W; setV ("%o"); setCb_W; @@ -322,7 +322,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_DEC: - r_strbuf_appendf (&op->esil, "1,r%u%c,-=", rdB(1)); + rz_strbuf_appendf (&op->esil, "1,r%u%c,-=", rdB(1)); //setZ setV("%o"); setN; @@ -330,11 +330,11 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_SUBS: - r_strbuf_appendf(&op->esil, "%d,r%u,-=", + rz_strbuf_appendf(&op->esil, "%d,r%u,-=", ( (buf[1] & 0xf0) == 0x80) ? 2 : 1, rd()); return 0; case H8300_CMP_1: - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-", rsB(), rdB(1)); //setZ setHb_B; setV("%o"); @@ -344,7 +344,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { setZ; return 0; case H8300_CMP_2: - r_strbuf_appendf(&op->esil, "r%u,r%u,-", rs(), rd()); + rz_strbuf_appendf(&op->esil, "r%u,r%u,-", rs(), rd()); //setZ setHb_W; setV("%o"); @@ -355,7 +355,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return 0; case H8300_SUBX: //Rd – (Rs) – C → Rd - r_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-=,C,r%u%c,-=", + rz_strbuf_appendf(&op->esil, "r%u%c,r%u%c,-=,C,r%u%c,-=", rsB(), rdB(1), rdB(1)); //setZ setHb_B; @@ -368,56 +368,56 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { case H8300_DAS: /*TODO*/ return 0; case H8300_BRA: - r_strbuf_appendf(&op->esil, "0x%02x,pc,+=", buf[1]); + rz_strbuf_appendf(&op->esil, "0x%02x,pc,+=", buf[1]); return 0; case H8300_BRN: - r_strbuf_appendf(&op->esil,","); + rz_strbuf_appendf(&op->esil,","); return 0; case H8300_BHI: - r_strbuf_appendf(&op->esil, "C,Z,|,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "C,Z,|,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BLS: - r_strbuf_appendf(&op->esil, "C,Z,|,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "C,Z,|,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BCC: - r_strbuf_appendf(&op->esil, "C,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "C,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BCS: - r_strbuf_appendf(&op->esil, "C,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "C,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BNE: - r_strbuf_appendf(&op->esil, "Z,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "Z,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BEQ: - r_strbuf_appendf(&op->esil, "Z,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "Z,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BVC: - r_strbuf_appendf(&op->esil, "V,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "V,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BVS: - r_strbuf_appendf(&op->esil, "V,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "V,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BPL: - r_strbuf_appendf(&op->esil, "N,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "N,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BMI: - r_strbuf_appendf(&op->esil, "N,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "N,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BGE: - r_strbuf_appendf(&op->esil, "N,V,^,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "N,V,^,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BLT: - r_strbuf_appendf(&op->esil, "N,V,^,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "N,V,^,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BGT: - r_strbuf_appendf(&op->esil, "Z,N,V,^,|,!,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "Z,N,V,^,|,!,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_BLE: - r_strbuf_appendf(&op->esil, "Z,N,V,^,|,?{0x%02x,pc,+=}", buf[1]); + rz_strbuf_appendf(&op->esil, "Z,N,V,^,|,?{0x%02x,pc,+=}", buf[1]); return 0; case H8300_MULXU: //Refer to pg. 100 of the manual linked at the beginning - r_strbuf_appendf(&op->esil, "r%u%c,r%ul,*,r%u,=", + rz_strbuf_appendf(&op->esil, "r%u%c,r%ul,*,r%u,=", rsB(), rd(), rd()); return 0; case H8300_DIVXU: /*TODO*/ return 0; @@ -434,26 +434,26 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { //NOTE - cases marked with TODO have mem. access also(not impl.) case H8300_BSET_1: /*TODO*/ //set rs&0x7th bit of rd. expr.- rd|= 1<<(rs&0x07) - r_strbuf_appendf(&op->esil, "0x7,r%u%c,&,1,<<,r%u%c,|=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "0x7,r%u%c,&,1,<<,r%u%c,|=", rsB(), rdB(1)); return 0; case H8300_BNOT_1: /*TODO*/ //invert rs&0x7th bit of rd. expr.- rd^= 1<<(rs&0x07) - r_strbuf_appendf(&op->esil,"0x07,r%u%c,&,1,<<,r%u%c,^=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil,"0x07,r%u%c,&,1,<<,r%u%c,^=", rsB(), rdB(1)); return 0; case H8300_BCLR_R2R8: /*TODO*/ //clear rs&0x7th bit of rd. expr.- rd&= !(1<<(rs&0x07)) - r_strbuf_appendf(&op->esil, "0x7,r%u%c,&,1,<<,!,r%u%c,&=", rsB(), rdB(1)); + rz_strbuf_appendf(&op->esil, "0x7,r%u%c,&,1,<<,!,r%u%c,&=", rsB(), rdB(1)); return 0; case H8300_BTST_R2R8: /*TODO*/ //¬ ( of ) → Z, extract bit value and shift it back - r_strbuf_appendf(&op->esil, "0x7,r%u%c,&,0x7,r%u%c,&,1,<<,r%u%c,&,>>,!,Z,=", + rz_strbuf_appendf(&op->esil, "0x7,r%u%c,&,0x7,r%u%c,&,1,<<,r%u%c,&,>>,!,Z,=", rsB(), rsB(), rdB(1)); return 0; case H8300_BST_BIST: /*TODO*/ if (!(buf[1] & 0x80)) { //BST - r_strbuf_appendf(&op->esil,"%d,C,<<,r%u%c,|=",rs(),rdB(1)); + rz_strbuf_appendf(&op->esil,"%d,C,<<,r%u%c,|=",rs(),rdB(1)); } else { //BIST - r_strbuf_appendf (&op->esil, "%d,C,!,<<,r%u%c,|=", rs (), rdB (1)); + rz_strbuf_appendf (&op->esil, "%d,C,!,<<,r%u%c,|=", rs (), rdB (1)); } return 0; case H8300_MOV_R82IND16: /*TODO*/ return 0; @@ -467,39 +467,39 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return 0; case H8300_BSET_2: /*TODO*/ //set imm bit of rd. expr.- rd|= (1<esil, "%d,1,<<,r%u%c,|=", rs(), rdB(1)); + rz_strbuf_appendf(&op->esil, "%d,1,<<,r%u%c,|=", rs(), rdB(1)); return 0; case H8300_BNOT_2: /*TODO*/ //inv. imm bit of rd. expr.- rd^= (1<esil,"%d,1,<<,r%u%c,^=",rs(),rdB(1)); + rz_strbuf_appendf(&op->esil,"%d,1,<<,r%u%c,^=",rs(),rdB(1)); return 0; case H8300_BCLR_IMM2R8: //clear imm bit of rd. expr.- rd&= !(1<esil, "%d,1,<<,!,r%u%c,&=", rs(), rdB(1)); + rz_strbuf_appendf(&op->esil, "%d,1,<<,!,r%u%c,&=", rs(), rdB(1)); return 0; case H8300_BTST: /*TODO*/ //see BTST above - r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,Z,=", + rz_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,Z,=", rs(), rs(), rdB(1)); return 0; case H8300_BOR_BIOR: /*TODO*/ if (!(buf[1] & 0x80)) { //BOR //C|=(rd&(1<>imm - r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,|=", + rz_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,|=", rs(), rs(), rdB(1)); } else { //BIOR //C|=!(rd&(1<>imm - r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,|=", + rz_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,|=", rs (), rs (), rdB (1)); } return 0; case H8300_BXOR_BIXOR: /*TODO*/ if (!(buf[1] & 0x80)) { //BXOR //C^=(rd&(1<>imm - r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,^=", + rz_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,^=", rs(), rs(), rdB(1)); } else { //BIXOR - r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,^=", + rz_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,^=", rs (), rs (), rdB (1)); } return 0; @@ -507,20 +507,20 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { /*TODO check functionality*/ //C&=(rd&(1<>imm if (!(buf[1] & 0x80)) { //BAND - r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,&=", + rz_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,&=", rs(), rs(), rdB(1)); } else { //BIAND - r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,&=", + rz_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,&=", rs (), rs (), rdB (1)); } return 0; case H8300_BILD_IMM2R8: /*TODO*/ if (!(buf[1] & 0x80)) { //BLD - r_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,=", + rz_strbuf_appendf(&op->esil, "%d,%d,1,<<,r%u%c,&,>>,C,=", rs(), rs(), rdB(1)); } else { //BILD - r_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,=", + rz_strbuf_appendf (&op->esil, "%d,%d,1,<<,r%u%c,&,>>,!,C,=", rs (), rs (), rdB (1)); } return 0; @@ -537,8 +537,8 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf) { return ret; } -static int h8300_op(RAnal *anal, RAnalOp *op, ut64 addr, - const ut8 *buf, int len, RAnalOpMask mask) +static int h8300_op(RzAnal *anal, RzAnalOp *op, ut64 addr, + const ut8 *buf, int len, RzAnalOpMask mask) { int ret; ut8 opcode = buf[0]; @@ -680,7 +680,7 @@ static int h8300_op(RAnal *anal, RAnalOp *op, ut64 addr, return ret; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { char *p = "=PC pc\n" "=SP r7\n" @@ -718,10 +718,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr Z .1 .146 0\n" "gpr V .1 .145 0\n" "gpr C .1 .144 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_h8300 = { +RzAnalPlugin rz_anal_plugin_h8300 = { .name = "h8300", .desc = "H8300 code analysis plugin", .license = "LGPL3", @@ -733,9 +733,9 @@ RAnalPlugin r_anal_plugin_h8300 = { }; #ifndef R2_PLUGIN_INCORE -struct r_lib_struct_t radare_plugin = { +struct rz_lib_struct_t radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_h8300, + .data = &rz_anal_plugin_h8300, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_hexagon.c b/librz/anal/p/anal_hexagon.c similarity index 80% rename from libr/anal/p/anal_hexagon.c rename to librz/anal/p/anal_hexagon.c index 1cbaa797f7..898ccb5a3b 100644 --- a/libr/anal/p/anal_hexagon.c +++ b/librz/anal/p/anal_hexagon.c @@ -1,18 +1,18 @@ /* radare - LGPL - Copyright 2018 - xvilka */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "hexagon.h" #include "hexagon_insn.h" #include "hexagon_anal.h" -static int hexagon_v6_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int hexagon_v6_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { HexInsn hi = {0};; ut32 data = 0; - data = r_read_le32 (buf); + data = rz_read_le32 (buf); int size = hexagon_disasm_instruction (data, &hi, (ut32) addr); op->size = size; if (size <= 0) { @@ -23,7 +23,7 @@ static int hexagon_v6_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, in return hexagon_anal_instruction (&hi, op); } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { // TODO: Add missing registers const char *p = "=PC pc\n" @@ -80,10 +80,10 @@ static bool set_reg_profile(RAnal *anal) { "flg s .1 132.30 0\n" "flg z .1 132.31 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_hexagon = { +RzAnalPlugin rz_anal_plugin_hexagon = { .name = "hexagon", .desc = "Qualcomm Hexagon (QDSP6) V6", .license = "LGPL3", @@ -95,9 +95,9 @@ RAnalPlugin r_anal_plugin_hexagon = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_hexagon_v6, + .data = &rz_anal_plugin_hexagon_v6, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_i4004.c b/librz/anal/p/anal_i4004.c similarity index 91% rename from libr/anal/p/anal_i4004.c rename to librz/anal/p/anal_i4004.c index ccea364bd1..4eb1d93d09 100644 --- a/libr/anal/p/anal_i4004.c +++ b/librz/anal/p/anal_i4004.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2016-2020 - pancake */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define AVR_SOFTCAST(x,y) ((x)+((y)*0x100)) -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC PC\n" /* syntax not yet supported */ @@ -42,7 +42,7 @@ static bool set_reg_profile(RAnal *anal) { "gpr PC3 .64 34 0\n" ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } /* That 3 is a hack */ @@ -97,7 +97,7 @@ static int i4004_get_ins_len (ut8 hex) { return ret; } -static int i4004_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int i4004_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { char basm[128]; const size_t basz = sizeof (basm)-1; int rlen = i4004_get_ins_len (*buf); @@ -201,7 +201,7 @@ static int i4004_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len return op->size = rlen; } -RAnalPlugin r_anal_plugin_i4004 = { +RzAnalPlugin rz_anal_plugin_i4004 = { .name = "i4004", .desc = "i4004 code analysis plugin", .license = "LGPL3", @@ -213,9 +213,9 @@ RAnalPlugin r_anal_plugin_i4004 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_i4004, + .data = &rz_anal_plugin_i4004, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_i8080.c b/librz/anal/p/anal_i8080.c similarity index 91% rename from libr/anal/p/anal_i8080.c rename to librz/anal/p/anal_i8080.c index 90db984055..b469673aa3 100644 --- a/libr/anal/p/anal_i8080.c +++ b/librz/anal/p/anal_i8080.c @@ -4,14 +4,14 @@ // the Intel 8080 disassembler by Alexander Demin, 2012. #include -#include -#include -#include -#include +#include +#include +#include +#include // hack #include "../../asm/arch/i8080/i8080dis.c" -static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int i8080_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { char out[32]; int ilen = i8080_disasm (data, out, len); op->addr = addr; @@ -187,7 +187,7 @@ static int i8080_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le return op->size = ilen; } -RAnalPlugin r_anal_plugin_i8080 = { +RzAnalPlugin rz_anal_plugin_i8080 = { .name = "i8080", .desc = "I8080 CPU code analysis plugin", .license = "LGPL3", @@ -197,9 +197,9 @@ RAnalPlugin r_anal_plugin_i8080 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_i8080, + .data = &rz_anal_plugin_i8080, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_java.c b/librz/anal/p/anal_java.c similarity index 86% rename from libr/anal/p/anal_java.c rename to librz/anal/p/anal_java.c index c009e9928e..da8c4713a5 100644 --- a/libr/anal/p/anal_java.c +++ b/librz/anal/p/anal_java.c @@ -3,9 +3,9 @@ #include -#include -#include -#include +#include +#include +#include #include "../../../shlr/java/ops.h" #include "../../../shlr/java/code.h" @@ -21,15 +21,15 @@ ut64 METHOD_START = 0; -static void java_update_anal_types (RAnal *anal, RBinJavaObj *bin_obj); +static void java_update_anal_types (RzAnal *anal, RBinJavaObj *bin_obj); -static int java_cmd_ext(RAnal *anal, const char* input); +static int java_cmd_ext(RzAnal *anal, const char* input); -static int java_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask); +static int java_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask); -static RBinJavaObj * get_java_bin_obj(RAnal *anal); +static RBinJavaObj * get_java_bin_obj(RzAnal *anal); -static RBinJavaObj * get_java_bin_obj(RAnal *anal) { +static RBinJavaObj * get_java_bin_obj(RzAnal *anal) { RBin *b = anal->binb.bin; RBinPlugin *plugin = b->cur && b->cur->o ? b->cur->o->plugin : NULL; ut8 is_java = (plugin && strcmp (plugin->name, "java") == 0) ? 1 : 0; @@ -40,7 +40,7 @@ static ut64 java_get_method_start(void) { return METHOD_START; } -static int java_switch_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len) { +static int java_switch_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len) { ut8 op_byte = data[0]; ut64 offset = addr - java_get_method_start (); ut8 pos = (offset + 1)%4 ? 1 + 4 - (offset+1)%4 : 1; @@ -54,10 +54,10 @@ static int java_switch_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, const int max_val = (ut32)(UINT (data, pos + 8)); ut32 default_loc = (ut32) (UINT (data, pos)), cur_case = 0; - op->switch_op = r_anal_switch_op_new (addr, min_val, max_val, default_loc); + op->switch_op = rz_anal_switch_op_new (addr, min_val, max_val, default_loc); pos += 12; if (max_val > min_val && ((max_val - min_val)<(UT16_MAX/4))) { - //caseop = r_anal_switch_op_add_case(op->switch_op, addr+default_loc, -1, addr+offset); + //caseop = rz_anal_switch_op_add_case(op->switch_op, addr+default_loc, -1, addr+offset); for (cur_case = 0; cur_case <= max_val - min_val; pos += 4, cur_case++) { //ut32 value = (ut32)(UINT (data, pos)); if (pos + 4 >= len) { @@ -65,7 +65,7 @@ static int java_switch_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, break; } int offset = (int)(ut32)(R_BIN_JAVA_UINT (data, pos)); - r_anal_switch_op_add_case (op->switch_op, addr + pos, cur_case + min_val, addr + offset); + rz_anal_switch_op_add_case (op->switch_op, addr + pos, cur_case + min_val, addr + offset); } } else { eprintf ("Invalid switch boundaries at 0x%"PFMT64x"\n", addr); @@ -189,7 +189,7 @@ static ut64 map_java_op_to_anal_op_type (ut64 t) { return R_ANAL_OP_TYPE_UNK; } -static int r_anal_java_is_op_type_eop(ut64 x) { +static int rz_anal_java_is_op_type_eop(ut64 x) { ut8 result = (x & R_ANAL_JAVA_CODE_OP) ? 1 : 0; return result && ( (x & R_ANAL_JAVA_CODEOP_LEAVE) == R_ANAL_JAVA_CODEOP_LEAVE || @@ -199,7 +199,7 @@ static int r_anal_java_is_op_type_eop(ut64 x) { } -static int java_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int java_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { /* get opcode size */ if (len < 1) { op->type = R_ANAL_OP_TYPE_ILL; @@ -244,9 +244,9 @@ static int java_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len } */ - op->eob = r_anal_java_is_op_type_eop (op->type2); + op->eob = rz_anal_java_is_op_type_eop (op->type2); IFDBG { - const char *ot_str = r_anal_optype_to_string (op->type); + const char *ot_str = rz_anal_optype_to_string (op->type); eprintf ("op_type2: %s @ 0x%04"PFMT64x" 0x%08"PFMT64x" op_type: (0x%02"PFMT64x") %s.\n", JAVA_OPS[op_byte].name, addr, (ut64)op->type2, (ut64)op->type, ot_str); //eprintf ("op_eob: 0x%02x.\n", op->eob); @@ -280,31 +280,31 @@ static int java_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len //IFDBG eprintf ("%s callto 0x%04x failto 0x%04x.\n", JAVA_OPS[op_byte].name, op->jump, op->fail); } - //r_java_disasm(addr, data, len, output, outlen); + //rz_java_disasm(addr, data, len, output, outlen); //IFDBG eprintf ("%s\n", output); return op->size; } -static void java_update_anal_types (RAnal *anal, RBinJavaObj *bin_obj) { +static void java_update_anal_types (RzAnal *anal, RBinJavaObj *bin_obj) { Sdb *D = anal->sdb_types; if (D && bin_obj) { - RListIter *iter; + RzListIter *iter; char *str; - RList * the_list = r_bin_java_extract_all_bin_type_values (bin_obj); + RzList * the_list = rz_bin_java_extract_all_bin_type_values (bin_obj); if (the_list) { - r_list_foreach (the_list, iter, str) { + rz_list_foreach (the_list, iter, str) { IFDBG eprintf ("Adding type: %s to known types.\n", str); if (str) { sdb_set (D, str, "type", 0); } } } - r_list_free (the_list); + rz_list_free (the_list); } } -static int java_cmd_ext(RAnal *anal, const char* input) { +static int java_cmd_ext(RzAnal *anal, const char* input) { RBinJavaObj *obj = (RBinJavaObj *) get_java_bin_obj (anal); if (!obj) { @@ -314,7 +314,7 @@ static int java_cmd_ext(RAnal *anal, const char* input) { switch (*input) { case 'c': // reset bytes counter for case operations - r_java_new_method (); + rz_java_new_method (); break; case 'u': switch (*(input+1)) { @@ -334,7 +334,7 @@ static int java_cmd_ext(RAnal *anal, const char* input) { return 0; } -RAnalPlugin r_anal_plugin_java = { +RzAnalPlugin rz_anal_plugin_java = { .name = "java", .desc = "Java bytecode analysis plugin", .license = "Apache", @@ -346,9 +346,9 @@ RAnalPlugin r_anal_plugin_java = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_java, + .data = &rz_anal_plugin_java, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_m680x_cs.c b/librz/anal/p/anal_m680x_cs.c similarity index 96% rename from libr/anal/p/anal_m680x_cs.c rename to librz/anal/p/anal_m680x_cs.c index d5ef94946b..b7e0579471 100644 --- a/libr/anal/p/anal_m680x_cs.c +++ b/librz/anal/p/anal_m680x_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2015-2019 - pancake */ +/* rizin - LGPL - Copyright 2015-2019 - pancake */ -#include -#include +#include +#include #include #if CS_API_MAJOR >= 4 && CS_API_MINOR >= 0 @@ -59,7 +59,7 @@ static int m680xmode(const char *str) { #define IMM(x) insn->detail->m680x.operands[x].imm #define REL(x) insn->detail->m680x.operands[x].rel -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int n, ret, opsize = -1; static csh handle = 0; static int omode = -1; @@ -515,7 +515,7 @@ fin: } // XXX -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = \ "=PC pc\n" "=SP sp\n" @@ -525,10 +525,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr sp .16 48 0\n" "gpr a0 .16 48 0\n" "gpr a1 .16 48 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_m680x_cs = { +RzAnalPlugin rz_anal_plugin_m680x_cs = { .name = "m680x", .desc = "Capstone M680X analysis plugin", .license = "BSD", @@ -539,7 +539,7 @@ RAnalPlugin r_anal_plugin_m680x_cs = { .op = &analop, }; #else -RAnalPlugin r_anal_plugin_m680x_cs = { +RzAnalPlugin rz_anal_plugin_m680x_cs = { .name = "m680x (unsupported)", .desc = "Capstone M680X analyzer (unsupported)", .license = "BSD", @@ -549,9 +549,9 @@ RAnalPlugin r_anal_plugin_m680x_cs = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_m680x_cs, + .data = &rz_anal_plugin_m680x_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_m68k_cs.c b/librz/anal/p/anal_m68k_cs.c similarity index 88% rename from libr/anal/p/anal_m68k_cs.c rename to librz/anal/p/anal_m68k_cs.c index e6a885acf7..d0dabcc296 100644 --- a/libr/anal/p/anal_m68k_cs.c +++ b/librz/anal/p/anal_m68k_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2015-2018 - pancake */ +/* rizin - LGPL - Copyright 2015-2018 - pancake */ -#include -#include +#include +#include #include #ifdef CAPSTONE_M68K_H @@ -30,7 +30,7 @@ static inline ut64 make_64bits_address(ut64 address) { return UT32_MAX & address; } -static inline void handle_branch_instruction(RAnalOp *op, ut64 addr, cs_m68k *m68k, ut32 type, int index) { +static inline void handle_branch_instruction(RzAnalOp *op, ut64 addr, cs_m68k *m68k, ut32 type, int index) { #if CS_API_MAJOR >= 4 if (m68k->operands[index].type == M68K_OP_BR_DISP) { op->type = type; @@ -46,7 +46,7 @@ static inline void handle_branch_instruction(RAnalOp *op, ut64 addr, cs_m68k *m6 #endif } -static inline void handle_jump_instruction(RAnalOp *op, ut64 addr, cs_m68k *m68k, ut32 type) { +static inline void handle_jump_instruction(RzAnalOp *op, ut64 addr, cs_m68k *m68k, ut32 type) { op->type = type; // Handle PC relative mode jump @@ -61,55 +61,55 @@ static inline void handle_jump_instruction(RAnalOp *op, ut64 addr, cs_m68k *m68k static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_m68k *x = &insn->detail->m68k; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_m68k_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case M68K_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case M68K_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case M68K_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base_reg != M68K_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.base_reg)); + rz_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.base_reg)); } if (op->mem.index_reg != M68K_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.index_reg)); + rz_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.index_reg)); } if (op->mem.in_base_reg != M68K_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.in_base_reg)); + rz_strbuf_appendf (buf, ",\"base_reg\":\"%s\"", cs_reg_name (handle, op->mem.in_base_reg)); } - r_strbuf_appendf (buf, ",\"in_disp\":%"PFMT64d"", op->mem.in_disp); - r_strbuf_appendf (buf, ",\"out_disp\":%"PFMT64d"", op->mem.out_disp); - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64)op->mem.disp); - r_strbuf_appendf (buf, ",\"scale\":%"PFMT64d"", (st64)op->mem.scale); - r_strbuf_appendf (buf, ",\"bitfield\":%"PFMT64d"", (st64)op->mem.bitfield); - r_strbuf_appendf (buf, ",\"width\":%"PFMT64d"", (st64)op->mem.width); - r_strbuf_appendf (buf, ",\"offset\":%"PFMT64d"", (st64)op->mem.offset); - r_strbuf_appendf (buf, ",\"index_size\":%"PFMT64d"", (st64)op->mem.index_size); + rz_strbuf_appendf (buf, ",\"in_disp\":%"PFMT64d"", op->mem.in_disp); + rz_strbuf_appendf (buf, ",\"out_disp\":%"PFMT64d"", op->mem.out_disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64)op->mem.disp); + rz_strbuf_appendf (buf, ",\"scale\":%"PFMT64d"", (st64)op->mem.scale); + rz_strbuf_appendf (buf, ",\"bitfield\":%"PFMT64d"", (st64)op->mem.bitfield); + rz_strbuf_appendf (buf, ",\"width\":%"PFMT64d"", (st64)op->mem.width); + rz_strbuf_appendf (buf, ",\"offset\":%"PFMT64d"", (st64)op->mem.offset); + rz_strbuf_appendf (buf, ",\"index_size\":%"PFMT64d"", (st64)op->mem.index_size); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]}"); + rz_strbuf_append (buf, "]}"); } -static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num) { if (!reg) { return -1; } @@ -128,18 +128,18 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) return 0; } -static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { - static RRegItem reg; +static void op_fillval(RzAnalOp *op, csh handle, cs_insn *insn) { + static RzRegItem reg; switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_MOV: ZERO_FILL (reg); if (OPERAND(1).type == M68K_OP_MEM) { - op->src[0] = r_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->reg = ® parse_reg_name (op->src[0]->reg, handle, insn, 1); op->src[0]->delta = OPERAND(0).mem.disp; } else if (OPERAND(0).type == M68K_OP_MEM) { - op->dst = r_anal_value_new (); + op->dst = rz_anal_value_new (); op->dst->reg = ® parse_reg_name (op->dst->reg, handle, insn, 0); op->dst->delta = OPERAND(1).mem.disp; @@ -148,7 +148,7 @@ static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { case R_ANAL_OP_TYPE_LEA: ZERO_FILL (reg); if (OPERAND(1).type == M68K_OP_MEM) { - op->dst = r_anal_value_new (); + op->dst = rz_anal_value_new (); op->dst->reg = ® parse_reg_name (op->dst->reg, handle, insn, 1); op->dst->delta = OPERAND(1).mem.disp; @@ -157,7 +157,7 @@ static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { } } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int n, ret, opsize = -1; static csh handle = 0; static int omode = -1; @@ -702,7 +702,7 @@ fin: return opsize; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = \ "=PC pc\n" "=SP a7\n" @@ -757,10 +757,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr fpcr .32 176 0\n" "gpr fpsr .32 180 0\n" "gpr fpiar .32 184 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_m68k_cs = { +RzAnalPlugin rz_anal_plugin_m68k_cs = { .name = "m68k", .desc = "Capstone M68K analyzer", .license = "BSD", @@ -771,7 +771,7 @@ RAnalPlugin r_anal_plugin_m68k_cs = { .op = &analop, }; #else -RAnalPlugin r_anal_plugin_m68k_cs = { +RzAnalPlugin rz_anal_plugin_m68k_cs = { .name = "m68k (unsupported)", .desc = "Capstone M68K analyzer (unsupported)", .license = "BSD", @@ -781,9 +781,9 @@ RAnalPlugin r_anal_plugin_m68k_cs = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_m68k_cs, + .data = &rz_anal_plugin_m68k_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_malbolge.c b/librz/anal/p/anal_malbolge.c similarity index 74% rename from libr/anal/p/anal_malbolge.c rename to librz/anal/p/anal_malbolge.c index 6afaa7dc37..68b4bc4b11 100644 --- a/libr/anal/p/anal_malbolge.c +++ b/librz/anal/p/anal_malbolge.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2015 - condret */ -#include -#include -#include +#include +#include +#include -static int mal_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int mal_anal(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { if (len) { switch ((data[0] + addr) % 94) { case 4: @@ -36,7 +36,7 @@ static int mal_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le return false; } -RAnalPlugin r_anal_plugin_malbolge = { +RzAnalPlugin rz_anal_plugin_malbolge = { .name = "malbolge", .desc = "Malbolge analysis plugin", .arch = "malbolge", @@ -46,9 +46,9 @@ RAnalPlugin r_anal_plugin_malbolge = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_malbolge, + .data = &rz_anal_plugin_malbolge, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_mcore.c b/librz/anal/p/anal_mcore.c similarity index 86% rename from libr/anal/p/anal_mcore.c rename to librz/anal/p/anal_mcore.c index 827995592c..0cf19acee9 100644 --- a/libr/anal/p/anal_mcore.c +++ b/librz/anal/p/anal_mcore.c @@ -1,11 +1,11 @@ /* radare - LGPL3 - Copyright 2018 - deroad */ -#include -#include -#include +#include +#include +#include #include "../../asm/arch/mcore/mcore.h" -static int mcore_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int mcore_anal(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { mcore_handle handle = {0}; mcore_t* instr = NULL; @@ -43,7 +43,7 @@ static int mcore_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int l return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = \ "=PC pc\n" "=SP r1\n" @@ -106,14 +106,14 @@ static bool set_reg_profile(RAnal *anal) { "gpr cr30 .32 184 0\n" "gpr cr31 .32 188 0\n" "gpr pc .32 192 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 2; } -RAnalPlugin r_anal_plugin_mcore = { +RzAnalPlugin rz_anal_plugin_mcore = { .name = "mcore", .desc = "MCore analysis plugin", .arch = "mcore", @@ -125,9 +125,9 @@ RAnalPlugin r_anal_plugin_mcore = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_mcore, + .data = &rz_anal_plugin_mcore, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_mips_cs.c b/librz/anal/p/anal_mips_cs.c similarity index 76% rename from libr/anal/p/anal_mips_cs.c rename to librz/anal/p/anal_mips_cs.c index 7181abc38f..8550744e7f 100644 --- a/libr/anal/p/anal_mips_cs.c +++ b/librz/anal/p/anal_mips_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ -#include -#include +#include +#include #include #include @@ -24,30 +24,30 @@ static ut64 t9_pre = UT64_MAX; } #define CREATE_SRC_DST_3(op) \ - (op)->src[0] = r_anal_value_new ();\ - (op)->src[1] = r_anal_value_new ();\ - (op)->dst = r_anal_value_new (); + (op)->src[0] = rz_anal_value_new ();\ + (op)->src[1] = rz_anal_value_new ();\ + (op)->dst = rz_anal_value_new (); #define CREATE_SRC_DST_2(op) \ - (op)->src[0] = r_anal_value_new ();\ - (op)->dst = r_anal_value_new (); + (op)->src[0] = rz_anal_value_new ();\ + (op)->dst = rz_anal_value_new (); #define SET_SRC_DST_3_REGS(op) \ CREATE_SRC_DST_3 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ - (op)->src[1]->reg = r_reg_get (anal->reg, REG (2), R_REG_TYPE_GPR); + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ + (op)->src[1]->reg = rz_reg_get (anal->reg, REG (2), R_REG_TYPE_GPR); #define SET_SRC_DST_3_IMM(op) \ CREATE_SRC_DST_3 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ (op)->src[1]->imm = IMM (2); #define SET_SRC_DST_2_REGS(op) \ CREATE_SRC_DST_2 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR); + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR); #define SET_SRC_DST_3_REG_OR_IMM(op) \ if (OPERAND(2).type == MIPS_OP_IMM) {\ @@ -93,70 +93,70 @@ static ut64 t9_pre = UT64_MAX; #define ES_ADD_CK32_OVERF(x, y, z) es_add_ck (op, x, y, z, 32) #define ES_ADD_CK64_OVERF(x, y, z) es_add_ck (op, x, y, z, 64) -static inline void es_sign_n_64(RAnal *a, RAnalOp *op, const char *arg, int bit) +static inline void es_sign_n_64(RzAnal *a, RzAnalOp *op, const char *arg, int bit) { if (a->bits == 64) { - r_strbuf_appendf (&op->esil, ",%d,%s,~,%s,=,", bit, arg, arg); + rz_strbuf_appendf (&op->esil, ",%d,%s,~,%s,=,", bit, arg, arg); } else { - r_strbuf_append (&op->esil,","); + rz_strbuf_append (&op->esil,","); } } -static inline void es_add_ck(RAnalOp *op, const char *a1, const char *a2, const char *re, int bit) +static inline void es_add_ck(RzAnalOp *op, const char *a1, const char *a2, const char *re, int bit) { ut64 mask = 1ULL << (bit-1); - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "%d,0x%lx,%s,%s,^,&,>>,%d,0x%lx,%s,%s,+,&,>>,|,1,==,$z,?{,$$,1,TRAP,}{,%s,%s,+,%s,=,}", bit-2, mask, a1, a2, bit-1, mask, a1, a2, a1, a2, re); } #define PROTECT_ZERO() \ if (REG(0)[0]=='z'){\ - r_strbuf_appendf (&op->esil, ",");\ + rz_strbuf_appendf (&op->esil, ",");\ } else #define ESIL_LOAD(size) \ PROTECT_ZERO () {\ - r_strbuf_appendf (&op->esil, "%s,["size"],%s,=",\ + rz_strbuf_appendf (&op->esil, "%s,["size"],%s,=",\ ARG(1), REG(0));\ } static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_mips *x = &insn->detail->mips; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_mips_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case MIPS_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case MIPS_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case MIPS_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != MIPS_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "}"); } static const char *arg(csh *handle, cs_insn *insn, char *buf, int n) { @@ -197,12 +197,12 @@ static const char *arg(csh *handle, cs_insn *insn, char *buf, int n) { #define ARG(x) (*str[x]!=0)?str[x]:arg(handle, insn, str[x], x) -static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { +static int analop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { char str[8][32] = {{0}}; int i; - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); if (insn) { // caching operands @@ -215,31 +215,31 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len if (insn) { switch (insn->id) { case MIPS_INS_NOP: - r_strbuf_setf (&op->esil, ","); + rz_strbuf_setf (&op->esil, ","); break; case MIPS_INS_BREAK: - r_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0)); + rz_strbuf_setf (&op->esil, "%d,%d,TRAP", IMM (0), IMM (0)); break; case MIPS_INS_SD: - r_strbuf_appendf (&op->esil, "%s,%s,=[8]", + rz_strbuf_appendf (&op->esil, "%s,%s,=[8]", ARG (0), ARG (1)); break; case MIPS_INS_SW: case MIPS_INS_SWL: case MIPS_INS_SWR: - r_strbuf_appendf (&op->esil, "%s,%s,=[4]", + rz_strbuf_appendf (&op->esil, "%s,%s,=[4]", ARG (0), ARG (1)); break; case MIPS_INS_SH: - r_strbuf_appendf (&op->esil, "%s,%s,=[2]", + rz_strbuf_appendf (&op->esil, "%s,%s,=[2]", ARG (0), ARG (1)); break; case MIPS_INS_SWC1: case MIPS_INS_SWC2: - r_strbuf_setf (&op->esil, "%s,$", ARG (1)); + rz_strbuf_setf (&op->esil, "%s,$", ARG (1)); break; case MIPS_INS_SB: - r_strbuf_appendf (&op->esil, "%s,%s,=[1]", + rz_strbuf_appendf (&op->esil, "%s,%s,=[1]", ARG (0), ARG (1)); break; case MIPS_INS_CMP: @@ -247,10 +247,10 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case MIPS_INS_CMPGU: case MIPS_INS_CMPGDU: case MIPS_INS_CMPI: - r_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,==", ARG (1), ARG (0)); break; case MIPS_INS_DSRA: - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "%s,%s,>>,31,%s,>>,?{,32,%s,32,-,0xffffffff,<<,0xffffffff,&,<<,}{,0,},|,%s,=", ARG (2), ARG (1), ARG (1), ARG (2), ARG (0)); break; @@ -259,7 +259,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case MIPS_INS_SHRA: case MIPS_INS_SHRA_R: case MIPS_INS_SRA: - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "0xffffffff,%s,%s,>>,&,31,%s,>>,?{,%s,32,-,0xffffffff,<<,0xffffffff,&,}{,0,},|,%s,=", ARG (2), ARG (1), ARG (1), ARG (2), ARG (0)); break; @@ -267,135 +267,135 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len // suffix 'S' forces conditional flag to be updated case MIPS_INS_SRLV: case MIPS_INS_SRL: - r_strbuf_appendf (&op->esil, "%s,%s,>>,%s,=", ARG (2), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,>>,%s,=", ARG (2), ARG (1), ARG (0)); break; case MIPS_INS_SLLV: case MIPS_INS_SLL: - r_strbuf_appendf (&op->esil, "%s,%s,<<,%s,=", ARG (2), ARG (1), ARG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,<<,%s,=", ARG (2), ARG (1), ARG (0)); break; case MIPS_INS_BAL: case MIPS_INS_JAL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0)); break; case MIPS_INS_JALR: case MIPS_INS_JALRS: if (OPCOUNT () < 2) { - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_D ("%s"), ARG (0)); } else { PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_DR ("%s", "%s"), ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_DR ("%s", "%s"), ARG (0), ARG (1)); } } break; case MIPS_INS_JALRC: // no delay if (OPCOUNT () < 2) { - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_ND ("%s"), ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_ND ("%s"), ARG (0)); } else { PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_NDR ("%s", "%s"), ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_CALL_NDR ("%s", "%s"), ARG (0), ARG (1)); } } break; case MIPS_INS_JRADDIUSP: // increment stackpointer in X and jump to %ra - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%d,sp,+=," ES_J ("ra"), ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%d,sp,+=," ES_J ("ra"), ARG (0)); break; case MIPS_INS_JR: case MIPS_INS_JRC: case MIPS_INS_J: case MIPS_INS_B: // ??? // jump to address with conditional - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_J ("%s"), ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "" ES_J ("%s"), ARG (0)); break; case MIPS_INS_BNE: // bne $s, $t, offset case MIPS_INS_BNEL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,!,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,!,?{," ES_J ("%s") ",}", ARG (0), ARG (1), ARG (2)); break; case MIPS_INS_BEQ: case MIPS_INS_BEQL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,%s,==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1), ARG (2)); break; case MIPS_INS_BZ: case MIPS_INS_BEQZ: case MIPS_INS_BEQZC: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BNEZ: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,!,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,!,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BEQZALC: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_CALL_ND ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "%s,0,==,$z,?{," ES_CALL_ND ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BLEZ: case MIPS_INS_BLEZC: case MIPS_INS_BLEZL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{," ES_J ("%s") ",BREAK,},", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{," ES_J ("%s") ",BREAK,},", ARG (0), ARG (1)); - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BGEZ: case MIPS_INS_BGEZC: case MIPS_INS_BGEZL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BGEZAL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BGEZALC: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BGTZALC: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0)); - r_strbuf_appendf (&op->esil, "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0)); + rz_strbuf_appendf (&op->esil, "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_ND ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BLTZAL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}", ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_CALL_D ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BLTZ: case MIPS_INS_BLTZC: case MIPS_INS_BLTZL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "1," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BGTZ: case MIPS_INS_BGTZC: case MIPS_INS_BGTZL: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0)); - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,%s,==,$z,?{,BREAK,},", ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0," ES_IS_NEGATIVE ("%s") ",==,$z,?{," ES_J ("%s") ",}", ARG (0), ARG (1)); break; case MIPS_INS_BTEQZ: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,?{," ES_J ("%s") ",}", ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,?{," ES_J ("%s") ",}", ARG (0)); break; case MIPS_INS_BTNEZ: - r_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,!,?{," ES_J ("%s") ",}", ARG (0)); + rz_strbuf_appendf (&op->esil, ES_TRAP_DS () "0,t,==,$z,!,?{," ES_J ("%s") ",}", ARG (0)); break; case MIPS_INS_MOV: case MIPS_INS_MOVE: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0)); + rz_strbuf_appendf (&op->esil, "%s,%s,=", ARG (1), REG (0)); } break; case MIPS_INS_MOVZ: case MIPS_INS_MOVF: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,%s,%s,=,}", + rz_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,%s,%s,=,}", ARG (2), ARG (1), REG (0)); } break; case MIPS_INS_MOVT: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "1,%s,==,$z,?{,%s,%s,=,}", + rz_strbuf_appendf (&op->esil, "1,%s,==,$z,?{,%s,%s,=,}", ARG (2), ARG (1), REG (0)); } break; @@ -405,13 +405,13 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case MIPS_INS_DSUB: case MIPS_INS_DSUBU: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", ARG (2), ARG (1), ARG (0)); } break; case MIPS_INS_NEG: case MIPS_INS_NEGU: - r_strbuf_appendf (&op->esil, "%s,0,-,%s,=,", + rz_strbuf_appendf (&op->esil, "%s,0,-,%s,=,", ARG (1), ARG (0)); break; @@ -442,10 +442,10 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len const char *arg2 = ARG(2); PROTECT_ZERO () { if (*arg2 == '-') { - r_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,-,%s,=", arg2+1, arg1, arg0); } else { - r_strbuf_appendf (&op->esil, "%s,%s,+,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,+,%s,=", arg2, arg1, arg0); } } @@ -453,10 +453,10 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len break; case MIPS_INS_LI: case MIPS_INS_LDI: - r_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,=", IMM(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "0x%"PFMT64x",%s,=", IMM(1), ARG(0)); break; case MIPS_INS_LUI: - r_strbuf_appendf (&op->esil, "0x%"PFMT64x"0000,%s,=", IMM(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "0x%"PFMT64x"0000,%s,=", IMM(1), ARG(0)); break; case MIPS_INS_LB: op->sign = true; @@ -498,9 +498,9 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len const char *arg1 = ARG(1); const char *arg2 = ARG(2); if (!strcmp (arg0, arg1)) { - r_strbuf_appendf (&op->esil, "%s,%s,&=", arg2, arg1); + rz_strbuf_appendf (&op->esil, "%s,%s,&=", arg2, arg1); } else { - r_strbuf_appendf (&op->esil, "%s,%s,&,%s,=", arg2, arg1, arg0); + rz_strbuf_appendf (&op->esil, "%s,%s,&,%s,=", arg2, arg1, arg0); } } break; @@ -511,7 +511,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len const char *arg1 = ARG(1); const char *arg2 = ARG(2); PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "%s,%s,|,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,|,%s,=", arg2, arg1, arg0); } } @@ -523,7 +523,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len const char *arg1 = ARG(1); const char *arg2 = ARG(2); PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "%s,%s,^,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,^,%s,=", arg2, arg1, arg0); } } @@ -534,7 +534,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len const char *arg1 = ARG(1); const char *arg2 = ARG(2); PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "%s,%s,|,0xffffffff,^,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,|,0xffffffff,^,%s,=", arg2, arg1, arg0); } } @@ -542,48 +542,48 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case MIPS_INS_SLT: case MIPS_INS_SLTI: if (OPCOUNT () < 3) { - r_strbuf_appendf (&op->esil, "%s,%s,<,t,=", ARG(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,%s,<,t,=", ARG(1), ARG(0)); } else { - r_strbuf_appendf (&op->esil, "%s,%s,<,%s,=", ARG(2), ARG(1), ARG(0)); + rz_strbuf_appendf (&op->esil, "%s,%s,<,%s,=", ARG(2), ARG(1), ARG(0)); } break; case MIPS_INS_SLTU: case MIPS_INS_SLTIU: if (OPCOUNT () < 3) { - r_strbuf_appendf (&op->esil, ES_W("%s")","ES_W("%s")",<,t,=", + rz_strbuf_appendf (&op->esil, ES_W("%s")","ES_W("%s")",<,t,=", ARG (1), ARG (0)); } else { - r_strbuf_appendf (&op->esil, ES_W("%s")","ES_W("%s")",<,%s,=", + rz_strbuf_appendf (&op->esil, ES_W("%s")","ES_W("%s")",<,%s,=", ARG (2), ARG (1), ARG (0)); } break; case MIPS_INS_MUL: - r_strbuf_appendf (&op->esil, ES_W("%s,%s,*")",%s,=", ARG(1), ARG(2), ARG(0)); + rz_strbuf_appendf (&op->esil, ES_W("%s,%s,*")",%s,=", ARG(1), ARG(2), ARG(0)); ES_SIGN32_64 (ARG(0)); break; case MIPS_INS_MULT: case MIPS_INS_MULTU: - r_strbuf_appendf (&op->esil, ES_W("%s,%s,*")",lo,=", ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, ES_W("%s,%s,*")",lo,=", ARG (0), ARG (1)); ES_SIGN32_64 ("lo"); - r_strbuf_appendf (&op->esil, ES_W("32,%s,%s,*,>>")",hi,=", ARG (0), ARG (1)); + rz_strbuf_appendf (&op->esil, ES_W("32,%s,%s,*,>>")",hi,=", ARG (0), ARG (1)); ES_SIGN32_64 ("hi"); break; case MIPS_INS_MFLO: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "lo,%s,=", REG (0)); + rz_strbuf_appendf (&op->esil, "lo,%s,=", REG (0)); } break; case MIPS_INS_MFHI: PROTECT_ZERO () { - r_strbuf_appendf (&op->esil, "hi,%s,=", REG (0)); + rz_strbuf_appendf (&op->esil, "hi,%s,=", REG (0)); } break; case MIPS_INS_MTLO: - r_strbuf_appendf (&op->esil, "%s,lo,=", REG (0)); + rz_strbuf_appendf (&op->esil, "%s,lo,=", REG (0)); ES_SIGN32_64 ("lo"); break; case MIPS_INS_MTHI: - r_strbuf_appendf (&op->esil, "%s,hi,=", REG (0)); + rz_strbuf_appendf (&op->esil, "%s,hi,=", REG (0)); ES_SIGN32_64 ("hi"); break; #if 0 @@ -594,7 +594,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len case MIPS_INS_DDIVU: PROTECT_ZERO () { // 32 bit needs sign extend - r_strbuf_appendf (&op->esil, "%s,%s,/,lo,=,%s,%s,%%,hi,=", REG(1), REG(0), REG(1), REG(0)); + rz_strbuf_appendf (&op->esil, "%s,%s,/,lo,=,%s,%s,%%,hi,=", REG(1), REG(0), REG(1), REG(0)); } break; #endif @@ -605,7 +605,7 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len return 0; } -static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num) { if (!reg) { return -1; } @@ -623,13 +623,13 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) return 0; } -static void op_fillval(RAnal *anal, RAnalOp *op, csh *handle, cs_insn *insn) { - static RRegItem reg; +static void op_fillval(RzAnal *anal, RzAnalOp *op, csh *handle, cs_insn *insn) { + static RzRegItem reg; switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: if (OPERAND(1).type == MIPS_OP_MEM) { ZERO_FILL (reg); - op->src[0] = r_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->reg = ® parse_reg_name (op->src[0]->reg, *handle, insn, 1); op->src[0]->delta = OPERAND(1).mem.disp; @@ -638,7 +638,7 @@ static void op_fillval(RAnal *anal, RAnalOp *op, csh *handle, cs_insn *insn) { case R_ANAL_OP_TYPE_STORE: if (OPERAND(1).type == MIPS_OP_MEM) { ZERO_FILL (reg); - op->dst = r_anal_value_new (); + op->dst = rz_anal_value_new (); op->dst->reg = ® parse_reg_name (op->dst->reg, *handle, insn, 1); op->dst->delta = OPERAND(1).mem.disp; @@ -699,7 +699,7 @@ capstone bug } } -static void set_opdir(RAnalOp *op) { +static void set_opdir(RzAnalOp *op) { switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: op->direction = R_ANAL_OP_DIR_READ; @@ -721,7 +721,7 @@ static void set_opdir(RAnalOp *op) { } } -static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int n, ret, opsize = -1; static csh hndl = 0; static int omode = -1; @@ -770,7 +770,7 @@ static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, goto beach; } if (mask & R_ANAL_OP_MASK_DISASM) { - op->mnemonic = r_str_newf ("%s%s%s", + op->mnemonic = rz_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]?" ":"", insn->op_str); @@ -1087,7 +1087,7 @@ beach: } if (mask & R_ANAL_OP_MASK_ESIL) { if (analop_esil (anal, op, addr, buf, len, &hndl, insn) != 0) { - r_strbuf_fini (&op->esil); + rz_strbuf_fini (&op->esil); } } if (mask & R_ANAL_OP_MASK_VAL) { @@ -1099,7 +1099,7 @@ fin: return opsize; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p = NULL; switch (anal->bits) { default: @@ -1203,18 +1203,18 @@ static char *get_reg_profile(RAnal *anal) { return p? strdup (p): NULL; } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; } -static RList *anal_preludes(RAnal *anal) { -#define KW(d,ds,m,ms) r_list_append (l, r_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) - RList *l = r_list_newf ((RListFree)r_search_keyword_free); +static RzList *anal_preludes(RzAnal *anal) { +#define KW(d,ds,m,ms) rz_list_append (l, rz_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) + RzList *l = rz_list_newf ((RzListFree)rz_search_keyword_free); KW ("\x27\xbd\x00", 3, NULL, 0); return l; } -RAnalPlugin r_anal_plugin_mips_cs = { +RzAnalPlugin rz_anal_plugin_mips_cs = { .name = "mips", .desc = "Capstone MIPS analyzer", .license = "BSD", @@ -1228,9 +1228,9 @@ RAnalPlugin r_anal_plugin_mips_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_mips_cs, + .data = &rz_anal_plugin_mips_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_mips_gnu.c b/librz/anal/p/anal_mips_gnu.c similarity index 92% rename from libr/anal/p/anal_mips_gnu.c rename to librz/anal/p/anal_mips_gnu.c index 74455679a2..8ac471cd22 100644 --- a/libr/anal/p/anal_mips_gnu.c +++ b/librz/anal/p/anal_mips_gnu.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2010-2015 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include /* Return a mapping from the register number i.e. $0 .. $31 to string name */ static const char* mips_reg_decode(unsigned reg_num) { @@ -21,7 +21,7 @@ static const char* mips_reg_decode(unsigned reg_num) { return NULL; } -static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RAnalOpMask mask) { +static int mips_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *b, int len, RzAnalOpMask mask) { ut32 opcode; const ut8 *buf; // WIP char buf[10]; int reg; int family; @@ -36,7 +36,7 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, R op->addr = addr; // Be endian aware - opcode = r_read_ble32 (b, anal->big_endian); + opcode = rz_read_ble32 (b, anal->big_endian); // eprintf ("MIPS: %02x %02x %02x %02x (after endian: big=%d)\n", buf[0], buf[1], buf[2], buf[3], anal->big_endian); if (opcode == 0) { @@ -44,7 +44,7 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, R return oplen; } - opcode = r_swap_ut32 (opcode); + opcode = rz_swap_ut32 (opcode); buf = (ut8 *) & opcode; optype = (buf[0] >> 2); @@ -183,14 +183,14 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, R op->type = R_ANAL_OP_TYPE_JMP; op->jump = page_hack + address; op->delay = 1; - r_strbuf_setf (&op->esil, "0x%08x,pc,=", address); + rz_strbuf_setf (&op->esil, "0x%08x,pc,=", address); break; case 3: // jal op->type = R_ANAL_OP_TYPE_CALL; op->jump = page_hack + address; op->fail = addr+8; op->delay = 1; - r_strbuf_setf (&op->esil, "pc,lr,=,0x%08x,pc,=", (ut32)address); + rz_strbuf_setf (&op->esil, "pc,lr,=,0x%08x,pc,=", (ut32)address); break; } //family = 'J'; @@ -275,19 +275,19 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, R // but the macro needs the opcode values as input // // TODO: this is a stop-gap. Really we need some smarts in here to tie this into the - // flags directly, as suggested here: https://github.com/radareorg/radare2/issues/949#issuecomment-43654922 + // flags directly, as suggested here: https://github.com/rizinorg/rizin/issues/949#issuecomment-43654922 case 15: // lui - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, mips_reg_decode(rt), R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, mips_reg_decode(rt), R_REG_TYPE_GPR); // TODO: currently there is no way for the macro to get access to this register op->val = imm; break; case 9: // addiu - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, mips_reg_decode(rt), R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, mips_reg_decode(rt), R_REG_TYPE_GPR); // TODO: currently there is no way for the macro to get access to this register - op->src[0] = r_anal_value_new (); - op->src[0]->reg = r_reg_get (anal->reg, mips_reg_decode(rs), R_REG_TYPE_GPR); + op->src[0] = rz_anal_value_new (); + op->src[0]->reg = rz_reg_get (anal->reg, mips_reg_decode(rs), R_REG_TYPE_GPR); op->val = imm; // Beware: this one is signed... use `?vi $v` break; case 8: // addi @@ -429,7 +429,7 @@ static int mips_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, R } /* Set the profile register */ -static bool mips_set_reg_profile(RAnal* anal){ +static bool mips_set_reg_profile(RzAnal* anal){ const char *p = #if 0 "=PC pc\n" @@ -521,14 +521,14 @@ static bool mips_set_reg_profile(RAnal* anal){ "gpr pc .64 272 0\n" ; #endif - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; } -RAnalPlugin r_anal_plugin_mips_gnu = { +RzAnalPlugin rz_anal_plugin_mips_gnu = { .name = "mips.gnu", .desc = "MIPS code analysis plugin", .license = "LGPL3", @@ -541,8 +541,8 @@ RAnalPlugin r_anal_plugin_mips_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_mips_gnu + .data = &rz_anal_plugin_mips_gnu }; #endif diff --git a/libr/anal/p/anal_msp430.c b/librz/anal/p/anal_msp430.c similarity index 86% rename from libr/anal/p/anal_msp430.c rename to librz/anal/p/anal_msp430.c index c268c47ed1..5e8eff3316 100644 --- a/libr/anal/p/anal_msp430.c +++ b/librz/anal/p/anal_msp430.c @@ -1,13 +1,13 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -static int msp430_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int msp430_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int ret; struct msp430_cmd cmd; @@ -37,7 +37,7 @@ static int msp430_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int le case MSP430_CALL: op->type = R_ANAL_OP_TYPE_CALL; op->fail = addr + op->size; - op->jump = r_read_at_le16 (buf, 2); + op->jump = rz_read_at_le16 (buf, 2); break; case MSP430_RETI: op->type = R_ANAL_OP_TYPE_RET; break; @@ -84,7 +84,7 @@ static int msp430_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int le return ret; } -RAnalPlugin r_anal_plugin_msp430 = { +RzAnalPlugin rz_anal_plugin_msp430 = { .name = "msp430", .desc = "TI MSP430 code analysis plugin", .license = "LGPL3", diff --git a/libr/anal/p/anal_nios2.c b/librz/anal/p/anal_nios2.c similarity index 82% rename from libr/anal/p/anal_nios2.c rename to librz/anal/p/anal_nios2.c index 62d43d5203..f710be4a19 100644 --- a/libr/anal/p/anal_nios2.c +++ b/librz/anal/p/anal_nios2.c @@ -1,12 +1,12 @@ -/* radare2 - LGPL - Copyright 2014 - pancake */ +/* rizin - LGPL - Copyright 2014 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include -static int nios2_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RAnalOpMask mask) { +static int nios2_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *b, int len, RzAnalOpMask mask) { if (!op) { return 1; } @@ -86,7 +86,7 @@ static int nios2_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, return op->size; } -RAnalPlugin r_anal_plugin_nios2 = { +RzAnalPlugin rz_anal_plugin_nios2 = { .name = "nios2", .desc = "NIOS II code analysis plugin", .license = "LGPL3", @@ -97,9 +97,9 @@ RAnalPlugin r_anal_plugin_nios2 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_nios2, + .data = &rz_anal_plugin_nios2, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_null.c b/librz/anal/p/anal_null.c similarity index 52% rename from libr/anal/p/anal_null.c rename to librz/anal/p/anal_null.c index 018289b9df..97c806b38f 100644 --- a/libr/anal/p/anal_null.c +++ b/librz/anal/p/anal_null.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2014 - jn, maijin */ -#include -#include -#include +#include +#include +#include -static int null_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int null_anal(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { /* This should better follow the disassembler */ return op->size = 1; } -static bool null_set_reg_profile(RAnal* anal){ - return r_reg_set_profile_string(anal->reg, ""); +static bool null_set_reg_profile(RzAnal* anal){ + return rz_reg_set_profile_string(anal->reg, ""); } -RAnalPlugin r_anal_plugin_null = { +RzAnalPlugin rz_anal_plugin_null = { .name = "null", .desc = "Fallback/Null analysis plugin", .arch = "none", @@ -24,9 +24,9 @@ RAnalPlugin r_anal_plugin_null = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_null, + .data = &rz_anal_plugin_null, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_or1k.c b/librz/anal/p/anal_or1k.c similarity index 91% rename from libr/anal/p/anal_or1k.c rename to librz/anal/p/anal_or1k.c index 173aff73fa..538e0a23eb 100644 --- a/libr/anal/p/anal_or1k.c +++ b/librz/anal/p/anal_or1k.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2019 - v3l0c1r4pt0r */ +/* rizin - LGPL - Copyright 2019 - v3l0c1r4pt0r */ -#include -#include -#include +#include +#include +#include #include struct operands { @@ -37,7 +37,7 @@ static ut64 n_oper_to_addr(ut32 n, ut32 mask, ut64 addr) { return (ut64) ((st64) ((st32) (sign_extend(n, mask) << 2)) + addr); } -static int insn_to_op(RAnal *a, RAnalOp *op, ut64 addr, insn_t *descr, insn_extra_t *extra, ut32 insn) { +static int insn_to_op(RzAnal *a, RzAnalOp *op, ut64 addr, insn_t *descr, insn_extra_t *extra, ut32 insn) { struct operands o = {0}; insn_type_t type = type_of_opcode(descr, extra); insn_type_descr_t *type_descr = &types[INSN_X]; @@ -147,14 +147,14 @@ static int insn_to_op(RAnal *a, RAnalOp *op, ut64 addr, insn_t *descr, insn_extr return 4; } -static int or1k_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int or1k_op(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { ut32 insn, opcode; ut8 opcode_idx; insn_t *insn_descr; insn_extra_t *extra_descr; /* read instruction and basic opcode value */ - insn = r_read_be32(data); + insn = rz_read_be32(data); op->size = 4; opcode = (insn & INSN_OPCODE_MASK); opcode_idx = opcode >> INSN_OPCODE_SHIFT; @@ -186,7 +186,7 @@ static int or1k_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, R return op->size; } -RAnalPlugin r_anal_plugin_or1k = { +RzAnalPlugin rz_anal_plugin_or1k = { .name = "or1k", .desc = "OpenRISC 1000", .license = "LGPL3", @@ -197,9 +197,9 @@ RAnalPlugin r_anal_plugin_or1k = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_or1k, + .data = &rz_anal_plugin_or1k, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_pic.c b/librz/anal/p/anal_pic.c similarity index 90% rename from libr/anal/p/anal_pic.c rename to librz/anal/p/anal_pic.c index 395cb7da3c..31fc6612d4 100644 --- a/libr/anal/p/anal_pic.c +++ b/librz/anal/p/anal_pic.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r, courk */ +/* rizin - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r, courk */ -#include -#include -#include +#include +#include +#include #include "../../asm/arch/pic/pic_midrange.h" @@ -15,7 +15,7 @@ typedef struct _pic_midrange_op_args_val { ut8 b; } PicMidrangeOpArgsVal; -typedef void (*pic_midrange_inst_handler_t) (RAnal *anal, RAnalOp *op, +typedef void (*pic_midrange_inst_handler_t) (RzAnal *anal, RzAnalOp *op, ut64 addr, PicMidrangeOpArgsVal *args); @@ -26,7 +26,7 @@ typedef struct _pic_midrange_op_anal_info { } PicMidrangeOpAnalInfo; #define INST_HANDLER(OPCODE_NAME) \ - static void _inst__##OPCODE_NAME (RAnal *anal, RAnalOp *op, \ + static void _inst__##OPCODE_NAME (RzAnal *anal, RzAnalOp *op, \ ut64 addr, \ PicMidrangeOpArgsVal *args) #define INST_DECL(NAME, ARGS) \ @@ -35,8 +35,8 @@ typedef struct _pic_midrange_op_anal_info { _inst__##NAME \ } -#define e(frag) r_strbuf_append (&op->esil, frag) -#define ef(frag, ...) r_strbuf_appendf (&op->esil, frag, __VA_ARGS__) +#define e(frag) rz_strbuf_append (&op->esil, frag) +#define ef(frag, ...) rz_strbuf_appendf (&op->esil, frag, __VA_ARGS__) #define PIC_MIDRANGE_ESIL_SRAM_START (1 << 16) #define PIC_MIDRANGE_ESIL_CSTACK_TOP ((1 << 16) + (1 << 12)) @@ -96,7 +96,7 @@ INST_HANDLER (RETURN) { INST_HANDLER (CALL) { ut64 pclath; op->type = R_ANAL_OP_TYPE_CALL; - r_anal_esil_reg_read (anal->esil, "pclath", &pclath, NULL); + rz_anal_esil_reg_read (anal->esil, "pclath", &pclath, NULL); op->jump = 2 * (((pclath & 0x78) << 8) + args->k); ef ("8,pclath,0x78,&,<<,0x%x,+,2,*,pc,=,", args->k); e ("0x1f,stkptr,==,$z,?{,0xff,stkptr,=,},"); @@ -108,7 +108,7 @@ INST_HANDLER (CALL) { INST_HANDLER (GOTO) { ut64 pclath; op->type = R_ANAL_OP_TYPE_JMP; - r_anal_esil_reg_read (anal->esil, "pclath", &pclath, NULL); + rz_anal_esil_reg_read (anal->esil, "pclath", &pclath, NULL); op->jump = 2 * (((pclath & 0x78) << 8) + args->k); ef ("8,pclath,0x78,&,<<,0x%x,+,2,*,pc,=,", args->k); } @@ -157,7 +157,7 @@ INST_HANDLER (BRA) { INST_HANDLER (BRW) { ut64 wreg; op->type = R_ANAL_OP_TYPE_UJMP; - r_anal_esil_reg_read (anal->esil, "wreg", &wreg, NULL); + rz_anal_esil_reg_read (anal->esil, "wreg", &wreg, NULL); op->jump = addr + 2 * (wreg + 1); e ("wreg,1,+,2,*,pc,+=,"); } @@ -631,12 +631,12 @@ static void anal_pic_midrange_extract_args (ut16 instr, } } -static RIODesc *mem_sram = 0; -static RIODesc *mem_stack = 0; +static RzIODesc *mem_sram = 0; +static RzIODesc *mem_stack = 0; -static RIODesc *cpu_memory_map (RIOBind *iob, RIODesc *desc, ut32 addr, +static RzIODesc *cpu_memory_map (RzIOBind *iob, RzIODesc *desc, ut32 addr, ut32 size) { - char *mstr = r_str_newf ("malloc://%d", size); + char *mstr = rz_str_newf ("malloc://%d", size); if (desc && iob->fd_get_name (iob->io, desc->fd)) { iob->fd_remap (iob->io, desc->fd, addr); } else { @@ -646,18 +646,18 @@ static RIODesc *cpu_memory_map (RIOBind *iob, RIODesc *desc, ut32 addr, return desc; } -static bool pic_midrange_reg_write (RReg *reg, const char *regname, ut32 num) { +static bool pic_midrange_reg_write (RzReg *reg, const char *regname, ut32 num) { if (reg) { - RRegItem *item = r_reg_get (reg, regname, R_REG_TYPE_GPR); + RzRegItem *item = rz_reg_get (reg, regname, R_REG_TYPE_GPR); if (item) { - r_reg_set_value (reg, item, num); + rz_reg_set_value (reg, item, num); return true; } } return false; } -static void anal_pic_midrange_malloc (RAnal *anal, bool force) { +static void anal_pic_midrange_malloc (RzAnal *anal, bool force) { static bool init_done = false; if (!init_done || force) { @@ -681,7 +681,7 @@ static void anal_pic_midrange_malloc (RAnal *anal, bool force) { } } -static int anal_pic_midrange_op (RAnal *anal, RAnalOp *op, ut64 addr, +static int anal_pic_midrange_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { ut16 instr; @@ -694,7 +694,7 @@ static int anal_pic_midrange_op (RAnal *anal, RAnalOp *op, ut64 addr, return op->size; } - instr = r_read_le16 (buf); + instr = rz_read_le16 (buf); // Default op params op->size = 2; @@ -718,15 +718,15 @@ static int anal_pic_midrange_op (RAnal *anal, RAnalOp *op, ut64 addr, return op->size; } -static void pic18_cond_branch (RAnalOp *op, ut64 addr, const ut8 *buf, char *flag) { +static void pic18_cond_branch (RzAnalOp *op, ut64 addr, const ut8 *buf, char *flag) { op->type = R_ANAL_OP_TYPE_CJMP; op->jump = addr + 2 + 2 * (*(ut16 *)buf & 0xff); op->fail = addr + op->size; op->cycles = 2; - r_strbuf_setf (&op->esil, "%s,?,{,0x%x,pc,=,}", flag, op->jump); + rz_strbuf_setf (&op->esil, "%s,?,{,0x%x,pc,=,}", flag, op->jump); } -static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { +static int anal_pic_pic18_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { //TODO code should be refactored and broken into smaller chunks!! //TODO complete the esil emitter if (len < 2) { @@ -757,14 +757,14 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf op->type = R_ANAL_OP_TYPE_JMP; op->cycles = 2; op->jump = addr + 2 + 2 * (*(ut16 *)buf & 0x7ff); - r_strbuf_setf (&op->esil, "0x%x,pc,=", op->jump); + rz_strbuf_setf (&op->esil, "0x%x,pc,=", op->jump); return op->size; } switch (b >> 12) { //NOP,movff,BAF_T case 0xf: //nop op->type = R_ANAL_OP_TYPE_NOP; op->cycles = 1; - r_strbuf_setf (&op->esil, ","); + rz_strbuf_setf (&op->esil, ","); return op->size; case 0xc: //movff if (len < 4) { @@ -822,50 +822,50 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf op->size = 4; op->cycles = 2; op->jump = ((dword_instr & 0xff) | ((dword_instr & 0xfff0000) >> 8)) * 2; - r_strbuf_setf (&op->esil, "0x%x,pc,=", op->jump); + rz_strbuf_setf (&op->esil, "0x%x,pc,=", op->jump); op->type = R_ANAL_OP_TYPE_JMP; return op->size; case 0xf: //addlw op->type = R_ANAL_OP_TYPE_ADD; op->cycles = 1; //TODO add support for dc flag - r_strbuf_setf (&op->esil, "0x%x,wreg,+=,$z,z,:=,7,$s,n,:=,7,$c,c,:=,7,$o,ov,:=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,+=,$z,z,:=,7,$s,n,:=,7,$c,c,:=,7,$o,ov,:=,", *(ut16 *)buf & 0xff); return op->size; case 0xe: //movlw op->type = R_ANAL_OP_TYPE_LOAD; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,wreg,=,"); + rz_strbuf_setf (&op->esil, "0x%x,wreg,=,"); return op->size; case 0xd: //mullw op->type = R_ANAL_OP_TYPE_MUL; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,wreg,*,prod,=", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,*,prod,=", *(ut16 *)buf & 0xff); return op->size; case 0xc: //retlw op->type = R_ANAL_OP_TYPE_RET; op->cycles = 2; - r_strbuf_setf (&op->esil, "0x%x,wreg,=,tos,pc,=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,=,tos,pc,=,", *(ut16 *)buf & 0xff); return op->size; case 0xb: //andlw op->type = R_ANAL_OP_TYPE_AND; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,wreg,&=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,&=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); return op->size; case 0xa: //xorlw op->type = R_ANAL_OP_TYPE_XOR; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,wreg,^=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,^=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); return op->size; case 0x9: //iorlw op->type = R_ANAL_OP_TYPE_OR; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,wreg,^=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "0x%x,wreg,^=,$z,z,:=,7,$s,n,:=,", *(ut16 *)buf & 0xff); return op->size; case 0x8: //sublw op->type = R_ANAL_OP_TYPE_SUB; op->cycles = 1; //TODO add support for dc flag - r_strbuf_setf (&op->esil, "wreg,0x%x,-,wreg,=,$z,z,:=,7,$s,n,:=,7,$c,c,:=,7,$o,ov,:=,", *(ut16 *)buf & 0xff); + rz_strbuf_setf (&op->esil, "wreg,0x%x,-,wreg,=,$z,z,:=,7,$s,n,:=,7,$c,c,:=,7,$o,ov,:=,", *(ut16 *)buf & 0xff); return op->size; }; @@ -952,7 +952,7 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf case 0x10: //movlb op->type = R_ANAL_OP_TYPE_LOAD; op->cycles = 1; - r_strbuf_setf (&op->esil, "0x%x,bsr,=,", *(ut16 *)buf & 0xf); + rz_strbuf_setf (&op->esil, "0x%x,bsr,=,", *(ut16 *)buf & 0xf); return op->size; }; switch (b) { @@ -965,12 +965,12 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf case 0x13: //return op->type = R_ANAL_OP_TYPE_RET; op->cycles = 2; - r_strbuf_setf (&op->esil, "tos,pc,=,"); + rz_strbuf_setf (&op->esil, "tos,pc,=,"); return op->size; case 0x12: //return op->type = R_ANAL_OP_TYPE_RET; op->cycles = 2; - r_strbuf_setf (&op->esil, "tos,pc,="); + rz_strbuf_setf (&op->esil, "tos,pc,="); return op->size; case 0x11: //retfie case 0x10: //retfie @@ -997,7 +997,7 @@ static int anal_pic_pic18_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf case 0x0: //nop op->type = R_ANAL_OP_TYPE_NOP; op->cycles = 1; - r_strbuf_setf (&op->esil, ","); + rz_strbuf_setf (&op->esil, ","); return op->size; }; beach: @@ -1005,7 +1005,7 @@ beach: return op->size; } -static bool anal_pic_midrange_set_reg_profile (RAnal *esil) { +static bool anal_pic_midrange_set_reg_profile (RzAnal *esil) { const char *p = \ "=PC pc\n" "=SP stkptr\n" @@ -1030,10 +1030,10 @@ static bool anal_pic_midrange_set_reg_profile (RAnal *esil) { "gpr stkptr .8 14 0\n" "gpr _sram .32 15 0\n" "gpr _stack .32 19 0\n"; - return r_reg_set_profile_string (esil->reg, p); + return rz_reg_set_profile_string (esil->reg, p); } -static bool anal_pic_pic18_set_reg_profile(RAnal *esil) { +static bool anal_pic_pic18_set_reg_profile(RzAnal *esil) { const char *p = "#pc lives in nowhere actually" "=PC pc\n" @@ -1147,11 +1147,11 @@ static bool anal_pic_pic18_set_reg_profile(RAnal *esil) { "gpr stkptr .8 96 0\n" "gpr tablat .8 14 0\n"; - return r_reg_set_profile_string (esil->reg, p); + return rz_reg_set_profile_string (esil->reg, p); } -static int anal_pic_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int anal_pic_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { if (anal->cpu && strcasecmp (anal->cpu, "baseline") == 0) { // TODO: implement return -1; @@ -1165,7 +1165,7 @@ static int anal_pic_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int return -1; } -static bool anal_pic_set_reg_profile(RAnal *anal) { +static bool anal_pic_set_reg_profile(RzAnal *anal) { if (anal->cpu && strcasecmp (anal->cpu, "baseline") == 0) { // TODO: We are using the midrange profile as the baseline return anal_pic_midrange_set_reg_profile (anal); @@ -1179,7 +1179,7 @@ static bool anal_pic_set_reg_profile(RAnal *anal) { return false; } -RAnalPlugin r_anal_plugin_pic = { +RzAnalPlugin rz_anal_plugin_pic = { .name = "pic", .desc = "PIC analysis plugin", .license = "LGPL3", @@ -1191,9 +1191,9 @@ RAnalPlugin r_anal_plugin_pic = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_pic, + .data = &rz_anal_plugin_pic, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_ppc_cs.c b/librz/anal/p/anal_ppc_cs.c similarity index 93% rename from libr/anal/p/anal_ppc_cs.c rename to librz/anal/p/anal_ppc_cs.c index 7c6b9b6b0f..8f75966ec7 100644 --- a/libr/anal/p/anal_ppc_cs.c +++ b/librz/anal/p/anal_ppc_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ -#include -#include +#include +#include #include #include #include "../../asm/arch/ppc/libvle/vle.h" @@ -162,48 +162,48 @@ static const char* getspr(struct Getarg *gop, int n) { static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_sysz *x = &insn->detail->sysz; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_sysz_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case SYSZ_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case SYSZ_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case SYSZ_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != SYSZ_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"index\":%"PFMT64d"", (st64) op->mem.index); - r_strbuf_appendf (buf, ",\"length\":%"PFMT64d"", (st64) op->mem.length); - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64) op->mem.disp); + rz_strbuf_appendf (buf, ",\"index\":%"PFMT64d"", (st64) op->mem.index); + rz_strbuf_appendf (buf, ",\"length\":%"PFMT64d"", (st64) op->mem.length); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64) op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]}"); + rz_strbuf_append (buf, "]}"); } #define PPCSPR(n) getspr(&gop, n) #define ARG(n) getarg2(&gop, n, "") #define ARG2(n,m) getarg2(&gop, n, m) -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = NULL; if (anal->bits == 32) { p = @@ -406,10 +406,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr dbat3u .32 484 0\n" "gpr mask .64 488 0\n"; //not a real register used on complex functions } - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int analop_vle(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { +static int analop_vle(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { vle_t* instr = NULL; vle_handle handle = {0}; op->size = 2; @@ -493,7 +493,7 @@ static int analop_vle(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) return -1; } -static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num) { if (!reg) { return -1; } @@ -512,20 +512,20 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) return 0; } -static RRegItem base_regs[4]; +static RzRegItem base_regs[4]; -static void create_src_dst(RAnalOp *op) { - op->src[0] = r_anal_value_new (); - op->src[1] = r_anal_value_new (); - op->src[2] = r_anal_value_new (); - op->dst = r_anal_value_new (); +static void create_src_dst(RzAnalOp *op) { + op->src[0] = rz_anal_value_new (); + op->src[1] = rz_anal_value_new (); + op->src[2] = rz_anal_value_new (); + op->dst = rz_anal_value_new (); ZERO_FILL (base_regs[0]); ZERO_FILL (base_regs[1]); ZERO_FILL (base_regs[2]); ZERO_FILL (base_regs[3]); } -static void set_src_dst(RAnalValue *val, csh *handle, cs_insn *insn, int x) { +static void set_src_dst(RzAnalValue *val, csh *handle, cs_insn *insn, int x) { cs_ppc_op ppcop = INSOP (x); parse_reg_name (&base_regs[x], *handle, insn, x); switch (ppcop.type) { @@ -543,7 +543,7 @@ static void set_src_dst(RAnalValue *val, csh *handle, cs_insn *insn, int x) { val->reg = &base_regs[x]; } -static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { +static void op_fillval(RzAnalOp *op, csh handle, cs_insn *insn) { create_src_dst (op); switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_MOV: @@ -578,7 +578,7 @@ static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { } } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static csh handle = 0; static int omode = -1, obits = -1; int n, ret; @@ -1246,7 +1246,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn op_fillval (op, handle, insn); } if (!(mask & R_ANAL_OP_MASK_ESIL)) { - r_strbuf_fini (&op->esil); + rz_strbuf_fini (&op->esil); } cs_free (insn, n); //cs_close (&handle); @@ -1254,21 +1254,21 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -static int archinfo(RAnal *a, int q) { +static int archinfo(RzAnal *a, int q) { if (a->cpu && !strncmp (a->cpu, "vle", 3)) { return 2; } return 4; } -static RList *anal_preludes(RAnal *anal) { -#define KW(d,ds,m,ms) r_list_append (l, r_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) - RList *l = r_list_newf ((RListFree)r_search_keyword_free); +static RzList *anal_preludes(RzAnal *anal) { +#define KW(d,ds,m,ms) rz_list_append (l, rz_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) + RzList *l = rz_list_newf ((RzListFree)rz_search_keyword_free); KW ("\x7c\x08\x02\xa6", 4, NULL, 0); return l; } -RAnalPlugin r_anal_plugin_ppc_cs = { +RzAnalPlugin rz_anal_plugin_ppc_cs = { .name = "ppc", .desc = "Capstone PowerPC analysis", .license = "BSD", @@ -1282,9 +1282,9 @@ RAnalPlugin r_anal_plugin_ppc_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_ppc_cs, + .data = &rz_anal_plugin_ppc_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_ppc_gnu.c b/librz/anal/p/anal_ppc_gnu.c similarity index 89% rename from libr/anal/p/anal_ppc_gnu.c rename to librz/anal/p/anal_ppc_gnu.c index c9188e17da..86a3d51de6 100644 --- a/libr/anal/p/anal_ppc_gnu.c +++ b/librz/anal/p/anal_ppc_gnu.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2014 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include // NOTE: buf should be at least 16 bytes! // XXX addr should be off_t for 64 love -static int ppc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len, RAnalOpMask mask) { +static int ppc_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *bytes, int len, RzAnalOpMask mask) { //int arch_ppc_op(ut64 addr, const u8 *bytes, struct op_t *op) // XXX hack int opcode = (bytes[0] & 0xf8) >> 3; // bytes 0-5 @@ -78,7 +78,7 @@ static int ppc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC srr0\n" "=SR srr1\n" // status register @@ -133,14 +133,14 @@ static bool set_reg_profile(RAnal *anal) { "gpr ctr .32 148 0\n" "gpr mq .32 152 0\n" "gpr vrsave .32 156 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; /* :D */ } -RAnalPlugin r_anal_plugin_ppc_gnu = { +RzAnalPlugin rz_anal_plugin_ppc_gnu = { .name = "ppc.gnu", .desc = "PowerPC analysis plugin", .license = "LGPL3", @@ -152,9 +152,9 @@ RAnalPlugin r_anal_plugin_ppc_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_ppc_gnu, + .data = &rz_anal_plugin_ppc_gnu, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_propeller.c b/librz/anal/p/anal_propeller.c similarity index 87% rename from libr/anal/p/anal_propeller.c rename to librz/anal/p/anal_propeller.c index f63a0d68a1..d8ebe5328a 100644 --- a/libr/anal/p/anal_propeller.c +++ b/librz/anal/p/anal_propeller.c @@ -2,15 +2,15 @@ 2014 - Fedor Sakharov */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -static int propeller_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int propeller_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int ret; struct propeller_cmd cmd; @@ -99,7 +99,7 @@ static int propeller_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int return ret; } -RAnalPlugin r_anal_plugin_propeller = { +RzAnalPlugin rz_anal_plugin_propeller = { .name = "propeller", .desc = "Parallax propeller code analysis plugin", .license = "LGPL3", diff --git a/libr/anal/p/anal_pyc.c b/librz/anal/p/anal_pyc.c similarity index 84% rename from libr/anal/p/anal_pyc.c rename to librz/anal/p/anal_pyc.c index 2588835668..d440005e6b 100644 --- a/libr/anal/p/anal_pyc.c +++ b/librz/anal/p/anal_pyc.c @@ -1,15 +1,15 @@ /* radare - LGPL3 - Copyright 2016-2020 - FXTi */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/pyc/pyc_dis.h" static pyc_opcodes *ops = NULL; -static int archinfo(RAnal *anal, int query) { +static int archinfo(RzAnal *anal, int query) { if (!strcmp (anal->cpu, "x86")) { return -1; } @@ -24,7 +24,7 @@ static int archinfo(RAnal *anal, int query) { } } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { return strdup ( "=PC pc\n" "=BP bp\n" @@ -35,18 +35,18 @@ static char *get_reg_profile(RAnal *anal) { ); } -static RList *get_pyc_code_obj(RAnal *anal) { +static RzList *get_pyc_code_obj(RzAnal *anal) { RBin *b = anal->binb.bin; RBinPlugin *plugin = b->cur && b->cur->o? b->cur->o->plugin: NULL; bool is_pyc = (plugin && strcmp (plugin->name, "pyc") == 0); return is_pyc? b->cur->o->bin_obj: NULL; } -static int pyc_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { - RList *cobjs = r_list_get_n (get_pyc_code_obj (a), 0); - RListIter *iter = NULL; +static int pyc_op(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { + RzList *cobjs = rz_list_get_n (get_pyc_code_obj (a), 0); + RzListIter *iter = NULL; pyc_code_object *func = NULL, *t = NULL; - r_list_foreach (cobjs, iter, t) { + rz_list_foreach (cobjs, iter, t) { if (R_BETWEEN (t->start_offset, addr, t->end_offset - 1)) { // addr in [start_offset, end_offset) func = t; break; @@ -133,7 +133,7 @@ static int finish(void *user) { return 0; } -RAnalPlugin r_anal_plugin_pyc = { +RzAnalPlugin rz_anal_plugin_pyc = { .name = "pyc", .desc = "Python bytecode analysis plugin", .license = "LGPL3", @@ -147,9 +147,9 @@ RAnalPlugin r_anal_plugin_pyc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_pyc, + .data = &rz_anal_plugin_pyc, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_riscv.c b/librz/anal/p/anal_riscv.c similarity index 93% rename from libr/anal/p/anal_riscv.c rename to librz/anal/p/anal_riscv.c index 62895734db..608e8aff6c 100644 --- a/libr/anal/p/anal_riscv.c +++ b/librz/anal/p/anal_riscv.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2015-2019 - qnix */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/riscv/riscv-opc.c" #include "../../asm/arch/riscv/riscv.h" #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) @@ -292,7 +292,7 @@ static const char* arg_n(riscv_args_t* args, int n) { return args->arg[n]; } -static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int riscv_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { const int no_alias = 1; riscv_args_t args = {0}; ut64 word = 0; @@ -302,9 +302,9 @@ static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le op->type = R_ANAL_OP_TYPE_UNK; if (len >= sizeof (ut64)) { - word = r_read_ble64 (data, anal->big_endian); + word = rz_read_ble64 (data, anal->big_endian); } else if (len >= sizeof (ut32)) { - word = r_read_ble16 (data, anal->big_endian); + word = rz_read_ble16 (data, anal->big_endian); } else { op->type = R_ANAL_OP_TYPE_ILL; return -1; @@ -356,37 +356,37 @@ static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le esilprintf (op, "%s,sp,+,%s,=", ARG (1), ARG (0)); if (!strcmp (ARG (0), riscv_gpr_names[X_SP])) { op->stackop = R_ANAL_STACK_INC; - op->stackptr = r_num_math (NULL, ARG (1)); + op->stackptr = rz_num_math (NULL, ARG (1)); } } else if (!strncmp (name, "addw", 4)) { esilprintf (op, "0xffffffff,%s,&,", ARG (2)); - r_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); - r_strbuf_appendf (&op->esil, "+,%s,=,", ARG (0)); - r_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); + rz_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); + rz_strbuf_appendf (&op->esil, "+,%s,=,", ARG (0)); + rz_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); } else if (!strncmp (name, "add", 3)) { esilprintf (op, "%s,%s,+,%s,=", ARG (2), ARG (1), ARG (0)); if (name[3] == 'i' && !strcmp (ARG (0), riscv_gpr_names[X_SP]) && !strcmp (ARG (1), riscv_gpr_names[X_SP])) { op->stackop = R_ANAL_STACK_INC; - op->stackptr = -(signed)r_num_math (NULL, ARG (2)); + op->stackptr = -(signed)rz_num_math (NULL, ARG (2)); } } else if (!strncmp (name, "subw", 4)) { esilprintf (op, "0xffffffff,%s,&,", ARG (2)); - r_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); - r_strbuf_appendf (&op->esil, "-,%s,=,", ARG (0)); - r_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); + rz_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); + rz_strbuf_appendf (&op->esil, "-,%s,=,", ARG (0)); + rz_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); } else if (!strncmp (name, "sub", 3)) { esilprintf (op, "%s,%s,-,%s,=", ARG (2), ARG (1), ARG (0)); if (name[3] == 'i' && !strcmp (ARG (0), riscv_gpr_names[X_SP]) && !strcmp (ARG (1), riscv_gpr_names[X_SP])) { op->stackop = R_ANAL_STACK_INC; - op->stackptr = r_num_math (NULL, ARG (2)); + op->stackptr = rz_num_math (NULL, ARG (2)); } } else if (!strncmp (name, "mulw", 4)) { esilprintf (op, "0xffffffff,%s,&,", ARG (2)); - r_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); - r_strbuf_appendf (&op->esil, "*,%s,=,", ARG (0)); - r_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); + rz_strbuf_appendf (&op->esil, "0xffffffff,%s,&,", ARG (1)); + rz_strbuf_appendf (&op->esil, "*,%s,=,", ARG (0)); + rz_strbuf_appendf (&op->esil, "31,%s,>>,?{,0xffffffff00000000,%s,|=,}", ARG (0), ARG (0)); } else if (!strncmp (name, "mul", 3)) { esilprintf (op, "%s,%s,*,%s,=", ARG (2), ARG (1), ARG (0)); } else if (!strncmp (name, "div", 3)) { @@ -613,29 +613,29 @@ static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le } if (mask & R_ANAL_OP_MASK_VAL && args.num) { int i, j = 1; - op->dst = R_NEW0 (RAnalValue); + op->dst = R_NEW0 (RzAnalValue); char *argf = strdup (o->args); char *comma = strtok (argf, ","); if (comma && strchr (comma, '(')) { - op->dst->delta = (st64)r_num_get (NULL, args.arg[0]); - op->dst->reg = r_reg_get (anal->reg, args.arg[1], -1); + op->dst->delta = (st64)rz_num_get (NULL, args.arg[0]); + op->dst->reg = rz_reg_get (anal->reg, args.arg[1], -1); j = 2; } else if (isdigit (args.arg[j][0])) { - op->dst->imm = r_num_get (NULL, args.arg[0]); + op->dst->imm = rz_num_get (NULL, args.arg[0]); } else { - op->dst->reg = r_reg_get (anal->reg, args.arg[0], -1); + op->dst->reg = rz_reg_get (anal->reg, args.arg[0], -1); } for (i = 0; j < args.num; i++, j++) { - op->src[i] = R_NEW0 (RAnalValue); + op->src[i] = R_NEW0 (RzAnalValue); comma = strtok (NULL, ","); if (comma && strchr (comma, '(')) { - op->src[i]->delta = (st64)r_num_get (NULL, args.arg[j]); - op->src[i]->reg = r_reg_get (anal->reg, args.arg[j + 1], -1); + op->src[i]->delta = (st64)rz_num_get (NULL, args.arg[j]); + op->src[i]->reg = rz_reg_get (anal->reg, args.arg[j + 1], -1); j++; } else if (isalpha (args.arg[j][0])) { - op->src[i]->reg = r_reg_get (anal->reg, args.arg[j], -1); + op->src[i]->reg = rz_reg_get (anal->reg, args.arg[j], -1); } else { - op->src[i]->imm = r_num_get (NULL, args.arg[j]); + op->src[i]->imm = rz_num_get (NULL, args.arg[j]); } } free (argf); @@ -643,7 +643,7 @@ static int riscv_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le return op->size; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p = NULL; switch (anal->bits) { case 32: p = @@ -819,7 +819,7 @@ static char *get_reg_profile(RAnal *anal) { return (p && *p)? strdup (p): NULL; } -RAnalPlugin r_anal_plugin_riscv = { +RzAnalPlugin rz_anal_plugin_riscv = { .name = "riscv", .desc = "RISC-V analysis plugin", .license = "GPL", @@ -830,9 +830,9 @@ RAnalPlugin r_anal_plugin_riscv = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_riscv, + .data = &rz_anal_plugin_riscv, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_riscv_cs.c b/librz/anal/p/anal_riscv_cs.c similarity index 84% rename from libr/anal/p/anal_riscv_cs.c rename to librz/anal/p/anal_riscv_cs.c index 13c26510bc..388af458e7 100644 --- a/libr/anal/p/anal_riscv_cs.c +++ b/librz/anal/p/anal_riscv_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ -#include -#include +#include +#include #if CSNEXT @@ -26,30 +26,30 @@ } #define CREATE_SRC_DST_3(op) \ - (op)->src[0] = r_anal_value_new ();\ - (op)->src[1] = r_anal_value_new ();\ - (op)->dst = r_anal_value_new (); + (op)->src[0] = rz_anal_value_new ();\ + (op)->src[1] = rz_anal_value_new ();\ + (op)->dst = rz_anal_value_new (); #define CREATE_SRC_DST_2(op) \ - (op)->src[0] = r_anal_value_new ();\ - (op)->dst = r_anal_value_new (); + (op)->src[0] = rz_anal_value_new ();\ + (op)->dst = rz_anal_value_new (); #define SET_SRC_DST_3_REGS(op) \ CREATE_SRC_DST_3 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ - (op)->src[1]->reg = r_reg_get (anal->reg, REG (2), R_REG_TYPE_GPR); + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ + (op)->src[1]->reg = rz_reg_get (anal->reg, REG (2), R_REG_TYPE_GPR); #define SET_SRC_DST_3_IMM(op) \ CREATE_SRC_DST_3 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR);\ (op)->src[1]->imm = IMM (2); #define SET_SRC_DST_2_REGS(op) \ CREATE_SRC_DST_2 (op);\ - (op)->dst->reg = r_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ - (op)->src[0]->reg = r_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR); + (op)->dst->reg = rz_reg_get (anal->reg, REG (0), R_REG_TYPE_GPR);\ + (op)->src[0]->reg = rz_reg_get (anal->reg, REG (1), R_REG_TYPE_GPR); #define SET_SRC_DST_3_REG_OR_IMM(op) \ if (OPERAND(2).type == RISCV_OP_IMM) {\ @@ -92,51 +92,51 @@ #define PROTECT_ZERO() \ if (REG(0)[0]=='z'){\ - r_strbuf_appendf (&op->esil, ",");\ + rz_strbuf_appendf (&op->esil, ",");\ } else #define ESIL_LOAD(size) \ PROTECT_ZERO () {\ - r_strbuf_appendf (&op->esil, "%s,["size"],%s,=",\ + rz_strbuf_appendf (&op->esil, "%s,["size"],%s,=",\ ARG(1), REG(0));\ } static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_riscv *x = &insn->detail->riscv; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_riscv_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case RISCV_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case RISCV_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case RISCV_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != RISCV_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "}"); } static const char *arg(csh *handle, cs_insn *insn, char *buf, int n) { @@ -177,12 +177,12 @@ static const char *arg(csh *handle, cs_insn *insn, char *buf, int n) { #define ARG(x) (*str[x]!=0)?str[x]:arg(handle, insn, str[x], x) -static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { +static int analop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { char str[8][32] = {{0}}; int i; - r_strbuf_init (&op->esil); - r_strbuf_set (&op->esil, ""); + rz_strbuf_init (&op->esil); + rz_strbuf_set (&op->esil, ""); if (insn) { // caching operands @@ -194,13 +194,13 @@ static int analop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len switch (insn->id) { //case RISCV_INS_NOP: - // r_strbuf_setf (&op->esil, ","); + // rz_strbuf_setf (&op->esil, ","); // break; } return 0; } -static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num) { if (!reg) { return -1; } @@ -218,13 +218,13 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) return 0; } -static void op_fillval(RAnal *anal, RAnalOp *op, csh *handle, cs_insn *insn) { - static RRegItem reg; +static void op_fillval(RzAnal *anal, RzAnalOp *op, csh *handle, cs_insn *insn) { + static RzRegItem reg; switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: if (OPERAND(1).type == RISCV_OP_MEM) { ZERO_FILL (reg); - op->src[0] = r_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->reg = ® parse_reg_name (op->src[0]->reg, *handle, insn, 1); op->src[0]->delta = OPERAND(1).mem.disp; @@ -233,7 +233,7 @@ static void op_fillval(RAnal *anal, RAnalOp *op, csh *handle, cs_insn *insn) { case R_ANAL_OP_TYPE_STORE: if (OPERAND(1).type == RISCV_OP_MEM) { ZERO_FILL (reg); - op->dst = r_anal_value_new (); + op->dst = rz_anal_value_new (); op->dst->reg = ® parse_reg_name (op->dst->reg, *handle, insn, 1); op->dst->delta = OPERAND(1).mem.disp; @@ -294,7 +294,7 @@ capstone bug } } -static void set_opdir(RAnalOp *op) { +static void set_opdir(RzAnalOp *op) { switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: op->direction = R_ANAL_OP_DIR_READ; @@ -316,7 +316,7 @@ static void set_opdir(RAnalOp *op) { } } -static int analop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int n, ret, opsize = -1; static csh hndl = 0; static int omode = -1; @@ -382,7 +382,7 @@ beach: } if (mask & R_ANAL_OP_MASK_ESIL) { if (analop_esil (anal, op, addr, buf, len, &hndl, insn) != 0) { - r_strbuf_fini (&op->esil); + rz_strbuf_fini (&op->esil); } } if (mask & R_ANAL_OP_MASK_VAL) { @@ -394,7 +394,7 @@ fin: return opsize; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p = NULL; switch (anal->bits) { case 32: p = @@ -570,7 +570,7 @@ static char *get_reg_profile(RAnal *anal) { return (p && *p)? strdup (p): NULL; } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { switch (q) { case R_ANAL_ARCHINFO_ALIGN: return 4; @@ -585,7 +585,7 @@ static int archinfo(RAnal *anal, int q) { return 0; } -RAnalPlugin r_anal_plugin_riscv_cs = { +RzAnalPlugin rz_anal_plugin_riscv_cs = { .name = "riscv.cs", .desc = "Capstone RISCV analyzer", .license = "BSD", @@ -598,17 +598,17 @@ RAnalPlugin r_anal_plugin_riscv_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_riscv_cs, + .data = &rz_anal_plugin_riscv_cs, .version = R2_VERSION }; #endif #else -RAnalPlugin r_anal_plugin_riscv_cs = {0}; +RzAnalPlugin rz_anal_plugin_riscv_cs = {0}; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, .version = R2_VERSION }; diff --git a/libr/anal/p/anal_rsp.c b/librz/anal/p/anal_rsp.c similarity index 70% rename from libr/anal/p/anal_rsp.c rename to librz/anal/p/anal_rsp.c index 6736e4afef..0c03d50ef3 100644 --- a/libr/anal/p/anal_rsp.c +++ b/librz/anal/p/anal_rsp.c @@ -7,23 +7,23 @@ */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/rsp/rsp_idec.h" -static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RAnalOpMask mask) { +static int rsp_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *b, int len, RzAnalOpMask mask) { int i; typedef struct { - RAnalValue* value; + RzAnalValue* value; char esil[32]; } ParsedOperands; ParsedOperands parsed_operands[RSP_MAX_OPNDS]; memset (parsed_operands, 0, sizeof (ParsedOperands) * RSP_MAX_OPNDS); ut32 iw; - rsp_instruction r_instr; + rsp_instruction rz_instr; if (!op) { return 4; @@ -32,49 +32,49 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->type = R_ANAL_OP_TYPE_UNK; op->size = 4; op->addr = addr; - r_strbuf_set (&op->esil, "TODO"); + rz_strbuf_set (&op->esil, "TODO"); - iw = r_read_ble32 (b, anal->big_endian); - r_instr = rsp_instruction_decode (addr, iw); + iw = rz_read_ble32 (b, anal->big_endian); + rz_instr = rsp_instruction_decode (addr, iw); /* parse operands */ - for (i = 0; i < r_instr.noperands; i++) { - parsed_operands[i].value = r_anal_value_new (); + for (i = 0; i < rz_instr.noperands; i++) { + parsed_operands[i].value = rz_anal_value_new (); parsed_operands[i].esil[0] = '\0'; - switch (r_instr.operands[i].type) { + switch (rz_instr.operands[i].type) { case RSP_OPND_GP_REG: - snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%s", rsp_gp_reg_soft_names[r_instr.operands[i].u]); - parsed_operands[i].value->reg = r_reg_get (anal->reg, rsp_gp_reg_soft_names[r_instr.operands[i].u], R_REG_TYPE_GPR); + snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%s", rsp_gp_reg_soft_names[rz_instr.operands[i].u]); + parsed_operands[i].value->reg = rz_reg_get (anal->reg, rsp_gp_reg_soft_names[rz_instr.operands[i].u], R_REG_TYPE_GPR); break; case RSP_OPND_ZIMM: case RSP_OPND_SHIFT_AMOUNT: - snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, r_instr.operands[i].u); - parsed_operands[i].value->imm = op->val = r_instr.operands[i].u; + snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, rz_instr.operands[i].u); + parsed_operands[i].value->imm = op->val = rz_instr.operands[i].u; break; case RSP_OPND_SIMM: - snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, r_instr.operands[i].s); - parsed_operands[i].value->imm = op->val = r_instr.operands[i].s; + snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, rz_instr.operands[i].s); + parsed_operands[i].value->imm = op->val = rz_instr.operands[i].s; break; case RSP_OPND_BASE_OFFSET: snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), - "%"PFMT64d",%s,+", r_instr.operands[i].s, rsp_gp_reg_soft_names[r_instr.operands[i].u]); - parsed_operands[i].value->reg = r_reg_get (anal->reg, rsp_gp_reg_soft_names[r_instr.operands[i].u], R_REG_TYPE_GPR); - parsed_operands[i].value->imm = r_instr.operands[i].s; + "%"PFMT64d",%s,+", rz_instr.operands[i].s, rsp_gp_reg_soft_names[rz_instr.operands[i].u]); + parsed_operands[i].value->reg = rz_reg_get (anal->reg, rsp_gp_reg_soft_names[rz_instr.operands[i].u], R_REG_TYPE_GPR); + parsed_operands[i].value->imm = rz_instr.operands[i].s; break; case RSP_OPND_OFFSET: case RSP_OPND_TARGET: op->delay = 1; - op->jump = r_instr.operands[i].u; + op->jump = rz_instr.operands[i].u; op->fail = rsp_mem_addr (addr + 8, RSP_IMEM_OFFSET); op->eob = 1; - snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, r_instr.operands[i].u); - parsed_operands[i].value->imm = r_instr.operands[i].u; + snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%"PFMT64d, rz_instr.operands[i].u); + parsed_operands[i].value->imm = rz_instr.operands[i].u; parsed_operands[i].value->memref = 4; break; case RSP_OPND_C0_REG: - snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%s", rsp_c0_reg_names[r_instr.operands[i].u]); - parsed_operands[i].value->reg = r_reg_get (anal->reg, rsp_c0_reg_names[r_instr.operands[i].u], R_REG_TYPE_GPR); + snprintf (parsed_operands[i].esil, sizeof (parsed_operands[i].esil), "%s", rsp_c0_reg_names[rz_instr.operands[i].u]); + parsed_operands[i].value->reg = rz_reg_get (anal->reg, rsp_c0_reg_names[rz_instr.operands[i].u], R_REG_TYPE_GPR); break; case RSP_OPND_C2_CREG: case RSP_OPND_C2_ACCU: @@ -87,13 +87,13 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA } } - switch (r_instr.opcode) { + switch (rz_instr.opcode) { case RSP_OP_INVALID: op->type = R_ANAL_OP_TYPE_ILL; break; case RSP_OP_NOP: op->type = R_ANAL_OP_TYPE_NOP; - r_strbuf_set (&op->esil, ","); + rz_strbuf_set (&op->esil, ","); break; case RSP_OP_BREAK: op->type = R_ANAL_OP_TYPE_TRAP; @@ -103,7 +103,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->type = R_ANAL_OP_TYPE_MOV; op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_ADD: case RSP_OP_ADDU: @@ -113,7 +113,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,+,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,+,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_SUB: case RSP_OP_SUBU: @@ -121,7 +121,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,-,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,-,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_AND: case RSP_OP_ANDI: @@ -129,7 +129,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,&,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,&,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_OR: case RSP_OP_ORI: @@ -137,7 +137,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,|,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,|,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_XOR: case RSP_OP_XORI: @@ -145,7 +145,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,^,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,^,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_NOR: op->type = R_ANAL_OP_TYPE_NOR; @@ -160,7 +160,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,<<,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,<<,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_SRL: case RSP_OP_SRLV: @@ -168,7 +168,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,>>,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,>>,%s,=", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_SRA: case RSP_OP_SRAV: @@ -187,98 +187,98 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[1] = parsed_operands[2].value; - r_strbuf_setf (&op->esil, "%s,%s,<,$z,?{,1,%s,=,}{,0,%s,=,}", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,<,$z,?{,1,%s,=,}{,0,%s,=,}", parsed_operands[2].esil, parsed_operands[1].esil, parsed_operands[0].esil, parsed_operands[0].esil); break; case RSP_OP_J: op->type = R_ANAL_OP_TYPE_JMP; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; - r_strbuf_setf (&op->esil, "%s,PC,=", parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,PC,=", parsed_operands[0].esil); break; case RSP_OP_JAL: op->type = R_ANAL_OP_TYPE_CALL; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; - r_strbuf_setf (&op->esil, "%s,PC,=,0x%08x,RA,=", parsed_operands[0].esil, op->fail); + rz_strbuf_setf (&op->esil, "%s,PC,=,0x%08x,RA,=", parsed_operands[0].esil, op->fail); break; case RSP_OP_JR: /* if register is RA, this is a return */ - op->type = (r_instr.operands[0].u == 29) + op->type = (rz_instr.operands[0].u == 29) ? R_ANAL_OP_TYPE_RET : R_ANAL_OP_TYPE_UJMP; op->delay = 1; op->eob = 1; op->fail = rsp_mem_addr (addr + 8, RSP_IMEM_OFFSET); - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; - r_strbuf_setf (&op->esil, "%s,PC,=", parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,PC,=", parsed_operands[0].esil); break; case RSP_OP_BEQ: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_EQ; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,%s,==,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil); + rz_strbuf_setf (&op->esil, "%s,%s,==,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil); break; case RSP_OP_BNE: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_NE; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,%s,==,$z,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil); + rz_strbuf_setf (&op->esil, "%s,%s,==,$z,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil, parsed_operands[2].esil); break; case RSP_OP_BLEZ: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_LE; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,!,%s,0x80000000,&,!,!,|,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil); -// r_strbuf_setf (&op->esil, "0,%s,<=,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,!,%s,0x80000000,&,!,!,|,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil); +// rz_strbuf_setf (&op->esil, "0,%s,<=,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_BGTZ: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_GT; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,0x80000000,&,!,%s,!,!,&,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil); -// r_strbuf_setf (&op->esil, "0,%s,>,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,0x80000000,&,!,%s,!,!,&,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[0].esil, parsed_operands[1].esil); +// rz_strbuf_setf (&op->esil, "0,%s,>,$z,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_BLTZ: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_LT; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,0x80000000,&,!,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); -// r_strbuf_setf (&op->esil, "0,%s,<,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,0x80000000,&,!,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); +// rz_strbuf_setf (&op->esil, "0,%s,<,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_BGEZ: op->type = R_ANAL_OP_TYPE_CJMP; op->cond = R_ANAL_COND_GE; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,0x80000000,&,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); -// r_strbuf_setf (&op->esil, "0,%s,>=,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,0x80000000,&,!,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); +// rz_strbuf_setf (&op->esil, "0,%s,>=,?{,%s,PC,=,}", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_BLTZAL: op->type = R_ANAL_OP_TYPE_CCALL; op->cond = R_ANAL_COND_LT; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; // TODO @@ -286,8 +286,8 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA case RSP_OP_BGEZAL: op->type = R_ANAL_OP_TYPE_CCALL; op->cond = R_ANAL_COND_GE; - op->dst = r_anal_value_new (); - op->dst->reg = r_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); + op->dst = rz_anal_value_new (); + op->dst->reg = rz_reg_get (anal->reg, "PC", R_REG_TYPE_GPR); op->src[0] = parsed_operands[0].value; op->src[1] = parsed_operands[1].value; // TODO @@ -298,7 +298,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->src[0] = parsed_operands[1].value; op->src[0]->memref = op->refptr = 1; // FIXME: sign extend - r_strbuf_setf (&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_LH: op->type = R_ANAL_OP_TYPE_LOAD; @@ -306,61 +306,61 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA op->src[0] = parsed_operands[1].value; op->src[0]->memref = op->refptr = 2; // FIXME: sign extend - r_strbuf_setf (&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_LW: op->type = R_ANAL_OP_TYPE_LOAD; op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[0]->memref = op->refptr = 4; - r_strbuf_setf (&op->esil, "%s,[4],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,[4],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_LBU: op->type = R_ANAL_OP_TYPE_LOAD; op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[0]->memref = op->refptr = 1; - r_strbuf_setf (&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,[1],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_LHU: op->type = R_ANAL_OP_TYPE_LOAD; op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; op->src[0]->memref = op->refptr = 2; - r_strbuf_setf (&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,[2],%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_SB: op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = parsed_operands[0].value; op->dst = parsed_operands[1].value; op->dst->memref = op->refptr = 1; - r_strbuf_setf (&op->esil, "%s,%s,=[1]", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=[1]", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_SH: op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = parsed_operands[0].value; op->dst = parsed_operands[1].value; op->dst->memref = op->refptr = 2; - r_strbuf_setf (&op->esil, "%s,%s,=[2]", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=[2]", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_SW: op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = parsed_operands[0].value; op->dst = parsed_operands[1].value; op->dst->memref = op->refptr = 4; - r_strbuf_setf (&op->esil, "%s,%s,=[4]", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=[4]", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_MFC0: op->type = R_ANAL_OP_TYPE_MOV; op->dst = parsed_operands[0].value; op->src[0] = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[1].esil, parsed_operands[0].esil); break; case RSP_OP_MTC0: op->type = R_ANAL_OP_TYPE_MOV; op->src[0] = parsed_operands[0].value; op->dst = parsed_operands[1].value; - r_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[0].esil, parsed_operands[1].esil); + rz_strbuf_setf (&op->esil, "%s,%s,=", parsed_operands[0].esil, parsed_operands[1].esil); break; case RSP_OP_MFC2: op->type = R_ANAL_OP_TYPE_MOV; @@ -578,7 +578,7 @@ static int rsp_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *b, int len, RA } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { static const char *p = "=PC pc\n" "=SP sp\n" @@ -682,11 +682,11 @@ static char *get_reg_profile(RAnal *anal) { return strdup (p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; } -RAnalPlugin r_anal_plugin_rsp = { +RzAnalPlugin rz_anal_plugin_rsp = { .name = "rsp", .desc = "RSP code analysis plugin", .license = "LGPL3", @@ -699,9 +699,9 @@ RAnalPlugin r_anal_plugin_rsp = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_rsp, + .data = &rz_anal_plugin_rsp, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_sh.c b/librz/anal/p/anal_sh.c similarity index 67% rename from libr/anal/p/anal_sh.c rename to librz/anal/p/anal_sh.c index 51ca45a050..3d4094c8ba 100644 --- a/libr/anal/p/anal_sh.c +++ b/librz/anal/p/anal_sh.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2010-2013 eloi */ #include -#include -#include -#include -#include +#include +#include +#include +#include #define API static @@ -180,7 +180,7 @@ #define PC_IDX 16 /* for {bra,bsr} only: (sign-extend 12bit offset)<<1 + PC +4 */ -static ut64 disarm_12bit_offset (RAnalOp *op, unsigned int insoff) { +static ut64 disarm_12bit_offset (RzAnalOp *op, unsigned int insoff) { ut64 off = insoff; /* sign extend if higher bit is 1 (0x0800) */ if ((off & 0x0800) == 0x0800) @@ -205,44 +205,44 @@ static ut64 disarm_8bit_offset (ut64 pc, ut32 offs) { static char *regs[]={"r0","r1","r2","r3","r4","r5","r6","r7","r8","r9","r10","r11","r12","r13","r14","r15","pc"}; -static RAnalValue *anal_fill_ai_rg(RAnal *anal, int idx) { - RAnalValue *ret = r_anal_value_new (); - ret->reg = r_reg_get (anal->reg, regs[idx], R_REG_TYPE_GPR); +static RzAnalValue *anal_fill_ai_rg(RzAnal *anal, int idx) { + RzAnalValue *ret = rz_anal_value_new (); + ret->reg = rz_reg_get (anal->reg, regs[idx], R_REG_TYPE_GPR); return ret; } -static RAnalValue *anal_fill_im(RAnal *anal, st32 v) { - RAnalValue *ret = r_anal_value_new (); +static RzAnalValue *anal_fill_im(RzAnal *anal, st32 v) { + RzAnalValue *ret = rz_anal_value_new (); ret->imm = v; return ret; } /* Implements @(disp,Rn) , size=1 for .b, 2 for .w, 4 for .l */ -static RAnalValue *anal_fill_reg_disp_mem(RAnal *anal, int reg, st64 delta, st64 size) { - RAnalValue *ret = anal_fill_ai_rg (anal, reg); +static RzAnalValue *anal_fill_reg_disp_mem(RzAnal *anal, int reg, st64 delta, st64 size) { + RzAnalValue *ret = anal_fill_ai_rg (anal, reg); ret->memref = size; ret->delta = delta*size; return ret; } /* Rn */ -static RAnalValue *anal_fill_reg_ref(RAnal *anal, int reg, st64 size) { - RAnalValue *ret = anal_fill_ai_rg (anal, reg); +static RzAnalValue *anal_fill_reg_ref(RzAnal *anal, int reg, st64 size) { + RzAnalValue *ret = anal_fill_ai_rg (anal, reg); ret->memref = size; return ret; } /* @(R0,Rx) references for all sizes */ -static RAnalValue *anal_fill_r0_reg_ref(RAnal *anal, int reg, st64 size) { - RAnalValue *ret = anal_fill_ai_rg (anal, 0); - ret->regdelta = r_reg_get (anal->reg, regs[reg], R_REG_TYPE_GPR); +static RzAnalValue *anal_fill_r0_reg_ref(RzAnal *anal, int reg, st64 size) { + RzAnalValue *ret = anal_fill_ai_rg (anal, 0); + ret->regdelta = rz_reg_get (anal->reg, regs[reg], R_REG_TYPE_GPR); ret->memref = size; return ret; } // @(disp,PC) for size=2(.w), size=4(.l). disp is 0-extended -static RAnalValue *anal_pcrel_disp_mov(RAnal* anal, RAnalOp* op, ut8 disp, int size) { - RAnalValue *ret = r_anal_value_new (); +static RzAnalValue *anal_pcrel_disp_mov(RzAnal* anal, RzAnalOp* op, ut8 disp, int size) { + RzAnalValue *ret = rz_anal_value_new (); if (size==2) { ret->base = op->addr + 4; ret->delta = disp << 1; @@ -255,133 +255,133 @@ static RAnalValue *anal_pcrel_disp_mov(RAnal* anal, RAnalOp* op, ut8 disp, int s } //= PC+4+R -static RAnalValue *anal_regrel_jump(RAnal* anal, RAnalOp* op, ut8 reg) { - RAnalValue *ret = r_anal_value_new (); - ret->reg = r_reg_get (anal->reg, regs[reg], R_REG_TYPE_GPR); +static RzAnalValue *anal_regrel_jump(RzAnal* anal, RzAnalOp* op, ut8 reg) { + RzAnalValue *ret = rz_anal_value_new (); + ret->reg = rz_reg_get (anal->reg, regs[reg], R_REG_TYPE_GPR); ret->base = op->addr + 4; return ret; } /* 16 decoder routines, based on 1st nibble value */ -static int first_nibble_is_0(RAnal* anal, RAnalOp* op, ut16 code) { //STOP +static int first_nibble_is_0(RzAnal* anal, RzAnalOp* op, ut16 code) { //STOP if (IS_BSRF (code)) { /* Call 'far' subroutine Rn+PC+4 */ op->type = R_ANAL_OP_TYPE_UCALL; op->delay = 1; op->dst = anal_regrel_jump (anal, op, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,r%d,2,+,pc,+=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,r%d,2,+,pc,+=", GET_TARGET_REG (code)); } else if (IS_BRAF (code)) { op->type = R_ANAL_OP_TYPE_UJMP; op->dst = anal_regrel_jump (anal, op, GET_TARGET_REG (code)); op->eob = true; op->delay = 1; - r_strbuf_setf (&op->esil, "1,SETD,r%d,2,+,pc,+=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,SETD,r%d,2,+,pc,+=", GET_TARGET_REG (code)); } else if (IS_RTS (code)) { op->type = R_ANAL_OP_TYPE_RET; op->delay = 1; op->eob = true; - r_strbuf_setf (&op->esil, "pr,pc,="); + rz_strbuf_setf (&op->esil, "pr,pc,="); } else if (IS_RTE (code)) { op->type = R_ANAL_OP_TYPE_RET; op->delay = 1; op->eob = true; - //r_strbuf_setf (&op->esil, "1,SETD,r15,[4],4,+,pc,=,r15,4,+,[4],0xFFF0FFF,&,sr,=,8,r15,+="); + //rz_strbuf_setf (&op->esil, "1,SETD,r15,[4],4,+,pc,=,r15,4,+,[4],0xFFF0FFF,&,sr,=,8,r15,+="); //not sure if should be added 4 to pc - r_strbuf_setf (&op->esil, "1,SETD,r15,[4],pc,=,r15,4,+,[4],0xFFF0FFF,&,sr,=,8,r15,+="); + rz_strbuf_setf (&op->esil, "1,SETD,r15,[4],pc,=,r15,4,+,[4],0xFFF0FFF,&,sr,=,8,r15,+="); } else if (IS_MOVB_REG_TO_R0REL (code)) { //0000nnnnmmmm0100 mov.b ,@(R0,) op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_r0_reg_ref (anal, GET_TARGET_REG (code), BYTE_SIZE); - r_strbuf_setf (&op->esil, "r%d,0xFF,&,r0,r%d,+,=[1]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFF,&,r0,r%d,+,=[1]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVW_REG_TO_R0REL (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_r0_reg_ref (anal, GET_TARGET_REG (code), WORD_SIZE); - r_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r0,r%d,+,=[2]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r0,r%d,+,=[2]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVL_REG_TO_R0REL (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_r0_reg_ref(anal, GET_TARGET_REG (code), LONG_SIZE); - r_strbuf_setf (&op->esil, "r%d,r0,r%d,+,=[4]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r0,r%d,+,=[4]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVB_R0REL_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_r0_reg_ref (anal, GET_SOURCE_REG (code), BYTE_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r0,r%d,+,[1],r%d,=,0x000000FF,r%d,&=,r%d,0x80,&,?{,0xFFFFFF00,r%d,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r0,r%d,+,[1],r%d,=,0x000000FF,r%d,&=,r%d,0x80,&,?{,0xFFFFFF00,r%d,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVW_R0REL_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_r0_reg_ref (anal, GET_SOURCE_REG (code), WORD_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r0,r%d,+,[2],r%d,=,0x0000FFFF,r%d,&=,r%d,0x8000,&,?{,0xFFFF0000,r%d,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r0,r%d,+,[2],r%d,=,0x0000FFFF,r%d,&=,r%d,0x8000,&,?{,0xFFFF0000,r%d,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVL_R0REL_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_r0_reg_ref (anal, GET_SOURCE_REG (code), LONG_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r0,r%d,+,[4],r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r0,r%d,+,[4],r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_NOP (code)) { op->type = R_ANAL_OP_TYPE_NOP; - r_strbuf_setf (&op->esil, " "); + rz_strbuf_setf (&op->esil, " "); } else if (IS_CLRT (code)) { op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&="); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&="); } else if (IS_SETT (code)) { op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "0x1,sr,|="); + rz_strbuf_setf (&op->esil, "0x1,sr,|="); } else if (IS_CLRMAC (code)) { op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "0,mach,=,0,macl,="); + rz_strbuf_setf (&op->esil, "0,mach,=,0,macl,="); } else if (IS_DIV0U (code)) { op->type = R_ANAL_OP_TYPE_DIV; - r_strbuf_setf (&op->esil, "0xFFFFFCFE,sr,&="); + rz_strbuf_setf (&op->esil, "0xFFFFFCFE,sr,&="); } else if (IS_MOVT (code)) { op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0x1,sr,&,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x1,sr,&,r%d,=", GET_TARGET_REG (code)); } else if (IS_MULL (code)) { //multiply long op->type = R_ANAL_OP_TYPE_MUL; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,*,macl,=", GET_TARGET_REG (code), GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,*,macl,=", GET_TARGET_REG (code), GET_SOURCE_REG (code)); } else if (IS_SLEEP (code)) { op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "sleep_called,TRAP", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "sleep_called,TRAP", GET_TARGET_REG (code)); } else if (IS_STSMACH (code)) { //0000nnnn0000101_ sts MAC*, op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "mach,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "mach,r%d,=", GET_TARGET_REG (code)); } else if (IS_STSMACL (code)) { //0000nnnn0000101_ sts MAC*, op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "macl,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "macl,r%d,=", GET_TARGET_REG (code)); } else if (IS_STSLMACL (code)) { op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "macl,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "macl,r%d,=", GET_TARGET_REG (code)); } else if (IS_STCSR1 (code)) { //0000nnnn00010010 stc {sr,gbr,vbr,ssr}, op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); //todo: plug in src switch(GET_SOURCE_REG (code)) { case 0: - r_strbuf_setf (&op->esil, "sr,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "sr,r%d,=", GET_TARGET_REG (code)); break; case 1: - r_strbuf_setf (&op->esil, "gbr,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "gbr,r%d,=", GET_TARGET_REG (code)); break; case 2: - r_strbuf_setf (&op->esil, "vbr,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "vbr,r%d,=", GET_TARGET_REG (code)); break; default: - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); break; } } else if (IS_STSPR (code)) { //0000nnnn00101010 sts PR, op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "pr,r%d,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "pr,r%d,=", GET_TARGET_REG (code)); } else if (IS_MACL (code)) { - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "mach,0x80000000,&,!," //mach_old sign (0) S32_EXT("r%d,[4]")"," //@Rn sign extended S32_EXT("r%d,[4]")"," //@Rm sign extended @@ -412,149 +412,149 @@ static int first_nibble_is_0(RAnal* anal, RAnalOp* op, ut16 code) { //STOP } //nibble=1; 0001nnnnmmmmi4*4 mov.l ,@(,) -static int movl_reg_rdisp(RAnal* anal, RAnalOp* op, ut16 code) { +static int movl_reg_rdisp(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_reg_disp_mem (anal, GET_TARGET_REG (code), code & 0x0F, LONG_SIZE); - r_strbuf_setf (&op->esil, "r%d,r%d,0x%x,+,=[4]", GET_SOURCE_REG (code), GET_TARGET_REG (code), (code & 0xF) << 2); + rz_strbuf_setf (&op->esil, "r%d,r%d,0x%x,+,=[4]", GET_SOURCE_REG (code), GET_TARGET_REG (code), (code & 0xF) << 2); return op->size; } -static int first_nibble_is_2(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_2(RzAnal* anal, RzAnalOp* op, ut16 code) { if (IS_MOVB_REG_TO_REGREF (code)) { // 0010nnnnmmmm0000 mov.b ,@ op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_reg_ref (anal, GET_TARGET_REG (code), BYTE_SIZE); - r_strbuf_setf (&op->esil, "r%d,r%d,=[1]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,=[1]", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVW_REG_TO_REGREF (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_reg_ref (anal, GET_TARGET_REG (code), WORD_SIZE); - r_strbuf_setf (&op->esil, "r%d,r%d,=[2]", GET_SOURCE_REG (code) & 0xFF, GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,=[2]", GET_SOURCE_REG (code) & 0xFF, GET_TARGET_REG (code)); } else if (IS_MOVL_REG_TO_REGREF (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_reg_ref (anal, GET_TARGET_REG (code), LONG_SIZE); - r_strbuf_setf (&op->esil, "r%d,r%d,=[4]", GET_SOURCE_REG (code) & 0xFF, GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,=[4]", GET_SOURCE_REG (code) & 0xFF, GET_TARGET_REG (code)); } else if (IS_AND_REGS (code)) { op->type = R_ANAL_OP_TYPE_AND; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,&=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,&=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_XOR_REGS (code)) { op->type = R_ANAL_OP_TYPE_XOR; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,^=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,^=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_OR_REGS (code)) { op->type = R_ANAL_OP_TYPE_OR; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,|=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,|=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_PUSHB (code)) { op->type = R_ANAL_OP_TYPE_PUSH; - r_strbuf_setf (&op->esil, "1,r%d,-=,r%d,r%d,=[1]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,r%d,-=,r%d,r%d,=[1]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_PUSHW (code)) { op->type = R_ANAL_OP_TYPE_PUSH; - r_strbuf_setf (&op->esil, "2,r%d,-=,r%d,r%d,=[2]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "2,r%d,-=,r%d,r%d,=[2]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_PUSHL (code)) { op->type = R_ANAL_OP_TYPE_PUSH; - r_strbuf_setf (&op->esil, "4,r%d,-=,r%d,r%d,=[4]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,r%d,r%d,=[4]", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_TSTRR (code)) { op->type = R_ANAL_OP_TYPE_ACMP; - r_strbuf_setf (&op->esil, "1,sr,|=,r%d,r%d,&,?{,0xFFFFFFFE,sr,&=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,sr,|=,r%d,r%d,&,?{,0xFFFFFFFE,sr,&=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_CMPSTR (code)) { //0010nnnnmmmm1100 cmp/str , op->type = R_ANAL_OP_TYPE_ACMP; //maybe not? op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,24,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},16,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},8,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},r%d,r%d,^,0xFF,&,!,?{,1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,24,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},16,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},8,r%d,r%d,^,>>,0xFF,&,!,?{,1,sr,|=,},r%d,r%d,^,0xFF,&,!,?{,1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_XTRCT (code)) { //0010nnnnmmmm1101 xtrct , op->type = R_ANAL_OP_TYPE_MOV; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "16,r%d,0xFFFF,&,<<,16,r%d,0xFFFF0000,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "16,r%d,0xFFFF,&,<<,16,r%d,0xFFFF0000,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_DIV0S (code)) { op->type = R_ANAL_OP_TYPE_DIV; - r_strbuf_setf (&op->esil, "0xFFFFFCFE,sr,&=,r%d,0x80000000,&,?{,0x200,sr,|=,},r%d,0x80000000,&,?{,0x100,sr,|=,},sr,1,sr,<<,^,0x200,&,?{,1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFCFE,sr,&=,r%d,0x80000000,&,?{,0x200,sr,|=,},r%d,0x80000000,&,?{,0x100,sr,|=,},sr,1,sr,<<,^,0x200,&,?{,1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MULUW (code)) { op->type = R_ANAL_OP_TYPE_MUL; op->src[0] = anal_fill_ai_rg(anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg(anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r%d,0xFFFF,&,*,macl,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r%d,0xFFFF,&,*,macl,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MULSW (code)) { //0010nnnnmmmm111_ mul{s,u}.w , op->type = R_ANAL_OP_TYPE_MUL; op->src[0] = anal_fill_ai_rg(anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg(anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, S16_EXT("r%d") "," S16_EXT("r%d") ",*,macl,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, S16_EXT("r%d") "," S16_EXT("r%d") ",*,macl,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } return op->size; } -static int first_nibble_is_3(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_3(RzAnal* anal, RzAnalOp* op, ut16 code) { //TODO Handle carry/overflow , CMP/xx? if (IS_ADD (code)) { op->type = R_ANAL_OP_TYPE_ADD; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_ADDC (code)) { op->type = R_ANAL_OP_TYPE_ADD; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "sr,0x1,&,0xFFFFFFFE,sr,&=,r%d,+=,31,$c,sr,|,sr,:=,r%d,r%d,+=,31,$c,sr,|,sr,:=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "sr,0x1,&,0xFFFFFFFE,sr,&=,r%d,+=,31,$c,sr,|,sr,:=,r%d,r%d,+=,31,$c,sr,|,sr,:=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_ADDV (code)) { op->type = R_ANAL_OP_TYPE_ADD; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,+=,31,$o,sr,|=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,+=,31,$o,sr,|=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_SUB (code)) { op->type = R_ANAL_OP_TYPE_SUB; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,-=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,-=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_SUBC (code)) { op->type = R_ANAL_OP_TYPE_SUB; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "sr,1,&," CLR_T ",r%d,-=,31,$b,sr,|,sr,:=,r%d,r%d,-=,31,$b,sr,|,sr,:=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "sr,1,&," CLR_T ",r%d,-=,31,$b,sr,|,sr,:=,r%d,r%d,-=,31,$b,sr,|,sr,:=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_SUBV (code)) { op->type = R_ANAL_OP_TYPE_SUB; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, CLR_T ",r%d,r%d,-=,31,$o,sr,|,sr,:=", GET_SOURCE_REG(code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, CLR_T ",r%d,r%d,-=,31,$o,sr,|,sr,:=", GET_SOURCE_REG(code), GET_TARGET_REG (code)); } else if (IS_CMPEQ (code)) { op->type = R_ANAL_OP_TYPE_CMP; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&,r%d,r%d,^,!,|,sr,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&,r%d,r%d,^,!,|,sr,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_CMPGE (code)) { op->type = R_ANAL_OP_TYPE_CMP; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,>=,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,>=,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_CMPGT (code)) { op->type = R_ANAL_OP_TYPE_CMP; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,>,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,r%d,>,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_CMPHI (code)) { op->type = R_ANAL_OP_TYPE_CMP; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x100000000,+,r%d,0x100000000,+,>,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x100000000,+,r%d,0x100000000,+,>,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_CMPHS (code)) { op->type = R_ANAL_OP_TYPE_CMP; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x100000000,+,r%d,0x100000000,+,>=,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x100000000,+,r%d,0x100000000,+,>=,?{,0x1,sr,|=,}", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_DIV1 (code)) { op->type = R_ANAL_OP_TYPE_DIV; op->src[0] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "1,sr,>>,sr,^,0x80,&," //old_Q^M "0xFFFFFF7F,sr,&=," "1,r%d,DUP,0x80000000,&,?{,0x80,sr,|=,},<<,sr,0x1,&,|,r%d,=," //shift Q<-Rn<-T @@ -582,58 +582,58 @@ static int first_nibble_is_3(RAnal* anal, RAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_MUL; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "32,r%d,r%d,*,DUP,0xFFFFFFFF,&,macl,=,>>,mach,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "32,r%d,r%d,*,DUP,0xFFFFFFFF,&,macl,=,>>,mach,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_DMULS (code)) { op->type = R_ANAL_OP_TYPE_MUL; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->src[1] = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "32,r%d,r%d,0x80000000,&,?{,0xFFFFFFFF00000000,+,},r%d,r%d,0x80000000,&,?{,0xFFFFFFFF00000000,+,},*,DUP,0xFFFFFFFF,&,macl,=,>>,mach,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "32,r%d,r%d,0x80000000,&,?{,0xFFFFFFFF00000000,+,},r%d,r%d,0x80000000,&,?{,0xFFFFFFFF00000000,+,},*,DUP,0xFFFFFFFF,&,macl,=,>>,mach,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); } return op->size; } -static int first_nibble_is_4(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_4(RzAnal* anal, RzAnalOp* op, ut16 code) { switch(code & 0xF0FF) { //TODO: change to common } else if construction case 0x4020: //shal op->type = R_ANAL_OP_TYPE_SAL; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,0x1,sr,|=,},1,r%d,<<=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,0x1,sr,|=,},1,r%d,<<=", GET_TARGET_REG (code), GET_TARGET_REG (code)); break; case 0x4021: //shar op->type = R_ANAL_OP_TYPE_SAR; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,?{,0x1,sr,|=,},0,r%d,0x80000000,&,?{,0x80000000,+,},1,r%d,>>=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,?{,0x1,sr,|=,},0,r%d,0x80000000,&,?{,0x80000000,+,},1,r%d,>>=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); break; case 0x4000: //shll op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,0x1,sr,|=,},1,r%d,<<=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,0x1,sr,|=,},1,r%d,<<=", GET_TARGET_REG (code), GET_TARGET_REG (code)); break; case 0x4008: //shll2 op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_setf (&op->esil, "2,r%d,<<=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "2,r%d,<<=", GET_TARGET_REG (code)); break; case 0x4018: //shll8 op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_setf (&op->esil, "8,r%d,<<=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "8,r%d,<<=", GET_TARGET_REG (code)); break; case 0x4028: //shll16 op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_setf (&op->esil, "16,r%d,<<=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "16,r%d,<<=", GET_TARGET_REG (code)); break; case 0x4001: //shlr - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,?{,0x1,sr,|=,},1,r%d,>>=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,?{,0x1,sr,|=,},1,r%d,>>=", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_SHR; break; case 0x4009: //shlr2 - r_strbuf_setf (&op->esil, "2,r%d,>>=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "2,r%d,>>=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_SHR; break; case 0x4019: //shlr8 - r_strbuf_setf (&op->esil, "8,r%d,>>=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "8,r%d,>>=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_SHR; break; case 0x4029: //shlr16 - r_strbuf_setf (&op->esil, "16,r%d,>>=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "16,r%d,>>=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_SHR; break; default: @@ -645,94 +645,94 @@ static int first_nibble_is_4(RAnal* anal, RAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_RCALL; //call to reg op->delay = 1; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,r%d,pc,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,r%d,pc,=", GET_TARGET_REG (code)); } else if (IS_JMP (code)) { op->type = R_ANAL_OP_TYPE_UJMP; //jmp to reg op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->delay = 1; op->eob = true; - r_strbuf_setf (&op->esil, "1,SETD,r%d,pc,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,SETD,r%d,pc,=", GET_TARGET_REG (code)); } else if (IS_CMPPL (code)) { op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0,r%d,>,?{,0x1,sr,|=,}", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0,r%d,>,?{,0x1,sr,|=,}", GET_TARGET_REG (code)); } else if (IS_CMPPZ (code)) { op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0,r%d,>=,?{,0x1,sr,|=,}", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0,r%d,>=,?{,0x1,sr,|=,}", GET_TARGET_REG (code)); } else if (IS_LDCLSR (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],0x0FFF0FFF,&,sr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],0x0FFF0FFF,&,sr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_LDCLSRGBR (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],gbr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],gbr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_LDCLSRVBR (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],vbr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],vbr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); //todo ssr? } else if (IS_LDSLMACH (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],mach,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],mach,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_LDSLMACL (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],macl,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],macl,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_LDSLPR (code)) { op->type = R_ANAL_OP_TYPE_POP; - r_strbuf_setf (&op->esil, "r%d,[4],pr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],pr,=,4,r%d,+=", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_LDCSR (code)) { - r_strbuf_setf (&op->esil, "r%d,0x0FFF0FFF,&,sr,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0x0FFF0FFF,&,sr,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_LDCGBR (code)) { - r_strbuf_setf (&op->esil, "r%d,gbr,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,gbr,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_LDCVBR (code)) { - r_strbuf_setf (&op->esil, "r%d,vbr,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,vbr,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_LDSMACH (code)) { - r_strbuf_setf (&op->esil, "r%d,mach,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,mach,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_LDSMACL (code)) { - r_strbuf_setf (&op->esil, "r%d,macl,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,macl,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_LDSPR (code)) { - r_strbuf_setf (&op->esil, "r%d,pr,=", GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,pr,=", GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } else if (IS_ROTR (code)) { - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,sr,|=,0x1,r%d,>>>,r%d,=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,0x1,&,sr,|=,0x1,r%d,>>>,r%d,=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = (code & 1)? R_ANAL_OP_TYPE_ROR:R_ANAL_OP_TYPE_ROL; } else if (IS_ROTL (code)) { - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0x1,r%d,<<<,r%d,=,r%d,0x1,&,sr,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0x1,r%d,<<<,r%d,=,r%d,0x1,&,sr,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = (code & 1)? R_ANAL_OP_TYPE_ROR:R_ANAL_OP_TYPE_ROL; } else if (IS_ROTCR (code)) { - r_strbuf_setf (&op->esil, "0,sr,0x1,&,?{,0x80000000,},0xFFFFFFFE,sr,&=,r%d,1,&,sr,|=,1,r%d,>>=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0,sr,0x1,&,?{,0x80000000,},0xFFFFFFFE,sr,&=,r%d,1,&,sr,|=,1,r%d,>>=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = (code & 1)? R_ANAL_OP_TYPE_ROR:R_ANAL_OP_TYPE_ROL; } else if (IS_ROTCL (code)) { - r_strbuf_setf (&op->esil, "sr,0x1,&,0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,1,sr,|=,},1,r%d,<<=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "sr,0x1,&,0xFFFFFFFE,sr,&=,r%d,0x80000000,&,?{,1,sr,|=,},1,r%d,<<=,r%d,|=", GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = (code & 1)? R_ANAL_OP_TYPE_ROR:R_ANAL_OP_TYPE_ROL; } else if (IS_STCLSR (code)) { - r_strbuf_setf (&op->esil, "4,r%d,-=,sr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,sr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_PUSH; } else if (IS_STCLGBR (code)) { - r_strbuf_setf (&op->esil, "4,r%d,-=,gbr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,gbr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_PUSH; } else if (IS_STCLVBR (code)) { - r_strbuf_setf (&op->esil, "4,r%d,-=,vbr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,vbr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_PUSH; } else if (IS_STSLMACL (code)) { - r_strbuf_setf (&op->esil, "4,r%d,-=,macl,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,macl,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_PUSH; } else if (IS_STSLMACH (code)) { - r_strbuf_setf (&op->esil, "4,r%d,-=,mach,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,mach,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_PUSH; } else if (IS_STSLPR (code)) { op->type = R_ANAL_OP_TYPE_PUSH; - r_strbuf_setf (&op->esil, "4,r%d,-=,pr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "4,r%d,-=,pr,r%d,=[4]", GET_TARGET_REG (code), GET_TARGET_REG (code)); } else if (IS_TASB (code)) { - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,[1],!,?{,0x80,r%d,=[1],1,sr,|=,}", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r%d,[1],!,?{,0x80,r%d,=[1],1,sr,|=,}", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_UNK; } else if (IS_DT (code)) { - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,1,r%d,-=,$z,sr,|,sr,:=", GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,1,r%d,-=,$z,sr,|,sr,:=", GET_TARGET_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_UNK; } else if (IS_MACW(code)){ - r_strbuf_setf (&op->esil, + rz_strbuf_setf (&op->esil, "0x2,sr,&,!,?{," //if S==0 S16_EXT("r%d,[2]")"," //@Rn sign extended S16_EXT("r%d,[2]")"," //@Rm sign extended @@ -770,36 +770,36 @@ static int first_nibble_is_4(RAnal* anal, RAnalOp* op, ut16 code) { } //nibble=5; 0101nnnnmmmmi4*4 mov.l @(,), -static int movl_rdisp_reg(RAnal* anal, RAnalOp* op, ut16 code) { +static int movl_rdisp_reg(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[0] = anal_fill_reg_disp_mem (anal, GET_SOURCE_REG (code), code & 0x0F, LONG_SIZE); - r_strbuf_setf (&op->esil, "r%d,0x%x,+,[4],r%d,=", GET_SOURCE_REG (code), (code&0xF) * 4, GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0x%x,+,[4],r%d,=", GET_SOURCE_REG (code), (code&0xF) * 4, GET_TARGET_REG (code)); return op->size; } -static int first_nibble_is_6(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_6(RzAnal* anal, RzAnalOp* op, ut16 code) { if (IS_MOV_REGS (code)) { op->type = R_ANAL_OP_TYPE_MOV; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVB_REGREF_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_reg_ref (anal, GET_SOURCE_REG (code), BYTE_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0x000000FF,r%d,&=,r%d,[1],DUP,0x80,&,?{,0xFFFFFF00,|=,},r%d,=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x000000FF,r%d,&=,r%d,[1],DUP,0x80,&,?{,0xFFFFFF00,|=,},r%d,=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVW_REGREF_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_reg_ref (anal, GET_SOURCE_REG (code), WORD_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0x0000FFFF,r%d,&=,r%d,[2],DUP,0x8000,&,?{,0xFFFF0000,|=,},r%d,=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x0000FFFF,r%d,&=,r%d,[2],DUP,0x8000,&,?{,0xFFFF0000,|=,},r%d,=", GET_TARGET_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_MOVL_REGREF_TO_REG (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_fill_reg_ref (anal, GET_SOURCE_REG (code), LONG_SIZE); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,[4],r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); } else if (IS_EXT (code)) { //ext{s,u}.{b,w} instructs. todo : more detail ? op->type = R_ANAL_OP_TYPE_MOV; @@ -807,56 +807,56 @@ static int first_nibble_is_6(RAnal* anal, RAnalOp* op, ut16 code) { op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); switch(code & 0xF) { case 0xC: //EXTU.B - r_strbuf_setf (&op->esil, "r%d,0xFF,&,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFF,&,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); break; case 0xD: //EXTU.W - r_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFFFF,&,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); break; case 0xE: //EXTS.B - r_strbuf_setf (&op->esil, "r%d,0xFF,&,DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFF,&,DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); break; case 0xF: //EXTS.W - r_strbuf_setf (&op->esil, "r%d,0xFFFF,&,DUP,0x8000,&,?{,0xFFFF0000,|,},r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFFFF,&,DUP,0x8000,&,?{,0xFFFF0000,|,},r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); break; default: - r_strbuf_setf (&op->esil, "TODO,NOT IMPLEMENTED"); + rz_strbuf_setf (&op->esil, "TODO,NOT IMPLEMENTED"); break; } } else if (IS_MOVB_POP (code)) { op->type = R_ANAL_OP_TYPE_POP; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,=,1,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,=,1,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); } else if (IS_MOVW_POP (code)) { op->type = R_ANAL_OP_TYPE_POP; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r%d,=,2,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r%d,=,2,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); } else if (IS_MOVL_POP (code)) { op->type = R_ANAL_OP_TYPE_POP; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "r%d,[4],r%d,=,4,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,[4],r%d,=,4,r%d,+=", GET_SOURCE_REG (code), GET_TARGET_REG (code), GET_SOURCE_REG (code)); } else if (IS_NEG (code)) { //todo: neg and negc details op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "r%d,0,-,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0,-,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); } else if (IS_NEGC (code)) { op->type = R_ANAL_OP_TYPE_UNK; - r_strbuf_setf (&op->esil, "1,sr,&,0xFFFFFFFE,sr,&=,r%d,+,0,-,31,$b,sr,|,sr,=,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "1,sr,&,0xFFFFFFFE,sr,&=,r%d,+,0,-,31,$b,sr,|,sr,=,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); } else if (IS_NOT (code)) { //todo : details? - r_strbuf_setf (&op->esil, "0xFFFFFFFF,r%d,^,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0xFFFFFFFF,r%d,^,r%d,=", GET_SOURCE_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_NOT; op->src[0] = anal_fill_ai_rg (anal, GET_SOURCE_REG (code)); op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); } else if (IS_SWAPB (code)) { - r_strbuf_setf (&op->esil, "r%d,0xFFFF0000,&,8,r%d,0xFF,&,<<,|,8,r%d,0xFF00,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "r%d,0xFFFF0000,&,8,r%d,0xFF,&,<<,|,8,r%d,0xFF00,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; //todo : details } else if (IS_SWAPW (code)) { - r_strbuf_setf (&op->esil, "16,r%d,0xFFFF,&,<<,16,r%d,0xFFFF0000,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "16,r%d,0xFFFF,&,<<,16,r%d,0xFFFF0000,&,>>,|,r%d,=", GET_SOURCE_REG (code), GET_SOURCE_REG (code), GET_TARGET_REG (code)); op->type = R_ANAL_OP_TYPE_MOV; } return op->size; @@ -864,105 +864,105 @@ static int first_nibble_is_6(RAnal* anal, RAnalOp* op, ut16 code) { //nibble=7; 0111nnnni8*1.... add #, -static int add_imm(RAnal* anal, RAnalOp* op, ut16 code) { +static int add_imm(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_ADD; op->src[0] = anal_fill_im (anal, (st8)(code & 0xFF)); //Casting to (st8) forces sign-extension. op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0x%x,DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,+=", code & 0xFF, GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x%x,DUP,0x80,&,?{,0xFFFFFF00,|,},r%d,+=", code & 0xFF, GET_TARGET_REG (code)); return op->size; } -static int first_nibble_is_8(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_8(RzAnal* anal, RzAnalOp* op, ut16 code) { if (IS_BT_OR_BF (code)) { op->type = R_ANAL_OP_TYPE_CJMP; //Jump if true or jump if false insns op->jump = disarm_8bit_offset (op->addr, GET_BTF_OFFSET (code)); op->fail = op->addr + 2 ; op->eob = true; if (IS_BT (code)) { - r_strbuf_setf (&op->esil, "sr,1,&,?{,0x%x,pc,=,}", op->jump); + rz_strbuf_setf (&op->esil, "sr,1,&,?{,0x%x,pc,=,}", op->jump); } else if (IS_BTS (code)) { - r_strbuf_setf (&op->esil, "1,SETD,sr,1,&,?{,0x%x,pc,=,}", op->jump); + rz_strbuf_setf (&op->esil, "1,SETD,sr,1,&,?{,0x%x,pc,=,}", op->jump); op->delay = 1; //Only /S versions have a delay slot } else if (IS_BFS (code)) { - r_strbuf_setf (&op->esil, "1,SETD,sr,1,&,!,?{,0x%x,pc,=,}",op->jump); + rz_strbuf_setf (&op->esil, "1,SETD,sr,1,&,!,?{,0x%x,pc,=,}",op->jump); op->delay = 1; //Only /S versions have a delay slot } else if (IS_BF (code)) { - r_strbuf_setf (&op->esil, "sr,1,&,!,?{,0x%x,pc,=,}", op->jump); + rz_strbuf_setf (&op->esil, "sr,1,&,!,?{,0x%x,pc,=,}", op->jump); } } else if (IS_MOVB_REGDISP_R0 (code)) { // 10000100mmmmi4*1 mov.b @(,),R0 op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, 0); op->src[0] = anal_fill_reg_disp_mem (anal, GET_SOURCE_REG (code), code & 0x0F, BYTE_SIZE); - r_strbuf_setf (&op->esil, "r%d,0x%x,+,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r0,=", GET_SOURCE_REG (code), code & 0xF); + rz_strbuf_setf (&op->esil, "r%d,0x%x,+,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r0,=", GET_SOURCE_REG (code), code & 0xF); } else if (IS_MOVW_REGDISP_R0 (code)) { // 10000101mmmmi4*2 mov.w @(,),R0 op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, 0); op->src[0] = anal_fill_reg_disp_mem (anal, GET_SOURCE_REG (code), code & 0x0F, WORD_SIZE); - r_strbuf_setf (&op->esil, "r%d,0x%x,+,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r0,=", GET_SOURCE_REG (code), (code & 0xF) * 2); + rz_strbuf_setf (&op->esil, "r%d,0x%x,+,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r0,=", GET_SOURCE_REG (code), (code & 0xF) * 2); } else if (IS_CMPIMM (code)) { op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0x%x,DUP,0x80,&,?{,0xFFFFFF00,|,},r0,==,$z,sr,|,sr,:=", code & 0xFF); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,0x%x,DUP,0x80,&,?{,0xFFFFFF00,|,},r0,==,$z,sr,|,sr,:=", code & 0xFF); } else if (IS_MOVB_R0_REGDISP (code)) { /* 10000000mmmmi4*1 mov.b R0,@(,)*/ op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, 0); op->dst = anal_fill_reg_disp_mem (anal, GET_SOURCE_REG (code), code & 0x0F, BYTE_SIZE); - r_strbuf_setf (&op->esil, "r0,0xFF,&,0x%x,r%d,+,=[1]", code & 0xF, GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r0,0xFF,&,0x%x,r%d,+,=[1]", code & 0xF, GET_SOURCE_REG (code)); } else if (IS_MOVW_R0_REGDISP (code)) { // 10000001mmmmi4*2 mov.w R0,@(,)) op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, 0); op->dst = anal_fill_reg_disp_mem (anal, GET_SOURCE_REG (code), code & 0x0F, WORD_SIZE); - r_strbuf_setf (&op->esil, "r0,0xFFFF,&,0x%x,r%d,+,=[2]", (code & 0xF) * 2, GET_SOURCE_REG (code)); + rz_strbuf_setf (&op->esil, "r0,0xFFFF,&,0x%x,r%d,+,=[2]", (code & 0xF) * 2, GET_SOURCE_REG (code)); } return op->size; } //nibble=9; 1001nnnni8p2.... mov.w @(,PC), -static int movw_pcdisp_reg(RAnal* anal, RAnalOp* op, ut16 code) { +static int movw_pcdisp_reg(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - op->src[0] = r_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->base = (code & 0xFF) * 2+op->addr + 4; op->src[0]->memref=1; - r_strbuf_setf (&op->esil, "0x%x,[2],r%d,=,r%d,0x8000,&,?{,0xFFFF0000,r%d,|=,}", op->src[0]->base, GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x%x,[2],r%d,=,r%d,0x8000,&,?{,0xFFFF0000,r%d,|=,}", op->src[0]->base, GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); return op->size; } //nibble=A; 1010i12......... bra -static int bra(RAnal* anal, RAnalOp* op, ut16 code) { +static int bra(RzAnal* anal, RzAnalOp* op, ut16 code) { /* Unconditional branch, relative to PC */ op->type = R_ANAL_OP_TYPE_JMP; op->delay = 1; op->jump = disarm_12bit_offset (op, GET_BRA_OFFSET (code)); op->eob = true; - r_strbuf_setf (&op->esil, "1,SETD,0x%x,pc,=", op->jump); + rz_strbuf_setf (&op->esil, "1,SETD,0x%x,pc,=", op->jump); return op->size; } //nibble=B; 1011i12......... bsr -static int bsr(RAnal* anal, RAnalOp* op, ut16 code) { +static int bsr(RzAnal* anal, RzAnalOp* op, ut16 code) { /* Subroutine call, relative to PC */ op->type = R_ANAL_OP_TYPE_CALL; op->jump = disarm_12bit_offset (op, GET_BRA_OFFSET (code)); op->delay = 1; - r_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,0x%x,pc,=", op->jump); + rz_strbuf_setf (&op->esil, "1,SETD,pc,2,+,pr,=,0x%x,pc,=", op->jump); return op->size; } -static int first_nibble_is_c(RAnal* anal, RAnalOp* op, ut16 code) { +static int first_nibble_is_c(RzAnal* anal, RzAnalOp* op, ut16 code) { if (IS_TRAP (code)) { op->type = R_ANAL_OP_TYPE_SWI; op->val = (ut8)(code & 0xFF); - r_strbuf_setf (&op->esil, "4,r15,-=,sr,r15,=[4],4,r15,-=,2,pc,-,r15,=[4],2,0x%x,<<,4,+,vbr,+,pc,=", code & 0xFF); + rz_strbuf_setf (&op->esil, "4,r15,-=,sr,r15,=[4],4,r15,-=,2,pc,-,r15,=[4],2,0x%x,<<,4,+,vbr,+,pc,=", code & 0xFF); } else if (IS_MOVA_PCREL_R0 (code)) { // 11000111i8p4.... mova @(,PC),R0 op->type = R_ANAL_OP_TYPE_LEA; op->src[0] = anal_pcrel_disp_mov (anal, op, code & 0xFF, LONG_SIZE); //this is wrong ! op->dst = anal_fill_ai_rg (anal, 0); //Always R0 - r_strbuf_setf (&op->esil, "0x%x,pc,+,r0,=", (code & 0xFF) * 4); + rz_strbuf_setf (&op->esil, "0x%x,pc,+,r0,=", (code & 0xFF) * 4); } else if (IS_BINLOGIC_IMM_R0 (code)) { // 110010__i8 (binop) #imm, R0 op->src[0] = anal_fill_im (anal, code & 0xFF); op->src[1] = anal_fill_ai_rg (anal, 0); //Always R0 @@ -971,19 +971,19 @@ static int first_nibble_is_c(RAnal* anal, RAnalOp* op, ut16 code) { case 0xC800: //tst //TODO : get correct op->dst ! (T flag) op->type = R_ANAL_OP_TYPE_ACMP; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r0,0x%x,&,!,?{,1,sr,|=,}", code & 0xFF); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r0,0x%x,&,!,?{,1,sr,|=,}", code & 0xFF); break; case 0xC900: //and op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_setf (&op->esil, "0x%x,r0,&=", code & 0xFF); + rz_strbuf_setf (&op->esil, "0x%x,r0,&=", code & 0xFF); break; case 0xCA00: //xor op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_setf (&op->esil, "0x%x,r0,^=", code & 0xFF); + rz_strbuf_setf (&op->esil, "0x%x,r0,^=", code & 0xFF); break; case 0xCB00: //or op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_setf (&op->esil, "0x%x,r0,|=", code & 0xFF); + rz_strbuf_setf (&op->esil, "0x%x,r0,|=", code & 0xFF); break; } } else if (IS_BINLOGIC_IMM_GBR (code)) { //110011__i8 (binop).b #imm, @(R0,gbr) @@ -992,80 +992,80 @@ static int first_nibble_is_c(RAnal* anal, RAnalOp* op, ut16 code) { case 0xCC00: //tst //TODO : get correct op->dst ! (T flag) op->type = R_ANAL_OP_TYPE_ACMP; - r_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r0,gbr,+,[1],0x%x,&,!,?{,1,sr,|=,}", code & 0xFF); + rz_strbuf_setf (&op->esil, "0xFFFFFFFE,sr,&=,r0,gbr,+,[1],0x%x,&,!,?{,1,sr,|=,}", code & 0xFF); break; case 0xCD00: //and op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,&,r0,gbr,+,=[1]", code & 0xFF); + rz_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,&,r0,gbr,+,=[1]", code & 0xFF); break; case 0xCE00: //xor op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,^,r0,gbr,+,=[1]", code & 0xFF); + rz_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,^,r0,gbr,+,=[1]", code & 0xFF); break; case 0xCF00: //or op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,|,r0,gbr,+,=[1]", code & 0xFF); + rz_strbuf_setf (&op->esil, "r0,gbr,+,[1],0x%x,|,r0,gbr,+,=[1]", code & 0xFF); break; } //TODO : implement @(R0,gbr) dest and src[1] } else if (IS_MOVB_R0_GBRREF (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[1]", code & 0xFF); + rz_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[1]", code & 0xFF); } else if (IS_MOVW_R0_GBRREF (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[2]", (code & 0xFF) * 2); + rz_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[2]", (code & 0xFF) * 2); } else if (IS_MOVL_R0_GBRREF (code)) { op->type = R_ANAL_OP_TYPE_STORE; op->src[0] = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[4]", (code & 0xFF) * 4); + rz_strbuf_setf (&op->esil, "r0,gbr,0x%x,+,=[4]", (code & 0xFF) * 4); } else if (IS_MOVB_GBRREF_R0 (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "gbr,0x%x,+,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r0,=", (code & 0xFF)); + rz_strbuf_setf (&op->esil, "gbr,0x%x,+,[1],DUP,0x80,&,?{,0xFFFFFF00,|,},r0,=", (code & 0xFF)); } else if (IS_MOVW_GBRREF_R0 (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "gbr,0x%x,+,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r0,=", (code & 0xFF)*2); + rz_strbuf_setf (&op->esil, "gbr,0x%x,+,[2],DUP,0x8000,&,?{,0xFFFF0000,|,},r0,=", (code & 0xFF)*2); } else if (IS_MOVL_GBRREF_R0 (code)) { op->type = R_ANAL_OP_TYPE_LOAD; op->dst = anal_fill_ai_rg (anal, 0); - r_strbuf_setf (&op->esil, "gbr,0x%x,+,[4],r0,=", (code & 0xFF) * 4); + rz_strbuf_setf (&op->esil, "gbr,0x%x,+,[4],r0,=", (code & 0xFF) * 4); } return op->size; } //nibble=d; 1101nnnni8 : mov.l @(,PC), Rn -static int movl_pcdisp_reg(RAnal* anal, RAnalOp* op, ut16 code) { +static int movl_pcdisp_reg(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_LOAD; op->src[0] = anal_pcrel_disp_mov (anal, op, code & 0xFF, LONG_SIZE); //TODO: check it op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); - //r_strbuf_setf (&op->esil, "0x%x,[4],r%d,=", (code & 0xFF) * 4 + (op->addr & 0xfffffff3) + 4, GET_TARGET_REG (code)); - r_strbuf_setf (&op->esil, "0x%x,[4],r%d,=", (code & 0xFF) * 4 + ((op->addr >> 2)<<2) + 4, GET_TARGET_REG (code)); + //rz_strbuf_setf (&op->esil, "0x%x,[4],r%d,=", (code & 0xFF) * 4 + (op->addr & 0xfffffff3) + 4, GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x%x,[4],r%d,=", (code & 0xFF) * 4 + ((op->addr >> 2)<<2) + 4, GET_TARGET_REG (code)); return op->size; } //nibble=e; 1110nnnni8*1.... mov #, -static int mov_imm_reg(RAnal* anal, RAnalOp* op, ut16 code) { +static int mov_imm_reg(RzAnal* anal, RzAnalOp* op, ut16 code) { op->type = R_ANAL_OP_TYPE_MOV; op->dst = anal_fill_ai_rg (anal, GET_TARGET_REG (code)); op->src[0] = anal_fill_im (anal, (st8)(code & 0xFF)); - r_strbuf_setf (&op->esil, "0x%x,r%d,=,r%d,0x80,&,?{,0xFFFFFF00,r%d,|=,}", code & 0xFF, GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); + rz_strbuf_setf (&op->esil, "0x%x,r%d,=,r%d,0x80,&,?{,0xFFFFFF00,r%d,|=,}", code & 0xFF, GET_TARGET_REG (code), GET_TARGET_REG (code), GET_TARGET_REG (code)); return op->size; } //nibble=f; -static int fpu_insn(RAnal* anal, RAnalOp* op, ut16 code) { +static int fpu_insn(RzAnal* anal, RzAnalOp* op, ut16 code) { //Not interested on FPU stuff for now op->family = R_ANAL_OP_FAMILY_FPU; return op->size; } /* Table of routines for further analysis based on 1st nibble */ -static int (*first_nibble_decode[])(RAnal*,RAnalOp*,ut16) = { +static int (*first_nibble_decode[])(RzAnal*,RzAnalOp*,ut16) = { first_nibble_is_0, movl_reg_rdisp, first_nibble_is_2, @@ -1088,7 +1088,7 @@ static int (*first_nibble_decode[])(RAnal*,RAnalOp*,ut16) = { /* This is the basic operation analysis. Just initialize and jump to * routines defined in first_nibble_decode table */ -static int sh_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int sh_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { ut8 op_MSB, op_LSB; int ret; if (!data || len < 2) { @@ -1107,7 +1107,7 @@ static int sh_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, } /* Set the profile register */ -static bool sh_set_reg_profile(RAnal* anal) { +static bool sh_set_reg_profile(RzAnal* anal) { //TODO Add system ( ssr, spc ) + fpu regs const char *p = "=PC pc\n" @@ -1142,10 +1142,10 @@ static bool sh_set_reg_profile(RAnal* anal) { "gpr vbr .32 80 0\n" "gpr mach .32 84 0\n" "gpr macl .32 88 0\n"; - return r_reg_set_profile_string(anal->reg, p); + return rz_reg_set_profile_string(anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { #if 0 if (q == R_ANAL_ARCHINFO_ALIGN) { return 4; @@ -1155,7 +1155,7 @@ static int archinfo(RAnal *anal, int q) { } -RAnalPlugin r_anal_plugin_sh = { +RzAnalPlugin rz_anal_plugin_sh = { .name = "sh", .desc = "SH-4 code analysis plugin", .license = "LGPL3", @@ -1168,9 +1168,9 @@ RAnalPlugin r_anal_plugin_sh = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_sh, + .data = &rz_anal_plugin_sh, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_snes.c b/librz/anal/p/anal_snes.c similarity index 95% rename from libr/anal/p/anal_snes.c rename to librz/anal/p/anal_snes.c index 62027ad2f2..6451e254ba 100644 --- a/libr/anal/p/anal_snes.c +++ b/librz/anal/p/anal_snes.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2015 - condret */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/snes/snes_op_table.h" #include "../../asm/p/asm_snes.h" static struct snes_asm_flags* snesflags = NULL; -static int snes_anop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int snes_anop(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { op->size = snes_op_get_size(snesflags->M, snesflags->X, &snes_op[data[0]]); if (op->size > len) { return op->size = 0; @@ -252,7 +252,7 @@ static int snes_anal_fini (void* user) { return 0; } -RAnalPlugin r_anal_plugin_snes = { +RzAnalPlugin rz_anal_plugin_snes = { .name = "snes", .desc = "SNES analysis plugin", .license = "LGPL3", @@ -264,9 +264,9 @@ RAnalPlugin r_anal_plugin_snes = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_snes, + .data = &rz_anal_plugin_snes, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_sparc_cs.c b/librz/anal/p/anal_sparc_cs.c similarity index 83% rename from libr/anal/p/anal_sparc_cs.c rename to librz/anal/p/anal_sparc_cs.c index 63b9825593..ef4945c1e5 100644 --- a/libr/anal/p/anal_sparc_cs.c +++ b/librz/anal/p/anal_sparc_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2014-2017 - pancake */ +/* rizin - LGPL - Copyright 2014-2017 - pancake */ -#include -#include +#include +#include #include #include @@ -9,49 +9,49 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->sparc.operands[n] #define INSCC insn->detail->sparc.cc static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_sparc *x = &insn->detail->sparc; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_sparc_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case SPARC_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case SPARC_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case SPARC_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != SPARC_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "}"); } -static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) { +static int parse_reg_name(RzRegItem *reg, csh handle, cs_insn *insn, int reg_num) { if (!reg) { return -1; } @@ -70,13 +70,13 @@ static int parse_reg_name(RRegItem *reg, csh handle, cs_insn *insn, int reg_num) return 0; } -static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { - static RRegItem reg; +static void op_fillval(RzAnalOp *op, csh handle, cs_insn *insn) { + static RzRegItem reg; switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_LOAD: if (INSOP(0).type == SPARC_OP_MEM) { ZERO_FILL (reg); - op->src[0] = r_anal_value_new (); + op->src[0] = rz_anal_value_new (); op->src[0]->reg = ® parse_reg_name (op->src[0]->reg, handle, insn, 0); op->src[0]->delta = INSOP(0).mem.disp; @@ -85,7 +85,7 @@ static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { case R_ANAL_OP_TYPE_STORE: if (INSOP(1).type == SPARC_OP_MEM) { ZERO_FILL (reg); - op->dst = r_anal_value_new (); + op->dst = rz_anal_value_new (); op->dst->reg = ® parse_reg_name (op->dst->reg, handle, insn, 1); op->dst->delta = INSOP(1).mem.disp; @@ -94,7 +94,7 @@ static void op_fillval(RAnalOp *op, csh handle, cs_insn *insn) { } } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static csh handle = 0; static int omode; cs_insn *insn; @@ -318,7 +318,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = \ "=PC pc\n" "=SP sp\n" @@ -373,14 +373,14 @@ static bool set_reg_profile(RAnal *anal) { "gpr fp .32 136 0\n" "gpr i7 .32 140 0\n" ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; /* :D */ } -RAnalPlugin r_anal_plugin_sparc_cs = { +RzAnalPlugin rz_anal_plugin_sparc_cs = { .name = "sparc", .desc = "Capstone SPARC analysis", .esil = true, @@ -393,9 +393,9 @@ RAnalPlugin r_anal_plugin_sparc_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_sparc_cs, + .data = &rz_anal_plugin_sparc_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_sparc_gnu.c b/librz/anal/p/anal_sparc_gnu.c similarity index 88% rename from libr/anal/p/anal_sparc_gnu.c rename to librz/anal/p/anal_sparc_gnu.c index ae42dcdf6e..026d15c804 100644 --- a/libr/anal/p/anal_sparc_gnu.c +++ b/librz/anal/p/anal_sparc_gnu.c @@ -2,10 +2,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include enum { GPR_G0 = 0, @@ -274,27 +274,27 @@ static st64 get_immed_sgnext(const ut64 insn, const ut8 nbit) { | (((insn & ((ut64)1 << nbit)) >> nbit) * mask)); } -static RAnalValue * value_fill_addr_pc_disp(const ut64 addr, const st64 disp) { - RAnalValue *val = r_anal_value_new(); +static RzAnalValue * value_fill_addr_pc_disp(const ut64 addr, const st64 disp) { + RzAnalValue *val = rz_anal_value_new(); val->base = addr + disp; return val; } -static RAnalValue * value_fill_addr_reg_regdelta(RAnal const * const anal, const int ireg, const int iregdelta) { - RAnalValue *val = r_anal_value_new(); - val->reg = r_reg_get(anal->reg, gpr_regs[ireg], R_REG_TYPE_GPR); - val->reg = r_reg_get(anal->reg, gpr_regs[iregdelta], R_REG_TYPE_GPR); +static RzAnalValue * value_fill_addr_reg_regdelta(RzAnal const * const anal, const int ireg, const int iregdelta) { + RzAnalValue *val = rz_anal_value_new(); + val->reg = rz_reg_get(anal->reg, gpr_regs[ireg], R_REG_TYPE_GPR); + val->reg = rz_reg_get(anal->reg, gpr_regs[iregdelta], R_REG_TYPE_GPR); return val; } -static RAnalValue * value_fill_addr_reg_disp(RAnal const * const anal, const int ireg, const st64 disp) { - RAnalValue *val = r_anal_value_new(); - val->reg = r_reg_get(anal->reg, gpr_regs[ireg], R_REG_TYPE_GPR); +static RzAnalValue * value_fill_addr_reg_disp(RzAnal const * const anal, const int ireg, const st64 disp) { + RzAnalValue *val = rz_anal_value_new(); + val->reg = rz_reg_get(anal->reg, gpr_regs[ireg], R_REG_TYPE_GPR); val->delta = disp; return val; } -static void anal_call(RAnalOp *op, const ut32 insn, const ut64 addr) { +static void anal_call(RzAnalOp *op, const ut32 insn, const ut64 addr) { const st64 disp = (get_immed_sgnext(insn, 29) * 4); op->type = R_ANAL_OP_TYPE_CALL; op->dst = value_fill_addr_pc_disp(addr, disp); @@ -302,7 +302,7 @@ static void anal_call(RAnalOp *op, const ut32 insn, const ut64 addr) { op->fail = addr + 4; } -static void anal_jmpl(RAnal const * const anal, RAnalOp *op, const ut32 insn, const ut64 addr) { +static void anal_jmpl(RzAnal const * const anal, RzAnalOp *op, const ut32 insn, const ut64 addr) { st64 disp = 0; if (X_LDST_I (insn)) { disp = get_immed_sgnext (insn, 12); @@ -331,23 +331,23 @@ static void anal_jmpl(RAnal const * const anal, RAnalOp *op, const ut32 insn, co } } -static void anal_branch(RAnalOp *op, const ut32 insn, const ut64 addr) { +static void anal_branch(RzAnalOp *op, const ut32 insn, const ut64 addr) { st64 disp = 0; - int r_cond = 0; + int rz_cond = 0; op->eob = true; /* handle the conditions */ if(X_OP2(insn) == OP2_Bicc || X_OP2(insn) == OP2_BPcc) { - r_cond = icc_to_r_cond (X_COND(insn)); + rz_cond = icc_to_r_cond (X_COND(insn)); } else if(X_OP2(insn) == OP2_FBfcc || X_OP2(insn) == OP2_FBPfcc) { - r_cond = fcc_to_r_cond (X_COND(insn)); + rz_cond = fcc_to_r_cond (X_COND(insn)); } else if(X_OP2(insn) == OP2_BPr) { - r_cond = R_ANAL_COND_UNKNOWN; + rz_cond = R_ANAL_COND_UNKNOWN; } - if (r_cond == R_ANAL_COND_ALWAYS) { + if (rz_cond == R_ANAL_COND_ALWAYS) { op->type = R_ANAL_OP_TYPE_JMP; - } else if (r_cond == R_ANAL_COND_NEVER) { + } else if (rz_cond == R_ANAL_COND_NEVER) { op->type = R_ANAL_OP_TYPE_NOP; return; } else { @@ -369,7 +369,7 @@ static void anal_branch(RAnalOp *op, const ut32 insn, const ut64 addr) { } // TODO: this implementation is just a fast hack. needs to be rewritten and completed -static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int sparc_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { int sz = 4; ut32 insn; @@ -391,7 +391,7 @@ static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case OP2_ILLTRAP: case OP2_INV: op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ break; case OP2_BPcc: case OP2_Bicc: @@ -412,24 +412,24 @@ static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case OP32_INV4: case OP32_INV5: op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ break; case OP32_CONDINV1: if(X_RD(insn) == 1) { op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ } break; case OP32_CONDINV2: if(X_RS1(insn) == 1) { op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ } break; case OP32_CONDINV3: if(X_RS1(insn) != 0) { op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ } break; @@ -456,7 +456,7 @@ static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le case OP33_INV15: case OP33_INV16: op->type = R_ANAL_OP_TYPE_ILL; - sz = 0; /* make r_core_anal_bb stop */ + sz = 0; /* make rz_core_anal_bb stop */ break; } } @@ -464,7 +464,7 @@ static int sparc_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int le return sz; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { /* As far as I can see, sparc v9 register and instruction set don't depened on bits of the running application. But: They depend on the bits of the consuming application, @@ -598,14 +598,14 @@ static bool set_reg_profile(RAnal *anal) { "fpu qf60 .128 544 0\n" /* df60 df62 */ "gpr fsr .64 560 0\n"; /* note that we've left out the filler */ - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; /* :D */ } -RAnalPlugin r_anal_plugin_sparc_gnu = { +RzAnalPlugin rz_anal_plugin_sparc_gnu = { .name = "sparc.gnu", .desc = "SPARC analysis plugin", .license = "LGPL3", @@ -617,9 +617,9 @@ RAnalPlugin r_anal_plugin_sparc_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_sparc_gnu, + .data = &rz_anal_plugin_sparc_gnu, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_sysz.c b/librz/anal/p/anal_sysz.c similarity index 75% rename from libr/anal/p/anal_sysz.c rename to librz/anal/p/anal_sysz.c index 07f0ea048c..92462bc9e7 100644 --- a/libr/anal/p/anal_sysz.c +++ b/librz/anal/p/anal_sysz.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2014-2019 - pancake */ +/* rizin - LGPL - Copyright 2014-2019 - pancake */ -#include -#include +#include +#include #include #include // instruction set: http://www.tachyonsoft.com/inst390m.htm @@ -10,47 +10,47 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->sysz.operands[n] static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_sysz *x = &insn->detail->sysz; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_sysz_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case SYSZ_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case SYSZ_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case SYSZ_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != SYSZ_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64)op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", (st64)op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]}"); + rz_strbuf_append (buf, "]}"); } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { csh handle; cs_insn *insn; int mode = CS_MODE_BIG_ENDIAN; @@ -141,7 +141,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC r15\n" "=LR r14\n" @@ -177,10 +177,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" ; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { switch (q) { case R_ANAL_ARCHINFO_ALIGN: return 2; @@ -192,7 +192,7 @@ static int archinfo(RAnal *anal, int q) { return 2; } -RAnalPlugin r_anal_plugin_sysz = { +RzAnalPlugin rz_anal_plugin_sysz = { .name = "sysz", .desc = "Capstone SystemZ microanalysis", .esil = false, @@ -205,9 +205,9 @@ RAnalPlugin r_anal_plugin_sysz = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_sysz, + .data = &rz_anal_plugin_sysz, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_tms320.c b/librz/anal/p/anal_tms320.c similarity index 72% rename from libr/anal/p/anal_tms320.c rename to librz/anal/p/anal_tms320.c index bc09c92a75..8ebac8e0a3 100644 --- a/libr/anal/p/anal_tms320.c +++ b/librz/anal/p/anal_tms320.c @@ -6,28 +6,28 @@ * Distributed under LGPL */ -#include +#include #include "anal_tms320c64x.c" #include "../../asm/arch/tms320/tms320_dasm.h" static tms320_dasm_t engine = { 0 }; -typedef int (* TMS_ANAL_OP_FN)(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len); +typedef int (* TMS_ANAL_OP_FN)(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len); -int tms320_c54x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len); -int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len); -int tms320_c55x_plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len); +int tms320_c54x_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len); +int tms320_c55x_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len); +int tms320_c55x_plus_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len); static bool match(const char * str, const char * token) { return !strncasecmp(str, token, strlen(token)); } -int tms320_c54x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { +int tms320_c54x_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { // TODO: add the implementation return 0; } -int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { +int tms320_c55x_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { const char * str = engine.syntax; op->delay = 0; @@ -80,21 +80,21 @@ int tms320_c55x_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) return op->size; } -int tms320_op(RAnal * anal, RAnalOp * op, ut64 addr, const ut8 * buf, int len, RAnalOpMask mask) { +int tms320_op(RzAnal * anal, RzAnalOp * op, ut64 addr, const ut8 * buf, int len, RzAnalOpMask mask) { TMS_ANAL_OP_FN aop = tms320_c55x_op; - if (anal->cpu && r_str_casecmp(anal->cpu, "c64x") == 0) { + if (anal->cpu && rz_str_casecmp(anal->cpu, "c64x") == 0) { #ifdef CAPSTONE_TMS320C64X_H return tms320c64x_analop (anal, op, addr, buf, len, mask); #else return -1; #endif } - if (anal->cpu && r_str_casecmp(anal->cpu, "c54x") == 0) { + if (anal->cpu && rz_str_casecmp(anal->cpu, "c54x") == 0) { aop = tms320_c54x_op; - } else if (anal->cpu && r_str_casecmp(anal->cpu, "c55x") == 0) { + } else if (anal->cpu && rz_str_casecmp(anal->cpu, "c55x") == 0) { aop = tms320_c55x_op; - } else if (anal->cpu && r_str_casecmp(anal->cpu, "c55x+") == 0) { + } else if (anal->cpu && rz_str_casecmp(anal->cpu, "c55x+") == 0) { aop = tms320_c55x_plus_op; } return aop (anal, op, addr, buf, len); @@ -108,7 +108,7 @@ static int tms320_fini(void * unused) { return tms320_dasm_fini (&engine); } -RAnalPlugin r_anal_plugin_tms320 = { +RzAnalPlugin rz_anal_plugin_tms320 = { .name = "tms320", .arch = "tms320", .bits = 32, @@ -120,9 +120,9 @@ RAnalPlugin r_anal_plugin_tms320 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_tms320, + .data = &rz_anal_plugin_tms320, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_tms320_c55x_plus.c b/librz/anal/p/anal_tms320_c55x_plus.c similarity index 92% rename from libr/anal/p/anal_tms320_c55x_plus.c rename to librz/anal/p/anal_tms320_c55x_plus.c index 391f6793b8..9204dfc6af 100644 --- a/libr/anal/p/anal_tms320_c55x_plus.c +++ b/librz/anal/p/anal_tms320_c55x_plus.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2014 - montekki */ #include -#include -#include -#include -#include +#include +#include +#include +#include ut32 get_ins_len(ut8 opcode); -int tms320_c55x_plus_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) { +int tms320_c55x_plus_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len) { ut16 *ins = (ut16*)buf; ut32 ins_len; diff --git a/libr/anal/p/anal_tms320c64x.c b/librz/anal/p/anal_tms320c64x.c similarity index 79% rename from libr/anal/p/anal_tms320c64x.c rename to librz/anal/p/anal_tms320c64x.c index dd3aa5e029..65f2939e95 100644 --- a/libr/anal/p/anal_tms320c64x.c +++ b/librz/anal/p/anal_tms320c64x.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017 - pancake */ +/* rizin - LGPL - Copyright 2017 - pancake */ -#include -#include +#include +#include #include #ifdef CAPSTONE_TMS320C64X_H @@ -24,42 +24,42 @@ static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_tms320c64x *x = &insn->detail->tms320c64x; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_tms320c64x_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case TMS320C64X_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case TMS320C64X_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case TMS320C64X_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != SPARC_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]}"); + rz_strbuf_append (buf, "]}"); } -static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int tms320c64x_analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static csh handle = 0; static int omode; cs_insn *insn; @@ -184,11 +184,11 @@ static int tms320c64x_analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, i /* -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 4; // :D } -RAnalPlugin r_anal_plugin_tms320c64x = { +RzAnalPlugin rz_anal_plugin_tms320c64x = { .name = "tms320c64x", .desc = "Capstone TMS320C64X analysis", .license = "BSD", @@ -199,7 +199,7 @@ RAnalPlugin r_anal_plugin_tms320c64x = { }; #else -RAnalPlugin r_anal_plugin_tms320c64x = { +RzAnalPlugin rz_anal_plugin_tms320c64x = { .name = "tms320c64x", .desc = "Capstone TMS320C64X analysis (unsupported)", .license = "BSD", @@ -209,9 +209,9 @@ RAnalPlugin r_anal_plugin_tms320c64x = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_tms320c64x, + .data = &rz_anal_plugin_tms320c64x, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_tricore.c b/librz/anal/p/anal_tricore.c similarity index 85% rename from libr/anal/p/anal_tricore.c rename to librz/anal/p/anal_tricore.c index 30ac06c78f..181e848a82 100644 --- a/libr/anal/p/anal_tricore.c +++ b/librz/anal/p/anal_tricore.c @@ -1,11 +1,11 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include //#include "../../asm/arch/tricore/gnu/tricore-opc.c" -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP a10\n" @@ -67,10 +67,10 @@ static bool set_reg_profile(RAnal *anal) { "gpr BIV .32 152 0\n" "gpr BTV .32 156 0\n" "gpr pc .32 160 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_tricore = { +RzAnalPlugin rz_anal_plugin_tricore = { .name = "tricore", .desc = "TRICORE analysis plugin", .license = "LGPL3", @@ -80,9 +80,9 @@ RAnalPlugin r_anal_plugin_tricore = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_tricore, + .data = &rz_anal_plugin_tricore, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_v810.c b/librz/anal/p/anal_v810.c similarity index 68% rename from libr/anal/p/anal_v810.c rename to librz/anal/p/anal_v810.c index b2fb12b092..31db81cb3a 100644 --- a/libr/anal/p/anal_v810.c +++ b/librz/anal/p/anal_v810.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2015 - danielps */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include @@ -16,37 +16,37 @@ enum { V810_FLAG_Z = 8, }; -static void update_flags(RAnalOp *op, int flags) { +static void update_flags(RzAnalOp *op, int flags) { if (flags & V810_FLAG_CY) { - r_strbuf_append (&op->esil, ",31,$c,cy,:="); + rz_strbuf_append (&op->esil, ",31,$c,cy,:="); } if (flags & V810_FLAG_OV) { - r_strbuf_append (&op->esil, ",31,$o,ov,:="); + rz_strbuf_append (&op->esil, ",31,$o,ov,:="); } if (flags & V810_FLAG_S) { - r_strbuf_append (&op->esil, ",31,$s,s,:="); + rz_strbuf_append (&op->esil, ",31,$s,s,:="); } if (flags & V810_FLAG_Z) { - r_strbuf_append (&op->esil, ",$z,z,:="); + rz_strbuf_append (&op->esil, ",$z,z,:="); } } -static void clear_flags(RAnalOp *op, int flags) { +static void clear_flags(RzAnalOp *op, int flags) { if (flags & V810_FLAG_CY) { - r_strbuf_append (&op->esil, ",0,cy,:="); + rz_strbuf_append (&op->esil, ",0,cy,:="); } if (flags & V810_FLAG_OV) { - r_strbuf_append (&op->esil, ",0,ov,:="); + rz_strbuf_append (&op->esil, ",0,ov,:="); } if (flags & V810_FLAG_S) { - r_strbuf_append (&op->esil, ",0,s,:="); + rz_strbuf_append (&op->esil, ",0,s,:="); } if (flags & V810_FLAG_Z) { - r_strbuf_append (&op->esil, ",0,z,:="); + rz_strbuf_append (&op->esil, ",0,z,:="); } } -static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int v810_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int ret; ut8 opcode, reg1, reg2, imm5, cond; ut16 word1, word2 = 0; @@ -60,10 +60,10 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, return ret; } - word1 = r_read_ble16 (buf, anal->big_endian); + word1 = rz_read_ble16 (buf, anal->big_endian); if (ret == 4) { - word2 = r_read_ble16 (buf+2, anal->big_endian); + word2 = rz_read_ble16 (buf+2, anal->big_endian); } op->addr = addr; @@ -76,22 +76,22 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, switch (opcode) { case V810_MOV: op->type = R_ANAL_OP_TYPE_MOV; - r_strbuf_appendf (&op->esil, "r%u,r%u,=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,=", REG1(word1), REG2(word1)); break; case V810_MOV_IMM5: op->type = R_ANAL_OP_TYPE_MOV; - r_strbuf_appendf (&op->esil, "%d,r%u,=", + rz_strbuf_appendf (&op->esil, "%d,r%u,=", (st8)SEXT5(IMM5(word1)), REG2(word1)); break; case V810_MOVHI: op->type = R_ANAL_OP_TYPE_MOV; - r_strbuf_appendf (&op->esil, "16,%hu,<<,r%u,+,r%u,=", + rz_strbuf_appendf (&op->esil, "16,%hu,<<,r%u,+,r%u,=", word2, REG1(word1), REG2(word1)); break; case V810_MOVEA: op->type = R_ANAL_OP_TYPE_MOV; - r_strbuf_appendf (&op->esil, "%hd,r%u,+,r%u,=", + rz_strbuf_appendf (&op->esil, "%hd,r%u,+,r%u,=", word2, REG1(word1), REG2(word1)); break; case V810_LDSR: @@ -102,7 +102,7 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, break; case V810_NOT: op->type = R_ANAL_OP_TYPE_NOT; - r_strbuf_appendf (&op->esil, "r%u,0xffffffff,^,r%u,=", + rz_strbuf_appendf (&op->esil, "r%u,0xffffffff,^,r%u,=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); @@ -110,7 +110,7 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, case V810_DIV: case V810_DIVU: op->type = R_ANAL_OP_TYPE_DIV; - r_strbuf_appendf (&op->esil, "r%u,r%u,/=,r%u,r%u,%,r30,=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,/=,r%u,r%u,%,r30,=", REG1(word1), REG2(word1), REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_OV | V810_FLAG_S | V810_FLAG_Z); @@ -121,19 +121,19 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, } else { op->type = R_ANAL_OP_TYPE_UJMP; } - r_strbuf_appendf (&op->esil, "r%u,pc,=", + rz_strbuf_appendf (&op->esil, "r%u,pc,=", REG1(word1)); break; case V810_OR: op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_appendf (&op->esil, "r%u,r%u,|=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,|=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_ORI: op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_appendf (&op->esil, "%hu,r%u,|,r%u,=", + rz_strbuf_appendf (&op->esil, "%hu,r%u,|,r%u,=", word2, REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); @@ -141,85 +141,85 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, case V810_MUL: case V810_MULU: op->type = R_ANAL_OP_TYPE_MUL; - r_strbuf_appendf (&op->esil, "r%u,r%u,*=,32,r%u,r%u,*,>>,r30,=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,*=,32,r%u,r%u,*,>>,r30,=", REG1(word1), REG2(word1), REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_OV | V810_FLAG_S | V810_FLAG_Z); break; case V810_XOR: op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_appendf (&op->esil, "r%u,r%u,^=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,^=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_XORI: op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_appendf (&op->esil, "%hu,r%u,^,r%u,=", + rz_strbuf_appendf (&op->esil, "%hu,r%u,^,r%u,=", word2, REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_AND: op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_appendf (&op->esil, "r%u,r%u,&=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,&=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_ANDI: op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_appendf (&op->esil, "%hu,r%u,&,r%u,=", + rz_strbuf_appendf (&op->esil, "%hu,r%u,&,r%u,=", word2, REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_Z); clear_flags (op, V810_FLAG_OV | V810_FLAG_S); break; case V810_CMP: op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_appendf (&op->esil, "r%u,r%u,==", + rz_strbuf_appendf (&op->esil, "r%u,r%u,==", REG1(word1), REG2(word1)); update_flags (op, -1); break; case V810_CMP_IMM5: op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_appendf (&op->esil, "%d,r%u,==", + rz_strbuf_appendf (&op->esil, "%d,r%u,==", (st8)SEXT5(IMM5(word1)), REG2(word1)); update_flags (op, -1); break; case V810_SUB: op->type = R_ANAL_OP_TYPE_SUB; - r_strbuf_appendf (&op->esil, "r%u,r%u,-=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,-=", REG1(word1), REG2(word1)); update_flags (op, -1); break; case V810_ADD: op->type = R_ANAL_OP_TYPE_ADD; - r_strbuf_appendf (&op->esil, "r%u,r%u,+=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,+=", REG1(word1), REG2(word1)); update_flags (op, -1); break; case V810_ADDI: op->type = R_ANAL_OP_TYPE_ADD; - r_strbuf_appendf (&op->esil, "%hd,r%u,+,r%u,=", + rz_strbuf_appendf (&op->esil, "%hd,r%u,+,r%u,=", word2, REG1(word1), REG2(word1)); update_flags (op, -1); break; case V810_ADD_IMM5: op->type = R_ANAL_OP_TYPE_ADD; - r_strbuf_appendf (&op->esil, "%d,r%u,+=", + rz_strbuf_appendf (&op->esil, "%d,r%u,+=", (st8)SEXT5(IMM5(word1)), REG2(word1)); update_flags(op, -1); break; case V810_SHR: op->type = R_ANAL_OP_TYPE_SHR; - r_strbuf_appendf (&op->esil, "r%u,r%u,>>=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,>>=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_SHR_IMM5: op->type = R_ANAL_OP_TYPE_SHR; - r_strbuf_appendf (&op->esil, "%u,r%u,>>=", + rz_strbuf_appendf (&op->esil, "%u,r%u,>>=", (ut8)IMM5(word1), REG2(word1)); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); @@ -228,7 +228,7 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->type = R_ANAL_OP_TYPE_SAR; reg1 = REG1(word1); reg2 = REG2(word1); - r_strbuf_appendf (&op->esil, "31,r%u,>>,?{,r%u,32,-,r%u,1,<<,--,<<,}{,0,},r%u,r%u,>>,|,r%u,=", + rz_strbuf_appendf (&op->esil, "31,r%u,>>,?{,r%u,32,-,r%u,1,<<,--,<<,}{,0,},r%u,r%u,>>,|,r%u,=", reg2, reg1, reg1, reg1, reg2, reg2); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); @@ -237,56 +237,56 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->type = R_ANAL_OP_TYPE_SAR; imm5 = IMM5(word1); reg2 = REG2(word1); - r_strbuf_appendf (&op->esil, "31,r%u,>>,?{,%u,32,-,%u,1,<<,--,<<,}{,0,},%u,r%u,>>,|,r%u,=", + rz_strbuf_appendf (&op->esil, "31,r%u,>>,?{,%u,32,-,%u,1,<<,--,<<,}{,0,},%u,r%u,>>,|,r%u,=", reg2, (ut8)imm5, (ut8)imm5, (ut8)imm5, reg2, reg2); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_SHL: op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_appendf (&op->esil, "r%u,r%u,<<=", + rz_strbuf_appendf (&op->esil, "r%u,r%u,<<=", REG1(word1), REG2(word1)); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_SHL_IMM5: op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_appendf (&op->esil, "%u,r%u,<<=", + rz_strbuf_appendf (&op->esil, "%u,r%u,<<=", (ut8)IMM5(word1), REG2(word1)); update_flags (op, V810_FLAG_CY | V810_FLAG_S | V810_FLAG_Z); clear_flags (op, V810_FLAG_OV); break; case V810_LDB: op->type = R_ANAL_OP_TYPE_LOAD; - r_strbuf_appendf (&op->esil, "r%u,%hd,+,[1],r%u,=", + rz_strbuf_appendf (&op->esil, "r%u,%hd,+,[1],r%u,=", REG1(word1), word2, REG2(word1)); - r_strbuf_appendf (&op->esil, ",DUP,0x80,&,?{,0xffffff00,|,}"); + rz_strbuf_appendf (&op->esil, ",DUP,0x80,&,?{,0xffffff00,|,}"); break; case V810_LDH: op->type = R_ANAL_OP_TYPE_LOAD; - r_strbuf_appendf (&op->esil, "r%u,%hd,+,0xfffffffe,&,[2],r%u,=", + rz_strbuf_appendf (&op->esil, "r%u,%hd,+,0xfffffffe,&,[2],r%u,=", REG1(word1), word2, REG2(word1)); - r_strbuf_appendf (&op->esil, ",DUP,0x8000,&,?{,0xffffff00,|,}"); + rz_strbuf_appendf (&op->esil, ",DUP,0x8000,&,?{,0xffffff00,|,}"); break; case V810_LDW: op->type = R_ANAL_OP_TYPE_LOAD; - r_strbuf_appendf (&op->esil, "r%u,%hd,+,0xfffffffc,&,[4],r%u,=", + rz_strbuf_appendf (&op->esil, "r%u,%hd,+,0xfffffffc,&,[4],r%u,=", REG1(word1), word2, REG2(word1)); - r_strbuf_appendf (&op->esil, ",DUP,0x80000000,&,?{,0xffffff00,|,}"); + rz_strbuf_appendf (&op->esil, ",DUP,0x80000000,&,?{,0xffffff00,|,}"); break; case V810_STB: op->type = R_ANAL_OP_TYPE_STORE; - r_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,=[1]", + rz_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,=[1]", REG2(word1), REG1(word1), word2); break; case V810_STH: op->type = R_ANAL_OP_TYPE_STORE; - r_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,0xfffffffe,&,=[2]", + rz_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,0xfffffffe,&,=[2]", REG2(word1), REG1(word1), word2); break; case V810_STW: op->type = R_ANAL_OP_TYPE_STORE; - r_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,=[4]", + rz_strbuf_appendf (&op->esil, "r%u,r%u,%hd,+,=[4]", REG2(word1), REG1(word1), word2); break; case V810_INB: @@ -299,11 +299,11 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, break; case V810_TRAP: op->type = R_ANAL_OP_TYPE_TRAP; - r_strbuf_appendf (&op->esil, "%u,TRAP", IMM5(word1)); + rz_strbuf_appendf (&op->esil, "%u,TRAP", IMM5(word1)); break; case V810_RETI: op->type = R_ANAL_OP_TYPE_RET; - //r_strbuf_appendf (&op->esil, "np,?{,fepc,fepsw,}{,eipc,eipsw,},psw,=,pc,="); + //rz_strbuf_appendf (&op->esil, "np,?{,fepc,fepsw,}{,eipc,eipsw,},psw,=,pc,="); break; case V810_JAL: case V810_JR: @@ -313,12 +313,12 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, if (opcode == V810_JAL) { op->type = R_ANAL_OP_TYPE_CALL; - r_strbuf_appendf (&op->esil, "$$,4,+,r31,=,", jumpdisp); + rz_strbuf_appendf (&op->esil, "$$,4,+,r31,=,", jumpdisp); } else { op->type = R_ANAL_OP_TYPE_JMP; } - r_strbuf_appendf (&op->esil, "$$,%d,+,pc,=", jumpdisp); + rz_strbuf_appendf (&op->esil, "$$,%d,+,pc,=", jumpdisp); break; case V810_BCOND: cond = COND(word1); @@ -334,59 +334,59 @@ static int v810_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, switch (cond) { case V810_COND_V: - r_strbuf_appendf (&op->esil, "ov"); + rz_strbuf_appendf (&op->esil, "ov"); break; case V810_COND_L: - r_strbuf_appendf (&op->esil, "cy"); + rz_strbuf_appendf (&op->esil, "cy"); break; case V810_COND_E: - r_strbuf_appendf (&op->esil, "z"); + rz_strbuf_appendf (&op->esil, "z"); break; case V810_COND_NH: - r_strbuf_appendf (&op->esil, "cy,z,|"); + rz_strbuf_appendf (&op->esil, "cy,z,|"); break; case V810_COND_N: - r_strbuf_appendf (&op->esil, "s"); + rz_strbuf_appendf (&op->esil, "s"); break; case V810_COND_NONE: - r_strbuf_appendf (&op->esil, "1"); + rz_strbuf_appendf (&op->esil, "1"); break; case V810_COND_LT: - r_strbuf_appendf (&op->esil, "s,ov,^"); + rz_strbuf_appendf (&op->esil, "s,ov,^"); break; case V810_COND_LE: - r_strbuf_appendf (&op->esil, "s,ov,^,z,|"); + rz_strbuf_appendf (&op->esil, "s,ov,^,z,|"); break; case V810_COND_NV: - r_strbuf_appendf (&op->esil, "ov,!"); + rz_strbuf_appendf (&op->esil, "ov,!"); break; case V810_COND_NL: - r_strbuf_appendf (&op->esil, "cy,!"); + rz_strbuf_appendf (&op->esil, "cy,!"); break; case V810_COND_NE: - r_strbuf_appendf (&op->esil, "z,!"); + rz_strbuf_appendf (&op->esil, "z,!"); break; case V810_COND_H: - r_strbuf_appendf (&op->esil, "cy,z,|,!"); + rz_strbuf_appendf (&op->esil, "cy,z,|,!"); break; case V810_COND_P: - r_strbuf_appendf (&op->esil, "s,!"); + rz_strbuf_appendf (&op->esil, "s,!"); break; case V810_COND_GE: - r_strbuf_appendf (&op->esil, "s,ov,^,!"); + rz_strbuf_appendf (&op->esil, "s,ov,^,!"); break; case V810_COND_GT: - r_strbuf_appendf (&op->esil, "s,ov,^,z,|,!"); + rz_strbuf_appendf (&op->esil, "s,ov,^,z,|,!"); break; } - r_strbuf_appendf (&op->esil, ",?{,$$,%d,+,pc,=,}", jumpdisp); + rz_strbuf_appendf (&op->esil, ",?{,$$,%d,+,pc,=,}", jumpdisp); break; } return ret; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP r3\n" @@ -439,10 +439,10 @@ static bool set_reg_profile(RAnal *anal) { "flg s .1 132.30 0\n" "flg z .1 132.31 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -RAnalPlugin r_anal_plugin_v810 = { +RzAnalPlugin rz_anal_plugin_v810 = { .name = "v810", .desc = "V810 code analysis plugin", .license = "LGPL3", @@ -454,9 +454,9 @@ RAnalPlugin r_anal_plugin_v810 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_v810, + .data = &rz_anal_plugin_v810, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_v850.c b/librz/anal/p/anal_v850.c similarity index 73% rename from libr/anal/p/anal_v850.c rename to librz/anal/p/anal_v850.c index 087afde850..12157b0b8e 100644 --- a/libr/anal/p/anal_v850.c +++ b/librz/anal/p/anal_v850.c @@ -2,12 +2,12 @@ 2014 - Fedor Sakharov */ #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include @@ -134,37 +134,37 @@ static const char* V850_REG_NAMES[] = { "lp", }; -static void update_flags(RAnalOp *op, int flags) { +static void update_flags(RzAnalOp *op, int flags) { if (flags & V850_FLAG_CY) { - r_strbuf_append (&op->esil, "31,$c,cy,:="); + rz_strbuf_append (&op->esil, "31,$c,cy,:="); } if (flags & V850_FLAG_OV) { - r_strbuf_append (&op->esil, ",31,$o,ov,:="); + rz_strbuf_append (&op->esil, ",31,$o,ov,:="); } if (flags & V850_FLAG_S) { - r_strbuf_append (&op->esil, ",31,$s,s,:="); + rz_strbuf_append (&op->esil, ",31,$s,s,:="); } if (flags & V850_FLAG_Z) { - r_strbuf_append (&op->esil, ",$z,z,:="); + rz_strbuf_append (&op->esil, ",$z,z,:="); } } -static void clear_flags(RAnalOp *op, int flags) { +static void clear_flags(RzAnalOp *op, int flags) { if (flags & V850_FLAG_CY) { - r_strbuf_append (&op->esil, ",0,cy,="); + rz_strbuf_append (&op->esil, ",0,cy,="); } if (flags & V850_FLAG_OV) { - r_strbuf_append (&op->esil, ",0,ov,="); + rz_strbuf_append (&op->esil, ",0,ov,="); } if (flags & V850_FLAG_S) { - r_strbuf_append (&op->esil, ",0,s,="); + rz_strbuf_append (&op->esil, ",0,s,="); } if (flags & V850_FLAG_Z) { - r_strbuf_append (&op->esil, ",0,z,="); + rz_strbuf_append (&op->esil, ",0,z,="); } } -static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int v850_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { int ret = 0; ut8 opcode = 0; const char *reg1 = NULL; @@ -185,9 +185,9 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->addr = addr; - word1 = r_read_le16 (buf); + word1 = rz_read_le16 (buf); if (ret == 4) { - word2 = r_read_le16 (buf + 2); + word2 = rz_read_le16 (buf + 2); } opcode = get_opcode (word1); @@ -197,15 +197,15 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, // 2 formats op->type = R_ANAL_OP_TYPE_MOV; if (opcode != V850_MOV_IMM5) { // Format I - r_strbuf_appendf (&op->esil, "%s,%s,=", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,=", F1_RN1(word1), F1_RN2(word1)); } else { // Format II - r_strbuf_appendf (&op->esil, "%"PFMT64d",%s,=", (st64)(F2_IMM(word1)), F2_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%"PFMT64d",%s,=", (st64)(F2_IMM(word1)), F2_RN2(word1)); } break; case V850_MOVEA: op->type = R_ANAL_OP_TYPE_MOV; // FIXME: to decide about reading 16/32 bit and use only macros to access - r_strbuf_appendf (&op->esil, "%s,0xffff,&,%u,+,%s,=", F6_RN1(word1), word2, F6_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,0xffff,&,%u,+,%s,=", F6_RN1(word1), word2, F6_RN2(word1)); break; case V850_SLDB: case V850_SLDH: @@ -229,13 +229,13 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, break; case V850_NOT: op->type = R_ANAL_OP_TYPE_NOT; - r_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,=",F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,0xffffffff,^,%s,=",F1_RN1(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_DIVH: op->type = R_ANAL_OP_TYPE_DIV; - r_strbuf_appendf (&op->esil, "%s,%s,0xffff,&,/,%s,=", + rz_strbuf_appendf (&op->esil, "%s,%s,0xffff,&,/,%s,=", F1_RN1(word1), F1_RN2(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_OV | V850_FLAG_S | V850_FLAG_Z); break; @@ -247,31 +247,31 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, } op->jump = word1; // UT64_MAX; // this is n RJMP instruction .. F1_RN1 (word1); op->fail = addr + 2; - r_strbuf_appendf (&op->esil, "%s,pc,=", F1_RN1(word1)); + rz_strbuf_appendf (&op->esil, "%s,pc,=", F1_RN1(word1)); break; case V850_JARL2: // TODO: fix displacement reading op->type = R_ANAL_OP_TYPE_JMP; op->jump = addr + F5_DISP(((ut32)word2 << 16) | word1); op->fail = addr + 4; - r_strbuf_appendf (&op->esil, "pc,%s,=,pc,%hu,+=", F5_RN2(word1), F5_DISP(((ut32)word2 << 16) | word1)); + rz_strbuf_appendf (&op->esil, "pc,%s,=,pc,%hu,+=", F5_RN2(word1), F5_DISP(((ut32)word2 << 16) | word1)); break; #if 0 // WTF - same opcode as JARL? case V850_JR: jumpdisp = DISP26(word1, word2); op->type = R_ANAL_OP_TYPE_JMP; - r_strbuf_appendf (&op->esil, "$$,%d,+,pc,=", jumpdisp); + rz_strbuf_appendf (&op->esil, "$$,%d,+,pc,=", jumpdisp); break; #endif case V850_OR: op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_appendf (&op->esil, "%s,%s,|=", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,|=", F1_RN1(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_ORI: op->type = R_ANAL_OP_TYPE_OR; - r_strbuf_appendf (&op->esil, "%hu,%s,|,%s,=", + rz_strbuf_appendf (&op->esil, "%hu,%s,|,%s,=", word2, F6_RN1(word1), F6_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); @@ -282,57 +282,57 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, break; case V850_XOR: op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_appendf (&op->esil, "%s,%s,^=", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,^=", F1_RN1(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_XORI: op->type = R_ANAL_OP_TYPE_XOR; - r_strbuf_appendf (&op->esil, "%hu,%s,^,%s,=", word2, F6_RN1(word1), F6_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%hu,%s,^,%s,=", word2, F6_RN1(word1), F6_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_AND: op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_appendf (&op->esil, "%s,%s,&=", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,&=", F1_RN1(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_ANDI: op->type = R_ANAL_OP_TYPE_AND; - r_strbuf_appendf (&op->esil, "%hu,%s,&,%s,=", word2, F6_RN1(word1), F6_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%hu,%s,&,%s,=", word2, F6_RN1(word1), F6_RN2(word1)); update_flags (op, V850_FLAG_Z); clear_flags (op, V850_FLAG_OV | V850_FLAG_S); break; case V850_CMP: op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_appendf (&op->esil, "%s,%s,==", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,==", F1_RN1(word1), F1_RN2(word1)); update_flags (op, -1); break; case V850_CMP_IMM5: op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_appendf (&op->esil, "%d,%s,==", (st8)SEXT5(F2_IMM(word1)), F2_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%d,%s,==", (st8)SEXT5(F2_IMM(word1)), F2_RN2(word1)); update_flags (op, -1); break; case V850_TST: op->type = R_ANAL_OP_TYPE_CMP; - r_strbuf_appendf (&op->esil, "%s,%s,&", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,&", F1_RN1(word1), F1_RN2(word1)); update_flags (op, V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_SUB: op->type = R_ANAL_OP_TYPE_SUB; - r_strbuf_appendf (&op->esil, "%s,%s,-=", F1_RN1(word1), F1_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,-=", F1_RN1(word1), F1_RN2(word1)); update_flags (op, -1); break; case V850_SUBR: op->type = R_ANAL_OP_TYPE_SUB; - r_strbuf_appendf (&op->esil, "%s,%s,-,%s=", F1_RN2 (word1), F1_RN1 (word1), F1_RN2 (word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,-,%s=", F1_RN2 (word1), F1_RN1 (word1), F1_RN2 (word1)); update_flags (op, -1); break; case V850_ADD: op->type = R_ANAL_OP_TYPE_ADD; - r_strbuf_appendf (&op->esil, "%s,%s,+=", F1_RN1 (word1), F1_RN2 (word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,+=", F1_RN1 (word1), F1_RN2 (word1)); update_flags (op, -1); break; case V850_ADD_IMM5: @@ -342,7 +342,7 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->stackptr = F2_IMM (word1); op->val = op->stackptr; } - r_strbuf_appendf (&op->esil, "%d,%s,+=", (st8)SEXT5(F2_IMM (word1)), F2_RN2 (word1)); + rz_strbuf_appendf (&op->esil, "%d,%s,+=", (st8)SEXT5(F2_IMM (word1)), F2_RN2 (word1)); update_flags (op, -1); break; case V850_ADDI: @@ -352,12 +352,12 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->stackptr = (st64) word2; op->val = op->stackptr; } - r_strbuf_appendf (&op->esil, "%d,%s,+,%s,=", (st32) word2, F6_RN1 (word1), F6_RN2 (word1)); + rz_strbuf_appendf (&op->esil, "%d,%s,+,%s,=", (st32) word2, F6_RN1 (word1), F6_RN2 (word1)); update_flags (op, -1); break; case V850_SHR_IMM5: op->type = R_ANAL_OP_TYPE_SHR; - r_strbuf_appendf (&op->esil, "%u,%s,>>=", (ut8)F2_IMM (word1), F2_RN2 (word1)); + rz_strbuf_appendf (&op->esil, "%u,%s,>>=", (ut8)F2_IMM (word1), F2_RN2 (word1)); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; @@ -365,13 +365,13 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->type = R_ANAL_OP_TYPE_SAR; ut16 imm5 = F2_IMM(word1); reg2 = F2_RN2(word1); - r_strbuf_appendf (&op->esil, "31,%s,>>,?{,%u,32,-,%u,1,<<,--,<<,}{,0,},%u,%s,>>,|,%s,=", reg2, (ut8)imm5, (ut8)imm5, (ut8)imm5, reg2, reg2); + rz_strbuf_appendf (&op->esil, "31,%s,>>,?{,%u,32,-,%u,1,<<,--,<<,}{,0,},%u,%s,>>,|,%s,=", reg2, (ut8)imm5, (ut8)imm5, (ut8)imm5, reg2, reg2); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_SHL_IMM5: op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_appendf (&op->esil, "%u,%s,<<=", (ut8)F2_IMM(word1), F2_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%u,%s,<<=", (ut8)F2_IMM(word1), F2_RN2(word1)); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; @@ -391,52 +391,52 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->type = R_ANAL_OP_TYPE_CJMP; switch (F3_COND(word1)) { case V850_COND_V: - r_strbuf_appendf (&op->esil, "ov"); + rz_strbuf_appendf (&op->esil, "ov"); break; case V850_COND_CL: - r_strbuf_appendf (&op->esil, "cy"); + rz_strbuf_appendf (&op->esil, "cy"); break; case V850_COND_ZE: - r_strbuf_appendf (&op->esil, "z"); + rz_strbuf_appendf (&op->esil, "z"); break; case V850_COND_NH: - r_strbuf_appendf (&op->esil, "cy,z,|"); + rz_strbuf_appendf (&op->esil, "cy,z,|"); break; case V850_COND_N: - r_strbuf_appendf (&op->esil, "s"); + rz_strbuf_appendf (&op->esil, "s"); break; case V850_COND_AL: // Always - r_strbuf_appendf (&op->esil, "1"); + rz_strbuf_appendf (&op->esil, "1"); break; case V850_COND_LT: - r_strbuf_appendf (&op->esil, "s,ov,^"); + rz_strbuf_appendf (&op->esil, "s,ov,^"); break; case V850_COND_LE: - r_strbuf_appendf (&op->esil, "s,ov,^,z,|"); + rz_strbuf_appendf (&op->esil, "s,ov,^,z,|"); break; case V850_COND_NV: - r_strbuf_appendf (&op->esil, "ov,!"); + rz_strbuf_appendf (&op->esil, "ov,!"); break; case V850_COND_NL: - r_strbuf_appendf (&op->esil, "cy,!"); + rz_strbuf_appendf (&op->esil, "cy,!"); break; case V850_COND_NE: - r_strbuf_appendf (&op->esil, "z,!"); + rz_strbuf_appendf (&op->esil, "z,!"); break; case V850_COND_H: - r_strbuf_appendf (&op->esil, "cy,z,|,!"); + rz_strbuf_appendf (&op->esil, "cy,z,|,!"); break; case V850_COND_P: - r_strbuf_appendf (&op->esil, "s,!"); + rz_strbuf_appendf (&op->esil, "s,!"); break; case V850_COND_GE: - r_strbuf_appendf (&op->esil, "s,ov,^,!"); + rz_strbuf_appendf (&op->esil, "s,ov,^,!"); break; case V850_COND_GT: - r_strbuf_appendf (&op->esil, "s,ov,^,z,|,!"); + rz_strbuf_appendf (&op->esil, "s,ov,^,z,|,!"); break; } - r_strbuf_appendf (&op->esil, ",?{,$$,%d,+,pc,=,}", destaddrs); + rz_strbuf_appendf (&op->esil, ",?{,$$,%d,+,pc,=,}", destaddrs); break; case V850_BIT_MANIP: { @@ -444,12 +444,12 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, switch (bitop) { case V850_BIT_CLR1: bitmask = (1 << F8_BIT(word1)); - r_strbuf_appendf (&op->esil, "%hu,%s,+,[1],%u,&,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1)); + rz_strbuf_appendf (&op->esil, "%hu,%s,+,[1],%u,&,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1)); // TODO: Read the value of the memory byte and set zero flag accordingly! break; case V850_BIT_NOT1: bitmask = (1 << F8_BIT(word1)); - r_strbuf_appendf (&op->esil, "%hu,%s,+,[1],%u,^,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1)); + rz_strbuf_appendf (&op->esil, "%hu,%s,+,[1],%u,^,%hu,%s,+,=[1]", word2, F8_RN1(word1), bitmask, word2, F8_RN1(word1)); // TODO: Read the value of the memory byte and set zero flag accordingly! break; } @@ -459,13 +459,13 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, switch (get_subopcode(word1 | (ut32)word2 << 16)) { case V850_EXT_SHL: op->type = R_ANAL_OP_TYPE_SHL; - r_strbuf_appendf (&op->esil, "%s,%s,<<=", F9_RN1(word1), F9_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,<<=", F9_RN1(word1), F9_RN2(word1)); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; case V850_EXT_SHR: op->type = R_ANAL_OP_TYPE_SHR; - r_strbuf_appendf (&op->esil, "%s,%s,>>=", F9_RN1(word1), F9_RN2(word1)); + rz_strbuf_appendf (&op->esil, "%s,%s,>>=", F9_RN1(word1), F9_RN2(word1)); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; @@ -473,7 +473,7 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, op->type = R_ANAL_OP_TYPE_SAR; reg1 = F9_RN1(word1); reg2 = F9_RN2(word1); - r_strbuf_appendf (&op->esil, "31,%s,>>,?{,%s,32,-,%s,1,<<,--,<<,}{,0,},%s,%s,>>,|,%s,=", reg2, reg1, reg1, reg1, reg2, reg2); + rz_strbuf_appendf (&op->esil, "31,%s,>>,?{,%s,32,-,%s,1,<<,--,<<,}{,0,},%s,%s,>>,|,%s,=", reg2, reg1, reg1, reg1, reg2, reg2); update_flags (op, V850_FLAG_CY | V850_FLAG_S | V850_FLAG_Z); clear_flags (op, V850_FLAG_OV); break; @@ -484,7 +484,7 @@ static int v850_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, return ret; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p = "=PC pc\n" "=SP r3\n" @@ -540,7 +540,7 @@ static char *get_reg_profile(RAnal *anal) { return strdup (p); } -RAnalPlugin r_anal_plugin_v850 = { +RzAnalPlugin rz_anal_plugin_v850 = { .name = "v850", .desc = "V850 code analysis plugin", .license = "LGPL3", @@ -552,9 +552,9 @@ RAnalPlugin r_anal_plugin_v850 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_v850, + .data = &rz_anal_plugin_v850, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_vax.c b/librz/anal/p/anal_vax.c similarity index 84% rename from libr/anal/p/anal_vax.c rename to librz/anal/p/anal_vax.c index adda377029..1aa974e78a 100644 --- a/libr/anal/p/anal_vax.c +++ b/librz/anal/p/anal_vax.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2015 - pancake */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include // XXX: this is just a PoC // XXX: do not hardcode size/type here, use proper decoding table // http://hotkosc.ru:8080/method-vax.doc -static int vax_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int vax_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { op->size = 1; if (len < 1) { return -1; @@ -79,7 +79,7 @@ static int vax_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, return op->size; } -RAnalPlugin r_anal_plugin_vax = { +RzAnalPlugin rz_anal_plugin_vax = { .name = "vax", .desc = "VAX code analysis plugin", .license = "LGPL3", @@ -96,9 +96,9 @@ RAnalPlugin r_anal_plugin_vax = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_vax, + .data = &rz_anal_plugin_vax, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_wasm.c b/librz/anal/p/anal_wasm.c similarity index 79% rename from libr/anal/p/anal_wasm.c rename to librz/anal/p/anal_wasm.c index 4e7ede23d9..e935ca17c4 100644 --- a/libr/anal/p/anal_wasm.c +++ b/librz/anal/p/anal_wasm.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2017-2020 - xvilka, deroad */ +/* rizin - LGPL - Copyright 2017-2020 - xvilka, deroad */ #include -#include -#include -#include -#include +#include +#include +#include +#include #undef R_IPI #define R_IPI static #define WASM_NO_ASM // to get rid of a warning @@ -17,26 +17,26 @@ static ut64 scope_hint = UT64_MAX; static ut64 addr_old = UT64_MAX; // finds the address of the call function (essentially where to jump to). -static ut64 get_cf_offset(RAnal *anal, const ut8 *data, int len) { +static ut64 get_cf_offset(RzAnal *anal, const ut8 *data, int len) { ut32 fcn_id; if (!read_u32_leb128 (&data[1], &data[len - 1], &fcn_id)) { return UT64_MAX; } - r_cons_push (); + rz_cons_push (); // 0xfff.. are bad addresses for wasm // cgvwzq: 0xfff... can be external imported JS funcs char *s = anal->coreb.cmdstrf (anal->coreb.core, "is~FUNC[2:%u]", fcn_id); - r_cons_pop (); + rz_cons_pop (); if (s) { - ut64 n = r_num_get (NULL, s); + ut64 n = rz_num_get (NULL, s); free (s); return n; } return UT64_MAX; } -static bool advance_till_scope_end(RAnal* anal, RAnalOp *op, ut64 address, ut32 expected_type, ut32 depth, bool use_else) { +static bool advance_till_scope_end(RzAnal* anal, RzAnalOp *op, ut64 address, ut32 expected_type, ut32 depth, bool use_else) { ut8 buffer[16]; ut8 *ptr = buffer; ut8 *end = ptr + sizeof (buffer); @@ -72,9 +72,9 @@ static bool advance_till_scope_end(RAnal* anal, RAnalOp *op, ut64 address, ut32 } // analyzes the wasm opcode. -static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int wasm_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { WasmOp wop = {{0}}; - RAnalHint *hint = NULL; + RzAnalHint *hint = NULL; int ret = wasm_dis (&wop, data, len); op->size = ret; op->addr = addr; @@ -108,25 +108,25 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len /* Calls here are using index instead of address */ case WASM_OP_LOOP: op->type = R_ANAL_OP_TYPE_NOP; - if (!(hint = r_anal_hint_get (anal, addr))) { + if (!(hint = rz_anal_hint_get (anal, addr))) { scope_hint--; - r_anal_hint_set_opcode (anal, scope_hint, "loop"); - r_anal_hint_set_jump (anal, scope_hint, addr); + rz_anal_hint_set_opcode (anal, scope_hint, "loop"); + rz_anal_hint_set_jump (anal, scope_hint, addr); } break; case WASM_OP_BLOCK: op->type = R_ANAL_OP_TYPE_NOP; - if (!(hint = r_anal_hint_get (anal, addr))) { + if (!(hint = rz_anal_hint_get (anal, addr))) { scope_hint--; - r_anal_hint_set_opcode (anal, scope_hint, "block"); - r_anal_hint_set_jump (anal, scope_hint, addr); + rz_anal_hint_set_opcode (anal, scope_hint, "block"); + rz_anal_hint_set_jump (anal, scope_hint, addr); } break; case WASM_OP_IF: - if (!(hint = r_anal_hint_get (anal, addr))) { + if (!(hint = rz_anal_hint_get (anal, addr))) { scope_hint--; - r_anal_hint_set_opcode (anal, scope_hint, "if"); - r_anal_hint_set_jump (anal, scope_hint, addr); + rz_anal_hint_set_opcode (anal, scope_hint, "if"); + rz_anal_hint_set_jump (anal, scope_hint, addr); if (advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_CJMP, 0, true)) { op->fail = addr + op->size; } @@ -138,7 +138,7 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len break; case WASM_OP_ELSE: // get if and set hint. - if (!(hint = r_anal_hint_get (anal, addr))) { + if (!(hint = rz_anal_hint_get (anal, addr))) { advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_JMP, 0, true); } else { op->type = R_ANAL_OP_TYPE_JMP; @@ -147,82 +147,82 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len break; case WASM_OP_BR: { - RAnalHint *hint2 = NULL; + RzAnalHint *hint2 = NULL; ut32 val; read_u32_leb128 (data + 1, data + len, &val); - if ((hint2 = r_anal_hint_get (anal, addr)) && hint2->jump != UT64_MAX) { + if ((hint2 = rz_anal_hint_get (anal, addr)) && hint2->jump != UT64_MAX) { op->type = R_ANAL_OP_TYPE_JMP; op->jump = hint2->jump; - } else if ((hint = r_anal_hint_get (anal, scope_hint))) { + } else if ((hint = rz_anal_hint_get (anal, scope_hint))) { if (hint->opcode && !strncmp ("loop", hint->opcode, 4)) { op->type = R_ANAL_OP_TYPE_JMP; op->jump = hint->jump; - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } else { if (advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_JMP, val, false)) { - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } } } else { if (advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_JMP, val, false)) { eprintf ("[wasm] cannot find jump type for br (using block type)\n"); - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } else { eprintf ("[wasm] cannot find jump for br\n"); } } - r_anal_hint_free (hint2); + rz_anal_hint_free (hint2); } break; case WASM_OP_BRIF: { - RAnalHint *hint2 = NULL; + RzAnalHint *hint2 = NULL; ut32 val; read_u32_leb128 (data + 1, data + len, &val); - if ((hint2 = r_anal_hint_get (anal, addr)) && hint2->jump != UT64_MAX) { + if ((hint2 = rz_anal_hint_get (anal, addr)) && hint2->jump != UT64_MAX) { op->type = R_ANAL_OP_TYPE_CJMP; op->jump = hint2->jump; op->fail = addr + op->size; - } else if ((hint = r_anal_hint_get (anal, scope_hint))) { + } else if ((hint = rz_anal_hint_get (anal, scope_hint))) { if (hint->opcode && !strncmp ("loop", hint->opcode, 4)) { op->fail = addr + op->size; op->jump = hint->jump; - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } else { if (advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_CJMP, val, false)) { op->fail = addr + op->size; - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } } } else { if (advance_till_scope_end (anal, op, addr + op->size, R_ANAL_OP_TYPE_CJMP, val, false)) { eprintf ("[wasm] cannot find jump type for br_if (using block type)\n"); op->fail = addr + op->size; - r_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, addr, op->jump); } else { eprintf ("[wasm] cannot find jump for br_if\n"); } } - r_anal_hint_free (hint2); + rz_anal_hint_free (hint2); } break; case WASM_OP_END: { op->type = R_ANAL_OP_TYPE_NOP; if (scope_hint < UT64_MAX) { - hint = r_anal_hint_get (anal, scope_hint); + hint = rz_anal_hint_get (anal, scope_hint); if (hint && !strncmp ("loop", hint->opcode, 4)) { - r_anal_hint_set_jump (anal, addr, op->jump); - r_anal_hint_set_jump (anal, op->jump, addr); + rz_anal_hint_set_jump (anal, addr, op->jump); + rz_anal_hint_set_jump (anal, op->jump, addr); } else if (hint && !strncmp ("block", hint->opcode, 5)) { // if/else/block - r_anal_hint_set_jump (anal, hint->jump, addr); - r_anal_hint_set_jump (anal, addr, UT64_MAX); + rz_anal_hint_set_jump (anal, hint->jump, addr); + rz_anal_hint_set_jump (anal, addr, UT64_MAX); } if (hint) { - r_anal_hint_set_opcode (anal, scope_hint, "invalid"); - r_anal_hint_set_jump (anal, scope_hint, UT64_MAX); - r_anal_hint_del (anal, scope_hint, 1); + rz_anal_hint_set_opcode (anal, scope_hint, "invalid"); + rz_anal_hint_set_jump (anal, scope_hint, UT64_MAX); + rz_anal_hint_del (anal, scope_hint, 1); scope_hint++; } else { // all wasm routines ends with an end. @@ -231,7 +231,7 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len scope_hint = UT64_MAX; } } else { - if (!(hint = r_anal_hint_get (anal, addr))) { + if (!(hint = rz_anal_hint_get (anal, addr))) { // all wasm routines ends with an end. op->eob = true; op->type = R_ANAL_OP_TYPE_RET; @@ -315,7 +315,7 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len op->type = R_ANAL_OP_TYPE_MOV; { ut8 arg = data[1]; - r_strbuf_setf (&op->esil, "4,sp,-=,%d,sp,=[4]", arg); + rz_strbuf_setf (&op->esil, "4,sp,-=,%d,sp,=[4]", arg); } break; case WASM_OP_I64ADD: @@ -332,7 +332,7 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len break; case WASM_OP_NOP: op->type = R_ANAL_OP_TYPE_NOP; - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); break; case WASM_OP_CALL: case WASM_OP_CALLINDIRECT: @@ -342,7 +342,7 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len if (op->jump != UT64_MAX) { op->ptr = op->jump; } - r_strbuf_setf (&op->esil, "4,sp,-=,0x%"PFMT64x",sp,=[4],0x%"PFMT64x",pc,=", op->fail, op->jump); + rz_strbuf_setf (&op->esil, "4,sp,-=,0x%"PFMT64x",sp,=[4],0x%"PFMT64x",pc,=", op->fail, op->jump); break; case WASM_OP_RETURN: // should be ret, but if there the analisys is stopped. @@ -435,15 +435,15 @@ static int wasm_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len anal_end: addr_old = addr; free (wop.txt); - r_anal_hint_free (hint); + rz_anal_hint_free (hint); return op->size; } -static int archinfo(RAnal *a, int q) { +static int archinfo(RzAnal *a, int q) { return 1; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { return strdup ( "=PC pc\n" "=BP bp\n" @@ -454,7 +454,7 @@ static char *get_reg_profile(RAnal *anal) { ); } -RAnalPlugin r_anal_plugin_wasm = { +RzAnalPlugin rz_anal_plugin_wasm = { .name = "wasm", .desc = "WebAssembly analysis plugin", .license = "LGPL3", @@ -467,9 +467,9 @@ RAnalPlugin r_anal_plugin_wasm = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_wasm, + .data = &rz_anal_plugin_wasm, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_ws.c b/librz/anal/p/anal_ws.c similarity index 80% rename from libr/anal/p/anal_ws.c rename to librz/anal/p/anal_ws.c index fadf92b0cc..3cac46574b 100644 --- a/libr/anal/p/anal_ws.c +++ b/librz/anal/p/anal_ws.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2014-2018 condret */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define WS_API static #include "../../asm/arch/whitespace/wsdis.c" -static ut64 ws_find_label(int l, const RIOBind *iob) { - RIO *io = iob->io; +static ut64 ws_find_label(int l, const RzIOBind *iob) { + RzIO *io = iob->io; ut64 cur = 0, size = iob->desc_size (io->desc); ut8 buf[128]; - RAsmOp aop; + RzAsmOp aop; iob->read_at (iob->io, cur, buf, 128); while (cur <= size && wsdis (&aop, buf, 128)) { - const char *buf_asm = r_strbuf_get (&aop.buf_asm); // r_asm_op_get_asm (&aop); + const char *buf_asm = rz_strbuf_get (&aop.buf_asm); // rz_asm_op_get_asm (&aop); if (buf_asm && (strlen (buf_asm) > 4) && buf_asm[0] == 'm' && buf_asm[1] == 'a' && l == atoi (buf_asm + 5)) { return cur; } @@ -26,13 +26,13 @@ static ut64 ws_find_label(int l, const RIOBind *iob) { return 0; } -static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int ws_anal(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { op->addr = addr; op->type = R_ANAL_OP_TYPE_UNK; - RAsmOp *aop = R_NEW0 (RAsmOp); + RzAsmOp *aop = R_NEW0 (RzAsmOp); op->size = wsdis (aop, data, len); if (op->size) { - const char *buf_asm = r_strbuf_get (&aop->buf_asm); // r_asm_op_get_asm (aop); + const char *buf_asm = rz_strbuf_get (&aop->buf_asm); // rz_asm_op_get_asm (aop); switch (*buf_asm) { case 'n': op->type = R_ANAL_OP_TYPE_NOP; @@ -91,7 +91,7 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len c[3] = '\0'; c[0] = c[2] = '\''; c[1] = (char) atoi (buf_asm + 5); - r_meta_set_string (anal, R_META_TYPE_COMMENT, addr, c); + rz_meta_set_string (anal, R_META_TYPE_COMMENT, addr, c); } } else { op->type = R_ANAL_OP_TYPE_IO; @@ -119,7 +119,7 @@ static int ws_anal(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len return op->size; } -RAnalPlugin r_anal_plugin_ws = { +RzAnalPlugin rz_anal_plugin_ws = { .name = "ws", .desc = "Space, tab and linefeed analysis plugin", .license = "LGPL3", @@ -129,9 +129,9 @@ RAnalPlugin r_anal_plugin_ws = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_ws, + .data = &rz_anal_plugin_ws, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_x86_cs.c b/librz/anal/p/anal_x86_cs.c similarity index 91% rename from libr/anal/p/anal_x86_cs.c rename to librz/anal/p/anal_x86_cs.c index ddf04d7222..68cc595ad4 100644 --- a/libr/anal/p/anal_x86_cs.c +++ b/librz/anal/p/anal_x86_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ -#include -#include +#include +#include #include #include @@ -26,14 +26,14 @@ call = 4 #define HAVE_CSGRP_PRIVILEGE 0 #endif -#define USE_ITER_API 0 +#define USE_ITERZ_API 0 #if CS_API_MAJOR < 2 #error Old Capstone not supported #endif -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) -#define opexprintf(op, fmt, ...) r_strbuf_setf (&op->opex, fmt, ##__VA_ARGS__) +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define opexprintf(op, fmt, ...) rz_strbuf_setf (&op->opex, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->x86.operands[n] #define INSOPS insn->detail->x86.op_count #define ISIMM(x) insn->detail->x86.operands[x].type == X86_OP_IMM @@ -108,76 +108,76 @@ static void hidden_op(cs_insn *insn, cs_x86 *x, int mode) { static void opex(RStrBuf *buf, cs_insn *insn, int mode) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_x86 *x = &insn->detail->x86; if (x->op_count == 0) { hidden_op (insn, x, mode); } - r_strbuf_appendf (buf, "\"operands\":[", x->op_count); + rz_strbuf_appendf (buf, "\"operands\":[", x->op_count); for (i = 0; i < x->op_count; i++) { cs_x86_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_appendf (buf, "{\"size\":%d", op->size); + rz_strbuf_appendf (buf, "{\"size\":%d", op->size); #if CS_API_MAJOR >= 4 - r_strbuf_appendf (buf, ",\"rw\":%d", op->access); // read , write, read|write + rz_strbuf_appendf (buf, ",\"rw\":%d", op->access); // read , write, read|write #endif switch (op->type) { case X86_OP_REG: - r_strbuf_appendf (buf, ",\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_appendf (buf, ",\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case X86_OP_IMM: - r_strbuf_appendf (buf, ",\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64u, op->imm); + rz_strbuf_appendf (buf, ",\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64u, op->imm); break; case X86_OP_MEM: - r_strbuf_appendf (buf, ",\"type\":\"mem\""); + rz_strbuf_appendf (buf, ",\"type\":\"mem\""); if (op->mem.segment != X86_REG_INVALID) { - r_strbuf_appendf (buf, ",\"segment\":\"%s\"", cs_reg_name (handle, op->mem.segment)); + rz_strbuf_appendf (buf, ",\"segment\":\"%s\"", cs_reg_name (handle, op->mem.segment)); } if (op->mem.base != X86_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } if (op->mem.index != X86_REG_INVALID) { - r_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); + rz_strbuf_appendf (buf, ",\"index\":\"%s\"", cs_reg_name (handle, op->mem.index)); } - r_strbuf_appendf (buf, ",\"scale\":%d", op->mem.scale); - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64u"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"scale\":%d", op->mem.scale); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64u"", op->mem.disp); break; default: - r_strbuf_appendf (buf, ",\"type\":\"invalid\""); + rz_strbuf_appendf (buf, ",\"type\":\"invalid\""); break; } - r_strbuf_appendf (buf, "}"); + rz_strbuf_appendf (buf, "}"); } - r_strbuf_appendf (buf, "]"); + rz_strbuf_appendf (buf, "]"); if (x->rex) { - r_strbuf_append (buf, ",\"rex\":true"); + rz_strbuf_append (buf, ",\"rex\":true"); } if (x->modrm) { - r_strbuf_append (buf, ",\"modrm\":true"); + rz_strbuf_append (buf, ",\"modrm\":true"); } if (x->sib) { - r_strbuf_appendf (buf, ",\"sib\":%d", x->sib); + rz_strbuf_appendf (buf, ",\"sib\":%d", x->sib); } if (x->disp) { - r_strbuf_appendf (buf, ",\"disp\":%d", x->disp); + rz_strbuf_appendf (buf, ",\"disp\":%d", x->disp); } if (x->sib_index) { - r_strbuf_appendf (buf, ",\"sib_index\":\"%s\"", + rz_strbuf_appendf (buf, ",\"sib_index\":\"%s\"", cs_reg_name (handle, x->sib_index)); } if (x->sib_scale) { - r_strbuf_appendf (buf, ",\"sib_scale\":%d", x->sib_scale); + rz_strbuf_appendf (buf, ",\"sib_scale\":%d", x->sib_scale); } if (x->sib_base) { - r_strbuf_appendf (buf, ",\"sib_base\":\"%s\"", + rz_strbuf_appendf (buf, ",\"sib_base\":\"%s\"", cs_reg_name (handle, x->sib_base)); } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } static bool is_xmm_reg(cs_x86_op op) { @@ -372,7 +372,7 @@ static const char *reg32_to_name(ut8 reg) { return reg < R_ARRAY_SIZE (names) ? names[reg] : "unk"; } -static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { +static void anop_esil(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { int rs = a->bits/8; const char *pc = (a->bits==16)?"ip": (a->bits==32)?"eip":"rip"; @@ -658,38 +658,38 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, break; case X86_INS_STOSB: if (a->bits<32) { - r_strbuf_appendf (&op->esil, "al,di,=[1],df,?{,1,di,-=,},df,!,?{,1,di,+=,}"); + rz_strbuf_appendf (&op->esil, "al,di,=[1],df,?{,1,di,-=,},df,!,?{,1,di,+=,}"); } else { - r_strbuf_appendf (&op->esil, "al,edi,=[1],df,?{,1,edi,-=,},df,!,?{,1,edi,+=,}"); + rz_strbuf_appendf (&op->esil, "al,edi,=[1],df,?{,1,edi,-=,},df,!,?{,1,edi,+=,}"); } break; case X86_INS_STOSW: if (a->bits<32) { - r_strbuf_appendf (&op->esil, "ax,di,=[2],df,?{,2,di,-=,},df,!,?{,2,di,+=,}"); + rz_strbuf_appendf (&op->esil, "ax,di,=[2],df,?{,2,di,-=,},df,!,?{,2,di,+=,}"); } else { - r_strbuf_appendf (&op->esil, "ax,edi,=[2],df,?{,2,edi,-=,},df,!,?{,2,edi,+=,}"); + rz_strbuf_appendf (&op->esil, "ax,edi,=[2],df,?{,2,edi,-=,},df,!,?{,2,edi,+=,}"); } break; case X86_INS_STOSD: - r_strbuf_appendf (&op->esil, "eax,edi,=[4],df,?{,4,edi,-=,},df,!,?{,4,edi,+=,}"); + rz_strbuf_appendf (&op->esil, "eax,edi,=[4],df,?{,4,edi,-=,},df,!,?{,4,edi,+=,}"); break; case X86_INS_STOSQ: - r_strbuf_appendf (&op->esil, "rax,rdi,=[8],df,?{,8,edi,-=,},df,!,?{,8,edi,+=,}"); + rz_strbuf_appendf (&op->esil, "rax,rdi,=[8],df,?{,8,edi,-=,},df,!,?{,8,edi,+=,}"); break; case X86_INS_LODSB: - r_strbuf_appendf (&op->esil, "%s,[1],al,=,df,?{,1,%s,-=,},df,!,?{,1,%s,+=,}", si, si, si); + rz_strbuf_appendf (&op->esil, "%s,[1],al,=,df,?{,1,%s,-=,},df,!,?{,1,%s,+=,}", si, si, si); break; case X86_INS_LODSW: - r_strbuf_appendf (&op->esil, "%s,[2],ax,=,df,?{,2,%s,-=,},df,!,?{,2,%s,+=,}", si, si, si); + rz_strbuf_appendf (&op->esil, "%s,[2],ax,=,df,?{,2,%s,-=,},df,!,?{,2,%s,+=,}", si, si, si); break; case X86_INS_LODSD: - r_strbuf_appendf (&op->esil, "esi,[4],eax,=,df,?{,4,esi,-=,},df,!,?{,4,esi,+=,}"); + rz_strbuf_appendf (&op->esil, "esi,[4],eax,=,df,?{,4,esi,-=,},df,!,?{,4,esi,+=,}"); break; case X86_INS_LODSQ: - r_strbuf_appendf (&op->esil, "rsi,[8],rax,=,df,?{,8,rsi,-=,},df,!,?{,8,rsi,+=,}"); + rz_strbuf_appendf (&op->esil, "rsi,[8],rax,=,df,?{,8,rsi,-=,},df,!,?{,8,rsi,+=,}"); break; case X86_INS_PEXTRB: - r_strbuf_appendf (&op->esil, "TODO"); + rz_strbuf_appendf (&op->esil, "TODO"); break; // string mov // PS: MOVSD can correspond to one of the two instruction (yes, intel x86 @@ -716,7 +716,7 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, int width = INSOP(0).size; src = (char *)cs_reg_name(*handle, INSOP(1).mem.base); dst = (char *)cs_reg_name(*handle, INSOP(0).mem.base); - r_strbuf_appendf (&op->esil, + rz_strbuf_appendf (&op->esil, "%s,[%d],%s,=[%d],"\ "df,?{,%d,%s,-=,%d,%s,-=,},"\ "df,!,?{,%d,%s,+=,%d,%s,+=,}", @@ -792,7 +792,7 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 1, 0, NULL, SRC_AR, NULL); // dst is name of register from instruction. dst = getarg (&gop, 0, 0, NULL, DST_AR, NULL); - const char *dst64 = r_reg_32_to_64 (a->reg, dst); + const char *dst64 = rz_reg_32_to_64 (a->reg, dst); if (a->bits == 64 && dst64) { // Here it is still correct, because 'e** = X' // turns into 'r** = X' (first one will keep higher bytes, @@ -1324,8 +1324,8 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, case X86_OP_REG: { src = getarg (&gop, 0, 0, NULL, SRC_AR, NULL); - op->src[0] = r_anal_value_new (); - op->src[0]->reg = r_reg_get (a->reg, src, R_REG_TYPE_GPR); + op->src[0] = rz_anal_value_new (); + op->src[0]->reg = rz_reg_get (a->reg, src, R_REG_TYPE_GPR); //XXX fallthrough } //case X86_OP_FP: @@ -1363,7 +1363,7 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 1, 0, NULL, SRC_AR, NULL); dst = getarg (&gop, 0, 1, "^", DST_AR, &bitsize); dst2 = getarg (&gop, 0, 0, NULL, DST2_AR, NULL); - const char *dst_reg64 = r_reg_32_to_64 (a->reg, dst2); // 64-bit destination if exists + const char *dst_reg64 = rz_reg_32_to_64 (a->reg, dst2); // 64-bit destination if exists if (a->bits == 64 && dst_reg64) { // (64-bit ^ 32-bit) & 0xFFFF FFFF -> 64-bit, it's alright, higher bytes will be eliminated // (consider this is operation with 32-bit regs in 64-bit environment). @@ -1534,7 +1534,7 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 1, 0, NULL, SRC_AR, NULL); dst = getarg (&gop, 0, 1, "&", DST_AR, &bitsize); dst2 = getarg (&gop, 0, 0, NULL, DST2_AR, NULL); - const char *dst_reg64 = r_reg_32_to_64 (a->reg, dst2); // 64-bit destination if exists + const char *dst_reg64 = rz_reg_32_to_64 (a->reg, dst2); // 64-bit destination if exists if (a->bits == 64 && dst_reg64) { // (64-bit & 32-bit) & 0xFFFF FFFF -> 64-bit, it's alright, higher bytes will be eliminated // (consider this is operation with 32-bit regs in 64-bit environment). @@ -1563,13 +1563,13 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, // if (arg0) { int width = INSOP(0).size; - const char *r_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; - const char *r_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; - const char *r_nume = (width==1)?"ax": r_quot; + const char *rz_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; + const char *rz_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; + const char *rz_nume = (width==1)?"ax": rz_quot; esilprintf (op, "%d,%s,~,%d,%s,<<,%s,+,~%%,%d,%s,~,%d,%s,<<,%s,+,~/,%s,=,%s,=", - width*8, arg0, width*8, r_rema, r_nume, width*8, arg0, width*8, r_rema, r_nume, r_quot, r_rema); + width*8, arg0, width*8, rz_rema, rz_nume, width*8, arg0, width*8, rz_rema, rz_nume, rz_quot, rz_rema); } else { /* should never happen */ @@ -1585,13 +1585,13 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, { int width = INSOP(0).size; dst = getarg (&gop, 0, 0, NULL, DST_AR, NULL); - const char *r_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; - const char *r_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; - const char *r_nume = (width==1)?"ax": r_quot; + const char *rz_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; + const char *rz_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; + const char *rz_nume = (width==1)?"ax": rz_quot; // DIV does not change flags and is unsigned esilprintf (op, "%s,%d,%s,<<,%s,+,%%,%s,%d,%s,<<,%s,+,/,%s,=,%s,=", - dst, width*8, r_rema, r_nume, dst, width*8, r_rema, r_nume, r_quot, r_rema); + dst, width*8, rz_rema, rz_nume, dst, width*8, rz_rema, rz_nume, rz_quot, rz_rema); } break; case X86_INS_IMUL: @@ -1609,17 +1609,17 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, esilprintf (op, "%d,%s,~,%d,%s,~,*,DUP,%s,=,%s,-,?{,1,1,}{,0,0,},cf,:=,of,:=", width*8, arg0, width*8, arg1, arg0, arg0); } else { if (arg0) { - const char *r_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; - const char *r_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; - const char *r_nume = (width==1)?"ax": r_quot; + const char *rz_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; + const char *rz_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; + const char *rz_nume = (width==1)?"ax": rz_quot; if ( width == 1 ) { esilprintf(op, "0xffffff00,eflags,&=,%s,%s,%%,eflags,|=,%s,%s,*,%s,=,0xff,eflags,&,%s,=,0xffffff00,eflags,&=,2,eflags,|=", - arg0, r_nume, arg0, r_nume, r_quot, r_rema); + arg0, rz_nume, arg0, rz_nume, rz_quot, rz_rema); } else { // this got a little bit crazy, esilprintf (op, "%d,%d,%s,~,%d,%s,~,*,>>,%s,=,%s,%s,*=,%d,%d,%s,~,>>,%s,-,?{,1,1,}{,0,0,},cf,:=,of,:=", - width*8, width*8, arg0, width*8, r_nume, r_rema, arg0, r_nume, width*8, width*8, r_nume, r_rema); + width*8, width*8, arg0, width*8, rz_nume, rz_rema, arg0, rz_nume, width*8, width*8, rz_nume, rz_rema); } } else { @@ -1634,16 +1634,16 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, src = getarg (&gop, 0, 0, NULL, SRC_AR, NULL); if (src) { int width = INSOP(0).size; - const char *r_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; - const char *r_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; - const char *r_nume = (width==1)?"ax": r_quot; + const char *rz_quot = (width==1)?"al": (width==2)?"ax": (width==4)?"eax":"rax"; + const char *rz_rema = (width==1)?"ah": (width==2)?"dx": (width==4)?"edx":"rdx"; + const char *rz_nume = (width==1)?"ax": rz_quot; if ( width == 1 ) { esilprintf(op, "0xffffff00,eflags,&=,%s,%s,%%,eflags,|=,%s,%s,*,%s,=,0xff,eflags,&,%s,=,0xffffff00,eflags,&=,2,eflags,|=", - src, r_nume, src, r_nume, r_quot, r_rema); + src, rz_nume, src, rz_nume, rz_quot, rz_rema); } else { esilprintf (op, "%d,%s,%s,*,>>,%s,=,%s,%s,*=,%s,?{,1,1,}{,0,0,},cf,:=,of,:=", - width*8, src, r_nume, r_rema, src, r_nume, r_rema); + width*8, src, rz_nume, rz_rema, src, rz_nume, rz_rema); } } else { /* should never happen */ @@ -1848,13 +1848,13 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, switch (insn->id) { case X86_INS_BTS: case X86_INS_BTC: - r_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,%d,%s,/,%s,+,%c=[%d]", + rz_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,%d,%s,/,%s,+,%c=[%d]", width * 8, src, width * 8, src, dst_r, (insn->id == X86_INS_BTS)?'|':'^', width); break; case X86_INS_BTR: dst_w = getarg (&gop, 0, 1, "&", DST_R_AR, NULL); - r_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,-1,^,%d,%s,/,%s,+,&=[%d]", + rz_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,-1,^,%d,%s,/,%s,+,&=[%d]", width * 8, src, width * 8, src, dst_r, width); break; } @@ -1868,11 +1868,11 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, case X86_INS_BTS: case X86_INS_BTC: dst_w = getarg (&gop, 0, 1, (insn->id == X86_INS_BTS)?"|":"^", DST_R_AR, NULL); - r_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,%s", width * 8, src, dst_w); + rz_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,%s", width * 8, src, dst_w); break; case X86_INS_BTR: dst_w = getarg (&gop, 0, 1, "&", DST_R_AR, NULL); - r_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,-1,^,%s", width * 8, src, dst_w); + rz_strbuf_appendf (&op->esil, ",%d,%s,%%,1,<<,-1,^,%s", width * 8, src, dst_w); break; } } @@ -1880,20 +1880,20 @@ static void anop_esil(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, } if (op->prefix & R_ANAL_OP_PREFIX_REP) { - r_strbuf_appendf (&op->esil, ",%s,--=,%s,?{,5,GOTO,}", counter, counter); + rz_strbuf_appendf (&op->esil, ",%s,--=,%s,?{,5,GOTO,}", counter, counter); } } -static RRegItem *cs_reg2reg(RReg *reg, csh *h, int id) { +static RzRegItem *cs_reg2reg(RzReg *reg, csh *h, int id) { if (id == X86_REG_INVALID) { return NULL; } - return r_reg_get (reg, (char *)cs_reg_name (*h, id), -1); + return rz_reg_get (reg, (char *)cs_reg_name (*h, id), -1); } -static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, int mode) { +static void set_access_info(RzReg *reg, RzAnalOp *op, csh *handle, cs_insn *insn, int mode) { int i; - RAnalValue *val; + RzAnalValue *val; int regsz; x86_reg sp; switch (mode) { @@ -1914,17 +1914,17 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, sp = X86_REG_ESP; break; } - RList *ret = r_list_newf ((RListFree)r_anal_value_free); + RzList *ret = rz_list_newf ((RzListFree)rz_anal_value_free); if (!ret) { return; } // PC register - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_REG; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, X86_REG_RIP); - r_list_append (ret, val); + rz_list_append (ret, val); #if CS_API_MAJOR >= 4 // Register access info @@ -1933,20 +1933,20 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, if (cs_regs_access (*handle, insn, regs_read, &read_count, regs_write, &write_count) == 0) { if (read_count > 0) { for (i = 0; i < read_count; i++) { - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_REG; val->access = R_ANAL_ACC_R; val->reg = cs_reg2reg (reg, handle, regs_read[i]); - r_list_append (ret, val); + rz_list_append (ret, val); } } if (write_count > 0) { for (i = 0; i < write_count; i++) { - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_REG; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, regs_write[i]); - r_list_append (ret, val); + rz_list_append (ret, val); } } } @@ -1954,70 +1954,70 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, switch (insn->id) { case X86_INS_PUSH: - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -INSOP(0).size; val->memref = INSOP(0).size; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_PUSHAW: // AX, CX, DX, BX, SP, BP, SI, DI - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -16; val->memref = 16; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_PUSHAL: // EAX, ECX, EDX, EBX, EBP, ESP, EBP, ESI, EDI - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -32; val->memref = 32; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_PUSHF: - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -2; val->memref = 2; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_PUSHFD: - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -4; val->memref = 4; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_PUSHFQ: - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -8; val->memref = 8; - r_list_append (ret, val); + rz_list_append (ret, val); break; case X86_INS_CALL: case X86_INS_LCALL: - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; val->access = R_ANAL_ACC_W; val->reg = cs_reg2reg (reg, handle, sp); val->delta = -regsz; val->memref = regsz; - r_list_append (ret, val); + rz_list_append (ret, val); break; default: break; @@ -2026,7 +2026,7 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, // Memory access info based on operands for (i = 0; i < INSOPS; i++) { if (INSOP (i).type == X86_OP_MEM) { - val = r_anal_value_new (); + val = rz_anal_value_new (); val->type = R_ANAL_VAL_MEM; #if CS_API_MAJOR >= 4 switch (INSOP (i).access) { @@ -2053,7 +2053,7 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, val->seg = cs_reg2reg (reg, handle, INSOP (i).mem.segment); val->reg = cs_reg2reg (reg, handle, INSOP (i).mem.base); val->regdelta = cs_reg2reg (reg, handle, INSOP (i).mem.index); - r_list_append (ret, val); + rz_list_append (ret, val); } } @@ -2061,12 +2061,12 @@ static void set_access_info(RReg *reg, RAnalOp *op, csh *handle, cs_insn *insn, } #define CREATE_SRC_DST(op) \ - (op)->src[0] = r_anal_value_new (); \ - (op)->src[1] = r_anal_value_new (); \ - (op)->src[2] = r_anal_value_new (); \ - (op)->dst = r_anal_value_new (); + (op)->src[0] = rz_anal_value_new (); \ + (op)->src[1] = rz_anal_value_new (); \ + (op)->src[2] = rz_anal_value_new (); \ + (op)->dst = rz_anal_value_new (); -static void set_src_dst(RReg *reg, RAnalValue *val, csh *handle, cs_insn *insn, int x) { +static void set_src_dst(RzReg *reg, RzAnalValue *val, csh *handle, cs_insn *insn, int x) { switch (INSOP (x).type) { case X86_OP_MEM: val->mul = INSOP (x).mem.scale; @@ -2087,7 +2087,7 @@ static void set_src_dst(RReg *reg, RAnalValue *val, csh *handle, cs_insn *insn, } } -static void op_fillval(RAnal *a, RAnalOp *op, csh *handle, cs_insn *insn, int mode) { +static void op_fillval(RzAnal *a, RzAnalOp *op, csh *handle, cs_insn *insn, int mode) { set_access_info (a->reg, op, handle, insn, mode); switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_MOV: @@ -2126,7 +2126,7 @@ static void op_fillval(RAnal *a, RAnalOp *op, csh *handle, cs_insn *insn, int mo } } -static void op0_memimmhandle(RAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { +static void op0_memimmhandle(RzAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { op->ptr = UT64_MAX; switch (INSOP(0).type) { case X86_OP_MEM: @@ -2164,7 +2164,7 @@ static void op0_memimmhandle(RAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { } } -static void op1_memimmhandle(RAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { +static void op1_memimmhandle(RzAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { if (op->refptr < 1 || op->ptr == UT64_MAX) { switch (INSOP(1).type) { case X86_OP_MEM: @@ -2192,7 +2192,7 @@ static void op1_memimmhandle(RAnalOp *op, cs_insn *insn, ut64 addr, int regsz) { } } -static void op_stackidx(RAnalOp *op, cs_insn *insn, bool minus) { +static void op_stackidx(RzAnalOp *op, cs_insn *insn, bool minus) { if (INSOP(0).type == X86_OP_REG && INSOP(1).type == X86_OP_IMM) { if (INSOP(0).reg == X86_REG_RSP || INSOP(0).reg == X86_REG_ESP) { op->stackop = R_ANAL_STACK_INC; @@ -2205,7 +2205,7 @@ static void op_stackidx(RAnalOp *op, cs_insn *insn, bool minus) { } } -static void set_opdir(RAnalOp *op, cs_insn *insn) { +static void set_opdir(RzAnalOp *op, cs_insn *insn) { switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_MOV: switch (INSOP(0).type) { @@ -2235,7 +2235,7 @@ static void set_opdir(RAnalOp *op, cs_insn *insn) { } } -static void anop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { +static void anop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, csh *handle, cs_insn *insn) { struct Getarg gop = { .handle = *handle, .insn = insn, @@ -2582,7 +2582,7 @@ static void anop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, csh op->type = R_ANAL_OP_TYPE_SHR; op->val = INSOP(1).imm; // XXX this should be op->imm - //op->src[0] = r_anal_value_new (); + //op->src[0] = rz_anal_value_new (); //op->src[0]->imm = INSOP(1).imm; break; case X86_INS_CMP: @@ -3161,9 +3161,9 @@ static int cs_len_prefix_opcode(uint8_t *item) { return len; } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static int omode = 0; -#if USE_ITER_API +#if USE_ITERZ_API static #endif cs_insn *insn = NULL; @@ -3189,7 +3189,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn op->cycles = 1; // aprox cs_option (handle, CS_OPT_DETAIL, CS_OPT_ON); // capstone-next -#if USE_ITER_API +#if USE_ITERZ_API { ut64 naddr = addr; size_t size = len; @@ -3209,7 +3209,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn } } else { if (mask & R_ANAL_OP_MASK_DISASM) { - op->mnemonic = r_str_newf ("%s%s%s", + op->mnemonic = rz_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]?" ":"", insn->op_str); @@ -3256,7 +3256,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn op->family = R_ANAL_OP_FAMILY_PRIV; } #endif -#if !USE_ITER_API +#if !USE_ITERZ_API cs_free (insn, n); #endif } @@ -3265,29 +3265,29 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn } #if 0 -static int x86_int_0x80(RAnalEsil *esil, int interrupt) { +static int x86_int_0x80(RzAnalEsil *esil, int interrupt) { int syscall; ut64 eax, ebx, ecx, edx; if (!esil || (interrupt != 0x80)) return false; - r_anal_esil_reg_read (esil, "eax", &eax, NULL); - r_anal_esil_reg_read (esil, "ebx", &ebx, NULL); - r_anal_esil_reg_read (esil, "ecx", &ecx, NULL); - r_anal_esil_reg_read (esil, "edx", &edx, NULL); + rz_anal_esil_reg_read (esil, "eax", &eax, NULL); + rz_anal_esil_reg_read (esil, "ebx", &ebx, NULL); + rz_anal_esil_reg_read (esil, "ecx", &ecx, NULL); + rz_anal_esil_reg_read (esil, "edx", &edx, NULL); syscall = (int) eax; switch (syscall) { case 3: { char *dst = calloc (1, (size_t)edx); (void)read ((ut32)ebx, dst, (size_t)edx); - r_anal_esil_mem_write (esil, ecx, (ut8 *)dst, (int)edx); + rz_anal_esil_mem_write (esil, ecx, (ut8 *)dst, (int)edx); free (dst); return true; } case 4: { char *src = malloc ((size_t)edx); - r_anal_esil_mem_read (esil, ecx, (ut8 *)src, (int)edx); + rz_anal_esil_mem_read (esil, ecx, (ut8 *)src, (int)edx); write ((ut32)ebx, src, (size_t)edx); free (src); return true; @@ -3299,21 +3299,21 @@ static int x86_int_0x80(RAnalEsil *esil, int interrupt) { #endif #if 0 -static int esil_x86_cs_intr(RAnalEsil *esil, int intr) { +static int esil_x86_cs_intr(RzAnalEsil *esil, int intr) { if (!esil) return false; eprintf ("INTERRUPT 0x%02x HAPPENS\n", intr); return true; } #endif -static int esil_x86_cs_init(RAnalEsil *esil) { +static int esil_x86_cs_init(RzAnalEsil *esil) { if (!esil) { return false; } // XXX. this depends on kernel - // r_anal_esil_set_interrupt (esil, 0x80, x86_int_0x80); + // rz_anal_esil_set_interrupt (esil, 0x80, x86_int_0x80); /* disable by default */ -// r_anal_esil_set_interrupt (esil, 0x80, NULL); // this is stupid, don't do this +// rz_anal_esil_set_interrupt (esil, 0x80, NULL); // this is stupid, don't do this return true; } @@ -3331,11 +3331,11 @@ static int fini(void *p) { return true; } -static int esil_x86_cs_fini(RAnalEsil *esil) { +static int esil_x86_cs_fini(RzAnalEsil *esil) { return true; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { const char *p = NULL; switch (anal->bits) { case 16: p = @@ -3460,7 +3460,7 @@ static char *get_reg_profile(RAnal *anal) { break; case 64: { - const char *cc = r_anal_cc_default (anal); + const char *cc = rz_anal_cc_default (anal); const char *args_prof = cc && !strcmp (cc, "ms") ? // Microsoft x64 CC "# RAX return value\n" @@ -3494,7 +3494,7 @@ static char *get_reg_profile(RAnal *anal) { "=A6 r10\n" "=A7 r11\n" "=SN rax\n"; - char *prof = r_str_newf ("%s%s", args_prof, + char *prof = rz_str_newf ("%s%s", args_prof, "gpr rax .64 80 0\n" "gpr eax .32 80 0\n" "gpr ax .16 80 0\n" @@ -3732,7 +3732,7 @@ static char *get_reg_profile(RAnal *anal) { return (p && *p)? strdup (p): NULL; } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { switch (q) { case R_ANAL_ARCHINFO_ALIGN: return 0; @@ -3744,9 +3744,9 @@ static int archinfo(RAnal *anal, int q) { return 0; } -static RList *anal_preludes(RAnal *anal) { -#define KW(d,ds,m,ms) r_list_append (l, r_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) - RList *l = r_list_newf ((RListFree)r_search_keyword_free); +static RzList *anal_preludes(RzAnal *anal) { +#define KW(d,ds,m,ms) rz_list_append (l, rz_search_keyword_new((const ut8*)d,ds,(const ut8*)m, ms, NULL)) + RzList *l = rz_list_newf ((RzListFree)rz_search_keyword_free); switch (anal->bits) { case 32: KW ("\x8b\xff\x55\x8b\xec", 5, NULL, 0); @@ -3760,14 +3760,14 @@ static RList *anal_preludes(RAnal *anal) { KW ("\xf3\x0f\x1e\xfa", 4, NULL, 0); // endbr64 break; default: - r_list_free (l); + rz_list_free (l); l = NULL; break; } return l; } -RAnalPlugin r_anal_plugin_x86_cs = { +RzAnalPlugin rz_anal_plugin_x86_cs = { .name = "x86", .desc = "Capstone X86 analysis", .esil = true, @@ -3786,9 +3786,9 @@ RAnalPlugin r_anal_plugin_x86_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_x86_cs, + .data = &rz_anal_plugin_x86_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_xap.c b/librz/anal/p/anal_xap.c similarity index 92% rename from libr/anal/p/anal_xap.c rename to librz/anal/p/anal_xap.c index 708eb6711f..9b65ac04b9 100644 --- a/libr/anal/p/anal_xap.c +++ b/librz/anal/p/anal_xap.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2008-2016 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../asm/arch/xap/dis.c" static int label_off(struct directive *d) { @@ -37,7 +37,7 @@ static inline ut16 i2ut16(struct instruction *in) { return *((uint16_t*)in); } -static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len, RAnalOpMask mask) { +static int xap_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *bytes, int len, RzAnalOpMask mask) { struct instruction *in = (struct instruction *)bytes; ut16 lol, ins; struct directive d = {{0}}; @@ -60,7 +60,7 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len xap_decode (&s, &d); d.d_operand = get_operand (&s, &d); - memset (op, 0, sizeof (RAnalOp)); + memset (op, 0, sizeof (RzAnalOp)); op->type = R_ANAL_OP_TYPE_UNK; op->size = 2; @@ -209,7 +209,7 @@ static int xap_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *bytes, int len return op->size; } -RAnalPlugin r_anal_plugin_xap = { +RzAnalPlugin rz_anal_plugin_xap = { .name = "xap", .desc = "XAP code analysis plugin", .license = "LGPL3", @@ -219,9 +219,9 @@ RAnalPlugin r_anal_plugin_xap = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_xap, + .data = &rz_anal_plugin_xap, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_xcore_cs.c b/librz/anal/p/anal_xcore_cs.c similarity index 67% rename from libr/anal/p/anal_xcore_cs.c rename to librz/anal/p/anal_xcore_cs.c index b62da816c1..5bc95d6cbe 100644 --- a/libr/anal/p/anal_xcore_cs.c +++ b/librz/anal/p/anal_xcore_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2014-2017 - pancake */ +/* rizin - LGPL - Copyright 2014-2017 - pancake */ -#include -#include +#include +#include #include #include @@ -9,48 +9,48 @@ #error Old Capstone not supported #endif -#define esilprintf(op, fmt, ...) r_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) #define INSOP(n) insn->detail->xcore.operands[n] static void opex(RStrBuf *buf, csh handle, cs_insn *insn) { int i; - r_strbuf_init (buf); - r_strbuf_append (buf, "{"); + rz_strbuf_init (buf); + rz_strbuf_append (buf, "{"); cs_xcore *x = &insn->detail->xcore; - r_strbuf_append (buf, "\"operands\":["); + rz_strbuf_append (buf, "\"operands\":["); for (i = 0; i < x->op_count; i++) { cs_xcore_op *op = &x->operands[i]; if (i > 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - r_strbuf_append (buf, "{"); + rz_strbuf_append (buf, "{"); switch (op->type) { case XCORE_OP_REG: - r_strbuf_append (buf, "\"type\":\"reg\""); - r_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); + rz_strbuf_append (buf, "\"type\":\"reg\""); + rz_strbuf_appendf (buf, ",\"value\":\"%s\"", cs_reg_name (handle, op->reg)); break; case XCORE_OP_IMM: - r_strbuf_append (buf, "\"type\":\"imm\""); - r_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); + rz_strbuf_append (buf, "\"type\":\"imm\""); + rz_strbuf_appendf (buf, ",\"value\":%"PFMT64d, op->imm); break; case XCORE_OP_MEM: - r_strbuf_append (buf, "\"type\":\"mem\""); + rz_strbuf_append (buf, "\"type\":\"mem\""); if (op->mem.base != XCORE_REG_INVALID) { - r_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); + rz_strbuf_appendf (buf, ",\"base\":\"%s\"", cs_reg_name (handle, op->mem.base)); } - r_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); + rz_strbuf_appendf (buf, ",\"disp\":%"PFMT64d"", op->mem.disp); break; default: - r_strbuf_append (buf, "\"type\":\"invalid\""); + rz_strbuf_append (buf, "\"type\":\"invalid\""); break; } - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "}"); } - r_strbuf_append (buf, "]"); - r_strbuf_append (buf, "}"); + rz_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "}"); } -static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) { +static int analop(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *buf, int len, RzAnalOpMask mask) { static csh handle = 0; static int omode = 0; cs_insn *insn; @@ -122,7 +122,7 @@ static int analop(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAn return op->size; } -RAnalPlugin r_anal_plugin_xcore_cs = { +RzAnalPlugin rz_anal_plugin_xcore_cs = { .name = "xcore", .desc = "Capstone XCORE analysis", .license = "BSD", @@ -134,9 +134,9 @@ RAnalPlugin r_anal_plugin_xcore_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_xcore_cs, + .data = &rz_anal_plugin_xcore_cs, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_xtensa.c b/librz/anal/p/anal_xtensa.c similarity index 85% rename from libr/anal/p/anal_xtensa.c rename to librz/anal/p/anal_xtensa.c index 3acb1d45a8..aa96441d17 100644 --- a/libr/anal/p/anal_xtensa.c +++ b/librz/anal/p/anal_xtensa.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2016-2018 - pancake */ +/* rizin - LGPL - Copyright 2016-2018 - pancake */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -57,74 +57,74 @@ static inline ut64 xtensa_imm12s (ut64 addr, const ut8 *buf) { return (addr + 4 + imm12); } -typedef void (*XtensaOpFn) (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf); +typedef void (*XtensaOpFn) (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf); -static void xtensa_null_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_null_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_NULL; } -static void xtensa_unk_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_unk_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_UNK; } -static void xtensa_mov_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_mov_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_MOV; } -static void xtensa_load_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_load_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_LOAD; } -static void xtensa_store_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_store_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_STORE; } -static void xtensa_add_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_add_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_ADD; } -static void xtensa_sub_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_sub_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_SUB; } -static void xtensa_mul_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_mul_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_MUL; } -static void xtensa_div_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_div_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_DIV; } -static void xtensa_mod_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_mod_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_MOD; } -static void xtensa_and_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_and_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_AND; } -static void xtensa_or_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_or_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_OR; } -static void xtensa_xor_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_xor_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_XOR; } -static void xtensa_shl_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_shl_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_SHL; } -static void xtensa_shr_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_shr_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_SHR; } -static void xtensa_l32r_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_l32r_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_LOAD; op->ptr = ((addr + 3) & ~3) + ((buf[2] << 8 | buf[1]) << 2) - 0x40000; } -static void xtensa_snm0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_snm0_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[0] >> 4) & 0xf) { case 0x0: case 0x1: case 0x2: case 0x3: op->type = R_ANAL_OP_TYPE_ILL; @@ -144,7 +144,7 @@ static void xtensa_snm0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_sync_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_sync_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[0] >> 4) & 0xf) { case 0x0: case 0x1: case 0x2: case 0x3: case 0x8: @@ -158,7 +158,7 @@ static void xtensa_sync_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_rfei_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_rfei_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[0] >> 4) & 0xf) { case 0x0: switch (buf[1] & 0xf) { @@ -180,7 +180,7 @@ static void xtensa_rfei_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_st0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_st0_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[1] >> 4) & 0xf) { case 0x0: xtensa_snm0_op (anal, op, addr, buf); @@ -209,7 +209,7 @@ static void xtensa_st0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_st1_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_st1_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[1] >> 4) & 0xf) { case 0x0: case 0x1: case 0x2: case 0x3: case 0x4: @@ -233,7 +233,7 @@ static void xtensa_st1_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_rt0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_rt0_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch (buf[1] & 0xf) { case 0: op->type = R_ANAL_OP_TYPE_NOT; @@ -248,7 +248,7 @@ static void xtensa_rt0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_tlb_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_tlb_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[2] >> 4) & 0xf) { case 0x3: case 0x4: case 0x5: case 0x6: case 0x7: @@ -262,7 +262,7 @@ static void xtensa_tlb_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_accer_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_accer_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[2] >> 4) & 0xf) { case 0x0: case 0x8: @@ -275,7 +275,7 @@ static void xtensa_accer_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf } } -static void xtensa_imp_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_imp_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[1] >> 4) & 0xf) { case 0x0: case 0x1: case 0x2: case 0x3: case 0x8: case 0x9: @@ -351,18 +351,18 @@ static XtensaOpFn xtensa_rst2_fns[] = { xtensa_mod_op }; -static void xtensa_rst0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_rst0_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { xtensa_rst0_fns[(buf[2] >> 4) & 0xf] (anal, op, addr, buf); } -static void xtensa_rst1_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_rst1_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { xtensa_rst1_fns[(buf[2] >> 4) & 0xf] (anal, op, addr, buf); } -static void xtensa_rst2_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_rst2_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { xtensa_rst2_fns[(buf[2] >> 4) & 0xf] (anal, op, addr, buf); } -static void xtensa_lsc4_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_lsc4_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[2] >> 4) & 0xf) { case 0x0: xtensa_load_op (anal, op, addr, buf); @@ -376,7 +376,7 @@ static void xtensa_lsc4_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_lscx_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_lscx_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->family = R_ANAL_OP_FAMILY_FPU; switch ((buf[2] >> 4) & 0xf) { case 0x0: case 0x1: @@ -391,7 +391,7 @@ static void xtensa_lscx_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_fp0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_fp0_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->family = R_ANAL_OP_FAMILY_FPU; switch ((buf[2] >> 4) & 0xf) { case 0x0: case 0x4: @@ -429,7 +429,7 @@ static void xtensa_fp0_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_fp1_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_fp1_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->family = R_ANAL_OP_FAMILY_FPU; switch ((buf[2] >> 4) & 0xf) { case 0x1: case 0x2: case 0x3: @@ -465,7 +465,7 @@ static XtensaOpFn xtensa_qrst_fns[] = { xtensa_unk_op }; -static void xtensa_qrst_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_qrst_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { xtensa_qrst_fns[buf[2] & 0xf] (anal, op, addr, buf); } @@ -488,11 +488,11 @@ static XtensaOpFn xtensa_lsai_fns[] = { xtensa_store_op }; -static void xtensa_lsai_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_lsai_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { xtensa_lsai_fns[(buf[1] >> 4) & 0xf] (anal, op, addr, buf); } -static void xtensa_lsci_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_lsci_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { ut8 r = buf[1] >> 4; op->family = R_ANAL_OP_FAMILY_FPU; if ((r & 3) == 0) { @@ -506,19 +506,19 @@ static void xtensa_lsci_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_calln_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_calln_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_CALL; op->fail = addr + op->size; op->jump = xtensa_offset (addr, buf); } -static void xtensa_b_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_b_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { op->type = R_ANAL_OP_TYPE_CJMP; op->fail = addr + op->size; op->jump = xtensa_imm8s (addr, buf[2]); } -static void xtensa_si_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_si_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { ut8 n = (buf[0] >> 4) & 3; ut8 m = (buf[0] >> 6); switch (n) { @@ -568,7 +568,7 @@ static void xtensa_si_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { } } -static void xtensa_st2n_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_st2n_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { if (buf[0] & 0x80) { op->type = R_ANAL_OP_TYPE_CJMP; op->fail = addr + op->size; @@ -578,7 +578,7 @@ static void xtensa_st2n_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) } } -static void xtensa_st3n_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf) { +static void xtensa_st3n_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf) { switch ((buf[1] >> 4) & 0xf) { case 0x0: op->type = R_ANAL_OP_TYPE_MOV; @@ -641,7 +641,7 @@ static inline void sign_extend2(st32 *value, ut8 bit1, ut8 bit2, ut8 shift) { } static void xtensa_check_stack_op(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { st32 imm; ut32 dst; ut32 src; @@ -665,9 +665,9 @@ static void xtensa_check_stack_op(xtensa_isa isa, xtensa_opcode opcode, xtensa_f static void esil_push_signed_imm(RStrBuf * esil, st32 imm) { if (imm >= 0) { - r_strbuf_appendf (esil, "0x%x" CM, imm); + rz_strbuf_appendf (esil, "0x%x" CM, imm); } else { - r_strbuf_appendf ( + rz_strbuf_appendf ( esil, "0x%x" CM "0x0" CM @@ -683,7 +683,7 @@ static void esil_sign_extend(RStrBuf *esil, ut8 bit) { ut32 bit_mask = 1 << bit; ut32 extend_mask = 0xFFFFFFFF << bit; - r_strbuf_appendf ( + rz_strbuf_appendf ( esil, "DUP" CM "0x%x" CM @@ -700,7 +700,7 @@ static void esil_sign_extend(RStrBuf *esil, ut8 bit) { } static void esil_load_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 offset; ut32 reg_d; ut32 reg_a; @@ -740,7 +740,7 @@ static void esil_load_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format fo break; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0x%x" CM "%s%d" CM @@ -759,7 +759,7 @@ static void esil_load_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format fo esil_sign_extend (&op->esil, sign_extend_bit); } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "=", @@ -770,7 +770,7 @@ static void esil_load_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format fo } static void esil_load_relative(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 offset; st32 dst; @@ -789,7 +789,7 @@ static void esil_load_relative(xtensa_isa isa, xtensa_opcode opcode, xtensa_form offset = - ((offset | 0xFFFF0000) << 2); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0x%x" CM "$$" CM @@ -810,7 +810,7 @@ static void esil_load_relative(xtensa_isa isa, xtensa_opcode opcode, xtensa_form } static void esil_add_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { st32 imm; ut32 dst; ut32 src; @@ -830,9 +830,9 @@ static void esil_add_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for sign_extend (&imm, 7); } - r_strbuf_appendf (&op->esil, "%s%d" CM, xtensa_regfile_shortname (isa, src_rf), src); + rz_strbuf_appendf (&op->esil, "%s%d" CM, xtensa_regfile_shortname (isa, src_rf), src); esil_push_signed_imm (&op->esil, imm); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "+" CM "%s%d" CM @@ -843,7 +843,7 @@ static void esil_add_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for } static void esil_store_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 offset; ut32 reg_d; @@ -879,7 +879,7 @@ static void esil_store_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format f break; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "0x%x" CM @@ -900,7 +900,7 @@ static void esil_store_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format f } static void esil_move_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { st32 imm; ut32 reg; @@ -922,7 +922,7 @@ static void esil_move_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format fo esil_push_signed_imm (&op->esil, imm); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "=", @@ -932,7 +932,7 @@ static void esil_move_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format fo } static void esil_move(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 dst; ut32 src; @@ -942,7 +942,7 @@ static void esil_move(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format xtensa_regfile dst_rf = xtensa_operand_regfile (isa, opcode, 0); xtensa_regfile src_rf = xtensa_operand_regfile (isa, opcode, 1); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "%s%d" CM @@ -955,7 +955,7 @@ static void esil_move(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format } static void esil_move_conditional(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 dst; ut32 src; ut32 cond; @@ -995,7 +995,7 @@ static void esil_move_conditional(xtensa_isa isa, xtensa_opcode opcode, xtensa_f // =, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0" CM "%s%d" CM @@ -1016,7 +1016,7 @@ static void esil_move_conditional(xtensa_isa isa, xtensa_opcode opcode, xtensa_f } static void esil_add_sub(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 dst; ut32 op1; ut32 op2; @@ -1056,7 +1056,7 @@ static void esil_add_sub(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for break; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "%d" CM @@ -1077,7 +1077,7 @@ static void esil_add_sub(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for } static void esil_branch_compare_imm(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 cmp_reg; // Unsigned immediate operands still fit in st32 st32 cmp_imm; @@ -1119,7 +1119,7 @@ static void esil_branch_compare_imm(xtensa_isa isa, xtensa_opcode opcode, // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM, // data reg @@ -1129,19 +1129,19 @@ static void esil_branch_compare_imm(xtensa_isa isa, xtensa_opcode opcode, esil_push_signed_imm (&op->esil, cmp_imm); - r_strbuf_appendf (&op->esil, "%s" CM, compare_op); - r_strbuf_appendf (&op->esil, "?{" CM); + rz_strbuf_appendf (&op->esil, "%s" CM, compare_op); + rz_strbuf_appendf (&op->esil, "?{" CM); // ISA defines branch target as offset + 4, // but at the time of ESIL evaluation // PC will be already incremented by 3 esil_push_signed_imm (&op->esil, branch_imm + 4 - 3); - r_strbuf_appendf (&op->esil, "pc" CM "+=" CM "}"); + rz_strbuf_appendf (&op->esil, "pc" CM "+=" CM "}"); } static void esil_branch_compare(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 op1_reg; ut32 op2_reg; st32 branch_imm; @@ -1185,7 +1185,7 @@ static void esil_branch_compare(xtensa_isa isa, xtensa_opcode opcode, // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "%s%d" CM @@ -1200,11 +1200,11 @@ static void esil_branch_compare(xtensa_isa isa, xtensa_opcode opcode, esil_push_signed_imm (&op->esil, branch_imm); - r_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); + rz_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); } static void esil_branch_compare_single(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 op_reg; st32 branch_imm; @@ -1245,7 +1245,7 @@ static void esil_branch_compare_single(xtensa_isa isa, xtensa_opcode opcode, // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0" CM "%s%d" CM @@ -1258,11 +1258,11 @@ static void esil_branch_compare_single(xtensa_isa isa, xtensa_opcode opcode, esil_push_signed_imm (&op->esil, branch_imm); - r_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); + rz_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); } static void esil_branch_check_mask(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 op1_reg; ut32 op2_reg; st32 branch_imm; @@ -1316,7 +1316,7 @@ static void esil_branch_check_mask(xtensa_isa isa, xtensa_opcode opcode, // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "%s%d" CM @@ -1335,11 +1335,11 @@ static void esil_branch_check_mask(xtensa_isa isa, xtensa_opcode opcode, esil_push_signed_imm (&op->esil, branch_imm); - r_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); + rz_strbuf_append (&op->esil, "pc" CM "+=" CM "}"); } static void esil_bitwise_op(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 dst; ut32 op1; ut32 op2; @@ -1368,7 +1368,7 @@ static void esil_bitwise_op(xtensa_isa isa, xtensa_opcode opcode, xtensa_format break; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "%s%d" CM @@ -1386,7 +1386,7 @@ static void esil_bitwise_op(xtensa_isa isa, xtensa_opcode opcode, xtensa_format } static void esil_branch_check_bit_imm(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 src_reg; ut32 imm_bit; st32 imm_offset; @@ -1420,7 +1420,7 @@ static void esil_branch_check_bit_imm(xtensa_isa isa, xtensa_opcode opcode, xten // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "0x%x" CM @@ -1436,7 +1436,7 @@ static void esil_branch_check_bit_imm(xtensa_isa isa, xtensa_opcode opcode, xten esil_push_signed_imm (&op->esil, imm_offset); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "pc" CM "+=" CM @@ -1445,7 +1445,7 @@ static void esil_branch_check_bit_imm(xtensa_isa isa, xtensa_opcode opcode, xten } static void esil_branch_check_bit(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 src_reg; ut32 bit_reg; st32 imm_offset; @@ -1481,7 +1481,7 @@ static void esil_branch_check_bit(xtensa_isa isa, xtensa_opcode opcode, xtensa_f // +=, // } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "1" CM @@ -1500,7 +1500,7 @@ static void esil_branch_check_bit(xtensa_isa isa, xtensa_opcode opcode, xtensa_f esil_push_signed_imm (&op->esil, imm_offset); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "pc" CM "+=" CM @@ -1509,7 +1509,7 @@ static void esil_branch_check_bit(xtensa_isa isa, xtensa_opcode opcode, xtensa_f } static void esil_abs_neg(xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 src_reg; ut32 dst_reg; @@ -1524,7 +1524,7 @@ static void esil_abs_neg(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for neg = opcode == 95; if (!neg) { - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0" CM "%s%d" CM @@ -1550,7 +1550,7 @@ static void esil_abs_neg(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for src_reg ); } else { - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0" CM "%s%d" CM @@ -1560,7 +1560,7 @@ static void esil_abs_neg(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for ); } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "=" CM, @@ -1570,7 +1570,7 @@ static void esil_abs_neg(xtensa_isa isa, xtensa_opcode opcode, xtensa_format for } static void esil_call(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { bool call = opcode == 76; st32 imm_offset; @@ -1578,7 +1578,7 @@ static void esil_call(xtensa_isa isa, xtensa_opcode opcode, (ut32 *) &imm_offset); if (call) { - r_strbuf_append( + rz_strbuf_append( &op->esil, "pc" CM "a0" CM @@ -1596,18 +1596,18 @@ static void esil_call(xtensa_isa isa, xtensa_opcode opcode, esil_push_signed_imm (&op->esil, imm_offset); - r_strbuf_append (&op->esil, "pc" CM "+="); + rz_strbuf_append (&op->esil, "pc" CM "+="); } static void esil_callx(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { bool callx = opcode == 77; ut32 dst_reg; xtensa_operand_get_field (isa, opcode, 0, format, i, slot_buffer, &dst_reg); xtensa_regfile dst_rf = xtensa_operand_regfile (isa, opcode, 0); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "0" CM "+" CM, xtensa_regfile_shortname (isa, dst_rf), @@ -1615,7 +1615,7 @@ static void esil_callx(xtensa_isa isa, xtensa_opcode opcode, ); if (callx) { - r_strbuf_append ( + rz_strbuf_append ( &op->esil, "pc" CM "a0" CM @@ -1623,17 +1623,17 @@ static void esil_callx(xtensa_isa isa, xtensa_opcode opcode, ); } - r_strbuf_append (&op->esil, "pc" CM "="); + rz_strbuf_append (&op->esil, "pc" CM "="); } static void esil_set_shift_amount(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 src_reg; xtensa_operand_get_field (isa, opcode, 0, format, i, slot_buffer, &src_reg); xtensa_regfile src_rf = xtensa_operand_regfile (isa, opcode, 0); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "%s%d" CM "sar" CM @@ -1644,13 +1644,13 @@ static void esil_set_shift_amount(xtensa_isa isa, xtensa_opcode opcode, } static void esil_set_shift_amount_imm(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 sa_imm; xtensa_operand_get_field (isa, opcode, 0, format, i, slot_buffer, &sa_imm); xtensa_operand_decode (isa, opcode, 0, &sa_imm); - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0x%x" CM "sar" CM @@ -1660,7 +1660,7 @@ static void esil_set_shift_amount_imm(xtensa_isa isa, xtensa_opcode opcode, } static void esil_shift_logic_imm(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 reg_dst; ut32 reg_src; ut32 imm_amount; @@ -1682,7 +1682,7 @@ static void esil_shift_logic_imm(xtensa_isa isa, xtensa_opcode opcode, shift_op = "<<"; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0x%x" CM "%s%d" CM @@ -1699,7 +1699,7 @@ static void esil_shift_logic_imm(xtensa_isa isa, xtensa_opcode opcode, } static void esil_shift_logic_sar(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 reg_dst; ut32 reg_src; @@ -1718,7 +1718,7 @@ static void esil_shift_logic_sar(xtensa_isa isa, xtensa_opcode opcode, shift_op = "<<"; } - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "sar" CM "%s%d" CM @@ -1734,7 +1734,7 @@ static void esil_shift_logic_sar(xtensa_isa isa, xtensa_opcode opcode, } static void esil_extract_unsigned(xtensa_isa isa, xtensa_opcode opcode, - xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + xtensa_format format, size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { ut32 reg_dst; ut32 reg_src; ut32 imm_shift; @@ -1750,7 +1750,7 @@ static void esil_extract_unsigned(xtensa_isa isa, xtensa_opcode opcode, ut32 and_mask = (1 << (imm_mask + 1)) - 1; - r_strbuf_appendf ( + rz_strbuf_appendf ( &op->esil, "0x%x" CM "%s%d" CM @@ -1769,7 +1769,7 @@ static void esil_extract_unsigned(xtensa_isa isa, xtensa_opcode opcode, } static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format format, - size_t i, xtensa_insnbuf slot_buffer, RAnalOp *op) { + size_t i, xtensa_insnbuf slot_buffer, RzAnalOp *op) { switch (opcode) { case 26: /* add.n */ case 41: /* add */ @@ -1791,7 +1791,7 @@ static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format for break; case 0: /* excw */ case 34: /* nop.n */ - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); break; // TODO: s32cli (s32c1i) is conditional (CAS) // should it be handled here? @@ -1809,7 +1809,7 @@ static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format for break; case 98: /* ret */ case 35: /* ret.n */ - r_strbuf_setf (&op->esil, "a0,pc,="); + rz_strbuf_setf (&op->esil, "a0,pc,="); break; case 82: /* l16ui */ case 83: /* l16si */ @@ -1873,7 +1873,7 @@ static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format for esil_extract_unsigned (isa, opcode, format, i, slot_buffer, op); break; case 79: /* ill */ - r_strbuf_setf (&op->esil, ""); + rz_strbuf_setf (&op->esil, ""); break; // TODO: windowed calls? case 7: /* call4 */ @@ -1914,7 +1914,7 @@ static void analop_esil (xtensa_isa isa, xtensa_opcode opcode, xtensa_format for } } -static int xtensa_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf_original, int len_original, RAnalOpMask mask) { +static int xtensa_op (RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *buf_original, int len_original, RzAnalOpMask mask) { if (!op) { return 1; } @@ -1978,7 +1978,7 @@ static int xtensa_op (RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf_origin return op->size; } -static char *get_reg_profile(RAnal *anal) { +static char *get_reg_profile(RzAnal *anal) { return strdup ( // Assuming call0 ABI "# a0 return address\n" @@ -2020,7 +2020,7 @@ static char *get_reg_profile(RAnal *anal) { ); } -RAnalPlugin r_anal_plugin_xtensa = { +RzAnalPlugin rz_anal_plugin_xtensa = { .name = "xtensa", .desc = "Xtensa disassembler", .license = "LGPL3", @@ -2032,9 +2032,9 @@ RAnalPlugin r_anal_plugin_xtensa = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_xtensa, + .data = &rz_anal_plugin_xtensa, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/anal_z80.c b/librz/anal/p/anal_z80.c similarity index 94% rename from libr/anal/p/anal_z80.c rename to librz/anal/p/anal_z80.c index 77300908e8..1958577a38 100644 --- a/libr/anal/p/anal_z80.c +++ b/librz/anal/p/anal_z80.c @@ -2,10 +2,10 @@ 2013 - condret */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../../asm/arch/z80/z80_tab.h" static void z80_op_size(const ut8 *data, int len, int *size, int *size_prefix) { @@ -55,7 +55,7 @@ static void z80_op_size(const ut8 *data, int len, int *size, int *size_prefix) { } } -static int z80_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) { +static int z80_anal_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask) { int ilen = 0; z80_op_size (data, len, &ilen, &op->nopcode); @@ -368,7 +368,7 @@ static int z80_anal_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int return ilen; } -static bool set_reg_profile(RAnal *anal) { +static bool set_reg_profile(RzAnal *anal) { const char *p = "=PC mpc\n" "=SP sp\n" @@ -407,14 +407,14 @@ static bool set_reg_profile(RAnal *anal) { "gpr mbcram .16 16 0\n" "gpr ime .1 18 0\n"; - return r_reg_set_profile_string (anal->reg, p); + return rz_reg_set_profile_string (anal->reg, p); } -static int archinfo(RAnal *anal, int q) { +static int archinfo(RzAnal *anal, int q) { return 1; } -RAnalPlugin r_anal_plugin_z80 = { +RzAnalPlugin rz_anal_plugin_z80 = { .name = "z80", .arch = "z80", .license = "LGPL3", @@ -426,9 +426,9 @@ RAnalPlugin r_anal_plugin_z80 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ANAL, - .data = &r_anal_plugin_z80, + .data = &rz_anal_plugin_z80, .version = R2_VERSION }; #endif diff --git a/libr/anal/p/arc.mk b/librz/anal/p/arc.mk similarity index 100% rename from libr/anal/p/arc.mk rename to librz/anal/p/arc.mk diff --git a/libr/anal/p/arm_cs.mk b/librz/anal/p/arm_cs.mk similarity index 100% rename from libr/anal/p/arm_cs.mk rename to librz/anal/p/arm_cs.mk diff --git a/libr/anal/p/arm_gnu.mk b/librz/anal/p/arm_gnu.mk similarity index 100% rename from libr/anal/p/arm_gnu.mk rename to librz/anal/p/arm_gnu.mk diff --git a/libr/anal/p/avr.mk b/librz/anal/p/avr.mk similarity index 100% rename from libr/anal/p/avr.mk rename to librz/anal/p/avr.mk diff --git a/libr/anal/p/bf.mk b/librz/anal/p/bf.mk similarity index 100% rename from libr/anal/p/bf.mk rename to librz/anal/p/bf.mk diff --git a/libr/anal/p/capstone.mk b/librz/anal/p/capstone.mk similarity index 100% rename from libr/anal/p/capstone.mk rename to librz/anal/p/capstone.mk diff --git a/libr/anal/p/chip8.mk b/librz/anal/p/chip8.mk similarity index 100% rename from libr/anal/p/chip8.mk rename to librz/anal/p/chip8.mk diff --git a/libr/anal/p/cr16.mk b/librz/anal/p/cr16.mk similarity index 100% rename from libr/anal/p/cr16.mk rename to librz/anal/p/cr16.mk diff --git a/libr/anal/p/cris.mk b/librz/anal/p/cris.mk similarity index 100% rename from libr/anal/p/cris.mk rename to librz/anal/p/cris.mk diff --git a/libr/anal/p/dalvik.mk b/librz/anal/p/dalvik.mk similarity index 100% rename from libr/anal/p/dalvik.mk rename to librz/anal/p/dalvik.mk diff --git a/libr/anal/p/ebc.mk b/librz/anal/p/ebc.mk similarity index 100% rename from libr/anal/p/ebc.mk rename to librz/anal/p/ebc.mk diff --git a/libr/anal/p/gb.mk b/librz/anal/p/gb.mk similarity index 100% rename from libr/anal/p/gb.mk rename to librz/anal/p/gb.mk diff --git a/libr/anal/p/h8300.mk b/librz/anal/p/h8300.mk similarity index 100% rename from libr/anal/p/h8300.mk rename to librz/anal/p/h8300.mk diff --git a/libr/anal/p/hexagon.mk b/librz/anal/p/hexagon.mk similarity index 100% rename from libr/anal/p/hexagon.mk rename to librz/anal/p/hexagon.mk diff --git a/libr/anal/p/i4004.mk b/librz/anal/p/i4004.mk similarity index 100% rename from libr/anal/p/i4004.mk rename to librz/anal/p/i4004.mk diff --git a/libr/anal/p/i8080.mk b/librz/anal/p/i8080.mk similarity index 100% rename from libr/anal/p/i8080.mk rename to librz/anal/p/i8080.mk diff --git a/libr/anal/p/java.mk b/librz/anal/p/java.mk similarity index 90% rename from libr/anal/p/java.mk rename to librz/anal/p/java.mk index 23486ff521..ab411f1eb4 100644 --- a/libr/anal/p/java.mk +++ b/librz/anal/p/java.mk @@ -12,5 +12,5 @@ ${TARGET_JAVA}: ${OBJ_JAVA} ${CC} $(call libname,anal_java) ${CFLAGS} \ -o anal_java.${EXT_SO} \ ${OBJ_JAVA} ${SHARED2_JAVA} \ - $(SHLR)/java/libr_java.$(EXT_AR) \ + $(SHLR)/java/librz_java.$(EXT_AR) \ $(SHLR)/sdb/src/libsdb.$(EXT_AR) diff --git a/libr/anal/p/m680x_cs.mk b/librz/anal/p/m680x_cs.mk similarity index 100% rename from libr/anal/p/m680x_cs.mk rename to librz/anal/p/m680x_cs.mk diff --git a/libr/anal/p/m68k_cs.mk b/librz/anal/p/m68k_cs.mk similarity index 100% rename from libr/anal/p/m68k_cs.mk rename to librz/anal/p/m68k_cs.mk diff --git a/libr/anal/p/malbolge.mk b/librz/anal/p/malbolge.mk similarity index 100% rename from libr/anal/p/malbolge.mk rename to librz/anal/p/malbolge.mk diff --git a/libr/anal/p/mcore.mk b/librz/anal/p/mcore.mk similarity index 100% rename from libr/anal/p/mcore.mk rename to librz/anal/p/mcore.mk diff --git a/libr/anal/p/mips_cs.mk b/librz/anal/p/mips_cs.mk similarity index 100% rename from libr/anal/p/mips_cs.mk rename to librz/anal/p/mips_cs.mk diff --git a/libr/anal/p/mips_gnu.mk b/librz/anal/p/mips_gnu.mk similarity index 100% rename from libr/anal/p/mips_gnu.mk rename to librz/anal/p/mips_gnu.mk diff --git a/libr/anal/p/msp430.mk b/librz/anal/p/msp430.mk similarity index 100% rename from libr/anal/p/msp430.mk rename to librz/anal/p/msp430.mk diff --git a/libr/anal/p/nios2.mk b/librz/anal/p/nios2.mk similarity index 100% rename from libr/anal/p/nios2.mk rename to librz/anal/p/nios2.mk diff --git a/libr/anal/p/null.mk b/librz/anal/p/null.mk similarity index 100% rename from libr/anal/p/null.mk rename to librz/anal/p/null.mk diff --git a/libr/anal/p/or1k.mk b/librz/anal/p/or1k.mk similarity index 100% rename from libr/anal/p/or1k.mk rename to librz/anal/p/or1k.mk diff --git a/libr/anal/p/pic.mk b/librz/anal/p/pic.mk similarity index 100% rename from libr/anal/p/pic.mk rename to librz/anal/p/pic.mk diff --git a/libr/anal/p/ppc_cs.mk b/librz/anal/p/ppc_cs.mk similarity index 100% rename from libr/anal/p/ppc_cs.mk rename to librz/anal/p/ppc_cs.mk diff --git a/libr/anal/p/ppc_gnu.mk b/librz/anal/p/ppc_gnu.mk similarity index 100% rename from libr/anal/p/ppc_gnu.mk rename to librz/anal/p/ppc_gnu.mk diff --git a/libr/anal/p/propeller.mk b/librz/anal/p/propeller.mk similarity index 100% rename from libr/anal/p/propeller.mk rename to librz/anal/p/propeller.mk diff --git a/libr/anal/p/pyc.mk b/librz/anal/p/pyc.mk similarity index 98% rename from libr/anal/p/pyc.mk rename to librz/anal/p/pyc.mk index 88a64d35a0..05ee1d982a 100644 --- a/libr/anal/p/pyc.mk +++ b/librz/anal/p/pyc.mk @@ -38,4 +38,4 @@ ALL_TARGETS+=${TARGET_PYC} CFLAGS+=-I$(PYC_ROOT) ${TARGET_PYC}: ${OBJ_PYC} - ${CC} $(call libname,anal_pyc) ${CFLAGS} $(LDFLAGS) -o ${TARGET_PYC} ${OBJ_PYC} -lr_util + ${CC} $(call libname,anal_pyc) ${CFLAGS} $(LDFLAGS) -o ${TARGET_PYC} ${OBJ_PYC} -lrz_util diff --git a/libr/anal/p/riscv.mk b/librz/anal/p/riscv.mk similarity index 100% rename from libr/anal/p/riscv.mk rename to librz/anal/p/riscv.mk diff --git a/libr/anal/p/riscv_cs.mk b/librz/anal/p/riscv_cs.mk similarity index 100% rename from libr/anal/p/riscv_cs.mk rename to librz/anal/p/riscv_cs.mk diff --git a/libr/anal/p/rsp.mk b/librz/anal/p/rsp.mk similarity index 100% rename from libr/anal/p/rsp.mk rename to librz/anal/p/rsp.mk diff --git a/libr/anal/p/sh.mk b/librz/anal/p/sh.mk similarity index 100% rename from libr/anal/p/sh.mk rename to librz/anal/p/sh.mk diff --git a/libr/anal/p/snes.mk b/librz/anal/p/snes.mk similarity index 100% rename from libr/anal/p/snes.mk rename to librz/anal/p/snes.mk diff --git a/libr/anal/p/sparc_cs.mk b/librz/anal/p/sparc_cs.mk similarity index 100% rename from libr/anal/p/sparc_cs.mk rename to librz/anal/p/sparc_cs.mk diff --git a/libr/anal/p/sparc_gnu.mk b/librz/anal/p/sparc_gnu.mk similarity index 100% rename from libr/anal/p/sparc_gnu.mk rename to librz/anal/p/sparc_gnu.mk diff --git a/libr/anal/p/sysz.mk b/librz/anal/p/sysz.mk similarity index 100% rename from libr/anal/p/sysz.mk rename to librz/anal/p/sysz.mk diff --git a/libr/anal/p/tms320.mk b/librz/anal/p/tms320.mk similarity index 100% rename from libr/anal/p/tms320.mk rename to librz/anal/p/tms320.mk diff --git a/libr/anal/p/tms320c64x.mk b/librz/anal/p/tms320c64x.mk similarity index 100% rename from libr/anal/p/tms320c64x.mk rename to librz/anal/p/tms320c64x.mk diff --git a/libr/anal/p/tricore.mk b/librz/anal/p/tricore.mk similarity index 100% rename from libr/anal/p/tricore.mk rename to librz/anal/p/tricore.mk diff --git a/libr/anal/p/v810.mk b/librz/anal/p/v810.mk similarity index 100% rename from libr/anal/p/v810.mk rename to librz/anal/p/v810.mk diff --git a/libr/anal/p/v850.mk b/librz/anal/p/v850.mk similarity index 100% rename from libr/anal/p/v850.mk rename to librz/anal/p/v850.mk diff --git a/libr/anal/p/vax.mk b/librz/anal/p/vax.mk similarity index 100% rename from libr/anal/p/vax.mk rename to librz/anal/p/vax.mk diff --git a/libr/anal/p/wasm.mk b/librz/anal/p/wasm.mk similarity index 100% rename from libr/anal/p/wasm.mk rename to librz/anal/p/wasm.mk diff --git a/libr/anal/p/ws.mk b/librz/anal/p/ws.mk similarity index 100% rename from libr/anal/p/ws.mk rename to librz/anal/p/ws.mk diff --git a/libr/anal/p/x86_cs.mk b/librz/anal/p/x86_cs.mk similarity index 100% rename from libr/anal/p/x86_cs.mk rename to librz/anal/p/x86_cs.mk diff --git a/libr/anal/p/xap.mk b/librz/anal/p/xap.mk similarity index 100% rename from libr/anal/p/xap.mk rename to librz/anal/p/xap.mk diff --git a/libr/anal/p/xcore_cs.mk b/librz/anal/p/xcore_cs.mk similarity index 100% rename from libr/anal/p/xcore_cs.mk rename to librz/anal/p/xcore_cs.mk diff --git a/libr/anal/p/xtensa.mk b/librz/anal/p/xtensa.mk similarity index 100% rename from libr/anal/p/xtensa.mk rename to librz/anal/p/xtensa.mk diff --git a/libr/anal/p/z80.mk b/librz/anal/p/z80.mk similarity index 100% rename from libr/anal/p/z80.mk rename to librz/anal/p/z80.mk diff --git a/libr/anal/pin.c b/librz/anal/pin.c similarity index 73% rename from libr/anal/pin.c rename to librz/anal/pin.c index 95d0fa81ab..bbfdcd87a9 100644 --- a/libr/anal/pin.c +++ b/librz/anal/pin.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2015 - pancake, nibble */ -#include +#include -typedef void (*RAnalEsilPin)(RAnal *a); +typedef void (*RzAnalEsilPin)(RzAnal *a); #if 0 // TODO: those hardcoded functions should go /* default pins from libc */ -static void pin_strlen(RAnal *a) { +static void pin_strlen(RzAnal *a) { // get a0 register // read memory and interpret it as a string // set a0 to the result of strlen; eprintf ("esilpin: strlen\n"); } -static void pin_write(RAnal *a) { +static void pin_write(RzAnal *a) { // get a0 register for fd // get a1 register for data // get a2 register for len @@ -28,32 +28,32 @@ static void pin_write(RAnal *a) { #define DB a->sdb_pins -R_API void r_anal_pin_init(RAnal *a) { +RZ_API void rz_anal_pin_init(RzAnal *a) { sdb_free (DB); DB = sdb_new0(); // sdb_ptr_set (DB, "strlen", pin_strlen, 0); // sdb_ptr_set (DB, "write", pin_write, 0); } -R_API void r_anal_pin_fini(RAnal *a) { +RZ_API void rz_anal_pin_fini(RzAnal *a) { if (sdb_free (DB)) { DB = NULL; } } -R_API void r_anal_pin(RAnal *a, ut64 addr, const char *name) { +RZ_API void rz_anal_pin(RzAnal *a, ut64 addr, const char *name) { char buf[64]; const char *key = sdb_itoa (addr, buf, 16); sdb_set (DB, key, name, 0); } -R_API void r_anal_pin_unset(RAnal *a, ut64 addr) { +RZ_API void rz_anal_pin_unset(RzAnal *a, ut64 addr) { char buf[64]; const char *key = sdb_itoa (addr, buf, 16); sdb_unset (DB, key, 0); } -R_API const char *r_anal_pin_call(RAnal *a, ut64 addr) { +RZ_API const char *rz_anal_pin_call(RzAnal *a, ut64 addr) { char buf[64]; const char *key = sdb_itoa (addr, buf, 16); if (key) { @@ -61,7 +61,7 @@ R_API const char *r_anal_pin_call(RAnal *a, ut64 addr) { #if 0 const char *name; if (name) { - RAnalEsilPin fcnptr = (RAnalEsilPin) + RzAnalEsilPin fcnptr = (RzAnalEsilPin) sdb_ptr_get (DB, name, NULL); if (fcnptr) { fcnptr (a); @@ -74,7 +74,7 @@ R_API const char *r_anal_pin_call(RAnal *a, ut64 addr) { } static bool cb_list(void *user, const char *k, const char *v) { - RAnal *a = (RAnal*)user; + RzAnal *a = (RzAnal*)user; if (*k == '0') { // bind a->cb_printf ("%s = %s\n", k, v); @@ -85,6 +85,6 @@ static bool cb_list(void *user, const char *k, const char *v) { return true; } -R_API void r_anal_pin_list(RAnal *a) { +RZ_API void rz_anal_pin_list(RzAnal *a) { sdb_foreach (DB, cb_list, a); } diff --git a/libr/anal/reflines.c b/librz/anal/reflines.c similarity index 66% rename from libr/anal/reflines.c rename to librz/anal/reflines.c index 3e80d919b7..d0dea1e367 100644 --- a/libr/anal/reflines.c +++ b/librz/anal/reflines.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include -#include -#include +#include +#include +#include #define mid_down_refline(a, r) ((r)->from > (r)->to && (a) < (r)->from && (a) > (r)->to) #define mid_up_refline(a, r) ((r)->from < (r)->to && (a) > (r)->from && (a) < (r)->to) @@ -12,18 +12,18 @@ typedef struct refline_end { int val; bool is_from; - RAnalRefline *r; + RzAnalRefline *r; } ReflineEnd; static int cmp_asc(const struct refline_end *a, const struct refline_end *b) { return (a->val > b->val) - (a->val < b->val); } -static int cmp_by_ref_lvl(const RAnalRefline *a, const RAnalRefline *b) { +static int cmp_by_ref_lvl(const RzAnalRefline *a, const RzAnalRefline *b) { return (a->level < b->level) - (a->level > b->level); } -static ReflineEnd *refline_end_new(ut64 val, bool is_from, RAnalRefline *ref) { +static ReflineEnd *refline_end_new(ut64 val, bool is_from, RzAnalRefline *ref) { ReflineEnd *re = R_NEW0 (struct refline_end); if (!re) { return NULL; @@ -34,9 +34,9 @@ static ReflineEnd *refline_end_new(ut64 val, bool is_from, RAnalRefline *ref) { return re; } -static bool add_refline(RList *list, RList *sten, ut64 addr, ut64 to, int *idx) { +static bool add_refline(RzList *list, RzList *sten, ut64 addr, ut64 to, int *idx) { ReflineEnd *re1, *re2; - RAnalRefline *item = R_NEW0 (RAnalRefline); + RzAnalRefline *item = R_NEW0 (RzAnalRefline); if (!item) { return false; } @@ -46,14 +46,14 @@ static bool add_refline(RList *list, RList *sten, ut64 addr, ut64 to, int *idx) item->level = -1; item->direction = (to > addr)? 1: -1; *idx += 1; - r_list_append (list, item); + rz_list_append (list, item); re1 = refline_end_new (item->from, true, item); if (!re1) { free (item); return false; } - r_list_add_sorted (sten, re1, (RListComparator)cmp_asc); + rz_list_add_sorted (sten, re1, (RzListComparator)cmp_asc); re2 = refline_end_new (item->to, false, item); if (!re2) { @@ -61,26 +61,26 @@ static bool add_refline(RList *list, RList *sten, ut64 addr, ut64 to, int *idx) free (item); return false; } - r_list_add_sorted (sten, re2, (RListComparator)cmp_asc); + rz_list_add_sorted (sten, re2, (RzListComparator)cmp_asc); return true; } -R_API void r_anal_reflines_free (RAnalRefline *rl) { +RZ_API void rz_anal_reflines_free (RzAnalRefline *rl) { free (rl); } -/* returns a list of RAnalRefline for the code present in the buffer buf, of - * length len. A RAnalRefline exists from address A to address B if a jmp, +/* returns a list of RzAnalRefline for the code present in the buffer buf, of + * length len. A RzAnalRefline exists from address A to address B if a jmp, * conditional jmp or call instruction exists at address A and it targets * address B. * * nlines - max number of lines of code to consider * linesout - true if you want to display lines that go outside of the scope [addr;addr+len) * linescall - true if you want to display call lines */ -R_API RList *r_anal_reflines_get(RAnal *anal, ut64 addr, const ut8 *buf, ut64 len, int nlines, int linesout, int linescall) { - RList *list, *sten; - RListIter *iter; - RAnalOp op; +RZ_API RzList *rz_anal_reflines_get(RzAnal *anal, ut64 addr, const ut8 *buf, ut64 len, int nlines, int linesout, int linescall) { + RzList *list, *sten; + RzListIter *iter; + RzAnalOp op; struct refline_end *el; const ut8 *ptr = buf; const ut8 *end = buf + len; @@ -100,17 +100,17 @@ R_API RList *r_anal_reflines_get(RAnal *anal, ut64 addr, const ut8 *buf, ut64 le * refline, we free that level. */ - list = r_list_newf (free); + list = rz_list_newf (free); if (!list) { return NULL; } - sten = r_list_newf ((RListFree)free); + sten = rz_list_newf ((RzListFree)free); if (!sten) { goto list_err; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); /* analyze code block */ - while (ptr < end && !r_cons_is_breaked ()) { + while (ptr < end && !rz_cons_is_breaked ()) { if (nlines != -1) { if (!nlines) { break; @@ -122,27 +122,27 @@ R_API RList *r_anal_reflines_get(RAnal *anal, ut64 addr, const ut8 *buf, ut64 le } addr += sz; { - RPVector *metas = r_meta_get_all_at (anal, addr); + RPVector *metas = rz_meta_get_all_at (anal, addr); if (metas) { void **it; ut64 skip = 0; - r_pvector_foreach (metas, it) { + rz_pvector_foreach (metas, it) { RIntervalNode *node = *it; - RAnalMetaItem *meta = node->data; + RzAnalMetaItem *meta = node->data; switch (meta->type) { case R_META_TYPE_DATA: case R_META_TYPE_STRING: case R_META_TYPE_HIDE: case R_META_TYPE_FORMAT: case R_META_TYPE_MAGIC: - skip = r_meta_node_size (node); + skip = rz_meta_node_size (node); goto do_skip; default: break; } } do_skip: - r_pvector_free (metas); + rz_pvector_free (metas); if (skip) { ptr += skip; addr += skip; @@ -158,8 +158,8 @@ do_skip: } // This can segfault if opcode length and buffer check fails - r_anal_op_fini (&op); - sz = r_anal_op (anal, &op, addr, ptr, (int)(end - ptr), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); + rz_anal_op_fini (&op); + sz = rz_anal_op (anal, &op, addr, ptr, (int)(end - ptr), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); sz = op.size; if (sz <= 0) { sz = 1; @@ -178,32 +178,32 @@ do_skip: break; } if (!(res = add_refline (list, sten, addr, op.jump, &count))) { - r_anal_op_fini (&op); + rz_anal_op_fini (&op); goto sten_err; } // add false branch in case its set and its not a call, useful for bf, maybe others if (!op.delay && op.fail != UT64_MAX && op.fail != addr + op.size) { if (!(res = add_refline (list, sten, addr, op.fail, &count))) { - r_anal_op_fini (&op); + rz_anal_op_fini (&op); goto sten_err; } } break; case R_ANAL_OP_TYPE_SWITCH: { - RAnalCaseOp *caseop; - RListIter *iter; + RzAnalCaseOp *caseop; + RzListIter *iter; // add caseops if (!op.switch_op) { break; } - r_list_foreach (op.switch_op->cases, iter, caseop) { + rz_list_foreach (op.switch_op->cases, iter, caseop) { if (!linesout && (op.jump > opc + len || op.jump < opc)) { goto __next; } if (!(res = add_refline (list, sten, op.switch_op->addr, caseop->jump, &count))) { - r_anal_op_fini (&op); + rz_anal_op_fini (&op); goto sten_err; } } @@ -213,16 +213,16 @@ do_skip: __next: ptr += sz; } - r_anal_op_fini (&op); - r_cons_break_pop (); + rz_anal_op_fini (&op); + rz_cons_break_pop (); - free_levels = R_NEWS0 (ut8, r_list_length (list) + 1); + free_levels = R_NEWS0 (ut8, rz_list_length (list) + 1); if (!free_levels) { goto sten_err; } int min = 0; - r_list_foreach (sten, iter, el) { + rz_list_foreach (sten, iter, el) { if ((el->is_from && el->r->level == -1) || (!el->is_from && el->r->level == -1)) { el->r->level = min + 1; free_levels[min] = 1; @@ -242,30 +242,30 @@ do_skip: /* XXX: the algorithm can be improved. We can calculate the set of * reflines used in each interval of addresses and store them. - * Considering r_anal_reflines_str is always called with increasing + * Considering rz_anal_reflines_str is always called with increasing * addresses, we can just traverse linearly the list of intervals to * know which reflines need to be drawn for each address. In this way, * we don't need to traverse again and again the reflines for each call - * to r_anal_reflines_str, but we can reuse the data already + * to rz_anal_reflines_str, but we can reuse the data already * calculated. Those data will be quickly available because the * intervals will be sorted and the addresses to consider are always * increasing. */ free (free_levels); - r_list_free (sten); + rz_list_free (sten); return list; sten_err: list_err: - r_list_free (sten); - r_list_free (list); + rz_list_free (sten); + rz_list_free (list); return NULL; } -R_API int r_anal_reflines_middle(RAnal *a, RList* /**/ list, ut64 addr, int len) { +RZ_API int rz_anal_reflines_middle(RzAnal *a, RzList* /**/ list, ut64 addr, int len) { if (a && list) { - RAnalRefline *ref; - RListIter *iter; - r_list_foreach (list, iter, ref) { + RzAnalRefline *ref; + RzListIter *iter; + rz_list_foreach (list, iter, ref) { if ((ref->to > addr) && (ref->to < addr + len)) { return true; } @@ -274,7 +274,7 @@ R_API int r_anal_reflines_middle(RAnal *a, RList* /**/ list, ut64 return false; } -static const char* get_corner_char(RAnalRefline *ref, ut64 addr, bool is_middle_before) { +static const char* get_corner_char(RzAnalRefline *ref, ut64 addr, bool is_middle_before) { if (ref->from == ref->to) { return "@"; } @@ -300,29 +300,29 @@ static void add_spaces(RBuffer *b, int level, int pos, bool wide) { level *= 2; } if (pos > level + 1) { - const char *pd = r_str_pad (' ', pos - level - 1); - r_buf_append_string (b, pd); + const char *pd = rz_str_pad (' ', pos - level - 1); + rz_buf_append_string (b, pd); } } } -static void fill_level(RBuffer *b, int pos, char ch, RAnalRefline *r, bool wide) { +static void fill_level(RBuffer *b, int pos, char ch, RzAnalRefline *r, bool wide) { int sz = r->level; if (wide) { sz *= 2; } - const char *pd = r_str_pad (ch, sz - 1); + const char *pd = rz_str_pad (ch, sz - 1); if (pos == -1) { - r_buf_append_string (b, pd); + rz_buf_append_string (b, pd); } else { int pdlen = strlen (pd); if (pdlen > 0) { - r_buf_write_at (b, pos, (const ut8 *)pd, pdlen); + rz_buf_write_at (b, pos, (const ut8 *)pd, pdlen); } } } -static inline bool refline_kept(RAnalRefline *ref, bool middle_after, ut64 addr) { +static inline bool refline_kept(RzAnalRefline *ref, bool middle_after, ut64 addr) { if (middle_after) { if (ref->direction < 0) { if (ref->from == addr) { @@ -339,14 +339,14 @@ static inline bool refline_kept(RAnalRefline *ref, bool middle_after, ut64 addr) // TODO: move into another file // TODO: this is TOO SLOW. do not iterate over all reflines or gtfo -R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { - RCore *core = _core; - RCons *cons = core->cons; - RAnal *anal = core->anal; +RZ_API RzAnalRefStr *rz_anal_reflines_str(void *_core, ut64 addr, int opts) { + RzCore *core = _core; + RzCons *cons = core->cons; + RzAnal *anal = core->anal; RBuffer *b; RBuffer *c; - RListIter *iter; - RAnalRefline *ref; + RzListIter *iter; + RzAnalRefline *ref; int l; bool wide = opts & R_ANAL_REFLINE_TYPE_WIDE; int dir = 0, pos = -1, max_level = -1; @@ -355,30 +355,30 @@ R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { char *str = NULL; char *col_str = NULL; - r_return_val_if_fail (cons && anal && anal->reflines, NULL); + rz_return_val_if_fail (cons && anal && anal->reflines, NULL); - RList *lvls = r_list_new (); + RzList *lvls = rz_list_new (); if (!lvls) { return NULL; } - r_list_foreach (anal->reflines, iter, ref) { + rz_list_foreach (anal->reflines, iter, ref) { if (core->cons && core->cons->context->breaked) { - r_list_free (lvls); + rz_list_free (lvls); return NULL; } if (in_refline (addr, ref) && refline_kept (ref, middle_after, addr)) { - r_list_add_sorted (lvls, (void *)ref, (RListComparator)cmp_by_ref_lvl); + rz_list_add_sorted (lvls, (void *)ref, (RzListComparator)cmp_by_ref_lvl); } } - b = r_buf_new (); - c = r_buf_new (); - r_buf_append_string (c, " "); - r_buf_append_string (b, " "); - r_list_foreach (lvls, iter, ref) { + b = rz_buf_new (); + c = rz_buf_new (); + rz_buf_append_string (c, " "); + rz_buf_append_string (b, " "); + rz_list_foreach (lvls, iter, ref) { if (core->cons && core->cons->context->breaked) { - r_list_free (lvls); - r_buf_free (b); - r_buf_free (c); + rz_list_free (lvls); + rz_buf_free (b); + rz_buf_free (c); return NULL; } if ((ref->from == addr || ref->to == addr) && !middle_after) { @@ -391,15 +391,15 @@ R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { if (wide) { ch_pos = ch_pos * 2 - 1; } - r_buf_write_at (b, ch_pos, (ut8 *)corner, 1); - r_buf_write_at (c, ch_pos, (ut8 *)col, 1); + rz_buf_write_at (b, ch_pos, (ut8 *)corner, 1); + rz_buf_write_at (c, ch_pos, (ut8 *)col, 1); fill_level (b, ch_pos + 1, ch, ref, wide); fill_level (c, ch_pos + 1, ch_col, ref, wide); } else { add_spaces (b, ref->level, pos, wide); add_spaces (c, ref->level, pos, wide); - r_buf_append_string (b, corner); - r_buf_append_string (c, col); + rz_buf_append_string (b, corner); + rz_buf_append_string (c, col); if (!middle_before) { fill_level (b, -1, ch, ref, wide); fill_level (c, -1, ch_col, ref, wide); @@ -416,11 +416,11 @@ R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { add_spaces (b, ref->level, pos, wide); add_spaces (c, ref->level, pos, wide); if (ref->from >= ref->to) { - r_buf_append_string (b, ":"); - r_buf_append_string (c, "t"); + rz_buf_append_string (b, ":"); + rz_buf_append_string (c, "t"); } else { - r_buf_append_string (b, "|"); - r_buf_append_string (c, "d"); + rz_buf_append_string (b, "|"); + rz_buf_append_string (c, "d"); } pos = ref->level; } @@ -430,27 +430,27 @@ R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { } add_spaces (c, 0, pos, wide); add_spaces (b, 0, pos, wide); - str = r_buf_to_string (b); - col_str = r_buf_to_string (c); - r_buf_free (b); - r_buf_free (c); + str = rz_buf_to_string (b); + col_str = rz_buf_to_string (c); + rz_buf_free (b); + rz_buf_free (c); b = NULL; c = NULL; if (!str || !col_str) { - r_list_free (lvls); - //r_buf_free_to_string already free b and if that is the case - //b will be NULL and r_buf_free will return but if there was + rz_list_free (lvls); + //rz_buf_free_to_string already free b and if that is the case + //b will be NULL and rz_buf_free will return but if there was //an error we free b here so in other words is safe - r_buf_free (b); - r_buf_free (c); + rz_buf_free (b); + rz_buf_free (c); return NULL; } if (core->anal->lineswidth > 0) { int lw = core->anal->lineswidth; l = strlen (str); if (l > lw) { - r_str_cpy (str, str + l - lw); - r_str_cpy (col_str, col_str + l - lw); + rz_str_cpy (str, str + l - lw); + rz_str_cpy (col_str, col_str + l - lw); } else { char pfx[128]; lw -= l; @@ -460,25 +460,25 @@ R_API RAnalRefStr *r_anal_reflines_str(void *_core, ut64 addr, int opts) { } if (lw > 0) { pfx[lw] = 0; - str = r_str_prepend (str, pfx); - col_str = r_str_prepend (col_str, pfx); + str = rz_str_prepend (str, pfx); + col_str = rz_str_prepend (col_str, pfx); } } } const char prev_col = col_str[strlen (col_str) - 1]; const char *arr_col = prev_col == 't' ? "tt ": "dd "; - str = r_str_append (str, (dir == 1) ? "-> " + str = rz_str_append (str, (dir == 1) ? "-> " : (dir == 2) ? "=< " : " "); - col_str = r_str_append (col_str, arr_col); + col_str = rz_str_append (col_str, arr_col); - r_list_free (lvls); - RAnalRefStr *out = R_NEW0 (RAnalRefStr); + rz_list_free (lvls); + RzAnalRefStr *out = R_NEW0 (RzAnalRefStr); out->str = str; out->cols = col_str; return out; } -R_API void r_anal_reflines_str_free(RAnalRefStr *refstr) { +RZ_API void rz_anal_reflines_str_free(RzAnalRefStr *refstr) { free (refstr->str); free (refstr->cols); free (refstr); diff --git a/librz/anal/rtti.c b/librz/anal/rtti.c new file mode 100644 index 0000000000..bd205cc732 --- /dev/null +++ b/librz/anal/rtti.c @@ -0,0 +1,99 @@ +/* radare - LGPL - Copyright 2009-2018 - pancake, maijin, thestr4ng3r */ + +#include "rz_anal.h" + +RZ_API char *rz_anal_rtti_demangle_class_name(RzAnal *anal, const char *name) { + RVTableContext context; + rz_anal_vtable_begin (anal, &context); + if (context.abi == R_ANAL_CPP_ABI_MSVC) { + return rz_anal_rtti_msvc_demangle_class_name (&context, name); + } + return rz_anal_rtti_itanium_demangle_class_name (&context, name); +} + +RZ_API void rz_anal_rtti_print_at_vtable(RzAnal *anal, ut64 addr, int mode) { + bool use_json = mode == 'j'; + if (use_json) { + rz_cons_print ("["); + } + + RVTableContext context; + rz_anal_vtable_begin (anal, &context); + if (context.abi == R_ANAL_CPP_ABI_MSVC) { + rz_anal_rtti_msvc_print_at_vtable (&context, addr, mode, false); + } else { + rz_anal_rtti_itanium_print_at_vtable (&context, addr, mode); + } + + if (use_json) { + rz_cons_print ("]\n"); + } +} + +RZ_API void rz_anal_rtti_print_all(RzAnal *anal, int mode) { + RVTableContext context; + rz_anal_vtable_begin (anal, &context); + + bool use_json = mode == 'j'; + if (use_json) { + rz_cons_print ("["); + } + + rz_cons_break_push (NULL, NULL); + RzList *vtables = rz_anal_vtable_search (&context); + RzListIter *vtableIter; + RVTableInfo *table; + + if (vtables) { + bool comma = false; + bool success = false; + rz_list_foreach (vtables, vtableIter, table) { + if (rz_cons_is_breaked ()) { + break; + } + if (use_json && success) { + rz_cons_print (","); + comma = true; + } + if (context.abi == R_ANAL_CPP_ABI_MSVC) { + success = rz_anal_rtti_msvc_print_at_vtable (&context, table->saddr, mode, true); + } else { + success = rz_anal_rtti_itanium_print_at_vtable (&context, table->saddr, mode); + } + if (success) { + comma = false; + if (!use_json) { + rz_cons_print ("\n"); + } + } + } + if (use_json && !success && comma) { + // drop last comma if necessary + rz_cons_drop (1); + } + } + rz_list_free (vtables); + + if (use_json) { + rz_cons_print ("]\n"); + } + + rz_cons_break_pop (); +} + +RZ_API void rz_anal_rtti_recover_all(RzAnal *anal) { + RVTableContext context; + rz_anal_vtable_begin (anal, &context); + + rz_cons_break_push (NULL, NULL); + RzList *vtables = rz_anal_vtable_search (&context); + if (vtables) { + if (context.abi == R_ANAL_CPP_ABI_MSVC) { + rz_anal_rtti_msvc_recover_all (&context, vtables); + } else { + rz_anal_rtti_itanium_recover_all (&context, vtables); + } + } + rz_list_free (vtables); + rz_cons_break_pop (); +} diff --git a/libr/anal/rtti_itanium.c b/librz/anal/rtti_itanium.c similarity index 90% rename from libr/anal/rtti_itanium.c rename to librz/anal/rtti_itanium.c index b3488806e5..3df0b0af73 100644 --- a/libr/anal/rtti_itanium.c +++ b/librz/anal/rtti_itanium.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2018 - pancake, r00tus3r */ -#include -#include -#include -#include +#include +#include +#include +#include #define VMI_CLASS_TYPE_INFO_NAME "__vmi_class_type_info" #define SI_CLASS_TYPE_INFO_NAME "__si_class_type_info" @@ -83,7 +83,7 @@ static bool rtti_itanium_read_type_name(RVTableContext *context, ut64 addr, clas return false; } buf[NAME_BUF_SIZE - 1] = 0; - cti->name = r_anal_rtti_itanium_demangle_class_name (context, (char *)buf); + cti->name = rz_anal_rtti_itanium_demangle_class_name (context, (char *)buf); if (!cti->name) { return false; } @@ -105,7 +105,7 @@ static char *rtti_itanium_read_type_name_custom(RVTableContext *context, ut64 ad return NULL; } buf[NAME_BUF_SIZE - 1] = 0; - char *name = r_anal_rtti_itanium_demangle_class_name (context, (char *)buf); + char *name = rz_anal_rtti_itanium_demangle_class_name (context, (char *)buf); return name; } @@ -300,11 +300,11 @@ static const char *type_to_string(RTypeInfoType type) { case R_TYPEINFO_TYPE_VMI_CLASS: return VMI_CLASS_TYPE_INFO_NAME; default: - r_return_val_if_reached (CLASS_TYPE_INFO_NAME); + rz_return_val_if_reached (CLASS_TYPE_INFO_NAME); } } static void rtti_itanium_print_class_type_info(class_type_info *cti, const char *prefix) { - r_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" + rz_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" "%s Type Info type: %s\n" "%s Belongs to class vtable: 0x%08" PFMT64x "\n" "%s Reference to RTTI's type class: 0x%08" PFMT64x "\n" @@ -336,12 +336,12 @@ static void rtti_itanium_print_class_type_info_json(class_type_info *cti) { pj_kb (pj, "name_unique", cti->name_unique); pj_end (pj); - r_cons_printf (pj_string (pj)); + rz_cons_printf (pj_string (pj)); pj_free (pj); } static void rtti_itanium_print_vmi_class_type_info(vmi_class_type_info *vmi_cti, const char *prefix) { - r_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" + rz_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" "%s Type Info type: %s\n" "%s Belongs to class vtable: 0x%08" PFMT64x "\n" "%s Reference to RTTI's type class: 0x%08" PFMT64x "\n" @@ -363,7 +363,7 @@ static void rtti_itanium_print_vmi_class_type_info(vmi_class_type_info *vmi_cti, int i; for (i = 0; i < vmi_cti->vmi_base_count; i++) { - r_cons_printf ("%s Base class type descriptor address: 0x%08" PFMT64x "\n" + rz_cons_printf ("%s Base class type descriptor address: 0x%08" PFMT64x "\n" "%s Base class flags: 0x%x" "\n", prefix, vmi_cti->vmi_bases[i].base_class_addr, @@ -398,12 +398,12 @@ static void rtti_itanium_print_vmi_class_type_info_json(vmi_class_type_info *vmi pj_end (pj); pj_end (pj); - r_cons_printf (pj_string (pj)); + rz_cons_printf (pj_string (pj)); pj_free (pj); } static void rtti_itanium_print_si_class_type_info(si_class_type_info *si_cti, const char *prefix) { - r_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" + rz_cons_printf ("%sType Info at 0x%08" PFMT64x ":\n" "%s Type Info type: %s\n" "%s Belongs to class vtable: 0x%08" PFMT64x "\n" "%s Reference to RTTI's type class: 0x%08" PFMT64x "\n" @@ -438,23 +438,23 @@ static void rtti_itanium_print_si_class_type_info_json(si_class_type_info *si_ct pj_kn (pj, "ref_to_parent_type", si_cti->base_class_addr); pj_end (pj); - r_cons_printf (pj_string (pj)); + rz_cons_printf (pj_string (pj)); pj_free (pj); } static RTypeInfoType rtti_itanium_type_info_type_from_flag(RVTableContext *context, ut64 atAddress) { - RCore *core = context->anal->coreb.core; - r_return_val_if_fail (core, R_TYPEINFO_TYPE_CLASS); + RzCore *core = context->anal->coreb.core; + rz_return_val_if_fail (core, R_TYPEINFO_TYPE_CLASS); // get the reloc flags - const RList *flags = context->anal->flb.get_list (core->flags, atAddress); + const RzList *flags = context->anal->flb.get_list (core->flags, atAddress); if (!flags) { return R_TYPEINFO_TYPE_UNKNOWN; } - RListIter *iter; - RFlagItem *flag; - r_list_foreach (flags, iter, flag) { + RzListIter *iter; + RzFlagItem *flag; + rz_list_foreach (flags, iter, flag) { if (strstr (flag->name, VMI_CLASS_TYPE_INFO_NAME)) { return R_TYPEINFO_TYPE_VMI_CLASS; } else if (strstr (flag->name, SI_CLASS_TYPE_INFO_NAME)) { @@ -477,7 +477,7 @@ static bool can_section_contain_rtti_vpointer(RBinSection *section) { } return !strcmp (section->name, ".data.rel.ro") || !strcmp (section->name, ".data.rel.ro.local") || - r_str_endswith (section->name, "__const"); + rz_str_endswith (section->name, "__const"); } static class_type_info *create_class_type(ut64 vtable_addr, char *name, ut64 name_addr, bool unique_name, ut64 typeinfo_addr, ut64 source_vtable) { @@ -667,7 +667,7 @@ static class_type_info *rtti_itanium_type_info_new(RVTableContext *context, ut64 case R_TYPEINFO_TYPE_CLASS: return rtti_itanium_class_type_info_new (context, rtti_addr, vtable_addr); default: - r_return_val_if_reached (NULL); + rz_return_val_if_reached (NULL); } } @@ -688,11 +688,11 @@ static void rtti_itanium_type_info_free(void *info) { rtti_itanium_class_type_info_free (cti); return; default: - r_return_if_reached (); + rz_return_if_reached (); } } -R_API bool r_anal_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode) { +RZ_API bool rz_anal_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode) { bool use_json = mode == 'j'; class_type_info *cti = rtti_itanium_type_info_new (context, addr); if (!cti) { @@ -731,11 +731,11 @@ R_API bool r_anal_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 add return true; default: rtti_itanium_class_type_info_free (cti); - r_return_val_if_reached (false); + rz_return_val_if_reached (false); } } -R_API char *r_anal_rtti_itanium_demangle_class_name(RVTableContext *context, const char *name) { +RZ_API char *rz_anal_rtti_itanium_demangle_class_name(RVTableContext *context, const char *name) { if (!name || !*name) { return NULL; } @@ -743,7 +743,7 @@ R_API char *r_anal_rtti_itanium_demangle_class_name(RVTableContext *context, con char *result = NULL; if (name[0] != '_') { - char *to_demangle = r_str_newf ("_Z%s", name); + char *to_demangle = rz_str_newf ("_Z%s", name); result = context->anal->binb.demangle (NULL, "cxx", to_demangle, 0, false); free (to_demangle); } else { @@ -758,18 +758,18 @@ static void recovery_apply_vtable(RVTableContext *context, const char *class_nam return; } - RAnalVTable vtable = { .id = NULL, .offset = 0, .size = 0, .addr = vtable_info->saddr}; - r_anal_class_vtable_set (context->anal, class_name, &vtable); - r_anal_class_vtable_fini (&vtable); + RzAnalVTable vtable = { .id = NULL, .offset = 0, .size = 0, .addr = vtable_info->saddr}; + rz_anal_class_vtable_set (context->anal, class_name, &vtable); + rz_anal_class_vtable_fini (&vtable); RVTableMethodInfo *vmeth; - r_vector_foreach (&vtable_info->methods, vmeth) { - RAnalMethod meth; + rz_vector_foreach (&vtable_info->methods, vmeth) { + RzAnalMethod meth; meth.addr = vmeth->addr; meth.vtable_offset = vmeth->vtable_offset; - meth.name = r_str_newf ("virtual_%d", meth.vtable_offset); - r_anal_class_method_set (context->anal, class_name, &meth); - r_anal_class_method_fini (&meth); + meth.name = rz_str_newf ("virtual_%d", meth.vtable_offset); + rz_anal_class_method_set (context->anal, class_name, &meth); + rz_anal_class_method_fini (&meth); } } @@ -790,9 +790,9 @@ static void add_class_bases(RVTableContext *context, const class_type_info *cti) base_addr += VT_WORD_SIZE (context); // offset to name if (rtti_itanium_read_type_name (context, base_addr, &base_info)) { // TODO in future, store the RTTI offset from vtable and use it - RAnalBaseClass base = { .class_name = base_info.name, .offset = 0 }; - r_anal_class_base_set (context->anal, cti->name, &base); - r_anal_class_base_fini (&base); + RzAnalBaseClass base = { .class_name = base_info.name, .offset = 0 }; + rz_anal_class_base_set (context->anal, cti->name, &base); + rz_anal_class_base_fini (&base); } } break; case R_TYPEINFO_TYPE_VMI_CLASS: { @@ -802,9 +802,9 @@ static void add_class_bases(RVTableContext *context, const class_type_info *cti) ut64 base_addr = base_class_info->base_class_addr + VT_WORD_SIZE (context); // offset to name if (rtti_itanium_read_type_name (context, base_addr, &base_info)) { // TODO in future, store the RTTI offset from vtable and use it - RAnalBaseClass base = { .class_name = base_info.name, .offset = 0 }; - r_anal_class_base_set (context->anal, cti->name, &base); - r_anal_class_base_fini (&base); + RzAnalBaseClass base = { .class_name = base_info.name, .offset = 0 }; + rz_anal_class_base_set (context->anal, cti->name, &base); + rz_anal_class_base_fini (&base); } } } break; @@ -813,21 +813,21 @@ static void add_class_bases(RVTableContext *context, const class_type_info *cti) } } -R_API void r_anal_rtti_itanium_recover_all(RVTableContext *context, RList *vtables) { - RList /**/ *rtti_list = r_list_new (); +RZ_API void rz_anal_rtti_itanium_recover_all(RVTableContext *context, RzList *vtables) { + RzList /**/ *rtti_list = rz_list_new (); rtti_list->free = rtti_itanium_type_info_free; // to escape multiple same infos from multiple inheritance SetU *unique_rttis = set_u_new (); - RListIter *iter; + RzListIter *iter; RVTableInfo *vtable; - r_list_foreach (vtables, iter, vtable) { + rz_list_foreach (vtables, iter, vtable) { class_type_info *cti = rtti_itanium_type_info_new (context, vtable->saddr); if (!cti) { continue; } - r_anal_class_create (context->anal, cti->name); + rz_anal_class_create (context->anal, cti->name); // can't we name virtual functions virtual even without RTTI? recovery_apply_vtable (context, cti->name, vtable); @@ -836,15 +836,15 @@ R_API void r_anal_rtti_itanium_recover_all(RVTableContext *context, RList *vtabl rtti_itanium_type_info_free (cti); } else { set_u_add (unique_rttis, cti->typeinfo_addr); - r_list_append (rtti_list, cti); + rz_list_append (rtti_list, cti); } } class_type_info *cti; - r_list_foreach (rtti_list, iter, cti) { + rz_list_foreach (rtti_list, iter, cti) { add_class_bases (context, cti); } set_u_free (unique_rttis); - r_list_free (rtti_list); + rz_list_free (rtti_list); } diff --git a/libr/anal/rtti_msvc.c b/librz/anal/rtti_msvc.c similarity index 82% rename from libr/anal/rtti_msvc.c rename to librz/anal/rtti_msvc.c index 6db4cd798a..238fa8f1c8 100644 --- a/libr/anal/rtti_msvc.c +++ b/librz/anal/rtti_msvc.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2018 - pancake, maijin, thestr4ng3r */ -#include "r_anal.h" +#include "rz_anal.h" #define NAME_BUF_SIZE 64 #define BASE_CLASSES_MAX 32 @@ -70,14 +70,14 @@ static bool rtti_msvc_read_complete_object_locator(RVTableContext *context, ut64 return false; } - ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? r_read_at_be32 : r_read_at_le32; + ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? rz_read_at_be32 : rz_read_at_le32; col->signature = read_at_32 (buf, 0); col->vtable_offset = read_at_32 (buf, 4); col->cd_offset = read_at_32 (buf, 8); int offsetSize = R_MIN (context->word_size, 4); - col->type_descriptor_addr = (ut32) r_read_ble (buf + 12, (bool) context->anal->big_endian, offsetSize * 8); - col->class_descriptor_addr = (ut32) r_read_ble (buf + 12 + offsetSize, (bool) context->anal->big_endian, offsetSize * 8); + col->type_descriptor_addr = (ut32) rz_read_ble (buf + 12, (bool) context->anal->big_endian, offsetSize * 8); + col->class_descriptor_addr = (ut32) rz_read_ble (buf + 12 + offsetSize, (bool) context->anal->big_endian, offsetSize * 8); if (context->word_size == 8) { // 64bit is special: // Type Descriptor and Class Hierarchy Descriptor addresses are computed @@ -106,12 +106,12 @@ static bool rtti_msvc_read_class_hierarchy_descriptor(RVTableContext *context, u return false; } - ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? r_read_at_be32 : r_read_at_le32; + ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? rz_read_at_be32 : rz_read_at_le32; chd->signature = read_at_32 (buf, 0); chd->attributes = read_at_32 (buf, 4); chd->num_base_classes = read_at_32 (buf, 8); if (context->word_size <= 4) { - chd->base_class_array_addr = (ut32) r_read_ble (buf + 12, (bool) context->anal->big_endian, context->word_size * 8); + chd->base_class_array_addr = (ut32) rz_read_ble (buf + 12, (bool) context->anal->big_endian, context->word_size * 8); } else { // 64bit is special, like in Complete Object Locator. // Only the offset from the base from Complete Object Locator @@ -140,9 +140,9 @@ static bool rtti_msvc_read_base_class_descriptor(RVTableContext *context, ut64 a return false; } - ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? r_read_at_be32 : r_read_at_le32; + ut32 (*read_at_32)(const void *src, size_t offset) = context->anal->big_endian ? rz_read_at_be32 : rz_read_at_le32; int typeDescriptorAddrSize = R_MIN (context->word_size, 4); - bcd->type_descriptor_addr = (ut32) r_read_ble (buf, (bool) context->anal->big_endian, typeDescriptorAddrSize * 8); + bcd->type_descriptor_addr = (ut32) rz_read_ble (buf, (bool) context->anal->big_endian, typeDescriptorAddrSize * 8); size_t offset = (size_t) typeDescriptorAddrSize; bcd->num_contained_bases = read_at_32 (buf, offset); bcd->where.mdisp = read_at_32 (buf, offset + sizeof (ut32)); @@ -152,12 +152,12 @@ static bool rtti_msvc_read_base_class_descriptor(RVTableContext *context, ut64 a return true; } -static RList *rtti_msvc_read_base_class_array(RVTableContext *context, ut32 num_base_classes, ut64 base, ut32 offset) { +static RzList *rtti_msvc_read_base_class_array(RVTableContext *context, ut32 num_base_classes, ut64 base, ut32 offset) { if (base == UT64_MAX || offset == UT32_MAX || num_base_classes == UT32_MAX) { return NULL; } - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } @@ -172,9 +172,9 @@ static RList *rtti_msvc_read_base_class_array(RVTableContext *context, ut32 num_ num_base_classes = BASE_CLASSES_MAX; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); while (num_base_classes > 0) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } @@ -190,10 +190,10 @@ static RList *rtti_msvc_read_base_class_array(RVTableContext *context, ut32 num_ // special offset calculation for 64bit ut8 tmp[4] = {0}; if (!context->anal->iob.read_at(context->anal->iob.io, addr, tmp, 4)) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - ut32 (*read_32)(const void *src) = context->anal->big_endian ? r_read_be32 : r_read_le32; + ut32 (*read_32)(const void *src) = context->anal->big_endian ? rz_read_be32 : rz_read_le32; ut32 bcdOffset = read_32 (tmp); if (bcdOffset == UT32_MAX) { break; @@ -209,15 +209,15 @@ static RList *rtti_msvc_read_base_class_array(RVTableContext *context, ut32 num_ free (bcd); break; } - r_list_append (ret, bcd); + rz_list_append (ret, bcd); addr += stride; num_base_classes--; } - r_cons_break_pop (); + rz_cons_break_pop (); if (num_base_classes > 0) { // there was an error in the loop above - r_list_free (ret); + rz_list_free (ret); return NULL; } @@ -282,7 +282,7 @@ static bool rtti_msvc_read_type_descriptor(RVTableContext *context, ut64 addr, r } static void rtti_msvc_print_complete_object_locator(rtti_complete_object_locator *col, ut64 addr, const char *prefix) { - r_cons_printf ("%sComplete Object Locator at 0x%08"PFMT64x":\n" + rz_cons_printf ("%sComplete Object Locator at 0x%08"PFMT64x":\n" "%s\tsignature: %#x\n" "%s\tvftableOffset: %#x\n" "%s\tcdOffset: %#x\n" @@ -294,19 +294,19 @@ static void rtti_msvc_print_complete_object_locator(rtti_complete_object_locator prefix, col->cd_offset, prefix, col->type_descriptor_addr, prefix, col->class_descriptor_addr); - r_cons_printf ("%s\tobjectBase: 0x%08"PFMT32x"\n\n", + rz_cons_printf ("%s\tobjectBase: 0x%08"PFMT32x"\n\n", prefix, col->object_base); } static void rtti_msvc_print_complete_object_locator_json(rtti_complete_object_locator *col) { - r_cons_printf ("{\"signature\":%"PFMT32u",\"vftable_offset\":%"PFMT32u",\"cd_offset\":%"PFMT32u"," + rz_cons_printf ("{\"signature\":%"PFMT32u",\"vftable_offset\":%"PFMT32u",\"cd_offset\":%"PFMT32u"," "\"type_desc_addr\":%"PFMT32u",\"class_desc_addr\":%"PFMT32u",\"object_base\":%"PFMT32u"}", col->signature, col->vtable_offset, col->cd_offset, col->type_descriptor_addr, col->class_descriptor_addr, col->object_base); } static void rtti_msvc_print_type_descriptor(rtti_type_descriptor *td, ut64 addr, const char *prefix) { - r_cons_printf ("%sType Descriptor at 0x%08"PFMT64x":\n" + rz_cons_printf ("%sType Descriptor at 0x%08"PFMT64x":\n" "%s\tvtableAddr: 0x%08"PFMT64x"\n" "%s\tspare: 0x%08"PFMT64x"\n" "%s\tname: %s\n\n", @@ -317,12 +317,12 @@ static void rtti_msvc_print_type_descriptor(rtti_type_descriptor *td, ut64 addr, } static void rtti_msvc_print_type_descriptor_json(rtti_type_descriptor *td) { - r_cons_printf ("{\"vtable_addr\":%"PFMT32u",\"spare\":%"PFMT32u",\"name\":\"%s\"}", + rz_cons_printf ("{\"vtable_addr\":%"PFMT32u",\"spare\":%"PFMT32u",\"name\":\"%s\"}", td->vtable_addr, td->spare, td->name); } static void rtti_msvc_print_class_hierarchy_descriptor(rtti_class_hierarchy_descriptor *chd, ut64 addr, const char *prefix) { - r_cons_printf ("%sClass Hierarchy Descriptor at 0x%08"PFMT64x":\n" + rz_cons_printf ("%sClass Hierarchy Descriptor at 0x%08"PFMT64x":\n" "%s\tsignature: %#x\n" "%s\tattributes: %#x\n" "%s\tnumBaseClasses: %#x\n" @@ -335,13 +335,13 @@ static void rtti_msvc_print_class_hierarchy_descriptor(rtti_class_hierarchy_desc } static void rtti_msvc_print_class_hierarchy_descriptor_json(rtti_class_hierarchy_descriptor *chd) { - r_cons_printf ("{\"signature\":%"PFMT32u",\"attributes\":%"PFMT32u",\"num_base_classes\":%"PFMT32u"," + rz_cons_printf ("{\"signature\":%"PFMT32u",\"attributes\":%"PFMT32u",\"num_base_classes\":%"PFMT32u"," "\"base_class_array_addr\":%"PFMT32u"}", chd->signature, chd->attributes, chd->num_base_classes, chd->base_class_array_addr); } static void rtti_msvc_print_base_class_descriptor(rtti_base_class_descriptor *bcd, const char *prefix) { - r_cons_printf ("%sBase Class Descriptor:\n" + rz_cons_printf ("%sBase Class Descriptor:\n" "%s\ttypeDescriptorAddr: 0x%08"PFMT32x"\n" "%s\tnumContainedBases: %#x\n" "%s\twhere:\n" @@ -360,7 +360,7 @@ static void rtti_msvc_print_base_class_descriptor(rtti_base_class_descriptor *bc } static void rtti_msvc_print_base_class_descriptor_json(rtti_base_class_descriptor *bcd) { - r_cons_printf ("{\"type_desc_addr\":%"PFMT32u",\"num_contained_bases\":%"PFMT32u"," + rz_cons_printf ("{\"type_desc_addr\":%"PFMT32u",\"num_contained_bases\":%"PFMT32u"," "\"where\":{\"mdisp\":%"PFMT32d",\"pdisp\":%"PFMT32d",\"vdisp\":%"PFMT32d"}," "\"attributes\":%"PFMT32u"}", bcd->type_descriptor_addr, bcd->num_contained_bases, @@ -377,7 +377,7 @@ static void rtti_msvc_print_base_class_descriptor_json(rtti_base_class_descripto * .?AVClassInInnerNamespace@InnerNamespace@OuterNamespace@@ * => OuterNamespace::InnerNamespace::AVClassInInnerNamespace */ -R_API char *r_anal_rtti_msvc_demangle_class_name(RVTableContext *context, const char *name) { +RZ_API char *rz_anal_rtti_msvc_demangle_class_name(RVTableContext *context, const char *name) { if (!name) { return NULL; } @@ -403,7 +403,7 @@ R_API char *r_anal_rtti_msvc_demangle_class_name(RVTableContext *context, const return ret; } -R_API void r_anal_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_anal_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode) { rtti_complete_object_locator col; if (!rtti_msvc_read_complete_object_locator (context, addr, &col)) { eprintf ("Failed to parse Complete Object Locator at 0x%08"PFMT64x"\n", addr); @@ -417,7 +417,7 @@ R_API void r_anal_rtti_msvc_print_complete_object_locator(RVTableContext *contex } } -R_API void r_anal_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_anal_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode) { rtti_type_descriptor td = { 0 }; if (!rtti_msvc_read_type_descriptor (context, addr, &td)) { eprintf ("Failed to parse Type Descriptor at 0x%08"PFMT64x"\n", addr); @@ -433,7 +433,7 @@ R_API void r_anal_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 rtti_type_descriptor_fini (&td); } -R_API void r_anal_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_anal_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode) { rtti_class_hierarchy_descriptor chd; if (!rtti_msvc_read_class_hierarchy_descriptor (context, addr, &chd)) { eprintf ("Failed to parse Class Hierarchy Descriptor at 0x%08"PFMT64x"\n", addr); @@ -447,7 +447,7 @@ R_API void r_anal_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *con } } -R_API void r_anal_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode) { +RZ_API void rz_anal_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode) { rtti_base_class_descriptor bcd; if (!rtti_msvc_read_base_class_descriptor (context, addr, &bcd)) { eprintf ("Failed to parse Base Class Descriptor at 0x%08"PFMT64x"\n", addr); @@ -507,7 +507,7 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont baseClassArrayOffset = chd.base_class_array_addr; } - RList *baseClassArray = rtti_msvc_read_base_class_array (context, chd.num_base_classes, base, baseClassArrayOffset); + RzList *baseClassArray = rtti_msvc_read_base_class_array (context, chd.num_base_classes, base, baseClassArrayOffset); if (!baseClassArray) { if (!strict) { eprintf ("Failed to parse Base Class Array starting at 0x%08"PFMT64x"\n", base + baseClassArrayOffset); @@ -519,13 +519,13 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont // print if (use_json) { - r_cons_print ("{\"complete_object_locator\":"); + rz_cons_print ("{\"complete_object_locator\":"); rtti_msvc_print_complete_object_locator_json (&col); - r_cons_print (",\"type_desc\":"); + rz_cons_print (",\"type_desc\":"); rtti_msvc_print_type_descriptor_json (&td); - r_cons_print (",\"class_hierarchy_desc\":"); + rz_cons_print (",\"class_hierarchy_desc\":"); rtti_msvc_print_class_hierarchy_descriptor_json (&chd); - r_cons_print (",\"base_classes\":["); + rz_cons_print (",\"base_classes\":["); } else { rtti_msvc_print_complete_object_locator (&col, colAddr, ""); rtti_msvc_print_type_descriptor (&td, typeDescriptorAddr, "\t"); @@ -535,15 +535,15 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont // base classes bool json_first = true; - RListIter *bcdIter; + RzListIter *bcdIter; rtti_base_class_descriptor *bcd; - r_list_foreach (baseClassArray, bcdIter, bcd) { + rz_list_foreach (baseClassArray, bcdIter, bcd) { if (use_json) { if (json_first) { - r_cons_print ("{\"desc\":"); + rz_cons_print ("{\"desc\":"); json_first = false; } else { - r_cons_print (",{\"desc\":"); + rz_cons_print (",{\"desc\":"); } } @@ -557,7 +557,7 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont rtti_type_descriptor btd = { 0 }; if (rtti_msvc_read_type_descriptor (context, baseTypeDescriptorAddr, &btd)) { if (use_json) { - r_cons_print (",\"type_desc\":"); + rz_cons_print (",\"type_desc\":"); rtti_msvc_print_type_descriptor_json (&btd); } else { rtti_msvc_print_type_descriptor (&btd, baseTypeDescriptorAddr, "\t\t\t"); @@ -570,22 +570,22 @@ static bool rtti_msvc_print_complete_object_locator_recurse(RVTableContext *cont } if(use_json) { - r_cons_print ("}"); + rz_cons_print ("}"); } } if (use_json) { - r_cons_print ("]"); + rz_cons_print ("]"); } if (use_json) { - r_cons_print ("}"); + rz_cons_print ("}"); } rtti_type_descriptor_fini (&td); return true; } -R_API bool r_anal_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict) { +RZ_API bool rz_anal_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict) { return rtti_msvc_print_complete_object_locator_recurse (context, addr, mode, strict); } @@ -603,8 +603,8 @@ typedef struct recovery_complete_object_locator_t { rtti_complete_object_locator col; RecoveryTypeDescriptor *td; rtti_class_hierarchy_descriptor chd; - RList *bcd; // - RVector base_td; // + RzList *bcd; // + RzVector base_td; // } RecoveryCompleteObjectLocator; RecoveryCompleteObjectLocator *recovery_complete_object_locator_new() { @@ -612,7 +612,7 @@ RecoveryCompleteObjectLocator *recovery_complete_object_locator_new() { if (!col) { return NULL; } - r_vector_init (&col->base_td, sizeof(RecoveryBaseDescriptor), NULL, NULL); + rz_vector_init (&col->base_td, sizeof(RecoveryBaseDescriptor), NULL, NULL); return col; } @@ -620,8 +620,8 @@ void recovery_complete_object_locator_free(RecoveryCompleteObjectLocator *col) { if (!col) { return; } - r_list_free (col->bcd); - r_vector_clear (&col->base_td); + rz_list_free (col->bcd); + rz_vector_clear (&col->base_td); free (col); } @@ -679,7 +679,7 @@ RecoveryCompleteObjectLocator *recovery_anal_complete_object_locator(RRTTIMSVCAn if (!col) { return NULL; } - r_pvector_push (&context->complete_object_locators, col); + rz_pvector_push (&context->complete_object_locators, col); ht_up_insert (context->addr_col, addr, col); col->addr = addr; col->valid = rtti_msvc_read_complete_object_locator (context->vt_context, addr, &col->col); @@ -719,10 +719,10 @@ RecoveryCompleteObjectLocator *recovery_anal_complete_object_locator(RRTTIMSVCAn } - r_vector_reserve (&col->base_td, (size_t)col->bcd->length); - RListIter *bcdIter; + rz_vector_reserve (&col->base_td, (size_t)col->bcd->length); + RzListIter *bcdIter; rtti_base_class_descriptor *bcd; - r_list_foreach (col->bcd, bcdIter, bcd) { + rz_list_foreach (col->bcd, bcdIter, bcd) { ut64 base_td_addr = rtti_msvc_addr (context->vt_context, col->addr, col->col.object_base, bcd->type_descriptor_addr); RecoveryTypeDescriptor *td = recovery_anal_type_descriptor (context, base_td_addr, NULL); if (td == col->td) { @@ -734,7 +734,7 @@ RecoveryCompleteObjectLocator *recovery_anal_complete_object_locator(RRTTIMSVCAn } continue; } - RecoveryBaseDescriptor *base_desc = r_vector_push (&col->base_td, NULL); + RecoveryBaseDescriptor *base_desc = rz_vector_push (&col->base_td, NULL); base_desc->bcd = bcd; base_desc->td = td; } @@ -755,7 +755,7 @@ RecoveryTypeDescriptor *recovery_anal_type_descriptor(RRTTIMSVCAnalContext *cont if (!td) { return NULL; } - r_pvector_push (&context->type_descriptors, td); + rz_pvector_push (&context->type_descriptors, td); ht_up_insert (context->addr_td, addr, td); td->addr = addr; td->valid = rtti_msvc_read_type_descriptor (context->vt_context, addr, &td->td); @@ -769,8 +769,8 @@ RecoveryTypeDescriptor *recovery_anal_type_descriptor(RRTTIMSVCAnalContext *cont } -static char *unique_class_name(RAnal *anal, const char *original_name) { - if (!r_anal_class_exists (anal, original_name)) { +static char *unique_class_name(RzAnal *anal, const char *original_name) { + if (!rz_anal_class_exists (anal, original_name)) { return strdup (original_name); } @@ -782,44 +782,44 @@ static char *unique_class_name(RAnal *anal, const char *original_name) { do { free (name); - name = r_str_newf ("%s.%d", original_name, i++); + name = rz_str_newf ("%s.%d", original_name, i++); if (!name) { return NULL; } - } while (r_anal_class_exists (anal, name)); + } while (rz_anal_class_exists (anal, name)); return name; } -static void recovery_apply_vtable(RAnal *anal, const char *class_name, RVTableInfo *vtable_info) { +static void recovery_apply_vtable(RzAnal *anal, const char *class_name, RVTableInfo *vtable_info) { if (!vtable_info) { return; } - RAnalVTable vtable; + RzAnalVTable vtable; vtable.id = NULL; vtable.offset = 0; vtable.addr = vtable_info->saddr; - r_anal_class_vtable_set (anal, class_name, &vtable); - r_anal_class_vtable_fini (&vtable); + rz_anal_class_vtable_set (anal, class_name, &vtable); + rz_anal_class_vtable_fini (&vtable); RVTableMethodInfo *vmeth; - r_vector_foreach (&vtable_info->methods, vmeth) { - RAnalMethod meth; + rz_vector_foreach (&vtable_info->methods, vmeth) { + RzAnalMethod meth; meth.addr = vmeth->addr; meth.vtable_offset = vmeth->vtable_offset; - meth.name = r_str_newf ("virtual_%d", meth.vtable_offset); - r_anal_class_method_set (anal, class_name, &meth); - r_anal_class_method_fini (&meth); + meth.name = rz_str_newf ("virtual_%d", meth.vtable_offset); + rz_anal_class_method_set (anal, class_name, &meth); + rz_anal_class_method_fini (&meth); } } static const char *recovery_apply_complete_object_locator(RRTTIMSVCAnalContext *context, RecoveryCompleteObjectLocator *col); static const char *recovery_apply_type_descriptor(RRTTIMSVCAnalContext *context, RecoveryTypeDescriptor *td); -static void recovery_apply_bases(RRTTIMSVCAnalContext *context, const char *class_name, RVector *base_descs) { +static void recovery_apply_bases(RRTTIMSVCAnalContext *context, const char *class_name, RzVector *base_descs) { RecoveryBaseDescriptor *base_desc; - r_vector_foreach (base_descs, base_desc) { + rz_vector_foreach (base_descs, base_desc) { RecoveryTypeDescriptor *base_td = base_desc->td; if (!base_td->valid) { eprintf ("Warning Base td is invalid!\n"); @@ -843,12 +843,12 @@ static void recovery_apply_bases(RRTTIMSVCAnalContext *context, const char *clas continue; } - RAnalBaseClass base; + RzAnalBaseClass base; base.id = NULL; base.offset = (ut64)base_desc->bcd->where.mdisp; base.class_name = strdup (base_class_name); - r_anal_class_base_set (context->vt_context->anal, class_name, &base); - r_anal_class_base_fini (&base); + rz_anal_class_base_set (context->vt_context->anal, class_name, &base); + rz_anal_class_base_fini (&base); } } @@ -865,14 +865,14 @@ static const char *recovery_apply_complete_object_locator(RRTTIMSVCAnalContext * return NULL; } - RAnal *anal = context->vt_context->anal; + RzAnal *anal = context->vt_context->anal; const char *existing = ht_up_find (context->col_td_classes, col->addr, NULL); if (existing != NULL) { return existing; } - char *name = r_anal_rtti_msvc_demangle_class_name (context->vt_context, col->td->td.name); + char *name = rz_anal_rtti_msvc_demangle_class_name (context->vt_context, col->td->td.name); if (!name) { if (context->vt_context->anal->verbose) { eprintf ("Failed to demangle a class name: \"%s\"\n", col->td->td.name); @@ -890,7 +890,7 @@ static const char *recovery_apply_complete_object_locator(RRTTIMSVCAnalContext * return NULL; } - r_anal_class_create (anal, name); + rz_anal_class_create (anal, name); ht_up_insert (context->col_td_classes, col->addr, name); recovery_apply_vtable (anal, name, col->vtable); @@ -906,14 +906,14 @@ static const char *recovery_apply_type_descriptor(RRTTIMSVCAnalContext *context, return NULL; } - RAnal *anal = context->vt_context->anal; + RzAnal *anal = context->vt_context->anal; const char *existing = ht_up_find (context->col_td_classes, td->addr, NULL); if (existing != NULL) { return existing; } - char *name = r_anal_rtti_msvc_demangle_class_name (context->vt_context, td->td.name); + char *name = rz_anal_rtti_msvc_demangle_class_name (context->vt_context, td->td.name); if (!name) { if (context->vt_context->anal->verbose) { eprintf("Failed to demangle a class name: \"%s\"\n", td->td.name); @@ -924,7 +924,7 @@ static const char *recovery_apply_type_descriptor(RRTTIMSVCAnalContext *context, } } - r_anal_class_create (anal, name); + rz_anal_class_create (anal, name); ht_up_insert (context->col_td_classes, td->addr, name); if (!td->col || !td->col->valid) { @@ -941,21 +941,21 @@ void str_value_free(HtPPKv *kv) { free (kv->value); } -R_API void r_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RList *vtables) { +RZ_API void rz_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RzList *vtables) { RRTTIMSVCAnalContext context; context.vt_context = vt_context; - r_pvector_init (&context.vtables, (RPVectorFree)r_anal_vtable_info_free); + rz_pvector_init (&context.vtables, (RPVectorFree)rz_anal_vtable_info_free); - r_pvector_init (&context.complete_object_locators, (RPVectorFree) recovery_complete_object_locator_free); + rz_pvector_init (&context.complete_object_locators, (RPVectorFree) recovery_complete_object_locator_free); context.addr_col = ht_up_new0 (); - r_pvector_init (&context.type_descriptors, (RPVectorFree) recovery_type_descriptor_free); + rz_pvector_init (&context.type_descriptors, (RPVectorFree) recovery_type_descriptor_free); context.addr_td = ht_up_new0 (); context.col_td_classes = ht_up_new (NULL, (HtUPKvFreeFunc)str_value_free, (HtUPCalcSizeV)strlen); - RListIter *vtableIter; + RzListIter *vtableIter; RVTableInfo *table; - r_list_foreach (vtables, vtableIter, table) { + rz_list_foreach (vtables, vtableIter, table) { ut64 colRefAddr = table->saddr - vt_context->word_size; ut64 colAddr; if (!vt_context->read_addr (vt_context->anal, colRefAddr, &colAddr)) { @@ -966,7 +966,7 @@ R_API void r_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RList *vtabl void **it; #if USE_TD_RECOVERY - r_pvector_foreach (&context.type_descriptors, it) { + rz_pvector_foreach (&context.type_descriptors, it) { RecoveryTypeDescriptor *td = *it; if (!td->valid) { continue; @@ -974,7 +974,7 @@ R_API void r_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RList *vtabl recovery_apply_type_descriptor (&context, td); } #else - r_pvector_foreach (&context.complete_object_locators, it) { + rz_pvector_foreach (&context.complete_object_locators, it) { RecoveryCompleteObjectLocator *col = *it; if (!col->valid) { continue; @@ -983,10 +983,10 @@ R_API void r_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RList *vtabl } #endif - r_pvector_clear (&context.vtables); - r_pvector_clear (&context.complete_object_locators); + rz_pvector_clear (&context.vtables); + rz_pvector_clear (&context.complete_object_locators); ht_up_free (context.addr_col); - r_pvector_clear (&context.type_descriptors); + rz_pvector_clear (&context.type_descriptors); ht_up_free (context.addr_td); ht_up_free (context.col_td_classes); } diff --git a/libr/anal/sign.c b/librz/anal/sign.c similarity index 57% rename from libr/anal/sign.c rename to librz/anal/sign.c index 3ea1ee7fbf..8611f383d0 100644 --- a/libr/anal/sign.c +++ b/librz/anal/sign.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include -#include -#include -#include +#include +#include +#include +#include -R_LIB_VERSION (r_sign); +R_LIB_VERSION (rz_sign); #define SIGN_DIFF_MATCH_BYTES_THRESHOLD 1.0 #define SIGN_DIFF_MATCH_GRAPH_THRESHOLD 1.0 -const char *getRealRef(RCore *core, ut64 off) { - RFlagItem *item; - RListIter *iter; +const char *getRealRef(RzCore *core, ut64 off) { + RzFlagItem *item; + RzListIter *iter; - const RList *list = r_flag_get_list (core->flags, off); + const RzList *list = rz_flag_get_list (core->flags, off); if (!list) { return NULL; } - r_list_foreach (list, iter, item) { + rz_list_foreach (list, iter, item) { if (!item->name) { continue; } @@ -32,63 +32,63 @@ const char *getRealRef(RCore *core, ut64 off) { return NULL; } -R_API RList *r_sign_fcn_vars(RAnal *a, RAnalFunction *fcn) { - r_return_val_if_fail (a && fcn, NULL); +RZ_API RzList *rz_sign_fcn_vars(RzAnal *a, RzAnalFunction *fcn) { + rz_return_val_if_fail (a && fcn, NULL); - RCore *core = a->coreb.core; + RzCore *core = a->coreb.core; if (!core) { return NULL; } - RListIter *iter; - RAnalVar *var; - RList *ret = r_list_newf ((RListFree) free); + RzListIter *iter; + RzAnalVar *var; + RzList *ret = rz_list_newf ((RzListFree) free); if (!ret) { return NULL; } - RList *reg_vars = r_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_REG); - RList *spv_vars = r_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_SPV); - RList *bpv_vars = r_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_BPV); - r_list_foreach (bpv_vars, iter, var) { - r_list_append (ret, r_str_newf ("b%d", var->delta)); + RzList *reg_vars = rz_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_REG); + RzList *spv_vars = rz_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_SPV); + RzList *bpv_vars = rz_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_BPV); + rz_list_foreach (bpv_vars, iter, var) { + rz_list_append (ret, rz_str_newf ("b%d", var->delta)); } - r_list_foreach (spv_vars, iter, var) { - r_list_append (ret, r_str_newf ("s%d", var->delta)); + rz_list_foreach (spv_vars, iter, var) { + rz_list_append (ret, rz_str_newf ("s%d", var->delta)); } - r_list_foreach (reg_vars, iter, var) { - r_list_append (ret, r_str_newf ("r%d", var->delta)); + rz_list_foreach (reg_vars, iter, var) { + rz_list_append (ret, rz_str_newf ("r%d", var->delta)); } - r_list_free (reg_vars); - r_list_free (bpv_vars); - r_list_free (spv_vars); + rz_list_free (reg_vars); + rz_list_free (bpv_vars); + rz_list_free (spv_vars); return ret; } -R_API RList *r_sign_fcn_types(RAnal *a, RAnalFunction *fcn) { +RZ_API RzList *rz_sign_fcn_types(RzAnal *a, RzAnalFunction *fcn) { // From anal/types/*: // Get key-value types from sdb matching "func.%s", fcn->name // Get func.%s.args (number of args) // Get type,name pairs - // Put everything in RList following the next format: + // Put everything in RzList following the next format: // types: main.ret=%type%, main.args=%num%, main.arg.0="int,argc", ... - r_return_val_if_fail (a && fcn, NULL); + rz_return_val_if_fail (a && fcn, NULL); - RList *ret = r_list_newf ((RListFree) free); + RzList *ret = rz_list_newf ((RzListFree) free); if (!ret) { return NULL; } - char *scratch = r_str_newf ("func.%s.args", fcn->name); + char *scratch = rz_str_newf ("func.%s.args", fcn->name); if (!scratch) { return NULL; } const char *fcntypes = sdb_const_get (a->sdb_types, scratch, 0); free (scratch); - scratch = r_str_newf ("func.%s.ret", fcn->name); + scratch = rz_str_newf ("func.%s.ret", fcn->name); if (!scratch) { return NULL; } @@ -97,74 +97,74 @@ R_API RList *r_sign_fcn_types(RAnal *a, RAnalFunction *fcn) { if (fcntypes) { if (ret_type) { - r_list_append (ret, r_str_newf ("func.%s.ret=%s", fcn->name, ret_type)); + rz_list_append (ret, rz_str_newf ("func.%s.ret=%s", fcn->name, ret_type)); } int argc = atoi (fcntypes); - r_list_append (ret, r_str_newf ("func.%s.args=%d", fcn->name, argc)); + rz_list_append (ret, rz_str_newf ("func.%s.args=%d", fcn->name, argc)); int i; for (i = 0; i < argc; i++) { - const char *arg = sdb_const_get (a->sdb_types, r_str_newf ("func.%s.arg.%d", fcn->name, i), 0); - r_list_append (ret, r_str_newf ("func.%s.arg.%d=\"%s\"", fcn->name, i, arg)); + const char *arg = sdb_const_get (a->sdb_types, rz_str_newf ("func.%s.arg.%d", fcn->name, i), 0); + rz_list_append (ret, rz_str_newf ("func.%s.arg.%d=\"%s\"", fcn->name, i, arg)); } } return ret; } -R_API RList *r_sign_fcn_xrefs(RAnal *a, RAnalFunction *fcn) { - RListIter *iter = NULL; - RAnalRef *refi = NULL; +RZ_API RzList *rz_sign_fcn_xrefs(RzAnal *a, RzAnalFunction *fcn) { + RzListIter *iter = NULL; + RzAnalRef *refi = NULL; - r_return_val_if_fail (a && fcn, NULL); + rz_return_val_if_fail (a && fcn, NULL); - RCore *core = a->coreb.core; + RzCore *core = a->coreb.core; if (!core) { return NULL; } - RList *ret = r_list_newf ((RListFree) free); - RList *xrefs = r_anal_function_get_xrefs (fcn); - r_list_foreach (xrefs, iter, refi) { + RzList *ret = rz_list_newf ((RzListFree) free); + RzList *xrefs = rz_anal_function_get_xrefs (fcn); + rz_list_foreach (xrefs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) { const char *flag = getRealRef (core, refi->addr); if (flag) { - r_list_append (ret, r_str_newf (flag)); + rz_list_append (ret, rz_str_newf (flag)); } } } - r_list_free (xrefs); + rz_list_free (xrefs); return ret; } -R_API RList *r_sign_fcn_refs(RAnal *a, RAnalFunction *fcn) { - RListIter *iter = NULL; - RAnalRef *refi = NULL; +RZ_API RzList *rz_sign_fcn_refs(RzAnal *a, RzAnalFunction *fcn) { + RzListIter *iter = NULL; + RzAnalRef *refi = NULL; - r_return_val_if_fail (a && fcn, NULL); + rz_return_val_if_fail (a && fcn, NULL); - RCore *core = a->coreb.core; + RzCore *core = a->coreb.core; if (!core) { return NULL; } - RList *ret = r_list_newf ((RListFree) free); - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, refi) { + RzList *ret = rz_list_newf ((RzListFree) free); + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) { const char *flag = getRealRef (core, refi->addr); if (flag) { - r_list_append (ret, r_str_newf (flag)); + rz_list_append (ret, rz_str_newf (flag)); } } } - r_list_free (refs); + rz_list_free (refs); return ret; } -static RList *zign_types_to_list(RAnal *a, const char *types) { - RList *ret = r_list_newf ((RListFree)free); +static RzList *zign_types_to_list(RzAnal *a, const char *types) { + RzList *ret = rz_list_newf ((RzListFree)free); if (!ret) { return NULL; } @@ -176,10 +176,10 @@ static RList *zign_types_to_list(RAnal *a, const char *types) { if (types[i] == '"') { quoted = !quoted; } else if ((types[i] == ',' && !quoted) || types[i] == '\0') { - token = r_str_ndup (types + prev, i - prev); + token = rz_str_ndup (types + prev, i - prev); if (token) { prev = i + 1; - r_list_append (ret, token); + rz_list_append (ret, token); token = NULL; } } @@ -188,14 +188,14 @@ static RList *zign_types_to_list(RAnal *a, const char *types) { return ret; } -static RList *do_reflike_sig(const char *token) { - RList *list = NULL; - char *scratch = r_str_new (token); - int cnt = r_str_split (scratch, ','); - if (cnt > 0 && (list = r_list_newf ((RListFree)free))) { +static RzList *do_reflike_sig(const char *token) { + RzList *list = NULL; + char *scratch = rz_str_new (token); + int cnt = rz_str_split (scratch, ','); + if (cnt > 0 && (list = rz_list_newf ((RzListFree)free))) { int i; for (i = 0; i < cnt; i++) { - r_list_append (list, r_str_new (r_str_word_get0 (scratch, i))); + rz_list_append (list, rz_str_new (rz_str_word_get0 (scratch, i))); } } free (scratch); @@ -208,41 +208,41 @@ static RList *do_reflike_sig(const char *token) { success = false; \ goto out; \ } -R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char *v) { - r_return_val_if_fail (a && it && k && v, false); +RZ_API bool rz_sign_deserialize(RzAnal *a, RzSignItem *it, const char *k, const char *v) { + rz_return_val_if_fail (a && it && k && v, false); bool success = true; - char *k2 = r_str_new (k); - char *v2 = r_str_new (v); + char *k2 = rz_str_new (k); + char *v2 = rz_str_new (v); if (!k2 || !v2) { success = false; goto out; } // Deserialize key: zign|space|name - int n = r_str_split (k2, '|'); + int n = rz_str_split (k2, '|'); if (n != 3) { eprintf ("Warning: Skipping signature with invalid key (%s)\n", k); success = false; goto out; } - if (strcmp (r_str_word_get0 (k2, 0), "zign")) { + if (strcmp (rz_str_word_get0 (k2, 0), "zign")) { eprintf ("Warning: Skipping signature with invalid value (%s)\n", k); success = false; goto out; } - it->space = r_spaces_add (&a->zign_spaces, r_str_word_get0 (k2, 1)); - it->name = r_str_new (r_str_word_get0 (k2, 2)); + it->space = rz_spaces_add (&a->zign_spaces, rz_str_word_get0 (k2, 1)); + it->name = rz_str_new (rz_str_word_get0 (k2, 2)); // remove newline at end strtok (v2, "\n"); // Deserialize value: |k:v|k:v|k:v|... - n = r_str_split (v2, '|'); + n = rz_str_split (v2, '|'); const char *token = NULL; int w, size; for (w = 0; w < n; w++) { - const char *word = r_str_word_get0 (v2, w); + const char *word = rz_str_word_get0 (v2, w); if (!word) { break; } @@ -258,7 +258,7 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char success = false; goto out; } - RSignType st = (RSignType)*word; + RzSignType st = (RzSignType)*word; switch (st) { case R_SIGN_ANAL: eprintf ("Unsupported\n"); @@ -273,10 +273,10 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char break; case R_SIGN_GRAPH: DBL_VAL_FAIL (it->graph, R_SIGN_GRAPH); - if (strlen (token) == 2 * sizeof (RSignGraph)) { - it->graph = R_NEW0 (RSignGraph); + if (strlen (token) == 2 * sizeof (RzSignGraph)) { + it->graph = R_NEW0 (RzSignGraph); if (it->graph) { - r_hex_str2bin (token, (ut8 *)it->graph); + rz_hex_str2bin (token, (ut8 *)it->graph); } } break; @@ -312,9 +312,9 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char case R_SIGN_BBHASH: DBL_VAL_FAIL (it->hash, R_SIGN_BBHASH); if (token[0] != 0) { - it->hash = R_NEW0 (RSignHash); + it->hash = R_NEW0 (RzSignHash); if (it->hash) { - it->hash->bbhash = r_str_new (token); + it->hash->bbhash = rz_str_new (token); } } break; @@ -333,7 +333,7 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char DBL_VAL_FAIL (it->bytes->bytes, R_SIGN_BYTES); it->bytes->bytes = malloc (it->bytes->size); if (it->bytes->bytes) { - r_hex_str2bin (token, it->bytes->bytes); + rz_hex_str2bin (token, it->bytes->bytes); } break; case R_SIGN_BYTES_MASK: @@ -353,14 +353,14 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char if (!it->bytes->mask) { goto out; } - r_hex_str2bin (token, it->bytes->mask); + rz_hex_str2bin (token, it->bytes->mask); break; case R_SIGN_BYTES_SIZE: // allocate size = atoi (token); if (size > 0) { DBL_VAL_FAIL (it->bytes, R_SIGN_BYTES_SIZE); - it->bytes = R_NEW0 (RSignBytes); + it->bytes = R_NEW0 (RzSignBytes); if (!it->bytes) { goto out; } @@ -379,23 +379,23 @@ out: } #undef DBL_VAL_FAIL -static void serializeKey(RAnal *a, const RSpace *space, const char* name, char *k) { +static void serializeKey(RzAnal *a, const RSpace *space, const char* name, char *k) { snprintf (k, R_SIGN_KEY_MAXSZ, "zign|%s|%s", space? space->name: "*", name); } -static void serializeKeySpaceStr(RAnal *a, const char *space, const char* name, char *k) { +static void serializeKeySpaceStr(RzAnal *a, const char *space, const char* name, char *k) { snprintf (k, R_SIGN_KEY_MAXSZ, "zign|%s|%s", space, name); } -static void serialize(RAnal *a, RSignItem *it, char *k, char *v) { - RListIter *iter = NULL; +static void serialize(RzAnal *a, RzSignItem *it, char *k, char *v) { + RzListIter *iter = NULL; char *hexbytes = NULL, *hexmask = NULL, *hexgraph = NULL; char *refs = NULL, *xrefs = NULL, *ref = NULL, *var, *vars = NULL; char *type, *types = NULL; int i = 0, len = 0; - RSignBytes *bytes = it->bytes; - RSignGraph *graph = it->graph; - RSignHash *hash = it->hash; + RzSignBytes *bytes = it->bytes; + RzSignGraph *graph = it->graph; + RzSignHash *hash = it->hash; if (k) { serializeKey (a, it->space, it->name, k); @@ -413,88 +413,88 @@ static void serialize(RAnal *a, RSignItem *it, char *k, char *v) { if (!bytes->bytes) { bytes->bytes = malloc ((bytes->size + 1) * 3); } - r_hex_bin2str (bytes->bytes, bytes->size, hexbytes); + rz_hex_bin2str (bytes->bytes, bytes->size, hexbytes); if (!bytes->mask) { bytes->mask = malloc ((bytes->size + 1) * 3); } - r_hex_bin2str (bytes->mask, bytes->size, hexmask); + rz_hex_bin2str (bytes->mask, bytes->size, hexmask); } if (graph) { - hexgraph = calloc (1, sizeof (RSignGraph) * 2 + 1); + hexgraph = calloc (1, sizeof (RzSignGraph) * 2 + 1); if (hexgraph) { - r_hex_bin2str ((ut8 *) graph, sizeof (RSignGraph), hexgraph); + rz_hex_bin2str ((ut8 *) graph, sizeof (RzSignGraph), hexgraph); } } i = 0; - r_list_foreach (it->refs, iter, ref) { + rz_list_foreach (it->refs, iter, ref) { if (i > 0) { - refs = r_str_appendch (refs, ','); + refs = rz_str_appendch (refs, ','); } - refs = r_str_append (refs, ref); + refs = rz_str_append (refs, ref); i++; } i = 0; - r_list_foreach (it->xrefs, iter, ref) { + rz_list_foreach (it->xrefs, iter, ref) { if (i > 0) { - xrefs = r_str_appendch (xrefs, ','); + xrefs = rz_str_appendch (xrefs, ','); } - xrefs = r_str_append (xrefs, ref); + xrefs = rz_str_append (xrefs, ref); i++; } i = 0; - r_list_foreach (it->vars, iter, var) { + rz_list_foreach (it->vars, iter, var) { if (i > 0) { - vars = r_str_appendch (vars, ','); + vars = rz_str_appendch (vars, ','); } - vars = r_str_append (vars, var); + vars = rz_str_append (vars, var); i++; } i = 0; - r_list_foreach (it->types, iter, type) { + rz_list_foreach (it->types, iter, type) { if (i > 0) { - types = r_str_appendch (types, ','); + types = rz_str_appendch (types, ','); } - types = r_str_append (types, type); + types = rz_str_append (types, type); i++; } - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); if (bytes) { - // TODO: do not hardcoded s,b,m here, use RSignType enum - r_strbuf_appendf (sb, "|s:%d|b:%s|m:%s", bytes->size, hexbytes, hexmask); + // TODO: do not hardcoded s,b,m here, use RzSignType enum + rz_strbuf_appendf (sb, "|s:%d|b:%s|m:%s", bytes->size, hexbytes, hexmask); } if (it->addr != UT64_MAX) { - r_strbuf_appendf (sb, "|%c:%"PFMT64d, R_SIGN_OFFSET, it->addr); + rz_strbuf_appendf (sb, "|%c:%"PFMT64d, R_SIGN_OFFSET, it->addr); } if (graph) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_GRAPH, hexgraph); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_GRAPH, hexgraph); } if (refs) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_REFS, refs); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_REFS, refs); } if (xrefs) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_XREFS, xrefs); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_XREFS, xrefs); } if (vars) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_VARS, vars); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_VARS, vars); } if (types) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_TYPES, types); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_TYPES, types); } if (it->comment) { // b64 encoded - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_COMMENT, it->comment); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_COMMENT, it->comment); } if (it->realname) { // b64 encoded - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_NAME, it->realname); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_NAME, it->realname); } if (hash && hash->bbhash) { - r_strbuf_appendf (sb, "|%c:%s", R_SIGN_BBHASH, hash->bbhash); + rz_strbuf_appendf (sb, "|%c:%s", R_SIGN_BBHASH, hash->bbhash); } - if (r_strbuf_length (sb) >= R_SIGN_VAL_MAXSZ) { + if (rz_strbuf_length (sb) >= R_SIGN_VAL_MAXSZ) { eprintf ("Signature limit reached for 0x%08"PFMT64x" (%s)\n", it->addr, it->name); } - char *res = r_strbuf_drain (sb); + char *res = rz_strbuf_drain (sb); if (res) { strncpy (v, res, R_SIGN_VAL_MAXSZ); free (res); @@ -510,8 +510,8 @@ static void serialize(RAnal *a, RSignItem *it, char *k, char *v) { } } -static RList *deserialize_sign_space(RAnal *a, RSpace *space) { - r_return_val_if_fail (a && space, NULL); +static RzList *deserialize_sign_space(RzAnal *a, RSpace *space) { + rz_return_val_if_fail (a && space, NULL); char k[R_SIGN_KEY_MAXSZ]; serializeKey (a, space, "", k); @@ -519,19 +519,19 @@ static RList *deserialize_sign_space(RAnal *a, RSpace *space) { SdbListIter *iter; SdbKv *kv; - RList *ret = r_list_newf ((RListFree)r_sign_item_free); + RzList *ret = rz_list_newf ((RzListFree)rz_sign_item_free); if (!ret) { goto beach; } ls_foreach (zigns, iter, kv) { - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { goto beach; } - if (r_sign_deserialize (a, it, kv->base.key, kv->base.value)) { - r_list_append (ret, it); + if (rz_sign_deserialize (a, it, kv->base.key, kv->base.value)) { + rz_list_append (ret, it); } else { - r_sign_item_free (it); + rz_sign_item_free (it); } } @@ -540,17 +540,17 @@ static RList *deserialize_sign_space(RAnal *a, RSpace *space) { beach: ls_free (zigns); - r_list_free (ret); + rz_list_free (ret); return NULL; } -static void mergeItem(RSignItem *dst, RSignItem *src) { - RListIter *iter = NULL; +static void mergeItem(RzSignItem *dst, RzSignItem *src) { + RzListIter *iter = NULL; char *ref, *var, *type; if (src->bytes) { - r_sign_bytes_free (dst->bytes); - dst->bytes = R_NEW0 (RSignBytes); + rz_sign_bytes_free (dst->bytes); + dst->bytes = R_NEW0 (RzSignBytes); if (!dst->bytes) { return; } @@ -558,13 +558,13 @@ static void mergeItem(RSignItem *dst, RSignItem *src) { dst->bytes->size = src->bytes->size; dst->bytes->bytes = malloc (src->bytes->size); if (!dst->bytes->bytes) { - r_sign_bytes_free (dst->bytes); + rz_sign_bytes_free (dst->bytes); return; } memcpy (dst->bytes->bytes, src->bytes->bytes, src->bytes->size); dst->bytes->mask = malloc (src->bytes->size); if (!dst->bytes->mask) { - r_sign_bytes_free (dst->bytes); + rz_sign_bytes_free (dst->bytes); return; } memcpy (dst->bytes->mask, src->bytes->mask, src->bytes->size); @@ -572,7 +572,7 @@ static void mergeItem(RSignItem *dst, RSignItem *src) { if (src->graph) { free (dst->graph); - dst->graph = R_NEW0 (RSignGraph); + dst->graph = R_NEW0 (RzSignGraph); if (!dst->graph) { return; } @@ -592,35 +592,35 @@ static void mergeItem(RSignItem *dst, RSignItem *src) { } if (src->refs) { - r_list_free (dst->refs); + rz_list_free (dst->refs); - dst->refs = r_list_newf ((RListFree)free); - r_list_foreach (src->refs, iter, ref) { - r_list_append (dst->refs, r_str_new (ref)); + dst->refs = rz_list_newf ((RzListFree)free); + rz_list_foreach (src->refs, iter, ref) { + rz_list_append (dst->refs, rz_str_new (ref)); } } if (src->vars) { - r_list_free (dst->vars); + rz_list_free (dst->vars); - dst->vars = r_list_newf ((RListFree)free); - r_list_foreach (src->vars, iter, var) { - r_list_append (dst->vars, r_str_new (var)); + dst->vars = rz_list_newf ((RzListFree)free); + rz_list_foreach (src->vars, iter, var) { + rz_list_append (dst->vars, rz_str_new (var)); } } if (src->types) { - r_list_free (dst->types); + rz_list_free (dst->types); - dst->types = r_list_newf ((RListFree)free); - r_list_foreach (src->types, iter, type) { - r_list_append (dst->types, r_str_new (type)); + dst->types = rz_list_newf ((RzListFree)free); + rz_list_foreach (src->types, iter, type) { + rz_list_append (dst->types, rz_str_new (type)); } } if (src->hash) { if (!dst->hash) { - dst->hash = R_NEW0 (RSignHash); + dst->hash = R_NEW0 (RzSignHash); if (!dst->hash) { return; } @@ -631,30 +631,30 @@ static void mergeItem(RSignItem *dst, RSignItem *src) { } } -R_API RSignItem *r_sign_get_item(RAnal *a, const char *name) { +RZ_API RzSignItem *rz_sign_get_item(RzAnal *a, const char *name) { char k[R_SIGN_KEY_MAXSZ]; - serializeKey (a, r_spaces_current (&a->zign_spaces), name, k); + serializeKey (a, rz_spaces_current (&a->zign_spaces), name, k); const char *v = sdb_const_get (a->sdb_zigns, k, 0); if (!v) { return NULL; } - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return NULL; } - if (!r_sign_deserialize (a, it, k, v)) { - r_sign_item_free (it); + if (!rz_sign_deserialize (a, it, k, v)) { + rz_sign_item_free (it); return NULL; } return it; } -R_API bool r_sign_add_item(RAnal *a, RSignItem *it) { +RZ_API bool rz_sign_add_item(RzAnal *a, RzSignItem *it) { char key[R_SIGN_KEY_MAXSZ], val[R_SIGN_VAL_MAXSZ]; const char *curval = NULL; bool retval = true; - RSignItem *curit = r_sign_item_new (); + RzSignItem *curit = rz_sign_item_new (); if (!curit) { return false; } @@ -662,7 +662,7 @@ R_API bool r_sign_add_item(RAnal *a, RSignItem *it) { serialize (a, it, key, val); curval = sdb_const_get (a->sdb_zigns, key, 0); if (curval) { - if (!r_sign_deserialize (a, curit, key, curval)) { + if (!rz_sign_deserialize (a, curit, key, curval)) { eprintf ("error: cannot deserialize zign\n"); retval = false; goto out; @@ -673,81 +673,81 @@ R_API bool r_sign_add_item(RAnal *a, RSignItem *it) { sdb_set (a->sdb_zigns, key, val, 0); out: - r_sign_item_free (curit); + rz_sign_item_free (curit); return retval; } -static bool addHash(RAnal *a, const char *name, int type, const char *val) { - RSignItem *it = r_sign_item_new (); +static bool addHash(RzAnal *a, const char *name, int type, const char *val) { + RzSignItem *it = rz_sign_item_new (); if (!it) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } - it->hash = R_NEW0 (RSignHash); + it->hash = R_NEW0 (RzSignHash); if (!it->hash) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); + it->space = rz_spaces_current (&a->zign_spaces); bool retval = false; switch (type) { case R_SIGN_BBHASH: it->hash->bbhash = strdup (val); - retval = r_sign_add_item (a, it); - r_sign_item_free (it); + retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); break; } return retval; } -static bool addBBHash(RAnal *a, RAnalFunction *fcn, const char *name) { +static bool addBBHash(RzAnal *a, RzAnalFunction *fcn, const char *name) { bool retval = false; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { goto beach; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { goto beach; } - it->space = r_spaces_current (&a->zign_spaces); + it->space = rz_spaces_current (&a->zign_spaces); - if (r_sign_addto_item (a, it, fcn, R_SIGN_BBHASH)) { - retval = r_sign_add_item (a, it); + if (rz_sign_addto_item (a, it, fcn, R_SIGN_BBHASH)) { + retval = rz_sign_add_item (a, it); } beach: - r_sign_item_free (it); + rz_sign_item_free (it); return retval; } -static bool addBytes(RAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask) { +static bool addBytes(RzAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask) { bool retval = true; - if (r_mem_is_zero (mask, size)) { + if (rz_mem_is_zero (mask, size)) { eprintf ("error: zero mask\n"); return false; } - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->bytes = R_NEW0 (RSignBytes); + it->space = rz_spaces_current (&a->zign_spaces); + it->bytes = R_NEW0 (RzSignBytes); if (!it->bytes) { goto fail; } @@ -762,25 +762,25 @@ static bool addBytes(RAnal *a, const char *name, ut64 size, const ut8 *bytes, co goto fail; } memcpy (it->bytes->mask, mask, size); - retval = r_sign_add_item (a, it); - r_sign_item_free (it); + retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; fail: if (it) { free (it->name); - r_sign_bytes_free (it->bytes); + rz_sign_bytes_free (it->bytes); } free (it); return false; } -R_API bool r_sign_add_hash(RAnal *a, const char *name, int type, const char *val, int len) { - r_return_val_if_fail (a && name && type && val && len > 0, false); +RZ_API bool rz_sign_add_hash(RzAnal *a, const char *name, int type, const char *val, int len) { + rz_return_val_if_fail (a && name && type && val && len > 0, false); if (type != R_SIGN_BBHASH) { eprintf ("error: hash type unknown"); return false; } - int digestsize = r_hash_size (R_ZIGN_HASH) * 2; + int digestsize = rz_hash_size (R_ZIGN_HASH) * 2; if (len != digestsize) { eprintf ("error: invalid hash size: %d (%s digest size is %d)\n", len, ZIGN_HASH, digestsize); return false; @@ -788,20 +788,20 @@ R_API bool r_sign_add_hash(RAnal *a, const char *name, int type, const char *val return addHash (a, name, type, val); } -R_API bool r_sign_add_bb_hash(RAnal *a, RAnalFunction *fcn, const char *name) { - r_return_val_if_fail (a && fcn && name, false); +RZ_API bool rz_sign_add_bb_hash(RzAnal *a, RzAnalFunction *fcn, const char *name) { + rz_return_val_if_fail (a && fcn && name, false); return addBBHash (a, fcn, name); } -R_API bool r_sign_add_bytes(RAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask) { - r_return_val_if_fail (a && name && size > 0 && bytes && mask, false); +RZ_API bool rz_sign_add_bytes(RzAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask) { + rz_return_val_if_fail (a && name && size > 0 && bytes && mask, false); return addBytes (a, name, size, bytes, mask); } -R_API bool r_sign_add_anal(RAnal *a, const char *name, ut64 size, const ut8 *bytes, ut64 at) { +RZ_API bool rz_sign_add_anal(RzAnal *a, const char *name, ut64 size, const ut8 *bytes, ut64 at) { bool retval = false; - r_return_val_if_fail (a && name && size > 0 && bytes, false); - ut8 *mask = r_anal_mask (a, size, bytes, at); + rz_return_val_if_fail (a && name && size > 0 && bytes, false); + ut8 *mask = rz_anal_mask (a, size, bytes, at); if (mask) { retval = addBytes (a, name, size, bytes, mask); free (mask); @@ -809,21 +809,21 @@ R_API bool r_sign_add_anal(RAnal *a, const char *name, ut64 size, const ut8 *byt return retval; } -static RSignGraph *r_sign_fcn_graph(RAnalFunction *fcn) { - r_return_val_if_fail (fcn, false); - RSignGraph *graph = R_NEW0 (RSignGraph); +static RzSignGraph *rz_sign_fcn_graph(RzAnalFunction *fcn) { + rz_return_val_if_fail (fcn, false); + RzSignGraph *graph = R_NEW0 (RzSignGraph); if (graph) { - graph->cc = r_anal_function_complexity (fcn), - graph->nbbs = r_list_length (fcn->bbs); - graph->edges = r_anal_function_count_edges (fcn, &graph->ebbs); - graph->bbsum = r_anal_function_realsize (fcn); + graph->cc = rz_anal_function_complexity (fcn), + graph->nbbs = rz_list_length (fcn->bbs); + graph->edges = rz_anal_function_count_edges (fcn, &graph->ebbs); + graph->bbsum = rz_anal_function_realsize (fcn); } return graph; } static int bb_sort_by_addr(const void *x, const void *y) { - RAnalBlock *a = (RAnalBlock *)x; - RAnalBlock *b = (RAnalBlock *)y; + RzAnalBlock *a = (RzAnalBlock *)x; + RzAnalBlock *b = (RzAnalBlock *)y; if (a->addr > b->addr) { return 1; } @@ -833,19 +833,19 @@ static int bb_sort_by_addr(const void *x, const void *y) { return 0; } -static RSignBytes *r_sign_fcn_bytes(RAnal *a, RAnalFunction *fcn) { - r_return_val_if_fail (a && fcn && fcn->bbs && fcn->bbs->head, false); +static RzSignBytes *rz_sign_fcn_bytes(RzAnal *a, RzAnalFunction *fcn) { + rz_return_val_if_fail (a && fcn && fcn->bbs && fcn->bbs->head, false); // get size - RCore *core = a->coreb.core; + RzCore *core = a->coreb.core; int maxsz = a->coreb.cfggeti (core, "zign.maxsz"); - r_list_sort (fcn->bbs, &bb_sort_by_addr); + rz_list_sort (fcn->bbs, &bb_sort_by_addr); ut64 ea = fcn->addr; - RAnalBlock *bb = (RAnalBlock *)fcn->bbs->tail->data; + RzAnalBlock *bb = (RzAnalBlock *)fcn->bbs->tail->data; int size = R_MIN (bb->addr + bb->size - ea, maxsz); // alloc space for signature - RSignBytes *sig = R_NEW0 (RSignBytes); + RzSignBytes *sig = R_NEW0 (RzSignBytes); if (!sig) { goto bytes_failed; } @@ -865,8 +865,8 @@ static RSignBytes *r_sign_fcn_bytes(RAnal *a, RAnalFunction *fcn) { } ut8 *tmpmask = NULL; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, bb) { + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr >= ea) { ut64 delta = bb->addr - ea; ut64 rsize = bb->size; @@ -880,7 +880,7 @@ static RSignBytes *r_sign_fcn_bytes(RAnal *a, RAnalFunction *fcn) { } // get mask for block - if (!(tmpmask = r_anal_mask (a, rsize, sig->bytes + delta, ea))) { + if (!(tmpmask = rz_anal_mask (a, rsize, sig->bytes + delta, ea))) { goto bytes_failed; } memcpy (sig->mask + delta, tmpmask, rsize); @@ -890,18 +890,18 @@ static RSignBytes *r_sign_fcn_bytes(RAnal *a, RAnalFunction *fcn) { return sig; bytes_failed: - r_sign_bytes_free (sig); + rz_sign_bytes_free (sig); return NULL; } -static RSignHash *r_sign_fcn_bbhash(RAnal *a, RAnalFunction *fcn) { - r_return_val_if_fail (a && fcn, NULL); - RSignHash *hash = R_NEW0 (RSignHash); +static RzSignHash *rz_sign_fcn_bbhash(RzAnal *a, RzAnalFunction *fcn) { + rz_return_val_if_fail (a && fcn, NULL); + RzSignHash *hash = R_NEW0 (RzSignHash); if (!hash) { return NULL; } - char *digest_hex = r_sign_calc_bbhash (a, fcn); + char *digest_hex = rz_sign_calc_bbhash (a, fcn); if (!digest_hex) { free (hash); return NULL; @@ -910,23 +910,23 @@ static RSignHash *r_sign_fcn_bbhash(RAnal *a, RAnalFunction *fcn) { return hash; } -R_API bool r_sign_addto_item(RAnal *a, RSignItem *it, RAnalFunction *fcn, RSignType type) { - r_return_val_if_fail (a && it && fcn, false); +RZ_API bool rz_sign_addto_item(RzAnal *a, RzSignItem *it, RzAnalFunction *fcn, RzSignType type) { + rz_return_val_if_fail (a && it && fcn, false); switch (type) { case R_SIGN_GRAPH: - return !it->graph && (it->graph = r_sign_fcn_graph (fcn)); + return !it->graph && (it->graph = rz_sign_fcn_graph (fcn)); case R_SIGN_BYTES: - return !it->bytes && (it->bytes = r_sign_fcn_bytes (a, fcn)); + return !it->bytes && (it->bytes = rz_sign_fcn_bytes (a, fcn)); case R_SIGN_XREFS: - return !it->xrefs && (it->xrefs = r_sign_fcn_xrefs (a, fcn)); + return !it->xrefs && (it->xrefs = rz_sign_fcn_xrefs (a, fcn)); case R_SIGN_REFS: - return !it->refs && (it->refs = r_sign_fcn_refs (a, fcn)); + return !it->refs && (it->refs = rz_sign_fcn_refs (a, fcn)); case R_SIGN_VARS: - return !it->vars && (it->vars = r_sign_fcn_vars (a, fcn)); + return !it->vars && (it->vars = rz_sign_fcn_vars (a, fcn)); case R_SIGN_TYPES: - return !it->types && (it->types = r_sign_fcn_types (a, fcn)); + return !it->types && (it->types = rz_sign_fcn_types (a, fcn)); case R_SIGN_BBHASH: - return !it->hash && (it->hash = r_sign_fcn_bbhash (a, fcn)); + return !it->hash && (it->hash = rz_sign_fcn_bbhash (a, fcn)); case R_SIGN_OFFSET: it->addr = fcn->addr; return true; @@ -945,183 +945,183 @@ R_API bool r_sign_addto_item(RAnal *a, RSignItem *it, RAnalFunction *fcn, RSignT return false; } -R_API bool r_sign_add_graph(RAnal *a, const char *name, RSignGraph graph) { - r_return_val_if_fail (a && !R_STR_ISEMPTY (name), false); +RZ_API bool rz_sign_add_graph(RzAnal *a, const char *name, RzSignGraph graph) { + rz_return_val_if_fail (a && !R_STR_ISEMPTY (name), false); bool retval = true; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->graph = R_NEW0 (RSignGraph); + it->space = rz_spaces_current (&a->zign_spaces); + it->graph = R_NEW0 (RzSignGraph); if (!it->graph) { free (it->name); free (it); return false; } *it->graph = graph; - retval = r_sign_add_item (a, it); - r_sign_item_free (it); + retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_comment(RAnal *a, const char *name, const char *comment) { - r_return_val_if_fail (a && name && comment, false); +RZ_API bool rz_sign_add_comment(RzAnal *a, const char *name, const char *comment) { + rz_return_val_if_fail (a && name && comment, false); - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); - it->space = r_spaces_current (&a->zign_spaces); + it->name = rz_str_new (name); + it->space = rz_spaces_current (&a->zign_spaces); it->comment = strdup (comment); - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_name(RAnal *a, const char *name, const char *realname) { - r_return_val_if_fail (a && name && realname, false); - RSignItem *it = r_sign_item_new (); +RZ_API bool rz_sign_add_name(RzAnal *a, const char *name, const char *realname) { + rz_return_val_if_fail (a && name && realname, false); + RzSignItem *it = rz_sign_item_new (); if (it) { - it->name = r_str_new (name); + it->name = rz_str_new (name); it->realname = strdup (realname); - it->space = r_spaces_current (&a->zign_spaces); - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + it->space = rz_spaces_current (&a->zign_spaces); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } return false; } -R_API bool r_sign_add_addr(RAnal *a, const char *name, ut64 addr) { - r_return_val_if_fail (a && name && addr != UT64_MAX, false); +RZ_API bool rz_sign_add_addr(RzAnal *a, const char *name, ut64 addr) { + rz_return_val_if_fail (a && name && addr != UT64_MAX, false); - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return NULL; } - it->name = r_str_new (name); - it->space = r_spaces_current (&a->zign_spaces); + it->name = rz_str_new (name); + it->space = rz_spaces_current (&a->zign_spaces); it->addr = addr; - bool retval = r_sign_add_item (a, it); + bool retval = rz_sign_add_item (a, it); - r_sign_item_free (it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_vars(RAnal *a, const char *name, RList *vars) { - r_return_val_if_fail (a && name && vars, false); +RZ_API bool rz_sign_add_vars(RzAnal *a, const char *name, RzList *vars) { + rz_return_val_if_fail (a && name && vars, false); - RListIter *iter; + RzListIter *iter; char *var; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->vars = r_list_newf ((RListFree)free); - r_list_foreach (vars, iter, var) { - r_list_append (it->vars, strdup (var)); + it->space = rz_spaces_current (&a->zign_spaces); + it->vars = rz_list_newf ((RzListFree)free); + rz_list_foreach (vars, iter, var) { + rz_list_append (it->vars, strdup (var)); } - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_types(RAnal *a, const char *name, RList *types) { - r_return_val_if_fail (a && name && types, false); +RZ_API bool rz_sign_add_types(RzAnal *a, const char *name, RzList *types) { + rz_return_val_if_fail (a && name && types, false); - RListIter *iter; + RzListIter *iter; char *type; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->types = r_list_newf ((RListFree) free); - r_list_foreach (types, iter, type) { - r_list_append (it->types, strdup (type)); + it->space = rz_spaces_current (&a->zign_spaces); + it->types = rz_list_newf ((RzListFree) free); + rz_list_foreach (types, iter, type) { + rz_list_append (it->types, strdup (type)); } - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_refs(RAnal *a, const char *name, RList *refs) { - r_return_val_if_fail (a && name && refs, false); +RZ_API bool rz_sign_add_refs(RzAnal *a, const char *name, RzList *refs) { + rz_return_val_if_fail (a && name && refs, false); char *ref; - RListIter *iter; - RSignItem *it = r_sign_item_new (); + RzListIter *iter; + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->refs = r_list_newf ((RListFree) free); - r_list_foreach (refs, iter, ref) { - r_list_append (it->refs, strdup (ref)); + it->space = rz_spaces_current (&a->zign_spaces); + it->refs = rz_list_newf ((RzListFree) free); + rz_list_foreach (refs, iter, ref) { + rz_list_append (it->refs, strdup (ref)); } - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } -R_API bool r_sign_add_xrefs(RAnal *a, const char *name, RList *xrefs) { - r_return_val_if_fail (a && name && xrefs, false); +RZ_API bool rz_sign_add_xrefs(RzAnal *a, const char *name, RzList *xrefs) { + rz_return_val_if_fail (a && name && xrefs, false); - RListIter *iter = NULL; + RzListIter *iter = NULL; char *ref = NULL; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - it->name = r_str_new (name); + it->name = rz_str_new (name); if (!it->name) { free (it); return false; } - it->space = r_spaces_current (&a->zign_spaces); - it->xrefs = r_list_newf ((RListFree) free); - r_list_foreach (xrefs, iter, ref) { - r_list_append (it->xrefs, strdup (ref)); + it->space = rz_spaces_current (&a->zign_spaces); + it->xrefs = rz_list_newf ((RzListFree) free); + rz_list_foreach (xrefs, iter, ref) { + rz_list_append (it->xrefs, strdup (ref)); } - bool retval = r_sign_add_item (a, it); - r_sign_item_free (it); + bool retval = rz_sign_add_item (a, it); + rz_sign_item_free (it); return retval; } struct ctxDeleteCB { - RAnal *anal; + RzAnal *anal; char buf[R_SIGN_KEY_MAXSZ]; }; @@ -1133,7 +1133,7 @@ static bool deleteBySpaceCB(void *user, const char *k, const char *v) { return true; } -R_API bool r_sign_delete(RAnal *a, const char *name) { +RZ_API bool rz_sign_delete(RzAnal *a, const char *name) { struct ctxDeleteCB ctx = {0}; char k[R_SIGN_KEY_MAXSZ]; @@ -1142,22 +1142,22 @@ R_API bool r_sign_delete(RAnal *a, const char *name) { } // Remove all zigns if (*name == '*') { - if (!r_spaces_current (&a->zign_spaces)) { + if (!rz_spaces_current (&a->zign_spaces)) { sdb_reset (a->sdb_zigns); return true; } ctx.anal = a; - serializeKey (a, r_spaces_current (&a->zign_spaces), "", ctx.buf); + serializeKey (a, rz_spaces_current (&a->zign_spaces), "", ctx.buf); sdb_foreach (a->sdb_zigns, deleteBySpaceCB, &ctx); return true; } // Remove specific zign - serializeKey (a, r_spaces_current (&a->zign_spaces), name, k); + serializeKey (a, rz_spaces_current (&a->zign_spaces), name, k); return sdb_remove (a->sdb_zigns, k, 0); } -static ut8 * build_combined_bytes(RSignBytes *bsig) { - r_return_val_if_fail (bsig && bsig->bytes && bsig->mask, NULL); +static ut8 * build_combined_bytes(RzSignBytes *bsig) { + rz_return_val_if_fail (bsig && bsig->bytes && bsig->mask, NULL); ut8 *buf = (ut8 *)malloc (bsig->size); if (buf) { size_t i; @@ -1168,18 +1168,18 @@ static ut8 * build_combined_bytes(RSignBytes *bsig) { return buf; } -static double cmp_bytesig_to_buff(RSignBytes *sig, ut8 *buf, int len) { - r_return_val_if_fail (sig && buf && len >= 0, (double)-1.0); +static double cmp_bytesig_to_buff(RzSignBytes *sig, ut8 *buf, int len) { + rz_return_val_if_fail (sig && buf && len >= 0, (double)-1.0); ut8 *sigbuf = build_combined_bytes (sig); double sim = -1.0; if (sigbuf) { - r_diff_buffers_distance (NULL, sigbuf, sig->size, buf, len, NULL, &sim); + rz_diff_buffers_distance (NULL, sigbuf, sig->size, buf, len, NULL, &sim); free (sigbuf); } return sim; } -static double matchBytes(RSignItem *a, RSignItem *b) { +static double matchBytes(RzSignItem *a, RzSignItem *b) { double result = 0.0; if (!a->bytes || !b->bytes) { @@ -1206,7 +1206,7 @@ static double matchBytes(RSignItem *a, RSignItem *b) { } } - if ((combined_mask && !r_mem_cmp_mask (a->bytes->bytes, b->bytes->bytes, combined_mask, min_size)) || + if ((combined_mask && !rz_mem_cmp_mask (a->bytes->bytes, b->bytes->bytes, combined_mask, min_size)) || (!combined_mask && !memcmp (a->bytes->bytes, b->bytes->bytes, min_size))) { result = (double)min_size / (double)R_MAX (a->bytes->size, b->bytes->size); } @@ -1219,7 +1219,7 @@ static double matchBytes(RSignItem *a, RSignItem *b) { #define SIMILARITY(a, b) \ ((a) == (b)? 1.0: (R_MAX ((a), (b)) == 0.0? 0.0: (double)R_MIN ((a), (b)) / (double)R_MAX ((a), (b)))) -static double matchGraph(RSignItem *a, RSignItem *b) { +static double matchGraph(RzSignItem *a, RzSignItem *b) { if (!a->graph || !b->graph) { return 0.0; } @@ -1236,8 +1236,8 @@ static double matchGraph(RSignItem *a, RSignItem *b) { } static int score_cmpr(const void *a, const void *b) { - double sa = ((RSignCloseMatch *)a)->score; - double sb = ((RSignCloseMatch *)b)->score; + double sa = ((RzSignCloseMatch *)a)->score; + double sb = ((RzSignCloseMatch *)b)->score; if (sa < sb) { return 1; @@ -1249,8 +1249,8 @@ static int score_cmpr(const void *a, const void *b) { } typedef struct { - RSignItem *test; - RList *output; + RzSignItem *test; + RzList *output; size_t count; double score_threshold; ut8 *bytes_combined; @@ -1259,7 +1259,7 @@ typedef struct { double infimum; } ClosestMatchData; -static bool closest_match_update(ClosestMatchData *data, RSignItem *it) { +static bool closest_match_update(ClosestMatchData *data, RzSignItem *it) { // quantify how close the signature matches int div = 0; double score = 0.0; @@ -1270,7 +1270,7 @@ static bool closest_match_update(ClosestMatchData *data, RSignItem *it) { div++; } double bscore = -1.0; - bool list_full = (r_list_length (data->output) == data->count); + bool list_full = (rz_list_length (data->output) == data->count); // value to beat to enter the list double pivot = data->score_threshold; @@ -1290,7 +1290,7 @@ static bool closest_match_update(ClosestMatchData *data, RSignItem *it) { maxscore = (maxscore + score) / div; } if (maxscore < pivot) { - r_sign_item_free (it); + rz_sign_item_free (it); return true; } } @@ -1301,35 +1301,35 @@ static bool closest_match_update(ClosestMatchData *data, RSignItem *it) { div++; } if (div == 0) { - r_sign_item_free (it); + rz_sign_item_free (it); return true; } score /= div; // score is too low, don't bother doing any more work if (score < pivot) { - r_sign_item_free (it); + rz_sign_item_free (it); return true; } // add new element - RSignCloseMatch *row = R_NEW (RSignCloseMatch); + RzSignCloseMatch *row = R_NEW (RzSignCloseMatch); if (!row) { - r_sign_item_free (it); + rz_sign_item_free (it); return false; } row->score = score; row->gscore = gscore; row->bscore = bscore; row->item = it; - r_list_add_sorted (data->output, (void *)row, &score_cmpr); + rz_list_add_sorted (data->output, (void *)row, &score_cmpr); if (list_full) { // remove smallest element - r_sign_close_match_free (r_list_pop (data->output)); + rz_sign_close_match_free (rz_list_pop (data->output)); // get new infimum - row = r_list_get_top (data->output); + row = rz_list_get_top (data->output); data->infimum = row->score; } return true; @@ -1339,33 +1339,33 @@ static bool closest_match_callback(void *a, const char *name, const char *value) ClosestMatchData *data = (ClosestMatchData *)a; // get signature in usable format - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { return false; } - if (!r_sign_deserialize (a, it, name, value)) { - r_sign_item_free (it); + if (!rz_sign_deserialize (a, it, name, value)) { + rz_sign_item_free (it); return false; } return closest_match_update (data, it); } -R_API void r_sign_close_match_free(RSignCloseMatch *match) { +RZ_API void rz_sign_close_match_free(RzSignCloseMatch *match) { if (match) { - r_sign_item_free (match->item); + rz_sign_item_free (match->item); free (match); } } -R_API RList *r_sign_find_closest_sig(RAnal *a, RSignItem *it, int count, double score_threshold) { - r_return_val_if_fail (a && it && count > 0 && score_threshold >= 0 && score_threshold <= 1, NULL); +RZ_API RzList *rz_sign_find_closest_sig(RzAnal *a, RzSignItem *it, int count, double score_threshold) { + rz_return_val_if_fail (a && it && count > 0 && score_threshold >= 0 && score_threshold <= 1, NULL); // need at least one acceptable signature type - r_return_val_if_fail (it->bytes || it->graph, NULL); + rz_return_val_if_fail (it->bytes || it->graph, NULL); ClosestMatchData data; - RList *output = r_list_newf ((RListFree)r_sign_close_match_free); + RzList *output = rz_list_newf ((RzListFree)rz_sign_close_match_free); if (!output) { return NULL; } @@ -1383,7 +1383,7 @@ R_API RList *r_sign_find_closest_sig(RAnal *a, RSignItem *it, int count, double // TODO: handle sign spaces if (!sdb_foreach (a->sdb_zigns, &closest_match_callback, (void *)&data)) { - r_list_free (output); + rz_list_free (output); output = NULL; } @@ -1391,11 +1391,11 @@ R_API RList *r_sign_find_closest_sig(RAnal *a, RSignItem *it, int count, double return output; } -R_API RList *r_sign_find_closest_fcn(RAnal *a, RSignItem *it, int count, double score_threshold) { - r_return_val_if_fail (a && it && count > 0 && score_threshold >= 0 && score_threshold <= 1, NULL); - r_return_val_if_fail (it->bytes || it->graph, NULL); +RZ_API RzList *rz_sign_find_closest_fcn(RzAnal *a, RzSignItem *it, int count, double score_threshold) { + rz_return_val_if_fail (a && it && count > 0 && score_threshold >= 0 && score_threshold <= 1, NULL); + rz_return_val_if_fail (it->bytes || it->graph, NULL); - RList *output = r_list_newf ((RListFree)r_sign_close_match_free); + RzList *output = rz_list_newf ((RzListFree)rz_sign_close_match_free); if (!output) { return NULL; } @@ -1412,23 +1412,23 @@ R_API RList *r_sign_find_closest_fcn(RAnal *a, RSignItem *it, int count, double data.bytes_combined = NULL; } - RAnalFunction *fcn; - RListIter *iter; - r_list_foreach (a->fcns, iter, fcn) { + RzAnalFunction *fcn; + RzListIter *iter; + rz_list_foreach (a->fcns, iter, fcn) { // turn function into signature item - RSignItem *fsig = r_sign_item_new (); + RzSignItem *fsig = rz_sign_item_new (); if (!fsig) { - r_list_free (output); + rz_list_free (output); return NULL; } if (data.bytes_combined) { - r_sign_addto_item (a, fsig, fcn, R_SIGN_BYTES); + rz_sign_addto_item (a, fsig, fcn, R_SIGN_BYTES); } if (it->graph) { - r_sign_addto_item (a, fsig, fcn, R_SIGN_GRAPH); + rz_sign_addto_item (a, fsig, fcn, R_SIGN_GRAPH); } - r_sign_addto_item (a, fsig, fcn, R_SIGN_OFFSET); - fsig->name = r_str_new (fcn->name); + rz_sign_addto_item (a, fsig, fcn, R_SIGN_OFFSET); + fsig->name = rz_str_new (fcn->name); // maybe add signature item to output list closest_match_update (&data, fsig); @@ -1437,41 +1437,41 @@ R_API RList *r_sign_find_closest_fcn(RAnal *a, RSignItem *it, int count, double return output; } -R_API bool r_sign_diff(RAnal *a, RSignOptions *options, const char *other_space_name) { - r_return_val_if_fail (a && other_space_name, false); +RZ_API bool rz_sign_diff(RzAnal *a, RzSignOptions *options, const char *other_space_name) { + rz_return_val_if_fail (a && other_space_name, false); - RSpace *current_space = r_spaces_current (&a->zign_spaces); + RSpace *current_space = rz_spaces_current (&a->zign_spaces); if (!current_space) { return false; } - RSpace *other_space = r_spaces_get (&a->zign_spaces, other_space_name); + RSpace *other_space = rz_spaces_get (&a->zign_spaces, other_space_name); if (!other_space) { return false; } - RList *la = deserialize_sign_space (a, current_space); + RzList *la = deserialize_sign_space (a, current_space); if (!la) { return false; } - RList *lb = deserialize_sign_space (a, other_space); + RzList *lb = deserialize_sign_space (a, other_space); if (!lb) { - r_list_free (la); + rz_list_free (la); return false; } eprintf ("Diff %d %d\n", (int)ls_length (la), (int)ls_length (lb)); - RListIter *itr; - RListIter *itr2; - RSignItem *si; - RSignItem *si2; + RzListIter *itr; + RzListIter *itr2; + RzSignItem *si; + RzSignItem *si2; // do the sign diff here - r_list_foreach (la, itr, si) { + rz_list_foreach (la, itr, si) { if (strstr (si->name, "imp.")) { continue; } - r_list_foreach (lb, itr2, si2) { + rz_list_foreach (lb, itr2, si2) { if (strstr (si2->name, "imp.")) { continue; } @@ -1490,46 +1490,46 @@ R_API bool r_sign_diff(RAnal *a, RSignOptions *options, const char *other_space_ } } - r_list_free (la); - r_list_free (lb); + rz_list_free (la); + rz_list_free (lb); return true; } -R_API bool r_sign_diff_by_name(RAnal *a, RSignOptions *options, const char *other_space_name, bool not_matching) { - r_return_val_if_fail (a && other_space_name, false); +RZ_API bool rz_sign_diff_by_name(RzAnal *a, RzSignOptions *options, const char *other_space_name, bool not_matching) { + rz_return_val_if_fail (a && other_space_name, false); - RSpace *current_space = r_spaces_current (&a->zign_spaces); + RSpace *current_space = rz_spaces_current (&a->zign_spaces); if (!current_space) { return false; } - RSpace *other_space = r_spaces_get (&a->zign_spaces, other_space_name); + RSpace *other_space = rz_spaces_get (&a->zign_spaces, other_space_name); if (!other_space) { return false; } - RList *la = deserialize_sign_space (a, current_space); + RzList *la = deserialize_sign_space (a, current_space); if (!la) { return false; } - RList *lb = deserialize_sign_space (a, other_space); + RzList *lb = deserialize_sign_space (a, other_space); if (!lb) { return false; } eprintf ("Diff by name %d %d (%s)\n", (int)ls_length (la), (int)ls_length (lb), not_matching? "not matching" : "matching"); - RListIter *itr; - RListIter *itr2; - RSignItem *si; - RSignItem *si2; + RzListIter *itr; + RzListIter *itr2; + RzSignItem *si; + RzSignItem *si2; size_t current_space_name_len = strlen (current_space->name); size_t other_space_name_len = strlen (other_space->name); - r_list_foreach (la, itr, si) { + rz_list_foreach (la, itr, si) { if (strstr (si->name, "imp.")) { continue; } - r_list_foreach (lb, itr2, si2) { + rz_list_foreach (lb, itr2, si2) { if (strcmp (si->name + current_space_name_len + 1, si2->name + other_space_name_len + 1)) { continue; } @@ -1547,26 +1547,26 @@ R_API bool r_sign_diff_by_name(RAnal *a, RSignOptions *options, const char *othe } } - r_list_free (la); - r_list_free (lb); + rz_list_free (la); + rz_list_free (lb); return true; } struct ctxListCB { - RAnal *anal; + RzAnal *anal; int idx; int format; PJ *pj; }; struct ctxGetListCB { - RAnal *anal; - RList *list; + RzAnal *anal; + RzList *list; }; -static void listBytes(RAnal *a, RSignItem *it, PJ *pj, int format) { - RSignBytes *bytes = it->bytes; +static void listBytes(RzAnal *a, RzSignItem *it, PJ *pj, int format) { + RzSignBytes *bytes = it->bytes; if (!bytes->bytes) { return; @@ -1577,11 +1577,11 @@ static void listBytes(RAnal *a, RSignItem *it, PJ *pj, int format) { masked += bytes->mask[i] == 0xff; } - char * strbytes = r_hex_bin2strdup (bytes->bytes, bytes->size); + char * strbytes = rz_hex_bin2strdup (bytes->bytes, bytes->size); if (!strbytes) { return; } - char * strmask = r_hex_bin2strdup (bytes->mask, bytes->size); + char * strmask = rz_hex_bin2strdup (bytes->mask, bytes->size); if (!strmask) { free (strbytes); return; @@ -1607,8 +1607,8 @@ static void listBytes(RAnal *a, RSignItem *it, PJ *pj, int format) { free (strmask); } -static void listGraph(RAnal *a, RSignItem *it, PJ *pj, int format) { - RSignGraph *graph = it->graph; +static void listGraph(RzAnal *a, RzSignItem *it, PJ *pj, int format) { + RzSignGraph *graph = it->graph; if (format == 'q') { a->cb_printf (" g(cc=%d,nb=%d,e=%d,eb=%d,h=%d)", @@ -1630,7 +1630,7 @@ static void listGraph(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listComment(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void listComment(RzAnal *a, RzSignItem *it, PJ *pj, int format) { if (it->comment) { if (format == 'q') { // a->cb_printf (" addr(0x%08"PFMT64x")", it->addr); @@ -1645,7 +1645,7 @@ static void listComment(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listRealname(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void listRealname(RzAnal *a, RzSignItem *it, PJ *pj, int format) { if (it->realname) { if (format == 'q') { // a->cb_printf (" addr(0x%08"PFMT64x")", it->addr); @@ -1660,7 +1660,7 @@ static void listRealname(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listOffset(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void listOffset(RzAnal *a, RzSignItem *it, PJ *pj, int format) { if (format == 'q') { // a->cb_printf (" addr(0x%08"PFMT64x")", it->addr); } else if (format == '*') { @@ -1672,15 +1672,15 @@ static void listOffset(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listVars(RAnal *a, RSignItem *it, PJ *pj, int format) { - RListIter *iter = NULL; +static void listVars(RzAnal *a, RzSignItem *it, PJ *pj, int format) { + RzListIter *iter = NULL; char *var = NULL; int i = 0; if (format == '*') { a->cb_printf ("za %s v ", it->name); } else if (format == 'q') { - a->cb_printf (" vars(%d)", r_list_length (it->vars)); + a->cb_printf (" vars(%d)", rz_list_length (it->vars)); return; } else if (format == 'j') { pj_ka (pj, "vars"); @@ -1688,7 +1688,7 @@ static void listVars(RAnal *a, RSignItem *it, PJ *pj, int format) { a->cb_printf (" vars: "); } - r_list_foreach (it->vars, iter, var) { + rz_list_foreach (it->vars, iter, var) { if (i > 0) { if (format == '*') { a->cb_printf (" "); @@ -1711,11 +1711,11 @@ static void listVars(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void print_list_type_header(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void print_list_type_header(RzAnal *a, RzSignItem *it, PJ *pj, int format) { if (format == '*') { a->cb_printf ("za %s t ", it->name); } else if (format == 'q') { - a->cb_printf (" types(%d)", r_list_length (it->types)); + a->cb_printf (" types(%d)", rz_list_length (it->types)); return; } else if (format == 'j') { pj_ka (pj, "types"); @@ -1724,7 +1724,7 @@ static void print_list_type_header(RAnal *a, RSignItem *it, PJ *pj, int format) } } -static void print_function_args_json(RAnal *a, PJ *pj, char *arg_type) { +static void print_function_args_json(RzAnal *a, PJ *pj, char *arg_type) { char *arg_name = strchr (arg_type, ','); if (arg_name == NULL) { @@ -1743,7 +1743,7 @@ static void print_function_args_json(RAnal *a, PJ *pj, char *arg_type) { pj_end (pj); } -static void print_type_json(RAnal *a, char *type, PJ *pj, size_t pos) { +static void print_type_json(RzAnal *a, char *type, PJ *pj, size_t pos) { if (pos == 0) { return; } @@ -1760,7 +1760,7 @@ static void print_type_json(RAnal *a, char *type, PJ *pj, size_t pos) { print_function_args_json (a, pj, str_type); } -static void print_list_separator(RAnal *a, RSignItem *it, PJ *pj, int format, int pos) { +static void print_list_separator(RzAnal *a, RzSignItem *it, PJ *pj, int format, int pos) { if (pos == 0 || format == 'j') { return; } @@ -1771,12 +1771,12 @@ static void print_list_separator(RAnal *a, RSignItem *it, PJ *pj, int format, in } } -static void print_list_type_body(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void print_list_type_body(RzAnal *a, RzSignItem *it, PJ *pj, int format) { int i = 0; char *type = NULL; - RListIter *iter = NULL; + RzListIter *iter = NULL; - r_list_foreach (it->types, iter, type) { + rz_list_foreach (it->types, iter, type) { print_list_separator (a, it, pj, format, i); if (format == 'j') { @@ -1790,7 +1790,7 @@ static void print_list_type_body(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listTypes(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void listTypes(RzAnal *a, RzSignItem *it, PJ *pj, int format) { print_list_type_header (a, it, pj, format); print_list_type_body (a, it, pj, format); @@ -1801,25 +1801,25 @@ static void listTypes(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listXRefs(RAnal *a, RSignItem *it, PJ *pj, int format) { - RListIter *iter = NULL; +static void listXRefs(RzAnal *a, RzSignItem *it, PJ *pj, int format) { + RzListIter *iter = NULL; char *ref = NULL; int i = 0; if (format == '*') { a->cb_printf ("za %s x ", it->name); } else if (format == 'q') { - a->cb_printf (" xrefs(%d)", r_list_length (it->xrefs)); + a->cb_printf (" xrefs(%d)", rz_list_length (it->xrefs)); return; } else if (format == 'j') { pj_ka (pj, "xrefs"); } else { - if (it->xrefs && !r_list_empty (it->xrefs)) { + if (it->xrefs && !rz_list_empty (it->xrefs)) { a->cb_printf (" xrefs: "); } } - r_list_foreach (it->xrefs, iter, ref) { + rz_list_foreach (it->xrefs, iter, ref) { if (i > 0) { if (format == '*') { a->cb_printf (" "); @@ -1842,25 +1842,25 @@ static void listXRefs(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listRefs(RAnal *a, RSignItem *it, PJ *pj, int format) { - RListIter *iter = NULL; +static void listRefs(RzAnal *a, RzSignItem *it, PJ *pj, int format) { + RzListIter *iter = NULL; char *ref = NULL; int i = 0; if (format == '*') { a->cb_printf ("za %s r ", it->name); } else if (format == 'q') { - a->cb_printf (" refs(%d)", r_list_length (it->refs)); + a->cb_printf (" refs(%d)", rz_list_length (it->refs)); return; } else if (format == 'j') { pj_ka (pj, "refs"); } else { - if (it->refs && !r_list_empty (it->refs)) { + if (it->refs && !rz_list_empty (it->refs)) { a->cb_printf (" refs: "); } } - r_list_foreach (it->refs, iter, ref) { + rz_list_foreach (it->refs, iter, ref) { if (i > 0) { if (format == '*') { a->cb_printf (" "); @@ -1883,14 +1883,14 @@ static void listRefs(RAnal *a, RSignItem *it, PJ *pj, int format) { } } -static void listHash(RAnal *a, RSignItem *it, PJ *pj, int format) { +static void listHash(RzAnal *a, RzSignItem *it, PJ *pj, int format) { if (!it->hash) { return; } switch (format) { case 'q': if (it->hash->bbhash) { - a->cb_printf (" h(%08x)", r_str_hash (it->hash->bbhash)); + a->cb_printf (" h(%08x)", rz_str_hash (it->hash->bbhash)); } break; case '*': @@ -1915,15 +1915,15 @@ static void listHash(RAnal *a, RSignItem *it, PJ *pj, int format) { static bool listCB(void *user, const char *k, const char *v) { struct ctxListCB *ctx = (struct ctxListCB *)user; - RSignItem *it = r_sign_item_new (); - RAnal *a = ctx->anal; + RzSignItem *it = rz_sign_item_new (); + RzAnal *a = ctx->anal; - if (!r_sign_deserialize (a, it, k, v)) { + if (!rz_sign_deserialize (a, it, k, v)) { eprintf ("error: cannot deserialize zign\n"); goto out; } - RSpace *cur = r_spaces_current (&a->zign_spaces); + RSpace *cur = rz_spaces_current (&a->zign_spaces); if (cur != it->space && cur) { goto out; } @@ -1942,7 +1942,7 @@ static bool listCB(void *user, const char *k, const char *v) { } } else if (ctx->format == 'q') { a->cb_printf ("0x%08" PFMT64x " ", it->addr); - const char *pad = r_str_pad (' ', 30 - strlen (it->name)); + const char *pad = rz_str_pad (' ', 30 - strlen (it->name)); a->cb_printf ("%s:%s", it->name, pad); } else if (ctx->format == 'j') { if (it->space) { @@ -1950,7 +1950,7 @@ static bool listCB(void *user, const char *k, const char *v) { } pj_ks (ctx->pj, "name", it->name); } else { - if (!r_spaces_current (&a->zign_spaces) && it->space) { + if (!rz_spaces_current (&a->zign_spaces) && it->space) { a->cb_printf ("(%s) ", it->space->name); } a->cb_printf ("%s:\n", it->name); @@ -2030,13 +2030,13 @@ static bool listCB(void *user, const char *k, const char *v) { ctx->idx++; out: - r_sign_item_free (it); + rz_sign_item_free (it); return true; } -R_API void r_sign_list(RAnal *a, int format) { - r_return_if_fail (a); +RZ_API void rz_sign_list(RzAnal *a, int format) { + rz_return_if_fail (a); PJ *pj = NULL; if (format == 'j') { @@ -2056,41 +2056,41 @@ R_API void r_sign_list(RAnal *a, int format) { static bool listGetCB(void *user, const char *key, const char *val) { struct ctxGetListCB *ctx = user; - RSignItem *item = r_sign_item_new (); + RzSignItem *item = rz_sign_item_new (); if (!item) { return false; } - if (!r_sign_deserialize (ctx->anal, item, key, val)) { - r_sign_item_free (item); + if (!rz_sign_deserialize (ctx->anal, item, key, val)) { + rz_sign_item_free (item); return false; } - r_list_append (ctx->list, item); + rz_list_append (ctx->list, item); return true; } -R_API RList *r_sign_get_list(RAnal *a) { - r_return_val_if_fail (a, NULL); - struct ctxGetListCB ctx = { a, r_list_newf ((RListFree)r_sign_item_free) }; +RZ_API RzList *rz_sign_get_list(RzAnal *a) { + rz_return_val_if_fail (a, NULL); + struct ctxGetListCB ctx = { a, rz_list_newf ((RzListFree)rz_sign_item_free) }; sdb_foreach (a->sdb_zigns, listGetCB, &ctx); return ctx.list; } static int cmpaddr(const void *_a, const void *_b) { - const RAnalBlock *a = _a, *b = _b; + const RzAnalBlock *a = _a, *b = _b; return (a->addr - b->addr); } -R_API char *r_sign_calc_bbhash(RAnal *a, RAnalFunction *fcn) { - RListIter *iter = NULL; - RAnalBlock *bbi = NULL; +RZ_API char *rz_sign_calc_bbhash(RzAnal *a, RzAnalFunction *fcn) { + RzListIter *iter = NULL; + RzAnalBlock *bbi = NULL; char *digest_hex = NULL; - RHash *ctx = r_hash_new (true, R_ZIGN_HASH); + RzHash *ctx = rz_hash_new (true, R_ZIGN_HASH); if (!ctx) { goto beach; } - r_list_sort (fcn->bbs, &cmpaddr); - r_hash_do_begin (ctx, R_ZIGN_HASH); - r_list_foreach (fcn->bbs, iter, bbi) { + rz_list_sort (fcn->bbs, &cmpaddr); + rz_hash_do_begin (ctx, R_ZIGN_HASH); + rz_list_foreach (fcn->bbs, iter, bbi) { ut8 *buf = malloc (bbi->size); if (!buf) { goto beach; @@ -2098,59 +2098,59 @@ R_API char *r_sign_calc_bbhash(RAnal *a, RAnalFunction *fcn) { if (!a->iob.read_at (a->iob.io, bbi->addr, buf, bbi->size)) { goto beach; } - if (!r_hash_do_sha256 (ctx, buf, bbi->size)) { + if (!rz_hash_do_sha256 (ctx, buf, bbi->size)) { goto beach; } free (buf); } - r_hash_do_end (ctx, R_ZIGN_HASH); + rz_hash_do_end (ctx, R_ZIGN_HASH); - digest_hex = r_hex_bin2strdup (ctx->digest, r_hash_size (R_ZIGN_HASH)); + digest_hex = rz_hex_bin2strdup (ctx->digest, rz_hash_size (R_ZIGN_HASH)); beach: free (ctx); return digest_hex; } struct ctxCountForCB { - RAnal *anal; + RzAnal *anal; const RSpace *space; int count; }; static bool countForCB(void *user, const char *k, const char *v) { struct ctxCountForCB *ctx = (struct ctxCountForCB *) user; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); - if (r_sign_deserialize (ctx->anal, it, k, v)) { + if (rz_sign_deserialize (ctx->anal, it, k, v)) { if (it->space == ctx->space) { ctx->count++; } } else { eprintf ("error: cannot deserialize zign\n"); } - r_sign_item_free (it); + rz_sign_item_free (it); return true; } -R_API int r_sign_space_count_for(RAnal *a, const RSpace *space) { +RZ_API int rz_sign_space_count_for(RzAnal *a, const RSpace *space) { struct ctxCountForCB ctx = { a, space, 0 }; - r_return_val_if_fail (a, 0); + rz_return_val_if_fail (a, 0); sdb_foreach (a->sdb_zigns, countForCB, &ctx); return ctx.count; } struct ctxUnsetForCB { - RAnal *anal; + RzAnal *anal; const RSpace *space; }; static bool unsetForCB(void *user, const char *k, const char *v) { struct ctxUnsetForCB *ctx = (struct ctxUnsetForCB *) user; char nk[R_SIGN_KEY_MAXSZ], nv[R_SIGN_VAL_MAXSZ]; - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); Sdb *db = ctx->anal->sdb_zigns; - if (r_sign_deserialize (ctx->anal, it, k, v)) { + if (rz_sign_deserialize (ctx->anal, it, k, v)) { if (it->space && it->space == ctx->space) { it->space = NULL; serialize (ctx->anal, it, nk, nv); @@ -2160,18 +2160,18 @@ static bool unsetForCB(void *user, const char *k, const char *v) { } else { eprintf ("error: cannot deserialize zign\n"); } - r_sign_item_free (it); + rz_sign_item_free (it); return true; } -R_API void r_sign_space_unset_for(RAnal *a, const RSpace *space) { - r_return_if_fail (a); +RZ_API void rz_sign_space_unset_for(RzAnal *a, const RSpace *space) { + rz_return_if_fail (a); struct ctxUnsetForCB ctx = { a, space }; sdb_foreach (a->sdb_zigns, unsetForCB, &ctx); } struct ctxRenameForCB { - RAnal *anal; + RzAnal *anal; char oprefix[R_SIGN_KEY_MAXSZ]; char nprefix[R_SIGN_KEY_MAXSZ]; }; @@ -2192,8 +2192,8 @@ static bool renameForCB(void *user, const char *k, const char *v) { return true; } -R_API void r_sign_space_rename_for(RAnal *a, const RSpace *space, const char *oname, const char *nname) { - r_return_if_fail (a && space && oname && nname); +RZ_API void rz_sign_space_rename_for(RzAnal *a, const RSpace *space, const char *oname, const char *nname) { + rz_return_if_fail (a && space && oname && nname); struct ctxRenameForCB ctx = {.anal = a}; serializeKeySpaceStr (a, oname, "", ctx.oprefix); serializeKeySpaceStr (a, nname, "", ctx.nprefix); @@ -2201,19 +2201,19 @@ R_API void r_sign_space_rename_for(RAnal *a, const RSpace *space, const char *on } struct ctxForeachCB { - RAnal *anal; - RSignForeachCallback cb; + RzAnal *anal; + RzSignForeachCallback cb; bool freeit; void *user; }; static bool foreachCB(void *user, const char *k, const char *v) { struct ctxForeachCB *ctx = (struct ctxForeachCB *) user; - RSignItem *it = r_sign_item_new (); - RAnal *a = ctx->anal; + RzSignItem *it = rz_sign_item_new (); + RzAnal *a = ctx->anal; - if (r_sign_deserialize (a, it, k, v)) { - RSpace *cur = r_spaces_current (&a->zign_spaces); + if (rz_sign_deserialize (a, it, k, v)) { + RSpace *cur = rz_spaces_current (&a->zign_spaces); if (ctx->cb && cur == it->space) { ctx->cb (it, ctx->user); } @@ -2221,55 +2221,55 @@ static bool foreachCB(void *user, const char *k, const char *v) { eprintf ("error: cannot deserialize zign\n"); } if (ctx->freeit) { - r_sign_item_free (it); + rz_sign_item_free (it); } return true; } -static bool r_sign_foreach_nofree(RAnal *a, RSignForeachCallback cb, void *user) { - r_return_val_if_fail (a && cb, false); +static bool rz_sign_foreach_nofree(RzAnal *a, RzSignForeachCallback cb, void *user) { + rz_return_val_if_fail (a && cb, false); struct ctxForeachCB ctx = { a, cb, false, user }; return sdb_foreach (a->sdb_zigns, foreachCB, &ctx); } -R_API bool r_sign_foreach(RAnal *a, RSignForeachCallback cb, void *user) { - r_return_val_if_fail (a && cb, false); +RZ_API bool rz_sign_foreach(RzAnal *a, RzSignForeachCallback cb, void *user) { + rz_return_val_if_fail (a && cb, false); struct ctxForeachCB ctx = { a, cb, true, user }; return sdb_foreach (a->sdb_zigns, foreachCB, &ctx); } -R_API RSignSearch *r_sign_search_new(void) { - RSignSearch *ret = R_NEW0 (RSignSearch); +RZ_API RzSignSearch *rz_sign_search_new(void) { + RzSignSearch *ret = R_NEW0 (RzSignSearch); if (ret) { - ret->search = r_search_new (R_SEARCH_KEYWORD); - ret->items = r_list_newf ((RListFree) r_sign_item_free); + ret->search = rz_search_new (R_SEARCH_KEYWORD); + ret->items = rz_list_newf ((RzListFree) rz_sign_item_free); } return ret; } -R_API void r_sign_search_free(RSignSearch *ss) { +RZ_API void rz_sign_search_free(RzSignSearch *ss) { if (!ss) { return; } - r_search_free (ss->search); - r_list_free (ss->items); + rz_search_free (ss->search); + rz_list_free (ss->items); free (ss); } -static int searchHitCB(RSearchKeyword *kw, void *user, ut64 addr) { - RSignSearch *ss = (RSignSearch *) user; - return ss->cb? ss->cb ((RSignItem *) kw->data, kw, addr, ss->user): 1; +static int searchHitCB(RzSearchKeyword *kw, void *user, ut64 addr) { + RzSignSearch *ss = (RzSignSearch *) user; + return ss->cb? ss->cb ((RzSignItem *) kw->data, kw, addr, ss->user): 1; } struct ctxAddSearchKwCB { - RSignSearch *ss; + RzSignSearch *ss; int minsz; }; -static int addSearchKwCB(RSignItem *it, void *user) { +static int addSearchKwCB(RzSignItem *it, void *user) { struct ctxAddSearchKwCB *ctx = (struct ctxAddSearchKwCB *) user; - RSignSearch *ss = ctx->ss; - RSignBytes *bytes = it->bytes; + RzSignSearch *ss = ctx->ss; + RzSignBytes *bytes = it->bytes; if (!bytes) { eprintf ("Cannot find bytes for this signature: %s\n", it->name); @@ -2279,28 +2279,28 @@ static int addSearchKwCB(RSignItem *it, void *user) { if (ctx->minsz && bytes->size < ctx->minsz) { return 1; } - r_list_append (ss->items, it); - // TODO(nibble): change arg data in r_search_keyword_new to void* - RSearchKeyword *kw = r_search_keyword_new (bytes->bytes, bytes->size, bytes->mask, bytes->size, (const char *)it); - r_search_kw_add (ss->search, kw); + rz_list_append (ss->items, it); + // TODO(nibble): change arg data in rz_search_keyword_new to void* + RzSearchKeyword *kw = rz_search_keyword_new (bytes->bytes, bytes->size, bytes->mask, bytes->size, (const char *)it); + rz_search_kw_add (ss->search, kw); return 1; } -R_API void r_sign_search_init(RAnal *a, RSignSearch *ss, int minsz, RSignSearchCallback cb, void *user) { +RZ_API void rz_sign_search_init(RzAnal *a, RzSignSearch *ss, int minsz, RzSignSearchCallback cb, void *user) { struct ctxAddSearchKwCB ctx = { ss, minsz }; - r_return_if_fail (a && ss && cb); + rz_return_if_fail (a && ss && cb); ss->cb = cb; ss->user = user; - r_list_purge (ss->items); - r_search_reset (ss->search, R_SEARCH_KEYWORD); - r_sign_foreach_nofree (a, addSearchKwCB, &ctx); - r_search_begin (ss->search); - r_search_set_callback (ss->search, searchHitCB, ss); + rz_list_purge (ss->items); + rz_search_reset (ss->search, R_SEARCH_KEYWORD); + rz_sign_foreach_nofree (a, addSearchKwCB, &ctx); + rz_search_begin (ss->search); + rz_search_set_callback (ss->search, searchHitCB, ss); } -R_API int r_sign_search_update(RAnal *a, RSignSearch *ss, ut64 *at, const ut8 *buf, int len) { - r_return_val_if_fail (a && ss && buf && len > 0, 0); - return r_search_update (ss->search, *at, buf, len); +RZ_API int rz_sign_search_update(RzAnal *a, RzSignSearch *ss, ut64 *at, const ut8 *buf, int len) { + rz_return_val_if_fail (a && ss && buf && len > 0, 0); + return rz_search_update (ss->search, *at, buf, len); } // allow ~10% of margin error @@ -2310,39 +2310,39 @@ static int matchCount(int a, int b) { return R_ABS (c) < m; } -static bool fcnMetricsCmp(RSignItem *it, RAnalFunction *fcn) { - RSignGraph *graph = it->graph; +static bool fcnMetricsCmp(RzSignItem *it, RzAnalFunction *fcn) { + RzSignGraph *graph = it->graph; int ebbs = -1; - if (graph->cc != -1 && graph->cc != r_anal_function_complexity (fcn)) { + if (graph->cc != -1 && graph->cc != rz_anal_function_complexity (fcn)) { return false; } - if (graph->nbbs != -1 && graph->nbbs != r_list_length (fcn->bbs)) { + if (graph->nbbs != -1 && graph->nbbs != rz_list_length (fcn->bbs)) { return false; } - if (graph->edges != -1 && graph->edges != r_anal_function_count_edges (fcn, &ebbs)) { + if (graph->edges != -1 && graph->edges != rz_anal_function_count_edges (fcn, &ebbs)) { return false; } if (graph->ebbs != -1 && graph->ebbs != ebbs) { return false; } - if (graph->bbsum > 0 && matchCount (graph->bbsum, r_anal_function_linear_size (fcn))) { + if (graph->bbsum > 0 && matchCount (graph->bbsum, rz_anal_function_linear_size (fcn))) { return false; } return true; } struct ctxFcnMatchCB { - RAnal *anal; - RAnalFunction *fcn; - RSignGraphMatchCallback cb; + RzAnal *anal; + RzAnalFunction *fcn; + RzSignGraphMatchCallback cb; void *user; int mincc; }; -static int graphMatchCB(RSignItem *it, void *user) { +static int graphMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; - RSignGraph *graph = it->graph; + RzSignGraph *graph = it->graph; if (!graph) { return 1; @@ -2363,13 +2363,13 @@ static int graphMatchCB(RSignItem *it, void *user) { return 1; } -R_API bool r_sign_match_graph(RAnal *a, RAnalFunction *fcn, int mincc, RSignGraphMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_graph(RzAnal *a, RzAnalFunction *fcn, int mincc, RzSignGraphMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, mincc }; - return r_sign_foreach (a, graphMatchCB, &ctx); + return rz_sign_foreach (a, graphMatchCB, &ctx); } -static int addrMatchCB(RSignItem *it, void *user) { +static int addrMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; if (it->addr == UT64_MAX) { @@ -2387,21 +2387,21 @@ static int addrMatchCB(RSignItem *it, void *user) { return 1; } -R_API bool r_sign_match_addr(RAnal *a, RAnalFunction *fcn, RSignOffsetMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_addr(RzAnal *a, RzAnalFunction *fcn, RzSignOffsetMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, 0 }; - return r_sign_foreach (a, addrMatchCB, &ctx); + return rz_sign_foreach (a, addrMatchCB, &ctx); } -static int hashMatchCB(RSignItem *it, void *user) { +static int hashMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; - RSignHash *hash = it->hash; + RzSignHash *hash = it->hash; if (!hash || !hash->bbhash || hash->bbhash[0] == 0) { return 1; } - char *digest_hex = r_sign_calc_bbhash (ctx->anal, ctx->fcn); + char *digest_hex = rz_sign_calc_bbhash (ctx->anal, ctx->fcn); bool retval = false; if (digest_hex && strcmp (hash->bbhash, digest_hex)) { goto beach; @@ -2415,16 +2415,16 @@ beach: return retval; } -R_API bool r_sign_match_hash(RAnal *a, RAnalFunction *fcn, RSignHashMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_hash(RzAnal *a, RzAnalFunction *fcn, RzSignHashMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, 0 }; - return r_sign_foreach (a, hashMatchCB, &ctx); + return rz_sign_foreach (a, hashMatchCB, &ctx); } -static int refsMatchCB(RSignItem *it, void *user) { +static int refsMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; - RList *refs = NULL; + RzList *refs = NULL; char *ref_a = NULL, *ref_b = NULL; int i = 0, retval = 1; @@ -2433,14 +2433,14 @@ static int refsMatchCB(RSignItem *it, void *user) { } // TODO(nibble): slow operation, add cache - refs = r_sign_fcn_refs (ctx->anal, ctx->fcn); + refs = rz_sign_fcn_refs (ctx->anal, ctx->fcn); if (!refs) { return 1; } for (i = 0; ; i++) { - ref_a = (char *) r_list_get_n (it->refs, i); - ref_b = (char *) r_list_get_n (refs, i); + ref_a = (char *) rz_list_get_n (it->refs, i); + ref_b = (char *) rz_list_get_n (refs, i); if (!ref_a || !ref_b) { if (ref_a != ref_b) { @@ -2461,20 +2461,20 @@ static int refsMatchCB(RSignItem *it, void *user) { } out: - r_list_free (refs); + rz_list_free (refs); return retval; } -R_API bool r_sign_match_refs(RAnal *a, RAnalFunction *fcn, RSignRefsMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_refs(RzAnal *a, RzAnalFunction *fcn, RzSignRefsMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, 0 }; - return r_sign_foreach (a, refsMatchCB, &ctx); + return rz_sign_foreach (a, refsMatchCB, &ctx); } -static int varsMatchCB(RSignItem *it, void *user) { +static int varsMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; - RList *vars = NULL; + RzList *vars = NULL; char *var_a = NULL, *var_b = NULL; int i = 0, retval = 1; @@ -2483,14 +2483,14 @@ static int varsMatchCB(RSignItem *it, void *user) { } // TODO(nibble): slow operation, add cache - vars = r_sign_fcn_vars (ctx->anal, ctx->fcn); + vars = rz_sign_fcn_vars (ctx->anal, ctx->fcn); if (!vars) { return 1; } for (i = 0; ; i++) { - var_a = (char *) r_list_get_n (it->vars, i); - var_b = (char *) r_list_get_n (vars, i); + var_a = (char *) rz_list_get_n (it->vars, i); + var_b = (char *) rz_list_get_n (vars, i); if (!var_a || !var_b) { if (var_a != var_b) { @@ -2511,20 +2511,20 @@ static int varsMatchCB(RSignItem *it, void *user) { } out: - r_list_free (vars); + rz_list_free (vars); return retval; } -R_API bool r_sign_match_vars(RAnal *a, RAnalFunction *fcn, RSignVarsMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_vars(RzAnal *a, RzAnalFunction *fcn, RzSignVarsMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, 0 }; - return r_sign_foreach (a, varsMatchCB, &ctx); + return rz_sign_foreach (a, varsMatchCB, &ctx); } -static int typesMatchCB(RSignItem *it, void *user) { +static int typesMatchCB(RzSignItem *it, void *user) { struct ctxFcnMatchCB *ctx = (struct ctxFcnMatchCB *) user; - RList *types = NULL; + RzList *types = NULL; char *type_a = NULL, *type_b = NULL; int i = 0, retval = 1; @@ -2532,13 +2532,13 @@ static int typesMatchCB(RSignItem *it, void *user) { return 1; } // TODO(nibble | oxcabe): slow operation, add cache - types = r_sign_fcn_types (ctx->anal, ctx->fcn); + types = rz_sign_fcn_types (ctx->anal, ctx->fcn); if (!types) { return 1; } for (i = 0; ; i++) { - type_a = (char *) r_list_get_n (it->types, i); - type_b = (char *) r_list_get_n (types, i); + type_a = (char *) rz_list_get_n (it->types, i); + type_b = (char *) rz_list_get_n (types, i); if (!type_a || !type_b) { if (type_a != type_b) { @@ -2559,19 +2559,19 @@ static int typesMatchCB(RSignItem *it, void *user) { } out: - r_list_free (types); + rz_list_free (types); return retval; } -R_API bool r_sign_match_types(RAnal *a, RAnalFunction *fcn, RSignVarsMatchCallback cb, void *user) { - r_return_val_if_fail (a && fcn && cb, false); +RZ_API bool rz_sign_match_types(RzAnal *a, RzAnalFunction *fcn, RzSignVarsMatchCallback cb, void *user) { + rz_return_val_if_fail (a && fcn && cb, false); struct ctxFcnMatchCB ctx = { a, fcn, cb, user, 0 }; - return r_sign_foreach (a, typesMatchCB, &ctx); + return rz_sign_foreach (a, typesMatchCB, &ctx); } -R_API RSignItem *r_sign_item_new(void) { - RSignItem *ret = R_NEW0 (RSignItem); +RZ_API RzSignItem *rz_sign_item_new(void) { + RzSignItem *ret = R_NEW0 (RzSignItem); if (ret) { ret->addr = UT64_MAX; ret->space = NULL; @@ -2579,31 +2579,31 @@ R_API RSignItem *r_sign_item_new(void) { return ret; } -R_API void r_sign_item_free(RSignItem *item) { +RZ_API void rz_sign_item_free(RzSignItem *item) { if (!item) { return; } free (item->name); - r_sign_bytes_free (item->bytes); + rz_sign_bytes_free (item->bytes); if (item->hash) { free (item->hash->bbhash); free (item->hash); } - r_sign_graph_free (item->graph); + rz_sign_graph_free (item->graph); free (item->comment); free (item->realname); - r_list_free (item->refs); - r_list_free (item->vars); - r_list_free (item->xrefs); - r_list_free (item->types); + rz_list_free (item->refs); + rz_list_free (item->vars); + rz_list_free (item->xrefs); + rz_list_free (item->types); free (item); } -R_API void r_sign_graph_free(RSignGraph *graph) { +RZ_API void rz_sign_graph_free(RzSignGraph *graph) { free (graph); } -R_API void r_sign_bytes_free(RSignBytes *bytes) { +RZ_API void rz_sign_bytes_free(RzSignBytes *bytes) { if (bytes) { free (bytes->bytes); free (bytes->mask); @@ -2612,48 +2612,48 @@ R_API void r_sign_bytes_free(RSignBytes *bytes) { } static bool loadCB(void *user, const char *k, const char *v) { - RAnal *a = (RAnal *) user; + RzAnal *a = (RzAnal *) user; char nk[R_SIGN_KEY_MAXSZ], nv[R_SIGN_VAL_MAXSZ]; - RSignItem *it = r_sign_item_new (); - if (it && r_sign_deserialize (a, it, k, v)) { + RzSignItem *it = rz_sign_item_new (); + if (it && rz_sign_deserialize (a, it, k, v)) { serialize (a, it, nk, nv); sdb_set (a->sdb_zigns, nk, nv, 0); } else { eprintf ("error: cannot deserialize zign\n"); } - r_sign_item_free (it); + rz_sign_item_free (it); return true; } -R_API char *r_sign_path(RAnal *a, const char *file) { - char *abs = r_file_abspath (file); +RZ_API char *rz_sign_path(RzAnal *a, const char *file) { + char *abs = rz_file_abspath (file); if (abs) { - if (r_file_is_regular (abs)) { + if (rz_file_is_regular (abs)) { return abs; } free (abs); } if (a->zign_path) { - char *path = r_str_newf ("%s%s%s", a->zign_path, R_SYS_DIR, file); - abs = r_file_abspath (path); + char *path = rz_str_newf ("%s%s%s", a->zign_path, R_SYS_DIR, file); + abs = rz_file_abspath (path); free (path); - if (r_file_is_regular (abs)) { + if (rz_file_is_regular (abs)) { return abs; } free (abs); } else { - char *home = r_str_home (R2_HOME_ZIGNS); - abs = r_str_newf ("%s%s%s", home, R_SYS_DIR, file); + char *home = rz_str_home (R2_HOME_ZIGNS); + abs = rz_str_newf ("%s%s%s", home, R_SYS_DIR, file); free (home); - if (r_file_is_regular (abs)) { + if (rz_file_is_regular (abs)) { return abs; } free (abs); } - abs = r_str_newf (R_JOIN_3_PATHS ("%s", R2_ZIGNS, "%s"), r_sys_prefix (NULL), file); - if (r_file_is_regular (abs)) { + abs = rz_str_newf (R_JOIN_3_PATHS ("%s", R2_ZIGNS, "%s"), rz_sys_prefix (NULL), file); + if (rz_file_is_regular (abs)) { return abs; } free (abs); @@ -2661,12 +2661,12 @@ R_API char *r_sign_path(RAnal *a, const char *file) { return NULL; } -R_API bool r_sign_load(RAnal *a, const char *file) { +RZ_API bool rz_sign_load(RzAnal *a, const char *file) { if (!a || !file) { return false; } - char *path = r_sign_path (a, file); - if (!r_file_exists (path)) { + char *path = rz_sign_path (a, file); + if (!rz_file_exists (path)) { eprintf ("error: file %s does not exist\n", file); free (path); return false; @@ -2683,44 +2683,44 @@ R_API bool r_sign_load(RAnal *a, const char *file) { return true; } -R_API bool r_sign_load_gz(RAnal *a, const char *filename) { +RZ_API bool rz_sign_load_gz(RzAnal *a, const char *filename) { ut8 *buf = NULL; int size = 0; char *tmpfile = NULL; bool retval = true; - char *path = r_sign_path (a, filename); - if (!r_file_exists (path)) { + char *path = rz_sign_path (a, filename); + if (!rz_file_exists (path)) { eprintf ("error: file %s does not exist\n", filename); retval = false; goto out; } - if (!(buf = r_file_gzslurp (path, &size, 0))) { + if (!(buf = rz_file_gzslurp (path, &size, 0))) { eprintf ("error: cannot decompress file\n"); retval = false; goto out; } - if (!(tmpfile = r_file_temp ("r2zign"))) { + if (!(tmpfile = rz_file_temp ("r2zign"))) { eprintf ("error: cannot create temp file\n"); retval = false; goto out; } - if (!r_file_dump (tmpfile, buf, size, 0)) { + if (!rz_file_dump (tmpfile, buf, size, 0)) { eprintf ("error: cannot dump file\n"); retval = false; goto out; } - if (!r_sign_load (a, tmpfile)) { + if (!rz_sign_load (a, tmpfile)) { eprintf ("error: cannot load file\n"); retval = false; goto out; } - if (!r_file_rm (tmpfile)) { + if (!rz_file_rm (tmpfile)) { eprintf ("error: cannot delete temp file\n"); retval = false; goto out; @@ -2734,8 +2734,8 @@ out: return retval; } -R_API bool r_sign_save(RAnal *a, const char *file) { - r_return_val_if_fail (a && file, false); +RZ_API bool rz_sign_save(RzAnal *a, const char *file) { + rz_return_val_if_fail (a && file, false); if (sdb_isempty (a->sdb_zigns)) { eprintf ("WARNING: no zignatures to save\n"); @@ -2754,14 +2754,14 @@ R_API bool r_sign_save(RAnal *a, const char *file) { return retval; } -R_API RSignOptions *r_sign_options_new(const char *bytes_thresh, const char *graph_thresh) { - RSignOptions *options = R_NEW0 (RSignOptions); +RZ_API RzSignOptions *rz_sign_options_new(const char *bytes_thresh, const char *graph_thresh) { + RzSignOptions *options = R_NEW0 (RzSignOptions); if (!options) { return NULL; } - options->bytes_diff_threshold = r_num_get_float (NULL, bytes_thresh); - options->graph_diff_threshold = r_num_get_float (NULL, graph_thresh); + options->bytes_diff_threshold = rz_num_get_float (NULL, bytes_thresh); + options->graph_diff_threshold = rz_num_get_float (NULL, graph_thresh); if (options->bytes_diff_threshold > 1.0) { options->bytes_diff_threshold = 1.0; @@ -2779,6 +2779,6 @@ R_API RSignOptions *r_sign_options_new(const char *bytes_thresh, const char *gra return options; } -R_API void r_sign_options_free(RSignOptions *options) { +RZ_API void rz_sign_options_free(RzSignOptions *options) { R_FREE (options); } diff --git a/librz/anal/switch.c b/librz/anal/switch.c new file mode 100644 index 0000000000..fe856a3ce6 --- /dev/null +++ b/librz/anal/switch.c @@ -0,0 +1,54 @@ +/* radare - LGPL - Copyright 2014-2019 - pancake, dso */ + +#include + +static RzAnalSwitchOp *__switch_op_new(void) { + RzAnalSwitchOp * swop = R_NEW0 (RzAnalSwitchOp); + if (swop) { + swop->cases = rz_list_new (); + if (!swop->cases) { + free (swop); + return NULL; + } + swop->cases->free = (void *)free; + swop->min_val = swop->def_val = swop->max_val = 0; + } + return swop; +} + +RZ_API RzAnalSwitchOp *rz_anal_switch_op_new(ut64 addr, ut64 min_val, ut64 max_val, ut64 def_val) { + RzAnalSwitchOp *swop = __switch_op_new (); + if (swop) { + swop->addr = addr; + swop->min_val = min_val; + swop->def_val = def_val; + swop->max_val = max_val; + } + return swop; +} + +RZ_API RzAnalCaseOp * rz_anal_case_op_new(ut64 addr, ut64 val, ut64 jump) { + RzAnalCaseOp *c = R_NEW0 (RzAnalCaseOp); + if (c) { + c->addr = addr; + c->value = val; + c->jump = jump; + } + return c; +} + +RZ_API void rz_anal_switch_op_free(RzAnalSwitchOp * swop) { + if (swop) { + rz_list_free (swop->cases); + free (swop); + } +} + +RZ_API RzAnalCaseOp* rz_anal_switch_op_add_case(RzAnalSwitchOp * swop, ut64 addr, ut64 value, ut64 jump) { + rz_return_val_if_fail (swop && addr != UT64_MAX, NULL); + RzAnalCaseOp * caseop = rz_anal_case_op_new (addr, value, jump); + if (caseop) { + rz_list_append (swop->cases, caseop); + } + return caseop; +} diff --git a/libr/anal/type.c b/librz/anal/type.c similarity index 52% rename from libr/anal/type.c rename to librz/anal/type.c index d8d5ed7310..4d794a6e61 100644 --- a/libr/anal/type.c +++ b/librz/anal/type.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2019 - pancake, oddcoder, Anton Kochkov */ -#include +#include #include #include #include "base_types.h" @@ -19,7 +19,7 @@ static char *is_type(char *type) { } static char *get_type_data(Sdb *sdb_types, const char *type, const char *sname) { - char *key = r_str_newf ("%s.%s", type, sname); + char *key = rz_str_newf ("%s.%s", type, sname); if (!key) { return NULL; } @@ -28,8 +28,8 @@ static char *get_type_data(Sdb *sdb_types, const char *type, const char *sname) return members; } -R_API void r_anal_remove_parsed_type(RAnal *anal, const char *name) { - r_return_if_fail (anal && name); +RZ_API void rz_anal_remove_parsed_type(RzAnal *anal, const char *name) { + rz_return_if_fail (anal && name); Sdb *TDB = anal->sdb_types; SdbKv *kv; SdbListIter *iter; @@ -39,13 +39,13 @@ R_API void r_anal_remove_parsed_type(RAnal *anal, const char *name) { } int tmp_len = strlen (name) + strlen (type); char *tmp = malloc (tmp_len + 1); - r_type_del (TDB, name); + rz_type_del (TDB, name); if (tmp) { snprintf (tmp, tmp_len + 1, "%s.%s.", type, name); SdbList *l = sdb_foreach_list (TDB, true); ls_foreach (l, iter, kv) { if (!strncmp (sdbkv_key (kv), tmp, tmp_len)) { - r_type_del (TDB, sdbkv_key (kv)); + rz_type_del (TDB, sdbkv_key (kv)); } } ls_free (l); @@ -53,8 +53,8 @@ R_API void r_anal_remove_parsed_type(RAnal *anal, const char *name) { } } -R_API void r_anal_save_parsed_type(RAnal *anal, const char *parsed) { - r_return_if_fail (anal && parsed); +RZ_API void rz_anal_save_parsed_type(RzAnal *anal, const char *parsed) { + rz_return_if_fail (anal && parsed); // First, if any parsed types exist, let's remove them. char *type = strdup (parsed); @@ -70,7 +70,7 @@ R_API void r_anal_save_parsed_type(RAnal *anal, const char *parsed) { while (name > type && *(name - 1) != '\n') { name--; } - r_anal_remove_parsed_type (anal, name); + rz_anal_remove_parsed_type (anal, name); } free (type); } @@ -83,43 +83,43 @@ static int typecmp(const void *a, const void *b) { return strcmp (a, b); } -R_API RList *r_anal_types_from_fcn(RAnal *anal, RAnalFunction *fcn) { - RListIter *iter; - RAnalVar *var; - RList *list = r_anal_var_all_list (anal, fcn); - RList *type_used = r_list_new (); - r_list_foreach (list, iter, var) { - r_list_append (type_used, var->type); +RZ_API RzList *rz_anal_types_from_fcn(RzAnal *anal, RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalVar *var; + RzList *list = rz_anal_var_all_list (anal, fcn); + RzList *type_used = rz_list_new (); + rz_list_foreach (list, iter, var) { + rz_list_append (type_used, var->type); } - RList *uniq = r_list_uniq (type_used, typecmp); - r_list_free (type_used); + RzList *uniq = rz_list_uniq (type_used, typecmp); + rz_list_free (type_used); return uniq; } R_IPI void enum_type_case_free(void *e, void *user) { (void)user; - RAnalEnumCase *cas = e; + RzAnalEnumCase *cas = e; free ((char *)cas->name); } R_IPI void struct_type_member_free(void *e, void *user) { (void)user; - RAnalStructMember *member = e; + RzAnalStructMember *member = e; free ((char *)member->name); free ((char *)member->type); } R_IPI void union_type_member_free(void *e, void *user) { (void)user; - RAnalUnionMember *member = e; + RzAnalUnionMember *member = e; free ((char *)member->name); free ((char *)member->type); } -static RAnalBaseType *get_enum_type(RAnal *anal, const char *sname) { - r_return_val_if_fail (anal && sname, NULL); +static RzAnalBaseType *get_enum_type(RzAnal *anal, const char *sname) { + rz_return_val_if_fail (anal && sname, NULL); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); if (!base_type) { return NULL; } @@ -129,14 +129,14 @@ static RAnalBaseType *get_enum_type(RAnal *anal, const char *sname) { goto error; } - RVector *cases = &base_type->enum_data.cases; - if (!r_vector_reserve (cases, (size_t)sdb_alen (members))) { + RzVector *cases = &base_type->enum_data.cases; + if (!rz_vector_reserve (cases, (size_t)sdb_alen (members))) { goto error; } char *cur; sdb_aforeach (cur, members) { - char *val_key = r_str_newf ("enum.%s.%s", sname, cur); + char *val_key = rz_str_newf ("enum.%s.%s", sname, cur); if (!val_key) { goto error; } @@ -147,9 +147,9 @@ static RAnalBaseType *get_enum_type(RAnal *anal, const char *sname) { goto error; } - RAnalEnumCase cas = { .name = strdup (cur), .val = strtol (value, NULL, 16) }; + RzAnalEnumCase cas = { .name = strdup (cur), .val = strtol (value, NULL, 16) }; - void *element = r_vector_push (cases, &cas); // returns null if no space available + void *element = rz_vector_push (cases, &cas); // returns null if no space available if (!element) { goto error; } @@ -162,14 +162,14 @@ static RAnalBaseType *get_enum_type(RAnal *anal, const char *sname) { error: free (members); - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); return NULL; } -static RAnalBaseType *get_struct_type(RAnal *anal, const char *sname) { - r_return_val_if_fail (anal && sname, NULL); +static RzAnalBaseType *get_struct_type(RzAnal *anal, const char *sname) { + rz_return_val_if_fail (anal && sname, NULL); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_STRUCT); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_STRUCT); if (!base_type) { return NULL; } @@ -179,14 +179,14 @@ static RAnalBaseType *get_struct_type(RAnal *anal, const char *sname) { goto error; } - RVector *members = &base_type->struct_data.members; - if (!r_vector_reserve (members, (size_t)sdb_alen (sdb_members))) { + RzVector *members = &base_type->struct_data.members; + if (!rz_vector_reserve (members, (size_t)sdb_alen (sdb_members))) { goto error; } char *cur; sdb_aforeach (cur, sdb_members) { - char *type_key = r_str_newf ("struct.%s.%s", sname, cur); + char *type_key = rz_str_newf ("struct.%s.%s", sname, cur); if (!type_key) { goto error; } @@ -203,7 +203,7 @@ static RAnalBaseType *get_struct_type(RAnal *anal, const char *sname) { goto error; } offset = sdb_anext (offset, NULL); - RAnalStructMember cas = { + RzAnalStructMember cas = { .name = strdup (cur), .type = strdup (type), .offset = strtol (offset, NULL, 10) @@ -211,7 +211,7 @@ static RAnalBaseType *get_struct_type(RAnal *anal, const char *sname) { free (values); - void *element = r_vector_push (members, &cas); // returns null if no space available + void *element = rz_vector_push (members, &cas); // returns null if no space available if (!element) { goto error; } @@ -223,15 +223,15 @@ static RAnalBaseType *get_struct_type(RAnal *anal, const char *sname) { return base_type; error: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); free (sdb_members); return NULL; } -static RAnalBaseType *get_union_type(RAnal *anal, const char *sname) { - r_return_val_if_fail (anal && sname, NULL); +static RzAnalBaseType *get_union_type(RzAnal *anal, const char *sname) { + rz_return_val_if_fail (anal && sname, NULL); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_UNION); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_UNION); if (!base_type) { return NULL; } @@ -241,14 +241,14 @@ static RAnalBaseType *get_union_type(RAnal *anal, const char *sname) { goto error; } - RVector *members = &base_type->union_data.members; - if (!r_vector_reserve (members, (size_t)sdb_alen (sdb_members))) { + RzVector *members = &base_type->union_data.members; + if (!rz_vector_reserve (members, (size_t)sdb_alen (sdb_members))) { goto error; } char *cur; sdb_aforeach (cur, sdb_members) { - char *type_key = r_str_newf ("union.%s.%s", sname, cur); + char *type_key = rz_str_newf ("union.%s.%s", sname, cur); if (!type_key) { goto error; } @@ -259,10 +259,10 @@ static RAnalBaseType *get_union_type(RAnal *anal, const char *sname) { goto error; } char *value = sdb_anext (values, NULL); - RAnalUnionMember cas = { .name = strdup (cur), .type = strdup (value) }; + RzAnalUnionMember cas = { .name = strdup (cur), .type = strdup (value) }; free (values); - void *element = r_vector_push (members, &cas); // returns null if no space available + void *element = rz_vector_push (members, &cas); // returns null if no space available if (!element) { goto error; } @@ -274,15 +274,15 @@ static RAnalBaseType *get_union_type(RAnal *anal, const char *sname) { return base_type; error: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); free (sdb_members); return NULL; } -static RAnalBaseType *get_typedef_type(RAnal *anal, const char *sname) { - r_return_val_if_fail (anal && R_STR_ISNOTEMPTY (sname), NULL); +static RzAnalBaseType *get_typedef_type(RzAnal *anal, const char *sname) { + rz_return_val_if_fail (anal && R_STR_ISNOTEMPTY (sname), NULL); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_TYPEDEF); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_TYPEDEF); if (!base_type) { return NULL; } @@ -294,14 +294,14 @@ static RAnalBaseType *get_typedef_type(RAnal *anal, const char *sname) { return base_type; error: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); return NULL; } -static RAnalBaseType *get_atomic_type(RAnal *anal, const char *sname) { - r_return_val_if_fail (anal && R_STR_ISNOTEMPTY (sname), NULL); +static RzAnalBaseType *get_atomic_type(RzAnal *anal, const char *sname) { + rz_return_val_if_fail (anal && R_STR_ISNOTEMPTY (sname), NULL); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ATOMIC); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ATOMIC); if (!base_type) { return NULL; } @@ -312,28 +312,28 @@ static RAnalBaseType *get_atomic_type(RAnal *anal, const char *sname) { } RStrBuf key; - base_type->size = sdb_num_get (anal->sdb_types, r_strbuf_initf (&key, "type.%s.size", sname), 0); - r_strbuf_fini (&key); + base_type->size = sdb_num_get (anal->sdb_types, rz_strbuf_initf (&key, "type.%s.size", sname), 0); + rz_strbuf_fini (&key); return base_type; error: - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); return NULL; } // returns NULL if name is not found or any failure happened -R_API RAnalBaseType *r_anal_get_base_type(RAnal *anal, const char *name) { - r_return_val_if_fail (anal && name, NULL); +RZ_API RzAnalBaseType *rz_anal_get_base_type(RzAnal *anal, const char *name) { + rz_return_val_if_fail (anal && name, NULL); - char *sname = r_str_sanitize_sdb_key (name); + char *sname = rz_str_sanitize_sdb_key (name); const char *type = sdb_const_get (anal->sdb_types, sname, NULL); if (!type) { free (sname); return NULL; } - RAnalBaseType *base_type = NULL; + RzAnalBaseType *base_type = NULL; if (!strcmp (type, "struct")) { base_type = get_struct_type (anal, sname); } else if (!strcmp (type, "enum")) { @@ -355,8 +355,8 @@ R_API RAnalBaseType *r_anal_get_base_type(RAnal *anal, const char *name) { return base_type; } -static void save_struct(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name +static void save_struct(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_STRUCT); char *kind = "struct"; /* @@ -369,43 +369,43 @@ static void save_struct(const RAnal *anal, const RAnalBaseType *type) { struct.name.param2=type,4,0 struct.name.paramN=type,8,0 */ - char *sname = r_str_sanitize_sdb_key (type->name); + char *sname = rz_str_sanitize_sdb_key (type->name); // name=struct sdb_set (anal->sdb_types, sname, kind, 0); RStrBuf arglist; RStrBuf param_key; RStrBuf param_val; - r_strbuf_init (&arglist); - r_strbuf_init (¶m_key); - r_strbuf_init (¶m_val); + rz_strbuf_init (&arglist); + rz_strbuf_init (¶m_key); + rz_strbuf_init (¶m_val); int i = 0; - RAnalStructMember *member; - r_vector_foreach (&type->struct_data.members, member) { + RzAnalStructMember *member; + rz_vector_foreach (&type->struct_data.members, member) { // struct.name.param=type,offset,argsize - char *member_sname = r_str_sanitize_sdb_key (member->name); + char *member_sname = rz_str_sanitize_sdb_key (member->name); sdb_set (anal->sdb_types, - r_strbuf_setf (¶m_key, "%s.%s.%s", kind, sname, member_sname), - r_strbuf_setf (¶m_val, "%s,%" PFMT64u ",%" PFMT64u "", member->type, member->offset, 0), 0); + rz_strbuf_setf (¶m_key, "%s.%s.%s", kind, sname, member_sname), + rz_strbuf_setf (¶m_val, "%s,%" PFMT64u ",%" PFMT64u "", member->type, member->offset, 0), 0); free (member_sname); - r_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", member->name); + rz_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", member->name); } // struct.name=param1,param2,paramN - char *key = r_str_newf ("%s.%s", kind, sname); - sdb_set (anal->sdb_types, key, r_strbuf_get (&arglist), 0); + char *key = rz_str_newf ("%s.%s", kind, sname); + sdb_set (anal->sdb_types, key, rz_strbuf_get (&arglist), 0); free (key); free (sname); - r_strbuf_fini (&arglist); - r_strbuf_fini (¶m_key); - r_strbuf_fini (¶m_val); + rz_strbuf_fini (&arglist); + rz_strbuf_fini (¶m_key); + rz_strbuf_fini (¶m_val); } -static void save_union(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name +static void save_union(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_UNION); const char *kind = "union"; /* @@ -418,43 +418,43 @@ static void save_union(const RAnal *anal, const RAnalBaseType *type) { union.name.param2=type,0,0 union.name.paramN=type,0,0 */ - char *sname = r_str_sanitize_sdb_key (type->name); + char *sname = rz_str_sanitize_sdb_key (type->name); // name=union sdb_set (anal->sdb_types, sname, kind, 0); RStrBuf arglist; RStrBuf param_key; RStrBuf param_val; - r_strbuf_init (&arglist); - r_strbuf_init (¶m_key); - r_strbuf_init (¶m_val); + rz_strbuf_init (&arglist); + rz_strbuf_init (¶m_key); + rz_strbuf_init (¶m_val); int i = 0; - RAnalUnionMember *member; - r_vector_foreach (&type->union_data.members, member) { + RzAnalUnionMember *member; + rz_vector_foreach (&type->union_data.members, member) { // union.name.arg1=type,offset,argsize - char *member_sname = r_str_sanitize_sdb_key (member->name); + char *member_sname = rz_str_sanitize_sdb_key (member->name); sdb_set (anal->sdb_types, - r_strbuf_setf (¶m_key, "%s.%s.%s", kind, sname, member_sname), - r_strbuf_setf (¶m_val, "%s,%" PFMT64u ",%" PFMT64u "", member->type, member->offset, 0), 0); + rz_strbuf_setf (¶m_key, "%s.%s.%s", kind, sname, member_sname), + rz_strbuf_setf (¶m_val, "%s,%" PFMT64u ",%" PFMT64u "", member->type, member->offset, 0), 0); free (member_sname); - r_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", member->name); + rz_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", member->name); } // union.name=arg1,arg2,argN - char *key = r_str_newf ("%s.%s", kind, sname); - sdb_set (anal->sdb_types, key, r_strbuf_get (&arglist), 0); + char *key = rz_str_newf ("%s.%s", kind, sname); + sdb_set (anal->sdb_types, key, rz_strbuf_get (&arglist), 0); free (key); free (sname); - r_strbuf_fini (&arglist); - r_strbuf_fini (¶m_key); - r_strbuf_fini (¶m_val); + rz_strbuf_fini (&arglist); + rz_strbuf_fini (¶m_key); + rz_strbuf_fini (¶m_val); } -static void save_enum(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name +static void save_enum(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_ENUM); /* C: @@ -469,46 +469,46 @@ static void save_enum(const RAnal *anal, const RAnalBaseType *type) { enum.MyEnum.arg2=0x63 enum.MyEnum.argN=0x3 */ - char *sname = r_str_sanitize_sdb_key (type->name); + char *sname = rz_str_sanitize_sdb_key (type->name); sdb_set (anal->sdb_types, sname, "enum", 0); RStrBuf arglist; RStrBuf param_key; RStrBuf param_val; - r_strbuf_init (&arglist); - r_strbuf_init (¶m_key); - r_strbuf_init (¶m_val); + rz_strbuf_init (&arglist); + rz_strbuf_init (¶m_key); + rz_strbuf_init (¶m_val); int i = 0; - RAnalEnumCase *cas; - r_vector_foreach (&type->enum_data.cases, cas) { + RzAnalEnumCase *cas; + rz_vector_foreach (&type->enum_data.cases, cas) { // enum.name.arg1=type,offset,??? - char *case_sname = r_str_sanitize_sdb_key (cas->name); + char *case_sname = rz_str_sanitize_sdb_key (cas->name); sdb_set (anal->sdb_types, - r_strbuf_setf (¶m_key, "enum.%s.%s", sname, case_sname), - r_strbuf_setf (¶m_val, "0x%" PFMT32x "", cas->val), 0); + rz_strbuf_setf (¶m_key, "enum.%s.%s", sname, case_sname), + rz_strbuf_setf (¶m_val, "0x%" PFMT32x "", cas->val), 0); sdb_set (anal->sdb_types, - r_strbuf_setf (¶m_key, "enum.%s.0x%" PFMT32x "", sname, cas->val), + rz_strbuf_setf (¶m_key, "enum.%s.0x%" PFMT32x "", sname, cas->val), case_sname, 0); free (case_sname); - r_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", cas->name); + rz_strbuf_appendf (&arglist, (i++ == 0) ? "%s" : ",%s", cas->name); } // enum.name=arg1,arg2,argN - char *key = r_str_newf ("enum.%s", sname); - sdb_set (anal->sdb_types, key, r_strbuf_get (&arglist), 0); + char *key = rz_str_newf ("enum.%s", sname); + sdb_set (anal->sdb_types, key, rz_strbuf_get (&arglist), 0); free (key); free (sname); - r_strbuf_fini (&arglist); - r_strbuf_fini (¶m_key); - r_strbuf_fini (¶m_val); + rz_strbuf_fini (&arglist); + rz_strbuf_fini (¶m_key); + rz_strbuf_fini (¶m_val); } -static void save_atomic_type(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name +static void save_atomic_type(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_ATOMIC); /* C: (cannot define a custom atomic type) @@ -517,29 +517,29 @@ static void save_atomic_type(const RAnal *anal, const RAnalBaseType *type) { type.char=c type.char.size=8 */ - char *sname = r_str_sanitize_sdb_key (type->name); + char *sname = rz_str_sanitize_sdb_key (type->name); sdb_set (anal->sdb_types, sname, "type", 0); RStrBuf key; RStrBuf val; - r_strbuf_init (&key); - r_strbuf_init (&val); + rz_strbuf_init (&key); + rz_strbuf_init (&val); sdb_set (anal->sdb_types, - r_strbuf_setf (&key, "type.%s.size", sname), - r_strbuf_setf (&val, "%" PFMT64u "", type->size), 0); + rz_strbuf_setf (&key, "type.%s.size", sname), + rz_strbuf_setf (&val, "%" PFMT64u "", type->size), 0); sdb_set (anal->sdb_types, - r_strbuf_setf (&key, "type.%s", sname), + rz_strbuf_setf (&key, "type.%s", sname), type->type, 0); free (sname); - r_strbuf_fini (&key); - r_strbuf_fini (&val); + rz_strbuf_fini (&key); + rz_strbuf_fini (&val); } -static void save_typedef(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_TYPEDEF); +static void save_typedef(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name && type->kind == R_ANAL_BASE_TYPE_KIND_TYPEDEF); /* C: typedef char byte; @@ -547,38 +547,38 @@ static void save_typedef(const RAnal *anal, const RAnalBaseType *type) { byte=typedef typedef.byte=char */ - char *sname = r_str_sanitize_sdb_key (type->name); + char *sname = rz_str_sanitize_sdb_key (type->name); sdb_set (anal->sdb_types, sname, "typedef", 0); RStrBuf key; RStrBuf val; - r_strbuf_init (&key); - r_strbuf_init (&val); + rz_strbuf_init (&key); + rz_strbuf_init (&val); sdb_set (anal->sdb_types, - r_strbuf_setf (&key, "typedef.%s", sname), - r_strbuf_setf (&val, "%s", type->type), 0); + rz_strbuf_setf (&key, "typedef.%s", sname), + rz_strbuf_setf (&val, "%s", type->type), 0); free (sname); - r_strbuf_fini (&key); - r_strbuf_fini (&val); + rz_strbuf_fini (&key); + rz_strbuf_fini (&val); } -R_API void r_anal_base_type_free(RAnalBaseType *type) { - r_return_if_fail (type); +RZ_API void rz_anal_base_type_free(RzAnalBaseType *type) { + rz_return_if_fail (type); R_FREE (type->name); R_FREE (type->type); switch (type->kind) { case R_ANAL_BASE_TYPE_KIND_STRUCT: - r_vector_fini (&type->struct_data.members); + rz_vector_fini (&type->struct_data.members); break; case R_ANAL_BASE_TYPE_KIND_UNION: - r_vector_fini (&type->union_data.members); + rz_vector_fini (&type->union_data.members); break; case R_ANAL_BASE_TYPE_KIND_ENUM: - r_vector_fini (&type->enum_data.cases); + rz_vector_fini (&type->enum_data.cases); break; case R_ANAL_BASE_TYPE_KIND_TYPEDEF: case R_ANAL_BASE_TYPE_KIND_ATOMIC: @@ -589,21 +589,21 @@ R_API void r_anal_base_type_free(RAnalBaseType *type) { R_FREE (type); } -R_API RAnalBaseType *r_anal_base_type_new(RAnalBaseTypeKind kind) { - RAnalBaseType *type = R_NEW0 (RAnalBaseType); +RZ_API RzAnalBaseType *rz_anal_base_type_new(RzAnalBaseTypeKind kind) { + RzAnalBaseType *type = R_NEW0 (RzAnalBaseType); if (!type) { return NULL; } type->kind = kind; switch (type->kind) { case R_ANAL_BASE_TYPE_KIND_STRUCT: - r_vector_init (&type->struct_data.members, sizeof (RAnalStructMember), struct_type_member_free, NULL); + rz_vector_init (&type->struct_data.members, sizeof (RzAnalStructMember), struct_type_member_free, NULL); break; case R_ANAL_BASE_TYPE_KIND_ENUM: - r_vector_init (&type->enum_data.cases, sizeof (RAnalEnumCase), enum_type_case_free, NULL); + rz_vector_init (&type->enum_data.cases, sizeof (RzAnalEnumCase), enum_type_case_free, NULL); break; case R_ANAL_BASE_TYPE_KIND_UNION: - r_vector_init (&type->union_data.members, sizeof (RAnalUnionMember), union_type_member_free, NULL); + rz_vector_init (&type->union_data.members, sizeof (RzAnalUnionMember), union_type_member_free, NULL); break; default: break; @@ -613,14 +613,14 @@ R_API RAnalBaseType *r_anal_base_type_new(RAnalBaseTypeKind kind) { } /** - * @brief Saves RAnalBaseType into the SDB + * @brief Saves RzAnalBaseType into the SDB * * @param anal - * @param type RAnalBaseType to save + * @param type RzAnalBaseType to save * @param name Name of the type */ -R_API void r_anal_save_base_type(const RAnal *anal, const RAnalBaseType *type) { - r_return_if_fail (anal && type && type->name); +RZ_API void rz_anal_save_base_type(const RzAnal *anal, const RzAnalBaseType *type) { + rz_return_if_fail (anal && type && type->name); // TODO, solve collisions, if there are 2 types with the same name and kind diff --git a/libr/anal/type_pdb.c b/librz/anal/type_pdb.c similarity index 65% rename from libr/anal/type_pdb.c rename to librz/anal/type_pdb.c index 6806b9203b..fdebf52152 100644 --- a/libr/anal/type_pdb.c +++ b/librz/anal/type_pdb.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include "../bin/pdb/types.h" #include "base_types.h" @@ -29,14 +29,14 @@ static char *create_type_name_from_offset(ut64 offset) { * * @param type_info Current type info (member) * @param types List of all types - * @return RAnalStructMember* parsed member, NULL if fail + * @return RzAnalStructMember* parsed member, NULL if fail */ -static RAnalStructMember *parse_member(STypeInfo *type_info, RList *types) { - r_return_val_if_fail (type_info && types, NULL); +static RzAnalStructMember *parse_member(STypeInfo *type_info, RzList *types) { + rz_return_val_if_fail (type_info && types, NULL); if (type_info->leaf_type != eLF_MEMBER) { return NULL; } - r_return_val_if_fail (type_info->get_name && + rz_return_val_if_fail (type_info->get_name && type_info->get_print_type && type_info->get_val, NULL); char *name = NULL; char *type = NULL; @@ -45,11 +45,11 @@ static RAnalStructMember *parse_member(STypeInfo *type_info, RList *types) { type_info->get_val (type_info, &offset); // gets offset type_info->get_name (type_info, &name); type_info->get_print_type (type_info, &type); - RAnalStructMember *member = R_NEW0 (RAnalStructMember); + RzAnalStructMember *member = R_NEW0 (RzAnalStructMember); if (!member) { goto cleanup; } - char *sname = r_str_sanitize_sdb_key (name); + char *sname = rz_str_sanitize_sdb_key (name); member->name = sname; member->type = strdup (type); // we assume it's sanitized member->offset = offset; @@ -63,22 +63,22 @@ cleanup: * * @param type_info Current type info (enum case) * @param types List of all types - * @return RAnalEnumCase* parsed enum case, NULL if fail + * @return RzAnalEnumCase* parsed enum case, NULL if fail */ -static RAnalEnumCase *parse_enumerate(STypeInfo *type_info, RList *types) { - r_return_val_if_fail (type_info && types && type_info->leaf_type == eLF_ENUMERATE, NULL); - r_return_val_if_fail (type_info->get_val && type_info->get_name, NULL); +static RzAnalEnumCase *parse_enumerate(STypeInfo *type_info, RzList *types) { + rz_return_val_if_fail (type_info && types && type_info->leaf_type == eLF_ENUMERATE, NULL); + rz_return_val_if_fail (type_info->get_val && type_info->get_name, NULL); char *name = NULL; int value = 0; // sometimes, the type doesn't have get_val for some reason type_info->get_val (type_info, &value); type_info->get_name (type_info, &name); - RAnalEnumCase *cas = R_NEW0 (RAnalEnumCase); + RzAnalEnumCase *cas = R_NEW0 (RzAnalEnumCase); if (!cas) { goto cleanup; } - char *sname = r_str_sanitize_sdb_key (name); + char *sname = rz_str_sanitize_sdb_key (name); cas->name = sname; cas->val = value; return cas; @@ -93,15 +93,15 @@ cleanup: * @param type Current type * @param types List of all types */ -static void parse_enum(const RAnal *anal, SType *type, RList *types) { - r_return_if_fail (anal && type && types); +static void parse_enum(const RzAnal *anal, SType *type, RzList *types) { + rz_return_if_fail (anal && type && types); STypeInfo *type_info = &type->type_data; // assert all member functions we need info from - r_return_if_fail (type_info->get_members && + rz_return_if_fail (type_info->get_members && type_info->get_name && type_info->get_utype); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_ENUM); if (!base_type) { return; } @@ -121,32 +121,32 @@ static void parse_enum(const RAnal *anal, SType *type, RList *types) { type_name = base_type->type; size = base_type->size; } - RList *members; + RzList *members; type_info->get_members (type_info, &members); - RListIter *it = r_list_iterator (members); - while (r_list_iter_next (it)) { - STypeInfo *member_info = r_list_iter_get (it); - RAnalEnumCase *enum_case = parse_enumerate (member_info, types); + RzListIter *it = rz_list_iterator (members); + while (rz_list_iter_next (it)) { + STypeInfo *member_info = rz_list_iter_get (it); + RzAnalEnumCase *enum_case = parse_enumerate (member_info, types); if (!enum_case) { continue; // skip it, move forward } - void *element = r_vector_push (&base_type->struct_data.members, enum_case); + void *element = rz_vector_push (&base_type->struct_data.members, enum_case); if (!element) { goto cleanup; } } - char *sname = r_str_sanitize_sdb_key (name); + char *sname = rz_str_sanitize_sdb_key (name); base_type->name = sname; base_type->size = size; base_type->type = strdup (type_name); // we assume it's sanitized - r_anal_save_base_type (anal, base_type); + rz_anal_save_base_type (anal, base_type); cleanup: if (to_free_name) { R_FREE (name); } - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); return; } @@ -157,16 +157,16 @@ cleanup: * @param type Current type * @param types List of all types */ -static void parse_structure(const RAnal *anal, SType *type, RList *types) { - r_return_if_fail (anal && type && types); +static void parse_structure(const RzAnal *anal, SType *type, RzList *types) { + rz_return_if_fail (anal && type && types); STypeInfo *type_info = &type->type_data; // assert all member functions we need info from - r_return_if_fail (type_info->get_members && + rz_return_if_fail (type_info->get_members && type_info->is_fwdref && type_info->get_name && type_info->get_val); - RAnalBaseType *base_type = r_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_STRUCT); + RzAnalBaseType *base_type = rz_anal_base_type_new (R_ANAL_BASE_TYPE_KIND_STRUCT); if (!base_type) { return; } @@ -181,17 +181,17 @@ static void parse_structure(const RAnal *anal, SType *type, RList *types) { int size; type_info->get_val (type_info, &size); // gets size - RList *members; + RzList *members; type_info->get_members (type_info, &members); - RListIter *it = r_list_iterator (members); - while (r_list_iter_next (it)) { - STypeInfo *member_info = r_list_iter_get (it); - RAnalStructMember *struct_member = parse_member (member_info, types); + RzListIter *it = rz_list_iterator (members); + while (rz_list_iter_next (it)) { + STypeInfo *member_info = rz_list_iter_get (it); + RzAnalStructMember *struct_member = parse_member (member_info, types); if (!struct_member) { continue; // skip the failure } - void *element = r_vector_push (&base_type->struct_data.members, struct_member); + void *element = rz_vector_push (&base_type->struct_data.members, struct_member); if (!element) { goto cleanup; } @@ -201,15 +201,15 @@ static void parse_structure(const RAnal *anal, SType *type, RList *types) { } else { // union base_type->kind = R_ANAL_BASE_TYPE_KIND_UNION; } - char *sname = r_str_sanitize_sdb_key (name); + char *sname = rz_str_sanitize_sdb_key (name); base_type->name = sname; base_type->size = size; - r_anal_save_base_type (anal, base_type); + rz_anal_save_base_type (anal, base_type); cleanup: if (to_free_name) { R_FREE (name); } - r_anal_base_type_free (base_type); + rz_anal_base_type_free (base_type); return; } @@ -220,8 +220,8 @@ cleanup: * @param type Current type * @param types List of all types */ -static void parse_type (const RAnal *anal, SType *type, RList *types) { - r_return_if_fail (anal && type && types); +static void parse_type (const RzAnal *anal, SType *type, RzList *types) { + rz_return_if_fail (anal && type && types); int is_forward_decl; if (type->type_data.is_fwdref) { @@ -253,18 +253,18 @@ static void parse_type (const RAnal *anal, SType *type, RList *types) { * @param anal * @param pdb PDB information */ -R_API void r_parse_pdb_types(const RAnal *anal, const RPdb *pdb) { - r_return_if_fail (anal && pdb); - RList *plist = pdb->pdb_streams; +RZ_API void rz_parse_pdb_types(const RzAnal *anal, const RPdb *pdb) { + rz_return_if_fail (anal && pdb); + RzList *plist = pdb->pdb_streams; // getting the TPI stream from the streams list - STpiStream *tpi_stream = r_list_get_n (plist, ePDB_STREAM_TPI); + STpiStream *tpi_stream = rz_list_get_n (plist, ePDB_STREAM_TPI); if (!tpi_stream) { // no TPI stream found return; } // Types should be DAC - only references previous records - RListIter *iter = r_list_iterator (tpi_stream->types); - while (r_list_iter_next (iter)) { // iterate all types - SType *type = r_list_iter_get (iter); + RzListIter *iter = rz_list_iterator (tpi_stream->types); + while (rz_list_iter_next (iter)) { // iterate all types + SType *type = rz_list_iter_get (iter); if (is_parsable_type (type->type_data.leaf_type)) { parse_type (anal, type, tpi_stream->types); } diff --git a/librz/anal/value.c b/librz/anal/value.c new file mode 100644 index 0000000000..35eab049bc --- /dev/null +++ b/librz/anal/value.c @@ -0,0 +1,125 @@ +/* radare - LGPL - Copyright 2010-2020 - pancake */ + +#include + +RZ_API RzAnalValue *rz_anal_value_new(void) { //macro for this ? + return R_NEW0 (RzAnalValue); +} + +RZ_API RzAnalValue *rz_anal_value_new_from_string(const char *str) { + /* TODO */ + return NULL; +} + +RZ_API RzAnalValue *rz_anal_value_copy(RzAnalValue *ov) { + rz_return_val_if_fail (ov, NULL); + + RzAnalValue *v = R_NEW0 (RzAnalValue); + if (!v) { + return NULL; + } + + memcpy (v, ov, sizeof (RzAnalValue)); + // reference to reg and regdelta should be kept + return v; +} + +// TODO: move into .h as #define free +RZ_API void rz_anal_value_free(RzAnalValue *value) { + free (value); +#if 0 + ut64 pval = (ut64)(size_t)value; + if (pval && pval != UT64_MAX) { + /* TODO: free RzRegItem objects? */ + free (value); + } +#endif +} + +// mul*value+regbase+regidx+delta +RZ_API ut64 rz_anal_value_to_ut64(RzAnal *anal, RzAnalValue *val) { + ut64 num; + if (!val) { + return 0LL; + } + num = val->base + (val->delta*(val->mul?val->mul:1)); + if (val->reg) { + num += rz_reg_get_value (anal->reg, val->reg); + } + if (val->regdelta) { + num += rz_reg_get_value (anal->reg, val->regdelta); + } + switch (val->memref) { + case 1: + case 2: + case 4: + case 8: + //anal->bio ... + eprintf ("TODO: memref for to_ut64 not supported\n"); + break; + } + return num; +} + +RZ_API int rz_anal_value_set_ut64(RzAnal *anal, RzAnalValue *val, ut64 num) { + if (val->memref) { + if (anal->iob.io) { + ut8 data[8]; + ut64 addr = rz_anal_value_to_ut64 (anal, val); + rz_mem_set_num (data, val->memref, num); + anal->iob.write_at (anal->iob.io, addr, data, val->memref); + } else { + eprintf ("No IO binded to rz_anal\n"); + } + } else { + if (val->reg) { + rz_reg_set_value (anal->reg, val->reg, num); + } + } + return false; //is this necessary +} + +RZ_API char *rz_anal_value_to_string (RzAnalValue *value) { + char *out = NULL; + if (value) { + out = rz_str_new (""); + if (!value->base && !value->reg) { + if (value->imm != -1LL) { + out = rz_str_appendf (out, "0x%"PFMT64x, value->imm); + } else { + out = rz_str_append (out, "-1"); + } + } else { + if (value->memref) { + switch (value->memref) { + case 1: out = rz_str_append (out, "(char)"); break; + case 2: out = rz_str_append (out, "(short)"); break; + case 4: out = rz_str_append (out, "(word)"); break; + case 8: out = rz_str_append (out, "(dword)"); break; + } + out = rz_str_append (out, "["); + } + if (value->mul) { + out = rz_str_appendf (out, "%d*", value->mul); + } + if (value->reg) { + out = rz_str_appendf (out, "%s", value->reg->name); + } + if (value->regdelta) { + out = rz_str_appendf (out, "+%s", value->regdelta->name); + } + if (value->base != 0) { + out = rz_str_appendf (out, "0x%" PFMT64x, value->base); + } + if (value->delta > 0) { + out = rz_str_appendf (out, "+0x%" PFMT64x, value->delta); + } else if (value->delta < 0) { + out = rz_str_appendf (out, "-0x%" PFMT64x, -value->delta); + } + if (value->memref) { + out = rz_str_append (out, "]"); + } + } + } + return out; +} diff --git a/libr/anal/var.c b/librz/anal/var.c similarity index 56% rename from libr/anal/var.c rename to librz/anal/var.c index 1208d78a89..9468700751 100644 --- a/libr/anal/var.c +++ b/librz/anal/var.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2010-2020 - pancake, oddcoder */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#define ACCESS_CMP(x, y) ((x) - ((RAnalVarAccess *)y)->offset) +#define ACCESS_CMP(x, y) ((x) - ((RzAnalVarAccess *)y)->offset) -R_API bool r_anal_var_display(RAnal *anal, RAnalVar *var) { - char *fmt = r_type_format (anal->sdb_types, var->type); - RRegItem *i; +RZ_API bool rz_anal_var_display(RzAnal *anal, RzAnalVar *var) { + char *fmt = rz_type_format (anal->sdb_types, var->type); + RzRegItem *i; if (!fmt) { eprintf ("type:%s doesn't exist\n", var->type); return false; @@ -18,7 +18,7 @@ R_API bool r_anal_var_display(RAnal *anal, RAnalVar *var) { bool usePxr = !strcmp (var->type, "int"); // hacky but useful switch (var->kind) { case R_ANAL_VAR_KIND_REG: - i = r_reg_index_get (anal->reg, var->delta); + i = rz_reg_index_get (anal->reg, var->delta); if (i) { if (usePxr) { anal->cb_printf ("pxr $w @r:%s\n", i->name); @@ -64,17 +64,17 @@ static const char *__int_type_from_size(int size) { } } -R_API bool r_anal_function_rebase_vars(RAnal *a, RAnalFunction *fcn) { - r_return_val_if_fail (a && fcn, false); - RListIter *it; - RAnalVar *var; - RList *var_list = r_anal_var_all_list (a, fcn); - r_return_val_if_fail (var_list, false); +RZ_API bool rz_anal_function_rebase_vars(RzAnal *a, RzAnalFunction *fcn) { + rz_return_val_if_fail (a && fcn, false); + RzListIter *it; + RzAnalVar *var; + RzList *var_list = rz_anal_var_all_list (a, fcn); + rz_return_val_if_fail (var_list, false); - r_list_foreach (var_list, it, var) { + rz_list_foreach (var_list, it, var) { // Resync delta in case the registers list changed if (var->isarg && var->kind == 'r') { - RRegItem *reg = r_reg_get (a->reg, var->regname, -1); + RzRegItem *reg = rz_reg_get (a->reg, var->regname, -1); if (reg) { if (var->delta != reg->index) { var->delta = reg->index; @@ -83,19 +83,19 @@ R_API bool r_anal_function_rebase_vars(RAnal *a, RAnalFunction *fcn) { } } - r_list_free (var_list); + rz_list_free (var_list); return true; } // If the type of var is a struct, // remove all other vars that are overlapped by var and are at the offset of one of its struct members -static void shadow_var_struct_members(RAnalVar *var) { +static void shadow_var_struct_members(RzAnalVar *var) { Sdb *TDB = var->fcn->anal->sdb_types; const char *type_kind = sdb_const_get (TDB, var->type, 0); - if (type_kind && r_str_startswith (type_kind, "struct")) { + if (type_kind && rz_str_startswith (type_kind, "struct")) { char *field; int field_n; - char *type_key = r_str_newf ("%s.%s", type_kind, var->type); + char *type_key = rz_str_newf ("%s.%s", type_kind, var->type); for (field_n = 0; (field = sdb_array_get (TDB, type_key, field_n, NULL)); field_n++) { char field_key[0x300]; if (snprintf (field_key, sizeof (field_key), "%s.%s", type_key, field) < 0) { @@ -104,9 +104,9 @@ static void shadow_var_struct_members(RAnalVar *var) { char *field_type = sdb_array_get (TDB, field_key, 0, NULL); ut64 field_offset = sdb_array_get_num (TDB, field_key, 1, NULL); if (field_offset != 0) { // delete variables which are overlaid by structure - RAnalVar *other = r_anal_function_get_var (var->fcn, var->kind, var->delta + field_offset); + RzAnalVar *other = rz_anal_function_get_var (var->fcn, var->kind, var->delta + field_offset); if (other && other != var) { - r_anal_var_delete (other); + rz_anal_var_delete (other); } } free (field_type); @@ -116,14 +116,14 @@ static void shadow_var_struct_members(RAnalVar *var) { } } -R_API RAnalVar *r_anal_function_set_var(RAnalFunction *fcn, int delta, char kind, R_NULLABLE const char *type, int size, bool isarg, R_NONNULL const char *name) { - r_return_val_if_fail (fcn && name, NULL); - RAnalVar *existing = r_anal_function_get_var_byname (fcn, name); +RZ_API RzAnalVar *rz_anal_function_set_var(RzAnalFunction *fcn, int delta, char kind, R_NULLABLE const char *type, int size, bool isarg, R_NONNULL const char *name) { + rz_return_val_if_fail (fcn && name, NULL); + RzAnalVar *existing = rz_anal_function_get_var_byname (fcn, name); if (existing && (existing->kind != kind || existing->delta != delta)) { // var name already exists at a different kind+delta return NULL; } - RRegItem *reg = NULL; + RzRegItem *reg = NULL; if (!kind) { kind = R_ANAL_VAR_KIND_BPV; } @@ -146,22 +146,22 @@ R_API RAnalVar *r_anal_function_set_var(RAnalFunction *fcn, int delta, char kind return NULL; } if (kind == R_ANAL_VAR_KIND_REG) { - reg = r_reg_index_get (fcn->anal->reg, R_ABS (delta)); + reg = rz_reg_index_get (fcn->anal->reg, R_ABS (delta)); if (!reg) { eprintf ("Register wasn't found at the given delta\n"); return NULL; } } - RAnalVar *var = r_anal_function_get_var (fcn, kind, delta); + RzAnalVar *var = rz_anal_function_get_var (fcn, kind, delta); if (!var) { - var = R_NEW0 (RAnalVar); + var = R_NEW0 (RzAnalVar); if (!var) { return NULL; } - r_pvector_push (&fcn->vars, var); + rz_pvector_push (&fcn->vars, var); var->fcn = fcn; - r_vector_init (&var->accesses, sizeof (RAnalVarAccess), NULL, NULL); - r_vector_init (&var->constraints, sizeof (RAnalVarConstraint), NULL, NULL); + rz_vector_init (&var->accesses, sizeof (RzAnalVarAccess), NULL, NULL); + rz_vector_init (&var->constraints, sizeof (RzAnalVarConstraint), NULL, NULL); } else { free (var->name); free (var->regname); @@ -177,7 +177,7 @@ R_API RAnalVar *r_anal_function_set_var(RAnalFunction *fcn, int delta, char kind return var; } -R_API void r_anal_var_set_type(RAnalVar *var, const char *type) { +RZ_API void rz_anal_var_set_type(RzAnalVar *var, const char *type) { char *nt = strdup (type); if (!nt) { return; @@ -187,12 +187,12 @@ R_API void r_anal_var_set_type(RAnalVar *var, const char *type) { shadow_var_struct_members (var); } -static void var_free(RAnalVar *var) { +static void var_free(RzAnalVar *var) { if (!var) { return; } - r_anal_var_clear_accesses (var); - r_vector_fini (&var->constraints); + rz_anal_var_clear_accesses (var); + rz_vector_fini (&var->constraints); free (var->name); free (var->regname); free (var->type); @@ -200,27 +200,27 @@ static void var_free(RAnalVar *var) { free (var); } -R_API void r_anal_var_delete(RAnalVar *var) { - r_return_if_fail (var); - RAnalFunction *fcn = var->fcn; +RZ_API void rz_anal_var_delete(RzAnalVar *var) { + rz_return_if_fail (var); + RzAnalFunction *fcn = var->fcn; size_t i; - for (i = 0; i < r_pvector_len (&fcn->vars); i++) { - RAnalVar *v = r_pvector_at (&fcn->vars, i); + for (i = 0; i < rz_pvector_len (&fcn->vars); i++) { + RzAnalVar *v = rz_pvector_at (&fcn->vars, i); if (v == var) { - r_pvector_remove_at (&fcn->vars, i); + rz_pvector_remove_at (&fcn->vars, i); var_free (v); return; } } } -R_API void r_anal_function_delete_vars_by_kind(RAnalFunction *fcn, RAnalVarKind kind) { - r_return_if_fail (fcn); +RZ_API void rz_anal_function_delete_vars_by_kind(RzAnalFunction *fcn, RzAnalVarKind kind) { + rz_return_if_fail (fcn); size_t i; - for (i = 0; i < r_pvector_len (&fcn->vars);) { - RAnalVar *var = r_pvector_at (&fcn->vars, i); + for (i = 0; i < rz_pvector_len (&fcn->vars);) { + RzAnalVar *var = rz_pvector_at (&fcn->vars, i); if (var->kind == kind) { - r_pvector_remove_at (&fcn->vars, i); + rz_pvector_remove_at (&fcn->vars, i); var_free (var); continue; } @@ -228,25 +228,25 @@ R_API void r_anal_function_delete_vars_by_kind(RAnalFunction *fcn, RAnalVarKind } } -R_API void r_anal_function_delete_all_vars(RAnalFunction *fcn) { +RZ_API void rz_anal_function_delete_all_vars(RzAnalFunction *fcn) { void **it; - r_pvector_foreach (&fcn->vars, it) { + rz_pvector_foreach (&fcn->vars, it) { var_free (*it); } - r_pvector_clear (&fcn->vars); + rz_pvector_clear (&fcn->vars); } -R_API void r_anal_function_delete_var(RAnalFunction *fcn, RAnalVar *var) { - r_return_if_fail (fcn && var); - r_pvector_remove_data (&fcn->vars, var); +RZ_API void rz_anal_function_delete_var(RzAnalFunction *fcn, RzAnalVar *var) { + rz_return_if_fail (fcn && var); + rz_pvector_remove_data (&fcn->vars, var); var_free (var); } -R_API R_BORROW RAnalVar *r_anal_function_get_var_byname(RAnalFunction *fcn, const char *name) { - r_return_val_if_fail (fcn && name, NULL); +RZ_API R_BORROW RzAnalVar *rz_anal_function_get_var_byname(RzAnalFunction *fcn, const char *name) { + rz_return_val_if_fail (fcn && name, NULL); void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (!strcmp (var->name, name)) { return var; } @@ -254,10 +254,10 @@ R_API R_BORROW RAnalVar *r_anal_function_get_var_byname(RAnalFunction *fcn, cons return NULL; } -R_API RAnalVar *r_anal_function_get_var(RAnalFunction *fcn, char kind, int delta) { +RZ_API RzAnalVar *rz_anal_function_get_var(RzAnalFunction *fcn, char kind, int delta) { void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (var->kind == kind && var->delta == delta) { return var; } @@ -265,30 +265,30 @@ R_API RAnalVar *r_anal_function_get_var(RAnalFunction *fcn, char kind, int delta return NULL; } -R_API ut64 r_anal_var_addr(RAnalVar *var) { - r_return_val_if_fail (var, UT64_MAX); - RAnal *anal = var->fcn->anal; +RZ_API ut64 rz_anal_var_addr(RzAnalVar *var) { + rz_return_val_if_fail (var, UT64_MAX); + RzAnal *anal = var->fcn->anal; const char *regname = NULL; if (var->kind == R_ANAL_VAR_KIND_BPV) { - regname = r_reg_get_name (anal->reg, R_REG_NAME_BP); - return r_reg_getv (anal->reg, regname) + var->delta + var->fcn->bp_off; + regname = rz_reg_get_name (anal->reg, R_REG_NAME_BP); + return rz_reg_getv (anal->reg, regname) + var->delta + var->fcn->bp_off; } else if (var->kind == R_ANAL_VAR_KIND_SPV) { - regname = r_reg_get_name (anal->reg, R_REG_NAME_SP); - return r_reg_getv (anal->reg, regname) + var->delta; + regname = rz_reg_get_name (anal->reg, R_REG_NAME_SP); + return rz_reg_getv (anal->reg, regname) + var->delta; } return 0; } -R_API st64 r_anal_function_get_var_stackptr_at(RAnalFunction *fcn, st64 delta, ut64 addr) { +RZ_API st64 rz_anal_function_get_var_stackptr_at(RzAnalFunction *fcn, st64 delta, ut64 addr) { st64 offset = (st64)addr - (st64)fcn->addr; RPVector *inst_accesses = ht_up_find (fcn->inst_vars, offset, NULL); if (!inst_accesses) { return ST64_MAX; } - RAnalVar *var = NULL; + RzAnalVar *var = NULL; void **it; - r_pvector_foreach (inst_accesses, it) { - RAnalVar *v = *it; + rz_pvector_foreach (inst_accesses, it) { + RzAnalVar *v = *it; if (v->delta == delta) { var = v; break; @@ -298,10 +298,10 @@ R_API st64 r_anal_function_get_var_stackptr_at(RAnalFunction *fcn, st64 delta, u return ST64_MAX; } size_t index; - r_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); - RAnalVarAccess *acc = NULL; + rz_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); + RzAnalVarAccess *acc = NULL; if (index < var->accesses.len) { - acc = r_vector_index_ptr (&var->accesses, index); + acc = rz_vector_index_ptr (&var->accesses, index); } if (!acc || acc->offset != offset) { return ST64_MAX; @@ -309,16 +309,16 @@ R_API st64 r_anal_function_get_var_stackptr_at(RAnalFunction *fcn, st64 delta, u return acc->stackptr; } -R_API const char *r_anal_function_get_var_reg_at(RAnalFunction *fcn, st64 delta, ut64 addr) { +RZ_API const char *rz_anal_function_get_var_reg_at(RzAnalFunction *fcn, st64 delta, ut64 addr) { st64 offset = (st64)addr - (st64)fcn->addr; RPVector *inst_accesses = ht_up_find (fcn->inst_vars, offset, NULL); if (!inst_accesses) { return NULL; } - RAnalVar *var = NULL; + RzAnalVar *var = NULL; void **it; - r_pvector_foreach (inst_accesses, it) { - RAnalVar *v = *it; + rz_pvector_foreach (inst_accesses, it) { + RzAnalVar *v = *it; if (v->delta == delta) { var = v; break; @@ -328,10 +328,10 @@ R_API const char *r_anal_function_get_var_reg_at(RAnalFunction *fcn, st64 delta, return NULL; } size_t index; - r_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); - RAnalVarAccess *acc = NULL; + rz_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); + RzAnalVarAccess *acc = NULL; if (index < var->accesses.len) { - acc = r_vector_index_ptr (&var->accesses, index); + acc = rz_vector_index_ptr (&var->accesses, index); } if (!acc || acc->offset != offset) { return NULL; @@ -339,16 +339,16 @@ R_API const char *r_anal_function_get_var_reg_at(RAnalFunction *fcn, st64 delta, return acc->reg; } -R_API bool r_anal_var_check_name(const char *name) { +RZ_API bool rz_anal_var_check_name(const char *name) { return !isdigit (*name) && strcspn (name, "., =/"); } -R_API bool r_anal_var_rename(RAnalVar *var, const char *new_name, bool verbose) { - r_return_val_if_fail (var, false); - if (!r_anal_var_check_name (new_name)) { +RZ_API bool rz_anal_var_rename(RzAnalVar *var, const char *new_name, bool verbose) { + rz_return_val_if_fail (var, false); + if (!rz_anal_var_check_name (new_name)) { return false; } - RAnalVar *v1 = r_anal_function_get_var_byname (var->fcn, new_name); + RzAnalVar *v1 = rz_anal_function_get_var_byname (var->fcn, new_name); if (v1) { if (verbose) { eprintf ("variable or arg with name `%s` already exist\n", new_name); @@ -364,23 +364,23 @@ R_API bool r_anal_var_rename(RAnalVar *var, const char *new_name, bool verbose) return true; } -R_API int r_anal_var_get_argnum(RAnalVar *var) { - r_return_val_if_fail (var, -1); - RAnal *anal = var->fcn->anal; +RZ_API int rz_anal_var_get_argnum(RzAnalVar *var) { + rz_return_val_if_fail (var, -1); + RzAnal *anal = var->fcn->anal; if (!var->isarg || var->kind != R_ANAL_VAR_KIND_REG) { // TODO: support bp and sp too return -1; } if (!var->regname) { return -1; } - RRegItem *reg = r_reg_get (anal->reg, var->regname, -1); + RzRegItem *reg = rz_reg_get (anal->reg, var->regname, -1); if (!reg) { return -1; } int i; - int arg_max = var->fcn->cc ? r_anal_cc_max_arg (anal, var->fcn->cc) : 0; + int arg_max = var->fcn->cc ? rz_anal_cc_max_arg (anal, var->fcn->cc) : 0; for (i = 0; i < arg_max; i++) { - const char *reg_arg = r_anal_cc_arg (anal, var->fcn->cc, i); + const char *reg_arg = rz_anal_cc_arg (anal, var->fcn->cc, i); if (reg_arg && !strcmp (reg->name, reg_arg)) { return i; } @@ -388,46 +388,46 @@ R_API int r_anal_var_get_argnum(RAnalVar *var) { return -1; } -R_API R_BORROW RPVector *r_anal_function_get_vars_used_at(RAnalFunction *fcn, ut64 op_addr) { - r_return_val_if_fail (fcn, NULL); +RZ_API R_BORROW RPVector *rz_anal_function_get_vars_used_at(RzAnalFunction *fcn, ut64 op_addr) { + rz_return_val_if_fail (fcn, NULL); return ht_up_find (fcn->inst_vars, (st64)op_addr - (st64)fcn->addr, NULL); } -R_API R_DEPRECATE RAnalVar *r_anal_get_used_function_var(RAnal *anal, ut64 addr) { - RList *fcns = r_anal_get_functions_in (anal, addr); +RZ_API R_DEPRECATE RzAnalVar *rz_anal_get_used_function_var(RzAnal *anal, ut64 addr) { + RzList *fcns = rz_anal_get_functions_in (anal, addr); if (!fcns) { return NULL; } - RAnalVar *var = NULL; - RListIter *it; - RAnalFunction *fcn; - r_list_foreach (fcns, it, fcn) { - RPVector *used_vars = r_anal_function_get_vars_used_at (fcn, addr); - if (used_vars && !r_pvector_empty (used_vars)) { - var = r_pvector_at (used_vars, 0); + RzAnalVar *var = NULL; + RzListIter *it; + RzAnalFunction *fcn; + rz_list_foreach (fcns, it, fcn) { + RPVector *used_vars = rz_anal_function_get_vars_used_at (fcn, addr); + if (used_vars && !rz_pvector_empty (used_vars)) { + var = rz_pvector_at (used_vars, 0); break; } } - r_list_free (fcns); + rz_list_free (fcns); return var; } -R_API RAnalVar *r_anal_var_get_dst_var(RAnalVar *var) { - r_return_val_if_fail (var, NULL); - RAnalVarAccess *acc; - r_vector_foreach (&var->accesses, acc) { +RZ_API RzAnalVar *rz_anal_var_get_dst_var(RzAnalVar *var) { + rz_return_val_if_fail (var, NULL); + RzAnalVarAccess *acc; + rz_vector_foreach (&var->accesses, acc) { if (!(acc->type & R_ANAL_VAR_ACCESS_TYPE_READ)) { continue; } ut64 addr = var->fcn->addr + acc->offset; - RPVector *used_vars = r_anal_function_get_vars_used_at (var->fcn, addr); + RPVector *used_vars = rz_anal_function_get_vars_used_at (var->fcn, addr); void **it; - r_pvector_foreach (used_vars, it) { - RAnalVar *used_var = *it; + rz_pvector_foreach (used_vars, it) { + RzAnalVar *used_var = *it; if (used_var == var) { continue; } - RAnalVarAccess *other_acc = r_anal_var_get_access_at (used_var, addr); + RzAnalVarAccess *other_acc = rz_anal_var_get_access_at (used_var, addr); if (other_acc && other_acc->type & R_ANAL_VAR_ACCESS_TYPE_WRITE) { return used_var; } @@ -436,22 +436,22 @@ R_API RAnalVar *r_anal_var_get_dst_var(RAnalVar *var) { return NULL; } -R_API void r_anal_var_set_access(RAnalVar *var, const char *reg, ut64 access_addr, int access_type, st64 stackptr) { - r_return_if_fail (var); +RZ_API void rz_anal_var_set_access(RzAnalVar *var, const char *reg, ut64 access_addr, int access_type, st64 stackptr) { + rz_return_if_fail (var); st64 offset = (st64)access_addr - (st64)var->fcn->addr; // accesses are stored ordered by offset, use binary search to get the matching existing or the index to insert a new one size_t index; - r_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); - RAnalVarAccess *acc = NULL; + rz_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); + RzAnalVarAccess *acc = NULL; if (index < var->accesses.len) { - acc = r_vector_index_ptr (&var->accesses, index); + acc = rz_vector_index_ptr (&var->accesses, index); } if (!acc || acc->offset != offset) { - acc = r_vector_insert (&var->accesses, index, NULL); + acc = rz_vector_insert (&var->accesses, index, NULL); acc->offset = offset; acc->type = 0; - acc->reg = r_str_constpool_get (&var->fcn->anal->constpool, reg); + acc->reg = rz_str_constpool_get (&var->fcn->anal->constpool, reg); } acc->type |= (ut8)access_type; @@ -460,151 +460,151 @@ R_API void r_anal_var_set_access(RAnalVar *var, const char *reg, ut64 access_add // add the inverse reference from the instruction to the var RPVector *inst_accesses = ht_up_find (var->fcn->inst_vars, (ut64)offset, NULL); if (!inst_accesses) { - inst_accesses = r_pvector_new (NULL); + inst_accesses = rz_pvector_new (NULL); if (!inst_accesses) { return; } ht_up_insert (var->fcn->inst_vars, (ut64)offset, inst_accesses); } - if (!r_pvector_contains (inst_accesses, var)) { - r_pvector_push (inst_accesses, var); + if (!rz_pvector_contains (inst_accesses, var)) { + rz_pvector_push (inst_accesses, var); } } -R_API void r_anal_var_remove_access_at(RAnalVar *var, ut64 address) { - r_return_if_fail (var); +RZ_API void rz_anal_var_remove_access_at(RzAnalVar *var, ut64 address) { + rz_return_if_fail (var); st64 offset = (st64)address - (st64)var->fcn->addr; size_t index; - r_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); + rz_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); if (index >= var->accesses.len) { return; } - RAnalVarAccess *acc = r_vector_index_ptr (&var->accesses, index); + RzAnalVarAccess *acc = rz_vector_index_ptr (&var->accesses, index); if (acc->offset == offset) { - r_vector_remove_at (&var->accesses, index, NULL); + rz_vector_remove_at (&var->accesses, index, NULL); RPVector *inst_accesses = ht_up_find (var->fcn->inst_vars, (ut64)offset, NULL); - r_pvector_remove_data (inst_accesses, var); + rz_pvector_remove_data (inst_accesses, var); } } -R_API void r_anal_var_clear_accesses(RAnalVar *var) { - r_return_if_fail (var); - RAnalFunction *fcn = var->fcn; +RZ_API void rz_anal_var_clear_accesses(RzAnalVar *var) { + rz_return_if_fail (var); + RzAnalFunction *fcn = var->fcn; if (fcn->inst_vars) { // remove all inverse references to the var's accesses - RAnalVarAccess *acc; - r_vector_foreach (&var->accesses, acc) { + RzAnalVarAccess *acc; + rz_vector_foreach (&var->accesses, acc) { RPVector *inst_accesses = ht_up_find (fcn->inst_vars, (ut64)acc->offset, NULL); if (!inst_accesses) { continue; } - r_pvector_remove_data (inst_accesses, var); + rz_pvector_remove_data (inst_accesses, var); } } - r_vector_clear (&var->accesses); + rz_vector_clear (&var->accesses); } -R_API RAnalVarAccess *r_anal_var_get_access_at(RAnalVar *var, ut64 addr) { - r_return_val_if_fail (var, NULL); +RZ_API RzAnalVarAccess *rz_anal_var_get_access_at(RzAnalVar *var, ut64 addr) { + rz_return_val_if_fail (var, NULL); st64 offset = (st64)addr - (st64)var->fcn->addr; size_t index; - r_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); + rz_vector_lower_bound (&var->accesses, offset, index, ACCESS_CMP); if (index >= var->accesses.len) { return NULL; } - RAnalVarAccess *acc = r_vector_index_ptr (&var->accesses, index); + RzAnalVarAccess *acc = rz_vector_index_ptr (&var->accesses, index); if (acc->offset == offset) { return acc; } return NULL; } -R_API void r_anal_var_add_constraint(RAnalVar *var, R_BORROW RAnalVarConstraint *constraint) { - r_vector_push (&var->constraints, constraint); +RZ_API void rz_anal_var_add_constraint(RzAnalVar *var, R_BORROW RzAnalVarConstraint *constraint) { + rz_vector_push (&var->constraints, constraint); } -R_API char *r_anal_var_get_constraints_readable(RAnalVar *var) { +RZ_API char *rz_anal_var_get_constraints_readable(RzAnalVar *var) { size_t n = var->constraints.len; if (!n) { return NULL; } bool low = false, high = false; RStrBuf sb; - r_strbuf_init (&sb); + rz_strbuf_init (&sb); size_t i; for (i = 0; i < n; i += 1) { - RAnalVarConstraint *constr = r_vector_index_ptr (&var->constraints, i); + RzAnalVarConstraint *constr = rz_vector_index_ptr (&var->constraints, i); switch (constr->cond) { case R_ANAL_COND_LE: if (high) { - r_strbuf_append (&sb, " && "); + rz_strbuf_append (&sb, " && "); } - r_strbuf_appendf (&sb, "<= 0x%"PFMT64x "", constr->val); + rz_strbuf_appendf (&sb, "<= 0x%"PFMT64x "", constr->val); low = true; break; case R_ANAL_COND_LT: if (high) { - r_strbuf_append (&sb, " && "); + rz_strbuf_append (&sb, " && "); } - r_strbuf_appendf (&sb, "< 0x%"PFMT64x "", constr->val); + rz_strbuf_appendf (&sb, "< 0x%"PFMT64x "", constr->val); low = true; break; case R_ANAL_COND_GE: - r_strbuf_appendf (&sb, ">= 0x%"PFMT64x "", constr->val); + rz_strbuf_appendf (&sb, ">= 0x%"PFMT64x "", constr->val); high = true; break; case R_ANAL_COND_GT: - r_strbuf_appendf (&sb, "> 0x%"PFMT64x "", constr->val); + rz_strbuf_appendf (&sb, "> 0x%"PFMT64x "", constr->val); high = true; break; default: break; } if (low && high && i != n - 1) { - r_strbuf_append (&sb, " || "); + rz_strbuf_append (&sb, " || "); low = false; high = false; } } - return r_strbuf_drain_nofree (&sb); + return rz_strbuf_drain_nofree (&sb); } -R_API int r_anal_var_count(RAnal *a, RAnalFunction *fcn, int kind, int type) { +RZ_API int rz_anal_var_count(RzAnal *a, RzAnalFunction *fcn, int kind, int type) { // type { local: 0, arg: 1 }; - RList *list = r_anal_var_list (a, fcn, kind); - RAnalVar *var; - RListIter *iter; + RzList *list = rz_anal_var_list (a, fcn, kind); + RzAnalVar *var; + RzListIter *iter; int count[2] = { 0 }; - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { if (kind == R_ANAL_VAR_KIND_REG) { count[1]++; continue; } count[var->isarg]++; } - r_list_free (list); + rz_list_free (list); return count[type]; } -static bool var_add_structure_fields_to_list(RAnal *a, RAnalVar *av, RList *list) { +static bool var_add_structure_fields_to_list(RzAnal *a, RzAnalVar *av, RzList *list) { Sdb *TDB = a->sdb_types; const char *type_kind = sdb_const_get (TDB, av->type, 0); if (type_kind && !strcmp (type_kind, "struct")) { char *field_name, *new_name; int field_n; - char *type_key = r_str_newf ("%s.%s", type_kind, av->type); + char *type_key = rz_str_newf ("%s.%s", type_kind, av->type); for (field_n = 0; (field_name = sdb_array_get (TDB, type_key, field_n, NULL)); field_n++) { - char *field_key = r_str_newf ("%s.%s", type_key, field_name); + char *field_key = rz_str_newf ("%s.%s", type_key, field_name); char *field_type = sdb_array_get (TDB, field_key, 0, NULL); ut64 field_offset = sdb_array_get_num (TDB, field_key, 1, NULL); - new_name = r_str_newf ("%s.%s", av->name, field_name); - RAnalVarField *field = R_NEW0 (RAnalVarField); + new_name = rz_str_newf ("%s.%s", av->name, field_name); + RzAnalVarField *field = R_NEW0 (RzAnalVarField); field->name = new_name; field->delta = av->delta + field_offset; field->field = true; - r_list_append (list, field); + rz_list_append (list, field); free (field_type); free (field_key); free (field_name); @@ -615,46 +615,46 @@ static bool var_add_structure_fields_to_list(RAnal *a, RAnalVar *av, RList *list return false; } -static const char *get_regname(RAnal *anal, RAnalValue *value) { +static const char *get_regname(RzAnal *anal, RzAnalValue *value) { const char *name = NULL; if (value && value->reg && value->reg->name) { name = value->reg->name; - RRegItem *ri = r_reg_get (anal->reg, value->reg->name, -1); + RzRegItem *ri = rz_reg_get (anal->reg, value->reg->name, -1); if (ri && (ri->size == 32) && (anal->bits == 64)) { - name = r_reg_32_to_64 (anal->reg, value->reg->name); + name = rz_reg_32_to_64 (anal->reg, value->reg->name); } } return name; } -R_API R_OWN char *r_anal_function_autoname_var(RAnalFunction *fcn, char kind, const char *pfx, int ptr) { +RZ_API R_OWN char *rz_anal_function_autoname_var(RzAnalFunction *fcn, char kind, const char *pfx, int ptr) { void **it; const ut32 uptr = R_ABS (ptr); - char *varname = r_str_newf ("%s_%xh", pfx, uptr); - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + char *varname = rz_str_newf ("%s_%xh", pfx, uptr); + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (!strcmp (varname, var->name)) { if (var->kind != kind) { const char *k = kind == R_ANAL_VAR_KIND_SPV ? "sp" : "bp"; free (varname); - varname = r_str_newf ("%s_%s_%xh", pfx, k, uptr); + varname = rz_str_newf ("%s_%s_%xh", pfx, k, uptr); return varname; } int i = 2; do { free (varname); - varname = r_str_newf ("%s_%xh_%u", pfx, uptr, i++); - } while (r_anal_function_get_var_byname (fcn, varname)); + varname = rz_str_newf ("%s_%xh_%u", pfx, uptr, i++); + } while (rz_anal_function_get_var_byname (fcn, varname)); return varname; } } return varname; } -static RAnalVar *get_stack_var(RAnalFunction *fcn, int delta) { +static RzAnalVar *get_stack_var(RzAnalFunction *fcn, int delta) { void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; bool is_stack = var->kind == R_ANAL_VAR_KIND_SPV || var->kind == R_ANAL_VAR_KIND_BPV; if (is_stack && var->delta == delta) { return var; @@ -663,11 +663,11 @@ static RAnalVar *get_stack_var(RAnalFunction *fcn, int delta) { return NULL; } -static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char *reg, const char *sign, char type) { +static void extract_arg(RzAnal *anal, RzAnalFunction *fcn, RzAnalOp *op, const char *reg, const char *sign, char type) { st64 ptr = 0; char *addr, *esil_buf = NULL; - r_return_if_fail (anal && fcn && op && reg); + rz_return_if_fail (anal && fcn && op && reg); size_t i; for (i = 0; i < R_ARRAY_SIZE (op->src); i++) { @@ -683,7 +683,7 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char } if (!ptr) { - const char *op_esil = r_strbuf_get (&op->esil); + const char *op_esil = rz_strbuf_get (&op->esil); if (!op_esil) { return; } @@ -704,8 +704,8 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char if (strncmp (addr, "0x", 2)) { //XXX: This is a workaround for inconsistent esil if (!op->stackop && op->dst) { - const char *sp = r_reg_get_name (anal->reg, R_REG_NAME_SP); - const char *bp = r_reg_get_name (anal->reg, R_REG_NAME_BP); + const char *sp = rz_reg_get_name (anal->reg, R_REG_NAME_SP); + const char *bp = rz_reg_get_name (anal->reg, R_REG_NAME_BP); const char *rn = op->dst->reg ? op->dst->reg->name : NULL; if (rn && ((bp && !strcmp (bp, rn)) || (sp && !strcmp (sp, rn)))) { if (anal->verbose) { @@ -718,8 +718,8 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char addr++; } if (!op->stackop && op->type != R_ANAL_OP_TYPE_PUSH && op->type != R_ANAL_OP_TYPE_POP - && op->type != R_ANAL_OP_TYPE_RET && r_str_isnumber (addr)) { - ptr = (st64)r_num_get (NULL, addr); + && op->type != R_ANAL_OP_TYPE_RET && rz_str_isnumber (addr)) { + ptr = (st64)rz_num_get (NULL, addr); if (ptr && op->src[0] && ptr == op->src[0]->imm) { goto beach; } @@ -732,7 +732,7 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char goto beach; } } else { - ptr = (st64)r_num_get (NULL, addr); + ptr = (st64)rz_num_get (NULL, addr); } } @@ -750,39 +750,39 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char } else { frame_off = ptr - fcn->bp_off; } - RAnalVar *var = get_stack_var (fcn, frame_off); + RzAnalVar *var = get_stack_var (fcn, frame_off); if (var) { - r_anal_var_set_access (var, reg, op->addr, rw, ptr); + rz_anal_var_set_access (var, reg, op->addr, rw, ptr); goto beach; } char *varname = NULL, *vartype = NULL; if (isarg) { - const char *place = fcn->cc ? r_anal_cc_arg (anal, fcn->cc, ST32_MAX) : NULL; + const char *place = fcn->cc ? rz_anal_cc_arg (anal, fcn->cc, ST32_MAX) : NULL; bool stack_rev = place ? !strcmp (place, "stack_rev") : false; - char *fname = r_type_func_guess (anal->sdb_types, fcn->name); + char *fname = rz_type_func_guess (anal->sdb_types, fcn->name); if (fname) { ut64 sum_sz = 0; size_t from, to, i; if (stack_rev) { - const size_t cnt = r_type_func_args_count (anal->sdb_types, fname); + const size_t cnt = rz_type_func_args_count (anal->sdb_types, fname); from = cnt ? cnt - 1 : cnt; - to = fcn->cc ? r_anal_cc_max_arg (anal, fcn->cc) : 0; + to = fcn->cc ? rz_anal_cc_max_arg (anal, fcn->cc) : 0; } else { - from = fcn->cc ? r_anal_cc_max_arg (anal, fcn->cc) : 0; - to = r_type_func_args_count (anal->sdb_types, fname); + from = fcn->cc ? rz_anal_cc_max_arg (anal, fcn->cc) : 0; + to = rz_type_func_args_count (anal->sdb_types, fname); } const int bytes = (fcn->bits ? fcn->bits : anal->bits) / 8; for (i = from; stack_rev ? i >= to : i < to; stack_rev ? i-- : i++) { - char *tp = r_type_func_args_type (anal->sdb_types, fname, i); + char *tp = rz_type_func_args_type (anal->sdb_types, fname, i); if (!tp) { break; } if (sum_sz == frame_off) { vartype = tp; - varname = strdup (r_type_func_args_name (anal->sdb_types, fname, i)); + varname = strdup (rz_type_func_args_name (anal->sdb_types, fname, i)); break; } - ut64 bit_sz = r_type_get_bitsize (anal->sdb_types, tp); + ut64 bit_sz = rz_type_get_bitsize (anal->sdb_types, tp); sum_sz += bit_sz ? bit_sz / 8 : bytes; sum_sz = R_ROUND (sum_sz, bytes); free (tp); @@ -792,33 +792,33 @@ static void extract_arg(RAnal *anal, RAnalFunction *fcn, RAnalOp *op, const char } if (!varname) { if (anal->opt.varname_stack) { - varname = r_str_newf ("%s_%xh", pfx, R_ABS (frame_off)); + varname = rz_str_newf ("%s_%xh", pfx, R_ABS (frame_off)); } else { - varname = r_anal_function_autoname_var (fcn, type, pfx, ptr); + varname = rz_anal_function_autoname_var (fcn, type, pfx, ptr); } } if (varname) { - RAnalVar *var = r_anal_function_set_var (fcn, frame_off, type, vartype, anal->bits / 8, isarg, varname); + RzAnalVar *var = rz_anal_function_set_var (fcn, frame_off, type, vartype, anal->bits / 8, isarg, varname); if (var) { - r_anal_var_set_access (var, reg, op->addr, rw, ptr); + rz_anal_var_set_access (var, reg, op->addr, rw, ptr); } free (varname); } free (vartype); } else { st64 frame_off = -(ptr + fcn->bp_off); - RAnalVar *var = get_stack_var (fcn, frame_off); + RzAnalVar *var = get_stack_var (fcn, frame_off); if (var) { - r_anal_var_set_access (var, reg, op->addr, rw, -ptr); + rz_anal_var_set_access (var, reg, op->addr, rw, -ptr); goto beach; } char *varname = anal->opt.varname_stack - ? r_str_newf ("%s_%xh", VARPREFIX, R_ABS (frame_off)) - : r_anal_function_autoname_var (fcn, type, VARPREFIX, -ptr); + ? rz_str_newf ("%s_%xh", VARPREFIX, R_ABS (frame_off)) + : rz_anal_function_autoname_var (fcn, type, VARPREFIX, -ptr); if (varname) { - RAnalVar *var = r_anal_function_set_var (fcn, frame_off, type, NULL, anal->bits / 8, false, varname); + RzAnalVar *var = rz_anal_function_set_var (fcn, frame_off, type, NULL, anal->bits / 8, false, varname); if (var) { - r_anal_var_set_access (var, reg, op->addr, rw, -ptr); + rz_anal_var_set_access (var, reg, op->addr, rw, -ptr); } free (varname); } @@ -827,9 +827,9 @@ beach: free (esil_buf); } -static bool is_reg_in_src(const char *regname, RAnal *anal, RAnalOp *op); +static bool is_reg_in_src(const char *regname, RzAnal *anal, RzAnalOp *op); -static inline bool op_affect_dst(RAnalOp* op) { +static inline bool op_affect_dst(RzAnalOp* op) { switch (op->type) { case R_ANAL_OP_TYPE_ADD: case R_ANAL_OP_TYPE_SUB: @@ -859,9 +859,9 @@ static inline bool arch_destroys_dst(const char *arch) { return (STR_EQUAL (arch, "arm") || STR_EQUAL (arch, "riscv") || STR_EQUAL (arch, "ppc")); } -static bool is_used_like_arg(const char *regname, const char *opsreg, const char *opdreg, RAnalOp *op, RAnal *anal) { - RAnalValue *dst = op->dst; - RAnalValue *src = op->src[0]; +static bool is_used_like_arg(const char *regname, const char *opsreg, const char *opdreg, RzAnalOp *op, RzAnal *anal) { + RzAnalValue *dst = op->dst; + RzAnalValue *src = op->src[0]; switch (op->type) { case R_ANAL_OP_TYPE_POP: return false; @@ -900,16 +900,16 @@ static bool is_used_like_arg(const char *regname, const char *opsreg, const char } } -static bool is_reg_in_src (const char *regname, RAnal *anal, RAnalOp *op) { +static bool is_reg_in_src (const char *regname, RzAnal *anal, RzAnalOp *op) { const char* opsreg0 = op->src[0] ? get_regname (anal, op->src[0]) : NULL; const char* opsreg1 = op->src[1] ? get_regname (anal, op->src[1]) : NULL; const char* opsreg2 = op->src[2] ? get_regname (anal, op->src[2]) : NULL; return (STR_EQUAL (regname, opsreg0)) || (STR_EQUAL (regname, opsreg1)) || (STR_EQUAL (regname, opsreg2)); } -R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int *reg_set, int *count) { +RZ_API void rz_anal_extract_rarg(RzAnal *anal, RzAnalOp *op, RzAnalFunction *fcn, int *reg_set, int *count) { int i, argc = 0; - r_return_if_fail (anal && op && fcn); + rz_return_if_fail (anal && op && fcn); const char *opsreg = op->src[0] ? get_regname (anal, op->src[0]) : NULL; const char *opdreg = op->dst ? get_regname (anal, op->dst) : NULL; const int size = (fcn->bits ? fcn->bits : anal->bits) / 8; @@ -917,45 +917,45 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int R_LOG_DEBUG ("No calling convention for function '%s' to extract register arguments\n", fcn->name); return; } - char *fname = r_type_func_guess (anal->sdb_types, fcn->name); + char *fname = rz_type_func_guess (anal->sdb_types, fcn->name); Sdb *TDB = anal->sdb_types; - int max_count = r_anal_cc_max_arg (anal, fcn->cc); + int max_count = rz_anal_cc_max_arg (anal, fcn->cc); if (!max_count || (*count >= max_count)) { free (fname); return; } if (fname) { - argc = r_type_func_args_count (TDB, fname); + argc = rz_type_func_args_count (TDB, fname); } bool is_call = (op->type & 0xf) == R_ANAL_OP_TYPE_CALL || (op->type & 0xf) == R_ANAL_OP_TYPE_UCALL; if (is_call && *count < max_count) { - RList *callee_rargs_l = NULL; + RzList *callee_rargs_l = NULL; int callee_rargs = 0; char *callee = NULL; ut64 offset = op->jump == UT64_MAX ? op->ptr : op->jump; - RAnalFunction *f = r_anal_get_function_at (anal, offset); + RzAnalFunction *f = rz_anal_get_function_at (anal, offset); if (!f) { - RCore *core = (RCore *)anal->coreb.core; - RFlagItem *flag = r_flag_get_by_spaces (core->flags, offset, R_FLAGS_FS_IMPORTS, NULL); + RzCore *core = (RzCore *)anal->coreb.core; + RzFlagItem *flag = rz_flag_get_by_spaces (core->flags, offset, R_FLAGS_FS_IMPORTS, NULL); if (flag) { - callee = r_type_func_guess (TDB, flag->name); + callee = rz_type_func_guess (TDB, flag->name); if (callee) { - const char *cc = r_anal_cc_func (anal, callee); + const char *cc = rz_anal_cc_func (anal, callee); if (cc && !strcmp (fcn->cc, cc)) { - callee_rargs = R_MIN (max_count, r_type_func_args_count (TDB, callee)); + callee_rargs = R_MIN (max_count, rz_type_func_args_count (TDB, callee)); } } } } else if (!f->is_variadic && !strcmp (fcn->cc, f->cc)) { - callee = r_type_func_guess (TDB, f->name); + callee = rz_type_func_guess (TDB, f->name); if (callee) { - callee_rargs = R_MIN (max_count, r_type_func_args_count (TDB, callee)); + callee_rargs = R_MIN (max_count, rz_type_func_args_count (TDB, callee)); } callee_rargs = callee_rargs ? callee_rargs - : r_anal_var_count (anal, f, R_ANAL_VAR_KIND_REG, 1); - callee_rargs_l = r_anal_var_list (anal, f, R_ANAL_VAR_KIND_REG); + : rz_anal_var_count (anal, f, R_ANAL_VAR_KIND_REG, 1); + callee_rargs_l = rz_anal_var_list (anal, f, R_ANAL_VAR_KIND_REG); } size_t i; for (i = 0; i < callee_rargs; i++) { @@ -966,26 +966,26 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int char *type = NULL; char *name = NULL; int delta = 0; - const char *regname = r_anal_cc_arg (anal, fcn->cc, i); - RRegItem *ri = r_reg_get (anal->reg, regname, -1); + const char *regname = rz_anal_cc_arg (anal, fcn->cc, i); + RzRegItem *ri = rz_reg_get (anal->reg, regname, -1); if (ri) { delta = ri->index; } if (fname) { - type = r_type_func_args_type (TDB, fname, i); - vname = r_type_func_args_name (TDB, fname, i); + type = rz_type_func_args_type (TDB, fname, i); + vname = rz_type_func_args_name (TDB, fname, i); } if (!vname && callee) { - type = r_type_func_args_type (TDB, callee, i); - vname = r_type_func_args_name (TDB, callee, i); + type = rz_type_func_args_type (TDB, callee, i); + vname = rz_type_func_args_name (TDB, callee, i); } if (vname) { reg_set[i] = 1; } else { - RListIter *it; - RAnalVar *arg, *found_arg = NULL; - r_list_foreach (callee_rargs_l, it, arg) { - if (r_anal_var_get_argnum (arg) == i) { + RzListIter *it; + RzAnalVar *arg, *found_arg = NULL; + rz_list_foreach (callee_rargs_l, it, arg) { + if (rz_anal_var_get_argnum (arg) == i) { found_arg = arg; break; } @@ -996,48 +996,48 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int } } if (!vname) { - name = r_str_newf ("arg%lu", i + 1); + name = rz_str_newf ("arg%lu", i + 1); vname = name; } - r_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, type, size, true, vname); + rz_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, type, size, true, vname); (*count)++; free (name); free (type); } free (callee); - r_list_free (callee_rargs_l); + rz_list_free (callee_rargs_l); free (fname); return; } for (i = 0; i < max_count; i++) { - const char *regname = r_anal_cc_arg (anal, fcn->cc, i); + const char *regname = rz_anal_cc_arg (anal, fcn->cc, i); if (regname) { int delta = 0; - RRegItem *ri = NULL; - RAnalVar *var = NULL; + RzRegItem *ri = NULL; + RzAnalVar *var = NULL; bool is_used_like_an_arg = is_used_like_arg (regname, opsreg, opdreg, op, anal); if (reg_set[i] != 2 && is_used_like_an_arg) { - ri = r_reg_get (anal->reg, regname, -1); + ri = rz_reg_get (anal->reg, regname, -1); if (ri) { delta = ri->index; } } if (reg_set[i] == 1 && is_used_like_an_arg) { - var = r_anal_function_get_var (fcn, R_ANAL_VAR_KIND_REG, delta); + var = rz_anal_function_get_var (fcn, R_ANAL_VAR_KIND_REG, delta); } else if (reg_set[i] != 2 && is_used_like_an_arg) { const char *vname = NULL; char *type = NULL; char *name = NULL; if ((i < argc) && fname) { - type = r_type_func_args_type (TDB, fname, i); - vname = r_type_func_args_name (TDB, fname, i); + type = rz_type_func_args_type (TDB, fname, i); + vname = rz_type_func_args_name (TDB, fname, i); } if (!vname) { - name = r_str_newf ("arg%d", i + 1); + name = rz_str_newf ("arg%d", i + 1); vname = name; } - var = r_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, type, size, true, vname); + var = rz_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, type, size, true, vname); free (name); free (type); (*count)++; @@ -1051,27 +1051,27 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int reg_set[i] = 1; } if (var) { - r_anal_var_set_access (var, var->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); - r_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, var->name); + rz_anal_var_set_access (var, var->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); + rz_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, var->name); } } } - const char *selfreg = r_anal_cc_self (anal, fcn->cc); + const char *selfreg = rz_anal_cc_self (anal, fcn->cc); if (selfreg) { bool is_used_like_an_arg = is_used_like_arg (selfreg, opsreg, opdreg, op, anal); if (reg_set[i] != 2 && is_used_like_an_arg) { int delta = 0; char *vname = strdup ("self"); - RRegItem *ri = r_reg_get (anal->reg, selfreg, -1); + RzRegItem *ri = rz_reg_get (anal->reg, selfreg, -1); if (ri) { delta = ri->index; } - RAnalVar *newvar = r_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, 0, size, true, vname); + RzAnalVar *newvar = rz_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, 0, size, true, vname); if (newvar) { - r_anal_var_set_access (newvar, newvar->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); + rz_anal_var_set_access (newvar, newvar->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); } - r_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, vname); + rz_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, vname); free (vname); (*count)++; } else { @@ -1082,20 +1082,20 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int i++; } - const char *errorreg = r_anal_cc_error (anal, fcn->cc); + const char *errorreg = rz_anal_cc_error (anal, fcn->cc); if (errorreg) { if (reg_set[i] == 0 && STR_EQUAL (opdreg, errorreg)) { int delta = 0; char *vname = strdup ("error"); - RRegItem *ri = r_reg_get (anal->reg, errorreg, -1); + RzRegItem *ri = rz_reg_get (anal->reg, errorreg, -1); if (ri) { delta = ri->index; } - RAnalVar *newvar = r_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, 0, size, true, vname); + RzAnalVar *newvar = rz_anal_function_set_var (fcn, delta, R_ANAL_VAR_KIND_REG, 0, size, true, vname); if (newvar) { - r_anal_var_set_access (newvar, newvar->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); + rz_anal_var_set_access (newvar, newvar->regname, op->addr, R_ANAL_VAR_ACCESS_TYPE_READ, 0); } - r_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, vname); + rz_meta_set_string (anal, R_META_TYPE_VARTYPE, op->addr, vname); free (vname); (*count)++; reg_set[i] = 2; @@ -1104,8 +1104,8 @@ R_API void r_anal_extract_rarg(RAnal *anal, RAnalOp *op, RAnalFunction *fcn, int free (fname); } -R_API void r_anal_extract_vars(RAnal *anal, RAnalFunction *fcn, RAnalOp *op) { - r_return_if_fail (anal && fcn && op); +RZ_API void rz_anal_extract_vars(RzAnal *anal, RzAnalFunction *fcn, RzAnalOp *op) { + rz_return_if_fail (anal && fcn && op); const char *BP = anal->reg->name[R_REG_NAME_BP]; const char *SP = anal->reg->name[R_REG_NAME_SP]; @@ -1116,48 +1116,48 @@ R_API void r_anal_extract_vars(RAnal *anal, RAnalFunction *fcn, RAnalOp *op) { extract_arg (anal, fcn, op, SP, "+", R_ANAL_VAR_KIND_SPV); } -static RList *var_generate_list(RAnal *a, RAnalFunction *fcn, int kind) { +static RzList *var_generate_list(RzAnal *a, RzAnalFunction *fcn, int kind) { if (!a || !fcn) { return NULL; } - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (kind < 1) { kind = R_ANAL_VAR_KIND_BPV; // by default show vars } void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (var->kind == kind) { - r_list_push (list, var); + rz_list_push (list, var); } } return list; } -R_API RList *r_anal_var_all_list(RAnal *anal, RAnalFunction *fcn) { - // r_anal_var_list if there are not vars with that kind returns a list with +RZ_API RzList *rz_anal_var_all_list(RzAnal *anal, RzAnalFunction *fcn) { + // rz_anal_var_list if there are not vars with that kind returns a list with // zero element.. which is an unnecessary loss of cpu time - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { return NULL; } - RList *reg_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); - RList *bpv_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV); - RList *spv_vars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV); - r_list_join (list, reg_vars); - r_list_join (list, bpv_vars); - r_list_join (list, spv_vars); - r_list_free (reg_vars); - r_list_free (bpv_vars); - r_list_free (spv_vars); + RzList *reg_vars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); + RzList *bpv_vars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV); + RzList *spv_vars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV); + rz_list_join (list, reg_vars); + rz_list_join (list, bpv_vars); + rz_list_join (list, spv_vars); + rz_list_free (reg_vars); + rz_list_free (bpv_vars); + rz_list_free (spv_vars); return list; } -R_API RList *r_anal_var_list(RAnal *a, RAnalFunction *fcn, int kind) { +RZ_API RzList *rz_anal_var_list(RzAnal *a, RzAnalFunction *fcn, int kind) { return var_generate_list (a, fcn, kind); } -static void var_field_free(RAnalVarField *field) { +static void var_field_free(RzAnalVarField *field) { if (!field) { return; } @@ -1165,17 +1165,17 @@ static void var_field_free(RAnalVarField *field) { free (field); } -R_API RList *r_anal_function_get_var_fields(RAnalFunction *fcn, int kind) { +RZ_API RzList *rz_anal_function_get_var_fields(RzAnalFunction *fcn, int kind) { if (!fcn) { return NULL; } - RList *list = r_list_newf ((RListFree)var_field_free); + RzList *list = rz_list_newf ((RzListFree)var_field_free); if (kind < 1) { kind = R_ANAL_VAR_KIND_BPV; // by default show vars } void **it; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (var->kind != kind) { continue; } @@ -1183,7 +1183,7 @@ R_API RList *r_anal_function_get_var_fields(RAnalFunction *fcn, int kind) { // this var is a struct and var_add_structure_fields_to_list added all the fields continue; } - RAnalVarField *field = R_NEW0 (RAnalVarField); + RzAnalVarField *field = R_NEW0 (RzAnalVarField); if (!field) { break; } @@ -1193,25 +1193,25 @@ R_API RList *r_anal_function_get_var_fields(RAnalFunction *fcn, int kind) { break; } field->delta = var->delta; - r_list_push (list, field); + rz_list_push (list, field); } return list; } -static int var_comparator(const RAnalVar *a, const RAnalVar *b){ +static int var_comparator(const RzAnalVar *a, const RzAnalVar *b){ // avoid NULL dereference return (a && b)? (a->delta > b->delta) - (a->delta < b->delta) : 0; } -static int regvar_comparator(const RAnalVar *a, const RAnalVar *b){ +static int regvar_comparator(const RzAnalVar *a, const RzAnalVar *b){ // avoid NULL dereference return (a && b)? (a->argnum > b->argnum) - (a->argnum < b->argnum): 0; } -R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int mode, PJ *pj) { - RList *list = r_anal_var_list (anal, fcn, kind); - RAnalVar *var; - RListIter *iter; +RZ_API void rz_anal_var_list_show(RzAnal *anal, RzAnalFunction *fcn, int kind, int mode, PJ *pj) { + RzList *list = rz_anal_var_list (anal, fcn, kind); + RzAnalVar *var; + RzListIter *iter; if (!pj && mode == 'j') { return; } @@ -1224,8 +1224,8 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m } return; } - r_list_sort (list, (RListComparator) var_comparator); - r_list_foreach (list, iter, var) { + rz_list_sort (list, (RzListComparator) var_comparator); + rz_list_foreach (list, iter, var) { if (var->kind != kind) { continue; } @@ -1233,7 +1233,7 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m case '*': // we can't express all type info here :( if (kind == R_ANAL_VAR_KIND_REG) { // registers - RRegItem *i = r_reg_index_get (anal->reg, var->delta); + RzRegItem *i = rz_reg_index_get (anal->reg, var->delta); if (!i) { eprintf ("Register not found"); break; @@ -1270,7 +1270,7 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m } break; case R_ANAL_VAR_KIND_REG: { - RRegItem *i = r_reg_index_get (anal->reg, var->delta); + RzRegItem *i = rz_reg_index_get (anal->reg, var->delta); if (!i) { eprintf ("Register not found"); break; @@ -1323,7 +1323,7 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m } break; case R_ANAL_VAR_KIND_REG: { - RRegItem *i = r_reg_index_get (anal->reg, var->delta); + RzRegItem *i = rz_reg_index_get (anal->reg, var->delta); if (!i) { eprintf ("Register not found"); break; @@ -1356,35 +1356,35 @@ R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int m if (mode == 'j') { pj_end (pj); } - r_list_free (list); + rz_list_free (list); } -R_API void r_anal_fcn_vars_cache_init(RAnal *anal, RAnalFcnVarsCache *cache, RAnalFunction *fcn) { - cache->bvars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV); - cache->rvars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); - cache->svars = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV); - r_list_sort (cache->bvars, (RListComparator)var_comparator); - RListIter *it; - RAnalVar *var; - r_list_foreach (cache->rvars, it, var) { - var->argnum = r_anal_var_get_argnum (var); +RZ_API void rz_anal_fcn_vars_cache_init(RzAnal *anal, RzAnalFcnVarsCache *cache, RzAnalFunction *fcn) { + cache->bvars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_BPV); + cache->rvars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); + cache->svars = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_SPV); + rz_list_sort (cache->bvars, (RzListComparator)var_comparator); + RzListIter *it; + RzAnalVar *var; + rz_list_foreach (cache->rvars, it, var) { + var->argnum = rz_anal_var_get_argnum (var); } - r_list_sort (cache->rvars, (RListComparator)regvar_comparator); - r_list_sort (cache->svars, (RListComparator)var_comparator); + rz_list_sort (cache->rvars, (RzListComparator)regvar_comparator); + rz_list_sort (cache->svars, (RzListComparator)var_comparator); } -R_API void r_anal_fcn_vars_cache_fini(RAnalFcnVarsCache *cache) { +RZ_API void rz_anal_fcn_vars_cache_fini(RzAnalFcnVarsCache *cache) { if (!cache) { return; } - r_list_free (cache->bvars); - r_list_free (cache->rvars); - r_list_free (cache->svars); + rz_list_free (cache->bvars); + rz_list_free (cache->rvars); + rz_list_free (cache->svars); } -R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction *fcn, R_NULLABLE char *fcn_name, - R_NULLABLE RAnalFcnVarsCache *reuse_cache, R_NULLABLE const char *fcn_name_pre, R_NULLABLE const char *fcn_name_post) { - RAnalFcnVarsCache *cache = NULL; +RZ_API char *rz_anal_fcn_format_sig(R_NONNULL RzAnal *anal, R_NONNULL RzAnalFunction *fcn, R_NULLABLE char *fcn_name, + R_NULLABLE RzAnalFcnVarsCache *reuse_cache, R_NULLABLE const char *fcn_name_pre, R_NULLABLE const char *fcn_name_post) { + RzAnalFcnVarsCache *cache = NULL; if (!fcn_name) { fcn_name = fcn->name; @@ -1393,41 +1393,41 @@ R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction } } - RStrBuf *buf = r_strbuf_new (NULL); + RStrBuf *buf = rz_strbuf_new (NULL); if (!buf) { return NULL; } Sdb *TDB = anal->sdb_types; - char *type_fcn_name = r_type_func_guess (TDB, fcn_name); - if (type_fcn_name && r_type_func_exist (TDB, type_fcn_name)) { - const char *fcn_type = r_type_func_ret (anal->sdb_types, type_fcn_name); + char *type_fcn_name = rz_type_func_guess (TDB, fcn_name); + if (type_fcn_name && rz_type_func_exist (TDB, type_fcn_name)) { + const char *fcn_type = rz_type_func_ret (anal->sdb_types, type_fcn_name); if (fcn_type) { const char *sp = " "; if (*fcn_type && (fcn_type[strlen (fcn_type) - 1] == '*')) { sp = ""; } - r_strbuf_appendf (buf, "%s%s", fcn_type, sp); + rz_strbuf_appendf (buf, "%s%s", fcn_type, sp); } } if (fcn_name_pre) { - r_strbuf_append (buf, fcn_name_pre); + rz_strbuf_append (buf, fcn_name_pre); } - r_strbuf_append (buf, fcn_name); + rz_strbuf_append (buf, fcn_name); if (fcn_name_post) { - r_strbuf_append (buf, fcn_name_post); + rz_strbuf_append (buf, fcn_name_post); } - r_strbuf_append (buf, " ("); + rz_strbuf_append (buf, " ("); - if (type_fcn_name && r_type_func_exist (TDB, type_fcn_name)) { - int i, argc = r_type_func_args_count (TDB, type_fcn_name); + if (type_fcn_name && rz_type_func_exist (TDB, type_fcn_name)) { + int i, argc = rz_type_func_args_count (TDB, type_fcn_name); bool comma = true; // This avoids false positives present in argument recovery // and straight away print arguments fetched from types db for (i = 0; i < argc; i++) { - char *type = r_type_func_args_type (TDB, type_fcn_name, i); - const char *name = r_type_func_args_name (TDB, type_fcn_name, i); + char *type = rz_type_func_args_type (TDB, type_fcn_name, i); + const char *name = rz_type_func_args_name (TDB, type_fcn_name, i); if (!type || !name) { eprintf ("Missing type for %s\n", type_fcn_name); goto beach; @@ -1437,7 +1437,7 @@ R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction } size_t len = strlen (type); const char *tc = len > 0 && type[len - 1] == '*'? "": " "; - r_strbuf_appendf (buf, "%s%s%s%s", type, tc, name, comma? ", ": ""); + rz_strbuf_appendf (buf, "%s%s%s%s", type, tc, name, comma? ", ": ""); free (type); } goto beach; @@ -1447,41 +1447,41 @@ R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction cache = reuse_cache; if (!cache) { - cache = R_NEW0 (RAnalFcnVarsCache); + cache = R_NEW0 (RzAnalFcnVarsCache); if (!cache) { type_fcn_name = NULL; goto beach; } - r_anal_fcn_vars_cache_init (anal, cache, fcn); + rz_anal_fcn_vars_cache_init (anal, cache, fcn); } bool comma = true; bool arg_bp = false; size_t tmp_len; - RAnalVar *var; - RListIter *iter; + RzAnalVar *var; + RzListIter *iter; - r_list_foreach (cache->rvars, iter, var) { + rz_list_foreach (cache->rvars, iter, var) { // assume self, error are always the last if (!strcmp (var->name, "self") || !strcmp (var->name, "error")) { - r_strbuf_slice (buf, 0, r_strbuf_length (buf) - 2); + rz_strbuf_slice (buf, 0, rz_strbuf_length (buf) - 2); break; } tmp_len = strlen (var->type); - r_strbuf_appendf (buf, "%s%s%s%s", var->type, + rz_strbuf_appendf (buf, "%s%s%s%s", var->type, tmp_len && var->type[tmp_len - 1] == '*' ? "" : " ", var->name, iter->n ? ", " : ""); } - r_list_foreach (cache->bvars, iter, var) { + rz_list_foreach (cache->bvars, iter, var) { if (var->isarg) { - if (!r_list_empty (cache->rvars) && comma) { - r_strbuf_append (buf, ", "); + if (!rz_list_empty (cache->rvars) && comma) { + rz_strbuf_append (buf, ", "); comma = false; } arg_bp = true; tmp_len = strlen (var->type); - r_strbuf_appendf (buf, "%s%s%s%s", var->type, + rz_strbuf_appendf (buf, "%s%s%s%s", var->type, tmp_len && var->type[tmp_len - 1] =='*' ? "" : " ", var->name, iter->n ? ", " : ""); } @@ -1489,31 +1489,31 @@ R_API char *r_anal_fcn_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFunction comma = true; const char *maybe_comma = ", "; - r_list_foreach (cache->svars, iter, var) { + rz_list_foreach (cache->svars, iter, var) { if (var->isarg) { - if (!*maybe_comma || ((arg_bp || !r_list_empty (cache->rvars)) && comma)) { + if (!*maybe_comma || ((arg_bp || !rz_list_empty (cache->rvars)) && comma)) { comma = false; - r_strbuf_append (buf, ", "); + rz_strbuf_append (buf, ", "); } tmp_len = strlen (var->type); - if (iter->n && ((RAnalVar *)iter->n->data)->isarg) { + if (iter->n && ((RzAnalVar *)iter->n->data)->isarg) { maybe_comma = ", "; } else { maybe_comma = ""; } - r_strbuf_appendf (buf, "%s%s%s%s", var->type, + rz_strbuf_appendf (buf, "%s%s%s%s", var->type, tmp_len && var->type[tmp_len - 1] =='*' ? "" : " ", var->name, maybe_comma); } } beach: - r_strbuf_append (buf, ");"); + rz_strbuf_append (buf, ");"); R_FREE (type_fcn_name); if (!reuse_cache) { // !reuse_cache => we created our own cache - r_anal_fcn_vars_cache_fini (cache); + rz_anal_fcn_vars_cache_fini (cache); free (cache); } - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } diff --git a/libr/anal/vtable.c b/librz/anal/vtable.c similarity index 60% rename from libr/anal/vtable.c rename to librz/anal/vtable.c index 7fff05f5a8..47ddb1b875 100644 --- a/libr/anal/vtable.c +++ b/librz/anal/vtable.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, maijin, thestr4ng3r */ -#include "r_util.h" -#include "r_anal.h" +#include "rz_util.h" +#include "rz_anal.h" #define VTABLE_BUFF_SIZE 10 #define VTABLE_READ_ADDR_FUNC(fname, read_fname, sz) \ - static bool fname(RAnal *anal, ut64 addr, ut64 *buf) {\ + static bool fname(RzAnal *anal, ut64 addr, ut64 *buf) {\ ut8 tmp[sz];\ if (!anal->iob.read_at (anal->iob.io, addr, tmp, sz)) {\ return false;\ @@ -14,32 +14,32 @@ *buf = read_fname (tmp);\ return true;\ } -VTABLE_READ_ADDR_FUNC (vtable_read_addr_le8, r_read_le8, 1) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_le16, r_read_le16, 2) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_le32, r_read_le32, 4) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_le64, r_read_le64, 8) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_be8, r_read_be8, 1) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_be16, r_read_be16, 2) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_be32, r_read_be32, 4) -VTABLE_READ_ADDR_FUNC (vtable_read_addr_be64, r_read_be64, 8) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_le8, rz_read_le8, 1) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_le16, rz_read_le16, 2) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_le32, rz_read_le32, 4) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_le64, rz_read_le64, 8) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_be8, rz_read_be8, 1) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_be16, rz_read_be16, 2) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_be32, rz_read_be32, 4) +VTABLE_READ_ADDR_FUNC (vtable_read_addr_be64, rz_read_be64, 8) -R_API void r_anal_vtable_info_free(RVTableInfo *vtable) { +RZ_API void rz_anal_vtable_info_free(RVTableInfo *vtable) { if (!vtable) { return; } - r_vector_clear (&vtable->methods); + rz_vector_clear (&vtable->methods); free (vtable); } -R_API ut64 r_anal_vtable_info_get_size(RVTableContext *context, RVTableInfo *vtable) { +RZ_API ut64 rz_anal_vtable_info_get_size(RVTableContext *context, RVTableInfo *vtable) { return (ut64)vtable->methods.len * context->word_size; } -R_API bool r_anal_vtable_begin(RAnal *anal, RVTableContext *context) { +RZ_API bool rz_anal_vtable_begin(RzAnal *anal, RVTableContext *context) { context->anal = anal; context->abi = anal->cpp_abi; context->word_size = (ut8) (anal->bits / 8); - const bool is_arm = anal->cur->arch && r_str_startswith (anal->cur->arch, "arm"); + const bool is_arm = anal->cur->arch && rz_str_startswith (anal->cur->arch, "arm"); if (is_arm && context->word_size < 4) { context->word_size = 4; } @@ -91,7 +91,7 @@ static bool vtable_section_can_contain_vtables(RBinSection *section) { !strcmp (section->name, ".rdata") || !strcmp (section->name, ".data.rel.ro") || !strcmp (section->name, ".data.rel.ro.local") || - r_str_endswith (section->name, "__const"); + rz_str_endswith (section->name, "__const"); } static bool section_can_contain_rtti(RBinSection *section) { @@ -103,7 +103,7 @@ static bool section_can_contain_rtti(RBinSection *section) { } return !strcmp (section->name, ".data.rel.ro") || !strcmp (section->name, ".data.rel.ro.local") || - r_str_endswith (section->name, "__const"); + rz_str_endswith (section->name, "__const"); } static bool vtable_is_addr_vtable_start_itanium(RVTableContext *context, RBinSection *section, ut64 curAddress) { @@ -131,8 +131,8 @@ static bool vtable_is_addr_vtable_start_itanium(RVTableContext *context, RBinSec } static bool vtable_is_addr_vtable_start_msvc(RVTableContext *context, ut64 curAddress) { - RAnalRef *xref; - RListIter *xrefIter; + RzAnalRef *xref; + RzListIter *xrefIter; if (!curAddress || curAddress == UT64_MAX) { return false; @@ -141,31 +141,31 @@ static bool vtable_is_addr_vtable_start_msvc(RVTableContext *context, ut64 curAd return false; } // total xref's to curAddress - RList *xrefs = r_anal_xrefs_get (context->anal, curAddress); - if (r_list_empty (xrefs)) { - r_list_free (xrefs); + RzList *xrefs = rz_anal_xrefs_get (context->anal, curAddress); + if (rz_list_empty (xrefs)) { + rz_list_free (xrefs); return false; } - r_list_foreach (xrefs, xrefIter, xref) { + rz_list_foreach (xrefs, xrefIter, xref) { // section in which currenct xref lies if (vtable_addr_in_text_section (context, xref->addr)) { ut8 buf[VTABLE_BUFF_SIZE]; context->anal->iob.read_at (context->anal->iob.io, xref->addr, buf, sizeof(buf)); - RAnalOp analop = { 0 }; - r_anal_op (context->anal, &analop, xref->addr, buf, sizeof(buf), R_ANAL_OP_MASK_BASIC); + RzAnalOp analop = { 0 }; + rz_anal_op (context->anal, &analop, xref->addr, buf, sizeof(buf), R_ANAL_OP_MASK_BASIC); if (analop.type == R_ANAL_OP_TYPE_MOV || analop.type == R_ANAL_OP_TYPE_LEA) { - r_list_free (xrefs); - r_anal_op_fini (&analop); + rz_list_free (xrefs); + rz_anal_op_fini (&analop); return true; } - r_anal_op_fini (&analop); + rz_anal_op_fini (&analop); } } - r_list_free (xrefs); + rz_list_free (xrefs); return false; } @@ -176,10 +176,10 @@ static bool vtable_is_addr_vtable_start(RVTableContext *context, RBinSection *se if (context->abi == R_ANAL_CPP_ABI_ITANIUM) { return vtable_is_addr_vtable_start_itanium (context, section, curAddress); } - r_return_val_if_reached (false); + rz_return_val_if_reached (false); } -R_API RVTableInfo *r_anal_vtable_parse_at(RVTableContext *context, ut64 addr) { +RZ_API RVTableInfo *rz_anal_vtable_parse_at(RVTableContext *context, ut64 addr) { ut64 offset_to_top; if (!context->read_addr (context->anal, addr - 2 * context->word_size, &offset_to_top)) { return NULL; @@ -192,51 +192,51 @@ R_API RVTableInfo *r_anal_vtable_parse_at(RVTableContext *context, ut64 addr) { vtable->saddr = addr; - r_vector_init (&vtable->methods, sizeof (RVTableMethodInfo), NULL, NULL); + rz_vector_init (&vtable->methods, sizeof (RVTableMethodInfo), NULL, NULL); RVTableMethodInfo meth; while (vtable_is_value_in_text_section (context, addr, &meth.addr)) { meth.vtable_offset = addr - vtable->saddr; - if (!r_vector_push (&vtable->methods, &meth)) { + if (!rz_vector_push (&vtable->methods, &meth)) { break; } addr += context->word_size; // a ref means the vtable has ended - RList *ll = r_anal_xrefs_get (context->anal, addr); - if (!r_list_empty (ll)) { - r_list_free (ll); + RzList *ll = rz_anal_xrefs_get (context->anal, addr); + if (!rz_list_empty (ll)) { + rz_list_free (ll); break; } - r_list_free (ll); + rz_list_free (ll); } return vtable; } -R_API RList *r_anal_vtable_search(RVTableContext *context) { - RAnal *anal = context->anal; +RZ_API RzList *rz_anal_vtable_search(RVTableContext *context) { + RzAnal *anal = context->anal; if (!anal) { return NULL; } - RList *vtables = r_list_newf ((RListFree)r_anal_vtable_info_free); + RzList *vtables = rz_list_newf ((RzListFree)rz_anal_vtable_info_free); if (!vtables) { return NULL; } - RList *sections = anal->binb.get_sections (anal->binb.bin); + RzList *sections = anal->binb.get_sections (anal->binb.bin); if (!sections) { - r_list_free (vtables); + rz_list_free (vtables); return NULL; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); - RListIter *iter; + RzListIter *iter; RBinSection *section; - r_list_foreach (sections, iter, section) { - if (r_cons_is_breaked ()) { + rz_list_foreach (sections, iter, section) { + if (rz_cons_is_breaked ()) { break; } @@ -251,7 +251,7 @@ R_API RList *r_anal_vtable_search(RVTableContext *context) { break; } while (startAddress <= endAddress) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (!anal->iob.is_valid_offset (anal->iob.io, startAddress, 0)) { @@ -259,10 +259,10 @@ R_API RList *r_anal_vtable_search(RVTableContext *context) { } if (vtable_is_addr_vtable_start (context, section, startAddress)) { - RVTableInfo *vtable = r_anal_vtable_parse_at (context, startAddress); + RVTableInfo *vtable = rz_anal_vtable_parse_at (context, startAddress); if (vtable) { - r_list_append (vtables, vtable); - ut64 size = r_anal_vtable_info_get_size (context, vtable); + rz_list_append (vtables, vtable); + ut64 size = rz_anal_vtable_info_get_size (context, vtable); if (size > 0) { startAddress += size; continue; @@ -273,79 +273,79 @@ R_API RList *r_anal_vtable_search(RVTableContext *context) { } } - r_cons_break_pop (); + rz_cons_break_pop (); - if (r_list_empty (vtables)) { + if (rz_list_empty (vtables)) { // stripped binary? - r_list_free (vtables); + rz_list_free (vtables); return NULL; } return vtables; } -R_API void r_anal_list_vtables(RAnal *anal, int rad) { +RZ_API void rz_anal_list_vtables(RzAnal *anal, int rad) { RVTableContext context; - r_anal_vtable_begin (anal, &context); + rz_anal_vtable_begin (anal, &context); const char *noMethodName = "No Name found"; RVTableMethodInfo *curMethod; - RListIter *vtableIter; + RzListIter *vtableIter; RVTableInfo *table; - RList *vtables = r_anal_vtable_search (&context); + RzList *vtables = rz_anal_vtable_search (&context); if (rad == 'j') { bool isFirstElement = true; - r_cons_print ("["); - r_list_foreach (vtables, vtableIter, table) { + rz_cons_print ("["); + rz_list_foreach (vtables, vtableIter, table) { if (!isFirstElement) { - r_cons_print (","); + rz_cons_print (","); } bool isFirstMethod = true; - r_cons_printf ("{\"offset\":%"PFMT64d",\"methods\":[", table->saddr); - r_vector_foreach (&table->methods, curMethod) { + rz_cons_printf ("{\"offset\":%"PFMT64d",\"methods\":[", table->saddr); + rz_vector_foreach (&table->methods, curMethod) { if (!isFirstMethod) { - r_cons_print (","); + rz_cons_print (","); } - RAnalFunction *fcn = r_anal_get_fcn_in (anal, curMethod->addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, curMethod->addr, 0); const char *const name = fcn ? fcn->name : NULL; - r_cons_printf ("{\"offset\":%"PFMT64d",\"name\":\"%s\"}", + rz_cons_printf ("{\"offset\":%"PFMT64d",\"name\":\"%s\"}", curMethod->addr, name ? name : noMethodName); isFirstMethod = false; } - r_cons_print ("]}"); + rz_cons_print ("]}"); isFirstElement = false; } - r_cons_println ("]"); + rz_cons_println ("]"); } else if (rad == '*') { - r_list_foreach (vtables, vtableIter, table) { - r_cons_printf ("f vtable.0x%08"PFMT64x" %"PFMT64d" @ 0x%08"PFMT64x"\n", + rz_list_foreach (vtables, vtableIter, table) { + rz_cons_printf ("f vtable.0x%08"PFMT64x" %"PFMT64d" @ 0x%08"PFMT64x"\n", table->saddr, - r_anal_vtable_info_get_size (&context, table), + rz_anal_vtable_info_get_size (&context, table), table->saddr); - r_vector_foreach (&table->methods, curMethod) { - r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", context.word_size, table->saddr + curMethod->vtable_offset); - RAnalFunction *fcn = r_anal_get_fcn_in (anal, curMethod->addr, 0); + rz_vector_foreach (&table->methods, curMethod) { + rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", context.word_size, table->saddr + curMethod->vtable_offset); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, curMethod->addr, 0); const char *const name = fcn ? fcn->name : NULL; if (name) { - r_cons_printf ("f %s=0x%08"PFMT64x"\n", name, curMethod->addr); + rz_cons_printf ("f %s=0x%08"PFMT64x"\n", name, curMethod->addr); } else { - r_cons_printf ("f method.virtual.0x%08"PFMT64x"=0x%08"PFMT64x"\n", curMethod->addr, curMethod->addr); + rz_cons_printf ("f method.virtual.0x%08"PFMT64x"=0x%08"PFMT64x"\n", curMethod->addr, curMethod->addr); } } } } else { - r_list_foreach (vtables, vtableIter, table) { + rz_list_foreach (vtables, vtableIter, table) { ut64 vtableStartAddress = table->saddr; - r_cons_printf ("\nVtable Found at 0x%08"PFMT64x"\n", vtableStartAddress); - r_vector_foreach (&table->methods, curMethod) { - RAnalFunction *fcn = r_anal_get_fcn_in (anal, curMethod->addr, 0); + rz_cons_printf ("\nVtable Found at 0x%08"PFMT64x"\n", vtableStartAddress); + rz_vector_foreach (&table->methods, curMethod) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, curMethod->addr, 0); const char *const name = fcn ? fcn->name : NULL; - r_cons_printf ("0x%08"PFMT64x" : %s\n", vtableStartAddress, name ? name : noMethodName); + rz_cons_printf ("0x%08"PFMT64x" : %s\n", vtableStartAddress, name ? name : noMethodName); vtableStartAddress += context.word_size; } - r_cons_newline (); + rz_cons_newline (); } } - r_list_free (vtables); + rz_list_free (vtables); } diff --git a/libr/anal/xrefs.c b/librz/anal/xrefs.c similarity index 64% rename from libr/anal/xrefs.c rename to librz/anal/xrefs.c index 1b5e64f637..830cc2e2be 100644 --- a/libr/anal/xrefs.c +++ b/librz/anal/xrefs.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble, defragger, ret2libc */ -#include -#include +#include +#include #if 0 DICT @@ -24,8 +24,8 @@ xrefs // XXX: is it possible to have multiple type for the same (from, to) pair? // if it is, things need to be adjusted -static RAnalRef *r_anal_ref_new(ut64 addr, ut64 at, ut64 type) { - RAnalRef *ref = R_NEW (RAnalRef); +static RzAnalRef *rz_anal_ref_new(ut64 addr, ut64 at, ut64 type) { + RzAnalRef *ref = R_NEW (RzAnalRef); if (ref) { ref->addr = addr; ref->at = at; @@ -34,12 +34,12 @@ static RAnalRef *r_anal_ref_new(ut64 addr, ut64 at, ut64 type) { return ref; } -static void r_anal_ref_free(void *ref) { +static void rz_anal_ref_free(void *ref) { free (ref); } -R_API RList *r_anal_ref_list_new(void) { - return r_list_newf (r_anal_ref_free); +RZ_API RzList *rz_anal_ref_list_new(void) { + return rz_list_newf (rz_anal_ref_free); } static void xrefs_ht_free(HtUPKv *kv) { @@ -47,15 +47,15 @@ static void xrefs_ht_free(HtUPKv *kv) { } static void xrefs_ref_free(HtUPKv *kv) { - r_anal_ref_free (kv->value); + rz_anal_ref_free (kv->value); } static bool appendRef(void *u, const ut64 k, const void *v) { - RList *list = (RList *)u; - RAnalRef *ref = (RAnalRef *)v; - RAnalRef *cloned = r_anal_ref_new (ref->addr, ref->at, ref->type); + RzList *list = (RzList *)u; + RzAnalRef *ref = (RzAnalRef *)v; + RzAnalRef *cloned = rz_anal_ref_new (ref->addr, ref->at, ref->type); if (cloned) { - r_list_append (list, cloned); + rz_list_append (list, cloned); return true; } return false; @@ -67,7 +67,7 @@ static bool mylistrefs_cb(void *list, const ut64 k, const void *v) { return true; } -static int ref_cmp(const RAnalRef *a, const RAnalRef *b) { +static int ref_cmp(const RzAnalRef *a, const RzAnalRef *b) { if (a->at < b->at) { return -1; } @@ -83,11 +83,11 @@ static int ref_cmp(const RAnalRef *a, const RAnalRef *b) { return 0; } -static void sortxrefs(RList *list) { - r_list_sort (list, (RListComparator)ref_cmp); +static void sortxrefs(RzList *list) { + rz_list_sort (list, (RzListComparator)ref_cmp); } -static void listxrefs(HtUP *m, ut64 addr, RList *list) { +static void listxrefs(HtUP *m, ut64 addr, RzList *list) { if (addr == UT64_MAX) { ht_up_foreach (m, mylistrefs_cb, list); } else { @@ -111,14 +111,14 @@ static void setxref(HtUP *m, ut64 from, ut64 to, int type) { } ht_up_insert (m, from, ht); } - RAnalRef *ref = r_anal_ref_new (to, from, type); + RzAnalRef *ref = rz_anal_ref_new (to, from, type); if (ref) { ht_up_update (ht, to, ref); } } // set a reference from FROM to TO and a cross-reference(xref) from TO to FROM. -R_API int r_anal_xrefs_set(RAnal *anal, ut64 from, ut64 to, const RAnalRefType type) { +RZ_API int rz_anal_xrefs_set(RzAnal *anal, ut64 from, ut64 to, const RzAnalRefType type) { if (!anal || from == to) { return false; } @@ -135,7 +135,7 @@ R_API int r_anal_xrefs_set(RAnal *anal, ut64 from, ut64 to, const RAnalRefType t return true; } -R_API int r_anal_xrefs_deln(RAnal *anal, ut64 from, ut64 to, const RAnalRefType type) { +RZ_API int rz_anal_xrefs_deln(RzAnal *anal, ut64 from, ut64 to, const RzAnalRefType type) { if (!anal) { return false; } @@ -144,69 +144,69 @@ R_API int r_anal_xrefs_deln(RAnal *anal, ut64 from, ut64 to, const RAnalRefType return true; } -R_API int r_anal_xref_del(RAnal *anal, ut64 from, ut64 to) { +RZ_API int rz_anal_xref_del(RzAnal *anal, ut64 from, ut64 to) { bool res = false; - res |= r_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_NULL); - res |= r_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_CODE); - res |= r_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_CALL); - res |= r_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_DATA); - res |= r_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_STRING); + res |= rz_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_NULL); + res |= rz_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_CODE); + res |= rz_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_CALL); + res |= rz_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_DATA); + res |= rz_anal_xrefs_deln (anal, from, to, R_ANAL_REF_TYPE_STRING); return res; } -R_API int r_anal_xrefs_from(RAnal *anal, RList *list, const char *kind, const RAnalRefType type, ut64 addr) { +RZ_API int rz_anal_xrefs_from(RzAnal *anal, RzList *list, const char *kind, const RzAnalRefType type, ut64 addr) { listxrefs (anal->dict_refs, addr, list); sortxrefs (list); return true; } -R_API RList *r_anal_xrefs_get(RAnal *anal, ut64 to) { - RList *list = r_anal_ref_list_new (); +RZ_API RzList *rz_anal_xrefs_get(RzAnal *anal, ut64 to) { + RzList *list = rz_anal_ref_list_new (); if (!list) { return NULL; } listxrefs (anal->dict_xrefs, to, list); sortxrefs (list); - if (r_list_empty (list)) { - r_list_free (list); + if (rz_list_empty (list)) { + rz_list_free (list); list = NULL; } return list; } -R_API RList *r_anal_refs_get(RAnal *anal, ut64 from) { - RList *list = r_anal_ref_list_new (); +RZ_API RzList *rz_anal_refs_get(RzAnal *anal, ut64 from) { + RzList *list = rz_anal_ref_list_new (); if (!list) { return NULL; } listxrefs (anal->dict_refs, from, list); sortxrefs (list); - if (r_list_empty (list)) { - r_list_free (list); + if (rz_list_empty (list)) { + rz_list_free (list); list = NULL; } return list; } -R_API RList *r_anal_xrefs_get_from(RAnal *anal, ut64 to) { - RList *list = r_anal_ref_list_new (); +RZ_API RzList *rz_anal_xrefs_get_from(RzAnal *anal, ut64 to) { + RzList *list = rz_anal_ref_list_new (); if (!list) { return NULL; } listxrefs (anal->dict_refs, to, list); sortxrefs (list); - if (r_list_empty (list)) { - r_list_free (list); + if (rz_list_empty (list)) { + rz_list_free (list); list = NULL; } return list; } -R_API void r_anal_xrefs_list(RAnal *anal, int rad) { - RListIter *iter; - RAnalRef *ref; +RZ_API void rz_anal_xrefs_list(RzAnal *anal, int rad) { + RzListIter *iter; + RzAnalRef *ref; PJ *pj = NULL; - RList *list = r_anal_ref_list_new(); + RzList *list = rz_anal_ref_list_new(); listxrefs (anal->dict_refs, UT64_MAX, list); sortxrefs (list); if (rad == 'j') { @@ -216,7 +216,7 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) { } pj_a (pj); } - r_list_foreach (list, iter, ref) { + rz_list_foreach (list, iter, ref) { int t = ref->type ? ref->type: ' '; switch (rad) { case '*': @@ -226,16 +226,16 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) { { char *name = anal->coreb.getNameDelta (anal->coreb.core, ref->at); if (name) { - r_str_replace_ch (name, ' ', 0, true); + rz_str_replace_ch (name, ' ', 0, true); anal->cb_printf ("%40s", name); free (name); } else { anal->cb_printf ("%40s", "?"); } - anal->cb_printf (" 0x%"PFMT64x" -> %9s -> 0x%"PFMT64x, ref->at, r_anal_xrefs_type_tostring (t), ref->addr); + anal->cb_printf (" 0x%"PFMT64x" -> %9s -> 0x%"PFMT64x, ref->at, rz_anal_xrefs_type_tostring (t), ref->addr); name = anal->coreb.getNameDelta (anal->coreb.core, ref->addr); if (name) { - r_str_replace_ch (name, ' ', 0, true); + rz_str_replace_ch (name, ' ', 0, true); anal->cb_printf (" %s\n", name); free (name); } else { @@ -244,23 +244,23 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) { } break; case 'q': - anal->cb_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" %s\n", ref->at, ref->addr, r_anal_xrefs_type_tostring (t)); + anal->cb_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" %s\n", ref->at, ref->addr, rz_anal_xrefs_type_tostring (t)); break; case 'j': { pj_o (pj); char *name = anal->coreb.getNameDelta (anal->coreb.core, ref->at); if (name) { - r_str_replace_ch (name, ' ', 0, true); + rz_str_replace_ch (name, ' ', 0, true); pj_ks (pj, "name", name); free (name); } pj_kn (pj, "from", ref->at); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (t)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (t)); pj_kn (pj, "addr", ref->addr); name = anal->coreb.getNameDelta (anal->coreb.core, ref->addr); if (name) { - r_str_replace_ch (name, ' ', 0, true); + rz_str_replace_ch (name, ' ', 0, true); pj_ks (pj, "refname", name); free (name); } @@ -276,10 +276,10 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad) { anal->cb_printf ("%s\n", pj_string (pj)); pj_free (pj); } - r_list_free (list); + rz_list_free (list); } -R_API const char *r_anal_xrefs_type_tostring(RAnalRefType type) { +RZ_API const char *rz_anal_xrefs_type_tostring(RzAnalRefType type) { switch (type) { case R_ANAL_REF_TYPE_CODE: return "CODE"; @@ -295,20 +295,20 @@ R_API const char *r_anal_xrefs_type_tostring(RAnalRefType type) { } } -R_API RAnalRefType r_anal_xrefs_type(char ch) { +RZ_API RzAnalRefType rz_anal_xrefs_type(char ch) { switch (ch) { case R_ANAL_REF_TYPE_CODE: case R_ANAL_REF_TYPE_CALL: case R_ANAL_REF_TYPE_DATA: case R_ANAL_REF_TYPE_STRING: case R_ANAL_REF_TYPE_NULL: - return (RAnalRefType)ch; + return (RzAnalRefType)ch; default: return R_ANAL_REF_TYPE_NULL; } } -R_API bool r_anal_xrefs_init(RAnal *anal) { +RZ_API bool rz_anal_xrefs_init(RzAnal *anal) { ht_up_free (anal->dict_refs); anal->dict_refs = NULL; ht_up_free (anal->dict_xrefs); @@ -335,24 +335,24 @@ static bool count_cb(void *user, const ut64 k, const void *v) { return true; } -R_API ut64 r_anal_xrefs_count(RAnal *anal) { +RZ_API ut64 rz_anal_xrefs_count(RzAnal *anal) { ut64 ret = 0; ht_up_foreach (anal->dict_xrefs, count_cb, &ret); return ret; } -static RList *fcn_get_refs(RAnalFunction *fcn, HtUP *ht) { - RListIter *iter; - RAnalBlock *bb; - RList *list = r_anal_ref_list_new (); +static RzList *fcn_get_refs(RzAnalFunction *fcn, HtUP *ht) { + RzListIter *iter; + RzAnalBlock *bb; + RzList *list = rz_anal_ref_list_new (); if (!list) { return NULL; } - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { int i; for (i = 0; i < bb->ninstr; i++) { - ut64 at = bb->addr + r_anal_bb_offset_inst (bb, i); + ut64 at = bb->addr + rz_anal_bb_offset_inst (bb, i); listxrefs (ht, at, list); } } @@ -360,17 +360,17 @@ static RList *fcn_get_refs(RAnalFunction *fcn, HtUP *ht) { return list; } -R_API RList *r_anal_function_get_refs(RAnalFunction *fcn) { - r_return_val_if_fail (fcn, NULL); +RZ_API RzList *rz_anal_function_get_refs(RzAnalFunction *fcn) { + rz_return_val_if_fail (fcn, NULL); return fcn_get_refs (fcn, fcn->anal->dict_refs); } -R_API RList *r_anal_function_get_xrefs(RAnalFunction *fcn) { - r_return_val_if_fail (fcn, NULL); +RZ_API RzList *rz_anal_function_get_xrefs(RzAnalFunction *fcn) { + rz_return_val_if_fail (fcn, NULL); return fcn_get_refs (fcn, fcn->anal->dict_xrefs); } -R_API const char *r_anal_ref_type_tostring(RAnalRefType t) { +RZ_API const char *rz_anal_ref_type_tostring(RzAnalRefType t) { switch (t) { case R_ANAL_REF_TYPE_NULL: return "null"; diff --git a/libr/asm/Makefile b/librz/asm/Makefile similarity index 79% rename from libr/asm/Makefile rename to librz/asm/Makefile index 3107a51970..29dcb1577a 100644 --- a/libr/asm/Makefile +++ b/librz/asm/Makefile @@ -1,12 +1,12 @@ include ../../global.mk -NAME=r_asm -R2DEPS=r_syscall r_lang r_util r_parse -R2DEPS+=r_flag r_cons r_reg +NAME=rz_asm +R2DEPS=rz_syscall rz_lang rz_util rz_parse +R2DEPS+=rz_flag rz_cons rz_reg CFLAGS+=-DR2_PLUGIN_INCORE -Iarch/include -Iarch -I../../shlr CURDIR=p/ -include $(TOP)/libr/config.mk +include $(TOP)/librz/config.mk include p/capstone.mk LDFLAGS+=${CS_LDFLAGS} @@ -33,4 +33,4 @@ STATIC_OBJS=$(subst ..,p/..,$(subst asm_,p/asm_,$(STATIC_OBJ))) OBJS=${STATIC_OBJS} asm.o acode.o aop.o OBJS+=${SHARED2_OBJ} -include $(TOP)/libr/rules.mk +include $(TOP)/librz/rules.mk diff --git a/librz/asm/acode.c b/librz/asm/acode.c new file mode 100644 index 0000000000..bff4eed5d5 --- /dev/null +++ b/librz/asm/acode.c @@ -0,0 +1,74 @@ +/* radare - LGPL - Copyright 2009-2019 - pancake */ + +#include +#include + +RZ_API RzAsmCode *rz_asm_code_new(void) { + return R_NEW0 (RzAsmCode); +} + +RZ_API void* rz_asm_code_free(RzAsmCode *acode) { + if (acode) { + rz_list_free (acode->equs); + free (acode->bytes); + free (acode->assembly); + free (acode); + } + return NULL; +} + +RZ_API void rz_asm_equ_item_free(RzAsmEqu *equ) { + if (equ) { + free (equ->key); + free (equ->value); + free (equ); + } +} + +static RzAsmEqu *__asm_equ_new(const char *key, const char *value) { + RzAsmEqu *equ = R_NEW0 (RzAsmEqu); + if (equ) { + equ->key = strdup (key); + equ->value = strdup (value); + } + return equ; +} + +RZ_API bool rz_asm_code_set_equ (RzAsmCode *code, const char *key, const char *value) { + rz_return_val_if_fail (code && key && value, false); + + if (code->equs) { + RzAsmEqu *equ; + RzListIter *iter; + rz_list_foreach (code->equs, iter, equ) { + if (!strcmp (equ->key, key)) { + free (equ->value); + equ->value = strdup (value); + return true; + } + } + } else { + code->equs = rz_list_newf ((RzListFree)rz_asm_equ_item_free); + } + rz_list_append (code->equs, __asm_equ_new (key, value)); + return true; +} + +RZ_API char *rz_asm_code_equ_replace (RzAsmCode *code, char *str) { + rz_return_val_if_fail (code && str, NULL); + RzAsmEqu *equ; + RzListIter *iter; + rz_list_foreach (code->equs, iter, equ) { + str = rz_str_replace (str, equ->key, equ->value, true); + } + return str; +} + +RZ_API char* rz_asm_code_get_hex(RzAsmCode *acode) { + rz_return_val_if_fail (acode, NULL); + char* str = calloc (acode->len + 1, 2); + if (str) { + rz_hex_bin2str (acode->bytes, acode->len, str); + } + return str; +} \ No newline at end of file diff --git a/librz/asm/aop.c b/librz/asm/aop.c new file mode 100644 index 0000000000..0ef69eff98 --- /dev/null +++ b/librz/asm/aop.c @@ -0,0 +1,86 @@ +/* radare - LGPL - Copyright 2018-2020 - pancake */ + +#include + +RZ_API RzAsmOp *rz_asm_op_new(void) { + return R_NEW0 (RzAsmOp); +} + +RZ_API void rz_asm_op_free(RzAsmOp *op) { + rz_asm_op_fini (op); + free (op); +} + +RZ_API void rz_asm_op_init(RzAsmOp *op) { + if (op) { + memset (op, 0, sizeof (*op)); + } +} + +RZ_API void rz_asm_op_fini(RzAsmOp *op) { + rz_strbuf_fini (&op->buf); + rz_strbuf_fini (&op->buf_asm); + rz_buf_fini (op->buf_inc); +} + +// accessors +RZ_API char *rz_asm_op_get_hex(RzAsmOp *op) { + rz_return_val_if_fail (op, NULL); + int size = rz_strbuf_length (&op->buf); + char* str = calloc (size + 1, 2); + rz_return_val_if_fail (str, NULL); + rz_hex_bin2str ((const ut8*) rz_strbuf_get (&op->buf), size, str); + return str; +} + +RZ_API char *rz_asm_op_get_asm(RzAsmOp *op) { + rz_return_val_if_fail (op, NULL); + return rz_strbuf_get (&op->buf_asm); +} + +RZ_API ut8 *rz_asm_op_get_buf(RzAsmOp *op) { + rz_return_val_if_fail (op, NULL); + return (ut8*)rz_strbuf_get (&op->buf); +} + +RZ_API int rz_asm_op_get_size(RzAsmOp *op) { + rz_return_val_if_fail (op, 1); + const int len = op->size - op->payload; + return R_MAX (1, len); +} + +RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str) { + rz_return_if_fail (op && str); + rz_strbuf_set (&op->buf_asm, str); +} + +RZ_API int rz_asm_op_set_hex(RzAsmOp *op, const char *str) { + ut8 *bin = (ut8*)strdup (str); + if (bin) { + int len = rz_hex_str2bin (str, bin); + if (len > 0) { + rz_strbuf_setbin (&op->buf, bin, len); + } + free (bin); + return len; + } + return 0; +} + +RZ_API int rz_asm_op_set_hexbuf(RzAsmOp *op, const ut8 *buf, int len) { + rz_return_val_if_fail (op && buf && len >= 0, 0); + char *hex = malloc (len * 4 + 1); + if (hex) { + (void)rz_hex_bin2str (buf, len, hex); + int olen = rz_asm_op_set_hex (op, hex); + free (hex); + return olen; + } + return 0; +} + +RZ_API void rz_asm_op_set_buf(RzAsmOp *op, const ut8 *buf, int len) { + rz_return_if_fail (op && buf && len >= 0); + rz_strbuf_setbin (&op->buf, buf, len); + rz_asm_op_set_hexbuf (op, buf, len); +} diff --git a/libr/asm/arch/6502/6502dis.c b/librz/asm/arch/6502/6502dis.c similarity index 96% rename from libr/asm/arch/6502/6502dis.c rename to librz/asm/arch/6502/6502dis.c index 3492095f54..5d85ace491 100644 --- a/libr/asm/arch/6502/6502dis.c +++ b/librz/asm/arch/6502/6502dis.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015-2016 - pancake, condret, riq, qnix */ -#include -#include +#include +#include #include #include "../snes/snesdis.c" @@ -134,7 +134,7 @@ static struct { {0x53, "sre (0x%02x),y", 2}, {-1, NULL, 0}}; -static int _6502Disass (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) { +static int _6502Disass (ut64 pc, RzAsmOp *op, const ut8 *buf, ut64 len) { int i; for (i=0; ops[i].name != NULL; i++) { if (ops[i].op == buf[0]) { @@ -171,7 +171,7 @@ static int _6502Disass (ut64 pc, RAsmOp *op, const ut8 *buf, ut64 len) { default: goto beach; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); return len; } } diff --git a/libr/asm/arch/8051/8051_ass.c b/librz/asm/arch/8051/8051_ass.c similarity index 93% rename from libr/asm/arch/8051/8051_ass.c rename to librz/asm/arch/8051/8051_ass.c index ce2dc2d376..2d31110d84 100644 --- a/libr/asm/arch/8051/8051_ass.c +++ b/librz/asm/arch/8051/8051_ass.c @@ -11,7 +11,7 @@ * ## Section 4: Generic instruction emitters * ## Section 5: Specific instruction parsing * ## Section 6: mnemonic token dispatcher - * ## Section 7: radare2 glue and mnemonic tokenization + * ## Section 7: rizin glue and mnemonic tokenization * * documentation date: 2019-10-04 * documentation date: 2019-10-14 @@ -81,7 +81,7 @@ * and splits up the arguments * \*****************************************************************************/ -#include +#include #include /****************************************************************************** @@ -226,7 +226,7 @@ static bool terminates_asm_line(char c) { } /** - * Like r_str_casecmp, but ignores all isspace characters + * Like rz_str_casecmp, but ignores all isspace characters */ static int str_iwhitecasecmp(char const*a, char const*b) { if (!a && !b) { @@ -325,13 +325,13 @@ static bool is_indirect_reg(char const*str) } if (str[0] == '@' ) { - return r_str_ansi_nlen (str, 4) == 3 + return rz_str_ansi_nlen (str, 4) == 3 && tolower (str[1]) == 'r' && (str[2] == '0' || str[2] == '1'); } if (str[0] == '[' ) { - return r_str_ansi_nlen (str, 5) == 4 + return rz_str_ansi_nlen (str, 5) == 4 && tolower (str[1]) == 'r' && (str[2] == '0' || str[2] == '1') && str[3] == ']'; @@ -345,7 +345,7 @@ static bool is_indirect_reg(char const*str) */ static bool is_reg(char const*str) { - return str && tolower (str[0]) == 'r' && r_str_ansi_nlen (str, 3) == 2 + return str && tolower (str[0]) == 'r' && rz_str_ansi_nlen (str, 3) == 2 && '0' <= str[1] && str[1] <= '7'; } @@ -366,13 +366,13 @@ static bool relative_address(ut16 pc, ut16 address, ut8 *out) } static bool resolve_immediate(char const* imm_str, ut16* imm_out) { - // rasm2 resolves symbols, so does this really only need to parse hex? + // rz_asm resolves symbols, so does this really only need to parse hex? // maybe TODO: skip leading '#' if exists? return parse_hexadecimal (imm_str, imm_out); } static bool to_address(char const* addr_str, ut16* addr_out) { - // rasm2 resolves symbols, so does this really only need to parse hex? + // rz_asm resolves symbols, so does this really only need to parse hex? // maybe TODO: check address bounds? return parse_hexadecimal (addr_str, addr_out); } @@ -382,7 +382,7 @@ static bool to_address(char const* addr_str, ut16* addr_out) { */ static bool address_direct(char const* addr_str, ut8* addr_out) { ut16 addr_big; - // rasm2 resolves symbols, so does this really only need to parse hex? + // rz_asm resolves symbols, so does this really only need to parse hex? // maybe TODO: check address bounds? if ( !parse_hexadecimal (addr_str, &addr_big) || (0xFF < addr_big)) { @@ -398,7 +398,7 @@ static bool address_direct(char const* addr_str, ut8* addr_out) { static bool address_bit(char const* addr_str, ut8* addr_out) { char *bitpart = malloc (strlen (addr_str) + 1); char *bytepart = malloc (strlen (addr_str) + 1); - char const *separator = r_str_lchr (addr_str, '.'); + char const *separator = rz_str_lchr (addr_str, '.'); ut8 byte; int bit; bool ret = false; @@ -410,9 +410,9 @@ static bool address_bit(char const* addr_str, ut8* addr_out) { if (!separator) { goto end; } - r_str_ncpy (bytepart, addr_str, separator - addr_str + 1); + rz_str_ncpy (bytepart, addr_str, separator - addr_str + 1); bytepart[separator - addr_str + 1] = '\0'; - r_str_ncpy (bitpart, separator + 1, strlen (separator)); + rz_str_ncpy (bitpart, separator + 1, strlen (separator)); if (!address_direct (bytepart, &byte)) { goto end; } @@ -515,7 +515,7 @@ static bool singlearg_register(ut8 firstbyte, char const*reg, ut8**out) { static bool single_a_arg_instr(ut8 const firstbyte, char const*arg , ut8 **out) { - if (r_str_casecmp ("a", arg)) { + if (rz_str_casecmp ("a", arg)) { return false; } return single_byte_instr (firstbyte, out); @@ -537,7 +537,7 @@ static bool mnem_acall(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_add(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } switch (arg[1][0]) { @@ -554,7 +554,7 @@ static bool mnem_add(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_addc(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } if (is_indirect_reg (arg[1])) { @@ -604,7 +604,7 @@ static bool mnem_anl(char const*const*arg, ut16 pc, ut8**out) { if (!address_direct (arg[0], &address)) { return false; } - if (!r_str_casecmp (arg[1], "a")) { + if (!rz_str_casecmp (arg[1], "a")) { return singlearg_direct (0x52, arg[0], out); } ut16 imm; @@ -624,7 +624,7 @@ static bool mnem_cjne(char const*const*arg, ut16 pc, ut8**out) { || !relative_address (pc+1, address, (*out)+2)) { return false; } - if (!r_str_casecmp (arg[0], "a")) { + if (!rz_str_casecmp (arg[0], "a")) { if (arg[1][0] == '#') { ut16 imm; if (!resolve_immediate (arg[1] + 1, &imm)) { @@ -672,20 +672,20 @@ static bool mnem_cjne(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_clr(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp ("a", arg[0])) { + if (!rz_str_casecmp ("a", arg[0])) { return single_byte_instr (0xe4, out); } - if (!r_str_casecmp ("c", arg[0])) { + if (!rz_str_casecmp ("c", arg[0])) { return single_byte_instr (0xc3, out); } return singlearg_bit (0xc2, arg[0], out); } static bool mnem_cpl(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp ("a", arg[0])) { + if (!rz_str_casecmp ("a", arg[0])) { return single_byte_instr (0xf4, out); } - if (!r_str_casecmp ("c", arg[0])) { + if (!rz_str_casecmp ("c", arg[0])) { return single_byte_instr (0xb3, out); } return singlearg_bit (0xb2, arg[0], out); @@ -702,14 +702,14 @@ static bool mnem_dec(char const*const*arg, ut16 pc, ut8**out) { if (is_reg (arg[0])) { return singlearg_register (0x18, arg[0], out); } - if (!r_str_casecmp ("a", arg[0])) { + if (!rz_str_casecmp ("a", arg[0])) { return single_byte_instr (0x14, out); } return singlearg_direct (0x15, arg[0], out); } static bool mnem_div(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp ("ab", arg[0])) { + if (rz_str_casecmp ("ab", arg[0])) { return false; } return single_byte_instr (0x84, out); @@ -748,10 +748,10 @@ static bool mnem_inc(char const*const*arg, ut16 pc, ut8**out) { if (is_indirect_reg (arg[0])) { return singlearg_register (0x06, arg[0], out); } - if (!r_str_casecmp ("a", arg[0])) { + if (!rz_str_casecmp ("a", arg[0])) { return single_byte_instr (0x04, out); } - if (!r_str_casecmp ("dptr", arg[0])) { + if (!rz_str_casecmp ("dptr", arg[0])) { return single_byte_instr (0xa3, out); } return singlearg_direct (0x05, arg[0], out); @@ -853,7 +853,7 @@ static bool mnem_mov_c(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp (arg[0], "dptr")) { + if (!rz_str_casecmp (arg[0], "dptr")) { ut16 imm; if (!resolve_immediate (arg[1] + 1, &imm)) { return false; @@ -865,7 +865,7 @@ static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { return true; } if (is_indirect_reg (arg[0])) { - if (!r_str_casecmp (arg[1], "a")) { + if (!rz_str_casecmp (arg[1], "a")) { return singlearg_register (0xf6, arg[0], out); } if (arg[1][0] != '#' ) { @@ -878,7 +878,7 @@ static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { , arg[1] , out); } - if (!r_str_casecmp (arg[0], "a")) { + if (!rz_str_casecmp (arg[0], "a")) { if (is_indirect_reg (arg[1])) { return singlearg_register (0xe6, arg[1], out); } @@ -891,7 +891,7 @@ static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { return singlearg_direct (0xe5, arg[1], out); } if (is_reg (arg[0])) { - if (!r_str_casecmp (arg[1], "a")) { + if (!rz_str_casecmp (arg[1], "a")) { return singlearg_register (0xf8, arg[0], out); } if (arg[1][0] == '#') { @@ -904,10 +904,10 @@ static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { , arg[1] , out); } - if (!r_str_casecmp (arg[1], "c")) { + if (!rz_str_casecmp (arg[1], "c")) { return singlearg_bit (0x92, arg[0], out); } - if (!r_str_casecmp (arg[1], "a")) { + if (!rz_str_casecmp (arg[1], "a")) { return singlearg_direct (0xf5, arg[0], out); } if (is_reg (arg[1])) { @@ -947,7 +947,7 @@ static bool mnem_mov(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_movc(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } if (!str_iwhitecasecmp (arg[1], "@a+dptr") @@ -962,7 +962,7 @@ static bool mnem_movc(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_movx(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp (arg[0], "a")) { + if (!rz_str_casecmp (arg[0], "a")) { if (is_indirect_reg (arg[1])) { return singlearg_register (0xe2, arg[1], out); } @@ -971,7 +971,7 @@ static bool mnem_movx(char const*const*arg, ut16 pc, ut8**out) { return single_byte_instr (0xe0, out); } } - if (r_str_casecmp (arg[1], "a")) { + if (rz_str_casecmp (arg[1], "a")) { return false; } if (is_indirect_reg (arg[0])) { @@ -985,7 +985,7 @@ static bool mnem_movx(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_mul(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_ncasecmp ("ab", arg[0], 3)) { + if (rz_str_ncasecmp ("ab", arg[0], 3)) { return false; } return single_byte_instr (0xa4, out); @@ -996,13 +996,13 @@ static bool mnem_nop(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_orl(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp (arg[0], "c")) { + if (!rz_str_casecmp (arg[0], "c")) { if (arg[1][0] == '/') { return singlearg_bit (0xa0, arg[1] + 1, out); } return singlearg_bit (0x72, arg[1], out); } - if (!r_str_casecmp (arg[0], "a")) { + if (!rz_str_casecmp (arg[0], "a")) { if (is_indirect_reg (arg[1])) { return singlearg_register (0x46, arg[1], out); } @@ -1067,7 +1067,7 @@ static bool mnem_rrc(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_setb(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp ("c", arg[0])) { + if (!rz_str_casecmp ("c", arg[0])) { return single_byte_instr (0xd3, out); } return singlearg_bit (0xd2, arg[0], out); @@ -1107,7 +1107,7 @@ static bool mnem_jmp(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_subb(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } if (is_indirect_reg (arg[1])) { @@ -1127,7 +1127,7 @@ static bool mnem_swap(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_xrl(char const*const*arg, ut16 pc, ut8**out) { - if (!r_str_casecmp (arg[0], "a")) { + if (!rz_str_casecmp (arg[0], "a")) { if (is_indirect_reg (arg[1])) { return singlearg_register (0x66, arg[1], out); } @@ -1140,7 +1140,7 @@ static bool mnem_xrl(char const*const*arg, ut16 pc, ut8**out) { return singlearg_direct (0x65, arg[1], out); } if (arg[1][0] != '#') { - if (r_str_casecmp (arg[1], "a")) { + if (rz_str_casecmp (arg[1], "a")) { return false; } return singlearg_direct (0x62, arg[0], out); @@ -1161,7 +1161,7 @@ static bool mnem_xrl(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_xch(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } if (is_indirect_reg (arg[1])) { @@ -1174,7 +1174,7 @@ static bool mnem_xch(char const*const*arg, ut16 pc, ut8**out) { } static bool mnem_xchd(char const*const*arg, ut16 pc, ut8**out) { - if (r_str_casecmp (arg[0], "a")) { + if (rz_str_casecmp (arg[0], "a")) { return false; } if (!is_indirect_reg (arg[1])) { @@ -1247,14 +1247,14 @@ static parse_mnem_args mnemonic(char const *user_asm, int*nargs) { } /****************************************************************************** - * ## Section 7: radare2 glue and mnemonic tokenization + * ## Section 7: rizin glue and mnemonic tokenization --------------------------------------*/ -int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm) { +int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm) { if (!a || !op || !user_asm) { return 0; } - r_strbuf_set (&op->buf_asm, user_asm); + rz_strbuf_set (&op->buf_asm, user_asm); while (!terminates_asm_line (*user_asm) && (*user_asm == ' ' || *user_asm == '\t')) { user_asm += 1; @@ -1294,7 +1294,7 @@ int assemble_8051(RAsm *a, RAsmOp *op, char const *user_asm) { free (arg[1]); arg[1] = 0; carg[1] = 0; free (arg[2]); arg[2] = 0; carg[0] = 0; size_t len = binp - instr; - r_strbuf_setbin (&op->buf, instr, len); + rz_strbuf_setbin (&op->buf, instr, len); return binp - instr; } } diff --git a/librz/asm/arch/8051/8051_ass.h b/librz/asm/arch/8051/8051_ass.h new file mode 100644 index 0000000000..a6a36f0fed --- /dev/null +++ b/librz/asm/arch/8051/8051_ass.h @@ -0,0 +1,7 @@ +#ifndef _8051_ASS_H +#define _8051_ASS_H + +#include +int assemble_8051(RzAsm *a, RzAsmOp *op, char const *user_asm); + +#endif diff --git a/libr/asm/arch/8051/8051_disas.c b/librz/asm/arch/8051/8051_disas.c similarity index 75% rename from libr/asm/arch/8051/8051_disas.c rename to librz/asm/arch/8051/8051_disas.c index 13d1357e09..adad5e0dcc 100644 --- a/libr/asm/arch/8051/8051_disas.c +++ b/librz/asm/arch/8051/8051_disas.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015-2019 - pancake, condret, riq, qnix, astuder */ -#include -#include +#include +#include #include #include "8051_ops.h" @@ -48,20 +48,20 @@ static char* _replace_register(char* disasm, ut8 arg, ut8 val) { if (_8051_regs[val]) { sprintf (key, " 0x%02x", val); sprintf (subst, " %s", _8051_regs[val]); - disasm = r_str_replace (disasm, key, subst, 0); + disasm = rz_str_replace (disasm, key, subst, 0); } } else if (arg == A_BIT) { val = arg_bit (val); if (_8051_regs[val]) { sprintf (key, "0x%02x.", val); sprintf (subst, "%s.", _8051_regs[val]); - disasm = r_str_replace (disasm, key, subst, 0); + disasm = rz_str_replace (disasm, key, subst, 0); } } return disasm; } -static char *r_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { +static char *rz_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { int i = 0; while (_8051_ops[i].string && _8051_ops[i].op != (buf[0] & ~_8051_ops[i].mask)) { i++; @@ -82,36 +82,36 @@ static char *r_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { case 1: if ((arg1 == A_RI) || (arg1 == A_RN)) { // op @Ri; op Rn - disasm = r_str_newf (name, buf[0] & mask); + disasm = rz_str_newf (name, buf[0] & mask); } else { - disasm = r_str_new (name); + disasm = rz_str_new (name); } break; case 2: if (len>1) { if (arg1 == A_OFFSET) { - disasm = r_str_newf (name, arg_offset (pc + 2, buf[1])); + disasm = rz_str_newf (name, arg_offset (pc + 2, buf[1])); } else if (arg1 == A_ADDR11) { - disasm = r_str_newf (name, arg_addr11 (pc + 2, buf)); + disasm = rz_str_newf (name, arg_addr11 (pc + 2, buf)); } else if ((arg1 == A_RI) || (arg1 == A_RN)) { // op @Ri, arg; op Rn, arg if (arg2 == A_OFFSET) { - disasm = r_str_newf (name, buf[0] & mask, arg_offset (pc + 2, buf[1])); + disasm = rz_str_newf (name, buf[0] & mask, arg_offset (pc + 2, buf[1])); } else { - disasm = r_str_newf (name, buf[0] & mask, buf[1]); + disasm = rz_str_newf (name, buf[0] & mask, buf[1]); } val2 = buf[1]; } else if ((arg2 == A_RI) || (arg2 == A_RN)) { // op arg, @Ri; op arg, Rn - disasm = r_str_newf (name, buf[1], buf[0] & mask); + disasm = rz_str_newf (name, buf[1], buf[0] & mask); val1 = buf[1]; } else if (arg1 == A_BIT) { // bit addressing mode - disasm = r_str_newf (name, arg_bit (buf[1]), buf[1] & 0x07); + disasm = rz_str_newf (name, arg_bit (buf[1]), buf[1] & 0x07); val1 = buf[1]; } else { // direct, immediate, bit - disasm = r_str_newf (name, buf[1]); + disasm = rz_str_newf (name, buf[1]); val1 = buf[1]; } } else { @@ -122,34 +122,34 @@ static char *r_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { case 3: if (len > 2) { if ((arg1 == A_ADDR16) || (arg1 == A_IMM16)) { - disasm = r_str_newf (name, 0x100 * buf[1] + buf[2]); + disasm = rz_str_newf (name, 0x100 * buf[1] + buf[2]); } else if (arg1 == A_IMM16) { - disasm = r_str_newf (name, 0x100 * buf[1] + buf[2]); + disasm = rz_str_newf (name, 0x100 * buf[1] + buf[2]); } else if (arg2 == A_OFFSET) { if (mask != A_NONE) { // @Ri, immediate, offset; Rn, immediate, offset - disasm = r_str_newf (name, buf[0] & mask, buf[1], arg_offset (pc + 3, buf[1])); + disasm = rz_str_newf (name, buf[0] & mask, buf[1], arg_offset (pc + 3, buf[1])); } else if (arg1 == A_BIT) { // bit, offset - disasm = r_str_newf (name, arg_bit (buf[1]), buf[1] & 0x07, arg_offset (pc + 3, buf[2])); + disasm = rz_str_newf (name, arg_bit (buf[1]), buf[1] & 0x07, arg_offset (pc + 3, buf[2])); val1 = buf[1]; } else { // direct, offset; a, immediate, offset - disasm = r_str_newf (name, buf[1], arg_offset (pc + 3, buf[2])); + disasm = rz_str_newf (name, buf[1], arg_offset (pc + 3, buf[2])); val1 = buf[1]; } } else if (arg3 == A_OFFSET) { // @Ri/Rn, direct, offset - disasm = r_str_newf (name, buf[0] & mask, buf[1], arg_offset (pc + 3, buf[2])); + disasm = rz_str_newf (name, buf[0] & mask, buf[1], arg_offset (pc + 3, buf[2])); val2 = buf[1]; } else if (arg1 == A_DIRECT && arg2 == A_DIRECT) { // op direct, direct has src and dest swapped - disasm = r_str_newf (name, buf[2], buf[1]); + disasm = rz_str_newf (name, buf[2], buf[1]); val1 = buf[2]; val2 = buf[1]; } else { // direct, immediate - disasm = r_str_newf (name, buf[1], buf[2]); + disasm = rz_str_newf (name, buf[1], buf[2]); val1 = buf[1]; } } else { diff --git a/libr/asm/arch/8051/8051_ops.h b/librz/asm/arch/8051/8051_ops.h similarity index 99% rename from libr/asm/arch/8051/8051_ops.h rename to librz/asm/arch/8051/8051_ops.h index 3cc07736cc..dd0555c79d 100644 --- a/libr/asm/arch/8051/8051_ops.h +++ b/librz/asm/arch/8051/8051_ops.h @@ -3,7 +3,7 @@ #ifndef _8051_OPS_H #define _8051_OPS_H -#include +#include static inline ut16 arg_offset (ut16 pc, ut8 offset) { if (offset < 0x80) { @@ -91,7 +91,7 @@ typedef struct { ut8 op; int cycles; op8051 instr; // instruction - _RAnalOpType type; + _RzAnalOpType type; char* string; // disassembly output size_t len; argmask8051 mask; // bits masked to determine opcode diff --git a/libr/asm/arch/amd29k/amd29k.c b/librz/asm/arch/amd29k/amd29k.c similarity index 99% rename from libr/asm/arch/amd29k/amd29k.c rename to librz/asm/arch/amd29k/amd29k.c index cde0f0d690..62eaa95110 100644 --- a/libr/asm/arch/amd29k/amd29k.c +++ b/librz/asm/arch/amd29k/amd29k.c @@ -2,7 +2,7 @@ #include "amd29k_internal.h" #include #include -#include +#include #define CPU_ANY "*" diff --git a/libr/asm/arch/amd29k/amd29k.h b/librz/asm/arch/amd29k/amd29k.h similarity index 96% rename from libr/asm/arch/amd29k/amd29k.h rename to librz/asm/arch/amd29k/amd29k.h index 8a5dc1a895..47f65eeb51 100644 --- a/libr/asm/arch/amd29k/amd29k.h +++ b/librz/asm/arch/amd29k/amd29k.h @@ -2,7 +2,7 @@ #define ASM_AMD_29K_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/libr/asm/arch/amd29k/amd29k_internal.h b/librz/asm/arch/amd29k/amd29k_internal.h similarity index 100% rename from libr/asm/arch/amd29k/amd29k_internal.h rename to librz/asm/arch/amd29k/amd29k_internal.h diff --git a/libr/asm/arch/arc/gnu/arc-dis.c b/librz/asm/arch/arc/gnu/arc-dis.c similarity index 99% rename from libr/asm/arch/arc/gnu/arc-dis.c rename to librz/asm/arch/arc/gnu/arc-dis.c index 1e8f6fb39d..44cd0f1692 100644 --- a/libr/asm/arch/arc/gnu/arc-dis.c +++ b/librz/asm/arch/arc/gnu/arc-dis.c @@ -42,7 +42,7 @@ if dbg is 1 then this definition is required */ //#define eprintf(x,y...) fprintf(stderr,x,##y) -#include "r_types.h" +#include "rz_types.h" #ifndef dbg #define dbg (0) diff --git a/libr/asm/arch/arc/gnu/arc-dis.h b/librz/asm/arch/arc/gnu/arc-dis.h similarity index 100% rename from libr/asm/arch/arc/gnu/arc-dis.h rename to librz/asm/arch/arc/gnu/arc-dis.h diff --git a/libr/asm/arch/arc/gnu/arc-ext.c b/librz/asm/arch/arc/gnu/arc-ext.c similarity index 100% rename from libr/asm/arch/arc/gnu/arc-ext.c rename to librz/asm/arch/arc/gnu/arc-ext.c diff --git a/libr/asm/arch/arc/gnu/arc-ext.h b/librz/asm/arch/arc/gnu/arc-ext.h similarity index 100% rename from libr/asm/arch/arc/gnu/arc-ext.h rename to librz/asm/arch/arc/gnu/arc-ext.h diff --git a/libr/asm/arch/arc/gnu/arc-opc-cgen.h b/librz/asm/arch/arc/gnu/arc-opc-cgen.h similarity index 100% rename from libr/asm/arch/arc/gnu/arc-opc-cgen.h rename to librz/asm/arch/arc/gnu/arc-opc-cgen.h diff --git a/libr/asm/arch/arc/gnu/arc-opc.c b/librz/asm/arch/arc/gnu/arc-opc.c similarity index 100% rename from libr/asm/arch/arc/gnu/arc-opc.c rename to librz/asm/arch/arc/gnu/arc-opc.c diff --git a/libr/asm/arch/arc/gnu/arc-opc.h b/librz/asm/arch/arc/gnu/arc-opc.h similarity index 100% rename from libr/asm/arch/arc/gnu/arc-opc.h rename to librz/asm/arch/arc/gnu/arc-opc.h diff --git a/libr/asm/arch/arc/gnu/arc.h b/librz/asm/arch/arc/gnu/arc.h similarity index 100% rename from libr/asm/arch/arc/gnu/arc.h rename to librz/asm/arch/arc/gnu/arc.h diff --git a/libr/asm/arch/arc/gnu/arcompact-dis.c b/librz/asm/arch/arc/gnu/arcompact-dis.c similarity index 99% rename from libr/asm/arch/arc/gnu/arcompact-dis.c rename to librz/asm/arch/arc/gnu/arcompact-dis.c index a4e613f2c8..f49db399d8 100644 --- a/libr/asm/arch/arc/gnu/arcompact-dis.c +++ b/librz/asm/arch/arc/gnu/arcompact-dis.c @@ -31,7 +31,7 @@ #include "arc-dis.h" #include "arcompact-dis.h" #include "elf-bfd.h" -#include "r_types.h" +#include "rz_types.h" /* warning: implicit declaration of function `eprintf' diff --git a/libr/asm/arch/arc/gnu/arcompact-dis.h b/librz/asm/arch/arc/gnu/arcompact-dis.h similarity index 100% rename from libr/asm/arch/arc/gnu/arcompact-dis.h rename to librz/asm/arch/arc/gnu/arcompact-dis.h diff --git a/librz/asm/arch/arm/Makefile b/librz/asm/arch/arm/Makefile new file mode 100644 index 0000000000..d34aad6453 --- /dev/null +++ b/librz/asm/arch/arm/Makefile @@ -0,0 +1,3 @@ +all: + gcc -I../../../include armass.c -DMAIN -lrz_util + ./a.out diff --git a/libr/asm/arch/arm/aarch64/Makefile b/librz/asm/arch/arm/aarch64/Makefile similarity index 100% rename from libr/asm/arch/arm/aarch64/Makefile rename to librz/asm/arch/arm/aarch64/Makefile diff --git a/libr/asm/arch/arm/aarch64/aarch64-dis-2.c b/librz/asm/arch/arm/aarch64/aarch64-dis-2.c similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-dis-2.c rename to librz/asm/arch/arm/aarch64/aarch64-dis-2.c diff --git a/libr/asm/arch/arm/aarch64/aarch64-dis.c b/librz/asm/arch/arm/aarch64/aarch64-dis.c similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-dis.c rename to librz/asm/arch/arm/aarch64/aarch64-dis.c diff --git a/libr/asm/arch/arm/aarch64/aarch64-dis.h b/librz/asm/arch/arm/aarch64/aarch64-dis.h similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-dis.h rename to librz/asm/arch/arm/aarch64/aarch64-dis.h diff --git a/libr/asm/arch/arm/aarch64/aarch64-opc-2.c b/librz/asm/arch/arm/aarch64/aarch64-opc-2.c similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-opc-2.c rename to librz/asm/arch/arm/aarch64/aarch64-opc-2.c diff --git a/libr/asm/arch/arm/aarch64/aarch64-opc.c b/librz/asm/arch/arm/aarch64/aarch64-opc.c similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-opc.c rename to librz/asm/arch/arm/aarch64/aarch64-opc.c diff --git a/libr/asm/arch/arm/aarch64/aarch64-opc.h b/librz/asm/arch/arm/aarch64/aarch64-opc.h similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-opc.h rename to librz/asm/arch/arm/aarch64/aarch64-opc.h diff --git a/libr/asm/arch/arm/aarch64/aarch64-tbl.h b/librz/asm/arch/arm/aarch64/aarch64-tbl.h similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64-tbl.h rename to librz/asm/arch/arm/aarch64/aarch64-tbl.h diff --git a/libr/asm/arch/arm/aarch64/aarch64.h b/librz/asm/arch/arm/aarch64/aarch64.h similarity index 100% rename from libr/asm/arch/arm/aarch64/aarch64.h rename to librz/asm/arch/arm/aarch64/aarch64.h diff --git a/libr/asm/arch/arm/aarch64/sysdep.h b/librz/asm/arch/arm/aarch64/sysdep.h similarity index 100% rename from libr/asm/arch/arm/aarch64/sysdep.h rename to librz/asm/arch/arm/aarch64/sysdep.h diff --git a/libr/asm/arch/arm/armass.c b/librz/asm/arch/arm/armass.c similarity index 97% rename from libr/asm/arch/arm/armass.c rename to librz/asm/arch/arm/armass.c index 3eba9427fc..93a3d09ed7 100644 --- a/libr/asm/arch/arm/armass.c +++ b/librz/asm/arch/arm/armass.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "armass16_const.h" // TODO: only lo registers accessible in thumb arm @@ -202,7 +202,7 @@ static char *parse_hints(char *input) { static st8 iflag(char *input) { st8 res = 0; - r_str_case (input, false); + rz_str_case (input, false); for (; *input; input++) { switch (*input) { @@ -232,7 +232,7 @@ static ut64 cqcheck(char **input) { "hi", "ls", "ge", "lt", "gt", "le", "al", "nv", 0 }; for (i = 0; conds[i]; i++) { - if (r_str_startswith (*input, conds[i])) { + if (rz_str_startswith (*input, conds[i])) { res |= C_MATCH_BIT; res |= i << 2; *input += 2; @@ -240,12 +240,12 @@ static ut64 cqcheck(char **input) { break; } } - if (r_str_startswith (*input, ".n")) { + if (rz_str_startswith (*input, ".n")) { res |= DOTN_BIT; *input += 2; offset += 2; } else - if (r_str_startswith (*input, ".w")) { + if (rz_str_startswith (*input, ".w")) { res |= DOTW_BIT; *input += 2; offset += 2; @@ -261,11 +261,11 @@ static ut64 cqcheck(char **input) { static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { ut64 res = 0; - r_str_case (input, false); + rz_str_case (input, false); if (strlen (opcode) > strlen (input)) { return 0; } - if (r_str_startswith (input, opcode)) { + if (rz_str_startswith (input, opcode)) { input += strlen (opcode); res |= M_BIT; res |= cqcheck (&input); @@ -276,28 +276,28 @@ static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { } res |= cqcheck (&input); - if ((r_str_startswith (input, "wb")) && (WB_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "wb")) && (WB_BIT & allowed_mask)) { res |= WB_BIT; input += 2; } - if ((r_str_startswith (input, "wt")) && (WT_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "wt")) && (WT_BIT & allowed_mask)) { res |= WT_BIT; input += 2; } res |= cqcheck (&input); - if ((r_str_startswith (input, "db")) && (DB_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "db")) && (DB_BIT & allowed_mask)) { res |= DB_BIT; input += 2; } - if ((r_str_startswith (input, "ea")) && (EA_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "ea")) && (EA_BIT & allowed_mask)) { res |= EA_BIT; input += 2; } - if ((r_str_startswith (input, "ia")) && (IA_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "ia")) && (IA_BIT & allowed_mask)) { res |= IA_BIT; input += 2; } - if ((r_str_startswith (input, "fd")) && (FD_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "fd")) && (FD_BIT & allowed_mask)) { res |= FD_BIT; input += 2; } @@ -307,19 +307,19 @@ static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { input++; } res |= cqcheck (&input); - if ((r_str_startswith (input, "bb")) && (BB_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "bb")) && (BB_BIT & allowed_mask)) { res |= BB_BIT; input += 2; } - if ((r_str_startswith (input, "tt")) && (TT_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "tt")) && (TT_BIT & allowed_mask)) { res |= TT_BIT; input += 2; } - if ((r_str_startswith (input, "bt")) && (BT_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "bt")) && (BT_BIT & allowed_mask)) { res |= BT_BIT; input += 2; } - if ((r_str_startswith (input, "tb")) && (TB_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "tb")) && (TB_BIT & allowed_mask)) { res |= TB_BIT; input += 2; } @@ -362,7 +362,7 @@ static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { res |= EIGHT_BIT; input++; } - if ((r_str_startswith (input, "16")) && (SIXTEEN_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "16")) && (SIXTEEN_BIT & allowed_mask)) { res |= SIXTEEN_BIT; input += 2; } @@ -376,16 +376,16 @@ static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { input++; } res |= cqcheck (&input); - if ((r_str_startswith (input, "id")) && (ID_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "id")) && (ID_BIT & allowed_mask)) { res |= ID_BIT; input += 2; } - if ((r_str_startswith (input, "ie")) && (IE_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "ie")) && (IE_BIT & allowed_mask)) { res |= IE_BIT; input += 2; } res |= cqcheck (&input); - if ((r_str_startswith (input, "sh")) && (SH_BIT & allowed_mask)) { + if ((rz_str_startswith (input, "sh")) && (SH_BIT & allowed_mask)) { res |= SH_BIT; input += 2; } @@ -403,11 +403,11 @@ static ut64 opmask(char *input, char *opcode, ut64 allowed_mask) { static ut32 itmask(char *input) { ut32 res = 0; ut32 i, length; - r_str_case (input, false); + rz_str_case (input, false); if (2 > strlen (input)) { return 0; } - if (r_str_startswith (input, "it")) { + if (rz_str_startswith (input, "it")) { input += 2; res |= 1; // matched if (strlen(input) > 3) { @@ -455,11 +455,11 @@ static ut64 getnum(const char *str) { static ut64 getnumbang(const char *str) { ut64 res; - if (!str || !*str || !r_str_endswith (str, "!")) { + if (!str || !*str || !rz_str_endswith (str, "!")) { err = true; return 0; } - char *temp = r_str_ndup (str, strlen (str) - 1); + char *temp = rz_str_ndup (str, strlen (str) - 1); if (!temp) { return -1; } @@ -663,7 +663,7 @@ static st32 getlistmask(char *input) { for (i = 0; input[i] != ',' && input[i] != '\0'; i++) { ; } - r_str_ncpy (temp, input, i + 1); + rz_str_ncpy (temp, input, i + 1); input += i; if (*input != '\0') { @@ -716,11 +716,11 @@ static st32 getregmemstart(const char *input) { static st32 getregmemstartend(const char *input) { st32 res; - if (!input || (strlen (input) < 2) || (*input != '[') || !r_str_endswith (input, "]")) { + if (!input || (strlen (input) < 2) || (*input != '[') || !rz_str_endswith (input, "]")) { return -1; } input++; - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { return -1; } @@ -731,11 +731,11 @@ static st32 getregmemstartend(const char *input) { static st32 getregmemend(const char *input) { st32 res; - if (!input || !*input || !r_str_endswith (input, "]")) { + if (!input || !*input || !rz_str_endswith (input, "]")) { return -1; } - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { return -1; } @@ -747,13 +747,13 @@ static st32 getregmemend(const char *input) { static st32 getreglist(const char *input) { st32 res; - if (!input || (strlen (input) < 2) || (*input != '{') || !r_str_endswith (input, "}")) { + if (!input || (strlen (input) < 2) || (*input != '{') || !rz_str_endswith (input, "}")) { return -1; } if (*input) { input++; } - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { return -1; } @@ -765,11 +765,11 @@ static st32 getreglist(const char *input) { static st32 getnummemend (const char *input) { st32 res; err = false; - if (!input || !*input || !r_str_endswith (input, "]")) { + if (!input || !*input || !rz_str_endswith (input, "]")) { err = true; return -1; } - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { err = true; return -1; @@ -782,11 +782,11 @@ static st32 getnummemend (const char *input) { static st32 getnummemendbang (const char *input) { st32 res; err = false; - if (!input || (strlen (input) < 2) || (input[strlen(input) - 2] != ']' || !r_str_endswith (input, "!"))) { + if (!input || (strlen (input) < 2) || (input[strlen(input) - 2] != ']' || !rz_str_endswith (input, "!"))) { err = true; return 0; } - char *temp = r_str_ndup (input, strlen (input) - 2); + char *temp = rz_str_ndup (input, strlen (input) - 2); if (!temp) { err = true; return 0; @@ -798,10 +798,10 @@ static st32 getnummemendbang (const char *input) { static st32 getregmembang(const char *input) { st32 res; - if (!input || !*input || !r_str_endswith (input, "!")) { + if (!input || !*input || !rz_str_endswith (input, "!")) { return -1; } - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { return -1; } @@ -833,7 +833,7 @@ static int getcoprocreg(const char *str) { if (!str || !*str) { return -1; } - if (r_str_startswith (str, "c")) { + if (rz_str_startswith (str, "c")) { int reg = strtol (str + 1, &ep, 10); if ((ep[0] != '\0') || (str[1] == '\0')) { return -1; @@ -849,13 +849,13 @@ static ut8 interpret_msrbank (char *str, ut8 *spsr) { const char fields[] = {'c', 'x', 's', 'f', 0}; int res = 0; int i, j; - if (r_str_startswith (str, "spsr_")) { + if (rz_str_startswith (str, "spsr_")) { *spsr = 1; } else { *spsr = 0; } - if (r_str_startswith (str, "apsr_")) { + if (rz_str_startswith (str, "apsr_")) { if (!(strcmp (str+5, "g"))) { return 0x4; } @@ -866,7 +866,7 @@ static ut8 interpret_msrbank (char *str, ut8 *spsr) { return 0xc; } } - if (r_str_startswith (str, "cpsr_") || r_str_startswith (str, "spsr_")) { + if (rz_str_startswith (str, "cpsr_") || rz_str_startswith (str, "spsr_")) { for (i = 0; str[5+i]; i++) { for (j = 0; fields[j]; j++) { if (str[5+i] == fields[j]) { @@ -897,7 +897,7 @@ static ut32 thumb_getshift(const char *str) { ut32 argn; ut32 i; - r_str_case (type,true); + rz_str_case (type,true); if (!strcmp (type, shifts[5])) { // handle RRX alias case @@ -946,11 +946,11 @@ static ut32 thumb_getshift(const char *str) { static st32 getshiftmemend(const char *input) { st32 res; - if (!input || !*input || !r_str_endswith (input, "]")) { + if (!input || !*input || !rz_str_endswith (input, "]")) { return -1; } - char *temp = r_str_ndup (input, strlen (input) - 1); + char *temp = rz_str_ndup (input, strlen (input) - 1); if (!temp) { return -1; } @@ -1094,7 +1094,7 @@ static ut32 getshift(const char *str) { strncpy (type, str, sizeof (type) - 1); // XXX strcaecmp is probably unportable - if (!r_str_casecmp (type, shifts[5])) { + if (!rz_str_casecmp (type, shifts[5])) { // handle RRX alias case shift = 6; } else { // all other shift types @@ -1106,7 +1106,7 @@ static ut32 getshift(const char *str) { strncpy (arg, ++space, sizeof(arg) - 1); for (i = 0; shifts[i]; i++) { - if (!r_str_casecmp (type, shifts[i])) { + if (!rz_str_casecmp (type, shifts[i])) { shift = 1; break; } @@ -1188,7 +1188,7 @@ static inline int arm_opcode_cond(ArmOpcode *ao, int delta) { } static st32 thumb_getoffset(char *label, ut64 cur) { - st32 res = r_num_math (NULL, label); + st32 res = rz_num_math (NULL, label); res -= 4; res -= cur; // possible integer underflow //printf("thumb_getoffset: %s, %lld, %lld\n", label, res, cur); @@ -2080,7 +2080,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { } break; case THUMB_OTHER: { - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); if (strcmpnull (ao->a[0], "sy")) { return -1; } @@ -2110,7 +2110,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { } // intentional fallthrough case THUMB_OTHER: { - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); if (!strcmpnull ((ao->a[0] = parse_hints(ao->a[0])), "-1")) { return -1; } @@ -2176,7 +2176,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { } // intentional fallthrough case THUMB_OTHER: { - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); if (strcmpnull (ao->a[0], "sy")) { return -1; } @@ -2208,7 +2208,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", "hi", "ls", "ge", "lt", "gt", "le", "al", "nv", 0 }; - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); for (i = 0; conds[i]; i++) { if (!(strcmpnull(ao->a[0], conds[i]))) { cond = i; @@ -3174,7 +3174,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { switch (argt) { case THUMB_REG_OTHER: { ut32 reg1 = getreg (ao->a[0]); - r_str_case (ao->a[1], false); + rz_str_case (ao->a[1], false); if (reg1 > 15) { return -1; @@ -3203,7 +3203,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { ut64 argt = thumb_selector (ao->a); switch (argt) { case THUMB_OTHER_REG: { - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); ut8 spsr = 0; ut8 bank = interpret_msrbank (ao->a[0], &spsr); ut32 reg1 = getreg (ao->a[1]); @@ -4068,7 +4068,7 @@ static int thumb_assemble(ArmOpcode *ao, ut64 off, const char *str) { ut64 argt = thumb_selector (ao->a); switch (argt) { case THUMB_OTHER: { - r_str_case (ao->a[0], false); + rz_str_case (ao->a[0], false); ao->o = 0x50b6; if (!(strcmpnull (ao->a[0], "be"))) { ao->o |= 1 << 11; @@ -6594,7 +6594,7 @@ void thisplay(const char *str) { char cmd[32]; int op = armass_assemble (str, 0x1000, 1); printf ("[%04x] %s\n", op, str); - snprintf (cmd, sizeof(cmd), "rasm2 -d -b 16 -a arm %04x", op); + snprintf (cmd, sizeof(cmd), "rz_asm -d -b 16 -a arm %04x", op); system (cmd); } @@ -6602,7 +6602,7 @@ void display(const char *str) { char cmd[32]; int op = armass_assemble (str, 0x1000, 0); printf ("[%08x] %s\n", op, str); - snprintf (cmd, sizeof(cmd), "rasm2 -d -a arm %08x", op); + snprintf (cmd, sizeof(cmd), "rz_asm -d -a arm %08x", op); system (cmd); } diff --git a/libr/asm/arch/arm/armass16_const.h b/librz/asm/arch/arm/armass16_const.h similarity index 100% rename from libr/asm/arch/arm/armass16_const.h rename to librz/asm/arch/arm/armass16_const.h diff --git a/libr/asm/arch/arm/armass64.c b/librz/asm/arch/arm/armass64.c similarity index 97% rename from libr/asm/arch/arm/armass64.c rename to librz/asm/arch/arm/armass64.c index 0b9f559ed4..330a061b67 100644 --- a/libr/asm/arch/arm/armass64.c +++ b/librz/asm/arch/arm/armass64.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include typedef enum optype_t { ARM_NOTYPE = -1, @@ -70,7 +70,7 @@ static int get_mem_option(char *token) { "xxx", "osh", "oshst", "oshld", NULL}; int i = 0; while (options[i]) { - if (!r_str_casecmp (token, options[i])) { + if (!rz_str_casecmp (token, options[i])) { return 15 - i; } i++; @@ -836,7 +836,7 @@ static bool parseOperands(char* str, ArmOp *op) { if ( token[0] == '#' || (token[0] >= '0' && token[0] <= '9')) { //immediate operand found. op->operands[operand].sp_val = 0xfffe; //not regiter, but a immediate - op->operands[operand].immediate = r_num_math (NULL, token[0]=='#'?token+1:token); + op->operands[operand].immediate = rz_num_math (NULL, token[0]=='#'?token+1:token); operand ++; token = next; continue; @@ -874,7 +874,7 @@ static bool parseOperands(char* str, ArmOp *op) { } if (strlen (token) > 4 && op->operands[operand].shift != ARM_NO_SHIFT) { op->operands_count ++; - op->operands[operand].shift_amount = r_num_math (NULL, token + 4); + op->operands[operand].shift_amount = rz_num_math (NULL, token + 4); if (op->operands[operand].shift_amount > 63) { free (t); return false; @@ -898,7 +898,7 @@ static bool parseOperands(char* str, ArmOp *op) { // XZR op->operands[operand].reg = 31; } else { - op->operands[operand].reg = r_num_math (NULL, token + 1); + op->operands[operand].reg = rz_num_math (NULL, token + 1); } if (op->operands[operand].reg > 31) { @@ -918,7 +918,7 @@ static bool parseOperands(char* str, ArmOp *op) { // WSP op->operands[operand].reg = 31; } else { - op->operands[operand].reg = r_num_math (NULL, token + 1); + op->operands[operand].reg = rz_num_math (NULL, token + 1); } if (op->operands[operand].reg > 31) { @@ -929,14 +929,14 @@ static bool parseOperands(char* str, ArmOp *op) { case 'v': op->operands_count ++; op->operands[operand].type = ARM_FP; - op->operands[operand].reg = r_num_math (NULL, token + 1); + op->operands[operand].reg = rz_num_math (NULL, token + 1); break; case 's': case 'S': if (token[1] == 'P' || token [1] == 'p') { int i; for (i = 0; msr_const[i].name; i++) { - if (!r_str_ncasecmp (token, msr_const[i].name, strlen (msr_const[i].name))) { + if (!rz_str_ncasecmp (token, msr_const[i].name, strlen (msr_const[i].name))) { op->operands[operand].sp_val = msr_const[i].val; break; } @@ -977,7 +977,7 @@ static bool parseOperands(char* str, ArmOp *op) { } op->operands_count ++; op->operands[operand].type = ARM_CONSTANT; - op->operands[operand].immediate = r_num_math (NULL, token + 1); + op->operands[operand].immediate = rz_num_math (NULL, token + 1); imm_count++; break; case '-': @@ -986,7 +986,7 @@ static bool parseOperands(char* str, ArmOp *op) { default: op->operands_count ++; op->operands[operand].type = ARM_CONSTANT; - op->operands[operand].immediate = r_num_math (NULL, token); + op->operands[operand].immediate = rz_num_math (NULL, token); imm_count++; break; } diff --git a/libr/asm/arch/arm/armass64_const.h b/librz/asm/arch/arm/armass64_const.h similarity index 100% rename from libr/asm/arch/arm/armass64_const.h rename to librz/asm/arch/arm/armass64_const.h diff --git a/libr/asm/arch/arm/asm-arm.h b/librz/asm/arch/arm/asm-arm.h similarity index 82% rename from libr/asm/arch/arm/asm-arm.h rename to librz/asm/arch/arm/asm-arm.h index e8a5f97564..f18468df9a 100644 --- a/libr/asm/arch/arm/asm-arm.h +++ b/librz/asm/arch/arm/asm-arm.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_ARMASS_H_ #define _INCLUDE_ARMASS_H_ -#include +#include int armass_assemble(const char *str, ut64 off, int thumb); diff --git a/libr/asm/arch/arm/gnu/README.md b/librz/asm/arch/arm/gnu/README.md similarity index 100% rename from libr/asm/arch/arm/gnu/README.md rename to librz/asm/arch/arm/gnu/README.md diff --git a/libr/asm/arch/arm/gnu/arm-dis.c b/librz/asm/arch/arm/gnu/arm-dis.c similarity index 100% rename from libr/asm/arch/arm/gnu/arm-dis.c rename to librz/asm/arch/arm/gnu/arm-dis.c diff --git a/libr/asm/arch/arm/gnu/elfarm.h b/librz/asm/arch/arm/gnu/elfarm.h similarity index 100% rename from libr/asm/arch/arm/gnu/elfarm.h rename to librz/asm/arch/arm/gnu/elfarm.h diff --git a/libr/asm/arch/arm/gnu/floatformat.c b/librz/asm/arch/arm/gnu/floatformat.c similarity index 100% rename from libr/asm/arch/arm/gnu/floatformat.c rename to librz/asm/arch/arm/gnu/floatformat.c diff --git a/libr/asm/arch/arm/gnu/floatformat.h b/librz/asm/arch/arm/gnu/floatformat.h similarity index 100% rename from libr/asm/arch/arm/gnu/floatformat.h rename to librz/asm/arch/arm/gnu/floatformat.h diff --git a/libr/asm/arch/arm/gnu/opcode-arm.h b/librz/asm/arch/arm/gnu/opcode-arm.h similarity index 100% rename from libr/asm/arch/arm/gnu/opcode-arm.h rename to librz/asm/arch/arm/gnu/opcode-arm.h diff --git a/libr/asm/arch/arm/winedbg/be_arm.c b/librz/asm/arch/arm/winedbg/be_arm.c similarity index 67% rename from libr/asm/arch/arm/winedbg/be_arm.c rename to librz/asm/arch/arm/winedbg/be_arm.c index aedfddb52b..73c0368502 100644 --- a/libr/asm/arch/arm/winedbg/be_arm.c +++ b/librz/asm/arch/arm/winedbg/be_arm.c @@ -1,8 +1,8 @@ #include #include #include -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" #include "be_arm.h" #define ARM_INSN_SIZE 4 @@ -76,7 +76,7 @@ static ut32 arm_disasm_branch(struct winedbg_arm_insn *arminsn, ut32 inst) { offset |= 0xfc000000; } offset += 8; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "b%s%s 0x%"PFMT64x, link ? "l" : "", get_cond (inst), arminsn->pc+offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "b%s%s 0x%"PFMT64x, link ? "l" : "", get_cond (inst), arminsn->pc+offset); arminsn->jmp = arminsn->pc+offset; arminsn->fail = arminsn->pc+4; @@ -88,12 +88,12 @@ static ut32 arm_disasm_mul(struct winedbg_arm_insn *arminsn, ut32 inst) { short condcodes = (inst >> 20) & 0x01; if (accu) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mla%s%s %s, %s, %s, %s", get_cond (inst), condcodes ? "s" : "", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mla%s%s %s, %s, %s, %s", get_cond (inst), condcodes ? "s" : "", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 3)]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mul%s%s %s, %s, %s", get_cond (inst), condcodes ? "s" : "", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mul%s%s %s, %s, %s", get_cond (inst), condcodes ? "s" : "", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 2)]); } @@ -105,7 +105,7 @@ static ut32 arm_disasm_longmul(struct winedbg_arm_insn *arminsn, ut32 inst) { short accu = (inst >> 21) & 0x01; short condcodes = (inst >> 20) & 0x01; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s%s %s, %s, %s, %s", sign ? "s" : "u", accu ? "mlal" : "mull", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s%s %s, %s, %s, %s", sign ? "s" : "u", accu ? "mlal" : "mull", get_cond (inst), condcodes ? "s" : "", tbl_regs[get_nibble (inst, 3)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 2)]); @@ -115,26 +115,26 @@ static ut32 arm_disasm_longmul(struct winedbg_arm_insn *arminsn, ut32 inst) { static ut32 arm_disasm_swp(struct winedbg_arm_insn *arminsn, ut32 inst) { short byte = (inst >> 22) & 0x01; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "swp%s%s %s, %s, [%s]", get_cond (inst), byte ? "b" : "", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "swp%s%s %s, %s, [%s]", get_cond (inst), byte ? "b" : "", tbl_regs[get_nibble (inst, 3)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 4)]); return 0; } static ut32 arm_disasm_branchreg(struct winedbg_arm_insn *arminsn, ut32 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "b%s %s", get_cond (inst), tbl_regs[get_nibble (inst, 0)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "b%s %s", get_cond (inst), tbl_regs[get_nibble (inst, 0)]); return 0; } static ut32 arm_disasm_branchxchg(struct winedbg_arm_insn *arminsn, ut32 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "bx%s %s", get_cond (inst), tbl_regs[get_nibble (inst, 0)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "bx%s %s", get_cond (inst), tbl_regs[get_nibble (inst, 0)]); return 0; } static ut32 arm_disasm_mrstrans(struct winedbg_arm_insn *arminsn, ut32 inst) { short src = (inst >> 22) & 0x01; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mrs%s %s, %s", get_cond (inst), tbl_regs[get_nibble (inst, 3)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mrs%s %s, %s", get_cond (inst), tbl_regs[get_nibble (inst, 3)], src ? "spsr" : "cpsr"); return 0; } @@ -145,11 +145,11 @@ static ut32 arm_disasm_msrtrans(struct winedbg_arm_insn *arminsn, ut32 inst) { short simple = (inst >> 16) & 0x01; if (simple || !immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "msr%s %s, %s", get_cond (inst), dst ? "spsr" : "cpsr", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "msr%s %s, %s", get_cond (inst), dst ? "spsr" : "cpsr", tbl_regs[get_nibble (inst, 0)]); return 0; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "msr%s %s, #%u", get_cond (inst), dst ? "spsr" : "cpsr", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "msr%s %s, #%u", get_cond (inst), dst ? "spsr" : "cpsr", ROR32 (inst & 0xff, 2 * get_nibble (inst, 2))); return 0; } @@ -157,14 +157,14 @@ static ut32 arm_disasm_msrtrans(struct winedbg_arm_insn *arminsn, ut32 inst) { static ut32 arm_disasm_wordmov(struct winedbg_arm_insn *arminsn, ut32 inst) { short top = (inst >> 22) & 0x01; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mov%s%s %s, #%u", top ? "t" : "w", get_cond (inst), + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mov%s%s %s, #%u", top ? "t" : "w", get_cond (inst), tbl_regs[get_nibble (inst, 3)], (get_nibble (inst, 4) << 12) | (inst & 0x0fff)); return 0; } static ut32 arm_disasm_nop(struct winedbg_arm_insn *arminsn, ut32 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "nop%s", get_cond (inst)); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "nop%s", get_cond (inst)); return 0; } @@ -175,36 +175,36 @@ static ut32 arm_disasm_dataprocessing(struct winedbg_arm_insn *arminsn, ut32 ins short no_op1 = (opcode & 0x0d) == 0x0d; short no_dst = (opcode & 0x0c) == 0x08; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s", tbl_dataops[opcode], condcodes ? "s" : "", get_cond (inst)); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s", tbl_dataops[opcode], condcodes ? "s" : "", get_cond (inst)); if (!no_dst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " "); } if (no_op1) { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "#%u", ROR32 (inst & 0xff, 2 * get_nibble (inst, 2))); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "#%u", ROR32 (inst & 0xff, 2 * get_nibble (inst, 2))); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s", tbl_regs[get_nibble (inst, 0)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s", tbl_regs[get_nibble (inst, 0)]); } } else { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, #%u", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, #%u", tbl_regs[get_nibble (inst, 4)], ROR32 (inst & 0xff, 2 * get_nibble (inst, 2))); } else if (((inst >> 4) & 0xff) == 0x00) { /* no shift */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); } else if (((inst >> 4) & 0x09) == 0x01) { /* register shift */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s, %s %s", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s, %s %s", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_shifts[(inst >> 5) & 0x03], tbl_regs[(inst >> 8) & 0x0f]); } else if (((inst >> 4) & 0x01) == 0x00) { /* immediate shift */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s, %s #%d", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s, %s #%d", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_shifts[(inst >> 5) & 0x03], (inst >> 7) & 0x1f); } @@ -228,19 +228,19 @@ static ut32 arm_disasm_singletrans(struct winedbg_arm_insn *arminsn, ut32 inst) offset *= -1; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s%s", load ? "ldr" : "str", byte ? "b" : "", writeback ? "t" : "", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s%s", load ? "ldr" : "str", byte ? "b" : "", writeback ? "t" : "", get_cond (inst)); - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); if (indexing) { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s, #%d]", tbl_regs[get_nibble (inst, 4)], offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s, #%d]", tbl_regs[get_nibble (inst, 4)], offset); } else if (((inst >> 4) & 0xff) == 0x00) { /* no shift */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s, %s]", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s, %s]", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); } else if (((inst >> 4) & 0x01) == 0x00) {/* immediate shift (there's no register shift) */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s, %s, %s #%d]", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s, %s, %s #%d]", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_shifts[(inst >> 5) & 0x03], (inst >> 7) & 0x1f); } @@ -249,14 +249,14 @@ static ut32 arm_disasm_singletrans(struct winedbg_arm_insn *arminsn, ut32 inst) } } else { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s], #%d", tbl_regs[get_nibble (inst, 4)], offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s], #%d", tbl_regs[get_nibble (inst, 4)], offset); } else if (((inst >> 4) & 0xff) == 0x00) { /* no shift */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s], %s", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s], %s", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); } else if (((inst >> 4) & 0x01) == 0x00) { /* immediate shift (there's no register shift) */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s], %s, %s #%d", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s], %s, %s #%d", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_shifts[(inst >> 5) & 0x03], (inst >> 7) & 0x1f); } @@ -281,23 +281,23 @@ static ut32 arm_disasm_halfwordtrans(struct winedbg_arm_insn *arminsn, ut32 inst offset *= -1; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s%s%s", load ? "ldr" : "str", sign ? "s" : "", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s%s%s", load ? "ldr" : "str", sign ? "s" : "", halfword ? "h" : (sign ? "b" : ""), writeback ? "t" : "", get_cond (inst)); - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " %s, ", tbl_regs[get_nibble (inst, 3)]); if (indexing) { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s, #%d]", tbl_regs[get_nibble (inst, 4)], offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s, #%d]", tbl_regs[get_nibble (inst, 4)], offset); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s, %s]", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s, %s]", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); } } else { if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s], #%d", tbl_regs[get_nibble (inst, 4)], offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s], #%d", tbl_regs[get_nibble (inst, 4)], offset); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "[%s], %s", tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "[%s], %s", tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); } } @@ -319,24 +319,24 @@ static ut32 arm_disasm_blocktrans(struct winedbg_arm_insn *arminsn, ut32 inst) { } } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s %s%s, {", load ? "ldm" : "stm", tbl_addrmode[addrmode], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s %s%s, {", load ? "ldm" : "stm", tbl_addrmode[addrmode], get_cond (inst), tbl_regs[get_nibble (inst, 4)], writeback ? "!" : ""); for (i=0;i<=15;i++) { if ((inst>>i) & 1) { if (i == last) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); } } } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "}%s", psr ? "^" : ""); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "}%s", psr ? "^" : ""); return 0; } static ut32 arm_disasm_swi(struct winedbg_arm_insn *arminsn, ut32 inst) { ut32 comment = inst & 0x00ffffff; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "swi%s #%d", get_cond (inst), comment); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "swi%s #%d", get_cond (inst), comment); return 0; } @@ -348,7 +348,7 @@ static ut32 arm_disasm_coproctrans(struct winedbg_arm_insn *arminsn, ut32 inst) ut16 load = (inst >> 20) & 0x01; ut16 CP_Opc = (inst >> 21) & 0x07; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s %u, %u, %s, cr%u, cr%u, {%u}", load ? "mrc" : "mcr", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s %u, %u, %s, cr%u, cr%u, {%u}", load ? "mrc" : "mcr", get_cond (inst), CPnum, CP, tbl_regs[get_nibble (inst, 3)], CRn, CRm, CP_Opc); return 0; } @@ -361,7 +361,7 @@ static ut32 arm_disasm_coprocdataop(struct winedbg_arm_insn *arminsn, ut32 inst) ut16 CRn = (inst >> 16) & 0x0f; ut16 CP_Opc = (inst >> 20) & 0x0f; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "cdp%s %u, %u, cr%u, cr%u, cr%u, {%u}", get_cond (inst), + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "cdp%s %u, %u, cr%u, cr%u, cr%u, {%u}", get_cond (inst), CPnum, CP, CRd, CRn, CRm, CP_Opc); return 0; } @@ -380,12 +380,12 @@ static ut32 arm_disasm_coprocdatatrans(struct winedbg_arm_insn *arminsn, ut32 in offset *= -1; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s%s", load ? "ldc" : "stc", translen ? "l" : "", get_cond (inst)); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s%s", load ? "ldc" : "stc", translen ? "l" : "", get_cond (inst)); if (indexing) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " %u, cr%u, [%s, #%d]%s", CPnum, CRd, tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " %u, cr%u, [%s, #%d]%s", CPnum, CRd, tbl_regs[get_nibble (inst, 4)], offset, writeback ? "!" : ""); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, " %u, cr%u, [%s], #%d", CPnum, CRd, tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, " %u, cr%u, [%s], #%d", CPnum, CRd, tbl_regs[get_nibble (inst, 4)], offset); } return 0; @@ -406,15 +406,15 @@ static ut16 thumb_disasm_hireg(struct winedbg_arm_insn *arminsn, ut16 inst) { } if (op == 2 && dst == src) { /* mov rx, rx */ - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "nop"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "nop"); return 0; } if (op == 3) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "b%sx %s", h1?"l":"", tbl_regs[src]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "b%sx %s", h1?"l":"", tbl_regs[src]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, %s", tbl_hiops_t[op], tbl_regs[dst], tbl_regs[src]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, %s", tbl_hiops_t[op], tbl_regs[dst], tbl_regs[src]); } return 0; } @@ -424,7 +424,7 @@ static ut16 thumb_disasm_aluop(struct winedbg_arm_insn *arminsn, ut16 inst) { short src = (inst >> 3) & 0x07; short op = (inst >> 6) & 0x0f; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, %s", tbl_aluops_t[op], tbl_regs[dst], tbl_regs[src]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, %s", tbl_aluops_t[op], tbl_regs[dst], tbl_regs[src]); return 0; } @@ -441,23 +441,23 @@ static ut16 thumb_disasm_pushpop(struct winedbg_arm_insn *arminsn, ut16 inst) { } last = i; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s {", load ? "pop" : "push"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s {", load ? "pop" : "push"); for (i=0;i<=7;i++) { if ((inst>>i) & 1) { if (i == last) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); } } } if (lrpc) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s", last ? ", " : "", load ? "pc" : "lr"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s", last ? ", " : "", load ? "pc" : "lr"); } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "}"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "}"); return 0; } @@ -473,26 +473,26 @@ static ut16 thumb_disasm_blocktrans(struct winedbg_arm_insn *arminsn, ut16 inst) } last = i; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s!, {", load ? "ldmia" : "stmia", tbl_regs[(inst >> 8) & 0x07]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s!, {", load ? "ldmia" : "stmia", tbl_regs[(inst >> 8) & 0x07]); for (i=0;i<=7;i++) { if ((inst>>i) & 1) { if (i == last) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s", tbl_regs[i]); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, ", tbl_regs[i]); } } } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "}"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "}"); return 0; } static ut16 thumb_disasm_condbranch(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = inst & 0x00ff; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "b%s 0x%"PFMT64x, tbl_cond[(inst >> 8) & 0x0f], arminsn->pc+offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "b%s 0x%"PFMT64x, tbl_cond[(inst >> 8) & 0x0f], arminsn->pc+offset); arminsn->jmp = arminsn->pc+offset; arminsn->fail = arminsn->pc+4; @@ -506,7 +506,7 @@ static ut16 thumb_disasm_uncondbranch(struct winedbg_arm_insn *arminsn, ut16 ins offset |= 0xf000; } offset += 4; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "b 0x%"PFMT64x, arminsn->pc+offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "b 0x%"PFMT64x, arminsn->pc+offset); arminsn->jmp = arminsn->pc+offset; return 0; @@ -516,31 +516,31 @@ static ut16 thumb_disasm_loadadr(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 src = (inst >> 11) & 0x01; ut16 offset = (inst & 0xff) << 2; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "add %s, %s, #%d", tbl_regs[(inst >> 8) & 0x07], src ? "sp" : "pc", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "add %s, %s, #%d", tbl_regs[(inst >> 8) & 0x07], src ? "sp" : "pc", offset); return 0; } static ut16 thumb_disasm_swi(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 comment = inst & 0x00ff; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "swi #%d", comment); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "swi #%d", comment); return 0; } static ut16 thumb_disasm_nop(struct winedbg_arm_insn *arminsn, ut16 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "nop"); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "nop"); return 0; } static ut16 thumb_disasm_ldrpcrel(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = (inst & 0xff) << 2; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "ldr %s, [pc, #%u]", tbl_regs[(inst >> 8) & 0x07], offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "ldr %s, [pc, #%u]", tbl_regs[(inst >> 8) & 0x07], offset); return 0; } static ut16 thumb_disasm_ldrsprel(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = (inst & 0xff) << 2; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, [sp, #%u]", (inst & 0x0800)?"ldr":"str", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, [sp, #%u]", (inst & 0x0800)?"ldr":"str", tbl_regs[(inst >> 8) & 0x07], offset); return 0; } @@ -548,17 +548,17 @@ static ut16 thumb_disasm_ldrsprel(struct winedbg_arm_insn *arminsn, ut16 inst) { static ut16 thumb_disasm_addsprel(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = (inst & 0x7f) << 2; if ((inst >> 7) & 0x01) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "sub sp, sp, #%u", offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "sub sp, sp, #%u", offset); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "add sp, sp, #%u", offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "add sp, sp, #%u", offset); } return 0; } static ut16 thumb_disasm_ldrimm(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = (inst & 0x07c0) >> 6; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s %s, [%s, #%u]", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s %s, [%s, #%u]", (inst & 0x0800)?"ldr":"str", (inst & 0x1000)?"b":"", tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07], (inst & 0x1000)?offset:(offset << 2)); @@ -567,13 +567,13 @@ static ut16 thumb_disasm_ldrimm(struct winedbg_arm_insn *arminsn, ut16 inst) { static ut16 thumb_disasm_ldrhimm(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 offset = (inst & 0x07c0) >> 5; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, [%s, #%u]", (inst & 0x0800)?"ldrh":"strh", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, [%s, #%u]", (inst & 0x0800)?"ldrh":"strh", tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07], offset); return 0; } static ut16 thumb_disasm_ldrreg(struct winedbg_arm_insn *arminsn, ut16 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s%s %s, [%s, %s]", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s %s, [%s, %s]", (inst & 0x0800)?"ldr":"str", (inst & 0x0400)?"b":"", tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07], tbl_regs[(inst >> 6) & 0x07]); @@ -581,7 +581,7 @@ static ut16 thumb_disasm_ldrreg(struct winedbg_arm_insn *arminsn, ut16 inst) { } static ut16 thumb_disasm_ldrsreg(struct winedbg_arm_insn *arminsn, ut16 inst) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, [%s, %s]", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, [%s, %s]", tbl_sregops_t[(inst >> 10) & 0x03], tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07], tbl_regs[(inst >> 6) & 0x07]); return 0; @@ -589,7 +589,7 @@ static ut16 thumb_disasm_ldrsreg(struct winedbg_arm_insn *arminsn, ut16 inst) { static ut16 thumb_disasm_immop(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 op = (inst >> 11) & 0x03; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, #%u", tbl_immops_t[op], tbl_regs[(inst >> 8) & 0x07], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, #%u", tbl_immops_t[op], tbl_regs[(inst >> 8) & 0x07], inst & 0xff); return 0; } @@ -598,27 +598,27 @@ static ut16 thumb_disasm_addsub(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 op = (inst >> 9) & 0x01; ut16 immediate = (inst >> 10) & 0x01; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, %s, ", op ? "sub" : "add", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, %s, ", op ? "sub" : "add", tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07]); if (immediate) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "#%d", (inst >> 6) & 0x07); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "#%d", (inst >> 6) & 0x07); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s", tbl_regs[(inst >> 6) & 0x07]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s", tbl_regs[(inst >> 6) & 0x07]); } return 0; } static ut16 thumb_disasm_movshift(struct winedbg_arm_insn *arminsn, ut16 inst) { ut16 op = (inst >> 11) & 0x03; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s %s, %s, #%u", tbl_shifts[op], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s %s, %s, #%u", tbl_shifts[op], tbl_regs[inst & 0x07], tbl_regs[(inst >> 3) & 0x07], (inst >> 6) & 0x1f); return 0; } static ut32 thumb2_disasm_branchlinked(struct winedbg_arm_insn *arminsn, ut32 inst) { ut32 offset = (((inst & 0x07ff0000) >> 4) | ((inst & 0x000007ff) << 1)) + 4; - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "bl 0x%"PFMT64x, arminsn->pc+offset); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "bl 0x%"PFMT64x, arminsn->pc+offset); arminsn->jmp = arminsn->pc+offset; return 0; @@ -633,7 +633,7 @@ static ut32 thumb2_disasm_misc(struct winedbg_arm_insn *arminsn, ut32 inst) { } if (op1 == 3 && op2 == 0) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "clz %s, %s ", tbl_regs[get_nibble (inst, 2)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "clz %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 0)]); return 0; } @@ -641,19 +641,19 @@ static ut32 thumb2_disasm_misc(struct winedbg_arm_insn *arminsn, ut32 inst) { if (op1 == 1) { switch (op2) { case 0: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "rev "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "rev "); break; case 1: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "rev16 "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "rev16 "); break; case 2: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "rbit "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "rbit "); break; case 3: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "revsh "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "revsh "); break; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 0)]); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 0)]); return 0; } @@ -669,7 +669,7 @@ static ut32 thumb2_disasm_mul(struct winedbg_arm_insn *arminsn, ut32 inst) { } if (op2 == 0 && get_nibble (inst, 3) != 0xf) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mla %s, %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mla %s, %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 3)]); @@ -677,14 +677,14 @@ static ut32 thumb2_disasm_mul(struct winedbg_arm_insn *arminsn, ut32 inst) { } if (op2 == 0 && get_nibble (inst, 3) == 0xf) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mul %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mul %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); return 0; } if (op2 == 1) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "mls %s, %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "mls %s, %s, %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)], tbl_regs[get_nibble (inst, 3)]); @@ -701,21 +701,21 @@ static ut32 thumb2_disasm_longmuldiv(struct winedbg_arm_insn *arminsn, ut32 inst if (op2 == 0) { switch (op1) { case 0: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "smull "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "smull "); break; case 2: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "umull "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "umull "); break; case 4: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "smlal "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "smlal "); break; case 6: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "umlal "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "umlal "); break; default: return inst; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s, %s, %s ", + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s, %s, %s ", tbl_regs[get_nibble (inst, 3)], tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); return 0; @@ -724,15 +724,15 @@ static ut32 thumb2_disasm_longmuldiv(struct winedbg_arm_insn *arminsn, ut32 inst if (op2 == 0xffff) { switch (op1) { case 1: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "sdiv "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "sdiv "); break; case 3: - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "udiv "); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "udiv "); break; default: return inst; } - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "%s, %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s, %s, %s ", tbl_regs[get_nibble (inst, 2)], tbl_regs[get_nibble (inst, 4)], tbl_regs[get_nibble (inst, 0)]); return 0; } @@ -745,13 +745,13 @@ static ut32 thumb2_disasm_coprocmov1(struct winedbg_arm_insn *arminsn, ut32 inst ut16 opc2 = (inst >> 5) & 0x07; if (opc2) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s\tp%u, #%u, %s, cr%u, cr%u, #%u", (inst & 0x00100000)?"mrc":"mcr", (inst & 0x10000000)?"2":"", get_nibble (inst, 2), opc1, tbl_regs[get_nibble (inst, 3)], get_nibble (inst, 4), get_nibble (inst, 0), opc2); } else { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "%s%s\tp%u, #%u, %s, cr%u, cr%u", (inst & 0x00100000)?"mrc":"mcr", (inst & 0x10000000)?"2":"", get_nibble (inst, 2), opc1, tbl_regs[get_nibble (inst, 3)], get_nibble (inst, 4), get_nibble (inst, 0)); @@ -886,12 +886,12 @@ int arm_disasm_one_insn(struct winedbg_arm_insn *arminsn) { } if (!matched) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "Unknown ARM Instruction: %08x", inst); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "Unknown ARM Instruction: %08x", inst); } else { a_ptr->func(arminsn, inst); } - arminsn->str_hex = r_str_appendf (arminsn->str_hex, "%02x%02x%02x%02x", + arminsn->str_hex = rz_str_appendf (arminsn->str_hex, "%02x%02x%02x%02x", *((ut8*)(&inst)), *((ut8*)(&inst)+1), *((ut8*)(&inst)+2), *((ut8*)(&inst)+3)); return size; } else { @@ -913,12 +913,12 @@ int arm_disasm_one_insn(struct winedbg_arm_insn *arminsn) { } if (!matched) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "Unknown Thumb2 Instruction: %08x", inst); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "Unknown Thumb2 Instruction: %08x", inst); } else { t2_ptr->func(arminsn, inst); } - arminsn->str_hex = r_str_appendf (arminsn->str_hex, "%02x%02x%02x%02x", + arminsn->str_hex = rz_str_appendf (arminsn->str_hex, "%02x%02x%02x%02x", *((ut8*)(&inst)), *((ut8*)(&inst)+1), *((ut8*)(&inst)+2), *((ut8*)(&inst)+3)); return size; default: @@ -935,12 +935,12 @@ int arm_disasm_one_insn(struct winedbg_arm_insn *arminsn) { } if (!matched) { - arminsn->str_asm = r_str_appendf (arminsn->str_asm, "Unknown Thumb Instruction: %04x", tinst); + arminsn->str_asm = rz_str_appendf (arminsn->str_asm, "Unknown Thumb Instruction: %04x", tinst); } else { t_ptr->func(arminsn, tinst); } - arminsn->str_hex = r_str_appendf (arminsn->str_hex, "%02x%02x", *((ut8*)(&tinst)), *((ut8*)(&tinst)+1)); + arminsn->str_hex = rz_str_appendf (arminsn->str_hex, "%02x%02x", *((ut8*)(&tinst)), *((ut8*)(&tinst)+1)); return size; } return size; diff --git a/libr/asm/arch/arm/winedbg/be_arm.h b/librz/asm/arch/arm/winedbg/be_arm.h similarity index 100% rename from libr/asm/arch/arm/winedbg/be_arm.h rename to librz/asm/arch/arm/winedbg/be_arm.h diff --git a/libr/asm/arch/avr/Makefile b/librz/asm/arch/avr/Makefile similarity index 100% rename from libr/asm/arch/avr/Makefile rename to librz/asm/arch/avr/Makefile diff --git a/libr/asm/arch/avr/README b/librz/asm/arch/avr/README similarity index 100% rename from libr/asm/arch/avr/README rename to librz/asm/arch/avr/README diff --git a/libr/asm/arch/avr/avr_disasm.c b/librz/asm/arch/avr/avr_disasm.c similarity index 99% rename from libr/asm/arch/avr/avr_disasm.c rename to librz/asm/arch/avr/avr_disasm.c index 6f64e66e4c..287445e743 100644 --- a/libr/asm/arch/avr/avr_disasm.c +++ b/librz/asm/arch/avr/avr_disasm.c @@ -27,7 +27,7 @@ #include "avr_disasm.h" #include "errorcodes.h" #include "avr_instructionset.c" -#include +#include /* AVR instructionSet is defined in avrinstructionset.c */ //extern instructionInfo instructionSet[AVR_TOTAL_INSTRUCTIONS]; diff --git a/libr/asm/arch/avr/avr_disasm.h b/librz/asm/arch/avr/avr_disasm.h similarity index 100% rename from libr/asm/arch/avr/avr_disasm.h rename to librz/asm/arch/avr/avr_disasm.h diff --git a/libr/asm/arch/avr/avr_instructionset.c b/librz/asm/arch/avr/avr_instructionset.c similarity index 100% rename from libr/asm/arch/avr/avr_instructionset.c rename to librz/asm/arch/avr/avr_instructionset.c diff --git a/libr/asm/arch/avr/disasm.c b/librz/asm/arch/avr/disasm.c similarity index 98% rename from libr/asm/arch/avr/disasm.c rename to librz/asm/arch/avr/disasm.c index 98446ff96f..2bf0ec8783 100644 --- a/libr/asm/arch/avr/disasm.c +++ b/librz/asm/arch/avr/disasm.c @@ -1,6 +1,6 @@ #include "avr_disasm.c" #include "format.c" -#include +#include static int avrdis (char *out, ut64 addr, cut8 *buf, int len) { formattingOptions opt = { 0 }; diff --git a/libr/asm/arch/avr/errorcodes.h b/librz/asm/arch/avr/errorcodes.h similarity index 100% rename from libr/asm/arch/avr/errorcodes.h rename to librz/asm/arch/avr/errorcodes.h diff --git a/libr/asm/arch/avr/format.c b/librz/asm/arch/avr/format.c similarity index 100% rename from libr/asm/arch/avr/format.c rename to librz/asm/arch/avr/format.c diff --git a/libr/asm/arch/avr/format.h b/librz/asm/arch/avr/format.h similarity index 100% rename from libr/asm/arch/avr/format.h rename to librz/asm/arch/avr/format.h diff --git a/libr/asm/arch/cr16/cr16_disas.c b/librz/asm/arch/cr16/cr16_disas.c similarity index 95% rename from libr/asm/arch/cr16/cr16_disas.c rename to librz/asm/arch/cr16/cr16_disas.c index 5b24c466cd..ca2f6323a0 100644 --- a/libr/asm/arch/cr16/cr16_disas.c +++ b/librz/asm/arch/cr16/cr16_disas.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "cr16_disas.h" @@ -396,7 +396,7 @@ static inline int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd, int le if (len < 2) { return -1; } - in = r_read_le16 (instr); + in = rz_read_le16 (instr); if (in == 0x0200) { return -1; @@ -419,7 +419,7 @@ static inline int cr16_decode_i_r(const ut8 *instr, struct cr16_cmd *cmd, int le if (len < 4) { return -1; } - immed = r_read_at_le16 (instr, 2); + immed = rz_read_at_le16 (instr, 2); ret = 4; } else { immed = cr16_get_short_imm(in); @@ -467,7 +467,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 2) { return -1; } - ut16 c = r_read_le16 (instr); + ut16 c = rz_read_le16 (instr); if (cr16_print_ld_sw_opcode(cmd, c)) { return -1; @@ -483,7 +483,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); disp32 = disp16 | ((c & 0x0100) << 9) | ((c & 0x0020) << 11); @@ -494,7 +494,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); if (cr16_print_short_reg_rel(cmd, cr16_get_srcreg(c), disp16, cr16_get_dstreg(c) & 0x9)) { @@ -529,7 +529,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); disp32 = disp16 | (((c >> 9) & 0x3) << 16); cr16_print_reg_rel_reg(cmd, disp32, cr16_get_srcreg(c), @@ -541,7 +541,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); disp32 = disp16 | (((c >> 9) & 0x3) << 16); if (cr16_get_srcreg(c) == 0xF) { @@ -556,7 +556,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); disp32 = disp16 | (((c >> 9) & 0x3) << 16); if (cr16_get_srcreg(c) == 0xF) { @@ -571,7 +571,7 @@ static inline int cr16_decode_ld_st(const ut8 *instr, struct cr16_cmd *cmd, int if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); disp32 = disp16 | (((c >> 9) & 0x3) << 16); cr16_print_reg_rel_reg(cmd, disp32, cr16_get_srcreg(c), @@ -611,11 +611,11 @@ static int cr16_decode_slpr(const ut8 *instr, struct cr16_cmd *cmd, int len) { if (len < 2) { return -1; } - ut16 c = r_read_le16 (instr); + ut16 c = rz_read_le16 (instr); const char *ins = instrs_4bit[c >> 9]; if (ins) { - r_str_ncpy (cmd->instr, ins, sizeof (cmd->instr) - 1); + rz_str_ncpy (cmd->instr, ins, sizeof (cmd->instr) - 1); } else { *cmd->instr = 0; } @@ -645,7 +645,7 @@ static int cr16_decode_r_r(const ut8 *instr, struct cr16_cmd *cmd, int len) { if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (!(c & 0x1)) { return -1; @@ -682,7 +682,7 @@ static int cr16_decode_push_pop(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if ((c & 1)) { return -1; @@ -716,7 +716,7 @@ static int cr16_decode_jmp(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); switch (c >> 9) { case CR16_JUMP: @@ -777,7 +777,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (c & 0x1) { return -1; @@ -793,7 +793,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - disp = r_read_at_le16 (instr, 2); + disp = rz_read_at_le16 (instr, 2); disp32 = disp | (((c >> 4) & 0x1) << 16); ret = 4; @@ -812,7 +812,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - disp = r_read_at_le16 (instr, 2); + disp = rz_read_at_le16 (instr, 2); disp32 = disp | (((c >> 1) & 0x7) << 17) | (((c >> 4) & 1) << 16); if (disp32 & 0x80000) { disp32 |= 0xFFF00000; @@ -846,7 +846,7 @@ static int cr16_decode_bcond_br(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - disp = r_read_at_le16 (instr, 2); + disp = rz_read_at_le16 (instr, 2); disp32 = disp | (GET_BIT(c, 4) << 16); if (disp32 & 0x80000) { disp32 |= 0xFFF00000; @@ -883,7 +883,7 @@ static int cr16_decode_bcond01i(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (!(c & 1)) { return -1; @@ -929,7 +929,7 @@ static int cr16_decode_misc(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); cmd->operands[0] = '\0'; switch (c) { @@ -982,8 +982,8 @@ static int cr16_decode_bal(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - c = r_read_le16 (instr); - disp16 = r_read_at_le16 (instr, 2); + c = rz_read_le16 (instr); + disp16 = rz_read_at_le16 (instr, 2); snprintf(cmd->instr, CR16_INSTR_MAXLEN - 1, "bal"); @@ -1013,7 +1013,7 @@ int cr16_decode_loadm_storm(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if ((c & 0x1F) != 4) { return -1; @@ -1037,7 +1037,7 @@ int cr16_decode_movz(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (c & 1) { return -1; @@ -1071,8 +1071,8 @@ int cr16_decode_movd(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - c = r_read_le16 (instr); - imm = r_read_at_le16 (instr, 2); + c = rz_read_le16 (instr); + imm = rz_read_at_le16 (instr, 2); if (c & 1) { return -1; @@ -1096,7 +1096,7 @@ int cr16_decode_muls(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); switch (c >> 9) { case CR16_MULSB: @@ -1136,7 +1136,7 @@ int cr16_decode_scond(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (c & 1) { return -1; @@ -1162,7 +1162,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - c = r_read_le16 (instr); + c = rz_read_le16 (instr); if (((c >> 6) & 0x3) == 0x3) { return -1; @@ -1185,7 +1185,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); abs18 = disp16 | ((reg & 0x1) << 16) | ((reg >> 3) << 17); @@ -1199,7 +1199,7 @@ int cr16_decode_biti(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 4) { return -1; } - disp16 = r_read_at_le16 (instr, 2); + disp16 = rz_read_at_le16 (instr, 2); snprintf(cmd->operands, CR16_INSTR_MAXLEN - 1, "$0x%02x,0x%04x(%s)", position, @@ -1226,7 +1226,7 @@ int cr16_decode_command(const ut8 *instr, struct cr16_cmd *cmd, int len) if (len < 2) { return -1; } - in = r_read_le16 (instr); + in = rz_read_le16 (instr); switch (cr16_get_opcode_low(in)) { case CR16_MOV: diff --git a/libr/asm/arch/cr16/cr16_disas.h b/librz/asm/arch/cr16/cr16_disas.h similarity index 100% rename from libr/asm/arch/cr16/cr16_disas.h rename to librz/asm/arch/cr16/cr16_disas.h diff --git a/libr/asm/arch/cris/gnu/cris-dis.c b/librz/asm/arch/cris/gnu/cris-dis.c similarity index 100% rename from libr/asm/arch/cris/gnu/cris-dis.c rename to librz/asm/arch/cris/gnu/cris-dis.c diff --git a/libr/asm/arch/cris/gnu/cris-opc.c b/librz/asm/arch/cris/gnu/cris-opc.c similarity index 100% rename from libr/asm/arch/cris/gnu/cris-opc.c rename to librz/asm/arch/cris/gnu/cris-opc.c diff --git a/libr/asm/arch/dalvik/opcode.h b/librz/asm/arch/dalvik/opcode.h similarity index 100% rename from libr/asm/arch/dalvik/opcode.h rename to librz/asm/arch/dalvik/opcode.h diff --git a/libr/asm/arch/dcpu16/Makefile b/librz/asm/arch/dcpu16/Makefile similarity index 100% rename from libr/asm/arch/dcpu16/Makefile rename to librz/asm/arch/dcpu16/Makefile diff --git a/libr/asm/arch/dcpu16/asm.c b/librz/asm/arch/dcpu16/asm.c similarity index 100% rename from libr/asm/arch/dcpu16/asm.c rename to librz/asm/arch/dcpu16/asm.c diff --git a/libr/asm/arch/dcpu16/dcpu16.h b/librz/asm/arch/dcpu16/dcpu16.h similarity index 100% rename from libr/asm/arch/dcpu16/dcpu16.h rename to librz/asm/arch/dcpu16/dcpu16.h diff --git a/libr/asm/arch/dcpu16/dis.c b/librz/asm/arch/dcpu16/dis.c similarity index 100% rename from libr/asm/arch/dcpu16/dis.c rename to librz/asm/arch/dcpu16/dis.c diff --git a/libr/asm/arch/dcpu16/main.c b/librz/asm/arch/dcpu16/main.c similarity index 100% rename from libr/asm/arch/dcpu16/main.c rename to librz/asm/arch/dcpu16/main.c diff --git a/libr/asm/arch/ebc/Makefile b/librz/asm/arch/ebc/Makefile similarity index 100% rename from libr/asm/arch/ebc/Makefile rename to librz/asm/arch/ebc/Makefile diff --git a/libr/asm/arch/ebc/ebc_disas.c b/librz/asm/arch/ebc/ebc_disas.c similarity index 99% rename from libr/asm/arch/ebc/ebc_disas.c rename to librz/asm/arch/ebc/ebc_disas.c index 15388bf52d..1435743347 100644 --- a/libr/asm/arch/ebc/ebc_disas.c +++ b/librz/asm/arch/ebc/ebc_disas.c @@ -1,7 +1,7 @@ /* radare - LGPL - 2013-2015 - Fedor Sakharov */ #include "ebc_disas.h" -#include +#include #define CHK_SNPRINTF(dst, sz, fmt, ...) do { \ int len_chk_snprintf_ = snprintf (dst, sz, fmt, __VA_ARGS__); \ diff --git a/libr/asm/arch/ebc/ebc_disas.h b/librz/asm/arch/ebc/ebc_disas.h similarity index 100% rename from libr/asm/arch/ebc/ebc_disas.h rename to librz/asm/arch/ebc/ebc_disas.h diff --git a/libr/asm/arch/gb/gb_op_table.h b/librz/asm/arch/gb/gb_op_table.h similarity index 100% rename from libr/asm/arch/gb/gb_op_table.h rename to librz/asm/arch/gb/gb_op_table.h diff --git a/libr/asm/arch/gb/gbasm.c b/librz/asm/arch/gb/gbasm.c similarity index 84% rename from libr/asm/arch/gb/gbasm.c rename to librz/asm/arch/gb/gbasm.c index 1c921488bd..b07f881370 100644 --- a/libr/asm/arch/gb/gbasm.c +++ b/librz/asm/arch/gb/gbasm.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2012-2020 - condret, pancake */ -#include -#include -#include +#include +#include +#include #include static void str_op(char *c) { @@ -27,9 +27,9 @@ static bool gb_parse_cb1 (ut8 *buf, const int minlen, char *buf_asm, ut8 base) { buf[0] = base; char *ptr_asm = buf_asm + minlen - 1; j = strlen (ptr_asm); - r_str_replace_in (ptr_asm, (ut32)j, "[ ", "[", true); - r_str_replace_in (ptr_asm, (ut32)j, " ]", "]", true); - r_str_do_until_token (str_op, buf_asm, ' '); + rz_str_replace_in (ptr_asm, (ut32)j, "[ ", "[", true); + rz_str_replace_in (ptr_asm, (ut32)j, " ]", "]", true); + rz_str_do_until_token (str_op, buf_asm, ' '); i = gb_reg_idx (buf_asm[minlen - 1]); if (i != (-1)) { buf[0] |= (ut8)i; @@ -49,9 +49,9 @@ static bool gb_parse_cb2 (ut8 *buf, const int minlen, char *buf_asm, ut8 base) { if ((i = strlen (buf_asm)) < minlen) { return false; } - r_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); - r_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); - r_str_replace_in (buf_asm, (ut32)i, ", ", ",", true); + rz_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); + rz_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); + rz_str_replace_in (buf_asm, (ut32)i, ", ", ",", true); p = strchr (buf_asm, (int)' '); if (!p) { return false; @@ -65,7 +65,7 @@ static bool gb_parse_cb2 (ut8 *buf, const int minlen, char *buf_asm, ut8 base) { q[0] = ','; return false; } - num = r_num_get (NULL, &p[1]); + num = rz_num_get (NULL, &p[1]); q[0] = ','; if (num > 7) { return false; @@ -95,9 +95,9 @@ static int gb_parse_arith1 (ut8 *buf, const int minlen, char *buf_asm, ut8 base, buf[0] = base; char *ptr_asm = buf_asm + minlen - 1; i = strlen (ptr_asm); - r_str_replace_in (ptr_asm, (ut32)i, "[ ", "[", true); - r_str_replace_in (ptr_asm, (ut32)i, " ]", "]", true); - r_str_do_until_token (str_op, buf_asm, ' '); + rz_str_replace_in (ptr_asm, (ut32)i, "[ ", "[", true); + rz_str_replace_in (ptr_asm, (ut32)i, " ]", "]", true); + rz_str_do_until_token (str_op, buf_asm, ' '); i = gb_reg_idx (buf_asm[minlen - 1]); if (i != -1) { buf[0] |= (ut8)i; @@ -105,7 +105,7 @@ static int gb_parse_arith1 (ut8 *buf, const int minlen, char *buf_asm, ut8 base, buf[0] |= 6; } else { buf[0] = alt; - num = r_num_get (NULL, buf_asm + minlen - 1); + num = rz_num_get (NULL, buf_asm + minlen - 1); buf[1] = (ut8)(num & 0xff); return 2; } @@ -114,11 +114,11 @@ static int gb_parse_arith1 (ut8 *buf, const int minlen, char *buf_asm, ut8 base, static bool gb_parse_ld1 (ut8 *buf, const int minlen, char *buf_asm) { int i; - r_str_replace_in (buf_asm, strlen (buf_asm), ", ", ",", true); + rz_str_replace_in (buf_asm, strlen (buf_asm), ", ", ",", true); if ((i = strlen (buf_asm)) < minlen) { return false; } - r_str_do_until_token (str_op, buf_asm, '\0'); + rz_str_do_until_token (str_op, buf_asm, '\0'); if (buf_asm[4] == ',') { i = gb_reg_idx (buf_asm[3]); if (i == (-1)) { @@ -157,12 +157,12 @@ static bool gb_parse_ld2 (ut8 *buf, char *buf_asm) { return false; } buf[0] = 0x6 + (ut8)(i * 8); - num = r_num_get (NULL, buf_asm + 5); + num = rz_num_get (NULL, buf_asm + 5); buf[1] = (ut8)(num & 0xff); return true; } else if (!strncmp (buf_asm + 3, "[hl],", 5)) { buf[0] = 0x36; - num = r_num_get (NULL, buf_asm + 8); + num = rz_num_get (NULL, buf_asm + 8); buf[1] = (ut8)(num & 0xff); return true; } @@ -195,13 +195,13 @@ static bool gb_parse_ld3 (ut8 *buf, char *buf_asm) { return false; } - const ut64 num = r_num_get (NULL, buf_asm + 6); + const ut64 num = rz_num_get (NULL, buf_asm + 6); buf[1] = num & 0xff; buf[2] = (num & 0xff00) >> 8; return true; } -static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { +static int gbAsm(RzAsm *a, RzAsmOp *op, const char *buf) { int mn_len, j, len = 1; ut32 mn = 0; ut64 num; @@ -210,14 +210,14 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { return 0; } ut8 opbuf[4] = {0}; - r_strbuf_set (&op->buf_asm, buf); - char *buf_asm = r_strbuf_get (&op->buf_asm); + rz_strbuf_set (&op->buf_asm, buf); + char *buf_asm = rz_strbuf_get (&op->buf_asm); ut32 buf_len = strlen (buf); while (strstr (buf_asm, " ")) { - r_str_replace_in (buf_asm, buf_len, " ", " ", true); + rz_str_replace_in (buf_asm, buf_len, " ", " ", true); } - r_str_replace_in (buf_asm, buf_len, " ,", ",", true); - mn_len = r_str_do_until_token (str_op, buf_asm, ' '); + rz_str_replace_in (buf_asm, buf_len, " ,", ",", true); + mn_len = rz_str_do_until_token (str_op, buf_asm, ' '); if (mn_len < 2 || mn_len > 4) { return 0; } @@ -232,9 +232,9 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { if ((i = strlen (buf_asm)) < 5) { return op->size = 0; } - r_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); - r_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); - r_str_do_until_token (str_op, buf_asm + 4, '\0'); + rz_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); + rz_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); + rz_str_do_until_token (str_op, buf_asm + 4, '\0'); if (buf_asm[4] == 'b') { opbuf[0] = (buf_asm[5] == 'c')? 3: 4; } else if (buf_asm[4] == 'c') { @@ -261,9 +261,9 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { if ((i = strlen (buf_asm)) < 5) { return op->size = 0; } - r_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); - r_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); - r_str_do_until_token (str_op, &buf_asm[4], '\0'); + rz_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); + rz_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); + rz_str_do_until_token (str_op, &buf_asm[4], '\0'); switch (buf_asm[4]) { case 'b': opbuf[0] = (buf_asm[5] == 'c')? 0x0b: 0x05; @@ -319,7 +319,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { opbuf[0] = 0x2f; break; case 0x616464: //add - r_str_replace_in (buf_asm, strlen(buf_asm), ", ", ",", true); + rz_str_replace_in (buf_asm, strlen(buf_asm), ", ", ",", true); if (strlen(buf_asm) < 5) return op->size = 0; if (buf_asm[4] == 's' @@ -327,7 +327,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { && buf_asm[6] == ',' && buf_asm[7] != '\0') { opbuf[0] = 0xe8; - num = r_num_get (NULL, buf_asm + 7); + num = rz_num_get (NULL, buf_asm + 7); opbuf[1] = (ut8)(num & 0xff); len = 2; } else if (!strcmp (buf_asm, "hl,bc")) { @@ -376,7 +376,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { if (strlen (buf_asm) < 5) { opbuf[0] = 0xc9; } else if (strlen (buf_asm) < 6) { - // there is no way that there can be " " - we did r_str_replace_in + // there is no way that there can be " " - we did rz_str_replace_in str_op (buf_asm + 4); if (buf_asm[4] == 'z') { //ret Z opbuf[0] = 0xc8; @@ -411,8 +411,8 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { break; case 0x6c64: //ld i = strlen (buf_asm); - r_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); - r_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); + rz_str_replace_in (buf_asm, (ut32)i, "[ ", "[", true); + rz_str_replace_in (buf_asm, (ut32)i, " ]", "]", true); if (!gb_parse_ld1 (opbuf, 6, buf_asm)) { len++; if (!gb_parse_ld2 (opbuf, buf_asm)) { @@ -427,7 +427,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { if (strlen (buf_asm) < 5) { return op->size = 0; } - num = r_num_get (NULL, &buf_asm[4]); + num = rz_num_get (NULL, &buf_asm[4]); if ((num & 7) || ((num/8) > 7)) { return op->size = 0; } @@ -480,7 +480,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { if (buf_asm[3] == 'h' && buf_asm[4] == 'l') opbuf[0] = 0xe9; else { - num = r_num_get (NULL, &buf_asm[3]); + num = rz_num_get (NULL, &buf_asm[3]); len = 3; opbuf[0] = 0xc3; opbuf[1] = (ut8)(num & 0xff); @@ -508,11 +508,11 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { } else { return op->size = 0; } - r_str_replace_in (p, strlen(p), ", ", ",", true); + rz_str_replace_in (p, strlen(p), ", ", ",", true); if (!p[0] || !p[1]) { return op->size = 0; } - num = r_num_get (NULL, p + 1); + num = rz_num_get (NULL, p + 1); opbuf[1] = (ut8)(num & 0xff); opbuf[2] = (ut8)((num & 0xff00) >> 8); len = 3; @@ -525,7 +525,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { { char *p = strchr (buf_asm, (int)','); if (!p) { - num = r_num_get (NULL, &buf_asm[3]); + num = rz_num_get (NULL, &buf_asm[3]); len = 2; opbuf[0] = 0x18; opbuf[1] = (ut8)(num & 0xff); @@ -547,11 +547,11 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { } else { return op->size = 0; } - r_str_replace_in (p, strlen(p), ", ", ",", true); + rz_str_replace_in (p, strlen(p), ", ", ",", true); if (!p[1]) { return op->size = 0; } - num = r_num_get (NULL, p + 1); + num = rz_num_get (NULL, p + 1); opbuf[1] = (ut8)(num & 0xff); len = 2; } @@ -564,7 +564,7 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { { char *p = strchr (buf_asm, (int)','); if (!p) { - num = r_num_get (NULL, buf_asm + 4); + num = rz_num_get (NULL, buf_asm + 4); len = 3; opbuf[0] = 0xcd; opbuf[1] = (ut8)(num & 0xff); @@ -591,11 +591,11 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { } else { return op->size = 0; } - r_str_replace_in (p, strlen(p), ", ", ",", true); + rz_str_replace_in (p, strlen(p), ", ", ",", true); if (!*p || !p[1]) { return op->size = 0; } - num = r_num_get (NULL, p + 1); + num = rz_num_get (NULL, p + 1); opbuf[1] = (ut8)(num & 0xff); opbuf[2] = (ut8)((num & 0xff00) >> 8); len = 3; @@ -650,6 +650,6 @@ static int gbAsm(RAsm *a, RAsmOp *op, const char *buf) { len = 0; break; } - memcpy(r_strbuf_get(&op->buf), opbuf, sizeof(ut8) * len); + memcpy(rz_strbuf_get(&op->buf), opbuf, sizeof(ut8) * len); return op->size = len; } diff --git a/libr/asm/arch/gb/gbdis.c b/librz/asm/arch/gb/gbdis.c similarity index 70% rename from libr/asm/arch/gb/gbdis.c rename to librz/asm/arch/gb/gbdis.c index aa6caa4076..de543f0612 100644 --- a/libr/asm/arch/gb/gbdis.c +++ b/librz/asm/arch/gb/gbdis.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2013-2018 - condret, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include "gb_op_table.h" @@ -26,144 +26,144 @@ static int gbOpLength(int gboptype){ static void gb_hardware_register_name (char *reg, ut8 offset) { switch (offset) { case 0x00: // Joy pad info - r_str_cpy (reg, "rP1") + rz_str_cpy (reg, "rP1") break; case 0x01: // Serial Transfer Data - r_str_cpy (reg, "rSB") + rz_str_cpy (reg, "rSB") break; case 0x02: // Serial I/O Control - r_str_cpy (reg, "rSC") + rz_str_cpy (reg, "rSC") break; case 0x04: // Divider register - r_str_cpy (reg, "rDIV") + rz_str_cpy (reg, "rDIV") break; case 0x05: // Timer Counter - r_str_cpy (reg, "rTIMA") + rz_str_cpy (reg, "rTIMA") break; case 0x06: // Timer modulo - r_str_cpy (reg, "rTMA") + rz_str_cpy (reg, "rTMA") break; case 0x07: // Timer control - r_str_cpy (reg, "rTAC") + rz_str_cpy (reg, "rTAC") break; case 0x0f: // Interrupt Flag - r_str_cpy (reg, "rIF") + rz_str_cpy (reg, "rIF") break; // Audio Channel #1 case 0x10: // Sweep Register - r_str_cpy (reg, "rAUD1SWEEP") + rz_str_cpy (reg, "rAUD1SWEEP") break; case 0x11: // Sound length/Wave pattern duty - r_str_cpy (reg, "rAUD1LEN") + rz_str_cpy (reg, "rAUD1LEN") break; case 0x12: // Envelope - r_str_cpy (reg, "rAUD1ENV") + rz_str_cpy (reg, "rAUD1ENV") break; case 0x13: // Frequency low - r_str_cpy (reg, "rAUD1LOW") + rz_str_cpy (reg, "rAUD1LOW") break; case 0x14: // Frequency high - r_str_cpy (reg, "rAUD1HIGH") + rz_str_cpy (reg, "rAUD1HIGH") break; // Audio Channel #2 case 0x16: // Sound length/Wave pattern duty - r_str_cpy (reg, "rAUD2LEN") + rz_str_cpy (reg, "rAUD2LEN") break; case 0x17: // Envelope - r_str_cpy (reg, "rAUD2ENV") + rz_str_cpy (reg, "rAUD2ENV") break; case 0x18: // Frequency low - r_str_cpy (reg, "rAUD2LOW") + rz_str_cpy (reg, "rAUD2LOW") break; case 0x19: // Frequency high - r_str_cpy (reg, "rAUD2HIGH") + rz_str_cpy (reg, "rAUD2HIGH") break; // Sound Channel #3 case 0x1a: // Sound on/off - r_str_cpy (reg, "rAUD3ENA") + rz_str_cpy (reg, "rAUD3ENA") break; case 0x1b: // Sound length - r_str_cpy (reg, "rAUD3LEN") + rz_str_cpy (reg, "rAUD3LEN") break; case 0x1c: // Select output level - r_str_cpy (reg, "rAUD3LEVEL") + rz_str_cpy (reg, "rAUD3LEVEL") break; case 0x1d: // Frequency low - r_str_cpy (reg, "rAUD3LOW") + rz_str_cpy (reg, "rAUD3LOW") break; case 0x1e: // Frequency high - r_str_cpy (reg, "rAUD3HIGH") + rz_str_cpy (reg, "rAUD3HIGH") break; // Sound Channel #4 case 0x20: // Sound length - r_str_cpy (reg, "rAUD4LEN") + rz_str_cpy (reg, "rAUD4LEN") break; case 0x21: // Envelope - r_str_cpy (reg, "rAUD4ENV") + rz_str_cpy (reg, "rAUD4ENV") break; case 0x22: // Polynomial counter - r_str_cpy (reg, "rAUD4POLY") + rz_str_cpy (reg, "rAUD4POLY") break; // Sound (general) case 0x23: - r_str_cpy (reg, "rAUD4GO") + rz_str_cpy (reg, "rAUD4GO") break; case 0x24: // Channel control / ON-OFF / Volume - r_str_cpy (reg, "rAUDVOL") + rz_str_cpy (reg, "rAUDVOL") break; case 0x25: // Selection of Sound output terminal - r_str_cpy (reg, "rAUDTERM") + rz_str_cpy (reg, "rAUDTERM") break; case 0x26: // Sound on/off - r_str_cpy (reg, "rAUDENA") + rz_str_cpy (reg, "rAUDENA") break; case 0x76: // Sound Channel 1&2 PCM amplitude - r_str_cpy (reg, "rPCM12") + rz_str_cpy (reg, "rPCM12") break; case 0x77: // Sound Channel 3&4 PCM amplitude - r_str_cpy (reg, "rPCM34") + rz_str_cpy (reg, "rPCM34") break; case 0x40: // LCD Control - r_str_cpy (reg, "rLCDC") + rz_str_cpy (reg, "rLCDC") break; case 0x41: // LCD Status - r_str_cpy (reg, "rSTAT") + rz_str_cpy (reg, "rSTAT") break; case 0x42: // Scroll Y - r_str_cpy (reg, "rSCY") + rz_str_cpy (reg, "rSCY") break; case 0x43: // Scroll X - r_str_cpy (reg, "rSCX") + rz_str_cpy (reg, "rSCX") break; case 0x44: // Y-Coordinate - r_str_cpy (reg, "rLY") + rz_str_cpy (reg, "rLY") break; case 0x45: // Y-Coordinate Compare - r_str_cpy (reg, "rLYC") + rz_str_cpy (reg, "rLYC") break; case 0x46: // Transfer and Start Address - r_str_cpy (reg, "rDMA") + rz_str_cpy (reg, "rDMA") break; case 0x47: // BG Palette Data - r_str_cpy (reg, "rBGP") + rz_str_cpy (reg, "rBGP") break; case 0x48: // Object Palette 0 Data - r_str_cpy (reg, "rOBP0") + rz_str_cpy (reg, "rOBP0") break; case 0x49: // Object Palette 1 Data - r_str_cpy (reg, "rOBP1") + rz_str_cpy (reg, "rOBP1") break; case 0x4a: // Window Y Position - r_str_cpy (reg, "rWY") + rz_str_cpy (reg, "rWY") break; case 0x4b: // Window X Position - r_str_cpy (reg, "rWX") + rz_str_cpy (reg, "rWX") break; case 0x4d: // Select CPU Speed - r_str_cpy (reg, "rKEY1") + rz_str_cpy (reg, "rKEY1") break; case 0x4f: // Select Video RAM Bank - r_str_cpy (reg, "rVBK") + rz_str_cpy (reg, "rVBK") break; case 0x51: // Horizontal Blanking, General Purpose DMA case 0x52: // Horizontal Blanking, General Purpose DMA @@ -173,25 +173,25 @@ static void gb_hardware_register_name (char *reg, ut8 offset) { sprintf (reg, "rHDMA%d", offset - 0x50); break; case 0x56: // Infrared Communications Port - r_str_cpy (reg, "rRP") + rz_str_cpy (reg, "rRP") break; case 0x68: // Background Color Palette Specification - r_str_cpy (reg, "rBCPS") + rz_str_cpy (reg, "rBCPS") break; case 0x69: // Background Color Palette Data - r_str_cpy (reg, "rBCPD") + rz_str_cpy (reg, "rBCPD") break; case 0x6a: // Object Color Palette Specification - r_str_cpy (reg, "rOCPS") + rz_str_cpy (reg, "rOCPS") break; case 0x6b: // Object Color Palette Data - r_str_cpy (reg, "rOCPD") + rz_str_cpy (reg, "rOCPD") break; case 0x70: // Select Main RAM Bank - r_str_cpy (reg, "rSVBK") + rz_str_cpy (reg, "rSVBK") break; case 0xff: // Interrupt Enable Flag - r_str_cpy (reg, "rIE") + rz_str_cpy (reg, "rIE") break; default: // If unknown, return the original address @@ -201,7 +201,7 @@ static void gb_hardware_register_name (char *reg, ut8 offset) { } #ifndef GB_DIS_LEN_ONLY -static int gbDisass(RAsmOp *op, const ut8 *buf, int len){ +static int gbDisass(RzAsmOp *op, const ut8 *buf, int len){ int foo = gbOpLength (gb_op[buf[0]].type); if (len < foo) { return 0; @@ -227,7 +227,7 @@ static int gbDisass(RAsmOp *op, const ut8 *buf, int len){ buf_asm = sdb_fmt (gb_op[buf[0]].name, reg); break; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); return foo; } #endif diff --git a/libr/asm/arch/h8300/h8300_disas.c b/librz/asm/arch/h8300/h8300_disas.c similarity index 97% rename from libr/asm/arch/h8300/h8300_disas.c rename to librz/asm/arch/h8300/h8300_disas.c index 626f98cd1d..4d20d47b99 100644 --- a/libr/asm/arch/h8300/h8300_disas.c +++ b/librz/asm/arch/h8300/h8300_disas.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "h8300_disas.h" static const char *commands_4bit[] = { @@ -143,7 +143,7 @@ static int decode_opcode(const ut8 *bytes, struct h8300_cmd *cmd) { ut16 ext_opcode; - ext_opcode = (r_read_be16 (bytes)) >> 7; + ext_opcode = (rz_read_be16 (bytes)) >> 7; switch (ext_opcode) { case H8300_BOR: @@ -331,7 +331,7 @@ static int decode_imm162r16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - imm = r_read_at_be16 (bytes, 2); + imm = rz_read_at_be16 (bytes, 2); snprintf(cmd->operands, H8300_INSTR_MAXLEN, "#0x%x:16,r%u", imm, bytes[1] & 0x7); @@ -348,7 +348,7 @@ static int decode_disp162r16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - disp = r_read_at_be16 (bytes, 2); + disp = rz_read_at_be16 (bytes, 2); if (bytes[1] & 0x80) { snprintf(cmd->operands, H8300_INSTR_MAXLEN, @@ -492,7 +492,7 @@ static int decode_r2r8(const ut8 *bytes, struct h8300_cmd *cmd) } /* [opcode] [0| rd | 0000] [opcode] [ rn | 0 ] */ -static int decode_r2ind16(const ut8 *bytes, struct h8300_cmd *cmd) +static int decode_rzind16(const ut8 *bytes, struct h8300_cmd *cmd) { int ret = 4; @@ -509,7 +509,7 @@ static int decode_r2ind16(const ut8 *bytes, struct h8300_cmd *cmd) } /* [opcode] [ abs ] [opcode] [ rn | 0000 ] */ -static int decode_r2abs8(const ut8 *bytes, struct h8300_cmd *cmd) +static int decode_rzabs8(const ut8 *bytes, struct h8300_cmd *cmd) { int ret = 4; @@ -595,7 +595,7 @@ int decode_jmp_abs16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - abs = r_read_at_be16 (bytes, 2); + abs = rz_read_at_be16 (bytes, 2); snprintf(cmd->operands, H8300_INSTR_MAXLEN, "@0x%x:16", abs); return ret; @@ -641,7 +641,7 @@ static int decode_abs162r16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - abs = r_read_at_be16 (bytes, 2); + abs = rz_read_at_be16 (bytes, 2); if (bytes[1] & 0x80) { snprintf(cmd->operands, H8300_INSTR_MAXLEN, "r%u,@0x%x:16", bytes[1] & 0x7, abs); @@ -685,7 +685,7 @@ static int decode_r82dispr16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - disp = r_read_at_be16 (bytes, 2); + disp = rz_read_at_be16 (bytes, 2); if (bytes[1] & 0x80) { snprintf(cmd->operands, H8300_INSTR_MAXLEN, "r%u%c,@(0x%x:16,r%u)", @@ -738,7 +738,7 @@ static int decode_r82abs16(const ut8 *bytes, struct h8300_cmd *cmd) return -1; } - abs = r_read_at_be16 (bytes, 2); + abs = rz_read_at_be16 (bytes, 2); if (bytes[1] & 0x80) { snprintf(cmd->operands, H8300_INSTR_MAXLEN, "r%u%c,@0x%x:16", @@ -781,7 +781,7 @@ static int decode_abs2r_short(const ut8 *bytes, struct h8300_cmd *cmd) return ret; } -static int decode_r2imm_short(const ut8 *bytes, struct h8300_cmd *cmd) +static int decode_rzimm_short(const ut8 *bytes, struct h8300_cmd *cmd) { int ret = 2; @@ -816,7 +816,7 @@ int h8300_decode_command(const ut8 *instr, struct h8300_cmd *cmd) switch (instr[0] >> 4) { case H8300_MOV_4BIT_3: - ret = decode_r2imm_short(instr, cmd); + ret = decode_rzimm_short(instr, cmd); break; case H8300_MOV_4BIT_2: ret = decode_abs2r_short(instr, cmd); @@ -883,7 +883,7 @@ int h8300_decode_command(const ut8 *instr, struct h8300_cmd *cmd) case 0x60: case 0x61: case 0x62: - ret = decode_r2ind16(instr, cmd); + ret = decode_rzind16(instr, cmd); break; case 0x70: case 0x71: @@ -901,7 +901,7 @@ int h8300_decode_command(const ut8 *instr, struct h8300_cmd *cmd) case 0x60: case 0x61: case 0x62: - ret = decode_r2abs8(instr, cmd); + ret = decode_rzabs8(instr, cmd); break; case 0x67: case 0x70: diff --git a/libr/asm/arch/h8300/h8300_disas.h b/librz/asm/arch/h8300/h8300_disas.h similarity index 100% rename from libr/asm/arch/h8300/h8300_disas.h rename to librz/asm/arch/h8300/h8300_disas.h diff --git a/libr/asm/arch/hexagon/hexagon.c b/librz/asm/arch/hexagon/hexagon.c similarity index 98% rename from libr/asm/arch/hexagon/hexagon.c rename to librz/asm/arch/hexagon/hexagon.c index 40610d5fcd..d3582d6927 100644 --- a/libr/asm/arch/hexagon/hexagon.c +++ b/librz/asm/arch/hexagon/hexagon.c @@ -1,9 +1,9 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "hexagon.h" // TODO: Handle also control reg pairs diff --git a/libr/asm/arch/hexagon/hexagon.h b/librz/asm/arch/hexagon/hexagon.h similarity index 100% rename from libr/asm/arch/hexagon/hexagon.h rename to librz/asm/arch/hexagon/hexagon.h diff --git a/libr/asm/arch/hexagon/hexagon_disas.c b/librz/asm/arch/hexagon/hexagon_disas.c similarity index 99% rename from libr/asm/arch/hexagon/hexagon_disas.c rename to librz/asm/arch/hexagon/hexagon_disas.c index 0533c752c6..9174d5a212 100644 --- a/libr/asm/arch/hexagon/hexagon_disas.c +++ b/librz/asm/arch/hexagon/hexagon_disas.c @@ -1,8 +1,8 @@ #include #include -#include -#include -#include +#include +#include +#include #include "hexagon.h" #include "hexagon_insn.h" diff --git a/libr/asm/arch/hexagon/hexagon_insn.h b/librz/asm/arch/hexagon/hexagon_insn.h similarity index 100% rename from libr/asm/arch/hexagon/hexagon_insn.h rename to librz/asm/arch/hexagon/hexagon_insn.h diff --git a/libr/asm/arch/hppa/gnu/hppa-dis.c b/librz/asm/arch/hppa/gnu/hppa-dis.c similarity index 99% rename from libr/asm/arch/hppa/gnu/hppa-dis.c rename to librz/asm/arch/hppa/gnu/hppa-dis.c index 73667fc3f4..e629b47a9c 100644 --- a/libr/asm/arch/hppa/gnu/hppa-dis.c +++ b/librz/asm/arch/hppa/gnu/hppa-dis.c @@ -26,7 +26,7 @@ #include "libhppa.h" #include "opcode/hppa.h" #include -#include +#include /* Integer register names, indexed by the numbers which appear in the opcodes. */ diff --git a/libr/asm/arch/i4004/i4004dis.c b/librz/asm/arch/i4004/i4004dis.c similarity index 93% rename from libr/asm/arch/i4004/i4004dis.c rename to librz/asm/arch/i4004/i4004dis.c index adac427b42..53dc6e3b96 100644 --- a/libr/asm/arch/i4004/i4004dis.c +++ b/librz/asm/arch/i4004/i4004dis.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2014-2018 - condret, pancake */ -#include -#include +#include +#include #include #include @@ -56,7 +56,7 @@ static int i4004_get_ins_len (ut8 hex) { return ret; } -static int i4004dis (RAsmOp *op, const ut8 *buf, int len) { +static int i4004dis (RzAsmOp *op, const ut8 *buf, int len) { int rlen = i4004_get_ins_len (*buf); ut8 high = (*buf & 0xf0) >> 4; ut8 low = (*buf & 0xf); @@ -94,6 +94,6 @@ static int i4004dis (RAsmOp *op, const ut8 *buf, int len) { case 14: buf_asm = i4004_e[low]; break; case 15: buf_asm = i4004_f[low]; break; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); return op->size = rlen; } diff --git a/libr/asm/arch/i8080/i8080dis.c b/librz/asm/arch/i8080/i8080dis.c similarity index 100% rename from libr/asm/arch/i8080/i8080dis.c rename to librz/asm/arch/i8080/i8080dis.c diff --git a/libr/asm/arch/i8080/i8080dis.h b/librz/asm/arch/i8080/i8080dis.h similarity index 100% rename from libr/asm/arch/i8080/i8080dis.h rename to librz/asm/arch/i8080/i8080dis.h diff --git a/libr/asm/arch/include/ansidecl.h b/librz/asm/arch/include/ansidecl.h similarity index 100% rename from libr/asm/arch/include/ansidecl.h rename to librz/asm/arch/include/ansidecl.h diff --git a/libr/asm/arch/include/bfdlink.h b/librz/asm/arch/include/bfdlink.h similarity index 100% rename from libr/asm/arch/include/bfdlink.h rename to librz/asm/arch/include/bfdlink.h diff --git a/libr/asm/arch/include/disas-asm.h b/librz/asm/arch/include/disas-asm.h similarity index 99% rename from libr/asm/arch/include/disas-asm.h rename to librz/asm/arch/include/disas-asm.h index 1e20f5d2ca..c7ceb46ddb 100644 --- a/libr/asm/arch/include/disas-asm.h +++ b/librz/asm/arch/include/disas-asm.h @@ -439,7 +439,7 @@ static int generic_fprintf_func(void *stream, const char *format, ...) { \ return 0; \ } \ va_start (ap, format); \ - ret = r_strbuf_vappendf (buf_global, format, ap); \ + ret = rz_strbuf_vappendf (buf_global, format, ap); \ va_end (ap); \ return ret; \ } @@ -449,7 +449,7 @@ static void generic_print_address_func(bfd_vma address, struct disassemble_info if (!buf_global) { \ return; \ } \ - r_strbuf_appendf (buf_global, "0x%08"PFMT64x, (ut64)address); \ + rz_strbuf_appendf (buf_global, "0x%08"PFMT64x, (ut64)address); \ } diff --git a/libr/asm/arch/include/elf-bfd.h b/librz/asm/arch/include/elf-bfd.h similarity index 99% rename from libr/asm/arch/include/elf-bfd.h rename to librz/asm/arch/include/elf-bfd.h index 6e5807e312..48972a8225 100644 --- a/libr/asm/arch/include/elf-bfd.h +++ b/librz/asm/arch/include/elf-bfd.h @@ -507,7 +507,7 @@ struct elf_reloc_cookie size_t locsymcount; size_t extsymoff; struct elf_link_hash_entry **sym_hashes; - int r_sym_shift; + int rz_sym_shift; bfd_boolean bad_symtab; }; @@ -708,7 +708,7 @@ struct elf_backend_data required. This generally means allocating space in the global offset table, and perhaps allocating space for a reloc. The relocs are always passed as Rela structures; if the section - actually uses Rel structures, the r_addend field will always be + actually uses Rel structures, the rz_addend field will always be zero. */ bfd_boolean (*check_relocs) (bfd *abfd, struct bfd_link_info *info, asection *o, @@ -772,7 +772,7 @@ struct elf_backend_data to handle the relocations for a section. The relocs are always passed as Rela structures; if the section - actually uses Rel structures, the r_addend field will always be + actually uses Rel structures, the rz_addend field will always be zero. This function is responsible for adjust the section contents as @@ -1198,7 +1198,7 @@ struct bfd_elf_section_data struct elf_link_hash_entry **rel_hashes; /* A pointer to the swapped relocs. If the section uses REL relocs, - rather than RELA, all the r_addend fields will be zero. This + rather than RELA, all the rz_addend fields will be zero. This pointer may be NULL. It is used by the backend linker. */ Elf_Internal_Rela *relocs; @@ -2065,7 +2065,7 @@ extern bfd_boolean _sh_elf_set_mach_from_flags /* This macro is to avoid lots of duplicated code in the body of xxx_relocate_section() in the various elfxx-xxxx.c files. */ #define RELOC_FOR_GLOBAL_SYMBOL(info, input_bfd, input_section, rel, \ - r_symndx, symtab_hdr, sym_hashes, \ + rz_symndx, symtab_hdr, sym_hashes, \ h, sec, relocation, \ unresolved_reloc, warned) \ do \ @@ -2075,7 +2075,7 @@ extern bfd_boolean _sh_elf_set_mach_from_flags if (!sym_hashes) \ return FALSE; \ \ - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; \ + h = sym_hashes[rz_symndx - symtab_hdr->sh_info]; \ \ while (h->root.type == bfd_link_hash_indirect \ || h->root.type == bfd_link_hash_warning) \ @@ -2114,7 +2114,7 @@ extern bfd_boolean _sh_elf_set_mach_from_flags h->root.root.string, \ input_bfd, \ input_section, \ - rel->r_offset, err)) \ + rel->rz_offset, err)) \ return FALSE; \ warned = TRUE; \ } \ diff --git a/libr/asm/arch/include/elf/common.h b/librz/asm/arch/include/elf/common.h similarity index 100% rename from libr/asm/arch/include/elf/common.h rename to librz/asm/arch/include/elf/common.h diff --git a/libr/asm/arch/include/elf/external.h b/librz/asm/arch/include/elf/external.h similarity index 93% rename from libr/asm/arch/include/elf/external.h rename to librz/asm/arch/include/elf/external.h index 21450f0059..7bd13bbb30 100644 --- a/libr/asm/arch/include/elf/external.h +++ b/librz/asm/arch/include/elf/external.h @@ -158,25 +158,25 @@ typedef struct { /* Relocation Entries */ typedef struct { - unsigned char r_offset[4]; /* Location at which to apply the action */ - unsigned char r_info[4]; /* index and type of relocation */ + unsigned char rz_offset[4]; /* Location at which to apply the action */ + unsigned char rz_info[4]; /* index and type of relocation */ } Elf32_External_Rel; typedef struct { - unsigned char r_offset[4]; /* Location at which to apply the action */ - unsigned char r_info[4]; /* index and type of relocation */ - unsigned char r_addend[4]; /* Constant addend used to compute value */ + unsigned char rz_offset[4]; /* Location at which to apply the action */ + unsigned char rz_info[4]; /* index and type of relocation */ + unsigned char rz_addend[4]; /* Constant addend used to compute value */ } Elf32_External_Rela; typedef struct { - unsigned char r_offset[8]; /* Location at which to apply the action */ - unsigned char r_info[8]; /* index and type of relocation */ + unsigned char rz_offset[8]; /* Location at which to apply the action */ + unsigned char rz_info[8]; /* index and type of relocation */ } Elf64_External_Rel; typedef struct { - unsigned char r_offset[8]; /* Location at which to apply the action */ - unsigned char r_info[8]; /* index and type of relocation */ - unsigned char r_addend[8]; /* Constant addend used to compute value */ + unsigned char rz_offset[8]; /* Location at which to apply the action */ + unsigned char rz_info[8]; /* index and type of relocation */ + unsigned char rz_addend[8]; /* Constant addend used to compute value */ } Elf64_External_Rela; /* dynamic section structure */ diff --git a/libr/asm/arch/include/elf/internal.h b/librz/asm/arch/include/elf/internal.h similarity index 98% rename from libr/asm/arch/include/elf/internal.h rename to librz/asm/arch/include/elf/internal.h index 152171136c..b59fda56ac 100644 --- a/libr/asm/arch/include/elf/internal.h +++ b/librz/asm/arch/include/elf/internal.h @@ -119,9 +119,9 @@ typedef struct elf_internal_note { /* Relocation Entries */ typedef struct elf_internal_rela { - bfd_vma r_offset; /* Location at which to apply the action */ - bfd_vma r_info; /* Index and Type of relocation */ - bfd_vma r_addend; /* Constant addend used to compute value */ + bfd_vma rz_offset; /* Location at which to apply the action */ + bfd_vma rz_info; /* Index and Type of relocation */ + bfd_vma rz_addend; /* Constant addend used to compute value */ } Elf_Internal_Rela; /* dynamic section structure */ diff --git a/libr/asm/arch/include/elf/mips.h b/librz/asm/arch/include/elf/mips.h similarity index 97% rename from libr/asm/arch/include/elf/mips.h rename to librz/asm/arch/include/elf/mips.h index 257ea21282..662ff7a0e7 100644 --- a/libr/asm/arch/include/elf/mips.h +++ b/librz/asm/arch/include/elf/mips.h @@ -733,8 +733,8 @@ extern void bfd_mips_elf32_swap_reginfo_out /* The 64-bit MIPS ELF ABI uses an unusual reloc format. Each relocation entry specifies up to three actual relocations, all at the same address. The first relocation which required a symbol - uses the symbol in the r_sym field. The second relocation which - requires a symbol uses the symbol in the r_ssym field. If all + uses the symbol in the rz_sym field. The second relocation which + requires a symbol uses the symbol in the rz_ssym field. If all three relocations require a symbol, the third one uses a zero value. */ @@ -743,33 +743,33 @@ extern void bfd_mips_elf32_swap_reginfo_out typedef struct { /* Address of relocation. */ - unsigned char r_offset[8]; + unsigned char rz_offset[8]; /* Symbol index. */ - unsigned char r_sym[4]; + unsigned char rz_sym[4]; /* Special symbol. */ - unsigned char r_ssym[1]; + unsigned char rz_ssym[1]; /* Third relocation. */ - unsigned char r_type3[1]; + unsigned char rz_type3[1]; /* Second relocation. */ - unsigned char r_type2[1]; + unsigned char rz_type2[1]; /* First relocation. */ - unsigned char r_type[1]; + unsigned char rz_type[1]; } Elf64_Mips_External_Rel; typedef struct { /* Address of relocation. */ - bfd_vma r_offset; + bfd_vma rz_offset; /* Symbol index. */ - unsigned long r_sym; + unsigned long rz_sym; /* Special symbol. */ - unsigned char r_ssym; + unsigned char rz_ssym; /* Third relocation. */ - unsigned char r_type3; + unsigned char rz_type3; /* Second relocation. */ - unsigned char r_type2; + unsigned char rz_type2; /* First relocation. */ - unsigned char r_type; + unsigned char rz_type; } Elf64_Mips_Internal_Rel; /* An entry in a 64 bit SHT_RELA section. */ @@ -777,37 +777,37 @@ typedef struct typedef struct { /* Address of relocation. */ - unsigned char r_offset[8]; + unsigned char rz_offset[8]; /* Symbol index. */ - unsigned char r_sym[4]; + unsigned char rz_sym[4]; /* Special symbol. */ - unsigned char r_ssym[1]; + unsigned char rz_ssym[1]; /* Third relocation. */ - unsigned char r_type3[1]; + unsigned char rz_type3[1]; /* Second relocation. */ - unsigned char r_type2[1]; + unsigned char rz_type2[1]; /* First relocation. */ - unsigned char r_type[1]; + unsigned char rz_type[1]; /* Addend. */ - unsigned char r_addend[8]; + unsigned char rz_addend[8]; } Elf64_Mips_External_Rela; typedef struct { /* Address of relocation. */ - bfd_vma r_offset; + bfd_vma rz_offset; /* Symbol index. */ - unsigned long r_sym; + unsigned long rz_sym; /* Special symbol. */ - unsigned char r_ssym; + unsigned char rz_ssym; /* Third relocation. */ - unsigned char r_type3; + unsigned char rz_type3; /* Second relocation. */ - unsigned char r_type2; + unsigned char rz_type2; /* First relocation. */ - unsigned char r_type; + unsigned char rz_type; /* Addend. */ - bfd_signed_vma r_addend; + bfd_signed_vma rz_addend; } Elf64_Mips_Internal_Rela; /* MIPS ELF 64 relocation info access macros. */ @@ -816,7 +816,7 @@ typedef struct #define ELF64_MIPS_R_TYPE2(i) (((i) >> 8) & 0xff) #define ELF64_MIPS_R_TYPE(i) ((i) & 0xff) -/* Values found in the r_ssym field of a relocation entry. */ +/* Values found in the rz_ssym field of a relocation entry. */ /* No relocation. */ #define RSS_UNDEF 0 diff --git a/libr/asm/arch/include/elf/reloc-macros.h b/librz/asm/arch/include/elf/reloc-macros.h similarity index 100% rename from libr/asm/arch/include/elf/reloc-macros.h rename to librz/asm/arch/include/elf/reloc-macros.h diff --git a/libr/asm/arch/include/elf/xtensa.h b/librz/asm/arch/include/elf/xtensa.h similarity index 100% rename from libr/asm/arch/include/elf/xtensa.h rename to librz/asm/arch/include/elf/xtensa.h diff --git a/libr/asm/arch/include/libhppa.h b/librz/asm/arch/include/libhppa.h similarity index 98% rename from libr/asm/arch/include/libhppa.h rename to librz/asm/arch/include/libhppa.h index 80d6350074..cde8c095df 100644 --- a/libr/asm/arch/include/libhppa.h +++ b/librz/asm/arch/include/libhppa.h @@ -296,12 +296,12 @@ re_assemble_22 (int as22) static inline bfd_signed_vma hppa_field_adjust (bfd_vma sym_val, bfd_signed_vma addend, - enum hppa_reloc_field_selector_type_alt r_field) + enum hppa_reloc_field_selector_type_alt rz_field) { bfd_signed_vma value; value = sym_val + addend; - switch (r_field) + switch (rz_field) { case e_fsel: /* F: No change. */ @@ -542,9 +542,9 @@ bfd_hppa_insn2fmt (bfd *abfd, int insn) bits to change. */ static inline int -hppa_rebuild_insn (int insn, int value, int r_format) +hppa_rebuild_insn (int insn, int value, int rz_format) { - switch (r_format) + switch (rz_format) { case 11: return (insn & ~ 0x7ff) | low_sign_unext (value, 11); diff --git a/libr/asm/arch/include/libiberty.h b/librz/asm/arch/include/libiberty.h similarity index 100% rename from libr/asm/arch/include/libiberty.h rename to librz/asm/arch/include/libiberty.h diff --git a/libr/asm/arch/include/mybfd.h b/librz/asm/arch/include/mybfd.h similarity index 100% rename from libr/asm/arch/include/mybfd.h rename to librz/asm/arch/include/mybfd.h diff --git a/libr/asm/arch/include/opcode/cris.h b/librz/asm/arch/include/opcode/cris.h similarity index 100% rename from libr/asm/arch/include/opcode/cris.h rename to librz/asm/arch/include/opcode/cris.h diff --git a/libr/asm/arch/include/opcode/hexagon.h b/librz/asm/arch/include/opcode/hexagon.h similarity index 100% rename from libr/asm/arch/include/opcode/hexagon.h rename to librz/asm/arch/include/opcode/hexagon.h diff --git a/libr/asm/arch/include/opcode/hppa.h b/librz/asm/arch/include/opcode/hppa.h similarity index 100% rename from libr/asm/arch/include/opcode/hppa.h rename to librz/asm/arch/include/opcode/hppa.h diff --git a/libr/asm/arch/include/opcode/lanai.h b/librz/asm/arch/include/opcode/lanai.h similarity index 100% rename from libr/asm/arch/include/opcode/lanai.h rename to librz/asm/arch/include/opcode/lanai.h diff --git a/libr/asm/arch/include/opcode/mips.h b/librz/asm/arch/include/opcode/mips.h similarity index 100% rename from libr/asm/arch/include/opcode/mips.h rename to librz/asm/arch/include/opcode/mips.h diff --git a/libr/asm/arch/include/opcode/nios2.h b/librz/asm/arch/include/opcode/nios2.h similarity index 100% rename from libr/asm/arch/include/opcode/nios2.h rename to librz/asm/arch/include/opcode/nios2.h diff --git a/libr/asm/arch/include/opcode/ppc.h b/librz/asm/arch/include/opcode/ppc.h similarity index 100% rename from libr/asm/arch/include/opcode/ppc.h rename to librz/asm/arch/include/opcode/ppc.h diff --git a/libr/asm/arch/include/opcode/sparc.h b/librz/asm/arch/include/opcode/sparc.h similarity index 100% rename from libr/asm/arch/include/opcode/sparc.h rename to librz/asm/arch/include/opcode/sparc.h diff --git a/libr/asm/arch/include/opcode/tricore.h b/librz/asm/arch/include/opcode/tricore.h similarity index 100% rename from libr/asm/arch/include/opcode/tricore.h rename to librz/asm/arch/include/opcode/tricore.h diff --git a/libr/asm/arch/include/opintl.h b/librz/asm/arch/include/opintl.h similarity index 100% rename from libr/asm/arch/include/opintl.h rename to librz/asm/arch/include/opintl.h diff --git a/libr/asm/arch/include/safe-ctype.h b/librz/asm/arch/include/safe-ctype.h similarity index 100% rename from libr/asm/arch/include/safe-ctype.h rename to librz/asm/arch/include/safe-ctype.h diff --git a/libr/asm/arch/include/symcat.h b/librz/asm/arch/include/symcat.h similarity index 100% rename from libr/asm/arch/include/symcat.h rename to librz/asm/arch/include/symcat.h diff --git a/libr/asm/arch/include/sysdep.h b/librz/asm/arch/include/sysdep.h similarity index 100% rename from libr/asm/arch/include/sysdep.h rename to librz/asm/arch/include/sysdep.h diff --git a/libr/asm/arch/include/wine-arm.h b/librz/asm/arch/include/wine-arm.h similarity index 100% rename from libr/asm/arch/include/wine-arm.h rename to librz/asm/arch/include/wine-arm.h diff --git a/libr/asm/arch/include/xtensa-isa-internal.h b/librz/asm/arch/include/xtensa-isa-internal.h similarity index 100% rename from libr/asm/arch/include/xtensa-isa-internal.h rename to librz/asm/arch/include/xtensa-isa-internal.h diff --git a/libr/asm/arch/include/xtensa-isa.h b/librz/asm/arch/include/xtensa-isa.h similarity index 99% rename from libr/asm/arch/include/xtensa-isa.h rename to librz/asm/arch/include/xtensa-isa.h index 39715af8e0..2a0ddea442 100644 --- a/libr/asm/arch/include/xtensa-isa.h +++ b/librz/asm/arch/include/xtensa-isa.h @@ -21,7 +21,7 @@ #ifndef XTENSA_LIBISA_H #define XTENSA_LIBISA_H -#include "r_types.h" +#include "rz_types.h" #ifdef __cplusplus extern "C" { diff --git a/libr/asm/arch/lanai/Makefile b/librz/asm/arch/lanai/Makefile similarity index 100% rename from libr/asm/arch/lanai/Makefile rename to librz/asm/arch/lanai/Makefile diff --git a/libr/asm/arch/lanai/gnu/lanai-dis.c b/librz/asm/arch/lanai/gnu/lanai-dis.c similarity index 100% rename from libr/asm/arch/lanai/gnu/lanai-dis.c rename to librz/asm/arch/lanai/gnu/lanai-dis.c diff --git a/libr/asm/arch/lanai/gnu/lanai-opc.c b/librz/asm/arch/lanai/gnu/lanai-opc.c similarity index 100% rename from libr/asm/arch/lanai/gnu/lanai-opc.c rename to librz/asm/arch/lanai/gnu/lanai-opc.c diff --git a/libr/asm/arch/lh5801/lh5801.c b/librz/asm/arch/lh5801/lh5801.c similarity index 99% rename from libr/asm/arch/lh5801/lh5801.c rename to librz/asm/arch/lh5801/lh5801.c index bb46a73a1b..17316c9706 100644 --- a/libr/asm/arch/lh5801/lh5801.c +++ b/librz/asm/arch/lh5801/lh5801.c @@ -14,7 +14,7 @@ #include "lh5801.h" #include #include -#include +#include #define ARRAY_LENGTH(a) (sizeof(a)/sizeof((a)[0])) diff --git a/libr/asm/arch/lh5801/lh5801.h b/librz/asm/arch/lh5801/lh5801.h similarity index 100% rename from libr/asm/arch/lh5801/lh5801.h rename to librz/asm/arch/lh5801/lh5801.h diff --git a/libr/asm/arch/lm32/lm32_isa.h b/librz/asm/arch/lm32/lm32_isa.h similarity index 71% rename from libr/asm/arch/lm32/lm32_isa.h rename to librz/asm/arch/lm32/lm32_isa.h index 76e9a6f051..6eccfaae33 100644 --- a/libr/asm/arch/lm32/lm32_isa.h +++ b/librz/asm/arch/lm32/lm32_isa.h @@ -1,22 +1,22 @@ -/* lm32 support for radare2 +/* lm32 support for rizin * 2-clause BSD * Copyright 2015 Felix Held */ #ifndef INCLUDE_LM32_ISA_H #define INCLUDE_LM32_ISA_H -#include +#include -#define RAsmLm32RegNameLength 8 -#define RAsmLm32OpNameLength 12 +#define RzAsmLm32RegNameLength 8 +#define RzAsmLm32OpNameLength 12 -typedef struct r_asm_lm32_csr_t { +typedef struct rz_asm_lm32_csr_t { ut8 number; - char name[RAsmLm32RegNameLength]; -} RAsmLm32Csr; + char name[RzAsmLm32RegNameLength]; +} RzAsmLm32Csr; -#define RAsmLm32CsrNumber 21 +#define RzAsmLm32CsrNumber 21 -static const RAsmLm32Csr RAsmLm32Csrs[RAsmLm32CsrNumber] = { +static const RzAsmLm32Csr RzAsmLm32Csrs[RzAsmLm32CsrNumber] = { {0x00, "IE"}, {0x01, "IM"}, {0x02, "IP"}, @@ -40,14 +40,14 @@ static const RAsmLm32Csr RAsmLm32Csrs[RAsmLm32CsrNumber] = { {0x1b, "WP3"}, }; -typedef struct r_asm_lm32_reg_t { +typedef struct rz_asm_lm32_reg_t { ut8 number; - char name[RAsmLm32RegNameLength]; -} RAsmLm32Reg; + char name[RzAsmLm32RegNameLength]; +} RzAsmLm32Reg; -#define RAsmLm32RegNumber 39 +#define RzAsmLm32RegNumber 39 -static const RAsmLm32Reg RAsmLm32Regs[RAsmLm32RegNumber] = { +static const RzAsmLm32Reg RzAsmLm32Regs[RzAsmLm32RegNumber] = { {0x00, "r0"}, {0x00, "zero"}, {0x01, "r1"}, @@ -89,7 +89,7 @@ static const RAsmLm32Reg RAsmLm32Regs[RAsmLm32RegNumber] = { {0x1f, "r31"}, }; -typedef enum r_asm_lm32_instr_type_t { +typedef enum rz_asm_lm32_instr_type_t { reserved, reg_imm16_signextend, reg_imm16_shift2_signextend, @@ -102,9 +102,9 @@ typedef enum r_asm_lm32_instr_type_t { reg_csr, //wcsr csr_reg, //rcsr imm26, -} RAsmLm32InstructionType; +} RzAsmLm32InstructionType; -enum r_asm_lm32_opcode_list_t { +enum rz_asm_lm32_opcode_list_t { lm32_op_srui = 0x00, lm32_op_nori = 0x01, lm32_op_muli = 0x02, @@ -171,14 +171,14 @@ enum r_asm_lm32_opcode_list_t { lm32_op_cmpne = 0x3f, }; -typedef struct r_asm_lm32_opcode { - RAsmLm32InstructionType type; - char name[RAsmLm32OpNameLength]; -} RAsmLm32Opcode; +typedef struct rz_asm_lm32_opcode { + RzAsmLm32InstructionType type; + char name[RzAsmLm32OpNameLength]; +} RzAsmLm32Opcode; -#define RAsmLm32OpcodeNumber 0x40 +#define RzAsmLm32OpcodeNumber 0x40 -static const RAsmLm32Opcode RAsmLm32OpcodeList[RAsmLm32OpcodeNumber] = { +static const RzAsmLm32Opcode RzAsmLm32OpcodeList[RzAsmLm32OpcodeNumber] = { {reg_imm5, "srui"}, //0x00 {reg_imm16_zeroextend, "nori"}, //0x01 {reg_imm16_signextend, "muli"}, //0x02 @@ -245,7 +245,7 @@ static const RAsmLm32Opcode RAsmLm32OpcodeList[RAsmLm32OpcodeNumber] = { {three_regs, "cmpne"}, //0x3f }; -typedef struct r_asm_lm32_instruction { +typedef struct rz_asm_lm32_instruction { //address of this instruction ut32 addr; //instruction dword @@ -254,24 +254,24 @@ typedef struct r_asm_lm32_instruction { //op code ut8 op; //op type and name - RAsmLm32Opcode op_decode; + RzAsmLm32Opcode op_decode; //dest is the destination register (the one right after most commands) ut8 dest_reg; - char dest_reg_str[RAsmLm32RegNameLength]; + char dest_reg_str[RzAsmLm32RegNameLength]; //src0 is the leftmost source register ut8 src0_reg; - char src0_reg_str[RAsmLm32RegNameLength]; + char src0_reg_str[RzAsmLm32RegNameLength]; //src1 is the second (rightmost) source register ut8 src1_reg; - char src1_reg_str[RAsmLm32RegNameLength]; + char src1_reg_str[RzAsmLm32RegNameLength]; //control and status register number ut8 csr; - char csr_reg_str[RAsmLm32RegNameLength]; + char csr_reg_str[RzAsmLm32RegNameLength]; //immediates in expanded form st32 immediate; //set if the command has a second string representation bool pseudoInstruction; -} RAsmLm32Instruction; +} RzAsmLm32Instruction; /* @@ -280,54 +280,54 @@ typedef struct r_asm_lm32_instruction { * bits 20..16 -> reg v * bits 15..11 -> reg w */ -static const int RAsmLm32OpShift = 26; -static const ut32 RAsmLm32OpMask = 0xfc000000; -static const int RAsmLm32RegUShift = 21; -static const ut32 RAsmLm32RegUMask = 0x03e00000; -static const int RAsmLm32RegVShift = 16; -static const ut32 RAsmLm32RegVMask = 0x001f0000; -static const int RAsmLm32RegWShift = 11; -static const ut32 RAsmLm32RegWMask = 0x0000f800; -static const ut32 RAsmLm32Imm5Mask = 0x0000001f; -static const ut32 RAsmLm32Imm16Mask = 0x0000ffff; -static const ut32 RAsmLm32Imm16SignBitPos = 15; -static const ut32 RAsmLm32Imm26Mask = 0x03ffffff; -static const ut32 RAsmLm32Imm26SignBitPos = 25; +static const int RzAsmLm32OpShift = 26; +static const ut32 RzAsmLm32OpMask = 0xfc000000; +static const int RzAsmLm32RegUShift = 21; +static const ut32 RzAsmLm32RegUMask = 0x03e00000; +static const int RzAsmLm32RegVShift = 16; +static const ut32 RzAsmLm32RegVMask = 0x001f0000; +static const int RzAsmLm32RegWShift = 11; +static const ut32 RzAsmLm32RegWMask = 0x0000f800; +static const ut32 RzAsmLm32Imm5Mask = 0x0000001f; +static const ut32 RzAsmLm32Imm16Mask = 0x0000ffff; +static const ut32 RzAsmLm32Imm16SignBitPos = 15; +static const ut32 RzAsmLm32Imm26Mask = 0x03ffffff; +static const ut32 RzAsmLm32Imm26SignBitPos = 25; -static const ut32 RAsmLm32InstrImm5InvalidBitsMask = 0x0000ffe0; -static const ut32 RAsmLm32InstrOneRegInvalidBitsMask = 0x001fffff; -static const ut32 RAsmLm32InstrTwoRegsInvalidBitsMask = 0x001f07ff; -static const ut32 RAsmLm32InstrWcsrInvalidBitsMask = 0x0000ffff; +static const ut32 RzAsmLm32InstrImm5InvalidBitsMask = 0x0000ffe0; +static const ut32 RzAsmLm32InstrOneRegInvalidBitsMask = 0x001fffff; +static const ut32 RzAsmLm32InstrTwoRegsInvalidBitsMask = 0x001f07ff; +static const ut32 RzAsmLm32InstrWcsrInvalidBitsMask = 0x0000ffff; //common helper functions static ut8 extract_opcode(ut32 instr_dword) { - return (instr_dword & RAsmLm32OpMask) >> RAsmLm32OpShift; + return (instr_dword & RzAsmLm32OpMask) >> RzAsmLm32OpShift; } static ut8 extract_reg_u(ut32 instr_dword) { - return (instr_dword & RAsmLm32RegUMask) >> RAsmLm32RegUShift; + return (instr_dword & RzAsmLm32RegUMask) >> RzAsmLm32RegUShift; } static ut8 extract_reg_v(ut32 instr_dword) { - return (instr_dword & RAsmLm32RegVMask) >> RAsmLm32RegVShift; + return (instr_dword & RzAsmLm32RegVMask) >> RzAsmLm32RegVShift; } static ut8 extract_reg_w(ut32 instr_dword) { - return (instr_dword & RAsmLm32RegWMask) >> RAsmLm32RegWShift; + return (instr_dword & RzAsmLm32RegWMask) >> RzAsmLm32RegWShift; } static ut8 extract_imm5(ut32 instr_dword) { - return instr_dword & RAsmLm32Imm5Mask; + return instr_dword & RzAsmLm32Imm5Mask; } static ut16 extract_imm16(ut32 instr_dword) { - return instr_dword & RAsmLm32Imm16Mask; + return instr_dword & RzAsmLm32Imm16Mask; } static ut32 extract_imm26(ut32 instr_dword) { - return instr_dword & RAsmLm32Imm26Mask; + return instr_dword & RzAsmLm32Imm26Mask; } #endif //INCLUDE_LM32_ISA_H diff --git a/libr/asm/arch/mcore/mcore.c b/librz/asm/arch/mcore/mcore.c similarity index 99% rename from libr/asm/arch/mcore/mcore.c rename to librz/asm/arch/mcore/mcore.c index cf795559ce..0d6a2817cb 100644 --- a/libr/asm/arch/mcore/mcore.c +++ b/librz/asm/arch/mcore/mcore.c @@ -1,6 +1,6 @@ #include "mcore.h" -#include +#include #include #include #include diff --git a/libr/asm/arch/mcore/mcore.h b/librz/asm/arch/mcore/mcore.h similarity index 97% rename from libr/asm/arch/mcore/mcore.h rename to librz/asm/arch/mcore/mcore.h index b6b2bcf89e..6281f2049e 100644 --- a/libr/asm/arch/mcore/mcore.h +++ b/librz/asm/arch/mcore/mcore.h @@ -2,7 +2,7 @@ #define MCORE_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/libr/asm/arch/mcs96/mcs96.h b/librz/asm/arch/mcs96/mcs96.h similarity index 99% rename from libr/asm/arch/mcs96/mcs96.h rename to librz/asm/arch/mcs96/mcs96.h index b7f21ca05d..3e1f13524c 100644 --- a/libr/asm/arch/mcs96/mcs96.h +++ b/librz/asm/arch/mcs96/mcs96.h @@ -1,5 +1,5 @@ -#include -#include +#include +#include typedef struct mcs96_op_t { const char *ins; diff --git a/libr/asm/arch/mips/gnu/mips-dis.c b/librz/asm/arch/mips/gnu/mips-dis.c similarity index 100% rename from libr/asm/arch/mips/gnu/mips-dis.c rename to librz/asm/arch/mips/gnu/mips-dis.c diff --git a/libr/asm/arch/mips/gnu/mips-opc.c b/librz/asm/arch/mips/gnu/mips-opc.c similarity index 100% rename from libr/asm/arch/mips/gnu/mips-opc.c rename to librz/asm/arch/mips/gnu/mips-opc.c diff --git a/libr/asm/arch/mips/gnu/mips16-opc.c b/librz/asm/arch/mips/gnu/mips16-opc.c similarity index 100% rename from libr/asm/arch/mips/gnu/mips16-opc.c rename to librz/asm/arch/mips/gnu/mips16-opc.c diff --git a/libr/asm/arch/mips/mipsasm.c b/librz/asm/arch/mips/mipsasm.c similarity index 96% rename from libr/asm/arch/mips/mipsasm.c rename to librz/asm/arch/mips/mipsasm.c index 5543e54bcb..56905c44d3 100644 --- a/libr/asm/arch/mips/mipsasm.c +++ b/librz/asm/arch/mips/mipsasm.c @@ -1,7 +1,7 @@ /* radare - Copyright 2012-2018 - pancake */ -#include -#include +#include +#include static const char *const regs[33] = { "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3", @@ -132,10 +132,10 @@ static int getreg(const char *p) { } /* try to convert it into a number */ if (p[0] == '-') { - n = (int) r_num_get (NULL, &p[1]); + n = (int) rz_num_get (NULL, &p[1]); n = -n; } else { - n = (int) r_num_get (NULL, p); + n = (int) rz_num_get (NULL, p); } if (n != 0 || p[0] == '0') { return n; @@ -148,9 +148,9 @@ R_IPI int mips_assemble(const char *str, ut64 pc, ut8 *out) { int i, hasp, is_branch; char *s = strdup (str); char w0[32], w1[32], w2[32], w3[32]; - r_str_replace_char (s, ',', ' '); - hasp = r_str_replace_char (s, '(', ' '); - r_str_replace_char (s, ')', ' '); + rz_str_replace_char (s, ',', ' '); + hasp = rz_str_replace_char (s, '(', ' '); + rz_str_replace_char (s, ')', ' '); *out = 0; *w0=*w1=*w2=*w3=0; diff --git a/libr/asm/arch/msp430/msp430_disas.c b/librz/asm/arch/msp430/msp430_disas.c similarity index 98% rename from libr/asm/arch/msp430/msp430_disas.c rename to librz/asm/arch/msp430/msp430_disas.c index 2ab696d8b1..8e8a404e9d 100644 --- a/libr/asm/arch/msp430/msp430_disas.c +++ b/librz/asm/arch/msp430/msp430_disas.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "msp430_disas.h" @@ -452,7 +452,7 @@ int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) { if (len < 2) { return -1; } - ut16 instr = r_read_le16 (in); + ut16 instr = rz_read_le16 (in); ut8 opcode = get_twoop_opcode (instr); switch (opcode) { @@ -464,7 +464,7 @@ int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) { if ((instr & 0x0f80) <= 0x0300) { // Single operand instructions. if (len >= 4) { - operand1 = r_read_at_le16 (in, 2); + operand1 = rz_read_at_le16 (in, 2); } ret = decode_oneop_opcode(instr, operand1, cmd); } @@ -479,9 +479,9 @@ int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd) { // Double operand instructions. cmd->type = MSP430_TWOOP; if (len >= 4) { - operand1 = r_read_at_le16 (in, 2); + operand1 = rz_read_at_le16 (in, 2); if (len >= 6) { - operand2 = r_read_at_le16 (in, 4); + operand2 = rz_read_at_le16 (in, 4); } } ret = decode_twoop_opcode (instr, operand1, operand2, cmd); diff --git a/libr/asm/arch/msp430/msp430_disas.h b/librz/asm/arch/msp430/msp430_disas.h similarity index 100% rename from libr/asm/arch/msp430/msp430_disas.h rename to librz/asm/arch/msp430/msp430_disas.h diff --git a/libr/asm/arch/nios/gnu/nios2-dis.c b/librz/asm/arch/nios/gnu/nios2-dis.c similarity index 100% rename from libr/asm/arch/nios/gnu/nios2-dis.c rename to librz/asm/arch/nios/gnu/nios2-dis.c diff --git a/libr/asm/arch/nios/gnu/nios2-opc.c b/librz/asm/arch/nios/gnu/nios2-opc.c similarity index 100% rename from libr/asm/arch/nios/gnu/nios2-opc.c rename to librz/asm/arch/nios/gnu/nios2-opc.c diff --git a/libr/asm/arch/or1k/or1k_disas.c b/librz/asm/arch/or1k/or1k_disas.c similarity index 99% rename from libr/asm/arch/or1k/or1k_disas.c rename to librz/asm/arch/or1k/or1k_disas.c index f6edee8c7c..ca72e77154 100644 --- a/libr/asm/arch/or1k/or1k_disas.c +++ b/librz/asm/arch/or1k/or1k_disas.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2019 - v3l0c1r4pt0r */ +/* rizin - LGPL - Copyright 2019 - v3l0c1r4pt0r */ -#include +#include #include "or1k_disas.h" insn_type_descr_t types[] = { diff --git a/libr/asm/arch/or1k/or1k_disas.h b/librz/asm/arch/or1k/or1k_disas.h similarity index 95% rename from libr/asm/arch/or1k/or1k_disas.h rename to librz/asm/arch/or1k/or1k_disas.h index 5e62307535..4341e202dd 100644 --- a/libr/asm/arch/or1k/or1k_disas.h +++ b/librz/asm/arch/or1k/or1k_disas.h @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2019 - v3l0c1r4pt0r */ +/* rizin - LGPL - Copyright 2019 - v3l0c1r4pt0r */ -#include +#include #ifndef OR1K_DISAS_H #define OR1K_DISAS_H @@ -106,14 +106,14 @@ typedef struct { char *name; int type; int opcode_mask; - int insn_type; /**< One of \link _RAnalOpType \endlink */ + int insn_type; /**< One of \link _RzAnalOpType \endlink */ } insn_extra_t; typedef struct { ut32 opcode; char *name; int type; - int insn_type; /**< One of \link _RAnalOpType \endlink */ + int insn_type; /**< One of \link _RzAnalOpType \endlink */ insn_extra_t *extra; } insn_t; @@ -169,7 +169,7 @@ static inline int is_type_descriptor_defined(insn_type_t type) { } static inline insn_type_t type_of_opcode(insn_t *descr, insn_extra_t *extra_descr) { - r_return_val_if_fail (descr, INSN_END); + rz_return_val_if_fail (descr, INSN_END); if (extra_descr == NULL) { return descr->type; diff --git a/libr/asm/arch/pic/pic_baseline.c b/librz/asm/arch/pic/pic_baseline.c similarity index 97% rename from libr/asm/arch/pic/pic_baseline.c rename to librz/asm/arch/pic/pic_baseline.c index 3c825453ef..ef5990d044 100644 --- a/libr/asm/arch/pic/pic_baseline.c +++ b/librz/asm/arch/pic/pic_baseline.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2018 - thestr4ng3r */ +/* rizin - LGPL - Copyright 2018 - thestr4ng3r */ #include "pic_baseline.h" @@ -191,7 +191,7 @@ const PicBaselineOpInfo *pic_baseline_get_op_info(PicBaselineOpcode opcode) { } -int pic_baseline_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l) { +int pic_baseline_disassemble(RzAsmOp *op, char *opbuf, const ut8 *b, int l) { #define EMIT_INVALID { \ op->size = 1; \ strcpy (opbuf, "invalid"); \ @@ -201,7 +201,7 @@ int pic_baseline_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l) { EMIT_INVALID } - ut16 instr = r_read_le16 (b); + ut16 instr = rz_read_le16 (b); PicBaselineOpcode opcode = pic_baseline_get_opcode (instr); if (opcode == PIC_BASELINE_OPCODE_INVALID) { EMIT_INVALID diff --git a/libr/asm/arch/pic/pic_baseline.h b/librz/asm/arch/pic/pic_baseline.h similarity index 92% rename from libr/asm/arch/pic/pic_baseline.h rename to librz/asm/arch/pic/pic_baseline.h index da5b88962e..4036702fb9 100644 --- a/libr/asm/arch/pic/pic_baseline.h +++ b/librz/asm/arch/pic/pic_baseline.h @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2018 - thestr4ng3r */ +/* rizin - LGPL - Copyright 2018 - thestr4ng3r */ #ifndef PIC_BASELINE_H #define PIC_BASELINE_H -#include -#include +#include +#include typedef enum { PIC_BASELINE_OP_ARGS_NONE = 0, @@ -76,6 +76,6 @@ typedef enum { PicBaselineOpcode pic_baseline_get_opcode(ut16 instr); const PicBaselineOpInfo *pic_baseline_get_op_info(PicBaselineOpcode opcode); -int pic_baseline_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int l); +int pic_baseline_disassemble(RzAsmOp *op, char *opbuf, const ut8 *b, int l); #endif //PIC_BASELINE_H diff --git a/libr/asm/arch/pic/pic_midrange.c b/librz/asm/arch/pic/pic_midrange.c similarity index 98% rename from libr/asm/arch/pic/pic_midrange.c rename to librz/asm/arch/pic/pic_midrange.c index d799c6896e..cdd4fb9fe2 100644 --- a/libr/asm/arch/pic/pic_midrange.c +++ b/librz/asm/arch/pic/pic_midrange.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2018 - courk */ +/* rizin - LGPL - Copyright 2018 - courk */ #include "pic_midrange.h" @@ -154,7 +154,7 @@ const PicMidrangeOpInfo *pic_midrange_get_op_info (PicMidrangeOpcode opcode) { return &pic_midrange_op_info[opcode]; } -int pic_midrange_disassemble (RAsmOp *op, char *opbuf, const ut8 *b, int l) { +int pic_midrange_disassemble (RzAsmOp *op, char *opbuf, const ut8 *b, int l) { char fsr_op[6]; st16 branch; @@ -167,7 +167,7 @@ int pic_midrange_disassemble (RAsmOp *op, char *opbuf, const ut8 *b, int l) { EMIT_INVALID } - ut16 instr = r_read_le16 (b); + ut16 instr = rz_read_le16 (b); PicMidrangeOpcode opcode = pic_midrange_get_opcode (instr); if (opcode == PIC_MIDRANGE_OPCODE_INVALID) { EMIT_INVALID diff --git a/libr/asm/arch/pic/pic_midrange.h b/librz/asm/arch/pic/pic_midrange.h similarity index 94% rename from libr/asm/arch/pic/pic_midrange.h rename to librz/asm/arch/pic/pic_midrange.h index 0bc498bada..b924dce6c4 100644 --- a/libr/asm/arch/pic/pic_midrange.h +++ b/librz/asm/arch/pic/pic_midrange.h @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2018 - courk */ +/* rizin - LGPL - Copyright 2018 - courk */ #ifndef PIC_MIDRANGE_H #define PIC_MIDRANGE_H -#include -#include +#include +#include typedef enum { PIC_MIDRANGE_OP_ARGS_NONE = 0, @@ -98,6 +98,6 @@ typedef enum { PicMidrangeOpcode pic_midrange_get_opcode (ut16 instr); const PicMidrangeOpInfo *pic_midrange_get_op_info (PicMidrangeOpcode opcode); -int pic_midrange_disassemble (RAsmOp *op, char *opbuf, const ut8 *b, int l); +int pic_midrange_disassemble (RzAsmOp *op, char *opbuf, const ut8 *b, int l); #endif // PIC_MIDRANGE_H diff --git a/libr/asm/arch/pic/pic_pic18.c b/librz/asm/arch/pic/pic_pic18.c similarity index 97% rename from libr/asm/arch/pic/pic_pic18.c rename to librz/asm/arch/pic/pic_pic18.c index 86309a1b6e..bf8b3e556a 100644 --- a/libr/asm/arch/pic/pic_pic18.c +++ b/librz/asm/arch/pic/pic_pic18.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r */ +/* rizin - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r */ -#include +#include #include "pic_pic18.h" @@ -109,7 +109,7 @@ static struct { {0x0, 0xffff, "invalid", NO_ARG}, }; -int pic_pic18_disassemble(RAsmOp *op, char *opbuf, const ut8 *b, int blen) { +int pic_pic18_disassemble(RzAsmOp *op, char *opbuf, const ut8 *b, int blen) { int i; if (blen < 2) { //well noone loves reading bitstream of size zero or 1 !! strcpy (opbuf, "invalid"); diff --git a/librz/asm/arch/pic/pic_pic18.h b/librz/asm/arch/pic/pic_pic18.h new file mode 100644 index 0000000000..41fad8b958 --- /dev/null +++ b/librz/asm/arch/pic/pic_pic18.h @@ -0,0 +1,10 @@ +/* rizin - LGPL - Copyright 2015-2018 - oddcoder, thestr4ng3r */ + +#ifndef PIC_PIC18_H +#define PIC_PIC18_H + +#include + +int pic_pic18_disassemble(RzAsmOp *op, char *opbuf, const ut8 *b, int l); + +#endif //PIC_PIC18_H diff --git a/libr/asm/arch/ppc/README b/librz/asm/arch/ppc/README similarity index 100% rename from libr/asm/arch/ppc/README rename to librz/asm/arch/ppc/README diff --git a/libr/asm/arch/ppc/gnu/ppc-dis.c b/librz/asm/arch/ppc/gnu/ppc-dis.c similarity index 100% rename from libr/asm/arch/ppc/gnu/ppc-dis.c rename to librz/asm/arch/ppc/gnu/ppc-dis.c diff --git a/libr/asm/arch/ppc/gnu/ppc-opc.c b/librz/asm/arch/ppc/gnu/ppc-opc.c similarity index 99% rename from libr/asm/arch/ppc/gnu/ppc-opc.c rename to librz/asm/arch/ppc/gnu/ppc-opc.c index 45cfa3be52..d459af95a4 100644 --- a/libr/asm/arch/ppc/gnu/ppc-opc.c +++ b/librz/asm/arch/ppc/gnu/ppc-opc.c @@ -207,12 +207,12 @@ const struct powerpc_operand powerpc_operands[] = #define MB_MASK (0x1f << 6) { 0x1f, 6, NULL, NULL, 0 }, - /* The CRFS field in an X form instruction. */ -#define CRFS (CRB + 1) + /* The CRzFS field in an X form instruction. */ +#define CRzFS (CRB + 1) { 0x7, 0, NULL, NULL, PPC_OPERAND_CR }, /* The CT field in an X form instruction. */ -#define CT (CRFS + 1) +#define CT (CRzFS + 1) /* The MO field in an mbar instruction. */ #define MO CT { 0x1f, 21, NULL, NULL, PPC_OPERAND_OPTIONAL }, @@ -2147,7 +2147,7 @@ const struct powerpc_opcode powerpc_opcodes[] = { {"vsplth", VX (4, 588), VX_MASK, PPCVEC, {VD, VB, UIMM}}, {"vupkhsh", VX (4, 590), VX_MASK, PPCVEC, {VD, VB}}, {"nget", APU(4, 300,0), APU_RA_MASK, PPC405, {RT, FSL}}, -{"evsel", EVSEL(4,79), EVSEL_MASK, PPCSPE, {RS, RA, RB, CRFS}}, +{"evsel", EVSEL(4,79), EVSEL_MASK, PPCSPE, {RS, RA, RB, CRzFS}}, {"ncget", APU(4, 316,0), APU_RA_MASK, PPC405, {RT, FSL}}, {"evfsadd", VX (4, 640), VX_MASK, PPCSPE, {RS, RA, RB}}, {"vadduws", VX (4, 640), VX_MASK, PPCVEC, {VD, VA, VB}}, diff --git a/libr/asm/arch/ppc/libps/libps.c b/librz/asm/arch/ppc/libps/libps.c similarity index 100% rename from libr/asm/arch/ppc/libps/libps.c rename to librz/asm/arch/ppc/libps/libps.c diff --git a/libr/asm/arch/ppc/libps/libps.h b/librz/asm/arch/ppc/libps/libps.h similarity index 94% rename from libr/asm/arch/ppc/libps/libps.h rename to librz/asm/arch/ppc/libps/libps.h index 6a6b1e93f8..13f6b75d86 100644 --- a/libr/asm/arch/ppc/libps/libps.h +++ b/librz/asm/arch/ppc/libps/libps.h @@ -2,7 +2,7 @@ #ifndef LIBPS_H #define LIBPS_H -#include +#include typedef struct { ut32 value; diff --git a/libr/asm/arch/ppc/libps/libps_internal.h b/librz/asm/arch/ppc/libps/libps_internal.h similarity index 99% rename from libr/asm/arch/ppc/libps/libps_internal.h rename to librz/asm/arch/ppc/libps/libps_internal.h index a75f7ea8cc..14016716ad 100644 --- a/libr/asm/arch/ppc/libps/libps_internal.h +++ b/librz/asm/arch/ppc/libps/libps_internal.h @@ -2,7 +2,7 @@ #ifndef LIBPS_INTERNAL_H #define LIBPS_INTERNAL_H -#include +#include #define TYPE_NONE 0 #define TYPE_REG 1 diff --git a/libr/asm/arch/ppc/libvle/vle.c b/librz/asm/arch/ppc/libvle/vle.c similarity index 99% rename from libr/asm/arch/ppc/libvle/vle.c rename to librz/asm/arch/ppc/libvle/vle.c index 9b0a7541ce..b2c110e4b2 100644 --- a/libr/asm/arch/ppc/libvle/vle.c +++ b/librz/asm/arch/ppc/libvle/vle.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017 - wargio */ +/* rizin - LGPL - Copyright 2017 - wargio */ #include "vle.h" #include "vle_internal.h" -#include +#include #define USE_INTERNAL_PPC(x) ((x)->options&VLE_INTERNAL_PPC) diff --git a/libr/asm/arch/ppc/libvle/vle.h b/librz/asm/arch/ppc/libvle/vle.h similarity index 97% rename from libr/asm/arch/ppc/libvle/vle.h rename to librz/asm/arch/ppc/libvle/vle.h index b562d04ae3..3362faf271 100644 --- a/libr/asm/arch/ppc/libvle/vle.h +++ b/librz/asm/arch/ppc/libvle/vle.h @@ -1,6 +1,6 @@ #ifndef LIB_PPCVLE #define LIB_PPCVLE -#include +#include #define VLE_DEFAULTS 0 #define VLE_INTERNAL_PPC 1 diff --git a/libr/asm/arch/ppc/libvle/vle_internal.h b/librz/asm/arch/ppc/libvle/vle_internal.h similarity index 100% rename from libr/asm/arch/ppc/libvle/vle_internal.h rename to librz/asm/arch/ppc/libvle/vle_internal.h diff --git a/libr/asm/arch/propeller/propeller_disas.c b/librz/asm/arch/propeller/propeller_disas.c similarity index 99% rename from libr/asm/arch/propeller/propeller_disas.c rename to librz/asm/arch/propeller/propeller_disas.c index 649cdcb2d3..b6cb796983 100644 --- a/libr/asm/arch/propeller/propeller_disas.c +++ b/librz/asm/arch/propeller/propeller_disas.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "propeller_disas.h" @@ -206,7 +206,7 @@ int propeller_decode_command(const ut8 *instr, struct propeller_cmd *cmd) ut32 in; ut16 opcode; - in = r_read_be32 (instr); + in = rz_read_be32 (instr); opcode = get_opcode (in); diff --git a/libr/asm/arch/propeller/propeller_disas.h b/librz/asm/arch/propeller/propeller_disas.h similarity index 100% rename from libr/asm/arch/propeller/propeller_disas.h rename to librz/asm/arch/propeller/propeller_disas.h diff --git a/libr/asm/arch/pyc/opcode.c b/librz/asm/arch/pyc/opcode.c similarity index 97% rename from libr/asm/arch/pyc/opcode.c rename to librz/asm/arch/pyc/opcode.c index 1c6322c615..5e678c1ee0 100644 --- a/libr/asm/arch/pyc/opcode.c +++ b/librz/asm/arch/pyc/opcode.c @@ -164,7 +164,7 @@ pyc_opcodes *new_pyc_opcodes() { return NULL; } for (i = 0; i < 256; i++) { - ret->opcodes[i].op_name = r_str_newf ("<%lu>", i); + ret->opcodes[i].op_name = rz_str_newf ("<%lu>", i); if (!ret->opcodes[i].op_name) { for (j = 0; j < i; j++) { free (ret->opcodes[j].op_name); @@ -179,7 +179,7 @@ pyc_opcodes *new_pyc_opcodes() { ret->opcodes[i].op_pop = 0; } - ret->opcode_arg_fmt = r_list_newf ((RListFree)free); + ret->opcode_arg_fmt = rz_list_newf ((RzListFree)free); return ret; } @@ -189,7 +189,7 @@ void free_opcode(pyc_opcodes *opcodes) { free (opcodes->opcodes[i].op_name); } free (opcodes->opcodes); - r_list_free (opcodes->opcode_arg_fmt); + rz_list_free (opcodes->opcode_arg_fmt); free (opcodes); } @@ -200,7 +200,7 @@ void add_arg_fmt(pyc_opcodes *ret, char *op_name, const char *(*formatter) (ut32 } fmt->op_name = op_name; fmt->formatter = formatter; - r_list_append (ret->opcode_arg_fmt, fmt); + rz_list_append (ret->opcode_arg_fmt, fmt); } void (def_opN)(struct op_parameter par) { @@ -290,7 +290,7 @@ void (rm_op)(struct op_parameter par) { pyc_opcode_object *op_obj = &par.op_obj[par.op_code]; if (op_obj->op_code == par.op_code && !strcmp (op_obj->op_name, par.op_name)) { free (op_obj->op_name); - op_obj->op_name = r_str_newf ("<%u>", par.op_code); + op_obj->op_name = rz_str_newf ("<%u>", par.op_code); op_obj->type = op_obj->op_pop = op_obj->op_push = 0; } else { eprintf ("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name); diff --git a/libr/asm/arch/pyc/opcode.h b/librz/asm/arch/pyc/opcode.h similarity index 95% rename from libr/asm/arch/pyc/opcode.h rename to librz/asm/arch/pyc/opcode.h index a0c3b34224..e1f9b4b2a1 100644 --- a/libr/asm/arch/pyc/opcode.h +++ b/librz/asm/arch/pyc/opcode.h @@ -3,10 +3,10 @@ #ifndef OPCODE_H #define OPCODE_H -#include -#include -#include -#include +#include +#include +#include +#include #define OBJECT_SIZE_ON_STACK 1 @@ -45,7 +45,7 @@ typedef struct { ut8 have_argument; ut8 bits; void *(*version_sig)(); - RList *opcode_arg_fmt; + RzList *opcode_arg_fmt; pyc_opcode_object *opcodes; } pyc_opcodes; @@ -61,10 +61,10 @@ typedef struct { typedef struct { char *op_name; - void (*func)(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg); + void (*func)(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg); } op_anal_func; -void anal_pyc_op(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg); +void anal_pyc_op(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg); pyc_opcodes *opcode_2x(void); pyc_opcodes *opcode_3x(void); diff --git a/libr/asm/arch/pyc/opcode_10.c b/librz/asm/arch/pyc/opcode_10.c similarity index 91% rename from libr/asm/arch/pyc/opcode_10.c rename to librz/asm/arch/pyc/opcode_10.c index 846e49c8e3..a45be47a4b 100644 --- a/libr/asm/arch/pyc/opcode_10.c +++ b/librz/asm/arch/pyc/opcode_10.c @@ -12,7 +12,7 @@ pyc_opcodes *opcode_10(void) { rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBALS", .op_code = 84); rm_op (.op_obj = ret->opcodes, .op_name = "EXEC_STMT", .op_code = 85); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_11.c b/librz/asm/arch/pyc/opcode_11.c similarity index 86% rename from libr/asm/arch/pyc/opcode_11.c rename to librz/asm/arch/pyc/opcode_11.c index d42ed26ae6..895a95b15d 100644 --- a/libr/asm/arch/pyc/opcode_11.c +++ b/librz/asm/arch/pyc/opcode_11.c @@ -8,7 +8,7 @@ pyc_opcodes *opcode_11(void) { ret->version_sig = (void *(*)())opcode_11; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_12.c b/librz/asm/arch/pyc/opcode_12.c similarity index 86% rename from libr/asm/arch/pyc/opcode_12.c rename to librz/asm/arch/pyc/opcode_12.c index da8ceeda14..29594976bf 100644 --- a/libr/asm/arch/pyc/opcode_12.c +++ b/librz/asm/arch/pyc/opcode_12.c @@ -8,7 +8,7 @@ pyc_opcodes *opcode_12(void) { ret->version_sig = (void *(*)())opcode_12; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_13.c b/librz/asm/arch/pyc/opcode_13.c similarity index 91% rename from libr/asm/arch/pyc/opcode_13.c rename to librz/asm/arch/pyc/opcode_13.c index b57bc1c09f..ca0f567c52 100644 --- a/libr/asm/arch/pyc/opcode_13.c +++ b/librz/asm/arch/pyc/opcode_13.c @@ -12,7 +12,7 @@ pyc_opcodes *opcode_13(void) { rm_op (.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19); def_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBALS", .op_code = 84); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_14.c b/librz/asm/arch/pyc/opcode_14.c similarity index 96% rename from libr/asm/arch/pyc/opcode_14.c rename to librz/asm/arch/pyc/opcode_14.c index 427322c3a3..1f58f7b7de 100644 --- a/libr/asm/arch/pyc/opcode_14.c +++ b/librz/asm/arch/pyc/opcode_14.c @@ -19,7 +19,7 @@ pyc_opcodes *opcode_14(void) { varargs_op (.op_obj = ret->opcodes, .op_name = "SET_FUNC_ARGS", .op_code = 117); // Argcount varargs_op (.op_obj = ret->opcodes, .op_name = "RESERVE_FAST", .op_code = 123); // Number of local variables - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_15.c b/librz/asm/arch/pyc/opcode_15.c similarity index 99% rename from libr/asm/arch/pyc/opcode_15.c rename to librz/asm/arch/pyc/opcode_15.c index 9a5b3dce7c..c2d009cf96 100644 --- a/libr/asm/arch/pyc/opcode_15.c +++ b/librz/asm/arch/pyc/opcode_15.c @@ -118,7 +118,7 @@ pyc_opcodes *opcode_15(void) { def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143); ret->extended_arg = 143; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_16.c b/librz/asm/arch/pyc/opcode_16.c similarity index 94% rename from libr/asm/arch/pyc/opcode_16.c rename to librz/asm/arch/pyc/opcode_16.c index fb3ce804ca..cd3d25fe4a 100644 --- a/libr/asm/arch/pyc/opcode_16.c +++ b/librz/asm/arch/pyc/opcode_16.c @@ -13,7 +13,7 @@ pyc_opcodes *opcode_16(void) { nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_KW", .op_code = 141, .pop = -1, .push = 1); // #args + (#kwargs << 8) nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR_KW", .op_code = 142, .pop = -1, .push = 1); // #args + (#kwargs << 8) - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_20.c b/librz/asm/arch/pyc/opcode_20.c similarity index 94% rename from libr/asm/arch/pyc/opcode_20.c rename to librz/asm/arch/pyc/opcode_20.c index 978d200ece..abddd71306 100644 --- a/libr/asm/arch/pyc/opcode_20.c +++ b/librz/asm/arch/pyc/opcode_20.c @@ -15,7 +15,7 @@ pyc_opcodes *opcode_20(void) { rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_DEREF", .op_code = 136); rm_op (.op_obj = ret->opcodes, .op_name = "STORE_DEREF", .op_code = 137); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_21.c b/librz/asm/arch/pyc/opcode_21.c similarity index 95% rename from libr/asm/arch/pyc/opcode_21.c rename to librz/asm/arch/pyc/opcode_21.c index 60552c0e60..4d624540f6 100644 --- a/libr/asm/arch/pyc/opcode_21.c +++ b/librz/asm/arch/pyc/opcode_21.c @@ -17,7 +17,7 @@ pyc_opcodes *opcode_21(void) { rm_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86); rm_op (.op_obj = ret->opcodes, .op_name = "FOR_ITER", .op_code = 93); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_22.c b/librz/asm/arch/pyc/opcode_22.c similarity index 91% rename from libr/asm/arch/pyc/opcode_22.c rename to librz/asm/arch/pyc/opcode_22.c index 78a5af5d85..8a6e3b17aa 100644 --- a/libr/asm/arch/pyc/opcode_22.c +++ b/librz/asm/arch/pyc/opcode_22.c @@ -12,7 +12,7 @@ pyc_opcodes *opcode_22(void) { def_op (.op_obj = ret->opcodes, .op_name = "FOR_LOOP", .op_code = 114); def_op (.op_obj = ret->opcodes, .op_name = "SET_LINENO", .op_code = 127, .pop = 0, .push = 0); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_23.c b/librz/asm/arch/pyc/opcode_23.c similarity index 86% rename from libr/asm/arch/pyc/opcode_23.c rename to librz/asm/arch/pyc/opcode_23.c index 63cee0ba84..fd360ebdba 100644 --- a/libr/asm/arch/pyc/opcode_23.c +++ b/librz/asm/arch/pyc/opcode_23.c @@ -8,7 +8,7 @@ pyc_opcodes *opcode_23(void) { ret->version_sig = (void *(*)())opcode_23; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_24.c b/librz/asm/arch/pyc/opcode_24.c similarity index 94% rename from libr/asm/arch/pyc/opcode_24.c rename to librz/asm/arch/pyc/opcode_24.c index c66eb87ef6..021a429d57 100644 --- a/libr/asm/arch/pyc/opcode_24.c +++ b/librz/asm/arch/pyc/opcode_24.c @@ -14,7 +14,7 @@ pyc_opcodes *opcode_24(void) { // Used to implement list comprehensions. def_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86, .pop = 1, .push = 0); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_25.c b/librz/asm/arch/pyc/opcode_25.c similarity index 90% rename from libr/asm/arch/pyc/opcode_25.c rename to librz/asm/arch/pyc/opcode_25.c index f02b8abc82..f737db6a02 100644 --- a/libr/asm/arch/pyc/opcode_25.c +++ b/librz/asm/arch/pyc/opcode_25.c @@ -11,7 +11,7 @@ pyc_opcodes *opcode_25(void) { // Bytecodes added in 2.5 from 2.4 def_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP", .op_code = 81); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_26.c b/librz/asm/arch/pyc/opcode_26.c similarity index 90% rename from libr/asm/arch/pyc/opcode_26.c rename to librz/asm/arch/pyc/opcode_26.c index 4f7cc106c3..5473e90e3a 100644 --- a/libr/asm/arch/pyc/opcode_26.c +++ b/librz/asm/arch/pyc/opcode_26.c @@ -11,7 +11,7 @@ pyc_opcodes *opcode_26(void) { // Below are opcode changes since Python 2.5 store_op (.op_obj = ret->opcodes, .op_name = "STORE_MAP", .op_code = 54, .pop = 3, .push = 1); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_27.c b/librz/asm/arch/pyc/opcode_27.c similarity index 98% rename from libr/asm/arch/pyc/opcode_27.c rename to librz/asm/arch/pyc/opcode_27.c index 42792e9702..93df58c315 100644 --- a/libr/asm/arch/pyc/opcode_27.c +++ b/librz/asm/arch/pyc/opcode_27.c @@ -40,7 +40,7 @@ pyc_opcodes *opcode_27(void) { def_op (.op_obj = ret->opcodes, .op_name = "MAP_ADD", .op_code = 147, .pop = 2, .push = 1); // Calls dict.setitem(TOS1[-i], TOS, TOS1) // Used to implement dict comprehensions. - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "CALL_FUNCTION", format_CALL_FUNCTION_pos_name_encoded); diff --git a/libr/asm/arch/pyc/opcode_2x.c b/librz/asm/arch/pyc/opcode_2x.c similarity index 99% rename from libr/asm/arch/pyc/opcode_2x.c rename to librz/asm/arch/pyc/opcode_2x.c index 0e4b5b1c2f..5085d6f710 100644 --- a/libr/asm/arch/pyc/opcode_2x.c +++ b/librz/asm/arch/pyc/opcode_2x.c @@ -146,7 +146,7 @@ pyc_opcodes *opcode_2x(void) { def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", 143); ret->extended_arg = 143; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); return ret; } diff --git a/libr/asm/arch/pyc/opcode_30.c b/librz/asm/arch/pyc/opcode_30.c similarity index 97% rename from libr/asm/arch/pyc/opcode_30.c rename to librz/asm/arch/pyc/opcode_30.c index 4a6524e935..81b7203158 100644 --- a/libr/asm/arch/pyc/opcode_30.c +++ b/librz/asm/arch/pyc/opcode_30.c @@ -28,7 +28,7 @@ pyc_opcodes *opcode_30(void) { jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111, .pop = 1, .push = 1, .conditional = true); jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112, .pop = 1, .push = 1, .conditional = true); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_31.c b/librz/asm/arch/pyc/opcode_31.c similarity index 95% rename from libr/asm/arch/pyc/opcode_31.c rename to librz/asm/arch/pyc/opcode_31.c index ca638282b4..0f0ba1309e 100644 --- a/libr/asm/arch/pyc/opcode_31.c +++ b/librz/asm/arch/pyc/opcode_31.c @@ -20,7 +20,7 @@ pyc_opcodes *opcode_31(void) { // This op is in 3.2 but its opcode is a 144 instead def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_32.c b/librz/asm/arch/pyc/opcode_32.c similarity index 91% rename from libr/asm/arch/pyc/opcode_32.c rename to librz/asm/arch/pyc/opcode_32.c index fe8dfdfefc..98c2ed34ab 100644 --- a/libr/asm/arch/pyc/opcode_32.c +++ b/librz/asm/arch/pyc/opcode_32.c @@ -11,7 +11,7 @@ pyc_opcodes *opcode_32(void) { // There are no opcodes to add or change. // If there were, they'd be listed below. - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_33.c b/librz/asm/arch/pyc/opcode_33.c similarity index 93% rename from libr/asm/arch/pyc/opcode_33.c rename to librz/asm/arch/pyc/opcode_33.c index fc101250c3..fb6e04a97d 100644 --- a/libr/asm/arch/pyc/opcode_33.c +++ b/librz/asm/arch/pyc/opcode_33.c @@ -13,7 +13,7 @@ pyc_opcodes *opcode_33(void) { rm_op (.op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0); def_op (.op_obj = ret->opcodes, .op_name = "YIELD_FROM", .op_code = 72, .pop = 1, .push = 0); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_34.c b/librz/asm/arch/pyc/opcode_34.c similarity index 94% rename from libr/asm/arch/pyc/opcode_34.c rename to librz/asm/arch/pyc/opcode_34.c index dd51c2d940..b00c455884 100644 --- a/libr/asm/arch/pyc/opcode_34.c +++ b/librz/asm/arch/pyc/opcode_34.c @@ -15,7 +15,7 @@ pyc_opcodes *opcode_34(void) { def_op (.op_obj = ret->opcodes, .op_name = "YIELD_FROM", .op_code = 72); free_op (.op_obj = ret->opcodes, .op_name = "LOAD_CLASSDEREF", .op_code = 148); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_35.c b/librz/asm/arch/pyc/opcode_35.c similarity index 98% rename from libr/asm/arch/pyc/opcode_35.c rename to librz/asm/arch/pyc/opcode_35.c index 162e4a2fd3..a906ca25fd 100644 --- a/libr/asm/arch/pyc/opcode_35.c +++ b/librz/asm/arch/pyc/opcode_35.c @@ -35,7 +35,7 @@ pyc_opcodes *opcode_35(void) { jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_ASYNC_WITH", .op_code = 154, .pop = 0, .push = 6); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x); diff --git a/libr/asm/arch/pyc/opcode_36.c b/librz/asm/arch/pyc/opcode_36.c similarity index 97% rename from libr/asm/arch/pyc/opcode_36.c rename to librz/asm/arch/pyc/opcode_36.c index cca567ca09..cc8cbadcdc 100644 --- a/libr/asm/arch/pyc/opcode_36.c +++ b/librz/asm/arch/pyc/opcode_36.c @@ -23,7 +23,7 @@ pyc_opcodes *opcode_36(void) { def_op (.op_obj = ret->opcodes, .op_name = "BUILD_STRING", .op_code = 157); varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE_UNPACK_WITH_CALL", .op_code = 158); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36); add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36); diff --git a/libr/asm/arch/pyc/opcode_37.c b/librz/asm/arch/pyc/opcode_37.c similarity index 95% rename from libr/asm/arch/pyc/opcode_37.c rename to librz/asm/arch/pyc/opcode_37.c index 188f541258..2697f859eb 100644 --- a/libr/asm/arch/pyc/opcode_37.c +++ b/librz/asm/arch/pyc/opcode_37.c @@ -16,7 +16,7 @@ pyc_opcodes *opcode_37(void) { name_op (.op_obj = ret->opcodes, .op_name = "LOAD_METHOD", .op_code = 160); nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_METHOD", .op_code = 161); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36); add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36); diff --git a/libr/asm/arch/pyc/opcode_38.c b/librz/asm/arch/pyc/opcode_38.c similarity index 97% rename from libr/asm/arch/pyc/opcode_38.c rename to librz/asm/arch/pyc/opcode_38.c index 69e892c7b3..3c94250b63 100644 --- a/libr/asm/arch/pyc/opcode_38.c +++ b/librz/asm/arch/pyc/opcode_38.c @@ -25,7 +25,7 @@ pyc_opcodes *opcode_38(void) { jrel_op (.op_obj = ret->opcodes, .op_name = "CALL_FINALLY", .op_code = 162, .pop = 0, .push = 1); nargs_op (.op_obj = ret->opcodes, .op_name = "POP_FINALLY", .op_code = 163, .pop = 0, .push = 0); // PUSH/POP vary - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36); add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36); diff --git a/libr/asm/arch/pyc/opcode_39.c b/librz/asm/arch/pyc/opcode_39.c similarity index 97% rename from libr/asm/arch/pyc/opcode_39.c rename to librz/asm/arch/pyc/opcode_39.c index eae0eb43dd..8e754699b9 100644 --- a/libr/asm/arch/pyc/opcode_39.c +++ b/librz/asm/arch/pyc/opcode_39.c @@ -22,7 +22,7 @@ pyc_opcodes *opcode_39(void) { def_op (.op_obj = ret->opcodes, .op_name = "WITH_EXCEPT_START", .op_code = 49, .pop = 3, .push = 0); def_op (.op_obj = ret->opcodes, .op_name = "LOAD_ASSERTION_ERROR", .op_code = 74, .pop = 0, .push = 1); - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36); add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36); add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36); diff --git a/libr/asm/arch/pyc/opcode_3x.c b/librz/asm/arch/pyc/opcode_3x.c similarity index 99% rename from libr/asm/arch/pyc/opcode_3x.c rename to librz/asm/arch/pyc/opcode_3x.c index 4492192b29..65a44fa936 100644 --- a/libr/asm/arch/pyc/opcode_3x.c +++ b/librz/asm/arch/pyc/opcode_3x.c @@ -158,7 +158,7 @@ pyc_opcodes *opcode_3x(void) { def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 144); ret->extended_arg = 144; - r_list_purge (ret->opcode_arg_fmt); + rz_list_purge (ret->opcode_arg_fmt); add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg); return ret; diff --git a/libr/asm/arch/pyc/opcode_anal.c b/librz/asm/arch/pyc/opcode_anal.c similarity index 62% rename from libr/asm/arch/pyc/opcode_anal.c rename to librz/asm/arch/pyc/opcode_anal.c index 934ffd4a13..53e78f0e75 100644 --- a/libr/asm/arch/pyc/opcode_anal.c +++ b/librz/asm/arch/pyc/opcode_anal.c @@ -3,93 +3,93 @@ // The actual code of one opcode varies across the versions. // That's why I specify one opcode by its name, not its code. -static inline void anal_push(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) { +static inline void anal_push(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) { op->type = type; op->stackop = R_ANAL_STACK_INC; op->stackptr = OBJECT_SIZE_ON_STACK * push_cnt; } -static inline void anal_pop(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) { +static inline void anal_pop(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) { op->type = type; op->stackop = R_ANAL_STACK_INC; op->stackptr = -(OBJECT_SIZE_ON_STACK * push_cnt); } -static void anal_BEFORE_ASYNC_WITH(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BEFORE_ASYNC_WITH(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_BEGIN_FINALLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BEGIN_FINALLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_BINARY_ADD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_ADD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_ADD, 1); } -static void anal_BINARY_AND(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_AND(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_AND, 1); } -static void anal_BINARY_CALL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_CALL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h // I can not find this opcode even in v1.4 version source code. op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_BINARY_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1); } -static void anal_BINARY_FLOOR_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_FLOOR_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1); } -static void anal_BINARY_LSHIFT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_LSHIFT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SHL, 1); } -static void anal_BINARY_MATRIX_MULTIPLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_MATRIX_MULTIPLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_BINARY_MODULO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_MODULO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_MOD, 1); } -static void anal_BINARY_MULTIPLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_MULTIPLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_MUL, 1); } -static void anal_BINARY_OR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_OR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_OR, 1); } -static void anal_BINARY_POWER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_POWER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_BINARY_RSHIFT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_RSHIFT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SHR, 1); } -static void anal_BINARY_SUBSCR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_SUBSCR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_BINARY_SUBTRACT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_SUBTRACT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SUB, 1); } -static void anal_BINARY_TRUE_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_TRUE_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1); } -static void anal_BINARY_XOR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BINARY_XOR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_XOR, 1); } -static void anal_BREAK_LOOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BREAK_LOOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { //op->type = R_ANAL_OP_TYPE_CJMP; // This is actually a jump, but require further analysis op->type = R_ANAL_OP_TYPE_UNK; @@ -97,67 +97,67 @@ static void anal_BREAK_LOOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) op->fail = -1; } -static void anal_BUILD_CLASS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_CLASS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, 2); } -static void anal_BUILD_CONST_KEY_MAP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_CONST_KEY_MAP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg); } -static void anal_BUILD_FUNCTION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_FUNCTION(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_NEW; } -static void anal_BUILD_LIST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_LIST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg); } -static void anal_BUILD_LIST_UNPACK(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_LIST_UNPACK(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_MAP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_MAP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, 2 * oparg - 1); } -static void anal_BUILD_MAP_UNPACK(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_MAP_UNPACK(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_MAP_UNPACK_WITH_CALL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_MAP_UNPACK_WITH_CALL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg); } -static void anal_BUILD_SET(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_SET(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_SET_UNPACK(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_SET_UNPACK(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_SLICE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_SLICE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_STRING(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_STRING(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_TUPLE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_TUPLE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_TUPLE_UNPACK(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_TUPLE_UNPACK(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1); } -static void anal_BUILD_TUPLE_UNPACK_WITH_CALL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_BUILD_TUPLE_UNPACK_WITH_CALL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg); } -static void anal_CALL_FUNCTION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_FUNCTION(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // TODO // Get callee function from stack // Parse oparg by version info @@ -165,89 +165,89 @@ static void anal_CALL_FUNCTION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 opar op->jump = -1; } -static void anal_CALL_FUNCTION_EX(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_FUNCTION_EX(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ICALL; op->jump = -1; } -static void anal_CALL_FUNCTION_KW(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_FUNCTION_KW(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ICALL; op->jump = -1; } -static void anal_CALL_FUNCTION_VAR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_FUNCTION_VAR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ICALL; op->jump = -1; } -static void anal_CALL_FUNCTION_VAR_KW(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_FUNCTION_VAR_KW(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ICALL; op->jump = -1; } -static void anal_CALL_METHOD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_CALL_METHOD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ICALL; op->jump = -1; } -static void anal_DELETE_ATTR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_ATTR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_DEREF(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_DEREF(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_FAST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_FAST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_GLOBAL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_GLOBAL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_NAME(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_NAME(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_SLICE_0(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_SLICE_0(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_SLICE_1(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_SLICE_1(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_SLICE_2(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_SLICE_2(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_SLICE_3(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_SLICE_3(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DELETE_SUBSCR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DELETE_SUBSCR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_DUP_TOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DUP_TOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 1); } -static void anal_DUP_TOPX(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DUP_TOPX(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 1); } -static void anal_DUP_TOP_TWO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_DUP_TOP_TWO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 2); } -static void anal_END_ASYNC_FOR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_END_ASYNC_FOR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // If TOS is StopAsyncIteration pop 7 values from the stack and restore the exception state using the second three of them. op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_END_FINALLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_END_FINALLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { //op->type = R_ANAL_OP_TYPE_CJMP; // This is actually a jump, but require further analysis op->type = R_ANAL_OP_TYPE_UNK; @@ -255,15 +255,15 @@ static void anal_END_FINALLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) op->fail = -1; } -static void anal_EXEC_STMT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_EXEC_STMT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_EXTENDED_ARG(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_EXTENDED_ARG(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_FORMAT_VALUE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_FORMAT_VALUE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; if ((oparg & 0x04) == 0x04) { op->stackop = R_ANAL_STACK_INC; @@ -271,458 +271,458 @@ static void anal_FORMAT_VALUE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg } } -static void anal_FOR_LOOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_FOR_LOOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/b2b1ed17819ecb24a78d07d3ff1e8e6bc6137721/Python/ceval.c#L1499 op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_GET_AITER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_GET_AITER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_GET_ANEXT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_GET_ANEXT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_GET_AWAITABLE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_GET_AWAITABLE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_GET_ITER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_GET_ITER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_GET_YIELD_FROM_ITER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_GET_YIELD_FROM_ITER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_IMPORT_FROM(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_IMPORT_FROM(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_IMPORT_NAME(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_IMPORT_NAME(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_IMPORT_STAR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_IMPORT_STAR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_INPLACE_ADD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_ADD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_ADD; } -static void anal_INPLACE_AND(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_AND(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_AND; } -static void anal_INPLACE_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_DIV; } -static void anal_INPLACE_FLOOR_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_FLOOR_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_DIV; } -static void anal_INPLACE_LSHIFT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_LSHIFT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_SHL; } -static void anal_INPLACE_MATRIX_MULTIPLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_MATRIX_MULTIPLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_INPLACE_MODULO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_MODULO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_MOD; } -static void anal_INPLACE_MULTIPLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_MULTIPLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_MUL; } -static void anal_INPLACE_OR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_OR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_OR; } -static void anal_INPLACE_POWER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_POWER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_INPLACE_RSHIFT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_RSHIFT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_SHR; } -static void anal_INPLACE_SUBTRACT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_SUBTRACT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_SUB; } -static void anal_INPLACE_TRUE_DIVIDE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_TRUE_DIVIDE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_DIV; } -static void anal_INPLACE_XOR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_INPLACE_XOR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_XOR; } -static void anal_LIST_APPEND(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LIST_APPEND(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_ASSERTION_ERROR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_ASSERTION_ERROR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_ATTR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_ATTR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_LOAD_BUILD_CLASS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_BUILD_CLASS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_CLASSDEREF(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_CLASSDEREF(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_CLOSURE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_CLOSURE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_CONST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_CONST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_DEREF(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_DEREF(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_FAST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_FAST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_GLOBAL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_GLOBAL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_GLOBALS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_GLOBALS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/24260ec91623c18569225229d5becb852010ae2c/Include/opcode.h#L80 // Can't find this opcode op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_LOAD_LOCAL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_LOCAL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_LOCALS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_LOCALS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_METHOD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_METHOD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_LOAD_NAME(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_LOAD_NAME(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_MAKE_CLOSURE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_MAKE_CLOSURE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg); } -static void anal_MAKE_FUNCTION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_MAKE_FUNCTION(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg); } -static void anal_MAP_ADD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_MAP_ADD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_NOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_NOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_NOP; } -static void anal_POP_BLOCK(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_POP_BLOCK(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1); } -static void anal_POP_EXCEPT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_POP_EXCEPT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1); } -static void anal_POP_FINALLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_POP_FINALLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // FIXME // POP_FINALLY will pop 6 elements if TOS is an exception type anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1); } -static void anal_POP_TOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_POP_TOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1); } -static void anal_PRINT_EXPR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_PRINT_EXPR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_PRINT_ITEM(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_PRINT_ITEM(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_PRINT_ITEM_TO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_PRINT_ITEM_TO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2); } -static void anal_PRINT_NEWLINE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_PRINT_NEWLINE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_PRINT_NEWLINE_TO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_PRINT_NEWLINE_TO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_RAISE_EXCEPTION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_RAISE_EXCEPTION(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/6c3a3aa17b028f6b93067083d32c7eaa4338757c/Include/opcode.h#L89 // Can't find this opcode op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_RAISE_VARARGS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_RAISE_VARARGS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg); } -static void anal_RERAISE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_RERAISE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3); } -static void anal_RESERVE_FAST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_RESERVE_FAST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/6c3a3aa17b028f6b93067083d32c7eaa4338757c/Include/opcode.h#L134 // Can't find this opcode op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_RETURN_VALUE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_RETURN_VALUE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_RET; op->stackop = R_ANAL_STACK_INC; op->stackptr = -OBJECT_SIZE_ON_STACK; op->eob = true; } -static void anal_ROT_FOUR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_ROT_FOUR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // Lifts second, third and forth stack items one position up, moves top down to position four. op->type = R_ANAL_OP_TYPE_XCHG; } -static void anal_ROT_THREE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_ROT_THREE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // Lifts second and third stack item one position up, moves top down to position three. op->type = R_ANAL_OP_TYPE_XCHG; } -static void anal_ROT_TWO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_ROT_TWO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // Swaps the two top-most stack items. op->type = R_ANAL_OP_TYPE_XCHG; } -static void anal_SETUP_ANNOTATIONS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_ANNOTATIONS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_SET_ADD(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SET_ADD(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_SET_FUNC_ARGS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SET_FUNC_ARGS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/v1.4/Python/ceval.c // Can't find this opcode op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_SET_LINENO(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SET_LINENO(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_SLICE_0(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SLICE_0(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_SLICE_1(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SLICE_1(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_SLICE_2(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SLICE_2(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_SLICE_3(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SLICE_3(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2); } -static void anal_STOP_CODE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STOP_CODE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_TRAP; } -static void anal_STORE_ANNOTATION(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_ANNOTATION(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_STORE_ATTR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_ATTR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_STORE_DEREF(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_DEREF(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_STORE_FAST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_FAST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_STORE_GLOBAL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_GLOBAL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_STORE_LOCALS(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_LOCALS(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_STORE_MAP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_MAP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2); } -static void anal_STORE_NAME(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_NAME(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_STORE_SLICE_0(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_SLICE_0(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2); } -static void anal_STORE_SLICE_1(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_SLICE_1(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3); } -static void anal_STORE_SLICE_2(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_SLICE_2(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3); } -static void anal_STORE_SLICE_3(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_SLICE_3(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 4); } -static void anal_STORE_SUBSCR(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_STORE_SUBSCR(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3); } -static void anal_UNARY_CALL(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_CALL(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h // I can not find this opcode even in v1.4 version source code. op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_UNARY_CONVERT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_CONVERT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_UNARY_INVERT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_INVERT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_NOT; } -static void anal_UNARY_NEGATIVE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_NEGATIVE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_UNARY_NOT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_NOT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_NOT; } -static void anal_UNARY_POSITIVE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNARY_POSITIVE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_UNPACK_ARG(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_ARG(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1); } -static void anal_UNPACK_EX(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_EX(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, (oparg & 0xFF) + (oparg >> 8)); } -static void anal_UNPACK_LIST(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_LIST(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1); } -static void anal_UNPACK_SEQUENCE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_SEQUENCE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1); } -static void anal_UNPACK_TUPLE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_TUPLE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1); } -static void anal_UNPACK_VARARG(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_UNPACK_VARARG(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h // I can not find this opcode even in v1.4 version source code. op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_WITH_CLEANUP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_WITH_CLEANUP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // Need the value on stack op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_WITH_CLEANUP_FINISH(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_WITH_CLEANUP_FINISH(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2); } -static void anal_WITH_CLEANUP_START(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_WITH_CLEANUP_START(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { // Need the value on stack op->type = R_ANAL_OP_TYPE_UNK; } -static void anal_WITH_EXCEPT_START(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_WITH_EXCEPT_START(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_YIELD_FROM(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_YIELD_FROM(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_YIELD_VALUE(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_YIELD_VALUE(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1); } -static void anal_FOR_ITER(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_FOR_ITER(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_CJMP; ut64 mid = op->jump; op->jump = op->fail; op->fail = mid; } -static void anal_SETUP_LOOP(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_LOOP(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { ut64 mid = op->jump; op->jump = op->fail; op->fail = mid; } -static void anal_SETUP_EXCEPT(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_EXCEPT(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { ut64 mid = op->jump; op->jump = op->fail; op->fail = mid; } -static void anal_SETUP_FINALLY(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_FINALLY(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { ut64 mid = op->jump; op->jump = op->fail; op->fail = mid; } -static void anal_SETUP_WITH(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_WITH(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_CJMP; ut64 mid = op->jump; op->jump = op->fail; op->fail = mid; } -static void anal_SETUP_ASYNC_WITH(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +static void anal_SETUP_ASYNC_WITH(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { op->type = R_ANAL_OP_TYPE_CJMP; ut64 mid = op->jump; op->jump = op->fail; @@ -896,7 +896,7 @@ static op_anal_func op_anal[] = { { "SETUP_ASYNC_WITH", anal_SETUP_ASYNC_WITH }, }; -void anal_pyc_op(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { +void anal_pyc_op(RzAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) { size_t i; for (i = 0; i < (sizeof (op_anal) / sizeof (op_anal_func)); i++) { if (!strcmp (op_anal[i].op_name, op_obj->op_name)) { diff --git a/libr/asm/arch/pyc/opcode_arg_fmt.c b/librz/asm/arch/pyc/opcode_arg_fmt.c similarity index 67% rename from libr/asm/arch/pyc/opcode_arg_fmt.c rename to librz/asm/arch/pyc/opcode_arg_fmt.c index d8f54adf4c..f0522c7cb0 100644 --- a/libr/asm/arch/pyc/opcode_arg_fmt.c +++ b/librz/asm/arch/pyc/opcode_arg_fmt.c @@ -1,41 +1,41 @@ #include "opcode.h" const char *format_extended_arg(ut32 oparg) { - return r_str_newf ("%lu", oparg * (1 << 16)); + return rz_str_newf ("%lu", oparg * (1 << 16)); } const char *format_CALL_FUNCTION_pos_name_encoded(ut32 oparg) { ut32 pos_args = oparg & 0xFF; ut32 name = (oparg >> 8) & 0xFF; - return r_str_newf ("%u positional, %u named", pos_args, name); + return rz_str_newf ("%u positional, %u named", pos_args, name); } const char *format_MAKE_FUNCTION_arg_3x(ut32 oparg) { ut32 pos_args = oparg & 0xFF; ut32 name_default = (oparg >> 8) & 0xFF; ut32 annotate_args = (oparg >> 16) & 0x7FFF; - return r_str_newf ("%u positional, %u name and default, %u annotations", pos_args, name_default, annotate_args); + return rz_str_newf ("%u positional, %u name and default, %u annotations", pos_args, name_default, annotate_args); } const char *format_CALL_FUNCTION_KW_36(ut32 oparg) { - return r_str_newf ("%u total positional and keyword args", oparg); + return rz_str_newf ("%u total positional and keyword args", oparg); } const char *format_CALL_FUNCTION_EX_36(ut32 oparg) { - return r_str_new ((oparg & 0x01)? "keyword args": ""); + return rz_str_new ((oparg & 0x01)? "keyword args": ""); } static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" }; const char *format_MAKE_FUNCTION_arg_36(ut32 oparg) { size_t i; - char *ret = r_str_new (" "); + char *ret = rz_str_new (" "); for (i = 0; i < sizeof (MAKE_FUNCTION_FLAGS) / sizeof (char *); ++i) { if (oparg & 0x1) { - r_str_appendf (ret, ", %s", MAKE_FUNCTION_FLAGS[i]); + rz_str_appendf (ret, ", %s", MAKE_FUNCTION_FLAGS[i]); } else { free (ret); - ret = r_str_new (MAKE_FUNCTION_FLAGS[i]); + ret = rz_str_new (MAKE_FUNCTION_FLAGS[i]); } oparg >>= 1; } @@ -60,9 +60,9 @@ const char *format_value_flags_36(ut32 oparg) { // empty fmt_spec. ret = ""; } - return r_str_new (ret); + return rz_str_new (ret); } const char *format_extended_arg_36(ut32 oparg) { - return r_str_newf ("%lu", oparg * (1 << 8)); + return rz_str_newf ("%lu", oparg * (1 << 8)); } diff --git a/libr/asm/arch/pyc/pyc_dis.c b/librz/asm/arch/pyc/pyc_dis.c similarity index 55% rename from libr/asm/arch/pyc/pyc_dis.c rename to librz/asm/arch/pyc/pyc_dis.c index 5db7de7ef7..ec8990aa6e 100644 --- a/libr/asm/arch/pyc/pyc_dis.c +++ b/librz/asm/arch/pyc/pyc_dis.c @@ -4,15 +4,15 @@ static const char *cmp_op[] = { "<", "<=", "==", "!=", ">", ">=", "in", "not in", "is", "is not", "exception match", "BAD" }; -static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table, RList *freevars, RList *cellvars, RList *opcode_arg_fmt); +static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RzList *names, RzList *consts, RzList *varnames, RzList *interned_table, RzList *freevars, RzList *cellvars, RzList *opcode_arg_fmt); -int r_pyc_disasm(RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interned_table, ut64 pc, pyc_opcodes *ops) { +int rz_pyc_disasm(RzAsmOp *opstruct, const ut8 *code, RzList *cobjs, RzList *interned_table, ut64 pc, pyc_opcodes *ops) { pyc_code_object *cobj = NULL, *t = NULL; ut32 extended_arg = 0, i = 0, oparg; st64 start_offset, end_offset; - RListIter *iter = NULL; + RzListIter *iter = NULL; - r_list_foreach (cobjs, iter, t) { + rz_list_foreach (cobjs, iter, t) { start_offset = t->start_offset; end_offset = t->end_offset; if (start_offset <= pc && pc < end_offset) { // pc in [start_offset, end_offset) @@ -23,16 +23,16 @@ int r_pyc_disasm(RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interne if (cobj) { /* TODO: adding line number and offset */ - RList *varnames = cobj->varnames->data; - RList *consts = cobj->consts->data; - RList *names = cobj->names->data; - RList *freevars = cobj->freevars->data; - RList *cellvars = cobj->cellvars->data; + RzList *varnames = cobj->varnames->data; + RzList *consts = cobj->consts->data; + RzList *names = cobj->names->data; + RzList *freevars = cobj->freevars->data; + RzList *cellvars = cobj->cellvars->data; ut8 op = code[i]; i++; char *name = ops->opcodes[op].op_name; - r_strbuf_set (&opstruct->buf_asm, name); + rz_strbuf_set (&opstruct->buf_asm, name); if (!name) { return 0; } @@ -54,7 +54,7 @@ int r_pyc_disasm(RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interne } const char *arg = parse_arg (&ops->opcodes[op], oparg, names, consts, varnames, interned_table, freevars, cellvars, ops->opcode_arg_fmt); if (arg != NULL) { - r_strbuf_appendf (&opstruct->buf_asm, "%20s", arg); + rz_strbuf_appendf (&opstruct->buf_asm, "%20s", arg); free ((char *)arg); } } else if (ops->bits == 8) { @@ -66,23 +66,23 @@ int r_pyc_disasm(RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interne return 0; } -static char *generic_array_obj_to_string(RList *l); +static char *generic_array_obj_to_string(RzList *l); -static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table, RList *freevars, RList *cellvars, RList *opcode_arg_fmt) { +static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RzList *names, RzList *consts, RzList *varnames, RzList *interned_table, RzList *freevars, RzList *cellvars, RzList *opcode_arg_fmt) { pyc_object *t = NULL; const char *arg = NULL; pyc_code_object *tmp_cobj; pyc_arg_fmt *fmt; - RListIter *i = NULL; + RzListIter *i = NULL; // version-specific formatter for certain opcodes - r_list_foreach (opcode_arg_fmt, i, fmt) + rz_list_foreach (opcode_arg_fmt, i, fmt) if (!strcmp (fmt->op_name, op->op_name)) { return fmt->formatter (oparg); } if (op->type & HASCONST) { - t = (pyc_object *)r_list_get_n (consts, oparg); + t = (pyc_object *)rz_list_get_n (consts, oparg); if (t == NULL) { return NULL; } @@ -90,7 +90,7 @@ static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RList *names, RL case TYPE_CODE_v0: case TYPE_CODE_v1: tmp_cobj = t->data; - arg = r_str_newf ("CodeObject(%s) from %s", tmp_cobj->name->data, tmp_cobj->filename->data); + arg = rz_str_newf ("CodeObject(%s) from %s", tmp_cobj->name->data, tmp_cobj->filename->data); break; case TYPE_TUPLE: case TYPE_SET: @@ -102,78 +102,78 @@ static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RList *names, RL case TYPE_STRING: case TYPE_INTERNED: case TYPE_STRINGREF: - arg = r_str_newf ("'%s'", t->data); + arg = rz_str_newf ("'%s'", t->data); break; default: - arg = r_str_new (t->data); + arg = rz_str_new (t->data); } } if (op->type & HASNAME) { - t = (pyc_object *)r_list_get_n (names, oparg); + t = (pyc_object *)rz_list_get_n (names, oparg); if (t == NULL) { return NULL; } - arg = r_str_new (t->data); + arg = rz_str_new (t->data); } if ((op->type & HASJREL) || (op->type & HASJABS)) { - arg = r_str_newf ("%u", oparg); + arg = rz_str_newf ("%u", oparg); } if (op->type & HASLOCAL) { - t = (pyc_object *)r_list_get_n (varnames, oparg); + t = (pyc_object *)rz_list_get_n (varnames, oparg); if (!t) return NULL; - arg = r_str_new (t->data); + arg = rz_str_new (t->data); } if (op->type & HASCOMPARE) { - arg = r_str_new (cmp_op[oparg]); + arg = rz_str_new (cmp_op[oparg]); } if (op->type & HASFREE) { if (!cellvars || !freevars) { - arg = r_str_newf ("%u", oparg); + arg = rz_str_newf ("%u", oparg); return arg; } - if (oparg < r_list_length (cellvars)) { - t = (pyc_object *)r_list_get_n (cellvars, oparg); - } else if ((oparg - r_list_length (cellvars)) < r_list_length (freevars)) { - t = (pyc_object *)r_list_get_n (freevars, oparg); + if (oparg < rz_list_length (cellvars)) { + t = (pyc_object *)rz_list_get_n (cellvars, oparg); + } else if ((oparg - rz_list_length (cellvars)) < rz_list_length (freevars)) { + t = (pyc_object *)rz_list_get_n (freevars, oparg); } else { - arg = r_str_newf ("%u", oparg); + arg = rz_str_newf ("%u", oparg); return arg; } if (!t) { return NULL; } - arg = r_str_new (t->data); + arg = rz_str_new (t->data); } if (op->type & HASNARGS) { - arg = r_str_newf ("%u", oparg); + arg = rz_str_newf ("%u", oparg); } if (op->type & HASVARGS) { - arg = r_str_newf ("%u", oparg); + arg = rz_str_newf ("%u", oparg); } return arg; } -static char *generic_array_obj_to_string(RList *l) { - RListIter *iter = NULL; +static char *generic_array_obj_to_string(RzList *l) { + RzListIter *iter = NULL; pyc_object *e = NULL; - RStrBuf *rbuf = r_strbuf_new (NULL); + RStrBuf *rbuf = rz_strbuf_new (NULL); - r_list_foreach (l, iter, e) { - r_strbuf_append (rbuf, e->data); - r_strbuf_append (rbuf, ","); + rz_list_foreach (l, iter, e) { + rz_strbuf_append (rbuf, e->data); + rz_strbuf_append (rbuf, ","); } - char *buf = r_strbuf_get (rbuf); + char *buf = rz_strbuf_get (rbuf); /* remove last , */ buf[strlen (buf) - 1] = '\0'; - char *r = r_str_newf ("(%s)", buf); + char *r = rz_str_newf ("(%s)", buf); - r_strbuf_free (rbuf); + rz_strbuf_free (rbuf); return r; } diff --git a/libr/asm/arch/pyc/pyc_dis.h b/librz/asm/arch/pyc/pyc_dis.h similarity index 86% rename from libr/asm/arch/pyc/pyc_dis.h rename to librz/asm/arch/pyc/pyc_dis.h index 84f88960c7..fbb394d355 100644 --- a/libr/asm/arch/pyc/pyc_dis.h +++ b/librz/asm/arch/pyc/pyc_dis.h @@ -3,10 +3,10 @@ #ifndef PYC_DIS_H #define PYC_DIS_H -#include -#include -#include -#include +#include +#include +#include +#include #include "opcode.h" @@ -74,6 +74,6 @@ typedef struct { st64 end_offset; } pyc_code_object; -int r_pyc_disasm(RAsmOp *op, const ut8 *buf, RList *cobjs, RList *interned_table, ut64 pc, pyc_opcodes *opcodes); +int rz_pyc_disasm(RzAsmOp *op, const ut8 *buf, RzList *cobjs, RzList *interned_table, ut64 pc, pyc_opcodes *opcodes); #endif diff --git a/libr/asm/arch/riscv/riscv-opc.c b/librz/asm/arch/riscv/riscv-opc.c similarity index 100% rename from libr/asm/arch/riscv/riscv-opc.c rename to librz/asm/arch/riscv/riscv-opc.c diff --git a/libr/asm/arch/riscv/riscv-opc.h b/librz/asm/arch/riscv/riscv-opc.h similarity index 100% rename from libr/asm/arch/riscv/riscv-opc.h rename to librz/asm/arch/riscv/riscv-opc.h diff --git a/libr/asm/arch/riscv/riscv.c b/librz/asm/arch/riscv/riscv.c similarity index 95% rename from libr/asm/arch/riscv/riscv.c rename to librz/asm/arch/riscv/riscv.c index 07861cec7c..81b9cf69c9 100644 --- a/libr/asm/arch/riscv/riscv.c +++ b/librz/asm/arch/riscv/riscv.c @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include #include #include "riscv-opc.h" @@ -285,7 +285,7 @@ static struct riscv_opcode *get_opcode (insn_t word) { return (struct riscv_opcode *)riscv_hash[OP_HASH_IDX (word)]; } -static int riscv_disassemble(RAsm *a, RAsmOp *rop, insn_t word, int xlen, int len) { +static int riscv_disassemble(RzAsm *a, RzAsmOp *rop, insn_t word, int xlen, int len) { const bool no_alias = false; const struct riscv_opcode *op = get_opcode (word); if (!op) { @@ -302,17 +302,17 @@ static int riscv_disassemble(RAsm *a, RAsmOp *rop, insn_t word, int xlen, int le continue; } if (op->name && op->args) { - r_asm_op_set_asm (rop, op->name); - get_insn_args (r_asm_op_get_asm (rop), op->args, word, a->pc); + rz_asm_op_set_asm (rop, op->name); + get_insn_args (rz_asm_op_get_asm (rop), op->args, word, a->pc); return 0; } - r_asm_op_set_asm (rop, sdb_fmt ("invalid word(%"PFMT64x")", (ut64)word)); + rz_asm_op_set_asm (rop, sdb_fmt ("invalid word(%"PFMT64x")", (ut64)word)); return -1; } return 0; } -static int riscv_dis(RAsm *a, RAsmOp *rop, const ut8 *buf, ut64 len) { +static int riscv_dis(RzAsm *a, RzAsmOp *rop, const ut8 *buf, ut64 len) { insn_t insn = {0}; if (len < 2) { return -1; diff --git a/libr/asm/arch/riscv/riscv.h b/librz/asm/arch/riscv/riscv.h similarity index 100% rename from libr/asm/arch/riscv/riscv.h rename to librz/asm/arch/riscv/riscv.h diff --git a/libr/asm/arch/rsp/rsp_idec.c b/librz/asm/arch/rsp/rsp_idec.c similarity index 98% rename from libr/asm/arch/rsp/rsp_idec.c rename to librz/asm/arch/rsp/rsp_idec.c index c03d409fc2..1c8d054aa2 100644 --- a/libr/asm/arch/rsp/rsp_idec.c +++ b/librz/asm/arch/rsp/rsp_idec.c @@ -392,14 +392,14 @@ rsp_instruction rsp_instruction_decode(ut64 pc, ut32 iw) { int opnd; const rsp_instruction_priv* priv = rsp_decode_priv (iw); - rsp_instruction r_instr; + rsp_instruction rz_instr; - r_instr.mnemonic = priv->mnemonic; - r_instr.opcode = priv->opcode; - r_instr.noperands = priv->noperands; - for (opnd = 0; opnd < r_instr.noperands; opnd++) { - r_instr.operands[opnd] = rsp_operand_decode (pc, iw, &priv->odecs[opnd]); + rz_instr.mnemonic = priv->mnemonic; + rz_instr.opcode = priv->opcode; + rz_instr.noperands = priv->noperands; + for (opnd = 0; opnd < rz_instr.noperands; opnd++) { + rz_instr.operands[opnd] = rsp_operand_decode (pc, iw, &priv->odecs[opnd]); } - return r_instr; + return rz_instr; } diff --git a/libr/asm/arch/rsp/rsp_idec.h b/librz/asm/arch/rsp/rsp_idec.h similarity index 99% rename from libr/asm/arch/rsp/rsp_idec.h rename to librz/asm/arch/rsp/rsp_idec.h index bb3e665e17..150b25fc3a 100644 --- a/libr/asm/arch/rsp/rsp_idec.h +++ b/librz/asm/arch/rsp/rsp_idec.h @@ -2,7 +2,7 @@ #ifndef R_ASM_ARCH_RSP_RSP_IDEC_H #define R_ASM_ARCH_RSP_RSP_IDEC_H -#include +#include extern const char* rsp_gp_reg_soft_names[]; diff --git a/libr/asm/arch/sh/gnu/sh-dis.c b/librz/asm/arch/sh/gnu/sh-dis.c similarity index 99% rename from libr/asm/arch/sh/gnu/sh-dis.c rename to librz/asm/arch/sh/gnu/sh-dis.c index 199cf3d003..0b069e0bb0 100644 --- a/libr/asm/arch/sh/gnu/sh-dis.c +++ b/librz/asm/arch/sh/gnu/sh-dis.c @@ -338,7 +338,7 @@ print_insn_shx (bfd_vma memaddr, struct disassemble_info *info) size = 4; } - //read_memory_func() is broken on ALL GNU disassemblers ! see libr/asm/p/asm_sh.c + //read_memory_func() is broken on ALL GNU disassemblers ! see librz/asm/p/asm_sh.c status = info->read_memory_func (disp_pc_addr, bytes, size, info); if (status != 0) { info->memory_error_func (status, memaddr, info); diff --git a/libr/asm/arch/sh/gnu/sh-opc.h b/librz/asm/arch/sh/gnu/sh-opc.h similarity index 100% rename from libr/asm/arch/sh/gnu/sh-opc.h rename to librz/asm/arch/sh/gnu/sh-opc.h diff --git a/libr/asm/arch/snes/snes_op_table.h b/librz/asm/arch/snes/snes_op_table.h similarity index 99% rename from libr/asm/arch/snes/snes_op_table.h rename to librz/asm/arch/snes/snes_op_table.h index 33a3743cc9..9ac9e07d78 100644 --- a/libr/asm/arch/snes/snes_op_table.h +++ b/librz/asm/arch/snes/snes_op_table.h @@ -3,7 +3,7 @@ #ifndef SNES_OP_TABLE_H #define SNES_OP_TABLE_H -#include +#include enum { SNES_OP_8BIT = 1, diff --git a/libr/asm/arch/snes/snesdis.c b/librz/asm/arch/snes/snesdis.c similarity index 86% rename from libr/asm/arch/snes/snesdis.c rename to librz/asm/arch/snes/snesdis.c index 9134f7ec76..d5a604abaf 100644 --- a/libr/asm/arch/snes/snesdis.c +++ b/librz/asm/arch/snes/snesdis.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2015-2018 - condret, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "snes_op_table.h" -static int snesDisass(int M_flag, int X_flag, ut64 pc, RAsmOp *op, const ut8 *buf, int len){ +static int snesDisass(int M_flag, int X_flag, ut64 pc, RzAsmOp *op, const ut8 *buf, int len){ snes_op_t *s_op = &snes_op[buf[0]]; int op_len = snes_op_get_size (M_flag, X_flag, s_op); if (len < op_len) { @@ -52,6 +52,6 @@ static int snesDisass(int M_flag, int X_flag, ut64 pc, RAsmOp *op, const ut8 *bu } break; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); return op_len; } diff --git a/libr/asm/arch/sparc/gnu/sparc-dis.c b/librz/asm/arch/sparc/gnu/sparc-dis.c similarity index 100% rename from libr/asm/arch/sparc/gnu/sparc-dis.c rename to librz/asm/arch/sparc/gnu/sparc-dis.c diff --git a/libr/asm/arch/sparc/gnu/sparc-opc.c b/librz/asm/arch/sparc/gnu/sparc-opc.c similarity index 100% rename from libr/asm/arch/sparc/gnu/sparc-opc.c rename to librz/asm/arch/sparc/gnu/sparc-opc.c diff --git a/libr/asm/arch/spc700/spc700_opcode_table.h b/librz/asm/arch/spc700/spc700_opcode_table.h similarity index 99% rename from libr/asm/arch/spc700/spc700_opcode_table.h rename to librz/asm/arch/spc700/spc700_opcode_table.h index 8e01beb784..1badeb21cf 100644 --- a/libr/asm/arch/spc700/spc700_opcode_table.h +++ b/librz/asm/arch/spc700/spc700_opcode_table.h @@ -1,4 +1,4 @@ -#include +#include #define SPC_OP 0 #define SPC_ARG8_1 1 diff --git a/libr/asm/arch/spc700/spc700dis.c b/librz/asm/arch/spc700/spc700dis.c similarity index 85% rename from libr/asm/arch/spc700/spc700dis.c rename to librz/asm/arch/spc700/spc700dis.c index 1764142b32..e48c003b1e 100644 --- a/libr/asm/arch/spc700/spc700dis.c +++ b/librz/asm/arch/spc700/spc700dis.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2014 - condret@runas-racer.com */ -#include -#include +#include +#include #include #include #include "spc700_opcode_table.h" @@ -19,7 +19,7 @@ static int spc700OpLength(int spcoptype){ return 0; } -static int spc700Disass(RAsmOp *op, const ut8 *buf, int len) { +static int spc700Disass(RzAsmOp *op, const ut8 *buf, int len) { int foo = spc700OpLength (spc_op_table[buf[0]].type); if (len < foo) { return 0; @@ -39,6 +39,6 @@ static int spc700Disass(RAsmOp *op, const ut8 *buf, int len) { buf_asm = sdb_fmt (spc_op_table[buf[0]].name, buf[1]+0x100*buf[2]); break; } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); return foo; } diff --git a/libr/asm/arch/tms320/c55x/table.h b/librz/asm/arch/tms320/c55x/table.h similarity index 100% rename from libr/asm/arch/tms320/c55x/table.h rename to librz/asm/arch/tms320/c55x/table.h diff --git a/libr/asm/arch/tms320/c55x_plus/c55plus.c b/librz/asm/arch/tms320/c55x_plus/c55plus.c similarity index 94% rename from libr/asm/arch/tms320/c55x_plus/c55plus.c rename to librz/asm/arch/tms320/c55x_plus/c55plus.c index 2cbfb2bd82..18dd562436 100644 --- a/libr/asm/arch/tms320/c55x_plus/c55plus.c +++ b/librz/asm/arch/tms320/c55x_plus/c55plus.c @@ -4,9 +4,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #define USE_DECODE #include "decode.h" diff --git a/libr/asm/arch/tms320/c55x_plus/c55plus.h b/librz/asm/arch/tms320/c55x_plus/c55plus.h similarity index 85% rename from libr/asm/arch/tms320/c55x_plus/c55plus.h rename to librz/asm/arch/tms320/c55x_plus/c55plus.h index 32d6a704d3..bd1a2ec7b4 100644 --- a/libr/asm/arch/tms320/c55x_plus/c55plus.h +++ b/librz/asm/arch/tms320/c55x_plus/c55plus.h @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include "../tms320_p.h" #include "../tms320_dasm.h" diff --git a/libr/asm/arch/tms320/c55x_plus/c55plus_decode.c b/librz/asm/arch/tms320/c55x_plus/c55plus_decode.c similarity index 91% rename from libr/asm/arch/tms320/c55x_plus/c55plus_decode.c rename to librz/asm/arch/tms320/c55x_plus/c55plus_decode.c index 628c1bf7cc..edac773262 100644 --- a/libr/asm/arch/tms320/c55x_plus/c55plus_decode.c +++ b/librz/asm/arch/tms320/c55x_plus/c55plus_decode.c @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include "ins.h" #include "decode.h" @@ -19,27 +19,27 @@ extern ut32 ins_buff_len; static ut32 get_q_bits(ut32 val, char *ins, ut32 ins_len, int *err_code) { ut32 res = 0; - if (!r_str_ncasecmp(ins, "q_MMAP", 6)) { + if (!rz_str_ncasecmp(ins, "q_MMAP", 6)) { res = val & 1; - } else if (!r_str_ncasecmp(ins, "q_LOCK", 6)) { + } else if (!rz_str_ncasecmp(ins, "q_LOCK", 6)) { res = val & 1; - } else if (!r_str_ncasecmp(ins, "q_LINR", 6)) { + } else if (!rz_str_ncasecmp(ins, "q_LINR", 6)) { res = (val >> 2) & 1; - } else if (!r_str_ncasecmp(ins, "q_CIRC", 6)) { + } else if (!rz_str_ncasecmp(ins, "q_CIRC", 6)) { res = (val >> 3) & 1; - } else if (!r_str_ncasecmp(ins, "q_PORT_READ", 11)) { + } else if (!rz_str_ncasecmp(ins, "q_PORT_READ", 11)) { res = (val >> 4) & 1; - } else if (!r_str_ncasecmp(ins, "q_PORT_WRITE", 12)) { + } else if (!rz_str_ncasecmp(ins, "q_PORT_WRITE", 12)) { res = (val >> 5) & 1; - } else if (!r_str_ncasecmp(ins, "q_XPORT_READ", 12)) { + } else if (!rz_str_ncasecmp(ins, "q_XPORT_READ", 12)) { res = (val >> 6) & 1; - } else if (!r_str_ncasecmp(ins, "q_XPORT_WRITE", 13)) { + } else if (!rz_str_ncasecmp(ins, "q_XPORT_WRITE", 13)) { res = (val >> 7) & 1; - } else if (!r_str_ncasecmp(ins, "q_SAT", 5)) { + } else if (!rz_str_ncasecmp(ins, "q_SAT", 5)) { res = (val >> 8) & 1; - } else if (!r_str_ncasecmp(ins, "q_XC0", 5)) { + } else if (!rz_str_ncasecmp(ins, "q_XC0", 5)) { res = (val >> 9) & 1; - } else if (!r_str_ncasecmp(ins, "q_XC1", 5)) { + } else if (!rz_str_ncasecmp(ins, "q_XC1", 5)) { res = (val >> 10) & 1; } else { /* INVALID CONDITION */ @@ -128,7 +128,7 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, ((ins_bits & 1) << 6)); break; case 100: - if (r_str_ncasecmp(reg_arg, "d(ALLx", 6)) { + if (rz_str_ncasecmp(reg_arg, "d(ALLx", 6)) { fprintf(stderr, "invalid register! %s\n", reg_arg); *err_code = -1; return NULL; @@ -139,7 +139,7 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, } break; case 41: - if (r_str_ncasecmp(reg_arg, ")ALLx", 5)) { + if (rz_str_ncasecmp(reg_arg, ")ALLx", 5)) { fprintf(stderr, "invalid register! %s\n", reg_arg); *err_code = -1; return NULL; @@ -150,13 +150,13 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, } break; case 65: - if (!r_str_ncasecmp(reg_arg, "ACLH", 4)) { + if (!rz_str_ncasecmp(reg_arg, "ACLH", 4)) { res = get_reg_name_1(ins_bits + 64); - } else if (!r_str_ncasecmp(reg_arg, "ACxP", 4)) { + } else if (!rz_str_ncasecmp(reg_arg, "ACxP", 4)) { res = get_reg_name_1(ins_bits + 1); - } else if (!r_str_ncasecmp(reg_arg, "ACx", 3) || - !r_str_ncasecmp(reg_arg, "ADR", 3) || - !r_str_ncasecmp(reg_arg, "ALL", 3) /* 430ADC */ + } else if (!rz_str_ncasecmp(reg_arg, "ACx", 3) || + !rz_str_ncasecmp(reg_arg, "ADR", 3) || + !rz_str_ncasecmp(reg_arg, "ALL", 3) /* 430ADC */ ) { res = get_reg_name_1(ins_bits); } @@ -168,7 +168,7 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, res = get_reg_name_1(ins_bits + 32); break; case 77: - if (!r_str_ncasecmp(reg_arg, "MA", 2) || !r_str_ncasecmp(reg_arg, "MR", 2)) { + if (!rz_str_ncasecmp(reg_arg, "MA", 2) || !rz_str_ncasecmp(reg_arg, "MR", 2)) { res = get_reg_name_1(ins_bits); } else { res = get_reg_name_2(ins_bits); @@ -178,11 +178,11 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, res = get_reg_name_1(ins_bits); break; case 82: - if (!r_str_ncasecmp(reg_arg, "RA", 2) || !r_str_ncasecmp(reg_arg, "RL", 2)) { + if (!rz_str_ncasecmp(reg_arg, "RA", 2) || !rz_str_ncasecmp(reg_arg, "RL", 2)) { res = get_reg_name_1(ins_bits); - } else if (!r_str_ncasecmp(reg_arg, "RLP", 3) || !r_str_ncasecmp(reg_arg, "RxP", 3)) { + } else if (!rz_str_ncasecmp(reg_arg, "RLP", 3) || !rz_str_ncasecmp(reg_arg, "RxP", 3)) { res = get_reg_name_1(ins_bits + 1); - } else if (!r_str_ncasecmp(reg_arg, "RX", 2)) { + } else if (!rz_str_ncasecmp(reg_arg, "RX", 2)) { res = get_reg_name_1(ins_bits); } else { res = get_reg_name_2(ins_bits); @@ -192,18 +192,18 @@ static char *decode_regis(char *reg_arg, st32 hash_code, ut32 ins_bits, res = get_reg_name_1(ins_bits + 48); break; case 87: - if (!r_str_ncasecmp(reg_arg, "WD", 2)) { + if (!rz_str_ncasecmp(reg_arg, "WD", 2)) { res = get_reg_name_2(ins_bits); - } else if (!r_str_ncasecmp(reg_arg, "WA", 2)) { + } else if (!rz_str_ncasecmp(reg_arg, "WA", 2)) { res = get_reg_name_1(ins_bits); } else { res = NULL; } break; case 88: - if (!r_str_ncasecmp(reg_arg, "XR", 2)) { + if (!rz_str_ncasecmp(reg_arg, "XR", 2)) { res = get_reg_name_3(ins_bits); - } else if (!r_str_ncasecmp(reg_arg, "XD", 2)) { + } else if (!rz_str_ncasecmp(reg_arg, "XD", 2)) { res = get_reg_name_2(ins_bits + 32); } else { res = NULL; @@ -585,7 +585,7 @@ static char* get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l if (*reg_arg == '!') { res = get_reg_pair(ins_bits); break; - } else if (!r_str_ncasecmp(reg_arg, "ST", 2)) { + } else if (!rz_str_ncasecmp(reg_arg, "ST", 2)) { res = get_status_regs_and_bits(reg_arg, ins_bits); break; } @@ -867,11 +867,11 @@ static char* get_token_decoded(st32 hash_code, char *ins_token, ut32 ins_token_l res = strdup(res); break; case 78: - if (!r_str_ncasecmp (ins_token, "q_SAT", 5)) { + if (!rz_str_ncasecmp (ins_token, "q_SAT", 5)) { res = ins_bits? "s": NULL; - } else if (!r_str_ncasecmp(ins_token, "q_CIRC", 6)) { + } else if (!rz_str_ncasecmp(ins_token, "q_CIRC", 6)) { res = ins_bits? ".cr": NULL; - } else if (!r_str_ncasecmp(ins_token, "q_LINR", 6)) { + } else if (!rz_str_ncasecmp(ins_token, "q_LINR", 6)) { res = ins_bits? ".lr": NULL; } else { fprintf (stderr, "Invalid instruction %s\n!", ins_token); diff --git a/libr/asm/arch/tms320/c55x_plus/decode.h b/librz/asm/arch/tms320/c55x_plus/decode.h similarity index 97% rename from libr/asm/arch/tms320/c55x_plus/decode.h rename to librz/asm/arch/tms320/c55x_plus/decode.h index 20feb9287e..22ef5d94fd 100644 --- a/libr/asm/arch/tms320/c55x_plus/decode.h +++ b/librz/asm/arch/tms320/c55x_plus/decode.h @@ -1,7 +1,7 @@ #ifndef DECODE_H #define DECODE_H -#include +#include char *decode(ut32 ins_pos, ut32 *next_ins_pos); diff --git a/libr/asm/arch/tms320/c55x_plus/decode_funcs.c b/librz/asm/arch/tms320/c55x_plus/decode_funcs.c similarity index 100% rename from libr/asm/arch/tms320/c55x_plus/decode_funcs.c rename to librz/asm/arch/tms320/c55x_plus/decode_funcs.c diff --git a/libr/asm/arch/tms320/c55x_plus/decode_funcs.h b/librz/asm/arch/tms320/c55x_plus/decode_funcs.h similarity index 96% rename from libr/asm/arch/tms320/c55x_plus/decode_funcs.h rename to librz/asm/arch/tms320/c55x_plus/decode_funcs.h index 3256f179e4..a5beaec9fa 100644 --- a/libr/asm/arch/tms320/c55x_plus/decode_funcs.h +++ b/librz/asm/arch/tms320/c55x_plus/decode_funcs.h @@ -1,7 +1,7 @@ #ifndef DECODE_FUNCS_H #define DECODE_FUNCS_H -#include +#include char *get_tc2_tc1(ut32 ins_bits); char *get_trans_reg(ut32 ins_bits); diff --git a/libr/asm/arch/tms320/c55x_plus/hashtable.c b/librz/asm/arch/tms320/c55x_plus/hashtable.c similarity index 99% rename from libr/asm/arch/tms320/c55x_plus/hashtable.c rename to librz/asm/arch/tms320/c55x_plus/hashtable.c index 6691932801..de693506d7 100644 --- a/libr/asm/arch/tms320/c55x_plus/hashtable.c +++ b/librz/asm/arch/tms320/c55x_plus/hashtable.c @@ -2,7 +2,7 @@ #include "ins.h" #include "hashvector.c" -#include +#include static const st32 hash_const_01 = 0x2474f685; static const st32 hash_const_02 = 0x42fbc0b8; diff --git a/libr/asm/arch/tms320/c55x_plus/hashtable.h b/librz/asm/arch/tms320/c55x_plus/hashtable.h similarity index 100% rename from libr/asm/arch/tms320/c55x_plus/hashtable.h rename to librz/asm/arch/tms320/c55x_plus/hashtable.h diff --git a/libr/asm/arch/tms320/c55x_plus/hashvector.c b/librz/asm/arch/tms320/c55x_plus/hashvector.c similarity index 100% rename from libr/asm/arch/tms320/c55x_plus/hashvector.c rename to librz/asm/arch/tms320/c55x_plus/hashvector.c diff --git a/libr/asm/arch/tms320/c55x_plus/hashvector.h b/librz/asm/arch/tms320/c55x_plus/hashvector.h similarity index 86% rename from libr/asm/arch/tms320/c55x_plus/hashvector.h rename to librz/asm/arch/tms320/c55x_plus/hashvector.h index 5a27f9e72d..58f6655724 100644 --- a/libr/asm/arch/tms320/c55x_plus/hashvector.h +++ b/librz/asm/arch/tms320/c55x_plus/hashvector.h @@ -1,7 +1,7 @@ #ifndef HASHVECTOR_H #define HASHVECTOR_H -#include +#include typedef struct { st32 code; diff --git a/libr/asm/arch/tms320/c55x_plus/ins.c b/librz/asm/arch/tms320/c55x_plus/ins.c similarity index 100% rename from libr/asm/arch/tms320/c55x_plus/ins.c rename to librz/asm/arch/tms320/c55x_plus/ins.c diff --git a/libr/asm/arch/tms320/c55x_plus/ins.h b/librz/asm/arch/tms320/c55x_plus/ins.h similarity index 89% rename from libr/asm/arch/tms320/c55x_plus/ins.h rename to librz/asm/arch/tms320/c55x_plus/ins.h index 2fc98cd1cf..1ff8ba8d2f 100644 --- a/libr/asm/arch/tms320/c55x_plus/ins.h +++ b/librz/asm/arch/tms320/c55x_plus/ins.h @@ -1,7 +1,7 @@ #ifndef INS_H #define INS_H -#include +#include #include "utils.h" // instruction length diff --git a/libr/asm/arch/tms320/c55x_plus/utils.c b/librz/asm/arch/tms320/c55x_plus/utils.c similarity index 100% rename from libr/asm/arch/tms320/c55x_plus/utils.c rename to librz/asm/arch/tms320/c55x_plus/utils.c diff --git a/libr/asm/arch/tms320/c55x_plus/utils.h b/librz/asm/arch/tms320/c55x_plus/utils.h similarity index 87% rename from libr/asm/arch/tms320/c55x_plus/utils.h rename to librz/asm/arch/tms320/c55x_plus/utils.h index cea0953fc0..caa3303d1c 100644 --- a/libr/asm/arch/tms320/c55x_plus/utils.h +++ b/librz/asm/arch/tms320/c55x_plus/utils.h @@ -1,7 +1,7 @@ #ifndef UUTILS_H #define UUTILS_H -#include +#include #define C55PLUS_DEBUG 0 char *strcat_dup(char *s1, char *s2, st32 n_free); diff --git a/libr/asm/arch/tms320/scripts/c55x_gen_tbl.pl b/librz/asm/arch/tms320/scripts/c55x_gen_tbl.pl similarity index 100% rename from libr/asm/arch/tms320/scripts/c55x_gen_tbl.pl rename to librz/asm/arch/tms320/scripts/c55x_gen_tbl.pl diff --git a/libr/asm/arch/tms320/tms320_dasm.c b/librz/asm/arch/tms320/tms320_dasm.c similarity index 99% rename from libr/asm/arch/tms320/tms320_dasm.c rename to librz/asm/arch/tms320/tms320_dasm.c index efa7f4361b..9d119912f6 100644 --- a/libr/asm/arch/tms320/tms320_dasm.c +++ b/librz/asm/arch/tms320/tms320_dasm.c @@ -10,8 +10,8 @@ #include /* public headers */ -#include -#include +#include +#include #include diff --git a/libr/asm/arch/tms320/tms320_dasm.h b/librz/asm/arch/tms320/tms320_dasm.h similarity index 100% rename from libr/asm/arch/tms320/tms320_dasm.h rename to librz/asm/arch/tms320/tms320_dasm.h diff --git a/libr/asm/arch/tms320/tms320_p.h b/librz/asm/arch/tms320/tms320_p.h similarity index 100% rename from libr/asm/arch/tms320/tms320_p.h rename to librz/asm/arch/tms320/tms320_p.h diff --git a/libr/asm/arch/tricore/README.md b/librz/asm/arch/tricore/README.md similarity index 100% rename from libr/asm/arch/tricore/README.md rename to librz/asm/arch/tricore/README.md diff --git a/libr/asm/arch/tricore/gnu/cpu-tricore.c b/librz/asm/arch/tricore/gnu/cpu-tricore.c similarity index 100% rename from libr/asm/arch/tricore/gnu/cpu-tricore.c rename to librz/asm/arch/tricore/gnu/cpu-tricore.c diff --git a/libr/asm/arch/tricore/gnu/tricore-dis.c b/librz/asm/arch/tricore/gnu/tricore-dis.c similarity index 100% rename from libr/asm/arch/tricore/gnu/tricore-dis.c rename to librz/asm/arch/tricore/gnu/tricore-dis.c diff --git a/libr/asm/arch/tricore/gnu/tricore-opc.c b/librz/asm/arch/tricore/gnu/tricore-opc.c similarity index 100% rename from libr/asm/arch/tricore/gnu/tricore-opc.c rename to librz/asm/arch/tricore/gnu/tricore-opc.c diff --git a/libr/asm/arch/v810/v810_disas.c b/librz/asm/arch/v810/v810_disas.c similarity index 98% rename from libr/asm/arch/v810/v810_disas.c rename to librz/asm/arch/v810/v810_disas.c index fd67b8a79f..f4d447e98c 100644 --- a/libr/asm/arch/v810/v810_disas.c +++ b/librz/asm/arch/v810/v810_disas.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015 - danielps */ -#include -#include +#include +#include #include "v810_disas.h" @@ -310,9 +310,9 @@ int v810_decode_command(const ut8 *instr, int len, struct v810_cmd *cmd) { ut16 word1 = 0; ut16 word2 = 0; - word1 = r_read_le16 (instr); + word1 = rz_read_le16 (instr); if (len >= 4) { - word2 = r_read_le16 (instr + 2); + word2 = rz_read_le16 (instr + 2); } switch (OPCODE(word1)) { diff --git a/libr/asm/arch/v810/v810_disas.h b/librz/asm/arch/v810/v810_disas.h similarity index 100% rename from libr/asm/arch/v810/v810_disas.h rename to librz/asm/arch/v810/v810_disas.h diff --git a/libr/asm/arch/v850/v850_disas.c b/librz/asm/arch/v850/v850_disas.c similarity index 94% rename from libr/asm/arch/v850/v850_disas.c rename to librz/asm/arch/v850/v850_disas.c index ae8ad87c9c..2b2936b854 100644 --- a/libr/asm/arch/v850/v850_disas.c +++ b/librz/asm/arch/v850/v850_disas.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2014-2018 - Fedor Sakharov */ -#include -#include -#include +#include +#include +#include #include "v850_disas.h" @@ -172,8 +172,8 @@ static int decode_jarl(const ut8 *instr, int len, struct v850_cmd *cmd) { return -1; } - ut16 word1 = r_read_le16 (instr); - ut16 word2 = r_read_at_le16 (instr, 2); + ut16 word1 = rz_read_le16 (instr); + ut16 word2 = rz_read_at_le16 (instr, 2); ut8 reg = get_reg2 (word1); ut32 disp = (word2 << 6) | get_reg1 (word1); @@ -189,8 +189,8 @@ static int decode_3operands(const ut8 *instr, int len, struct v850_cmd *cmd) { if (len < 4) { return -1; } - ut16 word1 = r_read_le16 (instr); - ut16 word2 = r_read_at_le16 (instr, 2); + ut16 word1 = rz_read_le16 (instr); + ut16 word2 = rz_read_at_le16 (instr, 2); snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s", instrs[get_opcode (word1)]); snprintf (cmd->operands, V850_INSTR_MAXLEN - 1, "0x%x, r%d, r%d", word2, get_reg1 (word1), get_reg2 (word1)); @@ -202,8 +202,8 @@ static int decode_load_store(const ut8 *instr, int len, struct v850_cmd *cmd) { return -1; } - ut16 word1 = r_read_le16 (instr); - ut16 word2 = r_read_at_le16 (instr, 2); + ut16 word1 = rz_read_le16 (instr); + ut16 word2 = rz_read_at_le16 (instr, 2); switch (get_opcode (word1)) { case V850_STB: @@ -238,8 +238,8 @@ static int decode_bit_op(const ut8 *instr, int len, struct v850_cmd *cmd) { return -1; } - ut16 word1 = r_read_le16 (instr); - ut16 word2 = r_read_at_le16 (instr, 2); + ut16 word1 = rz_read_le16 (instr); + ut16 word2 = rz_read_at_le16 (instr, 2); snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s", bit_instrs[word1 >> 14]); ut8 reg1 = get_reg1 (word1); snprintf (cmd->operands, V850_INSTR_MAXLEN - 1, "%u, 0x%x[r%d]", @@ -252,8 +252,8 @@ static int decode_extended(const ut8 *instr, int len, struct v850_cmd *cmd) { return -1; } - ut16 word1 = r_read_le16 (instr); - ut16 word2 = r_read_at_le16 (instr, 2); + ut16 word1 = rz_read_le16 (instr); + ut16 word2 = rz_read_at_le16 (instr, 2); snprintf (cmd->instr, V850_INSTR_MAXLEN - 1, "%s", ext_instrs1[get_subopcode (word1)]); @@ -303,7 +303,7 @@ int v850_decode_command (const ut8 *instr, int len, struct v850_cmd *cmd) { if (len < 2) { return -1; } - ut16 in = r_read_le16 (instr); + ut16 in = rz_read_le16 (instr); switch (get_opcode (in)) { case V850_MOV: diff --git a/libr/asm/arch/v850/v850_disas.h b/librz/asm/arch/v850/v850_disas.h similarity index 100% rename from libr/asm/arch/v850/v850_disas.h rename to librz/asm/arch/v850/v850_disas.h diff --git a/libr/asm/arch/vax/vax-dis.c b/librz/asm/arch/vax/vax-dis.c similarity index 100% rename from libr/asm/arch/vax/vax-dis.c rename to librz/asm/arch/vax/vax-dis.c diff --git a/libr/asm/arch/vax/vax.h b/librz/asm/arch/vax/vax.h similarity index 100% rename from libr/asm/arch/vax/vax.h rename to librz/asm/arch/vax/vax.h diff --git a/libr/asm/arch/wasm/wasm.c b/librz/asm/arch/wasm/wasm.c similarity index 96% rename from libr/asm/arch/wasm/wasm.c rename to librz/asm/arch/wasm/wasm.c index 4b94f4b186..9497f68a41 100644 --- a/libr/asm/arch/wasm/wasm.c +++ b/librz/asm/arch/wasm/wasm.c @@ -2,8 +2,8 @@ // http://webassembly.org/docs/binary-encoding/#module-structure -#include -#include +#include +#include #include #include "wasm.h" @@ -474,7 +474,7 @@ R_IPI int wasm_asm(const char *str, unsigned char *buf, int buf_len) { // disassemble an instruction from the given buffer. R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); int id = buf[0]; if (id < 0xc0) { op->type = WASM_TYPE_OP_CORE; @@ -613,7 +613,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { case WASM_OP_F64REINTERPRETI64: case WASM_OP_END: { - r_strbuf_set (sb, opdef->txt); + rz_strbuf_set (sb, opdef->txt); } break; case WASM_OP_BLOCK: @@ -627,25 +627,25 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { } switch (0x80 - val) { case R_BIN_WASM_VALUETYPE_EMPTY: - r_strbuf_set (sb, opdef->txt); + rz_strbuf_set (sb, opdef->txt); break; case R_BIN_WASM_VALUETYPE_i32: - r_strbuf_setf (sb, "%s (result i32)", opdef->txt); + rz_strbuf_setf (sb, "%s (result i32)", opdef->txt); break; case R_BIN_WASM_VALUETYPE_i64: - r_strbuf_setf (sb, "%s (result i64)", opdef->txt); + rz_strbuf_setf (sb, "%s (result i64)", opdef->txt); break; case R_BIN_WASM_VALUETYPE_f32: - r_strbuf_setf (sb, "%s (result f32)", opdef->txt); + rz_strbuf_setf (sb, "%s (result f32)", opdef->txt); break; case R_BIN_WASM_VALUETYPE_f64: - r_strbuf_setf (sb, "%s (result f64)", opdef->txt); + rz_strbuf_setf (sb, "%s (result f64)", opdef->txt); break; case R_BIN_WASM_VALUETYPE_v128: - r_strbuf_setf (sb, "%s (result v128)", opdef->txt); + rz_strbuf_setf (sb, "%s (result v128)", opdef->txt); break; default: - r_strbuf_setf (sb, "%s (result ?)", opdef->txt); + rz_strbuf_setf (sb, "%s (result ?)", opdef->txt); break; } op->len += n; @@ -660,7 +660,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && n < buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %d", opdef->txt, val); + rz_strbuf_setf (sb, "%s %d", opdef->txt, val); op->len += n; } break; @@ -691,11 +691,11 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { goto beach; } op->len += n; - r_strbuf_setf (sb, "%s %d ", opdef->txt, count); + rz_strbuf_setf (sb, "%s %d ", opdef->txt, count); for (i = 0; i < count; i++) { - r_strbuf_appendf (sb, "%d ", table[i]); + rz_strbuf_appendf (sb, "%d ", table[i]); } - r_strbuf_appendf (sb, "%d", def); + rz_strbuf_appendf (sb, "%d", def); free (table); break; beach: @@ -716,7 +716,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { goto err; } reserved &= 0x1; - r_strbuf_setf (sb, "%s %d %d", opdef->txt, val, reserved); + rz_strbuf_setf (sb, "%s %d %d", opdef->txt, val, reserved); op->len += n; } break; @@ -731,7 +731,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && n < buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %d", opdef->txt, val); + rz_strbuf_setf (sb, "%s %d", opdef->txt, val); op->len += n; } break; @@ -769,7 +769,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && op->len + n <= buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %d %d", opdef->txt, flag, offset); + rz_strbuf_setf (sb, "%s %d %d", opdef->txt, flag, offset); op->len += n; } break; @@ -782,7 +782,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { goto err; } reserved &= 0x1; - r_strbuf_setf (sb, "%s %d", opdef->txt, reserved); + rz_strbuf_setf (sb, "%s %d", opdef->txt, reserved); op->len += n; } break; @@ -793,7 +793,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && n < buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %" PFMT32d, opdef->txt, val); + rz_strbuf_setf (sb, "%s %" PFMT32d, opdef->txt, val); op->len += n; } break; @@ -804,7 +804,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && n < buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %" PFMT64d, opdef->txt, val); + rz_strbuf_setf (sb, "%s %" PFMT64d, opdef->txt, val); op->len += n; } break; @@ -814,8 +814,8 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { ut32 v; float f; } u; - u.v = r_read_at_le32 (buf, 1); - r_strbuf_setf (sb, "%s %f", opdef->txt, u.f); + u.v = rz_read_at_le32 (buf, 1); + rz_strbuf_setf (sb, "%s %f", opdef->txt, u.f); op->len += 4; } else { goto err; @@ -827,8 +827,8 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { ut64 v; double f; } u; - u.v = r_read_at_le64 (buf, 1); - r_strbuf_setf (sb, "%s %f", opdef->txt, u.f); + u.v = rz_read_at_le64 (buf, 1); + rz_strbuf_setf (sb, "%s %f", opdef->txt, u.f); op->len += 8; } else { goto err; @@ -912,7 +912,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && op->len + n <= buf_len)) { goto err; } - r_strbuf_setf (sb, "%s %d %d", opdef->txt, flag, offset); + rz_strbuf_setf (sb, "%s %d %d", opdef->txt, flag, offset); op->len += n; } break; @@ -1083,7 +1083,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { case WASM_OP_I16X8ABS: case WASM_OP_I32X4ABS: { - r_strbuf_set (sb, opdef->txt); + rz_strbuf_set (sb, opdef->txt); } break; case WASM_OP_V128LOAD: @@ -1110,7 +1110,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { if (!(n > 0 && n < buf_len)) { goto err; } - r_strbuf_setf (sb, "%s o:%d a:2^%d", opdef->txt, offset, align); + rz_strbuf_setf (sb, "%s o:%d a:2^%d", opdef->txt, offset, align); } break; case WASM_OP_V128CONST: @@ -1125,7 +1125,7 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { for (i = 0; i < 16; ++i) { bytes[i] = buf[i + 1 + simdop_size]; } - r_strbuf_setf (sb, "%s %02x %02x %02x %02x %02x %02x %02x " \ + rz_strbuf_setf (sb, "%s %02x %02x %02x %02x %02x %02x %02x " \ "%02x %02x %02x %02x %02x %02x %02x %02x %02x", opdef->txt, bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7], bytes[8], @@ -1153,19 +1153,19 @@ R_IPI int wasm_dis(WasmOp *op, const unsigned char *buf, int buf_len) { } unsigned char lane = buf[1 + simdop_size]; ++op->len; - r_strbuf_setf (sb, "%s %d", opdef->txt, lane); + rz_strbuf_setf (sb, "%s %d", opdef->txt, lane); } break; } } else { goto err; } - op->txt = r_strbuf_drain (sb); + op->txt = rz_strbuf_drain (sb); return op->len; err: op->len = 1; - r_strbuf_set (sb, "invalid"); - op->txt = r_strbuf_drain (sb); + rz_strbuf_set (sb, "invalid"); + op->txt = rz_strbuf_drain (sb); return op->len; } diff --git a/libr/asm/arch/wasm/wasm.h b/librz/asm/arch/wasm/wasm.h similarity index 99% rename from libr/asm/arch/wasm/wasm.h rename to librz/asm/arch/wasm/wasm.h index 3fafb904e1..9047844d73 100644 --- a/libr/asm/arch/wasm/wasm.h +++ b/librz/asm/arch/wasm/wasm.h @@ -1,6 +1,6 @@ #ifndef WASM_ASM_H #define WASM_ASM_H -#include +#include /*** * Core diff --git a/libr/asm/arch/whitespace/wsdis.c b/librz/asm/arch/whitespace/wsdis.c similarity index 80% rename from libr/asm/arch/whitespace/wsdis.c rename to librz/asm/arch/whitespace/wsdis.c index c957f73ef7..59610814f5 100644 --- a/libr/asm/arch/whitespace/wsdis.c +++ b/librz/asm/arch/whitespace/wsdis.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2014-2018 - dso, condret, pancake */ -#include -#include +#include +#include #include #ifndef WS_API @@ -103,14 +103,14 @@ WS_API int test_ws_token_exist(const ut8 *buf, ut8 token, int len) { return size; } -WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { +WS_API int wsdis(RzAsmOp *op, const ut8 *buf, int len) { const char *buf_asm = NULL; const ut8 *ptr = buf; switch (get_ws_optype (buf, len)) { case WS_OP_UNK: return op->size = 0; case WS_OP_NOP: - r_strbuf_set (&op->buf_asm, "nop"); + rz_strbuf_set (&op->buf_asm, "nop"); return op->size = 1; case WS_OP_STACK: ptr++; @@ -123,7 +123,7 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { return op->size = 0; } int n = test_ws_token_exist (ptr - 1, 10, len); - r_strbuf_set (&op->buf_asm, sdb_fmt ("push %d", n)); + rz_strbuf_set (&op->buf_asm, sdb_fmt ("push %d", n)); return op->size = n; case 10: ptr = get_ws_next_token (ptr, len - 1) + 1; @@ -133,13 +133,13 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case ' ': - r_strbuf_set (&op->buf_asm, "dup"); + rz_strbuf_set (&op->buf_asm, "dup"); break; case '\t': - r_strbuf_set (&op->buf_asm, "swap"); + rz_strbuf_set (&op->buf_asm, "swap"); break; case 10: - r_strbuf_set (&op->buf_asm, "pop"); + rz_strbuf_set (&op->buf_asm, "pop"); break; } return op->size = ptr - buf + 1; @@ -151,22 +151,22 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case ' ': - r_strbuf_set (&op->buf_asm, "copy"); + rz_strbuf_set (&op->buf_asm, "copy"); break; case 10: - r_strbuf_set (&op->buf_asm, "slide"); + rz_strbuf_set (&op->buf_asm, "slide"); break; case '\t': - r_strbuf_set (&op->buf_asm, "illegal_stack_t"); + rz_strbuf_set (&op->buf_asm, "illegal_stack_t"); return op->size = ptr - buf + 1; } ptr++; if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf) - 1)) { - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); return op->size = 0; } - if (r_strbuf_length (&op->buf_asm) < 6) { - r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); + if (rz_strbuf_length (&op->buf_asm) < 6) { + rz_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); } return op->size = test_ws_token_exist (ptr, 10, len - (ptr - buf) - 1) + ptr - buf + 1; // +1? } @@ -178,13 +178,13 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case ' ': - r_strbuf_set (&op->buf_asm, "store"); + rz_strbuf_set (&op->buf_asm, "store"); break; case '\t': - r_strbuf_set (&op->buf_asm, "load"); + rz_strbuf_set (&op->buf_asm, "load"); break; case 10: - r_strbuf_set (&op->buf_asm, "illegal_heap"); + rz_strbuf_set (&op->buf_asm, "illegal_heap"); break; } return op->size = ptr - buf + 1; @@ -203,10 +203,10 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case ' ': - r_strbuf_set (&op->buf_asm, "putc"); + rz_strbuf_set (&op->buf_asm, "putc"); return op->size = ptr - buf + 1; case '\t': - r_strbuf_set (&op->buf_asm, "puti"); + rz_strbuf_set (&op->buf_asm, "puti"); return op->size = ptr - buf + 1; } break; @@ -218,14 +218,14 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case ' ': - r_strbuf_set (&op->buf_asm, "getc"); + rz_strbuf_set (&op->buf_asm, "getc"); return op->size = ptr - buf + 1; case '\t': - r_strbuf_set (&op->buf_asm, "geti"); + rz_strbuf_set (&op->buf_asm, "geti"); return op->size = ptr - buf + 1; } } - r_strbuf_set (&op->buf_asm, "illegal_io"); + rz_strbuf_set (&op->buf_asm, "illegal_io"); return op->size = ptr - buf + 1; break; case WS_OP_ARITH: @@ -264,7 +264,7 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { break; } if (buf_asm) { - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); } return op->size = ptr - buf + 1; case WS_OP_FLOW: @@ -280,9 +280,9 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { return op->size = 0; } if (*ptr == 10) { - r_strbuf_set (&op->buf_asm, "exit"); + rz_strbuf_set (&op->buf_asm, "exit"); } else { - r_strbuf_set (&op->buf_asm, "illegal_fl_lf"); + rz_strbuf_set (&op->buf_asm, "illegal_fl_lf"); } return op->size = ptr - buf + 1; case '\t': @@ -293,22 +293,22 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } switch (*ptr) { case 10: - r_strbuf_set (&op->buf_asm, "ret"); + rz_strbuf_set (&op->buf_asm, "ret"); return op->size = ptr - buf + 1; case '\t': - r_strbuf_set (&op->buf_asm, "jn"); + rz_strbuf_set (&op->buf_asm, "jn"); break; case ' ': - r_strbuf_set (&op->buf_asm, "jz"); + rz_strbuf_set (&op->buf_asm, "jz"); break; } ptr++; if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf))) { - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); return op->size = 0; } - if (r_strbuf_length (&op->buf_asm) == 2) { - r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); + if (rz_strbuf_length (&op->buf_asm) == 2) { + rz_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); } return op->size = ptr - buf + test_ws_token_exist (ptr, 10, len - (ptr - buf)) + 1; case ' ': @@ -324,16 +324,16 @@ WS_API int wsdis(RAsmOp *op, const ut8 *buf, int len) { } ptr++; if (-1 == test_ws_token_exist (ptr, 10, len - (ptr - buf))) { - r_strbuf_set (&op->buf_asm, "invalid"); + rz_strbuf_set (&op->buf_asm, "invalid"); return op->size = 0; } if (buf_asm) { - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); } - r_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); + rz_strbuf_append (&op->buf_asm, sdb_fmt (" %d", get_ws_val (ptr, len - (ptr - buf) - 1))); return op->size = ptr - buf + test_ws_token_exist (ptr, 10, len - (ptr - buf)) + 1; } } - r_strbuf_set (&op->buf_asm, "wtf"); + rz_strbuf_set (&op->buf_asm, "wtf"); return op->size = 0; } diff --git a/libr/asm/arch/xap/dis.c b/librz/asm/arch/xap/dis.c similarity index 98% rename from libr/asm/arch/xap/dis.c rename to librz/asm/arch/xap/dis.c index 9bb1f95198..a296497248 100644 --- a/libr/asm/arch/xap/dis.c +++ b/librz/asm/arch/xap/dis.c @@ -10,8 +10,8 @@ static struct state _state; -#include -#include +#include +#include static inline struct state *get_state(void) { memset (&_state, 0, sizeof (struct state)); @@ -521,7 +521,7 @@ static void own(struct state *s) } if (s->s_nop) { - r_return_if_fail (!s->s_nopd); + rz_return_if_fail (!s->s_nopd); s->s_nopd = d; } else { last->d_next = d; @@ -561,7 +561,7 @@ static void own(struct state *s) } if (l) { print_label(s, l); - r_return_if_fail (!l->l_next); + rz_return_if_fail (!l->l_next); } output(s, "\n\tENDMOD\n"); diff --git a/libr/asm/arch/xap/dis.h b/librz/asm/arch/xap/dis.h similarity index 98% rename from libr/asm/arch/xap/dis.h rename to librz/asm/arch/xap/dis.h index a3838d1ff8..5e88a2342b 100644 --- a/libr/asm/arch/xap/dis.h +++ b/librz/asm/arch/xap/dis.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_XAP_DIS_H_ #define _INCLUDE_XAP_DIS_H_ -#include +#include #define __packed __attribute__((__packed__)) diff --git a/libr/asm/arch/xtensa/gnu/elf32-xtensa.c b/librz/asm/arch/xtensa/gnu/elf32-xtensa.c similarity index 92% rename from libr/asm/arch/xtensa/gnu/elf32-xtensa.c rename to librz/asm/arch/xtensa/gnu/elf32-xtensa.c index 6d253fb56f..36efe7aa13 100644 --- a/libr/asm/arch/xtensa/gnu/elf32-xtensa.c +++ b/librz/asm/arch/xtensa/gnu/elf32-xtensa.c @@ -214,7 +214,7 @@ static reloc_howto_type elf_howto_table[] = TRUE, 0xffffffff, 0xffffffff, FALSE), /* Replace a 32-bit value with a value from the runtime linker (only - used by linker-generated stub functions). The r_addend value is + used by linker-generated stub functions). The rz_addend value is special: 1 means to substitute a pointer to the runtime linker's dynamic resolver function; 2 means to substitute the link map for the shared object. */ @@ -501,13 +501,13 @@ elf_xtensa_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, static reloc_howto_type * elf_xtensa_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, - const char *r_name) + const char *rz_name) { unsigned int i; for (i = 0; i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]); i++) if (elf_howto_table[i].name != NULL - && r_str_casecmp (elf_howto_table[i].name, r_name) == 0) + && rz_str_casecmp (elf_howto_table[i].name, rz_name) == 0) return &elf_howto_table[i]; return NULL; @@ -522,14 +522,14 @@ elf_xtensa_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { - unsigned int r_type = ELF32_R_TYPE (dst->r_info); + unsigned int rz_type = ELF32_R_TYPE (dst->rz_info); - if (r_type >= (unsigned int) R_XTENSA_max) + if (rz_type >= (unsigned int) R_XTENSA_max) { - _bfd_error_handler (_("%B: invalid XTENSA reloc number: %d"), abfd, r_type); - r_type = 0; + _bfd_error_handler (_("%B: invalid XTENSA reloc number: %d"), abfd, rz_type); + rz_type = 0; } - cache_ptr->howto = &elf_howto_table[r_type]; + cache_ptr->howto = &elf_howto_table[rz_type]; } @@ -895,27 +895,27 @@ xtensa_read_table_entries (bfd *abfd, avoid confusion caused by unexpected relocations for the preceding table entry. */ while (irel && - (irel->r_offset < off - || (irel->r_offset == off - && ELF32_R_TYPE (irel->r_info) == R_XTENSA_NONE))) + (irel->rz_offset < off + || (irel->rz_offset == off + && ELF32_R_TYPE (irel->rz_info) == R_XTENSA_NONE))) { irel += 1; if (irel >= rel_end) irel = 0; } - if (irel && irel->r_offset == off) + if (irel && irel->rz_offset == off) { bfd_vma sym_off; - unsigned long r_symndx = ELF32_R_SYM (irel->r_info); - BFD_ASSERT (ELF32_R_TYPE (irel->r_info) == R_XTENSA_32); + unsigned long rz_symndx = ELF32_R_SYM (irel->rz_info); + BFD_ASSERT (ELF32_R_TYPE (irel->rz_info) == R_XTENSA_32); - if (get_elf_r_symndx_section (abfd, r_symndx) != section) + if (get_elf_r_symndx_section (abfd, rz_symndx) != section) continue; - sym_off = get_elf_r_symndx_offset (abfd, r_symndx); + sym_off = get_elf_r_symndx_offset (abfd, rz_symndx); BFD_ASSERT (sym_off == 0); - address += (section_addr + sym_off + irel->r_addend); + address += (section_addr + sym_off + irel->rz_addend); } else { @@ -1030,8 +1030,8 @@ elf_xtensa_check_relocs (bfd *abfd, rel_end = relocs + sec->reloc_count; for (rel = relocs; rel < rel_end; rel++) { - unsigned int r_type; - unsigned long r_symndx; + unsigned int rz_type; + unsigned long rz_symndx; struct elf_link_hash_entry *h = NULL; struct elf_xtensa_link_hash_entry *eh; int tls_type, old_tls_type; @@ -1039,19 +1039,19 @@ elf_xtensa_check_relocs (bfd *abfd, bfd_boolean is_plt = FALSE; bfd_boolean is_tlsfunc = FALSE; - r_symndx = ELF32_R_SYM (rel->r_info); - r_type = ELF32_R_TYPE (rel->r_info); + rz_symndx = ELF32_R_SYM (rel->rz_info); + rz_type = ELF32_R_TYPE (rel->rz_info); - if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) + if (rz_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) { (*_bfd_error_handler) (_("%B: bad symbol index: %d"), - abfd, r_symndx); + abfd, rz_symndx); return FALSE; } - if (r_symndx >= symtab_hdr->sh_info) + if (rz_symndx >= symtab_hdr->sh_info) { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + h = sym_hashes[rz_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; @@ -1062,7 +1062,7 @@ elf_xtensa_check_relocs (bfd *abfd, } eh = elf_xtensa_hash_entry (h); - switch (r_type) + switch (rz_type) { case R_XTENSA_TLSDESC_FN: if (info->shared) @@ -1117,7 +1117,7 @@ elf_xtensa_check_relocs (bfd *abfd, case R_XTENSA_GNU_VTINHERIT: /* This relocation describes the C++ object vtable hierarchy. Reconstruct it for later use during GC. */ - if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) + if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->rz_offset)) return FALSE; continue; @@ -1126,7 +1126,7 @@ elf_xtensa_check_relocs (bfd *abfd, used. Record for later use during GC. */ BFD_ASSERT (h != NULL); if (h != NULL - && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) + && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->rz_addend)) return FALSE; continue; @@ -1198,12 +1198,12 @@ elf_xtensa_check_relocs (bfd *abfd, /* This is a global offset table entry for a local symbol. */ if (is_got || is_plt) - elf_local_got_refcounts (abfd) [r_symndx] += 1; + elf_local_got_refcounts (abfd) [rz_symndx] += 1; if (is_tlsfunc) - elf_xtensa_local_tlsfunc_refcounts (abfd) [r_symndx] += 1; + elf_xtensa_local_tlsfunc_refcounts (abfd) [rz_symndx] += 1; - old_tls_type = elf_xtensa_local_got_tls_type (abfd) [r_symndx]; + old_tls_type = elf_xtensa_local_got_tls_type (abfd) [rz_symndx]; } if ((old_tls_type & GOT_TLS_IE) && (tls_type & GOT_TLS_IE)) @@ -1233,7 +1233,7 @@ elf_xtensa_check_relocs (bfd *abfd, if (eh) eh->tls_type = tls_type; else - elf_xtensa_local_got_tls_type (abfd) [r_symndx] = tls_type; + elf_xtensa_local_got_tls_type (abfd) [rz_symndx] = tls_type; } } @@ -1303,7 +1303,7 @@ elf_xtensa_gc_mark_hook (asection *sec, return NULL; if (h != NULL) - switch (ELF32_R_TYPE (rel->r_info)) + switch (ELF32_R_TYPE (rel->rz_info)) { case R_XTENSA_GNU_VTINHERIT: case R_XTENSA_GNU_VTENTRY: @@ -1344,26 +1344,26 @@ elf_xtensa_gc_sweep_hook (bfd *abfd, relend = relocs + sec->reloc_count; for (rel = relocs; rel < relend; rel++) { - unsigned long r_symndx; - unsigned int r_type; + unsigned long rz_symndx; + unsigned int rz_type; struct elf_link_hash_entry *h = NULL; struct elf_xtensa_link_hash_entry *eh; bfd_boolean is_got = FALSE; bfd_boolean is_plt = FALSE; bfd_boolean is_tlsfunc = FALSE; - r_symndx = ELF32_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) + rz_symndx = ELF32_R_SYM (rel->rz_info); + if (rz_symndx >= symtab_hdr->sh_info) { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + h = sym_hashes[rz_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; } eh = elf_xtensa_hash_entry (h); - r_type = ELF32_R_TYPE (rel->r_info); - switch (r_type) + rz_type = ELF32_R_TYPE (rel->rz_info); + switch (rz_type) { case R_XTENSA_TLSDESC_FN: if (info->shared) @@ -1427,14 +1427,14 @@ elf_xtensa_gc_sweep_hook (bfd *abfd, if (is_got || is_plt) { bfd_signed_vma *got_refcount - = &elf_local_got_refcounts (abfd) [r_symndx]; + = &elf_local_got_refcounts (abfd) [rz_symndx]; if (*got_refcount > 0) *got_refcount -= 1; } if (is_tlsfunc) { bfd_signed_vma *tlsfunc_refcount - = &elf_xtensa_local_tlsfunc_refcounts (abfd) [r_symndx]; + = &elf_xtensa_local_tlsfunc_refcounts (abfd) [rz_symndx]; if (*tlsfunc_refcount > 0) *tlsfunc_refcount -= 1; } @@ -1840,9 +1840,9 @@ elf_xtensa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, Elf_Internal_Rela irela; bfd_byte *loc; - irela.r_offset = 0; - irela.r_info = ELF32_R_INFO (0, R_XTENSA_RTLD); - irela.r_addend = 0; + irela.rz_offset = 0; + irela.rz_info = ELF32_R_INFO (0, R_XTENSA_RTLD); + irela.rz_addend = 0; loc = (srelgot->contents + srelgot->reloc_count * sizeof (Elf32_External_Rela)); @@ -2417,7 +2417,7 @@ replace_tls_insn (Elf_Internal_Rela *rel, xtensa_format fmt; xtensa_opcode old_op, new_op; bfd_size_type input_size; - int r_type; + int rz_type; unsigned dest_reg, src_reg; if (ibuff == NULL) @@ -2429,8 +2429,8 @@ replace_tls_insn (Elf_Internal_Rela *rel, input_size = bfd_get_section_limit (abfd, input_section); /* Read the instruction into a buffer and decode the opcode. */ - xtensa_insnbuf_from_chars (isa, ibuff, contents + rel->r_offset, - input_size - rel->r_offset); + xtensa_insnbuf_from_chars (isa, ibuff, contents + rel->rz_offset, + input_size - rel->rz_offset); fmt = xtensa_format_decode (isa, ibuff); if (fmt == XTENSA_UNDEFINED) { @@ -2448,8 +2448,8 @@ replace_tls_insn (Elf_Internal_Rela *rel, return FALSE; } - r_type = ELF32_R_TYPE (rel->r_info); - switch (r_type) + rz_type = ELF32_R_TYPE (rel->rz_info); + switch (rz_type) { case R_XTENSA_TLS_FUNC: case R_XTENSA_TLS_ARG: @@ -2478,7 +2478,7 @@ replace_tls_insn (Elf_Internal_Rela *rel, if (is_ld_model) { - switch (r_type) + switch (rz_type) { case R_XTENSA_TLS_FUNC: case R_XTENSA_TLS_ARG: @@ -2527,7 +2527,7 @@ replace_tls_insn (Elf_Internal_Rela *rel, } else { - switch (r_type) + switch (rz_type) { case R_XTENSA_TLS_FUNC: new_op = xtensa_opcode_lookup (isa, "rur.threadptr"); @@ -2567,8 +2567,8 @@ replace_tls_insn (Elf_Internal_Rela *rel, } xtensa_format_set_slot (isa, fmt, 0, ibuff, sbuff); - xtensa_insnbuf_to_chars (isa, ibuff, contents + rel->r_offset, - input_size - rel->r_offset); + xtensa_insnbuf_to_chars (isa, ibuff, contents + rel->rz_offset, + input_size - rel->rz_offset); return TRUE; } @@ -2636,9 +2636,9 @@ elf_xtensa_relocate_section (bfd *output_bfd, relend = relocs + input_section->reloc_count; for (; rel < relend; rel++) { - int r_type; + int rz_type; reloc_howto_type *howto; - unsigned long r_symndx; + unsigned long rz_symndx; struct elf_link_hash_entry *h; Elf_Internal_Sym *sym; char sym_type; @@ -2651,19 +2651,19 @@ elf_xtensa_relocate_section (bfd *output_bfd, bfd_boolean warned; bfd_boolean dynamic_symbol; - r_type = ELF32_R_TYPE (rel->r_info); - if (r_type == (int) R_XTENSA_GNU_VTINHERIT - || r_type == (int) R_XTENSA_GNU_VTENTRY) + rz_type = ELF32_R_TYPE (rel->rz_info); + if (rz_type == (int) R_XTENSA_GNU_VTINHERIT + || rz_type == (int) R_XTENSA_GNU_VTENTRY) continue; - if (r_type < 0 || r_type >= (int) R_XTENSA_max) + if (rz_type < 0 || rz_type >= (int) R_XTENSA_max) { bfd_set_error (bfd_error_bad_value); return FALSE; } - howto = &elf_howto_table[r_type]; + howto = &elf_howto_table[rz_type]; - r_symndx = ELF32_R_SYM (rel->r_info); + rz_symndx = ELF32_R_SYM (rel->rz_info); h = NULL; sym = NULL; @@ -2678,15 +2678,15 @@ elf_xtensa_relocate_section (bfd *output_bfd, problems with DWARF info in partial links, there may be an addend stored in the contents. Take it out of there and move it back into the addend field of the reloc. */ - rel->r_addend += bfd_get_32 (input_bfd, contents + rel->r_offset); - bfd_put_32 (input_bfd, 0, contents + rel->r_offset); + rel->rz_addend += bfd_get_32 (input_bfd, contents + rel->rz_offset); + bfd_put_32 (input_bfd, 0, contents + rel->rz_offset); } - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) { - sym = local_syms + r_symndx; + sym = local_syms + rz_symndx; sym_type = ELF32_ST_TYPE (sym->st_info); - sec = local_sections[r_symndx]; + sec = local_sections[rz_symndx]; relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); } else @@ -2694,7 +2694,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, bfd_boolean ignored; RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, - r_symndx, symtab_hdr, sym_hashes, + rz_symndx, symtab_hdr, sym_hashes, h, sec, relocation, unresolved_reloc, warned, ignored); @@ -2713,7 +2713,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, if (info->relocatable) { bfd_vma dest_addr; - asection * sym_sec = get_elf_r_symndx_section (input_bfd, r_symndx); + asection * sym_sec = get_elf_r_symndx_section (input_bfd, rz_symndx); /* This is a relocatable link. 1) If the reloc is against a section symbol, adjust @@ -2732,9 +2732,9 @@ elf_xtensa_relocate_section (bfd *output_bfd, } dest_addr = sym_sec->output_section->vma + sym_sec->output_offset - + get_elf_r_symndx_offset (input_bfd, r_symndx) + rel->r_addend; + + get_elf_r_symndx_offset (input_bfd, rz_symndx) + rel->rz_addend; - if (r_type == R_XTENSA_ASM_SIMPLIFY) + if (rz_type == R_XTENSA_ASM_SIMPLIFY) { error_message = NULL; /* Convert ASM_SIMPLIFY into the simpler relocation @@ -2745,23 +2745,23 @@ elf_xtensa_relocate_section (bfd *output_bfd, { if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } - r_type = ELF32_R_TYPE (rel->r_info); + rz_type = ELF32_R_TYPE (rel->rz_info); } /* This is a relocatable link, so we don't have to change anything unless the reloc is against a section symbol, in which case we have to adjust according to where the section symbol winds up in the output section. */ - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) { - sym = local_syms + r_symndx; + sym = local_syms + rz_symndx; if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) { - sec = local_sections[r_symndx]; - rel->r_addend += sec->output_offset + sym->st_value; + sec = local_sections[rz_symndx]; + rel->rz_addend += sec->output_offset + sym->st_value; } } @@ -2771,14 +2771,14 @@ elf_xtensa_relocate_section (bfd *output_bfd, with some previous version of BFD. Now we can't easily get rid of the hack without breaking backward compatibility.... */ r = bfd_reloc_ok; - howto = &elf_howto_table[r_type]; - if (howto->partial_inplace && rel->r_addend) + howto = &elf_howto_table[rz_type]; + if (howto->partial_inplace && rel->rz_addend) { r = elf_xtensa_do_reloc (howto, input_bfd, input_section, - rel->r_addend, contents, - rel->r_offset, FALSE, + rel->rz_addend, contents, + rel->rz_offset, FALSE, &error_message); - rel->r_addend = 0; + rel->rz_addend = 0; } else { @@ -2789,12 +2789,12 @@ elf_xtensa_relocate_section (bfd *output_bfd, relocations on anything other than calls and l32r's. */ /* If it is not in the same section, there is nothing we can do. */ - if (r_type >= R_XTENSA_SLOT0_OP && r_type <= R_XTENSA_SLOT14_OP && + if (rz_type >= R_XTENSA_SLOT0_OP && rz_type <= R_XTENSA_SLOT14_OP && sym_sec->output_section == input_section->output_section) { r = elf_xtensa_do_reloc (howto, input_bfd, input_section, dest_addr, contents, - rel->r_offset, FALSE, + rel->rz_offset, FALSE, &error_message); } } @@ -2802,7 +2802,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, { if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } @@ -2820,12 +2820,12 @@ elf_xtensa_relocate_section (bfd *output_bfd, } /* Sanity check the address. */ - if (rel->r_offset >= input_size - && ELF32_R_TYPE (rel->r_info) != R_XTENSA_NONE) + if (rel->rz_offset >= input_size + && ELF32_R_TYPE (rel->rz_info) != R_XTENSA_NONE) { (*_bfd_error_handler) (_("%B(%A+0x%lx): relocation offset out of range (size=0x%x)"), - input_bfd, input_section, rel->r_offset, input_size); + input_bfd, input_section, rel->rz_offset, input_size); bfd_set_error (bfd_error_bad_value); return FALSE; } @@ -2840,12 +2840,12 @@ elf_xtensa_relocate_section (bfd *output_bfd, name = bfd_section_name (input_bfd, sec); } - if (r_symndx != STN_UNDEF - && r_type != R_XTENSA_NONE + if (rz_symndx != STN_UNDEF + && rz_type != R_XTENSA_NONE && (h == NULL || h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) - && IS_XTENSA_TLS_RELOC (r_type) != (sym_type == STT_TLS)) + && IS_XTENSA_TLS_RELOC (rz_type) != (sym_type == STT_TLS)) { (*_bfd_error_handler) ((sym_type == STT_TLS @@ -2853,7 +2853,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), input_bfd, input_section, - (long) rel->r_offset, + (long) rel->rz_offset, howto->name, name); } @@ -2864,9 +2864,9 @@ elf_xtensa_relocate_section (bfd *output_bfd, if (h) tls_type = elf_xtensa_hash_entry (h)->tls_type; else if (local_got_tls_types) - tls_type = local_got_tls_types [r_symndx]; + tls_type = local_got_tls_types [rz_symndx]; - switch (r_type) + switch (rz_type) { case R_XTENSA_32: case R_XTENSA_PLT: @@ -2878,52 +2878,52 @@ elf_xtensa_relocate_section (bfd *output_bfd, bfd_byte *loc; asection *srel; - if (dynamic_symbol && r_type == R_XTENSA_PLT) + if (dynamic_symbol && rz_type == R_XTENSA_PLT) srel = htab->srelplt; else srel = htab->srelgot; BFD_ASSERT (srel != NULL); - outrel.r_offset = + outrel.rz_offset = _bfd_elf_section_offset (output_bfd, info, - input_section, rel->r_offset); + input_section, rel->rz_offset); - if ((outrel.r_offset | 1) == (bfd_vma) -1) + if ((outrel.rz_offset | 1) == (bfd_vma) -1) memset (&outrel, 0, sizeof outrel); else { - outrel.r_offset += (input_section->output_section->vma + outrel.rz_offset += (input_section->output_section->vma + input_section->output_offset); /* Complain if the relocation is in a read-only section and not in a literal pool. */ if ((input_section->flags & SEC_READONLY) != 0 && !elf_xtensa_in_literal_pool (lit_table, ltblsize, - outrel.r_offset)) + outrel.rz_offset)) { error_message = _("dynamic relocation in read-only section"); if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } if (dynamic_symbol) { - outrel.r_addend = rel->r_addend; - rel->r_addend = 0; + outrel.rz_addend = rel->rz_addend; + rel->rz_addend = 0; - if (r_type == R_XTENSA_32) + if (rz_type == R_XTENSA_32) { - outrel.r_info = + outrel.rz_info = ELF32_R_INFO (h->dynindx, R_XTENSA_GLOB_DAT); relocation = 0; } - else /* r_type == R_XTENSA_PLT */ + else /* rz_type == R_XTENSA_PLT */ { - outrel.r_info = + outrel.rz_info = ELF32_R_INFO (h->dynindx, R_XTENSA_JMP_SLOT); /* Create the PLT entry and set the initial @@ -2938,8 +2938,8 @@ elf_xtensa_relocate_section (bfd *output_bfd, else { /* Generate a RELATIVE relocation. */ - outrel.r_info = ELF32_R_INFO (0, R_XTENSA_RELATIVE); - outrel.r_addend = 0; + outrel.rz_info = ELF32_R_INFO (0, R_XTENSA_RELATIVE); + outrel.rz_addend = 0; } } @@ -2949,7 +2949,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, BFD_ASSERT (sizeof (Elf32_External_Rela) * srel->reloc_count <= srel->size); } - else if (r_type == R_XTENSA_ASM_EXPAND && dynamic_symbol) + else if (rz_type == R_XTENSA_ASM_EXPAND && dynamic_symbol) { /* This should only happen for non-PIC code, which is not supposed to be used on systems with dynamic linking. @@ -2970,21 +2970,21 @@ elf_xtensa_relocate_section (bfd *output_bfd, case R_XTENSA_TLSDESC_FN: case R_XTENSA_TLSDESC_ARG: { - if (r_type == R_XTENSA_TLSDESC_FN) + if (rz_type == R_XTENSA_TLSDESC_FN) { if (! info->shared || (tls_type & GOT_TLS_IE) != 0) - r_type = R_XTENSA_NONE; + rz_type = R_XTENSA_NONE; } - else if (r_type == R_XTENSA_TLSDESC_ARG) + else if (rz_type == R_XTENSA_TLSDESC_ARG) { if (info->shared) { if ((tls_type & GOT_TLS_IE) != 0) - r_type = R_XTENSA_TLS_TPOFF; + rz_type = R_XTENSA_TLS_TPOFF; } else { - r_type = R_XTENSA_TLS_TPOFF; + rz_type = R_XTENSA_TLS_TPOFF; if (! dynamic_symbol) { relocation = tpoff (info, relocation); @@ -2993,7 +2993,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, } } - if (r_type == R_XTENSA_NONE) + if (rz_type == R_XTENSA_NONE) /* Nothing to do here; skip to the next reloc. */ continue; @@ -3003,7 +3003,7 @@ elf_xtensa_relocate_section (bfd *output_bfd, _("TLS relocation invalid without dynamic sections"); if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } else @@ -3013,32 +3013,32 @@ elf_xtensa_relocate_section (bfd *output_bfd, asection *srel = htab->srelgot; int indx; - outrel.r_offset = (input_section->output_section->vma + outrel.rz_offset = (input_section->output_section->vma + input_section->output_offset - + rel->r_offset); + + rel->rz_offset); /* Complain if the relocation is in a read-only section and not in a literal pool. */ if ((input_section->flags & SEC_READONLY) != 0 && ! elf_xtensa_in_literal_pool (lit_table, ltblsize, - outrel.r_offset)) + outrel.rz_offset)) { error_message = _("dynamic relocation in read-only section"); if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } indx = h && h->dynindx != -1 ? h->dynindx : 0; if (indx == 0) - outrel.r_addend = relocation - dtpoff_base (info); + outrel.rz_addend = relocation - dtpoff_base (info); else - outrel.r_addend = 0; - rel->r_addend = 0; + outrel.rz_addend = 0; + rel->rz_addend = 0; - outrel.r_info = ELF32_R_INFO (indx, r_type); + outrel.rz_info = ELF32_R_INFO (indx, rz_type); relocation = 0; unresolved_reloc = FALSE; @@ -3073,14 +3073,14 @@ elf_xtensa_relocate_section (bfd *output_bfd, { if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } - if (r_type != R_XTENSA_TLS_ARG || is_ld_model) + if (rz_type != R_XTENSA_TLS_ARG || is_ld_model) { /* Skip subsequent relocations on the same instruction. */ - while (rel + 1 < relend && rel[1].r_offset == rel->r_offset) + while (rel + 1 < relend && rel[1].rz_offset == rel->rz_offset) rel++; } } @@ -3088,15 +3088,15 @@ elf_xtensa_relocate_section (bfd *output_bfd, default: if (elf_hash_table (info)->dynamic_sections_created - && dynamic_symbol && (is_operand_relocation (r_type) - || r_type == R_XTENSA_32_PCREL)) + && dynamic_symbol && (is_operand_relocation (rz_type) + || rz_type == R_XTENSA_32_PCREL)) { error_message = vsprint_msg ("invalid relocation for dynamic symbol", ": %s", strlen (name) + 2, name); if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; continue; } @@ -3110,26 +3110,26 @@ elf_xtensa_relocate_section (bfd *output_bfd, && !((input_section->flags & SEC_DEBUGGING) != 0 && h->def_dynamic) && _bfd_elf_section_offset (output_bfd, info, input_section, - rel->r_offset) != (bfd_vma) -1) + rel->rz_offset) != (bfd_vma) -1) { (*_bfd_error_handler) (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), input_bfd, input_section, - (long) rel->r_offset, + (long) rel->rz_offset, howto->name, name); return FALSE; } - /* TLS optimizations may have changed r_type; update "howto". */ - howto = &elf_howto_table[r_type]; + /* TLS optimizations may have changed rz_type; update "howto". */ + howto = &elf_howto_table[rz_type]; /* There's no point in calling bfd_perform_relocation here. Just go directly to our "special function". */ r = elf_xtensa_do_reloc (howto, input_bfd, input_section, - relocation + rel->r_addend, - contents, rel->r_offset, is_weak_undef, + relocation + rel->rz_addend, + contents, rel->rz_offset, is_weak_undef, &error_message); if (r != bfd_reloc_ok && !warned) @@ -3137,17 +3137,17 @@ elf_xtensa_relocate_section (bfd *output_bfd, BFD_ASSERT (r == bfd_reloc_dangerous || r == bfd_reloc_other); BFD_ASSERT (error_message != NULL); - if (rel->r_addend == 0) + if (rel->rz_addend == 0) error_message = vsprint_msg (error_message, ": %s", strlen (name) + 2, name); else error_message = vsprint_msg (error_message, ": (%s+0x%x)", strlen (name) + 22, - name, (int) rel->r_addend); + name, (int) rel->rz_addend); if (!((*info->callbacks->reloc_dangerous) (info, error_message, input_bfd, input_section, - rel->r_offset))) + rel->rz_offset))) return FALSE; } } @@ -3362,7 +3362,7 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd, { loc = srelgot->contents + rtld_reloc * sizeof (Elf32_External_Rela); bfd_elf32_swap_reloca_in (output_bfd, loc, &irela); - if (ELF32_R_TYPE (irela.r_info) == R_XTENSA_RTLD) + if (ELF32_R_TYPE (irela.rz_info) == R_XTENSA_RTLD) break; } BFD_ASSERT (rtld_reloc < srelgot->reloc_count); @@ -3383,10 +3383,10 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd, loc = srelgot->contents + rtld_reloc * sizeof (Elf32_External_Rela); bfd_elf32_swap_reloca_in (output_bfd, loc, &irela); - BFD_ASSERT (ELF32_R_TYPE (irela.r_info) == R_XTENSA_RTLD); - irela.r_offset = (sgotplt->output_section->vma + BFD_ASSERT (ELF32_R_TYPE (irela.rz_info) == R_XTENSA_RTLD); + irela.rz_offset = (sgotplt->output_section->vma + sgotplt->output_offset); - irela.r_addend = 1; /* tell rtld to set value to resolver function */ + irela.rz_addend = 1; /* tell rtld to set value to resolver function */ bfd_elf32_swap_reloca_out (output_bfd, &irela, loc); rtld_reloc += 1; BFD_ASSERT (rtld_reloc <= srelgot->reloc_count); @@ -3394,11 +3394,11 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd, /* Next literal immediately follows the first. */ loc += sizeof (Elf32_External_Rela); bfd_elf32_swap_reloca_in (output_bfd, loc, &irela); - BFD_ASSERT (ELF32_R_TYPE (irela.r_info) == R_XTENSA_RTLD); - irela.r_offset = (sgotplt->output_section->vma + BFD_ASSERT (ELF32_R_TYPE (irela.rz_info) == R_XTENSA_RTLD); + irela.rz_offset = (sgotplt->output_section->vma + sgotplt->output_offset + 4); /* Tell rtld to set value to object's link map. */ - irela.r_addend = 2; + irela.rz_addend = 2; bfd_elf32_swap_reloca_out (output_bfd, &irela, loc); rtld_reloc += 1; BFD_ASSERT (rtld_reloc <= srelgot->reloc_count); @@ -3649,7 +3649,7 @@ elf_xtensa_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, const asection *rel_sec ATTRIBUTE_UNUSED, const Elf_Internal_Rela *rela) { - switch ((int) ELF32_R_TYPE (rela->r_info)) + switch ((int) ELF32_R_TYPE (rela->rz_info)) { case R_XTENSA_RELATIVE: return reloc_class_relative; @@ -3710,21 +3710,21 @@ elf_xtensa_discard_info_for_section (bfd *abfd, /* The ...symbol_deleted_p function will skip over relocs but it won't adjust their offsets, so do that here. */ while (cookie->rel < cookie->relend - && cookie->rel->r_offset < offset) + && cookie->rel->rz_offset < offset) { - cookie->rel->r_offset -= removed_bytes; + cookie->rel->rz_offset -= removed_bytes; cookie->rel++; } while (cookie->rel < cookie->relend - && cookie->rel->r_offset == offset) + && cookie->rel->rz_offset == offset) { if (bfd_elf_reloc_symbol_deleted_p (offset, cookie)) { /* Remove the table entry. (If the reloc type is NONE, then the entry has already been merged with another and deleted during relaxation.) */ - if (ELF32_R_TYPE (cookie->rel->r_info) != R_XTENSA_NONE) + if (ELF32_R_TYPE (cookie->rel->rz_info) != R_XTENSA_NONE) { /* Shift the contents up. */ if (offset + entry_size < sec->size) @@ -3735,7 +3735,7 @@ elf_xtensa_discard_info_for_section (bfd *abfd, } /* Remove this relocation. */ - cookie->rel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); + cookie->rel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); } /* Adjust the relocation offset for previous removals. This @@ -3743,10 +3743,10 @@ elf_xtensa_discard_info_for_section (bfd *abfd, because it might mess up the offset comparisons there. Make sure the offset doesn't underflow in the case where the first entry is removed. */ - if (cookie->rel->r_offset >= removed_bytes) - cookie->rel->r_offset -= removed_bytes; + if (cookie->rel->rz_offset >= removed_bytes) + cookie->rel->rz_offset -= removed_bytes; else - cookie->rel->r_offset = 0; + cookie->rel->rz_offset = 0; cookie->rel++; } @@ -3757,10 +3757,10 @@ elf_xtensa_discard_info_for_section (bfd *abfd, /* Adjust any remaining relocs (shouldn't be any). */ for (; cookie->rel < cookie->relend; cookie->rel++) { - if (cookie->rel->r_offset >= removed_bytes) - cookie->rel->r_offset -= removed_bytes; + if (cookie->rel->rz_offset >= removed_bytes) + cookie->rel->rz_offset -= removed_bytes; else - cookie->rel->r_offset = 0; + cookie->rel->rz_offset = 0; } /* Clear the removed bytes. */ @@ -4019,7 +4019,7 @@ l32r_offset (bfd_vma addr, bfd_vma pc) static int -get_relocation_opnd (xtensa_opcode opcode, int r_type) +get_relocation_opnd (xtensa_opcode opcode, int rz_type) { xtensa_isa isa = xtensa_default_isa; int last_immed, last_opnd, opi; @@ -4050,9 +4050,9 @@ get_relocation_opnd (xtensa_opcode opcode, int r_type) /* If the operand number was specified in an old-style relocation, check for consistency with the operand computed above. */ - if (r_type >= R_XTENSA_OP0 && r_type <= R_XTENSA_OP2) + if (rz_type >= R_XTENSA_OP0 && rz_type <= R_XTENSA_OP2) { - int reloc_opnd = r_type - R_XTENSA_OP0; + int reloc_opnd = rz_type - R_XTENSA_OP0; if (reloc_opnd != last_immed) return XTENSA_UNDEFINED; } @@ -4062,9 +4062,9 @@ get_relocation_opnd (xtensa_opcode opcode, int r_type) int -get_relocation_slot (int r_type) +get_relocation_slot (int rz_type) { - switch (r_type) + switch (rz_type) { case R_XTENSA_OP0: case R_XTENSA_OP1: @@ -4072,10 +4072,10 @@ get_relocation_slot (int r_type) return 0; default: - if (r_type >= R_XTENSA_SLOT0_OP && r_type <= R_XTENSA_SLOT14_OP) - return r_type - R_XTENSA_SLOT0_OP; - if (r_type >= R_XTENSA_SLOT0_ALT && r_type <= R_XTENSA_SLOT14_ALT) - return r_type - R_XTENSA_SLOT0_ALT; + if (rz_type >= R_XTENSA_SLOT0_OP && rz_type <= R_XTENSA_SLOT14_OP) + return rz_type - R_XTENSA_SLOT0_OP; + if (rz_type >= R_XTENSA_SLOT0_ALT && rz_type <= R_XTENSA_SLOT14_ALT) + return rz_type - R_XTENSA_SLOT0_ALT; break; } @@ -4100,7 +4100,7 @@ get_relocation_opcode (bfd *abfd, if (contents == NULL) return XTENSA_UNDEFINED; - if (bfd_get_section_limit (abfd, sec) <= irel->r_offset) + if (bfd_get_section_limit (abfd, sec) <= irel->rz_offset) return XTENSA_UNDEFINED; if (ibuff == NULL) @@ -4110,10 +4110,10 @@ get_relocation_opcode (bfd *abfd, } /* Decode the instruction. */ - xtensa_insnbuf_from_chars (isa, ibuff, &contents[irel->r_offset], - sec->size - irel->r_offset); + xtensa_insnbuf_from_chars (isa, ibuff, &contents[irel->rz_offset], + sec->size - irel->rz_offset); fmt = xtensa_format_decode (isa, ibuff); - slot = get_relocation_slot (ELF32_R_TYPE (irel->r_info)); + slot = get_relocation_slot (ELF32_R_TYPE (irel->rz_info)); if (slot == XTENSA_UNDEFINED) return XTENSA_UNDEFINED; xtensa_format_get_slot (isa, fmt, slot, ibuff, sbuff); @@ -4128,7 +4128,7 @@ is_l32r_relocation (bfd *abfd, Elf_Internal_Rela *irel) { xtensa_opcode opcode; - if (!is_operand_relocation (ELF32_R_TYPE (irel->r_info))) + if (!is_operand_relocation (ELF32_R_TYPE (irel->rz_info))) return FALSE; opcode = get_relocation_opcode (abfd, sec, contents, irel); return (opcode == get_l32r_opcode ()); @@ -4159,17 +4159,17 @@ get_asm_simplify_size (bfd_byte *contents, bfd_boolean -is_alt_relocation (int r_type) +is_alt_relocation (int rz_type) { - return (r_type >= R_XTENSA_SLOT0_ALT - && r_type <= R_XTENSA_SLOT14_ALT); + return (rz_type >= R_XTENSA_SLOT0_ALT + && rz_type <= R_XTENSA_SLOT14_ALT); } bfd_boolean -is_operand_relocation (int r_type) +is_operand_relocation (int rz_type) { - switch (r_type) + switch (rz_type) { case R_XTENSA_OP0: case R_XTENSA_OP1: @@ -4177,9 +4177,9 @@ is_operand_relocation (int r_type) return TRUE; default: - if (r_type >= R_XTENSA_SLOT0_OP && r_type <= R_XTENSA_SLOT14_OP) + if (rz_type >= R_XTENSA_SLOT0_OP && rz_type <= R_XTENSA_SLOT14_OP) return TRUE; - if (r_type >= R_XTENSA_SLOT0_ALT && r_type <= R_XTENSA_SLOT14_ALT) + if (rz_type >= R_XTENSA_SLOT0_ALT && rz_type <= R_XTENSA_SLOT14_ALT) return TRUE; break; } @@ -4811,16 +4811,16 @@ contract_asm_expansion (bfd_byte *contents, char **error_message) { bfd_reloc_status_type retval = - elf_xtensa_do_asm_simplify (contents, irel->r_offset, content_length, + elf_xtensa_do_asm_simplify (contents, irel->rz_offset, content_length, error_message); if (retval != bfd_reloc_ok) return bfd_reloc_dangerous; - /* Update the irel->r_offset field so that the right immediate and + /* Update the irel->rz_offset field so that the right immediate and the right instruction are modified during the relocation. */ - irel->r_offset += 3; - irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_XTENSA_SLOT0_OP); + irel->rz_offset += 3; + irel->rz_info = ELF32_R_INFO (ELF32_R_SYM (irel->rz_info), R_XTENSA_SLOT0_OP); return bfd_reloc_ok; } @@ -4943,26 +4943,26 @@ get_expanded_call_opcode (bfd_byte *buf, int bufsize, bfd_boolean *p_uses_l32r) /* Data structures used during relaxation. */ -/* r_reloc: relocation values. */ +/* rz_reloc: relocation values. */ /* Through the relaxation process, we need to keep track of the values that will result from evaluating relocations. The standard ELF relocation structure is not sufficient for this purpose because we're operating on multiple input files at once, so we need to know which - input file a relocation refers to. The r_reloc structure thus + input file a relocation refers to. The rz_reloc structure thus records both the input file (bfd) and ELF relocation. - For efficiency, an r_reloc also contains a "target_offset" field to + For efficiency, an rz_reloc also contains a "target_offset" field to cache the target-section-relative offset value that is represented by the relocation. - The r_reloc also contains a virtual offset that allows multiple + The rz_reloc also contains a virtual offset that allows multiple inserted literals to be placed at the same "address" with different offsets. */ -typedef struct r_reloc_struct r_reloc; +typedef struct rz_reloc_struct rz_reloc; -struct r_reloc_struct +struct rz_reloc_struct { bfd *abfd; Elf_Internal_Rela rela; @@ -4971,56 +4971,56 @@ struct r_reloc_struct }; -/* The r_reloc structure is included by value in literal_value, but not +/* The rz_reloc structure is included by value in literal_value, but not every literal_value has an associated relocation -- some are simple - constants. In such cases, we set all the fields in the r_reloc - struct to zero. The r_reloc_is_const function should be used to + constants. In such cases, we set all the fields in the rz_reloc + struct to zero. The rz_reloc_is_const function should be used to detect this case. */ static bfd_boolean -r_reloc_is_const (const r_reloc *r_rel) +rz_reloc_is_const (const rz_reloc *rz_rel) { - return (r_rel->abfd == NULL); + return (rz_rel->abfd == NULL); } static bfd_vma -r_reloc_get_target_offset (const r_reloc *r_rel) +rz_reloc_get_target_offset (const rz_reloc *rz_rel) { bfd_vma target_offset; - unsigned long r_symndx; + unsigned long rz_symndx; - BFD_ASSERT (!r_reloc_is_const (r_rel)); - r_symndx = ELF32_R_SYM (r_rel->rela.r_info); - target_offset = get_elf_r_symndx_offset (r_rel->abfd, r_symndx); - return (target_offset + r_rel->rela.r_addend); + BFD_ASSERT (!rz_reloc_is_const (rz_rel)); + rz_symndx = ELF32_R_SYM (rz_rel->rela.rz_info); + target_offset = get_elf_r_symndx_offset (rz_rel->abfd, rz_symndx); + return (target_offset + rz_rel->rela.rz_addend); } static struct elf_link_hash_entry * -r_reloc_get_hash_entry (const r_reloc *r_rel) +rz_reloc_get_hash_entry (const rz_reloc *rz_rel) { - unsigned long r_symndx = ELF32_R_SYM (r_rel->rela.r_info); - return get_elf_r_symndx_hash_entry (r_rel->abfd, r_symndx); + unsigned long rz_symndx = ELF32_R_SYM (rz_rel->rela.rz_info); + return get_elf_r_symndx_hash_entry (rz_rel->abfd, rz_symndx); } static asection * -r_reloc_get_section (const r_reloc *r_rel) +rz_reloc_get_section (const rz_reloc *rz_rel) { - unsigned long r_symndx = ELF32_R_SYM (r_rel->rela.r_info); - return get_elf_r_symndx_section (r_rel->abfd, r_symndx); + unsigned long rz_symndx = ELF32_R_SYM (rz_rel->rela.rz_info); + return get_elf_r_symndx_section (rz_rel->abfd, rz_symndx); } static bfd_boolean -r_reloc_is_defined (const r_reloc *r_rel) +rz_reloc_is_defined (const rz_reloc *rz_rel) { asection *sec; - if (r_rel == NULL) + if (rz_rel == NULL) return FALSE; - sec = r_reloc_get_section (r_rel); + sec = rz_reloc_get_section (rz_rel); if (sec == bfd_abs_section_ptr || sec == bfd_com_section_ptr || sec == bfd_und_section_ptr) @@ -5030,57 +5030,57 @@ r_reloc_is_defined (const r_reloc *r_rel) static void -r_reloc_init (r_reloc *r_rel, +rz_reloc_init (rz_reloc *rz_rel, bfd *abfd, Elf_Internal_Rela *irel, bfd_byte *contents, bfd_size_type content_length) { - int r_type; + int rz_type; reloc_howto_type *howto; if (irel) { - r_rel->rela = *irel; - r_rel->abfd = abfd; - r_rel->target_offset = r_reloc_get_target_offset (r_rel); - r_rel->virtual_offset = 0; - r_type = ELF32_R_TYPE (r_rel->rela.r_info); - howto = &elf_howto_table[r_type]; + rz_rel->rela = *irel; + rz_rel->abfd = abfd; + rz_rel->target_offset = rz_reloc_get_target_offset (rz_rel); + rz_rel->virtual_offset = 0; + rz_type = ELF32_R_TYPE (rz_rel->rela.rz_info); + howto = &elf_howto_table[rz_type]; if (howto->partial_inplace) { bfd_vma inplace_val; - BFD_ASSERT (r_rel->rela.r_offset < content_length); + BFD_ASSERT (rz_rel->rela.rz_offset < content_length); - inplace_val = bfd_get_32 (abfd, &contents[r_rel->rela.r_offset]); - r_rel->target_offset += inplace_val; + inplace_val = bfd_get_32 (abfd, &contents[rz_rel->rela.rz_offset]); + rz_rel->target_offset += inplace_val; } } else - memset (r_rel, 0, sizeof (r_reloc)); + memset (rz_rel, 0, sizeof (rz_reloc)); } #if DEBUG static void -print_r_reloc (FILE *fp, const r_reloc *r_rel) +print_r_reloc (FILE *fp, const rz_reloc *rz_rel) { - if (r_reloc_is_defined (r_rel)) + if (rz_reloc_is_defined (rz_rel)) { - asection *sec = r_reloc_get_section (r_rel); + asection *sec = rz_reloc_get_section (rz_rel); fprintf (fp, " %s(%s + ", sec->owner->filename, sec->name); } - else if (r_reloc_get_hash_entry (r_rel)) - fprintf (fp, " %s + ", r_reloc_get_hash_entry (r_rel)->root.root.string); + else if (rz_reloc_get_hash_entry (rz_rel)) + fprintf (fp, " %s + ", rz_reloc_get_hash_entry (rz_rel)->root.root.string); else fprintf (fp, " ?? + "); - fprintf_vma (fp, r_rel->target_offset); - if (r_rel->virtual_offset) + fprintf_vma (fp, rz_rel->target_offset); + if (rz_rel->virtual_offset) { fprintf (fp, " + "); - fprintf_vma (fp, r_rel->virtual_offset); + fprintf_vma (fp, rz_rel->virtual_offset); } fprintf (fp, ")"); @@ -5097,8 +5097,8 @@ print_r_reloc (FILE *fp, const r_reloc *r_rel) source_reloc entries are kept in a per-literal-section array, sorted by offset within the literal section (i.e., target offset). - The source_sec and r_rel.rela.r_offset fields identify the source of - the relocation. The r_rel field records the relocation value, i.e., + The source_sec and rz_rel.rela.rz_offset fields identify the source of + the relocation. The rz_rel field records the relocation value, i.e., the offset of the literal being referenced. The opnd field is needed to determine the range of the immediate field to which the relocation applies, so we can determine whether another literal with the same @@ -5111,7 +5111,7 @@ typedef struct source_reloc_struct source_reloc; struct source_reloc_struct { asection *source_sec; - r_reloc r_rel; + rz_reloc rz_rel; xtensa_opcode opcode; int opnd; bfd_boolean is_null; @@ -5122,13 +5122,13 @@ struct source_reloc_struct static void init_source_reloc (source_reloc *reloc, asection *source_sec, - const r_reloc *r_rel, + const rz_reloc *rz_rel, xtensa_opcode opcode, int opnd, bfd_boolean is_abs_literal) { reloc->source_sec = source_sec; - reloc->r_rel = *r_rel; + reloc->rz_rel = *rz_rel; reloc->opcode = opcode; reloc->opnd = opnd; reloc->is_null = FALSE; @@ -5151,9 +5151,9 @@ find_source_reloc (source_reloc *src_relocs, for (i = 0; i < src_count; i++) { if (src_relocs[i].source_sec == sec - && src_relocs[i].r_rel.rela.r_offset == irel->r_offset - && (ELF32_R_TYPE (src_relocs[i].r_rel.rela.r_info) - == ELF32_R_TYPE (irel->r_info))) + && src_relocs[i].rz_rel.rela.rz_offset == irel->rz_offset + && (ELF32_R_TYPE (src_relocs[i].rz_rel.rela.rz_info) + == ELF32_R_TYPE (irel->rz_info))) return &src_relocs[i]; } @@ -5167,8 +5167,8 @@ source_reloc_compare (const void *ap, const void *bp) const source_reloc *a = (const source_reloc *) ap; const source_reloc *b = (const source_reloc *) bp; - if (a->r_rel.target_offset != b->r_rel.target_offset) - return (a->r_rel.target_offset - b->r_rel.target_offset); + if (a->rz_rel.target_offset != b->rz_rel.target_offset) + return (a->rz_rel.target_offset - b->rz_rel.target_offset); /* We don't need to sort on these criteria for correctness, but enforcing a more strict ordering prevents unstable qsort @@ -5179,14 +5179,14 @@ source_reloc_compare (const void *ap, const void *bp) if ((!a->is_null) - (!b->is_null)) return ((!a->is_null) - (!b->is_null)); - return internal_reloc_compare (&a->r_rel.rela, &b->r_rel.rela); + return internal_reloc_compare (&a->rz_rel.rela, &b->rz_rel.rela); } /* Literal values and value hash tables. */ /* Literals with the same value can be coalesced. The literal_value - structure records the value of a literal: the "r_rel" field holds the + structure records the value of a literal: the "rz_rel" field holds the information from the relocation on the literal (if there is one) and the "value" field holds the contents of the literal word itself. @@ -5202,7 +5202,7 @@ typedef struct value_map_hash_table_struct value_map_hash_table; struct literal_value_struct { - r_reloc r_rel; + rz_reloc rz_rel; unsigned long value; bfd_boolean is_abs_literal; }; @@ -5210,7 +5210,7 @@ struct literal_value_struct struct value_map_struct { literal_value val; /* The literal value. */ - r_reloc loc; /* Location of the literal. */ + rz_reloc loc; /* Location of the literal. */ value_map *next; }; @@ -5220,17 +5220,17 @@ struct value_map_hash_table_struct value_map **buckets; unsigned count; bfd_boolean has_last_loc; - r_reloc last_loc; + rz_reloc last_loc; }; static void init_literal_value (literal_value *lit, - const r_reloc *r_rel, + const rz_reloc *rz_rel, unsigned long value, bfd_boolean is_abs_literal) { - lit->r_rel = *r_rel; + lit->rz_rel = *rz_rel; lit->value = value; lit->is_abs_literal = is_abs_literal; } @@ -5243,20 +5243,20 @@ literal_value_equal (const literal_value *src1, { struct elf_link_hash_entry *h1, *h2; - if (r_reloc_is_const (&src1->r_rel) != r_reloc_is_const (&src2->r_rel)) + if (rz_reloc_is_const (&src1->rz_rel) != rz_reloc_is_const (&src2->rz_rel)) return FALSE; - if (r_reloc_is_const (&src1->r_rel)) + if (rz_reloc_is_const (&src1->rz_rel)) return (src1->value == src2->value); - if (ELF32_R_TYPE (src1->r_rel.rela.r_info) - != ELF32_R_TYPE (src2->r_rel.rela.r_info)) + if (ELF32_R_TYPE (src1->rz_rel.rela.rz_info) + != ELF32_R_TYPE (src2->rz_rel.rela.rz_info)) return FALSE; - if (src1->r_rel.target_offset != src2->r_rel.target_offset) + if (src1->rz_rel.target_offset != src2->rz_rel.target_offset) return FALSE; - if (src1->r_rel.virtual_offset != src2->r_rel.virtual_offset) + if (src1->rz_rel.virtual_offset != src2->rz_rel.virtual_offset) return FALSE; if (src1->value != src2->value) @@ -5264,15 +5264,15 @@ literal_value_equal (const literal_value *src1, /* Now check for the same section (if defined) or the same elf_hash (if undefined or weak). */ - h1 = r_reloc_get_hash_entry (&src1->r_rel); - h2 = r_reloc_get_hash_entry (&src2->r_rel); - if (r_reloc_is_defined (&src1->r_rel) + h1 = rz_reloc_get_hash_entry (&src1->rz_rel); + h2 = rz_reloc_get_hash_entry (&src2->rz_rel); + if (rz_reloc_is_defined (&src1->rz_rel) && (final_static_link || ((!h1 || h1->root.type != bfd_link_hash_defweak) && (!h2 || h2->root.type != bfd_link_hash_defweak)))) { - if (r_reloc_get_section (&src1->r_rel) - != r_reloc_get_section (&src2->r_rel)) + if (rz_reloc_get_section (&src1->rz_rel) + != rz_reloc_get_section (&src2->rz_rel)) return FALSE; } else @@ -5335,19 +5335,19 @@ literal_value_hash (const literal_value *src) unsigned hash_val; hash_val = hash_bfd_vma (src->value); - if (!r_reloc_is_const (&src->r_rel)) + if (!rz_reloc_is_const (&src->rz_rel)) { void *sec_or_hash; hash_val += hash_bfd_vma (src->is_abs_literal * 1000); - hash_val += hash_bfd_vma (src->r_rel.target_offset); - hash_val += hash_bfd_vma (src->r_rel.virtual_offset); + hash_val += hash_bfd_vma (src->rz_rel.target_offset); + hash_val += hash_bfd_vma (src->rz_rel.virtual_offset); /* Now check for the same section and the same elf_hash. */ - if (r_reloc_is_defined (&src->r_rel)) - sec_or_hash = r_reloc_get_section (&src->r_rel); + if (rz_reloc_is_defined (&src->rz_rel)) + sec_or_hash = rz_reloc_get_section (&src->rz_rel); else - sec_or_hash = r_reloc_get_hash_entry (&src->r_rel); + sec_or_hash = rz_reloc_get_hash_entry (&src->rz_rel); hash_val += hash_bfd_vma ((bfd_vma) (size_t) sec_or_hash); } return hash_val; @@ -5383,7 +5383,7 @@ value_map_get_cached_value (value_map_hash_table *map, static value_map * add_value_map (value_map_hash_table *map, const literal_value *val, - const r_reloc *loc, + const rz_reloc *loc, bfd_boolean final_static_link) { value_map **bucket_p; @@ -5653,12 +5653,12 @@ text_action_add (text_action_list *l, static void text_action_add_literal (text_action_list *l, text_action_t action, - const r_reloc *loc, + const rz_reloc *loc, const literal_value *value, int removed) { text_action *ta; - asection *sec = r_reloc_get_section (loc); + asection *sec = rz_reloc_get_section (loc); bfd_vma offset = loc->target_offset; bfd_vma virtual_offset = loc->virtual_offset; @@ -5939,8 +5939,8 @@ typedef struct removed_literal_list_struct removed_literal_list; struct removed_literal_struct { - r_reloc from; - r_reloc to; + rz_reloc from; + rz_reloc to; removed_literal *next; }; @@ -5965,8 +5965,8 @@ struct removed_literal_list_struct static void add_removed_literal (removed_literal_list *removed_list, - const r_reloc *from, - const r_reloc *to) + const rz_reloc *from, + const rz_reloc *to) { removed_literal *r, *new_r, *next_r; @@ -6610,7 +6610,7 @@ extend_ebb_bounds_forward (ebb_t *ebb) /* Update the reloc counter. */ while (ebb->end_reloc_idx + 1 < ebb->reloc_count - && (ebb->relocs[ebb->end_reloc_idx + 1].r_offset + && (ebb->relocs[ebb->end_reloc_idx + 1].rz_offset < ebb->end_offset)) { ebb->end_reloc_idx++; @@ -6683,7 +6683,7 @@ extend_ebb_bounds_backward (ebb_t *ebb) /* Update the reloc counter. */ while (ebb->start_reloc_idx > 0 - && (ebb->relocs[ebb->start_reloc_idx - 1].r_offset + && (ebb->relocs[ebb->start_reloc_idx - 1].rz_offset >= ebb->start_offset)) { ebb->start_reloc_idx--; @@ -6914,18 +6914,18 @@ static bfd_boolean identify_literal_placement value_map_hash_table *, bfd_boolean *, Elf_Internal_Rela *, int, source_reloc *, property_table_entry *, int, section_cache_t *, bfd_boolean); -static bfd_boolean relocations_reach (source_reloc *, int, const r_reloc *); +static bfd_boolean relocations_reach (source_reloc *, int, const rz_reloc *); static bfd_boolean coalesce_shared_literal (asection *, source_reloc *, property_table_entry *, int, value_map *); static bfd_boolean move_shared_literal (asection *, struct bfd_link_info *, source_reloc *, property_table_entry *, - int, const r_reloc *, const literal_value *, section_cache_t *); + int, const rz_reloc *, const literal_value *, section_cache_t *); /* Second pass: */ static bfd_boolean relax_section (bfd *, asection *, struct bfd_link_info *); static bfd_boolean translate_section_fixes (asection *); static bfd_boolean translate_reloc_bfd_fix (reloc_bfd_fix *); -static asection *translate_reloc (const r_reloc *, r_reloc *, asection *); +static asection *translate_reloc (const rz_reloc *, rz_reloc *, asection *); static void shrink_dynamic_reloc_sections (struct bfd_link_info *, bfd *, asection *, Elf_Internal_Rela *); static bfd_boolean move_literal @@ -7115,7 +7115,7 @@ find_relaxable_sections (bfd *abfd, for (i = 0; i < sec->reloc_count; i++) { Elf_Internal_Rela *irel = &internal_relocs[i]; - r_reloc r_rel; + rz_reloc rz_rel; asection *target_sec; xtensa_relax_info *target_relax_info; @@ -7125,7 +7125,7 @@ find_relaxable_sections (bfd *abfd, the section as "relaxable". */ if (source_relax_info && !source_relax_info->is_relaxable_asm_section - && ELF32_R_TYPE (irel->r_info) == R_XTENSA_ASM_EXPAND) + && ELF32_R_TYPE (irel->rz_info) == R_XTENSA_ASM_EXPAND) { bfd_boolean is_reachable = FALSE; if (is_resolvable_asm_expansion (abfd, sec, contents, irel, @@ -7137,10 +7137,10 @@ find_relaxable_sections (bfd *abfd, } } - r_reloc_init (&r_rel, abfd, irel, contents, + rz_reloc_init (&rz_rel, abfd, irel, contents, bfd_get_section_limit (abfd, sec)); - target_sec = r_reloc_get_section (&r_rel); + target_sec = rz_reloc_get_section (&rz_rel); target_relax_info = get_xtensa_relax_info (target_sec); if (!target_relax_info) continue; @@ -7149,20 +7149,20 @@ find_relaxable_sections (bfd *abfd, Note: The conditions tested here must match the conditions under which init_source_reloc is called in collect_source_relocs(). */ is_l32r_reloc = FALSE; - if (is_operand_relocation (ELF32_R_TYPE (irel->r_info))) + if (is_operand_relocation (ELF32_R_TYPE (irel->rz_info))) { xtensa_opcode opcode = get_relocation_opcode (abfd, sec, contents, irel); if (opcode != XTENSA_UNDEFINED) { is_l32r_reloc = (opcode == get_l32r_opcode ()); - if (!is_alt_relocation (ELF32_R_TYPE (irel->r_info)) + if (!is_alt_relocation (ELF32_R_TYPE (irel->rz_info)) || is_l32r_reloc) target_relax_info->src_count++; } } - if (is_l32r_reloc && r_reloc_is_defined (&r_rel)) + if (is_l32r_reloc && rz_reloc_is_defined (&rz_rel)) { /* Mark the target section as relaxable. */ target_relax_info->is_relaxable_literal_section = TRUE; @@ -7209,13 +7209,13 @@ collect_source_relocs (bfd *abfd, for (i = 0; i < sec->reloc_count; i++) { Elf_Internal_Rela *irel = &internal_relocs[i]; - r_reloc r_rel; + rz_reloc rz_rel; asection *target_sec; xtensa_relax_info *target_relax_info; - r_reloc_init (&r_rel, abfd, irel, contents, sec_size); + rz_reloc_init (&rz_rel, abfd, irel, contents, sec_size); - target_sec = r_reloc_get_section (&r_rel); + target_sec = rz_reloc_get_section (&rz_rel); target_relax_info = get_xtensa_relax_info (target_sec); if (target_relax_info @@ -7226,7 +7226,7 @@ collect_source_relocs (bfd *abfd, int opnd = -1; bfd_boolean is_abs_literal = FALSE; - if (is_alt_relocation (ELF32_R_TYPE (irel->r_info))) + if (is_alt_relocation (ELF32_R_TYPE (irel->rz_info))) { /* None of the current alternate relocs are PC-relative, and only PC-relative relocs matter here. However, we @@ -7241,10 +7241,10 @@ collect_source_relocs (bfd *abfd, else opcode = XTENSA_UNDEFINED; } - else if (is_operand_relocation (ELF32_R_TYPE (irel->r_info))) + else if (is_operand_relocation (ELF32_R_TYPE (irel->rz_info))) { opcode = get_relocation_opcode (abfd, sec, contents, irel); - opnd = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->r_info)); + opnd = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->rz_info)); } if (opcode != XTENSA_UNDEFINED) @@ -7252,7 +7252,7 @@ collect_source_relocs (bfd *abfd, int src_next = target_relax_info->src_next++; source_reloc *s_reloc = &target_relax_info->src_relocs[src_next]; - init_source_reloc (s_reloc, sec, &r_rel, opcode, opnd, + init_source_reloc (s_reloc, sec, &rz_rel, opcode, opnd, is_abs_literal); } } @@ -7276,7 +7276,7 @@ collect_source_relocs (bfd *abfd, if (is_reachable) { Elf_Internal_Rela *l32r_irel; - r_reloc r_rel; + rz_reloc rz_rel; asection *target_sec; xtensa_relax_info *target_relax_info; @@ -7288,9 +7288,9 @@ collect_source_relocs (bfd *abfd, if (l32r_irel == NULL) continue; - r_reloc_init (&r_rel, abfd, l32r_irel, contents, sec_size); + rz_reloc_init (&rz_rel, abfd, l32r_irel, contents, sec_size); - target_sec = r_reloc_get_section (&r_rel); + target_sec = rz_reloc_get_section (&rz_rel); target_relax_info = get_xtensa_relax_info (target_sec); if (target_relax_info @@ -7311,9 +7311,9 @@ collect_source_relocs (bfd *abfd, } /* Convert this reloc to ASM_SIMPLIFY. */ - irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), + irel->rz_info = ELF32_R_INFO (ELF32_R_SYM (irel->rz_info), R_XTENSA_ASM_SIMPLIFY); - l32r_irel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); + l32r_irel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); pin_internal_relocs (sec, internal_relocs); } @@ -7322,7 +7322,7 @@ collect_source_relocs (bfd *abfd, /* It is resolvable but doesn't reach. We resolve now by eliminating the relocation -- the call will remain expanded into L32R/CALLX. */ - irel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); + irel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); pin_internal_relocs (sec, internal_relocs); } } @@ -7350,7 +7350,7 @@ is_resolvable_asm_expansion (bfd *abfd, { asection *target_sec; bfd_vma target_offset; - r_reloc r_rel; + rz_reloc rz_rel; xtensa_opcode opcode, direct_call_opcode; bfd_vma self_address; bfd_vma dest_address; @@ -7362,12 +7362,12 @@ is_resolvable_asm_expansion (bfd *abfd, if (contents == NULL) return FALSE; - if (ELF32_R_TYPE (irel->r_info) != R_XTENSA_ASM_EXPAND) + if (ELF32_R_TYPE (irel->rz_info) != R_XTENSA_ASM_EXPAND) return FALSE; sec_size = bfd_get_section_limit (abfd, sec); - opcode = get_expanded_call_opcode (contents + irel->r_offset, - sec_size - irel->r_offset, &uses_l32r); + opcode = get_expanded_call_opcode (contents + irel->rz_offset, + sec_size - irel->rz_offset, &uses_l32r); /* Optimization of longcalls that use CONST16 is not yet implemented. */ if (!uses_l32r) return FALSE; @@ -7377,12 +7377,12 @@ is_resolvable_asm_expansion (bfd *abfd, return FALSE; /* Check and see that the target resolves. */ - r_reloc_init (&r_rel, abfd, irel, contents, sec_size); - if (!r_reloc_is_defined (&r_rel)) + rz_reloc_init (&rz_rel, abfd, irel, contents, sec_size); + if (!rz_reloc_is_defined (&rz_rel)) return FALSE; - target_sec = r_reloc_get_section (&r_rel); - target_offset = r_rel.target_offset; + target_sec = rz_reloc_get_section (&rz_rel); + target_offset = rz_rel.target_offset; /* If the target is in a shared library, then it doesn't reach. This isn't supposed to come up because the compiler should never generate @@ -7422,7 +7422,7 @@ is_resolvable_asm_expansion (bfd *abfd, self_address = sec->output_section->vma; if (sec->output_section->vma > target_sec->output_section->vma) - self_address += sec->output_offset + irel->r_offset + 3; + self_address += sec->output_offset + irel->rz_offset + 3; else dest_address += bfd_get_section_limit (abfd, target_sec->output_section); /* Call targets should be four-byte aligned. */ @@ -7432,7 +7432,7 @@ is_resolvable_asm_expansion (bfd *abfd, { self_address = (sec->output_section->vma - + sec->output_offset + irel->r_offset + 3); + + sec->output_offset + irel->rz_offset + 3); dest_address = (target_sec->output_section->vma + target_sec->output_offset + target_offset); } @@ -7463,7 +7463,7 @@ find_associated_l32r_irel (bfd *abfd, if (irel == other_irel) continue; - if (irel->r_offset != other_irel->r_offset) + if (irel->rz_offset != other_irel->rz_offset) continue; if (is_l32r_relocation (abfd, sec, contents, irel)) return irel; @@ -7558,19 +7558,19 @@ build_reloc_ranges (bfd *abfd, asection *sec, for (i = 0; i < sec->reloc_count; i++) { Elf_Internal_Rela *irel = &internal_relocs[i]; - int r_type = ELF32_R_TYPE (irel->r_info); - reloc_howto_type *howto = &elf_howto_table[r_type]; - r_reloc r_rel; + int rz_type = ELF32_R_TYPE (irel->rz_info); + reloc_howto_type *howto = &elf_howto_table[rz_type]; + rz_reloc rz_rel; - if (r_type == R_XTENSA_ASM_SIMPLIFY - || r_type == R_XTENSA_32_PCREL + if (rz_type == R_XTENSA_ASM_SIMPLIFY + || rz_type == R_XTENSA_32_PCREL || !howto->pc_relative) continue; - r_reloc_init (&r_rel, abfd, irel, contents, + rz_reloc_init (&rz_rel, abfd, irel, contents, bfd_get_section_limit (abfd, sec)); - if (r_reloc_get_section (&r_rel) != sec) + if (rz_reloc_get_section (&rz_rel) != sec) continue; if (n + 2 > max_n) @@ -7579,8 +7579,8 @@ build_reloc_ranges (bfd *abfd, asection *sec, ranges = bfd_realloc (ranges, max_n * sizeof (*ranges)); } - ranges[n].addr = irel->r_offset; - ranges[n + 1].addr = r_rel.target_offset; + ranges[n].addr = irel->rz_offset; + ranges[n + 1].addr = rz_rel.target_offset; ranges[n].add = ranges[n].addr < ranges[n + 1].addr; ranges[n + 1].add = !ranges[n].add; @@ -7594,7 +7594,7 @@ build_reloc_ranges (bfd *abfd, asection *sec, /* Every relocation won't possibly be checked in the optimized version of check_section_ebb_pcrels_fit, so this needs to be done here. */ - if (is_alt_relocation (ELF32_R_TYPE (irel->r_info))) + if (is_alt_relocation (ELF32_R_TYPE (irel->rz_info))) { /* None of the current alternate relocs are PC-relative, and only PC-relative relocs matter here. */ @@ -7615,7 +7615,7 @@ build_reloc_ranges (bfd *abfd, asection *sec, break; } - opnum = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->r_info)); + opnum = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->rz_info)); if (opnum == XTENSA_UNDEFINED) { list->ok = FALSE; @@ -7773,34 +7773,34 @@ compute_text_actions (bfd *abfd, for (i = 0; i < sec->reloc_count; i++) { Elf_Internal_Rela *irel = &internal_relocs[i]; - bfd_vma r_offset; + bfd_vma rz_offset; property_table_entry *the_entry; int ptbl_idx; ebb_t *ebb; ebb_constraint ebb_table; bfd_size_type simplify_size; - if (irel && ELF32_R_TYPE (irel->r_info) != R_XTENSA_ASM_SIMPLIFY) + if (irel && ELF32_R_TYPE (irel->rz_info) != R_XTENSA_ASM_SIMPLIFY) continue; - r_offset = irel->r_offset; + rz_offset = irel->rz_offset; - simplify_size = get_asm_simplify_size (contents, sec_size, r_offset); + simplify_size = get_asm_simplify_size (contents, sec_size, rz_offset); if (simplify_size == 0) { (*_bfd_error_handler) (_("%B(%A+0x%lx): could not decode instruction for XTENSA_ASM_SIMPLIFY relocation; possible configuration mismatch"), - sec->owner, sec, r_offset); + sec->owner, sec, rz_offset); continue; } /* If the instruction table is not around, then don't do this relaxation. */ the_entry = elf_xtensa_find_property_entry (prop_table, ptblsize, - sec->vma + irel->r_offset); + sec->vma + irel->rz_offset); if (the_entry == NULL || XTENSA_NO_NOP_REMOVAL) { text_action_add (&relax_info->action_list, - ta_convert_longcall, sec, r_offset, + ta_convert_longcall, sec, rz_offset, 0); continue; } @@ -7826,8 +7826,8 @@ compute_text_actions (bfd *abfd, ebb = &ebb_table.ebb; init_ebb (ebb, sec, contents, sec_size, prop_table, ptblsize, internal_relocs, sec->reloc_count); - ebb->start_offset = r_offset + simplify_size; - ebb->end_offset = r_offset + simplify_size; + ebb->start_offset = rz_offset + simplify_size; + ebb->end_offset = rz_offset + simplify_size; ebb->start_ptbl_idx = ptbl_idx; ebb->end_ptbl_idx = ptbl_idx; ebb->start_reloc_idx = i; @@ -7847,7 +7847,7 @@ compute_text_actions (bfd *abfd, critical branches, just convert to a NOP. */ text_action_add (&relax_info->action_list, - ta_convert_longcall, sec, r_offset, 0); + ta_convert_longcall, sec, rz_offset, 0); i = ebb_table.ebb.end_reloc_idx; free_ebb_constraint (&ebb_table); continue; @@ -7960,22 +7960,22 @@ compute_ebb_proposed_actions (ebb_constraint *ebb_table) xtensa_opcode opcode; while (rel_idx < ebb->end_reloc_idx - && (ebb->relocs[rel_idx].r_offset < offset - || (ebb->relocs[rel_idx].r_offset == offset - && (ELF32_R_TYPE (ebb->relocs[rel_idx].r_info) + && (ebb->relocs[rel_idx].rz_offset < offset + || (ebb->relocs[rel_idx].rz_offset == offset + && (ELF32_R_TYPE (ebb->relocs[rel_idx].rz_info) != R_XTENSA_ASM_SIMPLIFY)))) rel_idx++; /* Check for longcall. */ irel = &ebb->relocs[rel_idx]; - if (irel->r_offset == offset - && ELF32_R_TYPE (irel->r_info) == R_XTENSA_ASM_SIMPLIFY) + if (irel->rz_offset == offset + && ELF32_R_TYPE (irel->rz_info) == R_XTENSA_ASM_SIMPLIFY) { bfd_size_type simplify_size; simplify_size = get_asm_simplify_size (ebb->contents, ebb->content_length, - irel->r_offset); + irel->rz_offset); if (simplify_size == 0) goto decode_error; @@ -8534,10 +8534,10 @@ check_section_ebb_pcrels_fit (bfd *abfd, for (i = 0; i < n; i++) { - r_reloc r_rel; + rz_reloc rz_rel; bfd_vma orig_self_offset, orig_target_offset; bfd_vma self_offset, target_offset; - int r_type; + int rz_type; reloc_howto_type *howto; int self_removed_bytes, target_removed_bytes; @@ -8550,26 +8550,26 @@ check_section_ebb_pcrels_fit (bfd *abfd, { irel = internal_relocs + i; } - r_type = ELF32_R_TYPE (irel->r_info); + rz_type = ELF32_R_TYPE (irel->rz_info); - howto = &elf_howto_table[r_type]; + howto = &elf_howto_table[rz_type]; /* We maintain the required invariant: PC-relative relocations that fit before linking must fit after linking. Thus we only need to deal with relocations to the same section that are PC-relative. */ - if (r_type == R_XTENSA_ASM_SIMPLIFY - || r_type == R_XTENSA_32_PCREL + if (rz_type == R_XTENSA_ASM_SIMPLIFY + || rz_type == R_XTENSA_32_PCREL || !howto->pc_relative) continue; - r_reloc_init (&r_rel, abfd, irel, contents, + rz_reloc_init (&rz_rel, abfd, irel, contents, bfd_get_section_limit (abfd, sec)); - if (r_reloc_get_section (&r_rel) != sec) + if (rz_reloc_get_section (&rz_rel) != sec) continue; - orig_self_offset = irel->r_offset; - orig_target_offset = r_rel.target_offset; + orig_self_offset = irel->rz_offset; + orig_target_offset = rz_rel.target_offset; self_offset = orig_self_offset; target_offset = orig_target_offset; @@ -8605,7 +8605,7 @@ check_section_ebb_pcrels_fit (bfd *abfd, target_offset -= target_removed_bytes; /* Try to encode it. Get the operand and check. */ - if (is_alt_relocation (ELF32_R_TYPE (irel->r_info))) + if (is_alt_relocation (ELF32_R_TYPE (irel->rz_info))) { /* None of the current alternate relocs are PC-relative, and only PC-relative relocs matter here. */ @@ -8633,7 +8633,7 @@ check_section_ebb_pcrels_fit (bfd *abfd, break; } - opnum = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->r_info)); + opnum = get_relocation_opnd (opcode, ELF32_R_TYPE (irel->rz_info)); if (opnum == XTENSA_UNDEFINED) { ok = FALSE; @@ -8806,25 +8806,25 @@ compute_removed_literals (bfd *abfd, if (get_l32r_opcode () != rel->opcode) continue; irel = get_irel_at_offset (sec, internal_relocs, - rel->r_rel.target_offset); + rel->rz_rel.target_offset); /* If the relocation on this is not a simple R_XTENSA_32 or R_XTENSA_PLT then do not consider it. This may happen when the difference of two symbols is used in a literal. */ - if (irel && (ELF32_R_TYPE (irel->r_info) != R_XTENSA_32 - && ELF32_R_TYPE (irel->r_info) != R_XTENSA_PLT)) + if (irel && (ELF32_R_TYPE (irel->rz_info) != R_XTENSA_32 + && ELF32_R_TYPE (irel->rz_info) != R_XTENSA_PLT)) continue; /* If the target_offset for this relocation is the same as the previous relocation, then we've already considered whether the literal can be coalesced. Skip to the next one.... */ if (i != 0 && prev_i != -1 - && src_relocs[i-1].r_rel.target_offset == rel->r_rel.target_offset) + && src_relocs[i-1].rz_rel.target_offset == rel->rz_rel.target_offset) continue; prev_i = i; if (last_loc_is_prev && - last_target_offset + 4 != rel->r_rel.target_offset) + last_target_offset + 4 != rel->rz_rel.target_offset) last_loc_is_prev = FALSE; /* Check if the relocation was from an L32R that is being removed @@ -8839,7 +8839,7 @@ compute_removed_literals (bfd *abfd, ok = FALSE; goto error_return; } - last_target_offset = rel->r_rel.target_offset; + last_target_offset = rel->rz_rel.target_offset; continue; } @@ -8853,7 +8853,7 @@ compute_removed_literals (bfd *abfd, ok = FALSE; goto error_return; } - last_target_offset = rel->r_rel.target_offset; + last_target_offset = rel->rz_rel.target_offset; } #if DEBUG @@ -8879,13 +8879,13 @@ get_irel_at_offset (asection *sec, { unsigned i; Elf_Internal_Rela *irel; - unsigned r_type; + unsigned rz_type; Elf_Internal_Rela key; if (!internal_relocs) return NULL; - key.r_offset = offset; + key.rz_offset = offset; irel = bsearch (&key, internal_relocs, sec->reloc_count, sizeof (Elf_Internal_Rela), internal_reloc_matches); if (!irel) @@ -8896,15 +8896,15 @@ get_irel_at_offset (asection *sec, i = irel - internal_relocs; while (i > 0) { - if (internal_relocs[i-1].r_offset != offset) + if (internal_relocs[i-1].rz_offset != offset) break; i--; } for ( ; i < sec->reloc_count; i++) { irel = &internal_relocs[i]; - r_type = ELF32_R_TYPE (irel->r_info); - if (irel->r_offset == offset && r_type != R_XTENSA_NONE) + rz_type = ELF32_R_TYPE (irel->rz_info); + if (irel->rz_offset == offset && rz_type != R_XTENSA_NONE) return irel; } @@ -8928,7 +8928,7 @@ is_removable_literal (const source_reloc *rel, return FALSE; entry = elf_xtensa_find_property_entry (prop_table, ptblsize, - sec->vma + rel->r_rel.target_offset); + sec->vma + rel->rz_rel.target_offset); if (entry && (entry->flags & XTENSA_PROP_NO_TRANSFORM)) return FALSE; @@ -8936,7 +8936,7 @@ is_removable_literal (const source_reloc *rel, { curr_rel = &src_relocs[i]; /* If all others have the same target offset.... */ - if (curr_rel->r_rel.target_offset != rel->r_rel.target_offset) + if (curr_rel->rz_rel.target_offset != rel->rz_rel.target_offset) return TRUE; if (!curr_rel->is_null @@ -8966,13 +8966,13 @@ remove_dead_literal (bfd *abfd, return FALSE; entry = elf_xtensa_find_property_entry (prop_table, ptblsize, - sec->vma + rel->r_rel.target_offset); + sec->vma + rel->rz_rel.target_offset); /* Mark the unused literal so that it will be removed. */ - add_removed_literal (&relax_info->removed_list, &rel->r_rel, NULL); + add_removed_literal (&relax_info->removed_list, &rel->rz_rel, NULL); text_action_add (&relax_info->action_list, - ta_remove_literal, sec, rel->r_rel.target_offset, 4); + ta_remove_literal, sec, rel->rz_rel.target_offset, 4); /* If the section is 4-byte aligned, do not add fill. */ if (sec->alignment_power > 2) @@ -8986,7 +8986,7 @@ remove_dead_literal (bfd *abfd, if (entry) entry_sec_offset = entry->address - sec->vma + entry->size; else - entry_sec_offset = rel->r_rel.target_offset + 4; + entry_sec_offset = rel->rz_rel.target_offset + 4; /* If the literal range is at the end of the section, do not add fill. */ @@ -9010,7 +9010,7 @@ remove_dead_literal (bfd *abfd, if (elf_hash_table (link_info)->dynamic_sections_created) shrink_dynamic_reloc_sections (link_info, abfd, sec, irel); - irel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); + irel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); pin_internal_relocs (sec, internal_relocs); } @@ -9038,7 +9038,7 @@ identify_literal_placement (bfd *abfd, value_map *val_map; xtensa_relax_info *relax_info; bfd_boolean literal_placed = FALSE; - r_reloc r_rel; + rz_reloc rz_rel; unsigned long value; bfd_boolean final_static_link; bfd_size_type sec_size; @@ -9064,20 +9064,20 @@ identify_literal_placement (bfd *abfd, /* Find the literal value. */ value = 0; - r_reloc_init (&r_rel, abfd, irel, contents, sec_size); + rz_reloc_init (&rz_rel, abfd, irel, contents, sec_size); if (!irel) { - BFD_ASSERT (rel->r_rel.target_offset < sec_size); - value = bfd_get_32 (abfd, contents + rel->r_rel.target_offset); + BFD_ASSERT (rel->rz_rel.target_offset < sec_size); + value = bfd_get_32 (abfd, contents + rel->rz_rel.target_offset); } - init_literal_value (&val, &r_rel, value, is_abs_literal); + init_literal_value (&val, &rz_rel, value, is_abs_literal); /* Check if we've seen another literal with the same value that is in the same output section. */ val_map = value_map_get_cached_value (values, &val, final_static_link); if (val_map - && (r_reloc_get_section (&val_map->loc)->output_section + && (rz_reloc_get_section (&val_map->loc)->output_section == sec->output_section) && relocations_reach (rel, remaining_src_rels, &val_map->loc) && coalesce_shared_literal (sec, rel, prop_table, ptblsize, val_map)) @@ -9092,11 +9092,11 @@ identify_literal_placement (bfd *abfd, if (!link_info->relocatable && !literal_placed && values->has_last_loc && !(*last_loc_is_prev_p)) { - asection *target_sec = r_reloc_get_section (&values->last_loc); + asection *target_sec = rz_reloc_get_section (&values->last_loc); if (target_sec && target_sec->output_section == sec->output_section) { /* Increment the virtual offset. */ - r_reloc try_loc = values->last_loc; + rz_reloc try_loc = values->last_loc; try_loc.virtual_offset += 4; /* There is a last loc that was in the same output section. */ @@ -9120,11 +9120,11 @@ identify_literal_placement (bfd *abfd, { /* Nothing worked, leave the literal alone but update the last loc. */ values->has_last_loc = TRUE; - values->last_loc = rel->r_rel; + values->last_loc = rel->rz_rel; if (!val_map) - val_map = add_value_map (values, &val, &rel->r_rel, final_static_link); + val_map = add_value_map (values, &val, &rel->rz_rel, final_static_link); else - val_map->loc = rel->r_rel; + val_map->loc = rel->rz_rel; *last_loc_is_prev_p = TRUE; } @@ -9134,9 +9134,9 @@ identify_literal_placement (bfd *abfd, /* Check if the original relocations (presumably on L32R instructions) identified by reloc[0..N] can be changed to reference the literal - identified by r_rel. If r_rel is out of range for any of the + identified by rz_rel. If rz_rel is out of range for any of the original relocations, then we don't want to coalesce the original - literal with the one at r_rel. We only check reloc[0..N], where the + literal with the one at rz_rel. We only check reloc[0..N], where the offsets are all the same as for reloc[0] (i.e., they're all referencing the same literal) and where N is also bounded by the number of remaining entries in the "reloc" array. The "reloc" array @@ -9146,21 +9146,21 @@ identify_literal_placement (bfd *abfd, static bfd_boolean relocations_reach (source_reloc *reloc, int remaining_relocs, - const r_reloc *r_rel) + const rz_reloc *rz_rel) { bfd_vma from_offset, source_address, dest_address; asection *sec; int i; - if (!r_reloc_is_defined (r_rel)) + if (!rz_reloc_is_defined (rz_rel)) return FALSE; - sec = r_reloc_get_section (r_rel); - from_offset = reloc[0].r_rel.target_offset; + sec = rz_reloc_get_section (rz_rel); + from_offset = reloc[0].rz_rel.target_offset; for (i = 0; i < remaining_relocs; i++) { - if (reloc[i].r_rel.target_offset != from_offset) + if (reloc[i].rz_rel.target_offset != from_offset) break; /* Ignore relocations that have been removed. */ @@ -9169,7 +9169,7 @@ relocations_reach (source_reloc *reloc, /* The original and new output section for these must be the same in order to coalesce. */ - if (r_reloc_get_section (&reloc[i].r_rel)->output_section + if (rz_reloc_get_section (&reloc[i].rz_rel)->output_section != sec->output_section) return FALSE; @@ -9184,10 +9184,10 @@ relocations_reach (source_reloc *reloc, /* Otherwise, check to see that it fits. */ source_address = (reloc[i].source_sec->output_section->vma + reloc[i].source_sec->output_offset - + reloc[i].r_rel.rela.r_offset); + + reloc[i].rz_rel.rela.rz_offset); dest_address = (sec->output_section->vma + sec->output_offset - + r_rel->target_offset); + + rz_rel->target_offset); if (!pcrel_reloc_fits (reloc[i].opcode, reloc[i].opnd, source_address, dest_address)) @@ -9220,15 +9220,15 @@ coalesce_shared_literal (asection *sec, return FALSE; entry = elf_xtensa_find_property_entry - (prop_table, ptblsize, sec->vma + rel->r_rel.target_offset); + (prop_table, ptblsize, sec->vma + rel->rz_rel.target_offset); if (entry && (entry->flags & XTENSA_PROP_NO_TRANSFORM)) return TRUE; /* Mark that the literal will be coalesced. */ - add_removed_literal (&relax_info->removed_list, &rel->r_rel, &val_map->loc); + add_removed_literal (&relax_info->removed_list, &rel->rz_rel, &val_map->loc); text_action_add (&relax_info->action_list, - ta_remove_literal, sec, rel->r_rel.target_offset, 4); + ta_remove_literal, sec, rel->rz_rel.target_offset, 4); /* If the section is 4-byte aligned, do not add fill. */ if (sec->alignment_power > 2) @@ -9239,7 +9239,7 @@ coalesce_shared_literal (asection *sec, if (entry) entry_sec_offset = entry->address - sec->vma + entry->size; else - entry_sec_offset = rel->r_rel.target_offset + 4; + entry_sec_offset = rel->rz_rel.target_offset + 4; /* If the literal range is at the end of the section, do not add fill. */ @@ -9273,7 +9273,7 @@ move_shared_literal (asection *sec, source_reloc *rel, property_table_entry *prop_table, int ptblsize, - const r_reloc *target_loc, + const rz_reloc *target_loc, const literal_value *lit_value, section_cache_t *target_sec_cache) { @@ -9295,7 +9295,7 @@ move_shared_literal (asection *sec, if (!relax_info) return FALSE; - target_sec = r_reloc_get_section (target_loc); + target_sec = rz_reloc_get_section (target_loc); target_relax_info = get_xtensa_relax_info (target_sec); /* Literals to undefined sections may not be moved because they @@ -9304,7 +9304,7 @@ move_shared_literal (asection *sec, return FALSE; src_entry = elf_xtensa_find_property_entry - (prop_table, ptblsize, sec->vma + rel->r_rel.target_offset); + (prop_table, ptblsize, sec->vma + rel->rz_rel.target_offset); if (!section_cache_section (target_sec_cache, target_sec, link_info)) return FALSE; @@ -9376,11 +9376,11 @@ move_shared_literal (asection *sec, } /* Mark that the literal will be moved to the new location. */ - add_removed_literal (&relax_info->removed_list, &rel->r_rel, target_loc); + add_removed_literal (&relax_info->removed_list, &rel->rz_rel, target_loc); /* Remove the literal. */ text_action_add (&relax_info->action_list, - ta_remove_literal, sec, rel->r_rel.target_offset, 4); + ta_remove_literal, sec, rel->rz_rel.target_offset, 4); /* If the section is 4-byte aligned, do not add fill. */ if (sec->alignment_power > 2 && target_entry != src_entry) @@ -9391,7 +9391,7 @@ move_shared_literal (asection *sec, if (src_entry) entry_sec_offset = src_entry->address - sec->vma + src_entry->size; else - entry_sec_offset = rel->r_rel.target_offset+4; + entry_sec_offset = rel->rz_rel.target_offset+4; /* If the literal range is at the end of the section, do not add fill. */ @@ -9476,8 +9476,8 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) Elf_Internal_Rela *irel; xtensa_relax_info *target_relax_info; bfd_vma source_offset, old_source_offset; - r_reloc r_rel; - unsigned r_type; + rz_reloc rz_rel; + unsigned rz_type; asection *target_sec; /* Locally change the source address. @@ -9487,11 +9487,11 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) Write it back. */ irel = &internal_relocs[i]; - source_offset = irel->r_offset; + source_offset = irel->rz_offset; old_source_offset = source_offset; - r_type = ELF32_R_TYPE (irel->r_info); - r_reloc_init (&r_rel, abfd, irel, contents, + rz_type = ELF32_R_TYPE (irel->rz_info); + rz_reloc_init (&rz_rel, abfd, irel, contents, bfd_get_section_limit (abfd, sec)); /* If this section could have changed then we may need to @@ -9502,24 +9502,24 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) { pin_internal_relocs (sec, internal_relocs); - if (r_type != R_XTENSA_NONE + if (rz_type != R_XTENSA_NONE && find_removed_literal (&relax_info->removed_list, - irel->r_offset)) + irel->rz_offset)) { /* Remove this relocation. */ if (elf_hash_table (link_info)->dynamic_sections_created) shrink_dynamic_reloc_sections (link_info, abfd, sec, irel); - irel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); - irel->r_offset = offset_with_removed_text_map - (&relax_info->action_list, irel->r_offset); + irel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); + irel->rz_offset = offset_with_removed_text_map + (&relax_info->action_list, irel->rz_offset); continue; } - if (r_type == R_XTENSA_ASM_SIMPLIFY) + if (rz_type == R_XTENSA_ASM_SIMPLIFY) { text_action *action = find_insn_action (&relax_info->action_list, - irel->r_offset); + irel->rz_offset); if (action && (action->action == ta_convert_longcall || action->action == ta_remove_longcall)) { @@ -9532,7 +9532,7 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) { (*link_info->callbacks->reloc_dangerous) (link_info, error_message, abfd, sec, - irel->r_offset); + irel->rz_offset); goto error_return; } /* Update the action so that the code that moves @@ -9547,21 +9547,21 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) action->action = ta_remove_insn; else action->action = ta_none; - /* Refresh the info in the r_rel. */ - r_reloc_init (&r_rel, abfd, irel, contents, sec_size); - r_type = ELF32_R_TYPE (irel->r_info); + /* Refresh the info in the rz_rel. */ + rz_reloc_init (&rz_rel, abfd, irel, contents, sec_size); + rz_type = ELF32_R_TYPE (irel->rz_info); } } source_offset = offset_with_removed_text_map - (&relax_info->action_list, irel->r_offset); - irel->r_offset = source_offset; + (&relax_info->action_list, irel->rz_offset); + irel->rz_offset = source_offset; } /* If the target section could have changed then we may need to change the relocation's target offset. */ - target_sec = r_reloc_get_section (&r_rel); + target_sec = rz_reloc_get_section (&rz_rel); /* For a reference to a discarded section from a DWARF section, i.e., where action_discarded is PRETEND, the symbol will @@ -9616,12 +9616,12 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) && (target_relax_info->is_relaxable_literal_section || target_relax_info->is_relaxable_asm_section)) { - r_reloc new_reloc; - target_sec = translate_reloc (&r_rel, &new_reloc, target_sec); + rz_reloc new_reloc; + target_sec = translate_reloc (&rz_rel, &new_reloc, target_sec); - if (r_type == R_XTENSA_DIFF8 - || r_type == R_XTENSA_DIFF16 - || r_type == R_XTENSA_DIFF32) + if (rz_type == R_XTENSA_DIFF8 + || rz_type == R_XTENSA_DIFF16 + || rz_type == R_XTENSA_DIFF32) { bfd_signed_vma diff_value = 0; bfd_vma new_end_offset, diff_mask = 0; @@ -9634,7 +9634,7 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) goto error_return; } - switch (r_type) + switch (rz_type) { case R_XTENSA_DIFF8: diff_value = @@ -9652,10 +9652,10 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) new_end_offset = offset_with_removed_text_map (&target_relax_info->action_list, - r_rel.target_offset + diff_value); + rz_rel.target_offset + diff_value); diff_value = new_end_offset - new_reloc.target_offset; - switch (r_type) + switch (rz_type) { case R_XTENSA_DIFF8: diff_mask = 0x7f; @@ -9692,9 +9692,9 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) adding a "fix" record. */ if (target_sec->owner == abfd) { - unsigned r_symndx = ELF32_R_SYM (new_reloc.rela.r_info); - irel->r_info = ELF32_R_INFO (r_symndx, r_type); - irel->r_addend = new_reloc.rela.r_addend; + unsigned rz_symndx = ELF32_R_SYM (new_reloc.rela.rz_info); + irel->rz_info = ELF32_R_INFO (rz_symndx, rz_type); + irel->rz_addend = new_reloc.rela.rz_addend; pin_internal_relocs (sec, internal_relocs); } else @@ -9704,7 +9704,7 @@ relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info) addend_displacement = new_reloc.target_offset + new_reloc.virtual_offset; - fix = reloc_bfd_fix_init (sec, source_offset, r_type, + fix = reloc_bfd_fix_init (sec, source_offset, rz_type, target_sec, addend_displacement, TRUE); add_fix (sec, fix); @@ -10002,7 +10002,7 @@ translate_reloc_bfd_fix (reloc_bfd_fix *fix) BFD_ASSERT (removed->to.abfd != NULL); /* This was moved to some other address (possibly another section). */ - new_sec = r_reloc_get_section (&removed->to); + new_sec = rz_reloc_get_section (&removed->to); if (new_sec != sec) { sec = new_sec; @@ -10038,7 +10038,7 @@ translate_reloc_bfd_fix (reloc_bfd_fix *fix) /* Fix up a relocation to take account of removed literals. */ static asection * -translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) +translate_reloc (const rz_reloc *orig_rel, rz_reloc *new_rel, asection *sec) { xtensa_relax_info *relax_info; removed_literal *removed; @@ -10046,7 +10046,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) *new_rel = *orig_rel; - if (!r_reloc_is_defined (orig_rel)) + if (!rz_reloc_is_defined (orig_rel)) return sec ; relax_info = get_xtensa_relax_info (sec); @@ -10056,7 +10056,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) target_offset = orig_rel->target_offset; removed = FALSE; - if (is_operand_relocation (ELF32_R_TYPE (orig_rel->rela.r_info))) + if (is_operand_relocation (ELF32_R_TYPE (orig_rel->rela.rz_info))) { /* Check if the original relocation is against a literal being removed. */ @@ -10074,7 +10074,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) /* This was moved to some other address (possibly in another section). */ *new_rel = removed->to; - new_sec = r_reloc_get_section (new_rel); + new_sec = rz_reloc_get_section (new_rel); if (new_sec != sec) { sec = new_sec; @@ -10094,7 +10094,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) addend should not be adjusted due to relaxations located before the base offset. */ - base_offset = r_reloc_get_target_offset (new_rel) - new_rel->rela.r_addend; + base_offset = rz_reloc_get_target_offset (new_rel) - new_rel->rela.rz_addend; if (base_offset <= target_offset) { int base_removed = removed_by_actions_map (&relax_info->action_list, @@ -10104,7 +10104,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) base_removed; new_rel->target_offset = target_offset - base_removed - addend_removed; - new_rel->rela.r_addend -= addend_removed; + new_rel->rela.rz_addend -= addend_removed; } else { @@ -10116,7 +10116,7 @@ translate_reloc (const r_reloc *orig_rel, r_reloc *new_rel, asection *sec) tgt_removed; new_rel->target_offset = target_offset - tgt_removed; - new_rel->rela.r_addend += addend_removed; + new_rel->rela.rz_addend += addend_removed; } return sec; @@ -10141,8 +10141,8 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info, struct elf_xtensa_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; - unsigned long r_symndx; - int r_type; + unsigned long rz_symndx; + int rz_type; struct elf_link_hash_entry *h; bfd_boolean dynamic_symbol; @@ -10153,24 +10153,24 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info, symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); - r_type = ELF32_R_TYPE (rel->r_info); - r_symndx = ELF32_R_SYM (rel->r_info); + rz_type = ELF32_R_TYPE (rel->rz_info); + rz_symndx = ELF32_R_SYM (rel->rz_info); - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) h = NULL; else - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + h = sym_hashes[rz_symndx - symtab_hdr->sh_info]; dynamic_symbol = elf_xtensa_dynamic_symbol_p (h, info); - if ((r_type == R_XTENSA_32 || r_type == R_XTENSA_PLT) + if ((rz_type == R_XTENSA_32 || rz_type == R_XTENSA_PLT) && (input_section->flags & SEC_ALLOC) != 0 && (dynamic_symbol || info->shared)) { asection *srel; bfd_boolean is_plt = FALSE; - if (dynamic_symbol && r_type == R_XTENSA_PLT) + if (dynamic_symbol && rz_type == R_XTENSA_PLT) { srel = htab->srelplt; is_plt = TRUE; @@ -10227,9 +10227,9 @@ shrink_dynamic_reloc_sections (struct bfd_link_info *info, } -/* Take an r_rel and move it to another section. This usually +/* Take an rz_rel and move it to another section. This usually requires extending the interal_relocation array and pinning it. If - the original r_rel is from the same BFD, we can complete this here. + the original rz_rel is from the same BFD, we can complete this here. Otherwise, we add a fix record to let the final link fix the appropriate address. Contents and internal relocations for the section must be pinned after calling this routine. */ @@ -10247,34 +10247,34 @@ move_literal (bfd *abfd, Elf_Internal_Rela *new_relocs = NULL; size_t new_relocs_count = 0; Elf_Internal_Rela this_rela; - const r_reloc *r_rel; + const rz_reloc *rz_rel; - r_rel = &lit->r_rel; + rz_rel = &lit->rz_rel; BFD_ASSERT (elf_section_data (sec)->relocs == *internal_relocs_p); - if (r_reloc_is_const (r_rel)) + if (rz_reloc_is_const (rz_rel)) bfd_put_32 (abfd, lit->value, contents + offset); else { - int r_type; + int rz_type; unsigned i; reloc_bfd_fix *fix; unsigned insert_at; - r_type = ELF32_R_TYPE (r_rel->rela.r_info); + rz_type = ELF32_R_TYPE (rz_rel->rela.rz_info); /* This is the difficult case. We have to create a fix up. */ - this_rela.r_offset = offset; - this_rela.r_info = ELF32_R_INFO (0, r_type); - this_rela.r_addend = - r_rel->target_offset - r_reloc_get_target_offset (r_rel); + this_rela.rz_offset = offset; + this_rela.rz_info = ELF32_R_INFO (0, rz_type); + this_rela.rz_addend = + rz_rel->target_offset - rz_reloc_get_target_offset (rz_rel); bfd_put_32 (abfd, lit->value, contents + offset); /* Currently, we cannot move relocations during a relocatable link. */ BFD_ASSERT (!link_info->relocatable); - fix = reloc_bfd_fix_init (sec, offset, r_type, - r_reloc_get_section (r_rel), - r_rel->target_offset + r_rel->virtual_offset, + fix = reloc_bfd_fix_init (sec, offset, rz_type, + rz_reloc_get_section (rz_rel), + rz_rel->target_offset + rz_rel->virtual_offset, FALSE); /* We also need to mark that relocations are needed here. */ sec->flags |= SEC_RELOC; @@ -10289,7 +10289,7 @@ move_literal (bfd *abfd, insert_at = sec->reloc_count; for (i = 0; i < sec->reloc_count; ++i) { - if (this_rela.r_offset < (*internal_relocs_p)[i].r_offset) + if (this_rela.rz_offset < (*internal_relocs_p)[i].rz_offset) { insert_at = i; break; @@ -10402,7 +10402,7 @@ relax_property_section (bfd *abfd, { Elf_Internal_Rela *irel; xtensa_relax_info *target_relax_info; - unsigned r_type; + unsigned rz_type; asection *target_sec; literal_value val; bfd_byte *size_p, *flags_p; @@ -10414,19 +10414,19 @@ relax_property_section (bfd *abfd, (offset + 4). */ irel = &internal_relocs[i]; - r_type = ELF32_R_TYPE (irel->r_info); - if (r_type == R_XTENSA_NONE) + rz_type = ELF32_R_TYPE (irel->rz_info); + if (rz_type == R_XTENSA_NONE) continue; /* Find the literal value. */ - r_reloc_init (&val.r_rel, abfd, irel, contents, sec_size); - size_p = &contents[irel->r_offset + 4]; + rz_reloc_init (&val.rz_rel, abfd, irel, contents, sec_size); + size_p = &contents[irel->rz_offset + 4]; flags_p = NULL; if (is_full_prop_section) - flags_p = &contents[irel->r_offset + 8]; - BFD_ASSERT (irel->r_offset + entry_size <= sec_size); + flags_p = &contents[irel->rz_offset + 8]; + BFD_ASSERT (irel->rz_offset + entry_size <= sec_size); - target_sec = r_reloc_get_section (&val.r_rel); + target_sec = rz_reloc_get_section (&val.rz_rel); target_relax_info = get_xtensa_relax_info (target_sec); if (target_relax_info @@ -10434,7 +10434,7 @@ relax_property_section (bfd *abfd, || target_relax_info->is_relaxable_asm_section )) { /* Translate the relocation's destination. */ - bfd_vma old_offset = val.r_rel.target_offset; + bfd_vma old_offset = val.rz_rel.target_offset; bfd_vma new_offset; long old_size, new_size; int removed_by_old_offset = @@ -10499,7 +10499,7 @@ relax_property_section (bfd *abfd, if (new_offset != old_offset) { bfd_vma diff = new_offset - old_offset; - irel->r_addend += diff; + irel->rz_addend += diff; pin_internal_relocs (sec, internal_relocs); } } @@ -10549,14 +10549,14 @@ relax_property_section (bfd *abfd, { for (irel = next_rel; irel < rel_end; irel++) { - if ((irel->r_offset == offset - && ELF32_R_TYPE (irel->r_info) != R_XTENSA_NONE) - || irel->r_offset > offset) + if ((irel->rz_offset == offset + && ELF32_R_TYPE (irel->rz_info) != R_XTENSA_NONE) + || irel->rz_offset > offset) { offset_rel = irel; break; } - irel->r_offset -= removed_bytes; + irel->rz_offset -= removed_bytes; } } @@ -10566,7 +10566,7 @@ relax_property_section (bfd *abfd, { for (irel = offset_rel + 1; irel < rel_end; irel++) { - if (ELF32_R_TYPE (irel->r_info) != R_XTENSA_NONE) + if (ELF32_R_TYPE (irel->rz_info) != R_XTENSA_NONE) { extra_rel = irel; break; @@ -10581,16 +10581,16 @@ relax_property_section (bfd *abfd, next iteration. */ if (offset_rel) { - if (offset_rel->r_offset >= offset + entry_size) + if (offset_rel->rz_offset >= offset + entry_size) { next_rel = offset_rel; /* There are no relocations on the current entry, but we might still be able to remove it if the size is zero. */ offset_rel = NULL; } - else if (offset_rel->r_offset > offset + else if (offset_rel->rz_offset > offset || (extra_rel - && extra_rel->r_offset < offset + entry_size)) + && extra_rel->rz_offset < offset + entry_size)) { /* There is a relocation on the size or flags, so we can't do anything with this entry. Continue with the next. */ @@ -10599,8 +10599,8 @@ relax_property_section (bfd *abfd, } else { - BFD_ASSERT (offset_rel->r_offset == offset); - offset_rel->r_offset -= removed_bytes; + BFD_ASSERT (offset_rel->rz_offset == offset); + offset_rel->rz_offset -= removed_bytes; next_rel = offset_rel + 1; } } @@ -10627,27 +10627,27 @@ relax_property_section (bfd *abfd, remove_this_rel = TRUE; } else if (offset_rel - && ELF32_R_TYPE (offset_rel->r_info) == R_XTENSA_32) + && ELF32_R_TYPE (offset_rel->rz_info) == R_XTENSA_32) { if (last_irel) { flagword old_flags; bfd_vma old_size = - bfd_get_32 (abfd, &contents[last_irel->r_offset + 4]); + bfd_get_32 (abfd, &contents[last_irel->rz_offset + 4]); bfd_vma old_address = - (last_irel->r_addend - + bfd_get_32 (abfd, &contents[last_irel->r_offset])); + (last_irel->rz_addend + + bfd_get_32 (abfd, &contents[last_irel->rz_offset])); bfd_vma new_address = - (offset_rel->r_addend + (offset_rel->rz_addend + bfd_get_32 (abfd, &contents[actual_offset])); if (is_full_prop_section) old_flags = bfd_get_32 - (abfd, &contents[last_irel->r_offset + 8]); + (abfd, &contents[last_irel->rz_offset + 8]); else old_flags = predef_flags; - if ((ELF32_R_SYM (offset_rel->r_info) - == ELF32_R_SYM (last_irel->r_info)) + if ((ELF32_R_SYM (offset_rel->rz_info) + == ELF32_R_SYM (last_irel->rz_info)) && old_address + old_size == new_address && old_flags == flags && (old_flags & XTENSA_PROP_INSN_BRANCH_TARGET) == 0 @@ -10655,7 +10655,7 @@ relax_property_section (bfd *abfd, { /* Fix the old size. */ bfd_put_32 (abfd, old_size + size, - &contents[last_irel->r_offset + 4]); + &contents[last_irel->rz_offset + 4]); bytes_to_remove = entry_size; remove_this_rel = TRUE; } @@ -10668,8 +10668,8 @@ relax_property_section (bfd *abfd, if (remove_this_rel) { - offset_rel->r_info = ELF32_R_INFO (0, R_XTENSA_NONE); - offset_rel->r_offset = 0; + offset_rel->rz_info = ELF32_R_INFO (0, R_XTENSA_NONE); + offset_rel->rz_offset = 0; } if (bytes_to_remove != 0) @@ -10686,7 +10686,7 @@ relax_property_section (bfd *abfd, { /* Fix up any extra relocations on the last entry. */ for (irel = next_rel; irel < rel_end; irel++) - irel->r_offset -= removed_bytes; + irel->rz_offset -= removed_bytes; /* Clear the removed bytes. */ memset (&contents[sec->size - removed_bytes], 0, removed_bytes); @@ -10799,32 +10799,32 @@ do_fix_for_relocatable_link (Elf_Internal_Rela *rel, asection *input_section, bfd_byte *contents) { - r_reloc r_rel; + rz_reloc rz_rel; asection *sec, *old_sec; bfd_vma old_offset; - int r_type = ELF32_R_TYPE (rel->r_info); + int rz_type = ELF32_R_TYPE (rel->rz_info); reloc_bfd_fix *fix; - if (r_type == R_XTENSA_NONE) + if (rz_type == R_XTENSA_NONE) return TRUE; - fix = get_bfd_fix (input_section, rel->r_offset, r_type); + fix = get_bfd_fix (input_section, rel->rz_offset, rz_type); if (!fix) return TRUE; - r_reloc_init (&r_rel, input_bfd, rel, contents, + rz_reloc_init (&rz_rel, input_bfd, rel, contents, bfd_get_section_limit (input_bfd, input_section)); - old_sec = r_reloc_get_section (&r_rel); - old_offset = r_rel.target_offset; + old_sec = rz_reloc_get_section (&rz_rel); + old_offset = rz_rel.target_offset; - if (!old_sec || !r_reloc_is_defined (&r_rel)) + if (!old_sec || !rz_reloc_is_defined (&rz_rel)) { - if (r_type != R_XTENSA_ASM_EXPAND) + if (rz_type != R_XTENSA_ASM_EXPAND) { (*_bfd_error_handler) (_("%B(%A+0x%lx): unexpected fix for %s relocation"), - input_bfd, input_section, rel->r_offset, - elf_howto_table[r_type].name); + input_bfd, input_section, rel->rz_offset, + elf_howto_table[rz_type].name); return FALSE; } /* Leave it be. Resolution will happen in a later stage. */ @@ -10832,7 +10832,7 @@ do_fix_for_relocatable_link (Elf_Internal_Rela *rel, else { sec = fix->target_sec; - rel->r_addend += ((sec->output_offset + fix->target_offset) + rel->rz_addend += ((sec->output_offset + fix->target_offset) - (old_sec->output_offset + old_offset)); } return TRUE; @@ -10847,20 +10847,20 @@ do_fix_for_final_link (Elf_Internal_Rela *rel, bfd_vma *relocationp) { asection *sec; - int r_type = ELF32_R_TYPE (rel->r_info); + int rz_type = ELF32_R_TYPE (rel->rz_info); reloc_bfd_fix *fix; bfd_vma fixup_diff; - if (r_type == R_XTENSA_NONE) + if (rz_type == R_XTENSA_NONE) return; - fix = get_bfd_fix (input_section, rel->r_offset, r_type); + fix = get_bfd_fix (input_section, rel->rz_offset, rz_type); if (!fix) return; sec = fix->target_sec; - fixup_diff = rel->r_addend; + fixup_diff = rel->rz_addend; if (elf_howto_table[fix->src_type].partial_inplace) { bfd_vma inplace_val; @@ -10930,17 +10930,17 @@ elf_xtensa_get_gotplt_section (struct bfd_link_info *info, int chunk) . an absolute value, return the absolute section. */ static asection * -get_elf_r_symndx_section (bfd *abfd, unsigned long r_symndx) +get_elf_r_symndx_section (bfd *abfd, unsigned long rz_symndx) { Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; asection *target_sec = NULL; - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) { Elf_Internal_Sym *isymbuf; unsigned int section_index; isymbuf = retrieve_local_syms (abfd); - section_index = isymbuf[r_symndx].st_shndx; + section_index = isymbuf[rz_symndx].st_shndx; if (section_index == SHN_UNDEF) target_sec = bfd_und_section_ptr; @@ -10953,7 +10953,7 @@ get_elf_r_symndx_section (bfd *abfd, unsigned long r_symndx) } else { - unsigned long indx = r_symndx - symtab_hdr->sh_info; + unsigned long indx = rz_symndx - symtab_hdr->sh_info; struct elf_link_hash_entry *h = elf_sym_hashes (abfd)[indx]; while (h->root.type == bfd_link_hash_indirect @@ -10983,16 +10983,16 @@ get_elf_r_symndx_section (bfd *abfd, unsigned long r_symndx) static struct elf_link_hash_entry * -get_elf_r_symndx_hash_entry (bfd *abfd, unsigned long r_symndx) +get_elf_r_symndx_hash_entry (bfd *abfd, unsigned long rz_symndx) { unsigned long indx; struct elf_link_hash_entry *h; Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) return NULL; - indx = r_symndx - symtab_hdr->sh_info; + indx = rz_symndx - symtab_hdr->sh_info; h = elf_sym_hashes (abfd)[indx]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) @@ -11004,20 +11004,20 @@ get_elf_r_symndx_hash_entry (bfd *abfd, unsigned long r_symndx) /* Get the section-relative offset for a symbol number. */ static bfd_vma -get_elf_r_symndx_offset (bfd *abfd, unsigned long r_symndx) +get_elf_r_symndx_offset (bfd *abfd, unsigned long rz_symndx) { Elf_Internal_Shdr *symtab_hdr = &elf_tdata (abfd)->symtab_hdr; bfd_vma offset = 0; - if (r_symndx < symtab_hdr->sh_info) + if (rz_symndx < symtab_hdr->sh_info) { Elf_Internal_Sym *isymbuf; isymbuf = retrieve_local_syms (abfd); - offset = isymbuf[r_symndx].st_value; + offset = isymbuf[rz_symndx].st_value; } else { - unsigned long indx = r_symndx - symtab_hdr->sh_info; + unsigned long indx = rz_symndx - symtab_hdr->sh_info; struct elf_link_hash_entry *h = elf_sym_hashes (abfd)[indx]; @@ -11035,10 +11035,10 @@ get_elf_r_symndx_offset (bfd *abfd, unsigned long r_symndx) static bfd_boolean is_reloc_sym_weak (bfd *abfd, Elf_Internal_Rela *rel) { - unsigned long r_symndx = ELF32_R_SYM (rel->r_info); + unsigned long rz_symndx = ELF32_R_SYM (rel->rz_info); struct elf_link_hash_entry *h; - h = get_elf_r_symndx_hash_entry (abfd, r_symndx); + h = get_elf_r_symndx_hash_entry (abfd, rz_symndx); if (h && h->root.type == bfd_link_hash_defweak) return TRUE; return FALSE; @@ -11111,8 +11111,8 @@ internal_reloc_compare (const void *ap, const void *bp) const Elf_Internal_Rela *a = (const Elf_Internal_Rela *) ap; const Elf_Internal_Rela *b = (const Elf_Internal_Rela *) bp; - if (a->r_offset != b->r_offset) - return (a->r_offset - b->r_offset); + if (a->rz_offset != b->rz_offset) + return (a->rz_offset - b->rz_offset); /* We don't need to sort on these criteria for correctness, but enforcing a more strict ordering prevents unstable qsort @@ -11121,10 +11121,10 @@ internal_reloc_compare (const void *ap, const void *bp) on Solaris 2.7 and 2.8. We would like to always produce the same results no matter the host. */ - if (a->r_info != b->r_info) - return (a->r_info - b->r_info); + if (a->rz_info != b->rz_info) + return (a->rz_info - b->rz_info); - return (a->r_addend - b->r_addend); + return (a->rz_addend - b->rz_addend); } @@ -11136,7 +11136,7 @@ internal_reloc_matches (const void *ap, const void *bp) /* Check if one entry overlaps with the other; this shouldn't happen except when searching for a match. */ - return (a->r_offset - b->r_offset); + return (a->rz_offset - b->rz_offset); } @@ -11343,20 +11343,20 @@ xtensa_callback_required_dependence (bfd *abfd, Elf_Internal_Rela *irel = &internal_relocs[i]; if (is_l32r_relocation (abfd, sec, contents, irel)) { - r_reloc l32r_rel; + rz_reloc l32r_rel; asection *target_sec; bfd_vma target_offset; - r_reloc_init (&l32r_rel, abfd, irel, contents, sec_size); + rz_reloc_init (&l32r_rel, abfd, irel, contents, sec_size); target_sec = NULL; target_offset = 0; /* L32Rs must be local to the input file. */ - if (r_reloc_is_defined (&l32r_rel)) + if (rz_reloc_is_defined (&l32r_rel)) { - target_sec = r_reloc_get_section (&l32r_rel); + target_sec = rz_reloc_get_section (&l32r_rel); target_offset = l32r_rel.target_offset; } - (*callback) (sec, irel->r_offset, target_sec, target_offset, + (*callback) (sec, irel->rz_offset, target_sec, target_offset, closure); } } diff --git a/libr/asm/arch/xtensa/gnu/xtensa-dis.c b/librz/asm/arch/xtensa/gnu/xtensa-dis.c similarity index 100% rename from libr/asm/arch/xtensa/gnu/xtensa-dis.c rename to librz/asm/arch/xtensa/gnu/xtensa-dis.c diff --git a/libr/asm/arch/xtensa/gnu/xtensa-isa.c b/librz/asm/arch/xtensa/gnu/xtensa-isa.c similarity index 99% rename from libr/asm/arch/xtensa/gnu/xtensa-isa.c rename to librz/asm/arch/xtensa/gnu/xtensa-isa.c index a1d16cce36..177a379e7e 100644 --- a/libr/asm/arch/xtensa/gnu/xtensa-isa.c +++ b/librz/asm/arch/xtensa/gnu/xtensa-isa.c @@ -28,8 +28,8 @@ //#include "libbfd.h" #include "../../include/xtensa-isa.h" #include "../../include/xtensa-isa-internal.h" -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" extern int filename_cmp (const char *s1, const char *s2); xtensa_isa_status xtisa_errno; char xtisa_error_msg[1024]; @@ -396,7 +396,7 @@ xtensa_isa_name_compare (const void *v1, const void *v2) xtensa_lookup_entry *e1 = (xtensa_lookup_entry *) v1; xtensa_lookup_entry *e2 = (xtensa_lookup_entry *) v2; - return r_str_casecmp (e1->key, e2->key); + return rz_str_casecmp (e1->key, e2->key); } @@ -554,7 +554,7 @@ xtensa_format_lookup (xtensa_isa isa, const char *fmtname) for (fmt = 0; fmt < intisa->num_formats; fmt++) { - if (r_str_casecmp (fmtname, intisa->formats[fmt].name) == 0) { + if (rz_str_casecmp (fmtname, intisa->formats[fmt].name) == 0) { return fmt; } } diff --git a/libr/asm/arch/xtensa/gnu/xtensa-modules.c b/librz/asm/arch/xtensa/gnu/xtensa-modules.c similarity index 99% rename from libr/asm/arch/xtensa/gnu/xtensa-modules.c rename to librz/asm/arch/xtensa/gnu/xtensa-modules.c index cd33229ba7..9b38437293 100644 --- a/libr/asm/arch/xtensa/gnu/xtensa-modules.c +++ b/librz/asm/arch/xtensa/gnu/xtensa-modules.c @@ -2090,7 +2090,7 @@ Field_s2_Slot_inst16b_set (xtensa_insnbuf insn, uint32 val) } static unsigned -Field_r2_Slot_inst_get (const xtensa_insnbuf insn) +Field_rz_Slot_inst_get (const xtensa_insnbuf insn) { unsigned tie_t = 0; tie_t = (tie_t << 3) | ((insn[0] << 16) >> 29); @@ -2098,7 +2098,7 @@ Field_r2_Slot_inst_get (const xtensa_insnbuf insn) } static void -Field_r2_Slot_inst_set (xtensa_insnbuf insn, uint32 val) +Field_rz_Slot_inst_set (xtensa_insnbuf insn, uint32 val) { uint32 tie_t; tie_t = (val << 29) >> 29; @@ -2106,7 +2106,7 @@ Field_r2_Slot_inst_set (xtensa_insnbuf insn, uint32 val) } static unsigned -Field_r2_Slot_inst16a_get (const xtensa_insnbuf insn) +Field_rz_Slot_inst16a_get (const xtensa_insnbuf insn) { unsigned tie_t = 0; tie_t = (tie_t << 3) | ((insn[0] << 16) >> 29); @@ -2114,7 +2114,7 @@ Field_r2_Slot_inst16a_get (const xtensa_insnbuf insn) } static void -Field_r2_Slot_inst16a_set (xtensa_insnbuf insn, uint32 val) +Field_rz_Slot_inst16a_set (xtensa_insnbuf insn, uint32 val) { uint32 tie_t; tie_t = (val << 29) >> 29; @@ -2122,7 +2122,7 @@ Field_r2_Slot_inst16a_set (xtensa_insnbuf insn, uint32 val) } static unsigned -Field_r2_Slot_inst16b_get (const xtensa_insnbuf insn) +Field_rz_Slot_inst16b_get (const xtensa_insnbuf insn) { unsigned tie_t = 0; tie_t = (tie_t << 3) | ((insn[0] << 16) >> 29); @@ -2130,7 +2130,7 @@ Field_r2_Slot_inst16b_get (const xtensa_insnbuf insn) } static void -Field_r2_Slot_inst16b_set (xtensa_insnbuf insn, uint32 val) +Field_rz_Slot_inst16b_set (xtensa_insnbuf insn, uint32 val) { uint32 tie_t; tie_t = (val << 29) >> 29; @@ -4085,9 +4085,9 @@ Operand_ars_entry_encode (uint32 *valp) static int Operand_immrx4_decode (uint32 *valp) { - unsigned immrx4_0, r_0; - r_0 = *valp & 0xf; - immrx4_0 = (((0xfffffff) << 4) | r_0) << 2; + unsigned immrx4_0, rz_0; + rz_0 = *valp & 0xf; + immrx4_0 = (((0xfffffff) << 4) | rz_0) << 2; *valp = immrx4_0; return 0; } @@ -4095,19 +4095,19 @@ Operand_immrx4_decode (uint32 *valp) static int Operand_immrx4_encode (uint32 *valp) { - unsigned r_0, immrx4_0; + unsigned rz_0, immrx4_0; immrx4_0 = *valp; - r_0 = ((immrx4_0 >> 2) & 0xf); - *valp = r_0; + rz_0 = ((immrx4_0 >> 2) & 0xf); + *valp = rz_0; return 0; } static int Operand_lsi4x4_decode (uint32 *valp) { - unsigned lsi4x4_0, r_0; - r_0 = *valp & 0xf; - lsi4x4_0 = r_0 << 2; + unsigned lsi4x4_0, rz_0; + rz_0 = *valp & 0xf; + lsi4x4_0 = rz_0 << 2; *valp = lsi4x4_0; return 0; } @@ -4115,10 +4115,10 @@ Operand_lsi4x4_decode (uint32 *valp) static int Operand_lsi4x4_encode (uint32 *valp) { - unsigned r_0, lsi4x4_0; + unsigned rz_0, lsi4x4_0; lsi4x4_0 = *valp; - r_0 = ((lsi4x4_0 >> 2) & 0xf); - *valp = r_0; + rz_0 = ((lsi4x4_0 >> 2) & 0xf); + *valp = rz_0; return 0; } @@ -4217,9 +4217,9 @@ Operand_ai4const_encode (uint32 *valp) static int Operand_b4const_decode (uint32 *valp) { - unsigned b4const_0, r_0; - r_0 = *valp & 0xf; - b4const_0 = CONST_TBL_b4c_0[r_0 & 0xf]; + unsigned b4const_0, rz_0; + rz_0 = *valp & 0xf; + b4const_0 = CONST_TBL_b4c_0[rz_0 & 0xf]; *valp = b4const_0; return 0; } @@ -4227,37 +4227,37 @@ Operand_b4const_decode (uint32 *valp) static int Operand_b4const_encode (uint32 *valp) { - unsigned r_0, b4const_0; + unsigned rz_0, b4const_0; b4const_0 = *valp; switch (b4const_0) { - case 0xffffffff: r_0 = 0; break; - case 0x1: r_0 = 0x1; break; - case 0x2: r_0 = 0x2; break; - case 0x3: r_0 = 0x3; break; - case 0x4: r_0 = 0x4; break; - case 0x5: r_0 = 0x5; break; - case 0x6: r_0 = 0x6; break; - case 0x7: r_0 = 0x7; break; - case 0x8: r_0 = 0x8; break; - case 0xa: r_0 = 0x9; break; - case 0xc: r_0 = 0xa; break; - case 0x10: r_0 = 0xb; break; - case 0x20: r_0 = 0xc; break; - case 0x40: r_0 = 0xd; break; - case 0x80: r_0 = 0xe; break; - default: r_0 = 0xf; break; + case 0xffffffff: rz_0 = 0; break; + case 0x1: rz_0 = 0x1; break; + case 0x2: rz_0 = 0x2; break; + case 0x3: rz_0 = 0x3; break; + case 0x4: rz_0 = 0x4; break; + case 0x5: rz_0 = 0x5; break; + case 0x6: rz_0 = 0x6; break; + case 0x7: rz_0 = 0x7; break; + case 0x8: rz_0 = 0x8; break; + case 0xa: rz_0 = 0x9; break; + case 0xc: rz_0 = 0xa; break; + case 0x10: rz_0 = 0xb; break; + case 0x20: rz_0 = 0xc; break; + case 0x40: rz_0 = 0xd; break; + case 0x80: rz_0 = 0xe; break; + default: rz_0 = 0xf; break; } - *valp = r_0; + *valp = rz_0; return 0; } static int Operand_b4constu_decode (uint32 *valp) { - unsigned b4constu_0, r_0; - r_0 = *valp & 0xf; - b4constu_0 = CONST_TBL_b4cu_0[r_0 & 0xf]; + unsigned b4constu_0, rz_0; + rz_0 = *valp & 0xf; + b4constu_0 = CONST_TBL_b4cu_0[rz_0 & 0xf]; *valp = b4constu_0; return 0; } @@ -4265,28 +4265,28 @@ Operand_b4constu_decode (uint32 *valp) static int Operand_b4constu_encode (uint32 *valp) { - unsigned r_0, b4constu_0; + unsigned rz_0, b4constu_0; b4constu_0 = *valp; switch (b4constu_0) { - case 0x8000: r_0 = 0; break; - case 0x10000: r_0 = 0x1; break; - case 0x2: r_0 = 0x2; break; - case 0x3: r_0 = 0x3; break; - case 0x4: r_0 = 0x4; break; - case 0x5: r_0 = 0x5; break; - case 0x6: r_0 = 0x6; break; - case 0x7: r_0 = 0x7; break; - case 0x8: r_0 = 0x8; break; - case 0xa: r_0 = 0x9; break; - case 0xc: r_0 = 0xa; break; - case 0x10: r_0 = 0xb; break; - case 0x20: r_0 = 0xc; break; - case 0x40: r_0 = 0xd; break; - case 0x80: r_0 = 0xe; break; - default: r_0 = 0xf; break; + case 0x8000: rz_0 = 0; break; + case 0x10000: rz_0 = 0x1; break; + case 0x2: rz_0 = 0x2; break; + case 0x3: rz_0 = 0x3; break; + case 0x4: rz_0 = 0x4; break; + case 0x5: rz_0 = 0x5; break; + case 0x6: rz_0 = 0x6; break; + case 0x7: rz_0 = 0x7; break; + case 0x8: rz_0 = 0x8; break; + case 0xa: rz_0 = 0x9; break; + case 0xc: rz_0 = 0xa; break; + case 0x10: rz_0 = 0xb; break; + case 0x20: rz_0 = 0xc; break; + case 0x40: rz_0 = 0xd; break; + case 0x80: rz_0 = 0xe; break; + default: rz_0 = 0xf; break; } - *valp = r_0; + *valp = rz_0; return 0; } @@ -19413,7 +19413,7 @@ Slot_inst_get_field_fns[] = { Field_x_Slot_inst_get, Field_t2_Slot_inst_get, Field_s2_Slot_inst_get, - Field_r2_Slot_inst_get, + Field_rz_Slot_inst_get, Field_t4_Slot_inst_get, Field_s4_Slot_inst_get, Field_r4_Slot_inst_get, @@ -19552,7 +19552,7 @@ Slot_inst_set_field_fns[] = { Field_x_Slot_inst_set, Field_t2_Slot_inst_set, Field_s2_Slot_inst_set, - Field_r2_Slot_inst_set, + Field_rz_Slot_inst_set, Field_t4_Slot_inst_set, Field_s4_Slot_inst_set, Field_r4_Slot_inst_set, @@ -19691,7 +19691,7 @@ Slot_inst16a_get_field_fns[] = { 0, Field_t2_Slot_inst16a_get, Field_s2_Slot_inst16a_get, - Field_r2_Slot_inst16a_get, + Field_rz_Slot_inst16a_get, Field_t4_Slot_inst16a_get, Field_s4_Slot_inst16a_get, Field_r4_Slot_inst16a_get, @@ -19830,7 +19830,7 @@ Slot_inst16a_set_field_fns[] = { 0, Field_t2_Slot_inst16a_set, Field_s2_Slot_inst16a_set, - Field_r2_Slot_inst16a_set, + Field_rz_Slot_inst16a_set, Field_t4_Slot_inst16a_set, Field_s4_Slot_inst16a_set, Field_r4_Slot_inst16a_set, @@ -19969,7 +19969,7 @@ Slot_inst16b_get_field_fns[] = { 0, Field_t2_Slot_inst16b_get, Field_s2_Slot_inst16b_get, - Field_r2_Slot_inst16b_get, + Field_rz_Slot_inst16b_get, Field_t4_Slot_inst16b_get, Field_s4_Slot_inst16b_get, Field_r4_Slot_inst16b_get, @@ -20108,7 +20108,7 @@ Slot_inst16b_set_field_fns[] = { 0, Field_t2_Slot_inst16b_set, Field_s2_Slot_inst16b_set, - Field_r2_Slot_inst16b_set, + Field_rz_Slot_inst16b_set, Field_t4_Slot_inst16b_set, Field_s4_Slot_inst16b_set, Field_r4_Slot_inst16b_set, diff --git a/libr/asm/arch/z80/expressions.c b/librz/asm/arch/z80/expressions.c similarity index 100% rename from libr/asm/arch/z80/expressions.c rename to librz/asm/arch/z80/expressions.c diff --git a/libr/asm/arch/z80/z80.c b/librz/asm/arch/z80/z80.c similarity index 95% rename from libr/asm/arch/z80/z80.c rename to librz/asm/arch/z80/z80.c index 8d71e3b806..ca4d38d70d 100644 --- a/libr/asm/arch/z80/z80.c +++ b/librz/asm/arch/z80/z80.c @@ -2,8 +2,8 @@ Copyright 2016 - unlogic */ -#include -#include +#include +#include #include #include #include "z80_tab.h" @@ -68,7 +68,7 @@ static int z80OpLength (const ut8 *buf, int len) { } // #include'd in asm/p/asm_z80.c -FUNC_ATTR_USED static int z80Disass (RAsmOp *op, const ut8 *buf, int len) { +FUNC_ATTR_USED static int z80Disass (RzAsmOp *op, const ut8 *buf, int len) { int ret = z80OpLength (buf, len); z80_opcode *z_op; char **cb_tab; @@ -126,6 +126,6 @@ FUNC_ATTR_USED static int z80Disass (RAsmOp *op, const ut8 *buf, int len) { if (!strcmp (buf_asm, "invalid")) { ret = 0; } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); return ret; } diff --git a/libr/asm/arch/z80/z80_tab.h b/librz/asm/arch/z80/z80_tab.h similarity index 100% rename from libr/asm/arch/z80/z80_tab.h rename to librz/asm/arch/z80/z80_tab.h diff --git a/libr/asm/arch/z80/z80asm.c b/librz/asm/arch/z80/z80asm.c similarity index 99% rename from libr/asm/arch/z80/z80asm.c rename to librz/asm/arch/z80/z80asm.c index eeeed4f11d..e2ec37a431 100644 --- a/libr/asm/arch/z80/z80asm.c +++ b/librz/asm/arch/z80/z80asm.c @@ -1,4 +1,4 @@ -/* 2012 - pancake@nopcode.org - radare2 integration */ +/* 2012 - pancake@nopcode.org - rizin integration */ /* Z80 assembler by shevek Copyright (C) 2002-2009 Bas Wijnen @@ -20,11 +20,11 @@ along with this program. If not, see . */ -#ifndef R_API_I -#define R_API_I +#ifndef RZ_API_I +#define RZ_API_I #endif #include "z80asm.h" -#include +#include /* hack */ // must remove: equ, include, incbin, macro @@ -1123,7 +1123,7 @@ static int assemble(const char *str, unsigned char *_obuf) { break; } if (r == A_N) { - char n = r_num_math (NULL, readbyte); + char n = rz_num_math (NULL, readbyte); wrtb (0x3E); wrtb (n); break; @@ -1144,7 +1144,7 @@ static int assemble(const char *str, unsigned char *_obuf) { break; } if (s == 7) { - char n = r_num_math(NULL, readbyte); + char n = rz_num_math(NULL, readbyte); wrtb (0x08 * (r - 7) + 0x6); wrtb (n); } else { @@ -1539,7 +1539,7 @@ static int assemble(const char *str, unsigned char *_obuf) { } // XXX -R_API_I int z80asm(unsigned char *outbuf, const char *s) { +RZ_API_I int z80asm(unsigned char *outbuf, const char *s) { return assemble (s, outbuf); } diff --git a/libr/asm/arch/z80/z80asm.h b/librz/asm/arch/z80/z80asm.h similarity index 100% rename from libr/asm/arch/z80/z80asm.h rename to librz/asm/arch/z80/z80asm.h diff --git a/libr/asm/asm.c b/librz/asm/asm.c similarity index 61% rename from libr/asm/asm.c rename to librz/asm/asm.c index b35636a892..ef187eba70 100644 --- a/libr/asm/asm.c +++ b/librz/asm/asm.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ #include -#include -#include -#include -#include +#include +#include +#include +#include #define USE_R2 1 #include #include -R_LIB_VERSION (r_asm); +R_LIB_VERSION (rz_asm); static char *directives[] = { ".include", ".error", ".warning", @@ -17,29 +17,29 @@ static char *directives[] = { ".else", ".set", ".get", NULL }; -static RAsmPlugin *asm_static_plugins[] = { R_ASM_STATIC_PLUGINS }; +static RzAsmPlugin *asm_static_plugins[] = { R_ASM_STATIC_PLUGINS }; -static void parseHeap(RParse *p, RStrBuf *s) { - char *op_buf_asm = r_strbuf_get (s); - size_t len = r_strbuf_length (s); +static void parseHeap(RzParse *p, RStrBuf *s) { + char *op_buf_asm = rz_strbuf_get (s); + size_t len = rz_strbuf_length (s); char *out = malloc (64 + (len * 2)); if (out) { *out = 0; strcpy (out , op_buf_asm); - // XXX we shouldn't pad here because we have t orefactor the RParse API to handle boundaries and chunks properly - r_parse_parse (p, op_buf_asm, out); - r_strbuf_set (s, out); + // XXX we shouldn't pad here because we have t orefactor the RzParse API to handle boundaries and chunks properly + rz_parse_parse (p, op_buf_asm, out); + rz_strbuf_set (s, out); free (out); } } /* pseudo.c - private api */ -static int r_asm_pseudo_align(RAsmCode *acode, RAsmOp *op, char *input) { - acode->code_align = r_num_math (NULL, input); +static int rz_asm_pseudo_align(RzAsmCode *acode, RzAsmOp *op, char *input) { + acode->code_align = rz_num_math (NULL, input); return 0; } -static int r_asm_pseudo_string(RAsmOp *op, char *input, int zero) { +static int rz_asm_pseudo_string(RzAsmOp *op, char *input, int zero) { int len = strlen (input) - 1; if (len < 1) { return 0; @@ -51,95 +51,95 @@ static int r_asm_pseudo_string(RAsmOp *op, char *input, int zero) { if (*input == '"') { input++; } - len = r_str_unescape (input) + zero; - r_strbuf_set (&op->buf, input); // uh? + len = rz_str_unescape (input) + zero; + rz_strbuf_set (&op->buf, input); // uh? return len; } -static inline int r_asm_pseudo_arch(RAsm *a, char *input) { - if (!r_asm_use (a, input)) { +static inline int rz_asm_pseudo_arch(RzAsm *a, char *input) { + if (!rz_asm_use (a, input)) { eprintf ("Error: Unknown plugin\n"); return -1; } return 0; } -static inline int r_asm_pseudo_bits(RAsm *a, char *input) { - if (!(r_asm_set_bits (a, r_num_math (NULL, input)))) { +static inline int rz_asm_pseudo_bits(RzAsm *a, char *input) { + if (!(rz_asm_set_bits (a, rz_num_math (NULL, input)))) { eprintf ("Error: Unsupported value for .bits.\n"); return -1; } return 0; } -static inline int r_asm_pseudo_org(RAsm *a, char *input) { - r_asm_set_pc (a, r_num_math (NULL, input)); +static inline int rz_asm_pseudo_org(RzAsm *a, char *input) { + rz_asm_set_pc (a, rz_num_math (NULL, input)); return 0; } -static inline int r_asm_pseudo_intN(RAsm *a, RAsmOp *op, char *input, int n) { +static inline int rz_asm_pseudo_intN(RzAsm *a, RzAsmOp *op, char *input, int n) { short s; int i; long int l; - ut64 s64 = r_num_math (NULL, input); + ut64 s64 = rz_num_math (NULL, input); if (n != 8 && s64 >> (n * 8)) { eprintf ("int16 Out is out of range\n"); return 0; } // XXX honor endian here - ut8 *buf = (ut8*)r_strbuf_get (&op->buf); + ut8 *buf = (ut8*)rz_strbuf_get (&op->buf); if (!buf) { return 0; } if (n == 2) { s = (short)s64; - r_write_ble16 (buf, s, a->big_endian); + rz_write_ble16 (buf, s, a->big_endian); } else if (n == 4) { i = (int)s64; - r_write_ble32 (buf, i, a->big_endian); + rz_write_ble32 (buf, i, a->big_endian); } else if (n == 8) { l = (long int)s64; - r_write_ble64 (buf, l, a->big_endian); + rz_write_ble64 (buf, l, a->big_endian); } else { return 0; } return n; } -static inline int r_asm_pseudo_int16(RAsm *a, RAsmOp *op, char *input) { - return r_asm_pseudo_intN (a, op, input, 2); +static inline int rz_asm_pseudo_int16(RzAsm *a, RzAsmOp *op, char *input) { + return rz_asm_pseudo_intN (a, op, input, 2); } -static inline int r_asm_pseudo_int32(RAsm *a, RAsmOp *op, char *input) { - return r_asm_pseudo_intN (a, op, input, 4); +static inline int rz_asm_pseudo_int32(RzAsm *a, RzAsmOp *op, char *input) { + return rz_asm_pseudo_intN (a, op, input, 4); } -static inline int r_asm_pseudo_int64(RAsm *a, RAsmOp *op, char *input) { - return r_asm_pseudo_intN (a, op, input, 8); +static inline int rz_asm_pseudo_int64(RzAsm *a, RzAsmOp *op, char *input) { + return rz_asm_pseudo_intN (a, op, input, 8); } -static inline int r_asm_pseudo_byte(RAsmOp *op, char *input) { +static inline int rz_asm_pseudo_byte(RzAsmOp *op, char *input) { int i, len = 0; - r_str_replace_char (input, ',', ' '); - len = r_str_word_count (input); - r_str_word_set0 (input); + rz_str_replace_char (input, ',', ' '); + len = rz_str_word_count (input); + rz_str_word_set0 (input); ut8 *buf = malloc (len); if (!buf) { return 0; } for (i = 0; i < len; i++) { - const char *word = r_str_word_get0 (input, i); - int num = (int)r_num_math (NULL, word); + const char *word = rz_str_word_get0 (input, i); + int num = (int)rz_num_math (NULL, word); buf[i] = num; } - r_asm_op_set_buf (op, buf, len); + rz_asm_op_set_buf (op, buf, len); free (buf); return len; } -static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) { +static inline int rz_asm_pseudo_fill(RzAsmOp *op, char *input) { int i, repeat = 0, size=0, value=0; - sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use r_num? + sscanf (input, "%d,%d,%d", &repeat, &size, &value); // use rz_num? size *= (sizeof (value) * repeat); if (size > 0) { ut8 *buf = malloc (size); @@ -147,7 +147,7 @@ static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) { for (i = 0; i < size; i += sizeof (value)) { memcpy (&buf[i], &value, sizeof (value)); } - r_asm_op_set_buf (op, buf, size); + rz_asm_op_set_buf (op, buf, size); free (buf); } } else { @@ -156,15 +156,15 @@ static inline int r_asm_pseudo_fill(RAsmOp *op, char *input) { return size; } -static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) { +static inline int rz_asm_pseudo_incbin(RzAsmOp *op, char *input) { size_t bytes_read = 0; - r_str_replace_char (input, ',', ' '); - // int len = r_str_word_count (input); - r_str_word_set0 (input); - //const char *filename = r_str_word_get0 (input, 0); - size_t skip = (size_t)r_num_math (NULL, r_str_word_get0 (input, 1)); - size_t count = (size_t)r_num_math (NULL,r_str_word_get0 (input, 2)); - char *content = r_file_slurp (input, &bytes_read); + rz_str_replace_char (input, ',', ' '); + // int len = rz_str_word_count (input); + rz_str_word_set0 (input); + //const char *filename = rz_str_word_get0 (input, 0); + size_t skip = (size_t)rz_num_math (NULL, rz_str_word_get0 (input, 1)); + size_t count = (size_t)rz_num_math (NULL,rz_str_word_get0 (input, 2)); + char *content = rz_file_slurp (input, &bytes_read); if (!content) { eprintf ("Could not open '%s'.\n", input); return -1; @@ -178,22 +178,22 @@ static inline int r_asm_pseudo_incbin(RAsmOp *op, char *input) { count = bytes_read; } // Need to handle arbitrary amount of data - r_buf_free (op->buf_inc); - op->buf_inc = r_buf_new_with_string (content + skip); + rz_buf_free (op->buf_inc); + op->buf_inc = rz_buf_new_with_string (content + skip); // Terminate the original buffer free (content); return count; } -static void plugin_free(RAsmPlugin *p) { +static void plugin_free(RzAsmPlugin *p) { if (p && p->fini) { p->fini (NULL); } } -R_API RAsm *r_asm_new(void) { +RZ_API RzAsm *rz_asm_new(void) { int i; - RAsm *a = R_NEW0 (RAsm); + RzAsm *a = R_NEW0 (RzAsm); if (!a) { return NULL; } @@ -201,50 +201,50 @@ R_API RAsm *r_asm_new(void) { a->bits = R_SYS_BITS; a->bitshift = 0; a->syntax = R_ASM_SYNTAX_INTEL; - a->plugins = r_list_newf ((RListFree)plugin_free); + a->plugins = rz_list_newf ((RzListFree)plugin_free); if (!a->plugins) { free (a); return NULL; } for (i = 0; asm_static_plugins[i]; i++) { - r_asm_add (a, asm_static_plugins[i]); + rz_asm_add (a, asm_static_plugins[i]); } return a; } -R_API bool r_asm_setup(RAsm *a, const char *arch, int bits, int big_endian) { - r_return_val_if_fail (a && arch, false); - bool ret = !r_asm_use (a, arch); - return ret | !r_asm_set_bits (a, bits); +RZ_API bool rz_asm_setup(RzAsm *a, const char *arch, int bits, int big_endian) { + rz_return_val_if_fail (a && arch, false); + bool ret = !rz_asm_use (a, arch); + return ret | !rz_asm_set_bits (a, bits); } // TODO: spagueti -R_API int r_asm_filter_input(RAsm *a, const char *f) { - r_return_val_if_fail (a && f, false); +RZ_API int rz_asm_filter_input(RzAsm *a, const char *f) { + rz_return_val_if_fail (a && f, false); if (!a->ifilter) { - a->ifilter = r_parse_new (); + a->ifilter = rz_parse_new (); } - if (!r_parse_use (a->ifilter, f)) { - r_parse_free (a->ifilter); + if (!rz_parse_use (a->ifilter, f)) { + rz_parse_free (a->ifilter); a->ifilter = NULL; return false; } return true; } -R_API int r_asm_filter_output(RAsm *a, const char *f) { +RZ_API int rz_asm_filter_output(RzAsm *a, const char *f) { if (!a->ofilter) { - a->ofilter = r_parse_new (); + a->ofilter = rz_parse_new (); } - if (!r_parse_use (a->ofilter, f)) { - r_parse_free (a->ofilter); + if (!rz_parse_use (a->ofilter, f)) { + rz_parse_free (a->ofilter); a->ofilter = NULL; return false; } return true; } -R_API void r_asm_free(RAsm *a) { +RZ_API void rz_asm_free(RzAsm *a) { if (!a) { return; } @@ -252,10 +252,10 @@ R_API void r_asm_free(RAsm *a) { a->cur->fini (a->cur->user); } if (a->plugins) { - r_list_free (a->plugins); + rz_list_free (a->plugins); a->plugins = NULL; } - r_syscall_free (a->syscall); + rz_syscall_free (a->syscall); free (a->cpu); sdb_free (a->pair); ht_pp_free (a->flags); @@ -263,36 +263,36 @@ R_API void r_asm_free(RAsm *a) { free (a); } -R_API void r_asm_set_user_ptr(RAsm *a, void *user) { +RZ_API void rz_asm_set_user_ptr(RzAsm *a, void *user) { a->user = user; } -R_API bool r_asm_add(RAsm *a, RAsmPlugin *foo) { +RZ_API bool rz_asm_add(RzAsm *a, RzAsmPlugin *foo) { if (!foo->name) { return false; } if (foo->init) { foo->init (a->user); } - if (r_asm_is_valid (a, foo->name)) { + if (rz_asm_is_valid (a, foo->name)) { return false; } - r_list_append (a->plugins, foo); + rz_list_append (a->plugins, foo); return true; } -R_API int r_asm_del(RAsm *a, const char *name) { - /* TODO: Implement r_asm_del */ +RZ_API int rz_asm_del(RzAsm *a, const char *name) { + /* TODO: Implement rz_asm_del */ return false; } -R_API bool r_asm_is_valid(RAsm *a, const char *name) { - RAsmPlugin *h; - RListIter *iter; +RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name) { + RzAsmPlugin *h; + RzListIter *iter; if (!name || !*name) { return false; } - r_list_foreach (a->plugins, iter, h) { + rz_list_foreach (a->plugins, iter, h) { if (!strcmp (h->name, name)) { return true; } @@ -300,12 +300,12 @@ R_API bool r_asm_is_valid(RAsm *a, const char *name) { return false; } -R_API bool r_asm_use_assembler(RAsm *a, const char *name) { - RAsmPlugin *h; - RListIter *iter; +RZ_API bool rz_asm_use_assembler(RzAsm *a, const char *name) { + RzAsmPlugin *h; + RzListIter *iter; if (a) { if (name && *name) { - r_list_foreach (a->plugins, iter, h) { + rz_list_foreach (a->plugins, iter, h) { if (h->assemble && !strcmp (h->name, name)) { a->acur = h; return true; @@ -317,20 +317,20 @@ R_API bool r_asm_use_assembler(RAsm *a, const char *name) { return false; } -// TODO: this can be optimized using r_str_hash() -R_API bool r_asm_use(RAsm *a, const char *name) { - RAsmPlugin *h; - RListIter *iter; +// TODO: this can be optimized using rz_str_hash() +RZ_API bool rz_asm_use(RzAsm *a, const char *name) { + RzAsmPlugin *h; + RzListIter *iter; if (!a || !name) { return false; } - r_list_foreach (a->plugins, iter, h) { + rz_list_foreach (a->plugins, iter, h) { if (!strcmp (h->name, name) && h->arch) { if (!a->cur || (a->cur && strcmp (a->cur->arch, h->arch))) { - char *r2prefix = r_str_r2_prefix (R2_SDB_OPCODES); - char *file = r_str_newf ("%s/%s.sdb", r_str_get (r2prefix), h->arch); + char *r2prefix = rz_str_rz_prefix (R2_SDB_OPCODES); + char *file = rz_str_newf ("%s/%s.sdb", rz_str_get (r2prefix), h->arch); if (file) { - r_asm_set_cpu (a, NULL); + rz_asm_set_cpu (a, NULL); sdb_free (a->pair); a->pair = sdb_new (NULL, file, 0); free (file); @@ -346,18 +346,18 @@ R_API bool r_asm_use(RAsm *a, const char *name) { return false; } -R_DEPRECATE R_API void r_asm_set_cpu(RAsm *a, const char *cpu) { +R_DEPRECATE RZ_API void rz_asm_set_cpu(RzAsm *a, const char *cpu) { if (a) { free (a->cpu); a->cpu = cpu? strdup (cpu): NULL; } } -static bool has_bits(RAsmPlugin *h, int bits) { +static bool has_bits(RzAsmPlugin *h, int bits) { return (h && h->bits && (bits & h->bits)); } -R_DEPRECATE R_API int r_asm_set_bits(RAsm *a, int bits) { +R_DEPRECATE RZ_API int rz_asm_set_bits(RzAsm *a, int bits) { if (has_bits (a->cur, bits)) { a->bits = bits; // TODO : use OR? :) return true; @@ -365,8 +365,8 @@ R_DEPRECATE R_API int r_asm_set_bits(RAsm *a, int bits) { return false; } -R_API bool r_asm_set_big_endian(RAsm *a, bool b) { - r_return_val_if_fail (a && a->cur, false); +RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool b) { + rz_return_val_if_fail (a && a->cur, false); a->big_endian = false; // little endian by default switch (a->cur->endian) { case R_SYS_ENDIAN_NONE: @@ -381,14 +381,14 @@ R_API bool r_asm_set_big_endian(RAsm *a, bool b) { a->big_endian = true; break; default: - eprintf ("RAsmPlugin doesn't specify endianness\n"); + eprintf ("RzAsmPlugin doesn't specify endianness\n"); break; } return a->big_endian; } -R_API bool r_asm_set_syntax(RAsm *a, int syntax) { - // TODO: move into r_arch ? +RZ_API bool rz_asm_set_syntax(RzAsm *a, int syntax) { + // TODO: move into rz_arch ? switch (syntax) { case R_ASM_SYNTAX_REGNUM: case R_ASM_SYNTAX_INTEL: @@ -402,19 +402,19 @@ R_API bool r_asm_set_syntax(RAsm *a, int syntax) { } } -R_API int r_asm_set_pc(RAsm *a, ut64 pc) { +RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc) { a->pc = pc; return true; } -static bool __isInvalid (RAsmOp *op) { - const char *buf_asm = r_strbuf_get (&op->buf_asm); +static bool __isInvalid (RzAsmOp *op) { + const char *buf_asm = rz_strbuf_get (&op->buf_asm); return (buf_asm && *buf_asm && !strcmp (buf_asm, "invalid")); } -R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - r_asm_op_init (op); - r_return_val_if_fail (a && buf && op, -1); +RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + rz_asm_op_init (op); + rz_return_val_if_fail (a && buf && op, -1); if (len < 1) { return 0; } @@ -422,12 +422,12 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { int ret = op->payload = 0; op->size = 4; op->bitsize = 0; - r_asm_op_set_asm (op, ""); + rz_asm_op_set_asm (op, ""); if (a->pcalign) { const int mod = a->pc % a->pcalign; if (mod) { op->size = a->pcalign - mod; - r_strbuf_set (&op->buf_asm, "unaligned"); + rz_strbuf_set (&op->buf_asm, "unaligned"); return -1; } } @@ -436,7 +436,7 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (a->bitshift > 0) { ut8 *tmp = calloc (len, 1); if (tmp) { - r_mem_copybits_delta (tmp, 0, buf, a->bitshift, (len * 8) - a->bitshift); + rz_mem_copybits_delta (tmp, 0, buf, a->bitshift, (len * 8) - a->bitshift); ret = a->cur->disassemble (a, op, tmp, len); free (tmp); } @@ -460,42 +460,42 @@ R_API int r_asm_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (op->size < 1 || __isInvalid (op)) { if (a->invhex) { if (a->bits == 16) { - ut16 b = r_read_le16 (buf); - r_strbuf_set (&op->buf_asm, sdb_fmt (".word 0x%04x", b)); + ut16 b = rz_read_le16 (buf); + rz_strbuf_set (&op->buf_asm, sdb_fmt (".word 0x%04x", b)); } else { - ut32 b = r_read_le32 (buf); - r_strbuf_set (&op->buf_asm, sdb_fmt (".dword 0x%08x", b)); + ut32 b = rz_read_le32 (buf); + rz_strbuf_set (&op->buf_asm, sdb_fmt (".dword 0x%08x", b)); } // TODO: something for 64bits too? } else { - r_strbuf_set (&op->buf_asm, "invalid"); + rz_strbuf_set (&op->buf_asm, "invalid"); } } if (a->ofilter) { parseHeap (a->ofilter, &op->buf_asm); } int opsz = (op->size > 0)? R_MAX (0, R_MIN (len, op->size)): 1; - r_asm_op_set_buf (op, buf, opsz); + rz_asm_op_set_buf (op, buf, opsz); return ret; } -typedef int (*Ase)(RAsm *a, RAsmOp *op, const char *buf); +typedef int (*Ase)(RzAsm *a, RzAsmOp *op, const char *buf); -static bool assemblerMatches(RAsm *a, RAsmPlugin *h) { +static bool assemblerMatches(RzAsm *a, RzAsmPlugin *h) { if (!a || !h->arch || !h->assemble || !has_bits (h, a->bits)) { return false; } return (!strncmp (a->cur->arch, h->arch, strlen (a->cur->arch))); } -static Ase findAssembler(RAsm *a, const char *kw) { +static Ase findAssembler(RzAsm *a, const char *kw) { Ase ase = NULL; - RAsmPlugin *h; - RListIter *iter; + RzAsmPlugin *h; + RzListIter *iter; if (a->acur && a->acur->assemble) { return a->acur->assemble; } - r_list_foreach (a->plugins, iter, h) { + rz_list_foreach (a->plugins, iter, h) { if (assemblerMatches (a, h)) { if (kw) { if (strstr (h->name, kw)) { @@ -510,7 +510,7 @@ static Ase findAssembler(RAsm *a, const char *kw) { } static char *replace_directives_for(char *str, char *token) { - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); char *p = NULL; char *q = str; bool changes = false; @@ -525,23 +525,23 @@ static char *replace_directives_for(char *str, char *token) { } char _ = *p; *p = 0; - r_strbuf_append (sb, q); + rz_strbuf_append (sb, q); *p = _; - r_strbuf_appendf (sb, "<{%s}>\n", p + 1); + rz_strbuf_appendf (sb, "<{%s}>\n", p + 1); q = nl; changes = true; } else { if (q) { - r_strbuf_append (sb, q); + rz_strbuf_append (sb, q); } break; } } if (changes) { free (str); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } - r_strbuf_free (sb); + rz_strbuf_free (sb); return str; } @@ -556,7 +556,7 @@ static char *replace_directives(char *str) { return o; } -R_API void r_asm_list_directives(void) { +RZ_API void rz_asm_list_directives(void) { int i = 0; char *dir = directives[i++]; while (dir) { @@ -566,18 +566,18 @@ R_API void r_asm_list_directives(void) { } // returns instruction size -R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) { - r_return_val_if_fail (a && op && buf, 0); +RZ_API int rz_asm_assemble(RzAsm *a, RzAsmOp *op, const char *buf) { + rz_return_val_if_fail (a && op && buf, 0); int ret = 0; char *b = strdup (buf); if (!b) { return 0; } if (a->ifilter) { - r_parse_parse (a->ifilter, buf, b); + rz_parse_parse (a->ifilter, buf, b); } - r_str_case (b, 0); // to-lower - memset (op, 0, sizeof (RAsmOp)); + rz_str_case (b, 0); // to-lower + memset (op, 0, sizeof (RzAsmOp)); if (a->cur) { Ase ase = NULL; if (!a->cur->assemble) { @@ -599,67 +599,67 @@ R_API int r_asm_assemble(RAsm *a, RAsmOp *op, const char *buf) { // XXX delete this block, the ase thing should be setting asm, buf and hex if (op && ret > 0) { op->size = ret; // XXX shouldn't be necessary - r_asm_op_set_asm (op, b); // XXX ase should be updating this already, isn't? - ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf); - r_asm_op_set_buf (op, opbuf, ret); + rz_asm_op_set_asm (op, b); // XXX ase should be updating this already, isn't? + ut8 *opbuf = (ut8*)rz_strbuf_get (&op->buf); + rz_asm_op_set_buf (op, opbuf, ret); } free (b); return ret; } // TODO: Use RStrBuf api here pls -R_API RAsmCode* r_asm_mdisassemble(RAsm *a, const ut8 *buf, int len) { - r_return_val_if_fail (a && buf && len >= 0, NULL); +RZ_API RzAsmCode* rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len) { + rz_return_val_if_fail (a && buf && len >= 0, NULL); RStrBuf *buf_asm; - RAsmCode *acode; + RzAsmCode *acode; ut64 pc = a->pc; - RAsmOp op; + RzAsmOp op; ut64 idx; size_t ret, slen; - const size_t addrbytes = a->user? ((RCore *)a->user)->io->addrbytes: 1; + const size_t addrbytes = a->user? ((RzCore *)a->user)->io->addrbytes: 1; - if (!(acode = r_asm_code_new ())) { + if (!(acode = rz_asm_code_new ())) { return NULL; } if (!(acode->bytes = malloc (1 + len))) { - return r_asm_code_free (acode); + return rz_asm_code_free (acode); } memcpy (acode->bytes, buf, len); - if (!(buf_asm = r_strbuf_new (NULL))) { - return r_asm_code_free (acode); + if (!(buf_asm = rz_strbuf_new (NULL))) { + return rz_asm_code_free (acode); } for (idx = ret = slen = 0; idx + addrbytes <= len; idx += (addrbytes * ret)) { - r_asm_set_pc (a, pc + idx); - ret = r_asm_disassemble (a, &op, buf + idx, len - idx); + rz_asm_set_pc (a, pc + idx); + ret = rz_asm_disassemble (a, &op, buf + idx, len - idx); if (ret < 1) { ret = 1; } if (a->ofilter) { parseHeap (a->ofilter, &op.buf_asm); } - r_strbuf_append (buf_asm, r_strbuf_get (&op.buf_asm)); - r_strbuf_append (buf_asm, "\n"); + rz_strbuf_append (buf_asm, rz_strbuf_get (&op.buf_asm)); + rz_strbuf_append (buf_asm, "\n"); } - acode->assembly = r_strbuf_drain (buf_asm); + acode->assembly = rz_strbuf_drain (buf_asm); acode->len = idx; return acode; } -R_API RAsmCode* r_asm_mdisassemble_hexstr(RAsm *a, RParse *p, const char *hexstr) { +RZ_API RzAsmCode* rz_asm_mdisassemble_hexstr(RzAsm *a, RzParse *p, const char *hexstr) { ut8 *buf = malloc (strlen (hexstr) + 1); if (!buf) { return NULL; } - int len = r_hex_str2bin (hexstr, buf); + int len = rz_hex_str2bin (hexstr, buf); if (len < 1) { free (buf); return NULL; } - RAsmCode *ret = r_asm_mdisassemble (a, buf, (ut64)len); + RzAsmCode *ret = rz_asm_mdisassemble (a, buf, (ut64)len); if (ret && p) { // XXX this can crash - r_parse_parse (p, ret->assembly, ret->assembly); + rz_parse_parse (p, ret->assembly, ret->assembly); } free (buf); return ret; @@ -674,12 +674,12 @@ static void *__dup_val(const void *v) { return (void *)strdup ((char *)v); } -R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { +RZ_API RzAsmCode *rz_asm_massemble(RzAsm *a, const char *assembly) { int num, stage, ret, idx, ctr, i, j, linenum = 0; char *lbuf = NULL, *ptr2, *ptr = NULL, *ptr_start = NULL; const char *asmcpu = NULL; - RAsmCode *acode = NULL; - RAsmOp op = {0}; + RzAsmCode *acode = NULL; + RzAsmOp op = {0}; ut64 off, pc; char *buf_token = NULL; @@ -697,30 +697,30 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { free (tokens); return NULL; } - if (!(acode = r_asm_code_new ())) { + if (!(acode = rz_asm_code_new ())) { free (tokens); return NULL; } if (!(acode->assembly = malloc (strlen (assembly) + 16))) { free (tokens); - return r_asm_code_free (acode); + return rz_asm_code_free (acode); } - r_str_ncpy (acode->assembly, assembly, sizeof (acode->assembly) - 1); + rz_str_ncpy (acode->assembly, assembly, sizeof (acode->assembly) - 1); if (!(acode->bytes = calloc (1, 64))) { free (tokens); - return r_asm_code_free (acode); + return rz_asm_code_free (acode); } lbuf = strdup (assembly); acode->code_align = 0; /* consider ,, an alias for a newline */ - lbuf = r_str_replace (lbuf, ",,", "\n", true); + lbuf = rz_str_replace (lbuf, ",,", "\n", true); /* accept ';' as comments when input is multiline */ { char *nl = strchr (lbuf, '\n'); if (nl) { if (strchr (nl + 1, '\n')) { - r_str_replace_char (lbuf, ';', '#'); + rz_str_replace_char (lbuf, ';', '#'); } } } @@ -729,21 +729,21 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { { char val[32]; snprintf (val, sizeof (val), "0x%"PFMT64x, a->pc); - lbuf = r_str_replace (lbuf, "$$", val, 1); + lbuf = rz_str_replace (lbuf, "$$", val, 1); } if (a->syscall) { char val[32]; char *aa, *p = strstr (lbuf, "$sys."); while (p) { - char *sp = (char*)r_str_closer_chr (p, " \n\r#"); + char *sp = (char*)rz_str_closer_chr (p, " \n\r#"); if (sp) { char osp = *sp; *sp = 0; aa = strdup (p); *sp = osp; - num = r_syscall_get_num (a->syscall, aa+5); + num = rz_syscall_get_num (a->syscall, aa+5); snprintf (val, sizeof (val), "%d", num); - lbuf = r_str_replace (lbuf, aa, val, 1); + lbuf = rz_str_replace (lbuf, aa, val, 1); free (aa); } p = strstr (p + 5, "$sys."); @@ -791,7 +791,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { continue; } inComment = false; - r_asm_set_pc (a, pc); + rz_asm_set_pc (a, pc); for (idx = ret = i = j = 0, off = a->pc; i <= ctr; i++, idx += ret) { buf_token = tokens[i]; if (!buf_token) { @@ -839,7 +839,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { *ptr = '\0'; } } - r_asm_set_pc (a, a->pc + ret); + rz_asm_set_pc (a, a->pc + ret); off = a->pc; ret = 0; if (!*ptr_start) { @@ -866,9 +866,9 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { if (acode->code_align) { off += (acode->code_align - (off % acode->code_align)); } - char *food = r_str_newf ("0x%"PFMT64x, off); + char *food = rz_str_newf ("0x%"PFMT64x, off); ht_pp_insert (a->flags, ptr_start, food); - r_asm_code_set_equ (acode, p, food); + rz_asm_code_set_equ (acode, p, food); free (p); free (food); } @@ -884,63 +884,63 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { if (*ptr_start == '.') { /* pseudo */ /* TODO: move into a separate function */ ptr = ptr_start; - r_str_trim (ptr); + rz_str_trim (ptr); if (!strncmp (ptr, ".intel_syntax", 13)) { a->syntax = R_ASM_SYNTAX_INTEL; } else if (!strncmp (ptr, ".att_syntax", 11)) { a->syntax = R_ASM_SYNTAX_ATT; } else if (!strncmp (ptr, ".endian", 7)) { - r_asm_set_big_endian (a, atoi (ptr + 7)); + rz_asm_set_big_endian (a, atoi (ptr + 7)); } else if (!strncmp (ptr, ".big_endian", 7 + 4)) { - r_asm_set_big_endian (a, true); + rz_asm_set_big_endian (a, true); } else if (!strncmp (ptr, ".lil_endian", 7 + 4) || !strncmp (ptr, "little_endian", 7 + 6)) { - r_asm_set_big_endian (a, false); + rz_asm_set_big_endian (a, false); } else if (!strncmp (ptr, ".asciz", 6)) { - r_str_trim (ptr + 8); - ret = r_asm_pseudo_string (&op, ptr + 8, 1); + rz_str_trim (ptr + 8); + ret = rz_asm_pseudo_string (&op, ptr + 8, 1); } else if (!strncmp (ptr, ".string ", 8)) { - r_str_trim (ptr + 8); + rz_str_trim (ptr + 8); char * str = strdup (ptr + 8); - ret = r_asm_pseudo_string (&op, str, 1); + ret = rz_asm_pseudo_string (&op, str, 1); free (str); } else if (!strncmp (ptr, ".ascii", 6)) { - ret = r_asm_pseudo_string (&op, ptr + 7, 0); + ret = rz_asm_pseudo_string (&op, ptr + 7, 0); } else if (!strncmp (ptr, ".align", 6)) { - ret = r_asm_pseudo_align (acode, &op, ptr + 7); + ret = rz_asm_pseudo_align (acode, &op, ptr + 7); } else if (!strncmp (ptr, ".arm", 4)) { - r_asm_use (a, "arm"); - r_asm_set_bits (a, 32); + rz_asm_use (a, "arm"); + rz_asm_set_bits (a, 32); ret = 0; } else if (!strncmp (ptr, ".thumb", 6)) { - r_asm_use (a, "arm"); - r_asm_set_bits (a, 16); + rz_asm_use (a, "arm"); + rz_asm_set_bits (a, 16); ret = 0; } else if (!strncmp (ptr, ".arch ", 6)) { - ret = r_asm_pseudo_arch (a, ptr+6); + ret = rz_asm_pseudo_arch (a, ptr+6); } else if (!strncmp (ptr, ".bits ", 6)) { - ret = r_asm_pseudo_bits (a, ptr+6); + ret = rz_asm_pseudo_bits (a, ptr+6); } else if (!strncmp (ptr, ".fill ", 6)) { - ret = r_asm_pseudo_fill (&op, ptr+6); + ret = rz_asm_pseudo_fill (&op, ptr+6); } else if (!strncmp (ptr, ".kernel ", 8)) { - r_syscall_setup (a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 8); + rz_syscall_setup (a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 8); } else if (!strncmp (ptr, ".cpu ", 5)) { - r_asm_set_cpu (a, ptr + 5); + rz_asm_set_cpu (a, ptr + 5); } else if (!strncmp (ptr, ".os ", 4)) { - r_syscall_setup (a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 4); + rz_syscall_setup (a->syscall, a->cur->arch, a->bits, asmcpu, ptr + 4); } else if (!strncmp (ptr, ".hex ", 5)) { - ret = r_asm_op_set_hex (&op, ptr + 5); + ret = rz_asm_op_set_hex (&op, ptr + 5); } else if ((!strncmp (ptr, ".int16 ", 7)) || !strncmp (ptr, ".short ", 7)) { - ret = r_asm_pseudo_int16 (a, &op, ptr + 7); + ret = rz_asm_pseudo_int16 (a, &op, ptr + 7); } else if (!strncmp (ptr, ".int32 ", 7)) { - ret = r_asm_pseudo_int32 (a, &op, ptr + 7); + ret = rz_asm_pseudo_int32 (a, &op, ptr + 7); } else if (!strncmp (ptr, ".int64 ", 7)) { - ret = r_asm_pseudo_int64 (a, &op, ptr + 7); + ret = rz_asm_pseudo_int64 (a, &op, ptr + 7); } else if (!strncmp (ptr, ".size", 5)) { ret = true; // do nothing, ignored } else if (!strncmp (ptr, ".section", 8)) { ret = true; // do nothing, ignored } else if ((!strncmp (ptr, ".byte ", 6)) || (!strncmp (ptr, ".int8 ", 6))) { - ret = r_asm_pseudo_byte (&op, ptr + 6); + ret = rz_asm_pseudo_byte (&op, ptr + 6); } else if (!strncmp (ptr, ".glob", 5)) { // .global .globl // eprintf (".global directive not yet implemented\n"); ret = 0; @@ -955,14 +955,14 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { } if (ptr2) { *ptr2 = '\0'; - r_asm_code_set_equ (acode, ptr + 5, ptr2 + 1); + rz_asm_code_set_equ (acode, ptr + 5, ptr2 + 1); } else { eprintf ("Invalid syntax for '.equ': Use '.equ '\n"); } } else if (!strncmp (ptr, ".org ", 5)) { - ret = r_asm_pseudo_org (a, ptr + 5); + ret = rz_asm_pseudo_org (a, ptr + 5); off = a->pc; - } else if (r_str_startswith (ptr, ".offset ")) { + } else if (rz_str_startswith (ptr, ".offset ")) { eprintf ("Invalid use of the .offset directory. This directive is only supported in r2 -c 'waf'.\n"); } else if (!strncmp (ptr, ".text", 5)) { acode->code_offset = a->pc; @@ -973,7 +973,7 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { eprintf ("incbin missing filename\n"); continue; } - ret = r_asm_pseudo_incbin (&op, ptr + 8); + ret = rz_asm_pseudo_incbin (&op, ptr + 8); } else { eprintf ("Unknown directive (%s)\n", ptr); goto fail; @@ -987,22 +987,22 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { } } else { /* Instruction */ char *str = ptr_start; - r_str_trim (str); + rz_str_trim (str); if (a->ifilter) { - r_parse_parse (a->ifilter, ptr_start, ptr_start); + rz_parse_parse (a->ifilter, ptr_start, ptr_start); } if (acode->equs) { if (!*ptr_start) { continue; } - str = r_asm_code_equ_replace (acode, strdup (ptr_start)); - ret = r_asm_assemble (a, &op, str); + str = rz_asm_code_equ_replace (acode, strdup (ptr_start)); + ret = rz_asm_assemble (a, &op, str); free (str); } else { if (!*ptr_start) { continue; } - ret = r_asm_assemble (a, &op, ptr_start); + ret = rz_asm_assemble (a, &op, ptr_start); } } if (stage == STAGES - 1) { @@ -1016,13 +1016,13 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { goto fail; } acode->bytes = (ut8*)newbuf; - memcpy (acode->bytes + idx, r_strbuf_get (&op.buf), r_strbuf_length (&op.buf)); + memcpy (acode->bytes + idx, rz_strbuf_get (&op.buf), rz_strbuf_length (&op.buf)); memset (acode->bytes + idx + ret, 0, idx + ret); - if (op.buf_inc && r_buf_size (op.buf_inc) > 1) { - char *inc = r_buf_to_string (op.buf_inc); - r_buf_free (op.buf_inc); + if (op.buf_inc && rz_buf_size (op.buf_inc) > 1) { + char *inc = rz_buf_to_string (op.buf_inc); + rz_buf_free (op.buf_inc); if (inc) { - ret += r_hex_str2bin (inc, acode->bytes + idx + ret); + ret += rz_hex_str2bin (inc, acode->bytes + idx + ret); free (inc); } } @@ -1035,62 +1035,62 @@ R_API RAsmCode *r_asm_massemble(RAsm *a, const char *assembly) { fail: free (lbuf); free (tokens); - return r_asm_code_free (acode); + return rz_asm_code_free (acode); } -R_API bool r_asm_modify(RAsm *a, ut8 *buf, int field, ut64 val) { +RZ_API bool rz_asm_modify(RzAsm *a, ut8 *buf, int field, ut64 val) { return (a->cur && a->cur->modify) ? a->cur->modify (a, buf, field, val): false; } -R_API int r_asm_get_offset(RAsm *a, int type, int idx) { // link to rbin +RZ_API int rz_asm_get_offset(RzAsm *a, int type, int idx) { // link to rbin if (a && a->binb.bin && a->binb.get_offset) { return a->binb.get_offset (a->binb.bin, type, idx); } return -1; } -R_API char *r_asm_describe(RAsm *a, const char* str) { +RZ_API char *rz_asm_describe(RzAsm *a, const char* str) { return (a && a->pair)? sdb_get (a->pair, str, 0): NULL; } -R_API RList* r_asm_get_plugins(RAsm *a) { +RZ_API RzList* rz_asm_get_plugins(RzAsm *a) { return a->plugins; } -R_API bool r_asm_set_arch(RAsm *a, const char *name, int bits) { - return r_asm_use (a, name)? r_asm_set_bits (a, bits): false; +RZ_API bool rz_asm_set_arch(RzAsm *a, const char *name, int bits) { + return rz_asm_use (a, name)? rz_asm_set_bits (a, bits): false; } /* to ease the use of the native bindings (not used in r2) */ -R_API char *r_asm_to_string(RAsm *a, ut64 addr, const ut8 *b, int l) { - r_return_val_if_fail (a && b && l >= 0, NULL); - r_asm_set_pc (a, addr); - RAsmCode *code = r_asm_mdisassemble (a, b, l); +RZ_API char *rz_asm_to_string(RzAsm *a, ut64 addr, const ut8 *b, int l) { + rz_return_val_if_fail (a && b && l >= 0, NULL); + rz_asm_set_pc (a, addr); + RzAsmCode *code = rz_asm_mdisassemble (a, b, l); if (code) { char *buf_asm = code->assembly; code->assembly = NULL; - r_asm_code_free (code); + rz_asm_code_free (code); return buf_asm; } return NULL; } -R_API ut8 *r_asm_from_string(RAsm *a, ut64 addr, const char *b, int *l) { - r_asm_set_pc (a, addr); - RAsmCode *code = r_asm_massemble (a, b); +RZ_API ut8 *rz_asm_from_string(RzAsm *a, ut64 addr, const char *b, int *l) { + rz_asm_set_pc (a, addr); + RzAsmCode *code = rz_asm_massemble (a, b); if (code) { ut8 *buf = code->bytes; if (l) { *l = code->len; } - r_asm_code_free (code); + rz_asm_code_free (code); return buf; } return NULL; } -R_API int r_asm_syntax_from_string(const char *name) { - r_return_val_if_fail (name, -1); +RZ_API int rz_asm_syntax_from_string(const char *name) { + rz_return_val_if_fail (name, -1); if (!strcmp (name, "regnum")) { return R_ASM_SYNTAX_REGNUM; } @@ -1109,16 +1109,16 @@ R_API int r_asm_syntax_from_string(const char *name) { return -1; } -R_API char *r_asm_mnemonics(RAsm *a, int id, bool json) { - r_return_val_if_fail (a && a->cur, NULL); +RZ_API char *rz_asm_mnemonics(RzAsm *a, int id, bool json) { + rz_return_val_if_fail (a && a->cur, NULL); if (a->cur->mnemonics) { return a->cur->mnemonics (a, id, json); } return NULL; } -R_API int r_asm_mnemonics_byname(RAsm *a, const char *name) { - r_return_val_if_fail (a && a->cur, 0); +RZ_API int rz_asm_mnemonics_byname(RzAsm *a, const char *name) { + rz_return_val_if_fail (a && a->cur, 0); if (a->cur->mnemonics) { int i; for (i = 0; i < 1024; i++) { @@ -1132,27 +1132,27 @@ R_API int r_asm_mnemonics_byname(RAsm *a, const char *name) { return 0; } -R_API RAsmCode* r_asm_rasm_assemble(RAsm *a, const char *buf, bool use_spp) { - r_return_val_if_fail (a && buf, NULL); +RZ_API RzAsmCode* rz_asm_rasm_assemble(RzAsm *a, const char *buf, bool use_spp) { + rz_return_val_if_fail (a && buf, NULL); char *lbuf = strdup (buf); if (!lbuf) { return NULL; } - RAsmCode *acode; + RzAsmCode *acode; if (use_spp) { Output out; out.fout = NULL; - out.cout = r_strbuf_new (""); - r_strbuf_init (out.cout); + out.cout = rz_strbuf_new (""); + rz_strbuf_init (out.cout); struct Proc proc; spp_proc_set (&proc, "spp", 1); lbuf = replace_directives (lbuf); spp_eval (lbuf, &out); free (lbuf); - lbuf = strdup (r_strbuf_get (out.cout)); + lbuf = strdup (rz_strbuf_get (out.cout)); } - acode = r_asm_massemble (a, lbuf); + acode = rz_asm_massemble (a, lbuf); free (lbuf); return acode; } diff --git a/libr/asm/d/6502.sdb.txt b/librz/asm/d/6502.sdb.txt similarity index 100% rename from libr/asm/d/6502.sdb.txt rename to librz/asm/d/6502.sdb.txt diff --git a/libr/asm/d/8051.sdb.txt b/librz/asm/d/8051.sdb.txt similarity index 100% rename from libr/asm/d/8051.sdb.txt rename to librz/asm/d/8051.sdb.txt diff --git a/libr/asm/d/LH5801.sdb.txt b/librz/asm/d/LH5801.sdb.txt similarity index 100% rename from libr/asm/d/LH5801.sdb.txt rename to librz/asm/d/LH5801.sdb.txt diff --git a/libr/asm/d/Makefile b/librz/asm/d/Makefile similarity index 93% rename from libr/asm/d/Makefile rename to librz/asm/d/Makefile index 7416db88f7..23c228b76a 100644 --- a/libr/asm/d/Makefile +++ b/librz/asm/d/Makefile @@ -20,7 +20,7 @@ clean: .PHONY: all clean install install-symlink symstall uninstall # XXX rmdblslash not defined, but doesnt warns about it -OPDIR=${DESTDIR}${DATADIR}/radare2/${VERSION}/opcodes +OPDIR=${DESTDIR}${DATADIR}/rizin/${VERSION}/opcodes install: ${F_SDB} -rm -rf "${OPDIR}" diff --git a/libr/asm/d/arc.sdb.txt b/librz/asm/d/arc.sdb.txt similarity index 100% rename from libr/asm/d/arc.sdb.txt rename to librz/asm/d/arc.sdb.txt diff --git a/libr/asm/d/arm.sdb.txt b/librz/asm/d/arm.sdb.txt similarity index 100% rename from libr/asm/d/arm.sdb.txt rename to librz/asm/d/arm.sdb.txt diff --git a/libr/asm/d/avr.sdb.txt b/librz/asm/d/avr.sdb.txt similarity index 100% rename from libr/asm/d/avr.sdb.txt rename to librz/asm/d/avr.sdb.txt diff --git a/libr/asm/d/chip8.sdb.txt b/librz/asm/d/chip8.sdb.txt similarity index 100% rename from libr/asm/d/chip8.sdb.txt rename to librz/asm/d/chip8.sdb.txt diff --git a/libr/asm/d/dalvik.sdb.txt b/librz/asm/d/dalvik.sdb.txt similarity index 100% rename from libr/asm/d/dalvik.sdb.txt rename to librz/asm/d/dalvik.sdb.txt diff --git a/libr/asm/d/i4004.sdb.txt b/librz/asm/d/i4004.sdb.txt similarity index 100% rename from libr/asm/d/i4004.sdb.txt rename to librz/asm/d/i4004.sdb.txt diff --git a/libr/asm/d/i8080.sdb.txt b/librz/asm/d/i8080.sdb.txt similarity index 100% rename from libr/asm/d/i8080.sdb.txt rename to librz/asm/d/i8080.sdb.txt diff --git a/libr/asm/d/java.sdb.txt b/librz/asm/d/java.sdb.txt similarity index 100% rename from libr/asm/d/java.sdb.txt rename to librz/asm/d/java.sdb.txt diff --git a/libr/asm/d/lm32.sdb.txt b/librz/asm/d/lm32.sdb.txt similarity index 100% rename from libr/asm/d/lm32.sdb.txt rename to librz/asm/d/lm32.sdb.txt diff --git a/libr/asm/d/m68k.sdb.txt b/librz/asm/d/m68k.sdb.txt similarity index 100% rename from libr/asm/d/m68k.sdb.txt rename to librz/asm/d/m68k.sdb.txt diff --git a/libr/asm/d/malbolge.sdb.txt b/librz/asm/d/malbolge.sdb.txt similarity index 100% rename from libr/asm/d/malbolge.sdb.txt rename to librz/asm/d/malbolge.sdb.txt diff --git a/libr/asm/d/meson.build b/librz/asm/d/meson.build similarity index 100% rename from libr/asm/d/meson.build rename to librz/asm/d/meson.build diff --git a/libr/asm/d/mips.sdb.txt b/librz/asm/d/mips.sdb.txt similarity index 100% rename from libr/asm/d/mips.sdb.txt rename to librz/asm/d/mips.sdb.txt diff --git a/libr/asm/d/msp430.sdb.txt b/librz/asm/d/msp430.sdb.txt similarity index 100% rename from libr/asm/d/msp430.sdb.txt rename to librz/asm/d/msp430.sdb.txt diff --git a/libr/asm/d/pic18c.sdb.txt b/librz/asm/d/pic18c.sdb.txt similarity index 100% rename from libr/asm/d/pic18c.sdb.txt rename to librz/asm/d/pic18c.sdb.txt diff --git a/libr/asm/d/ppc.sdb.txt b/librz/asm/d/ppc.sdb.txt similarity index 100% rename from libr/asm/d/ppc.sdb.txt rename to librz/asm/d/ppc.sdb.txt diff --git a/libr/asm/d/propeller.sdb.txt b/librz/asm/d/propeller.sdb.txt similarity index 100% rename from libr/asm/d/propeller.sdb.txt rename to librz/asm/d/propeller.sdb.txt diff --git a/libr/asm/d/riscv.sdb.txt b/librz/asm/d/riscv.sdb.txt similarity index 100% rename from libr/asm/d/riscv.sdb.txt rename to librz/asm/d/riscv.sdb.txt diff --git a/libr/asm/d/sh.sdb.txt b/librz/asm/d/sh.sdb.txt similarity index 100% rename from libr/asm/d/sh.sdb.txt rename to librz/asm/d/sh.sdb.txt diff --git a/libr/asm/d/sparc.sdb.txt b/librz/asm/d/sparc.sdb.txt similarity index 100% rename from libr/asm/d/sparc.sdb.txt rename to librz/asm/d/sparc.sdb.txt diff --git a/libr/asm/d/sysz.sdb.txt b/librz/asm/d/sysz.sdb.txt similarity index 100% rename from libr/asm/d/sysz.sdb.txt rename to librz/asm/d/sysz.sdb.txt diff --git a/libr/asm/d/tms320.sdb.txt b/librz/asm/d/tms320.sdb.txt similarity index 100% rename from libr/asm/d/tms320.sdb.txt rename to librz/asm/d/tms320.sdb.txt diff --git a/libr/asm/d/v810.sdb.txt b/librz/asm/d/v810.sdb.txt similarity index 100% rename from libr/asm/d/v810.sdb.txt rename to librz/asm/d/v810.sdb.txt diff --git a/libr/asm/d/v850.sdb.txt b/librz/asm/d/v850.sdb.txt similarity index 100% rename from libr/asm/d/v850.sdb.txt rename to librz/asm/d/v850.sdb.txt diff --git a/libr/asm/d/x86.sdb.txt b/librz/asm/d/x86.sdb.txt similarity index 100% rename from libr/asm/d/x86.sdb.txt rename to librz/asm/d/x86.sdb.txt diff --git a/libr/asm/d/xtensa.sdb.txt b/librz/asm/d/xtensa.sdb.txt similarity index 100% rename from libr/asm/d/xtensa.sdb.txt rename to librz/asm/d/xtensa.sdb.txt diff --git a/libr/asm/d/z80.sdb.txt b/librz/asm/d/z80.sdb.txt similarity index 100% rename from libr/asm/d/z80.sdb.txt rename to librz/asm/d/z80.sdb.txt diff --git a/libr/asm/meson.build b/librz/asm/meson.build similarity index 91% rename from libr/asm/meson.build rename to librz/asm/meson.build index ea876bd45a..9724c461e7 100644 --- a/libr/asm/meson.build +++ b/librz/asm/meson.build @@ -1,4 +1,4 @@ -r_asm_sources = [ +rz_asm_sources = [ 'asm.c', 'aop.c', 'acode.c', @@ -192,7 +192,7 @@ r_asm_sources = [ #'arch/z80/z80asm.c', ] -r_asm_inc = [ +rz_asm_inc = [ platform_inc, include_directories( '../../shlr', @@ -213,16 +213,16 @@ r_asm_inc = [ ) ] -r_asm = library('r_asm', r_asm_sources, - include_directories: r_asm_inc, +rz_asm = library('rz_asm', rz_asm_sources, + include_directories: rz_asm_inc, c_args: library_cflags, dependencies: [ - r_util_dep, - r_syscall_dep, - r_parse_dep, - r_lang_dep, - r_flag_dep, - r_socket_dep, + rz_util_dep, + rz_syscall_dep, + rz_parse_dep, + rz_lang_dep, + rz_flag_dep, + rz_socket_dep, capstone_dep, java_dep ], @@ -232,22 +232,22 @@ r_asm = library('r_asm', r_asm_sources, soversion: r2_libversion ) -r_asm_dep = declare_dependency(link_with: r_asm, - include_directories: r_asm_inc) +rz_asm_dep = declare_dependency(link_with: rz_asm, + include_directories: rz_asm_inc) -pkgconfig_mod.generate(r_asm, - subdirs: 'libr', +pkgconfig_mod.generate(rz_asm, + subdirs: 'librz', version: r2_version, - name: 'r_asm', - filebase: 'r_asm', + name: 'rz_asm', + filebase: 'rz_asm', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_syscall', - 'r_parse', - 'r_lang', - 'r_flag', - 'r_socket' + 'rz_util', + 'rz_syscall', + 'rz_parse', + 'rz_lang', + 'rz_flag', + 'rz_socket' ], description: 'radare foundation libraries' ) diff --git a/libr/asm/p/6502.mk b/librz/asm/p/6502.mk similarity index 100% rename from libr/asm/p/6502.mk rename to librz/asm/p/6502.mk diff --git a/libr/asm/p/6502_cs.mk b/librz/asm/p/6502_cs.mk similarity index 100% rename from libr/asm/p/6502_cs.mk rename to librz/asm/p/6502_cs.mk diff --git a/libr/asm/p/8051.mk b/librz/asm/p/8051.mk similarity index 100% rename from libr/asm/p/8051.mk rename to librz/asm/p/8051.mk diff --git a/libr/asm/p/Makefile b/librz/asm/p/Makefile similarity index 92% rename from libr/asm/p/Makefile rename to librz/asm/p/Makefile index 3d4c7682cf..2cc5260452 100644 --- a/libr/asm/p/Makefile +++ b/librz/asm/p/Makefile @@ -5,9 +5,9 @@ CFLAGS+=-I$(TOP)/shlr -I../../include -I../arch/ -I../arch/include CFLAGS+=-Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}.. LDFLAGS+=-L../../util -L../../flag ifeq ($(CC),cccl) -LDFLAGS+=${LINK} -llibr_flag -llibr_util +LDFLAGS+=${LINK} -llibrz_flag -llibrz_util else -LDFLAGS+=${LINK} -lr_flag -lr_util +LDFLAGS+=${LINK} -lrz_flag -lrz_util endif CURDIR= diff --git a/libr/asm/p/amd29k.mk b/librz/asm/p/amd29k.mk similarity index 100% rename from libr/asm/p/amd29k.mk rename to librz/asm/p/amd29k.mk diff --git a/libr/asm/p/arc.mk b/librz/asm/p/arc.mk similarity index 100% rename from libr/asm/p/arc.mk rename to librz/asm/p/arc.mk diff --git a/libr/asm/p/arm_as.mk b/librz/asm/p/arm_as.mk similarity index 100% rename from libr/asm/p/arm_as.mk rename to librz/asm/p/arm_as.mk diff --git a/libr/asm/p/arm_cs.mk b/librz/asm/p/arm_cs.mk similarity index 100% rename from libr/asm/p/arm_cs.mk rename to librz/asm/p/arm_cs.mk diff --git a/libr/asm/p/arm_gnu.mk b/librz/asm/p/arm_gnu.mk similarity index 100% rename from libr/asm/p/arm_gnu.mk rename to librz/asm/p/arm_gnu.mk diff --git a/libr/asm/p/arm_winedbg.mk b/librz/asm/p/arm_winedbg.mk similarity index 100% rename from libr/asm/p/arm_winedbg.mk rename to librz/asm/p/arm_winedbg.mk diff --git a/libr/asm/p/asm_6502.c b/librz/asm/p/asm_6502.c similarity index 64% rename from libr/asm/p/asm_6502.c rename to librz/asm/p/asm_6502.c index 8c5aa3748c..e9ae0e7dc2 100644 --- a/libr/asm/p/asm_6502.c +++ b/librz/asm/p/asm_6502.c @@ -1,18 +1,18 @@ /* radare - LGPL - Copyright 2012-2018 - pancake, condret */ // copypasta from asm_gb.c -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/6502/6502dis.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { int dlen = _6502Disass (a->pc, op, buf, len); return op->size = R_MAX (dlen, 0); } -RAsmPlugin r_asm_plugin_6502 = { +RzAsmPlugin rz_asm_plugin_6502 = { .name = "6502", .desc = "6502/NES/C64/Tamagotchi/T-1000 CPU", .arch = "6502", @@ -23,9 +23,9 @@ RAsmPlugin r_asm_plugin_6502 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_6502, + .data = &rz_asm_plugin_6502, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_6502_cs.c b/librz/asm/p/asm_6502_cs.c similarity index 81% rename from libr/asm/p/asm_6502_cs.c rename to librz/asm/p/asm_6502_cs.c index 75350b6c47..d1b4ff51f3 100644 --- a/libr/asm/p/asm_6502_cs.c +++ b/librz/asm/p/asm_6502_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2018 - pancake */ +/* rizin - LGPL - Copyright 2018 - pancake */ -#include -#include +#include +#include #include #if CS_API_MAJOR >= 4 && CS_API_MINOR >= 1 @@ -22,7 +22,7 @@ static bool the_end(void *p) { return true; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = 0; int mode, n, ret; ut64 off = a->pc; @@ -52,14 +52,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (ptrstr) { memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1); } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); } cs_free (insn, n); } return op->size; } -RAsmPlugin r_asm_plugin_6502_cs = { +RzAsmPlugin rz_asm_plugin_6502_cs = { .name = "6502.cs", .desc = "Capstone mos65xx CPU disassembler", .license = "BSD", @@ -71,7 +71,7 @@ RAsmPlugin r_asm_plugin_6502_cs = { }; #else -RAsmPlugin r_asm_plugin_6502_cs = { +RzAsmPlugin rz_asm_plugin_6502_cs = { .name = "6502.cs", .desc = "Capstone mos65xx CPU disassembler (not supported)", .license = "BSD", @@ -81,9 +81,9 @@ RAsmPlugin r_asm_plugin_6502_cs = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_6502_cs, + .data = &rz_asm_plugin_6502_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_8051.c b/librz/asm/p/asm_8051.c similarity index 58% rename from libr/asm/p/asm_8051.c rename to librz/asm/p/asm_8051.c index 8c7b5ffcc0..16d2caaefc 100644 --- a/libr/asm/p/asm_8051.c +++ b/librz/asm/p/asm_8051.c @@ -1,31 +1,31 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake, astuder */ +/* rizin - LGPL - Copyright 2013-2019 - pancake, astuder */ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include <8051_ass.h> #include "../arch/8051/8051_disas.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { int dlen = 0; - char *s = r_8051_disas (a->pc, buf, len, &dlen); + char *s = rz_8051_disas (a->pc, buf, len, &dlen); if (dlen < 0) { dlen = 0; } if (s) { - r_strbuf_set (&op->buf_asm, s); + rz_strbuf_set (&op->buf_asm, s); free (s); } op->size = dlen; return dlen; } -RAsmPlugin r_asm_plugin_8051 = { +RzAsmPlugin rz_asm_plugin_8051 = { .name = "8051", .arch = "8051", .bits = 8, @@ -40,9 +40,9 @@ RAsmPlugin r_asm_plugin_8051 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_8051, + .data = &rz_asm_plugin_8051, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_amd29k.c b/librz/asm/p/asm_amd29k.c similarity index 70% rename from libr/asm/p/asm_amd29k.c rename to librz/asm/p/asm_amd29k.c index ce3f6a07cd..be33e22227 100644 --- a/libr/asm/p/asm_amd29k.c +++ b/librz/asm/p/asm_amd29k.c @@ -2,12 +2,12 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../arch/amd29k/amd29k.h" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { if (!a || !op || !buf || len < 4) { return -1; } @@ -17,14 +17,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = 4; if (amd29k_instr_decode (buf, len, &instruction, a->cpu)) { amd29k_instr_print (buf_asm, sizeof (buf_asm), offset, &instruction); - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); return 4; } - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); return -1; } -RAsmPlugin r_asm_plugin_amd29k = { +RzAsmPlugin rz_asm_plugin_amd29k = { .name = "amd29k", .license = "LGPL3", .desc = "AMD 29k RISC CPU", @@ -37,9 +37,9 @@ RAsmPlugin r_asm_plugin_amd29k = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_amd29k, + .data = &rz_asm_plugin_amd29k, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_arc.c b/librz/asm/p/asm_arc.c similarity index 87% rename from libr/asm/p/asm_arc.c rename to librz/asm/p/asm_arc.c index 2009ebde4e..f58184e60a 100644 --- a/libr/asm/p/asm_arc.c +++ b/librz/asm/p/asm_arc.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" #include @@ -44,7 +44,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static struct disassemble_info disasm_obj; if (len < 2) { return -1; @@ -68,19 +68,19 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { disasm_obj.fprintf_func = &generic_fprintf_func; disasm_obj.stream = stdout; disasm_obj.mach = 0; - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); if (a->bits == 16) { op->size = ARCompact_decodeInstr ((bfd_vma)Offset, &disasm_obj); } else { op->size = ARCTangent_decodeInstr ((bfd_vma)Offset, &disasm_obj); } if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_arc = { +RzAsmPlugin rz_asm_plugin_arc = { .name = "arc", .arch = "arc", .bits = 16 | 32, @@ -91,9 +91,9 @@ RAsmPlugin r_asm_plugin_arc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_arc, + .data = &rz_asm_plugin_arc, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_arm_as.c b/librz/asm/p/asm_arm_as.c similarity index 73% rename from libr/asm/p/asm_arm_as.c rename to librz/asm/p/asm_arm_as.c index bec1523df7..02f5403695 100644 --- a/libr/asm/p/asm_arm_as.c +++ b/librz/asm/p/asm_arm_as.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2015-2020 pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #ifndef O_BINARY #define O_BINARY 0 @@ -15,23 +15,23 @@ // toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-arm_64/bin/ // toolchains/aarch64-linux-android-4.9/prebuilt/darwin-arm_64/bin/ -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { const char *bitconfig = ""; char *ipath, *opath; char *as = NULL; - int ifd = r_file_mkstemp ("r_as", &ipath); + int ifd = rz_file_mkstemp ("rz_as", &ipath); if (ifd == -1) { return -1; } - int ofd = r_file_mkstemp ("r_as", &opath); + int ofd = rz_file_mkstemp ("rz_as", &opath); if (ofd == -1) { free (ipath); return -1; } - as = r_sys_getenv ("ARM_AS"); + as = rz_sys_getenv ("ARM_AS"); if (!as || !*as) { free (as); if (a->bits == 64) { @@ -44,7 +44,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { bitconfig = ".thumb"; } - char *asm_buf = r_str_newf ("%s\n" //.org 0x%"PFMT64x"\n" + char *asm_buf = rz_str_newf ("%s\n" //.org 0x%"PFMT64x"\n" ".ascii \"BEGINMARK\"\n" "%s\n" ".ascii \"ENDMARK\"\n", @@ -63,10 +63,10 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { } int len = 0; - if (!r_sys_cmdf ("%s %s -o %s", as, ipath, opath)) { + if (!rz_sys_cmdf ("%s %s -o %s", as, ipath, opath)) { const ut8 *begin, *end; close (ofd); - ofd = r_sandbox_open (opath, O_BINARY|O_RDONLY, 0644); + ofd = rz_sandbox_open (opath, O_BINARY|O_RDONLY, 0644); if (ofd < 0) { free (as); free (ipath); @@ -75,15 +75,15 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { } ut8 buf[4096]; len = read (ofd, buf, sizeof (buf)); - begin = r_mem_mem (buf, len, (const ut8*)"BEGINMARK", 9); - end = r_mem_mem (buf, len, (const ut8*)"ENDMARK", 7); + begin = rz_mem_mem (buf, len, (const ut8*)"BEGINMARK", 9); + end = rz_mem_mem (buf, len, (const ut8*)"ENDMARK", 7); if (!begin || !end) { eprintf ("Cannot find water marks\n"); len = 0; } else { len = (int)(size_t)(end - begin - 9); if (len > 0) { - r_strbuf_setbin (&op->buf, begin + 9, len); + rz_strbuf_setbin (&op->buf, begin + 9, len); } else { len = 0; } @@ -104,7 +104,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { return op->size = len; } -RAsmPlugin r_asm_plugin_arm_as = { +RzAsmPlugin rz_asm_plugin_arm_as = { .name = "arm.as", .desc = "as ARM Assembler (use ARM_AS environment)", .arch = "arm", @@ -116,9 +116,9 @@ RAsmPlugin r_asm_plugin_arm_as = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_arm_as, + .data = &rz_asm_plugin_arm_as, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_arm_cs.c b/librz/asm/p/asm_arm_cs.c similarity index 84% rename from libr/asm/p/asm_arm_cs.c rename to librz/asm/p/asm_arm_cs.c index 88ed7f8c89..6767ed7be0 100644 --- a/libr/asm/p/asm_arm_cs.c +++ b/librz/asm/p/asm_arm_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2018 - pancake */ +/* rizin - LGPL - Copyright 2013-2018 - pancake */ -#include -#include +#include +#include #include #include #include "../arch/arm/asm-arm.h" @@ -14,7 +14,7 @@ static HtUU *ht_it = NULL; #include "cs_mnemonics.c" -static bool check_features(RAsm *a, cs_insn *insn) { +static bool check_features(RzAsm *a, cs_insn *insn) { int i; if (!insn || !insn->detail) { return true; @@ -78,9 +78,9 @@ static const char *cc_name(arm_cc cc) { } } -static void disass_itblock(RAsm *a, cs_insn *insn) { +static void disass_itblock(RzAsm *a, cs_insn *insn) { size_t i, size; - size = r_str_nlen (insn->mnemonic, 5); + size = rz_str_nlen (insn->mnemonic, 5); ht_uu_update (ht_itblock, a->pc, size); for (i = 1; i < size; i++) { switch (insn->mnemonic[i]) { @@ -97,7 +97,7 @@ static void disass_itblock(RAsm *a, cs_insn *insn) { } } -static void check_itblock(RAsm *a, cs_insn *insn) { +static void check_itblock(RzAsm *a, cs_insn *insn) { size_t x; bool found; ut64 itlen = ht_uu_find (ht_itblock, a->pc, &found); @@ -109,7 +109,7 @@ static void check_itblock(RAsm *a, cs_insn *insn) { } } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = -1; static int obits = 32; bool disp_hash = a->immdisp; @@ -145,7 +145,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } if (op) { op->size = 4; - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); } if (!cd || mode != omode) { ret = (a->bits == 64)? @@ -181,7 +181,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (a->features && *a->features) { if (!check_features (a, insn) && op) { op->size = insn->size; - r_strbuf_set (&op->buf_asm, "illegal"); + rz_strbuf_set (&op->buf_asm, "illegal"); } } if (op && !op->size) { @@ -195,10 +195,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (found) { insn->detail->arm.cc = itcond; insn->detail->arm.update_flags = 0; - char *tmpstr = r_str_newf ("%s%s", + char *tmpstr = rz_str_newf ("%s%s", cs_insn_name (cd, insn->id), cc_name (itcond)); - r_str_cpy (insn->mnemonic, tmpstr); + rz_str_cpy (insn->mnemonic, tmpstr); free (tmpstr); } char *buf_asm = sdb_fmt ("%s%s%s", @@ -206,23 +206,23 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { insn->op_str[0]?" ":"", insn->op_str); if (!disp_hash) { - r_str_replace_char (buf_asm, '#', 0); + rz_str_replace_char (buf_asm, '#', 0); } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); } cs_free (insn, n); beach: cs_close (&cd); if (op) { - if (!*r_strbuf_get (&op->buf_asm)) { - r_strbuf_set (&op->buf_asm, "invalid"); + if (!*rz_strbuf_get (&op->buf_asm)) { + rz_strbuf_set (&op->buf_asm, "invalid"); } return op->size; } return ret; } -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { const bool is_thumb = (a->bits == 16); int opsize; ut32 opcode; @@ -246,27 +246,27 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { opsize = o > 0? 4: 2; if (opsize == 4) { if (a->big_endian) { - r_write_le16 (opbuf, opcode >> 16); - r_write_le16 (opbuf + 2, opcode & UT16_MAX); + rz_write_le16 (opbuf, opcode >> 16); + rz_write_le16 (opbuf + 2, opcode & UT16_MAX); } else { - r_write_be32 (opbuf, opcode); + rz_write_be32 (opbuf, opcode); } } else if (opsize == 2) { if (a->big_endian) { - r_write_le16 (opbuf, opcode & UT16_MAX); + rz_write_le16 (opbuf, opcode & UT16_MAX); } else { - r_write_be16 (opbuf, opcode & UT16_MAX); + rz_write_be16 (opbuf, opcode & UT16_MAX); } } } else { opsize = 4; if (a->big_endian) { - r_write_le32 (opbuf, opcode); + rz_write_le32 (opbuf, opcode); } else { - r_write_be32 (opbuf, opcode); + rz_write_be32 (opbuf, opcode); } } - r_strbuf_setbin (&op->buf, opbuf, opsize); + rz_strbuf_setbin (&op->buf, opbuf, opsize); // XXX. thumb endian assembler needs no swap return opsize; } @@ -289,7 +289,7 @@ static bool fini(void* user) { return 0; } -RAsmPlugin r_asm_plugin_arm_cs = { +RzAsmPlugin rz_asm_plugin_arm_cs = { .name = "arm", .desc = "Capstone ARM disassembler", .cpus = ",v8,cortex", @@ -314,9 +314,9 @@ RAsmPlugin r_asm_plugin_arm_cs = { #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_arm_cs, + .data = &rz_asm_plugin_arm_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_arm_gnu.c b/librz/asm/p/asm_arm_gnu.c similarity index 93% rename from libr/asm/p/asm_arm_gnu.c rename to librz/asm/p/asm_arm_gnu.c index c93a1d1507..dae186a0ee 100644 --- a/libr/asm/p/asm_arm_gnu.c +++ b/librz/asm/p/asm_arm_gnu.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" #include "../arch/arm/gnu/opcode-arm.h" @@ -94,7 +94,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static char *oldcpu = NULL; static int oldcpucode = 0; int opsize; @@ -183,7 +183,7 @@ cpucode = 66471; obj.bytes_per_chunk = obj.bytes_per_line = (a->bits / 8); - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); if (a->bits == 64) { obj.disassembler_options = NULL; memcpy (bytes, buf, 4); @@ -196,17 +196,17 @@ cpucode = 66471; } opsize = op->size; if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); op->size = 4; - } else if (strstr (r_strbuf_get (buf_global), "UNDEF")) { - r_strbuf_set (&op->buf_asm, "undefined"); + } else if (strstr (rz_strbuf_get (buf_global), "UNDEF")) { + rz_strbuf_set (&op->buf_asm, "undefined"); op->size = 2; opsize = 2; } return opsize; } -RAsmPlugin r_asm_plugin_arm_gnu = { +RzAsmPlugin rz_asm_plugin_arm_gnu = { .name = "arm.gnu", .arch = "arm", .cpus = "v2,v2a,v3M,v4,v5,v5t,v5te,v5j,XScale,ep9312,iWMMXt,iWMMXt2", @@ -218,9 +218,9 @@ RAsmPlugin r_asm_plugin_arm_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_arm_gnu, + .data = &rz_asm_plugin_arm_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_arm_hacks.inc b/librz/asm/p/asm_arm_hacks.inc similarity index 80% rename from libr/asm/p/asm_arm_hacks.inc rename to librz/asm/p/asm_arm_hacks.inc index 7417ae8d40..c067bfe453 100644 --- a/libr/asm/p/asm_arm_hacks.inc +++ b/librz/asm/p/asm_arm_hacks.inc @@ -21,9 +21,9 @@ static char *hack_handle_dp_imm(ut32 insn) { const ut8 uimm4 = (insn >> 10) & 0xf; const ut8 Xn = (insn >> 5) & 0x1f; const ut8 Xd = (insn >> 0) & 0x1f; - buf_asm = r_str_newf ("%s x%d, x%d, #0x%x, #0x%x", + buf_asm = rz_str_newf ("%s x%d, x%d, #0x%x, #0x%x", mnemonic, Xd, Xn, uimm6, uimm4); - buf_asm = r_str_replace (buf_asm, "x31", "sp", 1); + buf_asm = rz_str_replace (buf_asm, "x31", "sp", 1); return buf_asm; } } @@ -44,16 +44,16 @@ static char *hack_handle_br_exc_sys(ut32 insn) { if (CRm == 4 && (op2 & 1) == 0) { switch (op2) { case 0: - buf_asm = r_str_newf ("%s", mnemonic); + buf_asm = rz_str_newf ("%s", mnemonic); break; case 2: - buf_asm = r_str_newf ("%s c", mnemonic); + buf_asm = rz_str_newf ("%s c", mnemonic); break; case 4: - buf_asm = r_str_newf ("%s j", mnemonic); + buf_asm = rz_str_newf ("%s j", mnemonic); break; case 6: - buf_asm = r_str_newf ("%s jc", mnemonic); + buf_asm = rz_str_newf ("%s jc", mnemonic); break; } } @@ -92,14 +92,14 @@ static char *hack_handle_dp_reg(ut32 insn) { const ut8 Xd = (insn >> 0) & 0x1f; if (Xm == 31 && !strcmp (mnemonic, "irg")) { // Xm is xzr, discard it - buf_asm = r_str_newf ("%s x%d, x%d", mnemonic, Xd, Xn); + buf_asm = rz_str_newf ("%s x%d, x%d", mnemonic, Xd, Xn); } else if (!strcmp (mnemonic, "subps") && S == 1 && Xd == 0x1f) { // ccmp is an alias for subps when S == '1' && Xd == '11111' - buf_asm = r_str_newf ("cmpp x%d, x%d", Xn, Xm); + buf_asm = rz_str_newf ("cmpp x%d, x%d", Xn, Xm); } else { - buf_asm = r_str_newf ("%s x%d, x%d, x%d", mnemonic, Xd, Xn, Xm); + buf_asm = rz_str_newf ("%s x%d, x%d, x%d", mnemonic, Xd, Xn, Xm); } - buf_asm = r_str_replace (buf_asm, "x31", "sp", 1); + buf_asm = rz_str_replace (buf_asm, "x31", "sp", 1); return buf_asm; } } @@ -141,19 +141,19 @@ static char *hack_handle_ldst(ut32 insn) { switch (op2) { case 1: - buf_asm = r_str_newf ("%s x%d, [x%d], #0x%x", + buf_asm = rz_str_newf ("%s x%d, [x%d], #0x%x", mnemonic, Xt, Xn, imm9); break; case 2: - buf_asm = r_str_newf ("%s x%d, [x%d, #0x%x]", + buf_asm = rz_str_newf ("%s x%d, [x%d, #0x%x]", mnemonic, Xt, Xn, imm9); break; case 3: - buf_asm = r_str_newf ("%s x%d, [x%d, #0x%x]!", + buf_asm = rz_str_newf ("%s x%d, [x%d, #0x%x]!", mnemonic, Xt, Xn, imm9); break; } - buf_asm = r_str_replace (buf_asm, "x31", "sp", 1); + buf_asm = rz_str_replace (buf_asm, "x31", "sp", 1); return buf_asm; } else if (op2 == 0) { switch (opc) { @@ -174,13 +174,13 @@ static char *hack_handle_ldst(ut32 insn) { break; } if (ignore_imm9) { - buf_asm = r_str_newf ("%s x%d, [x%d]", + buf_asm = rz_str_newf ("%s x%d, [x%d]", mnemonic, Xt, Xn); } else { - buf_asm = r_str_newf ("%s x%d, [x%d, #0x%x]", + buf_asm = rz_str_newf ("%s x%d, [x%d, #0x%x]", mnemonic, Xt, Xn, imm9); } - buf_asm = r_str_replace (buf_asm, "x31", "sp", 1); + buf_asm = rz_str_replace (buf_asm, "x31", "sp", 1); return buf_asm; } // Load/store register pair @@ -196,28 +196,28 @@ static char *hack_handle_ldst(ut32 insn) { const ut8 Xt = (insn >> 0) & 0x1f; switch (op2) { case 1: - buf_asm = r_str_newf ("stgp x%d, x%d, [x%d], #0x%x", + buf_asm = rz_str_newf ("stgp x%d, x%d, [x%d], #0x%x", Xt, Xt2, Xn, imm7); break; case 2: - buf_asm = r_str_newf ("stgp x%d, [x%d, #0x%x]", + buf_asm = rz_str_newf ("stgp x%d, [x%d, #0x%x]", Xt, Xt2, Xn, imm7); break; case 3: - buf_asm = r_str_newf ("stgp x%d, [x%d, #0x%x]!", + buf_asm = rz_str_newf ("stgp x%d, [x%d, #0x%x]!", Xt, Xt2, Xn, imm7); break; default: return NULL; } - buf_asm = r_str_replace (buf_asm, "x31", "sp", 1); + buf_asm = rz_str_replace (buf_asm, "x31", "sp", 1); return buf_asm; } } return NULL; } -static int hackyArmAsm(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int hackyArmAsm(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { char *buf_asm = NULL; // Hacky support for ARMv8.5 if (a->bits == 64 && len >= 4) { @@ -256,9 +256,9 @@ static int hackyArmAsm(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (buf_asm) { if (!a->immdisp) { - r_str_replace_char (buf_asm, '#', 0); + rz_str_replace_char (buf_asm, '#', 0); } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); free (buf_asm); return op->size = 4; } diff --git a/libr/asm/p/asm_arm_winedbg.c b/librz/asm/p/asm_arm_winedbg.c similarity index 64% rename from libr/asm/p/asm_arm_winedbg.c rename to librz/asm/p/asm_arm_winedbg.c index fa9bf1ad17..3c755a0820 100644 --- a/libr/asm/p/asm_arm_winedbg.c +++ b/librz/asm/p/asm_arm_winedbg.c @@ -3,19 +3,19 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/arm/winedbg/be_arm.h" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { ut8 buf2[4]; struct winedbg_arm_insn *arminsn = arm_new(); arm_set_pc (arminsn, a->pc); arm_set_thumb (arminsn, a->bits == 16); if (a->big_endian && a->bits == 32) { - r_mem_swapendian (buf2, buf, 4); + rz_mem_swapendian (buf2, buf, 4); arm_set_input_buffer (arminsn, buf2); } else { arm_set_input_buffer (arminsn, buf); @@ -23,17 +23,17 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = arm_disasm_one_insn (arminsn); const char *asmstr = winedbg_arm_insn_asm (arminsn); if (asmstr) { - r_strbuf_set (&op->buf_asm, asmstr); - r_asm_op_set_hex(op, winedbg_arm_insn_hex (arminsn)); + rz_strbuf_set (&op->buf_asm, asmstr); + rz_asm_op_set_hex(op, winedbg_arm_insn_hex (arminsn)); } else { - r_strbuf_set (&op->buf_asm, "invalid"); - r_strbuf_set (&op->buf, ""); + rz_strbuf_set (&op->buf_asm, "invalid"); + rz_strbuf_set (&op->buf, ""); } arm_free (arminsn); return op->size; } -RAsmPlugin r_asm_plugin_arm_winedbg = { +RzAsmPlugin rz_asm_plugin_arm_winedbg = { .name = "arm.winedbg", .arch = "arm", .bits = 16|32, @@ -44,9 +44,9 @@ RAsmPlugin r_asm_plugin_arm_winedbg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_arm_winedbg, + .data = &rz_asm_plugin_arm_winedbg, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_avr.c b/librz/asm/p/asm_avr.c similarity index 94% rename from libr/asm/p/asm_avr.c rename to librz/asm/p/asm_avr.c index 1f0037deb2..81e9227b2e 100644 --- a/libr/asm/p/asm_avr.c +++ b/librz/asm/p/asm_avr.c @@ -6,20 +6,20 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/avr/disasm.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { char buf_asm[32] = {0}; op->size = avrdis (buf_asm, a->pc, buf, len); if (*buf_asm == '.') { *buf_asm = 0; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); return op->size; } @@ -79,20 +79,20 @@ static int parse_specialreg(const char *reg) { /* gets the number from string duplicate from asm_x86_nz.c -- may be create a generic function? */ -static int getnum(RAsm *a, const char *s) { +static int getnum(RzAsm *a, const char *s) { if (!s) { return 0; } if (*s == '$') { s++; } - return r_num_math (a->num, s); + return rz_num_math (a->num, s); } /* this function searches from instruction in instructionSet table (see avr_disasm.h for more info) returns index of the instruction in the table */ -static int search_instruction(RAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) { +static int search_instruction(RzAsm *a, char instr[3][MAX_TOKEN_SIZE], int args) { int i, op1 = 0, op2 = 0; for (i = 0; i < AVR_TOTAL_INSTRUCTIONS - 1; i++) { @@ -203,7 +203,7 @@ static int parse_registerpair(const char *operand) { anyway FIXME if you have better idea */ if (second && strlen (second) < 2) { /* the pair is set by pair - this is currently useless, cause rasm2 filters ':' from assembler + this is currently useless, cause rz_asm filters ':' from assembler however, this bug soon will be fixed */ if (first[0] == 'r' && second[0] == 'r') { fnum = atoi(first+1); @@ -233,7 +233,7 @@ static int parse_registerpair(const char *operand) { } // assembles instruction argument (operand) based on its type -static int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *res) { +static int assemble_operand(RzAsm *a, const char *operand, int type, uint32_t *res) { int ret = -1; int temp; @@ -308,7 +308,7 @@ static int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *re case OPERAND_REGISTER: if (strlen(operand) > 1) { - // returns register number (r__) + // returns register number (rz__) *res = getnum(a, operand + 1); if (*res <= 32) { ret = 0; @@ -317,7 +317,7 @@ static int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *re break; case OPERAND_REGISTER_STARTR16: if (strlen(operand) > 1) { - // returns register number (r__) + // returns register number (rz__) *res = getnum(a, operand + 1); if (*res >= 16 && *res <= 32) { *res -= 16; @@ -332,7 +332,7 @@ static int assemble_operand(RAsm *a, const char *operand, int type, uint32_t *re return ret; } -static int assemble(RAsm *a, RAsmOp *ao, const char *str) { +static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) { char tokens[3][MAX_TOKEN_SIZE]; char *token; uint32_t coded = 0; @@ -419,13 +419,13 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) { // copying result to radare struct if (len > 0) { - r_strbuf_setbin (&ao->buf, (const ut8*)&coded, len); + rz_strbuf_setbin (&ao->buf, (const ut8*)&coded, len); } return len; } // AVR assembler realization ends -RAsmPlugin r_asm_plugin_avr = { +RzAsmPlugin rz_asm_plugin_avr = { .name = "avr", .arch = "avr", .license = "GPL", @@ -450,9 +450,9 @@ RAsmPlugin r_asm_plugin_avr = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_avr, + .data = &rz_asm_plugin_avr, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_bf.c b/librz/asm/p/asm_bf.c similarity index 89% rename from libr/asm/p/asm_bf.c rename to librz/asm/p/asm_bf.c index 7c8b0e9318..3ee95137d4 100644 --- a/libr/asm/p/asm_bf.c +++ b/librz/asm/p/asm_bf.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble */ -#include +#include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { const ut8 *b; int rep = 1; @@ -53,12 +53,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { const char *fmt = strchr (buf_asm, ' ')? "%s, %d": "%s %d"; buf_asm = sdb_fmt (fmt, buf_asm, rep); } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); op->size = rep; return rep; } -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { int n = 0; if (buf[0] && buf[1] == ' ') { buf += 2; @@ -131,11 +131,11 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { n = 1; } } - r_strbuf_setbin (&op->buf, opbuf, n); + rz_strbuf_setbin (&op->buf, opbuf, n); return n; } -RAsmPlugin r_asm_plugin_bf = { +RzAsmPlugin rz_asm_plugin_bf = { .name = "bf", .author = "pancake, nibble", .version = "4.0.0", @@ -149,9 +149,9 @@ RAsmPlugin r_asm_plugin_bf = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_bf, + .data = &rz_asm_plugin_bf, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_chip8.c b/librz/asm/p/asm_chip8.c similarity index 92% rename from libr/asm/p/asm_chip8.c rename to librz/asm/p/asm_chip8.c index 10df412d8f..701cac8aef 100644 --- a/libr/asm/p/asm_chip8.c +++ b/librz/asm/p/asm_chip8.c @@ -1,10 +1,10 @@ /* radare - LGPL3 - Copyright 2017-2018 - maijin */ -#include -#include +#include +#include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) { - ut16 opcode = r_read_be16 (b); +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *b, int l) { + ut16 opcode = rz_read_be16 (b); uint8_t x = (opcode >> 8) & 0x0F; uint8_t y = (opcode >> 4) & 0x0F; uint8_t nibble = opcode & 0x0F; @@ -80,12 +80,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) { } } break; } - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); op->size = 2; return op->size; } -RAsmPlugin r_asm_plugin_chip8 = { +RzAsmPlugin rz_asm_plugin_chip8 = { .name = "chip8", .arch = "chip8", .license = "LGPL3", @@ -95,9 +95,9 @@ RAsmPlugin r_asm_plugin_chip8 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_chip8, + .data = &rz_asm_plugin_chip8, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_cr16.c b/librz/asm/p/asm_cr16.c similarity index 60% rename from libr/asm/p/asm_cr16.c rename to librz/asm/p/asm_cr16.c index ff37ed55fe..5ff81d4adc 100644 --- a/libr/asm/p/asm_cr16.c +++ b/librz/asm/p/asm_cr16.c @@ -2,19 +2,19 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct cr16_cmd cmd; int ret = cr16_decode_command (buf, &cmd, len); - r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); + rz_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); return op->size = ret; } -RAsmPlugin r_asm_plugin_cr16 = { +RzAsmPlugin rz_asm_plugin_cr16 = { .name = "cr16", .license = "LGPL3", .desc = "cr16 disassembly plugin", @@ -25,9 +25,9 @@ RAsmPlugin r_asm_plugin_cr16 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_cr16, + .data = &rz_asm_plugin_cr16, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_cris_gnu.c b/librz/asm/p/asm_cris_gnu.c similarity index 92% rename from libr/asm/p/asm_cris_gnu.c rename to librz/asm/p/asm_cris_gnu.c index dfa304f515..5762e31a46 100644 --- a/libr/asm/p/asm_cris_gnu.c +++ b/librz/asm/p/asm_cris_gnu.c @@ -13,10 +13,10 @@ http://developer.axis.com/old/documentation/hw/etraxfs/iop_howto/iop_howto.pdf #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -51,7 +51,7 @@ int print_insn_cris_without_register_prefix (bfd_vma vma, disassemble_info *info int print_insn_crisv32_with_register_prefix (bfd_vma vma, disassemble_info *info); int print_insn_crisv32_without_register_prefix (bfd_vma vma, disassemble_info *info); -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; int mode = 2; if (len < 4) { @@ -115,12 +115,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_cris_gnu = { +RzAsmPlugin rz_asm_plugin_cris_gnu = { .name = "cris", .arch = "cris", .cpus = "v0,v10,v32", @@ -133,9 +133,9 @@ RAsmPlugin r_asm_plugin_cris_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_cris_gnu, + .data = &rz_asm_plugin_cris_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_dalvik.c b/librz/asm/p/asm_dalvik.c similarity index 86% rename from libr/asm/p/asm_dalvik.c rename to librz/asm/p/asm_dalvik.c index 1284419712..0319e65715 100644 --- a/libr/asm/p/asm_dalvik.c +++ b/librz/asm/p/asm_dalvik.c @@ -3,14 +3,14 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - r_return_val_if_fail (a && op && buf && len > 0, -1); +static int dalvik_disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + rz_return_val_if_fail (a && op && buf && len > 0, -1); int vA, vB, vC, vD, vE, vF, vG, vH, payload = 0, i = (int) buf[0]; int size = dalvik_opcodes[i].len; @@ -69,7 +69,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } if (buf_asm) { - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); } strasm = NULL; if (size <= len) { @@ -81,37 +81,37 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { vA = buf[1] & 0x0f; vB = (buf[1] & 0xf0) >> 4; snprintf (str, sizeof (str), " v%i, v%i", vA, vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAvBBBB: vA = (int) buf[1]; vB = (buf[3] << 8) | buf[2]; snprintf (str, sizeof (str), " v%i, v%i", vA, vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAAAvBBBB: // buf[1] seems useless :/ vA = (buf[3] << 8) | buf[2]; vB = (buf[5] << 8) | buf[4]; snprintf (str, sizeof (str), " v%i, v%i", vA, vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAA: vA = (int) buf[1]; snprintf (str, sizeof (str), " v%i", vA); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAcB: vA = buf[1] & 0x0f; vB = (buf[1] & 0xf0) >> 4; snprintf (str, sizeof (str), " v%i, %#x", vA, vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAcBBBB: vA = (int) buf[1]; { short sB = (buf[3] << 8) | buf[2]; snprintf (str, sizeof (str), " v%i, %#04hx", vA, sB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); } break; case fmtopvAAcBBBBBBBB: @@ -122,7 +122,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { //const snprintf (str, sizeof (str), " v%i, 0x%08x", vA, vB); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAcBBBB0000: vA = (int) buf[1]; @@ -133,7 +133,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), " v%i, 0x%08x", vA, vB); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAcBBBBBBBBBBBBBBBB: vA = (int) buf[1]; @@ -142,52 +142,52 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { ((ut64)buf[6] << 32) | ((ut64)buf[7] << 40)| ((ut64)(buf[8]&0xff) << 48) | ((ut64)(buf[9]&0xff) << 56); snprintf (str, sizeof (str), " v%i:v%i, 0x%"PFMT64x, vA, vA + 1, lB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAvBBvCC: vA = (int) buf[1]; vB = (int) buf[2]; vC = (int) buf[3]; snprintf (str, sizeof (str), " v%i, v%i, v%i", vA, vB, vC); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAvBBcCC: vA = (int) buf[1]; vB = (int) buf[2]; vC = (int) buf[3]; snprintf (str, sizeof (str), " v%i, v%i, %#x", vA, vB, vC); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAvBcCCCC: vA = buf[1] & 0x0f; vB = (buf[1] & 0xf0) >> 4; vC = (buf[3] << 8) | buf[2]; snprintf (str, sizeof (str), " v%i, v%i, %#x", vA, vB, vC); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoppAA: vA = (char) buf[1]; //snprintf (str, sizeof (str), " %i", vA*2); // vA : word -> byte snprintf (str, sizeof (str), " 0x%08"PFMT64x, a->pc + (vA * 2)); // vA : word -> byte - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoppAAAA: vA = (short) (buf[3] << 8 | buf[2]); snprintf (str, sizeof (str), " 0x%08"PFMT64x, a->pc + (vA * 2)); // vA : word -> byte - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAApBBBB: // if-*z vA = (int) buf[1]; vB = (int) (buf[3] << 8 | buf[2]); //snprintf (str, sizeof (str), " v%i, %i", vA, vB); snprintf (str, sizeof (str), " v%i, 0x%08"PFMT64x, vA, a->pc + (vB * 2)); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoppAAAAAAAA: vA = (int) (buf[2] | (buf[3] << 8) | (buf[4] << 16) | (buf[5] << 24)); //snprintf (str, sizeof (str), " %#08x", vA*2); // vA: word -> byte snprintf (str, sizeof (str), " 0x%08"PFMT64x, a->pc + (vA*2)); // vA : word -> byte - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAvBpCCCC: // if-* vA = buf[1] & 0x0f; @@ -195,13 +195,13 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { vC = (int) (buf[3] << 8 | buf[2]); //snprintf (str, sizeof (str), " v%i, v%i, %i", vA, vB, vC); snprintf (str, sizeof (str)," v%i, v%i, 0x%08"PFMT64x, vA, vB, a->pc + (vC * 2)); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAApBBBBBBBB: vA = (int) buf[1]; vB = (short) (buf[2] | (buf[3] << 8) | (buf[4] << 16) | (buf[5] << 24)); snprintf (str, sizeof (str), " v%i, 0x%08"PFMT64x, vA, a->pc + (vB * 2) + 8); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoptinlineI: vA = (int) (buf[1] & 0x0f); @@ -224,9 +224,9 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { default: snprintf (str, sizeof (str), " {}"); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); snprintf (str, sizeof (str), ", [%04x]", vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoptinlineIR: case fmtoptinvokeVSR: @@ -234,7 +234,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { vB = (buf[3] << 8) | buf[2]; vC = (buf[5] << 8) | buf[4]; snprintf (str, sizeof (str), " {v%i..v%i}, [%04x]", vC, vC + vA - 1, vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoptinvokeVS: vA = (int) (buf[1] & 0xf0) >> 4; @@ -258,9 +258,9 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { snprintf (str, sizeof (str), " {}"); break; } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); snprintf (str, sizeof (str), ", [%04x]", vB); - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAtBBBB: // "sput-*" vA = (int) buf[1]; @@ -287,7 +287,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { snprintf (str, sizeof (str), " v%i, %s", vA, flag_str); } } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoptopvAvBoCCCC: vA = (buf[1] & 0x0f); @@ -299,7 +299,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), " v%i, v%i, [0x%"PFMT64x"]", vA, vB, offset); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopAAtBBBB: vA = (int) buf[1]; @@ -310,7 +310,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), " v%i, 0x%"PFMT64x, vA, offset); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAvBtCCCC: vA = (buf[1] & 0x0f); @@ -331,7 +331,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { snprintf (str, sizeof (str), " v%i, v%i, field+%i", vA, vB, vC); } } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvAAtBBBBBBBB: vA = (int) buf[1]; @@ -342,7 +342,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), " v%i, 0x%"PFMT64x, vA, offset); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvCCCCmBBBB: vA = (int) buf[1]; @@ -373,7 +373,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { snprintf (str, sizeof (str), " {v%i..v%i}, method+%i", vC, vC + vA - 1, vB); } } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtopvXtBBBB: vA = (int) (buf[1] & 0xf0) >> 4; @@ -400,7 +400,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { default: snprintf (str, sizeof (str), " {}"); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); if (buf[0] == 0x24) { // filled-new-array flag_str = R_ASM_GET_NAME (a, 'c', vB); if (flag_str) { @@ -424,7 +424,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtop45CC: vA = (buf[1] & 0xf0) >> 4; @@ -456,20 +456,20 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { snprintf (str, sizeof (str), " %d", vC); break; } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); flag_str = R_ASM_GET_NAME (a, 'm', vB); if (flag_str) { - strasm = r_str_appendf (strasm, ", %s", flag_str); + strasm = rz_str_appendf (strasm, ", %s", flag_str); } else { - strasm = r_str_appendf (strasm, ", method+%i", vB); + strasm = rz_str_appendf (strasm, ", method+%i", vB); } flag_str = R_ASM_GET_NAME (a, 'p', vH); if (flag_str) { - strasm = r_str_appendf (strasm, ", %s", flag_str); + strasm = rz_str_appendf (strasm, ", %s", flag_str); } else { - strasm = r_str_appendf (strasm, ", proto+%i", vH); + strasm = rz_str_appendf (strasm, ", proto+%i", vH); } break; case fmtop4RCC: @@ -483,7 +483,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), " {v%i..v%i}, method+%i", vC, vC + vA - 1, vB); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); flag_str = R_ASM_GET_NAME (a, 'p', vH); if (flag_str) { @@ -491,7 +491,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { snprintf (str, sizeof (str), ", proto+%i", vH); } - strasm = r_str_append (strasm, str); + strasm = rz_str_append (strasm, str); break; case fmtoptinvokeI: // Any opcode has this formats case fmtoptinvokeIR: @@ -501,9 +501,9 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { strasm = NULL; size = 2; } - r_strbuf_set (&op->buf_asm, strasm? strasm: "invalid"); + rz_strbuf_set (&op->buf_asm, strasm? strasm: "invalid"); } else if (len > 0) { - r_strbuf_set (&op->buf_asm, "invalid"); + rz_strbuf_set (&op->buf_asm, "invalid"); op->size = len; size = len; } @@ -528,7 +528,7 @@ static int dalvik_disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } //TODO -static int dalvik_assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int dalvik_assemble(RzAsm *a, RzAsmOp *op, const char *buf) { int i; char *p = strchr (buf, ' '); if (p) { @@ -538,8 +538,8 @@ static int dalvik_assemble(RAsm *a, RAsmOp *op, const char *buf) { for (i = 0; i < 256; i++) { if (!strcmp (dalvik_opcodes[i].name, buf)) { ut8 buf[4]; - r_write_ble32 (buf, i, a->big_endian); - r_strbuf_setbin (&op->buf, buf, sizeof (buf)); + rz_write_ble32 (buf, i, a->big_endian); + rz_strbuf_setbin (&op->buf, buf, sizeof (buf)); op->size = dalvik_opcodes[i].len; return op->size; } @@ -547,7 +547,7 @@ static int dalvik_assemble(RAsm *a, RAsmOp *op, const char *buf) { return 0; } -RAsmPlugin r_asm_plugin_dalvik = { +RzAsmPlugin rz_asm_plugin_dalvik = { .name = "dalvik", .arch = "dalvik", .license = "LGPL3", @@ -559,9 +559,9 @@ RAsmPlugin r_asm_plugin_dalvik = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_dalvik, + .data = &rz_asm_plugin_dalvik, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_dcpu16.c b/librz/asm/p/asm_dcpu16.c similarity index 55% rename from libr/asm/p/asm_dcpu16.c rename to librz/asm/p/asm_dcpu16.c index ac62001252..a346ded8fe 100644 --- a/libr/asm/p/asm_dcpu16.c +++ b/librz/asm/p/asm_dcpu16.c @@ -1,33 +1,33 @@ -/* radare2 - LGPL - Copyright 2012-2018 pancake */ +/* rizin - LGPL - Copyright 2012-2018 pancake */ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/dcpu16/dcpu16.h" #include "../arch/dcpu16/dis.c" #include "../arch/dcpu16/asm.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { char buf_asm[32]; if (len < 2) { return -1; // at least 2 bytes! } op->size = dcpu16_disasm (buf_asm, (const ut16*)buf, len, NULL); - r_strbuf_set (&op->buf_asm, (op->size > 0) ? buf_asm: "(data)"); + rz_strbuf_set (&op->buf_asm, (op->size > 0) ? buf_asm: "(data)"); return op->size; } -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { - int len = dcpu16_assemble ((ut8*)r_strbuf_get (&op->buf), buf); +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { + int len = dcpu16_assemble ((ut8*)rz_strbuf_get (&op->buf), buf); op->buf.len = len; return len; } -RAsmPlugin r_asm_plugin_dcpu16 = { +RzAsmPlugin rz_asm_plugin_dcpu16 = { .name = "dcpu16", .arch = "dpcu", .bits = 16, @@ -39,9 +39,9 @@ RAsmPlugin r_asm_plugin_dcpu16 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_dcpu16, + .data = &rz_asm_plugin_dcpu16, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_ebc.c b/librz/asm/p/asm_ebc.c similarity index 69% rename from libr/asm/p/asm_ebc.c rename to librz/asm/p/asm_ebc.c index d73ec0aa0f..34006b0d9d 100644 --- a/libr/asm/p/asm_ebc.c +++ b/librz/asm/p/asm_ebc.c @@ -2,21 +2,21 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { ebc_command_t cmd = { {0}, {0} }; int ret = ebc_decode_command (buf, &cmd); const char *buf_asm = (cmd.operands[0]) ? sdb_fmt ("%s %s", cmd.instr, cmd.operands): cmd.instr; - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); return op->size = ret; } -RAsmPlugin r_asm_plugin_ebc = { +RzAsmPlugin rz_asm_plugin_ebc = { .name = "ebc", .license = "LGPL3", .desc = "EFI Bytecode", @@ -28,9 +28,9 @@ RAsmPlugin r_asm_plugin_ebc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_ebc, + .data = &rz_asm_plugin_ebc, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_gas.c b/librz/asm/p/asm_gas.c similarity index 57% rename from libr/asm/p/asm_gas.c rename to librz/asm/p/asm_gas.c index aaad53bf07..35af930053 100644 --- a/libr/asm/p/asm_gas.c +++ b/librz/asm/p/asm_gas.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2010-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { int len = 0; ut8 *out; - char *cmd = r_str_newf ( + char *cmd = rz_str_newf ( "gas /dev/stdin -o /dev/stdout <<__\n" "BITS %i\nORG 0x%"PFMT64x"\n%s\n__", a->bits, a->pc, buf); - ut8 *out = (ut8 *)r_sys_cmd_str (cmd, "", &len); + ut8 *out = (ut8 *)rz_sys_cmd_str (cmd, "", &len); if (out) { - r_asm_op_set_buf (op, out, len); + rz_asm_op_set_buf (op, out, len); free (out); } op->size = len; @@ -22,7 +22,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { return len; } -RAsmPlugin r_asm_plugin_x86_gas = { +RzAsmPlugin rz_asm_plugin_x86_gas = { .name = "x86.gas", .license = "LGPL3", .desc = "GNU Assembler (gas)", @@ -32,9 +32,9 @@ RAsmPlugin r_asm_plugin_x86_gas = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_x86_gas, + .data = &rz_asm_plugin_x86_gas, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_gb.c b/librz/asm/p/asm_gb.c similarity index 50% rename from libr/asm/p/asm_gb.c rename to librz/asm/p/asm_gb.c index e0e33e7b8f..f288f24730 100644 --- a/libr/asm/p/asm_gb.c +++ b/librz/asm/p/asm_gb.c @@ -2,23 +2,23 @@ // fork of asm_z80.c -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/gb/gbdis.c" #include "../arch/gb/gbasm.c" -static int disassemble(RAsm *a, RAsmOp *r_op, const ut8 *buf, int len) { - int dlen = gbDisass(r_op,buf,len); - return r_op->size = R_MAX (0, dlen); +static int disassemble(RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) { + int dlen = gbDisass(rz_op,buf,len); + return rz_op->size = R_MAX (0, dlen); } -static int assemble(RAsm *a, RAsmOp *r_op, const char *buf) { - return gbAsm (a, r_op, buf); +static int assemble(RzAsm *a, RzAsmOp *rz_op, const char *buf) { + return gbAsm (a, rz_op, buf); } -RAsmPlugin r_asm_plugin_gb = { +RzAsmPlugin rz_asm_plugin_gb = { .name = "gb", .desc = "GameBoy(TM) (z80-like)", .arch = "z80", @@ -31,9 +31,9 @@ RAsmPlugin r_asm_plugin_gb = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_gb, + .data = &rz_asm_plugin_gb, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_h8300.c b/librz/asm/p/asm_h8300.c similarity index 60% rename from libr/asm/p/asm_h8300.c rename to librz/asm/p/asm_h8300.c index bd41831ebf..fcabc69caa 100644 --- a/libr/asm/p/asm_h8300.c +++ b/librz/asm/p/asm_h8300.c @@ -2,19 +2,19 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct h8300_cmd cmd; int ret = h8300_decode_command(buf, &cmd); - r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); + rz_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); return op->size = ret; } -RAsmPlugin r_asm_plugin_h8300 = { +RzAsmPlugin rz_asm_plugin_h8300 = { .name = "h8300", .license = "LGPL3", .desc = "H8/300 disassembly plugin", @@ -25,9 +25,9 @@ RAsmPlugin r_asm_plugin_h8300 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_h8300, + .data = &rz_asm_plugin_h8300, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_hexagon.c b/librz/asm/p/asm_hexagon.c similarity index 56% rename from libr/asm/p/asm_hexagon.c rename to librz/asm/p/asm_hexagon.c index c03fd0fb71..e837ab992a 100644 --- a/libr/asm/p/asm_hexagon.c +++ b/librz/asm/p/asm_hexagon.c @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2018 - xvilka */ -#include -#include -#include -#include +#include +#include +#include +#include #include "hexagon.h" #include "hexagon_insn.h" -static int disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int l) { +static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int l) { HexInsn hi = {0}; - ut32 data = r_read_le32 (buf); + ut32 data = rz_read_le32 (buf); op->size = hexagon_disasm_instruction (data, &hi, (ut32) a->pc); - r_strbuf_set (&op->buf_asm, hi.mnem); + rz_strbuf_set (&op->buf_asm, hi.mnem); return op->size; } -RAsmPlugin r_asm_plugin_hexagon = { +RzAsmPlugin rz_asm_plugin_hexagon = { .name = "hexagon", .arch = "hexagon", .author = "xvilka", @@ -26,8 +26,8 @@ RAsmPlugin r_asm_plugin_hexagon = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_hexagon + .data = &rz_asm_plugin_hexagon }; #endif diff --git a/libr/asm/p/asm_hppa_gnu.c b/librz/asm/p/asm_hppa_gnu.c similarity index 85% rename from libr/asm/p/asm_hppa_gnu.c rename to librz/asm/p/asm_hppa_gnu.c index bda704a2f7..c596358f9b 100644 --- a/libr/asm/p/asm_hppa_gnu.c +++ b/librz/asm/p/asm_hppa_gnu.c @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -42,7 +42,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -65,12 +65,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_hppa ((bfd_vma)Offset, &disasm_obj); if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_hppa_gnu = { +RzAsmPlugin rz_asm_plugin_hppa_gnu = { .name = "hppa", .arch = "hppa", .license = "GPL3", @@ -81,9 +81,9 @@ RAsmPlugin r_asm_plugin_hppa_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_hppa_gnu, + .data = &rz_asm_plugin_hppa_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_i4004.c b/librz/asm/p/asm_i4004.c similarity index 58% rename from libr/asm/p/asm_i4004.c rename to librz/asm/p/asm_i4004.c index c9394589fc..5c3ed419bf 100644 --- a/libr/asm/p/asm_i4004.c +++ b/librz/asm/p/asm_i4004.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2014 - condret */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/i4004/i4004dis.c" -static int disassemble (RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble (RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { return i4004dis (op,buf,len); } -RAsmPlugin r_asm_plugin_i4004 = { +RzAsmPlugin rz_asm_plugin_i4004 = { .name = "i4004", .desc = "Intel 4004 microprocessor", .arch = "i4004", @@ -21,9 +21,9 @@ RAsmPlugin r_asm_plugin_i4004 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_i4004, + .data = &rz_asm_plugin_i4004, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_i8080.c b/librz/asm/p/asm_i8080.c similarity index 53% rename from libr/asm/p/asm_i8080.c rename to librz/asm/p/asm_i8080.c index 518e12933f..b899c7eac0 100644 --- a/libr/asm/p/asm_i8080.c +++ b/librz/asm/p/asm_i8080.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2012-2018 - Alexander */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/i8080/i8080dis.c" -static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - int dlen = i8080_disasm (buf, r_strbuf_get (&op->buf_asm), len); +static int do_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + int dlen = i8080_disasm (buf, rz_strbuf_get (&op->buf_asm), len); return op->size = R_MAX (0, dlen); } -RAsmPlugin r_asm_plugin_i8080 = { +RzAsmPlugin rz_asm_plugin_i8080 = { .name = "i8080", .desc = "Intel 8080 CPU", .arch = "i8080", @@ -22,9 +22,9 @@ RAsmPlugin r_asm_plugin_i8080 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_i8080, + .data = &rz_asm_plugin_i8080, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_java.c b/librz/asm/p/asm_java.c similarity index 60% rename from libr/asm/p/asm_java.c rename to librz/asm/p/asm_java.c index 054007cb10..fbac7ddfb9 100644 --- a/libr/asm/p/asm_java.c +++ b/librz/asm/p/asm_java.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2009-2019 - nibble, pancake */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "../../shlr/java/code.h" #include "../../shlr/java/class.h" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { RBinJavaObj *obj = NULL; RBin *bin = a->binb.bin; RBinPlugin *plugin = bin && bin->cur && bin->cur->o ? @@ -21,18 +21,18 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } char buf_asm[256]; - op->size = r_java_disasm (obj, a->pc, buf, len, buf_asm, sizeof (buf_asm)); - r_strbuf_set (&op->buf_asm, buf_asm); + op->size = rz_java_disasm (obj, a->pc, buf, len, buf_asm, sizeof (buf_asm)); + rz_strbuf_set (&op->buf_asm, buf_asm); return op->size; } -static int assemble(RAsm *a, RAsmOp *op, const char *input) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *input) { // TODO: get class info from bin if possible // XXX wrong usage of strbuf_get here - return op->size = r_java_assemble (a->pc, (ut8*)r_strbuf_get (&op->buf), input); + return op->size = rz_java_assemble (a->pc, (ut8*)rz_strbuf_get (&op->buf), input); } -RAsmPlugin r_asm_plugin_java = { +RzAsmPlugin rz_asm_plugin_java = { .name = "java", .desc = "Java bytecode", .arch = "java", @@ -44,9 +44,9 @@ RAsmPlugin r_asm_plugin_java = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_java, + .data = &rz_asm_plugin_java, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_lanai_gnu.c b/librz/asm/p/asm_lanai_gnu.c similarity index 84% rename from libr/asm/p/asm_lanai_gnu.c rename to librz/asm/p/asm_lanai_gnu.c index 3da59579fb..08a1e1a063 100644 --- a/libr/asm/p/asm_lanai_gnu.c +++ b/librz/asm/p/asm_lanai_gnu.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" static unsigned long Offset = 0; @@ -29,7 +29,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -52,12 +52,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_lanai ((bfd_vma)Offset, &disasm_obj); if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_lanai_gnu = { +RzAsmPlugin rz_asm_plugin_lanai_gnu = { .name = "lanai", // .gnu", .arch = "lanai", .license = "GPL3", @@ -68,9 +68,9 @@ RAsmPlugin r_asm_plugin_lanai_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_lanai_gnu, + .data = &rz_asm_plugin_lanai_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_lh5801.c b/librz/asm/p/asm_lh5801.c similarity index 66% rename from libr/asm/p/asm_lh5801.c rename to librz/asm/p/asm_lh5801.c index ccd3ddd4ae..5cfb12a81c 100644 --- a/libr/asm/p/asm_lh5801.c +++ b/librz/asm/p/asm_lh5801.c @@ -1,32 +1,32 @@ -/* radare2, Sharp LH5801 disassembler. +/* rizin, Sharp LH5801 disassembler. * (C) Copyright 2014-2015 jn, published under the LGPLv3 */ #include "../../arch/lh5801/lh5801.c" -#include -#include -#include +#include +#include +#include -static int disassemble(RAsm *as, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *as, RzAsmOp *op, const ut8 *buf, int len) { struct lh5801_insn insn = {0}; if (!op) { return 0; } int consumed = lh5801_decode (&insn, buf, len); if (consumed == -1 || consumed == 0) { - r_strbuf_set (&op->buf_asm, "invalid"); + rz_strbuf_set (&op->buf_asm, "invalid"); op->size = 1; return 0; } char buf_asm[128] = {0}; lh5801_print_insn (buf_asm, sizeof (buf_asm), &insn); - r_strbuf_set (&op->buf_asm, buf_asm); + rz_strbuf_set (&op->buf_asm, buf_asm); op->size = consumed; //op->payload = lh5801_insn_descs[insn.type].format & 3; // ^ MAYBE? return op->size; } -RAsmPlugin r_asm_plugin_lh5801 = { +RzAsmPlugin rz_asm_plugin_lh5801 = { .name = "lh5801", .arch = "LH5801", .license = "LGPL3", @@ -37,9 +37,9 @@ RAsmPlugin r_asm_plugin_lh5801 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_lh5801, + .data = &rz_asm_plugin_lh5801, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_lm32.c b/librz/asm/p/asm_lm32.c similarity index 76% rename from libr/asm/p/asm_lm32.c rename to librz/asm/p/asm_lm32.c index 0c8168d7aa..f89e4f1fe9 100644 --- a/libr/asm/p/asm_lm32.c +++ b/librz/asm/p/asm_lm32.c @@ -1,11 +1,11 @@ -/* lm32 support for radare2 +/* lm32 support for rizin * 2-clause BSD * Copyright 2015 Felix Held */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/lm32/lm32_isa.h" #define LM32_UNUSED 0 @@ -14,8 +14,8 @@ static int reg_number_to_string(ut8 reg, char *str) { ut8 match_idx = 0xff; int i; - for (i = 0; i < RAsmLm32RegNumber; i++) { - if (RAsmLm32Regs[i].number == reg) { + for (i = 0; i < RzAsmLm32RegNumber; i++) { + if (RzAsmLm32Regs[i].number == reg) { match_idx = i; break; } @@ -24,7 +24,7 @@ static int reg_number_to_string(ut8 reg, char *str) { if (match_idx == 0xff) { return -1; } - strcpy (str, RAsmLm32Regs[match_idx].name); + strcpy (str, RzAsmLm32Regs[match_idx].name); return 0; } @@ -32,38 +32,38 @@ static int reg_number_to_string(ut8 reg, char *str) { static int string_to_reg_number(const char *str, ut8 *num) { ut8 match_idx = 0xff; int i; - for (i = 0; i < RAsmLm32RegNumber; i++) { - if (!strcmp (RAsmLm32Regs[i].name, str)) { + for (i = 0; i < RzAsmLm32RegNumber; i++) { + if (!strcmp (RzAsmLm32Regs[i].name, str)) { match_idx = i; break; } } //register name string not found in array if (match_idx == 0xff) return -1; - *num = RAsmLm32Regs[match_idx].number; + *num = RzAsmLm32Regs[match_idx].number; return 0; } static int string_to_csr_number(const char *str, ut8 *num) { ut8 match_idx = 0xff; int i; - for (i = 0; i < RAsmLm32CsrNumber; i++) { - if (!strcmp (RAsmLm32Csrs[i].name, str)) { + for (i = 0; i < RzAsmLm32CsrNumber; i++) { + if (!strcmp (RzAsmLm32Csrs[i].name, str)) { match_idx = i; break; } } //csr name string not found in array if (match_idx == 0xff) return -1; - *num = RAsmLm32Csrs[match_idx].number; + *num = RzAsmLm32Csrs[match_idx].number; return 0; } static int string_to_opcode(const char *str, ut8 *num) { ut8 tmp_num = 0xff; int i; - for (i = 0; i < RAsmLm32OpcodeNumber; i++) { - if (!strcmp (RAsmLm32OpcodeList[i].name, str)) { + for (i = 0; i < RzAsmLm32OpcodeNumber; i++) { + if (!strcmp (RzAsmLm32OpcodeList[i].name, str)) { tmp_num = i; } } @@ -78,8 +78,8 @@ static int string_to_opcode(const char *str, ut8 *num) { static int csr_number_to_string(ut8 csr, char *str) { ut8 match_idx = 0xff; int i; - for (i = 0; i < RAsmLm32CsrNumber; i++) { - if (RAsmLm32Csrs[i].number == csr) { + for (i = 0; i < RzAsmLm32CsrNumber; i++) { + if (RzAsmLm32Csrs[i].number == csr) { match_idx = i; break; } @@ -88,7 +88,7 @@ static int csr_number_to_string(ut8 csr, char *str) { if (match_idx == 0xff) { return -1; } - strcpy (str, RAsmLm32Csrs[match_idx].name); + strcpy (str, RzAsmLm32Csrs[match_idx].name); return 0; } @@ -102,77 +102,77 @@ static st32 shift_and_signextend(ut8 shift, ut8 sign_loc, ut32 val) { } -static bool is_invalid_imm5_instr(RAsmLm32Instruction *instr) { - return instr->value & RAsmLm32InstrImm5InvalidBitsMask; +static bool is_invalid_imm5_instr(RzAsmLm32Instruction *instr) { + return instr->value & RzAsmLm32InstrImm5InvalidBitsMask; } -static bool is_invalid_one_reg_instr(RAsmLm32Instruction *instr) { - return instr->value & RAsmLm32InstrOneRegInvalidBitsMask; +static bool is_invalid_one_reg_instr(RzAsmLm32Instruction *instr) { + return instr->value & RzAsmLm32InstrOneRegInvalidBitsMask; } -static bool is_invalid_two_reg_instr(RAsmLm32Instruction *instr) { - return instr->value & RAsmLm32InstrTwoRegsInvalidBitsMask; +static bool is_invalid_two_reg_instr(RzAsmLm32Instruction *instr) { + return instr->value & RzAsmLm32InstrTwoRegsInvalidBitsMask; } -static bool is_invalid_wcsr_instr(RAsmLm32Instruction *instr) { - return instr->value & RAsmLm32InstrWcsrInvalidBitsMask; +static bool is_invalid_wcsr_instr(RzAsmLm32Instruction *instr) { + return instr->value & RzAsmLm32InstrWcsrInvalidBitsMask; } //ret == b ra -static bool is_pseudo_instr_ret(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_ret(RzAsmLm32Instruction *instr) { //"ra" == 0x1d return (instr->op == lm32_op_b) && (instr->src0_reg == 0x1d); } //mv rX, rY == or rX, rY, r0 -static bool is_pseudo_instr_mv(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_mv(RzAsmLm32Instruction *instr) { return (instr->op == lm32_op_or) && !instr->src1_reg; } //mvhi rX, imm16 == orhi rX, r0, imm16 -static bool is_pseudo_instr_mvhi(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_mvhi(RzAsmLm32Instruction *instr) { return (instr->op == lm32_op_orhi) && !instr->src0_reg; } //not rX, rY == xnor rX, rY, r0 -static bool is_pseudo_instr_not(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_not(RzAsmLm32Instruction *instr) { return (instr->op == lm32_op_xnor) && !instr->src1_reg; } //mvi rX, imm16 == addi rX, r0, imm16 -static bool is_pseudo_instr_mvi(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_mvi(RzAsmLm32Instruction *instr) { return (instr->op == lm32_op_addi) && !instr->src0_reg; } //nop == addi r0, r0, 0 -static bool is_pseudo_instr_nop(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_nop(RzAsmLm32Instruction *instr) { return (instr->op == lm32_op_addi) && !instr->dest_reg && !instr->src0_reg && !instr->immediate; } //raise instruction is used for break, scall -static bool is_pseudo_instr_raise(RAsmLm32Instruction *instr) { +static bool is_pseudo_instr_raise(RzAsmLm32Instruction *instr) { return instr->op == raise_instr; } -static int r_asm_lm32_decode(RAsmLm32Instruction *instr) { +static int rz_asm_lm32_decode(RzAsmLm32Instruction *instr) { instr->op = extract_opcode (instr->value); - if (instr->op >= RAsmLm32OpcodeNumber) { + if (instr->op >= RzAsmLm32OpcodeNumber) { return -1; } - instr->op_decode = RAsmLm32OpcodeList[instr->op]; + instr->op_decode = RzAsmLm32OpcodeList[instr->op]; switch (instr->op_decode.type) { case reg_imm16_signextend: instr->dest_reg = extract_reg_v (instr->value); instr->src0_reg = extract_reg_u (instr->value); - instr->immediate = shift_and_signextend (0, RAsmLm32Imm16SignBitPos, + instr->immediate = shift_and_signextend (0, RzAsmLm32Imm16SignBitPos, extract_imm16 (instr->value)); break; case reg_imm16_shift2_signextend: instr->dest_reg = extract_reg_v (instr->value); instr->src0_reg = extract_reg_u (instr->value); - instr->immediate = shift_and_signextend (2, RAsmLm32Imm16SignBitPos, + instr->immediate = shift_and_signextend (2, RzAsmLm32Imm16SignBitPos, extract_imm16 (instr->value)); break; case reg_imm16_zeroextend: @@ -230,7 +230,7 @@ static int r_asm_lm32_decode(RAsmLm32Instruction *instr) { instr->csr = extract_reg_u (instr->value); break; case imm26: - instr->immediate = shift_and_signextend (2, RAsmLm32Imm26SignBitPos, + instr->immediate = shift_and_signextend (2, RzAsmLm32Imm26SignBitPos, extract_imm26 (instr->value)); break; case reserved: @@ -246,7 +246,7 @@ static int r_asm_lm32_decode(RAsmLm32Instruction *instr) { return 0; } -static int write_reg_names_to_struct(RAsmLm32Instruction *instr) { +static int write_reg_names_to_struct(RzAsmLm32Instruction *instr) { switch (instr->op_decode.type) { case reg_imm16_signextend: case reg_imm16_shift2_signextend: @@ -301,7 +301,7 @@ static int write_reg_names_to_struct(RAsmLm32Instruction *instr) { return 0; } -static int print_pseudo_instruction(RAsmLm32Instruction *instr, char *str) { +static int print_pseudo_instruction(RzAsmLm32Instruction *instr, char *str) { if (!instr->pseudoInstruction) { return -1; } @@ -351,7 +351,7 @@ static int print_pseudo_instruction(RAsmLm32Instruction *instr, char *str) { } -static int r_asm_lm32_stringify(RAsmLm32Instruction *instr, char *str) { +static int rz_asm_lm32_stringify(RzAsmLm32Instruction *instr, char *str) { if (write_reg_names_to_struct (instr)) { return -1; } @@ -410,41 +410,41 @@ static int r_asm_lm32_stringify(RAsmLm32Instruction *instr, char *str) { #if 0 -static int r_asm_lm32_destringify(const char *string, RAsmLm32Instruction *instr) { +static int rz_asm_lm32_destringify(const char *string, RzAsmLm32Instruction *instr) { //TODO return -1; } -static int r_asm_lm32_encode(RAsmLm32Instruction *instr, ut32 *val) { +static int rz_asm_lm32_encode(RzAsmLm32Instruction *instr, ut32 *val) { //TODO return -1; } -static int assemble(RAsm *a, RAsmOp *ao, const char *str) { +static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) { //TODO return -1; } #endif -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - RAsmLm32Instruction instr = {0}; +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + RzAsmLm32Instruction instr = {0}; instr.value = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; instr.addr = a->pc; - if (r_asm_lm32_decode (&instr)) { - r_strbuf_set (&op->buf_asm, "invalid"); + if (rz_asm_lm32_decode (&instr)) { + rz_strbuf_set (&op->buf_asm, "invalid"); a->invhex = 1; return -1; } //op->buf_asm is 256 chars long, which is more than sufficient - if (r_asm_lm32_stringify (&instr, r_strbuf_get (&op->buf_asm))) { - r_strbuf_set (&op->buf_asm, "invalid"); + if (rz_asm_lm32_stringify (&instr, rz_strbuf_get (&op->buf_asm))) { + rz_strbuf_set (&op->buf_asm, "invalid"); a->invhex = 1; return -1; } return 4; } -RAsmPlugin r_asm_plugin_lm32 = { +RzAsmPlugin rz_asm_plugin_lm32 = { .name = "lm32", .arch = "lm32", .desc = "disassembly plugin for Lattice Micro 32 ISA", @@ -456,9 +456,9 @@ RAsmPlugin r_asm_plugin_lm32 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_lm32, + .data = &rz_asm_plugin_lm32, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_m680x_cs.c b/librz/asm/p/asm_m680x_cs.c similarity index 86% rename from libr/asm/p/asm_m680x_cs.c rename to librz/asm/p/asm_m680x_cs.c index 9877c4b505..eea59cd305 100644 --- a/libr/asm/p/asm_m680x_cs.c +++ b/librz/asm/p/asm_m680x_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2018-2019 - pancake */ +/* rizin - LGPL - Copyright 2018-2019 - pancake */ -#include -#include +#include +#include #include #if CS_API_MAJOR >= 4 && CS_API_MINOR >= 0 @@ -54,7 +54,7 @@ static bool the_end(void *p) { return true; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = 0; int mode, n, ret; ut64 off = a->pc; @@ -84,14 +84,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (ptrstr) { memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1); } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); } cs_free (insn, n); } return op->size; } -RAsmPlugin r_asm_plugin_m680x_cs = { +RzAsmPlugin rz_asm_plugin_m680x_cs = { .name = "m680x", .cpus = "6800,6801,6805,6808,6809,6811,cpu12,6301,6309,hcs08", .desc = "Capstone M680X Disassembler", @@ -104,7 +104,7 @@ RAsmPlugin r_asm_plugin_m680x_cs = { }; #else -RAsmPlugin r_asm_plugin_m680x_cs = { +RzAsmPlugin rz_asm_plugin_m680x_cs = { .name = "m680x", .desc = "Capstone M680X Disassembler (Not supported)", .license = "BSD", @@ -114,9 +114,9 @@ RAsmPlugin r_asm_plugin_m680x_cs = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_m680x_cs, + .data = &rz_asm_plugin_m680x_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_m68k_cs.c b/librz/asm/p/asm_m68k_cs.c similarity index 81% rename from libr/asm/p/asm_m68k_cs.c rename to librz/asm/p/asm_m68k_cs.c index 315840a30b..8125aed4a5 100644 --- a/libr/asm/p/asm_m68k_cs.c +++ b/librz/asm/p/asm_m68k_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2015-2018 - pancake */ +/* rizin - LGPL - Copyright 2015-2018 - pancake */ -#include -#include +#include +#include #include #ifdef CAPSTONE_M68K_H @@ -20,11 +20,11 @@ // Size of the longest instruction in bytes #define M68K_LONGEST_INSTRUCTION 10 -static bool check_features(RAsm *a, cs_insn *insn); +static bool check_features(RzAsm *a, cs_insn *insn); static csh cd = 0; #include "cs_mnemonics.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { const char *buf_asm = NULL; static int omode = -1; static int obits = 32; @@ -105,10 +105,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { buf_asm = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]?" ":"", insn->op_str); } if (op && buf_asm) { - char *p = r_str_replace (strdup (buf_asm), "$", "0x", true); + char *p = rz_str_replace (strdup (buf_asm), "$", "0x", true); if (p) { - r_str_replace_char (p, '#', 0); - r_asm_op_set_asm (op, p); + rz_str_replace_char (p, '#', 0); + rz_asm_op_set_asm (op, p); free (p); } } @@ -117,14 +117,14 @@ beach: //cs_close (&cd); if (op && buf_asm) { if (!strncmp (buf_asm, "dc.w", 4)) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); } return op->size; } return ret; } -RAsmPlugin r_asm_plugin_m68k_cs = { +RzAsmPlugin rz_asm_plugin_m68k_cs = { .name = "m68k", .desc = "Capstone M68K disassembler", .cpus = "68000,68010,68020,68030,68040,68060", @@ -136,21 +136,21 @@ RAsmPlugin r_asm_plugin_m68k_cs = { .mnemonics = &mnemonics, }; -static bool check_features(RAsm *a, cs_insn *insn) { +static bool check_features(RzAsm *a, cs_insn *insn) { /* TODO: Implement support for m68k */ return true; } #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_m68k_cs, + .data = &rz_asm_plugin_m68k_cs, .version = R2_VERSION }; #endif #else -RAsmPlugin r_asm_plugin_m68k_cs = { +RzAsmPlugin rz_asm_plugin_m68k_cs = { .name = "m68k.cs (unsupported)", .desc = "Capstone M68K disassembler (unsupported)", .license = "BSD", @@ -161,9 +161,9 @@ RAsmPlugin r_asm_plugin_m68k_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_m68k_cs, + .data = &rz_asm_plugin_m68k_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_malbolge.c b/librz/asm/p/asm_malbolge.c similarity index 76% rename from libr/asm/p/asm_malbolge.c rename to librz/asm/p/asm_malbolge.c index f85997201a..0f7d79a9a0 100644 --- a/libr/asm/p/asm_malbolge.c +++ b/librz/asm/p/asm_malbolge.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2014-2018 condret, pancake */ -#include -#include -#include +#include +#include +#include #include static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) { @@ -21,12 +21,12 @@ static const char *mal_dis(ut64 c, const ut8 *buf, ut64 len) { return NULL; } -static int __disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int __disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { const char *opstr = mal_dis (a->pc, buf, len); return op->size = opstr? 1: 0; } -RAsmPlugin r_asm_plugin_malbolge = { +RzAsmPlugin rz_asm_plugin_malbolge = { .name = "malbolge", .desc = "Malbolge Ternary VM", .arch = "malbolge", @@ -38,9 +38,9 @@ RAsmPlugin r_asm_plugin_malbolge = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_malbolge, + .data = &rz_asm_plugin_malbolge, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_mcore.c b/librz/asm/p/asm_mcore.c similarity index 64% rename from libr/asm/p/asm_mcore.c rename to librz/asm/p/asm_mcore.c index 5be32d5974..716eb0d5bf 100644 --- a/libr/asm/p/asm_mcore.c +++ b/librz/asm/p/asm_mcore.c @@ -1,12 +1,12 @@ -/* radare2 - LGPL3 - Copyright 2018 - deroad */ +/* rizin - LGPL3 - Copyright 2018 - deroad */ -#include -#include +#include +#include #include "../arch/mcore/mcore.h" static mcore_handle handle = {0}; -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { mcore_t* instr = NULL; char tmp[256]; if (!op || mcore_init (&handle, buf, len)) { @@ -16,14 +16,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if ((instr = mcore_next (&handle))) { mcore_snprint (tmp, sizeof (tmp), a->pc, instr); mcore_free (instr); - r_asm_op_set_asm (op, tmp); + rz_asm_op_set_asm (op, tmp); } else { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); } return op->size; } -RAsmPlugin r_asm_plugin_mcore = { +RzAsmPlugin rz_asm_plugin_mcore = { .name = "mcore", .desc = "Motorola MCORE disassembler", .license = "LGPL3", @@ -35,9 +35,9 @@ RAsmPlugin r_asm_plugin_mcore = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_mcore, + .data = &rz_asm_plugin_mcore, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_mcs96.c b/librz/asm/p/asm_mcs96.c similarity index 82% rename from libr/asm/p/asm_mcs96.c rename to librz/asm/p/asm_mcs96.c index b27cc96d3e..c1cf21b352 100644 --- a/libr/asm/p/asm_mcs96.c +++ b/librz/asm/p/asm_mcs96.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright - 2015-2019 - condret */ -#include +#include #include -#include -#include +#include +#include #include "../arch/mcs96/mcs96.h" static int mcs96_len (const ut8 *buf, int len, RStrBuf *asm_buf) { @@ -45,10 +45,10 @@ static int mcs96_len (const ut8 *buf, int len, RStrBuf *asm_buf) { } if (ret <= len) { const ut32 fe_idx = ((buf[1] & 0x70) >> 4) ^ 0x4; - r_strbuf_set (asm_buf, mcs96_fe_op[fe_idx]); + rz_strbuf_set (asm_buf, mcs96_fe_op[fe_idx]); if ((mcs96_op[buf[1]].type & (MCS96_2OP | MCS96_REG_8)) == (MCS96_2OP | MCS96_REG_8) && buf[2] > 0x19 && buf[3] > 0x19) { - r_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[2] - 0x1a, buf[3] - 0x1a); + rz_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[2] - 0x1a, buf[3] - 0x1a); } } else { ret = 0; @@ -87,10 +87,10 @@ static int mcs96_len (const ut8 *buf, int len, RStrBuf *asm_buf) { ret = 2; } if (ret <= len) { - r_strbuf_set (asm_buf, mcs96_op[buf[0]].ins); + rz_strbuf_set (asm_buf, mcs96_op[buf[0]].ins); if ((mcs96_op[buf[0]].type & (MCS96_2OP | MCS96_REG_8)) == (MCS96_2OP | MCS96_REG_8) && buf[1] > 0x19 && buf[2] > 0x19) { - r_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[1] - 0x1a, buf[2] - 0x1a); + rz_strbuf_appendf(asm_buf, " rb%02x, rb%02x", buf[1] - 0x1a, buf[2] - 0x1a); } } else { ret = 0; @@ -98,7 +98,7 @@ static int mcs96_len (const ut8 *buf, int len, RStrBuf *asm_buf) { return ret; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { if (len > 1 && !memcmp (buf, "\xff\xff", 2)) { return -1; } @@ -106,7 +106,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return op->size; } -RAsmPlugin r_asm_plugin_mcs96 = { +RzAsmPlugin rz_asm_plugin_mcs96 = { .name = "mcs96", .desc = "condrets car", .arch = "mcs96", @@ -117,9 +117,9 @@ RAsmPlugin r_asm_plugin_mcs96 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_mcs96, + .data = &rz_asm_plugin_mcs96, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_mips_cs.c b/librz/asm/p/asm_mips_cs.c similarity index 75% rename from libr/asm/p/asm_mips_cs.c rename to librz/asm/p/asm_mips_cs.c index 9b48545731..5de0d62307 100644 --- a/libr/asm/p/asm_mips_cs.c +++ b/librz/asm/p/asm_mips_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2013-2018 - pancake */ +/* rizin - LGPL - Copyright 2013-2018 - pancake */ -#include -#include +#include +#include #include R_IPI int mips_assemble(const char *str, ut64 pc, ut8 *out); @@ -9,7 +9,7 @@ R_IPI int mips_assemble(const char *str, ut64 pc, ut8 *out); static csh cd = 0; #include "cs_mnemonics.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; int mode, n, ret = -1; mode = (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN; @@ -30,7 +30,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } mode |= (a->bits == 64)? CS_MODE_MIPS64 : CS_MODE_MIPS32; - memset (op, 0, sizeof (RAsmOp)); + memset (op, 0, sizeof (RzAsmOp)); op->size = 4; if (cd != 0) { cs_close (&cd); @@ -47,7 +47,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF); n = cs_disasm (cd, (ut8*)buf, len, a->pc, 1, &insn); if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; goto beach; } @@ -55,11 +55,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { goto beach; } op->size = insn->size; - char *str = r_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); + char *str = rz_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); if (str) { - r_str_replace_char (str, '$', 0); + rz_str_replace_char (str, '$', 0); // remove the '$' in the string - r_asm_op_set_asm (op, str); + rz_asm_op_set_asm (op, str); free (str); } cs_free (insn, n); @@ -69,8 +69,8 @@ fin: return op->size; } -static int assemble(RAsm *a, RAsmOp *op, const char *str) { - ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf); +static int assemble(RzAsm *a, RzAsmOp *op, const char *str) { + ut8 *opbuf = (ut8*)rz_strbuf_get (&op->buf); int ret = mips_assemble (str, a->pc, opbuf); if (a->big_endian) { ut8 *buf = opbuf; @@ -84,7 +84,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *str) { return ret; } -RAsmPlugin r_asm_plugin_mips_cs = { +RzAsmPlugin rz_asm_plugin_mips_cs = { .name = "mips", .desc = "Capstone MIPS disassembler", .license = "BSD", @@ -98,9 +98,9 @@ RAsmPlugin r_asm_plugin_mips_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_mips_cs, + .data = &rz_asm_plugin_mips_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_mips_gnu.c b/librz/asm/p/asm_mips_gnu.c similarity index 75% rename from libr/asm/p/asm_mips_gnu.c rename to librz/asm/p/asm_mips_gnu.c index 3aeeaf8484..a8934bb00e 100644 --- a/libr/asm/p/asm_mips_gnu.c +++ b/librz/asm/p/asm_mips_gnu.c @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" #include "opcode/mips.h" @@ -36,7 +36,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, int len) { +static int disassemble(struct rz_asm_t *a, struct rz_asm_op_t *op, const ut8 *buf, int len) { static struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -52,28 +52,28 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, /* prepare disassembler */ if (a->cpu && (!pre_cpu || !strcmp(a->cpu, pre_cpu))) { - if (!r_str_casecmp (a->cpu, "mips64r2")) { + if (!rz_str_casecmp (a->cpu, "mips64r2")) { disasm_obj.mach = bfd_mach_mipsisa64r2; - } else if (!r_str_casecmp (a->cpu, "mips32r2")) { + } else if (!rz_str_casecmp (a->cpu, "mips32r2")) { disasm_obj.mach = bfd_mach_mipsisa32r2; - } else if (!r_str_casecmp (a->cpu, "mips64")) { + } else if (!rz_str_casecmp (a->cpu, "mips64")) { disasm_obj.mach = bfd_mach_mipsisa64; - } else if (!r_str_casecmp (a->cpu, "mips32")) { + } else if (!rz_str_casecmp (a->cpu, "mips32")) { disasm_obj.mach = bfd_mach_mipsisa32; } - pre_cpu = r_str_dup (pre_cpu, a->cpu); + pre_cpu = rz_str_dup (pre_cpu, a->cpu); } if (a->features && (!pre_features || !strcmp (a->features, pre_features))) { free (disasm_obj.disassembler_options); if (strstr (a->features, "n64")) { - disasm_obj.disassembler_options = r_str_new ("abi=n64"); + disasm_obj.disassembler_options = rz_str_new ("abi=n64"); } else if (strstr (a->features, "n32")) { - disasm_obj.disassembler_options = r_str_new ("abi=n32"); + disasm_obj.disassembler_options = rz_str_new ("abi=n32"); } else if (strstr (a->features, "o32")) { - disasm_obj.disassembler_options = r_str_new ("abi=o32"); + disasm_obj.disassembler_options = rz_str_new ("abi=o32"); } - pre_features = r_str_dup (pre_features, a->features); + pre_features = rz_str_dup (pre_features, a->features); } mips_mode = a->bits; @@ -92,13 +92,13 @@ static int disassemble(struct r_asm_t *a, struct r_asm_op_t *op, const ut8 *buf, ? print_insn_little_mips ((bfd_vma)Offset, &disasm_obj) : print_insn_big_mips ((bfd_vma)Offset, &disasm_obj); if (op->size == -1) { - r_strbuf_set (&op->buf_asm, "(data)"); + rz_strbuf_set (&op->buf_asm, "(data)"); } return op->size; } -static int assemble(RAsm *a, RAsmOp *op, const char *str) { - ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf); +static int assemble(RzAsm *a, RzAsmOp *op, const char *str) { + ut8 *opbuf = (ut8*)rz_strbuf_get (&op->buf); int ret = mips_assemble (str, a->pc, opbuf); if (a->big_endian) { ut8 tmp = opbuf[0]; @@ -111,7 +111,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *str) { return ret; } -RAsmPlugin r_asm_plugin_mips_gnu = { +RzAsmPlugin rz_asm_plugin_mips_gnu = { .name = "mips.gnu", .arch = "mips", .license = "GPL3", @@ -123,9 +123,9 @@ RAsmPlugin r_asm_plugin_mips_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_mips_gnu, + .data = &rz_asm_plugin_mips_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_msp430.c b/librz/asm/p/asm_msp430.c similarity index 50% rename from libr/asm/p/asm_msp430.c rename to librz/asm/p/asm_msp430.c index 8732b554af..5c101d8883 100644 --- a/libr/asm/p/asm_msp430.c +++ b/librz/asm/p/asm_msp430.c @@ -2,34 +2,34 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct msp430_cmd cmd; int ret = msp430_decode_command (buf, len, &cmd); if (ret > 0) { if (cmd.operands[0]) { - r_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); + rz_strbuf_set (&op->buf_asm, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); } else { - r_strbuf_set (&op->buf_asm, sdb_fmt ("%s", cmd.instr)); + rz_strbuf_set (&op->buf_asm, sdb_fmt ("%s", cmd.instr)); } } if (a->syntax != R_ASM_SYNTAX_ATT) { - char *ba = (char *)r_strbuf_get (&op->buf_asm); - r_str_replace_ch (ba, '#', 0, 1); - // r_str_replace_ch (ba, "$", "$$", 1); - r_str_replace_ch (ba, '&', 0, 1); - r_str_replace_ch (ba, '%', 0, 1); + char *ba = (char *)rz_strbuf_get (&op->buf_asm); + rz_str_replace_ch (ba, '#', 0, 1); + // rz_str_replace_ch (ba, "$", "$$", 1); + rz_str_replace_ch (ba, '&', 0, 1); + rz_str_replace_ch (ba, '%', 0, 1); } return op->size = ret; } -RAsmPlugin r_asm_plugin_msp430 = { +RzAsmPlugin rz_asm_plugin_msp430 = { .name = "msp430", .license = "LGPL3", .desc = "msp430 disassembly plugin", @@ -40,9 +40,9 @@ RAsmPlugin r_asm_plugin_msp430 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_msp430, + .data = &rz_asm_plugin_msp430, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_nios2.c b/librz/asm/p/asm_nios2.c similarity index 84% rename from libr/asm/p/asm_nios2.c rename to librz/asm/p/asm_nios2.c index c533a145ef..3d85b18162 100644 --- a/libr/asm/p/asm_nios2.c +++ b/librz/asm/p/asm_nios2.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2014-2018 - pancake */ +/* rizin - LGPL - Copyright 2014-2018 - pancake */ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -34,7 +34,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, struct rz_asm_op_t *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -61,12 +61,12 @@ static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) op->size = print_insn_little_nios2 ((bfd_vma)Offset, &disasm_obj); } if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_nios2 = { +RzAsmPlugin rz_asm_plugin_nios2 = { .name = "nios2", .arch = "nios2", .license = "GPL3", @@ -77,9 +77,9 @@ RAsmPlugin r_asm_plugin_nios2 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_nios2, + .data = &rz_asm_plugin_nios2, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_null.c b/librz/asm/p/asm_null.c similarity index 58% rename from libr/asm/p/asm_null.c rename to librz/asm/p/asm_null.c index 75144974e2..62e3a1290d 100644 --- a/libr/asm/p/asm_null.c +++ b/librz/asm/p/asm_null.c @@ -2,22 +2,22 @@ #include #include -#include -#include -#include +#include +#include +#include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { int opsz = 0; - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); op->size = opsz; return opsz; } -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { return 0; } -RAsmPlugin r_asm_plugin_null = { +RzAsmPlugin rz_asm_plugin_null = { .name = "null", .author = "pancake", .version = "1.0.0", @@ -31,9 +31,9 @@ RAsmPlugin r_asm_plugin_null = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_null, + .data = &rz_asm_plugin_null, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_or1k.c b/librz/asm/p/asm_or1k.c similarity index 86% rename from libr/asm/p/asm_or1k.c rename to librz/asm/p/asm_or1k.c index 1c20883c05..afbe5e8cd6 100644 --- a/libr/asm/p/asm_or1k.c +++ b/librz/asm/p/asm_or1k.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2019 - v3l0c1r4pt0r */ +/* rizin - LGPL - Copyright 2019 - v3l0c1r4pt0r */ -#include -#include +#include +#include #include "../arch/or1k/or1k_disas.h" struct operands { @@ -16,7 +16,7 @@ struct operands { ut32 l; }; -static int insn_to_str(RAsm *a, char **line, insn_t *descr, insn_extra_t *extra, ut32 insn) { +static int insn_to_str(RzAsm *a, char **line, insn_t *descr, insn_extra_t *extra, ut32 insn) { struct operands o = {0}; char *name; insn_type_t type = type_of_opcode(descr, extra); @@ -104,7 +104,7 @@ static int insn_to_str(RAsm *a, char **line, insn_t *descr, insn_extra_t *extra, return 4; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { ut32 insn, opcode; ut8 opcode_idx; char *line = NULL; @@ -115,12 +115,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (len < 4) { line = sdb_fmt("invalid"); - r_strbuf_set (&op->buf_asm, line); + rz_strbuf_set (&op->buf_asm, line); return op->size; } /* read instruction and basic opcode value */ - insn = r_read_be32(buf); + insn = rz_read_be32(buf); op->size = 4; opcode = (insn & INSN_OPCODE_MASK); opcode_idx = opcode >> INSN_OPCODE_SHIFT; @@ -128,7 +128,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { /* make sure instruction descriptor table is not overflowed */ if (opcode_idx >= insns_count) { line = sdb_fmt("invalid"); - r_strbuf_set (&op->buf_asm, line); + rz_strbuf_set (&op->buf_asm, line); return op->size; } @@ -136,7 +136,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { insn_descr = &or1k_insns[opcode_idx]; if (insn_descr->type == INSN_INVAL) { line = sdb_fmt("invalid"); - r_strbuf_set (&op->buf_asm, line); + rz_strbuf_set (&op->buf_asm, line); return op->size; } @@ -148,16 +148,16 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { line = "invalid"; } - r_strbuf_set (&op->buf_asm, line); + rz_strbuf_set (&op->buf_asm, line); } else { /* otherwise basic descriptor is enough */ insn_to_str(a, &line, insn_descr, NULL, insn); - r_strbuf_set (&op->buf_asm, line); + rz_strbuf_set (&op->buf_asm, line); } return op->size; } -RAsmPlugin r_asm_plugin_or1k = { +RzAsmPlugin rz_asm_plugin_or1k = { .name = "or1k", .desc = "OpenRISC 1000", .license = "LGPL3", @@ -168,6 +168,6 @@ RAsmPlugin r_asm_plugin_or1k = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { - .type = R_LIB_TYPE_ASM, .data = &r_asm_plugin_or1k, .version = R2_VERSION}; +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_ASM, .data = &rz_asm_plugin_or1k, .version = R2_VERSION}; #endif diff --git a/libr/asm/p/asm_pic.c b/librz/asm/p/asm_pic.c similarity index 72% rename from libr/asm/p/asm_pic.c rename to librz/asm/p/asm_pic.c index 2f592e63ca..9e604ac850 100644 --- a/libr/asm/p/asm_pic.c +++ b/librz/asm/p/asm_pic.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2018 - thestr4ng3r, courk */ +/* rizin - LGPL - Copyright 2018 - thestr4ng3r, courk */ -#include -#include +#include +#include #include "../arch/pic/pic_baseline.h" #include "../arch/pic/pic_pic18.h" #include "../arch/pic/pic_midrange.h" -static int asm_pic_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) { +static int asm_pic_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *b, int l) { int res = -1; char opbuf[128]; const char *opstr = opbuf; @@ -19,11 +19,11 @@ static int asm_pic_disassemble(RAsm *a, RAsmOp *op, const ut8 *b, int l) { } else if (a->cpu && strcasecmp (a->cpu, "pic18") == 0) { res = pic_pic18_disassemble (op, opbuf, b, l); } - r_asm_op_set_asm (op, opstr); + rz_asm_op_set_asm (op, opstr); return op->size = res; } -RAsmPlugin r_asm_plugin_pic = { +RzAsmPlugin rz_asm_plugin_pic = { .name = "pic", .arch = "pic", .cpus = "baseline,midrange,pic18", @@ -34,8 +34,8 @@ RAsmPlugin r_asm_plugin_pic = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_pic + .data = &rz_asm_plugin_pic }; #endif diff --git a/libr/asm/p/asm_ppc_cs.c b/librz/asm/p/asm_ppc_cs.c similarity index 79% rename from libr/asm/p/asm_ppc_cs.c rename to librz/asm/p/asm_ppc_cs.c index 825db38547..693abb82c3 100644 --- a/libr/asm/p/asm_ppc_cs.c +++ b/librz/asm/p/asm_ppc_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2014-2018 - pancake */ +/* rizin - LGPL - Copyright 2014-2018 - pancake */ -#include -#include +#include +#include #include #include "../arch/ppc/libvle/vle.h" #include "../arch/ppc/libps/libps.h" @@ -16,7 +16,7 @@ static bool the_end(void *p) { return true; } -static int decompile_vle(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int decompile_vle(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { vle_t* instr = 0; vle_handle handle = {0}; if (len < 2) { @@ -26,17 +26,17 @@ static int decompile_vle(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = instr->size; char buf_asm[64]; vle_snprint (buf_asm, sizeof (buf_asm), a->pc, instr); - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); vle_free (instr); } else { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 2; return -1; } return op->size; } -static int decompile_ps(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int decompile_ps(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { ppcps_t instr = {0}; if (len < 4) { return -1; @@ -44,16 +44,16 @@ static int decompile_ps(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = 4; const ut32 data = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; if (libps_decode (data, &instr) < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); return -1; } char buf_asm[64]; libps_snprint (buf_asm, sizeof (buf_asm), a->pc, &instr); - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); return op->size; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = -1, obits = -1; int n, ret; ut64 off = a->pc; @@ -99,17 +99,17 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (n > 0 && insn->size > 0) { const char *opstr = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0] ? " " : "", insn->op_str); - r_asm_op_set_asm (op, opstr); + rz_asm_op_set_asm (op, opstr); cs_free (insn, n); return op->size; } - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; cs_free (insn, n); return op->size; } -RAsmPlugin r_asm_plugin_ppc_cs = { +RzAsmPlugin rz_asm_plugin_ppc_cs = { .name = "ppc", .desc = "Capstone PowerPC disassembler", .license = "BSD", @@ -123,9 +123,9 @@ RAsmPlugin r_asm_plugin_ppc_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_ppc_cs, + .data = &rz_asm_plugin_ppc_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_ppc_gnu.c b/librz/asm/p/asm_ppc_gnu.c similarity index 85% rename from libr/asm/p/asm_ppc_gnu.c rename to librz/asm/p/asm_ppc_gnu.c index 977b22fc20..d9c15fa8f2 100644 --- a/libr/asm/p/asm_ppc_gnu.c +++ b/librz/asm/p/asm_ppc_gnu.c @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -32,7 +32,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; if (len<4) { return -1; @@ -58,12 +58,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_little_powerpc ((bfd_vma)Offset, &disasm_obj); } if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_ppc_gnu = { +RzAsmPlugin rz_asm_plugin_ppc_gnu = { .name = "ppc.gnu", .arch = "ppc", .license = "GPL3", @@ -74,9 +74,9 @@ RAsmPlugin r_asm_plugin_ppc_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_ppc_gnu, + .data = &rz_asm_plugin_ppc_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_propeller.c b/librz/asm/p/asm_propeller.c similarity index 73% rename from libr/asm/p/asm_propeller.c rename to librz/asm/p/asm_propeller.c index dbbd2752d6..cdf1254002 100644 --- a/libr/asm/p/asm_propeller.c +++ b/librz/asm/p/asm_propeller.c @@ -2,13 +2,13 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { const char *buf_asm; struct propeller_cmd cmd; int ret = propeller_decode_command (buf, &cmd); @@ -19,12 +19,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } else { buf_asm = sdb_fmt ("%s", cmd.instr); } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); op->size = 4; return ret; } -RAsmPlugin r_asm_plugin_propeller = { +RzAsmPlugin rz_asm_plugin_propeller = { .name = "propeller", .license = "LGPL3", .desc = "propeller disassembly plugin", @@ -35,9 +35,9 @@ RAsmPlugin r_asm_plugin_propeller = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_propeller, + .data = &rz_asm_plugin_propeller, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_pyc.c b/librz/asm/p/asm_pyc.c similarity index 66% rename from libr/asm/p/asm_pyc.c rename to librz/asm/p/asm_pyc.c index 3c2b60539d..f05619d47b 100644 --- a/libr/asm/p/asm_pyc.c +++ b/librz/asm/p/asm_pyc.c @@ -1,16 +1,16 @@ /* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/pyc/pyc_dis.h" static pyc_opcodes *opcodes_cache = NULL; -static int disassemble(RAsm *a, RAsmOp *opstruct, const ut8 *buf, int len) { - RList *shared = NULL; +static int disassemble(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) { + RzList *shared = NULL; RBin *bin = a->binb.bin; ut64 pc = a->pc; @@ -22,13 +22,13 @@ static int disassemble(RAsm *a, RAsmOp *opstruct, const ut8 *buf, int len) { shared = bin->cur->o->bin_obj; } } - RList *cobjs = r_list_get_n (shared, 0); - RList *interned_table = r_list_get_n (shared, 1); + RzList *cobjs = rz_list_get_n (shared, 0); + RzList *interned_table = rz_list_get_n (shared, 1); if (!opcodes_cache || !pyc_opcodes_equal (opcodes_cache, a->cpu)) { opcodes_cache = get_opcode_by_version (a->cpu); opcodes_cache->bits = a->bits; } - int r = r_pyc_disasm (opstruct, buf, cobjs, interned_table, pc, opcodes_cache); + int r = rz_pyc_disasm (opstruct, buf, cobjs, interned_table, pc, opcodes_cache); opstruct->size = r; return r; } @@ -41,7 +41,7 @@ static bool finish(void *user) { return true; } -RAsmPlugin r_asm_plugin_pyc = { +RzAsmPlugin rz_asm_plugin_pyc = { .name = "pyc", .arch = "pyc", .license = "LGPL3", @@ -52,9 +52,9 @@ RAsmPlugin r_asm_plugin_pyc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_pyc, + .data = &rz_asm_plugin_pyc, .version = R2_VERSION }; diff --git a/libr/asm/p/asm_riscv.c b/librz/asm/p/asm_riscv.c similarity index 62% rename from libr/asm/p/asm_riscv.c rename to librz/asm/p/asm_riscv.c index c62b53757f..a256cb54ef 100644 --- a/libr/asm/p/asm_riscv.c +++ b/librz/asm/p/asm_riscv.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2015-2016 - qnix */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/riscv/riscv-opc.c" #include "../arch/riscv/riscv.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { return op->size = riscv_dis (a, op, buf, len); } -RAsmPlugin r_asm_plugin_riscv = { +RzAsmPlugin rz_asm_plugin_riscv = { .name = "riscv", .desc = "RISC-V", .arch = "riscv", @@ -22,9 +22,9 @@ RAsmPlugin r_asm_plugin_riscv = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_riscv, + .data = &rz_asm_plugin_riscv, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_riscv_cs.c b/librz/asm/p/asm_riscv_cs.c similarity index 69% rename from libr/asm/p/asm_riscv_cs.c rename to librz/asm/p/asm_riscv_cs.c index a484eda3b7..a4c7415d60 100644 --- a/libr/asm/p/asm_riscv_cs.c +++ b/librz/asm/p/asm_riscv_cs.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2019 - pancake */ +/* rizin - LGPL - Copyright 2019 - pancake */ -#include -#include +#include +#include #include #if CSNEXT @@ -9,7 +9,7 @@ static csh cd = 0; #include "cs_mnemonics.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; int mode = (a->bits == 64)? CS_MODE_RISCV64 : CS_MODE_RISCV32; op->size = 4; @@ -30,7 +30,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { #endif int n = cs_disasm (cd, (ut8*)buf, len, a->pc, 1, &insn); if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 2; goto beach; } @@ -38,11 +38,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { goto beach; } op->size = insn->size; - char *str = r_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); + char *str = rz_str_newf ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); if (str) { - r_str_replace_char (str, '$', 0); + rz_str_replace_char (str, '$', 0); // remove the '$' in the string - r_asm_op_set_asm (op, str); + rz_asm_op_set_asm (op, str); free (str); } cs_free (insn, n); @@ -52,7 +52,7 @@ fin: return op->size; } -RAsmPlugin r_asm_plugin_riscv_cs = { +RzAsmPlugin rz_asm_plugin_riscv_cs = { .name = "riscv.cs", .desc = "Capstone RISCV disassembler", .license = "BSD", @@ -65,19 +65,19 @@ RAsmPlugin r_asm_plugin_riscv_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_riscv_cs, + .data = &rz_asm_plugin_riscv_cs, .version = R2_VERSION }; #endif #else -RAsmPlugin r_asm_plugin_riscv_cs = { +RzAsmPlugin rz_asm_plugin_riscv_cs = { 0 }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, .version = R2_VERSION }; diff --git a/librz/asm/p/asm_rsp.c b/librz/asm/p/asm_rsp.c new file mode 100644 index 0000000000..4eb018af49 --- /dev/null +++ b/librz/asm/p/asm_rsp.c @@ -0,0 +1,107 @@ +/* radare - LGPL - Copyright 2016 - bobby.smiles32@gmail.com */ +// TODO: add assembler + +#include +#include +#include +#include + +#include +#include + +#include "rsp_idec.h" + + +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + rsp_instruction rz_instr; + int i; + + /* all instructions are 32bit words */ + if (len < 4) { + op->size = 0; + return 0; + } + op->size = 4; + + ut32 iw = rz_read_ble32 (buf, a->big_endian); + rz_instr = rsp_instruction_decode (a->pc, iw); + + rz_strbuf_append (&op->buf_asm, rz_instr.mnemonic); + for (i = 0; i < rz_instr.noperands; i++) { + rz_strbuf_append (&op->buf_asm, (i == 0) ? " " : ", "); + + switch (rz_instr.operands[i].type) { + case RSP_OPND_GP_REG: + rz_strbuf_append (&op->buf_asm, rsp_gp_reg_soft_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_OFFSET: + case RSP_OPND_TARGET: + rz_strbuf_appendf (&op->buf_asm, "0x%08"PFMT64x, rz_instr.operands[i].u); + break; + case RSP_OPND_ZIMM: + { + int shift = (rz_instr.operands[i].u & ~0xffff) ? 16 : 0; + rz_strbuf_appendf (&op->buf_asm, "0x%04"PFMT64x, + rz_instr.operands[i].u >> shift); + } + break; + case RSP_OPND_SIMM: + rz_strbuf_appendf (&op->buf_asm, "%s0x%04"PFMT64x, + (rz_instr.operands[i].s<0)?"-":"", + (rz_instr.operands[i].s<0)?-rz_instr.operands[i].s:rz_instr.operands[i].s); + break; + case RSP_OPND_SHIFT_AMOUNT: + rz_strbuf_appendf (&op->buf_asm, "%"PFMT64u, rz_instr.operands[i].u); + break; + case RSP_OPND_BASE_OFFSET: + rz_strbuf_appendf (&op->buf_asm, "%s0x%04x(%s)", + (rz_instr.operands[i].s<0)?"-":"", + (ut32)((rz_instr.operands[i].s<0)?-rz_instr.operands[i].s:rz_instr.operands[i].s), + rsp_gp_reg_soft_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_C0_REG: + rz_strbuf_append (&op->buf_asm, rsp_c0_reg_soft_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_C2_CREG: + rz_strbuf_append (&op->buf_asm, rsp_c2_creg_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_C2_ACCU: + rz_strbuf_append (&op->buf_asm, rsp_c2_accu_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_C2_VREG: + rz_strbuf_append (&op->buf_asm, rsp_c2_vreg_names[rz_instr.operands[i].u]); + break; + case RSP_OPND_C2_VREG_BYTE: + case RSP_OPND_C2_VREG_SCALAR: + rz_strbuf_appendf (&op->buf_asm, "%s[%u]", rsp_c2_vreg_names[rz_instr.operands[i].u], + (ut32)rz_instr.operands[i].s); + break; + case RSP_OPND_C2_VREG_ELEMENT: + rz_strbuf_appendf (&op->buf_asm, "%s%s", rsp_c2_vreg_names[rz_instr.operands[i].u], rsp_c2_vreg_element_names[rz_instr.operands[i].s]); + break; + default: /* should not happend */ + rz_strbuf_append (&op->buf_asm, "???"); + break; + } + } + + return op->size; +} + +RzAsmPlugin rz_asm_plugin_rsp = { + .name = "rsp", + .desc = "Reality Signal Processor", + .arch = "rsp", + .bits = 32, + .endian = R_SYS_ENDIAN_BI, /* For conveniance, we don't force BIG endian but allow both to be used */ + .license = "LGPL3", + .disassemble = &disassemble +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_ASM, + .data = &rz_asm_plugin_rsp, + .version = R2_VERSION +}; +#endif diff --git a/libr/asm/p/asm_sh.c b/librz/asm/p/asm_sh.c similarity index 87% rename from libr/asm/p/asm_sh.c rename to librz/asm/p/asm_sh.c index a28bc81c79..901e07effe 100644 --- a/libr/asm/p/asm_sh.c +++ b/librz/asm/p/asm_sh.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" static unsigned long Offset = 0; @@ -33,7 +33,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static struct disassemble_info disasm_obj; if (len < 2) { return -1; @@ -59,12 +59,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_shl ((bfd_vma)Offset, &disasm_obj); } if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_sh = { +RzAsmPlugin rz_asm_plugin_sh = { .name = "sh", .arch = "sh", .license = "GPL3", @@ -75,9 +75,9 @@ RAsmPlugin r_asm_plugin_sh = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_sh, + .data = &rz_asm_plugin_sh, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_snes.c b/librz/asm/p/asm_snes.c similarity index 81% rename from libr/asm/p/asm_snes.c rename to librz/asm/p/asm_snes.c index 1bf33ffe0f..742bca0c41 100644 --- a/libr/asm/p/asm_snes.c +++ b/librz/asm/p/asm_snes.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2012-2015 - condret, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/snes/snesdis.c" #include "asm_snes.h" @@ -23,7 +23,7 @@ static bool snes_asm_fini (void* user) { return 0; } -static int dis(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { int dlen = snesDisass (snesflags->M, snesflags->X, a->pc, op, buf, len); if (dlen < 0) { dlen = 0; @@ -47,7 +47,7 @@ static int dis(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return dlen; } -RAsmPlugin r_asm_plugin_snes = { +RzAsmPlugin rz_asm_plugin_snes = { .name = "snes", .desc = "SuperNES CPU", .arch = "snes", @@ -60,9 +60,9 @@ RAsmPlugin r_asm_plugin_snes = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_snes, + .data = &rz_asm_plugin_snes, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_snes.h b/librz/asm/p/asm_snes.h similarity index 100% rename from libr/asm/p/asm_snes.h rename to librz/asm/p/asm_snes.h diff --git a/libr/asm/p/asm_sparc_cs.c b/librz/asm/p/asm_sparc_cs.c similarity index 73% rename from libr/asm/p/asm_sparc_cs.c rename to librz/asm/p/asm_sparc_cs.c index c38195c4da..fd72122ba5 100644 --- a/libr/asm/p/asm_sparc_cs.c +++ b/librz/asm/p/asm_sparc_cs.c @@ -1,12 +1,12 @@ -/* radare2 - LGPL - Copyright 2014-2017 - pancake */ +/* rizin - LGPL - Copyright 2014-2017 - pancake */ -#include -#include +#include +#include #include static csh cd = 0; #include "cs_mnemonics.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; int n = -1, ret = -1; int mode = CS_MODE_BIG_ENDIAN; @@ -16,7 +16,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } if (op) { - memset (op, 0, sizeof (RAsmOp)); + memset (op, 0, sizeof (RzAsmOp)); op->size = 4; } if (cd != 0) { @@ -34,7 +34,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { n = cs_disasm (cd, buf, len, a->pc, 1, &insn); } if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; ret = -1; goto beach; @@ -48,8 +48,8 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { char *buf_asm = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); - r_str_replace_char (buf_asm, '%', 0); - r_asm_op_set_asm (op, buf_asm); + rz_str_replace_char (buf_asm, '%', 0); + rz_asm_op_set_asm (op, buf_asm); // TODO: remove the '$' in the string cs_free (insn, n); beach: @@ -58,7 +58,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return ret; } -RAsmPlugin r_asm_plugin_sparc_cs = { +RzAsmPlugin rz_asm_plugin_sparc_cs = { .name = "sparc", .desc = "Capstone SPARC disassembler", .license = "BSD", @@ -71,9 +71,9 @@ RAsmPlugin r_asm_plugin_sparc_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_sparc_cs, + .data = &rz_asm_plugin_sparc_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_sparc_gnu.c b/librz/asm/p/asm_sparc_gnu.c similarity index 78% rename from libr/asm/p/asm_sparc_gnu.c rename to librz/asm/p/asm_sparc_gnu.c index 1f1b815fe2..1d92b749d0 100644 --- a/libr/asm/p/asm_sparc_gnu.c +++ b/librz/asm/p/asm_sparc_gnu.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" #include @@ -30,7 +30,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -38,9 +38,9 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { buf_global = &op->buf_asm; Offset = a->pc; // disasm inverted - r_mem_swapendian (bytes, buf, 4); // TODO handle thumb + rz_mem_swapendian (bytes, buf, 4); // TODO handle thumb - r_strbuf_set (&op->buf_asm, ""); + rz_strbuf_set (&op->buf_asm, ""); /* prepare disassembler */ memset (&disasm_obj,'\0', sizeof (struct disassemble_info)); disasm_obj.buffer = bytes; @@ -57,16 +57,16 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_sparc ((bfd_vma)Offset, &disasm_obj); - if (!strncmp (r_strbuf_get (&op->buf_asm), "unknown", 7)) { - r_asm_op_set_asm (op, "invalid"); + if (!strncmp (rz_strbuf_get (&op->buf_asm), "unknown", 7)) { + rz_asm_op_set_asm (op, "invalid"); } if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_sparc_gnu = { +RzAsmPlugin rz_asm_plugin_sparc_gnu = { .name = "sparc.gnu", .arch = "sparc", .bits = 32|64, @@ -77,9 +77,9 @@ RAsmPlugin r_asm_plugin_sparc_gnu = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_sparc_gnu, + .data = &rz_asm_plugin_sparc_gnu, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_spc700.c b/librz/asm/p/asm_spc700.c similarity index 57% rename from libr/asm/p/asm_spc700.c rename to librz/asm/p/asm_spc700.c index 233dc3a7a3..9fe5e08e76 100644 --- a/libr/asm/p/asm_spc700.c +++ b/librz/asm/p/asm_spc700.c @@ -3,22 +3,22 @@ // fork of asm_z80.c -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/spc700/spc700dis.c" -static int disassemble(RAsm *a, RAsmOp *r_op, const ut8 *buf, int len) { - int dlen = spc700Disass(r_op, buf, len); +static int disassemble(RzAsm *a, RzAsmOp *rz_op, const ut8 *buf, int len) { + int dlen = spc700Disass(rz_op, buf, len); if (dlen < 0) { dlen = 0; } - r_op->size = dlen; + rz_op->size = dlen; return dlen; } -RAsmPlugin r_asm_plugin_spc700 = { +RzAsmPlugin rz_asm_plugin_spc700 = { .name = "spc700", .desc = "spc700, snes' sound-chip", .arch = "spc700", @@ -29,9 +29,9 @@ RAsmPlugin r_asm_plugin_spc700 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_spc700, + .data = &rz_asm_plugin_spc700, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_sysz.c b/librz/asm/p/asm_sysz.c similarity index 79% rename from libr/asm/p/asm_sysz.c rename to librz/asm/p/asm_sysz.c index c3466ea95e..c1331e259d 100644 --- a/libr/asm/p/asm_sysz.c +++ b/librz/asm/p/asm_sysz.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2013-2015 - pancake */ +/* rizin - LGPL - Copyright 2013-2015 - pancake */ // instruction set : http://www.tachyonsoft.com/inst390m.htm -#include -#include +#include +#include #include static csh cd = 0; @@ -16,7 +16,7 @@ static bool the_end(void *p) { return true; } -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = 0; int mode, n, ret; ut64 off = a->pc; @@ -46,14 +46,14 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (ptrstr) { memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1); } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); } cs_free (insn, n); } return op->size; } -RAsmPlugin r_asm_plugin_sysz = { +RzAsmPlugin rz_asm_plugin_sysz = { .name = "sysz", .desc = "SystemZ CPU disassembler", .license = "BSD", @@ -65,9 +65,9 @@ RAsmPlugin r_asm_plugin_sysz = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_sysz, + .data = &rz_asm_plugin_sysz, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_tms320.c b/librz/asm/p/asm_tms320.c similarity index 71% rename from libr/asm/p/asm_tms320.c rename to librz/asm/p/asm_tms320.c index e17dcd364e..6ca3378560 100644 --- a/libr/asm/p/asm_tms320.c +++ b/librz/asm/p/asm_tms320.c @@ -7,9 +7,9 @@ */ #include -#include -#include -#include +#include +#include +#include #include static csh cd = 0; @@ -24,12 +24,12 @@ static csh cd = 0; #if CAPSTONE_HAS_TMS320C64X -static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int tms320c64x_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; int n = -1, ret = -1; int mode = 0; if (op) { - memset (op, 0, sizeof (RAsmOp)); + memset (op, 0, sizeof (RzAsmOp)); op->size = 4; } if (cd != 0) { @@ -45,7 +45,7 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) } n = cs_disasm (cd, buf, len, a->pc, 1, &insn); if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; ret = -1; goto beach; @@ -57,9 +57,9 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) } op->size = insn->size; char *buf_asm = sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str); - r_str_replace_char (buf_asm, '%', 0); - r_str_case (buf_asm, false); - r_asm_op_set_asm (op, buf_asm); + rz_str_replace_char (buf_asm, '%', 0); + rz_str_case (buf_asm, false); + rz_asm_op_set_asm (op, buf_asm); cs_free (insn, n); beach: // cs_close (&cd); @@ -72,24 +72,24 @@ static int tms320c64x_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) static tms320_dasm_t engine = { 0 }; -static int tms320_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { - if (a->cpu && r_str_casecmp (a->cpu, "c54x") == 0) { +static int tms320_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { + if (a->cpu && rz_str_casecmp (a->cpu, "c54x") == 0) { tms320_f_set_cpu (&engine, TMS320_F_CPU_C54X); - } else if (a->cpu && r_str_casecmp(a->cpu, "c55x+") == 0) { + } else if (a->cpu && rz_str_casecmp(a->cpu, "c55x+") == 0) { tms320_f_set_cpu (&engine, TMS320_F_CPU_C55X_PLUS); - } else if (a->cpu && r_str_casecmp(a->cpu, "c55x") == 0) { + } else if (a->cpu && rz_str_casecmp(a->cpu, "c55x") == 0) { tms320_f_set_cpu (&engine, TMS320_F_CPU_C55X); } else { #if CAPSTONE_HAS_TMS320C64X - if (a->cpu && !r_str_casecmp (a->cpu, "c64x")) { + if (a->cpu && !rz_str_casecmp (a->cpu, "c64x")) { return tms320c64x_disassemble (a, op, buf, len); } #endif - r_asm_op_set_asm (op, "unknown asm.cpu"); + rz_asm_op_set_asm (op, "unknown asm.cpu"); return op->size = -1; } op->size = tms320_dasm (&engine, buf, len); - r_asm_op_set_asm (op, engine.syntax); + rz_asm_op_set_asm (op, engine.syntax); return op->size; } @@ -101,7 +101,7 @@ static bool tms320_fini(void * user) { return tms320_dasm_fini (&engine); } -RAsmPlugin r_asm_plugin_tms320 = { +RzAsmPlugin rz_asm_plugin_tms320 = { .name = "tms320", .arch = "tms320", #if CAPSTONE_HAS_TMS320C64X @@ -120,9 +120,9 @@ RAsmPlugin r_asm_plugin_tms320 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_tms320, + .data = &rz_asm_plugin_tms320, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_tms320c64x.c b/librz/asm/p/asm_tms320c64x.c similarity index 71% rename from libr/asm/p/asm_tms320c64x.c rename to librz/asm/p/asm_tms320c64x.c index 7dd67c1578..f29afacb81 100644 --- a/libr/asm/p/asm_tms320c64x.c +++ b/librz/asm/p/asm_tms320c64x.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017-2018 - pancake */ +/* rizin - LGPL - Copyright 2017-2018 - pancake */ -#include -#include +#include +#include #include static csh cd = 0; #include "cs_mnemonics.c" @@ -15,12 +15,12 @@ static csh cd = 0; #if CAPSTONE_HAS_TMS320C64X -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { cs_insn* insn; int n = -1, ret = -1; int mode = 0; if (op) { - memset (op, 0, sizeof (RAsmOp)); + memset (op, 0, sizeof (RzAsmOp)); op->size = 4; } if (cd != 0) { @@ -36,7 +36,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } n = cs_disasm (cd, buf, len, a->pc, 1, &insn); if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; ret = -1; goto beach; @@ -47,11 +47,11 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { goto beach; } op->size = insn->size; - r_asm_op_set_asm (op, sdb_fmt ("%s%s%s", + rz_asm_op_set_asm (op, sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str)); - r_str_replace_char (r_strbuf_get (&op->buf_asm), '%', 0); - r_str_case (r_strbuf_get (&op->buf_asm), false); + rz_str_replace_char (rz_strbuf_get (&op->buf_asm), '%', 0); + rz_str_case (rz_strbuf_get (&op->buf_asm), false); cs_free (insn, n); beach: // cs_close (&cd); @@ -59,7 +59,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return ret; } -RAsmPlugin r_asm_plugin_tms320c64x = { +RzAsmPlugin rz_asm_plugin_tms320c64x = { .name = "tms320c64x", .desc = "Capstone TMS320c64x disassembler", .license = "BSD", @@ -72,7 +72,7 @@ RAsmPlugin r_asm_plugin_tms320c64x = { #else -RAsmPlugin r_asm_plugin_tms320c64x = { +RzAsmPlugin rz_asm_plugin_tms320c64x = { .name = "tms320c64x", .desc = "Capstone TMS320c64x disassembler (unsupported)", .license = "BSD", @@ -85,9 +85,9 @@ RAsmPlugin r_asm_plugin_tms320c64x = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_tms320c64x, + .data = &rz_asm_plugin_tms320c64x, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_tricore.c b/librz/asm/p/asm_tricore.c similarity index 88% rename from libr/asm/p/asm_tricore.c rename to librz/asm/p/asm_tricore.c index 2a13e243bb..de2795149b 100644 --- a/libr/asm/p/asm_tricore.c +++ b/librz/asm/p/asm_tricore.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2016 - pancake */ +/* rizin - LGPL - Copyright 2016 - pancake */ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -68,7 +68,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; buf_global = &op->buf_asm; Offset = a->pc; @@ -91,12 +91,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_tricore ((bfd_vma)Offset, &disasm_obj); if (op->size == -1) { - r_asm_op_set_asm (op, " (data)"); + rz_asm_op_set_asm (op, " (data)"); } return op->size; } -RAsmPlugin r_asm_plugin_tricore = { +RzAsmPlugin rz_asm_plugin_tricore = { .name = "tricore", .arch = "tricore", .license = "GPL3", @@ -107,9 +107,9 @@ RAsmPlugin r_asm_plugin_tricore = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_tricore, + .data = &rz_asm_plugin_tricore, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_v810.c b/librz/asm/p/asm_v810.c similarity index 65% rename from libr/asm/p/asm_v810.c rename to librz/asm/p/asm_v810.c index ca9700133c..6c0c13e537 100644 --- a/libr/asm/p/asm_v810.c +++ b/librz/asm/p/asm_v810.c @@ -2,13 +2,13 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../arch/v810/v810_disas.h" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct v810_cmd cmd = { .instr = "", .operands = "" @@ -18,12 +18,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } int ret = v810_decode_command (buf, len, &cmd); if (ret > 0) { - r_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); + rz_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); } return op->size = ret; } -RAsmPlugin r_asm_plugin_v810 = { +RzAsmPlugin rz_asm_plugin_v810 = { .name = "v810", .license = "LGPL3", .desc = "v810 disassembly plugin", @@ -35,9 +35,9 @@ RAsmPlugin r_asm_plugin_v810 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_v810, + .data = &rz_asm_plugin_v810, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_v850.c b/librz/asm/p/asm_v850.c similarity index 65% rename from libr/asm/p/asm_v850.c rename to librz/asm/p/asm_v850.c index 6d94c846bf..a7159cf39c 100644 --- a/libr/asm/p/asm_v850.c +++ b/librz/asm/p/asm_v850.c @@ -2,13 +2,13 @@ #include #include -#include -#include -#include +#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct v850_cmd cmd = { .addr = a->pc, .instr = "", @@ -19,12 +19,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } int ret = v850_decode_command (buf, len, &cmd); if (ret > 0) { - r_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); + rz_asm_op_set_asm (op, sdb_fmt ("%s %s", cmd.instr, cmd.operands)); } return op->size = ret; } -RAsmPlugin r_asm_plugin_v850 = { +RzAsmPlugin rz_asm_plugin_v850 = { .name = "v850", .license = "LGPL3", .desc = "v850 disassembly plugin", @@ -35,9 +35,9 @@ RAsmPlugin r_asm_plugin_v850 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_v850, + .data = &rz_asm_plugin_v850, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_vax.c b/librz/asm/p/asm_vax.c similarity index 86% rename from libr/asm/p/asm_vax.c rename to librz/asm/p/asm_vax.c index c7b51d2f25..7956d48e1c 100644 --- a/libr/asm/p/asm_vax.c +++ b/librz/asm/p/asm_vax.c @@ -6,10 +6,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" #include "../arch/vax/vax.h" @@ -42,7 +42,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; if (len < 4) { return -1; @@ -65,12 +65,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_vax ((bfd_vma)Offset, &disasm_obj); if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_vax = { +RzAsmPlugin rz_asm_plugin_vax = { .name = "vax", .arch = "vax", .license = "GPL", @@ -81,9 +81,9 @@ RAsmPlugin r_asm_plugin_vax = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_vax, + .data = &rz_asm_plugin_vax, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_wasm.c b/librz/asm/p/asm_wasm.c similarity index 64% rename from libr/asm/p/asm_wasm.c rename to librz/asm/p/asm_wasm.c index ad65cd6d82..7961907f57 100644 --- a/libr/asm/p/asm_wasm.c +++ b/librz/asm/p/asm_wasm.c @@ -4,28 +4,28 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../arch/wasm/wasm.h" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { WasmOp wop = {{0}}; int ret = wasm_dis (&wop, buf, len); - r_asm_op_set_asm (op, wop.txt); + rz_asm_op_set_asm (op, wop.txt); free (wop.txt); op->size = ret; return op->size; } -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { - ut8 *opbuf = (ut8*)r_strbuf_get (&op->buf); +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { + ut8 *opbuf = (ut8*)rz_strbuf_get (&op->buf); op->size = wasm_asm (buf, opbuf, 32); // XXX hardcoded opsize return op->size; } -RAsmPlugin r_asm_plugin_wasm = { +RzAsmPlugin rz_asm_plugin_wasm = { .name = "wasm", .author = "cgvwzq", .version = "0.1.0", @@ -39,9 +39,9 @@ RAsmPlugin r_asm_plugin_wasm = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_wasm, + .data = &rz_asm_plugin_wasm, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_ws.c b/librz/asm/p/asm_ws.c similarity index 60% rename from libr/asm/p/asm_ws.c rename to librz/asm/p/asm_ws.c index 069e8a9f2c..44d16cabae 100644 --- a/libr/asm/p/asm_ws.c +++ b/librz/asm/p/asm_ws.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2014 - condret */ -#include -#include -#include -#include +#include +#include +#include +#include #define WS_API static #include "../arch/whitespace/wsdis.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { return wsdis (op, buf, len); } -RAsmPlugin r_asm_plugin_ws = { +RzAsmPlugin rz_asm_plugin_ws = { .name = "ws", .desc = "Whitespace esotheric VM", .arch = "whitespace", @@ -22,9 +22,9 @@ RAsmPlugin r_asm_plugin_ws = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_ws, + .data = &rz_asm_plugin_ws, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_x86_as.c b/librz/asm/p/asm_x86_as.c similarity index 72% rename from libr/asm/p/asm_x86_as.c rename to librz/asm/p/asm_x86_as.c index 76c7cccbcf..857d7899e7 100644 --- a/libr/asm/p/asm_x86_as.c +++ b/librz/asm/p/asm_x86_as.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2011-2020 pancake */ -#include -#include +#include +#include -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { char *ipath, *opath; const char *syntaxstr = ""; int len = 0; - int ifd = r_file_mkstemp ("r_as", &ipath); + int ifd = rz_file_mkstemp ("rz_as", &ipath); if (ifd == -1) { return -1; } - int ofd = r_file_mkstemp ("r_as", &opath); + int ofd = rz_file_mkstemp ("rz_as", &opath); if (ofd == -1) { free (ipath); close (ifd); @@ -29,7 +29,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { break; } - char *asm_buf = r_str_newf ( + char *asm_buf = rz_str_newf ( "%s.code%i\n" //.org 0x%"PFMT64x"\n" ".ascii \"BEGINMARK\"\n" "%s\n" @@ -47,7 +47,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { #else const char *x86as = ""; #endif - char *user_ass = r_sys_getenv ("R2_X86AS"); + char *user_ass = rz_sys_getenv ("R2_X86AS"); if (user_ass) { x86as = user_ass; } @@ -55,13 +55,13 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { eprintf ("Please set R2_X86AS env to define an x86 assembler program"); return 1; } - bool res = r_sys_cmdf ("%s %s -o %s", x86as, ipath, opath); + bool res = rz_sys_cmdf ("%s %s -o %s", x86as, ipath, opath); free (user_ass); if (!res) { const ut8 *begin, *end; close (ofd); -// r_sys_cmdf ("cat %s", opath); - ofd = r_sandbox_open (opath, O_BINARY | O_RDONLY, 0644); +// rz_sys_cmdf ("cat %s", opath); + ofd = rz_sandbox_open (opath, O_BINARY | O_RDONLY, 0644); if (ofd < 0) { free (ipath); free (opath); @@ -69,15 +69,15 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { } ut8 opbuf[512] = {0}; len = read (ofd, opbuf, sizeof (opbuf)); - begin = r_mem_mem (opbuf, len, (const ut8*)"BEGINMARK", 9); - end = r_mem_mem (opbuf, len, (const ut8*)"ENDMARK", 7); + begin = rz_mem_mem (opbuf, len, (const ut8*)"BEGINMARK", 9); + end = rz_mem_mem (opbuf, len, (const ut8*)"ENDMARK", 7); if (!begin || !end) { eprintf ("Cannot find water marks\n"); len = 0; } else { len = (int)(size_t)(end - begin - 9); if (len > 0) { - r_asm_op_set_buf (op, begin + 9, len); + rz_asm_op_set_buf (op, begin + 9, len); } else { len = 0; } @@ -98,7 +98,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { return len; } -RAsmPlugin r_asm_plugin_x86_as = { +RzAsmPlugin rz_asm_plugin_x86_as = { .name = "x86.as", .desc = "Intel X86 GNU Assembler (Use R2_X86AS env)", .arch = "x86", @@ -110,9 +110,9 @@ RAsmPlugin r_asm_plugin_x86_as = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_x86_as, + .data = &rz_asm_plugin_x86_as, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_x86_cs.c b/librz/asm/p/asm_x86_cs.c similarity index 85% rename from libr/asm/p/asm_x86_cs.c rename to librz/asm/p/asm_x86_cs.c index 53d9a5aa0d..f30f2a1cbf 100644 --- a/libr/asm/p/asm_x86_cs.c +++ b/librz/asm/p/asm_x86_cs.c @@ -1,17 +1,17 @@ -/* radare2 - LGPL - Copyright 2013-2019 - pancake */ +/* rizin - LGPL - Copyright 2013-2019 - pancake */ -#include -#include +#include +#include #include -#define USE_ITER_API 0 +#define USE_ITERZ_API 0 static csh cd = 0; static int n = 0; static bool the_end(void *p) { #if 0 -#if !USE_ITER_API +#if !USE_ITERZ_API if (insn) { cs_free (insn, n); insn = NULL; @@ -25,13 +25,13 @@ static bool the_end(void *p) { return true; } -static int check_features(RAsm *a, cs_insn *insn); +static int check_features(RzAsm *a, cs_insn *insn); #include "cs_mnemonics.c" #include "asm_x86_vm.c" -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { static int omode = 0; int mode, ret; ut64 off = a->pc; @@ -77,7 +77,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } op->size = 1; cs_insn *insn = NULL; -#if USE_ITER_API +#if USE_ITERZ_API { size_t size = len; if (!insn || cd < 1) { @@ -100,7 +100,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (a->features && *a->features) { if (!check_features (a, insn)) { op->size = insn->size; - r_asm_op_set_asm (op, "illegal"); + rz_asm_op_set_asm (op, "illegal"); } } if (op->size == 0 && n > 0 && insn->size > 0) { @@ -113,12 +113,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { if (ptrstr) { memmove (ptrstr, ptrstr + 4, strlen (ptrstr + 4) + 1); } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); } else { decompile_vm (a, op, buf, len); } if (a->syntax == R_ASM_SYNTAX_JZ) { - char *buf_asm = r_strbuf_get (&op->buf_asm); + char *buf_asm = rz_strbuf_get (&op->buf_asm); if (!strncmp (buf_asm, "je ", 3)) { memcpy (buf_asm, "jz", 2); } else if (!strncmp (buf_asm, "jne ", 4)) { @@ -145,7 +145,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { } } #endif -#if USE_ITER_API +#if USE_ITERZ_API /* do nothing because it should be allocated once and freed in the_end */ #else if (insn) { @@ -155,7 +155,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return op->size; } -RAsmPlugin r_asm_plugin_x86_cs = { +RzAsmPlugin rz_asm_plugin_x86_cs = { .name = "x86", .desc = "Capstone X86 disassembler", .license = "BSD", @@ -170,7 +170,7 @@ RAsmPlugin r_asm_plugin_x86_cs = { "sse3,sse41,sse42,sse4a,ssse3,pclmul,xop" }; -static int check_features(RAsm *a, cs_insn *insn) { +static int check_features(RzAsm *a, cs_insn *insn) { const char *name; int i; if (!insn || !insn->detail) { @@ -199,11 +199,11 @@ static int check_features(RAsm *a, cs_insn *insn) { } #ifndef R2_PLUGIN_INCORE -R_API RLibStruct *radare_plugin_function(void) { - RLibStruct *rp = R_NEW0 (RLibStruct); +RZ_API RzLibStruct *radare_plugin_function(void) { + RzLibStruct *rp = R_NEW0 (RzLibStruct); if (rp) { rp->type = R_LIB_TYPE_ASM; - rp->data = &r_asm_plugin_x86_cs; + rp->data = &rz_asm_plugin_x86_cs; rp->version = R2_VERSION; } return rp; diff --git a/libr/asm/p/asm_x86_nasm.c b/librz/asm/p/asm_x86_nasm.c similarity index 65% rename from libr/asm/p/asm_x86_nasm.c rename to librz/asm/p/asm_x86_nasm.c index 34cae455c9..774ce15501 100644 --- a/libr/asm/p/asm_x86_nasm.c +++ b/librz/asm/p/asm_x86_nasm.c @@ -1,27 +1,27 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include -static int assemble(RAsm *a, RAsmOp *op, const char *buf) { +static int assemble(RzAsm *a, RzAsmOp *op, const char *buf) { char *ipath, *opath; if (a->syntax != R_ASM_SYNTAX_INTEL) { eprintf ("asm.x86.nasm does not support non-intel syntax\n"); return -1; } - int ifd = r_file_mkstemp ("r_nasm", &ipath); + int ifd = rz_file_mkstemp ("rz_nasm", &ipath); if (ifd == -1) { return -1; } - int ofd = r_file_mkstemp ("r_nasm", &opath); + int ofd = rz_file_mkstemp ("rz_nasm", &opath); if (ofd == -1) { free (ipath); return -1; } - char *asm_buf = r_str_newf ("[BITS %i]\nORG 0x%"PFMT64x"\n%s\n", a->bits, a->pc, buf); + char *asm_buf = rz_str_newf ("[BITS %i]\nORG 0x%"PFMT64x"\n%s\n", a->bits, a->pc, buf); if (asm_buf) { (void)write (ifd, asm_buf, strlen (asm_buf)); free (asm_buf); @@ -29,10 +29,10 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { close (ifd); - if (!r_sys_cmdf ("nasm %s -o %s", ipath, opath)) { + if (!rz_sys_cmdf ("nasm %s -o %s", ipath, opath)) { ut8 buf[512]; // TODO: remove limits op->size = read (ofd, buf, sizeof (buf)); - r_asm_op_set_buf (op, buf, op->size); + rz_asm_op_set_buf (op, buf, op->size); } else { eprintf ("Error running 'nasm'\n"); } @@ -46,7 +46,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) { return op->size; } -RAsmPlugin r_asm_plugin_x86_nasm = { +RzAsmPlugin rz_asm_plugin_x86_nasm = { .name = "x86.nasm", .desc = "X86 nasm assembler", .license = "LGPL3", @@ -58,9 +58,9 @@ RAsmPlugin r_asm_plugin_x86_nasm = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_x86_nasm, + .data = &rz_asm_plugin_x86_nasm, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_x86_nz.c b/librz/asm/p/asm_x86_nz.c similarity index 93% rename from libr/asm/p/asm_x86_nz.c rename to librz/asm/p/asm_x86_nz.c index 464619bf1d..20188c5254 100644 --- a/libr/asm/p/asm_x86_nz.c +++ b/librz/asm/p/asm_x86_nz.c @@ -1,14 +1,14 @@ /* Copyright (C) 2008-2020 - pancake, unlogic, emvivre */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -static ut64 getnum(RAsm *a, const char *s); +static ut64 getnum(RzAsm *a, const char *s); #define ENCODING_SHIFT 0 #define OPTYPE_SHIFT 6 @@ -157,9 +157,9 @@ static int is_al_reg(const Operand *op) { return 0; } -static int oprep(RAsm *a, ut8 *data, const Opcode *op); +static int oprep(RzAsm *a, ut8 *data, const Opcode *op); -static int process_16bit_group_1(RAsm *a, ut8 *data, const Opcode *op, int op1) { +static int process_16bit_group_1(RzAsm *a, ut8 *data, const Opcode *op, int op1) { is_valid_registers (op); int l = 0; int immediate = op->operands[1].immediate * op->operands[1].sign; @@ -184,7 +184,7 @@ static int process_16bit_group_1(RAsm *a, ut8 *data, const Opcode *op, int op1) return l; } -static int process_group_1(RAsm *a, ut8 *data, const Opcode *op) { +static int process_group_1(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int modrm = 0; @@ -279,7 +279,7 @@ static int process_group_1(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int process_group_2(RAsm *a, ut8 *data, const Opcode *op) { +static int process_group_2(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int modrm = 0; @@ -351,7 +351,7 @@ static int process_group_2(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int process_1byte_op(RAsm *a, ut8 *data, const Opcode *op, int op1) { +static int process_1byte_op(RzAsm *a, ut8 *data, const Opcode *op, int op1) { is_valid_registers (op); int l = 0; int mod_byte = 0; @@ -498,7 +498,7 @@ static int process_1byte_op(RAsm *a, ut8 *data, const Opcode *op, int op1) { return l; } -static int opadc(RAsm *a, ut8 *data, const Opcode *op) { +static int opadc(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -511,7 +511,7 @@ static int opadc(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x10); } -static int opadd(RAsm *a, ut8 *data, const Opcode *op) { +static int opadd(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -524,7 +524,7 @@ static int opadd(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x00); } -static int opand(RAsm *a, ut8 *data, const Opcode *op) { +static int opand(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -537,7 +537,7 @@ static int opand(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x20); } -static int opcmp(RAsm *a, ut8 *data, const Opcode *op) { +static int opcmp(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -550,7 +550,7 @@ static int opcmp(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x38); } -static int opsub(RAsm *a, ut8 *data, const Opcode *op) { +static int opsub(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -563,7 +563,7 @@ static int opsub(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x28); } -static int opor(RAsm *a, ut8 * data, const Opcode *op) { +static int opor(RzAsm *a, ut8 * data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -576,7 +576,7 @@ static int opor(RAsm *a, ut8 * data, const Opcode *op) { return process_1byte_op (a, data, op, 0x08); } -static int opxadd(RAsm *a, ut8 *data, const Opcode *op) { +static int opxadd(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int i = 0; if (op->operands_count < 2 ) { @@ -601,7 +601,7 @@ static int opxadd(RAsm *a, ut8 *data, const Opcode *op) { return i; } -static int opxor(RAsm *a, ut8 * data, const Opcode *op) { +static int opxor(RzAsm *a, ut8 * data, const Opcode *op) { is_valid_registers (op); if (op->operands_count < 2) { return -1; @@ -624,7 +624,7 @@ static int opxor(RAsm *a, ut8 * data, const Opcode *op) { return process_1byte_op (a, data, op, 0x30); } -static int opneg(RAsm *a, ut8 * data, const Opcode *op) { +static int opneg(RzAsm *a, ut8 * data, const Opcode *op) { is_valid_registers (op); int l = 0; @@ -646,17 +646,17 @@ static int opneg(RAsm *a, ut8 * data, const Opcode *op) { return -1; } -static int endbr64(RAsm *a, ut8 * data, const Opcode *op) { +static int endbr64(RzAsm *a, ut8 * data, const Opcode *op) { memcpy (data, "\xf3\x0f\x1e\xfa", 4); return 4; } -static int endbr32(RAsm *a, ut8 * data, const Opcode *op) { +static int endbr32(RzAsm *a, ut8 * data, const Opcode *op) { memcpy (data, "\xf3\x0f\x1e\xfb", 4); return 4; } -static int opnot(RAsm *a, ut8 * data, const Opcode *op) { +static int opnot(RzAsm *a, ut8 * data, const Opcode *op) { is_valid_registers (op); int l = 0; @@ -689,7 +689,7 @@ static int opnot(RAsm *a, ut8 * data, const Opcode *op) { return l; } -static int opsbb(RAsm *a, ut8 *data, const Opcode *op) { +static int opsbb(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type & OT_CONSTANT) { if (op->operands[0].type & OT_GPREG && op->operands[0].type & OT_WORD) { @@ -702,7 +702,7 @@ static int opsbb(RAsm *a, ut8 *data, const Opcode *op) { return process_1byte_op (a, data, op, 0x18); } -static int opbs(RAsm *a, ut8 *data, const Opcode *op) { +static int opbs(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; if (a->bits >= 32 && op->operands[1].type & OT_MEMORY && op->operands[1].reg_size & OT_WORD) { return -1; @@ -743,7 +743,7 @@ static int opbs(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opbswap(RAsm *a, ut8 *data, const Opcode *op) { +static int opbswap(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; if (op->operands[0].type & OT_REGALL) { is_valid_registers (op); @@ -772,7 +772,7 @@ static int opbswap(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opcall(RAsm *a, ut8 *data, const Opcode *op) { +static int opcall(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int immediate = 0; @@ -823,7 +823,7 @@ static int opcall(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opcmov(RAsm *a, ut8 *data, const Opcode *op) { +static int opcmov(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int mod_byte = 0; @@ -953,7 +953,7 @@ static int opcmov(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opmovx(RAsm *a, ut8 *data, const Opcode *op) { +static int opmovx(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int word = 0; @@ -980,7 +980,7 @@ static int opmovx(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opaam(RAsm *a, ut8 *data, const Opcode *op) { +static int opaam(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int immediate = op->operands[0].immediate * op->operands[0].sign; @@ -993,7 +993,7 @@ static int opaam(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opdec(RAsm *a, ut8 *data, const Opcode *op) { +static int opdec(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type) { eprintf ("Error: Invalid operands\n"); return -1; @@ -1140,7 +1140,7 @@ static int opdec(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opidiv(RAsm *a, ut8 *data, const Opcode *op) { +static int opidiv(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; @@ -1169,7 +1169,7 @@ static int opidiv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opdiv(RAsm *a, ut8 *data, const Opcode *op) { +static int opdiv(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; @@ -1198,7 +1198,7 @@ static int opdiv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opimul(RAsm *a, ut8 *data, const Opcode *op) { +static int opimul(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int offset = 0; @@ -1338,7 +1338,7 @@ static int opimul(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opin(RAsm *a, ut8 *data, const Opcode *op) { +static int opin(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; st32 immediate = 0; @@ -1380,7 +1380,7 @@ static int opin(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opclflush(RAsm *a, ut8 *data, const Opcode *op) { +static int opclflush(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int offset = 0; @@ -1410,7 +1410,7 @@ static int opclflush(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opinc(RAsm *a, ut8 *data, const Opcode *op) { +static int opinc(RzAsm *a, ut8 *data, const Opcode *op) { if (op->operands[1].type) { eprintf ("Error: Invalid operands\n"); return -1; @@ -1556,7 +1556,7 @@ static int opinc(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opint(RAsm *a, ut8 *data, const Opcode *op) { +static int opint(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; if (op->operands[0].type & OT_CONSTANT) { st32 immediate = op->operands[0].immediate * op->operands[0].sign; @@ -1568,7 +1568,7 @@ static int opint(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opjc(RAsm *a, ut8 *data, const Opcode *op) { +static int opjc(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; bool is_short = op->is_short; @@ -1697,7 +1697,7 @@ static int opjc(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oplea(RAsm *a, ut8 *data, const Opcode *op){ +static int oplea(RzAsm *a, ut8 *data, const Opcode *op){ int l = 0; int mod = 0; st32 offset = 0; @@ -1763,7 +1763,7 @@ static int oplea(RAsm *a, ut8 *data, const Opcode *op){ return l; } -static int oples(RAsm *a, ut8* data, const Opcode *op) { +static int oples(RzAsm *a, ut8* data, const Opcode *op) { int l = 0; int offset = 0; int mod = 0; @@ -1799,7 +1799,7 @@ static int oples(RAsm *a, ut8* data, const Opcode *op) { return l; } -static int opmov(RAsm *a, ut8 *data, const Opcode *op) { +static int opmov(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; st64 offset = 0; int mod = 0; @@ -2308,7 +2308,7 @@ static int opmov(RAsm *a, ut8 *data, const Opcode *op) { } // Only for MOV r64, imm64 -static int opmovabs(RAsm *a, ut8 *data, const Opcode *op) { +static int opmovabs(RzAsm *a, ut8 *data, const Opcode *op) { if (!(a->bits == 64 && (op->operands[0].type & OT_GPREG) && !(op->operands[0].type & OT_MEMORY) && (op->operands[0].type & OT_QWORD) && (op->operands[1].type & OT_CONSTANT))) { return -1; @@ -2329,7 +2329,7 @@ static int opmovabs(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opmul(RAsm *a, ut8 *data, const Opcode *op) { +static int opmul(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; @@ -2358,7 +2358,7 @@ static int opmul(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oppop(RAsm *a, ut8 *data, const Opcode *op) { +static int oppop(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int offset = 0; @@ -2412,7 +2412,7 @@ static int oppop(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oppush(RAsm *a, ut8 *data, const Opcode *op) { +static int oppush(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int mod = 0; @@ -2481,7 +2481,7 @@ static int oppush(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opout(RAsm *a, ut8 *data, const Opcode *op) { +static int opout(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; st32 immediate = 0; @@ -2521,7 +2521,7 @@ static int opout(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oploop(RAsm *a, ut8 *data, const Opcode *op) { +static int oploop(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; data[l++] = 0xe2; @@ -2530,7 +2530,7 @@ static int oploop(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opret(RAsm *a, ut8 *data, const Opcode *op) { +static int opret(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; int immediate = 0; if (a->bits == 16) { @@ -2548,7 +2548,7 @@ static int opret(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opretf(RAsm *a, ut8 *data, const Opcode *op) { +static int opretf(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; st32 immediate = 0; if (op->operands[0].type & OT_CONSTANT) { @@ -2562,7 +2562,7 @@ static int opretf(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opstos(RAsm *a, ut8 *data, const Opcode *op) { +static int opstos(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; if (!strcmp(op->mnemonic, "stosw")) { @@ -2578,7 +2578,7 @@ static int opstos(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opset(RAsm *a, ut8 *data, const Opcode *op) { +static int opset(RzAsm *a, ut8 *data, const Opcode *op) { if (!(op->operands[0].type & (OT_GPREG | OT_BYTE))) {return -1;} int l = 0; int mod = 0; @@ -2642,7 +2642,7 @@ static int opset(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int optest(RAsm *a, ut8 *data, const Opcode *op) { +static int optest(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; if (!op->operands[0].type || !op->operands[1].type) { @@ -2708,7 +2708,7 @@ static int optest(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opxchg(RAsm *a, ut8 *data, const Opcode *op) { +static int opxchg(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; int mod_byte = 0; @@ -2808,7 +2808,7 @@ static int opxchg(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opcdqe(RAsm *a, ut8 *data, const Opcode *op) { +static int opcdqe(RzAsm *a, ut8 *data, const Opcode *op) { is_valid_registers (op); int l = 0; if (a->bits == 64) { @@ -2818,7 +2818,7 @@ static int opcdqe(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfcmov(RAsm *a, ut8 *data, const Opcode *op) { +static int opfcmov(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; char* fcmov = op->mnemonic + strlen("fcmov"); switch (op->operands_count) { @@ -2862,7 +2862,7 @@ static int opfcmov(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opffree(RAsm *a, ut8 *data, const Opcode *op) { +static int opffree(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -2879,7 +2879,7 @@ static int opffree(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfrstor(RAsm *a, ut8 *data, const Opcode *op) { +static int opfrstor(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -2896,7 +2896,7 @@ static int opfrstor(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfxch(RAsm *a, ut8 *data, const Opcode *op) { +static int opfxch(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -2917,7 +2917,7 @@ static int opfxch(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfucom(RAsm *a, ut8 *data, const Opcode *op) { +static int opfucom(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -2938,7 +2938,7 @@ static int opfucom(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfucomp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfucomp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -2959,7 +2959,7 @@ static int opfucomp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfaddp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfaddp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 2: @@ -2981,7 +2981,7 @@ static int opfaddp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfiadd(RAsm *a, ut8 *data, const Opcode *op) { +static int opfiadd(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3005,7 +3005,7 @@ static int opfiadd(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfadd(RAsm *a, ut8 *data, const Opcode *op) { +static int opfadd(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3042,7 +3042,7 @@ static int opfadd(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opficom(RAsm *a, ut8 *data, const Opcode *op) { +static int opficom(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3066,7 +3066,7 @@ static int opficom(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opficomp(RAsm *a, ut8 *data, const Opcode *op) { +static int opficomp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3090,7 +3090,7 @@ static int opficomp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfild(RAsm *a, ut8 *data, const Opcode *op) { +static int opfild(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3117,7 +3117,7 @@ static int opfild(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfldcw(RAsm *a, ut8 *data, const Opcode *op) { +static int opfldcw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3135,7 +3135,7 @@ static int opfldcw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfldenv(RAsm *a, ut8 *data, const Opcode *op) { +static int opfldenv(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3152,7 +3152,7 @@ static int opfldenv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfbld(RAsm *a, ut8 *data, const Opcode *op) { +static int opfbld(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3170,7 +3170,7 @@ static int opfbld(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfbstp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfbstp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3188,7 +3188,7 @@ static int opfbstp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfxrstor(RAsm *a, ut8 *data, const Opcode *op) { +static int opfxrstor(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3206,7 +3206,7 @@ static int opfxrstor(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfxsave(RAsm *a, ut8 *data, const Opcode *op) { +static int opfxsave(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3224,7 +3224,7 @@ static int opfxsave(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfist(RAsm *a, ut8 *data, const Opcode *op) { +static int opfist(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3248,7 +3248,7 @@ static int opfist(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfistp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfistp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3275,7 +3275,7 @@ static int opfistp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfisttp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfisttp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3302,7 +3302,7 @@ static int opfisttp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfstenv(RAsm *a, ut8 *data, const Opcode *op) { +static int opfstenv(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3320,7 +3320,7 @@ static int opfstenv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfnstenv(RAsm *a, ut8 *data, const Opcode *op) { +static int opfnstenv(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3337,7 +3337,7 @@ static int opfnstenv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfdiv(RAsm *a, ut8 *data, const Opcode *op) { +static int opfdiv(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3374,7 +3374,7 @@ static int opfdiv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfdivp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfdivp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -3396,7 +3396,7 @@ static int opfdivp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfidiv(RAsm *a, ut8 *data, const Opcode *op) { +static int opfidiv(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3420,7 +3420,7 @@ static int opfidiv(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfdivr(RAsm *a, ut8 *data, const Opcode *op) { +static int opfdivr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3457,7 +3457,7 @@ static int opfdivr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfdivrp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfdivrp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -3479,7 +3479,7 @@ static int opfdivrp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfidivr(RAsm *a, ut8 *data, const Opcode *op) { +static int opfidivr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3503,7 +3503,7 @@ static int opfidivr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfmul(RAsm *a, ut8 *data, const Opcode *op) { +static int opfmul(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3540,7 +3540,7 @@ static int opfmul(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfmulp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfmulp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -3562,7 +3562,7 @@ static int opfmulp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfimul(RAsm *a, ut8 *data, const Opcode *op) { +static int opfimul(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3586,7 +3586,7 @@ static int opfimul(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfsub(RAsm *a, ut8 *data, const Opcode *op) { +static int opfsub(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3623,7 +3623,7 @@ static int opfsub(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfsubp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfsubp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -3645,7 +3645,7 @@ static int opfsubp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfisub(RAsm *a, ut8 *data, const Opcode *op) { +static int opfisub(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3669,7 +3669,7 @@ static int opfisub(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfsubr(RAsm *a, ut8 *data, const Opcode *op) { +static int opfsubr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3706,7 +3706,7 @@ static int opfsubr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfsubrp(RAsm *a, ut8 *data, const Opcode *op) { +static int opfsubrp(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 0: @@ -3728,7 +3728,7 @@ static int opfsubrp(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfisubr(RAsm *a, ut8 *data, const Opcode *op) { +static int opfisubr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3752,7 +3752,7 @@ static int opfisubr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfnstcw(RAsm *a, ut8 *data, const Opcode *op) { +static int opfnstcw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3770,7 +3770,7 @@ static int opfnstcw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfstcw(RAsm *a, ut8 *data, const Opcode *op) { +static int opfstcw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3789,7 +3789,7 @@ static int opfstcw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfnstsw(RAsm *a, ut8 *data, const Opcode *op) { +static int opfnstsw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3812,7 +3812,7 @@ static int opfnstsw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfstsw(RAsm *a, ut8 *data, const Opcode *op) { +static int opfstsw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3837,7 +3837,7 @@ static int opfstsw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfnsave(RAsm *a, ut8 *data, const Opcode *op) { +static int opfnsave(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3855,7 +3855,7 @@ static int opfnsave(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opfsave(RAsm *a, ut8 *data, const Opcode *op) { +static int opfsave(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3874,7 +3874,7 @@ static int opfsave(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oplldt(RAsm *a, ut8 *data, const Opcode *op) { +static int oplldt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3896,7 +3896,7 @@ static int oplldt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oplmsw(RAsm *a, ut8 *data, const Opcode *op) { +static int oplmsw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3918,7 +3918,7 @@ static int oplmsw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oplgdt(RAsm *a, ut8 *data, const Opcode *op) { +static int oplgdt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3936,7 +3936,7 @@ static int oplgdt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int oplidt(RAsm *a, ut8 *data, const Opcode *op) { +static int oplidt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3954,7 +3954,7 @@ static int oplidt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opsgdt(RAsm *a, ut8 *data, const Opcode *op) { +static int opsgdt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3972,7 +3972,7 @@ static int opsgdt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opstmxcsr(RAsm *a, ut8 *data, const Opcode *op) { +static int opstmxcsr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -3991,7 +3991,7 @@ static int opstmxcsr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opstr(RAsm *a, ut8 *data, const Opcode *op) { +static int opstr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4015,7 +4015,7 @@ static int opstr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opsidt(RAsm *a, ut8 *data, const Opcode *op) { +static int opsidt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4033,7 +4033,7 @@ static int opsidt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opsldt(RAsm *a, ut8 *data, const Opcode *op) { +static int opsldt(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4054,7 +4054,7 @@ static int opsldt(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opsmsw(RAsm *a, ut8 *data, const Opcode *op) { +static int opsmsw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4075,7 +4075,7 @@ static int opsmsw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opverr(RAsm *a, ut8 *data, const Opcode *op) { +static int opverr(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4097,7 +4097,7 @@ static int opverr(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opverw(RAsm *a, ut8 *data, const Opcode *op) { +static int opverw(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4119,7 +4119,7 @@ static int opverw(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opvmclear(RAsm *a, ut8 *data, const Opcode *op) { +static int opvmclear(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4140,7 +4140,7 @@ static int opvmclear(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opvmon(RAsm *a, ut8 *data, const Opcode *op) { +static int opvmon(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4161,7 +4161,7 @@ static int opvmon(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opvmptrld(RAsm *a, ut8 *data, const Opcode *op) { +static int opvmptrld(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4181,7 +4181,7 @@ static int opvmptrld(RAsm *a, ut8 *data, const Opcode *op) { return l; } -static int opvmptrst(RAsm *a, ut8 *data, const Opcode *op) { +static int opvmptrst(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; switch (op->operands_count) { case 1: @@ -4204,7 +4204,7 @@ static int opvmptrst(RAsm *a, ut8 *data, const Opcode *op) { typedef struct lookup_t { char mnemonic[12]; int only_x32; - int (*opdo)(RAsm*, ut8*, const Opcode*); + int (*opdo)(RzAsm*, ut8*, const Opcode*); ut64 opcode; int size; } LookupTable; @@ -4600,7 +4600,7 @@ static x86newTokenType getToken(const char *str, size_t *begin, size_t *end) { static bool is_xmm_register(const char *token) { // check xmm0..xmm15 - if (!r_str_ncasecmp ("xmm", token, 3)) { + if (!rz_str_ncasecmp ("xmm", token, 3)) { int n = atoi (token + 3); return (n >= 0 && n <= 15); } @@ -4608,7 +4608,7 @@ static bool is_xmm_register(const char *token) { } static bool is_mm_register(const char *token) { - if (!r_str_ncasecmp ("mm", token, 2)) { + if (!rz_str_ncasecmp ("mm", token, 2)) { const bool parn = token[2] == '('; if (parn) { token++; @@ -4629,7 +4629,7 @@ static bool is_mm_register(const char *token) { } static bool is_st_register(const char *token) { - if (!r_str_ncasecmp ("st", token, 2)) { + if (!rz_str_ncasecmp ("st", token, 2)) { const bool parn = token[2] == '('; if (parn) { token++; @@ -4652,7 +4652,7 @@ static bool is_st_register(const char *token) { /** * Get the register at position pos in str. Increase pos afterwards. */ -static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { +static Register parseReg(RzAsm *a, const char *str, size_t *pos, ut32 *type) { int i; // Must be the same order as in enum register_t const char *regs[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", NULL }; @@ -4676,7 +4676,7 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { // General purpose registers if (length == 3 && token[0] == 'e') { for (i = 0; regs[i]; i++) { - if (!r_str_ncasecmp (regs[i], token, length)) { + if (!rz_str_ncasecmp (regs[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_DWORD; return i; } @@ -4685,7 +4685,7 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { // Control registers if (length == 3 && token[0] == 'c') { for (i = 0; cregs[i]; i++) { - if (!r_str_ncasecmp (cregs[i], token, length)) { + if (!rz_str_ncasecmp (cregs[i], token, length)) { *type = (OT_CONTROLREG & OT_REG (i)) | OT_DWORD; return i; } @@ -4694,7 +4694,7 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { // Debug registers if (length == 3 && token[0] == 'd') { for (i = 0; cregs[i]; i++) { - if (!r_str_ncasecmp (dregs[i], token, length)) { + if (!rz_str_ncasecmp (dregs[i], token, length)) { *type = (OT_DEBUGREG & OT_REG (i)) | OT_DWORD; return i; } @@ -4703,21 +4703,21 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { if (length == 2) { if (token[1] == 'l' || token[1] == 'h') { for (i = 0; regs8[i]; i++) { - if (!r_str_ncasecmp (regs8[i], token, length)) { + if (!rz_str_ncasecmp (regs8[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_BYTE; return i; } } } for (i = 0; regs16[i]; i++) { - if (!r_str_ncasecmp (regs16[i], token, length)) { + if (!rz_str_ncasecmp (regs16[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_WORD; return i; } } // This isn't working properly yet for (i = 0; sregs[i]; i++) { - if (!r_str_ncasecmp (sregs[i], token, length)) { + if (!rz_str_ncasecmp (sregs[i], token, length)) { *type = (OT_SEGMENTREG & OT_REG (i)) | OT_WORD; return i; } @@ -4725,21 +4725,21 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { } if (token[0] == 'r') { for (i = 0; regs64[i]; i++) { - if (!r_str_ncasecmp (regs64[i], token, length)) { + if (!rz_str_ncasecmp (regs64[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_QWORD; a->bits = 64; return i; } } for (i = 0; regs64ext[i]; i++) { - if (!r_str_ncasecmp (regs64ext[i], token, length)) { + if (!rz_str_ncasecmp (regs64ext[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_QWORD; a->bits = 64; return i + 9; } } for (i = 0; regsext[i]; i++) { - if (!r_str_ncasecmp (regsext[i], token, length)) { + if (!rz_str_ncasecmp (regsext[i], token, length)) { *type = (OT_GPREG & OT_REG (i)) | OT_DWORD; if (a->bits < 32) { a->bits = 32; @@ -4792,7 +4792,7 @@ static Register parseReg(RAsm *a, const char *str, size_t *pos, ut32 *type) { return X86R_UNDEFINED; } -static void parse_segment_offset(RAsm *a, const char *str, size_t *pos, +static void parse_segment_offset(RzAsm *a, const char *str, size_t *pos, Operand *op, int reg_index) { int nextpos = *pos; char *c = strchr (str + nextpos, ':'); @@ -4815,7 +4815,7 @@ static void parse_segment_offset(RAsm *a, const char *str, size_t *pos, } } // Parse operand -static int parseOperand(RAsm *a, const char *str, Operand *op, bool isrepop) { +static int parseOperand(RzAsm *a, const char *str, Operand *op, bool isrepop) { size_t pos, nextpos = 0; x86newTokenType last_type; int size_token = 1; @@ -4829,29 +4829,29 @@ static int parseOperand(RAsm *a, const char *str, Operand *op, bool isrepop) { last_type = getToken (str, &pos, &nextpos); // Token may indicate size: then skip - if (!r_str_ncasecmp (str + pos, "ptr", 3)) { + if (!rz_str_ncasecmp (str + pos, "ptr", 3)) { continue; - } else if (!r_str_ncasecmp (str + pos, "byte", 4)) { + } else if (!rz_str_ncasecmp (str + pos, "byte", 4)) { op->type |= OT_MEMORY | OT_BYTE; op->dest_size = OT_BYTE; explicit_size = true; - } else if (!r_str_ncasecmp (str + pos, "word", 4)) { + } else if (!rz_str_ncasecmp (str + pos, "word", 4)) { op->type |= OT_MEMORY | OT_WORD; op->dest_size = OT_WORD; explicit_size = true; - } else if (!r_str_ncasecmp (str + pos, "dword", 5)) { + } else if (!rz_str_ncasecmp (str + pos, "dword", 5)) { op->type |= OT_MEMORY | OT_DWORD; op->dest_size = OT_DWORD; explicit_size = true; - } else if (!r_str_ncasecmp (str + pos, "qword", 5)) { + } else if (!rz_str_ncasecmp (str + pos, "qword", 5)) { op->type |= OT_MEMORY | OT_QWORD; op->dest_size = OT_QWORD; explicit_size = true; - } else if (!r_str_ncasecmp (str + pos, "oword", 5)) { + } else if (!rz_str_ncasecmp (str + pos, "oword", 5)) { op->type |= OT_MEMORY | OT_OWORD; op->dest_size = OT_OWORD; explicit_size = true; - } else if (!r_str_ncasecmp (str + pos, "tbyte", 5)) { + } else if (!rz_str_ncasecmp (str + pos, "tbyte", 5)) { op->type |= OT_MEMORY | OT_TBYTE; op->dest_size = OT_TBYTE; explicit_size = true; @@ -4981,7 +4981,7 @@ static int parseOperand(RAsm *a, const char *str, Operand *op, bool isrepop) { } } else if (last_type == TT_WORD) { // register nextpos = pos; - RFlagItem *flag; + RzFlagItem *flag; if (isrepop) { op->is_good_flag = false; @@ -5007,8 +5007,8 @@ static int parseOperand(RAsm *a, const char *str, Operand *op, bool isrepop) { return nextpos; } op->type = OT_CONSTANT; - RCore *core = a->num? (RCore *)(a->num->userptr): NULL; - if (core && (flag = r_flag_get (core->flags, str))) { + RzCore *core = a->num? (RzCore *)(a->num->userptr): NULL; + if (core && (flag = rz_flag_get (core->flags, str))) { op->is_good_flag = true; } @@ -5037,7 +5037,7 @@ static int parseOperand(RAsm *a, const char *str, Operand *op, bool isrepop) { return nextpos; } -static int parseOpcode(RAsm *a, const char *op, Opcode *out) { +static int parseOpcode(RzAsm *a, const char *op, Opcode *out) { out->has_bnd = false; bool isrepop = false; if (!strncmp (op, "bnd ", 4)) { @@ -5045,7 +5045,7 @@ static int parseOpcode(RAsm *a, const char *op, Opcode *out) { op += 4; } char *args = strchr (op, ' '); - out->mnemonic = args ? r_str_ndup (op, args - op) : strdup (op); + out->mnemonic = args ? rz_str_ndup (op, args - op) : strdup (op); out->operands[0].type = out->operands[1].type = 0; out->operands[0].extended = out->operands[1].extended = false; out->operands[0].reg = out->operands[0].regs[0] = out->operands[0].regs[1] = X86R_UNDEFINED; @@ -5060,7 +5060,7 @@ static int parseOpcode(RAsm *a, const char *op, Opcode *out) { } else { return 1; } - if (!r_str_ncasecmp (args, "short", 5)) { + if (!rz_str_ncasecmp (args, "short", 5)) { out->is_short = true; args += 5; } @@ -5081,17 +5081,17 @@ static int parseOpcode(RAsm *a, const char *op, Opcode *out) { return 0; } -static ut64 getnum(RAsm *a, const char *s) { +static ut64 getnum(RzAsm *a, const char *s) { if (!s) { return 0; } if (*s == '$') { s++; } - return r_num_math (a->num, s); + return rz_num_math (a->num, s); } -static int oprep(RAsm *a, ut8 *data, const Opcode *op) { +static int oprep(RzAsm *a, ut8 *data, const Opcode *op) { int l = 0; LookupTable *lt_ptr; int retval; @@ -5107,7 +5107,7 @@ static int oprep(RAsm *a, ut8 *data, const Opcode *op) { parseOpcode (a, op->operands[0].rep_op, &instr); for (lt_ptr = oplookup; strcmp (lt_ptr->mnemonic, "null"); lt_ptr++) { - if (!r_str_casecmp (instr.mnemonic, lt_ptr->mnemonic)) { + if (!rz_str_casecmp (instr.mnemonic, lt_ptr->mnemonic)) { if (lt_ptr->opcode > 0) { if (lt_ptr->only_x32 && a->bits == 64) { free (instr.mnemonic); @@ -5143,7 +5143,7 @@ static int oprep(RAsm *a, ut8 *data, const Opcode *op) { return -1; } -static int assemble(RAsm *a, RAsmOp *ao, const char *str) { +static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) { ut8 __data[32] = {0}; ut8 *data = __data; char op[128]; @@ -5155,7 +5155,7 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) { op[sizeof (op) - 1] = '\0'; parseOpcode (a, op, &instr); for (lt_ptr = oplookup; strcmp (lt_ptr->mnemonic, "null"); lt_ptr++) { - if (!r_str_casecmp (instr.mnemonic, lt_ptr->mnemonic)) { + if (!rz_str_casecmp (instr.mnemonic, lt_ptr->mnemonic)) { if (lt_ptr->opcode > 0) { if (!lt_ptr->only_x32 || a->bits != 64) { ut8 *ptr = (ut8 *)<_ptr->opcode; @@ -5183,13 +5183,13 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) { } } if (retval > 0) { - r_asm_op_set_buf (ao, __data, retval); + rz_asm_op_set_buf (ao, __data, retval); } free (instr.mnemonic); return retval; } -RAsmPlugin r_asm_plugin_x86_nz = { +RzAsmPlugin rz_asm_plugin_x86_nz = { .name = "x86.nz", .desc = "x86 handmade assembler", .license = "LGPL3", @@ -5200,9 +5200,9 @@ RAsmPlugin r_asm_plugin_x86_nz = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_x86_nz, + .data = &rz_asm_plugin_x86_nz, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_x86_vm.c b/librz/asm/p/asm_x86_vm.c similarity index 96% rename from libr/asm/p/asm_x86_vm.c rename to librz/asm/p/asm_x86_vm.c index e163ea8c51..1396c7fc01 100644 --- a/libr/asm/p/asm_x86_vm.c +++ b/librz/asm/p/asm_x86_vm.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2018 - wargio */ +/* rizin - LGPL - Copyright 2018 - wargio */ /* "Missing" vm ops: @@ -27,7 +27,7 @@ #define VPCEXT2(y,x) ((y)[2]==(x)) -void decompile_vm(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +void decompile_vm(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { const char *buf_asm = "invalid"; if (len > 3 && buf[0] == 0x0F && buf[1] == 0x3F && (VPCEXT2 (buf, 0x01) || VPCEXT2 (buf, 0x05) || VPCEXT2 (buf, 0x07) || VPCEXT2 (buf, 0x0D) || VPCEXT2 (buf, 0x10))) { if (a->syntax == R_ASM_SYNTAX_ATT) { @@ -105,7 +105,7 @@ void decompile_vm(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { buf_asm ="vmsdte"; op->size = 5; } - r_asm_op_set_asm (op, buf_asm); + rz_asm_op_set_asm (op, buf_asm); } #undef VPCEXT2 diff --git a/libr/asm/p/asm_xap.c b/librz/asm/p/asm_xap.c similarity index 73% rename from libr/asm/p/asm_xap.c rename to librz/asm/p/asm_xap.c index 57bb650859..09d30d6501 100644 --- a/libr/asm/p/asm_xap.c +++ b/librz/asm/p/asm_xap.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2014 - nibble */ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "xap/dis.c" static int arch_xap_disasm(char *str, const unsigned char *buf, ut64 seek) { @@ -30,13 +30,13 @@ static int arch_xap_disasm(char *str, const unsigned char *buf, ut64 seek) { #endif return 0; } -static int disassemble(RAsm *a, struct r_asm_op_t *op, const ut8 *buf, int len) { - char *buf_asm = r_strbuf_get (&op->buf_asm); +static int disassemble(RzAsm *a, struct rz_asm_op_t *op, const ut8 *buf, int len) { + char *buf_asm = rz_strbuf_get (&op->buf_asm); arch_xap_disasm (buf_asm, buf, a->pc); return (op->size = 2); } -RAsmPlugin r_asm_plugin_xap = { +RzAsmPlugin rz_asm_plugin_xap = { .name = "xap", .arch = "xap", .license = "PD", @@ -47,9 +47,9 @@ RAsmPlugin r_asm_plugin_xap = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_xap, + .data = &rz_asm_plugin_xap, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_xcore_cs.c b/librz/asm/p/asm_xcore_cs.c similarity index 71% rename from libr/asm/p/asm_xcore_cs.c rename to librz/asm/p/asm_xcore_cs.c index 16db528a44..5e272938c9 100644 --- a/libr/asm/p/asm_xcore_cs.c +++ b/librz/asm/p/asm_xcore_cs.c @@ -1,15 +1,15 @@ -/* radare2 - LGPL - Copyright 2014-2018 - pancake */ +/* rizin - LGPL - Copyright 2014-2018 - pancake */ -#include -#include +#include +#include #include -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { csh handle; cs_insn* insn; int mode, n, ret = -1; mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN; - memset (op, 0, sizeof (RAsmOp)); + memset (op, 0, sizeof (RzAsmOp)); op->size = 4; ret = cs_open (CS_ARCH_XCORE, mode, &handle); if (ret) { @@ -18,7 +18,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF); n = cs_disasm (handle, (ut8*)buf, len, a->pc, 1, &insn); if (n < 1) { - r_asm_op_set_asm (op, "invalid"); + rz_asm_op_set_asm (op, "invalid"); op->size = 4; ret = -1; goto beach; @@ -28,7 +28,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { goto beach; } op->size = insn->size; - r_asm_op_set_asm (op, sdb_fmt ("%s%s%s", + rz_asm_op_set_asm (op, sdb_fmt ("%s%s%s", insn->mnemonic, insn->op_str[0]? " ": "", insn->op_str)); // TODO: remove the '$' in the string @@ -39,7 +39,7 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { return ret; } -RAsmPlugin r_asm_plugin_xcore_cs = { +RzAsmPlugin rz_asm_plugin_xcore_cs = { .name = "xcore", .desc = "Capstone XCore disassembler", .license = "BSD", @@ -51,9 +51,9 @@ RAsmPlugin r_asm_plugin_xcore_cs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_xcore_cs, + .data = &rz_asm_plugin_xcore_cs, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_xtensa.c b/librz/asm/p/asm_xtensa.c similarity index 83% rename from libr/asm/p/asm_xtensa.c rename to librz/asm/p/asm_xtensa.c index 13698609a0..007fdc986d 100644 --- a/libr/asm/p/asm_xtensa.c +++ b/librz/asm/p/asm_xtensa.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2016-2018 - pancake */ +/* rizin - LGPL - Copyright 2016-2018 - pancake */ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "disas-asm.h" @@ -36,7 +36,7 @@ static void memory_error_func(int status, bfd_vma memaddr, struct disassemble_in DECLARE_GENERIC_PRINT_ADDRESS_FUNC() DECLARE_GENERIC_FPRINTF_FUNC() -static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { struct disassemble_info disasm_obj; buf_global = &op->buf_asm; offset = a->pc; @@ -60,12 +60,12 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { op->size = print_insn_xtensa ((bfd_vma)offset, &disasm_obj); if (op->size == -1) { - r_asm_op_set_asm (op, "(data)"); + rz_asm_op_set_asm (op, "(data)"); } return op->size; } -RAsmPlugin r_asm_plugin_xtensa = { +RzAsmPlugin rz_asm_plugin_xtensa = { .name = "xtensa", .arch = "xtensa", .license = "GPL3", @@ -76,9 +76,9 @@ RAsmPlugin r_asm_plugin_xtensa = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_xtensa, + .data = &rz_asm_plugin_xtensa, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/asm_z80.c b/librz/asm/p/asm_z80.c similarity index 53% rename from libr/asm/p/asm_z80.c rename to librz/asm/p/asm_z80.c index 4e5fa1f4a8..19fd0e07ce 100644 --- a/libr/asm/p/asm_z80.c +++ b/librz/asm/p/asm_z80.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2012-2018 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../arch/z80/z80.c" #include "../arch/z80/z80asm.c" -static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) { +static int do_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { return op->size = z80Disass (op, buf, len); } -static int do_assemble(RAsm *a, RAsmOp *op, const char *buf) { - return op->size = z80asm ((ut8*)r_strbuf_get (&op->buf), buf); +static int do_assemble(RzAsm *a, RzAsmOp *op, const char *buf) { + return op->size = z80asm ((ut8*)rz_strbuf_get (&op->buf), buf); } -RAsmPlugin r_asm_plugin_z80 = { +RzAsmPlugin rz_asm_plugin_z80 = { .name = "z80", .desc = "Zilog Z80", .license = "GPL", @@ -29,9 +29,9 @@ RAsmPlugin r_asm_plugin_z80 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_ASM, - .data = &r_asm_plugin_z80, + .data = &rz_asm_plugin_z80, .version = R2_VERSION }; #endif diff --git a/libr/asm/p/avr.mk b/librz/asm/p/avr.mk similarity index 100% rename from libr/asm/p/avr.mk rename to librz/asm/p/avr.mk diff --git a/libr/asm/p/bf.mk b/librz/asm/p/bf.mk similarity index 100% rename from libr/asm/p/bf.mk rename to librz/asm/p/bf.mk diff --git a/libr/asm/p/capstone.mk b/librz/asm/p/capstone.mk similarity index 100% rename from libr/asm/p/capstone.mk rename to librz/asm/p/capstone.mk diff --git a/libr/asm/p/chip8.mk b/librz/asm/p/chip8.mk similarity index 100% rename from libr/asm/p/chip8.mk rename to librz/asm/p/chip8.mk diff --git a/libr/asm/p/cr16.mk b/librz/asm/p/cr16.mk similarity index 100% rename from libr/asm/p/cr16.mk rename to librz/asm/p/cr16.mk diff --git a/libr/asm/p/cris_gnu.mk b/librz/asm/p/cris_gnu.mk similarity index 100% rename from libr/asm/p/cris_gnu.mk rename to librz/asm/p/cris_gnu.mk diff --git a/libr/asm/p/cs_mnemonics.c b/librz/asm/p/cs_mnemonics.c similarity index 50% rename from libr/asm/p/cs_mnemonics.c rename to librz/asm/p/cs_mnemonics.c index 0becb5221b..76e1f59523 100644 --- a/libr/asm/p/cs_mnemonics.c +++ b/librz/asm/p/cs_mnemonics.c @@ -1,16 +1,16 @@ -static char *mnemonics(RAsm *a, int id, bool json) { +static char *mnemonics(RzAsm *a, int id, bool json) { int i; a->cur->disassemble (a, NULL, NULL, -1); if (id != -1) { const char *name = cs_insn_name (cd, id); if (json) { - return name? r_str_newf ("[\"%s\"]\n", name): NULL; + return name? rz_str_newf ("[\"%s\"]\n", name): NULL; } return name? strdup (name): NULL; } - RStrBuf *buf = r_strbuf_new (""); + RStrBuf *buf = rz_strbuf_new (""); if (json) { - r_strbuf_append (buf, "["); + rz_strbuf_append (buf, "["); } for (i = 1; ; i++) { const char *op = cs_insn_name (cd, i); @@ -18,18 +18,18 @@ static char *mnemonics(RAsm *a, int id, bool json) { break; } if (json) { - r_strbuf_append (buf, "\""); + rz_strbuf_append (buf, "\""); } - r_strbuf_append (buf, op); + rz_strbuf_append (buf, op); if (json) { if (cs_insn_name (cd, i + 1)) { - r_strbuf_append (buf, "\","); + rz_strbuf_append (buf, "\","); } else { - r_strbuf_append (buf, "\"]\n"); + rz_strbuf_append (buf, "\"]\n"); } } else { - r_strbuf_append (buf, "\n"); + rz_strbuf_append (buf, "\n"); } } - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } diff --git a/libr/asm/p/dalvik.mk b/librz/asm/p/dalvik.mk similarity index 100% rename from libr/asm/p/dalvik.mk rename to librz/asm/p/dalvik.mk diff --git a/libr/asm/p/dcpu16.mk b/librz/asm/p/dcpu16.mk similarity index 100% rename from libr/asm/p/dcpu16.mk rename to librz/asm/p/dcpu16.mk diff --git a/libr/asm/p/ebc.mk b/librz/asm/p/ebc.mk similarity index 100% rename from libr/asm/p/ebc.mk rename to librz/asm/p/ebc.mk diff --git a/libr/asm/p/gas.mk b/librz/asm/p/gas.mk similarity index 100% rename from libr/asm/p/gas.mk rename to librz/asm/p/gas.mk diff --git a/libr/asm/p/gb.mk b/librz/asm/p/gb.mk similarity index 100% rename from libr/asm/p/gb.mk rename to librz/asm/p/gb.mk diff --git a/libr/asm/p/h8300.mk b/librz/asm/p/h8300.mk similarity index 100% rename from libr/asm/p/h8300.mk rename to librz/asm/p/h8300.mk diff --git a/libr/asm/p/hexagon.mk b/librz/asm/p/hexagon.mk similarity index 100% rename from libr/asm/p/hexagon.mk rename to librz/asm/p/hexagon.mk diff --git a/libr/asm/p/hppa_gnu.mk b/librz/asm/p/hppa_gnu.mk similarity index 100% rename from libr/asm/p/hppa_gnu.mk rename to librz/asm/p/hppa_gnu.mk diff --git a/libr/asm/p/i4004.mk b/librz/asm/p/i4004.mk similarity index 100% rename from libr/asm/p/i4004.mk rename to librz/asm/p/i4004.mk diff --git a/libr/asm/p/i8080.mk b/librz/asm/p/i8080.mk similarity index 100% rename from libr/asm/p/i8080.mk rename to librz/asm/p/i8080.mk diff --git a/libr/asm/p/java.mk b/librz/asm/p/java.mk similarity index 91% rename from libr/asm/p/java.mk rename to librz/asm/p/java.mk index 3a1411a50d..0db235c0c5 100644 --- a/libr/asm/p/java.mk +++ b/librz/asm/p/java.mk @@ -12,6 +12,6 @@ ALL_TARGETS+=${TARGET_JAVA} ${TARGET_JAVA}: ${OBJ_JAVA} ${SHARED2_JAVA} ${CC} $(call libname,asm_java) ${LDFLAGS} ${CFLAGS} \ -o asm_java.${EXT_SO} ${OBJ_JAVA} ${SHARED2_JAVA} \ - $(SHLR)/java/libr_java.$(EXT_AR) \ + $(SHLR)/java/librz_java.$(EXT_AR) \ $(SHLR)/sdb/src/libsdb.$(EXT_AR) endif diff --git a/libr/asm/p/lanai_gnu.mk b/librz/asm/p/lanai_gnu.mk similarity index 100% rename from libr/asm/p/lanai_gnu.mk rename to librz/asm/p/lanai_gnu.mk diff --git a/libr/asm/p/lh5801.mk b/librz/asm/p/lh5801.mk similarity index 100% rename from libr/asm/p/lh5801.mk rename to librz/asm/p/lh5801.mk diff --git a/libr/asm/p/lm32.mk b/librz/asm/p/lm32.mk similarity index 100% rename from libr/asm/p/lm32.mk rename to librz/asm/p/lm32.mk diff --git a/libr/asm/p/m680x_cs.mk b/librz/asm/p/m680x_cs.mk similarity index 100% rename from libr/asm/p/m680x_cs.mk rename to librz/asm/p/m680x_cs.mk diff --git a/libr/asm/p/m68k_cs.mk b/librz/asm/p/m68k_cs.mk similarity index 100% rename from libr/asm/p/m68k_cs.mk rename to librz/asm/p/m68k_cs.mk diff --git a/libr/asm/p/malbolge.mk b/librz/asm/p/malbolge.mk similarity index 100% rename from libr/asm/p/malbolge.mk rename to librz/asm/p/malbolge.mk diff --git a/libr/asm/p/mcore.mk b/librz/asm/p/mcore.mk similarity index 100% rename from libr/asm/p/mcore.mk rename to librz/asm/p/mcore.mk diff --git a/libr/asm/p/mcs96.mk b/librz/asm/p/mcs96.mk similarity index 100% rename from libr/asm/p/mcs96.mk rename to librz/asm/p/mcs96.mk diff --git a/libr/asm/p/mips_cs.mk b/librz/asm/p/mips_cs.mk similarity index 100% rename from libr/asm/p/mips_cs.mk rename to librz/asm/p/mips_cs.mk diff --git a/libr/asm/p/mips_gnu.mk b/librz/asm/p/mips_gnu.mk similarity index 100% rename from libr/asm/p/mips_gnu.mk rename to librz/asm/p/mips_gnu.mk diff --git a/libr/asm/p/msp430.mk b/librz/asm/p/msp430.mk similarity index 100% rename from libr/asm/p/msp430.mk rename to librz/asm/p/msp430.mk diff --git a/libr/asm/p/nios2.mk b/librz/asm/p/nios2.mk similarity index 100% rename from libr/asm/p/nios2.mk rename to librz/asm/p/nios2.mk diff --git a/libr/asm/p/null.mk b/librz/asm/p/null.mk similarity index 100% rename from libr/asm/p/null.mk rename to librz/asm/p/null.mk diff --git a/libr/asm/p/or1k.mk b/librz/asm/p/or1k.mk similarity index 100% rename from libr/asm/p/or1k.mk rename to librz/asm/p/or1k.mk diff --git a/libr/asm/p/pic.mk b/librz/asm/p/pic.mk similarity index 100% rename from libr/asm/p/pic.mk rename to librz/asm/p/pic.mk diff --git a/libr/asm/p/ppc_cs.mk b/librz/asm/p/ppc_cs.mk similarity index 100% rename from libr/asm/p/ppc_cs.mk rename to librz/asm/p/ppc_cs.mk diff --git a/libr/asm/p/ppc_gnu.mk b/librz/asm/p/ppc_gnu.mk similarity index 100% rename from libr/asm/p/ppc_gnu.mk rename to librz/asm/p/ppc_gnu.mk diff --git a/libr/asm/p/propeller.mk b/librz/asm/p/propeller.mk similarity index 100% rename from libr/asm/p/propeller.mk rename to librz/asm/p/propeller.mk diff --git a/libr/asm/p/pyc.mk b/librz/asm/p/pyc.mk similarity index 94% rename from libr/asm/p/pyc.mk rename to librz/asm/p/pyc.mk index 6caf9af4c9..2f1a16b24c 100644 --- a/libr/asm/p/pyc.mk +++ b/librz/asm/p/pyc.mk @@ -39,5 +39,5 @@ ALL_TARGETS+=${TARGET_PYC} CFLAGS+=-I$(PYC_ROOT) ${TARGET_PYC}: ${OBJ_PYC} - ${CC} ${CFLAGS} $(LDFLAGS) -o ${TARGET_PYC} ${OBJ_PYC} -lr_util + ${CC} ${CFLAGS} $(LDFLAGS) -o ${TARGET_PYC} ${OBJ_PYC} -lrz_util diff --git a/libr/asm/p/riscv.mk b/librz/asm/p/riscv.mk similarity index 100% rename from libr/asm/p/riscv.mk rename to librz/asm/p/riscv.mk diff --git a/libr/asm/p/riscv_cs.mk b/librz/asm/p/riscv_cs.mk similarity index 100% rename from libr/asm/p/riscv_cs.mk rename to librz/asm/p/riscv_cs.mk diff --git a/libr/asm/p/rsp.mk b/librz/asm/p/rsp.mk similarity index 100% rename from libr/asm/p/rsp.mk rename to librz/asm/p/rsp.mk diff --git a/libr/asm/p/sh.mk b/librz/asm/p/sh.mk similarity index 100% rename from libr/asm/p/sh.mk rename to librz/asm/p/sh.mk diff --git a/libr/asm/p/snes.mk b/librz/asm/p/snes.mk similarity index 100% rename from libr/asm/p/snes.mk rename to librz/asm/p/snes.mk diff --git a/libr/asm/p/sparc_cs.mk b/librz/asm/p/sparc_cs.mk similarity index 100% rename from libr/asm/p/sparc_cs.mk rename to librz/asm/p/sparc_cs.mk diff --git a/libr/asm/p/sparc_gnu.mk b/librz/asm/p/sparc_gnu.mk similarity index 100% rename from libr/asm/p/sparc_gnu.mk rename to librz/asm/p/sparc_gnu.mk diff --git a/libr/asm/p/spc700.mk b/librz/asm/p/spc700.mk similarity index 100% rename from libr/asm/p/spc700.mk rename to librz/asm/p/spc700.mk diff --git a/libr/asm/p/sysz.mk b/librz/asm/p/sysz.mk similarity index 100% rename from libr/asm/p/sysz.mk rename to librz/asm/p/sysz.mk diff --git a/libr/asm/p/tms320.mk b/librz/asm/p/tms320.mk similarity index 100% rename from libr/asm/p/tms320.mk rename to librz/asm/p/tms320.mk diff --git a/libr/asm/p/tricore.mk b/librz/asm/p/tricore.mk similarity index 100% rename from libr/asm/p/tricore.mk rename to librz/asm/p/tricore.mk diff --git a/libr/asm/p/v810.mk b/librz/asm/p/v810.mk similarity index 100% rename from libr/asm/p/v810.mk rename to librz/asm/p/v810.mk diff --git a/libr/asm/p/v850.mk b/librz/asm/p/v850.mk similarity index 100% rename from libr/asm/p/v850.mk rename to librz/asm/p/v850.mk diff --git a/libr/asm/p/vax.mk b/librz/asm/p/vax.mk similarity index 100% rename from libr/asm/p/vax.mk rename to librz/asm/p/vax.mk diff --git a/libr/asm/p/wasm.mk b/librz/asm/p/wasm.mk similarity index 100% rename from libr/asm/p/wasm.mk rename to librz/asm/p/wasm.mk diff --git a/libr/asm/p/ws.mk b/librz/asm/p/ws.mk similarity index 100% rename from libr/asm/p/ws.mk rename to librz/asm/p/ws.mk diff --git a/libr/asm/p/x86_as.mk b/librz/asm/p/x86_as.mk similarity index 100% rename from libr/asm/p/x86_as.mk rename to librz/asm/p/x86_as.mk diff --git a/libr/asm/p/x86_cs.mk b/librz/asm/p/x86_cs.mk similarity index 100% rename from libr/asm/p/x86_cs.mk rename to librz/asm/p/x86_cs.mk diff --git a/libr/asm/p/x86_nasm.mk b/librz/asm/p/x86_nasm.mk similarity index 100% rename from libr/asm/p/x86_nasm.mk rename to librz/asm/p/x86_nasm.mk diff --git a/libr/asm/p/x86_nz.mk b/librz/asm/p/x86_nz.mk similarity index 100% rename from libr/asm/p/x86_nz.mk rename to librz/asm/p/x86_nz.mk diff --git a/libr/asm/p/xap.mk b/librz/asm/p/xap.mk similarity index 100% rename from libr/asm/p/xap.mk rename to librz/asm/p/xap.mk diff --git a/libr/asm/p/xcore_cs.mk b/librz/asm/p/xcore_cs.mk similarity index 100% rename from libr/asm/p/xcore_cs.mk rename to librz/asm/p/xcore_cs.mk diff --git a/libr/asm/p/xtensa.mk b/librz/asm/p/xtensa.mk similarity index 100% rename from libr/asm/p/xtensa.mk rename to librz/asm/p/xtensa.mk diff --git a/libr/asm/p/z80.mk b/librz/asm/p/z80.mk similarity index 100% rename from libr/asm/p/z80.mk rename to librz/asm/p/z80.mk diff --git a/libr/bin/Makefile b/librz/bin/Makefile similarity index 89% rename from libr/bin/Makefile rename to librz/bin/Makefile index d88a333cfe..a15ad0f5eb 100644 --- a/libr/bin/Makefile +++ b/librz/bin/Makefile @@ -1,8 +1,8 @@ include ../config.mk include ../../global.mk -NAME=r_bin -R2DEPS=r_util r_io r_socket r_magic r_hash r_syscall r_cons +NAME=rz_bin +R2DEPS=rz_util rz_io rz_socket rz_magic rz_hash rz_syscall rz_cons .PHONY: pre @@ -32,4 +32,4 @@ OBJS+=mangling/rust.o OBJS+=pdb/pdb_downloader.o pdb/omap.o pdb/stream_pe.o pdb/gdata.o OBJS+=pdb/fpo.o pdb/dbi.o pdb/tpi.o pdb/stream_file.o pdb/pdb.o -include $(TOP)/libr/rules.mk +include $(TOP)/librz/rules.mk diff --git a/libr/bin/bfile.c b/librz/bin/bfile.c similarity index 63% rename from libr/bin/bfile.c rename to librz/bin/bfile.c index 01627e7865..182627ca68 100644 --- a/libr/bin/bfile.c +++ b/librz/bin/bfile.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2009-2019 - pancake, nibble, dso */ +/* rizin - LGPL - Copyright 2009-2019 - pancake, nibble, dso */ -#include -#include +#include +#include #include "i/private.h" // maybe too big sometimes? 2KB of stack eaten here.. @@ -9,17 +9,17 @@ #define R_STRING_MAX_UNI_BLOCKS 4 static RBinClass *__getClass(RBinFile *bf, const char *name) { - r_return_val_if_fail (bf && bf->o && bf->o->classes_ht && name, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->classes_ht && name, NULL); return ht_pp_find (bf->o->classes_ht, name, NULL); } static RBinSymbol *__getMethod(RBinFile *bf, const char *klass, const char *method) { - r_return_val_if_fail (bf && bf->o && bf->o->methods_ht && klass && method, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->methods_ht && klass && method, NULL); const char *name = sdb_fmt ("%s::%s", klass, method); return ht_pp_find (bf->o->methods_ht, name, NULL); } -static RBinString *__stringAt(RBinFile *bf, RList *ret, ut64 addr) { +static RBinString *__stringAt(RBinFile *bf, RzList *ret, ut64 addr) { if (addr != 0 && addr != UT64_MAX) { return ht_up_find (bf->o->strings_db, addr, NULL); } @@ -31,7 +31,7 @@ static ut64 binobj_a2b(RBinObject *o, ut64 addr) { } static void print_string(RBinFile *bf, RBinString *string, int raw, PJ *pj) { - r_return_if_fail (bf && string); + rz_return_if_fail (bf && string); int mode = bf->strmode; ut64 addr, vaddr; @@ -40,17 +40,17 @@ static void print_string(RBinFile *bf, RBinString *string, int raw, PJ *pj) { return; } const char *section_name, *type_string; - RIO *io = bin->iob.io; + RzIO *io = bin->iob.io; if (!io) { return; } - RBinSection *s = r_bin_get_section_at (bf->o, string->paddr, false); + RBinSection *s = rz_bin_get_section_at (bf->o, string->paddr, false); if (s) { string->vaddr = s->vaddr + (string->paddr - s->paddr); } section_name = s ? s->name : ""; - type_string = r_bin_string_type (string->type); - vaddr = addr = r_bin_get_vaddr (bin, string->paddr, string->vaddr); + type_string = rz_bin_string_type (string->type); + vaddr = addr = rz_bin_get_vaddr (bin, string->paddr, string->vaddr); // If raw string dump mode, use printf to dump directly to stdout. // PrintfCallback temp = io->cb_printf; @@ -84,15 +84,15 @@ static void print_string(RBinFile *bf, RBinString *string, int raw, PJ *pj) { case R_MODE_RADARE: { char *f_name, *nstr; f_name = strdup (string->string); - r_name_filter (f_name, 512); + rz_name_filter (f_name, 512); if (bin->prefix) { - nstr = r_str_newf ("%s.str.%s", bin->prefix, f_name); + nstr = rz_str_newf ("%s.str.%s", bin->prefix, f_name); io->cb_printf ("f %s.str.%s %u @ 0x%08"PFMT64x"\n" "Cs %u @ 0x%08"PFMT64x"\n", bin->prefix, f_name, string->size, addr, string->size, addr); } else { - nstr = r_str_newf ("str.%s", f_name); + nstr = rz_str_newf ("str.%s", f_name); io->cb_printf ("f str.%s %u @ 0x%08"PFMT64x"\n" "Cs %u @ 0x%08"PFMT64x"\n", f_name, string->size, addr, @@ -112,7 +112,7 @@ static void print_string(RBinFile *bf, RBinString *string, int raw, PJ *pj) { } } -static int string_scan_range(RList *list, RBinFile *bf, int min, +static int string_scan_range(RzList *list, RBinFile *bf, int min, const ut64 from, const ut64 to, int type, int raw, RBinSection *section) { RBin *bin = bf->rbin; ut8 tmp[R_STRING_SCAN_BUFFER_SIZE]; @@ -121,7 +121,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, int str_type = R_STRING_TYPE_DETECT; // if list is null it means its gonna dump - r_return_val_if_fail (bf, -1); + rz_return_val_if_fail (bf, -1); if (type == -1) { type = R_STRING_TYPE_DETECT; @@ -149,7 +149,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, pj_a (pj); } } - r_buf_read_at (bf->buf, from, buf, len); + rz_buf_read_at (bf->buf, from, buf, len); // may oobread while (needle < to) { if (bin && bin->consb.is_breaked) { @@ -157,7 +157,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, break; } } - rc = r_utf8_decode (buf + needle - from, to - needle, NULL); + rc = rz_utf8_decode (buf + needle - from, to - needle, NULL); if (!rc) { needle++; continue; @@ -188,17 +188,17 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, RRune r = {0}; if (str_type == R_STRING_TYPE_WIDE32) { - rc = r_utf32le_decode (buf + needle - from, to - needle, &r); + rc = rz_utf32le_decode (buf + needle - from, to - needle, &r); if (rc) { rc = 4; } } else if (str_type == R_STRING_TYPE_WIDE) { - rc = r_utf16le_decode (buf + needle - from, to - needle, &r); + rc = rz_utf16le_decode (buf + needle - from, to - needle, &r); if (rc == 1) { rc = 2; } } else { - rc = r_utf8_decode (buf + needle - from, to - needle, &r); + rc = rz_utf8_decode (buf + needle - from, to - needle, &r); if (rc > 1) { str_type = R_STRING_TYPE_UTF8; } @@ -212,13 +212,13 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, needle += rc; - if (r_isprint (r) && r != '\\') { + if (rz_isprint (r) && r != '\\') { if (str_type == R_STRING_TYPE_WIDE32) { if (r == 0xff) { r = 0; } } - rc = r_utf8_encode (tmp + i, r); + rc = rz_utf8_encode (tmp + i, r); runes++; /* Print the escape code */ } else if (r && r < 0x100 && strchr ("\b\v\f\n\r\t\a\033\\", (char)r)) { @@ -265,7 +265,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, case R_STRING_TYPE_WIDE: case R_STRING_TYPE_WIDE32: num_blocks = 0; - block_list = r_utf_block_list ((const ut8*)tmp, i - 1, + block_list = rz_utf_block_list ((const ut8*)tmp, i - 1, str_type == R_STRING_TYPE_WIDE ? &freq_list : NULL); if (block_list) { for (j = 0; block_list[j] != -1; j++) { @@ -326,7 +326,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, if (section) { s = section; } else if (bf->o) { - s = r_bin_get_section_at (bf->o, str_start, false); + s = rz_bin_get_section_at (bf->o, str_start, false); } if (s) { vdelta = s->vaddr; @@ -335,15 +335,15 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, } bs->paddr = str_start; bs->vaddr = str_start - pdelta + vdelta; - bs->string = r_str_ndup ((const char *)tmp, i); + bs->string = rz_str_ndup ((const char *)tmp, i); if (list) { - r_list_append (list, bs); + rz_list_append (list, bs); if (bf->o) { ht_up_insert (bf->o->strings_db, bs->vaddr, bs); } } else { print_string (bf, bs, raw, pj); - r_bin_string_free (bs); + rz_bin_string_free (bs); } if (from == 0 && to == bf->size) { /* force lookup section at the next one */ @@ -355,7 +355,7 @@ static int string_scan_range(RList *list, RBinFile *bf, int min, free (buf); if (pj) { pj_end (pj); - RIO *io = bin->iob.io; + RzIO *io = bin->iob.io; if (io) { io->cb_printf ("%s\n", pj_string (pj)); } @@ -372,10 +372,10 @@ static bool __isDataSection(RBinFile *a, RBinSection *s) { return strstr (s->name, "_const") != NULL; } -static void get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 from, ut64 to, RBinSection * section) { - r_return_if_fail (bf && bf->buf); +static void get_strings_range(RBinFile *bf, RzList *list, int min, int raw, ut64 from, ut64 to, RBinSection * section) { + rz_return_if_fail (bf && bf->buf); - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); if (!raw && (!plugin || !plugin->info)) { return; @@ -391,8 +391,8 @@ static void get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 return; } if (!bf->rbin->is_debugger) { - if (!to || to > r_buf_size (bf->buf)) { - to = r_buf_size (bf->buf); + if (!to || to > rz_buf_size (bf->buf)) { + to = rz_buf_size (bf->buf); } if (!to) { return; @@ -403,7 +403,7 @@ static void get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 // in case of dump ignore here if (bf->rbin->maxstrbuf && size && size > bf->rbin->maxstrbuf) { if (bf->rbin->verbose) { - eprintf ("WARNING: bin_strings buffer is too big (0x%08" PFMT64x "). Use -zzz or set bin.maxstrbuf (RABIN2_MAXSTRBUF) in r2 (rabin2)\n", + eprintf ("WARNING: bin_strings buffer is too big (0x%08" PFMT64x "). Use -zzz or set bin.maxstrbuf (RABIN2_MAXSTRBUF) in r2 (rz_bin)\n", size); } return; @@ -428,9 +428,9 @@ static void get_strings_range(RBinFile *bf, RList *list, int min, int raw, ut64 string_scan_range (list, bf, min, from, to, type, raw, section); } -R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr) { +R_IPI RBinFile *rz_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr) { ut32 bf_id; - if (!r_id_pool_grab_id (bin->ids->pool, &bf_id)) { + if (!rz_id_pool_grab_id (bin->ids->pool, &bf_id)) { return NULL; } RBinFile *bf = R_NEW0 (RBinFile); @@ -440,10 +440,10 @@ R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int ra bf->file = file ? strdup (file) : NULL; bf->rawstr = rawstr; bf->fd = fd; - bf->curxtr = xtrname ? r_bin_get_xtrplugin_by_name (bin, xtrname) : NULL; + bf->curxtr = xtrname ? rz_bin_get_xtrplugin_by_name (bin, xtrname) : NULL; bf->sdb = sdb; bf->size = file_sz; - bf->xtr_data = r_list_newf ((RListFree)r_bin_xtrdata_free); + bf->xtr_data = rz_list_newf ((RzListFree)rz_bin_xtrdata_free); bf->xtr_obj = NULL; bf->sdb = sdb_new0 (); bf->sdb_addrinfo = sdb_new0 (); //ns (bf->sdb, "addrinfo", 1); @@ -453,31 +453,31 @@ R_IPI RBinFile *r_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int ra } static RBinPlugin *get_plugin_from_buffer(RBin *bin, const char *pluginname, RBuffer *buf) { - RBinPlugin *plugin = bin->force? r_bin_get_binplugin_by_name (bin, bin->force): NULL; + RBinPlugin *plugin = bin->force? rz_bin_get_binplugin_by_name (bin, bin->force): NULL; if (plugin) { return plugin; } - plugin = pluginname? r_bin_get_binplugin_by_name (bin, pluginname): NULL; + plugin = pluginname? rz_bin_get_binplugin_by_name (bin, pluginname): NULL; if (plugin) { return plugin; } - plugin = r_bin_get_binplugin_by_buffer (bin, buf); + plugin = rz_bin_get_binplugin_by_buffer (bin, buf); if (plugin) { return plugin; } - return r_bin_get_binplugin_by_name (bin, "any"); + return rz_bin_get_binplugin_by_name (bin, "any"); } -R_API bool r_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data) { - r_return_val_if_fail (bin && bf && data, false); +RZ_API bool rz_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data) { + rz_return_val_if_fail (bin && bf && data, false); ut64 offset = data->offset; ut64 sz = data->size; RBinPlugin *plugin = get_plugin_from_buffer (bin, NULL, data->buf); - bf->buf = r_buf_ref (data->buf); + bf->buf = rz_buf_ref (data->buf); - RBinObject *o = r_bin_object_new (bf, plugin, baseaddr, loadaddr, offset, sz); + RBinObject *o = rz_bin_object_new (bf, plugin, baseaddr, loadaddr, offset, sz); if (!o) { return false; } @@ -513,44 +513,44 @@ static bool xtr_metadata_match(RBinXtrData *xtr_data, const char *arch, int bits return bits == iter_bits && !strcmp (iter_arch, arch) && !xtr_data->loaded; } -R_IPI RBinFile *r_bin_file_new_from_buffer(RBin *bin, const char *file, RBuffer *buf, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname) { - r_return_val_if_fail (bin && file && buf, NULL); +R_IPI RBinFile *rz_bin_file_new_from_buffer(RBin *bin, const char *file, RBuffer *buf, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname) { + rz_return_val_if_fail (bin && file && buf, NULL); - RBinFile *bf = r_bin_file_new (bin, file, r_buf_size (buf), rawstr, fd, pluginname, NULL, false); + RBinFile *bf = rz_bin_file_new (bin, file, rz_buf_size (buf), rawstr, fd, pluginname, NULL, false); if (bf) { - RListIter *item = r_list_append (bin->binfiles, bf); - bf->buf = r_buf_ref (buf); + RzListIter *item = rz_list_append (bin->binfiles, bf); + bf->buf = rz_buf_ref (buf); RBinPlugin *plugin = get_plugin_from_buffer (bin, pluginname, bf->buf); - RBinObject *o = r_bin_object_new (bf, plugin, baseaddr, loadaddr, 0, r_buf_size (bf->buf)); + RBinObject *o = rz_bin_object_new (bf, plugin, baseaddr, loadaddr, 0, rz_buf_size (bf->buf)); if (!o) { - r_list_delete (bin->binfiles, item); + rz_list_delete (bin->binfiles, item); return NULL; } // size is set here because the reported size of the object depends on // if loaded from xtr plugin or partially read if (!o->size) { - o->size = r_buf_size (buf); + o->size = rz_buf_size (buf); } } return bf; } -R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits) { - RListIter *iter; +RZ_API RBinFile *rz_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits) { + RzListIter *iter; RBinFile *binfile = NULL; RBinXtrData *xtr_data; - r_return_val_if_fail (bin && arch, NULL); + rz_return_val_if_fail (bin && arch, NULL); - r_list_foreach (bin->binfiles, iter, binfile) { - RListIter *iter_xtr; + rz_list_foreach (bin->binfiles, iter, binfile) { + RzListIter *iter_xtr; if (!binfile->xtr_data) { continue; } // look for sub-bins in Xtr Data and Load if we need to - r_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) { + rz_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) { if (xtr_metadata_match (xtr_data, arch, bits)) { - if (!r_bin_file_object_new_from_xtr_data (bin, binfile, xtr_data->baddr, + if (!rz_bin_file_object_new_from_xtr_data (bin, binfile, xtr_data->baddr, xtr_data->laddr, xtr_data)) { return NULL; } @@ -561,10 +561,10 @@ R_API RBinFile *r_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bi return binfile; } -R_IPI RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 bf_id) { +R_IPI RBinFile *rz_bin_file_find_by_id(RBin *bin, ut32 bf_id) { RBinFile *bf; - RListIter *iter; - r_list_foreach (bin->binfiles, iter, bf) { + RzListIter *iter; + rz_list_foreach (bin->binfiles, iter, bf) { if (bf->id == bf_id) { return bf; } @@ -572,42 +572,42 @@ R_IPI RBinFile *r_bin_file_find_by_id(RBin *bin, ut32 bf_id) { return NULL; } -R_API ut64 r_bin_file_delete_all(RBin *bin) { +RZ_API ut64 rz_bin_file_delete_all(RBin *bin) { if (bin) { - ut64 counter = r_list_length (bin->binfiles); - r_list_purge (bin->binfiles); + ut64 counter = rz_list_length (bin->binfiles); + rz_list_purge (bin->binfiles); bin->cur = NULL; return counter; } return 0; } -R_API bool r_bin_file_delete(RBin *bin, ut32 bin_id) { - r_return_val_if_fail (bin, false); +RZ_API bool rz_bin_file_delete(RBin *bin, ut32 bin_id) { + rz_return_val_if_fail (bin, false); - RListIter *iter; - RBinFile *bf, *cur = r_bin_cur (bin); + RzListIter *iter; + RBinFile *bf, *cur = rz_bin_cur (bin); - r_list_foreach (bin->binfiles, iter, bf) { + rz_list_foreach (bin->binfiles, iter, bf) { if (bf && bf->id == bin_id) { if (cur && cur->id == bin_id) { // avoiding UaF due to dead reference bin->cur = NULL; } - r_list_delete (bin->binfiles, iter); + rz_list_delete (bin->binfiles, iter); return true; } } return false; } -R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd) { - RListIter *iter; +RZ_API RBinFile *rz_bin_file_find_by_fd(RBin *bin, ut32 bin_fd) { + RzListIter *iter; RBinFile *bf; - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); - r_list_foreach (bin->binfiles, iter, bf) { + rz_list_foreach (bin->binfiles, iter, bf) { if (bf->fd == bin_fd) { return bf; } @@ -615,13 +615,13 @@ R_API RBinFile *r_bin_file_find_by_fd(RBin *bin, ut32 bin_fd) { return NULL; } -R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name) { - RListIter *iter; +RZ_API RBinFile *rz_bin_file_find_by_name(RBin *bin, const char *name) { + RzListIter *iter; RBinFile *bf; - r_return_val_if_fail (bin && name, NULL); + rz_return_val_if_fail (bin && name, NULL); - r_list_foreach (bin->binfiles, iter, bf) { + rz_list_foreach (bin->binfiles, iter, bf) { if (bf->file && !strcmp (bf->file, name)) { return bf; } @@ -629,15 +629,15 @@ R_API RBinFile *r_bin_file_find_by_name(RBin *bin, const char *name) { return NULL; } -R_IPI RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx) { - RListIter *iter; +R_IPI RBinFile *rz_bin_file_find_by_name_n(RBin *bin, const char *name, int idx) { + RzListIter *iter; RBinFile *bf = NULL; int i = 0; if (!bin) { return bf; } - r_list_foreach (bin->binfiles, iter, bf) { + rz_list_foreach (bin->binfiles, iter, bf) { if (bf && bf->file && !strcmp (bf->file, name)) { if (i == idx) { break; @@ -649,18 +649,18 @@ R_IPI RBinFile *r_bin_file_find_by_name_n(RBin *bin, const char *name, int idx) return bf; } -R_API bool r_bin_file_set_cur_by_id(RBin *bin, ut32 bin_id) { - RBinFile *bf = r_bin_file_find_by_id (bin, bin_id); - return bf? r_bin_file_set_cur_binfile (bin, bf): false; +RZ_API bool rz_bin_file_set_cur_by_id(RBin *bin, ut32 bin_id) { + RBinFile *bf = rz_bin_file_find_by_id (bin, bin_id); + return bf? rz_bin_file_set_cur_binfile (bin, bf): false; } -R_API bool r_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd) { - RBinFile *bf = r_bin_file_find_by_fd (bin, bin_fd); - return bf? r_bin_file_set_cur_binfile (bin, bf): false; +RZ_API bool rz_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd) { + RBinFile *bf = rz_bin_file_find_by_fd (bin, bin_fd); + return bf? rz_bin_file_set_cur_binfile (bin, bf): false; } -R_IPI bool r_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj) { - r_return_val_if_fail (bin && bf, false); +R_IPI bool rz_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj) { + rz_return_val_if_fail (bin && bf, false); bin->file = bf->file; bin->cur = bf; bin->narch = bf->narch; @@ -669,7 +669,7 @@ R_IPI bool r_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj) { } else { obj = bf->o; } - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); if (bin->minstrlen < 1) { bin->minstrlen = plugin? plugin->minstrlen: bin->minstrlen; } @@ -678,45 +678,45 @@ R_IPI bool r_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj) { return false; } if (!obj->info->lang) { - obj->info->lang = r_bin_lang_tostring (obj->lang); + obj->info->lang = rz_bin_lang_tostring (obj->lang); } } return true; } -R_API bool r_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf) { - r_return_val_if_fail (bin && bf, false); - return r_bin_file_set_obj (bin, bf, bf->o); +RZ_API bool rz_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf) { + rz_return_val_if_fail (bin && bf, false); + return rz_bin_file_set_obj (bin, bf, bf->o); } -R_API bool r_bin_file_set_cur_by_name(RBin *bin, const char *name) { - r_return_val_if_fail (bin && name, false); - RBinFile *bf = r_bin_file_find_by_name (bin, name); - return r_bin_file_set_cur_binfile (bin, bf); +RZ_API bool rz_bin_file_set_cur_by_name(RBin *bin, const char *name) { + rz_return_val_if_fail (bin && name, false); + RBinFile *bf = rz_bin_file_find_by_name (bin, name); + return rz_bin_file_set_cur_binfile (bin, bf); } -R_API bool r_bin_file_deref(RBin *bin, RBinFile *a) { - r_return_val_if_fail (bin && a, false); - if (!r_bin_cur_object (bin)) { +RZ_API bool rz_bin_file_deref(RBin *bin, RBinFile *a) { + rz_return_val_if_fail (bin && a, false); + if (!rz_bin_cur_object (bin)) { return false; } bin->cur = NULL; return true; } -R_API void r_bin_file_free(void /*RBinFile*/ *_bf) { +RZ_API void rz_bin_file_free(void /*RBinFile*/ *_bf) { if (!_bf) { return; } RBinFile *bf = _bf; - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); // Binary format objects are connected to the // RBinObject, so the plugin must destroy the // format data first if (plugin && plugin->destroy) { plugin->destroy (bf); } - r_buf_free (bf->buf); + rz_buf_free (bf->buf); if (bf->curxtr && bf->curxtr->destroy && bf->xtr_obj) { bf->curxtr->free_xtr ((void *)(bf->xtr_obj)); } @@ -726,46 +726,46 @@ R_API void r_bin_file_free(void /*RBinFile*/ *_bf) { bf->sdb_addrinfo = NULL; } free (bf->file); - r_bin_object_free (bf->o); - r_list_free (bf->xtr_data); + rz_bin_object_free (bf->o); + rz_list_free (bf->xtr_data); if (bf->id != -1) { - // TODO: use r_storage api - r_id_pool_kick_id (bf->rbin->ids->pool, bf->id); + // TODO: use rz_storage api + rz_id_pool_kick_id (bf->rbin->ids->pool, bf->id); } - (void) r_bin_object_delete (bf->rbin, bf->id); + (void) rz_bin_object_delete (bf->rbin, bf->id); free (bf); } -R_IPI RBinFile *r_bin_file_xtr_load_buffer(RBin *bin, RBinXtrPlugin *xtr, const char *filename, RBuffer *buf, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr) { - r_return_val_if_fail (bin && xtr && buf, NULL); +R_IPI RBinFile *rz_bin_file_xtr_load_buffer(RBin *bin, RBinXtrPlugin *xtr, const char *filename, RBuffer *buf, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr) { + rz_return_val_if_fail (bin && xtr && buf, NULL); - RBinFile *bf = r_bin_file_find_by_name (bin, filename); + RBinFile *bf = rz_bin_file_find_by_name (bin, filename); if (!bf) { - bf = r_bin_file_new (bin, filename, r_buf_size (buf), rawstr, fd, xtr->name, bin->sdb, false); + bf = rz_bin_file_new (bin, filename, rz_buf_size (buf), rawstr, fd, xtr->name, bin->sdb, false); if (!bf) { return NULL; } - r_list_append (bin->binfiles, bf); + rz_list_append (bin->binfiles, bf); if (!bin->cur) { bin->cur = bf; } } - r_list_free (bf->xtr_data); + rz_list_free (bf->xtr_data); bf->xtr_data = NULL; if (xtr->extractall_from_buffer) { bf->xtr_data = xtr->extractall_from_buffer (bin, buf); } else if (xtr->extractall_from_bytes) { ut64 sz = 0; - const ut8 *bytes = r_buf_data (buf, &sz); + const ut8 *bytes = rz_buf_data (buf, &sz); eprintf ("TODO: Implement extractall_from_buffer in '%s' xtr.bin plugin\n", xtr->name); bf->xtr_data = xtr->extractall_from_bytes (bin, bytes, sz); } if (bf->xtr_data) { - RListIter *iter; + RzListIter *iter; RBinXtrData *x; //populate xtr_data with baddr and laddr that will be used later on - //r_bin_file_object_new_from_xtr_data - r_list_foreach (bf->xtr_data, iter, x) { + //rz_bin_file_object_new_from_xtr_data + rz_list_foreach (bf->xtr_data, iter, x) { x->baddr = baseaddr? baseaddr : UT64_MAX; x->laddr = loadaddr? loadaddr : UT64_MAX; } @@ -775,37 +775,37 @@ R_IPI RBinFile *r_bin_file_xtr_load_buffer(RBin *bin, RBinXtrPlugin *xtr, const } // XXX deprecate this function imho.. wee can just access bf->buf directly -R_IPI bool r_bin_file_set_bytes(RBinFile *bf, const ut8 *bytes, ut64 sz, bool steal_ptr) { - r_return_val_if_fail (bf && bytes, false); - r_buf_free (bf->buf); +R_IPI bool rz_bin_file_set_bytes(RBinFile *bf, const ut8 *bytes, ut64 sz, bool steal_ptr) { + rz_return_val_if_fail (bf && bytes, false); + rz_buf_free (bf->buf); if (steal_ptr) { - bf->buf = r_buf_new_with_pointers (bytes, sz, true); + bf->buf = rz_buf_new_with_pointers (bytes, sz, true); } else { - bf->buf = r_buf_new_with_bytes (bytes, sz); + bf->buf = rz_buf_new_with_bytes (bytes, sz); } return bf->buf != NULL; } -R_API RBinPlugin *r_bin_file_cur_plugin(RBinFile *bf) { +RZ_API RBinPlugin *rz_bin_file_cur_plugin(RBinFile *bf) { return (bf && bf->o)? bf->o->plugin: NULL; } // TODO: searchStrings() instead -R_IPI RList *r_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { - r_return_val_if_fail (bf, NULL); - RListIter *iter; +R_IPI RzList *rz_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { + rz_return_val_if_fail (bf, NULL); + RzListIter *iter; RBinSection *section; - RList *ret = dump? NULL: r_list_newf (r_bin_string_free); + RzList *ret = dump? NULL: rz_list_newf (rz_bin_string_free); - if (!raw && bf && bf->o && bf->o->sections && !r_list_empty (bf->o->sections)) { + if (!raw && bf && bf->o && bf->o->sections && !rz_list_empty (bf->o->sections)) { RBinObject *o = bf->o; - r_list_foreach (o->sections, iter, section) { + rz_list_foreach (o->sections, iter, section) { if (__isDataSection (bf, section)) { get_strings_range (bf, ret, min, raw, section->paddr, section->paddr + section->size, section); } } - r_list_foreach (o->sections, iter, section) { + rz_list_foreach (o->sections, iter, section) { /* load objc/swift strings */ const int bits = (bf->o && bf->o->info) ? bf->o->info->bits : 32; const int cfstr_size = (bits == 64) ? 32 : 16; @@ -821,7 +821,7 @@ R_IPI RList *r_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { if (!sbuf) { continue; } - r_buf_read_at (bf->buf, section->paddr + cfstr_offs, sbuf, section->size); + rz_buf_read_at (bf->buf, section->paddr + cfstr_offs, sbuf, section->size); for (i = 0; i < section->size; i += cfstr_size) { ut8 *buf = sbuf; p = buf + i; @@ -829,7 +829,7 @@ R_IPI RList *r_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { break; } ut64 cfstr_vaddr = section->vaddr + i; - ut64 cstr_vaddr = (bits == 64) ? r_read_le64 (p) : r_read_le32 (p); + ut64 cstr_vaddr = (bits == 64) ? rz_read_le64 (p) : rz_read_le32 (p); RBinString *s = __stringAt (bf, ret, cstr_vaddr); if (s) { RBinString *bs = R_NEW0 (RBinString); @@ -840,8 +840,8 @@ R_IPI RList *r_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { bs->ordinal = s->ordinal; bs->vaddr = cfstr_vaddr; bs->paddr = cfstr_vaddr; // XXX should be paddr instead - bs->string = r_str_newf ("cstr.%s", s->string); - r_list_append (ret, bs); + bs->string = rz_str_newf ("cstr.%s", s->string); + rz_list_append (ret, bs); ht_up_insert (o->strings_db, bs->vaddr, bs); } } @@ -855,41 +855,41 @@ R_IPI RList *r_bin_file_get_strings(RBinFile *bf, int min, int dump, int raw) { return ret; } -R_API ut64 r_bin_file_get_baddr(RBinFile *bf) { +RZ_API ut64 rz_bin_file_get_baddr(RBinFile *bf) { if (bf && bf->o) { return bf->o->baddr; } return UT64_MAX; } -R_API bool r_bin_file_close(RBin *bin, int bd) { - r_return_val_if_fail (bin, false); - RBinFile *bf = r_id_storage_take (bin->ids, bd); +RZ_API bool rz_bin_file_close(RBin *bin, int bd) { + rz_return_val_if_fail (bin, false); + RBinFile *bf = rz_id_storage_take (bin->ids, bd); if (bf) { // file_free removes the fd already.. maybe its unnecessary - r_id_storage_delete (bin->ids, bd); - r_bin_file_free (bf); + rz_id_storage_delete (bin->ids, bd); + rz_bin_file_free (bf); return true; } return false; } -R_API RList *r_bin_file_compute_hashes(RBin *bin, ut64 limit) { - r_return_val_if_fail (bin && bin->cur && bin->cur->o, NULL); +RZ_API RzList *rz_bin_file_compute_hashes(RBin *bin, ut64 limit) { + rz_return_val_if_fail (bin && bin->cur && bin->cur->o, NULL); ut64 buf_len = 0, r = 0; RBinFile *bf = bin->cur; RBinObject *o = bf->o; - RIODesc *iod = r_io_desc_get (bin->iob.io, bf->fd); + RzIODesc *iod = rz_io_desc_get (bin->iob.io, bf->fd); if (!iod) { return NULL; } - buf_len = r_io_desc_size (iod); + buf_len = rz_io_desc_size (iod); // By SLURP_LIMIT normally cannot compute ... if (buf_len > limit) { if (bin->verbose) { - eprintf ("Warning: r_bin_file_hash: file exceeds bin.hashlimit\n"); + eprintf ("Warning: rz_bin_file_hash: file exceeds bin.hashlimit\n"); } return NULL; } @@ -901,105 +901,105 @@ R_API RList *r_bin_file_compute_hashes(RBin *bin, ut64 limit) { } char hash[128]; - RHash *ctx = r_hash_new (false, R_HASH_MD5 | R_HASH_SHA1 | R_HASH_SHA256); + RzHash *ctx = rz_hash_new (false, R_HASH_MD5 | R_HASH_SHA1 | R_HASH_SHA256); while (r + blocksize < buf_len) { - r_io_desc_seek (iod, r, R_IO_SEEK_SET); - int b = r_io_desc_read (iod, buf, blocksize); - (void)r_hash_do_md5 (ctx, buf, blocksize); - (void)r_hash_do_sha1 (ctx, buf, blocksize); - (void)r_hash_do_sha256 (ctx, buf, blocksize); + rz_io_desc_seek (iod, r, R_IO_SEEK_SET); + int b = rz_io_desc_read (iod, buf, blocksize); + (void)rz_hash_do_md5 (ctx, buf, blocksize); + (void)rz_hash_do_sha1 (ctx, buf, blocksize); + (void)rz_hash_do_sha256 (ctx, buf, blocksize); r += b; } if (r < buf_len) { - r_io_desc_seek (iod, r, R_IO_SEEK_SET); + rz_io_desc_seek (iod, r, R_IO_SEEK_SET); const size_t rem_len = buf_len-r; - int b = r_io_desc_read (iod, buf, rem_len); + int b = rz_io_desc_read (iod, buf, rem_len); if (b < 1) { - eprintf ("r_io_desc_read: error\n"); + eprintf ("rz_io_desc_read: error\n"); } else { - (void)r_hash_do_md5 (ctx, buf, b); - (void)r_hash_do_sha1 (ctx, buf, b); - (void)r_hash_do_sha256 (ctx, buf, b); + (void)rz_hash_do_md5 (ctx, buf, b); + (void)rz_hash_do_sha1 (ctx, buf, b); + (void)rz_hash_do_sha256 (ctx, buf, b); } } - r_hash_do_end (ctx, R_HASH_MD5); - r_hex_bin2str (ctx->digest, R_HASH_SIZE_MD5, hash); + rz_hash_do_end (ctx, R_HASH_MD5); + rz_hex_bin2str (ctx->digest, R_HASH_SIZE_MD5, hash); - RList *file_hashes = r_list_newf ((RListFree) r_bin_file_hash_free); + RzList *file_hashes = rz_list_newf ((RzListFree) rz_bin_file_hash_free); RBinFileHash *md5h = R_NEW0 (RBinFileHash); if (md5h) { md5h->type = strdup ("md5"); md5h->hex = strdup (hash); - r_list_push (file_hashes, md5h); + rz_list_push (file_hashes, md5h); } - r_hash_do_end (ctx, R_HASH_SHA1); - r_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA1, hash); + rz_hash_do_end (ctx, R_HASH_SHA1); + rz_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA1, hash); RBinFileHash *sha1h = R_NEW0 (RBinFileHash); if (sha1h) { sha1h->type = strdup ("sha1"); sha1h->hex = strdup (hash); - r_list_push (file_hashes, sha1h); + rz_list_push (file_hashes, sha1h); } - r_hash_do_end (ctx, R_HASH_SHA256); - r_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA256, hash); + rz_hash_do_end (ctx, R_HASH_SHA256); + rz_hex_bin2str (ctx->digest, R_HASH_SIZE_SHA256, hash); RBinFileHash *sha256h = R_NEW0 (RBinFileHash); if (sha256h) { sha256h->type = strdup ("sha256"); sha256h->hex = strdup (hash); - r_list_push (file_hashes, sha256h); + rz_list_push (file_hashes, sha256h); } if (o->plugin && o->plugin->hashes) { - RList *plugin_hashes = o->plugin->hashes (bf); - r_list_join (file_hashes, plugin_hashes); + RzList *plugin_hashes = o->plugin->hashes (bf); + rz_list_join (file_hashes, plugin_hashes); free (plugin_hashes); } // TODO: add here more rows free (buf); - r_hash_free (ctx); + rz_hash_free (ctx); return file_hashes; } -// Set new hashes to current RBinInfo, caller should free the returned RList -R_API RList *r_bin_file_set_hashes(RBin *bin, RList/*cur && bin->cur->o && bin->cur->o->info, NULL); +// Set new hashes to current RBinInfo, caller should free the returned RzList +RZ_API RzList *rz_bin_file_set_hashes(RBin *bin, RzList/*cur && bin->cur->o && bin->cur->o->info, NULL); RBinFile *bf = bin->cur; RBinInfo *info = bf->o->info; - RList *prev_hashes = info->file_hashes; + RzList *prev_hashes = info->file_hashes; info->file_hashes = new_hashes; return prev_hashes; } -R_IPI RBinClass *r_bin_class_new(const char *name, const char *super, int view) { - r_return_val_if_fail (name, NULL); +R_IPI RBinClass *rz_bin_class_new(const char *name, const char *super, int view) { + rz_return_val_if_fail (name, NULL); RBinClass *c = R_NEW0 (RBinClass); if (c) { c->name = strdup (name); c->super = super? strdup (super): NULL; - c->methods = r_list_new (); - c->fields = r_list_new (); + c->methods = rz_list_new (); + c->fields = rz_list_new (); c->visibility = view; } return c; } -R_IPI void r_bin_class_free(RBinClass *k) { +R_IPI void rz_bin_class_free(RBinClass *k) { if (k && k->name) { free (k->name); free (k->super); - r_list_free (k->methods); - r_list_free (k->fields); + rz_list_free (k->methods); + rz_list_free (k->fields); free (k); } } -R_API RBinClass *r_bin_file_add_class(RBinFile *bf, const char *name, const char *super, int view) { - r_return_val_if_fail (name && bf && bf->o, NULL); +RZ_API RBinClass *rz_bin_file_add_class(RBinFile *bf, const char *name, const char *super, int view) { + rz_return_val_if_fail (name && bf && bf->o, NULL); RBinClass *c = __getClass (bf, name); if (c) { if (super) { @@ -1008,20 +1008,20 @@ R_API RBinClass *r_bin_file_add_class(RBinFile *bf, const char *name, const char } return c; } - c = r_bin_class_new (name, super, view); + c = rz_bin_class_new (name, super, view); if (c) { // XXX. no need for a list, the ht is iterable too - c->index = r_list_length (bf->o->classes); - r_list_append (bf->o->classes, c); + c->index = rz_list_length (bf->o->classes); + rz_list_append (bf->o->classes, c); ht_pp_insert (bf->o->classes_ht, name, c); } return c; } -R_API RBinSymbol *r_bin_file_add_method(RBinFile *bf, const char *klass, const char *method, int nargs) { - r_return_val_if_fail (bf, NULL); +RZ_API RBinSymbol *rz_bin_file_add_method(RBinFile *bf, const char *klass, const char *method, int nargs) { + rz_return_val_if_fail (bf, NULL); - RBinClass *c = r_bin_file_add_class (bf, klass, NULL, 0); + RBinClass *c = rz_bin_file_add_class (bf, klass, NULL, 0); if (!c) { eprintf ("Cannot allocate class %s\n", klass); return NULL; @@ -1031,7 +1031,7 @@ R_API RBinSymbol *r_bin_file_add_method(RBinFile *bf, const char *klass, const c sym = R_NEW0 (RBinSymbol); if (sym) { sym->name = strdup (method); - r_list_append (c->methods, sym); + rz_list_append (c->methods, sym); const char *name = sdb_fmt ("%s::%s", klass, method); ht_pp_insert (bf->o->methods_ht, name, sym); } @@ -1039,7 +1039,7 @@ R_API RBinSymbol *r_bin_file_add_method(RBinFile *bf, const char *klass, const c return sym; } -R_API RBinField *r_bin_file_add_field(RBinFile *binfile, const char *classname, const char *name) { +RZ_API RBinField *rz_bin_file_add_field(RBinFile *binfile, const char *classname, const char *name) { //TODO: add_field into class //eprintf ("TODO add field: %s \n", name); return NULL; @@ -1048,24 +1048,24 @@ R_API RBinField *r_bin_file_add_field(RBinFile *binfile, const char *classname, // XXX this api name makes no sense /* returns vaddr, rebased with the baseaddr of binfile, if va is enabled for * bin, paddr otherwise */ -R_API ut64 r_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr) { - r_return_val_if_fail (bf && bf->o, paddr); +RZ_API ut64 rz_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr) { + rz_return_val_if_fail (bf && bf->o, paddr); if (bf->o->info && bf->o->info->has_va) { return binobj_a2b (bf->o, vaddr); } return paddr; } -R_API RList *r_bin_file_get_trycatch(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->plugin, NULL); +RZ_API RzList *rz_bin_file_get_trycatch(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->plugin, NULL); if (bf->o->plugin->trycatch) { return bf->o->plugin->trycatch (bf); } return NULL; } -R_API RList *r_bin_file_get_symbols(RBinFile *bf) { - r_return_val_if_fail (bf, NULL); +RZ_API RzList *rz_bin_file_get_symbols(RBinFile *bf) { + rz_return_val_if_fail (bf, NULL); RBinObject *o = bf->o; return o? o->symbols: NULL; } diff --git a/libr/bin/bin.c b/librz/bin/bin.c similarity index 60% rename from libr/bin/bin.c rename to librz/bin/bin.c index 6da10f3ec4..dfce49fa02 100644 --- a/libr/bin/bin.c +++ b/librz/bin/bin.c @@ -1,19 +1,19 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake, nibble, dso */ +/* rizin - LGPL - Copyright 2009-2020 - pancake, nibble, dso */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include "i/private.h" -R_LIB_VERSION (r_bin); +R_LIB_VERSION (rz_bin); #define DB a->sdb; #define RBINLISTFREE(x)\ if (x) { \ - r_list_free (x);\ + rz_list_free (x);\ (x) = NULL;\ } @@ -34,8 +34,8 @@ static RBinXtrPlugin *bin_xtr_static_plugins[] = { R_BIN_XTR_STATIC_PLUGINS, NUL static RBinLdrPlugin *bin_ldr_static_plugins[] = { R_BIN_LDR_STATIC_PLUGINS, NULL }; static int __getoffset(RBin *bin, int type, int idx) { - RBinFile *a = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (a); + RBinFile *a = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (a); if (plugin && plugin->get_offset) { return plugin->get_offset (a, type, idx); } @@ -43,8 +43,8 @@ static int __getoffset(RBin *bin, int type, int idx) { } static const char *__getname(RBin *bin, int type, int idx, bool sd) { - RBinFile *a = r_bin_cur (bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (a); + RBinFile *a = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (a); if (plugin && plugin->get_name) { return plugin->get_name (a, type, idx, sd); } @@ -56,7 +56,7 @@ static ut64 binobj_a2b(RBinObject *o, ut64 addr) { } // TODO: move these two function do a different file -R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata) { +RZ_API RBinXtrData *rz_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata) { RBinXtrData *data = R_NEW0 (RBinXtrData); if (data) { data->offset = offset; @@ -65,12 +65,12 @@ R_API RBinXtrData *r_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 data->metadata = metadata; data->loaded = 0; // don't slice twice TODO. review this - data->buf = r_buf_ref (buf); // r_buf_new_slice (buf, offset, size); + data->buf = rz_buf_ref (buf); // rz_buf_new_slice (buf, offset, size); } return data; } -R_API const char *r_bin_string_type(int type) { +RZ_API const char *rz_bin_string_type(int type) { switch (type) { case 'a': return "ascii"; case 'u': return "utf8"; @@ -81,9 +81,9 @@ R_API const char *r_bin_string_type(int type) { return "ascii"; // XXX } -R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data_) { +RZ_API void rz_bin_xtrdata_free(void /*RBinXtrData*/ *data_) { RBinXtrData *data = data_; - r_return_if_fail (data); + rz_return_if_fail (data); if (data->metadata) { free (data->metadata->libname); free (data->metadata->arch); @@ -91,21 +91,21 @@ R_API void r_bin_xtrdata_free(void /*RBinXtrData*/ *data_) { free (data->metadata); } free (data->file); - r_buf_free (data->buf); + rz_buf_free (data->buf); free (data); } -R_API RList *r_bin_raw_strings(RBinFile *bf, int min) { - r_return_val_if_fail (bf, NULL); - return r_bin_file_get_strings (bf, min, 0, 2); +RZ_API RzList *rz_bin_raw_strings(RBinFile *bf, int min) { + rz_return_val_if_fail (bf, NULL); + return rz_bin_file_get_strings (bf, min, 0, 2); } -R_API RList *r_bin_dump_strings(RBinFile *bf, int min, int raw) { - r_return_val_if_fail (bf, NULL); - return r_bin_file_get_strings (bf, min, 1, raw); +RZ_API RzList *rz_bin_dump_strings(RBinFile *bf, int min, int raw) { + rz_return_val_if_fail (bf, NULL); + return rz_bin_file_get_strings (bf, min, 1, raw); } -R_API void r_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, int rawstr) { +RZ_API void rz_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, int rawstr) { memset (opt, 0, sizeof (*opt)); opt->baseaddr = baseaddr; opt->loadaddr = loadaddr; @@ -113,12 +113,12 @@ R_API void r_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 load opt->rawstr = rawstr; } -R_API void r_bin_arch_options_init(RBinArchOptions *opt, const char *arch, int bits) { +RZ_API void rz_bin_arch_options_init(RBinArchOptions *opt, const char *arch, int bits) { opt->arch = arch? arch: R_SYS_ARCH; opt->bits = bits? bits: R_SYS_BITS; } -R_API void r_bin_file_hash_free(RBinFileHash *fhash) { +RZ_API void rz_bin_file_hash_free(RBinFileHash *fhash) { if (fhash) { R_FREE (fhash->type); R_FREE (fhash->hex); @@ -126,12 +126,12 @@ R_API void r_bin_file_hash_free(RBinFileHash *fhash) { } } -R_API void r_bin_info_free(RBinInfo *rb) { +RZ_API void rz_bin_info_free(RBinInfo *rb) { if (!rb) { return; } - r_list_free (rb->file_hashes); + rz_list_free (rb->file_hashes); free (rb->intrp); free (rb->file); free (rb->type); @@ -152,10 +152,10 @@ R_API void r_bin_info_free(RBinInfo *rb) { free (rb); } -R_API RBinImport *r_bin_import_clone(RBinImport *o) { - r_return_val_if_fail (o, NULL); +RZ_API RBinImport *rz_bin_import_clone(RBinImport *o) { + rz_return_val_if_fail (o, NULL); - RBinImport *res = r_mem_dup (o, sizeof (*o)); + RBinImport *res = rz_mem_dup (o, sizeof (*o)); if (res) { res->name = R_STR_DUP (o->name); res->classname = R_STR_DUP (o->classname); @@ -164,7 +164,7 @@ R_API RBinImport *r_bin_import_clone(RBinImport *o) { return res; } -R_API void r_bin_import_free(void *_imp) { +RZ_API void rz_bin_import_free(void *_imp) { RBinImport *imp = (RBinImport *)_imp; if (imp) { R_FREE (imp->name); @@ -175,14 +175,14 @@ R_API void r_bin_import_free(void *_imp) { } } -R_API const char *r_bin_symbol_name(RBinSymbol *s) { +RZ_API const char *rz_bin_symbol_name(RBinSymbol *s) { if (s->dup_count) { return sdb_fmt ("%s_%d", s->name, s->dup_count); } return s->name; } -R_API RBinSymbol *r_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr) { +RZ_API RBinSymbol *rz_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (sym) { sym->name = name? strdup (name): NULL; @@ -192,7 +192,7 @@ R_API RBinSymbol *r_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr) { return sym; } -R_API void r_bin_symbol_free(void *_sym) { +RZ_API void rz_bin_symbol_free(void *_sym) { RBinSymbol *sym = (RBinSymbol *)_sym; if (sym) { free (sym->name); @@ -202,7 +202,7 @@ R_API void r_bin_symbol_free(void *_sym) { } } -R_API void r_bin_string_free(void *_str) { +RZ_API void rz_bin_string_free(void *_str) { RBinString *str = (RBinString *)_str; if (str) { free (str->string); @@ -215,10 +215,10 @@ R_API void r_bin_string_free(void *_str) { // kinda a clunky functions // XXX - this is a rather hacky way to do things, there may need to be a better // way. -R_API bool r_bin_open(RBin *bin, const char *file, RBinOptions *opt) { - r_return_val_if_fail (bin && bin->iob.io && opt, false); +RZ_API bool rz_bin_open(RBin *bin, const char *file, RBinOptions *opt) { + rz_return_val_if_fail (bin && bin->iob.io && opt, false); - RIOBind *iob = &(bin->iob); + RzIOBind *iob = &(bin->iob); if (!iob->desc_get (iob->io, opt->fd)) { opt->fd = iob->fd_open (iob->io, file, R_PERM_R, 0644); } @@ -228,30 +228,30 @@ R_API bool r_bin_open(RBin *bin, const char *file, RBinOptions *opt) { } opt->sz = 0; opt->pluginname = NULL; - return r_bin_open_io (bin, opt); + return rz_bin_open_io (bin, opt); } -R_API bool r_bin_reload(RBin *bin, ut32 bf_id, ut64 baseaddr) { - r_return_val_if_fail (bin, false); +RZ_API bool rz_bin_reload(RBin *bin, ut32 bf_id, ut64 baseaddr) { + rz_return_val_if_fail (bin, false); - RBinFile *bf = r_bin_file_find_by_id (bin, bf_id); + RBinFile *bf = rz_bin_file_find_by_id (bin, bf_id); if (!bf) { - eprintf ("r_bin_reload: No file to reopen\n"); + eprintf ("rz_bin_reload: No file to reopen\n"); return false; } RBinOptions opt; - r_bin_options_init (&opt, bf->fd, baseaddr, bf->loadaddr, bin->rawstr); + rz_bin_options_init (&opt, bf->fd, baseaddr, bf->loadaddr, bin->rawstr); opt.filename = bf->file; - bool res = r_bin_open_buf (bin, bf->buf, &opt); - r_bin_file_delete (bin, bf->id); + bool res = rz_bin_open_buf (bin, bf->buf, &opt); + rz_bin_file_delete (bin, bf->id); return res; } -R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt) { - r_return_val_if_fail (bin && opt, false); +RZ_API bool rz_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt) { + rz_return_val_if_fail (bin && opt, false); - RListIter *it; + RzListIter *it; RBinXtrPlugin *xtr; bin->rawstr = opt->rawstr; @@ -265,7 +265,7 @@ R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt) { // XXX - for the time being this is fine, but we may want to // change the name to something like // : - r_list_foreach (bin->binxtrs, it, xtr) { + rz_list_foreach (bin->binxtrs, it, xtr) { if (!xtr->check_buffer) { eprintf ("Missing check_buffer callback for '%s'\n", xtr->name); continue; @@ -273,7 +273,7 @@ R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt) { if (xtr->check_buffer (buf)) { if (xtr->extract_from_buffer || xtr->extractall_from_buffer || xtr->extract_from_bytes || xtr->extractall_from_bytes) { - bf = r_bin_file_xtr_load_buffer (bin, xtr, + bf = rz_bin_file_xtr_load_buffer (bin, xtr, bin->file, buf, opt->baseaddr, opt->loadaddr, opt->xtr_idx, opt->fd, bin->rawstr); } @@ -282,26 +282,26 @@ R_API bool r_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt) { } if (!bf) { // Uncomment for this speedup: 20s vs 22s - // RBuffer *buf = r_buf_new_slurp (bin->file); - bf = r_bin_file_new_from_buffer (bin, bin->file, buf, bin->rawstr, + // RBuffer *buf = rz_buf_new_slurp (bin->file); + bf = rz_bin_file_new_from_buffer (bin, bin->file, buf, bin->rawstr, opt->baseaddr, opt->loadaddr, opt->fd, opt->pluginname); if (!bf) { return false; } } - if (!r_bin_file_set_cur_binfile (bin, bf)) { + if (!rz_bin_file_set_cur_binfile (bin, bf)) { return false; } - r_id_storage_set (bin->ids, bin->cur, bf->id); + rz_id_storage_set (bin->ids, bin->cur, bf->id); return true; } -R_API bool r_bin_open_io(RBin *bin, RBinOptions *opt) { - r_return_val_if_fail (bin && opt && bin->iob.io, false); - r_return_val_if_fail (opt->fd >= 0 && (st64)opt->sz >= 0, false); +RZ_API bool rz_bin_open_io(RBin *bin, RBinOptions *opt) { + rz_return_val_if_fail (bin && opt && bin->iob.io, false); + rz_return_val_if_fail (opt->fd >= 0 && (st64)opt->sz >= 0, false); - RIOBind *iob = &(bin->iob); - RIO *io = iob? iob->io: NULL; + RzIOBind *iob = &(bin->iob); + RzIO *io = iob? iob->io: NULL; bool is_debugger = iob->fd_is_dbg (io, opt->fd); const char *fname = iob->fd_get_name (io, opt->fd); @@ -316,45 +316,45 @@ R_API bool r_bin_open_io(RBin *bin, RBinOptions *opt) { // debugee process. RBuffer *buf = NULL; if (is_debugger) { - buf = r_buf_new_file (fname, O_RDONLY, 0); + buf = rz_buf_new_file (fname, O_RDONLY, 0); is_debugger = false; } if (!buf) { - buf = r_buf_new_with_io (&bin->iob, opt->fd); + buf = rz_buf_new_with_io (&bin->iob, opt->fd); } if (!buf) { return false; } if (!opt->sz) { - opt->sz = r_buf_size (buf); + opt->sz = rz_buf_size (buf); } // Slice buffer if necessary RBuffer *slice = buf; - if (!is_debugger && (opt->loadaddr != 0 || opt->sz != r_buf_size (buf))) { - slice = r_buf_new_slice (buf, opt->loadaddr, opt->sz); + if (!is_debugger && (opt->loadaddr != 0 || opt->sz != rz_buf_size (buf))) { + slice = rz_buf_new_slice (buf, opt->loadaddr, opt->sz); } else if (is_debugger && opt->baseaddr != UT64_MAX && opt->baseaddr != 0) { - slice = r_buf_new_slice (buf, opt->baseaddr, opt->sz); + slice = rz_buf_new_slice (buf, opt->baseaddr, opt->sz); } if (slice != buf) { - r_buf_free (buf); + rz_buf_free (buf); buf = slice; } opt->filename = fname; - bool res = r_bin_open_buf (bin, buf, opt); - r_buf_free (buf); + bool res = rz_bin_open_buf (bin, buf, opt); + rz_buf_free (buf); return res; } -R_IPI RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name) { +R_IPI RBinPlugin *rz_bin_get_binplugin_by_name(RBin *bin, const char *name) { RBinPlugin *plugin; - RListIter *it; + RzListIter *it; - r_return_val_if_fail (bin && name, NULL); + rz_return_val_if_fail (bin && name, NULL); - r_list_foreach (bin->plugins, it, plugin) { + rz_list_foreach (bin->plugins, it, plugin) { if (!strcmp (plugin->name, name)) { return plugin; } @@ -362,13 +362,13 @@ R_IPI RBinPlugin *r_bin_get_binplugin_by_name(RBin *bin, const char *name) { return NULL; } -R_API RBinPlugin *r_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf) { +RZ_API RBinPlugin *rz_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf) { RBinPlugin *plugin; - RListIter *it; + RzListIter *it; - r_return_val_if_fail (bin && buf, NULL); + rz_return_val_if_fail (bin && buf, NULL); - r_list_foreach (bin->plugins, it, plugin) { + rz_list_foreach (bin->plugins, it, plugin) { if (plugin->check_buffer) { if (plugin->check_buffer (buf)) { return plugin; @@ -378,14 +378,14 @@ R_API RBinPlugin *r_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf) { return NULL; } -R_IPI RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name) { +R_IPI RBinXtrPlugin *rz_bin_get_xtrplugin_by_name(RBin *bin, const char *name) { RBinXtrPlugin *xtr; - RListIter *it; + RzListIter *it; - r_return_val_if_fail (bin && name, NULL); + rz_return_val_if_fail (bin && name, NULL); // TODO: use a hashtable here - r_list_foreach (bin->binxtrs, it, xtr) { + rz_list_foreach (bin->binxtrs, it, xtr) { if (!strcmp (xtr->name, name)) { return xtr; } @@ -395,91 +395,91 @@ R_IPI RBinXtrPlugin *r_bin_get_xtrplugin_by_name(RBin *bin, const char *name) { return NULL; } -static void r_bin_plugin_free(RBinPlugin *p) { +static void rz_bin_plugin_free(RBinPlugin *p) { if (p && p->fini) { p->fini (NULL); } R_FREE (p); } -// rename to r_bin_plugin_add like the rest -R_API bool r_bin_add(RBin *bin, RBinPlugin *foo) { - RListIter *it; +// rename to rz_bin_plugin_add like the rest +RZ_API bool rz_bin_add(RBin *bin, RBinPlugin *foo) { + RzListIter *it; RBinPlugin *plugin; - r_return_val_if_fail (bin && foo, false); + rz_return_val_if_fail (bin && foo, false); if (foo->init) { foo->init (bin->user); } - r_list_foreach (bin->plugins, it, plugin) { + rz_list_foreach (bin->plugins, it, plugin) { if (!strcmp (plugin->name, foo->name)) { return false; } } plugin = R_NEW0 (RBinPlugin); memcpy (plugin, foo, sizeof (RBinPlugin)); - r_list_append (bin->plugins, plugin); + rz_list_append (bin->plugins, plugin); return true; } -R_API bool r_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo) { - RListIter *it; +RZ_API bool rz_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo) { + RzListIter *it; RBinLdrPlugin *ldr; - r_return_val_if_fail (bin && foo, false); + rz_return_val_if_fail (bin && foo, false); if (foo->init) { foo->init (bin->user); } // avoid duplicates - r_list_foreach (bin->binldrs, it, ldr) { + rz_list_foreach (bin->binldrs, it, ldr) { if (!strcmp (ldr->name, foo->name)) { return false; } } - r_list_append (bin->binldrs, foo); + rz_list_append (bin->binldrs, foo); return true; } -R_API bool r_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo) { - RListIter *it; +RZ_API bool rz_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo) { + RzListIter *it; RBinXtrPlugin *xtr; - r_return_val_if_fail (bin && foo, false); + rz_return_val_if_fail (bin && foo, false); if (foo->init) { foo->init (bin->user); } // avoid duplicates - r_list_foreach (bin->binxtrs, it, xtr) { + rz_list_foreach (bin->binxtrs, it, xtr) { if (!strcmp (xtr->name, foo->name)) { return false; } } - r_list_append (bin->binxtrs, foo); + rz_list_append (bin->binxtrs, foo); return true; } -R_API void r_bin_free(RBin *bin) { +RZ_API void rz_bin_free(RBin *bin) { if (bin) { bin->file = NULL; free (bin->force); free (bin->srcdir); free (bin->strenc); - //r_bin_free_bin_files (bin); - r_list_free (bin->binfiles); - r_list_free (bin->binxtrs); - r_list_free (bin->plugins); - r_list_free (bin->binldrs); + //rz_bin_free_bin_files (bin); + rz_list_free (bin->binfiles); + rz_list_free (bin->binxtrs); + rz_list_free (bin->plugins); + rz_list_free (bin->binldrs); sdb_free (bin->sdb); - r_id_storage_free (bin->ids); - r_str_constpool_fini (&bin->constpool); + rz_id_storage_free (bin->ids); + rz_str_constpool_fini (&bin->constpool); free (bin); } } -static bool r_bin_print_plugin_details(RBin *bin, RBinPlugin *bp, int json) { +static bool rz_bin_print_plugin_details(RBin *bin, RBinPlugin *bp, int json) { if (json == 'q') { bin->cb_printf ("%s\n", bp->name); } else if (json) { @@ -520,21 +520,21 @@ static void __printXtrPluginDetails(RBin *bin, RBinXtrPlugin *bx, int json) { } } -R_API bool r_bin_list_plugin(RBin *bin, const char* name, int json) { - RListIter *it; +RZ_API bool rz_bin_list_plugin(RBin *bin, const char* name, int json) { + RzListIter *it; RBinPlugin *bp; RBinXtrPlugin *bx; - r_return_val_if_fail (bin && name, false); + rz_return_val_if_fail (bin && name, false); - r_list_foreach (bin->plugins, it, bp) { - if (!r_str_cmp (name, bp->name, strlen (name))) { + rz_list_foreach (bin->plugins, it, bp) { + if (!rz_str_cmp (name, bp->name, strlen (name))) { continue; } - return r_bin_print_plugin_details (bin, bp, json); + return rz_bin_print_plugin_details (bin, bp, json); } - r_list_foreach (bin->binxtrs, it, bx) { - if (!r_str_cmp (name, bx->name, strlen (name))) { + rz_list_foreach (bin->binxtrs, it, bx) { + if (!rz_str_cmp (name, bx->name, strlen (name))) { continue; } __printXtrPluginDetails (bin, bx, json); @@ -545,17 +545,17 @@ R_API bool r_bin_list_plugin(RBin *bin, const char* name, int json) { return false; } -R_API void r_bin_list(RBin *bin, int format) { - RListIter *it; +RZ_API void rz_bin_list(RBin *bin, int format) { + RzListIter *it; RBinPlugin *bp; RBinXtrPlugin *bx; RBinLdrPlugin *ld; if (format == 'q') { - r_list_foreach (bin->plugins, it, bp) { + rz_list_foreach (bin->plugins, it, bp) { bin->cb_printf ("%s\n", bp->name); } - r_list_foreach (bin->binxtrs, it, bx) { + rz_list_foreach (bin->binxtrs, it, bx) { bin->cb_printf ("%s\n", bx->name); } } else if (format) { @@ -563,7 +563,7 @@ R_API void r_bin_list(RBin *bin, int format) { i = 0; bin->cb_printf ("{\"bin\":["); - r_list_foreach (bin->plugins, it, bp) { + rz_list_foreach (bin->plugins, it, bp) { bin->cb_printf ( "%s{\"name\":\"%s\",\"description\":\"%s\"," "\"license\":\"%s\"}", @@ -573,7 +573,7 @@ R_API void r_bin_list(RBin *bin, int format) { i = 0; bin->cb_printf ("],\"xtr\":["); - r_list_foreach (bin->binxtrs, it, bx) { + rz_list_foreach (bin->binxtrs, it, bx) { bin->cb_printf ( "%s{\"name\":\"%s\",\"description\":\"%s\"," "\"license\":\"%s\"}", @@ -583,7 +583,7 @@ R_API void r_bin_list(RBin *bin, int format) { i = 0; bin->cb_printf ("],\"ldr\":["); - r_list_foreach (bin->binxtrs, it, ld) { + rz_list_foreach (bin->binxtrs, it, ld) { bin->cb_printf ( "%s{\"name\":\"%s\",\"description\":\"%s\"," "\"license\":\"%s\"}", @@ -592,18 +592,18 @@ R_API void r_bin_list(RBin *bin, int format) { } bin->cb_printf ("]}\n"); } else { - r_list_foreach (bin->plugins, it, bp) { + rz_list_foreach (bin->plugins, it, bp) { bin->cb_printf ("bin %-11s %s (%s) %s %s\n", bp->name, bp->desc, bp->license? bp->license: "???", bp->version? bp->version: "", bp->author? bp->author: ""); } - r_list_foreach (bin->binxtrs, it, bx) { + rz_list_foreach (bin->binxtrs, it, bx) { const char *name = strncmp (bx->name, "xtr.", 4)? bx->name : bx->name + 3; bin->cb_printf ("xtr %-11s %s (%s)\n", name, bx->desc, bx->license? bx->license: "???"); } - r_list_foreach (bin->binldrs, it, ld) { + rz_list_foreach (bin->binldrs, it, ld) { const char *name = strncmp (ld->name, "ldr.", 4)? ld->name : ld->name + 3; bin->cb_printf ("ldr %-11s %s (%s)\n", name, ld->desc, ld->license? ld->license: "???"); @@ -612,23 +612,23 @@ R_API void r_bin_list(RBin *bin, int format) { } /* returns the base address of bin or UT64_MAX in case of errors */ -R_API ut64 r_bin_get_baddr(RBin *bin) { - r_return_val_if_fail (bin, UT64_MAX); - return r_bin_file_get_baddr (bin->cur); +RZ_API ut64 rz_bin_get_baddr(RBin *bin) { + rz_return_val_if_fail (bin, UT64_MAX); + return rz_bin_file_get_baddr (bin->cur); } /* returns the load address of bin or UT64_MAX in case of errors */ -R_API ut64 r_bin_get_laddr(RBin *bin) { - r_return_val_if_fail (bin, UT64_MAX); - RBinObject *o = r_bin_cur_object (bin); +RZ_API ut64 rz_bin_get_laddr(RBin *bin) { + rz_return_val_if_fail (bin, UT64_MAX); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->loadaddr : UT64_MAX; } // TODO: should be RBinFile specific imho -R_API void r_bin_set_baddr(RBin *bin, ut64 baddr) { - r_return_if_fail (bin); - RBinFile *bf = r_bin_cur (bin); - RBinObject *o = r_bin_cur_object (bin); +RZ_API void rz_bin_set_baddr(RBin *bin, ut64 baddr) { + rz_return_if_fail (bin); + RBinFile *bf = rz_bin_cur (bin); + RBinObject *o = rz_bin_cur_object (bin); if (o) { if (!o->plugin || !o->plugin->baddr) { return; @@ -650,9 +650,9 @@ R_API void r_bin_set_baddr(RBin *bin, ut64 baddr) { // maybe in RBinFile.rebase() ? } -R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RBinAddr *rz_bin_get_sym(RBin *bin, int sym) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); if (sym < 0 || sym >= R_BIN_SYM_LAST) { return NULL; } @@ -660,87 +660,87 @@ R_API RBinAddr *r_bin_get_sym(RBin *bin, int sym) { } // XXX: those accessors are redundant -R_API RList *r_bin_get_entries(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_entries(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->entries : NULL; } -R_API RList *r_bin_get_fields(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_fields(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->fields : NULL; } -R_API RList *r_bin_get_imports(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_imports(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->imports : NULL; } -R_API RBinInfo *r_bin_get_info(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RBinInfo *rz_bin_get_info(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->info : NULL; } -R_API RList *r_bin_get_libs(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_libs(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->libs : NULL; } -static RList *relocs_rbtree2list(RBNode *root) { - RList *res = r_list_new (); +static RzList *relocs_rbtree2list(RBNode *root) { + RzList *res = rz_list_new (); RBinReloc *reloc; RBIter it; - r_rbtree_foreach (root, it, reloc, RBinReloc, vrb) { - r_list_append (res, reloc); + rz_rbtree_foreach (root, it, reloc, RBinReloc, vrb) { + rz_list_append (res, reloc); } return res; } -R_API RBNode *r_bin_patch_relocs(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); - return o? r_bin_object_patch_relocs (bin, o): NULL; +RZ_API RBNode *rz_bin_patch_relocs(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); + return o? rz_bin_object_patch_relocs (bin, o): NULL; } // return a list of that needs to be freed by the caller -R_API RList *r_bin_patch_relocs_list(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBNode *root = r_bin_patch_relocs (bin); +RZ_API RzList *rz_bin_patch_relocs_list(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBNode *root = rz_bin_patch_relocs (bin); return root? relocs_rbtree2list (root): NULL; } -R_API RBNode *r_bin_get_relocs(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RBNode *rz_bin_get_relocs(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->relocs : NULL; } // return a list of that needs to be freed by the caller -R_API RList *r_bin_get_relocs_list(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBNode *root = r_bin_get_relocs (bin); +RZ_API RzList *rz_bin_get_relocs_list(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBNode *root = rz_bin_get_relocs (bin); return root? relocs_rbtree2list (root): NULL; } -R_API RList *r_bin_get_sections(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_sections(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->sections : NULL; } -R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va) { +RZ_API RBinSection *rz_bin_get_section_at(RBinObject *o, ut64 off, int va) { RBinSection *section; - RListIter *iter; + RzListIter *iter; ut64 from, to; - r_return_val_if_fail (o, NULL); + rz_return_val_if_fail (o, NULL); // TODO: must be O(1) .. use sdb here - r_list_foreach (o->sections, iter, section) { + rz_list_foreach (o->sections, iter, section) { if (section->is_segment) { continue; } @@ -753,45 +753,45 @@ R_API RBinSection *r_bin_get_section_at(RBinObject *o, ut64 off, int va) { return NULL; } -R_API RList *r_bin_reset_strings(RBin *bin) { - RBinFile *bf = r_bin_cur (bin); +RZ_API RzList *rz_bin_reset_strings(RBin *bin) { + RBinFile *bf = rz_bin_cur (bin); if (!bf || !bf->o) { return NULL; } if (bf->o->strings) { - r_list_free (bf->o->strings); + rz_list_free (bf->o->strings); bf->o->strings = NULL; } bf->rawstr = bin->rawstr; - RBinPlugin *plugin = r_bin_file_cur_plugin (bf); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); if (plugin && plugin->strings) { bf->o->strings = plugin->strings (bf); } else { - bf->o->strings = r_bin_file_get_strings (bf, bin->minstrlen, 0, bf->rawstr); + bf->o->strings = rz_bin_file_get_strings (bf, bin->minstrlen, 0, bf->rawstr); } if (bin->debase64) { - r_bin_object_filter_strings (bf->o); + rz_bin_object_filter_strings (bf->o); } return bf->o->strings; } -R_API RList *r_bin_get_strings(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_strings(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->strings : NULL; } -R_API int r_bin_is_string(RBin *bin, ut64 va) { +RZ_API int rz_bin_is_string(RBin *bin, ut64 va) { RBinString *string; - RListIter *iter; - RList *list; - if (!(list = r_bin_get_strings (bin))) { + RzListIter *iter; + RzList *list; + if (!(list = rz_bin_get_strings (bin))) { return false; } - r_list_foreach (list, iter, string) { + rz_list_foreach (list, iter, string) { if (string->vaddr == va) { return true; } @@ -802,34 +802,34 @@ R_API int r_bin_is_string(RBin *bin, ut64 va) { return false; } -R_API RList *r_bin_get_symbols(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_symbols(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o? o->symbols: NULL; } -R_API RList *r_bin_get_mem(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList *rz_bin_get_mem(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->mem : NULL; } -R_API int r_bin_is_big_endian(RBin *bin) { - r_return_val_if_fail (bin, -1); - RBinObject *o = r_bin_cur_object (bin); +RZ_API int rz_bin_is_big_endian(RBin *bin) { + rz_return_val_if_fail (bin, -1); + RBinObject *o = rz_bin_cur_object (bin); return (o && o->info) ? o->info->big_endian : -1; } -R_API int r_bin_is_static(RBin *bin) { - r_return_val_if_fail (bin, false); - RBinObject *o = r_bin_cur_object (bin); - if (o && o->libs && r_list_length (o->libs) > 0) { +RZ_API int rz_bin_is_static(RBin *bin) { + rz_return_val_if_fail (bin, false); + RBinObject *o = rz_bin_cur_object (bin); + if (o && o->libs && rz_list_length (o->libs) > 0) { return R_BIN_DBG_STATIC & o->info->dbg_info; } return true; } -R_API RBin *r_bin_new(void) { +RZ_API RBin *rz_bin_new(void) { int i; RBinXtrPlugin *static_xtr_plugin; RBinLdrPlugin *static_ldr_plugin; @@ -837,28 +837,28 @@ R_API RBin *r_bin_new(void) { if (!bin) { return NULL; } - if (!r_str_constpool_init (&bin->constpool)) { + if (!rz_str_constpool_init (&bin->constpool)) { goto trashbin; } bin->force = NULL; bin->filter_rules = UT64_MAX; bin->sdb = sdb_new0 (); bin->cb_printf = (PrintfCallback)printf; - bin->plugins = r_list_newf ((RListFree)r_bin_plugin_free); + bin->plugins = rz_list_newf ((RzListFree)rz_bin_plugin_free); bin->minstrlen = 0; bin->strpurge = NULL; bin->strenc = NULL; bin->want_dbginfo = true; bin->cur = NULL; - bin->ids = r_id_storage_new (0, ST32_MAX); + bin->ids = rz_id_storage_new (0, ST32_MAX); /* bin parsers */ - bin->binfiles = r_list_newf ((RListFree)r_bin_file_free); + bin->binfiles = rz_list_newf ((RzListFree)rz_bin_file_free); for (i = 0; bin_static_plugins[i]; i++) { - r_bin_add (bin, bin_static_plugins[i]); + rz_bin_add (bin, bin_static_plugins[i]); } /* extractors */ - bin->binxtrs = r_list_new (); + bin->binxtrs = rz_list_new (); bin->binxtrs->free = free; for (i = 0; bin_xtr_static_plugins[i]; i++) { static_xtr_plugin = R_NEW0 (RBinXtrPlugin); @@ -866,10 +866,10 @@ R_API RBin *r_bin_new(void) { goto trashbin_binxtrs; } *static_xtr_plugin = *bin_xtr_static_plugins[i]; - r_bin_xtr_add (bin, static_xtr_plugin); + rz_bin_xtr_add (bin, static_xtr_plugin); } /* loaders */ - bin->binldrs = r_list_new (); + bin->binldrs = rz_list_new (); bin->binldrs->free = free; for (i = 0; bin_ldr_static_plugins[i]; i++) { static_ldr_plugin = R_NEW0 (RBinLdrPlugin); @@ -877,74 +877,74 @@ R_API RBin *r_bin_new(void) { goto trashbin_binldrs; } *static_ldr_plugin = *bin_ldr_static_plugins[i]; - r_bin_ldr_add (bin, static_ldr_plugin); + rz_bin_ldr_add (bin, static_ldr_plugin); } return bin; trashbin_binldrs: - r_list_free (bin->binldrs); + rz_list_free (bin->binldrs); trashbin_binxtrs: - r_list_free (bin->binxtrs); - r_list_free (bin->binfiles); - r_id_storage_free (bin->ids); - r_str_constpool_fini (&bin->constpool); + rz_list_free (bin->binxtrs); + rz_list_free (bin->binfiles); + rz_id_storage_free (bin->ids); + rz_str_constpool_fini (&bin->constpool); trashbin: free(bin); return NULL; } -R_API bool r_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name) { - r_return_val_if_fail (bin && arch, false); +RZ_API bool rz_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name) { + rz_return_val_if_fail (bin && arch, false); - RBinFile *binfile = r_bin_file_find_by_arch_bits (bin, arch, bits); + RBinFile *binfile = rz_bin_file_find_by_arch_bits (bin, arch, bits); if (!binfile) { R_LOG_WARN ("Cannot find binfile with arch/bits %s/%d\n", arch, bits); return false; } - RBinObject *obj = r_bin_object_find_by_arch_bits (binfile, arch, bits, name); + RBinObject *obj = rz_bin_object_find_by_arch_bits (binfile, arch, bits, name); if (!obj && binfile->xtr_data) { - RBinXtrData *xtr_data = r_list_get_n (binfile->xtr_data, 0); + RBinXtrData *xtr_data = rz_list_get_n (binfile->xtr_data, 0); if (xtr_data && !xtr_data->loaded) { - if (!r_bin_file_object_new_from_xtr_data (bin, binfile, - UT64_MAX, r_bin_get_laddr (bin), xtr_data)) { + if (!rz_bin_file_object_new_from_xtr_data (bin, binfile, + UT64_MAX, rz_bin_get_laddr (bin), xtr_data)) { return false; } } obj = binfile->o; } - return r_bin_file_set_obj (bin, binfile, obj); + return rz_bin_file_set_obj (bin, binfile, obj); } -R_API bool r_bin_select(RBin *bin, const char *arch, int bits, const char *name) { - r_return_val_if_fail (bin, false); +RZ_API bool rz_bin_select(RBin *bin, const char *arch, int bits, const char *name) { + rz_return_val_if_fail (bin, false); - RBinFile *cur = r_bin_cur (bin); + RBinFile *cur = rz_bin_cur (bin); RBinObject *obj = NULL; name = !name && cur? cur->file: name; - RBinFile *binfile = r_bin_file_find_by_arch_bits (bin, arch, bits); + RBinFile *binfile = rz_bin_file_find_by_arch_bits (bin, arch, bits); if (binfile && name) { - obj = r_bin_object_find_by_arch_bits (binfile, arch, bits, name); + obj = rz_bin_object_find_by_arch_bits (binfile, arch, bits, name); } - return r_bin_file_set_obj (bin, binfile, obj); + return rz_bin_file_set_obj (bin, binfile, obj); } -R_API int r_bin_select_object(RBinFile *binfile, const char *arch, int bits, const char *name) { - r_return_val_if_fail (binfile, false); - RBinObject *obj = r_bin_object_find_by_arch_bits (binfile, arch, bits, name); - return r_bin_file_set_obj (binfile->rbin, binfile, obj); +RZ_API int rz_bin_select_object(RBinFile *binfile, const char *arch, int bits, const char *name) { + rz_return_val_if_fail (binfile, false); + RBinObject *obj = rz_bin_object_find_by_arch_bits (binfile, arch, bits, name); + return rz_bin_file_set_obj (binfile->rbin, binfile, obj); } // NOTE: this functiona works as expected, but we need to merge bfid and boid -R_API bool r_bin_select_bfid (RBin *bin, ut32 bf_id) { - r_return_val_if_fail (bin, false); - RBinFile *bf = r_bin_file_find_by_id (bin, bf_id); - return bf? r_bin_file_set_obj (bin, bf, NULL): false; +RZ_API bool rz_bin_select_bfid (RBin *bin, ut32 bf_id) { + rz_return_val_if_fail (bin, false); + RBinFile *bf = rz_bin_file_find_by_id (bin, bf_id); + return bf? rz_bin_file_set_obj (bin, bf, NULL): false; } static void list_xtr_archs(RBin *bin, int mode) { - RBinFile *binfile = r_bin_cur (bin); + RBinFile *binfile = rz_bin_cur (bin); if (binfile->xtr_data) { - RListIter *iter_xtr; + RzListIter *iter_xtr; RBinXtrData *xtr_data; int bits, i = 0; char *arch, *machine; @@ -953,7 +953,7 @@ static void list_xtr_archs(RBin *bin, int mode) { bin->cb_printf ("\"bins\":["); } - r_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) { + rz_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) { if (!xtr_data || !xtr_data->metadata || !xtr_data->metadata->arch) { continue; @@ -998,32 +998,32 @@ static void list_xtr_archs(RBin *bin, int mode) { } } -R_API void r_bin_list_archs(RBin *bin, int mode) { - r_return_if_fail (bin); +RZ_API void rz_bin_list_archs(RBin *bin, int mode) { + rz_return_if_fail (bin); int i = 0; char unk[128]; char archline[256]; - RBinFile *binfile = r_bin_cur (bin); - RTable *table = r_table_new (); + RBinFile *binfile = rz_bin_cur (bin); + RTable *table = rz_table_new (); const char *name = binfile? binfile->file: NULL; int narch = binfile? binfile->narch: 0; //are we with xtr format? if (binfile && binfile->curxtr) { list_xtr_archs (bin, mode); - r_table_free (table); + rz_table_free (table); return; } Sdb *binfile_sdb = binfile? binfile->sdb: NULL; if (!binfile_sdb) { // eprintf ("Cannot find SDB!\n"); - r_table_free (table); + rz_table_free (table); return; } if (!binfile) { // eprintf ("Binary format not currently loaded!\n"); - r_table_free (table); + rz_table_free (table); return; } sdb_unset (binfile_sdb, ARCHS_KEY, 0); @@ -1033,10 +1033,10 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { pj_k (pj, "bins"); pj_a (pj); } - RBinFile *nbinfile = r_bin_file_find_by_name_n (bin, name, i); + RBinFile *nbinfile = rz_bin_file_find_by_name_n (bin, name, i); if (!nbinfile) { pj_free (pj); - r_table_free (table); + rz_table_free (table); return; } i = -1; @@ -1054,8 +1054,8 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { snprintf (unk, sizeof (unk), "unk_%d", i); arch = unk; } - r_table_hide_header (table); - r_table_set_columnsf (table, "nXnss", "num", "offset", "size", "arch", "machine", NULL); + rz_table_hide_header (table); + rz_table_set_columnsf (table, "nXnss", "num", "offset", "size", "arch", "machine", NULL); if (info && narch > 1) { switch (mode) { @@ -1080,8 +1080,8 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { default: str_fmt = h_flag && strcmp (h_flag, "unknown_flag")? sdb_fmt ("%s_%i %s", arch, bits, h_flag) \ : sdb_fmt ("%s_%i", arch, bits); - r_table_add_rowf (table, "nXnss", i, boffset, obj_size, str_fmt , machine); - bin->cb_printf ("%s\n", r_table_tostring(table)); + rz_table_add_rowf (table, "nXnss", i, boffset, obj_size, str_fmt , machine); + bin->cb_printf ("%s\n", rz_table_tostring(table)); } snprintf (archline, sizeof (archline) - 1, "0x%08" PFMT64x ":%" PFMT64u ":%s:%d:%s", @@ -1112,8 +1112,8 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { default: str_fmt = h_flag && strcmp (h_flag, "unknown_flag")? sdb_fmt ("%s_%i %s", arch, bits, h_flag) \ : sdb_fmt ("%s_%i", arch, bits); - r_table_add_rowf (table, "nsnss", i, sdb_fmt ("0x%08" PFMT64x , boffset), obj_size, str_fmt, ""); - bin->cb_printf ("%s\n", r_table_tostring(table)); + rz_table_add_rowf (table, "nsnss", i, sdb_fmt ("0x%08" PFMT64x , boffset), obj_size, str_fmt, ""); + bin->cb_printf ("%s\n", rz_table_tostring(table)); } snprintf (archline, sizeof (archline), "0x%08" PFMT64x ":%" PFMT64u ":%s:%d", @@ -1135,8 +1135,8 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { pj_end (pj); break; default: - r_table_add_rowf (table, "nsnss", i, sdb_fmt ("0x%08" PFMT64x , boffset), obj_size, "", ""); - bin->cb_printf ("%s\n", r_table_tostring(table)); + rz_table_add_rowf (table, "nsnss", i, sdb_fmt ("0x%08" PFMT64x , boffset), obj_size, "", ""); + bin->cb_printf ("%s\n", rz_table_tostring(table)); } snprintf (archline, sizeof (archline), "0x%08" PFMT64x ":%" PFMT64u ":%s:%d", @@ -1155,40 +1155,40 @@ R_API void r_bin_list_archs(RBin *bin, int mode) { } } pj_free (pj); - r_table_free (table); + rz_table_free (table); } -R_API void r_bin_set_user_ptr(RBin *bin, void *user) { +RZ_API void rz_bin_set_user_ptr(RBin *bin, void *user) { bin->user = user; } static RBinSection* __get_vsection_at(RBin *bin, ut64 vaddr) { - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); if (!bin->cur) { return NULL; } - return r_bin_get_section_at (bin->cur->o, vaddr, true); + return rz_bin_get_section_at (bin->cur->o, vaddr, true); } -R_API void r_bin_bind(RBin *bin, RBinBind *b) { +RZ_API void rz_bin_bind(RBin *bin, RBinBind *b) { if (b) { b->bin = bin; b->get_offset = __getoffset; b->get_name = __getname; - b->get_sections = r_bin_get_sections; + b->get_sections = rz_bin_get_sections; b->get_vsect_at = __get_vsection_at; - b->demangle = r_bin_demangle; + b->demangle = rz_bin_demangle; } } -R_API RBuffer *r_bin_create(RBin *bin, const char *p, +RZ_API RBuffer *rz_bin_create(RBin *bin, const char *p, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { - r_return_val_if_fail (bin && p && opt, NULL); + rz_return_val_if_fail (bin && p && opt, NULL); - RBinPlugin *plugin = r_bin_get_binplugin_by_name (bin, p); + RBinPlugin *plugin = rz_bin_get_binplugin_by_name (bin, p); if (!plugin) { R_LOG_WARN ("Cannot find RBin plugin named '%s'.\n", p); return NULL; @@ -1202,33 +1202,33 @@ R_API RBuffer *r_bin_create(RBin *bin, const char *p, return plugin->create (bin, code, codelen, data, datalen, opt); } -R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RList *files) { +RZ_API RBuffer *rz_bin_package(RBin *bin, const char *type, const char *file, RzList *files) { if (!strcmp (type, "zip")) { // XXX: implement me - r_warn_if_reached (); + rz_warn_if_reached (); } else if (!strcmp (type, "fat")) { // XXX: this should be implemented in the fat plugin, not here // XXX should pick the callback from the plugin list const char *f; - RListIter *iter; + RzListIter *iter; ut32 num; ut8 *num8 = (ut8*)# - RBuffer *buf = r_buf_new_file (file, O_RDWR | O_CREAT, 0644); + RBuffer *buf = rz_buf_new_file (file, O_RDWR | O_CREAT, 0644); if (!buf) { eprintf ("Cannot open file %s - Permission Denied.\n", file); return NULL; } - r_buf_write_at (buf, 0, (const ut8*)"\xca\xfe\xba\xbe", 4); - int count = r_list_length (files); + rz_buf_write_at (buf, 0, (const ut8*)"\xca\xfe\xba\xbe", 4); + int count = rz_list_length (files); - num = r_read_be32 (&count); + num = rz_read_be32 (&count); ut64 from = 0x1000; - r_buf_write_at (buf, 4, num8, 4); + rz_buf_write_at (buf, 4, num8, 4); int off = 12; int item = 0; - r_list_foreach (files, iter, f) { + rz_list_foreach (files, iter, f) { size_t f_len = 0; - ut8 *f_buf = (ut8 *)r_file_slurp (f, &f_len); + ut8 *f_buf = (ut8 *)rz_file_slurp (f, &f_len); if (f_buf) { eprintf ("ADD %s %"PFMT64u"\n", f, (ut64)f_len); } else { @@ -1242,43 +1242,43 @@ R_API RBuffer *r_bin_package(RBin *bin, const char *type, const char *file, RLis num8[1] = f_buf[6]; num8[2] = f_buf[5]; num8[3] = f_buf[4]; - r_buf_write_at (buf, off - 4, num8, 4); + rz_buf_write_at (buf, off - 4, num8, 4); /* SUBTYPE */ num8[0] = f_buf[11]; num8[1] = f_buf[10]; num8[2] = f_buf[9]; num8[3] = f_buf[8]; - r_buf_write_at (buf, off, num8, 4); + rz_buf_write_at (buf, off, num8, 4); ut32 from32 = from; /* FROM */ - num = r_read_be32 (&from32); - r_buf_write_at (buf, off + 4, num8, 4); - r_buf_write_at (buf, from, f_buf, f_len); + num = rz_read_be32 (&from32); + rz_buf_write_at (buf, off + 4, num8, 4); + rz_buf_write_at (buf, from, f_buf, f_len); /* SIZE */ - num = r_read_be32 (&f_len); - r_buf_write_at (buf, off + 8, num8, 4); + num = rz_read_be32 (&f_len); + rz_buf_write_at (buf, off + 8, num8, 4); off += 20; from += f_len + (f_len % 0x1000); free (f_buf); } - r_buf_free (buf); + rz_buf_free (buf); return NULL; } else { - eprintf ("Usage: rabin2 -X [fat|zip] [filename] [files ...]\n"); + eprintf ("Usage: rz-bin -X [fat|zip] [filename] [files ...]\n"); } return NULL; } -R_API RList * /**/ r_bin_get_classes(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinObject *o = r_bin_cur_object (bin); +RZ_API RzList * /**/ rz_bin_get_classes(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->classes : NULL; } /* returns vaddr, rebased with the baseaddr of bin, if va is enabled for bin, * paddr otherwise */ -R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) { - r_return_val_if_fail (bin && paddr != UT64_MAX, UT64_MAX); +RZ_API ut64 rz_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) { + rz_return_val_if_fail (bin && paddr != UT64_MAX, UT64_MAX); if (!bin->cur) { return paddr; @@ -1286,7 +1286,7 @@ R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) { /* hack to realign thumb symbols */ if (bin->cur->o && bin->cur->o->info && bin->cur->o->info->arch) { if (bin->cur->o->info->bits == 16) { - RBinSection *s = r_bin_get_section_at (bin->cur->o, paddr, false); + RBinSection *s = rz_bin_get_section_at (bin->cur->o, paddr, false); // autodetect thumb if (s && (s->perm & R_PERM_X) && strstr (s->name, "text")) { if (!strcmp (bin->cur->o->info->arch, "arm") && (vaddr & 1)) { @@ -1295,39 +1295,39 @@ R_API ut64 r_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr) { } } } - return r_bin_file_get_vaddr (bin->cur, paddr, vaddr); + return rz_bin_file_get_vaddr (bin->cur, paddr, vaddr); } -R_API ut64 r_bin_a2b(RBin *bin, ut64 addr) { - r_return_val_if_fail (bin, UT64_MAX); - RBinObject *o = r_bin_cur_object (bin); +RZ_API ut64 rz_bin_a2b(RBin *bin, ut64 addr) { + rz_return_val_if_fail (bin, UT64_MAX); + RBinObject *o = rz_bin_cur_object (bin); return binobj_a2b (o, addr); } -R_API ut64 r_bin_get_size(RBin *bin) { - r_return_val_if_fail (bin, UT64_MAX); - RBinObject *o = r_bin_cur_object (bin); +RZ_API ut64 rz_bin_get_size(RBin *bin) { + rz_return_val_if_fail (bin, UT64_MAX); + RBinObject *o = rz_bin_cur_object (bin); return o ? o->size : 0; } -R_API RBinFile *r_bin_cur(RBin *bin) { - r_return_val_if_fail (bin, NULL); +RZ_API RBinFile *rz_bin_cur(RBin *bin) { + rz_return_val_if_fail (bin, NULL); return bin->cur; } -R_API RBinObject *r_bin_cur_object(RBin *bin) { - r_return_val_if_fail (bin, NULL); - RBinFile *binfile = r_bin_cur (bin); +RZ_API RBinObject *rz_bin_cur_object(RBin *bin) { + rz_return_val_if_fail (bin, NULL); + RBinFile *binfile = rz_bin_cur (bin); return binfile ? binfile->o : NULL; } -R_API void r_bin_force_plugin(RBin *bin, const char *name) { - r_return_if_fail (bin); +RZ_API void rz_bin_force_plugin(RBin *bin, const char *name) { + rz_return_if_fail (bin); free (bin->force); bin->force = (name && *name) ? strdup (name) : NULL; } -R_API const char *r_bin_entry_type_string(int etype) { +RZ_API const char *rz_bin_entry_type_string(int etype) { switch (etype) { case R_BIN_ENTRY_TYPE_PROGRAM: return "program"; @@ -1345,12 +1345,12 @@ R_API const char *r_bin_entry_type_string(int etype) { return NULL; } -R_API void r_bin_load_filter(RBin *bin, ut64 rules) { +RZ_API void rz_bin_load_filter(RBin *bin, ut64 rules) { bin->filter_rules = rules; } /* RBinField */ -R_API RBinField *r_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named) { +RZ_API RBinField *rz_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named) { RBinField *ptr = R_NEW0 (RBinField); if (ptr) { ptr->name = strdup (name); @@ -1365,8 +1365,8 @@ R_API RBinField *r_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *n return ptr; } -// use void* to honor the RListFree signature -R_API void r_bin_field_free(void *_field) { +// use void* to honor the RzListFree signature +RZ_API void rz_bin_field_free(void *_field) { RBinField *field = (RBinField*) _field; if (field) { free (field->name); @@ -1378,7 +1378,7 @@ R_API void r_bin_field_free(void *_field) { // method name too long // RBin.methFlagToString(RBin.Method.CLASS) -R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact) { +RZ_API const char *rz_bin_get_meth_flag_string(ut64 flag, bool compact) { switch (flag) { case R_BIN_METH_CLASS: return compact ? "c" : "class"; @@ -1429,7 +1429,7 @@ R_API const char *r_bin_get_meth_flag_string(ut64 flag, bool compact) { } } -R_IPI RBinSection *r_bin_section_new(const char *name) { +R_IPI RBinSection *rz_bin_section_new(const char *name) { RBinSection *s = R_NEW0 (RBinSection); if (s) { s->name = name? strdup (name): NULL; @@ -1437,7 +1437,7 @@ R_IPI RBinSection *r_bin_section_new(const char *name) { return s; } -R_IPI void r_bin_section_free(RBinSection *bs) { +R_IPI void rz_bin_section_free(RBinSection *bs) { if (bs) { free (bs->name); free (bs->format); @@ -1445,14 +1445,14 @@ R_IPI void r_bin_section_free(RBinSection *bs) { } } -R_API RBinFile *r_bin_file_at(RBin *bin, ut64 at) { - RListIter *it, *it2; +RZ_API RBinFile *rz_bin_file_at(RBin *bin, ut64 at) { + RzListIter *it, *it2; RBinFile *bf; RBinSection *s; - r_list_foreach (bin->binfiles, it, bf) { + rz_list_foreach (bin->binfiles, it, bf) { // chk for baddr + size of no section is covering anything // we should honor maps not sections imho - r_list_foreach (bf->o->sections, it2, s) { + rz_list_foreach (bf->o->sections, it2, s) { if (at >= s->vaddr && at < (s->vaddr + s->vsize)) { return bf; } @@ -1464,7 +1464,7 @@ R_API RBinFile *r_bin_file_at(RBin *bin, ut64 at) { return NULL; } -R_API RBinTrycatch *r_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter) { +RZ_API RBinTrycatch *rz_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter) { RBinTrycatch *tc = R_NEW0 (RBinTrycatch); if (tc) { tc->source = source; @@ -1476,6 +1476,6 @@ R_API RBinTrycatch *r_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 han return tc; } -R_API void r_bin_trycatch_free(RBinTrycatch *tc) { +RZ_API void rz_bin_trycatch_free(RBinTrycatch *tc) { free (tc); } diff --git a/libr/bin/bin_ldr.c b/librz/bin/bin_ldr.c similarity index 64% rename from libr/bin/bin_ldr.c rename to librz/bin/bin_ldr.c index d2d8547c26..ace5df362e 100644 --- a/libr/bin/bin_ldr.c +++ b/librz/bin/bin_ldr.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2018 - pancake */ +/* rizin - LGPL - Copyright 2018 - pancake */ -#include +#include -R_API bool r_bin_loader(RBin *bin, ut32 boid, int options) { +RZ_API bool rz_bin_loader(RBin *bin, ut32 boid, int options) { // uses a plugin from bin.loader eval var and loads the selected binobj // options must be used to specify if we want to load the libraries of the libraries recursively // or resolve the PLT from the binary or not @@ -10,7 +10,7 @@ R_API bool r_bin_loader(RBin *bin, ut32 boid, int options) { return false; } -R_API bool r_bin_loader_library(RBin *bin, const char *name, int options) { +RZ_API bool rz_bin_loader_library(RBin *bin, const char *name, int options) { // options specify if we want to resolve the symbols and fill the PLT // this is obviously a problem if we have multiple libs that depend // on symbols recursively, and that's where the LD_BIND_NOW option comes to the action @@ -18,13 +18,13 @@ R_API bool r_bin_loader_library(RBin *bin, const char *name, int options) { return false; } -R_API bool r_bin_loader_option(RBin *bin, const char *key, const char *data) { +RZ_API bool rz_bin_loader_option(RBin *bin, const char *key, const char *data) { // key value storage to specify LD_LIBRARY_PATH LD_BIND_NOW and other useful options - // RCore or radare2 can set those vars from the environment if desired + // RzCore or rizin can set those vars from the environment if desired return false; } -R_API bool r_bin_loader_unload(RBin *bin) { +RZ_API bool rz_bin_loader_unload(RBin *bin) { // unload all libraries and drop PLT changes return false; } diff --git a/librz/bin/bin_write.c b/librz/bin/bin_write.c new file mode 100644 index 0000000000..89f03e86d6 --- /dev/null +++ b/librz/bin/bin_write.c @@ -0,0 +1,62 @@ +/* rizin - LGPL - Copyright 2009-2019 - pancake, nibble */ + +#include +#include +#include + +/* XXX Implement rz__bin_wr_scn_{ set, del } instead */ +RZ_API ut64 rz_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size) { + RBinFile *bf = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); + if (plugin && plugin->write && plugin->write->scn_resize) { + return plugin->write->scn_resize (bf, name, size); + } + return false; +} + +RZ_API bool rz_bin_wr_scn_perms(RBin *bin, const char *name, int perms) { + RBinFile *bf = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); + if (plugin && plugin->write && plugin->write->scn_perms) { + return plugin->write->scn_perms (bf, name, perms); + } + return false; +} + +RZ_API bool rz_bin_wr_rpath_del(RBin *bin) { + RBinFile *bf = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); + if (plugin && plugin->write && plugin->write->rpath_del) { + return plugin->write->rpath_del (bf); + } + return false; +} + +RZ_API bool rz_bin_wr_output(RBin *bin, const char *filename) { + rz_return_val_if_fail (bin && filename, false); + RBinFile *bf = rz_bin_cur (bin); + if (!bf || !bf->buf) { + return false; + } + ut64 tmpsz; + const ut8 *tmp = rz_buf_data (bf->buf, &tmpsz); + return rz_file_dump (filename, tmp, tmpsz, 0); +} + +RZ_API bool rz_bin_wr_entry(RBin *bin, ut64 addr) { + RBinFile *bf = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); + if (plugin && plugin->write && plugin->write->entry) { + return plugin->write->entry (bf, addr); + } + return false; +} + +RZ_API bool rz_bin_wr_addlib(RBin *bin, const char *lib) { + RBinFile *bf = rz_bin_cur (bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (bf); + if (plugin && plugin->write && plugin->write->addlib) { + return plugin->write->addlib (bin->cur, lib); + } + return false; +} diff --git a/libr/bin/blang.c b/librz/bin/blang.c similarity index 82% rename from libr/bin/blang.c rename to librz/bin/blang.c index da4b50443a..a89d438c8c 100644 --- a/libr/bin/blang.c +++ b/librz/bin/blang.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2018-2019 - pancake */ +/* rizin - LGPL - Copyright 2018-2019 - pancake */ -#include +#include typedef struct { bool rust; @@ -17,7 +17,7 @@ static inline bool check_rust(RBinSymbol *sym) { static inline bool check_objc(RBinSymbol *sym) { if (sym->name && !strncmp (sym->name, "_OBJC_", 6)) { - // free (r_bin_demangle_objc (binfile, sym->name)); + // free (rz_bin_demangle_objc (binfile, sym->name)); return true; } return false; @@ -45,7 +45,7 @@ static bool check_golang(RBinSymbol *sym) { } static inline bool is_cxx_symbol (const char *name) { - r_return_val_if_fail (name, false); + rz_return_val_if_fail (name, false); if (!strncmp (name, "_Z", 2)) { return true; } @@ -64,14 +64,14 @@ static bool check_msvc(RBinSymbol *sym) { } /* This is about 10% of the loading time, optimize if possible */ -R_API int r_bin_load_languages(RBinFile *binfile) { - r_return_val_if_fail (binfile, R_BIN_NM_NONE); - r_return_val_if_fail (binfile->o, R_BIN_NM_NONE); - r_return_val_if_fail (binfile->o->info, R_BIN_NM_NONE); +RZ_API int rz_bin_load_languages(RBinFile *binfile) { + rz_return_val_if_fail (binfile, R_BIN_NM_NONE); + rz_return_val_if_fail (binfile->o, R_BIN_NM_NONE); + rz_return_val_if_fail (binfile->o->info, R_BIN_NM_NONE); RBinObject *o = binfile->o; RBinInfo *info = o->info; RBinSymbol *sym; - RListIter *iter, *iter2; + RzListIter *iter, *iter2; Langs cantbe = {0}; bool phobosIsChecked = false; bool swiftIsChecked = false; @@ -92,7 +92,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) { } // check in imports . can be slow - r_list_foreach (o->imports, iter, sym) { + rz_list_foreach (o->imports, iter, sym) { const char *name = sym->name; if (!strcmp (name, "_NSConcreteGlobalBlock")) { isBlocks = true; @@ -102,7 +102,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) { } } - r_list_foreach (o->symbols, iter, sym) { + rz_list_foreach (o->symbols, iter, sym) { char *lib; if (!cantbe.rust) { if (check_rust (sym)) { @@ -117,7 +117,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) { if (!cantbe.swift) { bool hasswift = false; if (!swiftIsChecked) { - r_list_foreach (o->libs, iter2, lib) { + rz_list_foreach (o->libs, iter2, lib) { if (strstr (lib, "swift")) { hasswift = true; break; @@ -133,7 +133,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) { if (!cantbe.cxx) { bool hascxx = false; if (!cxxIsChecked) { - r_list_foreach (o->libs, iter2, lib) { + rz_list_foreach (o->libs, iter2, lib) { if (strstr (lib, "stdc++") || strstr (lib, "c++")) { hascxx = true; @@ -160,7 +160,7 @@ R_API int r_bin_load_languages(RBinFile *binfile) { if (!cantbe.dlang) { bool hasdlang = false; if (!phobosIsChecked) { - r_list_foreach (o->libs, iter2, lib) { + rz_list_foreach (o->libs, iter2, lib) { if (strstr (lib, "phobos")) { hasdlang = true; break; @@ -191,33 +191,33 @@ R_API int r_bin_load_languages(RBinFile *binfile) { return R_BIN_NM_C | (isBlocks?R_BIN_NM_BLOCKS:0); } -R_IPI int r_bin_lang_type(RBinFile *binfile, const char *def, const char *sym) { +R_IPI int rz_bin_lang_type(RBinFile *binfile, const char *def, const char *sym) { int type = 0; RBinPlugin *plugin; if (sym && sym[0] == sym[1] && sym[0] == '_') { type = R_BIN_NM_CXX; } if (def && *def) { - type = r_bin_demangle_type (def); + type = rz_bin_demangle_type (def); if (type != R_BIN_NM_NONE) { return type; } } - plugin = r_bin_file_cur_plugin (binfile); + plugin = rz_bin_file_cur_plugin (binfile); if (plugin && plugin->demangle_type) { type = plugin->demangle_type (def); } else { if (binfile && binfile->o && binfile->o->info) { - type = r_bin_demangle_type (binfile->o->info->lang); + type = rz_bin_demangle_type (binfile->o->info->lang); } } if (type == R_BIN_NM_NONE) { - type = r_bin_demangle_type (def); + type = rz_bin_demangle_type (def); } return type; } -R_API const char *r_bin_lang_tostring(int lang) { +RZ_API const char *rz_bin_lang_tostring(int lang) { switch (lang & 0xffff) { case R_BIN_NM_SWIFT: return "swift"; diff --git a/libr/bin/bobj.c b/librz/bin/bobj.c similarity index 66% rename from libr/bin/bobj.c rename to librz/bin/bobj.c index 59a0d0ec1a..e68f28f342 100644 --- a/libr/bin/bobj.c +++ b/librz/bin/bobj.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2009-2019 - pancake, nibble, dso */ +/* rizin - LGPL - Copyright 2009-2019 - pancake, nibble, dso */ -#include -#include +#include +#include #include "i/private.h" -R_API void r_bin_mem_free(void *data) { +RZ_API void rz_bin_mem_free(void *data) { RBinMem *mem = (RBinMem *)data; if (mem && mem->mirrors) { - mem->mirrors->free = r_bin_mem_free; - r_list_free (mem->mirrors); + mem->mirrors->free = rz_bin_mem_free; + rz_list_free (mem->mirrors); mem->mirrors = NULL; } free (mem); @@ -32,33 +32,33 @@ static void reloc_free(RBNode *rbn, void *user) { static void object_delete_items(RBinObject *o) { ut32 i = 0; - r_return_if_fail (o); - sdb_free (o->addr2klassmethod); - r_list_free (o->entries); - r_list_free (o->fields); - r_list_free (o->imports); - r_list_free (o->libs); - r_rbtree_free (o->relocs, reloc_free, NULL); - r_list_free (o->sections); - r_list_free (o->strings); + rz_return_if_fail (o); + sdb_free (o->addrzklassmethod); + rz_list_free (o->entries); + rz_list_free (o->fields); + rz_list_free (o->imports); + rz_list_free (o->libs); + rz_rbtree_free (o->relocs, reloc_free, NULL); + rz_list_free (o->sections); + rz_list_free (o->strings); ht_up_free (o->strings_db); - r_list_free (o->symbols); - r_list_free (o->classes); + rz_list_free (o->symbols); + rz_list_free (o->classes); ht_pp_free (o->classes_ht); ht_pp_free (o->methods_ht); - r_list_free (o->lines); + rz_list_free (o->lines); sdb_free (o->kv); - r_list_free (o->mem); + rz_list_free (o->mem); for (i = 0; i < R_BIN_SYM_LAST; i++) { free (o->binsym[i]); } } -R_IPI void r_bin_object_free(void /*RBinObject*/ *o_) { +R_IPI void rz_bin_object_free(void /*RBinObject*/ *o_) { RBinObject *o = o_; if (o) { free (o->regstate); - r_bin_info_free (o->info); + rz_bin_info_free (o->info); object_delete_items (o); free (o); } @@ -90,16 +90,16 @@ static char *swiftField(const char *dn, const char *cn) { return NULL; } -static RList *classes_from_symbols(RBinFile *bf) { +static RzList *classes_from_symbols(RBinFile *bf) { RBinSymbol *sym; - RListIter *iter; - r_list_foreach (bf->o->symbols, iter, sym) { + RzListIter *iter; + rz_list_foreach (bf->o->symbols, iter, sym) { if (sym->name[0] != '_') { continue; } const char *cn = sym->classname; if (cn) { - RBinClass *c = r_bin_file_add_class (bf, sym->classname, NULL, 0); + RBinClass *c = rz_bin_file_add_class (bf, sym->classname, NULL, 0); if (!c) { continue; } @@ -108,8 +108,8 @@ static RList *classes_from_symbols(RBinFile *bf) { char *fn = swiftField (dn, cn); if (fn) { // eprintf ("FIELD %s %s\n", cn, fn); - RBinField *f = r_bin_field_new (sym->paddr, sym->vaddr, sym->size, fn, NULL, NULL, false); - r_list_append (c->fields, f); + RBinField *f = rz_bin_field_new (sym->paddr, sym->vaddr, sym->size, fn, NULL, NULL, false); + rz_list_append (c->fields, f); free (fn); } else { char *mn = strstr (dn, ".."); @@ -118,7 +118,7 @@ static RList *classes_from_symbols(RBinFile *bf) { if (mn && mn[strlen (cn)] == '.') { mn += strlen (cn) + 1; // eprintf ("METHOD %s %s\n", sym->classname, mn); - r_list_append (c->methods, sym); + rz_list_append (c->methods, sym); } } } @@ -128,9 +128,9 @@ static RList *classes_from_symbols(RBinFile *bf) { } // TODO: kill offset and sz, because those should be inferred from binfile->buf -R_IPI RBinObject *r_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz) { - r_return_val_if_fail (bf && plugin, NULL); - ut64 bytes_sz = r_buf_size (bf->buf); +R_IPI RBinObject *rz_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz) { + rz_return_val_if_fail (bf && plugin, NULL); + ut64 bytes_sz = rz_buf_size (bf->buf); Sdb *sdb = bf->sdb; RBinObject *o = R_NEW0 (RBinObject); if (!o) { @@ -142,7 +142,7 @@ R_IPI RBinObject *r_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 basead o->regstate = NULL; o->kv = sdb_new0 (); // XXX bf->sdb bf->o->sdb wtf o->baddr = baseaddr; - o->classes = r_list_newf ((RListFree)r_bin_class_free); + o->classes = rz_list_newf ((RzListFree)rz_bin_class_free); o->classes_ht = ht_pp_new0 (); o->methods_ht = ht_pp_new0 (); o->baddr_shift = 0; @@ -152,7 +152,7 @@ R_IPI RBinObject *r_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 basead if (plugin && plugin->load_buffer) { if (!plugin->load_buffer (bf, &o->bin_obj, bf->buf, loadaddr, sdb)) { if (bf->rbin->verbose) { - eprintf ("Error in r_bin_object_new: load_buffer failed for %s plugin\n", plugin->name); + eprintf ("Error in rz_bin_object_new: load_buffer failed for %s plugin\n", plugin->name); } sdb_free (o->kv); free (o); @@ -169,9 +169,9 @@ R_IPI RBinObject *r_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 basead // the object is created from. The reason for this is to prevent // mis-reporting when the file is loaded from impartial bytes or is // extracted from a set of bytes in the file - r_bin_file_set_obj (bf->rbin, bf, o); - r_bin_set_baddr (bf->rbin, o->baddr); - r_bin_object_set_items (bf, o); + rz_bin_file_set_obj (bf->rbin, bf, o); + rz_bin_set_baddr (bf->rbin, o->baddr); + rz_bin_object_set_items (bf, o); bf->sdb_info = o->kv; sdb = bf->rbin->sdb; @@ -201,13 +201,13 @@ R_IPI RBinObject *r_bin_object_new(RBinFile *bf, RBinPlugin *plugin, ut64 basead return o; } -static void filter_classes(RBinFile *bf, RList *list) { +static void filter_classes(RBinFile *bf, RzList *list) { Sdb *db = sdb_new0 (); HtPP *ht = ht_pp_new0 (); - RListIter *iter, *iter2; + RzListIter *iter, *iter2; RBinClass *cls; RBinSymbol *sym; - r_list_foreach (list, iter, cls) { + rz_list_foreach (list, iter, cls) { if (!cls->name) { continue; } @@ -216,15 +216,15 @@ static void filter_classes(RBinFile *bf, RList *list) { if (namepad) { char *p; strcpy (namepad, cls->name); - p = r_bin_filter_name (bf, db, cls->index, namepad); + p = rz_bin_filter_name (bf, db, cls->index, namepad); if (p) { namepad = p; } free (cls->name); cls->name = namepad; - r_list_foreach (cls->methods, iter2, sym) { + rz_list_foreach (cls->methods, iter2, sym) { if (sym->name) { - r_bin_filter_sym (bf, ht, sym->vaddr, sym); + rz_bin_filter_sym (bf, ht, sym->vaddr, sym); } } } else { @@ -235,31 +235,31 @@ static void filter_classes(RBinFile *bf, RList *list) { ht_pp_free (ht); } -static RBNode *list2rbtree(RList *relocs) { - RListIter *it; +static RBNode *list2rbtree(RzList *relocs) { + RzListIter *it; RBinReloc *reloc; RBNode *res = NULL; - r_list_foreach (relocs, it, reloc) { - r_rbtree_insert (&res, reloc, &reloc->vrb, reloc_cmp, NULL); + rz_list_foreach (relocs, it, reloc) { + rz_rbtree_insert (&res, reloc, &reloc->vrb, reloc_cmp, NULL); } return res; } -static void r_bin_object_rebuild_classes_ht(RBinObject *o) { +static void rz_bin_object_rebuild_classes_ht(RBinObject *o) { ht_pp_free (o->classes_ht); ht_pp_free (o->methods_ht); o->classes_ht = ht_pp_new0 (); o->methods_ht = ht_pp_new0 (); - RListIter *it, *it2; + RzListIter *it, *it2; RBinClass *klass; RBinSymbol *method; - r_list_foreach (o->classes, it, klass) { + rz_list_foreach (o->classes, it, klass) { if (klass->name) { ht_pp_insert (o->classes_ht, klass->name, klass); - r_list_foreach (klass->methods, it2, method) { + rz_list_foreach (klass->methods, it2, method) { const char *name = sdb_fmt ("%s::%s", klass->name, method->name); ht_pp_insert (o->methods_ht, name, method); } @@ -267,8 +267,8 @@ static void r_bin_object_rebuild_classes_ht(RBinObject *o) { } } -R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *o) { - r_return_val_if_fail (bf && o && o->plugin, false); +RZ_API int rz_bin_object_set_items(RBinFile *bf, RBinObject *o) { + rz_return_val_if_fail (bf && o && o->plugin, false); int i; bool isSwift = false; @@ -314,24 +314,24 @@ R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *o) { if (p->fields) { o->fields = p->fields (bf); if (o->fields) { - o->fields->free = r_bin_field_free; + o->fields->free = rz_bin_field_free; REBASE_PADDR (o, o->fields, RBinField); } } if (p->imports) { - r_list_free (o->imports); + rz_list_free (o->imports); o->imports = p->imports (bf); if (o->imports) { - o->imports->free = r_bin_import_free; + o->imports->free = rz_bin_import_free; } } if (p->symbols) { o->symbols = p->symbols (bf); // 5s if (o->symbols) { - o->symbols->free = r_bin_symbol_free; + o->symbols->free = rz_bin_symbol_free; REBASE_PADDR (o, o->symbols, RBinSymbol); if (bin->filter) { - r_bin_filter_symbols (bf, o->symbols); // 5s + rz_bin_filter_symbols (bf, o->symbols); // 5s } } } @@ -346,44 +346,44 @@ R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *o) { } REBASE_PADDR (o, o->sections, RBinSection); if (bin->filter) { - r_bin_filter_sections (bf, o->sections); + rz_bin_filter_sections (bf, o->sections); } } if (bin->filter_rules & (R_BIN_REQ_RELOCS | R_BIN_REQ_IMPORTS)) { if (p->relocs) { - RList *l = p->relocs (bf); + RzList *l = p->relocs (bf); if (l) { REBASE_PADDR (o, l, RBinReloc); o->relocs = list2rbtree (l); l->free = NULL; - r_list_free (l); + rz_list_free (l); } } } if (bin->filter_rules & R_BIN_REQ_STRINGS) { o->strings = p->strings ? p->strings (bf) - : r_bin_file_get_strings (bf, minlen, 0, bf->rawstr); + : rz_bin_file_get_strings (bf, minlen, 0, bf->rawstr); if (bin->debase64) { - r_bin_object_filter_strings (o); + rz_bin_object_filter_strings (o); } REBASE_PADDR (o, o->strings, RBinString); } if (bin->filter_rules & R_BIN_REQ_CLASSES) { if (p->classes) { - RList *classes = p->classes (bf); + RzList *classes = p->classes (bf); if (classes) { // XXX we should probably merge them instead - r_list_free (o->classes); + rz_list_free (o->classes); o->classes = classes; - r_bin_object_rebuild_classes_ht (o); + rz_bin_object_rebuild_classes_ht (o); } - isSwift = r_bin_lang_swift (bf); + isSwift = rz_bin_lang_swift (bf); if (isSwift) { o->classes = classes_from_symbols (bf); } } else { - RList *classes = classes_from_symbols (bf); + RzList *classes = classes_from_symbols (bf); if (classes) { o->classes = classes; } @@ -393,18 +393,18 @@ R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *o) { } // cache addr=class+method if (o->classes) { - RList *klasses = o->classes; - RListIter *iter, *iter2; + RzList *klasses = o->classes; + RzListIter *iter, *iter2; RBinClass *klass; RBinSymbol *method; - if (!o->addr2klassmethod) { + if (!o->addrzklassmethod) { // this is slow. must be optimized, but at least its cached - o->addr2klassmethod = sdb_new0 (); - r_list_foreach (klasses, iter, klass) { - r_list_foreach (klass->methods, iter2, method) { + o->addrzklassmethod = sdb_new0 (); + rz_list_foreach (klasses, iter, klass) { + rz_list_foreach (klass->methods, iter2, method) { char *km = sdb_fmt ("method.%s.%s", klass->name, method->name); char *at = sdb_fmt ("0x%08"PFMT64x, method->vaddr); - sdb_set (o->addr2klassmethod, at, km, 0); + sdb_set (o->addrzklassmethod, at, km, 0); } } } @@ -424,25 +424,25 @@ R_API int r_bin_object_set_items(RBinFile *bf, RBinObject *o) { o->mem = p->mem (bf); } if (bin->filter_rules & (R_BIN_REQ_INFO | R_BIN_REQ_SYMBOLS | R_BIN_REQ_IMPORTS)) { - o->lang = isSwift? R_BIN_NM_SWIFT: r_bin_load_languages (bf); + o->lang = isSwift? R_BIN_NM_SWIFT: rz_bin_load_languages (bf); } return true; } -R_IPI RBNode *r_bin_object_patch_relocs(RBin *bin, RBinObject *o) { - r_return_val_if_fail (bin && o, NULL); +R_IPI RBNode *rz_bin_object_patch_relocs(RBin *bin, RBinObject *o) { + rz_return_val_if_fail (bin && o, NULL); static bool first = true; - // r_bin_object_set_items set o->relocs but there we don't have access + // rz_bin_object_set_items set o->relocs but there we don't have access // to io so we need to be run from bin_relocs, free the previous reloc and get // the patched ones if (first && o->plugin && o->plugin->patch_relocs) { - RList *tmp = o->plugin->patch_relocs (bin); + RzList *tmp = o->plugin->patch_relocs (bin); first = false; if (!tmp) { return o->relocs; } - r_rbtree_free (o->relocs, reloc_free, NULL); + rz_rbtree_free (o->relocs, reloc_free, NULL); REBASE_PADDR (o, tmp, RBinReloc); o->relocs = list2rbtree (tmp); first = false; @@ -451,13 +451,13 @@ R_IPI RBNode *r_bin_object_patch_relocs(RBin *bin, RBinObject *o) { return o->relocs; } -R_IPI RBinObject *r_bin_object_get_cur(RBin *bin) { - r_return_val_if_fail (bin && bin->cur, NULL); +R_IPI RBinObject *rz_bin_object_get_cur(RBin *bin) { + rz_return_val_if_fail (bin && bin->cur, NULL); return bin->cur->o; } -R_IPI RBinObject *r_bin_object_find_by_arch_bits(RBinFile *bf, const char *arch, int bits, const char *name) { - r_return_val_if_fail (bf && arch && name, NULL); +R_IPI RBinObject *rz_bin_object_find_by_arch_bits(RBinFile *bf, const char *arch, int bits, const char *name) { + rz_return_val_if_fail (bf && arch && name, NULL); if (bf->o) { RBinInfo *info = bf->o->info; if (info && info->arch && info->file && @@ -470,46 +470,46 @@ R_IPI RBinObject *r_bin_object_find_by_arch_bits(RBinFile *bf, const char *arch, return NULL; } -R_API bool r_bin_object_delete(RBin *bin, ut32 bf_id) { - r_return_val_if_fail (bin, false); +RZ_API bool rz_bin_object_delete(RBin *bin, ut32 bf_id) { + rz_return_val_if_fail (bin, false); bool res = false; - RBinFile *bf = r_bin_file_find_by_id (bin, bf_id); + RBinFile *bf = rz_bin_file_find_by_id (bin, bf_id); if (bf) { if (bin->cur == bf) { bin->cur = NULL; } // wtf if (!bf->o) { - r_list_delete_data (bin->binfiles, bf); + rz_list_delete_data (bin->binfiles, bf); } } return res; } -R_IPI void r_bin_object_filter_strings(RBinObject *bo) { - r_return_if_fail (bo && bo->strings); +R_IPI void rz_bin_object_filter_strings(RBinObject *bo) { + rz_return_if_fail (bo && bo->strings); - RList *strings = bo->strings; + RzList *strings = bo->strings; RBinString *ptr; - RListIter *iter; - r_list_foreach (strings, iter, ptr) { - char *dec = (char *)r_base64_decode_dyn (ptr->string, -1); + RzListIter *iter; + rz_list_foreach (strings, iter, ptr) { + char *dec = (char *)rz_base64_decode_dyn (ptr->string, -1); if (dec) { char *s = ptr->string; for (;;) { - char *dec2 = (char *)r_base64_decode_dyn (s, -1); + char *dec2 = (char *)rz_base64_decode_dyn (s, -1); if (!dec2) { break; } - if (!r_str_is_printable (dec2)) { + if (!rz_str_is_printable (dec2)) { free (dec2); break; } free (dec); s = dec = dec2; } - if (r_str_is_printable (dec) && strlen (dec) > 3) { + if (rz_str_is_printable (dec) && strlen (dec) > 3) { free (ptr->string); ptr->string = dec; ptr->type = R_STRING_TYPE_BASE64; diff --git a/libr/bin/d/Makefile b/librz/bin/d/Makefile similarity index 97% rename from libr/bin/d/Makefile rename to librz/bin/d/Makefile index 1cee5cd43e..a0d1614ee9 100644 --- a/libr/bin/d/Makefile +++ b/librz/bin/d/Makefile @@ -4,7 +4,7 @@ include ../../../config-user.mk SDBPATH=$(LTOP)/../shlr/sdb/ SDB=$(SDBPATH)/sdb -P=${DESTDIR}${DATADIR}/radare2/${VERSION}/format +P=${DESTDIR}${DATADIR}/rizin/${VERSION}/format DLLS=ws2_32 oleaut32 wsock32 msi csmfpapi msvbvm60 kernel32 DLLS+=aclui activeds atl borlndmm browseui comctl32 dsound diff --git a/libr/bin/d/bios b/librz/bin/d/bios similarity index 100% rename from libr/bin/d/bios rename to librz/bin/d/bios diff --git a/libr/bin/d/cdex.h b/librz/bin/d/cdex.h similarity index 100% rename from libr/bin/d/cdex.h rename to librz/bin/d/cdex.h diff --git a/libr/bin/d/dex b/librz/bin/d/dex similarity index 100% rename from libr/bin/d/dex rename to librz/bin/d/dex diff --git a/libr/bin/d/dex.h b/librz/bin/d/dex.h similarity index 100% rename from libr/bin/d/dex.h rename to librz/bin/d/dex.h diff --git a/libr/bin/d/dll/AVICAP.sdb.txt b/librz/bin/d/dll/AVICAP.sdb.txt similarity index 100% rename from libr/bin/d/dll/AVICAP.sdb.txt rename to librz/bin/d/dll/AVICAP.sdb.txt diff --git a/libr/bin/d/dll/AVIFILE.sdb.txt b/librz/bin/d/dll/AVIFILE.sdb.txt similarity index 100% rename from libr/bin/d/dll/AVIFILE.sdb.txt rename to librz/bin/d/dll/AVIFILE.sdb.txt diff --git a/libr/bin/d/dll/AWDEVL16.sdb.txt b/librz/bin/d/dll/AWDEVL16.sdb.txt similarity index 100% rename from libr/bin/d/dll/AWDEVL16.sdb.txt rename to librz/bin/d/dll/AWDEVL16.sdb.txt diff --git a/libr/bin/d/dll/CARDS.sdb.txt b/librz/bin/d/dll/CARDS.sdb.txt similarity index 100% rename from libr/bin/d/dll/CARDS.sdb.txt rename to librz/bin/d/dll/CARDS.sdb.txt diff --git a/libr/bin/d/dll/CMC.sdb.txt b/librz/bin/d/dll/CMC.sdb.txt similarity index 100% rename from libr/bin/d/dll/CMC.sdb.txt rename to librz/bin/d/dll/CMC.sdb.txt diff --git a/libr/bin/d/dll/COMM.sdb.txt b/librz/bin/d/dll/COMM.sdb.txt similarity index 100% rename from libr/bin/d/dll/COMM.sdb.txt rename to librz/bin/d/dll/COMM.sdb.txt diff --git a/libr/bin/d/dll/COMMCTRL.sdb.txt b/librz/bin/d/dll/COMMCTRL.sdb.txt similarity index 100% rename from libr/bin/d/dll/COMMCTRL.sdb.txt rename to librz/bin/d/dll/COMMCTRL.sdb.txt diff --git a/libr/bin/d/dll/COMMDLG.sdb.txt b/librz/bin/d/dll/COMMDLG.sdb.txt similarity index 100% rename from libr/bin/d/dll/COMMDLG.sdb.txt rename to librz/bin/d/dll/COMMDLG.sdb.txt diff --git a/libr/bin/d/dll/COMPOBJ.sdb.txt b/librz/bin/d/dll/COMPOBJ.sdb.txt similarity index 100% rename from libr/bin/d/dll/COMPOBJ.sdb.txt rename to librz/bin/d/dll/COMPOBJ.sdb.txt diff --git a/libr/bin/d/dll/CSPMAN.sdb.txt b/librz/bin/d/dll/CSPMAN.sdb.txt similarity index 100% rename from libr/bin/d/dll/CSPMAN.sdb.txt rename to librz/bin/d/dll/CSPMAN.sdb.txt diff --git a/libr/bin/d/dll/DCIMAN.sdb.txt b/librz/bin/d/dll/DCIMAN.sdb.txt similarity index 100% rename from libr/bin/d/dll/DCIMAN.sdb.txt rename to librz/bin/d/dll/DCIMAN.sdb.txt diff --git a/libr/bin/d/dll/DDEML.sdb.txt b/librz/bin/d/dll/DDEML.sdb.txt similarity index 100% rename from libr/bin/d/dll/DDEML.sdb.txt rename to librz/bin/d/dll/DDEML.sdb.txt diff --git a/libr/bin/d/dll/DESKCP16.sdb.txt b/librz/bin/d/dll/DESKCP16.sdb.txt similarity index 100% rename from libr/bin/d/dll/DESKCP16.sdb.txt rename to librz/bin/d/dll/DESKCP16.sdb.txt diff --git a/libr/bin/d/dll/DIBENG.sdb.txt b/librz/bin/d/dll/DIBENG.sdb.txt similarity index 100% rename from libr/bin/d/dll/DIBENG.sdb.txt rename to librz/bin/d/dll/DIBENG.sdb.txt diff --git a/libr/bin/d/dll/DISPDIB.sdb.txt b/librz/bin/d/dll/DISPDIB.sdb.txt similarity index 100% rename from libr/bin/d/dll/DISPDIB.sdb.txt rename to librz/bin/d/dll/DISPDIB.sdb.txt diff --git a/libr/bin/d/dll/DISPLAY.sdb.txt b/librz/bin/d/dll/DISPLAY.sdb.txt similarity index 100% rename from libr/bin/d/dll/DISPLAY.sdb.txt rename to librz/bin/d/dll/DISPLAY.sdb.txt diff --git a/libr/bin/d/dll/DSKMAINT.sdb.txt b/librz/bin/d/dll/DSKMAINT.sdb.txt similarity index 100% rename from libr/bin/d/dll/DSKMAINT.sdb.txt rename to librz/bin/d/dll/DSKMAINT.sdb.txt diff --git a/libr/bin/d/dll/ENABLE3.sdb.txt b/librz/bin/d/dll/ENABLE3.sdb.txt similarity index 100% rename from libr/bin/d/dll/ENABLE3.sdb.txt rename to librz/bin/d/dll/ENABLE3.sdb.txt diff --git a/libr/bin/d/dll/FAXCODEC.sdb.txt b/librz/bin/d/dll/FAXCODEC.sdb.txt similarity index 100% rename from libr/bin/d/dll/FAXCODEC.sdb.txt rename to librz/bin/d/dll/FAXCODEC.sdb.txt diff --git a/libr/bin/d/dll/GDI.sdb.txt b/librz/bin/d/dll/GDI.sdb.txt similarity index 100% rename from libr/bin/d/dll/GDI.sdb.txt rename to librz/bin/d/dll/GDI.sdb.txt diff --git a/libr/bin/d/dll/INET16.sdb.txt b/librz/bin/d/dll/INET16.sdb.txt similarity index 100% rename from libr/bin/d/dll/INET16.sdb.txt rename to librz/bin/d/dll/INET16.sdb.txt diff --git a/libr/bin/d/dll/IOSCLASS.sdb.txt b/librz/bin/d/dll/IOSCLASS.sdb.txt similarity index 100% rename from libr/bin/d/dll/IOSCLASS.sdb.txt rename to librz/bin/d/dll/IOSCLASS.sdb.txt diff --git a/libr/bin/d/dll/KERNEL.sdb.txt b/librz/bin/d/dll/KERNEL.sdb.txt similarity index 100% rename from libr/bin/d/dll/KERNEL.sdb.txt rename to librz/bin/d/dll/KERNEL.sdb.txt diff --git a/libr/bin/d/dll/KEYBOARD.sdb.txt b/librz/bin/d/dll/KEYBOARD.sdb.txt similarity index 100% rename from libr/bin/d/dll/KEYBOARD.sdb.txt rename to librz/bin/d/dll/KEYBOARD.sdb.txt diff --git a/libr/bin/d/dll/LZEXPAND.sdb.txt b/librz/bin/d/dll/LZEXPAND.sdb.txt similarity index 100% rename from libr/bin/d/dll/LZEXPAND.sdb.txt rename to librz/bin/d/dll/LZEXPAND.sdb.txt diff --git a/libr/bin/d/dll/MAINCP16.sdb.txt b/librz/bin/d/dll/MAINCP16.sdb.txt similarity index 100% rename from libr/bin/d/dll/MAINCP16.sdb.txt rename to librz/bin/d/dll/MAINCP16.sdb.txt diff --git a/libr/bin/d/dll/MAPI.sdb.txt b/librz/bin/d/dll/MAPI.sdb.txt similarity index 100% rename from libr/bin/d/dll/MAPI.sdb.txt rename to librz/bin/d/dll/MAPI.sdb.txt diff --git a/libr/bin/d/dll/MAPIU.sdb.txt b/librz/bin/d/dll/MAPIU.sdb.txt similarity index 100% rename from libr/bin/d/dll/MAPIU.sdb.txt rename to librz/bin/d/dll/MAPIU.sdb.txt diff --git a/libr/bin/d/dll/MAPIX.sdb.txt b/librz/bin/d/dll/MAPIX.sdb.txt similarity index 100% rename from libr/bin/d/dll/MAPIX.sdb.txt rename to librz/bin/d/dll/MAPIX.sdb.txt diff --git a/libr/bin/d/dll/MCIAVI.sdb.txt b/librz/bin/d/dll/MCIAVI.sdb.txt similarity index 100% rename from libr/bin/d/dll/MCIAVI.sdb.txt rename to librz/bin/d/dll/MCIAVI.sdb.txt diff --git a/libr/bin/d/dll/MCICDA.sdb.txt b/librz/bin/d/dll/MCICDA.sdb.txt similarity index 100% rename from libr/bin/d/dll/MCICDA.sdb.txt rename to librz/bin/d/dll/MCICDA.sdb.txt diff --git a/libr/bin/d/dll/MCIMIDI.sdb.txt b/librz/bin/d/dll/MCIMIDI.sdb.txt similarity index 100% rename from libr/bin/d/dll/MCIMIDI.sdb.txt rename to librz/bin/d/dll/MCIMIDI.sdb.txt diff --git a/libr/bin/d/dll/MCIOLE.sdb.txt b/librz/bin/d/dll/MCIOLE.sdb.txt similarity index 100% rename from libr/bin/d/dll/MCIOLE.sdb.txt rename to librz/bin/d/dll/MCIOLE.sdb.txt diff --git a/libr/bin/d/dll/MCIWAVE.sdb.txt b/librz/bin/d/dll/MCIWAVE.sdb.txt similarity index 100% rename from libr/bin/d/dll/MCIWAVE.sdb.txt rename to librz/bin/d/dll/MCIWAVE.sdb.txt diff --git a/libr/bin/d/dll/MIDIMAP.sdb.txt b/librz/bin/d/dll/MIDIMAP.sdb.txt similarity index 100% rename from libr/bin/d/dll/MIDIMAP.sdb.txt rename to librz/bin/d/dll/MIDIMAP.sdb.txt diff --git a/libr/bin/d/dll/ML3XEC16.sdb.txt b/librz/bin/d/dll/ML3XEC16.sdb.txt similarity index 100% rename from libr/bin/d/dll/ML3XEC16.sdb.txt rename to librz/bin/d/dll/ML3XEC16.sdb.txt diff --git a/libr/bin/d/dll/MMCI.sdb.txt b/librz/bin/d/dll/MMCI.sdb.txt similarity index 100% rename from libr/bin/d/dll/MMCI.sdb.txt rename to librz/bin/d/dll/MMCI.sdb.txt diff --git a/libr/bin/d/dll/MMSYSTEM.sdb.txt b/librz/bin/d/dll/MMSYSTEM.sdb.txt similarity index 100% rename from libr/bin/d/dll/MMSYSTEM.sdb.txt rename to librz/bin/d/dll/MMSYSTEM.sdb.txt diff --git a/libr/bin/d/dll/MODEM.sdb.txt b/librz/bin/d/dll/MODEM.sdb.txt similarity index 100% rename from libr/bin/d/dll/MODEM.sdb.txt rename to librz/bin/d/dll/MODEM.sdb.txt diff --git a/libr/bin/d/dll/MODEMUI.sdb.txt b/librz/bin/d/dll/MODEMUI.sdb.txt similarity index 100% rename from libr/bin/d/dll/MODEMUI.sdb.txt rename to librz/bin/d/dll/MODEMUI.sdb.txt diff --git a/libr/bin/d/dll/MOUSE.sdb.txt b/librz/bin/d/dll/MOUSE.sdb.txt similarity index 100% rename from libr/bin/d/dll/MOUSE.sdb.txt rename to librz/bin/d/dll/MOUSE.sdb.txt diff --git a/libr/bin/d/dll/MSACM.sdb.txt b/librz/bin/d/dll/MSACM.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSACM.sdb.txt rename to librz/bin/d/dll/MSACM.sdb.txt diff --git a/libr/bin/d/dll/MSACMMAP.sdb.txt b/librz/bin/d/dll/MSACMMAP.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSACMMAP.sdb.txt rename to librz/bin/d/dll/MSACMMAP.sdb.txt diff --git a/libr/bin/d/dll/MSDOS.sdb.txt b/librz/bin/d/dll/MSDOS.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSDOS.sdb.txt rename to librz/bin/d/dll/MSDOS.sdb.txt diff --git a/libr/bin/d/dll/MSDOSD.sdb.txt b/librz/bin/d/dll/MSDOSD.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSDOSD.sdb.txt rename to librz/bin/d/dll/MSDOSD.sdb.txt diff --git a/libr/bin/d/dll/MSGSRV32.sdb.txt b/librz/bin/d/dll/MSGSRV32.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSGSRV32.sdb.txt rename to librz/bin/d/dll/MSGSRV32.sdb.txt diff --git a/libr/bin/d/dll/MSJSTICK.sdb.txt b/librz/bin/d/dll/MSJSTICK.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSJSTICK.sdb.txt rename to librz/bin/d/dll/MSJSTICK.sdb.txt diff --git a/libr/bin/d/dll/MSMIXMGR.sdb.txt b/librz/bin/d/dll/MSMIXMGR.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSMIXMGR.sdb.txt rename to librz/bin/d/dll/MSMIXMGR.sdb.txt diff --git a/libr/bin/d/dll/MSPCIC.sdb.txt b/librz/bin/d/dll/MSPCIC.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSPCIC.sdb.txt rename to librz/bin/d/dll/MSPCIC.sdb.txt diff --git a/libr/bin/d/dll/MSPRINT.sdb.txt b/librz/bin/d/dll/MSPRINT.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSPRINT.sdb.txt rename to librz/bin/d/dll/MSPRINT.sdb.txt diff --git a/libr/bin/d/dll/MSTCP.sdb.txt b/librz/bin/d/dll/MSTCP.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSTCP.sdb.txt rename to librz/bin/d/dll/MSTCP.sdb.txt diff --git a/libr/bin/d/dll/MSVIDEO.sdb.txt b/librz/bin/d/dll/MSVIDEO.sdb.txt similarity index 100% rename from libr/bin/d/dll/MSVIDEO.sdb.txt rename to librz/bin/d/dll/MSVIDEO.sdb.txt diff --git a/libr/bin/d/dll/NETAPI.sdb.txt b/librz/bin/d/dll/NETAPI.sdb.txt similarity index 100% rename from libr/bin/d/dll/NETAPI.sdb.txt rename to librz/bin/d/dll/NETAPI.sdb.txt diff --git a/libr/bin/d/dll/NETCPL.sdb.txt b/librz/bin/d/dll/NETCPL.sdb.txt similarity index 100% rename from libr/bin/d/dll/NETCPL.sdb.txt rename to librz/bin/d/dll/NETCPL.sdb.txt diff --git a/libr/bin/d/dll/NETDI.sdb.txt b/librz/bin/d/dll/NETDI.sdb.txt similarity index 100% rename from libr/bin/d/dll/NETDI.sdb.txt rename to librz/bin/d/dll/NETDI.sdb.txt diff --git a/libr/bin/d/dll/NETOS.sdb.txt b/librz/bin/d/dll/NETOS.sdb.txt similarity index 100% rename from libr/bin/d/dll/NETOS.sdb.txt rename to librz/bin/d/dll/NETOS.sdb.txt diff --git a/libr/bin/d/dll/NETWARE.sdb.txt b/librz/bin/d/dll/NETWARE.sdb.txt similarity index 100% rename from libr/bin/d/dll/NETWARE.sdb.txt rename to librz/bin/d/dll/NETWARE.sdb.txt diff --git a/libr/bin/d/dll/NW16.sdb.txt b/librz/bin/d/dll/NW16.sdb.txt similarity index 100% rename from libr/bin/d/dll/NW16.sdb.txt rename to librz/bin/d/dll/NW16.sdb.txt diff --git a/libr/bin/d/dll/OLE2.sdb.txt b/librz/bin/d/dll/OLE2.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLE2.sdb.txt rename to librz/bin/d/dll/OLE2.sdb.txt diff --git a/libr/bin/d/dll/OLE2CONV.sdb.txt b/librz/bin/d/dll/OLE2CONV.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLE2CONV.sdb.txt rename to librz/bin/d/dll/OLE2CONV.sdb.txt diff --git a/libr/bin/d/dll/OLE2DISP.sdb.txt b/librz/bin/d/dll/OLE2DISP.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLE2DISP.sdb.txt rename to librz/bin/d/dll/OLE2DISP.sdb.txt diff --git a/libr/bin/d/dll/OLE2NLS.sdb.txt b/librz/bin/d/dll/OLE2NLS.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLE2NLS.sdb.txt rename to librz/bin/d/dll/OLE2NLS.sdb.txt diff --git a/libr/bin/d/dll/OLECLI.sdb.txt b/librz/bin/d/dll/OLECLI.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLECLI.sdb.txt rename to librz/bin/d/dll/OLECLI.sdb.txt diff --git a/libr/bin/d/dll/OLESVR.sdb.txt b/librz/bin/d/dll/OLESVR.sdb.txt similarity index 100% rename from libr/bin/d/dll/OLESVR.sdb.txt rename to librz/bin/d/dll/OLESVR.sdb.txt diff --git a/libr/bin/d/dll/PIFMGR.sdb.txt b/librz/bin/d/dll/PIFMGR.sdb.txt similarity index 100% rename from libr/bin/d/dll/PIFMGR.sdb.txt rename to librz/bin/d/dll/PIFMGR.sdb.txt diff --git a/libr/bin/d/dll/PKPD.sdb.txt b/librz/bin/d/dll/PKPD.sdb.txt similarity index 100% rename from libr/bin/d/dll/PKPD.sdb.txt rename to librz/bin/d/dll/PKPD.sdb.txt diff --git a/libr/bin/d/dll/PMSPL.sdb.txt b/librz/bin/d/dll/PMSPL.sdb.txt similarity index 100% rename from libr/bin/d/dll/PMSPL.sdb.txt rename to librz/bin/d/dll/PMSPL.sdb.txt diff --git a/libr/bin/d/dll/POWER.sdb.txt b/librz/bin/d/dll/POWER.sdb.txt similarity index 100% rename from libr/bin/d/dll/POWER.sdb.txt rename to librz/bin/d/dll/POWER.sdb.txt diff --git a/libr/bin/d/dll/RASAPI16.sdb.txt b/librz/bin/d/dll/RASAPI16.sdb.txt similarity index 100% rename from libr/bin/d/dll/RASAPI16.sdb.txt rename to librz/bin/d/dll/RASAPI16.sdb.txt diff --git a/libr/bin/d/dll/README.txt b/librz/bin/d/dll/README.txt similarity index 100% rename from libr/bin/d/dll/README.txt rename to librz/bin/d/dll/README.txt diff --git a/libr/bin/d/dll/RNASETUP.sdb.txt b/librz/bin/d/dll/RNASETUP.sdb.txt similarity index 100% rename from libr/bin/d/dll/RNASETUP.sdb.txt rename to librz/bin/d/dll/RNASETUP.sdb.txt diff --git a/libr/bin/d/dll/RSRC16.sdb.txt b/librz/bin/d/dll/RSRC16.sdb.txt similarity index 100% rename from libr/bin/d/dll/RSRC16.sdb.txt rename to librz/bin/d/dll/RSRC16.sdb.txt diff --git a/libr/bin/d/dll/SB16SND.sdb.txt b/librz/bin/d/dll/SB16SND.sdb.txt similarity index 100% rename from libr/bin/d/dll/SB16SND.sdb.txt rename to librz/bin/d/dll/SB16SND.sdb.txt diff --git a/libr/bin/d/dll/SBFM.sdb.txt b/librz/bin/d/dll/SBFM.sdb.txt similarity index 100% rename from libr/bin/d/dll/SBFM.sdb.txt rename to librz/bin/d/dll/SBFM.sdb.txt diff --git a/libr/bin/d/dll/SETUP4.sdb.txt b/librz/bin/d/dll/SETUP4.sdb.txt similarity index 100% rename from libr/bin/d/dll/SETUP4.sdb.txt rename to librz/bin/d/dll/SETUP4.sdb.txt diff --git a/libr/bin/d/dll/SETUPX.sdb.txt b/librz/bin/d/dll/SETUPX.sdb.txt similarity index 100% rename from libr/bin/d/dll/SETUPX.sdb.txt rename to librz/bin/d/dll/SETUPX.sdb.txt diff --git a/libr/bin/d/dll/SHELL.sdb.txt b/librz/bin/d/dll/SHELL.sdb.txt similarity index 100% rename from libr/bin/d/dll/SHELL.sdb.txt rename to librz/bin/d/dll/SHELL.sdb.txt diff --git a/libr/bin/d/dll/SOUND.sdb.txt b/librz/bin/d/dll/SOUND.sdb.txt similarity index 100% rename from libr/bin/d/dll/SOUND.sdb.txt rename to librz/bin/d/dll/SOUND.sdb.txt diff --git a/libr/bin/d/dll/SPOOLER.sdb.txt b/librz/bin/d/dll/SPOOLER.sdb.txt similarity index 100% rename from libr/bin/d/dll/SPOOLER.sdb.txt rename to librz/bin/d/dll/SPOOLER.sdb.txt diff --git a/libr/bin/d/dll/STORAGE.sdb.txt b/librz/bin/d/dll/STORAGE.sdb.txt similarity index 100% rename from libr/bin/d/dll/STORAGE.sdb.txt rename to librz/bin/d/dll/STORAGE.sdb.txt diff --git a/libr/bin/d/dll/SYSCLASS.sdb.txt b/librz/bin/d/dll/SYSCLASS.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSCLASS.sdb.txt rename to librz/bin/d/dll/SYSCLASS.sdb.txt diff --git a/libr/bin/d/dll/SYSDETMG.sdb.txt b/librz/bin/d/dll/SYSDETMG.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSDETMG.sdb.txt rename to librz/bin/d/dll/SYSDETMG.sdb.txt diff --git a/libr/bin/d/dll/SYSDM.sdb.txt b/librz/bin/d/dll/SYSDM.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSDM.sdb.txt rename to librz/bin/d/dll/SYSDM.sdb.txt diff --git a/libr/bin/d/dll/SYSEDIT.sdb.txt b/librz/bin/d/dll/SYSEDIT.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSEDIT.sdb.txt rename to librz/bin/d/dll/SYSEDIT.sdb.txt diff --git a/libr/bin/d/dll/SYSTEM.sdb.txt b/librz/bin/d/dll/SYSTEM.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSTEM.sdb.txt rename to librz/bin/d/dll/SYSTEM.sdb.txt diff --git a/libr/bin/d/dll/SYSTHUNK.sdb.txt b/librz/bin/d/dll/SYSTHUNK.sdb.txt similarity index 100% rename from libr/bin/d/dll/SYSTHUNK.sdb.txt rename to librz/bin/d/dll/SYSTHUNK.sdb.txt diff --git a/libr/bin/d/dll/TAPI.sdb.txt b/librz/bin/d/dll/TAPI.sdb.txt similarity index 100% rename from libr/bin/d/dll/TAPI.sdb.txt rename to librz/bin/d/dll/TAPI.sdb.txt diff --git a/libr/bin/d/dll/TAPIADDR.sdb.txt b/librz/bin/d/dll/TAPIADDR.sdb.txt similarity index 100% rename from libr/bin/d/dll/TAPIADDR.sdb.txt rename to librz/bin/d/dll/TAPIADDR.sdb.txt diff --git a/libr/bin/d/dll/TAPIEXE.sdb.txt b/librz/bin/d/dll/TAPIEXE.sdb.txt similarity index 100% rename from libr/bin/d/dll/TAPIEXE.sdb.txt rename to librz/bin/d/dll/TAPIEXE.sdb.txt diff --git a/libr/bin/d/dll/TAPIINI.sdb.txt b/librz/bin/d/dll/TAPIINI.sdb.txt similarity index 100% rename from libr/bin/d/dll/TAPIINI.sdb.txt rename to librz/bin/d/dll/TAPIINI.sdb.txt diff --git a/libr/bin/d/dll/TOOLHELP.sdb.txt b/librz/bin/d/dll/TOOLHELP.sdb.txt similarity index 100% rename from libr/bin/d/dll/TOOLHELP.sdb.txt rename to librz/bin/d/dll/TOOLHELP.sdb.txt diff --git a/libr/bin/d/dll/TYPELIB.sdb.txt b/librz/bin/d/dll/TYPELIB.sdb.txt similarity index 100% rename from libr/bin/d/dll/TYPELIB.sdb.txt rename to librz/bin/d/dll/TYPELIB.sdb.txt diff --git a/libr/bin/d/dll/UMDM16.sdb.txt b/librz/bin/d/dll/UMDM16.sdb.txt similarity index 100% rename from libr/bin/d/dll/UMDM16.sdb.txt rename to librz/bin/d/dll/UMDM16.sdb.txt diff --git a/libr/bin/d/dll/USER.sdb.txt b/librz/bin/d/dll/USER.sdb.txt similarity index 100% rename from libr/bin/d/dll/USER.sdb.txt rename to librz/bin/d/dll/USER.sdb.txt diff --git a/libr/bin/d/dll/VER.sdb.txt b/librz/bin/d/dll/VER.sdb.txt similarity index 100% rename from libr/bin/d/dll/VER.sdb.txt rename to librz/bin/d/dll/VER.sdb.txt diff --git a/libr/bin/d/dll/WHLP16T.sdb.txt b/librz/bin/d/dll/WHLP16T.sdb.txt similarity index 100% rename from libr/bin/d/dll/WHLP16T.sdb.txt rename to librz/bin/d/dll/WHLP16T.sdb.txt diff --git a/libr/bin/d/dll/WIN32S16.sdb.txt b/librz/bin/d/dll/WIN32S16.sdb.txt similarity index 100% rename from libr/bin/d/dll/WIN32S16.sdb.txt rename to librz/bin/d/dll/WIN32S16.sdb.txt diff --git a/libr/bin/d/dll/WIN87EM.sdb.txt b/librz/bin/d/dll/WIN87EM.sdb.txt similarity index 100% rename from libr/bin/d/dll/WIN87EM.sdb.txt rename to librz/bin/d/dll/WIN87EM.sdb.txt diff --git a/libr/bin/d/dll/WINASPI.sdb.txt b/librz/bin/d/dll/WINASPI.sdb.txt similarity index 100% rename from libr/bin/d/dll/WINASPI.sdb.txt rename to librz/bin/d/dll/WINASPI.sdb.txt diff --git a/libr/bin/d/dll/WINNET16.sdb.txt b/librz/bin/d/dll/WINNET16.sdb.txt similarity index 100% rename from libr/bin/d/dll/WINNET16.sdb.txt rename to librz/bin/d/dll/WINNET16.sdb.txt diff --git a/libr/bin/d/dll/WINOLDAP.sdb.txt b/librz/bin/d/dll/WINOLDAP.sdb.txt similarity index 100% rename from libr/bin/d/dll/WINOLDAP.sdb.txt rename to librz/bin/d/dll/WINOLDAP.sdb.txt diff --git a/libr/bin/d/dll/WINSOCK.sdb.txt b/librz/bin/d/dll/WINSOCK.sdb.txt similarity index 100% rename from libr/bin/d/dll/WINSOCK.sdb.txt rename to librz/bin/d/dll/WINSOCK.sdb.txt diff --git a/libr/bin/d/dll/WINSPL16.sdb.txt b/librz/bin/d/dll/WINSPL16.sdb.txt similarity index 100% rename from libr/bin/d/dll/WINSPL16.sdb.txt rename to librz/bin/d/dll/WINSPL16.sdb.txt diff --git a/libr/bin/d/dll/WPSAPD.sdb.txt b/librz/bin/d/dll/WPSAPD.sdb.txt similarity index 100% rename from libr/bin/d/dll/WPSAPD.sdb.txt rename to librz/bin/d/dll/WPSAPD.sdb.txt diff --git a/libr/bin/d/dll/WPSUNI.sdb.txt b/librz/bin/d/dll/WPSUNI.sdb.txt similarity index 100% rename from libr/bin/d/dll/WPSUNI.sdb.txt rename to librz/bin/d/dll/WPSUNI.sdb.txt diff --git a/libr/bin/d/dll/WPSUNIRE.sdb.txt b/librz/bin/d/dll/WPSUNIRE.sdb.txt similarity index 100% rename from libr/bin/d/dll/WPSUNIRE.sdb.txt rename to librz/bin/d/dll/WPSUNIRE.sdb.txt diff --git a/libr/bin/d/dll/WSASRV.sdb.txt b/librz/bin/d/dll/WSASRV.sdb.txt similarity index 100% rename from libr/bin/d/dll/WSASRV.sdb.txt rename to librz/bin/d/dll/WSASRV.sdb.txt diff --git a/libr/bin/d/dll/aclui.sdb.txt b/librz/bin/d/dll/aclui.sdb.txt similarity index 100% rename from libr/bin/d/dll/aclui.sdb.txt rename to librz/bin/d/dll/aclui.sdb.txt diff --git a/libr/bin/d/dll/activeds.sdb.txt b/librz/bin/d/dll/activeds.sdb.txt similarity index 100% rename from libr/bin/d/dll/activeds.sdb.txt rename to librz/bin/d/dll/activeds.sdb.txt diff --git a/libr/bin/d/dll/atl.sdb.txt b/librz/bin/d/dll/atl.sdb.txt similarity index 100% rename from libr/bin/d/dll/atl.sdb.txt rename to librz/bin/d/dll/atl.sdb.txt diff --git a/libr/bin/d/dll/borlndmm.sdb.txt b/librz/bin/d/dll/borlndmm.sdb.txt similarity index 100% rename from libr/bin/d/dll/borlndmm.sdb.txt rename to librz/bin/d/dll/borlndmm.sdb.txt diff --git a/libr/bin/d/dll/browseui.sdb.txt b/librz/bin/d/dll/browseui.sdb.txt similarity index 100% rename from libr/bin/d/dll/browseui.sdb.txt rename to librz/bin/d/dll/browseui.sdb.txt diff --git a/libr/bin/d/dll/cabinet.sdb.txt b/librz/bin/d/dll/cabinet.sdb.txt similarity index 100% rename from libr/bin/d/dll/cabinet.sdb.txt rename to librz/bin/d/dll/cabinet.sdb.txt diff --git a/libr/bin/d/dll/comctl32.sdb.txt b/librz/bin/d/dll/comctl32.sdb.txt similarity index 100% rename from libr/bin/d/dll/comctl32.sdb.txt rename to librz/bin/d/dll/comctl32.sdb.txt diff --git a/libr/bin/d/dll/convert_dumpbin_exports_to_sdb_txt.py b/librz/bin/d/dll/convert_dumpbin_exports_to_sdb_txt.py similarity index 100% rename from libr/bin/d/dll/convert_dumpbin_exports_to_sdb_txt.py rename to librz/bin/d/dll/convert_dumpbin_exports_to_sdb_txt.py diff --git a/libr/bin/d/dll/csmfpapi.sdb.txt b/librz/bin/d/dll/csmfpapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/csmfpapi.sdb.txt rename to librz/bin/d/dll/csmfpapi.sdb.txt diff --git a/libr/bin/d/dll/csmtpapi.sdb.txt b/librz/bin/d/dll/csmtpapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/csmtpapi.sdb.txt rename to librz/bin/d/dll/csmtpapi.sdb.txt diff --git a/libr/bin/d/dll/csncdapi.sdb.txt b/librz/bin/d/dll/csncdapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/csncdapi.sdb.txt rename to librz/bin/d/dll/csncdapi.sdb.txt diff --git a/libr/bin/d/dll/dsound.sdb.txt b/librz/bin/d/dll/dsound.sdb.txt similarity index 100% rename from libr/bin/d/dll/dsound.sdb.txt rename to librz/bin/d/dll/dsound.sdb.txt diff --git a/libr/bin/d/dll/gsprop32.sdb.txt b/librz/bin/d/dll/gsprop32.sdb.txt similarity index 100% rename from libr/bin/d/dll/gsprop32.sdb.txt rename to librz/bin/d/dll/gsprop32.sdb.txt diff --git a/libr/bin/d/dll/iertutil.sdb.txt b/librz/bin/d/dll/iertutil.sdb.txt similarity index 100% rename from libr/bin/d/dll/iertutil.sdb.txt rename to librz/bin/d/dll/iertutil.sdb.txt diff --git a/libr/bin/d/dll/kernel32.sdb.txt b/librz/bin/d/dll/kernel32.sdb.txt similarity index 100% rename from libr/bin/d/dll/kernel32.sdb.txt rename to librz/bin/d/dll/kernel32.sdb.txt diff --git a/librz/bin/d/dll/makefile b/librz/bin/d/dll/makefile new file mode 100644 index 0000000000..219766d2da --- /dev/null +++ b/librz/bin/d/dll/makefile @@ -0,0 +1,8 @@ +all: + #rz_bin -rs /tmp/ws2_32.dll | grep ^k| cut -d / -f 4- > ___WS2_32.sdb.txt + #rz_bin -rs /tmp/oleaut32.dll | grep ^k| cut -d / -f 4- > ___OLEAUT32.sdb.txt + #rz_bin -rs /tmp/wsock32.dll | grep ^k| cut -d / -f 4- > WSOCK32.sdb.txt + #rz_bin -rs /tmp/msi.dll | grep ^k| cut -d / -f 4- > MSI.sdb.txt + rz_bin -rs /tmp/csncdapi.dll | grep ^k| cut -d / -f 4- > CSNCDAPI.sdb.txt + rz_bin -rs /tmp/csmtpapi.dll | grep ^k| cut -d / -f 4- > CSMTPAPI.sdb.txt + rz_bin -rs /tmp/csftpapi.dll | grep ^k| cut -d / -f 4- > CSMFPAPI.sdb.txt diff --git a/libr/bin/d/dll/mfc100u.sdb.txt b/librz/bin/d/dll/mfc100u.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc100u.sdb.txt rename to librz/bin/d/dll/mfc100u.sdb.txt diff --git a/libr/bin/d/dll/mfc120.sdb.txt b/librz/bin/d/dll/mfc120.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc120.sdb.txt rename to librz/bin/d/dll/mfc120.sdb.txt diff --git a/libr/bin/d/dll/mfc140u.sdb.txt b/librz/bin/d/dll/mfc140u.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc140u.sdb.txt rename to librz/bin/d/dll/mfc140u.sdb.txt diff --git a/libr/bin/d/dll/mfc30.sdb.txt b/librz/bin/d/dll/mfc30.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc30.sdb.txt rename to librz/bin/d/dll/mfc30.sdb.txt diff --git a/libr/bin/d/dll/mfc40.sdb.txt b/librz/bin/d/dll/mfc40.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc40.sdb.txt rename to librz/bin/d/dll/mfc40.sdb.txt diff --git a/libr/bin/d/dll/mfc42.sdb.txt b/librz/bin/d/dll/mfc42.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc42.sdb.txt rename to librz/bin/d/dll/mfc42.sdb.txt diff --git a/libr/bin/d/dll/mfc42u.sdb.txt b/librz/bin/d/dll/mfc42u.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc42u.sdb.txt rename to librz/bin/d/dll/mfc42u.sdb.txt diff --git a/libr/bin/d/dll/mfc71.sdb.txt b/librz/bin/d/dll/mfc71.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc71.sdb.txt rename to librz/bin/d/dll/mfc71.sdb.txt diff --git a/libr/bin/d/dll/mfc71u.sdb.txt b/librz/bin/d/dll/mfc71u.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc71u.sdb.txt rename to librz/bin/d/dll/mfc71u.sdb.txt diff --git a/libr/bin/d/dll/mfc90u.sdb.txt b/librz/bin/d/dll/mfc90u.sdb.txt similarity index 100% rename from libr/bin/d/dll/mfc90u.sdb.txt rename to librz/bin/d/dll/mfc90u.sdb.txt diff --git a/libr/bin/d/dll/msi.sdb.txt b/librz/bin/d/dll/msi.sdb.txt similarity index 100% rename from libr/bin/d/dll/msi.sdb.txt rename to librz/bin/d/dll/msi.sdb.txt diff --git a/libr/bin/d/dll/mstlsapi.sdb.txt b/librz/bin/d/dll/mstlsapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/mstlsapi.sdb.txt rename to librz/bin/d/dll/mstlsapi.sdb.txt diff --git a/libr/bin/d/dll/msvbvm50.sdb.txt b/librz/bin/d/dll/msvbvm50.sdb.txt similarity index 100% rename from libr/bin/d/dll/msvbvm50.sdb.txt rename to librz/bin/d/dll/msvbvm50.sdb.txt diff --git a/libr/bin/d/dll/msvbvm60.sdb.txt b/librz/bin/d/dll/msvbvm60.sdb.txt similarity index 100% rename from libr/bin/d/dll/msvbvm60.sdb.txt rename to librz/bin/d/dll/msvbvm60.sdb.txt diff --git a/libr/bin/d/dll/odbc32.sdb.txt b/librz/bin/d/dll/odbc32.sdb.txt similarity index 100% rename from libr/bin/d/dll/odbc32.sdb.txt rename to librz/bin/d/dll/odbc32.sdb.txt diff --git a/libr/bin/d/dll/oleaut32.sdb.txt b/librz/bin/d/dll/oleaut32.sdb.txt similarity index 100% rename from libr/bin/d/dll/oleaut32.sdb.txt rename to librz/bin/d/dll/oleaut32.sdb.txt diff --git a/libr/bin/d/dll/olecli32.sdb.txt b/librz/bin/d/dll/olecli32.sdb.txt similarity index 100% rename from libr/bin/d/dll/olecli32.sdb.txt rename to librz/bin/d/dll/olecli32.sdb.txt diff --git a/libr/bin/d/dll/oledlg.sdb.txt b/librz/bin/d/dll/oledlg.sdb.txt similarity index 100% rename from libr/bin/d/dll/oledlg.sdb.txt rename to librz/bin/d/dll/oledlg.sdb.txt diff --git a/libr/bin/d/dll/olepro32.sdb.txt b/librz/bin/d/dll/olepro32.sdb.txt similarity index 100% rename from libr/bin/d/dll/olepro32.sdb.txt rename to librz/bin/d/dll/olepro32.sdb.txt diff --git a/libr/bin/d/dll/olesvr32.sdb.txt b/librz/bin/d/dll/olesvr32.sdb.txt similarity index 100% rename from libr/bin/d/dll/olesvr32.sdb.txt rename to librz/bin/d/dll/olesvr32.sdb.txt diff --git a/libr/bin/d/dll/shdocvw.sdb.txt b/librz/bin/d/dll/shdocvw.sdb.txt similarity index 100% rename from libr/bin/d/dll/shdocvw.sdb.txt rename to librz/bin/d/dll/shdocvw.sdb.txt diff --git a/libr/bin/d/dll/shell32.sdb.txt b/librz/bin/d/dll/shell32.sdb.txt similarity index 100% rename from libr/bin/d/dll/shell32.sdb.txt rename to librz/bin/d/dll/shell32.sdb.txt diff --git a/libr/bin/d/dll/shlwapi.sdb.txt b/librz/bin/d/dll/shlwapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/shlwapi.sdb.txt rename to librz/bin/d/dll/shlwapi.sdb.txt diff --git a/libr/bin/d/dll/spr32d70.sdb.txt b/librz/bin/d/dll/spr32d70.sdb.txt similarity index 100% rename from libr/bin/d/dll/spr32d70.sdb.txt rename to librz/bin/d/dll/spr32d70.sdb.txt diff --git a/libr/bin/d/dll/urlmon.sdb.txt b/librz/bin/d/dll/urlmon.sdb.txt similarity index 100% rename from libr/bin/d/dll/urlmon.sdb.txt rename to librz/bin/d/dll/urlmon.sdb.txt diff --git a/libr/bin/d/dll/uxtheme.sdb.txt b/librz/bin/d/dll/uxtheme.sdb.txt similarity index 100% rename from libr/bin/d/dll/uxtheme.sdb.txt rename to librz/bin/d/dll/uxtheme.sdb.txt diff --git a/libr/bin/d/dll/vb40032.sdb.txt b/librz/bin/d/dll/vb40032.sdb.txt similarity index 100% rename from libr/bin/d/dll/vb40032.sdb.txt rename to librz/bin/d/dll/vb40032.sdb.txt diff --git a/libr/bin/d/dll/vssapi.sdb.txt b/librz/bin/d/dll/vssapi.sdb.txt similarity index 100% rename from libr/bin/d/dll/vssapi.sdb.txt rename to librz/bin/d/dll/vssapi.sdb.txt diff --git a/libr/bin/d/dll/winmm.sdb.txt b/librz/bin/d/dll/winmm.sdb.txt similarity index 100% rename from libr/bin/d/dll/winmm.sdb.txt rename to librz/bin/d/dll/winmm.sdb.txt diff --git a/libr/bin/d/dll/wldap32.sdb.txt b/librz/bin/d/dll/wldap32.sdb.txt similarity index 100% rename from libr/bin/d/dll/wldap32.sdb.txt rename to librz/bin/d/dll/wldap32.sdb.txt diff --git a/libr/bin/d/dll/ws2_32.sdb.txt b/librz/bin/d/dll/ws2_32.sdb.txt similarity index 100% rename from libr/bin/d/dll/ws2_32.sdb.txt rename to librz/bin/d/dll/ws2_32.sdb.txt diff --git a/libr/bin/d/dll/wsnmp32.sdb.txt b/librz/bin/d/dll/wsnmp32.sdb.txt similarity index 100% rename from libr/bin/d/dll/wsnmp32.sdb.txt rename to librz/bin/d/dll/wsnmp32.sdb.txt diff --git a/libr/bin/d/dll/wsock32.sdb.txt b/librz/bin/d/dll/wsock32.sdb.txt similarity index 100% rename from libr/bin/d/dll/wsock32.sdb.txt rename to librz/bin/d/dll/wsock32.sdb.txt diff --git a/libr/bin/d/elf32 b/librz/bin/d/elf32 similarity index 100% rename from libr/bin/d/elf32 rename to librz/bin/d/elf32 diff --git a/libr/bin/d/elf64 b/librz/bin/d/elf64 similarity index 100% rename from libr/bin/d/elf64 rename to librz/bin/d/elf64 diff --git a/libr/bin/d/elf_enums b/librz/bin/d/elf_enums similarity index 100% rename from libr/bin/d/elf_enums rename to librz/bin/d/elf_enums diff --git a/libr/bin/d/fat b/librz/bin/d/fat similarity index 100% rename from libr/bin/d/fat rename to librz/bin/d/fat diff --git a/libr/bin/d/jni.h b/librz/bin/d/jni.h similarity index 100% rename from libr/bin/d/jni.h rename to librz/bin/d/jni.h diff --git a/libr/bin/d/macho b/librz/bin/d/macho similarity index 100% rename from libr/bin/d/macho rename to librz/bin/d/macho diff --git a/libr/bin/d/meson.build b/librz/bin/d/meson.build similarity index 100% rename from libr/bin/d/meson.build rename to librz/bin/d/meson.build diff --git a/libr/bin/d/mz b/librz/bin/d/mz similarity index 100% rename from libr/bin/d/mz rename to librz/bin/d/mz diff --git a/libr/bin/d/ntfs b/librz/bin/d/ntfs similarity index 100% rename from libr/bin/d/ntfs rename to librz/bin/d/ntfs diff --git a/libr/bin/d/pe32 b/librz/bin/d/pe32 similarity index 100% rename from libr/bin/d/pe32 rename to librz/bin/d/pe32 diff --git a/libr/bin/d/trx b/librz/bin/d/trx similarity index 100% rename from libr/bin/d/trx rename to librz/bin/d/trx diff --git a/libr/bin/d/zip b/librz/bin/d/zip similarity index 100% rename from libr/bin/d/zip rename to librz/bin/d/zip diff --git a/libr/bin/dbginfo.c b/librz/bin/dbginfo.c similarity index 65% rename from libr/bin/dbginfo.c rename to librz/bin/dbginfo.c index ae35161557..02d045d27a 100644 --- a/libr/bin/dbginfo.c +++ b/librz/bin/dbginfo.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, pancake */ -#include -#include +#include +#include -R_API bool r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line) { - r_return_val_if_fail (bin, false); - RBinFile *binfile = r_bin_cur (bin); - RBinObject *o = r_bin_cur_object (bin); - RBinPlugin *cp = r_bin_file_cur_plugin (binfile); - ut64 baddr = r_bin_get_baddr (bin); +RZ_API bool rz_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line) { + rz_return_val_if_fail (bin, false); + RBinFile *binfile = rz_bin_cur (bin); + RBinObject *o = rz_bin_cur_object (bin); + RBinPlugin *cp = rz_bin_file_cur_plugin (binfile); + ut64 baddr = rz_bin_get_baddr (bin); if (cp && cp->dbginfo) { if (o && addr >= baddr && addr < baddr + bin->cur->o->size) { if (cp->dbginfo->get_line) { @@ -20,8 +20,8 @@ R_API bool r_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line) return false; } -R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { - r_return_val_if_fail (bin, NULL); +RZ_API char *rz_bin_addr2text(RBin *bin, ut64 addr, int origin) { + rz_return_val_if_fail (bin, NULL); char file[4096]; int line; char *out = NULL, *out2 = NULL; @@ -29,14 +29,14 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { if (!bin->cur) { return NULL; } - char *key = r_str_newf ("0x%"PFMT64x, addr); + char *key = rz_str_newf ("0x%"PFMT64x, addr); char *file_line = sdb_get (bin->cur->sdb_addrinfo, key, 0); if (file_line) { char *token = strchr (file_line, '|'); if (token) { *token++ = 0; line = atoi (token); - out = r_file_slurp_line (file_line, line, 0); + out = rz_file_slurp_line (file_line, line, 0); *token++ = ':'; } else { return file_line; @@ -55,7 +55,7 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { } } if (origin) { - char *res = r_str_newf ("%s:%d%s%s", + char *res = rz_str_newf ("%s:%d%s%s", file_nopath? file_nopath: "", line, file_nopath? " ": "", out? out: ""); @@ -68,15 +68,15 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { R_FREE (file_line); file[0] = 0; - if (r_bin_addr2line (bin, addr, file, sizeof (file), &line)) { + if (rz_bin_addr2line (bin, addr, file, sizeof (file), &line)) { if (bin->srcdir && *bin->srcdir) { char *slash = strrchr (file, '/'); - char *nf = r_str_newf ("%s/%s", bin->srcdir, slash? slash + 1: file); + char *nf = rz_str_newf ("%s/%s", bin->srcdir, slash? slash + 1: file); strncpy (file, nf, sizeof (file) - 1); free (nf); } // TODO: this is slow. must use a cached pool of mapped files and line:off entries - out = r_file_slurp_line (file, line, 0); + out = rz_file_slurp_line (file, line, 0); if (!out) { if (origin > 1) { file_nopath = file; @@ -88,7 +88,7 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { file_nopath = file; } } - return r_str_newf ("%s:%d", file_nopath? file_nopath: "", line); + return rz_str_newf ("%s:%d", file_nopath? file_nopath: "", line); } out2 = malloc ((strlen (file) + 64 + strlen (out)) * sizeof (char)); if (origin > 1) { @@ -107,14 +107,14 @@ R_API char *r_bin_addr2text(RBin *bin, ut64 addr, int origin) { return out2; } -R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr) { - r_return_val_if_fail (bin, NULL); +RZ_API char *rz_bin_addr2fileline(RBin *bin, ut64 addr) { + rz_return_val_if_fail (bin, NULL); char file[1024]; int line = 0; - if (r_bin_addr2line (bin, addr, file, sizeof (file) - 1, &line)) { + if (rz_bin_addr2line (bin, addr, file, sizeof (file) - 1, &line)) { char *file_nopath = strrchr (file, '/'); - return r_str_newf ("%s:%d", file_nopath? file_nopath + 1: file, line); + return rz_str_newf ("%s:%d", file_nopath? file_nopath + 1: file, line); } return NULL; } diff --git a/libr/bin/demangle.c b/librz/bin/demangle.c similarity index 66% rename from libr/bin/demangle.c rename to librz/bin/demangle.c index aef332203e..e7f60bbbae 100644 --- a/libr/bin/demangle.c +++ b/librz/bin/demangle.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include +#include #include "i/private.h" #include -R_API void r_bin_demangle_list(RBin *bin) { +RZ_API void rz_bin_demangle_list(RBin *bin) { const char *langs[] = { "c++", "java", "objc", "swift", "dlang", "msvc", "rust", NULL }; RBinPlugin *plugin; - RListIter *it; + RzListIter *it; int i; if (!bin) { return; @@ -15,18 +15,18 @@ R_API void r_bin_demangle_list(RBin *bin) { for (i = 0; langs[i]; i++) { bin->cb_printf ("%s\n", langs[i]); } - r_list_foreach (bin->plugins, it, plugin) { + rz_list_foreach (bin->plugins, it, plugin) { if (plugin->demangle) { bin->cb_printf ("%s\n", plugin->name); } } } -R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str) { +RZ_API char *rz_bin_demangle_plugin(RBin *bin, const char *name, const char *str) { RBinPlugin *plugin; - RListIter *it; + RzListIter *it; if (bin && name && str) { - r_list_foreach (bin->plugins, it, plugin) { + rz_list_foreach (bin->plugins, it, plugin) { if (plugin->demangle && !strncmp (plugin->name, name, strlen (plugin->name))) { return plugin->demangle (str); } @@ -35,7 +35,7 @@ R_API char *r_bin_demangle_plugin(RBin *bin, const char *name, const char *str) return NULL; } -R_API int r_bin_demangle_type(const char *str) { +RZ_API int rz_bin_demangle_type(const char *str) { if (str && *str) { if (!strcmp (str, "swift")) { return R_BIN_NM_SWIFT; @@ -62,14 +62,14 @@ R_API int r_bin_demangle_type(const char *str) { return R_BIN_NM_NONE; } -R_API char *r_bin_demangle(RBinFile *bf, const char *def, const char *str, ut64 vaddr, bool libs) { +RZ_API char *rz_bin_demangle(RBinFile *bf, const char *def, const char *str, ut64 vaddr, bool libs) { int type = -1; if (!str || !*str) { return NULL; } RBin *bin = bf? bf->rbin: NULL; RBinObject *o = bf? bf->o: NULL; - RListIter *iter; + RzListIter *iter; const char *lib = NULL; if (!strncmp (str, "reloc.", 6)) { str += 6; @@ -82,9 +82,9 @@ R_API char *r_bin_demangle(RBinFile *bf, const char *def, const char *str, ut64 } if (o) { bool found = false; - r_list_foreach (o->libs, iter, lib) { + rz_list_foreach (o->libs, iter, lib) { size_t len = strlen (lib); - if (!r_str_ncasecmp (str, lib, len)) { + if (!rz_str_ncasecmp (str, lib, len)) { str += len; if (*str == '_') { str++; @@ -97,7 +97,7 @@ R_API char *r_bin_demangle(RBinFile *bf, const char *def, const char *str, ut64 lib = NULL; } size_t len = strlen (bin->file); - if (!r_str_ncasecmp (str, bin->file, len)) { + if (!rz_str_ncasecmp (str, bin->file, len)) { lib = bin->file; str += len; if (*str == '_') { @@ -118,20 +118,20 @@ R_API char *r_bin_demangle(RBinFile *bf, const char *def, const char *str, ut64 return NULL; } if (type == -1) { - type = r_bin_lang_type (bf, def, str); + type = rz_bin_lang_type (bf, def, str); } char *demangled = NULL; switch (type) { - case R_BIN_NM_JAVA: demangled = r_bin_demangle_java (str); break; - case R_BIN_NM_RUST: demangled = r_bin_demangle_rust (bf, str, vaddr); break; - case R_BIN_NM_OBJC: demangled = r_bin_demangle_objc (NULL, str); break; - case R_BIN_NM_SWIFT: demangled = r_bin_demangle_swift (str, bin? bin->demanglercmd: false); break; - case R_BIN_NM_CXX: demangled = r_bin_demangle_cxx (bf, str, vaddr); break; - case R_BIN_NM_MSVC: demangled = r_bin_demangle_msvc (str); break; - case R_BIN_NM_DLANG: demangled = r_bin_demangle_plugin (bin, "dlang", str); break; + case R_BIN_NM_JAVA: demangled = rz_bin_demangle_java (str); break; + case R_BIN_NM_RUST: demangled = rz_bin_demangle_rust (bf, str, vaddr); break; + case R_BIN_NM_OBJC: demangled = rz_bin_demangle_objc (NULL, str); break; + case R_BIN_NM_SWIFT: demangled = rz_bin_demangle_swift (str, bin? bin->demanglercmd: false); break; + case R_BIN_NM_CXX: demangled = rz_bin_demangle_cxx (bf, str, vaddr); break; + case R_BIN_NM_MSVC: demangled = rz_bin_demangle_msvc (str); break; + case R_BIN_NM_DLANG: demangled = rz_bin_demangle_plugin (bin, "dlang", str); break; } if (libs && demangled && lib) { - char *d = r_str_newf ("%s_%s", lib, demangled); + char *d = rz_str_newf ("%s_%s", lib, demangled); free (demangled); demangled = d; } @@ -146,7 +146,7 @@ main() { strncpy (str, "main([Ljava/lang/String;)V", sizeof (str)-1); strncpy (str, "foo([III)Ljava/lang/Integer;", sizeof (str)-1); //out = cplus_demangle_v3 (str, flags); - out = r_bin_demangle_java (str); //, flags); + out = rz_bin_demangle_java (str); //, flags); printf ("INPUT (%s)\n", str); printf ("OUTPUT (%s)\n", out); } diff --git a/libr/bin/dwarf.c b/librz/bin/dwarf.c similarity index 92% rename from libr/bin/dwarf.c rename to librz/bin/dwarf.c index 9efe8220fa..5d97104e5e 100644 --- a/libr/bin/dwarf.c +++ b/librz/bin/dwarf.c @@ -13,9 +13,9 @@ #define DBGFD NULL #endif -#include -#include -#include +#include +#include +#include #define STANDARD_OPERAND_COUNT_DWARF2 9 #define STANDARD_OPERAND_COUNT_DWARF3 12 @@ -32,13 +32,13 @@ static bool big_end = false; (((buf) + sizeof (ut8) < buf_end) ? ((ut8 *)buf)[0] : 0); \ (buf) += sizeof (ut8) #define READ16(buf) \ - (((buf) + sizeof (ut16) < buf_end) ? r_read_ble16 (buf, big_end) : 0); \ + (((buf) + sizeof (ut16) < buf_end) ? rz_read_ble16 (buf, big_end) : 0); \ (buf) += sizeof (ut16) #define READ32(buf) \ - (((buf) + sizeof (ut32) < buf_end) ? r_read_ble32 (buf, big_end) : 0); \ + (((buf) + sizeof (ut32) < buf_end) ? rz_read_ble32 (buf, big_end) : 0); \ (buf) += sizeof (ut32) #define READ64(buf) \ - (((buf) + sizeof (ut64) < buf_end) ? r_read_ble64 (buf, big_end) : 0); \ + (((buf) + sizeof (ut64) < buf_end) ? rz_read_ble64 (buf, big_end) : 0); \ (buf) += sizeof (ut64) static const char *dwarf_tag_name_encodings[] = { @@ -439,8 +439,8 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u } while (buf + 1 < buf_end) { size_t maxlen = R_MIN ((size_t) (buf_end - buf) - 1, 0xfff); - size_t len = r_str_nlen ((const char *)buf, maxlen); - char *str = r_str_ndup ((const char *)buf, len); + size_t len = rz_str_nlen ((const char *)buf, maxlen); + char *str = rz_str_ndup ((const char *)buf, len); if (len < 1 || len >= 0xfff || !str) { buf += 1; free (str); @@ -469,7 +469,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u const char *filename = (const char *)buf; size_t maxlen = R_MIN ((size_t) (buf_end - buf - 1), 0xfff); ut64 id_idx, mod_time, file_len; - size_t len = r_str_nlen (filename, maxlen); + size_t len = rz_str_nlen (filename, maxlen); if (!len) { buf++; @@ -480,17 +480,17 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u buf = NULL; goto beach; } - buf = r_uleb128 (buf, buf_end - buf, &id_idx, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &id_idx, NULL); if (buf >= buf_end) { buf = NULL; goto beach; } - buf = r_uleb128 (buf, buf_end - buf, &mod_time, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &mod_time, NULL); if (buf >= buf_end) { buf = NULL; goto beach; } - buf = r_uleb128 (buf, buf_end - buf, &file_len, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &file_len, NULL); if (buf >= buf_end) { buf = NULL; goto beach; @@ -503,7 +503,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u if (include_dir && include_dir[0] != '/') { comp_dir = sdb_get (bf->sdb_addrinfo, "DW_AT_comp_dir", 0); if (comp_dir) { - include_dir = r_str_newf("%s/%s/", comp_dir, include_dir); + include_dir = rz_str_newf("%s/%s/", comp_dir, include_dir); } } } else { @@ -514,7 +514,7 @@ static const ut8 *parse_line_header_source(RBinFile *bf, const ut8 *buf, const u } if (hdr->file_names) { - hdr->file_names[count].name = r_str_newf("%s/%s", include_dir ? include_dir : "", filename); + hdr->file_names[count].name = rz_str_newf("%s/%s", include_dir ? include_dir : "", filename); hdr->file_names[count].id_idx = id_idx; hdr->file_names[count].mod_time = mod_time; hdr->file_names[count].file_len = file_len; @@ -581,7 +581,7 @@ static const ut8 *parse_line_header ( RBinFile *bf, const ut8 *buf, const ut8 *buf_end, RBinDwarfLineHeader *hdr, int mode, PrintfCallback print) { - r_return_val_if_fail(hdr && bf && buf, NULL); + rz_return_val_if_fail(hdr && bf && buf, NULL); hdr->is_64bit = false; hdr->unit_length = READ32 (buf); @@ -681,7 +681,7 @@ static inline void add_sdb_addrline(Sdb *s, ut64 addr, const char *file, ut64 li if (!s || !file) { return; } - p = r_str_rchr (file, NULL, '/'); + p = rz_str_rchr (file, NULL, '/'); if (p) { p++; } else { @@ -697,13 +697,13 @@ static inline void add_sdb_addrline(Sdb *s, ut64 addr, const char *file, ut64 li } #if 0 /* THIS IS TOO SLOW */ - if (r_file_exists (file)) { + if (rz_file_exists (file)) { p = file; } #else p = file; #endif - fileline = r_str_newf ("%s|%"PFMT64d, p, line); + fileline = rz_str_newf ("%s|%"PFMT64d, p, line); offset_ptr = sdb_itoa (addr, offset, 16); sdb_add (s, offset_ptr, fileline, 0); sdb_add (s, fileline, offset_ptr, 0); @@ -714,7 +714,7 @@ static const ut8 *parse_ext_opcode(const RBin *bin, const ut8 *obuf, size_t len, const RBinDwarfLineHeader *hdr, RBinDwarfSMRegisters *regs, int mode) { - r_return_val_if_fail (bin && bin->cur && obuf && hdr && regs, NULL); + rz_return_val_if_fail (bin && bin->cur && obuf && hdr && regs, NULL); PrintfCallback print = bin->cb_printf; const ut8 *buf; @@ -729,7 +729,7 @@ static const ut8 *parse_ext_opcode(const RBin *bin, const ut8 *obuf, const char *filename; buf_end = buf + len; - buf = r_leb128 (buf, len, &op_len); + buf = rz_leb128 (buf, len, &op_len); if (buf >= buf_end) { return NULL; } @@ -779,17 +779,17 @@ static const ut8 *parse_ext_opcode(const RBin *bin, const ut8 *obuf, ut64 dir_idx; ut64 ignore; if (buf + 1 < buf_end) { - buf = r_uleb128 (buf, buf_end - buf, &dir_idx, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &dir_idx, NULL); } if (buf + 1 < buf_end) { - buf = r_uleb128 (buf, buf_end - buf, &ignore, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &ignore, NULL); } if (buf + 1 < buf_end) { - buf = r_uleb128 (buf, buf_end - buf, &ignore, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &ignore, NULL); } break; case DW_LNE_set_discriminator: - buf = r_uleb128 (buf, buf_end - buf, &addr, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &addr, NULL); if (mode == R_MODE_PRINT) { print ("set Discriminator to %"PFMT64d"\n", addr); } @@ -812,7 +812,7 @@ static const ut8 *parse_spec_opcode( RBinDwarfSMRegisters *regs, ut8 opcode, int mode) { - r_return_val_if_fail (bin && obuf && hdr && regs, NULL); + rz_return_val_if_fail (bin && obuf && hdr && regs, NULL); PrintfCallback print = bin->cb_printf; RBinFile *binfile = bin->cur; @@ -855,7 +855,7 @@ static const ut8 *parse_std_opcode( const RBinDwarfLineHeader *hdr, RBinDwarfSMRegisters *regs, ut8 opcode, int mode) { - r_return_val_if_fail (bin && bin->cur && obuf && hdr && regs, NULL); + rz_return_val_if_fail (bin && bin->cur && obuf && hdr && regs, NULL); PrintfCallback print = bin->cb_printf; RBinFile *binfile = bin->cur; @@ -887,7 +887,7 @@ static const ut8 *parse_std_opcode( regs->basic_block = DWARF_FALSE; break; case DW_LNS_advance_pc: - buf = r_uleb128 (buf, buf_end - buf, &addr, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &addr, NULL); regs->address += addr * hdr->min_inst_len; if (mode == R_MODE_PRINT) { print ("Advance PC by %"PFMT64d" to 0x%"PFMT64x"\n", @@ -895,21 +895,21 @@ static const ut8 *parse_std_opcode( } break; case DW_LNS_advance_line: - buf = r_leb128(buf, buf_end - buf, &sbuf); + buf = rz_leb128(buf, buf_end - buf, &sbuf); regs->line += sbuf; if (mode == R_MODE_PRINT) { print ("Advance line by %"PFMT64d", to %"PFMT64d"\n", sbuf, regs->line); } break; case DW_LNS_set_file: - buf = r_uleb128 (buf, buf_end - buf, &addr, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &addr, NULL); if (mode == R_MODE_PRINT) { print ("Set file to %"PFMT64d"\n", addr); } regs->file = addr; break; case DW_LNS_set_column: - buf = r_uleb128 (buf, buf_end - buf, &addr, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &addr, NULL); if (mode == R_MODE_PRINT) { print ("Set column to %"PFMT64d"\n", addr); } @@ -960,7 +960,7 @@ static const ut8 *parse_std_opcode( } break; case DW_LNS_set_isa: - buf = r_uleb128 (buf, buf_end - buf, &addr, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &addr, NULL); regs->isa = addr; if (mode == R_MODE_PRINT) { print ("set_isa\n"); @@ -1031,7 +1031,7 @@ static int parse_line_raw(const RBin *a, const ut8 *obuf, ut64 len, int mode) { RBinFile *binfile = a ? a->cur : NULL; - r_return_val_if_fail(binfile && obuf, false); + rz_return_val_if_fail(binfile && obuf, false); PrintfCallback print = a->cb_printf; if (mode == R_MODE_PRINT) { @@ -1105,11 +1105,11 @@ static int parse_line_raw(const RBin *a, const ut8 *obuf, (x)=*(y*)buf; idx+=sizeof(y);buf+=sizeof(y) #define READ_BUF64(x) if (idx+sizeof(ut64)>=len) { return false;} \ - (x)=r_read_ble64(buf, big_end); idx+=sizeof(ut64);buf+=sizeof(ut64) + (x)=rz_read_ble64(buf, big_end); idx+=sizeof(ut64);buf+=sizeof(ut64) #define READ_BUF32(x) if (idx+sizeof(ut32)>=len) { return false;} \ - (x)=r_read_ble32(buf, big_end); idx+=sizeof(ut32);buf+=sizeof(ut32) + (x)=rz_read_ble32(buf, big_end); idx+=sizeof(ut32);buf+=sizeof(ut32) #define READ_BUF16(x) if (idx+sizeof(ut16)>=len) { return false;} \ - (x)=r_read_ble16(buf, big_end); idx+=sizeof(ut16);buf+=sizeof(ut16) + (x)=rz_read_ble16(buf, big_end); idx+=sizeof(ut16);buf+=sizeof(ut16) static int parse_aranges_raw(const ut8 *obuf, int len, int mode, PrintfCallback print) { ut32 length, offset; @@ -1350,7 +1350,7 @@ static void print_abbrev_section(RBinDwarfDebugAbbrev *da, PrintfCallback print) } } -R_API void r_bin_dwarf_free_debug_abbrev(RBinDwarfDebugAbbrev *da) { +RZ_API void rz_bin_dwarf_free_debug_abbrev(RBinDwarfDebugAbbrev *da) { size_t i; if (!da) { return; @@ -1408,7 +1408,7 @@ static void free_comp_unit(RBinDwarfCompUnit *cu) { R_FREE (cu->dies); } -R_API void r_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf) { +RZ_API void rz_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf) { size_t i; if (!inf) { return; @@ -1423,7 +1423,7 @@ R_API void r_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf) { static void print_attr_value(const RBinDwarfAttrValue *val, PrintfCallback print) { size_t i; - r_return_if_fail(val); + rz_return_if_fail(val); switch (val->attr_form) { case DW_FORM_block: @@ -1512,7 +1512,7 @@ static void print_debug_info(const RBinDwarfDebugInfo *inf, PrintfCallback print RBinDwarfDie *dies; RBinDwarfAttrValue *values; - r_return_if_fail(inf); + rz_return_if_fail(inf); for (i = 0; i < inf->count; i++) { print ("\n"); @@ -1597,7 +1597,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, const ut8 *buf_end = obuf + obuf_len; size_t j; - r_return_val_if_fail(def && value && hdr && obuf && obuf_len >= 1, NULL); + rz_return_val_if_fail(def && value && hdr && obuf && obuf_len >= 1, NULL); value->attr_form = def->attr_form; value->attr_name = def->attr_name; @@ -1650,11 +1650,11 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, break; case DW_FORM_sdata: value->kind = DW_AT_KIND_CONSTANT; - buf = r_leb128 (buf, buf_end - buf, &value->sconstant); + buf = rz_leb128 (buf, buf_end - buf, &value->sconstant); break; case DW_FORM_udata: value->kind = DW_AT_KIND_CONSTANT; - buf = r_uleb128 (buf, buf_end - buf, &value->uconstant, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->uconstant, NULL); break; case DW_FORM_string: value->kind = DW_AT_KIND_STRING; @@ -1686,7 +1686,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, break; case DW_FORM_block: // variable length ULEB128 value->kind = DW_AT_KIND_BLOCK; - buf = r_uleb128 (buf, buf_end - buf, &value->block.length, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->block.length, NULL); if (!buf || buf >= buf_end) { return NULL; } @@ -1733,7 +1733,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, case DW_FORM_ref_udata: value->kind = DW_AT_KIND_REFERENCE; // uleb128 is enough to fit into ut64? - buf = r_uleb128 (buf, buf_end - buf, &value->reference, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->reference, NULL); value->reference += hdr->unit_offset; break; // offset in a section other than .debug_info or .debug_str @@ -1743,7 +1743,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, break; case DW_FORM_exprloc: value->kind = DW_AT_KIND_BLOCK; - buf = r_uleb128 (buf, buf_end - buf, &value->block.length, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->block.length, NULL); if (!buf || buf >= buf_end) { return NULL; } @@ -1794,7 +1794,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, index into an array of addresses in the .debug_addr section.*/ case DW_FORM_addrx: value->kind = DW_AT_KIND_ADDRESS; - buf = r_uleb128 (buf, buf_end - buf, &value->address, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->address, NULL); break; case DW_FORM_addrx1: value->kind = DW_AT_KIND_ADDRESS; @@ -1838,7 +1838,7 @@ static const ut8 *parse_attr_value(const ut8 *obuf, int obuf_len, // An index into the .debug_rnglists case DW_FORM_rnglistx: value->kind = DW_AT_KIND_ADDRESS; - buf = r_uleb128 (buf, buf_end - buf, &value->address, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &value->address, NULL); break; default: eprintf ("Unknown DW_FORM 0x%02" PFMT64x "\n", def->attr_form); @@ -1919,7 +1919,7 @@ static const ut8 *parse_comp_unit(RBinDwarfDebugInfo *info, Sdb *sdb, const ut8 // DIE starts with ULEB128 with the abbreviation code ut64 abbr_code; - buf = r_uleb128 (buf, buf_end - buf, &abbr_code, NULL); + buf = rz_uleb128 (buf, buf_end - buf, &abbr_code, NULL); if (abbr_code > abbrevs->count || !buf) { // something invalid return NULL; @@ -1994,7 +1994,7 @@ static const ut8 *info_comp_unit_read_hdr(const ut8 *buf, const ut8 *buf_end, RB return buf; } static int expand_info(RBinDwarfDebugInfo *info) { - r_return_val_if_fail (info && info->capacity == info->count, -1); + rz_return_val_if_fail (info && info->capacity == info->count, -1); RBinDwarfCompUnit *tmp = realloc (info->comp_units, info->capacity * 2 * sizeof (RBinDwarfCompUnit)); @@ -2021,13 +2021,13 @@ static int expand_info(RBinDwarfDebugInfo *info) { * @param debug_str start of the .debug_str section * @param debug_str_len length of the debug_str section * @param mode - * @return R_API* parse_info_raw Parsed information + * @return RZ_API* parse_info_raw Parsed information */ static RBinDwarfDebugInfo *parse_info_raw(Sdb *sdb, RBinDwarfDebugAbbrev *da, const ut8 *obuf, size_t len, const ut8 *debug_str, size_t debug_str_len) { - r_return_val_if_fail (da && sdb && obuf, false); + rz_return_val_if_fail (da && sdb && obuf, false); const ut8 *buf = obuf; const ut8 *buf_end = obuf + len; @@ -2068,7 +2068,7 @@ static RBinDwarfDebugInfo *parse_info_raw(Sdb *sdb, RBinDwarfDebugAbbrev *da, if (da->decls->count >= da->capacity) { eprintf ("WARNING: malformed dwarf have not enough buckets for decls.\n"); } - r_warn_if_fail (da->count <= da->capacity); + rz_warn_if_fail (da->count <= da->capacity); // find abbrev start for current comp unit // we could also do naive, ((char *)da->decls) + abbrev_offset, @@ -2093,7 +2093,7 @@ static RBinDwarfDebugInfo *parse_info_raw(Sdb *sdb, RBinDwarfDebugAbbrev *da, return info; cleanup: - r_bin_dwarf_free_debug_info (info); + rz_bin_dwarf_free_debug_info (info); return NULL; } @@ -2114,7 +2114,7 @@ static RBinDwarfDebugAbbrev *parse_abbrev_raw(const ut8 *obuf, size_t len) { while (buf && buf+1 < buf_end) { offset = buf - obuf; - buf = r_uleb128 (buf, (size_t)(buf_end-buf), &tmp, NULL); + buf = rz_uleb128 (buf, (size_t)(buf_end-buf), &tmp, NULL); if (!buf || !tmp || buf >= buf_end) { continue; } @@ -2125,7 +2125,7 @@ static RBinDwarfDebugAbbrev *parse_abbrev_raw(const ut8 *obuf, size_t len) { init_abbrev_decl (tmpdecl); tmpdecl->code = tmp; - buf = r_uleb128 (buf, (size_t)(buf_end-buf), &tmp, NULL); + buf = rz_uleb128 (buf, (size_t)(buf_end-buf), &tmp, NULL); tmpdecl->tag = tmp; tmpdecl->offset = offset; @@ -2138,14 +2138,14 @@ static RBinDwarfDebugAbbrev *parse_abbrev_raw(const ut8 *obuf, size_t len) { if (tmpdecl->count == tmpdecl->capacity) { expand_abbrev_decl (tmpdecl); } - buf = r_uleb128 (buf, (size_t)(buf_end - buf), &attr_code, NULL); + buf = rz_uleb128 (buf, (size_t)(buf_end - buf), &attr_code, NULL); if (buf >= buf_end) { break; } - buf = r_uleb128 (buf, (size_t)(buf_end - buf), &attr_form, NULL); + buf = rz_uleb128 (buf, (size_t)(buf_end - buf), &attr_form, NULL); // http://www.dwarfstd.org/doc/DWARF5.pdf#page=225 if (attr_form == DW_FORM_implicit_const) { - buf = r_leb128 (buf, (size_t)(buf_end - buf), &special); + buf = rz_leb128 (buf, (size_t)(buf_end - buf), &special); tmpdecl->defs[tmpdecl->count].special = special; } tmpdecl->defs[tmpdecl->count].attr_name = attr_code; @@ -2159,13 +2159,13 @@ static RBinDwarfDebugAbbrev *parse_abbrev_raw(const ut8 *obuf, size_t len) { } RBinSection *getsection(RBin *a, const char *sn) { - RListIter *iter; + RzListIter *iter; RBinSection *section = NULL; RBinFile *binfile = a ? a->cur: NULL; RBinObject *o = binfile ? binfile->o : NULL; if ( o && o->sections) { - r_list_foreach (o->sections, iter, section) { + rz_list_foreach (o->sections, iter, section) { if (strstr (section->name, sn)) { return section; } @@ -2185,7 +2185,7 @@ static ut8 *get_section_bytes(RBin *bin, const char *sect_name, size_t *len) { } *len = section->size; ut8 *buf = calloc (1,*len); - r_buf_read_at (binfile->buf, section->paddr, buf, *len); + rz_buf_read_at (binfile->buf, section->paddr, buf, *len); return buf; } @@ -2197,7 +2197,7 @@ static ut8 *get_section_bytes(RBin *bin, const char *sect_name, size_t *len) { * @param mode R_MODE_PRINT to print * @return RBinDwarfDebugInfo* Parsed information, NULL if error */ -R_API RBinDwarfDebugInfo *r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *bin, int mode) { +RZ_API RBinDwarfDebugInfo *rz_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *bin, int mode) { RBinDwarfDebugInfo *info = NULL; RBinSection *debug_str; RBinSection *section = getsection (bin, "debug_info"); @@ -2214,7 +2214,7 @@ R_API RBinDwarfDebugInfo *r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin if (!debug_str_buf) { goto cleanup; } - st64 ret = r_buf_read_at (binfile->buf, debug_str->paddr, + st64 ret = rz_buf_read_at (binfile->buf, debug_str->paddr, debug_str_buf, debug_str_len); if (!ret) { goto cleanup; @@ -2230,12 +2230,12 @@ R_API RBinDwarfDebugInfo *r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin if (!buf) { goto cleanup; } - if (!r_buf_read_at (binfile->buf, section->paddr, buf, len)) { + if (!rz_buf_read_at (binfile->buf, section->paddr, buf, len)) { free (buf); goto cleanup; } /* set the endianity global [HOTFIX] */ - big_end = r_bin_is_big_endian (bin); + big_end = rz_bin_is_big_endian (bin); info = parse_info_raw (binfile->sdb_addrinfo, da, buf, len, debug_str_buf, debug_str_len); @@ -2280,9 +2280,9 @@ static void row_free(void *p) { free (row); } -R_API RList *r_bin_dwarf_parse_line(RBin *bin, int mode) { +RZ_API RzList *rz_bin_dwarf_parse_line(RBin *bin, int mode) { ut8 *buf; - RList *list = NULL; + RzList *list = NULL; int len, ret; RBinSection *section = getsection (bin, "debug_line"); RBinFile *binfile = bin ? bin->cur: NULL; @@ -2295,18 +2295,18 @@ R_API RList *r_bin_dwarf_parse_line(RBin *bin, int mode) { if (!buf) { return NULL; } - ret = r_buf_read_at (binfile->buf, section->paddr, buf, len); + ret = rz_buf_read_at (binfile->buf, section->paddr, buf, len); if (ret != len) { free (buf); return NULL; } - list = r_list_newf (row_free); + list = rz_list_newf (row_free); if (!list) { free (buf); return NULL; } /* set the endianity global [HOTFIX] */ - big_end = r_bin_is_big_endian (bin); + big_end = rz_bin_is_big_endian (bin); // Actually parse the section parse_line_raw (bin, buf, len, mode); // k bin/cur/addrinfo/* @@ -2323,16 +2323,16 @@ R_API RList *r_bin_dwarf_parse_line(RBin *bin, int mode) { if (!file) { free (buf); ls_free (ls); - r_list_free (list); + rz_list_free (list); return NULL; } char *tok = strchr (file, '|'); if (tok) { *tok++ = 0; line = atoi (tok); - addr = r_num_math (NULL, sdbkv_key (kv)); + addr = rz_num_math (NULL, sdbkv_key (kv)); row = row_new (addr, file, line, 0); - r_list_append (list, row); + rz_list_append (list, row); } free (file); } @@ -2343,7 +2343,7 @@ R_API RList *r_bin_dwarf_parse_line(RBin *bin, int mode) { return list; } -R_API RList *r_bin_dwarf_parse_aranges(RBin *bin, int mode) { +RZ_API RzList *rz_bin_dwarf_parse_aranges(RBin *bin, int mode) { ut8 *buf; int ret; size_t len; @@ -2356,13 +2356,13 @@ R_API RList *r_bin_dwarf_parse_aranges(RBin *bin, int mode) { return NULL; } buf = calloc (1, len); - ret = r_buf_read_at (binfile->buf, section->paddr, buf, len); + ret = rz_buf_read_at (binfile->buf, section->paddr, buf, len); if (!ret) { free (buf); return NULL; } /* set the endianity global [HOTFIX] */ - big_end = r_bin_is_big_endian (bin); + big_end = rz_bin_is_big_endian (bin); parse_aranges_raw (buf, len, mode, bin->cb_printf); free (buf); @@ -2370,7 +2370,7 @@ R_API RList *r_bin_dwarf_parse_aranges(RBin *bin, int mode) { return NULL; } -R_API RBinDwarfDebugAbbrev *r_bin_dwarf_parse_abbrev(RBin *bin, int mode) { +RZ_API RBinDwarfDebugAbbrev *rz_bin_dwarf_parse_abbrev(RBin *bin, int mode) { size_t len = 0; ut8 *buf = get_section_bytes (bin, "debug_abbrev", &len); if (!buf) { @@ -2400,7 +2400,7 @@ static inline ut64 get_max_offset(size_t addr_size) { static inline RBinDwarfLocList *create_loc_list(ut64 offset) { RBinDwarfLocList *list = R_NEW0 (RBinDwarfLocList); if (list) { - list->list = r_list_new (); + list->list = rz_list_new (); list->offset = offset; } return list; @@ -2417,14 +2417,14 @@ static inline RBinDwarfLocRange *create_loc_range(ut64 start, ut64 end, RBinDwar } static void free_loc_table_list(RBinDwarfLocList *loc_list) { - RListIter *iter; + RzListIter *iter; RBinDwarfLocRange *range; - r_list_foreach (loc_list->list, iter, range) { + rz_list_foreach (loc_list->list, iter, range) { free (range->expression->data); free (range->expression); free (range); } - r_list_free (loc_list->list); + rz_list_free (loc_list->list); free (loc_list); } @@ -2465,7 +2465,7 @@ static HtUP *parse_loc_raw(HtUP/**/ *loc_table, con block->length = READ16 (buf); buf = fill_block_data (buf, buf_end, block); range = create_loc_range (start_addr + address_base, end_addr + address_base, block); - r_list_append (loc_list->list, range); + rz_list_append (loc_list->list, range); range = NULL; } } @@ -2482,10 +2482,10 @@ static HtUP *parse_loc_raw(HtUP/**/ *loc_table, con * * @param bin * @param addr_size machine address size used in executable (necessary for parsing) - * @return R_API* + * @return RZ_API* */ -R_API HtUP/**/ *sort_list = r_list_new (); + RzList /**/ *sort_list = rz_list_new (); /* sort the table contents by offset and print sorted a bit ugly, but I wanted to decouple the parsing and printing */ ht_up_foreach (loc_table, sort_loclists, sort_list); - RListIter *i; + RzListIter *i; RBinDwarfLocList *loc_list; - r_list_foreach (sort_list, i, loc_list) { - RListIter *j; + rz_list_foreach (sort_list, i, loc_list) { + RzListIter *j; RBinDwarfLocRange *range; ut64 base_offset = loc_list->offset; - r_list_foreach (loc_list->list, j, range) { + rz_list_foreach (loc_list->list, j, range) { print ("0x%" PFMT64x " 0x%" PFMT64x " 0x%" PFMT64x "\n", base_offset, range->start, range->end); base_offset += addr_size * 2; if (range->expression) { @@ -2548,7 +2548,7 @@ R_API void r_bin_dwarf_print_loc(HtUP /*\n", base_offset); } print ("\n"); - r_list_free (sort_list); + rz_list_free (sort_list); } static void free_loc_table_entry(HtUPKv *kv) { @@ -2557,8 +2557,8 @@ static void free_loc_table_entry(HtUPKv *kv) { } } -R_API void r_bin_dwarf_free_loc(HtUP /**/ *loc_table) { - r_return_if_fail (loc_table); +RZ_API void rz_bin_dwarf_free_loc(HtUP /**/ *loc_table) { + rz_return_if_fail (loc_table); loc_table->opt.freefn = free_loc_table_entry; ht_up_free (loc_table); } diff --git a/libr/bin/filter.c b/librz/bin/filter.c similarity index 82% rename from libr/bin/filter.c rename to librz/bin/filter.c index 9383c3afab..bb30962f34 100644 --- a/libr/bin/filter.c +++ b/librz/bin/filter.c @@ -1,23 +1,23 @@ /* radare - LGPL - Copyright 2015 - pancake */ -#include +#include #include "i/private.h" static char *__hashify(char *s, ut64 vaddr) { - r_return_val_if_fail (s, NULL); + rz_return_val_if_fail (s, NULL); char *os = s; while (*s) { if (!IS_PRINTABLE (*s)) { if (vaddr && vaddr != UT64_MAX) { - char *ret = r_str_newf ("_%" PFMT64d, vaddr); + char *ret = rz_str_newf ("_%" PFMT64d, vaddr); if (ret) { free (os); } return ret; } ut32 hash = sdb_hash (s); - char *ret = r_str_newf ("%x", hash); + char *ret = rz_str_newf ("%x", hash); if (ret) { free (os); } @@ -29,8 +29,8 @@ static char *__hashify(char *s, ut64 vaddr) { } // - name should be allocated on the heap -R_API char *r_bin_filter_name(RBinFile *bf, Sdb *db, ut64 vaddr, char *name) { - r_return_val_if_fail (db && name, NULL); +RZ_API char *rz_bin_filter_name(RBinFile *bf, Sdb *db, ut64 vaddr, char *name) { + rz_return_val_if_fail (db && name, NULL); char *resname = name; const char *uname = sdb_fmt ("%" PFMT64x ".%s", vaddr, resname); @@ -50,7 +50,7 @@ R_API char *r_bin_filter_name(RBinFile *bf, Sdb *db, ut64 vaddr, char *name) { } } if (count > 1) { - char *p = r_str_appendf (resname, "_%d", count - 1); + char *p = rz_str_appendf (resname, "_%d", count - 1); if (p) { resname = p; } @@ -61,18 +61,18 @@ R_API char *r_bin_filter_name(RBinFile *bf, Sdb *db, ut64 vaddr, char *name) { return resname; } -R_API void r_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym) { - r_return_if_fail (ht && sym && sym->name); +RZ_API void rz_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym) { + rz_return_if_fail (ht && sym && sym->name); const char *name = sym->name; // if (!strncmp (sym->name, "imp.", 4)) { // demangle symbol name depending on the language specs if any if (bf && bf->o && bf->o->lang) { - const char *lang = r_bin_lang_tostring (bf->o->lang); - char *dn = r_bin_demangle (bf, lang, sym->name, sym->vaddr, false); + const char *lang = rz_bin_lang_tostring (bf->o->lang); + char *dn = rz_bin_demangle (bf, lang, sym->name, sym->vaddr, false); if (dn && *dn) { sym->dname = dn; // XXX this is wrong but is required for this test to pass - // pmb:new pancake$ bin/r2r.js db/formats/mangling/swift + // pmb:new pancake$ bin/rz_test.js db/formats/mangling/swift sym->name = dn; // extract class information from demangled symbol name char *p = strchr (dn, '.'); @@ -111,28 +111,28 @@ R_API void r_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym) } } -R_API void r_bin_filter_symbols(RBinFile *bf, RList *list) { +RZ_API void rz_bin_filter_symbols(RBinFile *bf, RzList *list) { HtPP *ht = ht_pp_new0 (); if (!ht) { return; } - RListIter *iter; + RzListIter *iter; RBinSymbol *sym; - r_list_foreach (list, iter, sym) { + rz_list_foreach (list, iter, sym) { if (sym && sym->name && *sym->name) { - r_bin_filter_sym (bf, ht, sym->vaddr, sym); + rz_bin_filter_sym (bf, ht, sym->vaddr, sym); } } ht_pp_free (ht); } -R_API void r_bin_filter_sections(RBinFile *bf, RList *list) { +RZ_API void rz_bin_filter_sections(RBinFile *bf, RzList *list) { RBinSection *sec; Sdb *db = sdb_new0 (); - RListIter *iter; - r_list_foreach (list, iter, sec) { - char *p = r_bin_filter_name (bf, db, sec->vaddr, sec->name); + RzListIter *iter; + rz_list_foreach (list, iter, sec) { + char *p = rz_bin_filter_name (bf, db, sec->vaddr, sec->name); if (p) { sec->name = p; } @@ -191,12 +191,12 @@ static bool false_positive(const char *str) { return false; } -R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 refaddr) { +RZ_API bool rz_bin_strpurge(RBin *bin, const char *str, ut64 refaddr) { bool purge = false; if (bin->strpurge) { char *addrs = strdup (bin->strpurge); if (addrs) { - int splits = r_str_split (addrs, ','); + int splits = rz_str_split (addrs, ','); int i; char *ptr; char *range_sep; @@ -218,15 +218,15 @@ R_API bool r_bin_strpurge(RBin *bin, const char *str, ut64 refaddr) { range_sep = strchr (ptr, '-'); if (range_sep) { *range_sep = 0; - from = r_num_get (NULL, ptr); + from = rz_num_get (NULL, ptr); ptr = range_sep + 1; - to = r_num_get (NULL, ptr); + to = rz_num_get (NULL, ptr); if (refaddr >= from && refaddr <= to) { purge = !bang; continue; } } - addr = r_num_get (NULL, ptr); + addr = rz_num_get (NULL, ptr); if (addr != 0 || *ptr == '0') { if (refaddr == addr) { purge = !bang; @@ -364,8 +364,8 @@ loop_end: return true; } -R_API bool r_bin_string_filter(RBin *bin, const char *str, ut64 addr) { - if (r_bin_strpurge (bin, str, addr) || !bin_strfilter (bin, str)) { +RZ_API bool rz_bin_string_filter(RBin *bin, const char *str, ut64 addr) { + if (rz_bin_strpurge (bin, str, addr) || !bin_strfilter (bin, str)) { return false; } return true; diff --git a/libr/bin/format/bflt/bflt.c b/librz/bin/format/bflt/bflt.c similarity index 67% rename from libr/bin/format/bflt/bflt.c rename to librz/bin/format/bflt/bflt.c index aeac4c53f4..81c510710d 100644 --- a/libr/bin/format/bflt/bflt.c +++ b/librz/bin/format/bflt/bflt.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2016 - Oscar Salvador */ -#include -#include +#include +#include #include "bflt.h" -#define READ(x, i) r_read_be32 ((x) + (i)); (i) += 4; +#define READ(x, i) rz_read_be32 ((x) + (i)); (i) += 4; -RBinAddr *r_bflt_get_entry(struct r_bin_bflt_obj *bin) { +RBinAddr *rz_bflt_get_entry(struct rz_bin_bflt_obj *bin) { RBinAddr *addr = R_NEW0 (RBinAddr); if (addr && bin && bin->hdr) { addr->paddr = bin->hdr->entry; @@ -15,12 +15,12 @@ RBinAddr *r_bflt_get_entry(struct r_bin_bflt_obj *bin) { return addr; } -static int bflt_init_hdr (struct r_bin_bflt_obj *bin) { +static int bflt_init_hdr (struct rz_bin_bflt_obj *bin) { struct bflt_hdr *p_hdr; ut8 bhdr[BFLT_HDR_SIZE] = {0}; int len, i = 0; - len = r_buf_read_at (bin->b, 0, bhdr, BFLT_HDR_SIZE); + len = rz_buf_read_at (bin->b, 0, bhdr, BFLT_HDR_SIZE); if (len < 1) { eprintf ("Warning: read bFLT hdr failed\n"); goto fail; @@ -59,9 +59,9 @@ fail: return false; } -static int r_bin_bflt_init(struct r_bin_bflt_obj *obj, RBuffer *buf) { - obj->b = r_buf_ref (buf); - obj->size = r_buf_size (buf); +static int rz_bin_bflt_init(struct rz_bin_bflt_obj *obj, RBuffer *buf) { + obj->b = rz_buf_ref (buf); + obj->size = rz_buf_size (buf); obj->endian = false; obj->reloc_table = NULL; obj->got_table = NULL; @@ -73,19 +73,19 @@ static int r_bin_bflt_init(struct r_bin_bflt_obj *obj, RBuffer *buf) { return true; } -struct r_bin_bflt_obj *r_bin_bflt_new_buf(RBuffer *buf) { - struct r_bin_bflt_obj *bin = R_NEW0 (struct r_bin_bflt_obj); - if (bin && r_bin_bflt_init (bin, buf)) { +struct rz_bin_bflt_obj *rz_bin_bflt_new_buf(RBuffer *buf) { + struct rz_bin_bflt_obj *bin = R_NEW0 (struct rz_bin_bflt_obj); + if (bin && rz_bin_bflt_init (bin, buf)) { return bin; } - r_bin_bflt_free (bin); + rz_bin_bflt_free (bin); return NULL; } -void r_bin_bflt_free(struct r_bin_bflt_obj *obj) { +void rz_bin_bflt_free(struct rz_bin_bflt_obj *obj) { if (obj) { R_FREE (obj->hdr); - r_buf_free (obj->b); + rz_buf_free (obj->b); R_FREE (obj); } } diff --git a/libr/bin/format/bflt/bflt.h b/librz/bin/format/bflt/bflt.h similarity index 79% rename from libr/bin/format/bflt/bflt.h rename to librz/bin/format/bflt/bflt.h index be91d949ae..a831b7eabe 100644 --- a/libr/bin/format/bflt/bflt.h +++ b/librz/bin/format/bflt/bflt.h @@ -3,10 +3,10 @@ #ifndef BFLT_H #define BFLT_H -#include -#include -#include -#include +#include +#include +#include +#include /* Version 4 */ #define FLAT_VERSION 0x00000004L @@ -38,7 +38,7 @@ struct reloc_struct_t { ut32 data_offset; }; -struct r_bin_bflt_obj { +struct rz_bin_bflt_obj { struct bflt_hdr *hdr; struct reloc_struct_t *reloc_table; struct reloc_struct_t *got_table; @@ -51,8 +51,8 @@ struct r_bin_bflt_obj { #define BFLT_HDR_SIZE sizeof (struct bflt_hdr) #define VALID_GOT_ENTRY(x) (x != 0xFFFFFFFF) -RBinAddr *r_bflt_get_entry(struct r_bin_bflt_obj *bin); -struct r_bin_bflt_obj *r_bin_bflt_new_buf(RBuffer *buf); -void r_bin_bflt_free (struct r_bin_bflt_obj *obj); +RBinAddr *rz_bflt_get_entry(struct rz_bin_bflt_obj *bin); +struct rz_bin_bflt_obj *rz_bin_bflt_new_buf(RBuffer *buf); +void rz_bin_bflt_free (struct rz_bin_bflt_obj *obj); #endif diff --git a/libr/bin/format/coff/coff.c b/librz/bin/format/coff/coff.c similarity index 69% rename from libr/bin/format/coff/coff.c rename to librz/bin/format/coff/coff.c index 48040a6421..8a06c94463 100644 --- a/libr/bin/format/coff/coff.c +++ b/librz/bin/format/coff/coff.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2008-2019 pancake, inisider */ -#include +#include #include "coff.h" #define bprintf if(obj->verbose)eprintf -bool r_coff_supported_arch(const ut8 *buf) { +bool rz_coff_supported_arch(const ut8 *buf) { ut16 arch = *(ut16*)buf; switch (arch) { case COFF_FILE_MACHINE_AMD64: @@ -22,7 +22,7 @@ bool r_coff_supported_arch(const ut8 *buf) { } } -char *r_coff_symbol_name(struct r_bin_coff_obj *obj, void *ptr) { +char *rz_coff_symbol_name(struct rz_bin_coff_obj *obj, void *ptr) { char n[256] = {0}; int len = 0, offset = 0; union { @@ -36,13 +36,13 @@ char *r_coff_symbol_name(struct r_bin_coff_obj *obj, void *ptr) { return NULL; } if (p->zero) { - return r_str_ndup (p->name, 8); + return rz_str_ndup (p->name, 8); } offset = obj->hdr.f_symptr + obj->hdr.f_nsyms * sizeof (struct coff_symbol) + p->offset; if (offset > obj->size) { return NULL; } - len = r_buf_read_at (obj->b, offset, (ut8*)n, sizeof (n)); + len = rz_buf_read_at (obj->b, offset, (ut8*)n, sizeof (n)); if (len < 1) { return NULL; } @@ -51,7 +51,7 @@ char *r_coff_symbol_name(struct r_bin_coff_obj *obj, void *ptr) { return strdup (n); } -static int r_coff_rebase_sym(struct r_bin_coff_obj *obj, RBinAddr *addr, struct coff_symbol *sym) { +static int rz_coff_rebase_sym(struct rz_bin_coff_obj *obj, RBinAddr *addr, struct coff_symbol *sym) { if (sym->n_scnum < 1 || sym->n_scnum > obj->hdr.f_nscns) { return 0; } @@ -61,7 +61,7 @@ static int r_coff_rebase_sym(struct r_bin_coff_obj *obj, RBinAddr *addr, struct /* Try to get a valid entrypoint using the methods outlined in * http://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_mono/ld.html#SEC24 */ -RBinAddr *r_coff_get_entry(struct r_bin_coff_obj *obj) { +RBinAddr *rz_coff_get_entry(struct rz_bin_coff_obj *obj) { RBinAddr *addr = R_NEW0 (RBinAddr); int i; if (!addr) { @@ -78,14 +78,14 @@ RBinAddr *r_coff_get_entry(struct r_bin_coff_obj *obj) { for (i = 0; i < obj->hdr.f_nsyms; i++) { if ((!strcmp (obj->symbols[i].n_name, "_start") || !strcmp (obj->symbols[i].n_name, "start")) && - r_coff_rebase_sym (obj, addr, &obj->symbols[i])) { + rz_coff_rebase_sym (obj, addr, &obj->symbols[i])) { return addr; } } for (i = 0; i < obj->hdr.f_nsyms; i++) { if ((!strcmp (obj->symbols[i].n_name, "_main") || !strcmp (obj->symbols[i].n_name, "main")) && - r_coff_rebase_sym (obj, addr, &obj->symbols[i])) { + rz_coff_rebase_sym (obj, addr, &obj->symbols[i])) { return addr; } } @@ -108,8 +108,8 @@ RBinAddr *r_coff_get_entry(struct r_bin_coff_obj *obj) { return addr; } -static bool r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) { - ut16 magic = r_buf_read_ble16_at (obj->b, 0, COFF_IS_LITTLE_ENDIAN); +static bool rz_bin_coff_init_hdr(struct rz_bin_coff_obj *obj) { + ut16 magic = rz_buf_read_ble16_at (obj->b, 0, COFF_IS_LITTLE_ENDIAN); switch (magic) { case COFF_FILE_MACHINE_H8300: case COFF_FILE_MACHINE_AMD29KBE: @@ -119,12 +119,12 @@ static bool r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) { obj->endian = COFF_IS_LITTLE_ENDIAN; } int ret = 0; - ret = r_buf_fread_at (obj->b, 0, (ut8 *)&obj->hdr, obj->endian? "2S3I2S": "2s3i2s", 1); + ret = rz_buf_fread_at (obj->b, 0, (ut8 *)&obj->hdr, obj->endian? "2S3I2S": "2s3i2s", 1); if (ret != sizeof (struct coff_hdr)) { return false; } if (obj->hdr.f_magic == COFF_FILE_TI_COFF) { - ret = r_buf_fread (obj->b, (ut8 *)&obj->target_id, obj->endian? "S": "s", 1); + ret = rz_buf_fread (obj->b, (ut8 *)&obj->target_id, obj->endian? "S": "s", 1); if (ret != sizeof (ut16)) { return false; } @@ -132,12 +132,12 @@ static bool r_bin_coff_init_hdr(struct r_bin_coff_obj *obj) { return true; } -static bool r_bin_coff_init_opt_hdr(struct r_bin_coff_obj *obj) { +static bool rz_bin_coff_init_opt_hdr(struct rz_bin_coff_obj *obj) { int ret; if (!obj->hdr.f_opthdr) { return false; } - ret = r_buf_fread_at (obj->b, sizeof (struct coff_hdr), + ret = rz_buf_fread_at (obj->b, sizeof (struct coff_hdr), (ut8 *)&obj->opt_hdr, obj->endian? "2S6I": "2s6i", 1); if (ret != sizeof (struct coff_opt_hdr)) { return false; @@ -145,7 +145,7 @@ static bool r_bin_coff_init_opt_hdr(struct r_bin_coff_obj *obj) { return true; } -static bool r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) { +static bool rz_bin_coff_init_scn_hdr(struct rz_bin_coff_obj *obj) { int ret, size; ut64 offset = sizeof (struct coff_hdr) + (obj->hdr.f_opthdr ? sizeof (struct coff_opt_hdr) : 0); if (obj->hdr.f_magic == COFF_FILE_TI_COFF) { @@ -159,7 +159,7 @@ static bool r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) { if (!obj->scn_hdrs) { return false; } - ret = r_buf_fread_at (obj->b, offset, (ut8 *)obj->scn_hdrs, obj->endian? "8c6I2S1I": "8c6i2s1i", obj->hdr.f_nscns); + ret = rz_buf_fread_at (obj->b, offset, (ut8 *)obj->scn_hdrs, obj->endian? "8c6I2S1I": "8c6i2s1i", obj->hdr.f_nscns); if (ret != size) { R_FREE (obj->scn_hdrs); return false; @@ -167,7 +167,7 @@ static bool r_bin_coff_init_scn_hdr(struct r_bin_coff_obj *obj) { return true; } -static bool r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) { +static bool rz_bin_coff_init_symtable(struct rz_bin_coff_obj *obj) { int ret, size; ut64 offset = obj->hdr.f_symptr; if (obj->hdr.f_nsyms >= 0xffff || !obj->hdr.f_nsyms) { // too much symbols, probably not allocatable @@ -184,7 +184,7 @@ static bool r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) { if (!obj->symbols) { return false; } - ret = r_buf_fread_at (obj->b, offset, (ut8 *)obj->symbols, obj->endian? "8c1I2S2c": "8c1i2s2c", obj->hdr.f_nsyms); + ret = rz_buf_fread_at (obj->b, offset, (ut8 *)obj->symbols, obj->endian? "8c1I2S2c": "8c1i2s2c", obj->hdr.f_nsyms); if (ret != size) { R_FREE (obj->symbols); return false; @@ -192,39 +192,39 @@ static bool r_bin_coff_init_symtable(struct r_bin_coff_obj *obj) { return true; } -static int r_bin_coff_init(struct r_bin_coff_obj *obj, RBuffer *buf, bool verbose) { - obj->b = r_buf_ref (buf); - obj->size = r_buf_size (buf); +static int rz_bin_coff_init(struct rz_bin_coff_obj *obj, RBuffer *buf, bool verbose) { + obj->b = rz_buf_ref (buf); + obj->size = rz_buf_size (buf); obj->verbose = verbose; obj->sym_ht = ht_up_new0 (); obj->imp_ht = ht_up_new0 (); - if (!r_bin_coff_init_hdr (obj)) { + if (!rz_bin_coff_init_hdr (obj)) { bprintf ("Warning: failed to init hdr\n"); return false; } - r_bin_coff_init_opt_hdr (obj); - if (!r_bin_coff_init_scn_hdr (obj)) { + rz_bin_coff_init_opt_hdr (obj); + if (!rz_bin_coff_init_scn_hdr (obj)) { bprintf ("Warning: failed to init section header\n"); return false; } - if (!r_bin_coff_init_symtable (obj)) { + if (!rz_bin_coff_init_symtable (obj)) { bprintf ("Warning: failed to init symtable\n"); return false; } return true; } -void r_bin_coff_free(struct r_bin_coff_obj *obj) { +void rz_bin_coff_free(struct rz_bin_coff_obj *obj) { ht_up_free (obj->sym_ht); ht_up_free (obj->imp_ht); free (obj->scn_hdrs); free (obj->symbols); - r_buf_free (obj->b); + rz_buf_free (obj->b); free (obj); } -struct r_bin_coff_obj* r_bin_coff_new_buf(RBuffer *buf, bool verbose) { - struct r_bin_coff_obj* bin = R_NEW0 (struct r_bin_coff_obj); - r_bin_coff_init (bin, buf, verbose); +struct rz_bin_coff_obj* rz_bin_coff_new_buf(RBuffer *buf, bool verbose) { + struct rz_bin_coff_obj* bin = R_NEW0 (struct rz_bin_coff_obj); + rz_bin_coff_init (bin, buf, verbose); return bin; } diff --git a/libr/bin/format/coff/coff.h b/librz/bin/format/coff/coff.h similarity index 53% rename from libr/bin/format/coff/coff.h rename to librz/bin/format/coff/coff.h index 554f48d2cb..4b2740669d 100644 --- a/libr/bin/format/coff/coff.h +++ b/librz/bin/format/coff/coff.h @@ -3,10 +3,10 @@ #ifndef COFF_H #define COFF_H -#include -#include -#include -#include +#include +#include +#include +#include #include #define COFF_IS_BIG_ENDIAN 1 @@ -14,7 +14,7 @@ #include "coff_specs.h" -struct r_bin_coff_obj { +struct rz_bin_coff_obj { struct coff_hdr hdr; struct coff_opt_hdr opt_hdr; struct coff_scn_hdr *scn_hdrs; @@ -31,10 +31,10 @@ struct r_bin_coff_obj { HtUP *imp_ht; }; -bool r_coff_supported_arch(const ut8 *buf); /* Reads two bytes from buf. */ -struct r_bin_coff_obj* r_bin_coff_new_buf(RBuffer *buf, bool verbose); -void r_bin_coff_free(struct r_bin_coff_obj *obj); -RBinAddr *r_coff_get_entry(struct r_bin_coff_obj *obj); -char *r_coff_symbol_name (struct r_bin_coff_obj *obj, void *ptr); +bool rz_coff_supported_arch(const ut8 *buf); /* Reads two bytes from buf. */ +struct rz_bin_coff_obj* rz_bin_coff_new_buf(RBuffer *buf, bool verbose); +void rz_bin_coff_free(struct rz_bin_coff_obj *obj); +RBinAddr *rz_coff_get_entry(struct rz_bin_coff_obj *obj); +char *rz_coff_symbol_name (struct rz_bin_coff_obj *obj, void *ptr); #endif /* COFF_H */ diff --git a/libr/bin/format/coff/coff_specs.h b/librz/bin/format/coff/coff_specs.h similarity index 98% rename from libr/bin/format/coff/coff_specs.h rename to librz/bin/format/coff/coff_specs.h index 02095fa844..5dc644319c 100644 --- a/libr/bin/format/coff/coff_specs.h +++ b/librz/bin/format/coff/coff_specs.h @@ -2,7 +2,7 @@ #ifndef COFF_SPECS_H #define COFF_SPECS_H -#include +#include #define COFF_FILE_MACHINE_UNKNOWN 0x0 #define COFF_FILE_MACHINE_AM33 0x1d3 @@ -202,9 +202,9 @@ struct coff_symbol { R_PACKED ( struct coff_reloc { - ut32 r_vaddr; /* Reference Address */ - ut32 r_symndx; /* Symbol index */ - ut16 r_type; /* Type of relocation */ + ut32 rz_vaddr; /* Reference Address */ + ut32 rz_symndx; /* Symbol index */ + ut16 rz_type; /* Type of relocation */ }); #define COFF_SYM_GET_DTYPE(type) (((type) >> 4) & 3) diff --git a/libr/bin/format/dex/dex.c b/librz/bin/format/dex/dex.c similarity index 60% rename from libr/bin/format/dex/dex.c rename to librz/bin/format/dex/dex.c index 0130dbf514..c2c705b3f8 100644 --- a/libr/bin/format/dex/dex.c +++ b/librz/bin/format/dex/dex.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, h4ng3r */ -#include -#include +#include +#include #include "dex.h" -char* r_bin_dex_get_version(RBinDexObj *bin) { - r_return_val_if_fail (bin, NULL); +char* rz_bin_dex_get_version(RBinDexObj *bin) { + rz_return_val_if_fail (bin, NULL); char* version = calloc (1, 8); if (version) { - r_buf_read_at (bin->b, 4, (ut8*)version, 3); + rz_buf_read_at (bin->b, 4, (ut8*)version, 3); return version; } return NULL; } -void r_bin_dex_free(RBinDexObj *dex) { +void rz_bin_dex_free(RBinDexObj *dex) { struct dex_header_t *dexhdr = &dex->header; if (dex->cal_strings) { size_t i; @@ -26,16 +26,16 @@ void r_bin_dex_free(RBinDexObj *dex) { free (dex); } -RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { - r_return_val_if_fail (buf, NULL); +RBinDexObj *rz_bin_dex_new_buf(RBuffer *buf) { + rz_return_val_if_fail (buf, NULL); RBinDexObj *bin = R_NEW0 (RBinDexObj); int i; struct dex_header_t *dexhdr; if (!bin) { goto fail; } - bin->size = r_buf_size (buf); - bin->b = r_buf_ref (buf); + bin->size = rz_buf_size (buf); + bin->b = rz_buf_ref (buf); /* header */ if (bin->size < sizeof (struct dex_header_t)) { goto fail; @@ -46,32 +46,32 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { goto fail; } - r_buf_seek (bin->b, 0, R_BUF_SET); - r_buf_read (bin->b, (ut8 *)&dexhdr->magic, 8); - dexhdr->checksum = r_buf_read_le32 (bin->b); - r_buf_read (bin->b, (ut8 *)&dexhdr->signature, 20); - dexhdr->size = r_buf_read_le32 (bin->b); - dexhdr->header_size = r_buf_read_le32 (bin->b); - dexhdr->endian = r_buf_read_le32 (bin->b); + rz_buf_seek (bin->b, 0, R_BUF_SET); + rz_buf_read (bin->b, (ut8 *)&dexhdr->magic, 8); + dexhdr->checksum = rz_buf_read_le32 (bin->b); + rz_buf_read (bin->b, (ut8 *)&dexhdr->signature, 20); + dexhdr->size = rz_buf_read_le32 (bin->b); + dexhdr->header_size = rz_buf_read_le32 (bin->b); + dexhdr->endian = rz_buf_read_le32 (bin->b); // TODO: this offsets and size will be used for checking, // so they should be checked. Check overlap, < 0, > bin.size - dexhdr->linksection_size = r_buf_read_le32 (bin->b); - dexhdr->linksection_offset = r_buf_read_le32 (bin->b); - dexhdr->map_offset = r_buf_read_le32 (bin->b); - dexhdr->strings_size = r_buf_read_le32 (bin->b); - dexhdr->strings_offset = r_buf_read_le32 (bin->b); - dexhdr->types_size = r_buf_read_le32 (bin->b); - dexhdr->types_offset = r_buf_read_le32 (bin->b); - dexhdr->prototypes_size = r_buf_read_le32 (bin->b); - dexhdr->prototypes_offset = r_buf_read_le32 (bin->b); - dexhdr->fields_size = r_buf_read_le32 (bin->b); - dexhdr->fields_offset = r_buf_read_le32 (bin->b); - dexhdr->method_size = r_buf_read_le32 (bin->b); - dexhdr->method_offset = r_buf_read_le32 (bin->b); - dexhdr->class_size = r_buf_read_le32 (bin->b); - dexhdr->class_offset = r_buf_read_le32 (bin->b); - dexhdr->data_size = r_buf_read_le32 (bin->b); - dexhdr->data_offset = r_buf_read_le32 (bin->b); + dexhdr->linksection_size = rz_buf_read_le32 (bin->b); + dexhdr->linksection_offset = rz_buf_read_le32 (bin->b); + dexhdr->map_offset = rz_buf_read_le32 (bin->b); + dexhdr->strings_size = rz_buf_read_le32 (bin->b); + dexhdr->strings_offset = rz_buf_read_le32 (bin->b); + dexhdr->types_size = rz_buf_read_le32 (bin->b); + dexhdr->types_offset = rz_buf_read_le32 (bin->b); + dexhdr->prototypes_size = rz_buf_read_le32 (bin->b); + dexhdr->prototypes_offset = rz_buf_read_le32 (bin->b); + dexhdr->fields_size = rz_buf_read_le32 (bin->b); + dexhdr->fields_offset = rz_buf_read_le32 (bin->b); + dexhdr->method_size = rz_buf_read_le32 (bin->b); + dexhdr->method_offset = rz_buf_read_le32 (bin->b); + dexhdr->class_size = rz_buf_read_le32 (bin->b); + dexhdr->class_offset = rz_buf_read_le32 (bin->b); + dexhdr->data_size = rz_buf_read_le32 (bin->b); + dexhdr->data_offset = rz_buf_read_le32 (bin->b); /* strings */ #define STRINGS_SIZE ((dexhdr->strings_size + 1) * sizeof (ut32)) @@ -82,14 +82,14 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { if (!bin->strings) { goto fail; } - r_buf_read_at (bin->b, dexhdr->strings_offset, (ut8*)bin->strings, dexhdr->strings_size * sizeof (ut32)); + rz_buf_read_at (bin->b, dexhdr->strings_offset, (ut8*)bin->strings, dexhdr->strings_size * sizeof (ut32)); // TODO: this is unnecessary on Big endian machines for (i = 0; i < dexhdr->strings_size; i++) { ut64 offset = dexhdr->strings_offset + (i * sizeof (ut32)); if (offset + 4 > bin->size) { break; } - bin->strings[i] = r_read_le32 (&bin->strings[i]); + bin->strings[i] = rz_read_le32 (&bin->strings[i]); } /* classes */ // TODO: not sure about if that is needed @@ -112,15 +112,15 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { free (bin->classes); goto fail; } - r_buf_seek (bin->b, offset, R_BUF_SET); - bin->classes[i].class_id = r_buf_read_le32 (bin->b); - bin->classes[i].access_flags = r_buf_read_le32 (bin->b); - bin->classes[i].super_class = r_buf_read_le32 (bin->b); - bin->classes[i].interfaces_offset = r_buf_read_le32 (bin->b); - bin->classes[i].source_file = r_buf_read_le32 (bin->b); - bin->classes[i].anotations_offset = r_buf_read_le32 (bin->b); - bin->classes[i].class_data_offset = r_buf_read_le32 (bin->b); - bin->classes[i].static_values_offset = r_buf_read_le32 (bin->b); + rz_buf_seek (bin->b, offset, R_BUF_SET); + bin->classes[i].class_id = rz_buf_read_le32 (bin->b); + bin->classes[i].access_flags = rz_buf_read_le32 (bin->b); + bin->classes[i].super_class = rz_buf_read_le32 (bin->b); + bin->classes[i].interfaces_offset = rz_buf_read_le32 (bin->b); + bin->classes[i].source_file = rz_buf_read_le32 (bin->b); + bin->classes[i].anotations_offset = rz_buf_read_le32 (bin->b); + bin->classes[i].class_data_offset = rz_buf_read_le32 (bin->b); + bin->classes[i].static_values_offset = rz_buf_read_le32 (bin->b); } /* methods */ @@ -142,10 +142,10 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { free (bin->methods); goto fail; } - r_buf_seek (bin->b, offset, R_BUF_SET); - bin->methods[i].class_id = r_buf_read_le16 (bin->b); - bin->methods[i].proto_id = r_buf_read_le16 (bin->b); - bin->methods[i].name_id = r_buf_read_le32 (bin->b); + rz_buf_seek (bin->b, offset, R_BUF_SET); + bin->methods[i].class_id = rz_buf_read_le16 (bin->b); + bin->methods[i].proto_id = rz_buf_read_le16 (bin->b); + bin->methods[i].name_id = rz_buf_read_le32 (bin->b); } /* types */ @@ -164,7 +164,7 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { free (bin->types); goto fail; } - bin->types[i].descriptor_id = r_buf_read_le32_at (bin->b, offset); + bin->types[i].descriptor_id = rz_buf_read_le32_at (bin->b, offset); } /* fields */ @@ -188,10 +188,10 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { free (bin->fields); goto fail; } - r_buf_seek (bin->b, offset, R_BUF_SET); - bin->fields[i].class_id = r_buf_read_le16 (bin->b); - bin->fields[i].type_id = r_buf_read_le16 (bin->b); - bin->fields[i].name_id = r_buf_read_le32 (bin->b); + rz_buf_seek (bin->b, offset, R_BUF_SET); + bin->fields[i].class_id = rz_buf_read_le16 (bin->b); + bin->fields[i].type_id = rz_buf_read_le16 (bin->b); + bin->fields[i].name_id = rz_buf_read_le32 (bin->b); } /* proto */ @@ -216,15 +216,15 @@ RBinDexObj *r_bin_dex_new_buf(RBuffer *buf) { free (bin->protos); goto fail; } - r_buf_seek (bin->b, offset, R_BUF_SET); - bin->protos[i].shorty_id = r_buf_read_le32 (bin->b); - bin->protos[i].return_type_id = r_buf_read_le32 (bin->b); - bin->protos[i].parameters_off = r_buf_read_le32 (bin->b); + rz_buf_seek (bin->b, offset, R_BUF_SET); + bin->protos[i].shorty_id = rz_buf_read_le32 (bin->b); + bin->protos[i].return_type_id = rz_buf_read_le32 (bin->b); + bin->protos[i].parameters_off = rz_buf_read_le32 (bin->b); } return bin; fail: if (bin) { - r_buf_free (bin->b); + rz_buf_free (bin->b); free (bin); } return NULL; diff --git a/libr/bin/format/dex/dex.h b/librz/bin/format/dex/dex.h similarity index 85% rename from libr/bin/format/dex/dex.h rename to librz/bin/format/dex/dex.h index 3ee7db6401..891d33b211 100644 --- a/libr/bin/format/dex/dex.h +++ b/librz/bin/format/dex/dex.h @@ -1,10 +1,10 @@ #ifndef DEX_H #define DEX_H -#include -#include -#include -#include +#include +#include +#include +#include #define R_BIN_DEX_MAXSTR 256 #define DEX_CLASS_SIZE (32) @@ -100,7 +100,7 @@ typedef struct dex_class_data_item_t { ut64 virtual_methods_size; }) RBinDexClassData; -typedef struct r_bin_dex_obj_t { +typedef struct rz_bin_dex_obj_t { int size; const char *file; RBuffer *b; @@ -111,11 +111,11 @@ typedef struct r_bin_dex_obj_t { struct dex_field_t *fields; struct dex_method_t *methods; struct dex_class_t *classes; - RList *methods_list; - RList *trycatch_list; - RList *imports_list; - RList *classes_list; - RList *lines_list; + RzList *methods_list; + RzList *trycatch_list; + RzList *imports_list; + RzList *classes_list; + RzList *lines_list; ut64 code_from; ut64 code_to; char *version; @@ -123,7 +123,7 @@ typedef struct r_bin_dex_obj_t { char **cal_strings; } RBinDexObj; -struct r_bin_dex_str_t { +struct rz_bin_dex_str_t { char str[R_BIN_DEX_MAXSTR]; ut64 offset; ut64 ordinal; @@ -158,9 +158,9 @@ struct dex_debug_local_t { ut16 endAddress; }; -char* r_bin_dex_get_version(struct r_bin_dex_obj_t* bin); -void r_bin_dex_free(struct r_bin_dex_obj_t *bin); -struct r_bin_dex_obj_t *r_bin_dex_new_buf(RBuffer *buf); -struct r_bin_dex_str_t *r_bin_dex_get_strings(struct r_bin_dex_obj_t *bin); +char* rz_bin_dex_get_version(struct rz_bin_dex_obj_t* bin); +void rz_bin_dex_free(struct rz_bin_dex_obj_t *bin); +struct rz_bin_dex_obj_t *rz_bin_dex_new_buf(RBuffer *buf); +struct rz_bin_dex_str_t *rz_bin_dex_get_strings(struct rz_bin_dex_obj_t *bin); #endif diff --git a/libr/bin/format/dmp/dmp64.c b/librz/bin/format/dmp/dmp64.c similarity index 58% rename from libr/bin/format/dmp/dmp64.c rename to librz/bin/format/dmp/dmp64.c index 85f4be4990..56afbd8432 100644 --- a/libr/bin/format/dmp/dmp64.c +++ b/librz/bin/format/dmp/dmp64.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2020 - abcSup */ +/* rizin - LGPL - Copyright 2020 - abcSup */ -#include -#include +#include +#include #include "dmp64.h" -static int r_bin_dmp64_init_memory_runs(struct r_bin_dmp64_obj_t *obj) { +static int rz_bin_dmp64_init_memory_runs(struct rz_bin_dmp64_obj_t *obj) { int i, j; dmp64_p_memory_desc *mem_desc = &obj->header->PhysicalMemoryBlockBuffer; if (!memcmp (mem_desc, DMP_UNUSED_MAGIC, 4)) { @@ -13,17 +13,17 @@ static int r_bin_dmp64_init_memory_runs(struct r_bin_dmp64_obj_t *obj) { return false; } ut64 num_runs = mem_desc->NumberOfRuns; - if (num_runs * sizeof (dmp_p_memory_run) >= r_offsetof (dmp64_header, ContextRecord)) { + if (num_runs * sizeof (dmp_p_memory_run) >= rz_offsetof (dmp64_header, ContextRecord)) { eprintf ("Warning: Invalid PhysicalMemoryDescriptor\n"); return false; } - obj->pages = r_list_newf (free); + obj->pages = rz_list_newf (free); if (!obj->pages) { return false; } dmp_p_memory_run *runs = calloc (num_runs, sizeof (dmp_p_memory_run)); - ut64 num_runs_offset = r_offsetof (dmp64_header, PhysicalMemoryBlockBuffer) + r_offsetof (dmp64_p_memory_desc, NumberOfRuns); - if (r_buf_read_at (obj->b, num_runs_offset, (ut8*)runs, num_runs * sizeof (dmp_p_memory_run)) < 0) { + ut64 num_runs_offset = rz_offsetof (dmp64_header, PhysicalMemoryBlockBuffer) + rz_offsetof (dmp64_p_memory_desc, NumberOfRuns); + if (rz_buf_read_at (obj->b, num_runs_offset, (ut8*)runs, num_runs * sizeof (dmp_p_memory_run)) < 0) { eprintf ("Warning: read memory runs\n"); free (runs); return false; @@ -41,7 +41,7 @@ static int r_bin_dmp64_init_memory_runs(struct r_bin_dmp64_obj_t *obj) { } page->start = (run->BasePage + j) * PAGE_SIZE ; page->file_offset = base + num_page * PAGE_SIZE; - r_list_append (obj->pages, page); + rz_list_append (obj->pages, page); num_page++; } } @@ -53,12 +53,12 @@ static int r_bin_dmp64_init_memory_runs(struct r_bin_dmp64_obj_t *obj) { return true; } -static int r_bin_dmp64_init_header(struct r_bin_dmp64_obj_t *obj) { +static int rz_bin_dmp64_init_header(struct rz_bin_dmp64_obj_t *obj) { if (!(obj->header = R_NEW0 (dmp64_header))) { - r_sys_perror ("R_NEW0 (header)"); + rz_sys_perror ("R_NEW0 (header)"); return false; } - if (r_buf_read_at (obj->b, 0, (ut8*)obj->header, sizeof (dmp64_header)) < 0) { + if (rz_buf_read_at (obj->b, 0, (ut8*)obj->header, sizeof (dmp64_header)) < 0) { eprintf ("Warning: read header\n"); return false; } @@ -67,23 +67,23 @@ static int r_bin_dmp64_init_header(struct r_bin_dmp64_obj_t *obj) { return true; } -static int r_bin_dmp64_init_bmp_pages(struct r_bin_dmp64_obj_t *obj) { +static int rz_bin_dmp64_init_bmp_pages(struct rz_bin_dmp64_obj_t *obj) { int i; if (!obj->bmp_header) { return false; } - obj->pages = r_list_newf (free); + obj->pages = rz_list_newf (free); if (!obj->pages) { return false; } ut64 paddr_base = obj->bmp_header->FirstPage; ut64 num_pages = obj->bmp_header->Pages; - RBitmap *bitmap = r_bitmap_new(num_pages); - r_bitmap_set_bytes (bitmap, obj->bitmap, num_pages / 8); + RBitmap *bitmap = rz_bitmap_new(num_pages); + rz_bitmap_set_bytes (bitmap, obj->bitmap, num_pages / 8); ut64 num_bitset = 0; for(i = 0; i < num_pages; i++) { - if (!r_bitmap_test(bitmap, i)) { + if (!rz_bitmap_test(bitmap, i)) { continue; } dmp_page_desc *page = R_NEW0 (dmp_page_desc); @@ -92,7 +92,7 @@ static int r_bin_dmp64_init_bmp_pages(struct r_bin_dmp64_obj_t *obj) { } page->start = i * PAGE_SIZE; page->file_offset = paddr_base + num_bitset * PAGE_SIZE; - r_list_append (obj->pages, page); + rz_list_append (obj->pages, page); num_bitset++; } if (obj->bmp_header->TotalPresentPages != num_bitset) { @@ -100,16 +100,16 @@ static int r_bin_dmp64_init_bmp_pages(struct r_bin_dmp64_obj_t *obj) { return false; } - r_bitmap_free (bitmap); + rz_bitmap_free (bitmap); return true; } -static int r_bin_dmp64_init_bmp_header(struct r_bin_dmp64_obj_t *obj) { +static int rz_bin_dmp64_init_bmp_header(struct rz_bin_dmp64_obj_t *obj) { if (!(obj->bmp_header = R_NEW0 (dmp_bmp_header))) { - r_sys_perror ("R_NEW0 (dmp_bmp_header)"); + rz_sys_perror ("R_NEW0 (dmp_bmp_header)"); return false; } - if (r_buf_read_at (obj->b, sizeof (dmp64_header), (ut8*)obj->bmp_header, sizeof (dmp_bmp_header) - sizeof (ut8*)) < 0) { + if (rz_buf_read_at (obj->b, sizeof (dmp64_header), (ut8*)obj->bmp_header, sizeof (dmp_bmp_header) - sizeof (ut8*)) < 0) { eprintf ("Warning: read bmp_header\n"); return false; } @@ -119,7 +119,7 @@ static int r_bin_dmp64_init_bmp_header(struct r_bin_dmp64_obj_t *obj) { } ut64 bitmapsize = obj->bmp_header->Pages / 8; obj->bitmap = calloc (1, bitmapsize); - if (r_buf_read_at (obj->b, sizeof (dmp64_header) + sizeof (dmp_bmp_header) - sizeof (ut8*), obj->bitmap, bitmapsize) < 0) { + if (rz_buf_read_at (obj->b, sizeof (dmp64_header) + sizeof (dmp_bmp_header) - sizeof (ut8*), obj->bitmap, bitmapsize) < 0) { eprintf ("Warning: read bitmap\n"); return false; }; @@ -127,19 +127,19 @@ static int r_bin_dmp64_init_bmp_header(struct r_bin_dmp64_obj_t *obj) { return true; } -static int r_bin_dmp64_init(struct r_bin_dmp64_obj_t *obj) { - if (!r_bin_dmp64_init_header (obj)) { +static int rz_bin_dmp64_init(struct rz_bin_dmp64_obj_t *obj) { + if (!rz_bin_dmp64_init_header (obj)) { eprintf ("Warning: Invalid Kernel Dump x64 Format\n"); return false; } switch (obj->header->DumpType) { case DMP_DUMPTYPE_BITMAPFULL: case DMP_DUMPTYPE_BITMAPKERNEL: - r_bin_dmp64_init_bmp_header (obj); - r_bin_dmp64_init_bmp_pages (obj); + rz_bin_dmp64_init_bmp_header (obj); + rz_bin_dmp64_init_bmp_pages (obj); break; case DMP_DUMPTYPE_FULL: - r_bin_dmp64_init_memory_runs (obj); + rz_bin_dmp64_init_memory_runs (obj); break; default: break; @@ -148,32 +148,32 @@ static int r_bin_dmp64_init(struct r_bin_dmp64_obj_t *obj) { return true; } -void r_bin_dmp64_free(struct r_bin_dmp64_obj_t *obj) { +void rz_bin_dmp64_free(struct rz_bin_dmp64_obj_t *obj) { if (!obj) { return; } - r_buf_free (obj->b); + rz_buf_free (obj->b); obj->b = NULL; free (obj->header); free (obj->bmp_header); free (obj->runs); free (obj->bitmap); - r_list_free (obj->pages); + rz_list_free (obj->pages); free (obj); } -struct r_bin_dmp64_obj_t *r_bin_dmp64_new_buf(RBuffer* buf) { - struct r_bin_dmp64_obj_t *obj = R_NEW0 (struct r_bin_dmp64_obj_t); +struct rz_bin_dmp64_obj_t *rz_bin_dmp64_new_buf(RBuffer* buf) { + struct rz_bin_dmp64_obj_t *obj = R_NEW0 (struct rz_bin_dmp64_obj_t); if (!obj) { return NULL; } obj->kv = sdb_new0 (); - obj->size = (ut32) r_buf_size (buf); - obj->b = r_buf_ref (buf); + obj->size = (ut32) rz_buf_size (buf); + obj->b = rz_buf_ref (buf); - if (!r_bin_dmp64_init (obj)) { - r_bin_dmp64_free (obj); + if (!rz_bin_dmp64_init (obj)) { + rz_bin_dmp64_free (obj); return NULL; } diff --git a/libr/bin/format/dmp/dmp64.h b/librz/bin/format/dmp/dmp64.h similarity index 55% rename from libr/bin/format/dmp/dmp64.h rename to librz/bin/format/dmp/dmp64.h index 9f06da8019..5ec3831e10 100644 --- a/libr/bin/format/dmp/dmp64.h +++ b/librz/bin/format/dmp/dmp64.h @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2020 - abcSup */ +/* rizin - LGPL - Copyright 2020 - abcSup */ #ifndef DMP64_H #define DMP64_H -#include +#include #include "dmp_specs.h" @@ -12,21 +12,21 @@ typedef struct { ut64 file_offset; } dmp_page_desc; -struct r_bin_dmp64_obj_t { +struct rz_bin_dmp64_obj_t { dmp64_header *header; dmp_bmp_header *bmp_header; dmp_p_memory_run *runs; ut8 *bitmap; ut64 dtb; - RList *pages; + RzList *pages; RBuffer* b; int size; Sdb *kv; }; -void r_bin_dmp64_free(struct r_bin_dmp64_obj_t *obj); -struct r_bin_dmp64_obj_t *r_bin_dmp64_new_buf(RBuffer* buf); +void rz_bin_dmp64_free(struct rz_bin_dmp64_obj_t *obj); +struct rz_bin_dmp64_obj_t *rz_bin_dmp64_new_buf(RBuffer* buf); #endif /* DMP64_H */ diff --git a/libr/bin/format/dmp/dmp_specs.h b/librz/bin/format/dmp/dmp_specs.h similarity index 97% rename from libr/bin/format/dmp/dmp_specs.h rename to librz/bin/format/dmp/dmp_specs.h index 8566fe72bd..9275d1276e 100644 --- a/libr/bin/format/dmp/dmp_specs.h +++ b/librz/bin/format/dmp/dmp_specs.h @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2020 - abcSup */ +/* rizin - LGPL - Copyright 2020 - abcSup */ #ifndef DMP_SPECS_H #define DMP_SPECS_H -#include +#include #include "mdmp/mdmp_specs.h" #include "mdmp/mdmp_windefs.h" diff --git a/libr/bin/format/elf/Makefile b/librz/bin/format/elf/Makefile similarity index 100% rename from libr/bin/format/elf/Makefile rename to librz/bin/format/elf/Makefile diff --git a/libr/bin/format/elf/elf.c b/librz/bin/format/elf/elf.c similarity index 88% rename from libr/bin/format/elf/elf.c rename to librz/bin/format/elf/elf.c index 3d7cc064f1..6da7bedb2d 100644 --- a/libr/bin/format/elf/elf.c +++ b/librz/bin/format/elf/elf.c @@ -4,8 +4,8 @@ #include #include #include -#include -#include +#include +#include #include "elf.h" #define MIPS_PLT_OFFSET 0x20 @@ -28,15 +28,15 @@ #define MAX_REL_RELA_SZ (sizeof (Elf_(Rel)) > sizeof (Elf_(Rela))? sizeof (Elf_(Rel)): sizeof (Elf_(Rela))) -#define READ8(x, i) r_read_ble8((x) + (i)); (i) += 1 -#define READ16(x, i) r_read_ble16((x) + (i), bin->endian); (i) += 2 -#define READ32(x, i) r_read_ble32((x) + (i), bin->endian); (i) += 4 -#define READ64(x, i) r_read_ble64((x) + (i), bin->endian); (i) += 8 +#define READ8(x, i) rz_read_ble8((x) + (i)); (i) += 1 +#define READ16(x, i) rz_read_ble16((x) + (i), bin->endian); (i) += 2 +#define READ32(x, i) rz_read_ble32((x) + (i), bin->endian); (i) += 4 +#define READ64(x, i) rz_read_ble64((x) + (i), bin->endian); (i) += 8 -#define BREAD8(x, i) r_buf_read_ble8_at (x, i); (i) += 1 -#define BREAD16(x, i) r_buf_read_ble16_at (x, i, bin->endian); (i) += 2 -#define BREAD32(x, i) r_buf_read_ble32_at (x, i, bin->endian); (i) += 4 -#define BREAD64(x, i) r_buf_read_ble64_at (x, i, bin->endian); (i) += 8 +#define BREAD8(x, i) rz_buf_read_ble8_at (x, i); (i) += 1 +#define BREAD16(x, i) rz_buf_read_ble16_at (x, i, bin->endian); (i) += 2 +#define BREAD32(x, i) rz_buf_read_ble32_at (x, i, bin->endian); (i) += 4 +#define BREAD64(x, i) rz_buf_read_ble64_at (x, i, bin->endian); (i) += 8 #define NUMENTRIES_ROUNDUP(sectionsize, entrysize) (((sectionsize) + (entrysize)-1) / (entrysize)) #define COMPUTE_PLTGOT_POSITION(rel, pltgot_addr, n_initial_unused_entries) \ @@ -139,7 +139,7 @@ static bool init_ehdr(ELFOBJ *bin) { ut8 e_ident[EI_NIDENT]; ut8 ehdr[sizeof (Elf_(Ehdr))] = { 0 }; int i, len; - if (r_buf_read_at (bin->b, 0, e_ident, EI_NIDENT) == -1) { + if (rz_buf_read_at (bin->b, 0, e_ident, EI_NIDENT) == -1) { bprintf ("read (magic)\n"); return false; } @@ -202,7 +202,7 @@ static bool init_ehdr(ELFOBJ *bin) { #endif bin->endian = (e_ident[EI_DATA] == ELFDATA2MSB)? 1: 0; memset (&bin->ehdr, 0, sizeof (Elf_(Ehdr))); - len = r_buf_read_at (bin->b, 0, ehdr, sizeof (ehdr)); + len = rz_buf_read_at (bin->b, 0, ehdr, sizeof (ehdr)); if (len < 32) { // tinyelf != sizeof (Elf_(Ehdr))) { bprintf ("read (ehdr)\n"); return false; @@ -213,7 +213,7 @@ static bool init_ehdr(ELFOBJ *bin) { return false; } i = 16; - // TODO: use r_read or r_buf_read_ apis instead + // TODO: use rz_read or rz_buf_read_ apis instead bin->ehdr.e_type = READ16 (ehdr, i); bin->ehdr.e_machine = READ16 (ehdr, i); bin->ehdr.e_version = READ32 (ehdr, i); @@ -251,7 +251,7 @@ static bool read_phdr(ELFOBJ *bin, bool linux_kernel_hack) { ut8 phdr[sizeof (Elf_(Phdr))] = { 0 }; int j = 0; const size_t rsize = bin->ehdr.e_phoff + i * sizeof (Elf_(Phdr)); - int len = r_buf_read_at (bin->b, rsize, phdr, sizeof (Elf_(Phdr))); + int len = rz_buf_read_at (bin->b, rsize, phdr, sizeof (Elf_(Phdr))); if (len < 1) { bprintf ("read (phdr)\n"); R_FREE (bin->phdr); @@ -284,8 +284,8 @@ static bool read_phdr(ELFOBJ *bin, bool linux_kernel_hack) { * So after the first read, we fix the address and read it again */ if (linux_kernel_hack && phdr_found) { - ut64 load_addr = Elf_(r_bin_elf_get_baddr) (bin); - bin->ehdr.e_phoff = Elf_(r_bin_elf_v2p) (bin, load_addr + bin->ehdr.e_phoff); + ut64 load_addr = Elf_(rz_bin_elf_get_baddr) (bin); + bin->ehdr.e_phoff = Elf_(rz_bin_elf_v2p) (bin, load_addr + bin->ehdr.e_phoff); return read_phdr (bin, false); } return true; @@ -294,7 +294,7 @@ static bool read_phdr(ELFOBJ *bin, bool linux_kernel_hack) { static int init_phdr(ELFOBJ *bin) { ut32 phdr_size; - r_return_val_if_fail (!bin->phdr, false); + rz_return_val_if_fail (!bin->phdr, false); if (!bin->ehdr.e_phnum) { return false; @@ -325,7 +325,7 @@ static int init_phdr(ELFOBJ *bin) { bool linux_kern_hack = false; /* Enable this hack only for the X86 64bit ELFs */ const int _128K = 1024 * 128; - if (r_buf_size (bin->b) > _128K && (bin->ehdr.e_machine == EM_X86_64 || bin->ehdr.e_machine == EM_386)) { + if (rz_buf_size (bin->b) > _128K && (bin->ehdr.e_machine == EM_X86_64 || bin->ehdr.e_machine == EM_386)) { linux_kern_hack = true; } if (!read_phdr (bin, linux_kern_hack)) { @@ -359,7 +359,7 @@ static int init_shdr(ELFOBJ *bin) { ut8 shdr[sizeof (Elf_(Shdr))] = { 0 }; int i, j, len; - r_return_val_if_fail (bin && !bin->shdr, false); + rz_return_val_if_fail (bin && !bin->shdr, false); if (!UT32_MUL (&shdr_size, bin->ehdr.e_shnum, sizeof (Elf_(Shdr)))) { return false; @@ -389,7 +389,7 @@ static int init_shdr(ELFOBJ *bin) { for (i = 0; i < bin->ehdr.e_shnum; i++) { j = 0; - len = r_buf_read_at (bin->b, bin->ehdr.e_shoff + i * sizeof (Elf_(Shdr)), shdr, sizeof (Elf_(Shdr))); + len = rz_buf_read_at (bin->b, bin->ehdr.e_shoff + i * sizeof (Elf_(Shdr)), shdr, sizeof (Elf_(Shdr))); if (len < 1) { bprintf ("read (shdr) at 0x%" PFMT64x "\n", (ut64) bin->ehdr.e_shoff); R_FREE (bin->shdr); @@ -431,7 +431,7 @@ static bool is_shidx_valid(ELFOBJ *bin, Elf_(Half) value) { } static int init_strtab(ELFOBJ *bin) { - r_return_val_if_fail (!bin->strtab, false); + rz_return_val_if_fail (!bin->strtab, false); if (!bin->shdr) { return false; @@ -466,7 +466,7 @@ static int init_strtab(ELFOBJ *bin) { bin->shstrtab = NULL; return false; } - int res = r_buf_read_at (bin->b, bin->shstrtab_section->sh_offset, (ut8*)bin->shstrtab, + int res = rz_buf_read_at (bin->b, bin->shstrtab_section->sh_offset, (ut8*)bin->shstrtab, bin->shstrtab_section->sh_size); if (res < 1) { bprintf ("read (shstrtab) at 0x%" PFMT64x "\n", (ut64) bin->shstrtab_section->sh_offset); @@ -501,7 +501,7 @@ static Elf_(Phdr) *get_dynamic_segment(ELFOBJ *bin) { } static void init_dynamic_section_sdb(ELFOBJ *bin, Elf_(Addr) strtabaddr, size_t strsize) { - int r = Elf_(r_bin_elf_has_relro) (bin); + int r = Elf_(rz_bin_elf_has_relro) (bin); switch (r) { case R_ELF_FULL_RELRO: sdb_set (bin->kv, "elf.relro", "full", 0); @@ -540,7 +540,7 @@ static void set_default_value_dynamic_info(ELFOBJ *bin) { bin->dyn_info.dt_flags_1 = R_BIN_ELF_XWORD_MAX; bin->dyn_info.dt_rpath = R_BIN_ELF_XWORD_MAX; bin->dyn_info.dt_runpath = R_BIN_ELF_XWORD_MAX; - r_vector_init(&bin->dyn_info.dt_needed, sizeof(Elf_(Off)), NULL, NULL); + rz_vector_init(&bin->dyn_info.dt_needed, sizeof(Elf_(Off)), NULL, NULL); } static size_t get_maximum_number_of_dynamic_entries(ut64 dyn_size) { @@ -550,7 +550,7 @@ static size_t get_maximum_number_of_dynamic_entries(ut64 dyn_size) { static bool fill_dynamic_entry(ELFOBJ *bin, ut64 entry_offset, Elf_(Dyn) *d) { ut8 sdyn[sizeof (Elf_(Dyn))] = { 0 }; int j = 0; - int len = r_buf_read_at (bin->b, entry_offset, sdyn, sizeof (Elf_(Dyn))); + int len = rz_buf_read_at (bin->b, entry_offset, sdyn, sizeof (Elf_(Dyn))); if (len < 1) { return false; } @@ -639,7 +639,7 @@ static void fill_dynamic_entries(ELFOBJ *bin, ut64 loaded_offset, ut64 dyn_size) bin->dyn_info.dt_runpath = d.d_un.d_val; break; case DT_NEEDED: - r_vector_push (&bin->dyn_info.dt_needed, &d.d_un.d_val); + rz_vector_push (&bin->dyn_info.dt_needed, &d.d_un.d_val); break; case DT_INIT: case DT_FINI: @@ -677,7 +677,7 @@ static int init_dynamic_section(ELFOBJ *bin) { ut64 dyn_size = 0, loaded_offset; set_default_value_dynamic_info(bin); - r_return_val_if_fail (bin, false); + rz_return_val_if_fail (bin, false); if (!bin->phdr || !bin->ehdr.e_phnum) { return false; } @@ -688,7 +688,7 @@ static int init_dynamic_section(ELFOBJ *bin) { } dyn_size = dyn_phdr->p_filesz; - loaded_offset = Elf_(r_bin_elf_v2p_new) (bin, dyn_phdr->p_vaddr); + loaded_offset = Elf_(rz_bin_elf_v2p_new) (bin, dyn_phdr->p_vaddr); if (loaded_offset == UT64_MAX) { return false; } @@ -700,7 +700,7 @@ static int init_dynamic_section(ELFOBJ *bin) { fill_dynamic_entries (bin, loaded_offset, dyn_size); if (bin->dyn_info.dt_strtab != R_BIN_ELF_ADDR_MAX) { - strtabaddr = Elf_(r_bin_elf_v2p_new) (bin, bin->dyn_info.dt_strtab); + strtabaddr = Elf_(rz_bin_elf_v2p_new) (bin, bin->dyn_info.dt_strtab); } if (bin->dyn_info.dt_strsz > 0) { @@ -717,7 +717,7 @@ static int init_dynamic_section(ELFOBJ *bin) { if (!strtab) { return false; } - r = r_buf_read_at (bin->b, strtabaddr, (ut8 *)strtab, strsize); + r = rz_buf_read_at (bin->b, strtabaddr, (ut8 *)strtab, strsize); if (r < 1) { free (strtab); return false; @@ -793,14 +793,14 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) sdb_free (sdb); return NULL; } - ut64 off = Elf_(r_bin_elf_v2p) (bin, bin->version_info[DT_VERSIONTAGIDX (DT_VERSYM)]); + ut64 off = Elf_(rz_bin_elf_v2p) (bin, bin->version_info[DT_VERSIONTAGIDX (DT_VERSYM)]); if (bin->shstrtab && shdr->sh_name < bin->shstrtab_size) { section_name = &bin->shstrtab[shdr->sh_name]; } if (bin->shstrtab && link_shdr->sh_name < bin->shstrtab_size) { link_section_name = &bin->shstrtab[link_shdr->sh_name]; } - r_buf_read_at (bin->b, off, edata, sizeof (ut16) * num_entries); + rz_buf_read_at (bin->b, off, edata, sizeof (ut16) * num_entries); sdb_set (sdb, "section_name", section_name, 0); sdb_num_set (sdb, "num_entries", num_entries, 0); sdb_num_set (sdb, "addr", shdr->sh_addr, 0); @@ -808,7 +808,7 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) sdb_num_set (sdb, "link", shdr->sh_link, 0); sdb_set (sdb, "link_section_name", link_section_name, 0); for (i = num_entries; i--;) { - data[i] = r_read_ble16 (&edata[i * sizeof (ut16)], bin->endian); + data[i] = rz_read_ble16 (&edata[i * sizeof (ut16)], bin->endian); } R_FREE (edata); char *tmp_val = NULL; @@ -834,7 +834,7 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (bin->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) { Elf_(Verneed) vn; ut8 svn[sizeof (Elf_(Verneed))] = { 0 }; - ut64 offset = Elf_(r_bin_elf_v2p) (bin, bin->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]); + ut64 offset = Elf_(rz_bin_elf_v2p) (bin, bin->version_info[DT_VERSIONTAGIDX (DT_VERNEED)]); do { Elf_(Vernaux) vna; ut8 svna[sizeof (Elf_(Vernaux))] = { 0 }; @@ -842,7 +842,7 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (offset > bin->size || offset + sizeof (vn) > bin->size) { goto beach; } - if (r_buf_read_at (bin->b, offset, svn, sizeof (svn)) < 0) { + if (rz_buf_read_at (bin->b, offset, svn, sizeof (svn)) < 0) { bprintf ("Cannot read Verneed for Versym\n"); goto beach; } @@ -857,7 +857,7 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (a_off > bin->size || a_off + sizeof (vna) > bin->size) { goto beach; } - if (r_buf_read_at (bin->b, a_off, svna, sizeof (svna)) < 0) { + if (rz_buf_read_at (bin->b, a_off, svna, sizeof (svna)) < 0) { bprintf ("Cannot read Vernaux for Versym\n"); goto beach; } @@ -886,12 +886,12 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (check_def && data[i + j] != 0x8001 && vinfoaddr) { Elf_(Verdef) vd; ut8 svd[sizeof (Elf_(Verdef))] = { 0 }; - ut64 offset = Elf_(r_bin_elf_v2p) (bin, vinfoaddr); + ut64 offset = Elf_(rz_bin_elf_v2p) (bin, vinfoaddr); if (offset > bin->size || offset + sizeof (vd) > bin->size) { goto beach; } do { - if (r_buf_read_at (bin->b, offset, svd, sizeof (svd)) < 0) { + if (rz_buf_read_at (bin->b, offset, svd, sizeof (svd)) < 0) { bprintf ("Cannot read Verdef for Versym\n"); goto beach; } @@ -913,7 +913,7 @@ static Sdb *store_versioninfo_gnu_versym(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (off_vda > bin->size || off_vda + sizeof (vda) > bin->size) { goto beach; } - if (r_buf_read_at (bin->b, off_vda, svda, sizeof (svda)) < 0) { + if (rz_buf_read_at (bin->b, off_vda, svda, sizeof (svda)) < 0) { bprintf ("Cannot read Verdaux for Versym\n"); goto beach; } @@ -995,7 +995,7 @@ static Sdb *store_versioninfo_gnu_verdef(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (vstart + sizeof (*verdef) > end) { break; } - r_buf_read_at (bin->b, shdr->sh_offset + i, dfs, sizeof (Elf_(Verdef))); + rz_buf_read_at (bin->b, shdr->sh_offset + i, dfs, sizeof (Elf_(Verdef))); verdef->vd_version = READ16 (dfs, j); verdef->vd_flags = READ16 (dfs, j); verdef->vd_ndx = READ16 (dfs, j); @@ -1136,7 +1136,7 @@ static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) if (shdr->sh_offset + shdr->sh_size < shdr->sh_size) { goto beach; } - i = r_buf_read_at (bin->b, shdr->sh_offset, need, shdr->sh_size); + i = rz_buf_read_at (bin->b, shdr->sh_offset, need, shdr->sh_size); if (i < 1) { goto beach; } @@ -1168,7 +1168,7 @@ static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) goto beach; } { - char *s = r_str_ndup (&bin->dynstr[entry->vn_file], 16); + char *s = rz_str_ndup (&bin->dynstr[entry->vn_file], 16); sdb_set (sdb_version, "file_name", s, 0); free (s); } @@ -1212,8 +1212,8 @@ static Sdb *store_versioninfo_gnu_verneed(ELFOBJ *bin, Elf_(Shdr) *shdr, int sz) snprintf (key, sizeof (key), "vernaux%d", j); sdb_ns_set (sdb_version, key, sdb_vernaux); #else - char *key = r_str_newf ("vernaux%d", j); - char *val = r_str_newf ("%d,%s", isum, get_ver_flags (aux->vna_flags)); + char *key = rz_str_newf ("vernaux%d", j); + char *val = rz_str_newf ("%d,%s", isum, get_ver_flags (aux->vna_flags)); sdb_set (sdb_version, key, val, 0); free (key); free (val); @@ -1318,7 +1318,7 @@ static bool init_dynstr(ELFOBJ *bin) { if (bin->shdr[i].sh_offset + bin->shdr[i].sh_size < bin->shdr[i].sh_size) { return false; } - r = r_buf_read_at (bin->b, bin->shdr[i].sh_offset, (ut8*)bin->dynstr, bin->shdr[i].sh_size); + r = rz_buf_read_at (bin->b, bin->shdr[i].sh_offset, (ut8*)bin->dynstr, bin->shdr[i].sh_size); if (r < 1) { R_FREE (bin->dynstr); bin->dynstr_size = 0; @@ -1365,8 +1365,8 @@ static bool elf_init(ELFOBJ *bin) { if (!init_dynstr (bin) && !is_bin_etrel (bin)) { bprintf ("Cannot initialize dynamic strings\n"); } - bin->baddr = Elf_(r_bin_elf_get_baddr) (bin); - if (!init_dynamic_section (bin) && !Elf_(r_bin_elf_is_static) (bin) && !is_bin_etrel (bin)) { + bin->baddr = Elf_(rz_bin_elf_get_baddr) (bin); + if (!init_dynamic_section (bin) && !Elf_(rz_bin_elf_is_static) (bin) && !is_bin_etrel (bin)) { bprintf ("Cannot initialize dynamic section\n"); } } @@ -1375,25 +1375,25 @@ static bool elf_init(ELFOBJ *bin) { bin->imports_by_ord = NULL; bin->symbols_by_ord_size = 0; bin->symbols_by_ord = NULL; - bin->g_sections = Elf_(r_bin_elf_get_sections) (bin); - bin->boffset = Elf_(r_bin_elf_get_boffset) (bin); - bin->g_relocs = Elf_(r_bin_elf_get_relocs) (bin); + bin->g_sections = Elf_(rz_bin_elf_get_sections) (bin); + bin->boffset = Elf_(rz_bin_elf_get_boffset) (bin); + bin->g_relocs = Elf_(rz_bin_elf_get_relocs) (bin); bin->rel_cache = rel_cache_new (bin->g_relocs, bin->g_reloc_num); sdb_ns_set (bin->kv, "versioninfo", store_versioninfo (bin)); return true; } -ut64 Elf_(r_bin_elf_get_section_offset)(ELFOBJ *bin, const char *section_name) { +ut64 Elf_(rz_bin_elf_get_section_offset)(ELFOBJ *bin, const char *section_name) { RBinElfSection *section = get_section_by_name (bin, section_name); return section? section->offset: UT64_MAX; } -ut64 Elf_(r_bin_elf_get_section_addr)(ELFOBJ *bin, const char *section_name) { +ut64 Elf_(rz_bin_elf_get_section_addr)(ELFOBJ *bin, const char *section_name) { RBinElfSection *section = get_section_by_name (bin, section_name); return section? section->rva: UT64_MAX; } -ut64 Elf_(r_bin_elf_get_section_addr_end)(ELFOBJ *bin, const char *section_name) { +ut64 Elf_(rz_bin_elf_get_section_addr_end)(ELFOBJ *bin, const char *section_name) { RBinElfSection *section = get_section_by_name (bin, section_name); return section? section->rva + section->size: UT64_MAX; } @@ -1403,7 +1403,7 @@ static ut64 get_got_entry(ELFOBJ *bin, RBinElfReloc *rel) { return UT64_MAX; } - ut64 p_sym_got_addr = Elf_(r_bin_elf_v2p_new) (bin, rel->rva); + ut64 p_sym_got_addr = Elf_(rz_bin_elf_v2p_new) (bin, rel->rva); ut64 addr = R_BIN_ELF_BREADWORD (bin->b, p_sym_got_addr); return (!addr || addr == R_BIN_ELF_WORD_MAX) ? UT64_MAX : addr; @@ -1455,13 +1455,13 @@ static ut64 get_import_addr_mips(ELFOBJ *bin, RBinElfReloc *rel) { ut8 buf[1024]; ut64 plt_addr = jmprel_addr + bin->dyn_info.dt_pltrelsz; - ut64 p_plt_addr = Elf_(r_bin_elf_v2p_new) (bin, plt_addr); - int res = r_buf_read_at (bin->b, p_plt_addr, buf, sizeof (buf)); + ut64 p_plt_addr = Elf_(rz_bin_elf_v2p_new) (bin, plt_addr); + int res = rz_buf_read_at (bin->b, p_plt_addr, buf, sizeof (buf)); if (res != sizeof (buf)) { return UT64_MAX; } - const ut8 *base = r_mem_mem_aligned (buf, sizeof (buf), (const ut8 *)"\x3c\x0f\x00", 3, 4); + const ut8 *base = rz_mem_mem_aligned (buf, sizeof (buf), (const ut8 *)"\x3c\x0f\x00", 3, 4); plt_addr += base? (int)(size_t) (base - buf): MIPS_PLT_OFFSET + 8; // HARDCODED HACK plt_addr += pos * 16; @@ -1511,12 +1511,12 @@ static ut64 get_import_addr_ppc(ELFOBJ *bin, RBinElfReloc *rel) { if (plt_addr == R_BIN_ELF_ADDR_MAX) { return UT64_MAX; } - ut64 p_plt_addr = Elf_(r_bin_elf_v2p_new) (bin, plt_addr); + ut64 p_plt_addr = Elf_(rz_bin_elf_v2p_new) (bin, plt_addr); if (p_plt_addr == UT64_MAX) { return UT64_MAX; } - ut64 base = r_buf_read_ble32_at (bin->b, p_plt_addr, bin->endian); + ut64 base = rz_buf_read_ble32_at (bin->b, p_plt_addr, bin->endian); if (base == UT32_MAX) { return UT64_MAX; } @@ -1541,7 +1541,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *bin, RBinElfReloc *rel) { return UT64_MAX; } - ut64 got_offset = Elf_(r_bin_elf_v2p_new) (bin, got_addr); + ut64 got_offset = Elf_(rz_bin_elf_v2p_new) (bin, got_addr); if (got_offset == UT64_MAX) { return UT64_MAX; } @@ -1549,7 +1549,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *bin, RBinElfReloc *rel) { //XXX HACK ALERT!!!! full relro?? try to fix it //will there always be .plt.got, what would happen if is .got.plt? RBinElfSection *s = get_section_by_name (bin, ".plt.got"); - if (Elf_(r_bin_elf_has_relro) (bin) < R_ELF_PART_RELRO || !s) { + if (Elf_(rz_bin_elf_has_relro) (bin) < R_ELF_PART_RELRO || !s) { return UT64_MAX; } @@ -1571,7 +1571,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *bin, RBinElfReloc *rel) { return plt_addr, that will be our sym addr perhaps this hack doesn't work on 32 bits */ - int res = r_buf_read_at (bin->b, plt_addr + 2, buf, sizeof (ut32)); + int res = rz_buf_read_at (bin->b, plt_addr + 2, buf, sizeof (ut32)); if (res < 0) { return UT64_MAX; } @@ -1580,7 +1580,7 @@ static ut64 get_import_addr_x86_manual(ELFOBJ *bin, RBinElfReloc *rel) { plt_sym_addr = R_BIN_ELF_READWORD (buf, i); //relative address - if ((plt_addr + 6 + Elf_(r_bin_elf_v2p) (bin, plt_sym_addr)) == rel->rva) { + if ((plt_addr + 6 + Elf_(rz_bin_elf_v2p) (bin, plt_sym_addr)) == rel->rva) { return plt_addr; } if (plt_sym_addr == rel->rva) { @@ -1650,8 +1650,8 @@ static ut64 get_import_addr(ELFOBJ *bin, int sym) { } } -int Elf_(r_bin_elf_has_nx)(ELFOBJ *bin) { - r_return_val_if_fail (bin, 0); +int Elf_(rz_bin_elf_has_nx)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, 0); int i; if (bin && bin->phdr) { for (i = 0; i < bin->ehdr.e_phnum; i++) { @@ -1663,8 +1663,8 @@ int Elf_(r_bin_elf_has_nx)(ELFOBJ *bin) { return 0; } -int Elf_(r_bin_elf_has_relro)(ELFOBJ *bin) { - r_return_val_if_fail (bin, R_ELF_NO_RELRO); +int Elf_(rz_bin_elf_has_relro)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, R_ELF_NO_RELRO); bool haveBindNow = false; bool haveGnuRelro = false; @@ -1700,7 +1700,7 @@ truncating the memory address to the nearest multiple of the maximum page size */ -ut64 Elf_(r_bin_elf_get_baddr)(ELFOBJ *bin) { +ut64 Elf_(rz_bin_elf_get_baddr)(ELFOBJ *bin) { ut64 tmp, base = UT64_MAX; if (!bin) { return 0; @@ -1725,9 +1725,9 @@ ut64 Elf_(r_bin_elf_get_baddr)(ELFOBJ *bin) { return base == UT64_MAX? 0: base; } -ut64 Elf_(r_bin_elf_get_boffset)(ELFOBJ *bin) { +ut64 Elf_(rz_bin_elf_get_boffset)(ELFOBJ *bin) { ut64 tmp, base = UT64_MAX; - r_return_val_if_fail (bin, 0); + rz_return_val_if_fail (bin, 0); if (!bin->phdr) { return 0; @@ -1746,66 +1746,66 @@ ut64 Elf_(r_bin_elf_get_boffset)(ELFOBJ *bin) { return base == UT64_MAX? 0: base; } -ut64 Elf_(r_bin_elf_get_init_offset)(ELFOBJ *bin) { - ut64 entry = Elf_(r_bin_elf_get_entry_offset) (bin); +ut64 Elf_(rz_bin_elf_get_init_offset)(ELFOBJ *bin) { + ut64 entry = Elf_(rz_bin_elf_get_entry_offset) (bin); ut8 buf[128]; if (!bin || entry == UT64_MAX) { return UT64_MAX; } - if (r_buf_read_at (bin->b, entry + 16, buf, sizeof (buf)) < 1) { + if (rz_buf_read_at (bin->b, entry + 16, buf, sizeof (buf)) < 1) { bprintf ("read (init_offset)\n"); return 0; } if (buf[0] == 0x68) { // push // x86 only ut64 addr; memmove (buf, buf + 1, 4); - addr = (ut64)r_read_le32 (buf); - return Elf_(r_bin_elf_v2p) (bin, addr); + addr = (ut64)rz_read_le32 (buf); + return Elf_(rz_bin_elf_v2p) (bin, addr); } return 0; } -ut64 Elf_(r_bin_elf_get_fini_offset)(ELFOBJ *bin) { - r_return_val_if_fail (bin, UT64_MAX); - ut64 entry = Elf_(r_bin_elf_get_entry_offset) (bin); +ut64 Elf_(rz_bin_elf_get_fini_offset)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, UT64_MAX); + ut64 entry = Elf_(rz_bin_elf_get_entry_offset) (bin); if (entry == UT64_MAX) { return UT64_MAX; } ut8 buf[512]; - if (r_buf_read_at (bin->b, entry + 11, buf, sizeof (buf)) == -1) { + if (rz_buf_read_at (bin->b, entry + 11, buf, sizeof (buf)) == -1) { bprintf ("read (get_fini)\n"); return 0; } if (*buf == 0x68) { // push // x86/32 only memmove (buf, buf + 1, 4); - ut64 addr = (ut64)r_read_le32 (buf); - return Elf_(r_bin_elf_v2p) (bin, addr); + ut64 addr = (ut64)rz_read_le32 (buf); + return Elf_(rz_bin_elf_v2p) (bin, addr); } return 0; } -ut64 Elf_(r_bin_elf_get_entry_offset)(ELFOBJ *bin) { - r_return_val_if_fail (bin, UT64_MAX); +ut64 Elf_(rz_bin_elf_get_entry_offset)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, UT64_MAX); ut64 entry = bin->ehdr.e_entry; if (!entry) { - if (!Elf_(r_bin_elf_is_executable) (bin)) { + if (!Elf_(rz_bin_elf_is_executable) (bin)) { return UT64_MAX; } - entry = Elf_(r_bin_elf_get_section_offset)(bin, ".init.text"); + entry = Elf_(rz_bin_elf_get_section_offset)(bin, ".init.text"); if (entry != UT64_MAX) { return entry; } - entry = Elf_(r_bin_elf_get_section_offset)(bin, ".text"); + entry = Elf_(rz_bin_elf_get_section_offset)(bin, ".text"); if (entry != UT64_MAX) { return entry; } - return Elf_(r_bin_elf_get_section_offset)(bin, ".init"); + return Elf_(rz_bin_elf_get_section_offset)(bin, ".init"); } - return Elf_(r_bin_elf_v2p) (bin, entry); + return Elf_(rz_bin_elf_v2p) (bin, entry); } static ut64 getmainsymbol(ELFOBJ *bin) { - struct r_bin_elf_symbol_t *symbol = Elf_(r_bin_elf_get_symbols) (bin); + struct rz_bin_elf_symbol_t *symbol = Elf_(rz_bin_elf_get_symbols) (bin); if (symbol) { size_t i; for (i = 0; !symbol[i].last; i++) { @@ -1817,9 +1817,9 @@ static ut64 getmainsymbol(ELFOBJ *bin) { return UT64_MAX; } -ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { - r_return_val_if_fail (bin, UT64_MAX); - ut64 entry = Elf_(r_bin_elf_get_entry_offset) (bin); +ut64 Elf_(rz_bin_elf_get_main_offset)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, UT64_MAX); + ut64 entry = Elf_(rz_bin_elf_get_entry_offset) (bin); if (entry == UT64_MAX) { return UT64_MAX; } @@ -1828,16 +1828,16 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { return UT64_MAX; } // unnecessary to read 512 bytes imho - if (r_buf_read_at (bin->b, entry, buf, sizeof (buf)) < 1) { + if (rz_buf_read_at (bin->b, entry, buf, sizeof (buf)) < 1) { bprintf ("read (main)\n"); return UT64_MAX; } // ARM64 if (buf[0x18+3] == 0x58 && buf[0x2f] == 0x00) { - ut32 entry_vaddr = Elf_(r_bin_elf_p2v) (bin, entry); - ut32 main_addr = r_read_le32 (&buf[0x30]); + ut32 entry_vaddr = Elf_(rz_bin_elf_p2v) (bin, entry); + ut32 main_addr = rz_read_le32 (&buf[0x30]); if ((main_addr >> 16) == (entry_vaddr >> 16)) { - return Elf_(r_bin_elf_v2p) (bin, main_addr); + return Elf_(rz_bin_elf_v2p) (bin, main_addr); } } @@ -1855,18 +1855,18 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { delta = 0x30; } if (delta) { - ut64 pa = Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[delta-1]) & ~1); - if (pa < r_buf_size (bin->b)) { + ut64 pa = Elf_(rz_bin_elf_v2p) (bin, rz_read_le32 (&buf[delta-1]) & ~1); + if (pa < rz_buf_size (bin->b)) { return pa; } } } else { /* non-thumb entry points */ if (!memcmp (buf, "\x00\xb0\xa0\xe3\x00\xe0\xa0\xe3", 8)) { - return Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[0x34]) & ~1); + return Elf_(rz_bin_elf_v2p) (bin, rz_read_le32 (&buf[0x34]) & ~1); } if (!memcmp (buf, "\x24\xc0\x9f\xe5\x00\xb0\xa0\xe3", 8)) { - return Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[0x30]) & ~1); + return Elf_(rz_bin_elf_v2p) (bin, rz_read_le32 (&buf[0x30]) & ~1); } } @@ -1884,17 +1884,17 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { */ ut64 got_offset; - if ((got_offset = Elf_(r_bin_elf_get_section_offset) (bin, ".got")) != -1 || - (got_offset = Elf_(r_bin_elf_get_section_offset) (bin, ".got.plt")) != -1) + if ((got_offset = Elf_(rz_bin_elf_get_section_offset) (bin, ".got")) != -1 || + (got_offset = Elf_(rz_bin_elf_get_section_offset) (bin, ".got.plt")) != -1) { const ut64 gp = got_offset + 0x7ff0; size_t i, len = sizeof (buf) / sizeof (buf[0]); for (i = 0; i < len; i += 4) { - const ut32 instr = r_read_le32 (&buf[i]); + const ut32 instr = rz_read_le32 (&buf[i]); if ((instr & 0xffff0000) == 0x8f840000) { // lw a0, offset(gp) const short delta = instr & 0x0000ffff; - r_buf_read_at (bin->b, /* got_entry_offset = */ gp + delta, buf, 4); - return Elf_(r_bin_elf_v2p) (bin, r_read_le32 (&buf[0])); + rz_buf_read_at (bin->b, /* got_entry_offset = */ gp + delta, buf, 4); + return Elf_(rz_bin_elf_v2p) (bin, rz_read_le32 (&buf[0])); } } } @@ -1905,15 +1905,15 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { if (buf[0] == 0xe8 && !memcmp (buf + 5, "\x50\xe8\x00\x00\x00\x00\xb8\x01\x00\x00\x00\x53", 12)) { size_t SIZEOF_CALL = 5; ut64 rel_addr = (ut64)((int)(buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24))); - ut64 addr = Elf_(r_bin_elf_p2v)(bin, entry + SIZEOF_CALL); + ut64 addr = Elf_(rz_bin_elf_p2v)(bin, entry + SIZEOF_CALL); addr += rel_addr; - return Elf_(r_bin_elf_v2p) (bin, addr); + return Elf_(rz_bin_elf_v2p) (bin, addr); } // X86-PIE if (buf[0x00] == 0x48 && buf[0x1e] == 0x8d && buf[0x11] == 0xe8) { ut32 *pmain = (ut32*)(buf + 0x30); - ut64 vmain = Elf_(r_bin_elf_p2v) (bin, (ut64)*pmain); - ut64 ventry = Elf_(r_bin_elf_p2v) (bin, entry); + ut64 vmain = Elf_(rz_bin_elf_p2v) (bin, (ut64)*pmain); + ut64 ventry = Elf_(rz_bin_elf_p2v) (bin, entry); if (vmain >> 16 == ventry >> 16) { return (ut64)vmain; } @@ -1923,15 +1923,15 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { if (!memcmp (buf, "\x31\xed\x49\x89", 4)) {// linux ut64 maddr, baddr; ut8 n32s[sizeof (ut32)] = {0}; - maddr = entry + 0x24 + r_read_le32 (buf + 0x20); - if (r_buf_read_at (bin->b, maddr, n32s, sizeof (ut32)) == -1) { + maddr = entry + 0x24 + rz_read_le32 (buf + 0x20); + if (rz_buf_read_at (bin->b, maddr, n32s, sizeof (ut32)) == -1) { bprintf ("read (maddr) 2\n"); return 0; } - maddr = (ut64)r_read_le32 (&n32s[0]); + maddr = (ut64)rz_read_le32 (&n32s[0]); baddr = (bin->ehdr.e_entry >> 16) << 16; if (bin->phdr) { - baddr = Elf_(r_bin_elf_get_baddr) (bin); + baddr = Elf_(rz_bin_elf_get_baddr) (bin); } maddr += baddr; return maddr; @@ -1940,16 +1940,16 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { // X86-NONPIE #if R_BIN_ELF64 if (!memcmp (buf, "\x49\x89\xd9", 3) && buf[156] == 0xe8) { // openbsd - return r_read_le32 (&buf[157]) + entry + 156 + 5; + return rz_read_le32 (&buf[157]) + entry + 156 + 5; } if (!memcmp (buf+29, "\x48\xc7\xc7", 3)) { // linux - ut64 addr = (ut64)r_read_le32 (&buf[29 + 3]); - return Elf_(r_bin_elf_v2p) (bin, addr); + ut64 addr = (ut64)rz_read_le32 (&buf[29 + 3]); + return Elf_(rz_bin_elf_v2p) (bin, addr); } #else if (buf[23] == '\x68') { - ut64 addr = (ut64)r_read_le32 (&buf[23 + 1]); - return Elf_(r_bin_elf_v2p) (bin, addr); + ut64 addr = (ut64)rz_read_le32 (&buf[23 + 1]); + return Elf_(rz_bin_elf_v2p) (bin, addr); } #endif /* linux64 pie main -- probably buggy in some cases */ @@ -1963,15 +1963,15 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { ut8 ch = buf[bo + 1]; if (ch == 0x8d) { // lea rdi, qword [rip-0x21c4] ut8 *p = buf + bo + 3; - st32 maindelta = (st32)r_read_le32 (p); + st32 maindelta = (st32)rz_read_le32 (p); ut64 vmain = (ut64)(entry + bo + maindelta) + 7; - ut64 ventry = Elf_(r_bin_elf_p2v) (bin, entry); + ut64 ventry = Elf_(rz_bin_elf_p2v) (bin, entry); if (vmain>>16 == ventry>>16) { return (ut64)vmain; } } else if (0xc7) { // mov rdi, 0xADDR ut8 *p = buf + bo + 3; - return (ut64)(ut32)r_read_le32 (p); + return (ut64)(ut32)rz_read_le32 (p); } } @@ -1985,7 +1985,7 @@ ut64 Elf_(r_bin_elf_get_main_offset)(ELFOBJ *bin) { return UT64_MAX; } -bool Elf_(r_bin_elf_get_stripped)(ELFOBJ *bin) { +bool Elf_(rz_bin_elf_get_stripped)(ELFOBJ *bin) { if (!bin->shdr) { return false; } @@ -1998,7 +1998,7 @@ bool Elf_(r_bin_elf_get_stripped)(ELFOBJ *bin) { return true; } -char *Elf_(r_bin_elf_intrp)(ELFOBJ *bin) { +char *Elf_(rz_bin_elf_intrp)(ELFOBJ *bin) { int i; if (!bin || !bin->phdr) { return NULL; @@ -2009,14 +2009,14 @@ char *Elf_(r_bin_elf_intrp)(ELFOBJ *bin) { int sz = bin->phdr[i].p_filesz; sdb_num_set (bin->kv, "elf_header.intrp_addr", addr, 0); sdb_num_set (bin->kv, "elf_header.intrp_size", sz, 0); - if (sz < 1 || sz > r_buf_size (bin->b)) { + if (sz < 1 || sz > rz_buf_size (bin->b)) { return NULL; } char *str = malloc (sz + 1); if (!str) { return NULL; } - if (r_buf_read_at (bin->b, addr, (ut8*)str, sz) < 1) { + if (rz_buf_read_at (bin->b, addr, (ut8*)str, sz) < 1) { bprintf ("read (main)\n"); free (str); return 0; @@ -2029,7 +2029,7 @@ char *Elf_(r_bin_elf_intrp)(ELFOBJ *bin) { return NULL; } -bool Elf_(r_bin_elf_is_static)(ELFOBJ *bin) { +bool Elf_(rz_bin_elf_is_static)(ELFOBJ *bin) { size_t i; if (!bin->phdr) { return false; @@ -2043,20 +2043,20 @@ bool Elf_(r_bin_elf_is_static)(ELFOBJ *bin) { return true; } -char* Elf_(r_bin_elf_get_data_encoding)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_data_encoding)(ELFOBJ *bin) { switch (bin->ehdr.e_ident[EI_DATA]) { case ELFDATANONE: return strdup ("none"); case ELFDATA2LSB: return strdup ("2's complement, little endian"); case ELFDATA2MSB: return strdup ("2's complement, big endian"); - default: return r_str_newf ("", bin->ehdr.e_ident[EI_DATA]); + default: return rz_str_newf ("", bin->ehdr.e_ident[EI_DATA]); } } -int Elf_(r_bin_elf_has_va)(ELFOBJ *bin) { +int Elf_(rz_bin_elf_has_va)(ELFOBJ *bin) { return true; } -char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_arch)(ELFOBJ *bin) { switch (bin->ehdr.e_machine) { case EM_ARC: case EM_ARC_A5: @@ -2118,7 +2118,7 @@ char* Elf_(r_bin_elf_get_arch)(ELFOBJ *bin) { default: return strdup ("x86"); } } -char* Elf_(r_bin_elf_get_abi)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_abi)(ELFOBJ *bin) { Elf_(Ehdr)* ehdr = (Elf_(Ehdr) *) &bin->ehdr; if (ehdr->e_machine == EM_MIPS) { @@ -2135,7 +2135,7 @@ char* Elf_(r_bin_elf_get_abi)(ELFOBJ *bin) { return NULL; } -char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_cpu)(ELFOBJ *bin) { if (bin->phdr && bin->ehdr.e_machine == EM_MIPS) { const ut32 mipsType = bin->ehdr.e_flags & EF_MIPS_ARCH; switch (mipsType) { @@ -2154,25 +2154,25 @@ char* Elf_(r_bin_elf_get_cpu)(ELFOBJ *bin) { return NULL; } -char* Elf_(r_bin_elf_get_head_flag)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_head_flag)(ELFOBJ *bin) { char *head_flag = NULL; - char *str = Elf_(r_bin_elf_get_cpu) (bin); + char *str = Elf_(rz_bin_elf_get_cpu) (bin); if (str) { - head_flag = r_str_append (head_flag, str); + head_flag = rz_str_append (head_flag, str); } - str = Elf_(r_bin_elf_get_abi) (bin); + str = Elf_(rz_bin_elf_get_abi) (bin); if (str) { - head_flag = r_str_appendf (head_flag, " %s", str); + head_flag = rz_str_appendf (head_flag, " %s", str); } if (R_STR_ISEMPTY (head_flag)) { - head_flag = r_str_append (head_flag, "unknown_flag"); + head_flag = rz_str_append (head_flag, "unknown_flag"); } return head_flag; } // http://www.sco.com/developers/gabi/latest/ch4.eheader.html -char* Elf_(r_bin_elf_get_machine_name)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_machine_name)(ELFOBJ *bin) { switch (bin->ehdr.e_machine) { case EM_NONE: return strdup ("No machine"); case EM_M32: return strdup ("AT&T WE 32100"); @@ -2331,12 +2331,12 @@ char* Elf_(r_bin_elf_get_machine_name)(ELFOBJ *bin) { case EM_MOXIE: return strdup ("Moxie processor family"); case EM_AMDGPU: return strdup ("AMD GPU architecture"); - default: return r_str_newf (": 0x%x", bin->ehdr.e_machine); + default: return rz_str_newf (": 0x%x", bin->ehdr.e_machine); } } -char* Elf_(r_bin_elf_get_file_type)(ELFOBJ *bin) { - r_return_val_if_fail (bin, NULL); +char* Elf_(rz_bin_elf_get_file_type)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, NULL); ut32 e_type = (ut32)bin->ehdr.e_type; // cast to avoid warn in iphone-gcc, must be ut16 switch (e_type) { case ET_NONE: return strdup ("NONE (None)"); @@ -2346,24 +2346,24 @@ char* Elf_(r_bin_elf_get_file_type)(ELFOBJ *bin) { case ET_CORE: return strdup ("CORE (Core file)"); } if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) { - return r_str_newf ("Processor Specific: %x", e_type); + return rz_str_newf ("Processor Specific: %x", e_type); } if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) { - return r_str_newf ("OS Specific: %x", e_type); + return rz_str_newf ("OS Specific: %x", e_type); } - return r_str_newf (": %x", e_type); + return rz_str_newf (": %x", e_type); } -char* Elf_(r_bin_elf_get_elf_class)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_elf_class)(ELFOBJ *bin) { switch (bin->ehdr.e_ident[EI_CLASS]) { case ELFCLASSNONE: return strdup ("none"); case ELFCLASS32: return strdup ("ELF32"); case ELFCLASS64: return strdup ("ELF64"); - default: return r_str_newf ("", bin->ehdr.e_ident[EI_CLASS]); + default: return rz_str_newf ("", bin->ehdr.e_ident[EI_CLASS]); } } -int Elf_(r_bin_elf_get_bits)(ELFOBJ *bin) { +int Elf_(rz_bin_elf_get_bits)(ELFOBJ *bin) { /* Hack for ARCompact */ if (bin->ehdr.e_machine == EM_ARC_A5) { return 16; @@ -2406,8 +2406,8 @@ int Elf_(r_bin_elf_get_bits)(ELFOBJ *bin) { /* Hack for Thumb */ if (bin->ehdr.e_machine == EM_ARM) { if (bin->ehdr.e_type != ET_EXEC) { - struct r_bin_elf_symbol_t *symbol; - if ((symbol = Elf_(r_bin_elf_get_symbols) (bin))) { + struct rz_bin_elf_symbol_t *symbol; + if ((symbol = Elf_(rz_bin_elf_get_symbols) (bin))) { int i = 0; for (i = 0; !symbol[i].last; i++) { ut64 paddr = symbol[i].offset; @@ -2417,7 +2417,7 @@ int Elf_(r_bin_elf_get_bits)(ELFOBJ *bin) { } } } - ut64 entry = Elf_(r_bin_elf_get_entry_offset) (bin); + ut64 entry = Elf_(rz_bin_elf_get_entry_offset) (bin); if (entry & 1) { return 16; } @@ -2431,12 +2431,12 @@ int Elf_(r_bin_elf_get_bits)(ELFOBJ *bin) { } static inline int noodle(ELFOBJ *bin, const char *s) { - if (r_buf_size (bin->b) <= 64) { + if (rz_buf_size (bin->b) <= 64) { return 0; } ut8 tmp[64]; - r_buf_read_at (bin->b, r_buf_size (bin->b) - 64, tmp, 64); - return r_mem_mem (tmp, 64, (const ut8 *)s, strlen (s)) != NULL; + rz_buf_read_at (bin->b, rz_buf_size (bin->b) - 64, tmp, 64); + return rz_mem_mem (tmp, 64, (const ut8 *)s, strlen (s)) != NULL; } static inline int needle(ELFOBJ *bin, const char *s) { @@ -2445,14 +2445,14 @@ static inline int needle(ELFOBJ *bin, const char *s) { if (len > 4096) { len = 4096; // avoid slow loading .. can be buggy? } - return r_mem_mem ((const ut8*)bin->shstrtab, len, + return rz_mem_mem ((const ut8*)bin->shstrtab, len, (const ut8*)s, strlen (s)) != NULL; } return 0; } // TODO: must return const char * all those strings must be const char os[LINUX] or so -char* Elf_(r_bin_elf_get_osabi_name)(ELFOBJ *bin) { +char* Elf_(rz_bin_elf_get_osabi_name)(ELFOBJ *bin) { size_t i; size_t num = bin->ehdr.e_shnum; const char *section_name = NULL; @@ -2495,7 +2495,7 @@ char* Elf_(r_bin_elf_get_osabi_name)(ELFOBJ *bin) { return strdup ("linux"); } -ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { +ut8 *Elf_(rz_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { if (bin->phdr) { size_t i; int num = bin->ehdr.e_phnum; @@ -2503,7 +2503,7 @@ ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { if (bin->phdr[i].p_type != PT_NOTE) { continue; } - int bits = Elf_(r_bin_elf_get_bits)(bin); + int bits = Elf_(rz_bin_elf_get_bits)(bin); int elf_nhdr_size = (bits == 64) ? sizeof (Elf64_Nhdr) : sizeof (Elf32_Nhdr); void *elf_nhdr = calloc (elf_nhdr_size, 1); bool regs_found = false; @@ -2512,7 +2512,7 @@ ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { while (!regs_found) { ut32 n_descsz, n_namesz, n_type; int ret; - ret = r_buf_read_at (bin->b, bin->phdr[i].p_offset + offset, elf_nhdr, elf_nhdr_size); + ret = rz_buf_read_at (bin->b, bin->phdr[i].p_offset + offset, elf_nhdr, elf_nhdr_size); if (ret != elf_nhdr_size) { bprintf ("Cannot read NOTES hdr from CORE file\n"); free (elf_nhdr); @@ -2556,7 +2556,7 @@ ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { break; } ut8 *buf = malloc (regsize); - if (r_buf_read_at (bin->b, bin->phdr[i].p_offset + offset + regdelta, buf, regsize) != regsize) { + if (rz_buf_read_at (bin->b, bin->phdr[i].p_offset + offset + regdelta, buf, regsize) != regsize) { free (buf); bprintf ("Cannot read register state from CORE file\n"); return NULL; @@ -2571,13 +2571,13 @@ ut8 *Elf_(r_bin_elf_grab_regstate)(ELFOBJ *bin, int *len) { return NULL; } -int Elf_(r_bin_elf_is_big_endian)(ELFOBJ *bin) { +int Elf_(rz_bin_elf_is_big_endian)(ELFOBJ *bin) { return (bin->ehdr.e_ident[EI_DATA] == ELFDATA2MSB); } /* XXX Init dt_strtab? */ -char *Elf_(r_bin_elf_get_rpath)(ELFOBJ *bin) { - r_return_val_if_fail (bin, NULL); +char *Elf_(rz_bin_elf_get_rpath)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, NULL); char *ret; Elf_(Xword) val; @@ -2601,7 +2601,7 @@ char *Elf_(r_bin_elf_get_rpath)(ELFOBJ *bin) { return NULL; } - r_str_ncpy (ret, bin->strtab + val, ELF_STRING_LENGTH); + rz_str_ncpy (ret, bin->strtab + val, ELF_STRING_LENGTH); return ret; } @@ -2613,7 +2613,7 @@ static bool has_valid_section_header(ELFOBJ *bin, size_t pos) { static void fix_rva_and_offset_relocable_file(ELFOBJ *bin, RBinElfReloc *r, size_t pos) { if (has_valid_section_header (bin, pos)) { r->rva = bin->shdr[bin->g_sections[pos].info].sh_offset + r->offset; - r->rva = Elf_(r_bin_elf_p2v) (bin, r->rva); + r->rva = Elf_(rz_bin_elf_p2v) (bin, r->rva); } else { r->rva = r->offset; } @@ -2621,7 +2621,7 @@ static void fix_rva_and_offset_relocable_file(ELFOBJ *bin, RBinElfReloc *r, size static void fix_rva_and_offset_exec_file(ELFOBJ *bin, RBinElfReloc *r) { r->rva = r->offset; - r->offset = Elf_(r_bin_elf_v2p) (bin, r->offset); + r->offset = Elf_(rz_bin_elf_v2p) (bin, r->offset); } static void fix_rva_and_offset(ELFOBJ *bin, RBinElfReloc *r, size_t pos) { @@ -2633,7 +2633,7 @@ static void fix_rva_and_offset(ELFOBJ *bin, RBinElfReloc *r, size_t pos) { } static bool read_reloc(ELFOBJ *bin, RBinElfReloc *r, Elf_(Xword) rel_mode, ut64 vaddr) { - ut64 offset = Elf_(r_bin_elf_v2p_new) (bin, vaddr); + ut64 offset = Elf_(rz_bin_elf_v2p_new) (bin, vaddr); if (offset == UT64_MAX) { return false; } @@ -2641,7 +2641,7 @@ static bool read_reloc(ELFOBJ *bin, RBinElfReloc *r, Elf_(Xword) rel_mode, ut64 size_t size_struct = get_size_rel_mode (rel_mode); ut8 buf[sizeof (Elf_(Rela))] = { 0 }; - int res = r_buf_read_at (bin->b, offset, buf, size_struct); + int res = rz_buf_read_at (bin->b, offset, buf, size_struct); if (res != size_struct) { return false; } @@ -2649,19 +2649,19 @@ static bool read_reloc(ELFOBJ *bin, RBinElfReloc *r, Elf_(Xword) rel_mode, ut64 size_t i = 0; Elf_(Rela) reloc_info; - reloc_info.r_offset = R_BIN_ELF_READWORD (buf, i); - reloc_info.r_info = R_BIN_ELF_READWORD (buf, i); + reloc_info.rz_offset = R_BIN_ELF_READWORD (buf, i); + reloc_info.rz_info = R_BIN_ELF_READWORD (buf, i); if (rel_mode == DT_RELA) { - reloc_info.r_addend = R_BIN_ELF_READWORD (buf, i); - r->addend = reloc_info.r_addend; + reloc_info.rz_addend = R_BIN_ELF_READWORD (buf, i); + r->addend = reloc_info.rz_addend; } r->rel_mode = rel_mode; r->last = 0; - r->offset = reloc_info.r_offset; - r->sym = ELF_R_SYM (reloc_info.r_info); - r->type = ELF_R_TYPE (reloc_info.r_info); + r->offset = reloc_info.rz_offset; + r->sym = ELF_R_SYM (reloc_info.rz_info); + r->type = ELF_R_TYPE (reloc_info.rz_info); return true; } @@ -2685,10 +2685,10 @@ static bool sectionIsValid(ELFOBJ *bin, RBinElfSection *sect) { } static Elf_(Xword) get_section_mode(ELFOBJ *bin, size_t pos) { - if (r_str_startswith (bin->g_sections[pos].name, ".rela.")) { + if (rz_str_startswith (bin->g_sections[pos].name, ".rela.")) { return DT_RELA; } - if (r_str_startswith (bin->g_sections[pos].name, ".rel.")) { + if (rz_str_startswith (bin->g_sections[pos].name, ".rel.")) { return DT_REL; } return 0; @@ -2830,7 +2830,7 @@ static RBinElfReloc *populate_relocs_record(ELFOBJ *bin) { return relocs; } -RBinElfReloc* Elf_(r_bin_elf_get_relocs) (ELFOBJ *bin) { +RBinElfReloc* Elf_(rz_bin_elf_get_relocs) (ELFOBJ *bin) { if (!bin) { return NULL; } @@ -2841,7 +2841,7 @@ RBinElfReloc* Elf_(r_bin_elf_get_relocs) (ELFOBJ *bin) { return bin->g_relocs; } -RBinElfLib* Elf_(r_bin_elf_get_libs)(ELFOBJ *bin) { +RBinElfLib* Elf_(rz_bin_elf_get_libs)(ELFOBJ *bin) { RBinElfLib *ret = NULL; Elf_(Off) *it = NULL; size_t k = 0; @@ -2850,7 +2850,7 @@ RBinElfLib* Elf_(r_bin_elf_get_libs)(ELFOBJ *bin) { return NULL; } - r_vector_foreach(&bin->dyn_info.dt_needed, it) { + rz_vector_foreach(&bin->dyn_info.dt_needed, it) { Elf_(Off) val = *it; RBinElfLib *r = realloc (ret, (k + 1) * sizeof (RBinElfLib)); @@ -2888,7 +2888,7 @@ static void create_section_from_phdr(ELFOBJ *bin, RBinElfSection *ret, size_t *i return; } - ret[*i].offset = Elf_(r_bin_elf_v2p_new) (bin, addr); + ret[*i].offset = Elf_(rz_bin_elf_v2p_new) (bin, addr); ret[*i].rva = addr; ret[*i].size = sz; strncpy (ret[*i].name, name, R_ARRAY_SIZE (ret[*i].name) - 1); @@ -2902,7 +2902,7 @@ static RBinElfSection *get_sections_from_phdr(ELFOBJ *bin) { size_t num_sections = 0; ut64 reldyn = 0, relava = 0, pltgotva = 0, relva = 0; ut64 reldynsz = 0, relasz = 0, pltgotsz = 0; - r_return_val_if_fail (bin && bin->phdr, NULL); + rz_return_val_if_fail (bin && bin->phdr, NULL); if (!bin->ehdr.e_phnum) { return NULL; @@ -2949,12 +2949,12 @@ static RBinElfSection *get_sections_from_phdr(ELFOBJ *bin) { return ret; } -RBinElfSection* Elf_(r_bin_elf_get_sections)(ELFOBJ *bin) { +RBinElfSection* Elf_(rz_bin_elf_get_sections)(ELFOBJ *bin) { RBinElfSection *ret = NULL; char unknown_s[32], invalid_s[32]; int i, nidx, unknown_c=0, invalid_c=0; - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); if (bin->g_sections) { return bin->g_sections; } @@ -3045,7 +3045,7 @@ static const char *bind2str(Elf_(Sym) *sym) { } } -static const char *type2str(ELFOBJ *bin, struct r_bin_elf_symbol_t *ret, Elf_(Sym) *sym) { +static const char *type2str(ELFOBJ *bin, struct rz_bin_elf_symbol_t *ret, Elf_(Sym) *sym) { if (bin && ret && is_special_symbol (bin, sym, ret->name)) { return R_BIN_TYPE_SPECIAL_SYM_STR; } @@ -3066,7 +3066,7 @@ static const char *type2str(ELFOBJ *bin, struct r_bin_elf_symbol_t *ret, Elf_(Sy } } -static void fill_symbol_bind_and_type(ELFOBJ *bin, struct r_bin_elf_symbol_t *ret, Elf_(Sym) *sym) { +static void fill_symbol_bind_and_type(ELFOBJ *bin, struct rz_bin_elf_symbol_t *ret, Elf_(Sym) *sym) { ret->bind = bind2str (sym); ret->type = type2str (bin, ret, sym); } @@ -3088,7 +3088,7 @@ static RBinElfSymbol* get_symbols_from_phdr(ELFOBJ *bin, int type) { return NULL; } - addr_sym_table = Elf_(r_bin_elf_v2p) (bin, bin->dyn_info.dt_symtab); + addr_sym_table = Elf_(rz_bin_elf_v2p) (bin, bin->dyn_info.dt_symtab); sym_size = bin->dyn_info.dt_syment; if (!sym_size) { goto beach; @@ -3112,7 +3112,7 @@ static RBinElfSymbol* get_symbols_from_phdr(ELFOBJ *bin, int type) { size_t capacity1 = 4096; size_t capacity2 = 4096; sym = (Elf_(Sym)*) calloc (capacity1, sym_size); - ret = (RBinElfSymbol *) calloc (capacity2, sizeof (struct r_bin_elf_symbol_t)); + ret = (RBinElfSymbol *) calloc (capacity2, sizeof (struct rz_bin_elf_symbol_t)); if (!sym || !ret) { goto beach; } @@ -3127,7 +3127,7 @@ static RBinElfSymbol* get_symbols_from_phdr(ELFOBJ *bin, int type) { capacity1 *= GROWTH_FACTOR; } if (ret_ctr >= capacity2) { // maybe grow - RBinElfSymbol *temp_ret = realloc (ret, capacity2 * GROWTH_FACTOR * sizeof (struct r_bin_elf_symbol_t)); + RBinElfSymbol *temp_ret = realloc (ret, capacity2 * GROWTH_FACTOR * sizeof (struct rz_bin_elf_symbol_t)); if (!temp_ret) { goto beach; } @@ -3135,7 +3135,7 @@ static RBinElfSymbol* get_symbols_from_phdr(ELFOBJ *bin, int type) { capacity2 *= GROWTH_FACTOR; } // read in one entry - r = r_buf_read_at (bin->b, addr_sym_table + i * sizeof (Elf_ (Sym)), s, sizeof (Elf_ (Sym))); + r = rz_buf_read_at (bin->b, addr_sym_table + i * sizeof (Elf_ (Sym)), s, sizeof (Elf_ (Sym))); if (r < 1) { goto beach; } @@ -3179,7 +3179,7 @@ static RBinElfSymbol* get_symbols_from_phdr(ELFOBJ *bin, int type) { !strcmp (type2str (NULL, NULL, &sym[i]), R_BIN_TYPE_UNKNOWN_STR)) { goto done; } - tmp_offset = Elf_(r_bin_elf_v2p_new) (bin, toffset); + tmp_offset = Elf_(rz_bin_elf_v2p_new) (bin, toffset); if (tmp_offset == UT64_MAX) { tmp_offset = toffset; is_vaddr = true; @@ -3254,7 +3254,7 @@ beach: return NULL; } -static RBinElfSymbol *Elf_(r_bin_elf_get_phdr_symbols)(ELFOBJ *bin) { +static RBinElfSymbol *Elf_(rz_bin_elf_get_phdr_symbols)(ELFOBJ *bin) { if (!bin) { return NULL; } @@ -3265,8 +3265,8 @@ static RBinElfSymbol *Elf_(r_bin_elf_get_phdr_symbols)(ELFOBJ *bin) { return bin->phdr_symbols; } -static RBinElfSymbol *Elf_(r_bin_elf_get_phdr_imports)(ELFOBJ *bin) { - r_return_val_if_fail (bin, NULL); +static RBinElfSymbol *Elf_(rz_bin_elf_get_phdr_imports)(ELFOBJ *bin) { + rz_return_val_if_fail (bin, NULL); if (!bin->phdr_imports) { bin->phdr_imports = get_symbols_from_phdr (bin, R_BIN_ELF_IMPORT_SYMBOLS); } @@ -3275,8 +3275,8 @@ static RBinElfSymbol *Elf_(r_bin_elf_get_phdr_imports)(ELFOBJ *bin) { static RBinElfSymbol *Elf_(get_phdr_symbols)(ELFOBJ *bin, int type) { return (type != R_BIN_ELF_IMPORT_SYMBOLS) - ? Elf_(r_bin_elf_get_phdr_symbols) (bin) - : Elf_(r_bin_elf_get_phdr_imports) (bin); + ? Elf_(rz_bin_elf_get_phdr_symbols) (bin) + : Elf_(rz_bin_elf_get_phdr_imports) (bin); } static int Elf_(fix_symbols)(ELFOBJ *bin, int nsym, int type, RBinElfSymbol **sym) { @@ -3303,7 +3303,7 @@ static int Elf_(fix_symbols)(ELFOBJ *bin, int nsym, int type, RBinElfSymbol **sy } if (d) { p->in_shdr = true; - if (*p->name && *d->name && r_str_startswith (d->name, "$")) { + if (*p->name && *d->name && rz_str_startswith (d->name, "$")) { strcpy (d->name, p->name); } } @@ -3368,12 +3368,12 @@ static void setsymord(ELFOBJ* eobj, ut32 ord, RBinSymbol *ptr) { if (!eobj->symbols_by_ord || ord >= eobj->symbols_by_ord_size) { return; } - r_bin_symbol_free (eobj->symbols_by_ord[ord]); + rz_bin_symbol_free (eobj->symbols_by_ord[ord]); eobj->symbols_by_ord[ord] = ptr; } -static void _set_arm_thumb_bits(struct Elf_(r_bin_elf_obj_t) *bin, RBinSymbol **sym) { - int bin_bits = Elf_(r_bin_elf_get_bits) (bin); +static void _set_arm_thumb_bits(struct Elf_(rz_bin_elf_obj_t) *bin, RBinSymbol **sym) { + int bin_bits = Elf_(rz_bin_elf_get_bits) (bin); RBinSymbol *ptr = *sym; int len = strlen (ptr->name); if (ptr->name[0] == '$' && (len >= 2 && !ptr->name[2])) { @@ -3414,8 +3414,8 @@ arm_symbol: } } -RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin, - struct r_bin_elf_symbol_t *symbol, +RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(rz_bin_elf_obj_t) *bin, + struct rz_bin_elf_symbol_t *symbol, const char *namefmt) { ut64 paddr, vaddr; RBinSymbol *ptr = NULL; @@ -3424,13 +3424,13 @@ RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(r_bin_elf_obj_t) *bin, vaddr = symbol->offset; } else { paddr = symbol->offset; - vaddr = Elf_(r_bin_elf_p2v_new) (bin, paddr); + vaddr = Elf_(rz_bin_elf_p2v_new) (bin, paddr); } if (!(ptr = R_NEW0 (RBinSymbol))) { return NULL; } - ptr->name = symbol->name[0] ? r_str_newf (namefmt, &symbol->name[0]) : strdup (""); + ptr->name = symbol->name[0] ? rz_str_newf (namefmt, &symbol->name[0]) : strdup (""); ptr->forwarder = "NONE"; ptr->bind = symbol->bind; ptr->type = symbol->type; @@ -3468,7 +3468,7 @@ static int cmp_RBinElfSymbol(const RBinElfSymbol *a, const RBinElfSymbol *b) { return strcmp(a->type, b->type); } -// TODO: return RList .. or run a callback with that symbol constructed, so we don't have to do it twice +// TODO: return RzList .. or run a callback with that symbol constructed, so we don't have to do it twice static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type) { ut32 shdr_size; int tsize, nsym, ret_ctr = 0, i, j, r, k, newsize; @@ -3529,7 +3529,7 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type strtab_section->sh_offset + strtab_section->sh_size > bin->size) { goto beach; } - if (r_buf_read_at (bin->b, strtab_section->sh_offset, + if (rz_buf_read_at (bin->b, strtab_section->sh_offset, (ut8*)strtab, strtab_section->sh_size) == -1) { bprintf ("read (syms strtab)\n"); goto beach; @@ -3574,7 +3574,7 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type } for (j = 0; j < nsym; j++) { int k = 0; - r = r_buf_read_at (bin->b, bin->shdr[i].sh_offset + j * sizeof (Elf_(Sym)), s, sizeof (Elf_(Sym))); + r = rz_buf_read_at (bin->b, bin->shdr[i].sh_offset + j * sizeof (Elf_(Sym)), s, sizeof (Elf_(Sym))); if (r < 1) { bprintf ("read (sym)\n"); goto beach; @@ -3631,7 +3631,7 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type ret[ret_ctr].offset = sym[k].st_value + bin->shdr[sym[k].st_shndx].sh_offset; } } else { - ret[ret_ctr].offset = Elf_(r_bin_elf_v2p_new) (bin, toffset); + ret[ret_ctr].offset = Elf_(rz_bin_elf_v2p_new) (bin, toffset); if (ret[ret_ctr].offset == UT64_MAX) { ret[ret_ctr].offset = toffset; is_vaddr = true; @@ -3644,14 +3644,14 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type } { int st_name = sym[k].st_name; - int maxsize = R_MIN (r_buf_size (bin->b), strtab_section->sh_size); + int maxsize = R_MIN (rz_buf_size (bin->b), strtab_section->sh_size); if (is_section_local_sym (bin, &sym[k])) { const char *shname = &bin->shstrtab[bin->shdr[sym[k].st_shndx].sh_name]; - r_str_ncpy (ret[ret_ctr].name, shname, ELF_STRING_LENGTH); + rz_str_ncpy (ret[ret_ctr].name, shname, ELF_STRING_LENGTH); } else if (st_name <= 0 || st_name >= maxsize) { ret[ret_ctr].name[0] = 0; } else { - r_str_ncpy(ret[ret_ctr].name, &strtab[st_name], ELF_STRING_LENGTH); + rz_str_ncpy(ret[ret_ctr].name, &strtab[st_name], ELF_STRING_LENGTH); ret[ret_ctr].type = type2str (bin, &ret[ret_ctr], &sym[k]); if (ht_pp_find (symbol_map, &ret[ret_ctr], NULL)) { @@ -3694,7 +3694,7 @@ static RBinElfSymbol* Elf_(_r_bin_elf_get_symbols_imports)(ELFOBJ *bin, int type // Elf_(fix_symbols) may find additional symbols, some of which could be // imported symbols. Let's reserve additional space for them. - r_warn_if_fail (nsym >= ret_ctr); + rz_warn_if_fail (nsym >= ret_ctr); import_ret_ctr += nsym - ret_ctr; aux = ret; @@ -3742,21 +3742,21 @@ beach: return NULL; } -RBinElfSymbol *Elf_(r_bin_elf_get_symbols)(ELFOBJ *bin) { +RBinElfSymbol *Elf_(rz_bin_elf_get_symbols)(ELFOBJ *bin) { if (!bin->g_symbols) { bin->g_symbols = Elf_(_r_bin_elf_get_symbols_imports) (bin, R_BIN_ELF_ALL_SYMBOLS); } return bin->g_symbols; } -RBinElfSymbol *Elf_(r_bin_elf_get_imports)(ELFOBJ *bin) { +RBinElfSymbol *Elf_(rz_bin_elf_get_imports)(ELFOBJ *bin) { if (!bin->g_imports) { bin->g_imports = Elf_(_r_bin_elf_get_symbols_imports) (bin, R_BIN_ELF_IMPORT_SYMBOLS); } return bin->g_imports; } -RBinElfField* Elf_(r_bin_elf_get_fields)(ELFOBJ *bin) { +RBinElfField* Elf_(rz_bin_elf_get_fields)(ELFOBJ *bin) { RBinElfField *ret = NULL; int i = 0, j; if (!bin || !(ret = calloc ((bin->ehdr.e_phnum + 3 + 1), sizeof (RBinElfField)))) { @@ -3780,7 +3780,7 @@ RBinElfField* Elf_(r_bin_elf_get_fields)(ELFOBJ *bin) { return ret; } -void Elf_(r_bin_elf_free)(ELFOBJ* bin) { +void Elf_(rz_bin_elf_free)(ELFOBJ* bin) { if (!bin) { return; } @@ -3789,7 +3789,7 @@ void Elf_(r_bin_elf_free)(ELFOBJ* bin) { free (bin->strtab); free (bin->shstrtab); free (bin->dynstr); - r_vector_fini (&bin->dyn_info.dt_needed); + rz_vector_fini (&bin->dyn_info.dt_needed); //free (bin->strtab_section); size_t i; if (bin->imports_by_ord) { @@ -3800,11 +3800,11 @@ void Elf_(r_bin_elf_free)(ELFOBJ* bin) { } if (bin->symbols_by_ord) { for (i = 0; isymbols_by_ord_size; i++) { - r_bin_symbol_free (bin->symbols_by_ord[i]); + rz_bin_symbol_free (bin->symbols_by_ord[i]); } free (bin->symbols_by_ord); } - r_buf_free (bin->b); + rz_buf_free (bin->b); if (bin->g_symbols != bin->phdr_symbols) { R_FREE (bin->phdr_symbols); } @@ -3820,15 +3820,15 @@ void Elf_(r_bin_elf_free)(ELFOBJ* bin) { free (bin); } -ELFOBJ* Elf_(r_bin_elf_new_buf)(RBuffer *buf, bool verbose) { +ELFOBJ* Elf_(rz_bin_elf_new_buf)(RBuffer *buf, bool verbose) { ELFOBJ *bin = R_NEW0 (ELFOBJ); if (bin) { bin->kv = sdb_new0 (); - bin->size = r_buf_size (buf); + bin->size = rz_buf_size (buf); bin->verbose = verbose; - bin->b = r_buf_ref (buf); + bin->b = rz_buf_ref (buf); if (!elf_init (bin)) { - Elf_(r_bin_elf_free) (bin); + Elf_(rz_bin_elf_free) (bin); return NULL; } } @@ -3843,11 +3843,11 @@ static int is_in_vphdr(Elf_(Phdr) * p, ut64 addr) { return addr >= p->p_vaddr && addr < p->p_vaddr + p->p_filesz; } -/* Deprecated temporarily. Use r_bin_elf_p2v_new in new code for now. */ -ut64 Elf_(r_bin_elf_p2v) (ELFOBJ *bin, ut64 paddr) { +/* Deprecated temporarily. Use rz_bin_elf_p2v_new in new code for now. */ +ut64 Elf_(rz_bin_elf_p2v) (ELFOBJ *bin, ut64 paddr) { size_t i; - r_return_val_if_fail (bin, 0); + rz_return_val_if_fail (bin, 0); if (!bin->phdr) { if (is_bin_etrel (bin)) { return bin->baddr + paddr; @@ -3867,9 +3867,9 @@ ut64 Elf_(r_bin_elf_p2v) (ELFOBJ *bin, ut64 paddr) { return paddr; } -/* Deprecated temporarily. Use r_bin_elf_v2p_new in new code for now. */ -ut64 Elf_(r_bin_elf_v2p) (ELFOBJ *bin, ut64 vaddr) { - r_return_val_if_fail (bin, 0); +/* Deprecated temporarily. Use rz_bin_elf_v2p_new in new code for now. */ +ut64 Elf_(rz_bin_elf_v2p) (ELFOBJ *bin, ut64 vaddr) { + rz_return_val_if_fail (bin, 0); if (!bin->phdr) { if (is_bin_etrel (bin)) { return vaddr - bin->baddr; @@ -3892,10 +3892,10 @@ ut64 Elf_(r_bin_elf_v2p) (ELFOBJ *bin, ut64 vaddr) { /* converts a physical address to the virtual address, looking * at the program headers in the binary bin */ -ut64 Elf_(r_bin_elf_p2v_new) (ELFOBJ *bin, ut64 paddr) { +ut64 Elf_(rz_bin_elf_p2v_new) (ELFOBJ *bin, ut64 paddr) { size_t i; - r_return_val_if_fail (bin, UT64_MAX); + rz_return_val_if_fail (bin, UT64_MAX); if (!bin->phdr) { if (is_bin_etrel (bin)) { return bin->baddr + paddr; @@ -3914,10 +3914,10 @@ ut64 Elf_(r_bin_elf_p2v_new) (ELFOBJ *bin, ut64 paddr) { /* converts a virtual address to the relative physical address, looking * at the program headers in the binary bin */ -ut64 Elf_(r_bin_elf_v2p_new) (ELFOBJ *bin, ut64 vaddr) { +ut64 Elf_(rz_bin_elf_v2p_new) (ELFOBJ *bin, ut64 vaddr) { size_t i; - r_return_val_if_fail (bin, UT64_MAX); + rz_return_val_if_fail (bin, UT64_MAX); if (!bin->phdr) { if (is_bin_etrel (bin)) { return vaddr - bin->baddr; @@ -3933,13 +3933,13 @@ ut64 Elf_(r_bin_elf_v2p_new) (ELFOBJ *bin, ut64 vaddr) { return UT64_MAX; } -static bool get_nt_file_maps (ELFOBJ *bin, RList *core_maps) { +static bool get_nt_file_maps (ELFOBJ *bin, RzList *core_maps) { ut16 ph, ph_num = bin->ehdr.e_phnum; for (ph = 0; ph < ph_num; ph++) { Elf_(Phdr) *p = &bin->phdr[ph]; if (p->p_type == PT_NOTE) { - int bits = Elf_(r_bin_elf_get_bits)(bin); + int bits = Elf_(rz_bin_elf_get_bits)(bin); int elf_nhdr_size = (bits == 64) ? sizeof (Elf64_Nhdr) : sizeof (Elf32_Nhdr); int size_of = (bits == 64) ? sizeof (ut64) : sizeof (ut32); void *elf_nhdr = calloc (elf_nhdr_size, 1); @@ -3949,7 +3949,7 @@ static bool get_nt_file_maps (ELFOBJ *bin, RList *core_maps) { while (!found) { int ret; ut32 n_descsz, n_namesz, n_type; - ret = r_buf_read_at (bin->b, + ret = rz_buf_read_at (bin->b, bin->phdr[ph].p_offset + offset, elf_nhdr, elf_nhdr_size); if (ret != elf_nhdr_size) { @@ -3997,11 +3997,11 @@ static bool get_nt_file_maps (ELFOBJ *bin, RList *core_maps) { break; } char str[512] = {0}; - r_buf_read_at (bin->b, jump + len_str, (ut8*)str, sizeof (str) - 1); + rz_buf_read_at (bin->b, jump + len_str, (ut8*)str, sizeof (str) - 1); str[sizeof (str) - 1] = 0; // null terminate string - RListIter *iter; + RzListIter *iter; RBinMap *p; - r_list_foreach (core_maps, iter, p) { + rz_list_foreach (core_maps, iter, p) { if (p->addr == addr) { p->file = strdup (str); } @@ -4018,19 +4018,19 @@ fail: return false; } -static void r_bin_elf_map_free(RBinMap *map) { +static void rz_bin_elf_map_free(RBinMap *map) { if (map) { free (map->file); free (map); } } -RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *bin) { +RzList *Elf_(rz_bin_elf_get_maps)(ELFOBJ *bin) { ut16 ph, ph_num = bin->ehdr.e_phnum; //Skip PT_NOTE if (!bin->phdr) { return NULL; } - RList *maps = r_list_newf ((RListFree)r_bin_elf_map_free); + RzList *maps = rz_list_newf ((RzListFree)rz_bin_elf_map_free); for (ph = 0; ph < ph_num; ph++) { Elf_(Phdr) *p = &bin->phdr[ph]; if (p->p_type == PT_LOAD) { @@ -4041,12 +4041,12 @@ RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *bin) { map->perms = p->p_flags; map->offset = p->p_offset; map->file = NULL; - r_list_append (maps, map); + rz_list_append (maps, map); } } } - if (!r_list_empty (maps)) { + if (!rz_list_empty (maps)) { if (!get_nt_file_maps (bin, maps)) { eprintf ("Could not retrieve the names of all maps from NT_FILE\n"); } @@ -4055,7 +4055,7 @@ RList *Elf_(r_bin_elf_get_maps)(ELFOBJ *bin) { return maps; } -char *Elf_(r_bin_elf_compiler)(ELFOBJ *bin) { +char *Elf_(rz_bin_elf_compiler)(ELFOBJ *bin) { RBinElfSection *section = get_section_by_name (bin, ".comment"); if (!section) { return NULL; @@ -4069,7 +4069,7 @@ char *Elf_(r_bin_elf_compiler)(ELFOBJ *bin) { if (!buf) { return NULL; } - if (r_buf_read_at (bin->b, off, (ut8*)buf, sz) < 1) { + if (rz_buf_read_at (bin->b, off, (ut8*)buf, sz) < 1) { free (buf); return NULL; } @@ -4080,13 +4080,13 @@ char *Elf_(r_bin_elf_compiler)(ELFOBJ *bin) { nullbyte[0] = ' '; } buf[sz] = 0; - r_str_trim (buf); - char * res = r_str_escape (buf); + rz_str_trim (buf); + char * res = rz_str_escape (buf); free (buf); return res; } -bool Elf_(r_bin_elf_is_executable)(ELFOBJ *bin) { +bool Elf_(rz_bin_elf_is_executable)(ELFOBJ *bin) { const int t = bin->ehdr.e_type; return t == ET_EXEC || t == ET_DYN; } diff --git a/librz/bin/format/elf/elf.h b/librz/bin/format/elf/elf.h new file mode 100644 index 0000000000..a675a77a65 --- /dev/null +++ b/librz/bin/format/elf/elf.h @@ -0,0 +1,221 @@ +#include +#include +#include +#include + +#include "elf_specs.h" + +#ifndef _INCLUDE_ELF_H_ +#define _INCLUDE_ELF_H_ + +#define R_BIN_ELF_SCN_IS_EXECUTABLE(x) x & SHF_EXECINSTR +#define R_BIN_ELF_SCN_IS_READABLE(x) x & SHF_ALLOC +#define R_BIN_ELF_SCN_IS_WRITABLE(x) x & SHF_WRITE + +#define R_BIN_ELF_SYMTAB_SYMBOLS 1 << 0 +#define R_BIN_ELF_DYNSYM_SYMBOLS 1 << 1 +#define R_BIN_ELF_IMPORT_SYMBOLS (1 << 2 | (bin->ehdr.e_type == ET_REL ? R_BIN_ELF_SYMTAB_SYMBOLS : R_BIN_ELF_DYNSYM_SYMBOLS)) +#define R_BIN_ELF_ALL_SYMBOLS (R_BIN_ELF_SYMTAB_SYMBOLS | R_BIN_ELF_DYNSYM_SYMBOLS) +#define ELFOBJ struct Elf_(rz_bin_elf_obj_t) + +#if R_BIN_ELF64 +#define R_BIN_ELF_WORDSIZE 0x8 +#define R_BIN_ELF_WORD_MAX UT64_MAX +#define R_BIN_ELF_READWORD(x, i) READ64 (x, i) +#define R_BIN_ELF_BREADWORD(x, i) BREAD64 (x, i) +#define R_BIN_ELF_ADDR_MAX UT64_MAX +#define R_BIN_ELF_XWORD_MAX UT64_MAX +#else +#define R_BIN_ELF_WORDSIZE 0x4 +#define R_BIN_ELF_WORD_MAX UT32_MAX +#define R_BIN_ELF_READWORD(x, i) READ32 (x, i) +#define R_BIN_ELF_BREADWORD(x, i) BREAD32 (x, i) +#define R_BIN_ELF_ADDR_MAX UT32_MAX +#define R_BIN_ELF_XWORD_MAX UT64_MAX +#endif + + +typedef struct rz_bin_elf_section_t { + ut64 offset; + ut64 rva; + ut64 size; + ut64 align; + ut32 flags; + ut32 link; + ut32 info; + char name[ELF_STRING_LENGTH]; + int last; + int type; +} RBinElfSection; + +typedef struct rz_bin_elf_symbol_t { + ut64 offset; + ut64 size; + ut32 ordinal; + const char *bind; + const char *type; + char name[ELF_STRING_LENGTH]; + char libname[ELF_STRING_LENGTH]; + int last; + bool in_shdr; + bool is_sht_null; + bool is_vaddr; /* when true, offset is virtual address, otherwise it's physical */ + bool is_imported; +} RBinElfSymbol; + +typedef struct rz_bin_elf_reloc_t { + int sym; + int type; + Elf_(Xword) rel_mode; + st64 addend; + ut64 offset; + ut64 rva; + ut16 section; + int last; + ut64 sto; +} RBinElfReloc; + +typedef struct rz_bin_elf_field_t { + ut64 offset; + char name[ELF_STRING_LENGTH]; + int last; +} RBinElfField; + +typedef struct rz_bin_elf_string_t { + ut64 offset; + ut64 size; + char type; + char string[ELF_STRING_LENGTH]; + int last; +} RBinElfString; + +typedef struct Elf_(rz_bin_elf_dynamic_info) { + Elf_(Xword) dt_pltrelsz; + Elf_(Addr) dt_pltgot; + Elf_(Addr) dt_hash; + Elf_(Addr) dt_strtab; + Elf_(Addr) dt_symtab; + Elf_(Addr) dt_rela; + Elf_(Xword) dt_relasz; + Elf_(Xword) dt_relaent; + Elf_(Xword) dt_strsz; + Elf_(Xword) dt_syment; + Elf_(Addr) dt_fini; + Elf_(Addr) dt_rel; + Elf_(Xword) dt_relsz; + Elf_(Xword) dt_relent; + Elf_(Xword) dt_pltrel; + Elf_(Addr) dt_jmprel; + Elf_(Addr) dt_mips_pltgot; + bool dt_bind_now; + Elf_(Xword) dt_flags; + Elf_(Xword) dt_flags_1; + Elf_(Xword) dt_rpath; + Elf_(Xword) dt_runpath; + RzVector dt_needed; +} RBinElfDynamicInfo; + +typedef struct rz_bin_elf_lib_t { + char name[ELF_STRING_LENGTH]; + int last; +} RBinElfLib; + +struct Elf_(rz_bin_elf_obj_t) { + Elf_(Ehdr) ehdr; + Elf_(Phdr) *phdr; + Elf_(Shdr) *shdr; + + Elf_(Shdr) *strtab_section; + ut64 strtab_size; + char *strtab; + + Elf_(Shdr) *shstrtab_section; + ut64 shstrtab_size; + char *shstrtab; + + RBinElfDynamicInfo dyn_info; + + ut64 version_info[DT_VERSIONTAGNUM]; + + char *dynstr; + ut32 dynstr_size; + + RBinImport **imports_by_ord; + size_t imports_by_ord_size; + RBinSymbol **symbols_by_ord; + size_t symbols_by_ord_size; + + int bss; + ut64 size; + ut64 baddr; + ut64 boffset; + int endian; + bool verbose; + const char* file; + RBuffer *b; + Sdb *kv; + /*cache purpose*/ + RBinElfSection *g_sections; + RBinElfSymbol *g_symbols; + RBinElfSymbol *g_imports; + RBinElfReloc *g_relocs; + ut32 g_reloc_num; + RBinElfSymbol *phdr_symbols; + RBinElfSymbol *phdr_imports; + HtUP *rel_cache; +}; + +int Elf_(rz_bin_elf_has_va)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_get_section_addr)(struct Elf_(rz_bin_elf_obj_t) *bin, const char *section_name); +ut64 Elf_(rz_bin_elf_get_section_offset)(struct Elf_(rz_bin_elf_obj_t) *bin, const char *section_name); +ut64 Elf_(rz_bin_elf_get_baddr)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_p2v)(struct Elf_(rz_bin_elf_obj_t) *bin, ut64 paddr); +ut64 Elf_(rz_bin_elf_v2p)(struct Elf_(rz_bin_elf_obj_t) *bin, ut64 vaddr); +ut64 Elf_(rz_bin_elf_p2v_new)(struct Elf_(rz_bin_elf_obj_t) *bin, ut64 paddr); +ut64 Elf_(rz_bin_elf_v2p_new)(struct Elf_(rz_bin_elf_obj_t) *bin, ut64 vaddr); +ut64 Elf_(rz_bin_elf_get_boffset)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_get_entry_offset)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_get_main_offset)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_get_init_offset)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut64 Elf_(rz_bin_elf_get_fini_offset)(struct Elf_(rz_bin_elf_obj_t) *bin); +char *Elf_(rz_bin_elf_intrp)(struct Elf_(rz_bin_elf_obj_t) *bin); +char *Elf_(rz_bin_elf_compiler)(ELFOBJ *bin); +bool Elf_(rz_bin_elf_get_stripped)(struct Elf_(rz_bin_elf_obj_t) *bin); +bool Elf_(rz_bin_elf_is_static)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_data_encoding)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_arch)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_machine_name)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_head_flag)(ELFOBJ *bin); //yin +char* Elf_(rz_bin_elf_get_abi)(ELFOBJ *bin); +char* Elf_(rz_bin_elf_get_cpu)(ELFOBJ *bin); +char* Elf_(rz_bin_elf_get_file_type)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_elf_class)(struct Elf_(rz_bin_elf_obj_t) *bin); +int Elf_(rz_bin_elf_get_bits)(struct Elf_(rz_bin_elf_obj_t) *bin); +char* Elf_(rz_bin_elf_get_osabi_name)(struct Elf_(rz_bin_elf_obj_t) *bin); +int Elf_(rz_bin_elf_is_big_endian)(struct Elf_(rz_bin_elf_obj_t) *bin); +RBinElfReloc* Elf_(rz_bin_elf_get_relocs)(struct Elf_(rz_bin_elf_obj_t) *bin); +RBinElfLib* Elf_(rz_bin_elf_get_libs)(struct Elf_(rz_bin_elf_obj_t) *bin); +RBinElfSection* Elf_(rz_bin_elf_get_sections)(struct Elf_(rz_bin_elf_obj_t) *bin); +RBinElfSymbol* Elf_(rz_bin_elf_get_symbols)(struct Elf_(rz_bin_elf_obj_t) *bin); +RBinElfSymbol* Elf_(rz_bin_elf_get_imports)(struct Elf_(rz_bin_elf_obj_t) *bin); +struct rz_bin_elf_field_t* Elf_(rz_bin_elf_get_fields)(struct Elf_(rz_bin_elf_obj_t) *bin); +char *Elf_(rz_bin_elf_get_rpath)(struct Elf_(rz_bin_elf_obj_t) *bin); + +struct Elf_(rz_bin_elf_obj_t)* Elf_(rz_bin_elf_new)(const char* file, bool verbose); +struct Elf_(rz_bin_elf_obj_t)* Elf_(rz_bin_elf_new_buf)(RBuffer *buf, bool verbose); +void Elf_(rz_bin_elf_free)(struct Elf_(rz_bin_elf_obj_t)* bin); + +ut64 Elf_(rz_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size); +bool Elf_(rz_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms); +bool Elf_(rz_bin_elf_entry_write)(RBinFile *bf, ut64 addr); +bool Elf_(rz_bin_elf_del_rpath)(RBinFile *bf); + +bool Elf_(rz_bin_elf_is_executable)(ELFOBJ *bin); +int Elf_(rz_bin_elf_has_relro)(struct Elf_(rz_bin_elf_obj_t) *bin); +int Elf_(rz_bin_elf_has_nx)(struct Elf_(rz_bin_elf_obj_t) *bin); +ut8 *Elf_(rz_bin_elf_grab_regstate)(struct Elf_(rz_bin_elf_obj_t) *bin, int *len); +RzList *Elf_(rz_bin_elf_get_maps)(ELFOBJ *bin); +RBinSymbol *Elf_(_r_bin_elf_convert_symbol)(struct Elf_(rz_bin_elf_obj_t) *bin, + struct rz_bin_elf_symbol_t *symbol, + const char *namefmt); +#endif diff --git a/libr/bin/format/elf/elf64.c b/librz/bin/format/elf/elf64.c similarity index 100% rename from libr/bin/format/elf/elf64.c rename to librz/bin/format/elf/elf64.c diff --git a/libr/bin/format/elf/elf64.h b/librz/bin/format/elf/elf64.h similarity index 100% rename from libr/bin/format/elf/elf64.h rename to librz/bin/format/elf/elf64.h diff --git a/libr/bin/format/elf/elf64_write.c b/librz/bin/format/elf/elf64_write.c similarity index 100% rename from libr/bin/format/elf/elf64_write.c rename to librz/bin/format/elf/elf64_write.c diff --git a/libr/bin/format/elf/elf_specs.h b/librz/bin/format/elf/elf_specs.h similarity index 100% rename from libr/bin/format/elf/elf_specs.h rename to librz/bin/format/elf/elf_specs.h diff --git a/libr/bin/format/elf/elf_write.c b/librz/bin/format/elf/elf_write.c similarity index 74% rename from libr/bin/format/elf/elf_write.c rename to librz/bin/format/elf/elf_write.c index f171b661f4..c8266a02ab 100644 --- a/libr/bin/format/elf/elf_write.c +++ b/librz/bin/format/elf/elf_write.c @@ -3,17 +3,17 @@ #include #include #include -#include -#include +#include +#include #include "elf.h" // XXX UGLY CODE /* TODO: Take care of endianness */ /* TODO: Real error handling */ /* TODO: Resize sections before .init */ -// ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const char *name, ut64 size) { -ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; // , const char *name, ut64 size) { +// ut64 Elf_(rz_bin_elf_resize_section)(struct Elf_(rz_bin_elf_obj_t) *bin, const char *name, ut64 size) { +ut64 Elf_(rz_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; // , const char *name, ut64 size) { Elf_(Ehdr) *ehdr = &bin->ehdr; Elf_(Phdr) *phdr = bin->phdr, *phdrp; Elf_(Shdr) *shdr = bin->shdr, *shdrp; @@ -68,15 +68,15 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { perror ("malloc"); return 0; } - if (r_buf_read_at (bin->b, shdrp->sh_offset, (ut8*)rel, shdrp->sh_size) == -1) { + if (rz_buf_read_at (bin->b, shdrp->sh_offset, (ut8*)rel, shdrp->sh_size) == -1) { perror("read (rel)"); } for (j = 0, relp = rel; j < shdrp->sh_size; j += sizeof(Elf_(Rel)), relp++) { - /* rewrite relp->r_offset */ - if (relp->r_offset - got_addr + got_offset >= rsz_offset + rsz_osize) { - relp->r_offset+=delta; + /* rewrite relp->rz_offset */ + if (relp->rz_offset - got_addr + got_offset >= rsz_offset + rsz_osize) { + relp->rz_offset+=delta; off = shdrp->sh_offset + j; - if (r_buf_write_at (bin->b, off, (ut8*)relp, sizeof (Elf_(Rel))) == -1) { + if (rz_buf_write_at (bin->b, off, (ut8*)relp, sizeof (Elf_(Rel))) == -1) { perror("write (imports)"); } } @@ -90,15 +90,15 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { perror("malloc"); return 0; } - if (r_buf_read_at (bin->b, shdrp->sh_offset, (ut8*)rel, shdrp->sh_size) == -1) { + if (rz_buf_read_at (bin->b, shdrp->sh_offset, (ut8*)rel, shdrp->sh_size) == -1) { perror("read (rel)"); } for (j = 0, relp = rel; j < shdrp->sh_size; j += sizeof(Elf_(Rela)), relp++) { - /* rewrite relp->r_offset */ - if (relp->r_offset - got_addr + got_offset >= rsz_offset + rsz_osize) { - relp->r_offset+=delta; + /* rewrite relp->rz_offset */ + if (relp->rz_offset - got_addr + got_offset >= rsz_offset + rsz_osize) { + relp->rz_offset+=delta; off = shdrp->sh_offset + j; - if (r_buf_write_at (bin->b, off, (ut8*)relp, sizeof (Elf_(Rela))) == -1) { + if (rz_buf_write_at (bin->b, off, (ut8*)relp, sizeof (Elf_(Rela))) == -1) { perror("write (imports)"); } } @@ -120,7 +120,7 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { } } off = ehdr->e_shoff + i * sizeof (Elf_(Shdr)); - if (r_buf_write_at (bin->b, off, (ut8*)shdrp, sizeof (Elf_(Shdr))) == -1) { + if (rz_buf_write_at (bin->b, off, (ut8*)shdrp, sizeof (Elf_(Shdr))) == -1) { perror ("write (shdr)"); } printf ("-> elf section (%s)\n", &strtab[shdrp->sh_name]); @@ -147,7 +147,7 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { phdrp->p_memsz += delta; } off = ehdr->e_phoff + i * sizeof (Elf_(Phdr)); - if (r_buf_write_at (bin->b, off, (ut8 *)phdrp, sizeof (Elf_ (Phdr))) == -1) { + if (rz_buf_write_at (bin->b, off, (ut8 *)phdrp, sizeof (Elf_ (Phdr))) == -1) { perror ("write (phdr)"); } printf ("-> program header (0x%08"PFMT64x")\n", (ut64) phdrp->p_offset); @@ -163,7 +163,7 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { if (ehdr->e_shoff >= rsz_offset + rsz_osize) { ehdr->e_shoff += delta; } - if (r_buf_write_at (bin->b, 0, (ut8*)ehdr, sizeof (Elf_(Ehdr))) == -1) { + if (rz_buf_write_at (bin->b, 0, (ut8*)ehdr, sizeof (Elf_(Ehdr))) == -1) { perror ("write (ehdr)"); } @@ -172,23 +172,23 @@ ut64 Elf_(r_bin_elf_resize_section)(RBinFile *bf, const char *name, ut64 size) { rest_size = bin->size - (rsz_offset + rsz_osize); buf = (ut8 *)malloc (1+bin->size); - r_buf_read_at (bin->b, 0, (ut8*)buf, bin->size); - r_buf_set_bytes (bin->b, (ut8*)buf, (int)(rsz_offset+rsz_size+rest_size)); + rz_buf_read_at (bin->b, 0, (ut8*)buf, bin->size); + rz_buf_set_bytes (bin->b, (ut8*)buf, (int)(rsz_offset+rsz_size+rest_size)); printf ("COPY FROM 0x%08"PFMT64x"\n", (ut64)(rsz_offset+rsz_osize)); - r_buf_read_at (bin->b, rsz_offset + rsz_osize, (ut8*)buf, rest_size); + rz_buf_read_at (bin->b, rsz_offset + rsz_osize, (ut8*)buf, rest_size); printf ("COPY TO 0x%08"PFMT64x"\n", (ut64)(rsz_offset+rsz_size)); - r_buf_write_at (bin->b, rsz_offset + rsz_size, (ut8*)buf, rest_size); + rz_buf_write_at (bin->b, rsz_offset + rsz_size, (ut8*)buf, rest_size); printf ("Shifted %d byte(s)\n", (int)delta); free (buf); - bin->size = r_buf_size (bin->b); + bin->size = rz_buf_size (bin->b); return delta; } /* XXX Endianness? */ -bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) { - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; +bool Elf_(rz_bin_elf_del_rpath)(RBinFile *bf) { + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; Elf_(Dyn) *dyn = NULL; ut64 stroff = 0LL; int ndyn, i, j; @@ -204,7 +204,7 @@ bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) { perror ("malloc (dyn)"); return false; } - if (r_buf_read_at (bin->b, bin->phdr[i].p_offset, (ut8*)dyn, bin->phdr[i].p_filesz) == -1) { + if (rz_buf_read_at (bin->b, bin->phdr[i].p_offset, (ut8*)dyn, bin->phdr[i].p_filesz) == -1) { eprintf ("Error: read (dyn)\n"); free (dyn); return false; @@ -218,7 +218,7 @@ bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) { } for (j = 0; j < ndyn; j++) { if (dyn[j].d_tag == DT_RPATH || dyn[j].d_tag == DT_RUNPATH) { - if (r_buf_write_at (bin->b, stroff + dyn[j].d_un.d_val, + if (rz_buf_write_at (bin->b, stroff + dyn[j].d_un.d_val, (ut8*)"", 1) == -1) { eprintf ("Error: write (rpath)\n"); free (dyn); @@ -233,8 +233,8 @@ bool Elf_(r_bin_elf_del_rpath)(RBinFile *bf) { return true; } -bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms) { - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; +bool Elf_(rz_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms) { + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; Elf_(Ehdr) *ehdr = &bin->ehdr; Elf_(Shdr) *shdr = bin->shdr, *shdrp; const char *strtab = bin->shstrtab; @@ -260,24 +260,24 @@ bool Elf_(r_bin_elf_section_perms)(RBinFile *bf, const char *name, int perms) { } patchoff = bin->ehdr.e_shoff; patchoff += ((const ut8*)shdrp - (const ut8*)bin->shdr); - patchoff += r_offsetof (Elf_(Shdr), sh_flags); + patchoff += rz_offsetof (Elf_(Shdr), sh_flags); printf ("wx %02x @ 0x%x\n", newperms, patchoff); - r_buf_write_at (bf->buf, patchoff, (ut8*)&newperms, 1); + rz_buf_write_at (bf->buf, patchoff, (ut8*)&newperms, 1); return true; } } return false; } -bool Elf_(r_bin_elf_entry_write)(RBinFile *bf, ut64 addr) { +bool Elf_(rz_bin_elf_entry_write)(RBinFile *bf, ut64 addr) { const int patchoff = 0x18; #if R_BIN_ELF64 printf ("wv8 0x%"PFMT64x" @ 0x%x\n", addr, patchoff); - r_buf_write_at (bf->buf, patchoff, (ut8*)&addr, sizeof (addr)); + rz_buf_write_at (bf->buf, patchoff, (ut8*)&addr, sizeof (addr)); #else ut32 addr32 = (ut32)addr; printf ("wv4 0x%x @ 0x%x\n", addr32, patchoff); - r_buf_write_at (bf->buf, patchoff, (ut8*)&addr32, sizeof (addr32)); + rz_buf_write_at (bf->buf, patchoff, (ut8*)&addr32, sizeof (addr32)); #endif return true; } diff --git a/libr/bin/format/elf/glibc_elf.h b/librz/bin/format/elf/glibc_elf.h similarity index 99% rename from libr/bin/format/elf/glibc_elf.h rename to librz/bin/format/elf/glibc_elf.h index 987c97da3e..bb06f5e9e5 100644 --- a/libr/bin/format/elf/glibc_elf.h +++ b/librz/bin/format/elf/glibc_elf.h @@ -633,8 +633,8 @@ typedef struct typedef struct { - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Addr rz_offset; /* Address */ + Elf32_Word rz_info; /* Relocation type and symbol index */ } Elf32_Rel; /* I have seen two different definitions of the Elf64_Rel and @@ -644,27 +644,27 @@ typedef struct typedef struct { - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ + Elf64_Addr rz_offset; /* Address */ + Elf64_Xword rz_info; /* Relocation type and symbol index */ } Elf64_Rel; /* Relocation table entry with addend (in section of type SHT_RELA). */ typedef struct { - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ + Elf32_Addr rz_offset; /* Address */ + Elf32_Word rz_info; /* Relocation type and symbol index */ + Elf32_Sword rz_addend; /* Addend */ } Elf32_Rela; typedef struct { - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ - Elf64_Sxword r_addend; /* Addend */ + Elf64_Addr rz_offset; /* Address */ + Elf64_Xword rz_info; /* Relocation type and symbol index */ + Elf64_Sxword rz_addend; /* Addend */ } Elf64_Rela; -/* How to extract and insert information held in the r_info field. */ +/* How to extract and insert information held in the rz_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) #define ELF32_R_TYPE(val) ((val) & 0xff) diff --git a/libr/bin/format/le/le.c b/librz/bin/format/le/le.c similarity index 69% rename from libr/bin/format/le/le.c rename to librz/bin/format/le/le.c index 0b16b554a1..5816114057 100644 --- a/libr/bin/format/le/le.c +++ b/librz/bin/format/le/le.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2019 - GustavoLCR */ #include "le.h" -#include +#include -const char *__get_module_type(r_bin_le_obj_t *bin) { +const char *__get_module_type(rz_bin_le_obj_t *bin) { switch (bin->header->mflags & M_TYPE_MASK) { case M_TYPE_EXE: return "Program module (EXE)"; case M_TYPE_DLL: return "Library module (DLL)"; @@ -13,7 +13,7 @@ const char *__get_module_type(r_bin_le_obj_t *bin) { } } -const char *__get_os_type(r_bin_le_obj_t *bin) { +const char *__get_os_type(rz_bin_le_obj_t *bin) { switch (bin->header->os) { case 1: return "OS/2"; case 2: return "Windows"; @@ -24,7 +24,7 @@ const char *__get_os_type(r_bin_le_obj_t *bin) { } } -const char *__get_cpu_type(r_bin_le_obj_t *bin) { +const char *__get_cpu_type(rz_bin_le_obj_t *bin) { switch (bin->header->cpu) { case 1: return "80286"; case 2: return "80386"; @@ -38,7 +38,7 @@ const char *__get_cpu_type(r_bin_le_obj_t *bin) { } } -const char *__get_arch(r_bin_le_obj_t *bin) { +const char *__get_arch(rz_bin_le_obj_t *bin) { switch (bin->header->cpu) { case 1: case 2: @@ -57,52 +57,52 @@ const char *__get_arch(r_bin_le_obj_t *bin) { } static char *__read_nonnull_str_at(RBuffer *buf, ut64 *offset) { - ut8 size = r_buf_read8_at (buf, *offset); + ut8 size = rz_buf_read8_at (buf, *offset); size &= 0x7F; // Max is 127 if (!size) { return NULL; } (*offset)++; char *str = calloc ((ut64)size + 1, sizeof (char)); - r_buf_read_at (buf, *offset, (ut8 *)str, size); + rz_buf_read_at (buf, *offset, (ut8 *)str, size); *offset += size; return str; } -static RBinSymbol *__get_symbol(r_bin_le_obj_t *bin, ut64 *offset) { +static RBinSymbol *__get_symbol(rz_bin_le_obj_t *bin, ut64 *offset) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { return NULL; } char *name = __read_nonnull_str_at (bin->buf, offset); if (!name) { - r_bin_symbol_free (sym); + rz_bin_symbol_free (sym); return NULL; } sym->name = name; - ut16 entry_idx = r_buf_read_le16_at (bin->buf, *offset); + ut16 entry_idx = rz_buf_read_le16_at (bin->buf, *offset); *offset += 2; sym->ordinal = entry_idx; return sym; } -RList *__get_entries(r_bin_le_obj_t *bin) { +RzList *__get_entries(rz_bin_le_obj_t *bin) { ut64 offset = (ut64)bin->header->enttab + bin->headerOff; - RList *l = r_list_newf (free); + RzList *l = rz_list_newf (free); if (!l) { return NULL; } while (true) { LE_entry_bundle_header header; LE_entry_bundle_entry e; - r_buf_read_at (bin->buf, offset, (ut8 *)&header, sizeof (header)); + rz_buf_read_at (bin->buf, offset, (ut8 *)&header, sizeof (header)); if (!header.count) { break; } if ((header.type & ~ENTRY_PARAMETER_TYPING_PRESENT) == UNUSED_ENTRY) { offset += sizeof (header.type) + sizeof (header.count); while (header.count) { - r_list_append (l, strdup ("")); // (ut64 *)-1); + rz_list_append (l, strdup ("")); // (ut64 *)-1); header.count--; } continue; @@ -112,7 +112,7 @@ RList *__get_entries(r_bin_le_obj_t *bin) { int i; for (i = 0; i < header.count; i++) { ut64 entry = -1; - r_buf_read_at (bin->buf, offset, (ut8 *)&e, sizeof (e)); + rz_buf_read_at (bin->buf, offset, (ut8 *)&e, sizeof (e)); switch (header.type & ~ENTRY_PARAMETER_TYPING_PRESENT) { case ENTRY16: if ((header.objnum - 1) < bin->header->objcnt) { @@ -146,36 +146,36 @@ RList *__get_entries(r_bin_le_obj_t *bin) { break; } if (entry != UT64_MAX) { - r_list_append (l, r_str_newf ("0x%"PFMT64x, entry)); + rz_list_append (l, rz_str_newf ("0x%"PFMT64x, entry)); } } } return l; } -static void __get_symbols_at(r_bin_le_obj_t *bin, RList *syml, RList *entl, ut64 offset, ut64 end) { +static void __get_symbols_at(rz_bin_le_obj_t *bin, RzList *syml, RzList *entl, ut64 offset, ut64 end) { while (offset < end) { RBinSymbol *sym = __get_symbol (bin, &offset); if (!sym) { break; } if (sym->ordinal) { - const char *n = r_list_get_n (entl, sym->ordinal - 1); + const char *n = rz_list_get_n (entl, sym->ordinal - 1); if (n) { - sym->vaddr = r_num_get (NULL, n); + sym->vaddr = rz_num_get (NULL, n); sym->bind = R_BIN_BIND_GLOBAL_STR; sym->type = R_BIN_TYPE_FUNC_STR; - r_list_append (syml, sym); + rz_list_append (syml, sym); } } else { - r_bin_symbol_free (sym); + rz_bin_symbol_free (sym); } } } -RList *r_bin_le_get_symbols(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)r_bin_symbol_free); - RList *entries = __get_entries (bin); +RzList *rz_bin_le_get_symbols(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)rz_bin_symbol_free); + RzList *entries = __get_entries (bin); LE_image_header *h = bin->header; ut64 offset = (ut64)h->restab + bin->headerOff; ut32 end = h->enttab + bin->headerOff; @@ -183,12 +183,12 @@ RList *r_bin_le_get_symbols(r_bin_le_obj_t *bin) { offset = h->nrestab; end = h->nrestab + h->cbnrestab; __get_symbols_at (bin, l, entries, offset, end); - r_list_free (entries); + rz_list_free (entries); return l; } -RList *r_bin_le_get_imports(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)r_bin_import_free); +RzList *rz_bin_le_get_imports(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)rz_bin_import_free); if (!l) { return NULL; } @@ -202,18 +202,18 @@ RList *r_bin_le_get_imports(r_bin_le_obj_t *bin) { } imp->name = __read_nonnull_str_at (bin->buf, &offset); if (!imp->name) { - r_bin_import_free (imp); + rz_bin_import_free (imp); break; } imp->type = R_BIN_TYPE_FUNC_STR; - r_list_append (l, imp); + rz_list_append (l, imp); } return l; } -RList *r_bin_le_get_entrypoints(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)free); +RzList *rz_bin_le_get_entrypoints(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)free); if (!l) { return NULL; } @@ -223,13 +223,13 @@ RList *r_bin_le_get_entrypoints(r_bin_le_obj_t *bin) { entry->vaddr = (ut64)bin->objtbl[bin->header->startobj - 1].reloc_base_addr + bin->header->eip; } } - r_list_append (l, entry); + rz_list_append (l, entry); return l; } -RList *r_bin_le_get_libs(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)free); +RzList *rz_bin_le_get_libs(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)free); if (!l) { return NULL; } @@ -241,7 +241,7 @@ RList *r_bin_le_get_libs(r_bin_le_obj_t *bin) { if (!name) { break; } - r_list_append (l, name); + rz_list_append (l, name); } return l; } @@ -251,15 +251,15 @@ RList *r_bin_le_get_libs(r_bin_le_obj_t *bin) { * page->size is the total size of iter records that describe the page * TODO: Don't do this */ -static void __create_iter_sections(RList *l, r_bin_le_obj_t *bin, RBinSection *sec, LE_object_page_entry *page, ut64 vaddr, int cur_page) { - r_return_if_fail (l && bin && sec && page); +static void __create_iter_sections(RzList *l, rz_bin_le_obj_t *bin, RBinSection *sec, LE_object_page_entry *page, ut64 vaddr, int cur_page) { + rz_return_if_fail (l && bin && sec && page); LE_image_header *h = bin->header; ut32 offset = (h->itermap + (page->offset << (bin->is_le ? 0 : h->pageshift))); // Gets the first iter record - ut16 iter_n = r_buf_read_ble16_at (bin->buf, offset, h->worder); + ut16 iter_n = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); - ut16 data_size = r_buf_read_ble16_at (bin->buf, offset, h->worder); + ut16 data_size = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); ut64 tot_size = 0; @@ -272,7 +272,7 @@ static void __create_iter_sections(RList *l, r_bin_le_obj_t *bin, RBinSection *s if (!s) { break; } - s->name = r_str_newf ("%s.page.%d.iter.%d", sec->name, cur_page, iter_cnt); + s->name = rz_str_newf ("%s.page.%d.iter.%d", sec->name, cur_page, iter_cnt); s->bits = sec->bits; s->perm = sec->perm; s->size = data_size; @@ -282,15 +282,15 @@ static void __create_iter_sections(RList *l, r_bin_le_obj_t *bin, RBinSection *s s->add = true; vaddr += data_size; tot_size += data_size; - r_list_append (l, s); + rz_list_append (l, s); iter_cnt++; } bytes_left -= sizeof (ut16) * 2 + data_size; // Get the next iter record offset += data_size; - iter_n = r_buf_read_ble16_at (bin->buf, offset, h->worder); + iter_n = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); - data_size = r_buf_read_ble16_at (bin->buf, offset, h->worder); + data_size = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } if (tot_size < h->pagesize) { @@ -298,19 +298,19 @@ static void __create_iter_sections(RList *l, r_bin_le_obj_t *bin, RBinSection *s if (!s) { return; } - s->name = r_str_newf ("%s.page.%d.iter.zerofill", sec->name, cur_page); + s->name = rz_str_newf ("%s.page.%d.iter.zerofill", sec->name, cur_page); s->bits = sec->bits; s->perm = sec->perm; s->vsize = h->pagesize - tot_size; s->vaddr = vaddr; s->add = true; - r_list_append (l, s); + rz_list_append (l, s); } } // TODO: Compressed page -RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)r_bin_section_free); +RzList *rz_bin_le_get_sections(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)rz_bin_section_free); if (!l) { return NULL; } @@ -327,7 +327,7 @@ RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { free (sec); return l; } - sec->name = r_str_newf ("obj.%d", i + 1); + sec->name = rz_str_newf ("obj.%d", i + 1); sec->vsize = entry->virtual_size; sec->vaddr = entry->reloc_base_addr; sec->add = true; @@ -347,7 +347,7 @@ RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { } sec->is_data = entry->flags & O_RESOURCE || !(sec->perm & R_PERM_X); if (!entry->page_tbl_entries) { - r_list_append (l, sec); + rz_list_append (l, sec); } int j; ut32 page_size_sum = 0; @@ -358,19 +358,19 @@ RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { LE_object_page_entry page; RBinSection *s = R_NEW0 (RBinSection); if (!s) { - r_bin_section_free (sec); + rz_bin_section_free (sec); return l; } - s->name = r_str_newf ("%s.page.%d", sec->name, j); + s->name = rz_str_newf ("%s.page.%d", sec->name, j); s->is_data = sec->is_data; int cur_idx = entry->page_tbl_idx + j - 1; ut64 page_entry_off = objpageentrysz * cur_idx + objmaptbloff; - r_buf_read_at (bin->buf, page_entry_off, (ut8 *)&page, sizeof (page)); + rz_buf_read_at (bin->buf, page_entry_off, (ut8 *)&page, sizeof (page)); if (cur_idx < next_idx) { // If not true rest of pages will be zeroes if (bin->is_le) { // Why is it big endian??? - ut64 offset = r_buf_read_be32_at (bin->buf, page_entry_off) >> 8; + ut64 offset = rz_buf_read_be32_at (bin->buf, page_entry_off) >> 8; s->paddr = (offset - 1) * h->pagesize + pages_start_off; if (entry->page_tbl_idx + j == h->mpages) { page.size = h->pageshift; @@ -380,7 +380,7 @@ RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { } else if (page.flags == P_ITERATED) { ut64 vaddr = sec->vaddr + page_size_sum; __create_iter_sections (l, bin, sec, &page, vaddr, j); - r_bin_section_free (s); + rz_bin_section_free (s); page_size_sum += h->pagesize; continue; } else if (page.flags == P_COMPRESSED) { @@ -396,17 +396,17 @@ RList *r_bin_le_get_sections(r_bin_le_obj_t *bin) { s->size = page.size; s->add = true; s->bits = sec->bits; - r_list_append (l, s); + rz_list_append (l, s); page_size_sum += s->vsize; } if (entry->page_tbl_entries) { - r_bin_section_free (sec); + rz_bin_section_free (sec); } } return l; } -char *__get_modname_by_ord(r_bin_le_obj_t *bin, ut32 ordinal) { +char *__get_modname_by_ord(rz_bin_le_obj_t *bin, ut32 ordinal) { char *modname = NULL; ut64 off = (ut64)bin->header->impmod + bin->headerOff; while (ordinal > 0) { @@ -417,19 +417,19 @@ char *__get_modname_by_ord(r_bin_le_obj_t *bin, ut32 ordinal) { return modname; } -RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { - RList *l = r_list_newf ((RListFree)free); +RzList *rz_bin_le_get_relocs(rz_bin_le_obj_t *bin) { + RzList *l = rz_list_newf ((RzListFree)free); if (!l) { return NULL; } - RList *entries = __get_entries (bin); - RList *sections = r_bin_le_get_sections (bin); + RzList *entries = __get_entries (bin); + RzList *sections = rz_bin_le_get_sections (bin); LE_image_header *h = bin->header; ut64 cur_page = 0; const ut64 fix_rec_tbl_off = (ut64)h->frectab + bin->headerOff; - ut64 offset = fix_rec_tbl_off + r_buf_read_ble32_at (bin->buf, (ut64)h->fpagetab + bin->headerOff + cur_page * sizeof (ut32), h->worder); - ut64 end = fix_rec_tbl_off + r_buf_read_ble32_at (bin->buf, (ut64)h->fpagetab + bin->headerOff + (cur_page + 1) * sizeof (ut32), h->worder); - const RBinSection *cur_section = (RBinSection *)r_list_get_n (sections, cur_page); + ut64 offset = fix_rec_tbl_off + rz_buf_read_ble32_at (bin->buf, (ut64)h->fpagetab + bin->headerOff + cur_page * sizeof (ut32), h->worder); + ut64 end = fix_rec_tbl_off + rz_buf_read_ble32_at (bin->buf, (ut64)h->fpagetab + bin->headerOff + (cur_page + 1) * sizeof (ut32), h->worder); + const RBinSection *cur_section = (RBinSection *)rz_list_get_n (sections, cur_page); ut64 cur_page_offset = cur_section ? cur_section->vaddr : 0; while (cur_page < h->mpages) { RBinReloc *rel = R_NEW0 (RBinReloc); @@ -438,7 +438,7 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { break; } LE_fixup_record_header header; - int ret = r_buf_read_at (bin->buf, offset, (ut8 *)&header, sizeof (header)); + int ret = rz_buf_read_at (bin->buf, offset, (ut8 *)&header, sizeof (header)); if (ret != sizeof (header)) { eprintf ("Warning: oobread in LE header parsing relocs\n"); break; @@ -464,18 +464,18 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { ut64 repeat = 0; ut64 source = 0; if (header.source & F_SOURCE_LIST) { - repeat = r_buf_read8_at (bin->buf, offset); + repeat = rz_buf_read8_at (bin->buf, offset); offset += sizeof (ut8); } else { - source = r_buf_read_ble16_at (bin->buf, offset, h->worder); + source = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } ut32 ordinal; if (header.target & F_TARGET_ORD16) { - ordinal = r_buf_read_ble16_at (bin->buf, offset, h->worder); + ordinal = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } else { - ordinal = r_buf_read8_at (bin->buf, offset); + ordinal = rz_buf_read8_at (bin->buf, offset); offset += sizeof (ut8); } switch (header.target & F_TARGET_TYPE_MASK) { @@ -484,10 +484,10 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { rel->addend = bin->objtbl[ordinal - 1].reloc_base_addr; if ((header.source & F_SOURCE_TYPE_MASK) != SELECTOR16) { if (header.target & F_TARGET_OFF32) { - rel->addend += r_buf_read_ble32_at (bin->buf, offset, h->worder); + rel->addend += rz_buf_read_ble32_at (bin->buf, offset, h->worder); offset += sizeof (ut32); } else { - rel->addend += r_buf_read_ble16_at (bin->buf, offset, h->worder); + rel->addend += rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } } @@ -501,21 +501,21 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { } char *mod_name = __get_modname_by_ord (bin, ordinal); if (!mod_name) { - r_bin_import_free (imp); + rz_bin_import_free (imp); break; } if (header.target & F_TARGET_ORD8) { - ordinal = r_buf_read8_at (bin->buf, offset); + ordinal = rz_buf_read8_at (bin->buf, offset); offset += sizeof (ut8); } else if (header.target & F_TARGET_OFF32) { - ordinal = r_buf_read_ble32_at (bin->buf, offset, h->worder); + ordinal = rz_buf_read_ble32_at (bin->buf, offset, h->worder); offset += sizeof (ut32); } else { - ordinal = r_buf_read_ble16_at (bin->buf, offset, h->worder); + ordinal = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } - imp->name = r_str_newf ("%s.%u", mod_name, ordinal); + imp->name = rz_str_newf ("%s.%u", mod_name, ordinal); imp->ordinal = ordinal; rel->import = imp; free (mod_name); @@ -529,30 +529,30 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { } ut32 nameoff; if (header.target & F_TARGET_OFF32) { - nameoff = r_buf_read_ble32_at (bin->buf, offset, h->worder); + nameoff = rz_buf_read_ble32_at (bin->buf, offset, h->worder); offset += sizeof (ut32); } else { - nameoff = r_buf_read_ble16_at (bin->buf, offset, h->worder); + nameoff = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } ut64 off = (ut64)h->impproc + nameoff + bin->headerOff; char *proc_name = __read_nonnull_str_at (bin->buf, &off); char *mod_name = __get_modname_by_ord (bin, ordinal); - imp->name = r_str_newf ("%s.%s", mod_name ? mod_name : "", proc_name ? proc_name : ""); + imp->name = rz_str_newf ("%s.%s", mod_name ? mod_name : "", proc_name ? proc_name : ""); rel->import = imp; break; } case INTERNALENTRY: - rel->addend = (ut64)r_list_get_n (entries, ordinal - 1); + rel->addend = (ut64)rz_list_get_n (entries, ordinal - 1); break; } if (header.target & F_TARGET_ADDITIVE) { ut32 additive = 0; if (header.target & F_TARGET_ADD32) { - additive = r_buf_read_ble32_at (bin->buf, offset, h->worder); + additive = rz_buf_read_ble32_at (bin->buf, offset, h->worder); offset += sizeof (ut32); } else { - additive = r_buf_read_ble16_at (bin->buf, offset, h->worder); + additive = rz_buf_read_ble16_at (bin->buf, offset, h->worder); offset += sizeof (ut16); } rel->addend += additive; @@ -560,30 +560,30 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { if (!repeat) { rel->vaddr = cur_page_offset + source; rel->paddr = cur_section ? cur_section->paddr + source : 0; - r_list_append (l, rel); + rz_list_append (l, rel); rel_appended = true; } if (header.target & F_TARGET_CHAIN) { - ut32 fixupinfo = r_buf_read_ble32_at (bin->buf, cur_page_offset + source, h->worder); + ut32 fixupinfo = rz_buf_read_ble32_at (bin->buf, cur_page_offset + source, h->worder); ut64 base_target_address = rel->addend - (fixupinfo & 0xFFFFF); do { - fixupinfo = r_buf_read_ble32_at (bin->buf, cur_page_offset + source, h->worder); + fixupinfo = rz_buf_read_ble32_at (bin->buf, cur_page_offset + source, h->worder); RBinReloc *new = R_NEW0 (RBinReloc); *new = *rel; new->addend = base_target_address + (fixupinfo & 0xFFFFF); - r_list_append (l, new); + rz_list_append (l, new); source = (fixupinfo >> 20) & 0xFFF; } while (source != 0xFFF); } while (repeat) { - ut16 off = r_buf_read_ble16_at (bin->buf, offset, h->worder); + ut16 off = rz_buf_read_ble16_at (bin->buf, offset, h->worder); rel->vaddr = cur_page_offset + off; rel->paddr = cur_section ? cur_section->paddr + off : 0; RBinReloc *new = R_NEW0 (RBinReloc); *new = *rel; - r_list_append (l, new); + rz_list_append (l, new); offset += sizeof (ut16); repeat--; } @@ -593,12 +593,12 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { break; } ut64 at = h->fpagetab + bin->headerOff; - ut32 w0 = r_buf_read_ble32_at (bin->buf, at + cur_page * sizeof (ut32), h->worder); - ut32 w1 = r_buf_read_ble32_at (bin->buf, at + (cur_page + 1) * sizeof (ut32), h->worder); + ut32 w0 = rz_buf_read_ble32_at (bin->buf, at + cur_page * sizeof (ut32), h->worder); + ut32 w1 = rz_buf_read_ble32_at (bin->buf, at + (cur_page + 1) * sizeof (ut32), h->worder); offset = fix_rec_tbl_off + w0; end = fix_rec_tbl_off + w1; if (offset < end) { - cur_section = (RBinSection *)r_list_get_n (sections, cur_page); + cur_section = (RBinSection *)rz_list_get_n (sections, cur_page); cur_page_offset = cur_section ? cur_section->vaddr : 0; } } @@ -606,22 +606,22 @@ RList *r_bin_le_get_relocs(r_bin_le_obj_t *bin) { free (rel); } } - r_list_free (entries); - r_list_free (sections); + rz_list_free (entries); + rz_list_free (sections); return l; } -static bool __init_header(r_bin_le_obj_t *bin, RBuffer *buf) { +static bool __init_header(rz_bin_le_obj_t *bin, RBuffer *buf) { ut8 magic[2]; - r_buf_read_at (buf, 0, magic, sizeof (magic)); + rz_buf_read_at (buf, 0, magic, sizeof (magic)); if (!memcmp (&magic, "MZ", 2)) { - bin->headerOff = r_buf_read_le16_at (buf, 0x3c); + bin->headerOff = rz_buf_read_le16_at (buf, 0x3c); } else { bin->headerOff = 0; } bin->header = R_NEW0 (LE_image_header); if (bin->header) { - r_buf_read_at (buf, bin->headerOff, (ut8 *)bin->header, sizeof (LE_image_header)); + rz_buf_read_at (buf, bin->headerOff, (ut8 *)bin->header, sizeof (LE_image_header)); } else { R_LOG_ERROR ("Failed to allocate memory"); return false; @@ -629,16 +629,16 @@ static bool __init_header(r_bin_le_obj_t *bin, RBuffer *buf) { return true; } -void r_bin_le_free(r_bin_le_obj_t *bin) { - r_return_if_fail (bin); +void rz_bin_le_free(rz_bin_le_obj_t *bin) { + rz_return_if_fail (bin); free (bin->header); free (bin->objtbl); free (bin->filename); free (bin); } -r_bin_le_obj_t *r_bin_le_new_buf(RBuffer *buf) { - r_bin_le_obj_t *bin = R_NEW0 (r_bin_le_obj_t); +rz_bin_le_obj_t *rz_bin_le_new_buf(RBuffer *buf) { + rz_bin_le_obj_t *bin = R_NEW0 (rz_bin_le_obj_t); if (!bin) { return NULL; } @@ -654,12 +654,12 @@ r_bin_le_obj_t *r_bin_le_new_buf(RBuffer *buf) { bin->arch = __get_arch (bin); bin->objtbl = calloc (h->objcnt, sizeof (LE_object_entry)); if (!bin->objtbl) { - r_bin_le_free (bin); + rz_bin_le_free (bin); return NULL; } ut64 offset = (ut64)bin->headerOff + h->restab; bin->filename = __read_nonnull_str_at (buf, &offset); - r_buf_read_at (buf, (ut64)h->objtab + bin->headerOff, (ut8 *)bin->objtbl, h->objcnt * sizeof (LE_object_entry)); + rz_buf_read_at (buf, (ut64)h->objtab + bin->headerOff, (ut8 *)bin->objtbl, h->objcnt * sizeof (LE_object_entry)); bin->buf = buf; return bin; diff --git a/librz/bin/format/le/le.h b/librz/bin/format/le/le.h new file mode 100644 index 0000000000..941fc73c0c --- /dev/null +++ b/librz/bin/format/le/le.h @@ -0,0 +1,27 @@ +#ifndef LE_H +#define LE_H +#include +#include "le_specs.h" + +typedef struct rz_bin_le_obj_s { + LE_image_header *header; + bool is_le; /* Used for differences between LE and LX */ + char *filename; + const char *type; + const char *cpu; + const char *os; + const char *arch; + ut32 headerOff; /* File offset to start of LE/LX header */ + LE_object_entry *objtbl; + void *buf; /* Pointer to RBuffer of file */ +} rz_bin_le_obj_t; + +rz_bin_le_obj_t *rz_bin_le_new_buf(RBuffer *buf); +void rz_bin_le_free(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_entrypoints(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_sections(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_symbols(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_imports(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_libs(rz_bin_le_obj_t *bin); +RzList *rz_bin_le_get_relocs(rz_bin_le_obj_t *bin); +#endif diff --git a/libr/bin/format/le/le_specs.h b/librz/bin/format/le/le_specs.h similarity index 99% rename from libr/bin/format/le/le_specs.h rename to librz/bin/format/le/le_specs.h index 74444b6856..cf98131293 100644 --- a/libr/bin/format/le/le_specs.h +++ b/librz/bin/format/le/le_specs.h @@ -1,6 +1,6 @@ #ifndef LE_SPECS_H #define LE_SPECS_H -#include +#include typedef enum { UNUSED_ENTRY = 0, diff --git a/libr/bin/format/mach0/coresymbolication.c b/librz/bin/format/mach0/coresymbolication.c similarity index 59% rename from libr/bin/format/mach0/coresymbolication.c rename to librz/bin/format/mach0/coresymbolication.c index 1db8f9b946..1a4fc0e1d7 100644 --- a/libr/bin/format/mach0/coresymbolication.c +++ b/librz/bin/format/mach0/coresymbolication.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2020 - mrmacete */ -#include -#include -#include +#include +#include +#include #include "coresymbolication.h" #define R_CS_EL_OFF_SEGS 0x58 @@ -13,81 +13,81 @@ #define R_CS_EL_SIZE_LSYM 0x24 #define R_CS_EL_SIZE_LINFO 0x14 -static RCoreSymCacheElementHdr *r_coresym_cache_element_header_new(RBuffer *buf, size_t off, int bits) { - RCoreSymCacheElementHdr *hdr = R_NEW0 (RCoreSymCacheElementHdr); - if (hdr && r_buf_fread_at (buf, off, (ut8 *)hdr, "13i16c5i", 1) == sizeof (RCoreSymCacheElementHdr)) { +static RzCoreSymCacheElementHdr *rz_coresym_cache_element_header_new(RBuffer *buf, size_t off, int bits) { + RzCoreSymCacheElementHdr *hdr = R_NEW0 (RzCoreSymCacheElementHdr); + if (hdr && rz_buf_fread_at (buf, off, (ut8 *)hdr, "13i16c5i", 1) == sizeof (RzCoreSymCacheElementHdr)) { return hdr; } free (hdr); return NULL; } -static void r_coresym_cache_element_segment_fini(RCoreSymCacheElementSegment *seg) { +static void rz_coresym_cache_element_segment_fini(RzCoreSymCacheElementSegment *seg) { if (seg) { free (seg->name); } } -static void r_coresym_cache_element_section_fini(RCoreSymCacheElementSection *sec) { +static void rz_coresym_cache_element_section_fini(RzCoreSymCacheElementSection *sec) { if (sec) { free (sec->name); } } -static void r_coresym_cache_element_flc_fini(RCoreSymCacheElementFLC *flc) { +static void rz_coresym_cache_element_flc_fini(RzCoreSymCacheElementFLC *flc) { if (flc) { free (flc->file); } } -static void r_coresym_cache_element_symbol_fini(RCoreSymCacheElementSymbol *sym) { +static void rz_coresym_cache_element_symbol_fini(RzCoreSymCacheElementSymbol *sym) { if (sym) { free (sym->name); free (sym->mangled_name); } } -static void r_coresym_cache_element_lined_symbol_fini(RCoreSymCacheElementLinedSymbol *sym) { +static void rz_coresym_cache_element_lined_symbol_fini(RzCoreSymCacheElementLinedSymbol *sym) { if (sym) { - r_coresym_cache_element_symbol_fini (&sym->sym); - r_coresym_cache_element_flc_fini (&sym->flc); + rz_coresym_cache_element_symbol_fini (&sym->sym); + rz_coresym_cache_element_flc_fini (&sym->flc); } } -static void r_coresym_cache_element_line_info_fini(RCoreSymCacheElementLineInfo *line) { +static void rz_coresym_cache_element_line_info_fini(RzCoreSymCacheElementLineInfo *line) { if (line) { - r_coresym_cache_element_flc_fini (&line->flc); + rz_coresym_cache_element_flc_fini (&line->flc); } } -void r_coresym_cache_element_free(RCoreSymCacheElement *element) { +void rz_coresym_cache_element_free(RzCoreSymCacheElement *element) { if (!element) { return; } size_t i; if (element->segments) { for (i = 0; i < element->hdr->n_segments; i++) { - r_coresym_cache_element_segment_fini (&element->segments[i]); + rz_coresym_cache_element_segment_fini (&element->segments[i]); } } if (element->sections) { for (i = 0; i < element->hdr->n_sections; i++) { - r_coresym_cache_element_section_fini (&element->sections[i]); + rz_coresym_cache_element_section_fini (&element->sections[i]); } } if (element->symbols) { for (i = 0; i < element->hdr->n_symbols; i++) { - r_coresym_cache_element_symbol_fini (&element->symbols[i]); + rz_coresym_cache_element_symbol_fini (&element->symbols[i]); } } if (element->lined_symbols) { for (i = 0; i < element->hdr->n_lined_symbols; i++) { - r_coresym_cache_element_lined_symbol_fini (&element->lined_symbols[i]); + rz_coresym_cache_element_lined_symbol_fini (&element->lined_symbols[i]); } } if (element->line_info) { for (i = 0; i < element->hdr->n_line_info; i++) { - r_coresym_cache_element_line_info_fini (&element->line_info[i]); + rz_coresym_cache_element_line_info_fini (&element->line_info[i]); } } free (element->segments); @@ -101,10 +101,10 @@ void r_coresym_cache_element_free(RCoreSymCacheElement *element) { free (element); } -ut64 r_coresym_cache_element_pa2va(RCoreSymCacheElement *element, ut64 pa) { +ut64 rz_coresym_cache_element_pa2va(RzCoreSymCacheElement *element, ut64 pa) { size_t i; for (i = 0; i < element->hdr->n_segments; i++) { - RCoreSymCacheElementSegment *seg = &element->segments[i]; + RzCoreSymCacheElementSegment *seg = &element->segments[i]; if (seg->size == 0) { continue; } @@ -115,7 +115,7 @@ ut64 r_coresym_cache_element_pa2va(RCoreSymCacheElement *element, ut64 pa) { return pa; } -static void meta_add_fileline(RBinFile *bf, ut64 vaddr, ut32 size, RCoreSymCacheElementFLC *flc) { +static void meta_add_fileline(RBinFile *bf, ut64 vaddr, ut32 size, RzCoreSymCacheElementFLC *flc) { Sdb *s = bf->sdb_addrinfo; if (!s) { return; @@ -123,7 +123,7 @@ static void meta_add_fileline(RBinFile *bf, ut64 vaddr, ut32 size, RCoreSymCache char aoffset[64]; ut64 cursor = vaddr; ut64 end = cursor + R_MAX (size, 1); - char *fileline = r_str_newf ("%s:%d", flc->file, flc->line); + char *fileline = rz_str_newf ("%s:%d", flc->file, flc->line); while (cursor < end) { char *aoffsetptr = sdb_itoa (cursor, aoffset, 16); if (!aoffsetptr) { @@ -138,9 +138,9 @@ static void meta_add_fileline(RBinFile *bf, ut64 vaddr, ut32 size, RCoreSymCache static char *str_dup_safe(const ut8 *b, const ut8 *str, const ut8 *end) { if (str >= b && str < end) { - int len = r_str_nlen ((const char *)str, end - str); + int len = rz_str_nlen ((const char *)str, end - str); if (len) { - return r_str_ndup ((const char *)str, len); + return rz_str_ndup ((const char *)str, len); } } return NULL; @@ -150,17 +150,17 @@ static char *str_dup_safe_fixed(const ut8 *b, const ut8 *str, ut64 len, const ut if (str >= b && str + len < end) { char *result = calloc (1, len + 1); if (result) { - r_str_ncpy (result, (const char *)str, len); + rz_str_ncpy (result, (const char *)str, len); return result; } } return NULL; } -RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut64 off, int bits) { - RCoreSymCacheElement *result = NULL; +RzCoreSymCacheElement *rz_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut64 off, int bits) { + RzCoreSymCacheElement *result = NULL; ut8 *b = NULL; - RCoreSymCacheElementHdr *hdr = r_coresym_cache_element_header_new (buf, off, bits); + RzCoreSymCacheElementHdr *hdr = rz_coresym_cache_element_header_new (buf, off, bits); if (!hdr) { return NULL; } @@ -168,11 +168,11 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut eprintf ("Unsupported CoreSymbolication cache version (%d)\n", hdr->version); goto beach; } - if (hdr->size == 0 || hdr->size > r_buf_size (buf) - off) { + if (hdr->size == 0 || hdr->size > rz_buf_size (buf) - off) { eprintf ("Corrupted CoreSymbolication header: size out of bounds (0x%x)\n", hdr->size); goto beach; } - result = R_NEW0 (RCoreSymCacheElement); + result = R_NEW0 (RzCoreSymCacheElement); if (!result) { goto beach; } @@ -181,7 +181,7 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut if (!b) { goto beach; } - if (r_buf_read_at (buf, off, b, hdr->size) != hdr->size) { + if (rz_buf_read_at (buf, off, b, hdr->size) != hdr->size) { goto beach; } ut8 *end = b + hdr->size; @@ -195,20 +195,20 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut ut64 page_zero_size = 0; size_t page_zero_idx = 0; if (hdr->n_segments > 0) { - result->segments = R_NEWS0 (RCoreSymCacheElementSegment, hdr->n_segments); + result->segments = R_NEWS0 (RzCoreSymCacheElementSegment, hdr->n_segments); if (!result->segments) { goto beach; } size_t i; ut8 *cursor = b + R_CS_EL_OFF_SEGS; for (i = 0; i < hdr->n_segments && cursor < end; i++) { - RCoreSymCacheElementSegment *seg = &result->segments[i]; - seg->paddr = seg->vaddr = r_read_le64 (cursor); + RzCoreSymCacheElementSegment *seg = &result->segments[i]; + seg->paddr = seg->vaddr = rz_read_le64 (cursor); cursor += 8; if (cursor >= end) { break; } - seg->size = seg->vsize = r_read_le64 (cursor); + seg->size = seg->vsize = rz_read_le64 (cursor); cursor += 8; if (cursor >= end) { break; @@ -230,7 +230,7 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut if (i == page_zero_idx) { continue; } - RCoreSymCacheElementSegment *seg = &result->segments[i]; + RzCoreSymCacheElementSegment *seg = &result->segments[i]; if (seg->vaddr < page_zero_size) { seg->vaddr += page_zero_size; } @@ -238,7 +238,7 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut } const ut64 start_of_sections = (ut64)hdr->n_segments * R_CS_EL_SIZE_SEG + R_CS_EL_OFF_SEGS; if (hdr->n_sections > 0) { - result->sections = R_NEWS0 (RCoreSymCacheElementSection, hdr->n_sections); + result->sections = R_NEWS0 (RzCoreSymCacheElementSection, hdr->n_sections); if (!result->sections) { goto beach; } @@ -246,8 +246,8 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut ut8 *cursor = b + start_of_sections; for (i = 0; i < hdr->n_sections && cursor < end; i++) { ut8 *sect_start = cursor; - RCoreSymCacheElementSection *sect = &result->sections[i]; - sect->vaddr = sect->paddr = r_read_ble (cursor, false, bits); + RzCoreSymCacheElementSection *sect = &result->sections[i]; + sect->vaddr = sect->paddr = rz_read_ble (cursor, false, bits); if (sect->vaddr < page_zero_size) { sect->vaddr += page_zero_size; } @@ -255,12 +255,12 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut if (cursor >= end) { break; } - sect->size = r_read_ble (cursor, false, bits); + sect->size = rz_read_ble (cursor, false, bits); cursor += word_size; if (cursor >= end) { break; } - ut64 sect_name_off = r_read_ble (cursor, false, bits); + ut64 sect_name_off = rz_read_ble (cursor, false, bits); cursor += word_size; if (bits == 32) { cursor += word_size; @@ -271,20 +271,20 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut const ut64 sect_size = (bits == 32) ? R_CS_EL_SIZE_SECT_32 : R_CS_EL_SIZE_SECT_64; const ut64 start_of_symbols = start_of_sections + (ut64)hdr->n_sections * sect_size; if (hdr->n_symbols) { - result->symbols = R_NEWS0 (RCoreSymCacheElementSymbol, hdr->n_symbols); + result->symbols = R_NEWS0 (RzCoreSymCacheElementSymbol, hdr->n_symbols); if (!result->symbols) { goto beach; } size_t i; ut8 *cursor = b + start_of_symbols; for (i = 0; i < hdr->n_symbols && cursor + R_CS_EL_SIZE_SYM <= end; i++) { - RCoreSymCacheElementSymbol *sym = &result->symbols[i]; - sym->paddr = r_read_le32 (cursor); - sym->size = r_read_le32 (cursor + 0x4); - sym->unk1 = r_read_le32 (cursor + 0x8); - size_t name_off = r_read_le32 (cursor + 0xc); - size_t mangled_name_off = r_read_le32 (cursor + 0x10); - sym->unk2 = (st32)r_read_le32 (cursor + 0x14); + RzCoreSymCacheElementSymbol *sym = &result->symbols[i]; + sym->paddr = rz_read_le32 (cursor); + sym->size = rz_read_le32 (cursor + 0x4); + sym->unk1 = rz_read_le32 (cursor + 0x8); + size_t name_off = rz_read_le32 (cursor + 0xc); + size_t mangled_name_off = rz_read_le32 (cursor + 0x10); + sym->unk2 = (st32)rz_read_le32 (cursor + 0x14); sym->name = str_dup_safe (b, cursor + name_off, end); if (!sym->name) { cursor += R_CS_EL_SIZE_SYM; @@ -300,23 +300,23 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut } const ut64 start_of_lined_symbols = start_of_symbols + (ut64)hdr->n_symbols * R_CS_EL_SIZE_SYM; if (hdr->n_lined_symbols) { - result->lined_symbols = R_NEWS0 (RCoreSymCacheElementLinedSymbol, hdr->n_lined_symbols); + result->lined_symbols = R_NEWS0 (RzCoreSymCacheElementLinedSymbol, hdr->n_lined_symbols); if (!result->lined_symbols) { goto beach; } size_t i; ut8 *cursor = b + start_of_lined_symbols; for (i = 0; i < hdr->n_lined_symbols && cursor + R_CS_EL_SIZE_LSYM <= end; i++) { - RCoreSymCacheElementLinedSymbol *lsym = &result->lined_symbols[i]; - lsym->sym.paddr = r_read_le32 (cursor); - lsym->sym.size = r_read_le32 (cursor + 0x4); - lsym->sym.unk1 = r_read_le32 (cursor + 0x8); - size_t name_off = r_read_le32 (cursor + 0xc); - size_t mangled_name_off = r_read_le32 (cursor + 0x10); - lsym->sym.unk2 = (st32)r_read_le32 (cursor + 0x14); - size_t file_name_off = r_read_le32 (cursor + 0x18); - lsym->flc.line = r_read_le32 (cursor + 0x1c); - lsym->flc.col = r_read_le32 (cursor + 0x20); + RzCoreSymCacheElementLinedSymbol *lsym = &result->lined_symbols[i]; + lsym->sym.paddr = rz_read_le32 (cursor); + lsym->sym.size = rz_read_le32 (cursor + 0x4); + lsym->sym.unk1 = rz_read_le32 (cursor + 0x8); + size_t name_off = rz_read_le32 (cursor + 0xc); + size_t mangled_name_off = rz_read_le32 (cursor + 0x10); + lsym->sym.unk2 = (st32)rz_read_le32 (cursor + 0x14); + size_t file_name_off = rz_read_le32 (cursor + 0x18); + lsym->flc.line = rz_read_le32 (cursor + 0x1c); + lsym->flc.col = rz_read_le32 (cursor + 0x20); lsym->sym.name = str_dup_safe (b, cursor + name_off, end); if (!lsym->sym.name) { cursor += R_CS_EL_SIZE_LSYM; @@ -333,30 +333,30 @@ RCoreSymCacheElement *r_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut continue; } cursor += R_CS_EL_SIZE_LSYM; - meta_add_fileline (bf, r_coresym_cache_element_pa2va (result, lsym->sym.paddr), lsym->sym.size, &lsym->flc); + meta_add_fileline (bf, rz_coresym_cache_element_pa2va (result, lsym->sym.paddr), lsym->sym.size, &lsym->flc); } } const ut64 start_of_line_info = start_of_lined_symbols + (ut64)hdr->n_lined_symbols * R_CS_EL_SIZE_LSYM; if (hdr->n_line_info) { - result->line_info = R_NEWS0 (RCoreSymCacheElementLineInfo, hdr->n_line_info); + result->line_info = R_NEWS0 (RzCoreSymCacheElementLineInfo, hdr->n_line_info); if (!result->line_info) { goto beach; } size_t i; ut8 *cursor = b + start_of_line_info; for (i = 0; i < hdr->n_line_info && cursor + R_CS_EL_SIZE_LINFO <= end; i++) { - RCoreSymCacheElementLineInfo *info = &result->line_info[i]; - info->paddr = r_read_le32 (cursor); - info->size = r_read_le32 (cursor + 4); - size_t file_name_off = r_read_le32 (cursor + 8); - info->flc.line = r_read_le32 (cursor + 0xc); - info->flc.col = r_read_le32 (cursor + 0x10); + RzCoreSymCacheElementLineInfo *info = &result->line_info[i]; + info->paddr = rz_read_le32 (cursor); + info->size = rz_read_le32 (cursor + 4); + size_t file_name_off = rz_read_le32 (cursor + 8); + info->flc.line = rz_read_le32 (cursor + 0xc); + info->flc.col = rz_read_le32 (cursor + 0x10); info->flc.file = str_dup_safe (b, cursor + file_name_off, end); if (!info->flc.file) { break; } cursor += R_CS_EL_SIZE_LINFO; - meta_add_fileline (bf, r_coresym_cache_element_pa2va (result, info->paddr), info->size, &info->flc); + meta_add_fileline (bf, rz_coresym_cache_element_pa2va (result, info->paddr), info->size, &info->flc); } } diff --git a/librz/bin/format/mach0/coresymbolication.h b/librz/bin/format/mach0/coresymbolication.h new file mode 100644 index 0000000000..4d327fc4ba --- /dev/null +++ b/librz/bin/format/mach0/coresymbolication.h @@ -0,0 +1,85 @@ +#include +#include + +#ifndef _INCLUDE_R_BIN_CORESYMBOLICATION_H +#define _INCLUDE_R_BIN_CORESYMBOLICATION_H + +typedef struct rz_coresym_cache_element_hdr_t { + ut32 version; + ut32 size; + ut32 n_segments; + ut32 n_sections; + ut32 n_symbols; + ut32 n_lined_symbols; + ut32 n_line_info; + ut32 f; + ut32 g; + ut32 h; + ut32 file_name_off; + ut32 version_off; + ut32 k; + ut8 uuid[16]; + ut32 cputype; + ut32 cpusubtype; + ut32 o; + ut32 strings_off; + ut32 p; +} RzCoreSymCacheElementHdr; + +typedef struct rz_coresym_cache_element_segment_t { + ut64 paddr; + ut64 vaddr; + ut64 size; + ut64 vsize; + char *name; +} RzCoreSymCacheElementSegment; + +typedef struct rz_coresym_cache_element_section_t { + ut64 paddr; + ut64 vaddr; + ut64 size; + char *name; +} RzCoreSymCacheElementSection; + +typedef struct rz_coresym_cache_element_flc_t { + char *file; + ut32 line; + ut32 col; +} RzCoreSymCacheElementFLC; + +typedef struct rz_coresym_cache_element_line_info_t { + ut32 paddr; + ut32 size; + RzCoreSymCacheElementFLC flc; +} RzCoreSymCacheElementLineInfo; + +typedef struct rz_coresym_cache_element_symbol_t { + ut32 paddr; + ut32 size; + ut32 unk1; + char *name; + char *mangled_name; + st32 unk2; +} RzCoreSymCacheElementSymbol; + +typedef struct rz_coresym_cache_element_lined_symbol_t { + RzCoreSymCacheElementSymbol sym; + RzCoreSymCacheElementFLC flc; +} RzCoreSymCacheElementLinedSymbol; + +typedef struct rz_coresym_cache_element_t { + RzCoreSymCacheElementHdr *hdr; + char *file_name; + char *binary_version; + RzCoreSymCacheElementSegment *segments; + RzCoreSymCacheElementSection *sections; + RzCoreSymCacheElementSymbol *symbols; + RzCoreSymCacheElementLinedSymbol *lined_symbols; + RzCoreSymCacheElementLineInfo *line_info; +} RzCoreSymCacheElement; + +RZ_API RzCoreSymCacheElement *rz_coresym_cache_element_new(RBinFile *bf, RBuffer *buf, ut64 off, int bits); +RZ_API void rz_coresym_cache_element_free(RzCoreSymCacheElement *element); +RZ_API ut64 rz_coresym_cache_element_pa2va(RzCoreSymCacheElement *element, ut64 pa); + +#endif diff --git a/libr/bin/format/mach0/dyldcache.c b/librz/bin/format/mach0/dyldcache.c similarity index 61% rename from libr/bin/format/mach0/dyldcache.c rename to librz/bin/format/mach0/dyldcache.c index 21dcdb2434..bac2dc7bd4 100644 --- a/libr/bin/format/mach0/dyldcache.c +++ b/librz/bin/format/mach0/dyldcache.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2010-2018 - nibble, pancake */ #include -#include -#include +#include +#include #include "dyldcache.h" -static int r_bin_dyldcache_init(struct r_bin_dyldcache_obj_t* bin) { - int len = r_buf_fread_at (bin->b, 0, (ut8*)&bin->hdr, "16c4i7l", 1); +static int rz_bin_dyldcache_init(struct rz_bin_dyldcache_obj_t* bin) { + int len = rz_buf_fread_at (bin->b, 0, (ut8*)&bin->hdr, "16c4i7l", 1); if (len == -1) { perror ("read (cache_header)"); return false; @@ -15,23 +15,23 @@ static int r_bin_dyldcache_init(struct r_bin_dyldcache_obj_t* bin) { return true; } -static int r_bin_dyldcache_apply_patch(RBuffer* buf, ut32 data, ut64 offset) { - return r_buf_write_at (buf, offset, (ut8 *)&data, sizeof (data)); +static int rz_bin_dyldcache_apply_patch(RBuffer* buf, ut32 data, ut64 offset) { + return rz_buf_write_at (buf, offset, (ut8 *)&data, sizeof (data)); } -#define NZ_OFFSET(x, y, z) if((x) > 0) r_bin_dyldcache_apply_patch (dbuf, (x) - linkedit_offset, addend + r_offsetof (y, z)) +#define NZ_OFFSET(x, y, z) if((x) > 0) rz_bin_dyldcache_apply_patch (dbuf, (x) - linkedit_offset, addend + rz_offsetof (y, z)) // make it public in util/buf.c ? -static ut64 r_buf_read64le(RBuffer *buf, ut64 off) { +static ut64 rz_buf_read64le(RBuffer *buf, ut64 off) { ut8 data[8] = {0}; - r_buf_read_at (buf, off, data, 8); - return r_read_le64 (data); + rz_buf_read_at (buf, off, data, 8); + return rz_read_le64 (data); } -static char *r_buf_read_string(RBuffer *buf, ut64 addr, int len) { +static char *rz_buf_read_string(RBuffer *buf, ut64 addr, int len) { ut8 *data = malloc (len); if (data) { - r_buf_read_at (buf, addr, data, len); + rz_buf_read_at (buf, addr, data, len); data[len - 1] = 0; return (char *)data; } @@ -39,11 +39,11 @@ static char *r_buf_read_string(RBuffer *buf, ut64 addr, int len) { } /* TODO: Needs more testing and ERROR HANDLING */ -struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj_t* bin, int idx, int *nlib) { +struct rz_bin_dyldcache_lib_t *rz_bin_dyldcache_extract(struct rz_bin_dyldcache_obj_t* bin, int idx, int *nlib) { ut64 liboff, linkedit_offset; ut64 dyld_vmbase; ut32 addend = 0; - struct r_bin_dyldcache_lib_t *ret = NULL; + struct rz_bin_dyldcache_lib_t *ret = NULL; struct dyld_cache_image_info* image_infos = NULL; struct mach_header mh; ut64 cmdptr; @@ -62,7 +62,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj return NULL; } *nlib = bin->nlibs; - ret = R_NEW0 (struct r_bin_dyldcache_lib_t); + ret = R_NEW0 (struct rz_bin_dyldcache_lib_t); if (!ret) { return NULL; } @@ -80,8 +80,8 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj if (!image_infos) { goto ret_err; } - r_buf_read_at (bin->b, bin->hdr.startaddr, (ut8*)image_infos, sz); - dyld_vmbase = r_buf_read64le (bin->b, bin->hdr.baseaddroff); + rz_buf_read_at (bin->b, bin->hdr.startaddr, (ut8*)image_infos, sz); + dyld_vmbase = rz_buf_read64le (bin->b, bin->hdr.baseaddroff); liboff = image_infos[idx].address - dyld_vmbase; if (liboff > bin->size) { eprintf ("Corrupted file\n"); @@ -93,9 +93,9 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj eprintf ("corrupted file: pathFileOffset > bin->size (%d)\n", pfo); goto ret_err; } - libname = r_buf_read_string (bin->b, pfo, 64); + libname = rz_buf_read_string (bin->b, pfo, 64); /* Locate lib hdr in cache */ - int r = r_buf_read_at (bin->b, liboff, (ut8 *)&mh, sizeof (mh)); + int r = rz_buf_read_at (bin->b, liboff, (ut8 *)&mh, sizeof (mh)); if (r != sizeof (mh)) { goto ret_err; } @@ -109,29 +109,29 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj } addend = mh.magic == MH_MAGIC? sizeof (struct mach_header) : sizeof (struct mach_header_64); /* Write mach-o hdr */ - if (!(dbuf = r_buf_new ())) { + if (!(dbuf = rz_buf_new ())) { eprintf ("new (dbuf)\n"); goto ret_err; } - if (!r_buf_append_buf_slice (dbuf, bin->b, liboff, addend)) { + if (!rz_buf_append_buf_slice (dbuf, bin->b, liboff, addend)) { goto dbuf_err; } cmdptr = liboff + addend; /* Write load commands */ for (cmd = 0; cmd < mh.ncmds; cmd++) { struct load_command lc; - int r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&lc, sizeof (lc)); + int r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&lc, sizeof (lc)); if (r != sizeof (lc)) { goto dbuf_err; } - r_buf_append_bytes (dbuf, (ut8 *)&lc, lc.cmdsize); + rz_buf_append_bytes (dbuf, (ut8 *)&lc, lc.cmdsize); cmdptr += lc.cmdsize; } cmdptr = liboff + addend; /* Write segments */ for (cmd = linkedit_offset = 0; cmd < mh.ncmds; cmd++) { struct load_command lc; - int r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&lc, sizeof (lc)); + int r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&lc, sizeof (lc)); if (r != sizeof (lc)) { goto dbuf_err; } @@ -140,7 +140,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj { /* Write segment and patch offset */ struct segment_command seg; - r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&seg, sizeof (seg)); + r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&seg, sizeof (seg)); if (r != sizeof (seg)) { goto dbuf_err; } @@ -149,12 +149,12 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj eprintf ("malformed dyldcache\n"); goto dbuf_err; } - r_buf_append_buf_slice (dbuf, bin->b, seg.fileoff, t); - r_bin_dyldcache_apply_patch (dbuf, r_buf_size (dbuf), - addend + r_offsetof (struct segment_command, fileoff)); + rz_buf_append_buf_slice (dbuf, bin->b, seg.fileoff, t); + rz_bin_dyldcache_apply_patch (dbuf, rz_buf_size (dbuf), + addend + rz_offsetof (struct segment_command, fileoff)); /* Patch section offsets */ int sect_offset = seg.fileoff - libsz; - libsz = r_buf_size (dbuf); + libsz = rz_buf_size (dbuf); if (!strcmp (seg.segname, "__LINKEDIT")) { linkedit_offset = sect_offset; } @@ -162,13 +162,13 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj int nsect; for (nsect = 0; nsect < seg.nsects; nsect++) { struct section sect; - r = r_buf_read_at (bin->b, cmdptr + nsect * sizeof (struct segment_command), (ut8 *)§, sizeof (sect)); + r = rz_buf_read_at (bin->b, cmdptr + nsect * sizeof (struct segment_command), (ut8 *)§, sizeof (sect)); if (r != sizeof (sect)) { break; } if (sect.offset > libsz) { - r_bin_dyldcache_apply_patch (dbuf, sect.offset - sect_offset, - addend + r_offsetof (struct section, offset)); + rz_bin_dyldcache_apply_patch (dbuf, sect.offset - sect_offset, + addend + rz_offsetof (struct section, offset)); } } } @@ -177,7 +177,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj case LC_SYMTAB: { struct symtab_command st; - r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); + r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); if (r != sizeof (st)) { goto dbuf_err; } @@ -188,7 +188,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj case LC_DYSYMTAB: { struct dysymtab_command st; - r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); + r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); if (r != sizeof (st)) { goto dbuf_err; } @@ -204,7 +204,7 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj case LC_DYLD_INFO_ONLY: { struct dyld_info_command st; - r = r_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); + r = rz_buf_read_at (bin->b, cmdptr, (ut8 *)&st, sizeof (st)); if (r != sizeof (st)) { goto dbuf_err; } @@ -218,29 +218,29 @@ struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj } cmdptr += lc.cmdsize; } - /* Fill r_bin_dyldcache_lib_t ret */ + /* Fill rz_bin_dyldcache_lib_t ret */ ret->b = dbuf; strncpy (ret->path, libname, sizeof (ret->path) - 1); ret->size = libsz; return ret; dbuf_err: - r_buf_free (dbuf); + rz_buf_free (dbuf); ret_err: free (ret); return NULL; } -void* r_bin_dyldcache_free(struct r_bin_dyldcache_obj_t* bin) { +void* rz_bin_dyldcache_free(struct rz_bin_dyldcache_obj_t* bin) { if (!bin) { return NULL; } - r_buf_free (bin->b); + rz_buf_free (bin->b); free (bin); return NULL; } -void r_bin_dydlcache_get_libname(struct r_bin_dyldcache_lib_t *lib, char **libname) { +void rz_bin_dydlcache_get_libname(struct rz_bin_dyldcache_lib_t *lib, char **libname) { char *cur = lib->path; char *res = lib->path; int path_length = strlen (lib->path); @@ -255,44 +255,44 @@ void r_bin_dydlcache_get_libname(struct r_bin_dyldcache_lib_t *lib, char **libna *libname = res; } -struct r_bin_dyldcache_obj_t* r_bin_dyldcache_new(const char* file) { - struct r_bin_dyldcache_obj_t *bin; - if (!(bin = R_NEW0 (struct r_bin_dyldcache_obj_t))) { +struct rz_bin_dyldcache_obj_t* rz_bin_dyldcache_new(const char* file) { + struct rz_bin_dyldcache_obj_t *bin; + if (!(bin = R_NEW0 (struct rz_bin_dyldcache_obj_t))) { return NULL; } bin->file = file; size_t binsz; - ut8 *buf = (ut8 *)r_file_slurp (file, &binsz); + ut8 *buf = (ut8 *)rz_file_slurp (file, &binsz); bin->size = binsz; if (!buf) { - return r_bin_dyldcache_free (bin); + return rz_bin_dyldcache_free (bin); } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { free (buf); - return r_bin_dyldcache_free (bin); + return rz_bin_dyldcache_free (bin); } free (buf); - if (!r_bin_dyldcache_init (bin)) { - return r_bin_dyldcache_free (bin); + if (!rz_bin_dyldcache_init (bin)) { + return rz_bin_dyldcache_free (bin); } return bin; } -struct r_bin_dyldcache_obj_t* r_bin_dyldcache_from_bytes_new(const ut8* buf, ut64 size) { - struct r_bin_dyldcache_obj_t *bin = R_NEW0 (struct r_bin_dyldcache_obj_t); +struct rz_bin_dyldcache_obj_t* rz_bin_dyldcache_from_bytes_new(const ut8* buf, ut64 size) { + struct rz_bin_dyldcache_obj_t *bin = R_NEW0 (struct rz_bin_dyldcache_obj_t); if (!bin) { return NULL; } if (!buf) { - return r_bin_dyldcache_free (bin); + return rz_bin_dyldcache_free (bin); } - bin->b = r_buf_new (); - if (!bin->b || !r_buf_set_bytes (bin->b, buf, size)) { - return r_bin_dyldcache_free (bin); + bin->b = rz_buf_new (); + if (!bin->b || !rz_buf_set_bytes (bin->b, buf, size)) { + return rz_bin_dyldcache_free (bin); } - if (!r_bin_dyldcache_init (bin)) { - return r_bin_dyldcache_free (bin); + if (!rz_bin_dyldcache_init (bin)) { + return rz_bin_dyldcache_free (bin); } bin->size = size; return bin; diff --git a/libr/bin/format/mach0/dyldcache.h b/librz/bin/format/mach0/dyldcache.h similarity index 66% rename from libr/bin/format/mach0/dyldcache.h rename to librz/bin/format/mach0/dyldcache.h index 9f00182cd2..21522b1d57 100644 --- a/libr/bin/format/mach0/dyldcache.h +++ b/librz/bin/format/mach0/dyldcache.h @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2009-2010 nibble<.ds@gmail.com> */ -#include +#include #include "mach0_specs.h" #ifndef _INCLUDE_R_BIN_DYLDCACHE_H_ #define _INCLUDE_R_BIN_DYLDCACHE_H_ -struct r_bin_dyldcache_obj_t { +struct rz_bin_dyldcache_obj_t { const char *file; int size; int nlibs; @@ -14,7 +14,7 @@ struct r_bin_dyldcache_obj_t { RBuffer* b; }; -struct r_bin_dyldcache_lib_t { +struct rz_bin_dyldcache_lib_t { char path[1024]; int size; ut64 offset; @@ -63,10 +63,10 @@ typedef struct _dyld_cache_local_symbols_entry { ut32 nlistCount; } dyld_cache_local_symbols_entry; -struct r_bin_dyldcache_lib_t *r_bin_dyldcache_extract(struct r_bin_dyldcache_obj_t* bin, int idx, int *nlib); -void *r_bin_dyldcache_free(struct r_bin_dyldcache_obj_t* bin); -struct r_bin_dyldcache_obj_t* r_bin_dyldcache_new(const char* file); -struct r_bin_dyldcache_obj_t* r_bin_dyldcache_from_bytes_new (const ut8* bytes, ut64 size); -void r_bin_dydlcache_get_libname(struct r_bin_dyldcache_lib_t *lib, char **libname); +struct rz_bin_dyldcache_lib_t *rz_bin_dyldcache_extract(struct rz_bin_dyldcache_obj_t* bin, int idx, int *nlib); +void *rz_bin_dyldcache_free(struct rz_bin_dyldcache_obj_t* bin); +struct rz_bin_dyldcache_obj_t* rz_bin_dyldcache_new(const char* file); +struct rz_bin_dyldcache_obj_t* rz_bin_dyldcache_from_bytes_new (const ut8* bytes, ut64 size); +void rz_bin_dydlcache_get_libname(struct rz_bin_dyldcache_lib_t *lib, char **libname); #endif diff --git a/librz/bin/format/mach0/fatmach0.c b/librz/bin/format/mach0/fatmach0.c new file mode 100644 index 0000000000..ed7f1af8f8 --- /dev/null +++ b/librz/bin/format/mach0/fatmach0.c @@ -0,0 +1,142 @@ +/* radare - LGPL - Copyright 2010-2013 - nibble */ + +#include +#include +#include +#include "fatmach0.h" + +static int rz_bin_fatmach0_init(struct rz_bin_fatmach0_obj_t* bin) { + ut32 size; + ut32 i; + ut8 hdrbytes[sizeof (struct fat_header)] = {0}; + int len = rz_buf_read_at (bin->b, 0, &hdrbytes[0], sizeof (struct fat_header)); + if (len != sizeof (struct fat_header)) { + perror ("read (fat_header)"); + return false; + } + bin->hdr.magic = rz_read_be32 (&hdrbytes[0]); + bin->hdr.nfat_arch = rz_read_be32 (&hdrbytes[4]); + bin->nfat_arch = bin->hdr.nfat_arch; + if (sizeof (struct fat_header) + bin->nfat_arch * + sizeof (struct fat_arch) > bin->size) { + return false; + } + if (bin->hdr.magic != FAT_MAGIC || !bin->nfat_arch || bin->nfat_arch < 1) { + eprintf ("Endian FAT_MAGIC failed (?)\n"); + return false; + } + size = bin->nfat_arch * sizeof (struct fat_arch); + if (size < bin->nfat_arch) { + return false; + } + if (!(bin->archs = malloc (size))) { + perror ("malloc (fat_arch)"); + return false; + } + for (i = 0; i < bin->nfat_arch; i++) { + ut8 archbytes[sizeof (struct fat_arch)] = {0}; + len = rz_buf_read_at (bin->b, 8 + i * sizeof (struct fat_arch), &archbytes[0], sizeof (struct fat_arch)); + if (len != sizeof (struct fat_arch)) { + perror ("read (fat_arch)"); + R_FREE (bin->archs); + return false; + } + bin->archs[i].cputype = rz_read_be32 (&archbytes[0]); + bin->archs[i].cpusubtype = rz_read_be32 (&archbytes[4]); + bin->archs[i].offset = rz_read_be32 (&archbytes[8]); + bin->archs[i].size = rz_read_be32 (&archbytes[12]); + bin->archs[i].align = rz_read_be32 (&archbytes[16]); + } + return true; +} + +struct rz_bin_fatmach0_arch_t *rz_bin_fatmach0_extract(struct rz_bin_fatmach0_obj_t* bin, int idx, int *narch) { + if (!bin || (idx < 0) || (idx > bin->nfat_arch)) { + return NULL; + } + if (bin->archs[idx].offset > bin->size || + bin->archs[idx].offset + bin->archs[idx].size > bin->size) { + return NULL; + } + if (narch) { + *narch = bin->nfat_arch; + } + struct rz_bin_fatmach0_arch_t *ret = R_NEW0 (struct rz_bin_fatmach0_arch_t); + if (ret) { + ret->size = bin->archs[idx].size; + if (!ret->size || ret->size > bin->size) { + eprintf ("Skipping corrupted sub-bin %d arch %d\n", idx, bin->archs[idx].size); + free (ret); + return NULL; + } + ret->offset = bin->archs[idx].offset; + ret->b = rz_buf_new_slice (bin->b, ret->offset, ret->size); + } + return ret; +} + +void* rz_bin_fatmach0_free(struct rz_bin_fatmach0_obj_t* bin) { + if (!bin) { + return NULL; + } + free (bin->archs); + rz_buf_free (bin->b); + R_FREE (bin); + return NULL; +} + +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_new(const char* file) { + struct rz_bin_fatmach0_obj_t *bin = R_NEW0 (struct rz_bin_fatmach0_obj_t); + if (!bin) { + return NULL; + } + bin->file = file; + size_t binsz; + ut8 *buf = (ut8 *)rz_file_slurp (file, &binsz); + bin->size = binsz; + if (!buf) { + return rz_bin_fatmach0_free (bin); + } + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { + free (buf); + return rz_bin_fatmach0_free (bin); + } + free (buf); + if (!rz_bin_fatmach0_init (bin)) { + return rz_bin_fatmach0_free (bin); + } + return bin; +} + +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_from_buffer_new(RBuffer *b) { + rz_return_val_if_fail (b, NULL); + struct rz_bin_fatmach0_obj_t *bo = R_NEW0 (struct rz_bin_fatmach0_obj_t); + if (bo) { + bo->b = rz_buf_ref (b); + bo->size = rz_buf_size (bo->b); // XXX implicit in bo->b + if (!rz_bin_fatmach0_init (bo)) { + return rz_bin_fatmach0_free (bo); + } + } + return bo; +} + +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_from_bytes_new(const ut8* buf, ut64 size) { + struct rz_bin_fatmach0_obj_t *bin = R_NEW0 (struct rz_bin_fatmach0_obj_t); + if (!bin) { + return NULL; + } + if (!buf) { + return rz_bin_fatmach0_free (bin); + } + bin->b = rz_buf_new (); + bin->size = size; + if (!rz_buf_set_bytes (bin->b, buf, size)) { + return rz_bin_fatmach0_free (bin); + } + if (!rz_bin_fatmach0_init (bin)) { + return rz_bin_fatmach0_free (bin); + } + return bin; +} diff --git a/librz/bin/format/mach0/fatmach0.h b/librz/bin/format/mach0/fatmach0.h new file mode 100644 index 0000000000..fe9b5776d0 --- /dev/null +++ b/librz/bin/format/mach0/fatmach0.h @@ -0,0 +1,28 @@ +#include +#include "mach0_specs.h" + +#ifndef _INCLUDE_R_BIN_FATMACH0_H_ +#define _INCLUDE_R_BIN_FATMACH0_H_ + +struct rz_bin_fatmach0_obj_t { + const char *file; + int size; + int nfat_arch; + struct fat_header hdr; + struct fat_arch *archs; + RBuffer* b; +}; + +struct rz_bin_fatmach0_arch_t { + int size; + int offset; + RBuffer *b; + int last; +}; + +struct rz_bin_fatmach0_arch_t *rz_bin_fatmach0_extract(struct rz_bin_fatmach0_obj_t* bin, int idx, int *narch); +void* rz_bin_fatmach0_free(struct rz_bin_fatmach0_obj_t* bin); +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_new(const char* file); +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_from_bytes_new(const ut8* buf, ut64 size); +struct rz_bin_fatmach0_obj_t* rz_bin_fatmach0_from_buffer_new(RBuffer *b); +#endif diff --git a/libr/bin/format/mach0/mach0.c b/librz/bin/format/mach0/mach0.c similarity index 82% rename from libr/bin/format/mach0/mach0.c rename to librz/bin/format/mach0/mach0.c index 882274a707..f9d8ea3631 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/librz/bin/format/mach0/mach0.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2010-2020 - nibble, pancake */ #include -#include -#include +#include +#include #include "mach0.h" -#include +#include // TODO: deprecate bprintf and use Eprintf (bin->self) #define bprintf if (bin->verbose) eprintf @@ -33,7 +33,7 @@ typedef struct { static ut64 read_uleb128(ut8 **p, ut8 *end) { const char *error = NULL; ut64 v; - *p = (ut8 *)r_uleb128 (*p, end - *p, &v, &error); + *p = (ut8 *)rz_uleb128 (*p, end - *p, &v, &error); if (error) { eprintf ("%s", error); R_FREE (error); @@ -83,8 +83,8 @@ static ut64 offset_to_vaddr(struct MACH0_(obj_t) *bin, ut64 offset) { } static ut64 pa2va(RBinFile *bf, ut64 offset) { - r_return_val_if_fail (bf && bf->rbin, offset); - RIO *io = bf->rbin->iob.io; + rz_return_val_if_fail (bf && bf->rbin, offset); + RzIO *io = bf->rbin->iob.io; if (!io || !io->va) { return offset; } @@ -95,7 +95,7 @@ static ut64 pa2va(RBinFile *bf, ut64 offset) { static void init_sdb_formats(struct MACH0_(obj_t) *bin) { /* * These definitions are used by r2 -nn - * must be kept in sync with libr/bin/d/macho + * must be kept in sync with librz/bin/d/macho */ sdb_set (bin->kv, "mach0_build_platform.cparse", "enum mach0_build_platform" "{MACOS=1, IOS=2, TVOS=3, WATCHOS=4, BRIDGEOS=5, IOSMAC=6, IOSSIMULATOR=7, TVOSSIMULATOR=8, WATCHOSSIMULATOR=9};", @@ -232,38 +232,38 @@ static bool init_hdr(struct MACH0_(obj_t) *bin) { ut8 machohdrbytes[sizeof (struct MACH0_(mach_header))] = {0}; int len; - if (r_buf_read_at (bin->b, 0 + bin->header_at, magicbytes, 4) < 1) { + if (rz_buf_read_at (bin->b, 0 + bin->header_at, magicbytes, 4) < 1) { return false; } - if (r_read_le32 (magicbytes) == 0xfeedface) { + if (rz_read_le32 (magicbytes) == 0xfeedface) { bin->big_endian = false; - } else if (r_read_be32 (magicbytes) == 0xfeedface) { + } else if (rz_read_be32 (magicbytes) == 0xfeedface) { bin->big_endian = true; - } else if (r_read_le32 (magicbytes) == FAT_MAGIC) { + } else if (rz_read_le32 (magicbytes) == FAT_MAGIC) { bin->big_endian = false; - } else if (r_read_be32 (magicbytes) == FAT_MAGIC) { + } else if (rz_read_be32 (magicbytes) == FAT_MAGIC) { bin->big_endian = true; - } else if (r_read_le32 (magicbytes) == 0xfeedfacf) { + } else if (rz_read_le32 (magicbytes) == 0xfeedfacf) { bin->big_endian = false; - } else if (r_read_be32 (magicbytes) == 0xfeedfacf) { + } else if (rz_read_be32 (magicbytes) == 0xfeedfacf) { bin->big_endian = true; } else { return false; // object files are magic == 0, but body is different :? } - len = r_buf_read_at (bin->b, 0 + bin->header_at, machohdrbytes, sizeof (machohdrbytes)); + len = rz_buf_read_at (bin->b, 0 + bin->header_at, machohdrbytes, sizeof (machohdrbytes)); if (len != sizeof (machohdrbytes)) { bprintf ("Error: read (hdr)\n"); return false; } - bin->hdr.magic = r_read_ble (&machohdrbytes[0], bin->big_endian, 32); - bin->hdr.cputype = r_read_ble (&machohdrbytes[4], bin->big_endian, 32); - bin->hdr.cpusubtype = r_read_ble (&machohdrbytes[8], bin->big_endian, 32); - bin->hdr.filetype = r_read_ble (&machohdrbytes[12], bin->big_endian, 32); - bin->hdr.ncmds = r_read_ble (&machohdrbytes[16], bin->big_endian, 32); - bin->hdr.sizeofcmds = r_read_ble (&machohdrbytes[20], bin->big_endian, 32); - bin->hdr.flags = r_read_ble (&machohdrbytes[24], bin->big_endian, 32); + bin->hdr.magic = rz_read_ble (&machohdrbytes[0], bin->big_endian, 32); + bin->hdr.cputype = rz_read_ble (&machohdrbytes[4], bin->big_endian, 32); + bin->hdr.cpusubtype = rz_read_ble (&machohdrbytes[8], bin->big_endian, 32); + bin->hdr.filetype = rz_read_ble (&machohdrbytes[12], bin->big_endian, 32); + bin->hdr.ncmds = rz_read_ble (&machohdrbytes[16], bin->big_endian, 32); + bin->hdr.sizeofcmds = rz_read_ble (&machohdrbytes[20], bin->big_endian, 32); + bin->hdr.flags = rz_read_ble (&machohdrbytes[24], bin->big_endian, 32); #if R_BIN_MACH064 - bin->hdr.reserved = r_read_ble (&machohdrbytes[28], bin->big_endian, 32); + bin->hdr.reserved = rz_read_ble (&machohdrbytes[28], bin->big_endian, 32); #endif init_sdb_formats (bin); sdb_num_set (bin->kv, "mach0_header.offset", 0, 0); // wat about fatmach0? @@ -290,44 +290,44 @@ static bool parse_segments(struct MACH0_(obj_t) *bin, ut64 off) { return false; } j = bin->nsegs - 1; - len = r_buf_read_at (bin->b, off, segcom, sizeof (struct MACH0_(segment_command))); + len = rz_buf_read_at (bin->b, off, segcom, sizeof (struct MACH0_(segment_command))); if (len != sizeof (struct MACH0_(segment_command))) { bprintf ("Error: read (seg)\n"); return false; } i = 0; - bin->segs[j].cmd = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].cmd = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].cmdsize = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].cmdsize = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); memcpy (&bin->segs[j].segname, &segcom[i], 16); i += 16; #if R_BIN_MACH064 - bin->segs[j].vmaddr = r_read_ble64 (&segcom[i], bin->big_endian); + bin->segs[j].vmaddr = rz_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); - bin->segs[j].vmsize = r_read_ble64 (&segcom[i], bin->big_endian); + bin->segs[j].vmsize = rz_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); - bin->segs[j].fileoff = r_read_ble64 (&segcom[i], bin->big_endian); + bin->segs[j].fileoff = rz_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); - bin->segs[j].filesize = r_read_ble64 (&segcom[i], bin->big_endian); + bin->segs[j].filesize = rz_read_ble64 (&segcom[i], bin->big_endian); i += sizeof (ut64); #else - bin->segs[j].vmaddr = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].vmaddr = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].vmsize = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].vmsize = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].fileoff = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].fileoff = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].filesize = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].filesize = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); #endif - bin->segs[j].maxprot = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].maxprot = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].initprot = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].initprot = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].nsects = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].nsects = rz_read_ble32 (&segcom[i], bin->big_endian); i += sizeof (ut32); - bin->segs[j].flags = r_read_ble32 (&segcom[i], bin->big_endian); + bin->segs[j].flags = rz_read_ble32 (&segcom[i], bin->big_endian); #if R_BIN_MACH064 sdb_num_set (bin->kv, sdb_fmt ("mach0_segment64_%d.offset", j), off, 0); @@ -380,7 +380,7 @@ static bool parse_segments(struct MACH0_(obj_t) *bin, ut64 off) { for (k = sect, j = 0; k < bin->nsects; k++, j++) { ut64 offset = off + sizeof (struct MACH0_(segment_command)) + j * sizeof (struct MACH0_(section)); - len = r_buf_read_at (bin->b, offset, sec, sizeof (struct MACH0_(section))); + len = rz_buf_read_at (bin->b, offset, sec, sizeof (struct MACH0_(section))); if (len != sizeof (struct MACH0_(section))) { bprintf ("Error: read (sects)\n"); bin->nsects = sect; @@ -401,32 +401,32 @@ static bool parse_segments(struct MACH0_(obj_t) *bin, ut64 off) { #endif #if R_BIN_MACH064 - bin->sects[k].addr = r_read_ble64 (&sec[i], bin->big_endian); + bin->sects[k].addr = rz_read_ble64 (&sec[i], bin->big_endian); i += sizeof (ut64); - bin->sects[k].size = r_read_ble64 (&sec[i], bin->big_endian); + bin->sects[k].size = rz_read_ble64 (&sec[i], bin->big_endian); i += sizeof (ut64); #else - bin->sects[k].addr = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].addr = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].size = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].size = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); #endif - bin->sects[k].offset = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].offset = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].align = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].align = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].reloff = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].reloff = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].nreloc = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].nreloc = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].flags = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].flags = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].reserved1 = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].reserved1 = rz_read_ble32 (&sec[i], bin->big_endian); i += sizeof (ut32); - bin->sects[k].reserved2 = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].reserved2 = rz_read_ble32 (&sec[i], bin->big_endian); #if R_BIN_MACH064 i += sizeof (ut32); - bin->sects[k].reserved3 = r_read_ble32 (&sec[i], bin->big_endian); + bin->sects[k].reserved3 = rz_read_ble32 (&sec[i], bin->big_endian); #endif } } @@ -446,17 +446,17 @@ static bool parse_symtab(struct MACH0_(obj_t) *mo, ut64 off) { if (off > (ut64)mo->size || off + sizeof (struct symtab_command) > (ut64)mo->size) { return false; } - int len = r_buf_read_at (mo->b, off, symt, sizeof (struct symtab_command)); + int len = rz_buf_read_at (mo->b, off, symt, sizeof (struct symtab_command)); if (len != sizeof (struct symtab_command)) { Eprintf ("Error: read (symtab)\n"); return false; } - st.cmd = r_read_ble32 (symt, be); - st.cmdsize = r_read_ble32 (symt + 4, be); - st.symoff = r_read_ble32 (symt + 8, be); - st.nsyms = r_read_ble32 (symt + 12, be); - st.stroff = r_read_ble32 (symt + 16, be); - st.strsize = r_read_ble32 (symt + 20, be); + st.cmd = rz_read_ble32 (symt, be); + st.cmdsize = rz_read_ble32 (symt + 4, be); + st.symoff = rz_read_ble32 (symt + 8, be); + st.nsyms = rz_read_ble32 (symt + 12, be); + st.stroff = rz_read_ble32 (symt + 16, be); + st.strsize = rz_read_ble32 (symt + 20, be); mo->symtab = NULL; mo->nsymtab = 0; @@ -478,7 +478,7 @@ static bool parse_symtab(struct MACH0_(obj_t) *mo, ut64 off) { Error ("symoff is out of bounds"); } mo->symstrlen = st.strsize; - len = r_buf_read_at (mo->b, st.stroff, (ut8*)mo->symstr, st.strsize); + len = rz_buf_read_at (mo->b, st.stroff, (ut8*)mo->symstr, st.strsize); if (len != st.strsize) { Error ("Error: read (symstr)"); } @@ -487,19 +487,19 @@ static bool parse_symtab(struct MACH0_(obj_t) *mo, ut64 off) { } for (i = 0; i < mo->nsymtab; i++) { ut64 at = st.symoff + (i * sizeof (struct MACH0_(nlist))); - len = r_buf_read_at (mo->b, at, nlst, sizeof (struct MACH0_(nlist))); + len = rz_buf_read_at (mo->b, at, nlst, sizeof (struct MACH0_(nlist))); if (len != sizeof (struct MACH0_(nlist))) { Error ("read (nlist)"); } //XXX not very safe what if is n_un.n_name instead? - mo->symtab[i].n_strx = r_read_ble32 (nlst, be); - mo->symtab[i].n_type = r_read_ble8 (nlst + 4); - mo->symtab[i].n_sect = r_read_ble8 (nlst + 5); - mo->symtab[i].n_desc = r_read_ble16 (nlst + 6, be); + mo->symtab[i].n_strx = rz_read_ble32 (nlst, be); + mo->symtab[i].n_type = rz_read_ble8 (nlst + 4); + mo->symtab[i].n_sect = rz_read_ble8 (nlst + 5); + mo->symtab[i].n_desc = rz_read_ble16 (nlst + 6, be); #if R_BIN_MACH064 - mo->symtab[i].n_value = r_read_ble64 (&nlst[8], be); + mo->symtab[i].n_value = rz_read_ble64 (&nlst[8], be); #else - mo->symtab[i].n_value = r_read_ble32 (&nlst[8], be); + mo->symtab[i].n_value = rz_read_ble32 (&nlst[8], be); #endif } } @@ -523,32 +523,32 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { return false; } - len = r_buf_read_at (bin->b, off, dysym, sizeof (struct dysymtab_command)); + len = rz_buf_read_at (bin->b, off, dysym, sizeof (struct dysymtab_command)); if (len != sizeof (struct dysymtab_command)) { bprintf ("Error: read (dysymtab)\n"); return false; } - bin->dysymtab.cmd = r_read_ble32 (&dysym[0], bin->big_endian); - bin->dysymtab.cmdsize = r_read_ble32 (&dysym[4], bin->big_endian); - bin->dysymtab.ilocalsym = r_read_ble32 (&dysym[8], bin->big_endian); - bin->dysymtab.nlocalsym = r_read_ble32 (&dysym[12], bin->big_endian); - bin->dysymtab.iextdefsym = r_read_ble32 (&dysym[16], bin->big_endian); - bin->dysymtab.nextdefsym = r_read_ble32 (&dysym[20], bin->big_endian); - bin->dysymtab.iundefsym = r_read_ble32 (&dysym[24], bin->big_endian); - bin->dysymtab.nundefsym = r_read_ble32 (&dysym[28], bin->big_endian); - bin->dysymtab.tocoff = r_read_ble32 (&dysym[32], bin->big_endian); - bin->dysymtab.ntoc = r_read_ble32 (&dysym[36], bin->big_endian); - bin->dysymtab.modtaboff = r_read_ble32 (&dysym[40], bin->big_endian); - bin->dysymtab.nmodtab = r_read_ble32 (&dysym[44], bin->big_endian); - bin->dysymtab.extrefsymoff = r_read_ble32 (&dysym[48], bin->big_endian); - bin->dysymtab.nextrefsyms = r_read_ble32 (&dysym[52], bin->big_endian); - bin->dysymtab.indirectsymoff = r_read_ble32 (&dysym[56], bin->big_endian); - bin->dysymtab.nindirectsyms = r_read_ble32 (&dysym[60], bin->big_endian); - bin->dysymtab.extreloff = r_read_ble32 (&dysym[64], bin->big_endian); - bin->dysymtab.nextrel = r_read_ble32 (&dysym[68], bin->big_endian); - bin->dysymtab.locreloff = r_read_ble32 (&dysym[72], bin->big_endian); - bin->dysymtab.nlocrel = r_read_ble32 (&dysym[76], bin->big_endian); + bin->dysymtab.cmd = rz_read_ble32 (&dysym[0], bin->big_endian); + bin->dysymtab.cmdsize = rz_read_ble32 (&dysym[4], bin->big_endian); + bin->dysymtab.ilocalsym = rz_read_ble32 (&dysym[8], bin->big_endian); + bin->dysymtab.nlocalsym = rz_read_ble32 (&dysym[12], bin->big_endian); + bin->dysymtab.iextdefsym = rz_read_ble32 (&dysym[16], bin->big_endian); + bin->dysymtab.nextdefsym = rz_read_ble32 (&dysym[20], bin->big_endian); + bin->dysymtab.iundefsym = rz_read_ble32 (&dysym[24], bin->big_endian); + bin->dysymtab.nundefsym = rz_read_ble32 (&dysym[28], bin->big_endian); + bin->dysymtab.tocoff = rz_read_ble32 (&dysym[32], bin->big_endian); + bin->dysymtab.ntoc = rz_read_ble32 (&dysym[36], bin->big_endian); + bin->dysymtab.modtaboff = rz_read_ble32 (&dysym[40], bin->big_endian); + bin->dysymtab.nmodtab = rz_read_ble32 (&dysym[44], bin->big_endian); + bin->dysymtab.extrefsymoff = rz_read_ble32 (&dysym[48], bin->big_endian); + bin->dysymtab.nextrefsyms = rz_read_ble32 (&dysym[52], bin->big_endian); + bin->dysymtab.indirectsymoff = rz_read_ble32 (&dysym[56], bin->big_endian); + bin->dysymtab.nindirectsyms = rz_read_ble32 (&dysym[60], bin->big_endian); + bin->dysymtab.extreloff = rz_read_ble32 (&dysym[64], bin->big_endian); + bin->dysymtab.nextrel = rz_read_ble32 (&dysym[68], bin->big_endian); + bin->dysymtab.locreloff = rz_read_ble32 (&dysym[72], bin->big_endian); + bin->dysymtab.nlocrel = rz_read_ble32 (&dysym[76], bin->big_endian); bin->ntoc = bin->dysymtab.ntoc; if (bin->ntoc > 0) { @@ -569,7 +569,7 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { return false; } for (i = 0; i < bin->ntoc; i++) { - len = r_buf_read_at (bin->b, bin->dysymtab.tocoff + + len = rz_buf_read_at (bin->b, bin->dysymtab.tocoff + i * sizeof (struct dylib_table_of_contents), dytoc, sizeof (struct dylib_table_of_contents)); if (len != sizeof (struct dylib_table_of_contents)) { @@ -577,8 +577,8 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { R_FREE (bin->toc); return false; } - bin->toc[i].symbol_index = r_read_ble32 (&dytoc[0], bin->big_endian); - bin->toc[i].module_index = r_read_ble32 (&dytoc[4], bin->big_endian); + bin->toc[i].symbol_index = rz_read_ble32 (&dytoc[0], bin->big_endian); + bin->toc[i].module_index = rz_read_ble32 (&dytoc[4], bin->big_endian); } } bin->nmodtab = bin->dysymtab.nmodtab; @@ -601,7 +601,7 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { return false; } for (i = 0; i < bin->nmodtab; i++) { - len = r_buf_read_at (bin->b, bin->dysymtab.modtaboff + + len = rz_buf_read_at (bin->b, bin->dysymtab.modtaboff + i * sizeof (struct MACH0_(dylib_module)), dymod, sizeof (struct MACH0_(dylib_module))); if (len == -1) { @@ -610,23 +610,23 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { return false; } - bin->modtab[i].module_name = r_read_ble32 (&dymod[0], bin->big_endian); - bin->modtab[i].iextdefsym = r_read_ble32 (&dymod[4], bin->big_endian); - bin->modtab[i].nextdefsym = r_read_ble32 (&dymod[8], bin->big_endian); - bin->modtab[i].irefsym = r_read_ble32 (&dymod[12], bin->big_endian); - bin->modtab[i].nrefsym = r_read_ble32 (&dymod[16], bin->big_endian); - bin->modtab[i].ilocalsym = r_read_ble32 (&dymod[20], bin->big_endian); - bin->modtab[i].nlocalsym = r_read_ble32 (&dymod[24], bin->big_endian); - bin->modtab[i].iextrel = r_read_ble32 (&dymod[28], bin->big_endian); - bin->modtab[i].nextrel = r_read_ble32 (&dymod[32], bin->big_endian); - bin->modtab[i].iinit_iterm = r_read_ble32 (&dymod[36], bin->big_endian); - bin->modtab[i].ninit_nterm = r_read_ble32 (&dymod[40], bin->big_endian); + bin->modtab[i].module_name = rz_read_ble32 (&dymod[0], bin->big_endian); + bin->modtab[i].iextdefsym = rz_read_ble32 (&dymod[4], bin->big_endian); + bin->modtab[i].nextdefsym = rz_read_ble32 (&dymod[8], bin->big_endian); + bin->modtab[i].irefsym = rz_read_ble32 (&dymod[12], bin->big_endian); + bin->modtab[i].nrefsym = rz_read_ble32 (&dymod[16], bin->big_endian); + bin->modtab[i].ilocalsym = rz_read_ble32 (&dymod[20], bin->big_endian); + bin->modtab[i].nlocalsym = rz_read_ble32 (&dymod[24], bin->big_endian); + bin->modtab[i].iextrel = rz_read_ble32 (&dymod[28], bin->big_endian); + bin->modtab[i].nextrel = rz_read_ble32 (&dymod[32], bin->big_endian); + bin->modtab[i].iinit_iterm = rz_read_ble32 (&dymod[36], bin->big_endian); + bin->modtab[i].ninit_nterm = rz_read_ble32 (&dymod[40], bin->big_endian); #if R_BIN_MACH064 - bin->modtab[i].objc_module_info_size = r_read_ble32 (&dymod[44], bin->big_endian); - bin->modtab[i].objc_module_info_addr = r_read_ble64 (&dymod[48], bin->big_endian); + bin->modtab[i].objc_module_info_size = rz_read_ble32 (&dymod[44], bin->big_endian); + bin->modtab[i].objc_module_info_addr = rz_read_ble64 (&dymod[48], bin->big_endian); #else - bin->modtab[i].objc_module_info_addr = r_read_ble32 (&dymod[44], bin->big_endian); - bin->modtab[i].objc_module_info_size = r_read_ble32 (&dymod[48], bin->big_endian); + bin->modtab[i].objc_module_info_addr = rz_read_ble32 (&dymod[44], bin->big_endian); + bin->modtab[i].objc_module_info_size = rz_read_ble32 (&dymod[48], bin->big_endian); #endif } } @@ -650,13 +650,13 @@ static bool parse_dysymtab(struct MACH0_(obj_t) *bin, ut64 off) { return false; } for (i = 0; i < bin->nindirectsyms; i++) { - len = r_buf_read_at (bin->b, bin->dysymtab.indirectsymoff + i * sizeof (ut32), idsyms, 4); + len = rz_buf_read_at (bin->b, bin->dysymtab.indirectsymoff + i * sizeof (ut32), idsyms, 4); if (len == -1) { bprintf ("Error: read (indirect syms)\n"); R_FREE (bin->indirectsyms); return false; } - bin->indirectsyms[i] = r_read_ble32 (&idsyms[0], bin->big_endian); + bin->indirectsyms[i] = rz_read_ble32 (&idsyms[0], bin->big_endian); } } /* TODO extrefsyms, extrel, locrel */ @@ -667,7 +667,7 @@ static char *readString (ut8 *p, int off, int len) { if (off < 0 || off >= len) { return NULL; } - return r_str_ndup ((const char *)p + off, len - off); + return rz_str_ndup ((const char *)p + off, len - off); } static void parseCodeDirectory (RBuffer *b, int offset, int datasize) { @@ -702,10 +702,10 @@ static void parseCodeDirectory (RBuffer *b, int offset, int datasize) { return; } eprintf ("Offset: 0x%08"PFMT64x"\n", off); - r_buf_read_at (b, off, p, datasize); + rz_buf_read_at (b, off, p, datasize); CS_CodeDirectory cscd = {0}; - #define READFIELD(x) cscd.x = r_read_ble32 (p + r_offsetof (CS_CodeDirectory, x), 1) - #define READFIELD8(x) cscd.x = p[r_offsetof (CS_CodeDirectory, x)] + #define READFIELD(x) cscd.x = rz_read_ble32 (p + rz_offsetof (CS_CodeDirectory, x), 1) + #define READFIELD8(x) cscd.x = p[rz_offsetof (CS_CodeDirectory, x)] READFIELD (length); READFIELD (version); READFIELD (flags); @@ -751,21 +751,21 @@ static void parseCodeDirectory (RBuffer *b, int offset, int datasize) { break; } // computed cdhash - RHash *ctx = r_hash_new (true, algoType); + RzHash *ctx = rz_hash_new (true, algoType); int fofsz = cscd.length; ut8 *fofbuf = calloc (fofsz, 1); if (fofbuf) { int i; - if (r_buf_read_at (b, off, fofbuf, fofsz) != fofsz) { + if (rz_buf_read_at (b, off, fofbuf, fofsz) != fofsz) { eprintf ("Invalid cdhash offset/length values\n"); } - r_hash_do_begin (ctx, algoType); + rz_hash_do_begin (ctx, algoType); if (algoType == R_HASH_SHA1) { - r_hash_do_sha1 (ctx, fofbuf, fofsz); + rz_hash_do_sha1 (ctx, fofbuf, fofsz); } else { - r_hash_do_sha256 (ctx, fofbuf, fofsz); + rz_hash_do_sha256 (ctx, fofbuf, fofsz); } - r_hash_do_end (ctx, algoType); + rz_hash_do_end (ctx, algoType); eprintf ("ph %s @ 0x%"PFMT64x"!%d\n", hashName, off, fofsz); eprintf ("ComputedCDHash: "); for (i = 0; i < hashSize;i++) { @@ -788,14 +788,14 @@ static void parseCodeDirectory (RBuffer *b, int offset, int datasize) { } ut8 fofbuf[4096]; int fofsz = R_MIN (sizeof (fofbuf), cscd.codeLimit - fof); - r_buf_read_at (b, fof, fofbuf, sizeof (fofbuf)); - r_hash_do_begin (ctx, algoType); + rz_buf_read_at (b, fof, fofbuf, sizeof (fofbuf)); + rz_hash_do_begin (ctx, algoType); if (algoType == R_HASH_SHA1) { - r_hash_do_sha1 (ctx, fofbuf, fofsz); + rz_hash_do_sha1 (ctx, fofbuf, fofsz); } else { - r_hash_do_sha256 (ctx, fofbuf, fofsz); + rz_hash_do_sha256 (ctx, fofbuf, fofsz); } - r_hash_do_end (ctx, algoType); + rz_hash_do_end (ctx, algoType); if (memcmp (hash + idx, ctx->digest, hashSize)) { eprintf (" wx "); int i; @@ -807,7 +807,7 @@ static void parseCodeDirectory (RBuffer *b, int offset, int datasize) { } eprintf ("\n"); } - r_hash_free (ctx); + rz_hash_free (ctx); free (p); } @@ -824,25 +824,25 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { if (off > bin->size || off + sizeof (struct linkedit_data_command) > bin->size) { return false; } - len = r_buf_read_at (bin->b, off, lit, sizeof (struct linkedit_data_command)); + len = rz_buf_read_at (bin->b, off, lit, sizeof (struct linkedit_data_command)); if (len != sizeof (struct linkedit_data_command)) { bprintf ("Failed to get data while parsing LC_CODE_SIGNATURE command\n"); return false; } - link.cmd = r_read_ble32 (&lit[0], bin->big_endian); - link.cmdsize = r_read_ble32 (&lit[4], bin->big_endian); - link.dataoff = r_read_ble32 (&lit[8], bin->big_endian); - link.datasize = r_read_ble32 (&lit[12], bin->big_endian); + link.cmd = rz_read_ble32 (&lit[0], bin->big_endian); + link.cmdsize = rz_read_ble32 (&lit[4], bin->big_endian); + link.dataoff = rz_read_ble32 (&lit[8], bin->big_endian); + link.datasize = rz_read_ble32 (&lit[12], bin->big_endian); data = link.dataoff; if (data > bin->size || data + sizeof (struct super_blob_t) > bin->size) { bin->signature = (ut8 *)strdup ("Malformed entitlement"); return true; } - super.blob.magic = r_buf_read_ble32_at (bin->b, data, mach0_endian); - super.blob.length = r_buf_read_ble32_at (bin->b, data + 4, mach0_endian); - super.count = r_buf_read_ble32_at (bin->b, data + 8, mach0_endian); - char *verbose = r_sys_getenv ("RABIN2_CODESIGN_VERBOSE"); + super.blob.magic = rz_buf_read_ble32_at (bin->b, data, mach0_endian); + super.blob.length = rz_buf_read_ble32_at (bin->b, data + 4, mach0_endian); + super.count = rz_buf_read_ble32_at (bin->b, data + 8, mach0_endian); + char *verbose = rz_sys_getenv ("RABIN2_CODESIGN_VERBOSE"); bool isVerbose = false; if (verbose) { isVerbose = *verbose; @@ -859,12 +859,12 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { break; } struct blob_index_t bi; - if (r_buf_read_at (bin->b, data + 12 + (i * sizeof (struct blob_index_t)), + if (rz_buf_read_at (bin->b, data + 12 + (i * sizeof (struct blob_index_t)), (ut8*)&bi, sizeof (struct blob_index_t)) < sizeof (struct blob_index_t)) { break; } - idx.type = r_read_ble32 (&bi.type, mach0_endian); - idx.offset = r_read_ble32 (&bi.offset, mach0_endian); + idx.type = rz_read_ble32 (&bi.type, mach0_endian); + idx.offset = rz_read_ble32 (&bi.offset, mach0_endian); switch (idx.type) { case CSSLOT_ENTITLEMENTS: if (true || isVerbose) { @@ -874,16 +874,16 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { break; } struct blob_t entitlements = {0}; - entitlements.magic = r_buf_read_ble32_at (bin->b, off, mach0_endian); - entitlements.length = r_buf_read_ble32_at (bin->b, off + 4, mach0_endian); + entitlements.magic = rz_buf_read_ble32_at (bin->b, off, mach0_endian); + entitlements.length = rz_buf_read_ble32_at (bin->b, off + 4, mach0_endian); len = entitlements.length - sizeof (struct blob_t); if (len <= bin->size && len > 1) { bin->signature = calloc (1, len + 1); if (!bin->signature) { break; } - if (off + sizeof (struct blob_t) + len < r_buf_size (bin->b)) { - r_buf_read_at (bin->b, off + sizeof (struct blob_t), (ut8 *)bin->signature, len); + if (off + sizeof (struct blob_t) + len < rz_buf_size (bin->b)) { + rz_buf_read_at (bin->b, off + sizeof (struct blob_t), (ut8 *)bin->signature, len); if (len >= 0) { bin->signature[len] = '\0'; } @@ -906,11 +906,11 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { case CSSLOT_CMS_SIGNATURE: // ASN1/DER certificate if (isVerbose) { ut8 header[8] = {0}; - r_buf_read_at (bin->b, data + idx.offset, header, sizeof (header)); - ut32 length = R_MIN (UT16_MAX, r_read_ble32 (header + 4, 1)); + rz_buf_read_at (bin->b, data + idx.offset, header, sizeof (header)); + ut32 length = R_MIN (UT16_MAX, rz_read_ble32 (header + 4, 1)); ut8 *p = calloc (length, 1); if (p) { - r_buf_read_at (bin->b, data + idx.offset + 0, p, length); + rz_buf_read_at (bin->b, data + idx.offset + 0, p, length); ut32 *words = (ut32*)p; eprintf ("Magic: %x\n", words[0]); eprintf ("wtf DUMP @%d!%d\n", @@ -927,12 +927,12 @@ static bool parse_signature(struct MACH0_(obj_t) *bin, ut64 off) { case CSSLOT_REQUIREMENTS: // 2 { ut8 p[256]; - r_buf_read_at (bin->b, data + idx.offset + 16, p, sizeof (p)); + rz_buf_read_at (bin->b, data + idx.offset + 16, p, sizeof (p)); p[sizeof (p) - 1] = 0; - ut32 slot_size = r_read_ble32 (p + 8, 1); + ut32 slot_size = rz_read_ble32 (p + 8, 1); if (slot_size < sizeof (p)) { - ut32 ident_size = r_read_ble32 (p + 8, 1); - char *ident = r_str_ndup ((const char *)p + 28, ident_size); + ut32 ident_size = rz_read_ble32 (p + 8, 1); + char *ident = rz_str_ndup ((const char *)p + 28, ident_size); if (ident) { sdb_set (bin->kv, "mach0.ident", ident, 0); free (ident); @@ -977,16 +977,16 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 return false; } - len = r_buf_read_at (bin->b, off, thc, 8); + len = rz_buf_read_at (bin->b, off, thc, 8); if (len < 1) { goto wrong_read; } - bin->thread.cmd = r_read_ble32 (&thc[0], bin->big_endian); - bin->thread.cmdsize = r_read_ble32 (&thc[4], bin->big_endian); - if (r_buf_read_at (bin->b, off + sizeof (struct thread_command), tmp, 4) < 4) { + bin->thread.cmd = rz_read_ble32 (&thc[0], bin->big_endian); + bin->thread.cmdsize = rz_read_ble32 (&thc[4], bin->big_endian); + if (rz_buf_read_at (bin->b, off + sizeof (struct thread_command), tmp, 4) < 4) { goto wrong_read; } - flavor = r_read_ble32 (tmp, bin->big_endian); + flavor = rz_read_ble32 (tmp, bin->big_endian); if (len == -1) { goto wrong_read; } @@ -997,10 +997,10 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 } // TODO: use count for checks - if (r_buf_read_at (bin->b, off + sizeof (struct thread_command) + sizeof (flavor), tmp, 4) < 4) { + if (rz_buf_read_at (bin->b, off + sizeof (struct thread_command) + sizeof (flavor), tmp, 4) < 4) { goto wrong_read; } - count = r_read_ble32 (tmp, bin->big_endian); + count = rz_read_ble32 (tmp, bin->big_endian); ptr_thread = off + sizeof (struct thread_command) + sizeof (flavor) + sizeof (count); if (ptr_thread > bin->size) { @@ -1015,13 +1015,13 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 if (ptr_thread + sizeof (struct x86_thread_state32) > bin->size) { return false; } - if ((len = r_buf_fread_at (bin->b, ptr_thread, + if ((len = rz_buf_fread_at (bin->b, ptr_thread, (ut8*)&bin->thread_state.x86_32, "16i", 1)) == -1) { bprintf ("Error: read (thread state x86_32)\n"); return false; } pc = bin->thread_state.x86_32.eip; - pc_offset = ptr_thread + r_offsetof(struct x86_thread_state32, eip); + pc_offset = ptr_thread + rz_offsetof(struct x86_thread_state32, eip); arw_ptr = (ut8 *)&bin->thread_state.x86_32; arw_sz = sizeof (struct x86_thread_state32); break; @@ -1029,13 +1029,13 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 if (ptr_thread + sizeof (struct x86_thread_state64) > bin->size) { return false; } - if ((len = r_buf_fread_at (bin->b, ptr_thread, + if ((len = rz_buf_fread_at (bin->b, ptr_thread, (ut8*)&bin->thread_state.x86_64, "32l", 1)) == -1) { bprintf ("Error: read (thread state x86_64)\n"); return false; } pc = bin->thread_state.x86_64.rip; - pc_offset = ptr_thread + r_offsetof(struct x86_thread_state64, rip); + pc_offset = ptr_thread + rz_offsetof(struct x86_thread_state64, rip); arw_ptr = (ut8 *)&bin->thread_state.x86_64; arw_sz = sizeof (struct x86_thread_state64); break; @@ -1048,26 +1048,26 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 if (ptr_thread + sizeof (struct ppc_thread_state32) > bin->size) { return false; } - if ((len = r_buf_fread_at (bin->b, ptr_thread, + if ((len = rz_buf_fread_at (bin->b, ptr_thread, (ut8*)&bin->thread_state.ppc_32, bin->big_endian?"40I":"40i", 1)) == -1) { bprintf ("Error: read (thread state ppc_32)\n"); return false; } pc = bin->thread_state.ppc_32.srr0; - pc_offset = ptr_thread + r_offsetof(struct ppc_thread_state32, srr0); + pc_offset = ptr_thread + rz_offsetof(struct ppc_thread_state32, srr0); arw_ptr = (ut8 *)&bin->thread_state.ppc_32; arw_sz = sizeof (struct ppc_thread_state32); } else if (flavor == X86_THREAD_STATE64) { if (ptr_thread + sizeof (struct ppc_thread_state64) > bin->size) { return false; } - if ((len = r_buf_fread_at (bin->b, ptr_thread, + if ((len = rz_buf_fread_at (bin->b, ptr_thread, (ut8*)&bin->thread_state.ppc_64, bin->big_endian?"34LI3LI":"34li3li", 1)) == -1) { bprintf ("Error: read (thread state ppc_64)\n"); return false; } pc = bin->thread_state.ppc_64.srr0; - pc_offset = ptr_thread + r_offsetof(struct ppc_thread_state64, srr0); + pc_offset = ptr_thread + rz_offsetof(struct ppc_thread_state64, srr0); arw_ptr = (ut8 *)&bin->thread_state.ppc_64; arw_sz = sizeof (struct ppc_thread_state64); } @@ -1076,13 +1076,13 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 if (ptr_thread + sizeof (struct arm_thread_state32) > bin->size) { return false; } - if ((len = r_buf_fread_at (bin->b, ptr_thread, + if ((len = rz_buf_fread_at (bin->b, ptr_thread, (ut8*)&bin->thread_state.arm_32, bin->big_endian?"17I":"17i", 1)) == -1) { bprintf ("Error: read (thread state arm)\n"); return false; } pc = bin->thread_state.arm_32.r15; - pc_offset = ptr_thread + r_offsetof (struct arm_thread_state32, r15); + pc_offset = ptr_thread + rz_offsetof (struct arm_thread_state32, r15); arw_ptr = (ut8 *)&bin->thread_state.arm_32; arw_sz = sizeof (struct arm_thread_state32); break; @@ -1090,13 +1090,13 @@ static int parse_thread(struct MACH0_(obj_t) *bin, struct load_command *lc, ut64 if (ptr_thread + sizeof (struct arm_thread_state64) > bin->size) { return false; } - if ((len = r_buf_fread_at(bin->b, ptr_thread, + if ((len = rz_buf_fread_at(bin->b, ptr_thread, (ut8*)&bin->thread_state.arm_64, bin->big_endian?"34LI1I":"34Li1i", 1)) == -1) { bprintf ("Error: read (thread state arm)\n"); return false; } - pc = r_read_be64 (&bin->thread_state.arm_64.pc); - pc_offset = ptr_thread + r_offsetof (struct arm_thread_state64, pc); + pc = rz_read_be64 (&bin->thread_state.arm_64.pc); + pc_offset = ptr_thread + rz_offsetof (struct arm_thread_state64, pc); arw_ptr = (ut8*)&bin->thread_state.arm_64; arw_sz = sizeof (struct arm_thread_state64); break; @@ -1142,15 +1142,15 @@ static int parse_function_starts (struct MACH0_(obj_t) *bin, ut64 off) { " LC_FUNCTION_STARTS command\n"); } bin->func_start = NULL; - len = r_buf_read_at (bin->b, off, sfc, sizeof (struct linkedit_data_command)); + len = rz_buf_read_at (bin->b, off, sfc, sizeof (struct linkedit_data_command)); if (len < 1) { bprintf ("Failed to get data while parsing" " LC_FUNCTION_STARTS command\n"); } - fc.cmd = r_read_ble32 (&sfc[0], bin->big_endian); - fc.cmdsize = r_read_ble32 (&sfc[4], bin->big_endian); - fc.dataoff = r_read_ble32 (&sfc[8], bin->big_endian); - fc.datasize = r_read_ble32 (&sfc[12], bin->big_endian); + fc.cmd = rz_read_ble32 (&sfc[0], bin->big_endian); + fc.cmdsize = rz_read_ble32 (&sfc[4], bin->big_endian); + fc.dataoff = rz_read_ble32 (&sfc[8], bin->big_endian); + fc.datasize = rz_read_ble32 (&sfc[12], bin->big_endian); if ((int)fc.datasize > 0) { ut8 *buf = calloc (1, fc.datasize + 1); @@ -1165,7 +1165,7 @@ static int parse_function_starts (struct MACH0_(obj_t) *bin, ut64 off) { "LC_FUNCTION_STARTS command\n"); return false; } - len = r_buf_read_at (bin->b, fc.dataoff, buf, fc.datasize); + len = rz_buf_read_at (bin->b, fc.dataoff, buf, fc.datasize); if (len != fc.datasize) { free (buf); bprintf ("Failed to get data while parsing" @@ -1197,17 +1197,17 @@ static int parse_dylib(struct MACH0_(obj_t) *bin, ut64 off) { return false; } bin->libs = relibs; - len = r_buf_read_at (bin->b, off, sdl, sizeof (struct dylib_command)); + len = rz_buf_read_at (bin->b, off, sdl, sizeof (struct dylib_command)); if (len < 1) { bprintf ("Error: read (dylib)\n"); return false; } - dl.cmd = r_read_ble32 (&sdl[0], bin->big_endian); - dl.cmdsize = r_read_ble32 (&sdl[4], bin->big_endian); - dl.dylib.name = r_read_ble32 (&sdl[8], bin->big_endian); - dl.dylib.timestamp = r_read_ble32 (&sdl[12], bin->big_endian); - dl.dylib.current_version = r_read_ble32 (&sdl[16], bin->big_endian); - dl.dylib.compatibility_version = r_read_ble32 (&sdl[20], bin->big_endian); + dl.cmd = rz_read_ble32 (&sdl[0], bin->big_endian); + dl.cmdsize = rz_read_ble32 (&sdl[4], bin->big_endian); + dl.dylib.name = rz_read_ble32 (&sdl[8], bin->big_endian); + dl.dylib.timestamp = rz_read_ble32 (&sdl[12], bin->big_endian); + dl.dylib.current_version = rz_read_ble32 (&sdl[16], bin->big_endian); + dl.dylib.compatibility_version = rz_read_ble32 (&sdl[20], bin->big_endian); if (off + dl.dylib.name > bin->size ||\ off + dl.dylib.name + R_BIN_MACH0_STRING_LENGTH > bin->size) { @@ -1215,7 +1215,7 @@ static int parse_dylib(struct MACH0_(obj_t) *bin, ut64 off) { } memset (bin->libs[lib], 0, R_BIN_MACH0_STRING_LENGTH); - len = r_buf_read_at (bin->b, off + dl.dylib.name, + len = rz_buf_read_at (bin->b, off + dl.dylib.name, (ut8*)bin->libs[lib], R_BIN_MACH0_STRING_LENGTH); bin->libs[lib][R_BIN_MACH0_STRING_LENGTH - 1] = 0; if (len < 1) { @@ -1479,7 +1479,7 @@ static bool parse_chained_fixups(struct MACH0_(obj_t) *bin, ut32 offset, ut32 si if (size < sizeof (header)) { return false; } - if (r_buf_fread_at (bin->b, offset, (ut8 *)&header, "7i", 1) != sizeof (header)) { + if (rz_buf_fread_at (bin->b, offset, (ut8 *)&header, "7i", 1) != sizeof (header)) { return false; } if (header.fixups_version > 0) { @@ -1491,10 +1491,10 @@ static bool parse_chained_fixups(struct MACH0_(obj_t) *bin, ut32 offset, ut32 si return false; } ut32 segs_count; - if ((segs_count = r_buf_read_le32_at (bin->b, starts_at)) == UT32_MAX) { + if ((segs_count = rz_buf_read_le32_at (bin->b, starts_at)) == UT32_MAX) { return false; } - bin->chained_starts = R_NEWS0 (struct r_dyld_chained_starts_in_segment *, segs_count); + bin->chained_starts = R_NEWS0 (struct rz_dyld_chained_starts_in_segment *, segs_count); if (!bin->chained_starts) { return false; } @@ -1502,19 +1502,19 @@ static bool parse_chained_fixups(struct MACH0_(obj_t) *bin, ut32 offset, ut32 si ut64 cursor = starts_at + sizeof (ut32); for (i = 0; i < segs_count; i++) { ut32 seg_off; - if ((seg_off = r_buf_read_le32_at (bin->b, cursor)) == UT32_MAX || !seg_off) { + if ((seg_off = rz_buf_read_le32_at (bin->b, cursor)) == UT32_MAX || !seg_off) { cursor += sizeof (ut32); continue; } if (i >= bin->nsegs) { break; } - struct r_dyld_chained_starts_in_segment *cur_seg = R_NEW0 (struct r_dyld_chained_starts_in_segment); + struct rz_dyld_chained_starts_in_segment *cur_seg = R_NEW0 (struct rz_dyld_chained_starts_in_segment); if (!cur_seg) { return false; } bin->chained_starts[i] = cur_seg; - if (r_buf_fread_at (bin->b, starts_at + seg_off, (ut8 *)cur_seg, "isslis", 1) != 22) { + if (rz_buf_fread_at (bin->b, starts_at + seg_off, (ut8 *)cur_seg, "isslis", 1) != 22) { return false; } if (cur_seg->page_count > 0) { @@ -1522,7 +1522,7 @@ static bool parse_chained_fixups(struct MACH0_(obj_t) *bin, ut32 offset, ut32 si if (!page_start) { return false; } - if (r_buf_fread_at (bin->b, starts_at + seg_off + 22, (ut8 *)page_start, "s", cur_seg->page_count) + if (rz_buf_fread_at (bin->b, starts_at + seg_off + 22, (ut8 *)page_start, "s", cur_seg->page_count) != cur_seg->page_count * 2) { return false; } @@ -1541,7 +1541,7 @@ static bool reconstruct_chained_fixup(struct MACH0_(obj_t) *bin) { if (!bin->nsegs) { return false; } - bin->chained_starts = R_NEWS0 (struct r_dyld_chained_starts_in_segment *, bin->nsegs); + bin->chained_starts = R_NEWS0 (struct rz_dyld_chained_starts_in_segment *, bin->nsegs); if (!bin->chained_starts) { return false; } @@ -1564,12 +1564,12 @@ static bool reconstruct_chained_fixup(struct MACH0_(obj_t) *bin) { if (!opcodes) { return false; } - if (r_buf_read_at (bin->b, bin->dyld_info->bind_off, opcodes, bind_size) != bind_size) { + if (rz_buf_read_at (bin->b, bin->dyld_info->bind_off, opcodes, bind_size) != bind_size) { bprintf ("Error: read (dyld_info bind) at 0x%08"PFMT64x"\n", (ut64)(size_t)bin->dyld_info->bind_off); R_FREE (opcodes); return false; } - struct r_dyld_chained_starts_in_segment *cur_seg = NULL; + struct rz_dyld_chained_starts_in_segment *cur_seg = NULL; size_t cur_seg_idx = 0; ut8 *end; bool done = false; @@ -1592,7 +1592,7 @@ static bool reconstruct_chained_fixup(struct MACH0_(obj_t) *bin) { cur_seg_idx = seg_idx; cur_seg = bin->chained_starts[seg_idx]; if (!cur_seg) { - cur_seg = R_NEW0 (struct r_dyld_chained_starts_in_segment); + cur_seg = R_NEW0 (struct rz_dyld_chained_starts_in_segment); if (!cur_seg) { break; } @@ -1636,7 +1636,7 @@ static bool reconstruct_chained_fixup(struct MACH0_(obj_t) *bin) { } break; case BIND_OPCODE_SET_ADDEND_SLEB: - r_sleb128 ((const ut8 **)&p, end); + rz_sleb128 ((const ut8 **)&p, end); break; case BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: seg_idx = imm; @@ -1700,13 +1700,13 @@ static int init_items(struct MACH0_(obj_t) *bin) { bprintf ("mach0: out of bounds command\n"); return false; } - len = r_buf_read_at (bin->b, off, loadc, sizeof (struct load_command)); + len = rz_buf_read_at (bin->b, off, loadc, sizeof (struct load_command)); if (len < 1) { bprintf ("Error: read (lc) at 0x%08"PFMT64x"\n", off); return false; } - lc.cmd = r_read_ble32 (&loadc[0], bin->big_endian); - lc.cmdsize = r_read_ble32 (&loadc[4], bin->big_endian); + lc.cmd = rz_read_ble32 (&loadc[0], bin->big_endian); + lc.cmdsize = rz_read_ble32 (&loadc[4], bin->big_endian); if (lc.cmdsize < 1 || off + lc.cmdsize > bin->size) { bprintf ("Warning: mach0_header %d = cmdsize<1. (0x%llx vs 0x%llx)\n", i, @@ -1786,11 +1786,11 @@ static int init_items(struct MACH0_(obj_t) *bin) { bprintf ("UUID out of bounds\n"); return false; } - if (r_buf_fread_at (bin->b, off, (ut8*)&uc, "24c", 1) != -1) { + if (rz_buf_fread_at (bin->b, off, (ut8*)&uc, "24c", 1) != -1) { char key[128]; char val[128]; snprintf (key, sizeof (key)-1, "uuid.%d", bin->uuidn++); - r_hex_bin2str ((ut8*)&uc.uuid, 16, val); + rz_hex_bin2str ((ut8*)&uc.uuid, 16, val); sdb_set (bin->kv, key, val, 0); //for (i=0;i<16; i++) bprintf ("%02x%c", uc.uuid[i], (i==15)?'\n':'-'); } @@ -1807,12 +1807,12 @@ static int init_items(struct MACH0_(obj_t) *bin) { bprintf ("encryption info out of bounds\n"); return false; } - if (r_buf_read_at (bin->b, off, seic, sizeof (struct MACH0_(encryption_info_command))) != -1) { - eic.cmd = r_read_ble32 (&seic[0], bin->big_endian); - eic.cmdsize = r_read_ble32 (&seic[4], bin->big_endian); - eic.cryptoff = r_read_ble32 (&seic[8], bin->big_endian); - eic.cryptsize = r_read_ble32 (&seic[12], bin->big_endian); - eic.cryptid = r_read_ble32 (&seic[16], bin->big_endian); + if (rz_buf_read_at (bin->b, off, seic, sizeof (struct MACH0_(encryption_info_command))) != -1) { + eic.cmd = rz_read_ble32 (&seic[0], bin->big_endian); + eic.cmdsize = rz_read_ble32 (&seic[4], bin->big_endian); + eic.cryptoff = rz_read_ble32 (&seic[8], bin->big_endian); + eic.cryptsize = rz_read_ble32 (&seic[12], bin->big_endian); + eic.cryptid = rz_read_ble32 (&seic[16], bin->big_endian); bin->has_crypto = eic.cryptid; sdb_set (bin->kv, "crypto", "true", 0); @@ -1833,18 +1833,18 @@ static int init_items(struct MACH0_(obj_t) *bin) { bprintf ("Warning: Cannot parse dylinker command\n"); return false; } - if (r_buf_read_at (bin->b, off, sdy, sizeof (struct dylinker_command)) == -1) { + if (rz_buf_read_at (bin->b, off, sdy, sizeof (struct dylinker_command)) == -1) { bprintf ("Warning: read (LC_DYLD_INFO) at 0x%08"PFMT64x"\n", off); } else { - dy.cmd = r_read_ble32 (&sdy[0], bin->big_endian); - dy.cmdsize = r_read_ble32 (&sdy[4], bin->big_endian); - dy.name = r_read_ble32 (&sdy[8], bin->big_endian); + dy.cmd = rz_read_ble32 (&sdy[0], bin->big_endian); + dy.cmdsize = rz_read_ble32 (&sdy[4], bin->big_endian); + dy.name = rz_read_ble32 (&sdy[8], bin->big_endian); int len = dy.cmdsize; char *buf = malloc (len+1); if (buf) { // wtf @ off + 0xc ? - r_buf_read_at (bin->b, off + 0xc, (ut8*)buf, len); + rz_buf_read_at (bin->b, off + 0xc, (ut8*)buf, len); buf[len] = 0; free (bin->intrp); bin->intrp = buf; @@ -1869,9 +1869,9 @@ static int init_items(struct MACH0_(obj_t) *bin) { bprintf ("invalid command size for main\n"); return false; } - r_buf_read_at (bin->b, off + 8, sep, 2 * sizeof (ut64)); - ep.eo = r_read_ble64 (&sep[0], bin->big_endian); - ep.ss = r_read_ble64 (&sep[8], bin->big_endian); + rz_buf_read_at (bin->b, off + 8, sep, 2 * sizeof (ut64)); + ep.eo = rz_read_ble64 (&sep[0], bin->big_endian); + ep.ss = rz_read_ble64 (&sep[8], bin->big_endian); bin->entry = ep.eo; bin->main_cmd = lc; @@ -1918,22 +1918,22 @@ static int init_items(struct MACH0_(obj_t) *bin) { R_FREE (bin->dyld_info); return false; } - if (r_buf_read_at (bin->b, off, dyldi, sizeof (struct dyld_info_command)) == -1) { + if (rz_buf_read_at (bin->b, off, dyldi, sizeof (struct dyld_info_command)) == -1) { R_FREE (bin->dyld_info); bprintf ("Error: read (LC_DYLD_INFO) at 0x%08"PFMT64x"\n", off); } else { - bin->dyld_info->cmd = r_read_ble32 (&dyldi[0], bin->big_endian); - bin->dyld_info->cmdsize = r_read_ble32 (&dyldi[4], bin->big_endian); - bin->dyld_info->rebase_off = r_read_ble32 (&dyldi[8], bin->big_endian); - bin->dyld_info->rebase_size = r_read_ble32 (&dyldi[12], bin->big_endian); - bin->dyld_info->bind_off = r_read_ble32 (&dyldi[16], bin->big_endian); - bin->dyld_info->bind_size = r_read_ble32 (&dyldi[20], bin->big_endian); - bin->dyld_info->weak_bind_off = r_read_ble32 (&dyldi[24], bin->big_endian); - bin->dyld_info->weak_bind_size = r_read_ble32 (&dyldi[28], bin->big_endian); - bin->dyld_info->lazy_bind_off = r_read_ble32 (&dyldi[32], bin->big_endian); - bin->dyld_info->lazy_bind_size = r_read_ble32 (&dyldi[36], bin->big_endian); - bin->dyld_info->export_off = r_read_ble32 (&dyldi[40], bin->big_endian); - bin->dyld_info->export_size = r_read_ble32 (&dyldi[44], bin->big_endian); + bin->dyld_info->cmd = rz_read_ble32 (&dyldi[0], bin->big_endian); + bin->dyld_info->cmdsize = rz_read_ble32 (&dyldi[4], bin->big_endian); + bin->dyld_info->rebase_off = rz_read_ble32 (&dyldi[8], bin->big_endian); + bin->dyld_info->rebase_size = rz_read_ble32 (&dyldi[12], bin->big_endian); + bin->dyld_info->bind_off = rz_read_ble32 (&dyldi[16], bin->big_endian); + bin->dyld_info->bind_size = rz_read_ble32 (&dyldi[20], bin->big_endian); + bin->dyld_info->weak_bind_off = rz_read_ble32 (&dyldi[24], bin->big_endian); + bin->dyld_info->weak_bind_size = rz_read_ble32 (&dyldi[28], bin->big_endian); + bin->dyld_info->lazy_bind_off = rz_read_ble32 (&dyldi[32], bin->big_endian); + bin->dyld_info->lazy_bind_size = rz_read_ble32 (&dyldi[36], bin->big_endian); + bin->dyld_info->export_off = rz_read_ble32 (&dyldi[40], bin->big_endian); + bin->dyld_info->export_size = rz_read_ble32 (&dyldi[44], bin->big_endian); } } } @@ -1972,13 +1972,13 @@ static int init_items(struct MACH0_(obj_t) *bin) { bool has_chained_fixups = false; for (i = 0, off = sizeof (struct MACH0_(mach_header)) + bin->header_at; \ i < bin->hdr.ncmds; i++, off += lc.cmdsize) { - len = r_buf_read_at (bin->b, off, loadc, sizeof (struct load_command)); + len = rz_buf_read_at (bin->b, off, loadc, sizeof (struct load_command)); if (len < 1) { bprintf ("Error: read (lc) at 0x%08"PFMT64x"\n", off); return false; } - lc.cmd = r_read_ble32 (&loadc[0], bin->big_endian); - lc.cmdsize = r_read_ble32 (&loadc[4], bin->big_endian); + lc.cmd = rz_read_ble32 (&loadc[0], bin->big_endian); + lc.cmdsize = rz_read_ble32 (&loadc[4], bin->big_endian); if (lc.cmdsize < 1 || off + lc.cmdsize > bin->size) { bprintf ("Warning: mach0_header %d = cmdsize<1. (0x%llx vs 0x%llx)\n", i, @@ -1999,19 +1999,19 @@ static int init_items(struct MACH0_(obj_t) *bin) { sdb_set (bin->kv, sdb_fmt ("mach0_cmd_%d.cmd", i), "data_in_code", 0); if (bin->verbose) { ut8 buf[8]; - r_buf_read_at (bin->b, off + 8, buf, sizeof (buf)); - ut32 dataoff = r_read_ble32 (buf, bin->big_endian); - ut32 datasize= r_read_ble32 (buf + 4, bin->big_endian); + rz_buf_read_at (bin->b, off + 8, buf, sizeof (buf)); + ut32 dataoff = rz_read_ble32 (buf, bin->big_endian); + ut32 datasize= rz_read_ble32 (buf + 4, bin->big_endian); eprintf ("data-in-code at 0x%x size %d\n", dataoff, datasize); ut8 *db = (ut8*)malloc (datasize); if (db) { - r_buf_read_at (bin->b, dataoff, db, datasize); + rz_buf_read_at (bin->b, dataoff, db, datasize); // TODO table of non-instructions regions in __text int j; for (j = 0; j < datasize; j += 8) { - ut32 dw = r_read_ble32 (db + j, bin->big_endian); - // int kind = r_read_ble16 (db + i + 4 + 2, bin->big_endian); - int len = r_read_ble16 (db + j + 4, bin->big_endian); + ut32 dw = rz_read_ble32 (db + j, bin->big_endian); + // int kind = rz_read_ble16 (db + i + 4 + 2, bin->big_endian); + int len = rz_read_ble16 (db + j + 4, bin->big_endian); ut64 va = offset_to_vaddr(bin, dw); // eprintf ("# 0x%d -> 0x%x\n", dw, va); // eprintf ("0x%x kind %d len %d\n", dw, kind, len); @@ -2023,17 +2023,17 @@ static int init_items(struct MACH0_(obj_t) *bin) { case LC_DYLD_EXPORTS_TRIE: if (bin->verbose) { ut8 buf[8]; - r_buf_read_at (bin->b, off + 8, buf, sizeof (buf)); - ut32 dataoff = r_read_ble32 (buf, bin->big_endian); - ut32 datasize= r_read_ble32 (buf + 4, bin->big_endian); + rz_buf_read_at (bin->b, off + 8, buf, sizeof (buf)); + ut32 dataoff = rz_read_ble32 (buf, bin->big_endian); + ut32 datasize= rz_read_ble32 (buf + 4, bin->big_endian); eprintf ("exports trie at 0x%x size %d\n", dataoff, datasize); } break; case LC_DYLD_CHAINED_FIXUPS: { ut8 buf[8]; - if (r_buf_read_at (bin->b, off + 8, buf, sizeof (buf)) == sizeof (buf)) { - ut32 dataoff = r_read_ble32 (buf, bin->big_endian); - ut32 datasize= r_read_ble32 (buf + 4, bin->big_endian); + if (rz_buf_read_at (bin->b, off + 8, buf, sizeof (buf)) == sizeof (buf)) { + ut32 dataoff = rz_read_ble32 (buf, bin->big_endian); + ut32 datasize= rz_read_ble32 (buf + 4, bin->big_endian); if (bin->verbose) { eprintf ("chained fixups at 0x%x size %d\n", dataoff, datasize); } @@ -2103,13 +2103,13 @@ void *MACH0_(mach0_free)(struct MACH0_(obj_t) *mo) { } free (mo->chained_starts); } - r_buf_free (mo->b); + rz_buf_free (mo->b); free (mo); return NULL; } void MACH0_(opts_set_default)(struct MACH0_(opts_t) *options, RBinFile *bf) { - r_return_if_fail (options && bf && bf->rbin); + rz_return_if_fail (options && bf && bf->rbin); options->header_at = 0; options->verbose = bf->rbin->verbose; } @@ -2139,13 +2139,13 @@ struct MACH0_(obj_t) *MACH0_(mach0_new)(const char *file, struct MACH0_(opts_t) } bin->file = file; size_t binsz; - ut8 *buf = (ut8 *)r_file_slurp (file, &binsz); + ut8 *buf = (ut8 *)rz_file_slurp (file, &binsz); bin->size = binsz; if (!buf) { return MACH0_(mach0_free)(bin); } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { free (buf); return MACH0_(mach0_free)(bin); } @@ -2161,13 +2161,13 @@ struct MACH0_(obj_t) *MACH0_(mach0_new)(const char *file, struct MACH0_(opts_t) } struct MACH0_(obj_t) *MACH0_(new_buf)(RBuffer *buf, struct MACH0_(opts_t) *options) { - r_return_val_if_fail (buf, NULL); + rz_return_val_if_fail (buf, NULL); struct MACH0_(obj_t) *bin = R_NEW0 (struct MACH0_(obj_t)); if (bin) { - bin->b = r_buf_ref (buf); + bin->b = rz_buf_ref (buf); bin->main_addr = UT64_MAX; bin->kv = sdb_new (NULL, "bin.mach0", 0); - bin->size = r_buf_size (bin->b); + bin->size = rz_buf_size (bin->b); if (options) { bin->verbose = options->verbose; bin->header_at = options->header_at; @@ -2211,9 +2211,9 @@ static bool __isDataSection(RBinSection *sect) { return false; } -RList *MACH0_(get_segments)(RBinFile *bf) { +RzList *MACH0_(get_segments)(RBinFile *bf) { struct MACH0_(obj_t) *bin = bf->o->bin_obj; - RList *list = r_list_newf ((RListFree)r_bin_section_free); + RzList *list = rz_list_newf ((RzListFree)rz_bin_section_free); size_t i, j; /* for core files */ @@ -2224,7 +2224,7 @@ RList *MACH0_(get_segments)(RBinFile *bf) { if (!seg->initprot) { continue; } - RBinSection *s = r_bin_section_new (NULL); + RBinSection *s = rz_bin_section_new (NULL); if (!s) { break; } @@ -2234,12 +2234,12 @@ RList *MACH0_(get_segments)(RBinFile *bf) { s->paddr = seg->fileoff; s->paddr += bf->o->boffset; //TODO s->flags = seg->flags; - s->name = r_str_ndup (seg->segname, 16); + s->name = rz_str_ndup (seg->segname, 16); s->is_segment = true; - r_str_filter (s->name, -1); + rz_str_filter (s->name, -1); s->perm = prot2perm (seg->initprot); s->add = true; - r_list_append (list, s); + rz_list_append (list, s); } } if (bin->nsects > 0) { @@ -2265,9 +2265,9 @@ RList *MACH0_(get_segments)(RBinFile *bf) { break; } } - char *section_name = r_str_ndup (bin->sects[i].sectname, 16); - char *segment_name = r_str_newf ("%d.%s", i, bin->segs[segment_index].segname); - s->name = r_str_newf ("%s.%s", segment_name, section_name); + char *section_name = rz_str_ndup (bin->sects[i].sectname, 16); + char *segment_name = rz_str_newf ("%d.%s", i, bin->segs[segment_index].segname); + s->name = rz_str_newf ("%s.%s", segment_name, section_name); s->is_data = __isDataSection (s); if (strstr (section_name, "interpos") || strstr (section_name, "__mod_")) { #if R_BIN_MACH064 @@ -2275,9 +2275,9 @@ RList *MACH0_(get_segments)(RBinFile *bf) { #else const int ws = 4; #endif - s->format = r_str_newf ("Cd %d[%"PFMT64d"]", ws, s->vsize / ws); + s->format = rz_str_newf ("Cd %d[%"PFMT64d"]", ws, s->vsize / ws); } - r_list_append (list, s); + rz_list_append (list, s); free (segment_name); free (section_name); } @@ -2308,9 +2308,9 @@ struct section_t *MACH0_(get_sections)(struct MACH0_(obj_t) *bin) { sections[i].vsize = seg->vmsize; sections[i].align = 4096; sections[i].flags = seg->flags; - r_str_ncpy (sectname, seg->segname, 16); + rz_str_ncpy (sectname, seg->segname, 16); sectname[16] = 0; - r_str_filter (sectname, -1); + rz_str_filter (sectname, -1); // hack to support multiple sections with same name sections[i].perm = prot2perm (seg->initprot); sections[i].last = 0; @@ -2336,8 +2336,8 @@ struct section_t *MACH0_(get_sections)(struct MACH0_(obj_t) *bin) { sections[i].vsize = (ut64)bin->sects[i].size; sections[i].align = bin->sects[i].align; sections[i].flags = bin->sects[i].flags; - r_str_ncpy (sectname, bin->sects[i].sectname, 17); - r_str_filter (sectname, -1); + rz_str_ncpy (sectname, bin->sects[i].sectname, 17); + rz_str_filter (sectname, -1); // hack to support multiple sections with same name // snprintf (segname, sizeof (segname), "%d", i); // wtf memcpy (raw_segname, bin->sects[i].segname, 16); @@ -2431,7 +2431,7 @@ static bool parse_import_stub(struct MACH0_(obj_t) *bin, struct symbol_t *symbol static int inSymtab(HtPP *hash, const char *name, ut64 addr) { bool found = false; - char *key = r_str_newf ("%"PFMT64x".%s", addr, name); + char *key = rz_str_newf ("%"PFMT64x".%s", addr, name); ht_pp_find (hash, key, &found); if (found) { free (key); @@ -2455,9 +2455,9 @@ static char *get_name(struct MACH0_(obj_t) *mo, ut32 stridx, bool filter) { } } if (len > 0) { - char *res = r_str_ndup (symstr, len); + char *res = rz_str_ndup (symstr, len); if (filter) { - r_str_filter (res, -1); + rz_str_filter (res, -1); } return res; } @@ -2466,7 +2466,7 @@ static char *get_name(struct MACH0_(obj_t) *mo, ut32 stridx, bool filter) { static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, void * ctx) { #define ULEB(at) read_uleb128 (&p, end) - r_return_val_if_fail (bin, 0); + rz_return_val_if_fail (bin, 0); if (!bin->dyld_info) { return 0; } @@ -2474,7 +2474,7 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo size_t count = 0; ut8 *p = NULL; ut8 * trie = NULL; - RList * states = NULL; + RzList * states = NULL; ut64 size = bin->dyld_info->export_size; if (!size) { return count; @@ -2485,11 +2485,11 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo } ut8 * end = trie + size; - if (r_buf_read_at (bin->b, bin->dyld_info->export_off, trie, bin->dyld_info->export_size) != size) { + if (rz_buf_read_at (bin->b, bin->dyld_info->export_off, trie, bin->dyld_info->export_size) != size) { goto beach; } - states = r_list_newf ((RListFree)free); + states = rz_list_newf ((RzListFree)free); if (!states) { goto beach; } @@ -2501,10 +2501,10 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo root->node = trie; root->i = 0; root->label = NULL; - r_list_push (states, root); + rz_list_push (states, root); do { - RTrieState * state = r_list_get_top (states); + RTrieState * state = rz_list_get_top (states); p = state->node; ut64 len = ULEB (); if (len == UT64_MAX) { @@ -2537,20 +2537,20 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo } if (iterator && !isReexport) { char * name = NULL; - RListIter *iter; + RzListIter *iter; RTrieState *s; - r_list_foreach (states, iter, s) { + rz_list_foreach (states, iter, s) { if (!s->label) { continue; } - name = r_str_append (name, s->label); + name = rz_str_append (name, s->label); } if (name == NULL) { eprintf ("malformed export trie\n"); goto beach; } if (hasResolver) { - char * stub_name = r_str_newf ("stub.%s", name); + char * stub_name = rz_str_newf ("stub.%s", name); iterator (bin, stub_name, flags, offset, ctx); iterator (bin, name, flags, resolver, ctx); R_FREE (stub_name); @@ -2571,7 +2571,7 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo goto beach; } if (state->i == child_count) { - r_list_pop (states); + rz_list_pop (states); continue; } if (!state->next_child) { @@ -2602,9 +2602,9 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo } { // avoid loops - RListIter *it; + RzListIter *it; RTrieState *s; - r_list_foreach (states, it, s) { + rz_list_foreach (states, it, s) { if (s->node == next->node) { eprintf ("malformed export trie\n"); R_FREE (next); @@ -2615,18 +2615,18 @@ static int walk_exports(struct MACH0_(obj_t) *bin, RExportsIterator iterator, vo next->i = 0; state->i++; state->next_child = p; - r_list_push (states, next); - } while (r_list_length (states)); + rz_list_push (states, next); + } while (rz_list_length (states)); #undef ULEB beach: - r_list_free (states); + rz_list_free (states); R_FREE (trie); return count; } static void fill_exports_list(struct MACH0_(obj_t) *bin, const char *name, ut64 flags, ut64 offset, void * ctx) { - RList *list = (RList*) ctx; + RzList *list = (RzList*) ctx; RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { return; @@ -2636,22 +2636,22 @@ static void fill_exports_list(struct MACH0_(obj_t) *bin, const char *name, ut64 sym->type = "EXT"; sym->name = strdup (name); sym->bind = R_BIN_BIND_GLOBAL_STR; - r_list_append (list, sym); + rz_list_append (list, sym); } -// TODO: Return RList // 2x speedup -const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { - static RList * cache = NULL; // XXX DONT COMMIT WITH THIS +// TODO: Return RzList // 2x speedup +const RzList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { + static RzList * cache = NULL; // XXX DONT COMMIT WITH THIS struct symbol_t *symbols; size_t j, s, symbols_size, symbols_count; ut32 to, from; size_t i; - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); if (cache) { return cache; } - RList *list = r_list_newf ((RListFree)r_bin_symbol_free); + RzList *list = rz_list_newf ((RzListFree)rz_bin_symbol_free); cache = list; HtPP *hash = ht_pp_new0 (); @@ -2660,10 +2660,10 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { } walk_exports (bin, fill_exports_list, list); - if (r_list_length (list)) { - RListIter *it; + if (rz_list_length (list)) { + RzListIter *it; RBinSymbol *s; - r_list_foreach (list, it, s) { + rz_list_foreach (list, it, s) { inSymtab (hash, s->name, s->vaddr); } } @@ -2745,10 +2745,10 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { } } } else { - sym->name = r_str_newf ("unk%d", i); + sym->name = rz_str_newf ("unk%d", i); } if (!inSymtab (hash, sym->name, sym->vaddr)) { - r_list_append (list, sym); + rz_list_append (list, sym); } } } @@ -2766,10 +2766,10 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { sym->paddr = symbol.offset; sym->name = symbol.name; if (!sym->name) { - sym->name = r_str_newf ("unk%d", i); + sym->name = rz_str_newf ("unk%d", i); } sym->is_imported = symbol.is_imported; - r_list_append (list, sym); + rz_list_append (list, sym); } } @@ -2794,7 +2794,7 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { if (sym_name) { sym->name = sym_name; if (inSymtab (hash, sym->name, sym->vaddr)) { - r_bin_symbol_free (sym); + rz_bin_symbol_free (sym); continue; } if (!bin->main_addr || bin->main_addr == UT64_MAX) { @@ -2808,9 +2808,9 @@ const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin) { } } } else { - sym->name = r_str_newf ("unk%d", i); + sym->name = rz_str_newf ("unk%d", i); } - r_list_append (list, sym); + rz_list_append (list, sym); j++; } } @@ -2849,7 +2849,7 @@ const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) { return NULL; } - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); int n_exports = walk_exports (bin, NULL, NULL); symbols_count = n_exports; @@ -2972,7 +2972,7 @@ const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin) { if (sym_name) { symbols[j].name = sym_name; } else { - symbols[j].name = r_str_newf ("entry%d", i); + symbols[j].name = rz_str_newf ("entry%d", i); } symbols[j].last = 0; if (inSymtab (hash, symbols[j].name, symbols[j].addr)) { @@ -3070,7 +3070,7 @@ static int parse_import_ptr(struct MACH0_(obj_t) *bin, struct reloc_t *reloc, in } struct import_t *MACH0_(get_imports)(struct MACH0_(obj_t) *bin) { - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); int i, j, idx, stridx; if (!bin->sects || !bin->symtab || !bin->symstr || !bin->indirectsyms) { @@ -3095,7 +3095,7 @@ struct import_t *MACH0_(get_imports)(struct MACH0_(obj_t) *bin) { stridx = bin->symtab[idx].n_strx; char *imp_name = get_name (bin, stridx, false); if (imp_name) { - r_str_ncpy (imports[j].name, imp_name, R_BIN_MACH0_STRING_LENGTH); + rz_str_ncpy (imports[j].name, imp_name, R_BIN_MACH0_STRING_LENGTH); free (imp_name); } else { //imports[j].name[0] = 0; @@ -3123,7 +3123,7 @@ static int reloc_comparator(struct reloc_t *a, struct reloc_t *b) { return a->addr - b->addr; } -static void parse_relocation_info(struct MACH0_(obj_t) *bin, RSkipList * relocs, ut32 offset, ut32 num) { +static void parse_relocation_info(struct MACH0_(obj_t) *bin, RzSkipList * relocs, ut32 offset, ut32 num) { if (!num || !offset || (st32)num < 0) { return; } @@ -3134,7 +3134,7 @@ static void parse_relocation_info(struct MACH0_(obj_t) *bin, RSkipList * relocs, return; } - if (r_buf_read_at (bin->b, offset, (ut8 *) info, total_size) < total_size) { + if (rz_buf_read_at (bin->b, offset, (ut8 *) info, total_size) < total_size) { free (info); return; } @@ -3142,7 +3142,7 @@ static void parse_relocation_info(struct MACH0_(obj_t) *bin, RSkipList * relocs, size_t i; for (i = 0; i < num; i++) { struct relocation_info a_info = info[i]; - ut32 sym_num = a_info.r_symbolnum; + ut32 sym_num = a_info.rz_symbolnum; if (sym_num > bin->nsymtab) { continue; } @@ -3158,15 +3158,15 @@ static void parse_relocation_info(struct MACH0_(obj_t) *bin, RSkipList * relocs, return; } - reloc->addr = offset_to_vaddr (bin, a_info.r_address); - reloc->offset = a_info.r_address; + reloc->addr = offset_to_vaddr (bin, a_info.rz_address); + reloc->offset = a_info.rz_address; reloc->ord = sym_num; - reloc->type = a_info.r_type; // enum RelocationInfoType - reloc->external = a_info.r_extern; - reloc->pc_relative = a_info.r_pcrel; - reloc->size = a_info.r_length; - r_str_ncpy (reloc->name, sym_name, sizeof (reloc->name) - 1); - r_skiplist_insert (relocs, reloc); + reloc->type = a_info.rz_type; // enum RelocationInfoType + reloc->external = a_info.rz_extern; + reloc->pc_relative = a_info.rz_pcrel; + reloc->size = a_info.rz_length; + rz_str_ncpy (reloc->name, sym_name, sizeof (reloc->name) - 1); + rz_skiplist_insert (relocs, reloc); } } @@ -3174,8 +3174,8 @@ static bool is_valid_ordinal_table_size(ut64 size) { return size > 0 && size <= UT16_MAX; } -RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { - RSkipList *relocs = NULL; +RzSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { + RzSkipList *relocs = NULL; RPVector *threaded_binds = NULL; size_t wordsize = get_word_size (bin); if (bin->dyld_info) { @@ -3222,23 +3222,23 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { if (!bin->segs) { return NULL; } - relocs = r_skiplist_new ((RListFree) &free, (RListComparator) &reloc_comparator); + relocs = rz_skiplist_new ((RzListFree) &free, (RzListComparator) &reloc_comparator); if (!relocs) { return NULL; } opcodes = calloc (1, amount + 1); if (!opcodes) { - r_skiplist_free (relocs); + rz_skiplist_free (relocs); return NULL; } - int len = r_buf_read_at (bin->b, bin->dyld_info->bind_off, opcodes, bind_size); - len += r_buf_read_at (bin->b, bin->dyld_info->lazy_bind_off, opcodes + bind_size, lazy_size); - len += r_buf_read_at (bin->b, bin->dyld_info->weak_bind_off, opcodes + bind_size + lazy_size, weak_size); + int len = rz_buf_read_at (bin->b, bin->dyld_info->bind_off, opcodes, bind_size); + len += rz_buf_read_at (bin->b, bin->dyld_info->lazy_bind_off, opcodes + bind_size, lazy_size); + len += rz_buf_read_at (bin->b, bin->dyld_info->weak_bind_off, opcodes + bind_size + lazy_size, weak_size); if (len < amount) { bprintf ("Error: read (dyld_info bind) at 0x%08"PFMT64x"\n", (ut64)(size_t)bin->dyld_info->bind_off); R_FREE (opcodes); - r_skiplist_free (relocs); + rz_skiplist_free (relocs); return NULL; } @@ -3265,7 +3265,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { p++; switch (op) { #define ULEB() read_uleb128 (&p, end) -#define SLEB() r_sleb128 ((const ut8 **)&p, end) +#define SLEB() rz_sleb128 ((const ut8 **)&p, end) case BIND_OPCODE_DONE: { bool in_lazy_binds = pidx == 1; if (!in_lazy_binds) { @@ -3282,9 +3282,9 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { break; } if (threaded_binds) { - r_pvector_free (threaded_binds); + rz_pvector_free (threaded_binds); } - threaded_binds = r_pvector_new_with_len ((RPVectorFree) &free, table_size); + threaded_binds = rz_pvector_new_with_len ((RPVectorFree) &free, table_size); if (threaded_binds) { sym_ord = 0; } @@ -3293,16 +3293,16 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { case BIND_SUBOPCODE_THREADED_APPLY: if (threaded_binds) { int cur_seg_idx = (seg_idx != -1)? seg_idx: 0; - size_t n_threaded_binds = r_pvector_len (threaded_binds); + size_t n_threaded_binds = rz_pvector_len (threaded_binds); while (addr < segment_end_addr) { ut8 tmp[8]; ut64 paddr = addr - bin->segs[cur_seg_idx].vmaddr + bin->segs[cur_seg_idx].fileoff; bin->rebasing_buffer = true; - if (r_buf_read_at (bin->b, paddr, tmp, 8) != 8) { + if (rz_buf_read_at (bin->b, paddr, tmp, 8) != 8) { break; } bin->rebasing_buffer = false; - ut64 raw_ptr = r_read_le64 (tmp); + ut64 raw_ptr = rz_read_le64 (tmp); bool is_auth = (raw_ptr & (1ULL << 63)) != 0; bool is_bind = (raw_ptr & (1ULL << 62)) != 0; int ordinal = -1; @@ -3333,7 +3333,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { bprintf ("Error: Malformed bind chain\n"); break; } - struct reloc_t *ref = r_pvector_at (threaded_binds, ordinal); + struct reloc_t *ref = rz_pvector_at (threaded_binds, ordinal); if (!ref) { bprintf ("Error: Inconsistent bind opcodes\n"); break; @@ -3348,7 +3348,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { if (addend != -1) { reloc->addend = addend; } - r_skiplist_insert (relocs, reloc); + rz_skiplist_insert (relocs, reloc); } addr += delta * wordsize; if (!delta) { @@ -3416,8 +3416,8 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { bprintf ("Error: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB" " has unexistent segment %d\n", seg_idx); free (opcodes); - r_skiplist_free (relocs); - r_pvector_free (threaded_binds); + rz_skiplist_free (relocs); + rz_pvector_free (threaded_binds); return NULL; // early exit to avoid future mayhem } addr = bin->segs[seg_idx].vmaddr + ULEB (); @@ -3449,11 +3449,11 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { reloc->ord = sym_ord;\ reloc->type = rel_type;\ if (sym_name)\ - r_str_ncpy (reloc->name, sym_name, 256);\ + rz_str_ncpy (reloc->name, sym_name, 256);\ if (threaded_binds)\ - r_pvector_set (threaded_binds, sym_ord, reloc);\ + rz_pvector_set (threaded_binds, sym_ord, reloc);\ else\ - r_skiplist_insert (relocs, reloc);\ + rz_skiplist_insert (relocs, reloc);\ } while (0) case BIND_OPCODE_DO_BIND: if (!threaded_binds && addr >= segment_end_addr) { @@ -3501,7 +3501,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { default: bprintf ("Error: unknown bind opcode 0x%02x in dyld_info\n", *p); R_FREE (opcodes); - r_pvector_free (threaded_binds); + rz_pvector_free (threaded_binds); return relocs; } } @@ -3510,7 +3510,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { } R_FREE (opcodes); - r_pvector_free (threaded_binds); + rz_pvector_free (threaded_binds); threaded_binds = NULL; } @@ -3521,7 +3521,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { amount = 0; } if (!relocs) { - relocs = r_skiplist_new ((RListFree) &free, (RListComparator) &reloc_comparator); + relocs = rz_skiplist_new ((RzListFree) &free, (RzListComparator) &reloc_comparator); if (!relocs) { return NULL; } @@ -3533,7 +3533,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { } if (parse_import_ptr (bin, reloc, bin->dysymtab.iundefsym + j)) { reloc->ord = j; - r_skiplist_insert (relocs, reloc); + rz_skiplist_insert (relocs, reloc); } else { R_FREE (reloc); } @@ -3542,7 +3542,7 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { if (bin->symtab && bin->dysymtab.extreloff && bin->dysymtab.nextrel) { if (!relocs) { - relocs = r_skiplist_new ((RListFree) &free, (RListComparator) &reloc_comparator); + relocs = rz_skiplist_new ((RzListFree) &free, (RzListComparator) &reloc_comparator); if (!relocs) { return NULL; } @@ -3550,12 +3550,12 @@ RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin) { parse_relocation_info (bin, relocs, bin->dysymtab.extreloff, bin->dysymtab.nextrel); } beach: - r_pvector_free (threaded_binds); + rz_pvector_free (threaded_binds); return relocs; } struct addr_t *MACH0_(get_entrypoint)(struct MACH0_(obj_t) *bin) { - r_return_val_if_fail (bin, NULL); + rz_return_val_if_fail (bin, NULL); ut64 ea = entry_to_vaddr (bin); if (ea == 0 || ea == UT64_MAX) { @@ -3637,9 +3637,9 @@ ut64 MACH0_(get_baddr)(struct MACH0_(obj_t) *bin) { char *MACH0_(get_class)(struct MACH0_(obj_t) *bin) { #if R_BIN_MACH064 - return r_str_new ("MACH064"); + return rz_str_new ("MACH064"); #else - return r_str_new ("MACH0"); + return rz_str_new ("MACH0"); #endif } @@ -3901,7 +3901,7 @@ static const char *cpusubtype_tostring (ut32 cputype, ut32 cpusubtype) { } char *MACH0_(get_cpusubtype_from_hdr)(struct MACH0_(mach_header) *hdr) { - r_return_val_if_fail (hdr, NULL); + rz_return_val_if_fail (hdr, NULL); return strdup (cpusubtype_tostring (hdr->cputype, hdr->cpusubtype)); } @@ -3974,7 +3974,7 @@ ut64 MACH0_(get_main)(struct MACH0_(obj_t) *bin) { if (entry > bin->size || entry + sizeof (b) > bin->size) { return UT64_MAX; } - i = r_buf_read_at (bin->b, entry, b, sizeof (b)); + i = rz_buf_read_at (bin->b, entry, b, sizeof (b)); if (i < 80) { return UT64_MAX; } @@ -3998,7 +3998,7 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { cb_printf = printf; } RBuffer *buf = bf->buf; - ut64 length = r_buf_size (buf); + ut64 length = rz_buf_size (buf); int n = 0; struct MACH0_(mach_header) *mh = MACH0_(get_hdr)(buf); if (!mh) { @@ -4033,13 +4033,13 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { break; } #define READWORD() \ - if (r_buf_read_at (buf, addr, (ut8*)wordbuf, 4) != 4) { \ + if (rz_buf_read_at (buf, addr, (ut8*)wordbuf, 4) != 4) { \ eprintf ("Invalid address in buffer."); \ break; \ } \ addr += 4; \ pvaddr += 4;\ - word = isBe? r_read_be32 (wordbuf): r_read_le32 (wordbuf); + word = isBe? rz_read_be32 (wordbuf): rz_read_le32 (wordbuf); if (is64) { addr += 4; pvaddr += 4; @@ -4067,28 +4067,28 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { switch (lcType) { case LC_BUILD_VERSION: { cb_printf ("0x%08"PFMT64x" platform %s\n", - pvaddr, build_version_platform_to_string (r_buf_read_le32_at (buf, addr))); + pvaddr, build_version_platform_to_string (rz_buf_read_le32_at (buf, addr))); cb_printf ("0x%08"PFMT64x" minos %d.%d.%d\n", - pvaddr + 4, r_buf_read_le16_at (buf, addr + 6), r_buf_read8_at (buf, addr + 5), - r_buf_read8_at (buf, addr + 4)); + pvaddr + 4, rz_buf_read_le16_at (buf, addr + 6), rz_buf_read8_at (buf, addr + 5), + rz_buf_read8_at (buf, addr + 4)); cb_printf ("0x%08"PFMT64x" sdk %d.%d.%d\n", - pvaddr + 8, r_buf_read_le16_at (buf, addr + 10), r_buf_read8_at (buf, addr + 9), - r_buf_read8_at (buf, addr + 8)); - ut32 ntools = r_buf_read_le32_at (buf, addr + 12); + pvaddr + 8, rz_buf_read_le16_at (buf, addr + 10), rz_buf_read8_at (buf, addr + 9), + rz_buf_read8_at (buf, addr + 8)); + ut32 ntools = rz_buf_read_le32_at (buf, addr + 12); cb_printf ("0x%08"PFMT64x" ntools %d\n", pvaddr + 12, ntools); ut64 off = 16; while (off < (lcSize - 8) && ntools--) { cb_printf ("pf.mach0_build_version_tool @ 0x%08"PFMT64x"\n", pvaddr + off); cb_printf ("0x%08"PFMT64x" tool %s\n", - pvaddr + off, build_version_tool_to_string (r_buf_read_le32_at (buf, addr + off))); + pvaddr + off, build_version_tool_to_string (rz_buf_read_le32_at (buf, addr + off))); off += 4; if (off >= (lcSize - 8)) { break; } cb_printf ("0x%08"PFMT64x" version %d.%d.%d\n", - pvaddr + off, r_buf_read_le16_at (buf, addr + off + 2), r_buf_read8_at (buf, addr + off + 1), - r_buf_read8_at (buf, addr + off)); + pvaddr + off, rz_buf_read_le16_at (buf, addr + off + 2), rz_buf_read8_at (buf, addr + off + 1), + rz_buf_read8_at (buf, addr + off)); off += 4; } break; @@ -4096,16 +4096,16 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { case LC_MAIN: { ut8 data[64]; - r_buf_read_at (buf, addr, data, sizeof (data)); + rz_buf_read_at (buf, addr, data, sizeof (data)); #if R_BIN_MACH064 - ut64 ep = r_read_ble64 (&data, false); // bin->big_endian); + ut64 ep = rz_read_ble64 (&data, false); // bin->big_endian); cb_printf ("0x%08"PFMT64x" entry0 0x%" PFMT64x "\n", pvaddr, ep); - ut64 ss = r_read_ble64 (&data[8], false); // bin->big_endian); + ut64 ss = rz_read_ble64 (&data[8], false); // bin->big_endian); cb_printf ("0x%08"PFMT64x" stacksize 0x%" PFMT64x "\n", pvaddr + 8, ss); #else - ut32 ep = r_read_ble32 (&data, false); // bin->big_endian); + ut32 ep = rz_read_ble32 (&data, false); // bin->big_endian); cb_printf ("0x%08"PFMT32x" entry0 0x%" PFMT32x "\n", (ut32)pvaddr, ep); - ut32 ss = r_read_ble32 (&data[4], false); // bin->big_endian); + ut32 ss = rz_read_ble32 (&data[4], false); // bin->big_endian); cb_printf ("0x%08"PFMT32x" stacksize 0x%" PFMT32x "\n", (ut32)pvaddr + 4, ss); #endif } @@ -4113,7 +4113,7 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { case LC_SYMTAB: #if 0 { - char *id = r_buf_get_string (buf, addr + 20); + char *id = rz_buf_get_string (buf, addr + 20); cb_printf ("0x%08"PFMT64x" id 0x%x\n", addr + 20, id? id: ""); cb_printf ("0x%08"PFMT64x" symooff 0x%x\n", addr + 20, id? id: ""); cb_printf ("0x%08"PFMT64x" nsyms %d\n", addr + 20, id? id: ""); @@ -4124,14 +4124,14 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { #endif break; case LC_ID_DYLIB: { // install_name_tool - ut32 str_off = r_buf_read_ble32_at (buf, addr, isBe); - char *id = r_buf_get_string (buf, addr + str_off - 8); + ut32 str_off = rz_buf_read_ble32_at (buf, addr, isBe); + char *id = rz_buf_get_string (buf, addr + str_off - 8); cb_printf ("0x%08"PFMT64x" current %d.%d.%d\n", - pvaddr + 8, r_buf_read_le16_at (buf, addr + 10), r_buf_read8_at (buf, addr + 9), - r_buf_read8_at (buf, addr + 8)); + pvaddr + 8, rz_buf_read_le16_at (buf, addr + 10), rz_buf_read8_at (buf, addr + 9), + rz_buf_read8_at (buf, addr + 8)); cb_printf ("0x%08"PFMT64x" compat %d.%d.%d\n", - pvaddr + 12, r_buf_read_le16_at (buf, addr + 14), r_buf_read8_at (buf, addr + 13), - r_buf_read8_at (buf, addr + 12)); + pvaddr + 12, rz_buf_read_le16_at (buf, addr + 14), rz_buf_read8_at (buf, addr + 13), + rz_buf_read8_at (buf, addr + 12)); cb_printf ("0x%08"PFMT64x" id %s\n", pvaddr + str_off - 8, id? id: ""); free (id); @@ -4140,7 +4140,7 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { case LC_UUID: { ut8 i, uuid[16]; - r_buf_read_at (buf, addr, uuid, sizeof (uuid)); + rz_buf_read_at (buf, addr, uuid, sizeof (uuid)); cb_printf ("0x%08"PFMT64x" uuid ", pvaddr); for (i = 0; i < sizeof (uuid); i++) { cb_printf ("%02x", uuid[i]); @@ -4152,9 +4152,9 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { case LC_SEGMENT_64: { ut8 name[17] = {0}; - r_buf_read_at (buf, addr, name, sizeof (name) - 1); + rz_buf_read_at (buf, addr, name, sizeof (name) - 1); cb_printf ("0x%08"PFMT64x" name %s\n", pvaddr, name); - ut32 nsects = r_buf_read_le32_at (buf, addr - 8 + (is64 ? 64 : 48)); + ut32 nsects = rz_buf_read_le32_at (buf, addr - 8 + (is64 ? 64 : 48)); ut64 off = is64 ? 72 : 56; while (off < lcSize && nsects--) { if (is64) { @@ -4169,21 +4169,21 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { break; case LC_LOAD_DYLIB: case LC_LOAD_WEAK_DYLIB: { - ut32 str_off = r_buf_read_ble32_at (buf, addr, isBe); - char *load_dylib = r_buf_get_string (buf, addr + str_off - 8); + ut32 str_off = rz_buf_read_ble32_at (buf, addr, isBe); + char *load_dylib = rz_buf_get_string (buf, addr + str_off - 8); cb_printf ("0x%08"PFMT64x" current %d.%d.%d\n", - pvaddr + 8, r_buf_read_le16_at (buf, addr + 10), r_buf_read8_at (buf, addr + 9), - r_buf_read8_at (buf, addr + 8)); + pvaddr + 8, rz_buf_read_le16_at (buf, addr + 10), rz_buf_read8_at (buf, addr + 9), + rz_buf_read8_at (buf, addr + 8)); cb_printf ("0x%08"PFMT64x" compat %d.%d.%d\n", - pvaddr + 12, r_buf_read_le16_at (buf, addr + 14), r_buf_read8_at (buf, addr + 13), - r_buf_read8_at (buf, addr + 12)); + pvaddr + 12, rz_buf_read_le16_at (buf, addr + 14), rz_buf_read8_at (buf, addr + 13), + rz_buf_read8_at (buf, addr + 12)); cb_printf ("0x%08"PFMT64x" load_dylib %s\n", pvaddr + str_off - 8, load_dylib? load_dylib: ""); free (load_dylib); break; } case LC_RPATH: { - char *rpath = r_buf_get_string (buf, addr + 4); + char *rpath = rz_buf_get_string (buf, addr + 4); cb_printf ("0x%08" PFMT64x " rpath %s\n", pvaddr + 4, rpath ? rpath : ""); free (rpath); @@ -4191,17 +4191,17 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { } case LC_ENCRYPTION_INFO: case LC_ENCRYPTION_INFO_64: { - ut32 word = r_buf_read_le32_at (buf, addr); + ut32 word = rz_buf_read_le32_at (buf, addr); cb_printf ("0x%08"PFMT64x" cryptoff 0x%08x\n", pvaddr, word); - word = r_buf_read_le32_at (buf, addr + 4); + word = rz_buf_read_le32_at (buf, addr + 4); cb_printf ("0x%08"PFMT64x" cryptsize %d\n", pvaddr + 4, word); - word = r_buf_read_le32_at (buf, addr + 8); + word = rz_buf_read_le32_at (buf, addr + 8); cb_printf ("0x%08"PFMT64x" cryptid %d\n", pvaddr + 8, word); break; } case LC_CODE_SIGNATURE: { ut32 words[2]; - r_buf_read_at (buf, addr, (ut8 *)words, sizeof (words)); + rz_buf_read_at (buf, addr, (ut8 *)words, sizeof (words)); cb_printf ("0x%08"PFMT64x" dataoff 0x%08x\n", pvaddr, words[0]); cb_printf ("0x%08"PFMT64x" datasize %d\n", pvaddr + 4, words[1]); cb_printf ("# wtf mach0.sign %d @ 0x%x\n", words[1], words[0]); @@ -4214,14 +4214,14 @@ void MACH0_(mach_headerfields)(RBinFile *bf) { free (mh); } -RList *MACH0_(mach_fields)(RBinFile *bf) { +RzList *MACH0_(mach_fields)(RBinFile *bf) { RBuffer *buf = bf->buf; - ut64 length = r_buf_size (buf); + ut64 length = rz_buf_size (buf); struct MACH0_(mach_header) *mh = MACH0_(get_hdr) (buf); if (!mh) { return NULL; } - RList *ret = r_list_new (); + RzList *ret = rz_list_new (); if (!ret) { free (mh); return NULL; @@ -4230,7 +4230,7 @@ RList *MACH0_(mach_fields)(RBinFile *bf) { ut64 addr = pa2va (bf, 0); ut64 paddr = 0; - r_list_append (ret, r_bin_field_new (addr, addr, 1, "header", "mach0_header", "mach0_header", true)); + rz_list_append (ret, rz_bin_field_new (addr, addr, 1, "header", "mach0_header", "mach0_header", true)); addr += 0x20 - 4; paddr += 0x20 - 4; bool is64 = mh->cputype >> 16; @@ -4249,8 +4249,8 @@ RList *MACH0_(mach_fields)(RBinFile *bf) { int n; for (n = 0; n < mh->ncmds; n++) { - ut32 lcType = r_buf_read_ble32_at (buf, paddr, isBe); - ut32 word = r_buf_read_ble32_at (buf, paddr + 4, isBe); + ut32 lcType = rz_buf_read_ble32_at (buf, paddr, isBe); + ut32 word = rz_buf_read_ble32_at (buf, paddr + 4, isBe); if (paddr + 8 > length) { break; } @@ -4265,29 +4265,29 @@ RList *MACH0_(mach_fields)(RBinFile *bf) { } const char *pf_definition = cmd_to_pf_definition (lcType); if (pf_definition) { - r_list_append (ret, r_bin_field_new (addr, addr, 1, sdb_fmt ("load_command_%d_%s", n, cmd_to_string (lcType)), pf_definition, pf_definition, true)); + rz_list_append (ret, rz_bin_field_new (addr, addr, 1, sdb_fmt ("load_command_%d_%s", n, cmd_to_string (lcType)), pf_definition, pf_definition, true)); } switch (lcType) { case LC_BUILD_VERSION: { - ut32 ntools = r_buf_read_le32_at (buf, paddr + 20); + ut32 ntools = rz_buf_read_le32_at (buf, paddr + 20); ut64 off = 24; int j = 0; while (off < lcSize && ntools--) { - r_list_append (ret, r_bin_field_new (addr + off, addr + off, 1, sdb_fmt ("tool_%d", j++), "mach0_build_version_tool", "mach0_build_version_tool", true)); + rz_list_append (ret, rz_bin_field_new (addr + off, addr + off, 1, sdb_fmt ("tool_%d", j++), "mach0_build_version_tool", "mach0_build_version_tool", true)); off += 8; } break; } case LC_SEGMENT: case LC_SEGMENT_64: { - ut32 nsects = r_buf_read_le32_at (buf, addr + (is64 ? 64 : 48)); + ut32 nsects = rz_buf_read_le32_at (buf, addr + (is64 ? 64 : 48)); ut64 off = is64 ? 72 : 56; size_t i, j = 0; for (i = 0; i < nsects && (addr + off) < length && off < lcSize; i++) { const char *sname = is64? "mach0_section64": "mach0_section"; - RBinField *f = r_bin_field_new (addr + off, addr + off, 1, + RBinField *f = rz_bin_field_new (addr + off, addr + off, 1, sdb_fmt ("section_%zu", j++), sname, sname, true); - r_list_append (ret, f); + rz_list_append (ret, f); off += is64? 80: 68; } break; @@ -4312,22 +4312,22 @@ struct MACH0_(mach_header) *MACH0_(get_hdr)(RBuffer *buf) { if (!macho_hdr) { return NULL; } - if (r_buf_read_at (buf, 0, magicbytes, 4) < 1) { + if (rz_buf_read_at (buf, 0, magicbytes, 4) < 1) { free (macho_hdr); return false; } - if (r_read_le32 (magicbytes) == 0xfeedface) { + if (rz_read_le32 (magicbytes) == 0xfeedface) { big_endian = false; - } else if (r_read_be32 (magicbytes) == 0xfeedface) { + } else if (rz_read_be32 (magicbytes) == 0xfeedface) { big_endian = true; - } else if (r_read_le32 (magicbytes) == FAT_MAGIC) { + } else if (rz_read_le32 (magicbytes) == FAT_MAGIC) { big_endian = false; - } else if (r_read_be32 (magicbytes) == FAT_MAGIC) { + } else if (rz_read_be32 (magicbytes) == FAT_MAGIC) { big_endian = true; - } else if (r_read_le32 (magicbytes) == 0xfeedfacf) { + } else if (rz_read_le32 (magicbytes) == 0xfeedfacf) { big_endian = false; - } else if (r_read_be32 (magicbytes) == 0xfeedfacf) { + } else if (rz_read_be32 (magicbytes) == 0xfeedfacf) { big_endian = true; } else { /* also extract non-mach0s */ @@ -4336,20 +4336,20 @@ struct MACH0_(mach_header) *MACH0_(get_hdr)(RBuffer *buf) { return NULL; #endif } - len = r_buf_read_at (buf, 0, machohdrbytes, sizeof (machohdrbytes)); + len = rz_buf_read_at (buf, 0, machohdrbytes, sizeof (machohdrbytes)); if (len != sizeof (struct MACH0_(mach_header))) { free (macho_hdr); return NULL; } - macho_hdr->magic = r_read_ble (&machohdrbytes[0], big_endian, 32); - macho_hdr->cputype = r_read_ble (&machohdrbytes[4], big_endian, 32); - macho_hdr->cpusubtype = r_read_ble (&machohdrbytes[8], big_endian, 32); - macho_hdr->filetype = r_read_ble (&machohdrbytes[12], big_endian, 32); - macho_hdr->ncmds = r_read_ble (&machohdrbytes[16], big_endian, 32); - macho_hdr->sizeofcmds = r_read_ble (&machohdrbytes[20], big_endian, 32); - macho_hdr->flags = r_read_ble (&machohdrbytes[24], big_endian, 32); + macho_hdr->magic = rz_read_ble (&machohdrbytes[0], big_endian, 32); + macho_hdr->cputype = rz_read_ble (&machohdrbytes[4], big_endian, 32); + macho_hdr->cpusubtype = rz_read_ble (&machohdrbytes[8], big_endian, 32); + macho_hdr->filetype = rz_read_ble (&machohdrbytes[12], big_endian, 32); + macho_hdr->ncmds = rz_read_ble (&machohdrbytes[16], big_endian, 32); + macho_hdr->sizeofcmds = rz_read_ble (&machohdrbytes[20], big_endian, 32); + macho_hdr->flags = rz_read_ble (&machohdrbytes[24], big_endian, 32); #if R_BIN_MACH064 - macho_hdr->reserved = r_read_ble (&machohdrbytes[28], big_endian, 32); + macho_hdr->reserved = rz_read_ble (&machohdrbytes[28], big_endian, 32); #endif return macho_hdr; } diff --git a/libr/bin/format/mach0/mach0.h b/librz/bin/format/mach0/mach0.h similarity index 91% rename from libr/bin/format/mach0/mach0.h rename to librz/bin/format/mach0/mach0.h index 226c2f33ff..7ae95cefc9 100644 --- a/libr/bin/format/mach0/mach0.h +++ b/librz/bin/format/mach0/mach0.h @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include "mach0_specs.h" #ifndef _INCLUDE_R_BIN_MACH0_H_ @@ -117,7 +117,7 @@ struct MACH0_(obj_t) { char *intrp; char *compiler; int nsegs; - struct r_dyld_chained_starts_in_segment **chained_starts; + struct rz_dyld_chained_starts_in_segment **chained_starts; struct MACH0_(section) *sects; int nsects; struct MACH0_(nlist) *symtab; @@ -174,7 +174,7 @@ struct MACH0_(obj_t) { ut64 (*va2pa)(ut64 p, ut32 *offset, ut32 *left, RBinFile *bf); struct symbol_t *symbols; ut64 main_addr; - int (*original_io_read)(RIO *io, RIODesc *fd, ut8 *buf, int count); + int (*original_io_read)(RzIO *io, RzIODesc *fd, ut8 *buf, int count); bool rebasing_buffer; }; @@ -183,13 +183,13 @@ struct MACH0_(obj_t) *MACH0_(mach0_new)(const char *file, struct MACH0_(opts_t) struct MACH0_(obj_t) *MACH0_(new_buf)(RBuffer *buf, struct MACH0_(opts_t) *options); void *MACH0_(mach0_free)(struct MACH0_(obj_t) *bin); struct section_t *MACH0_(get_sections)(struct MACH0_(obj_t) *bin); -//RList *MACH0_(get_segments)(struct MACH0_(obj_t) *bin); -RList *MACH0_(get_segments)(RBinFile *bf); // struct MACH0_(obj_t) *bin); +//RzList *MACH0_(get_segments)(struct MACH0_(obj_t) *bin); +RzList *MACH0_(get_segments)(RBinFile *bf); // struct MACH0_(obj_t) *bin); const struct symbol_t *MACH0_(get_symbols)(struct MACH0_(obj_t) *bin); -const RList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin); +const RzList *MACH0_(get_symbols_list)(struct MACH0_(obj_t) *bin); void MACH0_(pull_symbols)(struct MACH0_(obj_t) *mo, RBinSymbolCallback cb, void *user); struct import_t *MACH0_(get_imports)(struct MACH0_(obj_t) *bin); -RSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin); +RzSkipList *MACH0_(get_relocs)(struct MACH0_(obj_t) *bin); struct addr_t *MACH0_(get_entrypoint)(struct MACH0_(obj_t) *bin); struct lib_t *MACH0_(get_libs)(struct MACH0_(obj_t) *bin); ut64 MACH0_(get_baddr)(struct MACH0_(obj_t) *bin); @@ -210,5 +210,5 @@ const char *MACH0_(get_cputype_from_hdr)(struct MACH0_(mach_header) *hdr); int MACH0_(get_bits_from_hdr)(struct MACH0_(mach_header) *hdr); struct MACH0_(mach_header) *MACH0_(get_hdr)(RBuffer *buf); void MACH0_(mach_headerfields)(RBinFile *bf); -RList *MACH0_(mach_fields)(RBinFile *bf); +RzList *MACH0_(mach_fields)(RBinFile *bf); #endif diff --git a/libr/bin/format/mach0/mach064.c b/librz/bin/format/mach0/mach064.c similarity index 100% rename from libr/bin/format/mach0/mach064.c rename to librz/bin/format/mach0/mach064.c diff --git a/libr/bin/format/mach0/mach064.h b/librz/bin/format/mach0/mach064.h similarity index 100% rename from libr/bin/format/mach0/mach064.h rename to librz/bin/format/mach0/mach064.h diff --git a/libr/bin/format/mach0/mach064_is_kernelcache.c b/librz/bin/format/mach0/mach064_is_kernelcache.c similarity index 71% rename from libr/bin/format/mach0/mach064_is_kernelcache.c rename to librz/bin/format/mach0/mach064_is_kernelcache.c index f8f2c0eb56..4eb29ab360 100644 --- a/libr/bin/format/mach0/mach064_is_kernelcache.c +++ b/librz/bin/format/mach0/mach064_is_kernelcache.c @@ -1,24 +1,24 @@ #include "mach0_defines.h" static bool is_kernelcache_buffer(RBuffer *b) { - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (length < sizeof (struct MACH0_(mach_header))) { return false; } - ut32 cputype = r_buf_read_le32_at (b, 4); + ut32 cputype = rz_buf_read_le32_at (b, 4); if (cputype != CPU_TYPE_ARM64) { return false; } - ut32 filetype = r_buf_read_le32_at (b, 12); + ut32 filetype = rz_buf_read_le32_at (b, 12); if (filetype == MH_FILESET) { return true; } - ut32 flags = r_buf_read_le32_at (b, 24); + ut32 flags = rz_buf_read_le32_at (b, 24); if (!(flags & MH_PIE)) { return false; } - int i, ncmds = r_buf_read_le32_at (b, 16); + int i, ncmds = rz_buf_read_le32_at (b, 16); bool has_unixthread = false; bool has_negative_vaddr = false; bool has_kext = false; @@ -26,8 +26,8 @@ static bool is_kernelcache_buffer(RBuffer *b) { ut32 cursor = sizeof (struct MACH0_(mach_header)); for (i = 0; i < ncmds && cursor < length; i++) { - ut32 cmdtype = r_buf_read_le32_at (b, cursor); - ut32 cmdsize = r_buf_read_le32_at (b, cursor + 4); + ut32 cmdtype = rz_buf_read_le32_at (b, cursor); + ut32 cmdsize = rz_buf_read_le32_at (b, cursor + 4); switch (cmdtype) { case LC_KEXT: @@ -45,7 +45,7 @@ static bool is_kernelcache_buffer(RBuffer *b) { if (has_negative_vaddr) { break; } - st64 vmaddr = r_buf_read_le64_at (b, cursor + 24); + st64 vmaddr = rz_buf_read_le64_at (b, cursor + 24); if (vmaddr < 0) { has_negative_vaddr = true; } diff --git a/libr/bin/format/mach0/mach0_defines.h b/librz/bin/format/mach0/mach0_defines.h similarity index 97% rename from libr/bin/format/mach0/mach0_defines.h rename to librz/bin/format/mach0/mach0_defines.h index 61b4aa54ce..8d192d2109 100644 --- a/libr/bin/format/mach0/mach0_defines.h +++ b/librz/bin/format/mach0/mach0_defines.h @@ -481,17 +481,17 @@ enum StabType { }; enum { - // Constant values for the r_symbolnum field in an - // llvm::MachO::relocation_info structure when r_extern is 0. + // Constant values for the rz_symbolnum field in an + // llvm::MachO::relocation_info structure when rz_extern is 0. R_ABS = 0, - // Constant bits for the r_address field in an + // Constant bits for the rz_address field in an // llvm::MachO::relocation_info structure. R_SCATTERED = 0x80000000 }; enum RelocationInfoType { - // Constant values for the r_type field in an + // Constant values for the rz_type field in an // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info // structure. GENERIC_RELOC_VANILLA = 0, @@ -501,7 +501,7 @@ enum RelocationInfoType { GENERIC_RELOC_LOCAL_SECTDIFF = 4, GENERIC_RELOC_TLV = 5, - // Constant values for the r_type field in a PowerPC architecture + // Constant values for the rz_type field in a PowerPC architecture // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info // structure. PPC_RELOC_VANILLA = GENERIC_RELOC_VANILLA, @@ -521,7 +521,7 @@ enum RelocationInfoType { PPC_RELOC_LO14_SECTDIFF = 14, PPC_RELOC_LOCAL_SECTDIFF = 15, - // Constant values for the r_type field in an ARM architecture + // Constant values for the rz_type field in an ARM architecture // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info // structure. ARM_RELOC_VANILLA = GENERIC_RELOC_VANILLA, @@ -535,7 +535,7 @@ enum RelocationInfoType { ARM_RELOC_HALF = 8, ARM_RELOC_HALF_SECTDIFF = 9, - // Constant values for the r_type field in an ARM64 architecture + // Constant values for the rz_type field in an ARM64 architecture // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info // structure. @@ -547,23 +547,23 @@ enum RelocationInfoType { ARM64_RELOC_BRANCH26 = 2, // PC-rel distance to page of target. ARM64_RELOC_PAGE21 = 3, - // Offset within page, scaled by r_length. + // Offset within page, scaled by rz_length. ARM64_RELOC_PAGEOFF12 = 4, // PC-rel distance to page of GOT slot. ARM64_RELOC_GOT_LOAD_PAGE21 = 5, - // Offset within page of GOT slot, scaled by r_length. + // Offset within page of GOT slot, scaled by rz_length. ARM64_RELOC_GOT_LOAD_PAGEOFF12 = 6, // For pointers to GOT slots. ARM64_RELOC_POINTER_TO_GOT = 7, // PC-rel distance to page of TLVP slot. ARM64_RELOC_TLVP_LOAD_PAGE21 = 8, - // Offset within page of TLVP slot, scaled by r_length. + // Offset within page of TLVP slot, scaled by rz_length. ARM64_RELOC_TLVP_LOAD_PAGEOFF12 = 9, // Must be followed by ARM64_RELOC_PAGE21 or ARM64_RELOC_PAGEOFF12. ARM64_RELOC_ADDEND = 10, - // Constant values for the r_type field in an x86_64 architecture + // Constant values for the rz_type field in an x86_64 architecture // llvm::MachO::relocation_info or llvm::MachO::scattered_relocation_info // structure X86_64_RELOC_UNSIGNED = 0, @@ -997,34 +997,34 @@ struct fat_arch { // Structs from struct relocation_info { - int32_t r_address; - uint32_t r_symbolnum:24, - r_pcrel:1, - r_length:2, - r_extern:1, - r_type:4; + int32_t rz_address; + uint32_t rz_symbolnum:24, + rz_pcrel:1, + rz_length:2, + rz_extern:1, + rz_type:4; }; struct scattered_relocation_info { #if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) - uint32_t r_scattered:1, - r_pcrel:1, - r_length:2, - r_type:4, - r_address:24; + uint32_t rz_scattered:1, + rz_pcrel:1, + rz_length:2, + rz_type:4, + rz_address:24; #else - uint32_t r_address:24, - r_type:4, - r_length:2, - r_pcrel:1, - r_scattered:1; + uint32_t rz_address:24, + rz_type:4, + rz_length:2, + rz_pcrel:1, + rz_scattered:1; #endif - int32_t r_value; + int32_t rz_value; }; // Structs NOT from , but that make LLVM's life easier struct any_relocation_info { - uint32_t r_word0, r_word1; + uint32_t rz_word0, rz_word1; }; // Structs from @@ -1463,7 +1463,7 @@ struct dyld_chained_starts_in_segment { uint16_t page_count; }; -struct r_dyld_chained_starts_in_segment { +struct rz_dyld_chained_starts_in_segment { uint32_t size; uint16_t page_size; uint16_t pointer_format; diff --git a/libr/bin/format/mach0/mach0_specs.h b/librz/bin/format/mach0/mach0_specs.h similarity index 100% rename from libr/bin/format/mach0/mach0_specs.h rename to librz/bin/format/mach0/mach0_specs.h diff --git a/libr/bin/format/mdmp/mdmp.c b/librz/bin/format/mdmp/mdmp.c similarity index 76% rename from libr/bin/format/mdmp/mdmp.c rename to librz/bin/format/mdmp/mdmp.c index fef6023651..7bdc331a81 100644 --- a/libr/bin/format/mdmp/mdmp.c +++ b/librz/bin/format/mdmp/mdmp.c @@ -1,21 +1,21 @@ -/* radare2 - LGPL - Copyright 2016-2017 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016-2017 - Davis, Alex Kornitzer */ -#include +#include #include "mdmp.h" // XXX: this is a random number, no idea how long it should be. #define COMMENTS_SIZE 32 -ut64 r_bin_mdmp_get_paddr(struct r_bin_mdmp_obj *obj, ut64 vaddr) { +ut64 rz_bin_mdmp_get_paddr(struct rz_bin_mdmp_obj *obj, ut64 vaddr) { /* FIXME: Will only resolve exact matches, probably no need to fix as ** this function will become redundant on the optimisation stage */ struct minidump_memory_descriptor64 *memory; ut64 index, paddr = 0; - RListIter *it; + RzListIter *it; /* Loop through the memories sections looking for a match */ index = obj->streams.memories64.base_rva; - r_list_foreach (obj->streams.memories64.memories, it, memory) { + rz_list_foreach (obj->streams.memories64.memories, it, memory) { if (vaddr == memory->start_of_memory_range) { paddr = index; break; @@ -25,15 +25,15 @@ ut64 r_bin_mdmp_get_paddr(struct r_bin_mdmp_obj *obj, ut64 vaddr) { return paddr; } -struct minidump_memory_info *r_bin_mdmp_get_mem_info(struct r_bin_mdmp_obj *obj, ut64 vaddr) { +struct minidump_memory_info *rz_bin_mdmp_get_mem_info(struct rz_bin_mdmp_obj *obj, ut64 vaddr) { struct minidump_memory_info *mem_info; - RListIter *it; + RzListIter *it; if (!obj) { return NULL; } - r_list_foreach (obj->streams.memory_infos, it, mem_info) { + rz_list_foreach (obj->streams.memory_infos, it, mem_info) { if (mem_info->allocation_base && vaddr == mem_info->base_address) { return mem_info; } @@ -42,10 +42,10 @@ struct minidump_memory_info *r_bin_mdmp_get_mem_info(struct r_bin_mdmp_obj *obj, return NULL; } -ut32 r_bin_mdmp_get_perm(struct r_bin_mdmp_obj *obj, ut64 vaddr) { +ut32 rz_bin_mdmp_get_perm(struct rz_bin_mdmp_obj *obj, ut64 vaddr) { struct minidump_memory_info *mem_info; - if (!(mem_info = r_bin_mdmp_get_mem_info(obj, vaddr))) { + if (!(mem_info = rz_bin_mdmp_get_mem_info(obj, vaddr))) { /* if there is no mem info in the dump, assume default permission */ return R_PERM_R; } @@ -74,39 +74,39 @@ ut32 r_bin_mdmp_get_perm(struct r_bin_mdmp_obj *obj, ut64 vaddr) { } } -static void r_bin_mdmp_free_pe32_bin(void *pe_bin_) { - struct Pe32_r_bin_mdmp_pe_bin *pe_bin = pe_bin_; +static void rz_bin_mdmp_free_pe32_bin(void *pe_bin_) { + struct Pe32_rz_bin_mdmp_pe_bin *pe_bin = pe_bin_; if (pe_bin) { sdb_free (pe_bin->bin->kv); - Pe32_r_bin_pe_free (pe_bin->bin); + Pe32_rz_bin_pe_free (pe_bin->bin); R_FREE (pe_bin); } } -static void r_bin_mdmp_free_pe64_bin(void *pe_bin_) { - struct Pe64_r_bin_mdmp_pe_bin *pe_bin = pe_bin_; +static void rz_bin_mdmp_free_pe64_bin(void *pe_bin_) { + struct Pe64_rz_bin_mdmp_pe_bin *pe_bin = pe_bin_; if (pe_bin) { sdb_free (pe_bin->bin->kv); - Pe64_r_bin_pe_free (pe_bin->bin); + Pe64_rz_bin_pe_free (pe_bin->bin); R_FREE (pe_bin); } } -void r_bin_mdmp_free(struct r_bin_mdmp_obj *obj) { +void rz_bin_mdmp_free(struct rz_bin_mdmp_obj *obj) { if (!obj) { return; } - r_list_free (obj->streams.ex_threads); - r_list_free (obj->streams.memories); - r_list_free (obj->streams.memories64.memories); - r_list_free (obj->streams.memory_infos); - r_list_free (obj->streams.modules); - r_list_free (obj->streams.operations); - r_list_free (obj->streams.thread_infos); - r_list_free (obj->streams.threads); - r_list_free (obj->streams.token_infos); - r_list_free (obj->streams.unloaded_modules); + rz_list_free (obj->streams.ex_threads); + rz_list_free (obj->streams.memories); + rz_list_free (obj->streams.memories64.memories); + rz_list_free (obj->streams.memory_infos); + rz_list_free (obj->streams.modules); + rz_list_free (obj->streams.operations); + rz_list_free (obj->streams.thread_infos); + rz_list_free (obj->streams.threads); + rz_list_free (obj->streams.token_infos); + rz_list_free (obj->streams.unloaded_modules); free (obj->streams.exception); free (obj->streams.system_info); free (obj->streams.comments_a); @@ -115,10 +115,10 @@ void r_bin_mdmp_free(struct r_bin_mdmp_obj *obj) { free (obj->streams.function_table); free (obj->streams.misc_info.misc_info_1); - r_list_free (obj->pe32_bins); - r_list_free (obj->pe64_bins); + rz_list_free (obj->pe32_bins); + rz_list_free (obj->pe64_bins); - r_buf_free (obj->b); + rz_buf_free (obj->b); free (obj->hdr); obj->b = NULL; free (obj); @@ -126,7 +126,7 @@ void r_bin_mdmp_free(struct r_bin_mdmp_obj *obj) { return; } -static void r_bin_mdmp_init_parsing(struct r_bin_mdmp_obj *obj) { +static void rz_bin_mdmp_init_parsing(struct rz_bin_mdmp_obj *obj) { /* TODO: Handle unions, can we? */ /* FIXME: Why are we getting struct missing errors when it finds them */ sdb_set (obj->kv, "mdmp_mem_state.cparse", @@ -323,12 +323,12 @@ static void r_bin_mdmp_init_parsing(struct r_bin_mdmp_obj *obj) { sdb_set (obj->kv, "mdmp_string.format", "dZ Length Buffer", 0); } -static bool r_bin_mdmp_init_hdr(struct r_bin_mdmp_obj *obj) { +static bool rz_bin_mdmp_init_hdr(struct rz_bin_mdmp_obj *obj) { obj->hdr = R_NEW (struct minidump_header); if (!obj->hdr) { return false; } - r_buf_read_at (obj->b, 0, (ut8 *)obj->hdr, sizeof (*obj->hdr)); + rz_buf_read_at (obj->b, 0, (ut8 *)obj->hdr, sizeof (*obj->hdr)); if (obj->hdr->number_of_streams == 0) { eprintf ("[WARN] No streams present!\n"); @@ -356,7 +356,7 @@ static bool r_bin_mdmp_init_hdr(struct r_bin_mdmp_obj *obj) { return true; } -static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct minidump_directory *entry) { +static bool rz_bin_mdmp_init_directory_entry(struct rz_bin_mdmp_obj *obj, struct minidump_directory *entry) { struct minidump_handle_operation_list handle_operation_list; struct minidump_memory_list memory_list; struct minidump_memory64_list memory64_list; @@ -372,14 +372,14 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m /* We could confirm data sizes but a malcious MDMP will always get around ** this! But we can ensure that the data is not outside of the file */ - if ((ut64)entry->location.rva + entry->location.data_size > r_buf_size (obj->b)) { + if ((ut64)entry->location.rva + entry->location.data_size > rz_buf_size (obj->b)) { eprintf ("[ERROR] Size Mismatch - Stream data is larger than file size!\n"); return false; } switch (entry->stream_type) { case THREAD_LIST_STREAM: - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_list, sizeof (thread_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_list, sizeof (thread_list)); if (r != sizeof (thread_list)) { break; } @@ -399,7 +399,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m /* TODO: Not yet fully parsed or utilised */ break; case MODULE_LIST_STREAM: - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&module_list, sizeof (module_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&module_list, sizeof (module_list)); if (r != sizeof (module_list)) { break; } @@ -426,16 +426,16 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!module) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)module, sizeof (*module)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)module, sizeof (*module)); if (r != sizeof (*module)) { break; } - r_list_append (obj->streams.modules, module); + rz_list_append (obj->streams.modules, module); offset += sizeof (*module); } break; case MEMORY_LIST_STREAM: - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory_list, sizeof (memory_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory_list, sizeof (memory_list)); if (r != sizeof (memory_list)) { break; } @@ -456,11 +456,11 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!desc) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)desc, sizeof (*desc)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)desc, sizeof (*desc)); if (r != sizeof (*desc)) { break; } - r_list_append (obj->streams.memories, desc); + rz_list_append (obj->streams.memories, desc); offset += sizeof (*desc); } break; @@ -471,7 +471,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m break; } - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.exception, sizeof (*obj->streams.exception)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.exception, sizeof (*obj->streams.exception)); if (r != sizeof (*obj->streams.exception)) { break; } @@ -497,7 +497,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.system_info) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.system_info, sizeof (*obj->streams.system_info)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.system_info, sizeof (*obj->streams.system_info)); if (r != sizeof (*obj->streams.system_info)) { break; } @@ -515,7 +515,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m break; case THREAD_EX_LIST_STREAM: /* TODO: Not yet fully parsed or utilised */ - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_ex_list, sizeof (thread_ex_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_ex_list, sizeof (thread_ex_list)); if (r != sizeof (thread_ex_list)) { break; } @@ -539,16 +539,16 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!thread) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)thread, sizeof (*thread)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)thread, sizeof (*thread)); if (r != sizeof (*thread)) { break; } - r_list_append (obj->streams.ex_threads, thread); + rz_list_append (obj->streams.ex_threads, thread); offset += sizeof (*thread); } break; case MEMORY_64_LIST_STREAM: - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory64_list, sizeof (memory64_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory64_list, sizeof (memory64_list)); if (r != sizeof (memory64_list)) { break; } @@ -569,11 +569,11 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!desc) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)desc, sizeof (*desc)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)desc, sizeof (*desc)); if (r != sizeof (*desc)) { break; } - r_list_append (obj->streams.memories64.memories, desc); + rz_list_append (obj->streams.memories64.memories, desc); offset += sizeof (*desc); } break; @@ -583,7 +583,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.comments_a) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, obj->streams.comments_a, COMMENTS_SIZE); + r = rz_buf_read_at (obj->b, entry->location.rva, obj->streams.comments_a, COMMENTS_SIZE); if (r != COMMENTS_SIZE) { break; } @@ -600,7 +600,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.comments_w) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, obj->streams.comments_w, COMMENTS_SIZE); + r = rz_buf_read_at (obj->b, entry->location.rva, obj->streams.comments_w, COMMENTS_SIZE); if (r != COMMENTS_SIZE) { break; } @@ -617,7 +617,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.handle_data) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.handle_data, sizeof (*obj->streams.handle_data)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.handle_data, sizeof (*obj->streams.handle_data)); if (r != sizeof (*obj->streams.handle_data)) { break; } @@ -634,7 +634,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.function_table) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.function_table, sizeof (*obj->streams.function_table)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.function_table, sizeof (*obj->streams.function_table)); if (r != sizeof (*obj->streams.function_table)) { break; } @@ -648,7 +648,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m break; case UNLOADED_MODULE_LIST_STREAM: /* TODO: Not yet fully parsed or utilised */ - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&unloaded_module_list, sizeof (unloaded_module_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&unloaded_module_list, sizeof (unloaded_module_list)); if (r != sizeof (unloaded_module_list)) { break; } @@ -667,11 +667,11 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!module) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)module, sizeof (*module)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)module, sizeof (*module)); if (r != sizeof (*module)) { break; } - r_list_append (obj->streams.unloaded_modules, module); + rz_list_append (obj->streams.unloaded_modules, module); offset += sizeof (*module); } break; @@ -681,7 +681,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!obj->streams.misc_info.misc_info_1) { break; } - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.misc_info.misc_info_1, sizeof (*obj->streams.misc_info.misc_info_1)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)obj->streams.misc_info.misc_info_1, sizeof (*obj->streams.misc_info.misc_info_1)); if (r != sizeof (*obj->streams.misc_info.misc_info_1)) { break; } @@ -698,7 +698,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m break; case MEMORY_INFO_LIST_STREAM: - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory_info_list, sizeof (memory_info_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&memory_info_list, sizeof (memory_info_list)); if (r != sizeof (memory_info_list)) { break; } @@ -722,17 +722,17 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!info) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); if (r != sizeof (*info)) { break; } - r_list_append (obj->streams.memory_infos, info); + rz_list_append (obj->streams.memory_infos, info); offset += sizeof (*info); } break; case THREAD_INFO_LIST_STREAM: /* TODO: Not yet fully parsed or utilised */ - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_info_list, sizeof (thread_info_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&thread_info_list, sizeof (thread_info_list)); if (r != sizeof (thread_info_list)) { break; } @@ -752,17 +752,17 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!info) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); if (r != sizeof (*info)) { break; } - r_list_append (obj->streams.thread_infos, info); + rz_list_append (obj->streams.thread_infos, info); offset += sizeof (*info); } break; case HANDLE_OPERATION_LIST_STREAM: /* TODO: Not yet fully parsed or utilised */ - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&handle_operation_list, sizeof (handle_operation_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&handle_operation_list, sizeof (handle_operation_list)); if (r != sizeof (handle_operation_list)) { break; } @@ -778,18 +778,18 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!op) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)op, sizeof (*op)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)op, sizeof (*op)); if (r != sizeof (*op)) { break; } - r_list_append (obj->streams.operations, op); + rz_list_append (obj->streams.operations, op); offset += sizeof (*op); } break; case TOKEN_STREAM: /* TODO: Not fully parsed or utilised */ - r = r_buf_read_at (obj->b, entry->location.rva, (ut8 *)&token_info_list, sizeof (token_info_list)); + r = rz_buf_read_at (obj->b, entry->location.rva, (ut8 *)&token_info_list, sizeof (token_info_list)); if (r != sizeof (token_info_list)) { break; } @@ -808,11 +808,11 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m if (!info) { break; } - r = r_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); + r = rz_buf_read_at (obj->b, offset, (ut8 *)info, sizeof (*info)); if (r != sizeof (*info)) { break; } - r_list_append (obj->streams.token_infos, info); + rz_list_append (obj->streams.token_infos, info); offset += sizeof (*info); } break; @@ -832,7 +832,7 @@ static bool r_bin_mdmp_init_directory_entry(struct r_bin_mdmp_obj *obj, struct m return true; } -static bool r_bin_mdmp_init_directory(struct r_bin_mdmp_obj *obj) { +static bool rz_bin_mdmp_init_directory(struct rz_bin_mdmp_obj *obj) { ut32 i; struct minidump_directory entry; @@ -852,9 +852,9 @@ static bool r_bin_mdmp_init_directory(struct r_bin_mdmp_obj *obj) { /* Parse each entry in the directory */ for (i = 0; i < max_entries; i++) { ut32 delta = i * sizeof (struct minidump_directory); - int r = r_buf_read_at (obj->b, rvadir + delta, (ut8*) &entry, sizeof (struct minidump_directory)); + int r = rz_buf_read_at (obj->b, rvadir + delta, (ut8*) &entry, sizeof (struct minidump_directory)); if (r) { - if (!r_bin_mdmp_init_directory_entry (obj, &entry)) { + if (!rz_bin_mdmp_init_directory_entry (obj, &entry)) { return false; } } @@ -863,21 +863,21 @@ static bool r_bin_mdmp_init_directory(struct r_bin_mdmp_obj *obj) { return true; } -static bool r_bin_mdmp_patch_pe_headers(RBuffer *pe_buf) { +static bool rz_bin_mdmp_patch_pe_headers(RBuffer *pe_buf) { int i; Pe64_image_dos_header dos_hdr; Pe64_image_nt_headers nt_hdr; - r_buf_read_at (pe_buf, 0, (ut8 *)&dos_hdr, sizeof (Pe64_image_dos_header)); - r_buf_read_at (pe_buf, dos_hdr.e_lfanew, (ut8 *)&nt_hdr, sizeof (Pe64_image_nt_headers)); + rz_buf_read_at (pe_buf, 0, (ut8 *)&dos_hdr, sizeof (Pe64_image_dos_header)); + rz_buf_read_at (pe_buf, dos_hdr.e_lfanew, (ut8 *)&nt_hdr, sizeof (Pe64_image_nt_headers)); /* Patch RawData in headers */ ut64 sect_hdrs_off = dos_hdr.e_lfanew + 4 + sizeof (Pe64_image_file_header) + nt_hdr.file_header.SizeOfOptionalHeader; Pe64_image_section_header section_hdr; for (i = 0; i < nt_hdr.file_header.NumberOfSections; i++) { - r_buf_read_at (pe_buf, sect_hdrs_off + i * sizeof (section_hdr), (ut8 *)§ion_hdr, sizeof (section_hdr)); + rz_buf_read_at (pe_buf, sect_hdrs_off + i * sizeof (section_hdr), (ut8 *)§ion_hdr, sizeof (section_hdr)); section_hdr.PointerToRawData = section_hdr.VirtualAddress; - r_buf_write_at (pe_buf, sect_hdrs_off + i * sizeof (section_hdr), (const ut8 *)§ion_hdr, sizeof (section_hdr)); + rz_buf_write_at (pe_buf, sect_hdrs_off + i * sizeof (section_hdr), (const ut8 *)§ion_hdr, sizeof (section_hdr)); } return true; @@ -888,12 +888,12 @@ static int check_pe32_buf(RBuffer *buf, ut64 length) { if (!buf || length <= 0x3d) { return false; } - idx = (r_buf_read8_at (buf, 0x3c) | (r_buf_read8_at (buf, 0x3d)<<8)); + idx = (rz_buf_read8_at (buf, 0x3c) | (rz_buf_read8_at (buf, 0x3d)<<8)); if (length > idx + 0x18 + 2) { ut8 tmp1[2], tmp2[2], tmp3[2]; - r_buf_read_at (buf, 0, tmp1, 2); - r_buf_read_at (buf, idx, tmp2, 2); - r_buf_read_at (buf, idx + 0x18, tmp3, 2); + rz_buf_read_at (buf, 0, tmp1, 2); + rz_buf_read_at (buf, idx, tmp2, 2); + rz_buf_read_at (buf, idx + 0x18, tmp3, 2); if (!memcmp (tmp1, "MZ", 2) && !memcmp (tmp2, "PE", 2) && !memcmp (tmp3, "\x0b\x01", 2)) { return true; } @@ -906,12 +906,12 @@ static int check_pe64_buf(RBuffer *buf, ut64 length) { if (!buf || length <= 0x3d) { return false; } - idx = r_buf_read8_at (buf, 0x3c) | (r_buf_read8_at (buf, 0x3d)<<8); + idx = rz_buf_read8_at (buf, 0x3c) | (rz_buf_read8_at (buf, 0x3d)<<8); if (length >= idx + 0x20) { ut8 tmp1[2], tmp2[2], tmp3[2]; - r_buf_read_at (buf, 0, tmp1, 2); - r_buf_read_at (buf, idx, tmp2, 2); - r_buf_read_at (buf, idx + 0x18, tmp3, 2); + rz_buf_read_at (buf, 0, tmp1, 2); + rz_buf_read_at (buf, idx, tmp2, 2); + rz_buf_read_at (buf, idx + 0x18, tmp3, 2); if (!memcmp (tmp1, "MZ", 2) && !memcmp (tmp2, "PE", 2) && !memcmp (tmp3, "\x0b\x02", 2)) { ret = true; } @@ -919,30 +919,30 @@ static int check_pe64_buf(RBuffer *buf, ut64 length) { return ret; } -static bool r_bin_mdmp_init_pe_bins(struct r_bin_mdmp_obj *obj) { +static bool rz_bin_mdmp_init_pe_bins(struct rz_bin_mdmp_obj *obj) { bool dup; ut64 paddr; struct minidump_module *module; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin, *pe32_dup; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin, *pe64_dup; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin, *pe32_dup; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin, *pe64_dup; RBuffer *buf; - RListIter *it, *it_dup; + RzListIter *it, *it_dup; - r_list_foreach (obj->streams.modules, it, module) { + rz_list_foreach (obj->streams.modules, it, module) { /* Duplicate modules can appear in the MDMP module list, ** filtering them out seems to be the correct behaviour */ - if (!(paddr = r_bin_mdmp_get_paddr (obj, module->base_of_image))) { + if (!(paddr = rz_bin_mdmp_get_paddr (obj, module->base_of_image))) { continue; } ut8 *b = R_NEWS (ut8, module->size_of_image); if (!b) { continue; } - int r = r_buf_read_at (obj->b, paddr, b, module->size_of_image); - buf = r_buf_new_with_bytes (b, r); + int r = rz_buf_read_at (obj->b, paddr, b, module->size_of_image); + buf = rz_buf_new_with_bytes (b, r); dup = false; if (check_pe32_buf (buf, module->size_of_image)) { - r_list_foreach(obj->pe32_bins, it_dup, pe32_dup) { + rz_list_foreach(obj->pe32_bins, it_dup, pe32_dup) { if (pe32_dup->vaddr == module->base_of_image) { dup = true; continue; @@ -951,17 +951,17 @@ static bool r_bin_mdmp_init_pe_bins(struct r_bin_mdmp_obj *obj) { if (dup) { continue; } - if (!(pe32_bin = R_NEW0 (struct Pe32_r_bin_mdmp_pe_bin))) { + if (!(pe32_bin = R_NEW0 (struct Pe32_rz_bin_mdmp_pe_bin))) { continue; } - r_bin_mdmp_patch_pe_headers (buf); + rz_bin_mdmp_patch_pe_headers (buf); pe32_bin->vaddr = module->base_of_image; pe32_bin->paddr = paddr; - pe32_bin->bin = Pe32_r_bin_pe_new_buf (buf, 0); + pe32_bin->bin = Pe32_rz_bin_pe_new_buf (buf, 0); - r_list_append (obj->pe32_bins, pe32_bin); + rz_list_append (obj->pe32_bins, pe32_bin); } else if (check_pe64_buf (buf, module->size_of_image)) { - r_list_foreach(obj->pe64_bins, it_dup, pe64_dup) { + rz_list_foreach(obj->pe64_bins, it_dup, pe64_dup) { if (pe64_dup->vaddr == module->base_of_image) { dup = true; continue; @@ -970,35 +970,35 @@ static bool r_bin_mdmp_init_pe_bins(struct r_bin_mdmp_obj *obj) { if (dup) { continue; } - if (!(pe64_bin = R_NEW0 (struct Pe64_r_bin_mdmp_pe_bin))) { + if (!(pe64_bin = R_NEW0 (struct Pe64_rz_bin_mdmp_pe_bin))) { continue; } - r_bin_mdmp_patch_pe_headers (buf); + rz_bin_mdmp_patch_pe_headers (buf); pe64_bin->vaddr = module->base_of_image; pe64_bin->paddr = paddr; - pe64_bin->bin = Pe64_r_bin_pe_new_buf (buf, 0); + pe64_bin->bin = Pe64_rz_bin_pe_new_buf (buf, 0); - r_list_append (obj->pe64_bins, pe64_bin); + rz_list_append (obj->pe64_bins, pe64_bin); } - r_buf_free (buf); + rz_buf_free (buf); } return true; } -static int r_bin_mdmp_init(struct r_bin_mdmp_obj *obj) { - r_bin_mdmp_init_parsing (obj); +static int rz_bin_mdmp_init(struct rz_bin_mdmp_obj *obj) { + rz_bin_mdmp_init_parsing (obj); - if (!r_bin_mdmp_init_hdr (obj)) { + if (!rz_bin_mdmp_init_hdr (obj)) { eprintf ("[ERROR] Failed to initialise header\n"); return false; } - if (!r_bin_mdmp_init_directory (obj)) { + if (!rz_bin_mdmp_init_directory (obj)) { eprintf ("[ERROR] Failed to initialise directory structures!\n"); return false; } - if (!r_bin_mdmp_init_pe_bins (obj)) { + if (!rz_bin_mdmp_init_pe_bins (obj)) { eprintf ("[ERROR] Failed to initialise pe binaries!\n"); return false; } @@ -1006,37 +1006,37 @@ static int r_bin_mdmp_init(struct r_bin_mdmp_obj *obj) { return true; } -struct r_bin_mdmp_obj *r_bin_mdmp_new_buf(RBuffer *buf) { +struct rz_bin_mdmp_obj *rz_bin_mdmp_new_buf(RBuffer *buf) { bool fail = false; - struct r_bin_mdmp_obj *obj = R_NEW0 (struct r_bin_mdmp_obj); + struct rz_bin_mdmp_obj *obj = R_NEW0 (struct rz_bin_mdmp_obj); if (!obj) { return NULL; } obj->kv = sdb_new0 (); - obj->size = (ut32) r_buf_size (buf); + obj->size = (ut32) rz_buf_size (buf); - fail |= (!(obj->streams.ex_threads = r_list_new ())); - fail |= (!(obj->streams.memories = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.memories64.memories = r_list_new ())); - fail |= (!(obj->streams.memory_infos = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.modules = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.operations = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.thread_infos = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.token_infos = r_list_newf ((RListFree)free))); - fail |= (!(obj->streams.threads = r_list_new ())); - fail |= (!(obj->streams.unloaded_modules = r_list_newf ((RListFree)free))); + fail |= (!(obj->streams.ex_threads = rz_list_new ())); + fail |= (!(obj->streams.memories = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.memories64.memories = rz_list_new ())); + fail |= (!(obj->streams.memory_infos = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.modules = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.operations = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.thread_infos = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.token_infos = rz_list_newf ((RzListFree)free))); + fail |= (!(obj->streams.threads = rz_list_new ())); + fail |= (!(obj->streams.unloaded_modules = rz_list_newf ((RzListFree)free))); - fail |= (!(obj->pe32_bins = r_list_newf (r_bin_mdmp_free_pe32_bin))); - fail |= (!(obj->pe64_bins = r_list_newf (r_bin_mdmp_free_pe64_bin))); + fail |= (!(obj->pe32_bins = rz_list_newf (rz_bin_mdmp_free_pe32_bin))); + fail |= (!(obj->pe64_bins = rz_list_newf (rz_bin_mdmp_free_pe64_bin))); if (fail) { - r_bin_mdmp_free (obj); + rz_bin_mdmp_free (obj); return NULL; } - obj->b = r_buf_ref (buf); - if (!r_bin_mdmp_init (obj)) { - r_bin_mdmp_free (obj); + obj->b = rz_buf_ref (buf); + if (!rz_bin_mdmp_init (obj)) { + rz_bin_mdmp_free (obj); return NULL; } diff --git a/librz/bin/format/mdmp/mdmp.h b/librz/bin/format/mdmp/mdmp.h new file mode 100644 index 0000000000..092a731e2e --- /dev/null +++ b/librz/bin/format/mdmp/mdmp.h @@ -0,0 +1,65 @@ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ + +#ifndef MDMP_H +#define MDMP_H + +#include +#include +#include +#include + +#include "mdmp_specs.h" +#include "mdmp_pe.h" +#include "mdmp_pe64.h" + +struct rz_bin_mdmp_obj { + struct minidump_header *hdr; + + /* Encountered streams */ + struct minidump_streams { + ut8 *comments_a; + ut8 *comments_w; + + struct minidump_exception_stream *exception; + struct minidump_function_table_stream *function_table; + struct minidump_handle_data_stream *handle_data; + struct minidump_system_info *system_info; + + union { + struct minidump_misc_info *misc_info_1; + struct minidump_misc_info_2 *misc_info_2; + } misc_info; + + /* Lists */ + RzList *ex_threads; + RzList *memories; + RzList *memory_infos; + RzList *modules; + RzList *operations; + RzList *thread_infos; + RzList *threads; + RzList *token_infos; + RzList *unloaded_modules; + struct { + rva64_t base_rva; + RzList *memories; + } memories64; + } streams; + + /* Binary memory objects */ + RzList *pe32_bins; + RzList *pe64_bins; + + RBuffer *b; + size_t size; + ut8 endian; + Sdb *kv; +}; + +struct rz_bin_mdmp_obj *rz_bin_mdmp_new_buf(RBuffer *buf); +void rz_bin_mdmp_free(struct rz_bin_mdmp_obj *obj); +ut64 rz_bin_mdmp_get_paddr(struct rz_bin_mdmp_obj *obj, ut64 vaddr); +ut32 rz_bin_mdmp_get_perm(struct rz_bin_mdmp_obj *obj, ut64 vaddr); +struct minidump_memory_info *rz_bin_mdmp_get_mem_info(struct rz_bin_mdmp_obj *obj, ut64 vaddr); + +#endif /* MDMP_H */ diff --git a/libr/bin/format/mdmp/mdmp_pe.c b/librz/bin/format/mdmp/mdmp_pe.c similarity index 76% rename from libr/bin/format/mdmp/mdmp_pe.c rename to librz/bin/format/mdmp/mdmp_pe.c index d28d3a0e61..da0d41623c 100644 --- a/libr/bin/format/mdmp/mdmp_pe.c +++ b/librz/bin/format/mdmp/mdmp_pe.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2016-2018 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016-2018 - Davis, Alex Kornitzer */ -#include -#include +#include +#include #include "mdmp_pe.h" -static void PE_(add_tls_callbacks)(struct PE_(r_bin_pe_obj_t) * bin, RList *list) { +static void PE_(add_tls_callbacks)(struct PE_(rz_bin_pe_obj_t) * bin, RzList *list) { char *key; int count = 0; PE_DWord haddr, paddr, vaddr; @@ -34,22 +34,22 @@ static void PE_(add_tls_callbacks)(struct PE_(r_bin_pe_obj_t) * bin, RList *list ptr->vaddr = vaddr; ptr->hpaddr = haddr; ptr->type = R_BIN_ENTRY_TYPE_TLS; - r_list_append (list, ptr); + rz_list_append (list, ptr); } count++; } while (vaddr); } -RList *PE_(r_bin_mdmp_pe_get_entrypoint) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { +RzList *PE_(rz_bin_mdmp_pe_get_entrypoint) (struct PE_(rz_bin_mdmp_pe_bin) * pe_bin) { ut64 offset; - struct r_bin_pe_addr_t *entry = NULL; + struct rz_bin_pe_addr_t *entry = NULL; RBinAddr *ptr = NULL; - RList *ret; + RzList *ret; - if (!(entry = PE_(r_bin_pe_get_entrypoint) (pe_bin->bin))) { + if (!(entry = PE_(rz_bin_pe_get_entrypoint) (pe_bin->bin))) { return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } @@ -63,7 +63,7 @@ RList *PE_(r_bin_mdmp_pe_get_entrypoint) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin ptr->hpaddr = pe_bin->paddr + entry->haddr; ptr->type = R_BIN_ENTRY_TYPE_PROGRAM; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } PE_(add_tls_callbacks) @@ -84,17 +84,17 @@ static void filter_import(ut8 *n) { } } -RList *PE_(r_bin_mdmp_pe_get_imports) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { +RzList *PE_(rz_bin_mdmp_pe_get_imports) (struct PE_(rz_bin_mdmp_pe_bin) * pe_bin) { int i; ut64 offset; - struct r_bin_pe_import_t *imports = NULL; + struct rz_bin_pe_import_t *imports = NULL; RBinImport *ptr = NULL; RBinReloc *rel; - RList *ret, *relocs; + RzList *ret, *relocs; - imports = PE_(r_bin_pe_get_imports) (pe_bin->bin); - ret = r_list_new (); - relocs = r_list_newf (free); + imports = PE_(rz_bin_pe_get_imports) (pe_bin->bin); + ret = rz_list_new (); + relocs = rz_list_newf (free); if (!imports || !ret || !relocs) { free (imports); @@ -114,7 +114,7 @@ RList *PE_(r_bin_mdmp_pe_get_imports) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { ptr->bind = "NONE"; ptr->type = R_BIN_TYPE_FUNC_STR; ptr->ordinal = imports[i].ordinal; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(rel = R_NEW0 (RBinReloc))) { break; @@ -133,29 +133,29 @@ RList *PE_(r_bin_mdmp_pe_get_imports) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { rel->addend = 0; rel->vaddr = offset + pe_bin->vaddr; rel->paddr = imports[i].paddr + pe_bin->paddr; - r_list_append (relocs, rel); + rz_list_append (relocs, rel); } free (imports); return ret; } -RList *PE_(r_bin_mdmp_pe_get_sections) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { +RzList *PE_(rz_bin_mdmp_pe_get_sections) (struct PE_(rz_bin_mdmp_pe_bin) * pe_bin) { /* TODO: Vet code, taken verbatim(ish) from bin_pe.c */ int i; ut64 ba = pe_bin->vaddr; //baddr (arch); - struct r_bin_pe_section_t *sections = NULL; + struct rz_bin_pe_section_t *sections = NULL; RBinSection *ptr; - RList *ret; + RzList *ret; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!pe_bin->bin || !(sections = pe_bin->bin->sections)) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - PE_(r_bin_pe_check_sections) + PE_(rz_bin_pe_check_sections) (pe_bin->bin, §ions); for (i = 0; !sections[i].last; i++) { if (!(ptr = R_NEW0 (RBinSection))) { @@ -202,25 +202,25 @@ RList *PE_(r_bin_mdmp_pe_get_sections) (struct PE_(r_bin_mdmp_pe_bin) * pe_bin) ptr->is_data = true; } } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -RList *PE_(r_bin_mdmp_pe_get_symbols) (RBin *rbin, struct PE_(r_bin_mdmp_pe_bin) * pe_bin) { +RzList *PE_(rz_bin_mdmp_pe_get_symbols) (RBin *rbin, struct PE_(rz_bin_mdmp_pe_bin) * pe_bin) { int i; ut64 offset; - struct r_bin_pe_export_t *symbols = NULL; - struct r_bin_pe_import_t *imports = NULL; + struct rz_bin_pe_export_t *symbols = NULL; + struct rz_bin_pe_import_t *imports = NULL; RBinSymbol *ptr = NULL; - RList *ret; + RzList *ret; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } /* TODO: Load symbol table from pdb file */ - if ((symbols = PE_(r_bin_pe_get_exports) (pe_bin->bin))) { + if ((symbols = PE_(rz_bin_pe_get_exports) (pe_bin->bin))) { for (i = 0; !symbols[i].last; i++) { if (!(ptr = R_NEW0 (RBinSymbol))) { break; @@ -231,7 +231,7 @@ RList *PE_(r_bin_mdmp_pe_get_symbols) (RBin *rbin, struct PE_(r_bin_mdmp_pe_bin) } ptr->name = strdup ((char *)symbols[i].name); ptr->libname = *symbols[i].libname ? strdup ((char *)symbols[i].libname) : NULL; - ptr->forwarder = r_str_constpool_get (&rbin->constpool, (char *)symbols[i].forwarder); + ptr->forwarder = rz_str_constpool_get (&rbin->constpool, (char *)symbols[i].forwarder); ptr->bind = R_BIN_BIND_GLOBAL_STR; ptr->type = R_BIN_TYPE_FUNC_STR; ptr->size = 0; @@ -239,12 +239,12 @@ RList *PE_(r_bin_mdmp_pe_get_symbols) (RBin *rbin, struct PE_(r_bin_mdmp_pe_bin) ptr->paddr = symbols[i].paddr + pe_bin->paddr; ptr->ordinal = symbols[i].ordinal; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (symbols); } /* Calling imports is unstable at the moment, I think this is an issue in pe.c */ - if ((imports = PE_(r_bin_pe_get_imports) (pe_bin->bin))) { + if ((imports = PE_(rz_bin_pe_get_imports) (pe_bin->bin))) { for (i = 0; !imports[i].last; i++) { if (!(ptr = R_NEW0 (RBinSymbol))) { break; @@ -263,7 +263,7 @@ RList *PE_(r_bin_mdmp_pe_get_symbols) (RBin *rbin, struct PE_(r_bin_mdmp_pe_bin) ptr->paddr = imports[i].paddr + pe_bin->paddr; ptr->ordinal = imports[i].ordinal; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (imports); } diff --git a/librz/bin/format/mdmp/mdmp_pe.h b/librz/bin/format/mdmp/mdmp_pe.h new file mode 100644 index 0000000000..7e6f6a0d40 --- /dev/null +++ b/librz/bin/format/mdmp/mdmp_pe.h @@ -0,0 +1,27 @@ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ + +#ifndef MDMP_PE_H +#define MDMP_PE_H + +#include +#include +#include +#include + +#include "pe/pe.h" + +#include "mdmp_specs.h" + +struct PE_(rz_bin_mdmp_pe_bin) { + ut64 vaddr; + ut64 paddr; + struct PE_(rz_bin_pe_obj_t) *bin; +}; + + +RzList *PE_(rz_bin_mdmp_pe_get_entrypoint)(struct PE_(rz_bin_mdmp_pe_bin) *pe_bin); +RzList *PE_(rz_bin_mdmp_pe_get_imports)(struct PE_(rz_bin_mdmp_pe_bin) *pe_bin); +RzList *PE_(rz_bin_mdmp_pe_get_sections)(struct PE_(rz_bin_mdmp_pe_bin) *pe_bin); +RzList *PE_(rz_bin_mdmp_pe_get_symbols)(RBin *rbin, struct PE_(rz_bin_mdmp_pe_bin) *pe_bin); + +#endif /* MDMP_PE_H */ diff --git a/librz/bin/format/mdmp/mdmp_pe64.c b/librz/bin/format/mdmp/mdmp_pe64.c new file mode 100644 index 0000000000..0b96492340 --- /dev/null +++ b/librz/bin/format/mdmp/mdmp_pe64.c @@ -0,0 +1,4 @@ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ + +#define R_BIN_PE64 1 +#include "mdmp_pe.c" diff --git a/libr/bin/format/mdmp/mdmp_pe64.h b/librz/bin/format/mdmp/mdmp_pe64.h similarity index 75% rename from libr/bin/format/mdmp/mdmp_pe64.h rename to librz/bin/format/mdmp/mdmp_pe64.h index 23bfacb268..dd225df9cf 100644 --- a/libr/bin/format/mdmp/mdmp_pe64.h +++ b/librz/bin/format/mdmp/mdmp_pe64.h @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ #ifndef MDMP_PE64_H #define MDMP_PE64_H diff --git a/libr/bin/format/mdmp/mdmp_specs.h b/librz/bin/format/mdmp/mdmp_specs.h similarity index 99% rename from libr/bin/format/mdmp/mdmp_specs.h rename to librz/bin/format/mdmp/mdmp_specs.h index b59e3375c9..b4e1ca6b55 100644 --- a/libr/bin/format/mdmp/mdmp_specs.h +++ b/librz/bin/format/mdmp/mdmp_specs.h @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ #ifndef MDMP_SPECS_H #define MDMP_SPECS_H -#include +#include #include "mdmp_windefs.h" diff --git a/libr/bin/format/mdmp/mdmp_windefs.h b/librz/bin/format/mdmp/mdmp_windefs.h similarity index 99% rename from libr/bin/format/mdmp/mdmp_windefs.h rename to librz/bin/format/mdmp/mdmp_windefs.h index 1f9fb548d2..a7cef45690 100644 --- a/libr/bin/format/mdmp/mdmp_windefs.h +++ b/librz/bin/format/mdmp/mdmp_windefs.h @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016 - Davis, Alex Kornitzer */ #ifndef MDMP_WINDEFS_H #define MDMP_WINDEFS_H diff --git a/libr/bin/format/mz/mz.c b/librz/bin/format/mz/mz.c similarity index 63% rename from libr/bin/format/mz/mz.c rename to librz/bin/format/mz/mz.c index f00f4588c6..6f6aa8959c 100644 --- a/libr/bin/format/mz/mz.c +++ b/librz/bin/format/mz/mz.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2015-2018 nodepad, pancake */ #include "mz.h" -#include +#include -static ut64 r_bin_mz_va_to_la(const ut16 segment, const ut16 offset) { +static ut64 rz_bin_mz_va_to_la(const ut16 segment, const ut16 offset) { return (segment << 4) + offset; } -static ut64 r_bin_mz_la_to_pa(const struct r_bin_mz_obj_t *bin, ut64 la) { +static ut64 rz_bin_mz_la_to_pa(const struct rz_bin_mz_obj_t *bin, ut64 la) { return la + (bin->dos_header->header_paragraphs << 4); } -RBinAddr *r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin) { +RBinAddr *rz_bin_mz_get_entrypoint (const struct rz_bin_mz_obj_t *bin) { const MZ_image_dos_header *mz; ut64 la; RBinAddr *entrypoint; @@ -21,7 +21,7 @@ RBinAddr *r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin) { } mz = bin->dos_header; - la = r_bin_mz_va_to_la (mz->cs, mz->ip); + la = rz_bin_mz_va_to_la (mz->cs, mz->ip); la &= 0xfffff; if (la >= bin->load_module_size) { eprintf ("Error: entry point outside load module\n"); @@ -30,7 +30,7 @@ RBinAddr *r_bin_mz_get_entrypoint (const struct r_bin_mz_obj_t *bin) { entrypoint = R_NEW0 (RBinAddr); if (entrypoint) { entrypoint->vaddr = la; - entrypoint->paddr = r_bin_mz_la_to_pa (bin, la); + entrypoint->paddr = rz_bin_mz_la_to_pa (bin, la); } return entrypoint; @@ -45,7 +45,7 @@ static int cmp_sections(const void *a, const void *b) { return s_a->vaddr - s_b->vaddr; } -static RBinSection *r_bin_mz_init_section(const struct r_bin_mz_obj_t *bin, +static RBinSection *rz_bin_mz_init_section(const struct rz_bin_mz_obj_t *bin, ut64 laddr) { RBinSection *section; @@ -57,9 +57,9 @@ static RBinSection *r_bin_mz_init_section(const struct r_bin_mz_obj_t *bin, return section; } -RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin) { - RList *seg_list; - RListIter *iter; +RzList *rz_bin_mz_get_segments (const struct rz_bin_mz_obj_t *bin) { + RzList *seg_list; + RzListIter *iter; RBinSection *section; MZ_image_relocation_entry *relocs; int i, num_relocs, section_number; @@ -69,7 +69,7 @@ RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin) { return NULL; } - seg_list = r_list_newf (free); + seg_list = rz_list_newf (free); if (!seg_list) { return NULL; } @@ -77,11 +77,11 @@ RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin) { /* Add address of first segment to make sure that it is present * even if there are no relocations or there isn't first segment in * the relocations. */ - section = r_bin_mz_init_section (bin, 0); + section = rz_bin_mz_init_section (bin, 0); if (!section) { goto err_out; } - r_list_add_sorted (seg_list, section, cmp_sections); + rz_list_add_sorted (seg_list, section, cmp_sections); relocs = bin->relocation_entries; num_relocs = bin->dos_header->num_relocs; @@ -90,60 +90,60 @@ RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin) { ut64 laddr, paddr, section_laddr; ut16 curr_seg; - laddr = r_bin_mz_va_to_la (relocs[i].segment, relocs[i].offset); + laddr = rz_bin_mz_va_to_la (relocs[i].segment, relocs[i].offset); if ((laddr + 2) >= bin->load_module_size) { continue; } - paddr = r_bin_mz_la_to_pa (bin, laddr); - if (r_buf_size (bin->b) < paddr + 2) { + paddr = rz_bin_mz_la_to_pa (bin, laddr); + if (rz_buf_size (bin->b) < paddr + 2) { continue; } - curr_seg = r_buf_read_le16_at (bin->b, paddr); + curr_seg = rz_buf_read_le16_at (bin->b, paddr); - section_laddr = r_bin_mz_va_to_la (curr_seg, 0); + section_laddr = rz_bin_mz_va_to_la (curr_seg, 0); if (section_laddr > bin->load_module_size) { continue; } c.vaddr = section_laddr; - if (r_list_find (seg_list, &c, cmp_sections)) { + if (rz_list_find (seg_list, &c, cmp_sections)) { continue; } - section = r_bin_mz_init_section (bin, section_laddr); + section = rz_bin_mz_init_section (bin, section_laddr); if (!section) { goto err_out; } - r_list_add_sorted (seg_list, section, cmp_sections); + rz_list_add_sorted (seg_list, section, cmp_sections); } /* Add address of stack segment if it's inside the load module. */ ss = bin->dos_header->ss; - if (r_bin_mz_va_to_la (ss, 0) < bin->load_module_size) { - section = r_bin_mz_init_section (bin, r_bin_mz_va_to_la (ss, 0)); + if (rz_bin_mz_va_to_la (ss, 0) < bin->load_module_size) { + section = rz_bin_mz_init_section (bin, rz_bin_mz_va_to_la (ss, 0)); if (!section) { goto err_out; } - r_list_add_sorted (seg_list, section, cmp_sections); + rz_list_add_sorted (seg_list, section, cmp_sections); } /* Fixup sizes and addresses, set name, permissions and set add flag */ section_number = 0; - r_list_foreach (seg_list, iter, section) { - section->name = r_str_newf ("seg_%03d", section_number); + rz_list_foreach (seg_list, iter, section) { + section->name = rz_str_newf ("seg_%03d", section_number); if (section_number) { RBinSection *p_section = iter->p->data; p_section->size = section->vaddr - p_section->vaddr; p_section->vsize = p_section->size; } section->vsize = section->size; - section->paddr = r_bin_mz_la_to_pa (bin, section->vaddr); - section->perm = r_str_rwx ("rwx"); + section->paddr = rz_bin_mz_la_to_pa (bin, section->vaddr); + section->perm = rz_str_rwx ("rwx"); section->add = true; section_number++; } - section = r_list_get_top (seg_list); + section = rz_list_get_top (seg_list); section->size = bin->load_module_size - section->vaddr; section->vsize = section->size; @@ -151,25 +151,25 @@ RList *r_bin_mz_get_segments (const struct r_bin_mz_obj_t *bin) { err_out: eprintf ("Error: alloc (RBinSection)\n"); - r_list_free (seg_list); + rz_list_free (seg_list); return NULL; } -struct r_bin_mz_reloc_t *r_bin_mz_get_relocs (const struct r_bin_mz_obj_t *bin) { +struct rz_bin_mz_reloc_t *rz_bin_mz_get_relocs (const struct rz_bin_mz_obj_t *bin) { int i, j; const int num_relocs = bin->dos_header->num_relocs; const MZ_image_relocation_entry *const rel_entry = bin->relocation_entries; - struct r_bin_mz_reloc_t *relocs = calloc (num_relocs + 1, sizeof (*relocs)); + struct rz_bin_mz_reloc_t *relocs = calloc (num_relocs + 1, sizeof (*relocs)); if (!relocs) { - eprintf ("Error: calloc (struct r_bin_mz_reloc_t)\n"); + eprintf ("Error: calloc (struct rz_bin_mz_reloc_t)\n"); return NULL; } for (i = 0, j = 0; i < num_relocs; i++) { - relocs[j].vaddr = r_bin_mz_va_to_la (rel_entry[i].segment, + relocs[j].vaddr = rz_bin_mz_va_to_la (rel_entry[i].segment, rel_entry[i].offset); - relocs[j].paddr = r_bin_mz_la_to_pa (bin, relocs[j].vaddr); + relocs[j].paddr = rz_bin_mz_la_to_pa (bin, relocs[j].vaddr); /* Add only relocations which resides inside dos executable */ if (relocs[j].vaddr < bin->load_module_size) { @@ -181,29 +181,29 @@ struct r_bin_mz_reloc_t *r_bin_mz_get_relocs (const struct r_bin_mz_obj_t *bin) return relocs; } -void *r_bin_mz_free (struct r_bin_mz_obj_t *bin) { +void *rz_bin_mz_free (struct rz_bin_mz_obj_t *bin) { if (!bin) { return NULL; } free ((void *)bin->dos_header); free ((void *)bin->dos_extended_header); free ((void *)bin->relocation_entries); - r_buf_free (bin->b); + rz_buf_free (bin->b); bin->b = NULL; free (bin); return NULL; } -static int r_bin_mz_init_hdr(struct r_bin_mz_obj_t *bin) { +static int rz_bin_mz_init_hdr(struct rz_bin_mz_obj_t *bin) { int relocations_size, dos_file_size; MZ_image_dos_header *mz; if (!(mz = R_NEW0 (MZ_image_dos_header))) { - r_sys_perror ("malloc (MZ_image_dos_header)"); + rz_sys_perror ("malloc (MZ_image_dos_header)"); return false; } bin->dos_header = mz; // TODO: read field by field to avoid endian and alignment issues - if (r_buf_read_at (bin->b, 0, (ut8 *)mz, sizeof (*mz)) == -1) { + if (rz_buf_read_at (bin->b, 0, (ut8 *)mz, sizeof (*mz)) == -1) { eprintf ("Error: read (MZ_image_dos_header)\n"); return false; } @@ -242,10 +242,10 @@ static int r_bin_mz_init_hdr(struct r_bin_mz_obj_t *bin) { if (bin->dos_extended_header_size > 0) { if (!(bin->dos_extended_header = malloc (bin->dos_extended_header_size))) { - r_sys_perror ("malloc (dos extended header)"); + rz_sys_perror ("malloc (dos extended header)"); return false; } - if (r_buf_read_at (bin->b, sizeof (MZ_image_dos_header), + if (rz_buf_read_at (bin->b, sizeof (MZ_image_dos_header), (ut8 *)bin->dos_extended_header, bin->dos_extended_header_size) == -1) { eprintf ("Error: read (dos extended header)\n"); @@ -255,10 +255,10 @@ static int r_bin_mz_init_hdr(struct r_bin_mz_obj_t *bin) { if (relocations_size > 0) { if (!(bin->relocation_entries = malloc (relocations_size))) { - r_sys_perror ("malloc (dos relocation entries)"); + rz_sys_perror ("malloc (dos relocation entries)"); return false; } - if (r_buf_read_at (bin->b, bin->dos_header->reloc_table_offset, + if (rz_buf_read_at (bin->b, bin->dos_header->reloc_table_offset, (ut8 *)bin->relocation_entries, relocations_size) == -1) { eprintf ("Error: read (dos relocation entries)\n"); R_FREE (bin->relocation_entries); @@ -268,67 +268,67 @@ static int r_bin_mz_init_hdr(struct r_bin_mz_obj_t *bin) { return true; } -static bool r_bin_mz_init(struct r_bin_mz_obj_t *bin) { +static bool rz_bin_mz_init(struct rz_bin_mz_obj_t *bin) { bin->dos_header = NULL; bin->dos_extended_header = NULL; bin->relocation_entries = NULL; bin->kv = sdb_new0 (); - if (!r_bin_mz_init_hdr (bin)) { + if (!rz_bin_mz_init_hdr (bin)) { eprintf ("Warning: File is not MZ\n"); return false; } return true; } -struct r_bin_mz_obj_t *r_bin_mz_new (const char *file) { - struct r_bin_mz_obj_t *bin = R_NEW0 (struct r_bin_mz_obj_t); +struct rz_bin_mz_obj_t *rz_bin_mz_new (const char *file) { + struct rz_bin_mz_obj_t *bin = R_NEW0 (struct rz_bin_mz_obj_t); if (!bin) { return NULL; } bin->file = file; size_t binsz; - ut8 *buf = (ut8*)r_file_slurp (file, &binsz); + ut8 *buf = (ut8*)rz_file_slurp (file, &binsz); bin->size = binsz; if (!buf) { - return r_bin_mz_free (bin); + return rz_bin_mz_free (bin); } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { free ((void *)buf); - return r_bin_mz_free (bin); + return rz_bin_mz_free (bin); } free ((void *)buf); - if (!r_bin_mz_init (bin)) { - return r_bin_mz_free (bin); + if (!rz_bin_mz_init (bin)) { + return rz_bin_mz_free (bin); } return bin; } -struct r_bin_mz_obj_t *r_bin_mz_new_buf(RBuffer *buf) { - struct r_bin_mz_obj_t *bin = R_NEW0 (struct r_bin_mz_obj_t); +struct rz_bin_mz_obj_t *rz_bin_mz_new_buf(RBuffer *buf) { + struct rz_bin_mz_obj_t *bin = R_NEW0 (struct rz_bin_mz_obj_t); if (!bin) { return NULL; } - bin->b = r_buf_new_with_buf (buf); + bin->b = rz_buf_new_with_buf (buf); if (!bin->b) { - return r_bin_mz_free (bin); + return rz_bin_mz_free (bin); } - bin->size = r_buf_size (buf); - return r_bin_mz_init (bin)? bin: r_bin_mz_free (bin); + bin->size = rz_buf_size (buf); + return rz_bin_mz_init (bin)? bin: rz_bin_mz_free (bin); } -RBinAddr *r_bin_mz_get_main_vaddr (struct r_bin_mz_obj_t *bin) { +RBinAddr *rz_bin_mz_get_main_vaddr (struct rz_bin_mz_obj_t *bin) { int n; ut8 b[512]; if (!bin || !bin->b) { return NULL; } - RBinAddr *entry = r_bin_mz_get_entrypoint (bin); + RBinAddr *entry = rz_bin_mz_get_entrypoint (bin); if (!entry) { return NULL; } ZERO_FILL (b); - if (r_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { + if (rz_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { eprintf ("Warning: Cannot read entry at 0x%16" PFMT64x "\n", (ut64)entry->paddr); free (entry); return NULL; @@ -342,10 +342,10 @@ RBinAddr *r_bin_mz_get_main_vaddr (struct r_bin_mz_obj_t *bin) { // 50 push ax for (n = 0; n < sizeof (b) - 18; n++) { if (b[n] == 0xff && b[n + 4] == 0xff && b[n + 8] == 0xff && b[n + 12] == 0x9a && b[n + 17] == 0x50) { - const ut16 call_addr = r_read_ble16 (b + n + 13, 0); - const ut16 call_seg = r_read_ble16 (b + n + 15, 0); - entry->vaddr = r_bin_mz_va_to_la (call_seg, call_addr); - entry->paddr = r_bin_mz_la_to_pa (bin, entry->vaddr); + const ut16 call_addr = rz_read_ble16 (b + n + 13, 0); + const ut16 call_seg = rz_read_ble16 (b + n + 15, 0); + entry->vaddr = rz_bin_mz_va_to_la (call_seg, call_addr); + entry->paddr = rz_bin_mz_la_to_pa (bin, entry->vaddr); return entry; } } diff --git a/librz/bin/format/mz/mz.h b/librz/bin/format/mz/mz.h new file mode 100644 index 0000000000..9e3b20c8d0 --- /dev/null +++ b/librz/bin/format/mz/mz.h @@ -0,0 +1,48 @@ +/* radare - LGPL - Copyright 2015 nodepad */ + +#ifndef MZ_H +#define MZ_H + +#include +#include +#include +#include +#include "mz_specs.h" + +struct rz_bin_mz_segment_t { + ut64 paddr; + ut64 vaddr; + ut64 size; + int last; +}; + +struct rz_bin_mz_reloc_t { + ut64 paddr; + ut64 vaddr; + int last; +}; + +struct rz_bin_mz_obj_t { + const MZ_image_dos_header *dos_header; + const void *dos_extended_header; + MZ_image_relocation_entry *relocation_entries; + + int dos_extended_header_size; + + int size; + int dos_file_size; /* Size of dos file from dos executable header */ + int load_module_size; /* Size of load module: dos_file_size - header size */ + const char *file; + RBuffer *b; + Sdb *kv; +}; + +RBinAddr *rz_bin_mz_get_entrypoint (const struct rz_bin_mz_obj_t *bin); +RzList *rz_bin_mz_get_segments (const struct rz_bin_mz_obj_t *bin); +struct rz_bin_mz_reloc_t *rz_bin_mz_get_relocs (const struct rz_bin_mz_obj_t *bin); +void *rz_bin_mz_free (struct rz_bin_mz_obj_t *bin); +struct rz_bin_mz_obj_t *rz_bin_mz_new (const char *file); +struct rz_bin_mz_obj_t *rz_bin_mz_new_buf(RBuffer *buf); +RBinAddr *rz_bin_mz_get_main_vaddr (struct rz_bin_mz_obj_t *bin); + +#endif diff --git a/libr/bin/format/mz/mz_specs.h b/librz/bin/format/mz/mz_specs.h similarity index 100% rename from libr/bin/format/mz/mz_specs.h rename to librz/bin/format/mz/mz_specs.h diff --git a/libr/bin/format/ne/ne.c b/librz/bin/format/ne/ne.c similarity index 69% rename from libr/bin/format/ne/ne.c rename to librz/bin/format/ne/ne.c index 568d1756a2..6f197426d2 100644 --- a/libr/bin/format/ne/ne.c +++ b/librz/bin/format/ne/ne.c @@ -2,7 +2,7 @@ #include "ne.h" -static char *__get_target_os(r_bin_ne_obj_t *bin) { +static char *__get_target_os(rz_bin_ne_obj_t *bin) { switch (bin->ne_header->targOS) { case 1: return "OS/2"; @@ -35,7 +35,7 @@ static int __translate_perms(int flags) { } static char *__read_nonnull_str_at(RBuffer *buf, ut64 offset) { - ut8 sz = r_buf_read8_at (buf, offset); + ut8 sz = rz_buf_read8_at (buf, offset); if (!sz) { return NULL; } @@ -43,16 +43,16 @@ static char *__read_nonnull_str_at(RBuffer *buf, ut64 offset) { if (!str) { return NULL; } - r_buf_read_at (buf, offset + 1, (ut8 *)str, sz); + rz_buf_read_at (buf, offset + 1, (ut8 *)str, sz); str[sz] = '\0'; return str; } static char *__func_name_from_ord(char *module, ut16 ordinal) { - char *path = r_str_newf (R_JOIN_4_PATHS ("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), r_sys_prefix (NULL), module); - char *ord = r_str_newf ("%d", ordinal); + char *path = rz_str_newf (R_JOIN_4_PATHS ("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), rz_sys_prefix (NULL), module); + char *ord = rz_str_newf ("%d", ordinal); char *name; - if (r_file_exists (path)) { + if (rz_file_exists (path)) { Sdb *sdb = sdb_new (NULL, path, 0); name = sdb_get (sdb, ord, NULL); if (!name) { @@ -68,12 +68,12 @@ static char *__func_name_from_ord(char *module, ut16 ordinal) { return name; } -RList *r_bin_ne_get_segments(r_bin_ne_obj_t *bin) { +RzList *rz_bin_ne_get_segments(rz_bin_ne_obj_t *bin) { int i; if (!bin) { return NULL; } - RList *segments = r_list_newf (free); + RzList *segments = rz_list_newf (free); for (i = 0; i < bin->ne_header->SegCount; i++) { RBinSection *bs = R_NEW0 (RBinSection); NE_image_segment_entry *se = &bin->segment_entries[i]; @@ -86,9 +86,9 @@ RList *r_bin_ne_get_segments(r_bin_ne_obj_t *bin) { bs->is_data = se->flags & IS_DATA; bs->perm = __translate_perms (se->flags); bs->paddr = (ut64)se->offset * bin->alignment; - bs->name = r_str_newf ("%s.%d", se->flags & IS_MOVEABLE ? "MOVEABLE" : "FIXED", bs->paddr); + bs->name = rz_str_newf ("%s.%d", se->flags & IS_MOVEABLE ? "MOVEABLE" : "FIXED", bs->paddr); bs->is_segment = true; - r_list_append (segments, bs); + rz_list_append (segments, bs); } bin->segments = segments; return segments; @@ -98,23 +98,23 @@ static int __find_symbol_by_paddr (const void *paddr, const void *sym) { return (int)!(*(ut64 *)paddr == ((RBinSymbol *)sym)->paddr); } -RList *r_bin_ne_get_symbols(r_bin_ne_obj_t *bin) { +RzList *rz_bin_ne_get_symbols(rz_bin_ne_obj_t *bin) { RBinSymbol *sym; ut16 off = bin->ne_header->ResidNamTable + bin->header_offset; - RList *symbols = r_list_newf (free); + RzList *symbols = rz_list_newf (free); if (!symbols) { return NULL; } - RList *entries = r_bin_ne_get_entrypoints (bin); + RzList *entries = rz_bin_ne_get_entrypoints (bin); bool resident = true, first = true; while (true) { - ut8 sz = r_buf_read8_at (bin->buf, off); + ut8 sz = rz_buf_read8_at (bin->buf, off); if (!sz) { first = true; if (resident) { resident = false; off = bin->ne_header->OffStartNonResTab; - sz = r_buf_read8_at (bin->buf, off); + sz = rz_buf_read8_at (bin->buf, off); if (!sz) { break; } @@ -127,7 +127,7 @@ RList *r_bin_ne_get_symbols(r_bin_ne_obj_t *bin) { break; } off++; - r_buf_read_at (bin->buf, off, (ut8 *)name, sz); + rz_buf_read_at (bin->buf, off, (ut8 *)name, sz); name[sz] = '\0'; off += sz; sym = R_NEW0 (RBinSymbol); @@ -138,32 +138,32 @@ RList *r_bin_ne_get_symbols(r_bin_ne_obj_t *bin) { if (!first) { sym->bind = R_BIN_BIND_GLOBAL_STR; } - ut16 entry_off = r_buf_read_le16_at (bin->buf, off); + ut16 entry_off = rz_buf_read_le16_at (bin->buf, off); off += 2; - RBinAddr *entry = r_list_get_n (entries, entry_off); + RBinAddr *entry = rz_list_get_n (entries, entry_off); if (entry) { sym->paddr = entry->paddr; } else { sym->paddr = -1; } sym->ordinal = entry_off; - r_list_append (symbols, sym); + rz_list_append (symbols, sym); first = false; } - RListIter *it; + RzListIter *it; RBinAddr *en; int i = 1; - r_list_foreach (entries, it, en) { - if (!r_list_find (symbols, &en->paddr, __find_symbol_by_paddr)) { + rz_list_foreach (entries, it, en) { + if (!rz_list_find (symbols, &en->paddr, __find_symbol_by_paddr)) { sym = R_NEW0 (RBinSymbol); if (!sym) { break; } - sym->name = r_str_newf ("entry%d", i - 1); + sym->name = rz_str_newf ("entry%d", i - 1); sym->paddr = en->paddr; sym->bind = R_BIN_BIND_GLOBAL_STR; sym->ordinal = i; - r_list_append (symbols, sym); + rz_list_append (symbols, sym); } i++; } @@ -241,42 +241,42 @@ static char *__resource_type_str(int type) { typeName = "MANIFEST"; break; default: - return r_str_newf ("UNKNOWN (%d)", type); + return rz_str_newf ("UNKNOWN (%d)", type); } return strdup (typeName); } static void __free_resource_entry(void *entry) { - r_ne_resource_entry *en = (r_ne_resource_entry *)entry; + rz_ne_resource_entry *en = (rz_ne_resource_entry *)entry; free (en->name); free (en); } static void __free_resource(void *resource) { - r_ne_resource *res = (r_ne_resource *)resource; + rz_ne_resource *res = (rz_ne_resource *)resource; free (res->name); - r_list_free (res->entry); + rz_list_free (res->entry); free (res); } -static bool __ne_get_resources(r_bin_ne_obj_t *bin) { +static bool __ne_get_resources(rz_bin_ne_obj_t *bin) { if (!bin->resources) { - bin->resources = r_list_newf (__free_resource); + bin->resources = rz_list_newf (__free_resource); } ut16 resoff = bin->ne_header->ResTableOffset + bin->header_offset; - ut16 alignment = r_buf_read_le16_at (bin->buf, resoff); + ut16 alignment = rz_buf_read_le16_at (bin->buf, resoff); ut32 off = resoff + 2; while (true) { NE_image_typeinfo_entry ti = {0}; - r_ne_resource *res = R_NEW0 (r_ne_resource); + rz_ne_resource *res = R_NEW0 (rz_ne_resource); if (!res) { break; } - res->entry = r_list_newf (__free_resource_entry); + res->entry = rz_list_newf (__free_resource_entry); if (!res->entry) { break; } - r_buf_read_at (bin->buf, off, (ut8 *)&ti, sizeof (ti)); + rz_buf_read_at (bin->buf, off, (ut8 *)&ti, sizeof (ti)); if (!ti.rtTypeID) { break; } else if (ti.rtTypeID & 0x8000) { @@ -289,29 +289,29 @@ static bool __ne_get_resources(r_bin_ne_obj_t *bin) { int i; for (i = 0; i < ti.rtResourceCount; i++) { NE_image_nameinfo_entry ni; - r_ne_resource_entry *ren = R_NEW0 (r_ne_resource_entry); + rz_ne_resource_entry *ren = R_NEW0 (rz_ne_resource_entry); if (!ren) { break; } - r_buf_read_at (bin->buf, off, (ut8 *)&ni, sizeof (NE_image_nameinfo_entry)); + rz_buf_read_at (bin->buf, off, (ut8 *)&ni, sizeof (NE_image_nameinfo_entry)); ren->offset = ni.rnOffset << alignment; ren->size = ni.rnLength; if (ni.rnID & 0x8000) { - ren->name = r_str_newf ("%d", ni.rnID & ~0x8000); + ren->name = rz_str_newf ("%d", ni.rnID & ~0x8000); } else { // Offset to resident name table ren->name = __read_nonnull_str_at (bin->buf, (ut64)resoff + ni.rnID); } - r_list_append (res->entry, ren); + rz_list_append (res->entry, ren); off += sizeof (NE_image_nameinfo_entry); } - r_list_append (bin->resources, res); + rz_list_append (bin->resources, res); } return true; } -RList *r_bin_ne_get_imports(r_bin_ne_obj_t *bin) { - RList *imports = r_list_newf (free); +RzList *rz_bin_ne_get_imports(rz_bin_ne_obj_t *bin) { + RzList *imports = rz_list_newf (free); if (!imports) { return NULL; } @@ -322,9 +322,9 @@ RList *r_bin_ne_get_imports(r_bin_ne_obj_t *bin) { if (!imp) { break; } - ut8 sz = r_buf_read8_at (bin->buf, off); + ut8 sz = rz_buf_read8_at (bin->buf, off); if (!sz) { - r_bin_import_free (imp); + rz_bin_import_free (imp); break; } off++; @@ -332,38 +332,38 @@ RList *r_bin_ne_get_imports(r_bin_ne_obj_t *bin) { if (!name) { break; } - r_buf_read_at (bin->buf, off, (ut8 *)name, sz); + rz_buf_read_at (bin->buf, off, (ut8 *)name, sz); name[sz] = '\0'; imp->name = name; imp->ordinal = i + 1; - r_list_append (imports, imp); + rz_list_append (imports, imp); off += sz; } bin->imports = imports; return imports; } -RList *r_bin_ne_get_entrypoints(r_bin_ne_obj_t *bin) { - RList *entries = r_list_newf (free); +RzList *rz_bin_ne_get_entrypoints(rz_bin_ne_obj_t *bin) { + RzList *entries = rz_list_newf (free); if (!entries) { return NULL; } RBinAddr *entry; - RList *segments = r_bin_ne_get_segments (bin); + RzList *segments = rz_bin_ne_get_segments (bin); if (!segments) { - r_list_free (entries); + rz_list_free (entries); return NULL; } if (bin->ne_header->csEntryPoint) { entry = R_NEW0 (RBinAddr); if (!entry) { - r_list_free (entries); + rz_list_free (entries); return NULL; } entry->bits = 16; - RBinSection *s = r_list_get_n (segments, bin->ne_header->csEntryPoint - 1); + RBinSection *s = rz_list_get_n (segments, bin->ne_header->csEntryPoint - 1); entry->paddr = bin->ne_header->ipEntryPoint + (s? s->paddr: 0); - r_list_append (entries, entry); + rz_list_append (entries, entry); } int off = 0; while (off < bin->ne_header->EntryTableLength) { @@ -378,7 +378,7 @@ RList *r_bin_ne_get_entrypoints(r_bin_ne_obj_t *bin) { for (i = 0; i < bundle_length; i++) { entry = R_NEW0 (RBinAddr); if (!entry) { - r_list_free (entries); + rz_list_free (entries); return NULL; } off++; @@ -396,24 +396,24 @@ RList *r_bin_ne_get_entrypoints(r_bin_ne_obj_t *bin) { entry->paddr = (ut64)bin->segment_entries[bundle_type - 1].offset * bin->alignment + *(ut16 *)(bin->entry_table + off); } off += 2; - r_list_append (entries, entry); + rz_list_append (entries, entry); } } - r_list_free (segments); + rz_list_free (segments); bin->entries = entries; return entries; } -RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { - RList *segments = bin->segments; +RzList *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin) { + RzList *segments = bin->segments; if (!segments) { return NULL; } - RList *entries = bin->entries; + RzList *entries = bin->entries; if (!entries) { return NULL; } - RList *symbols = bin->symbols; + RzList *symbols = bin->symbols; if (!symbols) { return NULL; } @@ -422,24 +422,24 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { if (!modref) { return NULL; } - r_buf_read_at (bin->buf, (ut64)bin->ne_header->ModRefTable + bin->header_offset, (ut8 *)modref, bin->ne_header->ModRefs * sizeof (ut16)); + rz_buf_read_at (bin->buf, (ut64)bin->ne_header->ModRefTable + bin->header_offset, (ut8 *)modref, bin->ne_header->ModRefs * sizeof (ut16)); - RList *relocs = r_list_newf (free); + RzList *relocs = rz_list_newf (free); if (!relocs) { free (modref); return NULL; } - RListIter *it; + RzListIter *it; RBinSection *seg; int index = -1; - r_list_foreach (segments, it, seg) { + rz_list_foreach (segments, it, seg) { index++; if (!(bin->segment_entries[index].flags & RELOCINFO)) { continue; } ut32 off, start = off = seg->paddr + seg->size; - ut16 length = r_buf_read_le16_at (bin->buf, off); + ut16 length = rz_buf_read_le16_at (bin->buf, off); if (!length) { continue; } @@ -450,7 +450,7 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { return NULL; } NE_image_reloc_item rel; - r_buf_read_at (bin->buf, off, (ut8 *)&rel, sizeof (rel)); + rz_buf_read_at (bin->buf, off, (ut8 *)&rel, sizeof (rel)); reloc->paddr = seg->paddr + rel.offset; switch (rel.type) { case LOBYTE: @@ -478,18 +478,18 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { } char *name; if (rel.index > bin->ne_header->ModRefs) { - name = r_str_newf ("UnknownModule%d_%x", rel.index, off); // ???? + name = rz_str_newf ("UnknownModule%d_%x", rel.index, off); // ???? } else { offset = modref[rel.index - 1] + bin->header_offset + bin->ne_header->ImportNameTable; name = __read_nonnull_str_at (bin->buf, offset); } if (rel.flags & IMPORTED_ORD) { imp->ordinal = rel.func_ord; - imp->name = r_str_newf ("%s.%s", name, __func_name_from_ord(name, rel.func_ord)); + imp->name = rz_str_newf ("%s.%s", name, __func_name_from_ord(name, rel.func_ord)); } else { offset = bin->header_offset + bin->ne_header->ImportNameTable + rel.name_off; char *func = __read_nonnull_str_at (bin->buf, offset); - imp->name = r_str_newf ("%s.%s", name, func); + imp->name = rz_str_newf ("%s.%s", name, func); free (func); } free (name); @@ -498,14 +498,14 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { // TODO } else { if (strstr (seg->name, "FIXED")) { - RBinSection *s = r_list_get_n (segments, rel.segnum - 1); + RBinSection *s = rz_list_get_n (segments, rel.segnum - 1); if (s) { offset = s->paddr + rel.segoff; } else { offset = -1; } } else { - RBinAddr *entry = r_list_get_n (entries, rel.entry_ordinal - 1); + RBinAddr *entry = rz_list_get_n (entries, rel.entry_ordinal - 1); if (entry) { offset = entry->paddr; } else { @@ -514,8 +514,8 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { } reloc->addend = offset; RBinSymbol *sym = NULL; - RListIter *sit; - r_list_foreach (symbols, sit, sym) { + RzListIter *sit; + rz_list_foreach (symbols, sit, sym) { if (sym->paddr == reloc->addend) { reloc->symbol = sym; break; @@ -525,12 +525,12 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { if (rel.flags & ADDITIVE) { reloc->additive = 1; - r_list_append (relocs, reloc); + rz_list_append (relocs, reloc); } else { do { - r_list_append (relocs, reloc); + rz_list_append (relocs, reloc); - offset = r_buf_read_le16_at (bin->buf, reloc->paddr); + offset = rz_buf_read_le16_at (bin->buf, reloc->paddr); RBinReloc *tmp = reloc; reloc = R_NEW0 (RBinReloc); if (!reloc) { @@ -549,14 +549,14 @@ RList *r_bin_ne_get_relocs(r_bin_ne_obj_t *bin) { return relocs; } -void __init(RBuffer *buf, r_bin_ne_obj_t *bin) { - bin->header_offset = r_buf_read_le16_at (buf, 0x3c); +void __init(RBuffer *buf, rz_bin_ne_obj_t *bin) { + bin->header_offset = rz_buf_read_le16_at (buf, 0x3c); bin->ne_header = R_NEW0 (NE_image_header); if (!bin->ne_header) { return; } bin->buf = buf; - r_buf_read_at (buf, bin->header_offset, (ut8 *)bin->ne_header, sizeof (NE_image_header)); + rz_buf_read_at (buf, bin->header_offset, (ut8 *)bin->ne_header, sizeof (NE_image_header)); bin->alignment = 1 << bin->ne_header->FileAlnSzShftCnt; if (!bin->alignment) { bin->alignment = 1 << 9; @@ -569,24 +569,24 @@ void __init(RBuffer *buf, r_bin_ne_obj_t *bin) { if (!bin->segment_entries) { return; } - r_buf_read_at (buf, offset, (ut8 *)bin->segment_entries, size); + rz_buf_read_at (buf, offset, (ut8 *)bin->segment_entries, size); bin->entry_table = calloc (1, bin->ne_header->EntryTableLength); - r_buf_read_at (buf, (ut64)bin->header_offset + bin->ne_header->EntryTableOffset, bin->entry_table, bin->ne_header->EntryTableLength); - bin->imports = r_bin_ne_get_imports (bin); + rz_buf_read_at (buf, (ut64)bin->header_offset + bin->ne_header->EntryTableOffset, bin->entry_table, bin->ne_header->EntryTableLength); + bin->imports = rz_bin_ne_get_imports (bin); __ne_get_resources (bin); } -void r_bin_ne_free(r_bin_ne_obj_t *bin) { - // r_list_free (bin->imports); // double free - r_list_free (bin->resources); +void rz_bin_ne_free(rz_bin_ne_obj_t *bin) { + // rz_list_free (bin->imports); // double free + rz_list_free (bin->resources); free (bin->entry_table); free (bin->ne_header); free (bin->resident_name_table); free (bin->segment_entries); } -r_bin_ne_obj_t *r_bin_ne_new_buf(RBuffer *buf, bool verbose) { - r_bin_ne_obj_t *bin = R_NEW0 (r_bin_ne_obj_t); +rz_bin_ne_obj_t *rz_bin_ne_new_buf(RBuffer *buf, bool verbose) { + rz_bin_ne_obj_t *bin = R_NEW0 (rz_bin_ne_obj_t); if (!bin) { return NULL; } diff --git a/librz/bin/format/ne/ne.h b/librz/bin/format/ne/ne.h new file mode 100644 index 0000000000..0caae2cdd8 --- /dev/null +++ b/librz/bin/format/ne/ne.h @@ -0,0 +1,44 @@ +#ifndef NE_H +#define NE_H +#include +#include +#include +#include +#include "ne_specs.h" + +typedef struct { + char *name; + ut32 offset; + ut32 size; +} rz_ne_resource_entry; + +typedef struct { + char *name; + RzList /**/ *entry; +} rz_ne_resource; + +typedef struct { + NE_image_header *ne_header; + ut16 header_offset; + ut16 alignment; + NE_image_segment_entry *segment_entries; + ut8 *entry_table; + ut8 *resident_name_table; + RBuffer *buf; + RzList *segments; + RzList *entries; + RzList *resources; + RzList *imports; + RzList *symbols; + char *os; +} rz_bin_ne_obj_t; + +void rz_bin_ne_free(rz_bin_ne_obj_t *bin); +rz_bin_ne_obj_t *rz_bin_ne_new_buf(RBuffer *buf, bool verbose); +RzList *rz_bin_ne_get_relocs(rz_bin_ne_obj_t *bin); +RzList *rz_bin_ne_get_imports(rz_bin_ne_obj_t *bin); +RzList *rz_bin_ne_get_symbols(rz_bin_ne_obj_t *bin); +RzList *rz_bin_ne_get_segments(rz_bin_ne_obj_t *bin); +RzList *rz_bin_ne_get_entrypoints(rz_bin_ne_obj_t *bin); + +#endif diff --git a/libr/bin/format/ne/ne_specs.h b/librz/bin/format/ne/ne_specs.h similarity index 100% rename from libr/bin/format/ne/ne_specs.h rename to librz/bin/format/ne/ne_specs.h diff --git a/libr/bin/format/nes/nes_specs.h b/librz/bin/format/nes/nes_specs.h similarity index 100% rename from libr/bin/format/nes/nes_specs.h rename to librz/bin/format/nes/nes_specs.h diff --git a/libr/bin/format/nin/gba.h b/librz/bin/format/nin/gba.h similarity index 97% rename from libr/bin/format/nin/gba.h rename to librz/bin/format/nin/gba.h index 96fc84d379..cbd634830a 100644 --- a/libr/bin/format/nin/gba.h +++ b/librz/bin/format/nin/gba.h @@ -1,4 +1,4 @@ -#include +#include const ut8 lic_gba[]={ 0x24, 0xff, 0xae, 0x51, 0x69, 0x9a, 0xa2, 0x21, 0x3d, 0x84, 0x82, diff --git a/libr/bin/format/nin/n3ds.h b/librz/bin/format/nin/n3ds.h similarity index 94% rename from libr/bin/format/nin/n3ds.h rename to librz/bin/format/nin/n3ds.h index af4604e862..2ce170f0c6 100644 --- a/libr/bin/format/nin/n3ds.h +++ b/librz/bin/format/nin/n3ds.h @@ -7,7 +7,7 @@ More formats to support: https://www.3dbrew.org/wiki/Category:File_formats #ifndef NIN_N3DS_H #define NIN_N3DS_H -#include +#include R_PACKED ( struct n3ds_firm_sect_hdr { diff --git a/libr/bin/format/nin/nds.h b/librz/bin/format/nin/nds.h similarity index 98% rename from libr/bin/format/nin/nds.h rename to librz/bin/format/nin/nds.h index 069dc9531c..8474ffccd5 100644 --- a/libr/bin/format/nin/nds.h +++ b/librz/bin/format/nin/nds.h @@ -7,7 +7,7 @@ http://sourceforge.net/p/devkitpro/ndstool/ci/master/tree/source/header.h #ifndef NIN_NDS_H #define NIN_NDS_H -#include +#include R_PACKED ( struct nds_hdr diff --git a/libr/bin/format/nin/nin.h b/librz/bin/format/nin/nin.h similarity index 99% rename from libr/bin/format/nin/nin.h rename to librz/bin/format/nin/nin.h index dde7b81640..c320f922ba 100644 --- a/libr/bin/format/nin/nin.h +++ b/librz/bin/format/nin/nin.h @@ -1,4 +1,4 @@ -#include +#include #include enum{ diff --git a/libr/bin/format/nxo/nxo.c b/librz/bin/format/nxo/nxo.c similarity index 77% rename from libr/bin/format/nxo/nxo.c rename to librz/bin/format/nxo/nxo.c index cb33fc4482..7e2a74585d 100644 --- a/libr/bin/format/nxo/nxo.c +++ b/librz/bin/format/nxo/nxo.c @@ -4,15 +4,15 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "nxo.h" static char *readString(RBuffer *buf, int off) { char symbol[128]; // assume 128 as max symbol name length - int left = r_buf_read_at (buf, off, (ut8*)symbol, sizeof (symbol)); + int left = rz_buf_read_at (buf, off, (ut8*)symbol, sizeof (symbol)); if (left < 1) { return NULL; } @@ -41,11 +41,11 @@ static void walkSymbols (RBuffer *buf, RBinNXOObj *bin, ut64 symtab, ut64 strtab RBinSymbol *sym; RBinImport *imp; for (i = 8; i < 99999; i++) { - ut64 addr = r_buf_read_le64_at (buf, symtab + i); - ut64 size = r_buf_read_le64_at (buf, symtab + i + 8); + ut64 addr = rz_buf_read_le64_at (buf, symtab + i); + ut64 size = rz_buf_read_le64_at (buf, symtab + i + 8); i += 16; // NULL, NULL - ut64 name = r_buf_read_le32_at (buf, symtab + i); - //ut64 type = r_buf_read_le32_at (buf, symtab + i + 4); + ut64 name = rz_buf_read_le32_at (buf, symtab + i); + //ut64 type = rz_buf_read_le32_at (buf, symtab + i + 4); char *symName = readString (buf, strtab + name); if (!symName) { break; @@ -61,7 +61,7 @@ static void walkSymbols (RBuffer *buf, RBinNXOObj *bin, ut64 symtab, ut64 strtab if (addr == 0) { import ++; - ut64 pltSym = r_buf_read_le64_at (buf, relplt + (import * 24)); + ut64 pltSym = rz_buf_read_le64_at (buf, relplt + (import * 24)); imp = R_NEW0 (RBinImport); if (!imp) { R_FREE (sym); @@ -81,7 +81,7 @@ static void walkSymbols (RBuffer *buf, RBinNXOObj *bin, ut64 symtab, ut64 strtab goto out_walk_symbol; } imp->ordinal = bin->imports_list->length; - r_list_append (bin->imports_list, imp); + rz_list_append (bin->imports_list, imp); sym->is_imported = true; sym->name = strdup (symName); if (!sym->name) { @@ -100,7 +100,7 @@ static void walkSymbols (RBuffer *buf, RBinNXOObj *bin, ut64 symtab, ut64 strtab sym->vaddr = sym->paddr + baddr; eprintf ("f sym.%s %"PFMT64u "0x%"PFMT64x"\n", symName, size, addr); } - r_list_append (bin->methods_list, sym); + rz_list_append (bin->methods_list, sym); i += 8 - 1; } return; @@ -112,18 +112,18 @@ out_walk_symbol: } void parseMod(RBuffer *buf, RBinNXOObj *bin, ut32 mod0, ut64 baddr) { - ut32 ptr = r_buf_read_le32_at (buf, mod0); + ut32 ptr = rz_buf_read_le32_at (buf, mod0); eprintf ("magic %x at 0x%x\n", ptr, mod0); if (ptr == 0x30444f4d) { // MOD0 eprintf ("is mode0\n"); MODHeader mh = { - .magic = r_buf_read_le32_at (buf, mod0), - .dynamic = r_buf_read_le32_at (buf, mod0 + 4), - .bss_start = r_buf_read_le32_at (buf, mod0 + 8), - .bss_end = r_buf_read_le32_at (buf, mod0 + 12), - .unwind_start = r_buf_read_le32_at (buf, mod0 + 16), - .unwind_end = r_buf_read_le32_at (buf, mod0 + 20), - .mod_object = r_buf_read_le32_at (buf, mod0 + 24), + .magic = rz_buf_read_le32_at (buf, mod0), + .dynamic = rz_buf_read_le32_at (buf, mod0 + 4), + .bss_start = rz_buf_read_le32_at (buf, mod0 + 8), + .bss_end = rz_buf_read_le32_at (buf, mod0 + 12), + .unwind_start = rz_buf_read_le32_at (buf, mod0 + 16), + .unwind_end = rz_buf_read_le32_at (buf, mod0 + 20), + .mod_object = rz_buf_read_le32_at (buf, mod0 + 24), }; mh.mod_object += mod0; eprintf ("magic 0x%x\n", mh.magic); @@ -132,7 +132,7 @@ void parseMod(RBuffer *buf, RBinNXOObj *bin, ut32 mod0, ut64 baddr) { eprintf ("unwind 0x%x 0x%x\n", mh.unwind_start, mh.unwind_end); eprintf ("-------------\n"); eprintf ("mod 0x%x\n", mh.mod_object); -#define MO_(x) r_buf_read_le64_at(buf, mh.mod_object + r_offsetof(MODObject, x)) +#define MO_(x) rz_buf_read_le64_at(buf, mh.mod_object + rz_offsetof(MODObject, x)) MODObject mo = { .next = MO_(next), .prev = MO_(prev), diff --git a/libr/bin/format/nxo/nxo.h b/librz/bin/format/nxo/nxo.h similarity index 93% rename from libr/bin/format/nxo/nxo.h rename to librz/bin/format/nxo/nxo.h index 45cb07ab78..e988c5edd0 100644 --- a/libr/bin/format/nxo/nxo.h +++ b/librz/bin/format/nxo/nxo.h @@ -58,9 +58,9 @@ typedef struct { typedef struct { ut32 *strings; - RList *methods_list; - RList *imports_list; - RList *classes_list; + RzList *methods_list; + RzList *imports_list; + RzList *classes_list; } RBinNXOObj; void parseMod(RBuffer *buf, RBinNXOObj *bin, ut32 mod0, ut64 baddr); diff --git a/libr/bin/format/objc/mach064_classes.c b/librz/bin/format/objc/mach064_classes.c similarity index 100% rename from libr/bin/format/objc/mach064_classes.c rename to librz/bin/format/objc/mach064_classes.c diff --git a/libr/bin/format/objc/mach064_classes.h b/librz/bin/format/objc/mach064_classes.h similarity index 100% rename from libr/bin/format/objc/mach064_classes.h rename to librz/bin/format/objc/mach064_classes.h diff --git a/libr/bin/format/objc/mach0_classes.c b/librz/bin/format/objc/mach0_classes.c similarity index 77% rename from libr/bin/format/objc/mach0_classes.c rename to librz/bin/format/objc/mach0_classes.c index 1d21d46d54..5591584398 100644 --- a/libr/bin/format/objc/mach0_classes.c +++ b/librz/bin/format/objc/mach0_classes.c @@ -110,7 +110,7 @@ static void get_objc_property_list(mach0_ut p, RBinFile *bf, RBinClass *klass); static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinClass *klass, bool is_static); static void get_protocol_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass); static void get_class_ro_t(mach0_ut p, RBinFile *bf, ut32 *is_meta_class, RBinClass *klass); -static RList *MACH0_(parse_categories)(RBinFile *bf, RSkipList *relocs); +static RzList *MACH0_(parse_categories)(RBinFile *bf, RzSkipList *relocs); static bool read_ptr_pa(RBinFile *bf, ut64 paddr, mach0_ut *out); static bool read_ptr_va(RBinFile *bf, ut64 vaddr, mach0_ut *out); static char *read_str(RBinFile *bf, mach0_ut p, ut32 *offset, ut32 *left); @@ -126,13 +126,13 @@ static bool is_thumb(RBinFile *bf) { } static mach0_ut va2pa(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, 0); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, 0); mach0_ut r; mach0_ut addr; - static RList *sctns = NULL; - RListIter *iter = NULL; + static RzList *sctns = NULL; + RzListIter *iter = NULL; RBinSection *s = NULL; RBinObject *obj = bf->o; @@ -142,7 +142,7 @@ static mach0_ut va2pa(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *bf) { } if (!sctns) { - sctns = r_bin_plugin_mach.sections (bf); + sctns = rz_bin_plugin_mach.sections (bf); if (!sctns) { // retain just for debug // eprintf ("there is no sections\n"); @@ -151,7 +151,7 @@ static mach0_ut va2pa(mach0_ut p, ut32 *offset, ut32 *left, RBinFile *bf) { } addr = p; - r_list_foreach (sctns, iter, s) { + rz_list_foreach (sctns, iter, s) { if (addr >= s->vaddr && addr < s->vaddr + s->vsize) { if (offset) { *offset = addr - s->vaddr; @@ -220,17 +220,17 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { return; } if (left < sizeof (struct MACH0_(SIVarList))) { - if (r_buf_read_at (bf->buf, r, sivarlist, left) != left) { + if (rz_buf_read_at (bf->buf, r, sivarlist, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, sivarlist, sizeof (struct MACH0_(SIVarList))); + len = rz_buf_read_at (bf->buf, r, sivarlist, sizeof (struct MACH0_(SIVarList))); if (len != sizeof (struct MACH0_(SIVarList))) { return; } } - il.entsize = r_read_ble (&sivarlist[0], bigendian, 32); - il.count = r_read_ble (&sivarlist[4], bigendian, 32); + il.entsize = rz_read_ble (&sivarlist[0], bigendian, 32); + il.count = rz_read_ble (&sivarlist[4], bigendian, 32); p += sizeof (struct MACH0_(SIVarList)); offset += sizeof (struct MACH0_(SIVarList)); @@ -251,27 +251,27 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { goto error; } if (left < sizeof (struct MACH0_(SIVar))) { - if (r_buf_read_at (bf->buf, r, sivar, left) != left) { + if (rz_buf_read_at (bf->buf, r, sivar, left) != left) { goto error; } } else { - len = r_buf_read_at (bf->buf, r, sivar, sizeof (struct MACH0_(SIVar))); + len = rz_buf_read_at (bf->buf, r, sivar, sizeof (struct MACH0_(SIVar))); if (len != sizeof (struct MACH0_(SIVar))) { goto error; } } #if R_BIN_MACH064 - i.offset = r_read_ble (&sivar[0], bigendian, 64); - i.name = r_read_ble (&sivar[8], bigendian, 64); - i.type = r_read_ble (&sivar[16], bigendian, 64); - i.alignment = r_read_ble (&sivar[24], bigendian, 32); - i.size = r_read_ble (&sivar[28], bigendian, 32); + i.offset = rz_read_ble (&sivar[0], bigendian, 64); + i.name = rz_read_ble (&sivar[8], bigendian, 64); + i.type = rz_read_ble (&sivar[16], bigendian, 64); + i.alignment = rz_read_ble (&sivar[24], bigendian, 32); + i.size = rz_read_ble (&sivar[28], bigendian, 32); #else - i.offset = r_read_ble (&sivar[0], bigendian, 32); - i.name = r_read_ble (&sivar[4], bigendian, 32); - i.type = r_read_ble (&sivar[8], bigendian, 32); - i.alignment = r_read_ble (&sivar[12], bigendian, 32); - i.size = r_read_ble (&sivar[16], bigendian, 32); + i.offset = rz_read_ble (&sivar[0], bigendian, 32); + i.name = rz_read_ble (&sivar[4], bigendian, 32); + i.type = rz_read_ble (&sivar[8], bigendian, 32); + i.alignment = rz_read_ble (&sivar[12], bigendian, 32); + i.size = rz_read_ble (&sivar[16], bigendian, 32); #endif field->vaddr = i.offset; mach0_ut offset_at = va2pa (i.offset, NULL, &left, bf); @@ -283,12 +283,12 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { goto error; } if (offset_at != 0 && left >= sizeof (mach0_ut)) { - len = r_buf_read_at (bf->buf, offset_at, offs, sizeof (mach0_ut)); + len = rz_buf_read_at (bf->buf, offset_at, offs, sizeof (mach0_ut)); if (len != sizeof (mach0_ut)) { eprintf ("Error reading\n"); goto error; } - ivar_offset = r_read_ble (offs, bigendian, 8 * sizeof (mach0_ut)); + ivar_offset = rz_read_ble (offs, bigendian, 8 * sizeof (mach0_ut)); field->offset = ivar_offset; } r = va2pa (i.name, NULL, &left, bf); @@ -307,7 +307,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { } else { int name_len = R_MIN (MAX_CLASS_NAME_LEN, left); name = malloc (name_len + 1); - len = r_buf_read_at (bf->buf, r, (ut8 *)name, name_len); + len = rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len); if (len < 1) { eprintf ("Error reading\n"); R_FREE (name); @@ -316,7 +316,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { name[name_len] = 0; } // XXX the field name shouldnt contain the class name - field->name = r_str_newf ("%s::%s%s", klass->name, "(ivar)", name); + field->name = rz_str_newf ("%s::%s%s", klass->name, "(ivar)", name); R_FREE (name); } @@ -338,7 +338,7 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { int type_len = R_MIN (MAX_CLASS_NAME_LEN, left); type = calloc (1, type_len + 1); if (type) { - r_buf_read_at (bf->buf, r, (ut8 *)type, type_len); + rz_buf_read_at (bf->buf, r, (ut8 *)type, type_len); type[type_len] = 0; } } @@ -348,15 +348,15 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { } else { field->type = NULL; } - r_list_append (klass->fields, field); + rz_list_append (klass->fields, field); } else { goto error; } p += sizeof (struct MACH0_(SIVar)); offset += sizeof (struct MACH0_(SIVar)); } - if (!r_list_empty (klass->fields)) { - r_list_sort (klass->fields, sort_by_offset); + if (!rz_list_empty (klass->fields)) { + rz_list_sort (klass->fields, sort_by_offset); } RBinField *isa_field = R_NEW0 (RBinField); isa_field->name = strdup ("isa"); @@ -364,10 +364,10 @@ static void get_ivar_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { isa_field->type = strdup ("struct objc_class *"); isa_field->vaddr = 0; isa_field->offset = 0; - r_list_prepend (klass->fields, isa_field); + rz_list_prepend (klass->fields, isa_field); return; error: - r_bin_field_free (field); + rz_bin_field_free (field); } /////////////////////////////////////////////////////////////////////////////// @@ -403,18 +403,18 @@ static void get_objc_property_list(mach0_ut p, RBinFile *bf, RBinClass *klass) { return; } if (left < sizeof (struct MACH0_(SObjcPropertyList))) { - if (r_buf_read_at (bf->buf, r, sopl, left) != left) { + if (rz_buf_read_at (bf->buf, r, sopl, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, sopl, sizeof (struct MACH0_(SObjcPropertyList))); + len = rz_buf_read_at (bf->buf, r, sopl, sizeof (struct MACH0_(SObjcPropertyList))); if (len != sizeof (struct MACH0_(SObjcPropertyList))) { return; } } - opl.entsize = r_read_ble (&sopl[0], bigendian, 32); - opl.count = r_read_ble (&sopl[4], bigendian, 32); + opl.entsize = rz_read_ble (&sopl[0], bigendian, 32); + opl.count = rz_read_ble (&sopl[4], bigendian, 32); p += sizeof (struct MACH0_(SObjcPropertyList)); offset += sizeof (struct MACH0_(SObjcPropertyList)); @@ -443,17 +443,17 @@ static void get_objc_property_list(mach0_ut p, RBinFile *bf, RBinClass *klass) { } if (left < sizeof (struct MACH0_(SObjcProperty))) { - if (r_buf_read_at (bf->buf, r, sop, left) != left) { + if (rz_buf_read_at (bf->buf, r, sop, left) != left) { goto error; } } else { - len = r_buf_read_at (bf->buf, r, sop, sizeof (struct MACH0_(SObjcProperty))); + len = rz_buf_read_at (bf->buf, r, sop, sizeof (struct MACH0_(SObjcProperty))); if (len != sizeof (struct MACH0_(SObjcProperty))) { goto error; } } - op.name = r_read_ble (&sop[0], bigendian, 8 * sizeof (mach0_ut)); - op.attributes = r_read_ble (&sop[sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); + op.name = rz_read_ble (&sop[0], bigendian, 8 * sizeof (mach0_ut)); + op.attributes = rz_read_ble (&sop[sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); r = va2pa (op.name, NULL, &left, bf); if (r) { struct MACH0_(obj_t) *bin = (struct MACH0_(obj_t) *)bf->o->bin_obj; @@ -472,11 +472,11 @@ static void get_objc_property_list(mach0_ut p, RBinFile *bf, RBinClass *klass) { if (!name) { goto error; } - if (r_buf_read_at (bf->buf, r, (ut8 *)name, name_len) != name_len) { + if (rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len) != name_len) { goto error; } } - property->name = r_str_newf ("%s::%s%s", klass->name, + property->name = rz_str_newf ("%s::%s%s", klass->name, "(property)", name); R_FREE (name); } @@ -494,14 +494,14 @@ static void get_objc_property_list(mach0_ut p, RBinFile *bf, RBinClass *klass) { left = strlen (name) + 1; } else { name = malloc (left); - len = r_buf_read_at (bf->buf, r, (ut8 *)name, left); + len = rz_buf_read_at (bf->buf, r, (ut8 *)name, left); if (len == 0 || len == -1) goto error; } R_FREE (name); } #endif - r_list_append (klass->fields, property); + rz_list_append (klass->fields, property); p += sizeof (struct MACH0_(SObjcProperty)); offset += sizeof (struct MACH0_(SObjcProperty)); @@ -547,17 +547,17 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl return; } if (left < sizeof (struct MACH0_(SMethodList))) { - if (r_buf_read_at (bf->buf, r, sml, left) != left) { + if (rz_buf_read_at (bf->buf, r, sml, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, sml, sizeof (struct MACH0_(SMethodList))); + len = rz_buf_read_at (bf->buf, r, sml, sizeof (struct MACH0_(SMethodList))); if (len != sizeof (struct MACH0_(SMethodList))) { return; } } - ml.entsize = r_read_ble (&sml[0], bigendian, 32); - ml.count = r_read_ble (&sml[4], bigendian, 32); + ml.entsize = rz_read_ble (&sml[0], bigendian, 32); + ml.count = rz_read_ble (&sml[4], bigendian, 32); bool is_small = (ml.entsize & METHOD_LIST_FLAG_IS_SMALL) != 0; ut8 mlflags = ml.entsize & 0x3; @@ -591,21 +591,21 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl goto error; } if (left < read_size) { - if (r_buf_read_at (bf->buf, r, sm, left) != left) { + if (rz_buf_read_at (bf->buf, r, sm, left) != left) { goto error; } } else { - len = r_buf_read_at (bf->buf, r, sm, read_size); + len = rz_buf_read_at (bf->buf, r, sm, read_size); if (len != read_size) { goto error; } } if (!is_small) { - m.name = r_read_ble (&sm[0], bigendian, 8 * sizeof (mach0_ut)); - m.types = r_read_ble (&sm[sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); - m.imp = r_read_ble (&sm[2 * sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); + m.name = rz_read_ble (&sm[0], bigendian, 8 * sizeof (mach0_ut)); + m.types = rz_read_ble (&sm[sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); + m.imp = rz_read_ble (&sm[2 * sizeof (mach0_ut)], bigendian, 8 * sizeof (mach0_ut)); } else { - st64 name_offset = (st32) r_read_ble (&sm[0], bigendian, 8 * sizeof (ut32)); + st64 name_offset = (st32) rz_read_ble (&sm[0], bigendian, 8 * sizeof (ut32)); mach0_ut name = p + name_offset; if (mlflags != METHOD_LIST_FLAG_IS_PREOPT) { r = va2pa (name, &offset, &left, bf); @@ -613,16 +613,16 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl goto error; } ut8 tmp[8]; - if (r_buf_read_at (bf->buf, r, tmp, sizeof (mach0_ut)) != sizeof (mach0_ut)) { + if (rz_buf_read_at (bf->buf, r, tmp, sizeof (mach0_ut)) != sizeof (mach0_ut)) { goto error; } - m.name = r_read_ble (tmp, bigendian, 8 * sizeof (mach0_ut)); + m.name = rz_read_ble (tmp, bigendian, 8 * sizeof (mach0_ut)); } else { m.name = name; } - st64 types_offset = (st32) r_read_ble (&sm[sizeof (ut32)], bigendian, 8 * sizeof (ut32)); + st64 types_offset = (st32) rz_read_ble (&sm[sizeof (ut32)], bigendian, 8 * sizeof (ut32)); m.types = p + types_offset + 4; - st64 imp_offset = (st32) r_read_ble (&sm[2 * sizeof (ut32)], bigendian, 8 * sizeof (ut32)); + st64 imp_offset = (st32) rz_read_ble (&sm[2 * sizeof (ut32)], bigendian, 8 * sizeof (ut32)); m.imp = p + imp_offset + 8; } @@ -641,7 +641,7 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl } else { int name_len = R_MIN (MAX_CLASS_NAME_LEN, left); name = malloc (name_len + 1); - len = r_buf_read_at (bf->buf, r, (ut8 *)name, name_len); + len = rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len); name[name_len] = 0; if (len < 1) { goto error; @@ -669,7 +669,7 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl if (!rtype) { goto error; } - if (r_buf_read_at (bf->buf, r, (ut8 *)rtype, left) != left) { + if (rz_buf_read_at (bf->buf, r, (ut8 *)rtype, left) != left) { free (rtype); goto error; } @@ -695,7 +695,7 @@ static void get_method_list_t(mach0_ut p, RBinFile *bf, char *class_name, RBinCl //eprintf ("0x%08llx METHOD %s\n", method->vaddr, method->name); } } - r_list_append (klass->methods, method); + rz_list_append (klass->methods, method); next: p += read_size; offset += read_size; @@ -738,16 +738,16 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { return; } if (left < sizeof (struct MACH0_(SProtocolList))) { - if (r_buf_read_at (bf->buf, r, spl, left) != left) { + if (rz_buf_read_at (bf->buf, r, spl, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, spl, sizeof (struct MACH0_(SProtocolList))); + len = rz_buf_read_at (bf->buf, r, spl, sizeof (struct MACH0_(SProtocolList))); if (len != sizeof (struct MACH0_(SProtocolList))) { return; } } - pl.count = r_read_ble (&spl[0], bigendian, 8 * sizeof (mach0_ut)); + pl.count = rz_read_ble (&spl[0], bigendian, 8 * sizeof (mach0_ut)); p += sizeof (struct MACH0_(SProtocolList)); offset += sizeof (struct MACH0_(SProtocolList)); @@ -765,16 +765,16 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { return; } if (left < sizeof (ut32)) { - if (r_buf_read_at (bf->buf, r, sptr, left) != left) { + if (rz_buf_read_at (bf->buf, r, sptr, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, sptr, sizeof (mach0_ut)); + len = rz_buf_read_at (bf->buf, r, sptr, sizeof (mach0_ut)); if (len != sizeof (mach0_ut)) { return; } } - q = r_read_ble (&sptr[0], bigendian, 8 * sizeof (mach0_ut)); + q = rz_read_ble (&sptr[0], bigendian, 8 * sizeof (mach0_ut)); if (!(r = va2pa (q, &offset, &left, bf))) { return; } @@ -789,32 +789,32 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { return; } if (left < sizeof (struct MACH0_(SProtocol))) { - if (r_buf_read_at (bf->buf, r, spc, left) != left) { + if (rz_buf_read_at (bf->buf, r, spc, left) != left) { return; } } else { - len = r_buf_read_at (bf->buf, r, spc, sizeof (struct MACH0_(SProtocol))); + len = rz_buf_read_at (bf->buf, r, spc, sizeof (struct MACH0_(SProtocol))); if (len != sizeof (struct MACH0_(SProtocol))) { return; } } j = 0; - pc.isa = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.isa = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.name = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.name = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.protocols = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.protocols = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.instanceMethods = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.instanceMethods = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.classMethods = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.classMethods = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.optionalInstanceMethods = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.optionalInstanceMethods = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.optionalClassMethods = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.optionalClassMethods = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); j += sizeof (mach0_ut); - pc.instanceProperties = r_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); + pc.instanceProperties = rz_read_ble (&spc[j], bigendian, 8 * sizeof (mach0_ut)); r = va2pa (pc.name, NULL, &left, bf); if (r != 0) { char *name = NULL; @@ -834,13 +834,13 @@ static void get_protocol_list_t(mach0_ut p, RBinFile *bf, RBinClass *klass) { if (!name) { return; } - if (r_buf_read_at (bf->buf, r, (ut8 *)name, name_len) != name_len) { + if (rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len) != name_len) { R_FREE (name); return; } name[name_len] = 0; } - class_name = r_str_newf ("%s::%s%s", klass->name, "(protocol)", name); + class_name = rz_str_newf ("%s::%s%s", klass->name, "(protocol)", name); R_FREE (name); } @@ -878,7 +878,7 @@ static char *demangle_classname(const char *s) { if (!len || len >= modlen) { return strdup (s); } - module = r_str_ndup (skipnum (s + off), len); + module = rz_str_ndup (skipnum (s + off), len); int skip = (skipnum (s + off) - s) + len; if (s[skip] == 'P') { skip++; @@ -892,8 +892,8 @@ static char *demangle_classname(const char *s) { free (module); return strdup (s); } - klass = r_str_ndup (skipnum (kstr), len); - ret = r_str_newf ("%s.%s", module, klass); + klass = rz_str_ndup (skipnum (kstr), len); + ret = rz_str_newf ("%s.%s", module, klass); free (module); free (klass); } else { @@ -936,12 +936,12 @@ static char *get_class_name(mach0_ut p, RBinFile *bf) { if (left < sizeof (sc)) { return NULL; } - len = r_buf_read_at (bf->buf, r + 4 * ptr_size, sc, sizeof (sc)); + len = rz_buf_read_at (bf->buf, r + 4 * ptr_size, sc, sizeof (sc)); if (len != sizeof (sc)) { return NULL; } - ut64 rodata = r_read_ble (sc, bigendian, 8 * ptr_size); + ut64 rodata = rz_read_ble (sc, bigendian, 8 * ptr_size); if (!(r = va2pa (rodata, &offset, &left, bf))) { return NULL; } @@ -959,14 +959,14 @@ static char *get_class_name(mach0_ut p, RBinFile *bf) { } #ifdef R_BIN_MACH064 - len = r_buf_read_at (bf->buf, r + 4 * sizeof (ut32) + ptr_size, sc, sizeof (sc)); + len = rz_buf_read_at (bf->buf, r + 4 * sizeof (ut32) + ptr_size, sc, sizeof (sc)); #else - len = r_buf_read_at (bf->buf, r + 3 * sizeof (ut32) + ptr_size, sc, sizeof (sc)); + len = rz_buf_read_at (bf->buf, r + 3 * sizeof (ut32) + ptr_size, sc, sizeof (sc)); #endif if (len != sizeof (sc)) { return NULL; } - ut64 name = r_read_ble (sc, bigendian, 8 * ptr_size); + ut64 name = rz_read_ble (sc, bigendian, 8 * ptr_size); if ((r = va2pa (name, NULL, &left, bf))) { if (left < 1 || r + left < r) { @@ -981,7 +981,7 @@ static char *get_class_name(mach0_ut p, RBinFile *bf) { int name_len = R_MIN (MAX_CLASS_NAME_LEN, left); char *name = malloc (name_len + 1); if (name) { - int rc = r_buf_read_at (bf->buf, r, (ut8 *)name, name_len); + int rc = rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len); if (rc != name_len) { rc = 0; } @@ -1027,39 +1027,39 @@ static void get_class_ro_t(mach0_ut p, RBinFile *bf, ut32 *is_meta_class, RBinCl return; } - // TODO: use r_buf_fread to avoid endianness issues + // TODO: use rz_buf_fread to avoid endianness issues if (left < sizeof (cro)) { eprintf ("Not enough data for SClassRoT\n"); return; } - len = r_buf_read_at (bf->buf, r, scro, sizeof (cro)); + len = rz_buf_read_at (bf->buf, r, scro, sizeof (cro)); if (len < 1) { return; } i = 0; - cro.flags = r_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); + cro.flags = rz_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); i += sizeof (ut32); - cro.instanceStart = r_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); + cro.instanceStart = rz_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); i += sizeof (ut32); - cro.instanceSize = r_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); + cro.instanceSize = rz_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); i += sizeof (ut32); #ifdef R_BIN_MACH064 - cro.reserved = r_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); + cro.reserved = rz_read_ble (&scro[i], bigendian, 8 * sizeof (ut32)); i += sizeof (ut32); #endif - cro.ivarLayout = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.ivarLayout = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.name = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.name = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.baseMethods = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.baseMethods = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.baseProtocols = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.baseProtocols = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.ivars = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.ivars = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.weakIvarLayout = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.weakIvarLayout = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - cro.baseProperties = r_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); + cro.baseProperties = rz_read_ble (&scro[i], bigendian, 8 * sizeof (mach0_ut)); s = r; if ((r = va2pa (cro.name, NULL, &left, bf))) { @@ -1076,7 +1076,7 @@ static void get_class_ro_t(mach0_ut p, RBinFile *bf, ut32 *is_meta_class, RBinCl int name_len = R_MIN (MAX_CLASS_NAME_LEN, left); char *name = malloc (name_len + 1); if (name) { - int rc = r_buf_read_at (bf->buf, r, (ut8 *)name, name_len); + int rc = rz_buf_read_at (bf->buf, r, (ut8 *)name, name_len); if (rc != name_len) { rc = 0; } @@ -1120,7 +1120,7 @@ static mach0_ut get_isa_value(void) { return 0; } -void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, RSkipList *relocs) { +void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, RzSkipList *relocs) { struct MACH0_(SClass) c = { 0 }; const int size = sizeof (struct MACH0_(SClass)); mach0_ut r = 0; @@ -1151,21 +1151,21 @@ void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, eprintf ("Cannot parse obj class info out of bounds\n"); return; } - len = r_buf_read_at (bf->buf, r, sc, size); + len = rz_buf_read_at (bf->buf, r, sc, size); if (len != size) { return; } i = 0; - c.isa = r_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); + c.isa = rz_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - c.superclass = r_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); + c.superclass = rz_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - c.cache = r_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); + c.cache = rz_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - c.vtable = r_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); + c.vtable = rz_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); i += sizeof (mach0_ut); - c.data = r_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); + c.data = rz_read_ble (&sc[i], bigendian, 8 * sizeof (mach0_ut)); klass->addr = c.isa; if (c.superclass) { @@ -1173,12 +1173,12 @@ void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, } else if (relocs) { struct reloc_t reloc_at_class_addr; reloc_at_class_addr.addr = p + sizeof (mach0_ut); - RSkipListNode *found = r_skiplist_find (relocs, &reloc_at_class_addr); + RzSkipListNode *found = rz_skiplist_find (relocs, &reloc_at_class_addr); if (found) { const char *_objc_class = "_OBJC_CLASS_$_"; const int _objc_class_len = strlen (_objc_class); char *target_class_name = (char*) ((struct reloc_t*) found->data)->name; - if (r_str_startswith (target_class_name, _objc_class)) { + if (rz_str_startswith (target_class_name, _objc_class)) { target_class_name += _objc_class_len; klass->super = strdup (target_class_name); } @@ -1200,15 +1200,15 @@ void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, } #if 0 -static RList *parse_swift_classes(RBinFile *bf) { +static RzList *parse_swift_classes(RBinFile *bf) { bool is_swift = false; RBinString *str; - RListIter *iter; + RzListIter *iter; RBinClass *cls; - RList *ret; + RzList *ret; char *lib; - r_list_foreach (bf->o->libs, iter, lib) { + rz_list_foreach (bf->o->libs, iter, lib) { if (strstr (lib, "libswift")) { is_swift = true; break; @@ -1219,15 +1219,15 @@ static RList *parse_swift_classes(RBinFile *bf) { } int idx = 0; - ret = r_list_newf (r_bin_string_free); - r_list_foreach (bf->o->strings, iter, str) { + ret = rz_list_newf (rz_bin_string_free); + rz_list_foreach (bf->o->strings, iter, str) { if (!strncmp (str->string, "_TtC", 4)) { char *msg = strdup (str->string + 4); cls = R_NEW0 (RBinClass); cls->name = strdup (msg); cls->super = strdup (msg); cls->index = idx++; - r_list_append (ret, cls); + rz_list_append (ret, cls); free (msg); } } @@ -1235,12 +1235,12 @@ static RList *parse_swift_classes(RBinFile *bf) { } #endif -RList *MACH0_(parse_classes)(RBinFile *bf) { - RList /**/ *ret = NULL; +RzList *MACH0_(parse_classes)(RBinFile *bf) { + RzList /**/ *ret = NULL; ut64 num_of_unnamed_class = 0; RBinClass *klass = NULL; ut32 i = 0, size = 0; - RList *sctns = NULL; + RzList *sctns = NULL; bool is_found = false; mach0_ut p = 0; ut32 left = 0; @@ -1250,14 +1250,14 @@ RList *MACH0_(parse_classes)(RBinFile *bf) { bool bigendian; ut8 pp[sizeof (mach0_ut)] = {0}; - r_return_val_if_fail (bf && bf->o, NULL); + rz_return_val_if_fail (bf && bf->o, NULL); if (!bf->o->bin_obj || !bf->o->info) { return NULL; } bigendian = bf->o->info->big_endian; - RSkipList *relocs = MACH0_(get_relocs) (bf->o->bin_obj); + RzSkipList *relocs = MACH0_(get_relocs) (bf->o->bin_obj); ret = MACH0_(parse_categories) (bf, relocs); @@ -1289,9 +1289,9 @@ RList *MACH0_(parse_classes)(RBinFile *bf) { } // end of seaching of section with name __objc_classlist - if (!ret && !(ret = r_list_newf ((RListFree)r_bin_class_free))) { + if (!ret && !(ret = rz_list_newf ((RzListFree)rz_bin_class_free))) { // retain just for debug - // eprintf ("RList allocation error\n"); + // eprintf ("RzList allocation error\n"); goto get_classes_error; } // start of getting information about each class in file @@ -1306,14 +1306,14 @@ RList *MACH0_(parse_classes)(RBinFile *bf) { // eprintf ("RBinClass allocation error\n"); goto get_classes_error; } - if (!(klass->methods = r_list_new ())) { + if (!(klass->methods = rz_list_new ())) { // retain just for debug - // eprintf ("RList allocation error\n"); + // eprintf ("RzList allocation error\n"); goto get_classes_error; } - if (!(klass->fields = r_list_new ())) { + if (!(klass->fields = rz_list_new ())) { // retain just for debug - // eprintf ("RList allocation error\n"); + // eprintf ("RzList allocation error\n"); goto get_classes_error; } size = sizeof (mach0_ut); @@ -1323,34 +1323,34 @@ RList *MACH0_(parse_classes)(RBinFile *bf) { if (paddr + size < paddr) { goto get_classes_error; } - len = r_buf_read_at (bf->buf, paddr + i, pp, sizeof (mach0_ut)); + len = rz_buf_read_at (bf->buf, paddr + i, pp, sizeof (mach0_ut)); if (len != sizeof (mach0_ut)) { goto get_classes_error; } - p = r_read_ble (&pp[0], bigendian, 8 * sizeof (mach0_ut)); + p = rz_read_ble (&pp[0], bigendian, 8 * sizeof (mach0_ut)); MACH0_(get_class_t) (p, bf, klass, false, relocs); if (!klass->name) { - klass->name = r_str_newf ("UnnamedClass%" PFMT64d, num_of_unnamed_class); + klass->name = rz_str_newf ("UnnamedClass%" PFMT64d, num_of_unnamed_class); if (!klass->name) { goto get_classes_error; } num_of_unnamed_class++; } - r_list_append (ret, klass); + rz_list_append (ret, klass); } return ret; get_classes_error: - r_list_free (sctns); - r_list_free (ret); - // XXX DOUBLE FREE r_bin_class_free (klass); + rz_list_free (sctns); + rz_list_free (ret); + // XXX DOUBLE FREE rz_bin_class_free (klass); return NULL; } -static RList *MACH0_(parse_categories)(RBinFile *bf, RSkipList *relocs) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj && bf->o->info, NULL); +static RzList *MACH0_(parse_categories)(RBinFile *bf, RzSkipList *relocs) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj && bf->o->info, NULL); - RList /**/ *ret = NULL; + RzList /**/ *ret = NULL; RBinObject *obj = bf->o; const ut32 ptr_size = sizeof (mach0_ut); bool is_found = false; @@ -1378,7 +1378,7 @@ static RList *MACH0_(parse_categories)(RBinFile *bf, RSkipList *relocs) { goto error; } - if (!ret && !(ret = r_list_newf ((RListFree)r_bin_class_free))) { + if (!ret && !(ret = rz_list_newf ((RzListFree)rz_bin_class_free))) { goto error; } @@ -1397,11 +1397,11 @@ static RList *MACH0_(parse_categories)(RBinFile *bf, RSkipList *relocs) { if (!(klass = R_NEW0 (RBinClass))) { goto error; } - if (!(klass->methods = r_list_new ())) { + if (!(klass->methods = rz_list_new ())) { R_FREE (klass); goto error; } - if (!(klass->fields = r_list_new ())) { + if (!(klass->fields = rz_list_new ())) { R_FREE (klass); goto error; } @@ -1414,17 +1414,17 @@ static RList *MACH0_(parse_categories)(RBinFile *bf, RSkipList *relocs) { R_FREE (klass); continue; } - r_list_append (ret, klass); + rz_list_append (ret, klass); } return ret; error: - r_list_free (ret); + rz_list_free (ret); return NULL; } -void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipList *relocs) { - r_return_if_fail (bf && bf->o && bf->o->info); +void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RzSkipList *relocs) { + rz_return_if_fail (bf && bf->o && bf->o->info); struct MACH0_(SCategory) c = { 0 }; const int size = sizeof (struct MACH0_(SCategory)); @@ -1451,7 +1451,7 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis eprintf ("Cannot parse obj category info out of bounds\n"); return; } - len = r_buf_read_at (bf->buf, r, sc, size); + len = rz_buf_read_at (bf->buf, r, sc, size); if (len != size) { return; } @@ -1460,17 +1460,17 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis ut32 bits = 8 * ptr_size; i = 0; - c.name = r_read_ble (&sc[i], bigendian, bits); + c.name = rz_read_ble (&sc[i], bigendian, bits); i += ptr_size; - c.targetClass = r_read_ble (&sc[i], bigendian, bits); + c.targetClass = rz_read_ble (&sc[i], bigendian, bits); i += ptr_size; - c.instanceMethods = r_read_ble (&sc[i], bigendian, bits); + c.instanceMethods = rz_read_ble (&sc[i], bigendian, bits); i += ptr_size; - c.classMethods = r_read_ble (&sc[i], bigendian, bits); + c.classMethods = rz_read_ble (&sc[i], bigendian, bits); i += ptr_size; - c.protocols = r_read_ble (&sc[i], bigendian, bits); + c.protocols = rz_read_ble (&sc[i], bigendian, bits); i += ptr_size; - c.properties = r_read_ble (&sc[i], bigendian, bits); + c.properties = rz_read_ble (&sc[i], bigendian, bits); char *category_name = read_str (bf, c.name, &offset, &left); if (!category_name) { @@ -1485,7 +1485,7 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis } struct reloc_t reloc_at_class_addr; reloc_at_class_addr.addr = p + ptr_size; - RSkipListNode *found = r_skiplist_find (relocs, &reloc_at_class_addr); + RzSkipListNode *found = rz_skiplist_find (relocs, &reloc_at_class_addr); if (!found) { R_FREE (category_name); return; @@ -1494,12 +1494,12 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis const char *_objc_class = "_OBJC_CLASS_$_"; const int _objc_class_len = strlen (_objc_class); target_class_name = (char*) ((struct reloc_t*) found->data)->name; - if (!r_str_startswith (target_class_name, _objc_class)) { + if (!rz_str_startswith (target_class_name, _objc_class)) { R_FREE (category_name); return; } target_class_name += _objc_class_len; - klass->name = r_str_newf ("%s(%s)", target_class_name, category_name); + klass->name = rz_str_newf ("%s(%s)", target_class_name, category_name); } else { mach0_ut ro_data_field = c.targetClass + 4 * ptr_size; mach0_ut ro_data; @@ -1522,7 +1522,7 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis if (target_class_name) { demangled = demangle_classname (target_class_name); } - klass->name = r_str_newf ("%s(%s)", demangled ? demangled : "(null)", category_name); + klass->name = rz_str_newf ("%s(%s)", demangled ? demangled : "(null)", category_name); R_FREE (target_class_name); R_FREE (demangled); } @@ -1549,25 +1549,25 @@ void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RSkipLis } static bool read_ptr_pa(RBinFile *bf, ut64 paddr, mach0_ut *out) { - r_return_val_if_fail (out, false); - r_return_val_if_fail (bf && bf->o && bf->o->info, false); + rz_return_val_if_fail (out, false); + rz_return_val_if_fail (bf && bf->o && bf->o->info, false); size_t ptr_size = sizeof (mach0_ut); ut8 pp[sizeof (mach0_ut)] = {0}; - int len = r_buf_read_at (bf->buf, paddr, pp, ptr_size); + int len = rz_buf_read_at (bf->buf, paddr, pp, ptr_size); if (len != ptr_size) { return false; } - mach0_ut p = r_read_ble (&pp[0], bf->o->info->big_endian, 8 * ptr_size); + mach0_ut p = rz_read_ble (&pp[0], bf->o->info->big_endian, 8 * ptr_size); *out = p; return true; } static bool read_ptr_va(RBinFile *bf, ut64 vaddr, mach0_ut *out) { - r_return_val_if_fail (bf, false); + rz_return_val_if_fail (bf, false); ut32 offset = 0, left = 0; mach0_ut paddr = va2pa (vaddr, &offset, &left, bf); if (paddr == 0 || left < sizeof (mach0_ut)) { @@ -1577,7 +1577,7 @@ static bool read_ptr_va(RBinFile *bf, ut64 vaddr, mach0_ut *out) { } static char *read_str(RBinFile *bf, mach0_ut p, ut32 *offset, ut32 *left) { - r_return_val_if_fail (bf && offset && left, NULL); + rz_return_val_if_fail (bf && offset && left, NULL); mach0_ut paddr = va2pa (p, offset, left, bf); if (paddr == 0 || *left <= 1) { @@ -1586,7 +1586,7 @@ static char *read_str(RBinFile *bf, mach0_ut p, ut32 *offset, ut32 *left) { int name_len = R_MIN (MAX_CLASS_NAME_LEN, *left); char *name = calloc (1, name_len + 1); - int len = r_buf_read_at (bf->buf, paddr, (ut8 *)name, name_len); + int len = rz_buf_read_at (bf->buf, paddr, (ut8 *)name, name_len); if (len < name_len) { eprintf ("Error reading\n"); R_FREE (name); diff --git a/librz/bin/format/objc/mach0_classes.h b/librz/bin/format/objc/mach0_classes.h new file mode 100644 index 0000000000..7720b9efd7 --- /dev/null +++ b/librz/bin/format/objc/mach0_classes.h @@ -0,0 +1,24 @@ +#include + +#include "mach0/mach0_specs.h" +#include "mach0/mach0.h" + +#undef mach0_ut +#undef rz_bin_plugin_mach + +#ifdef R_BIN_MACH064 +#define mach0_ut ut64 +#define rz_bin_plugin_mach rz_bin_plugin_mach064 +#else +#define mach0_ut ut32 +#define rz_bin_plugin_mach rz_bin_plugin_mach0 +#endif + +#ifndef MACH0_CLASSES_H +#define MACH0_CLASSES_H + +RZ_API RzList *MACH0_(parse_classes)(RBinFile *bf); +RZ_API void MACH0_(get_class_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, bool dupe, RzSkipList *relocs); +RZ_API void MACH0_(get_category_t)(mach0_ut p, RBinFile *bf, RBinClass *klass, RzSkipList *relocs); + +#endif // MACH0_CLASSES_H diff --git a/libr/bin/format/omf/omf.c b/librz/bin/format/omf/omf.c similarity index 89% rename from libr/bin/format/omf/omf.c rename to librz/bin/format/omf/omf.c index 20b32d32f1..13f321e9f8 100644 --- a/libr/bin/format/omf/omf.c +++ b/librz/bin/format/omf/omf.c @@ -22,7 +22,7 @@ static bool is_valid_omf_type(ut8 type) { return false; } -bool r_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size) { +bool rz_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size) { ut16 size; ut8 checksum = 0; @@ -157,7 +157,7 @@ static int load_omf_segdef(OMF_record *record, const ut8 *buf, ut64 buf_size) { if (buf[3] & 2) { ret->size = UT32_MAX; } else { - ret->size = r_read_le32 (buf + 4 + off_add); + ret->size = rz_read_le32 (buf + 4 + off_add); } } else { if (record->size < 3 + off_add) { @@ -168,7 +168,7 @@ static int load_omf_segdef(OMF_record *record, const ut8 *buf, ut64 buf_size) { if (buf[3] & 2) { ret->size = UT16_MAX; } - ret->size = r_read_le16 (buf + 4 + off_add); + ret->size = rz_read_le16 (buf + 4 + off_add); } ret->bits = (buf[3] & 1)? 32: 16; @@ -215,13 +215,13 @@ static int load_omf_symb(OMF_record *record, ut32 ct, const ut8 *buf, int buf_si eprintf ("Invalid Pubdef record (bad size)\n"); return false; } - symbol->offset = r_read_le32 (buf + ct + 1 + str_size); + symbol->offset = rz_read_le32 (buf + ct + 1 + str_size); } else { if (ct + 1 + str_size + 2 - 3 > record->size) { eprintf ("Invalid Pubdef record (bad size)\n"); return false; } - symbol->offset = r_read_le16 (buf + ct + 1 + str_size); + symbol->offset = rz_read_le16 (buf + ct + 1 + str_size); } symbol->seg_idx = seg_idx; @@ -337,10 +337,10 @@ static int load_omf_data(const ut8 *buf, int buf_size, OMF_record *record, ut64 ct++; } if (record->type == OMF_LEDATA32) { - offset = r_read_le32 (buf + ct); + offset = rz_read_le32 (buf + ct); ct += 4; } else { - offset = r_read_le16 (buf + ct); + offset = rz_read_le16 (buf + ct); ct += 2; } if (!(ret = R_NEW0 (OMF_data))) { @@ -387,12 +387,12 @@ static int load_omf_content(OMF_record *record, const ut8 *buf, ut64 global_ct, static OMF_record_handler *load_record_omf(const ut8 *buf, ut64 global_ct, ut64 buf_size){ OMF_record_handler *new = NULL; - if (is_valid_omf_type (*buf) && r_bin_checksum_omf_ok (buf, buf_size)) { + if (is_valid_omf_type (*buf) && rz_bin_checksum_omf_ok (buf, buf_size)) { if (!(new = R_NEW0 (OMF_record_handler))) { return NULL; } ((OMF_record *)new)->type = *buf; - ((OMF_record *)new)->size = r_read_le16 (buf + 1); + ((OMF_record *)new)->size = rz_read_le16 (buf + 1); // at least a record have a type a size and a checksum if (((OMF_record *)new)->size > buf_size - 3 || buf_size < 4) { @@ -411,7 +411,7 @@ static OMF_record_handler *load_record_omf(const ut8 *buf, ut64 global_ct, ut64 return new; } -static int load_all_omf_records(r_bin_omf_obj *obj, const ut8 *buf, ut64 size) { +static int load_all_omf_records(rz_bin_omf_obj *obj, const ut8 *buf, ut64 size) { ut64 ct = 0; OMF_record_handler *new_rec = NULL; OMF_record_handler *tmp = NULL; @@ -434,7 +434,7 @@ static int load_all_omf_records(r_bin_omf_obj *obj, const ut8 *buf, ut64 size) { return true; } -static ut32 count_omf_record_type(r_bin_omf_obj *obj, ut8 type) { +static ut32 count_omf_record_type(rz_bin_omf_obj *obj, ut8 type) { OMF_record_handler *tmp = obj->records; ut32 ct = 0; @@ -447,7 +447,7 @@ static ut32 count_omf_record_type(r_bin_omf_obj *obj, ut8 type) { return ct; } -static ut32 count_omf_multi_record_type(r_bin_omf_obj *obj, ut8 type) { +static ut32 count_omf_multi_record_type(rz_bin_omf_obj *obj, ut8 type) { OMF_record_handler *tmp = obj->records; ut32 ct = 0; @@ -470,7 +470,7 @@ static OMF_record_handler *get_next_omf_record_type(OMF_record_handler *tmp, ut8 return NULL; } -static int cpy_omf_names(r_bin_omf_obj *obj) { +static int cpy_omf_names(rz_bin_omf_obj *obj) { OMF_record_handler *tmp = obj->records; OMF_multi_datas *lname; int ct_obj = 0; @@ -492,7 +492,7 @@ static int cpy_omf_names(r_bin_omf_obj *obj) { return true; } -static void get_omf_section_info(r_bin_omf_obj *obj) { +static void get_omf_section_info(rz_bin_omf_obj *obj) { OMF_record_handler *tmp = obj->records; ut32 ct_obj = 0; @@ -511,7 +511,7 @@ static void get_omf_section_info(r_bin_omf_obj *obj) { } } -static int get_omf_symbol_info(r_bin_omf_obj *obj) { +static int get_omf_symbol_info(rz_bin_omf_obj *obj) { OMF_record_handler *tmp = obj->records; OMF_multi_datas *symbols; int ct_obj = 0; @@ -534,7 +534,7 @@ static int get_omf_symbol_info(r_bin_omf_obj *obj) { return true; } -static int get_omf_data_info(r_bin_omf_obj *obj) { +static int get_omf_data_info(rz_bin_omf_obj *obj) { OMF_record_handler *tmp = obj->records; OMF_data *tmp_data; @@ -558,7 +558,7 @@ static int get_omf_data_info(r_bin_omf_obj *obj) { return true; } -static int get_omf_infos(r_bin_omf_obj *obj) { +static int get_omf_infos(rz_bin_omf_obj *obj) { // get all name defined in lnames records obj->nb_name = count_omf_multi_record_type (obj, OMF_LNAMES); if (obj->nb_name>0) { @@ -602,7 +602,7 @@ static void free_pubdef(OMF_multi_datas *datas) { R_FREE (datas); } -static void free_all_omf_records(r_bin_omf_obj *obj) { +static void free_all_omf_records(rz_bin_omf_obj *obj) { OMF_record_handler *tmp = NULL; OMF_record_handler *rec = obj->records; @@ -621,7 +621,7 @@ static void free_all_omf_records(r_bin_omf_obj *obj) { obj->records = NULL; } -static void free_all_omf_sections(r_bin_omf_obj *obj) { +static void free_all_omf_sections(rz_bin_omf_obj *obj) { ut32 ct = 0; OMF_data *data; @@ -637,7 +637,7 @@ static void free_all_omf_sections(r_bin_omf_obj *obj) { R_FREE (obj->sections); } -static void free_all_omf_symbols(r_bin_omf_obj *obj) { +static void free_all_omf_symbols(rz_bin_omf_obj *obj) { ut32 ct = 0; while (ct < obj->nb_symbol) { R_FREE(obj->symbols[ct]->name); @@ -648,7 +648,7 @@ static void free_all_omf_symbols(r_bin_omf_obj *obj) { R_FREE (obj->symbols); } -static void free_all_omf_names(r_bin_omf_obj *obj) { +static void free_all_omf_names(rz_bin_omf_obj *obj) { ut32 ct = 0; while (ct < obj->nb_name) { @@ -658,7 +658,7 @@ static void free_all_omf_names(r_bin_omf_obj *obj) { R_FREE(obj->names); } -void r_bin_free_all_omf_obj(r_bin_omf_obj *obj) { +void rz_bin_free_all_omf_obj(rz_bin_omf_obj *obj) { if (obj) { if (obj->records) { free_all_omf_records (obj); @@ -676,25 +676,25 @@ void r_bin_free_all_omf_obj(r_bin_omf_obj *obj) { } } -r_bin_omf_obj *r_bin_internal_omf_load(const ut8 *buf, ut64 size) { - r_bin_omf_obj *ret = NULL; +rz_bin_omf_obj *rz_bin_internal_omf_load(const ut8 *buf, ut64 size) { + rz_bin_omf_obj *ret = NULL; - if (!(ret = R_NEW0 (r_bin_omf_obj))) { + if (!(ret = R_NEW0 (rz_bin_omf_obj))) { return NULL; } if (!load_all_omf_records(ret, buf, size)) { - r_bin_free_all_omf_obj(ret); + rz_bin_free_all_omf_obj(ret); return NULL; } if(!(get_omf_infos(ret))) { - r_bin_free_all_omf_obj(ret); + rz_bin_free_all_omf_obj(ret); return NULL; } free_all_omf_records(ret); return ret; } -bool r_bin_omf_get_entry(r_bin_omf_obj *obj, RBinAddr *addr) { +bool rz_bin_omf_get_entry(rz_bin_omf_obj *obj, RBinAddr *addr) { ut32 ct_sym = 0; OMF_data *data; ut32 offset = 0; @@ -724,7 +724,7 @@ bool r_bin_omf_get_entry(r_bin_omf_obj *obj, RBinAddr *addr) { return false; } -int r_bin_omf_get_bits(r_bin_omf_obj *obj) { +int rz_bin_omf_get_bits(rz_bin_omf_obj *obj) { ut32 ct_sec = 0; if (!obj) { return 32; @@ -739,7 +739,7 @@ int r_bin_omf_get_bits(r_bin_omf_obj *obj) { return 16; } -int r_bin_omf_send_sections(RList *list, OMF_segment *section, r_bin_omf_obj *obj) { +int rz_bin_omf_send_sections(RzList *list, OMF_segment *section, rz_bin_omf_obj *obj) { RBinSection *new; OMF_data *data = section->data; ut32 ct_name = 1; @@ -751,9 +751,9 @@ int r_bin_omf_send_sections(RList *list, OMF_segment *section, r_bin_omf_obj *ob // if index == 0, it's mean there is no name if (section->name_idx && section->name_idx - 1 < obj->nb_name) { - new->name = r_str_newf ("%s_%d", obj->names[section->name_idx - 1], ct_name++); + new->name = rz_str_newf ("%s_%d", obj->names[section->name_idx - 1], ct_name++); } else { - new->name = r_str_newf ("no_name_%d", ct_name++); + new->name = rz_str_newf ("no_name_%d", ct_name++); } new->size = data->size; @@ -762,13 +762,13 @@ int r_bin_omf_send_sections(RList *list, OMF_segment *section, r_bin_omf_obj *ob new->vaddr = section->vaddr + data->offset + OMF_BASE_ADDR; new->perm = R_PERM_RWX; new->add = true; - r_list_append (list, new); + rz_list_append (list, new); data = data->next; } return true; } -ut64 r_bin_omf_get_paddr_sym(r_bin_omf_obj *obj, OMF_symbol *sym) { +ut64 rz_bin_omf_get_paddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym) { ut64 offset = 0; if (!obj->sections) { return 0LL; @@ -791,7 +791,7 @@ ut64 r_bin_omf_get_paddr_sym(r_bin_omf_obj *obj, OMF_symbol *sym) { return 0; } -ut64 r_bin_omf_get_vaddr_sym(r_bin_omf_obj *obj, OMF_symbol *sym) { +ut64 rz_bin_omf_get_vaddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym) { if (!obj->sections) { return 0LL; } diff --git a/libr/bin/format/omf/omf.h b/librz/bin/format/omf/omf.h similarity index 63% rename from libr/bin/format/omf/omf.h rename to librz/bin/format/omf/omf.h index 0ace48bbc9..af24549cbd 100644 --- a/libr/bin/format/omf/omf.h +++ b/librz/bin/format/omf/omf.h @@ -1,9 +1,9 @@ #ifndef OMF_H_ #define OMF_H_ -#include -#include -#include +#include +#include +#include #include "omf_specs.h" @@ -50,19 +50,19 @@ typedef struct { OMF_symbol **symbols; ut32 nb_symbol; OMF_record_handler *records; -} r_bin_omf_obj; +} rz_bin_omf_obj; // this value was chosen arbitrarily to made the loader work correctly // if someone want to implement rellocation for omf he has to remove this #define OMF_BASE_ADDR 0x1000 -bool r_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size); -r_bin_omf_obj *r_bin_internal_omf_load(const ut8 *buf, ut64 size); -void r_bin_free_all_omf_obj(r_bin_omf_obj *obj); -bool r_bin_omf_get_entry(r_bin_omf_obj *obj, RBinAddr *addr); -int r_bin_omf_get_bits(r_bin_omf_obj *obj); -int r_bin_omf_send_sections(RList *list, OMF_segment *section, r_bin_omf_obj *obj); -ut64 r_bin_omf_get_paddr_sym(r_bin_omf_obj *obj, OMF_symbol *sym); -ut64 r_bin_omf_get_vaddr_sym(r_bin_omf_obj *obj, OMF_symbol *sym); +bool rz_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size); +rz_bin_omf_obj *rz_bin_internal_omf_load(const ut8 *buf, ut64 size); +void rz_bin_free_all_omf_obj(rz_bin_omf_obj *obj); +bool rz_bin_omf_get_entry(rz_bin_omf_obj *obj, RBinAddr *addr); +int rz_bin_omf_get_bits(rz_bin_omf_obj *obj); +int rz_bin_omf_send_sections(RzList *list, OMF_segment *section, rz_bin_omf_obj *obj); +ut64 rz_bin_omf_get_paddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym); +ut64 rz_bin_omf_get_vaddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym); #endif diff --git a/libr/bin/format/omf/omf_specs.h b/librz/bin/format/omf/omf_specs.h similarity index 100% rename from libr/bin/format/omf/omf_specs.h rename to librz/bin/format/omf/omf_specs.h diff --git a/libr/bin/format/p9/p9bin.c b/librz/bin/format/p9/p9bin.c similarity index 83% rename from libr/bin/format/p9/p9bin.c rename to librz/bin/format/p9/p9bin.c index 96f9326ca5..6b79e69d8c 100644 --- a/libr/bin/format/p9/p9bin.c +++ b/librz/bin/format/p9/p9bin.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2011 pancake */ #include "p9bin.h" -#include +#include -int r_bin_p9_get_arch(RBuffer *b, int *bits, int *big_endian) { - st32 a = (st32) r_buf_read_be32_at (b, 0); +int rz_bin_p9_get_arch(RBuffer *b, int *bits, int *big_endian) { + st32 a = (st32) rz_buf_read_be32_at (b, 0); if (bits) { *bits = 32; } diff --git a/libr/bin/format/p9/p9bin.h b/librz/bin/format/p9/p9bin.h similarity index 95% rename from libr/bin/format/p9/p9bin.h rename to librz/bin/format/p9/p9bin.h index bd9edf7040..4ab3819b47 100644 --- a/libr/bin/format/p9/p9bin.h +++ b/librz/bin/format/p9/p9bin.h @@ -1,7 +1,7 @@ #ifndef P9BIN_H #define P9BIN_H -#include +#include /* * Binary loader for Plan 9's a.out executable format @@ -51,6 +51,6 @@ struct plan9_exec { #define p9bin_close(x) fclose(x) /* Reads four bytes from b. */ -int r_bin_p9_get_arch(RBuffer *b, int *bits, int *big_endian); +int rz_bin_p9_get_arch(RBuffer *b, int *bits, int *big_endian); #endif diff --git a/libr/bin/format/pe/dotnet.c b/librz/bin/format/pe/dotnet.c similarity index 99% rename from libr/bin/format/pe/dotnet.c rename to librz/bin/format/pe/dotnet.c index 8a04564af7..9e243fbf8b 100644 --- a/libr/bin/format/pe/dotnet.c +++ b/librz/bin/format/pe/dotnet.c @@ -34,7 +34,7 @@ typedef struct _IMAGE_DATA_DIRECTORY { DWORD Size; } IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY; -#include "r_types.h" +#include "rz_types.h" #include "pe_specs.h" #include "dotnet.h" diff --git a/libr/bin/format/pe/dotnet.h b/librz/bin/format/pe/dotnet.h similarity index 99% rename from libr/bin/format/pe/dotnet.h rename to librz/bin/format/pe/dotnet.h index b511f44df8..0258d7a0ca 100644 --- a/libr/bin/format/pe/dotnet.h +++ b/librz/bin/format/pe/dotnet.h @@ -1,7 +1,7 @@ #ifndef YR_DOTNET_H #define YR_DOTNET_H -#include +#include #include "pe_specs.h" #pragma pack(push, 1) diff --git a/libr/bin/format/pe/pe.c b/librz/bin/format/pe/pe.c similarity index 84% rename from libr/bin/format/pe/pe.c rename to librz/bin/format/pe/pe.c index e4e8816037..a4223663d2 100644 --- a/libr/bin/format/pe/pe.c +++ b/librz/bin/format/pe/pe.c @@ -3,9 +3,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "pe.h" #include #include @@ -41,11 +41,11 @@ typedef struct { void (* free)(struct SCV_RSDS_HEADER* rsds_hdr); } SCV_RSDS_HEADER; -static inline int is_thumb(struct PE_(r_bin_pe_obj_t)* bin) { +static inline int is_thumb(struct PE_(rz_bin_pe_obj_t)* bin) { return bin->nt_headers->optional_header.AddressOfEntryPoint & 1; } -static inline int is_arm(struct PE_(r_bin_pe_obj_t)* bin) { +static inline int is_arm(struct PE_(rz_bin_pe_obj_t)* bin) { switch (bin->nt_headers->file_header.Machine) { case PE_IMAGE_FILE_MACHINE_RPI2: // 462 case PE_IMAGE_FILE_MACHINE_ARM: @@ -55,33 +55,33 @@ static inline int is_arm(struct PE_(r_bin_pe_obj_t)* bin) { return 0; } -static inline bool read_and_follow_jump(struct r_bin_pe_addr_t *entry, RBuffer *buf, ut8 *b, int len, bool big_endian) { - if (!r_buf_read_at (buf, entry->paddr, b, len)) { +static inline bool read_and_follow_jump(struct rz_bin_pe_addr_t *entry, RBuffer *buf, ut8 *b, int len, bool big_endian) { + if (!rz_buf_read_at (buf, entry->paddr, b, len)) { return false; } if (b[0] != 0xe9) { return true; } - const st32 jmp_dst = r_read_ble32 (b + 1, big_endian) + 5; + const st32 jmp_dst = rz_read_ble32 (b + 1, big_endian) + 5; entry->paddr += jmp_dst; entry->vaddr += jmp_dst; - return r_buf_read_at (buf, entry->paddr, b, len) > 0; + return rz_buf_read_at (buf, entry->paddr, b, len) > 0; } -static inline bool follow_offset(struct r_bin_pe_addr_t *entry, RBuffer *buf, ut8 *b, int len, bool big_endian, size_t instr_off) { - const st32 dst_offset = r_read_ble32 (b + instr_off + 1, big_endian) + instr_off + 5; +static inline bool follow_offset(struct rz_bin_pe_addr_t *entry, RBuffer *buf, ut8 *b, int len, bool big_endian, size_t instr_off) { + const st32 dst_offset = rz_read_ble32 (b + instr_off + 1, big_endian) + instr_off + 5; entry->paddr += dst_offset; entry->vaddr += dst_offset; return read_and_follow_jump (entry, buf, b, len, big_endian); } -struct r_bin_pe_addr_t *PE_(check_msvcseh)(struct PE_(r_bin_pe_obj_t) *bin) { - r_return_val_if_fail (bin && bin->b, NULL); +struct rz_bin_pe_addr_t *PE_(check_msvcseh)(struct PE_(rz_bin_pe_obj_t) *bin) { + rz_return_val_if_fail (bin && bin->b, NULL); ut8 b[512]; size_t n = 0; - struct r_bin_pe_addr_t* entry = PE_(r_bin_pe_get_entrypoint) (bin); + struct rz_bin_pe_addr_t* entry = PE_(rz_bin_pe_get_entrypoint) (bin); ZERO_FILL (b); - if (r_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { + if (rz_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { bprintf ("Warning: Cannot read entry at 0x%08"PFMT64x "\n", entry->paddr); free (entry); return NULL; @@ -100,7 +100,7 @@ struct r_bin_pe_addr_t *PE_(check_msvcseh)(struct PE_(r_bin_pe_obj_t) *bin) { // E8 3E F9 FF FF call 0x44B4FF ut32 imageBase = bin->nt_headers->optional_header.ImageBase; for (n = 0; n < sizeof (b) - 6; n++) { - const ut32 tmp_imgbase = r_read_ble32 (b + n + 1, bin->big_endian); + const ut32 tmp_imgbase = rz_read_ble32 (b + n + 1, bin->big_endian); if (b[n] == 0x68 && tmp_imgbase == imageBase && b[n + 5] == 0xe8) { follow_offset (entry, bin->b, b, sizeof (b), bin->big_endian, n + 5); return entry; @@ -271,17 +271,17 @@ struct r_bin_pe_addr_t *PE_(check_msvcseh)(struct PE_(r_bin_pe_obj_t) *bin) { return NULL; } -struct r_bin_pe_addr_t *PE_(check_mingw)(struct PE_(r_bin_pe_obj_t) *bin) { - struct r_bin_pe_addr_t* entry; +struct rz_bin_pe_addr_t *PE_(check_mingw)(struct PE_(rz_bin_pe_obj_t) *bin) { + struct rz_bin_pe_addr_t* entry; bool sw = false; ut8 b[1024]; size_t n = 0; if (!bin || !bin->b) { return 0LL; } - entry = PE_(r_bin_pe_get_entrypoint) (bin); + entry = PE_(rz_bin_pe_get_entrypoint) (bin); ZERO_FILL (b); - if (r_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { + if (rz_buf_read_at (bin->b, entry->paddr, b, sizeof (b)) < 0) { bprintf ("Warning: Cannot read entry at 0x%08"PFMT64x "\n", entry->paddr); free (entry); return NULL; @@ -328,16 +328,16 @@ struct r_bin_pe_addr_t *PE_(check_mingw)(struct PE_(r_bin_pe_obj_t) *bin) { return NULL; } -struct r_bin_pe_addr_t *PE_(check_unknow)(struct PE_(r_bin_pe_obj_t) *bin) { - struct r_bin_pe_addr_t *entry; +struct rz_bin_pe_addr_t *PE_(check_unknow)(struct PE_(rz_bin_pe_obj_t) *bin) { + struct rz_bin_pe_addr_t *entry; if (!bin || !bin->b) { return 0LL; } ut8 b[512]; ZERO_FILL (b); - entry = PE_ (r_bin_pe_get_entrypoint) (bin); + entry = PE_ (rz_bin_pe_get_entrypoint) (bin); // option2: /x 8bff558bec83ec20 - if (r_buf_read_at (bin->b, entry->paddr, b, 512) < 1) { + if (rz_buf_read_at (bin->b, entry->paddr, b, 512) < 1) { bprintf ("Warning: Cannot read entry at 0x%08"PFMT64x"\n", entry->paddr); free (entry); return NULL; @@ -366,8 +366,8 @@ struct r_bin_pe_addr_t *PE_(check_unknow)(struct PE_(r_bin_pe_obj_t) *bin) { return NULL; } -struct r_bin_pe_addr_t *PE_(r_bin_pe_get_main_vaddr)(struct PE_(r_bin_pe_obj_t) *bin) { - struct r_bin_pe_addr_t *winmain = PE_(check_msvcseh) (bin); +struct rz_bin_pe_addr_t *PE_(rz_bin_pe_get_main_vaddr)(struct PE_(rz_bin_pe_obj_t) *bin) { + struct rz_bin_pe_addr_t *winmain = PE_(check_msvcseh) (bin); if (!winmain) { winmain = PE_(check_mingw) (bin); if (!winmain) { @@ -377,7 +377,7 @@ struct r_bin_pe_addr_t *PE_(r_bin_pe_get_main_vaddr)(struct PE_(r_bin_pe_obj_t) return winmain; } -#define RBinPEObj struct PE_(r_bin_pe_obj_t) +#define RBinPEObj struct PE_(rz_bin_pe_obj_t) static PE_DWord bin_pe_rva_to_paddr(RBinPEObj* bin, PE_DWord rva) { PE_DWord section_base; int i, section_size; @@ -391,7 +391,7 @@ static PE_DWord bin_pe_rva_to_paddr(RBinPEObj* bin, PE_DWord rva) { return rva; } -ut64 PE_(r_bin_pe_get_image_base)(struct PE_(r_bin_pe_obj_t)* bin) { +ut64 PE_(rz_bin_pe_get_image_base)(struct PE_(rz_bin_pe_obj_t)* bin) { ut64 imageBase = 0; if (!bin || !bin->nt_headers) { return 0LL; @@ -407,11 +407,11 @@ ut64 PE_(r_bin_pe_get_image_base)(struct PE_(r_bin_pe_obj_t)* bin) { } static PE_DWord bin_pe_rva_to_va(RBinPEObj* bin, PE_DWord rva) { - return PE_(r_bin_pe_get_image_base) (bin) + rva; + return PE_(rz_bin_pe_get_image_base) (bin) + rva; } static PE_DWord bin_pe_va_to_rva(RBinPEObj* bin, PE_DWord va) { - ut64 imageBase = PE_(r_bin_pe_get_image_base) (bin); + ut64 imageBase = PE_(rz_bin_pe_get_image_base) (bin); if (va < imageBase) { return va; } @@ -429,8 +429,8 @@ static char* resolveModuleOrdinal(Sdb* sdb, const char* module, int ordinal) { return NULL; } -static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, - struct r_bin_pe_import_t** importp, int* nimp, +static int bin_pe_parse_imports(struct PE_(rz_bin_pe_obj_t)* bin, + struct rz_bin_pe_import_t** importp, int* nimp, const char* dll_name, PE_DWord OriginalFirstThunk, PE_DWord FirstThunk) { @@ -460,7 +460,7 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, if (off + i * sizeof(PE_DWord) > bin->size) { break; } - len = r_buf_read_at (bin->b, off + i * sizeof (PE_DWord), (ut8*) &import_table, sizeof (PE_DWord)); + len = rz_buf_read_at (bin->b, off + i * sizeof (PE_DWord), (ut8*) &import_table, sizeof (PE_DWord)); if (len != sizeof (PE_DWord)) { bprintf ("Warning: read (import table)\n"); goto error; @@ -476,7 +476,7 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, // remove the trailling ".dll" size_t len = strlen (symdllname); - r_str_case (symdllname, 0); + rz_str_case (symdllname, 0); len = len < 4? 0: len - 4; symdllname[len] = 0; @@ -489,13 +489,13 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, free (sdb_module); sdb_module = strdup (symdllname); filename = sdb_fmt ("%s.sdb", symdllname); - if (r_file_exists (filename)) { + if (rz_file_exists (filename)) { db = sdb_new (NULL, filename, 0); } else { - const char *dirPrefix = r_sys_prefix (NULL); + const char *dirPrefix = rz_sys_prefix (NULL); filename = sdb_fmt (R_JOIN_4_PATHS ("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), dirPrefix, symdllname); - if (r_file_exists (filename)) { + if (rz_file_exists (filename)) { db = sdb_new (NULL, filename, 0); } } @@ -517,13 +517,13 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, bprintf ("Warning: off > bin->size\n"); goto error; } - len = r_buf_read_at (bin->b, off, (ut8*) &import_hint, sizeof (PE_Word)); + len = rz_buf_read_at (bin->b, off, (ut8*) &import_hint, sizeof (PE_Word)); if (len != sizeof (PE_Word)) { bprintf ("Warning: read import hint at 0x%08"PFMT64x "\n", off); goto error; } name[0] = '\0'; - len = r_buf_read_at (bin->b, off + sizeof(PE_Word), (ut8*) name, PE_NAME_LENGTH); + len = rz_buf_read_at (bin->b, off + sizeof(PE_Word), (ut8*) name, PE_NAME_LENGTH); if (len < 1) { bprintf ("Warning: read (import name)\n"); goto error; @@ -536,9 +536,9 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin, eprintf ("Import name '%s' has been truncated.\n", import_name); } } - struct r_bin_pe_import_t *new_importp = realloc (*importp, (*nimp + 1) * sizeof (struct r_bin_pe_import_t)); + struct rz_bin_pe_import_t *new_importp = realloc (*importp, (*nimp + 1) * sizeof (struct rz_bin_pe_import_t)); if (!new_importp) { - r_sys_perror ("realloc (import)"); + rz_sys_perror ("realloc (import)"); goto error; } *importp = new_importp; @@ -574,12 +574,12 @@ error: return false; } -static int bin_pe_init_hdr(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_hdr(struct PE_(rz_bin_pe_obj_t)* bin) { if (!(bin->dos_header = malloc (sizeof(PE_(image_dos_header))))) { - r_sys_perror ("malloc (dos header)"); + rz_sys_perror ("malloc (dos header)"); return false; } - if (r_buf_read_at (bin->b, 0, (ut8*) bin->dos_header, sizeof(PE_(image_dos_header))) < 0) { + if (rz_buf_read_at (bin->b, 0, (ut8*) bin->dos_header, sizeof(PE_(image_dos_header))) < 0) { bprintf ("Warning: read (dos header)\n"); return false; } @@ -593,11 +593,11 @@ static int bin_pe_init_hdr(struct PE_(r_bin_pe_obj_t)* bin) { return false; } if (!(bin->nt_headers = malloc (sizeof (PE_(image_nt_headers))))) { - r_sys_perror ("malloc (nt header)"); + rz_sys_perror ("malloc (nt header)"); return false; } bin->nt_header_offset = bin->dos_header->e_lfanew; - if (r_buf_read_at (bin->b, bin->dos_header->e_lfanew, (ut8*) bin->nt_headers, sizeof (PE_(image_nt_headers))) < 0) { + if (rz_buf_read_at (bin->b, bin->dos_header->e_lfanew, (ut8*) bin->nt_headers, sizeof (PE_(image_nt_headers))) < 0) { bprintf ("Warning: read (dos header)\n"); return false; } @@ -650,7 +650,7 @@ static int bin_pe_init_hdr(struct PE_(r_bin_pe_obj_t)* bin) { // adding compile time to the SDB { sdb_num_set (bin->kv, "image_file_header.TimeDateStamp", bin->nt_headers->file_header.TimeDateStamp, 0); - char *timestr = r_time_stamp_to_str (bin->nt_headers->file_header.TimeDateStamp); + char *timestr = rz_time_stamp_to_str (bin->nt_headers->file_header.TimeDateStamp); sdb_set_owned (bin->kv, "image_file_header.TimeDateStamp_string", timestr, 0); } bin->optional_header = &bin->nt_headers->optional_header; @@ -674,13 +674,13 @@ typedef struct { ut8 numaux; } SymbolRecord; -static struct r_bin_pe_export_t* parse_symbol_table(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_pe_export_t* exports, int sz) { +static struct rz_bin_pe_export_t* parse_symbol_table(struct PE_(rz_bin_pe_obj_t)* bin, struct rz_bin_pe_export_t* exports, int sz) { ut64 sym_tbl_off, num = 0; const int srsz = COFF_SYMBOL_SIZE; // symbol record size - struct r_bin_pe_section_t* sections; - struct r_bin_pe_export_t* exp; - struct r_bin_pe_export_t* new_exports = NULL; - const size_t export_t_sz = sizeof (struct r_bin_pe_export_t); + struct rz_bin_pe_section_t* sections; + struct rz_bin_pe_export_t* exp; + struct rz_bin_pe_export_t* new_exports = NULL; + const size_t export_t_sz = sizeof (struct rz_bin_pe_export_t); int bufsz, i, shsz; SymbolRecord sr; ut64 text_off = 0LL; @@ -715,7 +715,7 @@ static struct r_bin_pe_export_t* parse_symbol_table(struct PE_(r_bin_pe_obj_t)* } exports = new_exports; new_exports = NULL; - exp = (struct r_bin_pe_export_t*) (((const ut8*) exports) + osz); + exp = (struct rz_bin_pe_export_t*) (((const ut8*) exports) + osz); } else { sz = exports_sz; exports = malloc (sz + export_t_sz); @@ -732,7 +732,7 @@ static struct r_bin_pe_export_t* parse_symbol_table(struct PE_(r_bin_pe_obj_t)* } } symctr = 0; - if (r_buf_read_at (bin->b, sym_tbl_off, (ut8*) buf, bufsz) > 0) { + if (rz_buf_read_at (bin->b, sym_tbl_off, (ut8*) buf, bufsz) > 0) { for (i = 0; i < shsz; i += srsz) { // sr = (SymbolRecord*) (buf + i); if (i + sizeof (sr) >= bufsz) { @@ -749,8 +749,8 @@ static struct r_bin_pe_export_t* parse_symbol_table(struct PE_(r_bin_pe_obj_t)* strncpy ((char*) exp[symctr].name, shortname, PE_NAME_LENGTH - 1); } else { char* longname, name[128]; - ut32 idx = r_read_le32 (buf + i + 4); - if (r_buf_read_at (bin->b, sym_tbl_off + idx + shsz, (ut8*) name, 128)) { // == 128) { + ut32 idx = rz_read_le32 (buf + i + 4); + if (rz_buf_read_at (bin->b, sym_tbl_off + idx + shsz, (ut8*) name, 128)) { // == 128) { longname = name; name[sizeof(name) - 1] = 0; strncpy ((char*) exp[symctr].name, longname, PE_NAME_LENGTH - 1); @@ -775,8 +775,8 @@ static struct r_bin_pe_export_t* parse_symbol_table(struct PE_(r_bin_pe_obj_t)* return exports; } -static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe_obj_t)* bin); -static int bin_pe_init_sections(struct PE_(r_bin_pe_obj_t)* bin) { +static struct rz_bin_pe_section_t* PE_(rz_bin_pe_get_sections)(struct PE_(rz_bin_pe_obj_t)* bin); +static int bin_pe_init_sections(struct PE_(rz_bin_pe_obj_t)* bin) { bin->num_sections = bin->nt_headers->file_header.NumberOfSections; if (bin->num_sections < 1) { return true; @@ -790,12 +790,12 @@ static int bin_pe_init_sections(struct PE_(r_bin_pe_obj_t)* bin) { //goto out_error; } if (!(bin->section_header = malloc (sections_size))) { - r_sys_perror ("malloc (section header)"); + rz_sys_perror ("malloc (section header)"); goto out_error; } bin->section_header_offset = bin->dos_header->e_lfanew + 4 + sizeof (PE_(image_file_header)) + bin->nt_headers->file_header.SizeOfOptionalHeader; - if (r_buf_read_at (bin->b, bin->section_header_offset, (ut8*) bin->section_header, sections_size) < 0) { + if (rz_buf_read_at (bin->b, bin->section_header_offset, (ut8*) bin->section_header, sections_size) < 0) { bprintf ("Warning: read (sections)\n"); R_FREE (bin->section_header); goto out_error; @@ -844,14 +844,14 @@ out_error: return false; } -int PE_(bin_pe_get_claimed_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(bin_pe_get_claimed_checksum)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->optional_header) { return 0; } return bin->optional_header->CheckSum; } -int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(bin_pe_get_actual_checksum)(struct PE_(rz_bin_pe_obj_t)* bin) { size_t i, j, checksum_offset = 0; ut64 computed_cs = 0; int remaining_bytes; @@ -865,13 +865,13 @@ int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { if (!buf) { return 0; } - if (r_buf_read_at (bin->b, 0, (ut8 *)buf, buf_sz) < 0) { + if (rz_buf_read_at (bin->b, 0, (ut8 *)buf, buf_sz) < 0) { free (buf); return 0; } checksum_offset = bin->nt_header_offset + 4 + sizeof(PE_(image_file_header)) + 0x40; for (i = 0, j = 0; i < bin->size / 4; i++) { - cur = r_read_at_ble32 (buf, j * 4, bin->endian); + cur = rz_read_at_ble32 (buf, j * 4, bin->endian); j++; // skip the checksum bytes if (i * 4 == checksum_offset) { @@ -883,7 +883,7 @@ int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { computed_cs = (computed_cs & 0xFFFFFFFF) + (computed_cs >> 32); } if (j == buf_sz / 4) { - if (r_buf_read_at (bin->b, (i + 1) * 4, (ut8 *)buf, buf_sz) < 0) { + if (rz_buf_read_at (bin->b, (i + 1) * 4, (ut8 *)buf, buf_sz) < 0) { break; } j = 0; @@ -894,10 +894,10 @@ int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { remaining_bytes = bin->size % 4; i = i * 4; if (remaining_bytes != 0) { - cur = r_buf_read8_at (bin->b, i); + cur = rz_buf_read8_at (bin->b, i); shift = 8; for (j = 1; j < remaining_bytes; j++, shift += 8) { - cur |= r_buf_read8_at (bin->b, i + j) << shift; + cur |= rz_buf_read8_at (bin->b, i + j) << shift; } computed_cs = (computed_cs & 0xFFFFFFFF) + cur + (computed_cs >> 32); if (computed_cs >> 32) { @@ -916,22 +916,22 @@ int PE_(bin_pe_get_actual_checksum)(struct PE_(r_bin_pe_obj_t)* bin) { return computed_cs; } -static const char* PE_(bin_pe_get_claimed_authentihash)(struct PE_(r_bin_pe_obj_t)* bin) { +static const char* PE_(bin_pe_get_claimed_authentihash)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin->spcinfo) { return NULL; } RASN1Binary *digest = bin->spcinfo->messageDigest.digest; - return r_hex_bin2strdup (digest->binary, digest->length); + return rz_hex_bin2strdup (digest->binary, digest->length); } -const char* PE_(bin_pe_compute_authentihash)(struct PE_(r_bin_pe_obj_t)* bin) { +const char* PE_(bin_pe_compute_authentihash)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin->spcinfo) { return NULL; } char *hashtype = strdup (bin->spcinfo->messageDigest.digestAlgorithm.algorithm->string); - r_str_replace_char (hashtype, '-', 0); - ut64 algobit = r_hash_name_to_bits (hashtype); + rz_str_replace_char (hashtype, '-', 0); + ut64 algobit = rz_hash_name_to_bits (hashtype); if (!(algobit & (R_HASH_MD5 | R_HASH_SHA1 | R_HASH_SHA256))) { eprintf ("Authenticode only supports md5, sha1, sha256. This PE uses %s\n", hashtype); free (hashtype); @@ -944,38 +944,38 @@ const char* PE_(bin_pe_compute_authentihash)(struct PE_(r_bin_pe_obj_t)* bin) { PE_DWord security_dir_offset = data_dir_security->VirtualAddress; ut32 security_dir_size = data_dir_security->Size; - RBuffer *buf = r_buf_new (); - r_buf_append_buf_slice (buf, bin->b, 0, checksum_paddr); - r_buf_append_buf_slice (buf, bin->b, + RBuffer *buf = rz_buf_new (); + rz_buf_append_buf_slice (buf, bin->b, 0, checksum_paddr); + rz_buf_append_buf_slice (buf, bin->b, checksum_paddr + 4, security_entry_offset - checksum_paddr - 4); - r_buf_append_buf_slice (buf, bin->b, + rz_buf_append_buf_slice (buf, bin->b, security_entry_offset + 8, security_dir_offset - security_entry_offset - 8); - r_buf_append_buf_slice (buf, bin->b, + rz_buf_append_buf_slice (buf, bin->b, security_dir_offset + security_dir_size, - r_buf_size (bin->b) - security_dir_offset - security_dir_size); + rz_buf_size (bin->b) - security_dir_offset - security_dir_size); ut64 len; - const ut8 *data = r_buf_data (buf, &len); + const ut8 *data = rz_buf_data (buf, &len); char *hashstr = NULL; - RHash *ctx = r_hash_new (true, algobit); + RzHash *ctx = rz_hash_new (true, algobit); if (ctx) { - r_hash_do_begin (ctx, algobit); - int digest_size = r_hash_calculate (ctx, algobit, data, len); - r_hash_do_end (ctx, algobit); - hashstr = r_hex_bin2strdup (ctx->digest, digest_size); - r_buf_free (buf); - r_hash_free (ctx); + rz_hash_do_begin (ctx, algobit); + int digest_size = rz_hash_calculate (ctx, algobit, data, len); + rz_hash_do_end (ctx, algobit); + hashstr = rz_hex_bin2strdup (ctx->digest, digest_size); + rz_buf_free (buf); + rz_hash_free (ctx); } return hashstr; } -const char* PE_(bin_pe_get_authentihash)(struct PE_(r_bin_pe_obj_t)* bin) { +const char* PE_(bin_pe_get_authentihash)(struct PE_(rz_bin_pe_obj_t)* bin) { return bin->authentihash; } -int PE_(bin_pe_is_authhash_valid)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(bin_pe_is_authhash_valid)(struct PE_(rz_bin_pe_obj_t)* bin) { return bin->is_authhash_valid; } @@ -987,7 +987,7 @@ static void computeOverlayOffset(ut64 offset, ut64 size, ut64 file_size, ut64* l } /* Inspired from https://github.com/erocarrera/pefile/blob/master/pefile.py#L5425 */ -int PE_(bin_pe_get_overlay)(struct PE_(r_bin_pe_obj_t)* bin, ut64* size) { +int PE_(bin_pe_get_overlay)(struct PE_(rz_bin_pe_obj_t)* bin, ut64* size) { ut64 largest_offset = 0; ut64 largest_size = 0; *size = 0; @@ -1006,7 +1006,7 @@ int PE_(bin_pe_get_overlay)(struct PE_(r_bin_pe_obj_t)* bin, ut64* size) { &largest_size); } - struct r_bin_pe_section_t *sects = bin->sections; + struct rz_bin_pe_section_t *sects = bin->sections; for (i = 0; !sects[i].last; i++) { computeOverlayOffset( sects[i].paddr, @@ -1043,7 +1043,7 @@ int PE_(bin_pe_get_overlay)(struct PE_(r_bin_pe_obj_t)* bin, ut64* size) { static int bin_pe_read_metadata_string(char* to, RBuffer *frombuf, int fromoff) { int covered = 0; while (covered < MAX_METADATA_STRING_LENGTH) { - char covch = r_buf_read8_at (frombuf, covered); + char covch = rz_buf_read8_at (frombuf, covered); to[covered] = covch; if (covch == '\0') { covered += 1; @@ -1055,7 +1055,7 @@ static int bin_pe_read_metadata_string(char* to, RBuffer *frombuf, int fromoff) return covered; } -static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_metadata_hdr(struct PE_(rz_bin_pe_obj_t)* bin) { PE_DWord metadata_directory = bin->clr_hdr? bin_pe_rva_to_paddr (bin, bin->clr_hdr->MetaDataDirectoryAddress): 0; PE_(image_metadata_header) * metadata = R_NEW0 (PE_(image_metadata_header)); int rr; @@ -1068,19 +1068,19 @@ static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { } - rr = r_buf_fread_at (bin->b, metadata_directory, + rr = rz_buf_fread_at (bin->b, metadata_directory, (ut8*) metadata, bin->big_endian? "1I2S": "1i2s", 1); if (rr < 1) { goto fail; } - rr = r_buf_fread_at (bin->b, metadata_directory + 8, + rr = rz_buf_fread_at (bin->b, metadata_directory + 8, (ut8*) (&metadata->Reserved), bin->big_endian? "1I": "1i", 1); if (rr < 1) { goto fail; } - rr = r_buf_fread_at (bin->b, metadata_directory + 12, + rr = rz_buf_fread_at (bin->b, metadata_directory + 12, (ut8*) (&metadata->VersionStringLength), bin->big_endian? "1I": "1i", 1); if (rr < 1) { goto fail; @@ -1097,7 +1097,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { goto fail; } - rr = r_buf_read_at (bin->b, metadata_directory + 16, (ut8*)(metadata->VersionString), len); + rr = rz_buf_read_at (bin->b, metadata_directory + 16, (ut8*)(metadata->VersionString), len); if (rr != len) { eprintf ("Warning: read (metadata header) - cannot parse version string\n"); free (metadata->VersionString); @@ -1108,7 +1108,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { } // read the header after the string - rr = r_buf_fread_at (bin->b, metadata_directory + 16 + metadata->VersionStringLength, + rr = rz_buf_fread_at (bin->b, metadata_directory + 16 + metadata->VersionStringLength, (ut8*) (&metadata->Flags), bin->big_endian? "2S": "2s", 1); if (rr < 1) { @@ -1135,7 +1135,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { goto fail; } - if (r_buf_fread_at (bin->b, start_of_stream, (ut8*) stream, bin->big_endian? "2I": "2i", 1) < 1) { + if (rz_buf_fread_at (bin->b, start_of_stream, (ut8*) stream, bin->big_endian? "2I": "2i", 1) < 1) { free (stream); free (streams); goto fail; @@ -1149,7 +1149,7 @@ static int bin_pe_init_metadata_hdr(struct PE_(r_bin_pe_obj_t)* bin) { goto fail; } - if (r_buf_size (bin->b) < (start_of_stream + 8 + MAX_METADATA_STRING_LENGTH)) { + if (rz_buf_size (bin->b) < (start_of_stream + 8 + MAX_METADATA_STRING_LENGTH)) { free (stream_name); free (stream); free (streams); @@ -1176,7 +1176,7 @@ fail: return 0; } -static int bin_pe_init_overlay(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_overlay(struct PE_(rz_bin_pe_obj_t)* bin) { ut64 pe_overlay_size; ut64 pe_overlay_offset = PE_(bin_pe_get_overlay) (bin, &pe_overlay_size); if (pe_overlay_offset) { @@ -1186,7 +1186,7 @@ static int bin_pe_init_overlay(struct PE_(r_bin_pe_obj_t)* bin) { return 0; } -static int bin_pe_init_clr_hdr(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_clr_hdr(struct PE_(rz_bin_pe_obj_t)* bin) { PE_(image_data_directory) * clr_dir = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR]; PE_DWord image_clr_hdr_paddr = bin_pe_rva_to_paddr (bin, clr_dir->VirtualAddress); // int clr_dir_size = clr_dir? clr_dir->Size: 0; @@ -1196,7 +1196,7 @@ static int bin_pe_init_clr_hdr(struct PE_(r_bin_pe_obj_t)* bin) { if (!clr_hdr) { return 0; } - rr = r_buf_read_at (bin->b, image_clr_hdr_paddr, (ut8*) (clr_hdr), len); + rr = rz_buf_read_at (bin->b, image_clr_hdr_paddr, (ut8*) (clr_hdr), len); // printf("%x\n", clr_hdr->HeaderSize); @@ -1215,7 +1215,7 @@ static int bin_pe_init_clr_hdr(struct PE_(r_bin_pe_obj_t)* bin) { return 1; } -static int bin_pe_init_imports(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_imports(struct PE_(rz_bin_pe_obj_t)* bin) { PE_(image_data_directory) * data_dir_import = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_IMPORT]; PE_(image_data_directory) * data_dir_delay_import = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT]; @@ -1253,7 +1253,7 @@ static int bin_pe_init_imports(struct PE_(r_bin_pe_obj_t)* bin) { if (maxidsz < 0) { maxidsz = 0; } - //int maxcount = maxidsz/ sizeof (struct r_bin_pe_import_t); + //int maxcount = maxidsz/ sizeof (struct rz_bin_pe_import_t); R_FREE (bin->import_directory); if (import_dir_paddr != 0) { @@ -1266,7 +1266,7 @@ static int bin_pe_init_imports(struct PE_(r_bin_pe_obj_t)* bin) { do { new_import_dir = (PE_(image_import_directory)*)realloc (import_dir, ((1 + indx) * dir_size)); if (!new_import_dir) { - r_sys_perror ("malloc (import directory)"); + rz_sys_perror ("malloc (import directory)"); R_FREE (import_dir); break; // // goto fail; @@ -1274,7 +1274,7 @@ static int bin_pe_init_imports(struct PE_(r_bin_pe_obj_t)* bin) { import_dir = new_import_dir; new_import_dir = NULL; curr_import_dir = import_dir + indx; - if (r_buf_read_at (bin->b, import_dir_offset + indx * dir_size, (ut8*) (curr_import_dir), dir_size) <= 0) { + if (rz_buf_read_at (bin->b, import_dir_offset + indx * dir_size, (ut8*) (curr_import_dir), dir_size) <= 0) { bprintf ("Warning: read (import directory)\n"); R_FREE (import_dir); break; //return false; @@ -1293,27 +1293,27 @@ static int bin_pe_init_imports(struct PE_(r_bin_pe_obj_t)* bin) { } indx = 0; - if (r_buf_size (bin->b) > 0) { - if ((delay_import_dir_offset != 0) && (delay_import_dir_offset < (ut32)r_buf_size (bin->b))) { + if (rz_buf_size (bin->b) > 0) { + if ((delay_import_dir_offset != 0) && (delay_import_dir_offset < (ut32)rz_buf_size (bin->b))) { ut64 off; bin->delay_import_directory_offset = delay_import_dir_offset; do { indx++; off = indx * delay_import_size; - if (off >= r_buf_size (bin->b)) { + if (off >= rz_buf_size (bin->b)) { bprintf ("Warning: Cannot find end of import symbols\n"); break; } new_delay_import_dir = (PE_(image_delay_import_directory)*)realloc ( delay_import_dir, (indx * delay_import_size) + 1); if (!new_delay_import_dir) { - r_sys_perror ("malloc (delay import directory)"); + rz_sys_perror ("malloc (delay import directory)"); free (delay_import_dir); return false; } delay_import_dir = new_delay_import_dir; curr_delay_import_dir = delay_import_dir + (indx - 1); - rr = r_buf_read_at (bin->b, delay_import_dir_offset + (indx - 1) * delay_import_size, + rr = rz_buf_read_at (bin->b, delay_import_dir_offset + (indx - 1) * delay_import_size, (ut8 *)(curr_delay_import_dir), dir_size); if (rr != dir_size) { bprintf ("Warning: read (delay import directory)\n"); @@ -1332,7 +1332,7 @@ fail: return false; } -static int bin_pe_init_exports(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_exports(struct PE_(rz_bin_pe_obj_t)* bin) { PE_(image_data_directory) * data_dir_export = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_EXPORT]; PE_DWord export_dir_paddr = bin_pe_rva_to_paddr (bin, data_dir_export->VirtualAddress); if (!export_dir_paddr) { @@ -1343,10 +1343,10 @@ static int bin_pe_init_exports(struct PE_(r_bin_pe_obj_t)* bin) { // sdb_setn (DB, "hdr.exports_directory", export_dir_paddr); // bprintf ("Pexports paddr at 0x%"PFMT64x"\n", export_dir_paddr); if (!(bin->export_directory = malloc (sizeof(PE_(image_export_directory))))) { - r_sys_perror ("malloc (export directory)"); + rz_sys_perror ("malloc (export directory)"); return false; } - if (r_buf_read_at (bin->b, export_dir_paddr, (ut8*) bin->export_directory, sizeof (PE_(image_export_directory))) < 0) { + if (rz_buf_read_at (bin->b, export_dir_paddr, (ut8*) bin->export_directory, sizeof (PE_(image_export_directory))) < 0) { bprintf ("Warning: read (export directory)\n"); R_FREE (bin->export_directory); return false; @@ -1354,7 +1354,7 @@ static int bin_pe_init_exports(struct PE_(r_bin_pe_obj_t)* bin) { return true; } -static void _free_resource(r_pe_resource *rs) { +static void _free_resource(rz_pe_resource *rs) { if (rs) { free (rs->name); free (rs->timestr); @@ -1366,22 +1366,22 @@ static void _free_resource(r_pe_resource *rs) { } -static int bin_pe_init_resource(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_resource(struct PE_(rz_bin_pe_obj_t)* bin) { PE_(image_data_directory) * resource_dir = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_RESOURCE]; PE_DWord resource_dir_paddr = bin_pe_rva_to_paddr (bin, resource_dir->VirtualAddress); if (!resource_dir_paddr) { return false; } - bin->resources = r_list_newf ((RListFree)_free_resource); + bin->resources = rz_list_newf ((RzListFree)_free_resource); if (!bin->resources) { return false; } if (!(bin->resource_directory = malloc (sizeof(*bin->resource_directory)))) { - r_sys_perror ("malloc (resource directory)"); + rz_sys_perror ("malloc (resource directory)"); return false; } - if (r_buf_read_at (bin->b, resource_dir_paddr, (ut8*) bin->resource_directory, + if (rz_buf_read_at (bin->b, resource_dir_paddr, (ut8*) bin->resource_directory, sizeof (*bin->resource_directory)) != sizeof (*bin->resource_directory)) { bprintf ("Warning: read (resource directory)\n"); R_FREE (bin->resource_directory); @@ -1391,14 +1391,14 @@ static int bin_pe_init_resource(struct PE_(r_bin_pe_obj_t)* bin) { return true; } -static void bin_pe_store_tls_callbacks(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord callbacks) { +static void bin_pe_store_tls_callbacks(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord callbacks) { PE_DWord paddr, haddr; int count = 0; PE_DWord addressOfTLSCallback = 1; char* key; while (addressOfTLSCallback != 0) { - if (r_buf_read_at (bin->b, callbacks, (ut8*) &addressOfTLSCallback, sizeof(addressOfTLSCallback)) != sizeof (addressOfTLSCallback)) { + if (rz_buf_read_at (bin->b, callbacks, (ut8*) &addressOfTLSCallback, sizeof(addressOfTLSCallback)) != sizeof (addressOfTLSCallback)) { bprintf ("Warning: read (tls_callback)\n"); return; } @@ -1424,13 +1424,13 @@ static void bin_pe_store_tls_callbacks(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord } } -static int bin_pe_init_tls(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init_tls(struct PE_(rz_bin_pe_obj_t)* bin) { PE_(image_tls_directory) * image_tls_directory; PE_(image_data_directory) * data_dir_tls = &bin->data_directory[PE_IMAGE_DIRECTORY_ENTRY_TLS]; PE_DWord tls_paddr = bin_pe_rva_to_paddr (bin, data_dir_tls->VirtualAddress); image_tls_directory = R_NEW0 (PE_(image_tls_directory)); - if (r_buf_read_at (bin->b, tls_paddr, (ut8*) image_tls_directory, sizeof (PE_(image_tls_directory))) != sizeof (PE_(image_tls_directory))) { + if (rz_buf_read_at (bin->b, tls_paddr, (ut8*) image_tls_directory, sizeof (PE_(image_tls_directory))) != sizeof (PE_(image_tls_directory))) { bprintf ("Warning: read (image_tls_directory)\n"); free (image_tls_directory); return 0; @@ -1522,25 +1522,25 @@ void PE_(free_VS_VERSIONINFO)(PE_VS_VERSIONINFO * vs_VersionInfo) { free_VS_VERSIONINFO (vs_VersionInfo); } -static Var* Pe_r_bin_pe_parse_var(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* curAddr) { +static Var* Pe_r_bin_pe_parse_var(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord* curAddr) { Var* var = calloc (1, sizeof(*var)); if (!var) { bprintf ("Warning: calloc (Var)\n"); return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &var->wLength, sizeof(var->wLength)) != sizeof(var->wLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &var->wLength, sizeof(var->wLength)) != sizeof(var->wLength)) { bprintf ("Warning: read (Var wLength)\n"); free_Var (var); return NULL; } *curAddr += sizeof(var->wLength); - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &var->wValueLength, sizeof(var->wValueLength)) != sizeof(var->wValueLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &var->wValueLength, sizeof(var->wValueLength)) != sizeof(var->wValueLength)) { bprintf ("Warning: read (Var wValueLength)\n"); free_Var (var); return NULL; } *curAddr += sizeof(var->wValueLength); - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &var->wType, sizeof(var->wType)) != sizeof(var->wType)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &var->wType, sizeof(var->wType)) != sizeof(var->wType)) { bprintf ("Warning: read (Var wType)\n"); free_Var (var); return NULL; @@ -1558,7 +1558,7 @@ static Var* Pe_r_bin_pe_parse_var(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* cur free_Var (var); return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) var->szKey, TRANSLATION_UTF_16_LEN) < 1) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) var->szKey, TRANSLATION_UTF_16_LEN) < 1) { bprintf ("Warning: read (Var szKey)\n"); free_Var (var); return NULL; @@ -1582,7 +1582,7 @@ static Var* Pe_r_bin_pe_parse_var(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* cur free_Var (var); return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) var->Value, var->wValueLength) != var->wValueLength) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) var->Value, var->wValueLength) != var->wValueLength) { bprintf ("Warning: read (Var Value)\n"); free_Var (var); return NULL; @@ -1591,21 +1591,21 @@ static Var* Pe_r_bin_pe_parse_var(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* cur return var; } -static VarFileInfo* Pe_r_bin_pe_parse_var_file_info(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* curAddr) { +static VarFileInfo* Pe_r_bin_pe_parse_var_file_info(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord* curAddr) { VarFileInfo* varFileInfo = calloc (1, sizeof(*varFileInfo)); if (!varFileInfo) { bprintf ("Warning: calloc (VarFileInfo)\n"); return NULL; } PE_DWord startAddr = *curAddr; - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wLength, sizeof(varFileInfo->wLength)) != sizeof(varFileInfo->wLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wLength, sizeof(varFileInfo->wLength)) != sizeof(varFileInfo->wLength)) { bprintf ("Warning: read (VarFileInfo wLength)\n"); free_VarFileInfo (varFileInfo); return NULL; } *curAddr += sizeof(varFileInfo->wLength); - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wValueLength, sizeof(varFileInfo->wValueLength)) != sizeof(varFileInfo->wValueLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wValueLength, sizeof(varFileInfo->wValueLength)) != sizeof(varFileInfo->wValueLength)) { bprintf ("Warning: read (VarFileInfo wValueLength)\n"); free_VarFileInfo (varFileInfo); return NULL; @@ -1618,7 +1618,7 @@ static VarFileInfo* Pe_r_bin_pe_parse_var_file_info(struct PE_(r_bin_pe_obj_t)* return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wType, sizeof(varFileInfo->wType)) != sizeof(varFileInfo->wType)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &varFileInfo->wType, sizeof(varFileInfo->wType)) != sizeof(varFileInfo->wType)) { bprintf ("Warning: read (VarFileInfo wType)\n"); free_VarFileInfo (varFileInfo); return NULL; @@ -1637,7 +1637,7 @@ static VarFileInfo* Pe_r_bin_pe_parse_var_file_info(struct PE_(r_bin_pe_obj_t)* return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) varFileInfo->szKey, VARFILEINFO_UTF_16_LEN) != VARFILEINFO_UTF_16_LEN) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) varFileInfo->szKey, VARFILEINFO_UTF_16_LEN) != VARFILEINFO_UTF_16_LEN) { bprintf ("Warning: read (VarFileInfo szKey)\n"); free_VarFileInfo (varFileInfo); return NULL; @@ -1669,7 +1669,7 @@ static VarFileInfo* Pe_r_bin_pe_parse_var_file_info(struct PE_(r_bin_pe_obj_t)* return varFileInfo; } -static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* curAddr) { +static String* Pe_r_bin_pe_parse_string(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord* curAddr) { String* string = calloc (1, sizeof(*string)); PE_DWord begAddr = *curAddr; int len_value = 0; @@ -1682,7 +1682,7 @@ static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWor free_String (string); return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &string->wLength, sizeof(string->wLength)) != sizeof(string->wLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &string->wLength, sizeof(string->wLength)) != sizeof(string->wLength)) { bprintf ("Warning: read (String wLength)\n"); goto out_error; } @@ -1690,7 +1690,7 @@ static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWor if (*curAddr > bin->size || *curAddr + sizeof(string->wValueLength) > bin->size) { goto out_error; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &string->wValueLength, sizeof(string->wValueLength)) != sizeof(string->wValueLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &string->wValueLength, sizeof(string->wValueLength)) != sizeof(string->wValueLength)) { bprintf ("Warning: read (String wValueLength)\n"); goto out_error; } @@ -1699,7 +1699,7 @@ static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWor if (*curAddr > bin->size || *curAddr + sizeof(string->wType) > bin->size) { goto out_error; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &string->wType, sizeof(string->wType)) != sizeof(string->wType)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &string->wType, sizeof(string->wType)) != sizeof(string->wType)) { bprintf ("Warning: read (String wType)\n"); goto out_error; } @@ -1715,7 +1715,7 @@ static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWor if (*curAddr > bin->size || *curAddr + sizeof (ut16) > bin->size) { goto out_error; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &utf16_char, sizeof (ut16)) != sizeof (ut16)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &utf16_char, sizeof (ut16)) != sizeof (ut16)) { bprintf ("Warning: check (String szKey)\n"); goto out_error; } @@ -1746,7 +1746,7 @@ static String* Pe_r_bin_pe_parse_string(struct PE_(r_bin_pe_obj_t)* bin, PE_DWor if (*curAddr > bin->size || *curAddr + len_value > bin->size) { goto out_error; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) string->Value, len_value) != len_value) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) string->Value, len_value) != len_value) { bprintf ("Warning: read (String Value)\n"); goto out_error; } @@ -1757,7 +1757,7 @@ out_error: return NULL; } -static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* curAddr) { +static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord* curAddr) { StringTable* stringTable = calloc (1, sizeof(*stringTable)); if (!stringTable) { bprintf ("Warning: calloc (stringTable)\n"); @@ -1765,14 +1765,14 @@ static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(r_bin_pe_obj_t)* b } PE_DWord startAddr = *curAddr; - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wLength, sizeof(stringTable->wLength)) != sizeof(stringTable->wLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wLength, sizeof(stringTable->wLength)) != sizeof(stringTable->wLength)) { bprintf ("Warning: read (StringTable wLength)\n"); free_StringTable (stringTable); return NULL; } *curAddr += sizeof(stringTable->wLength); - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wValueLength, sizeof(stringTable->wValueLength)) != sizeof(stringTable->wValueLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wValueLength, sizeof(stringTable->wValueLength)) != sizeof(stringTable->wValueLength)) { bprintf ("Warning: read (StringTable wValueLength)\n"); free_StringTable (stringTable); return NULL; @@ -1785,7 +1785,7 @@ static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(r_bin_pe_obj_t)* b return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wType, sizeof(stringTable->wType)) != sizeof(stringTable->wType)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringTable->wType, sizeof(stringTable->wType)) != sizeof(stringTable->wType)) { bprintf ("Warning: read (StringTable wType)\n"); free_StringTable (stringTable); return NULL; @@ -1803,7 +1803,7 @@ static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(r_bin_pe_obj_t)* b return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) stringTable->szKey, EIGHT_HEX_DIG_UTF_16_LEN) != EIGHT_HEX_DIG_UTF_16_LEN) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) stringTable->szKey, EIGHT_HEX_DIG_UTF_16_LEN) != EIGHT_HEX_DIG_UTF_16_LEN) { bprintf ("Warning: read (StringTable szKey)\n"); free_StringTable (stringTable); return NULL; @@ -1836,7 +1836,7 @@ static StringTable* Pe_r_bin_pe_parse_string_table(struct PE_(r_bin_pe_obj_t)* b return stringTable; } -static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord* curAddr) { +static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord* curAddr) { StringFileInfo* stringFileInfo = calloc (1, sizeof(*stringFileInfo)); if (!stringFileInfo) { bprintf ("Warning: calloc (StringFileInfo)\n"); @@ -1845,14 +1845,14 @@ static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(r_bin_pe_ob PE_DWord startAddr = *curAddr; - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wLength, sizeof(stringFileInfo->wLength)) != sizeof(stringFileInfo->wLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wLength, sizeof(stringFileInfo->wLength)) != sizeof(stringFileInfo->wLength)) { bprintf ("Warning: read (StringFileInfo wLength)\n"); free_StringFileInfo (stringFileInfo); return NULL; } *curAddr += sizeof(stringFileInfo->wLength); - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wValueLength, sizeof(stringFileInfo->wValueLength)) != sizeof(stringFileInfo->wValueLength)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wValueLength, sizeof(stringFileInfo->wValueLength)) != sizeof(stringFileInfo->wValueLength)) { bprintf ("Warning: read (StringFileInfo wValueLength)\n"); free_StringFileInfo (stringFileInfo); return NULL; @@ -1865,7 +1865,7 @@ static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(r_bin_pe_ob return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wType, sizeof(stringFileInfo->wType)) != sizeof(stringFileInfo->wType)) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) &stringFileInfo->wType, sizeof(stringFileInfo->wType)) != sizeof(stringFileInfo->wType)) { bprintf ("Warning: read (StringFileInfo wType)\n"); free_StringFileInfo (stringFileInfo); return NULL; @@ -1885,7 +1885,7 @@ static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(r_bin_pe_ob return NULL; } - if (r_buf_read_at (bin->b, *curAddr, (ut8*) stringFileInfo->szKey, STRINGFILEINFO_UTF_16_LEN) != STRINGFILEINFO_UTF_16_LEN) { + if (rz_buf_read_at (bin->b, *curAddr, (ut8*) stringFileInfo->szKey, STRINGFILEINFO_UTF_16_LEN) != STRINGFILEINFO_UTF_16_LEN) { bprintf ("Warning: read (StringFileInfo szKey)\n"); free_StringFileInfo (stringFileInfo); return NULL; @@ -1929,7 +1929,7 @@ static StringFileInfo* Pe_r_bin_pe_parse_string_file_info(struct PE_(r_bin_pe_ob #define EXIT_ON_OVERFLOW(S)\ if (curAddr > bin->size || curAddr + (S) > bin->size) { \ goto out_error; } -static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(r_bin_pe_obj_t)* bin, PE_DWord version_info_paddr) { +static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(rz_bin_pe_obj_t)* bin, PE_DWord version_info_paddr) { ut32 sz; PE_VS_VERSIONINFO* vs_VersionInfo = calloc (1, sizeof(PE_VS_VERSIONINFO)); if (!vs_VersionInfo) { @@ -1944,19 +1944,19 @@ static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(r_bin_pe_obj //Mb we are in subsequent version resource data and not aligned. sz = sizeof(ut16); EXIT_ON_OVERFLOW (sz); - if (r_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wLength, sz) != sz) { + if (rz_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wLength, sz) != sz) { bprintf ("Warning: read (VS_VERSIONINFO wLength)\n"); goto out_error; } curAddr += sz; EXIT_ON_OVERFLOW (sz); - if (r_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wValueLength, sz) != sz) { + if (rz_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wValueLength, sz) != sz) { bprintf ("Warning: read (VS_VERSIONINFO wValueLength)\n"); goto out_error; } curAddr += sz; EXIT_ON_OVERFLOW (sz); - if (r_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wType, sz) != sz) { + if (rz_buf_read_at (bin->b, curAddr, (ut8*) &vs_VersionInfo->wType, sz) != sz) { bprintf ("Warning: read (VS_VERSIONINFO wType)\n"); goto out_error; } @@ -1973,7 +1973,7 @@ static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(r_bin_pe_obj } sz = VS_VERSION_INFO_UTF_16_LEN; EXIT_ON_OVERFLOW (sz); - if (r_buf_read_at (bin->b, curAddr, (ut8*) vs_VersionInfo->szKey, sz) != sz) { + if (rz_buf_read_at (bin->b, curAddr, (ut8*) vs_VersionInfo->szKey, sz) != sz) { bprintf ("Warning: read (VS_VERSIONINFO szKey)\n"); goto out_error; } @@ -1995,7 +1995,7 @@ static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(r_bin_pe_obj } sz = sizeof(PE_VS_FIXEDFILEINFO); EXIT_ON_OVERFLOW (sz); - if (r_buf_read_at (bin->b, curAddr, (ut8*) vs_VersionInfo->Value, sz) != sz) { + if (rz_buf_read_at (bin->b, curAddr, (ut8*) vs_VersionInfo->Value, sz) != sz) { bprintf ("Warning: read (VS_VERSIONINFO Value)\n"); goto out_error; } @@ -2013,7 +2013,7 @@ static PE_VS_VERSIONINFO* Pe_r_bin_pe_parse_version_info(struct PE_(r_bin_pe_obj if (curAddr + 3 * sizeof(ut16) > bin->size || curAddr + 3 + sizeof(ut64) + 1 > bin->size) { goto out_error; } - if (r_buf_read_at (bin->b, curAddr + 3 * sizeof(ut16), (ut8*) &t, 1) != 1) { + if (rz_buf_read_at (bin->b, curAddr + 3 * sizeof(ut16), (ut8*) &t, 1) != 1) { bprintf ("Warning: read (VS_VERSIONINFO Children V or S)\n"); goto out_error; } @@ -2461,36 +2461,36 @@ static char* _known_product_ids(int id) { } } -static void bin_pe_init_rich_info(struct PE_(r_bin_pe_obj_t) *bin) { +static void bin_pe_init_rich_info(struct PE_(rz_bin_pe_obj_t) *bin) { if (!bin->rich_entries) { - bin->rich_entries = r_list_newf (free); + bin->rich_entries = rz_list_newf (free); } bin->rich_header_offset = bin->nt_header_offset; ut64 off = bin->nt_header_offset - sizeof (ut32); ut32 magic = 0x68636952; // Rich - while ((r_buf_read_le32_at (bin->b, off) != magic) && off) { + while ((rz_buf_read_le32_at (bin->b, off) != magic) && off) { off -= sizeof (ut32); } if (!off) { return; } - ut32 mask = r_buf_read_le32_at (bin->b, off + sizeof (ut32)); + ut32 mask = rz_buf_read_le32_at (bin->b, off + sizeof (ut32)); magic = 0x536E6144; // DanS int data; off -= sizeof (ut32); - while (((data = r_buf_read_le32_at (bin->b, off)) != magic) && data ^ mask && off > 0x80) { + while (((data = rz_buf_read_le32_at (bin->b, off)) != magic) && data ^ mask && off > 0x80) { Pe_image_rich_entry *entry = R_NEW0 (Pe_image_rich_entry); if (!entry) { return; } entry->timesUsed = data ^ mask; off -= sizeof (ut32); - data = r_buf_read_le32_at (bin->b, off) ^ mask; + data = rz_buf_read_le32_at (bin->b, off) ^ mask; entry->productId = data >> 16; entry->minVersion = data & 0xFFFF; entry->productName = _known_product_ids (entry->productId); off -= sizeof (ut32); - r_list_append (bin->rich_entries, entry); + rz_list_append (bin->rich_entries, entry); } bin->rich_header_offset = off + sizeof (ut32); } @@ -2660,12 +2660,12 @@ static char* _resource_type_str(int type) { case 24: typeName = "MANIFEST"; break; - default: return r_str_newf ("UNKNOWN (%d)",type); + default: return rz_str_newf ("UNKNOWN (%d)",type); } return strdup (typeName); } -static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_resource_directory *dir, ut64 offDir, int type, int id, HtUU *dirs, const char *resource_name) { +static void _parse_resource_directory(struct PE_(rz_bin_pe_obj_t) *bin, Pe_image_resource_directory *dir, ut64 offDir, int type, int id, HtUU *dirs, const char *resource_name) { char *resourceEntryName = NULL; int index = 0; ut32 totalRes = dir->NumberOfNamedEntries + dir->NumberOfIdEntries; @@ -2684,22 +2684,22 @@ static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_ if (off > bin->size || off + sizeof (entry) > bin->size) { break; } - if (r_buf_read_at (bin->b, off, (ut8*)&entry, sizeof(entry)) < 1) { + if (rz_buf_read_at (bin->b, off, (ut8*)&entry, sizeof(entry)) < 1) { eprintf ("Warning: read resource entry\n"); break; } if (entry.u1.s.NameIsString) { int i; ut16 buf; - if (r_buf_read_at (bin->b, bin->resource_directory_offset + entry.u1.s.NameOffset, (ut8*)&buf, sizeof (ut16)) != sizeof (ut16)) { + if (rz_buf_read_at (bin->b, bin->resource_directory_offset + entry.u1.s.NameOffset, (ut8*)&buf, sizeof (ut16)) != sizeof (ut16)) { break; } - ut16 resourceEntryNameLength = r_read_le16 (&buf); + ut16 resourceEntryNameLength = rz_read_le16 (&buf); resourceEntryName = calloc (resourceEntryNameLength + 1, 1); if (resourceEntryName) { for (i = 0; i < resourceEntryNameLength; i++) { /* Convert Unicode to ASCII */ ut8 byte; - int r = r_buf_read_at (bin->b, bin->resource_directory_offset + entry.u1.s.NameOffset + 2 + (i*2), &byte, sizeof (ut8)); + int r = rz_buf_read_at (bin->b, bin->resource_directory_offset + entry.u1.s.NameOffset + 2 + (i*2), &byte, sizeof (ut8)); if (r != sizeof (ut8) || !byte) { R_FREE (resourceEntryName); break; @@ -2712,7 +2712,7 @@ static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_ //detect here malicious file trying to making us infinite loop Pe_image_resource_directory identEntry; off = rsrc_base + entry.u2.s.OffsetToDirectory; - int len = r_buf_read_at (bin->b, off, (ut8*) &identEntry, sizeof (identEntry)); + int len = rz_buf_read_at (bin->b, off, (ut8*) &identEntry, sizeof (identEntry)); if (len < 1 || len != sizeof (Pe_image_resource_directory)) { eprintf ("Warning: parsing resource directory\n"); } @@ -2731,7 +2731,7 @@ static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_ free (data); break; } - if (r_buf_read_at (bin->b, off, (ut8*)data, sizeof (*data)) != sizeof (*data)) { + if (rz_buf_read_at (bin->b, off, (ut8*)data, sizeof (*data)) != sizeof (*data)) { eprintf ("Warning: read (resource data entry)\n"); free (data); break; @@ -2777,16 +2777,16 @@ static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_ } sdb_ns_set (bin->kv, "vs_version_info", sdb); } - r_pe_resource *rs = R_NEW0 (r_pe_resource); + rz_pe_resource *rs = R_NEW0 (rz_pe_resource); if (!rs) { free (data); break; } /* Compare compileTimeStamp to resource timestamp to figure out if DOS date or POSIX date */ - if (r_time_stamp_is_dos_format ((ut32) sdb_num_get (bin->kv, "image_file_header.TimeDateStamp", 0), dir->TimeDateStamp)) { - rs->timestr = r_time_stamp_to_str ( r_time_dos_time_stamp_to_posix (dir->TimeDateStamp)); + if (rz_time_stamp_is_dos_format ((ut32) sdb_num_get (bin->kv, "image_file_header.TimeDateStamp", 0), dir->TimeDateStamp)) { + rs->timestr = rz_time_stamp_to_str ( rz_time_dos_time_stamp_to_posix (dir->TimeDateStamp)); } else { - rs->timestr = r_time_stamp_to_str (dir->TimeDateStamp); + rs->timestr = rz_time_stamp_to_str (dir->TimeDateStamp); } rs->type = _resource_type_str (type); rs->language = strdup (_resource_lang_str (entry.u1.Name & 0x3ff)); @@ -2794,15 +2794,15 @@ static void _parse_resource_directory(struct PE_(r_bin_pe_obj_t) *bin, Pe_image_ if (resource_name) { rs->name = strdup (resource_name); } else { - rs->name = r_str_newf ("%d", id); + rs->name = rz_str_newf ("%d", id); } - r_list_append (bin->resources, rs); + rz_list_append (bin->resources, rs); } } -static void _store_resource_sdb(struct PE_(r_bin_pe_obj_t) *bin) { - RListIter *iter; - r_pe_resource *rs; +static void _store_resource_sdb(struct PE_(rz_bin_pe_obj_t) *bin) { + RzListIter *iter; + rz_pe_resource *rs; int index = 0; ut64 vaddr = 0; char *key; @@ -2810,7 +2810,7 @@ static void _store_resource_sdb(struct PE_(r_bin_pe_obj_t) *bin) { if (!sdb) { return; } - r_list_foreach (bin->resources, iter, rs) { + rz_list_foreach (bin->resources, iter, rs) { key = sdb_fmt ("resource.%d.timestr", index); sdb_set (sdb, key, rs->timestr, 0); key = sdb_fmt ("resource.%d.vaddr", index); @@ -2830,7 +2830,7 @@ static void _store_resource_sdb(struct PE_(r_bin_pe_obj_t) *bin) { } -R_API void PE_(bin_pe_parse_resource)(struct PE_(r_bin_pe_obj_t) *bin) { +RZ_API void PE_(bin_pe_parse_resource)(struct PE_(rz_bin_pe_obj_t) *bin) { int index = 0; ut64 off = 0, rsrc_base = bin->resource_directory_offset; Pe_image_resource_directory *rs_directory = bin->resource_directory; @@ -2859,14 +2859,14 @@ R_API void PE_(bin_pe_parse_resource)(struct PE_(r_bin_pe_obj_t) *bin) { if (off > bin->size || off + sizeof(typeEntry) > bin->size) { break; } - if (r_buf_read_at (bin->b, off, (ut8*)&typeEntry, sizeof(typeEntry)) < 1) { + if (rz_buf_read_at (bin->b, off, (ut8*)&typeEntry, sizeof(typeEntry)) < 1) { eprintf ("Warning: read resource directory entry\n"); break; } if (typeEntry.u2.s.DataIsDirectory) { Pe_image_resource_directory identEntry; off = rsrc_base + typeEntry.u2.s.OffsetToDirectory; - int len = r_buf_read_at (bin->b, off, (ut8*)&identEntry, sizeof(identEntry)); + int len = rz_buf_read_at (bin->b, off, (ut8*)&identEntry, sizeof(identEntry)); if (len < 1 || len != sizeof (identEntry)) { eprintf ("Warning: parsing resource directory\n"); } @@ -2877,7 +2877,7 @@ R_API void PE_(bin_pe_parse_resource)(struct PE_(r_bin_pe_obj_t) *bin) { _store_resource_sdb (bin); } -static int bin_pe_init_security(struct PE_(r_bin_pe_obj_t) * bin) { +static int bin_pe_init_security(struct PE_(rz_bin_pe_obj_t) * bin) { if (!bin || !bin->nt_headers) { return false; } @@ -2909,15 +2909,15 @@ static int bin_pe_init_security(struct PE_(r_bin_pe_obj_t) * bin) { if (!cert) { return false; } - cert->dwLength = r_buf_read_le32_at (bin->b, offset); + cert->dwLength = rz_buf_read_le32_at (bin->b, offset); cert->dwLength += (8 - (cert->dwLength & 7)) & 7; // align32 if (offset + cert->dwLength > paddr + size) { bprintf ("Invalid certificate entry"); R_FREE (cert); return false; } - cert->wRevision = r_buf_read_le16_at (bin->b, offset + 4); - cert->wCertificateType = r_buf_read_le16_at (bin->b, offset + 6); + cert->wRevision = rz_buf_read_le16_at (bin->b, offset + 4); + cert->wCertificateType = rz_buf_read_le16_at (bin->b, offset + 6); if (cert->dwLength < 6) { eprintf ("Cert.dwLength must be > 6\n"); R_FREE (cert); @@ -2927,11 +2927,11 @@ static int bin_pe_init_security(struct PE_(r_bin_pe_obj_t) * bin) { R_FREE (cert); return false; } - r_buf_read_at (bin->b, offset + 8, cert->bCertificate, cert->dwLength - 6); + rz_buf_read_at (bin->b, offset + 8, cert->bCertificate, cert->dwLength - 6); if (!bin->cms && cert->wCertificateType == PE_WIN_CERT_TYPE_PKCS_SIGNED_DATA) { - bin->cms = r_pkcs7_parse_cms (cert->bCertificate, cert->dwLength - 6); - bin->spcinfo = r_pkcs7_parse_spcinfo (bin->cms); + bin->cms = rz_pkcs7_parse_cms (cert->bCertificate, cert->dwLength - 6); + bin->spcinfo = rz_pkcs7_parse_spcinfo (bin->cms); } security_directory->certificates[security_directory->length] = cert; @@ -2968,7 +2968,7 @@ static void free_security_directory(Pe_image_security_directory *security_direct free (security_directory); } -static int bin_pe_init(struct PE_(r_bin_pe_obj_t)* bin) { +static int bin_pe_init(struct PE_(rz_bin_pe_obj_t)* bin) { bin->dos_header = NULL; bin->nt_headers = NULL; bin->section_header = NULL; @@ -2990,13 +2990,13 @@ static int bin_pe_init(struct PE_(r_bin_pe_obj_t)* bin) { eprintf ("Warning: Cannot initialize sections\n"); return false; } - bin->sections = PE_(r_bin_pe_get_sections) (bin); + bin->sections = PE_(rz_bin_pe_get_sections) (bin); bin_pe_init_imports (bin); bin_pe_init_exports (bin); bin_pe_init_resource (bin); bin_pe_init_security (bin); - bin->big_endian = PE_(r_bin_pe_is_big_endian) (bin); + bin->big_endian = PE_(rz_bin_pe_is_big_endian) (bin); bin_pe_init_rich_info (bin); bin_pe_init_tls (bin); @@ -3008,7 +3008,7 @@ static int bin_pe_init(struct PE_(r_bin_pe_obj_t)* bin) { return true; } -char* PE_(r_bin_pe_get_arch)(struct PE_(r_bin_pe_obj_t)* bin) { +char* PE_(rz_bin_pe_get_arch)(struct PE_(rz_bin_pe_obj_t)* bin) { char* arch; if (!bin || !bin->nt_headers) { return strdup ("x86"); @@ -3048,16 +3048,16 @@ char* PE_(r_bin_pe_get_arch)(struct PE_(r_bin_pe_obj_t)* bin) { return arch; } -struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)* bin) { - struct r_bin_pe_addr_t* entry = NULL; +struct rz_bin_pe_addr_t* PE_(rz_bin_pe_get_entrypoint)(struct PE_(rz_bin_pe_obj_t)* bin) { + struct rz_bin_pe_addr_t* entry = NULL; static bool debug = false; int i; - ut64 base_addr = PE_(r_bin_pe_get_image_base) (bin); + ut64 base_addr = PE_(rz_bin_pe_get_image_base) (bin); if (!bin || !bin->optional_header) { return NULL; } - if (!(entry = malloc (sizeof (struct r_bin_pe_addr_t)))) { - r_sys_perror ("malloc (entrypoint)"); + if (!(entry = malloc (sizeof (struct rz_bin_pe_addr_t)))) { + rz_sys_perror ("malloc (entrypoint)"); return NULL; } PE_DWord pe_entry = bin->optional_header->AddressOfEntryPoint; @@ -3067,7 +3067,7 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)* entry->haddr = bin->dos_header->e_lfanew + 4 + sizeof (PE_(image_file_header)) + 16; if (entry->paddr >= bin->size) { - struct r_bin_pe_section_t* sections = bin->sections; + struct rz_bin_pe_section_t* sections = bin->sections; ut64 paddr = 0; if (!debug) { bprintf ("Warning: Invalid entrypoint ... " @@ -3105,7 +3105,7 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)* if (!debug) { bprintf ("Warning: NULL entrypoint\n"); } - struct r_bin_pe_section_t* sections = bin->sections; + struct rz_bin_pe_section_t* sections = bin->sections; for (i = 0; i < bin->num_sections; i++) { //If there is a section with x without w perm is a good candidate to be the entrypoint if (sections[i].perm & PE_IMAGE_SCN_MEM_EXECUTE && !(sections[i].perm & PE_IMAGE_SCN_MEM_WRITE)) { @@ -3129,9 +3129,9 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)* return entry; } -struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* bin) { - r_return_val_if_fail (bin, NULL); - struct r_bin_pe_export_t* exp, * exports = NULL; +struct rz_bin_pe_export_t* PE_(rz_bin_pe_get_exports)(struct PE_(rz_bin_pe_obj_t)* bin) { + rz_return_val_if_fail (bin, NULL); + struct rz_bin_pe_export_t* exp, * exports = NULL; PE_Word function_ordinal = 0; PE_VWord functions_paddr, names_paddr, ordinals_paddr, function_rva, name_vaddr, name_paddr; char function_name[PE_NAME_LENGTH + 1], forwarder_name[PE_NAME_LENGTH + 1]; @@ -3155,8 +3155,8 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* // avoid integer overflow return NULL; } - exports_sz = (bin->export_directory->NumberOfFunctions + 1) * sizeof (struct r_bin_pe_export_t); - // we cant exit with export_sz > bin->size, us r_bin_pe_export_t is 256+256+8+8+8+4 bytes is easy get over file size + exports_sz = (bin->export_directory->NumberOfFunctions + 1) * sizeof (struct rz_bin_pe_export_t); + // we cant exit with export_sz > bin->size, us rz_bin_pe_export_t is 256+256+8+8+8+4 bytes is easy get over file size // to avoid fuzzing we can abort on export_directory->NumberOfFunctions>0xffff if (exports_sz < 0 || bin->export_directory->NumberOfFunctions + 1 > 0xffff) { return NULL; @@ -3164,7 +3164,7 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* if (!(exports = malloc (exports_sz))) { return NULL; } - if (r_buf_read_at (bin->b, bin_pe_rva_to_paddr (bin, bin->export_directory->Name), (ut8*) dll_name, PE_NAME_LENGTH) < 1) { + if (rz_buf_read_at (bin->b, bin_pe_rva_to_paddr (bin, bin->export_directory->Name), (ut8*) dll_name, PE_NAME_LENGTH) < 1) { // we dont stop if dll name cant be read, we set dllname to null and continue bprintf ("Warning: read (dll name)\n"); dll_name[0] = '\0'; @@ -3180,28 +3180,28 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* if (!ordinals || !func_rvas) { goto beach; } - int r = r_buf_read_at (bin->b, ordinals_paddr, (ut8 *)ordinals, names_sz); + int r = rz_buf_read_at (bin->b, ordinals_paddr, (ut8 *)ordinals, names_sz); if (r != names_sz) { goto beach; } - r = r_buf_read_at (bin->b, functions_paddr, (ut8 *)func_rvas, funcs_sz); + r = rz_buf_read_at (bin->b, functions_paddr, (ut8 *)func_rvas, funcs_sz); if (r != funcs_sz) { goto beach; } for (i = 0; i < bin->export_directory->NumberOfFunctions; i++) { // get vaddr from AddressOfFunctions array - function_rva = r_read_at_ble32 ((ut8 *)func_rvas, i * sizeof (PE_VWord), bin->endian); + function_rva = rz_read_at_ble32 ((ut8 *)func_rvas, i * sizeof (PE_VWord), bin->endian); // have exports by name? if (bin->export_directory->NumberOfNames > 0) { // search for value of i into AddressOfOrdinals name_vaddr = 0; for (n = 0; n < bin->export_directory->NumberOfNames; n++) { - PE_Word fo = r_read_at_ble16 ((ut8 *)ordinals, n * sizeof (PE_Word), bin->endian); + PE_Word fo = rz_read_at_ble16 ((ut8 *)ordinals, n * sizeof (PE_Word), bin->endian); // if exist this index into AddressOfOrdinals if (i == fo) { function_ordinal = fo; // get the VA of export name from AddressOfNames - r_buf_read_at (bin->b, names_paddr + n * sizeof (PE_VWord), (ut8*) &name_vaddr, sizeof (PE_VWord)); + rz_buf_read_at (bin->b, names_paddr + n * sizeof (PE_VWord), (ut8*) &name_vaddr, sizeof (PE_VWord)); break; } } @@ -3209,7 +3209,7 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* if (name_vaddr) { // get the name of the Export name_paddr = bin_pe_rva_to_paddr (bin, name_vaddr); - if (r_buf_read_at (bin->b, name_paddr, (ut8*) function_name, PE_NAME_LENGTH) < 1) { + if (rz_buf_read_at (bin->b, name_paddr, (ut8*) function_name, PE_NAME_LENGTH) < 1) { bprintf ("Warning: read (function name)\n"); exports[i].last = 1; return exports; @@ -3224,7 +3224,7 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* // check if VA are into export directory, this mean a forwarder export if (function_rva >= export_dir_rva && function_rva < (export_dir_rva + export_dir_size)) { // if forwarder, the VA point to Forwarded name - if (r_buf_read_at (bin->b, bin_pe_rva_to_paddr (bin, function_rva), (ut8*) forwarder_name, PE_NAME_LENGTH) < 1) { + if (rz_buf_read_at (bin->b, bin_pe_rva_to_paddr (bin, function_rva), (ut8*) forwarder_name, PE_NAME_LENGTH) < 1) { exports[i].last = 1; return exports; } @@ -3248,7 +3248,7 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)* free (ordinals); free (func_rvas); } - exp = parse_symbol_table (bin, exports, exports_sz - sizeof (struct r_bin_pe_export_t)); + exp = parse_symbol_table (bin, exports, exports_sz - sizeof (struct rz_bin_pe_export_t)); if (exp) { exports = exp; } @@ -3297,7 +3297,7 @@ static void get_nb10(ut8* dbg_data, int dbg_data_len, SCV_NB10_HEADER* res) { res->file_name = (ut8*) strdup ((const char*) dbg_data + nb10sz); } -static int get_debug_info(struct PE_(r_bin_pe_obj_t)* bin, PE_(image_debug_directory_entry)* dbg_dir_entry, ut8* dbg_data, int dbg_data_len, SDebugInfo* res) { +static int get_debug_info(struct PE_(rz_bin_pe_obj_t)* bin, PE_(image_debug_directory_entry)* dbg_dir_entry, ut8* dbg_data, int dbg_data_len, SDebugInfo* res) { #define SIZEOF_FILE_NAME 255 int i = 0; const char* dbgname; @@ -3367,7 +3367,7 @@ static int get_debug_info(struct PE_(r_bin_pe_obj_t)* bin, PE_(image_debug_direc return 1; } -int PE_(r_bin_pe_get_debug_data)(struct PE_(r_bin_pe_obj_t)* bin, SDebugInfo* res) { +int PE_(rz_bin_pe_get_debug_data)(struct PE_(rz_bin_pe_obj_t)* bin, SDebugInfo* res) { PE_(image_debug_directory_entry) img_dbg_dir_entry; PE_(image_data_directory) * dbg_dir; PE_DWord dbg_dir_offset; @@ -3381,29 +3381,29 @@ int PE_(r_bin_pe_get_debug_data)(struct PE_(r_bin_pe_obj_t)* bin, SDebugInfo* re if ((int) dbg_dir_offset < 0 || dbg_dir_offset >= bin->size) { return false; } - if (dbg_dir_offset >= r_buf_size (bin->b)) { + if (dbg_dir_offset >= rz_buf_size (bin->b)) { return false; } - r_buf_read_at (bin->b, dbg_dir_offset, (ut8 *)&img_dbg_dir_entry, sizeof (img_dbg_dir_entry)); - if ((r_buf_size (bin->b) - dbg_dir_offset) < sizeof (PE_(image_debug_directory_entry))) { + rz_buf_read_at (bin->b, dbg_dir_offset, (ut8 *)&img_dbg_dir_entry, sizeof (img_dbg_dir_entry)); + if ((rz_buf_size (bin->b) - dbg_dir_offset) < sizeof (PE_(image_debug_directory_entry))) { return false; } - ut32 dbg_data_poff = R_MIN (img_dbg_dir_entry.PointerToRawData, r_buf_size (bin->b)); - int dbg_data_len = R_MIN (img_dbg_dir_entry.SizeOfData, r_buf_size (bin->b) - dbg_data_poff); + ut32 dbg_data_poff = R_MIN (img_dbg_dir_entry.PointerToRawData, rz_buf_size (bin->b)); + int dbg_data_len = R_MIN (img_dbg_dir_entry.SizeOfData, rz_buf_size (bin->b) - dbg_data_poff); if (dbg_data_len < 1) { return false; } dbg_data = (ut8*) calloc (1, dbg_data_len + 1); if (dbg_data) { - r_buf_read_at (bin->b, dbg_data_poff, dbg_data, dbg_data_len); + rz_buf_read_at (bin->b, dbg_data_poff, dbg_data, dbg_data_len); result = get_debug_info (bin, &img_dbg_dir_entry, dbg_data, dbg_data_len, res); R_FREE (dbg_data); } return result; } -struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* bin) { - struct r_bin_pe_import_t* imps, * imports = NULL; +struct rz_bin_pe_import_t* PE_(rz_bin_pe_get_imports)(struct PE_(rz_bin_pe_obj_t)* bin) { + struct rz_bin_pe_import_t* imps, * imports = NULL; char dll_name[PE_NAME_LENGTH + 1]; int nimp = 0; ut64 off; //used to cache value @@ -3430,7 +3430,7 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* if (off + sizeof(PE_(image_import_directory)) > bin->size) { return NULL; } - int r = r_buf_read_at (bin->b, bin->import_directory_offset + idi * sizeof (curr_import_dir), + int r = rz_buf_read_at (bin->b, bin->import_directory_offset + idi * sizeof (curr_import_dir), (ut8 *)&curr_import_dir, sizeof (curr_import_dir)); if (r < 0) { return NULL; @@ -3456,13 +3456,13 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* goto beach; } if (paddr + PE_NAME_LENGTH > bin->size) { - rr = r_buf_read_at (bin->b, paddr, (ut8*) dll_name, bin->size - paddr); + rr = rz_buf_read_at (bin->b, paddr, (ut8*) dll_name, bin->size - paddr); if (rr != bin->size - paddr) { goto beach; } dll_name[bin->size - paddr] = '\0'; }else { - rr = r_buf_read_at (bin->b, paddr, (ut8*) dll_name, PE_NAME_LENGTH); + rr = rz_buf_read_at (bin->b, paddr, (ut8*) dll_name, PE_NAME_LENGTH); if (rr != PE_NAME_LENGTH) { goto beach; } @@ -3474,7 +3474,7 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* break; } idi++; - r = r_buf_read_at (bin->b, bin->import_directory_offset + idi * sizeof (curr_import_dir), + r = rz_buf_read_at (bin->b, bin->import_directory_offset + idi * sizeof (curr_import_dir), (ut8 *)&curr_import_dir, sizeof (curr_import_dir)); if (r < 0) { free (imports); @@ -3488,16 +3488,16 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* if (off + sizeof(PE_(image_delay_import_directory)) > bin->size) { goto beach; } - int r = r_buf_read_at (bin->b, off + didi * sizeof (curr_delay_import_dir), + int r = rz_buf_read_at (bin->b, off + didi * sizeof (curr_delay_import_dir), (ut8 *)&curr_delay_import_dir, sizeof (curr_delay_import_dir)); if (r != sizeof (curr_delay_import_dir)) { goto beach; } if (!curr_delay_import_dir.Attributes) { dll_name_offset = bin_pe_rva_to_paddr (bin, - curr_delay_import_dir.Name - PE_(r_bin_pe_get_image_base)(bin)); + curr_delay_import_dir.Name - PE_(rz_bin_pe_get_image_base)(bin)); import_func_name_offset = curr_delay_import_dir.DelayImportNameTable - - PE_(r_bin_pe_get_image_base)(bin); + PE_(rz_bin_pe_get_image_base)(bin); } else { dll_name_offset = bin_pe_rva_to_paddr (bin, curr_delay_import_dir.Name); import_func_name_offset = curr_delay_import_dir.DelayImportNameTable; @@ -3506,7 +3506,7 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* if (dll_name_offset > bin->size || dll_name_offset + PE_NAME_LENGTH > bin->size) { goto beach; } - int rr = r_buf_read_at (bin->b, dll_name_offset, (ut8*) dll_name, PE_NAME_LENGTH); + int rr = rz_buf_read_at (bin->b, dll_name_offset, (ut8*) dll_name, PE_NAME_LENGTH); if (rr < 5) { goto beach; } @@ -3517,7 +3517,7 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* break; } didi++; - r = r_buf_read_at (bin->b, off + didi * sizeof (curr_delay_import_dir), + r = rz_buf_read_at (bin->b, off + didi * sizeof (curr_delay_import_dir), (ut8 *)&curr_delay_import_dir, sizeof (curr_delay_import_dir)); if (r != sizeof (curr_delay_import_dir)) { goto beach; @@ -3526,9 +3526,9 @@ struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t)* } beach: if (nimp) { - imps = realloc (imports, (nimp + 1) * sizeof(struct r_bin_pe_import_t)); + imps = realloc (imports, (nimp + 1) * sizeof(struct rz_bin_pe_import_t)); if (!imps) { - r_sys_perror ("realloc (import)"); + rz_sys_perror ("realloc (import)"); free (imports); return NULL; } @@ -3538,12 +3538,12 @@ beach: return imports; } -struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { +struct rz_bin_pe_lib_t* PE_(rz_bin_pe_get_libs)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin) { return NULL; } - struct r_bin_pe_lib_t* libs = NULL; - struct r_bin_pe_lib_t* new_libs = NULL; + struct rz_bin_pe_lib_t* libs = NULL; + struct rz_bin_pe_lib_t* new_libs = NULL; PE_(image_import_directory) curr_import_dir; PE_(image_delay_import_directory) curr_delay_import_dir; PE_DWord name_off = 0; @@ -3552,9 +3552,9 @@ struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { int index = 0; int len = 0; int max_libs = 20; - libs = calloc (max_libs + 1, sizeof(struct r_bin_pe_lib_t)); + libs = calloc (max_libs + 1, sizeof(struct rz_bin_pe_lib_t)); if (!libs) { - r_sys_perror ("malloc (libs)"); + rz_sys_perror ("malloc (libs)"); return NULL; } @@ -3571,7 +3571,7 @@ struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { if (off + sizeof (PE_(image_import_directory)) > bin->size) { goto out_error; } - int r = r_buf_read_at (bin->b, off + iidi * sizeof (curr_import_dir), + int r = rz_buf_read_at (bin->b, off + iidi * sizeof (curr_import_dir), (ut8 *)&curr_import_dir, sizeof (curr_import_dir)); last = off + bin->import_directory_size; while (r == sizeof (curr_import_dir) && off + (iidi + 1) * sizeof (curr_import_dir) <= last && ( @@ -3579,7 +3579,7 @@ struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { curr_import_dir.TimeDateStamp || curr_import_dir.Characteristics || curr_import_dir.ForwarderChain)) { name_off = bin_pe_rva_to_paddr (bin, curr_import_dir.Name); - len = r_buf_read_at (bin->b, name_off, (ut8*) libs[index].name, PE_STRING_LENGTH); + len = rz_buf_read_at (bin->b, name_off, (ut8*) libs[index].name, PE_STRING_LENGTH); if (!libs[index].name[0]) { // minimum string length goto next; } @@ -3588,14 +3588,14 @@ struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { break; } libs[index].name[len - 1] = '\0'; - r_str_case (libs[index].name, 0); + rz_str_case (libs[index].name, 0); if (!sdb_ht_find (lib_map, libs[index].name, NULL)) { sdb_ht_insert (lib_map, libs[index].name, "a"); libs[index++].last = 0; if (index >= max_libs) { - new_libs = realloc (libs, (max_libs * 2) * sizeof (struct r_bin_pe_lib_t)); + new_libs = realloc (libs, (max_libs * 2) * sizeof (struct rz_bin_pe_lib_t)); if (!new_libs) { - r_sys_perror ("realloc (libs)"); + rz_sys_perror ("realloc (libs)"); goto out_error; } libs = new_libs; @@ -3605,7 +3605,7 @@ struct r_bin_pe_lib_t* PE_(r_bin_pe_get_libs)(struct PE_(r_bin_pe_obj_t)* bin) { } next: iidi++; - r = r_buf_read_at (bin->b, off + iidi * sizeof (curr_import_dir), + r = rz_buf_read_at (bin->b, off + iidi * sizeof (curr_import_dir), (ut8 *)&curr_import_dir, sizeof (curr_import_dir)); } } @@ -3615,7 +3615,7 @@ next: if (off + sizeof(PE_(image_delay_import_directory)) > bin->size) { goto out_error; } - int r = r_buf_read_at (bin->b, off, (ut8 *)&curr_delay_import_dir, sizeof (curr_delay_import_dir)); + int r = rz_buf_read_at (bin->b, off, (ut8 *)&curr_delay_import_dir, sizeof (curr_delay_import_dir)); if (r != sizeof (curr_delay_import_dir)) { goto out_error; } @@ -3625,20 +3625,20 @@ next: if (name_off > bin->size || name_off + PE_STRING_LENGTH > bin->size) { goto out_error; } - len = r_buf_read_at (bin->b, name_off, (ut8*) libs[index].name, PE_STRING_LENGTH); + len = rz_buf_read_at (bin->b, name_off, (ut8*) libs[index].name, PE_STRING_LENGTH); if (len != PE_STRING_LENGTH) { bprintf ("Warning: read (libs - delay import dirs)\n"); break; } libs[index].name[len - 1] = '\0'; - r_str_case (libs[index].name, 0); + rz_str_case (libs[index].name, 0); if (!sdb_ht_find (lib_map, libs[index].name, NULL)) { sdb_ht_insert (lib_map, libs[index].name, "a"); libs[index++].last = 0; if (index >= max_libs) { - new_libs = realloc (libs, (max_libs * 2) * sizeof (struct r_bin_pe_lib_t)); + new_libs = realloc (libs, (max_libs * 2) * sizeof (struct rz_bin_pe_lib_t)); if (!new_libs) { - r_sys_perror ("realloc (libs)"); + rz_sys_perror ("realloc (libs)"); goto out_error; } libs = new_libs; @@ -3647,7 +3647,7 @@ next: } } did++; - r = r_buf_read_at (bin->b, off + did * sizeof (curr_delay_import_dir), + r = rz_buf_read_at (bin->b, off + did * sizeof (curr_delay_import_dir), (ut8 *)&curr_delay_import_dir, sizeof (curr_delay_import_dir)); } } @@ -3660,12 +3660,12 @@ out_error: return NULL; } -int PE_(r_bin_pe_get_image_size)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_get_image_size)(struct PE_(rz_bin_pe_obj_t)* bin) { return bin->nt_headers->optional_header.SizeOfImage; } // TODO: make it const! like in elf -char* PE_(r_bin_pe_get_machine)(struct PE_(r_bin_pe_obj_t)* bin) { +char* PE_(rz_bin_pe_get_machine)(struct PE_(rz_bin_pe_obj_t)* bin) { char* machine = NULL; if (bin && bin->nt_headers) { @@ -3705,7 +3705,7 @@ char* PE_(r_bin_pe_get_machine)(struct PE_(r_bin_pe_obj_t)* bin) { } // TODO: make it const! like in elf -char* PE_(r_bin_pe_get_os)(struct PE_(r_bin_pe_obj_t)* bin) { +char* PE_(rz_bin_pe_get_os)(struct PE_(rz_bin_pe_obj_t)* bin) { char* os; if (!bin || !bin->nt_headers) { return NULL; @@ -3739,7 +3739,7 @@ char* PE_(r_bin_pe_get_os)(struct PE_(r_bin_pe_obj_t)* bin) { } // TODO: make it const -char* PE_(r_bin_pe_get_class)(struct PE_(r_bin_pe_obj_t)* bin) { +char* PE_(rz_bin_pe_get_class)(struct PE_(rz_bin_pe_obj_t)* bin) { if (bin && bin->nt_headers) { switch (bin->nt_headers->optional_header.Magic) { case PE_IMAGE_FILE_TYPE_PE32: return strdup ("PE32"); @@ -3750,7 +3750,7 @@ char* PE_(r_bin_pe_get_class)(struct PE_(r_bin_pe_obj_t)* bin) { return NULL; } -int PE_(r_bin_pe_get_bits)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_get_bits)(struct PE_(rz_bin_pe_obj_t)* bin) { int bits = 32; if (bin && bin->nt_headers) { if (is_arm (bin)) { @@ -3768,7 +3768,7 @@ int PE_(r_bin_pe_get_bits)(struct PE_(r_bin_pe_obj_t)* bin) { return bits; } -char *PE_(r_bin_pe_get_cc)(struct PE_(r_bin_pe_obj_t)* bin) { +char *PE_(rz_bin_pe_get_cc)(struct PE_(rz_bin_pe_obj_t)* bin) { if (bin && bin->nt_headers) { if (is_arm (bin)) { if (is_thumb (bin)) { @@ -3790,11 +3790,11 @@ char *PE_(r_bin_pe_get_cc)(struct PE_(r_bin_pe_obj_t)* bin) { //This function try to detect anomalies within section //we check if there is a section mapped at entrypoint, otherwise add it up -void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_pe_section_t* * sects) { +void PE_(rz_bin_pe_check_sections)(struct PE_(rz_bin_pe_obj_t)* bin, struct rz_bin_pe_section_t* * sects) { int i = 0; - struct r_bin_pe_section_t* sections = *sects; + struct rz_bin_pe_section_t* sections = *sects; ut64 addr_beg, addr_end, new_section_size, new_perm, base_addr; - struct r_bin_pe_addr_t* entry = PE_(r_bin_pe_get_entrypoint) (bin); + struct rz_bin_pe_addr_t* entry = PE_(rz_bin_pe_get_entrypoint) (bin); if (!entry) { return; @@ -3802,7 +3802,7 @@ void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_ new_section_size = bin->size; new_section_size -= entry->paddr > bin->size? 0: entry->paddr; new_perm = (PE_IMAGE_SCN_MEM_READ | PE_IMAGE_SCN_MEM_WRITE | PE_IMAGE_SCN_MEM_EXECUTE); - base_addr = PE_(r_bin_pe_get_image_base) (bin); + base_addr = PE_(rz_bin_pe_get_image_base) (bin); for (i = 0; !sections[i].last; i++) { //strcmp against .text doesn't work in somes cases @@ -3874,7 +3874,7 @@ void PE_(r_bin_pe_check_sections)(struct PE_(r_bin_pe_obj_t)* bin, struct r_bin_ } } //we need to create another section in order to load the entrypoint - void *ss = realloc (sections, (bin->num_sections + 2) * sizeof(struct r_bin_pe_section_t)); + void *ss = realloc (sections, (bin->num_sections + 2) * sizeof(struct rz_bin_pe_section_t)); if (!ss) { goto out_function; } @@ -3894,8 +3894,8 @@ out_function: } -static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe_obj_t)* bin) { - struct r_bin_pe_section_t* sections = NULL; +static struct rz_bin_pe_section_t* PE_(rz_bin_pe_get_sections)(struct PE_(rz_bin_pe_obj_t)* bin) { + struct rz_bin_pe_section_t* sections = NULL; PE_(image_section_header) * shdr; int i, j, section_count = 0; @@ -3909,9 +3909,9 @@ static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe section_count++; } } - sections = calloc (section_count + 1, sizeof(struct r_bin_pe_section_t)); + sections = calloc (section_count + 1, sizeof(struct rz_bin_pe_section_t)); if (!sections) { - r_sys_perror ("malloc (sections)"); + rz_sys_perror ("malloc (sections)"); return NULL; } for (i = 0, j = 0; i < bin->num_sections; i++) { @@ -3919,7 +3919,7 @@ static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe continue; } if (shdr[i].Name[0] == '\0') { - char* new_name = r_str_newf ("sect_%d", j); + char* new_name = rz_str_newf ("sect_%d", j); strncpy ((char*) sections[j].name, new_name, R_ARRAY_SIZE (sections[j].name) - 1); free (new_name); } else if (shdr[i].Name[0] == '/') { @@ -3933,7 +3933,7 @@ static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe sym_tbl_off + off + idx > off) { int sz = PE_IMAGE_SIZEOF_SHORT_NAME * 3; char* buf[64] = {0}; - if (r_buf_read_at (bin->b, + if (rz_buf_read_at (bin->b, sym_tbl_off + off + idx, (ut8*)buf, 64)) { memcpy (sections[j].name, buf, sz); @@ -3983,7 +3983,7 @@ static struct r_bin_pe_section_t* PE_(r_bin_pe_get_sections)(struct PE_(r_bin_pe return sections; } -char* PE_(r_bin_pe_get_subsystem)(struct PE_(r_bin_pe_obj_t)* bin) { +char* PE_(rz_bin_pe_get_subsystem)(struct PE_(rz_bin_pe_obj_t)* bin) { char* subsystem = NULL; if (bin && bin->nt_headers) { switch (bin->nt_headers->optional_header.Subsystem) { @@ -4016,14 +4016,14 @@ char* PE_(r_bin_pe_get_subsystem)(struct PE_(r_bin_pe_obj_t)* bin) { #define HASCHR(x) (bin->nt_headers->file_header.Characteristics & (x)) -int PE_(r_bin_pe_is_dll)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_dll)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } return HASCHR (PE_IMAGE_FILE_DLL); } -int PE_(r_bin_pe_is_pie)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_pie)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } @@ -4035,7 +4035,7 @@ int PE_(r_bin_pe_is_pie)(struct PE_(r_bin_pe_obj_t)* bin) { #endif } -int PE_(r_bin_pe_is_big_endian)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_big_endian)(struct PE_(rz_bin_pe_obj_t)* bin) { ut16 arch; if (!bin || !bin->nt_headers) { return false; @@ -4048,35 +4048,35 @@ int PE_(r_bin_pe_is_big_endian)(struct PE_(r_bin_pe_obj_t)* bin) { return HASCHR (PE_IMAGE_FILE_BYTES_REVERSED_HI); } -int PE_(r_bin_pe_is_stripped_relocs)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_stripped_relocs)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } return HASCHR (PE_IMAGE_FILE_RELOCS_STRIPPED); } -int PE_(r_bin_pe_is_stripped_line_nums)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_stripped_line_nums)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } return HASCHR (PE_IMAGE_FILE_LINE_NUMS_STRIPPED); } -int PE_(r_bin_pe_is_stripped_local_syms)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_stripped_local_syms)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } return HASCHR (PE_IMAGE_FILE_LOCAL_SYMS_STRIPPED); } -int PE_(r_bin_pe_is_stripped_debug)(struct PE_(r_bin_pe_obj_t)* bin) { +int PE_(rz_bin_pe_is_stripped_debug)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin || !bin->nt_headers) { return false; } return HASCHR (PE_IMAGE_FILE_DEBUG_STRIPPED); } -void* PE_(r_bin_pe_free)(struct PE_(r_bin_pe_obj_t)* bin) { +void* PE_(rz_bin_pe_free)(struct PE_(rz_bin_pe_obj_t)* bin) { if (!bin) { return NULL; } @@ -4091,52 +4091,52 @@ void* PE_(r_bin_pe_free)(struct PE_(r_bin_pe_obj_t)* bin) { free (bin->tls_directory); free (bin->sections); free (bin->authentihash); - r_list_free (bin->rich_entries); - r_list_free (bin->resources); - r_pkcs7_free_cms (bin->cms); - r_pkcs7_free_spcinfo (bin->spcinfo); - r_buf_free (bin->b); + rz_list_free (bin->rich_entries); + rz_list_free (bin->resources); + rz_pkcs7_free_cms (bin->cms); + rz_pkcs7_free_spcinfo (bin->spcinfo); + rz_buf_free (bin->b); bin->b = NULL; free (bin); return NULL; } -struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new)(const char* file, bool verbose) { - struct PE_(r_bin_pe_obj_t)* bin = R_NEW0 (struct PE_(r_bin_pe_obj_t)); +struct PE_(rz_bin_pe_obj_t)* PE_(rz_bin_pe_new)(const char* file, bool verbose) { + struct PE_(rz_bin_pe_obj_t)* bin = R_NEW0 (struct PE_(rz_bin_pe_obj_t)); if (!bin) { return NULL; } bin->file = file; size_t binsz; - ut8 *buf = (ut8*)r_file_slurp (file, &binsz); + ut8 *buf = (ut8*)rz_file_slurp (file, &binsz); bin->size = binsz; if (!buf) { - return PE_(r_bin_pe_free)(bin); + return PE_(rz_bin_pe_free)(bin); } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { free (buf); - return PE_(r_bin_pe_free)(bin); + return PE_(rz_bin_pe_free)(bin); } bin->verbose = verbose; free (buf); if (!bin_pe_init (bin)) { - return PE_(r_bin_pe_free)(bin); + return PE_(rz_bin_pe_free)(bin); } return bin; } -struct PE_(r_bin_pe_obj_t)* PE_(r_bin_pe_new_buf)(RBuffer *buf, bool verbose) { - struct PE_(r_bin_pe_obj_t)* bin = R_NEW0 (struct PE_(r_bin_pe_obj_t)); +struct PE_(rz_bin_pe_obj_t)* PE_(rz_bin_pe_new_buf)(RBuffer *buf, bool verbose) { + struct PE_(rz_bin_pe_obj_t)* bin = R_NEW0 (struct PE_(rz_bin_pe_obj_t)); if (!bin) { return NULL; } bin->kv = sdb_new0 (); - bin->b = r_buf_ref (buf); + bin->b = rz_buf_ref (buf); bin->verbose = verbose; - bin->size = r_buf_size (buf); + bin->size = rz_buf_size (buf); if (!bin_pe_init (bin)) { - return PE_(r_bin_pe_free)(bin); + return PE_(rz_bin_pe_free)(bin); } return bin; } diff --git a/librz/bin/format/pe/pe.h b/librz/bin/format/pe/pe.h new file mode 100644 index 0000000000..96f647e9a2 --- /dev/null +++ b/librz/bin/format/pe/pe.h @@ -0,0 +1,174 @@ +/* radare - LGPL - Copyright 2008 nibble<.ds@gmail.com> */ + +#include +#include +#include +#include + +#include "pe_specs.h" + +#ifndef _INCLUDE_R_BIN_PE_H_ +#define _INCLUDE_R_BIN_PE_H_ + +#define R_BIN_PE_SCN_IS_SHAREABLE(x) x & PE_IMAGE_SCN_MEM_SHARED +#define R_BIN_PE_SCN_IS_EXECUTABLE(x) x & PE_IMAGE_SCN_MEM_EXECUTE +#define R_BIN_PE_SCN_IS_READABLE(x) x & PE_IMAGE_SCN_MEM_READ +#define R_BIN_PE_SCN_IS_WRITABLE(x) x & PE_IMAGE_SCN_MEM_WRITE + +struct rz_bin_pe_addr_t { + ut64 vaddr; + ut64 paddr; + ut64 haddr; +}; + +struct rz_bin_pe_section_t { + ut8 name[PE_IMAGE_SIZEOF_SHORT_NAME * 3]; + ut64 size; + ut64 vsize; + ut64 vaddr; + ut64 paddr; + ut64 perm; + int last; +}; + +struct rz_bin_pe_import_t { + ut8 name[PE_NAME_LENGTH + 1]; + ut8 libname[PE_NAME_LENGTH + 1]; + ut64 vaddr; + ut64 paddr; + ut64 hint; + ut64 ordinal; + int last; +}; + +struct rz_bin_pe_export_t { + ut8 name[PE_NAME_LENGTH + 1]; + ut8 libname[PE_NAME_LENGTH + 1]; + ut8 forwarder[PE_NAME_LENGTH + 1]; + ut64 vaddr; + ut64 paddr; + ut64 ordinal; + int last; +}; + +struct rz_bin_pe_string_t { + char string[PE_STRING_LENGTH]; + ut64 vaddr; + ut64 paddr; + ut64 size; + char type; + int last; +}; + +struct rz_bin_pe_lib_t { + char name[PE_STRING_LENGTH]; + int last; +}; + + +typedef struct _PE_RESOURCE { + char *timestr; + char *type; + char *language; + char *name; + Pe_image_resource_data_entry *data; +} rz_pe_resource; + +#define GUIDSTR_LEN 41 +#define DBG_FILE_NAME_LEN 255 + +typedef struct SDebugInfo { + char guidstr[GUIDSTR_LEN]; + char file_name[DBG_FILE_NAME_LEN]; +} SDebugInfo; + +#endif + +struct PE_(rz_bin_pe_obj_t) { + // these pointers contain a copy of the headers and sections! + PE_(image_dos_header) * dos_header; + PE_(image_nt_headers) * nt_headers; + PE_(image_optional_header) * optional_header; //not free this just pointer into nt_headers + PE_(image_data_directory) * data_directory; //not free this just pointer into nt_headers + PE_(image_section_header) * section_header; + PE_(image_export_directory) * export_directory; + PE_(image_import_directory) * import_directory; + PE_(image_tls_directory) * tls_directory; + Pe_image_resource_directory* resource_directory; + PE_(image_delay_import_directory) * delay_import_directory; + Pe_image_security_directory * security_directory; + + // these pointers pertain to the .net relevant sections + PE_(image_clr_header) * clr_hdr; + PE_(image_metadata_header) * metadata_header; + PE_(image_metadata_stream) * *streams; + + /* store the section information for future use */ + struct rz_bin_pe_section_t *sections; + + // these values define the real offset into the untouched binary + ut64 rich_header_offset; + ut64 nt_header_offset; + ut64 section_header_offset; + ut64 import_directory_offset; + ut64 export_directory_offset; + ut64 resource_directory_offset; + ut64 delay_import_directory_offset; + + int import_directory_size; + int size; + int num_sections; + int endian; + bool verbose; + int big_endian; + RzList* rich_entries; + RzList* relocs; + RzList* resources; //RzList of rz_pe_resources + const char* file; + RBuffer* b; + Sdb *kv; + RCMS* cms; + SpcIndirectDataContent *spcinfo; + char *authentihash; + bool is_authhash_valid; + bool is_signed; +}; + +void PE_(rz_bin_store_all_resource_version_info)(struct PE_(rz_bin_pe_obj_t)* bin); +char* PE_(rz_bin_pe_get_arch)(struct PE_(rz_bin_pe_obj_t)* bin); +char *PE_(rz_bin_pe_get_cc)(struct PE_(rz_bin_pe_obj_t)* bin); +struct rz_bin_pe_addr_t* PE_(rz_bin_pe_get_entrypoint)(struct PE_(rz_bin_pe_obj_t)* bin); +struct rz_bin_pe_addr_t* PE_(rz_bin_pe_get_main_vaddr)(struct PE_(rz_bin_pe_obj_t)* bin); +struct rz_bin_pe_export_t* PE_(rz_bin_pe_get_exports)(struct PE_(rz_bin_pe_obj_t)* bin); // TODO +int PE_(rz_bin_pe_get_file_alignment)(struct PE_(rz_bin_pe_obj_t)* bin); +ut64 PE_(rz_bin_pe_get_image_base)(struct PE_(rz_bin_pe_obj_t)* bin); +struct rz_bin_pe_import_t* PE_(rz_bin_pe_get_imports)(struct PE_(rz_bin_pe_obj_t)* bin); // TODO +struct rz_bin_pe_lib_t* PE_(rz_bin_pe_get_libs)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_get_image_size)(struct PE_(rz_bin_pe_obj_t)* bin); +char* PE_(rz_bin_pe_get_machine)(struct PE_(rz_bin_pe_obj_t)* bin); +char* PE_(rz_bin_pe_get_os)(struct PE_(rz_bin_pe_obj_t)* bin); +char* PE_(rz_bin_pe_get_class)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_get_bits)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_get_section_alignment)(struct PE_(rz_bin_pe_obj_t)* bin); +char* PE_(rz_bin_pe_get_subsystem)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_dll)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_big_endian)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_stripped_relocs)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_stripped_line_nums)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_stripped_local_syms)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(rz_bin_pe_is_stripped_debug)(struct PE_(rz_bin_pe_obj_t)* bin); +void* PE_(rz_bin_pe_free)(struct PE_(rz_bin_pe_obj_t)* bin); +struct PE_(rz_bin_pe_obj_t)* PE_(rz_bin_pe_new)(const char* file, bool verbose); +struct PE_(rz_bin_pe_obj_t)* PE_(rz_bin_pe_new_buf)(RBuffer* buf, bool verbose); +int PE_(rz_bin_pe_get_debug_data)(struct PE_(rz_bin_pe_obj_t)* bin, struct SDebugInfo* res); +int PE_(bin_pe_get_claimed_checksum)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(bin_pe_get_actual_checksum)(struct PE_(rz_bin_pe_obj_t)* bin); +const char* PE_(bin_pe_compute_authentihash)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(bin_pe_is_authhash_valid)(struct PE_(rz_bin_pe_obj_t)* bin); +int PE_(bin_pe_get_overlay)(struct PE_(rz_bin_pe_obj_t)* bin, ut64* size); +void PE_(rz_bin_pe_check_sections)(struct PE_(rz_bin_pe_obj_t)* bin, struct rz_bin_pe_section_t** sects); +struct rz_bin_pe_addr_t *PE_(check_unknow) (struct PE_(rz_bin_pe_obj_t) *bin); +struct rz_bin_pe_addr_t *PE_(check_msvcseh) (struct PE_(rz_bin_pe_obj_t) *bin); +struct rz_bin_pe_addr_t *PE_(check_mingw) (struct PE_(rz_bin_pe_obj_t) *bin); +bool PE_(rz_bin_pe_section_perms)(RBinFile *bf, const char *name, int perms); +RZ_API void PE_(bin_pe_parse_resource) (struct PE_(rz_bin_pe_obj_t) *bin); diff --git a/libr/bin/format/pe/pe64.c b/librz/bin/format/pe/pe64.c similarity index 100% rename from libr/bin/format/pe/pe64.c rename to librz/bin/format/pe/pe64.c diff --git a/libr/bin/format/pe/pe64.h b/librz/bin/format/pe/pe64.h similarity index 100% rename from libr/bin/format/pe/pe64.h rename to librz/bin/format/pe/pe64.h diff --git a/libr/bin/format/pe/pe64_write.c b/librz/bin/format/pe/pe64_write.c similarity index 100% rename from libr/bin/format/pe/pe64_write.c rename to librz/bin/format/pe/pe64_write.c diff --git a/libr/bin/format/pe/pe_specs.h b/librz/bin/format/pe/pe_specs.h similarity index 100% rename from libr/bin/format/pe/pe_specs.h rename to librz/bin/format/pe/pe_specs.h diff --git a/libr/bin/format/pe/pe_write.c b/librz/bin/format/pe/pe_write.c similarity index 71% rename from libr/bin/format/pe/pe_write.c rename to librz/bin/format/pe/pe_write.c index 40d054f2a4..500c50407c 100644 --- a/libr/bin/format/pe/pe_write.c +++ b/librz/bin/format/pe/pe_write.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2010-2019 pancake, nibble */ -#include -#include +#include +#include #include "pe.h" -// bool PE_(r_bin_pe_section_perms)(struct PE_(r_bin_pe_obj_t) *bin, const char *name, int perms) { -bool PE_(r_bin_pe_section_perms)(RBinFile *bf, const char *name, int perms) { - struct PE_(r_bin_pe_obj_t) *pe = bf->o->bin_obj; +// bool PE_(rz_bin_pe_section_perms)(struct PE_(rz_bin_pe_obj_t) *bin, const char *name, int perms) { +bool PE_(rz_bin_pe_section_perms)(RBinFile *bf, const char *name, int perms) { + struct PE_(rz_bin_pe_obj_t) *pe = bf->o->bin_obj; PE_(image_section_header) *shdr = pe->section_header; int i; @@ -44,10 +44,10 @@ bool PE_(r_bin_pe_section_perms)(RBinFile *bf, const char *name, int perms) { int patchoff = pe->section_header_offset; patchoff += i * sizeof (PE_(image_section_header)); - patchoff += r_offsetof (PE_(image_section_header), Characteristics); - r_write_le32 (&newperms_le, newperms); + patchoff += rz_offsetof (PE_(image_section_header), Characteristics); + rz_write_le32 (&newperms_le, newperms); printf ("wx %02x @ 0x%x\n", newperms_le, patchoff); - int res = r_buf_write_at (bf->buf, patchoff, (ut8*)&newperms_le, sizeof (newperms_le)); + int res = rz_buf_write_at (bf->buf, patchoff, (ut8*)&newperms_le, sizeof (newperms_le)); if (res != sizeof (newperms_le)) { return false; } diff --git a/libr/bin/format/pe/pemixed.c b/librz/bin/format/pe/pemixed.c similarity index 51% rename from libr/bin/format/pe/pemixed.c rename to librz/bin/format/pe/pemixed.c index 2c9e193ece..52e479f93f 100644 --- a/libr/bin/format/pe/pemixed.c +++ b/librz/bin/format/pe/pemixed.c @@ -5,17 +5,17 @@ static bool check_il_only(ut32 flags); -static int r_bin_pemixed_init(struct r_bin_pemixed_obj_t* bin, struct PE_(r_bin_pe_obj_t)* pe_bin) { - struct PE_(r_bin_pe_obj_t)* sub_bin_dos; - struct PE_(r_bin_pe_obj_t)* sub_bin_native; - struct PE_(r_bin_pe_obj_t)* sub_bin_net; +static int rz_bin_pemixed_init(struct rz_bin_pemixed_obj_t* bin, struct PE_(rz_bin_pe_obj_t)* pe_bin) { + struct PE_(rz_bin_pe_obj_t)* sub_bin_dos; + struct PE_(rz_bin_pe_obj_t)* sub_bin_native; + struct PE_(rz_bin_pe_obj_t)* sub_bin_net; - sub_bin_dos = r_bin_pemixed_init_dos (pe_bin); + sub_bin_dos = rz_bin_pemixed_init_dos (pe_bin); if (sub_bin_dos) { bin->sub_bin_dos = sub_bin_dos; } - sub_bin_native = r_bin_pemixed_init_native (pe_bin); + sub_bin_native = rz_bin_pemixed_init_native (pe_bin); if (sub_bin_native) { bin->sub_bin_native = sub_bin_native; } @@ -26,7 +26,7 @@ static int r_bin_pemixed_init(struct r_bin_pemixed_obj_t* bin, struct PE_(r_bin_ //carves out dos from original pe //TODO: return mz file instead pe -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_dos(struct PE_(r_bin_pe_obj_t)* pe_bin) { +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_init_dos(struct PE_(rz_bin_pe_obj_t)* pe_bin) { ut8 * tmp_buf; ut64 pe_hdr_off = pe_bin->dos_header->e_lfanew; @@ -37,14 +37,14 @@ struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_dos(struct PE_(r_bin_pe_obj_t)* p return NULL; } - if ((r_buf_read_at (pe_bin->b, 0, tmp_buf, pe_hdr_off)) == -1) { + if ((rz_buf_read_at (pe_bin->b, 0, tmp_buf, pe_hdr_off)) == -1) { eprintf ("Error reading to buffer\n"); return NULL; } - struct PE_(r_bin_pe_obj_t)* sub_bin_dos = R_NEW0 (struct PE_(r_bin_pe_obj_t)); - if (!(sub_bin_dos->b = r_buf_new_with_bytes(tmp_buf, pe_hdr_off))) { - PE_(r_bin_pe_free) (sub_bin_dos); + struct PE_(rz_bin_pe_obj_t)* sub_bin_dos = R_NEW0 (struct PE_(rz_bin_pe_obj_t)); + if (!(sub_bin_dos->b = rz_buf_new_with_bytes(tmp_buf, pe_hdr_off))) { + PE_(rz_bin_pe_free) (sub_bin_dos); return NULL; } @@ -55,11 +55,11 @@ struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_dos(struct PE_(r_bin_pe_obj_t)* p return sub_bin_dos; } -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_native(struct PE_(r_bin_pe_obj_t)* pe_bin) { +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_init_native(struct PE_(rz_bin_pe_obj_t)* pe_bin) { ut8* zero_out; - struct PE_(r_bin_pe_obj_t)* sub_bin_native = R_NEW0 (struct PE_(r_bin_pe_obj_t)); - memcpy (sub_bin_native, pe_bin, sizeof(struct PE_(r_bin_pe_obj_t))); + struct PE_(rz_bin_pe_obj_t)* sub_bin_native = R_NEW0 (struct PE_(rz_bin_pe_obj_t)); + memcpy (sub_bin_native, pe_bin, sizeof(struct PE_(rz_bin_pe_obj_t))); //copy pe_bin->b and assign to sub_bin_native @@ -67,12 +67,12 @@ struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_native(struct PE_(r_bin_pe_obj_t) // eprintf("wtf malloc\n"); // }; - // if (!(r_buf_read_at (pe_bin->b, 0, tmp_buf, b_size))) { + // if (!(rz_buf_read_at (pe_bin->b, 0, tmp_buf, b_size))) { // free (sub_bin_native); // return NULL; // } - if (!(sub_bin_native->b = r_buf_new_with_buf(pe_bin->b))) { + if (!(sub_bin_native->b = rz_buf_new_with_buf(pe_bin->b))) { free (sub_bin_native); eprintf ("failed\n"); return NULL; @@ -84,17 +84,17 @@ struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_native(struct PE_(r_bin_pe_obj_t) dotnet_offset -= sizeof (PE_(image_data_directory)) * 2; if (!(zero_out = (ut8*) calloc (2, 4 * sizeof (ut8)))) { - // can't call PE_(r_bin_pe_free) since this will free the underlying pe_bin + // can't call PE_(rz_bin_pe_free) since this will free the underlying pe_bin // object which we may need for later - // PE_(r_bin_pe_free) (sub_bin_native); - r_buf_free (sub_bin_native->b); + // PE_(rz_bin_pe_free) (sub_bin_native); + rz_buf_free (sub_bin_native->b); free (sub_bin_native); return NULL; } - if (r_buf_write_at (sub_bin_native->b, dotnet_offset, zero_out, sizeof (PE_(image_data_directory))) < -1) { + if (rz_buf_write_at (sub_bin_native->b, dotnet_offset, zero_out, sizeof (PE_(image_data_directory))) < -1) { eprintf ("Zeroing out dotnet offset failed\n"); - r_buf_free (sub_bin_native->b); + rz_buf_free (sub_bin_native->b); free (sub_bin_native); free (zero_out); return NULL; @@ -105,12 +105,12 @@ struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_native(struct PE_(r_bin_pe_obj_t) } //this method should just return the original pe file -// struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_init_net(struct PE_(r_bin_pe_obj_t)* pe_bin) { +// struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_init_net(struct PE_(rz_bin_pe_obj_t)* pe_bin) { // return pe_bin; // } //not sure if this function is nessescary -struct PE_(r_bin_pe_obj_t)* r_bin_pemixed_extract(struct r_bin_pemixed_obj_t* bin, int sub_bin) { +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_extract(struct rz_bin_pemixed_obj_t* bin, int sub_bin) { if (!bin) { return NULL; } @@ -132,57 +132,57 @@ static bool check_il_only(ut32 flag) { return flag & check_mask; } -void* r_bin_pemixed_free(struct r_bin_pemixed_obj_t* bin) { +void* rz_bin_pemixed_free(struct rz_bin_pemixed_obj_t* bin) { if (!bin) { return NULL; } //only one free is nessescary since they all point //to the same original pe struct //possible memleak here - PE_(r_bin_pe_free)(bin->sub_bin_net); + PE_(rz_bin_pe_free)(bin->sub_bin_net); if (bin->sub_bin_dos) { - r_buf_free (bin->sub_bin_dos->b); //dos is the only one with its own buf + rz_buf_free (bin->sub_bin_dos->b); //dos is the only one with its own buf } free (bin->sub_bin_dos); free (bin->sub_bin_native); - // PE_(r_bin_pe_free)(bin->sub_bin_native); - // PE_(r_bin_pe_free)(bin->sub_bin_net); - r_buf_free (bin->b); + // PE_(rz_bin_pe_free)(bin->sub_bin_native); + // PE_(rz_bin_pe_free)(bin->sub_bin_net); + rz_buf_free (bin->b); R_FREE(bin); return NULL; } -struct r_bin_pemixed_obj_t * r_bin_pemixed_from_bytes_new(const ut8* buf, ut64 size) { - struct r_bin_pemixed_obj_t* bin = R_NEW0 (struct r_bin_pemixed_obj_t); - struct PE_(r_bin_pe_obj_t)* pe_bin; +struct rz_bin_pemixed_obj_t * rz_bin_pemixed_from_bytes_new(const ut8* buf, ut64 size) { + struct rz_bin_pemixed_obj_t* bin = R_NEW0 (struct rz_bin_pemixed_obj_t); + struct PE_(rz_bin_pe_obj_t)* pe_bin; if (!bin || !buf) { - return r_bin_pemixed_free (bin); + return rz_bin_pemixed_free (bin); } - bin->b = r_buf_new_with_bytes (buf, size); + bin->b = rz_buf_new_with_bytes (buf, size); if (!bin->b) { - return r_bin_pemixed_free (bin); + return rz_bin_pemixed_free (bin); } bin->size = size; - pe_bin = PE_(r_bin_pe_new_buf) (bin->b, true); + pe_bin = PE_(rz_bin_pe_new_buf) (bin->b, true); if (!pe_bin) { - PE_(r_bin_pe_free)(pe_bin); - return r_bin_pemixed_free (bin); + PE_(rz_bin_pe_free)(pe_bin); + return rz_bin_pemixed_free (bin); } if (!pe_bin->clr_hdr) { - PE_(r_bin_pe_free) (pe_bin); - return r_bin_pemixed_free (bin); + PE_(rz_bin_pe_free) (pe_bin); + return rz_bin_pemixed_free (bin); } //check if binary only contains managed code //check implemented here cuz we need to intialize //the pe header to access the clr hdr if (check_il_only(pe_bin->clr_hdr->Flags)) { - PE_(r_bin_pe_free) (pe_bin); - return r_bin_pemixed_free (bin); + PE_(rz_bin_pe_free) (pe_bin); + return rz_bin_pemixed_free (bin); } - if (!r_bin_pemixed_init (bin, pe_bin)) { - PE_(r_bin_pe_free) (pe_bin); - return r_bin_pemixed_free (bin); + if (!rz_bin_pemixed_init (bin, pe_bin)) { + PE_(rz_bin_pe_free) (pe_bin); + return rz_bin_pemixed_free (bin); } return bin; } diff --git a/librz/bin/format/pe/pemixed.h b/librz/bin/format/pe/pemixed.h new file mode 100644 index 0000000000..01cf8e22ce --- /dev/null +++ b/librz/bin/format/pe/pemixed.h @@ -0,0 +1,29 @@ +#include +#include "pe.h" + +#define SUB_BIN_DOS 0 +#define SUB_BIN_NATIVE 1 +#define SUB_BIN_NET 2 + +#ifndef _INCLUDE_R_BIN_PEMIXED_H_ +#define _INCLUDE_R_BIN_PEMIXED_H_ + +struct rz_bin_pemixed_obj_t { + const char* file; + int size; + struct PE_(rz_bin_pe_obj_t)* sub_bin_dos; + struct PE_(rz_bin_pe_obj_t)* sub_bin_native; + struct PE_(rz_bin_pe_obj_t)* sub_bin_net; + + RBuffer* b; +}; + +// static int rz_bin_pemixed_init(struct rz_bin_pemixed_obj_t* bin, struct PE_(rz_bin_pe_obj_t)* pe_bin); +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_init_dos(struct PE_(rz_bin_pe_obj_t)* pe_bin); +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_init_native(struct PE_(rz_bin_pe_obj_t)* pe_bin); +struct PE_(rz_bin_pe_obj_t)* rz_bin_pemixed_extract(struct rz_bin_pemixed_obj_t* bin, int sub_bin); +// static bool check_il_only(ut32 flags); +void* rz_bin_pemixed_free(struct rz_bin_pemixed_obj_t* bin); +struct rz_bin_pemixed_obj_t * rz_bin_pemixed_from_bytes_new(const ut8* buf, ut64 size); + +#endif diff --git a/libr/bin/format/psxexe/psxexe.h b/librz/bin/format/psxexe/psxexe.h similarity index 95% rename from libr/bin/format/psxexe/psxexe.h rename to librz/bin/format/psxexe/psxexe.h index b7f09bc2ad..a7e0f6fe23 100644 --- a/libr/bin/format/psxexe/psxexe.h +++ b/librz/bin/format/psxexe/psxexe.h @@ -5,7 +5,7 @@ #define PSXEXE_ID_LEN 8 #define PSXEXE_TEXTSECTION_OFFSET 0x800 -#include +#include typedef struct psxexe_header { ut8 id[8]; diff --git a/libr/bin/format/pyc/marshal.c b/librz/bin/format/pyc/marshal.c similarity index 90% rename from libr/bin/format/pyc/marshal.c rename to librz/bin/format/pyc/marshal.c index 32d1d0748c..8a8199fd48 100644 --- a/libr/bin/format/pyc/marshal.c +++ b/librz/bin/format/pyc/marshal.c @@ -1,7 +1,7 @@ /* radare - LGPL3 - Copyright 2016-2020 - Matthieu (c0riolis) Tardy - l0stb1t*/ -#include -#include +#include +#include #include "marshal.h" #include "pyc_magic.h" @@ -11,10 +11,10 @@ static ut32 magic_int; static ut32 symbols_ordinal = 0; -static RList *refs = NULL; // If you don't have a good reason, do not change this. And also checkout !refs in get_code_object() +static RzList *refs = NULL; // If you don't have a good reason, do not change this. And also checkout !refs in get_code_object() /* interned_table is used to handle TYPE_INTERNED object */ -extern RList *interned_table; +extern RzList *interned_table; static pyc_object *get_object(RBuffer *buffer); static pyc_object *copy_object(pyc_object *object); @@ -22,7 +22,7 @@ static void free_object(pyc_object *object); static ut8 get_ut8(RBuffer *buffer, bool *error) { ut8 ret = 0; - int size = r_buf_read (buffer, &ret, sizeof (ret)); + int size = rz_buf_read (buffer, &ret, sizeof (ret)); if (size < sizeof (ret)) { *error = true; } @@ -32,7 +32,7 @@ static ut8 get_ut8(RBuffer *buffer, bool *error) { static ut16 get_ut16(RBuffer *buffer, bool *error) { ut16 ret = 0; - int size = r_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); + int size = rz_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); if (size != sizeof (ret)) { *error = true; } @@ -41,7 +41,7 @@ static ut16 get_ut16(RBuffer *buffer, bool *error) { static ut32 get_ut32(RBuffer *buffer, bool *error) { ut32 ret = 0; - int size = r_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); + int size = rz_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); if (size != sizeof (ret)) { *error = true; } @@ -50,7 +50,7 @@ static ut32 get_ut32(RBuffer *buffer, bool *error) { static st32 get_st32(RBuffer *buffer, bool *error) { st32 ret = 0; - int size = r_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); + int size = rz_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); if (size < sizeof (ret)) { *error = true; } @@ -59,7 +59,7 @@ static st32 get_st32(RBuffer *buffer, bool *error) { static st64 get_st64(RBuffer *buffer, bool *error) { st64 ret = 0; - int size = r_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); + int size = rz_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); if (size < sizeof (ret)) { *error = true; } @@ -68,7 +68,7 @@ static st64 get_st64(RBuffer *buffer, bool *error) { static double get_float64(RBuffer *buffer, bool *error) { double ret = 0; - int size = r_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); + int size = rz_buf_read (buffer, (ut8 *)&ret, sizeof (ret)); if (size < sizeof (ret)) { *error = true; } @@ -80,7 +80,7 @@ static ut8 *get_bytes(RBuffer *buffer, ut32 size) { if (!ret) { return NULL; } - if (r_buf_read (buffer, ret, size) < size) { + if (rz_buf_read (buffer, ret, size) < size) { free (ret); return NULL; } @@ -141,7 +141,7 @@ static pyc_object *get_int_object(RBuffer *buffer) { return NULL; } ret->type = TYPE_INT; - ret->data = r_str_newf ("%d", i); + ret->data = rz_str_newf ("%d", i); if (!ret->data) { R_FREE (ret); } @@ -163,7 +163,7 @@ static pyc_object *get_int64_object(RBuffer *buffer) { return NULL; } ret->type = TYPE_INT64; - ret->data = r_str_newf ("%lld", i); + ret->data = rz_str_newf ("%lld", i); if (!ret->data) { R_FREE (ret); } @@ -241,7 +241,7 @@ static pyc_object *get_stringref_object(RBuffer *buffer) { ut32 n = 0; n = get_st32 (buffer, &error); - if (n >= r_list_length (interned_table)) { + if (n >= rz_list_length (interned_table)) { eprintf ("bad marshal data (string ref out of range)"); return NULL; } @@ -253,7 +253,7 @@ static pyc_object *get_stringref_object(RBuffer *buffer) { return NULL; } ret->type = TYPE_STRINGREF; - ret->data = r_list_get_n (interned_table, n); + ret->data = rz_list_get_n (interned_table, n); if (!ret->data) { R_FREE (ret); } @@ -280,7 +280,7 @@ static pyc_object *get_float_object(RBuffer *buffer) { return NULL; } /* object contain string representation of the number */ - size = r_buf_read (buffer, s, n); + size = rz_buf_read (buffer, s, n); if (size != n) { R_FREE (s); R_FREE (ret); @@ -306,7 +306,7 @@ static pyc_object *get_binary_float_object(RBuffer *buffer) { return NULL; } ret->type = TYPE_FLOAT; - ret->data = r_str_newf ("%.15g", f); + ret->data = rz_str_newf ("%.15g", f); if (!ret->data) { R_FREE (ret); return NULL; @@ -340,7 +340,7 @@ static pyc_object *get_complex_object(RBuffer *buffer) { return NULL; } /* object contain string representation of the number */ - size = r_buf_read (buffer, s1, n1); + size = rz_buf_read (buffer, s1, n1); if (size != n1) { R_FREE (s1); R_FREE (ret); @@ -360,7 +360,7 @@ static pyc_object *get_complex_object(RBuffer *buffer) { return NULL; } /* object contain string representation of the number */ - size = r_buf_read (buffer, s2, n2); + size = rz_buf_read (buffer, s2, n2); if (size != n2) { R_FREE (s1); R_FREE (s2); @@ -370,7 +370,7 @@ static pyc_object *get_complex_object(RBuffer *buffer) { s2[n2] = '\0'; ret->type = TYPE_COMPLEX; - ret->data = r_str_newf ("%s+%sj", s1, s2); + ret->data = rz_str_newf ("%s+%sj", s1, s2); R_FREE (s1); R_FREE (s2); if (!ret->data) { @@ -396,7 +396,7 @@ static pyc_object *get_binary_complex_object(RBuffer *buffer) { return NULL; } ret->type = TYPE_BINARY_COMPLEX; - ret->data = r_str_newf ("%.15g+%.15gj", a, b); + ret->data = rz_str_newf ("%.15g+%.15gj", a, b); if (!ret->data) { R_FREE (ret); return NULL; @@ -473,7 +473,7 @@ static pyc_object *get_interned_object(RBuffer *buffer) { ret->type = TYPE_INTERNED; ret->data = get_bytes (buffer, n); /* add data pointer to interned table */ - r_list_append (interned_table, ret->data); + rz_list_append (interned_table, ret->data); if (!ret->data) { R_FREE (ret); } @@ -489,7 +489,7 @@ static pyc_object *get_array_object_generic(RBuffer *buffer, ut32 size) { if (!ret) { return NULL; } - ret->data = r_list_newf ((RListFree)free_object); + ret->data = rz_list_newf ((RzListFree)free_object); if (!ret->data) { free (ret); return NULL; @@ -497,13 +497,13 @@ static pyc_object *get_array_object_generic(RBuffer *buffer, ut32 size) { for (i = 0; i < size; i++) { tmp = get_object (buffer); if (!tmp) { - r_list_free (ret->data); + rz_list_free (ret->data); R_FREE (ret); return NULL; } - if (!r_list_append (ret->data, tmp)) { + if (!rz_list_append (ret->data, tmp)) { free_object (tmp); - r_list_free (ret->data); + rz_list_free (ret->data); free (ret); return NULL; } @@ -581,7 +581,7 @@ static pyc_object *get_dict_object(RBuffer *buffer) { if (!ret) { return NULL; } - ret->data = r_list_newf ((RListFree)free_object); + ret->data = rz_list_newf ((RzListFree)free_object); if (!ret->data) { R_FREE (ret); return NULL; @@ -591,8 +591,8 @@ static pyc_object *get_dict_object(RBuffer *buffer) { if (!key) { break; } - if (!r_list_append (ret->data, key)) { - r_list_free (ret->data); + if (!rz_list_append (ret->data, key)) { + rz_list_free (ret->data); R_FREE (ret); free_object (key); return NULL; @@ -601,8 +601,8 @@ static pyc_object *get_dict_object(RBuffer *buffer) { if (!val) { break; } - if (!r_list_append (ret->data, val)) { - r_list_free (ret->data); + if (!rz_list_append (ret->data, val)) { + rz_list_free (ret->data); R_FREE (ret); free_object (val); return NULL; @@ -702,10 +702,10 @@ static pyc_object *get_ref_object(RBuffer *buffer) { if (error) { return NULL; } - if (index >= r_list_length (refs)) { + if (index >= rz_list_length (refs)) { return NULL; } - obj = r_list_get_n (refs, index); + obj = rz_list_get_n (refs, index); if (!obj) { return NULL; } @@ -720,7 +720,7 @@ static void free_object(pyc_object *object) { switch (object->type) { case TYPE_SMALL_TUPLE: case TYPE_TUPLE: - r_list_free (object->data); + rz_list_free (object->data); break; case TYPE_STRING: case TYPE_TRUE: @@ -788,7 +788,7 @@ static pyc_object *copy_object(pyc_object *object) { break; case TYPE_TUPLE: case TYPE_SMALL_TUPLE: - copy->data = r_list_clone (object->data); + copy->data = rz_list_clone (object->data); break; case TYPE_INT: case TYPE_INT64: @@ -924,12 +924,12 @@ static pyc_object *get_code_object(RBuffer *buffer) { } //to help disassemble the code - cobj->start_offset = r_buf_tell (buffer) + 5; // 1 from get_object() and 4 from get_string_object() + cobj->start_offset = rz_buf_tell (buffer) + 5; // 1 from get_object() and 4 from get_string_object() if (!refs) { return ret; //return for entried part to get the root object of this file } cobj->code = get_object (buffer); - cobj->end_offset = r_buf_tell (buffer); + cobj->end_offset = rz_buf_tell (buffer); cobj->consts = get_object (buffer); cobj->names = get_object (buffer); @@ -1002,7 +1002,7 @@ static pyc_object *get_object(RBuffer *buffer) { pyc_object *ret = NULL; ut8 code = get_ut8 (buffer, &error); ut8 flag = code & FLAG_REF; - RListIter *ref_idx; + RzListIter *ref_idx; ut8 type = code & ~FLAG_REF; if (error) { @@ -1014,7 +1014,7 @@ static pyc_object *get_object(RBuffer *buffer) { if (!ret) { return NULL; } - ref_idx = r_list_append (refs, ret); + ref_idx = rz_list_append (refs, ret); if (!ref_idx) { free_object (ret); return NULL; @@ -1133,11 +1133,11 @@ static pyc_object *get_object(RBuffer *buffer) { return ret; } -static bool extract_sections_symbols(pyc_object *obj, RList *sections, RList *symbols, RList *cobjs, char *prefix) { +static bool extract_sections_symbols(pyc_object *obj, RzList *sections, RzList *symbols, RzList *cobjs, char *prefix) { pyc_code_object *cobj = NULL; RBinSection *section = NULL; RBinSymbol *symbol = NULL; - RListIter *i = NULL; + RzListIter *i = NULL; //each code object is a section if_true_return (!obj || (obj->type != TYPE_CODE_v1 && obj->type != TYPE_CODE_v0), false); @@ -1150,12 +1150,12 @@ static bool extract_sections_symbols(pyc_object *obj, RList *sections, RList *sy if_true_return (!cobj->consts, false); //add the cobj to objs list - if (!r_list_append (cobjs, cobj)) { + if (!rz_list_append (cobjs, cobj)) { goto fail; } section = R_NEW0 (RBinSection); symbol = R_NEW0 (RBinSymbol); - prefix = r_str_newf ("%s%s%s", prefix? prefix: "", + prefix = rz_str_newf ("%s%s%s", prefix? prefix: "", prefix? ".": "", (const char *)cobj->name->data); if (!prefix || !section || !symbol) { goto fail; @@ -1168,7 +1168,7 @@ static bool extract_sections_symbols(pyc_object *obj, RList *sections, RList *sy section->vaddr = cobj->start_offset; section->size = cobj->end_offset - cobj->start_offset; section->vsize = cobj->end_offset - cobj->start_offset; - if (!r_list_append (sections, section)) { + if (!rz_list_append (sections, section)) { goto fail; } // start building symbol @@ -1182,10 +1182,10 @@ static bool extract_sections_symbols(pyc_object *obj, RList *sections, RList *sy if (cobj->consts->type != TYPE_TUPLE && cobj->consts->type != TYPE_SMALL_TUPLE) { goto fail; } - if (!r_list_append (symbols, symbol)) { + if (!rz_list_append (symbols, symbol)) { goto fail; } - r_list_foreach (((RList *)(cobj->consts->data)), i, obj) + rz_list_foreach (((RzList *)(cobj->consts->data)), i, obj) extract_sections_symbols (obj, sections, symbols, cobjs, prefix); free (prefix); return true; @@ -1197,14 +1197,14 @@ fail: return false; } -bool get_sections_symbols_from_code_objects(RBuffer *buffer, RList *sections, RList *symbols, RList *cobjs, ut32 magic) { +bool get_sections_symbols_from_code_objects(RBuffer *buffer, RzList *sections, RzList *symbols, RzList *cobjs, ut32 magic) { bool ret; magic_int = magic; - refs = r_list_newf ((RListFree)free_object); + refs = rz_list_newf ((RzListFree)free_object); if (!refs) { return false; } ret = extract_sections_symbols (get_object (buffer), sections, symbols, cobjs, NULL); - r_list_free (refs); + rz_list_free (refs); return ret; } diff --git a/libr/bin/format/pyc/marshal.h b/librz/bin/format/pyc/marshal.h similarity index 89% rename from libr/bin/format/pyc/marshal.h rename to librz/bin/format/pyc/marshal.h index aa732c806c..57f24f0d17 100644 --- a/libr/bin/format/pyc/marshal.h +++ b/librz/bin/format/pyc/marshal.h @@ -3,8 +3,8 @@ #ifndef MARSHAL_H #define MARSHAL_H -#include -#include +#include +#include typedef enum { TYPE_ASCII = 'a', @@ -70,7 +70,7 @@ typedef struct { st64 end_offset; } pyc_code_object; -bool get_sections_symbols_from_code_objects(RBuffer *buffer, RList *sections, RList *symbols, RList *objs, ut32 magic); +bool get_sections_symbols_from_code_objects(RBuffer *buffer, RzList *sections, RzList *symbols, RzList *objs, ut32 magic); ut64 get_code_object_addr(RBuffer *buffer, ut32 magic); #endif diff --git a/libr/bin/format/pyc/pyc.c b/librz/bin/format/pyc/pyc.c similarity index 84% rename from libr/bin/format/pyc/pyc.c rename to librz/bin/format/pyc/pyc.c index ee3037eff2..1f535f70a8 100644 --- a/libr/bin/format/pyc/pyc.c +++ b/librz/bin/format/pyc/pyc.c @@ -3,7 +3,7 @@ #include "pyc.h" #include "marshal.h" -bool pyc_get_sections_symbols(RList *sections, RList *symbols, RList *cobjs, RBuffer *buf, ut32 magic) { +bool pyc_get_sections_symbols(RzList *sections, RzList *symbols, RzList *cobjs, RBuffer *buf, ut32 magic) { return get_sections_symbols_from_code_objects (buf, sections, symbols, cobjs, magic); } diff --git a/librz/bin/format/pyc/pyc.h b/librz/bin/format/pyc/pyc.h new file mode 100644 index 0000000000..742ac8137d --- /dev/null +++ b/librz/bin/format/pyc/pyc.h @@ -0,0 +1,16 @@ +/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */ + +#ifndef PYC_H +#define PYC_H + +#include +#include +#include +#include +#include "pyc_magic.h" +#include "marshal.h" + +bool pyc_get_sections_symbols(RzList *sections, RzList *symbols, RzList *mem, RBuffer *buf, ut32 magic); +bool pyc_is_code(ut8 b, ut32 magic); + +#endif diff --git a/libr/bin/format/pyc/pyc_magic.c b/librz/bin/format/pyc/pyc_magic.c similarity index 100% rename from libr/bin/format/pyc/pyc_magic.c rename to librz/bin/format/pyc/pyc_magic.c diff --git a/libr/bin/format/pyc/pyc_magic.h b/librz/bin/format/pyc/pyc_magic.h similarity index 94% rename from libr/bin/format/pyc/pyc_magic.h rename to librz/bin/format/pyc/pyc_magic.h index b6e04663cd..e9458b20e1 100644 --- a/libr/bin/format/pyc/pyc_magic.h +++ b/librz/bin/format/pyc/pyc_magic.h @@ -3,7 +3,7 @@ #ifndef PYC_MAGIC_H #define PYC_MAGIC_H -#include +#include struct pyc_version { ut32 magic; diff --git a/libr/bin/format/qnx/qnx.h b/librz/bin/format/qnx/qnx.h similarity index 93% rename from libr/bin/format/qnx/qnx.h rename to librz/bin/format/qnx/qnx.h index a240effa54..bdba891a1e 100644 --- a/libr/bin/format/qnx/qnx.h +++ b/librz/bin/format/qnx/qnx.h @@ -5,10 +5,10 @@ #include "qnx_specs.h" -#include -#include -#include -#include +#include +#include +#include +#include enum { LMF_HEADER_REC = 0, @@ -80,8 +80,8 @@ R_PACKED ( typedef struct { Sdb *kv; lmf_header lmfh; - RList* fixups; - RList* sections; + RzList* fixups; + RzList* sections; lmf_rw_end rwend; }) QnxObj; diff --git a/libr/bin/format/qnx/qnx_specs.h b/librz/bin/format/qnx/qnx_specs.h similarity index 100% rename from libr/bin/format/qnx/qnx_specs.h rename to librz/bin/format/qnx/qnx_specs.h diff --git a/libr/bin/format/sfc/sfc_specs.h b/librz/bin/format/sfc/sfc_specs.h similarity index 100% rename from libr/bin/format/sfc/sfc_specs.h rename to librz/bin/format/sfc/sfc_specs.h diff --git a/libr/bin/format/spc700/spc_specs.h b/librz/bin/format/spc700/spc_specs.h similarity index 100% rename from libr/bin/format/spc700/spc_specs.h rename to librz/bin/format/spc700/spc_specs.h diff --git a/libr/bin/format/te/te.c b/librz/bin/format/te/te.c similarity index 81% rename from libr/bin/format/te/te.c rename to librz/bin/format/te/te.c index 92d1a7ad31..d9a2baefc1 100644 --- a/libr/bin/format/te/te.c +++ b/librz/bin/format/te/te.c @@ -3,27 +3,27 @@ #include #include #include -#include -#include +#include +#include #include "te_specs.h" #include "te.h" -ut64 r_bin_te_get_stripped_delta(struct r_bin_te_obj_t *bin) { +ut64 rz_bin_te_get_stripped_delta(struct rz_bin_te_obj_t *bin) { if (bin && bin->header) { return bin->header->StrippedSize - sizeof (TE_image_file_header); } return 0LL; } -static int r_bin_te_init_hdr(struct r_bin_te_obj_t *bin) { +static int rz_bin_te_init_hdr(struct rz_bin_te_obj_t *bin) { if (!bin) { return false; } if (!(bin->header = malloc (sizeof(TE_image_file_header)))) { - r_sys_perror ("malloc (header)"); + rz_sys_perror ("malloc (header)"); return false; } - if (r_buf_read_at (bin->b, 0, (ut8*)bin->header, sizeof (TE_image_file_header)) == -1) { + if (rz_buf_read_at (bin->b, 0, (ut8*)bin->header, sizeof (TE_image_file_header)) == -1) { eprintf("Error: read (header)\n"); return false; } @@ -64,14 +64,14 @@ static int r_bin_te_init_hdr(struct r_bin_te_obj_t *bin) { return true; } -ut64 r_bin_te_get_main_paddr(struct r_bin_te_obj_t *bin) { - RBinAddr *entry = r_bin_te_get_entrypoint (bin); +ut64 rz_bin_te_get_main_paddr(struct rz_bin_te_obj_t *bin) { + RBinAddr *entry = rz_bin_te_get_entrypoint (bin); ut64 addr = 0LL; ut8 buf[512]; if (!bin) { return 0LL; } - if (r_buf_read_at (bin->b, entry->paddr, buf, sizeof (buf)) == -1) { + if (rz_buf_read_at (bin->b, entry->paddr, buf, sizeof (buf)) == -1) { eprintf ("Error: read (entry)\n"); } else { if (buf[367] == 0xe8) { @@ -89,7 +89,7 @@ ut64 r_bin_te_get_main_paddr(struct r_bin_te_obj_t *bin) { return addr; } -static TE_DWord r_bin_te_vaddr_to_paddr(struct r_bin_te_obj_t* bin, TE_DWord vaddr) { +static TE_DWord rz_bin_te_vaddr_to_paddr(struct rz_bin_te_obj_t* bin, TE_DWord vaddr) { TE_DWord section_base; int i, section_size; @@ -103,7 +103,7 @@ static TE_DWord r_bin_te_vaddr_to_paddr(struct r_bin_te_obj_t* bin, TE_DWord vad return 0; } -static int r_bin_te_init_sections(struct r_bin_te_obj_t* bin) { +static int rz_bin_te_init_sections(struct rz_bin_te_obj_t* bin) { int sections_size = sizeof(TE_image_section_header) * bin->header->NumberOfSections; if (sections_size > bin->size) { eprintf ("Invalid NumberOfSections value\n"); @@ -113,7 +113,7 @@ static int r_bin_te_init_sections(struct r_bin_te_obj_t* bin) { perror ("malloc (sections headers)"); return false; } - if (r_buf_read_at (bin->b, sizeof(TE_image_file_header), + if (rz_buf_read_at (bin->b, sizeof(TE_image_file_header), (ut8*)bin->section_header, sections_size) == -1) { eprintf ("Error: read (sections headers)\n"); return false; @@ -121,22 +121,22 @@ static int r_bin_te_init_sections(struct r_bin_te_obj_t* bin) { return true; } -static int r_bin_te_init(struct r_bin_te_obj_t* bin) { +static int rz_bin_te_init(struct rz_bin_te_obj_t* bin) { bin->header = NULL; bin->section_header = NULL; bin->endian = 0; - if (!r_bin_te_init_hdr (bin)) { + if (!rz_bin_te_init_hdr (bin)) { eprintf("Warning: File is not TE\n"); return false; } - if (!r_bin_te_init_sections (bin)) { + if (!rz_bin_te_init_sections (bin)) { eprintf("Warning: Cannot initialize sections\n"); return false; } return true; } -char* r_bin_te_get_arch(struct r_bin_te_obj_t* bin) { +char* rz_bin_te_get_arch(struct rz_bin_te_obj_t* bin) { char *arch; if (!bin) { return NULL; @@ -169,12 +169,12 @@ char* r_bin_te_get_arch(struct r_bin_te_obj_t* bin) { return arch; } -int r_bin_te_get_bits(struct r_bin_te_obj_t* bin) { +int rz_bin_te_get_bits(struct rz_bin_te_obj_t* bin) { return 32; // It is always 32 bit by now } -RBinAddr* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin) { +RBinAddr* rz_bin_te_get_entrypoint(struct rz_bin_te_obj_t* bin) { RBinAddr *entry = NULL; if (!bin || !bin->header) { @@ -184,15 +184,15 @@ RBinAddr* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin) { perror("malloc (entrypoint)"); return NULL; } - entry->vaddr = bin->header->AddressOfEntryPoint - r_bin_te_get_stripped_delta (bin); + entry->vaddr = bin->header->AddressOfEntryPoint - rz_bin_te_get_stripped_delta (bin); if (entry->vaddr == 0) { // in TE if EP = 0 then EP = baddr entry->vaddr = bin->header->ImageBase; } - entry->paddr = r_bin_te_vaddr_to_paddr (bin, entry->vaddr); + entry->paddr = rz_bin_te_vaddr_to_paddr (bin, entry->vaddr); return entry; } -ut64 r_bin_te_get_image_base(struct r_bin_te_obj_t* bin) +ut64 rz_bin_te_get_image_base(struct rz_bin_te_obj_t* bin) { if (bin && bin->header) { return (ut64)bin->header->ImageBase; @@ -200,7 +200,7 @@ ut64 r_bin_te_get_image_base(struct r_bin_te_obj_t* bin) return 0LL; } -char* r_bin_te_get_machine(struct r_bin_te_obj_t* bin) { +char* rz_bin_te_get_machine(struct rz_bin_te_obj_t* bin) { char *machine; if (!bin) { return NULL; @@ -296,7 +296,7 @@ char* r_bin_te_get_machine(struct r_bin_te_obj_t* bin) { return machine; } -char* r_bin_te_get_os(struct r_bin_te_obj_t* bin) { +char* rz_bin_te_get_os(struct rz_bin_te_obj_t* bin) { char *os; if (!bin) { return NULL; @@ -330,8 +330,8 @@ char* r_bin_te_get_os(struct r_bin_te_obj_t* bin) { return os; } -struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) { - struct r_bin_te_section_t *sections = NULL; +struct rz_bin_te_section_t* rz_bin_te_get_sections(struct rz_bin_te_obj_t* bin) { + struct rz_bin_te_section_t *sections = NULL; TE_image_section_header *shdr; int i, sections_count; if (!bin) { @@ -340,7 +340,7 @@ struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) { shdr = bin->section_header; sections_count = bin->header->NumberOfSections; - if (!(sections = calloc ((sections_count + 1), sizeof (struct r_bin_te_section_t)))) { + if (!(sections = calloc ((sections_count + 1), sizeof (struct rz_bin_te_section_t)))) { perror ("malloc (sections)"); return NULL; } @@ -348,10 +348,10 @@ struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) { memcpy (sections[i].name, shdr[i].Name, TE_IMAGE_SIZEOF_NAME); // not a null terminated string if len==buflen //sections[i].name[TE_IMAGE_SIZEOF_NAME] = '\0'; - sections[i].vaddr = shdr[i].VirtualAddress - r_bin_te_get_stripped_delta (bin); + sections[i].vaddr = shdr[i].VirtualAddress - rz_bin_te_get_stripped_delta (bin); sections[i].size = shdr[i].SizeOfRawData; sections[i].vsize = shdr[i].VirtualSize; - sections[i].paddr = shdr[i].PointerToRawData - r_bin_te_get_stripped_delta (bin); + sections[i].paddr = shdr[i].PointerToRawData - rz_bin_te_get_stripped_delta (bin); sections[i].flags = shdr[i].Characteristics; sections[i].last = 0; } @@ -359,7 +359,7 @@ struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) { return sections; } -char* r_bin_te_get_subsystem(struct r_bin_te_obj_t* bin) { +char* rz_bin_te_get_subsystem(struct rz_bin_te_obj_t* bin) { char *subsystem; if (!bin) { @@ -402,54 +402,54 @@ char* r_bin_te_get_subsystem(struct r_bin_te_obj_t* bin) { return subsystem; } -void* r_bin_te_free(struct r_bin_te_obj_t* bin) { +void* rz_bin_te_free(struct rz_bin_te_obj_t* bin) { if (!bin) { return NULL; } free (bin->header); free (bin->section_header); - r_buf_free (bin->b); + rz_buf_free (bin->b); free (bin); return NULL; } -struct r_bin_te_obj_t* r_bin_te_new(const char* file) { - struct r_bin_te_obj_t *bin = R_NEW0 (struct r_bin_te_obj_t); +struct rz_bin_te_obj_t* rz_bin_te_new(const char* file) { + struct rz_bin_te_obj_t *bin = R_NEW0 (struct rz_bin_te_obj_t); if (!bin) { return NULL; } bin->file = file; size_t binsz; - ut8 *buf = (ut8*)r_file_slurp (file, &binsz); + ut8 *buf = (ut8*)rz_file_slurp (file, &binsz); bin->size = binsz; if (!buf) { - return r_bin_te_free (bin); + return rz_bin_te_free (bin); } - bin->b = r_buf_new (); - if (!r_buf_set_bytes (bin->b, buf, bin->size)) { + bin->b = rz_buf_new (); + if (!rz_buf_set_bytes (bin->b, buf, bin->size)) { free (buf); - return r_bin_te_free (bin); + return rz_bin_te_free (bin); } free (buf); - if (!r_bin_te_init (bin)) { - return r_bin_te_free (bin); + if (!rz_bin_te_init (bin)) { + return rz_bin_te_free (bin); } return bin; } -struct r_bin_te_obj_t* r_bin_te_new_buf(RBuffer *buf) { - struct r_bin_te_obj_t *bin = R_NEW0 (struct r_bin_te_obj_t); +struct rz_bin_te_obj_t* rz_bin_te_new_buf(RBuffer *buf) { + struct rz_bin_te_obj_t *bin = R_NEW0 (struct rz_bin_te_obj_t); if (!bin) { return NULL; } bin->kv = sdb_new0 (); - bin->size = r_buf_size (buf); - bin->b = r_buf_new_with_buf (buf); + bin->size = rz_buf_size (buf); + bin->b = rz_buf_new_with_buf (buf); if (!bin->b) { - return r_bin_te_free (bin); + return rz_bin_te_free (bin); } - if (!r_bin_te_init (bin)) { - return r_bin_te_free (bin); + if (!rz_bin_te_init (bin)) { + return rz_bin_te_free (bin); } return bin; } diff --git a/librz/bin/format/te/te.h b/librz/bin/format/te/te.h new file mode 100644 index 0000000000..fefbb220a7 --- /dev/null +++ b/librz/bin/format/te/te.h @@ -0,0 +1,60 @@ +/* radare - LGPL - Copyright 2013 xvilka */ + +#include +#include +#include +#include +#include + +#ifndef _INCLUDE_R_BIN_TE_H_ +#define _INCLUDE_R_BIN_TE_H_ + +#define R_BIN_TE_SCN_IS_SHAREABLE(x) x & TE_IMAGE_SCN_MEM_SHARED +#define R_BIN_TE_SCN_IS_EXECUTABLE(x) x & TE_IMAGE_SCN_MEM_EXECUTE +#define R_BIN_TE_SCN_IS_READABLE(x) x & TE_IMAGE_SCN_MEM_READ +#define R_BIN_TE_SCN_IS_WRITABLE(x) x & TE_IMAGE_SCN_MEM_WRITE + +struct rz_bin_te_section_t { + ut8 name[TE_IMAGE_SIZEOF_NAME]; + ut64 size; + ut64 vsize; + ut64 vaddr; + ut64 paddr; + ut64 flags; + int last; +}; + +struct rz_bin_te_string_t { + char string[TE_STRING_LENGTH]; + ut64 vaddr; + ut64 paddr; + ut64 size; + char type; + int last; +}; + +struct rz_bin_te_obj_t { + TE_image_file_header *header; + TE_image_section_header *section_header; + int size; + int endian; + const char* file; + RBuffer* b; + Sdb *kv; +}; + +char* rz_bin_te_get_arch(struct rz_bin_te_obj_t* bin); +RBinAddr* rz_bin_te_get_entrypoint(struct rz_bin_te_obj_t* bin); +ut64 rz_bin_te_get_main_paddr(struct rz_bin_te_obj_t *bin); +ut64 rz_bin_te_get_image_base(struct rz_bin_te_obj_t* bin); +int rz_bin_te_get_image_size(struct rz_bin_te_obj_t* bin); +char* rz_bin_te_get_machine(struct rz_bin_te_obj_t* bin); +int rz_bin_te_get_bits(struct rz_bin_te_obj_t* bin); +char* rz_bin_te_get_os(struct rz_bin_te_obj_t* bin); +struct rz_bin_te_section_t* rz_bin_te_get_sections(struct rz_bin_te_obj_t* bin); +char* rz_bin_te_get_subsystem(struct rz_bin_te_obj_t* bin); +void* rz_bin_te_free(struct rz_bin_te_obj_t* bin); +struct rz_bin_te_obj_t* rz_bin_te_new(const char* file); +struct rz_bin_te_obj_t* rz_bin_te_new_buf(RBuffer *buf); + +#endif diff --git a/libr/bin/format/te/te_specs.h b/librz/bin/format/te/te_specs.h similarity index 100% rename from libr/bin/format/te/te_specs.h rename to librz/bin/format/te/te_specs.h diff --git a/libr/bin/format/vsf/vsf_specs.h b/librz/bin/format/vsf/vsf_specs.h similarity index 93% rename from libr/bin/format/vsf/vsf_specs.h rename to librz/bin/format/vsf/vsf_specs.h index 75c0847497..bdac3e1088 100644 --- a/libr/bin/format/vsf/vsf_specs.h +++ b/librz/bin/format/vsf/vsf_specs.h @@ -2,10 +2,10 @@ #ifndef VSF_SPECS_H #define VSF_SPECS_H -#include -#include -#include -#include +#include +#include +#include +#include /* Snapshot format for VICE: http://vice-emu.sourceforge.net/ */ @@ -69,7 +69,7 @@ struct vsf_c128rom { }); /* Internal structure */ -struct r_bin_vsf_obj { +struct rz_bin_vsf_obj { int machine_idx; /* 0=C64, 1=C128, ... see bin_vsf.c */ ut64 rom; /* ptr to C64/C128 rom */ ut64 mem; /* ptr to C64/C128 ram */ diff --git a/libr/bin/format/wasm/wasm.c b/librz/bin/format/wasm/wasm.c similarity index 63% rename from libr/bin/format/wasm/wasm.c rename to librz/bin/format/wasm/wasm.c index 8dc5e5f2f8..897bc57969 100644 --- a/libr/bin/format/wasm/wasm.c +++ b/librz/bin/format/wasm/wasm.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2017 - pancake, cgvwzq */ +/* rizin - LGPL - Copyright 2017 - pancake, cgvwzq */ -#include -#include -#include -#include +#include +#include +#include +#include #include "wasm.h" @@ -12,12 +12,12 @@ typedef void *(*ParseEntryFcn) (RBuffer *b, ut64 max); // RBuffer consume functions static ut32 consume_r (RBuffer *b, ut64 max, size_t *n_out, ConsumeFcn consume_fcn) { - r_return_val_if_fail (b && n_out && consume_fcn, 0); + rz_return_val_if_fail (b && n_out && consume_fcn, 0); size_t n; ut32 tmp; - ut64 cur = r_buf_tell (b); - if (max >= r_buf_size (b) || cur > max) { + ut64 cur = rz_buf_tell (b); + if (max >= rz_buf_size (b) || cur > max) { return 0; } // 16 bytes are enough to store 128bits values @@ -25,12 +25,12 @@ static ut32 consume_r (RBuffer *b, ut64 max, size_t *n_out, ConsumeFcn consume_f if (!buf) { return 0; } - r_buf_read (b, buf, 16); + rz_buf_read (b, buf, 16); if (!(n = consume_fcn (buf, buf + max + 1, &tmp))) { free (buf); return 0; } - r_buf_seek (b, cur + n, R_BUF_SET); + rz_buf_seek (b, cur + n, R_BUF_SET); *n_out = n; free (buf); return tmp; @@ -73,15 +73,15 @@ static size_t consume_u1_r (RBuffer *b, ut64 max, ut8 *out) { } static size_t consume_str_r (RBuffer *b, ut64 max, size_t sz, char *out) { - ut64 cur = r_buf_tell (b); - if (!b || max >= r_buf_size (b) || cur > max) { + ut64 cur = rz_buf_tell (b); + if (!b || max >= rz_buf_size (b) || cur > max) { return 0; } if (!(cur + sz - 1 <= max)) { return 0; } if (sz > 0) { - r_buf_read (b, (ut8 *)out, R_MIN (R_BIN_WASM_STRING_LENGTH - 1, sz)); + rz_buf_read (b, (ut8 *)out, R_MIN (R_BIN_WASM_STRING_LENGTH - 1, sz)); } else { *out = 0; } @@ -89,13 +89,13 @@ static size_t consume_str_r (RBuffer *b, ut64 max, size_t sz, char *out) { } static size_t consume_init_expr_r (RBuffer *b, ut64 max, ut8 eoc, void *out) { - if (!b || max >= r_buf_size (b) || r_buf_tell (b) > max) { + if (!b || max >= rz_buf_size (b) || rz_buf_tell (b) > max) { return 0; } size_t res = 0; - ut8 cur = r_buf_read8 (b); - while (r_buf_tell (b) <= max && cur != eoc) { - cur = r_buf_read8 (b); + ut8 cur = rz_buf_read8 (b); + while (rz_buf_tell (b) <= max && cur != eoc) { + cur = rz_buf_read8 (b); res++; } if (cur != eoc) { @@ -105,18 +105,18 @@ static size_t consume_init_expr_r (RBuffer *b, ut64 max, ut8 eoc, void *out) { } static size_t consume_locals_r (RBuffer *b, ut64 max, RBinWasmCodeEntry *out) { - ut64 cur = r_buf_tell (b); - if (!b || max >= r_buf_size (b) || cur > max) { + ut64 cur = rz_buf_tell (b); + if (!b || max >= rz_buf_size (b) || cur > max) { return 0; } ut32 count = out ? out->local_count : 0; if (count > 0) { - if (!(out->locals = R_NEWS0 (struct r_bin_wasm_local_entry_t, count))) { + if (!(out->locals = R_NEWS0 (struct rz_bin_wasm_local_entry_t, count))) { return 0; } } ut32 j = 0; - while (r_buf_tell (b) <= max && j < count) { + while (rz_buf_tell (b) <= max && j < count) { if (!(consume_u32_r (b, max, (out ? &out->locals[j].count : NULL)))) { goto beach; } @@ -134,11 +134,11 @@ beach: return 0; } -static size_t consume_limits_r (RBuffer *b, ut64 max, struct r_bin_wasm_resizable_limits_t *out) { - if (!b || max >= r_buf_size (b) || r_buf_tell (b) > max || !out) { +static size_t consume_limits_r (RBuffer *b, ut64 max, struct rz_bin_wasm_resizable_limits_t *out) { + if (!b || max >= rz_buf_size (b) || rz_buf_tell (b) > max || !out) { return 0; } - ut32 i = r_buf_tell (b); + ut32 i = rz_buf_tell (b); if (!(consume_u7_r (b, max, &out->flags))) { return 0; } @@ -148,27 +148,27 @@ static size_t consume_limits_r (RBuffer *b, ut64 max, struct r_bin_wasm_resizabl if (out->flags && (!(consume_u32_r (b, max, &out->maximum)))) { return 0; } - return (size_t)R_ABS (r_buf_tell (b) - i); + return (size_t)R_ABS (rz_buf_tell (b) - i); } // Utils -static RList *r_bin_wasm_get_sections_by_id (RList *sections, ut8 id) { +static RzList *rz_bin_wasm_get_sections_by_id (RzList *sections, ut8 id) { RBinWasmSection *sec = NULL; - RList *ret = r_list_newf (NULL); + RzList *ret = rz_list_newf (NULL); if (!ret) { return NULL; } - RListIter *iter; - r_list_foreach (sections, iter, sec) { + RzListIter *iter; + rz_list_foreach (sections, iter, sec) { if (sec->id == id) { - r_list_append (ret, sec); + rz_list_append (ret, sec); } } return ret; } #if 0 -const char *r_bin_wasm_valuetype_to_string (r_bin_wasm_value_type_t type) { +const char *rz_bin_wasm_valuetype_to_string (rz_bin_wasm_value_type_t type) { switch (type) { case R_BIN_WASM_VALUETYPE_i32: return "i32"; @@ -187,7 +187,7 @@ const char *r_bin_wasm_valuetype_to_string (r_bin_wasm_value_type_t type) { } } -static char *r_bin_wasm_type_entry_to_string(RBinWasmTypeEntry *ptr) { +static char *rz_bin_wasm_type_entry_to_string(RBinWasmTypeEntry *ptr) { if (!ptr) { return NULL; } @@ -197,28 +197,28 @@ static char *r_bin_wasm_type_entry_to_string(RBinWasmTypeEntry *ptr) { } int p; for (p = 0; p < ptr->param_count; p++) { - strcat (buf, r_bin_wasm_valuetype_to_string (ptr->param_types[p])); + strcat (buf, rz_bin_wasm_valuetype_to_string (ptr->param_types[p])); if (p < ptr->param_count - 1) { strcat (buf, ", "); } } snprintf (ptr->to_str, R_BIN_WASM_STRING_LENGTH, "(%s) -> (%s)", (ptr->param_count > 0? buf: ""), - (ptr->return_count == 1? r_bin_wasm_valuetype_to_string (ptr->return_type): "")); + (ptr->return_count == 1? rz_bin_wasm_valuetype_to_string (ptr->return_type): "")); free (buf); return ptr->to_str; } #endif // Free -static void r_bin_wasm_free_types (RBinWasmTypeEntry *ptr) { +static void rz_bin_wasm_free_types (RBinWasmTypeEntry *ptr) { if (ptr) { free (ptr->param_types); } free (ptr); } -static void r_bin_wasm_free_codes (RBinWasmCodeEntry *ptr) { +static void rz_bin_wasm_free_codes (RBinWasmCodeEntry *ptr) { if (ptr) { free (ptr->locals); } @@ -226,27 +226,27 @@ static void r_bin_wasm_free_codes (RBinWasmCodeEntry *ptr) { } // Parsing -static RList *get_entries_from_section (RBinWasmObj *bin, RBinWasmSection *sec, ParseEntryFcn parse_entry, RListFree free_entry) { - r_return_val_if_fail (sec && bin, NULL); +static RzList *get_entries_from_section (RBinWasmObj *bin, RBinWasmSection *sec, ParseEntryFcn parse_entry, RzListFree free_entry) { + rz_return_val_if_fail (sec && bin, NULL); - RList *ret = r_list_newf (free_entry); + RzList *ret = rz_list_newf (free_entry); if (!ret) { return NULL; } RBuffer *b = bin->buf; - r_buf_seek (b, sec->payload_data, R_BUF_SET); + rz_buf_seek (b, sec->payload_data, R_BUF_SET); ut32 r = 0; - ut64 max = r_buf_tell (b) + sec->payload_len - 1; - if (!(max < r_buf_size (b))) { + ut64 max = rz_buf_tell (b) + sec->payload_len - 1; + if (!(max < rz_buf_size (b))) { goto beach; } - while (r_buf_tell (b) <= max && r < sec->count) { + while (rz_buf_tell (b) <= max && r < sec->count) { void *entry = parse_entry (b, max); if (!entry) { goto beach; } - if (!r_list_append (ret, entry)) { + if (!rz_list_append (ret, entry)) { free_entry (entry); // should this jump to beach? } @@ -271,11 +271,11 @@ static void *parse_type_entry (RBuffer *b, ut64 max) { goto beach; } ut32 count = ptr ? ptr->param_count : 0; - if (!(r_buf_tell (b) + count <= max)) { + if (!(rz_buf_tell (b) + count <= max)) { goto beach; } if (count > 0) { - if (!(ptr->param_types = R_NEWS0 (r_bin_wasm_value_type_t, count))) { + if (!(ptr->param_types = R_NEWS0 (rz_bin_wasm_value_type_t, count))) { goto beach; } } @@ -299,7 +299,7 @@ static void *parse_type_entry (RBuffer *b, ut64 max) { return ptr; beach: - r_bin_wasm_free_types (ptr); + rz_bin_wasm_free_types (ptr); return NULL; } static void *parse_import_entry (RBuffer *b, ut64 max) { @@ -390,8 +390,8 @@ static void *parse_code_entry (RBuffer *b, ut64 max) { if (!(consume_u32_r (b, max, &ptr->body_size))) { goto beach; } - ut32 j = r_buf_tell (b); - if (!(r_buf_tell (b) + ptr->body_size - 1 <= max)) { + ut32 j = rz_buf_tell (b); + if (!(rz_buf_tell (b) + ptr->body_size - 1 <= max)) { goto beach; } if (!(consume_u32_r (b, max, &ptr->local_count))) { @@ -400,17 +400,17 @@ static void *parse_code_entry (RBuffer *b, ut64 max) { if (consume_locals_r (b, max, ptr) < ptr->local_count) { goto beach; } - ptr->code = r_buf_tell (b); + ptr->code = rz_buf_tell (b); ptr->len = ptr->body_size - ptr->code + j; - r_buf_seek (b, ptr->len - 1, R_BUF_CUR); // consume bytecode - r_buf_read (b, &ptr->byte, 1); + rz_buf_seek (b, ptr->len - 1, R_BUF_CUR); // consume bytecode + rz_buf_read (b, &ptr->byte, 1); if (ptr->byte != R_BIN_WASM_END_OF_CODE) { goto beach; } return ptr; beach: - r_bin_wasm_free_codes (ptr); + rz_bin_wasm_free_codes (ptr); return NULL; } @@ -428,8 +428,8 @@ static void *parse_data_entry (RBuffer *b, ut64 max) { if (!(consume_u32_r (b, max, &ptr->size))) { goto beach; } - ptr->data = r_buf_tell (b); - r_buf_seek (b, ptr->size, R_BUF_CUR); + ptr->data = rz_buf_tell (b); + rz_buf_seek (b, ptr->size, R_BUF_CUR); return ptr; beach: @@ -444,7 +444,7 @@ static bool parse_namemap (RBuffer *b, ut64 max, RIDStorage *map, ut32 *count) { } for (i = 0; i < *count; i++) { - struct r_bin_wasm_name_t *name = R_NEW0 (struct r_bin_wasm_name_t); + struct rz_bin_wasm_name_t *name = R_NEW0 (struct rz_bin_wasm_name_t); if (!name) { return false; } @@ -466,7 +466,7 @@ static bool parse_namemap (RBuffer *b, ut64 max, RIDStorage *map, ut32 *count) { } name->name[name->len] = 0; - if (!r_id_storage_add (map, name, &idx)) { + if (!rz_id_storage_add (map, name, &idx)) { R_FREE (name); return false; }; @@ -492,7 +492,7 @@ static void *parse_custom_name_entry (RBuffer *b, ut64 max) { switch (ptr->type) { case R_BIN_WASM_NAMETYPE_Module: - ptr->mod_name = R_NEW0 (struct r_bin_wasm_name_t); + ptr->mod_name = R_NEW0 (struct rz_bin_wasm_name_t); if (!ptr->mod_name) { goto beach; } @@ -512,7 +512,7 @@ static void *parse_custom_name_entry (RBuffer *b, ut64 max) { goto beach; } - ptr->func->names = r_id_storage_new (0, UT32_MAX); + ptr->func->names = rz_id_storage_new (0, UT32_MAX); if (!ptr->func->names) { goto beach; @@ -532,7 +532,7 @@ static void *parse_custom_name_entry (RBuffer *b, ut64 max) { goto beach; } - ptr->local->locals = r_list_new (); + ptr->local->locals = rz_list_new (); for (i = 0; i < ptr->local->count; i++) { RBinWasmCustomNameLocalName *local_name = R_NEW0 (RBinWasmCustomNameLocalName); @@ -543,29 +543,29 @@ static void *parse_custom_name_entry (RBuffer *b, ut64 max) { } if (!(consume_u32_r (b, max, &local_name->index))) { - r_list_free (ptr->local->locals); + rz_list_free (ptr->local->locals); free (ptr->local); free (local_name); goto beach; } - local_name->names = r_id_storage_new (0, UT32_MAX); + local_name->names = rz_id_storage_new (0, UT32_MAX); if (!local_name->names) { - r_list_free (ptr->local->locals); + rz_list_free (ptr->local->locals); free (ptr->local); free (local_name); goto beach; } if (!parse_namemap (b, max, local_name->names, &local_name->names_count)) { - r_id_storage_free (local_name->names); - r_list_free (ptr->local->locals); + rz_id_storage_free (local_name->names); + rz_list_free (ptr->local->locals); free (ptr->local); free (local_name); goto beach; } - if (!r_list_append (ptr->local->locals, local_name)) { + if (!rz_list_append (ptr->local->locals, local_name)) { free (local_name); goto beach; }; @@ -648,7 +648,7 @@ static void *parse_element_entry (RBuffer *b, ut64 max) { goto beach; } ut32 j = 0; - while (r_buf_tell (b) <= max && j < ptr->num_elem) { + while (rz_buf_tell (b) <= max && j < ptr->num_elem) { // TODO: allocate space and fill entry if (!(consume_u32_r (b, max, NULL))) { goto beach; @@ -661,27 +661,27 @@ beach: return NULL; } -static RList *r_bin_wasm_get_type_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_type_entry, (RListFree)r_bin_wasm_free_types); +static RzList *rz_bin_wasm_get_type_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_type_entry, (RzListFree)rz_bin_wasm_free_types); } -static RList *r_bin_wasm_get_import_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_import_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_import_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_import_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_export_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_export_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_export_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_export_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_code_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_code_entry, (RListFree)r_bin_wasm_free_codes); +static RzList *rz_bin_wasm_get_code_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_code_entry, (RzListFree)rz_bin_wasm_free_codes); } -static RList *r_bin_wasm_get_data_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_data_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_data_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_data_entry, (RzListFree)free); } -static RBinWasmStartEntry *r_bin_wasm_get_start (RBinWasmObj *bin, RBinWasmSection *sec) { +static RBinWasmStartEntry *rz_bin_wasm_get_start (RBinWasmObj *bin, RBinWasmSection *sec) { RBinWasmStartEntry *ptr; if (!(ptr = R_NEW0 (RBinWasmStartEntry))) { @@ -689,9 +689,9 @@ static RBinWasmStartEntry *r_bin_wasm_get_start (RBinWasmObj *bin, RBinWasmSecti } RBuffer *b = bin->buf; - r_buf_seek (b, sec->payload_data, R_BUF_SET); - ut64 max = r_buf_tell (b) + sec->payload_len - 1; - if (!(max < r_buf_size (b))) { + rz_buf_seek (b, sec->payload_data, R_BUF_SET); + ut64 max = rz_buf_tell (b) + sec->payload_len - 1; + if (!(max < rz_buf_size (b))) { goto beach; } if (!(consume_u32_r (b, max, &ptr->index))) { @@ -704,82 +704,82 @@ beach: return NULL; } -static RList *r_bin_wasm_get_memory_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_memory_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_memory_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_memory_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_table_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_table_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_table_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_table_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_global_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_global_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_global_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_global_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_element_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - return get_entries_from_section (bin, sec, parse_element_entry, (RListFree)free); +static RzList *rz_bin_wasm_get_element_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + return get_entries_from_section (bin, sec, parse_element_entry, (RzListFree)free); } -static RList *r_bin_wasm_get_custom_name_entries (RBinWasmObj *bin, RBinWasmSection *sec) { - RList *ret = r_list_new (); +static RzList *rz_bin_wasm_get_custom_name_entries (RBinWasmObj *bin, RBinWasmSection *sec) { + RzList *ret = rz_list_new (); RBuffer *buf = bin->buf; - r_buf_seek (buf, sec->payload_data, R_BUF_SET); + rz_buf_seek (buf, sec->payload_data, R_BUF_SET); ut64 max = sec->payload_data + sec->payload_len - 1; - if (max > r_buf_size (buf)) { + if (max > rz_buf_size (buf)) { goto beach; } - while (r_buf_tell (buf) < max) { + while (rz_buf_tell (buf) < max) { RBinWasmCustomNameEntry *nam = parse_custom_name_entry (buf, max); if (!nam) { goto beach; } - if (!r_list_append (ret, nam)) { + if (!rz_list_append (ret, nam)) { goto beach; } } return ret; beach: - r_list_free (ret); + rz_list_free (ret); return NULL; } // Public functions -RBinWasmObj *r_bin_wasm_init (RBinFile *bf, RBuffer *buf) { +RBinWasmObj *rz_bin_wasm_init (RBinFile *bf, RBuffer *buf) { RBinWasmObj *bin = R_NEW0 (RBinWasmObj); if (!bin) { return NULL; } - bin->buf = r_buf_ref (buf); - bin->size = (ut32)r_buf_size (bf->buf); - bin->g_sections = r_bin_wasm_get_sections (bin); + bin->buf = rz_buf_ref (buf); + bin->size = (ut32)rz_buf_size (bf->buf); + bin->g_sections = rz_bin_wasm_get_sections (bin); // TODO: recursive invocation more natural with streamed parsing // but dependency problems when sections are disordered (against spec) - bin->g_types = r_bin_wasm_get_types (bin); - bin->g_imports = r_bin_wasm_get_imports (bin); - bin->g_exports = r_bin_wasm_get_exports (bin); - bin->g_tables = r_bin_wasm_get_tables (bin); - bin->g_memories = r_bin_wasm_get_memories (bin); - bin->g_globals = r_bin_wasm_get_globals (bin); - bin->g_codes = r_bin_wasm_get_codes (bin); - bin->g_datas = r_bin_wasm_get_datas (bin); + bin->g_types = rz_bin_wasm_get_types (bin); + bin->g_imports = rz_bin_wasm_get_imports (bin); + bin->g_exports = rz_bin_wasm_get_exports (bin); + bin->g_tables = rz_bin_wasm_get_tables (bin); + bin->g_memories = rz_bin_wasm_get_memories (bin); + bin->g_globals = rz_bin_wasm_get_globals (bin); + bin->g_codes = rz_bin_wasm_get_codes (bin); + bin->g_datas = rz_bin_wasm_get_datas (bin); - bin->g_names = r_bin_wasm_get_custom_names (bin); + bin->g_names = rz_bin_wasm_get_custom_names (bin); // entrypoint from Start section - bin->entrypoint = r_bin_wasm_get_entrypoint (bin); + bin->entrypoint = rz_bin_wasm_get_entrypoint (bin); return bin; } -void r_bin_wasm_destroy (RBinFile *bf) { +void rz_bin_wasm_destroy (RBinFile *bf) { RBinWasmObj *bin; if (!bf || !bf->o || !bf->o->bin_obj) { @@ -787,22 +787,22 @@ void r_bin_wasm_destroy (RBinFile *bf) { } bin = bf->o->bin_obj; - r_buf_free (bin->buf); + rz_buf_free (bin->buf); - r_list_free (bin->g_sections); - r_list_free (bin->g_types); + rz_list_free (bin->g_sections); + rz_list_free (bin->g_types); - r_list_free (bin->g_imports); - r_list_free (bin->g_exports); - r_list_free (bin->g_tables); - r_list_free (bin->g_memories); - r_list_free (bin->g_globals); - r_list_free (bin->g_codes); - r_list_free (bin->g_datas); + rz_list_free (bin->g_imports); + rz_list_free (bin->g_exports); + rz_list_free (bin->g_tables); + rz_list_free (bin->g_memories); + rz_list_free (bin->g_globals); + rz_list_free (bin->g_codes); + rz_list_free (bin->g_datas); - RListIter *iter; + RzListIter *iter; RBinWasmCustomNameEntry *nam; - r_list_foreach (bin->g_names, iter, nam) { + rz_list_foreach (bin->g_names, iter, nam) { switch (nam->type) { case R_BIN_WASM_NAMETYPE_Module: if (nam->mod_name) { @@ -811,33 +811,33 @@ void r_bin_wasm_destroy (RBinFile *bf) { break; case R_BIN_WASM_NAMETYPE_Function: if (nam->func) { - r_id_storage_free (nam->func->names); + rz_id_storage_free (nam->func->names); } break; case R_BIN_WASM_NAMETYPE_Local: if (nam->local && nam->local->locals) { - RListIter *iter; + RzListIter *iter; RBinWasmCustomNameLocalName *local; - r_list_foreach (nam->local->locals, iter, local) { + rz_list_foreach (nam->local->locals, iter, local) { if (local->names) { - r_id_storage_free (local->names); + rz_id_storage_free (local->names); } } - r_list_free (nam->local->locals); + rz_list_free (nam->local->locals); } break; } } - r_list_free (bin->g_names); + rz_list_free (bin->g_names); free (bin->g_start); free (bin); bf->o->bin_obj = NULL; } -RList *r_bin_wasm_get_sections (RBinWasmObj *bin) { - RList *ret = NULL; +RzList *rz_bin_wasm_get_sections (RBinWasmObj *bin) { + RzList *ret = NULL; RBinWasmSection *ptr = NULL; if (!bin) { @@ -846,13 +846,13 @@ RList *r_bin_wasm_get_sections (RBinWasmObj *bin) { if (bin->g_sections) { return bin->g_sections; } - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } RBuffer *b = bin->buf; - ut64 max = r_buf_size (b) - 1; - r_buf_seek (b, 8, R_BUF_SET); - while (r_buf_tell (b) <= max) { + ut64 max = rz_buf_size (b) - 1; + rz_buf_seek (b, 8, R_BUF_SET); + while (rz_buf_tell (b) <= max) { if (!(ptr = R_NEW0 (RBinWasmSection))) { return ret; } @@ -868,11 +868,11 @@ RList *r_bin_wasm_get_sections (RBinWasmObj *bin) { // free (ptr); // continue; } - if (!(r_buf_tell (b) + (ut64)ptr->size - 1 <= max)) { + if (!(rz_buf_tell (b) + (ut64)ptr->size - 1 <= max)) { goto beach; } ptr->count = 0; - ptr->offset = r_buf_tell (b); + ptr->offset = rz_buf_tell (b); switch (ptr->id) { case R_BIN_WASM_SECTION_CUSTOM: // eprintf("custom section: 0x%x, ", (ut32)b->cur); @@ -941,7 +941,7 @@ RList *r_bin_wasm_get_sections (RBinWasmObj *bin) { break; default: eprintf ("[wasm] error: unkown section id: %d\n", ptr->id); - r_buf_seek (b, ptr->size - 1, R_BUF_CUR); + rz_buf_seek (b, ptr->size - 1, R_BUF_CUR); continue; } if (ptr->id != R_BIN_WASM_SECTION_START && ptr->id != R_BIN_WASM_SECTION_CUSTOM) { @@ -950,13 +950,13 @@ RList *r_bin_wasm_get_sections (RBinWasmObj *bin) { } // eprintf("count %d\n", ptr->count); } - ptr->payload_data = r_buf_tell (b); + ptr->payload_data = rz_buf_tell (b); ptr->payload_len = ptr->size - (ptr->payload_data - ptr->offset); if (ptr->payload_len > ptr->size) { goto beach; } - r_buf_seek (b, ptr->payload_len, R_BUF_CUR); - if (!r_list_append (ret, ptr)) { + rz_buf_seek (b, ptr->payload_len, R_BUF_CUR); + if (!rz_list_append (ret, ptr)) { free (ptr); // should it jump to beach? } @@ -970,8 +970,8 @@ beach: return ret; } -ut32 r_bin_wasm_get_entrypoint (RBinWasmObj *bin) { - RList *secs = NULL; +ut32 rz_bin_wasm_get_entrypoint (RBinWasmObj *bin) { + RzList *secs = NULL; RBinWasmStartEntry *start = NULL; RBinWasmSection *sec = NULL; RBinWasmCodeEntry *func = NULL; @@ -984,32 +984,32 @@ ut32 r_bin_wasm_get_entrypoint (RBinWasmObj *bin) { } if (bin->g_start) { start = bin->g_start; - } else if (!(secs = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_START))) { + } else if (!(secs = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_START))) { return 0; - } else if (!(sec = (RBinWasmSection *)r_list_first (secs))) { - r_list_free (secs); + } else if (!(sec = (RBinWasmSection *)rz_list_first (secs))) { + rz_list_free (secs); return 0; } else { - start = r_bin_wasm_get_start (bin, sec); + start = rz_bin_wasm_get_start (bin, sec); bin->g_start = start; } if (!start) { - r_list_free (secs); + rz_list_free (secs); return 0; } // FIX: entrypoint can be also an import if (!bin->g_codes) { - r_list_free (secs); + rz_list_free (secs); return 0; } - func = r_list_get_n (bin->g_codes, start->index); - r_list_free (secs); + func = rz_list_get_n (bin->g_codes, start->index); + rz_list_free (secs); return (ut32) (func ? func->code : 0); } -RList *r_bin_wasm_get_imports (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_imports (RBinWasmObj *bin) { RBinWasmSection *import = NULL; - RList *imports = NULL; + RzList *imports = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1017,22 +1017,22 @@ RList *r_bin_wasm_get_imports (RBinWasmObj *bin) { if (bin->g_imports) { return bin->g_imports; } - if (!(imports = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_IMPORT))) { - return r_list_new (); + if (!(imports = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_IMPORT))) { + return rz_list_new (); } // support for multiple import sections against spec - if (!(import = (RBinWasmSection *)r_list_first (imports))) { - r_list_free (imports); - return r_list_new (); + if (!(import = (RBinWasmSection *)rz_list_first (imports))) { + rz_list_free (imports); + return rz_list_new (); } - bin->g_imports = r_bin_wasm_get_import_entries (bin, import); - r_list_free (imports); + bin->g_imports = rz_bin_wasm_get_import_entries (bin, import); + rz_list_free (imports); return bin->g_imports; } -RList *r_bin_wasm_get_exports (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_exports (RBinWasmObj *bin) { RBinWasmSection *export = NULL; - RList *exports = NULL; + RzList *exports = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1040,22 +1040,22 @@ RList *r_bin_wasm_get_exports (RBinWasmObj *bin) { if (bin->g_exports) { return bin->g_exports; } - if (!(exports = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_EXPORT))) { - return r_list_new (); + if (!(exports = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_EXPORT))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(export = (RBinWasmSection *)r_list_first (exports))) { - r_list_free (exports); - return r_list_new (); + if (!(export = (RBinWasmSection *)rz_list_first (exports))) { + rz_list_free (exports); + return rz_list_new (); } - bin->g_exports = r_bin_wasm_get_export_entries (bin, export); - r_list_free (exports); + bin->g_exports = rz_bin_wasm_get_export_entries (bin, export); + rz_list_free (exports); return bin->g_exports; } -RList *r_bin_wasm_get_types (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_types (RBinWasmObj *bin) { RBinWasmSection *type = NULL; - RList *types = NULL; + RzList *types = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1063,22 +1063,22 @@ RList *r_bin_wasm_get_types (RBinWasmObj *bin) { if (bin->g_types) { return bin->g_types; } - if (!(types = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_TYPE))) { - return r_list_new (); + if (!(types = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_TYPE))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(type = (RBinWasmSection *)r_list_first (types))) { - r_list_free (types); - return r_list_new (); + if (!(type = (RBinWasmSection *)rz_list_first (types))) { + rz_list_free (types); + return rz_list_new (); } - bin->g_types = r_bin_wasm_get_type_entries (bin, type); - r_list_free (types); + bin->g_types = rz_bin_wasm_get_type_entries (bin, type); + rz_list_free (types); return bin->g_types; } -RList *r_bin_wasm_get_tables (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_tables (RBinWasmObj *bin) { RBinWasmSection *table = NULL; - RList *tables = NULL; + RzList *tables = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1086,22 +1086,22 @@ RList *r_bin_wasm_get_tables (RBinWasmObj *bin) { if (bin->g_tables) { return bin->g_tables; } - if (!(tables = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_TABLE))) { - return r_list_new (); + if (!(tables = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_TABLE))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(table = (RBinWasmSection *)r_list_first (tables))) { - r_list_free (tables); - return r_list_new (); + if (!(table = (RBinWasmSection *)rz_list_first (tables))) { + rz_list_free (tables); + return rz_list_new (); } - bin->g_tables = r_bin_wasm_get_table_entries (bin, table); - r_list_free (tables); + bin->g_tables = rz_bin_wasm_get_table_entries (bin, table); + rz_list_free (tables); return bin->g_tables; } -RList *r_bin_wasm_get_memories (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_memories (RBinWasmObj *bin) { RBinWasmSection *memory; - RList *memories; + RzList *memories; if (!bin || !bin->g_sections) { return NULL; @@ -1111,24 +1111,24 @@ RList *r_bin_wasm_get_memories (RBinWasmObj *bin) { return bin->g_memories; } - if (!(memories = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_MEMORY))) { - return r_list_new (); + if (!(memories = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_MEMORY))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(memory = (RBinWasmSection *)r_list_first (memories))) { - r_list_free (memories); - return r_list_new (); + if (!(memory = (RBinWasmSection *)rz_list_first (memories))) { + rz_list_free (memories); + return rz_list_new (); } - bin->g_memories = r_bin_wasm_get_memory_entries (bin, memory); - r_list_free (memories); + bin->g_memories = rz_bin_wasm_get_memory_entries (bin, memory); + rz_list_free (memories); return bin->g_memories; } -RList *r_bin_wasm_get_globals (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_globals (RBinWasmObj *bin) { RBinWasmSection *global = NULL; - RList *globals = NULL; + RzList *globals = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1136,22 +1136,22 @@ RList *r_bin_wasm_get_globals (RBinWasmObj *bin) { if (bin->g_globals) { return bin->g_globals; } - if (!(globals = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_GLOBAL))) { - return r_list_new (); + if (!(globals = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_GLOBAL))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(global = (RBinWasmSection *)r_list_first (globals))) { - r_list_free (globals); - return r_list_new (); + if (!(global = (RBinWasmSection *)rz_list_first (globals))) { + rz_list_free (globals); + return rz_list_new (); } - bin->g_globals = r_bin_wasm_get_global_entries (bin, global); - r_list_free (globals); + bin->g_globals = rz_bin_wasm_get_global_entries (bin, global); + rz_list_free (globals); return bin->g_globals; } -RList *r_bin_wasm_get_elements (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_elements (RBinWasmObj *bin) { RBinWasmSection *element = NULL; - RList *elements = NULL; + RzList *elements = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1159,23 +1159,23 @@ RList *r_bin_wasm_get_elements (RBinWasmObj *bin) { if (bin->g_elements) { return bin->g_elements; } - if (!(elements = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_ELEMENT))) { - return r_list_new (); + if (!(elements = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_ELEMENT))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(element = (RBinWasmSection *)r_list_first (elements))) { - r_list_free (elements); - return r_list_new (); + if (!(element = (RBinWasmSection *)rz_list_first (elements))) { + rz_list_free (elements); + return rz_list_new (); } - bin->g_elements = r_bin_wasm_get_element_entries (bin, element); - r_list_free (elements); + bin->g_elements = rz_bin_wasm_get_element_entries (bin, element); + rz_list_free (elements); return bin->g_elements; } -RList *r_bin_wasm_get_codes (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_codes (RBinWasmObj *bin) { RBinWasmSection *code = NULL; ; - RList *codes = NULL; + RzList *codes = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1183,22 +1183,22 @@ RList *r_bin_wasm_get_codes (RBinWasmObj *bin) { if (bin->g_codes) { return bin->g_codes; } - if (!(codes = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_CODE))) { - return r_list_new (); + if (!(codes = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_CODE))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(code = (RBinWasmSection *)r_list_first (codes))) { - r_list_free (codes); - return r_list_new (); + if (!(code = (RBinWasmSection *)rz_list_first (codes))) { + rz_list_free (codes); + return rz_list_new (); } - bin->g_codes = r_bin_wasm_get_code_entries (bin, code); - r_list_free (codes); + bin->g_codes = rz_bin_wasm_get_code_entries (bin, code); + rz_list_free (codes); return bin->g_codes; } -RList *r_bin_wasm_get_datas (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_datas (RBinWasmObj *bin) { RBinWasmSection *data = NULL; - RList *datas = NULL; + RzList *datas = NULL; if (!bin || !bin->g_sections) { return NULL; @@ -1206,53 +1206,53 @@ RList *r_bin_wasm_get_datas (RBinWasmObj *bin) { if (bin->g_datas) { return bin->g_datas; } - if (!(datas = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_DATA))) { - return r_list_new (); + if (!(datas = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_DATA))) { + return rz_list_new (); } // support for multiple export sections against spec - if (!(data = (RBinWasmSection *)r_list_first (datas))) { - r_list_free (datas); - return r_list_new (); + if (!(data = (RBinWasmSection *)rz_list_first (datas))) { + rz_list_free (datas); + return rz_list_new (); } - bin->g_datas = r_bin_wasm_get_data_entries (bin, data); - r_list_free (datas); + bin->g_datas = rz_bin_wasm_get_data_entries (bin, data); + rz_list_free (datas); return bin->g_datas; } -RList *r_bin_wasm_get_custom_names (RBinWasmObj *bin) { +RzList *rz_bin_wasm_get_custom_names (RBinWasmObj *bin) { RBinWasmSection *cust = NULL; - RList *customs = NULL; + RzList *customs = NULL; - r_return_val_if_fail (bin && bin->g_sections, NULL); + rz_return_val_if_fail (bin && bin->g_sections, NULL); if (bin->g_names) { return bin->g_names; } - if (!(customs = r_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_CUSTOM))) { - return r_list_new (); + if (!(customs = rz_bin_wasm_get_sections_by_id (bin->g_sections, R_BIN_WASM_SECTION_CUSTOM))) { + return rz_list_new (); } // support for multiple "name" sections against spec - if (!(cust = (RBinWasmSection *)r_list_first (customs)) || strncmp (cust->name, "name", 5)) { - r_list_free (customs); - return r_list_new (); + if (!(cust = (RBinWasmSection *)rz_list_first (customs)) || strncmp (cust->name, "name", 5)) { + rz_list_free (customs); + return rz_list_new (); } - bin->g_names = r_bin_wasm_get_custom_name_entries (bin, cust); - r_list_free (customs); + bin->g_names = rz_bin_wasm_get_custom_name_entries (bin, cust); + rz_list_free (customs); return bin->g_names; } -const char *r_bin_wasm_get_function_name (RBinWasmObj *bin, ut32 idx) { +const char *rz_bin_wasm_get_function_name (RBinWasmObj *bin, ut32 idx) { if (!(bin && bin->g_names)) { return NULL; }; - RListIter *iter; + RzListIter *iter; RBinWasmCustomNameEntry *nam; - r_list_foreach (bin->g_names, iter, nam) { + rz_list_foreach (bin->g_names, iter, nam) { if (nam->type == R_BIN_WASM_NAMETYPE_Function) { - struct r_bin_wasm_name_t *n = NULL; + struct rz_bin_wasm_name_t *n = NULL; - if ((n = r_id_storage_get (nam->func->names, idx))) { + if ((n = rz_id_storage_get (nam->func->names, idx))) { return (const char *)n->name; } } diff --git a/libr/bin/format/wasm/wasm.h b/librz/bin/format/wasm/wasm.h similarity index 52% rename from libr/bin/format/wasm/wasm.h rename to librz/bin/format/wasm/wasm.h index 9b840f7222..5cd20413e8 100644 --- a/libr/bin/format/wasm/wasm.h +++ b/librz/bin/format/wasm/wasm.h @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2017-2018 - cgvwzq */ +/* rizin - LGPL - Copyright 2017-2018 - cgvwzq */ -#include -#include -#include -#include +#include +#include +#include +#include #ifndef _INCLUDE_WASM_H_ #define _INCLUDE_WASM_H_ @@ -39,38 +39,38 @@ typedef enum { R_BIN_WASM_VALUETYPE_ANYFUNC = 0x10, R_BIN_WASM_VALUETYPE_FUNC = 0x20, R_BIN_WASM_VALUETYPE_EMPTY = 0x40, -} r_bin_wasm_value_type_t; +} rz_bin_wasm_value_type_t; typedef enum { R_BIN_WASM_EXTERNALKIND_Function = 0x0, R_BIN_WASM_EXTERNALKIND_Table = 0x1, R_BIN_WASM_EXTERNALKIND_Memory = 0x2, R_BIN_WASM_EXTERNALKIND_Global = 0x3, -} r_bin_wasm_external_kind_t; +} rz_bin_wasm_external_kind_t; typedef enum { R_BIN_WASM_NAMETYPE_Module = 0x0, R_BIN_WASM_NAMETYPE_Function = 0x1, R_BIN_WASM_NAMETYPE_Local = 0x2, -} r_bin_wasm_custom_name_type_t; +} rz_bin_wasm_custom_name_type_t; -struct r_bin_wasm_init_expr_t { +struct rz_bin_wasm_init_expr_t { // bytecode terminated in 0xb size_t len; }; -struct r_bin_wasm_resizable_limits_t { +struct rz_bin_wasm_resizable_limits_t { ut8 flags; // 1 if max field is present, 0 otherwise ut32 initial; ut32 maximum; }; -struct r_bin_wasm_name_t { +struct rz_bin_wasm_name_t { ut32 len; ut8 name[R_BIN_WASM_STRING_LENGTH]; }; -typedef struct r_bin_wasm_section_t { +typedef struct rz_bin_wasm_section_t { ut8 id; ut32 size; ut32 name_len; @@ -81,31 +81,31 @@ typedef struct r_bin_wasm_section_t { ut32 count; } RBinWasmSection; -typedef struct r_bin_wasm_type_t { +typedef struct rz_bin_wasm_type_t { ut8 form; ut32 param_count; - r_bin_wasm_value_type_t *param_types; + rz_bin_wasm_value_type_t *param_types; st8 return_count; // MVP = 1 - r_bin_wasm_value_type_t return_type; + rz_bin_wasm_value_type_t return_type; char to_str[R_BIN_WASM_STRING_LENGTH]; } RBinWasmTypeEntry; // Other Types -struct r_bin_wasm_global_type_t { - r_bin_wasm_value_type_t content_type; +struct rz_bin_wasm_global_type_t { + rz_bin_wasm_value_type_t content_type; ut8 mutability; }; -struct r_bin_wasm_table_type_t { - r_bin_wasm_value_type_t elem_type; - struct r_bin_wasm_resizable_limits_t limits; +struct rz_bin_wasm_table_type_t { + rz_bin_wasm_value_type_t elem_type; + struct rz_bin_wasm_resizable_limits_t limits; }; -struct r_bin_wasm_memory_type_t { - struct r_bin_wasm_resizable_limits_t limits; +struct rz_bin_wasm_memory_type_t { + struct rz_bin_wasm_resizable_limits_t limits; }; -typedef struct r_bin_wasm_import_t { +typedef struct rz_bin_wasm_import_t { ut32 module_len; char module_str[R_BIN_WASM_STRING_LENGTH]; ut32 field_len; @@ -113,59 +113,59 @@ typedef struct r_bin_wasm_import_t { ut8 kind; union { ut32 type_f; - struct r_bin_wasm_global_type_t type_g; - struct r_bin_wasm_table_type_t type_t; - struct r_bin_wasm_memory_type_t type_m; + struct rz_bin_wasm_global_type_t type_g; + struct rz_bin_wasm_table_type_t type_t; + struct rz_bin_wasm_memory_type_t type_m; }; } RBinWasmImportEntry; -typedef struct r_bin_wasm_function_t { +typedef struct rz_bin_wasm_function_t { ut32 type_index; // index to Type entries } RBinWasmFunctionEntry; -typedef struct r_bin_wasm_table_t { +typedef struct rz_bin_wasm_table_t { ut8 element_type; // only anyfunc - struct r_bin_wasm_resizable_limits_t limits; + struct rz_bin_wasm_resizable_limits_t limits; } RBinWasmTableEntry; -typedef struct r_bin_wasm_memory_t { - struct r_bin_wasm_resizable_limits_t limits; +typedef struct rz_bin_wasm_memory_t { + struct rz_bin_wasm_resizable_limits_t limits; } RBinWasmMemoryEntry; -typedef struct r_bin_wasm_global_t { - r_bin_wasm_value_type_t content_type; +typedef struct rz_bin_wasm_global_t { + rz_bin_wasm_value_type_t content_type; ut8 mutability; // 0 if immutable, 1 if mutable - struct r_bin_wasm_init_expr_t init; + struct rz_bin_wasm_init_expr_t init; } RBinWasmGlobalEntry; -typedef struct r_bin_wasm_export_t { +typedef struct rz_bin_wasm_export_t { ut32 field_len; char field_str[R_BIN_WASM_STRING_LENGTH]; ut8 kind; ut32 index; } RBinWasmExportEntry; -typedef struct r_bin_wasm_start_t { +typedef struct rz_bin_wasm_start_t { ut32 index; } RBinWasmStartEntry; -struct r_bin_wasm_local_entry_t { +struct rz_bin_wasm_local_entry_t { ut32 count; - r_bin_wasm_value_type_t type; + rz_bin_wasm_value_type_t type; }; -typedef struct r_bin_wasm_element_t { +typedef struct rz_bin_wasm_element_t { ut32 index; - struct r_bin_wasm_init_expr_t init; + struct rz_bin_wasm_init_expr_t init; ut32 num_elem; ut32 elems[]; } RBinWasmElementEntry; -typedef struct r_bin_wasm_code_t { +typedef struct rz_bin_wasm_code_t { ut32 body_size; ut32 local_count; // numer of local entries - struct r_bin_wasm_local_entry_t *locals; + struct rz_bin_wasm_local_entry_t *locals; ut32 code; // offset ut32 len; // real bytecode length ut8 byte; // 0xb, indicating end of the body @@ -173,9 +173,9 @@ typedef struct r_bin_wasm_code_t { char *signature; } RBinWasmCodeEntry; -typedef struct r_bin_wasm_data_t { +typedef struct rz_bin_wasm_data_t { ut32 index; // linear memory index (0 in MVP) - struct r_bin_wasm_init_expr_t offset; // bytecode evaluated at runtime + struct rz_bin_wasm_init_expr_t offset; // bytecode evaluated at runtime ut32 size; ut32 data; // offset } RBinWasmDataEntry; @@ -183,37 +183,37 @@ typedef struct r_bin_wasm_data_t { // TODO: custom sections -typedef struct r_bin_wasm_custom_name_function_names_t { +typedef struct rz_bin_wasm_custom_name_function_names_t { ut32 count; RIDStorage *names; } RBinWasmCustomNameFunctionNames; -typedef struct r_bin_wasm_custom_name_local_name_t { +typedef struct rz_bin_wasm_custom_name_local_name_t { ut32 index; // function index ut32 names_count; RIDStorage *names; // local names } RBinWasmCustomNameLocalName; -typedef struct r_bin_wasm_custom_name_local_names_t { +typedef struct rz_bin_wasm_custom_name_local_names_t { ut32 count; - RList *locals; // RBinWasmCustomNameLocalName + RzList *locals; // RBinWasmCustomNameLocalName } RBinWasmCustomNameLocalNames; // "name" section entry -typedef struct r_bin_wasm_custom_name_entry_t { +typedef struct rz_bin_wasm_custom_name_entry_t { ut8 type; ut32 size; ut8 payload_data; union { - struct r_bin_wasm_name_t* mod_name; + struct rz_bin_wasm_name_t* mod_name; RBinWasmCustomNameFunctionNames *func; RBinWasmCustomNameLocalNames *local; }; } RBinWasmCustomNameEntry; -typedef struct r_bin_wasm_obj_t { +typedef struct rz_bin_wasm_obj_t { RBuffer *buf; size_t size; @@ -221,38 +221,38 @@ typedef struct r_bin_wasm_obj_t { ut32 entrypoint; // cache purposes - RList *g_sections; - RList *g_types; - RList *g_imports; - RList *g_exports; - RList *g_tables; - RList *g_memories; - RList *g_globals; - RList *g_elements; - RList *g_codes; - RList *g_datas; + RzList *g_sections; + RzList *g_types; + RzList *g_imports; + RzList *g_exports; + RzList *g_tables; + RzList *g_memories; + RzList *g_globals; + RzList *g_elements; + RzList *g_codes; + RzList *g_datas; RBinWasmStartEntry *g_start; - RList *g_names; + RzList *g_names; // etc... } RBinWasmObj; -RBinWasmObj *r_bin_wasm_init (RBinFile *bf, RBuffer *buf); -void r_bin_wasm_destroy (RBinFile *bf); -RList *r_bin_wasm_get_sections (RBinWasmObj *bin); -RList *r_bin_wasm_get_types (RBinWasmObj *bin); -RList *r_bin_wasm_get_imports (RBinWasmObj *bin); -RList *r_bin_wasm_get_exports (RBinWasmObj *bin); -RList *r_bin_wasm_get_tables (RBinWasmObj *bin); -RList *r_bin_wasm_get_memories (RBinWasmObj *bin); -RList *r_bin_wasm_get_globals (RBinWasmObj *bin); -RList *r_bin_wasm_get_elements (RBinWasmObj *bin); -RList *r_bin_wasm_get_codes (RBinWasmObj *bin); -RList *r_bin_wasm_get_datas (RBinWasmObj *bin); -RList *r_bin_wasm_get_custom_names (RBinWasmObj *bin); -ut32 r_bin_wasm_get_entrypoint (RBinWasmObj *bin); -const char *r_bin_wasm_get_function_name (RBinWasmObj *bin, ut32 idx); -const char *r_bin_wasm_valuetype_to_string (r_bin_wasm_value_type_t type); +RBinWasmObj *rz_bin_wasm_init (RBinFile *bf, RBuffer *buf); +void rz_bin_wasm_destroy (RBinFile *bf); +RzList *rz_bin_wasm_get_sections (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_types (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_imports (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_exports (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_tables (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_memories (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_globals (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_elements (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_codes (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_datas (RBinWasmObj *bin); +RzList *rz_bin_wasm_get_custom_names (RBinWasmObj *bin); +ut32 rz_bin_wasm_get_entrypoint (RBinWasmObj *bin); +const char *rz_bin_wasm_get_function_name (RBinWasmObj *bin, ut32 idx); +const char *rz_bin_wasm_valuetype_to_string (rz_bin_wasm_value_type_t type); #endif diff --git a/libr/bin/format/xbe/kernel.h b/librz/bin/format/xbe/kernel.h similarity index 100% rename from libr/bin/format/xbe/kernel.h rename to librz/bin/format/xbe/kernel.h diff --git a/libr/bin/format/xbe/xbe.h b/librz/bin/format/xbe/xbe.h similarity index 98% rename from libr/bin/format/xbe/xbe.h rename to librz/bin/format/xbe/xbe.h index 7bb35ae942..f61a1910aa 100644 --- a/libr/bin/format/xbe/xbe.h +++ b/librz/bin/format/xbe/xbe.h @@ -68,6 +68,6 @@ typedef struct { xbe_header header; int kt_key; int ep_key; -} r_bin_xbe_obj_t; +} rz_bin_xbe_obj_t; diff --git a/libr/bin/format/xnu/mig_index.h b/librz/bin/format/xnu/mig_index.h similarity index 99% rename from libr/bin/format/xnu/mig_index.h rename to librz/bin/format/xnu/mig_index.h index 2199d21cf4..8b9eec0e10 100644 --- a/libr/bin/format/xnu/mig_index.h +++ b/librz/bin/format/xnu/mig_index.h @@ -4,7 +4,7 @@ * python2 build_mig_index.py ~/xnu-4570.51.1/bsd/kern/trace_codes traps.json > mig_index.h * * - * The traps.json file is generated from any dyld cache using the machtraps.py r2pipe script. + * The traps.json file is generated from any dyld cache using the machtraps.py rzpipe script. * */ diff --git a/libr/bin/format/xnu/r_cf_dict.c b/librz/bin/format/xnu/rz_cf_dict.c similarity index 52% rename from libr/bin/format/xnu/r_cf_dict.c rename to librz/bin/format/xnu/rz_cf_dict.c index ac41869487..4abcde4213 100644 --- a/libr/bin/format/xnu/r_cf_dict.c +++ b/librz/bin/format/xnu/rz_cf_dict.c @@ -1,10 +1,10 @@ #include #include -#include -#include +#include +#include #include "yxml.h" -#include "r_cf_dict.h" +#include "rz_cf_dict.h" #define XMLBUFSIZE 4096 @@ -25,44 +25,44 @@ typedef struct _RCFParseState { RCFValueArray *array; } RCFParseState; -static RCFParseState *r_cf_parse_state_new(RCFParsePhase phase); -static void r_cf_parse_state_free(RCFParseState *state); +static RCFParseState *rz_cf_parse_state_new(RCFParsePhase phase); +static void rz_cf_parse_state_free(RCFParseState *state); -static RCFKeyValue *r_cf_key_value_new(char *key, RCFValue *value); -static void r_cf_key_value_free(RCFKeyValue *key_value); +static RCFKeyValue *rz_cf_key_value_new(char *key, RCFValue *value); +static void rz_cf_key_value_free(RCFKeyValue *key_value); -static RCFValueDict *r_cf_value_dict_new(void); -static void r_cf_value_dict_add(RCFValueDict *dict, RCFKeyValue *key_value); -static void r_cf_value_dict_print(RCFValueDict *dict); +static RCFValueDict *rz_cf_value_dict_new(void); +static void rz_cf_value_dict_add(RCFValueDict *dict, RCFKeyValue *key_value); +static void rz_cf_value_dict_print(RCFValueDict *dict); -static RCFValueArray *r_cf_value_array_new(void); -static void r_cf_value_array_free(RCFValueArray *array); -static void r_cf_value_array_add(RCFValueArray *array, RCFValue *value); -static void r_cf_value_array_print(RCFValueArray *dict); +static RCFValueArray *rz_cf_value_array_new(void); +static void rz_cf_value_array_free(RCFValueArray *array); +static void rz_cf_value_array_add(RCFValueArray *array, RCFValue *value); +static void rz_cf_value_array_print(RCFValueArray *dict); -static RCFValueString *r_cf_value_string_new(char *string); -static void r_cf_value_string_free(RCFValueString *string); -static void r_cf_value_string_print(RCFValueString *string); +static RCFValueString *rz_cf_value_string_new(char *string); +static void rz_cf_value_string_free(RCFValueString *string); +static void rz_cf_value_string_print(RCFValueString *string); -static RCFValueInteger *r_cf_value_integer_new(char *string); -static void r_cf_value_integer_free(RCFValueInteger *integer); -static void r_cf_value_integer_print(RCFValueInteger *integer); +static RCFValueInteger *rz_cf_value_integer_new(char *string); +static void rz_cf_value_integer_free(RCFValueInteger *integer); +static void rz_cf_value_integer_print(RCFValueInteger *integer); -static RCFValueData *r_cf_value_data_new(char *string); -static void r_cf_value_data_free(RCFValueData *data); -static void r_cf_value_data_print(RCFValueData *data); +static RCFValueData *rz_cf_value_data_new(char *string); +static void rz_cf_value_data_free(RCFValueData *data); +static void rz_cf_value_data_print(RCFValueData *data); -static RCFValueNULL *r_cf_value_null_new(void); -static void r_cf_value_null_free(RCFValueNULL *null); -static void r_cf_value_null_print(RCFValueNULL *null); +static RCFValueNULL *rz_cf_value_null_new(void); +static void rz_cf_value_null_free(RCFValueNULL *null); +static void rz_cf_value_null_print(RCFValueNULL *null); -static RCFValueBool *r_cf_value_bool_new(bool value); -static void r_cf_value_bool_free(RCFValueBool *bool_value); -static void r_cf_value_bool_print(RCFValueBool *bool_value); +static RCFValueBool *rz_cf_value_bool_new(bool value); +static void rz_cf_value_bool_free(RCFValueBool *bool_value); +static void rz_cf_value_bool_print(RCFValueBool *bool_value); -static void r_cf_value_free(RCFValue *value); +static void rz_cf_value_free(RCFValue *value); -RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, int options) { +RCFValueDict *rz_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, int options) { RCFValueDict *result = NULL; yxml_t x; int i, depth = 0; @@ -75,16 +75,16 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, yxml_init (&x, xml_buf, XMLBUFSIZE); - RList *stack = r_list_newf ((RListFree)&r_cf_parse_state_free); + RzList *stack = rz_list_newf ((RzListFree)&rz_cf_parse_state_free); if (!stack) { goto beach; } - r_list_push (stack, r_cf_parse_state_new (R_CF_STATE_ROOT)); + rz_list_push (stack, rz_cf_parse_state_new (R_CF_STATE_ROOT)); for (i = 0; i < size; i++) { ut8 doc = 0; - r_buf_read_at (file_buf, offset + i, &doc, 1); + rz_buf_read_at (file_buf, offset + i, &doc, 1); if (!doc) { break; } @@ -98,57 +98,57 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, switch (r) { case YXML_ELEMSTART: { - RCFParseState *state = (RCFParseState *)r_list_get_top (stack); + RCFParseState *state = (RCFParseState *)rz_list_get_top (stack); RCFParseState *next_state = NULL; if (!strcmp (x.elem, "dict")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_DICT); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_DICT); if (!next_state) { goto beach; } - next_state->dict = r_cf_value_dict_new (); + next_state->dict = rz_cf_value_dict_new (); } else if (!strcmp (x.elem, "array")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_ARRAY); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_ARRAY); if (!next_state) { goto beach; } - next_state->array = r_cf_value_array_new (); + next_state->array = rz_cf_value_array_new (); } else if (!strcmp (x.elem, "key") && state->phase == R_CF_STATE_IN_DICT) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_KEY); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_KEY); if (!next_state) { goto beach; } next_state->dict = state->dict; } else if (!strcmp (x.elem, "string")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_SCALAR); if (!next_state) { goto beach; } next_state->value_type = R_CF_STRING; } else if (!strcmp (x.elem, "integer")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_SCALAR); if (!next_state) { goto beach; } next_state->value_type = R_CF_INTEGER; } else if (!strcmp (x.elem, "data")) { if (options & R_CF_OPTION_SKIP_NSDATA) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_IGNORE); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_IGNORE); } else { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_SCALAR); if (!next_state) { goto beach; } next_state->value_type = R_CF_DATA; } } else if (!strcmp (x.elem, "true")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_SCALAR); if (!next_state) { goto beach; } next_state->value_type = R_CF_TRUE; } else if (!strcmp (x.elem, "false")) { - next_state = r_cf_parse_state_new (R_CF_STATE_IN_SCALAR); + next_state = rz_cf_parse_state_new (R_CF_STATE_IN_SCALAR); if (!next_state) { goto beach; } @@ -156,7 +156,7 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, } if (next_state) { - r_list_push (stack, next_state); + rz_list_push (stack, next_state); } else { eprintf ("Missing next state for elem: %s phase: %d\n", x.elem, state->phase); break; @@ -166,8 +166,8 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, break; } case YXML_ELEMEND: { - RCFParseState *state = (RCFParseState *)r_list_pop (stack); - RCFParseState *next_state = (RCFParseState *)r_list_get_top (stack); + RCFParseState *state = (RCFParseState *)rz_list_pop (stack); + RCFParseState *next_state = (RCFParseState *)rz_list_get_top (stack); if (!state || !next_state) { goto beach; } @@ -175,7 +175,7 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, if (next_state->phase == R_CF_STATE_ROOT) { if (state->phase == R_CF_STATE_IN_DICT) { result = state->dict; - r_cf_parse_state_free (state); + rz_cf_parse_state_free (state); break; } else { eprintf ("Root element is not a dict\n"); @@ -203,25 +203,25 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, break; case R_CF_STATE_IN_SCALAR: if (!content && state->value_type != R_CF_FALSE && state->value_type != R_CF_TRUE) { - value = (RCFValue *)r_cf_value_null_new (); + value = (RCFValue *)rz_cf_value_null_new (); } else { switch (state->value_type) { case R_CF_STRING: - value = (RCFValue *)r_cf_value_string_new (content); + value = (RCFValue *)rz_cf_value_string_new (content); break; case R_CF_INTEGER: - value = (RCFValue *)r_cf_value_integer_new (content); + value = (RCFValue *)rz_cf_value_integer_new (content); R_FREE (content); break; case R_CF_DATA: - value = (RCFValue *)r_cf_value_data_new (content); + value = (RCFValue *)rz_cf_value_data_new (content); R_FREE (content); break; case R_CF_TRUE: - value = (RCFValue *)r_cf_value_bool_new (true); + value = (RCFValue *)rz_cf_value_bool_new (true); break; case R_CF_FALSE: - value = (RCFValue *)r_cf_value_bool_new (false); + value = (RCFValue *)rz_cf_value_bool_new (false); break; default: break; @@ -234,19 +234,19 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, if (next_state->phase == R_CF_STATE_IN_DICT) { if (value) { - RCFKeyValue *key_value = r_cf_key_value_new (next_state->key, value); - r_cf_value_dict_add (next_state->dict, key_value); + RCFKeyValue *key_value = rz_cf_key_value_new (next_state->key, value); + rz_cf_value_dict_add (next_state->dict, key_value); } else if (state->phase != R_CF_STATE_IN_IGNORE) { eprintf ("Missing value for key %s\n", next_state->key); - r_cf_value_free ((RCFValue *)value); + rz_cf_value_free ((RCFValue *)value); goto beach; } } else if (next_state->phase == R_CF_STATE_IN_ARRAY) { if (value) { - r_cf_value_array_add (next_state->array, value); + rz_cf_value_array_add (next_state->array, value); } else if (state->phase != R_CF_STATE_IN_IGNORE) { eprintf ("Missing value for array\n"); - r_cf_value_free ((RCFValue *)value); + rz_cf_value_free ((RCFValue *)value); goto beach; } } @@ -254,18 +254,18 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, depth--; content = NULL; - r_cf_parse_state_free (state); + rz_cf_parse_state_free (state); break; } case YXML_CONTENT: { - RCFParseState *state = (RCFParseState *)r_list_get_top (stack); + RCFParseState *state = (RCFParseState *)rz_list_get_top (stack); if (state->phase == R_CF_STATE_IN_IGNORE) { break; } if (!content) { - content = r_str_new (x.data); + content = rz_str_new (x.data); } else { - content = r_str_append (content, x.data); + content = rz_str_append (content, x.data); } break; } @@ -286,13 +286,13 @@ RCFValueDict *r_cf_value_dict_parse (RBuffer *file_buf, ut64 offset, ut64 size, beach: R_FREE (xml_buf); if (stack) { - r_list_free (stack); + rz_list_free (stack); } return result; } -static RCFParseState *r_cf_parse_state_new(RCFParsePhase phase) { +static RCFParseState *rz_cf_parse_state_new(RCFParsePhase phase) { RCFParseState *state = R_NEW0 (RCFParseState); if (state) { state->phase = phase; @@ -300,13 +300,13 @@ static RCFParseState *r_cf_parse_state_new(RCFParsePhase phase) { return state; } -static void r_cf_parse_state_free(RCFParseState *state) { +static void rz_cf_parse_state_free(RCFParseState *state) { if (state) { R_FREE (state); } } -static RCFKeyValue *r_cf_key_value_new(char *key, RCFValue *value) { +static RCFKeyValue *rz_cf_key_value_new(char *key, RCFValue *value) { RCFKeyValue *key_value = R_NEW0 (RCFKeyValue); if (!key_value) { return NULL; @@ -318,7 +318,7 @@ static RCFKeyValue *r_cf_key_value_new(char *key, RCFValue *value) { return key_value; } -static void r_cf_key_value_free(RCFKeyValue *key_value) { +static void rz_cf_key_value_free(RCFKeyValue *key_value) { if (!key_value) { return; } @@ -327,53 +327,53 @@ static void r_cf_key_value_free(RCFKeyValue *key_value) { R_FREE (key_value->key); } if (key_value->value) { - r_cf_value_free (key_value->value); + rz_cf_value_free (key_value->value); key_value->value = NULL; } R_FREE (key_value); } -static RCFValueDict *r_cf_value_dict_new(void) { +static RCFValueDict *rz_cf_value_dict_new(void) { RCFValueDict *dict = R_NEW0 (RCFValueDict); if (!dict) { return NULL; } dict->type = R_CF_DICT; - dict->pairs = r_list_newf ((RListFree)&r_cf_key_value_free); + dict->pairs = rz_list_newf ((RzListFree)&rz_cf_key_value_free); return dict; } -void r_cf_value_dict_free (RCFValueDict *dict) { - r_return_if_fail (dict); +void rz_cf_value_dict_free (RCFValueDict *dict) { + rz_return_if_fail (dict); if (dict->pairs) { - r_list_free (dict->pairs); + rz_list_free (dict->pairs); dict->pairs = NULL; } dict->type = R_CF_INVALID; R_FREE (dict); } -static void r_cf_value_dict_add(RCFValueDict *dict, RCFKeyValue *key_value) { +static void rz_cf_value_dict_add(RCFValueDict *dict, RCFKeyValue *key_value) { if (!dict || !dict->pairs) { return; } - r_list_push (dict->pairs, key_value); + rz_list_push (dict->pairs, key_value); } -static void r_cf_value_dict_print(RCFValueDict *dict) { - RListIter *iter; +static void rz_cf_value_dict_print(RCFValueDict *dict) { + RzListIter *iter; RCFKeyValue *key_value; - int length = r_list_length (dict->pairs); + int length = rz_list_length (dict->pairs); int i = 0; printf ("{"); - r_list_foreach (dict->pairs, iter, key_value) { + rz_list_foreach (dict->pairs, iter, key_value) { printf ("\"%s\":", key_value->key); - r_cf_value_print (key_value->value); + rz_cf_value_print (key_value->value); if (i++ < length - 1) { printf (","); } @@ -381,25 +381,25 @@ static void r_cf_value_dict_print(RCFValueDict *dict) { printf ("}"); } -static RCFValueArray *r_cf_value_array_new(void) { +static RCFValueArray *rz_cf_value_array_new(void) { RCFValueArray *array = R_NEW0 (RCFValueArray); if (!array) { return NULL; } array->type = R_CF_ARRAY; - array->values = r_list_newf ((RListFree)&r_cf_value_free); + array->values = rz_list_newf ((RzListFree)&rz_cf_value_free); return array; } -static void r_cf_value_array_free(RCFValueArray *array) { +static void rz_cf_value_array_free(RCFValueArray *array) { if (!array) { return; } if (array->values) { - r_list_free (array->values); + rz_list_free (array->values); array->values = NULL; } @@ -407,22 +407,22 @@ static void r_cf_value_array_free(RCFValueArray *array) { R_FREE (array); } -static void r_cf_value_array_add(RCFValueArray *array, RCFValue *value) { +static void rz_cf_value_array_add(RCFValueArray *array, RCFValue *value) { if (!array || !array->values) { return; } - r_list_push (array->values, value); + rz_list_push (array->values, value); } -static void r_cf_value_array_print(RCFValueArray *array) { - RListIter *iter; +static void rz_cf_value_array_print(RCFValueArray *array) { + RzListIter *iter; RCFValue *value; - int length = r_list_length (array->values); + int length = rz_list_length (array->values); int i = 0; printf ("["); - r_list_foreach (array->values, iter, value) { - r_cf_value_print (value); + rz_list_foreach (array->values, iter, value) { + rz_cf_value_print (value); if (i++ < length - 1) { printf (","); } @@ -430,7 +430,7 @@ static void r_cf_value_array_print(RCFValueArray *array) { printf ("]"); } -static RCFValueString *r_cf_value_string_new(char *string) { +static RCFValueString *rz_cf_value_string_new(char *string) { RCFValueString *value_string = R_NEW0 (RCFValueString); if (!value_string) { return NULL; @@ -442,7 +442,7 @@ static RCFValueString *r_cf_value_string_new(char *string) { return value_string; } -static void r_cf_value_string_free(RCFValueString *string) { +static void rz_cf_value_string_free(RCFValueString *string) { if (!string) { return; } @@ -455,26 +455,26 @@ static void r_cf_value_string_free(RCFValueString *string) { R_FREE (string); } -static void r_cf_value_string_print(RCFValueString *string) { +static void rz_cf_value_string_print(RCFValueString *string) { char *escaped = strdup (string->value); - escaped = r_str_replace (escaped, "\"", "\\\"", 1); + escaped = rz_str_replace (escaped, "\"", "\\\"", 1); printf ("\"%s\"", escaped); R_FREE (escaped); } -static RCFValueInteger *r_cf_value_integer_new(char *string) { +static RCFValueInteger *rz_cf_value_integer_new(char *string) { RCFValueInteger *integer = R_NEW0 (RCFValueInteger); if (!integer) { return NULL; } integer->type = R_CF_INTEGER; - integer->value = r_num_get (NULL, string); + integer->value = rz_num_get (NULL, string); return integer; } -static void r_cf_value_integer_free(RCFValueInteger *integer) { +static void rz_cf_value_integer_free(RCFValueInteger *integer) { if (!integer) { return; } @@ -483,11 +483,11 @@ static void r_cf_value_integer_free(RCFValueInteger *integer) { R_FREE (integer); } -static void r_cf_value_integer_print(RCFValueInteger *integer) { +static void rz_cf_value_integer_print(RCFValueInteger *integer) { printf ("%llu", integer->value); } -static RCFValueData *r_cf_value_data_new(char *string) { +static RCFValueData *rz_cf_value_data_new(char *string) { RCFValueData *data = R_NEW0 (RCFValueData); if (!data) { return NULL; @@ -500,33 +500,33 @@ static RCFValueData *r_cf_value_data_new(char *string) { R_FREE (data); return NULL; } - r_base64_decode (out, string, len); + rz_base64_decode (out, string, len); data->type = R_CF_DATA; - data->value = r_buf_new_with_pointers (out, out_len, true); + data->value = rz_buf_new_with_pointers (out, out_len, true); return data; } -static void r_cf_value_data_free(RCFValueData *data) { +static void rz_cf_value_data_free(RCFValueData *data) { if (!data) { return; } data->type = R_CF_INVALID; if (data->value) { - r_buf_free (data->value); + rz_buf_free (data->value); data->value = NULL; } R_FREE (data); } -static void r_cf_value_data_print(RCFValueData *data) { +static void rz_cf_value_data_print(RCFValueData *data) { printf ("\"...\""); } -static RCFValueNULL *r_cf_value_null_new(void) { +static RCFValueNULL *rz_cf_value_null_new(void) { RCFValueNULL *null = R_NEW0 (RCFValueNULL); if (!null) { return NULL; @@ -537,7 +537,7 @@ static RCFValueNULL *r_cf_value_null_new(void) { return null; } -static void r_cf_value_null_free(RCFValueNULL *null) { +static void rz_cf_value_null_free(RCFValueNULL *null) { if (!null) { return; } @@ -546,11 +546,11 @@ static void r_cf_value_null_free(RCFValueNULL *null) { R_FREE (null); } -static void r_cf_value_null_print(RCFValueNULL *null) { +static void rz_cf_value_null_print(RCFValueNULL *null) { printf ("null"); } -static RCFValueBool *r_cf_value_bool_new(bool value) { +static RCFValueBool *rz_cf_value_bool_new(bool value) { RCFValueBool *bool_value = R_NEW0 (RCFValueBool); if (!bool_value) { return NULL; @@ -560,80 +560,80 @@ static RCFValueBool *r_cf_value_bool_new(bool value) { return bool_value; } -static void r_cf_value_bool_free(RCFValueBool *bool_value) { +static void rz_cf_value_bool_free(RCFValueBool *bool_value) { if (bool_value) { bool_value->type = R_CF_INVALID; R_FREE (bool_value); } } -static void r_cf_value_bool_print(RCFValueBool *bool_value) { +static void rz_cf_value_bool_print(RCFValueBool *bool_value) { if (bool_value->type == R_CF_TRUE) { printf ("true"); } else { printf ("false"); } } -static void r_cf_value_free(RCFValue *value) { +static void rz_cf_value_free(RCFValue *value) { if (!value) { return; } switch (value->type) { case R_CF_DICT: - r_cf_value_dict_free ((RCFValueDict *)value); + rz_cf_value_dict_free ((RCFValueDict *)value); break; case R_CF_ARRAY: - r_cf_value_array_free ((RCFValueArray *)value); + rz_cf_value_array_free ((RCFValueArray *)value); break; case R_CF_STRING: - r_cf_value_string_free ((RCFValueString *)value); + rz_cf_value_string_free ((RCFValueString *)value); break; case R_CF_INTEGER: - r_cf_value_integer_free ((RCFValueInteger *)value); + rz_cf_value_integer_free ((RCFValueInteger *)value); break; case R_CF_DATA: - r_cf_value_data_free ((RCFValueData *)value); + rz_cf_value_data_free ((RCFValueData *)value); break; case R_CF_NULL: - r_cf_value_null_free ((RCFValueNULL *)value); + rz_cf_value_null_free ((RCFValueNULL *)value); break; case R_CF_TRUE: case R_CF_FALSE: - r_cf_value_bool_free ((RCFValueBool *)value); + rz_cf_value_bool_free ((RCFValueBool *)value); break; default: break; } } -void r_cf_value_print (RCFValue *value) { +void rz_cf_value_print (RCFValue *value) { if (!value) { return; } switch (value->type) { case R_CF_DICT: - r_cf_value_dict_print ((RCFValueDict *)value); + rz_cf_value_dict_print ((RCFValueDict *)value); break; case R_CF_ARRAY: - r_cf_value_array_print ((RCFValueArray *)value); + rz_cf_value_array_print ((RCFValueArray *)value); break; case R_CF_STRING: - r_cf_value_string_print ((RCFValueString *)value); + rz_cf_value_string_print ((RCFValueString *)value); break; case R_CF_INTEGER: - r_cf_value_integer_print ((RCFValueInteger *)value); + rz_cf_value_integer_print ((RCFValueInteger *)value); break; case R_CF_DATA: - r_cf_value_data_print ((RCFValueData *)value); + rz_cf_value_data_print ((RCFValueData *)value); break; case R_CF_NULL: - r_cf_value_null_print ((RCFValueNULL *)value); + rz_cf_value_null_print ((RCFValueNULL *)value); break; case R_CF_TRUE: case R_CF_FALSE: - r_cf_value_bool_print ((RCFValueBool *)value); + rz_cf_value_bool_print ((RCFValueBool *)value); break; default: break; diff --git a/libr/bin/format/xnu/r_cf_dict.h b/librz/bin/format/xnu/rz_cf_dict.h similarity index 77% rename from libr/bin/format/xnu/r_cf_dict.h rename to librz/bin/format/xnu/rz_cf_dict.h index 47ec8149b6..2fe46d9ab0 100644 --- a/libr/bin/format/xnu/r_cf_dict.h +++ b/librz/bin/format/xnu/rz_cf_dict.h @@ -27,12 +27,12 @@ typedef struct _CFKeyValue { typedef struct _CFValueDict { RCFValueType type; - RList * pairs; //_CFKeyValue + RzList * pairs; //_CFKeyValue } RCFValueDict; typedef struct _CFValueArray { RCFValueType type; - RList * values; //_CFValue + RzList * values; //_CFValue } RCFValueArray; typedef struct _CFValueString { @@ -58,8 +58,8 @@ typedef struct _CFValueNULL { RCFValueType type; } RCFValueNULL; -R_API RCFValueDict * r_cf_value_dict_parse(RBuffer * file_buf, ut64 offset, ut64 size, int options); -R_API void r_cf_value_dict_free(RCFValueDict * dict); -R_API void r_cf_value_print(RCFValue * value); +RZ_API RCFValueDict * rz_cf_value_dict_parse(RBuffer * file_buf, ut64 offset, ut64 size, int options); +RZ_API void rz_cf_value_dict_free(RCFValueDict * dict); +RZ_API void rz_cf_value_print(RCFValue * value); #endif diff --git a/libr/bin/format/xnu/scripts/build_mig_index.py b/librz/bin/format/xnu/scripts/build_mig_index.py similarity index 98% rename from libr/bin/format/xnu/scripts/build_mig_index.py rename to librz/bin/format/xnu/scripts/build_mig_index.py index 6c9b4f10cd..7c24263a85 100644 --- a/libr/bin/format/xnu/scripts/build_mig_index.py +++ b/librz/bin/format/xnu/scripts/build_mig_index.py @@ -9,7 +9,7 @@ header = """ /* * python2 build_mig_index.py ~/xnu-4570.51.1/bsd/kern/trace_codes traps.json > mig_index.h * * - * The traps.json file is generated from any dyld cache using the machtraps.py r2pipe script. + * The traps.json file is generated from any dyld cache using the machtraps.py rzpipe script. * */ """ diff --git a/libr/bin/format/xnu/scripts/machtraps.py b/librz/bin/format/xnu/scripts/machtraps.py similarity index 98% rename from libr/bin/format/xnu/scripts/machtraps.py rename to librz/bin/format/xnu/scripts/machtraps.py index 65ce21372e..56105e65c0 100644 --- a/libr/bin/format/xnu/scripts/machtraps.py +++ b/librz/bin/format/xnu/scripts/machtraps.py @@ -11,9 +11,9 @@ R_DYLDCACHE_FILTER=libsystem_kernel r2 -e bin.usextr=false ~/Library/Developer/X """ -import r2pipe, json, re +import rzpipe, json, re -r = r2pipe.open('#!pipe') +r = rzpipe.open('#!pipe') def walk_back_until (addr, pattern, min_addr): cursor = addr diff --git a/librz/bin/format/zimg/zimg.c b/librz/bin/format/zimg/zimg.c new file mode 100644 index 0000000000..1ec07350eb --- /dev/null +++ b/librz/bin/format/zimg/zimg.c @@ -0,0 +1,28 @@ +/* radare - LGPL - Copyright 2009-2015 - ninjahacker */ + +#include +#include +#include "zimg.h" + + +struct rz_bin_zimg_obj_t* rz_bin_zimg_new_buf(RBuffer *buf) { + struct rz_bin_zimg_obj_t *bin = R_NEW0 (struct rz_bin_zimg_obj_t); + if (!bin) { + goto fail; + } + bin->size = rz_buf_size (buf); + bin->b = rz_buf_ref (buf); + if (rz_buf_size (bin->b) < sizeof (struct zimg_header_t)) { + goto fail; + } + rz_buf_read_at (bin->b, 0, (ut8 *)&bin->header, sizeof (bin->header)); + return bin; + +fail: + if (bin) { + rz_buf_free (bin->b); + free (bin); + } + return NULL; +} + diff --git a/libr/bin/format/zimg/zimg.h b/librz/bin/format/zimg/zimg.h similarity index 55% rename from libr/bin/format/zimg/zimg.h rename to librz/bin/format/zimg/zimg.h index d65093b682..4ecb0294c1 100644 --- a/libr/bin/format/zimg/zimg.h +++ b/librz/bin/format/zimg/zimg.h @@ -1,10 +1,10 @@ #ifndef ZIMG_H #define ZIMG_H -#include -#include -#include -#include +#include +#include +#include +#include #define R_BIN_ZIMG_MAXSTR 256 @@ -16,20 +16,20 @@ struct zimg_header_t { ut32 kernel_end; }; -typedef struct r_bin_zimg_obj_t { +typedef struct rz_bin_zimg_obj_t { int size; const char *file; RBuffer *b; struct zimg_header_t header; ut32 *strings; - RList *methods_list; - RList *imports_list; + RzList *methods_list; + RzList *imports_list; ut64 code_from; ut64 code_to; Sdb *kv; } RBinZimgObj; -struct r_bin_zimg_str_t { +struct rz_bin_zimg_str_t { char str[R_BIN_ZIMG_MAXSTR]; ut64 offset; ut64 ordinal; @@ -37,7 +37,7 @@ struct r_bin_zimg_str_t { int last; }; -struct r_bin_zimg_obj_t *r_bin_zimg_new_buf(RBuffer *buf); -struct r_bin_zimg_str_t *r_bin_zimg_get_strings (struct r_bin_zimg_obj_t *bin); +struct rz_bin_zimg_obj_t *rz_bin_zimg_new_buf(RBuffer *buf); +struct rz_bin_zimg_str_t *rz_bin_zimg_get_strings (struct rz_bin_zimg_obj_t *bin); #endif diff --git a/librz/bin/i/private.h b/librz/bin/i/private.h new file mode 100644 index 0000000000..a9067b80cf --- /dev/null +++ b/librz/bin/i/private.h @@ -0,0 +1,42 @@ +#ifndef R_BIN_PRIVATE_H_ +#define R_BIN_PRIVATE_H_ + +#include +#include +#include + +R_IPI RBinFile *rz_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr); +R_IPI RBinObject *rz_bin_file_object_find_by_id(RBinFile *binfile, ut32 binobj_id); +R_IPI RzList *rz_bin_file_get_strings(RBinFile *a, int min, int dump, int raw); +R_IPI RBinFile *rz_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id); +R_IPI RBinFile *rz_bin_file_find_by_id(RBin *bin, ut32 binfile_id); +R_IPI RBinFile *rz_bin_file_find_by_name_n(RBin *bin, const char *name, int idx); +R_IPI bool rz_bin_file_set_obj(RBin *bin, RBinFile *bf, RBinObject *obj); +R_IPI RBinFile *rz_bin_file_xtr_load_bytes(RBin *bin, RBinXtrPlugin *xtr, const char *filename, const ut8 *bytes, ut64 sz, ut64 file_sz, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr); +R_IPI bool rz_bin_file_set_bytes(RBinFile *binfile, const ut8 *bytes, ut64 sz, bool steal_ptr); + +R_IPI RBinPlugin *rz_bin_get_binplugin_any(RBin *bin); +R_IPI RBinXtrPlugin *rz_bin_get_xtrplugin_by_name(RBin *bin, const char *name); +R_IPI RBinPlugin *rz_bin_get_binplugin_by_name(RBin *bin, const char *name); + +R_IPI void rz_bin_section_free(RBinSection *bs); + +R_IPI void rz_bin_object_free(void /*RBinObject*/ *o_); +R_IPI ut64 rz_bin_object_get_baddr(RBinObject *o); +R_IPI void rz_bin_object_filter_strings(RBinObject *bo); +R_IPI RBinObject *rz_bin_object_new(RBinFile *binfile, RBinPlugin *plugin, ut64 baseaddr, ut64 loadaddr, ut64 offset, ut64 sz); +R_IPI RBinObject *rz_bin_object_get_cur(RBin *bin); +R_IPI RBinObject *rz_bin_object_find_by_arch_bits(RBinFile *binfile, const char *arch, int bits, const char *name); +R_IPI RBNode *rz_bin_object_patch_relocs(RBin *bin, RBinObject *o); + +R_IPI const char *rz_bin_lang_tostring(int lang); +R_IPI int rz_bin_lang_type(RBinFile *binfile, const char *def, const char *sym); +R_IPI bool rz_bin_lang_swift(RBinFile *binfile); + +R_IPI void rz_bin_class_free(RBinClass *c); +R_IPI RBinSymbol *rz_bin_class_add_method(RBinFile *binfile, const char *classname, const char *name, int nargs); +R_IPI void rz_bin_class_add_field(RBinFile *binfile, const char *classname, const char *name); + +R_IPI RBinFile *rz_bin_file_xtr_load_buffer(RBin *bin, RBinXtrPlugin *xtr, const char *filename, RBuffer *buf, ut64 baseaddr, ut64 loadaddr, int idx, int fd, int rawstr); +R_IPI RBinFile *rz_bin_file_new_from_buffer(RBin *bin, const char *file, RBuffer *buf, int rawstr, ut64 baseaddr, ut64 loadaddr, int fd, const char *pluginname); +#endif diff --git a/libr/bin/mangling/Makefile b/librz/bin/mangling/Makefile similarity index 89% rename from libr/bin/mangling/Makefile rename to librz/bin/mangling/Makefile index de903f170e..316a27a0f6 100644 --- a/libr/bin/mangling/Makefile +++ b/librz/bin/mangling/Makefile @@ -1,3 +1,3 @@ all: - $(CC) -g -DHAS_MAIN=1 -I../../include swift-sd.c -L../../util -lr_util + $(CC) -g -DHAS_MAIN=1 -I../../include swift-sd.c -L../../util -lrz_util ./a.out diff --git a/libr/bin/mangling/cxx.c b/librz/bin/mangling/cxx.c similarity index 90% rename from libr/bin/mangling/cxx.c rename to librz/bin/mangling/cxx.c index 810617d9b7..7df176208f 100644 --- a/libr/bin/mangling/cxx.c +++ b/librz/bin/mangling/cxx.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include +#include #include "../i/private.h" #include "./cxx/demangle.h" -R_API char *r_bin_demangle_cxx(RBinFile *bf, const char *str, ut64 vaddr) { +RZ_API char *rz_bin_demangle_cxx(RBinFile *bf, const char *str, ut64 vaddr) { // DMGL_TYPES | DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE // | DMGL_RET_POSTFIX | DMGL_TYPES; int i; @@ -67,7 +67,7 @@ R_API char *r_bin_demangle_cxx(RBinFile *bf, const char *str, ut64 vaddr) { if (nerd && *nerd) { *nerd = 0; if (bf) { - RBinSymbol *sym = r_bin_file_add_method (bf, out, nerd + 2, 0); + RBinSymbol *sym = rz_bin_file_add_method (bf, out, nerd + 2, 0); if (sym) { if (sym->vaddr != 0 && sym->vaddr != vaddr) { if (bf && bf->rbin && bf->rbin->verbose) { diff --git a/libr/bin/mangling/cxx/Makefile b/librz/bin/mangling/cxx/Makefile similarity index 100% rename from libr/bin/mangling/cxx/Makefile rename to librz/bin/mangling/cxx/Makefile diff --git a/libr/bin/mangling/cxx/ansidecl.h b/librz/bin/mangling/cxx/ansidecl.h similarity index 100% rename from libr/bin/mangling/cxx/ansidecl.h rename to librz/bin/mangling/cxx/ansidecl.h diff --git a/libr/bin/mangling/cxx/cp-demangle.c b/librz/bin/mangling/cxx/cp-demangle.c similarity index 100% rename from libr/bin/mangling/cxx/cp-demangle.c rename to librz/bin/mangling/cxx/cp-demangle.c diff --git a/libr/bin/mangling/cxx/cp-demangle.h b/librz/bin/mangling/cxx/cp-demangle.h similarity index 100% rename from libr/bin/mangling/cxx/cp-demangle.h rename to librz/bin/mangling/cxx/cp-demangle.h diff --git a/libr/bin/mangling/cxx/demangle.h b/librz/bin/mangling/cxx/demangle.h similarity index 100% rename from libr/bin/mangling/cxx/demangle.h rename to librz/bin/mangling/cxx/demangle.h diff --git a/libr/bin/mangling/cxx/libiberty.h b/librz/bin/mangling/cxx/libiberty.h similarity index 100% rename from libr/bin/mangling/cxx/libiberty.h rename to librz/bin/mangling/cxx/libiberty.h diff --git a/libr/bin/mangling/cxx/test.js b/librz/bin/mangling/cxx/test.js similarity index 100% rename from libr/bin/mangling/cxx/test.js rename to librz/bin/mangling/cxx/test.js diff --git a/libr/bin/mangling/demangler.c b/librz/bin/mangling/demangler.c similarity index 98% rename from libr/bin/mangling/demangler.c rename to librz/bin/mangling/demangler.c index e1013b63b9..5a681b76d2 100644 --- a/libr/bin/mangling/demangler.c +++ b/librz/bin/mangling/demangler.c @@ -3,7 +3,7 @@ #include "demangler.h" #include -#include // eprintf() +#include // eprintf() #include "microsoft_demangle.h" diff --git a/libr/bin/mangling/demangler.h b/librz/bin/mangling/demangler.h similarity index 100% rename from libr/bin/mangling/demangler.h rename to librz/bin/mangling/demangler.h diff --git a/libr/bin/mangling/demangler_types.h b/librz/bin/mangling/demangler_types.h similarity index 100% rename from libr/bin/mangling/demangler_types.h rename to librz/bin/mangling/demangler_types.h diff --git a/libr/bin/mangling/java.c b/librz/bin/mangling/java.c similarity index 66% rename from libr/bin/mangling/java.c rename to librz/bin/mangling/java.c index 0a892959a7..e73486b0f0 100644 --- a/libr/bin/mangling/java.c +++ b/librz/bin/mangling/java.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2011-2018 - pancake */ -#include +#include // http://code.google.com/p/smali/wiki/TypesMethodsAndFields -R_API char *r_bin_demangle_java(const char *str) { +RZ_API char *rz_bin_demangle_java(const char *str) { const char *w = NULL; int is_array = 0; const char *ptr; @@ -17,12 +17,12 @@ R_API char *r_bin_demangle_java(const char *str) { if (!ptr) { return NULL; } - buf = r_buf_new (); + buf = rz_buf_new (); if (!buf) { return NULL; } - r_buf_append_bytes (buf, (const ut8*)str, (int)(size_t)(ptr-str)); - r_buf_append_bytes (buf, (const ut8*)" (", 2); + rz_buf_append_bytes (buf, (const ut8*)str, (int)(size_t)(ptr-str)); + rz_buf_append_bytes (buf, (const ut8*)" (", 2); while (*str) { switch (*str) { case ')': @@ -52,18 +52,18 @@ R_API char *r_bin_demangle_java(const char *str) { } if (w) { if (is_ret) { - r_buf_prepend_bytes (buf, (const ut8*)" ", 1); - r_buf_prepend_bytes (buf, (const ut8*)w, wlen); - r_buf_append_bytes (buf, (const ut8*)")", 1); + rz_buf_prepend_bytes (buf, (const ut8*)" ", 1); + rz_buf_prepend_bytes (buf, (const ut8*)w, wlen); + rz_buf_append_bytes (buf, (const ut8*)")", 1); break; } else { if (n++ > 0) { - r_buf_append_bytes (buf, (const ut8 *)", ", 2); + rz_buf_append_bytes (buf, (const ut8 *)", ", 2); } - r_buf_append_bytes (buf, (const ut8*)w, wlen); + rz_buf_append_bytes (buf, (const ut8*)w, wlen); } if (is_array) { - r_buf_append_bytes (buf, (const ut8*)"[]", 2); + rz_buf_append_bytes (buf, (const ut8*)"[]", 2); is_array = 0; } } @@ -73,8 +73,8 @@ R_API char *r_bin_demangle_java(const char *str) { } str++; } - ret = r_buf_to_string (buf); - r_buf_free (buf); + ret = rz_buf_to_string (buf); + rz_buf_free (buf); return ret; } diff --git a/libr/bin/mangling/microsoft_demangle.c b/librz/bin/mangling/microsoft_demangle.c similarity index 94% rename from libr/bin/mangling/microsoft_demangle.c rename to librz/bin/mangling/microsoft_demangle.c index d9635e168d..a08687360a 100644 --- a/libr/bin/mangling/microsoft_demangle.c +++ b/librz/bin/mangling/microsoft_demangle.c @@ -2,18 +2,18 @@ #include "microsoft_demangle.h" #include -#include +#include #define _R_LIST_C -#include +#include #define MICROSOFT_NAME_LEN (256) #define MICROSOFR_CLASS_NAMESPACE_LEN (256) #define IMPOSSIBLE_LEN (MICROSOFT_NAME_LEN + MICROSOFR_CLASS_NAMESPACE_LEN) // TODO: it will be good to change this to some kind of map data structure -static RList *abbr_types = NULL; -static RList *abbr_names = NULL; +static RzList *abbr_types = NULL; +static RzList *abbr_names = NULL; typedef enum EObjectType { eObjectTypeStaticClassMember = 2, @@ -156,7 +156,7 @@ static int copy_string(STypeCodeStr *type_code_str, const char *str_for_copy, si } if (str_for_copy) { - r_str_ncpy (dst, str_for_copy, str_for_copy_len + 1); + rz_str_ncpy (dst, str_for_copy, str_for_copy_len + 1); } else { memset (dst, 0, str_for_copy_len); } @@ -180,7 +180,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch state.buff_for_parsing += 1; res = get_num (&state); if (res) { - tmp = r_str_newf("%s%s", template_param, res); + tmp = rz_str_newf("%s%s", template_param, res); free (res); res = tmp; } @@ -198,7 +198,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch a = get_num (&state); if (a) { int signed_a = atoi (a); - res = r_str_newf ("%d", signed_a); + res = rz_str_newf ("%d", signed_a); free (a); } break; @@ -221,7 +221,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch } sym += ret; *amount_of_read_chars = sym - start_sym + 1; - *str_type_code = r_str_newf ("&%s %s", data_type, str.type_str); + *str_type_code = rz_str_newf ("&%s %s", data_type, str.type_str); return eDemanglerErrOK; } case '2': @@ -230,7 +230,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch b = get_num (&state); if (a && b) { int signed_b = atoi (b); - res = r_str_newf ("%sE%d", a, signed_b); + res = rz_str_newf ("%sE%d", a, signed_b); } free (a); free (b); @@ -239,7 +239,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch // anonymous template param res = get_num (&state); if (res) { - tmp = r_str_newf ("%s%s", template_param, res); + tmp = rz_str_newf ("%s%s", template_param, res); free (res); res = tmp; } @@ -251,7 +251,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch if (a && b) { int signed_a = atoi (a); int signed_b = atoi (b); - res = r_str_newf ("{%d, %d}", signed_a, signed_b); + res = rz_str_newf ("{%d, %d}", signed_a, signed_b); } free (a); free (b); @@ -265,7 +265,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch int signed_a = atoi (a); int signed_b = atoi (b); int signed_c = atoi (c); - res = r_str_newf ("{%d, %d, %d}", signed_a, signed_b, signed_c); + res = rz_str_newf ("{%d, %d, %d}", signed_a, signed_b, signed_c); } free (a); free (b); @@ -280,7 +280,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch a = get_num (&state); b = get_num (&state); if (a && b) { - res = r_str_newf ("{%s, %s}", a, b); + res = rz_str_newf ("{%s, %s}", a, b); } free (a); free (b); @@ -291,7 +291,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch b = get_num (&state); c = get_num (&state); if (a && b && c) { - res = r_str_newf ("{%s, %s, %s}", a, b, c); + res = rz_str_newf ("{%s, %s, %s}", a, b, c); } free (a); free (b); @@ -301,7 +301,7 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch // anonymous non-type template parameter res = get_num (&state); if (res) { - tmp = r_str_newf("non-type-%s%s", template_param, res); + tmp = rz_str_newf("non-type-%s%s", template_param, res); free (res); res = tmp; } @@ -321,14 +321,14 @@ static int get_template_params(const char *sym, size_t *amount_of_read_chars, ch return eDemanglerErrOK; } -static size_t get_operator_code(const char *buf, RList *names_l, bool memorize) { +static size_t get_operator_code(const char *buf, RzList *names_l, bool memorize) { // C++ operator code (one character, or two if the first is '_') #define SET_OPERATOR_CODE(str) { \ str_info = (SStrInfo *) malloc (sizeof(SStrInfo)); \ if (!str_info) break; \ str_info->len = strlen (str); \ str_info->str_ptr = strdup (str); \ - r_list_append (names_l, str_info); \ + rz_list_append (names_l, str_info); \ } SStrInfo *str_info; size_t read_len = 1; @@ -380,7 +380,7 @@ static size_t get_operator_code(const char *buf, RList *names_l, bool memorize) R_FREE (str_info); return 0; } - r_list_append (names_l, str_info); + rz_list_append (names_l, str_info); buf += i; read_len += i; break; @@ -417,13 +417,13 @@ static size_t get_operator_code(const char *buf, RList *names_l, bool memorize) case 'X': SET_OPERATOR_CODE ("placement_new_closure"); break; case 'Y': SET_OPERATOR_CODE ("placement_delete_closure"); break; default: - r_list_free (names_l); + rz_list_free (names_l); return 0; } read_len++; break; default: - r_list_free (names_l); + rz_list_free (names_l); return 0; } read_len++; @@ -436,15 +436,15 @@ static size_t get_template(const char *buf, SStrInfo *str_info, bool memorize) { size_t len = 0; char *str_type_code = NULL; STypeCodeStr type_code_str; - // RListIter *it = NULL; - // RList *saved_abbr_names = abbr_names; // save current abbr names, this + // RzListIter *it = NULL; + // RzList *saved_abbr_names = abbr_names; // save current abbr names, this if (!init_type_code_str_struct(&type_code_str)) { goto get_template_err; } if (*buf == '?') { - RList *names_l = r_list_newf ((RListFree)sstrinfo_free); + RzList *names_l = rz_list_newf ((RzListFree)sstrinfo_free); if (!names_l) { return 0; } @@ -454,9 +454,9 @@ static size_t get_template(const char *buf, SStrInfo *str_info, bool memorize) { } len += i; buf += i; - SStrInfo *name = r_list_head (names_l)->data; + SStrInfo *name = rz_list_head (names_l)->data; copy_string (&type_code_str, name->str_ptr, name->len); - r_list_free (names_l); + rz_list_free (names_l); } else { char *tmp = strchr(buf, '@'); if (!tmp) { @@ -467,7 +467,7 @@ static size_t get_template(const char *buf, SStrInfo *str_info, bool memorize) { len += (tmp - buf + 1); copy_string (&type_code_str, buf, len - 1); if (memorize) { - r_list_append (abbr_names, r_str_ndup (buf, len - 1)); + rz_list_append (abbr_names, rz_str_ndup (buf, len - 1)); } buf += len; } @@ -508,11 +508,11 @@ static size_t get_template(const char *buf, SStrInfo *str_info, bool memorize) { get_template_err: #if 0 - it = r_list_iterator (abbr_names); - r_list_foreach (abbr_names, it, tmp) { + it = rz_list_iterator (abbr_names); + rz_list_foreach (abbr_names, it, tmp) { R_FREE (tmp); } - r_list_free (abbr_names); + rz_list_free (abbr_names); abbr_names = saved_abbr_names; // restore global list with name abbr. #endif @@ -531,13 +531,13 @@ get_template_err: static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_str, size_t *amount_of_names, bool memorize) { const char *curr_pos = NULL, *prev_pos = NULL, *tmp = NULL; - RList /* */ *names_l = NULL; - RListIter *it = NULL; + RzList /* */ *names_l = NULL; + RzListIter *it = NULL; SStrInfo *str_info = NULL; size_t len = 0, read_len = 0, tmp_len = 0; - names_l = r_list_newf ((RListFree)sstrinfo_free); + names_l = rz_list_newf ((RzListFree)sstrinfo_free); if (*buf == '?') { size_t res = get_operator_code (buf, names_l, memorize); @@ -581,7 +581,7 @@ static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_st R_FREE (str_info); goto get_namespace_and_name_err; } - r_list_append (names_l, str_info); + rz_list_append (names_l, str_info); prev_pos = tmp + i + 2; curr_pos = strchr (prev_pos, '@'); @@ -592,7 +592,7 @@ static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_st } if (isdigit ((ut8)*tmp)) { - tmp = r_list_get_n (abbr_names, *tmp - '0'); + tmp = rz_list_get_n (abbr_names, *tmp - '0'); if (!tmp) { goto get_namespace_and_name_err; } @@ -601,7 +601,7 @@ static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_st char *tmpname = (char *)malloc (len + 1); memset (tmpname, 0, len + 1); memcpy (tmpname, prev_pos, len); - r_list_append (abbr_names, tmpname); + rz_list_append (abbr_names, tmpname); tmp = tmpname; } @@ -609,7 +609,7 @@ static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_st str_info->str_ptr = strdup (tmp); str_info->len = strlen (tmp); - r_list_append (names_l, str_info); + rz_list_append (names_l, str_info); read_len += len; if (len == 1) { @@ -628,19 +628,19 @@ static size_t get_namespace_and_name(const char *buf, STypeCodeStr *type_code_st } get_namespace_and_name_err: - tmp_len = r_list_length (names_l); + tmp_len = rz_list_length (names_l); if (amount_of_names) { *amount_of_names = tmp_len; } - it = r_list_iterator (names_l); - r_list_foreach_prev (names_l, it, str_info) { + it = rz_list_iterator (names_l); + rz_list_foreach_prev (names_l, it, str_info) { copy_string (type_code_str, str_info->str_ptr, str_info->len); if (--tmp_len) { copy_string (type_code_str, "::", 0); } } - r_list_free (names_l); + rz_list_free (names_l); return read_len; } @@ -1103,7 +1103,7 @@ DEF_STATE_ACTION(P) // abbreviation of type processing if ((*state->buff_for_parsing >= '0') && (*state->buff_for_parsing <= '9')) { ut32 id = (ut32)(*state->buff_for_parsing - '0'); - arg = r_list_get_n (abbr_types, id); + arg = rz_list_get_n (abbr_types, id); if (!arg) { state->err = eTCStateMachineErrUncorrectTypeCode; goto FUNCTION_POINTER_err; @@ -1117,7 +1117,7 @@ DEF_STATE_ACTION(P) } if (i > 1) { - r_list_append (abbr_types, strdup (arg)); + rz_list_append (abbr_types, strdup (arg)); } copy_string (type_code_str, arg, 0); @@ -1370,14 +1370,14 @@ static EDemanglerErr parse_data_type(const char *sym, char **data_type, char **a if (!storage_class) { *data_type = tmp; } else { - *data_type = r_str_newf ("%s %s", tmp, storage_class); + *data_type = rz_str_newf ("%s %s", tmp, storage_class); free (tmp); } } else { if (!storage_class) { - *data_type = r_str_newf ("%s %s", tmp, ptr64); + *data_type = rz_str_newf ("%s %s", tmp, ptr64); } else { - *data_type = r_str_newf ("%s %s %s", tmp, storage_class, ptr64); + *data_type = rz_str_newf ("%s %s %s", tmp, storage_class, ptr64); } free (tmp); } @@ -1448,8 +1448,8 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang const char *storage_class_code_for_ret = NULL; char *ret_type = NULL; const char *__64ptr = NULL; - RList /* */ *func_args = NULL; - RListIter *it = NULL; + RzList /* */ *func_args = NULL; + RzListIter *it = NULL; SStrInfo *str_arg = NULL; char *access_modifier = NULL; char *data_type = NULL; @@ -1495,7 +1495,7 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang curr_pos += len; if (data_type) { - *demangled_name = r_str_newf ("%s %s", data_type, type_code_str.type_str); + *demangled_name = rz_str_newf ("%s %s", data_type, type_code_str.type_str); goto parse_microsoft_mangled_name_err; } @@ -1570,7 +1570,7 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang curr_pos += i; } - func_args = r_list_new (); + func_args = rz_list_new (); // Function arguments while (*curr_pos && *curr_pos != 'Z') @@ -1580,7 +1580,7 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang if (err != eDemanglerErrOK) { // abbreviation of type processing if ((*curr_pos >= '0') && (*curr_pos <= '9')) { - tmp = r_list_get_n (abbr_types, (ut32)(*curr_pos - '0')); + tmp = rz_list_get_n (abbr_types, (ut32)(*curr_pos - '0')); if (!tmp) { err = eDemanglerErrUncorrectMangledSymbol; goto parse_microsoft_mangled_name_err; @@ -1595,14 +1595,14 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang curr_pos += i; if (i > 1) { - r_list_append (abbr_types, strdup (tmp)); + rz_list_append (abbr_types, strdup (tmp)); } str_arg = (SStrInfo *) malloc (sizeof(SStrInfo)); str_arg->str_ptr = strdup (tmp); str_arg->len = strlen (tmp); - r_list_append (func_args, str_arg); + rz_list_append (func_args, str_arg); if (strncmp (tmp, "void", 4) == 0 && strlen (tmp) == 4) { // arguments list is void @@ -1656,10 +1656,10 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang copy_string (&func_str, type_code_str.type_str, type_code_str.curr_pos); } - if (r_list_length (func_args)) { + if (rz_list_length (func_args)) { copy_string (&func_str, "(", 0); - i = r_list_length (func_args); - r_list_foreach (func_args, it, str_arg) { + i = rz_list_length (func_args); + rz_list_foreach (func_args, it, str_arg) { copy_string (&func_str, str_arg->str_ptr, 0); if (--i) { copy_string (&func_str, ", ", 0); @@ -1681,7 +1681,7 @@ static EDemanglerErr parse_microsoft_mangled_name(const char *sym, char **demang if (ret_type) { if (strstr (func_str.type_str, "#{return_type}")) { - func_str.type_str = r_str_replace (func_str.type_str, "#{return_type}", ret_type, 0); + func_str.type_str = rz_str_replace (func_str.type_str, "#{return_type}", ret_type, 0); func_str.curr_pos -= strlen ("#{return_type}") - strlen (ret_type); } } @@ -1696,7 +1696,7 @@ parse_microsoft_mangled_name_err: // R_FREE (tmp); free_type_code_str_struct (&type_code_str); free_type_code_str_struct (&func_str); - r_list_free (func_args); + rz_list_free (func_args); return err; } @@ -1727,7 +1727,7 @@ static EDemanglerErr parse_microsoft_rtti_mangled_name(const char *sym, char **d goto parse_microsoft_rtti_mangled_name_err; } - *demangled_name = r_str_newf ("%s %s", type, type_code_str.type_str); + *demangled_name = rz_str_newf ("%s %s", type, type_code_str.type_str); free (type_code_str.type_str); parse_microsoft_rtti_mangled_name_err: @@ -1737,12 +1737,12 @@ parse_microsoft_rtti_mangled_name_err: /////////////////////////////////////////////////////////////////////////////// EDemanglerErr microsoft_demangle(SDemangler *demangler, char **demangled_name) { EDemanglerErr err = eDemanglerErrOK; -// RListIter *it = NULL; +// RzListIter *it = NULL; // char *tmp = NULL; // TODO: need refactor... maybe remove the static variable somewhere? - abbr_types = r_list_newf (free); - abbr_names = r_list_newf (free); + abbr_types = rz_list_newf (free); + abbr_names = rz_list_newf (free); if (!demangler || !demangled_name) { err = eDemanglerErrMemoryAllocation; @@ -1756,8 +1756,8 @@ EDemanglerErr microsoft_demangle(SDemangler *demangler, char **demangled_name) { } microsoft_demangle_err: - r_list_free (abbr_names); - r_list_free (abbr_types); + rz_list_free (abbr_names); + rz_list_free (abbr_types); return err; } diff --git a/libr/bin/mangling/microsoft_demangle.h b/librz/bin/mangling/microsoft_demangle.h similarity index 100% rename from libr/bin/mangling/microsoft_demangle.h rename to librz/bin/mangling/microsoft_demangle.h diff --git a/libr/bin/mangling/msvc.c b/librz/bin/mangling/msvc.c similarity index 82% rename from libr/bin/mangling/msvc.c rename to librz/bin/mangling/msvc.c index 41fd1e85dc..9ad3767b8d 100644 --- a/libr/bin/mangling/msvc.c +++ b/librz/bin/mangling/msvc.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2015-2018 - inisider */ -#include +#include #include "./demangler.h" -R_API char *r_bin_demangle_msvc(const char *str) { +RZ_API char *rz_bin_demangle_msvc(const char *str) { char *out = NULL; SDemangler *mangler = 0; diff --git a/libr/bin/mangling/objc.c b/librz/bin/mangling/objc.c similarity index 78% rename from libr/bin/mangling/objc.c rename to librz/bin/mangling/objc.c index 2e477d85b1..ccdbae271a 100644 --- a/libr/bin/mangling/objc.c +++ b/librz/bin/mangling/objc.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2012-2019 - pancake */ -#include +#include #include "../i/private.h" -R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) { - r_return_val_if_fail ((!bf || (bf && bf->o && bf->o->classes)) && sym, NULL); +RZ_API char *rz_bin_demangle_objc(RBinFile *bf, const char *sym) { + rz_return_val_if_fail ((!bf || (bf && bf->o && bf->o->classes)) && sym, NULL); char *ret = NULL; char *clas = NULL; char *name = NULL; @@ -18,17 +18,17 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) { /* classes */ if (!strncmp (sym, "_OBJC_Class_", 12)) { const char *className = sym + 12; - ret = r_str_newf ("class %s", className); + ret = rz_str_newf ("class %s", className); if (bf) { - r_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC); + rz_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC); } return ret; } if (!strncmp (sym, "_OBJC_CLASS_$_", 14)) { const char *className = sym + 14; - ret = r_str_newf ("class %s", className); + ret = rz_str_newf ("class %s", className); if (bf) { - r_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC); + rz_bin_file_add_class (bf, className, NULL, R_BIN_CLASS_PUBLIC); } return ret; } @@ -44,7 +44,7 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) { name = NULL; } if (bf) { - r_bin_file_add_field (bf, clas, name); + rz_bin_file_add_field (bf, clas, name); } } /* methods */ @@ -110,7 +110,7 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) { } if (type) { if (!strcmp (type, "field")) { - ret = r_str_newf ("field int %s::%s", clas, name); + ret = rz_str_newf ("field int %s::%s", clas, name); } else { if (nargs) { const char *arg = "int"; @@ -126,9 +126,9 @@ R_API char *r_bin_demangle_objc(RBinFile *bf, const char *sym) { args = strdup (""); } if (type && name && *name) { - ret = r_str_newf ("%s int %s::%s(%s)", type, clas, name, args); + ret = rz_str_newf ("%s int %s::%s(%s)", type, clas, name, args); if (bf) { - r_bin_file_add_method (bf, clas, name, nargs); + rz_bin_file_add_method (bf, clas, name, nargs); } } } diff --git a/libr/bin/mangling/rust.c b/librz/bin/mangling/rust.c similarity index 89% rename from libr/bin/mangling/rust.c rename to librz/bin/mangling/rust.c index c43718ac56..b3e8f64b60 100644 --- a/libr/bin/mangling/rust.c +++ b/librz/bin/mangling/rust.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2011-2018 - pancake */ -#include +#include #define RS(from, to) (replace_seq ((const char **)&in, &out, (const char *)(from), to)) @@ -19,11 +19,11 @@ static bool replace_seq (const char **in, char **out, const char *seq, char valu return true; } -R_API char *r_bin_demangle_rust (RBinFile *binfile, const char *sym, ut64 vaddr) { +RZ_API char *rz_bin_demangle_rust (RBinFile *binfile, const char *sym, ut64 vaddr) { int len; char *str, *out, *in; - str = r_bin_demangle_cxx (binfile, sym, vaddr); + str = rz_bin_demangle_cxx (binfile, sym, vaddr); if (!str) { return str; diff --git a/libr/bin/mangling/swift-sd.c b/librz/bin/mangling/swift-sd.c similarity index 96% rename from libr/bin/mangling/swift-sd.c rename to librz/bin/mangling/swift-sd.c index 029523da86..30858dbae9 100644 --- a/libr/bin/mangling/swift-sd.c +++ b/librz/bin/mangling/swift-sd.c @@ -4,10 +4,10 @@ #include #include -#include -#include +#include +#include #include -#include +#include #ifndef HAS_MAIN #define HAS_MAIN 0 @@ -125,13 +125,13 @@ static char *swift_demangle_cmd(const char *s) { if (have_swift_demangle == -1) { if (!swift_demangle) { have_swift_demangle = 0; - swift_demangle = r_file_path ("swift-demangle"); + swift_demangle = rz_file_path ("swift-demangle"); if (!swift_demangle || !strcmp (swift_demangle, "swift-demangle")) { - char *xcrun = r_file_path ("xcrun"); + char *xcrun = rz_file_path ("xcrun"); if (xcrun) { if (strcmp (xcrun, "xcrun")) { free (swift_demangle); - swift_demangle = r_str_newf ("%s swift-demangle", xcrun); + swift_demangle = rz_str_newf ("%s swift-demangle", xcrun); have_swift_demangle = 1; } free (xcrun); @@ -144,14 +144,14 @@ static char *swift_demangle_cmd(const char *s) { /* nice try */ return NULL; } - //char *res = r_sys_cmd_strf ("%s -compact -simplified '%s'", - char *res = r_sys_cmd_strf ("%s -compact '%s'", + //char *res = rz_sys_cmd_strf ("%s -compact -simplified '%s'", + char *res = rz_sys_cmd_strf ("%s -compact '%s'", swift_demangle, s); if (res && !*res) { free (res); res = NULL; } - r_str_trim (res); + rz_str_trim (res); return res; } return NULL; @@ -162,9 +162,9 @@ static char *swift_demangle_lib(const char *s) { static bool haveSwiftCore = false; static char *(*swift_demangle)(const char *sym, int symlen, void *out, int *outlen, int flags) = NULL; if (!haveSwiftCore) { - void *lib = r_lib_dl_open ("/usr/lib/swift/libswiftCore.dylib"); + void *lib = rz_lib_dl_open ("/usr/lib/swift/libswiftCore.dylib"); if (lib) { - swift_demangle = r_lib_dl_sym (lib, "swift_demangle"); + swift_demangle = rz_lib_dl_sym (lib, "swift_demangle"); } haveSwiftCore = true; } @@ -175,7 +175,7 @@ static char *swift_demangle_lib(const char *s) { return NULL; } -R_API char *r_bin_demangle_swift(const char *s, bool syscmd) { +RZ_API char *rz_bin_demangle_swift(const char *s, bool syscmd) { #define STRCAT_BOUNDS(x) if (((x) + 2 + strlen (out)) > sizeof (out)) break; char out[1024]; int i, len, is_generic = 0; @@ -723,7 +723,7 @@ int main(int argc, char **argv) { int rc = 0; char *ret; if (argc > 1) { - ret = r_bin_demangle_swift (argv[1], 0); + ret = rz_bin_demangle_swift (argv[1], 0); if (ret) { printf ("%s\n", ret); free (ret); @@ -733,7 +733,7 @@ int main(int argc, char **argv) { for (i = 0; swift_tests[i].sym; i++) { Test *test = &swift_tests[i]; printf ("[>>] %s\n", test->sym); - ret = r_bin_demangle_swift (test->sym, 0); + ret = rz_bin_demangle_swift (test->sym, 0); if (ret) { if (test->dem && !strcmp (ret, test->dem)) { printf (Color_GREEN"[OK]"Color_RESET" %s\n", ret); diff --git a/libr/bin/mangling/swift.c b/librz/bin/mangling/swift.c similarity index 68% rename from libr/bin/mangling/swift.c rename to librz/bin/mangling/swift.c index ddf2da6759..a173addcaf 100644 --- a/libr/bin/mangling/swift.c +++ b/librz/bin/mangling/swift.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2013-2016 - pancake */ -#include +#include -R_IPI bool r_bin_lang_swift(RBinFile *binfile) { +R_IPI bool rz_bin_lang_swift(RBinFile *binfile) { RBinObject *o = binfile? binfile->o: NULL; RBinInfo *info = o? o->info: NULL; RBinSymbol *sym; - RListIter *iter; + RzListIter *iter; if (info) { - r_list_foreach (o->symbols, iter, sym) { + rz_list_foreach (o->symbols, iter, sym) { if (sym->name && strstr (sym->name, "swift_once")) { info->lang = "swift"; return true; diff --git a/libr/bin/meson.build b/librz/bin/meson.build similarity index 82% rename from libr/bin/meson.build rename to librz/bin/meson.build index 1012f37df7..728b4f9614 100644 --- a/libr/bin/meson.build +++ b/librz/bin/meson.build @@ -1,4 +1,4 @@ -r_bin_sources = [ +rz_bin_sources = [ 'bin.c', 'bin_write.c', 'dbginfo.c', @@ -90,7 +90,7 @@ r_bin_sources = [ 'format/mach0/fatmach0.c', 'format/mach0/mach0.c', 'format/mach0/mach064.c', - 'format/xnu/r_cf_dict.c', + 'format/xnu/rz_cf_dict.c', 'format/mdmp/mdmp.c', 'format/mdmp/mdmp_pe.c', 'format/mdmp/mdmp_pe64.c', @@ -136,18 +136,18 @@ r_bin_sources = [ 'pdb/tpi.c' ] -r_bin_inc = [platform_inc, yxml_inc, include_directories('mangling', 'format')] +rz_bin_inc = [platform_inc, yxml_inc, include_directories('mangling', 'format')] -r_bin = library('r_bin', r_bin_sources, - include_directories: r_bin_inc, - c_args: ['-DR_API_BIN_ONLY=1'] + library_cflags, +rz_bin = library('rz_bin', rz_bin_sources, + include_directories: rz_bin_inc, + c_args: ['-DRZ_API_BIN_ONLY=1'] + library_cflags, dependencies: [ - r_util_dep, - r_io_dep, - r_hash_dep, - r_magic_dep, - r_socket_dep, - r_syscall_dep, + rz_util_dep, + rz_io_dep, + rz_hash_dep, + rz_magic_dep, + rz_socket_dep, + rz_syscall_dep, java_dep, lz4_dep, yxml_dep @@ -158,20 +158,20 @@ r_bin = library('r_bin', r_bin_sources, soversion: r2_libversion ) -r_bin_dep = declare_dependency(link_with: r_bin, - include_directories: r_bin_inc) +rz_bin_dep = declare_dependency(link_with: rz_bin, + include_directories: rz_bin_inc) -pkgconfig_mod.generate(r_bin, - subdirs: 'libr', +pkgconfig_mod.generate(rz_bin, + subdirs: 'librz', version: r2_version, - name: 'r_bin', - filebase: 'r_bin', + name: 'rz_bin', + filebase: 'rz_bin', libraries: pkgcfg_sanitize_libs, requires: pkgconfig_magic_requires + [ - 'r_util', - 'r_io', - 'r_socket', - 'r_syscall' + 'rz_util', + 'rz_io', + 'rz_socket', + 'rz_syscall' ], description: 'radare foundation libraries' ) diff --git a/libr/bin/p/Makefile b/librz/bin/p/Makefile similarity index 77% rename from libr/bin/p/Makefile rename to librz/bin/p/Makefile index b9014844fb..718dc6cc7d 100644 --- a/libr/bin/p/Makefile +++ b/librz/bin/p/Makefile @@ -3,13 +3,13 @@ include ../../../mk/platform.mk CFLAGS+=-I$(LTOP)/include -I$(LTOP)/bin/format/ -Wall $(PIC_CFLAGS) ifeq ($(CC),cccl) -LDFLAGS+=-L$(LTOP)/util -llibr_util -LDFLAGS+=-L$(LTOP)/bin -llibr_bin -LDFLAGS+=-L$(LTOP)/io -llibr_io +LDFLAGS+=-L$(LTOP)/util -llibrz_util +LDFLAGS+=-L$(LTOP)/bin -llibrz_bin +LDFLAGS+=-L$(LTOP)/io -llibrz_io else -LDFLAGS+=-L$(LTOP)/util -lr_util -LDFLAGS+=-L$(LTOP)/bin -lr_bin -LDFLAGS+=-L$(LTOP)/io -lr_io +LDFLAGS+=-L$(LTOP)/util -lrz_util +LDFLAGS+=-L$(LTOP)/bin -lrz_bin +LDFLAGS+=-L$(LTOP)/io -lrz_io endif SHLR=$(LTOP)/../shlr @@ -34,7 +34,7 @@ clean: -rm -f *.so *.o ${STATIC_OBJ} mrproper: clean - -rm -f *.d $(TOP)/libr/bin/format/*/*.d + -rm -f *.d $(TOP)/librz/bin/format/*/*.d .PHONY: all clean mrproper else diff --git a/libr/bin/p/any.mk b/librz/bin/p/any.mk similarity index 76% rename from libr/bin/p/any.mk rename to librz/bin/p/any.mk index 220e9aa7b9..ae691df397 100644 --- a/libr/bin/p/any.mk +++ b/librz/bin/p/any.mk @@ -10,10 +10,10 @@ include $(SHLR)/zip/deps.mk ${TARGET_ANY}: ${OBJ_ANY} ifeq ($(CC),cccl) ${CC} $(call libname,bin_any) $(DL_LIBS) ${CFLAGS} $(OBJ_ANY) $(LINK) $(LDFLAGS) \ - -L../../magic -llibr_magic \ - -L../../util -llibr_util + -L../../magic -llibrz_magic \ + -L../../util -llibrz_util else ${CC} $(call libname,bin_any) $(DL_LIBS) ${CFLAGS} $(OBJ_ANY) $(LINK) $(LDFLAGS) \ - -L../../magic -lr_magic \ - -L../../util -lr_util + -L../../magic -lrz_magic \ + -L../../util -lrz_util endif diff --git a/libr/bin/p/art.mk b/librz/bin/p/art.mk similarity index 100% rename from libr/bin/p/art.mk rename to librz/bin/p/art.mk diff --git a/libr/bin/p/avr.mk b/librz/bin/p/avr.mk similarity index 100% rename from libr/bin/p/avr.mk rename to librz/bin/p/avr.mk diff --git a/libr/bin/p/bf.mk b/librz/bin/p/bf.mk similarity index 100% rename from libr/bin/p/bf.mk rename to librz/bin/p/bf.mk diff --git a/libr/bin/p/bflt.mk b/librz/bin/p/bflt.mk similarity index 100% rename from libr/bin/p/bflt.mk rename to librz/bin/p/bflt.mk diff --git a/libr/bin/p/bin_any.c b/librz/bin/p/bin_any.c similarity index 72% rename from libr/bin/p/bin_any.c rename to librz/bin/p/bin_any.c index 5e38a08f9a..55f0fcd881 100644 --- a/libr/bin/p/bin_any.c +++ b/librz/bin/p/bin_any.c @@ -1,27 +1,27 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static char *get_filetype(RBuffer *b) { ut8 buf[4096] = { 0 }; char *res = NULL; - RMagic *ck = r_magic_new (0); + RzMagic *ck = rz_magic_new (0); if (!ck) { return NULL; } const char *tmp = NULL; // TODO: dir.magic not honored here - r_magic_load (ck, R2_SDB_MAGIC); - r_buf_read_at (b, 0, buf, sizeof (buf)); - tmp = r_magic_buffer (ck, buf, sizeof (buf)); + rz_magic_load (ck, R2_SDB_MAGIC); + rz_buf_read_at (b, 0, buf, sizeof (buf)); + tmp = rz_magic_buffer (ck, buf, sizeof (buf)); if (tmp) { res = strdup (tmp); } - r_magic_free (ck); + rz_magic_free (ck); return res; } @@ -55,16 +55,16 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy(RBinFile *bf) { - r_buf_free (bf->o->bin_obj); + rz_buf_free (bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { return 0LL; } -RBinPlugin r_bin_plugin_any = { +RBinPlugin rz_bin_plugin_any = { .name = "any", - .desc = "Dummy format r_bin plugin", + .desc = "Dummy format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .destroy = &destroy, @@ -74,9 +74,9 @@ RBinPlugin r_bin_plugin_any = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_any, + .data = &rz_bin_plugin_any, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_art.c b/librz/bin/p/bin_art.c similarity index 84% rename from libr/bin/p/bin_art.c rename to librz/bin/p/bin_art.c index 6656839518..a652f87605 100644 --- a/libr/bin/p/bin_art.c +++ b/librz/bin/p/bin_art.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2015-2018 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #ifdef _MSC_VER typedef struct art_header_t { @@ -36,11 +36,11 @@ typedef struct { static int art_header_load(ArtObj *ao, Sdb *db) { /* TODO: handle read errors here */ - if (r_buf_size (ao->buf) < sizeof (ARTHeader)) { + if (rz_buf_size (ao->buf) < sizeof (ARTHeader)) { return false; } ARTHeader *art = &ao->art; - (void) r_buf_fread_at (ao->buf, 0, (ut8 *) art, "IIiiiiiiiiiiii", 1); + (void) rz_buf_fread_at (ao->buf, 0, (ut8 *) art, "IIiiiiiiiiiiii", 1); sdb_set (db, "img.base", sdb_fmt ("0x%x", art->image_base), 0); sdb_set (db, "img.size", sdb_fmt ("0x%x", art->image_size), 0); sdb_set (db, "art.checksum", sdb_fmt ("0x%x", art->checksum), 0); @@ -73,7 +73,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd free (ao); return false; } - ao->buf = r_buf_ref (buf); + ao->buf = rz_buf_ref (buf); art_header_load (ao, ao->kv); sdb_ns_set (sdb, "info", ao->kv); *bin_obj = ao; @@ -84,7 +84,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd static void destroy(RBinFile *bf) { ArtObj *obj = bf->o->bin_obj; - r_buf_free (obj->buf); + rz_buf_free (obj->buf); free (obj); } @@ -93,12 +93,12 @@ static ut64 baddr(RBinFile *bf) { return ao? ao->art.image_base: 0; } -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } static RBinInfo *info(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) { return NULL; @@ -128,32 +128,32 @@ static RBinInfo *info(RBinFile *bf) { static bool check_buffer(RBuffer *buf) { char tmp[4]; - int r = r_buf_read_at (buf, 0, (ut8 *)tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, (ut8 *)tmp, sizeof (tmp)); return r == 4 && !strncmp (tmp, "art\n", 4); } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_newf (free); if (ret) { RBinAddr *ptr = R_NEW0 (RBinAddr); if (ptr) { ptr->paddr = ptr->vaddr = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } return ret; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { ArtObj *ao = bf->o->bin_obj; if (!ao) { return NULL; } ARTHeader art = ao->art; - RList *ret = NULL; + RzList *ret = NULL; RBinSection *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -162,13 +162,13 @@ static RList *sections(RBinFile *bf) { return ret; } ptr->name = strdup ("load"); - ptr->size = r_buf_size (bf->buf); + ptr->size = rz_buf_size (bf->buf); ptr->vsize = art.image_size; // TODO: align? ptr->paddr = 0; ptr->vaddr = art.image_base; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -180,7 +180,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = art.image_base + art.bitmap_offset; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -192,7 +192,7 @@ static RList *sections(RBinFile *bf) { ptr->vsize = ptr->size; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -204,12 +204,12 @@ static RList *sections(RBinFile *bf) { ptr->vsize = ptr->size; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -RBinPlugin r_bin_plugin_art = { +RBinPlugin rz_bin_plugin_art = { .name = "art", .desc = "Android Runtime", .license = "LGPL3", @@ -225,9 +225,9 @@ RBinPlugin r_bin_plugin_art = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_art, + .data = &rz_bin_plugin_art, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_avr.c b/librz/bin/p/bin_avr.c similarity index 72% rename from libr/bin/p/bin_avr.c rename to librz/bin/p/bin_avr.c index aa12d1bc8d..40ca8cc665 100644 --- a/libr/bin/p/bin_avr.c +++ b/librz/bin/p/bin_avr.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016-2017 - pancake */ -#include -#include +#include +#include #define CHECK4INSTR(b, instr, size) \ if (!instr (b, 0) || \ @@ -21,27 +21,27 @@ static ut64 tmp_entry = UT64_MAX; static bool rjmp(RBuffer* b, ut64 addr) { - return (r_buf_read8_at (b, addr + 1) & 0xf0) == 0xc0; + return (rz_buf_read8_at (b, addr + 1) & 0xf0) == 0xc0; } static bool jmp(RBuffer* b, ut64 addr) { - return (r_buf_read8_at (b, addr) == 0x0c) && (r_buf_read8_at (b, addr + 1) == 0x94); + return (rz_buf_read8_at (b, addr) == 0x0c) && (rz_buf_read8_at (b, addr + 1) == 0x94); } static ut64 rjmp_dest(ut64 addr, RBuffer* b) { - ut64 dst = 2 + addr + r_buf_read8_at (b, addr) * 2; - dst += ((r_buf_read8_at (b, addr + 1) & 0xf) * 2) << 8; + ut64 dst = 2 + addr + rz_buf_read8_at (b, addr) * 2; + dst += ((rz_buf_read8_at (b, addr + 1) & 0xf) * 2) << 8; return dst; } static ut64 jmp_dest(RBuffer* b, ut64 addr) { - return (r_buf_read8_at (b, addr + 2) + (r_buf_read8_at (b, addr + 3) << 8)) * 2; + return (rz_buf_read8_at (b, addr + 2) + (rz_buf_read8_at (b, addr + 3) << 8)) * 2; } static bool check_buffer_rjmp(RBuffer *b) { CHECK3INSTR (b, rjmp, 4); ut64 dst = rjmp_dest (0, b); - if (dst < 1 || dst > r_buf_size (b)) { + if (dst < 1 || dst > rz_buf_size (b)) { return false; } tmp_entry = dst; @@ -52,7 +52,7 @@ static bool check_buffer_rjmp(RBuffer *b) { static bool check_buffer_jmp(RBuffer *b) { CHECK4INSTR (b, jmp, 4); ut64 dst = jmp_dest (b, 0); - if (dst < 1 || dst > r_buf_size (b)) { + if (dst < 1 || dst > rz_buf_size (b)) { return false; } tmp_entry = dst; @@ -60,7 +60,7 @@ static bool check_buffer_jmp(RBuffer *b) { } static bool check_buffer(RBuffer *buf) { - if (r_buf_size (buf) < 32) { + if (rz_buf_size (buf) < 32) { return false; } if (!rjmp (buf, 0)) { @@ -74,11 +74,11 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy(RBinFile *bf) { - r_buf_free (bf->o->bin_obj); + rz_buf_free (bf->o->bin_obj); } static RBinInfo* info(RBinFile *bf) { - r_return_val_if_fail (bf, NULL); + rz_return_val_if_fail (bf, NULL); RBinInfo *bi = R_NEW0 (RBinInfo); if (bi) { bi->file = strdup (bf->file); @@ -93,36 +93,36 @@ static RBinInfo* info(RBinFile *bf) { return bi; } -static RList* entries(RBinFile *bf) { - RList *ret; +static RzList* entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; if (tmp_entry == UT64_MAX) { return false; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if ((ptr = R_NEW0 (RBinAddr))) { ut64 addr = tmp_entry; ptr->vaddr = ptr->paddr = addr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static void addsym(RList *ret, const char *name, ut64 addr) { +static void addsym(RzList *ret, const char *name, ut64 addr) { RBinSymbol *ptr = R_NEW0 (RBinSymbol); if (ptr) { ptr->name = strdup (name? name: ""); ptr->paddr = ptr->vaddr = addr; ptr->size = 0; ptr->ordinal = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } -static void addptr(RList *ret, const char *name, ut64 addr, RBuffer *b) { +static void addptr(RzList *ret, const char *name, ut64 addr, RBuffer *b) { if (b && rjmp (b, 0)) { addsym (ret, sdb_fmt ("vector.%s", name), addr); ut64 ptr_addr = rjmp_dest (addr, b); @@ -130,11 +130,11 @@ static void addptr(RList *ret, const char *name, ut64 addr, RBuffer *b) { } } -static RList *symbols(RBinFile *bf) { - RList *ret = NULL; +static RzList *symbols(RBinFile *bf) { + RzList *ret = NULL; RBuffer *obj = bf->o->bin_obj; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } /* atmega8 */ @@ -147,12 +147,12 @@ static RList *symbols(RBinFile *bf) { return ret; } -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { // we dont want to find strings in avr bins because there are lot of false positives return NULL; } -RBinPlugin r_bin_plugin_avr = { +RBinPlugin rz_bin_plugin_avr = { .name = "avr", .desc = "ATmel AVR MCUs", .license = "LGPL3", @@ -166,9 +166,9 @@ RBinPlugin r_bin_plugin_avr = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_avr, + .data = &rz_bin_plugin_avr, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_bf.c b/librz/bin/p/bin_bf.c similarity index 82% rename from libr/bin/p/bin_bf.c rename to librz/bin/p/bin_bf.c index 30e3e5c04f..99510d3c10 100644 --- a/libr/bin/p/bin_bf.c +++ b/librz/bin/p/bin_bf.c @@ -1,23 +1,23 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { return true; } static void destroy(RBinFile *bf) { - r_buf_free (bf->o->bin_obj); + rz_buf_free (bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { return 0; } -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } @@ -61,10 +61,10 @@ static RBinInfo *info(RBinFile *bf) { } static bool check_buffer(RBuffer *buf) { - r_return_val_if_fail (buf, false); + rz_return_val_if_fail (buf, false); ut8 tmp[16]; - int read_length = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int read_length = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); if (read_length <= 0) { return false; } @@ -92,22 +92,22 @@ static bool check_buffer(RBuffer *buf) { return true; } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } if (!(ptr = R_NEW0 (RBinAddr))) { return ret; } ptr->paddr = ptr->vaddr = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -RBinPlugin r_bin_plugin_bf = { +RBinPlugin rz_bin_plugin_bf = { .name = "bf", .desc = "brainfuck", .license = "LGPL3", @@ -121,9 +121,9 @@ RBinPlugin r_bin_plugin_bf = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_bf, + .data = &rz_bin_plugin_bf, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_bflt.c b/librz/bin/p/bin_bflt.c similarity index 78% rename from libr/bin/p/bin_bflt.c rename to librz/bin/p/bin_bflt.c index 7f76e1ff9b..1a0ba2a977 100644 --- a/libr/bin/p/bin_bflt.c +++ b/librz/bin/p/bin_bflt.c @@ -1,31 +1,31 @@ /* radare - LGPL - Copyright 2016-2019 - Oscar Salvador */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "bflt/bflt.h" static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - *bin_obj = r_bin_bflt_new_buf (buf); + *bin_obj = rz_bin_bflt_new_buf (buf); return *bin_obj; } -static RList *entries(RBinFile *bf) { - struct r_bin_bflt_obj *obj = (struct r_bin_bflt_obj *) bf->o->bin_obj; - RList *ret; +static RzList *entries(RBinFile *bf) { + struct rz_bin_bflt_obj *obj = (struct rz_bin_bflt_obj *) bf->o->bin_obj; + RzList *ret; RBinAddr *ptr; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - ptr = r_bflt_get_entry (obj); + ptr = rz_bflt_get_entry (obj); if (!ptr) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } @@ -33,8 +33,8 @@ static void __patch_reloc(RBuffer *buf, ut32 addr_to_patch, ut32 data_offset) { ut8 val[4] = { 0 }; - r_write_le32 (val, data_offset); - r_buf_write_at (buf, addr_to_patch, (void *) val, sizeof (val)); + rz_write_le32 (val, data_offset); + rz_buf_write_at (buf, addr_to_patch, (void *) val, sizeof (val)); } static int search_old_relocation(struct reloc_struct_t *reloc_table, @@ -48,9 +48,9 @@ static int search_old_relocation(struct reloc_struct_t *reloc_table, return -1; } -static RList *patch_relocs(RBin *b) { - struct r_bin_bflt_obj *bin = NULL; - RList *list = NULL; +static RzList *patch_relocs(RBin *b) { + struct rz_bin_bflt_obj *bin = NULL; + RzList *list = NULL; RBinObject *obj; int i = 0; if (!b || !b->iob.io || !b->iob.io->desc) { @@ -63,12 +63,12 @@ static RList *patch_relocs(RBin *b) { return NULL; } - obj = r_bin_cur_object (b); + obj = rz_bin_cur_object (b); if (!obj) { return NULL; } bin = obj->bin_obj; - list = r_list_newf ((RListFree) free); + list = rz_list_newf ((RzListFree) free); if (!list) { return NULL; } @@ -82,7 +82,7 @@ static RList *patch_relocs(RBin *b) { reloc->type = R_BIN_RELOC_32; reloc->paddr = got_table[i].addr_to_patch; reloc->vaddr = reloc->paddr; - r_list_append (list, reloc); + rz_list_append (list, reloc); } } R_FREE (bin->got_table); @@ -106,18 +106,18 @@ static RList *patch_relocs(RBin *b) { reloc->type = R_BIN_RELOC_32; reloc->paddr = reloc_table[i].addr_to_patch; reloc->vaddr = reloc->paddr; - r_list_append (list, reloc); + rz_list_append (list, reloc); } } R_FREE (bin->reloc_table); } ut64 tmpsz; - const ut8 *tmp = r_buf_data (bin->b, &tmpsz); + const ut8 *tmp = rz_buf_data (bin->b, &tmpsz); b->iob.write_at (b->iob.io, 0, tmp, tmpsz); return list; } -static ut32 get_ngot_entries(struct r_bin_bflt_obj *obj) { +static ut32 get_ngot_entries(struct rz_bin_bflt_obj *obj) { ut32 data_size = obj->hdr->data_end - obj->hdr->data_start; ut32 i = 0, n_got = 0; if (data_size > obj->size) { @@ -129,7 +129,7 @@ static ut32 get_ngot_entries(struct r_bin_bflt_obj *obj) { offset + i + sizeof (ut32) < offset) { return 0; } - int len = r_buf_read_at (obj->b, offset + i, (ut8 *) &entry, + int len = rz_buf_read_at (obj->b, offset + i, (ut8 *) &entry, sizeof (ut32)); if (len != sizeof (ut32)) { return 0; @@ -141,12 +141,12 @@ static ut32 get_ngot_entries(struct r_bin_bflt_obj *obj) { return n_got; } -static RList *relocs(RBinFile *bf) { - struct r_bin_bflt_obj *obj = (struct r_bin_bflt_obj *) bf->o->bin_obj; - RList *list = r_list_newf ((RListFree) free); +static RzList *relocs(RBinFile *bf) { + struct rz_bin_bflt_obj *obj = (struct rz_bin_bflt_obj *) bf->o->bin_obj; + RzList *list = rz_list_newf ((RzListFree) free); ut32 i, len, n_got, amount; if (!list || !obj) { - r_list_free (list); + rz_list_free (list); return NULL; } if (obj->hdr->flags & FLAT_FLAG_GOTPIC) { @@ -165,7 +165,7 @@ static RList *relocs(RBinFile *bf) { obj->hdr->data_start + offset + 4 < offset) { break; } - len = r_buf_read_at (obj->b, obj->hdr->data_start + offset, + len = rz_buf_read_at (obj->b, obj->hdr->data_start + offset, (ut8 *) &got_entry, sizeof (ut32)); if (!VALID_GOT_ENTRY (got_entry) || len != sizeof (ut32)) { break; @@ -201,7 +201,7 @@ static RList *relocs(RBinFile *bf) { free (reloc_pointer_table); goto out_error; } - len = r_buf_read_at (obj->b, obj->hdr->reloc_start, + len = rz_buf_read_at (obj->b, obj->hdr->reloc_start, (ut8 *) reloc_pointer_table, amount); if (len != amount) { free (reloc_table); @@ -211,7 +211,7 @@ static RList *relocs(RBinFile *bf) { for (i = 0; i < n_reloc; i++) { // XXX it doesn't take endian as consideration when swapping ut32 reloc_offset = - r_swap_ut32 (reloc_pointer_table[i]) + + rz_swap_ut32 (reloc_pointer_table[i]) + BFLT_HDR_SIZE; if (reloc_offset < obj->hdr->bss_end && reloc_offset < obj->size) { @@ -222,7 +222,7 @@ static RList *relocs(RBinFile *bf) { free (reloc_pointer_table); goto out_error; } - len = r_buf_read_at (obj->b, reloc_offset, + len = rz_buf_read_at (obj->b, reloc_offset, (ut8 *) &reloc_fixed, sizeof (ut32)); if (len != sizeof (ut32)) { @@ -231,7 +231,7 @@ static RList *relocs(RBinFile *bf) { free (reloc_pointer_table); goto out_error; } - reloc_data_offset = r_swap_ut32 (reloc_fixed) + BFLT_HDR_SIZE; + reloc_data_offset = rz_swap_ut32 (reloc_fixed) + BFLT_HDR_SIZE; reloc_table[i].addr_to_patch = reloc_offset; reloc_table[i].data_offset = reloc_data_offset; @@ -240,7 +240,7 @@ static RList *relocs(RBinFile *bf) { reloc->type = R_BIN_RELOC_32; reloc->paddr = reloc_table[i].addr_to_patch; reloc->vaddr = reloc->paddr; - r_list_append (list, reloc); + rz_list_append (list, reloc); } } } @@ -249,17 +249,17 @@ static RList *relocs(RBinFile *bf) { } return list; out_error: - r_list_free (list); + rz_list_free (list); return NULL; } static RBinInfo *info(RBinFile *bf) { - struct r_bin_bflt_obj *obj = NULL; + struct rz_bin_bflt_obj *obj = NULL; RBinInfo *info = NULL; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - obj = (struct r_bin_bflt_obj *) bf->o->bin_obj; + obj = (struct rz_bin_bflt_obj *) bf->o->bin_obj; if (!(info = R_NEW0 (RBinInfo))) { return NULL; } @@ -280,17 +280,17 @@ static RBinInfo *info(RBinFile *bf) { static bool check_buffer(RBuffer *buf) { ut8 tmp[4]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); return r == sizeof (tmp) && !memcmp (tmp, "bFLT", 4); } static void destroy(RBinFile *bf) { - r_bin_bflt_free (bf->o->bin_obj); + rz_bin_bflt_free (bf->o->bin_obj); } -RBinPlugin r_bin_plugin_bflt = { +RBinPlugin rz_bin_plugin_bflt = { .name = "bflt", - .desc = "bFLT format r_bin plugin", + .desc = "bFLT format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .destroy = &destroy, @@ -302,9 +302,9 @@ RBinPlugin r_bin_plugin_bflt = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_bflt, + .data = &rz_bin_plugin_bflt, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_bios.c b/librz/bin/p/bin_bios.c similarity index 74% rename from libr/bin/p/bin_bios.c rename to librz/bin/p/bin_bios.c index 1e94bd4381..879575db76 100644 --- a/libr/bin/p/bin_bios.c +++ b/librz/bin/p/bin_bios.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../i/private.h" static bool check_buffer(RBuffer *buf) { - r_return_val_if_fail (buf, false); + rz_return_val_if_fail (buf, false); - ut64 sz = r_buf_size (buf); + ut64 sz = rz_buf_size (buf); if (sz <= 0xffff) { return false; } - ut8 b0 = r_buf_read8_at (buf, 0); + ut8 b0 = rz_buf_read8_at (buf, 0); if (b0 == 0xcf || b0 == 0x7f) { return false; } @@ -23,13 +23,13 @@ static bool check_buffer(RBuffer *buf) { /* hacky check to avoid detecting multidex or MZ bins as bios */ /* need better fix for this */ ut8 tmp[3]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); if (r <= 0 || !memcmp (tmp, "dex", 3) || !memcmp (tmp, "MZ", 2)) { return false; } /* Check if this a 'jmp' opcode */ - ut8 bep = r_buf_read8_at (buf, ep); + ut8 bep = rz_buf_read8_at (buf, ep); return bep == 0xea || bep == 0xe9; } @@ -37,12 +37,12 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd if (!check_buffer (buf)) { return false; } - *bin_obj = r_buf_ref (buf); + *bin_obj = rz_buf_ref (buf); return true; } static void destroy(RBinFile *bf) { - r_buf_free (bf->o->bin_obj); + rz_buf_free (bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { @@ -50,7 +50,7 @@ static ut64 baddr(RBinFile *bf) { } /* accelerate binary load */ -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } @@ -75,12 +75,12 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; RBuffer *obj = bf->o->bin_obj; - if (!(ret = r_list_newf ((RListFree) r_bin_section_free))) { + if (!(ret = rz_list_newf ((RzListFree) rz_bin_section_free))) { return NULL; } // program headers is another section @@ -89,11 +89,11 @@ static RList *sections(RBinFile *bf) { } ptr->name = strdup ("bootblk"); // Maps to 0xF000:0000 segment ptr->vsize = ptr->size = 0x10000; - ptr->paddr = r_buf_size (bf->buf) - ptr->size; + ptr->paddr = rz_buf_size (bf->buf) - ptr->size; ptr->vaddr = 0xf0000; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // If image bigger than 128K - add one more section if (bf->size >= 0x20000) { if (!(ptr = R_NEW0 (RBinSection))) { @@ -101,19 +101,19 @@ static RList *sections(RBinFile *bf) { } ptr->name = strdup ("_e000"); // Maps to 0xE000:0000 segment ptr->vsize = ptr->size = 0x10000; - ptr->paddr = r_buf_size (obj) - 2 * ptr->size; + ptr->paddr = rz_buf_size (obj) - 2 * ptr->size; ptr->vaddr = 0xe0000; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -122,11 +122,11 @@ static RList *entries(RBinFile *bf) { } ptr->paddr = 0; // 0x70000; ptr->vaddr = 0xffff0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -RBinPlugin r_bin_plugin_bios = { +RBinPlugin rz_bin_plugin_bios = { .name = "bios", .desc = "BIOS bin plugin", .license = "LGPL", @@ -141,9 +141,9 @@ RBinPlugin r_bin_plugin_bios = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_bios, + .data = &rz_bin_plugin_bios, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_bootimg.c b/librz/bin/p/bin_bootimg.c similarity index 82% rename from libr/bin/p/bin_bootimg.c rename to librz/bin/p/bin_bootimg.c index 6c98cbefb2..1ac297ada4 100644 --- a/libr/bin/p/bin_bootimg.c +++ b/librz/bin/p/bin_bootimg.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2015-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include typedef struct boot_img_hdr BootImage; @@ -50,24 +50,24 @@ typedef struct { static int bootimg_header_load(BootImageObj *obj, Sdb *db) { char *n; int i; - if (r_buf_size (obj->buf) < sizeof (BootImage)) { + if (rz_buf_size (obj->buf) < sizeof (BootImage)) { return false; } - // TODO make it endian-safe (void)r_buf_fread_at (buf, 0, (ut8*)bi, "IIiiiiiiiiiiii", 1); + // TODO make it endian-safe (void)rz_buf_fread_at (buf, 0, (ut8*)bi, "IIiiiiiiiiiiii", 1); BootImage *bi = &obj->bi; - (void) r_buf_read_at (obj->buf, 0, (ut8 *)bi, sizeof (BootImage)); - if ((n = r_str_ndup ((char *) bi->name, BOOT_NAME_SIZE))) { + (void) rz_buf_read_at (obj->buf, 0, (ut8 *)bi, sizeof (BootImage)); + if ((n = rz_str_ndup ((char *) bi->name, BOOT_NAME_SIZE))) { sdb_set (db, "name", n, 0); free (n); } - if ((n = r_str_ndup ((char *) bi->cmdline, BOOT_ARGS_SIZE))) { + if ((n = rz_str_ndup ((char *) bi->cmdline, BOOT_ARGS_SIZE))) { sdb_set (db, "cmdline", n, 0); free (n); } for (i = 0; i < 8; i++) { sdb_num_set (db, "id", (ut64) bi->id[i], 0); } - if ((n = r_str_ndup ((char *) bi->extra_cmdline, BOOT_EXTRA_ARGS_SIZE))) { + if ((n = rz_str_ndup ((char *) bi->extra_cmdline, BOOT_EXTRA_ARGS_SIZE))) { sdb_set (db, "extra_cmdline", n, 0); free (n); } @@ -94,7 +94,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd free (bio); return false; } - bio->buf = r_buf_ref (buf); + bio->buf = rz_buf_ref (buf); if (!bootimg_header_load (bio, bio->kv)) { free (bio); return false; @@ -106,7 +106,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd static void destroy(RBinFile *bf) { BootImageObj *bio = bf->o->bin_obj; - r_buf_free (bio->buf); + rz_buf_free (bio->buf); R_FREE (bf->o->bin_obj); } @@ -115,7 +115,7 @@ static ut64 baddr(RBinFile *bf) { return bio? bio->bi.kernel_addr: 0; } -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } @@ -147,20 +147,20 @@ static RBinInfo *info(RBinFile *bf) { static bool check_buffer(RBuffer *buf) { ut8 tmp[13]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); return r > 12 && !strncmp ((const char *)tmp, "ANDROID!", 8); } -static RList *entries(RBinFile *bf) { +static RzList *entries(RBinFile *bf) { BootImageObj *bio = bf->o->bin_obj; RBinAddr *ptr = NULL; if (!bio) { return NULL; } BootImage *bi = &bio->bi; - RList *ret; + RzList *ret; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } if (!(ptr = R_NEW0 (RBinAddr))) { @@ -168,20 +168,20 @@ static RList *entries(RBinFile *bf) { } ptr->paddr = bi->page_size; ptr->vaddr = bi->kernel_addr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { BootImageObj *bio = bf->o->bin_obj; if (!bio) { return NULL; } BootImage *bi = &bio->bi; - RList *ret = NULL; + RzList *ret = NULL; RBinSection *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -196,7 +196,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = 0; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -208,7 +208,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = bi->kernel_addr; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (bi->ramdisk_size > 0) { ut64 base = bi->kernel_size + 2 * bi->page_size - 1; @@ -222,7 +222,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = bi->ramdisk_addr; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } if (bi->second_size > 0) { @@ -237,13 +237,13 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = bi->second_addr; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -RBinPlugin r_bin_plugin_bootimg = { +RBinPlugin rz_bin_plugin_bootimg = { .name = "bootimg", .desc = "Android Boot Image", .license = "LGPL3", @@ -259,9 +259,9 @@ RBinPlugin r_bin_plugin_bootimg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_bootimg, + .data = &rz_bin_plugin_bootimg, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_cgc.c b/librz/bin/p/bin_cgc.c similarity index 68% rename from libr/bin/p/bin_cgc.c rename to librz/bin/p/bin_cgc.c index c8e5ed5f6f..df07726837 100644 --- a/libr/bin/p/bin_cgc.c +++ b/librz/bin/p/bin_cgc.c @@ -3,12 +3,12 @@ #define R_BIN_CGC 1 #include "bin_elf.inc" -extern struct r_bin_dbginfo_t r_bin_dbginfo_elf; -extern struct r_bin_write_t r_bin_write_elf; +extern struct rz_bin_dbginfo_t rz_bin_dbginfo_elf; +extern struct rz_bin_write_t rz_bin_write_elf; static bool check_buffer(RBuffer *buf) { ut8 tmp[SCGCMAG + 1]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); return r > SCGCMAG && !memcmp (tmp, CGCMAG, SCGCMAG) && tmp[4] != 2; } @@ -19,14 +19,14 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, ut16 ehdrsz, phdrsz; ut32 p_vaddr, p_paddr, p_fs, p_fs2; ut32 baddr = 0x8048000; - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define D(x) r_buf_append_ut32(buf,x) -#define H(x) r_buf_append_ut16(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) -#define WZ(x,y) p_tmp=r_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define D(x) rz_buf_append_ut32(buf,x) +#define H(x) rz_buf_append_ut16(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) +#define WZ(x,y) p_tmp=rz_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) B ("\x7F" "CGC" "\x01\x01\x01\x43", 8); Z (8); @@ -34,38 +34,38 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, H (3); // e_machne = EM_I386 D (1); - p_start = r_buf_size (buf); + p_start = rz_buf_size (buf); D (-1); // _start - p_phoff = r_buf_size (buf); + p_phoff = rz_buf_size (buf); D (-1); // phoff -- program headers offset D (0); // shoff -- section headers offset D (0); // flags - p_ehdrsz = r_buf_size (buf); + p_ehdrsz = rz_buf_size (buf); H (-1); // ehdrsz - p_phdrsz = r_buf_size (buf); + p_phdrsz = rz_buf_size (buf); H (-1); // phdrsz H (1); H (0); H (0); H (0); // phdr: - p_phdr = r_buf_size (buf); + p_phdr = rz_buf_size (buf); D (1); D (0); - p_vaddr = r_buf_size (buf); + p_vaddr = rz_buf_size (buf); D (-1); // vaddr = $$ - p_paddr = r_buf_size (buf); + p_paddr = rz_buf_size (buf); D (-1); // paddr = $$ - p_fs = r_buf_size (buf); + p_fs = rz_buf_size (buf); D (-1); // filesize - p_fs2 = r_buf_size (buf); + p_fs2 = rz_buf_size (buf); D (-1); // filesize D (5); // flags D (0x1000); // align ehdrsz = p_phdr; - phdrsz = r_buf_size (buf) - p_phdr; - code_pa = r_buf_size (buf); + phdrsz = rz_buf_size (buf) - p_phdr; + code_pa = rz_buf_size (buf); code_va = code_pa + baddr; phoff = 0x34;//p_phdr ; filesize = code_pa + codelen + datalen; @@ -93,9 +93,9 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, return buf; } -RBinPlugin r_bin_plugin_cgc = { +RBinPlugin rz_bin_plugin_cgc = { .name = "cgc", - .desc = "CGC format r_bin plugin", + .desc = "CGC format rz_bin plugin", .license = "LGPL3", .get_sdb = &get_sdb, .load_buffer = load_buffer, @@ -114,10 +114,10 @@ RBinPlugin r_bin_plugin_cgc = { .size = &size, .libs = &libs, .relocs = &relocs, - .dbginfo = &r_bin_dbginfo_elf, + .dbginfo = &rz_bin_dbginfo_elf, .create = &create, .patch_relocs = &patch_relocs, - .write = &r_bin_write_elf, + .write = &rz_bin_write_elf, .file_type = get_file_type, .regstate = regstate, .maps = maps, diff --git a/libr/bin/p/bin_coff.c b/librz/bin/p/bin_coff.c similarity index 75% rename from libr/bin/p/bin_coff.c rename to librz/bin/p/bin_coff.c index a27fc8196a..ba311a3063 100644 --- a/libr/bin/p/bin_coff.c +++ b/librz/bin/p/bin_coff.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2014-2019 - Fedor Sakharov */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "coff/coff.h" @@ -13,25 +13,25 @@ static Sdb* get_sdb(RBinFile *bf) { if (!o) { return NULL; } - struct r_bin_coff_obj *bin = (struct r_bin_coff_obj *) o->bin_obj; + struct rz_bin_coff_obj *bin = (struct rz_bin_coff_obj *) o->bin_obj; if (bin->kv) { return bin->kv; } return NULL; } -static bool r_coff_is_stripped(struct r_bin_coff_obj *obj) { +static bool rz_coff_is_stripped(struct rz_bin_coff_obj *obj) { return !!(obj->hdr.f_flags & (COFF_FLAGS_TI_F_RELFLG | \ COFF_FLAGS_TI_F_LNNO | COFF_FLAGS_TI_F_LSYMS)); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - *bin_obj = r_bin_coff_new_buf (buf, bf->rbin->verbose); + *bin_obj = rz_bin_coff_new_buf (buf, bf->rbin->verbose); return *bin_obj != NULL; } static void destroy(RBinFile *bf) { - r_bin_coff_free ((struct r_bin_coff_obj*)bf->o->bin_obj); + rz_bin_coff_free ((struct rz_bin_coff_obj*)bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { @@ -44,7 +44,7 @@ static RBinAddr *binsym(RBinFile *bf, int sym) { #define DTYPE_IS_FUNCTION(type) (COFF_SYM_GET_DTYPE (type) == COFF_SYM_DTYPE_FUNCTION) -static bool _fill_bin_symbol(RBin *rbin, struct r_bin_coff_obj *bin, int idx, RBinSymbol **sym) { +static bool _fill_bin_symbol(RBin *rbin, struct rz_bin_coff_obj *bin, int idx, RBinSymbol **sym) { RBinSymbol *ptr = *sym; struct coff_symbol *s = NULL; struct coff_scn_hdr *sc_hdr = NULL; @@ -55,7 +55,7 @@ static bool _fill_bin_symbol(RBin *rbin, struct r_bin_coff_obj *bin, int idx, RB return false; } s = &bin->symbols[idx]; - char *coffname = r_coff_symbol_name (bin, s); + char *coffname = rz_coff_symbol_name (bin, s); if (!coffname) { return false; } @@ -95,7 +95,7 @@ static bool _fill_bin_symbol(RBin *rbin, struct r_bin_coff_obj *bin, int idx, RB if (s->n_scnum == COFF_SYM_SCNUM_ABS) { ptr->type = "ABS"; ptr->paddr = UT64_MAX; - ptr->name = r_str_newf ("%s-0x%08x", coffname, s->n_value); + ptr->name = rz_str_newf ("%s-0x%08x", coffname, s->n_value); if (ptr->name) { R_FREE (coffname); } else { @@ -110,7 +110,7 @@ static bool _fill_bin_symbol(RBin *rbin, struct r_bin_coff_obj *bin, int idx, RB } break; default: - ptr->type = r_str_constpool_get (&rbin->constpool, sdb_fmt ("%i", s->n_sclass)); + ptr->type = rz_str_constpool_get (&rbin->constpool, sdb_fmt ("%i", s->n_sclass)); break; } ptr->vaddr = ptr->paddr; @@ -123,7 +123,7 @@ static bool is_imported_symbol(struct coff_symbol *s) { return s->n_scnum == COFF_SYM_SCNUM_UNDEF && s->n_sclass == COFF_SYM_CLASS_EXTERNAL; } -static RBinImport *_fill_bin_import(struct r_bin_coff_obj *bin, int idx) { +static RBinImport *_fill_bin_import(struct rz_bin_coff_obj *bin, int idx) { RBinImport *ptr = R_NEW0 (RBinImport); if (!ptr || idx < 0 || idx > bin->hdr.f_nsyms) { free (ptr); @@ -134,7 +134,7 @@ static RBinImport *_fill_bin_import(struct r_bin_coff_obj *bin, int idx) { free (ptr); return NULL; } - char *coffname = r_coff_symbol_name (bin, s); + char *coffname = rz_coff_symbol_name (bin, s); if (!coffname) { free (ptr); return NULL; @@ -147,34 +147,34 @@ static RBinImport *_fill_bin_import(struct r_bin_coff_obj *bin, int idx) { return ptr; } -static RList *entries(RBinFile *bf) { - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)bf->o->bin_obj; - RList *ret; - if (!(ret = r_list_newf (free))) { +static RzList *entries(RBinFile *bf) { + struct rz_bin_coff_obj *obj = (struct rz_bin_coff_obj*)bf->o->bin_obj; + RzList *ret; + if (!(ret = rz_list_newf (free))) { return NULL; } - RBinAddr *ptr = r_coff_get_entry (obj); + RBinAddr *ptr = rz_coff_get_entry (obj); if (ptr) { - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { char *tmp = NULL; size_t i; RBinSection *ptr = NULL; - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)bf->o->bin_obj; + struct rz_bin_coff_obj *obj = (struct rz_bin_coff_obj*)bf->o->bin_obj; - RList *ret = r_list_newf ((RListFree)r_bin_section_free); + RzList *ret = rz_list_newf ((RzListFree)rz_bin_section_free); if (!ret) { return NULL; } if (obj && obj->scn_hdrs) { for (i = 0; i < obj->hdr.f_nscns; i++) { - tmp = r_coff_symbol_name (obj, &obj->scn_hdrs[i]); + tmp = rz_coff_symbol_name (obj, &obj->scn_hdrs[i]); if (!tmp) { - r_list_free (ret); + rz_list_free (ret); return NULL; } //IO does not like sections with the same name append idx @@ -184,7 +184,7 @@ static RList *sections(RBinFile *bf) { free (tmp); return ret; } - ptr->name = r_str_newf ("%s-%d", tmp, i); + ptr->name = rz_str_newf ("%s-%d", tmp, i); free (tmp); if (strstr (ptr->name, "data")) { ptr->is_data = true; @@ -203,17 +203,17 @@ static RList *sections(RBinFile *bf) { if (obj->scn_hdrs[i].s_flags & COFF_SCN_MEM_EXECUTE) { ptr->perm |= R_PERM_X; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } return ret; } -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { int i; RBinSymbol *ptr = NULL; - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)bf->o->bin_obj; - RList *ret = r_list_newf ((RListFree)r_bin_symbol_free); + struct rz_bin_coff_obj *obj = (struct rz_bin_coff_obj*)bf->o->bin_obj; + RzList *ret = rz_list_newf ((RzListFree)rz_bin_symbol_free); if (!ret) { return NULL; } @@ -224,7 +224,7 @@ static RList *symbols(RBinFile *bf) { break; } if (_fill_bin_symbol (bf->rbin, obj, i, &ptr)) { - r_list_append (ret, ptr); + rz_list_append (ret, ptr); ht_up_insert (obj->sym_ht, (ut64)i, ptr); } else { free (ptr); @@ -235,10 +235,10 @@ static RList *symbols(RBinFile *bf) { return ret; } -static RList *imports(RBinFile *bf) { +static RzList *imports(RBinFile *bf) { int i; - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)bf->o->bin_obj; - RList *ret = r_list_newf ((RListFree)r_bin_import_free); + struct rz_bin_coff_obj *obj = (struct rz_bin_coff_obj*)bf->o->bin_obj; + RzList *ret = rz_list_newf ((RzListFree)rz_bin_import_free); if (!ret) { return NULL; } @@ -248,7 +248,7 @@ static RList *imports(RBinFile *bf) { RBinImport *ptr = _fill_bin_import (obj, i); if (ptr) { ptr->ordinal = ord++; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); ht_up_insert (obj->imp_ht, (ut64)i, ptr); } i += obj->symbols[i].n_numaux; @@ -257,7 +257,7 @@ static RList *imports(RBinFile *bf) { return ret; } -static RList *libs(RBinFile *bf) { +static RzList *libs(RBinFile *bf) { return NULL; } @@ -266,25 +266,25 @@ static ut32 _read_le32(RBin *rbin, ut64 addr) { if (!rbin->iob.read_at (rbin->iob.io, addr, data, sizeof (data))) { return UT32_MAX; } - return r_read_le32 (data); + return rz_read_le32 (data); } #define BYTES_PER_IMP_RELOC 8 -static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, ut64 imp_map) { - r_return_val_if_fail (bin && bin->scn_hdrs, NULL); +static RzList *_relocs_list(RBin *rbin, struct rz_bin_coff_obj *bin, bool patch, ut64 imp_map) { + rz_return_val_if_fail (bin && bin->scn_hdrs, NULL); RBinReloc *reloc; struct coff_reloc *rel; int j, i = 0; - RList *list_rel = r_list_new (); + RzList *list_rel = rz_list_new (); if (!list_rel) { return NULL; } const bool patch_imports = patch && (imp_map != UT64_MAX); HtUU *imp_vaddr_ht = patch_imports? ht_uu_new0 (): NULL; if (patch_imports && !imp_vaddr_ht) { - r_list_free (list_rel); + rz_list_free (list_rel); return NULL; } for (i = 0; i < bin->hdr.f_nscns; i++) { @@ -304,13 +304,13 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u free (rel); break; } - len = r_buf_read_at (bin->b, bin->scn_hdrs[i].s_relptr, (ut8*)rel, size); + len = rz_buf_read_at (bin->b, bin->scn_hdrs[i].s_relptr, (ut8*)rel, size); if (len != size) { free (rel); break; } for (j = 0; j < bin->scn_hdrs[i].s_nreloc; j++) { - RBinSymbol *symbol = (RBinSymbol *)ht_up_find (bin->sym_ht, (ut64)rel[j].r_symndx, NULL); + RBinSymbol *symbol = (RBinSymbol *)ht_up_find (bin->sym_ht, (ut64)rel[j].rz_symndx, NULL); if (!symbol) { continue; } @@ -320,20 +320,20 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u } reloc->symbol = symbol; - reloc->paddr = bin->scn_hdrs[i].s_scnptr + rel[j].r_vaddr; + reloc->paddr = bin->scn_hdrs[i].s_scnptr + rel[j].rz_vaddr; reloc->vaddr = reloc->paddr; - reloc->type = rel[j].r_type; + reloc->type = rel[j].rz_type; ut64 sym_vaddr = symbol->vaddr; if (symbol->is_imported) { - reloc->import = (RBinImport *)ht_up_find (bin->sym_ht, (ut64)rel[j].r_symndx, NULL); + reloc->import = (RBinImport *)ht_up_find (bin->sym_ht, (ut64)rel[j].rz_symndx, NULL); if (patch_imports) { bool found; - sym_vaddr = ht_uu_find (imp_vaddr_ht, (ut64)rel[j].r_symndx, &found); + sym_vaddr = ht_uu_find (imp_vaddr_ht, (ut64)rel[j].rz_symndx, &found); if (!found) { sym_vaddr = imp_map; imp_map += BYTES_PER_IMP_RELOC; - ht_uu_insert (imp_vaddr_ht, (ut64)rel[j].r_symndx, sym_vaddr); + ht_uu_insert (imp_vaddr_ht, (ut64)rel[j].rz_symndx, sym_vaddr); } } } @@ -343,10 +343,10 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u ut8 patch_buf[8]; switch (bin->hdr.f_magic) { case COFF_FILE_MACHINE_I386: - switch (rel[j].r_type) { + switch (rel[j].rz_type) { case COFF_REL_I386_DIR32: reloc->type = R_BIN_RELOC_32; - r_write_le32 (patch_buf, (ut32)sym_vaddr); + rz_write_le32 (patch_buf, (ut32)sym_vaddr); plen = 4; break; case COFF_REL_I386_REL32: @@ -358,13 +358,13 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u } reloc->addend = data; data += sym_vaddr - reloc->vaddr - 4; - r_write_le32 (patch_buf, (st32)data); + rz_write_le32 (patch_buf, (st32)data); plen = 4; break; } break; case COFF_FILE_MACHINE_AMD64: - switch (rel[j].r_type) { + switch (rel[j].rz_type) { case COFF_REL_AMD64_REL32: reloc->type = R_BIN_RELOC_32; reloc->additive = 1; @@ -374,7 +374,7 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u } reloc->addend = data; data += sym_vaddr - reloc->vaddr - 4; - r_write_le32 (patch_buf, (st32)data); + rz_write_le32 (patch_buf, (st32)data); plen = 4; break; } @@ -388,7 +388,7 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u } } } - r_list_append (list_rel, reloc); + rz_list_append (list_rel, reloc); } free (rel); } @@ -396,19 +396,19 @@ static RList *_relocs_list(RBin *rbin, struct r_bin_coff_obj *bin, bool patch, u return list_rel; } -static RList *relocs(RBinFile *bf) { - struct r_bin_coff_obj *bin = (struct r_bin_coff_obj*)bf->o->bin_obj; +static RzList *relocs(RBinFile *bf) { + struct rz_bin_coff_obj *bin = (struct rz_bin_coff_obj*)bf->o->bin_obj; return _relocs_list (bf->rbin, bin, false, UT64_MAX); } -static RList *patch_relocs(RBin *b) { - r_return_val_if_fail (b && b->iob.io && b->iob.io->desc, NULL); - RBinObject *bo = r_bin_cur_object (b); - RIO *io = b->iob.io; +static RzList *patch_relocs(RBin *b) { + rz_return_val_if_fail (b && b->iob.io && b->iob.io->desc, NULL); + RBinObject *bo = rz_bin_cur_object (b); + RzIO *io = b->iob.io; if (!bo || !bo->bin_obj) { return NULL; } - struct r_bin_coff_obj *bin = (struct r_bin_coff_obj*)bo->bin_obj; + struct rz_bin_coff_obj *bin = (struct rz_bin_coff_obj*)bo->bin_obj; if (bin->hdr.f_flags & COFF_FLAGS_TI_F_EXEC) { return NULL; } @@ -431,14 +431,14 @@ static RList *patch_relocs(RBin *b) { if (nimports) { m_vaddr = bin->size; ut64 size = nimports * BYTES_PER_IMP_RELOC; - char *muri = r_str_newf ("malloc://%" PFMT64u, size); - RIODesc *desc = b->iob.open_at (io, muri, R_PERM_R, 0664, m_vaddr); + char *muri = rz_str_newf ("malloc://%" PFMT64u, size); + RzIODesc *desc = b->iob.open_at (io, muri, R_PERM_R, 0664, m_vaddr); free (muri); if (!desc) { return NULL; } - RIOMap *map = b->iob.map_get (io, m_vaddr); + RzIOMap *map = b->iob.map_get (io, m_vaddr); if (!map) { return NULL; } @@ -450,7 +450,7 @@ static RList *patch_relocs(RBin *b) { static RBinInfo *info(RBinFile *bf) { RBinInfo *ret = R_NEW0(RBinInfo); - struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)bf->o->bin_obj; + struct rz_bin_coff_obj *obj = (struct rz_bin_coff_obj*)bf->o->bin_obj; ret->file = bf->file? strdup (bf->file): NULL; ret->rclass = strdup ("coff"); @@ -463,7 +463,7 @@ static RBinInfo *info(RBinFile *bf) { ret->dbg_info = 0; ret->has_lit = true; - if (r_coff_is_stripped (obj)) { + if (rz_coff_is_stripped (obj)) { ret->dbg_info |= R_BIN_DBG_STRIPPED; } else { if (!(obj->hdr.f_flags & COFF_FLAGS_TI_F_RELFLG)) { @@ -526,7 +526,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *fields(RBinFile *bf) { +static RzList *fields(RBinFile *bf) { return NULL; } @@ -549,13 +549,13 @@ ut16 CHARACTERISTICS #endif ut8 tmp[20]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); - return r >= 20 && r_coff_supported_arch (tmp); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); + return r >= 20 && rz_coff_supported_arch (tmp); } -RBinPlugin r_bin_plugin_coff = { +RBinPlugin rz_bin_plugin_coff = { .name = "coff", - .desc = "COFF format r_bin plugin", + .desc = "COFF format rz_bin plugin", .license = "LGPL3", .get_sdb = &get_sdb, .load_buffer = &load_buffer, @@ -576,9 +576,9 @@ RBinPlugin r_bin_plugin_coff = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_coff, + .data = &rz_bin_plugin_coff, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_dbginfo_dex.c b/librz/bin/p/bin_dbginfo_dex.c similarity index 86% rename from libr/bin/p/bin_dbginfo_dex.c rename to librz/bin/p/bin_dbginfo_dex.c index ec49053e2c..44f78f85ae 100644 --- a/libr/bin/p/bin_dbginfo_dex.c +++ b/librz/bin/p/bin_dbginfo_dex.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, montekki, pancake */ -#include -#include +#include +#include static bool get_line(RBinFile *bf, ut64 addr, char *file, int len, int *line) { if (bf->sdb_addrinfo) { @@ -21,6 +21,6 @@ static bool get_line(RBinFile *bf, ut64 addr, char *file, int len, int *line) { return false; } -RBinDbgInfo r_bin_dbginfo_dex = { +RBinDbgInfo rz_bin_dbginfo_dex = { .get_line = &get_line, }; diff --git a/libr/bin/p/bin_dbginfo_elf.c b/librz/bin/p/bin_dbginfo_elf.c similarity index 84% rename from libr/bin/p/bin_dbginfo_elf.c rename to librz/bin/p/bin_dbginfo_elf.c index ec41027c89..808f86df4c 100644 --- a/libr/bin/p/bin_dbginfo_elf.c +++ b/librz/bin/p/bin_dbginfo_elf.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, montekki, pancake */ -#include -#include +#include +#include // TODO: use proper dwarf api here.. or deprecate static bool get_line(RBinFile *bf, ut64 addr, char *file, int len, int *line) { @@ -23,11 +23,11 @@ static bool get_line(RBinFile *bf, ut64 addr, char *file, int len, int *line) { } #if R_BIN_ELF64 -RBinDbgInfo r_bin_dbginfo_elf64 = { +RBinDbgInfo rz_bin_dbginfo_elf64 = { .get_line = &get_line, }; #else -RBinDbgInfo r_bin_dbginfo_elf = { +RBinDbgInfo rz_bin_dbginfo_elf = { .get_line = &get_line, }; #endif diff --git a/libr/bin/p/bin_dbginfo_elf64.c b/librz/bin/p/bin_dbginfo_elf64.c similarity index 100% rename from libr/bin/p/bin_dbginfo_elf64.c rename to librz/bin/p/bin_dbginfo_elf64.c diff --git a/libr/bin/p/bin_dex.c b/librz/bin/p/bin_dex.c similarity index 80% rename from libr/bin/p/bin_dex.c rename to librz/bin/p/bin_dex.c index 491dc840c6..b9dd760a25 100644 --- a/libr/bin/p/bin_dex.c +++ b/librz/bin/p/bin_dex.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2011-2020 - pancake, h4ng3r */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "../i/private.h" #include "dex/dex.h" -#define r_hash_adler32 __adler32 +#define rz_hash_adler32 __adler32 #include "../../hash/adler32.c" // globals to kill -extern struct r_bin_dbginfo_t r_bin_dbginfo_dex; +extern struct rz_bin_dbginfo_t rz_bin_dbginfo_dex; static bool dexdump = false; static Sdb *mdb = NULL; static const char *dexSubsystem = NULL; @@ -67,7 +67,7 @@ static ut64 get_method_flags(ut64 MA) { return flags; } -static ut64 offset_of_method_idx(RBinFile *bf, struct r_bin_dex_obj_t *dex, int idx) { +static ut64 offset_of_method_idx(RBinFile *bf, struct rz_bin_dex_obj_t *dex, int idx) { // ut64 off = dex->header.method_offset + idx; return sdb_num_get (mdb, sdb_fmt ("method.%d", idx), 0); } @@ -93,11 +93,11 @@ static const char *getstr(RBinDexObj *dex, int idx) { if (string_index >= dex->size) { return NULL; } - if (r_buf_read_at (dex->b, string_index, buf, sizeof (buf)) != sizeof (buf)) { + if (rz_buf_read_at (dex->b, string_index, buf, sizeof (buf)) != sizeof (buf)) { return NULL; } ut64 len; - int uleblen = r_uleb128 (buf, sizeof (buf), &len, NULL) - buf; + int uleblen = rz_uleb128 (buf, sizeof (buf), &len, NULL) - buf; if (!uleblen || uleblen >= dex->size || uleblen >= dex->header.strings_size) { return NULL; } @@ -106,7 +106,7 @@ static const char *getstr(RBinDexObj *dex, int idx) { } ut8 *ptr = malloc (len + 1); if (ptr) { - r_buf_read_at (dex->b, string_index + uleblen, ptr, len); + rz_buf_read_at (dex->b, string_index + uleblen, ptr, len); ptr[len] = 0; dex->cal_strings[idx] = (char *)ptr; return (const char *)ptr; @@ -268,14 +268,14 @@ static char *dex_get_proto(RBinDexObj *bin, int proto_id) { return NULL; } if (!params_off) { - return r_str_newf ("()%s", return_type);; + return rz_str_newf ("()%s", return_type);; } ut8 params_buf[sizeof (ut32)]; - if (!r_buf_read_at (bin->b, params_off, params_buf, sizeof (params_buf))) { + if (!rz_buf_read_at (bin->b, params_off, params_buf, sizeof (params_buf))) { return NULL; } // size of the list, in 16 bit entries - ut32 list_size = r_read_le32 (params_buf); + ut32 list_size = rz_read_le32 (params_buf); if (list_size >= ST32_MAX) { eprintf ("Warning: function prototype contains too many parameters (> 2 million).\n"); list_size = ST32_MAX; @@ -285,28 +285,28 @@ static char *dex_get_proto(RBinDexObj *bin, int proto_id) { typeidx_bufsize = bin->size - params_off; eprintf ("Warning: truncated typeidx buffer\n"); } - RStrBuf *sig = r_strbuf_new ("("); + RStrBuf *sig = rz_strbuf_new ("("); if (typeidx_bufsize > 0) { ut8 *typeidx_buf = malloc (typeidx_bufsize); - if (!typeidx_buf || !r_buf_read_at (bin->b, params_off + 4, typeidx_buf, typeidx_bufsize)) { - r_strbuf_free (sig); + if (!typeidx_buf || !rz_buf_read_at (bin->b, params_off + 4, typeidx_buf, typeidx_bufsize)) { + rz_strbuf_free (sig); return NULL; } size_t off; for (off = 0; off + 1 < typeidx_bufsize; off += 2) { - ut16 type_idx = r_read_le16 (typeidx_buf + off); + ut16 type_idx = rz_read_le16 (typeidx_buf + off); ut16 type_desc_id = type_desc (bin, type_idx); if (type_desc_id == UT16_MAX) { - r_strbuf_append (sig, "?;"); + rz_strbuf_append (sig, "?;"); } else { const char *buff = getstr (bin, type_desc_id); - r_strbuf_append (sig, buff? buff: "?;"); + rz_strbuf_append (sig, buff? buff: "?;"); } } free (typeidx_buf); } - r_strbuf_appendf (sig, ")%s", return_type); - return r_strbuf_drain (sig); + rz_strbuf_appendf (sig, ")%s", return_type); + return rz_strbuf_drain (sig); } static char *dex_method_signature(RBinDexObj *bin, int method_idx) { @@ -318,22 +318,22 @@ static char *dex_method_signature(RBinDexObj *bin, int method_idx) { static ut32 read32(RBuffer* b, ut64 addr) { ut32 n = 0; - r_buf_read_at (b, addr, (ut8*)&n, sizeof (n)); - return r_read_le32 (&n); + rz_buf_read_at (b, addr, (ut8*)&n, sizeof (n)); + return rz_read_le32 (&n); } static ut16 read16(RBuffer* b, ut64 addr) { ut16 n = 0; - r_buf_read_at (b, addr, (ut8*)&n, sizeof (n)); - return r_read_le16 (&n); + rz_buf_read_at (b, addr, (ut8*)&n, sizeof (n)); + return rz_read_le16 (&n); } -static RList *dex_method_signature2(RBinDexObj *bin, int method_idx) { +static RzList *dex_method_signature2(RBinDexObj *bin, int method_idx) { ut32 proto_id, params_off, list_size; ut16 type_idx; size_t i; - RList *params = r_list_new (); + RzList *params = rz_list_new (); if (!params) { return NULL; } @@ -365,11 +365,11 @@ static RList *dex_method_signature2(RBinDexObj *bin, int method_idx) { if (!buff) { break; } - r_list_append (params, (void *)buff); + rz_list_append (params, (void *)buff); } return params; out_error: - r_list_free (params); + rz_list_free (params); return NULL; } @@ -381,7 +381,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, RBin *rbin = bf->rbin; RBinDexObj *dex = bf->o->bin_obj; // bin .. unnecessary arg // runtime error: pointer index expression with base 0x000000004402 overflowed to 0xffffffffff0043fc - if (debug_info_off >= r_buf_size (bf->buf)) { + if (debug_info_off >= rz_buf_size (bf->buf)) { return; } ut64 line_start; @@ -389,26 +389,26 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, ut64 param_type_idx; ut16 argReg = regsz - ins_size; ut64 source_file_idx = c->source_file; - RList *params, *debug_positions, *emitted_debug_locals = NULL; + RzList *params, *debug_positions, *emitted_debug_locals = NULL; bool keep = true; if (argReg > regsz) { return; // this return breaks tests } - r_buf_seek (bf->buf, debug_info_off, R_BUF_SET); + rz_buf_seek (bf->buf, debug_info_off, R_BUF_SET); ut64 res; - r_buf_uleb128 (bf->buf, &res); + rz_buf_uleb128 (bf->buf, &res); line_start = res; - r_buf_uleb128 (bf->buf, &res); + rz_buf_uleb128 (bf->buf, &res); parameters_size = res; // TODO: check when we should use source_file // The state machine consists of five registers ut32 address = 0; ut32 line = line_start; - if (!(debug_positions = r_list_newf ((RListFree)free))) { + if (!(debug_positions = rz_list_newf ((RzListFree)free))) { return; } - if (!(emitted_debug_locals = r_list_newf ((RListFree)free))) { + if (!(emitted_debug_locals = rz_list_newf ((RzListFree)free))) { free (debug_positions); return; } @@ -416,7 +416,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, struct dex_debug_local_t *debug_locals = calloc (sizeof (struct dex_debug_local_t), regsz + 1); if (!(MA & 0x0008)) { debug_locals[argReg].name = "this"; - debug_locals[argReg].descriptor = r_str_newf ("%s;", class_name); + debug_locals[argReg].descriptor = rz_str_newf ("%s;", class_name); debug_locals[argReg].startAddress = 0; debug_locals[argReg].signature = NULL; debug_locals[argReg].live = true; @@ -426,16 +426,16 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, goto beach; } - RListIter *iter; + RzListIter *iter; const char *name; char *type; int reg; - r_list_foreach (params, iter, type) { + rz_list_foreach (params, iter, type) { if ((argReg >= regsz) || !type || parameters_size <= 0) { goto beach; } - (void)r_buf_uleb128 (bf->buf, &res); + (void)rz_buf_uleb128 (bf->buf, &res); param_type_idx = res - 1; name = getstr (dex, param_type_idx); reg = argReg; @@ -458,7 +458,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, parameters_size--; } ut8 opcode = 0; - if (r_buf_read (bf->buf, &opcode, 1) != 1) { + if (rz_buf_read (bf->buf, &opcode, 1) != 1) { goto beach; } while (keep) { @@ -469,23 +469,23 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, case 0x1: // DBG_ADVANCE_PC { ut64 addr_diff; - r_buf_uleb128 (bf->buf, &addr_diff); + rz_buf_uleb128 (bf->buf, &addr_diff); address += addr_diff; } break; case 0x2: // DBG_ADVANCE_LINE { st64 line_diff; - r_buf_sleb128 (bf->buf, &line_diff); + rz_buf_sleb128 (bf->buf, &line_diff); line += line_diff; } break; case 0x3: // DBG_START_LOCAL { ut64 register_num, name_idx, type_idx; - r_buf_uleb128 (bf->buf, ®ister_num); - r_buf_uleb128 (bf->buf, &name_idx); - r_buf_uleb128 (bf->buf, &type_idx); + rz_buf_uleb128 (bf->buf, ®ister_num); + rz_buf_uleb128 (bf->buf, &name_idx); + rz_buf_uleb128 (bf->buf, &type_idx); name_idx--; type_idx--; if (register_num >= regsz) { @@ -507,7 +507,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, local->live = true; local->reg = register_num; local->endAddress = address; - r_list_append (emitted_debug_locals, local); + rz_list_append (emitted_debug_locals, local); } debug_locals[register_num].name = getstr (dex, name_idx); debug_locals[register_num].descriptor = dex_type_descriptor (dex, type_idx); @@ -520,10 +520,10 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, case 0x4: //DBG_START_LOCAL_EXTENDED { ut64 register_num, name_idx, type_idx, sig_idx; - r_buf_uleb128 (bf->buf, ®ister_num); - r_buf_uleb128 (bf->buf, &name_idx); - r_buf_uleb128 (bf->buf, &type_idx); - r_buf_uleb128 (bf->buf, &sig_idx); + rz_buf_uleb128 (bf->buf, ®ister_num); + rz_buf_uleb128 (bf->buf, &name_idx); + rz_buf_uleb128 (bf->buf, &type_idx); + rz_buf_uleb128 (bf->buf, &sig_idx); sig_idx--; type_idx--; name_idx--; @@ -547,7 +547,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, local->live = true; local->reg = register_num; local->endAddress = address; - r_list_append (emitted_debug_locals, local); + rz_list_append (emitted_debug_locals, local); } debug_locals[register_num].name = getstr (dex, name_idx); debug_locals[register_num].descriptor = dex_type_descriptor (dex, type_idx); @@ -559,7 +559,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, case 0x5: // DBG_END_LOCAL { ut64 register_num; - r_buf_uleb128 (bf->buf, ®ister_num); + rz_buf_uleb128 (bf->buf, ®ister_num); // emitLocalCbIfLive if (register_num >= regsz) { goto beach; @@ -578,7 +578,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, local->live = true; local->reg = register_num; local->endAddress = address; - r_list_append (emitted_debug_locals, local); + rz_list_append (emitted_debug_locals, local); } debug_locals[register_num].live = false; } @@ -586,7 +586,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, case 0x6: // DBG_RESTART_LOCAL { ut64 register_num; - r_buf_uleb128 (bf->buf, ®ister_num); + rz_buf_uleb128 (bf->buf, ®ister_num); if (register_num >= regsz) { goto beach; } @@ -603,7 +603,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, case 0x9: { ut64 res; - r_buf_uleb128 (bf->buf, &res); + rz_buf_uleb128 (bf->buf, &res); source_file_idx = res - 1; } break; @@ -621,11 +621,11 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, position->source_file_idx = source_file_idx; position->address = address; position->line = line; - r_list_append (debug_positions, position); + rz_list_append (debug_positions, position); } break; } - if (r_buf_read (bf->buf, &opcode, 1) != 1) { + if (rz_buf_read (bf->buf, &opcode, 1) != 1) { break; } } @@ -634,17 +634,17 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, bf->sdb_addrinfo = sdb_new0 (); } - RListIter *iter1; + RzListIter *iter1; struct dex_debug_position_t *pos; // Loading the debug info takes too much time and nobody uses this afaik // 0.5s of 5s is spent in this loop - r_list_foreach (debug_positions, iter1, pos) { + rz_list_foreach (debug_positions, iter1, pos) { const char *line = getstr (dex, pos->source_file_idx); char offset[64] = {0}; if (!line || !*line) { continue; } - char *fileline = r_str_newf ("%s|%"PFMT64d, line, pos->line); + char *fileline = rz_str_newf ("%s|%"PFMT64d, line, pos->line); char *offset_ptr = sdb_itoa (pos->address + paddr, offset, 16); sdb_set (bf->sdb_addrinfo, offset_ptr, fileline, 0); sdb_set (bf->sdb_addrinfo, fileline, offset_ptr, 0); @@ -659,7 +659,7 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, rbindwardrow->file = strdup (line); rbindwardrow->address = pos->address; rbindwardrow->line = pos->line; - r_list_append (dex->lines_list, rbindwardrow); + rz_list_append (dex->lines_list, rbindwardrow); } else { free (rbindwardrow); } @@ -668,20 +668,20 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, goto beach; } - RListIter *iter2; + RzListIter *iter2; struct dex_debug_position_t *position; rbin->cb_printf (" positions :\n"); - r_list_foreach (debug_positions, iter2, position) { + rz_list_foreach (debug_positions, iter2, position) { rbin->cb_printf (" 0x%04"PFMT64x" line=%llu\n", position->address, position->line); } rbin->cb_printf (" locals :\n"); - RListIter *iter3; + RzListIter *iter3; struct dex_debug_local_t *local; - r_list_foreach (emitted_debug_locals, iter3, local) { + rz_list_foreach (emitted_debug_locals, iter3, local) { if (local->signature) { rbin->cb_printf ( " 0x%04x - 0x%04x reg=%d %s %s %s\n", @@ -718,22 +718,22 @@ static void dex_parse_debug_item(RBinFile *bf, RBinDexClass *c, int MI, int MA, } } beach: - r_list_free (debug_positions); - r_list_free (emitted_debug_locals); - r_list_free (params); + rz_list_free (debug_positions); + rz_list_free (emitted_debug_locals); + rz_list_free (params); free (debug_locals); } static Sdb *get_sdb(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); + rz_return_val_if_fail (bf && bf->o, NULL); RBinObject *o = bf->o; - r_return_val_if_fail (o && o->bin_obj, NULL); - struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *) o->bin_obj; + rz_return_val_if_fail (o && o->bin_obj, NULL); + struct rz_bin_dex_obj_t *bin = (struct rz_bin_dex_obj_t *) o->bin_obj; return bin->kv; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - *bin_obj = r_bin_dex_new_buf (buf); + *bin_obj = rz_bin_dex_new_buf (buf); return *bin_obj != NULL; } @@ -743,7 +743,7 @@ static ut64 baddr(RBinFile *bf) { static bool check_buffer(RBuffer *buf) { ut8 tmp[8]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); if (r < sizeof (tmp)) { return false; } @@ -784,7 +784,7 @@ static RBinInfo *info(RBinFile *bf) { ret->type = strdup ("DEX CLASS"); ret->has_va = true; ret->has_lit = true; - ret->bclass = r_bin_dex_get_version (bf->o->bin_obj); + ret->bclass = rz_bin_dex_get_version (bf->o->bin_obj); ret->rclass = strdup ("class"); ret->os = strdup ("linux"); ret->subsystem = strdup (dexSubsystem? dexSubsystem: "java"); @@ -794,25 +794,25 @@ static RBinInfo *info(RBinFile *bf) { h->len = 20; h->addr = 12; h->from = 12; - h->to = r_buf_size (bf->buf) - 32; - r_buf_read_at (bf->buf, 12, h->buf, 20); + h->to = rz_buf_size (bf->buf) - 32; + rz_buf_read_at (bf->buf, 12, h->buf, 20); h = &ret->sum[1]; h->type = "adler32"; h->len = 4; h->addr = 8; h->from = 12; - h->to = r_buf_size (bf->buf) - h->from; - r_buf_read_at (bf->buf, 8, h->buf, 12); + h->to = rz_buf_size (bf->buf) - h->from; + rz_buf_read_at (bf->buf, 8, h->buf, 12); h = &ret->sum[2]; h->type = 0; - r_buf_read_at (bf->buf, 8, h->buf, 4); - // this is slow but computed once, so we can use r_buf_data or just do r_buf_read() + rz_buf_read_at (bf->buf, 8, h->buf, 4); + // this is slow but computed once, so we can use rz_buf_data or just do rz_buf_read() // not sure if we want to expose the computed checksum everytime we open the file // also the checksum is computed by other methods in RBin, so maybe good to generalize { - ut32 fc = r_buf_read_le32_at (bf->buf, 8); + ut32 fc = rz_buf_read_le32_at (bf->buf, 8); ut64 tmpsz; - const ut8 *tmp = r_buf_data (bf->buf, &tmpsz); + const ut8 *tmp = rz_buf_data (bf->buf, &tmpsz); ut32 cc = __adler32 (tmp + 12, tmpsz - 12); if (fc != cc) { eprintf ("# adler32 checksum doesn't match. Type this to fix it:\n"); @@ -827,15 +827,15 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *strings(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); +static RzList *strings(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o, NULL); RBinString *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; int i; ut64 len; ut8 buf[LEB_MAX_SIZE]; ut64 off; - struct r_bin_dex_obj_t *bin = (struct r_bin_dex_obj_t *)bf->o->bin_obj; + struct rz_bin_dex_obj_t *bin = (struct rz_bin_dex_obj_t *)bf->o->bin_obj; if (!bin || !bin->strings) { return NULL; } @@ -843,7 +843,7 @@ static RList *strings(RBinFile *bf) { bin->strings = NULL; return NULL; } - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } for (i = 0; i < bin->header.strings_size; i++) { @@ -853,20 +853,20 @@ static RList *strings(RBinFile *bf) { if (bin->strings[i] > bin->size || bin->strings[i] + 6 > bin->size) { goto out_error; } - r_buf_read_at (bin->b, bin->strings[i], buf, sizeof (buf)); - r_uleb128 (buf, sizeof (buf), &len, NULL); + rz_buf_read_at (bin->b, bin->strings[i], buf, sizeof (buf)); + rz_uleb128 (buf, sizeof (buf), &len, NULL); if (len > 5 && len < R_BIN_SIZEOF_STRINGS) { ptr->string = malloc (len + 1); if (!ptr->string) { goto out_error; } - off = bin->strings[i] + r_uleb128_len (buf, sizeof (buf)); + off = bin->strings[i] + rz_uleb128_len (buf, sizeof (buf)); if (off + len >= bin->size || off + len < len) { free (ptr->string); goto out_error; } - r_buf_read_at (bin->b, off, (ut8*)ptr->string, len); + rz_buf_read_at (bin->b, off, (ut8*)ptr->string, len); ptr->string[len] = 0; if ((ptr->string[0] == 'L' && strchr (ptr->string, '/')) || !strncmp (ptr->string, "[L", 2)) { free (ptr->string); @@ -877,14 +877,14 @@ static RList *strings(RBinFile *bf) { ptr->size = len; ptr->length = len; ptr->ordinal = i+1; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } else { free (ptr); } } return ret; out_error: - r_list_free (ret); + rz_list_free (ret); free (ptr); return NULL; } @@ -905,16 +905,16 @@ static const char *dex_method_name(RBinDexObj *bin, int idx) { } static char *simplify(char *s) { - char *p = (char *)r_str_rchr (s, NULL, '/'); + char *p = (char *)rz_str_rchr (s, NULL, '/'); if (p) { - r_str_cpy (s, p + 1); + rz_str_cpy (s, p + 1); } - r_str_replace_char (s, '/', '.'); + rz_str_replace_char (s, '/', '.'); return s; } static char *dex_class_name_byid(RBinDexObj *bin, int cid) { - r_return_val_if_fail (bin && bin->types, NULL); + rz_return_val_if_fail (bin && bin->types, NULL); if (cid < 0 || cid >= bin->header.types_size) { return NULL; } @@ -935,7 +935,7 @@ static char *dex_class_name(RBinDexObj *bin, RBinDexClass *c) { if (simplifiedDemangling) { simplify (s); if (*s == 'L') { - r_str_cpy (s, s + 1); + rz_str_cpy (s, s + 1); } } return s; @@ -944,7 +944,7 @@ static char *dex_class_name(RBinDexObj *bin, RBinDexClass *c) { static char *dex_field_name(RBinDexObj *bin, int fid) { int tid; ut16 cid, type_id; - r_return_val_if_fail (bin && bin->fields, NULL); + rz_return_val_if_fail (bin && bin->fields, NULL); if (fid < 0 || fid >= bin->header.fields_size) { return NULL; @@ -966,24 +966,24 @@ static char *dex_field_name(RBinDexObj *bin, int fid) { char *_a = simplify (strdup (a)); char *_b = simplify (strdup (b)); char *_c = simplify (strdup (c)); - char *str = r_str_newf ("(%s) %s.%s", _c, _a, _b); + char *str = rz_str_newf ("(%s) %s.%s", _c, _a, _b); free (_a); free (_b); free (_c); return str; } - return r_str_newf ("(%d) %d.%d", + return rz_str_newf ("(%d) %d.%d", bin->types[type_id].descriptor_id, tid, bin->types[cid].descriptor_id); } return (a && b && c) - ? r_str_newf ("%s->%s %s", a, b, c) - : r_str_newf ("%d->%d %d", bin->types[cid].descriptor_id, tid, bin->types[type_id].descriptor_id); + ? rz_str_newf ("%s->%s %s", a, b, c) + : rz_str_newf ("%d->%d %d", bin->types[cid].descriptor_id, tid, bin->types[type_id].descriptor_id); } static char *dex_method_fullname(RBinDexObj *bin, int method_idx) { - r_return_val_if_fail (bin && bin->types, NULL); + rz_return_val_if_fail (bin && bin->types, NULL); if (method_idx < 0 || method_idx >= bin->header.method_size) { return NULL; } @@ -1001,13 +1001,13 @@ static char *dex_method_fullname(RBinDexObj *bin, int method_idx) { if (!class_name) { class_name = strdup ("???"); } - r_str_replace_char (class_name, ';', 0); + rz_str_replace_char (class_name, ';', 0); char *signature = dex_method_signature (bin, method_idx); if (signature) { - flagname = r_str_newf ("%s.%s%s", class_name, name, signature); + flagname = rz_str_newf ("%s.%s%s", class_name, name, signature); free (signature); } else { - flagname = r_str_newf ("%s.%s%s", class_name, name, "???"); + flagname = rz_str_newf ("%s.%s%s", class_name, name, "???"); } free (class_name); if (flagname && simplifiedDemangling) { @@ -1017,7 +1017,7 @@ static char *dex_method_fullname(RBinDexObj *bin, int method_idx) { char *q = strchr (p + 1, ')'); if (q) { simplify (q + 1); - r_str_cpy (p, q + 1); + rz_str_cpy (p, q + 1); } simplify (flagname); } @@ -1037,7 +1037,7 @@ static ut64 dex_get_type_offset(RBinFile *bf, int type_idx) { } static const char *dex_class_super_name(RBinDexObj *bin, RBinDexClass *c) { - r_return_val_if_fail (bin && bin->types && c, NULL); + rz_return_val_if_fail (bin && bin->types && c, NULL); int cid = c->super_class; if (cid < 0 || cid >= bin->header.types_size) { @@ -1049,7 +1049,7 @@ static const char *dex_class_super_name(RBinDexObj *bin, RBinDexClass *c) { static ut64 peek_uleb(RBuffer *b, bool *err, size_t *nn) { ut64 n = UT64_MAX; - int len = r_buf_uleb128 (b, &n); + int len = rz_buf_uleb128 (b, &n); if (len < 1) { if (err) { *err |= true; @@ -1082,12 +1082,12 @@ static void parse_dex_class_fields(RBinFile *bf, RBinDexClass *c, RBinClass *cls if (total >= dex->size || total < dex->header.fields_offset) { break; } - if (r_buf_read_at (bf->buf, total, ff, sizeof (DexField)) != sizeof (DexField)) { + if (rz_buf_read_at (bf->buf, total, ff, sizeof (DexField)) != sizeof (DexField)) { break; } - field.class_id = r_read_le16 (ff); - field.type_id = r_read_le16 (ff + 2); - field.name_id = r_read_le32 (ff + 4); + field.class_id = rz_read_le16 (ff); + field.type_id = rz_read_le16 (ff + 2); + field.name_id = rz_read_le32 (ff + 4); const char *fieldName = getstr (dex, field.name_id); if (field.type_id >= dex->header.types_size) { break; @@ -1099,14 +1099,14 @@ static void parse_dex_class_fields(RBinFile *bf, RBinDexClass *c, RBinClass *cls break; } if (is_sfield) { - sym->name = r_str_newf ("%s.sfield_%s:%s", cls->name, fieldName, type_str); + sym->name = rz_str_newf ("%s.sfield_%s:%s", cls->name, fieldName, type_str); sym->type = "STATIC"; } else { - sym->name = r_str_newf ("%s.ifield_%s:%s", cls->name, fieldName, type_str); + sym->name = rz_str_newf ("%s.ifield_%s:%s", cls->name, fieldName, type_str); sym->type = "FIELD"; } - sym->name = r_str_replace (sym->name, "method.", "", 0); - r_str_replace_char (sym->name, ';', 0); + sym->name = rz_str_replace (sym->name, "method.", "", 0); + rz_str_replace_char (sym->name, ';', 0); sym->paddr = sym->vaddr = total; sym->ordinal = (*sym_count)++; @@ -1120,14 +1120,14 @@ static void parse_dex_class_fields(RBinFile *bf, RBinDexClass *c, RBinClass *cls bin->cb_printf (" access : 0x%04x (%s)\n", (ut32)accessFlags, accessStr? accessStr: ""); } - r_list_append (dex->methods_list, sym); + rz_list_append (dex->methods_list, sym); RBinField *field = R_NEW0 (RBinField); if (field) { field->vaddr = field->paddr = sym->paddr; field->name = strdup (sym->name); field->flags = get_method_flags (accessFlags); - r_list_append (cls->fields, field); + rz_list_append (cls->fields, field); } lastIndex = fieldIndex; } @@ -1148,10 +1148,10 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls ut32 debug_info_off = 0, insns_size = 0; if (!dex->trycatch_list) { - dex->trycatch_list = r_list_newf ((RListFree)r_bin_trycatch_free); + dex->trycatch_list = rz_list_newf ((RzListFree)rz_bin_trycatch_free); } size_t skip = 0; - ut64 bufsz = r_buf_size (bf->buf); + ut64 bufsz = rz_buf_size (bf->buf); ut64 encoded_method_addr; bool err = false; ut64 MI, MA, MC; @@ -1159,7 +1159,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls err = false; skip = 0; // Needed because theres another rbufseek call inside this loop. must be fixed - encoded_method_addr = r_buf_tell (bf->buf); + encoded_method_addr = rz_buf_tell (bf->buf); MI = peek_uleb (bf->buf, &err, &skip); if (err) { eprintf ("Error\n"); @@ -1188,7 +1188,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls if (!method_name) { method_name = strdup ("unknown"); } - char *flag_name = r_str_newf ("%s.method.%s%s", cls->name, method_name, signature); + char *flag_name = rz_str_newf ("%s.method.%s%s", cls->name, method_name, signature); if (!flag_name || !*flag_name) { R_FREE (flag_name); R_FREE (signature); @@ -1211,27 +1211,27 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls R_FREE (signature); continue; } - regsz = r_buf_read_le16_at (bf->buf, MC); + regsz = rz_buf_read_le16_at (bf->buf, MC); if (regsz == UT16_MAX) { R_FREE (flag_name); R_FREE (signature); break; } - ins_size = r_buf_read_le16_at (bf->buf, MC + 2); + ins_size = rz_buf_read_le16_at (bf->buf, MC + 2); if (ins_size == UT16_MAX) { R_FREE (flag_name); R_FREE (signature); break; } - outs_size = r_buf_read_le16_at (bf->buf, MC + 4); - tries_size = r_buf_read_le16_at (bf->buf, MC + 6); + outs_size = rz_buf_read_le16_at (bf->buf, MC + 4); + tries_size = rz_buf_read_le16_at (bf->buf, MC + 6); if (tries_size == UT16_MAX) { R_FREE (flag_name); R_FREE (signature); break; } - debug_info_off = r_buf_read_le32_at (bf->buf, MC + 8); - insns_size = r_buf_read_le32_at (bf->buf, MC + 12); + debug_info_off = rz_buf_read_le32_at (bf->buf, MC + 8); + insns_size = rz_buf_read_le32_at (bf->buf, MC + 12); int padd = 0; if (tries_size > 0 && insns_size % 2) { padd = 2; @@ -1263,7 +1263,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } int j, m = 0; //XXX bucle controlled by tainted variable it could produces huge loop - ut64 offorig = r_buf_tell (bf->buf); + ut64 offorig = rz_buf_tell (bf->buf); for (j = 0; j < tries_size; j++) { ut64 offset = MC + t + j * 8; if (offset >= dex->size || offset < MC) { @@ -1276,14 +1276,14 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } // start address of the block of code covered by this entry. // The address is a count of 16-bit code units to the start of the first covered instruction. - start_addr = r_buf_read_le32_at (bf->buf, offset); + start_addr = rz_buf_read_le32_at (bf->buf, offset); // number of 16-bit code units covered by this entry. // The last code unit covered (inclusive) is start_addr + insn_count - 1. - insn_count = r_buf_read_le16_at (bf->buf, offset + 4); + insn_count = rz_buf_read_le16_at (bf->buf, offset + 4); // offset in bytes from the start of the associated encoded_catch_hander_list // to the encoded_catch_handler for this entry. // This must be an offset to the start of an encoded_catch_handler. - ut64 handler_off = r_buf_read_le16_at (bf->buf, offset + 6); + ut64 handler_off = rz_buf_read_le16_at (bf->buf, offset + 6); ut64 method_offset = MC + 16; ut64 try_from = (start_addr * 2) + method_offset; @@ -1292,8 +1292,8 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls if (dexdump) { cb_printf (" 0x%04x - 0x%04x\n", start_addr, (start_addr + insn_count)); } - RBinTrycatch *tc = r_bin_trycatch_new (method_offset, try_from, try_to, try_catch, 0); - r_list_append (dex->trycatch_list, tc); + RBinTrycatch *tc = rz_bin_trycatch_new (method_offset, try_from, try_to, try_catch, 0); + rz_list_append (dex->trycatch_list, tc); //XXX tries_size is tainted and oob here int off = MC + t + tries_size * 8 + handler_off; @@ -1303,10 +1303,10 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } // TODO: catch left instead of null st64 size; - if (r_buf_seek (bf->buf, off, R_BUF_SET) == -1) { + if (rz_buf_seek (bf->buf, off, R_BUF_SET) == -1) { break; } - int r = r_buf_sleb128 (bf->buf, &size); + int r = rz_buf_sleb128 (bf->buf, &size); if (r <= 0) { break; } @@ -1319,11 +1319,11 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } for (m = 0; m < size; m++) { - r = r_buf_uleb128 (bf->buf, &handler_type); + r = rz_buf_uleb128 (bf->buf, &handler_type); if (r <= 0) { break; } - r = r_buf_uleb128 (bf->buf, &handler_addr); + r = rz_buf_uleb128 (bf->buf, &handler_addr); if (r <= 0) { break; } @@ -1343,7 +1343,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } } if (catchAll) { - r = r_buf_uleb128 (bf->buf, &v2); + r = rz_buf_uleb128 (bf->buf, &v2); if (r <= 0) { break; } @@ -1352,7 +1352,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } } } - r_buf_seek (bf->buf, offorig, R_BUF_SET); + rz_buf_seek (bf->buf, offorig, R_BUF_SET); } else { if (dexdump) { cb_printf ( @@ -1394,8 +1394,8 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls R_FREE (signature); continue; } - ut16 tries_size = r_buf_read_le16_at (bf->buf, MC + 6); - ut32 insns_size = r_buf_read_le32_at (bf->buf, MC + 12); + ut16 tries_size = rz_buf_read_le16_at (bf->buf, MC + 6); + ut32 insns_size = rz_buf_read_le32_at (bf->buf, MC + 12); ut64 prolog_size = 2 + 2 + 2 + 2 + 4 + 4; if (tries_size > 0) { //prolog_size += 2 + 8*tries_size; // we need to parse all so the catch info... @@ -1407,8 +1407,8 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls sym->size = insns_size * 2; //} //eprintf("%s (0x%x-0x%x) size=%d\nregsz=%d\ninsns_size=%d\nouts_size=%d\ntries_size=%d\ninsns_size=%d\n", flag_name, sym->vaddr, sym->vaddr+sym->size, prolog_size, regsz, ins_size, outs_size, tries_size, insns_size); - r_list_append (dex->methods_list, sym); - r_list_append (cls->methods, sym); + rz_list_append (dex->methods_list, sym); + rz_list_append (cls->methods, sym); if (dex->code_from == UT64_MAX || dex->code_from > sym->paddr) { dex->code_from = sym->paddr; @@ -1436,16 +1436,16 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls #endif } else { sym->size = 0; - r_list_append (dex->methods_list, sym); - r_list_append (cls->methods, sym); + rz_list_append (dex->methods_list, sym); + rz_list_append (cls->methods, sym); } if (MC > 0 && debug_info_off > 0 && dex->header.data_offset < debug_info_off && debug_info_off < dex->header.data_offset + dex->header.data_size) { if (bin_dbginfo) { - ut64 addr = r_buf_tell (bf->buf); + ut64 addr = rz_buf_tell (bf->buf); dex_parse_debug_item (bf, c, MI, MA, sym->paddr, ins_size, insns_size, cls->name, regsz, debug_info_off); - r_buf_seek (bf->buf, addr, R_BUF_SET); + rz_buf_seek (bf->buf, addr, R_BUF_SET); } } else if (MC > 0) { if (dexdump) { @@ -1461,7 +1461,7 @@ static void parse_dex_class_method(RBinFile *bf, RBinDexClass *c, RBinClass *cls } static void parse_class(RBinFile *bf, RBinDexClass *c, int class_index, int *methods, int *sym_count) { - r_return_if_fail (bf && bf->o && c); + rz_return_if_fail (bf && bf->o && c); RBinDexObj *dex = bf->o->bin_obj; RBin *rbin = bf->rbin; @@ -1474,25 +1474,25 @@ static void parse_class(RBinFile *bf, RBinDexClass *c, int class_index, int *met if (!cls->name) { goto beach; } - r_str_replace_char (cls->name, ';', 0); + rz_str_replace_char (cls->name, ';', 0); cls->index = class_index; cls->addr = dex->header.class_offset + (class_index * DEX_CLASS_SIZE); - cls->methods = r_list_new (); + cls->methods = rz_list_new (); const char *super = dex_class_super_name (dex, c); cls->super = super? strdup (super): NULL; if (!cls->methods) { free (cls); goto beach; } - cls->fields = r_list_new (); + cls->fields = rz_list_new (); if (!cls->fields) { - r_list_free (cls->methods); + rz_list_free (cls->methods); free (cls); goto beach; } const char *str = createAccessFlagStr (c->access_flags, kAccessForClass); cls->visibility_str = strdup (str? str: ""); - r_list_append (dex->classes_list, cls); + rz_list_append (dex->classes_list, cls); if (dexdump) { rbin->cb_printf (" Class descriptor : '%s;'\n", cls->name); rbin->cb_printf (" Access flags : 0x%04x (%s)\n", c->access_flags, @@ -1504,15 +1504,15 @@ static void parse_class(RBinFile *bf, RBinDexClass *c, int class_index, int *met if (c->interfaces_offset > 0 && dex->header.data_offset < c->interfaces_offset && c->interfaces_offset < dex->header.data_offset + dex->header.data_size) { - int types_list_size = r_buf_read_le32_at (bf->buf, c->interfaces_offset); + int types_list_size = rz_buf_read_le32_at (bf->buf, c->interfaces_offset); if (types_list_size < 0 || types_list_size >= dex->header.types_size ) { goto beach; } for (z = 0; z < types_list_size; z++) { ut16 le16; ut32 off = c->interfaces_offset + 4 + (z * 2); - r_buf_read_at (bf->buf, off, (ut8*)&le16, sizeof (le16)); - int t = r_read_le16 (&le16); + rz_buf_read_at (bf->buf, off, (ut8*)&le16, sizeof (le16)); + int t = rz_read_le16 (&le16); if (t > 0 && t < dex->header.types_size ) { int tid = dex->types[t].descriptor_id; if (dexdump) { @@ -1548,7 +1548,7 @@ static void parse_class(RBinFile *bf, RBinDexClass *c, int class_index, int *met bool err = false; size_t skip = 0; - r_buf_seek (bf->buf, c->class_data_offset, R_BUF_SET); + rz_buf_seek (bf->buf, c->class_data_offset, R_BUF_SET); dc->static_fields_size = peek_uleb (bf->buf, &err, &skip); dc->instance_fields_size = peek_uleb (bf->buf, &err, &skip); dc->direct_methods_size = peek_uleb (bf->buf, &err, &skip); @@ -1601,7 +1601,7 @@ static bool is_class_idx_in_code_classes(RBinDexObj *bin, int class_idx) { } static bool dex_loadcode(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, false); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, false); PrintfCallback cb_printf = bf->rbin->cb_printf; RBinDexObj *bin = bf->o->bin_obj; @@ -1613,29 +1613,29 @@ static bool dex_loadcode(RBinFile *bf) { if (bin->methods_list) { return false; } - bin->version = r_bin_dex_get_version (bin); + bin->version = rz_bin_dex_get_version (bin); bin->code_from = UT64_MAX; bin->code_to = 0; - bin->methods_list = r_list_newf ((RListFree)free); + bin->methods_list = rz_list_newf ((RzListFree)free); if (!bin->methods_list) { return false; } - bin->imports_list = r_list_newf ((RListFree)free); + bin->imports_list = rz_list_newf ((RzListFree)free); if (!bin->imports_list) { - r_list_free (bin->methods_list); + rz_list_free (bin->methods_list); return false; } - bin->lines_list = r_list_newf ((RListFree)free); + bin->lines_list = rz_list_newf ((RzListFree)free); if (!bin->lines_list) { - r_list_free (bin->methods_list); - r_list_free (bin->imports_list); + rz_list_free (bin->methods_list); + rz_list_free (bin->imports_list); return false; } - bin->classes_list = r_list_newf ((RListFree)r_bin_class_free); + bin->classes_list = rz_list_newf ((RzListFree)rz_bin_class_free); if (!bin->classes_list) { - r_list_free (bin->methods_list); - r_list_free (bin->imports_list); - r_list_free (bin->lines_list); + rz_list_free (bin->methods_list); + rz_list_free (bin->imports_list); + rz_list_free (bin->lines_list); return false; } @@ -1706,7 +1706,7 @@ static bool dex_loadcode(RBinFile *bf) { free (class_name); continue; } - r_str_replace_char (class_name, ';', 0); + rz_str_replace_char (class_name, ';', 0); const char *method_name = dex_method_name (bin, i); char *signature = dex_method_signature (bin, i); if (!R_STR_ISEMPTY (method_name)) { @@ -1717,11 +1717,11 @@ static bool dex_loadcode(RBinFile *bf) { free (class_name); return false; } - imp->name = r_str_newf ("%s.method.%s%s", class_name, method_name, signature); + imp->name = rz_str_newf ("%s.method.%s%s", class_name, method_name, signature); imp->type = "FUNC"; imp->bind = "NONE"; imp->ordinal = import_count++; - r_list_append (bin->imports_list, imp); + rz_list_append (bin->imports_list, imp); RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { @@ -1735,10 +1735,10 @@ static bool dex_loadcode(RBinFile *bf) { sym->type = R_BIN_TYPE_FUNC_STR; sym->bind = "NONE"; //XXX so damn unsafe check buffer boundaries!!!! - //XXX use r_buf API!! + //XXX use rz_buf API!! sym->paddr = sym->vaddr = bin->header.method_offset + (sizeof (struct dex_method_t) * i) ; sym->ordinal = sym_count++; - r_list_append (bin->methods_list, sym); + rz_list_append (bin->methods_list, sym); const char *mname = sdb_fmt ("method.%"PFMT64d, (ut64)i); sdb_num_set (mdb, mname, sym->paddr, 0); } @@ -1750,8 +1750,8 @@ static bool dex_loadcode(RBinFile *bf) { return true; } -static RList* imports(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList* imports(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinDexObj *bin = (RBinDexObj*) bf->o->bin_obj; if (!bin->imports_list) { dex_loadcode (bf); @@ -1759,8 +1759,8 @@ static RList* imports(RBinFile *bf) { return bin->imports_list; } -static RList *trycatch(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList *trycatch(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinDexObj *bin = (RBinDexObj*) bf->o->bin_obj; if (!bin->trycatch_list) { dex_loadcode (bf); @@ -1768,8 +1768,8 @@ static RList *trycatch(RBinFile *bf) { return bin->trycatch_list; } -static RList *methods(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList *methods(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinDexObj *bin = (RBinDexObj*) bf->o->bin_obj; if (!bin->methods_list) { dex_loadcode (bf); @@ -1777,8 +1777,8 @@ static RList *methods(RBinFile *bf) { return bin->methods_list; } -static RList *classes(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList *classes(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinDexObj *bin = (RBinDexObj*) bf->o->bin_obj; if (!bin->classes_list) { dex_loadcode (bf); @@ -1786,10 +1786,10 @@ static RList *classes(RBinFile *bf) { return bin->classes_list; } -static bool already_entry(RList *entries, ut64 vaddr) { +static bool already_entry(RzList *entries, ut64 vaddr) { RBinAddr *e; - RListIter *iter; - r_list_foreach (entries, iter, e) { + RzListIter *iter; + rz_list_foreach (entries, iter, e) { if (e->vaddr == vaddr) { return true; } @@ -1797,22 +1797,22 @@ static bool already_entry(RList *entries, ut64 vaddr) { return false; } -static RList *entries(RBinFile *bf) { - RListIter *iter; +static RzList *entries(RBinFile *bf) { + RzListIter *iter; RBinSymbol *m; RBinAddr *ptr; - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinDexObj *bin = (RBinDexObj*) bf->o->bin_obj; - RList *ret = r_list_newf ((RListFree)free); + RzList *ret = rz_list_newf ((RzListFree)free); if (!bin->methods_list) { dex_loadcode (bf); } // STEP 1. ".onCreate(Landroid/os/Bundle;)V" - r_list_foreach (bin->methods_list, iter, m) { + rz_list_foreach (bin->methods_list, iter, m) { if (strlen (m->name) > 30 && m->bind && (!strcmp (m->bind, R_BIN_BIND_LOCAL_STR) || !strcmp (m->bind, R_BIN_BIND_GLOBAL_STR)) && !strcmp (m->name + strlen (m->name) - 31, @@ -1820,22 +1820,22 @@ static RList *entries(RBinFile *bf) { if (!already_entry (ret, m->paddr)) { if ((ptr = R_NEW0 (RBinAddr))) { ptr->paddr = ptr->vaddr = m->paddr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } } } // STEP 2. ".main([Ljava/lang/String;)V" - if (r_list_empty (ret)) { - r_list_foreach (bin->methods_list, iter, m) { + if (rz_list_empty (ret)) { + rz_list_foreach (bin->methods_list, iter, m) { if (strlen (m->name) > 26 && !strcmp (m->name + strlen (m->name) - 27, ".main([Ljava/lang/String;)V")) { if (!already_entry (ret, m->paddr)) { if ((ptr = R_NEW0 (RBinAddr))) { ptr->paddr = ptr->vaddr = m->paddr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } } @@ -1844,12 +1844,12 @@ static RList *entries(RBinFile *bf) { #if 0 // this is now done by r2 in a generic way // STEP 3. NOTHING FOUND POINT TO CODE_INIT - if (r_list_empty (ret)) { + if (rz_list_empty (ret)) { if (!already_entry (ret, bin->code_from)) { ptr = R_NEW0 (RBinAddr); if (ptr) { ptr->paddr = ptr->vaddr = bin->code_from; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } } @@ -1858,7 +1858,7 @@ static RList *entries(RBinFile *bf) { } static int getoffset(RBinFile *bf, int type, int idx) { - struct r_bin_dex_obj_t *dex = bf->o->bin_obj; + struct rz_bin_dex_obj_t *dex = bf->o->bin_obj; switch (type) { case 'm': // methods // TODO: ADD CHECK @@ -1885,7 +1885,7 @@ static int getoffset(RBinFile *bf, int type, int idx) { static char *getname(RBinFile *bf, int type, int idx, bool sd) { simplifiedDemangling = sd; // XXX kill globals - struct r_bin_dex_obj_t *dex = bf->o->bin_obj; + struct rz_bin_dex_obj_t *dex = bf->o->bin_obj; switch (type) { case 'm': // methods return dex_method_fullname (dex, idx); @@ -1904,10 +1904,10 @@ typedef struct { ut64 size; } Section; -static RBinSection *add_section(RList *ret, const char *name, Section s, int perm, char *format) { - r_return_val_if_fail (ret && name, NULL); - r_return_val_if_fail (s.addr < UT32_MAX, NULL); - r_return_val_if_fail (s.size > 0 && s.size < UT32_MAX, NULL); +static RBinSection *add_section(RzList *ret, const char *name, Section s, int perm, char *format) { + rz_return_val_if_fail (ret && name, NULL); + rz_return_val_if_fail (s.addr < UT32_MAX, NULL); + rz_return_val_if_fail (s.size > 0 && s.size < UT32_MAX, NULL); RBinSection *ptr = R_NEW0 (RBinSection); if (ptr) { ptr->name = strdup (name); @@ -1918,12 +1918,12 @@ static RBinSection *add_section(RList *ret, const char *name, Section s, int per if (format) { ptr->format = format; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ptr; } -static void add_segment(RList *ret, const char *name, Section s, int perm) { +static void add_segment(RzList *ret, const char *name, Section s, int perm) { RBinSection *bs = add_section (ret, name, s, perm, NULL); if (bs) { bs->is_segment = true; @@ -1932,7 +1932,7 @@ static void add_segment(RList *ret, const char *name, Section s, int perm) { } static bool validate_section(const char *name, Section *pre, Section *cur, Section *nex, Section *all) { - r_return_val_if_fail (cur && all, false); + rz_return_val_if_fail (cur && all, false); if (pre && cur->addr < (pre->addr + pre->size)) { eprintf ("Warning: %s Section starts before the previous.\n", name); } @@ -1962,14 +1962,14 @@ static bool validate_section(const char *name, Section *pre, Section *cur, Secti } static void fast_code_size(RBinFile *bf) { - const size_t bs = r_buf_size (bf->buf); + const size_t bs = rz_buf_size (bf->buf); ut64 ns; ut64 fsym = 0LL; ut64 fsymsz = 0LL; - RListIter *iter; + RzListIter *iter; RBinSymbol *m; - RList *ml = methods (bf); - r_list_foreach (ml, iter, m) { + RzList *ml = methods (bf); + rz_list_foreach (ml, iter, m) { if (!fsym || m->paddr < fsym) { fsym = m->paddr; } @@ -1981,21 +1981,21 @@ static void fast_code_size(RBinFile *bf) { fsymsz = ns; } } - struct r_bin_dex_obj_t *bin = bf->o->bin_obj; + struct rz_bin_dex_obj_t *bin = bf->o->bin_obj; bin->code_from = fsym; bin->code_to = fsymsz; } -static RList *sections(RBinFile *bf) { - struct r_bin_dex_obj_t *bin = bf->o->bin_obj; - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + struct rz_bin_dex_obj_t *bin = bf->o->bin_obj; + RzList *ret = NULL; /* find the last method */ - const size_t bs = r_buf_size (bf->buf); + const size_t bs = rz_buf_size (bf->buf); if (!bin->code_from || !bin->code_to) { fast_code_size (bf); } - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } @@ -2011,7 +2011,7 @@ static RList *sections(RBinFile *bf) { add_section (ret, "header", s_head, R_PERM_R, NULL); } if (validate_section ("constpool", &s_head, &s_pool, &s_code, &s_file)) { - char *s_pool_format = r_str_newf ("Cd %d[%"PFMT64d"]", 4, (ut64) s_pool.size / 4); + char *s_pool_format = rz_str_newf ("Cd %d[%"PFMT64d"]", 4, (ut64) s_pool.size / 4); add_section (ret, "constpool", s_pool, R_PERM_R, s_pool_format); } if (validate_section ("code", &s_pool, &s_code, &s_data, &s_file)) { @@ -2070,26 +2070,26 @@ static void dex_header(RBinFile *bf) { static ut64 size(RBinFile *bf) { ut8 u32s[sizeof (ut32)] = {0}; - int ret = r_buf_read_at (bf->buf, 108, u32s, 4); + int ret = rz_buf_read_at (bf->buf, 108, u32s, 4); if (ret != 4) { return 0; } - ut32 off = r_read_le32 (u32s); - ret = r_buf_read_at (bf->buf, 104, u32s, 4); + ut32 off = rz_read_le32 (u32s); + ret = rz_buf_read_at (bf->buf, 104, u32s, 4); if (ret != 4) { return 0; } - return off + r_read_le32 (u32s); + return off + rz_read_le32 (u32s); } -static R_BORROW RList *lines(RBinFile *bf) { - struct r_bin_dex_obj_t *dex = bf->o->bin_obj; +static R_BORROW RzList *lines(RBinFile *bf) { + struct rz_bin_dex_obj_t *dex = bf->o->bin_obj; return dex->lines_list; } // iH* -static RList *dex_fields(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList *dex_fields(RBinFile *bf) { + RzList *ret = rz_list_new (); if (!ret) { return NULL; } @@ -2097,21 +2097,21 @@ static RList *dex_fields(RBinFile *bf) { ut64 addr = 0; #define ROW(nam,siz,val,fmt) \ - r_list_append (ret, r_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08"PFMT64x, (ut64)val), fmt, false)); \ + rz_list_append (ret, rz_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08"PFMT64x, (ut64)val), fmt, false)); \ addr += siz; - r_buf_seek (bf->buf, 0, R_BUF_SET); - ut64 magic = r_buf_read_le64 (bf->buf); + rz_buf_seek (bf->buf, 0, R_BUF_SET); + ut64 magic = rz_buf_read_le64 (bf->buf); ROW ("dex_magic", 8, magic, "[8]c"); - ut32 checksum = r_buf_read_le32 (bf->buf); + ut32 checksum = rz_buf_read_le32 (bf->buf); ROW ("dex_checksum", 4, checksum, "x"); ut8 signature[20]; ROW ("dex_signature", 8, signature, "[20]c"); - ut32 size = r_buf_read_le32 (bf->buf); + ut32 size = rz_buf_read_le32 (bf->buf); ROW ("dex_size", 4, size, "x"); - ut32 header_size = r_buf_read_le32 (bf->buf); + ut32 header_size = rz_buf_read_le32 (bf->buf); ROW ("dex_header_size", 4, header_size, "x"); - ut32 endian = r_buf_read_le32 (bf->buf); + ut32 endian = rz_buf_read_le32 (bf->buf); ROW ("dex_endian", 4, endian, "x"); /* ROW ("hdr.cputype", 4, mh->cputype, "x"); @@ -2131,54 +2131,54 @@ static int cmp_path(const void *a, const void *b) { } static bool is_classes_dex(const char *filename) { - return r_str_startswith (filename, "classes") \ - && r_str_endswith (filename, ".dex"); + return rz_str_startswith (filename, "classes") \ + && rz_str_endswith (filename, ".dex"); } -static RList* libs(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - char *path = r_file_dirname (bf->file); - if (r_str_startswith (path, "./")) { +static RzList* libs(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + char *path = rz_file_dirname (bf->file); + if (rz_str_startswith (path, "./")) { // avoids stuff like .//.//.//.//.// free (path); return NULL; } - RList *files = r_sys_dir (path); + RzList *files = rz_sys_dir (path); if (!files) { free (path); return NULL; } - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { free (path); - r_list_free (files); + rz_list_free (files); return NULL; } /* opening dex files in order. */ - r_list_sort (files, cmp_path); - RListIter *iter; + rz_list_sort (files, cmp_path); + RzListIter *iter; char *file; - r_list_foreach (files, iter, file) { + rz_list_foreach (files, iter, file) { if (is_classes_dex (file)) { - char *n = r_str_newf ("%s%s%s", path, R_SYS_DIR, file); + char *n = rz_str_newf ("%s%s%s", path, R_SYS_DIR, file); if (strcmp (n, bf->file)) { - r_list_append (ret, n); + rz_list_append (ret, n); } free (n); } } - r_list_free (files); + rz_list_free (files); free (path); return ret; } static void destroy(RBinFile *bf) { - r_return_if_fail (bf && bf->o); + rz_return_if_fail (bf && bf->o); RBinDexObj *obj = bf->o->bin_obj; - r_bin_dex_free (obj); + rz_bin_dex_free (obj); } -RBinPlugin r_bin_plugin_dex = { +RBinPlugin rz_bin_plugin_dex = { .name = "dex", .desc = "dex format bin plugin", .license = "LGPL3", @@ -2201,14 +2201,14 @@ RBinPlugin r_bin_plugin_dex = { .size = &size, .get_offset = &getoffset, .get_name = &getname, - .dbginfo = &r_bin_dbginfo_dex, + .dbginfo = &rz_bin_dbginfo_dex, .lines = &lines, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_dex, + .data = &rz_bin_plugin_dex, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_dmp64.c b/librz/bin/p/bin_dmp64.c similarity index 74% rename from libr/bin/p/bin_dmp64.c rename to librz/bin/p/bin_dmp64.c index b943ee4bfa..a0c11f59a1 100644 --- a/libr/bin/p/bin_dmp64.c +++ b/librz/bin/p/bin_dmp64.c @@ -1,26 +1,26 @@ -/* radare2 - LGPL - Copyright 2020 - abcSup */ +/* rizin - LGPL - Copyright 2020 - abcSup */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "dmp/dmp64.h" static Sdb *get_sdb(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); - struct r_bin_dmp64_obj_t *obj = (struct r_bin_dmp64_obj_t *)bf->o->bin_obj; + rz_return_val_if_fail (bf && bf->o, NULL); + struct rz_bin_dmp64_obj_t *obj = (struct rz_bin_dmp64_obj_t *)bf->o->bin_obj; return (obj && obj->kv) ? obj->kv: NULL; } static void destroy(RBinFile *bf) { - r_bin_dmp64_free ((struct r_bin_dmp64_obj_t*)bf->o->bin_obj); + rz_bin_dmp64_free ((struct rz_bin_dmp64_obj_t*)bf->o->bin_obj); } static void header(RBinFile *bf) { - struct r_bin_dmp64_obj_t *obj = (struct r_bin_dmp64_obj_t *)bf->o->bin_obj; - struct r_bin_t *rbin = bf->rbin; + struct rz_bin_dmp64_obj_t *obj = (struct rz_bin_dmp64_obj_t *)bf->o->bin_obj; + struct rz_bin_t *rbin = bf->rbin; rbin->cb_printf ("DUMP_HEADER64:\n"); rbin->cb_printf (" MajorVersion : 0x%08"PFMT32x"\n", obj->header->MajorVersion); rbin->cb_printf (" MinorVersion : 0x%08"PFMT32x"\n", obj->header->MinorVersion); @@ -53,7 +53,7 @@ static RBinInfo *info(RBinFile *bf) { if (!(ret = R_NEW0 (RBinInfo))) { return NULL; } - struct r_bin_dmp64_obj_t *obj = (struct r_bin_dmp64_obj_t *)bf->o->bin_obj; + struct rz_bin_dmp64_obj_t *obj = (struct rz_bin_dmp64_obj_t *)bf->o->bin_obj; ret->arch = strdup ("x86"); ret->bits = 64; @@ -64,17 +64,17 @@ static RBinInfo *info(RBinFile *bf) { switch (obj->header->ProductType) { case MDMP_VER_NT_WORKSTATION: - ret->os = r_str_newf ("Windows NT Workstation %d.%d", + ret->os = rz_str_newf ("Windows NT Workstation %d.%d", obj->header->MajorVersion, obj->header->MinorVersion); break; case MDMP_VER_NT_DOMAIN_CONTROLLER: - ret->os = r_str_newf ("Windows NT Server Domain Controller %d.%d", + ret->os = rz_str_newf ("Windows NT Server Domain Controller %d.%d", obj->header->MajorVersion, obj->header->MinorVersion); break; case MDMP_VER_NT_SERVER: - ret->os = r_str_newf ("Windows NT Server %d.%d", + ret->os = rz_str_newf ("Windows NT Server %d.%d", obj->header->MajorVersion, obj->header->MinorVersion); break; @@ -85,18 +85,18 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { dmp_page_desc *page; - RList *ret; - RListIter *it; + RzList *ret; + RzListIter *it; RBinSection *ptr; - struct r_bin_dmp64_obj_t *obj = (struct r_bin_dmp64_obj_t *)bf->o->bin_obj; + struct rz_bin_dmp64_obj_t *obj = (struct rz_bin_dmp64_obj_t *)bf->o->bin_obj; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - r_list_foreach (obj->pages, it, page) { + rz_list_foreach (obj->pages, it, page) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; } @@ -109,14 +109,14 @@ static RList *sections(RBinFile *bf) { ptr->add = true; ptr->perm = R_PERM_R; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (buf, false); - struct r_bin_dmp64_obj_t *res = r_bin_dmp64_new_buf (buf); + rz_return_val_if_fail (buf, false); + struct rz_bin_dmp64_obj_t *res = rz_bin_dmp64_new_buf (buf); if (res) { sdb_ns_set (sdb, "info", res->kv); *bin_obj = res; @@ -127,15 +127,15 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd static bool check_buffer(RBuffer *b) { ut8 magic[8]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) == 8) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) == 8) { return !memcmp (magic, DMP64_MAGIC, 8); } return false; } -RBinPlugin r_bin_plugin_dmp64 = { +RBinPlugin rz_bin_plugin_dmp64 = { .name = "dmp64", - .desc = "Windows Crash Dump x64 r_bin plugin", + .desc = "Windows Crash Dump x64 rz_bin plugin", .license = "LGPL3", .destroy = &destroy, .get_sdb = &get_sdb, @@ -147,9 +147,9 @@ RBinPlugin r_bin_plugin_dmp64 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_dmp64, + .data = &rz_bin_plugin_dmp64, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_dol.c b/librz/bin/p/bin_dol.c similarity index 76% rename from libr/bin/p/bin_dol.c rename to librz/bin/p/bin_dol.c index c443476f58..afb75103e8 100644 --- a/libr/bin/p/bin_dol.c +++ b/librz/bin/p/bin_dol.c @@ -1,9 +1,9 @@ /* radare - LGPL - 2015-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include /* @@ -40,10 +40,10 @@ typedef struct { static bool check_buffer(RBuffer *buf) { ut8 tmp[6]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); bool one = r == sizeof (tmp) && !memcmp (tmp, "\x00\x00\x01\x00\x00\x00", sizeof (tmp)); if (one) { - int r = r_buf_read_at (buf, 6, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 6, tmp, sizeof (tmp)); if (r != 6) { return false; } @@ -53,7 +53,7 @@ static bool check_buffer(RBuffer *buf) { } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - if (r_buf_size (buf) < sizeof (DolHeader)) { + if (rz_buf_size (buf) < sizeof (DolHeader)) { return false; } DolHeader *dol = R_NEW0 (DolHeader); @@ -64,13 +64,13 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd if (!lowername) { goto dol_err; } - r_str_case (lowername, 0); + rz_str_case (lowername, 0); char *ext = strstr (lowername, ".dol"); if (!ext || ext[4] != 0) { goto lowername_err; } free (lowername); - r_buf_fread_at (bf->buf, 0, (void *) dol, "67I", 1); + rz_buf_fread_at (bf->buf, 0, (void *) dol, "67I", 1); *bin_obj = dol; return true; @@ -81,13 +81,13 @@ dol_err: return false; } -static RList *sections(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList *sections(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); int i; - RList *ret; + RzList *ret; RBinSection *s; DolHeader *dol = bf->o->bin_obj; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } @@ -97,14 +97,14 @@ static RList *sections(RBinFile *bf) { continue; } s = R_NEW0 (RBinSection); - s->name = r_str_newf ("text_%d", i); + s->name = rz_str_newf ("text_%d", i); s->paddr = dol->text_paddr[i]; s->vaddr = dol->text_vaddr[i]; s->size = dol->text_size[i]; s->vsize = s->size; - s->perm = r_str_rwx ("r-x"); + s->perm = rz_str_rwx ("r-x"); s->add = true; - r_list_append (ret, s); + rz_list_append (ret, s); } /* data sections */ for (i = 0; i < N_DATA; i++) { @@ -112,14 +112,14 @@ static RList *sections(RBinFile *bf) { continue; } s = R_NEW0 (RBinSection); - s->name = r_str_newf ("data_%d", i); + s->name = rz_str_newf ("data_%d", i); s->paddr = dol->data_paddr[i]; s->vaddr = dol->data_vaddr[i]; s->size = dol->data_size[i]; s->vsize = s->size; - s->perm = r_str_rwx ("r--"); + s->perm = rz_str_rwx ("r--"); s->add = true; - r_list_append (ret, s); + rz_list_append (ret, s); } /* bss section */ s = R_NEW0 (RBinSection); @@ -128,26 +128,26 @@ static RList *sections(RBinFile *bf) { s->vaddr = dol->bss_addr; s->size = dol->bss_size; s->vsize = s->size; - s->perm = r_str_rwx ("rw-"); + s->perm = rz_str_rwx ("rw-"); s->add = true; - r_list_append (ret, s); + rz_list_append (ret, s); return ret; } -static RList *entries(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - RList *ret = r_list_new (); +static RzList *entries(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + RzList *ret = rz_list_new (); RBinAddr *addr = R_NEW0 (RBinAddr); DolHeader *dol = bf->o->bin_obj; addr->vaddr = (ut64) dol->entrypoint; addr->paddr = addr->vaddr & 0xFFFF; - r_list_append (ret, addr); + rz_list_append (ret, addr); return ret; } static RBinInfo *info(RBinFile *bf) { - r_return_val_if_fail (bf && bf->buf, NULL); + rz_return_val_if_fail (bf && bf->buf, NULL); RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) { return NULL; @@ -168,7 +168,7 @@ static ut64 baddr(RBinFile *bf) { return 0x80b00000; // XXX } -RBinPlugin r_bin_plugin_dol = { +RBinPlugin rz_bin_plugin_dol = { .name = "dol", .desc = "Nintendo Dolphin binary format", .license = "BSD", @@ -181,9 +181,9 @@ RBinPlugin r_bin_plugin_dol = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_dol, + .data = &rz_bin_plugin_dol, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_dyldcache.c b/librz/bin/p/bin_dyldcache.c similarity index 85% rename from libr/bin/p/bin_dyldcache.c rename to librz/bin/p/bin_dyldcache.c index 692109580c..199c9ec58e 100644 --- a/libr/bin/p/bin_dyldcache.c +++ b/librz/bin/p/bin_dyldcache.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2018 - pancake */ +/* rizin - LGPL - Copyright 2018 - pancake */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // #include "../format/mach0/mach0_defines.h" #define R_BIN_MACH064 1 #include "../format/mach0/mach0.h" @@ -84,9 +84,9 @@ typedef struct { typedef struct _r_dyldcache { ut8 magic[8]; - RList *bins; + RzList *bins; RBuffer *buf; - int (*original_io_read)(RIO *io, RIODesc *fd, ut8 *buf, int count); + int (*original_io_read)(RzIO *io, RzIODesc *fd, ut8 *buf, int count); RDyldRebaseInfos *rebase_infos; cache_hdr_t *hdr; cache_map_t *maps; @@ -99,7 +99,7 @@ typedef struct _r_bin_image { ut64 header_at; } RDyldBinImage; -static RList * pending_bin_files = NULL; +static RzList * pending_bin_files = NULL; static ut64 va2pa(uint64_t addr, cache_hdr_t *hdr, cache_map_t *maps, RBuffer *cache_buf, ut64 slide, ut32 *offset, ut32 *left); @@ -161,7 +161,7 @@ static void rebase_info_free(RDyldRebaseInfo *rebase_info) { } } -static RDyldLocSym *r_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { +static RDyldLocSym *rz_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { if (!cache_buf || !hdr || !hdr->localSymbolsSize || !hdr->localSymbolsOffset) { return NULL; } @@ -176,7 +176,7 @@ static RDyldLocSym *r_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { if (!info) { goto beach; } - if (r_buf_fread_at (cache_buf, hdr->localSymbolsOffset, (ut8*) info, "6i", 1) != info_size) { + if (rz_buf_fread_at (cache_buf, hdr->localSymbolsOffset, (ut8*) info, "6i", 1) != info_size) { goto beach; } @@ -185,7 +185,7 @@ static RDyldLocSym *r_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { if (!nlists) { goto beach; } - if (r_buf_fread_at (cache_buf, hdr->localSymbolsOffset + info->nlistOffset, (ut8*) nlists, "iccsl", + if (rz_buf_fread_at (cache_buf, hdr->localSymbolsOffset + info->nlistOffset, (ut8*) nlists, "iccsl", info->nlistCount) != nlists_size) { goto beach; } @@ -194,7 +194,7 @@ static RDyldLocSym *r_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { if (!strings) { goto beach; } - if (r_buf_read_at (cache_buf, hdr->localSymbolsOffset + info->stringsOffset, (ut8*) strings, + if (rz_buf_read_at (cache_buf, hdr->localSymbolsOffset + info->stringsOffset, (ut8*) strings, info->stringsSize) != info->stringsSize) { goto beach; } @@ -204,7 +204,7 @@ static RDyldLocSym *r_dyld_locsym_new(RBuffer *cache_buf, cache_hdr_t *hdr) { if (!entries) { goto beach; } - if (r_buf_fread_at (cache_buf, hdr->localSymbolsOffset + info->entriesOffset, (ut8*) entries, "3i", + if (rz_buf_fread_at (cache_buf, hdr->localSymbolsOffset + info->entriesOffset, (ut8*) entries, "3i", info->entriesCount) != entries_size) { goto beach; } @@ -235,7 +235,7 @@ beach: return NULL; } -static void r_dyld_locsym_free(RDyldLocSym *locsym) { +static void rz_dyld_locsym_free(RDyldLocSym *locsym) { if (!locsym) { return; } @@ -260,7 +260,7 @@ static ut64 rebase_infos_get_slide(RDyldCache *cache) { return 0; } -static void r_dyld_locsym_entries_by_offset(RDyldCache *cache, RList *symbols, HtPP *hash, ut64 bin_header_offset) { +static void rz_dyld_locsym_entries_by_offset(RDyldCache *cache, RzList *symbols, HtPP *hash, ut64 bin_header_offset) { RDyldLocSym *locsym = cache->locsym; if (!locsym->entries) { return; @@ -311,25 +311,25 @@ static void r_dyld_locsym_entries_by_offset(RDyldCache *cache, RList *symbols, H } } if (len > 0) { - sym->name = r_str_ndup (symstr, len); + sym->name = rz_str_ndup (symstr, len); } else { - sym->name = r_str_newf ("unk_local%d", k); + sym->name = rz_str_newf ("unk_local%d", k); } - r_list_append (symbols, sym); + rz_list_append (symbols, sym); } break; } } -static void r_dyldcache_free(RDyldCache *cache) { +static void rz_dyldcache_free(RDyldCache *cache) { if (!cache) { return; } - r_list_free (cache->bins); + rz_list_free (cache->bins); cache->bins = NULL; - r_buf_free (cache->buf); + rz_buf_free (cache->buf); cache->buf = NULL; if (cache->rebase_infos) { int i; @@ -343,7 +343,7 @@ static void r_dyldcache_free(RDyldCache *cache) { R_FREE (cache->hdr); R_FREE (cache->maps); R_FREE (cache->accel); - r_dyld_locsym_free (cache->locsym); + rz_dyld_locsym_free (cache->locsym); R_FREE (cache); } @@ -448,9 +448,9 @@ static ut64 estimate_slide(RBinFile *bf, RDyldCache *cache, ut64 value_mask) { goto beach; } - RListIter *iter; + RzListIter *iter; RDyldBinImage *bin; - r_list_foreach (cache->bins, iter, bin) { + rz_list_foreach (cache->bins, iter, bin) { bool found_sample = false; struct MACH0_(opts_t) opts; @@ -494,7 +494,7 @@ static ut64 estimate_slide(RBinFile *bf, RDyldCache *cache, ut64 value_mask) { int classlist_sample_size = R_MIN (64, sections[classlist_idx].size); int n_classes = classlist_sample_size / 8; - if (r_buf_fread_at (cache->buf, sections[classlist_idx].offset, (ut8*) classlist, "l", n_classes) < classlist_sample_size) { + if (rz_buf_fread_at (cache->buf, sections[classlist_idx].offset, (ut8*) classlist, "l", n_classes) < classlist_sample_size) { goto next_bin; } @@ -533,14 +533,14 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl ut64 offset = slideInfoOffset; ut32 slide_info_version = 0; - if (r_buf_read_at (cache_buf, offset, (ut8*) &slide_info_version, 4) != 4) { + if (rz_buf_read_at (cache_buf, offset, (ut8*) &slide_info_version, 4) != 4) { return NULL; } if (slide_info_version == 3) { cache_slide3_t slide_info; ut64 size = sizeof (cache_slide3_t); - if (r_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "4i1l", 1) < 20) { + if (rz_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "4i1l", 1) < 20) { return NULL; } @@ -556,7 +556,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl if (!tmp_buf_1) { goto beach; } - if (r_buf_fread_at (cache_buf, page_starts_offset, tmp_buf_1, "s", slide_info.page_starts_count) != page_starts_size) { + if (rz_buf_fread_at (cache_buf, page_starts_offset, tmp_buf_1, "s", slide_info.page_starts_count) != page_starts_size) { goto beach; } } @@ -595,7 +595,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl } else if (slide_info_version == 2 || slide_info_version == 4) { cache_slide2_t slide_info; ut64 size = sizeof (cache_slide2_t); - if (r_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "6i2l", 1) != size) { + if (rz_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "6i2l", 1) != size) { return NULL; } @@ -618,7 +618,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl if (!tmp_buf_1) { goto beach; } - if (r_buf_fread_at (cache_buf, at, tmp_buf_1, "s", slide_info.page_starts_count) != size) { + if (rz_buf_fread_at (cache_buf, at, tmp_buf_1, "s", slide_info.page_starts_count) != size) { goto beach; } } @@ -630,7 +630,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl if (!tmp_buf_2) { goto beach; } - if (r_buf_fread_at (cache_buf, at, tmp_buf_2, "s", slide_info.page_extras_count) != size) { + if (rz_buf_fread_at (cache_buf, at, tmp_buf_2, "s", slide_info.page_extras_count) != size) { goto beach; } } @@ -672,7 +672,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl } else if (slide_info_version == 1) { cache_slide1_t slide_info; ut64 size = sizeof (cache_slide1_t); - if (r_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "6i", 1) != size) { + if (rz_buf_fread_at (cache_buf, offset, (ut8*) &slide_info, "6i", 1) != size) { return NULL; } @@ -695,7 +695,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl if (!tmp_buf_1) { goto beach; } - if (r_buf_fread_at (cache_buf, at, tmp_buf_1, "s", slide_info.toc_count) != size) { + if (rz_buf_fread_at (cache_buf, at, tmp_buf_1, "s", slide_info.toc_count) != size) { goto beach; } } @@ -707,7 +707,7 @@ static RDyldRebaseInfo *get_rebase_info(RBinFile *bf, RDyldCache *cache, ut64 sl if (!tmp_buf_2) { goto beach; } - if (r_buf_read_at (cache_buf, at, tmp_buf_2, size) != size) { + if (rz_buf_read_at (cache_buf, at, tmp_buf_2, size) != size) { goto beach; } } @@ -763,10 +763,10 @@ static RDyldRebaseInfos *get_rebase_infos(RBinFile *bf, RDyldCache *cache) { if (!cache->hdr->slideInfoOffset || !cache->hdr->slideInfoSize) { ut64 slide_infos_offset; size_t n_slide_infos; - if ((slide_infos_offset = r_buf_read_le32_at (cache_buf, 0x138)) == UT32_MAX) { + if ((slide_infos_offset = rz_buf_read_le32_at (cache_buf, 0x138)) == UT32_MAX) { goto beach; } - if ((n_slide_infos = r_buf_read_le32_at (cache_buf, 0x13c)) == UT32_MAX) { + if ((n_slide_infos = rz_buf_read_le32_at (cache_buf, 0x13c)) == UT32_MAX) { goto beach; } @@ -780,7 +780,7 @@ static RDyldRebaseInfos *get_rebase_infos(RBinFile *bf, RDyldCache *cache) { for (i = 0, j = 0; i < n_slide_infos; i++) { ut64 offset = slide_infos_offset + i * sizeof (cache_mapping_slide); cache_mapping_slide entry; - if (r_buf_fread_at (cache_buf, offset, (ut8*)&entry, "6lii", 1) != sizeof (cache_mapping_slide)) { + if (rz_buf_fread_at (cache_buf, offset, (ut8*)&entry, "6lii", 1) != sizeof (cache_mapping_slide)) { free (infos); goto beach; } @@ -838,14 +838,14 @@ beach: } static bool check_buffer(RBuffer *buf) { - if (r_buf_size (buf) < 32) { + if (rz_buf_size (buf) < 32) { return false; } ut8 hdr[4]; ut8 arch[9] = { 0 }; - int rarch = r_buf_read_at (buf, 9, arch, sizeof (arch) - 1); - int rhdr = r_buf_read_at (buf, 0, hdr, sizeof (hdr)); + int rarch = rz_buf_read_at (buf, 9, arch, sizeof (arch) - 1); + int rhdr = rz_buf_read_at (buf, 0, hdr, sizeof (hdr)); if (rhdr != sizeof (hdr) || memcmp (hdr, "dyld", 4)) { return false; } @@ -866,7 +866,7 @@ static cache_img_t *read_cache_images(RBuffer *cache_buf, cache_hdr_t *hdr) { return NULL; } - if (r_buf_fread_at (cache_buf, hdr->imagesOffset, (ut8*) images, "3l2i", hdr->imagesCount) != size) { + if (rz_buf_fread_at (cache_buf, hdr->imagesOffset, (ut8*) images, "3l2i", hdr->imagesCount) != size) { R_FREE (images); return NULL; } @@ -885,7 +885,7 @@ static cache_imgxtr_t *read_cache_imgextra(RBuffer *cache_buf, cache_hdr_t *hdr, return NULL; } - if (r_buf_fread_at (cache_buf, accel->imagesExtrasOffset, (ut8*) images, "ll4i", accel->imageExtrasCount) != size) { + if (rz_buf_fread_at (cache_buf, accel->imagesExtrasOffset, (ut8*) images, "ll4i", accel->imageExtrasCount) != size) { R_FREE (images); return NULL; } @@ -896,7 +896,7 @@ static cache_imgxtr_t *read_cache_imgextra(RBuffer *cache_buf, cache_hdr_t *hdr, static char *get_lib_name(RBuffer *cache_buf, cache_img_t *img) { char file[256]; char *lib_name = file; - if (r_buf_read_at (cache_buf, img->pathFileOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { + if (rz_buf_read_at (cache_buf, img->pathFileOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { file[255] = 0; /*char * last_slash = strrchr (file, '/'); if (last_slash && *last_slash) { @@ -919,7 +919,7 @@ static HtPP * create_path_to_index(RBuffer *cache_buf, cache_img_t *img, cache_h size_t i; for (i = 0; i != hdr->imagesCount; i++) { char file[256]; - if (r_buf_read_at (cache_buf, img[i].pathFileOffset, (ut8*) &file, sizeof (file)) != sizeof (file)) { + if (rz_buf_read_at (cache_buf, img[i].pathFileOffset, (ut8*) &file, sizeof (file)) != sizeof (file)) { continue; } file[255] = 0; @@ -936,7 +936,7 @@ static void carve_deps_at_address(RBuffer *cache_buf, cache_img_t *img, cache_hd return; } struct MACH0_(mach_header) mh; - if (r_buf_fread_at (cache_buf, pa, (ut8*) &mh, "8i", 1) != sizeof (struct MACH0_(mach_header))) { + if (rz_buf_fread_at (cache_buf, pa, (ut8*) &mh, "8i", 1) != sizeof (struct MACH0_(mach_header))) { return; } if (mh.magic != MH_MAGIC_64 || mh.sizeofcmds == 0) { @@ -944,15 +944,15 @@ static void carve_deps_at_address(RBuffer *cache_buf, cache_img_t *img, cache_hd } ut64 cmds_at = pa + sizeof (struct MACH0_(mach_header)); ut8 *cmds = malloc (mh.sizeofcmds + 1); - if (!cmds || r_buf_read_at (cache_buf, cmds_at, cmds, mh.sizeofcmds) != mh.sizeofcmds) { + if (!cmds || rz_buf_read_at (cache_buf, cmds_at, cmds, mh.sizeofcmds) != mh.sizeofcmds) { goto beach; } cmds[mh.sizeofcmds] = 0; ut8 *cursor = cmds; ut8 *end = cmds + mh.sizeofcmds; while (cursor < end) { - ut32 cmd = r_read_le32 (cursor); - ut32 cmdsize = r_read_le32 (cursor + sizeof (ut32)); + ut32 cmd = rz_read_le32 (cursor); + ut32 cmdsize = rz_read_le32 (cursor + sizeof (ut32)); if (cmd == LC_LOAD_DYLIB || cmd == LC_LOAD_WEAK_DYLIB || cmd == LC_REEXPORT_DYLIB || @@ -977,27 +977,27 @@ beach: free (cmds); } -static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *hdr, cache_map_t *maps, cache_accel_t *accel) { - RList *bins = r_list_newf ((RListFree)free_bin); +static RzList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *hdr, cache_map_t *maps, cache_accel_t *accel) { + RzList *bins = rz_list_newf ((RzListFree)free_bin); if (!bins) { return NULL; } cache_img_t *img = read_cache_images (cache_buf, hdr); if (!img) { - r_list_free (bins); + rz_list_free (bins); return NULL; } int i; int *deps = NULL; char *target_libs = NULL; - target_libs = r_sys_getenv ("R_DYLDCACHE_FILTER"); - RList *target_lib_names = NULL; + target_libs = rz_sys_getenv ("R_DYLDCACHE_FILTER"); + RzList *target_lib_names = NULL; ut16 *depArray = NULL; cache_imgxtr_t *extras = NULL; if (target_libs) { - target_lib_names = r_str_split_list (target_libs, ":", 0); + target_lib_names = rz_str_split_list (target_libs, ":", 0); if (!target_lib_names) { goto error; } @@ -1014,7 +1014,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h goto error; } - if (r_buf_fread_at (cache_buf, accel->depListOffset, (ut8*) depArray, "s", accel->depListCount) != accel->depListCount * 2) { + if (rz_buf_fread_at (cache_buf, accel->depListOffset, (ut8*) depArray, "s", accel->depListCount) != accel->depListCount * 2) { goto error; } @@ -1034,7 +1034,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h if (strstr (lib_name, "libobjc.A.dylib")) { deps[i]++; } - if (!r_list_find (target_lib_names, lib_name, string_contains)) { + if (!rz_list_find (target_lib_names, lib_name, string_contains)) { R_FREE (lib_name); continue; } @@ -1064,7 +1064,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h R_FREE (depArray); R_FREE (extras); R_FREE (target_libs); - r_list_free (target_lib_names); + rz_list_free (target_lib_names); target_lib_names = NULL; } @@ -1077,8 +1077,8 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h continue; } ut8 magicbytes[4]; - r_buf_read_at (cache_buf, pa, magicbytes, 4); - int magic = r_read_le32 (magicbytes); + rz_buf_read_at (cache_buf, pa, magicbytes, 4); + int magic = rz_read_le32 (magicbytes); switch (magic) { case MH_MAGIC: // parse_mach0 (ret, *ptr, bf); @@ -1091,7 +1091,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h goto error; } bin->header_at = pa; - if (r_buf_read_at (cache_buf, img[i].pathFileOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { + if (rz_buf_read_at (cache_buf, img[i].pathFileOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { file[255] = 0; char *last_slash = strrchr (file, '/'); if (last_slash && *last_slash) { @@ -1112,7 +1112,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h bin->file = strdup (file); } } - r_list_append (bins, bin); + rz_list_append (bins, bin); break; } default: @@ -1124,7 +1124,7 @@ static RList *create_cache_bins(RBinFile *bf, RBuffer *cache_buf, cache_hdr_t *h goto beach; error: if (bins) { - r_list_free (bins); + rz_list_free (bins); } bins = NULL; beach: @@ -1132,7 +1132,7 @@ beach: R_FREE (extras); R_FREE (target_libs); if (target_lib_names) { - r_list_free (target_lib_names); + rz_list_free (target_lib_names); } R_FREE (deps); R_FREE (img); @@ -1163,9 +1163,9 @@ static void rebase_bytes_v1(RDyldRebaseInfo1 *rebase_info, ut8 *buf, ut64 offset ut8 b = entry[entry_index]; if (b & (1 << offset_in_entry)) { - ut64 value = r_read_le64 (buf + in_buf); + ut64 value = rz_read_le64 (buf + in_buf); value += rebase_info->slide; - r_write_le64 (buf + in_buf, value); + rz_write_le64 (buf + in_buf, value); in_buf += 8; offset += 8; } else { @@ -1201,7 +1201,7 @@ static void rebase_bytes_v2(RDyldRebaseInfo2 *rebase_info, ut8 *buf, ut64 offset if (position >= count) { break; } - ut64 raw_value = r_read_le64 (buf + position); + ut64 raw_value = rz_read_le64 (buf + position); delta = ((raw_value & rebase_info->delta_mask) >> rebase_info->delta_shift); if (position >= start_of_write) { ut64 new_value = raw_value & rebase_info->value_mask; @@ -1209,7 +1209,7 @@ static void rebase_bytes_v2(RDyldRebaseInfo2 *rebase_info, ut8 *buf, ut64 offset new_value += rebase_info->value_add; new_value += rebase_info->slide; } - r_write_le64 (buf + position, new_value); + rz_write_le64 (buf + position, new_value); } first_rebase_off += delta; } @@ -1245,7 +1245,7 @@ static void rebase_bytes_v3(RDyldRebaseInfo3 *rebase_info, ut8 *buf, ut64 offset if (position >= count) { break; } - ut64 raw_value = r_read_le64 (buf + position); + ut64 raw_value = rz_read_le64 (buf + position); delta = ((raw_value & rebase_info->delta_mask) >> rebase_info->delta_shift) * 8; if (position >= start_of_write) { ut64 new_value = 0; @@ -1259,7 +1259,7 @@ static void rebase_bytes_v3(RDyldRebaseInfo3 *rebase_info, ut8 *buf, ut64 offset if (new_value != 0) { new_value += rebase_info->slide; } - r_write_le64 (buf + position, new_value); + rz_write_le64 (buf + position, new_value); } first_rebase_off += delta; } while (delta); @@ -1306,18 +1306,18 @@ static void rebase_bytes(RDyldRebaseInfo *rebase_info, ut8 *buf, ut64 offset, in } } -static int dyldcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - r_return_val_if_fail (io, -1); - RCore *core = (RCore*) io->corebind.core; +static int dyldcache_io_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + rz_return_val_if_fail (io, -1); + RzCore *core = (RzCore*) io->corebind.core; if (!core || !core->bin || !core->bin->binfiles) { return -1; } RDyldCache *cache = NULL; - RListIter *iter; + RzListIter *iter; RBinFile *bf; - r_list_foreach (core->bin->binfiles, iter, bf) { + rz_list_foreach (core->bin->binfiles, iter, bf) { if (bf->fd == fd->fd ) { if (!strncmp ((char*) bf->o->bin_obj, "dyldcac", 7)) { cache = bf->o->bin_obj; @@ -1325,11 +1325,11 @@ static int dyldcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { cache = ((struct MACH0_(obj_t)*) bf->o->bin_obj)->user; } if (pending_bin_files) { - RListIter *to_remove = r_list_contains (pending_bin_files, bf); + RzListIter *to_remove = rz_list_contains (pending_bin_files, bf); if (to_remove) { - r_list_delete (pending_bin_files, to_remove); - if (r_list_empty (pending_bin_files)) { - r_list_free (pending_bin_files); + rz_list_delete (pending_bin_files, to_remove); + if (rz_list_empty (pending_bin_files)) { + rz_list_free (pending_bin_files); pending_bin_files = NULL; } } @@ -1338,7 +1338,7 @@ static int dyldcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { } } if (!cache) { - r_list_foreach (pending_bin_files, iter, bf) { + rz_list_foreach (pending_bin_files, iter, bf) { if (bf->fd == fd->fd && bf->o) { if (!strncmp ((char*) bf->o->bin_obj, "dyldcac", 7)) { cache = bf->o->bin_obj; @@ -1403,12 +1403,12 @@ static int dyldcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return result; } -static void swizzle_io_read(RDyldCache *cache, RIO *io) { +static void swizzle_io_read(RDyldCache *cache, RzIO *io) { if (!io || !io->desc || !io->desc->plugin) { return; } - RIOPlugin *plugin = io->desc->plugin; + RzIOPlugin *plugin = io->desc->plugin; cache->original_io_read = plugin->read; plugin->read = &dyldcache_io_read; } @@ -1424,7 +1424,7 @@ static cache_hdr_t *read_cache_header(RBuffer *cache_buf) { } ut64 size = sizeof (cache_hdr_t); - if (r_buf_fread_at (cache_buf, 0, (ut8*) hdr, "16c4i7l16clii4l", 1) != size) { + if (rz_buf_fread_at (cache_buf, 0, (ut8*) hdr, "16c4i7l16clii4l", 1) != size) { R_FREE (hdr); return NULL; } @@ -1443,7 +1443,7 @@ static cache_map_t *read_cache_maps(RBuffer *cache_buf, cache_hdr_t *hdr) { return NULL; } - if (r_buf_fread_at (cache_buf, hdr->mappingOffset, (ut8*) maps, "3l2i", hdr->mappingCount) != size) { + if (rz_buf_fread_at (cache_buf, hdr->mappingOffset, (ut8*) maps, "3l2i", hdr->mappingCount) != size) { R_FREE (maps); return NULL; } @@ -1467,7 +1467,7 @@ static cache_accel_t *read_cache_accel(RBuffer *cache_buf, cache_hdr_t *hdr, cac return NULL; } - if (r_buf_fread_at (cache_buf, offset, (ut8*) accel, "16il", 1) != size) { + if (rz_buf_fread_at (cache_buf, offset, (ut8*) accel, "16il", 1) != size) { R_FREE (accel); return NULL; } @@ -1487,39 +1487,39 @@ static cache_accel_t *read_cache_accel(RBuffer *cache_buf, cache_hdr_t *hdr, cac static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { RDyldCache *cache = R_NEW0 (RDyldCache); memcpy (cache->magic, "dyldcac", 7); - cache->buf = r_buf_ref (buf); + cache->buf = rz_buf_ref (buf); cache->hdr = read_cache_header (cache->buf); if (!cache->hdr) { - r_dyldcache_free (cache); + rz_dyldcache_free (cache); return false; } cache->maps = read_cache_maps (cache->buf, cache->hdr); if (!cache->maps) { - r_dyldcache_free (cache); + rz_dyldcache_free (cache); return false; } cache->accel = read_cache_accel (cache->buf, cache->hdr, cache->maps); - cache->locsym = r_dyld_locsym_new (cache->buf, cache->hdr); + cache->locsym = rz_dyld_locsym_new (cache->buf, cache->hdr); if (!cache->locsym) { - r_dyldcache_free (cache); + rz_dyldcache_free (cache); return false; } cache->bins = create_cache_bins (bf, cache->buf, cache->hdr, cache->maps, cache->accel); if (!cache->bins) { - r_dyldcache_free (cache); + rz_dyldcache_free (cache); return false; } cache->rebase_infos = get_rebase_infos (bf, cache); if (cache->rebase_infos) { if (!rebase_infos_get_slide (cache)) { if (!pending_bin_files) { - pending_bin_files = r_list_new (); + pending_bin_files = rz_list_new (); if (!pending_bin_files) { - r_dyldcache_free (cache); + rz_dyldcache_free (cache); return false; } } - r_list_push (pending_bin_files, bf); + rz_list_push (pending_bin_files, bf); swizzle_io_read (cache, bf->rbin->iob.io); } } @@ -1527,14 +1527,14 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd return true; } -static RList *entries(RBinFile *bf) { +static RzList *entries(RBinFile *bf) { RBinAddr *ptr = NULL; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } if ((ptr = R_NEW0 (RBinAddr))) { - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } @@ -1572,7 +1572,7 @@ static RBinInfo *info(RBinFile *bf) { } #if 0 -static void parse_mach0 (RList *ret, ut64 paddr, RBinFile *bf) { +static void parse_mach0 (RzList *ret, ut64 paddr, RBinFile *bf) { // TODO } #endif @@ -1582,13 +1582,13 @@ static ut64 baddr(RBinFile *bf) { return 0x180000000; } -void symbols_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin, HtPP *hash) { +void symbols_from_bin(RzList *ret, RBinFile *bf, RDyldBinImage *bin, HtPP *hash) { struct MACH0_(obj_t) *mach0 = bin_to_mach0 (bf, bin); if (!mach0) { return; } - // const RList*symbols = MACH0_(get_symbols_list) (mach0); + // const RzList*symbols = MACH0_(get_symbols_list) (mach0); const struct symbol_t *symbols = MACH0_(get_symbols) (mach0); if (!symbols) { return; @@ -1616,7 +1616,7 @@ void symbols_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin, HtPP *hash) const char *key = sdb_fmt ("%"PFMT64x, sym->vaddr); ht_pp_insert (hash, key, "1"); - r_list_append (ret, sym); + rz_list_append (ret, sym); } MACH0_(mach0_free) (mach0); } @@ -1640,7 +1640,7 @@ static bool __is_data_section(const char *name) { return false; } -static void sections_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin) { +static void sections_from_bin(RzList *ret, RBinFile *bf, RDyldBinImage *bin) { struct MACH0_(obj_t) *mach0 = bin_to_mach0 (bf, bin); if (!mach0) { return; @@ -1658,13 +1658,13 @@ static void sections_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin) { break; } if (bin->file) { - ptr->name = r_str_newf ("%s.%s", bin->file, (char*)sections[i].name); + ptr->name = rz_str_newf ("%s.%s", bin->file, (char*)sections[i].name); } else { - ptr->name = r_str_newf ("%s", (char*)sections[i].name); + ptr->name = rz_str_newf ("%s", (char*)sections[i].name); } if (strstr (ptr->name, "la_symbol_ptr")) { int len = sections[i].size / 8; - ptr->format = r_str_newf ("Cd %d[%d]", 8, len); + ptr->format = rz_str_newf ("Cd %d[%d]", 8, len); } ptr->is_data = __is_data_section (ptr->name); ptr->size = sections[i].size; @@ -1675,26 +1675,26 @@ static void sections_from_bin(RList *ret, RBinFile *bf, RDyldBinImage *bin) { ptr->vaddr = ptr->paddr; } ptr->perm = sections[i].perm; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (sections); MACH0_(mach0_free) (mach0); } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { RDyldCache *cache = (RDyldCache*) bf->o->bin_obj; if (!cache) { return NULL; } - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RListIter *iter; + RzListIter *iter; RDyldBinImage *bin; - r_list_foreach (cache->bins, iter, bin) { + rz_list_foreach (cache->bins, iter, bin) { sections_from_bin (ret, bf, bin); } @@ -1704,7 +1704,7 @@ static RList *sections(RBinFile *bf) { if (!(ptr = R_NEW0 (RBinSection))) { return NULL; } - ptr->name = r_str_newf ("cache_map.%d", i); + ptr->name = rz_str_newf ("cache_map.%d", i); ptr->size = cache->maps[i].size; ptr->vsize = ptr->size; ptr->paddr = cache->maps[i].fileOffset; @@ -1712,13 +1712,13 @@ static RList *sections(RBinFile *bf) { ptr->add = true; ptr->is_segment = true; ptr->perm = prot2perm (cache->maps[i].initProt); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } ut64 slide = rebase_infos_get_slide (cache); if (slide) { RBinSection *section; - r_list_foreach (ret, iter, section) { + rz_list_foreach (ret, iter, section) { section->vaddr += slide; } } @@ -1726,34 +1726,34 @@ static RList *sections(RBinFile *bf) { return ret; } -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { RDyldCache *cache = (RDyldCache*) bf->o->bin_obj; if (!cache) { return NULL; } - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RListIter *iter; + RzListIter *iter; RDyldBinImage *bin; - r_list_foreach (cache->bins, iter, bin) { + rz_list_foreach (cache->bins, iter, bin) { HtPP *hash = ht_pp_new0 (); if (!hash) { - r_list_free (ret); + rz_list_free (ret); return NULL; } symbols_from_bin (ret, bf, bin, hash); - r_dyld_locsym_entries_by_offset (cache, ret, hash, bin->header_at); + rz_dyld_locsym_entries_by_offset (cache, ret, hash, bin->header_at); ht_pp_free (hash); } ut64 slide = rebase_infos_get_slide (cache); if (slide) { RBinSymbol *sym; - r_list_foreach (ret, iter, sym) { + rz_list_foreach (ret, iter, sym) { sym->vaddr += slide; } } @@ -1761,12 +1761,12 @@ static RList *symbols(RBinFile *bf) { return ret; } -/* static void unswizzle_io_read(RDyldCache *cache, RIO *io) { +/* static void unswizzle_io_read(RDyldCache *cache, RzIO *io) { if (!io || !io->desc || !io->desc->plugin || !cache->original_io_read) { return; } - RIOPlugin *plugin = io->desc->plugin; + RzIOPlugin *plugin = io->desc->plugin; plugin->read = cache->original_io_read; cache->original_io_read = NULL; } */ @@ -1774,26 +1774,26 @@ static RList *symbols(RBinFile *bf) { static void destroy(RBinFile *bf) { RDyldCache *cache = (RDyldCache*) bf->o->bin_obj; // unswizzle_io_read (cache, bf->rbin->iob.io); // XXX io may be dead here - r_dyldcache_free (cache); + rz_dyldcache_free (cache); } -static RList *classes(RBinFile *bf) { +static RzList *classes(RBinFile *bf) { RDyldCache *cache = (RDyldCache*) bf->o->bin_obj; if (!cache) { return NULL; } - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RListIter *iter; + RzListIter *iter; RDyldBinImage *bin; RBuffer *orig_buf = bf->buf; ut32 num_of_unnamed_class = 0; - r_list_foreach (cache->bins, iter, bin) { + rz_list_foreach (cache->bins, iter, bin) { struct MACH0_(obj_t) *mach0 = bin_to_mach0 (bf, bin); if (!mach0) { goto beach; @@ -1819,7 +1819,7 @@ static RList *classes(RBinFile *bf) { } ut8 *pointers = malloc (sections[i].size); - if (r_buf_read_at (cache->buf, sections[i].offset, pointers, sections[i].size) < sections[i].size) { + if (rz_buf_read_at (cache->buf, sections[i].offset, pointers, sections[i].size) < sections[i].size) { R_FREE (pointers); continue; } @@ -1827,12 +1827,12 @@ static RList *classes(RBinFile *bf) { ut8 *pointers_end = pointers + sections[i].size; for (; cursor < pointers_end; cursor += 8) { - ut64 pointer_to_class = r_read_le64 (cursor); + ut64 pointer_to_class = rz_read_le64 (cursor); RBinClass *klass; if (!(klass = R_NEW0 (RBinClass)) || - !(klass->methods = r_list_new ()) || - !(klass->fields = r_list_new ())) { + !(klass->methods = rz_list_new ()) || + !(klass->fields = rz_list_new ())) { R_FREE (klass); R_FREE (pointers); R_FREE (sections); @@ -1851,7 +1851,7 @@ static RList *classes(RBinFile *bf) { bf->buf = orig_buf; if (!klass->name) { - klass->name = r_str_newf ("UnnamedClass%" PFMT64d, num_of_unnamed_class); + klass->name = rz_str_newf ("UnnamedClass%" PFMT64d, num_of_unnamed_class); if (!klass->name) { R_FREE (klass); R_FREE (pointers); @@ -1861,7 +1861,7 @@ static RList *classes(RBinFile *bf) { } num_of_unnamed_class++; } - r_list_append (ret, klass); + rz_list_append (ret, klass); } R_FREE (pointers); @@ -1874,7 +1874,7 @@ static RList *classes(RBinFile *bf) { return ret; beach: - r_list_free (ret); + rz_list_free (ret); return NULL; } @@ -1913,7 +1913,7 @@ static void header(RBinFile *bf) { pj_kn (pj, "localSymbolsOffset", cache->hdr->localSymbolsOffset); pj_kn (pj, "localSymbolsSize", cache->hdr->localSymbolsSize); char uuidstr[128]; - r_hex_bin2str ((ut8*)cache->hdr->uuid, 16, uuidstr); + rz_hex_bin2str ((ut8*)cache->hdr->uuid, 16, uuidstr); pj_ks (pj, "uuid", uuidstr); pj_ks (pj, "cacheType", (cache->hdr->cacheType == 0) ? "development" : "production"); pj_kn (pj, "branchPoolsOffset", cache->hdr->branchPoolsOffset); @@ -1993,20 +1993,20 @@ static void header(RBinFile *bf) { if (!text_infos) { goto beach; } - if (r_buf_fread_at (cache->buf, cache->hdr->imagesTextOffset, (ut8*)text_infos, "16clii", cache->hdr->imagesTextCount) != total_size) { + if (rz_buf_fread_at (cache->buf, cache->hdr->imagesTextOffset, (ut8*)text_infos, "16clii", cache->hdr->imagesTextCount) != total_size) { free (text_infos); goto beach; } size_t i; for (i = 0; i != cache->hdr->imagesTextCount; i++) { cache_text_info_t * text_info = &text_infos[i]; - r_hex_bin2str ((ut8*)text_info->uuid, 16, uuidstr); + rz_hex_bin2str ((ut8*)text_info->uuid, 16, uuidstr); pj_o (pj); pj_ks (pj, "uuid", uuidstr); pj_kn (pj, "address", text_info->loadAddress + slide); pj_kn (pj, "textSegmentSize", text_info->textSegmentSize); char file[256]; - if (r_buf_read_at (cache->buf, text_info->pathOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { + if (rz_buf_read_at (cache->buf, text_info->pathOffset, (ut8*) &file, sizeof (file)) == sizeof (file)) { file[255] = 0; pj_ks (pj, "path", file); char *last_slash = strrchr (file, '/'); @@ -2029,7 +2029,7 @@ beach: pj_free (pj); } -RBinPlugin r_bin_plugin_dyldcache = { +RBinPlugin rz_bin_plugin_dyldcache = { .name = "dyldcache", .desc = "dyldcache bin plugin", .license = "LGPL3", @@ -2046,9 +2046,9 @@ RBinPlugin r_bin_plugin_dyldcache = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_dyldcache, + .data = &rz_bin_plugin_dyldcache, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_elf.c b/librz/bin/p/bin_elf.c similarity index 59% rename from libr/bin/p/bin_elf.c rename to librz/bin/p/bin_elf.c index 94d6b6cfd4..8128c85524 100644 --- a/libr/bin/p/bin_elf.c +++ b/librz/bin/p/bin_elf.c @@ -1,29 +1,29 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake, nibble, dso */ +/* rizin - LGPL - Copyright 2009-2020 - pancake, nibble, dso */ #include "bin_elf.inc" static void headers32(RBinFile *bf) { #define p bf->rbin->cb_printf - p ("0x00000000 ELF MAGIC 0x%08x\n", r_buf_read_le32_at (bf->buf, 0)); - p ("0x00000010 Type 0x%04x\n", r_buf_read_le16_at (bf->buf, 0x10)); - p ("0x00000012 Machine 0x%04x\n", r_buf_read_le16_at (bf->buf, 0x12)); - p ("0x00000014 Version 0x%08x\n", r_buf_read_le32_at (bf->buf, 0x14)); - p ("0x00000018 Entrypoint 0x%08x\n", r_buf_read_le32_at (bf->buf, 0x18)); - p ("0x0000001c PhOff 0x%08x\n", r_buf_read_le32_at (bf->buf, 0x1c)); - p ("0x00000020 ShOff 0x%08x\n", r_buf_read_le32_at (bf->buf, 0x20)); + p ("0x00000000 ELF MAGIC 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0)); + p ("0x00000010 Type 0x%04x\n", rz_buf_read_le16_at (bf->buf, 0x10)); + p ("0x00000012 Machine 0x%04x\n", rz_buf_read_le16_at (bf->buf, 0x12)); + p ("0x00000014 Version 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0x14)); + p ("0x00000018 Entrypoint 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0x18)); + p ("0x0000001c PhOff 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0x1c)); + p ("0x00000020 ShOff 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0x20)); } static bool check_buffer(RBuffer *buf) { ut8 b[5] = {0}; - r_buf_read_at (buf, 0, b, sizeof (b)); + rz_buf_read_at (buf, 0, b, sizeof (b)); return !memcmp (b, ELFMAG, SELFMAG) && b[4] != 2; } -extern struct r_bin_dbginfo_t r_bin_dbginfo_elf; -extern struct r_bin_write_t r_bin_write_elf; +extern struct rz_bin_dbginfo_t rz_bin_dbginfo_elf; +extern struct rz_bin_write_t rz_bin_write_elf; static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { - r_return_val_if_fail (bin && opt && opt->arch, NULL); + rz_return_val_if_fail (bin && opt && opt->arch, NULL); ut32 filesize, code_va, code_pa, phoff; ut32 p_start, p_phoff, p_phdr; @@ -31,7 +31,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, ut16 ehdrsz, phdrsz; ut32 p_vaddr, p_paddr, p_fs, p_fs2; ut32 baddr; - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); bool is_arm = !strcmp (opt->arch, "arm"); // XXX: hardcoded @@ -41,12 +41,12 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, baddr = 0x8048000; } -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define D(x) r_buf_append_ut32(buf,x) -#define H(x) r_buf_append_ut16(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) -#define WZ(x,y) p_tmp=r_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define D(x) rz_buf_append_ut32(buf,x) +#define H(x) rz_buf_append_ut16(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) +#define WZ(x,y) p_tmp=rz_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) B ("\x7F" "ELF" "\x01\x01\x01\x00", 8); Z (8); @@ -58,38 +58,38 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, } D (1); - p_start = r_buf_size (buf); + p_start = rz_buf_size (buf); D (-1); // _start - p_phoff = r_buf_size (buf); + p_phoff = rz_buf_size (buf); D (-1); // phoff -- program headers offset D (0); // shoff -- section headers offset D (0); // flags - p_ehdrsz = r_buf_size (buf); + p_ehdrsz = rz_buf_size (buf); H (-1); // ehdrsz - p_phdrsz = r_buf_size (buf); + p_phdrsz = rz_buf_size (buf); H (-1); // phdrsz H (1); H (0); H (0); H (0); // phdr: - p_phdr = r_buf_size (buf); + p_phdr = rz_buf_size (buf); D (1); D (0); - p_vaddr = r_buf_size (buf); + p_vaddr = rz_buf_size (buf); D (-1); // vaddr = $$ - p_paddr = r_buf_size (buf); + p_paddr = rz_buf_size (buf); D (-1); // paddr = $$ - p_fs = r_buf_size (buf); + p_fs = rz_buf_size (buf); D (-1); // filesize - p_fs2 = r_buf_size (buf); + p_fs2 = rz_buf_size (buf); D (-1); // filesize D (5); // flags D (0x1000); // align ehdrsz = p_phdr; - phdrsz = r_buf_size (buf) - p_phdr; - code_pa = r_buf_size (buf); + phdrsz = rz_buf_size (buf) - p_phdr; + code_pa = rz_buf_size (buf); code_va = code_pa + baddr; phoff = 0x34;//p_phdr ; filesize = code_pa + codelen + datalen; @@ -117,7 +117,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, return buf; } -RBinPlugin r_bin_plugin_elf = { +RBinPlugin rz_bin_plugin_elf = { .name = "elf", .desc = "ELF format r2 plugin", .license = "LGPL3", @@ -140,18 +140,18 @@ RBinPlugin r_bin_plugin_elf = { .libs = &libs, .relocs = &relocs, .patch_relocs = &patch_relocs, - .dbginfo = &r_bin_dbginfo_elf, + .dbginfo = &rz_bin_dbginfo_elf, .create = &create, - .write = &r_bin_write_elf, + .write = &rz_bin_write_elf, .file_type = &get_file_type, .regstate = ®state, .maps = &maps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_elf, + .data = &rz_bin_plugin_elf, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_elf.inc b/librz/bin/p/bin_elf.inc similarity index 71% rename from libr/bin/p/bin_elf.inc rename to librz/bin/p/bin_elf.inc index d05604cc45..fb850b8fb2 100644 --- a/libr/bin/p/bin_elf.inc +++ b/librz/bin/p/bin_elf.inc @@ -1,47 +1,47 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, pancake */ #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "../i/private.h" #include "elf/elf.h" #include static RBinInfo* info(RBinFile *bf); -//TODO: implement r_bin_symbol_dup() and r_bin_symbol_free ? +//TODO: implement rz_bin_symbol_dup() and rz_bin_symbol_free ? static int get_file_type(RBinFile *bf) { - struct Elf_(r_bin_elf_obj_t) *obj = bf->o->bin_obj; - char *type = Elf_(r_bin_elf_get_file_type (obj)); + struct Elf_(rz_bin_elf_obj_t) *obj = bf->o->bin_obj; + char *type = Elf_(rz_bin_elf_get_file_type (obj)); int res = type? ((!strncmp (type, "CORE", 4)) ? R_BIN_TYPE_CORE : R_BIN_TYPE_DEFAULT) : -1; free (type); return res; } -static RList *maps(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); - return Elf_(r_bin_elf_get_maps)(bf->o->bin_obj); +static RzList *maps(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o, NULL); + return Elf_(rz_bin_elf_get_maps)(bf->o->bin_obj); } static char* regstate(RBinFile *bf) { - struct Elf_(r_bin_elf_obj_t) *obj = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t) *obj = bf->o->bin_obj; if (obj->ehdr.e_machine != EM_AARCH64 && obj->ehdr.e_machine != EM_ARM && obj->ehdr.e_machine != EM_386 && obj->ehdr.e_machine != EM_X86_64) { eprintf ("Cannot retrieve regstate on: %s (not yet supported)\n", - Elf_(r_bin_elf_get_machine_name)(obj)); + Elf_(rz_bin_elf_get_machine_name)(obj)); return NULL; } int len = 0; - ut8 *regs = Elf_(r_bin_elf_grab_regstate) (obj, &len); - char *hexregs = (regs && len > 0) ? r_hex_bin2strdup (regs, len) : NULL; + ut8 *regs = Elf_(rz_bin_elf_grab_regstate) (obj, &len); + char *hexregs = (regs && len > 0) ? rz_hex_bin2strdup (regs, len) : NULL; free (regs); return hexregs; @@ -51,8 +51,8 @@ static void setimpord(ELFOBJ* eobj, ut32 ord, RBinImport *ptr) { if (!eobj->imports_by_ord || ord >= eobj->imports_by_ord_size) { return; } - r_bin_import_free (eobj->imports_by_ord[ord]); - eobj->imports_by_ord[ord] = r_bin_import_clone (ptr); + rz_bin_import_free (eobj->imports_by_ord[ord]); + eobj->imports_by_ord[ord] = rz_bin_import_clone (ptr); } static char *setphname(ut16 mach, Elf_(Word) ptyp) { @@ -75,14 +75,14 @@ static char *setphname(ut16 mach, Elf_(Word) ptyp) { static Sdb* get_sdb(RBinFile *bf) { RBinObject *o = bf->o; if (o && o->bin_obj) { - struct Elf_(r_bin_elf_obj_t) *bin = (struct Elf_(r_bin_elf_obj_t) *) o->bin_obj; + struct Elf_(rz_bin_elf_obj_t) *bin = (struct Elf_(rz_bin_elf_obj_t) *) o->bin_obj; return bin->kv; } return NULL; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - struct Elf_(r_bin_elf_obj_t) *res = Elf_(r_bin_elf_new_buf) (buf, bf->rbin->verbose); + struct Elf_(rz_bin_elf_obj_t) *res = Elf_(rz_bin_elf_new_buf) (buf, bf->rbin->verbose); if (res) { // sdb_ns_set (sdb, "info", res->kv); *bin_obj = res; @@ -105,41 +105,41 @@ static void destroy(RBinFile *bf) { } R_FREE (eobj->imports_by_ord); } - Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)bf->o->bin_obj); + Elf_(rz_bin_elf_free) ((struct Elf_(rz_bin_elf_obj_t)*)bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { - return Elf_(r_bin_elf_get_baddr) (bf->o->bin_obj); + return Elf_(rz_bin_elf_get_baddr) (bf->o->bin_obj); } static ut64 boffset(RBinFile *bf) { - return Elf_(r_bin_elf_get_boffset) (bf->o->bin_obj); + return Elf_(rz_bin_elf_get_boffset) (bf->o->bin_obj); } static RBinAddr* binsym(RBinFile *bf, int sym) { - struct Elf_(r_bin_elf_obj_t)* obj = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t)* obj = bf->o->bin_obj; RBinAddr *ret = NULL; ut64 addr = 0LL; switch (sym) { case R_BIN_SYM_ENTRY: - addr = Elf_(r_bin_elf_get_entry_offset) (bf->o->bin_obj); + addr = Elf_(rz_bin_elf_get_entry_offset) (bf->o->bin_obj); break; case R_BIN_SYM_MAIN: - addr = Elf_(r_bin_elf_get_main_offset) (bf->o->bin_obj); + addr = Elf_(rz_bin_elf_get_main_offset) (bf->o->bin_obj); break; case R_BIN_SYM_INIT: - addr = Elf_(r_bin_elf_get_init_offset) (bf->o->bin_obj); + addr = Elf_(rz_bin_elf_get_init_offset) (bf->o->bin_obj); break; case R_BIN_SYM_FINI: - addr = Elf_(r_bin_elf_get_fini_offset) (bf->o->bin_obj); + addr = Elf_(rz_bin_elf_get_fini_offset) (bf->o->bin_obj); break; } if (addr && addr != UT64_MAX && (ret = R_NEW0 (RBinAddr))) { - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; bool is_arm = bin->ehdr.e_machine == EM_ARM; ret->paddr = addr; - ret->vaddr = Elf_(r_bin_elf_p2v) (obj, addr); + ret->vaddr = Elf_(rz_bin_elf_p2v) (obj, addr); if (is_arm && addr & 1) { ret->bits = 16; ret->vaddr--; @@ -171,21 +171,21 @@ static bool is_wordable_section(const char *name) { return false; } -static RList* sections(RBinFile *bf) { - struct Elf_(r_bin_elf_obj_t)* obj = (bf && bf->o)? bf->o->bin_obj : NULL; - struct r_bin_elf_section_t *section = NULL; +static RzList* sections(RBinFile *bf) { + struct Elf_(rz_bin_elf_obj_t)* obj = (bf && bf->o)? bf->o->bin_obj : NULL; + struct rz_bin_elf_section_t *section = NULL; int i, num, found_load = 0; Elf_(Phdr)* phdr = NULL; RBinSection *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; - if (!obj || !(ret = r_list_newf ((RListFree)r_bin_section_free))) { + if (!obj || !(ret = rz_list_newf ((RzListFree)rz_bin_section_free))) { return NULL; } //there is not leak in section since they are cached by elf.c - //and freed within Elf_(r_bin_elf_free) - if ((section = Elf_(r_bin_elf_get_sections) (obj))) { + //and freed within Elf_(rz_bin_elf_free) + if ((section = Elf_(rz_bin_elf_get_sections) (obj))) { for (i = 0; !section[i].last; i++) { if (!(ptr = R_NEW0 (RBinSection))) { break; @@ -197,7 +197,7 @@ static RList* sections(RBinFile *bf) { ptr->is_data = true; } if (is_wordable_section (ptr->name)) { - ptr->format = r_str_newf ("Cd %d[%"PFMT64d"]", + ptr->format = rz_str_newf ("Cd %d[%"PFMT64d"]", R_BIN_ELF_WORDSIZE, section[i].size / R_BIN_ELF_WORDSIZE); } ptr->size = section[i].type != SHT_NOBITS ? section[i].size : 0; @@ -215,7 +215,7 @@ static RList* sections(RBinFile *bf) { if (R_BIN_ELF_SCN_IS_READABLE (section[i].flags)) { ptr->perm |= R_PERM_R; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } @@ -241,7 +241,7 @@ static RList* sections(RBinFile *bf) { ptr->name = strdup ("DYNAMIC"); break; case PT_LOAD: - ptr->name = r_str_newf ("LOAD%d", n++); + ptr->name = rz_str_newf ("LOAD%d", n++); ptr->perm |= R_PERM_R; found_load = 1; ptr->add = true; @@ -284,13 +284,13 @@ static RList* sections(RBinFile *bf) { } break; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } - if (r_list_empty (ret)) { + if (rz_list_empty (ret)) { if (!bf->size) { - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; bf->size = bin? bin->size: 0x9999; } if (found_load == 0) { @@ -304,7 +304,7 @@ static RList* sections(RBinFile *bf) { ptr->vaddr = 0x10000; ptr->add = true; ptr->perm = R_PERM_RWX; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } // add entry for ehdr @@ -325,18 +325,18 @@ static RList* sections(RBinFile *bf) { } ptr->perm = R_PERM_RW; ptr->is_segment = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } static RBinAddr* newEntry(RBinFile *bf, ut64 hpaddr, ut64 hvaddr, ut64 vaddr, int type, int bits) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - struct Elf_(r_bin_elf_obj_t)* obj = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t)* obj = bf->o->bin_obj; RBinAddr *ptr = R_NEW0 (RBinAddr); if (ptr) { - ptr->paddr = Elf_(r_bin_elf_v2p) (obj, vaddr); + ptr->paddr = Elf_(rz_bin_elf_v2p) (obj, vaddr); ptr->vaddr = vaddr; ptr->hpaddr = hpaddr; ptr->hvaddr = hvaddr; @@ -351,12 +351,12 @@ static RBinAddr* newEntry(RBinFile *bf, ut64 hpaddr, ut64 hvaddr, ut64 vaddr, in return ptr; } -static void process_constructors(RBinFile *bf, RList *ret, int bits) { - RList *secs = sections (bf); - RListIter *iter; +static void process_constructors(RBinFile *bf, RzList *ret, int bits) { + RzList *secs = sections (bf); + RzListIter *iter; RBinSection *sec; int i, type; - r_list_foreach (secs, iter, sec) { + rz_list_foreach (secs, iter, sec) { type = -1; if (!strcmp (sec->name, ".fini_array")) { type = R_BIN_ENTRY_TYPE_FINI; @@ -370,62 +370,62 @@ static void process_constructors(RBinFile *bf, RList *ret, int bits) { if (!buf) { continue; } - (void)r_buf_read_at (bf->buf, sec->paddr, buf, sec->size); + (void)rz_buf_read_at (bf->buf, sec->paddr, buf, sec->size); if (bits == 32) { for (i = 0; (i + 3) < sec->size; i += 4) { - ut32 addr32 = r_read_le32 (buf + i); + ut32 addr32 = rz_read_le32 (buf + i); if (addr32) { RBinAddr *ba = newEntry (bf, sec->paddr + i, sec->vaddr + i, (ut64)addr32, type, bits); - r_list_append (ret, ba); + rz_list_append (ret, ba); } } } else { for (i = 0; (i + 7) < sec->size; i += 8) { - ut64 addr64 = r_read_le64 (buf + i); + ut64 addr64 = rz_read_le64 (buf + i); if (addr64) { RBinAddr *ba = newEntry (bf, sec->paddr + i, sec->vaddr + i, addr64, type, bits); - r_list_append (ret, ba); + rz_list_append (ret, ba); } } } free (buf); } } - r_list_free (secs); + rz_list_free (secs); } -static RList* entries(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList* entries(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinAddr *ptr = NULL; - struct r_bin_elf_symbol_t *symbol; + struct rz_bin_elf_symbol_t *symbol; int i; - struct Elf_(r_bin_elf_obj_t)* obj = bf->o->bin_obj; - RList *ret = r_list_newf ((RListFree)free); + struct Elf_(rz_bin_elf_obj_t)* obj = bf->o->bin_obj; + RzList *ret = rz_list_newf ((RzListFree)free); if (!ret) { return NULL; } - ut64 pa = Elf_(r_bin_elf_get_entry_offset) (obj); + ut64 pa = Elf_(rz_bin_elf_get_entry_offset) (obj); if (pa != UT64_MAX) { if (!(ptr = R_NEW0 (RBinAddr))) { return ret; } ptr->paddr = pa; - ptr->vaddr = Elf_(r_bin_elf_p2v) (obj, ptr->paddr); + ptr->vaddr = Elf_(rz_bin_elf_p2v) (obj, ptr->paddr); ptr->hpaddr = 0x18; // e_entry offset in ELF header ptr->hvaddr = UT64_MAX; - if (ptr->vaddr != (ut64)obj->ehdr.e_entry && Elf_(r_bin_elf_is_executable) (obj)) { + if (ptr->vaddr != (ut64)obj->ehdr.e_entry && Elf_(rz_bin_elf_is_executable) (obj)) { eprintf ("Cannot determine entrypoint, using 0x%08" PFMT64x ".\n", ptr->vaddr); } if (bf->o->sections) { - RListIter *iter; + RzListIter *iter; RBinSection *section; - r_list_foreach_prev (bf->o->sections, iter, section) { + rz_list_foreach_prev (bf->o->sections, iter, section) { if (!strcmp (section->name, "ehdr")) { ptr->hvaddr = section->vaddr + ptr->hpaddr; break; @@ -433,11 +433,11 @@ static RList* entries(RBinFile *bf) { } } if (ptr->hvaddr == UT64_MAX) { - Elf_(r_bin_elf_p2v_new) (obj, ptr->hpaddr); + Elf_(rz_bin_elf_p2v_new) (obj, ptr->hpaddr); } if (obj->ehdr.e_machine == EM_ARM) { - int bin_bits = Elf_(r_bin_elf_get_bits) (obj); + int bin_bits = Elf_(rz_bin_elf_get_bits) (obj); if (bin_bits != 64) { ptr->bits = 32; if (ptr->vaddr & 1) { @@ -450,58 +450,58 @@ static RList* entries(RBinFile *bf) { } } } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } // add entrypoint for jni libraries // NOTE: this is slow, we shouldnt find for java constructors here - if (!(symbol = Elf_(r_bin_elf_get_symbols) (obj))) { + if (!(symbol = Elf_(rz_bin_elf_get_symbols) (obj))) { return ret; } for (i = 0; !symbol[i].last; i++) { if (!strncmp (symbol[i].name, "Java", 4)) { - if (r_str_endswith (symbol[i].name, "_init")) { + if (rz_str_endswith (symbol[i].name, "_init")) { if (!(ptr = R_NEW0 (RBinAddr))) { return ret; } ptr->paddr = symbol[i].offset; - ptr->vaddr = Elf_(r_bin_elf_p2v) (obj, ptr->paddr); + ptr->vaddr = Elf_(rz_bin_elf_p2v) (obj, ptr->paddr); ptr->hpaddr = UT64_MAX; ptr->type = R_BIN_ENTRY_TYPE_INIT; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); break; } } } - int bin_bits = Elf_(r_bin_elf_get_bits) (bf->o->bin_obj); + int bin_bits = Elf_(rz_bin_elf_get_bits) (bf->o->bin_obj); process_constructors (bf, ret, bin_bits < 32 ? 32: bin_bits); return ret; } -static void insert_symbol(struct Elf_(r_bin_elf_obj_t) *bin, RBinSymbol *ptr, bool is_sht_null, RList *ret) { +static void insert_symbol(struct Elf_(rz_bin_elf_obj_t) *bin, RBinSymbol *ptr, bool is_sht_null, RzList *ret) { // add it to the list of symbols only if it doesn't point to SHT_NULL if (is_sht_null) { - r_bin_symbol_free (ptr); + rz_bin_symbol_free (ptr); } else { - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } -static RList* symbols(RBinFile *bf) { - struct r_bin_elf_symbol_t *symbol = NULL; +static RzList* symbols(RBinFile *bf) { + struct rz_bin_elf_symbol_t *symbol = NULL; RBinSymbol *ptr = NULL; int i; - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; - RList *ret = r_list_newf (free); + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } // traverse symbols - if (!(symbol = Elf_(r_bin_elf_get_symbols) (bin))) { + if (!(symbol = Elf_(rz_bin_elf_get_symbols) (bin))) { return ret; } for (i = 0; !symbol[i].last; i++) { @@ -513,7 +513,7 @@ static RList* symbols(RBinFile *bf) { } // traverse imports - if (!(symbol = Elf_(r_bin_elf_get_imports) (bin))) { + if (!(symbol = Elf_(rz_bin_elf_get_imports) (bin))) { return ret; } for (i = 0; !symbol[i].last; i++) { @@ -535,19 +535,19 @@ static RList* symbols(RBinFile *bf) { return ret; } -static RList* imports(RBinFile *bf) { +static RzList* imports(RBinFile *bf) { RBinElfSymbol *import = NULL; RBinImport *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; int i; - r_return_val_if_fail (bf && bf->o, NULL); - struct Elf_(r_bin_elf_obj_t) *elf = bf->o->bin_obj; - if (!(ret = r_list_newf (r_bin_import_free))) { + rz_return_val_if_fail (bf && bf->o, NULL); + struct Elf_(rz_bin_elf_obj_t) *elf = bf->o->bin_obj; + if (!(ret = rz_list_newf (rz_bin_import_free))) { return NULL; } - if (!(import = Elf_(r_bin_elf_get_imports) (elf))) { - r_list_free (ret); + if (!(import = Elf_(rz_bin_elf_get_imports) (elf))) { + rz_list_free (ret); return NULL; } for (i = 0; !import[i].last; i++) { @@ -559,32 +559,32 @@ static RList* imports(RBinFile *bf) { ptr->type = import[i].type; ptr->ordinal = import[i].ordinal; setimpord (elf, ptr->ordinal, ptr); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList* libs(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); +static RzList* libs(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - struct r_bin_elf_lib_t *libs = Elf_(r_bin_elf_get_libs) (bf->o->bin_obj); + struct rz_bin_elf_lib_t *libs = Elf_(rz_bin_elf_get_libs) (bf->o->bin_obj); if (libs) { int i; for (i = 0; !libs[i].last; i++) { char *ptr = strdup (libs[i].name); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (libs); } return ret; } -static RBinReloc *reloc_convert(struct Elf_(r_bin_elf_obj_t) *bin, RBinElfReloc *rel, ut64 GOT) { - r_return_val_if_fail (bin && rel, NULL); +static RBinReloc *reloc_convert(struct Elf_(rz_bin_elf_obj_t) *bin, RBinElfReloc *rel, ut64 GOT) { + rz_return_val_if_fail (bin && rel, NULL); ut64 B = bin->baddr; ut64 P = rel->rva; // rva has taken baddr into account @@ -701,33 +701,33 @@ static RBinReloc *reloc_convert(struct Elf_(r_bin_elf_obj_t) *bin, RBinElfReloc return NULL; } -static RList* relocs(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - RList *ret = NULL; +static RzList* relocs(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + RzList *ret = NULL; RBinReloc *ptr = NULL; RBinElfReloc *relocs = NULL; - struct Elf_(r_bin_elf_obj_t) *bin = bf->o->bin_obj; - if (!(ret = r_list_newf (free))) { + struct Elf_(rz_bin_elf_obj_t) *bin = bf->o->bin_obj; + if (!(ret = rz_list_newf (free))) { return NULL; } /* FIXME: This is a _temporary_ fix/workaround to prevent a use-after- * free detected by ASan that would corrupt the relocation names */ - r_list_free (imports (bf)); - ut64 got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got"); + rz_list_free (imports (bf)); + ut64 got_addr = Elf_(rz_bin_elf_get_section_addr) (bin, ".got"); if (got_addr == UT64_MAX) { - got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got.plt"); + got_addr = Elf_(rz_bin_elf_get_section_addr) (bin, ".got.plt"); if (got_addr == UT64_MAX) { got_addr = 0; } } if (got_addr < 1 && bin->ehdr.e_type == ET_REL) { - got_addr = Elf_(r_bin_elf_get_section_addr) (bin, ".got.r2"); + got_addr = Elf_(rz_bin_elf_get_section_addr) (bin, ".got.r2"); if (got_addr == -1) { got_addr = 0; } } if (bf->o) { - if (!(relocs = Elf_(r_bin_elf_get_relocs) (bin))) { + if (!(relocs = Elf_(rz_bin_elf_get_relocs) (bin))) { return ret; } size_t i; @@ -735,25 +735,25 @@ static RList* relocs(RBinFile *bf) { if (!(ptr = reloc_convert (bin, &relocs[i], got_addr))) { continue; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } return ret; } -static void _patch_reloc(ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S, ut64 B, ut64 L) { +static void _patch_reloc(ut16 e_machine, RzIOBind *iob, RBinElfReloc *rel, ut64 S, ut64 B, ut64 L) { ut64 val; ut64 A = rel->addend, P = rel->rva; ut8 buf[8]; switch (e_machine) { case EM_ARM: val = S + A; - r_write_le32 (buf, val); + rz_write_le32 (buf, val); iob->write_at (iob->io, rel->rva, buf, 4); break; case EM_AARCH64: val = S + A; - r_write_le64 (buf, val); + rz_write_le64 (buf, val); iob->write_at (iob->io, rel->rva, buf, 8); break; case EM_PPC64: { @@ -788,13 +788,13 @@ static void _patch_reloc(ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S case 14: val &= (1 << 14) - 1; iob->read_at (iob->io, rel->rva, buf, 2); - r_write_le32 (buf, (r_read_le32 (buf) & ~((1<<16) - (1<<2))) | val << 2); + rz_write_le32 (buf, (rz_read_le32 (buf) & ~((1<<16) - (1<<2))) | val << 2); iob->write_at (iob->io, rel->rva, buf, 2); break; case 24: val &= (1 << 24) - 1; iob->read_at (iob->io, rel->rva, buf, 4); - r_write_le32 (buf, (r_read_le32 (buf) & ~((1<<26) - (1<<2))) | val << 2); + rz_write_le32 (buf, (rz_read_le32 (buf) & ~((1<<26) - (1<<2))) | val << 2); iob->write_at (iob->io, rel->rva, buf, 4); break; } @@ -802,11 +802,11 @@ static void _patch_reloc(ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S // TODO big-endian switch (word) { case 2: - r_write_le16 (buf, val); + rz_write_le16 (buf, val); iob->write_at (iob->io, rel->rva, buf, 2); break; case 4: - r_write_le32 (buf, val); + rz_write_le32 (buf, val); iob->write_at (iob->io, rel->rva, buf, 4); break; } @@ -874,15 +874,15 @@ static void _patch_reloc(ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S iob->write_at (iob->io, rel->rva, buf, 1); break; case 2: - r_write_le16 (buf, val); + rz_write_le16 (buf, val); iob->write_at (iob->io, rel->rva, buf, 2); break; case 4: - r_write_le32 (buf, val); + rz_write_le32 (buf, val); iob->write_at (iob->io, rel->rva, buf, 4); break; case 8: - r_write_le64 (buf, val); + rz_write_le64 (buf, val); iob->write_at (iob->io, rel->rva, buf, 8); break; } @@ -891,25 +891,25 @@ static void _patch_reloc(ut16 e_machine, RIOBind *iob, RBinElfReloc *rel, ut64 S } } -static RList* patch_relocs(RBin *b) { - r_return_val_if_fail (b, NULL); - RList *ret = NULL; +static RzList* patch_relocs(RBin *b) { + rz_return_val_if_fail (b, NULL); + RzList *ret = NULL; RBinReloc *ptr = NULL; - RIOMap *g = NULL; + RzIOMap *g = NULL; HtUU *relocs_by_sym; RBinElfReloc *relcs = NULL; RBinInfo *info; ut64 size, offset = 0; - RIO *io = b->iob.io; + RzIO *io = b->iob.io; if (!io || !io->desc) { return NULL; } - RBinObject *obj = r_bin_cur_object (b); + RBinObject *obj = rz_bin_cur_object (b); if (!obj) { return NULL; } - struct Elf_(r_bin_elf_obj_t) *bin = obj->bin_obj; + struct Elf_(rz_bin_elf_obj_t) *bin = obj->bin_obj; info = obj ? obj->info: NULL; size_t cdsz = info? (info->bits == 64? 8: info->bits == 32? 4: info->bits == 16 ? 4: 0): 0; if (bin->ehdr.e_type != ET_REL && bin->ehdr.e_type != ET_DYN) { @@ -921,8 +921,8 @@ static RList* patch_relocs(RBin *b) { } void **it; - r_pvector_foreach (&io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; if (map->itv.addr > offset) { offset = map->itv.addr; g = map; @@ -938,29 +938,29 @@ static RList* patch_relocs(RBin *b) { ut64 n_vaddr = g->itv.addr + g->itv.size; // reserve at least that space size = bin->g_reloc_num * cdsz; - char *muri = r_str_newf ("malloc://%" PFMT64u, size); - RIODesc *gotr2desc = b->iob.open_at (io, muri, R_PERM_R, 0664, n_vaddr); + char *muri = rz_str_newf ("malloc://%" PFMT64u, size); + RzIODesc *gotr2desc = b->iob.open_at (io, muri, R_PERM_R, 0664, n_vaddr); free (muri); if (!gotr2desc) { return NULL; } - RIOMap *gotr2map = b->iob.map_get (io, n_vaddr); + RzIOMap *gotr2map = b->iob.map_get (io, n_vaddr); if (!gotr2map) { return NULL; } gotr2map->name = strdup (".got.r2"); - if (!(relcs = Elf_(r_bin_elf_get_relocs) (bin))) { + if (!(relcs = Elf_(rz_bin_elf_get_relocs) (bin))) { return NULL; } - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } HtUUOptions opt = { 0 }; if (!(relocs_by_sym = ht_uu_new_opt (&opt))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } ut64 vaddr = n_vaddr; @@ -994,19 +994,19 @@ static RList* patch_relocs(RBin *b) { ht_uu_insert (relocs_by_sym, relcs[i].sym, vaddr); vaddr += cdsz; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } ht_uu_free (relocs_by_sym); return ret; } static void lookup_symbols(RBinFile *bf, RBinInfo *ret) { - RList* symbols_list = symbols (bf); - RListIter *iter; + RzList* symbols_list = symbols (bf); + RzListIter *iter; RBinSymbol *symbol; bool is_rust = false; if (symbols_list) { - r_list_foreach (symbols_list, iter, symbol) { + rz_list_foreach (symbols_list, iter, symbol) { if (ret->has_canary && is_rust) { break; } @@ -1023,18 +1023,18 @@ static void lookup_symbols(RBinFile *bf, RBinInfo *ret) { ret->lang = "rust"; } } - symbols_list->free = r_bin_symbol_free; - r_list_free (symbols_list); + symbols_list->free = rz_bin_symbol_free; + rz_list_free (symbols_list); } } static void lookup_sections(RBinFile *bf, RBinInfo *ret) { - RList* sections_list = sections (bf); - RListIter *iter; + RzList* sections_list = sections (bf); + RzListIter *iter; RBinSection *section; bool is_go = false; ret->has_retguard = -1; - r_list_foreach (sections_list, iter, section) { + rz_list_foreach (sections_list, iter, section) { if (ret->has_retguard != -1 && is_go == true) { break; } @@ -1051,22 +1051,22 @@ static void lookup_sections(RBinFile *bf, RBinInfo *ret) { break; } } - r_list_free (sections_list); + rz_list_free (sections_list); } static bool has_sanitizers(RBinFile *bf) { bool ret = false; - RList* imports_list = imports (bf); - RListIter *iter; + RzList* imports_list = imports (bf); + RzListIter *iter; RBinImport *import; - r_list_foreach (imports_list, iter, import) { + rz_list_foreach (imports_list, iter, import) { if (strstr (import->name, "__sanitizer") || strstr (import->name, "__ubsan")) { ret = true; break; } } - r_list_free (imports_list); + rz_list_free (imports_list); return ret; } @@ -1081,13 +1081,13 @@ static RBinInfo* info(RBinFile *bf) { ? strdup (bf->file) : NULL; void *obj = bf->o->bin_obj; - if ((str = Elf_(r_bin_elf_get_rpath)(obj))) { + if ((str = Elf_(rz_bin_elf_get_rpath)(obj))) { ret->rpath = strdup (str); free (str); } else { ret->rpath = strdup ("NONE"); } - if (!(str = Elf_(r_bin_elf_get_file_type) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_file_type) (obj))) { free (ret); return NULL; } @@ -1095,61 +1095,61 @@ static RBinInfo* info(RBinFile *bf) { ret->has_pi = (strstr (str, "DYN"))? 1: 0; ret->has_lit = true; ret->has_sanitizers = has_sanitizers (bf); - if (!(str = Elf_(r_bin_elf_get_elf_class) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_elf_class) (obj))) { free (ret); return NULL; } ret->bclass = str; - if (!(str = Elf_(r_bin_elf_get_osabi_name) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_osabi_name) (obj))) { free (ret); return NULL; } ret->os = str; - if (!(str = Elf_(r_bin_elf_get_osabi_name) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_osabi_name) (obj))) { free (ret); return NULL; } ret->subsystem = str; - if (!(str = Elf_(r_bin_elf_get_machine_name) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_machine_name) (obj))) { free (ret); return NULL; } ret->machine = str; - if (!(str = Elf_(r_bin_elf_get_head_flag) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_head_flag) (obj))) { free (ret); return NULL; } ret->head_flag = str; - if (!(str = Elf_(r_bin_elf_get_arch) (obj))) { + if (!(str = Elf_(rz_bin_elf_get_arch) (obj))) { free (ret); return NULL; } ret->arch = str; - if ((str = Elf_(r_bin_elf_get_cpu) (obj))) { + if ((str = Elf_(rz_bin_elf_get_cpu) (obj))) { ret->cpu = str; } - if ((str = Elf_(r_bin_elf_get_abi) (obj))) { + if ((str = Elf_(rz_bin_elf_get_abi) (obj))) { ret->features = str; } ret->rclass = strdup ("elf"); - ret->bits = Elf_(r_bin_elf_get_bits) (obj); + ret->bits = Elf_(rz_bin_elf_get_bits) (obj); if (!strcmp (ret->arch, "avr")) { ret->bits = 16; } - ret->big_endian = Elf_(r_bin_elf_is_big_endian) (obj); - ret->has_va = Elf_(r_bin_elf_has_va) (obj); - ret->has_nx = Elf_(r_bin_elf_has_nx) (obj); - ret->intrp = Elf_(r_bin_elf_intrp) (obj); - ret->compiler = Elf_(r_bin_elf_compiler) (obj); + ret->big_endian = Elf_(rz_bin_elf_is_big_endian) (obj); + ret->has_va = Elf_(rz_bin_elf_has_va) (obj); + ret->has_nx = Elf_(rz_bin_elf_has_nx) (obj); + ret->intrp = Elf_(rz_bin_elf_intrp) (obj); + ret->compiler = Elf_(rz_bin_elf_compiler) (obj); ret->dbg_info = 0; - if (!Elf_(r_bin_elf_get_stripped) (obj)) { + if (!Elf_(rz_bin_elf_get_stripped) (obj)) { ret->dbg_info |= R_BIN_DBG_LINENUMS | R_BIN_DBG_SYMS | R_BIN_DBG_RELOCS; } else { ret->dbg_info |= R_BIN_DBG_STRIPPED; } - if (Elf_(r_bin_elf_is_static) (obj)) { + if (Elf_(rz_bin_elf_is_static) (obj)) { ret->dbg_info |= R_BIN_DBG_STATIC; } lookup_sections (bf, ret); @@ -1157,39 +1157,39 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -static RList* fields(RBinFile *bf) { - RList *ret = r_list_newf ((RListFree)free); +static RzList* fields(RBinFile *bf) { + RzList *ret = rz_list_newf ((RzListFree)free); if (!ret) { return NULL; } #define ROW(nam, siz, val, fmt) \ - r_list_append (ret, r_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); - if (r_buf_size (bf->buf) < sizeof (Elf_ (Ehdr))) { + rz_list_append (ret, rz_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); + if (rz_buf_size (bf->buf) < sizeof (Elf_ (Ehdr))) { return ret; } ut64 addr = 0; - ROW ("ELF", 4, r_buf_read_le32_at (bf->buf, addr), "x"); + ROW ("ELF", 4, rz_buf_read_le32_at (bf->buf, addr), "x"); addr += 0x10; - ROW ("Type", 2, r_buf_read_le16_at (bf->buf, addr), "x"); + ROW ("Type", 2, rz_buf_read_le16_at (bf->buf, addr), "x"); addr += 0x2; - ROW ("Machine", 2, r_buf_read_le16_at (bf->buf, addr), "x"); + ROW ("Machine", 2, rz_buf_read_le16_at (bf->buf, addr), "x"); addr += 0x2; - ROW ("Version", 4, r_buf_read_le32_at (bf->buf, addr), "x"); + ROW ("Version", 4, rz_buf_read_le32_at (bf->buf, addr), "x"); addr += 0x4; - if (r_buf_read8_at (bf->buf, 0x04) == 1) { - ROW ("Entry point", 4, r_buf_read_le32_at (bf->buf, addr), "x"); + if (rz_buf_read8_at (bf->buf, 0x04) == 1) { + ROW ("Entry point", 4, rz_buf_read_le32_at (bf->buf, addr), "x"); addr += 0x4; - ROW ("PhOff", 4, r_buf_read_le32_at (bf->buf, addr), "x"); + ROW ("PhOff", 4, rz_buf_read_le32_at (bf->buf, addr), "x"); addr += 0x4; - ROW ("ShOff", 4, r_buf_read_le32_at (bf->buf, addr), "x"); + ROW ("ShOff", 4, rz_buf_read_le32_at (bf->buf, addr), "x"); } else { - ROW ("Entry point", 8, r_buf_read_le64_at (bf->buf, addr), "x"); + ROW ("Entry point", 8, rz_buf_read_le64_at (bf->buf, addr), "x"); addr += 0x8; - ROW ("PhOff", 8, r_buf_read_le64_at (bf->buf, addr), "x"); + ROW ("PhOff", 8, rz_buf_read_le64_at (bf->buf, addr), "x"); addr += 0x8; - ROW ("ShOff", 8, r_buf_read_le64_at (bf->buf, addr), "x"); + ROW ("ShOff", 8, rz_buf_read_le64_at (bf->buf, addr), "x"); } return ret; } @@ -1198,10 +1198,10 @@ static ut64 size(RBinFile *bf) { ut64 off = 0; ut64 len = 0; if (!bf->o->sections) { - RListIter *iter; + RzListIter *iter; RBinSection *section; bf->o->sections = sections (bf); - r_list_foreach (bf->o->sections, iter, section) { + rz_list_foreach (bf->o->sections, iter, section) { if (section->paddr > off) { off = section->paddr; len = section->size; diff --git a/libr/bin/p/bin_elf64.c b/librz/bin/p/bin_elf64.c similarity index 63% rename from libr/bin/p/bin_elf64.c rename to librz/bin/p/bin_elf64.c index b7450a7d92..4102bfba8e 100644 --- a/libr/bin/p/bin_elf64.c +++ b/librz/bin/p/bin_elf64.c @@ -6,8 +6,8 @@ static bool check_buffer(RBuffer *b) { ut8 buf[5] = {0}; - if (r_buf_size (b) > 4) { - r_buf_read_at (b, 0, buf, sizeof (buf)); + if (rz_buf_size (b) > 4) { + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "\x7F\x45\x4c\x46\x02", 5)) { return true; } @@ -15,24 +15,24 @@ static bool check_buffer(RBuffer *b) { return false; } -extern struct r_bin_dbginfo_t r_bin_dbginfo_elf64; -extern struct r_bin_write_t r_bin_write_elf64; +extern struct rz_bin_dbginfo_t rz_bin_dbginfo_elf64; +extern struct rz_bin_write_t rz_bin_write_elf64; static ut64 get_elf_vaddr64 (RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr) { //NOTE(aaSSfxxx): since RVA is vaddr - "official" image base, we just need to add imagebase to vaddr - struct Elf_(r_bin_elf_obj_t)* obj = bf->o->bin_obj; + struct Elf_(rz_bin_elf_obj_t)* obj = bf->o->bin_obj; return obj->baddr - obj->boffset + vaddr; } static void headers64(RBinFile *bf) { #define p bf->rbin->cb_printf - p ("0x00000000 ELF64 0x%08x\n", r_buf_read_le32_at (bf->buf, 0)); - p ("0x00000010 Type 0x%04x\n", r_buf_read_le16_at (bf->buf, 0x10)); - p ("0x00000012 Machine 0x%04x\n", r_buf_read_le16_at (bf->buf, 0x12)); - p ("0x00000014 Version 0x%08x\n", r_buf_read_le32_at (bf->buf, 0x14)); - p ("0x00000018 Entrypoint 0x%08"PFMT64x"\n", r_buf_read_le64_at (bf->buf, 0x18)); - p ("0x00000020 PhOff 0x%08"PFMT64x"\n", r_buf_read_le64_at (bf->buf, 0x20)); - p ("0x00000028 ShOff 0x%08"PFMT64x"\n", r_buf_read_le64_at (bf->buf, 0x28)); + p ("0x00000000 ELF64 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0)); + p ("0x00000010 Type 0x%04x\n", rz_buf_read_le16_at (bf->buf, 0x10)); + p ("0x00000012 Machine 0x%04x\n", rz_buf_read_le16_at (bf->buf, 0x12)); + p ("0x00000014 Version 0x%08x\n", rz_buf_read_le32_at (bf->buf, 0x14)); + p ("0x00000018 Entrypoint 0x%08"PFMT64x"\n", rz_buf_read_le64_at (bf->buf, 0x18)); + p ("0x00000020 PhOff 0x%08"PFMT64x"\n", rz_buf_read_le64_at (bf->buf, 0x20)); + p ("0x00000028 ShOff 0x%08"PFMT64x"\n", rz_buf_read_le64_at (bf->buf, 0x28)); } static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { @@ -42,14 +42,14 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, ut64 filesize, code_va, code_pa, phoff; ut16 ehdrsz, phdrsz; ut64 baddr = 0x400000LL; - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define Q(x) r_buf_append_ut64(buf,x) -#define D(x) r_buf_append_ut32(buf,x) -#define H(x) r_buf_append_ut16(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define Q(x) rz_buf_append_ut64(buf,x) +#define D(x) rz_buf_append_ut32(buf,x) +#define H(x) rz_buf_append_ut16(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) /* Ehdr */ B ("\x7F" "ELF" "\x02\x01\x01\x00", 8); // e_ident (ei_class = ELFCLASS64) @@ -57,15 +57,15 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, H (2); // e_type = ET_EXEC H (62); // e_machine = EM_X86_64 D (1); // e_version = EV_CURRENT - p_start = r_buf_size (buf); + p_start = rz_buf_size (buf); Q (-1); // e_entry = 0xFFFFFFFF - p_phoff = r_buf_size (buf); + p_phoff = rz_buf_size (buf); Q (-1); // e_phoff = 0xFFFFFFFF Q (0); // e_shoff = 0xFFFFFFFF D (0); // e_flags - p_ehdrsz = r_buf_size (buf); + p_ehdrsz = rz_buf_size (buf); H (-1); // e_ehsize = 0xFFFFFFFF - p_phdrsz = r_buf_size (buf); + p_phdrsz = rz_buf_size (buf); H (-1); // e_phentsize = 0xFFFFFFFF H (1); // e_phnum H (0); // e_shentsize @@ -73,24 +73,24 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, H (0); // e_shstrndx /* Phdr */ - p_phdr = r_buf_size (buf); + p_phdr = rz_buf_size (buf); D (1); // p_type D (5); // p_flags = PF_R | PF_X Q (0); // p_offset - p_vaddr = r_buf_size (buf); + p_vaddr = rz_buf_size (buf); Q (-1); // p_vaddr = 0xFFFFFFFF - p_paddr = r_buf_size (buf); + p_paddr = rz_buf_size (buf); Q (-1); // p_paddr = 0xFFFFFFFF - p_fs = r_buf_size (buf); + p_fs = rz_buf_size (buf); Q (-1); // p_filesz - p_fs2 = r_buf_size (buf); + p_fs2 = rz_buf_size (buf); Q (-1); // p_memsz Q (0x200000); // p_align /* Calc fields */ ehdrsz = p_phdr; - phdrsz = r_buf_size (buf) - p_phdr; - code_pa = r_buf_size (buf); + phdrsz = rz_buf_size (buf) - p_phdr; + code_pa = rz_buf_size (buf); code_va = code_pa + baddr; phoff = p_phdr; filesize = code_pa + codelen + datalen; @@ -116,7 +116,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, return buf; } -RBinPlugin r_bin_plugin_elf64 = { +RBinPlugin rz_bin_plugin_elf64 = { .name = "elf64", .desc = "elf64 bin plugin", .license = "LGPL3", @@ -139,9 +139,9 @@ RBinPlugin r_bin_plugin_elf64 = { .libs = &libs, .relocs = &relocs, .patch_relocs = &patch_relocs, - .dbginfo = &r_bin_dbginfo_elf64, + .dbginfo = &rz_bin_dbginfo_elf64, .create = &create, - .write = &r_bin_write_elf64, + .write = &rz_bin_write_elf64, .get_vaddr = &get_elf_vaddr64, .file_type = &get_file_type, .regstate = ®state, @@ -149,9 +149,9 @@ RBinPlugin r_bin_plugin_elf64 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_elf64, + .data = &rz_bin_plugin_elf64, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_fs.c b/librz/bin/p/bin_fs.c similarity index 78% rename from libr/bin/p/bin_fs.c rename to librz/bin/p/bin_fs.c index 247d9b9de9..d6df90689d 100644 --- a/libr/bin/p/bin_fs.c +++ b/librz/bin/p/bin_fs.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../../fs/types.h" static char *fsname(RBuffer *b) { @@ -11,9 +11,9 @@ static char *fsname(RBuffer *b) { int i, j; for (i = 0; fstypes[i].name; i++) { - RFSType *f = &fstypes[i]; + RzFSType *f = &fstypes[i]; - if (r_buf_read_at (b, f->bufoff, buf, sizeof (buf)) != sizeof (buf)) { + if (rz_buf_read_at (b, f->bufoff, buf, sizeof (buf)) != sizeof (buf)) { break; } if (f->buflen > 0) { @@ -21,7 +21,7 @@ static char *fsname(RBuffer *b) { if (!memcmp (buf, f->buf, min)) { bool ret = true; min = R_MIN (f->bytelen, sizeof (buf)); - if (r_buf_read_at (b, f->byteoff, buf, min) != min) { + if (rz_buf_read_at (b, f->byteoff, buf, min) != min) { break; } for (j = 0; j < min; j++) { @@ -40,7 +40,7 @@ static char *fsname(RBuffer *b) { } static bool check_buffer(RBuffer *b) { - r_return_val_if_fail (b, false); + rz_return_val_if_fail (b, false); char *p = fsname (b); bool hasFs = p != NULL; free (p); @@ -52,7 +52,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy(RBinFile *bf) { - //r_bin_fs_free ((struct r_bin_fs_obj_t*)bf->o->bin_obj); + //rz_bin_fs_free ((struct rz_bin_fs_obj_t*)bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { @@ -60,7 +60,7 @@ static ut64 baddr(RBinFile *bf) { } /* accelerate binary load */ -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } @@ -87,7 +87,7 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -RBinPlugin r_bin_plugin_fs = { +RBinPlugin rz_bin_plugin_fs = { .name = "fs", .desc = "filesystem bin plugin", .author = "pancake", @@ -102,9 +102,9 @@ RBinPlugin r_bin_plugin_fs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_fs, + .data = &rz_bin_plugin_fs, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_java.c b/librz/bin/p/bin_java.c similarity index 66% rename from libr/bin/p/bin_java.c rename to librz/bin/p/bin_java.c index 2f20819d08..e9535212d1 100644 --- a/libr/bin/p/bin_java.c +++ b/librz/bin/p/bin_java.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble, Adam Pridgen */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../../shlr/java/class.h" #include "../../shlr/java/code.h" @@ -55,7 +55,7 @@ static void add_bin_obj_to_sdb(RBinJavaObj *bin) { if (!bin) { return; } - char *jvcname = r_bin_java_build_obj_key (bin); + char *jvcname = rz_bin_java_build_obj_key (bin); add_sdb_bin_obj (jvcname, bin); bin->AllJavaBinObjs = DB; free (jvcname); @@ -63,11 +63,11 @@ static void add_bin_obj_to_sdb(RBinJavaObj *bin) { static Sdb *get_sdb(RBinFile *bf) { RBinObject *o = bf->o; - struct r_bin_java_obj_t *bin; + struct rz_bin_java_obj_t *bin; if (!o) { return NULL; } - bin = (struct r_bin_java_obj_t *) o->bin_obj; + bin = (struct rz_bin_java_obj_t *) o->bin_obj; if (bin->kv) { return bin->kv; } @@ -75,9 +75,9 @@ static Sdb *get_sdb(RBinFile *bf) { } static bool load_buffer(RBinFile * bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - struct r_bin_java_obj_t *tmp_bin_obj = NULL; - RBuffer *tbuf = r_buf_ref (buf); - tmp_bin_obj = r_bin_java_new_buf (tbuf, loadaddr, sdb); + struct rz_bin_java_obj_t *tmp_bin_obj = NULL; + RBuffer *tbuf = rz_buf_ref (buf); + tmp_bin_obj = rz_bin_java_new_buf (tbuf, loadaddr, sdb); if (!tmp_bin_obj) { return false; } @@ -86,34 +86,34 @@ static bool load_buffer(RBinFile * bf, void **bin_obj, RBuffer *buf, ut64 loadad if (bf && bf->file) { tmp_bin_obj->file = strdup (bf->file); } - r_buf_free (tbuf); + rz_buf_free (tbuf); return true; } static void destroy(RBinFile *bf) { - r_bin_java_free ((struct r_bin_java_obj_t *) bf->o->bin_obj); + rz_bin_java_free ((struct rz_bin_java_obj_t *) bf->o->bin_obj); sdb_free (DB); DB = NULL; } -static RList *entries(RBinFile *bf) { - return r_bin_java_get_entrypoints (bf->o->bin_obj); +static RzList *entries(RBinFile *bf) { + return rz_bin_java_get_entrypoints (bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { return 0; } -static RList *classes(RBinFile *bf) { - return r_bin_java_get_classes ((struct r_bin_java_obj_t *) bf->o->bin_obj); +static RzList *classes(RBinFile *bf) { + return rz_bin_java_get_classes ((struct rz_bin_java_obj_t *) bf->o->bin_obj); } -static RList *symbols(RBinFile *bf) { - return r_bin_java_get_symbols ((struct r_bin_java_obj_t *) bf->o->bin_obj); +static RzList *symbols(RBinFile *bf) { + return rz_bin_java_get_symbols ((struct rz_bin_java_obj_t *) bf->o->bin_obj); } -static RList *strings(RBinFile *bf) { - return r_bin_java_get_strings ((struct r_bin_java_obj_t *) bf->o->bin_obj); +static RzList *strings(RBinFile *bf) { + return rz_bin_java_get_strings ((struct rz_bin_java_obj_t *) bf->o->bin_obj); } static RBinInfo *info(RBinFile *bf) { @@ -125,7 +125,7 @@ static RBinInfo *info(RBinFile *bf) { ret->lang = (jo && jo->lang) ? jo->lang : "java"; ret->file = strdup (bf->file); ret->type = strdup ("JAVA CLASS"); - ret->bclass = r_bin_java_get_version (bf->o->bin_obj); + ret->bclass = rz_bin_java_get_version (bf->o->bin_obj); ret->has_va = 0; // ret->has_lit = true; ret->rclass = strdup ("class"); @@ -140,12 +140,12 @@ static RBinInfo *info(RBinFile *bf) { } static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) > 32) { + if (rz_buf_size (b) > 32) { ut8 buf[4]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "\xca\xfe\xba\xbe", 4)) { - int off = r_buf_read_be32_at (b, 4 * sizeof (int)); - int version = r_buf_read_be16_at (b, 6); + int off = rz_buf_read_be32_at (b, 4 * sizeof (int)); + int version = rz_buf_read_be16_at (b, 6); if (off > 0 && version < 1024) { return true; } @@ -159,46 +159,46 @@ static int retdemangle(const char *str) { } static RBinAddr *binsym(RBinFile *bf, int sym) { - return r_bin_java_get_entrypoint (bf->o->bin_obj, sym); + return rz_bin_java_get_entrypoint (bf->o->bin_obj, sym); } -static R_BORROW RList *lines(RBinFile *bf) { +static R_BORROW RzList *lines(RBinFile *bf) { return NULL; #if 0 char *file = bf->file? strdup (bf->file): strdup (""); - RList *list = r_list_newf (free); + RzList *list = rz_list_newf (free); // XXX the owner of this list should be the plugin, so we are leaking here - file = r_str_replace (file, ".class", ".java", 0); + file = rz_str_replace (file, ".class", ".java", 0); /* int i; RBinJavaObj *b = bf->o->bin_obj; for (i=0; ilines.count; i++) { RBinDwarfRow *row = R_NEW0(RBinDwarfRow); - r_bin_dwarf_line_new (row, b->lines.addr[i], file, b->lines.line[i]); - r_list_append (list, row); + rz_bin_dwarf_line_new (row, b->lines.addr[i], file, b->lines.line[i]); + rz_list_append (list, row); }*/ free (file); return list; #endif } -static RList *sections(RBinFile *bf) { - return r_bin_java_get_sections (bf->o->bin_obj); +static RzList *sections(RBinFile *bf) { + return rz_bin_java_get_sections (bf->o->bin_obj); } -static RList *imports(RBinFile *bf) { - return r_bin_java_get_imports (bf->o->bin_obj); +static RzList *imports(RBinFile *bf) { + return rz_bin_java_get_imports (bf->o->bin_obj); } -static RList *fields(RBinFile *bf) { - return NULL;// r_bin_java_get_fields (bf->o->bin_obj); +static RzList *fields(RBinFile *bf) { + return NULL;// rz_bin_java_get_fields (bf->o->bin_obj); } -static RList *libs(RBinFile *bf) { - return r_bin_java_get_lib_names (bf->o->bin_obj); +static RzList *libs(RBinFile *bf) { + return rz_bin_java_get_lib_names (bf->o->bin_obj); } -RBinPlugin r_bin_plugin_java = { +RBinPlugin rz_bin_plugin_java = { .name = "java", .desc = "java bin plugin", .license = "LGPL3", @@ -225,9 +225,9 @@ RBinPlugin r_bin_plugin_java = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_java, + .data = &rz_bin_plugin_java, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_ldr_linux.c b/librz/bin/p/bin_ldr_linux.c similarity index 66% rename from libr/bin/p/bin_ldr_linux.c rename to librz/bin/p/bin_ldr_linux.c index 6e324c9972..c686b3ddeb 100644 --- a/libr/bin/p/bin_ldr_linux.c +++ b/librz/bin/p/bin_ldr_linux.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2018 pancake */ -#include -#include -#include -#include +#include +#include +#include +#include static bool load(RBin *bin) { if (!bin || !bin->cur) { @@ -16,7 +16,7 @@ static bool load(RBin *bin) { } -RBinLdrPlugin r_bin_ldr_plugin_ldr_linux = { +RBinLdrPlugin rz_bin_ldr_plugin_ldr_linux = { .name = "ldr.linux", .desc = "Linux loader plugin for RBin", .license = "MIT", @@ -24,9 +24,9 @@ RBinLdrPlugin r_bin_ldr_plugin_ldr_linux = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN_LDR, - .data = &r_bin_ldr_plugin_ldr_linux, + .data = &rz_bin_ldr_plugin_ldr_linux, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_le.c b/librz/bin/p/bin_le.c similarity index 77% rename from libr/bin/p/bin_le.c rename to librz/bin/p/bin_le.c index 7bab1d6176..52d9956337 100644 --- a/libr/bin/p/bin_le.c +++ b/librz/bin/p/bin_le.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2019 - GustavoLCR */ -#include +#include #include "../format/le/le.h" static bool check_buffer(RBuffer *b) { - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (length < 2) { return false; } - ut16 idx = r_buf_read_le16_at (b, 0x3c); + ut16 idx = rz_buf_read_le16_at (b, 0x3c); if ((ut64)idx + 26 < length) { ut8 buf[2]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "LX", 2) || !memcmp (buf, "LE", 2)) { return true; } if (!memcmp (buf, "MZ", 2)) { - r_buf_read_at (b, idx, buf, sizeof (buf)); + rz_buf_read_at (b, idx, buf, sizeof (buf)); if (!memcmp (buf, "LX", 2) || !memcmp (buf, "LE", 2)) { return true; } @@ -26,8 +26,8 @@ static bool check_buffer(RBuffer *b) { } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && bin_obj && buf, false); - r_bin_le_obj_t *res = r_bin_le_new_buf (buf); + rz_return_val_if_fail (bf && bin_obj && buf, false); + rz_bin_le_obj_t *res = rz_bin_le_new_buf (buf); if (res) { *bin_obj = res; return true; @@ -36,13 +36,13 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy(RBinFile *bf) { - r_bin_le_free (bf->o->bin_obj); + rz_bin_le_free (bf->o->bin_obj); } static void header(RBinFile *bf) { - r_return_if_fail (bf && bf->rbin && bf->o && bf->o->bin_obj); + rz_return_if_fail (bf && bf->rbin && bf->o && bf->o->bin_obj); RBin *rbin = bf->rbin; - r_bin_le_obj_t *bin = bf->o->bin_obj; + rz_bin_le_obj_t *bin = bf->o->bin_obj; LE_image_header *h = bin->header; PrintfCallback p = rbin->cb_printf; if (!h || !p) { @@ -101,34 +101,34 @@ static void header(RBinFile *bf) { p ("Stack Size: 0x%04x\n", h->stacksize); } -static RList *sections(RBinFile *bf) { - return r_bin_le_get_sections (bf->o->bin_obj); +static RzList *sections(RBinFile *bf) { + return rz_bin_le_get_sections (bf->o->bin_obj); } -static RList *entries(RBinFile *bf) { - return r_bin_le_get_entrypoints (bf->o->bin_obj); +static RzList *entries(RBinFile *bf) { + return rz_bin_le_get_entrypoints (bf->o->bin_obj); } -static RList *symbols(RBinFile *bf) { - return r_bin_le_get_symbols (bf->o->bin_obj); +static RzList *symbols(RBinFile *bf) { + return rz_bin_le_get_symbols (bf->o->bin_obj); } -static RList *imports(RBinFile *bf) { - return r_bin_le_get_imports (bf->o->bin_obj); +static RzList *imports(RBinFile *bf) { + return rz_bin_le_get_imports (bf->o->bin_obj); } -static RList *libs(RBinFile *bf) { - return r_bin_le_get_libs (bf->o->bin_obj); +static RzList *libs(RBinFile *bf) { + return rz_bin_le_get_libs (bf->o->bin_obj); } -static RList *relocs(RBinFile *bf) { - return r_bin_le_get_relocs (bf->o->bin_obj); +static RzList *relocs(RBinFile *bf) { + return rz_bin_le_get_relocs (bf->o->bin_obj); } static RBinInfo *info(RBinFile *bf) { RBinInfo *info = R_NEW0 (RBinInfo); if (info) { - r_bin_le_obj_t *bin = bf->o->bin_obj; + rz_bin_le_obj_t *bin = bf->o->bin_obj; LE_image_header *h = bin->header; info->bits = 32; info->type = strdup (bin->type); @@ -143,7 +143,7 @@ static RBinInfo *info(RBinFile *bf) { return info; } -RBinPlugin r_bin_plugin_le = { +RBinPlugin rz_bin_plugin_le = { .name = "le", .desc = "LE/LX format r2 plugin", .author = "GustavoLCR", @@ -164,9 +164,9 @@ RBinPlugin r_bin_plugin_le = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_le, + .data = &rz_bin_plugin_le, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_mach0.c b/librz/bin/p/bin_mach0.c similarity index 81% rename from libr/bin/p/bin_mach0.c rename to librz/bin/p/bin_mach0.c index 6b6a7d8013..aba131e3da 100644 --- a/libr/bin/p/bin_mach0.c +++ b/librz/bin/p/bin_mach0.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "../i/private.h" #include "mach0/mach0.h" #include "objc/mach0_classes.h" @@ -12,13 +12,13 @@ // wip settings -extern RBinWrite r_bin_write_mach0; +extern RBinWrite rz_bin_write_mach0; static RBinInfo *info(RBinFile *bf); -static void swizzle_io_read(struct MACH0_(obj_t) *obj, RIO *io); -static int rebasing_and_stripping_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count); -static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RIODesc *fd, ut8 *buf, int count); +static void swizzle_io_read(struct MACH0_(obj_t) *obj, RzIO *io); +static int rebasing_and_stripping_io_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count); +static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RzIODesc *fd, ut8 *buf, int count); #define IS_PTR_AUTH(x) ((x & (1ULL << 63)) != 0) #define IS_PTR_BIND(x) ((x & (1ULL << 62)) != 0) @@ -33,19 +33,19 @@ static Sdb *get_sdb (RBinFile *bf) { } static char *entitlements(RBinFile *bf, bool json) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); struct MACH0_(obj_t) *bin = bf->o->bin_obj; - return r_str_dup (NULL, (const char*)bin->signature); + return rz_str_dup (NULL, (const char*)bin->signature); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb){ - r_return_val_if_fail (bf && bin_obj && buf, false); + rz_return_val_if_fail (bf && bin_obj && buf, false); struct MACH0_(opts_t) opts; MACH0_(opts_set_default) (&opts, bf); struct MACH0_(obj_t) *res = MACH0_(new_buf) (buf, &opts); if (res) { if (res->chained_starts) { - RIO *io = bf->rbin->iob.io; + RzIO *io = bf->rbin->iob.io; swizzle_io_read (res, io); } sdb_ns_set (sdb, "info", res->kv); @@ -60,12 +60,12 @@ static void destroy(RBinFile *bf) { } static ut64 baddr(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, UT64_MAX); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, UT64_MAX); struct MACH0_(obj_t) *bin = bf->o->bin_obj; return MACH0_(get_baddr)(bin); } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { return MACH0_(get_segments) (bf); } @@ -86,12 +86,12 @@ static RBinAddr *newEntry(ut64 hpaddr, ut64 paddr, int type, int bits) { return ptr; } -static void process_constructors(RBinFile *bf, RList *ret, int bits) { - RList *secs = sections (bf); - RListIter *iter; +static void process_constructors(RBinFile *bf, RzList *ret, int bits) { + RzList *secs = sections (bf); + RzListIter *iter; RBinSection *sec; int i, type; - r_list_foreach (secs, iter, sec) { + rz_list_foreach (secs, iter, sec) { type = -1; if (strstr (sec->name, "_mod_fini_func")) { type = R_BIN_ENTRY_TYPE_FINI; @@ -103,41 +103,41 @@ static void process_constructors(RBinFile *bf, RList *ret, int bits) { if (!buf) { continue; } - int read = r_buf_read_at (bf->buf, sec->paddr, buf, sec->size); + int read = rz_buf_read_at (bf->buf, sec->paddr, buf, sec->size); if (read < sec->size) { eprintf ("process_constructors: cannot process section %s\n", sec->name); continue; } if (bits == 32) { for (i = 0; i + 3 < sec->size; i += 4) { - ut32 addr32 = r_read_le32 (buf + i); + ut32 addr32 = rz_read_le32 (buf + i); RBinAddr *ba = newEntry (sec->paddr + i, (ut64)addr32, type, bits); if (ba) { - r_list_append (ret, ba); + rz_list_append (ret, ba); } } } else { for (i = 0; i + 7 < sec->size; i += 8) { - ut64 addr64 = r_read_le64 (buf + i); + ut64 addr64 = rz_read_le64 (buf + i); RBinAddr *ba = newEntry (sec->paddr + i, addr64, type, bits); if (ba) { - r_list_append (ret, ba); + rz_list_append (ret, ba); } } } free (buf); } } - r_list_free (secs); + rz_list_free (secs); } -static RList *entries(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); +static RzList *entries(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o, NULL); RBinAddr *ptr = NULL; struct addr_t *entry = NULL; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } @@ -158,7 +158,7 @@ static RList *entries(RBinFile *bf) { ptr->vaddr--; } } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } process_constructors (bf, ret, bits); @@ -179,18 +179,18 @@ static void _handle_arm_thumb(struct MACH0_(obj_t) *bin, RBinSymbol **p) { } #if FEATURE_SYMLIST -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { RBinObject *obj = bf? bf->o: NULL; - return (RList *)MACH0_(get_symbols_list) (obj->bin_obj); + return (RzList *)MACH0_(get_symbols_list) (obj->bin_obj); } #else -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { struct MACH0_(obj_t) *bin; int i; const struct symbol_t *syms = NULL; RBinSymbol *ptr = NULL; RBinObject *obj = bf? bf->o: NULL; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); #if 0 const char *lang = "c"; // XXX deprecate this #endif @@ -221,7 +221,7 @@ static RList *symbols(RBinFile *bf) { ptr->name = strdup ((char*)syms[i].name); ptr->is_imported = syms[i].is_imported; if (ptr->name[0] == '_' && !ptr->is_imported) { - char *dn = r_bin_demangle (bf, ptr->name, ptr->name, ptr->vaddr, false); + char *dn = rz_bin_demangle (bf, ptr->name, ptr->name, ptr->vaddr, false); if (dn) { ptr->dname = dn; char *p = strchr (dn, '.'); @@ -262,7 +262,7 @@ static RList *symbols(RBinFile *bf) { lang = "rust"; } #endif - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } //functions from LC_FUNCTION_STARTS if (bin->func_start) { @@ -272,7 +272,7 @@ static RList *symbols(RBinFile *bf) { const ut8 *temp_end = bin->func_start + bin->func_size; strcpy (symstr, "sym0x"); while (temp + 3 < temp_end && *temp) { - temp = r_uleb128_decode (temp, NULL, &value); + temp = rz_uleb128_decode (temp, NULL, &value); address += value; ptr = R_NEW0 (RBinSymbol); if (!ptr) { @@ -281,7 +281,7 @@ static RList *symbols(RBinFile *bf) { ptr->vaddr = bin->baddr + address; ptr->paddr = address; ptr->size = 0; - ptr->name = r_str_newf ("func.%08"PFMT64x, ptr->vaddr); + ptr->name = rz_str_newf ("func.%08"PFMT64x, ptr->vaddr); ptr->type = R_BIN_TYPE_FUNC_STR; ptr->forwarder = "NONE"; ptr->bind = R_BIN_BIND_LOCAL_STR; @@ -289,7 +289,7 @@ static RList *symbols(RBinFile *bf) { if (bin->hdr.cputype == CPU_TYPE_ARM && wordsize < 64) { _handle_arm_thumb (bin, &ptr); } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // if any func is not found in syms then we can consider it is stripped if (!isStripped) { snprintf (symstr + 5, sizeof (symstr) - 5 , "%" PFMT64x, ptr->vaddr); @@ -349,7 +349,7 @@ static RBinImport *import_from_name(RBin *rbin, const char *orig_name, HtPP *imp } ptr->name = strdup (name); ptr->bind = "NONE"; - ptr->type = r_str_constpool_get (&rbin->constpool, type); + ptr->type = rz_str_constpool_get (&rbin->constpool, type); if (imports_by_name) { ht_pp_insert (imports_by_name, orig_name, ptr); @@ -358,16 +358,16 @@ static RBinImport *import_from_name(RBin *rbin, const char *orig_name, HtPP *imp return ptr; } -static RList *imports(RBinFile *bf) { +static RzList *imports(RBinFile *bf) { RBinObject *obj = bf ? bf->o : NULL; struct MACH0_(obj_t) *bin = bf ? bf->o->bin_obj : NULL; struct import_t *imports = NULL; const char *name; RBinImport *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; int i; - if (!obj || !bin || !obj->bin_obj || !(ret = r_list_newf (free))) { + if (!obj || !bin || !obj->bin_obj || !(ret = rz_list_newf (free))) { return NULL; } if (!(imports = MACH0_(get_imports) (bf->o->bin_obj))) { @@ -396,32 +396,32 @@ static RList *imports(RBinFile *bf) { if (!strcmp (name, "_NSConcreteGlobalBlock")) { bin->has_blocks_ext = true; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (imports); return ret; } -static RList *relocs(RBinFile *bf) { - RList *ret = NULL; +static RzList *relocs(RBinFile *bf) { + RzList *ret = NULL; struct MACH0_(obj_t) *bin = NULL; RBinObject *obj = bf ? bf->o : NULL; if (bf && bf->o) { bin = bf->o->bin_obj; } - if (!obj || !obj->bin_obj || !(ret = r_list_newf (free))) { + if (!obj || !obj->bin_obj || !(ret = rz_list_newf (free))) { return NULL; } ret->free = free; - RSkipList *relocs; + RzSkipList *relocs; if (!(relocs = MACH0_(get_relocs) (bf->o->bin_obj))) { return ret; } - RSkipListNode *it; + RzSkipListNode *it; struct reloc_t *reloc; - r_skiplist_foreach (relocs, it, reloc) { + rz_skiplist_foreach (relocs, it, reloc) { if (reloc->external) { continue; } @@ -445,28 +445,28 @@ static RList *relocs(RBinFile *bf) { ptr->addend = reloc->addend; ptr->vaddr = reloc->addr; ptr->paddr = reloc->offset; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } - r_skiplist_free (relocs); + rz_skiplist_free (relocs); return ret; } -static RList *libs(RBinFile *bf) { +static RzList *libs(RBinFile *bf) { int i; char *ptr = NULL; struct lib_t *libs; - RList *ret = NULL; + RzList *ret = NULL; RBinObject *obj = bf ? bf->o : NULL; - if (!obj || !obj->bin_obj || !(ret = r_list_newf (free))) { + if (!obj || !obj->bin_obj || !(ret = rz_list_newf (free))) { return NULL; } if ((libs = MACH0_(get_libs) (obj->bin_obj))) { for (i = 0; !libs[i].last; i++) { ptr = strdup (libs[i].name); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (libs); } @@ -477,7 +477,7 @@ static RBinInfo *info(RBinFile *bf) { struct MACH0_(obj_t) *bin = NULL; char *str; - r_return_val_if_fail (bf && bf->o, NULL); + rz_return_val_if_fail (bf && bf->o, NULL); RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) { return NULL; @@ -497,8 +497,8 @@ static RBinInfo *info(RBinFile *bf) { ret->dbg_info = bin->dbg_info; ret->lang = bin->lang; } - ret->intrp = r_str_dup (NULL, MACH0_(get_intrp)(bf->o->bin_obj)); - ret->compiler = r_str_dup (NULL, ""); + ret->intrp = rz_str_dup (NULL, MACH0_(get_intrp)(bf->o->bin_obj)); + ret->compiler = rz_str_dup (NULL, ""); ret->rclass = strdup ("mach0"); ret->os = strdup (MACH0_(get_os)(bf->o->bin_obj)); ret->subsystem = strdup ("darwin"); @@ -519,7 +519,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static bool _patch_reloc(struct MACH0_(obj_t) *bin, RIOBind *iob, struct reloc_t * reloc, ut64 symbol_at) { +static bool _patch_reloc(struct MACH0_(obj_t) *bin, RzIOBind *iob, struct reloc_t * reloc, ut64 symbol_at) { ut64 pc = reloc->addr; ut64 ins_len = 0; @@ -556,50 +556,50 @@ static bool _patch_reloc(struct MACH0_(obj_t) *bin, RIOBind *iob, struct reloc_t } ut8 buf[8]; - r_write_ble (buf, val, false, reloc->size * 8); + rz_write_ble (buf, val, false, reloc->size * 8); iob->write_at (iob->io, reloc->addr, buf, reloc->size); return true; } -static RList* patch_relocs(RBin *b) { - RList *ret = NULL; - RIO *io = NULL; +static RzList* patch_relocs(RBin *b) { + RzList *ret = NULL; + RzIO *io = NULL; RBinObject *obj = NULL; struct MACH0_(obj_t) *bin = NULL; - RIOMap *g = NULL; + RzIOMap *g = NULL; HtUU *relocs_by_sym = NULL; - RIODesc *gotr2desc = NULL; + RzIODesc *gotr2desc = NULL; - r_return_val_if_fail (b, NULL); + rz_return_val_if_fail (b, NULL); io = b->iob.io; if (!io || !io->desc) { return NULL; } - obj = r_bin_cur_object (b); + obj = rz_bin_cur_object (b); if (!obj) { return NULL; } bin = obj->bin_obj; - RSkipList * all_relocs = MACH0_(get_relocs)(bin); + RzSkipList * all_relocs = MACH0_(get_relocs)(bin); if (!all_relocs) { return NULL; } - RList * ext_relocs = r_list_new (); + RzList * ext_relocs = rz_list_new (); if (!ext_relocs) { goto beach; } - RSkipListNode *it; + RzSkipListNode *it; struct reloc_t * reloc; - r_skiplist_foreach (all_relocs, it, reloc) { + rz_skiplist_foreach (all_relocs, it, reloc) { if (!reloc->external) { continue; } - r_list_append (ext_relocs, reloc); + rz_list_append (ext_relocs, reloc); } - ut64 num_ext_relocs = r_list_length (ext_relocs); + ut64 num_ext_relocs = rz_list_length (ext_relocs); if (!num_ext_relocs) { goto beach; } @@ -613,8 +613,8 @@ static RList* patch_relocs(RBin *b) { ut64 offset = 0; void **vit; - r_pvector_foreach (&io->maps, vit) { - RIOMap *map = *vit; + rz_pvector_foreach (&io->maps, vit) { + RzIOMap *map = *vit; if (map->itv.addr > offset) { offset = map->itv.addr; g = map; @@ -625,28 +625,28 @@ static RList* patch_relocs(RBin *b) { } ut64 n_vaddr = g->itv.addr + g->itv.size; ut64 size = num_ext_relocs * cdsz; - char *muri = r_str_newf ("malloc://%" PFMT64u, size); + char *muri = rz_str_newf ("malloc://%" PFMT64u, size); gotr2desc = b->iob.open_at (io, muri, R_PERM_R, 0664, n_vaddr); free (muri); if (!gotr2desc) { goto beach; } - RIOMap *gotr2map = b->iob.map_get (io, n_vaddr); + RzIOMap *gotr2map = b->iob.map_get (io, n_vaddr); if (!gotr2map) { goto beach; } gotr2map->name = strdup (".got.r2"); - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { goto beach; } if (!(relocs_by_sym = ht_uu_new0 ())) { goto beach; } ut64 vaddr = n_vaddr; - RListIter *liter; - r_list_foreach (ext_relocs, liter, reloc) { + RzListIter *liter; + rz_list_foreach (ext_relocs, liter, reloc) { ut64 sym_addr = 0; sym_addr = ht_uu_find (relocs_by_sym, reloc->ord, NULL); if (!sym_addr) { @@ -670,42 +670,42 @@ static RList* patch_relocs(RBin *b) { } ptr->vaddr = sym_addr; ptr->import = imp; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } - if (r_list_empty (ret)) { + if (rz_list_empty (ret)) { goto beach; } ht_uu_free (relocs_by_sym); - r_list_free (ext_relocs); - r_skiplist_free (all_relocs); + rz_list_free (ext_relocs); + rz_skiplist_free (all_relocs); return ret; beach: - r_list_free (ext_relocs); - r_skiplist_free (all_relocs); - r_io_desc_free (gotr2desc); - r_list_free (ret); + rz_list_free (ext_relocs); + rz_skiplist_free (all_relocs); + rz_io_desc_free (gotr2desc); + rz_list_free (ret); ht_uu_free (relocs_by_sym); return NULL; } -static void swizzle_io_read(struct MACH0_(obj_t) *obj, RIO *io) { - r_return_if_fail (io && io->desc && io->desc->plugin); - RIOPlugin *plugin = io->desc->plugin; +static void swizzle_io_read(struct MACH0_(obj_t) *obj, RzIO *io) { + rz_return_if_fail (io && io->desc && io->desc->plugin); + RzIOPlugin *plugin = io->desc->plugin; obj->original_io_read = plugin->read; plugin->read = &rebasing_and_stripping_io_read; } -static int rebasing_and_stripping_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - r_return_val_if_fail (io, -1); - RCore *core = (RCore*) io->corebind.core; +static int rebasing_and_stripping_io_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + rz_return_val_if_fail (io, -1); + RzCore *core = (RzCore*) io->corebind.core; if (!core || !core->bin || !core->bin->binfiles) { return -1; } struct MACH0_(obj_t) *obj = NULL; - RListIter *iter; + RzListIter *iter; RBinFile *bf; - r_list_foreach (core->bin->binfiles, iter, bf) { + rz_list_foreach (core->bin->binfiles, iter, bf) { if (bf->fd == fd->fd ) { /* The first field of MACH0_(obj_t) is * the mach_header, whose first field is @@ -751,7 +751,7 @@ static int rebasing_and_stripping_io_read(RIO *io, RIODesc *fd, ut8 *buf, int co return result; } -static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RIODesc *fd, ut8 *buf, int count) { +static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RzIODesc *fd, ut8 *buf, int count) { if (obj->rebasing_buffer) { return; } @@ -779,10 +779,10 @@ static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RIODesc *fd, ut8 ut64 cursor = start + page_idx * page_size + page_start; while (cursor < eob && cursor < end) { ut8 tmp[8]; - if (r_buf_read_at (obj->b, cursor, tmp, 8) != 8) { + if (rz_buf_read_at (obj->b, cursor, tmp, 8) != 8) { break; } - ut64 raw_ptr = r_read_le64 (tmp); + ut64 raw_ptr = rz_read_le64 (tmp); bool is_auth = IS_PTR_AUTH (raw_ptr); bool is_bind = IS_PTR_BIND (raw_ptr); ut64 ptr_value = raw_ptr; @@ -808,7 +808,7 @@ static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RIODesc *fd, ut8 } ut64 in_buf = cursor - off; if (cursor >= off && cursor <= eob - 8) { - r_write_le64 (&buf[in_buf], ptr_value); + rz_write_le64 (&buf[in_buf], ptr_value); } cursor += delta * 8; if (!delta) { @@ -824,9 +824,9 @@ static void rebase_buffer(struct MACH0_(obj_t) *obj, ut64 off, RIODesc *fd, ut8 #if !R_BIN_MACH064 static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) >= 4) { + if (rz_buf_size (b) >= 4) { ut8 buf[4] = {0}; - if (r_buf_read_at (b, 0, buf, 4)) { + if (rz_buf_read_at (b, 0, buf, 4)) { if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) || !memcmp (buf, "\xfe\xed\xfa\xce", 4)) { return true; @@ -848,10 +848,10 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in ut32 p_cmdsize = 0, p_entry = 0, p_tmp = 0; ut32 baddr = 0x1000; - r_return_val_if_fail (bin && opt, NULL); + rz_return_val_if_fail (bin && opt, NULL); bool is_arm = strstr (opt->arch, "arm"); - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); #ifndef R_BIN_MACH064 if (opt->bits == 64) { eprintf ("TODO: Please use mach064 instead of mach0\n"); @@ -860,11 +860,11 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in } #endif -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define D(x) r_buf_append_ut32(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) -#define WZ(x,y) p_tmp=r_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define D(x) rz_buf_append_ut32(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) +#define WZ(x,y) p_tmp=rz_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) /* MACH0 HEADER */ B ("\xce\xfa\xed\xfe", 4); // header @@ -902,11 +902,11 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in /* COMMANDS */ D (ncmds); // ncmds - p_cmdsize = r_buf_size (buf); + p_cmdsize = rz_buf_size (buf); D (-1); // cmdsize D (0); // flags // D (0x01200085); // alternative flags found in some a.out.. - magiclen = r_buf_size (buf); + magiclen = rz_buf_size (buf); if (use_pagezero) { /* PAGEZERO */ @@ -930,7 +930,7 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in D (baddr); // vmaddr D (0x1000); // vmsize XXX D (0); // fileoff - p_codefsz = r_buf_size (buf); + p_codefsz = rz_buf_size (buf); D (-1); // filesize D (7); // maxprot D (5); // initprot @@ -938,11 +938,11 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in D (0); // flags WZ (16, "__text"); WZ (16, "__TEXT"); - p_codeva = r_buf_size (buf); // virtual address + p_codeva = rz_buf_size (buf); // virtual address D (-1); - p_codesz = r_buf_size (buf); // size of code (end-start) + p_codesz = rz_buf_size (buf); // size of code (end-start) D (-1); - p_codepa = r_buf_size (buf); // code - baddr + p_codepa = rz_buf_size (buf); // code - baddr D (-1); //_start-0x1000); D (0); // align // should be 2 for 64bit D (0); // reloff @@ -955,13 +955,13 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in /* DATA SEGMENT */ D (1); // cmd.LC_SEGMENT D (124); // sizeof (cmd) - p_tmp = r_buf_size (buf); + p_tmp = rz_buf_size (buf); Z (16); W (p_tmp, "__TEXT", 6); // segment name D (0x2000); // vmaddr D (0x1000); // vmsize D (0); // fileoff - p_datafsz = r_buf_size (buf); + p_datafsz = rz_buf_size (buf); D (-1); // filesize D (6); // maxprot D (6); // initprot @@ -971,11 +971,11 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in WZ (16, "__data"); WZ (16, "__DATA"); - p_datava = r_buf_size (buf); + p_datava = rz_buf_size (buf); D (-1); - p_datasz = r_buf_size (buf); + p_datasz = rz_buf_size (buf); D (-1); - p_datapa = r_buf_size (buf); + p_datapa = rz_buf_size (buf); D (-1); //_start-0x1000); D (2); // align D (0); // reloff @@ -1051,25 +1051,25 @@ static RBuffer *create(RBin *bin, const ut8 *code, int clen, const ut8 *data, in /* arm */ D (1); // i386-thread-state D (17); // thread-state-count - p_entry = r_buf_size (buf) + (16 * sizeof (ut32)); + p_entry = rz_buf_size (buf) + (16 * sizeof (ut32)); Z (17 * sizeof (ut32)); // mach0-arm has one byte more } else { /* x86-32 */ D (1); // i386-thread-state D (16); // thread-state-count - p_entry = r_buf_size (buf) + (10 * sizeof (ut32)); + p_entry = rz_buf_size (buf) + (10 * sizeof (ut32)); Z (16 * sizeof (ut32)); } } /* padding to make mach_loader checks happy */ /* binaries must be at least of 4KB :( not tiny anymore */ - WZ (4096 - r_buf_size (buf), ""); + WZ (4096 - rz_buf_size (buf), ""); - cmdsize = r_buf_size (buf) - magiclen; - codeva = r_buf_size (buf) + baddr; - datava = r_buf_size (buf) + clen + baddr; + cmdsize = rz_buf_size (buf) - magiclen; + codeva = rz_buf_size (buf) + baddr; + datava = rz_buf_size (buf) + clen + baddr; if (p_entry != 0) { W (p_entry, &codeva, 4); // set PC } @@ -1124,10 +1124,10 @@ static ut64 size(RBinFile *bf) { ut64 off = 0; ut64 len = 0; if (!bf->o->sections) { - RListIter *iter; + RzListIter *iter; RBinSection *section; bf->o->sections = sections (bf); - r_list_foreach (bf->o->sections, iter, section) { + rz_list_foreach (bf->o->sections, iter, section) { if (section->paddr > off) { off = section->paddr; len = section->size; @@ -1137,7 +1137,7 @@ static ut64 size(RBinFile *bf) { return off + len; } -RBinPlugin r_bin_plugin_mach0 = { +RBinPlugin rz_bin_plugin_mach0 = { .name = "mach0", .desc = "mach0 bin plugin", .license = "LGPL3", @@ -1161,13 +1161,13 @@ RBinPlugin r_bin_plugin_mach0 = { .patch_relocs = &patch_relocs, .create = &create, .classes = &MACH0_(parse_classes), - .write = &r_bin_write_mach0, + .write = &rz_bin_write_mach0, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_mach0, + .data = &rz_bin_plugin_mach0, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_mach064.c b/librz/bin/p/bin_mach064.c similarity index 84% rename from libr/bin/p/bin_mach064.c rename to librz/bin/p/bin_mach064.c index c0f3cf0453..3c14bd0dbb 100644 --- a/libr/bin/p/bin_mach064.c +++ b/librz/bin/p/bin_mach064.c @@ -8,8 +8,8 @@ static bool check_buffer(RBuffer *b) { ut8 buf[4] = {0}; - if (r_buf_size (b) > 4) { - r_buf_read_at (b, 0, buf, sizeof (buf)); + if (rz_buf_size (b) > 4) { + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "\xfe\xed\xfa\xcf", 4)) { return true; } @@ -33,14 +33,14 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, ut64 p_cmdsize=0, p_entry=0, p_tmp=0; ut64 baddr = 0x100001000LL; // TODO: baddr must be overriden with -b - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define D(x) r_buf_append_ut32(buf,x) -#define Q(x) r_buf_append_ut64(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) -#define WZ(x,y) p_tmp=r_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define D(x) rz_buf_append_ut32(buf,x) +#define Q(x) rz_buf_append_ut64(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) +#define WZ(x,y) p_tmp=rz_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) /* MACH0 HEADER */ // 32bit B ("\xce\xfa\xed\xfe", 4); // header @@ -66,12 +66,12 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, /* COMMANDS */ D (ncmds); // ncmds - p_cmdsize = r_buf_size (buf); + p_cmdsize = rz_buf_size (buf); D (-1); // headsize // cmdsize? D (0);//0x85); // flags D (0); // reserved -- only found in x86-64 - magiclen = r_buf_size (buf); + magiclen = rz_buf_size (buf); if (use_pagezero) { /* PAGEZERO */ @@ -97,7 +97,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, Q (0x1000); // vmsize XXX Q (0); // fileoff - p_codefsz = r_buf_size (buf); + p_codefsz = rz_buf_size (buf); Q (-1); // filesize D (7); // maxprot D (5); // initprot @@ -106,11 +106,11 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, // define section WZ (16, "__text"); WZ (16, "__TEXT"); - p_codeva = r_buf_size (buf); // virtual address + p_codeva = rz_buf_size (buf); // virtual address Q (-1); - p_codesz = r_buf_size (buf); // size of code (end-start) + p_codesz = rz_buf_size (buf); // size of code (end-start) Q (-1); - p_codepa = r_buf_size (buf); // code - baddr + p_codepa = rz_buf_size (buf); // code - baddr D (-1); // offset, _start-0x1000); D (2); // align D (0); // reloff @@ -124,7 +124,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, /* DATA SEGMENT */ D (0x19); // cmd.LC_SEGMENT_64 D (124+28); // sizeof (cmd) - p_tmp = r_buf_size (buf); + p_tmp = rz_buf_size (buf); Z (16); W (p_tmp, "__TEXT", 6); // segment name //XXX must be vmaddr+baddr @@ -132,7 +132,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, //XXX must be vmaddr+baddr Q (0x1000); // vmsize Q (0); // fileoff - p_datafsz = r_buf_size (buf); + p_datafsz = rz_buf_size (buf); Q (-1); // filesize D (6); // maxprot D (6); // initprot @@ -142,11 +142,11 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, WZ (16, "__data"); WZ (16, "__DATA"); - p_datava = r_buf_size (buf); + p_datava = rz_buf_size (buf); Q (-1); - p_datasz = r_buf_size (buf); + p_datasz = rz_buf_size (buf); Q (-1); - p_datapa = r_buf_size (buf); + p_datapa = rz_buf_size (buf); D (-1); //_start-0x1000); D (2); // align D (0); // reloff @@ -221,15 +221,15 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, D (184); // sizeof (cmd) D (4); // 1=i386, 4=x86_64 D (42); // thread-state-count - p_entry = r_buf_size (buf) + (16*sizeof (ut64)); + p_entry = rz_buf_size (buf) + (16*sizeof (ut64)); Z (STATESIZE); } - WZ (4096 - r_buf_size (buf), ""); - headerlen = r_buf_size (buf) - magiclen; + WZ (4096 - rz_buf_size (buf), ""); + headerlen = rz_buf_size (buf) - magiclen; - codeva = r_buf_size (buf) + baddr; - datava = r_buf_size (buf) + codelen + baddr; + codeva = rz_buf_size (buf) + baddr; + datava = rz_buf_size (buf) + codelen + baddr; if (p_entry != 0) { W (p_entry, &codeva, 8); // set PC @@ -279,7 +279,7 @@ static RBinAddr* binsym(RBinFile *bf, int sym) { return ret; } -RBinPlugin r_bin_plugin_mach064 = { +RBinPlugin rz_bin_plugin_mach064 = { .name = "mach064", .desc = "mach064 bin plugin", .license = "LGPL3", @@ -302,13 +302,13 @@ RBinPlugin r_bin_plugin_mach064 = { .fields = &MACH0_(mach_fields), .create = &create, .classes = &MACH0_(parse_classes), - .write = &r_bin_write_mach0, + .write = &rz_bin_write_mach0, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_mach064, + .data = &rz_bin_plugin_mach064, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_mbn.c b/librz/bin/p/bin_mbn.c similarity index 84% rename from libr/bin/p/bin_mbn.c rename to librz/bin/p/bin_mbn.c index afedb85821..f2304d74f4 100644 --- a/libr/bin/p/bin_mbn.c +++ b/librz/bin/p/bin_mbn.c @@ -1,12 +1,12 @@ -/* radare2 - LGPL - Copyright 2015-2019 - pancake */ +/* rizin - LGPL - Copyright 2015-2019 - pancake */ // XXX: this plugin have 0 tests and no binaries // -#include -#include -#include -#include +#include +#include +#include +#include typedef struct sbl_header { ut32 load_index; @@ -25,10 +25,10 @@ typedef struct sbl_header { static SblHeader sb = {0}; static bool check_buffer(RBuffer *b) { - r_return_val_if_fail (b, false); - ut64 bufsz = r_buf_size (b); + rz_return_val_if_fail (b, false); + ut64 bufsz = rz_buf_size (b); if (sizeof (SblHeader) < bufsz) { - int ret = r_buf_fread_at (b, 0, (ut8*)&sb, "10i", 1); + int ret = rz_buf_fread_at (b, 0, (ut8*)&sb, "10i", 1); if (!ret) { return false; } @@ -82,31 +82,31 @@ static ut64 baddr(RBinFile *bf) { return sb.vaddr; // XXX } -static RList* entries(RBinFile *bf) { - RList* ret = r_list_newf (free);; +static RzList* entries(RBinFile *bf) { + RzList* ret = rz_list_newf (free);; if (ret) { RBinAddr *ptr = R_NEW0 (RBinAddr); if (ptr) { ptr->paddr = 40 + sb.code_pa; ptr->vaddr = 40 + sb.code_pa + sb.vaddr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } return ret; } -static RList* sections(RBinFile *bf) { +static RzList* sections(RBinFile *bf) { RBinSection *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; int rc; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; - rc = r_buf_fread_at (bf->buf, 0, (ut8*)&sb, "10i", 1); + rc = rz_buf_fread_at (bf->buf, 0, (ut8*)&sb, "10i", 1); if (!rc) { - r_list_free (ret); + rz_list_free (ret); return false; } @@ -122,7 +122,7 @@ static RList* sections(RBinFile *bf) { ptr->perm = R_PERM_RX; // r-x ptr->add = true; ptr->has_strings = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -135,7 +135,7 @@ static RList* sections(RBinFile *bf) { ptr->perm = R_PERM_R; // r-- ptr->has_strings = true; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (sb.cert_sz && sb.cert_va > sb.vaddr) { if (!(ptr = R_NEW0 (RBinSection))) { @@ -149,7 +149,7 @@ static RList* sections(RBinFile *bf) { ptr->perm = R_PERM_R; // r-- ptr->has_strings = true; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } @@ -182,7 +182,7 @@ static ut64 size(RBinFile *bf) { return sizeof (SblHeader) + sb.psize; } -RBinPlugin r_bin_plugin_mbn = { +RBinPlugin rz_bin_plugin_mbn = { .name = "mbn", .desc = "MBN/SBL bootloader things", .license = "LGPL3", @@ -197,9 +197,9 @@ RBinPlugin r_bin_plugin_mbn = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_mbn, + .data = &rz_bin_plugin_mbn, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_mdmp.c b/librz/bin/p/bin_mdmp.c similarity index 55% rename from libr/bin/p/bin_mdmp.c rename to librz/bin/p/bin_mdmp.c index 2c7f53ecf6..642cd29493 100644 --- a/libr/bin/p/bin_mdmp.c +++ b/librz/bin/p/bin_mdmp.c @@ -1,59 +1,59 @@ -/* radare2 - LGPL - Copyright 2016-2018 - Davis, Alex Kornitzer */ +/* rizin - LGPL - Copyright 2016-2018 - Davis, Alex Kornitzer */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "mdmp/mdmp.h" static Sdb *get_sdb(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); - struct r_bin_mdmp_obj *obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + rz_return_val_if_fail (bf && bf->o, NULL); + struct rz_bin_mdmp_obj *obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; return (obj && obj->kv) ? obj->kv: NULL; } static void destroy(RBinFile *bf) { - r_bin_mdmp_free ((struct r_bin_mdmp_obj*)bf->o->bin_obj); + rz_bin_mdmp_free ((struct rz_bin_mdmp_obj*)bf->o->bin_obj); } -static RList* entries(RBinFile *bf) { - struct r_bin_mdmp_obj *obj; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RListIter *it; - RList* ret, *list; +static RzList* entries(RBinFile *bf) { + struct rz_bin_mdmp_obj *obj; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzListIter *it; + RzList* ret, *list; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; - r_list_foreach (obj->pe32_bins, it, pe32_bin) { - list = Pe32_r_bin_mdmp_pe_get_entrypoint (pe32_bin); - r_list_join (ret, list); - r_list_free (list); + rz_list_foreach (obj->pe32_bins, it, pe32_bin) { + list = Pe32_rz_bin_mdmp_pe_get_entrypoint (pe32_bin); + rz_list_join (ret, list); + rz_list_free (list); } - r_list_foreach (obj->pe64_bins, it, pe64_bin) { - list = Pe64_r_bin_mdmp_pe_get_entrypoint (pe64_bin); - r_list_join (ret, list); - r_list_free (list); + rz_list_foreach (obj->pe64_bins, it, pe64_bin) { + list = Pe64_rz_bin_mdmp_pe_get_entrypoint (pe64_bin); + rz_list_join (ret, list); + rz_list_free (list); } return ret; } static RBinInfo *info(RBinFile *bf) { - struct r_bin_mdmp_obj *obj; + struct rz_bin_mdmp_obj *obj; RBinInfo *ret; if (!(ret = R_NEW0 (RBinInfo))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; ret->big_endian = obj->endian; ret->claimed_checksum = strdup (sdb_fmt ("0x%08x", obj->hdr->check_sum)); // FIXME: Leaks @@ -97,19 +97,19 @@ static RBinInfo *info(RBinFile *bf) { switch (obj->streams.system_info->product_type) { case MDMP_VER_NT_WORKSTATION: - ret->os = r_str_newf ("Windows NT Workstation %d.%d.%d", + ret->os = rz_str_newf ("Windows NT Workstation %d.%d.%d", obj->streams.system_info->major_version, obj->streams.system_info->minor_version, obj->streams.system_info->build_number); break; case MDMP_VER_NT_DOMAIN_CONTROLLER: - ret->os = r_str_newf ("Windows NT Server Domain Controller %d.%d.%d", + ret->os = rz_str_newf ("Windows NT Server Domain Controller %d.%d.%d", obj->streams.system_info->major_version, obj->streams.system_info->minor_version, obj->streams.system_info->build_number); break; case MDMP_VER_NT_SERVER: - ret->os = r_str_newf ("Windows NT Server %d.%d.%d", + ret->os = rz_str_newf ("Windows NT Server %d.%d.%d", obj->streams.system_info->major_version, obj->streams.system_info->minor_version, obj->streams.system_info->build_number); @@ -122,44 +122,44 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList* libs(RBinFile *bf) { +static RzList* libs(RBinFile *bf) { char *ptr = NULL; int i; - struct r_bin_mdmp_obj *obj; - struct r_bin_pe_lib_t *libs = NULL; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RList *ret = NULL; - RListIter *it; + struct rz_bin_mdmp_obj *obj; + struct rz_bin_pe_lib_t *libs = NULL; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzList *ret = NULL; + RzListIter *it; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; /* TODO: Resolve module name for lib, or filter to remove duplicates, ** rather than the vaddr :) */ - r_list_foreach (obj->pe32_bins, it, pe32_bin) { - if (!(libs = Pe32_r_bin_pe_get_libs (pe32_bin->bin))) { + rz_list_foreach (obj->pe32_bins, it, pe32_bin) { + if (!(libs = Pe32_rz_bin_pe_get_libs (pe32_bin->bin))) { return ret; } for (i = 0; !libs[i].last; i++) { - ptr = r_str_newf ("[0x%.08x] - %s", pe32_bin->vaddr, libs[i].name); - r_list_append (ret, ptr); + ptr = rz_str_newf ("[0x%.08x] - %s", pe32_bin->vaddr, libs[i].name); + rz_list_append (ret, ptr); } free (libs); } - r_list_foreach (obj->pe64_bins, it, pe64_bin) { - if (!(libs = Pe64_r_bin_pe_get_libs (pe64_bin->bin))) { + rz_list_foreach (obj->pe64_bins, it, pe64_bin) { + if (!(libs = Pe64_rz_bin_pe_get_libs (pe64_bin->bin))) { return ret; } for (i = 0; !libs[i].last; i++) { - ptr = r_str_newf ("[0x%.08"PFMT64x"] - %s", pe64_bin->vaddr, libs[i].name); - r_list_append (ret, ptr); + ptr = rz_str_newf ("[0x%.08"PFMT64x"] - %s", pe64_bin->vaddr, libs[i].name); + rz_list_append (ret, ptr); } free (libs); } @@ -167,8 +167,8 @@ static RList* libs(RBinFile *bf) { } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (buf, false); - struct r_bin_mdmp_obj *res = r_bin_mdmp_new_buf (buf); + rz_return_val_if_fail (buf, false); + struct rz_bin_mdmp_obj *res = rz_bin_mdmp_new_buf (buf); if (res) { sdb_ns_set (sdb, "info", res->kv); *bin_obj = res; @@ -177,29 +177,29 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd return false; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { struct minidump_memory_descriptor *memory; struct minidump_memory_descriptor64 *memory64; struct minidump_module *module; struct minidump_string *str; - struct r_bin_mdmp_obj *obj; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RList *ret, *pe_secs; - RListIter *it, *it0; + struct rz_bin_mdmp_obj *obj; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzList *ret, *pe_secs; + RzListIter *it, *it0; RBinSection *ptr; ut64 index; - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } /* TODO: Can't remove the memories from this section until get_vaddr is ** implemented correctly, currently it is never called!?!? Is it a ** relic? */ - r_list_foreach (obj->streams.memories, it, memory) { + rz_list_foreach (obj->streams.memories, it, memory) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; } @@ -212,13 +212,13 @@ static RList *sections(RBinFile *bf) { ptr->add = true; ptr->has_strings = false; - ptr->perm = r_bin_mdmp_get_perm (obj, ptr->vaddr); + ptr->perm = rz_bin_mdmp_get_perm (obj, ptr->vaddr); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } index = obj->streams.memories64.base_rva; - r_list_foreach (obj->streams.memories64.memories, it, memory64) { + rz_list_foreach (obj->streams.memories64.memories, it, memory64) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; } @@ -231,31 +231,31 @@ static RList *sections(RBinFile *bf) { ptr->add = true; ptr->has_strings = false; - ptr->perm = r_bin_mdmp_get_perm (obj, ptr->vaddr); + ptr->perm = rz_bin_mdmp_get_perm (obj, ptr->vaddr); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); index += memory64->data_size; } // XXX: Never add here as they are covered above - r_list_foreach (obj->streams.modules, it, module) { + rz_list_foreach (obj->streams.modules, it, module) { ut8 b[512]; if (!(ptr = R_NEW0 (RBinSection))) { return ret; } - if (module->module_name_rva + sizeof (struct minidump_string) >= r_buf_size (obj->b)) { + if (module->module_name_rva + sizeof (struct minidump_string) >= rz_buf_size (obj->b)) { free (ptr); continue; } - r_buf_read_at (obj->b, module->module_name_rva, (ut8*)&b, sizeof (b)); + rz_buf_read_at (obj->b, module->module_name_rva, (ut8*)&b, sizeof (b)); str = (struct minidump_string *)b; int ptr_name_len = (str->length + 2) * 4; if (ptr_name_len < 1 || ptr_name_len > sizeof (b) - 4) { continue; } - if (module->module_name_rva + str->length > r_buf_size (obj->b)) { + if (module->module_name_rva + str->length > rz_buf_size (obj->b)) { free (ptr); break; } @@ -264,35 +264,35 @@ static RList *sections(RBinFile *bf) { free (ptr); continue; } - r_str_utf16_to_utf8 ((ut8 *)ptr->name, str->length * 4, + rz_str_utf16_to_utf8 ((ut8 *)ptr->name, str->length * 4, (const ut8 *)(&str->buffer), str->length, obj->endian); ptr->vaddr = module->base_of_image; ptr->vsize = module->size_of_image; - ptr->paddr = r_bin_mdmp_get_paddr (obj, ptr->vaddr); + ptr->paddr = rz_bin_mdmp_get_paddr (obj, ptr->vaddr); ptr->size = module->size_of_image; ptr->add = false; ptr->has_strings = false; /* As this is an encompassing section we will set the RWX to 0 */ ptr->perm = 0; - if (!r_list_append (ret, ptr)) { + if (!rz_list_append (ret, ptr)) { free (ptr); break; } /* Grab the pe sections */ - r_list_foreach (obj->pe32_bins, it0, pe32_bin) { + rz_list_foreach (obj->pe32_bins, it0, pe32_bin) { if (pe32_bin->vaddr == module->base_of_image && pe32_bin->bin) { - pe_secs = Pe32_r_bin_mdmp_pe_get_sections(pe32_bin); - r_list_join (ret, pe_secs); - r_list_free (pe_secs); + pe_secs = Pe32_rz_bin_mdmp_pe_get_sections(pe32_bin); + rz_list_join (ret, pe_secs); + rz_list_free (pe_secs); } } - r_list_foreach (obj->pe64_bins, it0, pe64_bin) { + rz_list_foreach (obj->pe64_bins, it0, pe64_bin) { if (pe64_bin->vaddr == module->base_of_image && pe64_bin->bin) { - pe_secs = Pe64_r_bin_mdmp_pe_get_sections(pe64_bin); - r_list_join (ret, pe_secs); - r_list_free (pe_secs); + pe_secs = Pe64_rz_bin_mdmp_pe_get_sections(pe64_bin); + rz_list_join (ret, pe_secs); + rz_list_free (pe_secs); } } } @@ -302,37 +302,37 @@ static RList *sections(RBinFile *bf) { return ret; } -static RList *mem(RBinFile *bf) { +static RzList *mem(RBinFile *bf) { struct minidump_location_descriptor *location = NULL; struct minidump_memory_descriptor *module; struct minidump_memory_descriptor64 *module64; struct minidump_memory_info *mem_info; - struct r_bin_mdmp_obj *obj; - RList *ret; - RListIter *it; + struct rz_bin_mdmp_obj *obj; + RzList *ret; + RzListIter *it; RBinMem *ptr; ut64 index; ut64 state, type, a_protect; - if (!(ret = r_list_newf (r_bin_mem_free))) { + if (!(ret = rz_list_newf (rz_bin_mem_free))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; /* [1] As there isnt a better place to put this info at the moment we will ** mash it into the name field, but without enumeration for now */ - r_list_foreach (obj->streams.memories, it, module) { + rz_list_foreach (obj->streams.memories, it, module) { if (!(ptr = R_NEW0 (RBinMem))) { return ret; } ptr->addr = module->start_of_memory_range; ptr->size = location? location->data_size: 0; - ptr->perms = r_bin_mdmp_get_perm (obj, ptr->addr); + ptr->perms = rz_bin_mdmp_get_perm (obj, ptr->addr); /* [1] */ state = type = a_protect = 0; - if ((mem_info = r_bin_mdmp_get_mem_info (obj, ptr->addr))) { + if ((mem_info = rz_bin_mdmp_get_mem_info (obj, ptr->addr))) { state = mem_info->state; type = mem_info->type; a_protect = mem_info->allocation_protect; @@ -342,21 +342,21 @@ static RList *mem(RBinFile *bf) { " type=0x%08"PFMT64x" allocation_protect=0x%08"PFMT64x" Memory_Section", location->rva, state, type, a_protect)); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } index = obj->streams.memories64.base_rva; - r_list_foreach (obj->streams.memories64.memories, it, module64) { + rz_list_foreach (obj->streams.memories64.memories, it, module64) { if (!(ptr = R_NEW0 (RBinMem))) { return ret; } ptr->addr = module64->start_of_memory_range; ptr->size = module64->data_size; - ptr->perms = r_bin_mdmp_get_perm (obj, ptr->addr); + ptr->perms = rz_bin_mdmp_get_perm (obj, ptr->addr); /* [1] */ state = type = a_protect = 0; - if ((mem_info = r_bin_mdmp_get_mem_info (obj, ptr->addr))) { + if ((mem_info = rz_bin_mdmp_get_mem_info (obj, ptr->addr))) { state = mem_info->state; type = mem_info->type; a_protect = mem_info->allocation_protect; @@ -367,106 +367,106 @@ static RList *mem(RBinFile *bf) { index += module64->data_size; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList* relocs(RBinFile *bf) { - struct r_bin_mdmp_obj *obj; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RListIter *it; - RList* ret; +static RzList* relocs(RBinFile *bf) { + struct rz_bin_mdmp_obj *obj; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzListIter *it; + RzList* ret; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; - r_list_foreach (obj->pe32_bins, it, pe32_bin) { + rz_list_foreach (obj->pe32_bins, it, pe32_bin) { if (pe32_bin->bin && pe32_bin->bin->relocs) { - r_list_join (ret, pe32_bin->bin->relocs); + rz_list_join (ret, pe32_bin->bin->relocs); } } - r_list_foreach (obj->pe64_bins, it, pe64_bin) { + rz_list_foreach (obj->pe64_bins, it, pe64_bin) { if (pe64_bin->bin && pe64_bin->bin->relocs) { - r_list_join (ret, pe64_bin->bin->relocs); + rz_list_join (ret, pe64_bin->bin->relocs); } } return ret; } -static RList* imports(RBinFile *bf) { - struct r_bin_mdmp_obj *obj; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RList *ret = NULL, *list; - RListIter *it; +static RzList* imports(RBinFile *bf) { + struct rz_bin_mdmp_obj *obj; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzList *ret = NULL, *list; + RzListIter *it; - if (!(ret = r_list_newf (r_bin_import_free))) { + if (!(ret = rz_list_newf (rz_bin_import_free))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; - r_list_foreach (obj->pe32_bins, it, pe32_bin) { - list = Pe32_r_bin_mdmp_pe_get_imports (pe32_bin); + rz_list_foreach (obj->pe32_bins, it, pe32_bin) { + list = Pe32_rz_bin_mdmp_pe_get_imports (pe32_bin); if (list) { - r_list_join (ret, list); - r_list_free (list); + rz_list_join (ret, list); + rz_list_free (list); } } - r_list_foreach (obj->pe64_bins, it, pe64_bin) { - list = Pe64_r_bin_mdmp_pe_get_imports (pe64_bin); + rz_list_foreach (obj->pe64_bins, it, pe64_bin) { + list = Pe64_rz_bin_mdmp_pe_get_imports (pe64_bin); if (list) { - r_list_join (ret, list); - r_list_free (list); + rz_list_join (ret, list); + rz_list_free (list); } } return ret; } -static RList* symbols(RBinFile *bf) { - struct r_bin_mdmp_obj *obj; - struct Pe32_r_bin_mdmp_pe_bin *pe32_bin; - struct Pe64_r_bin_mdmp_pe_bin *pe64_bin; - RList *ret, *list; - RListIter *it; +static RzList* symbols(RBinFile *bf) { + struct rz_bin_mdmp_obj *obj; + struct Pe32_rz_bin_mdmp_pe_bin *pe32_bin; + struct Pe64_rz_bin_mdmp_pe_bin *pe64_bin; + RzList *ret, *list; + RzListIter *it; - if (!(ret = r_list_newf (r_bin_import_free))) { + if (!(ret = rz_list_newf (rz_bin_import_free))) { return NULL; } - obj = (struct r_bin_mdmp_obj *)bf->o->bin_obj; + obj = (struct rz_bin_mdmp_obj *)bf->o->bin_obj; - r_list_foreach (obj->pe32_bins, it, pe32_bin) { - list = Pe32_r_bin_mdmp_pe_get_symbols (bf->rbin, pe32_bin); - r_list_join (ret, list); - r_list_free (list); + rz_list_foreach (obj->pe32_bins, it, pe32_bin) { + list = Pe32_rz_bin_mdmp_pe_get_symbols (bf->rbin, pe32_bin); + rz_list_join (ret, list); + rz_list_free (list); } - r_list_foreach (obj->pe64_bins, it, pe64_bin) { - list = Pe64_r_bin_mdmp_pe_get_symbols (bf->rbin, pe64_bin); - r_list_join (ret, list); - r_list_free (list); + rz_list_foreach (obj->pe64_bins, it, pe64_bin) { + list = Pe64_rz_bin_mdmp_pe_get_symbols (bf->rbin, pe64_bin); + rz_list_join (ret, list); + rz_list_free (list); } return ret; } static bool check_buffer(RBuffer *b) { ut8 magic[6]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) == 6) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) == 6) { return !memcmp (magic, MDMP_MAGIC, 6); } return false; } -RBinPlugin r_bin_plugin_mdmp = { +RBinPlugin rz_bin_plugin_mdmp = { .name = "mdmp", - .desc = "Minidump format r_bin plugin", + .desc = "Minidump format rz_bin plugin", .license = "LGPL3", .destroy = &destroy, .entries = entries, @@ -483,9 +483,9 @@ RBinPlugin r_bin_plugin_mdmp = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_mdmp, + .data = &rz_bin_plugin_mdmp, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_menuet.c b/librz/bin/p/bin_menuet.c similarity index 72% rename from libr/bin/p/bin_menuet.c rename to librz/bin/p/bin_menuet.c index cf2e3e569b..d9bc344960 100644 --- a/libr/bin/p/bin_menuet.c +++ b/librz/bin/p/bin_menuet.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2016-2019 - pancake */ +/* rizin - LGPL - Copyright 2016-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #define MENUET_VERSION(x) x[7] @@ -51,10 +51,10 @@ static bool check_buffer(RBuffer *b) { ut8 buf[8]; - if (r_buf_read_at (b, 0, buf, sizeof (buf)) != sizeof (buf)) { + if (rz_buf_read_at (b, 0, buf, sizeof (buf)) != sizeof (buf)) { return false; } - if (r_buf_size (b) >= 32 && !memcmp (buf, "MENUET0", 7)) { + if (rz_buf_size (b) >= 32 && !memcmp (buf, "MENUET0", 7)) { switch (buf[7]) { case '0': case '1': @@ -76,48 +76,48 @@ static ut64 baddr(RBinFile *bf) { static ut64 menuetEntry(const ut8 *buf, int buf_size) { switch (MENUET_VERSION(buf)) { - case '0': return r_read_ble32 (buf + 12, false); - case '1': return r_read_ble32 (buf + 12, false); - case '2': return r_read_ble32 (buf + 44, false); + case '0': return rz_read_ble32 (buf + 12, false); + case '1': return rz_read_ble32 (buf + 12, false); + case '2': return rz_read_ble32 (buf + 44, false); } return UT64_MAX; } -static RList* entries(RBinFile *bf) { - RList* ret; +static RzList* entries(RBinFile *bf) { + RzList* ret; ut8 buf[64] = {0}; RBinAddr *ptr = NULL; - const int buf_size = R_MIN (sizeof (buf), r_buf_size (bf->buf)); + const int buf_size = R_MIN (sizeof (buf), rz_buf_size (bf->buf)); - r_buf_read_at (bf->buf, 0, buf, buf_size); + rz_buf_read_at (bf->buf, 0, buf, buf_size); ut64 entry = menuetEntry (buf, buf_size); if (entry == UT64_MAX) { return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if ((ptr = R_NEW0 (RBinAddr))) { - ptr->paddr = r_read_ble32 (buf + 12, false); + ptr->paddr = rz_read_ble32 (buf + 12, false); ptr->vaddr = ptr->paddr + baddr (bf); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList* sections(RBinFile *bf) { - RList *ret = NULL; +static RzList* sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; ut8 buf[64] = {0}; - const int buf_size = R_MIN (sizeof (buf), r_buf_size (bf->buf)); + const int buf_size = R_MIN (sizeof (buf), rz_buf_size (bf->buf)); - r_buf_read_at (bf->buf, 0, buf, buf_size); + rz_buf_read_at (bf->buf, 0, buf, buf_size); if (!bf->o->info) { return NULL; } - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } // add text segment @@ -125,13 +125,13 @@ static RList* sections(RBinFile *bf) { return ret; } ptr->name = strdup ("text"); - ptr->size = r_read_ble32 (buf + 16, false); + ptr->size = rz_read_ble32 (buf + 16, false); ptr->vsize = ptr->size + (ptr->size % 4096); - ptr->paddr = r_read_ble32 (buf + 12, false); + ptr->paddr = rz_read_ble32 (buf + 12, false); ptr->vaddr = ptr->paddr + baddr (bf); ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (MENUET_VERSION(buf)) { /* add data section */ @@ -139,15 +139,15 @@ static RList* sections(RBinFile *bf) { return ret; } ptr->name = strdup ("idata"); - const ut32 idata_start = r_read_ble32 (buf + 40, false); - const ut32 idata_end = r_read_ble32 (buf + 44, false); + const ut32 idata_start = rz_read_ble32 (buf + 40, false); + const ut32 idata_end = rz_read_ble32 (buf + 44, false); ptr->size = idata_end - idata_start; ptr->vsize = ptr->size + (ptr->size % 4096); - ptr->paddr = r_read_ble32 (buf + 40, false); + ptr->paddr = rz_read_ble32 (buf + 40, false); ptr->vaddr = ptr->paddr + baddr (bf); ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; @@ -181,17 +181,17 @@ static ut64 size(RBinFile *bf) { if (!bf->o->info) { return 0; } - r_buf_read_at (bf->buf, 16, buf, 4); - return (ut64)r_read_ble32 (buf, false); + rz_buf_read_at (bf->buf, 16, buf, 4); + return (ut64)rz_read_ble32 (buf, false); } #if !R_BIN_P9 /* inspired in http://www.phreedom.org/solar/code/tinype/tiny.97/tiny.asm */ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { - RBuffer *buf = r_buf_new (); -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define D(x) r_buf_append_ut32(buf,x) + RBuffer *buf = rz_buf_new (); +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define D(x) rz_buf_append_ut32(buf,x) B ("MENUET01", 8); D (1); // header version D (32); // program start @@ -203,7 +203,7 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, return buf; } -RBinPlugin r_bin_plugin_menuet = { +RBinPlugin rz_bin_plugin_menuet = { .name = "menuet", .desc = "Menuet/KolibriOS bin plugin", .license = "LGPL3", @@ -218,9 +218,9 @@ RBinPlugin r_bin_plugin_menuet = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_menuet, + .data = &rz_bin_plugin_menuet, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_mz.c b/librz/bin/p/bin_mz.c similarity index 74% rename from libr/bin/p/bin_mz.c rename to librz/bin/p/bin_mz.c index af0f583f5c..4a83214347 100644 --- a/libr/bin/p/bin_mz.c +++ b/librz/bin/p/bin_mz.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2015-2019 nodepad */ -#include -#include -#include +#include +#include +#include #include "mz/mz.h" @@ -10,9 +10,9 @@ #define HM(x) (int)((int)(x[0]<<8)|(int)(x[1])) static Sdb *get_sdb(RBinFile *bf) { - const struct r_bin_mz_obj_t *bin; + const struct rz_bin_mz_obj_t *bin; if (bf && bf->o && bf->o->bin_obj) { - bin = (struct r_bin_mz_obj_t *)bf->o->bin_obj; + bin = (struct rz_bin_mz_obj_t *)bf->o->bin_obj; if (bin && bin->kv) { return bin->kv; } @@ -22,12 +22,12 @@ static Sdb *get_sdb(RBinFile *bf) { static bool knownHeaderBuffer(RBuffer *b, ut16 offset) { ut8 h[2]; - if (r_buf_read_at (b, offset, h, sizeof (h)) != sizeof (h)) { + if (rz_buf_read_at (b, offset, h, sizeof (h)) != sizeof (h)) { return false; } if (!memcmp (h, "PE", 2)) { - if (offset + 0x20 < r_buf_size (b)) { - if (r_buf_read_at (b, offset + 0x18, h, sizeof (h)) != 2) { + if (offset + 0x20 < rz_buf_size (b)) { + if (rz_buf_read_at (b, offset + 0x18, h, sizeof (h)) != 2) { return false; } if (!memcmp (h, "\x0b\x01", 2)) { @@ -46,9 +46,9 @@ static bool knownHeaderBuffer(RBuffer *b, ut16 offset) { } static bool checkEntrypointBuffer(RBuffer *b) { - st16 cs = r_buf_read_le16_at (b, 0x16); - ut16 ip = r_buf_read_le16_at (b, 0x14); - ut32 pa = ((r_buf_read_le16_at (b, 0x08) + cs) << 4) + ip; + st16 cs = rz_buf_read_le16_at (b, 0x16); + ut16 ip = rz_buf_read_le16_at (b, 0x14); + ut32 pa = ((rz_buf_read_le16_at (b, 0x08) + cs) << 4) + ip; /* A minimal MZ header is 0x1B bytes. Header length is measured in * 16-byte paragraphs so the minimum header must occupy 2 paragraphs. @@ -56,12 +56,12 @@ static bool checkEntrypointBuffer(RBuffer *b) { * cleverly fit a few instructions inside the header. */ pa &= 0xffff; - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (pa >= 0x20 && pa + 1 < length) { - ut16 pe = r_buf_read_le16_at (b, 0x3c); + ut16 pe = rz_buf_read_le16_at (b, 0x3c); if (pe + 2 < length && length > 0x104) { ut8 h[2]; - if (r_buf_read_at (b, pe, h, 2) == 2) { + if (rz_buf_read_at (b, pe, h, 2) == 2) { if (!memcmp (h, "PE", 2)) { return false; } @@ -73,15 +73,15 @@ static bool checkEntrypointBuffer(RBuffer *b) { } static bool check_buffer(RBuffer *b) { - r_return_val_if_fail (b, false); - ut64 b_size = r_buf_size (b); + rz_return_val_if_fail (b, false); + ut64 b_size = rz_buf_size (b); if (b_size <= 0x3d) { return false; } // Check for MZ magic. ut8 h[2]; - if (r_buf_read_at (b, 0, h, 2) != 2) { + if (rz_buf_read_at (b, 0, h, 2) != 2) { return false; } if (memcmp (h, "MZ", 2)) { @@ -89,7 +89,7 @@ static bool check_buffer(RBuffer *b) { } // See if there is a new exe header. - ut16 new_exe_header_offset = r_buf_read_le16_at (b, 0x3c); + ut16 new_exe_header_offset = rz_buf_read_le16_at (b, 0x3c); if (b_size > new_exe_header_offset + 2) { if (knownHeaderBuffer (b, new_exe_header_offset)) { return false; @@ -104,7 +104,7 @@ static bool check_buffer(RBuffer *b) { } static bool load(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - struct r_bin_mz_obj_t *mz_obj = r_bin_mz_new_buf (buf); + struct rz_bin_mz_obj_t *mz_obj = rz_bin_mz_new_buf (buf); if (mz_obj) { sdb_ns_set (sdb, "info", mz_obj->kv); *bin_obj = mz_obj; @@ -114,7 +114,7 @@ static bool load(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb } static void destroy(RBinFile *bf) { - r_bin_mz_free ((struct r_bin_mz_obj_t *)bf->o->bin_obj); + rz_bin_mz_free ((struct rz_bin_mz_obj_t *)bf->o->bin_obj); } static RBinAddr *binsym(RBinFile *bf, int type) { @@ -122,28 +122,28 @@ static RBinAddr *binsym(RBinFile *bf, int type) { if (bf && bf->o && bf->o->bin_obj) { switch (type) { case R_BIN_SYM_MAIN: - mzaddr = r_bin_mz_get_main_vaddr (bf->o->bin_obj); + mzaddr = rz_bin_mz_get_main_vaddr (bf->o->bin_obj); break; } } return mzaddr; } -static RList *entries(RBinFile *bf) { +static RzList *entries(RBinFile *bf) { RBinAddr *ptr = NULL; - RList *res = NULL; - if (!(res = r_list_newf (free))) { + RzList *res = NULL; + if (!(res = rz_list_newf (free))) { return NULL; } - ptr = r_bin_mz_get_entrypoint (bf->o->bin_obj); + ptr = rz_bin_mz_get_entrypoint (bf->o->bin_obj); if (ptr) { - r_list_append (res, ptr); + rz_list_append (res, ptr); } return res; } -static RList *sections(RBinFile *bf) { - return r_bin_mz_get_segments (bf->o->bin_obj); +static RzList *sections(RBinFile *bf) { + return rz_bin_mz_get_segments (bf->o->bin_obj); } static RBinInfo *info(RBinFile *bf) { @@ -172,7 +172,7 @@ static RBinInfo *info(RBinFile *bf) { } static void header(RBinFile *bf) { - const struct r_bin_mz_obj_t *mz = (struct r_bin_mz_obj_t *)bf->o->bin_obj; + const struct rz_bin_mz_obj_t *mz = (struct rz_bin_mz_obj_t *)bf->o->bin_obj; eprintf ("[0000:0000] Signature %c%c\n", mz->dos_header->signature & 0xFF, mz->dos_header->signature >> 8); @@ -204,37 +204,37 @@ static void header(RBinFile *bf) { mz->dos_header->overlay_number); } -static RList *relocs(RBinFile *bf) { - RList *ret = NULL; +static RzList *relocs(RBinFile *bf) { + RzList *ret = NULL; RBinReloc *rel = NULL; - const struct r_bin_mz_reloc_t *relocs = NULL; + const struct rz_bin_mz_reloc_t *relocs = NULL; int i; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - if (!(relocs = r_bin_mz_get_relocs (bf->o->bin_obj))) { + if (!(relocs = rz_bin_mz_get_relocs (bf->o->bin_obj))) { return ret; } for (i = 0; !relocs[i].last; i++) { if (!(rel = R_NEW0 (RBinReloc))) { free ((void *)relocs); - r_list_free (ret); + rz_list_free (ret); return NULL; } rel->type = R_BIN_RELOC_16; rel->vaddr = relocs[i].vaddr; rel->paddr = relocs[i].paddr; - r_list_append (ret, rel); + rz_list_append (ret, rel); } free ((void *)relocs); return ret; } -RBinPlugin r_bin_plugin_mz = { +RBinPlugin rz_bin_plugin_mz = { .name = "mz", .desc = "MZ bin plugin", .license = "MIT", @@ -252,9 +252,9 @@ RBinPlugin r_bin_plugin_mz = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_mz, + .data = &rz_bin_plugin_mz, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_ne.c b/librz/bin/p/bin_ne.c similarity index 77% rename from libr/bin/p/bin_ne.c rename to librz/bin/p/bin_ne.c index dcf8f194dc..aa8357eae8 100644 --- a/libr/bin/p/bin_ne.c +++ b/librz/bin/p/bin_ne.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2009-2019 - GustavoLCR, nibble, pancake, alvarofe */ -#include +#include #include "../i/private.h" #include "../format/ne/ne.h" static bool check_buffer(RBuffer *b) { - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (length <= 0x3d) { return false; } - ut16 idx = r_buf_read_le16_at (b, 0x3c); + ut16 idx = rz_buf_read_le16_at (b, 0x3c); if ((ut64)idx + 26 < length) { ut8 buf[2]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "MZ", 2)) { - r_buf_read_at (b, idx, buf, sizeof (buf)); + rz_buf_read_at (b, idx, buf, sizeof (buf)); if (!memcmp (buf, "NE", 2)) { return true; } @@ -24,8 +24,8 @@ static bool check_buffer(RBuffer *b) { } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && bin_obj && buf, false); - r_bin_ne_obj_t *res = r_bin_ne_new_buf (buf, bf->rbin->verbose); + rz_return_val_if_fail (bf && bin_obj && buf, false); + rz_bin_ne_obj_t *res = rz_bin_ne_new_buf (buf, bf->rbin->verbose); if (res) { *bin_obj = res; return true; @@ -34,12 +34,12 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy (RBinFile *bf) { - r_bin_ne_free (bf->o->bin_obj); + rz_bin_ne_free (bf->o->bin_obj); } static void header(RBinFile *bf) { - struct r_bin_t *rbin = bf->rbin; - r_bin_ne_obj_t *ne = bf->o->bin_obj; + struct rz_bin_t *rbin = bf->rbin; + rz_bin_ne_obj_t *ne = bf->o->bin_obj; rbin->cb_printf ("Signature: NE\n"); rbin->cb_printf ("MajLinkerVersion: %d\n", ne->ne_header->MajLinkerVersion); rbin->cb_printf ("MinLinkerVersion: %d\n", ne->ne_header->MinLinkerVersion); @@ -75,38 +75,38 @@ static void header(RBinFile *bf) { } RBinInfo *info(RBinFile *bf) { - r_bin_ne_obj_t *ne = bf->o->bin_obj; + rz_bin_ne_obj_t *ne = bf->o->bin_obj; RBinInfo *i = R_NEW0 (RBinInfo); if (i) { i->bits = 16; i->arch = strdup ("x86"); i->os = strdup (ne->os); - i->claimed_checksum = r_str_newf ("%08x", ne->ne_header->FileLoadCRC); + i->claimed_checksum = rz_str_newf ("%08x", ne->ne_header->FileLoadCRC); } return i; } -RList *entries(RBinFile *bf) { - return r_bin_ne_get_entrypoints (bf->o->bin_obj); +RzList *entries(RBinFile *bf) { + return rz_bin_ne_get_entrypoints (bf->o->bin_obj); } -RList *symbols(RBinFile *bf) { - return r_bin_ne_get_symbols (bf->o->bin_obj); +RzList *symbols(RBinFile *bf) { + return rz_bin_ne_get_symbols (bf->o->bin_obj); } -RList *imports(RBinFile *bf) { - return r_bin_ne_get_imports (bf->o->bin_obj); +RzList *imports(RBinFile *bf) { + return rz_bin_ne_get_imports (bf->o->bin_obj); } -RList *sections(RBinFile *bf) { - return r_bin_ne_get_segments (bf->o->bin_obj); +RzList *sections(RBinFile *bf) { + return rz_bin_ne_get_segments (bf->o->bin_obj); } -RList *relocs(RBinFile *bf) { - return r_bin_ne_get_relocs (bf->o->bin_obj); +RzList *relocs(RBinFile *bf) { + return rz_bin_ne_get_relocs (bf->o->bin_obj); } -RBinPlugin r_bin_plugin_ne = { +RBinPlugin rz_bin_plugin_ne = { .name = "ne", .desc = "NE format r2 plugin", .author = "GustavoLCR", @@ -125,9 +125,9 @@ RBinPlugin r_bin_plugin_ne = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_ne, + .data = &rz_bin_plugin_ne, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_nes.c b/librz/bin/p/bin_nes.c similarity index 74% rename from libr/bin/p/bin_nes.c rename to librz/bin/p/bin_nes.c index 89c23bdfd1..61a2fab81f 100644 --- a/libr/bin/p/bin_nes.c +++ b/librz/bin/p/bin_nes.c @@ -1,14 +1,14 @@ /* radare - LGPL3 - 2015-2019 - maijin */ -#include -#include +#include +#include #include "nes/nes_specs.h" static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) > 4) { + if (rz_buf_size (b) > 4) { ut8 buf[4]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); return (!memcmp (buf, INES_MAGIC, sizeof (buf))); } return false; @@ -22,7 +22,7 @@ static RBinInfo *info(RBinFile *bf) { RBinInfo *ret = NULL; ines_hdr ihdr; memset (&ihdr, 0, INES_HDR_SIZE); - int reat = r_buf_read_at (bf->buf, 0, (ut8*)&ihdr, INES_HDR_SIZE); + int reat = rz_buf_read_at (bf->buf, 0, (ut8*)&ihdr, INES_HDR_SIZE); if (reat != INES_HDR_SIZE) { eprintf ("Truncated Header\n"); return NULL; @@ -40,7 +40,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static void addsym(RList *ret, const char *name, ut64 addr, ut32 size) { +static void addsym(RzList *ret, const char *name, ut64 addr, ut32 size) { RBinSymbol *ptr = R_NEW0 (RBinSymbol); if (!ptr) { return; @@ -49,12 +49,12 @@ static void addsym(RList *ret, const char *name, ut64 addr, ut32 size) { ptr->paddr = ptr->vaddr = addr; ptr->size = size; ptr->ordinal = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } -static RList* symbols(RBinFile *bf) { - RList *ret = NULL; - if (!(ret = r_list_newf (free))) { +static RzList* symbols(RBinFile *bf) { + RzList *ret = NULL; + if (!(ret = rz_list_newf (free))) { return NULL; } addsym (ret, "NMI_VECTOR_START_ADDRESS", NMI_VECTOR_START_ADDRESS,2); @@ -82,17 +82,17 @@ static RList* symbols(RBinFile *bf) { return ret; } -static RList* sections(RBinFile *bf) { - RList *ret = NULL; +static RzList* sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; ines_hdr ihdr; memset (&ihdr, 0, INES_HDR_SIZE); - int reat = r_buf_read_at (bf->buf, 0, (ut8*)&ihdr, INES_HDR_SIZE); + int reat = rz_buf_read_at (bf->buf, 0, (ut8*)&ihdr, INES_HDR_SIZE); if (reat != INES_HDR_SIZE) { eprintf ("Truncated Header\n"); return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(ptr = R_NEW0 (RBinSection))) { @@ -105,7 +105,7 @@ static RList* sections(RBinFile *bf) { ptr->vsize = ROM_SIZE; ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (ROM_START_ADDRESS + ptr->size <= ROM_MIRROR_ADDRESS) { // not a 256bit ROM, mapper 0 mirrors the complete ROM in this case if (!(ptr = R_NEW0 (RBinSection))) { @@ -118,94 +118,94 @@ static RList* sections(RBinFile *bf) { ptr->vsize = ROM_MIRROR_SIZE; ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *mem(RBinFile *bf) { - RList *ret; +static RzList *mem(RBinFile *bf) { + RzList *ret; RBinMem *m, *n; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("RAM"); m->addr = RAM_START_ADDRESS; m->size = RAM_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(n = R_NEW0 (RBinMem))) { return ret; } - m->mirrors = r_list_new (); + m->mirrors = rz_list_new (); n->name = strdup ("RAM_MIRROR_2"); n->addr = RAM_MIRROR_2_ADDRESS; n->size = RAM_MIRROR_2_SIZE; - n->perms = r_str_rwx ("rwx"); - r_list_append (m->mirrors, n); + n->perms = rz_str_rwx ("rwx"); + rz_list_append (m->mirrors, n); if (!(n = R_NEW0 (RBinMem))) { - r_list_free (m->mirrors); + rz_list_free (m->mirrors); m->mirrors = NULL; return ret; } n->name = strdup ("RAM_MIRROR_3"); n->addr = RAM_MIRROR_3_ADDRESS; n->size = RAM_MIRROR_3_SIZE; - n->perms = r_str_rwx ("rwx"); - r_list_append (m->mirrors, n); + n->perms = rz_str_rwx ("rwx"); + rz_list_append (m->mirrors, n); if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("PPU_REG"); m->addr = PPU_REG_ADDRESS; m->size = PPU_REG_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); - m->mirrors = r_list_new (); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); + m->mirrors = rz_list_new (); int i; for (i = 1; i < 1024; i++) { if (!(n = R_NEW0 (RBinMem))) { - r_list_free (m->mirrors); + rz_list_free (m->mirrors); m->mirrors = NULL; return ret; } - n->name = r_str_newf ("PPU_REG_MIRROR_%d", i); + n->name = rz_str_newf ("PPU_REG_MIRROR_%d", i); n->addr = PPU_REG_ADDRESS+i*PPU_REG_SIZE; n->size = PPU_REG_SIZE; - n->perms = r_str_rwx ("rwx"); - r_list_append (m->mirrors, n); + n->perms = rz_str_rwx ("rwx"); + rz_list_append (m->mirrors, n); } if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("APU_AND_IOREGS"); m->addr = APU_AND_IOREGS_START_ADDRESS; m->size = APU_AND_IOREGS_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("SRAM"); m->addr = SRAM_START_ADDRESS; m->size = SRAM_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); return ret; } -static RList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR - RList *ret; +static RzList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(ptr = R_NEW0 (RBinAddr))) { @@ -213,7 +213,7 @@ static RList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESE } ptr->paddr = INES_HDR_SIZE; ptr->vaddr = ROM_START_ADDRESS; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } @@ -222,7 +222,7 @@ static ut64 baddr(RBinFile *bf) { return 0; } -RBinPlugin r_bin_plugin_nes = { +RBinPlugin rz_bin_plugin_nes = { .name = "nes", .desc = "NES", .license = "MIT", @@ -237,9 +237,9 @@ RBinPlugin r_bin_plugin_nes = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_nes, + .data = &rz_bin_plugin_nes, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_nin3ds.c b/librz/bin/p/bin_nin3ds.c similarity index 76% rename from libr/bin/p/bin_nin3ds.c rename to librz/bin/p/bin_nin3ds.c index d52ba7eb12..bfecc056f0 100644 --- a/libr/bin/p/bin_nin3ds.c +++ b/librz/bin/p/bin_nin3ds.c @@ -1,9 +1,9 @@ /* radare - LGPL - 2018-2019 - a0rtega */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "nin/n3ds.h" @@ -12,26 +12,26 @@ static struct n3ds_firm_hdr loaded_header; static bool check_buffer(RBuffer *b) { ut8 magic[4]; - r_buf_read_at (b, 0, magic, sizeof (magic)); + rz_buf_read_at (b, 0, magic, sizeof (magic)); return (!memcmp (magic, "FIRM", 4)); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { - if (r_buf_read_at (b, 0, (ut8*)&loaded_header, sizeof (loaded_header)) == sizeof (loaded_header)) { + if (rz_buf_read_at (b, 0, (ut8*)&loaded_header, sizeof (loaded_header)) == sizeof (loaded_header)) { *bin_obj = &loaded_header; return true; } return false; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *sections[4] = { NULL, NULL, NULL, NULL }; int i, corrupt = false; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } @@ -53,7 +53,7 @@ static RList *sections(RBinFile *bf) { sections[i]->vsize = loaded_header.sections[i].size; sections[i]->paddr = loaded_header.sections[i].offset; sections[i]->vaddr = loaded_header.sections[i].address; - sections[i]->perm = r_str_rwx ("rwx"); + sections[i]->perm = rz_str_rwx ("rwx"); sections[i]->add = true; } } @@ -64,20 +64,20 @@ static RList *sections(RBinFile *bf) { if (corrupt) { free (sections[i]); } else { - r_list_append (ret, sections[i]); + rz_list_append (ret, sections[i]); } } } if (corrupt) { - r_list_free (ret); + rz_list_free (ret); return NULL; } return ret; } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_new (); RBinAddr *ptr9 = NULL, *ptr11 = NULL; if (bf && bf->buf) { @@ -86,22 +86,22 @@ static RList *entries(RBinFile *bf) { } ret->free = free; if (!(ptr9 = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } if (!(ptr11 = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); free (ptr9); return NULL; } /* ARM9 entry point */ ptr9->vaddr = loaded_header.arm9_ep; - r_list_append (ret, ptr9); + rz_list_append (ret, ptr9); /* ARM11 entry point */ ptr11->vaddr = loaded_header.arm11_ep; - r_list_append (ret, ptr11); + rz_list_append (ret, ptr11); } return ret; } @@ -127,9 +127,9 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -RBinPlugin r_bin_plugin_nin3ds = { +RBinPlugin rz_bin_plugin_nin3ds = { .name = "nin3ds", - .desc = "Nintendo 3DS FIRM format r_bin plugin", + .desc = "Nintendo 3DS FIRM format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .check_buffer = &check_buffer, @@ -139,9 +139,9 @@ RBinPlugin r_bin_plugin_nin3ds = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_nin3ds, + .data = &rz_bin_plugin_nin3ds, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_ninds.c b/librz/bin/p/bin_ninds.c similarity index 73% rename from libr/bin/p/bin_ninds.c rename to librz/bin/p/bin_ninds.c index 0ca5b7467a..1bbf9b3082 100644 --- a/libr/bin/p/bin_ninds.c +++ b/librz/bin/p/bin_ninds.c @@ -1,9 +1,9 @@ /* radare - LGPL - 2015-2019 - a0rtega */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "../format/nin/nds.h" @@ -12,7 +12,7 @@ static struct nds_hdr loaded_header; static bool check_buffer(RBuffer *b) { ut8 ninlogohead[6]; - if (r_buf_read_at (b, 0xc0, ninlogohead, sizeof (ninlogohead)) == 6) { + if (rz_buf_read_at (b, 0xc0, ninlogohead, sizeof (ninlogohead)) == 6) { /* begin of nintendo logo = \x24\xff\xae\x51\x69\x9a */ if (!memcmp (ninlogohead, "\x24\xff\xae\x51\x69\x9a", 6)) { return true; @@ -26,7 +26,7 @@ static bool check_buffer(RBuffer *b) { } static bool load_buffer (RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { - r_buf_read_at (b, 0, (ut8*)&loaded_header, sizeof (loaded_header)); + rz_buf_read_at (b, 0, (ut8*)&loaded_header, sizeof (loaded_header)); *bin_obj = &loaded_header; return (*bin_obj != NULL); } @@ -39,19 +39,19 @@ static ut64 boffset(RBinFile *bf) { return 0LL; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr9 = NULL, *ptr7 = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(ptr9 = R_NEW0 (RBinSection))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } if (!(ptr7 = R_NEW0 (RBinSection))) { - r_list_free (ret); + rz_list_free (ret); free (ptr9); return NULL; } @@ -61,24 +61,24 @@ static RList *sections(RBinFile *bf) { ptr9->vsize = loaded_header.arm9_size; ptr9->paddr = loaded_header.arm9_rom_offset; ptr9->vaddr = loaded_header.arm9_ram_address; - ptr9->perm = r_str_rwx ("rwx"); + ptr9->perm = rz_str_rwx ("rwx"); ptr9->add = true; - r_list_append (ret, ptr9); + rz_list_append (ret, ptr9); ptr7->name = strdup ("arm7"); ptr7->size = loaded_header.arm7_size; ptr7->vsize = loaded_header.arm7_size; ptr7->paddr = loaded_header.arm7_rom_offset; ptr7->vaddr = loaded_header.arm7_ram_address; - ptr7->perm = r_str_rwx ("rwx"); + ptr7->perm = rz_str_rwx ("rwx"); ptr7->add = true; - r_list_append (ret, ptr7); + rz_list_append (ret, ptr7); return ret; } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_new (); RBinAddr *ptr9 = NULL, *ptr7 = NULL; if (bf && bf->buf) { @@ -87,11 +87,11 @@ static RList *entries(RBinFile *bf) { } ret->free = free; if (!(ptr9 = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } if (!(ptr7 = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); free (ptr9); return NULL; } @@ -99,21 +99,21 @@ static RList *entries(RBinFile *bf) { /* ARM9 entry point */ ptr9->vaddr = loaded_header.arm9_entry_address; // ptr9->paddr = loaded_header.arm9_entry_address; - r_list_append (ret, ptr9); + rz_list_append (ret, ptr9); /* ARM7 entry point */ ptr7->vaddr = loaded_header.arm7_entry_address; // ptr7->paddr = loaded_header.arm7_entry_address; - r_list_append (ret, ptr7); + rz_list_append (ret, ptr7); } return ret; } static RBinInfo *info(RBinFile *bf) { - r_return_val_if_fail (bf && bf->buf, NULL); + rz_return_val_if_fail (bf && bf->buf, NULL); RBinInfo *ret = R_NEW0 (RBinInfo); if (ret) { - char *filepath = r_str_newf ("%.12s - %.4s", + char *filepath = rz_str_newf ("%.12s - %.4s", loaded_header.title, loaded_header.gamecode); ret->file = filepath; ret->type = strdup ("ROM"); @@ -126,9 +126,9 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -RBinPlugin r_bin_plugin_ninds = { +RBinPlugin rz_bin_plugin_ninds = { .name = "ninds", - .desc = "Nintendo DS format r_bin plugin", + .desc = "Nintendo DS format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .check_buffer = &check_buffer, @@ -140,9 +140,9 @@ RBinPlugin r_bin_plugin_ninds = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_ninds, + .data = &rz_bin_plugin_ninds, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_ningb.c b/librz/bin/p/bin_ningb.c similarity index 73% rename from libr/bin/p/bin_ningb.c rename to librz/bin/p/bin_ningb.c index a8a90c7ad3..4cc99aef86 100644 --- a/libr/bin/p/bin_ningb.c +++ b/librz/bin/p/bin_ningb.c @@ -1,15 +1,15 @@ /* radare - LGPL - 2013 - 2017 - condret@runas-racer.com */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "../format/nin/nin.h" static bool check_buffer(RBuffer *b) { ut8 lict[sizeof (lic)]; - if (r_buf_read_at (b, 0x104, lict, sizeof (lict)) == sizeof (lict)) { + if (rz_buf_read_at (b, 0x104, lict, sizeof (lict)) == sizeof (lict)) { return !memcmp (lict, lic, sizeof (lict)); } return false; @@ -30,7 +30,7 @@ static RBinAddr* binsym(RBinFile *bf, int type) { if (!ret) { return NULL; } - r_buf_read_at (bf->buf, 0x100, init_jmp, 4); + rz_buf_read_at (bf->buf, 0x100, init_jmp, 4); if (init_jmp[1] == 0xc3) { ret->paddr = ret->vaddr = init_jmp[3]*0x100 + init_jmp[2]; return ret; @@ -40,8 +40,8 @@ static RBinAddr* binsym(RBinFile *bf, int type) { return NULL; } -static RList* entries(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList* entries(RBinFile *bf) { + RzList *ret = rz_list_new (); RBinAddr *ptr = NULL; if (bf && bf->buf != NULL) { @@ -53,26 +53,26 @@ static RList* entries(RBinFile *bf) { return ret; } ptr->paddr = ptr->vaddr = ptr->hpaddr = 0x100; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList* sections(RBinFile *bf){ +static RzList* sections(RBinFile *bf){ ut8 bank; int i; - RList *ret; + RzList *ret; if (!bf) { return NULL; } - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { return NULL; } - r_buf_read_at (bf->buf, 0x148, &bank, 1); + rz_buf_read_at (bf->buf, 0x148, &bank, 1); bank = gb_get_rombanks(bank); #ifdef _MSC_VER RBinSection **rombank = (RBinSection**) malloc (sizeof (RBinSection*) * bank); @@ -96,20 +96,20 @@ static RList* sections(RBinFile *bf){ rombank[0]->size = 0x4000; rombank[0]->vsize = 0x4000; rombank[0]->vaddr = 0; - rombank[0]->perm = r_str_rwx ("rx"); + rombank[0]->perm = rz_str_rwx ("rx"); rombank[0]->add = true; - r_list_append (ret, rombank[0]); + rz_list_append (ret, rombank[0]); for (i = 1; i < bank; i++) { rombank[i] = R_NEW0 (RBinSection); - rombank[i]->name = r_str_newf ("rombank%02x", i); + rombank[i]->name = rz_str_newf ("rombank%02x", i); rombank[i]->paddr = i*0x4000; rombank[i]->vaddr = i*0x10000-0xc000; //spaaaaaaaaaaaaaaaace!!! rombank[i]->size = rombank[i]->vsize = 0x4000; - rombank[i]->perm = r_str_rwx ("rx"); + rombank[i]->perm = rz_str_rwx ("rx"); rombank[i]->add = true; - r_list_append (ret,rombank[i]); + rz_list_append (ret,rombank[i]); } #ifdef _MSC_VER free (rombank); @@ -117,11 +117,11 @@ static RList* sections(RBinFile *bf){ return ret; } -static RList* symbols(RBinFile *bf) { - RList *ret = NULL; +static RzList* symbols(RBinFile *bf) { + RzList *ret = NULL; RBinSymbol *ptr[13]; int i; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -131,11 +131,11 @@ static RList* symbols(RBinFile *bf) { ret->free (ret); return NULL; } - ptr[i]->name = r_str_newf ("rst_%i", i*8); + ptr[i]->name = rz_str_newf ("rst_%i", i*8); ptr[i]->paddr = ptr[i]->vaddr = i*8; ptr[i]->size = 1; ptr[i]->ordinal = i; - r_list_append (ret, ptr[i]); + rz_list_append (ret, ptr[i]); } if (!(ptr[8] = R_NEW0 (RBinSymbol))) { @@ -146,7 +146,7 @@ static RList* symbols(RBinFile *bf) { ptr[8]->paddr = ptr[8]->vaddr = 64; ptr[8]->size = 1; ptr[8]->ordinal = 8; - r_list_append (ret, ptr[8]); + rz_list_append (ret, ptr[8]); if (!(ptr[9] = R_NEW0 (RBinSymbol))) { return ret; @@ -156,7 +156,7 @@ static RList* symbols(RBinFile *bf) { ptr[9]->paddr = ptr[9]->vaddr = 72; ptr[9]->size = 1; ptr[9]->ordinal = 9; - r_list_append (ret, ptr[9]); + rz_list_append (ret, ptr[9]); if (!(ptr[10] = R_NEW0 (RBinSymbol))) { return ret; @@ -166,7 +166,7 @@ static RList* symbols(RBinFile *bf) { ptr[10]->paddr = ptr[10]->vaddr = 80; ptr[10]->size = 1; ptr[10]->ordinal = 10; - r_list_append (ret, ptr[10]); + rz_list_append (ret, ptr[10]); if (!(ptr[11] = R_NEW0 (RBinSymbol))) { return ret; @@ -176,7 +176,7 @@ static RList* symbols(RBinFile *bf) { ptr[11]->paddr = ptr[11]->vaddr = 88; ptr[11]->size = 1; ptr[11]->ordinal = 11; - r_list_append (ret, ptr[11]); + rz_list_append (ret, ptr[11]); if (!(ptr[12] = R_NEW0 (RBinSymbol))) { return ret; @@ -186,7 +186,7 @@ static RList* symbols(RBinFile *bf) { ptr[12]->paddr = ptr[12]->vaddr = 96; ptr[12]->size = 1; ptr[12]->ordinal = 12; - r_list_append (ret, ptr[12]); + rz_list_append (ret, ptr[12]); return ret; } @@ -198,8 +198,8 @@ static RBinInfo* info(RBinFile *bf) { free (ret); return NULL; } - r_buf_read_at (bf->buf, 0x104, rom_header, 76); - ret->file = r_str_ndup ((const char*)&rom_header[48], 16); + rz_buf_read_at (bf->buf, 0x104, rom_header, 76); + ret->file = rz_str_ndup ((const char*)&rom_header[48], 16); ret->type = malloc (128); ret->type[0] = 0; gb_get_gbtype (ret->type, rom_header[66], rom_header[63]); @@ -214,22 +214,22 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -RList *mem (RBinFile *bf) { - RList *ret; +RzList *mem (RBinFile *bf) { + RzList *ret; RBinMem *m, *n; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("fastram"); m->addr = 0xff80LL; m->size = 0x80; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; @@ -237,8 +237,8 @@ RList *mem (RBinFile *bf) { m->name = strdup ("ioports"); m->addr = 0xff00LL; m->size = 0x4c; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; @@ -246,8 +246,8 @@ RList *mem (RBinFile *bf) { m->name = strdup ("oam"); m->addr = 0xfe00LL; m->size = 0xa0; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; @@ -255,8 +255,8 @@ RList *mem (RBinFile *bf) { m->name = strdup ("videoram"); m->addr = 0x8000LL; m->size = 0x2000; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; @@ -264,28 +264,28 @@ RList *mem (RBinFile *bf) { m->name = strdup ("iram"); m->addr = 0xc000LL; m->size = 0x2000; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); - if (!(m->mirrors = r_list_new ())) { + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); + if (!(m->mirrors = rz_list_new ())) { return ret; } if (!(n = R_NEW0 (RBinMem))) { - r_list_free (m->mirrors); + rz_list_free (m->mirrors); m->mirrors = NULL; return ret; } n->name = strdup ("iram_echo"); n->addr = 0xe000LL; n->size = 0x1e00; - n->perms = r_str_rwx ("rx"); - r_list_append (m->mirrors, n); + n->perms = rz_str_rwx ("rx"); + rz_list_append (m->mirrors, n); return ret; } -RBinPlugin r_bin_plugin_ningb = { +RBinPlugin rz_bin_plugin_ningb = { .name = "ningb", - .desc = "Gameboy format r_bin plugin", + .desc = "Gameboy format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .check_buffer = &check_buffer, @@ -299,9 +299,9 @@ RBinPlugin r_bin_plugin_ningb = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_ningb, + .data = &rz_bin_plugin_ningb, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_ningba.c b/librz/bin/p/bin_ningba.c similarity index 65% rename from libr/bin/p/bin_ningba.c rename to librz/bin/p/bin_ningba.c index 240e2f225b..15ead11dca 100644 --- a/libr/bin/p/bin_ningba.c +++ b/librz/bin/p/bin_ningba.c @@ -1,16 +1,16 @@ /* radare - LGPL - 2014-2019 - condret@runas-racer.com */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "../format/nin/gba.h" static bool check_buffer(RBuffer *b) { ut8 lict[156]; - r_return_val_if_fail (b, false); - r_buf_read_at (b, 4, (ut8*)lict, sizeof (lict)); + rz_return_val_if_fail (b, false); + rz_buf_read_at (b, 4, (ut8*)lict, sizeof (lict)); return !memcmp (lict, lic_gba, 156); } @@ -18,8 +18,8 @@ static bool load_buffer(RBinFile * bf, void **bin_obj, RBuffer *buf, ut64 loadad return check_buffer (buf); } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_newf (free); RBinAddr *ptr = NULL; if (bf && bf->buf) { @@ -30,7 +30,7 @@ static RList *entries(RBinFile *bf) { return ret; } ptr->paddr = ptr->vaddr = 0x8000000; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } @@ -49,9 +49,9 @@ static RBinInfo *info(RBinFile *bf) { } ret->lang = NULL; - r_buf_read_at (bf->buf, 0xa0, rom_info, 16); - ret->file = r_str_ndup ((const char *) rom_info, 12); - ret->type = r_str_ndup ((char *) &rom_info[12], 4); + rz_buf_read_at (bf->buf, 0xa0, rom_info, 16); + ret->file = rz_str_ndup ((const char *) rom_info, 12); + ret->type = rz_str_ndup ((char *) &rom_info[12], 4); ret->machine = strdup ("GameBoy Advance"); ret->os = strdup ("any"); ret->arch = strdup ("arm"); @@ -62,11 +62,11 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *s = R_NEW0 (RBinSection); - ut64 sz = r_buf_size (bf->buf); - if (!(ret = r_list_new ())) { + ut64 sz = rz_buf_size (bf->buf); + if (!(ret = rz_list_new ())) { free (s); return NULL; } @@ -78,13 +78,13 @@ static RList *sections(RBinFile *bf) { s->perm = R_PERM_RX; s->add = true; - r_list_append (ret, s); + rz_list_append (ret, s); return ret; } -RBinPlugin r_bin_plugin_ningba = { +RBinPlugin rz_bin_plugin_ningba = { .name = "ningba", - .desc = "Game Boy Advance format r_bin plugin", + .desc = "Game Boy Advance format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .check_buffer = &check_buffer, @@ -94,9 +94,9 @@ RBinPlugin r_bin_plugin_ningba = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_ningba, + .data = &rz_bin_plugin_ningba, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_nro.c b/librz/bin/p/bin_nro.c similarity index 71% rename from libr/bin/p/bin_nro.c rename to librz/bin/p/bin_nro.c index 9abcfaf064..24d0fbd27a 100644 --- a/libr/bin/p/bin_nro.c +++ b/librz/bin/p/bin_nro.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2017-2019 - pancake */ +/* rizin - LGPL - Copyright 2017-2019 - pancake */ // TODO: Support NRR and MODF -#include -#include -#include -#include +#include +#include +#include +#include #include "nxo/nxo.h" -#define NRO_OFF(x) (sizeof (NXOStart) + r_offsetof (NROHeader, x)) -#define NRO_OFFSET_MODMEMOFF r_offsetof (NXOStart, mod_memoffset) +#define NRO_OFF(x) (sizeof (NXOStart) + rz_offsetof (NROHeader, x)) +#define NRO_OFFSET_MODMEMOFF rz_offsetof (NXOStart, mod_memoffset) // starting at 0x10 (16th byte) typedef struct { @@ -27,12 +27,12 @@ typedef struct { } NROHeader; static ut64 baddr(RBinFile *bf) { - return bf? r_buf_read_le32_at (bf->buf, NRO_OFFSET_MODMEMOFF): 0; + return bf? rz_buf_read_le32_at (bf->buf, NRO_OFFSET_MODMEMOFF): 0; } static bool check_buffer(RBuffer *b) { ut8 magic[4]; - if (r_buf_read_at (b, NRO_OFF (magic), magic, sizeof (magic)) == 4) { + if (rz_buf_read_at (b, NRO_OFF (magic), magic, sizeof (magic)) == 4) { return fileType (magic) != NULL; } return false; @@ -43,10 +43,10 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, RBinNXOObj *bin = R_NEW0 (RBinNXOObj); if (bin) { ut64 ba = baddr (bf); - bin->methods_list = r_list_newf ((RListFree)free); - bin->imports_list = r_list_newf ((RListFree)free); - bin->classes_list = r_list_newf ((RListFree)free); - ut32 mod0 = r_buf_read_le32_at (b, NRO_OFFSET_MODMEMOFF); + bin->methods_list = rz_list_newf ((RzListFree)free); + bin->imports_list = rz_list_newf ((RzListFree)free); + bin->classes_list = rz_list_newf ((RzListFree)free); + ut32 mod0 = rz_buf_read_le32_at (b, NRO_OFFSET_MODMEMOFF); parseMod (b, bin, mod0, ba); *bin_obj = bin; } @@ -57,17 +57,17 @@ static RBinAddr *binsym(RBinFile *bf, int type) { return NULL; // TODO } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if ((ptr = R_NEW0 (RBinAddr))) { ptr->paddr = 0x80; ptr->vaddr = ptr->paddr + baddr (bf); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } @@ -84,14 +84,14 @@ static Sdb *get_sdb(RBinFile *bf) { return kv; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; RBuffer *b = bf->buf; if (!bf->o->info) { return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -108,16 +108,16 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = 0; ptr->perm = R_PERM_R; ptr->add = false; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); - int bufsz = r_buf_size (bf->buf); + int bufsz = rz_buf_size (bf->buf); - ut32 mod0 = r_buf_read_le32_at (bf->buf, NRO_OFFSET_MODMEMOFF); + ut32 mod0 = rz_buf_read_le32_at (bf->buf, NRO_OFFSET_MODMEMOFF); if (mod0 && mod0 + 8 < bufsz) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; } - ut32 mod0sz = r_buf_read_le32_at (bf->buf, mod0 + 4); + ut32 mod0sz = rz_buf_read_le32_at (bf->buf, mod0 + 4); ptr->name = strdup ("mod0"); ptr->size = mod0sz; ptr->vsize = mod0sz; @@ -125,17 +125,17 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = mod0 + ba; ptr->perm = R_PERM_R; // rw- ptr->add = false; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } else { eprintf ("Invalid MOD0 address\n"); } - ut32 sig0 = r_buf_read_le32_at (bf->buf, 0x18); + ut32 sig0 = rz_buf_read_le32_at (bf->buf, 0x18); if (sig0 && sig0 + 8 < bufsz) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; } - ut32 sig0sz = r_buf_read_le32_at (bf->buf, sig0 + 4); + ut32 sig0sz = rz_buf_read_le32_at (bf->buf, sig0 + 4); ptr->name = strdup ("sig0"); ptr->size = sig0sz; ptr->vsize = sig0sz; @@ -143,7 +143,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = sig0 + ba; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } else { eprintf ("Invalid SIG0 address\n"); } @@ -153,46 +153,46 @@ static RList *sections(RBinFile *bf) { return ret; } ptr->name = strdup ("text"); - ptr->vsize = r_buf_read_le32_at (b, NRO_OFF (text_size)); + ptr->vsize = rz_buf_read_le32_at (b, NRO_OFF (text_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NRO_OFF (text_memoffset)); + ptr->paddr = rz_buf_read_le32_at (b, NRO_OFF (text_memoffset)); ptr->vaddr = ptr->paddr + ba; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add ro segment if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("ro"); - ptr->vsize = r_buf_read_le32_at (b, NRO_OFF (ro_size)); + ptr->vsize = rz_buf_read_le32_at (b, NRO_OFF (ro_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NRO_OFF (ro_memoffset)); + ptr->paddr = rz_buf_read_le32_at (b, NRO_OFF (ro_memoffset)); ptr->vaddr = ptr->paddr + ba; ptr->perm = R_PERM_R; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add data segment if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("data"); - ptr->vsize = r_buf_read_le32_at (b, NRO_OFF (data_size)); + ptr->vsize = rz_buf_read_le32_at (b, NRO_OFF (data_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NRO_OFF (data_memoffset)); + ptr->paddr = rz_buf_read_le32_at (b, NRO_OFF (data_memoffset)); ptr->vaddr = ptr->paddr + ba; ptr->perm = R_PERM_RW; ptr->add = true; eprintf ("Base Address 0x%08"PFMT64x "\n", ba); eprintf ("BSS Size 0x%08"PFMT64x "\n", (ut64) - r_buf_read_le32_at (bf->buf, NRO_OFF (bss_size))); - r_list_append (ret, ptr); + rz_buf_read_le32_at (bf->buf, NRO_OFF (bss_size))); + rz_list_append (ret, ptr); return ret; } -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { RBinNXOObj *bin; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; @@ -201,7 +201,7 @@ static RList *symbols(RBinFile *bf) { return bin->methods_list; } -static RList *imports(RBinFile *bf) { +static RzList *imports(RBinFile *bf) { RBinNXOObj *bin; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; @@ -210,7 +210,7 @@ static RList *imports(RBinFile *bf) { return bin->imports_list; } -static RList *libs(RBinFile *bf) { +static RzList *libs(RBinFile *bf) { return NULL; } @@ -220,7 +220,7 @@ static RBinInfo *info(RBinFile *bf) { return NULL; } ut8 magic[4]; - r_buf_read_at (bf->buf, NRO_OFF (magic), magic, sizeof (magic)); + rz_buf_read_at (bf->buf, NRO_OFF (magic), magic, sizeof (magic)); const char *ft = fileType (magic); if (!ft) { ft = "nro"; @@ -252,7 +252,7 @@ static RBinInfo *info(RBinFile *bf) { #if !R_BIN_NRO -RBinPlugin r_bin_plugin_nro = { +RBinPlugin rz_bin_plugin_nro = { .name = "nro", .desc = "Nintendo Switch NRO0 binaries", .license = "MIT", @@ -270,9 +270,9 @@ RBinPlugin r_bin_plugin_nro = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_nro, + .data = &rz_bin_plugin_nro, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_nso.c b/librz/bin/p/bin_nso.c similarity index 63% rename from libr/bin/p/bin_nso.c rename to librz/bin/p/bin_nso.c index 667fb8866a..5453ff197c 100644 --- a/libr/bin/p/bin_nso.c +++ b/librz/bin/p/bin_nso.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2017-2018 - rkx1209 */ +/* rizin - LGPL - Copyright 2017-2018 - rkx1209 */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "nxo/nxo.h" #ifdef R_MESON_VERSION #include @@ -13,8 +13,8 @@ #include "../../../shlr/lz4/lz4.c" #endif -#define NSO_OFF(x) r_offsetof (NSOHeader, x) -#define NSO_OFFSET_MODMEMOFF r_offsetof (NXOStart, mod_memoffset) +#define NSO_OFF(x) rz_offsetof (NSOHeader, x) +#define NSO_OFFSET_MODMEMOFF rz_offsetof (NXOStart, mod_memoffset) // starting at 0 typedef struct { @@ -48,9 +48,9 @@ static ut64 baddr(RBinFile *bf) { } static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) >= 0x20) { + if (rz_buf_size (b) >= 0x20) { ut8 magic[4]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) != 4) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) != 4) { return false; } return fileType (magic) != NULL; @@ -61,9 +61,9 @@ static bool check_buffer(RBuffer *b) { static RBinNXOObj *nso_new(void) { RBinNXOObj *bin = R_NEW0 (RBinNXOObj); if (bin) { - bin->methods_list = r_list_newf ((RListFree)free); - bin->imports_list = r_list_newf ((RListFree)free); - bin->classes_list = r_list_newf ((RListFree)free); + bin->methods_list = rz_list_newf ((RzListFree)free); + bin->imports_list = rz_list_newf ((RzListFree)free); + bin->classes_list = rz_list_newf ((RzListFree)free); } return bin; } @@ -71,14 +71,14 @@ static RBinNXOObj *nso_new(void) { static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) { eprintf ("load_bytes in bin.nso must die\n"); RBin *rbin = bf->rbin; - ut32 toff = r_buf_read_le32_at (bf->buf, NSO_OFF (text_memoffset)); - ut32 tsize = r_buf_read_le32_at (bf->buf, NSO_OFF (text_size)); - ut32 rooff = r_buf_read_le32_at (bf->buf, NSO_OFF (ro_memoffset)); - ut32 rosize = r_buf_read_le32_at (bf->buf, NSO_OFF (ro_size)); - ut32 doff = r_buf_read_le32_at (bf->buf, NSO_OFF (data_memoffset)); - ut32 dsize = r_buf_read_le32_at (bf->buf, NSO_OFF (data_size)); + ut32 toff = rz_buf_read_le32_at (bf->buf, NSO_OFF (text_memoffset)); + ut32 tsize = rz_buf_read_le32_at (bf->buf, NSO_OFF (text_size)); + ut32 rooff = rz_buf_read_le32_at (bf->buf, NSO_OFF (ro_memoffset)); + ut32 rosize = rz_buf_read_le32_at (bf->buf, NSO_OFF (ro_size)); + ut32 doff = rz_buf_read_le32_at (bf->buf, NSO_OFF (data_memoffset)); + ut32 dsize = rz_buf_read_le32_at (bf->buf, NSO_OFF (data_size)); ut64 total_size = tsize + rosize + dsize; - RBuffer *newbuf = r_buf_new_empty (total_size); + RBuffer *newbuf = rz_buf_new_empty (total_size); ut64 ba = baddr (bf); ut8 *tmp = NULL; @@ -95,7 +95,7 @@ static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut eprintf ("decompression failure\n"); goto fail; } - r_buf_write_at (newbuf, 0, tmp, tsize); + rz_buf_write_at (newbuf, 0, tmp, tsize); R_FREE (tmp); tmp = R_NEWS (ut8, rosize); @@ -106,42 +106,42 @@ static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut eprintf ("decompression2 failure\n"); goto fail; } - r_buf_write_at (newbuf, tsize, tmp, rosize); + rz_buf_write_at (newbuf, tsize, tmp, rosize); R_FREE (tmp); tmp = R_NEWS (ut8, dsize); if (!tmp) { goto fail; } - if (decompress (buf + doff, tmp, r_buf_size (bf->buf) - doff, dsize) != dsize) { + if (decompress (buf + doff, tmp, rz_buf_size (bf->buf) - doff, dsize) != dsize) { eprintf ("decompression3 failure\n"); goto fail; } - r_buf_write_at (newbuf, tsize + rosize, tmp, dsize); + rz_buf_write_at (newbuf, tsize + rosize, tmp, dsize); R_FREE (tmp); /* Load unpacked binary */ - const ut8 *tmpbuf = r_buf_data (newbuf, &total_size); - r_io_write_at (rbin->iob.io, ba, tmpbuf, total_size); - ut32 modoff = r_buf_read_le32_at (newbuf, NSO_OFFSET_MODMEMOFF); + const ut8 *tmpbuf = rz_buf_data (newbuf, &total_size); + rz_io_write_at (rbin->iob.io, ba, tmpbuf, total_size); + ut32 modoff = rz_buf_read_le32_at (newbuf, NSO_OFFSET_MODMEMOFF); RBinNXOObj *bin = nso_new (); eprintf ("MOD Offset = 0x%"PFMT64x"\n", (ut64)modoff); parseMod (newbuf, bin, modoff, ba); - r_buf_free (newbuf); + rz_buf_free (newbuf); *bin_obj = bin; return true; fail: free (tmp); - r_buf_free (newbuf); + rz_buf_free (newbuf); *bin_obj = NULL; return false; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && buf, NULL); + rz_return_val_if_fail (bf && buf, NULL); const ut64 la = bf->loadaddr; ut64 sz = 0; - const ut8 *bytes = r_buf_data (buf, &sz); + const ut8 *bytes = rz_buf_data (buf, &sz); return load_bytes (bf, bin_obj, bytes, sz, la, bf->sdb); } @@ -149,18 +149,18 @@ static RBinAddr *binsym(RBinFile *bf, int type) { return NULL; // TODO } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; RBuffer *b = bf->buf; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if ((ptr = R_NEW0 (RBinAddr))) { - ptr->paddr = r_buf_read_le32_at (b, NSO_OFF (text_memoffset)); - ptr->vaddr = r_buf_read_le32_at (b, NSO_OFF (text_loc)) + baddr (bf); - r_list_append (ret, ptr); + ptr->paddr = rz_buf_read_le32_at (b, NSO_OFF (text_memoffset)); + ptr->vaddr = rz_buf_read_le32_at (b, NSO_OFF (text_loc)) + baddr (bf); + rz_list_append (ret, ptr); } return ret; } @@ -177,14 +177,14 @@ static Sdb *get_sdb(RBinFile *bf) { return kv; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; RBuffer *b = bf->buf; if (!bf->o->info) { return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -195,54 +195,54 @@ static RList *sections(RBinFile *bf) { return ret; } ptr->name = strdup ("header"); - ptr->size = r_buf_read_le32_at (b, NSO_OFF (text_memoffset)); - ptr->vsize = r_buf_read_le32_at (b, NSO_OFF (text_memoffset)); + ptr->size = rz_buf_read_le32_at (b, NSO_OFF (text_memoffset)); + ptr->vsize = rz_buf_read_le32_at (b, NSO_OFF (text_memoffset)); ptr->paddr = 0; ptr->vaddr = 0; ptr->perm = R_PERM_R; ptr->add = false; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add text segment if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("text"); - ptr->vsize = r_buf_read_le32_at (b, NSO_OFF (text_size)); + ptr->vsize = rz_buf_read_le32_at (b, NSO_OFF (text_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NSO_OFF (text_memoffset)); - ptr->vaddr = r_buf_read_le32_at (b, NSO_OFF (text_loc)) + ba; + ptr->paddr = rz_buf_read_le32_at (b, NSO_OFF (text_memoffset)); + ptr->vaddr = rz_buf_read_le32_at (b, NSO_OFF (text_loc)) + ba; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add ro segment if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("ro"); - ptr->vsize = r_buf_read_le32_at (b, NSO_OFF (ro_size)); + ptr->vsize = rz_buf_read_le32_at (b, NSO_OFF (ro_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NSO_OFF (ro_memoffset)); - ptr->vaddr = r_buf_read_le32_at (b, NSO_OFF (ro_loc)) + ba; + ptr->paddr = rz_buf_read_le32_at (b, NSO_OFF (ro_memoffset)); + ptr->vaddr = rz_buf_read_le32_at (b, NSO_OFF (ro_loc)) + ba; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add data segment if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("data"); - ptr->vsize = r_buf_read_le32_at (b, NSO_OFF (data_size)); + ptr->vsize = rz_buf_read_le32_at (b, NSO_OFF (data_size)); ptr->size = ptr->vsize; - ptr->paddr = r_buf_read_le32_at (b, NSO_OFF (data_memoffset)); - ptr->vaddr = r_buf_read_le32_at (b, NSO_OFF (data_loc)) + ba; + ptr->paddr = rz_buf_read_le32_at (b, NSO_OFF (data_memoffset)); + ptr->vaddr = rz_buf_read_le32_at (b, NSO_OFF (data_loc)) + ba; ptr->perm = R_PERM_RW; ptr->add = true; eprintf ("BSS Size 0x%08"PFMT64x "\n", (ut64) - r_buf_read_le32_at (bf->buf, NSO_OFF (bss_size))); - r_list_append (ret, ptr); + rz_buf_read_le32_at (bf->buf, NSO_OFF (bss_size))); + rz_list_append (ret, ptr); return ret; } @@ -252,7 +252,7 @@ static RBinInfo *info(RBinFile *bf) { return NULL; } ut8 magic[4]; - if (r_buf_read_at (bf->buf, NSO_OFF (magic), magic, sizeof (magic)) != sizeof (magic)) { + if (rz_buf_read_at (bf->buf, NSO_OFF (magic), magic, sizeof (magic)) != sizeof (magic)) { free (ret); return NULL; } @@ -279,7 +279,7 @@ static RBinInfo *info(RBinFile *bf) { #if !R_BIN_NSO -RBinPlugin r_bin_plugin_nso = { +RBinPlugin rz_bin_plugin_nso = { .name = "nso", .desc = "Nintendo Switch NSO0 binaries", .license = "MIT", @@ -294,9 +294,9 @@ RBinPlugin r_bin_plugin_nso = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_nso, + .data = &rz_bin_plugin_nso, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_omf.c b/librz/bin/p/bin_omf.c similarity index 61% rename from libr/bin/p/bin_omf.c rename to librz/bin/p/bin_omf.c index b67a7f54e7..442c2d5f9f 100644 --- a/libr/bin/p/bin_omf.c +++ b/librz/bin/p/bin_omf.c @@ -1,97 +1,97 @@ /* radare - LGPL - Copyright 2015-2019 - ampotos, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "omf/omf.h" static bool load_buffer (RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { ut64 size; - const ut8 *buf = r_buf_data (b, &size); - r_return_val_if_fail (buf, false); - *bin_obj = r_bin_internal_omf_load (buf, size); + const ut8 *buf = rz_buf_data (b, &size); + rz_return_val_if_fail (buf, false); + *bin_obj = rz_bin_internal_omf_load (buf, size); return *bin_obj != NULL; } static void destroy(RBinFile *bf) { - r_bin_free_all_omf_obj (bf->o->bin_obj); + rz_bin_free_all_omf_obj (bf->o->bin_obj); bf->o->bin_obj = NULL; } static bool check_buffer(RBuffer *b) { int i; ut8 ch; - if (r_buf_read_at (b, 0, &ch, 1) != 1) { + if (rz_buf_read_at (b, 0, &ch, 1) != 1) { return false; } if (ch != 0x80 && ch != 0x82) { return false; } - ut16 rec_size = r_buf_read_le16_at (b, 1); - ut8 str_size; (void)r_buf_read_at (b, 3, &str_size, 1); - ut64 length = r_buf_size (b); + ut16 rec_size = rz_buf_read_le16_at (b, 1); + ut8 str_size; (void)rz_buf_read_at (b, 3, &str_size, 1); + ut64 length = rz_buf_size (b); if (str_size + 2 != rec_size || length < rec_size + 3) { return false; } // check that the string is ASCII for (i = 4; i < str_size + 4; i++) { - if (r_buf_read_at (b, i, &ch, 1) != 1) { + if (rz_buf_read_at (b, i, &ch, 1) != 1) { break; } if (ch > 0x7f) { return false; } } - const ut8 *buf = r_buf_data (b, NULL); + const ut8 *buf = rz_buf_data (b, NULL); if (buf == NULL) { // hackaround until we make this plugin not use RBuf.data ut8 buf[1024] = {0}; - r_buf_read_at (b, 0, buf, sizeof (buf)); - return r_bin_checksum_omf_ok (buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); + return rz_bin_checksum_omf_ok (buf, sizeof (buf)); } - r_return_val_if_fail (buf, false); - return r_bin_checksum_omf_ok (buf, length); + rz_return_val_if_fail (buf, false); + return rz_bin_checksum_omf_ok (buf, length); } static ut64 baddr(RBinFile *bf) { return OMF_BASE_ADDR; } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *addr; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } if (!(addr = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - if (!r_bin_omf_get_entry (bf->o->bin_obj, addr)) { + if (!rz_bin_omf_get_entry (bf->o->bin_obj, addr)) { R_FREE (addr); } else { - r_list_append (ret, addr); + rz_list_append (ret, addr); } return ret; } -static RList *sections(RBinFile *bf) { - RList *ret; +static RzList *sections(RBinFile *bf) { + RzList *ret; ut32 ct_omf_sect = 0; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - r_bin_omf_obj *obj = bf->o->bin_obj; + rz_bin_omf_obj *obj = bf->o->bin_obj; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } while (ct_omf_sect < obj->nb_section) { - if (!r_bin_omf_send_sections (ret,\ + if (!rz_bin_omf_send_sections (ret,\ obj->sections[ct_omf_sect++], bf->o->bin_obj)) { return ret; } @@ -99,32 +99,32 @@ static RList *sections(RBinFile *bf) { return ret; } -static RList *symbols(RBinFile *bf) { - RList *ret; +static RzList *symbols(RBinFile *bf) { + RzList *ret; RBinSymbol *sym; OMF_symbol *sym_omf; int ct_sym = 0; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; - while (ct_sym < ((r_bin_omf_obj *) bf->o->bin_obj)->nb_symbol) { + while (ct_sym < ((rz_bin_omf_obj *) bf->o->bin_obj)->nb_symbol) { if (!(sym = R_NEW0 (RBinSymbol))) { return ret; } - sym_omf = ((r_bin_omf_obj *) bf->o->bin_obj)->symbols[ct_sym++]; + sym_omf = ((rz_bin_omf_obj *) bf->o->bin_obj)->symbols[ct_sym++]; sym->name = strdup (sym_omf->name); sym->forwarder = "NONE"; - sym->paddr = r_bin_omf_get_paddr_sym (bf->o->bin_obj, sym_omf); - sym->vaddr = r_bin_omf_get_vaddr_sym (bf->o->bin_obj, sym_omf); + sym->paddr = rz_bin_omf_get_paddr_sym (bf->o->bin_obj, sym_omf); + sym->vaddr = rz_bin_omf_get_vaddr_sym (bf->o->bin_obj, sym_omf); sym->ordinal = ct_sym; sym->size = 0; - r_list_append (ret, sym); + rz_list_append (ret, sym); } return ret; } @@ -146,7 +146,7 @@ static RBinInfo *info(RBinFile *bf) { ret->big_endian = false; ret->has_va = true; ret->has_lit = true; - ret->bits = r_bin_omf_get_bits (bf->o->bin_obj); + ret->bits = rz_bin_omf_get_bits (bf->o->bin_obj); ret->dbg_info = 0; ret->has_nx = false; return ret; @@ -156,7 +156,7 @@ static ut64 get_vaddr(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr) { return vaddr; } -RBinPlugin r_bin_plugin_omf = { +RBinPlugin rz_bin_plugin_omf = { .name = "omf", .desc = "omf bin plugin", .license = "LGPL3", @@ -172,9 +172,9 @@ RBinPlugin r_bin_plugin_omf = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_omf, + .data = &rz_bin_plugin_omf, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_p9.c b/librz/bin/p/bin_p9.c similarity index 72% rename from libr/bin/p/bin_p9.c rename to librz/bin/p/bin_p9.c index 39de6a12a5..2bd6db0f55 100644 --- a/libr/bin/p/bin_p9.c +++ b/librz/bin/p/bin_p9.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2009-2019 - nibble, pancake */ +/* rizin - LGPL - Copyright 2009-2019 - nibble, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../format/p9/p9bin.h" static bool check_buffer(RBuffer *buf) { - return r_bin_p9_get_arch (buf, NULL, NULL); + return rz_bin_p9_get_arch (buf, NULL, NULL); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb){ @@ -15,7 +15,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, } static void destroy(RBinFile *bf) { - r_buf_free (bf->o->bin_obj); + rz_buf_free (bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { @@ -26,41 +26,41 @@ static RBinAddr *binsym(RBinFile *bf, int type) { return NULL; // TODO } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if ((ptr = R_NEW0 (RBinAddr))) { ptr->paddr = 8 * 4; ptr->vaddr = 8 * 4;// + baddr (bf); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; ut64 textsize, datasize, symssize, spszsize, pcszsize; if (!bf->o->info) { return NULL; } - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } - if (r_buf_size (bf->buf) < 28) { - r_list_free (ret); + if (rz_buf_size (bf->buf) < 28) { + rz_list_free (ret); return NULL; } // add text segment - textsize = r_buf_read_le32_at (bf->buf, 4); + textsize = rz_buf_read_le32_at (bf->buf, 4); if (!(ptr = R_NEW0 (RBinSection))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } ptr->name = strdup ("text"); @@ -70,9 +70,9 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; ptr->perm = R_PERM_RX; // r-x ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // add data segment - datasize = r_buf_read_le32_at (bf->buf, 8); + datasize = rz_buf_read_le32_at (bf->buf, 8); if (datasize > 0) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -84,11 +84,11 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; ptr->perm = R_PERM_RW; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } // ignore bss or what // add syms segment - symssize = r_buf_read_le32_at (bf->buf, 16); + symssize = rz_buf_read_le32_at (bf->buf, 16); if (symssize) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -100,10 +100,10 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } // add spsz segment - spszsize = r_buf_read_le32_at (bf->buf, 24); + spszsize = rz_buf_read_le32_at (bf->buf, 24); if (spszsize) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -115,10 +115,10 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } // add pcsz segment - pcszsize = r_buf_read_le32_at (bf->buf, 24); + pcszsize = rz_buf_read_le32_at (bf->buf, 24); if (pcszsize) { if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -130,21 +130,21 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; ptr->perm = R_PERM_R; // r-- ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *symbols(RBinFile *bf) { +static RzList *symbols(RBinFile *bf) { // TODO: parse symbol table return NULL; } -static RList *imports(RBinFile *bf) { +static RzList *imports(RBinFile *bf) { return NULL; } -static RList *libs(RBinFile *bf) { +static RzList *libs(RBinFile *bf) { return NULL; } @@ -152,7 +152,7 @@ static RBinInfo *info(RBinFile *bf) { RBinInfo *ret = NULL; int bits = 32, bina, big_endian = 0; - if (!(bina = r_bin_p9_get_arch (bf->buf, &bits, &big_endian))) { + if (!(bina = rz_bin_p9_get_arch (bf->buf, &bits, &big_endian))) { return NULL; } if (!(ret = R_NEW0 (RBinInfo))) { @@ -162,7 +162,7 @@ static RBinInfo *info(RBinFile *bf) { ret->bclass = strdup ("program"); ret->rclass = strdup ("p9"); ret->os = strdup ("Plan9"); - ret->arch = strdup (r_sys_arch_str (bina)); + ret->arch = strdup (rz_sys_arch_str (bina)); ret->machine = strdup (ret->arch); ret->subsystem = strdup ("plan9"); ret->type = strdup ("EXEC (executable file)"); @@ -185,13 +185,13 @@ static ut64 size(RBinFile *bf) { return 0; } // TODO: reuse section list - if (r_buf_size (bf->buf) < 28) { + if (rz_buf_size (bf->buf) < 28) { return 0; } - text = r_buf_read_le32_at (bf->buf, 4); - data = r_buf_read_le32_at (bf->buf, 8); - syms = r_buf_read_le32_at (bf->buf, 16); - spsz = r_buf_read_le32_at (bf->buf, 24); + text = rz_buf_read_le32_at (bf->buf, 4); + data = rz_buf_read_le32_at (bf->buf, 8); + syms = rz_buf_read_le32_at (bf->buf, 16); + spsz = rz_buf_read_le32_at (bf->buf, 24); return text + data + syms + spsz + (6 * 4); } @@ -199,9 +199,9 @@ static ut64 size(RBinFile *bf) { /* inspired in http://www.phreedom.org/solar/code/tinype/tiny.97/tiny.asm */ static RBuffer *create(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { - RBuffer *buf = r_buf_new (); -#define B(x, y) r_buf_append_bytes (buf, (const ut8 *) (x), y) -#define D(x) r_buf_append_ut32 (buf, x) + RBuffer *buf = rz_buf_new (); +#define B(x, y) rz_buf_append_bytes (buf, (const ut8 *) (x), y) +#define D(x) rz_buf_append_ut32 (buf, x) D (I_MAGIC); // i386 only atm D (codelen); D (datalen); @@ -217,7 +217,7 @@ static RBuffer *create(RBin *bin, const ut8 *code, int codelen, const ut8 *data, return buf; } -RBinPlugin r_bin_plugin_p9 = { +RBinPlugin rz_bin_plugin_p9 = { .name = "p9", .desc = "Plan9 bin plugin", .license = "LGPL3", @@ -237,9 +237,9 @@ RBinPlugin r_bin_plugin_p9 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_p9, + .data = &rz_bin_plugin_p9, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_pe.c b/librz/bin/p/bin_pe.c similarity index 92% rename from libr/bin/p/bin_pe.c rename to librz/bin/p/bin_pe.c index ada3f48cdb..2db5539284 100644 --- a/libr/bin/p/bin_pe.c +++ b/librz/bin/p/bin_pe.c @@ -3,25 +3,25 @@ #include "bin_pe.inc" static bool check_buffer(RBuffer *b) { - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (length <= 0x3d) { return false; } - ut16 idx = r_buf_read_le16_at (b, 0x3c); + ut16 idx = rz_buf_read_le16_at (b, 0x3c); if (idx + 26 < length) { /* Here PE signature for usual PE files * and PL signature for Phar Lap TNT DOS extender 32bit executables */ ut8 buf[2]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "MZ", 2)) { - r_buf_read_at (b, idx, buf, sizeof (buf)); + rz_buf_read_at (b, idx, buf, sizeof (buf)); // TODO: Add one more indicator, to prevent false positives if (!memcmp (buf, "PL", 2)) { return true; } if (!memcmp (buf, "PE", 2)) { - r_buf_read_at (b, idx + 0x18, buf, sizeof (buf)); + rz_buf_read_at (b, idx + 0x18, buf, sizeof (buf)); return !memcmp (buf, "\x0b\x01", 2); } } @@ -33,14 +33,14 @@ static bool check_buffer(RBuffer *b) { static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { ut32 hdrsize, p_start, p_opthdr, p_sections, p_lsrlc, n; ut32 baddr = 0x400000; - RBuffer *buf = r_buf_new (); + RBuffer *buf = rz_buf_new (); -#define B(x,y) r_buf_append_bytes(buf,(const ut8*)(x),y) -#define H(x) r_buf_append_ut16(buf,x) -#define D(x) r_buf_append_ut32(buf,x) -#define Z(x) r_buf_append_nbytes(buf,x) -#define W(x,y,z) r_buf_write_at(buf,x,(const ut8*)(y),z) -#define WZ(x,y) p_tmp=r_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) +#define B(x,y) rz_buf_append_bytes(buf,(const ut8*)(x),y) +#define H(x) rz_buf_append_ut16(buf,x) +#define D(x) rz_buf_append_ut32(buf,x) +#define Z(x) rz_buf_append_nbytes(buf,x) +#define W(x,y,z) rz_buf_write_at(buf,x,(const ut8*)(y),z) +#define WZ(x,y) p_tmp=rz_buf_size (buf);Z(x);W(p_tmp,y,strlen(y)) B ("MZ\x00\x00", 4); // MZ Header B ("PE\x00\x00", 4); // PE Signature @@ -49,16 +49,16 @@ static RBuffer* create(RBin* bin, const ut8 *code, int codelen, const ut8 *data, D (0); // Timestamp (Unused) D (0); // PointerToSymbolTable (Unused) D (0); // NumberOfSymbols (Unused) - p_lsrlc = r_buf_size (buf); + p_lsrlc = rz_buf_size (buf); H (-1); // SizeOfOptionalHeader H (0x103); // Characteristics /* Optional Header */ - p_opthdr = r_buf_size (buf); + p_opthdr = rz_buf_size (buf); H (0x10b); // Magic B ("\x08\x00", 2); // (Major/Minor)LinkerVersion (Unused) - p_sections = r_buf_size (buf); + p_sections = rz_buf_size (buf); n = p_sections - p_opthdr; W (p_lsrlc, &n, 2); // Fix SizeOfOptionalHeader @@ -107,33 +107,33 @@ static char *signature (RBinFile *bf, bool json) { if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - struct PE_ (r_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct PE_ (rz_bin_pe_obj_t) * bin = bf->o->bin_obj; if (json) { - PJ *pj = r_pkcs7_cms_json (bin->cms); + PJ *pj = rz_pkcs7_cms_json (bin->cms); if (pj) { return pj_drain (pj); } return strdup ("{}"); } - return r_pkcs7_cms_to_string (bin->cms); + return rz_pkcs7_cms_to_string (bin->cms); } -static RList *fields(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList *fields(RBinFile *bf) { + RzList *ret = rz_list_new (); if (!ret) { return NULL; } #define ROWL(nam,siz,val,fmt) \ - r_list_append (ret, r_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); + rz_list_append (ret, rz_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); - struct PE_(r_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct PE_(rz_bin_pe_obj_t) * bin = bf->o->bin_obj; ut64 addr = bin->rich_header_offset ? bin->rich_header_offset : 128; - RListIter *it; + RzListIter *it; Pe_image_rich_entry *rich; - r_list_foreach (bin->rich_entries, it, rich) { - r_list_append (ret, r_bin_field_new (addr, addr, 0, "RICH_ENTRY_NAME", strdup (rich->productName), "s", false)); + rz_list_foreach (bin->rich_entries, it, rich) { + rz_list_append (ret, rz_bin_field_new (addr, addr, 0, "RICH_ENTRY_NAME", strdup (rich->productName), "s", false)); ROWL ("RICH_ENTRY_ID", 2, rich->productId, "x"); addr += 2; ROWL ("RICH_ENTRY_VERSION", 2, rich->minVersion, "x"); addr += 2; ROWL ("RICH_ENTRY_TIMES", 4, rich->timesUsed, "x"); addr += 4; @@ -297,8 +297,8 @@ static RList *fields(RBinFile *bf) { } static void header(RBinFile *bf) { - struct PE_(r_bin_pe_obj_t) * bin = bf->o->bin_obj; - struct r_bin_t *rbin = bf->rbin; + struct PE_(rz_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct rz_bin_t *rbin = bf->rbin; rbin->cb_printf ("PE file header:\n"); rbin->cb_printf ("IMAGE_NT_HEADERS\n"); rbin->cb_printf (" Signature : 0x%x\n", bin->nt_headers->Signature); @@ -341,10 +341,10 @@ static void header(RBinFile *bf) { rbin->cb_printf (" SizeOfHeapCommit : 0x%x\n", bin->nt_headers->optional_header.SizeOfHeapCommit); rbin->cb_printf (" LoaderFlags : 0x%x\n", bin->nt_headers->optional_header.LoaderFlags); rbin->cb_printf (" NumberOfRvaAndSizes : 0x%x\n", bin->nt_headers->optional_header.NumberOfRvaAndSizes); - RListIter *it; + RzListIter *it; Pe_image_rich_entry *entry; rbin->cb_printf ("RICH_FIELDS\n"); - r_list_foreach (bin->rich_entries, it, entry) { + rz_list_foreach (bin->rich_entries, it, entry) { rbin->cb_printf (" Product: %d Name: %s Version: %d Times: %d\n", entry->productId, entry->productName, entry->minVersion, entry->timesUsed); } int i; @@ -404,9 +404,9 @@ static void header(RBinFile *bf) { } } -extern struct r_bin_write_t r_bin_write_pe; +extern struct rz_bin_write_t rz_bin_write_pe; -RBinPlugin r_bin_plugin_pe = { +RBinPlugin rz_bin_plugin_pe = { .name = "pe", .desc = "PE bin plugin", .license = "LGPL3", @@ -429,14 +429,14 @@ RBinPlugin r_bin_plugin_pe = { .minstrlen = 4, .create = &create, .get_vaddr = &get_vaddr, - .write = &r_bin_write_pe, + .write = &rz_bin_write_pe, .hashes = &compute_hashes }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_pe, + .data = &rz_bin_plugin_pe, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_pe.inc b/librz/bin/p/bin_pe.inc similarity index 70% rename from libr/bin/p/bin_pe.inc rename to librz/bin/p/bin_pe.inc index e198e63b40..9643501d11 100644 --- a/libr/bin/p/bin_pe.inc +++ b/librz/bin/p/bin_pe.inc @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2009-2019 - nibble, pancake, alvarofe */ -#include -#include -#include -#include +#include +#include +#include +#include #include "../i/private.h" #include "pe/pe.h" static Sdb* get_sdb (RBinFile *bf) { RBinObject *o = bf->o; - struct PE_(r_bin_pe_obj_t) *bin; + struct PE_(rz_bin_pe_obj_t) *bin; if (!o || !o->bin_obj) { return NULL; } - bin = (struct PE_(r_bin_pe_obj_t) *) o->bin_obj; + bin = (struct PE_(rz_bin_pe_obj_t) *) o->bin_obj; return bin? bin->kv: NULL; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && bin_obj && buf, false); - struct PE_(r_bin_pe_obj_t) *res = PE_(r_bin_pe_new_buf) (buf, bf->rbin->verbose); + rz_return_val_if_fail (bf && bin_obj && buf, false); + struct PE_(rz_bin_pe_obj_t) *res = PE_(rz_bin_pe_new_buf) (buf, bf->rbin->verbose); if (res) { sdb_ns_set (sdb, "info", res->kv); *bin_obj = res; @@ -29,20 +29,20 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static void destroy(RBinFile *bf) { - PE_(r_bin_pe_free) ((struct PE_(r_bin_pe_obj_t)*)bf->o->bin_obj); + PE_(rz_bin_pe_free) ((struct PE_(rz_bin_pe_obj_t)*)bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { - return PE_(r_bin_pe_get_image_base) (bf->o->bin_obj); + return PE_(rz_bin_pe_get_image_base) (bf->o->bin_obj); } static RBinAddr* binsym(RBinFile *bf, int type) { - struct r_bin_pe_addr_t *peaddr = NULL; + struct rz_bin_pe_addr_t *peaddr = NULL; RBinAddr *ret = NULL; if (bf && bf->o && bf->o->bin_obj) { switch (type) { case R_BIN_SYM_MAIN: - peaddr = PE_(r_bin_pe_get_main_vaddr) (bf->o->bin_obj); + peaddr = PE_(rz_bin_pe_get_main_vaddr) (bf->o->bin_obj); break; } } @@ -54,11 +54,11 @@ static RBinAddr* binsym(RBinFile *bf, int type) { return ret; } -static void add_tls_callbacks(RBinFile *bf, RList* list) { +static void add_tls_callbacks(RBinFile *bf, RzList* list) { PE_DWord paddr, vaddr, haddr; int count = 0; RBinAddr *ptr = NULL; - struct PE_(r_bin_pe_obj_t) *bin = (struct PE_(r_bin_pe_obj_t) *) (bf->o->bin_obj); + struct PE_(rz_bin_pe_obj_t) *bin = (struct PE_(rz_bin_pe_obj_t) *) (bf->o->bin_obj); char *key; do { @@ -84,21 +84,21 @@ static void add_tls_callbacks(RBinFile *bf, RList* list) { ptr->vaddr = vaddr; ptr->hpaddr = haddr; ptr->type = R_BIN_ENTRY_TYPE_TLS; - r_list_append (list, ptr); + rz_list_append (list, ptr); } count++; } while (vaddr); } -static RList* entries(RBinFile *bf) { - struct r_bin_pe_addr_t *entry = NULL; +static RzList* entries(RBinFile *bf) { + struct rz_bin_pe_addr_t *entry = NULL; RBinAddr *ptr = NULL; - RList* ret; + RzList* ret; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - if (!(entry = PE_(r_bin_pe_get_entrypoint) (bf->o->bin_obj))) { + if (!(entry = PE_(rz_bin_pe_get_entrypoint) (bf->o->bin_obj))) { return ret; } if ((ptr = R_NEW0 (RBinAddr))) { @@ -106,7 +106,7 @@ static RList* entries(RBinFile *bf) { ptr->vaddr = entry->vaddr; ptr->hpaddr = entry->haddr; ptr->type = R_BIN_ENTRY_TYPE_PROGRAM; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (entry); // get TLS callback addresses @@ -115,21 +115,21 @@ static RList* entries(RBinFile *bf) { return ret; } -static RList* sections(RBinFile *bf) { - RList *ret = NULL; +static RzList* sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; - struct r_bin_pe_section_t *sections = NULL; - struct PE_(r_bin_pe_obj_t) *bin = (struct PE_(r_bin_pe_obj_t)*)bf->o->bin_obj; + struct rz_bin_pe_section_t *sections = NULL; + struct PE_(rz_bin_pe_obj_t) *bin = (struct PE_(rz_bin_pe_obj_t)*)bf->o->bin_obj; ut64 ba = baddr (bf); int i; - if (!(ret = r_list_newf ((RListFree)r_bin_section_free))) { + if (!(ret = rz_list_newf ((RzListFree)rz_bin_section_free))) { return NULL; } if (!bin || !(sections = bin->sections)){ - r_list_free (ret); + rz_list_free (ret); return NULL; } - PE_(r_bin_pe_check_sections) (bin, §ions); + PE_(rz_bin_pe_check_sections) (bin, §ions); for (i = 0; !sections[i].last; i++) { if (!(ptr = R_NEW0 (RBinSection))) { break; @@ -177,7 +177,7 @@ static RList* sections(RBinFile *bf) { ptr->is_data = true; } } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } @@ -191,24 +191,24 @@ static void find_pe_overlay(RBinFile *bf) { } } -static RList* symbols(RBinFile *bf) { - RList *ret = NULL; +static RzList* symbols(RBinFile *bf) { + RzList *ret = NULL; RBinSymbol *ptr = NULL; - struct r_bin_pe_export_t *symbols = NULL; - struct r_bin_pe_import_t *imports = NULL; + struct rz_bin_pe_export_t *symbols = NULL; + struct rz_bin_pe_import_t *imports = NULL; int i; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } - if ((symbols = PE_(r_bin_pe_get_exports)(bf->o->bin_obj))) { + if ((symbols = PE_(rz_bin_pe_get_exports)(bf->o->bin_obj))) { for (i = 0; !symbols[i].last; i++) { if (!(ptr = R_NEW0 (RBinSymbol))) { break; } ptr->name = strdup ((char *)symbols[i].name); ptr->libname = *symbols[i].libname ? strdup ((char *)symbols[i].libname) : NULL; - ptr->forwarder = r_str_constpool_get (&bf->rbin->constpool, (char *)symbols[i].forwarder); + ptr->forwarder = rz_str_constpool_get (&bf->rbin->constpool, (char *)symbols[i].forwarder); //strncpy (ptr->bind, "NONE", R_BIN_SIZEOF_STRINGS); ptr->bind = R_BIN_BIND_GLOBAL_STR; ptr->type = R_BIN_TYPE_FUNC_STR; @@ -216,13 +216,13 @@ static RList* symbols(RBinFile *bf) { ptr->vaddr = symbols[i].vaddr; ptr->paddr = symbols[i].paddr; ptr->ordinal = symbols[i].ordinal; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (symbols); } - if ((imports = PE_(r_bin_pe_get_imports)(bf->o->bin_obj))) { + if ((imports = PE_(rz_bin_pe_get_imports)(bf->o->bin_obj))) { for (i = 0; !imports[i].last; i++) { if (!(ptr = R_NEW0 (RBinSymbol))) { break; @@ -238,7 +238,7 @@ static RList* symbols(RBinFile *bf) { ptr->vaddr = imports[i].vaddr; ptr->paddr = imports[i].paddr; ptr->ordinal = imports[i].ordinal; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (imports); } @@ -256,32 +256,32 @@ static void filter_import(ut8 *n) { } } -static RList* imports(RBinFile *bf) { - RList *ret = NULL, *relocs = NULL; +static RzList* imports(RBinFile *bf) { + RzList *ret = NULL, *relocs = NULL; RBinImport *ptr = NULL; RBinReloc *rel = NULL; - struct r_bin_pe_import_t *imports = NULL; + struct rz_bin_pe_import_t *imports = NULL; int i; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } - if (!(ret = r_list_newf (r_bin_import_free))) { + if (!(ret = rz_list_newf (rz_bin_import_free))) { return NULL; } // XXX: has_canary is causing problems! thus we need to check and clean here until it is fixed! - if (((struct PE_(r_bin_pe_obj_t)*)bf->o->bin_obj)->relocs) { - r_list_free (((struct PE_(r_bin_pe_obj_t)*)bf->o->bin_obj)->relocs); + if (((struct PE_(rz_bin_pe_obj_t)*)bf->o->bin_obj)->relocs) { + rz_list_free (((struct PE_(rz_bin_pe_obj_t)*)bf->o->bin_obj)->relocs); } - if (!(relocs = r_list_newf (free))) { + if (!(relocs = rz_list_newf (free))) { free (ret); return NULL; } - ((struct PE_(r_bin_pe_obj_t)*)bf->o->bin_obj)->relocs = relocs; + ((struct PE_(rz_bin_pe_obj_t)*)bf->o->bin_obj)->relocs = relocs; - if (!(imports = PE_(r_bin_pe_get_imports)(bf->o->bin_obj))) { + if (!(imports = PE_(rz_bin_pe_get_imports)(bf->o->bin_obj))) { return ret; } for (i = 0; !imports[i].last; i++) { @@ -297,7 +297,7 @@ static RList* imports(RBinFile *bf) { // NOTE(eddyb) a PE hint is just an optional possible DLL export table // index for the import. There is no point in exposing it. //ptr->hint = imports[i].hint; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(rel = R_NEW0 (RBinReloc))) { break; @@ -312,50 +312,50 @@ static RList* imports(RBinFile *bf) { rel->addend = 0; { ut8 addr[4]; - r_buf_read_at (bf->buf, imports[i].paddr, addr, 4); - ut64 newaddr = (ut64) r_read_le32 (&addr); + rz_buf_read_at (bf->buf, imports[i].paddr, addr, 4); + ut64 newaddr = (ut64) rz_read_le32 (&addr); rel->vaddr = newaddr; } rel->paddr = imports[i].paddr; - r_list_append (relocs, rel); + rz_list_append (relocs, rel); } free (imports); return ret; } -static RList* relocs(RBinFile *bf) { - struct PE_(r_bin_pe_obj_t)* obj= bf->o->bin_obj; +static RzList* relocs(RBinFile *bf) { + struct PE_(rz_bin_pe_obj_t)* obj= bf->o->bin_obj; if (obj) { return obj->relocs; } return NULL; } -static RList* libs(RBinFile *bf) { - struct r_bin_pe_lib_t *libs = NULL; - RList *ret = NULL; +static RzList* libs(RBinFile *bf) { + struct rz_bin_pe_lib_t *libs = NULL; + RzList *ret = NULL; char *ptr = NULL; int i; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; - if (!(libs = PE_(r_bin_pe_get_libs)(bf->o->bin_obj))) { + if (!(libs = PE_(rz_bin_pe_get_libs)(bf->o->bin_obj))) { return ret; } for (i = 0; !libs[i].last; i++) { ptr = strdup (libs[i].name); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (libs); return ret; } static int is_dot_net(RBinFile *bf) { - struct r_bin_pe_lib_t *libs = NULL; + struct rz_bin_pe_lib_t *libs = NULL; int i; - if (!(libs = PE_(r_bin_pe_get_libs)(bf->o->bin_obj))) { + if (!(libs = PE_(rz_bin_pe_get_libs)(bf->o->bin_obj))) { return false; } for (i = 0; !libs[i].last; i++) { @@ -369,9 +369,9 @@ static int is_dot_net(RBinFile *bf) { } static int is_vb6(RBinFile *bf) { - struct r_bin_pe_lib_t *libs = NULL; + struct rz_bin_pe_lib_t *libs = NULL; int i; - if (!(libs = PE_(r_bin_pe_get_libs)(bf->o->bin_obj))) { + if (!(libs = PE_(rz_bin_pe_get_libs)(bf->o->bin_obj))) { return false; } for (i = 0; !libs[i].last; i++) { @@ -387,23 +387,23 @@ static int is_vb6(RBinFile *bf) { static int has_canary(RBinFile *bf) { // XXX: We only need imports here but this causes leaks, we need to wait for the below. This is a horrible solution! // TODO: use O(1) when imports sdbized - RListIter *iter; - struct PE_ (r_bin_pe_obj_t) *bin = bf->o->bin_obj; + RzListIter *iter; + struct PE_ (rz_bin_pe_obj_t) *bin = bf->o->bin_obj; if (bin) { - const RList* relocs_list = bin->relocs; + const RzList* relocs_list = bin->relocs; RBinReloc *rel; if (relocs_list) { - r_list_foreach (relocs_list, iter, rel) { + rz_list_foreach (relocs_list, iter, rel) { if (!strcmp (rel->import->name, "__security_init_cookie")) { return true; } } } - } else { // rabin2 needs this as it will not initialise bin - const RList* imports_list = imports (bf); + } else { // rz_bin needs this as it will not initialise bin + const RzList* imports_list = imports (bf); RBinImport *imp; if (imports_list) { - r_list_foreach (imports_list, iter, imp) { + rz_list_foreach (imports_list, iter, imp) { if (!strcmp (imp->name, "__security_init_cookie")) { return true; } @@ -420,7 +420,7 @@ static int haschr(const RBinFile* bf, ut16 dllCharacteristic) { if (!bf) { return false; } - buf = r_buf_data (bf->buf, &sz); + buf = rz_buf_data (bf->buf, &sz); if (!buf) { return false; } @@ -434,7 +434,7 @@ static int haschr(const RBinFile* bf, ut16 dllCharacteristic) { } static RBinInfo* info(RBinFile *bf) { - struct PE_ (r_bin_pe_obj_t) *bin; + struct PE_ (rz_bin_pe_obj_t) *bin; SDebugInfo di = {{0}}; RBinInfo *ret = R_NEW0 (RBinInfo); ut32 claimed_checksum, actual_checksum, pe_overlay; @@ -444,20 +444,20 @@ static RBinInfo* info(RBinFile *bf) { } bin = bf->o->bin_obj; ret->file = strdup (bf->file); - ret->bclass = PE_(r_bin_pe_get_class) (bf->o->bin_obj); + ret->bclass = PE_(rz_bin_pe_get_class) (bf->o->bin_obj); ret->rclass = strdup ("pe"); - ret->os = PE_(r_bin_pe_get_os) (bf->o->bin_obj); - ret->arch = PE_(r_bin_pe_get_arch) (bf->o->bin_obj); - ret->machine = PE_(r_bin_pe_get_machine) (bf->o->bin_obj); - ret->subsystem = PE_(r_bin_pe_get_subsystem) (bf->o->bin_obj); - ret->default_cc = PE_(r_bin_pe_get_cc) (bf->o->bin_obj); + ret->os = PE_(rz_bin_pe_get_os) (bf->o->bin_obj); + ret->arch = PE_(rz_bin_pe_get_arch) (bf->o->bin_obj); + ret->machine = PE_(rz_bin_pe_get_machine) (bf->o->bin_obj); + ret->subsystem = PE_(rz_bin_pe_get_subsystem) (bf->o->bin_obj); + ret->default_cc = PE_(rz_bin_pe_get_cc) (bf->o->bin_obj); if (is_dot_net (bf)) { ret->lang = "cil"; } if (is_vb6 (bf)) { ret->lang = "vb"; } - if (PE_(r_bin_pe_is_dll) (bf->o->bin_obj)) { + if (PE_(rz_bin_pe_is_dll) (bf->o->bin_obj)) { ret->type = strdup ("DLL (Dynamic Link Library)"); } else { ret->type = strdup ("EXEC (Executable file)"); @@ -465,8 +465,8 @@ static RBinInfo* info(RBinFile *bf) { claimed_checksum = PE_(bin_pe_get_claimed_checksum) (bf->o->bin_obj); actual_checksum = PE_(bin_pe_get_actual_checksum) (bf->o->bin_obj); pe_overlay = sdb_num_get (bf->sdb, "pe_overlay.size", 0); - ret->bits = PE_(r_bin_pe_get_bits) (bf->o->bin_obj); - ret->big_endian = PE_(r_bin_pe_is_big_endian) (bf->o->bin_obj); + ret->bits = PE_(rz_bin_pe_get_bits) (bf->o->bin_obj); + ret->big_endian = PE_(rz_bin_pe_is_big_endian) (bf->o->bin_obj); ret->dbg_info = 0; ret->has_lit = true; ret->has_canary = has_canary (bf); @@ -476,7 +476,7 @@ static RBinInfo* info(RBinFile *bf) { ret->actual_checksum = strdup (sdb_fmt ("0x%08x", actual_checksum)); ret->pe_overlay = pe_overlay > 0; ret->signature = bin ? bin->is_signed : false; - ret->file_hashes = r_list_newf ((RListFree) r_bin_file_hash_free); + ret->file_hashes = rz_list_newf ((RzListFree) rz_bin_file_hash_free); Sdb *db = sdb_ns (bf->sdb, "pe", true); sdb_bool_set (db, "canary", has_canary (bf), 0); sdb_bool_set (db, "highva", haschr (bf, IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA), 0); @@ -497,22 +497,22 @@ static RBinInfo* info(RBinFile *bf) { ret->has_va = true; - if (PE_(r_bin_pe_is_stripped_debug) (bf->o->bin_obj)) { + if (PE_(rz_bin_pe_is_stripped_debug) (bf->o->bin_obj)) { ret->dbg_info |= R_BIN_DBG_STRIPPED; } - if (PE_(r_bin_pe_is_stripped_line_nums) (bf->o->bin_obj)) { + if (PE_(rz_bin_pe_is_stripped_line_nums) (bf->o->bin_obj)) { ret->dbg_info |= R_BIN_DBG_LINENUMS; } - if (PE_(r_bin_pe_is_stripped_local_syms) (bf->o->bin_obj)) { + if (PE_(rz_bin_pe_is_stripped_local_syms) (bf->o->bin_obj)) { ret->dbg_info |= R_BIN_DBG_SYMS; } - if (PE_(r_bin_pe_is_stripped_relocs) (bf->o->bin_obj)) { + if (PE_(rz_bin_pe_is_stripped_relocs) (bf->o->bin_obj)) { ret->dbg_info |= R_BIN_DBG_RELOCS; } - if (PE_(r_bin_pe_get_debug_data)(bf->o->bin_obj, &di)) { - ret->guid = r_str_ndup (di.guidstr, GUIDSTR_LEN); + if (PE_(rz_bin_pe_get_debug_data)(bf->o->bin_obj, &di)) { + ret->guid = rz_str_ndup (di.guidstr, GUIDSTR_LEN); if (ret->guid) { - ret->debug_file_name = r_str_ndup (di.file_name, DBG_FILE_NAME_LEN); + ret->debug_file_name = rz_str_ndup (di.file_name, DBG_FILE_NAME_LEN); if (!ret->debug_file_name) { R_FREE (ret->guid); } @@ -526,15 +526,15 @@ static ut64 get_vaddr (RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr) { return baddr + vaddr; } -static RList *compute_hashes(RBinFile *bf) { - RList *file_hashes = r_list_newf ((RListFree) r_bin_file_hash_free); +static RzList *compute_hashes(RBinFile *bf) { + RzList *file_hashes = rz_list_newf ((RzListFree) rz_bin_file_hash_free); const char *authentihash = PE_(bin_pe_compute_authentihash) (bf->o->bin_obj); if (authentihash) { RBinFileHash *authhash = R_NEW0 (RBinFileHash); if (authhash) { authhash->type = strdup ("authentihash"); authhash->hex = authentihash; - r_list_push (file_hashes, authhash); + rz_list_push (file_hashes, authhash); } } diff --git a/libr/bin/p/bin_pe64.c b/librz/bin/p/bin_pe64.c similarity index 89% rename from libr/bin/p/bin_pe64.c rename to librz/bin/p/bin_pe64.c index a64f075bd8..331ed0f091 100644 --- a/libr/bin/p/bin_pe64.c +++ b/librz/bin/p/bin_pe64.c @@ -3,23 +3,23 @@ #include "bin_pe.inc" static bool check_buffer(RBuffer *b) { - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); if (length <= 0x3d) { return false; } - ut16 idx = r_buf_read_le16_at (b, 0x3c); + ut16 idx = rz_buf_read_le16_at (b, 0x3c); if (idx + 26 < length) { /* Here PE signature for usual PE files * and PL signature for Phar Lap TNT DOS extender 32bit executables */ ut8 buf[2]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "MZ", 2)) { - r_buf_read_at (b, idx, buf, sizeof (buf)); + rz_buf_read_at (b, idx, buf, sizeof (buf)); // TODO: Add one more indicator, to prevent false positives // if (!memcmp (buf, "PL", 2)) { return true; } if (!memcmp (buf, "PE", 2)) { - r_buf_read_at (b, idx + 0x18, buf, sizeof (buf)); + rz_buf_read_at (b, idx + 0x18, buf, sizeof (buf)); return !memcmp (buf, "\x0b\x02", 2); } } @@ -27,22 +27,22 @@ static bool check_buffer(RBuffer *b) { return false; } -static RList *fields(RBinFile *bf) { - RList *ret = r_list_new (); +static RzList *fields(RBinFile *bf) { + RzList *ret = rz_list_new (); if (!ret) { return NULL; } #define ROWL(nam,siz,val,fmt) \ - r_list_append (ret, r_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); + rz_list_append (ret, rz_bin_field_new (addr, addr, siz, nam, sdb_fmt ("0x%08x", val), fmt, false)); - struct PE_(r_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct PE_(rz_bin_pe_obj_t) * bin = bf->o->bin_obj; ut64 addr = bin->rich_header_offset ? bin->rich_header_offset : 128; - RListIter *it; + RzListIter *it; Pe_image_rich_entry *rich; - r_list_foreach (bin->rich_entries, it, rich) { - r_list_append (ret, r_bin_field_new (addr, addr, 0, "RICH_ENTRY_NAME", strdup (rich->productName), "s", false)); + rz_list_foreach (bin->rich_entries, it, rich) { + rz_list_append (ret, rz_bin_field_new (addr, addr, 0, "RICH_ENTRY_NAME", strdup (rich->productName), "s", false)); ROWL ("RICH_ENTRY_ID", 2, rich->productId, "x"); addr += 2; ROWL ("RICH_ENTRY_VERSION", 2, rich->minVersion, "x"); addr += 2; ROWL ("RICH_ENTRY_TIMES", 4, rich->timesUsed, "x"); addr += 4; @@ -205,8 +205,8 @@ static RList *fields(RBinFile *bf) { } static void header(RBinFile *bf) { - struct PE_(r_bin_pe_obj_t) * bin = bf->o->bin_obj; - struct r_bin_t *rbin = bf->rbin; + struct PE_(rz_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct rz_bin_t *rbin = bf->rbin; rbin->cb_printf ("PE file header:\n"); rbin->cb_printf ("IMAGE_NT_HEADERS\n"); rbin->cb_printf (" Signature : 0x%x\n", bin->nt_headers->Signature); @@ -248,10 +248,10 @@ static void header(RBinFile *bf) { rbin->cb_printf (" SizeOfHeapCommit : 0x%x\n", bin->nt_headers->optional_header.SizeOfHeapCommit); rbin->cb_printf (" LoaderFlags : 0x%x\n", bin->nt_headers->optional_header.LoaderFlags); rbin->cb_printf (" NumberOfRvaAndSizes : 0x%x\n", bin->nt_headers->optional_header.NumberOfRvaAndSizes); - RListIter *it; + RzListIter *it; Pe_image_rich_entry *entry; rbin->cb_printf ("RICH_FIELDS\n"); - r_list_foreach (bin->rich_entries, it, entry) { + rz_list_foreach (bin->rich_entries, it, entry) { rbin->cb_printf (" Product: %d Name: %s Version: %d Times: %d\n", entry->productId, entry->productName, entry->minVersion, entry->timesUsed); } int i; @@ -311,36 +311,36 @@ static void header(RBinFile *bf) { } } -extern struct r_bin_write_t r_bin_write_pe64; +extern struct rz_bin_write_t rz_bin_write_pe64; -static RList *trycatch(RBinFile *bf) { - RIO *io = bf->rbin->iob.io; +static RzList *trycatch(RBinFile *bf) { + RzIO *io = bf->rbin->iob.io; ut64 baseAddr = bf->o->baddr; int i; ut64 offset; ut32 c_handler = 0; - struct PE_(r_bin_pe_obj_t) * bin = bf->o->bin_obj; + struct PE_(rz_bin_pe_obj_t) * bin = bf->o->bin_obj; PE_(image_data_directory) *expdir = &bin->optional_header->DataDirectory[PE_IMAGE_DIRECTORY_ENTRY_EXCEPTION]; if (!expdir->Size) { return NULL; } - RList *tclist = r_list_newf ((RListFree)r_bin_trycatch_free); + RzList *tclist = rz_list_newf ((RzListFree)rz_bin_trycatch_free); if (!tclist) { return NULL; } for (offset = expdir->VirtualAddress; offset < (ut64)expdir->VirtualAddress + expdir->Size; offset += sizeof (PE64_RUNTIME_FUNCTION)) { PE64_RUNTIME_FUNCTION rfcn; - bool suc = r_io_read_at_mapped (io, offset + baseAddr, (ut8 *)&rfcn, sizeof (rfcn)); + bool suc = rz_io_read_at_mapped (io, offset + baseAddr, (ut8 *)&rfcn, sizeof (rfcn)); if (!rfcn.BeginAddress) { break; } ut32 savedBeginOff = rfcn.BeginAddress; ut32 savedEndOff = rfcn.EndAddress; while (suc && rfcn.UnwindData & 1) { - suc = r_io_read_at_mapped (io, baseAddr + (rfcn.UnwindData & ~1), (ut8 *)&rfcn, sizeof (rfcn)); + suc = rz_io_read_at_mapped (io, baseAddr + (rfcn.UnwindData & ~1), (ut8 *)&rfcn, sizeof (rfcn)); } rfcn.BeginAddress = savedBeginOff; rfcn.EndAddress = savedEndOff; @@ -348,7 +348,7 @@ static RList *trycatch(RBinFile *bf) { continue; } PE64_UNWIND_INFO info; - suc = r_io_read_at_mapped (io, rfcn.UnwindData + baseAddr, (ut8 *)&info, sizeof (info)); + suc = rz_io_read_at_mapped (io, rfcn.UnwindData + baseAddr, (ut8 *)&info, sizeof (info)); if (!suc || info.Version != 1 || (!(info.Flags & PE64_UNW_FLAG_EHANDLER) && !(info.Flags & PE64_UNW_FLAG_CHAININFO))) { continue; } @@ -361,15 +361,15 @@ static RList *trycatch(RBinFile *bf) { savedBeginOff = rfcn.BeginAddress; savedEndOff = rfcn.EndAddress; do { - if (!r_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&rfcn, sizeof (rfcn))) { + if (!rz_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&rfcn, sizeof (rfcn))) { break; } - suc = r_io_read_at_mapped (io, rfcn.UnwindData + baseAddr, (ut8 *)&info, sizeof (info)); + suc = rz_io_read_at_mapped (io, rfcn.UnwindData + baseAddr, (ut8 *)&info, sizeof (info)); if (!suc || info.Version != 1) { break; } while (suc && (rfcn.UnwindData & 1)) { - suc = r_io_read_at_mapped (io, baseAddr + (rfcn.UnwindData & ~1), (ut8 *)&rfcn, sizeof (rfcn)); + suc = rz_io_read_at_mapped (io, baseAddr + (rfcn.UnwindData & ~1), (ut8 *)&rfcn, sizeof (rfcn)); } if (!suc || info.Version != 1) { break; @@ -386,7 +386,7 @@ static RList *trycatch(RBinFile *bf) { } ut32 handler; - if (!r_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&handler, sizeof (handler))) { + if (!rz_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&handler, sizeof (handler))) { continue; } if (c_handler && c_handler != handler) { @@ -396,8 +396,8 @@ static RList *trycatch(RBinFile *bf) { if (!c_handler) { ut32 magic, rva_to_fcninfo; - if (r_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&rva_to_fcninfo, sizeof (rva_to_fcninfo)) && - r_io_read_at_mapped (io, baseAddr + rva_to_fcninfo, (ut8 *)&magic, sizeof (magic))) { + if (rz_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&rva_to_fcninfo, sizeof (rva_to_fcninfo)) && + rz_io_read_at_mapped (io, baseAddr + rva_to_fcninfo, (ut8 *)&magic, sizeof (magic))) { if (magic >= 0x19930520 && magic <= 0x19930522) { // __CxxFrameHandler3 or __GSHandlerCheck_EH continue; @@ -406,14 +406,14 @@ static RList *trycatch(RBinFile *bf) { } PE64_SCOPE_TABLE tbl; - if (!r_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&tbl, sizeof (tbl))) { + if (!rz_io_read_at_mapped (io, exceptionDataOff, (ut8 *)&tbl, sizeof (tbl))) { continue; } PE64_SCOPE_RECORD scope; ut64 scopeRecOff = exceptionDataOff + sizeof (tbl); for (i = 0; i < tbl.Count; i++) { - if (!r_io_read_at_mapped (io, scopeRecOff, (ut8 *)&scope, sizeof (PE64_SCOPE_RECORD))) { + if (!rz_io_read_at_mapped (io, scopeRecOff, (ut8 *)&scope, sizeof (PE64_SCOPE_RECORD))) { break; } if (scope.BeginAddress > scope.EndAddress @@ -430,7 +430,7 @@ static RList *trycatch(RBinFile *bf) { continue; } ut64 handlerAddr = scope.HandlerAddress == 1 ? 0 : scope.HandlerAddress + baseAddr; - RBinTrycatch *tc = r_bin_trycatch_new ( + RBinTrycatch *tc = rz_bin_trycatch_new ( rfcn.BeginAddress + baseAddr, scope.BeginAddress + baseAddr, scope.EndAddress + baseAddr, @@ -438,14 +438,14 @@ static RList *trycatch(RBinFile *bf) { handlerAddr ); c_handler = handler; - r_list_append (tclist, tc); + rz_list_append (tclist, tc); scopeRecOff += sizeof (PE64_SCOPE_RECORD); } } return tclist; } -RBinPlugin r_bin_plugin_pe64 = { +RBinPlugin rz_bin_plugin_pe64 = { .name = "pe64", .desc = "PE64 (PE32+) bin plugin", .license = "LGPL3", @@ -466,14 +466,14 @@ RBinPlugin r_bin_plugin_pe64 = { .relocs = &relocs, .get_vaddr = &get_vaddr, .trycatch = &trycatch, - .write = &r_bin_write_pe64, + .write = &rz_bin_write_pe64, .hashes = &compute_hashes }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_pe64, + .data = &rz_bin_plugin_pe64, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_pebble.c b/librz/bin/p/bin_pebble.c similarity index 81% rename from libr/bin/p/bin_pebble.c rename to librz/bin/p/bin_pebble.c index 0ad83c7e96..6f6b7836f8 100644 --- a/libr/bin/p/bin_pebble.c +++ b/librz/bin/p/bin_pebble.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2014-2019 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include // Taken from https://pebbledev.org/wiki/Applications @@ -37,7 +37,7 @@ typedef struct { static bool check_buffer(RBuffer *b) { ut8 magic[8]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) != sizeof (magic)) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) != sizeof (magic)) { return false; } return !memcmp (magic, "PBLAPP\x00\x00", 8); @@ -52,7 +52,7 @@ static ut64 baddr(RBinFile *bf) { } /* accelerate binary load */ -static RList *strings(RBinFile *bf) { +static RzList *strings(RBinFile *bf) { return NULL; } @@ -60,7 +60,7 @@ static RBinInfo* info(RBinFile *bf) { RBinInfo *ret = NULL; PebbleAppInfo pai; memset (&pai, 0, sizeof (pai)); - int reat = r_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof (pai)); + int reat = rz_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof (pai)); if (reat != sizeof (pai)) { eprintf ("Truncated Header\n"); return NULL; @@ -71,8 +71,8 @@ static RBinInfo* info(RBinFile *bf) { ret->lang = NULL; ret->file = strdup (bf->file); ret->type = strdup ("pebble"); - ret->bclass = r_str_ndup (pai.name, 32); - ret->rclass = r_str_ndup (pai.company, 32); + ret->bclass = rz_str_ndup (pai.name, 32); + ret->rclass = rz_str_ndup (pai.company, 32); ret->os = strdup ("rtos"); ret->subsystem = strdup ("pebble"); ret->machine = strdup ("watch"); @@ -84,16 +84,16 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -static RList* sections(RBinFile *bf) { +static RzList* sections(RBinFile *bf) { ut64 textsize = UT64_MAX; - RList *ret = NULL; + RzList *ret = NULL; RBinSection *ptr = NULL; PebbleAppInfo pai = {{0}}; - if (!r_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof(pai))) { + if (!rz_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof(pai))) { eprintf ("Truncated Header\n"); return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -106,7 +106,7 @@ static RList* sections(RBinFile *bf) { ptr->vaddr = ptr->paddr = pai.reloc_list_start; ptr->perm = R_PERM_RW; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (ptr->vaddr < textsize) { textsize = ptr->vaddr; } @@ -120,7 +120,7 @@ static RList* sections(RBinFile *bf) { ptr->vaddr = ptr->paddr = pai.sym_table_addr; ptr->perm = R_PERM_R; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (ptr->vaddr < textsize) { textsize = ptr->vaddr; } @@ -133,7 +133,7 @@ static RList* sections(RBinFile *bf) { ptr->vsize = ptr->size = textsize - ptr->paddr; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -143,34 +143,34 @@ static RList* sections(RBinFile *bf) { ptr->vaddr = ptr->paddr = 0; ptr->perm = R_PERM_R; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } #if 0 -static RList* relocs(RBinFile *bf) { - RList *ret = NULL; +static RzList* relocs(RBinFile *bf) { + RzList *ret = NULL; RBinReloc *ptr = NULL; ut64 got_addr; int i; - if (!(ret = r_list_new ())) + if (!(ret = rz_list_new ())) return NULL; ret->free = free; return ret; } #endif -static RList* entries(RBinFile *bf) { +static RzList* entries(RBinFile *bf) { RBinAddr *ptr = NULL; - RList *ret; + RzList *ret; PebbleAppInfo pai; - if (!r_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof(pai))) { + if (!rz_buf_read_at (bf->buf, 0, (ut8*)&pai, sizeof(pai))) { eprintf ("Truncated Header\n"); return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -179,11 +179,11 @@ static RList* entries(RBinFile *bf) { } ptr->paddr = pai.offset; ptr->vaddr = pai.offset; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -RBinPlugin r_bin_plugin_pebble = { +RBinPlugin rz_bin_plugin_pebble = { .name = "pebble", .desc = "Pebble Watch App", .license = "LGPL", @@ -198,9 +198,9 @@ RBinPlugin r_bin_plugin_pebble = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_pebble, + .data = &rz_bin_plugin_pebble, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_prg.c b/librz/bin/p/bin_prg.c similarity index 75% rename from libr/bin/p/bin_prg.c rename to librz/bin/p/bin_prg.c index 0c49016a3f..f5e0c0c69a 100644 --- a/libr/bin/p/bin_prg.c +++ b/librz/bin/p/bin_prg.c @@ -1,7 +1,7 @@ /* radare - LGPL3 - 2019 - thestr4ng3r */ -#include -#include +#include +#include static bool check_buffer(RBuffer *b) { // no magic @@ -13,7 +13,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } static ut64 baddr(RBinFile *bf) { - ut16 base = r_buf_read_le16_at (bf->buf, 0); + ut16 base = rz_buf_read_le16_at (bf->buf, 0); return base != UT16_MAX ? base : 0; } @@ -32,12 +32,12 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = r_list_newf ((RListFree)r_bin_section_free); +static RzList *sections(RBinFile *bf) { + RzList *ret = rz_list_newf ((RzListFree)rz_bin_section_free); if (!ret) { return NULL; } - ut64 sz = r_buf_size (bf->buf); + ut64 sz = rz_buf_size (bf->buf); if (sz < 2) { return ret; } @@ -52,12 +52,12 @@ static RList *sections(RBinFile *bf) { section->vsize = sz - 2; section->perm = R_PERM_RWX; section->add = true; - r_list_append (ret, section); + rz_list_append (ret, section); return ret; } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } @@ -67,11 +67,11 @@ static RList *entries(RBinFile *bf) { } binaddr->paddr = 2; binaddr->vaddr = baddr (bf); - r_list_append (ret, binaddr); + rz_list_append (ret, binaddr); return ret; } -RBinPlugin r_bin_plugin_prg = { +RBinPlugin rz_bin_plugin_prg = { .name = "prg", .desc = "C64 PRG", .license = "LGPL3", @@ -84,9 +84,9 @@ RBinPlugin r_bin_plugin_prg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_prg, + .data = &rz_bin_plugin_prg, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_psxexe.c b/librz/bin/p/bin_psxexe.c similarity index 67% rename from libr/bin/p/bin_psxexe.c rename to librz/bin/p/bin_psxexe.c index c016bfe48e..d5439f32d7 100644 --- a/libr/bin/p/bin_psxexe.c +++ b/librz/bin/p/bin_psxexe.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2015-2018 - Dax89, pancake */ #include -#include -#include -#include +#include +#include +#include #include "../i/private.h" #include "psxexe/psxexe.h" static bool check_buffer(RBuffer *b) { ut8 magic[PSXEXE_ID_LEN]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) == PSXEXE_ID_LEN) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) == PSXEXE_ID_LEN) { return !memcmp (magic, PSXEXE_ID, PSXEXE_ID_LEN); } return false; @@ -23,7 +23,7 @@ static RBinInfo* info(RBinFile* bf) { RBinInfo* ret = NULL; psxexe_header psxheader; - if (r_buf_read_at (bf->buf, 0, (ut8*)&psxheader, sizeof(psxexe_header)) < sizeof(psxexe_header)) { + if (rz_buf_read_at (bf->buf, 0, (ut8*)&psxheader, sizeof(psxexe_header)) < sizeof(psxexe_header)) { eprintf ("Truncated Header\n"); return NULL; } @@ -42,29 +42,29 @@ static RBinInfo* info(RBinFile* bf) { return ret; } -static RList* sections(RBinFile* bf) { - RList* ret = NULL; +static RzList* sections(RBinFile* bf) { + RzList* ret = NULL; RBinSection* sect = NULL; psxexe_header psxheader; ut64 sz = 0; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(sect = R_NEW0 (RBinSection))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - if (r_buf_fread_at (bf->buf, 0, (ut8*)&psxheader, "8c17i", 1) < sizeof (psxexe_header)) { + if (rz_buf_fread_at (bf->buf, 0, (ut8*)&psxheader, "8c17i", 1) < sizeof (psxexe_header)) { eprintf ("Truncated Header\n"); free (sect); - r_list_free (ret); + rz_list_free (ret); return NULL; } - sz = r_buf_size (bf->buf); + sz = rz_buf_size (bf->buf); sect->name = strdup ("TEXT"); sect->paddr = PSXEXE_TEXTSECTION_OFFSET; @@ -75,27 +75,27 @@ static RList* sections(RBinFile* bf) { sect->add = true; sect->has_strings = true; - r_list_append (ret, sect); + rz_list_append (ret, sect); return ret; } -static RList* entries(RBinFile* bf) { - RList* ret = NULL; +static RzList* entries(RBinFile* bf) { + RzList* ret = NULL; RBinAddr* addr = NULL; psxexe_header psxheader; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(addr = R_NEW0 (RBinAddr))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - if (r_buf_fread_at (bf->buf, 0, (ut8*)&psxheader, "8c17i", 1) < sizeof (psxexe_header)) { + if (rz_buf_fread_at (bf->buf, 0, (ut8*)&psxheader, "8c17i", 1) < sizeof (psxexe_header)) { eprintf ("PSXEXE Header truncated\n"); - r_list_free (ret); + rz_list_free (ret); free (addr); return NULL; } @@ -103,16 +103,16 @@ static RList* entries(RBinFile* bf) { addr->paddr = (psxheader.pc0 - psxheader.t_addr) + PSXEXE_TEXTSECTION_OFFSET; addr->vaddr = psxheader.pc0; - r_list_append (ret, addr); + rz_list_append (ret, addr); return ret; } -static RList* strings(RBinFile* bf) { +static RzList* strings(RBinFile* bf) { // hardcode minstrlen = 20 - return r_bin_file_get_strings (bf, 20, 0, 2); + return rz_bin_file_get_strings (bf, 20, 0, 2); } -RBinPlugin r_bin_plugin_psxexe = { +RBinPlugin rz_bin_plugin_psxexe = { .name = "psxexe", .desc = "Sony PlayStation 1 Executable", .license = "LGPL3", @@ -125,9 +125,9 @@ RBinPlugin r_bin_plugin_psxexe = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_psxexe, + .data = &rz_bin_plugin_psxexe, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_pyc.c b/librz/bin/p/bin_pyc.c similarity index 63% rename from libr/bin/p/bin_pyc.c rename to librz/bin/p/bin_pyc.c index 556fec88d4..fbacafe84c 100644 --- a/libr/bin/p/bin_pyc.c +++ b/librz/bin/p/bin_pyc.c @@ -1,6 +1,6 @@ /* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */ -#include +#include #include "../format/pyc/pyc.h" // XXX: to not use globals @@ -8,13 +8,13 @@ static ut64 code_start_offset = 0; static struct pyc_version version; /* used from marshall.c */ -RList *interned_table = NULL; -static RList *sections_cache = NULL; +RzList *interned_table = NULL; +static RzList *sections_cache = NULL; static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) > 4) { + if (rz_buf_size (b) > 4) { ut32 buf; - r_buf_read_at (b, 0, (ut8 *)&buf, sizeof (buf)); + rz_buf_read_at (b, 0, (ut8 *)&buf, sizeof (buf)); version = get_pyc_version (buf); return version.magic != -1; } @@ -30,10 +30,10 @@ static ut64 get_entrypoint(RBuffer *buf) { ut64 result; int addr; for (addr = 0x8; addr <= 0x10; addr += 0x4) { - r_buf_read_at (buf, addr, &b, sizeof (b)); + rz_buf_read_at (buf, addr, &b, sizeof (b)); if (pyc_is_code (b, version.magic)) { code_start_offset = addr; - r_buf_seek (buf, addr + 1, R_BUF_SET); + rz_buf_seek (buf, addr + 1, R_BUF_SET); if ((result = get_code_object_addr (buf, version.magic)) == 0) { return addr; } @@ -49,11 +49,11 @@ static RBinInfo *info(RBinFile *arch) { return NULL; } ret->file = strdup (arch->file); - ret->type = r_str_newf ("Python %s byte-compiled file", version.version); + ret->type = rz_str_newf ("Python %s byte-compiled file", version.version); ret->bclass = strdup ("Python byte-compiled file"); ret->rclass = strdup ("pyc"); ret->arch = strdup ("pyc"); - ret->machine = r_str_newf ("Python %s VM (rev %s)", version.version, + ret->machine = rz_str_newf ("Python %s VM (rev %s)", version.version, version.revision); ret->os = strdup ("any"); ret->bits = version2double (version.version) < 3.6? 16: 8; @@ -61,25 +61,25 @@ static RBinInfo *info(RBinFile *arch) { return ret; } -static RList *sections(RBinFile *arch) { +static RzList *sections(RBinFile *arch) { return sections_cache; } -static RList *entries(RBinFile *arch) { - RList *entries = r_list_newf ((RListFree)free); +static RzList *entries(RBinFile *arch) { + RzList *entries = rz_list_newf ((RzListFree)free); if (!entries) { return NULL; } RBinAddr *addr = R_NEW0 (RBinAddr); if (!addr) { - r_list_free (entries); + rz_list_free (entries); return NULL; } ut64 entrypoint = get_entrypoint (arch->buf); addr->paddr = entrypoint; addr->vaddr = entrypoint; - r_buf_seek (arch->buf, entrypoint, R_IO_SEEK_SET); - r_list_append (entries, addr); + rz_buf_seek (arch->buf, entrypoint, R_IO_SEEK_SET); + rz_list_append (entries, addr); return entries; } @@ -87,46 +87,46 @@ static ut64 baddr(RBinFile *bf) { return 0; } -static RList *symbols(RBinFile *arch) { - RList *shared = r_list_newf ((RListFree)r_list_free); +static RzList *symbols(RBinFile *arch) { + RzList *shared = rz_list_newf ((RzListFree)rz_list_free); if (!shared) { return NULL; } - RList *cobjs = r_list_newf ((RListFree)free); + RzList *cobjs = rz_list_newf ((RzListFree)free); if (!cobjs) { - r_list_free (shared); + rz_list_free (shared); return NULL; } - interned_table = r_list_newf ((RListFree)free); + interned_table = rz_list_newf ((RzListFree)free); if (!interned_table) { - r_list_free (shared); - r_list_free (cobjs); + rz_list_free (shared); + rz_list_free (cobjs); return NULL; } - r_list_append (shared, cobjs); - r_list_append (shared, interned_table); + rz_list_append (shared, cobjs); + rz_list_append (shared, interned_table); arch->o->bin_obj = shared; - RList *sections = r_list_newf ((RListFree)free); + RzList *sections = rz_list_newf ((RzListFree)free); if (!sections) { - r_list_free (shared); + rz_list_free (shared); arch->o->bin_obj = NULL; return NULL; } - RList *symbols = r_list_newf ((RListFree)free); + RzList *symbols = rz_list_newf ((RzListFree)free); if (!symbols) { - r_list_free (shared); + rz_list_free (shared); arch->o->bin_obj = NULL; - r_list_free (sections); + rz_list_free (sections); return NULL; } RBuffer *buffer = arch->buf; - r_buf_seek (buffer, code_start_offset, R_BUF_SET); + rz_buf_seek (buffer, code_start_offset, R_BUF_SET); pyc_get_sections_symbols (sections, symbols, cobjs, buffer, version.magic); sections_cache = sections; return symbols; } -RBinPlugin r_bin_plugin_pyc = { +RBinPlugin rz_bin_plugin_pyc = { .name = "pyc", .desc = "Python byte-compiled file plugin", .license = "LGPL3", @@ -140,9 +140,9 @@ RBinPlugin r_bin_plugin_pyc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_pyc, + .data = &rz_bin_plugin_pyc, .version = R2_VERSION, }; #endif diff --git a/libr/bin/p/bin_qnx.c b/librz/bin/p/bin_qnx.c similarity index 77% rename from libr/bin/p/bin_qnx.c rename to librz/bin/p/bin_qnx.c index 9e97a3f5d8..a1c5764b5a 100644 --- a/libr/bin/p/bin_qnx.c +++ b/librz/bin/p/bin_qnx.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL3 - 2015-2019 - deepakchethan */ +/* rizin - LGPL3 - 2015-2019 - deepakchethan */ #include "qnx/qnx.h" #include "../i/private.h" static int lmf_header_load(lmf_header *lmfh, RBuffer *buf, Sdb *db) { - if (r_buf_size (buf) < sizeof (lmf_header)) { + if (rz_buf_size (buf) < sizeof (lmf_header)) { return false; } - if (r_buf_fread_at (buf, QNX_HEADER_ADDR, (ut8 *) lmfh, "iiiiiiiicccciiiicc", 1) < QNX_HDR_SIZE) { + if (rz_buf_fread_at (buf, QNX_HEADER_ADDR, (ut8 *) lmfh, "iiiiiiiicccciiiicc", 1) < QNX_HDR_SIZE) { return false; } sdb_set (db, "qnx.version", sdb_fmt ("0x%xH", lmfh->version), 0); @@ -27,15 +27,15 @@ static int lmf_header_load(lmf_header *lmfh, RBuffer *buf, Sdb *db) { static bool check_buffer(RBuffer *buf) { ut8 tmp[6]; - int r = r_buf_read_at (buf, 0, tmp, sizeof (tmp)); + int r = rz_buf_read_at (buf, 0, tmp, sizeof (tmp)); return r == sizeof (tmp) && !memcmp (tmp, QNX_MAGIC, sizeof (tmp)); } // Frees the bin_obj of the binary file static void destroy(RBinFile *bf) { QnxObj *qo = bf->o->bin_obj; - r_list_free (qo->sections); - r_list_free (qo->fixups); + rz_list_free (qo->sections); + rz_list_free (qo->fixups); bf->o->bin_obj = NULL; free (qo); } @@ -49,13 +49,13 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd lmf_resource lres; lmf_data ldata; ut64 offset = QNX_RECORD_SIZE; - RList *sections = NULL; - RList *fixups = NULL; + RzList *sections = NULL; + RzList *fixups = NULL; if (!qo) { goto beach; } - if (!(sections = r_list_newf ((RListFree)r_bin_section_free)) || !(fixups = r_list_new ())) { + if (!(sections = rz_list_newf ((RzListFree)rz_bin_section_free)) || !(fixups = rz_list_new ())) { goto beach; } qo->kv = sdb_new0 (); @@ -63,7 +63,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd goto beach; } // Read the first record - if (r_buf_fread_at (bf->buf, 0, (ut8 *)&lrec, "ccss", 1) < QNX_RECORD_SIZE) { + if (rz_buf_fread_at (bf->buf, 0, (ut8 *)&lrec, "ccss", 1) < QNX_RECORD_SIZE) { goto beach; } // Load the header @@ -71,7 +71,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd offset += lrec.data_nbytes; for (;;) { - if (r_buf_fread_at (bf->buf, offset, (ut8 *)&lrec, "ccss", 1) < QNX_RECORD_SIZE) { + if (rz_buf_fread_at (bf->buf, offset, (ut8 *)&lrec, "ccss", 1) < QNX_RECORD_SIZE) { goto beach; } offset += sizeof (lmf_record); @@ -83,7 +83,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd if (!ptr) { goto beach; } - if (r_buf_fread_at (bf->buf, offset, (ut8 *)&lres, "ssss", 1) < sizeof (lmf_resource)) { + if (rz_buf_fread_at (bf->buf, offset, (ut8 *)&lres, "ssss", 1) < sizeof (lmf_resource)) { goto beach; } ptr->name = strdup ("LMF_RESOURCE"); @@ -91,10 +91,10 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd ptr->vsize = lrec.data_nbytes - sizeof (lmf_resource); ptr->size = ptr->vsize; ptr->add = true; - r_list_append (sections, ptr); + rz_list_append (sections, ptr); } else if (lrec.rec_type == LMF_LOAD_REC) { RBinSection *ptr = R_NEW0 (RBinSection); - if (r_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { + if (rz_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { goto beach; } if (!ptr) { @@ -106,25 +106,25 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd ptr->vsize = lrec.data_nbytes - sizeof (lmf_data); ptr->size = ptr->vsize; ptr->add = true; - r_list_append (sections, ptr); + rz_list_append (sections, ptr); } else if (lrec.rec_type == LMF_FIXUP_REC) { RBinReloc *ptr = R_NEW0 (RBinReloc); - if (!ptr || r_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { + if (!ptr || rz_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { goto beach; } ptr->vaddr = ptr->paddr = ldata.offset; ptr->type = 'f'; // "LMF_FIXUP"; - r_list_append (fixups, ptr); + rz_list_append (fixups, ptr); } else if (lrec.rec_type == LMF_8087_FIXUP_REC) { RBinReloc *ptr = R_NEW0 (RBinReloc); - if (!ptr || r_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { + if (!ptr || rz_buf_fread_at (bf->buf, offset, (ut8 *)&ldata, "si", 1) < sizeof (lmf_data)) { goto beach; } ptr->vaddr = ptr->paddr = ldata.offset; ptr->type = 'F'; // "LMF_8087_FIXUP"; - r_list_append (fixups, ptr); + rz_list_append (fixups, ptr); } else if (lrec.rec_type == LMF_RW_END_REC) { - r_buf_fread_at (bf->buf, offset, (ut8 *)&qo->rwend, "si", 1); + rz_buf_fread_at (bf->buf, offset, (ut8 *)&qo->rwend, "si", 1); } offset += lrec.data_nbytes; } @@ -135,8 +135,8 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd return true; beach: free (qo); - r_list_free (fixups); - r_list_free (sections); + rz_list_free (fixups); + rz_list_free (sections); return false; } @@ -146,7 +146,7 @@ beach: * @return RBinInfo file with the info */ static RBinInfo *info(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); RBinInfo *ret = R_NEW0 (RBinInfo); if (!ret) { return NULL; @@ -164,14 +164,14 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static RList *relocs(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); +static RzList *relocs(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o, NULL); QnxObj *qo = bf->o->bin_obj; - return r_list_clone (qo->fixups); + return rz_list_clone (qo->fixups); } static void header(RBinFile *bf) { - r_return_if_fail (bf && bf->o && bf->rbin); + rz_return_if_fail (bf && bf->o && bf->rbin); QnxObj *bin = bf->o->bin_obj; RBin *rbin = bf->rbin; rbin->cb_printf ("QNX file header:\n"); @@ -194,15 +194,15 @@ static void header(RBinFile *bf) { /* * No mention of symbols in the doc */ -static RList* symbols(RBinFile *bf) { +static RzList* symbols(RBinFile *bf) { return NULL; } // Returns the sections -static RList* sections(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, NULL); +static RzList* sections(RBinFile *bf) { + rz_return_val_if_fail (bf && bf->o, NULL); QnxObj *qo = bf->o->bin_obj; - return r_list_clone (qo->sections); + return rz_list_clone (qo->sections); } /* @@ -233,11 +233,11 @@ static ut64 baddr(RBinFile *bf) { * Currently both physical and virtual address are set to 0 * The memory map has different values for entry */ -static RList* entries(RBinFile *bf) { - RList *ret; +static RzList* entries(RBinFile *bf) { + RzList *ret; RBinAddr *ptr = NULL; QnxObj *qo = bf->o->bin_obj; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -246,7 +246,7 @@ static RList* entries(RBinFile *bf) { } ptr->paddr = qo->lmfh.code_offset; ptr->vaddr = qo->lmfh.code_offset + baddr (bf); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } @@ -257,7 +257,7 @@ static RList* entries(RBinFile *bf) { static char *signature(RBinFile *bf, bool json) { char buf[64]; QnxObj *qo = bf->o->bin_obj; - return qo? r_str_dup (NULL, sdb_itoa (qo->rwend.signature, buf, 10)): NULL; + return qo? rz_str_dup (NULL, sdb_itoa (qo->rwend.signature, buf, 10)): NULL; } /* @@ -268,7 +268,7 @@ static ut64 get_vaddr(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr) { } // Declaration of the plugin -RBinPlugin r_bin_plugin_qnx = { +RBinPlugin rz_bin_plugin_qnx = { .name = "qnx", .desc = "QNX executable file support", .license = "LGPL3", @@ -289,9 +289,9 @@ RBinPlugin r_bin_plugin_qnx = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_qnx, + .data = &rz_bin_plugin_qnx, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_sfc.c b/librz/bin/p/bin_sfc.c similarity index 72% rename from libr/bin/p/bin_sfc.c rename to librz/bin/p/bin_sfc.c index c829f05c15..bdaf7b2a01 100644 --- a/libr/bin/p/bin_sfc.c +++ b/librz/bin/p/bin_sfc.c @@ -1,13 +1,13 @@ /* radare - LGPL3 - 2017-2019 - usrshare */ -#include -#include +#include +#include #include "sfc/sfc_specs.h" -#include +#include static bool check_buffer(RBuffer *b) { ut16 cksum1, cksum2; - ut64 length = r_buf_size (b); + ut64 length = rz_buf_size (b); // FIXME: this was commented out because it always evaluates to false. // Need to be fixed by someone with SFC knowledge // if ((length & 0x8000) == 0x200) { @@ -17,8 +17,8 @@ static bool check_buffer(RBuffer *b) { return false; } //determine if ROM is headered, and add a 0x200 gap if so. - cksum1 = r_buf_read_le16_at (b, 0x7fdc); - cksum2 = r_buf_read_le16_at (b, 0x7fde); + cksum1 = rz_buf_read_le16_at (b, 0x7fdc); + cksum2 = rz_buf_read_le16_at (b, 0x7fde); if (cksum1 == (ut16)~cksum2) { return true; @@ -26,8 +26,8 @@ static bool check_buffer(RBuffer *b) { if (length < 0xffee) { return false; } - cksum1 = r_buf_read_le16_at (b, 0xffdc); - cksum2 = r_buf_read_le16_at (b, 0xffde); + cksum1 = rz_buf_read_le16_at (b, 0xffdc); + cksum2 = rz_buf_read_le16_at (b, 0xffde); return (cksum1 == (ut16)~cksum2); } @@ -44,7 +44,7 @@ static RBinInfo* info(RBinFile *bf) { hdroffset = 0x200; } #endif - int reat = r_buf_read_at (bf->buf, 0x7FC0 + hdroffset, + int reat = rz_buf_read_at (bf->buf, 0x7FC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); if (reat != SFC_HDR_SIZE) { eprintf ("Unable to read SFC/SNES header\n"); @@ -55,7 +55,7 @@ static RBinInfo* info(RBinFile *bf) { // if the fixed 0x33 byte or the LoROM indication are not found, then let's try interpreting the ROM as HiROM - reat = r_buf_read_at (bf->buf, 0xFFC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); + reat = rz_buf_read_at (bf->buf, 0xFFC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); if (reat != SFC_HDR_SIZE) { eprintf ("Unable to read SFC/SNES header\n"); return NULL; @@ -81,22 +81,22 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -static void addrom(RList *ret, const char *name, int i, ut64 paddr, ut64 vaddr, ut32 size) { +static void addrom(RzList *ret, const char *name, int i, ut64 paddr, ut64 vaddr, ut32 size) { RBinSection *ptr = R_NEW0 (RBinSection); if (!ptr) { return; } - ptr->name = r_str_newf ("%s_%02x", name, i); + ptr->name = rz_str_newf ("%s_%02x", name, i); ptr->paddr = paddr; ptr->vaddr = vaddr; ptr->size = ptr->vsize = size; ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } #if 0 -static void addsym(RList *ret, const char *name, ut64 addr, ut32 size) { +static void addsym(RzList *ret, const char *name, ut64 addr, ut32 size) { RBinSymbol *ptr = R_NEW0 (RBinSymbol); if (!ptr) { return; @@ -105,16 +105,16 @@ static void addsym(RList *ret, const char *name, ut64 addr, ut32 size) { ptr->paddr = ptr->vaddr = addr; ptr->size = size; ptr->ordinal = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } #endif -static RList* symbols(RBinFile *bf) { +static RzList* symbols(RBinFile *bf) { return NULL; } -static RList* sections(RBinFile *bf) { - RList *ret = NULL; +static RzList* sections(RBinFile *bf) { + RzList *ret = NULL; // RBinSection *ptr = NULL; int hdroffset = 0; bool is_hirom = false; @@ -126,7 +126,7 @@ static RList* sections(RBinFile *bf) { #endif sfc_int_hdr sfchdr = {{0}}; - int reat = r_buf_read_at (bf->buf, 0x7FC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); + int reat = rz_buf_read_at (bf->buf, 0x7FC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); if (reat != SFC_HDR_SIZE) { eprintf ("Unable to read SFC/SNES header\n"); return NULL; @@ -136,7 +136,7 @@ static RList* sections(RBinFile *bf) { // if the fixed 0x33 byte or the LoROM indication are not found, then let's try interpreting the ROM as HiROM - reat = r_buf_read_at (bf->buf, 0xFFC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); + reat = rz_buf_read_at (bf->buf, 0xFFC0 + hdroffset, (ut8*)&sfchdr, SFC_HDR_SIZE); if (reat != SFC_HDR_SIZE) { eprintf ("Unable to read SFC/SNES header\n"); return NULL; @@ -150,7 +150,7 @@ static RList* sections(RBinFile *bf) { is_hirom = true; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } @@ -172,92 +172,92 @@ static RList* sections(RBinFile *bf) { return ret; } -static RList *mem (RBinFile *bf) { - RList *ret; +static RzList *mem (RBinFile *bf) { + RzList *ret; RBinMem *m; RBinMem *m_bak; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("LOWRAM"); m->addr = LOWRAM_START_ADDRESS; m->size = LOWRAM_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; } - m->mirrors = r_list_new (); + m->mirrors = rz_list_new (); m->name = strdup ("LOWRAM_MIRROR"); m->addr = LOWRAM_MIRROR_START_ADDRESS; m->size = LOWRAM_MIRROR_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (m->mirrors, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (m->mirrors, m); m_bak = m; if (!(m = R_NEW0 (RBinMem))) { - r_list_free (m_bak->mirrors); + rz_list_free (m_bak->mirrors); return ret; } m->name = strdup ("HIRAM"); m->addr = HIRAM_START_ADDRESS; m->size = HIRAM_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; } m->name = strdup ("EXTRAM"); m->addr = EXTRAM_START_ADDRESS; m->size = EXTRAM_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { return ret; } m->name = strdup ("PPU1_REG"); m->addr = PPU1_REG_ADDRESS; m->size = PPU1_REG_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("DSP_REG"); m->addr = DSP_REG_ADDRESS; m->size = DSP_REG_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("OLDJOY_REG"); m->addr = OLDJOY_REG_ADDRESS; m->size = OLDJOY_REG_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("PPU2_REG"); m->addr = PPU2_REG_ADDRESS; m->size = PPU2_REG_SIZE; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); return ret; } -static RList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR - RList *ret; - if (!(ret = r_list_new ())) { +static RzList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR + RzList *ret; + if (!(ret = rz_list_new ())) { return NULL; } /* @@ -267,12 +267,12 @@ static RList* entries(RBinFile *bf) { //Should be 3 offsets pointed by NMI, RESE } ptr->paddr = INES_HDR_SIZE; ptr->vaddr = ROM_START_ADDRESS; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); */ return ret; } -RBinPlugin r_bin_plugin_sfc = { +RBinPlugin rz_bin_plugin_sfc = { .name = "sfc", .desc = "Super NES / Super Famicom ROM file", .license = "LGPL3", @@ -286,9 +286,9 @@ RBinPlugin r_bin_plugin_sfc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_sfc, + .data = &rz_bin_plugin_sfc, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_smd.c b/librz/bin/p/bin_smd.c similarity index 80% rename from libr/bin/p/bin_smd.c rename to librz/bin/p/bin_smd.c index ce1e4bbf9f..a881380cda 100644 --- a/libr/bin/p/bin_smd.c +++ b/librz/bin/p/bin_smd.c @@ -1,6 +1,6 @@ /* radare - LGPL3 - 2015-2018 - pancake */ -#include +#include typedef struct gen_hdr { ut8 CopyRights[32]; @@ -96,9 +96,9 @@ static ut64 baddr(RBinFile *bf) { } static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) > 0x190) { + if (rz_buf_size (b) > 0x190) { ut8 buf[4]; - r_buf_read_at (b, 0x100, buf, sizeof (buf)); + rz_buf_read_at (b, 0x100, buf, sizeof (buf)); return !memcmp (buf, "SEGA", 4); } return false; @@ -117,8 +117,8 @@ static RBinInfo *info(RBinFile *bf) { ret->type = strdup ("ROM"); ret->machine = strdup ("Sega Megadrive"); ut8 tmp[32]; - r_buf_read_at (bf->buf, 0x100, tmp, sizeof (tmp)); - ret->bclass = r_str_ndup ((char *)tmp, 32); + rz_buf_read_at (bf->buf, 0x100, tmp, sizeof (tmp)); + ret->bclass = rz_str_ndup ((char *)tmp, 32); ret->os = strdup ("smd"); ret->arch = strdup ("m68k"); ret->bits = 16; @@ -127,7 +127,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -static void addsym(RList *ret, const char *name, ut64 addr) { +static void addsym(RzList *ret, const char *name, ut64 addr) { RBinSymbol *ptr = R_NEW0 (RBinSymbol); if (!ptr) { return; @@ -136,33 +136,33 @@ static void addsym(RList *ret, const char *name, ut64 addr) { ptr->paddr = ptr->vaddr = addr; ptr->size = 0; ptr->ordinal = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } static void showstr(const char *str, const ut8 *s, int len) { - char *msg = r_str_ndup ((const char *) s, len); + char *msg = rz_str_ndup ((const char *) s, len); eprintf ("%s: %s\n", str, msg); free (msg); } -static RList *symbols(RBinFile *bf) { - RList *ret = NULL; +static RzList *symbols(RBinFile *bf) { + RzList *ret = NULL; const char *name = NULL; int i; - if (!(ret = r_list_newf (free))) { + if (!(ret = rz_list_newf (free))) { return NULL; } SMD_Header hdr; - int left = r_buf_read_at (bf->buf, 0x100, (ut8*)&hdr, sizeof (hdr)); + int left = rz_buf_read_at (bf->buf, 0x100, (ut8*)&hdr, sizeof (hdr)); if (left < sizeof (SMD_Header)) { return NULL; } // TODO: store all this stuff in SDB - addsym (ret, "rom_start", r_read_be32 (&hdr.RomStart)); - addsym (ret, "rom_end", r_read_be32 (&hdr.RomEnd)); - addsym (ret, "ram_start", r_read_be32 (&hdr.RamStart)); - addsym (ret, "ram_end", r_read_be32 (&hdr.RamEnd)); + addsym (ret, "rom_start", rz_read_be32 (&hdr.RomStart)); + addsym (ret, "rom_end", rz_read_be32 (&hdr.RomEnd)); + addsym (ret, "ram_start", rz_read_be32 (&hdr.RamStart)); + addsym (ret, "ram_end", rz_read_be32 (&hdr.RamEnd)); showstr ("Copyright", hdr.CopyRights, 32); showstr ("DomesticName", hdr.DomesticName, 48); showstr ("OverseasName", hdr.OverseasName, 48); @@ -173,7 +173,7 @@ static RList *symbols(RBinFile *bf) { showstr ("ModemCode", hdr.ModemCode, 12); showstr ("CountryCode", hdr.CountryCode, 16); ut32 vtable[64]; - r_buf_read_at (bf->buf, 0, (ut8*)&vtable, sizeof (ut32) * 64); + rz_buf_read_at (bf->buf, 0, (ut8*)&vtable, sizeof (ut32) * 64); /* parse vtable */ for (i = 0; i < 64; i++) { switch (i) { @@ -244,16 +244,16 @@ static RList *symbols(RBinFile *bf) { default: name = NULL; } if (name && vtable[i]) { - ut32 addr = r_read_be32 (&vtable[i]); + ut32 addr = rz_read_be32 (&vtable[i]); addsym (ret, name, addr); } } return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; - if (!(ret = r_list_new ())) { +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; + if (!(ret = rz_list_new ())) { return NULL; } RBinSection *ptr; @@ -265,7 +265,7 @@ static RList *sections(RBinFile *bf) { ptr->size = ptr->vsize = 0x100; ptr->perm = R_PERM_R; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -275,7 +275,7 @@ static RList *sections(RBinFile *bf) { ptr->size = ptr->vsize = sizeof (SMD_Header); ptr->perm = R_PERM_R; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -284,21 +284,21 @@ static RList *sections(RBinFile *bf) { ptr->paddr = ptr->vaddr = 0x100 + sizeof (SMD_Header); { SMD_Header hdr = {{0}}; - r_buf_read_at (bf->buf, 0x100, (ut8*)&hdr, sizeof (hdr)); - ut64 baddr = r_read_be32 (&hdr.RomStart); + rz_buf_read_at (bf->buf, 0x100, (ut8*)&hdr, sizeof (hdr)); + ut64 baddr = rz_read_be32 (&hdr.RomStart); ptr->vaddr += baddr; } - ptr->size = ptr->vsize = r_buf_size (bf->buf) - ptr->paddr; + ptr->size = ptr->vsize = rz_buf_size (bf->buf) - ptr->paddr; ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -static RList *entries(RBinFile *bf) { // Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR - RList *ret; +static RzList *entries(RBinFile *bf) { // Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(ptr = R_NEW0 (RBinAddr))) { @@ -307,17 +307,17 @@ static RList *entries(RBinFile *bf) { // Should be 3 offsets pointed by NMI, RES if (bf->size < sizeof (SMD_Vectors)) { eprintf ("ERR: binfile too small!\n"); ptr->paddr = ptr->vaddr = 0x100 + sizeof (SMD_Header); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } else { SMD_Vectors vectors; - r_buf_read_at (bf->buf, 0, (ut8*)&vectors, sizeof (vectors)); - ptr->paddr = ptr->vaddr = r_read_be32 (&vectors.Reset); - r_list_append (ret, ptr); + rz_buf_read_at (bf->buf, 0, (ut8*)&vectors, sizeof (vectors)); + ptr->paddr = ptr->vaddr = rz_read_be32 (&vectors.Reset); + rz_list_append (ret, ptr); } return ret; } -RBinPlugin r_bin_plugin_smd = { +RBinPlugin rz_bin_plugin_smd = { .name = "smd", .desc = "SEGA Genesis/Megadrive", .license = "LGPL3", @@ -333,9 +333,9 @@ RBinPlugin r_bin_plugin_smd = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_smd, + .data = &rz_bin_plugin_smd, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_sms.c b/librz/bin/p/bin_sms.c similarity index 90% rename from libr/bin/p/bin_sms.c rename to librz/bin/p/bin_sms.c index 516d381907..2df6b50853 100644 --- a/libr/bin/p/bin_sms.c +++ b/librz/bin/p/bin_sms.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2015-2018 - shengdi */ -#include +#include typedef struct gen_hdr { ut8 HeaderID[8]; @@ -17,7 +17,7 @@ static bool check_buffer(RBuffer *b) { ut32 *off, offs[] = { 0x2000, 0x4000, 0x8000, 0x9000, 0 }; ut8 signature[8]; for (off = (ut32*)&offs; *off; off++) { - r_buf_read_at (b, *off - 16, (ut8*)&signature, 8); + rz_buf_read_at (b, *off - 16, (ut8*)&signature, 8); if (!strncmp ((const char *)signature, "TMR SEGA", 8)) { cb = *off - 16; return true; // int)(*off - 16); @@ -55,8 +55,8 @@ static RBinInfo *info(RBinFile *bf) { return NULL; } SMS_Header hdr = {{0}}; - r_buf_read_at (bf->buf, cb, (ut8*)&hdr, sizeof (hdr)); - hdr.CheckSum = r_read_le16 (&hdr.CheckSum); + rz_buf_read_at (bf->buf, cb, (ut8*)&hdr, sizeof (hdr)); + hdr.CheckSum = rz_read_le16 (&hdr.CheckSum); eprintf ("Checksum: 0x%04x\n", (ut32)hdr.CheckSum); // use endian safe apis here eprintf ("ProductCode: %02d%02X%02X\n", (hdr.Version >> 4), hdr.ProductCode[1], @@ -99,7 +99,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -RBinPlugin r_bin_plugin_sms = { +RBinPlugin rz_bin_plugin_sms = { .name = "sms", .desc = "SEGA MasterSystem/GameGear", .license = "LGPL3", @@ -111,9 +111,9 @@ RBinPlugin r_bin_plugin_sms = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_sms, + .data = &rz_bin_plugin_sms, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_spc700.c b/librz/bin/p/bin_spc700.c similarity index 73% rename from libr/bin/p/bin_spc700.c rename to librz/bin/p/bin_spc700.c index e7f4422678..48ceefee32 100644 --- a/libr/bin/p/bin_spc700.c +++ b/librz/bin/p/bin_spc700.c @@ -1,12 +1,12 @@ /* radare - LGPL - 2015-2019 - maijin */ -#include -#include +#include +#include #include "../format/spc700/spc_specs.h" static bool check_buffer(RBuffer *b) { ut8 buf[27]; - if (r_buf_read_at (b, 0, buf, sizeof (buf)) == 27) { + if (rz_buf_read_at (b, 0, buf, sizeof (buf)) == 27) { return !memcmp (buf, SPC_MAGIC, 27); } return false; @@ -20,7 +20,7 @@ static RBinInfo* info(RBinFile *bf) { RBinInfo *ret = NULL; spc_hdr spchdr; memset (&spchdr, 0, SPC_HDR_SIZE); - int reat = r_buf_read_at (bf->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE); + int reat = rz_buf_read_at (bf->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE); if (reat != SPC_HDR_SIZE) { eprintf ("Truncated Header\n"); return NULL; @@ -38,21 +38,21 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -static RList* sections(RBinFile *bf) { - RList *ret = NULL; +static RzList* sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; spc_hdr spchdr; memset (&spchdr, 0, SPC_HDR_SIZE); - int reat = r_buf_read_at (bf->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE); + int reat = rz_buf_read_at (bf->buf, 0, (ut8*)&spchdr, SPC_HDR_SIZE); if (reat != SPC_HDR_SIZE) { eprintf ("Truncated Header\n"); return NULL; } - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } if (!(ptr = R_NEW0 (RBinSection))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } ptr->name = strdup ("RAM"); @@ -62,24 +62,24 @@ static RList* sections(RBinFile *bf) { ptr->vsize = RAM_SIZE; ptr->perm = R_PERM_R; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -static RList* entries(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList* entries(RBinFile *bf) { + RzList *ret = rz_list_newf (free); if (ret) { RBinAddr *ptr = R_NEW0 (RBinAddr); if (ptr) { ptr->paddr = RAM_START_ADDRESS; ptr->vaddr = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } return ret; } -RBinPlugin r_bin_plugin_spc700 = { +RBinPlugin rz_bin_plugin_spc700 = { .name = "spc700", .desc = "SNES-SPC700 Sound File Data", .license = "LGPL3", @@ -91,9 +91,9 @@ RBinPlugin r_bin_plugin_spc700 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_spc700, + .data = &rz_bin_plugin_spc700, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_symbols.c b/librz/bin/p/bin_symbols.c similarity index 75% rename from libr/bin/p/bin_symbols.c rename to librz/bin/p/bin_symbols.c index 855cd84904..798a616319 100644 --- a/libr/bin/p/bin_symbols.c +++ b/librz/bin/p/bin_symbols.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2018 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "../i/private.h" #include "mach0/coresymbolication.h" @@ -32,7 +32,7 @@ typedef struct symbols_metadata_t { // 0x40 ut32 name; bool valid; ut32 size; - //RList *segments; + //RzList *segments; ut32 addr; int bits; const char *arch; @@ -43,17 +43,17 @@ typedef struct symbols_metadata_t { // 0x40 static SymbolsHeader parseHeader(RBuffer *buf) { ut8 b[64]; SymbolsHeader sh = { 0 }; - (void)r_buf_read_at (buf, 0, b, sizeof (b)); - sh.magic = r_read_le32 (b); - sh.version = r_read_le32 (b + 4); + (void)rz_buf_read_at (buf, 0, b, sizeof (b)); + sh.magic = rz_read_le32 (b); + sh.version = rz_read_le32 (b + 4); sh.valid = sh.magic == 0xff01ff02; int i; for (i = 0; i < 16; i++) { sh.uuid[i] = b[24 + i]; } - sh.unk0 = r_read_le16 (b + 0x28); - sh.unk1 = r_read_le16 (b + 0x2c); // is slotsize + 1 :? - sh.slotsize = r_read_le16 (b + 0x2e); + sh.unk0 = rz_read_le16 (b + 0x28); + sh.unk1 = rz_read_le16 (b + 0x2c); // is slotsize + 1 :? + sh.slotsize = rz_read_le16 (b + 0x2e); sh.size = 0x40; return sh; } @@ -86,18 +86,18 @@ static const char *subtypeString(int n) { static SymbolsMetadata parseMetadata(RBuffer *buf, int off) { SymbolsMetadata sm = { 0 }; ut8 b[0x100] = { 0 }; - (void)r_buf_read_at (buf, off, b, sizeof (b)); + (void)rz_buf_read_at (buf, off, b, sizeof (b)); sm.addr = off; - sm.cputype = r_read_le32 (b); + sm.cputype = rz_read_le32 (b); sm.arch = typeString (sm.cputype, &sm.bits); // eprintf ("0x%08x cputype 0x%x -> %s\n", 0x40, sm.cputype, typeString (sm.cputype)); // bits = (strstr (typeString (sm.cputype, &sm.bits), "64"))? 64: 32; - sm.subtype = r_read_le32 (b + 4); + sm.subtype = rz_read_le32 (b + 4); sm.cpu = subtypeString (sm.subtype); // eprintf ("0x%08x subtype 0x%x -> %s\n", 0x44, sm.subtype, subtypeString (sm.subtype)); - sm.n_segments = r_read_le32 (b + 8); - // int count = r_read_le32 (b + 0x48); - sm.namelen = r_read_le32 (b + 0xc); + sm.n_segments = rz_read_le32 (b + 8); + // int count = rz_read_le32 (b + 0x48); + sm.namelen = rz_read_le32 (b + 0xc); // eprintf ("0x%08x count %d\n", 0x48, count); // eprintf ("0x%08x strlen %d\n", 0x4c, sm.namelen); // eprintf ("0x%08x filename %s\n", 0x50, b + 16); @@ -107,11 +107,11 @@ static SymbolsMetadata parseMetadata(RBuffer *buf, int off) { // hack to detect format ut32 nm, nm2, nm3; - r_buf_read_at (buf, off + sm.size, (ut8 *)&nm, sizeof (nm)); - r_buf_read_at (buf, off + sm.size + 4, (ut8 *)&nm2, sizeof (nm2)); - r_buf_read_at (buf, off + sm.size + 8, (ut8 *)&nm3, sizeof (nm3)); + rz_buf_read_at (buf, off + sm.size, (ut8 *)&nm, sizeof (nm)); + rz_buf_read_at (buf, off + sm.size + 4, (ut8 *)&nm2, sizeof (nm2)); + rz_buf_read_at (buf, off + sm.size + 8, (ut8 *)&nm3, sizeof (nm3)); // eprintf ("0x%x next %x %x %x\n", off + sm.size, nm, nm2, nm3); - if (r_read_le32 (&nm3) != 0xa1b22b1a) { + if (rz_read_le32 (&nm3) != 0xa1b22b1a) { sm.size -= 8; // is64 = true; } @@ -127,12 +127,12 @@ static void printSymbolsHeader(SymbolsHeader sh) { } eprintf ("\n"); // parse header - // eprintf ("0x%08x unknown 0x%x\n", 0x28, sh.unk0); //r_read_le32 (b+ 0x28)); - // eprintf ("0x%08x unknown 0x%x\n", 0x2c, sh.unk1); //r_read_le16 (b+ 0x2c)); - // eprintf ("0x%08x slotsize %d\n", 0x2e, sh.slotsize); // r_read_le16 (b+ 0x2e)); + // eprintf ("0x%08x unknown 0x%x\n", 0x28, sh.unk0); //rz_read_le32 (b+ 0x28)); + // eprintf ("0x%08x unknown 0x%x\n", 0x2c, sh.unk1); //rz_read_le16 (b+ 0x2c)); + // eprintf ("0x%08x slotsize %d\n", 0x2e, sh.slotsize); // rz_read_le16 (b+ 0x2e)); } -static RBinSection *bin_section_from_section(RCoreSymCacheElementSection *sect) { +static RBinSection *bin_section_from_section(RzCoreSymCacheElementSection *sect) { if (!sect->name) { return NULL; } @@ -140,7 +140,7 @@ static RBinSection *bin_section_from_section(RCoreSymCacheElementSection *sect) if (!s) { return NULL; } - s->name = r_str_ndup (sect->name, 256); + s->name = rz_str_ndup (sect->name, 256); s->size = sect->size; s->vsize = s->size; s->paddr = sect->paddr; @@ -151,7 +151,7 @@ static RBinSection *bin_section_from_section(RCoreSymCacheElementSection *sect) return s; } -static RBinSection *bin_section_from_segment(RCoreSymCacheElementSegment *seg) { +static RBinSection *bin_section_from_segment(RzCoreSymCacheElementSegment *seg) { if (!seg->name) { return NULL; } @@ -159,7 +159,7 @@ static RBinSection *bin_section_from_segment(RCoreSymCacheElementSegment *seg) { if (!s) { return NULL; } - s->name = r_str_ndup (seg->name, 16); + s->name = rz_str_ndup (seg->name, 16); s->size = seg->size; s->vsize = seg->vsize; s->paddr = seg->paddr; @@ -170,7 +170,7 @@ static RBinSection *bin_section_from_segment(RCoreSymCacheElementSegment *seg) { return s; } -static RBinSymbol *bin_symbol_from_symbol(RCoreSymCacheElement *element, RCoreSymCacheElementSymbol *s) { +static RBinSymbol *bin_symbol_from_symbol(RzCoreSymCacheElement *element, RzCoreSymCacheElementSymbol *s) { if (!s->name && !s->mangled_name) { return NULL; } @@ -185,7 +185,7 @@ static RBinSymbol *bin_symbol_from_symbol(RCoreSymCacheElement *element, RCoreSy sym->name = s->mangled_name; } sym->paddr = s->paddr; - sym->vaddr = r_coresym_cache_element_pa2va (element, s->paddr); + sym->vaddr = rz_coresym_cache_element_pa2va (element, s->paddr); sym->size = s->size; sym->type = R_BIN_TYPE_FUNC_STR; sym->bind = "NONE"; @@ -193,9 +193,9 @@ static RBinSymbol *bin_symbol_from_symbol(RCoreSymCacheElement *element, RCoreSy return sym; } -static RCoreSymCacheElement *parseDragons(RBinFile *bf, RBuffer *buf, int off, int bits) { +static RzCoreSymCacheElement *parseDragons(RBinFile *bf, RBuffer *buf, int off, int bits) { D eprintf ("Dragons at 0x%x\n", off); - ut64 size = r_buf_size (buf); + ut64 size = rz_buf_size (buf); if (off >= size) { return NULL; } @@ -207,9 +207,9 @@ static RCoreSymCacheElement *parseDragons(RBinFile *bf, RBuffer *buf, int off, i if (!b) { return NULL; } - int available = r_buf_read_at (buf, off, b, size); + int available = rz_buf_read_at (buf, off, b, size); if (available != size) { - eprintf ("Warning: r_buf_read_at failed\n"); + eprintf ("Warning: rz_buf_read_at failed\n"); return NULL; } #if 0 @@ -244,9 +244,9 @@ static RCoreSymCacheElement *parseDragons(RBinFile *bf, RBuffer *buf, int off, i } if (magicCombo != 2) { // hack for C22F7494 - available = r_buf_read_at (buf, off - 8, b, size); + available = rz_buf_read_at (buf, off - 8, b, size); if (available != size) { - eprintf ("Warning: r_buf_read_at failed\n"); + eprintf ("Warning: rz_buf_read_at failed\n"); return NULL; } if (!memcmp ("\x1a\x2b\xb2\xa1", b, 4)) { // 0x130 ? @@ -257,11 +257,11 @@ static RCoreSymCacheElement *parseDragons(RBinFile *bf, RBuffer *buf, int off, i } D eprintf ("0x%08x magic OK\n", off); D { - const int e0ss = r_read_le32 (b + 12); + const int e0ss = rz_read_le32 (b + 12); eprintf ("0x%08x eoss 0x%x\n", off + 12, e0ss); } free (b); - return r_coresym_cache_element_new (bf, buf, off + 16, bits); + return rz_coresym_cache_element_new (bf, buf, off + 16, bits); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { @@ -291,7 +291,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } printSymbolsHeader (sh); SymbolsMetadata sm = parseMetadata (buf, 0x40); - RCoreSymCacheElement *element = parseDragons (bf, buf, sm.addr + sm.size, sm.bits); + RzCoreSymCacheElement *element = parseDragons (bf, buf, sm.addr + sm.size, sm.bits); if (element) { *bin_obj = element; return true; @@ -299,23 +299,23 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd return false; } -static RList *sections(RBinFile *bf) { - RList *res = r_list_newf ((RListFree)r_bin_section_free); - r_return_val_if_fail (res && bf->o && bf->o->bin_obj, res); - RCoreSymCacheElement *element = bf->o->bin_obj; +static RzList *sections(RBinFile *bf) { + RzList *res = rz_list_newf ((RzListFree)rz_bin_section_free); + rz_return_val_if_fail (res && bf->o && bf->o->bin_obj, res); + RzCoreSymCacheElement *element = bf->o->bin_obj; size_t i; for (i = 0; i < element->hdr->n_segments; i++) { - RCoreSymCacheElementSegment *seg = &element->segments[i]; + RzCoreSymCacheElementSegment *seg = &element->segments[i]; RBinSection *s = bin_section_from_segment (seg); if (s) { - r_list_append (res, s); + rz_list_append (res, s); } } for (i = 0; i < element->hdr->n_sections; i++) { - RCoreSymCacheElementSection *sect = &element->sections[i]; + RzCoreSymCacheElementSection *sect = &element->sections[i]; RBinSection *s = bin_section_from_section (sect); if (s) { - r_list_append (res, s); + rz_list_append (res, s); } } return res; @@ -345,14 +345,14 @@ static RBinInfo *info(RBinFile *bf) { static bool check_buffer(RBuffer *b) { ut8 buf[4]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); return !memcmp (buf, "\x02\xff\x01\xff", 4); } -static RList *symbols(RBinFile *bf) { - RList *res = r_list_newf ((RListFree)r_bin_symbol_free); - r_return_val_if_fail (res && bf->o && bf->o->bin_obj, res); - RCoreSymCacheElement *element = bf->o->bin_obj; +static RzList *symbols(RBinFile *bf) { + RzList *res = rz_list_newf ((RzListFree)rz_bin_symbol_free); + rz_return_val_if_fail (res && bf->o && bf->o->bin_obj, res); + RzCoreSymCacheElement *element = bf->o->bin_obj; size_t i; HtUU *hash = ht_uu_new0 (); if (!hash) { @@ -360,26 +360,26 @@ static RList *symbols(RBinFile *bf) { } bool found = false; for (i = 0; i < element->hdr->n_lined_symbols; i++) { - RCoreSymCacheElementSymbol *sym = (RCoreSymCacheElementSymbol *)&element->lined_symbols[i]; + RzCoreSymCacheElementSymbol *sym = (RzCoreSymCacheElementSymbol *)&element->lined_symbols[i]; ht_uu_find (hash, sym->paddr, &found); if (found) { continue; } RBinSymbol *s = bin_symbol_from_symbol (element, sym); if (s) { - r_list_append (res, s); + rz_list_append (res, s); ht_uu_insert (hash, sym->paddr, 1); } } for (i = 0; i < element->hdr->n_symbols; i++) { - RCoreSymCacheElementSymbol *sym = &element->symbols[i]; + RzCoreSymCacheElementSymbol *sym = &element->symbols[i]; ht_uu_find (hash, sym->paddr, &found); if (found) { continue; } RBinSymbol *s = bin_symbol_from_symbol (element, sym); if (s) { - r_list_append (res, s); + rz_list_append (res, s); } } ht_uu_free (hash); @@ -391,13 +391,13 @@ static ut64 size(RBinFile *bf) { } static void destroy(RBinFile *bf) { - r_coresym_cache_element_free (bf->o->bin_obj); + rz_coresym_cache_element_free (bf->o->bin_obj); } static void header(RBinFile *bf) { - r_return_if_fail (bf && bf->o); + rz_return_if_fail (bf && bf->o); - RCoreSymCacheElement *element = bf->o->bin_obj; + RzCoreSymCacheElement *element = bf->o->bin_obj; if (!element) { return; } @@ -419,7 +419,7 @@ static void header(RBinFile *bf) { pj_ks (pj, "version", element->binary_version); } char uuidstr[R_UUID_LENGTH]; - r_hex_bin2str (element->hdr->uuid, 16, uuidstr); + rz_hex_bin2str (element->hdr->uuid, 16, uuidstr); pj_ks (pj, "uuid", uuidstr); pj_kn (pj, "segments", element->hdr->n_segments); pj_kn (pj, "sections", element->hdr->n_sections); @@ -432,7 +432,7 @@ static void header(RBinFile *bf) { pj_free (pj); } -RBinPlugin r_bin_plugin_symbols = { +RBinPlugin rz_bin_plugin_symbols = { .name = "symbols", .desc = "Apple Symbols file", .license = "MIT", @@ -448,9 +448,9 @@ RBinPlugin r_bin_plugin_symbols = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_symbols, + .data = &rz_bin_plugin_symbols, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_te.c b/librz/bin/p/bin_te.c similarity index 68% rename from libr/bin/p/bin_te.c rename to librz/bin/p/bin_te.c index fe80f345b0..0f5e8d1722 100644 --- a/libr/bin/p/bin_te.c +++ b/librz/bin/p/bin_te.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2013-2019 - xvilka */ -#include -#include -#include -#include +#include +#include +#include +#include #include "te/te_specs.h" #include "te/te.h" @@ -12,17 +12,17 @@ static Sdb *get_sdb(RBinFile *bf) { if (!o) { return NULL; } - struct r_bin_te_obj_t *bin = (struct r_bin_te_obj_t *) o->bin_obj; + struct rz_bin_te_obj_t *bin = (struct rz_bin_te_obj_t *) o->bin_obj; return bin? bin->kv: NULL; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && bin_obj && b, false); - ut64 sz = r_buf_size (b); + rz_return_val_if_fail (bf && bin_obj && b, false); + ut64 sz = rz_buf_size (b); if (sz == 0 || sz == UT64_MAX) { return false; } - struct r_bin_te_obj_t *res = r_bin_te_new_buf (b); + struct rz_bin_te_obj_t *res = rz_bin_te_new_buf (b); if (res) { sdb_ns_set (sdb, "info", res->kv); } @@ -31,11 +31,11 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, } static void destroy(RBinFile *bf) { - r_bin_te_free ((struct r_bin_te_obj_t *) bf->o->bin_obj); + rz_bin_te_free ((struct rz_bin_te_obj_t *) bf->o->bin_obj); } static ut64 baddr(RBinFile *bf) { - return r_bin_te_get_image_base (bf->o->bin_obj); + return rz_bin_te_get_image_base (bf->o->bin_obj); } static RBinAddr *binsym(RBinFile *bf, int type) { @@ -45,22 +45,22 @@ static RBinAddr *binsym(RBinFile *bf, int type) { if (!(ret = R_NEW (RBinAddr))) { return NULL; } - ret->paddr = ret->vaddr = r_bin_te_get_main_paddr (bf->o->bin_obj); + ret->paddr = ret->vaddr = rz_bin_te_get_main_paddr (bf->o->bin_obj); break; } return ret; } -static RList *entries(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList *entries(RBinFile *bf) { + RzList *ret = rz_list_newf (free); if (ret) { - RBinAddr *entry = r_bin_te_get_entrypoint (bf->o->bin_obj); + RBinAddr *entry = rz_bin_te_get_entrypoint (bf->o->bin_obj); if (entry) { RBinAddr *ptr = R_NEW0 (RBinAddr); if (ptr) { ptr->paddr = entry->paddr; ptr->vaddr = entry->vaddr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (entry); } @@ -68,17 +68,17 @@ static RList *entries(RBinFile *bf) { return ret; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinSection *ptr = NULL; - struct r_bin_te_section_t *sections = NULL; + struct rz_bin_te_section_t *sections = NULL; int i; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; - if (!(sections = r_bin_te_get_sections (bf->o->bin_obj))) { + if (!(sections = rz_bin_te_get_sections (bf->o->bin_obj))) { free (ret); return NULL; } @@ -110,7 +110,7 @@ static RList *sections(RBinFile *bf) { if (!strncmp (ptr->name, "_TEXT_RE", 8)) { ptr->bits = R_SYS_BITS_16; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (sections); return ret; @@ -124,12 +124,12 @@ static RBinInfo *info(RBinFile *bf) { ret->file = strdup (bf->file); ret->bclass = strdup ("TE"); ret->rclass = strdup ("te"); - ret->os = r_bin_te_get_os (bf->o->bin_obj); - ret->arch = r_bin_te_get_arch (bf->o->bin_obj); - ret->machine = r_bin_te_get_machine (bf->o->bin_obj); - ret->subsystem = r_bin_te_get_subsystem (bf->o->bin_obj); + ret->os = rz_bin_te_get_os (bf->o->bin_obj); + ret->arch = rz_bin_te_get_arch (bf->o->bin_obj); + ret->machine = rz_bin_te_get_machine (bf->o->bin_obj); + ret->subsystem = rz_bin_te_get_subsystem (bf->o->bin_obj); ret->type = strdup ("EXEC (Executable file)"); - ret->bits = r_bin_te_get_bits (bf->o->bin_obj); + ret->bits = rz_bin_te_get_bits (bf->o->bin_obj); ret->big_endian = 1; ret->dbg_info = 0; ret->has_va = true; @@ -141,13 +141,13 @@ static RBinInfo *info(RBinFile *bf) { static bool check_buffer(RBuffer *b) { ut8 buf[2]; - if (r_buf_read_at (b, 0, buf, 2) == 2) { + if (rz_buf_read_at (b, 0, buf, 2) == 2) { return !memcmp (buf, "\x56\x5a", 2); } return false; } -RBinPlugin r_bin_plugin_te = { +RBinPlugin rz_bin_plugin_te = { .name = "te", .desc = "TE bin plugin", // Terse Executable format .license = "LGPL3", @@ -164,9 +164,9 @@ RBinPlugin r_bin_plugin_te = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_te, + .data = &rz_bin_plugin_te, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_vsf.c b/librz/bin/p/bin_vsf.c similarity index 81% rename from libr/bin/p/bin_vsf.c rename to librz/bin/p/bin_vsf.c index 888f642220..12843e0da8 100644 --- a/libr/bin/p/bin_vsf.c +++ b/librz/bin/p/bin_vsf.c @@ -2,7 +2,7 @@ /* VICE Snapshot File loader: http://vice-emu.sourceforge.net/ */ -#include +#include #include "vsf/vsf_specs.h" static const char VICE_MAGIC[] = "VICE Snapshot File\032"; @@ -19,20 +19,20 @@ static const struct { const int offset_mem; const int ram_size; } _machines[] = { - {"C64", "Commodore 64", r_offsetof(struct vsf_c64mem, ram), 64 * 1024}, - {"C128", "Commodore 128", r_offsetof(struct vsf_c128mem, ram), 128 * 1024}, + {"C64", "Commodore 64", rz_offsetof(struct vsf_c64mem, ram), 64 * 1024}, + {"C128", "Commodore 128", rz_offsetof(struct vsf_c128mem, ram), 128 * 1024}, }; static const int MACHINES_MAX = sizeof(_machines) / sizeof(_machines[0]); static Sdb* get_sdb (RBinFile *bf) { - r_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); - struct r_bin_vsf_obj* bin = (struct r_bin_vsf_obj*) bf->o->bin_obj; + rz_return_val_if_fail (bf && bf->o && bf->o->bin_obj, NULL); + struct rz_bin_vsf_obj* bin = (struct rz_bin_vsf_obj*) bf->o->bin_obj; return bin->kv; } static bool check_buffer(RBuffer *b) { ut8 magic[VICE_MAGIC_LEN]; - if (r_buf_read_at (b, 0, magic, VICE_MAGIC_LEN) == VICE_MAGIC_LEN) { + if (rz_buf_read_at (b, 0, magic, VICE_MAGIC_LEN) == VICE_MAGIC_LEN) { return !memcmp (magic, VICE_MAGIC, VICE_MAGIC_LEN); } return false; @@ -41,19 +41,19 @@ static bool check_buffer(RBuffer *b) { // XXX b vs bf->buf static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { ut64 offset = 0; - struct r_bin_vsf_obj* res = NULL; + struct rz_bin_vsf_obj* res = NULL; if (check_buffer (bf->buf)) { int i = 0; - if (!(res = R_NEW0 (struct r_bin_vsf_obj))) { + if (!(res = R_NEW0 (struct rz_bin_vsf_obj))) { return false; } - offset = r_offsetof(struct vsf_hdr, machine); + offset = rz_offsetof(struct vsf_hdr, machine); if (offset > bf->size) { free (res); return false; } char machine[20]; - int l = r_buf_read_at (bf->buf, offset, (ut8 *)machine, sizeof (machine)); + int l = rz_buf_read_at (bf->buf, offset, (ut8 *)machine, sizeof (machine)); if (l < 0) { free (res); return false; @@ -75,10 +75,10 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, } // read all VSF modules offset = sizeof (struct vsf_hdr); - ut64 sz = r_buf_size (bf->buf); + ut64 sz = rz_buf_size (bf->buf); while (offset < sz) { struct vsf_module module; - int read = r_buf_fread_at (bf->buf, offset, (ut8*)&module, "16ccci", 1); + int read = rz_buf_fread_at (bf->buf, offset, (ut8*)&module, "16ccci", 1); if (read != sizeof(module)) { eprintf ("Truncated Header\n"); free (res); @@ -95,7 +95,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, res->rom = offset + read; } else if (!CMP_MODULE (VICE_MAINCPU) && module.major == 1) { res->maincpu = R_NEW (struct vsf_maincpu); - r_buf_read_at (bf->buf, offset + read, (ut8 *)res->maincpu, sizeof (*res->maincpu)); + rz_buf_read_at (bf->buf, offset + read, (ut8 *)res->maincpu, sizeof (*res->maincpu)); } #undef CMP_MODULE offset += module.length; @@ -113,39 +113,39 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, return true; } -static RList *mem(RBinFile *bf) { +static RzList *mem(RBinFile *bf) { // FIXME: What does Mem do? Should I remove it ? - struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) bf->o->bin_obj; + struct rz_bin_vsf_obj* vsf_obj = (struct rz_bin_vsf_obj*) bf->o->bin_obj; if (!vsf_obj) { return NULL; } - RList *ret; + RzList *ret; RBinMem *m; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; if (!(m = R_NEW0 (RBinMem))) { - r_list_free (ret); + rz_list_free (ret); return NULL; } m->name = strdup ("RAM"); m->addr = 0; // start address m->size = _machines[vsf_obj->machine_idx].ram_size; - m->perms = r_str_rwx ("rwx"); - r_list_append (ret, m); + m->perms = rz_str_rwx ("rwx"); + rz_list_append (ret, m); return ret; } -static RList* sections(RBinFile* bf) { - struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) bf->o->bin_obj; +static RzList* sections(RBinFile* bf) { + struct rz_bin_vsf_obj* vsf_obj = (struct rz_bin_vsf_obj*) bf->o->bin_obj; if (!vsf_obj) { return NULL; } - RList *ret = NULL; + RzList *ret = NULL; RBinSection *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } const int m_idx = vsf_obj->machine_idx; @@ -161,26 +161,26 @@ static RList* sections(RBinFile* bf) { return ret; } ptr->name = strdup ("BASIC"); - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c64rom, basic); + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c64rom, basic); ptr->size = 1024 * 8; // (8k) ptr->vaddr = 0xa000; ptr->vsize = 1024 * 8; // BASIC size (8k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // KERNAL (0xe000 - 0xffff) if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("KERNAL"); - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c64rom, kernal); + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c64rom, kernal); ptr->size = 1024 * 8; // (8k) ptr->vaddr = 0xe000; ptr->vsize = 1024 * 8; // KERNAL size (8k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // CHARGEN section ignored } else { @@ -190,13 +190,13 @@ static RList* sections(RBinFile* bf) { return ret; } ptr->name = strdup ("BASIC"); - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c128rom, basic); + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c128rom, basic); ptr->size = 1024 * 28; // (28k) ptr->vaddr = 0x4000; ptr->vsize = 1024 * 28; // BASIC size (28k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // MONITOR (0xb000 - 0xbfff) if (!(ptr = R_NEW0 (RBinSection))) { @@ -204,39 +204,39 @@ static RList* sections(RBinFile* bf) { } ptr->name = strdup ("MONITOR"); // skip first 28kb since "BASIC" and "MONITOR" share the same section in VSF - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c128rom, basic) + 1024 * 28; + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c128rom, basic) + 1024 * 28; ptr->size = 1024 * 4; // (4k) ptr->vaddr = 0xb000; ptr->vsize = 1024 * 4; // BASIC size (4k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // EDITOR (0xc000 - 0xcfff) if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("EDITOR"); - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c128rom, editor); + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c128rom, editor); ptr->size = 1024 * 4; // (4k) ptr->vaddr = 0xc000; ptr->vsize = 1024 * 4; // BASIC size (4k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // KERNAL (0xe000 - 0xffff) if (!(ptr = R_NEW0 (RBinSection))) { return ret; } ptr->name = strdup ("KERNAL"); - ptr->paddr = vsf_obj->rom + r_offsetof (struct vsf_c128rom, kernal); + ptr->paddr = vsf_obj->rom + rz_offsetof (struct vsf_c128rom, kernal); ptr->size = 1024 * 8; // (8k) ptr->vaddr = 0xe000; ptr->vsize = 1024 * 8; // KERNAL size (8k) ptr->perm = R_PERM_RX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // CHARGEN section ignored } @@ -257,7 +257,7 @@ static RList* sections(RBinFile* bf) { ptr->vsize = size; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } else { // RAM C128 (0x0000 - 0xffff): Bank 0 // RAM C128 (0x0000 - 0xffff): Bank 1 @@ -274,7 +274,7 @@ static RList* sections(RBinFile* bf) { ptr->vsize = size; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); if (!(ptr = R_NEW0 (RBinSection))) { return ret; @@ -286,7 +286,7 @@ static RList* sections(RBinFile* bf) { ptr->vsize = size; ptr->perm = R_PERM_RWX; ptr->add = true; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } } @@ -295,7 +295,7 @@ static RList* sections(RBinFile* bf) { static RBinInfo* info(RBinFile *bf) { - struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) bf->o->bin_obj; + struct rz_bin_vsf_obj* vsf_obj = (struct rz_bin_vsf_obj*) bf->o->bin_obj; if (!vsf_obj) { return NULL; } @@ -305,7 +305,7 @@ static RBinInfo* info(RBinFile *bf) { RBinInfo *ret = NULL; struct vsf_hdr hdr; memset (&hdr, 0, sizeof(hdr)); - int read = r_buf_read_at (bf->buf, 0, (ut8*)&hdr, sizeof(hdr)); + int read = rz_buf_read_at (bf->buf, 0, (ut8*)&hdr, sizeof(hdr)); if (read != sizeof(hdr)) { eprintf ("Truncated Header\n"); return NULL; @@ -337,7 +337,7 @@ static RBinInfo* info(RBinFile *bf) { return ret; } -static RList* symbols(RBinFile *bf) { +static RzList* symbols(RBinFile *bf) { static const struct { const ut16 address; @@ -371,7 +371,7 @@ static RList* symbols(RBinFile *bf) { {0xd017, "VIC_SPR_EXP_Y"}, {0xd01d, "VIC_SPR_EXP_X"}, {0xd01c, "VIC_SPR_MCOLOR"}, - {0xd01b, "VIC_SPR_BG_PRIO"}, + {0xd01b, "VIC_SPR_BG_PRzIO"}, {0xd025, "VIC_SPR_MCOLOR0"}, {0xd026, "VIC_SPR_MCOLOR1"}, @@ -472,15 +472,15 @@ static RList* symbols(RBinFile *bf) { {0xDD0F, "CIA2_CRB"}, }; static const int SYMBOLS_MAX = sizeof(_symbols) / sizeof(_symbols[0]); - struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) bf->o->bin_obj; + struct rz_bin_vsf_obj* vsf_obj = (struct rz_bin_vsf_obj*) bf->o->bin_obj; if (!vsf_obj) { return NULL; } const int m_idx = vsf_obj->machine_idx; int offset = _machines[m_idx].offset_mem; - RList *ret = NULL; + RzList *ret = NULL; RBinSymbol *ptr; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } ret->free = free; @@ -499,28 +499,28 @@ static RList* symbols(RBinFile *bf) { ptr->size = 2; ptr->paddr = vsf_obj->mem + offset + _symbols[i].address; ptr->ordinal = i; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } static void destroy(RBinFile *bf) { - struct r_bin_vsf_obj *obj = (struct r_bin_vsf_obj *)bf->o->bin_obj; + struct rz_bin_vsf_obj *obj = (struct rz_bin_vsf_obj *)bf->o->bin_obj; free (obj->maincpu); free (obj); } -static RList* entries(RBinFile *bf) { - struct r_bin_vsf_obj* vsf_obj = (struct r_bin_vsf_obj*) bf->o->bin_obj; +static RzList* entries(RBinFile *bf) { + struct rz_bin_vsf_obj* vsf_obj = (struct rz_bin_vsf_obj*) bf->o->bin_obj; if (!vsf_obj) { return NULL; } const int m_idx = vsf_obj->machine_idx; - RList *ret; + RzList *ret; RBinAddr *ptr = NULL; - if (!(ret = r_list_new ())) { + if (!(ret = rz_list_new ())) { return NULL; } int offset = _machines[m_idx].offset_mem; @@ -530,19 +530,19 @@ static RList* entries(RBinFile *bf) { } ptr->paddr = vsf_obj->mem + offset; ptr->vaddr = vsf_obj->maincpu ? vsf_obj->maincpu->pc : 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); // IRQ: 0xFFFE or 0x0314 ? // if (!(ptr = R_NEW0 (RBinAddr))) // return ret; // ptr->paddr = (vsf_obj->mem + offset) - (void*) bf->buf->buf; // ptr->vaddr = 0x314; // or 0xfffe ? -// r_list_append (ret, ptr); +// rz_list_append (ret, ptr); return ret; } -RBinPlugin r_bin_plugin_vsf = { +RBinPlugin rz_bin_plugin_vsf = { .name = "vsf", .desc = "VICE Snapshot File", .license = "LGPL3", @@ -558,9 +558,9 @@ RBinPlugin r_bin_plugin_vsf = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_vsf, + .data = &rz_bin_plugin_vsf, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_wasm.c b/librz/bin/p/bin_wasm.c similarity index 68% rename from libr/bin/p/bin_wasm.c rename to librz/bin/p/bin_wasm.c index 09833157d1..6e05510501 100644 --- a/libr/bin/p/bin_wasm.c +++ b/librz/bin/p/bin_wasm.c @@ -1,18 +1,18 @@ -/* radare2 - LGPL - Copyright 2017-2019 - pancake, cgvwzq */ +/* rizin - LGPL - Copyright 2017-2019 - pancake, cgvwzq */ // http://webassembly.org/docs/binary-encoding/#module-structure -#include -#include -#include -#include +#include +#include +#include +#include #include "wasm/wasm.h" #include "../format/wasm/wasm.h" static bool check_buffer (RBuffer *rbuf) { ut8 buf[4] = { 0 }; - return rbuf && r_buf_read_at (rbuf, 0, buf, 4) == 4 && !memcmp (buf, R_BIN_WASM_MAGIC_BYTES, 4); + return rbuf && rz_buf_read_at (rbuf, 0, buf, 4) == 4 && !memcmp (buf, R_BIN_WASM_MAGIC_BYTES, 4); } static bool find_export (const ut32 *p, const RBinWasmExportEntry *q) { @@ -23,17 +23,17 @@ static bool find_export (const ut32 *p, const RBinWasmExportEntry *q) { } static bool load_buffer (RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_return_val_if_fail (bf && buf && r_buf_size (buf) != UT64_MAX, NULL); + rz_return_val_if_fail (bf && buf && rz_buf_size (buf) != UT64_MAX, NULL); if (check_buffer (buf)) { - *bin_obj = r_bin_wasm_init (bf, buf); + *bin_obj = rz_bin_wasm_init (bf, buf); return true; } return false; } static void destroy (RBinFile *bf) { - r_bin_wasm_destroy (bf); + rz_bin_wasm_destroy (bf); } static ut64 baddr (RBinFile *bf) { @@ -44,62 +44,62 @@ static RBinAddr *binsym (RBinFile *bf, int type) { return NULL; // TODO } -static RList *sections (RBinFile *bf); +static RzList *sections (RBinFile *bf); -static RList *entries (RBinFile *bf) { +static RzList *entries (RBinFile *bf) { RBinWasmObj *bin = bf && bf->o ? bf->o->bin_obj : NULL; // TODO - RList *ret = NULL; + RzList *ret = NULL; RBinAddr *ptr = NULL; ut64 addr = 0x0; - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } - addr = (ut64)r_bin_wasm_get_entrypoint (bin); + addr = (ut64)rz_bin_wasm_get_entrypoint (bin); if (!addr) { - RList *codes = r_bin_wasm_get_codes (bin); + RzList *codes = rz_bin_wasm_get_codes (bin); if (codes) { - RListIter *iter; + RzListIter *iter; RBinWasmCodeEntry *func; - r_list_foreach (codes, iter, func) { + rz_list_foreach (codes, iter, func) { addr = func->code; break; } } if (!addr) { - r_list_free (ret); + rz_list_free (ret); return NULL; } } if ((ptr = R_NEW0 (RBinAddr))) { ptr->paddr = addr; ptr->vaddr = addr; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *sections (RBinFile *bf) { +static RzList *sections (RBinFile *bf) { RBinWasmObj *bin = bf && bf->o ? bf->o->bin_obj : NULL; - RList *ret = NULL; - RList *secs = NULL; + RzList *ret = NULL; + RzList *secs = NULL; RBinSection *ptr = NULL; RBinWasmSection *sec; - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } - if (!(secs = r_bin_wasm_get_sections (bin))) { - r_list_free (ret); + if (!(secs = rz_bin_wasm_get_sections (bin))) { + rz_list_free (ret); return NULL; } - RListIter *iter; - r_list_foreach (secs, iter, sec) { + RzListIter *iter; + rz_list_foreach (secs, iter, sec) { if (!(ptr = R_NEW0 (RBinSection))) { - r_list_free (secs); - r_list_free (ret); + rz_list_free (secs); + rz_list_free (ret); return NULL; } ptr->name = strdup ((char *)sec->name); @@ -113,30 +113,30 @@ static RList *sections (RBinFile *bf) { ptr->add = true; // TODO permissions ptr->perm = 0; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *symbols (RBinFile *bf) { +static RzList *symbols (RBinFile *bf) { RBinWasmObj *bin = NULL; - RList *ret = NULL, *codes = NULL, *imports = NULL, *exports = NULL; + RzList *ret = NULL, *codes = NULL, *imports = NULL, *exports = NULL; RBinSymbol *ptr = NULL; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } bin = bf->o->bin_obj; - if (!(ret = r_list_newf ((RListFree)free))) { + if (!(ret = rz_list_newf ((RzListFree)free))) { return NULL; } - if (!(codes = r_bin_wasm_get_codes (bin))) { + if (!(codes = rz_bin_wasm_get_codes (bin))) { goto bad_alloc; } - if (!(imports = r_bin_wasm_get_imports (bin))) { + if (!(imports = rz_bin_wasm_get_imports (bin))) { goto bad_alloc; } - if (!(exports = r_bin_wasm_get_exports (bin))) { + if (!(exports = rz_bin_wasm_get_exports (bin))) { goto bad_alloc; } @@ -147,8 +147,8 @@ static RList *symbols (RBinFile *bf) { ut32 i = 0; RBinWasmImportEntry *imp; - RListIter *iter; - r_list_foreach (imports, iter, imp) { + RzListIter *iter; + rz_list_foreach (imports, iter, imp) { if (!(ptr = R_NEW0 (RBinSymbol))) { goto bad_alloc; } @@ -180,28 +180,28 @@ static RList *symbols (RBinFile *bf) { ptr->paddr = -1; ptr->ordinal = i; i += 1; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } - RListIter *is_exp = NULL; + RzListIter *is_exp = NULL; RBinWasmCodeEntry *func; // RBinWasmExportEntry *export = NULL; - r_list_foreach (codes, iter, func) { + rz_list_foreach (codes, iter, func) { if (!(ptr = R_NEW0 (RBinSymbol))) { goto bad_alloc; } - const char *fcn_name = r_bin_wasm_get_function_name (bin, fcn_idx); + const char *fcn_name = rz_bin_wasm_get_function_name (bin, fcn_idx); if (fcn_name) { ptr->name = strdup (fcn_name); - is_exp = r_list_find (exports, &fcn_idx, (RListComparator)find_export); + is_exp = rz_list_find (exports, &fcn_idx, (RzListComparator)find_export); if (is_exp) { ptr->bind = R_BIN_BIND_GLOBAL_STR; } } else { // fallback if symbol is not found. - ptr->name = r_str_newf ("fcn.%d", fcn_idx); + ptr->name = rz_str_newf ("fcn.%d", fcn_idx); } ptr->forwarder = "NONE"; @@ -215,40 +215,40 @@ static RList *symbols (RBinFile *bf) { ptr->ordinal = i; i++; fcn_idx++; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } // TODO: globals, tables and memories return ret; bad_alloc: // not so sure if imports should be freed. - r_list_free (exports); - r_list_free (codes); - r_list_free (ret); + rz_list_free (exports); + rz_list_free (codes); + rz_list_free (ret); return NULL; } -static RList *imports (RBinFile *bf) { +static RzList *imports (RBinFile *bf) { RBinWasmObj *bin = NULL; - RList *imports = NULL; + RzList *imports = NULL; RBinImport *ptr = NULL; - RList *ret = NULL; + RzList *ret = NULL; if (!bf || !bf->o || !bf->o->bin_obj) { return NULL; } bin = bf->o->bin_obj; - if (!(ret = r_list_newf (r_bin_import_free))) { + if (!(ret = rz_list_newf (rz_bin_import_free))) { return NULL; } - if (!(imports = r_bin_wasm_get_imports (bin))) { + if (!(imports = rz_bin_wasm_get_imports (bin))) { goto bad_alloc; } RBinWasmImportEntry *import = NULL; ut32 i = 0; - RListIter *iter; - r_list_foreach (imports, iter, import) { + RzListIter *iter; + rz_list_foreach (imports, iter, import) { if (!(ptr = R_NEW0 (RBinImport))) { goto bad_alloc; } @@ -270,16 +270,16 @@ static RList *imports (RBinFile *bf) { ptr->type = "GLOBAL"; break; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; bad_alloc: - r_list_free (imports); - r_list_free (ret); + rz_list_free (imports); + rz_list_free (ret); return NULL; } -static RList *libs (RBinFile *bf) { +static RzList *libs (RBinFile *bf) { return NULL; } @@ -308,14 +308,14 @@ static ut64 size (RBinFile *bf) { if (!bf || !bf->buf) { return 0; } - return r_buf_size (bf->buf); + return rz_buf_size (bf->buf); } /* inspired in http://www.phreedom.org/solar/code/tinype/tiny.97/tiny.asm */ static RBuffer *create (RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt) { - RBuffer *buf = r_buf_new (); -#define B(x, y) r_buf_append_bytes (buf, (const ut8 *)(x), y) -#define D(x) r_buf_append_ut32 (buf, x) + RBuffer *buf = rz_buf_new (); +#define B(x, y) rz_buf_append_bytes (buf, (const ut8 *)(x), y) +#define D(x) rz_buf_append_ut32 (buf, x) B ("\x00" "asm", 4); @@ -323,7 +323,7 @@ static RBuffer *create (RBin *bin, const ut8 *code, int codelen, const ut8 *data return buf; } -RBinPlugin r_bin_plugin_wasm = { +RBinPlugin rz_bin_plugin_wasm = { .name = "wasm", .desc = "WebAssembly bin plugin", .license = "MIT", @@ -343,9 +343,9 @@ RBinPlugin r_bin_plugin_wasm = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_wasm, + .data = &rz_bin_plugin_wasm, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_write_elf.c b/librz/bin/p/bin_write_elf.c similarity index 86% rename from libr/bin/p/bin_write_elf.c rename to librz/bin/p/bin_write_elf.c index 92e8f90099..e89694f267 100644 --- a/libr/bin/p/bin_write_elf.c +++ b/librz/bin/p/bin_write_elf.c @@ -2,7 +2,7 @@ #include "bin_write_elf.inc" -RBinWrite r_bin_write_elf = { +RBinWrite rz_bin_write_elf = { .scn_resize = &scn_resize, .scn_perms = &scn_perms, .rpath_del = &rpath_del, diff --git a/libr/bin/p/bin_write_elf.inc b/librz/bin/p/bin_write_elf.inc similarity index 55% rename from libr/bin/p/bin_write_elf.inc rename to librz/bin/p/bin_write_elf.inc index 5c252962b8..1724df42f0 100644 --- a/libr/bin/p/bin_write_elf.inc +++ b/librz/bin/p/bin_write_elf.inc @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include -#include +#include +#include #include "elf/elf.h" static ut64 scn_resize(RBinFile *bf, const char *name, ut64 size) { - return Elf_(r_bin_elf_resize_section) (bf, name, size); + return Elf_(rz_bin_elf_resize_section) (bf, name, size); } static bool scn_perms(RBinFile *bf, const char *name, int perms) { - return Elf_(r_bin_elf_section_perms) (bf, name, perms); + return Elf_(rz_bin_elf_section_perms) (bf, name, perms); } static int rpath_del(RBinFile *bf) { - return Elf_(r_bin_elf_del_rpath) (bf); + return Elf_(rz_bin_elf_del_rpath) (bf); } static bool chentry(RBinFile *bf, ut64 addr) { - return Elf_(r_bin_elf_entry_write) (bf, addr); + return Elf_(rz_bin_elf_entry_write) (bf, addr); } diff --git a/libr/bin/p/bin_write_elf64.c b/librz/bin/p/bin_write_elf64.c similarity index 86% rename from libr/bin/p/bin_write_elf64.c rename to librz/bin/p/bin_write_elf64.c index b94b17aeda..d5526952c6 100644 --- a/libr/bin/p/bin_write_elf64.c +++ b/librz/bin/p/bin_write_elf64.c @@ -3,7 +3,7 @@ #define R_BIN_ELF64 1 #include "bin_write_elf.inc" -RBinWrite r_bin_write_elf64 = { +RBinWrite rz_bin_write_elf64 = { .scn_resize = &scn_resize, .scn_perms = &scn_perms, .rpath_del = &rpath_del, diff --git a/libr/bin/p/bin_write_mach0.c b/librz/bin/p/bin_write_mach0.c similarity index 72% rename from libr/bin/p/bin_write_mach0.c rename to librz/bin/p/bin_write_mach0.c index 6e6ae37ca9..16124e715b 100644 --- a/libr/bin/p/bin_write_mach0.c +++ b/librz/bin/p/bin_write_mach0.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016-2019 - pancake */ -#include -#include +#include +#include #include "mach0/mach0.h" typedef struct machoPointers_t { @@ -24,14 +24,14 @@ static MachoPointers findLastCommand(RBinFile *bf) { for (i = 0, off = 0x20 + bin->header_at; i < mp.ncmds; i++) { ut32 loadc[2] = {0}; - r_buf_read_at (bin->b, off, (ut8*)&loadc, sizeof (loadc)); - //r_buf_seek (bin->b, off, R_BUF_SET); - int len = loadc[1]; // r_buf_read_le32 (loadc[1]); // bin->b); // + rz_buf_read_at (bin->b, off, (ut8*)&loadc, sizeof (loadc)); + //rz_buf_seek (bin->b, off, R_BUF_SET); + int len = loadc[1]; // rz_buf_read_le32 (loadc[1]); // bin->b); // if (len < 1) { eprintf ("Error: read (lc) at 0x%08"PFMT64x"\n", off); break; } - int size = r_read_ble32 (&loadc[1], bin->big_endian); + int size = rz_read_ble32 (&loadc[1], bin->big_endian); off += size; } mp.lastcmd_off = off; @@ -52,10 +52,10 @@ static bool MACH0_(write_addlib)(RBinFile *bf, const char *lib) { size_t size_of_lib = 56; ut32 ncmds = mp.ncmds + 1; - r_buf_write_at (bf->buf, mp.ncmds_off, (const ut8*)&ncmds, sizeof (ncmds)); + rz_buf_write_at (bf->buf, mp.ncmds_off, (const ut8*)&ncmds, sizeof (ncmds)); ut32 sizeofcmds = mp.sizeofcmds + size_of_lib; // , &ncmds, sizeof (ncmds)); - r_buf_write_at (bf->buf, mp.sizeofcmds_off, (ut8*)&sizeofcmds, sizeof (sizeofcmds)); + rz_buf_write_at (bf->buf, mp.sizeofcmds_off, (ut8*)&sizeofcmds, sizeof (sizeofcmds)); size_t lib_len = strlen (lib); if (lib_len > 22) { @@ -65,9 +65,9 @@ static bool MACH0_(write_addlib)(RBinFile *bf, const char *lib) { } const size_t sample_dylib_name_off = 24; - r_buf_write_at (bf->buf, mp.lastcmd_off, sample_dylib, 56); - r_buf_write_at (bf->buf, mp.lastcmd_off + 4, (const ut8*)&size_of_lib, 4); - r_buf_write_at (bf->buf, mp.lastcmd_off + sample_dylib_name_off, (const ut8*)lib, lib_len + 1); + rz_buf_write_at (bf->buf, mp.lastcmd_off, sample_dylib, 56); + rz_buf_write_at (bf->buf, mp.lastcmd_off + 4, (const ut8*)&size_of_lib, 4); + rz_buf_write_at (bf->buf, mp.lastcmd_off + sample_dylib_name_off, (const ut8*)lib, lib_len + 1); return true; } @@ -76,7 +76,7 @@ static bool addlib(RBinFile *bf, const char *lib) { } #if !R_BIN_MACH064 -RBinWrite r_bin_write_mach0 = { +RBinWrite rz_bin_write_mach0 = { #if 0 .scn_resize = &scn_resize, .scn_perms = &scn_perms, diff --git a/libr/bin/p/bin_write_mach064.c b/librz/bin/p/bin_write_mach064.c similarity index 87% rename from libr/bin/p/bin_write_mach064.c rename to librz/bin/p/bin_write_mach064.c index caa05f8086..3369f23221 100644 --- a/libr/bin/p/bin_write_mach064.c +++ b/librz/bin/p/bin_write_mach064.c @@ -3,7 +3,7 @@ #define R_BIN_MACH064 1 #include "bin_write_mach0.c" -RBinWrite r_bin_write_mach064 = { +RBinWrite rz_bin_write_mach064 = { #if 0 .scn_resize = &scn_resize, .scn_perms = &scn_perms, diff --git a/libr/bin/p/bin_write_pe.c b/librz/bin/p/bin_write_pe.c similarity index 61% rename from libr/bin/p/bin_write_pe.c rename to librz/bin/p/bin_write_pe.c index aab5fc35e0..1a4c2e23eb 100644 --- a/libr/bin/p/bin_write_pe.c +++ b/librz/bin/p/bin_write_pe.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2009-2019 - pancake, nibble */ -#include -#include +#include +#include #include "pe/pe.h" static bool scn_perms(RBinFile *bf, const char *name, int perms) { - return PE_(r_bin_pe_section_perms) (bf, name, perms); + return PE_(rz_bin_pe_section_perms) (bf, name, perms); } #if !R_BIN_PE64 -RBinWrite r_bin_write_pe = { +RBinWrite rz_bin_write_pe = { .scn_perms = &scn_perms }; #endif diff --git a/libr/bin/p/bin_write_pe64.c b/librz/bin/p/bin_write_pe64.c similarity index 79% rename from libr/bin/p/bin_write_pe64.c rename to librz/bin/p/bin_write_pe64.c index c4d96072af..085c18adb1 100644 --- a/libr/bin/p/bin_write_pe64.c +++ b/librz/bin/p/bin_write_pe64.c @@ -3,6 +3,6 @@ #define R_BIN_PE64 1 #include "bin_write_pe.c" -RBinWrite r_bin_write_pe64 = { +RBinWrite rz_bin_write_pe64 = { .scn_perms = &scn_perms }; diff --git a/libr/bin/p/bin_xbe.c b/librz/bin/p/bin_xbe.c similarity index 76% rename from libr/bin/p/bin_xbe.c rename to librz/bin/p/bin_xbe.c index 50dcd4eedb..421f85b98a 100644 --- a/libr/bin/p/bin_xbe.c +++ b/librz/bin/p/bin_xbe.c @@ -1,9 +1,9 @@ /* radare - LGPL - 2014-2019 - thatlemon@gmail.com, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include "../format/xbe/xbe.h" @@ -13,18 +13,18 @@ static const char *kt_name[] = { static bool check_buffer(RBuffer *b) { ut8 magic[4]; - if (r_buf_read_at (b, 0, magic, sizeof (magic)) == 4) { + if (rz_buf_read_at (b, 0, magic, sizeof (magic)) == 4) { return !memcmp (magic, "XBEH", 4); } return false; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - r_bin_xbe_obj_t *obj = R_NEW (r_bin_xbe_obj_t); + rz_bin_xbe_obj_t *obj = R_NEW (rz_bin_xbe_obj_t); if (!obj) { return false; } - st64 r = r_buf_read_at (buf, 0, (ut8 *)&obj->header, sizeof (obj->header)); + st64 r = rz_buf_read_at (buf, 0, (ut8 *)&obj->header, sizeof (obj->header)); if (r != sizeof (obj->header)) { R_FREE (obj); return false; @@ -55,7 +55,7 @@ static RBinAddr *binsym(RBinFile *bf, int type) { if (!bf || !bf->buf || type != R_BIN_SYM_MAIN) { return NULL; } - r_bin_xbe_obj_t *obj = bf->o->bin_obj; + rz_bin_xbe_obj_t *obj = bf->o->bin_obj; RBinAddr *ret = R_NEW0 (RBinAddr); if (!ret) { return NULL; @@ -65,15 +65,15 @@ static RBinAddr *binsym(RBinFile *bf, int type) { return ret; } -static RList *entries(RBinFile *bf) { - const r_bin_xbe_obj_t *obj; - RList *ret; +static RzList *entries(RBinFile *bf) { + const rz_bin_xbe_obj_t *obj; + RzList *ret; RBinAddr *ptr = R_NEW0 (RBinAddr); if (!bf || !bf->buf || !bf->o->bin_obj || !ptr) { free (ptr); return NULL; } - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { free (ptr); return NULL; @@ -82,15 +82,15 @@ static RList *entries(RBinFile *bf) { obj = bf->o->bin_obj; ptr->vaddr = obj->header.ep ^ obj->ep_key; ptr->paddr = ptr->vaddr - obj->header.base; - r_list_append (ret, ptr); + rz_list_append (ret, ptr); return ret; } -static RList *sections(RBinFile *bf) { +static RzList *sections(RBinFile *bf) { xbe_section *sect = NULL; - r_bin_xbe_obj_t *obj = NULL; + rz_bin_xbe_obj_t *obj = NULL; xbe_header *h = NULL; - RList *ret = NULL; + RzList *ret = NULL; char tmp[0x100]; int i, r; ut32 addr; @@ -103,7 +103,7 @@ static RList *sections(RBinFile *bf) { if (h->sections < 1) { return NULL; } - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { return NULL; } @@ -119,7 +119,7 @@ static RList *sections(RBinFile *bf) { if (addr > bf->size || addr + (sizeof(xbe_section) * h->sections) > bf->size) { goto out_error; } - r = r_buf_read_at (bf->buf, addr, (ut8 *) sect, sizeof(xbe_section) * h->sections); + r = rz_buf_read_at (bf->buf, addr, (ut8 *) sect, sizeof(xbe_section) * h->sections); if (r < 1) { goto out_error; } @@ -131,13 +131,13 @@ static RList *sections(RBinFile *bf) { free (item); goto out_error; } - r = r_buf_read_at (bf->buf, addr, (ut8 *) tmp, sizeof (tmp)); + r = rz_buf_read_at (bf->buf, addr, (ut8 *) tmp, sizeof (tmp)); if (r < 1) { free (item); goto out_error; } tmp[sizeof (tmp) - 1] = 0; - item->name = r_str_newf ("%s.%i", tmp, i); + item->name = rz_str_newf ("%s.%i", tmp, i); item->paddr = sect[i].offset; item->vaddr = sect[i].vaddr; item->size = sect[i].size; @@ -151,22 +151,22 @@ static RList *sections(RBinFile *bf) { if (sect[i].flags & SECT_FLAG_W) { item->perm |= R_PERM_W; } - r_list_append (ret, item); + rz_list_append (ret, item); } free (sect); return ret; out_error: - r_list_free (ret); + rz_list_free (ret); free (sect); return NULL; } -static RList *libs(RBinFile *bf) { - r_bin_xbe_obj_t *obj; +static RzList *libs(RBinFile *bf) { + rz_bin_xbe_obj_t *obj; xbe_header *h = NULL; int i, off, libs, r; xbe_lib lib; - RList *ret; + RzList *ret; char *s; ut32 addr; @@ -175,7 +175,7 @@ static RList *libs(RBinFile *bf) { } obj = bf->o->bin_obj; h = &obj->header; - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { return NULL; } @@ -188,14 +188,14 @@ static RList *libs(RBinFile *bf) { if (off > bf->size || off + sizeof(xbe_lib) > bf->size) { goto out_error; } - r = r_buf_read_at (bf->buf, off, (ut8 *) &lib, sizeof(xbe_lib)); + r = rz_buf_read_at (bf->buf, off, (ut8 *) &lib, sizeof(xbe_lib)); if (r < 1) { goto out_error; } lib.name[7] = 0; - s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); + s = rz_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); if (s) { - r_list_append (ret, s); + rz_list_append (ret, s); } if (h->xapi_lib_addr < h->base) { off = 0; @@ -205,15 +205,15 @@ static RList *libs(RBinFile *bf) { if (off > bf->size || off + sizeof(xbe_lib) > bf->size) { goto out_error; } - r = r_buf_read_at (bf->buf, off, (ut8 *) &lib, sizeof(xbe_lib)); + r = rz_buf_read_at (bf->buf, off, (ut8 *) &lib, sizeof(xbe_lib)); if (r < 1) { goto out_error; } lib.name[7] = 0; - s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); + s = rz_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); if (s) { - r_list_append (ret, s); + rz_list_append (ret, s); } libs = h->lib_versions; if (libs < 1) { @@ -224,28 +224,28 @@ static RList *libs(RBinFile *bf) { if (addr > bf->size || addr + sizeof (xbe_lib) > bf->size) { goto out_error; } - r = r_buf_read_at (bf->buf, addr, (ut8 *) &lib, sizeof (xbe_lib)); + r = rz_buf_read_at (bf->buf, addr, (ut8 *) &lib, sizeof (xbe_lib)); if (r < 1) { goto out_error; } // make sure it ends with 0 lib.name[7] = '\0'; - s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); + s = rz_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build); if (s) { - r_list_append (ret, s); + rz_list_append (ret, s); } } return ret; out_error: - r_list_free (ret); + rz_list_free (ret); return NULL; } -static RList *symbols(RBinFile *bf) { - r_bin_xbe_obj_t *obj; +static RzList *symbols(RBinFile *bf) { + rz_bin_xbe_obj_t *obj; xbe_header *h; - RList *ret; + RzList *ret; int i, found = false; ut32 thunk_addr[XBE_MAX_THUNK]; ut32 kt_addr; @@ -259,7 +259,7 @@ static RList *symbols(RBinFile *bf) { obj = bf->o->bin_obj; h = &obj->header; kt_addr = h->kernel_thunk_addr ^ obj->kt_key; - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { return NULL; } @@ -274,7 +274,7 @@ static RList *symbols(RBinFile *bf) { if (addr > bf->size || addr + sizeof(sect) > bf->size) { goto out_error; } - r_buf_read_at (bf->buf, addr, (ut8 *) §, sizeof(sect)); + rz_buf_read_at (bf->buf, addr, (ut8 *) §, sizeof(sect)); if (kt_addr >= sect.vaddr && kt_addr < sect.vaddr + sect.vsize) { found = true; } @@ -286,7 +286,7 @@ static RList *symbols(RBinFile *bf) { if (addr > bf->size || addr + sizeof(thunk_addr) > bf->size) { goto out_error; } - i = r_buf_read_at (bf->buf, addr, (ut8 *) &thunk_addr, sizeof (thunk_addr)); + i = rz_buf_read_at (bf->buf, addr, (ut8 *) &thunk_addr, sizeof (thunk_addr)); if (i != sizeof (thunk_addr)) { goto out_error; } @@ -299,24 +299,24 @@ static RList *symbols(RBinFile *bf) { // Basic sanity checks if (thunk_addr[i] & 0x80000000 && thunk_index < XBE_MAX_THUNK) { eprintf ("%d\n", thunk_index); - sym->name = r_str_newf ("kt.%s", kt_name[thunk_index]); + sym->name = rz_str_newf ("kt.%s", kt_name[thunk_index]); sym->vaddr = (h->kernel_thunk_addr ^ obj->kt_key) + (4 * i); sym->paddr = sym->vaddr - h->base; sym->size = 4; sym->ordinal = i; - r_list_append (ret, sym); + rz_list_append (ret, sym); } else { free (sym); } } return ret; out_error: - r_list_free (ret); + rz_list_free (ret); return NULL; } static RBinInfo *info(RBinFile *bf) { - r_bin_xbe_obj_t *obj; + rz_bin_xbe_obj_t *obj; RBinInfo *ret; ut8 dbg_name[256]; @@ -332,7 +332,7 @@ static RBinInfo *info(RBinFile *bf) { obj = bf->o->bin_obj; memset (dbg_name, 0, sizeof (dbg_name)); - r_buf_read_at (bf->buf, obj->header.debug_name_addr -\ + rz_buf_read_at (bf->buf, obj->header.debug_name_addr -\ obj->header.base, dbg_name, sizeof (dbg_name)); dbg_name[sizeof(dbg_name) - 1] = 0; ret->file = strdup ((char *) dbg_name); @@ -350,13 +350,13 @@ static RBinInfo *info(RBinFile *bf) { } static ut64 baddr(RBinFile *bf) { - r_bin_xbe_obj_t *obj = bf->o->bin_obj; + rz_bin_xbe_obj_t *obj = bf->o->bin_obj; return obj->header.base; } -RBinPlugin r_bin_plugin_xbe = { +RBinPlugin rz_bin_plugin_xbe = { .name = "xbe", - .desc = "Microsoft Xbox xbe format r_bin plugin", + .desc = "Microsoft Xbox xbe format rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .destroy = &destroy, @@ -371,9 +371,9 @@ RBinPlugin r_bin_plugin_xbe = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_xbe, + .data = &rz_bin_plugin_xbe, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_xnu_kernelcache.c b/librz/bin/p/bin_xnu_kernelcache.c similarity index 76% rename from libr/bin/p/bin_xnu_kernelcache.c rename to librz/bin/p/bin_xnu_kernelcache.c index b5db11175d..d035a29c5e 100644 --- a/libr/bin/p/bin_xnu_kernelcache.c +++ b/librz/bin/p/bin_xnu_kernelcache.c @@ -1,16 +1,16 @@ -/* radare2 - LGPL - Copyright 2019 - mrmacete */ +/* rizin - LGPL - Copyright 2019 - mrmacete */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define R_BIN_MACH064 1 #include "../format/mach0/mach0.h" -#include "../format/xnu/r_cf_dict.h" +#include "../format/xnu/rz_cf_dict.h" #include "../format/xnu/mig_index.h" #include "../format/mach0/mach064_is_kernelcache.c" @@ -24,7 +24,7 @@ typedef struct _RKernelCacheObj { struct _RKextIndex *kexts; struct MACH0_(obj_t) *mach0; struct _RRebaseInfo *rebase_info; - int (*original_io_read)(RIO *io, RIODesc *fd, ut8 *buf, int count); + int (*original_io_read)(RzIO *io, RzIODesc *fd, ut8 *buf, int count); bool rebase_info_populated; bool rebasing_buffer; bool kexts_initialized; @@ -78,9 +78,9 @@ typedef struct _RRebaseCtx { RKernelCacheObj *obj; } RRebaseCtx; -typedef struct _RParsedPointer { +typedef struct _RzParsedPointer { ut64 address; -} RParsedPointer; +} RzParsedPointer; typedef struct _RKmodInfo { char name[0x41]; @@ -118,66 +118,66 @@ typedef struct _RKmodInfo { #define R_K_CONSTRUCTOR_TO_SYMBOL 1 #define K_PPTR(p) p_ptr (p, obj) -#define K_RPTR(buf) r_ptr (buf, obj) +#define K_RPTR(buf) rz_ptr (buf, obj) #define IS_PTR_AUTH(x) ((x & (1ULL << 63)) != 0) #define IS_PTR_BIND(x) ((x & (1ULL << 62)) != 0) static ut64 p_ptr (ut64 decorated_addr, RKernelCacheObj *obj); -static ut64 r_ptr (ut8 *buf, RKernelCacheObj *obj); +static ut64 rz_ptr (ut8 *buf, RKernelCacheObj *obj); -static RRebaseInfo *r_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH0_(obj_t) *mach0); -static void r_rebase_info_free(RRebaseInfo *info); -static void r_rebase_info_populate(RRebaseInfo *info, RKernelCacheObj *obj); +static RRebaseInfo *rz_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH0_(obj_t) *mach0); +static void rz_rebase_info_free(RRebaseInfo *info); +static void rz_rebase_info_populate(RRebaseInfo *info, RKernelCacheObj *obj); static ut64 iterate_rebase_list(RBuffer *cache_buf, ut64 multiplier, ut64 start_offset, ROnRebaseFunc func, void *user_data); -static ut64 r_rebase_offset_to_paddr (RKernelCacheObj *obj, struct section_t *sections, ut64 offset); -static void swizzle_io_read(RKernelCacheObj *obj, RIO *io); -static int kernelcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count); -static bool r_parse_pointer(RParsedPointer *ptr, ut64 decorated_addr, RKernelCacheObj *obj); +static ut64 rz_rebase_offset_to_paddr (RKernelCacheObj *obj, struct section_t *sections, ut64 offset); +static void swizzle_io_read(RKernelCacheObj *obj, RzIO *io); +static int kernelcache_io_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count); +static bool rz_parse_pointer(RzParsedPointer *ptr, ut64 decorated_addr, RKernelCacheObj *obj); static bool on_rebase_pointer (ut64 offset, ut64 decorated_addr, RRebaseCtx *ctx); -static void rebase_buffer(RKernelCacheObj *obj, ut64 off, RIODesc *fd, ut8 *buf, int count); -static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RIODesc *fd, ut8 *buf, int count); +static void rebase_buffer(RKernelCacheObj *obj, ut64 off, RzIODesc *fd, ut8 *buf, int count); +static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RzIODesc *fd, ut8 *buf, int count); static RPrelinkRange *get_prelink_info_range_from_mach0(struct MACH0_(obj_t) *mach0); -static RList *filter_kexts(RKernelCacheObj *obj); -static RList *carve_kexts(RKernelCacheObj *obj); -static RList *kexts_from_load_commands(RKernelCacheObj *obj); +static RzList *filter_kexts(RKernelCacheObj *obj); +static RzList *carve_kexts(RKernelCacheObj *obj); +static RzList *kexts_from_load_commands(RKernelCacheObj *obj); -static void sections_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, char *prefix, RKernelCacheObj *obj); +static void sections_from_mach0(RzList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, char *prefix, RKernelCacheObj *obj); static void handle_data_sections(RBinSection *sect); -static void symbols_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, int ordinal); -static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr); -static RList *resolve_mig_subsystem(RKernelCacheObj *obj); -static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCacheObj *obj, RBinFile *bf, RKext *kext, int ordinal); +static void symbols_from_mach0(RzList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, int ordinal); +static RzList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr); +static RzList *resolve_mig_subsystem(RKernelCacheObj *obj); +static void symbols_from_stubs(RzList *ret, HtPP *kernel_syms_by_addr, RKernelCacheObj *obj, RBinFile *bf, RKext *kext, int ordinal); static RStubsInfo *get_stubs_info(struct MACH0_(obj_t) *mach0, ut64 paddr, RKernelCacheObj *obj); static int prot2perm (int x); -static void r_kext_free(RKext *kext); -static void r_kext_fill_text_range(RKext *kext); +static void rz_kext_free(RKext *kext); +static void rz_kext_fill_text_range(RKext *kext); static int kexts_sort_vaddr_func(const void *a, const void *b); static struct MACH0_(obj_t) *create_kext_mach0(RKernelCacheObj *obj, RKext *kext); static struct MACH0_(obj_t) *create_kext_shared_mach0(RKernelCacheObj *obj, RKext *kext); -#define r_kext_index_foreach(index, i, item)\ +#define rz_kext_index_foreach(index, i, item)\ if (index)\ for (i = 0; i < index->length && (item = index->entries[i], 1); i++) -static RKextIndex *r_kext_index_new(RList *kexts); -static void r_kext_index_free(RKextIndex *index); -static RKext *r_kext_index_vget(RKextIndex *index, ut64 vaddr); +static RKextIndex *rz_kext_index_new(RzList *kexts); +static void rz_kext_index_free(RKextIndex *index); +static RKext *rz_kext_index_vget(RKextIndex *index, ut64 vaddr); -static void process_kmod_init_term(RKernelCacheObj *obj, RKext *kext, RList *ret, ut64 **inits, ut64 **terms); -static void create_initterm_syms(RKext *kext, RList *ret, int type, ut64 *pointers); -static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mach0, RList *ret, ut64 paddr, bool is_first, int mode, const char *prefix); +static void process_kmod_init_term(RKernelCacheObj *obj, RKext *kext, RzList *ret, ut64 **inits, ut64 **terms); +static void create_initterm_syms(RKext *kext, RzList *ret, int type, ut64 *pointers); +static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mach0, RzList *ret, ut64 paddr, bool is_first, int mode, const char *prefix); static RBinAddr *newEntry(ut64 haddr, ut64 vaddr, int type); static void ensure_kexts_initialized(RKernelCacheObj *obj); -static void r_kernel_cache_free(RKernelCacheObj *obj); +static void rz_kernel_cache_free(RKernelCacheObj *obj); -static RList * pending_bin_files = NULL; +static RzList * pending_bin_files = NULL; static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) { - RBuffer *fbuf = r_buf_ref (buf); + RBuffer *fbuf = rz_buf_ref (buf); struct MACH0_(opts_t) opts; MACH0_(opts_set_default) (&opts, bf); struct MACH0_(obj_t) *main_mach0 = MACH0_(new_buf) (fbuf, &opts); @@ -185,7 +185,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd return false; } - RRebaseInfo *rebase_info = r_rebase_info_new_from_mach0 (fbuf, main_mach0); + RRebaseInfo *rebase_info = rz_rebase_info_new_from_mach0 (fbuf, main_mach0); RPrelinkRange *prelink_range = get_prelink_info_range_from_mach0 (main_mach0); if (!prelink_range) { @@ -200,7 +200,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd RCFValueDict *prelink_info = NULL; if (main_mach0->hdr.filetype != MH_FILESET) { - prelink_info = r_cf_value_dict_parse (fbuf, prelink_range->range.offset, + prelink_info = rz_cf_value_dict_parse (fbuf, prelink_range->range.offset, prelink_range->range.size, R_CF_OPTION_SKIP_NSDATA); if (!prelink_info) { R_FREE (prelink_range); @@ -210,7 +210,7 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd } if (!pending_bin_files) { - pending_bin_files = r_list_new (); + pending_bin_files = rz_list_new (); if (!pending_bin_files) { R_FREE (prelink_range); R_FREE (obj); @@ -228,17 +228,17 @@ static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadadd *bin_obj = obj; - r_list_push (pending_bin_files, bf); + rz_list_push (pending_bin_files, bf); if (rebase_info || main_mach0->chained_starts) { - RIO *io = bf->rbin->iob.io; + RzIO *io = bf->rbin->iob.io; swizzle_io_read (obj, io); } return true; beach: - r_buf_free (fbuf); + rz_buf_free (fbuf); MACH0_(mach0_free) (main_mach0); return false; } @@ -249,14 +249,14 @@ static void ensure_kexts_initialized(RKernelCacheObj *obj) { } obj->kexts_initialized = true; - RList *kexts = NULL; + RzList *kexts = NULL; if (obj->prelink_info) { kexts = filter_kexts (obj); } - if (kexts && !r_list_length (kexts)) { - r_list_free (kexts); + if (kexts && !rz_list_length (kexts)) { + rz_list_free (kexts); kexts = NULL; } @@ -264,8 +264,8 @@ static void ensure_kexts_initialized(RKernelCacheObj *obj) { kexts = kexts_from_load_commands (obj); } - if (kexts && !r_list_length (kexts)) { - r_list_free (kexts); + if (kexts && !rz_list_length (kexts)) { + rz_list_free (kexts); kexts = NULL; } @@ -273,7 +273,7 @@ static void ensure_kexts_initialized(RKernelCacheObj *obj) { kexts = carve_kexts (obj); } - obj->kexts = r_kext_index_new (kexts); + obj->kexts = rz_kext_index_new (kexts); } static RPrelinkRange *get_prelink_info_range_from_mach0(struct MACH0_(obj_t) *mach0) { @@ -337,11 +337,11 @@ static RPrelinkRange *get_prelink_info_range_from_mach0(struct MACH0_(obj_t) *ma return prelink_range; } -static RList *filter_kexts(RKernelCacheObj *obj) { +static RzList *filter_kexts(RKernelCacheObj *obj) { RCFValueArray *kext_array = NULL; - RListIter *iter; + RzListIter *iter; RCFKeyValue *item; - r_list_foreach (obj->prelink_info->pairs, iter, item) { + rz_list_foreach (obj->prelink_info->pairs, iter, item) { if (!strcmp (item->key, "_PrelinkInfoDictionary")) { kext_array = (RCFValueArray*) item->value; break; @@ -352,7 +352,7 @@ static RList *filter_kexts(RKernelCacheObj *obj) { return NULL; } - RList *kexts = r_list_newf ((RListFree) &r_kext_free); + RzList *kexts = rz_list_newf ((RzListFree) &rz_kext_free); if (!kexts) { return NULL; } @@ -360,7 +360,7 @@ static RList *filter_kexts(RKernelCacheObj *obj) { bool is_sorted = true; RKext *prev_kext = NULL; RCFValueDict *kext_item; - r_list_foreach (kext_array->values, iter, kext_item) { + rz_list_foreach (kext_array->values, iter, kext_item) { RKext *kext = R_NEW0 (RKext); if (!kext) { R_FREE (kexts); @@ -368,8 +368,8 @@ static RList *filter_kexts(RKernelCacheObj *obj) { } int kext_incomplete = 5; - RListIter *internal_iter; - r_list_foreach (kext_item->pairs, internal_iter, item) { + RzListIter *internal_iter; + rz_list_foreach (kext_item->pairs, internal_iter, item) { if (!strcmp (item->key, "CFBundlePackageType")) { if (item->value->type != R_CF_STRING) { break; @@ -415,7 +415,7 @@ static RList *filter_kexts(RKernelCacheObj *obj) { } if (kext_incomplete) { - r_kext_free (kext); + rz_kext_free (kext); continue; } @@ -426,34 +426,34 @@ static RList *filter_kexts(RKernelCacheObj *obj) { kext->mach0 = create_kext_mach0 (obj, kext); if (!kext->mach0) { - r_kext_free (kext); + rz_kext_free (kext); continue; } - r_kext_fill_text_range (kext); + rz_kext_fill_text_range (kext); - r_list_push (kexts, kext); + rz_list_push (kexts, kext); } if (!is_sorted) { eprintf ("SORTING KEXTs...\n"); - r_list_sort (kexts, kexts_sort_vaddr_func); + rz_list_sort (kexts, kexts_sort_vaddr_func); } return kexts; } static ut64 p_ptr (ut64 decorated_addr, RKernelCacheObj *obj) { - RParsedPointer ptr; - r_parse_pointer (&ptr, decorated_addr, obj); + RzParsedPointer ptr; + rz_parse_pointer (&ptr, decorated_addr, obj); return ptr.address; } -static ut64 r_ptr (ut8 *buf, RKernelCacheObj *obj) { - ut64 decorated_addr = r_read_le64 (buf); +static ut64 rz_ptr (ut8 *buf, RKernelCacheObj *obj) { + ut64 decorated_addr = rz_read_le64 (buf); return K_PPTR (decorated_addr); } -static RList *carve_kexts(RKernelCacheObj *obj) { +static RzList *carve_kexts(RKernelCacheObj *obj) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (obj->mach0))) { return NULL; @@ -494,7 +494,7 @@ static RList *carve_kexts(RKernelCacheObj *obj) { return NULL; } - RList *kexts = r_list_newf ((RListFree) &r_kext_free); + RzList *kexts = rz_list_newf ((RzListFree) &rz_kext_free); if (!kexts) { return NULL; } @@ -514,7 +514,7 @@ static RList *carve_kexts(RKernelCacheObj *obj) { for (; j < n_kmod_info; j++) { ut64 entry_offset = j * 8 + kmod_info; - if (r_buf_read_at (obj->cache_buf, entry_offset, bytes, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, entry_offset, bytes, 8) < 8) { goto beach; } @@ -523,13 +523,13 @@ static RList *carve_kexts(RKernelCacheObj *obj) { ut64 field_name = kmod_info_paddr + 0x10; ut64 field_start = kmod_info_paddr + 0xb4; - if (r_buf_read_at (obj->cache_buf, field_start, bytes, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, field_start, bytes, 8) < 8) { goto beach; } all_infos[j].start = K_RPTR (bytes); - if (r_buf_read_at (obj->cache_buf, field_name, (ut8 *) all_infos[j].name, 0x40) < 0x40) { + if (rz_buf_read_at (obj->cache_buf, field_name, (ut8 *) all_infos[j].name, 0x40) < 0x40) { goto beach; } @@ -539,7 +539,7 @@ static RList *carve_kexts(RKernelCacheObj *obj) { ut64 cursor = kmod_start; for(; cursor < kmod_end; cursor += 8) { ut8 bytes[8]; - if (r_buf_read_at (obj->cache_buf, cursor, bytes, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, cursor, bytes, 8) < 8) { goto beach; } @@ -553,11 +553,11 @@ static RList *carve_kexts(RKernelCacheObj *obj) { kext->mach0 = create_kext_mach0 (obj, kext); if (!kext->mach0) { - r_kext_free (kext); + rz_kext_free (kext); continue; } - r_kext_fill_text_range (kext); + rz_kext_fill_text_range (kext); kext->vaddr = K_PPTR (kext->vaddr); kext->pa2va_exec = pa2va_exec; kext->pa2va_data = pa2va_data; @@ -566,7 +566,7 @@ static RList *carve_kexts(RKernelCacheObj *obj) { ut64 text_end = text_start + kext->text_range.size; if (text_start == text_end) { - r_kext_free (kext); + rz_kext_free (kext); continue; } @@ -581,42 +581,42 @@ static RList *carve_kexts(RKernelCacheObj *obj) { } if (!kext->name) { - r_kext_free (kext); + rz_kext_free (kext); continue; } - r_list_push (kexts, kext); + rz_list_push (kexts, kext); } R_FREE (all_infos); return kexts; beach: - r_list_free (kexts); + rz_list_free (kexts); R_FREE (all_infos); return NULL; } -static RList *kexts_from_load_commands(RKernelCacheObj *obj) { - RList *kexts = r_list_newf ((RListFree) &r_kext_free); +static RzList *kexts_from_load_commands(RKernelCacheObj *obj) { + RzList *kexts = rz_list_newf ((RzListFree) &rz_kext_free); if (!kexts) { return NULL; } - ut32 i, ncmds = r_buf_read_le32_at (obj->cache_buf, 16); - ut64 length = r_buf_size (obj->cache_buf); + ut32 i, ncmds = rz_buf_read_le32_at (obj->cache_buf, 16); + ut64 length = rz_buf_size (obj->cache_buf); ut32 cursor = sizeof (struct MACH0_(mach_header)); for (i = 0; i < ncmds && cursor < length; i++) { - ut32 cmdtype = r_buf_read_le32_at (obj->cache_buf, cursor); - ut32 cmdsize = r_buf_read_le32_at (obj->cache_buf, cursor + 4); + ut32 cmdtype = rz_buf_read_le32_at (obj->cache_buf, cursor); + ut32 cmdsize = rz_buf_read_le32_at (obj->cache_buf, cursor + 4); if (cmdtype != LC_KEXT) { cursor += cmdsize; continue; } - ut64 vaddr = r_buf_read_le64_at (obj->cache_buf, cursor + 8); - ut64 paddr = r_buf_read_le64_at (obj->cache_buf, cursor + 16); + ut64 vaddr = rz_buf_read_le64_at (obj->cache_buf, cursor + 8); + ut64 paddr = rz_buf_read_le64_at (obj->cache_buf, cursor + 16); st32 padded_name_length = (st32)cmdsize - 32; if (padded_name_length <= 0) { cursor += cmdsize; @@ -627,7 +627,7 @@ static RList *kexts_from_load_commands(RKernelCacheObj *obj) { if (!padded_name) { goto beach; } - if (r_buf_read_at (obj->cache_buf, cursor + 32, (ut8 *)padded_name, padded_name_length) + if (rz_buf_read_at (obj->cache_buf, cursor + 32, (ut8 *)padded_name, padded_name_length) != padded_name_length) { free (padded_name); goto early; @@ -645,30 +645,30 @@ static RList *kexts_from_load_commands(RKernelCacheObj *obj) { kext->mach0 = create_kext_shared_mach0 (obj, kext); if (!kext->mach0) { free (padded_name); - r_kext_free (kext); + rz_kext_free (kext); cursor += cmdsize; continue; } - r_kext_fill_text_range (kext); + rz_kext_fill_text_range (kext); kext->vaddr = K_PPTR (kext->vaddr); kext->pa2va_exec = obj->pa2va_exec; kext->pa2va_data = obj->pa2va_data; kext->name = strdup (padded_name); kext->own_name = true; free (padded_name); - r_list_push (kexts, kext); + rz_list_push (kexts, kext); cursor += cmdsize; } early: return kexts; beach: - r_list_free (kexts); + rz_list_free (kexts); return NULL; } -static void r_kext_free(RKext *kext) { +static void rz_kext_free(RKext *kext) { if (!kext) { return; } @@ -686,7 +686,7 @@ static void r_kext_free(RKext *kext) { R_FREE (kext); } -static void r_kext_fill_text_range(RKext *kext) { +static void rz_kext_fill_text_range(RKext *kext) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (kext->mach0))) { return; @@ -715,12 +715,12 @@ static int kexts_sort_vaddr_func(const void *a, const void *b) { return vaddr_compare; } -static RKextIndex *r_kext_index_new(RList *kexts) { +static RKextIndex *rz_kext_index_new(RzList *kexts) { if (!kexts) { return NULL; } - int length = r_list_length (kexts); + int length = rz_list_length (kexts); if (!length) { return NULL; } @@ -736,10 +736,10 @@ static RKextIndex *r_kext_index_new(RList *kexts) { return NULL; } - RListIter *iter; + RzListIter *iter; RKext *kext; int i = 0; - r_list_foreach (kexts, iter, kext) { + rz_list_foreach (kexts, iter, kext) { index->entries[i++] = kext; } index->length = i; @@ -747,15 +747,15 @@ static RKextIndex *r_kext_index_new(RList *kexts) { return index; } -static void r_kext_index_free(RKextIndex *index) { +static void rz_kext_index_free(RKextIndex *index) { if (!index) { return; } int i = 0; RKext *kext; - r_kext_index_foreach (index, i, kext) { - r_kext_free (kext); + rz_kext_index_foreach (index, i, kext) { + rz_kext_free (kext); index->entries[i] = NULL; } @@ -763,7 +763,7 @@ static void r_kext_index_free(RKextIndex *index) { R_FREE (index); } -static RKext *r_kext_index_vget(RKextIndex *index, ut64 vaddr) { +static RKext *rz_kext_index_vget(RKextIndex *index, ut64 vaddr) { int imid; int imin = 0; int imax = index->length - 1; @@ -786,30 +786,30 @@ static RKext *r_kext_index_vget(RKextIndex *index, ut64 vaddr) { } static struct MACH0_(obj_t) *create_kext_mach0(RKernelCacheObj *obj, RKext *kext) { - RBuffer *buf = r_buf_new_slice (obj->cache_buf, kext->range.offset, r_buf_size (obj->cache_buf) - kext->range.offset); + RBuffer *buf = rz_buf_new_slice (obj->cache_buf, kext->range.offset, rz_buf_size (obj->cache_buf) - kext->range.offset); struct MACH0_(opts_t) opts; opts.verbose = true; opts.header_at = 0; struct MACH0_(obj_t) *mach0 = MACH0_(new_buf) (buf, &opts); - r_buf_free (buf); + rz_buf_free (buf); return mach0; } static struct MACH0_(obj_t) *create_kext_shared_mach0(RKernelCacheObj *obj, RKext *kext) { - RBuffer *buf = r_buf_ref (obj->cache_buf); + RBuffer *buf = rz_buf_ref (obj->cache_buf); struct MACH0_(opts_t) opts; opts.verbose = false; opts.header_at = kext->range.offset; struct MACH0_(obj_t) *mach0 = MACH0_(new_buf) (buf, &opts); - r_buf_free (buf); + rz_buf_free (buf); return mach0; } -static RList *entries(RBinFile *bf) { - RList *ret; +static RzList *entries(RBinFile *bf) { + RzList *ret; RBinObject *obj = bf ? bf->o : NULL; - if (!obj || !obj->bin_obj || !(ret = r_list_newf (free))) { + if (!obj || !obj->bin_obj || !(ret = rz_list_newf (free))) { return NULL; } @@ -819,7 +819,7 @@ static RList *entries(RBinFile *bf) { ut64 entry_paddr = entry_vaddr - kobj->pa2va_exec; RBinAddr *ba = newEntry (entry_paddr, entry_vaddr, 0); if (ba) { - r_list_append (ret, ba); + rz_list_append (ret, ba); } } @@ -828,7 +828,7 @@ static RList *entries(RBinFile *bf) { return ret; } -static void process_kmod_init_term(RKernelCacheObj *obj, RKext *kext, RList *ret, ut64 **inits, ut64 **terms) { +static void process_kmod_init_term(RKernelCacheObj *obj, RKext *kext, RzList *ret, ut64 **inits, ut64 **terms) { if (!*inits || !*terms) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (obj->mach0))) { @@ -870,7 +870,7 @@ static void process_kmod_init_term(RKernelCacheObj *obj, RKext *kext, RList *ret int j = 0; ut8 bytes[8]; for (; j < n_ptrs; j++) { - if (r_buf_read_at (obj->cache_buf, start_paddr + j * 8, bytes, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, start_paddr + j * 8, bytes, 8) < 8) { break; } target[j] = K_RPTR (bytes); @@ -900,7 +900,7 @@ static const char *kext_short_name(RKext *kext) { return sn ? sn + 1 : kext->name; } -static void create_initterm_syms(RKext *kext, RList *ret, int type, ut64 *pointers) { +static void create_initterm_syms(RKext *kext, RzList *ret, int type, ut64 *pointers) { int i = 0; int count = 0; for (; pointers[i]; i++) { @@ -921,7 +921,7 @@ static void create_initterm_syms(RKext *kext, RList *ret, int type, ut64 *pointe break; } - sym->name = r_str_newf ("%s.%s.%d", kext_short_name (kext), (type == R_BIN_ENTRY_TYPE_INIT) ? "init" : "fini", count++); + sym->name = rz_str_newf ("%s.%s.%d", kext_short_name (kext), (type == R_BIN_ENTRY_TYPE_INIT) ? "init" : "fini", count++); sym->vaddr = func_vaddr; sym->paddr = func_vaddr - kext->pa2va_exec; sym->size = 0; @@ -929,11 +929,11 @@ static void create_initterm_syms(RKext *kext, RList *ret, int type, ut64 *pointe sym->bind = "GLOBAL"; sym->type = "FUNC"; - r_list_append (ret, sym); + rz_list_append (ret, sym); } } -static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mach0, RList *ret, ut64 paddr, bool is_first, int mode, const char *prefix) { +static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mach0, RzList *ret, ut64 paddr, bool is_first, int mode, const char *prefix) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (mach0))) { return; @@ -957,7 +957,7 @@ static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mac if (!buf) { break; } - if (r_buf_read_at (obj->cache_buf, sections[i].offset + paddr, buf, sections[i].size) < sections[i].size) { + if (rz_buf_read_at (obj->cache_buf, sections[i].offset + paddr, buf, sections[i].size) < sections[i].size) { free (buf); break; } @@ -968,14 +968,14 @@ static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mac ut64 paddr64 = sections[i].offset + paddr + j; if (mode == R_K_CONSTRUCTOR_TO_ENTRY) { RBinAddr *ba = newEntry (paddr64, addr64, type); - r_list_append (ret, ba); + rz_list_append (ret, ba); } else if (mode == R_K_CONSTRUCTOR_TO_SYMBOL) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { break; } - sym->name = r_str_newf ("%s.%s.%d", prefix, (type == R_BIN_ENTRY_TYPE_INIT) ? "init" : "fini", count++); + sym->name = rz_str_newf ("%s.%s.%d", prefix, (type == R_BIN_ENTRY_TYPE_INIT) ? "init" : "fini", count++); sym->vaddr = addr64; sym->paddr = paddr64; sym->size = 0; @@ -983,7 +983,7 @@ static void process_constructors(RKernelCacheObj *obj, struct MACH0_(obj_t) *mac sym->bind = "GLOBAL"; sym->type = "FUNC"; - r_list_append (ret, sym); + rz_list_append (ret, sym); } } free (buf); @@ -1005,9 +1005,9 @@ static RBinAddr *newEntry(ut64 haddr, ut64 vaddr, int type) { } static bool check_buffer(RBuffer *b) { - if (r_buf_size (b) > 4) { + if (rz_buf_size (b) > 4) { ut8 buf[4]; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); if (!memcmp (buf, "\xcf\xfa\xed\xfe", 4)) { return is_kernelcache_buffer (b); } @@ -1015,11 +1015,11 @@ static bool check_buffer(RBuffer *b) { return false; } -static RList *sections(RBinFile *bf) { - RList *ret = NULL; +static RzList *sections(RBinFile *bf) { + RzList *ret = NULL; RBinObject *obj = bf ? bf->o : NULL; - if (!obj || !obj->bin_obj || !(ret = r_list_newf ((RListFree)free))) { + if (!obj || !obj->bin_obj || !(ret = rz_list_newf ((RzListFree)free))) { return NULL; } @@ -1028,11 +1028,11 @@ static RList *sections(RBinFile *bf) { int iter; RKext *kext; - r_kext_index_foreach (kobj->kexts, iter, kext) { + rz_kext_index_foreach (kobj->kexts, iter, kext) { ut8 magicbytes[4]; - r_buf_read_at (kobj->cache_buf, kext->range.offset, magicbytes, 4); - int magic = r_read_le32 (magicbytes); + rz_buf_read_at (kobj->cache_buf, kext->range.offset, magicbytes, 4); + int magic = rz_read_le32 (magicbytes); switch (magic) { case MH_MAGIC_64: sections_from_mach0 (ret, kext->mach0, bf, kext->range.offset, kext->name, kobj); @@ -1057,9 +1057,9 @@ static RList *sections(RBinFile *bf) { } seg = &kobj->mach0->segs[i]; - r_str_ncpy (segname, seg->segname, 17); - r_str_filter (segname, -1); - ptr->name = r_str_newf ("%d.%s", i, segname); + rz_str_ncpy (segname, seg->segname, 17); + rz_str_filter (segname, -1); + ptr->name = rz_str_newf ("%d.%s", i, segname); ptr->size = seg->vmsize; ptr->vsize = seg->vmsize; ptr->paddr = seg->fileoff + bf->o->boffset; @@ -1070,7 +1070,7 @@ static RList *sections(RBinFile *bf) { ptr->vaddr = ptr->paddr; } ptr->perm = prot2perm (seg->initprot); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; @@ -1084,7 +1084,7 @@ static int prot2perm (int x) { return r; } -static void sections_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, char *prefix, RKernelCacheObj *obj) { +static void sections_from_mach0(RzList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, char *prefix, RKernelCacheObj *obj) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (mach0))) { return; @@ -1096,13 +1096,13 @@ static void sections_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFil break; } if (prefix) { - ptr->name = r_str_newf ("%s.%s", prefix, (char*)sections[i].name); + ptr->name = rz_str_newf ("%s.%s", prefix, (char*)sections[i].name); } else { - ptr->name = r_str_newf ("%s", (char*)sections[i].name); + ptr->name = rz_str_newf ("%s", (char*)sections[i].name); } if (strstr (ptr->name, "la_symbol_ptr")) { int len = sections[i].size / 8; - ptr->format = r_str_newf ("Cd %d[%d]", 8, len); + ptr->format = rz_str_newf ("Cd %d[%d]", 8, len); } handle_data_sections (ptr); ptr->size = sections[i].size; @@ -1116,7 +1116,7 @@ static void sections_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFil if (!ptr->perm && strstr (sections[i].name, "__TEXT_EXEC.__text")) { ptr->perm = 1 | 4; } - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } free (sections); } @@ -1135,8 +1135,8 @@ static void handle_data_sections(RBinSection *sect) { } } -static RList *symbols(RBinFile *bf) { - RList *ret = r_list_newf (free); +static RzList *symbols(RBinFile *bf) { + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } @@ -1147,14 +1147,14 @@ static RList *symbols(RBinFile *bf) { HtPP *kernel_syms_by_addr = sdb_ht_new (); if (!kernel_syms_by_addr) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - RListIter *iter; + RzListIter *iter; RBinSymbol *sym; ut64 enosys_addr = 0; - r_list_foreach (ret, iter, sym) { + rz_list_foreach (ret, iter, sym) { const char *key = sdb_fmt ("%"PFMT64x, sym->vaddr); sdb_ht_insert (kernel_syms_by_addr, key, sym->dname ? sym->dname : sym->name); if (!enosys_addr && strstr (sym->name, "enosys")) { @@ -1162,26 +1162,26 @@ static RList *symbols(RBinFile *bf) { } } - RList *syscalls = resolve_syscalls (obj, enosys_addr); + RzList *syscalls = resolve_syscalls (obj, enosys_addr); if (syscalls) { - r_list_foreach (syscalls, iter, sym) { + rz_list_foreach (syscalls, iter, sym) { const char *key = sdb_fmt ("%"PFMT64x, sym->vaddr); sdb_ht_insert (kernel_syms_by_addr, key, sym->name); - r_list_append (ret, sym); + rz_list_append (ret, sym); } syscalls->free = NULL; - r_list_free (syscalls); + rz_list_free (syscalls); } - RList *subsystem = resolve_mig_subsystem (obj); + RzList *subsystem = resolve_mig_subsystem (obj); if (subsystem) { - r_list_foreach (subsystem, iter, sym) { + rz_list_foreach (subsystem, iter, sym) { const char *key = sdb_fmt ("%"PFMT64x, sym->vaddr); sdb_ht_insert (kernel_syms_by_addr, key, sym->name); - r_list_append (ret, sym); + rz_list_append (ret, sym); } subsystem->free = NULL; - r_list_free (subsystem); + rz_list_free (subsystem); } ensure_kexts_initialized (obj); @@ -1190,14 +1190,14 @@ static RList *symbols(RBinFile *bf) { int kiter; ut64 *inits = NULL; ut64 *terms = NULL; - r_kext_index_foreach (obj->kexts, kiter, kext) { + rz_kext_index_foreach (obj->kexts, kiter, kext) { ut8 magicbytes[4]; - r_buf_read_at (obj->cache_buf, kext->range.offset, magicbytes, 4); - int magic = r_read_le32 (magicbytes); + rz_buf_read_at (obj->cache_buf, kext->range.offset, magicbytes, 4); + int magic = rz_read_le32 (magicbytes); switch (magic) { case MH_MAGIC_64: - symbols_from_mach0 (ret, kext->mach0, bf, kext->range.offset, r_list_length (ret)); - symbols_from_stubs (ret, kernel_syms_by_addr, obj, bf, kext, r_list_length (ret)); + symbols_from_mach0 (ret, kext->mach0, bf, kext->range.offset, rz_list_length (ret)); + symbols_from_stubs (ret, kernel_syms_by_addr, obj, bf, kext, rz_list_length (ret)); process_constructors (obj, kext->mach0, ret, kext->range.offset, false, R_K_CONSTRUCTOR_TO_SYMBOL, kext_short_name (kext)); process_kmod_init_term (obj, kext, ret, &inits, &terms); @@ -1216,7 +1216,7 @@ static RList *symbols(RBinFile *bf) { return ret; } -static void symbols_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, int ordinal) { +static void symbols_from_mach0(RzList *ret, struct MACH0_(obj_t) *mach0, RBinFile *bf, ut64 paddr, int ordinal) { const struct symbol_t *symbols = MACH0_(get_symbols) (mach0); if (!symbols) { return; @@ -1233,7 +1233,7 @@ static void symbols_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile sym->name = strdup (symbols[i].name); sym->vaddr = symbols[i].addr; if (sym->name[0] == '_') { - char *dn = r_bin_demangle (bf, sym->name, sym->name, sym->vaddr, false); + char *dn = rz_bin_demangle (bf, sym->name, sym->name, sym->vaddr, false); if (dn) { sym->dname = dn; char *p = strchr (dn, '.'); @@ -1257,7 +1257,7 @@ static void symbols_from_mach0(RList *ret, struct MACH0_(obj_t) *mach0, RBinFile sym->paddr = symbols[i].offset + bf->o->boffset + paddr; sym->size = symbols[i].size; sym->ordinal = ordinal + i; - r_list_append (ret, sym); + rz_list_append (ret, sym); } } @@ -1271,14 +1271,14 @@ typedef struct _r_sysent { ut16 sy_arg_bytes; } RSysEnt; -static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { +static RzList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (obj->mach0))) { return NULL; } - RList *syscalls = NULL; - RSyscall *syscall = NULL; + RzList *syscalls = NULL; + RzSyscall *syscall = NULL; ut8 *data_const = NULL; ut64 data_const_offset = 0, data_const_size = 0, data_const_vaddr = 0; int i = 0; @@ -1299,14 +1299,14 @@ static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { if (!data_const) { goto beach; } - if (r_buf_read_at (obj->cache_buf, data_const_offset, data_const, data_const_size) < data_const_size) { + if (rz_buf_read_at (obj->cache_buf, data_const_offset, data_const, data_const_size) < data_const_size) { goto beach; } ut8 *cursor = data_const; ut8 *end = data_const + data_const_size; while (cursor < end) { - ut64 test = r_read_le64 (cursor); + ut64 test = rz_read_le64 (cursor); if (test == enosys_addr) { break; } @@ -1319,9 +1319,9 @@ static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { cursor -= 24; while (cursor >= data_const) { - ut64 addr = r_read_le64 (cursor); - ut64 x = r_read_le64 (cursor + 8); - ut64 y = r_read_le64 (cursor + 16); + ut64 addr = rz_read_le64 (cursor); + ut64 x = rz_read_le64 (cursor + 8); + ut64 y = rz_read_le64 (cursor + 16); if (IS_KERNEL_ADDR (addr) && (x == 0 || IS_KERNEL_ADDR (x)) && @@ -1338,18 +1338,18 @@ static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { goto beach; } - syscalls = r_list_newf (r_bin_symbol_free); + syscalls = rz_list_newf (rz_bin_symbol_free); if (!syscalls) { goto beach; } - syscall = r_syscall_new (); + syscall = rz_syscall_new (); if (!syscall) { goto beach; } - r_syscall_setup (syscall, "arm", 64, NULL, "ios"); + rz_syscall_setup (syscall, "arm", 64, NULL, "ios"); if (!syscall->db) { - r_syscall_free (syscall); + rz_syscall_free (syscall); goto beach; } @@ -1360,52 +1360,52 @@ static RList *resolve_syscalls(RKernelCacheObj *obj, ut64 enosys_addr) { goto beach; } - sym->name = r_str_newf ("sysent"); + sym->name = rz_str_newf ("sysent"); sym->vaddr = sysent_vaddr; sym->paddr = cursor - data_const + data_const_offset; sym->size = 0; sym->forwarder = "NONE"; sym->bind = "GLOBAL"; sym->type = "OBJECT"; - r_list_append (syscalls, sym); + rz_list_append (syscalls, sym); i = 1; cursor += 24; int num_syscalls = sdb_count (syscall->db); while (cursor < end && i < num_syscalls) { - ut64 addr = r_read_le64 (cursor); - RSyscallItem *item = r_syscall_get (syscall, i, 0x80); + ut64 addr = rz_read_le64 (cursor); + RzSyscallItem *item = rz_syscall_get (syscall, i, 0x80); if (item && item->name) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { goto beach; } - sym->name = r_str_newf ("syscall.%d.%s", i, item->name); + sym->name = rz_str_newf ("syscall.%d.%s", i, item->name); sym->vaddr = addr; sym->paddr = addr; sym->size = 0; sym->forwarder = "NONE"; sym->bind = "GLOBAL"; sym->type = "FUNC"; - r_list_append (syscalls, sym); + rz_list_append (syscalls, sym); - r_syscall_item_free (item); + rz_syscall_item_free (item); } cursor += 24; i++; } - r_syscall_free (syscall); + rz_syscall_free (syscall); R_FREE (data_const); R_FREE (sections); return syscalls; beach: - r_syscall_free (syscall); + rz_syscall_free (syscall); if (syscalls) { - r_list_free (syscalls); + rz_list_free (syscalls); } R_FREE (data_const); R_FREE (sections); @@ -1432,14 +1432,14 @@ static HtPP *mig_hash_new(void) { return hash; } -static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { +static RzList *resolve_mig_subsystem(RKernelCacheObj *obj) { struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (obj->mach0))) { return NULL; } HtPP *mig_hash = NULL; - RList *subsystem = NULL; + RzList *subsystem = NULL; ut8 *data_const = NULL; ut64 data_const_offset = 0, data_const_size = 0, data_const_vaddr = 0; ut64 text_exec_offset = 0, text_exec_size = 0, text_exec_vaddr = 0; @@ -1469,11 +1469,11 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { if (!data_const) { goto beach; } - if (r_buf_read_at (obj->cache_buf, data_const_offset, data_const, data_const_size) < data_const_size) { + if (rz_buf_read_at (obj->cache_buf, data_const_offset, data_const, data_const_size) < data_const_size) { goto beach; } - subsystem = r_list_newf (r_bin_symbol_free); + subsystem = rz_list_newf (rz_bin_symbol_free); if (!subsystem) { goto beach; } @@ -1486,13 +1486,13 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { ut8 *cursor = data_const; ut8 *end = data_const + data_const_size; while (cursor < end) { - ut64 subs_p = K_PPTR (r_read_le64 (cursor)); + ut64 subs_p = K_PPTR (rz_read_le64 (cursor)); if (subs_p < text_exec_vaddr || subs_p >= text_exec_vaddr + text_exec_size) { cursor += 8; continue; } - ut32 subs_min_idx = r_read_le32 (cursor + 8); - ut32 subs_max_idx = r_read_le32 (cursor + 12); + ut32 subs_min_idx = rz_read_le32 (cursor + 8); + ut32 subs_max_idx = rz_read_le32 (cursor + 12); ut32 n_routines = (subs_max_idx - subs_min_idx); if (subs_min_idx >= subs_max_idx || (subs_max_idx - subs_min_idx) > K_MIG_MAX_ROUTINES) { cursor += 16; @@ -1508,13 +1508,13 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { bool is_consistent = true; int idx = 0; while (array_cursor < end_array) { - ut64 should_be_null = r_read_le64 (array_cursor); + ut64 should_be_null = rz_read_le64 (array_cursor); if (should_be_null != 0) { is_consistent = false; break; } - ut64 routine_p = K_PPTR (r_read_le64 (array_cursor + 8)); + ut64 routine_p = K_PPTR (rz_read_le64 (array_cursor + 8)); if (routine_p != 0 && (routine_p < text_exec_vaddr || routine_p >= text_exec_vaddr + text_exec_size)) { is_consistent = false; break; @@ -1542,9 +1542,9 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { const char *key = sdb_fmt ("%d", num); const char *name = sdb_ht_find (mig_hash, key, &found); if (found && name && *name) { - sym->name = r_str_newf ("mig.%d.%s", num, name); + sym->name = rz_str_newf ("mig.%d.%s", num, name); } else { - sym->name = r_str_newf ("mig.%d", num); + sym->name = rz_str_newf ("mig.%d", num); } sym->vaddr = routine_p; @@ -1553,7 +1553,7 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { sym->forwarder = "NONE"; sym->bind = "GLOBAL"; sym->type = "OBJECT"; - r_list_append (subsystem, sym); + rz_list_append (subsystem, sym); } cursor += K_MIG_SUBSYSTEM_SIZE + n_routines * K_MIG_ROUTINE_SIZE; @@ -1571,7 +1571,7 @@ static RList *resolve_mig_subsystem(RKernelCacheObj *obj) { beach: if (subsystem) { - r_list_free (subsystem); + rz_list_free (subsystem); } if (mig_hash) { sdb_ht_free (mig_hash); @@ -1584,17 +1584,17 @@ beach: static ut64 extract_addr_from_code(ut8 *arm64_code, ut64 vaddr) { ut64 addr = vaddr & ~0xfff; - ut64 adrp = r_read_le32 (arm64_code); + ut64 adrp = rz_read_le32 (arm64_code); ut64 adrp_offset = ((adrp & 0x60000000) >> 29) | ((adrp & 0xffffe0) >> 3); addr += adrp_offset << 12; - ut64 ldr = r_read_le32 (arm64_code + 4); + ut64 ldr = rz_read_le32 (arm64_code + 4); addr += ((ldr & 0x3ffc00) >> 10) << ((ldr & 0xc0000000) >> 30); return addr; } -static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCacheObj *obj, RBinFile *bf, RKext *kext, int ordinal) { +static void symbols_from_stubs(RzList *ret, HtPP *kernel_syms_by_addr, RKernelCacheObj *obj, RBinFile *bf, RKext *kext, int ordinal) { RStubsInfo *stubs_info = get_stubs_info(kext->mach0, kext->range.offset, obj); if (!stubs_info) { return; @@ -1604,7 +1604,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac for (; stubs_cursor < stubs_end; stubs_cursor += 12) { ut8 arm64_code[8]; - if (r_buf_read_at (obj->cache_buf, stubs_cursor, arm64_code, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, stubs_cursor, arm64_code, 8) < 8) { break; } @@ -1619,7 +1619,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac while (!found && level-- > 0) { ut64 offset_in_got = addr_in_got - obj->pa2va_exec; ut64 addr; - if (r_buf_read_at (obj->cache_buf, offset_in_got, (ut8*) &addr, 8) < 8) { + if (rz_buf_read_at (obj->cache_buf, offset_in_got, (ut8*) &addr, 8) < 8) { break; } @@ -1635,7 +1635,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac if (!sym) { break; } - sym->name = r_str_newf ("stub.%s", name); + sym->name = rz_str_newf ("stub.%s", name); sym->vaddr = vaddr; sym->paddr = stubs_cursor; sym->size = 12; @@ -1643,7 +1643,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac sym->bind = "LOCAL"; sym->type = "FUNC"; sym->ordinal = ordinal ++; - r_list_append (ret, sym); + rz_list_append (ret, sym); break; } @@ -1655,7 +1655,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac } ensure_kexts_initialized (obj); - RKext *remote_kext = r_kext_index_vget (obj->kexts, target_addr); + RKext *remote_kext = rz_kext_index_vget (obj->kexts, target_addr); if (!remote_kext) { continue; } @@ -1665,7 +1665,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac break; } - remote_sym->name = r_str_newf ("exp.%s.0x%"PFMT64x, kext_short_name (remote_kext), target_addr); + remote_sym->name = rz_str_newf ("exp.%s.0x%"PFMT64x, kext_short_name (remote_kext), target_addr); remote_sym->vaddr = target_addr; remote_sym->paddr = target_addr - obj->pa2va_exec; remote_sym->size = 0; @@ -1673,14 +1673,14 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac remote_sym->bind = "GLOBAL"; remote_sym->type = "FUNC"; remote_sym->ordinal = ordinal ++; - r_list_append (ret, remote_sym); + rz_list_append (ret, remote_sym); RBinSymbol *local_sym = R_NEW0 (RBinSymbol); if (!local_sym) { break; } - local_sym->name = r_str_newf ("stub.%s.0x%"PFMT64x, kext_short_name (remote_kext), target_addr); + local_sym->name = rz_str_newf ("stub.%s.0x%"PFMT64x, kext_short_name (remote_kext), target_addr); local_sym->vaddr = vaddr; local_sym->paddr = stubs_cursor; local_sym->size = 12; @@ -1688,7 +1688,7 @@ static void symbols_from_stubs(RList *ret, HtPP *kernel_syms_by_addr, RKernelCac local_sym->bind = "GLOBAL"; local_sym->type = "FUNC"; local_sym->ordinal = ordinal ++; - r_list_append (ret, local_sym); + rz_list_append (ret, local_sym); } R_FREE (stubs_info); @@ -1766,10 +1766,10 @@ static ut64 baddr(RBinFile *bf) { } static void destroy(RBinFile *bf) { - r_kernel_cache_free ((RKernelCacheObj*) bf->o->bin_obj); + rz_kernel_cache_free ((RKernelCacheObj*) bf->o->bin_obj); } -static void r_kernel_cache_free(RKernelCacheObj *obj) { +static void rz_kernel_cache_free(RKernelCacheObj *obj) { if (!obj) { return; } @@ -1781,29 +1781,29 @@ static void r_kernel_cache_free(RKernelCacheObj *obj) { } if (obj->cache_buf) { - r_buf_free (obj->cache_buf); + rz_buf_free (obj->cache_buf); obj->cache_buf = NULL; } if (obj->prelink_info) { - r_cf_value_dict_free (obj->prelink_info); + rz_cf_value_dict_free (obj->prelink_info); obj->prelink_info = NULL; } if (obj->kexts) { - r_kext_index_free (obj->kexts); + rz_kext_index_free (obj->kexts); obj->kexts = NULL; } if (obj->rebase_info) { - r_rebase_info_free (obj->rebase_info); + rz_rebase_info_free (obj->rebase_info); obj->rebase_info = NULL; } R_FREE (obj); } -static RRebaseInfo *r_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH0_(obj_t) *mach0) { +static RRebaseInfo *rz_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH0_(obj_t) *mach0) { RFileRange *rebase_ranges = NULL; struct section_t *sections = NULL; if (!(sections = MACH0_(get_sections) (mach0))) { @@ -1830,7 +1830,7 @@ static RRebaseInfo *r_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH for (i = 0; i < nsegs; i++) { char segname[17]; seg = &mach0->segs[i]; - r_str_ncpy (segname, seg->segname, 17); + rz_str_ncpy (segname, seg->segname, 17); if (!strncmp (segname, "__TEXT", 6) && segname[6] == '\0') { kernel_base = seg->vmaddr; break; @@ -1853,16 +1853,16 @@ static RRebaseInfo *r_rebase_info_new_from_mach0(RBuffer *cache_buf, struct MACH ut64 multiplier = 4; for (i = 0; i != n_starts; i++) { ut8 bytes[4]; - if (r_buf_read_at (cache_buf, starts_offset + i * 4, bytes, 4) < 4) { + if (rz_buf_read_at (cache_buf, starts_offset + i * 4, bytes, 4) < 4) { goto beach; } if (i == 0) { - multiplier += 4 * (r_read_le32 (bytes) & 1); + multiplier += 4 * (rz_read_le32 (bytes) & 1); continue; } - rebase_ranges[i - 1].offset = r_read_le32 (bytes); + rebase_ranges[i - 1].offset = rz_read_le32 (bytes); rebase_ranges[i - 1].size = UT64_MAX; } @@ -1883,7 +1883,7 @@ beach: return NULL; } -static void r_rebase_info_free(RRebaseInfo *info) { +static void rz_rebase_info_free(RRebaseInfo *info) { if (!info) { return; } @@ -1896,7 +1896,7 @@ static void r_rebase_info_free(RRebaseInfo *info) { R_FREE (info); } -static void r_rebase_info_populate(RRebaseInfo *info, RKernelCacheObj *obj) { +static void rz_rebase_info_populate(RRebaseInfo *info, RKernelCacheObj *obj) { struct section_t *sections = NULL; int i = 0; @@ -1913,7 +1913,7 @@ static void r_rebase_info_populate(RRebaseInfo *info, RKernelCacheObj *obj) { return; } } - info->ranges[i].offset = r_rebase_offset_to_paddr (obj, sections, info->ranges[i].offset); + info->ranges[i].offset = rz_rebase_offset_to_paddr (obj, sections, info->ranges[i].offset); ut64 end = iterate_rebase_list (obj->cache_buf, info->multiplier, info->ranges[i].offset, NULL, NULL); if (end != UT64_MAX) { info->ranges[i].size = end - info->ranges[i].offset + 8; @@ -1926,7 +1926,7 @@ cleanup: R_FREE (sections); } -static ut64 r_rebase_offset_to_paddr (RKernelCacheObj *obj, struct section_t *sections, ut64 offset) { +static ut64 rz_rebase_offset_to_paddr (RKernelCacheObj *obj, struct section_t *sections, ut64 offset) { ut64 vaddr = obj->rebase_info->kernel_base + offset; int i = 0; for (; !sections[i].last; i++) { @@ -1942,11 +1942,11 @@ static ut64 iterate_rebase_list(RBuffer *cache_buf, ut64 multiplier, ut64 start_ ut64 cursor = start_offset; while (true) { - if (r_buf_read_at (cache_buf, cursor, bytes, 8) < 8) { + if (rz_buf_read_at (cache_buf, cursor, bytes, 8) < 8) { return UT64_MAX; } - ut64 decorated_addr = r_read_le64 (bytes); + ut64 decorated_addr = rz_read_le64 (bytes); if (func) { bool carry_on = func (cursor, decorated_addr, user_data); @@ -1965,33 +1965,33 @@ static ut64 iterate_rebase_list(RBuffer *cache_buf, ut64 multiplier, ut64 start_ return cursor; } -static void swizzle_io_read(RKernelCacheObj *obj, RIO *io) { - r_return_if_fail (io && io->desc && io->desc->plugin); - RIOPlugin *plugin = io->desc->plugin; +static void swizzle_io_read(RKernelCacheObj *obj, RzIO *io) { + rz_return_if_fail (io && io->desc && io->desc->plugin); + RzIOPlugin *plugin = io->desc->plugin; obj->original_io_read = plugin->read; plugin->read = &kernelcache_io_read; } -static int kernelcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - r_return_val_if_fail (io, -1); - RCore *core = (RCore*) io->corebind.core; +static int kernelcache_io_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + rz_return_val_if_fail (io, -1); + RzCore *core = (RzCore*) io->corebind.core; if (!core || !core->bin || !core->bin->binfiles) { return -1; } RKernelCacheObj *cache = NULL; - RListIter *iter; + RzListIter *iter; RBinFile *bf; - r_list_foreach (core->bin->binfiles, iter, bf) { + rz_list_foreach (core->bin->binfiles, iter, bf) { if (bf->fd == fd->fd ) { cache = bf->o->bin_obj; if (pending_bin_files) { - RListIter *to_remove = r_list_contains (pending_bin_files, bf); + RzListIter *to_remove = rz_list_contains (pending_bin_files, bf); if (to_remove) { - r_list_delete (pending_bin_files, to_remove); - if (r_list_empty (pending_bin_files)) { - r_list_free (pending_bin_files); + rz_list_delete (pending_bin_files, to_remove); + if (rz_list_empty (pending_bin_files)) { + rz_list_free (pending_bin_files); pending_bin_files = NULL; } } @@ -2001,7 +2001,7 @@ static int kernelcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { } if (!cache) { - r_list_foreach (pending_bin_files, iter, bf) { + rz_list_foreach (pending_bin_files, iter, bf) { if (bf->fd == fd->fd && bf->o) { cache = bf->o->bin_obj; break; @@ -2021,7 +2021,7 @@ static int kernelcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { } if (cache->rebase_info) { - r_rebase_info_populate (cache->rebase_info, cache); + rz_rebase_info_populate (cache->rebase_info, cache); } static ut8 *internal_buffer = NULL; @@ -2050,7 +2050,7 @@ static int kernelcache_io_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return result; } -static void rebase_buffer(RKernelCacheObj *obj, ut64 off, RIODesc *fd, ut8 *buf, int count) { +static void rebase_buffer(RKernelCacheObj *obj, ut64 off, RzIODesc *fd, ut8 *buf, int count) { if (obj->rebasing_buffer) { return; } @@ -2078,7 +2078,7 @@ static void rebase_buffer(RKernelCacheObj *obj, ut64 off, RIODesc *fd, ut8 *buf, obj->rebasing_buffer = false; } -static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RIODesc *fd, ut8 *buf, int count) { +static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RzIODesc *fd, ut8 *buf, int count) { if (kobj->rebasing_buffer) { return; } @@ -2107,10 +2107,10 @@ static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RIODesc *fd, ut ut64 cursor = start + page_idx * page_size + page_start; while (cursor < eob && cursor < end) { ut8 tmp[8]; - if (r_buf_read_at (obj->b, cursor, tmp, 8) != 8) { + if (rz_buf_read_at (obj->b, cursor, tmp, 8) != 8) { break; } - ut64 raw_ptr = r_read_le64 (tmp); + ut64 raw_ptr = rz_read_le64 (tmp); ut64 ptr_value = raw_ptr; ut64 delta = 0; ut64 stride = 8; @@ -2157,7 +2157,7 @@ static void rebase_buffer_fixup(RKernelCacheObj *kobj, ut64 off, RIODesc *fd, ut } ut64 in_buf = cursor - off; if (cursor >= off && cursor <= eob - 8) { - r_write_le64 (&buf[in_buf], ptr_value); + rz_write_le64 (&buf[in_buf], ptr_value); } cursor += delta * stride; if (!delta) { @@ -2182,15 +2182,15 @@ static bool on_rebase_pointer (ut64 offset, ut64 decorated_addr, RRebaseCtx *ctx return false; } - RParsedPointer ptr; - r_parse_pointer (&ptr, decorated_addr, ctx->obj); + RzParsedPointer ptr; + rz_parse_pointer (&ptr, decorated_addr, ctx->obj); - r_write_le64 (&ctx->buf[in_buf], ptr.address); + rz_write_le64 (&ctx->buf[in_buf], ptr.address); return true; } -static bool r_parse_pointer(RParsedPointer *ptr, ut64 decorated_addr, RKernelCacheObj *obj) { +static bool rz_parse_pointer(RzParsedPointer *ptr, ut64 decorated_addr, RKernelCacheObj *obj) { /* * Logic taken from: * https://github.com/Synacktiv/kernelcache-laundering/blob/master/ios12_kernel_cache_helper.py @@ -2212,7 +2212,7 @@ static bool r_parse_pointer(RParsedPointer *ptr, ut64 decorated_addr, RKernelCac return true; } -RBinPlugin r_bin_plugin_xnu_kernelcache = { +RBinPlugin rz_bin_plugin_xnu_kernelcache = { .name = "kernelcache", .desc = "kernelcache bin plugin", .license = "LGPL3", @@ -2227,9 +2227,9 @@ RBinPlugin r_bin_plugin_xnu_kernelcache = { }; #ifndef R2_PLUGIN_INCORE -RLibStruct radare_plugin = { +RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_kernelcache, + .data = &rz_bin_plugin_kernelcache, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_xtr_dyldcache.c b/librz/bin/p/bin_xtr_dyldcache.c similarity index 68% rename from libr/bin/p/bin_xtr_dyldcache.c rename to librz/bin/p/bin_xtr_dyldcache.c index 57180b079a..29751b7a62 100644 --- a/libr/bin/p/bin_xtr_dyldcache.c +++ b/librz/bin/p/bin_xtr_dyldcache.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2009-2019 nibble, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "mach0/dyldcache.h" #include "mach0/mach0.h" static RBinXtrData * extract(RBin *bin, int idx); -static RList * extractall(RBin *bin); +static RzList * extractall(RBin *bin); static RBinXtrData * oneshot(RBin *bin, const ut8 *buf, ut64 size, int idx); -static RList * oneshotall(RBin *bin, const ut8 *buf, ut64 size); +static RzList * oneshotall(RBin *bin, const ut8 *buf, ut64 size); static bool check_buffer(RBuffer *buf) { ut8 b[4] = {0}; - r_buf_read_at (buf, 0, b, sizeof (b)); + rz_buf_read_at (buf, 0, b, sizeof (b)); return !memcmp (buf, "dyld", 4); } static void free_xtr(void *xtr_obj) { - r_bin_dyldcache_free ((struct r_bin_dyldcache_obj_t*)xtr_obj); + rz_bin_dyldcache_free ((struct rz_bin_dyldcache_obj_t*)xtr_obj); } static void destroy(RBin *bin) { @@ -31,7 +31,7 @@ static bool load(RBin *bin) { return false; } if (!bin->cur->xtr_obj) { - bin->cur->xtr_obj = r_bin_dyldcache_new (bin->cur->file); + bin->cur->xtr_obj = rz_bin_dyldcache_new (bin->cur->file); } if (!bin->file) { bin->file = bin->cur->file; @@ -39,8 +39,8 @@ static bool load(RBin *bin) { return bin->cur->xtr_obj? true : false; } -static RList * extractall(RBin *bin) { - RList *result = NULL; +static RzList * extractall(RBin *bin) { + RzList *result = NULL; int nlib, i = 0; RBinXtrData *data = extract (bin, i); if (!data) { @@ -48,15 +48,15 @@ static RList * extractall(RBin *bin) { } // XXX - how do we validate a valid nlib? nlib = data->file_count; - result = r_list_newf (r_bin_xtrdata_free); + result = rz_list_newf (rz_bin_xtrdata_free); if (!result) { - r_bin_xtrdata_free (data); + rz_bin_xtrdata_free (data); return NULL; } - r_list_append (result, data); + rz_list_append (result, data); for (i = 1; data && i < nlib; i++) { data = extract (bin, i); - r_list_append (result, data); + rz_list_append (result, data); } return result; } @@ -73,8 +73,8 @@ static RBinXtrData *extract(RBin *bin, int idx) { RBinXtrData *res = NULL; char *libname; struct MACH0_(mach_header) *hdr; - struct r_bin_dyldcache_lib_t *lib = r_bin_dyldcache_extract ( - (struct r_bin_dyldcache_obj_t*)bin->cur->xtr_obj, idx, &nlib); + struct rz_bin_dyldcache_lib_t *lib = rz_bin_dyldcache_extract ( + (struct rz_bin_dyldcache_obj_t*)bin->cur->xtr_obj, idx, &nlib); if (lib) { RBinXtrMetadata *metadata = R_NEW0(RBinXtrMetadata); @@ -90,11 +90,11 @@ static RBinXtrData *extract(RBin *bin, int idx) { return NULL; } fill_metadata_info_from_hdr (metadata, hdr); - r_bin_dydlcache_get_libname (lib, &libname); + rz_bin_dydlcache_get_libname (lib, &libname); metadata->libname = strdup (libname); - res = r_bin_xtrdata_new (lib->b, lib->offset, lib->size, nlib, metadata); - r_buf_free (lib->b); + res = rz_bin_xtrdata_new (lib->b, lib->offset, lib->size, nlib, metadata); + rz_buf_free (lib->b); free (lib); free (hdr); } @@ -103,8 +103,8 @@ static RBinXtrData *extract(RBin *bin, int idx) { static RBinXtrData *oneshot(RBin *bin, const ut8* buf, ut64 size, int idx) { RBinXtrData *res = NULL; - struct r_bin_dyldcache_obj_t *xtr_obj; - struct r_bin_dyldcache_lib_t *lib; + struct rz_bin_dyldcache_obj_t *xtr_obj; + struct rz_bin_dyldcache_lib_t *lib; int nlib = 0; char *libname; struct MACH0_(mach_header) *hdr; @@ -114,7 +114,7 @@ static RBinXtrData *oneshot(RBin *bin, const ut8* buf, ut64 size, int idx) { } xtr_obj = bin->cur->xtr_obj; - lib = r_bin_dyldcache_extract (xtr_obj, idx, &nlib); + lib = rz_bin_dyldcache_extract (xtr_obj, idx, &nlib); if (!lib) { free_xtr (xtr_obj); bin->cur->xtr_obj = NULL; @@ -132,19 +132,19 @@ static RBinXtrData *oneshot(RBin *bin, const ut8* buf, ut64 size, int idx) { return NULL; } fill_metadata_info_from_hdr (metadata, hdr); - r_bin_dydlcache_get_libname (lib, &libname); + rz_bin_dydlcache_get_libname (lib, &libname); metadata->libname = strdup (libname); - res = r_bin_xtrdata_new (lib->b, lib->offset, r_buf_size (lib->b), nlib, metadata); - r_buf_free (lib->b); + res = rz_bin_xtrdata_new (lib->b, lib->offset, rz_buf_size (lib->b), nlib, metadata); + rz_buf_free (lib->b); free (hdr); free (lib); return res; } -static RList * oneshotall(RBin *bin, const ut8* buf, ut64 size) { +static RzList * oneshotall(RBin *bin, const ut8* buf, ut64 size) { RBinXtrData *data = NULL; - RList *res = NULL; + RzList *res = NULL; int nlib, i = 0; if (!bin->file) { if (!load (bin)) { @@ -157,20 +157,20 @@ static RList * oneshotall(RBin *bin, const ut8* buf, ut64 size) { } // XXX - how do we validate a valid nlib? nlib = data->file_count; - res = r_list_newf (r_bin_xtrdata_free); + res = rz_list_newf (rz_bin_xtrdata_free); if (!res) { - r_bin_xtrdata_free (data); + rz_bin_xtrdata_free (data); return NULL; } - r_list_append (res, data); + rz_list_append (res, data); for (i = 1; data && i < nlib; i++) { data = oneshot (bin, buf, size, i); - r_list_append (res, data); + rz_list_append (res, data); } return res; } -RBinXtrPlugin r_bin_xtr_plugin_xtr_dyldcache = { +RBinXtrPlugin rz_bin_xtr_plugin_xtr_dyldcache = { .name = "xtr.dyldcache", .desc = "dyld cache bin extractor plugin", .license = "LGPL3", @@ -185,9 +185,9 @@ RBinXtrPlugin r_bin_xtr_plugin_xtr_dyldcache = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN_XTR, - .data = &r_bin_xtr_plugin_dyldcache, + .data = &rz_bin_xtr_plugin_dyldcache, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_xtr_fatmach0.c b/librz/bin/p/bin_xtr_fatmach0.c similarity index 67% rename from libr/bin/p/bin_xtr_fatmach0.c rename to librz/bin/p/bin_xtr_fatmach0.c index d1887abdc6..8ad106dfa1 100644 --- a/libr/bin/p/bin_xtr_fatmach0.c +++ b/librz/bin/p/bin_xtr_fatmach0.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2019 - nibble, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include "mach0/fatmach0.h" #include "mach0/mach0.h" @@ -11,14 +11,14 @@ static RBinXtrData * extract(RBin *bin, int idx); static bool checkHeader(RBuffer *b) { ut8 buf[4]; - const ut64 sz = r_buf_size (b); - r_buf_read_at (b, 0, buf, 4); + const ut64 sz = rz_buf_size (b); + rz_buf_read_at (b, 0, buf, 4); if (sz >= 0x300 && !memcmp (buf, "\xca\xfe\xba\xbe", 4)) { ut64 addr = 4 * sizeof (32); - ut64 off = r_buf_read_be32_at (b, addr); + ut64 off = rz_buf_read_be32_at (b, addr); if (off > 0 && off + 4 < sz) { ut64 h = 0; - r_buf_read_at (b, h + off, buf, 4); + rz_buf_read_at (b, h + off, buf, 4); if (!memcmp (buf, "\xce\xfa\xed\xfe", 4) || !memcmp (buf, "\xfe\xed\xfa\xce", 4) || !memcmp (buf, "\xfe\xed\xfa\xcf", 4) || @@ -31,12 +31,12 @@ static bool checkHeader(RBuffer *b) { } static bool check_buffer (RBuffer *buf) { - r_return_val_if_fail (buf, false); + rz_return_val_if_fail (buf, false); return checkHeader (buf); } static void free_xtr (void *xtr_obj) { - r_bin_fatmach0_free ((struct r_bin_fatmach0_obj_t*)xtr_obj); + rz_bin_fatmach0_free ((struct rz_bin_fatmach0_obj_t*)xtr_obj); } static void destroy(RBin *bin) { @@ -44,7 +44,7 @@ static void destroy(RBin *bin) { } static bool load(RBin *bin) { - return ((bin->cur->xtr_obj = r_bin_fatmach0_new (bin->file)) != NULL); + return ((bin->cur->xtr_obj = rz_bin_fatmach0_new (bin->file)) != NULL); } static int size(RBin *bin) { @@ -64,14 +64,14 @@ static inline void fill_metadata_info_from_hdr(RBinXtrMetadata *meta, struct MAC // XXX deprecate static RBinXtrData *extract(RBin* bin, int idx) { int narch; - struct r_bin_fatmach0_obj_t *fb = bin->cur->xtr_obj; - struct r_bin_fatmach0_arch_t *arch = r_bin_fatmach0_extract (fb, idx, &narch); + struct rz_bin_fatmach0_obj_t *fb = bin->cur->xtr_obj; + struct rz_bin_fatmach0_arch_t *arch = rz_bin_fatmach0_extract (fb, idx, &narch); if (!arch) { return NULL; } RBinXtrMetadata *metadata = R_NEW0 (RBinXtrMetadata); if (!metadata) { - r_buf_free (arch->b); + rz_buf_free (arch->b); free (arch); return NULL; } @@ -83,30 +83,30 @@ static RBinXtrData *extract(RBin* bin, int idx) { return NULL; } fill_metadata_info_from_hdr (metadata, hdr); - RBinXtrData * res = r_bin_xtrdata_new (arch->b, arch->offset, arch->size, narch, metadata); - r_buf_free (arch->b); + RBinXtrData * res = rz_bin_xtrdata_new (arch->b, arch->offset, arch->size, narch, metadata); + rz_buf_free (arch->b); free (arch); free (hdr); return res; } static RBinXtrData *oneshot_buffer(RBin *bin, RBuffer *b, int idx) { - r_return_val_if_fail (bin && bin->cur, NULL); + rz_return_val_if_fail (bin && bin->cur, NULL); if (!bin->cur->xtr_obj) { - bin->cur->xtr_obj = r_bin_fatmach0_from_buffer_new (b); + bin->cur->xtr_obj = rz_bin_fatmach0_from_buffer_new (b); } int narch; - struct r_bin_fatmach0_obj_t *fb = bin->cur->xtr_obj; - struct r_bin_fatmach0_arch_t *arch = r_bin_fatmach0_extract (fb, idx, &narch); + struct rz_bin_fatmach0_obj_t *fb = bin->cur->xtr_obj; + struct rz_bin_fatmach0_arch_t *arch = rz_bin_fatmach0_extract (fb, idx, &narch); if (arch) { RBinXtrMetadata *metadata = R_NEW0 (RBinXtrMetadata); if (metadata) { struct MACH0_(mach_header) *hdr = MACH0_(get_hdr) (arch->b); if (hdr) { fill_metadata_info_from_hdr (metadata, hdr); - RBinXtrData *res = r_bin_xtrdata_new (arch->b, arch->offset, arch->size, narch, metadata); - r_buf_free (arch->b); + RBinXtrData *res = rz_bin_xtrdata_new (arch->b, arch->offset, arch->size, narch, metadata); + rz_buf_free (arch->b); free (arch); free (hdr); return res; @@ -118,22 +118,22 @@ static RBinXtrData *oneshot_buffer(RBin *bin, RBuffer *b, int idx) { return NULL; } -static RList * oneshotall_buffer(RBin *bin, RBuffer *b) { +static RzList * oneshotall_buffer(RBin *bin, RBuffer *b) { RBinXtrData *data = oneshot_buffer (bin, b, 0); if (data) { // XXX - how do we validate a valid narch? int narch = data->file_count; - RList *res = r_list_newf (r_bin_xtrdata_free); + RzList *res = rz_list_newf (rz_bin_xtrdata_free); if (!res) { - r_bin_xtrdata_free (data); + rz_bin_xtrdata_free (data); return NULL; } - r_list_append (res, data); + rz_list_append (res, data); int i = 0; for (i = 1; data && i < narch; i++) { data = oneshot_buffer (bin, b, i); if (data) { - r_list_append (res, data); + rz_list_append (res, data); } } return res; @@ -141,7 +141,7 @@ static RList * oneshotall_buffer(RBin *bin, RBuffer *b) { return NULL; } -RBinXtrPlugin r_bin_xtr_plugin_xtr_fatmach0 = { +RBinXtrPlugin rz_bin_xtr_plugin_xtr_fatmach0 = { .name = "xtr.fatmach0", .desc = "fat mach0 bin extractor plugin", .license = "LGPL3", @@ -156,9 +156,9 @@ RBinXtrPlugin r_bin_xtr_plugin_xtr_fatmach0 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN_XTR, - .data = &r_bin_xtr_plugin_fatmach0, + .data = &rz_bin_xtr_plugin_fatmach0, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_xtr_pemixed.c b/librz/bin/p/bin_xtr_pemixed.c similarity index 71% rename from libr/bin/p/bin_xtr_pemixed.c rename to librz/bin/p/bin_xtr_pemixed.c index ccfeab3285..8967406c53 100644 --- a/libr/bin/p/bin_xtr_pemixed.c +++ b/librz/bin/p/bin_xtr_pemixed.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2018-2019 - JohnPeng47 */ -#include -#include -#include -#include +#include +#include +#include +#include #include "pe/pemixed.h" -static RList * oneshotall(RBin *bin, const ut8 *buf, ut64 size); +static RzList * oneshotall(RBin *bin, const ut8 *buf, ut64 size); static RBinXtrData * oneshot(RBin *bin, const ut8 *buf, ut64 size, int subbin_type); static void free_xtr (void *xtr_obj) { - r_bin_pemixed_free ((struct r_bin_pemixed_obj_t*) xtr_obj); + rz_bin_pemixed_free ((struct rz_bin_pemixed_obj_t*) xtr_obj); } static void destroy(RBin *bin) { @@ -47,7 +47,7 @@ static bool check_buffer(RBuffer *b) { } // TODO RBufferify -static RList * oneshotall(RBin *bin, const ut8 *buf, ut64 size) { +static RzList * oneshotall(RBin *bin, const ut8 *buf, ut64 size) { //extract dos componenent first RBinXtrData *data = oneshot (bin, buf, size, SUB_BIN_DOS); @@ -55,22 +55,22 @@ static RList * oneshotall(RBin *bin, const ut8 *buf, ut64 size) { return NULL; } // XXX - how do we validate a valid narch? - RList * res = r_list_newf (r_bin_xtrdata_free); - r_list_append (res, data); + RzList * res = rz_list_newf (rz_bin_xtrdata_free); + rz_list_append (res, data); if ((data = oneshot (bin, buf, size, SUB_BIN_NATIVE))){ - r_list_append (res, data); + rz_list_append (res, data); } if ((data = oneshot (bin, buf, size, SUB_BIN_NET))){ - r_list_append (res, data); + rz_list_append (res, data); } return res; } //implement this later -static void fill_metadata_info_from_hdr(RBinXtrMetadata *meta, void *foo) {// struct Pe_32_r_bin_pemixed_obj_t* pe_bin){ +static void fill_metadata_info_from_hdr(RBinXtrMetadata *meta, void *foo) {// struct Pe_32_rz_bin_pemixed_obj_t* pe_bin){ meta->arch = NULL; meta->bits = 0; meta->machine = NULL; @@ -82,15 +82,15 @@ static void fill_metadata_info_from_hdr(RBinXtrMetadata *meta, void *foo) {// st // XXX: ut8* should be RBuffer * static RBinXtrData * oneshot(RBin *bin, const ut8 *buf, ut64 size, int sub_bin_type) { - r_return_val_if_fail (bin && bin->cur && buf, false); + rz_return_val_if_fail (bin && bin->cur && buf, false); if (!bin->cur->xtr_obj) { - bin->cur->xtr_obj = r_bin_pemixed_from_bytes_new (buf, size); + bin->cur->xtr_obj = rz_bin_pemixed_from_bytes_new (buf, size); } - struct r_bin_pemixed_obj_t* fb = bin->cur->xtr_obj; + struct rz_bin_pemixed_obj_t* fb = bin->cur->xtr_obj; // this function is prolly not nessescary - struct PE_(r_bin_pe_obj_t)* pe = r_bin_pemixed_extract (fb, sub_bin_type); + struct PE_(rz_bin_pe_obj_t)* pe = rz_bin_pemixed_extract (fb, sub_bin_type); if (!pe) { return NULL; } @@ -99,10 +99,10 @@ static RBinXtrData * oneshot(RBin *bin, const ut8 *buf, ut64 size, int sub_bin_t return NULL; } fill_metadata_info_from_hdr (metadata, pe); - return r_bin_xtrdata_new (pe->b, 0, pe->size, 3, metadata); + return rz_bin_xtrdata_new (pe->b, 0, pe->size, 3, metadata); } -RBinXtrPlugin r_bin_xtr_plugin_xtr_pemixed = { +RBinXtrPlugin rz_bin_xtr_plugin_xtr_pemixed = { .name = "xtr.pemixed", .desc = "Extract sub-binaries in PE files", .load = NULL, //not yet implemented @@ -116,9 +116,9 @@ RBinXtrPlugin r_bin_xtr_plugin_xtr_pemixed = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN_XTR, - .data = &r_bin_xtr_plugin_pemixed, + .data = &rz_bin_xtr_plugin_pemixed, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_xtr_sep64.c b/librz/bin/p/bin_xtr_sep64.c similarity index 84% rename from libr/bin/p/bin_xtr_sep64.c rename to librz/bin/p/bin_xtr_sep64.c index e2f666d1a1..2ac9edf1a8 100644 --- a/libr/bin/p/bin_xtr_sep64.c +++ b/librz/bin/p/bin_xtr_sep64.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2019 - nibble, pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #define R_BIN_MACH064 1 #include "../format/mach0/mach0.h" @@ -90,9 +90,9 @@ static inline void fill_metadata_info_from_hdr(RBinXtrMetadata *meta, struct MAC #define BTW(val, min, max) ((val) > min && (val) < max) static bool check_buffer(RBuffer *b) { - r_return_val_if_fail (b, false); + rz_return_val_if_fail (b, false); - const ut64 sz = r_buf_size (b); + const ut64 sz = rz_buf_size (b); if (sz < 0x11c0) { return false; } @@ -126,7 +126,7 @@ static bool check_buffer(RBuffer *b) { } /* check size */ - if (r_buf_read_le64_at (b, hdr_offset + 56) != sz) { + if (rz_buf_read_le64_at (b, hdr_offset + 56) != sz) { return false; } @@ -147,7 +147,7 @@ static int size(RBin *bin) { } static RBinXtrData *oneshot_buffer(RBin *bin, RBuffer *b, int idx) { - r_return_val_if_fail (bin && bin->cur, NULL); + rz_return_val_if_fail (bin && bin->cur, NULL); if (!bin->cur->xtr_obj) { bin->cur->xtr_obj = sep64_xtr_ctx_new (b); @@ -155,27 +155,27 @@ static RBinXtrData *oneshot_buffer(RBin *bin, RBuffer *b, int idx) { RSepXtr64Ctx * ctx = bin->cur->xtr_obj; RSepSlice64 * slice = sep64_xtr_ctx_get_slice (ctx, b, idx); - RBinXtrData * res = r_bin_xtrdata_new (slice->buf, slice->nominal_offset, slice->total_size, 3 + ctx->hdr->n_apps, slice->meta); + RBinXtrData * res = rz_bin_xtrdata_new (slice->buf, slice->nominal_offset, slice->total_size, 3 + ctx->hdr->n_apps, slice->meta); - r_buf_free (slice->buf); + rz_buf_free (slice->buf); free (slice); return res; } -static RList * oneshotall_buffer(RBin *bin, RBuffer *b) { +static RzList * oneshotall_buffer(RBin *bin, RBuffer *b) { RBinXtrData *data = oneshot_buffer (bin, b, 0); if (data) { int narch = data->file_count; - RList *res = r_list_newf (r_bin_xtrdata_free); + RzList *res = rz_list_newf (rz_bin_xtrdata_free); if (!res) { - r_bin_xtrdata_free (data); + rz_bin_xtrdata_free (data); return NULL; } - r_list_append (res, data); + rz_list_append (res, data); int i; for (i = 1; data && i < narch; i++) { data = oneshot_buffer (bin, b, i); - r_list_append (res, data); + rz_list_append (res, data); } return res; } @@ -187,7 +187,7 @@ static RSepXtr64Ctx * sep64_xtr_ctx_new(RBuffer * buf) { RSepApp64 * apps = NULL; RSepXtr64Ctx * ctx = NULL; - ut64 hdr_offset = r_buf_read_le64_at (buf, 0x1014); + ut64 hdr_offset = rz_buf_read_le64_at (buf, 0x1014); if (hdr_offset == UT64_MAX) { goto beach; } @@ -196,7 +196,7 @@ static RSepXtr64Ctx * sep64_xtr_ctx_new(RBuffer * buf) { if (!hdr) { goto beach; } - if (r_buf_fread_at (buf, hdr_offset, (ut8 *) hdr, "16c16l16c16c3l", 1) != sizeof (RSepHdr64)) { + if (rz_buf_fread_at (buf, hdr_offset, (ut8 *) hdr, "16c16l16c16c3l", 1) != sizeof (RSepHdr64)) { goto beach; } @@ -209,7 +209,7 @@ static RSepXtr64Ctx * sep64_xtr_ctx_new(RBuffer * buf) { if (!apps) { goto beach; } - if (r_buf_fread_at (buf, apps_at, (ut8*) apps, "9l2i16c16cl", hdr->n_apps) != (sizeof (RSepApp64) * hdr->n_apps)) { + if (rz_buf_fread_at (buf, apps_at, (ut8*) apps, "9l2i16c16cl", hdr->n_apps) != (sizeof (RSepApp64) * hdr->n_apps)) { goto beach; } @@ -248,7 +248,7 @@ static RSepSlice64 * sep64_xtr_ctx_get_slice(RSepXtr64Ctx * ctx, RBuffer * whole return NULL; } - ut64 whole_size = r_buf_size (whole); + ut64 whole_size = rz_buf_size (whole); RBuffer * slice_buf = NULL; char * name = NULL; RSepSlice64 * slice = NULL; @@ -259,7 +259,7 @@ static RSepSlice64 * sep64_xtr_ctx_get_slice(RSepXtr64Ctx * ctx, RBuffer * whole if (idx == 0) { name = strdup ("boot"); - slice_buf = r_buf_new_slice (whole, 0, ctx->hdr->kernel_base_paddr); + slice_buf = rz_buf_new_slice (whole, 0, ctx->hdr->kernel_base_paddr); total_size = ctx->hdr->kernel_base_paddr; } else if (idx == 1) { name = strdup ("kernel"); @@ -267,7 +267,7 @@ static RSepSlice64 * sep64_xtr_ctx_get_slice(RSepXtr64Ctx * ctx, RBuffer * whole if (!info) { goto beach; } - slice_buf = r_buf_new_slice (whole, ctx->hdr->kernel_base_paddr, info->total_size); + slice_buf = rz_buf_new_slice (whole, ctx->hdr->kernel_base_paddr, info->total_size); nominal_offset = ctx->hdr->kernel_base_paddr; total_size = info->total_size; } else if (idx == 2) { @@ -327,7 +327,7 @@ static RSepSlice64 * sep64_xtr_ctx_get_slice(RSepXtr64Ctx * ctx, RBuffer * whole return slice; beach: - r_buf_free (slice_buf); + rz_buf_free (slice_buf); free (name); free (slice); free (meta); @@ -336,7 +336,7 @@ beach: } static RSepMachoInfo * mach0_info_new(RBuffer * buf, ut64 at, ut64 max_size) { - r_return_val_if_fail (max_size >= 1024, NULL); + rz_return_val_if_fail (max_size >= 1024, NULL); RSepMachoInfo * result = NULL; struct MACH0_(mach_header) *hdr = NULL; @@ -348,7 +348,7 @@ static RSepMachoInfo * mach0_info_new(RBuffer * buf, ut64 at, ut64 max_size) { if (!hdr) { goto beach; } - if (r_buf_read_at (buf, at, (ut8 *) hdr, hdr_size) != hdr_size) { + if (rz_buf_read_at (buf, at, (ut8 *) hdr, hdr_size) != hdr_size) { goto beach; } if (hdr->magic != MH_MAGIC_64 || !BTW (hdr->sizeofcmds, 0, max_size)) { @@ -359,7 +359,7 @@ static RSepMachoInfo * mach0_info_new(RBuffer * buf, ut64 at, ut64 max_size) { if (!commands) { goto beach; } - if (r_buf_read_at (buf, at + hdr_size, commands, hdr->sizeofcmds) != hdr->sizeofcmds) { + if (rz_buf_read_at (buf, at + hdr_size, commands, hdr->sizeofcmds) != hdr->sizeofcmds) { goto beach; } @@ -427,15 +427,15 @@ static RBuffer * extract_slice(RBuffer * whole, RSepMachoInfo * info) { if (!content) { goto beach; } - if (r_buf_read_at (whole, info->text_offset_in_whole, content, info->text_size) != info->text_size) { + if (rz_buf_read_at (whole, info->text_offset_in_whole, content, info->text_size) != info->text_size) { goto beach; } ut64 data_offset = info->data_offset_in_whole ? info->data_offset_in_whole : info->text_offset_in_whole + info->data_offset; - if (r_buf_read_at (whole, data_offset, content + info->data_offset, info->data_size) != info->data_size) { + if (rz_buf_read_at (whole, data_offset, content + info->data_offset, info->data_size) != info->data_size) { goto beach; } - return r_buf_new_with_pointers (content, info->total_size, true); + return rz_buf_new_with_pointers (content, info->total_size, true); beach: free (content); @@ -468,10 +468,10 @@ static char * get_proper_name (const char * app_name) { } static ut32 read_arm64_ins(RBuffer *b, int idx) { - return r_buf_read_le32_at (b, idx * 4); + return rz_buf_read_le32_at (b, idx * 4); } -RBinXtrPlugin r_bin_xtr_plugin_xtr_sep64 = { +RBinXtrPlugin rz_bin_xtr_plugin_xtr_sep64 = { .name = "xtr.sep64", .desc = "64-bit SEP bin extractor plugin", .license = "LGPL3", @@ -485,9 +485,9 @@ RBinXtrPlugin r_bin_xtr_plugin_xtr_sep64 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN_XTR, - .data = &r_bin_xtr_plugin_xtr_sep64, + .data = &rz_bin_xtr_plugin_xtr_sep64, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_z64.c b/librz/bin/p/bin_z64.c similarity index 79% rename from libr/bin/p/bin_z64.c rename to librz/bin/p/bin_z64.c index efa4c1dc13..da6997ec31 100644 --- a/libr/bin/p/bin_z64.c +++ b/librz/bin/p/bin_z64.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL 3 - Copyright 2018-2019 - lowlyw */ +/* rizin - LGPL 3 - Copyright 2018-2019 - lowlyw */ /* * info comes from here. @@ -6,12 +6,12 @@ * http://en64.shoutwiki.com/wiki/N64_Memory */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define N64_ROM_START 0x1000 @@ -66,30 +66,30 @@ typedef struct { static N64Header n64_header; static ut64 baddr(RBinFile *bf) { - return (ut64) r_read_be32(&n64_header.BootAddress); + return (ut64) rz_read_be32(&n64_header.BootAddress); } static bool check_buffer(RBuffer *b) { ut8 magic[4]; - if (r_buf_size (b) < N64_ROM_START) { + if (rz_buf_size (b) < N64_ROM_START) { return false; } - (void)r_buf_read_at (b, 0, magic, sizeof (magic)); + (void)rz_buf_read_at (b, 0, magic, sizeof (magic)); return !memcmp (magic, "\x80\x37\x12\x40", 4); } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb) { if (check_buffer (b)) { ut8 buf[sizeof (N64Header)] = {0}; - r_buf_read_at (b, 0, buf, sizeof (buf)); + rz_buf_read_at (b, 0, buf, sizeof (buf)); *bin_obj = memcpy (&n64_header, buf, sizeof (N64Header)); return true; } return false; } -static RList *entries(RBinFile *bf) { - RList /**/ *ret = r_list_newf (free); +static RzList *entries(RBinFile *bf) { + RzList /**/ *ret = rz_list_newf (free); if (!ret) { return NULL; } @@ -97,29 +97,29 @@ static RList *entries(RBinFile *bf) { if (ptr) { ptr->paddr = N64_ROM_START; ptr->vaddr = baddr (bf); - r_list_append (ret, ptr); + rz_list_append (ret, ptr); } return ret; } -static RList *sections(RBinFile *bf) { - RList /**/ *ret = r_list_new (); +static RzList *sections(RBinFile *bf) { + RzList /**/ *ret = rz_list_new (); if (!ret) { return NULL; } RBinSection *text = R_NEW0 (RBinSection); if (!text) { - r_list_free (ret); + rz_list_free (ret); return NULL; } text->name = strdup ("text"); - text->size = r_buf_size (bf->buf) - N64_ROM_START; + text->size = rz_buf_size (bf->buf) - N64_ROM_START; text->vsize = text->size; text->paddr = N64_ROM_START; text->vaddr = baddr (bf); text->perm = R_PERM_RX; text->add = true; - r_list_append (ret, text); + rz_list_append (ret, text); return ret; } @@ -134,7 +134,7 @@ static RBinInfo *info(RBinFile *bf) { return NULL; } memcpy (GameName, n64_header.Name, sizeof (n64_header.Name)); - ret->file = r_str_newf ("%s (%c)", GameName, n64_header.CountryCode); + ret->file = rz_str_newf ("%s (%c)", GameName, n64_header.CountryCode); ret->os = strdup ("n64"); ret->arch = strdup ("mips"); ret->machine = strdup ("Nintendo 64"); @@ -147,9 +147,9 @@ static RBinInfo *info(RBinFile *bf) { #if !R_BIN_Z64 -RBinPlugin r_bin_plugin_z64 = { +RBinPlugin rz_bin_plugin_z64 = { .name = "z64", - .desc = "Nintendo 64 binaries big endian r_bin plugin", + .desc = "Nintendo 64 binaries big endian rz_bin plugin", .license = "LGPL3", .load_buffer = &load_buffer, .check_buffer = &check_buffer, @@ -161,9 +161,9 @@ RBinPlugin r_bin_plugin_z64 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_z64, + .data = &rz_bin_plugin_z64, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bin_zimg.c b/librz/bin/p/bin_zimg.c similarity index 77% rename from libr/bin/p/bin_zimg.c rename to librz/bin/p/bin_zimg.c index 3c70e39726..d8b8c5707c 100644 --- a/libr/bin/p/bin_zimg.c +++ b/librz/bin/p/bin_zimg.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2011-2019 - ninjahacker */ -#include -#include -#include -#include +#include +#include +#include +#include #include "zimg/zimg.h" static Sdb *get_sdb(RBinFile *bf) { - r_return_val_if_fail (bf && bf->o, false); - struct r_bin_zimg_obj_t *bin = (struct r_bin_zimg_obj_t *) bf->o->bin_obj; + rz_return_val_if_fail (bf && bf->o, false); + struct rz_bin_zimg_obj_t *bin = (struct rz_bin_zimg_obj_t *) bf->o->bin_obj; return bin? bin->kv: NULL; } static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb){ - *bin_obj = r_bin_zimg_new_buf (b); + *bin_obj = rz_bin_zimg_new_buf (b); return *bin_obj != NULL; } @@ -23,7 +23,7 @@ static ut64 baddr(RBinFile *bf) { static bool check_buffer(RBuffer *b) { ut8 zimghdr[8]; - if (r_buf_read_at (b, 0, zimghdr, sizeof (zimghdr))) { + if (rz_buf_read_at (b, 0, zimghdr, sizeof (zimghdr))) { // Checking ARM zImage kernel if (!memcmp (zimghdr, "\x00\x00\xa0\xe1\x00\x00\xa0\xe1", 8)) { return true; @@ -53,7 +53,7 @@ static RBinInfo *info(RBinFile *bf) { return ret; } -RBinPlugin r_bin_plugin_zimg = { +RBinPlugin rz_bin_plugin_zimg = { .name = "zimg", .desc = "zimg format bin plugin", .license = "LGPL3", @@ -65,9 +65,9 @@ RBinPlugin r_bin_plugin_zimg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BIN, - .data = &r_bin_plugin_zimg, + .data = &rz_bin_plugin_zimg, .version = R2_VERSION }; #endif diff --git a/libr/bin/p/bios.mk b/librz/bin/p/bios.mk similarity index 100% rename from libr/bin/p/bios.mk rename to librz/bin/p/bios.mk diff --git a/libr/bin/p/bootimg.mk b/librz/bin/p/bootimg.mk similarity index 100% rename from libr/bin/p/bootimg.mk rename to librz/bin/p/bootimg.mk diff --git a/libr/bin/p/cgc.mk b/librz/bin/p/cgc.mk similarity index 80% rename from libr/bin/p/cgc.mk rename to librz/bin/p/cgc.mk index d0e49819c5..9016f442a6 100644 --- a/libr/bin/p/cgc.mk +++ b/librz/bin/p/cgc.mk @@ -2,7 +2,7 @@ OBJ_CGC=bin_cgc.o STATIC_OBJ+=${OBJ_CGC} TARGET_CGC=bin_cgc.${EXT_SO} -#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a +#LINK+=-L../../util -lrz_util $(SHLR)/sdb/src/libsdb.a ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_CGC} diff --git a/libr/bin/p/coff.mk b/librz/bin/p/coff.mk similarity index 100% rename from libr/bin/p/coff.mk rename to librz/bin/p/coff.mk diff --git a/libr/bin/p/dex.mk b/librz/bin/p/dex.mk similarity index 100% rename from libr/bin/p/dex.mk rename to librz/bin/p/dex.mk diff --git a/libr/bin/p/dmp64.mk b/librz/bin/p/dmp64.mk similarity index 100% rename from libr/bin/p/dmp64.mk rename to librz/bin/p/dmp64.mk diff --git a/libr/bin/p/dol.mk b/librz/bin/p/dol.mk similarity index 85% rename from libr/bin/p/dol.mk rename to librz/bin/p/dol.mk index 07345bdebe..8d9fdf477c 100644 --- a/libr/bin/p/dol.mk +++ b/librz/bin/p/dol.mk @@ -8,8 +8,8 @@ ALL_TARGETS+=${TARGET_DOLPHIN} ${TARGET_DOLPHIN}: ${OBJ_DOLPHIN} ifeq ($(CC),cccl) ${CC} $(call libname,bin_dol) ${CFLAGS} $(OBJ_DOLPHIN) $(LINK) $(LDFLAGS) \ - -L../../magic -llibr_magic + -L../../magic -llibrz_magic else ${CC} $(call libname,bin_dol) ${CFLAGS} $(OBJ_DOLPHIN) $(LINK) $(LDFLAGS) \ - -L../../magic -lr_magic + -L../../magic -lrz_magic endif diff --git a/libr/bin/p/dyldcache.mk b/librz/bin/p/dyldcache.mk similarity index 100% rename from libr/bin/p/dyldcache.mk rename to librz/bin/p/dyldcache.mk diff --git a/libr/bin/p/elf.mk b/librz/bin/p/elf.mk similarity index 85% rename from libr/bin/p/elf.mk rename to librz/bin/p/elf.mk index 8f4d33215d..58b0eb0807 100644 --- a/libr/bin/p/elf.mk +++ b/librz/bin/p/elf.mk @@ -1,6 +1,6 @@ OBJ_ELF=bin_elf.o bin_dbginfo_elf.o bin_write_elf.o OBJ_ELF+=../format/elf/elf.o ../format/elf/elf_write.o -#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a +#LINK+=-L../../util -lrz_util $(SHLR)/sdb/src/libsdb.a STATIC_OBJ+=${OBJ_ELF} TARGET_ELF=bin_elf.${EXT_SO} diff --git a/libr/bin/p/elf64.mk b/librz/bin/p/elf64.mk similarity index 100% rename from libr/bin/p/elf64.mk rename to librz/bin/p/elf64.mk diff --git a/libr/bin/p/fs.mk b/librz/bin/p/fs.mk similarity index 100% rename from libr/bin/p/fs.mk rename to librz/bin/p/fs.mk diff --git a/libr/bin/p/java.mk b/librz/bin/p/java.mk similarity index 90% rename from libr/bin/p/java.mk rename to librz/bin/p/java.mk index e5ebb1db99..f710630078 100644 --- a/libr/bin/p/java.mk +++ b/librz/bin/p/java.mk @@ -13,5 +13,5 @@ ALL_TARGETS+=${TARGET_JAVA} ${TARGET_JAVA}: ${OBJ_JAVA} ${CC} $(call libname,bin_java) ${CFLAGS} ${OBJ_JAVA} \ $(LINK) $(LDFLAGS) ${SHARED2_JAVA} \ - ${SHLR}/java/libr_java.${EXT_AR} \ + ${SHLR}/java/librz_java.${EXT_AR} \ ${SHLR}/sdb/src/libsdb.${EXT_AR} diff --git a/libr/bin/p/ldr_linux.mk b/librz/bin/p/ldr_linux.mk similarity index 100% rename from libr/bin/p/ldr_linux.mk rename to librz/bin/p/ldr_linux.mk diff --git a/libr/bin/p/le.mk b/librz/bin/p/le.mk similarity index 100% rename from libr/bin/p/le.mk rename to librz/bin/p/le.mk diff --git a/libr/bin/p/mach0.mk b/librz/bin/p/mach0.mk similarity index 100% rename from libr/bin/p/mach0.mk rename to librz/bin/p/mach0.mk diff --git a/libr/bin/p/mach064.mk b/librz/bin/p/mach064.mk similarity index 100% rename from libr/bin/p/mach064.mk rename to librz/bin/p/mach064.mk diff --git a/libr/bin/p/mbn.mk b/librz/bin/p/mbn.mk similarity index 80% rename from libr/bin/p/mbn.mk rename to librz/bin/p/mbn.mk index 56aa1d5dfa..c97c831740 100644 --- a/libr/bin/p/mbn.mk +++ b/librz/bin/p/mbn.mk @@ -2,7 +2,7 @@ OBJ_MBN=bin_mbn.o STATIC_OBJ+=${OBJ_MBN} TARGET_MBN=bin_mbn.${EXT_SO} -#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a +#LINK+=-L../../util -lrz_util $(SHLR)/sdb/src/libsdb.a ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_MBN} diff --git a/libr/bin/p/mdmp.mk b/librz/bin/p/mdmp.mk similarity index 100% rename from libr/bin/p/mdmp.mk rename to librz/bin/p/mdmp.mk diff --git a/libr/bin/p/menuet.mk b/librz/bin/p/menuet.mk similarity index 100% rename from libr/bin/p/menuet.mk rename to librz/bin/p/menuet.mk diff --git a/libr/bin/p/mz.mk b/librz/bin/p/mz.mk similarity index 100% rename from libr/bin/p/mz.mk rename to librz/bin/p/mz.mk diff --git a/libr/bin/p/ne.mk b/librz/bin/p/ne.mk similarity index 100% rename from libr/bin/p/ne.mk rename to librz/bin/p/ne.mk diff --git a/libr/bin/p/nes.mk b/librz/bin/p/nes.mk similarity index 100% rename from libr/bin/p/nes.mk rename to librz/bin/p/nes.mk diff --git a/libr/bin/p/nin3ds.mk b/librz/bin/p/nin3ds.mk similarity index 85% rename from libr/bin/p/nin3ds.mk rename to librz/bin/p/nin3ds.mk index c3a54a8829..643b701d3f 100644 --- a/libr/bin/p/nin3ds.mk +++ b/librz/bin/p/nin3ds.mk @@ -8,8 +8,8 @@ ALL_TARGETS+=${TARGET_NIN3DS} ${TARGET_NIN3DS}: ${OBJ_NIN3DS} ifeq ($(CC),cccl) ${CC} $(call libname,bin_nin3ds) ${CFLAGS} $(OBJ_NIN3DS) $(LINK) $(LDFLAGS) \ - -L../../magic -llibr_magic + -L../../magic -llibrz_magic else ${CC} $(call libname,bin_nin3ds) ${CFLAGS} $(OBJ_NIN3DS) $(LINK) $(LDFLAGS) \ - -L../../magic -lr_magic + -L../../magic -lrz_magic endif diff --git a/libr/bin/p/ninds.mk b/librz/bin/p/ninds.mk similarity index 85% rename from libr/bin/p/ninds.mk rename to librz/bin/p/ninds.mk index 72083ec798..87d80f0386 100644 --- a/libr/bin/p/ninds.mk +++ b/librz/bin/p/ninds.mk @@ -8,8 +8,8 @@ ALL_TARGETS+=${TARGET_NINDS} ${TARGET_NINDS}: ${OBJ_NINDS} ifeq ($(CC),cccl) ${CC} $(call libname,bin_ninds) ${CFLAGS} $(OBJ_NINDS) $(LINK) $(LDFLAGS) \ - -L../../magic -llibr_magic + -L../../magic -llibrz_magic else ${CC} $(call libname,bin_ninds) ${CFLAGS} $(OBJ_NINDS) $(LINK) $(LDFLAGS) \ - -L../../magic -lr_magic + -L../../magic -lrz_magic endif diff --git a/libr/bin/p/ningb.mk b/librz/bin/p/ningb.mk similarity index 100% rename from libr/bin/p/ningb.mk rename to librz/bin/p/ningb.mk diff --git a/libr/bin/p/ningba.mk b/librz/bin/p/ningba.mk similarity index 100% rename from libr/bin/p/ningba.mk rename to librz/bin/p/ningba.mk diff --git a/libr/bin/p/nro.mk b/librz/bin/p/nro.mk similarity index 100% rename from libr/bin/p/nro.mk rename to librz/bin/p/nro.mk diff --git a/libr/bin/p/nso.mk b/librz/bin/p/nso.mk similarity index 100% rename from libr/bin/p/nso.mk rename to librz/bin/p/nso.mk diff --git a/libr/bin/p/omf.mk b/librz/bin/p/omf.mk similarity index 100% rename from libr/bin/p/omf.mk rename to librz/bin/p/omf.mk diff --git a/libr/bin/p/p9.mk b/librz/bin/p/p9.mk similarity index 100% rename from libr/bin/p/p9.mk rename to librz/bin/p/p9.mk diff --git a/libr/bin/p/pe.mk b/librz/bin/p/pe.mk similarity index 100% rename from libr/bin/p/pe.mk rename to librz/bin/p/pe.mk diff --git a/libr/bin/p/pe64.mk b/librz/bin/p/pe64.mk similarity index 100% rename from libr/bin/p/pe64.mk rename to librz/bin/p/pe64.mk diff --git a/libr/bin/p/pebble.mk b/librz/bin/p/pebble.mk similarity index 100% rename from libr/bin/p/pebble.mk rename to librz/bin/p/pebble.mk diff --git a/libr/bin/p/prg.mk b/librz/bin/p/prg.mk similarity index 100% rename from libr/bin/p/prg.mk rename to librz/bin/p/prg.mk diff --git a/libr/bin/p/psxexe.mk b/librz/bin/p/psxexe.mk similarity index 100% rename from libr/bin/p/psxexe.mk rename to librz/bin/p/psxexe.mk diff --git a/libr/bin/p/pyc.mk b/librz/bin/p/pyc.mk similarity index 94% rename from libr/bin/p/pyc.mk rename to librz/bin/p/pyc.mk index 6cb3ce6873..e1f016776f 100644 --- a/libr/bin/p/pyc.mk +++ b/librz/bin/p/pyc.mk @@ -10,5 +10,5 @@ CFLAGS+=-I../format/pyc/ ALL_TARGETS+=${TARGET_PYC} ${TARGET_PYC}: ${OBJ_PYC} - ${CC} ${CFLAGS} -o ${TARGET_PYC} ${OBJ_PYC} $(R2_CFLAGS) $(R2_LDFLAGS) -lr_util + ${CC} ${CFLAGS} -o ${TARGET_PYC} ${OBJ_PYC} $(R2_CFLAGS) $(R2_LDFLAGS) -lrz_util diff --git a/libr/bin/p/qnx.mk b/librz/bin/p/qnx.mk similarity index 100% rename from libr/bin/p/qnx.mk rename to librz/bin/p/qnx.mk diff --git a/libr/bin/p/sfc.mk b/librz/bin/p/sfc.mk similarity index 100% rename from libr/bin/p/sfc.mk rename to librz/bin/p/sfc.mk diff --git a/libr/bin/p/smd.mk b/librz/bin/p/smd.mk similarity index 100% rename from libr/bin/p/smd.mk rename to librz/bin/p/smd.mk diff --git a/libr/bin/p/sms.mk b/librz/bin/p/sms.mk similarity index 100% rename from libr/bin/p/sms.mk rename to librz/bin/p/sms.mk diff --git a/libr/bin/p/spc700.mk b/librz/bin/p/spc700.mk similarity index 100% rename from libr/bin/p/spc700.mk rename to librz/bin/p/spc700.mk diff --git a/libr/bin/p/symbols.mk b/librz/bin/p/symbols.mk similarity index 100% rename from libr/bin/p/symbols.mk rename to librz/bin/p/symbols.mk diff --git a/libr/bin/p/te.mk b/librz/bin/p/te.mk similarity index 79% rename from libr/bin/p/te.mk rename to librz/bin/p/te.mk index 5b3d67480c..069a009783 100644 --- a/libr/bin/p/te.mk +++ b/librz/bin/p/te.mk @@ -2,7 +2,7 @@ OBJ_TE=bin_te.o ../format/te/te.o STATIC_OBJ+=${OBJ_TE} TARGET_TE=bin_te.${EXT_SO} -#LINK+=-L../../util -lr_util $(SHLR)/sdb/src/libsdb.a +#LINK+=-L../../util -lrz_util $(SHLR)/sdb/src/libsdb.a ALL_TARGETS+=${TARGET_TE} diff --git a/libr/bin/p/vsf.mk b/librz/bin/p/vsf.mk similarity index 100% rename from libr/bin/p/vsf.mk rename to librz/bin/p/vsf.mk diff --git a/libr/bin/p/wasm.mk b/librz/bin/p/wasm.mk similarity index 100% rename from libr/bin/p/wasm.mk rename to librz/bin/p/wasm.mk diff --git a/libr/bin/p/xbe.mk b/librz/bin/p/xbe.mk similarity index 100% rename from libr/bin/p/xbe.mk rename to librz/bin/p/xbe.mk diff --git a/libr/bin/p/xnu_kernelcache.mk b/librz/bin/p/xnu_kernelcache.mk similarity index 80% rename from libr/bin/p/xnu_kernelcache.mk rename to librz/bin/p/xnu_kernelcache.mk index fbde72f74f..bbeb2cff29 100644 --- a/libr/bin/p/xnu_kernelcache.mk +++ b/librz/bin/p/xnu_kernelcache.mk @@ -1,5 +1,5 @@ OBJ_XNU_KERNELCACHE=bin_xnu_kernelcache.o -OBJ_XNU_KERNELCACHE+=../format/xnu/r_cf_dict.o +OBJ_XNU_KERNELCACHE+=../format/xnu/rz_cf_dict.o LINK+=$(STOP)/yxml/libyxml.a CFLAGS+=-I$(STOP)/yxml/ @@ -13,5 +13,5 @@ ALL_TARGETS+=${TARGET_XNU_KERNELCACHE} ${TARGET_XNU_KERNELCACHE}: ${OBJ_XNU_KERNELCACHE} -${CC} $(call libname,bin_xnu_kernelcache) -shared ${CFLAGS} \ -o ${TARGET_XNU_KERNELCACHE} ${OBJ_XNU_KERNELCACHE} $(LINK) $(LDFLAGS) \ - ${LDFLAGS_LINKPATH}../../syscall -L../../util -lr_syscall + ${LDFLAGS_LINKPATH}../../syscall -L../../util -lrz_syscall endif diff --git a/libr/bin/p/xtr_dyldcache.mk b/librz/bin/p/xtr_dyldcache.mk similarity index 100% rename from libr/bin/p/xtr_dyldcache.mk rename to librz/bin/p/xtr_dyldcache.mk diff --git a/libr/bin/p/xtr_fatmach0.mk b/librz/bin/p/xtr_fatmach0.mk similarity index 100% rename from libr/bin/p/xtr_fatmach0.mk rename to librz/bin/p/xtr_fatmach0.mk diff --git a/libr/bin/p/xtr_pemixed.mk b/librz/bin/p/xtr_pemixed.mk similarity index 100% rename from libr/bin/p/xtr_pemixed.mk rename to librz/bin/p/xtr_pemixed.mk diff --git a/libr/bin/p/xtr_sep64.mk b/librz/bin/p/xtr_sep64.mk similarity index 100% rename from libr/bin/p/xtr_sep64.mk rename to librz/bin/p/xtr_sep64.mk diff --git a/libr/bin/p/z64.mk b/librz/bin/p/z64.mk similarity index 100% rename from libr/bin/p/z64.mk rename to librz/bin/p/z64.mk diff --git a/libr/bin/p/zimg.mk b/librz/bin/p/zimg.mk similarity index 100% rename from libr/bin/p/zimg.mk rename to librz/bin/p/zimg.mk diff --git a/libr/bin/pdb/dbi.c b/librz/bin/pdb/dbi.c similarity index 96% rename from libr/bin/pdb/dbi.c rename to librz/bin/pdb/dbi.c index 8aa944503f..a7cfdc3eb1 100644 --- a/libr/bin/pdb/dbi.c +++ b/librz/bin/pdb/dbi.c @@ -10,14 +10,14 @@ static void free_dbi_stream(void *stream) { SDbiStream *t = (SDbiStream *) stream; SDBIExHeader *dbi_ex_header = 0; - RListIter *it = r_list_iterator(t->dbiexhdrs); - while (r_list_iter_next(it)) { - dbi_ex_header = (SDBIExHeader *) r_list_iter_get(it); + RzListIter *it = rz_list_iterator(t->dbiexhdrs); + while (rz_list_iter_next(it)) { + dbi_ex_header = (SDBIExHeader *) rz_list_iter_get(it); free(dbi_ex_header->modName.name); free(dbi_ex_header->objName.name); free(dbi_ex_header); } - r_list_free (t->dbiexhdrs); + rz_list_free (t->dbiexhdrs); } /////////////////////////////////////////////////////////////////////////////// @@ -136,7 +136,7 @@ void parse_dbi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream_file) { } stream_file_read (stream_file, size, dbiexhdr_data); - dbi_stream->dbiexhdrs = r_list_new (); + dbi_stream->dbiexhdrs = rz_list_new (); p_tmp = dbiexhdr_data; while (i < size) { dbi_ex_header = (SDBIExHeader *) malloc (sizeof(SDBIExHeader)); @@ -150,7 +150,7 @@ void parse_dbi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream_file) { } i += sz; p_tmp += sz; - r_list_append (dbi_stream->dbiexhdrs, dbi_ex_header); + rz_list_append (dbi_stream->dbiexhdrs, dbi_ex_header); } free (dbiexhdr_data); diff --git a/libr/bin/pdb/dbi.h b/librz/bin/pdb/dbi.h similarity index 100% rename from libr/bin/pdb/dbi.h rename to librz/bin/pdb/dbi.h diff --git a/libr/bin/pdb/fpo.c b/librz/bin/pdb/fpo.c similarity index 83% rename from libr/bin/pdb/fpo.c rename to librz/bin/pdb/fpo.c index d291e10b03..95cce6591c 100644 --- a/libr/bin/pdb/fpo.c +++ b/librz/bin/pdb/fpo.c @@ -43,7 +43,7 @@ void parse_fpo_stream(void *stream, R_STREAM_FILE *stream_file) stream_file_get_data(stream_file, data); fpo_stream = (SFPOStream *) stream; - fpo_stream->fpo_data_list = r_list_new (); + fpo_stream->fpo_data_list = rz_list_new (); ptmp = data; while (read_bytes < data_size) { fpo_data = (SFPO_DATA *) malloc(sizeof(SFPO_DATA)); @@ -55,7 +55,7 @@ void parse_fpo_stream(void *stream, R_STREAM_FILE *stream_file) break; } - r_list_append (fpo_stream->fpo_data_list, fpo_data); + rz_list_append (fpo_stream->fpo_data_list, fpo_data); } free(data); @@ -65,30 +65,30 @@ void parse_fpo_stream(void *stream, R_STREAM_FILE *stream_file) void free_fpo_stream(void *stream) { SFPOStream *fpo_stream = (SFPOStream *) stream; - RListIter *it = 0; + RzListIter *it = 0; SFPO_DATA *fpo_data = 0; - it = r_list_iterator(fpo_stream->fpo_data_list); - while (r_list_iter_next(it)) { - fpo_data = (SFPO_DATA *) r_list_iter_get(it); + it = rz_list_iterator(fpo_stream->fpo_data_list); + while (rz_list_iter_next(it)) { + fpo_data = (SFPO_DATA *) rz_list_iter_get(it); free(fpo_data); } - r_list_free (fpo_stream->fpo_data_list); + rz_list_free (fpo_stream->fpo_data_list); } /////////////////////////////////////////////////////////////////////////////// void free_fpo_new_stream(void *stream) { SFPONewStream *fpo_stream = (SFPONewStream *) stream; - RListIter *it = 0; + RzListIter *it = 0; SFPO_DATA_V2 *fpo_data = 0; - it = r_list_iterator(fpo_stream->fpo_data_list); - while (r_list_iter_next(it)) { - fpo_data = (SFPO_DATA_V2 *) r_list_iter_get(it); + it = rz_list_iterator(fpo_stream->fpo_data_list); + while (rz_list_iter_next(it)) { + fpo_data = (SFPO_DATA_V2 *) rz_list_iter_get(it); free(fpo_data); } - r_list_free (fpo_stream->fpo_data_list); + rz_list_free (fpo_stream->fpo_data_list); } /////////////////////////////////////////////////////////////////////////////// @@ -108,7 +108,7 @@ void parse_fpo_new_stream(void *stream, R_STREAM_FILE *stream_file) stream_file_get_data (stream_file, data); fpo_stream = (SFPONewStream *) stream; - fpo_stream->fpo_data_list = r_list_new (); + fpo_stream->fpo_data_list = rz_list_new (); ptmp = data; while (read_bytes < data_size) { fpo_data = (SFPO_DATA_V2 *) malloc (sizeof(SFPO_DATA_V2)); @@ -124,7 +124,7 @@ void parse_fpo_new_stream(void *stream, R_STREAM_FILE *stream_file) break; } - r_list_append (fpo_stream->fpo_data_list, fpo_data); + rz_list_append (fpo_stream->fpo_data_list, fpo_data); } free (data); diff --git a/libr/bin/pdb/fpo.h b/librz/bin/pdb/fpo.h similarity index 100% rename from libr/bin/pdb/fpo.h rename to librz/bin/pdb/fpo.h diff --git a/libr/bin/pdb/gdata.c b/librz/bin/pdb/gdata.c similarity index 87% rename from libr/bin/pdb/gdata.c rename to librz/bin/pdb/gdata.c index 1d17b6a18c..bf4192cd03 100644 --- a/libr/bin/pdb/gdata.c +++ b/librz/bin/pdb/gdata.c @@ -28,7 +28,7 @@ void parse_gdata_stream(void *stream, R_STREAM_FILE *stream_file) { SGDATAStream *data_stream = (SGDATAStream *) stream; SGlobal *global = 0; - data_stream->globals_list = r_list_new (); + data_stream->globals_list = rz_list_new (); while (1) { stream_file_read (stream_file, 2, (char *)&len); if (len == 0) { @@ -49,7 +49,7 @@ void parse_gdata_stream(void *stream, R_STREAM_FILE *stream_file) { } global->leaf_type = leaf_type; parse_global (data + 2, len, global); - r_list_append (data_stream->globals_list, global); + rz_list_append (data_stream->globals_list, global); } free (data); } @@ -70,15 +70,15 @@ void parse_gdata_stream(void *stream, R_STREAM_FILE *stream_file) { void free_gdata_stream(void *stream) { SGDATAStream *data_stream = (SGDATAStream *) stream; SGlobal *global = 0; - RListIter *it = 0; + RzListIter *it = 0; - it = r_list_iterator(data_stream->globals_list); - while (r_list_iter_next(it)) { - global = (SGlobal *) r_list_iter_get(it); + it = rz_list_iterator(data_stream->globals_list); + while (rz_list_iter_next(it)) { + global = (SGlobal *) rz_list_iter_get(it); if (global->name.name) { free (global->name.name); } free (global); } - r_list_free (data_stream->globals_list); + rz_list_free (data_stream->globals_list); } diff --git a/libr/bin/pdb/gdata.h b/librz/bin/pdb/gdata.h similarity index 100% rename from libr/bin/pdb/gdata.h rename to librz/bin/pdb/gdata.h diff --git a/libr/bin/pdb/main.c b/librz/bin/pdb/main.c similarity index 98% rename from libr/bin/pdb/main.c rename to librz/bin/pdb/main.c index a73a8e32a8..d01320b166 100644 --- a/libr/bin/pdb/main.c +++ b/librz/bin/pdb/main.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/libr/bin/pdb/omap.c b/librz/bin/pdb/omap.c similarity index 82% rename from libr/bin/pdb/omap.c rename to librz/bin/pdb/omap.c index e80acd826d..9977fe18e2 100644 --- a/libr/bin/pdb/omap.c +++ b/librz/bin/pdb/omap.c @@ -27,7 +27,7 @@ void parse_omap_stream(void *stream, R_STREAM_FILE *stream_file) { omap_stream = (SOmapStream *) stream; omap_stream->froms = 0; - omap_stream->omap_entries = r_list_new (); + omap_stream->omap_entries = rz_list_new (); ptmp = data; while (read_bytes < data_size) { omap_entry = (SOmapEntry *) malloc (sizeof(SOmapEntry)); @@ -40,7 +40,7 @@ void parse_omap_stream(void *stream, R_STREAM_FILE *stream_file) { break; } ptmp += curr_read_bytes; - r_list_append (omap_stream->omap_entries, omap_entry); + rz_list_append (omap_stream->omap_entries, omap_entry); } free (data); @@ -49,12 +49,12 @@ void parse_omap_stream(void *stream, R_STREAM_FILE *stream_file) { void free_omap_stream(void *stream) { SOmapStream *omap_stream = (SOmapStream *) stream; SOmapEntry *omap_entry = NULL; - RListIter *it = r_list_iterator (omap_stream->omap_entries); - while (r_list_iter_next (it)) { - omap_entry = (SOmapEntry *) r_list_iter_get (it); + RzListIter *it = rz_list_iterator (omap_stream->omap_entries); + while (rz_list_iter_next (it)) { + omap_entry = (SOmapEntry *) rz_list_iter_get (it); free (omap_entry); } - r_list_free (omap_stream->omap_entries); + rz_list_free (omap_stream->omap_entries); } // inclusive indices @@ -89,7 +89,7 @@ static int binary_search(unsigned int *A, int key, int imin, int imax) { int omap_remap(void *stream, int address) { SOmapStream *omap_stream = (SOmapStream *) stream; SOmapEntry *omap_entry = 0; - RListIter *it = 0; + RzListIter *it = 0; int i = 0; int pos = 0; int len = 0; @@ -98,16 +98,16 @@ int omap_remap(void *stream, int address) { return address; } - len = r_list_length (omap_stream->omap_entries); + len = rz_list_length (omap_stream->omap_entries); if (omap_stream->froms == 0) { omap_stream->froms = (unsigned int *) malloc (4 * len); if (!omap_stream->froms) { return -1; } - it = r_list_iterator (omap_stream->omap_entries); - while (r_list_iter_next (it)) { - omap_entry = (SOmapEntry *) r_list_iter_get (it); + it = rz_list_iterator (omap_stream->omap_entries); + while (rz_list_iter_next (it)) { + omap_entry = (SOmapEntry *) rz_list_iter_get (it); omap_stream->froms[i] = omap_entry->from; i++; } @@ -123,7 +123,7 @@ int omap_remap(void *stream, int address) { if (omap_stream->froms[pos] != address) { pos -= 1; } - omap_entry = (SOmapEntry *) r_list_get_n (omap_stream->omap_entries, pos); + omap_entry = (SOmapEntry *) rz_list_get_n (omap_stream->omap_entries, pos); if (!omap_entry) { return -1; } diff --git a/libr/bin/pdb/omap.h b/librz/bin/pdb/omap.h similarity index 100% rename from libr/bin/pdb/omap.h rename to librz/bin/pdb/omap.h diff --git a/libr/bin/pdb/pdb.c b/librz/bin/pdb/pdb.c similarity index 85% rename from libr/bin/pdb/pdb.c rename to librz/bin/pdb/pdb.c index 84fba32539..232f105677 100644 --- a/libr/bin/pdb/pdb.c +++ b/librz/bin/pdb/pdb.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2014 - inisider */ -#include -#include +#include +#include #include #include "types.h" @@ -89,7 +89,7 @@ static int read_int_var(char *var_name, int *var, RPdb *pdb) { if (var) { *var = 0; } - int bytes_read = r_buf_read (pdb->buf, (ut8 *) var, 4); + int bytes_read = rz_buf_read (pdb->buf, (ut8 *) var, 4); if (bytes_read != 4) { eprintf ("Error while reading from file '%s'\n", var_name); return 0; @@ -179,8 +179,8 @@ static int init_pdb7_root_stream(RPdb *pdb, int *root_page_list, int pages_amoun // short ii; // FILE *tmp_file; tmp_data = ((char *) data + num_streams * 4 + 4); - root_stream7->streams_list = r_list_new (); - RList *pList = root_stream7->streams_list; + root_stream7->streams_list = rz_list_new (); + RzList *pList = root_stream7->streams_list; SPage *page = 0; for (i = 0; i < num_streams; i++) { num_pages = count_pages (sizes[i], page_size); @@ -224,7 +224,7 @@ static int init_pdb7_root_stream(RPdb *pdb, int *root_page_list, int pages_amoun free (tmp); } - r_list_append (pList, page); + rz_list_append (pList, page); } free (sizes); free (data); @@ -289,12 +289,12 @@ static void free_info_stream(void *stream) { } else { \ stream_parse_func->stream = 0; \ } \ - r_list_append ((list), stream_parse_func); \ + rz_list_append ((list), stream_parse_func); \ } \ } /////////////////////////////////////////////////////////////////////////////// -static void fill_list_for_stream_parsing(RList *l, SDbiStream *dbi_stream) { +static void fill_list_for_stream_parsing(RzList *l, SDbiStream *dbi_stream) { ADD_INDX_TO_LIST (l, dbi_stream->dbi_header.symrecStream, sizeof (SGDATAStream), ePDB_STREAM_GSYM, free_gdata_stream, parse_gdata_stream); ADD_INDX_TO_LIST (l, dbi_stream->dbg_header.sn_section_hdr, sizeof (SPEStream), @@ -317,14 +317,14 @@ static void fill_list_for_stream_parsing(RList *l, SDbiStream *dbi_stream) { } /////////////////////////////////////////////////////////////////////////////// -static void find_indx_in_list(RList *l, int index, SStreamParseFunc **res) { +static void find_indx_in_list(RzList *l, int index, SStreamParseFunc **res) { SStreamParseFunc *stream_parse_func = 0; - RListIter *it = 0; + RzListIter *it = 0; *res = 0; - it = r_list_iterator (l); - while (r_list_iter_next (it)) { - stream_parse_func = (SStreamParseFunc *) r_list_iter_get (it); + it = rz_list_iterator (l); + while (rz_list_iter_next (it)) { + stream_parse_func = (SStreamParseFunc *) rz_list_iter_get (it); if (index == stream_parse_func->indx) { *res = stream_parse_func; return; @@ -335,22 +335,22 @@ static void find_indx_in_list(RList *l, int index, SStreamParseFunc **res) { /////////////////////////////////////////////////////////////////////////////// static int pdb_read_root(RPdb *pdb) { int i = 0; - RList *pList = pdb->pdb_streams; + RzList *pList = pdb->pdb_streams; R_PDB7_ROOT_STREAM *root_stream = pdb->root_stream; R_PDB_STREAM *pdb_stream = 0; SPDBInfoStream *pdb_info_stream = 0; STpiStream *tpi_stream = 0; R_STREAM_FILE stream_file; - RListIter *it; + RzListIter *it; SPage *page = 0; SStreamParseFunc *stream_parse_func = 0; - it = r_list_iterator (root_stream->streams_list); - while (r_list_iter_next (it)) { - page = (SPage *) r_list_iter_get (it); + it = rz_list_iterator (root_stream->streams_list); + while (rz_list_iter_next (it)) { + page = (SPage *) rz_list_iter_get (it); if (page->stream_pages == 0) { //eprintf ("Warning: no stream pages. Skipping.\n"); - r_list_append (pList, NULL); + rz_list_append (pList, NULL); i++; continue; } @@ -368,7 +368,7 @@ static int pdb_read_root(RPdb *pdb) { } pdb_info_stream->free_ = free_info_stream; parse_pdb_info_stream (pdb_info_stream, &stream_file); - r_list_append (pList, pdb_info_stream); + rz_list_append (pList, pdb_info_stream); break; case ePDB_STREAM_TPI: tpi_stream = R_NEW0 (STpiStream); @@ -380,7 +380,7 @@ static int pdb_read_root(RPdb *pdb) { free (tpi_stream); return 0; } - r_list_append (pList, tpi_stream); + rz_list_append (pList, tpi_stream); break; case ePDB_STREAM_DBI: { @@ -390,8 +390,8 @@ static int pdb_read_root(RPdb *pdb) { } init_dbi_stream (dbi_stream); parse_dbi_stream (dbi_stream, &stream_file); - r_list_append (pList, dbi_stream); - pdb->pdb_streams2 = r_list_new (); + rz_list_append (pList, dbi_stream); + pdb->pdb_streams2 = rz_list_new (); fill_list_for_stream_parsing (pdb->pdb_streams2, dbi_stream); break; } @@ -409,7 +409,7 @@ static int pdb_read_root(RPdb *pdb) { init_r_pdb_stream (pdb_stream, pdb->buf, (int *) page->stream_pages, root_stream->pdb_stream.pages_amount, i, page->stream_size, root_stream->pdb_stream.page_size); - r_list_append (pList, pdb_stream); + rz_list_append (pList, pdb_stream); break; } if (stream_file.error) { @@ -436,7 +436,7 @@ static bool pdb7_parse(RPdb *pdb) { void *p_tmp; int i = 0; - bytes_read = r_buf_read (pdb->buf, (unsigned char *) signature, PDB7_SIGNATURE_LEN); + bytes_read = rz_buf_read (pdb->buf, (unsigned char *) signature, PDB7_SIGNATURE_LEN); if (bytes_read != PDB7_SIGNATURE_LEN) { //eprintf ("Error while reading PDB7_SIGNATURE.\n"); goto error; @@ -469,7 +469,7 @@ static bool pdb7_parse(RPdb *pdb) { goto error; } - bytes_read = r_buf_read (pdb->buf, (unsigned char *) root_index_pages, 4 * num_root_index_pages); + bytes_read = rz_buf_read (pdb->buf, (unsigned char *) root_index_pages, 4 * num_root_index_pages); // fread(root_index_pages, 4, num_root_index_pages, pdb->fp); if (bytes_read != 4 * num_root_index_pages) { eprintf ("Error while reading root_index_pages.\n"); @@ -489,9 +489,9 @@ static bool pdb7_parse(RPdb *pdb) { if (UT64_MUL_OVFCHK (root_index_pages[i], page_size)) { break; } - r_buf_seek (pdb->buf, root_index_pages[i] * page_size, + rz_buf_seek (pdb->buf, root_index_pages[i] * page_size, R_BUF_SET); - r_buf_read (pdb->buf, p_tmp, page_size); + rz_buf_read (pdb->buf, p_tmp, page_size); p_tmp = (char *) p_tmp + page_size; } root_page_list = (int *) calloc (sizeof(int), num_root_pages); @@ -530,21 +530,21 @@ error: static void finish_pdb_parse(RPdb *pdb) { R_PDB7_ROOT_STREAM *p = pdb->root_stream; - RListIter *it; + RzListIter *it; SPage *page = 0; if (!p) { return; } - it = r_list_iterator (p->streams_list); - while (r_list_iter_next (it)) { - page = (SPage *) r_list_iter_get (it); + it = rz_list_iterator (p->streams_list); + while (rz_list_iter_next (it)) { + page = (SPage *) rz_list_iter_get (it); free (page->stream_pages); page->stream_pages = 0; free (page); page = 0; } - r_list_free (p->streams_list); + rz_list_free (p->streams_list); p->streams_list = 0; free (p); p = 0; @@ -560,26 +560,26 @@ static void finish_pdb_parse(RPdb *pdb) { R_PDB_STREAM *pdb_stream = 0; int i = 0; #if 1 -/* r_list_free should be enough, all the items in a list should be freeable using a generic destructor +/* rz_list_free should be enough, all the items in a list should be freeable using a generic destructor hacking up things like that may only produce problems. so it is better to not assume that a specific element in a list is of a specific type and just store this info in the type struct or so. */ // XXX: this loop is fucked up. i prefer to leak than crash - it = r_list_iterator (pdb->pdb_streams); - while (r_list_iter_next (it)) { + it = rz_list_iterator (pdb->pdb_streams); + while (rz_list_iter_next (it)) { switch (i) { case 1: - pdb_info_stream = (SPDBInfoStream *) r_list_iter_get (it); + pdb_info_stream = (SPDBInfoStream *) rz_list_iter_get (it); free_pdb_stream (pdb_info_stream); free (pdb_info_stream); break; case 2: - tpi_stream = (STpiStream *) r_list_iter_get (it); + tpi_stream = (STpiStream *) rz_list_iter_get (it); free_pdb_stream (tpi_stream); free (tpi_stream); break; case 3: - dbi_stream = (SDbiStream *) r_list_iter_get (it); + dbi_stream = (SDbiStream *) rz_list_iter_get (it); free_pdb_stream (dbi_stream); free (dbi_stream); break; @@ -588,7 +588,7 @@ static void finish_pdb_parse(RPdb *pdb) { if (stream_parse_func) { break; } - pdb_stream = (R_PDB_STREAM *) r_list_iter_get (it); + pdb_stream = (R_PDB_STREAM *) rz_list_iter_get (it); free_pdb_stream (pdb_stream); free (pdb_stream); break; @@ -596,14 +596,14 @@ static void finish_pdb_parse(RPdb *pdb) { i++; } #endif - r_list_free (pdb->pdb_streams); + rz_list_free (pdb->pdb_streams); // enf of free of pdb->pdb_streams #if 1 // start of free pdb->pdb_streams2 - it = r_list_iterator (pdb->pdb_streams2); - while (r_list_iter_next (it)) { - stream_parse_func = (SStreamParseFunc *) r_list_iter_get (it); + it = rz_list_iterator (pdb->pdb_streams2); + while (rz_list_iter_next (it)) { + stream_parse_func = (SStreamParseFunc *) rz_list_iter_get (it); if (stream_parse_func->free) { stream_parse_func->free (stream_parse_func->stream); free (stream_parse_func->stream); @@ -611,11 +611,11 @@ static void finish_pdb_parse(RPdb *pdb) { free (stream_parse_func); } #endif - r_list_free (pdb->pdb_streams2); + rz_list_free (pdb->pdb_streams2); // end of free pdb->streams2 free (pdb->stream_map); - r_buf_free (pdb->buf); + rz_buf_free (pdb->buf); // fclose(pdb->fp); // printf("finish_pdb_parse()\n"); @@ -760,7 +760,7 @@ static int simple_type_to_format (const SLF_SIMPLE_TYPE *simple_type, char **mem *member_format = "::::"; return -2; default: - r_warn_if_reached (); + rz_warn_if_reached (); break; } } break; @@ -787,7 +787,7 @@ static int simple_type_to_format (const SLF_SIMPLE_TYPE *simple_type, char **mem break; default: // unknown mode ?? - r_warn_if_reached (); + rz_warn_if_reached (); return -1; } return 0; @@ -802,7 +802,7 @@ static int simple_type_to_format (const SLF_SIMPLE_TYPE *simple_type, char **mem * @return int -1 if it can't build the format */ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *names) { - r_return_val_if_fail (type_info && format && names && type_info->type_info, -1); + rz_return_val_if_fail (type_info && format && names && type_info->type_info, -1); // THOUGHT: instead of not doing anything for unknown types I can just skip the bytes // format is 2 chars tops + null terminator @@ -813,7 +813,7 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n if (!name) { // name should never be null, but malformed PDB exists return -1; } - name = r_str_sanitize_sdb_key (name); + name = rz_str_sanitize_sdb_key (name); SType *under_type = NULL; if (type_info->leaf_type == eLF_MEMBER || @@ -821,13 +821,13 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n if (type_info->get_index) { type_info->get_index (type_info, (void **)&under_type); } else { - r_warn_if_reached (); + rz_warn_if_reached (); } } else if (type_info->leaf_type == eLF_METHOD || type_info->leaf_type == eLF_ONEMETHOD) { return 0; // skip method member } else { - r_warn_if_reached (); + rz_warn_if_reached (); return -1; } type_info = &under_type->type_data; @@ -845,7 +845,7 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n goto skip; } } - r_strbuf_append (names, name); + rz_strbuf_append (names, name); } break; case eLF_POINTER: { int size = 4; @@ -854,7 +854,7 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n } snprintf (tmp_format, 5, "p%d", size); member_format = tmp_format; - r_strbuf_appendf (names, name); + rz_strbuf_appendf (names, name); } break; case eLF_CLASS: case eLF_UNION: @@ -867,20 +867,20 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n if (!field_name) { field_name = create_type_name_from_offset (under_type->tpi_idx); } else { - field_name = r_str_sanitize_sdb_key (field_name); + field_name = rz_str_sanitize_sdb_key (field_name); } - r_strbuf_appendf (names, "(%s)%s", field_name, name); + rz_strbuf_appendf (names, "(%s)%s", field_name, name); free (field_name); } break; // TODO complete the type with additional info case eLF_BITFIELD: { member_format = "B"; - r_strbuf_appendf (names, "(uint)%s", name); + rz_strbuf_appendf (names, "(uint)%s", name); } break; // TODO complete the type with additional info case eLF_ENUM: { member_format = "E"; - r_strbuf_appendf (names, "(int)%s", name); + rz_strbuf_appendf (names, "(int)%s", name); } break; case eLF_ARRAY: { int size = 0; @@ -889,19 +889,19 @@ static int build_member_format(STypeInfo *type_info, RStrBuf *format, RStrBuf *n } snprintf (tmp_format, 5, "[%d]", size); member_format = tmp_format; - r_strbuf_append (names, name); // TODO complete the type with additional info + rz_strbuf_append (names, name); // TODO complete the type with additional info } break; default: - r_warn_if_reached (); // Unhandled type format + rz_warn_if_reached (); // Unhandled type format goto error; } if (!member_format) { - r_warn_if_reached (); // Unhandled type format + rz_warn_if_reached (); // Unhandled type format goto error; } - r_strbuf_appendf (format, "%s", member_format); + rz_strbuf_appendf (format, "%s", member_format); skip: // shortcut for unknown types where we only skip the bytes free (name); return 0; @@ -947,13 +947,13 @@ static char *get_enum_base_type_name(STypeInfo *type_info) { * @param members List of members * @param printf Print function */ -static void print_struct(const char *name, const int size, const RList *members, PrintfCallback printf) { - r_return_if_fail (name && printf); +static void print_struct(const char *name, const int size, const RzList *members, PrintfCallback printf) { + rz_return_if_fail (name && printf); printf ("struct %s { // size 0x%x\n", name, size); - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { - STypeInfo *type_info = r_list_iter_get (member_iter); + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { + STypeInfo *type_info = rz_list_iter_get (member_iter); char *member_name = NULL; if (type_info->get_name) { type_info->get_name (type_info, &member_name); @@ -980,13 +980,13 @@ static void print_struct(const char *name, const int size, const RList *members, * @param members List of members * @param printf Print function */ -static void print_union(const char *name, const int size, const RList *members, PrintfCallback printf) { - r_return_if_fail (name && printf); +static void print_union(const char *name, const int size, const RzList *members, PrintfCallback printf) { + rz_return_if_fail (name && printf); printf ("union %s { // size 0x%x\n", name, size); - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { - STypeInfo *type_info = r_list_iter_get (member_iter); + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { + STypeInfo *type_info = rz_list_iter_get (member_iter); char *member_name = NULL; if (type_info->get_name) { type_info->get_name (type_info, &member_name); @@ -1013,13 +1013,13 @@ static void print_union(const char *name, const int size, const RList *members, * @param members List of cases * @param printf Print function */ -static void print_enum(const char *name, const char *type, const RList *members, PrintfCallback printf) { - r_return_if_fail (name && printf); +static void print_enum(const char *name, const char *type, const RzList *members, PrintfCallback printf) { + rz_return_if_fail (name && printf); printf ("enum %s { // type: %s\n", name, type); - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { - STypeInfo *type_info = r_list_iter_get (member_iter); + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { + STypeInfo *type_info = rz_list_iter_get (member_iter); char *member_name = NULL; if (type_info->get_name) { type_info->get_name (type_info, &member_name); @@ -1039,12 +1039,12 @@ static void print_enum(const char *name, const char *type, const RList *members, * @param pdb pdb structure for printing function * @param types List of types */ -static void print_types_regular(const RPdb *pdb, const RList *types) { - r_return_if_fail (pdb && types); - RListIter *it = r_list_iterator (types); +static void print_types_regular(const RPdb *pdb, const RzList *types) { + rz_return_if_fail (pdb && types); + RzListIter *it = rz_list_iterator (types); - while (r_list_iter_next (it)) { - SType *type = r_list_iter_get (it); + while (rz_list_iter_next (it)) { + SType *type = rz_list_iter_get (it); STypeInfo *type_info = &type->type_data; // skip unprintable types if (!is_printable_type (type_info->leaf_type)) { @@ -1066,7 +1066,7 @@ static void print_types_regular(const RPdb *pdb, const RList *types) { if (type_info->get_val) { type_info->get_val (type_info, &size); } - RList *members = NULL; + RzList *members = NULL; if (type_info->get_members) { // do we wanna print empty types? type_info->get_members (type_info, &members); } @@ -1084,7 +1084,7 @@ static void print_types_regular(const RPdb *pdb, const RList *types) { break; default: // Unimplemented printing of printable type - r_warn_if_reached (); + rz_warn_if_reached (); break; } } @@ -1096,14 +1096,14 @@ static void print_types_regular(const RPdb *pdb, const RList *types) { * @param pdb pdb structure for printing function * @param types List of types */ -static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { - r_return_if_fail (pdb && types && pj); +static void print_types_json(const RPdb *pdb, PJ *pj, const RzList *types) { + rz_return_if_fail (pdb && types && pj); - RListIter *it = r_list_iterator (types); + RzListIter *it = rz_list_iterator (types); pj_ka (pj, "types"); - while (r_list_iter_next (it)) { - SType *type = r_list_iter_get (it); + while (rz_list_iter_next (it)) { + SType *type = rz_list_iter_get (it); STypeInfo *type_info = &type->type_data; // skip unprintable types if (!is_printable_type (type_info->leaf_type)) { @@ -1126,7 +1126,7 @@ static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { if (type_info->get_val) { type_info->get_val (type_info, &size); } - RList *members = NULL; // Should we print empty structures/enums? + RzList *members = NULL; // Should we print empty structures/enums? if (type_info->get_members) { type_info->get_members (type_info, &members); } @@ -1143,10 +1143,10 @@ static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { pj_ka (pj, "members"); if (members) { - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { pj_o (pj); - STypeInfo *type_info = r_list_iter_get (member_iter); + STypeInfo *type_info = rz_list_iter_get (member_iter); char *member_name = NULL; if (type_info->get_name) { type_info->get_name (type_info, &member_name); @@ -1178,10 +1178,10 @@ static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { pj_ka (pj, "cases"); if (members) { - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { pj_o (pj); - STypeInfo *type_info = r_list_iter_get (member_iter); + STypeInfo *type_info = rz_list_iter_get (member_iter); char *member_name = NULL; if (type_info->get_name) { type_info->get_name (type_info, &member_name); @@ -1201,7 +1201,7 @@ static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { } default: // Unimplemented printing of printable type - r_warn_if_reached (); + rz_warn_if_reached (); break; } } @@ -1214,12 +1214,12 @@ static void print_types_json(const RPdb *pdb, PJ *pj, const RList *types) { * @param pdb pdb structure for printing function * @param types List of types */ -static void print_types_format(const RPdb *pdb, const RList *types) { - r_return_if_fail (pdb && types); - RListIter *it = r_list_iterator (types); +static void print_types_format(const RPdb *pdb, const RzList *types) { + rz_return_if_fail (pdb && types); + RzListIter *it = rz_list_iterator (types); bool to_free_name = false; - while (r_list_iter_next (it)) { - SType *type = r_list_iter_get (it); + while (rz_list_iter_next (it)) { + SType *type = rz_list_iter_get (it); STypeInfo *type_info = &type->type_data; // skip unprintable types and enums if (!is_printable_type (type_info->leaf_type) || type_info->leaf_type == eLF_ENUM) { @@ -1245,23 +1245,23 @@ static void print_types_format(const RPdb *pdb, const RList *types) { if (type_info->get_val) { type_info->get_val (type_info, &size); } - RList *members = NULL; + RzList *members = NULL; if (type_info->get_members) { type_info->get_members (type_info, &members); } // pf.name RStrBuf format; - r_strbuf_init (&format); + rz_strbuf_init (&format); RStrBuf member_names; - r_strbuf_init (&member_names); + rz_strbuf_init (&member_names); if (type_info->leaf_type == eLF_UNION) { - r_strbuf_append (&format, "0"); // every type start from the offset 0 + rz_strbuf_append (&format, "0"); // every type start from the offset 0 } - RListIter *member_iter = r_list_iterator (members); - while (r_list_iter_next (member_iter)) { - STypeInfo *member_info = r_list_iter_get (member_iter); + RzListIter *member_iter = rz_list_iterator (members); + while (rz_list_iter_next (member_iter)) { + STypeInfo *member_info = rz_list_iter_get (member_iter); switch (type_info->leaf_type) { case eLF_STRUCTURE: case eLF_CLASS: @@ -1271,29 +1271,29 @@ static void print_types_format(const RPdb *pdb, const RList *types) { } break; default: - r_warn_if_reached (); + rz_warn_if_reached (); } - r_strbuf_append (&member_names, " "); + rz_strbuf_append (&member_names, " "); } if (format.len == 0) { // if it has no members, it's useless for us then? goto fail; } - char *sanitized_name = r_str_sanitize_sdb_key (name); - pdb->cb_printf ("pf.%s %s %s\n", sanitized_name, r_strbuf_get (&format), r_strbuf_get (&member_names)); + char *sanitized_name = rz_str_sanitize_sdb_key (name); + pdb->cb_printf ("pf.%s %s %s\n", sanitized_name, rz_strbuf_get (&format), rz_strbuf_get (&member_names)); if (to_free_name) { // name can be generated or part of the PDB data R_FREE (name); } R_FREE (sanitized_name); - r_strbuf_fini (&format); - r_strbuf_fini (&member_names); + rz_strbuf_fini (&format); + rz_strbuf_fini (&member_names); fail: // if we can't print whole type correctly, don't print at all if (to_free_name) { R_FREE (name); } - r_strbuf_fini (&format); - r_strbuf_fini (&member_names); + rz_strbuf_fini (&format); + rz_strbuf_fini (&member_names); } } @@ -1304,8 +1304,8 @@ static void print_types_format(const RPdb *pdb, const RList *types) { * @param mode printing mode */ static void print_types(const RPdb *pdb, PJ *pj, const int mode) { - RList *plist = pdb->pdb_streams; - STpiStream *tpi_stream = r_list_get_n (plist, ePDB_STREAM_TPI); + RzList *plist = pdb->pdb_streams; + STpiStream *tpi_stream = rz_list_get_n (plist, ePDB_STREAM_TPI); if (!tpi_stream) { eprintf ("There is no tpi stream in current pdb\n"); @@ -1325,14 +1325,14 @@ static void print_gvars(RPdb *pdb, ut64 img_base, PJ *pj, int format) { SGDATAStream *gsym_data_stream = 0; SPEStream *pe_stream = 0; SGlobal *gdata = 0; - RListIter *it = 0; - RList *l = 0; + RzListIter *it = 0; + RzList *l = 0; char *name; l = pdb->pdb_streams2; - it = r_list_iterator (l); - while (r_list_iter_next (it)) { - tmp = (SStreamParseFunc *) r_list_iter_get (it); + it = rz_list_iterator (l); + while (rz_list_iter_next (it)) { + tmp = (SStreamParseFunc *) rz_list_iter_get (it); switch (tmp->type) { case ePDB_STREAM_SECT__HDR_ORIG: sctns_orig = tmp; @@ -1369,16 +1369,16 @@ static void print_gvars(RPdb *pdb, ut64 img_base, PJ *pj, int format) { if (!pe_stream) { return; } - it = r_list_iterator (gsym_data_stream->globals_list); - while (r_list_iter_next (it)) { - gdata = (SGlobal *)r_list_iter_get (it); - sctn_header = r_list_get_n (pe_stream->sections_hdrs, (gdata->segment - 1)); + it = rz_list_iterator (gsym_data_stream->globals_list); + while (rz_list_iter_next (it)) { + gdata = (SGlobal *)rz_list_iter_get (it); + sctn_header = rz_list_get_n (pe_stream->sections_hdrs, (gdata->segment - 1)); if (sctn_header) { - name = r_bin_demangle_msvc (gdata->name.name); + name = rz_bin_demangle_msvc (gdata->name.name); name = (name) ? name : strdup (gdata->name.name); if (name && format != 'd') { char *_name = name; - name = r_name_filter2 (_name); + name = rz_name_filter2 (_name); free (_name); } switch (format) { @@ -1418,7 +1418,7 @@ static void print_gvars(RPdb *pdb, ut64 img_base, PJ *pj, int format) { } /////////////////////////////////////////////////////////////////////////////// -R_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer* buf) { +RZ_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer* buf) { char *signature = NULL; int bytes_read = 0; @@ -1440,13 +1440,13 @@ R_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer* buf) { goto error; } - bytes_read = r_buf_read (pdb->buf, (ut8 *) signature, PDB7_SIGNATURE_LEN); + bytes_read = rz_buf_read (pdb->buf, (ut8 *) signature, PDB7_SIGNATURE_LEN); if (bytes_read != PDB7_SIGNATURE_LEN) { eprintf ("PDB reading error.\n"); goto error; } - r_buf_seek (pdb->buf, 0, R_BUF_SET); + rz_buf_seek (pdb->buf, 0, R_BUF_SET); if (!memcmp (signature, PDB7_SIGNATURE, PDB7_SIGNATURE_LEN)) { pdb->pdb_parse = pdb7_parse; @@ -1456,7 +1456,7 @@ R_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer* buf) { R_FREE (signature); - pdb->pdb_streams = r_list_new (); + pdb->pdb_streams = rz_list_new (); pdb->stream_map = 0; pdb->finish_pdb_parse = finish_pdb_parse; pdb->print_types = print_types; @@ -1468,8 +1468,8 @@ error: return false; } -R_API bool init_pdb_parser(RPdb *pdb, const char *filename) { - RBuffer *buf = r_buf_new_slurp (filename); +RZ_API bool init_pdb_parser(RPdb *pdb, const char *filename) { + RBuffer *buf = rz_buf_new_slurp (filename); if (!buf) { eprintf ("%s: Error reading file \"%s\"\n", __func__, filename); return false; diff --git a/libr/bin/pdb/pdb_downloader.c b/librz/bin/pdb/pdb_downloader.c similarity index 75% rename from libr/bin/pdb/pdb_downloader.c rename to librz/bin/pdb/pdb_downloader.c index 12d5b8f5c7..dcdc7efc09 100644 --- a/libr/bin/pdb/pdb_downloader.c +++ b/librz/bin/pdb/pdb_downloader.c @@ -1,33 +1,33 @@ /* radare - LGPL - Copyright 2014-2020 - inisider */ #include -#include -#include +#include +#include #include "pdb_downloader.h" static bool checkExtract(void) { #if __WINDOWS__ - return r_sys_cmd ("expand -? >nul") == 0; + return rz_sys_cmd ("expand -? >nul") == 0; #else - return r_sys_cmd ("cabextract -v > /dev/null") == 0; + return rz_sys_cmd ("cabextract -v > /dev/null") == 0; #endif } static bool download_and_write(SPDBDownloaderOpt *opt, const char *file) { - char *dir = r_str_newf ("%s%s%s%s%s", + char *dir = rz_str_newf ("%s%s%s%s%s", opt->symbol_store_path, R_SYS_DIR, opt->dbg_file, R_SYS_DIR, opt->guid); - if (!r_sys_mkdirp (dir)) { + if (!rz_sys_mkdirp (dir)) { free (dir); return false; } - char *url = r_str_newf ("%s/%s/%s/%s", opt->symbol_server, opt->dbg_file, opt->guid, file); - char *path = r_str_newf ("%s%s%s", dir, R_SYS_DIR, opt->dbg_file); + char *url = rz_str_newf ("%s/%s/%s/%s", opt->symbol_server, opt->dbg_file, opt->guid, file); + char *path = rz_str_newf ("%s%s%s", dir, R_SYS_DIR, opt->dbg_file); #if __WINDOWS__ - if (r_str_startswith (url, "\\\\")) { // Network path - LPCWSTR origin = r_utf8_to_utf16 (url); - LPCWSTR dest = r_utf8_to_utf16 (path); + if (rz_str_startswith (url, "\\\\")) { // Network path + LPCWSTR origin = rz_utf8_to_utf16 (url); + LPCWSTR dest = rz_utf8_to_utf16 (path); BOOL ret = CopyFileW (origin, dest, FALSE); free (dir); free (path); @@ -37,7 +37,7 @@ static bool download_and_write(SPDBDownloaderOpt *opt, const char *file) { } #endif int len; - char *file_buf = r_socket_http_get (url, NULL, &len); + char *file_buf = rz_socket_http_get (url, NULL, &len); free (url); if (!len || R_STR_ISEMPTY (file_buf)) { free (dir); @@ -66,13 +66,13 @@ static int download(struct SPDBDownloader *pd) { return 0; } - char *abspath_to_file = r_str_newf ("%s%s%s%s%s%s%s", + char *abspath_to_file = rz_str_newf ("%s%s%s%s%s%s%s", opt->symbol_store_path, R_SYS_DIR, opt->dbg_file, R_SYS_DIR, opt->guid, R_SYS_DIR, opt->dbg_file); - if (r_file_exists (abspath_to_file)) { + if (rz_file_exists (abspath_to_file)) { eprintf ("File already downloaded.\n"); free (abspath_to_file); return 1; @@ -82,28 +82,28 @@ static int download(struct SPDBDownloader *pd) { char *extractor_cmd = NULL; char *archive_name = strdup (opt->dbg_file); archive_name[strlen (archive_name) - 1] = '_'; - char *abspath_to_archive = r_str_newf ("%s%s%s%s%s%s%s", + char *abspath_to_archive = rz_str_newf ("%s%s%s%s%s%s%s", opt->symbol_store_path, R_SYS_DIR, opt->dbg_file, R_SYS_DIR, opt->guid, R_SYS_DIR, archive_name); eprintf ("Attempting to download compressed pdb in %s\n", abspath_to_archive); - char *abs_arch_esc = r_str_escape_sh (abspath_to_archive); + char *abs_arch_esc = rz_str_escape_sh (abspath_to_archive); #if __WINDOWS__ - char *abs_file_esc = r_str_escape_sh (abspath_to_file); + char *abs_file_esc = rz_str_escape_sh (abspath_to_file); // expand %1 %2 // %1 - absolute path to archive // %2 - absolute path to file that will be dearchive - extractor_cmd = r_str_newf ("expand \"%s\" \"%s\"", abs_arch_esc, abs_file_esc); + extractor_cmd = rz_str_newf ("expand \"%s\" \"%s\"", abs_arch_esc, abs_file_esc); free (abs_file_esc); #else - char *abspath_to_dir = r_file_dirname (abspath_to_archive); - char *abs_dir_esc = r_str_escape_sh (abspath_to_dir); + char *abspath_to_dir = rz_file_dirname (abspath_to_archive); + char *abs_dir_esc = rz_str_escape_sh (abspath_to_dir); // cabextract -d %1 %2 // %1 - path to directory where to extract all files from cab archive // %2 - absolute path to cab archive - extractor_cmd = r_str_newf ("cabextract -d \"%s\" \"%s\"", abs_arch_esc, abs_dir_esc); + extractor_cmd = rz_str_newf ("cabextract -d \"%s\" \"%s\"", abs_arch_esc, abs_dir_esc); free (abs_dir_esc); free (abspath_to_dir); #endif @@ -112,11 +112,11 @@ static int download(struct SPDBDownloader *pd) { if (opt->extract > 0 && res) { eprintf ("Attempting to decompress pdb\n"); - if (res && ((cmd_ret = r_sys_cmd (extractor_cmd)) != 0)) { + if (res && ((cmd_ret = rz_sys_cmd (extractor_cmd)) != 0)) { eprintf ("cab extractor exited with error %d\n", cmd_ret); res = 0; } - r_file_rm (abspath_to_archive); + rz_file_rm (abspath_to_archive); } free (archive_name); free (abspath_to_archive); @@ -170,11 +170,11 @@ static bool is_valid_guid(const char *guid) { return i >= 33; // len of GUID and age } -int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOptions *options) { +int rz_bin_pdb_download(RzCore *core, int isradjson, int *actions_done, SPDBOptions *options) { int ret; SPDBDownloaderOpt opt; SPDBDownloader pdb_downloader; - RBinInfo *info = r_bin_get_info (core->bin); + RBinInfo *info = rz_bin_get_info (core->bin); if (!info || !info->debug_file_name) { eprintf ("Can't find debug filename\n"); @@ -191,7 +191,7 @@ int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOption return 1; } - opt.dbg_file = (char*) r_file_basename (info->debug_file_name); + opt.dbg_file = (char*) rz_file_basename (info->debug_file_name); opt.guid = info->guid; opt.symbol_server = options->symbol_server; opt.user_agent = options->user_agent; diff --git a/libr/bin/pdb/pdb_downloader.h b/librz/bin/pdb/pdb_downloader.h similarity index 87% rename from libr/bin/pdb/pdb_downloader.h rename to librz/bin/pdb/pdb_downloader.h index 77a49f5639..011b1defd6 100644 --- a/libr/bin/pdb/pdb_downloader.h +++ b/librz/bin/pdb/pdb_downloader.h @@ -1,8 +1,8 @@ #ifndef PDB_DOWNLOADER_H #define PDB_DOWNLOADER_H -#include -#include +#include +#include #ifdef __cplusplus extern "C" { @@ -45,7 +45,7 @@ void deinit_pdb_downloader(SPDBDownloader *pdb_downloader); /// /// \brief download PDB file -R_API int r_bin_pdb_download(RCore *core, int isradjson, int *actions_done, SPDBOptions *options); +RZ_API int rz_bin_pdb_download(RzCore *core, int isradjson, int *actions_done, SPDBOptions *options); #ifdef __cplusplus } diff --git a/libr/bin/pdb/stream_file.c b/librz/bin/pdb/stream_file.c similarity index 97% rename from libr/bin/pdb/stream_file.c rename to librz/bin/pdb/stream_file.c index 40156b4e69..00910718ea 100644 --- a/libr/bin/pdb/stream_file.c +++ b/librz/bin/pdb/stream_file.c @@ -35,8 +35,8 @@ static void stream_file_read_pages(R_STREAM_FILE *stream_file, int start_indx, i if (page_offset < 1) { return; } - r_buf_seek (stream_file->buf, page_offset, R_BUF_SET); - r_buf_read_at (stream_file->buf, page_offset, + rz_buf_seek (stream_file->buf, page_offset, R_BUF_SET); + rz_buf_read_at (stream_file->buf, page_offset, (ut8 *)res, stream_file->page_size); res += stream_file->page_size; } diff --git a/libr/bin/pdb/stream_file.h b/librz/bin/pdb/stream_file.h similarity index 100% rename from libr/bin/pdb/stream_file.h rename to librz/bin/pdb/stream_file.h diff --git a/libr/bin/pdb/stream_pe.c b/librz/bin/pdb/stream_pe.c similarity index 78% rename from libr/bin/pdb/stream_pe.c rename to librz/bin/pdb/stream_pe.c index aa058994b3..9f56b135e1 100644 --- a/libr/bin/pdb/stream_pe.c +++ b/librz/bin/pdb/stream_pe.c @@ -21,7 +21,7 @@ void parse_pe_stream(void *stream, R_STREAM_FILE *stream_file) sctn_header_size = sizeof (SIMAGE_SECTION_HEADER); ptmp = data; - pe_stream->sections_hdrs = r_list_new (); + pe_stream->sections_hdrs = rz_list_new (); while (read_bytes < data_size) { sctn_header = (SIMAGE_SECTION_HEADER *) malloc (sctn_header_size); if (!sctn_header) { @@ -29,7 +29,7 @@ void parse_pe_stream(void *stream, R_STREAM_FILE *stream_file) } memcpy (sctn_header, ptmp, sctn_header_size); ptmp += sctn_header_size; - r_list_append (pe_stream->sections_hdrs, sctn_header); + rz_list_append (pe_stream->sections_hdrs, sctn_header); read_bytes += sctn_header_size; } @@ -41,12 +41,12 @@ void free_pe_stream(void *stream) { SPEStream *pe_stream = (SPEStream *) stream; SIMAGE_SECTION_HEADER *sctn_header = 0; - RListIter *it = 0; + RzListIter *it = 0; - it = r_list_iterator (pe_stream->sections_hdrs); - while (r_list_iter_next (it)) { - sctn_header = (SIMAGE_SECTION_HEADER *) r_list_iter_get (it); + it = rz_list_iterator (pe_stream->sections_hdrs); + while (rz_list_iter_next (it)) { + sctn_header = (SIMAGE_SECTION_HEADER *) rz_list_iter_get (it); free (sctn_header); } - r_list_free (pe_stream->sections_hdrs); + rz_list_free (pe_stream->sections_hdrs); } diff --git a/libr/bin/pdb/stream_pe.h b/librz/bin/pdb/stream_pe.h similarity index 100% rename from libr/bin/pdb/stream_pe.h rename to librz/bin/pdb/stream_pe.h diff --git a/libr/bin/pdb/tpi.c b/librz/bin/pdb/tpi.c similarity index 96% rename from libr/bin/pdb/tpi.c rename to librz/bin/pdb/tpi.c index 4f89ebf8cd..6e1809fff5 100644 --- a/libr/bin/pdb/tpi.c +++ b/librz/bin/pdb/tpi.c @@ -3,7 +3,7 @@ #include "stream_file.h" static unsigned int base_idx = 0; -static RList *p_types_list; +static RzList *p_types_list; static bool is_simple_type(int idx) { ut32 value = (ut32) idx; @@ -818,7 +818,7 @@ static int get_array_element_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -844,7 +844,7 @@ static int get_array_index_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -871,7 +871,7 @@ static int get_bitfield_base_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -885,7 +885,7 @@ static int get_class_struct_derived(void *type, void **ret_type) { if (curr_idx) { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } else { *ret_type = NULL; } @@ -900,7 +900,7 @@ static int get_class_struct_vshape(void *type, void **ret_type) { if (curr_idx) { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } else { *ret_type = NULL; } @@ -927,7 +927,7 @@ static int get_mfunction_return_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -940,7 +940,7 @@ static int get_mfunction_class_type(void *type, void **ret_type) { if (curr_idx) { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } else { *ret_type = NULL; } @@ -955,7 +955,7 @@ static int get_mfunction_this_type(void *type, void **ret_type) { if (curr_idx) { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } else { *ret_type = NULL; } @@ -971,7 +971,7 @@ static int get_mfunction_arglist(void *type, void **ret_type) { if (curr_idx) { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } else { *ret_type = NULL; } @@ -999,7 +999,7 @@ static int get_modifier_modified_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1025,7 +1025,7 @@ static int get_pointer_utype(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1050,7 +1050,7 @@ static int get_procedure_return_type(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1075,7 +1075,7 @@ static int get_procedure_arglist(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1100,7 +1100,7 @@ static int get_member_index(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1125,7 +1125,7 @@ static int get_nesttype_index(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1150,7 +1150,7 @@ static int get_onemethod_index(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1175,7 +1175,7 @@ static int get_method_mlist(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; @@ -1200,20 +1200,20 @@ static int get_enum_utype(void *type, void **ret_type) { return true; // check what are the return values used for } else { curr_idx -= base_idx; - *ret_type = r_list_get_n(p_types_list, curr_idx); + *ret_type = rz_list_get_n(p_types_list, curr_idx); } return curr_idx; } -static void get_fieldlist_members(void *type, RList **l) { +static void get_fieldlist_members(void *type, RzList **l) { STypeInfo *t = (STypeInfo *) type; SLF_FIELDLIST *lf_fieldlist = (SLF_FIELDLIST *) t->type_info; *l = lf_fieldlist->substructs; } -static void get_union_members(void *type, RList **l) { +static void get_union_members(void *type, RzList **l) { STypeInfo *t = (STypeInfo *) type; SLF_UNION *lf_union = (SLF_UNION *) t->type_info; unsigned int indx = 0; @@ -1223,12 +1223,12 @@ static void get_union_members(void *type, RList **l) { } else { SType *tmp = 0; indx = lf_union->field_list - base_idx; - tmp = (SType *)r_list_get_n(p_types_list, indx); + tmp = (SType *)rz_list_get_n(p_types_list, indx); *l = ((SLF_FIELDLIST *) tmp->type_data.type_info)->substructs; } } -static void get_struct_class_members(void *type, RList **l) { +static void get_struct_class_members(void *type, RzList **l) { SLF_FIELDLIST *lf_fieldlist = 0; STypeInfo *t = (STypeInfo *) type; SLF_STRUCTURE *lf = (SLF_STRUCTURE *) t->type_info; @@ -1239,13 +1239,13 @@ static void get_struct_class_members(void *type, RList **l) { } else { SType *tmp = 0; indx = lf->field_list - base_idx; - tmp = (SType *)r_list_get_n(p_types_list, indx); + tmp = (SType *)rz_list_get_n(p_types_list, indx); lf_fieldlist = (SLF_FIELDLIST *) tmp->type_data.type_info; *l = lf_fieldlist->substructs; } } -static void get_enum_members(void *type, RList **l) { +static void get_enum_members(void *type, RzList **l) { STypeInfo *t = (STypeInfo *) type; SLF_ENUM *lf = (SLF_ENUM *) t->type_info; unsigned int indx = 0; @@ -1255,7 +1255,7 @@ static void get_enum_members(void *type, RList **l) { } else { SType *tmp = 0; indx = lf->field_list - base_idx; - tmp = (SType *)r_list_get_n(p_types_list, indx); + tmp = (SType *)rz_list_get_n(p_types_list, indx); *l = ((SLF_FIELDLIST *) tmp->type_data.type_info)->substructs; } } @@ -1578,12 +1578,12 @@ static void free_lf_member(void *type_info) { static void free_lf_fieldlist(void *type) { STypeInfo *t = (STypeInfo *) type; SLF_FIELDLIST *lf_fieldlist = (SLF_FIELDLIST *) t->type_info; - RListIter *it; + RzListIter *it; STypeInfo *type_info = 0; - it = r_list_iterator(lf_fieldlist->substructs); - while (r_list_iter_next(it)) { - type_info = (STypeInfo *) r_list_iter_get(it); + it = rz_list_iterator(lf_fieldlist->substructs); + while (rz_list_iter_next(it)) { + type_info = (STypeInfo *) rz_list_iter_get(it); if (type_info->free_) { type_info->free_ (type_info); } @@ -1592,7 +1592,7 @@ static void free_lf_fieldlist(void *type) { } free(type_info); } - r_list_free (lf_fieldlist->substructs); + rz_list_free (lf_fieldlist->substructs); } static void free_lf_class(void *type) { @@ -1642,12 +1642,12 @@ static void free_lf_vtshape(void *type) { static void free_tpi_stream(void *stream) { STpiStream *tpi_stream = (STpiStream *)stream; - RListIter *it; + RzListIter *it; SType *type = NULL; - it = r_list_iterator (tpi_stream->types); - while (r_list_iter_next (it)) { - type = (SType *) r_list_iter_get (it); + it = rz_list_iterator (tpi_stream->types); + while (rz_list_iter_next (it)) { + type = (SType *) rz_list_iter_get (it); if (!type) { continue; } @@ -1662,7 +1662,7 @@ static void free_tpi_stream(void *stream) { } R_FREE (type); } - r_list_free (tpi_stream->types); + rz_list_free (tpi_stream->types); } static void get_array_print_type(void *type, char **name) { @@ -1672,7 +1672,7 @@ static void get_array_print_type(void *type, char **name) { SType *t = 0; ti->get_element_type (ti, (void **)&t); - r_return_if_fail (t); // t == NULL indicates malformed PDB ? + rz_return_if_fail (t); // t == NULL indicates malformed PDB ? if (t->type_data.leaf_type == eLF_SIMPLE_TYPE) { need_to_free = false; SLF_SIMPLE_TYPE *base_type = t->type_data.type_info; @@ -1686,13 +1686,13 @@ static void get_array_print_type(void *type, char **name) { ti->get_val (ti, &size); } RStrBuf buff; - r_strbuf_init (&buff); + rz_strbuf_init (&buff); if (tmp_name) { - r_strbuf_append (&buff, tmp_name); + rz_strbuf_append (&buff, tmp_name); } - r_strbuf_appendf (&buff, "[%d]", size); - *name = r_strbuf_drain_nofree (&buff); - r_strbuf_fini (&buff); + rz_strbuf_appendf (&buff, "[%d]", size); + *name = rz_strbuf_drain_nofree (&buff); + rz_strbuf_fini (&buff); if (need_to_free) { R_FREE (tmp_name); } @@ -1705,7 +1705,7 @@ static void get_pointer_print_type(void *type, char **name) { int need_to_free = 1; ti->get_utype (ti, (void **)&t); - r_return_if_fail (t); // t == NULL indicates malformed PDB ? + rz_return_if_fail (t); // t == NULL indicates malformed PDB ? if (t->type_data.leaf_type == eLF_SIMPLE_TYPE) { need_to_free = false; SLF_SIMPLE_TYPE *base_type = t->type_data.type_info; @@ -1716,13 +1716,13 @@ static void get_pointer_print_type(void *type, char **name) { } RStrBuf buff; - r_strbuf_init (&buff); + rz_strbuf_init (&buff); if (tmp_name) { - r_strbuf_append (&buff, tmp_name); + rz_strbuf_append (&buff, tmp_name); } - r_strbuf_append (&buff, "*"); - *name = r_strbuf_drain_nofree (&buff); - r_strbuf_fini (&buff); + rz_strbuf_append (&buff, "*"); + *name = rz_strbuf_drain_nofree (&buff); + rz_strbuf_fini (&buff); if (need_to_free) { free (tmp_name); tmp_name = 0; @@ -1748,21 +1748,21 @@ static void get_modifier_print_type(void *type, char **name) { SLF_MODIFIER *modifier = stype_info->type_info; RStrBuf buff; - r_strbuf_init (&buff); + rz_strbuf_init (&buff); if (modifier->umodifier.bits.const_) { - r_strbuf_append (&buff, "const "); + rz_strbuf_append (&buff, "const "); } if (modifier->umodifier.bits.volatile_) { - r_strbuf_append (&buff, "volatile "); + rz_strbuf_append (&buff, "volatile "); } if (modifier->umodifier.bits.unaligned) { - r_strbuf_append (&buff, "unaligned "); + rz_strbuf_append (&buff, "unaligned "); } if (tmp_name) { - r_strbuf_append (&buff, tmp_name); + rz_strbuf_append (&buff, tmp_name); } - *name = r_strbuf_drain_nofree (&buff); - r_strbuf_fini (&buff); + *name = rz_strbuf_drain_nofree (&buff); + rz_strbuf_fini (&buff); if (need_to_free) { free (tmp_name); @@ -1842,7 +1842,7 @@ static void get_enum_print_type(void *type, char **name) { int need_to_free = 1; ti->get_utype (ti, (void **)&t); - r_return_if_fail (t); // This shouldn't happen?, TODO explore this situation + rz_return_if_fail (t); // This shouldn't happen?, TODO explore this situation if (t->type_data.leaf_type == eLF_SIMPLE_TYPE) { // BaseType need_to_free = 0; SLF_SIMPLE_TYPE *base_type = t->type_data.type_info; @@ -1853,13 +1853,13 @@ static void get_enum_print_type(void *type, char **name) { } RStrBuf buff; - r_strbuf_init (&buff); - r_strbuf_append (&buff, "enum "); + rz_strbuf_init (&buff); + rz_strbuf_append (&buff, "enum "); if (tmp_name) { - r_strbuf_append (&buff, tmp_name); + rz_strbuf_append (&buff, tmp_name); } - *name = r_strbuf_drain_nofree (&buff); - r_strbuf_fini (&buff); + *name = rz_strbuf_drain_nofree (&buff); + rz_strbuf_fini (&buff); if (need_to_free) { free (tmp_name); @@ -2574,7 +2574,7 @@ static void init_stype_info(STypeInfo *type_info) type_info->type_info = (void *) lf; \ type_info->leaf_type = type; \ init_stype_info (type_info); \ - r_list_append (lf_fieldlist->substructs, type_info); \ + rz_list_append (lf_fieldlist->substructs, type_info); \ } /////////////////////////////////////////////////////////////////////////////// @@ -2584,7 +2584,7 @@ static int parse_lf_fieldlist(SLF_FIELDLIST *lf_fieldlist, uint8_t *leaf_data, int curr_read_bytes = 0; uint8_t *p = leaf_data; - lf_fieldlist->substructs = r_list_new (); + lf_fieldlist->substructs = rz_list_new (); while (*read_bytes <= len) { READ2(*read_bytes, len, leaf_type, p, ut16); @@ -2952,7 +2952,7 @@ int parse_tpi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream) { int i; SType *type = 0; STpiStream *tpi_stream = (STpiStream *) parsed_pdb_stream; - tpi_stream->types = r_list_new (); + tpi_stream->types = rz_list_new (); p_types_list = tpi_stream->types; stream_file_read(stream, sizeof(STPIHeader), (char *)&tpi_stream->header); @@ -2972,7 +2972,7 @@ int parse_tpi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream) { free (type); return 0; } - r_list_append(tpi_stream->types, type); + rz_list_append(tpi_stream->types, type); } return 1; } diff --git a/libr/bin/pdb/tpi.h b/librz/bin/pdb/tpi.h similarity index 100% rename from libr/bin/pdb/tpi.h rename to librz/bin/pdb/tpi.h diff --git a/libr/bin/pdb/types.h b/librz/bin/pdb/types.h similarity index 98% rename from libr/bin/pdb/types.h rename to librz/bin/pdb/types.h index 8bbcb7d37c..f0df8742d5 100644 --- a/libr/bin/pdb/types.h +++ b/librz/bin/pdb/types.h @@ -2,11 +2,11 @@ #define PDB_TYPES_H #define _R_LIST_C -#include +#include #define READ_PAGE_FAIL 0x01 -// TODO: Move to a general macros in r_util/r_types +// TODO: Move to a general macros in rz_util/rz_types /////////////////////////////////////////////////////////////////////////////// #define GET_PAGE(pn, off, pos, page_size) { \ @@ -49,15 +49,15 @@ } #define PEEK_READ2(curr_read_bytes, max_len, dst, src, type_name) { \ CAN_READ((curr_read_bytes), 2, (max_len)); \ - (dst) = (type_name) r_read_le16 (src); \ + (dst) = (type_name) rz_read_le16 (src); \ } #define PEEK_READ4(curr_read_bytes, max_len, dst, src, type_name) { \ CAN_READ((curr_read_bytes), 4, (max_len)); \ - (dst) = (type_name) r_read_le32 (src); \ + (dst) = (type_name) rz_read_le32 (src); \ } #define PEEK_READ8(curr_read_bytes, max_len, dst, src, type_name) { \ CAN_READ((curr_read_bytes), 8, (max_len)); \ - (dst) = (type_name) r_read_le64 (src); \ + (dst) = (type_name) rz_read_le64 (src); \ } /////////////////////////////////////////////////////////////////////////////// #define READ1(curr_read_bytes, max_len, dst, src, type_name) { \ @@ -105,7 +105,7 @@ typedef void (*free_func)(void *); typedef void (*get_value_name)(void *type, char **res_name); typedef void (*get_value)(void *type, int *res); typedef void (*get_value_name_len)(void *type, int *res); -typedef void (*get_member_list)(void *type, RList **l); +typedef void (*get_member_list)(void *type, RzList **l); typedef int (*get_arg_type_)(void *type, void **ret_type); typedef int (*get_val_type)(void *type, void **ret_type); @@ -724,7 +724,7 @@ typedef struct { typedef struct R_PDB7_ROOT_STREAM{ R_PDB_STREAM pdb_stream; int num_streams; - RList *streams_list; + RzList *streams_list; } R_PDB7_ROOT_STREAM; typedef enum EStream_{ @@ -916,7 +916,7 @@ typedef struct { typedef struct { // ELeafType leaf_type; - RList *substructs; + RzList *substructs; } SLF_FIELDLIST; typedef struct { @@ -1149,7 +1149,7 @@ typedef struct { typedef struct { STPIHeader header; - RList *types; + RzList *types; free_func free_; } STpiStream; @@ -1255,7 +1255,7 @@ typedef struct { typedef struct { SDBIHeader dbi_header; SDbiDbgHeader dbg_header; - RList *dbiexhdrs; + RzList *dbiexhdrs; free_func free_; } SDbiStream; @@ -1284,7 +1284,7 @@ typedef struct { }) SFPO_DATA; typedef struct { - RList *fpo_data_list; + RzList *fpo_data_list; } SFPOStream; typedef enum { @@ -1308,13 +1308,13 @@ typedef struct { }) SFPO_DATA_V2; typedef struct { - RList *fpo_data_list; + RzList *fpo_data_list; } SFPONewStream; // end of FPO stream structures // GDATA structrens typedef struct { - RList *globals_list; + RzList *globals_list; } SGDATAStream; R_PACKED ( @@ -1351,7 +1351,7 @@ typedef struct { }) SIMAGE_SECTION_HEADER; typedef struct { - RList *sections_hdrs; + RzList *sections_hdrs; } SPEStream; // end PE stream structures @@ -1362,7 +1362,7 @@ typedef struct { } SOmapEntry; typedef struct { - RList *omap_entries; + RzList *omap_entries; ut32 *froms; } SOmapStream; // end of omap structures diff --git a/libr/bp/Makefile b/librz/bp/Makefile similarity index 78% rename from libr/bp/Makefile rename to librz/bp/Makefile index 5108d029e1..8c18621163 100644 --- a/libr/bp/Makefile +++ b/librz/bp/Makefile @@ -1,12 +1,12 @@ include ../config.mk -NAME=r_bp -R2DEPS+=r_util +NAME=rz_bp +R2DEPS+=rz_util CFLAGS+=-DR2_PLUGIN_INCORE .PHONY: pre -pre: libr_bp.${EXT_SO} libr_bp.${EXT_AR} +pre: librz_bp.${EXT_SO} librz_bp.${EXT_AR} ${MAKE} -C p include ${STATIC_BP_PLUGINS} diff --git a/libr/bp/README b/librz/bp/README similarity index 99% rename from libr/bp/README rename to librz/bp/README index 9b5d01939e..aa01b989b3 100644 --- a/libr/bp/README +++ b/librz/bp/README @@ -1,4 +1,4 @@ -libr.bp +librz.bp ======= Breakpoint API diff --git a/libr/bp/bp.c b/librz/bp/bp.c similarity index 69% rename from libr/bp/bp.c rename to librz/bp/bp.c index 7fbe46f51f..e0944a7438 100644 --- a/libr/bp/bp.c +++ b/librz/bp/bp.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake */ +/* rizin - LGPL - Copyright 2009-2020 - pancake */ -#include +#include #include -R_LIB_VERSION (r_bp); +R_LIB_VERSION (rz_bp); -static struct r_bp_plugin_t *bp_static_plugins[] = +static struct rz_bp_plugin_t *bp_static_plugins[] = { R_BP_STATIC_PLUGINS }; -static void r_bp_item_free (RBreakpointItem *b) { +static void rz_bp_item_free (RBreakpointItem *b) { free (b->name); free (b->bbytes); free (b->obytes); @@ -18,7 +18,7 @@ static void r_bp_item_free (RBreakpointItem *b) { free (b); } -R_API RBreakpoint *r_bp_new(void) { +RZ_API RBreakpoint *rz_bp_new(void) { int i; RBreakpointPlugin *static_plugin; RBreakpoint *bp = R_NEW0 (RBreakpoint); @@ -28,33 +28,33 @@ R_API RBreakpoint *r_bp_new(void) { bp->bps_idx_count = 16; bp->bps_idx = R_NEWS0 (RBreakpointItem*, bp->bps_idx_count); bp->stepcont = R_BP_CONT_NORMAL; - bp->traces = r_bp_traptrace_new (); + bp->traces = rz_bp_traptrace_new (); bp->cb_printf = (PrintfCallback)printf; - bp->bps = r_list_newf ((RListFree)r_bp_item_free); - bp->plugins = r_list_newf ((RListFree)free); + bp->bps = rz_list_newf ((RzListFree)rz_bp_item_free); + bp->plugins = rz_list_newf ((RzListFree)free); bp->nhwbps = 0; for (i = 0; bp_static_plugins[i]; i++) { static_plugin = R_NEW (RBreakpointPlugin); memcpy (static_plugin, bp_static_plugins[i], sizeof (RBreakpointPlugin)); - r_bp_plugin_add (bp, static_plugin); + rz_bp_plugin_add (bp, static_plugin); } memset (&bp->iob, 0, sizeof (bp->iob)); return bp; } -R_API RBreakpoint *r_bp_free(RBreakpoint *bp) { - r_list_free (bp->bps); - r_list_free (bp->plugins); - r_list_free (bp->traces); +RZ_API RBreakpoint *rz_bp_free(RBreakpoint *bp) { + rz_list_free (bp->bps); + rz_list_free (bp->plugins); + rz_list_free (bp->traces); free (bp->bps_idx); free (bp); return NULL; } -R_API int r_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx) { +RZ_API int rz_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx) { int i; - struct r_bp_arch_t *b; + struct rz_bp_arch_t *b; if (bp->cur) { // find matching size breakpoint repeat: @@ -88,10 +88,10 @@ repeat: return 0; } -R_API RBreakpointItem *r_bp_get_at(RBreakpoint *bp, ut64 addr) { - RListIter *iter; +RZ_API RBreakpointItem *rz_bp_get_at(RBreakpoint *bp, ut64 addr) { + RzListIter *iter; RBreakpointItem *b; - r_list_foreach(bp->bps, iter, b) { + rz_list_foreach(bp->bps, iter, b) { if (b->addr == addr) { return b; } @@ -107,10 +107,10 @@ static inline bool matchProt(RBreakpointItem *b, int perm) { return (!perm || (perm && b->perm)); } -R_API RBreakpointItem *r_bp_get_in(RBreakpoint *bp, ut64 addr, int perm) { +RZ_API RBreakpointItem *rz_bp_get_in(RBreakpoint *bp, ut64 addr, int perm) { RBreakpointItem *b; - RListIter *iter; - r_list_foreach (bp->bps, iter, b) { + RzListIter *iter; + rz_list_foreach (bp->bps, iter, b) { // eprintf ("---ataddr--- 0x%08"PFMT64x" %d %d %x\n", b->addr, b->size, b->recoil, b->perm); // Check addr within range and provided perm matches (or null) if (inRange (b, addr) && matchProt (b, perm)) { @@ -120,8 +120,8 @@ R_API RBreakpointItem *r_bp_get_in(RBreakpoint *bp, ut64 addr, int perm) { return NULL; } -R_API RBreakpointItem *r_bp_enable(RBreakpoint *bp, ut64 addr, int set, int count) { - RBreakpointItem *b = r_bp_get_in (bp, addr, 0); +RZ_API RBreakpointItem *rz_bp_enable(RBreakpoint *bp, ut64 addr, int set, int count) { + RBreakpointItem *b = rz_bp_get_in (bp, addr, 0); if (b) { b->enabled = set; b->togglehits = count; @@ -130,16 +130,16 @@ R_API RBreakpointItem *r_bp_enable(RBreakpoint *bp, ut64 addr, int set, int coun return NULL; } -R_API int r_bp_enable_all(RBreakpoint *bp, int set) { - RListIter *iter; +RZ_API int rz_bp_enable_all(RBreakpoint *bp, int set) { + RzListIter *iter; RBreakpointItem *b; - r_list_foreach (bp->bps, iter, b) { + rz_list_foreach (bp->bps, iter, b) { b->enabled = set; } return true; } -R_API int r_bp_stepy_continuation(RBreakpoint *bp) { +RZ_API int rz_bp_stepy_continuation(RBreakpoint *bp) { // TODO: implement return bp->stepcont; } @@ -151,21 +151,21 @@ static void unlinkBreakpoint(RBreakpoint *bp, RBreakpointItem *b) { bp->bps_idx[i] = NULL; } } - r_list_delete_data (bp->bps, b); + rz_list_delete_data (bp->bps, b); } /* TODO: detect overlapping of breakpoints */ -static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, int size, int hw, int perm) { +static RBreakpointItem *rz_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, int size, int hw, int perm) { int ret; RBreakpointItem *b; if (addr == UT64_MAX || size < 1) { return NULL; } - if (r_bp_get_in (bp, addr, perm)) { + if (rz_bp_get_in (bp, addr, perm)) { eprintf ("Breakpoint already set at this address.\n"); return NULL; } - b = r_bp_item_new (bp); + b = rz_bp_item_new (bp); if (!b) { return NULL; } @@ -195,7 +195,7 @@ static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, b->obytes = NULL; } /* XXX: endian .. use bp->endian */ - ret = r_bp_get_bytes (bp, b->bbytes, size, bp->endian, 0); + ret = rz_bp_get_bytes (bp, b->bbytes, size, bp->endian, 0); if (ret != size) { eprintf ("Cannot get breakpoint bytes. No architecture selected?\n"); unlinkBreakpoint (bp, b); @@ -204,16 +204,16 @@ static RBreakpointItem *r_bp_add(RBreakpoint *bp, const ut8 *obytes, ut64 addr, b->recoil = ret; } bp->nbps++; - r_list_append (bp->bps, b); + rz_list_append (bp->bps, b); return b; } -R_API int r_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm) { +RZ_API int rz_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm) { // TODO return false; } -R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm) { +RZ_API RBreakpointItem* rz_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm) { RBreakpointItem *item; ut8 *bytes; if (size < 1) { @@ -226,19 +226,19 @@ R_API RBreakpointItem* r_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int per if (bp->iob.read_at) { bp->iob.read_at (bp->iob.io, addr, bytes, size); } - item = r_bp_add (bp, bytes, addr, size, R_BP_TYPE_SW, perm); + item = rz_bp_add (bp, bytes, addr, size, R_BP_TYPE_SW, perm); free (bytes); return item; } -R_API RBreakpointItem* r_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm) { - return r_bp_add (bp, NULL, addr, size, R_BP_TYPE_HW, perm); +RZ_API RBreakpointItem* rz_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm) { + return rz_bp_add (bp, NULL, addr, size, R_BP_TYPE_HW, perm); } -R_API int r_bp_del_all(RBreakpoint *bp) { +RZ_API int rz_bp_del_all(RBreakpoint *bp) { int i; - if (!r_list_empty (bp->bps)) { - r_list_purge (bp->bps); + if (!rz_list_empty (bp->bps)) { + rz_list_purge (bp->bps); for (i = 0; i < bp->bps_idx_count; i++) { bp->bps_idx[i] = NULL; } @@ -247,22 +247,22 @@ R_API int r_bp_del_all(RBreakpoint *bp) { return false; } -R_API int r_bp_del(RBreakpoint *bp, ut64 addr) { - RListIter *iter; +RZ_API int rz_bp_del(RBreakpoint *bp, ut64 addr) { + RzListIter *iter; RBreakpointItem *b; /* No _safe loop necessary because we return immediately after the delete. */ - r_list_foreach (bp->bps, iter, b) { + rz_list_foreach (bp->bps, iter, b) { if (b->addr == addr) { unlinkBreakpoint (bp, b); - // r_list_delete (bp->bps, iter); + // rz_list_delete (bp->bps, iter); return true; } } return false; } -R_API int r_bp_set_trace(RBreakpoint *bp, ut64 addr, int set) { - RBreakpointItem *b = r_bp_get_in (bp, addr, 0); +RZ_API int rz_bp_set_trace(RBreakpoint *bp, ut64 addr, int set) { + RBreakpointItem *b = rz_bp_get_in (bp, addr, 0); if (b) { b->trace = set; return true; @@ -270,25 +270,25 @@ R_API int r_bp_set_trace(RBreakpoint *bp, ut64 addr, int set) { return false; } -R_API int r_bp_set_trace_all(RBreakpoint *bp, int set) { - RListIter *iter; +RZ_API int rz_bp_set_trace_all(RBreakpoint *bp, int set) { + RzListIter *iter; RBreakpointItem *b; - r_list_foreach (bp->bps, iter, b) { + rz_list_foreach (bp->bps, iter, b) { b->trace = set; } return true; } // TODO: deprecate -R_API int r_bp_list(RBreakpoint *bp, int rad) { +RZ_API int rz_bp_list(RBreakpoint *bp, int rad) { int n = 0; RBreakpointItem *b; - RListIter *iter; + RzListIter *iter; if (rad == 'j') { bp->cb_printf ("["); } //eprintf ("Breakpoint list:\n"); - r_list_foreach (bp->bps, iter, b) { + rz_list_foreach (bp->bps, iter, b) { switch (rad) { case 0: bp->cb_printf ("0x%08"PFMT64x" - 0x%08"PFMT64x \ @@ -301,11 +301,11 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) { b->hw ? "hw": "sw", b->trace ? "trace" : "break", b->enabled ? "enabled" : "disabled", - r_bp_is_valid (bp, b) ? "valid" : "invalid", - r_str_get2 (b->data), - r_str_get2 (b->cond), - r_str_get2 (b->name), - r_str_get2 (b->module_name)); + rz_bp_is_valid (bp, b) ? "valid" : "invalid", + rz_str_get2 (b->data), + rz_str_get2 (b->cond), + rz_str_get2 (b->name), + rz_str_get2 (b->module_name)); break; case 1: case 'r': @@ -334,9 +334,9 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) { b->hw ? "true" : "false", b->trace ? "true" : "false", b->enabled ? "true" : "false", - r_bp_is_valid (bp, b) ? "true" : "false", - r_str_get2 (b->data), - r_str_get2 (b->cond)); + rz_bp_is_valid (bp, b) ? "true" : "false", + rz_str_get2 (b->data), + rz_str_get2 (b->cond)); break; } /* TODO: Show list of pids and trace points, conditionals */ @@ -348,7 +348,7 @@ R_API int r_bp_list(RBreakpoint *bp, int rad) { return n; } -R_API RBreakpointItem *r_bp_item_new (RBreakpoint *bp) { +RZ_API RBreakpointItem *rz_bp_item_new (RBreakpoint *bp) { int i, j; /* find empty slot */ for (i = 0; i < bp->bps_idx_count; i++) { @@ -372,14 +372,14 @@ return_slot: return (bp->bps_idx[i] = R_NEW0 (RBreakpointItem)); } -R_API RBreakpointItem *r_bp_get_index(RBreakpoint *bp, int idx) { +RZ_API RBreakpointItem *rz_bp_get_index(RBreakpoint *bp, int idx) { if (idx >= 0 && idx < bp->bps_idx_count) { return bp->bps_idx[idx]; } return NULL; } -R_API int r_bp_get_index_at (RBreakpoint *bp, ut64 addr) { +RZ_API int rz_bp_get_index_at (RBreakpoint *bp, ut64 addr) { int i; for (i = 0; i< bp->bps_idx_count; i++) { if (bp->bps_idx[i] && bp->bps_idx[i]->addr == addr) { @@ -389,16 +389,16 @@ R_API int r_bp_get_index_at (RBreakpoint *bp, ut64 addr) { return -1; } -R_API int r_bp_del_index(RBreakpoint *bp, int idx) { +RZ_API int rz_bp_del_index(RBreakpoint *bp, int idx) { if (idx >= 0 && idx < bp->bps_idx_count) { - r_list_delete_data (bp->bps, bp->bps_idx[idx]); + rz_list_delete_data (bp->bps, bp->bps_idx[idx]); bp->bps_idx[idx] = 0; return true; } return false; } -R_API int r_bp_size(RBreakpoint *bp) { +RZ_API int rz_bp_size(RBreakpoint *bp) { RBreakpointArch *bpa; int i, bpsize = 8; if (!bp || !bp->cur) { @@ -417,7 +417,7 @@ R_API int r_bp_size(RBreakpoint *bp) { } // Check if the breakpoint is in a valid map -R_API bool r_bp_is_valid(RBreakpoint *bp, RBreakpointItem *b) { +RZ_API bool rz_bp_is_valid(RBreakpoint *bp, RBreakpointItem *b) { if (!bp->bpinmaps) { return true; } diff --git a/libr/bp/bp_io.c b/librz/bp/bp_io.c similarity index 60% rename from libr/bp/bp_io.c rename to librz/bp/bp_io.c index 8727d196e2..ed8b554023 100644 --- a/libr/bp/bp_io.c +++ b/librz/bp/bp_io.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2018 pancake */ -#include +#include #include -R_API void r_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set) { +RZ_API void rz_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set) { if (set) { //eprintf ("Setting bp at 0x%08"PFMT64x"\n", b->addr); if (b->hw || !b->bbytes) { @@ -22,27 +22,27 @@ R_API void r_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set) { } /** - * reflect all r_bp stuff in the process using dbg->bp_write or ->breakpoint + * reflect all rz_bp stuff in the process using dbg->bp_write or ->breakpoint */ -R_API int r_bp_restore(RBreakpoint *bp, bool set) { - return r_bp_restore_except (bp, set, UT64_MAX); +RZ_API int rz_bp_restore(RBreakpoint *bp, bool set) { + return rz_bp_restore_except (bp, set, UT64_MAX); } /** - * reflect all r_bp stuff in the process using dbg->bp_write or ->breakpoint + * reflect all rz_bp stuff in the process using dbg->bp_write or ->breakpoint * * except the specified breakpoint... */ -R_API bool r_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr) { +RZ_API bool rz_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr) { bool rc = true; - RListIter *iter; + RzListIter *iter; RBreakpointItem *b; if (set && bp->bpinmaps) { bp->corebind.syncDebugMaps (bp->corebind.core); } - r_list_foreach (bp->bps, iter, b) { + rz_list_foreach (bp->bps, iter, b) { if (addr && b->addr == addr) { continue; } @@ -51,15 +51,15 @@ R_API bool r_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr) { continue; } // Check if the breakpoint is in a valid map - if (set && bp->bpinmaps && !r_bp_is_valid (bp, b)) { + if (set && bp->bpinmaps && !rz_bp_is_valid (bp, b)) { continue; } if (bp->breakpoint && bp->breakpoint (bp, b, set)) { continue; } - /* write (o|b)bytes from every breakpoint in r_bp if not handled by plugin */ - r_bp_restore_one (bp, b, set); + /* write (o|b)bytes from every breakpoint in rz_bp if not handled by plugin */ + rz_bp_restore_one (bp, b, set); rc = true; } return rc; diff --git a/libr/bp/bp_plugin.c b/librz/bp/bp_plugin.c similarity index 57% rename from libr/bp/bp_plugin.c rename to librz/bp/bp_plugin.c index 1b834a4d72..2120d92cae 100644 --- a/libr/bp/bp_plugin.c +++ b/librz/bp/bp_plugin.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2009-2015 - pancake */ -#include +#include -R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name) { - RListIter *iter; +RZ_API int rz_bp_plugin_del(RBreakpoint *bp, const char *name) { + RzListIter *iter; RBreakpointPlugin *h; if (name && *name) { - r_list_foreach (bp->plugins, iter, h) { + rz_list_foreach (bp->plugins, iter, h) { if (!strcmp (h->name, name)) { if (bp->cur == h) { bp->cur = NULL; } - r_list_delete (bp->plugins, iter); + rz_list_delete (bp->plugins, iter); bp->nbps--; return true; } @@ -20,29 +20,29 @@ R_API int r_bp_plugin_del(RBreakpoint *bp, const char *name) { return false; } -R_API int r_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) { - RListIter *iter; +RZ_API int rz_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo) { + RzListIter *iter; RBreakpointPlugin *h; if (!bp) { eprintf ("Cannot add plugin because dbg->bp is null and/or plugin is null\n"); return false; } /* avoid dupped plugins */ - r_list_foreach (bp->bps, iter, h) { + rz_list_foreach (bp->bps, iter, h) { if (!strcmp (h->name, foo->name)) { return false; } } bp->nbps++; - r_list_append (bp->plugins, foo); + rz_list_append (bp->plugins, foo); return true; } -R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) { - RListIter *iter; +RZ_API int rz_bp_use(RBreakpoint *bp, const char *name, int bits) { + RzListIter *iter; bp->bits = bits; RBreakpointPlugin *h; - r_list_foreach (bp->plugins, iter, h) { + rz_list_foreach (bp->plugins, iter, h) { if (!strcmp (h->name, name)) { bp->cur = h; return true; @@ -52,10 +52,10 @@ R_API int r_bp_use(RBreakpoint *bp, const char *name, int bits) { } // TODO: deprecate -R_API void r_bp_plugin_list(RBreakpoint *bp) { - RListIter *iter; +RZ_API void rz_bp_plugin_list(RBreakpoint *bp) { + RzListIter *iter; RBreakpointPlugin *b; - r_list_foreach (bp->plugins, iter, b) { + rz_list_foreach (bp->plugins, iter, b) { bp->cb_printf ("bp %c %s\n", (bp->cur && !strcmp (bp->cur->name, b->name))? '*': '-', b->name); diff --git a/libr/bp/bp_traptrace.c b/librz/bp/bp_traptrace.c similarity index 65% rename from libr/bp/bp_traptrace.c rename to librz/bp/bp_traptrace.c index d142780beb..9dfde924c6 100644 --- a/libr/bp/bp_traptrace.c +++ b/librz/bp/bp_traptrace.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2010 pancake */ -// TODO: use r_range here?? -#include -#include +// TODO: use rz_range here?? +#include +#include -R_API void r_bp_traptrace_free(void *ptr) { +RZ_API void rz_bp_traptrace_free(void *ptr) { RBreakpointTrace *trace = ptr; free (trace->buffer); free (trace->traps); @@ -12,49 +12,49 @@ R_API void r_bp_traptrace_free(void *ptr) { free (trace); } -R_API RList *r_bp_traptrace_new(void) { - RList *list = r_list_new (); +RZ_API RzList *rz_bp_traptrace_new(void) { + RzList *list = rz_list_new (); if (!list) { return NULL; } - list->free = &r_bp_traptrace_free; + list->free = &rz_bp_traptrace_free; return list; } -R_API void r_bp_traptrace_enable(RBreakpoint *bp, int enable) { - RListIter *iter; +RZ_API void rz_bp_traptrace_enable(RBreakpoint *bp, int enable) { + RzListIter *iter; RBreakpointTrace *trace; - r_list_foreach (bp->traces, iter, trace) { + rz_list_foreach (bp->traces, iter, trace) { ut8 *buf = (enable)?trace->traps:trace->buffer; bp->iob.write_at (bp->iob.io, trace->addr, buf, trace->length); } } -R_API void r_bp_traptrace_reset(RBreakpoint *bp, int hard) { - RListIter *iter; +RZ_API void rz_bp_traptrace_reset(RBreakpoint *bp, int hard) { + RzListIter *iter; RBreakpointTrace *trace; - r_list_foreach (bp->traces, iter, trace) { + rz_list_foreach (bp->traces, iter, trace) { if (hard) { - r_bp_traptrace_free (trace); + rz_bp_traptrace_free (trace); // XXX: This segfaults - //r_list_delete (bp->traces, r_list_iter_cur (iter)); + //rz_list_delete (bp->traces, rz_list_iter_cur (iter)); } else { memset (trace->bits, 0x00, trace->bitlen); } } if (hard) { // XXX: traces not freed correctly (memleak) - bp->traces = r_list_new (); - bp->traces->free = r_bp_traptrace_free; + bp->traces = rz_list_new (); + bp->traces->free = rz_bp_traptrace_free; } } // FIX: efficiency -R_API ut64 r_bp_traptrace_next(RBreakpoint *bp, ut64 addr) { +RZ_API ut64 rz_bp_traptrace_next(RBreakpoint *bp, ut64 addr) { int i, delta; - RListIter *iter; + RzListIter *iter; RBreakpointTrace *trace; - r_list_foreach (bp->traces, iter, trace) { + rz_list_foreach (bp->traces, iter, trace) { if (addr>=trace->addr && addr<=trace->addr_end) { delta = (int)(addr-trace->addr); for (i=delta; ilength; i++) { @@ -67,7 +67,7 @@ R_API ut64 r_bp_traptrace_next(RBreakpoint *bp, ut64 addr) { return 0LL; } -R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) { +RZ_API int rz_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) { RBreakpointTrace *trace; ut8 *buf, *trap, *bits; ut64 len; @@ -102,7 +102,7 @@ R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) { // TODO: check return value bp->iob.read_at (bp->iob.io, from, buf, len); memset (bits, 0x00, bitlen); - r_bp_get_bytes (bp, trap, len, bp->endian, 0); + rz_bp_get_bytes (bp, trap, len, bp->endian, 0); trace = R_NEW (RBreakpointTrace); if (!trace) { @@ -117,7 +117,7 @@ R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) { trace->traps = trap; trace->buffer = buf; trace->length = len; - if (!r_list_append (bp->traces, trace)){ + if (!rz_list_append (bp->traces, trace)){ free (buf); free (trap); free (trace); @@ -128,27 +128,27 @@ R_API int r_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to) { return true; } -R_API int r_bp_traptrace_free_at(RBreakpoint *bp, ut64 from) { +RZ_API int rz_bp_traptrace_free_at(RBreakpoint *bp, ut64 from) { int ret = false; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; RBreakpointTrace *trace; - r_list_foreach_safe (bp->traces, iter, iter_tmp, trace) { + rz_list_foreach_safe (bp->traces, iter, iter_tmp, trace) { if (from>=trace->addr && from<=trace->addr_end) { bp->iob.write_at (bp->iob.io, trace->addr, trace->buffer, trace->length); - r_bp_traptrace_free (trace); - r_list_delete (bp->traces, iter); + rz_bp_traptrace_free (trace); + rz_list_delete (bp->traces, iter); ret = true; } } return ret; } -R_API void r_bp_traptrace_list(RBreakpoint *bp) { +RZ_API void rz_bp_traptrace_list(RBreakpoint *bp) { int i; - RListIter *iter; + RzListIter *iter; RBreakpointTrace *trace; - r_list_foreach (bp->traces, iter, trace) { + rz_list_foreach (bp->traces, iter, trace) { for (i = 0; i < trace->bitlen; i++) { if (R_BIT_CHK (trace->bits, i)) { eprintf (" - 0x%08" PFMT64x "\n", trace->addr + (i << 4)); @@ -157,11 +157,11 @@ R_API void r_bp_traptrace_list(RBreakpoint *bp) { } } -R_API int r_bp_traptrace_at(RBreakpoint *bp, ut64 from, int len) { +RZ_API int rz_bp_traptrace_at(RBreakpoint *bp, ut64 from, int len) { int delta; - RListIter *iter; + RzListIter *iter; RBreakpointTrace *trace; - r_list_foreach (bp->traces, iter, trace) { + rz_list_foreach (bp->traces, iter, trace) { // TODO: do we really need len? if (from>=trace->addr && from+len<=trace->addr_end) { delta = (int) (from-trace->addr); diff --git a/libr/bp/bp_watch.c b/librz/bp/bp_watch.c similarity index 60% rename from libr/bp/bp_watch.c rename to librz/bp/bp_watch.c index ca126d2b5f..57828e71af 100644 --- a/libr/bp/bp_watch.c +++ b/librz/bp/bp_watch.c @@ -1,38 +1,38 @@ /* radare - LGPL - Copyright 2010-2017 pancake, rkx1209 */ -#include +#include -static void r_bp_watch_add_hw(RBreakpoint *bp, RBreakpointItem *b) { +static void rz_bp_watch_add_hw(RBreakpoint *bp, RBreakpointItem *b) { if (bp->breakpoint) { bp->breakpoint (bp, b, true); } } -R_API RBreakpointItem* r_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int perm) { +RZ_API RBreakpointItem* rz_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int perm) { RBreakpointItem *b; if (addr == UT64_MAX || size < 1) { return NULL; } - if (r_bp_get_in (bp, addr, perm)) { + if (rz_bp_get_in (bp, addr, perm)) { eprintf ("Breakpoint already set at this address.\n"); return NULL; } - b = r_bp_item_new (bp); + b = rz_bp_item_new (bp); b->addr = addr + bp->delta; b->size = size; b->enabled = true; b->perm = perm; b->hw = hw; if (hw) { - r_bp_watch_add_hw (bp, b); + rz_bp_watch_add_hw (bp, b); } else { eprintf ("[TODO]: Software watchpoint is not implemented yet (use ESIL)\n"); /* TODO */ } bp->nbps++; - r_list_append (bp->bps, b); + rz_list_append (bp->bps, b); return b; } -R_API void r_bp_watch_del(void) { +RZ_API void rz_bp_watch_del(void) { } diff --git a/libr/bp/meson.build b/librz/bp/meson.build similarity index 69% rename from libr/bp/meson.build rename to librz/bp/meson.build index ed7aa6d352..b8c184e0cd 100644 --- a/libr/bp/meson.build +++ b/librz/bp/meson.build @@ -1,4 +1,4 @@ -r_bp_sources = [ +rz_bp_sources = [ 'bp.c', 'bp_io.c', 'bp_plugin.c', @@ -12,27 +12,27 @@ r_bp_sources = [ 'p/bp_x86.c' ] -r_bp = library('r_bp', r_bp_sources, +rz_bp = library('rz_bp', rz_bp_sources, include_directories: [platform_inc], c_args: library_cflags, - dependencies: [r_util_dep], + dependencies: [rz_util_dep], install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_bp_dep = declare_dependency(link_with: r_bp, +rz_bp_dep = declare_dependency(link_with: rz_bp, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_bp, - subdirs: 'libr', +pkgconfig_mod.generate(rz_bp, + subdirs: 'librz', version: r2_version, - name: 'r_bp', - filebase: 'r_bp', + name: 'rz_bp', + filebase: 'rz_bp', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/bp/p/Makefile b/librz/bp/p/Makefile similarity index 100% rename from libr/bp/p/Makefile rename to librz/bp/p/Makefile diff --git a/libr/bp/p/arm.mk b/librz/bp/p/arm.mk similarity index 100% rename from libr/bp/p/arm.mk rename to librz/bp/p/arm.mk diff --git a/libr/bp/p/bf.mk b/librz/bp/p/bf.mk similarity index 100% rename from libr/bp/p/bf.mk rename to librz/bp/p/bf.mk diff --git a/libr/bp/p/bp_arm.c b/librz/bp/p/bp_arm.c similarity index 87% rename from libr/bp/p/bp_arm.c rename to librz/bp/p/bp_arm.c index cb900fd063..250d9fef49 100644 --- a/libr/bp/p/bp_arm.c +++ b/librz/bp/p/bp_arm.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_arm_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_arm_bps[] = { { 64, 4, 0, (const ut8*)"\x00\x00\x20\xd4" }, // le - arm64 brk0 { 64, 4, 1, (const ut8*)"\xd4\x20\x00\x00" }, // be - arm64 //{ 64, 1, 0, (const ut8*)"\xfe\xde\xff\xe7" }, // le - arm64 // hacky fix @@ -30,17 +30,17 @@ static struct r_bp_arch_t r_bp_plugin_arm_bps[] = { { 0, 0, 0, NULL } }; -struct r_bp_plugin_t r_bp_plugin_arm = { +struct rz_bp_plugin_t rz_bp_plugin_arm = { .name = "arm", .arch = "arm", .nbps = 9, - .bps = r_bp_plugin_arm_bps, + .bps = rz_bp_plugin_arm_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_arm, + .data = &rz_bp_plugin_arm, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/bp_bf.c b/librz/bp/p/bp_bf.c similarity index 55% rename from libr/bp/p/bp_bf.c rename to librz/bp/p/bp_bf.c index 7730465dfb..a8d859b0bb 100644 --- a/libr/bp/p/bp_bf.c +++ b/librz/bp/p/bp_bf.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2011 pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_bf_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_bf_bps[] = { { 0, 1, 0, (const ut8*)"\xff" }, { 0, 1, 0, (const ut8*)"\x00" }, { 0, 0, 0, NULL }, }; -struct r_bp_plugin_t r_bp_plugin_bf = { +struct rz_bp_plugin_t rz_bp_plugin_bf = { .name = "bf", .arch = "bf", .nbps = 2, - .bps = r_bp_plugin_bf_bps, + .bps = rz_bp_plugin_bf_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_bf, + .data = &rz_bp_plugin_bf, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/bp_mips.c b/librz/bp/p/bp_mips.c similarity index 54% rename from libr/bp/p/bp_mips.c rename to librz/bp/p/bp_mips.c index 53ea947086..5aabde197a 100644 --- a/libr/bp/p/bp_mips.c +++ b/librz/bp/p/bp_mips.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2010-2015 - pancake */ +/* rizin - LGPL - Copyright 2010-2015 - pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_mips_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_mips_bps[] = { { 32, 4, 0, (const ut8*)"\x0d\x00\x00\x00" }, { 32, 4, 1, (const ut8*)"\x00\x00\x00\x0d" }, { 64, 4, 0, (const ut8*)"\x0d\x00\x00\x00" }, @@ -11,17 +11,17 @@ static struct r_bp_arch_t r_bp_plugin_mips_bps[] = { { 0, 0, 0, NULL } }; -struct r_bp_plugin_t r_bp_plugin_mips = { +struct rz_bp_plugin_t rz_bp_plugin_mips = { .name = "mips", .arch = "mips", .nbps = 10, - .bps = r_bp_plugin_mips_bps, + .bps = rz_bp_plugin_mips_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_mips, + .data = &rz_bp_plugin_mips, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/bp_ppc.c b/librz/bp/p/bp_ppc.c similarity index 63% rename from libr/bp/p/bp_ppc.c rename to librz/bp/p/bp_ppc.c index 7525b3eab8..7d5aea2f48 100644 --- a/libr/bp/p/bp_ppc.c +++ b/librz/bp/p/bp_ppc.c @@ -1,26 +1,26 @@ /* radare - LGPL - Copyright 2010 pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_ppc_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_ppc_bps[] = { /* XXX: FIX those are not really breakpoint opcodes at all */ { 32, 4, 0, (const ut8*)"\x00\x00\x00\x0d" }, // little endian { 32, 4, 1, (const ut8*)"\x0d\x00\x00\x00" }, // big endian { 0, 0, 0, NULL } }; -struct r_bp_plugin_t r_bp_plugin_ppc = { +struct rz_bp_plugin_t rz_bp_plugin_ppc = { .name = "ppc", .arch = "ppc", .nbps = 2, - .bps = r_bp_plugin_ppc_bps, + .bps = rz_bp_plugin_ppc_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_ppc, + .data = &rz_bp_plugin_ppc, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/bp_sh.c b/librz/bp/p/bp_sh.c similarity index 58% rename from libr/bp/p/bp_sh.c rename to librz/bp/p/bp_sh.c index c81f838ea4..495ed57163 100644 --- a/libr/bp/p/bp_sh.c +++ b/librz/bp/p/bp_sh.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2009-2015 - pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_sh_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_sh_bps[] = { { 32, 2, 0, (const ut8*)"\x20\xc3" }, //Little endian bp { 32, 2, 1, (const ut8*)"\xc3\x20" }, //Big endian bp { 0, 0, 0, NULL }, }; -struct r_bp_plugin_t r_bp_plugin_sh = { +struct rz_bp_plugin_t rz_bp_plugin_sh = { .name = "sh", .arch = "sh", .nbps = 2, - .bps = r_bp_plugin_sh_bps, + .bps = rz_bp_plugin_sh_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_sh, + .data = &rz_bp_plugin_sh, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/bp_x86.c b/librz/bp/p/bp_x86.c similarity index 56% rename from libr/bp/p/bp_x86.c rename to librz/bp/p/bp_x86.c index 0f7b234a1c..5ede1fe94d 100644 --- a/libr/bp/p/bp_x86.c +++ b/librz/bp/p/bp_x86.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2009-2015 - pancake */ -#include -#include +#include +#include -static struct r_bp_arch_t r_bp_plugin_x86_bps[] = { +static struct rz_bp_arch_t rz_bp_plugin_x86_bps[] = { { 0, 1, 0, (const ut8*)"\xcc" }, // valid for 16, 32, 64 { 0, 2, 0, (const ut8*)"\xcd\x03" }, { 0, 0, 0, NULL }, }; -struct r_bp_plugin_t r_bp_plugin_x86 = { +struct rz_bp_plugin_t rz_bp_plugin_x86 = { .name = "x86", .arch = "x86", .nbps = 2, - .bps = r_bp_plugin_x86_bps, + .bps = rz_bp_plugin_x86_bps, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_BP, - .data = &r_bp_plugin_x86, + .data = &rz_bp_plugin_x86, .version = R2_VERSION }; #endif diff --git a/libr/bp/p/mips.mk b/librz/bp/p/mips.mk similarity index 100% rename from libr/bp/p/mips.mk rename to librz/bp/p/mips.mk diff --git a/libr/bp/p/ppc.mk b/librz/bp/p/ppc.mk similarity index 100% rename from libr/bp/p/ppc.mk rename to librz/bp/p/ppc.mk diff --git a/libr/bp/p/sh.mk b/librz/bp/p/sh.mk similarity index 100% rename from libr/bp/p/sh.mk rename to librz/bp/p/sh.mk diff --git a/libr/bp/p/x86.mk b/librz/bp/p/x86.mk similarity index 100% rename from libr/bp/p/x86.mk rename to librz/bp/p/x86.mk diff --git a/libr/config.h.head b/librz/config.h.head similarity index 100% rename from libr/config.h.head rename to librz/config.h.head diff --git a/libr/config.h.in b/librz/config.h.in similarity index 100% rename from libr/config.h.in rename to librz/config.h.in diff --git a/libr/config.h.tail b/librz/config.h.tail similarity index 100% rename from libr/config.h.tail rename to librz/config.h.tail diff --git a/libr/config.mk.head b/librz/config.mk.head similarity index 100% rename from libr/config.mk.head rename to librz/config.mk.head diff --git a/libr/config.mk.tail b/librz/config.mk.tail similarity index 90% rename from libr/config.mk.tail rename to librz/config.mk.tail index 32dc82cece..4f6c11f6d9 100644 --- a/libr/config.mk.tail +++ b/librz/config.mk.tail @@ -9,7 +9,7 @@ ifeq ($(LIBR),) ifeq ($(R2DIR),) $(error ERROR: Cannot find R2DIR. Please define this variable) else -LIBR=$(R2DIR)/libr +LIBR=$(R2DIR)/librz MSVC=$(R2DIR)/msvc endif endif @@ -25,15 +25,15 @@ CFLAGS+=${CPPFLAGS} ifeq (1,1) #$(WITHPIC),1) -LINK+=$(subst r_,-L$(LIBR)/,$(R2DEPS)) -LINK+=$(subst r_,-lr_,$(R2DEPS)) -LINK+=$(subst r_,-L$(LIBR)/,$(BINDEPS)) -LINK+=$(subst r_,-lr_,$(BINDEPS)) +LINK+=$(subst rz_,-L$(LIBR)/,$(R2DEPS)) +LINK+=$(subst rz_,-lrz_,$(R2DEPS)) +LINK+=$(subst rz_,-L$(LIBR)/,$(BINDEPS)) +LINK+=$(subst rz_,-lrz_,$(BINDEPS)) CFLAGS+=${PIC_CFLAGS} LINK+=${PIC_CFLAGS} else ifneq ($(R2DEPS),) -LINK+=$(shell echo ${R2DEPS} | sed -e 's:r_\([^ ]\+\):$(LIBR)/\1/libr_\1.${EXT_AR}:g') +LINK+=$(shell echo ${R2DEPS} | sed -e 's:rz_\([^ ]\+\):$(LIBR)/\1/libr_\1.${EXT_AR}:g') endif endif @@ -58,7 +58,7 @@ BN_LIBS=${SSL_LDFLAGS} endif #both of these need ssl includes -ifneq (,$(filter r_socket r_util,$(BINDEPS))) +ifneq (,$(filter rz_socket rz_util,$(BINDEPS))) ifeq (${HAVE_LIB_SSL},1) CFLAGS+=${SSL_CFLAGS} endif diff --git a/libr/config/Makefile b/librz/config/Makefile similarity index 71% rename from libr/config/Makefile rename to librz/config/Makefile index 646cf3cfe6..94e744d085 100644 --- a/libr/config/Makefile +++ b/librz/config/Makefile @@ -1,7 +1,7 @@ include ../config.mk -NAME=r_config -R2DEPS=r_util +NAME=rz_config +R2DEPS=rz_util OBJS=config.o callback.o hold.o include ../rules.mk diff --git a/librz/config/callback.c b/librz/config/callback.c new file mode 100644 index 0000000000..090f93ff43 --- /dev/null +++ b/librz/config/callback.c @@ -0,0 +1,56 @@ +/* radare - LGPL - Copyright 2006-2019 - pancake */ + +#include "rz_config.h" + +static bool rz_config_setter_q(void *data) { + RConfigNode *node = data; + *(node->cb_ptr_q) = node->i_value; + return true; +} + +static bool rz_config_setter_i(void *data) { + RConfigNode *node = data; + *(node->cb_ptr_i) = node->i_value; + return true; +} + +static bool rz_config_setter_s(void *data) { + RConfigNode *node = data; + if (!node->value || !*node->value) { + free (*node->cb_ptr_s); + *node->cb_ptr_s = NULL; + } else { + *node->cb_ptr_s = rz_str_dup (*node->cb_ptr_s, node->value); + } + return true; +} + +RZ_API bool rz_config_set_setter_q(RConfig *cfg, const char *name, ut64 *ptr) { + RConfigNode *node = rz_config_node_get (cfg, name); + if (node) { + node->cb_ptr_q = ptr; + node->setter = (void *) &rz_config_setter_q; + return true; + } + return false; +} + +RZ_API bool rz_config_set_setter_i(RConfig *cfg, const char *name, int *ptr) { + RConfigNode *node = rz_config_node_get (cfg, name); + if (node) { + node->cb_ptr_i = ptr; + node->setter = (void *) &rz_config_setter_i; + return true; + } + return false; +} + +RZ_API bool rz_config_set_setter_s(RConfig *cfg, const char *name, char * *ptr) { + RConfigNode *node = rz_config_node_get (cfg, name); + if (node) { + node->cb_ptr_s = ptr; + node->setter = (void *) &rz_config_setter_s; + return true; + } + return false; +} diff --git a/libr/config/config.c b/librz/config/config.c similarity index 57% rename from libr/config/config.c rename to librz/config/config.c index f077ee2881..4b7b956265 100644 --- a/libr/config/config.c +++ b/librz/config/config.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2006-2020 - pancake */ -#include "r_config.h" +#include "rz_config.h" -R_API RConfigNode* r_config_node_new(const char *name, const char *value) { - r_return_val_if_fail (name && *name && value, NULL); +RZ_API RConfigNode* rz_config_node_new(const char *name, const char *value) { + rz_return_val_if_fail (name && *name && value, NULL); RConfigNode *node = R_NEW0 (RConfigNode); if (!node) { return NULL; @@ -11,13 +11,13 @@ R_API RConfigNode* r_config_node_new(const char *name, const char *value) { node->name = strdup (name); node->value = strdup (value? value: ""); node->flags = CN_RW | CN_STR; - node->i_value = r_num_get (NULL, value); - node->options = r_list_new (); + node->i_value = rz_num_get (NULL, value); + node->options = rz_list_new (); return node; } -R_API RConfigNode* r_config_node_clone(RConfigNode *n) { - r_return_val_if_fail (n, NULL); +RZ_API RConfigNode* rz_config_node_clone(RConfigNode *n) { + rz_return_val_if_fail (n, NULL); RConfigNode *cn = R_NEW0 (RConfigNode); if (!cn) { return NULL; @@ -28,11 +28,11 @@ R_API RConfigNode* r_config_node_clone(RConfigNode *n) { cn->i_value = n->i_value; cn->flags = n->flags; cn->setter = n->setter; - cn->options = r_list_clone (n->options); + cn->options = rz_list_clone (n->options); return cn; } -R_API void r_config_node_free(void *n) { +RZ_API void rz_config_node_free(void *n) { RConfigNode *node = (RConfigNode *)n; if (!node) { return; @@ -40,22 +40,22 @@ R_API void r_config_node_free(void *n) { free (node->name); free (node->desc); free (node->value); - r_list_free (node->options); + rz_list_free (node->options); free (node); } static void config_print_value_json(RConfig *cfg, RConfigNode *node) { - r_return_if_fail (cfg && node); + rz_return_if_fail (cfg && node); const char *val = node->value; if (!val) { val = "0"; } - char *sval = r_str_escape (val); - if (r_config_node_is_bool (node) || r_config_node_is_int (node)) { + char *sval = rz_str_escape (val); + if (rz_config_node_is_bool (node) || rz_config_node_is_int (node)) { if (!strncmp (val, "0x", 2)) { - ut64 n = r_num_get (NULL, val); + ut64 n = rz_num_get (NULL, val); cfg->cb_printf ("%"PFMT64d, n); - } else if (r_str_isnumber (val) || (*val /* HACK */ && r_str_is_bool (val))) { + } else if (rz_str_isnumber (val) || (*val /* HACK */ && rz_str_is_bool (val))) { cfg->cb_printf ("%s", val); // TODO: always use true/false for bool json str } else { cfg->cb_printf ("\"%s\"", sval); @@ -67,10 +67,10 @@ static void config_print_value_json(RConfig *cfg, RConfigNode *node) { } static void config_print_node(RConfig *cfg, RConfigNode *node, const char *pfx, const char *sfx, bool verbose, bool json) { - r_return_if_fail (cfg && node && pfx && sfx); + rz_return_if_fail (cfg && node && pfx && sfx); char *option; bool isFirst; - RListIter *iter; + RzListIter *iter; char *es = NULL; if (json) { @@ -79,18 +79,18 @@ static void config_print_node(RConfig *cfg, RConfigNode *node, const char *pfx, cfg->cb_printf ("\"name\":\"%s\",", node->name); cfg->cb_printf ("\"value\":"); config_print_value_json (cfg, node); - cfg->cb_printf (",\"type\":\"%s\",", r_config_node_type (node)); - es = r_str_escape (node->desc); + cfg->cb_printf (",\"type\":\"%s\",", rz_config_node_type (node)); + es = rz_str_escape (node->desc); if (es) { cfg->cb_printf ("\"desc\":\"%s\",", es); free (es); } - cfg->cb_printf ("\"ro\":%s", r_str_bool (r_config_node_is_ro (node))); - if (!r_list_empty (node->options)) { + cfg->cb_printf ("\"ro\":%s", rz_str_bool (rz_config_node_is_ro (node))); + if (!rz_list_empty (node->options)) { isFirst = true; cfg->cb_printf (",\"options\":["); - r_list_foreach (node->options, iter, option) { - es = r_str_escape (option); + rz_list_foreach (node->options, iter, option) { + es = rz_str_escape (option); if (es) { if (isFirst) { isFirst = false; @@ -112,12 +112,12 @@ static void config_print_node(RConfig *cfg, RConfigNode *node, const char *pfx, if (verbose) { cfg->cb_printf ("%s%s = %s%s %s; %s", pfx, node->name, node->value, sfx, - r_config_node_is_ro (node) ? "(ro)" : "", + rz_config_node_is_ro (node) ? "(ro)" : "", node->desc); - if (!r_list_empty (node->options)) { + if (!rz_list_empty (node->options)) { isFirst = true; cfg->cb_printf(" ["); - r_list_foreach (node->options, iter, option) { + rz_list_foreach (node->options, iter, option) { if (isFirst) { isFirst = false; } else { @@ -135,10 +135,10 @@ static void config_print_node(RConfig *cfg, RConfigNode *node, const char *pfx, } } -R_API void r_config_list(RConfig *cfg, const char *str, int rad) { - r_return_if_fail (cfg); +RZ_API void rz_config_list(RConfig *cfg, const char *str, int rad) { + rz_return_if_fail (cfg); RConfigNode *node; - RListIter *iter; + RzListIter *iter; const char *sfx = ""; const char *pfx = ""; int len = 0; @@ -147,7 +147,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { bool isFirst = false; if (!IS_NULLSTR (str)) { - str = r_str_trim_head_ro (str); + str = rz_str_trim_head_ro (str); len = strlen (str); if (len > 0 && str[0] == 'j') { str++; @@ -171,14 +171,14 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { sfx = "\""; /* fallthrou */ case 0: - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { if (!str || (str && (!strncmp (str, node->name, len)))) { config_print_node (cfg, node, pfx, sfx, verbose, json); } } break; case 2: - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { if (!str || (str && (!strncmp (str, node->name, len)))) { if (!str || !strncmp (str, node->name, len)) { cfg->cb_printf ("%20s: %s\n", node->name, @@ -189,7 +189,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { break; case 's': if (str && *str) { - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { char *space = strdup (node->name); char *dot = strchr (space, '.'); if (dot) { @@ -202,7 +202,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { } } else { char *oldSpace = NULL; - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { char *space = strdup (node->name); char *dot = strchr (space, '.'); if (dot) { @@ -225,14 +225,14 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { break; case 'v': verbose = true; - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { if (!str || (str && (!strncmp (str, node->name, len)))) { config_print_node (cfg, node, pfx, sfx, verbose, json); } } break; case 'q': - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { cfg->cb_printf ("%s\n", node->name); } break; @@ -246,7 +246,7 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { } else { cfg->cb_printf ("{"); } - r_list_foreach (cfg->nodes, iter, node) { + rz_list_foreach (cfg->nodes, iter, node) { if (!str || (str && (!strncmp (str, node->name, len)))) { if (!str || !strncmp (str, node->name, len)) { if (isFirst) { @@ -267,14 +267,14 @@ R_API void r_config_list(RConfig *cfg, const char *str, int rad) { } } -R_API RConfigNode* r_config_node_get(RConfig *cfg, const char *name) { - r_return_val_if_fail (cfg && name, NULL); +RZ_API RConfigNode* rz_config_node_get(RConfig *cfg, const char *name) { + rz_return_val_if_fail (cfg && name, NULL); return ht_pp_find (cfg->ht, name, NULL); } -R_API bool r_config_set_getter(RConfig *cfg, const char *key, RConfigCallback cb) { - r_return_val_if_fail (cfg && key, false); - RConfigNode *node = r_config_node_get (cfg, key); +RZ_API bool rz_config_set_getter(RConfig *cfg, const char *key, RConfigCallback cb) { + rz_return_val_if_fail (cfg && key, false); + RConfigNode *node = rz_config_node_get (cfg, key); if (node) { node->getter = cb; return true; @@ -282,8 +282,8 @@ R_API bool r_config_set_getter(RConfig *cfg, const char *key, RConfigCallback cb return false; } -R_API bool r_config_set_setter(RConfig *cfg, const char *key, RConfigCallback cb) { - RConfigNode *node = r_config_node_get (cfg, key); +RZ_API bool rz_config_set_setter(RConfig *cfg, const char *key, RConfigCallback cb) { + RConfigNode *node = rz_config_node_get (cfg, key); if (node) { node->setter = cb; return true; @@ -291,34 +291,34 @@ R_API bool r_config_set_setter(RConfig *cfg, const char *key, RConfigCallback cb return false; } -R_API const char* r_config_get(RConfig *cfg, const char *name) { - r_return_val_if_fail (cfg && name, NULL); - RConfigNode *node = r_config_node_get (cfg, name); +RZ_API const char* rz_config_get(RConfig *cfg, const char *name) { + rz_return_val_if_fail (cfg && name, NULL); + RConfigNode *node = rz_config_node_get (cfg, name); if (node) { if (node->getter) { node->getter (cfg->user, node); } - if (r_config_node_is_bool (node)) { - return r_str_bool (r_str_is_true (node->value)); + if (rz_config_node_is_bool (node)) { + return rz_str_bool (rz_str_is_true (node->value)); } return node->value; } else { - eprintf ("r_config_get: variable '%s' not found\n", name); + eprintf ("rz_config_get: variable '%s' not found\n", name); } return NULL; } -R_API bool r_config_toggle(RConfig *cfg, const char *name) { - RConfigNode *node = r_config_node_get (cfg, name); - if (node && r_config_node_is_bool (node)) { - (void)r_config_set_i (cfg, name, !node->i_value); +RZ_API bool rz_config_toggle(RConfig *cfg, const char *name) { + RConfigNode *node = rz_config_node_get (cfg, name); + if (node && rz_config_node_is_bool (node)) { + (void)rz_config_set_i (cfg, name, !node->i_value); return true; } return false; } -R_API ut64 r_config_get_i(RConfig *cfg, const char *name) { - RConfigNode *node = r_config_node_get (cfg, name); +RZ_API ut64 rz_config_get_i(RConfig *cfg, const char *name) { + RConfigNode *node = rz_config_node_get (cfg, name); if (node) { if (node->getter) { node->getter (cfg->user, node); @@ -329,21 +329,21 @@ R_API ut64 r_config_get_i(RConfig *cfg, const char *name) { if (!strcmp (node->value, "true")) { return 1; } - return (ut64) r_num_math (cfg->num, node->value); + return (ut64) rz_num_math (cfg->num, node->value); } return (ut64) 0LL; } -R_API const char* r_config_node_type(RConfigNode *node) { - r_return_val_if_fail (node, ""); +RZ_API const char* rz_config_node_type(RConfigNode *node) { + rz_return_val_if_fail (node, ""); - if (r_config_node_is_bool (node)) { + if (rz_config_node_is_bool (node)) { return "bool"; } - if (r_config_node_is_str (node)) { + if (rz_config_node_is_str (node)) { return "str"; } - if (r_config_node_is_int (node)) { + if (rz_config_node_is_int (node)) { if (!strncmp (node->value, "0x", 2)) { return "addr"; } @@ -352,8 +352,8 @@ R_API const char* r_config_node_type(RConfigNode *node) { return ""; } -R_API RConfigNode* r_config_set_cb(RConfig *cfg, const char *name, const char *value, RConfigCallback cb) { - RConfigNode *node = r_config_set (cfg, name, value); +RZ_API RConfigNode* rz_config_set_cb(RConfig *cfg, const char *name, const char *value, RConfigCallback cb) { + RConfigNode *node = rz_config_set (cfg, name, value); if (node && (node->setter = cb)) { if (!cb (cfg->user, node)) { return NULL; @@ -362,8 +362,8 @@ R_API RConfigNode* r_config_set_cb(RConfig *cfg, const char *name, const char *v return node; } -R_API RConfigNode* r_config_set_i_cb(RConfig *cfg, const char *name, int ivalue, RConfigCallback cb) { - RConfigNode *node = r_config_set_i (cfg, name, ivalue); +RZ_API RConfigNode* rz_config_set_i_cb(RConfig *cfg, const char *name, int ivalue, RConfigCallback cb) { + RConfigNode *node = rz_config_set_i (cfg, name, ivalue); if (node && (node->setter = cb)) { if (!node->setter (cfg->user, node)) { return NULL; @@ -373,21 +373,21 @@ R_API RConfigNode* r_config_set_i_cb(RConfig *cfg, const char *name, int ivalue, } static bool __is_true_or_false(const char *s) { - return s && (!r_str_casecmp (s, "true") || !r_str_casecmp (s, "false")); + return s && (!rz_str_casecmp (s, "true") || !rz_str_casecmp (s, "false")); } /* TODO: reduce number of strdups here */ -R_API RConfigNode* r_config_set(RConfig *cfg, const char *name, const char *value) { +RZ_API RConfigNode* rz_config_set(RConfig *cfg, const char *name, const char *value) { RConfigNode *node = NULL; char *ov = NULL; ut64 oi; - r_return_val_if_fail (cfg && cfg->ht, NULL); - r_return_val_if_fail (!IS_NULLSTR (name), NULL); + rz_return_val_if_fail (cfg && cfg->ht, NULL); + rz_return_val_if_fail (!IS_NULLSTR (name), NULL); - node = r_config_node_get (cfg, name); + node = rz_config_node_get (cfg, name); if (node) { - if (r_config_node_is_ro (node)) { + if (rz_config_node_is_ro (node)) { eprintf ("(error: '%s' config key is read only)\n", name); return node; } @@ -401,10 +401,10 @@ R_API RConfigNode* r_config_set(RConfig *cfg, const char *name, const char *valu free (node->value); node->value = strdup (""); } - if (r_config_node_is_bool (node)) { - bool b = r_str_is_true (value); + if (rz_config_node_is_bool (node)) { + bool b = rz_str_is_true (value); node->i_value = b? 1: 0; - char *value = strdup (r_str_bool (b)); + char *value = strdup (rz_str_bool (b)); if (value) { free (node->value); node->value = value; @@ -422,9 +422,9 @@ R_API RConfigNode* r_config_set(RConfig *cfg, const char *name, const char *valu node->value = strdup (value); if (IS_DIGIT (*value) || (value[0] == '-' && IS_DIGIT (value[1]))) { if (strchr (value, '/')) { - node->i_value = r_num_get (cfg->num, value); + node->i_value = rz_num_get (cfg->num, value); } else { - node->i_value = r_num_math (cfg->num, value); + node->i_value = rz_num_math (cfg->num, value); } } else { node->i_value = 0; @@ -435,19 +435,19 @@ R_API RConfigNode* r_config_set(RConfig *cfg, const char *name, const char *valu } else { // Create a new RConfigNode oi = UT64_MAX; if (!cfg->lock) { - node = r_config_node_new (name, value); + node = rz_config_node_new (name, value); if (node) { if (__is_true_or_false (value)) { node->flags |= CN_BOOL; - node->i_value = r_str_is_true (value)? 1: 0; + node->i_value = rz_str_is_true (value)? 1: 0; } ht_pp_insert (cfg->ht, node->name, node); - r_list_append (cfg->nodes, node); + rz_list_append (cfg->nodes, node); } else { - eprintf ("r_config_set: unable to create a new RConfigNode\n"); + eprintf ("rz_config_set: unable to create a new RConfigNode\n"); } } else { - eprintf ("r_config_set: variable '%s' not found\n", name); + eprintf ("rz_config_set: variable '%s' not found\n", name); } } @@ -467,16 +467,16 @@ beach: return node; } -/* r_config_desc takes a RConfig and a name, - * r_config_node_desc takes a RConfigNode +/* rz_config_desc takes a RConfig and a name, + * rz_config_node_desc takes a RConfigNode * Both set and return node->desc */ -R_API const char* r_config_desc(RConfig *cfg, const char *name, const char *desc) { - RConfigNode *node = r_config_node_get (cfg, name); - return r_config_node_desc (node, desc); +RZ_API const char* rz_config_desc(RConfig *cfg, const char *name, const char *desc) { + RConfigNode *node = rz_config_node_get (cfg, name); + return rz_config_node_desc (node, desc); } -R_API const char* r_config_node_desc(RConfigNode *node, const char *desc) { - r_return_val_if_fail (node, NULL); +RZ_API const char* rz_config_node_desc(RConfigNode *node, const char *desc) { + rz_return_val_if_fail (node, NULL); if (desc) { free (node->desc); node->desc = strdup (desc); @@ -484,19 +484,19 @@ R_API const char* r_config_node_desc(RConfigNode *node, const char *desc) { return node->desc; } -R_API bool r_config_rm(RConfig *cfg, const char *name) { - RConfigNode *node = r_config_node_get (cfg, name); +RZ_API bool rz_config_rm(RConfig *cfg, const char *name) { + RConfigNode *node = rz_config_node_get (cfg, name); if (node) { ht_pp_delete (cfg->ht, node->name); - r_list_delete_data (cfg->nodes, node); + rz_list_delete_data (cfg->nodes, node); return true; } return false; } -R_API void r_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i, R_NULLABLE RConfigNode *node) { - if (node && r_config_node_is_bool (node)) { - r_str_ncpy (buf, r_str_bool ((int) i), buf_size); +RZ_API void rz_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i, R_NULLABLE RConfigNode *node) { + if (node && rz_config_node_is_bool (node)) { + rz_str_ncpy (buf, rz_str_bool ((int) i), buf_size); return; } if (i < 1024) { @@ -506,17 +506,17 @@ R_API void r_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i } } -R_API RConfigNode* r_config_set_i(RConfig *cfg, const char *name, const ut64 i) { +RZ_API RConfigNode* rz_config_set_i(RConfig *cfg, const char *name, const ut64 i) { char buf[128], *ov = NULL; - r_return_val_if_fail (cfg && name, NULL); - RConfigNode *node = r_config_node_get (cfg, name); + rz_return_val_if_fail (cfg && name, NULL); + RConfigNode *node = rz_config_node_get (cfg, name); if (node) { - if (r_config_node_is_ro (node)) { + if (rz_config_node_is_ro (node)) { node = NULL; goto beach; } ov = node->value; - r_config_node_value_format_i (buf, sizeof (buf), i, NULL); + rz_config_node_value_format_i (buf, sizeof (buf), i, NULL); node->value = strdup (buf); if (!node->value) { node = NULL; @@ -525,8 +525,8 @@ R_API RConfigNode* r_config_set_i(RConfig *cfg, const char *name, const ut64 i) node->i_value = i; } else { if (!cfg->lock) { - r_config_node_value_format_i (buf, sizeof (buf), i, NULL); - node = r_config_node_new (name, buf); + rz_config_node_value_format_i (buf, sizeof (buf), i, NULL); + node = rz_config_node_new (name, buf); if (!node) { node = NULL; goto beach; @@ -535,7 +535,7 @@ R_API RConfigNode* r_config_set_i(RConfig *cfg, const char *name, const ut64 i) node->i_value = i; ht_pp_insert (cfg->ht, node->name, node); if (cfg->nodes) { - r_list_append (cfg->nodes, node); + rz_list_append (cfg->nodes, node); } } else { eprintf ("(locked: no new keys can be created (%s))\n", name); @@ -564,16 +564,16 @@ static void __evalString(RConfig *cfg, char *name) { char *eq = strchr (name, '='); if (eq) { *eq++ = 0; - r_str_trim (name); - r_str_trim (eq); + rz_str_trim (name); + rz_str_trim (eq); if (*name) { - (void) r_config_set (cfg, name, eq); + (void) rz_config_set (cfg, name, eq); } } else { - if (r_str_endswith (name, ".")) { - r_config_list (cfg, name, 0); + if (rz_str_endswith (name, ".")) { + rz_config_list (cfg, name, 0); } else { - const char *v = r_config_get (cfg, name); + const char *v = rz_config_get (cfg, name); if (v) { cfg->cb_printf ("%s\n", v); } else { @@ -583,29 +583,29 @@ static void __evalString(RConfig *cfg, char *name) { } } -R_API bool r_config_eval(RConfig *cfg, const char *str, bool many) { - r_return_val_if_fail (cfg && str, false); +RZ_API bool rz_config_eval(RConfig *cfg, const char *str, bool many) { + rz_return_val_if_fail (cfg && str, false); - char *s = r_str_trim_dup (str); + char *s = rz_str_trim_dup (str); if (!*s || !strcmp (s, "help")) { - r_config_list (cfg, NULL, 0); + rz_config_list (cfg, NULL, 0); free (s); return false; } if (*s == '-') { - r_config_rm (cfg, s + 1); + rz_config_rm (cfg, s + 1); free (s); return false; } if (many) { // space separated list of k=v k=v,.. // if you want to use spaces go for base64 or e. - RList *list = r_str_split_list (s, ",", 0); - RListIter *iter; + RzList *list = rz_str_split_list (s, ",", 0); + RzListIter *iter; char *name; - r_list_foreach (list, iter, name) { + rz_list_foreach (list, iter, name) { __evalString (cfg, name); } free (s); @@ -620,13 +620,13 @@ static int cmp(RConfigNode *a, RConfigNode *b) { return strcmp (a->name, b->name); } -R_API void r_config_lock(RConfig *cfg, int l) { - r_list_sort (cfg->nodes, (RListComparator) cmp); +RZ_API void rz_config_lock(RConfig *cfg, int l) { + rz_list_sort (cfg->nodes, (RzListComparator) cmp); cfg->lock = l; } -R_API bool r_config_readonly(RConfig *cfg, const char *key) { - RConfigNode *n = r_config_node_get (cfg, key); +RZ_API bool rz_config_readonly(RConfig *cfg, const char *key) { + RConfigNode *n = rz_config_node_get (cfg, key); if (n) { n->flags |= CN_RO; return true; @@ -634,13 +634,13 @@ R_API bool r_config_readonly(RConfig *cfg, const char *key) { return false; } -R_API RConfig* r_config_new(void *user) { +RZ_API RConfig* rz_config_new(void *user) { RConfig *cfg = R_NEW0 (RConfig); if (!cfg) { return NULL; } cfg->ht = ht_pp_new0 (); - cfg->nodes = r_list_newf ((RListFree)r_config_node_free); + cfg->nodes = rz_list_newf ((RzListFree)rz_config_node_free); if (!cfg->nodes) { R_FREE (cfg); return NULL; @@ -652,65 +652,65 @@ R_API RConfig* r_config_new(void *user) { return cfg; } -R_API RConfig* r_config_clone(RConfig *cfg) { - RListIter *iter; +RZ_API RConfig* rz_config_clone(RConfig *cfg) { + RzListIter *iter; RConfigNode *node; - RConfig *c = r_config_new (cfg->user); + RConfig *c = rz_config_new (cfg->user); if (!c) { return NULL; } - r_list_foreach (cfg->nodes, iter, node) { - RConfigNode *nn = r_config_node_clone (node); + rz_list_foreach (cfg->nodes, iter, node) { + RConfigNode *nn = rz_config_node_clone (node); ht_pp_insert (c->ht, node->name, nn); - r_list_append (c->nodes, nn); + rz_list_append (c->nodes, nn); } c->lock = cfg->lock; c->cb_printf = cfg->cb_printf; return c; } -R_API void r_config_free(RConfig *cfg) { +RZ_API void rz_config_free(RConfig *cfg) { if (cfg) { - cfg->nodes->free = r_config_node_free; // damn - r_list_free (cfg->nodes); + cfg->nodes->free = rz_config_node_free; // damn + rz_list_free (cfg->nodes); ht_pp_free (cfg->ht); free (cfg); } } -R_API void r_config_visual_hit_i(RConfig *cfg, const char *name, int delta) { - RConfigNode *node = r_config_node_get (cfg, name); - if (node && r_config_node_is_int (node)) { - (void)r_config_set_i (cfg, name, r_config_get_i (cfg, name) + delta); +RZ_API void rz_config_visual_hit_i(RConfig *cfg, const char *name, int delta) { + RConfigNode *node = rz_config_node_get (cfg, name); + if (node && rz_config_node_is_int (node)) { + (void)rz_config_set_i (cfg, name, rz_config_get_i (cfg, name) + delta); } } -R_API void r_config_bump(RConfig *cfg, const char *key) { - char *orig = strdup (r_config_get (cfg, key)); +RZ_API void rz_config_bump(RConfig *cfg, const char *key) { + char *orig = strdup (rz_config_get (cfg, key)); if (orig) { - r_config_set (cfg, key, orig); + rz_config_set (cfg, key, orig); free (orig); } } -R_API void r_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db) { - RListIter *iter; +RZ_API void rz_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db) { + RzListIter *iter; RConfigNode *node; - r_list_foreach (config->nodes, iter, node) { + rz_list_foreach (config->nodes, iter, node) { sdb_set (db, node->name, node->value, 0); } } static bool load_config_cb(void *user, const char *k, const char *v) { RConfig *config = user; - RConfigNode *node = r_config_node_get (config, k); + RConfigNode *node = rz_config_node_get (config, k); if (node) { - r_config_set (config, k, v); + rz_config_set (config, k, v); } return true; } -R_API bool r_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err) { +RZ_API bool rz_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err) { sdb_foreach (db, load_config_cb, config); return true; } diff --git a/libr/config/hold.c b/librz/config/hold.c similarity index 57% rename from libr/config/hold.c rename to librz/config/hold.c index c9b340b012..52c614d9c9 100644 --- a/libr/config/hold.c +++ b/librz/config/hold.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2006-2019 - pancake */ -#include +#include -static void r_config_hold_char_free(RConfigHoldChar *hc) { +static void rz_config_hold_char_free(RConfigHoldChar *hc) { free (hc->key); free (hc->value); free (hc); } -static void r_config_hold_num_free(RConfigHoldNum *hc) { +static void rz_config_hold_num_free(RConfigHoldNum *hc) { free (hc->key); free (hc); } @@ -25,22 +25,22 @@ static int key_cmp_hold_i(const void *a, const void *b) { return strcmp (a_s, b_s->key); } -R_API bool r_config_hold_s(RConfigHold *h, ...) { +RZ_API bool rz_config_hold_s(RConfigHold *h, ...) { va_list ap; char *key; va_start (ap, h); if (!h->list_char) { - h->list_char = r_list_newf ((RListFree)r_config_hold_char_free); + h->list_char = rz_list_newf ((RzListFree)rz_config_hold_char_free); if (!h->list_char) { va_end (ap); return false; } } while ((key = va_arg (ap, char *))) { - if (r_list_find (h->list_char, key, key_cmp_hold_s)) { + if (rz_list_find (h->list_char, key, key_cmp_hold_s)) { continue; } - const char *val = r_config_get (h->cfg, key); + const char *val = rz_config_get (h->cfg, key); if (!val) { continue; } @@ -48,28 +48,28 @@ R_API bool r_config_hold_s(RConfigHold *h, ...) { if (hc) { hc->key = strdup (key); hc->value = strdup (val); - r_list_append (h->list_char, hc); + rz_list_append (h->list_char, hc); } } va_end (ap); return true; } -R_API bool r_config_hold_i(RConfigHold *h, ...) { +RZ_API bool rz_config_hold_i(RConfigHold *h, ...) { va_list ap; char *key; if (!h) { return false; } if (!h->list_num) { - h->list_num = r_list_newf ((RListFree)r_config_hold_num_free); + h->list_num = rz_list_newf ((RzListFree)rz_config_hold_num_free); if (!h->list_num) { return false; } } va_start (ap, h); while ((key = va_arg (ap, char *))) { - if (r_list_find (h->list_num, key, key_cmp_hold_i)) { + if (rz_list_find (h->list_num, key, key_cmp_hold_i)) { continue; } RConfigHoldNum *hc = R_NEW0 (RConfigHoldNum); @@ -77,14 +77,14 @@ R_API bool r_config_hold_i(RConfigHold *h, ...) { continue; } hc->key = strdup (key); - hc->value = r_config_get_i (h->cfg, key); - r_list_append (h->list_num, hc); + hc->value = rz_config_get_i (h->cfg, key); + rz_list_append (h->list_num, hc); } va_end (ap); return true; } -R_API RConfigHold* r_config_hold_new(RConfig *cfg) { +RZ_API RConfigHold* rz_config_hold_new(RConfig *cfg) { if (cfg) { RConfigHold *hold = R_NEW0 (RConfigHold); if (hold) { @@ -95,25 +95,25 @@ R_API RConfigHold* r_config_hold_new(RConfig *cfg) { return NULL; } -R_API void r_config_hold_restore(RConfigHold *h) { - RListIter *iter; +RZ_API void rz_config_hold_restore(RConfigHold *h) { + RzListIter *iter; RConfigHoldChar *hchar; RConfigHoldNum *hnum; if (h) { RConfig *cfg = h->cfg; - r_list_foreach (h->list_num, iter, hnum) { - (void)r_config_set_i (cfg, hnum->key, hnum->value); + rz_list_foreach (h->list_num, iter, hnum) { + (void)rz_config_set_i (cfg, hnum->key, hnum->value); } - r_list_foreach (h->list_char, iter, hchar) { - (void)r_config_set (cfg, hchar->key, hchar->value); + rz_list_foreach (h->list_char, iter, hchar) { + (void)rz_config_set (cfg, hchar->key, hchar->value); } } } -R_API void r_config_hold_free(RConfigHold *h) { +RZ_API void rz_config_hold_free(RConfigHold *h) { if (h) { - r_list_free (h->list_num); - r_list_free (h->list_char); + rz_list_free (h->list_num); + rz_list_free (h->list_char); R_FREE (h); } } diff --git a/libr/config/meson.build b/librz/config/meson.build similarity index 61% rename from libr/config/meson.build rename to librz/config/meson.build index 2072f81631..b80b38d6c5 100644 --- a/libr/config/meson.build +++ b/librz/config/meson.build @@ -1,13 +1,13 @@ -r_config_sources = [ +rz_config_sources = [ 'callback.c', 'config.c', 'hold.c', ] -r_config = library('r_config', r_config_sources, +rz_config = library('rz_config', rz_config_sources, include_directories: [platform_inc], dependencies: [ - r_util_dep + rz_util_dep ], install: true, implicit_include_directories: false, @@ -15,17 +15,17 @@ r_config = library('r_config', r_config_sources, soversion: r2_libversion ) -r_config_dep = declare_dependency(link_with: r_config, +rz_config_dep = declare_dependency(link_with: rz_config, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_config, - subdirs: 'libr', +pkgconfig_mod.generate(rz_config, + subdirs: 'librz', version: r2_version, - name: 'r_config', - filebase: 'r_config', + name: 'rz_config', + filebase: 'rz_config', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/cons/2048.c b/librz/cons/2048.c similarity index 83% rename from libr/cons/2048.c rename to librz/cons/2048.c index 591f04779d..12d8126292 100644 --- a/libr/cons/2048.c +++ b/librz/cons/2048.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2008-2020 - pancake */ +/* rizin - LGPL - Copyright 2008-2020 - pancake */ -#include +#include static ut8 twok_buf[4][4]; static int score = 0; @@ -19,10 +19,10 @@ static void twok_init(void) { static void twok_add(void) { int i, j; while (true) { - i = r_num_rand (4); - j = r_num_rand (4); + i = rz_num_rand (4); + j = rz_num_rand (4); if (!twok_buf[i][j]) { - twok_buf[i][j] = 1 + (r_num_rand (10) == 1); + twok_buf[i][j] = 1 + (rz_num_rand (10) == 1); break; } } @@ -147,23 +147,23 @@ static void twok_print(bool color) { } } -R_API void r_cons_2048(bool color) { +RZ_API void rz_cons_2048(bool color) { int ch; - r_cons_set_raw (1); + rz_cons_set_raw (1); twok_init (); twok_add (); twok_add (); while (twok_fin ()) { - r_cons_clear00 (); + rz_cons_clear00 (); if (color) { - r_cons_printf (Color_GREEN"[r2048]"Color_BYELLOW" score: %d moves: %d\n"Color_RESET, score, moves); + rz_cons_printf (Color_GREEN"[r2048]"Color_BYELLOW" score: %d moves: %d\n"Color_RESET, score, moves); } else { - r_cons_printf ("[r2048] score: %d moves: %d\n", score, moves); + rz_cons_printf ("[r2048] score: %d moves: %d\n", score, moves); } - r_cons_flush (); + rz_cons_flush (); twok_print (color); - ch = r_cons_readchar (); - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_readchar (); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { case 'h': twok_move (1, 1); @@ -182,14 +182,14 @@ R_API void r_cons_2048(bool color) { break; } } - r_cons_clear00 (); - r_cons_printf ("[r2048] score: %d\n", score); - r_cons_flush (); + rz_cons_clear00 (); + rz_cons_printf ("[r2048] score: %d\n", score); + rz_cons_flush (); twok_print (color); - r_cons_printf ("\n [r2048.score] %d\n", score); + rz_cons_printf ("\n [r2048.score] %d\n", score); do { - ch = r_cons_any_key ("Press 'q' to quit."); + ch = rz_cons_any_key ("Press 'q' to quit."); } while (ch != 'q' && ch >= 1); - r_cons_set_raw (0); + rz_cons_set_raw (0); } diff --git a/libr/cons/Makefile b/librz/cons/Makefile similarity index 89% rename from libr/cons/Makefile rename to librz/cons/Makefile index 7346b12d91..e46881a010 100644 --- a/libr/cons/Makefile +++ b/librz/cons/Makefile @@ -1,10 +1,10 @@ include ../config.mk -NAME=r_cons +NAME=rz_cons OBJS=cons.o cpipe.o output.o grep.o less.o more.o pager.o cutf8.o OBJS+=line.o hud.o rgb.o input.o pal.o editor.o 2048.o html.o OBJS+=canvas.o canvas_line.o stiv.o -R2DEPS=r_util +R2DEPS=rz_util include ../rules.mk diff --git a/libr/cons/README b/librz/cons/README similarity index 100% rename from libr/cons/README rename to librz/cons/README diff --git a/libr/cons/canvas.c b/librz/cons/canvas.c similarity index 78% rename from libr/cons/canvas.c rename to librz/cons/canvas.c index 817706f5bd..1065ce5835 100644 --- a/libr/cons/canvas.c +++ b/librz/cons/canvas.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2013-2020 - pancake */ -#include -#include +#include +#include -#define useUtf8 (r_cons_singleton ()->use_utf8) -#define useUtf8Curvy (r_cons_singleton ()->use_utf8_curvy) +#define useUtf8 (rz_cons_singleton ()->use_utf8) +#define useUtf8Curvy (rz_cons_singleton ()->use_utf8_curvy) -#define W(y) r_cons_canvas_write (c, y) -#define G(x, y) r_cons_canvas_gotoxy (c, x, y) +#define W(y) rz_cons_canvas_write (c, y) +#define G(x, y) rz_cons_canvas_gotoxy (c, x, y) static inline bool __isAnsiSequence(const char *s) { return s && s[0] == 033 && s[1] == '['; @@ -31,14 +31,14 @@ static void attribute_free_kv(HtUPKv *kv) { free (kv->value); } -static const char *__attributeAt(RConsCanvas *c, int loc) { +static const char *__attributeAt(RzConsCanvas *c, int loc) { if (!c->color) { return NULL; } return ht_up_find (c->attrs, loc, NULL); } -static void __stampAttribute(RConsCanvas *c, int loc, int length) { +static void __stampAttribute(RzConsCanvas *c, int loc, int length) { if (!c->color) { return; } @@ -50,7 +50,7 @@ static void __stampAttribute(RConsCanvas *c, int loc, int length) { } /* check for ANSI sequences and use them as attr */ -static const char *set_attr(RConsCanvas *c, const char *s) { +static const char *set_attr(RzConsCanvas *c, const char *s) { if (!c || !s) { return NULL; } @@ -67,10 +67,10 @@ static const char *set_attr(RConsCanvas *c, const char *s) { const int slen = p - s; if (slen > 0) { RStrBuf tmp; - r_strbuf_init (&tmp); - r_strbuf_append_n (&tmp, s, slen); - c->attr = r_str_constpool_get (&c->constpool, r_strbuf_get (&tmp)); - r_strbuf_fini (&tmp); + rz_strbuf_init (&tmp); + rz_strbuf_append_n (&tmp, s, slen); + c->attr = rz_str_constpool_get (&c->constpool, rz_strbuf_get (&tmp)); + rz_strbuf_fini (&tmp); } return p; } @@ -80,7 +80,7 @@ static int __getUtf8Length(const char *s, int n) { while (s[i] && n > 0) { if ((s[i] & 0xc0) != 0x80) { j++; - if (r_str_char_fullwidth (s + i, n)) { + if (rz_str_char_fullwidth (s + i, n)) { fullwidths++; } } @@ -93,7 +93,7 @@ static int __getUtf8Length(const char *s, int n) { static int __getUtf8Length2(const char *s, int n, int left) { int i = 0, fullwidths = 0; while (n > -1 && i < left && s[i]) { - if (r_str_char_fullwidth (s + i, left - i)) { + if (rz_str_char_fullwidth (s + i, left - i)) { fullwidths++; } if ((s[i] & 0xc0) != 0x80) { @@ -105,7 +105,7 @@ static int __getUtf8Length2(const char *s, int n, int left) { return n == -1 ? i - 1 : i; } -static bool __expandLine(RConsCanvas *c, int real_len, int utf8_len) { +static bool __expandLine(RzConsCanvas *c, int real_len, int utf8_len) { if (real_len == 0) { return true; } @@ -145,7 +145,7 @@ static bool __expandLine(RConsCanvas *c, int real_len, int utf8_len) { return true; } -R_API void r_cons_canvas_free(RConsCanvas *c) { +RZ_API void rz_cons_canvas_free(RzConsCanvas *c) { if (!c) { return; } @@ -159,7 +159,7 @@ R_API void r_cons_canvas_free(RConsCanvas *c) { free (c->bsize); free (c->blen); ht_up_free (c->attrs); - r_str_constpool_fini (&c->constpool); + rz_str_constpool_fini (&c->constpool); free (c); } @@ -169,8 +169,8 @@ static bool attribute_delete_cb(void *user, const ut64 key, const void *value) { return true; } -R_API void r_cons_canvas_clear(RConsCanvas *c) { - r_return_if_fail (c && c->b); +RZ_API void rz_cons_canvas_clear(RzConsCanvas *c) { + rz_return_if_fail (c && c->b); int y; for (y = 0; y < c->h; y++) { memset (c->b[y], '\n', c->bsize[y]); @@ -179,7 +179,7 @@ R_API void r_cons_canvas_clear(RConsCanvas *c) { ht_up_foreach (c->attrs, attribute_delete_cb, c->attrs); } -R_API bool r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y) { +RZ_API bool rz_cons_canvas_gotoxy(RzConsCanvas *c, int x, int y) { bool ret = true; if (!c) { return 0; @@ -218,11 +218,11 @@ R_API bool r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y) { return ret; } -R_API RConsCanvas *r_cons_canvas_new(int w, int h) { +RZ_API RzConsCanvas *rz_cons_canvas_new(int w, int h) { if (w < 1 || h < 1) { return NULL; } - RConsCanvas *c = R_NEW0 (RConsCanvas); + RzConsCanvas *c = R_NEW0 (RzConsCanvas); if (!c) { return NULL; } @@ -255,7 +255,7 @@ R_API RConsCanvas *r_cons_canvas_new(int w, int h) { c->w = w; c->h = h; c->x = c->y = 0; - if (!r_str_constpool_init (&c->constpool)) { + if (!rz_str_constpool_init (&c->constpool)) { goto beach; } c->attrs = ht_up_new ((HtUPDupValue)strdup, attribute_free_kv, NULL); @@ -263,10 +263,10 @@ R_API RConsCanvas *r_cons_canvas_new(int w, int h) { goto beach; } c->attr = Color_RESET; - r_cons_canvas_clear (c); + rz_cons_canvas_clear (c); return c; beach: - r_str_constpool_fini (&c->constpool); + rz_str_constpool_fini (&c->constpool); int j; for (j = 0; j < i; j++) { free (c->b[j]); @@ -278,7 +278,7 @@ beach: return NULL; } -R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) { +RZ_API void rz_cons_canvas_write(RzConsCanvas *c, const char *s) { if (!c || !s || !*s || !R_BETWEEN (0, c->y, c->h - 1) || !R_BETWEEN (0, c->x, c->w - 1)) { return; } @@ -291,7 +291,7 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) { /* split the string into pieces of non-ANSI chars and print them normally, ** using the ANSI chars to set the attr of the canvas */ - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { const char *s_part = set_attr (c, s); ch = 0; @@ -309,7 +309,7 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) { } } - int real_len = r_str_nlen (s_part, slen); + int real_len = rz_str_nlen (s_part, slen); int utf8_len = __getUtf8Length (s_part, slen); if (!__expandLine (c, real_len, utf8_len)) { @@ -341,13 +341,13 @@ R_API void r_cons_canvas_write(RConsCanvas *c, const char *s) { attr_x += utf8_len; } s += piece_len; - } while (*s && !r_cons_is_breaked ()); - r_cons_break_pop (); + } while (*s && !rz_cons_is_breaked ()); + rz_cons_break_pop (); c->x = orig_x; } -R_API char *r_cons_canvas_to_string(RConsCanvas *c) { - r_return_val_if_fail (c, NULL); +RZ_API char *rz_cons_canvas_to_string(RzConsCanvas *c) { + rz_return_val_if_fail (c, NULL); int x, y, olen = 0, attr_x = 0; bool is_first = true; @@ -380,7 +380,7 @@ R_API char *r_cons_canvas_to_string(RConsCanvas *c) { olen += len; } attr_x++; - if (r_str_char_fullwidth (c->b[y] + x, c->blen[y] - x)) { + if (rz_str_char_fullwidth (c->b[y] + x, c->blen[y] - x)) { attr_x++; } } @@ -388,7 +388,7 @@ R_API char *r_cons_canvas_to_string(RConsCanvas *c) { o[olen++] = ' '; continue; } - const char *rune = r_cons_get_rune ((const ut8)c->b[y][x]); + const char *rune = rz_cons_get_rune ((const ut8)c->b[y][x]); if (rune) { size_t rune_len = strlen (rune); memcpy (o + olen, rune, rune_len + 1); @@ -405,44 +405,44 @@ R_API char *r_cons_canvas_to_string(RConsCanvas *c) { return o; } -R_API void r_cons_canvas_print_region(RConsCanvas *c) { - char *o = r_cons_canvas_to_string (c); +RZ_API void rz_cons_canvas_print_region(RzConsCanvas *c) { + char *o = rz_cons_canvas_to_string (c); if (o) { - r_str_trim_tail (o); + rz_str_trim_tail (o); if (*o) { - r_cons_strcat (o); + rz_cons_strcat (o); } free (o); } } -R_API void r_cons_canvas_print(RConsCanvas *c) { - char *o = r_cons_canvas_to_string (c); +RZ_API void rz_cons_canvas_print(RzConsCanvas *c) { + char *o = rz_cons_canvas_to_string (c); if (o) { - r_cons_strcat (o); + rz_cons_strcat (o); free (o); } } -R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) { +RZ_API int rz_cons_canvas_resize(RzConsCanvas *c, int w, int h) { if (!c || w < 0 || h <= 0) { return false; } int *newblen = realloc (c->blen, sizeof *c->blen * h); if (!newblen) { - r_cons_canvas_free (c); + rz_cons_canvas_free (c); return false; } c->blen = newblen; int *newbsize = realloc (c->bsize, sizeof *c->bsize * h); if (!newbsize) { - r_cons_canvas_free (c); + rz_cons_canvas_free (c); return false; } c->bsize = newbsize; char **newb = realloc (c->b, sizeof *c->b * h); if (!newb) { - r_cons_canvas_free (c); + rz_cons_canvas_free (c); return false; } c->b = newb; @@ -474,13 +474,13 @@ R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h) { c->h = h; c->x = 0; c->y = 0; - r_cons_canvas_clear (c); + rz_cons_canvas_clear (c); return true; } #include #define PI 3.1415 -R_API void r_cons_canvas_circle(RConsCanvas *c, int x, int y, int w, int h, const char *color) { +RZ_API void rz_cons_canvas_circle(RzConsCanvas *c, int x, int y, int w, int h, const char *color) { if (color) { c->attr = color; } @@ -490,8 +490,8 @@ R_API void r_cons_canvas_circle(RConsCanvas *c, int x, int y, int w, int h, cons float a = 0.0; double s = size / 2; while (a < (2 * PI)) { - double sa = r_num_sin (a); - double ca = r_num_cos (a); + double sa = rz_num_sin (a); + double ca = rz_num_cos (a); double cx = s * ca + (size / 2); double cy = s * sa + (size / 4); int X = x + (xfactor * cx) - 2; @@ -506,11 +506,11 @@ R_API void r_cons_canvas_circle(RConsCanvas *c, int x, int y, int w, int h, cons } } -R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color) { +RZ_API void rz_cons_canvas_box(RzConsCanvas *c, int x, int y, int w, int h, const char *color) { const char *hline = useUtf8? RUNECODESTR_LINE_HORIZ : "-"; const char *vtmp = useUtf8? RUNECODESTR_LINE_VERT : "|"; - RStrBuf *vline = r_strbuf_new (NULL); - r_strbuf_appendf (vline, Color_RESET"%s%s", color, vtmp); + RStrBuf *vline = rz_strbuf_new (NULL); + rz_strbuf_appendf (vline, Color_RESET"%s%s", color, vtmp); const char *tl_corner = useUtf8 ? (useUtf8Curvy ? RUNECODESTR_CURVE_CORNER_TL : RUNECODESTR_CORNER_TL) : "."; const char *tr_corner = useUtf8 ? (useUtf8Curvy ? RUNECODESTR_CURVE_CORNER_TR : RUNECODESTR_CORNER_TR) : "."; const char *bl_corner = useUtf8 ? (useUtf8Curvy ? RUNECODESTR_CURVE_CORNER_BL : RUNECODESTR_CORNER_BL) : "`"; @@ -557,20 +557,20 @@ R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const c } for (i = 1; i < h - 1; i++) { if (G (x, y + i)) { - W (r_strbuf_get (vline)); + W (rz_strbuf_get (vline)); } if (G (x + w - 1, y + i)) { - W (r_strbuf_get (vline)); + W (rz_strbuf_get (vline)); } } free (row); - r_strbuf_free (vline); + rz_strbuf_free (vline); if (color) { c->attr = Color_RESET; } } -R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char ch) { +RZ_API void rz_cons_canvas_fill(RzConsCanvas *c, int x, int y, int w, int h, char ch) { int i; if (w < 0) { return; @@ -589,10 +589,10 @@ R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char c free (row); } -R_API void r_cons_canvas_line(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { +RZ_API void rz_cons_canvas_line(RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { if (c->linemode) { - r_cons_canvas_line_square (c, x, y, x2, y2, style); + rz_cons_canvas_line_square (c, x, y, x2, y2, style); } else { - r_cons_canvas_line_diagonal (c, x, y, x2, y2, style); + rz_cons_canvas_line_diagonal (c, x, y, x2, y2, style); } } diff --git a/libr/cons/canvas_line.c b/librz/cons/canvas_line.c similarity index 80% rename from libr/cons/canvas_line.c rename to librz/cons/canvas_line.c index 230cac86a0..ad704894b3 100644 --- a/libr/cons/canvas_line.c +++ b/librz/cons/canvas_line.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include -#define W(y) r_cons_canvas_write(c,y) -#define G(x,y) r_cons_canvas_gotoxy(c,x,y) +#include +#define W(y) rz_cons_canvas_write(c,y) +#define G(x,y) rz_cons_canvas_gotoxy(c,x,y) -#define useUtf8 (r_cons_singleton ()->use_utf8) -#define useUtf8Curvy (r_cons_singleton ()->use_utf8_curvy) +#define useUtf8 (rz_cons_singleton ()->use_utf8) +#define useUtf8Curvy (rz_cons_singleton ()->use_utf8_curvy) #define DOTTED_LINE_HORIZ "┄" #define DOTTED_LINE_VERT "┊" @@ -26,7 +26,7 @@ enum { }; static char* utf8_line_vert (int dot_style) { - if (r_cons_singleton ()->dotted_lines) { + if (rz_cons_singleton ()->dotted_lines) { switch (dot_style) { case DOT_STYLE_NORMAL: return RUNECODESTR_LINE_VERT; case DOT_STYLE_CONDITIONAL: return DOTTED_LINE_VERT; @@ -37,7 +37,7 @@ static char* utf8_line_vert (int dot_style) { } static char* utf8_line_horiz (int dot_style) { - if (r_cons_singleton ()->dotted_lines) { + if (rz_cons_singleton ()->dotted_lines) { switch (dot_style) { case DOT_STYLE_NORMAL: return RUNECODESTR_LINE_HORIZ; case DOT_STYLE_CONDITIONAL: return DOTTED_LINE_HORIZ; @@ -47,9 +47,9 @@ static char* utf8_line_horiz (int dot_style) { return RUNECODESTR_LINE_HORIZ; } -static void apply_line_style(RConsCanvas *c, int x, int y, int x2, int y2, +static void apply_line_style(RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int isvert) { - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); switch (style->color) { case LINE_UNCJMP: c->attr = cons->context->pal.graph_trufae; @@ -104,8 +104,8 @@ static void apply_line_style(RConsCanvas *c, int x, int y, int x2, int y2, } } -static void draw_horizontal_line (RConsCanvas *c, int x, int y, int width, int style, int dot_style) { - const char *l_corner = "?", *r_corner = "?"; +static void draw_horizontal_line (RzConsCanvas *c, int x, int y, int width, int style, int dot_style) { + const char *l_corner = "?", *rz_corner = "?"; int i; if (width < 1) { @@ -124,81 +124,81 @@ static void draw_horizontal_line (RConsCanvas *c, int x, int y, int width, int s if (useUtf8) { if (useUtf8Curvy) { l_corner = RUNECODESTR_CURVE_CORNER_BL; - r_corner = RUNECODESTR_CURVE_CORNER_TR; + rz_corner = RUNECODESTR_CURVE_CORNER_TR; } else { l_corner = RUNECODESTR_CORNER_BL; - r_corner = RUNECODESTR_CORNER_TR; + rz_corner = RUNECODESTR_CORNER_TR; } } else { l_corner = "'"; - r_corner = "."; + rz_corner = "."; } break; case DOT_APEX: if (useUtf8) { if (useUtf8Curvy) { l_corner = RUNECODESTR_CURVE_CORNER_TL; - r_corner = RUNECODESTR_CURVE_CORNER_BR; + rz_corner = RUNECODESTR_CURVE_CORNER_BR; } else { l_corner = RUNECODESTR_CORNER_TL; - r_corner = RUNECODESTR_CORNER_BR; + rz_corner = RUNECODESTR_CORNER_BR; } } else { l_corner = "."; - r_corner = "'"; + rz_corner = "'"; } break; case REV_APEX_APEX: if (useUtf8) { if (useUtf8Curvy) { l_corner = RUNECODESTR_CURVE_CORNER_BL; - r_corner = RUNECODESTR_CURVE_CORNER_BR; + rz_corner = RUNECODESTR_CURVE_CORNER_BR; } else { l_corner = RUNECODESTR_CORNER_BL; - r_corner = RUNECODESTR_CORNER_BR; + rz_corner = RUNECODESTR_CORNER_BR; } } else { l_corner = "`"; - r_corner = "'"; + rz_corner = "'"; } break; case DOT_DOT: if (useUtf8) { if (useUtf8Curvy) { l_corner = RUNECODESTR_CURVE_CORNER_TL; - r_corner = RUNECODESTR_CURVE_CORNER_TR; + rz_corner = RUNECODESTR_CURVE_CORNER_TR; } else { l_corner = RUNECODESTR_CORNER_TL; - r_corner = RUNECODESTR_CORNER_TR; + rz_corner = RUNECODESTR_CORNER_TR; } } else { - l_corner = r_corner = "."; + l_corner = rz_corner = "."; } break; case NRM_DOT: if (useUtf8) { l_corner = utf8_line_horiz (dot_style); if (useUtf8Curvy) { - r_corner = RUNECODESTR_CURVE_CORNER_TR; + rz_corner = RUNECODESTR_CURVE_CORNER_TR; } else { - r_corner = RUNECODESTR_CORNER_TR; + rz_corner = RUNECODESTR_CORNER_TR; } } else { l_corner = "-"; - r_corner = "."; + rz_corner = "."; } break; case NRM_APEX: if (useUtf8) { l_corner = utf8_line_horiz (dot_style); if (useUtf8Curvy) { - r_corner = RUNECODESTR_CURVE_CORNER_BR; + rz_corner = RUNECODESTR_CURVE_CORNER_BR; } else { - r_corner = RUNECODESTR_CORNER_BR; + rz_corner = RUNECODESTR_CORNER_BR; } } else { l_corner = "-"; - r_corner = "'"; + rz_corner = "'"; } break; case DOT_NRM: @@ -208,10 +208,10 @@ static void draw_horizontal_line (RConsCanvas *c, int x, int y, int width, int s } else { l_corner = RUNECODESTR_CORNER_TL; } - r_corner = utf8_line_horiz (dot_style); + rz_corner = utf8_line_horiz (dot_style); } else { l_corner = "."; - r_corner = "-"; + rz_corner = "-"; } break; case REV_APEX_NRM: @@ -221,18 +221,18 @@ static void draw_horizontal_line (RConsCanvas *c, int x, int y, int width, int s } else { l_corner = RUNECODESTR_CORNER_BL; } - r_corner = utf8_line_horiz (dot_style); + rz_corner = utf8_line_horiz (dot_style); } else { l_corner = "`"; - r_corner = "-"; + rz_corner = "-"; } break; case NRM_NRM: default: if (useUtf8) { - l_corner = r_corner = utf8_line_horiz (dot_style); + l_corner = rz_corner = utf8_line_horiz (dot_style); } else { - l_corner = r_corner = "-"; + l_corner = rz_corner = "-"; } break; } @@ -242,23 +242,23 @@ static void draw_horizontal_line (RConsCanvas *c, int x, int y, int width, int s } const char *hline = useUtf8 ? utf8_line_horiz (dot_style) : "-"; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = x + 1; i < x + width - 1; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (G (i, y)) { W (hline); } } - r_cons_break_pop (); + rz_cons_break_pop (); if (G (x + width - 1, y)) { - W (r_corner); + W (rz_corner); } } -static void draw_vertical_line (RConsCanvas *c, int x, int y, int height, int dot_style) { +static void draw_vertical_line (RzConsCanvas *c, int x, int y, int height, int dot_style) { int i; /* do not render offscreen vertical lines */ if (x + c->sx < 0) { @@ -268,22 +268,22 @@ static void draw_vertical_line (RConsCanvas *c, int x, int y, int height, int do return; } const char *vline = useUtf8 ? utf8_line_vert (dot_style) : "|"; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = y; i < y + height; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (G (x, i)) { W (vline); } } - r_cons_break_pop (); + rz_cons_break_pop (); } -R_API void r_cons_canvas_line_diagonal (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { +RZ_API void rz_cons_canvas_line_diagonal (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { if (x == x2 || y == y2) { style->dot_style = DOT_STYLE_NORMAL; - r_cons_canvas_line_square (c, x, y +1, x2, y2, style); + rz_cons_canvas_line_square (c, x, y +1, x2, y2, style); return; } apply_line_style (c, x, y, x2, y2, style, 1); @@ -366,7 +366,7 @@ loop: c->attr = Color_RESET; } -R_API void r_cons_canvas_line_square (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { +RZ_API void rz_cons_canvas_line_square (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style) { int min_x = R_MIN (x, x2); int diff_x = R_ABS (x - x2); int diff_y = R_ABS (y - y2); @@ -396,9 +396,9 @@ R_API void r_cons_canvas_line_square (RConsCanvas *c, int x, int y, int x2, int c->attr = Color_RESET; } -R_API void r_cons_canvas_line_square_defined (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int bendpoint, int isvert) { +RZ_API void rz_cons_canvas_line_square_defined (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int bendpoint, int isvert) { if (!c->linemode) { - r_cons_canvas_line (c, x, y, x2, y2, style); + rz_cons_canvas_line (c, x, y, x2, y2, style); return; } int min_x = R_MIN (x, x2); @@ -449,9 +449,9 @@ R_API void r_cons_canvas_line_square_defined (RConsCanvas *c, int x, int y, int c->attr = Color_RESET; } -R_API void r_cons_canvas_line_back_edge (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int ybendpoint1, int xbendpoint, int ybendpoint2, int isvert) { +RZ_API void rz_cons_canvas_line_back_edge (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int ybendpoint1, int xbendpoint, int ybendpoint2, int isvert) { if (!c->linemode) { - r_cons_canvas_line (c, x, y, x2, y2, style); + rz_cons_canvas_line (c, x, y, x2, y2, style); return; } int min_x1 = R_MIN (x, xbendpoint); diff --git a/libr/cons/cons.c b/librz/cons/cons.c similarity index 71% rename from libr/cons/cons.c rename to librz/cons/cons.c index 2b44d27863..4a27510bc4 100644 --- a/libr/cons/cons.c +++ b/librz/cons/cons.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2008-2020 - pancake, Jody Frankowski */ +/* rizin - LGPL - Copyright 2008-2020 - pancake, Jody Frankowski */ -#include -#include -#include +#include +#include +#include #include #include #include @@ -12,35 +12,35 @@ #define COUNT_LINES 1 #define CTX(x) I.context->x -R_LIB_VERSION (r_cons); +R_LIB_VERSION (rz_cons); -static RConsContext r_cons_context_default = {{{{0}}}}; -static RCons r_cons_instance = {0}; -#define I r_cons_instance +static RzConsContext rz_cons_context_default = {{{{0}}}}; +static RzCons rz_cons_instance = {0}; +#define I rz_cons_instance -//this structure goes into cons_stack when r_cons_push/pop +//this structure goes into cons_stack when rz_cons_push/pop typedef struct { char *buf; int buf_len; int buf_size; - RConsGrep *grep; -} RConsStack; + RzConsGrep *grep; +} RzConsStack; typedef struct { bool breaked; - RConsEvent event_interrupt; + RzConsEvent event_interrupt; void *event_interrupt_data; -} RConsBreakStack; +} RzConsBreakStack; -static void cons_grep_reset(RConsGrep *grep); +static void cons_grep_reset(RzConsGrep *grep); static void break_stack_free(void *ptr) { - RConsBreakStack *b = (RConsBreakStack*)ptr; + RzConsBreakStack *b = (RzConsBreakStack*)ptr; free (b); } static void cons_stack_free(void *ptr) { - RConsStack *s = (RConsStack *)ptr; + RzConsStack *s = (RzConsStack *)ptr; free (s->buf); if (s->grep) { R_FREE (s->grep->str); @@ -50,17 +50,17 @@ static void cons_stack_free(void *ptr) { free (s); } -static RConsStack *cons_stack_dump(bool recreate) { - RConsStack *data = R_NEW0 (RConsStack); +static RzConsStack *cons_stack_dump(bool recreate) { + RzConsStack *data = R_NEW0 (RzConsStack); if (data) { if (CTX (buffer)) { data->buf = CTX (buffer); data->buf_len = CTX (buffer_len); data->buf_size = CTX (buffer_sz); } - data->grep = R_NEW0 (RConsGrep); + data->grep = R_NEW0 (RzConsGrep); if (data->grep) { - memcpy (data->grep, &I.context->grep, sizeof (RConsGrep)); + memcpy (data->grep, &I.context->grep, sizeof (RzConsGrep)); if (I.context->grep.str) { data->grep->str = strdup (I.context->grep.str); } @@ -79,8 +79,8 @@ static RConsStack *cons_stack_dump(bool recreate) { return data; } -static void cons_stack_load(RConsStack *data, bool free_current) { - r_return_if_fail (data); +static void cons_stack_load(RzConsStack *data, bool free_current) { + rz_return_if_fail (data); if (free_current) { free (I.context->buffer); } @@ -90,11 +90,11 @@ static void cons_stack_load(RConsStack *data, bool free_current) { I.context->buffer_sz = data->buf_size; if (data->grep) { free (I.context->grep.str); - memcpy (&I.context->grep, data->grep, sizeof (RConsGrep)); + memcpy (&I.context->grep, data->grep, sizeof (RzConsGrep)); } } -static void cons_context_init(RConsContext *context, R_NULLABLE RConsContext *parent) { +static void cons_context_init(RzConsContext *context, R_NULLABLE RzConsContext *parent) { context->breaked = false; context->cmd_depth = R_CONS_CMD_DEPTH + 1; context->buffer = NULL; @@ -102,8 +102,8 @@ static void cons_context_init(RConsContext *context, R_NULLABLE RConsContext *pa context->lastEnabled = true; context->buffer_len = 0; context->is_interactive = false; - context->cons_stack = r_stack_newf (6, cons_stack_free); - context->break_stack = r_stack_newf (6, break_stack_free); + context->cons_stack = rz_stack_newf (6, cons_stack_free); + context->break_stack = rz_stack_newf (6, break_stack_free); context->event_interrupt = NULL; context->event_interrupt_data = NULL; context->pageable = true; @@ -111,25 +111,25 @@ static void cons_context_init(RConsContext *context, R_NULLABLE RConsContext *pa if (parent) { context->color_mode = parent->color_mode; - r_cons_pal_copy (context, parent); + rz_cons_pal_copy (context, parent); } else { context->color_mode = COLOR_MODE_DISABLED; - r_cons_pal_init (context); + rz_cons_pal_init (context); } cons_grep_reset (&context->grep); } -static void cons_context_deinit(RConsContext *context) { - r_stack_free (context->cons_stack); +static void cons_context_deinit(RzConsContext *context) { + rz_stack_free (context->cons_stack); context->cons_stack = NULL; - r_stack_free (context->break_stack); + rz_stack_free (context->break_stack); context->break_stack = NULL; - r_cons_pal_free (context); + rz_cons_pal_free (context); } static void __break_signal(int sig) { - r_cons_context_break (&r_cons_context_default); + rz_cons_context_break (&rz_cons_context_default); } static inline void __cons_write_ll(const char *buf, int len) { @@ -138,7 +138,7 @@ static inline void __cons_write_ll(const char *buf, int len) { (void) write (I.fdout, buf, len); } else { if (I.fdout == 1) { - r_cons_w32_print (buf, len, false); + rz_cons_w32_print (buf, len, false); } else { (void) write (I.fdout, buf, len); } @@ -165,16 +165,16 @@ static inline void __cons_write(const char *obuf, int olen) { } } -R_API RColor r_cons_color_random(ut8 alpha) { +RZ_API RColor rz_cons_color_random(ut8 alpha) { RColor rcolor = {0}; if (I.context->color_mode > COLOR_MODE_16) { - rcolor.r = r_num_rand (0xff); - rcolor.g = r_num_rand (0xff); - rcolor.b = r_num_rand (0xff); + rcolor.r = rz_num_rand (0xff); + rcolor.g = rz_num_rand (0xff); + rcolor.b = rz_num_rand (0xff); rcolor.a = alpha; return rcolor; } - int r = r_num_rand (16); + int r = rz_num_rand (16); switch (r) { case 0: case 1: rcolor = (RColor) RColor_RED; break; case 2: case 3: rcolor = (RColor) RColor_WHITE; break; @@ -191,7 +191,7 @@ R_API RColor r_cons_color_random(ut8 alpha) { return rcolor; } -R_API void r_cons_color(int fg, int r, int g, int b) { +RZ_API void rz_cons_color(int fg, int r, int g, int b) { int k; r = R_DIM (r, 0, 255); g = R_DIM (g, 0, 255); @@ -204,42 +204,42 @@ R_API void r_cons_color(int fg, int r, int g, int b) { b = (int)(b / 42.6); k = 16 + (r * 36) + (g * 6) + b; } - r_cons_printf ("\x1b[%d;5;%dm", fg? 48: 38, k); + rz_cons_printf ("\x1b[%d;5;%dm", fg? 48: 38, k); } -R_API void r_cons_println(const char* str) { - r_cons_print (str); - r_cons_newline (); +RZ_API void rz_cons_println(const char* str) { + rz_cons_print (str); + rz_cons_newline (); } -R_API void r_cons_strcat_justify(const char *str, int j, char c) { +RZ_API void rz_cons_strcat_justify(const char *str, int j, char c) { int i, o, len; for (o = i = len = 0; str[i]; i++, len++) { if (str[i] == '\n') { - r_cons_memset (' ', j); + rz_cons_memset (' ', j); if (c) { - r_cons_memset (c, 1); - r_cons_memset (' ', 1); + rz_cons_memset (c, 1); + rz_cons_memset (' ', 1); } - r_cons_memcat (str + o, len); + rz_cons_memcat (str + o, len); if (str[o + len] == '\n') { - r_cons_newline (); + rz_cons_newline (); } o = i + 1; len = 0; } } if (len > 1) { - r_cons_memcat (str + o, len); + rz_cons_memcat (str + o, len); } } -R_API void r_cons_strcat_at(const char *_str, int x, char y, int w, int h) { +RZ_API void rz_cons_strcat_at(const char *_str, int x, char y, int w, int h) { int i, o, len; int cols = 0; int rows = 0; if (x < 0 || y < 0) { - int H, W = r_cons_get_size (&H); + int H, W = rz_cons_get_size (&H); if (x < 0) { x += W; } @@ -247,55 +247,55 @@ R_API void r_cons_strcat_at(const char *_str, int x, char y, int w, int h) { y += H; } } - char *str = r_str_ansi_crop (_str, 0, 0, w + 1, h); - r_cons_strcat (R_CONS_CURSOR_SAVE); + char *str = rz_str_ansi_crop (_str, 0, 0, w + 1, h); + rz_cons_strcat (R_CONS_CURSOR_SAVE); for (o = i = len = 0; str[i]; i++, len++) { if (w < 0 || rows > w) { break; } if (str[i] == '\n') { - r_cons_gotoxy (x, y + rows); - int ansilen = r_str_ansi_len (str + o); + rz_cons_gotoxy (x, y + rows); + int ansilen = rz_str_ansi_len (str + o); cols = R_MIN (w, ansilen); - const char *end = r_str_ansi_chrn (str + o, cols); + const char *end = rz_str_ansi_chrn (str + o, cols); cols = end - str + o; - r_cons_memcat (str + o, R_MIN (len, cols)); + rz_cons_memcat (str + o, R_MIN (len, cols)); o = i + 1; len = 0; rows++; } } if (len > 1) { - r_cons_gotoxy (x, y + rows); - r_cons_memcat (str + o, len); + rz_cons_gotoxy (x, y + rows); + rz_cons_memcat (str + o, len); } - r_cons_strcat (Color_RESET); - r_cons_strcat (R_CONS_CURSOR_RESTORE); + rz_cons_strcat (Color_RESET); + rz_cons_strcat (R_CONS_CURSOR_RESTORE); free (str); } -R_API RCons *r_cons_singleton(void) { +RZ_API RzCons *rz_cons_singleton(void) { return &I; } -R_API void r_cons_break_clear(void) { +RZ_API void rz_cons_break_clear(void) { I.context->breaked = false; } -R_API void r_cons_context_break_push(RConsContext *context, RConsBreak cb, void *user, bool sig) { +RZ_API void rz_cons_context_break_push(RzConsContext *context, RzConsBreak cb, void *user, bool sig) { if (!context->break_stack) { return; } //if we don't have any element in the stack start the signal - RConsBreakStack *b = R_NEW0 (RConsBreakStack); + RzConsBreakStack *b = R_NEW0 (RzConsBreakStack); if (!b) { return; } - if (r_stack_is_empty (context->break_stack)) { + if (rz_stack_is_empty (context->break_stack)) { #if __UNIX__ - if (sig && r_cons_context_is_main ()) { - r_sys_signal (SIGINT, __break_signal); + if (sig && rz_cons_context_is_main ()) { + rz_sys_signal (SIGINT, __break_signal); } #endif context->breaked = false; @@ -303,19 +303,19 @@ R_API void r_cons_context_break_push(RConsContext *context, RConsBreak cb, void //save the actual state b->event_interrupt = context->event_interrupt; b->event_interrupt_data = context->event_interrupt_data; - r_stack_push (context->break_stack, b); + rz_stack_push (context->break_stack, b); //configure break context->event_interrupt = cb; context->event_interrupt_data = user; } -R_API void r_cons_context_break_pop(RConsContext *context, bool sig) { +RZ_API void rz_cons_context_break_pop(RzConsContext *context, bool sig) { if (!context->break_stack) { return; } //restore old state - RConsBreakStack *b = NULL; - b = r_stack_pop (context->break_stack); + RzConsBreakStack *b = NULL; + b = rz_stack_pop (context->break_stack); if (b) { context->event_interrupt = b->event_interrupt; context->event_interrupt_data = b->event_interrupt_data; @@ -323,36 +323,36 @@ R_API void r_cons_context_break_pop(RConsContext *context, bool sig) { } else { //there is not more elements in the stack #if __UNIX__ - if (sig && r_cons_context_is_main ()) { - r_sys_signal (SIGINT, SIG_IGN); + if (sig && rz_cons_context_is_main ()) { + rz_sys_signal (SIGINT, SIG_IGN); } #endif context->breaked = false; } } -R_API void r_cons_break_push(RConsBreak cb, void *user) { - r_cons_context_break_push (I.context, cb, user, true); +RZ_API void rz_cons_break_push(RzConsBreak cb, void *user) { + rz_cons_context_break_push (I.context, cb, user, true); } -R_API void r_cons_break_pop(void) { - r_cons_context_break_pop (I.context, true); +RZ_API void rz_cons_break_pop(void) { + rz_cons_context_break_pop (I.context, true); } -R_API bool r_cons_is_interactive(void) { +RZ_API bool rz_cons_is_interactive(void) { return I.context->is_interactive; } -R_API bool r_cons_default_context_is_interactive(void) { - return r_cons_context_default.is_interactive; +RZ_API bool rz_cons_default_context_is_interactive(void) { + return rz_cons_context_default.is_interactive; } -R_API bool r_cons_is_breaked(void) { +RZ_API bool rz_cons_is_breaked(void) { if (I.cb_break) { I.cb_break (I.user); } if (I.timeout) { - if (r_time_now_mono () > I.timeout) { + if (rz_time_now_mono () > I.timeout) { I.context->breaked = true; eprintf ("\nTimeout!\n"); I.timeout = 0; @@ -361,7 +361,7 @@ R_API bool r_cons_is_breaked(void) { return I.context->breaked; } -R_API int r_cons_get_cur_line(void) { +RZ_API int rz_cons_get_cur_line(void) { int curline = 0; #if __WINDOWS__ POINT point; @@ -393,35 +393,35 @@ R_API int r_cons_get_cur_line(void) { return curline; } -R_API void r_cons_break_timeout(int timeout) { +RZ_API void rz_cons_break_timeout(int timeout) { I.timeout = (timeout && !I.timeout) - ? r_time_now_mono () + ((ut64) timeout << 20) : 0; + ? rz_time_now_mono () + ((ut64) timeout << 20) : 0; } -R_API void r_cons_break_end(void) { +RZ_API void rz_cons_break_end(void) { I.context->breaked = false; I.timeout = 0; #if __UNIX__ - r_sys_signal (SIGINT, SIG_IGN); + rz_sys_signal (SIGINT, SIG_IGN); #endif - if (!r_stack_is_empty (I.context->break_stack)) { + if (!rz_stack_is_empty (I.context->break_stack)) { // free all the stack - r_stack_free (I.context->break_stack); + rz_stack_free (I.context->break_stack); // create another one - I.context->break_stack = r_stack_newf (6, break_stack_free); + I.context->break_stack = rz_stack_newf (6, break_stack_free); I.context->event_interrupt_data = NULL; I.context->event_interrupt = NULL; } } -R_API void *r_cons_sleep_begin(void) { +RZ_API void *rz_cons_sleep_begin(void) { if (!I.cb_sleep_begin) { return NULL; } return I.cb_sleep_begin (I.user); } -R_API void r_cons_sleep_end(void *user) { +RZ_API void rz_cons_sleep_end(void *user) { if (I.cb_sleep_end) { I.cb_sleep_end (I.user, user); } @@ -449,14 +449,14 @@ void resizeWin(void) { } } -R_API void r_cons_set_click(int x, int y) { +RZ_API void rz_cons_set_click(int x, int y) { I.click_x = x; I.click_y = y; I.click_set = true; I.mouse_event = 1; } -R_API bool r_cons_get_click(int *x, int *y) { +RZ_API bool rz_cons_get_click(int *x, int *y) { if (x) { *x = I.click_x; } @@ -468,11 +468,11 @@ R_API bool r_cons_get_click(int *x, int *y) { return set; } -R_API void r_cons_enable_highlight(const bool enable) { +RZ_API void rz_cons_enable_highlight(const bool enable) { I.enable_highlight = enable; } -R_API bool r_cons_enable_mouse(const bool enable) { +RZ_API bool rz_cons_enable_mouse(const bool enable) { if ((I.mouse && enable) || (!I.mouse && !enable)) { return I.mouse; @@ -513,15 +513,15 @@ R_API bool r_cons_enable_mouse(const bool enable) { #endif } -// Stub function that cb_main_output gets pointed to in util/log.c by r_cons_new +// Stub function that cb_main_output gets pointed to in util/log.c by rz_cons_new // This allows Cutter to set per-task logging redirection -R_API RCons *r_cons_new(void) { +RZ_API RzCons *rz_cons_new(void) { I.refcnt++; if (I.refcnt != 1) { return &I; } - I.rgbstr = r_cons_rgb_str_off; - I.line = r_line_new (); + I.rgbstr = rz_cons_rgb_str_off; + I.line = rz_line_new (); I.enable_highlight = true; I.highlight = NULL; I.is_wine = -1; @@ -542,15 +542,15 @@ R_API RCons *r_cons_new(void) { I.break_lines = false; I.lines = 0; - I.context = &r_cons_context_default; + I.context = &rz_cons_context_default; cons_context_init (I.context, NULL); - r_cons_get_size (&I.pagesize); + rz_cons_get_size (&I.pagesize); I.num = NULL; I.null = 0; #if __WINDOWS__ I.old_cp = GetConsoleOutputCP (); - I.vtmode = r_cons_is_vtcompat (); + I.vtmode = rz_cons_is_vtcompat (); #else I.vtmode = 2; #endif @@ -564,33 +564,33 @@ R_API RCons *r_cons_new(void) { I.term_raw.c_cflag &= ~(CSIZE|PARENB); I.term_raw.c_cflag |= CS8; I.term_raw.c_cc[VMIN] = 1; // Solaris stuff hehe - r_sys_signal (SIGWINCH, resize); + rz_sys_signal (SIGWINCH, resize); #elif __WINDOWS__ h = GetStdHandle (STD_INPUT_HANDLE); GetConsoleMode (h, &I.term_buf); I.term_raw = 0; if (!SetConsoleCtrlHandler ((PHANDLER_ROUTINE)__w32_control, TRUE)) { - eprintf ("r_cons: Cannot set control console handler\n"); + eprintf ("rz_cons: Cannot set control console handler\n"); } #endif I.pager = NULL; /* no pager by default */ I.mouse = 0; I.show_vals = false; - r_cons_reset (); - r_cons_rgb_init (); + rz_cons_reset (); + rz_cons_rgb_init (); - r_print_set_is_interrupted_cb (r_cons_is_breaked); + rz_print_set_is_interrupted_cb (rz_cons_is_breaked); return &I; } -R_API RCons *r_cons_free(void) { +RZ_API RzCons *rz_cons_free(void) { #if __WINDOWS__ - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); if (I.old_cp) { (void)SetConsoleOutputCP (I.old_cp); // chcp doesn't pick up the code page switch for some reason - (void)r_sys_cmdf ("chcp %u > NUL", I.old_cp); + (void)rz_sys_cmdf ("chcp %u > NUL", I.old_cp); } #endif I.refcnt--; @@ -598,7 +598,7 @@ R_API RCons *r_cons_free(void) { return NULL; } if (I.line) { - r_line_free (); + rz_line_free (); I.line = NULL; } R_FREE (I.context->buffer); @@ -646,23 +646,23 @@ static bool palloc(int moar) { return true; } -R_API int r_cons_eof(void) { +RZ_API int rz_cons_eof(void) { return feof (I.fdin); } -R_API void r_cons_gotoxy(int x, int y) { +RZ_API void rz_cons_gotoxy(int x, int y) { #if __WINDOWS__ - r_cons_w32_gotoxy (1, x, y); + rz_cons_w32_gotoxy (1, x, y); #else - r_cons_printf ("\x1b[%d;%dH", y, x); + rz_cons_printf ("\x1b[%d;%dH", y, x); #endif } -R_API void r_cons_print_clear(void) { - r_cons_strcat ("\x1b[0;0H\x1b[0m"); +RZ_API void rz_cons_print_clear(void) { + rz_cons_strcat ("\x1b[0;0H\x1b[0m"); } -R_API void r_cons_fill_line(void) { +RZ_API void rz_cons_fill_line(void) { char *p, white[1024]; int cols = I.columns - 1; if (cols < 1) { @@ -673,14 +673,14 @@ R_API void r_cons_fill_line(void) { if (p) { memset (p, ' ', cols); p[cols] = 0; - r_cons_strcat (p); + rz_cons_strcat (p); if (white != p) { free (p); } } } -R_API void r_cons_clear_line(int std_err) { +RZ_API void rz_cons_clear_line(int std_err) { #if __WINDOWS__ if (I.vtmode) { fprintf (std_err? stderr: stdout,"%s", R_CONS_CLEAR_LINE); @@ -702,25 +702,25 @@ R_API void r_cons_clear_line(int std_err) { fflush (std_err? stderr: stdout); } -R_API void r_cons_clear00(void) { - r_cons_clear (); - r_cons_gotoxy (0, 0); +RZ_API void rz_cons_clear00(void) { + rz_cons_clear (); + rz_cons_gotoxy (0, 0); } -R_API void r_cons_reset_colors(void) { - r_cons_strcat (Color_RESET_BG Color_RESET); +RZ_API void rz_cons_reset_colors(void) { + rz_cons_strcat (Color_RESET_BG Color_RESET); } -R_API void r_cons_clear(void) { +RZ_API void rz_cons_clear(void) { I.lines = 0; #if __WINDOWS__ - r_cons_w32_clear (); + rz_cons_w32_clear (); #else - r_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN); + rz_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN); #endif } -static void cons_grep_reset(RConsGrep *grep) { +static void cons_grep_reset(RzConsGrep *grep) { R_FREE (grep->str); ZERO_FILL (*grep); grep->line = -1; @@ -728,7 +728,7 @@ static void cons_grep_reset(RConsGrep *grep) { grep->sort_invert = false; } -R_API void r_cons_reset(void) { +RZ_API void rz_cons_reset(void) { if (I.context->buffer) { I.context->buffer[0] = '\0'; } @@ -739,26 +739,26 @@ R_API void r_cons_reset(void) { CTX (pageable) = true; } -R_API const char *r_cons_get_buffer(void) { +RZ_API const char *rz_cons_get_buffer(void) { //check len otherwise it will return trash return I.context->buffer_len? I.context->buffer : NULL; } -R_API int r_cons_get_buffer_len(void) { +RZ_API int rz_cons_get_buffer_len(void) { return I.context->buffer_len; } -R_API void r_cons_filter(void) { +RZ_API void rz_cons_filter(void) { /* grep */ if (I.filter || I.context->grep.nstrings > 0 || I.context->grep.tokens_used || I.context->grep.less || I.context->grep.json) { - (void)r_cons_grepbuf (); + (void)rz_cons_grepbuf (); I.filter = false; } /* html */ if (I.is_html) { int newlen = 0; - char *input = r_str_ndup (I.context->buffer, I.context->buffer_len); - char *res = r_cons_html_filter (input, &newlen); + char *input = rz_str_ndup (I.context->buffer, I.context->buffer_len); + char *res = rz_cons_html_filter (input, &newlen); free (I.context->buffer); I.context->buffer = res; I.context->buffer_len = newlen; @@ -771,26 +771,26 @@ R_API void r_cons_filter(void) { } } -R_API void r_cons_push(void) { +RZ_API void rz_cons_push(void) { if (!I.context->cons_stack) { return; } - RConsStack *data = cons_stack_dump (true); + RzConsStack *data = cons_stack_dump (true); if (!data) { return; } - r_stack_push (I.context->cons_stack, data); + rz_stack_push (I.context->cons_stack, data); I.context->buffer_len = 0; if (I.context->buffer) { memset (I.context->buffer, 0, I.context->buffer_sz); } } -R_API void r_cons_pop(void) { +RZ_API void rz_cons_pop(void) { if (!I.context->cons_stack) { return; } - RConsStack *data = (RConsStack *)r_stack_pop (I.context->cons_stack); + RzConsStack *data = (RzConsStack *)rz_stack_pop (I.context->cons_stack); if (!data) { return; } @@ -798,8 +798,8 @@ R_API void r_cons_pop(void) { cons_stack_free ((void *)data); } -R_API RConsContext *r_cons_context_new(R_NULLABLE RConsContext *parent) { - RConsContext *context = R_NEW0 (RConsContext); +RZ_API RzConsContext *rz_cons_context_new(R_NULLABLE RzConsContext *parent) { + RzConsContext *context = R_NEW0 (RzConsContext); if (!context) { return NULL; } @@ -807,7 +807,7 @@ R_API RConsContext *r_cons_context_new(R_NULLABLE RConsContext *parent) { return context; } -R_API void r_cons_context_free(RConsContext *context) { +RZ_API void rz_cons_context_free(RzConsContext *context) { if (!context) { return; } @@ -815,19 +815,19 @@ R_API void r_cons_context_free(RConsContext *context) { free (context); } -R_API void r_cons_context_load(RConsContext *context) { +RZ_API void rz_cons_context_load(RzConsContext *context) { I.context = context; } -R_API void r_cons_context_reset(void) { - I.context = &r_cons_context_default; +RZ_API void rz_cons_context_reset(void) { + I.context = &rz_cons_context_default; } -R_API bool r_cons_context_is_main(void) { - return I.context == &r_cons_context_default; +RZ_API bool rz_cons_context_is_main(void) { + return I.context == &rz_cons_context_default; } -R_API void r_cons_context_break(RConsContext *context) { +RZ_API void rz_cons_context_break(RzConsContext *context) { if (!context) { return; } @@ -837,12 +837,12 @@ R_API void r_cons_context_break(RConsContext *context) { } } -R_API void r_cons_last(void) { +RZ_API void rz_cons_last(void) { if (!CTX (lastEnabled)) { return; } CTX (lastMode) = true; - r_cons_memcat (CTX (lastOutput), CTX (lastLength)); + rz_cons_memcat (CTX (lastOutput), CTX (lastLength)); } static bool lastMatters(void) { @@ -852,33 +852,33 @@ static bool lastMatters(void) { !I.context->grep.json && !I.is_html); } -R_API void r_cons_echo(const char *msg) { - static RStrBuf *echodata = NULL; // TODO: move into RConsInstance? maybe nope +RZ_API void rz_cons_echo(const char *msg) { + static RStrBuf *echodata = NULL; // TODO: move into RzConsInstance? maybe nope if (msg) { if (echodata) { - r_strbuf_append (echodata, msg); - r_strbuf_append (echodata, "\n"); + rz_strbuf_append (echodata, msg); + rz_strbuf_append (echodata, "\n"); } else { - echodata = r_strbuf_new (msg); + echodata = rz_strbuf_new (msg); } } else { if (echodata) { - char *data = r_strbuf_drain (echodata); - r_cons_strcat (data); - r_cons_newline (); + char *data = rz_strbuf_drain (echodata); + rz_cons_strcat (data); + rz_cons_newline (); echodata = NULL; free (data); } } } -R_API void r_cons_flush(void) { +RZ_API void rz_cons_flush(void) { const char *tee = I.teefile; if (I.noflush) { return; } if (I.null) { - r_cons_reset (); + rz_cons_reset (); return; } if (lastMatters () && !CTX (lastMode)) { @@ -892,21 +892,21 @@ R_API void r_cons_flush(void) { } else { CTX (lastMode) = false; } - r_cons_filter (); - if (r_cons_is_interactive () && I.fdout == 1) { + rz_cons_filter (); + if (rz_cons_is_interactive () && I.fdout == 1) { /* Use a pager if the output doesn't fit on the terminal window. */ - if (CTX (pageable) && CTX (buffer) && I.pager && *I.pager && CTX (buffer_len) > 0 && r_str_char_count (CTX (buffer), '\n') >= I.rows) { + if (CTX (pageable) && CTX (buffer) && I.pager && *I.pager && CTX (buffer_len) > 0 && rz_str_char_count (CTX (buffer), '\n') >= I.rows) { I.context->buffer[I.context->buffer_len - 1] = 0; if (!strcmp (I.pager, "..")) { - char *str = r_str_ndup (CTX (buffer), CTX (buffer_len)); + char *str = rz_str_ndup (CTX (buffer), CTX (buffer_len)); CTX (pageable) = false; - r_cons_less_str (str, NULL); - r_cons_reset (); + rz_cons_less_str (str, NULL); + rz_cons_reset (); free (str); return; } else { - r_sys_cmd_str_full (I.pager, CTX (buffer), NULL, NULL, NULL); - r_cons_reset (); + rz_sys_cmd_str_full (I.pager, CTX (buffer), NULL, NULL, NULL); + rz_cons_reset (); } } else if (I.context->buffer_len > CONS_MAX_USER) { #if COUNT_LINES @@ -916,37 +916,37 @@ R_API void r_cons_flush(void) { lines ++; } } - if (lines > 0 && !r_cons_yesno ('n',"Do you want to print %d lines? (y/N)", lines)) { - r_cons_reset (); + if (lines > 0 && !rz_cons_yesno ('n',"Do you want to print %d lines? (y/N)", lines)) { + rz_cons_reset (); return; } #else char buf[8]; - r_num_units (buf, sizeof (buf), I.context->buffer_len); - if (!r_cons_yesno ('n', "Do you want to print %s chars? (y/N)", buf)) { - r_cons_reset (); + rz_num_units (buf, sizeof (buf), I.context->buffer_len); + if (!rz_cons_yesno ('n', "Do you want to print %s chars? (y/N)", buf)) { + rz_cons_reset (); return; } #endif // fix | more | less problem - r_cons_set_raw (true); + rz_cons_set_raw (true); } } if (tee && *tee) { - FILE *d = r_sandbox_fopen (tee, "a+"); + FILE *d = rz_sandbox_fopen (tee, "a+"); if (d) { if (I.context->buffer_len != fwrite (I.context->buffer, 1, I.context->buffer_len, d)) { - eprintf ("r_cons_flush: fwrite: error (%s)\n", tee); + eprintf ("rz_cons_flush: fwrite: error (%s)\n", tee); } fclose (d); } else { eprintf ("Cannot write on '%s'\n", tee); } } - r_cons_highlight (I.highlight); + rz_cons_highlight (I.highlight); // is_html must be a filter, not a write endpoint - if (r_cons_is_interactive () && !r_sandbox_enable (false)) { + if (rz_cons_is_interactive () && !rz_sandbox_enable (false)) { if (I.linesleep > 0 && I.linesleep < 1000) { int i = 0; int pagesize = R_MAX (1, I.pagesize); @@ -954,18 +954,18 @@ R_API void r_cons_flush(void) { char *nl = strchr (ptr, '\n'); int len = I.context->buffer_len; I.context->buffer[I.context->buffer_len] = 0; - r_cons_break_push (NULL, NULL); - while (nl && !r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + while (nl && !rz_cons_is_breaked ()) { __cons_write (ptr, nl - ptr + 1); if (I.linesleep && !(i % pagesize)) { - r_sys_usleep (I.linesleep * 1000); + rz_sys_usleep (I.linesleep * 1000); } ptr = nl + 1; nl = strchr (ptr, '\n'); i++; } __cons_write (ptr, I.context->buffer + len - ptr); - r_cons_break_pop (); + rz_cons_break_pop (); } else { __cons_write (I.context->buffer, I.context->buffer_len); } @@ -973,42 +973,42 @@ R_API void r_cons_flush(void) { __cons_write (I.context->buffer, I.context->buffer_len); } - r_cons_reset (); + rz_cons_reset (); if (I.newline) { eprintf ("\n"); I.newline = false; } } -R_API void r_cons_visual_flush(void) { +RZ_API void rz_cons_visual_flush(void) { if (I.noflush) { return; } - r_cons_highlight (I.highlight); + rz_cons_highlight (I.highlight); if (!I.null) { /* TODO: this ifdef must go in the function body */ #if __WINDOWS__ if (I.vtmode) { - r_cons_visual_write (I.context->buffer); + rz_cons_visual_write (I.context->buffer); } else { - r_cons_w32_print (I.context->buffer, I.context->buffer_len, true); + rz_cons_w32_print (I.context->buffer, I.context->buffer_len, true); } #else - r_cons_visual_write (I.context->buffer); + rz_cons_visual_write (I.context->buffer); #endif } - r_cons_reset (); + rz_cons_reset (); if (I.fps) { - r_cons_print_fps (0); + rz_cons_print_fps (0); } } -R_API void r_cons_print_fps (int col) { - int fps = 0, w = r_cons_get_size (NULL); - static ut64 prev = 0LL; //r_time_now_mono (); +RZ_API void rz_cons_print_fps (int col) { + int fps = 0, w = rz_cons_get_size (NULL); + static ut64 prev = 0LL; //rz_time_now_mono (); fps = 0; if (prev) { - ut64 now = r_time_now_mono (); + ut64 now = rz_time_now_mono (); st64 diff = (st64)(now - prev); if (diff < 0) { fps = 0; @@ -1017,7 +1017,7 @@ R_API void r_cons_print_fps (int col) { } prev = now; } else { - prev = r_time_now_mono (); + prev = rz_time_now_mono (); } if (col < 1) { col = 12; @@ -1026,7 +1026,7 @@ R_API void r_cons_print_fps (int col) { if (I.vtmode) { eprintf ("\x1b[0;%dH[%d FPS] \n", w - col, fps); } else { - r_cons_w32_gotoxy (2, w - col, 0); + rz_cons_w32_gotoxy (2, w - col, 0); eprintf (" [%d FPS] \n", fps); } #else @@ -1035,8 +1035,8 @@ R_API void r_cons_print_fps (int col) { } static int real_strlen(const char *ptr, int len) { - int utf8len = r_str_len_utf8 (ptr); - int ansilen = r_str_ansi_len (ptr); + int utf8len = rz_str_len_utf8 (ptr); + int ansilen = rz_str_ansi_len (ptr); int diff = len - utf8len; if (diff > 0) { diff--; @@ -1044,7 +1044,7 @@ static int real_strlen(const char *ptr, int len) { return ansilen - diff; } -R_API void r_cons_visual_write(char *buffer) { +RZ_API void rz_cons_visual_write(char *buffer) { char white[1024]; int cols = I.columns; int alen, plen, lines = I.rows; @@ -1072,7 +1072,7 @@ R_API void r_cons_visual_write(char *buffer) { if ((break_lines && lines < lines_needed && lines > 0) || (!break_lines && alen > cols)) { int olen = len; - endptr = r_str_ansi_chrn (ptr, (break_lines ? cols * lines : cols) + 1); + endptr = rz_str_ansi_chrn (ptr, (break_lines ? cols * lines : cols) + 1); endptr++; len = endptr - ptr; plen = ptr > buffer ? len : len - 1; @@ -1095,7 +1095,7 @@ R_API void r_cons_visual_write(char *buffer) { } } // TRICK to empty columns.. maybe buggy in w32 - if (r_mem_mem ((const ut8*)ptr, len, (const ut8*)"\x1b[0;0H", 6)) { + if (rz_mem_mem ((const ut8*)ptr, len, (const ut8*)"\x1b[0;0H", 6)) { lines = I.rows; __cons_write (pptr, plen); } @@ -1118,7 +1118,7 @@ R_API void r_cons_visual_write(char *buffer) { } } -R_API void r_cons_printf_list(const char *format, va_list ap) { +RZ_API void rz_cons_printf_list(const char *format, va_list ap) { size_t size, written; va_list ap2, ap3; @@ -1145,35 +1145,35 @@ club: I.context->buffer[I.context->buffer_len] = 0; } } else { - r_cons_strcat (format); + rz_cons_strcat (format); } va_end (ap2); va_end (ap3); } -R_API int r_cons_printf(const char *format, ...) { +RZ_API int rz_cons_printf(const char *format, ...) { va_list ap; if (!format || !*format) { return -1; } va_start (ap, format); - r_cons_printf_list (format, ap); + rz_cons_printf_list (format, ap); va_end (ap); return 0; } -R_API int r_cons_get_column(void) { +RZ_API int rz_cons_get_column(void) { char *line = strrchr (I.context->buffer, '\n'); if (!line) { line = I.context->buffer; } I.context->buffer[I.context->buffer_len] = 0; - return r_str_ansi_len (line); + return rz_str_ansi_len (line); } /* final entrypoint for adding stuff in the buffer screen */ -R_API int r_cons_memcat(const char *str, int len) { +RZ_API int rz_cons_memcat(const char *str, int len) { if (len < 0) { return -1; } @@ -1192,17 +1192,17 @@ R_API int r_cons_memcat(const char *str, int len) { } } if (I.flush) { - r_cons_flush (); + rz_cons_flush (); } if (I.break_word && str && len > 0) { - if (r_mem_mem ((const ut8*)str, len, (const ut8*)I.break_word, I.break_word_len)) { + if (rz_mem_mem ((const ut8*)str, len, (const ut8*)I.break_word, I.break_word_len)) { I.context->breaked = true; } } return len; } -R_API void r_cons_memset(char ch, int len) { +RZ_API void rz_cons_memset(char ch, int len) { if (!I.null && len > 0) { if (palloc (len + 1)) { memset (I.context->buffer + I.context->buffer_len, ch, len); @@ -1212,44 +1212,44 @@ R_API void r_cons_memset(char ch, int len) { } } -R_API void r_cons_strcat(const char *str) { +RZ_API void rz_cons_strcat(const char *str) { int len; if (!str || I.null) { return; } len = strlen (str); if (len > 0) { - r_cons_memcat (str, len); + rz_cons_memcat (str, len); } } -R_API void r_cons_newline(void) { +RZ_API void rz_cons_newline(void) { if (!I.null) { - r_cons_strcat ("\n"); + rz_cons_strcat ("\n"); } #if 0 -This place is wrong to manage the color reset, can interfire with r2pipe output sending resetchars +This place is wrong to manage the color reset, can interfire with rzpipe output sending resetchars and break json output appending extra chars. -this code now is managed into output.c:118 at function r_cons_w32_print +this code now is managed into output.c:118 at function rz_cons_w32_print now the console color is reset with each \n (same stuff do it here but in correct place ... i think) #if __WINDOWS__ - r_cons_reset_colors(); + rz_cons_reset_colors(); #else - r_cons_strcat (Color_RESET_ALL"\n"); + rz_cons_strcat (Color_RESET_ALL"\n"); #endif - if (I.is_html) r_cons_strcat ("
\n"); + if (I.is_html) rz_cons_strcat ("
\n"); #endif } /* return the aproximated x,y of cursor before flushing */ // XXX this function is a huge bottleneck -R_API int r_cons_get_cursor(int *rows) { +RZ_API int rz_cons_get_cursor(int *rows) { int i, col = 0; int row = 0; // TODO: we need to handle GOTOXY and CLRSCR ansi escape code too for (i = 0; i < I.context->buffer_len; i++) { - // ignore ansi chars, copypasta from r_str_ansi_len + // ignore ansi chars, copypasta from rz_str_ansi_len if (I.context->buffer[i] == 0x1b) { char ch2 = I.context->buffer[i + 1]; char *str = I.context->buffer; @@ -1277,7 +1277,7 @@ R_API int r_cons_get_cursor(int *rows) { return col; } -R_API bool r_cons_isatty(void) { +RZ_API bool rz_cons_isatty(void) { #if __UNIX__ struct winsize win = { 0 }; const char *tty; @@ -1318,9 +1318,9 @@ static int __xterm_get_cur_pos(int *xpos) { bool is_reply; do { is_reply = true; - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (ch != 0x1b) { - while (ch = r_cons_readchar_timeout (25)) { + while (ch = rz_cons_readchar_timeout (25)) { if (ch < 1) { return 0; } @@ -1329,9 +1329,9 @@ static int __xterm_get_cur_pos(int *xpos) { } } } - (void)r_cons_readchar (); + (void)rz_cons_readchar (); for (i = 0; i < R_ARRAY_SIZE (pos) - 1; i++) { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if ((!i && !IS_DIGIT (ch)) || // dumps arrow keys etc. (i == 1 && ch == '~')) { // dumps PgUp, PgDn etc. is_reply = false; @@ -1347,7 +1347,7 @@ static int __xterm_get_cur_pos(int *xpos) { pos[R_ARRAY_SIZE (pos) - 1] = 0; ypos = atoi (pos); for (i = 0; i < R_ARRAY_SIZE (pos) - 1; i++) { - if ((ch = r_cons_readchar ()) == 'R') { + if ((ch = rz_cons_readchar ()) == 'R') { pos[i] = 0; break; } @@ -1377,7 +1377,7 @@ static bool __xterm_get_size(void) { #endif // XXX: if this function returns <0 in rows or cols expect MAYHEM -R_API int r_cons_get_size(int *rows) { +RZ_API int rz_cons_get_size(int *rows) { #if __WINDOWS__ CONSOLE_SCREEN_BUFFER_INFO csbi; bool ret = GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &csbi); @@ -1419,7 +1419,7 @@ R_API int r_cons_get_size(int *rows) { I.rows = 23; } #else - char *str = r_sys_getenv ("COLUMNS"); + char *str = rz_sys_getenv ("COLUMNS"); if (str) { I.columns = atoi (str); I.rows = 23; // XXX. windows must get console size @@ -1464,21 +1464,21 @@ R_API int r_cons_get_size(int *rows) { } #if __WINDOWS__ -R_API int r_cons_is_vtcompat(void) { +RZ_API int rz_cons_is_vtcompat(void) { DWORD major; DWORD minor; DWORD release = 0; - char *wt_session = r_sys_getenv ("WT_SESSION"); + char *wt_session = rz_sys_getenv ("WT_SESSION"); if (wt_session) { free (wt_session); return 2; } - char *alacritty = r_sys_getenv ("ALACRITTY_LOG"); + char *alacritty = rz_sys_getenv ("ALACRITTY_LOG"); if (alacritty) { free (alacritty); return 1; } - char *term = r_sys_getenv ("TERM"); + char *term = rz_sys_getenv ("TERM"); if (term) { if (strstr (term, "xterm")) { I.term_xterm = 1; @@ -1488,13 +1488,13 @@ R_API int r_cons_is_vtcompat(void) { I.term_xterm = 0; free (term); } - char *ansicon = r_sys_getenv ("ANSICON"); + char *ansicon = rz_sys_getenv ("ANSICON"); if (ansicon) { free (ansicon); return 1; } bool win_support = 0; - RSysInfo *info = r_sys_info (); + RSysInfo *info = rz_sys_info (); if (info && info->version) { char *dot = strtok (info->version, "."); major = atoi (dot); @@ -1509,12 +1509,12 @@ R_API int r_cons_is_vtcompat(void) { win_support = 1; } } - r_sys_info_free (info); + rz_sys_info_free (info); return win_support; } #endif -R_API void r_cons_show_cursor(int cursor) { +RZ_API void rz_cons_show_cursor(int cursor) { #if __WINDOWS__ if (I.vtmode) { #endif @@ -1539,18 +1539,18 @@ R_API void r_cons_show_cursor(int cursor) { } /** - * void r_cons_set_raw( [0,1] ) + * void rz_cons_set_raw( [0,1] ) * * Change canonicality of the terminal * * For optimization reasons, there's no initialization flag, so you need to - * ensure that the make the first call to r_cons_set_raw() with '1' and + * ensure that the make the first call to rz_cons_set_raw() with '1' and * the next calls ^=1, so: 1, 0, 1, 0, 1, ... * * If you doesn't use this order you'll probably loss your terminal properties. * */ -R_API void r_cons_set_raw(bool is_raw) { +RZ_API void rz_cons_set_raw(bool is_raw) { static int oldraw = -1; if (oldraw != -1) { if (is_raw == oldraw) { @@ -1570,13 +1570,13 @@ R_API void r_cons_set_raw(bool is_raw) { #elif __WINDOWS__ if (is_raw) { if (I.term_xterm) { - r_sandbox_system ("stty raw -echo", 1); + rz_sandbox_system ("stty raw -echo", 1); } else { SetConsoleMode (h, I.term_raw); } } else { if (I.term_xterm) { - r_sandbox_system ("stty -raw echo", 1); + rz_sandbox_system ("stty -raw echo", 1); } else { SetConsoleMode (h, I.term_buf); } @@ -1588,13 +1588,13 @@ R_API void r_cons_set_raw(bool is_raw) { oldraw = is_raw; } -R_API void r_cons_set_utf8(bool b) { +RZ_API void rz_cons_set_utf8(bool b) { I.use_utf8 = b; #if __WINDOWS__ if (b) { if (IsValidCodePage (CP_UTF8)) { if (!SetConsoleOutputCP (CP_UTF8)) { - r_sys_perror ("r_cons_set_utf8"); + rz_sys_perror ("rz_cons_set_utf8"); } #if UNICODE UINT inCP = CP_UTF8; @@ -1602,7 +1602,7 @@ R_API void r_cons_set_utf8(bool b) { UINT inCP = GetACP (); #endif if (!SetConsoleCP (inCP)) { - r_sys_perror ("r_cons_set_utf8"); + rz_sys_perror ("rz_cons_set_utf8"); } } else { R_LOG_WARN ("UTF-8 Codepage not installed.\n"); @@ -1610,23 +1610,23 @@ R_API void r_cons_set_utf8(bool b) { } else { UINT acp = GetACP (); if (!SetConsoleCP (acp) || !SetConsoleOutputCP (acp)) { - r_sys_perror ("r_cons_set_utf8"); + rz_sys_perror ("rz_cons_set_utf8"); } } #endif } -R_API void r_cons_invert(int set, int color) { - r_cons_strcat (R_CONS_INVERT (set, color)); +RZ_API void rz_cons_invert(int set, int color) { + rz_cons_strcat (R_CONS_INVERT (set, color)); } /* Enable/Disable scrolling in terminal: - FMI: cd libr/cons/t ; make ti ; ./ti + FMI: cd librz/cons/t ; make ti ; ./ti smcup: disable terminal scrolling (fullscreen mode) rmcup: enable terminal scrolling (normal mode) */ -R_API bool r_cons_set_cup(bool enable) { +RZ_API bool rz_cons_set_cup(bool enable) { #if __UNIX__ const char *code = enable ? "\x1b[?1049h" "\x1b" "7\x1b[?47h" @@ -1653,36 +1653,36 @@ R_API bool r_cons_set_cup(bool enable) { return true; } -R_API void r_cons_column(int c) { +RZ_API void rz_cons_column(int c) { char *b = malloc (I.context->buffer_len + 1); if (!b) { return; } memcpy (b, I.context->buffer, I.context->buffer_len); b[I.context->buffer_len] = 0; - r_cons_reset (); + rz_cons_reset (); // align current buffer N chars right - r_cons_strcat_justify (b, c, 0); - r_cons_gotoxy (0, 0); + rz_cons_strcat_justify (b, c, 0); + rz_cons_gotoxy (0, 0); free (b); } // XXX deprecate must be push/pop context state static bool lasti = false; /* last interactive mode */ -R_API void r_cons_set_interactive(bool x) { - lasti = r_cons_singleton ()->context->is_interactive; - r_cons_singleton ()->context->is_interactive = x; +RZ_API void rz_cons_set_interactive(bool x) { + lasti = rz_cons_singleton ()->context->is_interactive; + rz_cons_singleton ()->context->is_interactive = x; } -R_API void r_cons_set_last_interactive(void) { - r_cons_singleton ()->context->is_interactive = lasti; +RZ_API void rz_cons_set_last_interactive(void) { + rz_cons_singleton ()->context->is_interactive = lasti; } -R_API void r_cons_set_title(const char *str) { +RZ_API void rz_cons_set_title(const char *str) { #if __WINDOWS__ # if defined(_UNICODE) - wchar_t* wstr = r_utf8_to_utf16_l (str, strlen (str)); + wchar_t* wstr = rz_utf8_to_utf16_l (str, strlen (str)); if (wstr) { SetConsoleTitleW (wstr); R_FREE (wstr); @@ -1691,18 +1691,18 @@ R_API void r_cons_set_title(const char *str) { SetConsoleTitle (str); # endif // defined(_UNICODE) #else - r_cons_printf ("\x1b]0;%s\007", str); + rz_cons_printf ("\x1b]0;%s\007", str); #endif } -R_API void r_cons_zero(void) { +RZ_API void rz_cons_zero(void) { if (I.line) { I.line->zerosep = true; } (void)write (1, "", 1); } -R_API void r_cons_highlight(const char *word) { +RZ_API void rz_cons_highlight(const char *word) { int l, *cpos = NULL; char *rword = NULL, *res, *clean = NULL; char *inv[2] = { @@ -1715,14 +1715,14 @@ R_API void r_cons_highlight(const char *word) { }; if (!I.enable_highlight) { - r_cons_enable_highlight (true); + rz_cons_enable_highlight (true); return; } if (word && *word && I.context->buffer) { int word_len = strlen (word); char *orig; - clean = r_str_ndup (I.context->buffer, I.context->buffer_len); - l = r_str_ansi_filter (clean, &orig, &cpos, -1); + clean = rz_str_ndup (I.context->buffer, I.context->buffer_len); + l = rz_str_ansi_filter (clean, &orig, &cpos, -1); free (I.context->buffer); I.context->buffer = orig; if (I.highlight) { @@ -1742,7 +1742,7 @@ R_API void r_cons_highlight(const char *word) { strcpy (rword, inv[0]); strcpy (rword + linv[0], word); strcpy (rword + linv[0] + word_len, inv[1]); - res = r_str_replace_thunked (I.context->buffer, clean, cpos, + res = rz_str_replace_thunked (I.context->buffer, clean, cpos, l, word, rword, 1); if (res) { I.context->buffer = res; @@ -1758,7 +1758,7 @@ R_API void r_cons_highlight(const char *word) { } } -R_API char *r_cons_lastline(int *len) { +RZ_API char *rz_cons_lastline(int *len) { char *b = I.context->buffer + I.context->buffer_len; while (b > I.context->buffer) { if (*b == '\n') { @@ -1774,11 +1774,11 @@ R_API char *r_cons_lastline(int *len) { return b; } -// same as r_cons_lastline(), but len will be the number of +// same as rz_cons_lastline(), but len will be the number of // utf-8 characters excluding ansi escape sequences as opposed to just bytes -R_API char *r_cons_lastline_utf8_ansi_len(int *len) { +RZ_API char *rz_cons_lastline_utf8_ansi_len(int *len) { if (!len) { - return r_cons_lastline (0); + return rz_cons_lastline (0); } char *b = I.context->buffer + I.context->buffer_len; @@ -1816,27 +1816,27 @@ R_API char *r_cons_lastline_utf8_ansi_len(int *len) { } /* swap color from foreground to background, returned value must be freed */ -R_API char *r_cons_swap_ground(const char *col) { +RZ_API char *rz_cons_swap_ground(const char *col) { if (!col) { return NULL; } if (!strncmp (col, "\x1b[48;5;", 7)) { /* rgb background */ - return r_str_newf ("\x1b[38;5;%s", col+7); + return rz_str_newf ("\x1b[38;5;%s", col+7); } else if (!strncmp (col, "\x1b[38;5;", 7)) { /* rgb foreground */ - return r_str_newf ("\x1b[48;5;%s", col+7); + return rz_str_newf ("\x1b[48;5;%s", col+7); } else if (!strncmp (col, "\x1b[4", 3)) { /* is background */ - return r_str_newf ("\x1b[3%s", col+3); + return rz_str_newf ("\x1b[3%s", col+3); } else if (!strncmp (col, "\x1b[3", 3)) { /* is foreground */ - return r_str_newf ("\x1b[4%s", col+3); + return rz_str_newf ("\x1b[4%s", col+3); } return strdup (col); } -R_API bool r_cons_drop(int n) { +RZ_API bool rz_cons_drop(int n) { if (n > I.context->buffer_len) { I.context->buffer_len = 0; return false; @@ -1845,7 +1845,7 @@ R_API bool r_cons_drop(int n) { return true; } -R_API void r_cons_chop(void) { +RZ_API void rz_cons_chop(void) { while (I.context->buffer_len > 0) { char ch = I.context->buffer[I.context->buffer_len - 1]; if (ch != '\n' && !IS_WHITESPACE (ch)) { @@ -1855,19 +1855,19 @@ R_API void r_cons_chop(void) { } } -R_API void r_cons_bind(RConsBind *bind) { +RZ_API void rz_cons_bind(RzConsBind *bind) { if (!bind) { return; } - bind->get_size = r_cons_get_size; - bind->get_cursor = r_cons_get_cursor; - bind->cb_printf = r_cons_printf; - bind->cb_flush = r_cons_flush; - bind->cb_grep = r_cons_grep; - bind->is_breaked = r_cons_is_breaked; + bind->get_size = rz_cons_get_size; + bind->get_cursor = rz_cons_get_cursor; + bind->cb_printf = rz_cons_printf; + bind->cb_flush = rz_cons_flush; + bind->cb_grep = rz_cons_grep; + bind->is_breaked = rz_cons_is_breaked; } -R_API const char* r_cons_get_rune(const ut8 ch) { +RZ_API const char* rz_cons_get_rune(const ut8 ch) { switch (ch) { case RUNECODE_LINE_HORIZ: return RUNE_LINE_HORIZ; case RUNECODE_LINE_VERT: return RUNE_LINE_VERT; @@ -1884,7 +1884,7 @@ R_API const char* r_cons_get_rune(const ut8 ch) { return NULL; } -R_API void r_cons_breakword(R_NULLABLE const char *s) { +RZ_API void rz_cons_breakword(R_NULLABLE const char *s) { free (I.break_word); if (s) { I.break_word = strdup (s); @@ -1899,8 +1899,8 @@ R_API void r_cons_breakword(R_NULLABLE const char *s) { * help should be an array of the following form: * {"command", "args", "description", * "command2", "args2", "description"}; */ -R_API void r_cons_cmd_help(const char *help[], bool use_color) { - RCons *cons = r_cons_singleton (); +RZ_API void rz_cons_cmd_help(const char *help[], bool use_color) { + RzCons *cons = rz_cons_singleton (); const char *pal_args_color = use_color ? cons->context->pal.args : "", *pal_help_color = use_color ? cons->context->pal.help : "", *pal_input_color = use_color ? cons->context->pal.input : "", @@ -1919,25 +1919,25 @@ R_API void r_cons_cmd_help(const char *help[], bool use_color) { for (i = 0; help[i]; i += 3) { if (!strncmp (help[i], usage_str, strlen (usage_str))) { // Lines matching Usage: should always be the first in inline doc - r_cons_printf ("%s%s %s %s%s\n", pal_args_color, + rz_cons_printf ("%s%s %s %s%s\n", pal_args_color, help[i], help[i + 1], help[i + 2], pal_reset); continue; } if (!help[i + 1][0] && !help[i + 2][0]) { // no need to indent the sections lines - r_cons_printf ("%s%s%s\n", pal_help_color, help[i], pal_reset); + rz_cons_printf ("%s%s%s\n", pal_help_color, help[i], pal_reset); } else { // these are the normal lines int str_length = strlen (help[i]) + strlen (help[i + 1]); int padding = (str_length < max_length)? (max_length - str_length): 0; - r_cons_printf ("| %s%s%s%s%*s %s%s%s\n", + rz_cons_printf ("| %s%s%s%s%*s %s%s%s\n", pal_input_color, help[i], pal_args_color, help[i + 1], padding, "", pal_help_color, help[i + 2], pal_reset); } } } -R_API void r_cons_clear_buffer(void) { +RZ_API void rz_cons_clear_buffer(void) { if (I.vtmode) { (void)write (1, "\x1b" "c\x1b[3J", 6); } diff --git a/libr/cons/cpipe.c b/librz/cons/cpipe.c similarity index 81% rename from libr/cons/cpipe.c rename to librz/cons/cpipe.c index d2f6d7e0b4..34cdb1df5f 100644 --- a/libr/cons/cpipe.c +++ b/librz/cons/cpipe.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include #include // TODO: kill globals, and make this stackable @@ -25,16 +25,16 @@ static bool __dupDescriptor(int fd, int fdn) { #endif } -R_API int r_cons_pipe_open(const char *file, int fdn, int append) { +RZ_API int rz_cons_pipe_open(const char *file, int fdn, int append) { if (fdn < 1) { return -1; } char *targetFile = (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) - ? r_str_home (file + 2): strdup (file); + ? rz_str_home (file + 2): strdup (file); const int fd_flags = O_BINARY | O_RDWR | O_CREAT | (append? O_APPEND: O_TRUNC); - int fd = r_sandbox_open (targetFile, fd_flags, 0644); + int fd = rz_sandbox_open (targetFile, fd_flags, 0644); if (fd == -1) { - eprintf ("r_cons_pipe_open: Cannot open file '%s'\n", file); + eprintf ("rz_cons_pipe_open: Cannot open file '%s'\n", file); free (targetFile); return -1; } @@ -54,7 +54,7 @@ R_API int r_cons_pipe_open(const char *file, int fdn, int append) { return fd; } -R_API void r_cons_pipe_close(int fd) { +RZ_API void rz_cons_pipe_close(int fd) { if (fd != -1) { close (fd); if (backup_fd != -1) { diff --git a/libr/cons/cutf8.c b/librz/cons/cutf8.c similarity index 95% rename from libr/cons/cutf8.c rename to librz/cons/cutf8.c index 4e6d4f22dd..3d5bbdcb8d 100644 --- a/libr/cons/cutf8.c +++ b/librz/cons/cutf8.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015-2020 - pancake */ // Copypasta from http://www.linuxquestions.org/questions/programming-9/get-cursor-position-in-c-947833/ -#include +#include #if __UNIX__ #include @@ -191,15 +191,15 @@ static int cursor_position(const int tty, int *const rowptr, int *const colptr) } #endif -R_API bool r_cons_is_utf8(void) { +RZ_API bool rz_cons_is_utf8(void) { bool ret = false; #if UTF8_DETECT_ENV const char *keys[] = { "LC_ALL", "LC_CTYPE", "LANG", NULL }; const char **key = keys; for (; *key; key++) { - char *val = r_sys_getenv (*key); + char *val = rz_sys_getenv (*key); if (val) { - r_str_case (val, false); + rz_str_case (val, false); ret = strstr (val, "utf-8") || strstr (val, "utf8"); free (val); break; @@ -210,7 +210,7 @@ R_API bool r_cons_is_utf8(void) { #include const char *ctype = setlocale(LC_CTYPE, NULL); if ( (ctype != NULL) && (ctype = strchr(ctype, '.')) && ctype++ && - (r_str_casecmp(ctype, "UTF-8") == 0 || r_str_casecmp(ctype, "UTF8") == 0)) { + (rz_str_casecmp(ctype, "UTF-8") == 0 || rz_str_casecmp(ctype, "UTF8") == 0)) { return true; } #endif @@ -236,7 +236,7 @@ R_API bool r_cons_is_utf8(void) { return ret; } #else -R_API bool r_cons_is_utf8(void) { +RZ_API bool rz_cons_is_utf8(void) { #if __WINDOWS__ return GetConsoleOutputCP () == CP_UTF8; #else diff --git a/libr/cons/d/Makefile b/librz/cons/d/Makefile similarity index 91% rename from libr/cons/d/Makefile rename to librz/cons/d/Makefile index 1eca577c5f..0b1ea4d3a4 100644 --- a/libr/cons/d/Makefile +++ b/librz/cons/d/Makefile @@ -1,5 +1,5 @@ include ../../../config-user.mk -P=${DESTDIR}${DATADIR}/radare2/${VERSION}/cons +P=${DESTDIR}${DATADIR}/rizin/${VERSION}/cons all clean: diff --git a/libr/cons/d/ayu b/librz/cons/d/ayu similarity index 100% rename from libr/cons/d/ayu rename to librz/cons/d/ayu diff --git a/libr/cons/d/basic b/librz/cons/d/basic similarity index 100% rename from libr/cons/d/basic rename to librz/cons/d/basic diff --git a/libr/cons/d/behelit b/librz/cons/d/behelit similarity index 100% rename from libr/cons/d/behelit rename to librz/cons/d/behelit diff --git a/libr/cons/d/bold b/librz/cons/d/bold similarity index 100% rename from libr/cons/d/bold rename to librz/cons/d/bold diff --git a/libr/cons/d/bright b/librz/cons/d/bright similarity index 100% rename from libr/cons/d/bright rename to librz/cons/d/bright diff --git a/libr/cons/d/cga b/librz/cons/d/cga similarity index 100% rename from libr/cons/d/cga rename to librz/cons/d/cga diff --git a/libr/cons/d/consonance b/librz/cons/d/consonance similarity index 100% rename from libr/cons/d/consonance rename to librz/cons/d/consonance diff --git a/libr/cons/d/cutter b/librz/cons/d/cutter similarity index 100% rename from libr/cons/d/cutter rename to librz/cons/d/cutter diff --git a/libr/cons/d/dark b/librz/cons/d/dark similarity index 100% rename from libr/cons/d/dark rename to librz/cons/d/dark diff --git a/libr/cons/d/darkda b/librz/cons/d/darkda similarity index 100% rename from libr/cons/d/darkda rename to librz/cons/d/darkda diff --git a/libr/cons/d/defragger b/librz/cons/d/defragger similarity index 100% rename from libr/cons/d/defragger rename to librz/cons/d/defragger diff --git a/libr/cons/d/focus b/librz/cons/d/focus similarity index 100% rename from libr/cons/d/focus rename to librz/cons/d/focus diff --git a/libr/cons/d/gb b/librz/cons/d/gb similarity index 100% rename from libr/cons/d/gb rename to librz/cons/d/gb diff --git a/libr/cons/d/gentoo b/librz/cons/d/gentoo similarity index 100% rename from libr/cons/d/gentoo rename to librz/cons/d/gentoo diff --git a/libr/cons/d/lima b/librz/cons/d/lima similarity index 100% rename from libr/cons/d/lima rename to librz/cons/d/lima diff --git a/libr/cons/d/matrix b/librz/cons/d/matrix similarity index 100% rename from libr/cons/d/matrix rename to librz/cons/d/matrix diff --git a/libr/cons/d/meson.build b/librz/cons/d/meson.build similarity index 100% rename from libr/cons/d/meson.build rename to librz/cons/d/meson.build diff --git a/libr/cons/d/monokai b/librz/cons/d/monokai similarity index 100% rename from libr/cons/d/monokai rename to librz/cons/d/monokai diff --git a/libr/cons/d/ogray b/librz/cons/d/ogray similarity index 100% rename from libr/cons/d/ogray rename to librz/cons/d/ogray diff --git a/libr/cons/d/onedark b/librz/cons/d/onedark similarity index 100% rename from libr/cons/d/onedark rename to librz/cons/d/onedark diff --git a/libr/cons/d/pink b/librz/cons/d/pink similarity index 100% rename from libr/cons/d/pink rename to librz/cons/d/pink diff --git a/libr/cons/d/rasta b/librz/cons/d/rasta similarity index 100% rename from libr/cons/d/rasta rename to librz/cons/d/rasta diff --git a/libr/cons/d/sepia b/librz/cons/d/sepia similarity index 100% rename from libr/cons/d/sepia rename to librz/cons/d/sepia diff --git a/libr/cons/d/smyck b/librz/cons/d/smyck similarity index 100% rename from libr/cons/d/smyck rename to librz/cons/d/smyck diff --git a/libr/cons/d/solarized b/librz/cons/d/solarized similarity index 100% rename from libr/cons/d/solarized rename to librz/cons/d/solarized diff --git a/libr/cons/d/tango b/librz/cons/d/tango similarity index 100% rename from libr/cons/d/tango rename to librz/cons/d/tango diff --git a/libr/cons/d/twilight b/librz/cons/d/twilight similarity index 100% rename from libr/cons/d/twilight rename to librz/cons/d/twilight diff --git a/libr/cons/d/white b/librz/cons/d/white similarity index 100% rename from libr/cons/d/white rename to librz/cons/d/white diff --git a/libr/cons/d/white2 b/librz/cons/d/white2 similarity index 100% rename from libr/cons/d/white2 rename to librz/cons/d/white2 diff --git a/libr/cons/d/xvilka b/librz/cons/d/xvilka similarity index 100% rename from libr/cons/d/xvilka rename to librz/cons/d/xvilka diff --git a/libr/cons/d/zenburn b/librz/cons/d/zenburn similarity index 100% rename from libr/cons/d/zenburn rename to librz/cons/d/zenburn diff --git a/libr/cons/dietline.c b/librz/cons/dietline.c similarity index 85% rename from libr/cons/dietline.c rename to librz/cons/dietline.c index 0d47fc3f91..5c011f876d 100644 --- a/libr/cons/dietline.c +++ b/librz/cons/dietline.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ /* dietline is a lightweight and portable library similar to GNU readline */ -#include -#include +#include +#include #include #include #if __WINDOWS__ #include -#define printf(...) r_cons_win_printf (false, __VA_ARGS__) +#define printf(...) rz_cons_win_printf (false, __VA_ARGS__) #define USE_UTF8 1 -static int r_line_readchar_win(ut8 *s, int slen); +static int rz_line_readchar_win(ut8 *s, int slen); #else #include #include @@ -18,7 +18,7 @@ static int r_line_readchar_win(ut8 *s, int slen); #define USE_UTF8 1 #endif -static char *r_line_nullstr = ""; +static char *rz_line_nullstr = ""; static const char word_break_characters[] = "\t\n ~`!@#$%^&*()-_=+[]{}\\|;:\"'<>,./"; @@ -65,8 +65,8 @@ static void backward_kill_word(void) { } len = I.buffer.index - i + 1; free (I.clipboard); - I.clipboard = r_str_ndup (I.buffer.data + i, len); - r_line_clipboard_push (I.clipboard); + I.clipboard = rz_str_ndup (I.buffer.data + i, len); + rz_line_clipboard_push (I.clipboard); memmove (I.buffer.data + i, I.buffer.data + I.buffer.index, I.buffer.length - I.buffer.index + 1); I.buffer.length = strlen (I.buffer.data); @@ -93,8 +93,8 @@ static void backward_kill_Word(void) { } len = I.buffer.index - i + 1; free (I.clipboard); - I.clipboard = r_str_ndup (I.buffer.data + i, len); - r_line_clipboard_push (I.clipboard); + I.clipboard = rz_str_ndup (I.buffer.data + i, len); + rz_line_clipboard_push (I.clipboard); memmove (I.buffer.data + i, I.buffer.data + I.buffer.index, I.buffer.length - I.buffer.index + 1); I.buffer.length = strlen (I.buffer.data); @@ -115,8 +115,8 @@ static void kill_word(void) { } len = i - I.buffer.index + 1; free (I.clipboard); - I.clipboard = r_str_ndup (I.buffer.data + I.buffer.index, len); - r_line_clipboard_push (I.clipboard); + I.clipboard = rz_str_ndup (I.buffer.data + I.buffer.index, len); + rz_line_clipboard_push (I.clipboard); memmove (I.buffer.data + I.buffer.index, I.buffer.data + i, len); I.buffer.length = strlen (I.buffer.data); } @@ -134,8 +134,8 @@ static void kill_Word(void) { } len = i - I.buffer.index + 1; free (I.clipboard); - I.clipboard = r_str_ndup (I.buffer.data + I.buffer.index, len); - r_line_clipboard_push (I.clipboard); + I.clipboard = rz_str_ndup (I.buffer.data + I.buffer.index, len); + rz_line_clipboard_push (I.clipboard); memmove (I.buffer.data + I.buffer.index, I.buffer.data + i, len); I.buffer.length = strlen (I.buffer.data); } @@ -174,8 +174,8 @@ static void unix_word_rubout(void) { } len = I.buffer.index - i + 1; free (I.clipboard); - I.clipboard = r_str_ndup (I.buffer.data + i, len); - r_line_clipboard_push (I.clipboard); + I.clipboard = rz_str_ndup (I.buffer.data + i, len); + rz_line_clipboard_push (I.clipboard); memmove (I.buffer.data + i, I.buffer.data + I.buffer.index, I.buffer.length - I.buffer.index + 1); @@ -198,7 +198,7 @@ static int inithist(void) { } /* initialize history stuff */ -R_API int r_line_dietline_init(void) { +RZ_API int rz_line_dietline_init(void) { ZERO_FILL (I.completion); if (!inithist ()) { return false; @@ -209,16 +209,16 @@ R_API int r_line_dietline_init(void) { #if USE_UTF8 /* read utf8 char into 's', return the length in bytes */ -static int r_line_readchar_utf8(ut8 *s, int slen) { +static int rz_line_readchar_utf8(ut8 *s, int slen) { #if __WINDOWS__ - return r_line_readchar_win (s, slen); + return rz_line_readchar_win (s, slen); #else // TODO: add support for w32 ssize_t len, i; if (slen < 1) { return 0; } - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == -1) { return -1; } @@ -228,7 +228,7 @@ static int r_line_readchar_utf8(ut8 *s, int slen) { return t; } #endif - *s = r_cons_controlz (*s); + *s = rz_cons_controlz (*s); if (*s < 0x80) { len = 1; } else if ((s[0] & 0xe0) == 0xc0) { @@ -244,7 +244,7 @@ static int r_line_readchar_utf8(ut8 *s, int slen) { return -1; } for (i = 1; i < len; i++) { - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch != -1) { s[i] = ch; } @@ -258,7 +258,7 @@ static int r_line_readchar_utf8(ut8 *s, int slen) { #endif #if __WINDOWS__ -static int r_line_readchar_win(ut8 *s, int slen) { // this function handle the input in console mode +static int rz_line_readchar_win(ut8 *s, int slen) { // this function handle the input in console mode INPUT_RECORD irInBuf = { { 0 } }; BOOL ret, bCtrl = FALSE; DWORD mode, out; @@ -271,10 +271,10 @@ static int r_line_readchar_win(ut8 *s, int slen) { // this function handle the i GetConsoleMode (h, &mode); SetConsoleMode (h, new_mode); if (I.zerosep) { - bed = r_cons_sleep_begin (); + bed = rz_cons_sleep_begin (); DWORD rsz = 0; BOOL ret = ReadFile (h, s, 1, &rsz, NULL); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); SetConsoleMode (h, mode); if (!ret || rsz != 1) { return 0; @@ -282,20 +282,20 @@ static int r_line_readchar_win(ut8 *s, int slen) { // this function handle the i return 1; } do_it_again: - bed = r_cons_sleep_begin (); - if (r_cons_singleton()->term_xterm) { + bed = rz_cons_sleep_begin (); + if (rz_cons_singleton()->term_xterm) { ret = ReadFile (h, buf, 1, &out, NULL); } else { ret = ReadConsoleInput (h, &irInBuf, 1, &out); } - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (ret < 1) { return 0; } if (irInBuf.EventType == KEY_EVENT) { if (irInBuf.Event.KeyEvent.bKeyDown) { if (irInBuf.Event.KeyEvent.uChar.UnicodeChar) { - char *tmp = r_sys_conv_win_to_utf8_l ((PTCHAR)&irInBuf.Event.KeyEvent.uChar, 1); + char *tmp = rz_sys_conv_win_to_utf8_l ((PTCHAR)&irInBuf.Event.KeyEvent.uChar, 1); if (!tmp) { return 0; } @@ -314,7 +314,7 @@ do_it_again: case VK_DOWN: buf[idx++] = 'B'; break; case VK_RIGHT: buf[idx++] = 'C'; break; case VK_LEFT: buf[idx++] = 'D'; break; - case VK_PRIOR: buf[idx++] = '5'; break; // PAGE UP + case VK_PRzIOR: buf[idx++] = '5'; break; // PAGE UP case VK_NEXT: buf[idx++] = '6'; break; // PAGE DOWN case VK_DELETE: buf[idx++] = '3'; break; // SUPR KEY case VK_HOME: buf[idx++] = 'H'; break; // HOME KEY @@ -334,16 +334,16 @@ do_it_again: #endif -R_API int r_line_set_hist_callback(RLine *line, RLineHistoryUpCb up, RLineHistoryDownCb down) { +RZ_API int rz_line_set_hist_callback(RLine *line, RLineHistoryUpCb up, RLineHistoryDownCb down) { line->cb_history_up = up; line->cb_history_down = down; line->offset_hist_index = 0; line->file_hist_index = 0; - line->sdbshell_hist_iter = r_list_head (line->sdbshell_hist); + line->sdbshell_hist_iter = rz_list_head (line->sdbshell_hist); return 1; } -R_API int r_line_hist_cmd_up(RLine *line) { +RZ_API int rz_line_hist_cmd_up(RLine *line) { if (line->hist_up) { return line->hist_up (line->user); } @@ -358,7 +358,7 @@ R_API int r_line_hist_cmd_up(RLine *line) { return false; } -R_API int r_line_hist_cmd_down(RLine *line) { +RZ_API int rz_line_hist_cmd_down(RLine *line) { if (line->hist_down) { return line->hist_down (line->user); } @@ -382,7 +382,7 @@ R_API int r_line_hist_cmd_down(RLine *line) { return true; } -R_API int r_line_hist_add(const char *line) { +RZ_API int rz_line_hist_add(const char *line) { if (!line || !*line) { return false; } @@ -410,21 +410,21 @@ R_API int r_line_hist_add(const char *line) { return true; } -static int r_line_hist_up(void) { +static int rz_line_hist_up(void) { if (!I.cb_history_up) { - r_line_set_hist_callback (&I, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (&I, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); } return I.cb_history_up (&I); } -static int r_line_hist_down(void) { +static int rz_line_hist_down(void) { if (!I.cb_history_down) { - r_line_set_hist_callback (&I, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (&I, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); } return I.cb_history_down (&I); } -R_API const char *r_line_hist_get(int n) { +RZ_API const char *rz_line_hist_get(int n) { int i = 0; if (!I.history.data) { inithist (); @@ -440,21 +440,21 @@ R_API const char *r_line_hist_get(int n) { return NULL; } -R_API int r_line_hist_list(void) { +RZ_API int rz_line_hist_list(void) { int i = 0; if (!I.history.data) { inithist (); } if (I.history.data) { for (i = 0; i < I.history.size && I.history.data[i]; i++) { - const char *pad = r_str_pad (' ', 32 - strlen (I.history.data[i])); - r_cons_printf ("%s %s # !%d\n", I.history.data[i], pad, i); + const char *pad = rz_str_pad (' ', 32 - strlen (I.history.data[i])); + rz_cons_printf ("%s %s # !%d\n", I.history.data[i], pad, i); } } return i; } -R_API void r_line_hist_free(void) { +RZ_API void rz_line_hist_free(void) { int i; if (I.history.data) { for (i = 0; i < I.history.size; i++) { @@ -467,43 +467,43 @@ R_API void r_line_hist_free(void) { } /* load history from file. TODO: if file == NULL load from ~/..history or so */ -R_API int r_line_hist_load(const char *file) { +RZ_API int rz_line_hist_load(const char *file) { FILE *fd; - char buf[R_LINE_BUFSIZE], *path = r_str_home (file); + char buf[R_LINE_BUFSIZE], *path = rz_str_home (file); if (!path) { return false; } - if (!(fd = r_sandbox_fopen (path, "r"))) { + if (!(fd = rz_sandbox_fopen (path, "r"))) { free (path); return false; } while (fgets (buf, sizeof (buf), fd) != NULL) { - r_str_trim_tail (buf); - r_line_hist_add (buf); + rz_str_trim_tail (buf); + rz_line_hist_add (buf); } fclose (fd); free (path); return true; } -R_API int r_line_hist_save(const char *file) { +RZ_API int rz_line_hist_save(const char *file) { FILE *fd; int i, ret = false; if (!file || !*file) { return false; } - char *p, *path = r_str_home (file); + char *p, *path = rz_str_home (file); if (path != NULL) { - p = (char *) r_str_lastbut (path, R_SYS_DIR[0], NULL); // TODO: use fs + p = (char *) rz_str_lastbut (path, R_SYS_DIR[0], NULL); // TODO: use fs if (p) { *p = 0; - if (!r_sys_mkdirp (path)) { + if (!rz_sys_mkdirp (path)) { eprintf ("could not save history into %s\n", path); goto end; } *p = R_SYS_DIR[0]; } - fd = r_sandbox_fopen (path, "w"); + fd = rz_sandbox_fopen (path, "w"); if (fd != NULL) { if (I.history.data) { for (i = 0; i < I.history.index; i++) { @@ -522,15 +522,15 @@ end: return ret; } -R_API int r_line_hist_chop(const char *file, int limit) { +RZ_API int rz_line_hist_chop(const char *file, int limit) { /* TODO */ return 0; } static void selection_widget_draw(void) { - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); RSelWidget *sel_widget = I.sel_widget; - int y, pos_y, pos_x = r_str_ansi_len (I.prompt); + int y, pos_y, pos_x = rz_str_ansi_len (I.prompt); sel_widget->h = R_MIN (sel_widget->h, R_SELWIDGET_MAXH); for (y = 0; y < sel_widget->options_len; y++) { sel_widget->w = R_MAX (sel_widget->w, strlen (sel_widget->options[y])); @@ -538,9 +538,9 @@ static void selection_widget_draw(void) { if (sel_widget->direction == R_SELWIDGET_DIR_UP) { pos_y = cons->rows; } else { - pos_y = r_cons_get_cur_line (); + pos_y = rz_cons_get_cur_line (); if (pos_y + sel_widget->h > cons->rows) { - printf ("%s\n", r_str_pad('\n', sel_widget->h)); + printf ("%s\n", rz_str_pad('\n', sel_widget->h)); pos_y = cons->rows - sel_widget->h - 1; } } @@ -557,24 +557,24 @@ static void selection_widget_draw(void) { for (y = 0; y < sel_widget->h; y++) { if (sel_widget->direction == R_SELWIDGET_DIR_UP) { - r_cons_gotoxy (pos_x + 1, pos_y - y - 1); + rz_cons_gotoxy (pos_x + 1, pos_y - y - 1); } else { - r_cons_gotoxy (pos_x + 1, pos_y + y + 1); + rz_cons_gotoxy (pos_x + 1, pos_y + y + 1); } int scroll = R_MAX (0, sel_widget->selection - sel_widget->scroll); const char *option = y < sel_widget->options_len ? sel_widget->options[y + scroll] : ""; - r_cons_printf ("%s", sel_widget->selection == y + scroll ? selected_color : background_color); - r_cons_printf ("%-*.*s", sel_widget->w, sel_widget->w, option); + rz_cons_printf ("%s", sel_widget->selection == y + scroll ? selected_color : background_color); + rz_cons_printf ("%-*.*s", sel_widget->w, sel_widget->w, option); if (scrollbar && R_BETWEEN (scrollbar_y, y, scrollbar_y + scrollbar_l)) { - r_cons_memcat (Color_INVERT" "Color_INVERT_RESET, 10); + rz_cons_memcat (Color_INVERT" "Color_INVERT_RESET, 10); } else { - r_cons_memcat (" ", 1); + rz_cons_memcat (" ", 1); } } - r_cons_gotoxy (pos_x + I.buffer.length, pos_y); - r_cons_memcat (Color_RESET_BG, 5); - r_cons_flush (); + rz_cons_gotoxy (pos_x + I.buffer.length, pos_y); + rz_cons_memcat (Color_RESET_BG, 5); + rz_cons_flush (); } static void selection_widget_up(int steps) { @@ -622,9 +622,9 @@ static void selection_widget_down(int steps) { } static void print_rline_task(void *core) { - r_cons_clear_line (0); - r_cons_printf ("%s%s%s", Color_RESET, I.prompt, I.buffer.data); - r_cons_flush (); + rz_cons_clear_line (0); + rz_cons_printf ("%s%s%s", Color_RESET, I.prompt, I.buffer.data); + rz_cons_flush (); } static void selection_widget_erase(void) { @@ -634,10 +634,10 @@ static void selection_widget_erase(void) { sel_widget->selection = -1; selection_widget_draw (); R_FREE (I.sel_widget); - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); if (cons->event_resize && cons->event_data) { cons->event_resize (cons->event_data); - RCore *core = (RCore *)(cons->user); + RzCore *core = (RzCore *)(cons->user); if (core) { cons->cb_task_oneshot (&core->tasks, print_rline_task, core); } @@ -666,8 +666,8 @@ static void selection_widget_select(void) { } static void selection_widget_update(void) { - int argc = r_pvector_len (&I.completion.args); - const char **argv = (const char **)r_pvector_data (&I.completion.args); + int argc = rz_pvector_len (&I.completion.args); + const char **argv = (const char **)rz_pvector_data (&I.completion.args); if (argc == 0 || (argc == 1 && I.buffer.length >= strlen (argv[0]))) { selection_widget_erase (); return; @@ -688,24 +688,24 @@ static void selection_widget_update(void) { I.sel_widget->direction = R_SELWIDGET_DIR_UP; } selection_widget_draw (); - r_cons_flush (); + rz_cons_flush (); return; } -R_API void r_line_autocomplete(void) { +RZ_API void rz_line_autocomplete(void) { char *p; const char **argv = NULL; int argc = 0, i, j, plen, len = 0; bool opt = false; - int cols = (int)(r_cons_get_size (NULL) * 0.82); - RCons *cons = r_cons_singleton (); + int cols = (int)(rz_cons_get_size (NULL) * 0.82); + RzCons *cons = rz_cons_singleton (); /* prepare argc and argv */ if (I.completion.run) { I.completion.opt = false; I.completion.run (&I.completion, &I.buffer, I.prompt_type, I.completion.run_user); - argc = r_pvector_len (&I.completion.args); - argv = (const char **)r_pvector_data (&I.completion.args); + argc = rz_pvector_len (&I.completion.args); + argv = (const char **)rz_pvector_data (&I.completion.args); opt = I.completion.opt; } if (I.sel_widget && !I.sel_widget->complete_common) { @@ -714,12 +714,12 @@ R_API void r_line_autocomplete(void) { } if (opt) { - p = (char *) r_sub_str_lchr (I.buffer.data, 0, I.buffer.index, '='); + p = (char *) rz_sub_str_lchr (I.buffer.data, 0, I.buffer.index, '='); } else { - p = (char *) r_sub_str_lchr (I.buffer.data, 0, I.buffer.index, ' '); + p = (char *) rz_sub_str_lchr (I.buffer.data, 0, I.buffer.index, ' '); } if (!p) { - p = (char *) r_sub_str_lchr (I.buffer.data, 0, I.buffer.index, '@'); // HACK FOR r2 + p = (char *) rz_sub_str_lchr (I.buffer.data, 0, I.buffer.index, '@'); // HACK FOR r2 } if (p) { p++; @@ -730,7 +730,7 @@ R_API void r_line_autocomplete(void) { } /* autocomplete */ if (argc == 1) { - const char *end_word = r_sub_str_rchr (I.buffer.data, + const char *end_word = rz_sub_str_rchr (I.buffer.data, I.buffer.index, strlen (I.buffer.data), ' '); const char *t = end_word != NULL? end_word: I.buffer.data + I.buffer.index; @@ -804,7 +804,7 @@ R_API void r_line_autocomplete(void) { const int sep = 3; int slen, col = 10; #ifdef __WINDOWS__ - r_cons_win_printf (false, "%s%s\n", I.prompt, I.buffer.data); + rz_cons_win_printf (false, "%s%s\n", I.prompt, I.buffer.data); #else printf ("%s%s\n", I.prompt, I.buffer.data); #endif @@ -832,26 +832,26 @@ R_API void r_line_autocomplete(void) { fflush (stdout); } -R_API const char *r_line_readline(void) { - return r_line_readline_cb (NULL, NULL); +RZ_API const char *rz_line_readline(void) { + return rz_line_readline_cb (NULL, NULL); } static inline void rotate_kill_ring(void) { if (enable_yank_pop) { - I.buffer.index -= strlen (r_list_get_n (I.kill_ring, I.kill_ring_ptr)); + I.buffer.index -= strlen (rz_list_get_n (I.kill_ring, I.kill_ring_ptr)); I.buffer.data[I.buffer.index] = 0; I.kill_ring_ptr -= 1; if (I.kill_ring_ptr < 0) { I.kill_ring_ptr = I.kill_ring->length - 1; } - I.clipboard = r_list_get_n (I.kill_ring, I.kill_ring_ptr); + I.clipboard = rz_list_get_n (I.kill_ring, I.kill_ring_ptr); paste (); } } static inline void __delete_next_char(void) { if (I.buffer.index < I.buffer.length) { - int len = r_str_utf8_charsize (I.buffer.data + I.buffer.index); + int len = rz_str_utf8_charsize (I.buffer.data + I.buffer.index); memmove (I.buffer.data + I.buffer.index, I.buffer.data + I.buffer.index + len, strlen (I.buffer.data + I.buffer.index + 1) + 1); @@ -862,7 +862,7 @@ static inline void __delete_next_char(void) { static inline void __delete_prev_char(void) { if (I.buffer.index < I.buffer.length) { if (I.buffer.index > 0) { - size_t len = r_str_utf8_charsize_prev (I.buffer.data + I.buffer.index, I.buffer.index); + size_t len = rz_str_utf8_charsize_prev (I.buffer.data + I.buffer.index, I.buffer.index); I.buffer.index -= len; memmove (I.buffer.data + I.buffer.index, I.buffer.data + I.buffer.index + len, @@ -870,7 +870,7 @@ static inline void __delete_prev_char(void) { I.buffer.length -= len; } } else { - I.buffer.length -= r_str_utf8_charsize_last (I.buffer.data); + I.buffer.length -= rz_str_utf8_charsize_last (I.buffer.data); I.buffer.index = I.buffer.length; if (I.buffer.length < 0) { I.buffer.length = 0; @@ -889,15 +889,15 @@ static inline void delete_till_end(void) { } static void __print_prompt(void) { - RCons *cons = r_cons_singleton (); - int columns = r_cons_get_size (NULL) - 2; + RzCons *cons = rz_cons_singleton (); + int columns = rz_cons_get_size (NULL) - 2; int chars = R_MAX (1, strlen (I.buffer.data)); - int len, i, cols = R_MAX (1, columns - r_str_ansi_len (I.prompt) - 2); + int len, i, cols = R_MAX (1, columns - rz_str_ansi_len (I.prompt) - 2); if (cons->line->prompt_type == R_LINE_PROMPT_OFFSET) { - r_cons_gotoxy (0, cons->rows); - r_cons_flush (); + rz_cons_gotoxy (0, cons->rows); + rz_cons_flush (); } - r_cons_clear_line (0); + rz_cons_clear_line (0); printf ("\r%s%s", Color_RESET, I.prompt); fwrite (I.buffer.data, 1, R_MIN (cols, chars), stdout); printf ("\r%s", I.prompt); @@ -919,13 +919,13 @@ static void __print_prompt(void) { static inline void __move_cursor_right(void) { I.buffer.index = I.buffer.index < I.buffer.length - ? I.buffer.index + r_str_utf8_charsize (I.buffer.data + I.buffer.index) + ? I.buffer.index + rz_str_utf8_charsize (I.buffer.data + I.buffer.index) : I.buffer.length; } static inline void __move_cursor_left(void) { I.buffer.index = I.buffer.index - ? I.buffer.index - r_str_utf8_charsize_prev (I.buffer.data + I.buffer.index, I.buffer.index) + ? I.buffer.index - rz_str_utf8_charsize_prev (I.buffer.data + I.buffer.index, I.buffer.index) : 0; } @@ -1020,7 +1020,7 @@ static inline void vi_cmd_e(void) { } static void __update_prompt_color (void) { - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); const char *BEGIN = "", *END = ""; if (cons->context->color_mode) { if (I.prompt_mode) { @@ -1038,9 +1038,9 @@ static void __update_prompt_color (void) { } END = cons->context->pal.reset; } - char *prompt = r_str_escape (I.prompt); // remote the color + char *prompt = rz_str_escape (I.prompt); // remote the color free (I.prompt); - I.prompt = r_str_newf ("%s%s%s", BEGIN, prompt, END); + I.prompt = rz_str_newf ("%s%s%s", BEGIN, prompt, END); } static void __vi_mode(void) { @@ -1058,14 +1058,14 @@ static void __vi_mode(void) { __update_prompt_color (); break; } - ch = r_cons_readchar (); + ch = rz_cons_readchar (); while (IS_DIGIT (ch)) { // handle commands like 3b if (ch == '0' && rep == 0) { // to handle the command 0 break; } int tmp = ch - '0'; rep = (rep * 10) + tmp; - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } rep = rep > 0 ? rep : 1; @@ -1086,7 +1086,7 @@ static void __vi_mode(void) { delete_till_end (); break; case 'r': { - char c = r_cons_readchar (); + char c = rz_cons_readchar (); I.buffer.data[I.buffer.index] = c; } break; case 'x': @@ -1096,11 +1096,11 @@ static void __vi_mode(void) { case 'c': I.vi_mode = INSERT_MODE; // goto insert mode case 'd': { - char c = r_cons_readchar (); + char c = rz_cons_readchar (); while (rep--) { switch (c) { case 'i': { - char t = r_cons_readchar (); + char t = rz_cons_readchar (); if (t == 'w') { // diw kill_word (); backward_kill_word (); @@ -1215,13 +1215,13 @@ static void __vi_mode(void) { vi_cmd_w (); } break; default: // escape key - ch = tolower (r_cons_arrow_to_hjkl (ch)); + ch = tolower (rz_cons_arrow_to_hjkl (ch)); switch (ch) { case 'k': // up - r_line_hist_up (); + rz_line_hist_up (); break; case 'j': // down - r_line_hist_down (); + rz_line_hist_down (); break; case 'l': // right __move_cursor_right (); @@ -1238,7 +1238,7 @@ static void __vi_mode(void) { } } -R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { +RZ_API const char *rz_line_readline_cb(RLineReadCallback cb, void *user) { int rows; const char *gcomp_line = ""; static int gcomp_idx = 0; @@ -1251,7 +1251,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { int ch = 0, key, i = 0; /* grep completion */ char *tmp_ed_cmd, prev = 0; int prev_buflen = -1; - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); if (!I.hud || (I.hud && !I.hud->activate)) { I.buffer.index = I.buffer.length = 0; @@ -1275,20 +1275,20 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { if (!fgets (I.buffer.data, R_LINE_BUFSIZE, stdin)) { return NULL; } - return (*I.buffer.data)? I.buffer.data: r_line_nullstr; + return (*I.buffer.data)? I.buffer.data: rz_line_nullstr; } memset (&buf, 0, sizeof buf); - r_cons_set_raw (1); + rz_cons_set_raw (1); if (I.echo) { __print_prompt (); } - r_cons_break_push (NULL, NULL); - r_cons_enable_mouse (I.hud); + rz_cons_break_push (NULL, NULL); + rz_cons_enable_mouse (I.hud); for (;;) { yank_flag = 0; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } I.buffer.data[I.buffer.length] = '\0'; @@ -1300,35 +1300,35 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } } #if USE_UTF8 - utflen = r_line_readchar_utf8 ((ut8 *) buf, sizeof (buf)); + utflen = rz_line_readchar_utf8 ((ut8 *) buf, sizeof (buf)); if (utflen < 1) { - r_cons_break_pop (); + rz_cons_break_pop (); return NULL; } buf[utflen] = 0; #else #if __WINDOWS__ { - int len = r_line_readchar_win ((ut8 *)buf, sizeof (buf)); + int len = rz_line_readchar_win ((ut8 *)buf, sizeof (buf)); if (len < 1) { - r_cons_break_pop (); + rz_cons_break_pop (); return NULL; } buf[len] = 0; } #else - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (ch == -1) { - r_cons_break_pop (); + rz_cons_break_pop (); return NULL; } buf[0] = ch; #endif #endif if (I.echo) { - r_cons_clear_line (0); + rz_cons_clear_line (0); } - (void)r_cons_get_size (&rows); + (void)rz_cons_get_size (&rows); switch (*buf) { case 0: // control-space /* ignore atm */ @@ -1387,8 +1387,8 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { if (I.echo) { printf ("^D\n"); } - r_cons_set_raw (false); - r_cons_break_pop (); + rz_cons_set_raw (false); + rz_cons_break_pop (); return NULL; } if (I.buffer.index < I.buffer.length) { @@ -1396,7 +1396,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } break; case 10:// ^J -- ignore - r_cons_break_pop (); + rz_cons_break_pop (); return I.buffer.data; case 11:// ^K I.buffer.data[I.buffer.index] = '\0'; @@ -1428,7 +1428,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { case 21:// ^U - cut free (I.clipboard); I.clipboard = strdup (I.buffer.data); - r_line_clipboard_push (I.clipboard); + rz_line_clipboard_push (I.clipboard); I.buffer.data[0] = '\0'; I.buffer.length = 0; I.buffer.index = 0; @@ -1447,7 +1447,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { if (hClipBoard) { clipText = GlobalLock (hClipBoard); if (clipText) { - char *txt = r_sys_conv_win_to_utf8 (clipText); + char *txt = rz_sys_conv_win_to_utf8 (clipText); if (!txt) { R_LOG_ERROR ("Failed to allocate memory\n"); break; @@ -1506,7 +1506,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { gcomp_idx--; } } else { - r_line_hist_down (); + rz_line_hist_down (); } break; case 16:// ^p @@ -1520,7 +1520,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } else if (gcomp) { gcomp_idx++; } else { - r_line_hist_up (); + rz_line_hist_up (); } break; case 27: // esc-5b-41-00-00 alt/meta key @@ -1532,7 +1532,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } } else { #endif - buf[0] = r_cons_readchar_timeout (50); + buf[0] = rz_cons_readchar_timeout (50); #if __WINDOWS__ } #endif @@ -1590,9 +1590,9 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { break; default: if (I.vtmode == 2) { - buf[1] = r_cons_readchar_timeout (50); + buf[1] = rz_cons_readchar_timeout (50); if (buf[1] == -1) { // alt+e - r_cons_break_pop (); + rz_cons_break_pop (); __print_prompt (); continue; } @@ -1602,16 +1602,16 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { case '3': // supr __delete_next_char (); if (I.vtmode == 2) { - buf[1] = r_cons_readchar (); + buf[1] = rz_cons_readchar (); if (buf[1] == -1) { - r_cons_break_pop (); + rz_cons_break_pop (); return NULL; } } break; case '5': // pag up if (I.vtmode == 2) { - buf[1] = r_cons_readchar (); + buf[1] = rz_cons_readchar (); } if (I.hud) { I.hud->top_entry_n -= (rows - 1); @@ -1626,7 +1626,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { break; case '6': // pag down if (I.vtmode == 2) { - buf[1] = r_cons_readchar (); + buf[1] = rz_cons_readchar (); } if (I.hud) { I.hud->top_entry_n += (rows - 1); @@ -1640,7 +1640,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } break; case '9': // handle mouse wheel - key = r_cons_readchar (); + key = rz_cons_readchar (); cons->mouse_event = 1; if (key == '6') { // up if (I.hud && I.hud->top_entry_n + 1 < I.hud->current_entry_n) { @@ -1651,7 +1651,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { I.hud->top_entry_n++; } } - while (r_cons_readchar () != 'M') {} + while (rz_cons_readchar () != 'M') {} break; /* arrows */ case 'A': // up arrow @@ -1664,8 +1664,8 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { selection_widget_draw (); } else if (gcomp) { gcomp_idx++; - } else if (r_line_hist_up () == -1) { - r_cons_break_pop (); + } else if (rz_line_hist_up () == -1) { + rz_cons_break_pop (); return NULL; } break; @@ -1681,8 +1681,8 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { if (gcomp_idx > 0) { gcomp_idx--; } - } else if (r_line_hist_down () == -1) { - r_cons_break_pop (); + } else if (rz_line_hist_down () == -1) { + rz_cons_break_pop (); return NULL; } break; @@ -1694,13 +1694,13 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { break; case 0x31: // control + arrow if (I.vtmode == 2) { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (ch == 0x7e) { // HOME in screen/tmux // corresponding END is 0x34 below (the 0x7e is ignored there) I.buffer.index = 0; break; } - r_cons_readchar (); + rz_cons_readchar (); } #if __WINDOWS__ else { @@ -1749,10 +1749,10 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } break; } - r_cons_set_raw (1); + rz_cons_set_raw (1); break; case 0x37: // HOME xrvt-unicode - r_cons_readchar (); + rz_cons_readchar (); case 0x48: // HOME if (I.sel_widget) { selection_widget_up (I.sel_widget->options_len - 1); @@ -1763,7 +1763,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { break; case 0x34: // END case 0x38: // END xrvt-unicode - r_cons_readchar (); + rz_cons_readchar (); case 0x46: // END if (I.sel_widget) { selection_widget_down (I.sel_widget->options_len - 1); @@ -1802,7 +1802,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { I.hud->top_entry_n = 0; } } else { - r_line_autocomplete (); + rz_line_autocomplete (); } break; case 13: // enter @@ -1879,7 +1879,7 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } if (I.sel_widget && I.buffer.length != prev_buflen) { prev_buflen = I.buffer.length; - r_line_autocomplete (); + rz_line_autocomplete (); } prev = buf[0]; if (I.echo) { @@ -1914,9 +1914,9 @@ R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user) { } } _end: - r_cons_break_pop (); - r_cons_set_raw (0); - r_cons_enable_mouse (mouse_status); + rz_cons_break_pop (); + rz_cons_set_raw (0); + rz_cons_enable_mouse (mouse_status); if (I.echo) { printf ("\r%s%s\n", I.prompt, I.buffer.data); fflush (stdout); @@ -1927,8 +1927,8 @@ _end: // should be here or not? if (!memcmp (I.buffer.data, "!history", 8)) { // if (I.buffer.data[0]=='!' && I.buffer.data[1]=='\0') { - r_line_hist_list (); - return r_line_nullstr; + rz_line_hist_list (); + return rz_line_nullstr; } - return I.buffer.data[0] != '\0'? I.buffer.data: r_line_nullstr; + return I.buffer.data[0] != '\0'? I.buffer.data: rz_line_nullstr; } diff --git a/libr/cons/editor.c b/librz/cons/editor.c similarity index 79% rename from libr/cons/editor.c rename to librz/cons/editor.c index 8dbba5b10d..cc24a3641a 100644 --- a/libr/cons/editor.c +++ b/librz/cons/editor.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2018 - pancake */ -#include -#define I r_cons_singleton () +#include +#define I rz_cons_singleton () /* TODO: remove global vars */ static char *lines = NULL; @@ -11,8 +11,8 @@ static int bytes, nlines, _n = 0; static void setnewline(int old) { snprintf (prompt, sizeof (prompt), "%d: ", _n); - r_line_set_prompt (prompt); - strncpy (I->line->buffer.data, r_str_word_get0 (lines, _n), + rz_line_set_prompt (prompt); + strncpy (I->line->buffer.data, rz_str_word_get0 (lines, _n), sizeof (I->line->buffer.data) - 1); I->line->buffer.data[sizeof (I->line->buffer.data) - 1] = '\0'; I->line->buffer.index = I->line->buffer.length = strlen (I->line->buffer.data); @@ -24,7 +24,7 @@ static void saveline(int n, const char *str) { if (!str) { return; } - out = r_str_word_get0set (lines, bytes, _n, str, &bytes); + out = rz_str_word_get0set (lines, bytes, _n, str, &bytes); free (lines); lines = out; } @@ -52,7 +52,7 @@ static void filesave(void) { buf[0] = 0; if (fgets (buf, sizeof (buf), stdin)) { if (buf[0]) { - r_str_trim_tail (buf); + rz_str_trim_tail (buf); free (path); path = strdup (buf); } @@ -65,15 +65,15 @@ static void filesave(void) { } } } - if (r_file_dump (path, (const ut8 *)lines, bytes, 0)) { + if (rz_file_dump (path, (const ut8 *)lines, bytes, 0)) { eprintf ("File '%s' saved (%d byte(s))\n", path, bytes); } else { eprintf ("Cannot save file\n"); } - nlines = r_str_split (lines, '\n'); + nlines = rz_str_split (lines, '\n'); } -R_API char *r_cons_editor(const char *file, const char *str) { +RZ_API char *rz_cons_editor(const char *file, const char *str) { const char *line; _n = 0; if (I->cb_editor) { @@ -84,14 +84,14 @@ R_API char *r_cons_editor(const char *file, const char *str) { path = strdup (file); bytes = 0; size_t sz = 0; - lines = r_file_slurp (file, &sz); + lines = rz_file_slurp (file, &sz); bytes = (int)sz; if (!lines) { eprintf ("Failed to load '%s'.\n", file); R_FREE (path); return NULL; } - nlines = r_str_split (lines, '\n'); + nlines = rz_str_split (lines, '\n'); eprintf ("Loaded %d lines on %d byte(s)\n", (nlines? (nlines - 1): 0), bytes); } else { @@ -103,8 +103,8 @@ R_API char *r_cons_editor(const char *file, const char *str) { for (;;) { setnewline (_n); snprintf (prompt, sizeof (prompt), "%d: ", _n); - r_line_set_prompt (prompt); - line = r_line_readline (); + rz_line_set_prompt (prompt); + line = rz_line_readline (); saveline (_n, line); _n++; if (!line) { diff --git a/libr/cons/grep.c b/librz/cons/grep.c similarity index 81% rename from libr/cons/grep.c rename to librz/cons/grep.c index 28b71cbaec..e08a5d5795 100644 --- a/libr/cons/grep.c +++ b/librz/cons/grep.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include -#include +#include +#include #include -#define I(x) r_cons_singleton ()->x +#define I(x) rz_cons_singleton ()->x static char *strchr_ns (char *s, const char ch) { char *p = strchr (s, ch); @@ -60,12 +60,12 @@ static const char *help_detail_tilde[] = { }; /* TODO: remove globals */ -static RList *sorted_lines = NULL; -static RList *unsorted_lines = NULL; +static RzList *sorted_lines = NULL; +static RzList *unsorted_lines = NULL; static int sorted_column = -1; -R_API void r_cons_grep_help(void) { - r_cons_cmd_help (help_detail_tilde, true); +RZ_API void rz_cons_grep_help(void) { + rz_cons_cmd_help (help_detail_tilde, true); } #define R_CONS_GREP_BUFSIZE 4096 @@ -79,8 +79,8 @@ static void parse_grep_expression(const char *str) { if (!str || !*str) { return; } - RCons *cons = r_cons_singleton (); - RConsGrep *grep = &cons->context->grep; + RzCons *cons = rz_cons_singleton (); + RzConsGrep *grep = &cons->context->grep; sorted_column = 0; bool first = true; while (*str) { @@ -177,7 +177,7 @@ static void parse_grep_expression(const char *str) { str++; } else if (*str == '?') { cons->filter = true; - r_cons_grep_help (); + rz_cons_grep_help (); return; } break; @@ -190,7 +190,7 @@ while_end: len = strlen (str) - 1; if (len > R_CONS_GREP_BUFSIZE - 1) { - eprintf ("r_cons_grep: too long!\n"); + eprintf ("rz_cons_grep: too long!\n"); return; } if (len > 0 && str[len] == '?') { @@ -249,13 +249,13 @@ while_end: default: if (!num_is_parsed) { if (is_range) { - range_end = r_num_get (cons->num, ptr2); + range_end = rz_num_get (cons->num, ptr2); // check for bad value, if range_end == 0, we check if ptr2 == '0' if (range_end == 0 && *ptr != '0') { range_end = -1; // this allow [n- ] } } else { - range_begin = range_end = r_num_get (cons->num, ptr2); + range_begin = range_end = rz_num_get (cons->num, ptr2); } num_is_parsed = 1; } @@ -271,18 +271,18 @@ while_end: char *p, *token = ptr2 + 1; p = strstr (token, ".."); if (!p) { - grep->line = r_num_get (cons->num, ptr2 + 1); + grep->line = rz_num_get (cons->num, ptr2 + 1); grep->range_line = 0; } else { *p = '\0'; grep->range_line = 1; if (*token) { - grep->f_line = r_num_get (cons->num, token); + grep->f_line = rz_num_get (cons->num, token); } else { grep->f_line = 0; } if (p[2]) { - grep->l_line = r_num_get (cons->num, p + 2); + grep->l_line = rz_num_get (cons->num, p + 2); } else { grep->l_line = 0; } @@ -335,7 +335,7 @@ while_end: static char *find_next_intgrep(char *cmd, const char *quotes) { char *p; do { - p = (char *)r_str_firstbut (cmd, '~', quotes); + p = (char *)rz_str_firstbut (cmd, '~', quotes); if (!p) { break; } @@ -369,9 +369,9 @@ static char *preprocess_filter_expr(char *cmd, const char *quotes) { } len = strlen (p1); - if (len > 4 && r_str_endswith (p1, "~?") && p1[len - 3] != '\\') { + if (len > 4 && rz_str_endswith (p1, "~?") && p1[len - 3] != '\\') { p1[len - 2] = '\0'; - ns = r_str_append (ns, "?"); + ns = rz_str_append (ns, "?"); } *p1 = '\0'; // remove grep part from cmd @@ -379,43 +379,43 @@ static char *preprocess_filter_expr(char *cmd, const char *quotes) { i = 0; // parse words between '~' while ((p2 = find_next_intgrep (p1 + 1, quotes))) { - ns = r_str_append (ns, strsep); - ns = r_str_appendlen (ns, p1 + 1, (int)(p2 - p1 - 1)); + ns = rz_str_append (ns, strsep); + ns = rz_str_appendlen (ns, p1 + 1, (int)(p2 - p1 - 1)); p1 = p2; strsep = ","; i++; } if (i > 0) { - ns = r_str_append (ns, ","); + ns = rz_str_append (ns, ","); } - ns = r_str_append (ns, p1 + 1); + ns = rz_str_append (ns, p1 + 1); return ns; } -R_API void r_cons_grep_parsecmd(char *cmd, const char *quotestr) { - r_return_if_fail (cmd && quotestr); +RZ_API void rz_cons_grep_parsecmd(char *cmd, const char *quotestr) { + rz_return_if_fail (cmd && quotestr); char *ptr = preprocess_filter_expr (cmd, quotestr); if (ptr) { - r_str_trim (cmd); + rz_str_trim (cmd); parse_grep_expression (ptr); free (ptr); } } -R_API char *r_cons_grep_strip(char *cmd, const char *quotestr) { +RZ_API char *rz_cons_grep_strip(char *cmd, const char *quotestr) { char *ptr = NULL; if (cmd) { ptr = preprocess_filter_expr (cmd, quotestr); - r_str_trim (cmd); + rz_str_trim (cmd); } return ptr; } -R_API void r_cons_grep_process(char * grep) { +RZ_API void rz_cons_grep_process(char * grep) { if (grep) { parse_grep_expression (grep); free (grep); @@ -425,22 +425,22 @@ R_API void r_cons_grep_process(char * grep) { static int cmp(const void *a, const void *b) { char *da = NULL; char *db = NULL; - const char *ca = r_str_trim_head_ro (a); - const char *cb = r_str_trim_head_ro (b); + const char *ca = rz_str_trim_head_ro (a); + const char *cb = rz_str_trim_head_ro (b); if (!a || !b) { return (int) (size_t) ((char*) a - (char*) b); } if (sorted_column > 0) { da = strdup (ca); db = strdup (cb); - int colsa = r_str_word_set0 (da); - int colsb = r_str_word_set0 (db); - ca = (colsa > sorted_column)? r_str_word_get0 (da, sorted_column): ""; - cb = (colsb > sorted_column)? r_str_word_get0 (db, sorted_column): ""; + int colsa = rz_str_word_set0 (da); + int colsb = rz_str_word_set0 (db); + ca = (colsa > sorted_column)? rz_str_word_get0 (da, sorted_column): ""; + cb = (colsb > sorted_column)? rz_str_word_get0 (db, sorted_column): ""; } if (IS_DIGIT (*ca) && IS_DIGIT (*cb)) { - ut64 na = r_num_get (NULL, ca); - ut64 nb = r_num_get (NULL, cb); + ut64 na = rz_num_get (NULL, ca); + ut64 nb = rz_num_get (NULL, cb); int ret = (na > nb) - (na < nb); free (da); free (db); @@ -457,11 +457,11 @@ static int cmp(const void *a, const void *b) { return strcmp (a, b); } -R_API void r_cons_grepbuf(void) { - RCons *cons = r_cons_singleton (); +RZ_API void rz_cons_grepbuf(void) { + RzCons *cons = rz_cons_singleton (); const char *buf = cons->context->buffer; const int len = cons->context->buffer_len; - RConsGrep *grep = &cons->context->grep; + RzConsGrep *grep = &cons->context->grep; const char *in = buf; int ret, total_lines = 0, buffer_len = 0, l = 0, tl = 0; bool show = false; @@ -481,7 +481,7 @@ R_API void r_cons_grepbuf(void) { if (grep->zoom) { char *in = calloc (cons->context->buffer_len + 2, 4); strcpy (in, cons->context->buffer); - char *out = r_str_scale (in, grep->zoom * 2, grep->zoomy?grep->zoomy:grep->zoom); + char *out = rz_str_scale (in, grep->zoom * 2, grep->zoomy?grep->zoomy:grep->zoom); if (out) { free (cons->context->buffer); cons->context->buffer = out; @@ -501,7 +501,7 @@ R_API void r_cons_grepbuf(void) { cons->context->buffer_len = strlen (u); cons->context->buffer_sz = cons->context->buffer_len + 1; grep->json = 0; - r_cons_newline (); + rz_cons_newline (); } R_FREE (grep->json_path); } else { @@ -514,10 +514,10 @@ R_API void r_cons_grepbuf(void) { NULL }; char *bb = strdup (buf); - r_str_ansi_filter (bb, NULL, NULL, -1); + rz_str_ansi_filter (bb, NULL, NULL, -1); char *out = (cons->context->grep.human) - ? r_print_json_human (bb) - : r_print_json_indent (bb, I (context->color_mode), " ", palette); + ? rz_print_json_human (bb) + : rz_print_json_indent (bb, I (context->color_mode), " ", palette); free (bb); if (!out) { return; @@ -529,10 +529,10 @@ R_API void r_cons_grepbuf(void) { grep->json = 0; if (grep->hud) { grep->hud = false; - r_cons_hud_string (cons->context->buffer); + rz_cons_hud_string (cons->context->buffer); } else if (grep->less) { grep->less = 0; - r_cons_less_str (cons->context->buffer, NULL); + rz_cons_less_str (cons->context->buffer, NULL); } } return; @@ -542,13 +542,13 @@ R_API void r_cons_grepbuf(void) { int less = grep->less; grep->less = 0; if (less == 2) { - char *res = r_cons_hud_string (buf); + char *res = rz_cons_hud_string (buf); if (res) { - r_cons_println (res); + rz_cons_println (res); free (res); } } else { - r_cons_less_str (buf, NULL); + rz_cons_less_str (buf, NULL); cons->context->buffer_len = 0; if (cons->context->buffer) { cons->context->buffer[0] = 0; @@ -562,7 +562,7 @@ R_API void r_cons_grepbuf(void) { cons->context->buffer = malloc (cons->context->buffer_len); cons->context->buffer[0] = 0; } - RStrBuf *ob = r_strbuf_new (""); + RStrBuf *ob = rz_strbuf_new (""); // if we modify cons->lines we should update I.context->buffer too cons->lines = 0; // used to count lines and change negative grep.line values @@ -598,16 +598,16 @@ R_API void r_cons_grepbuf(void) { } l = p - in; if (l > 0) { - char *tline = r_str_ndup (in, l); + char *tline = rz_str_ndup (in, l); if (cons->grep_color) { tl = l; } else { - tl = r_str_ansi_filter (tline, NULL, NULL, l); + tl = rz_str_ansi_filter (tline, NULL, NULL, l); } if (tl < 0) { ret = -1; } else { - ret = r_cons_grep_line (tline, tl); + ret = rz_cons_grep_line (tline, tl); if (!grep->range_line) { if (grep->line == cons->lines) { show = true; @@ -625,24 +625,24 @@ R_API void r_cons_grepbuf(void) { } if (ret > 0) { if (show) { - char *str = r_str_ndup (tline, ret); + char *str = rz_str_ndup (tline, ret); if (cons->grep_highlight) { int i; for (i = 0; i < grep->nstrings; i++) { - char *newstr = r_str_newf (Color_INVERT"%s"Color_RESET, grep->strings[i]); + char *newstr = rz_str_newf (Color_INVERT"%s"Color_RESET, grep->strings[i]); if (str && newstr) { if (grep->icase) { - str = r_str_replace_icase (str, grep->strings[i], newstr, 1, 1); + str = rz_str_replace_icase (str, grep->strings[i], newstr, 1, 1); } else { - str = r_str_replace (str, grep->strings[i], newstr, 1); + str = rz_str_replace (str, grep->strings[i], newstr, 1); } } free (newstr); } } if (str) { - r_strbuf_append (ob, str); - r_strbuf_append (ob, "\n"); + rz_strbuf_append (ob, str); + rz_strbuf_append (ob, "\n"); } buffer_len += ret + 1; free (str); @@ -662,7 +662,7 @@ R_API void r_cons_grepbuf(void) { } } - cons->context->buffer_len = r_strbuf_length (ob); + cons->context->buffer_len = rz_strbuf_length (ob); if (grep->counter) { int cnt = grep->charCounter? strlen (cons->context->buffer): cons->lines; if (cons->context->buffer_len < 10) { @@ -671,25 +671,25 @@ R_API void r_cons_grepbuf(void) { snprintf (cons->context->buffer, cons->context->buffer_len, "%d\n", cnt); cons->context->buffer_len = strlen (cons->context->buffer); cons->num->value = cons->lines; - r_strbuf_free (ob); + rz_strbuf_free (ob); return; } - const int ob_len = r_strbuf_length (ob); + const int ob_len = rz_strbuf_length (ob); if (ob_len >= cons->context->buffer_sz) { cons->context->buffer_sz = ob_len + 1; - cons->context->buffer = r_strbuf_drain (ob); + cons->context->buffer = rz_strbuf_drain (ob); } else { - memcpy (cons->context->buffer, r_strbuf_getbin (ob, NULL), ob_len); + memcpy (cons->context->buffer, rz_strbuf_getbin (ob, NULL), ob_len); cons->context->buffer[ob_len] = 0; - r_strbuf_free (ob); + rz_strbuf_free (ob); } cons->context->buffer_len = ob_len; if (grep->sort != -1) { #define INSERT_LINES(list)\ do {\ - r_list_foreach (list, iter, str) {\ + rz_list_foreach (list, iter, str) {\ int len = strlen (str);\ memcpy (ptr, str, len);\ memcpy (ptr + len, "\n", 2);\ @@ -699,28 +699,28 @@ R_API void r_cons_grepbuf(void) { }\ while (false) - RListIter *iter; + RzListIter *iter; int nl = 0; char *ptr = cons->context->buffer; char *str; sorted_column = grep->sort; - r_list_sort (sorted_lines, cmp); + rz_list_sort (sorted_lines, cmp); if (grep->sort_invert) { - r_list_reverse (sorted_lines); + rz_list_reverse (sorted_lines); } INSERT_LINES (unsorted_lines); INSERT_LINES (sorted_lines); cons->lines = nl; - r_list_free (sorted_lines); + rz_list_free (sorted_lines); sorted_lines = NULL; - r_list_free (unsorted_lines); + rz_list_free (unsorted_lines); unsorted_lines = NULL; } } -R_API int r_cons_grep_line(char *buf, int len) { - RCons *cons = r_cons_singleton (); - RConsGrep *grep = &cons->context->grep; +RZ_API int rz_cons_grep_line(char *buf, int len) { + RzCons *cons = rz_cons_singleton (); + RzConsGrep *grep = &cons->context->grep; const char *delims = " |,;=\t"; char *tok = NULL; bool hit = grep->neg; @@ -742,14 +742,14 @@ R_API int r_cons_grep_line(char *buf, int len) { if (grep->nstrings > 0) { int ampfail = grep->amp; if (grep->icase) { - r_str_case (in, false); + rz_str_case (in, false); } for (i = 0; i < grep->nstrings; i++) { char *str = grep->strings[i]; if (grep->icase) { - r_str_case (str, false); + rz_str_case (str, false); } - const char *p = r_strstr_ansi (in, grep->strings[i]); + const char *p = rz_strstr_ansi (in, grep->strings[i]); if (!p) { ampfail = 0; continue; @@ -810,7 +810,7 @@ R_API int r_cons_grep_line(char *buf, int len) { } outlen = outlen > 0? outlen - 1: 0; if (outlen > len) { // should never happen - eprintf ("r_cons_grep_line: wtf, how you reach this?\n"); + eprintf ("rz_cons_grep_line: wtf, how you reach this?\n"); free (in); free (out); return -1; @@ -827,15 +827,15 @@ R_API int r_cons_grep_line(char *buf, int len) { char ch = buf[len]; buf[len] = 0; if (!sorted_lines) { - sorted_lines = r_list_newf (free); + sorted_lines = rz_list_newf (free); } if (!unsorted_lines) { - unsorted_lines = r_list_newf (free); + unsorted_lines = rz_list_newf (free); } if (cons->lines >= grep->sort_row) { - r_list_append (sorted_lines, strdup (buf)); + rz_list_append (sorted_lines, strdup (buf)); } else { - r_list_append (unsorted_lines, strdup (buf)); + rz_list_append (unsorted_lines, strdup (buf)); } buf[len] = ch; } @@ -843,7 +843,7 @@ R_API int r_cons_grep_line(char *buf, int len) { return len; } -R_API void r_cons_grep(const char *grep) { +RZ_API void rz_cons_grep(const char *grep) { parse_grep_expression (grep); - r_cons_grepbuf (); + rz_cons_grepbuf (); } diff --git a/libr/cons/html.c b/librz/cons/html.c similarity index 75% rename from libr/cons/html.c rename to librz/cons/html.c index 094f71f6b5..3412a5f922 100644 --- a/libr/cons/html.c +++ b/librz/cons/html.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include +#include static bool gethtmlrgb(const char *str, char *buf) { ut8 r = 0, g = 0, b = 0; - if (r_cons_rgb_parse (str, &r, &g, &b, 0)) { + if (rz_cons_rgb_parse (str, &r, &g, &b, 0)) { sprintf (buf, "#%02x%02x%02x", r, g, b); return true; } @@ -28,8 +28,8 @@ static const char *gethtmlcolor(const char ptrch) { return ""; } -// TODO: move into r_util/str -R_API char *r_cons_html_filter(const char *ptr, int *newlen) { +// TODO: move into rz_util/str +RZ_API char *rz_cons_html_filter(const char *ptr, int *newlen) { const char *str = ptr; int esc = 0; int len = 0; @@ -44,33 +44,33 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { if (!ptr) { return NULL; } - RStrBuf *res = r_strbuf_new (""); + RStrBuf *res = rz_strbuf_new (""); if (!res) { return NULL; } for (; ptr[0]; ptr = ptr + 1) { if (esc == 0 && ptr[0] != 0x1b && need_to_set) { if (has_set) { - r_strbuf_append (res, ""); + rz_strbuf_append (res, ""); has_set = false; } if (!need_to_clear) { first_style = true; - r_strbuf_append (res, "": "'>"); + rz_strbuf_append (res, first_style? ">": "'>"); has_set = true; } need_to_clear = false; @@ -78,38 +78,38 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { } if (ptr[0] == '\n') { tmp = (int) (size_t) (ptr - str); - r_strbuf_append_n (res, str, tmp); + rz_strbuf_append_n (res, str, tmp); if (!ptr[1]) { // write new line if it's the end of the output - r_strbuf_append (res, "\n"); + rz_strbuf_append (res, "\n"); } else { - r_strbuf_append (res, "
"); + rz_strbuf_append (res, "
"); } str = ptr + 1; continue; } else if (ptr[0] == '<') { tmp = (int)(size_t) (ptr - str); - r_strbuf_append_n (res, str, tmp); - r_strbuf_append (res, "<"); + rz_strbuf_append_n (res, str, tmp); + rz_strbuf_append (res, "<"); str = ptr + 1; continue; } else if (ptr[0] == '>') { tmp = (int)(size_t) (ptr - str); - r_strbuf_append_n (res, str, tmp); - r_strbuf_append (res, ">"); + rz_strbuf_append_n (res, str, tmp); + rz_strbuf_append (res, ">"); str = ptr + 1; continue; } else if (ptr[0] == ' ') { tmp = (int) (size_t) (ptr - str); - r_strbuf_append_n (res, str, tmp); - r_strbuf_append (res, " "); + rz_strbuf_append_n (res, str, tmp); + rz_strbuf_append (res, " "); str = ptr + 1; continue; } if (ptr[0] == 0x1b) { esc = 1; tmp = (int)(size_t) (ptr - str); - r_strbuf_append_n (res, str, tmp); + rz_strbuf_append_n (res, str, tmp); str = ptr + 1; continue; } @@ -135,7 +135,7 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { str = ptr; continue; } else if (ptr[0] == '2' && ptr[1] == 'J') { - r_strbuf_append (res, "
"); + rz_strbuf_append (res, "
"); ptr++; esc = 0; str = ptr; @@ -156,7 +156,7 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { esc = 0; } else if (ptr[0] == '0' && ptr[1] == ';' && ptr[2] == '0') { // wtf ? - r_cons_gotoxy (0, 0); + rz_cons_gotoxy (0, 0); ptr += 4; esc = 0; str = ptr; @@ -188,7 +188,7 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { } else if (ptr[0] == '3' && ptr[2] == 'm') { const char *htmlColor = gethtmlcolor (ptr[1]); if (htmlColor) { - r_str_ncpy (text_color, htmlColor, sizeof (text_color)); + rz_str_ncpy (text_color, htmlColor, sizeof (text_color)); } need_to_set = true; ptr = ptr + 2; @@ -198,7 +198,7 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { } else if (ptr[0] == '4' && ptr[2] == 'm') { const char *htmlColor = gethtmlcolor (ptr[1]); if (htmlColor) { - r_str_ncpy (background_color, htmlColor, sizeof (background_color)); + rz_str_ncpy (background_color, htmlColor, sizeof (background_color)); } need_to_set = true; ptr = ptr + 2; @@ -209,13 +209,13 @@ R_API char *r_cons_html_filter(const char *ptr, int *newlen) { } len++; } - r_strbuf_append_n (res, str, ptr - str); + rz_strbuf_append_n (res, str, ptr - str); if (has_set) { - r_strbuf_append (res, ""); + rz_strbuf_append (res, ""); } if (newlen) { *newlen = res->len; } - return r_strbuf_drain (res); + return rz_strbuf_drain (res); } diff --git a/libr/cons/hud.c b/librz/cons/hud.c similarity index 68% rename from libr/cons/hud.c rename to librz/cons/hud.c index fc2ba69e96..d64b3bab3e 100644 --- a/libr/cons/hud.c +++ b/librz/cons/hud.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2008-2018 - pancake */ -#include +#include #include -#define I(x) r_cons_singleton ()->x +#define I(x) rz_cons_singleton ()->x // Display the content of a file in the hud -R_API char *r_cons_hud_file(const char *f) { - char *s = r_file_slurp (f, NULL); +RZ_API char *rz_cons_hud_file(const char *f) { + char *s = rz_file_slurp (f, NULL); if (s) { - char *ret = r_cons_hud_string (s); + char *ret = rz_cons_hud_string (s); free (s); return ret; } @@ -18,14 +18,14 @@ R_API char *r_cons_hud_file(const char *f) { // Display a buffer in the hud (splitting it line-by-line and ignoring // the lines starting with # ) -R_API char *r_cons_hud_string(const char *s) { +RZ_API char *rz_cons_hud_string(const char *s) { char *os, *track, *ret, *o = strdup (s); if (!o) { return NULL; } - r_str_replace_ch (o, '\r', 0, true); - r_str_replace_ch (o, '\t', 0, true); - RList *fl = r_list_new (); + rz_str_replace_ch (o, '\r', 0, true); + rz_str_replace_ch (o, '\t', 0, true); + RzList *fl = rz_list_new (); int i; if (!fl) { free (o); @@ -37,7 +37,7 @@ R_API char *r_cons_hud_string(const char *s) { o[i] = 0; if (*os && *os != '#') { track = strdup (os); - if (!r_list_append (fl, track)) { + if (!rz_list_append (fl, track)) { free (track); break; } @@ -45,9 +45,9 @@ R_API char *r_cons_hud_string(const char *s) { os = o + i + 1; } } - ret = r_cons_hud (fl, NULL); + ret = rz_cons_hud (fl, NULL); free (o); - r_list_free (fl); + rz_list_free (fl); return ret; } @@ -61,7 +61,7 @@ static bool __matchString(char *entry, char *filter, char *mask, const int mask_ const char *filter_end = filter + strlen (filter); char *ansi_filtered = strdup (entry); int *cps; - r_str_ansi_filter (ansi_filtered, NULL, &cps, -1); + rz_str_ansi_filter (ansi_filtered, NULL, &cps, -1); entry = ansi_filtered; // first we separate the filter in words (include the terminator char // to avoid special handling of the last token) @@ -79,7 +79,7 @@ static bool __matchString(char *entry, char *filter, char *mask, const int mask_ *p = 0; token_len = strlen (current_token); // look for all matches of the current_token in this entry - while ((next_match = r_str_casestr (entry_ptr, current_token))) { + while ((next_match = rz_str_casestr (entry_ptr, current_token))) { int real_pos, filtered_pos = next_match - entry; int end_pos = cps[filtered_pos + token_len]; for (real_pos = cps[filtered_pos]; @@ -105,17 +105,17 @@ static bool __matchString(char *entry, char *filter, char *mask, const int mask_ } -static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *current_entry_n, char **selected_entry) { - RListIter *iter; +static RzList *hud_filter(RzList *list, char *user_input, int top_entry_n, int *current_entry_n, char **selected_entry) { + RzListIter *iter; char *current_entry; char mask[HUD_BUF_SIZE]; char *p, *x; int j, rows; - (void) r_cons_get_size (&rows); + (void) rz_cons_get_size (&rows); int counter = 0; bool first_line = true; - RList *res = r_list_newf (free); - r_list_foreach (list, iter, current_entry) { + RzList *res = rz_list_newf (free); + rz_list_foreach (list, iter, current_entry) { memset (mask, 0, HUD_BUF_SIZE); if (*user_input && !__matchString (current_entry, user_input, mask, HUD_BUF_SIZE)) { continue; @@ -133,13 +133,13 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu p = strdup (current_entry); // if the filter is empty, print the entry and move on if (!user_input[0]) { - r_list_append (res, r_str_newf (" %c %s", first_line? '-': ' ', p)); + rz_list_append (res, rz_str_newf (" %c %s", first_line? '-': ' ', p)); } else { // otherwise we need to emphasize the matching part if (I (context->color_mode)) { int last_color_change = 0; int last_mask = 0; - char *str = r_str_newf (" %c ", first_line? '-': ' '); + char *str = rz_str_newf (" %c ", first_line? '-': ' '); // Instead of printing one char at the time // (which would be slow), we group substrings of the same color for (j = 0; p[j] && j < HUD_BUF_SIZE; j++) { @@ -147,9 +147,9 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu char tmp = p[j]; p[j] = 0; if (mask[j]) { - str = r_str_appendf (str, Color_RESET "%s", p + last_color_change); + str = rz_str_appendf (str, Color_RESET "%s", p + last_color_change); } else { - str = r_str_appendf (str, Color_GREEN "%s", p + last_color_change); + str = rz_str_appendf (str, Color_GREEN "%s", p + last_color_change); } p[j] = tmp; last_color_change = j; @@ -157,11 +157,11 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu } } if (last_mask) { - str = r_str_appendf (str, Color_GREEN "%s"Color_RESET, p + last_color_change); + str = rz_str_appendf (str, Color_GREEN "%s"Color_RESET, p + last_color_change); } else { - str = r_str_appendf (str, Color_RESET "%s", p + last_color_change); + str = rz_str_appendf (str, Color_RESET "%s", p + last_color_change); } - r_list_append (res, str); + rz_list_append (res, str); } else { // Otherwise we print the matching characters uppercase for (j = 0; p[j]; j++) { @@ -169,7 +169,7 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu p[j] = toupper ((unsigned char) p[j]); } } - r_list_append (res, r_str_newf (" %c %s", first_line? '-': ' ', p)); + rz_list_append (res, rz_str_newf (" %c %s", first_line? '-': ' ', p)); } } // Clean up and restore the tab character (if any) @@ -190,16 +190,16 @@ static RList *hud_filter(RList *list, char *user_input, int top_entry_n, int *cu static void mht_free_kv(HtPPKv *kv) { free (kv->key); - r_list_free (kv->value); + rz_list_free (kv->value); } // Display a list of entries in the hud, filtered and emphasized based on the user input. #define HUD_CACHE 0 -R_API char *r_cons_hud(RList *list, const char *prompt) { +RZ_API char *rz_cons_hud(RzList *list, const char *prompt) { char user_input[HUD_BUF_SIZE + 1]; char *selected_entry = NULL; - RListIter *iter; + RzListIter *iter; HtPP *ht = ht_pp_new (NULL, (HtPPKvFreeFunc)mht_free_kv, (HtPPCalcSizeV)strlen); RLineHud *hud = (RLineHud*) R_NEW (RLineHud); @@ -210,13 +210,13 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { user_input [0] = 0; user_input[HUD_BUF_SIZE] = 0; hud->top_entry_n = 0; - r_cons_show_cursor (false); - r_cons_enable_mouse (false); - r_cons_clear (); + rz_cons_show_cursor (false); + rz_cons_enable_mouse (false); + rz_cons_clear (); // Repeat until the user exits the hud for (;;) { - r_cons_gotoxy (0, 0); + rz_cons_gotoxy (0, 0); hud->current_entry_n = 0; if (hud->top_entry_n < 0) { @@ -224,11 +224,11 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { } selected_entry = NULL; if (prompt && *prompt) { - r_cons_printf (">> %s\n", prompt); + rz_cons_printf (">> %s\n", prompt); } - r_cons_printf ("%d> %s|\n", hud->top_entry_n, user_input); + rz_cons_printf ("%d> %s|\n", hud->top_entry_n, user_input); char *row; - RList *filtered_list = NULL; + RzList *filtered_list = NULL; bool found = false; filtered_list = ht_pp_find (ht, user_input, &found); @@ -239,17 +239,17 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { ht_pp_insert (ht, user_input, filtered_list); #endif } - r_list_foreach (filtered_list, iter, row) { - r_cons_printf ("%s\n", row); + rz_list_foreach (filtered_list, iter, row) { + rz_cons_printf ("%s\n", row); } if (!filtered_list->length) { // hack to remove garbage value when list is empty printf ("%s", R_CONS_CLEAR_LINE); } #if !HUD_CACHE - r_list_free (filtered_list); + rz_list_free (filtered_list); #endif - r_cons_visual_flush (); - (void) r_line_readline (); + rz_cons_visual_flush (); + (void) rz_line_readline (); strncpy (user_input, I(line)->buffer.data, HUD_BUF_SIZE); // to search if (!hud->activate) { @@ -258,9 +258,9 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { if (selected_entry) { R_FREE (I(line)->hud); I(line)->echo = true; - r_cons_enable_mouse (false); - r_cons_show_cursor (true); - r_cons_set_raw (false); + rz_cons_enable_mouse (false); + rz_cons_show_cursor (true); + rz_cons_set_raw (false); return strdup (selected_entry); } } else { @@ -271,40 +271,40 @@ R_API char *r_cons_hud(RList *list, const char *prompt) { _beach: R_FREE (I(line)->hud); I(line)->echo = true; - r_cons_show_cursor (true); - r_cons_enable_mouse (false); - r_cons_set_raw (false); + rz_cons_show_cursor (true); + rz_cons_enable_mouse (false); + rz_cons_set_raw (false); ht_pp_free (ht); return NULL; } // Display the list of files in a directory -R_API char *r_cons_hud_path(const char *path, int dir) { +RZ_API char *rz_cons_hud_path(const char *path, int dir) { char *tmp, *ret = NULL; - RList *files; + RzList *files; if (path) { - path = r_str_trim_head_ro (path); + path = rz_str_trim_head_ro (path); tmp = strdup (*path? path: "./"); } else { tmp = strdup ("./"); } - files = r_sys_dir (tmp); + files = rz_sys_dir (tmp); if (files) { - ret = r_cons_hud (files, tmp); + ret = rz_cons_hud (files, tmp); if (ret) { - tmp = r_str_append (tmp, "/"); - tmp = r_str_append (tmp, ret); + tmp = rz_str_append (tmp, "/"); + tmp = rz_str_append (tmp, ret); free (ret); - ret = r_file_abspath (tmp); + ret = rz_file_abspath (tmp); free (tmp); tmp = ret; - if (r_file_is_directory (tmp)) { - ret = r_cons_hud_path (tmp, dir); + if (rz_file_is_directory (tmp)) { + ret = rz_cons_hud_path (tmp, dir); free (tmp); tmp = ret; } } - r_list_free (files); + rz_list_free (files); } else { eprintf ("No files found\n"); } @@ -315,14 +315,14 @@ R_API char *r_cons_hud_path(const char *path, int dir) { return tmp; } -R_API char *r_cons_message(const char *msg) { +RZ_API char *rz_cons_message(const char *msg) { int len = strlen (msg); - int rows, cols = r_cons_get_size (&rows); - r_cons_clear (); - r_cons_gotoxy ((cols - len) / 2, rows / 2); - r_cons_println (msg); - r_cons_flush (); - r_cons_gotoxy (0, rows - 2); - r_cons_any_key (NULL); + int rows, cols = rz_cons_get_size (&rows); + rz_cons_clear (); + rz_cons_gotoxy ((cols - len) / 2, rows / 2); + rz_cons_println (msg); + rz_cons_flush (); + rz_cons_gotoxy (0, rows - 2); + rz_cons_any_key (NULL); return NULL; } diff --git a/libr/cons/input.c b/librz/cons/input.c similarity index 79% rename from libr/cons/input.c rename to librz/cons/input.c index 8074211748..9a4f06e88e 100644 --- a/libr/cons/input.c +++ b/librz/cons/input.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include #include #if __UNIX__ #include #endif -#define I r_cons_singleton () +#define I rz_cons_singleton () // TODO: Support binary, use RBuffer and remove globals static char *readbuffer = NULL; @@ -32,12 +32,12 @@ static int __is_fd_ready(int fd) { } #endif -R_API int r_cons_controlz(int ch) { +RZ_API int rz_cons_controlz(int ch) { #if __UNIX__ if (ch == 0x1a) { - r_cons_show_cursor (true); - r_cons_enable_mouse (false); - r_sys_stop (); + rz_cons_show_cursor (true); + rz_cons_enable_mouse (false); + rz_sys_stop (); return 0; } #endif @@ -51,8 +51,8 @@ R_API int r_cons_controlz(int ch) { static int __parseMouseEvent(void) { char xpos[32]; char ypos[32]; - (void)r_cons_readchar (); // skip first char - int ch2 = r_cons_readchar (); + (void)rz_cons_readchar (); // skip first char + int ch2 = rz_cons_readchar (); // [32M - mousedown // [35M - mouseup @@ -60,7 +60,7 @@ static int __parseMouseEvent(void) { int i; // read until next ; for (i = 0; i < sizeof (xpos) - 1; i++) { - char ch = r_cons_readchar (); + char ch = rz_cons_readchar (); if (ch == ';' || ch == 'M') { break; } @@ -68,23 +68,23 @@ static int __parseMouseEvent(void) { } xpos[i] = 0; for (i = 0; i < sizeof (ypos) - 1; i++) { - char ch = r_cons_readchar (); + char ch = rz_cons_readchar (); if (ch == ';' || ch == 'M') { break; } ypos[i] = ch; } ypos[i] = 0; - r_cons_set_click (atoi (xpos), atoi (ypos)); - (void) r_cons_readchar (); + rz_cons_set_click (atoi (xpos), atoi (ypos)); + (void) rz_cons_readchar (); // ignored - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == 27) { - ch = r_cons_readchar (); // '[' + ch = rz_cons_readchar (); // '[' } if (ch == '[') { do { - ch = r_cons_readchar (); // '3' + ch = rz_cons_readchar (); // '3' } while (ch != 'M'); } } @@ -96,7 +96,7 @@ static bool bCtrl; static bool is_arrow; #endif -R_API int r_cons_arrow_to_hjkl(int ch) { +RZ_API int rz_cons_arrow_to_hjkl(int ch) { #if __WINDOWS__ if (I->vtmode != 2) { if (is_arrow) { @@ -113,7 +113,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { case VK_LEFT: // key left ch = bCtrl ? 'H' : 'h'; break; - case VK_PRIOR: // key home + case VK_PRzIOR: // key home ch = 'K'; break; case VK_NEXT: // key end @@ -127,7 +127,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { I->mouse_event = 0; /* emacs */ switch ((ut8)ch) { - case 0xc3: r_cons_readchar (); ch='K'; break; // emacs repag (alt + v) + case 0xc3: rz_cons_readchar (); ch='K'; break; // emacs repag (alt + v) case 0x16: ch='J'; break; // emacs avpag (ctrl + v) case 0x10: ch='k'; break; // emacs up (ctrl + p) case 0x0e: ch='j'; break; // emacs down (ctrl + n) @@ -137,7 +137,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { if (ch != 0x1b) { return ch; } - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (!ch) { return 0; } @@ -146,7 +146,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { ch = 'q'; // XXX: must be 0x1b (R_CONS_KEY_ESC) break; case 0x4f: // function keys from f1 to f4 - ch = r_cons_readchar (); + ch = rz_cons_readchar (); #if defined(__HAIKU__) /* Haiku't don use the '[' char for function keys */ if (ch > 'O') {/* only in f1..f12 function keys */ @@ -156,13 +156,13 @@ R_API int r_cons_arrow_to_hjkl(int ch) { case '[': // 0x5b function keys (2) /* Haiku need ESC + [ for PageUp and PageDown */ if (ch < 'A' || ch == '[') { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } #else ch = 0xf1 + (ch & 0xf); break; case '[': // function keys (2) - ch = r_cons_readchar (); + ch = rz_cons_readchar (); #endif switch (ch) { case '<': @@ -176,7 +176,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { char vel[8] = {0}; int vn = 0; do { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); // just for debugging //eprintf ( "%c", ch); if (sc > 0) { @@ -210,11 +210,11 @@ R_API int r_cons_arrow_to_hjkl(int ch) { } pos[p++] = 0; y = atoi (pos); - r_cons_set_click (x, y); + rz_cons_set_click (x, y); } return 0; case '[': - ch = r_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case '2': ch = R_CONS_KEY_F11; break; case 'A': ch = R_CONS_KEY_F1; break; @@ -226,7 +226,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { case '9': // handle mouse wheel // __parseWheelEvent(); - ch = r_cons_readchar (); + ch = rz_cons_readchar (); // 6 is up // 7 is down I->mouse_event = 1; @@ -240,7 +240,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { } int ch2; do { - ch2 = r_cons_readchar (); + ch2 = rz_cons_readchar (); } while (ch2 != 'M'); break; case '3': @@ -249,13 +249,13 @@ R_API int r_cons_arrow_to_hjkl(int ch) { return 0; break; case '2': - ch = r_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case 0x7e: ch = R_CONS_KEY_F12; break; default: - r_cons_readchar (); + rz_cons_readchar (); switch (ch) { case '0': ch = R_CONS_KEY_F9; break; case '1': ch = R_CONS_KEY_F10; break; @@ -265,7 +265,7 @@ R_API int r_cons_arrow_to_hjkl(int ch) { } break; case '1': - ch = r_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case '1': ch = R_CONS_KEY_F1; break; case '2': ch = R_CONS_KEY_F2; break; @@ -278,33 +278,33 @@ R_API int r_cons_arrow_to_hjkl(int ch) { case '9': ch = R_CONS_KEY_F8; break; #if 0 case '5': - r_cons_readchar (); + rz_cons_readchar (); ch = 0xf5; break; case '6': - r_cons_readchar (); + rz_cons_readchar (); ch = 0xf7; break; case '7': - r_cons_readchar (); + rz_cons_readchar (); ch = 0xf6; break; case '8': - r_cons_readchar (); + rz_cons_readchar (); ch = 0xf7; break; case '9': - r_cons_readchar (); + rz_cons_readchar (); ch = 0xf8; break; #endif // Support st/st-256color term and others // for shift+arrows case ';': // arrow+mod - ch = r_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case '2': // arrow+shift - ch = r_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case 'A': ch = 'K'; break; case 'B': ch = 'J'; break; @@ -316,8 +316,8 @@ R_API int r_cons_arrow_to_hjkl(int ch) { } break; case ':': // arrow+shift - ch = r_cons_readchar (); - ch = r_cons_readchar (); + ch = rz_cons_readchar (); + ch = rz_cons_readchar (); switch (ch) { case 'A': ch = 'K'; break; case 'B': ch = 'J'; break; @@ -327,8 +327,8 @@ R_API int r_cons_arrow_to_hjkl(int ch) { break; } // F9-F12 not yet supported!! break; - case '5': ch = 'K'; r_cons_readchar (); break; // repag - case '6': ch = 'J'; r_cons_readchar (); break; // avpag + case '5': ch = 'K'; rz_cons_readchar (); break; // repag + case '6': ch = 'J'; rz_cons_readchar (); break; // avpag /* arrow keys */ case 'A': ch = 'k'; break; // up case 'B': ch = 'j'; break; // down @@ -347,18 +347,18 @@ R_API int r_cons_arrow_to_hjkl(int ch) { } // XXX no control for max length here?!?! -R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { +RZ_API int rz_cons_fgets(char *buf, int len, int argc, const char **argv) { #define RETURN(x) { ret=x; goto beach; } - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); int ret = 0, color = cons->context->pal.input && *cons->context->pal.input; if (cons->echo) { - r_cons_set_raw (false); - r_cons_show_cursor (true); + rz_cons_set_raw (false); + rz_cons_show_cursor (true); } #if 0 - int mouse = r_cons_enable_mouse (false); - r_cons_enable_mouse (false); - r_cons_flush (); + int mouse = rz_cons_enable_mouse (false); + rz_cons_enable_mouse (false); + rz_cons_flush (); #endif errno = 0; if (cons->user_fgets) { @@ -387,25 +387,25 @@ R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { } RETURN (-2); } - r_str_trim_tail (buf); + rz_str_trim_tail (buf); if (color) { printf (Color_RESET); } ret = strlen (buf); beach: - //r_cons_enable_mouse (mouse); + //rz_cons_enable_mouse (mouse); return ret; } -R_API int r_cons_any_key(const char *msg) { +RZ_API int rz_cons_any_key(const char *msg) { if (msg && *msg) { - r_cons_printf ("\n-- %s --\n", msg); + rz_cons_printf ("\n-- %s --\n", msg); } else { - r_cons_print ("\n--press any key--\n"); + rz_cons_print ("\n--press any key--\n"); } - r_cons_flush (); - return r_cons_readchar (); - //r_cons_strcat ("\x1b[2J\x1b[0;0H"); // wtf? + rz_cons_flush (); + return rz_cons_readchar (); + //rz_cons_strcat ("\x1b[2J\x1b[0;0H"); // wtf? } extern void resizeWin(void); @@ -433,29 +433,29 @@ static int __cons_readchar_w32(ut32 usec) { newmode |= mode; SetConsoleMode (h, newmode); do { - bed = r_cons_sleep_begin (); + bed = rz_cons_sleep_begin (); if (usec) { if (WaitForSingleObject (h, usec) == WAIT_TIMEOUT) { - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); return -1; } } if (I->term_xterm) { ret = ReadFile (h, &ch, 1, &out, NULL); if (ret) { - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); return ch; } } else { ret = ReadConsoleInput (h, &irInBuf, 1, &out); } - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (ret) { if (irInBuf.EventType == MENU_EVENT || irInBuf.EventType == FOCUS_EVENT) { continue; } if (mouse_enabled) { - r_cons_enable_mouse (true); + rz_cons_enable_mouse (true); } if (irInBuf.EventType == MOUSE_EVENT) { if (irInBuf.Event.MouseEvent.dwEventFlags == MOUSE_MOVED) { @@ -476,14 +476,14 @@ static int __cons_readchar_w32(ut32 usec) { case FROM_LEFT_1ST_BUTTON_PRESSED: GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info); int rel_y = irInBuf.Event.MouseEvent.dwMousePosition.Y - info.srWindow.Top; - r_cons_set_click (irInBuf.Event.MouseEvent.dwMousePosition.X + 1, rel_y + 1); + rz_cons_set_click (irInBuf.Event.MouseEvent.dwMousePosition.X + 1, rel_y + 1); ch = UT8_MAX; break; } // TODO: Handle more buttons? } if (click_n_drag) { - r_cons_set_click (irInBuf.Event.MouseEvent.dwMousePosition.X + 1, irInBuf.Event.MouseEvent.dwMousePosition.Y + 1); + rz_cons_set_click (irInBuf.Event.MouseEvent.dwMousePosition.X + 1, irInBuf.Event.MouseEvent.dwMousePosition.Y + 1); ch = UT8_MAX; } @@ -497,7 +497,7 @@ static int __cons_readchar_w32(ut32 usec) { case VK_RIGHT: // key right case VK_UP: // key up case VK_LEFT: // key left - case VK_PRIOR: // key home + case VK_PRzIOR: // key home case VK_NEXT: // key end ch = irInBuf.Event.KeyEvent.wVirtualKeyCode; is_arrow = true; @@ -539,7 +539,7 @@ static int __cons_readchar_w32(ut32 usec) { ch = R_CONS_KEY_F12; case VK_SHIFT: if (mouse_enabled) { - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); } break; default: @@ -561,7 +561,7 @@ static int __cons_readchar_w32(ut32 usec) { } #endif -R_API int r_cons_readchar_timeout(ut32 usec) { +RZ_API int rz_cons_readchar_timeout(ut32 usec) { #if __UNIX__ struct timeval tv; fd_set fdset, errset; @@ -570,11 +570,11 @@ R_API int r_cons_readchar_timeout(ut32 usec) { FD_SET (0, &fdset); tv.tv_sec = 0; // usec / 1000; tv.tv_usec = 1000 * usec; - r_cons_set_raw (1); + rz_cons_set_raw (1); if (select (1, &fdset, NULL, &errset, &tv) == 1) { - return r_cons_readchar (); + return rz_cons_readchar (); } - r_cons_set_raw (0); + rz_cons_set_raw (0); // timeout return -1; #else @@ -582,7 +582,7 @@ R_API int r_cons_readchar_timeout(ut32 usec) { #endif } -R_API bool r_cons_readpush(const char *str, int len) { +RZ_API bool rz_cons_readpush(const char *str, int len) { char *res = (len + readbuffer_length > 0) ? realloc (readbuffer, len + readbuffer_length) : NULL; if (res) { readbuffer = res; @@ -593,12 +593,12 @@ R_API bool r_cons_readpush(const char *str, int len) { return false; } -R_API void r_cons_readflush(void) { +RZ_API void rz_cons_readflush(void) { R_FREE (readbuffer); readbuffer_length = 0; } -R_API void r_cons_switchbuf(bool active) { +RZ_API void rz_cons_switchbuf(bool active) { bufactive = active; } @@ -606,7 +606,7 @@ R_API void r_cons_switchbuf(bool active) { extern volatile sig_atomic_t sigwinchFlag; #endif -R_API int r_cons_readchar(void) { +RZ_API int rz_cons_readchar(void) { char buf[2]; buf[0] = -1; if (readbuffer_length > 0) { @@ -615,11 +615,11 @@ R_API int r_cons_readchar(void) { memmove (readbuffer, readbuffer + 1, readbuffer_length); return ch; } - r_cons_set_raw (1); + rz_cons_set_raw (1); #if __WINDOWS__ return __cons_readchar_w32 (0); #else - void *bed = r_cons_sleep_begin (); + void *bed = rz_cons_sleep_begin (); // Blocks until either stdin has something to read or a signal happens. // This serves to check if the terminal window was resized. It avoids the race @@ -631,11 +631,11 @@ R_API int r_cons_readchar(void) { sigset_t sigmask; FD_ZERO (&readfds); FD_SET (STDIN_FILENO, &readfds); - r_signal_sigmask (0, NULL, &sigmask); + rz_signal_sigmask (0, NULL, &sigmask); sigdelset (&sigmask, SIGWINCH); while (pselect (STDIN_FILENO + 1, &readfds, NULL, NULL, NULL, &sigmask) == -1) { if (errno == EBADF) { - eprintf ("r_cons_readchar (): EBADF\n"); + eprintf ("rz_cons_readchar (): EBADF\n"); return -1; } if (sigwinchFlag) { @@ -645,30 +645,30 @@ R_API int r_cons_readchar(void) { } ssize_t ret = read (STDIN_FILENO, buf, 1); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (ret != 1) { return -1; } if (bufactive) { - r_cons_set_raw (0); + rz_cons_set_raw (0); } - return r_cons_controlz (buf[0]); + return rz_cons_controlz (buf[0]); #endif } -R_API bool r_cons_yesno(int def, const char *fmt, ...) { +RZ_API bool rz_cons_yesno(int def, const char *fmt, ...) { va_list ap; ut8 key = (ut8)def; va_start (ap, fmt); - if (!r_cons_is_interactive ()) { + if (!rz_cons_is_interactive ()) { va_end (ap); return def == 'y'; } vfprintf (stderr, fmt, ap); va_end (ap); fflush (stderr); - r_cons_set_raw (true); + rz_cons_set_raw (true); char buf[] = " ?\n"; if (read (0, buf + 1, 1) == 1) { key = (ut8)buf[1]; @@ -676,7 +676,7 @@ R_API bool r_cons_yesno(int def, const char *fmt, ...) { if (key == 'Y') { key = 'y'; } - r_cons_set_raw (false); + rz_cons_set_raw (false); if (key == '\n' || key == '\r') { key = def; } @@ -686,23 +686,23 @@ R_API bool r_cons_yesno(int def, const char *fmt, ...) { return false; } -R_API char *r_cons_password(const char *msg) { +RZ_API char *rz_cons_password(const char *msg) { int i = 0; char buf[256] = {0}; printf ("\r%s", msg); fflush (stdout); - r_cons_set_raw (1); + rz_cons_set_raw (1); #if __UNIX__ - RCons *a = r_cons_singleton (); + RzCons *a = rz_cons_singleton (); a->term_raw.c_lflag &= ~(ECHO | ECHONL); // // required to make therm/iterm show the key // // cannot read when enabled in this way // a->term_raw.c_lflag |= ICANON; tcsetattr (0, TCSADRAIN, &a->term_raw); - r_sys_signal (SIGTSTP, SIG_IGN); + rz_sys_signal (SIGTSTP, SIG_IGN); #endif while (i < sizeof (buf) - 1) { - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == 127) { // backspace if (i < 1) { break; @@ -716,28 +716,28 @@ R_API char *r_cons_password(const char *msg) { buf[i++] = ch; } buf[i] = 0; - r_cons_set_raw (0); + rz_cons_set_raw (0); printf ("\n"); #if __UNIX__ - r_sys_signal (SIGTSTP, SIG_DFL); + rz_sys_signal (SIGTSTP, SIG_DFL); #endif return strdup (buf); } -R_API char *r_cons_input(const char *msg) { - char *oprompt = r_line_get_prompt (); +RZ_API char *rz_cons_input(const char *msg) { + char *oprompt = rz_line_get_prompt (); if (!oprompt) { return NULL; } char buf[1024]; if (msg) { - r_line_set_prompt (msg); + rz_line_set_prompt (msg); } else { - r_line_set_prompt (""); + rz_line_set_prompt (""); } buf[0] = 0; - r_cons_fgets (buf, sizeof (buf), 0, NULL); - r_line_set_prompt (oprompt); + rz_cons_fgets (buf, sizeof (buf), 0, NULL); + rz_line_set_prompt (oprompt); free (oprompt); return strdup (buf); } diff --git a/libr/cons/less.c b/librz/cons/less.c similarity index 70% rename from libr/cons/less.c rename to librz/cons/less.c index ca4ace1684..a1ab7a8a61 100644 --- a/libr/cons/less.c +++ b/librz/cons/less.c @@ -1,15 +1,15 @@ -/* radare2 - LGPL - Copyright 2014-2019 - pancake, Judge_Dredd */ +/* rizin - LGPL - Copyright 2014-2019 - pancake, Judge_Dredd */ -#include -#include -#include +#include +#include +#include #include "pager_private.h" -R_API int r_cons_less_str(const char *str, const char *exitkeys) { - r_return_val_if_fail (str && *str, 0); +RZ_API int rz_cons_less_str(const char *str, const char *exitkeys) { + rz_return_val_if_fail (str && *str, 0); static int in_help = false; - static const char *r_cons_less_help = \ + static const char *rz_cons_less_help = \ " u/space - page up/down\n" " jk - line down/up\n" " gG - begin/end buffer\n" @@ -20,10 +20,10 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { " ? - show this help\n" "\n"; int lines_count = 0; - RRegex *rx = NULL; + RzRegex *rx = NULL; int w, h, ch, to, ui = 1, from = 0, i; const char *sreg; - RList **mla; + RzList **mla; // rcons kills str after flushing the buffer, so we must keep a copy char *ostr = strdup (str); @@ -39,7 +39,7 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { if (lines_count < 1) { mla = NULL; } else { - mla = calloc (lines_count, sizeof (RList *)); + mla = calloc (lines_count, sizeof (RzList *)); if (!mla) { free (p); free (ostr); @@ -48,14 +48,14 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { } } for (i = 0; i < lines_count; i++) { - mla[i] = r_list_new (); + mla[i] = rz_list_new (); } - r_cons_set_raw (true); - r_cons_show_cursor (false); - r_cons_reset (); + rz_cons_set_raw (true); + rz_cons_show_cursor (false); + rz_cons_reset (); h = 0; while (ui) { - w = r_cons_get_size (&h); + w = rz_cons_get_size (&h); to = R_MIN (lines_count, from + h); if (from + 3 > lines_count) { from = lines_count - 3; @@ -64,10 +64,10 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { from = 0; } pager_printpage (p, lines, mla, from, to, w); - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (exitkeys && strchr (exitkeys, ch)) { for (i = 0; i < lines_count; i++) { - r_list_free (mla[i]); + rz_list_free (mla[i]); } free (p); free (mla); @@ -75,15 +75,15 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { free (lines); return ch; } - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { case '_': - r_cons_hud_string (ostr); + rz_cons_hud_string (ostr); break; case '?': if (!in_help) { in_help = true; - (void)r_cons_less_str (r_cons_less_help, NULL); + (void)rz_cons_less_str (rz_cons_less_help, NULL); in_help = false; } break; @@ -111,16 +111,16 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { case 'K': from = (from>=h)? from-h: 0; break; case '/': /* search */ - r_cons_reset_colors (); - r_line_set_prompt ("/"); - sreg = r_line_readline (); + rz_cons_reset_colors (); + rz_line_set_prompt ("/"); + sreg = rz_line_readline (); from = R_MIN (lines_count - 1, from); /* repeat last search if empty string is provided */ if (sreg[0]) { /* prepare for a new search */ if (rx) { - r_regex_free (rx); + rz_regex_free (rx); } - rx = r_regex_new (sreg, ""); + rx = rz_regex_new (sreg, ""); } else { /* we got an empty string */ from = pager_next_match (from, mla, lines_count); break; @@ -148,27 +148,27 @@ R_API int r_cons_less_str(const char *str, const char *exitkeys) { } } for (i = 0; i < lines_count; i++) { - r_list_free (mla[i]); + rz_list_free (mla[i]); } free (mla); - r_regex_free (rx); + rz_regex_free (rx); free (lines); free (p); - r_cons_reset_colors (); - r_cons_set_raw (false); - r_cons_show_cursor (true); + rz_cons_reset_colors (); + rz_cons_set_raw (false); + rz_cons_show_cursor (true); free (ostr); return 0; } -R_API void r_cons_less(void) { - (void)r_cons_less_str (r_cons_singleton ()->context->buffer, NULL); +RZ_API void rz_cons_less(void) { + (void)rz_cons_less_str (rz_cons_singleton ()->context->buffer, NULL); } #if 0 main (int argc, char **argv) { - char *s = r_file_slurp (argv[1], NULL); - r_cons_new (); - r_cons_less (s); + char *s = rz_file_slurp (argv[1], NULL); + rz_cons_new (); + rz_cons_less (s); } #endif diff --git a/librz/cons/line.c b/librz/cons/line.c new file mode 100644 index 0000000000..385663eca1 --- /dev/null +++ b/librz/cons/line.c @@ -0,0 +1,107 @@ +/* radare - LGPL - Copyright 2007-2019 - pancake */ + +#include +#include + +static RLine rz_line_instance; +#define I rz_line_instance + +RZ_API RLine *rz_line_singleton(void) { + return &rz_line_instance; +} + +RZ_API RLine *rz_line_new(void) { + I.hist_up = NULL; + I.hist_down = NULL; + I.prompt = strdup ("> "); + I.contents = NULL; + I.enable_vi_mode = false; + I.clipboard = NULL; + I.kill_ring = rz_list_newf (NULL); + I.kill_ring_ptr = -1; +#if __WINDOWS__ + I.vtmode = rz_cons_is_vtcompat (); +#else + I.vtmode = 2; +#endif + if (!rz_line_dietline_init ()) { + eprintf ("error: rz_line_dietline_init\n"); + } + rz_line_completion_init (&I.completion, 4096); + return &I; +} + +RZ_API void rz_line_free(void) { + // XXX: prompt out of the heap? + free ((void *)I.prompt); + I.prompt = NULL; + rz_line_hist_free (); + rz_line_completion_fini (&I.completion); +} + +RZ_API void rz_line_clipboard_push (const char *str) { + I.kill_ring_ptr += 1; + rz_list_insert (I.kill_ring, I.kill_ring_ptr, strdup (str)); +} + +// handle const or dynamic prompts? +RZ_API void rz_line_set_prompt(const char *prompt) { + free (I.prompt); + I.prompt = strdup (prompt); + RzCons *cons = rz_cons_singleton (); + I.cb_fkey = cons->cb_fkey; +} + +// handle const or dynamic prompts? +RZ_API char *rz_line_get_prompt(void) { + return strdup (I.prompt); +} + +RZ_API void rz_line_completion_init(RLineCompletion *completion, size_t args_limit) { + completion->run = NULL; + completion->run_user = NULL; + completion->args_limit = args_limit; + rz_pvector_init (&completion->args, free); +} + +RZ_API void rz_line_completion_fini(RLineCompletion *completion) { + rz_line_completion_clear (completion); +} + +RZ_API void rz_line_completion_push(RLineCompletion *completion, const char *str) { + rz_return_if_fail (completion && str); + if (completion->quit) { + return; + } + if (rz_pvector_len (&completion->args) < completion->args_limit) { + char *s = strdup (str); + if (s) { + rz_pvector_push (&completion->args, (void *)s); + } + } else { + completion->quit = true; + eprintf ("WARNING: Maximum completion capacity reached, increase scr.maxtab"); + } +} + +RZ_API void rz_line_completion_set(RLineCompletion *completion, int argc, const char **argv) { + rz_return_if_fail (completion && (argc >= 0)); + rz_line_completion_clear (completion); + if (argc > completion->args_limit) { + eprintf ("WARNING: Maximum completion capacity reached, increase scr.maxtab"); + } + size_t count = R_MIN (argc, completion->args_limit); + rz_pvector_reserve (&completion->args, count); + int i; + for (i = 0; i < count; i++) { + rz_line_completion_push (completion, argv[i]); + } +} + +RZ_API void rz_line_completion_clear(RLineCompletion *completion) { + rz_return_if_fail (completion); + completion->quit = false; + rz_pvector_clear (&completion->args); +} + +#include "dietline.c" diff --git a/libr/cons/meson.build b/librz/cons/meson.build similarity index 71% rename from libr/cons/meson.build rename to librz/cons/meson.build index 6fcfaff8ad..53b048beec 100644 --- a/libr/cons/meson.build +++ b/librz/cons/meson.build @@ -1,4 +1,4 @@ -r_cons_sources = [ +rz_cons_sources = [ '2048.c', 'canvas.c', 'canvas_line.c', @@ -21,27 +21,27 @@ r_cons_sources = [ 'cutf8.c' ] -r_cons = library('r_cons', r_cons_sources, +rz_cons = library('rz_cons', rz_cons_sources, include_directories: [platform_inc], c_args: library_cflags, - dependencies: [r_util_dep], + dependencies: [rz_util_dep], install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_cons_dep = declare_dependency(link_with: r_cons, +rz_cons_dep = declare_dependency(link_with: rz_cons, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_cons, - subdirs: 'libr', +pkgconfig_mod.generate(rz_cons, + subdirs: 'librz', version: r2_version, - name: 'r_cons', - filebase: 'r_cons', + name: 'rz_cons', + filebase: 'rz_cons', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/cons/more.c b/librz/cons/more.c similarity index 69% rename from libr/cons/more.c rename to librz/cons/more.c index bcad22f5f4..9f5c1521b3 100644 --- a/libr/cons/more.c +++ b/librz/cons/more.c @@ -1,13 +1,13 @@ -/* radare2 - LGPL - Copyright 2008-2019 - pancake */ +/* rizin - LGPL - Copyright 2008-2019 - pancake */ -#include -#include -#include +#include +#include +#include #include "pager_private.h" -R_API int r_cons_more_str(const char *str, const char *exitkeys) { +RZ_API int rz_cons_more_str(const char *str, const char *exitkeys) { static bool inHelp = false; - static const char *r_cons_more_help = \ + static const char *rz_cons_more_help = \ " space - page up\n" " j - line down\n" " / - search in buffer\n" @@ -17,10 +17,10 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { " ? - show this help\n" "\n"; int lines_count = 0; - RRegex *rx = NULL; + RzRegex *rx = NULL; int w, h, ch, to, ui = 1, from = 0, i; const char *sreg; - RList **mla; + RzList **mla; if (!str || !*str) { return 0; @@ -39,7 +39,7 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { if (lines_count < 1) { mla = NULL; } else { - mla = calloc (lines_count, sizeof (RList *)); + mla = calloc (lines_count, sizeof (RzList *)); if (!mla) { free (p); free (ostr); @@ -48,14 +48,14 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { } } for (i = 0; i < lines_count; i++) { - mla[i] = r_list_new (); + mla[i] = rz_list_new (); } - r_cons_set_raw (true); - r_cons_show_cursor (false); - r_cons_reset (); + rz_cons_set_raw (true); + rz_cons_show_cursor (false); + rz_cons_reset (); h = 0; while (ui) { - w = r_cons_get_size (&h); + w = rz_cons_get_size (&h); to = R_MIN (lines_count, from + h); if (from + 3 > lines_count) { from = lines_count - 3; @@ -64,10 +64,10 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { from = 0; } pager_printpage (p, lines, mla, from, to, w); - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (exitkeys && strchr (exitkeys, ch)) { for (i = 0; i < lines_count; i++) { - r_list_free (mla[i]); + rz_list_free (mla[i]); } free (p); free (mla); @@ -75,15 +75,15 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { free (lines); return ch; } - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { case '_': - r_cons_hud_string (ostr); + rz_cons_hud_string (ostr); break; case '?': if (!inHelp) { inHelp = true; - r_cons_more_str (r_cons_more_help, NULL); + rz_cons_more_str (rz_cons_more_help, NULL); inHelp = false; } break; @@ -96,16 +96,16 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { case 'j': from++; break; case 'J': from+=h; break; case '/': /* search */ - r_cons_reset_colors (); - r_line_set_prompt ("/"); - sreg = r_line_readline (); + rz_cons_reset_colors (); + rz_line_set_prompt ("/"); + sreg = rz_line_readline (); from = R_MIN (lines_count - 1, from); /* repeat last search if empty string is provided */ if (sreg[0]) { /* prepare for a new search */ if (rx) { - r_regex_free (rx); + rz_regex_free (rx); } - rx = r_regex_new (sreg, ""); + rx = rz_regex_new (sreg, ""); } else { /* we got an empty string */ from = pager_next_match (from, mla, lines_count); break; @@ -127,19 +127,19 @@ R_API int r_cons_more_str(const char *str, const char *exitkeys) { } } for (i = 0; i < lines_count; i++) { - r_list_free (mla[i]); + rz_list_free (mla[i]); } free (mla); - r_regex_free (rx); + rz_regex_free (rx); free (lines); free (p); - r_cons_reset_colors (); - r_cons_set_raw (false); - r_cons_show_cursor (true); + rz_cons_reset_colors (); + rz_cons_set_raw (false); + rz_cons_show_cursor (true); free (ostr); return 0; } -R_API void r_cons_more(void) { - (void)r_cons_more_str (r_cons_singleton ()->context->buffer, NULL); +RZ_API void rz_cons_more(void) { + (void)rz_cons_more_str (rz_cons_singleton ()->context->buffer, NULL); } diff --git a/libr/cons/output.c b/librz/cons/output.c similarity index 86% rename from libr/cons/output.c rename to librz/cons/output.c index 9b7cdbd835..d8c995ff53 100644 --- a/libr/cons/output.c +++ b/librz/cons/output.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include -#include -#define I r_cons_singleton () +#include +#include +#define I rz_cons_singleton () #if __WINDOWS__ static void __fill_tail(int cols, int lines) { @@ -19,13 +19,13 @@ static void __fill_tail(int cols, int lines) { } } -R_API void r_cons_w32_clear(void) { +RZ_API void rz_cons_w32_clear(void) { static HANDLE hStdout = NULL; static CONSOLE_SCREEN_BUFFER_INFO csbi; COORD startCoords; DWORD dummy; if (I->vtmode) { - r_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN); + rz_cons_strcat (Color_RESET R_CONS_CLEAR_SCREEN); return; } if (I->is_wine == 1) { @@ -47,7 +47,7 @@ R_API void r_cons_w32_clear(void) { nLength, startCoords, &dummy); } -R_API void r_cons_w32_gotoxy(int fd, int x, int y) { +RZ_API void rz_cons_w32_gotoxy(int fd, int x, int y) { static HANDLE hStdout = NULL; static HANDLE hStderr = NULL; HANDLE *hConsole = fd == 1 ? &hStdout : &hStderr; @@ -55,7 +55,7 @@ R_API void r_cons_w32_gotoxy(int fd, int x, int y) { coord.X = x; coord.Y = y; if (I->vtmode) { - r_cons_printf ("\x1b[%d;%dH", y, x); + rz_cons_printf ("\x1b[%d;%dH", y, x); return; } if (I->is_wine == 1) { @@ -74,7 +74,7 @@ R_API void r_cons_w32_gotoxy(int fd, int x, int y) { static int wrapline(const char *s, int len) { int l = 0, n = 0; for (; n < len; ) { - l = r_str_len_utf8char (s+n, (len-n)); + l = rz_str_len_utf8char (s+n, (len-n)); n += l; } return n - ((n > len) ? l : 1); @@ -86,7 +86,7 @@ static int utf8len_fixed(const char *s, int n) { while (s[i] && n > 0) { if ((s[i] & 0xc0) != 0x80) { j++; - if (r_str_char_fullwidth (s + i, n)) { + if (rz_str_char_fullwidth (s + i, n)) { fullwidths++; } } @@ -99,7 +99,7 @@ static int utf8len_fixed(const char *s, int n) { static int bytes_utf8len(const char *s, int n) { int ret = 0; while (n > 0) { - int sz = r_str_utf8_charsize (s); + int sz = rz_str_utf8_charsize (s); ret += sz; s += sz; n--; @@ -107,7 +107,7 @@ static int bytes_utf8len(const char *s, int n) { return ret; } -static int r_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { +static int rz_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { HANDLE hConsole = GetStdHandle (hdl); int fd = hdl == STD_OUTPUT_HANDLE ? 1 : 2; int esc = 0; @@ -118,9 +118,9 @@ static int r_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { int linelen = 0; int ll = 0; int raw_ll = 0; - int lines, cols = r_cons_get_size (&lines); + int lines, cols = rz_cons_get_size (&lines); if (I->is_wine == -1) { - I->is_wine = r_file_is_directory ("/proc")? 1: 0; + I->is_wine = rz_file_is_directory ("/proc")? 1: 0; } if (len < 0) { len = strlen ((const char *)ptr); @@ -247,7 +247,7 @@ static int r_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { } } if (state == -2) { - r_cons_w32_gotoxy (fd, x, y); + rz_cons_w32_gotoxy (fd, x, y); ptr += i; str = ptr; // + i-2; continue; @@ -260,14 +260,14 @@ static int r_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { // fill row here __fill_tail (cols, lines); } - r_cons_w32_gotoxy (fd, 0, 0); + rz_cons_w32_gotoxy (fd, 0, 0); lines = 0; esc = 0; ptr += 3; str = ptr + 1; continue; } else if (ptr[0]=='2'&&ptr[1]=='J') { - r_cons_w32_clear (); + rz_cons_w32_clear (); esc = 0; ptr = ptr + 1; str = ptr + 1; @@ -401,11 +401,11 @@ static int r_cons_w32_hprint(DWORD hdl, const char *ptr, int len, bool vmode) { return ret; } -R_API int r_cons_w32_print(const char *ptr, int len, bool vmode) { - return r_cons_w32_hprint (STD_OUTPUT_HANDLE, ptr, len, vmode); +RZ_API int rz_cons_w32_print(const char *ptr, int len, bool vmode) { + return rz_cons_w32_hprint (STD_OUTPUT_HANDLE, ptr, len, vmode); } -R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap) { +RZ_API int rz_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap) { va_list ap2; int ret = -1; FILE *con = hdl == STD_OUTPUT_HANDLE ? stdout : stderr; @@ -414,7 +414,7 @@ R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap if (I->vtmode) { return fwrite (fmt, 1, len, con); } - return r_cons_w32_hprint (hdl, fmt, len, vmode); + return rz_cons_w32_hprint (hdl, fmt, len, vmode); } va_copy (ap2, ap); int num_chars = vsnprintf (NULL, 0, fmt, ap2); @@ -425,7 +425,7 @@ R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap if (I->vtmode) { ret = fwrite (buf, 1, num_chars - 1, con); } else { - ret = r_cons_w32_hprint (hdl, buf, num_chars - 1, vmode); + ret = rz_cons_w32_hprint (hdl, buf, num_chars - 1, vmode); } free (buf); } @@ -433,24 +433,24 @@ R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap return ret; } -R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) { +RZ_API int rz_cons_win_printf(bool vmode, const char *fmt, ...) { va_list ap; int ret; - r_return_val_if_fail (fmt, -1); + rz_return_val_if_fail (fmt, -1); va_start (ap, fmt); - ret = r_cons_win_vhprintf (STD_OUTPUT_HANDLE, vmode, fmt, ap); + ret = rz_cons_win_vhprintf (STD_OUTPUT_HANDLE, vmode, fmt, ap); va_end (ap); return ret; } -R_API int r_cons_win_eprintf(bool vmode, const char *fmt, ...) { +RZ_API int rz_cons_win_eprintf(bool vmode, const char *fmt, ...) { va_list ap; int ret; - r_return_val_if_fail (fmt, -1); + rz_return_val_if_fail (fmt, -1); va_start (ap, fmt); - ret = r_cons_win_vhprintf (STD_ERROR_HANDLE, vmode, fmt, ap); + ret = rz_cons_win_vhprintf (STD_ERROR_HANDLE, vmode, fmt, ap); va_end (ap); return ret; } diff --git a/libr/cons/pager.c b/librz/cons/pager.c similarity index 60% rename from libr/cons/pager.c rename to librz/cons/pager.c index cdcbd762df..4f2061df84 100644 --- a/libr/cons/pager.c +++ b/librz/cons/pager.c @@ -1,15 +1,15 @@ -/* radare2 - LGPL - Copyright 2019 - pancake */ +/* rizin - LGPL - Copyright 2019 - pancake */ -#include -#include -#include +#include +#include +#include #include "pager_private.h" -R_IPI void pager_color_line(const char *line, RStrpool *p, RList *ml) { +R_IPI void pager_color_line(const char *line, RStrpool *p, RzList *ml) { int m_len, offset = 0; char *m_addr; - RListIter *it; - RRegexMatch *m; + RzListIter *it; + RzRegexMatch *m; char *inv[2] = { R_CONS_INVERT (true, true), R_CONS_INVERT (false, true) @@ -18,89 +18,89 @@ R_IPI void pager_color_line(const char *line, RStrpool *p, RList *ml) { strlen (inv[0]), strlen (inv[1]) }; - r_strpool_empty (p); - r_list_foreach (ml, it, m) { + rz_strpool_empty (p); + rz_list_foreach (ml, it, m) { /* highlight a match */ - r_strpool_memcat (p, line + offset, m->rm_so - offset); - r_strpool_memcat (p, inv[0], linv[0]); + rz_strpool_memcat (p, line + offset, m->rm_so - offset); + rz_strpool_memcat (p, inv[0], linv[0]); m_len = m->rm_eo - m->rm_so; if (m_len < 0) { m_len = 0; } - m_addr = r_str_ndup (line + m->rm_so, m_len); + m_addr = rz_str_ndup (line + m->rm_so, m_len); if (m_addr) { /* in case there's a CSI in the middle of this match*/ - m_len = r_str_ansi_filter (m_addr, NULL, NULL, m_len); + m_len = rz_str_ansi_filter (m_addr, NULL, NULL, m_len); if (m_len < 0) { m_len = 0; } - r_strpool_memcat (p, m_addr, m_len); - r_strpool_memcat (p, inv[1], linv[1]); + rz_strpool_memcat (p, m_addr, m_len); + rz_strpool_memcat (p, inv[1], linv[1]); offset = m->rm_eo; free (m_addr); } } /* append final part of string w/o matches */ - r_strpool_append (p, line + offset); + rz_strpool_append (p, line + offset); } -R_IPI void pager_printpage(const char *line, int *index, RList **mla, int from, int to, int w) { +R_IPI void pager_printpage(const char *line, int *index, RzList **mla, int from, int to, int w) { int i; - r_cons_clear00 (); + rz_cons_clear00 (); if (from < 0 || to < 0) { return; } - RStrpool *p = r_strpool_new (0); + RStrpool *p = rz_strpool_new (0); if (!p) { return; } for (i = from; i < to; i++) { pager_color_line (line + index[i], p, mla[i]); - r_strpool_ansi_chop (p, w); - r_cons_reset_colors (); + rz_strpool_ansi_chop (p, w); + rz_cons_reset_colors (); if (i + 1 == to) { - r_cons_print (p->str); + rz_cons_print (p->str); } else { - r_cons_println (p->str); + rz_cons_println (p->str); } } - r_strpool_free (p); - r_cons_flush (); + rz_strpool_free (p); + rz_cons_flush (); } -R_IPI int pager_next_match(int from, RList **mla, int lcount) { +R_IPI int pager_next_match(int from, RzList **mla, int lcount) { int l; if (from > lcount - 2) { return from; } for (l = from + 1; l < lcount; l++){ /* if there's at least one match on the line */ - if (r_list_first (mla[l])) { + if (rz_list_first (mla[l])) { return l; } } return from; } -R_IPI int pager_prev_match(int from, RList **mla) { +R_IPI int pager_prev_match(int from, RzList **mla) { int l; if (from < 1) { return from; } for (l = from - 1; l > 0; l--) { - if (r_list_first (mla[l])) { + if (rz_list_first (mla[l])) { return l; } } return from; } -R_IPI bool pager_all_matches(const char *s, RRegex *rx, RList **mla, int *lines, int lcount) { +R_IPI bool pager_all_matches(const char *s, RzRegex *rx, RzList **mla, int *lines, int lcount) { bool res = false; - RRegexMatch m; + RzRegexMatch m; int l, slen; for (l = 0; l < lcount; l++) { m.rm_so = 0; @@ -110,18 +110,18 @@ R_IPI bool pager_all_matches(const char *s, RRegex *rx, RList **mla, int *lines, return false; } int *cpos = NULL; - int ncpos = r_str_ansi_filter (clean, NULL, &cpos, -1); + int ncpos = rz_str_ansi_filter (clean, NULL, &cpos, -1); m.rm_eo = slen = strlen (clean); - r_list_purge (mla[l]); - while (!r_regex_exec (rx, clean, 1, &m, R_REGEX_STARTEND)) { + rz_list_purge (mla[l]); + while (!rz_regex_exec (rx, clean, 1, &m, R_REGEX_STARTEND)) { if (!cpos || m.rm_so >= ncpos) { break; } - RRegexMatch *ms = R_NEW0 (RRegexMatch); + RzRegexMatch *ms = R_NEW0 (RzRegexMatch); if (ms && cpos) { ms->rm_so = cpos[m.rm_so]; ms->rm_eo = cpos[m.rm_eo]; - r_list_append (mla[l], ms); + rz_list_append (mla[l], ms); } m.rm_so = m.rm_eo; m.rm_eo = slen; diff --git a/librz/cons/pager_private.h b/librz/cons/pager_private.h new file mode 100644 index 0000000000..f1fc91dcff --- /dev/null +++ b/librz/cons/pager_private.h @@ -0,0 +1,11 @@ +#ifndef PAGER_PRIVATE_H +#define PAGER_PRIVATE_H + +R_IPI void pager_color_line(const char *line, RStrpool *p, RzList *ml); +R_IPI void pager_printpage(const char *line, int *index, RzList **mla, int from, int to, int w); +R_IPI int pager_next_match(int from, RzList **mla, int lcount); +R_IPI int pager_prev_match(int from, RzList **mla); +R_IPI bool pager_all_matches(const char *s, RzRegex *rx, RzList **mla, int *lines, int lcount); +R_IPI int *pager_splitlines(char *s, int *lines_count); + +#endif diff --git a/libr/cons/pal.c b/librz/cons/pal.c similarity index 58% rename from libr/cons/pal.c rename to librz/cons/pal.c index 8e9b6eb416..674758a0be 100644 --- a/libr/cons/pal.c +++ b/librz/cons/pal.c @@ -1,89 +1,89 @@ /* radare - LGPL - Copyright 2013-2020 - pancake, sghctoma, xarkes */ -#include +#include -#define RCOLOR_AT(i) (RColor *) (((ut8 *) &(r_cons_singleton ()->context->cpal)) + keys[i].coff) -#define COLOR_AT(i) (char **) (((ut8 *) &(r_cons_singleton ()->context->pal)) + keys[i].off) +#define RCOLOR_AT(i) (RColor *) (((ut8 *) &(rz_cons_singleton ()->context->cpal)) + keys[i].coff) +#define COLOR_AT(i) (char **) (((ut8 *) &(rz_cons_singleton ()->context->pal)) + keys[i].off) static struct { const char *name; - int off; // RConsPrintablePalette offset - int coff; // RConsPalette offset + int off; // RzConsPrintablePalette offset + int coff; // RzConsPalette offset } keys[] = { - { "comment", r_offsetof (RConsPrintablePalette, comment), r_offsetof (RConsPalette, comment) }, - { "usrcmt", r_offsetof (RConsPrintablePalette, usercomment), r_offsetof (RConsPalette, usercomment) }, - { "args", r_offsetof (RConsPrintablePalette, args), r_offsetof (RConsPalette, args) }, - { "fname", r_offsetof (RConsPrintablePalette, fname), r_offsetof (RConsPalette, fname) }, - { "floc", r_offsetof (RConsPrintablePalette, floc), r_offsetof (RConsPalette, floc) }, - { "fline", r_offsetof (RConsPrintablePalette, fline), r_offsetof (RConsPalette, fline) }, - { "flag", r_offsetof (RConsPrintablePalette, flag), r_offsetof (RConsPalette, flag) }, - { "label", r_offsetof (RConsPrintablePalette, label), r_offsetof (RConsPalette, label) }, - { "help", r_offsetof (RConsPrintablePalette, help), r_offsetof (RConsPalette, help) }, - { "flow", r_offsetof (RConsPrintablePalette, flow), r_offsetof (RConsPalette, flow) }, - { "flow2", r_offsetof (RConsPrintablePalette, flow2), r_offsetof (RConsPalette, flow2) }, - { "prompt", r_offsetof (RConsPrintablePalette, prompt), r_offsetof (RConsPalette, prompt) }, - { "offset", r_offsetof (RConsPrintablePalette, offset), r_offsetof (RConsPalette, offset) }, - { "input", r_offsetof (RConsPrintablePalette, input), r_offsetof (RConsPalette, input) }, - { "invalid", r_offsetof (RConsPrintablePalette, invalid), r_offsetof (RConsPalette, invalid) }, - { "other", r_offsetof (RConsPrintablePalette, other), r_offsetof (RConsPalette, other) }, - { "b0x00", r_offsetof (RConsPrintablePalette, b0x00), r_offsetof (RConsPalette, b0x00) }, - { "b0x7f", r_offsetof (RConsPrintablePalette, b0x7f), r_offsetof (RConsPalette, b0x7f) }, - { "b0xff", r_offsetof (RConsPrintablePalette, b0xff), r_offsetof (RConsPalette, b0xff) }, - { "math", r_offsetof (RConsPrintablePalette, math), r_offsetof (RConsPalette, math) }, - { "bin", r_offsetof (RConsPrintablePalette, bin), r_offsetof (RConsPalette, bin) }, - { "btext", r_offsetof (RConsPrintablePalette, btext), r_offsetof (RConsPalette, btext) }, - { "push", r_offsetof (RConsPrintablePalette, push), r_offsetof (RConsPalette, push) }, - { "pop", r_offsetof (RConsPrintablePalette, pop), r_offsetof (RConsPalette, pop) }, - { "crypto", r_offsetof (RConsPrintablePalette, crypto), r_offsetof (RConsPalette, crypto) }, - { "jmp", r_offsetof (RConsPrintablePalette, jmp), r_offsetof (RConsPalette, jmp) }, - { "cjmp", r_offsetof (RConsPrintablePalette, cjmp), r_offsetof (RConsPalette, cjmp) }, - { "call", r_offsetof (RConsPrintablePalette, call), r_offsetof (RConsPalette, call) }, - { "nop", r_offsetof (RConsPrintablePalette, nop), r_offsetof (RConsPalette, nop) }, - { "ret", r_offsetof (RConsPrintablePalette, ret), r_offsetof (RConsPalette, ret) }, - { "trap", r_offsetof (RConsPrintablePalette, trap), r_offsetof (RConsPalette, trap) }, - { "ucall", r_offsetof (RConsPrintablePalette, ucall), r_offsetof (RConsPalette, ucall) }, - { "ujmp", r_offsetof (RConsPrintablePalette, ujmp), r_offsetof (RConsPalette, ujmp) }, - { "swi", r_offsetof (RConsPrintablePalette, swi), r_offsetof (RConsPalette, swi) }, - { "cmp", r_offsetof (RConsPrintablePalette, cmp), r_offsetof (RConsPalette, cmp) }, - { "reg", r_offsetof (RConsPrintablePalette, reg), r_offsetof (RConsPalette, reg) }, - { "creg", r_offsetof (RConsPrintablePalette, creg), r_offsetof (RConsPalette, creg) }, - { "num", r_offsetof (RConsPrintablePalette, num), r_offsetof (RConsPalette, num) }, - { "mov", r_offsetof (RConsPrintablePalette, mov), r_offsetof (RConsPalette, mov) }, - { "func_var", r_offsetof (RConsPrintablePalette, func_var), r_offsetof (RConsPalette, func_var) }, - { "func_var_type", r_offsetof (RConsPrintablePalette, func_var_type), r_offsetof (RConsPalette, func_var_type) }, - { "func_var_addr", r_offsetof (RConsPrintablePalette, func_var_addr), r_offsetof (RConsPalette, func_var_addr) }, - { "widget_bg", r_offsetof (RConsPrintablePalette, widget_bg), r_offsetof (RConsPalette, widget_bg) }, - { "widget_sel", r_offsetof (RConsPrintablePalette, widget_sel), r_offsetof (RConsPalette, widget_sel) }, + { "comment", rz_offsetof (RzConsPrintablePalette, comment), rz_offsetof (RzConsPalette, comment) }, + { "usrcmt", rz_offsetof (RzConsPrintablePalette, usercomment), rz_offsetof (RzConsPalette, usercomment) }, + { "args", rz_offsetof (RzConsPrintablePalette, args), rz_offsetof (RzConsPalette, args) }, + { "fname", rz_offsetof (RzConsPrintablePalette, fname), rz_offsetof (RzConsPalette, fname) }, + { "floc", rz_offsetof (RzConsPrintablePalette, floc), rz_offsetof (RzConsPalette, floc) }, + { "fline", rz_offsetof (RzConsPrintablePalette, fline), rz_offsetof (RzConsPalette, fline) }, + { "flag", rz_offsetof (RzConsPrintablePalette, flag), rz_offsetof (RzConsPalette, flag) }, + { "label", rz_offsetof (RzConsPrintablePalette, label), rz_offsetof (RzConsPalette, label) }, + { "help", rz_offsetof (RzConsPrintablePalette, help), rz_offsetof (RzConsPalette, help) }, + { "flow", rz_offsetof (RzConsPrintablePalette, flow), rz_offsetof (RzConsPalette, flow) }, + { "flow2", rz_offsetof (RzConsPrintablePalette, flow2), rz_offsetof (RzConsPalette, flow2) }, + { "prompt", rz_offsetof (RzConsPrintablePalette, prompt), rz_offsetof (RzConsPalette, prompt) }, + { "offset", rz_offsetof (RzConsPrintablePalette, offset), rz_offsetof (RzConsPalette, offset) }, + { "input", rz_offsetof (RzConsPrintablePalette, input), rz_offsetof (RzConsPalette, input) }, + { "invalid", rz_offsetof (RzConsPrintablePalette, invalid), rz_offsetof (RzConsPalette, invalid) }, + { "other", rz_offsetof (RzConsPrintablePalette, other), rz_offsetof (RzConsPalette, other) }, + { "b0x00", rz_offsetof (RzConsPrintablePalette, b0x00), rz_offsetof (RzConsPalette, b0x00) }, + { "b0x7f", rz_offsetof (RzConsPrintablePalette, b0x7f), rz_offsetof (RzConsPalette, b0x7f) }, + { "b0xff", rz_offsetof (RzConsPrintablePalette, b0xff), rz_offsetof (RzConsPalette, b0xff) }, + { "math", rz_offsetof (RzConsPrintablePalette, math), rz_offsetof (RzConsPalette, math) }, + { "bin", rz_offsetof (RzConsPrintablePalette, bin), rz_offsetof (RzConsPalette, bin) }, + { "btext", rz_offsetof (RzConsPrintablePalette, btext), rz_offsetof (RzConsPalette, btext) }, + { "push", rz_offsetof (RzConsPrintablePalette, push), rz_offsetof (RzConsPalette, push) }, + { "pop", rz_offsetof (RzConsPrintablePalette, pop), rz_offsetof (RzConsPalette, pop) }, + { "crypto", rz_offsetof (RzConsPrintablePalette, crypto), rz_offsetof (RzConsPalette, crypto) }, + { "jmp", rz_offsetof (RzConsPrintablePalette, jmp), rz_offsetof (RzConsPalette, jmp) }, + { "cjmp", rz_offsetof (RzConsPrintablePalette, cjmp), rz_offsetof (RzConsPalette, cjmp) }, + { "call", rz_offsetof (RzConsPrintablePalette, call), rz_offsetof (RzConsPalette, call) }, + { "nop", rz_offsetof (RzConsPrintablePalette, nop), rz_offsetof (RzConsPalette, nop) }, + { "ret", rz_offsetof (RzConsPrintablePalette, ret), rz_offsetof (RzConsPalette, ret) }, + { "trap", rz_offsetof (RzConsPrintablePalette, trap), rz_offsetof (RzConsPalette, trap) }, + { "ucall", rz_offsetof (RzConsPrintablePalette, ucall), rz_offsetof (RzConsPalette, ucall) }, + { "ujmp", rz_offsetof (RzConsPrintablePalette, ujmp), rz_offsetof (RzConsPalette, ujmp) }, + { "swi", rz_offsetof (RzConsPrintablePalette, swi), rz_offsetof (RzConsPalette, swi) }, + { "cmp", rz_offsetof (RzConsPrintablePalette, cmp), rz_offsetof (RzConsPalette, cmp) }, + { "reg", rz_offsetof (RzConsPrintablePalette, reg), rz_offsetof (RzConsPalette, reg) }, + { "creg", rz_offsetof (RzConsPrintablePalette, creg), rz_offsetof (RzConsPalette, creg) }, + { "num", rz_offsetof (RzConsPrintablePalette, num), rz_offsetof (RzConsPalette, num) }, + { "mov", rz_offsetof (RzConsPrintablePalette, mov), rz_offsetof (RzConsPalette, mov) }, + { "func_var", rz_offsetof (RzConsPrintablePalette, func_var), rz_offsetof (RzConsPalette, func_var) }, + { "func_var_type", rz_offsetof (RzConsPrintablePalette, func_var_type), rz_offsetof (RzConsPalette, func_var_type) }, + { "func_var_addr", rz_offsetof (RzConsPrintablePalette, func_var_addr), rz_offsetof (RzConsPalette, func_var_addr) }, + { "widget_bg", rz_offsetof (RzConsPrintablePalette, widget_bg), rz_offsetof (RzConsPalette, widget_bg) }, + { "widget_sel", rz_offsetof (RzConsPrintablePalette, widget_sel), rz_offsetof (RzConsPalette, widget_sel) }, - { "ai.read", r_offsetof (RConsPrintablePalette, ai_read), r_offsetof (RConsPalette, ai_read) }, - { "ai.write", r_offsetof (RConsPrintablePalette, ai_write), r_offsetof (RConsPalette, ai_write) }, - { "ai.exec", r_offsetof (RConsPrintablePalette, ai_exec), r_offsetof (RConsPalette, ai_exec) }, - { "ai.seq", r_offsetof (RConsPrintablePalette, ai_seq), r_offsetof (RConsPalette, ai_seq) }, - { "ai.ascii", r_offsetof (RConsPrintablePalette, ai_ascii), r_offsetof (RConsPalette, ai_ascii) }, + { "ai.read", rz_offsetof (RzConsPrintablePalette, ai_read), rz_offsetof (RzConsPalette, ai_read) }, + { "ai.write", rz_offsetof (RzConsPrintablePalette, ai_write), rz_offsetof (RzConsPalette, ai_write) }, + { "ai.exec", rz_offsetof (RzConsPrintablePalette, ai_exec), rz_offsetof (RzConsPalette, ai_exec) }, + { "ai.seq", rz_offsetof (RzConsPrintablePalette, ai_seq), rz_offsetof (RzConsPalette, ai_seq) }, + { "ai.ascii", rz_offsetof (RzConsPrintablePalette, ai_ascii), rz_offsetof (RzConsPalette, ai_ascii) }, - { "graph.box", r_offsetof (RConsPrintablePalette, graph_box), r_offsetof (RConsPalette, graph_box) }, - { "graph.box2", r_offsetof (RConsPrintablePalette, graph_box2), r_offsetof (RConsPalette, graph_box2) }, - { "graph.box3", r_offsetof (RConsPrintablePalette, graph_box3), r_offsetof (RConsPalette, graph_box3) }, - { "graph.box4", r_offsetof (RConsPrintablePalette, graph_box4), r_offsetof (RConsPalette, graph_box4) }, - { "graph.true", r_offsetof (RConsPrintablePalette, graph_true), r_offsetof (RConsPalette, graph_true) }, - { "graph.false", r_offsetof (RConsPrintablePalette, graph_false), r_offsetof (RConsPalette, graph_false) }, - { "graph.trufae", r_offsetof (RConsPrintablePalette, graph_trufae), r_offsetof (RConsPalette, graph_trufae) }, - { "graph.current", r_offsetof (RConsPrintablePalette, graph_current), r_offsetof (RConsPalette, graph_current) }, - { "graph.traced", r_offsetof (RConsPrintablePalette, graph_traced), r_offsetof (RConsPalette, graph_traced) }, + { "graph.box", rz_offsetof (RzConsPrintablePalette, graph_box), rz_offsetof (RzConsPalette, graph_box) }, + { "graph.box2", rz_offsetof (RzConsPrintablePalette, graph_box2), rz_offsetof (RzConsPalette, graph_box2) }, + { "graph.box3", rz_offsetof (RzConsPrintablePalette, graph_box3), rz_offsetof (RzConsPalette, graph_box3) }, + { "graph.box4", rz_offsetof (RzConsPrintablePalette, graph_box4), rz_offsetof (RzConsPalette, graph_box4) }, + { "graph.true", rz_offsetof (RzConsPrintablePalette, graph_true), rz_offsetof (RzConsPalette, graph_true) }, + { "graph.false", rz_offsetof (RzConsPrintablePalette, graph_false), rz_offsetof (RzConsPalette, graph_false) }, + { "graph.trufae", rz_offsetof (RzConsPrintablePalette, graph_trufae), rz_offsetof (RzConsPalette, graph_trufae) }, + { "graph.current", rz_offsetof (RzConsPrintablePalette, graph_current), rz_offsetof (RzConsPalette, graph_current) }, + { "graph.traced", rz_offsetof (RzConsPrintablePalette, graph_traced), rz_offsetof (RzConsPalette, graph_traced) }, - { "graph.diff.unknown", r_offsetof (RConsPrintablePalette, graph_diff_unknown), r_offsetof (RConsPalette, graph_diff_unknown) }, - { "graph.diff.new", r_offsetof (RConsPrintablePalette, graph_diff_new), r_offsetof (RConsPalette, graph_diff_new) }, - { "graph.diff.match", r_offsetof (RConsPrintablePalette, graph_diff_match), r_offsetof (RConsPalette, graph_diff_match) }, - { "graph.diff.unmatch", r_offsetof (RConsPrintablePalette, graph_diff_unmatch), r_offsetof (RConsPalette, graph_diff_unmatch) }, + { "graph.diff.unknown", rz_offsetof (RzConsPrintablePalette, graph_diff_unknown), rz_offsetof (RzConsPalette, graph_diff_unknown) }, + { "graph.diff.new", rz_offsetof (RzConsPrintablePalette, graph_diff_new), rz_offsetof (RzConsPalette, graph_diff_new) }, + { "graph.diff.match", rz_offsetof (RzConsPrintablePalette, graph_diff_match), rz_offsetof (RzConsPalette, graph_diff_match) }, + { "graph.diff.unmatch", rz_offsetof (RzConsPrintablePalette, graph_diff_unmatch), rz_offsetof (RzConsPalette, graph_diff_unmatch) }, - { "gui.cflow", r_offsetof (RConsPrintablePalette, gui_cflow), r_offsetof (RConsPalette, gui_cflow) }, - { "gui.dataoffset", r_offsetof (RConsPrintablePalette, gui_dataoffset), r_offsetof (RConsPalette, gui_dataoffset) }, - { "gui.background", r_offsetof (RConsPrintablePalette, gui_background), r_offsetof (RConsPalette, gui_background) }, - { "gui.alt_background", r_offsetof (RConsPrintablePalette, gui_alt_background), r_offsetof (RConsPalette, gui_alt_background) }, - { "gui.border", r_offsetof (RConsPrintablePalette, gui_border), r_offsetof (RConsPalette, gui_border) }, - { "wordhl", r_offsetof (RConsPrintablePalette, wordhl), r_offsetof (RConsPalette, wordhl) }, - { "linehl", r_offsetof (RConsPrintablePalette, linehl), r_offsetof (RConsPalette, linehl) }, + { "gui.cflow", rz_offsetof (RzConsPrintablePalette, gui_cflow), rz_offsetof (RzConsPalette, gui_cflow) }, + { "gui.dataoffset", rz_offsetof (RzConsPrintablePalette, gui_dataoffset), rz_offsetof (RzConsPalette, gui_dataoffset) }, + { "gui.background", rz_offsetof (RzConsPrintablePalette, gui_background), rz_offsetof (RzConsPalette, gui_background) }, + { "gui.alt_background", rz_offsetof (RzConsPrintablePalette, gui_alt_background), rz_offsetof (RzConsPalette, gui_alt_background) }, + { "gui.border", rz_offsetof (RzConsPrintablePalette, gui_border), rz_offsetof (RzConsPalette, gui_border) }, + { "wordhl", rz_offsetof (RzConsPrintablePalette, wordhl), rz_offsetof (RzConsPalette, wordhl) }, + { "linehl", rz_offsetof (RzConsPrintablePalette, linehl), rz_offsetof (RzConsPalette, linehl) }, { NULL, 0, 0 } @@ -119,12 +119,12 @@ struct { static inline ut8 rgbnum(const char ch1, const char ch2) { ut8 r = 0, r2 = 0; - r_hex_to_byte (&r, ch1); - r_hex_to_byte (&r2, ch2); + rz_hex_to_byte (&r, ch1); + rz_hex_to_byte (&r2, ch2); return r << 4 | r2; } -static void __cons_pal_update_event(RConsContext *ctx) { +static void __cons_pal_update_event(RzConsContext *ctx) { Sdb *db = sdb_new0 (); int i, n = 0; /* Compute cons->pal values */ @@ -133,15 +133,15 @@ static void __cons_pal_update_event(RConsContext *ctx) { char **color = (char **) (((ut8 *) &(ctx->pal)) + keys[i].off); // Color is dynamically allocated, needs to be freed R_FREE (*color); - *color = r_cons_rgb_str_mode (ctx->color_mode, NULL, 0, rcolor); + *color = rz_cons_rgb_str_mode (ctx->color_mode, NULL, 0, rcolor); const char *rgb = sdb_fmt ("rgb:%02x%02x%02x", rcolor->r, rcolor->g, rcolor->b); sdb_set (db, rgb, "1", 0); } SdbList *list = sdb_foreach_list (db, true); SdbListIter *iter; SdbKv *kv; - r_cons_rainbow_free (ctx); - r_cons_rainbow_new (ctx, list->length); + rz_cons_rainbow_free (ctx); + rz_cons_rainbow_new (ctx, list->length); ls_foreach (list, iter, kv) { ctx->pal.rainbow[n++] = strdup (sdbkv_key (kv)); } @@ -150,7 +150,7 @@ static void __cons_pal_update_event(RConsContext *ctx) { sdb_free (db); } -R_API void r_cons_pal_init(RConsContext *ctx) { +RZ_API void rz_cons_pal_init(RzConsContext *ctx) { memset (&ctx->cpal, 0, sizeof (ctx->cpal)); ctx->cpal.b0x00 = (RColor) RColor_GREEN; @@ -238,12 +238,12 @@ R_API void r_cons_pal_init(RConsContext *ctx) { ctx->cpal.graph_diff_unmatch = (RColor) RColor_YELLOW; - r_cons_pal_free (ctx); + rz_cons_pal_free (ctx); ctx->pal.reset = Color_RESET; // reset is not user accessible, const char* is ok __cons_pal_update_event (ctx); } -R_API void r_cons_pal_free(RConsContext *ctx) { +RZ_API void rz_cons_pal_free(RzConsContext *ctx) { int i; for (i = 0; keys[i].name; i++) { char **color = (char **) (((ut8 *) &(ctx->pal)) + keys[i].off); @@ -251,10 +251,10 @@ R_API void r_cons_pal_free(RConsContext *ctx) { R_FREE (*color); } } - r_cons_rainbow_free (ctx); + rz_cons_rainbow_free (ctx); } -R_API void r_cons_pal_copy(RConsContext *dst, RConsContext *src) { +RZ_API void rz_cons_pal_copy(RzConsContext *dst, RzConsContext *src) { memcpy (&dst->cpal, &src->cpal, sizeof (src->cpal)); memset (&dst->pal, 0, sizeof (dst->pal)); @@ -266,18 +266,18 @@ R_API void r_cons_pal_copy(RConsContext *dst, RConsContext *src) { __cons_pal_update_event (dst); } -R_API void r_cons_pal_random(void) { +RZ_API void rz_cons_pal_random(void) { int i; RColor *rcolor; for (i = 0; keys[i].name; i++) { rcolor = RCOLOR_AT (i); - *rcolor = r_cons_color_random (ALPHA_FG); + *rcolor = rz_cons_color_random (ALPHA_FG); } - r_cons_pal_update_event (); + rz_cons_pal_update_event (); } /* Return NULL if outcol is given */ -R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { +RZ_API char *rz_cons_pal_parse(const char *str, RColor *outcol) { int i; RColor rcolor = (RColor) RColor_BLACK; rcolor.id16 = -1; @@ -304,9 +304,9 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { // Handle first color (fgcolor) if (!strcmp (fgcolor, "random")) { - rcolor = r_cons_color_random (ALPHA_FG); + rcolor = rz_cons_color_random (ALPHA_FG); if (!outcol) { - r_cons_rgb_str (out, sizeof (out), &rcolor); + rz_cons_rgb_str (out, sizeof (out), &rcolor); } } else if (!strncmp (fgcolor, "#", 1)) { // "#00ff00" HTML format if (strlen (fgcolor) == 7) { @@ -315,7 +315,7 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { eprintf ("Error while parsing HTML color: %s\n", fgcolor); } if (!outcol) { - r_cons_rgb_str (out, sizeof (out), &rcolor); + rz_cons_rgb_str (out, sizeof (out), &rcolor); } } else { eprintf ("Invalid html color code\n"); @@ -326,14 +326,14 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { rcolor.g = rgbnum (fgcolor[5], '0'); rcolor.b = rgbnum (fgcolor[6], '0'); if (!outcol) { - r_cons_rgb_str (out, sizeof (out), &rcolor); + rz_cons_rgb_str (out, sizeof (out), &rcolor); } } else if (strlen (fgcolor) == 10) { rcolor.r = rgbnum (fgcolor[4], fgcolor[5]); rcolor.g = rgbnum (fgcolor[6], fgcolor[7]); rcolor.b = rgbnum (fgcolor[8], fgcolor[9]); if (!outcol) { - r_cons_rgb_str (out, sizeof (out), &rcolor); + rz_cons_rgb_str (out, sizeof (out), &rcolor); } } } @@ -346,7 +346,7 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { rcolor.b2 = rgbnum (bgcolor[6], '0'); if (!outcol) { size_t len = strlen (out); - r_cons_rgb_str (out + len, sizeof (out) - len, &rcolor); + rz_cons_rgb_str (out + len, sizeof (out) - len, &rcolor); } } else if (strlen (bgcolor) == 10) { rcolor.a |= ALPHA_BG; @@ -355,7 +355,7 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { rcolor.b2 = rgbnum (bgcolor[8], bgcolor[9]); if (!outcol) { size_t len = strlen (out); - r_cons_rgb_str (out + len, sizeof (out) - len, &rcolor); + rz_cons_rgb_str (out + len, sizeof (out) - len, &rcolor); } } } @@ -417,9 +417,9 @@ R_API char *r_cons_pal_parse(const char *str, RColor *outcol) { return (*out && !outcol) ? strdup (out) : NULL; } -static void r_cons_pal_show_gs(void) { +static void rz_cons_pal_show_gs(void) { int i, n; - r_cons_print ("\nGreyscale:\n"); + rz_cons_print ("\nGreyscale:\n"); RColor rcolor = RColor_BLACK; for (i = 0x08, n = 0; i <= 0xee; i += 0xa) { char fg[32], bg[32]; @@ -432,19 +432,19 @@ static void r_cons_pal_show_gs(void) { } else { strcpy (fg, Color_BLACK); } - r_cons_rgb_str (bg, sizeof (bg), &rcolor); - r_cons_printf ("%s%s rgb:%02x%02x%02x "Color_RESET, + rz_cons_rgb_str (bg, sizeof (bg), &rcolor); + rz_cons_printf ("%s%s rgb:%02x%02x%02x "Color_RESET, fg, bg, i, i, i); if (n++ == 5) { n = 0; - r_cons_newline (); + rz_cons_newline (); } } } -static void r_cons_pal_show_256(void) { +static void rz_cons_pal_show_256(void) { RColor rc = RColor_BLACK; - r_cons_print ("\n\nXTerm colors:\n"); + rz_cons_print ("\n\nXTerm colors:\n"); int r = 0; int g = 0; int b = 0; @@ -465,20 +465,20 @@ static void r_cons_pal_show_256(void) { rc.g = 0x5f; } const char *fg = ((rc.r <= 0x5f) && (rc.g <= 0x5f)) ? Color_WHITE: Color_BLACK; - r_cons_rgb_str (bg, sizeof (bg), &rc); - r_cons_printf ("%s%s rgb:%02x%02x%02x " + rz_cons_rgb_str (bg, sizeof (bg), &rc); + rz_cons_printf ("%s%s rgb:%02x%02x%02x " Color_RESET, fg, bg, rc.r, rc.g, rc.b); } - r_cons_newline (); + rz_cons_newline (); } } } -static void r_cons_pal_show_rgb(void) { +static void rz_cons_pal_show_rgb(void) { const int inc = 3; int i, j, k, n = 0; RColor rc = RColor_BLACK; - r_cons_print ("\n\nRGB:\n"); + rz_cons_print ("\n\nRGB:\n"); for (i = n = 0; i <= 0xf; i += inc) { for (k = 0; k <= 0xf; k += inc) { for (j = 0; j <= 0xf; j += inc) { @@ -488,34 +488,34 @@ static void r_cons_pal_show_rgb(void) { rc.b = k * 16; strcpy (fg, ((i < 6) && (j < 5)) ? Color_WHITE: Color_BLACK); - r_cons_rgb_str (bg, sizeof (bg), &rc); - r_cons_printf ("%s%s rgb:%02x%02x%02x " + rz_cons_rgb_str (bg, sizeof (bg), &rc); + rz_cons_printf ("%s%s rgb:%02x%02x%02x " Color_RESET, fg, bg, rc.r, rc.g, rc.b); if (n ++== 5) { n = 0; - r_cons_newline (); + rz_cons_newline (); } } } } } -R_API void r_cons_pal_show(void) { +RZ_API void rz_cons_pal_show(void) { int i; for (i = 0; colors[i].name; i++) { - r_cons_printf ("%s%s__"Color_RESET" %s\n", + rz_cons_printf ("%s%s__"Color_RESET" %s\n", colors[i].code, colors[i].bgcode, colors[i].name); } - switch (r_cons_singleton ()->context->color_mode) { + switch (rz_cons_singleton ()->context->color_mode) { case COLOR_MODE_256: // 256 color palette - r_cons_pal_show_gs (); - r_cons_pal_show_256 (); + rz_cons_pal_show_gs (); + rz_cons_pal_show_256 (); break; case COLOR_MODE_16M: // 16M (truecolor) - r_cons_pal_show_gs (); - r_cons_pal_show_rgb (); + rz_cons_pal_show_gs (); + rz_cons_pal_show_rgb (); break; default: break; @@ -527,12 +527,12 @@ typedef struct { const char *str; } RAttrStr; -R_API void r_cons_pal_list(int rad, const char *arg) { +RZ_API void rz_cons_pal_list(int rad, const char *arg) { char *name, **color; const char *hasnext; int i; if (rad == 'j') { - r_cons_print ("{"); + rz_cons_print ("{"); } for (i = 0; keys[i].name; i++) { RColor *rcolor = RCOLOR_AT (i); @@ -540,11 +540,11 @@ R_API void r_cons_pal_list(int rad, const char *arg) { switch (rad) { case 'j': hasnext = (keys[i + 1].name) ? "," : ""; - r_cons_printf ("\"%s\":[%d,%d,%d]%s", + rz_cons_printf ("\"%s\":[%d,%d,%d]%s", keys[i].name, rcolor->r, rcolor->g, rcolor->b, hasnext); break; case 'c': { - const char *prefix = r_str_trim_head_ro (arg); + const char *prefix = rz_str_trim_head_ro (arg); if (!prefix) { prefix = ""; } @@ -557,25 +557,25 @@ R_API void r_cons_pal_list(int rad, const char *arg) { name[j] = '_'; } } - r_cons_printf (".%s%s { color: rgb(%d, %d, %d); }%s", + rz_cons_printf (".%s%s { color: rgb(%d, %d, %d); }%s", prefix, name, rcolor->r, rcolor->g, rcolor->b, hasnext); free (name); } break; case 'h': name = strdup (keys[i].name); - r_str_replace_char (name, '.', '_'); - r_cons_printf (".%s { color:#%02x%02x%02x }\n", + rz_str_replace_char (name, '.', '_'); + rz_cons_printf (".%s { color:#%02x%02x%02x }\n", name, rcolor->r, rcolor->g, rcolor->b); free (name); break; case '*': case 'r': case 1: - r_cons_printf ("ec %s rgb:%02x%02x%02x", + rz_cons_printf ("ec %s rgb:%02x%02x%02x", keys[i].name, rcolor->r, rcolor->g, rcolor->b); if (rcolor->a == ALPHA_FGBG) { - r_cons_printf (" rgb:%02x%02x%02x", + rz_cons_printf (" rgb:%02x%02x%02x", rcolor->r2, rcolor->g2, rcolor->b2); } if (rcolor->attr) { @@ -588,45 +588,45 @@ R_API void r_cons_pal_list(int rad, const char *arg) { }; int j; if (rcolor->a != ALPHA_FGBG) { - r_cons_strcat (" ."); + rz_cons_strcat (" ."); } for (j = 0; j < R_ARRAY_SIZE (attrs); j++) { if (rcolor->attr & attrs[j].val) { - r_cons_printf (" %s", attrs[j].str); + rz_cons_printf (" %s", attrs[j].str); } } } - r_cons_newline (); + rz_cons_newline (); break; default: - r_cons_printf (" %s##"Color_RESET" %s\n", *color, + rz_cons_printf (" %s##"Color_RESET" %s\n", *color, keys[i].name); } } if (rad == 'j') { - r_cons_print ("}\n"); + rz_cons_print ("}\n"); } } /* Modify the palette to set a color value. - * r_cons_pal_update_event () must be called after this function + * rz_cons_pal_update_event () must be called after this function * so the changes take effect. */ -R_API int r_cons_pal_set(const char *key, const char *val) { +RZ_API int rz_cons_pal_set(const char *key, const char *val) { int i; RColor *rcolor; for (i = 0; keys[i].name; i++) { if (!strcmp (key, keys[i].name)) { rcolor = RCOLOR_AT (i); - r_cons_pal_parse (val, rcolor); + rz_cons_pal_parse (val, rcolor); return true; } } - eprintf ("r_cons_pal_set: Invalid color %s\n", key); + eprintf ("rz_cons_pal_set: Invalid color %s\n", key); return false; } /* Get the named RColor */ -R_API RColor r_cons_pal_get(const char *key) { +RZ_API RColor rz_cons_pal_get(const char *key) { int i; RColor *rcolor; for (i = 0; keys[i].name; i++) { @@ -639,30 +639,30 @@ R_API RColor r_cons_pal_get(const char *key) { } /* Get the RColor at specified index */ -R_API RColor r_cons_pal_get_i(int index) { +RZ_API RColor rz_cons_pal_get_i(int index) { return *(RCOLOR_AT (index)); } /* Get color name at index */ -R_API const char *r_cons_pal_get_name(int index) { +RZ_API const char *rz_cons_pal_get_name(int index) { return (index >= 0 && index < keys_len) ? keys[index].name : NULL; } -R_API int r_cons_pal_len(void) { +RZ_API int rz_cons_pal_len(void) { return keys_len; } -R_API void r_cons_pal_update_event(void) { - __cons_pal_update_event (r_cons_singleton ()->context); +RZ_API void rz_cons_pal_update_event(void) { + __cons_pal_update_event (rz_cons_singleton ()->context); } -R_API void r_cons_rainbow_new(RConsContext *ctx, int sz) { +RZ_API void rz_cons_rainbow_new(RzConsContext *ctx, int sz) { ctx->pal.rainbow_sz = sz; free (ctx->pal.rainbow); ctx->pal.rainbow = calloc (sizeof (char *), sz); } -R_API void r_cons_rainbow_free(RConsContext *ctx) { +RZ_API void rz_cons_rainbow_free(RzConsContext *ctx) { int i, sz = ctx->pal.rainbow_sz; if (ctx->pal.rainbow) { for (i = 0; i < sz; i++) { @@ -673,8 +673,8 @@ R_API void r_cons_rainbow_free(RConsContext *ctx) { R_FREE (ctx->pal.rainbow); } -R_API char *r_cons_rainbow_get(int idx, int last, bool bg) { - RCons *cons = r_cons_singleton (); +RZ_API char *rz_cons_rainbow_get(int idx, int last, bool bg) { + RzCons *cons = rz_cons_singleton (); if (last < 0) { last = cons->context->pal.rainbow_sz; } @@ -685,10 +685,10 @@ R_API char *r_cons_rainbow_get(int idx, int last, bool bg) { ? idx : (cons->context->pal.rainbow_sz * idx) / (last + 1); const char *a = cons->context->pal.rainbow[x]; if (bg) { - char *dup = r_str_newf ("%s %s", a, a); - char *res = r_cons_pal_parse (dup, NULL); + char *dup = rz_str_newf ("%s %s", a, a); + char *res = rz_cons_pal_parse (dup, NULL); free (dup); return res; } - return r_cons_pal_parse (a, NULL); + return rz_cons_pal_parse (a, NULL); } diff --git a/libr/cons/rgb.c b/librz/cons/rgb.c similarity index 87% rename from libr/cons/rgb.c rename to librz/cons/rgb.c index decafb854a..b8616f8235 100644 --- a/libr/cons/rgb.c +++ b/librz/cons/rgb.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2013-2020 - pancake, xarkes */ -/* ansi 256 color extension for r_cons */ +/* ansi 256 color extension for rz_cons */ /* https://en.wikipedia.org/wiki/ANSI_color */ -#include +#include int color_table[256] = { 0 }; int value_range[6] = { 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff}; @@ -101,14 +101,14 @@ static void __unrgb(int color, int *r, int *g, int *b) { } } -R_API void r_cons_rgb_init(void) { +RZ_API void rz_cons_rgb_init(void) { if (color_table[255] == 0) { init_color_table (); } } /* Parse an ANSI code string into RGB values -- Used by HTML filter only */ -R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) { +RZ_API int rz_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) { const char *q = 0; ut8 isbg = 0, bold = 127; if (!p) { @@ -198,17 +198,17 @@ R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a) { return 1; } -R_API char *r_cons_rgb_str_off(char *outstr, size_t sz, ut64 off) { +RZ_API char *rz_cons_rgb_str_off(char *outstr, size_t sz, ut64 off) { RColor rc = RColor_BLACK; rc.id16 = -1; rc.r = (off >> 2) & 0xff; rc.g = (off >> 6) & 0xff; rc.b = (off >> 12) & 0xff; - return r_cons_rgb_str (outstr, sz, &rc); + return rz_cons_rgb_str (outstr, sz, &rc); } /* Compute color string depending on cons->color */ -static void r_cons_rgb_gen(RConsColorMode mode, char *outstr, size_t sz, ut8 attr, ut8 a, ut8 r, ut8 g, ut8 b, +static void rz_cons_rgb_gen(RzConsColorMode mode, char *outstr, size_t sz, ut8 attr, ut8 a, ut8 r, ut8 g, ut8 b, st8 id16) { ut8 fgbg = (a == ALPHA_BG)? 48: 38; // ANSI codes for Background/Foreground @@ -280,7 +280,7 @@ static void r_cons_rgb_gen(RConsColorMode mode, char *outstr, size_t sz, ut8 att } /* Return the computed color string for the specified color in the specified mode */ -R_API char *r_cons_rgb_str_mode(RConsColorMode mode, char *outstr, size_t sz, RColor *rcolor) { +RZ_API char *rz_cons_rgb_str_mode(RzConsColorMode mode, char *outstr, size_t sz, RColor *rcolor) { if (!rcolor) { return NULL; } @@ -295,22 +295,22 @@ R_API char *r_cons_rgb_str_mode(RConsColorMode mode, char *outstr, size_t sz, RC } // If the color handles both foreground and background, also add background if (rcolor->a == ALPHA_FGBG) { - r_cons_rgb_gen (mode, outstr, sz, 0, ALPHA_BG, rcolor->r2, rcolor->g2, rcolor->b2, rcolor->id16); + rz_cons_rgb_gen (mode, outstr, sz, 0, ALPHA_BG, rcolor->r2, rcolor->g2, rcolor->b2, rcolor->id16); } // APPEND size_t len = strlen (outstr); - r_cons_rgb_gen (mode, outstr + len, sz - len, rcolor->attr, rcolor->a, rcolor->r, rcolor->g, rcolor->b, + rz_cons_rgb_gen (mode, outstr + len, sz - len, rcolor->attr, rcolor->a, rcolor->r, rcolor->g, rcolor->b, rcolor->id16); return outstr; } /* Return the computed color string for the specified color */ -R_API char *r_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor) { - return r_cons_rgb_str_mode (r_cons_singleton ()->context->color_mode, outstr, sz, rcolor); +RZ_API char *rz_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor) { + return rz_cons_rgb_str_mode (rz_cons_singleton ()->context->color_mode, outstr, sz, rcolor); } -R_API char *r_cons_rgb_tostring(ut8 r, ut8 g, ut8 b) { +RZ_API char *rz_cons_rgb_tostring(ut8 r, ut8 g, ut8 b) { const char *str = NULL; if (r == 0x00 && g == b && g == 0) { str = "black"; @@ -336,5 +336,5 @@ R_API char *r_cons_rgb_tostring(ut8 r, ut8 g, ut8 b) { if (r == 0xff && g == 0x00 && b == 0xff) { str = "magenta"; } - return str? strdup (str) : r_str_newf ("#%02x%02x%02x", r, g, b); + return str? strdup (str) : rz_str_newf ("#%02x%02x%02x", r, g, b); } diff --git a/libr/cons/stiv.c b/librz/cons/stiv.c similarity index 96% rename from libr/cons/stiv.c rename to librz/cons/stiv.c index d1dc8b1b74..083d33c670 100644 --- a/libr/cons/stiv.c +++ b/librz/cons/stiv.c @@ -1,6 +1,6 @@ /* tiv - terminal image viewer - MIT 2013-2019 - pancake */ -#include +#include #define XY(b,x,y) ( b+((y)*(w*3))+(x*3) ) #define ABS(x) (((x)<0)?-(x):(x)) @@ -127,10 +127,10 @@ static void selectrenderer(int mode) { } } -R_API void r_cons_image(const ut8 *buf, int bufsz, int width, int mode) { +RZ_API void rz_cons_image(const ut8 *buf, int bufsz, int width, int mode) { int height = (bufsz / width) / 3; selectrenderer (mode); - dorender (r_cons_printf, buf, bufsz, width, height); + dorender (rz_cons_printf, buf, bufsz, width, height); } #if 0 diff --git a/libr/core/Makefile b/librz/core/Makefile similarity index 77% rename from libr/core/Makefile rename to librz/core/Makefile index 1bd0803405..612fad8d85 100644 --- a/libr/core/Makefile +++ b/librz/core/Makefile @@ -1,10 +1,10 @@ include ../config.mk -NAME=r_core +NAME=rz_core -R2DEPS=r_config r_cons r_io r_util r_flag r_asm -R2DEPS+=r_debug r_hash r_bin r_lang r_io r_anal r_parse r_bp r_egg -R2DEPS+=r_reg r_search r_syscall r_socket r_fs r_magic r_crypto +R2DEPS=rz_config rz_cons rz_io rz_util rz_flag rz_asm +R2DEPS+=rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg +R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto OBJS=core.o cmd.o cmd_helps.o cfile.o cconfig.o visual.o cio.o yank.o libs.o agraph.o OBJS+=fortune.o hack.o vasm.o patch.o cbin.o corelog.o rtr.o cmd_api.o @@ -14,7 +14,7 @@ OBJS+=task.o panels.o pseudo.o vmarks.o anal_tp.o anal_objc.o blaze.o cundo.o OBJS+=cannotated_code.o CFLAGS+=-I../../shlr/heap/include -CFLAGS+=-I../../shlr/tree-sitter/lib/include -I../../shlr/radare2-shell-parser/src/tree_parser +CFLAGS+=-I../../shlr/tree-sitter/lib/include -I../../shlr/rizin-shell-parser/src/tree_parser CFLAGS+=-DR2_PLUGIN_INCORE -I../../shlr LDFLAGS+=${DL_LIBS} LDFLAGS+=${CLOCK_LDFLAGS} @@ -40,7 +40,7 @@ STATIC_OBJS=$(addprefix $(LTOP)/core/p/,$(STATIC_OBJ)) OBJS+=$(STATIC_OBJS) include $(TOP)/shlr/gdb/deps.mk -include $(TOP)/shlr/radare2-shell-parser-deps.mk +include $(TOP)/shlr/rizin-shell-parser-deps.mk include $(LTOP)/rules.mk cmd.o: cmd_hash.c cmd_debug.c cmd_zign.c cmd_project.c \ diff --git a/libr/core/agraph.c b/librz/core/agraph.c similarity index 64% rename from libr/core/agraph.c rename to librz/core/agraph.c index 1a962bc27b..b8e8c221f5 100644 --- a/libr/core/agraph.c +++ b/librz/core/agraph.c @@ -1,7 +1,7 @@ -/* Copyright radare2 - 2014-2020 - pancake, ret2libc */ +/* Copyright rizin - 2014-2020 - pancake, ret2libc */ -#include -#include +#include +#include #include #include @@ -50,13 +50,13 @@ static const char *mousemodes[] = { #define hash_set(sdb, k, v) (sdb_num_set (sdb, sdb_fmt ("%"PFMT64u, (ut64) (size_t) (k)), (ut64) (size_t) (v), 0)) #define hash_get(sdb, k) (sdb_num_get (sdb, sdb_fmt ("%"PFMT64u, (ut64) (size_t) (k)), NULL)) #define hash_get_rnode(sdb, k) ((RGraphNode *) (size_t) hash_get (sdb, k)) -#define hash_get_rlist(sdb, k) ((RList *) (size_t) hash_get (sdb, k)) +#define hash_get_rlist(sdb, k) ((RzList *) (size_t) hash_get (sdb, k)) #define hash_get_int(sdb, k) ((int) hash_get (sdb, k)) /* don't use macros for this */ -#define get_anode(gn) ((gn)? (RANode *) (gn)->data: NULL) +#define get_anode(gn) ((gn)? (RzANode *) (gn)->data: NULL) #define graph_foreach_anode(list, it, pos, anode)\ - if (list) for ((it) = (list)->head; (it) && ((pos) = (it)->data) && (pos) && ((anode) = (RANode *) (pos)->data); (it) = (it)->n) + if (list) for ((it) = (list)->head; (it) && ((pos) = (it)->data) && (pos) && ((anode) = (RzANode *) (pos)->data); (it) = (it)->n) struct len_pos_t { int len; @@ -70,16 +70,16 @@ struct dist_t { }; struct g_cb { - RAGraph *graph; - RANodeCallback node_cb; + RzAGraph *graph; + RzANodeCallback node_cb; RAEdgeCallback edge_cb; void *data; }; typedef struct ascii_edge_t { - RANode *from; - RANode *to; - RList *x, *y; + RzANode *from; + RzANode *to; + RzList *x, *y; int is_reversed; } AEdge; @@ -93,39 +93,39 @@ struct layer_t { }; struct agraph_refresh_data { - RCore *core; - RAGraph *g; - RAnalFunction **fcn; + RzCore *core; + RzAGraph *g; + RzAnalFunction **fcn; bool follow_offset; int fs; }; -struct r_agraph_location { +struct rz_agraph_location { int x; int y; }; -#define G(x, y) r_cons_canvas_gotoxy (g->can, x, y) -#define W(x) r_cons_canvas_write (g->can, x) -#define F(x, y, x2, y2, c) r_cons_canvas_fill (g->can, x, y, x2, y2, c) +#define G(x, y) rz_cons_canvas_gotoxy (g->can, x, y) +#define W(x) rz_cons_canvas_write (g->can, x) +#define F(x, y, x2, y2, c) rz_cons_canvas_fill (g->can, x, y, x2, y2, c) -static bool is_offset(const RAGraph *g) { +static bool is_offset(const RzAGraph *g) { return g->mode == R_AGRAPH_MODE_OFFSET; } -static bool is_mini(const RAGraph *g) { +static bool is_mini(const RzAGraph *g) { return g->mode == R_AGRAPH_MODE_MINI; } -static bool is_tiny(const RAGraph *g) { +static bool is_tiny(const RzAGraph *g) { return g->is_tiny || g->mode == R_AGRAPH_MODE_TINY; } -static bool is_summary(const RAGraph *g) { +static bool is_summary(const RzAGraph *g) { return g->mode == R_AGRAPH_MODE_SUMMARY; } -static bool is_comments(const RAGraph *g) { +static bool is_comments(const RzAGraph *g) { return g->mode == R_AGRAPH_MODE_COMMENTS; } @@ -137,25 +137,25 @@ static int prev_mode(int mode) { return (mode + R_AGRAPH_MODE_MAX - 1) % R_AGRAPH_MODE_MAX; } -static RGraphNode *agraph_get_title(const RAGraph *g, RANode *n, bool in) { +static RGraphNode *agraph_get_title(const RzAGraph *g, RzANode *n, bool in) { if (!n) { return NULL; } if (n->title && *n->title) { return n->gnode; } - const RList *outnodes = in? n->gnode->in_nodes : n->gnode->out_nodes; + const RzList *outnodes = in? n->gnode->in_nodes : n->gnode->out_nodes; RGraphNode *gn; - RListIter *iter; + RzListIter *iter; - r_list_foreach (outnodes, iter, gn) { - RANode *an = gn->data; + rz_list_foreach (outnodes, iter, gn) { + RzANode *an = gn->data; return agraph_get_title (g, an, in); } return NULL; } -static int mode2opts(const RAGraph *g) { +static int mode2opts(const RzAGraph *g) { int opts = 0; if (is_offset (g)) { opts |= BODY_OFFSETS; @@ -170,43 +170,43 @@ static int mode2opts(const RAGraph *g) { } // duplicated from visual.c -static void rotateAsmemu(RCore *core) { - const bool isEmuStr = r_config_get_i (core->config, "emu.str"); - const bool isEmu = r_config_get_i (core->config, "asm.emu"); +static void rotateAsmemu(RzCore *core) { + const bool isEmuStr = rz_config_get_i (core->config, "emu.str"); + const bool isEmu = rz_config_get_i (core->config, "asm.emu"); if (isEmu) { if (isEmuStr) { - r_config_set (core->config, "emu.str", "false"); + rz_config_set (core->config, "emu.str", "false"); } else { - r_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "asm.emu", "false"); } } else { - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "emu.str", "true"); } } -static void showcursor(RCore *core, int x) { +static void showcursor(RzCore *core, int x) { if (!x) { - int wheel = r_config_get_i (core->config, "scr.wheel"); + int wheel = rz_config_get_i (core->config, "scr.wheel"); if (wheel) { - r_cons_enable_mouse (true); + rz_cons_enable_mouse (true); } } else { - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); } - r_cons_show_cursor (x); + rz_cons_show_cursor (x); } static char *get_title(ut64 addr) { - return r_str_newf ("0x%"PFMT64x, addr); + return rz_str_newf ("0x%"PFMT64x, addr); } static int agraph_refresh(struct agraph_refresh_data *grd); static void update_node_dimension(const RGraph *g, int is_mini, int zoom, int edgemode, bool callgraph, int layout) { - const RList *nodes = r_graph_get_nodes (g); + const RzList *nodes = rz_graph_get_nodes (g); RGraphNode *gn; - RListIter *it; - RANode *n; + RzListIter *it; + RzANode *n; graph_foreach_anode (nodes, it, gn, n) { if (is_mini) { n->h = 1; @@ -215,7 +215,7 @@ static void update_node_dimension(const RGraph *g, int is_mini, int zoom, int ed n->h = 1; n->w = MININODE_MIN_WIDTH; } else { - n->w = r_str_bounds (n->body, (int *) &n->h); + n->w = rz_str_bounds (n->body, (int *) &n->h); ut32 len = strlen (n->title) + MARGIN_TEXT_X; if (len > INT_MAX) { len = INT_MAX; @@ -232,18 +232,18 @@ static void update_node_dimension(const RGraph *g, int is_mini, int zoom, int ed if (edgemode == 2 && !callgraph) { if (!layout) { - n->w = R_MAX (n->w, (r_list_length (n->gnode->out_nodes) * 2 + 1) + R_EDGES_X_INC * 2); - n->w = R_MAX (n->w, (r_list_length (n->gnode->in_nodes) * 2 + 1) + R_EDGES_X_INC * 2); + n->w = R_MAX (n->w, (rz_list_length (n->gnode->out_nodes) * 2 + 1) + R_EDGES_X_INC * 2); + n->w = R_MAX (n->w, (rz_list_length (n->gnode->in_nodes) * 2 + 1) + R_EDGES_X_INC * 2); } else { - n->h = R_MAX (n->h, (r_list_length (n->gnode->out_nodes) + 1) + R_EDGES_X_INC); - n->h = R_MAX (n->h, (r_list_length (n->gnode->in_nodes) + 1) + R_EDGES_X_INC); + n->h = R_MAX (n->h, (rz_list_length (n->gnode->out_nodes) + 1) + R_EDGES_X_INC); + n->h = R_MAX (n->h, (rz_list_length (n->gnode->in_nodes) + 1) + R_EDGES_X_INC); } } } } } -static void append_shortcut (const RAGraph *g, char *title, char *nodetitle, int left) { +static void append_shortcut (const RzAGraph *g, char *title, char *nodetitle, int left) { const char *shortcut = sdb_const_get (g->db, sdb_fmt ("agraph.nodes.%s.shortcut", nodetitle), 0); if (shortcut) { if (g->can->color) { @@ -255,7 +255,7 @@ static void append_shortcut (const RAGraph *g, char *title, char *nodetitle, int } } -static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool details) { +static void mini_RzANode_print(const RzAGraph *g, const RzANode *n, int cur, bool details) { char title[TITLE_LEN]; int x, delta_x = 0; @@ -280,7 +280,7 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool d "[ %s ]", n->title); W (title); if (discroll > 0) { - char *body = r_str_ansi_crop (n->body, 0, discroll, -1, -1); + char *body = rz_str_ansi_crop (n->body, 0, discroll, -1, -1); (void) G (-g->can->sx, -g->can->sy + 3); W (body); free (body); @@ -303,7 +303,7 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool d snprintf (title, sizeof (title) - 1, "__%s__", str); } append_shortcut (g, title, n->title, sizeof (title) - strlen (title) - 1); - W (r_str_ansi_crop (title, delta_x, 0, 20, 1)); + W (rz_str_ansi_crop (title, delta_x, 0, 20, 1)); } } else { snprintf (title, sizeof (title) - 1, @@ -313,9 +313,9 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur, bool d return; } -static void tiny_RANode_print(const RAGraph *g, const RANode *n, int cur) { +static void tiny_RzANode_print(const RzAGraph *g, const RzANode *n, int cur) { G (n->x, n->y); - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); char *circle = cons->use_utf8 ? UTF_CIRCLE :"()"; if (cur) { W ("##"); @@ -325,7 +325,7 @@ static void tiny_RANode_print(const RAGraph *g, const RANode *n, int cur) { } static char *get_node_color (int color, int cur) { - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); if (color == -1) { return cur ? cons->context->pal.graph_box2 : cons->context->pal.graph_box; } @@ -334,7 +334,7 @@ static char *get_node_color (int color, int cur) { color==R_ANAL_DIFF_TYPE_UNMATCH? cons->context->pal.graph_diff_unmatch : cons->context->pal.graph_diff_new): cons->context->pal.graph_diff_unknown; } -static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) { +static void normal_RzANode_print(const RzAGraph *g, const RzANode *n, int cur) { ut32 center_x = 0, center_y = 0; ut32 delta_x = 0, delta_txt_x = 0; ut32 delta_y = 0, delta_txt_y = 0; @@ -366,7 +366,7 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) { append_shortcut (g, title, n->title, sizeof (title) - strlen (title) - 1); } if ((delta_x < strlen (title)) && G (n->x + MARGIN_TEXT_X + delta_x, n->y + 1)) { - char *res = r_str_ansi_crop (title, delta_x, 0, n->w - BORDER_WIDTH, 1); + char *res = rz_str_ansi_crop (title, delta_x, 0, n->w - BORDER_WIDTH, 1); W (res); free (res); } @@ -390,7 +390,7 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) { body_h--; } if (body_y + 1 <= body_h) { - body = r_str_ansi_crop (n->body, + body = rz_str_ansi_crop (n->body, body_x, body_y, n->w - BORDER_WIDTH, body_h); @@ -418,11 +418,11 @@ static void normal_RANode_print(const RAGraph *g, const RANode *n, int cur) { } // TODO: check if node is traced or not and show proper color - // This info must be stored inside RANode* from RCore* + // This info must be stored inside RzANode* from RzCore* if (g->show_node_bubble) { - r_cons_canvas_circle (g->can, n->x, n->y, n->w, n->h, get_node_color (color, cur)); + rz_cons_canvas_circle (g->can, n->x, n->y, n->w, n->h, get_node_color (color, cur)); } else { - r_cons_canvas_box (g->can, n->x, n->y, n->w, n->h, get_node_color (color, cur)); + rz_cons_canvas_box (g->can, n->x, n->y, n->w, n->h, get_node_color (color, cur)); } } @@ -445,16 +445,16 @@ static int **get_crossing_matrix(const RGraph *g, /* calculate crossings between layer i and layer i-1 */ /* consider the crossings generated by each pair of edges */ if (i > 0 && from_up) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto err_row; } for (j = 0; j < layers[i - 1].n_nodes; j++) { const RGraphNode *gj = layers[i - 1].nodes[j]; - const RList *neigh = r_graph_get_neighbours (g, gj); + const RzList *neigh = rz_graph_get_neighbours (g, gj); RGraphNode *gk; - RListIter *itk; + RzListIter *itk; - r_list_foreach (neigh, itk, gk) { + rz_list_foreach (neigh, itk, gk) { int s; // skip self-loop if (gj == gk) { @@ -462,12 +462,12 @@ static int **get_crossing_matrix(const RGraph *g, } for (s = 0; s < j; s++) { const RGraphNode *gs = layers[i - 1].nodes[s]; - const RList *neigh_s = r_graph_get_neighbours (g, gs); + const RzList *neigh_s = rz_graph_get_neighbours (g, gs); RGraphNode *gt; - RListIter *itt; + RzListIter *itt; - r_list_foreach (neigh_s, itt, gt) { - const RANode *ak, *at; /* k and t should be "indexes" on layer i */ + rz_list_foreach (neigh_s, itt, gt) { + const RzANode *ak, *at; /* k and t should be "indexes" on layer i */ if (gt == gk || gt == gs) { continue; } @@ -493,32 +493,32 @@ static int **get_crossing_matrix(const RGraph *g, /* calculate crossings between layer i and layer i+1 */ if (i < maxlayer - 1 && !from_up) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto err_row; } for (j = 0; j < layers[i].n_nodes; j++) { const RGraphNode *gj = layers[i].nodes[j]; - const RList *neigh = r_graph_get_neighbours (g, gj); - const RANode *ak, *aj = get_anode (gj); + const RzList *neigh = rz_graph_get_neighbours (g, gj); + const RzANode *ak, *aj = get_anode (gj); RGraphNode *gk; - RListIter *itk; + RzListIter *itk; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto err_row; } graph_foreach_anode (neigh, itk, gk, ak) { int s; for (s = 0; s < layers[i].n_nodes; s++) { const RGraphNode *gs = layers[i].nodes[s]; - const RList *neigh_s; + const RzList *neigh_s; RGraphNode *gt; - RListIter *itt; - const RANode *at, *as = get_anode (gs); + RzListIter *itt; + const RzANode *at, *as = get_anode (gs); if (gs == gj) { continue; } - neigh_s = r_graph_get_neighbours (g, gs); + neigh_s = rz_graph_get_neighbours (g, gs); graph_foreach_anode (neigh_s, itt, gt, at) { if (at->pos_in_layer < ak->pos_in_layer) { m[aj->pos_in_layer][as->pos_in_layer]++; @@ -545,7 +545,7 @@ err_row: static int layer_sweep(const RGraph *g, const struct layer_t layers[], int maxlayer, int i, int from_up) { RGraphNode *u, *v; - const RANode *au, *av; + const RzANode *au, *av; int n_rows, j, changed = false; int len = layers[i].n_nodes; @@ -576,7 +576,7 @@ static int layer_sweep(const RGraph *g, const struct layer_t layers[], * elements we didn't swap also the pos_in_layer because the cross_matrix * is indexed by it, so do it now! */ for (j = 0; j < layers[i].n_nodes; j++) { - RANode *n = get_anode (layers[i].nodes[j]); + RzANode *n = get_anode (layers[i].nodes[j]); n->pos_in_layer = j; } @@ -588,7 +588,7 @@ static int layer_sweep(const RGraph *g, const struct layer_t layers[], } static void view_cyclic_edge(const RGraphEdge *e, const RGraphVisitor *vis) { - const RAGraph *g = (RAGraph *) vis->data; + const RzAGraph *g = (RzAGraph *) vis->data; RGraphEdge *new_e = R_NEW0 (RGraphEdge); if (!new_e) { return; @@ -596,13 +596,13 @@ static void view_cyclic_edge(const RGraphEdge *e, const RGraphVisitor *vis) { new_e->from = e->from; new_e->to = e->to; new_e->nth = e->nth; - r_list_append (g->back_edges, new_e); + rz_list_append (g->back_edges, new_e); } static void view_dummy(const RGraphEdge *e, const RGraphVisitor *vis) { - const RANode *a = get_anode (e->from); - const RANode *b = get_anode (e->to); - RList *long_edges = (RList *) vis->data; + const RzANode *a = get_anode (e->from); + const RzANode *b = get_anode (e->to); + RzList *long_edges = (RzList *) vis->data; if (!a || !b) { return; } @@ -614,37 +614,37 @@ static void view_dummy(const RGraphEdge *e, const RGraphVisitor *vis) { new_e->from = e->from; new_e->to = e->to; new_e->nth = e->nth; - r_list_append (long_edges, new_e); + rz_list_append (long_edges, new_e); } } /* find a set of edges that, removed, makes the graph acyclic */ /* invert the edges identified in the previous step */ -static void remove_cycles(RAGraph *g) { +static void remove_cycles(RzAGraph *g) { RGraphVisitor cyclic_vis = { NULL, NULL, NULL, NULL, NULL, NULL }; const RGraphEdge *e; - const RListIter *it; + const RzListIter *it; - g->back_edges = r_list_new (); + g->back_edges = rz_list_new (); cyclic_vis.back_edge = (RGraphEdgeCallback) view_cyclic_edge; cyclic_vis.data = g; - r_graph_dfs (g->graph, &cyclic_vis); + rz_graph_dfs (g->graph, &cyclic_vis); - r_list_foreach (g->back_edges, it, e) { - RANode *from = e->from? get_anode (e->from): NULL; - RANode *to = e->to? get_anode (e->to): NULL; + rz_list_foreach (g->back_edges, it, e) { + RzANode *from = e->from? get_anode (e->from): NULL; + RzANode *to = e->to? get_anode (e->to): NULL; if (from && to) { - r_agraph_del_edge (g, from, to); - r_agraph_add_edge_at (g, to, from, e->nth); + rz_agraph_del_edge (g, from, to); + rz_agraph_add_edge_at (g, to, from, e->nth); } } } static void add_sorted(RGraphNode *n, RGraphVisitor *vis) { - RList *l = (RList *) vis->data; - r_list_prepend (l, n); + RzList *l = (RzList *) vis->data; + rz_list_prepend (l, n); } /* assign a layer to each node of the graph. @@ -653,24 +653,24 @@ static void add_sorted(RGraphNode *n, RGraphVisitor *vis) { * you visit a node, you can be sure that you have already visited all nodes * that can lead to that node and thus you can easily compute the layer based * on the layer of these "parent" nodes. */ -static void assign_layers(const RAGraph *g) { +static void assign_layers(const RzAGraph *g) { RGraphVisitor layer_vis = { NULL, NULL, NULL, NULL, NULL, NULL }; const RGraphNode *gn; - const RListIter *it; - RANode *n; - RList *topological_sort = r_list_new (); + const RzListIter *it; + RzANode *n; + RzList *topological_sort = rz_list_new (); layer_vis.data = topological_sort; layer_vis.finish_node = (RGraphNodeCallback) add_sorted; - r_graph_dfs (g->graph, &layer_vis); + rz_graph_dfs (g->graph, &layer_vis); graph_foreach_anode (topological_sort, it, gn, n) { - const RList *innodes = r_graph_innodes (g->graph, gn); - RListIter *it; + const RzList *innodes = rz_graph_innodes (g->graph, gn); + RzListIter *it; RGraphNode *prev; - RANode *preva; + RzANode *preva; n->layer = 0; graph_foreach_anode (innodes, it, prev, preva) { @@ -680,44 +680,44 @@ static void assign_layers(const RAGraph *g) { } } - r_list_free (topological_sort); + rz_list_free (topological_sort); } static int find_edge(const RGraphEdge *a, const RGraphEdge *b) { return a->from == b->to && a->to == b->from? 0: 1; } -static bool is_reversed(const RAGraph *g, const RGraphEdge *e) { - return (bool)r_list_find (g->back_edges, e, (RListComparator) find_edge); +static bool is_reversed(const RzAGraph *g, const RGraphEdge *e) { + return (bool)rz_list_find (g->back_edges, e, (RzListComparator) find_edge); } /* add dummy nodes when there are edges that span multiple layers */ -static void create_dummy_nodes(RAGraph *g) { +static void create_dummy_nodes(RzAGraph *g) { if (!g->dummy) { return; } RGraphVisitor dummy_vis = { NULL, NULL, NULL, NULL, NULL, NULL }; - const RListIter *it; + const RzListIter *it; const RGraphEdge *e; - g->long_edges = r_list_newf ((RListFree)free); + g->long_edges = rz_list_newf ((RzListFree)free); dummy_vis.data = g->long_edges; dummy_vis.tree_edge = (RGraphEdgeCallback) view_dummy; dummy_vis.fcross_edge = (RGraphEdgeCallback) view_dummy; - r_graph_dfs (g->graph, &dummy_vis); + rz_graph_dfs (g->graph, &dummy_vis); - r_list_foreach (g->long_edges, it, e) { - RANode *from = get_anode (e->from); - RANode *to = get_anode (e->to); + rz_list_foreach (g->long_edges, it, e) { + RzANode *from = get_anode (e->from); + RzANode *to = get_anode (e->to); int diff_layer = R_ABS (from->layer - to->layer); - RANode *prev = get_anode (e->from); + RzANode *prev = get_anode (e->from); int i, nth = e->nth; - r_agraph_del_edge (g, from, to); + rz_agraph_del_edge (g, from, to); for (i = 1; i < diff_layer; i++) { - RANode *dummy = r_agraph_add_node (g, NULL, NULL); + RzANode *dummy = rz_agraph_add_node (g, NULL, NULL); if (!dummy) { return; } @@ -725,21 +725,21 @@ static void create_dummy_nodes(RAGraph *g) { dummy->layer = from->layer + i; dummy->is_reversed = is_reversed (g, e); dummy->w = 1; - r_agraph_add_edge_at (g, prev, dummy, nth); + rz_agraph_add_edge_at (g, prev, dummy, nth); prev = dummy; nth = -1; } - r_graph_add_edge (g->graph, prev->gnode, e->to); + rz_graph_add_edge (g->graph, prev->gnode, e->to); } } /* create layers and assign an initial ordering of the nodes into them */ -static void create_layers(RAGraph *g) { - const RList *nodes = r_graph_get_nodes (g->graph); +static void create_layers(RzAGraph *g) { + const RzList *nodes = rz_graph_get_nodes (g->graph); RGraphNode *gn; - const RListIter *it; - RANode *n; + const RzListIter *it; + RzANode *n; int i; /* identify max layer */ @@ -778,7 +778,7 @@ static void create_layers(RAGraph *g) { /* layer-by-layer sweep */ /* it permutes each layer, trying to find the best ordering for each layer * to minimize the number of crossing edges */ -static void minimize_crossings(const RAGraph *g) { +static void minimize_crossings(const RzAGraph *g) { int i, cross_changed, max_changes = 4096; do { @@ -817,18 +817,18 @@ static int find_dist(const struct dist_t *a, const struct dist_t *b) { /* returns the distance between two nodes */ /* if the distance between two nodes were explicitly set, returns that; * otherwise calculate the distance of two nodes on the same layer */ -static int dist_nodes(const RAGraph *g, const RGraphNode *a, const RGraphNode *b) { +static int dist_nodes(const RzAGraph *g, const RGraphNode *a, const RGraphNode *b) { struct dist_t d; - const RANode *aa, *ab; - RListIter *it; + const RzANode *aa, *ab; + RzListIter *it; int res = 0; if (g->dists) { d.from = a; d.to = b; - it = r_list_find (g->dists, &d, (RListComparator) find_dist); + it = rz_list_find (g->dists, &d, (RzListComparator) find_dist); if (it) { - struct dist_t *old = (struct dist_t *) r_list_iter_get_data (it); + struct dist_t *old = (struct dist_t *) rz_list_iter_get_data (it); return old->dist; } } @@ -842,16 +842,16 @@ static int dist_nodes(const RAGraph *g, const RGraphNode *a, const RGraphNode *b for (i = aa->pos_in_layer; i < ab->pos_in_layer; i++) { const RGraphNode *cur = g->layers[aa->layer].nodes[i]; const RGraphNode *next = g->layers[aa->layer].nodes[i + 1]; - const RANode *anext = get_anode (next); - const RANode *acur = get_anode (cur); + const RzANode *anext = get_anode (next); + const RzANode *acur = get_anode (cur); int found = false; if (g->dists) { d.from = cur; d.to = next; - it = r_list_find (g->dists, &d, (RListComparator) find_dist); + it = rz_list_find (g->dists, &d, (RzListComparator) find_dist); if (it) { - struct dist_t *old = (struct dist_t *) r_list_iter_get_data (it); + struct dist_t *old = (struct dist_t *) rz_list_iter_get_data (it); res += old->dist; found = true; } @@ -877,11 +877,11 @@ static int dist_nodes(const RAGraph *g, const RGraphNode *a, const RGraphNode *b } /* explicitly set the distance between two nodes on the same layer */ -static void set_dist_nodes(const RAGraph *g, int l, int cur, int next) { +static void set_dist_nodes(const RzAGraph *g, int l, int cur, int next) { struct dist_t *d, find_el; const RGraphNode *vi, *vip; - const RANode *avi, *avip; - RListIter *it; + const RzANode *avi, *avip; + RzListIter *it; if (!g->dists) { return; @@ -893,18 +893,18 @@ static void set_dist_nodes(const RAGraph *g, int l, int cur, int next) { find_el.from = vi; find_el.to = vip; - it = r_list_find (g->dists, &find_el, (RListComparator) find_dist); - d = it? (struct dist_t *) r_list_iter_get_data (it): R_NEW0 (struct dist_t); + it = rz_list_find (g->dists, &find_el, (RzListComparator) find_dist); + d = it? (struct dist_t *) rz_list_iter_get_data (it): R_NEW0 (struct dist_t); d->from = vi; d->to = vip; d->dist = (avip && avi)? avip->x - avi->x: 0; if (!it) { - r_list_push (g->dists, d); + rz_list_push (g->dists, d); } } -static int is_valid_pos(const RAGraph *g, int l, int pos) { +static int is_valid_pos(const RzAGraph *g, int l, int pos) { return pos >= 0 && pos < g->layers[l].n_nodes; } @@ -912,33 +912,33 @@ static int is_valid_pos(const RAGraph *g, int l, int pos) { /* if v is an original node, L(v) = { v } * if v is a dummy node, L(v) is the set of all the dummies node that belongs * to the same long edge */ -static Sdb *compute_vertical_nodes(const RAGraph *g) { +static Sdb *compute_vertical_nodes(const RzAGraph *g) { Sdb *res = sdb_new0 (); int i, j; for (i = 0; i < g->n_layers; i++) { for (j = 0; j < g->layers[i].n_nodes; j++) { RGraphNode *gn = g->layers[i].nodes[j]; - const RList *Ln = hash_get_rlist (res, gn); - const RANode *an = get_anode (gn); + const RzList *Ln = hash_get_rlist (res, gn); + const RzANode *an = get_anode (gn); if (!Ln) { - RList *vert = r_list_new (); + RzList *vert = rz_list_new (); hash_set (res, gn, vert); if (an->is_dummy) { RGraphNode *next = gn; - const RANode *anext = get_anode (next); + const RzANode *anext = get_anode (next); while (anext->is_dummy) { - r_list_append (vert, next); - next = r_graph_nth_neighbour (g->graph, next, 0); + rz_list_append (vert, next); + next = rz_graph_nth_neighbour (g->graph, next, 0); if (!next) { break; } anext = get_anode (next); } } else { - r_list_append (vert, gn); + rz_list_append (vert, gn); } } } @@ -952,14 +952,14 @@ static Sdb *compute_vertical_nodes(const RAGraph *g) { * - v E C * - w E C => L(v) is a subset of C * - w E C, the s+(w) exists and is not in any class yet => s+(w) E C */ -static RList **compute_classes(const RAGraph *g, Sdb *v_nodes, int is_left, int *n_classes) { +static RzList **compute_classes(const RzAGraph *g, Sdb *v_nodes, int is_left, int *n_classes) { int i, j, c; - RList **res = R_NEWS0 (RList *, g->n_layers); + RzList **res = R_NEWS0 (RzList *, g->n_layers); RGraphNode *gn; - const RListIter *it; - RANode *n; + const RzListIter *it; + RzANode *n; - graph_foreach_anode (r_graph_get_nodes (g->graph), it, gn, n) { + graph_foreach_anode (rz_graph_get_nodes (g->graph), it, gn, n) { n->klass = -1; } @@ -970,16 +970,16 @@ static RList **compute_classes(const RAGraph *g, Sdb *v_nodes, int is_left, int (is_left && j < g->layers[i].n_nodes) || (!is_left && j >= 0); j = is_left? j + 1: j - 1) { const RGraphNode *gj = g->layers[i].nodes[j]; - const RANode *aj = get_anode (gj); + const RzANode *aj = get_anode (gj); if (aj->klass == -1) { - const RList *laj = hash_get_rlist (v_nodes, gj); + const RzList *laj = hash_get_rlist (v_nodes, gj); if (!res[c]) { - res[c] = r_list_new (); + res[c] = rz_list_new (); } graph_foreach_anode (laj, it, gn, n) { - r_list_append (res[c], gn); + rz_list_append (res[c], gn); n->klass = c; } } else { @@ -998,7 +998,7 @@ static int cmp_dist(const size_t a, const size_t b) { return (a < b) - (a > b); } -static RGraphNode *get_sibling(const RAGraph *g, const RANode *n, int is_left, int is_adjust_class) { +static RGraphNode *get_sibling(const RzAGraph *g, const RzANode *n, int is_left, int is_adjust_class) { RGraphNode *res = NULL; int pos = n->pos_in_layer; @@ -1014,7 +1014,7 @@ static RGraphNode *get_sibling(const RAGraph *g, const RANode *n, int is_left, i return res; } -static int adjust_class_val(const RAGraph *g, const RGraphNode *gn, const RGraphNode *sibl, Sdb *res, int is_left) { +static int adjust_class_val(const RzAGraph *g, const RGraphNode *gn, const RGraphNode *sibl, Sdb *res, int is_left) { if (is_left) { return hash_get_int (res, sibl) - hash_get_int (res, gn) - dist_nodes (g, gn, sibl); } @@ -1023,15 +1023,15 @@ static int adjust_class_val(const RAGraph *g, const RGraphNode *gn, const RGraph /* adjusts the position of previously placed left/right classes */ /* tries to place classes as close as possible */ -static void adjust_class(const RAGraph *g, int is_left, RList **classes, Sdb *res, int c) { +static void adjust_class(const RzAGraph *g, int is_left, RzList **classes, Sdb *res, int c) { const RGraphNode *gn; - const RListIter *it; - const RANode *an; + const RzListIter *it; + const RzANode *an; int dist, v, is_first = true; graph_foreach_anode (classes[c], it, gn, an) { const RGraphNode *sibling; - const RANode *sibl_anode; + const RzANode *sibl_anode; sibling = get_sibling (g, an, is_left, true); if (!sibling) { @@ -1047,34 +1047,34 @@ static void adjust_class(const RAGraph *g, int is_left, RList **classes, Sdb *re } if (is_first) { - RList *heap = r_list_new (); + RzList *heap = rz_list_new (); int len; graph_foreach_anode (classes[c], it, gn, an) { - const RList *neigh = r_graph_all_neighbours (g->graph, gn); + const RzList *neigh = rz_graph_all_neighbours (g->graph, gn); const RGraphNode *gk; - const RListIter *itk; - const RANode *ak; + const RzListIter *itk; + const RzANode *ak; graph_foreach_anode (neigh, itk, gk, ak) { if (ak->klass < c) { size_t d = (ak->x - an->x); if (d > 0) { - r_list_append (heap, (void *) d); + rz_list_append (heap, (void *) d); } } } } - len = r_list_length (heap); + len = rz_list_length (heap); if (len == 0) { dist = 0; } else { - r_list_sort (heap, (RListComparator) cmp_dist); - dist = (int) (size_t) r_list_get_n (heap, len / 2); + rz_list_sort (heap, (RzListComparator) cmp_dist); + dist = (int) (size_t) rz_list_get_n (heap, len / 2); } - r_list_free (heap); + rz_list_free (heap); } graph_foreach_anode (classes[c], it, gn, an) { @@ -1084,7 +1084,7 @@ static void adjust_class(const RAGraph *g, int is_left, RList **classes, Sdb *re } } -static int place_nodes_val(const RAGraph *g, const RGraphNode *gn, const RGraphNode *sibl, Sdb *res, int is_left) { +static int place_nodes_val(const RzAGraph *g, const RGraphNode *gn, const RGraphNode *sibl, Sdb *res, int is_left) { if (is_left) { return hash_get_int (res, sibl) + dist_nodes (g, sibl, gn); } @@ -1102,16 +1102,16 @@ static int place_nodes_sel_p(int newval, int oldval, int is_first, int is_left) } /* places left/right the nodes of a class */ -static void place_nodes(const RAGraph *g, const RGraphNode *gn, int is_left, Sdb *v_nodes, RList **classes, Sdb *res, Sdb *placed) { - const RList *lv = hash_get_rlist (v_nodes, gn); +static void place_nodes(const RzAGraph *g, const RGraphNode *gn, int is_left, Sdb *v_nodes, RzList **classes, Sdb *res, Sdb *placed) { + const RzList *lv = hash_get_rlist (v_nodes, gn); int p = 0, v, is_first = true; const RGraphNode *gk; - const RListIter *itk; - const RANode *ak; + const RzListIter *itk; + const RzANode *ak; graph_foreach_anode (lv, itk, gk, ak) { const RGraphNode *sibling; - const RANode *sibl_anode; + const RzANode *sibl_anode; sibling = get_sibling (g, ak, is_left, false); if (!sibling) { @@ -1140,10 +1140,10 @@ static void place_nodes(const RAGraph *g, const RGraphNode *gn, int is_left, Sdb } /* computes the position to the left/right of all the nodes */ -static Sdb *compute_pos(const RAGraph *g, int is_left, Sdb *v_nodes) { +static Sdb *compute_pos(const RzAGraph *g, int is_left, Sdb *v_nodes) { int n_classes, i; - RList **classes = compute_classes (g, v_nodes, is_left, &n_classes); + RzList **classes = compute_classes (g, v_nodes, is_left, &n_classes); if (!classes) { return NULL; } @@ -1152,9 +1152,9 @@ static Sdb *compute_pos(const RAGraph *g, int is_left, Sdb *v_nodes) { Sdb *placed = sdb_new0 (); for (i = 0; i < n_classes; i++) { const RGraphNode *gn; - const RListIter *it; + const RzListIter *it; - r_list_foreach (classes[i], it, gn) { + rz_list_foreach (classes[i], it, gn) { if (!hash_get_rnode (placed, gn)) { place_nodes (g, gn, is_left, v_nodes, classes, res, placed); } @@ -1166,7 +1166,7 @@ static Sdb *compute_pos(const RAGraph *g, int is_left, Sdb *v_nodes) { sdb_free (placed); for (i = 0; i < n_classes; i++) { if (classes[i]) { - r_list_free (classes[i]); + rz_list_free (classes[i]); } } free (classes); @@ -1174,18 +1174,18 @@ static Sdb *compute_pos(const RAGraph *g, int is_left, Sdb *v_nodes) { } static int free_vertical_nodes_cb(void *user UNUSED, const char *k UNUSED, const char *v) { - r_list_free ((RList *) (size_t) sdb_atoi (v)); + rz_list_free ((RzList *) (size_t) sdb_atoi (v)); return 1; } /* calculates position of all nodes, but in particular dummies nodes */ /* computes two different placements (called "left"/"right") and set the final * position of each node to the average of the values in the two placements */ -static void place_dummies(const RAGraph *g) { - const RList *nodes; +static void place_dummies(const RzAGraph *g) { + const RzList *nodes; const RGraphNode *gn; - const RListIter *it; - RANode *n; + const RzListIter *it; + RzANode *n; Sdb *vertical_nodes = compute_vertical_nodes (g); if (!vertical_nodes) { @@ -1200,7 +1200,7 @@ static void place_dummies(const RAGraph *g) { goto xplus_err; } - nodes = r_graph_get_nodes (g->graph); + nodes = rz_graph_get_nodes (g->graph); graph_foreach_anode (nodes, it, gn, n) { n->x = (hash_get_int (xminus, gn) + hash_get_int (xplus, gn)) / 2; } @@ -1213,8 +1213,8 @@ xminus_err: sdb_free (vertical_nodes); } -static RGraphNode *get_right_dummy(const RAGraph *g, const RGraphNode *n) { - const RANode *an = get_anode (n); +static RGraphNode *get_right_dummy(const RzAGraph *g, const RGraphNode *n) { + const RzANode *an = get_anode (n); if (!an) { return NULL; } @@ -1222,7 +1222,7 @@ static RGraphNode *get_right_dummy(const RAGraph *g, const RGraphNode *n) { for (k = an->pos_in_layer + 1; k < g->layers[layer].n_nodes; k++) { RGraphNode *gk = g->layers[layer].nodes[k]; - const RANode *ak = get_anode (gk); + const RzANode *ak = get_anode (gk); if (!ak) { break; } @@ -1234,9 +1234,9 @@ static RGraphNode *get_right_dummy(const RAGraph *g, const RGraphNode *n) { return NULL; } -static void adjust_directions(const RAGraph *g, int i, int from_up, Sdb *D, Sdb *P) { +static void adjust_directions(const RzAGraph *g, int i, int from_up, Sdb *D, Sdb *P) { const RGraphNode *vm = NULL, *wm = NULL; - const RANode *vma = NULL, *wma = NULL; + const RzANode *vma = NULL, *wma = NULL; int j, d = from_up? 1: -1; if (i + d < 0 || i + d >= g->n_layers) { @@ -1244,15 +1244,15 @@ static void adjust_directions(const RAGraph *g, int i, int from_up, Sdb *D, Sdb } for (j = 0; j < g->layers[i + d].n_nodes; j++) { const RGraphNode *wp, *vp = g->layers[i + d].nodes[j]; - const RANode *wpa, *vpa = get_anode (vp); + const RzANode *wpa, *vpa = get_anode (vp); if (!vpa || !vpa->is_dummy) { continue; } if (from_up) { - wp = r_list_get_n (r_graph_innodes (g->graph, vp), 0); + wp = rz_list_get_n (rz_graph_innodes (g->graph, vp), 0); } else { - wp = r_graph_nth_neighbour (g->graph, vp, 0); + wp = rz_graph_nth_neighbour (g->graph, vp, 0); } wpa = get_anode (wp); if (!wpa || !wpa->is_dummy) { @@ -1264,7 +1264,7 @@ static void adjust_directions(const RAGraph *g, int i, int from_up, Sdb *D, Sdb for (k = wma->pos_in_layer + 1; k < wpa->pos_in_layer; k++) { const RGraphNode *w = g->layers[wma->layer].nodes[k]; - const RANode *aw = get_anode (w); + const RzANode *aw = get_anode (w); if (aw && aw->is_dummy) { p &= hash_get_int (P, w); } @@ -1273,7 +1273,7 @@ static void adjust_directions(const RAGraph *g, int i, int from_up, Sdb *D, Sdb hash_set (D, vm, from_up); for (k = vma->pos_in_layer + 1; k < vpa->pos_in_layer; k++) { const RGraphNode *v = g->layers[vma->layer].nodes[k]; - const RANode *av = get_anode (v); + const RzANode *av = get_anode (v); if (av && av->is_dummy) { hash_set (D, v, from_up); } @@ -1288,20 +1288,20 @@ static void adjust_directions(const RAGraph *g, int i, int from_up, Sdb *D, Sdb } /* find a placement for a single node */ -static void place_single(const RAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int va) { +static void place_single(const RzAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int va) { const RGraphNode *gk, *v = g->layers[l].nodes[va]; - const RANode *ak; - RANode *av = get_anode (v); + const RzANode *ak; + RzANode *av = get_anode (v); if (!av) { return; } - const RListIter *itk; + const RzListIter *itk; - const RList *neigh = from_up - ? r_graph_innodes (g->graph, v) - : r_graph_get_neighbours (g->graph, v); + const RzList *neigh = from_up + ? rz_graph_innodes (g->graph, v) + : rz_graph_get_neighbours (g->graph, v); - int len = r_list_length (neigh); + int len = rz_list_length (neigh); if (len == 0) { return; } @@ -1322,11 +1322,11 @@ static void place_single(const RAGraph *g, int l, const RGraphNode *bm, const RG av->x = sum_x / len; } if (bm) { - const RANode *bma = get_anode (bm); + const RzANode *bma = get_anode (bm); av->x = R_MAX (av->x, bma->x + dist_nodes (g, bm, v)); } if (bp) { - const RANode *bpa = get_anode (bp); + const RzANode *bpa = get_anode (bp); av->x = R_MIN (av->x, bpa->x - dist_nodes (g, v, bp)); } } @@ -1339,27 +1339,27 @@ static int RP_listcmp(const struct len_pos_t *a, const struct len_pos_t *b) { return (a->pos > b->pos) - (a->pos < b->pos); } -static void collect_changes(const RAGraph *g, int l, const RGraphNode *b, int from_up, int s, int e, RList *list, int is_left) { +static void collect_changes(const RzAGraph *g, int l, const RGraphNode *b, int from_up, int s, int e, RzList *list, int is_left) { const RGraphNode *vt = g->layers[l].nodes[e - 1]; const RGraphNode *vtp = g->layers[l].nodes[s]; struct len_pos_t *cx; int i; - RListComparator lcmp = is_left? (RListComparator) RM_listcmp: (RListComparator) RP_listcmp; + RzListComparator lcmp = is_left? (RzListComparator) RM_listcmp: (RzListComparator) RP_listcmp; for (i = is_left? s: e - 1; (is_left && i < e) || (!is_left && i >= s); i = is_left? i + 1: i - 1) { const RGraphNode *v, *vi = g->layers[l].nodes[i]; - const RANode *av, *avi = get_anode (vi); - const RList *neigh; - const RListIter *it; + const RzANode *av, *avi = get_anode (vi); + const RzList *neigh; + const RzListIter *it; int c = 0; if (!avi) { continue; } neigh = from_up - ? r_graph_innodes (g->graph, vi) - : r_graph_get_neighbours (g->graph, vi); + ? rz_graph_innodes (g->graph, vi) + : rz_graph_get_neighbours (g->graph, vi); graph_foreach_anode (neigh, it, v, av) { if ((is_left && av->x >= avi->x) || (!is_left && av->x <= avi->x)) { @@ -1374,7 +1374,7 @@ static void collect_changes(const RAGraph *g, int l, const RGraphNode *b, int fr } else { cx->pos -= dist_nodes (g, vtp, vi); } - r_list_add_sorted (list, cx, lcmp); + rz_list_add_sorted (list, cx, lcmp); } } @@ -1386,11 +1386,11 @@ static void collect_changes(const RAGraph *g, int l, const RGraphNode *b, int fr } else { cx->pos -= dist_nodes (g, vtp, vi); } - r_list_add_sorted (list, cx, lcmp); + rz_list_add_sorted (list, cx, lcmp); } if (b) { - const RANode *ab = get_anode (b); + const RzANode *ab = get_anode (b); cx = R_NEW (struct len_pos_t); if (cx) { cx->len = is_left? INT_MAX: INT_MIN; @@ -1400,18 +1400,18 @@ static void collect_changes(const RAGraph *g, int l, const RGraphNode *b, int fr } else { cx->pos -= dist_nodes (g, vtp, b); } - r_list_add_sorted (list, cx, lcmp); + rz_list_add_sorted (list, cx, lcmp); } } } -static void combine_sequences(const RAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int a, int r) { - RList *Rm = r_list_new (), *Rp = r_list_new (); +static void combine_sequences(const RzAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int a, int r) { + RzList *Rm = rz_list_new (), *Rp = rz_list_new (); const RGraphNode *vt, *vtp; - RANode *at, *atp; + RzANode *at, *atp; int rm, rp, t, m, i; - Rm->free = (RListFree) free; - Rp->free = (RListFree) free; + Rm->free = (RzListFree) free; + Rp->free = (RzListFree) free; t = (a + r) / 2; vt = g->layers[l].nodes[t - 1]; @@ -1432,19 +1432,19 @@ static void combine_sequences(const RAGraph *g, int l, const RGraphNode *bm, con atp->x += m - step; } else { if (rm < rp) { - if (r_list_empty (Rm)) { + if (rz_list_empty (Rm)) { at->x = atp->x - m; } else { - struct len_pos_t *cx = (struct len_pos_t *) r_list_pop (Rm); + struct len_pos_t *cx = (struct len_pos_t *) rz_list_pop (Rm); rm = rm + cx->len; at->x = R_MAX (cx->pos, atp->x - m); free (cx); } } else { - if (r_list_empty (Rp)) { + if (rz_list_empty (Rp)) { atp->x = at->x + m; } else { - struct len_pos_t *cx = (struct len_pos_t *) r_list_pop (Rp); + struct len_pos_t *cx = (struct len_pos_t *) rz_list_pop (Rp); rp = rp + cx->len; atp->x = R_MIN (cx->pos, at->x + m); free (cx); @@ -1454,12 +1454,12 @@ static void combine_sequences(const RAGraph *g, int l, const RGraphNode *bm, con } } - r_list_free (Rm); - r_list_free (Rp); + rz_list_free (Rm); + rz_list_free (Rp); for (i = t - 2; i >= a; i--) { const RGraphNode *gv = g->layers[l].nodes[i]; - RANode *av = get_anode (gv); + RzANode *av = get_anode (gv); if (av && at) { av->x = R_MIN (av->x, at->x - dist_nodes (g, gv, vt)); } @@ -1467,7 +1467,7 @@ static void combine_sequences(const RAGraph *g, int l, const RGraphNode *bm, con for (i = t + 1; i < r; i++) { const RGraphNode *gv = g->layers[l].nodes[i]; - RANode *av = get_anode (gv); + RzANode *av = get_anode (gv); if (av && atp) { av->x = R_MAX (av->x, atp->x + dist_nodes (g, vtp, gv)); } @@ -1479,7 +1479,7 @@ static void combine_sequences(const RAGraph *g, int l, const RGraphNode *bm, con * neighbours in the "previous" layer. Those neighbours are considered as * "fixed". The previous layer depends on the direction used during the layers * traversal */ -static void place_sequence(const RAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int va, int vr) { +static void place_sequence(const RzAGraph *g, int l, const RGraphNode *bm, const RGraphNode *bp, int from_up, int va, int vr) { if (vr == va + 1) { place_single (g, l, bm, bp, from_up, va); } else if (vr > va + 1) { @@ -1493,7 +1493,7 @@ static void place_sequence(const RAGraph *g, int l, const RGraphNode *bm, const /* finds the placements of nodes while traversing the graph in the given * direction */ /* places all the sequences of consecutive original nodes in each layer. */ -static void original_traverse_l(const RAGraph *g, Sdb *D, Sdb *P, int from_up) { +static void original_traverse_l(const RzAGraph *g, Sdb *D, Sdb *P, int from_up) { int i, k, va, vr; for (i = from_up? 0: g->n_layers - 1; @@ -1501,12 +1501,12 @@ static void original_traverse_l(const RAGraph *g, Sdb *D, Sdb *P, int from_up) { i = from_up? i + 1: i - 1) { int j; const RGraphNode *bm = NULL; - const RANode *bma = NULL; + const RzANode *bma = NULL; j = 0; while (j < g->layers[i].n_nodes && !bm) { const RGraphNode *gn = g->layers[i].nodes[j]; - const RANode *an = get_anode (gn); + const RzANode *an = get_anode (gn); if (an && an->is_dummy) { va = 0; vr = j; @@ -1528,7 +1528,7 @@ static void original_traverse_l(const RAGraph *g, Sdb *D, Sdb *P, int from_up) { } while (bm) { const RGraphNode *bp = get_right_dummy (g, bm); - const RANode *bpa = NULL; + const RzANode *bpa = NULL; bma = get_anode (bm); if (!bp) { @@ -1558,11 +1558,11 @@ static void original_traverse_l(const RAGraph *g, Sdb *D, Sdb *P, int from_up) { /* computes a final position of original nodes, considering dummies nodes as * fixed */ /* set the node placements traversing the graph downward and then upward */ -static void place_original(RAGraph *g) { - const RList *nodes = r_graph_get_nodes (g->graph); +static void place_original(RzAGraph *g) { + const RzList *nodes = rz_graph_get_nodes (g->graph); const RGraphNode *gn; - const RListIter *itn; - const RANode *an; + const RzListIter *itn; + const RzANode *an; Sdb *D = sdb_new0 (); if (!D) { @@ -1573,7 +1573,7 @@ static void place_original(RAGraph *g) { sdb_free (D); return; } - g->dists = r_list_newf ((RListFree) free); + g->dists = rz_list_newf ((RzListFree) free); if (!g->dists) { sdb_free (D); sdb_free (P); @@ -1585,7 +1585,7 @@ static void place_original(RAGraph *g) { continue; } const RGraphNode *right_v = get_right_dummy (g, gn); - const RANode *right = get_anode (right_v); + const RzANode *right = get_anode (right_v); if (right_v && right) { hash_set (D, gn, 0); int dt_eq = right->x - an->x == dist_nodes (g, gn, right_v); @@ -1596,23 +1596,23 @@ static void place_original(RAGraph *g) { original_traverse_l (g, D, P, true); original_traverse_l (g, D, P, false); - r_list_free (g->dists); + rz_list_free (g->dists); g->dists = NULL; sdb_free (P); sdb_free (D); } #if 0 -static void free_anode(RANode *n); -static void remove_dummy_nodes(const RAGraph *g) { - const RList *nodes = r_graph_get_nodes (g->graph); +static void free_anode(RzANode *n); +static void remove_dummy_nodes(const RzAGraph *g) { + const RzList *nodes = rz_graph_get_nodes (g->graph); RGraphNode *gn; - RListIter *it; - RANode *n; + RzListIter *it; + RzANode *n; graph_foreach_anode (nodes, it, gn, n) { if (n->is_dummy) { - r_graph_del_node (g->graph, gn); + rz_graph_del_node (g->graph, gn); n->gnode = NULL; free_anode (n); } @@ -1620,13 +1620,13 @@ static void remove_dummy_nodes(const RAGraph *g) { } #endif -static void set_layer_gap (RAGraph *g) { +static void set_layer_gap (RzAGraph *g) { int gap = 0; int i = 0, j = 0; - RListIter *itn; + RzListIter *itn; RGraphNode *ga, *gb; - RANode *a, *b; - const RList *outnodes; + RzANode *a, *b; + const RzList *outnodes; g->layers[0].gap = 0; for (i = 0; i < g->n_layers; i++) { @@ -1639,7 +1639,7 @@ static void set_layer_gap (RAGraph *g) { if (!ga) { continue; } - a = (RANode *) ga->data; + a = (RzANode *) ga->data; outnodes = ga->out_nodes; if (!outnodes || !a) { @@ -1673,17 +1673,17 @@ static void set_layer_gap (RAGraph *g) { } } -static void fix_back_edge_dummy_nodes(RAGraph *g, RANode *from, RANode *to) { - RANode *v, *tmp = NULL; +static void fix_back_edge_dummy_nodes(RzAGraph *g, RzANode *from, RzANode *to) { + RzANode *v, *tmp = NULL; RGraphNode *gv = NULL; - RListIter *it; + RzListIter *it; int i; - r_return_if_fail (g && from && to); - const RList *neighbours = r_graph_get_neighbours (g->graph, to->gnode); + rz_return_if_fail (g && from && to); + const RzList *neighbours = rz_graph_get_neighbours (g->graph, to->gnode); graph_foreach_anode (neighbours, it, gv, v) { tmp = v; while (tmp->is_dummy) { - tmp = (RANode *) (((RGraphNode *)r_list_first (tmp->gnode->out_nodes))->data); + tmp = (RzANode *) (((RGraphNode *)rz_list_first (tmp->gnode->out_nodes))->data); } if (tmp->gnode->idx == from->gnode->idx) { break; @@ -1695,7 +1695,7 @@ static void fix_back_edge_dummy_nodes(RAGraph *g, RANode *from, RANode *to) { v = to; while (tmp->gnode->idx != from->gnode->idx) { v = tmp; - tmp = (RANode *) (((RGraphNode *)r_list_first (v->gnode->out_nodes))->data); + tmp = (RzANode *) (((RGraphNode *)rz_list_first (v->gnode->out_nodes))->data); i = 0; while (v->gnode->idx != g->layers[v->layer].nodes[i]->idx) { @@ -1709,26 +1709,26 @@ static void fix_back_edge_dummy_nodes(RAGraph *g, RANode *from, RANode *to) { g->layers[v->layer].nodes[g->layers[v->layer].n_nodes - 1] = 0; g->layers[v->layer].n_nodes -= 1; - r_graph_del_node (g->graph, v->gnode); + rz_graph_del_node (g->graph, v->gnode); } } } -static int get_edge_number (const RAGraph *g, RANode *src, RANode *dst, bool outgoing) { - RListIter *itn; +static int get_edge_number (const RzAGraph *g, RzANode *src, RzANode *dst, bool outgoing) { + RzListIter *itn; RGraphNode *gv; int cur_nth = 0; int nth = 0; - RANode *v; + RzANode *v; if (outgoing && src->is_dummy) { - RANode *in = (RANode *) (((RGraphNode *)r_list_first ((src->gnode)->in_nodes))->data); + RzANode *in = (RzANode *) (((RGraphNode *)rz_list_first ((src->gnode)->in_nodes))->data); cur_nth = get_edge_number (g, in, src, outgoing); } else { - const RList *neighbours = outgoing - ? r_graph_get_neighbours (g->graph, src->gnode) - : r_graph_innodes (g->graph, dst->gnode); - const int exit_edges = r_list_length (neighbours); + const RzList *neighbours = outgoing + ? rz_graph_get_neighbours (g->graph, src->gnode) + : rz_graph_innodes (g->graph, dst->gnode); + const int exit_edges = rz_list_length (neighbours); graph_foreach_anode (neighbours, itn, gv, v) { cur_nth = nth; if (g->is_callgraph) { @@ -1748,11 +1748,11 @@ static int get_edge_number (const RAGraph *g, RANode *src, RANode *dst, bool out return cur_nth; } -static int count_edges (const RAGraph *g, RANode *src, RANode *dst) { +static int count_edges (const RzAGraph *g, RzANode *src, RzANode *dst) { return get_edge_number (g, src, dst, true); } -static void backedge_info (RAGraph *g) { +static void backedge_info (RzAGraph *g) { int i, j, k; int min, max; int inedge = 0; @@ -1775,7 +1775,7 @@ static void backedge_info (RAGraph *g) { if (!gt) { continue; } - RANode *t = (RANode *) gt->data; + RzANode *t = (RzANode *) gt->data; if (!t) { continue; } @@ -1796,20 +1796,20 @@ static void backedge_info (RAGraph *g) { } for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *a = get_anode (g->layers[i].nodes[j]); + RzANode *a = get_anode (g->layers[i].nodes[j]); if (!a || a->is_dummy) { continue; } - const RList *neighbours = r_graph_get_neighbours (g->graph, a->gnode); + const RzList *neighbours = rz_graph_get_neighbours (g->graph, a->gnode); RGraphNode *gb; - RANode *b; - RListIter *itm; + RzANode *b; + RzListIter *itm; if (i == 0) { - inedge += r_list_length (r_graph_innodes (g->graph, a->gnode)); + inedge += rz_list_length (rz_graph_innodes (g->graph, a->gnode)); } else if (i == g->n_layers - 1) { - outedge += r_list_length (neighbours); + outedge += rz_list_length (neighbours); } graph_foreach_anode (neighbours, itm, gb, b) { @@ -1859,23 +1859,23 @@ static void backedge_info (RAGraph *g) { e->is_reversed = true; e->from = a; e->to = b; - e->x = r_list_new (); - e->y = r_list_new (); + e->x = rz_list_new (); + e->y = rz_list_new (); if (r < l) { - r_list_append ((g->layout == 0 ? e->x : e->y), (void *) (size_t) (max + 1)); + rz_list_append ((g->layout == 0 ? e->x : e->y), (void *) (size_t) (max + 1)); } else { - r_list_append ((g->layout == 0 ? e->x : e->y), (void *) (size_t) (min - 1)); + rz_list_append ((g->layout == 0 ? e->x : e->y), (void *) (size_t) (min - 1)); } - r_list_append(g->edges, e); + rz_list_append(g->edges, e); } } } //Assumption: layer layout is not changed w.r.t x-coordinate/y-coordinate for horizontal/vertical layout respectively. if (inedge) { - RANode *n = (RANode *)g->layers[0].nodes[0]->data; + RzANode *n = (RzANode *)g->layers[0].nodes[0]->data; AEdge *e = R_NEW0 (AEdge); if (!e) { free (arr); @@ -1884,18 +1884,18 @@ static void backedge_info (RAGraph *g) { e->is_reversed = true; e->from = NULL; e->to = NULL; - e->x = r_list_new (); - e->y = r_list_new (); + e->x = rz_list_new (); + e->y = rz_list_new (); if (g->layout == 0) { - r_list_append (e->y, (void *) (size_t) (n->y - 1 - inedge)); + rz_list_append (e->y, (void *) (size_t) (n->y - 1 - inedge)); } else { - r_list_append (e->x, (void *) (size_t) (n->x - 1 - inedge)); + rz_list_append (e->x, (void *) (size_t) (n->x - 1 - inedge)); } - r_list_append (g->edges, e); + rz_list_append (g->edges, e); } if (outedge) { - RANode *n = (RANode *)g->layers[g->n_layers - 1].nodes[0]->data; + RzANode *n = (RzANode *)g->layers[g->n_layers - 1].nodes[0]->data; AEdge *e = R_NEW0 (AEdge); if (!e) { free (arr); @@ -1905,14 +1905,14 @@ static void backedge_info (RAGraph *g) { e->is_reversed = true; e->from = NULL; e->to = NULL; - e->x = r_list_new (); - e->y = r_list_new (); + e->x = rz_list_new (); + e->y = rz_list_new (); if (g->layout == 0) { - r_list_append (e->y, (void *) (size_t) (n->y + g->layers[g->n_layers - 1].height + 2 + outedge)); + rz_list_append (e->y, (void *) (size_t) (n->y + g->layers[g->n_layers - 1].height + 2 + outedge)); } else { - r_list_append (e->x, (void *) (size_t) (n->x + g->layers[g->n_layers - 1].width + 2 + outedge)); + rz_list_append (e->x, (void *) (size_t) (n->x + g->layers[g->n_layers - 1].width + 2 + outedge)); } - r_list_append (g->edges, e); + rz_list_append (g->edges, e); } err: for (i = i - 1; i >= 0; i--) { @@ -1928,11 +1928,11 @@ static void backedge_info (RAGraph *g) { * 4) reorder nodes in each layer to reduce the number of edge crossing * 5) assign x and y coordinates to each node * 6) restore the original graph, with long edges and cycles */ -static void set_layout(RAGraph *g) { +static void set_layout(RzAGraph *g) { int i, j, k; - r_list_free (g->edges); - g->edges = r_list_new (); + rz_list_free (g->edges); + g->edges = rz_list_new (); remove_cycles (g); assign_layers (g); @@ -1940,8 +1940,8 @@ static void set_layout(RAGraph *g) { create_layers (g); minimize_crossings (g); - if (r_cons_is_breaked ()) { - r_cons_break_end (); + if (rz_cons_is_breaked ()) { + rz_cons_break_end (); return; } /* identify row height */ @@ -1949,7 +1949,7 @@ static void set_layout(RAGraph *g) { int rh = 0; int rw = 0; for (j = 0; j < g->layers[i].n_nodes; j++) { - const RANode *n = get_anode (g->layers[i].nodes[j]); + const RzANode *n = get_anode (g->layers[i].nodes[j]); if (n->h > rh) { rh = n->h; } @@ -1963,7 +1963,7 @@ static void set_layout(RAGraph *g) { for (i = 0; i < g->n_layers; i++) { for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *a = (RANode *) g->layers[i].nodes[j]->data; + RzANode *a = (RzANode *) g->layers[i].nodes[j]->data; if (a->is_dummy) { if (g->layout == 0) { a->h = g->layers[i].height; @@ -1985,14 +1985,14 @@ static void set_layout(RAGraph *g) { /* IDEA: need to put this hack because of the way algorithm is implemented. * I think backedges should be restored to their original state instead of * converting them to longedges and adding dummy nodes. */ - const RListIter *it; + const RzListIter *it; const RGraphEdge *e; - r_list_foreach (g->back_edges, it, e) { - RANode *from = e->from? get_anode (e->from): NULL; - RANode *to = e->to? get_anode (e->to): NULL; + rz_list_foreach (g->back_edges, it, e) { + RzANode *from = e->from? get_anode (e->from): NULL; + RzANode *to = e->to? get_anode (e->to): NULL; fix_back_edge_dummy_nodes (g, from, to); - r_agraph_del_edge (g, to, from); - r_agraph_add_edge_at (g, from, to, e->nth); + rz_agraph_del_edge (g, to, from); + rz_agraph_add_edge_at (g, from, to, e->nth); } switch (g->layout) { @@ -2001,7 +2001,7 @@ static void set_layout(RAGraph *g) { /* horizontal finalize x coordinate */ for (i = 0; i < g->n_layers; i++) { for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *n = get_anode (g->layers[i].nodes[j]); + RzANode *n = get_anode (g->layers[i].nodes[j]); if (n) { n->x -= n->w / 2; if (g->is_tiny) { @@ -2024,7 +2024,7 @@ static void set_layout(RAGraph *g) { tmp_y = i; } for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *n = get_anode (g->layers[i].nodes[j]); + RzANode *n = get_anode (g->layers[i].nodes[j]); if (n) { n->y = tmp_y; } @@ -2036,10 +2036,10 @@ static void set_layout(RAGraph *g) { /* vertical y coordinate */ for (i = 0; i < g->n_layers; i++) { for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *n = get_anode (g->layers[i].nodes[j]); + RzANode *n = get_anode (g->layers[i].nodes[j]); n->y = 1; for (k = 0; k < j; k++) { - RANode *m = get_anode (g->layers[i].nodes[k]); + RzANode *m = get_anode (g->layers[i].nodes[k]); n->y -= (m->h + VERTICAL_NODE_SPACING); } } @@ -2054,7 +2054,7 @@ static void set_layout(RAGraph *g) { xval += g->layers[k-1].width + g->layers[k].gap + 3; } for (j = 0; j < g->layers[i].n_nodes; j++) { - RANode *n = get_anode (g->layers[i].nodes[j]); + RzANode *n = get_anode (g->layers[i].nodes[j]); n->x = xval; } } @@ -2069,86 +2069,86 @@ static void set_layout(RAGraph *g) { } free (g->layers); - r_list_free (g->long_edges); - r_list_free (g->back_edges); - r_cons_break_pop (); + rz_list_free (g->long_edges); + rz_list_free (g->back_edges); + rz_cons_break_pop (); } -static char *get_body(RCore *core, ut64 addr, int size, int opts) { +static char *get_body(RzCore *core, ut64 addr, int size, int opts) { char *body; - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { return NULL; } - r_config_hold_i (hc, "asm.lines", "asm.bytes", + rz_config_hold_i (hc, "asm.lines", "asm.bytes", "asm.cmt.col", "asm.marks", "asm.offset", "asm.comments", "asm.cmt.right", "asm.bb.line", NULL); - const bool o_comments = r_config_get_i (core->config, "graph.comments"); - const bool o_cmtright = r_config_get_i (core->config, "graph.cmtright"); - const bool o_bytes = r_config_get_i (core->config, "graph.bytes"); - const bool o_flags_in_bytes = r_config_get_i (core->config, "asm.flags.inbytes"); - const bool o_graph_offset = r_config_get_i (core->config, "graph.offset"); + const bool o_comments = rz_config_get_i (core->config, "graph.comments"); + const bool o_cmtright = rz_config_get_i (core->config, "graph.cmtright"); + const bool o_bytes = rz_config_get_i (core->config, "graph.bytes"); + const bool o_flags_in_bytes = rz_config_get_i (core->config, "asm.flags.inbytes"); + const bool o_graph_offset = rz_config_get_i (core->config, "graph.offset"); int o_cursor = core->print->cur_enabled; if (opts & BODY_COMMENTS) { - r_core_visual_toggle_decompiler_disasm (core, true, false); - char * res = r_core_cmd_strf (core, "pD %d @ 0x%08"PFMT64x, size, addr); - res = r_str_replace (res, "; ", "", true); - // res = r_str_replace (res, "\n", "(\n)", true); - r_str_trim (res); - res = r_str_trim_lines (res); - r_core_visual_toggle_decompiler_disasm (core, true, false); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_core_visual_toggle_decompiler_disasm (core, true, false); + char * res = rz_core_cmd_strf (core, "pD %d @ 0x%08"PFMT64x, size, addr); + res = rz_str_replace (res, "; ", "", true); + // res = rz_str_replace (res, "\n", "(\n)", true); + rz_str_trim (res); + res = rz_str_trim_lines (res); + rz_core_visual_toggle_decompiler_disasm (core, true, false); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return res; } const char *cmd = (opts & BODY_SUMMARY)? "pds": "pD"; // configure options - r_config_set_i (core->config, "asm.bb.line", false); - r_config_set_i (core->config, "asm.lines", false); - r_config_set_i (core->config, "asm.cmt.col", 0); - r_config_set_i (core->config, "asm.marks", false); - r_config_set_i (core->config, "asm.cmt.right", (opts & BODY_SUMMARY) || o_cmtright); - r_config_set_i (core->config, "asm.comments", (opts & BODY_SUMMARY) || o_comments); - r_config_set_i (core->config, "asm.bytes", + rz_config_set_i (core->config, "asm.bb.line", false); + rz_config_set_i (core->config, "asm.lines", false); + rz_config_set_i (core->config, "asm.cmt.col", 0); + rz_config_set_i (core->config, "asm.marks", false); + rz_config_set_i (core->config, "asm.cmt.right", (opts & BODY_SUMMARY) || o_cmtright); + rz_config_set_i (core->config, "asm.comments", (opts & BODY_SUMMARY) || o_comments); + rz_config_set_i (core->config, "asm.bytes", (opts & (BODY_SUMMARY | BODY_OFFSETS)) || o_bytes || o_flags_in_bytes); - r_config_set_i (core->config, "asm.bb.middle", false); + rz_config_set_i (core->config, "asm.bb.middle", false); core->print->cur_enabled = false; if (opts & BODY_OFFSETS || opts & BODY_SUMMARY || o_graph_offset) { - r_config_set_i (core->config, "asm.offset", true); + rz_config_set_i (core->config, "asm.offset", true); } else { - r_config_set_i (core->config, "asm.offset", false); + rz_config_set_i (core->config, "asm.offset", false); } - bool html = r_config_get_i (core->config, "scr.html"); - r_config_set_i (core->config, "scr.html", 0); - if (r_config_get_i (core->config, "graph.aeab")) { - body = r_core_cmd_strf (core, "%s 0x%08"PFMT64x, "aeab", addr); + bool html = rz_config_get_i (core->config, "scr.html"); + rz_config_set_i (core->config, "scr.html", 0); + if (rz_config_get_i (core->config, "graph.aeab")) { + body = rz_core_cmd_strf (core, "%s 0x%08"PFMT64x, "aeab", addr); } else { - body = r_core_cmd_strf (core, "%s %d @ 0x%08"PFMT64x, cmd, size, addr); + body = rz_core_cmd_strf (core, "%s %d @ 0x%08"PFMT64x, cmd, size, addr); } - r_config_set_i (core->config, "scr.html", html); + rz_config_set_i (core->config, "scr.html", html); // restore original options core->print->cur_enabled = o_cursor; - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return body; } -static char *get_bb_body(RCore *core, RAnalBlock *b, int opts, RAnalFunction *fcn, bool emu, ut64 saved_gp, ut8 *saved_arena) { +static char *get_bb_body(RzCore *core, RzAnalBlock *b, int opts, RzAnalFunction *fcn, bool emu, ut64 saved_gp, ut8 *saved_arena) { if (emu) { core->anal->gp = saved_gp; if (b->parent_reg_arena) { - r_reg_arena_poke (core->anal->reg, b->parent_reg_arena); + rz_reg_arena_poke (core->anal->reg, b->parent_reg_arena); R_FREE (b->parent_reg_arena); - ut64 gp = r_reg_getv (core->anal->reg, "gp"); + ut64 gp = rz_reg_getv (core->anal->reg, "gp"); if (gp) { core->anal->gp = gp; } } else { - r_reg_arena_poke (core->anal->reg, saved_arena); + rz_reg_arena_poke (core->anal->reg, saved_arena); } } if (b->parent_stackptr != INT_MAX) { @@ -2157,10 +2157,10 @@ static char *get_bb_body(RCore *core, RAnalBlock *b, int opts, RAnalFunction *fc char *body = get_body (core, b->addr, b->size, opts); if (b->jump != UT64_MAX) { if (b->jump > b->addr) { - RAnalBlock *jumpbb = r_anal_get_block_at (b->anal, b->jump); - if (jumpbb && r_list_contains (jumpbb->fcns, fcn)) { + RzAnalBlock *jumpbb = rz_anal_get_block_at (b->anal, b->jump); + if (jumpbb && rz_list_contains (jumpbb->fcns, fcn)) { if (emu && core->anal->last_disasm_reg != NULL && !jumpbb->parent_reg_arena) { - jumpbb->parent_reg_arena = r_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); + jumpbb->parent_reg_arena = rz_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); } if (jumpbb->parent_stackptr == INT_MAX) { jumpbb->parent_stackptr = core->anal->stackptr + b->stackptr; @@ -2170,10 +2170,10 @@ static char *get_bb_body(RCore *core, RAnalBlock *b, int opts, RAnalFunction *fc } if (b->fail != UT64_MAX) { if (b->fail > b->addr) { - RAnalBlock *failbb = r_anal_get_block_at (b->anal, b->fail); - if (failbb && r_list_contains (failbb->fcns, fcn)) { + RzAnalBlock *failbb = rz_anal_get_block_at (b->anal, b->fail); + if (failbb && rz_list_contains (failbb->fcns, fcn)) { if (emu && core->anal->last_disasm_reg != NULL && !failbb->parent_reg_arena) { - failbb->parent_reg_arena = r_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); + failbb->parent_reg_arena = rz_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); } if (failbb->parent_stackptr == INT_MAX) { failbb->parent_stackptr = core->anal->stackptr + b->stackptr; @@ -2184,14 +2184,14 @@ static char *get_bb_body(RCore *core, RAnalBlock *b, int opts, RAnalFunction *fc return body; } -static int bbcmp(RAnalBlock *a, RAnalBlock *b) { +static int bbcmp(RzAnalBlock *a, RzAnalBlock *b) { return a->addr - b->addr; } -static void get_bbupdate(RAGraph *g, RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *iter; - bool emu = r_config_get_i (core->config, "asm.emu"); +static void get_bbupdate(RzAGraph *g, RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *iter; + bool emu = rz_config_get_i (core->config, "asm.emu"); ut64 saved_gp = core->anal->gp; ut8 *saved_arena = NULL; int saved_stackptr = core->anal->stackptr; @@ -2200,16 +2200,16 @@ static void get_bbupdate(RAGraph *g, RCore *core, RAnalFunction *fcn) { core->keep_asmqjmps = false; if (emu) { - saved_arena = r_reg_arena_peek (core->anal->reg); + saved_arena = rz_reg_arena_peek (core->anal->reg); } if (!fcn) { R_FREE (saved_arena); return; } - r_list_sort (fcn->bbs, (RListComparator) bbcmp); + rz_list_sort (fcn->bbs, (RzListComparator) bbcmp); - shortcuts = r_config_get_i (core->config, "graph.nodejmps"); - r_list_foreach (fcn->bbs, iter, bb) { + shortcuts = rz_config_get_i (core->config, "graph.nodejmps"); + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } @@ -2217,13 +2217,13 @@ static void get_bbupdate(RAGraph *g, RCore *core, RAnalFunction *fcn) { char *title = get_title (bb->addr); if (shortcuts) { - shortcut = r_core_add_asmqjmp (core, bb->addr); + shortcut = rz_core_add_asmqjmp (core, bb->addr); if (shortcut) { sdb_set (g->db, sdb_fmt ("agraph.nodes.%s.shortcut", title), shortcut, 0); free (shortcut); } } - RANode *node = r_agraph_get_node (g, title); + RzANode *node = rz_agraph_get_node (g, title); if (node) { free (node->body); node->body = body; @@ -2237,45 +2237,45 @@ static void get_bbupdate(RAGraph *g, RCore *core, RAnalFunction *fcn) { if (emu) { core->anal->gp = saved_gp; if (saved_arena) { - r_reg_arena_poke (core->anal->reg, saved_arena); + rz_reg_arena_poke (core->anal->reg, saved_arena); R_FREE (saved_arena); } } core->anal->stackptr = saved_stackptr; } -static void fold_asm_trace(RCore *core, RAGraph *g) { - const RList *nodes = r_graph_get_nodes (g->graph); +static void fold_asm_trace(RzCore *core, RzAGraph *g) { + const RzList *nodes = rz_graph_get_nodes (g->graph); RGraphNode *gn; - RListIter *it; - RANode *n; + RzListIter *it; + RzANode *n; - RANode *curnode = get_anode (g->curnode); + RzANode *curnode = get_anode (g->curnode); graph_foreach_anode (nodes, it, gn, n) { if (curnode == n) { n->is_mini = false; g->need_reload_nodes = true; continue; } - ut64 addr = r_num_get (NULL, n->title); - RDebugTracepoint *tp = r_debug_trace_get (core->dbg, addr); + ut64 addr = rz_num_get (NULL, n->title); + RzDebugTracepoint *tp = rz_debug_trace_get (core->dbg, addr); n->is_mini = (tp == NULL); } g->need_update_dim = 1; - //agraph_refresh (r_cons_singleton ()->event_data); + //agraph_refresh (rz_cons_singleton ()->event_data); } -static void delete_dup_edges (RAGraph *g) { - RListIter *it, *in_it, *in_it2, *in_it2_tmp; +static void delete_dup_edges (RzAGraph *g) { + RzListIter *it, *in_it, *in_it2, *in_it2_tmp; RGraphNode *n, *a, *b; - r_list_foreach (g->graph->nodes, it, n) { - r_list_foreach (n->out_nodes, in_it, a) { + rz_list_foreach (g->graph->nodes, it, n) { + rz_list_foreach (n->out_nodes, in_it, a) { for (in_it2 = in_it->n; in_it2 && (b = in_it2->data, in_it2_tmp = in_it2->n, 1); in_it2 = in_it2_tmp) { if (a->idx == b->idx) { - r_list_delete (n->out_nodes, in_it2); - r_list_delete_data (n->all_neighbours, b); - r_list_delete_data (b->in_nodes, n); - r_list_delete_data (b->all_neighbours, n); + rz_list_delete (n->out_nodes, in_it2); + rz_list_delete_data (n->all_neighbours, b); + rz_list_delete_data (b->in_nodes, n); + rz_list_delete_data (b->all_neighbours, n); g->graph->n_edges--; } } @@ -2283,15 +2283,15 @@ static void delete_dup_edges (RAGraph *g) { } } -static bool isbbfew(RAnalBlock *curbb, RAnalBlock *bb) { +static bool isbbfew(RzAnalBlock *curbb, RzAnalBlock *bb) { if (bb->addr == curbb->addr || bb->addr == curbb->jump || bb->addr == curbb->fail) { // do nothing return true; } if (curbb->switch_op) { - RListIter *it; - RAnalCaseOp *cop; - r_list_foreach (curbb->switch_op->cases, it, cop) { + RzListIter *it; + RzAnalCaseOp *cop; + rz_list_foreach (curbb->switch_op->cases, it, cop) { if (cop->addr == bb->addr) { return true; } @@ -2300,14 +2300,14 @@ static bool isbbfew(RAnalBlock *curbb, RAnalBlock *bb) { return false; } -/* build the RGraph inside the RAGraph g, starting from the Basic Blocks */ -static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *iter; +/* build the RGraph inside the RzAGraph g, starting from the Basic Blocks */ +static int get_bbnodes(RzAGraph *g, RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *iter; char *shortcut = NULL; int shortcuts = 0; - bool emu = r_config_get_i (core->config, "asm.emu"); - bool few = r_config_get_i (core->config, "graph.few"); + bool emu = rz_config_get_i (core->config, "asm.emu"); + bool few = rz_config_get_i (core->config, "graph.few"); int ret = false; ut64 saved_gp = core->anal->gp; ut8 *saved_arena = NULL; @@ -2318,16 +2318,16 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { return false; } if (emu) { - saved_arena = r_reg_arena_peek (core->anal->reg); + saved_arena = rz_reg_arena_peek (core->anal->reg); } - r_list_sort (fcn->bbs, (RListComparator) bbcmp); - RAnalBlock *curbb = NULL; + rz_list_sort (fcn->bbs, (RzListComparator) bbcmp); + RzAnalBlock *curbb = NULL; if (few) { - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (!curbb) { curbb = bb; } - if (r_anal_block_contains (bb, core->offset)) { + if (rz_anal_block_contains (bb, core->offset)) { curbb = bb; break; } @@ -2335,7 +2335,7 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { } core->keep_asmqjmps = false; - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } @@ -2345,11 +2345,11 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { char *body = get_bb_body (core, bb, mode2opts (g), fcn, emu, saved_gp, saved_arena); char *title = get_title (bb->addr); - RANode *node = r_agraph_add_node (g, title, body); - shortcuts = g->is_interactive ? r_config_get_i (core->config, "graph.nodejmps") : false; + RzANode *node = rz_agraph_add_node (g, title, body); + shortcuts = g->is_interactive ? rz_config_get_i (core->config, "graph.nodejmps") : false; if (shortcuts) { - shortcut = r_core_add_asmqjmp (core, bb->addr); + shortcut = rz_core_add_asmqjmp (core, bb->addr); if (shortcut) { sdb_set (g->db, sdb_fmt ("agraph.nodes.%s.shortcut", title), shortcut, 0); free (shortcut); @@ -2363,7 +2363,7 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { core->keep_asmqjmps = true; } - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } @@ -2372,29 +2372,29 @@ static int get_bbnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { } char *title = get_title (bb->addr); - RANode *u = r_agraph_get_node (g, title); - RANode *v; + RzANode *u = rz_agraph_get_node (g, title); + RzANode *v; free (title); if (bb->jump != UT64_MAX) { title = get_title (bb->jump); - v = r_agraph_get_node (g, title); + v = rz_agraph_get_node (g, title); free (title); - r_agraph_add_edge (g, u, v); + rz_agraph_add_edge (g, u, v); } if (bb->fail != UT64_MAX) { title = get_title (bb->fail); - v = r_agraph_get_node (g, title); + v = rz_agraph_get_node (g, title); free (title); - r_agraph_add_edge (g, u, v); + rz_agraph_add_edge (g, u, v); } if (bb->switch_op) { - RListIter *it; - RAnalCaseOp *cop; - r_list_foreach (bb->switch_op->cases, it, cop) { + RzListIter *it; + RzAnalCaseOp *cop; + rz_list_foreach (bb->switch_op->cases, it, cop) { title = get_title (cop->addr); - v = r_agraph_get_node (g, title); + v = rz_agraph_get_node (g, title); free (title); - r_agraph_add_edge (g, u, v); + rz_agraph_add_edge (g, u, v); } } } @@ -2406,7 +2406,7 @@ cleanup: if (emu) { core->anal->gp = saved_gp; if (saved_arena) { - r_reg_arena_poke (core->anal->reg, saved_arena); + rz_reg_arena_poke (core->anal->reg, saved_arena); R_FREE (saved_arena); } } @@ -2414,14 +2414,14 @@ cleanup: return ret; } -/* build the RGraph inside the RAGraph g, starting from the Call Graph +/* build the RGraph inside the RzAGraph g, starting from the Call Graph * information */ -static bool get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, 0); - RANode *node, *fcn_anode; - RListIter *iter; - RAnalRef *ref; - RList *refs; +static bool get_cgnodes(RzAGraph *g, RzCore *core, RzAnalFunction *fcn) { + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, 0); + RzANode *node, *fcn_anode; + RzListIter *iter; + RzAnalRef *ref; + RzList *refs; if (!f) { return false; } @@ -2429,10 +2429,10 @@ static bool get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { fcn = f; } - r_core_seek (core, f->addr, true); + rz_core_seek (core, f->addr, true); char *title = get_title (fcn->addr); - fcn_anode = r_agraph_add_node (g, title, ""); + fcn_anode = rz_agraph_add_node (g, title, ""); free (title); if (!fcn_anode) { @@ -2442,16 +2442,16 @@ static bool get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { fcn_anode->x = 10; fcn_anode->y = 3; - refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { + refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { title = get_title (ref->addr); - if (r_agraph_get_node (g, title) != NULL) { + if (rz_agraph_get_node (g, title) != NULL) { continue; } free (title); int size = 0; - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, ref->addr); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, ref->addr); if (bb) { size = bb->size; } @@ -2459,7 +2459,7 @@ static bool get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { char *body = get_body (core, ref->addr, size, mode2opts (g)); title = get_title (ref->addr); - node = r_agraph_add_node (g, title, body); + node = rz_agraph_add_node (g, title, body); if (!node) { return false; } @@ -2470,19 +2470,19 @@ static bool get_cgnodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { node->x = 10; node->y = 10; - r_agraph_add_edge (g, fcn_anode, node); + rz_agraph_add_edge (g, fcn_anode, node); } - r_list_free (refs); + rz_list_free (refs); return true; } -static bool reload_nodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { +static bool reload_nodes(RzAGraph *g, RzCore *core, RzAnalFunction *fcn) { const bool is_c = g->is_callgraph; return is_c? get_cgnodes (g, core, fcn): get_bbnodes (g, core, fcn); } -static void update_seek(RConsCanvas *can, RANode *n, int force) { +static void update_seek(RzConsCanvas *can, RzANode *n, int force) { if (!n) { return; } @@ -2506,7 +2506,7 @@ static void update_seek(RConsCanvas *can, RANode *n, int force) { } } -static int is_near(const RANode *n, int x, int y, int is_next) { +static int is_near(const RzANode *n, int x, int y, int is_next) { if (is_next) { return (n->y == y && n->x > x) || n->y > y; } @@ -2514,19 +2514,19 @@ static int is_near(const RANode *n, int x, int y, int is_next) { } /// XXX is wrong -static int is_near_h(const RANode *n, int x, int y, int is_next) { +static int is_near_h(const RzANode *n, int x, int y, int is_next) { if (is_next) { return (n->x == x && n->y > y) || n->x > x; } return (n->x == x && n->y < y) || n->x < x; } -static const RGraphNode *find_near_of(const RAGraph *g, const RGraphNode *cur, int is_next) { +static const RGraphNode *find_near_of(const RzAGraph *g, const RGraphNode *cur, int is_next) { /* XXX: it's slow */ - const RList *nodes = r_graph_get_nodes (g->graph); - const RListIter *it; + const RzList *nodes = rz_graph_get_nodes (g->graph); + const RzListIter *it; const RGraphNode *gn, *resgn = NULL; - const RANode *n, *acur = cur? get_anode (cur): NULL; + const RzANode *n, *acur = cur? get_anode (cur): NULL; const int default_v = is_next? INT_MIN: INT_MAX; const int start_x = acur? acur->x: default_v; const int start_y = acur? acur->y: default_v; @@ -2537,7 +2537,7 @@ static const RGraphNode *find_near_of(const RAGraph *g, const RGraphNode *cur, i ? is_near (n, start_x, start_y, is_next) : is_near_h (n, start_x, start_y, is_next); if (isNear) { - const RANode *resn; + const RzANode *resn; if (!resgn) { resgn = gn; @@ -2559,10 +2559,10 @@ static const RGraphNode *find_near_of(const RAGraph *g, const RGraphNode *cur, i return resgn; } -static void update_graph_sizes(RAGraph *g) { - RListIter *it; +static void update_graph_sizes(RzAGraph *g) { + RzListIter *it; RGraphNode *gk; - RANode *ak, *min_gn, *max_gn; + RzANode *ak, *min_gn, *max_gn; int max_x, max_y; int delta_x, delta_y; AEdge *e; @@ -2571,15 +2571,15 @@ static void update_graph_sizes(RAGraph *g) { max_x = max_y = INT_MIN; min_gn = max_gn = NULL; - graph_foreach_anode (r_graph_get_nodes (g->graph), it, gk, ak) { - const RList *nd = NULL; + graph_foreach_anode (rz_graph_get_nodes (g->graph), it, gk, ak) { + const RzList *nd = NULL; int len; if (ak->x < g->x) { g->x = ak->x; } - nd = r_graph_innodes (g->graph, gk); - len = nd ? r_list_length (nd) + 1 : 0; + nd = rz_graph_innodes (g->graph, gk); + len = nd ? rz_list_length (nd) + 1 : 0; if (ak->y - len < g->y) { g->y = ak->y - len; min_gn = ak; @@ -2590,22 +2590,22 @@ static void update_graph_sizes(RAGraph *g) { } nd = NULL; - nd = r_graph_get_neighbours (g->graph, gk); - len = nd ? r_list_length (nd) + 2 : 0; + nd = rz_graph_get_neighbours (g->graph, gk); + len = nd ? rz_list_length (nd) + 2 : 0; if (ak->y + ak->h + len > max_y) { max_y = ak->y + ak->h + len; max_gn = ak; } } /* while calculating the graph size, take into account long edges */ - r_list_foreach (g->edges, it, e) { - RListIter *kt; + rz_list_foreach (g->edges, it, e) { + RzListIter *kt; void *vv; int v; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_list_foreach (e->x, kt, vv) { + rz_list_foreach (e->x, kt, vv) { v = (int) (size_t) vv; if (v < g->x) { g->x = v; @@ -2614,7 +2614,7 @@ static void update_graph_sizes(RAGraph *g) { max_x = v + 1; } } - r_list_foreach (e->y, kt, vv) { + rz_list_foreach (e->y, kt, vv) { v = (int) (size_t) vv; if (v < g->y) { g->y = v; @@ -2624,17 +2624,17 @@ static void update_graph_sizes(RAGraph *g) { } } } - r_cons_break_pop (); + rz_cons_break_pop (); if (min_gn) { - const RList *neigh = r_graph_innodes (g->graph, min_gn->gnode); - if (r_list_length (neigh) > 0) { + const RzList *neigh = rz_graph_innodes (g->graph, min_gn->gnode); + if (rz_list_length (neigh) > 0) { g->y--; max_y++; } if (max_gn) { - const RList *neigh = r_graph_get_neighbours (g->graph, min_gn->gnode); - if (r_list_length (neigh) > 0) { + const RzList *neigh = rz_graph_get_neighbours (g->graph, min_gn->gnode); + if (rz_list_length (neigh) > 0) { max_y++; } } @@ -2667,7 +2667,7 @@ static void update_graph_sizes(RAGraph *g) { sdb_num_set (g->db, "agraph.delta_y", delta_y, 0); } -R_API void r_agraph_set_curnode(RAGraph *g, RANode *a) { +RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *a) { if (!a) { return; } @@ -2680,19 +2680,19 @@ R_API void r_agraph_set_curnode(RAGraph *g, RANode *a) { } } -static ut64 rebase(RAGraph *g, int v) { +static ut64 rebase(RzAGraph *g, int v) { return g->x < 0? -g->x + v: v; } -static void agraph_set_layout(RAGraph *g) { - RListIter *it; +static void agraph_set_layout(RzAGraph *g) { + RzListIter *it; RGraphNode *n; - RANode *a; + RzANode *a; set_layout (g); update_graph_sizes (g); - graph_foreach_anode (r_graph_get_nodes (g->graph), it, n, a) { + graph_foreach_anode (rz_graph_get_nodes (g->graph), it, n, a) { if (a->is_dummy) { continue; } @@ -2709,31 +2709,31 @@ static void agraph_set_layout(RAGraph *g) { } /* set the willing to center the screen on a particular node */ -static void agraph_update_seek(RAGraph *g, RANode *n, int force) { +static void agraph_update_seek(RzAGraph *g, RzANode *n, int force) { g->update_seek_on = n; g->force_update_seek = force; } -static void agraph_print_node(const RAGraph *g, RANode *n) { +static void agraph_print_node(const RzAGraph *g, RzANode *n) { if (n->is_dummy) { return; } const int cur = g->curnode && get_anode (g->curnode) == n; const bool isMini = is_mini (g); if (g->is_tiny) { - tiny_RANode_print (g, n, cur); + tiny_RzANode_print (g, n, cur); } else if (isMini || n->is_mini) { - mini_RANode_print (g, n, cur, isMini); + mini_RzANode_print (g, n, cur, isMini); } else { - normal_RANode_print (g, n, cur); + normal_RzANode_print (g, n, cur); } } -static void agraph_print_nodes(const RAGraph *g) { - const RList *nodes = r_graph_get_nodes (g->graph); +static void agraph_print_nodes(const RzAGraph *g) { + const RzList *nodes = rz_graph_get_nodes (g->graph); RGraphNode *gn; - RListIter *it; - RANode *n; + RzListIter *it; + RzANode *n; graph_foreach_anode (nodes, it, gn, n) { if (gn != g->curnode) { @@ -2769,14 +2769,14 @@ int tmplayercmp (const void *a, const void *b) { return ((struct tmplayer *)a)->layer > ((struct tmplayer *)b)->layer; } -static void agraph_print_edges_simple(RAGraph *g) { +static void agraph_print_edges_simple(RzAGraph *g) { RCanvasLineStyle style = {0}; - RANode *n, *n2; + RzANode *n, *n2; RGraphNode *gn, *gn2; - RListIter *iter, *iter2; - const RList *nodes = r_graph_get_nodes (g->graph); + RzListIter *iter, *iter2; + const RzList *nodes = rz_graph_get_nodes (g->graph); graph_foreach_anode (nodes, iter, gn, n) { - const RList *outnodes = n->gnode->out_nodes; + const RzList *outnodes = n->gnode->out_nodes; graph_foreach_anode (outnodes, iter2, gn2, n2) { int sx = n->w / 2; int sy = n->h; @@ -2787,12 +2787,12 @@ static void agraph_print_edges_simple(RAGraph *g) { sx2 = 0; } // TODO: better alignments here - r_cons_canvas_line (g->can, + rz_cons_canvas_line (g->can, n->x + sx, n->y + sy, n2->x + sx2, n2->y, &style); if (n2->is_dummy) { - r_cons_canvas_line (g->can, + rz_cons_canvas_line (g->can, n2->x + sx2, n2->y - 1, n2->x + sx2, n2->y + n2->h, &style); } @@ -2803,8 +2803,8 @@ static void agraph_print_edges_simple(RAGraph *g) { static int first_x_cmp (const void *_a, const void *_b) { RGraphNode *ga = (RGraphNode *)_a; RGraphNode *gb = (RGraphNode *)_b; - RANode *a = (RANode*) ga->data; - RANode *b = (RANode*) gb->data; + RzANode *a = (RzANode*) ga->data; + RzANode *b = (RzANode*) gb->data; if (b->y < a->y) { return -1; } @@ -2820,7 +2820,7 @@ static int first_x_cmp (const void *_a, const void *_b) { return 0; } -static void agraph_print_edges(RAGraph *g) { +static void agraph_print_edges(RzAGraph *g) { if (!g->edgemode) { return; } @@ -2829,27 +2829,27 @@ static void agraph_print_edges(RAGraph *g) { return; } int out_nth, in_nth, bendpoint; - RListIter *itn, *itm, *ito; + RzListIter *itn, *itm, *ito; RCanvasLineStyle style = {0}; - const RList *nodes = r_graph_get_nodes (g->graph); + const RzList *nodes = rz_graph_get_nodes (g->graph); RGraphNode *ga; - RANode *a; + RzANode *a; - RList *lyr = r_list_new (); - RList *bckedges = r_list_new (); + RzList *lyr = rz_list_new (); + RzList *bckedges = rz_list_new (); struct tmplayer *tl, *tm; graph_foreach_anode (nodes, itm, ga, a) { const RGraphNode *gb; - RANode *b; - RList *neighbours = (RList *)r_graph_get_neighbours (g->graph, ga); + RzANode *b; + RzList *neighbours = (RzList *)rz_graph_get_neighbours (g->graph, ga); int ax, ay, bx, by, a_x_inc, b_x_inc; tl = tm = NULL; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_list_foreach (lyr, ito, tl) { + rz_list_foreach (lyr, ito, tl) { if (tl->layer == a->layer) { tm = tl; if (g->layout == 0) { //vertical layout @@ -2884,15 +2884,15 @@ static void agraph_print_edges(RAGraph *g) { tm->minx = a->y; tm->maxx = a->y + a->h; } - r_list_add_sorted (lyr, tm, tmplayercmp); + rz_list_add_sorted (lyr, tm, tmplayercmp); } } - bool many = r_list_length (neighbours) > 2; + bool many = rz_list_length (neighbours) > 2; if (many && !g->is_callgraph) { ga->out_nodes->sorted = false; - r_list_sort (neighbours, first_x_cmp); + rz_list_sort (neighbours, first_x_cmp); } graph_foreach_anode (neighbours, itn, gb, b) { @@ -2901,12 +2901,12 @@ static void agraph_print_edges(RAGraph *g) { bool parent_many = false; if (a->is_dummy) { - RANode *in = (RANode *) (((RGraphNode *)r_list_first (ga->in_nodes))->data); + RzANode *in = (RzANode *) (((RGraphNode *)rz_list_first (ga->in_nodes))->data); while (in && in->is_dummy) { - in = (RANode *) (((RGraphNode *)r_list_first ((in->gnode)->in_nodes))->data); + in = (RzANode *) (((RGraphNode *)rz_list_first ((in->gnode)->in_nodes))->data); } if (in && in->gnode) { - parent_many = r_list_length (in->gnode->out_nodes) > 2; + parent_many = rz_list_length (in->gnode->out_nodes) > 2; } else { parent_many = false; } @@ -2962,12 +2962,12 @@ static void agraph_print_edges(RAGraph *g) { ax += (many && !g->is_callgraph) ? 0 : 4; } if (a->h < a->layer_height) { - r_cons_canvas_line (g->can, ax, ay, ax, ay + a->layer_height - a->h, &style); + rz_cons_canvas_line (g->can, ax, ay, ax, ay + a->layer_height - a->h, &style); ay = a->y + a->layer_height; style.symbol = LINE_NOSYM_VERT; } if (by >= ay) { - r_cons_canvas_line_square_defined (g->can, ax, ay, bx, by, &style, bendpoint, true); + rz_cons_canvas_line_square_defined (g->can, ax, ay, bx, by, &style, bendpoint, true); } else { struct tmpbackedgeinfo *tmp = calloc (1, sizeof (struct tmpbackedgeinfo)); tmp->ax = ax; @@ -2978,11 +2978,11 @@ static void agraph_print_edges(RAGraph *g) { tmp->fromlayer = a->layer; tmp->tolayer = b->layer; tmp->style = style; - r_list_append (bckedges, tmp); + rz_list_append (bckedges, tmp); } if (b->is_dummy) { style.symbol = LINE_NOSYM_VERT; - r_cons_canvas_line (g->can, bx, by, bx, b->y + b->h, &style); + rz_cons_canvas_line (g->can, bx, by, bx, b->y + b->h, &style); } if (b->x != a->x || b->layer <= a->layer || (!a->is_dummy && b->is_dummy) || (a->is_dummy && !b->is_dummy)) { if (tm) { @@ -3013,7 +3013,7 @@ static void agraph_print_edges(RAGraph *g) { } if (a->w < a->layer_width) { - r_cons_canvas_line_square_defined (g->can, ax, ay, a->x + a->layer_width, ay, &style, 0, false); + rz_cons_canvas_line_square_defined (g->can, ax, ay, a->x + a->layer_width, ay, &style, 0, false); ax = a->x; if (g->zoom > 1) { ax += a->layer_width; @@ -3023,7 +3023,7 @@ static void agraph_print_edges(RAGraph *g) { style.symbol = LINE_NOSYM_HORIZ; } if (bx >= ax) { - r_cons_canvas_line_square_defined (g->can, ax, ay, bx, by, &style, tm->edgectr, false); + rz_cons_canvas_line_square_defined (g->can, ax, ay, bx, by, &style, tm->edgectr, false); } else { struct tmpbackedgeinfo *tmp = calloc (1, sizeof (struct tmpbackedgeinfo)); if (tmp) { @@ -3035,12 +3035,12 @@ static void agraph_print_edges(RAGraph *g) { tmp->fromlayer = a->layer; tmp->tolayer = b->layer; tmp->style = style; - r_list_append (bckedges, tmp); + rz_list_append (bckedges, tmp); } } if (b->is_dummy) { style.symbol = LINE_NOSYM_HORIZ; - r_cons_canvas_line_square_defined (g->can, bx, by, bx + b->layer_width, by, &style, 0, false); + rz_cons_canvas_line_square_defined (g->can, bx, by, bx + b->layer_width, by, &style, 0, false); } if ((b->y == a->y && b->h != a->h) || b->y != a->y || b->layer <= a->layer || (!a->is_dummy && b->is_dummy) || (a->is_dummy && !b->is_dummy)) { tm->edgectr += 1; @@ -3051,16 +3051,16 @@ static void agraph_print_edges(RAGraph *g) { } struct tmpbackedgeinfo *temp; - r_list_foreach (bckedges, itm, temp) { + rz_list_foreach (bckedges, itm, temp) { int leftlen, rightlen; int minx = 0, maxx = 0; struct tmplayer *tt = NULL; - tl = r_list_get_n (lyr, temp->fromlayer); - if (r_cons_is_breaked ()) { + tl = rz_list_get_n (lyr, temp->fromlayer); + if (rz_cons_is_breaked ()) { break; } - r_list_foreach (lyr, ito, tl) { + rz_list_foreach (lyr, ito, tl) { if (tl->layer <= temp->tolayer) { tt = tl; minx = tl->minx; @@ -3087,10 +3087,10 @@ static void agraph_print_edges(RAGraph *g) { if (tt) { int arg = (rightlen < leftlen)? maxx + 1: minx - 1; - r_cons_canvas_line_back_edge (g->can, temp->ax, temp->ay, temp->bx, temp->by, &(temp->style), temp->edgectr, arg, tt->revedgectr, !g->layout); + rz_cons_canvas_line_back_edge (g->can, temp->ax, temp->ay, temp->bx, temp->by, &(temp->style), temp->edgectr, arg, tt->revedgectr, !g->layout); } - r_list_foreach (lyr, ito, tl) { + rz_list_foreach (lyr, ito, tl) { if (tl->layer < temp->tolayer) { continue; } @@ -3105,26 +3105,26 @@ static void agraph_print_edges(RAGraph *g) { } } - r_list_foreach (lyr, ito, tl) { + rz_list_foreach (lyr, ito, tl) { free (tl); } - r_list_foreach (bckedges, ito, tl) { + rz_list_foreach (bckedges, ito, tl) { free (tl); } - r_list_free (lyr); - r_list_free (bckedges); - r_cons_break_pop (); + rz_list_free (lyr); + rz_list_free (bckedges); + rz_cons_break_pop (); } -static void agraph_toggle_callgraph(RAGraph *g) { +static void agraph_toggle_callgraph(RzAGraph *g) { g->is_callgraph = !g->is_callgraph; g->need_reload_nodes = true; g->force_update_seek = true; } -static void agraph_set_zoom(RAGraph *g, int v) { +static void agraph_set_zoom(RzAGraph *g, int v) { if (v >= -10) { g->is_tiny = false; if (v == 0) { @@ -3151,26 +3151,26 @@ static void agraph_set_zoom(RAGraph *g, int v) { /* reload all the info in the nodes, depending on the type of the graph * (callgraph, CFG, etc.), set the default layout for these nodes and center * the screen on the selected one */ -static bool agraph_reload_nodes(RAGraph *g, RCore *core, RAnalFunction *fcn) { - r_agraph_reset (g); +static bool agraph_reload_nodes(RzAGraph *g, RzCore *core, RzAnalFunction *fcn) { + rz_agraph_reset (g); return reload_nodes (g, core, fcn); } -static void follow_nth(RAGraph *g, int nth) { - const RGraphNode *cn = r_graph_nth_neighbour (g->graph, g->curnode, nth); - RANode *a = get_anode (cn); +static void follow_nth(RzAGraph *g, int nth) { + const RGraphNode *cn = rz_graph_nth_neighbour (g->graph, g->curnode, nth); + RzANode *a = get_anode (cn); while (a && a->is_dummy) { - cn = r_graph_nth_neighbour (g->graph, a->gnode, 0); + cn = rz_graph_nth_neighbour (g->graph, a->gnode, 0); a = get_anode (cn); } if (a) { - r_agraph_set_curnode (g, a); + rz_agraph_set_curnode (g, a); } } -static void move_current_node(RAGraph *g, int xdiff, int ydiff) { - RANode *n = get_anode (g->curnode); +static void move_current_node(RzAGraph *g, int xdiff, int ydiff) { + RzANode *n = get_anode (g->curnode); if (n) { if (is_tiny (g)) { xdiff = NORMALIZE_MOV (xdiff); @@ -3183,28 +3183,28 @@ static void move_current_node(RAGraph *g, int xdiff, int ydiff) { #if GRAPH_MERGE_FEATURE #define K_NEIGHBOURS(x) (sdb_fmt ("agraph.nodes.%s.neighbours", x->title)) -static void agraph_merge_child(RAGraph *g, int idx) { - const RGraphNode *nn = r_graph_nth_neighbour (g->graph, g->curnode, idx); +static void agraph_merge_child(RzAGraph *g, int idx) { + const RGraphNode *nn = rz_graph_nth_neighbour (g->graph, g->curnode, idx); const RGraphNode *cn = g->curnode; if (cn && nn) { - RANode *ann = get_anode (nn); - RANode *acn = get_anode (cn); - acn->body = r_str_append (acn->body, ann->title); - acn->body = r_str_append (acn->body, "\n"); - acn->body = r_str_append (acn->body, ann->body); + RzANode *ann = get_anode (nn); + RzANode *acn = get_anode (cn); + acn->body = rz_str_append (acn->body, ann->title); + acn->body = rz_str_append (acn->body, "\n"); + acn->body = rz_str_append (acn->body, ann->body); /* remove node from the graph */ acn->h += ann->h - 3; free (ann->body); // TODO: do not merge nodes if those have edges targeting them // TODO: Add children neighbours to current one // nn->body - // r_agraph_set_curnode (g, get_anode (cn)); + // rz_agraph_set_curnode (g, get_anode (cn)); // agraph_refresh (grd); - // r_agraph_add_edge (g, from, to); + // rz_agraph_add_edge (g, from, to); char *neis = sdb_get (g->db, K_NEIGHBOURS (ann), 0); if (neis) { sdb_set_owned (g->db, K_NEIGHBOURS (ann), neis, 0); - r_agraph_del_node (g, ann->title); + rz_agraph_del_node (g, ann->title); agraph_print_nodes (g); agraph_print_edges (g); } @@ -3213,72 +3213,72 @@ static void agraph_merge_child(RAGraph *g, int idx) { } #endif -static void agraph_toggle_tiny (RAGraph *g) { +static void agraph_toggle_tiny (RzAGraph *g) { g->is_tiny = !g->is_tiny; g->need_update_dim = 1; - agraph_refresh (r_cons_singleton ()->event_data); - agraph_set_layout ((RAGraph *) g); + agraph_refresh (rz_cons_singleton ()->event_data); + agraph_set_layout ((RzAGraph *) g); //remove_dummy_nodes (g); } -static void agraph_toggle_mini(RAGraph *g) { - RANode *n = get_anode (g->curnode); +static void agraph_toggle_mini(RzAGraph *g) { + RzANode *n = get_anode (g->curnode); if (n) { n->is_mini = !n->is_mini; } g->need_update_dim = 1; - agraph_refresh (r_cons_singleton ()->event_data); - agraph_set_layout ((RAGraph *) g); + agraph_refresh (rz_cons_singleton ()->event_data); + agraph_set_layout ((RzAGraph *) g); } -static void agraph_follow_innodes(RAGraph *g, bool in) { +static void agraph_follow_innodes(RzAGraph *g, bool in) { int count = 0; - RListIter *iter; - RANode *an = get_anode (g->curnode); + RzListIter *iter; + RzANode *an = get_anode (g->curnode); if (!an) { return; } RGraphNode *gn = an->gnode; - const RList *list = in? an->gnode->in_nodes: an->gnode->out_nodes; + const RzList *list = in? an->gnode->in_nodes: an->gnode->out_nodes; int nth = -1; - if (r_list_length (list) == 0) { + if (rz_list_length (list) == 0) { return; } - r_cons_gotoxy (0, 2); - r_cons_printf (in? "Input nodes:\n": "Output nodes:\n"); - RList *options = r_list_newf (NULL); - RList *gnodes = in? an->gnode->in_nodes: an->gnode->out_nodes; - r_list_foreach (gnodes, iter, gn) { - RANode *an = get_anode (gn); + rz_cons_gotoxy (0, 2); + rz_cons_printf (in? "Input nodes:\n": "Output nodes:\n"); + RzList *options = rz_list_newf (NULL); + RzList *gnodes = in? an->gnode->in_nodes: an->gnode->out_nodes; + rz_list_foreach (gnodes, iter, gn) { + RzANode *an = get_anode (gn); RGraphNode *gnn = agraph_get_title (g, an, in); if (gnn) { - RANode *nnn = gnn->data; - RANode *o; - RListIter *iter2; + RzANode *nnn = gnn->data; + RzANode *o; + RzListIter *iter2; // avoid dupes - r_list_foreach (options, iter2, o) { + rz_list_foreach (options, iter2, o) { if (!strcmp (o->title, nnn->title)) { continue; } } - r_cons_printf ("%d %s\n", count, nnn->title); - r_list_append (options, nnn); + rz_cons_printf ("%d %s\n", count, nnn->title); + rz_list_append (options, nnn); count++; } } - r_cons_flush (); - if (r_list_length (list) == 1) { + rz_cons_flush (); + if (rz_list_length (list) == 1) { nth = 0; - } else if (r_list_length (list) < 10) { + } else if (rz_list_length (list) < 10) { // just 1 key - char ch = r_cons_readchar (); + char ch = rz_cons_readchar (); if (ch >= '0' && ch <= '9') { nth = ch - '0'; } } else { - r_cons_show_cursor (true); - r_cons_enable_mouse (false); - char *nth_string = r_cons_input ("index> "); + rz_cons_show_cursor (true); + rz_cons_enable_mouse (false); + char *nth_string = rz_cons_input ("index> "); nth = atoi (nth_string); if (nth == 0 && *nth_string != '0') { nth = -1; @@ -3286,58 +3286,58 @@ static void agraph_follow_innodes(RAGraph *g, bool in) { free (nth_string); } if (nth != -1) { - RANode *selected_node = r_list_get_n (options, nth); - r_agraph_set_curnode (g, selected_node); + RzANode *selected_node = rz_list_get_n (options, nth); + rz_agraph_set_curnode (g, selected_node); } - r_list_free (options); + rz_list_free (options); agraph_update_seek (g, get_anode (g->curnode), false); } -static void agraph_follow_true(RAGraph *g) { +static void agraph_follow_true(RzAGraph *g) { follow_nth (g, 0); agraph_update_seek (g, get_anode (g->curnode), false); } -static void agraph_follow_false(RAGraph *g) { +static void agraph_follow_false(RzAGraph *g) { follow_nth (g, 1); agraph_update_seek (g, get_anode (g->curnode), false); } /* seek the next node in visual order */ -static void agraph_next_node(RAGraph *g) { - RANode *a = get_anode (find_near_of (g, g->curnode, true)); +static void agraph_next_node(RzAGraph *g) { + RzANode *a = get_anode (find_near_of (g, g->curnode, true)); while (a && a->is_dummy) { a = get_anode (find_near_of (g, a->gnode, true)); } - r_agraph_set_curnode (g, a); + rz_agraph_set_curnode (g, a); agraph_update_seek (g, get_anode (g->curnode), false); } /* seek the previous node in visual order */ -static void agraph_prev_node(RAGraph *g) { - RANode *a = get_anode (find_near_of (g, g->curnode, false)); +static void agraph_prev_node(RzAGraph *g) { + RzANode *a = get_anode (find_near_of (g, g->curnode, false)); while (a && a->is_dummy) { a = get_anode (find_near_of (g, a->gnode, false)); } - r_agraph_set_curnode (g, a); + rz_agraph_set_curnode (g, a); agraph_update_seek (g, get_anode (g->curnode), false); } -static void agraph_update_title(RCore *core, RAGraph *g, RAnalFunction *fcn) { - RANode *a = get_anode (g->curnode); - char *sig = r_core_cmd_str (core, "afcf"); - char *new_title = r_str_newf ( +static void agraph_update_title(RzCore *core, RzAGraph *g, RzAnalFunction *fcn) { + RzANode *a = get_anode (g->curnode); + char *sig = rz_core_cmd_str (core, "afcf"); + char *new_title = rz_str_newf ( "%s[0x%08"PFMT64x "]> %s # %s ", graphCursor? "(cursor)": "", fcn->addr, a? a->title: "", sig); - r_agraph_set_title (g, new_title); + rz_agraph_set_title (g, new_title); free (new_title); free (sig); } /* look for any change in the state of the graph * and update what's necessary */ -static bool check_changes(RAGraph *g, int is_interactive, RCore *core, RAnalFunction *fcn) { +static bool check_changes(RzAGraph *g, int is_interactive, RzCore *core, RzAnalFunction *fcn) { int oldpos[2] = { 0, 0 }; @@ -3355,7 +3355,7 @@ static bool check_changes(RAGraph *g, int is_interactive, RCore *core, RAnalFunc agraph_update_title (core, g, fcn); } if (core && core->config) { - if (r_config_get_i (core->config, "graph.trace")) { + if (rz_config_get_i (core->config, "graph.trace")) { // fold all bbs not traced fold_asm_trace (core, g); } @@ -3367,24 +3367,24 @@ static bool check_changes(RAGraph *g, int is_interactive, RCore *core, RAnalFunc agraph_set_layout (g); } if (core) { - ut64 off = r_anal_get_bbaddr (core->anal, core->offset); + ut64 off = rz_anal_get_bbaddr (core->anal, core->offset); if (off != UT64_MAX) { char *title = get_title (off); - RANode *cur_anode = get_anode (g->curnode); + RzANode *cur_anode = get_anode (g->curnode); if (fcn && ((is_interactive && !cur_anode) || (cur_anode && strcmp (cur_anode->title, title)))) { - g->update_seek_on = r_agraph_get_node (g, title); + g->update_seek_on = rz_agraph_get_node (g, title); if (g->update_seek_on) { - r_agraph_set_curnode (g, g->update_seek_on); + rz_agraph_set_curnode (g, g->update_seek_on); g->force_update_seek = true; } } free (title); } - g->can->color = r_config_get_i (core->config, "scr.color"); - g->hints = r_config_get_i (core->config, "graph.hints"); + g->can->color = rz_config_get_i (core->config, "scr.color"); + g->hints = rz_config_get_i (core->config, "graph.hints"); } if (g->update_seek_on || g->force_update_seek) { - RANode *n = g->update_seek_on; + RzANode *n = g->update_seek_on; if (!n && g->curnode) { n = get_anode (g->curnode); } @@ -3404,15 +3404,15 @@ static bool check_changes(RAGraph *g, int is_interactive, RCore *core, RAnalFunc return true; } -static int agraph_print(RAGraph *g, int is_interactive, RCore *core, RAnalFunction *fcn) { - int h, w = r_cons_get_size (&h); +static int agraph_print(RzAGraph *g, int is_interactive, RzCore *core, RzAnalFunction *fcn) { + int h, w = rz_cons_get_size (&h); bool ret = check_changes (g, is_interactive, core, fcn); if (!ret) { return false; } if (is_interactive) { - r_cons_clear00 (); + rz_cons_clear00 (); } else { /* TODO: limit to screen size when the output is not redirected to file */ update_graph_sizes (g); @@ -3420,30 +3420,30 @@ static int agraph_print(RAGraph *g, int is_interactive, RCore *core, RAnalFuncti h = is_interactive? h: g->h + 1; w = is_interactive? w: g->w + 2; - if (!r_cons_canvas_resize (g->can, w, h)) { + if (!rz_cons_canvas_resize (g->can, w, h)) { return false; } - // r_cons_canvas_clear (g->can); + // rz_cons_canvas_clear (g->can); if (!is_interactive) { g->can->sx = -g->x; g->can->sy = -g->y - 1; } if (g->is_dis) { (void) G (-g->can->sx + 1, -g->can->sy + 2); - int scr_utf8 = r_config_get_i (core->config, "scr.utf8"); - int asm_bytes = r_config_get_i (core->config, "asm.bytes"); - int asm_cmt_right = r_config_get_i (core->config, "asm.cmt.right"); - r_config_set_i (core->config, "scr.utf8", 0); - r_config_set_i (core->config, "asm.bytes", 0); - r_config_set_i (core->config, "asm.cmt.right", 0); - char *str = r_core_cmd_str (core, "pd $r"); + int scr_utf8 = rz_config_get_i (core->config, "scr.utf8"); + int asm_bytes = rz_config_get_i (core->config, "asm.bytes"); + int asm_cmt_right = rz_config_get_i (core->config, "asm.cmt.right"); + rz_config_set_i (core->config, "scr.utf8", 0); + rz_config_set_i (core->config, "asm.bytes", 0); + rz_config_set_i (core->config, "asm.cmt.right", 0); + char *str = rz_core_cmd_str (core, "pd $r"); if (str) { W (str); free (str); } - r_config_set_i (core->config, "scr.utf8", scr_utf8); - r_config_set_i (core->config, "asm.bytes", asm_bytes); - r_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); + rz_config_set_i (core->config, "scr.utf8", scr_utf8); + rz_config_set_i (core->config, "asm.bytes", asm_bytes); + rz_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); } if (g->title && *g->title) { g->can->sy ++; @@ -3460,28 +3460,28 @@ static int agraph_print(RAGraph *g, int is_interactive, RCore *core, RAnalFuncti } if (is_interactive && g->title) { int title_len = strlen (g->title); - r_cons_canvas_fill (g->can, -g->can->sx + title_len, -g->can->sy, + rz_cons_canvas_fill (g->can, -g->can->sx + title_len, -g->can->sy, w - title_len, 1, ' '); } - r_cons_canvas_print_region (g->can); + rz_cons_canvas_print_region (g->can); if (is_interactive) { - r_cons_newline (); - const char *cmdv = r_config_get (core->config, "cmd.gprompt"); + rz_cons_newline (); + const char *cmdv = rz_config_get (core->config, "cmd.gprompt"); bool mustFlush = false; - r_cons_visual_flush (); + rz_cons_visual_flush (); if (cmdv && *cmdv) { - r_cons_gotoxy (0, 2); - r_cons_strcat (Color_RESET); - r_core_cmd0 (core, cmdv); + rz_cons_gotoxy (0, 2); + rz_cons_strcat (Color_RESET); + rz_core_cmd0 (core, cmdv); mustFlush = true; } if (core && core->scr_gadgets) { - r_core_cmd0 (core, "pg"); + rz_core_cmd0 (core, "pg"); } if (mustFlush) { - r_cons_flush (); + rz_cons_flush (); } } return true; @@ -3491,11 +3491,11 @@ static int agraph_refresh(struct agraph_refresh_data *grd) { if (!grd) { return 0; } - r_cons_singleton ()->event_data = grd; - RCore *core = grd->core; - RAGraph *g = grd->g; - RAnalFunction *f = NULL; - RAnalFunction **fcn = grd->fcn; + rz_cons_singleton ()->event_data = grd; + RzCore *core = grd->core; + RzAGraph *g = grd->g; + RzAnalFunction *f = NULL; + RzAnalFunction **fcn = grd->fcn; if (!fcn) { return agraph_print (g, grd->fs, core, NULL); @@ -3504,31 +3504,31 @@ static int agraph_refresh(struct agraph_refresh_data *grd) { // allow to change the current function during debugging if (g->is_instep && core->bin->is_debugger) { // seek only when the graph node changes - const char *pc = r_reg_get_name (core->dbg->reg, R_REG_NAME_PC); - RRegItem *r = r_reg_get (core->dbg->reg, pc, -1); - ut64 addr = r_reg_get_value (core->dbg->reg, r); - RANode *acur = get_anode (g->curnode); + const char *pc = rz_reg_get_name (core->dbg->reg, R_REG_NAME_PC); + RzRegItem *r = rz_reg_get (core->dbg->reg, pc, -1); + ut64 addr = rz_reg_get_value (core->dbg->reg, r); + RzANode *acur = get_anode (g->curnode); - addr = r_anal_get_bbaddr (core->anal, addr); + addr = rz_anal_get_bbaddr (core->anal, addr); char *title = get_title (addr); if (!acur || strcmp (acur->title, title)) { - r_core_cmd0 (core, "sr PC"); + rz_core_cmd0 (core, "sr PC"); } free (title); g->is_instep = false; } if (grd->follow_offset) { - if (r_io_is_valid_offset (core->io, core->offset, 0)) { - f = r_anal_get_fcn_in (core->anal, core->offset, 0); + if (rz_io_is_valid_offset (core->io, core->offset, 0)) { + f = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (!f) { if (!g->is_dis) { - if (!r_cons_yesno ('y', "\rNo function at 0x%08"PFMT64x". Define it here (Y/n)? ", core->offset)) { + if (!rz_cons_yesno ('y', "\rNo function at 0x%08"PFMT64x". Define it here (Y/n)? ", core->offset)) { return 0; } - r_core_cmd0 (core, "af"); + rz_core_cmd0 (core, "af"); } - f = r_anal_get_fcn_in (core->anal, core->offset, 0); + f = rz_anal_get_fcn_in (core->anal, core->offset, 0); g->need_reload_nodes = true; } if (f && fcn && f != *fcn) { @@ -3538,53 +3538,53 @@ static int agraph_refresh(struct agraph_refresh_data *grd) { } } else { // TODO: maybe go back to avoid seeking from graph view to an scary place? - r_cons_message ("This is not a valid offset\n"); - r_cons_flush (); + rz_cons_message ("This is not a valid offset\n"); + rz_cons_flush (); } } int res = agraph_print (g, grd->fs, core, *fcn); - if (r_config_get_i (core->config, "scr.scrollbar")) { - r_core_print_scrollbar (core); + if (rz_config_get_i (core->config, "scr.scrollbar")) { + rz_core_print_scrollbar (core); } return res; } static void agraph_refresh_oneshot(struct agraph_refresh_data *grd) { - r_core_task_enqueue_oneshot (&grd->core->tasks, (RCoreTaskOneShot) agraph_refresh, grd); + rz_core_task_enqueue_oneshot (&grd->core->tasks, (RzCoreTaskOneShot) agraph_refresh, grd); } -static void agraph_toggle_speed(RAGraph *g, RCore *core) { - const int alt = r_config_get_i (core->config, "graph.scroll"); +static void agraph_toggle_speed(RzAGraph *g, RzCore *core) { + const int alt = rz_config_get_i (core->config, "graph.scroll"); g->movspeed = g->movspeed == DEFAULT_SPEED? alt: DEFAULT_SPEED; } -static void agraph_init(RAGraph *g) { +static void agraph_init(RzAGraph *g) { g->is_callgraph = false; g->is_instep = false; g->need_reload_nodes = true; g->show_node_titles = true; g->show_node_body = true; g->force_update_seek = true; - g->graph = r_graph_new (); + g->graph = rz_graph_new (); g->nodes = sdb_new0 (); g->edgemode = 2; g->zoom = ZOOM_DEFAULT; g->hints = 1; g->movspeed = DEFAULT_SPEED; g->db = sdb_new0 (); - r_vector_init (&g->ghits.word_list, sizeof (struct r_agraph_location), NULL, NULL); + rz_vector_init (&g->ghits.word_list, sizeof (struct rz_agraph_location), NULL, NULL); } -static void free_anode(RANode *n) { +static void free_anode(RzANode *n) { free (n->title); free (n->body); free (n); } -static void graphNodeMove(RAGraph *g, int dir, int speed) { +static void graphNodeMove(RzAGraph *g, int dir, int speed) { int delta = (dir == 'k')? -1: 1; if (dir == 'H') { return; @@ -3599,23 +3599,23 @@ static void graphNodeMove(RAGraph *g, int dir, int speed) { } return; } - RCore *core = NULL; + RzCore *core = NULL; // vertical scroll if (is_mini (g)) { discroll += (delta * speed); } else if (g->is_dis) { - r_core_cmdf (core, "so %d", (delta * 4) * speed); + rz_core_cmdf (core, "so %d", (delta * 4) * speed); } else { move_current_node (g, 0, delta * speed); } } -static void agraph_free_nodes(const RAGraph *g) { - RListIter *it; +static void agraph_free_nodes(const RzAGraph *g) { + RzListIter *it; RGraphNode *n; - RANode *a; + RzANode *a; - graph_foreach_anode (r_graph_get_nodes (g->graph), it, n, a) { + graph_foreach_anode (rz_graph_get_nodes (g->graph), it, n, a) { free_anode (a); } @@ -3628,9 +3628,9 @@ static void sdb_set_enc(Sdb *db, const char *key, const char *v, ut32 cas) { free (estr); } -static void agraph_sdb_init(const RAGraph *g) { +static void agraph_sdb_init(const RzAGraph *g) { sdb_bool_set (g->db, "agraph.is_callgraph", g->is_callgraph, 0); - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); sdb_set_enc (g->db, "agraph.color_box", cons->context->pal.graph_box, 0); sdb_set_enc (g->db, "agraph.color_box2", cons->context->pal.graph_box2, 0); sdb_set_enc (g->db, "agraph.color_box3", cons->context->pal.graph_box3, 0); @@ -3638,7 +3638,7 @@ static void agraph_sdb_init(const RAGraph *g) { sdb_set_enc (g->db, "agraph.color_false", cons->context->pal.graph_false, 0); } -R_API Sdb *r_agraph_get_sdb(RAGraph *g) { +RZ_API Sdb *rz_agraph_get_sdb(RzAGraph *g) { g->need_update_dim = true; g->need_set_layout = true; (void)check_changes (g, false, NULL, NULL); @@ -3646,22 +3646,22 @@ R_API Sdb *r_agraph_get_sdb(RAGraph *g) { return g->db; } -R_API void r_agraph_print(RAGraph *g) { +RZ_API void rz_agraph_print(RzAGraph *g) { agraph_print (g, false, NULL, NULL); if (g->graph->n_nodes > 0) { - r_cons_newline (); + rz_cons_newline (); } } -R_API void r_agraph_print_json(RAGraph *g, PJ *pj) { - RList *nodes = g->graph->nodes, *neighbours = NULL; - RListIter *it, *itt; +RZ_API void rz_agraph_print_json(RzAGraph *g, PJ *pj) { + RzList *nodes = g->graph->nodes, *neighbours = NULL; + RzListIter *it, *itt; RGraphNode *node = NULL, *neighbour = NULL; if (!pj) { return; } - r_list_foreach (nodes, it, node) { - RANode *anode = (RANode *) node->data; + rz_list_foreach (nodes, it, node) { + RzANode *anode = (RzANode *) node->data; char *label = strdup (anode->body); pj_o (pj); pj_ki (pj, "id", anode->gnode->idx); @@ -3670,7 +3670,7 @@ R_API void r_agraph_print_json(RAGraph *g, PJ *pj) { pj_k (pj, "out_nodes"); pj_a (pj); neighbours = anode->gnode->out_nodes; - r_list_foreach (neighbours, itt, neighbour) { + rz_list_foreach (neighbours, itt, neighbour) { pj_i (pj, neighbour->idx); } pj_end (pj); @@ -3679,23 +3679,23 @@ R_API void r_agraph_print_json(RAGraph *g, PJ *pj) { } } -R_API void r_agraph_set_title(RAGraph *g, const char *title) { +RZ_API void rz_agraph_set_title(RzAGraph *g, const char *title) { free (g->title); g->title = title? strdup (title): NULL; sdb_set (g->db, "agraph.title", g->title, 0); } -R_API RANode *r_agraph_add_node_with_color(const RAGraph *g, const char *title, const char *body, int color) { - RANode *res = r_agraph_get_node (g, title); +RZ_API RzANode *rz_agraph_add_node_with_color(const RzAGraph *g, const char *title, const char *body, int color) { + RzANode *res = rz_agraph_get_node (g, title); if (res) { return res; } - res = R_NEW0 (RANode); + res = R_NEW0 (RzANode); if (!res) { return NULL; } - res->title = title? r_str_trunc_ellipsis (title, 255) : strdup (""); + res->title = title? rz_str_trunc_ellipsis (title, 255) : strdup (""); res->body = body? strdup (body): strdup (""); res->layer = -1; res->pos_in_layer = -1; @@ -3703,7 +3703,7 @@ R_API RANode *r_agraph_add_node_with_color(const RAGraph *g, const char *title, res->is_reversed = false; res->klass = -1; res->difftype = color; - res->gnode = r_graph_add_node (g->graph, res); + res->gnode = rz_graph_add_node (g->graph, res); sdb_num_set (g->nodes, res->title, (ut64) (size_t) res, 0); if (res->title) { char *s, *estr, *b; @@ -3716,7 +3716,7 @@ R_API RANode *r_agraph_add_node_with_color(const RAGraph *g, const char *title, } estr = sdb_encode ((const void *) b, -1); //s = sdb_fmt ("base64:%s", estr); - s = r_str_newf ("base64:%s", estr); + s = rz_str_newf ("base64:%s", estr); free (estr); free (b); sdb_set_owned (g->db, sdb_fmt ("agraph.nodes.%s.body", res->title), s, 0); @@ -3724,16 +3724,16 @@ R_API RANode *r_agraph_add_node_with_color(const RAGraph *g, const char *title, return res; } -R_API RANode *r_agraph_add_node(const RAGraph *g, const char *title, const char *body) { - return r_agraph_add_node_with_color(g, title, body, -1); +RZ_API RzANode *rz_agraph_add_node(const RzAGraph *g, const char *title, const char *body) { + return rz_agraph_add_node_with_color(g, title, body, -1); } -R_API bool r_agraph_del_node(const RAGraph *g, const char *title) { - char *title_trunc = r_str_trunc_ellipsis (title, 255); - RANode *an, *res = r_agraph_get_node (g, title_trunc); +RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title) { + char *title_trunc = rz_str_trunc_ellipsis (title, 255); + RzANode *an, *res = rz_agraph_get_node (g, title_trunc); free (title_trunc); RGraphNode *gn; - RListIter *it; + RzListIter *it; if (!res) { return false; @@ -3748,13 +3748,13 @@ R_API bool r_agraph_del_node(const RAGraph *g, const char *title) { sdb_set (g->db, sdb_fmt ("agraph.nodes.%s.h", res->title), NULL, 0); sdb_set (g->db, sdb_fmt ("agraph.nodes.%s.neighbours", res->title), NULL, 0); - const RList *innodes = r_graph_innodes (g->graph, res->gnode); + const RzList *innodes = rz_graph_innodes (g->graph, res->gnode); graph_foreach_anode (innodes, it, gn, an) { const char *key = sdb_fmt ("agraph.nodes.%s.neighbours", an->title); sdb_array_remove (g->db, key, res->title, 0); } - r_graph_del_node (g->graph, res->gnode); + rz_graph_del_node (g->graph, res->gnode); res->gnode = NULL; free_anode (res); @@ -3762,9 +3762,9 @@ R_API bool r_agraph_del_node(const RAGraph *g, const char *title) { } static int user_node_cb(struct g_cb *user, const char *k UNUSED, const char *v) { - RANodeCallback cb = user->node_cb; + RzANodeCallback cb = user->node_cb; void *user_data = user->data; - RANode *n = (RANode *) (size_t) sdb_atoi (v); + RzANode *n = (RzANode *) (size_t) sdb_atoi (v); if (n) { cb (n, user_data); } @@ -3773,14 +3773,14 @@ static int user_node_cb(struct g_cb *user, const char *k UNUSED, const char *v) static int user_edge_cb(struct g_cb *user, const char *k UNUSED, const char *v) { RAEdgeCallback cb = user->edge_cb; - RAGraph *g = user->graph; + RzAGraph *g = user->graph; void *user_data = user->data; - RANode *an, *n = (RANode *) (size_t) sdb_atoi (v); + RzANode *an, *n = (RzANode *) (size_t) sdb_atoi (v); if (!n) { return 0; } - const RList *neigh = r_graph_get_neighbours (g->graph, n->gnode); - RListIter *it; + const RzList *neigh = rz_graph_get_neighbours (g->graph, n->gnode); + RzListIter *it; RGraphNode *gn; graph_foreach_anode (neigh, it, gn, an) { @@ -3789,7 +3789,7 @@ static int user_edge_cb(struct g_cb *user, const char *k UNUSED, const char *v) return 1; } -R_API void r_agraph_foreach(RAGraph *g, RANodeCallback cb, void *user) { +RZ_API void rz_agraph_foreach(RzAGraph *g, RzANodeCallback cb, void *user) { struct g_cb u = { .node_cb = cb, .data = user @@ -3797,7 +3797,7 @@ R_API void r_agraph_foreach(RAGraph *g, RANodeCallback cb, void *user) { sdb_foreach (g->nodes, (SdbForeachCallback) user_node_cb, &u); } -R_API void r_agraph_foreach_edge(RAGraph *g, RAEdgeCallback cb, void *user) { +RZ_API void rz_agraph_foreach_edge(RzAGraph *g, RAEdgeCallback cb, void *user) { struct g_cb u = { .graph = g, .edge_cb = cb, @@ -3806,53 +3806,53 @@ R_API void r_agraph_foreach_edge(RAGraph *g, RAEdgeCallback cb, void *user) { sdb_foreach (g->nodes, (SdbForeachCallback) user_edge_cb, &u); } -R_API RANode *r_agraph_get_first_node(const RAGraph *g) { - const RList *l = r_graph_get_nodes (g->graph); - RGraphNode *rgn = r_list_first (l); +RZ_API RzANode *rz_agraph_get_first_node(const RzAGraph *g) { + const RzList *l = rz_graph_get_nodes (g->graph); + RGraphNode *rgn = rz_list_first (l); return get_anode (rgn); } -R_API RANode *r_agraph_get_node(const RAGraph *g, const char *title) { - char *title_trunc = title ? r_str_trunc_ellipsis (title, 255) : NULL; - RANode *node = (RANode *) (size_t) sdb_num_get (g->nodes, title_trunc, NULL); +RZ_API RzANode *rz_agraph_get_node(const RzAGraph *g, const char *title) { + char *title_trunc = title ? rz_str_trunc_ellipsis (title, 255) : NULL; + RzANode *node = (RzANode *) (size_t) sdb_num_get (g->nodes, title_trunc, NULL); free (title_trunc); return node; } -R_API void r_agraph_add_edge(const RAGraph *g, RANode *a, RANode *b) { - r_return_if_fail (g && a && b); - r_graph_add_edge (g->graph, a->gnode, b->gnode); +RZ_API void rz_agraph_add_edge(const RzAGraph *g, RzANode *a, RzANode *b) { + rz_return_if_fail (g && a && b); + rz_graph_add_edge (g->graph, a->gnode, b->gnode); if (a->title && b->title) { char *k = sdb_fmt ("agraph.nodes.%s.neighbours", a->title); sdb_array_add (g->db, k, b->title, 0); } } -R_API void r_agraph_add_edge_at(const RAGraph *g, RANode *a, RANode *b, int nth) { - r_return_if_fail (g && a && b); +RZ_API void rz_agraph_add_edge_at(const RzAGraph *g, RzANode *a, RzANode *b, int nth) { + rz_return_if_fail (g && a && b); if (a->title && b->title) { char *k = sdb_fmt ("agraph.nodes.%s.neighbours", a->title); sdb_array_insert (g->db, k, nth, b->title, 0); } - r_graph_add_edge_at (g->graph, a->gnode, b->gnode, nth); + rz_graph_add_edge_at (g->graph, a->gnode, b->gnode, nth); } -R_API void r_agraph_del_edge(const RAGraph *g, RANode *a, RANode *b) { - r_return_if_fail (g && a && b); +RZ_API void rz_agraph_del_edge(const RzAGraph *g, RzANode *a, RzANode *b) { + rz_return_if_fail (g && a && b); if (a->title && b->title) { const char *k = sdb_fmt ("agraph.nodes.%s.neighbours", a->title); sdb_array_remove (g->db, k, b->title, 0); } - r_graph_del_edge (g->graph, a->gnode, b->gnode); + rz_graph_del_edge (g->graph, a->gnode, b->gnode); } -R_API void r_agraph_reset(RAGraph *g) { +RZ_API void rz_agraph_reset(RzAGraph *g) { agraph_free_nodes (g); - r_graph_reset (g->graph); - r_agraph_set_title (g, NULL); + rz_graph_reset (g->graph); + rz_agraph_set_title (g, NULL); sdb_reset (g->db); if (g->edges) { - r_list_purge (g->edges); + rz_list_purge (g->edges); } g->nodes = sdb_new0 (); g->update_seek_on = NULL; @@ -3864,20 +3864,20 @@ R_API void r_agraph_reset(RAGraph *g) { g->curnode = NULL; } -R_API void r_agraph_free(RAGraph *g) { +RZ_API void rz_agraph_free(RzAGraph *g) { if (g) { agraph_free_nodes (g); - r_graph_free (g->graph); - r_list_free (g->edges); - r_agraph_set_title (g, NULL); + rz_graph_free (g->graph); + rz_list_free (g->edges); + rz_agraph_set_title (g, NULL); sdb_free (g->db); - r_cons_canvas_free (g->can); + rz_cons_canvas_free (g->can); free (g); } } -R_API RAGraph *r_agraph_new(RConsCanvas *can) { - RAGraph *g = R_NEW0 (RAGraph); +RZ_API RzAGraph *rz_agraph_new(RzConsCanvas *can) { + RzAGraph *g = R_NEW0 (RzAGraph); if (!g) { return NULL; } @@ -3888,73 +3888,73 @@ R_API RAGraph *r_agraph_new(RConsCanvas *can) { return g; } -static void visual_offset(RAGraph *g, RCore *core) { +static void visual_offset(RzAGraph *g, RzCore *core) { char buf[256]; int rows; - r_cons_get_size (&rows); - r_cons_gotoxy (0, rows); - r_cons_flush (); + rz_cons_get_size (&rows); + rz_cons_gotoxy (0, rows); + rz_cons_flush (); core->cons->line->prompt_type = R_LINE_PROMPT_OFFSET; - r_line_set_hist_callback (core->cons->line, &r_line_hist_offset_up, &r_line_hist_offset_down); - r_line_set_prompt ("[offset]> "); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_offset_up, &rz_line_hist_offset_down); + rz_line_set_prompt ("[offset]> "); strcpy (buf, "s "); - if (r_cons_fgets (buf + 2, sizeof (buf) - 2, 0, NULL) > 0) { + if (rz_cons_fgets (buf + 2, sizeof (buf) - 2, 0, NULL) > 0) { if (buf[2] == '.') { buf[1] = '.'; } - r_core_cmd0 (core, buf); - r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_core_cmd0 (core, buf); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); } core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT; } -static void goto_asmqjmps(RAGraph *g, RCore *core) { +static void goto_asmqjmps(RzAGraph *g, RzCore *core) { const char *h = "[Fast goto call/jmp]> "; char obuf[R_CORE_ASMQJMPS_LEN_LETTERS + 1]; int rows, i = 0; bool cont; - r_cons_get_size (&rows); - r_cons_gotoxy (0, rows); - r_cons_clear_line (0); - r_cons_printf (Color_RESET); - r_cons_printf (h); - r_cons_flush (); + rz_cons_get_size (&rows); + rz_cons_gotoxy (0, rows); + rz_cons_clear_line (0); + rz_cons_printf (Color_RESET); + rz_cons_printf (h); + rz_cons_flush (); do { - char ch = r_cons_readchar (); + char ch = rz_cons_readchar (); obuf[i++] = ch; - r_cons_printf ("%c", ch); + rz_cons_printf ("%c", ch); cont = isalpha ((ut8) ch) && !islower ((ut8) ch); } while (i < R_CORE_ASMQJMPS_LEN_LETTERS && cont); - r_cons_flush (); + rz_cons_flush (); obuf[i] = '\0'; - ut64 addr = r_core_get_asmqjmps (core, obuf); + ut64 addr = rz_core_get_asmqjmps (core, obuf); if (addr != UT64_MAX) { char *title = get_title (addr); - RANode *addr_node = r_agraph_get_node (g, title); + RzANode *addr_node = rz_agraph_get_node (g, title); if (addr_node) { - r_agraph_set_curnode (g, addr_node); - r_core_seek (core, addr, false); + rz_agraph_set_curnode (g, addr_node); + rz_core_seek (core, addr, false); agraph_update_seek (g, addr_node, true); } else { - r_io_sundo_push (core->io, core->offset, 0); - r_core_seek (core, addr, false); + rz_io_sundo_push (core->io, core->offset, 0); + rz_core_seek (core, addr, false); } free (title); } } -static void seek_to_node(RANode *n, RCore *core) { - ut64 off = r_anal_get_bbaddr (core->anal, core->offset); +static void seek_to_node(RzANode *n, RzCore *core) { + ut64 off = rz_anal_get_bbaddr (core->anal, core->offset); char *title = get_title (off); if (title && strcmp (title, n->title)) { - char *cmd = r_str_newf ("s %s", n->title); + char *cmd = rz_str_newf ("s %s", n->title); if (cmd) { if (*cmd) { - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } free (cmd); } @@ -3962,114 +3962,114 @@ static void seek_to_node(RANode *n, RCore *core) { free (title); } -static void graph_single_step_in(RCore *core, RAGraph *g) { - if (r_config_get_i (core->config, "cfg.debug")) { +static void graph_single_step_in(RzCore *core, RzAGraph *g) { + if (rz_config_get_i (core->config, "cfg.debug")) { if (core->print->cur_enabled) { // dcu 0xaddr - r_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); core->print->cur_enabled = 0; } else { - r_core_cmd (core, "ds", 0); - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, "ds", 0); + rz_core_cmd (core, ".dr*", 0); } } else { - r_core_cmd (core, "aes", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aes", 0); + rz_core_cmd (core, ".ar*", 0); } g->is_instep = true; g->need_reload_nodes = true; } -static void graph_single_step_over(RCore *core, RAGraph *g) { - if (r_config_get_i (core->config, "cfg.debug")) { +static void graph_single_step_over(RzCore *core, RzAGraph *g) { + if (rz_config_get_i (core->config, "cfg.debug")) { if (core->print->cur_enabled) { - r_core_cmd (core, "dcr", 0); + rz_core_cmd (core, "dcr", 0); core->print->cur_enabled = 0; } else { - r_core_cmd (core, "dso", 0); - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, "dso", 0); + rz_core_cmd (core, ".dr*", 0); } } else { - r_core_cmd (core, "aeso", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aeso", 0); + rz_core_cmd (core, ".ar*", 0); } g->is_instep = true; g->need_reload_nodes = true; } -static void graph_breakpoint(RCore *core) { - r_core_cmd (core, "dbs $$", 0); +static void graph_breakpoint(RzCore *core) { + rz_core_cmd (core, "dbs $$", 0); } -static void graph_continue(RCore *core) { - r_core_cmd (core, "dc", 0); +static void graph_continue(RzCore *core) { + rz_core_cmd (core, "dc", 0); } -static void applyDisMode(RCore *core) { +static void applyDisMode(RzCore *core) { switch (disMode) { case 0: - r_config_set (core->config, "asm.pseudo", "false"); - r_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "asm.pseudo", "false"); + rz_config_set (core->config, "asm.esil", "false"); break; case 1: - r_config_set (core->config, "asm.pseudo", "true"); - r_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "asm.pseudo", "true"); + rz_config_set (core->config, "asm.esil", "false"); break; case 2: - r_config_set (core->config, "asm.pseudo", "false"); - r_config_set (core->config, "asm.esil", "true"); + rz_config_set (core->config, "asm.pseudo", "false"); + rz_config_set (core->config, "asm.esil", "true"); break; } } -static void rotateColor(RCore *core) { - int color = r_config_get_i (core->config, "scr.color"); +static void rotateColor(RzCore *core) { + int color = rz_config_get_i (core->config, "scr.color"); if (++color > 2) { color = 0; } - r_config_set_i (core->config, "scr.color", color); + rz_config_set_i (core->config, "scr.color", color); } // dupe in visual.c -static bool toggle_bb(RCore *core, ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); +static bool toggle_bb(RzCore *core, ut64 addr) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, addr); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, fcn, addr); if (bb) { bb->folded = !bb->folded; } else { - r_warn_if_reached (); + rz_warn_if_reached (); } return true; } return false; } -static char *get_graph_string(RCore *core, RAGraph *g) { - int c = r_config_get_i (core->config, "scr.color"); - int u = r_config_get_i (core->config, "scr.utf8"); - r_config_set_i (core->config, "scr.color", 0); - r_config_set_i (core->config, "scr.utf8", 0); - r_core_visual_graph (core, g, NULL, false); - char *s = strdup (r_cons_get_buffer ()); - r_cons_reset (); - r_config_set_i (core->config, "scr.color", c); - r_config_set_i (core->config, "scr.utf8", u); +static char *get_graph_string(RzCore *core, RzAGraph *g) { + int c = rz_config_get_i (core->config, "scr.color"); + int u = rz_config_get_i (core->config, "scr.utf8"); + rz_config_set_i (core->config, "scr.color", 0); + rz_config_set_i (core->config, "scr.utf8", 0); + rz_core_visual_graph (core, g, NULL, false); + char *s = strdup (rz_cons_get_buffer ()); + rz_cons_reset (); + rz_config_set_i (core->config, "scr.color", c); + rz_config_set_i (core->config, "scr.utf8", u); return s; } -static void nextword(RCore *core, RAGraph *g, const char *word) { - r_return_if_fail (core && core->graph && g && g->can && word); +static void nextword(RzCore *core, RzAGraph *g, const char *word) { + rz_return_if_fail (core && core->graph && g && g->can && word); if (R_STR_ISEMPTY (word)) { return; } - RAGraphHits *gh = &g->ghits; - RConsCanvas *can = g->can; + RzAGraphHits *gh = &g->ghits; + RzConsCanvas *can = g->can; if (gh->word_list.len && gh->old_word && !strcmp (word, gh->old_word)) { if (gh->word_nth >= gh->word_list.len) { gh->word_nth = 0; } - struct r_agraph_location *pos = r_vector_index_ptr (&gh->word_list, gh->word_nth); + struct rz_agraph_location *pos = rz_vector_index_ptr (&gh->word_list, gh->word_nth); gh->word_nth++; if (pos) { can->sx = -pos->x + can->w / 2; @@ -4077,21 +4077,21 @@ static void nextword(RCore *core, RAGraph *g, const char *word) { } return; } else { - r_vector_clear (&gh->word_list); + rz_vector_clear (&gh->word_list); } char *s = get_graph_string (core, g); - r_cons_clear00 (); - r_cons_flush (); + rz_cons_clear00 (); + rz_cons_flush (); const size_t MAX_COUNT = 4096; const char *a = NULL; size_t count = 0; int x = 0, y = 0; for (count = 0; count < MAX_COUNT; count++) { - a = r_str_str_xy (s, word, a, &x, &y); + a = rz_str_str_xy (s, word, a, &x, &y); if (!a) { break; } - struct r_agraph_location *pos = r_vector_push (&gh->word_list, NULL); + struct rz_agraph_location *pos = rz_vector_push (&gh->word_list, NULL); if (pos) { pos->x = x + g->x; pos->y = y + g->y; @@ -4106,79 +4106,79 @@ static void nextword(RCore *core, RAGraph *g, const char *word) { nextword (core, g, word); } -R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int is_interactive) { +RZ_API int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalFunction *_fcn, int is_interactive) { int o_asmqjmps_letter = core->is_asmqjmps_letter; - int o_scrinteractive = r_cons_is_interactive (); + int o_scrinteractive = rz_cons_is_interactive (); int o_vmode = core->vmode; int exit_graph = false, is_error = false; int update_seek = false; struct agraph_refresh_data *grd; int okey, key; - RAnalFunction *fcn = NULL; + RzAnalFunction *fcn = NULL; const char *key_s; - RConsCanvas *can, *o_can = NULL; + RzConsCanvas *can, *o_can = NULL; bool graph_allocated = false; int movspeed; int ret, invscroll; - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { return false; } - r_config_hold_i (hc, "asm.pseudo", "asm.esil", "asm.cmt.right", NULL); + rz_config_hold_i (hc, "asm.pseudo", "asm.esil", "asm.cmt.right", NULL); - int h, w = r_cons_get_size (&h); - can = r_cons_canvas_new (w, h); + int h, w = rz_cons_get_size (&h); + can = rz_cons_canvas_new (w, h); if (!can) { w = 80; h = 25; - can = r_cons_canvas_new (w, h); + can = rz_cons_canvas_new (w, h); if (!can) { - eprintf ("Cannot create RCons.canvas context. Invalid screen " + eprintf ("Cannot create RzCons.canvas context. Invalid screen " "size? See scr.columns + scr.rows\n"); - r_config_hold_free (hc); + rz_config_hold_free (hc); return false; } } - can->linemode = r_config_get_i (core->config, "graph.linemode"); - can->color = r_config_get_i (core->config, "scr.color"); + can->linemode = rz_config_get_i (core->config, "graph.linemode"); + can->color = rz_config_get_i (core->config, "scr.color"); if (!g) { graph_allocated = true; - fcn = _fcn? _fcn: r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = _fcn? _fcn: rz_anal_get_fcn_in (core->anal, core->offset, 0); if (!fcn) { - r_config_hold_restore (hc); - r_config_hold_free (hc); - r_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); + rz_cons_canvas_free (can); return false; } - g = r_agraph_new (can); + g = rz_agraph_new (can); if (!g) { - r_cons_canvas_free (can); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return false; } g->is_tiny = is_interactive == 2; - g->layout = r_config_get_i (core->config, "graph.layout"); - g->dummy = r_config_get_i (core->config, "graph.dummy"); - g->show_node_titles = r_config_get_i (core->config, "graph.ntitles"); + g->layout = rz_config_get_i (core->config, "graph.layout"); + g->dummy = rz_config_get_i (core->config, "graph.dummy"); + g->show_node_titles = rz_config_get_i (core->config, "graph.ntitles"); } else { o_can = g->can; } - r_config_set_i (core->config, "scr.interactive", false); + rz_config_set_i (core->config, "scr.interactive", false); g->can = can; - g->movspeed = r_config_get_i (core->config, "graph.scroll"); - g->show_node_titles = r_config_get_i (core->config, "graph.ntitles"); - g->show_node_body = r_config_get_i (core->config, "graph.body"); - g->show_node_bubble = r_config_get_i (core->config, "graph.bubble"); - g->on_curnode_change = (RANodeCallback) seek_to_node; + g->movspeed = rz_config_get_i (core->config, "graph.scroll"); + g->show_node_titles = rz_config_get_i (core->config, "graph.ntitles"); + g->show_node_body = rz_config_get_i (core->config, "graph.body"); + g->show_node_bubble = rz_config_get_i (core->config, "graph.bubble"); + g->on_curnode_change = (RzANodeCallback) seek_to_node; g->on_curnode_change_data = core; - g->edgemode = r_config_get_i (core->config, "graph.edges"); - g->hints = r_config_get_i (core->config, "graph.hints"); + g->edgemode = rz_config_get_i (core->config, "graph.edges"); + g->hints = rz_config_get_i (core->config, "graph.hints"); g->is_interactive = is_interactive; - bool asm_comments = r_config_get_i (core->config, "asm.comments"); - r_config_set (core->config, "asm.comments", - r_str_bool (r_config_get_i (core->config, "graph.comments"))); + bool asm_comments = rz_config_get_i (core->config, "asm.comments"); + rz_config_set (core->config, "asm.comments", + rz_str_bool (rz_config_get_i (core->config, "graph.comments"))); /* we want letters as shortcuts for call/jmps */ core->is_asmqjmps_letter = true; @@ -4186,10 +4186,10 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int grd = R_NEW0 (struct agraph_refresh_data); if (!grd) { - r_cons_canvas_free (can); - r_config_hold_restore (hc); - r_config_hold_free (hc); - r_agraph_free (g); + rz_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); + rz_agraph_free (g); return false; } grd->g = g; @@ -4199,20 +4199,20 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int grd->fcn = fcn != NULL? &fcn: NULL; ret = agraph_refresh (grd); if (!ret || is_interactive != 1) { - r_cons_newline (); + rz_cons_newline (); exit_graph = true; is_error = !ret; } core->cons->event_resize = NULL; // avoid running old event with new data core->cons->event_data = grd; - core->cons->event_resize = (RConsEvent) agraph_refresh_oneshot; + core->cons->event_resize = (RzConsEvent) agraph_refresh_oneshot; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); - while (!exit_graph && !is_error && !r_cons_is_breaked ()) { - w = r_cons_get_size (&h); - invscroll = r_config_get_i (core->config, "graph.invscroll"); + while (!exit_graph && !is_error && !rz_cons_is_breaked ()) { + w = rz_cons_get_size (&h); + invscroll = rz_config_get_i (core->config, "graph.invscroll"); ret = agraph_refresh (grd); if (!ret) { @@ -4221,12 +4221,12 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int } showcursor (core, false); - // r_core_graph_inputhandle() - okey = r_cons_readchar (); - key = r_cons_arrow_to_hjkl (okey); + // rz_core_graph_inputhandle() + okey = rz_cons_readchar (); + key = rz_cons_arrow_to_hjkl (okey); if (core->cons->mouse_event) { - movspeed = r_config_get_i (core->config, "scr.wheel.speed"); + movspeed = rz_config_get_i (core->config, "scr.wheel.speed"); switch (key) { case 'j': case 'k': @@ -4258,31 +4258,31 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; // Those hardcoded keys are useful only for aegi, should add subcommand of ag to set key actions case '1': - r_core_cmd0 (core, "so;.aeg*"); + rz_core_cmd0 (core, "so;.aeg*"); break; case '2': - r_core_cmd0 (core, "so-1;.aeg*"); + rz_core_cmd0 (core, "so-1;.aeg*"); break; case '=': { // TODO: edit showcursor (core, true); - const char *cmd = r_config_get (core->config, "cmd.gprompt"); - r_line_set_prompt ("cmd.gprompt> "); + const char *cmd = rz_config_get (core->config, "cmd.gprompt"); + rz_line_set_prompt ("cmd.gprompt> "); core->cons->line->contents = strdup (cmd); - const char *buf = r_line_readline (); + const char *buf = rz_line_readline (); core->cons->line->contents = NULL; - r_config_set (core->config, "cmd.gprompt", buf); + rz_config_set (core->config, "cmd.gprompt", buf); showcursor (core, false); } break; case '|': { - int e = r_config_get_i (core->config, "graph.layout"); + int e = rz_config_get_i (core->config, "graph.layout"); if (++e > 1) { e = 0; } - r_config_set_i (core->config, "graph.layout", e); - g->layout = r_config_get_i (core->config, "graph.layout"); + rz_config_set_i (core->config, "graph.layout", e); + g->layout = rz_config_get_i (core->config, "graph.layout"); g->need_update_dim = true; g->need_set_layout = true; } @@ -4291,31 +4291,31 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case 'e': { - int e = r_config_get_i (core->config, "graph.edges"); + int e = rz_config_get_i (core->config, "graph.edges"); e++; if (e > 2) { e = 0; } - r_config_set_i (core->config, "graph.edges", e); + rz_config_set_i (core->config, "graph.edges", e); g->edgemode = e; g->need_update_dim = true; get_bbupdate (g, core, fcn); } break; case '\\': - nextword (core, g, r_config_get (core->config, "scr.highlight")); + nextword (core, g, rz_config_get (core->config, "scr.highlight")); break; case 'b': - r_core_visual_browse (core, ""); + rz_core_visual_browse (core, ""); break; case 'E': { - int e = r_config_get_i (core->config, "graph.linemode"); + int e = rz_config_get_i (core->config, "graph.linemode"); e--; if (e < 0) { e = 1; } - r_config_set_i (core->config, "graph.linemode", e); + rz_config_set_i (core->config, "graph.linemode", e); g->can->linemode = e; get_bbupdate (g, core, fcn); } @@ -4326,18 +4326,18 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int exit_graph = true; break; case '>': - if (fcn && r_cons_yesno ('y', "Compute function callgraph? (Y/n)")) { - r_core_cmd0 (core, "ag-;.agc* @$FB;.axfg @$FB;aggi"); + if (fcn && rz_cons_yesno ('y', "Compute function callgraph? (Y/n)")) { + rz_core_cmd0 (core, "ag-;.agc* @$FB;.axfg @$FB;aggi"); } break; case '<': - // r_core_visual_refs (core, true, false); + // rz_core_visual_refs (core, true, false); if (fcn) { - r_core_cmd0 (core, "ag-;.axtg $FB;aggi"); + rz_core_cmd0 (core, "ag-;.axtg $FB;aggi"); } break; case 'G': - r_core_cmd0 (core, "ag-;.dtg*;aggi"); + rz_core_cmd0 (core, "ag-;.dtg*;aggi"); break; case 'V': if (fcn) { @@ -4348,9 +4348,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int if (okey == 27) { // shift-tab agraph_prev_node (g); } else { - RANode *n = get_anode (g->curnode); + RzANode *n = get_anode (g->curnode); if (n) { - ut64 addr = r_num_get (NULL, n->title); + ut64 addr = rz_num_get (NULL, n->title); toggle_bb (core, addr); g->need_reload_nodes = true; } @@ -4360,9 +4360,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int if (!fcn) { break; } - key_s = r_config_get (core->config, "key.s"); + key_s = rz_config_get (core->config, "key.s"); if (key_s && *key_s) { - r_core_cmd0 (core, key_s); + rz_core_cmd0 (core, key_s); } else { graph_single_step_in (core, g); } @@ -4381,11 +4381,11 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; } ut64 old_off = core->offset; - ut64 off = r_anal_get_bbaddr (core->anal, core->offset); - r_core_seek (core, off, false); - if ((key == 'x' && !r_core_visual_refs (core, true, true)) || - (key == 'X' && !r_core_visual_refs (core, false, true))) { - r_core_seek (core, old_off, false); + ut64 off = rz_anal_get_bbaddr (core->anal, core->offset); + rz_core_seek (core, off, false); + if ((key == 'x' && !rz_core_visual_refs (core, true, true)) || + (key == 'X' && !rz_core_visual_refs (core, false, true))) { + rz_core_seek (core, old_off, false); } break; } @@ -4394,8 +4394,8 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int discroll = 0; break; case '?': - r_cons_clear00 (); - r_cons_printf ("Visual Ascii Art graph keybindings:\n" + rz_cons_clear00 (); + rz_cons_printf ("Visual Ascii Art graph keybindings:\n" " :e cmd.gprompt = agft - show tinygraph in one side\n" " +/-/0 - zoom in/out/default\n" " ; - add comment in current basic block\n" @@ -4449,11 +4449,11 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int " Y - toggle tiny graph\n" " z - toggle node folding\n" " Z - toggle basic block folding"); - r_cons_less (); - r_cons_any_key (NULL); + rz_cons_less (); + rz_cons_any_key (NULL); break; case '"': - r_config_toggle (core->config, "graph.refs"); + rz_config_toggle (core->config, "graph.refs"); break; case '#': if (g->mode == R_AGRAPH_MODE_COMMENTS) { @@ -4464,7 +4464,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int g->need_reload_nodes = true; discroll = 0; agraph_update_seek (g, get_anode (g->curnode), true); - // r_config_toggle (core->config, "graph.hints"); + // rz_config_toggle (core->config, "graph.hints"); break; case 'p': g->mode = next_mode (g->mode); @@ -4501,13 +4501,13 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int if (!fcn) { break; } - RIOUndos *undo = r_io_sundo (core->io, core->offset); + RzIOUndos *undo = rz_io_sundo (core->io, core->offset); if (undo) { - r_core_seek (core, undo->off, false); + rz_core_seek (core, undo->off, false); } else { eprintf ("Cannot undo\n"); } - if (r_config_get_i (core->config, "graph.few")) { + if (rz_config_get_i (core->config, "graph.few")) { g->need_reload_nodes = true; } break; @@ -4517,9 +4517,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int if (!fcn) { break; } - RIOUndos *undo = r_io_sundo_redo (core->io); + RzIOUndos *undo = rz_io_sundo_redo (core->io); if (undo) { - r_core_seek (core, undo->off, false); + rz_core_seek (core, undo->off, false); } else { eprintf ("Cannot redo\n"); } @@ -4527,44 +4527,44 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int } case 'r': if (fcn) { - g->layout = r_config_get_i (core->config, "graph.layout"); + g->layout = rz_config_get_i (core->config, "graph.layout"); g->need_reload_nodes = true; } // TODO: toggle shortcut hotkeys - if (r_config_get_i (core->config, "asm.hint.call")) { - r_core_cmd0 (core, "e!asm.hint.call"); - r_core_cmd0 (core, "e!asm.hint.jmp"); - } else if (r_config_get_i (core->config, "asm.hint.jmp")) { - r_core_cmd0 (core, "e!asm.hint.jmp"); - r_core_cmd0 (core, "e!asm.hint.lea"); - } else if (r_config_get_i (core->config, "asm.hint.lea")) { - r_core_cmd0 (core, "e!asm.hint.lea"); - r_core_cmd0 (core, "e!asm.hint.call"); + if (rz_config_get_i (core->config, "asm.hint.call")) { + rz_core_cmd0 (core, "e!asm.hint.call"); + rz_core_cmd0 (core, "e!asm.hint.jmp"); + } else if (rz_config_get_i (core->config, "asm.hint.jmp")) { + rz_core_cmd0 (core, "e!asm.hint.jmp"); + rz_core_cmd0 (core, "e!asm.hint.lea"); + } else if (rz_config_get_i (core->config, "asm.hint.lea")) { + rz_core_cmd0 (core, "e!asm.hint.lea"); + rz_core_cmd0 (core, "e!asm.hint.call"); } break; case '$': - r_core_cmd (core, "dr PC=$$", 0); - r_core_cmd (core, "sr PC", 0); + rz_core_cmd (core, "dr PC=$$", 0); + rz_core_cmd (core, "sr PC", 0); g->need_reload_nodes = true; break; case 'R': - if (r_config_get_i (core->config, "scr.randpal")) { - r_core_cmd0 (core, "ecr"); + if (rz_config_get_i (core->config, "scr.randpal")) { + rz_core_cmd0 (core, "ecr"); } else { - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); } if (!fcn) { break; } - g->edgemode = r_config_get_i (core->config, "graph.edges"); + g->edgemode = rz_config_get_i (core->config, "graph.edges"); get_bbupdate (g, core, fcn); break; case '!': - r_core_visual_panels_root (core, core->panels_root); + rz_core_visual_panels_root (core, core->panels_root); break; case '\'': if (fcn) { - r_config_toggle (core->config, "graph.comments"); + rz_config_toggle (core->config, "graph.comments"); g->need_reload_nodes = true; } break; @@ -4572,9 +4572,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int if (fcn) { showcursor (core, true); char buf[256]; - r_line_set_prompt ("[comment]> "); - if (r_cons_fgets (buf, sizeof (buf), 0, NULL) > 0) { - r_core_cmdf (core, "\"CC %s\"", buf); + rz_line_set_prompt ("[comment]> "); + if (rz_cons_fgets (buf, sizeof (buf), 0, NULL) > 0) { + rz_core_cmdf (core, "\"CC %s\"", buf); } g->need_reload_nodes = true; showcursor (core, false); @@ -4597,7 +4597,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case '(': if (fcn) { - r_core_cmd0 (core, "wao recj@B:-1"); + rz_core_cmd0 (core, "wao recj@B:-1"); g->need_reload_nodes = true; } break; @@ -4611,8 +4611,8 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int { showcursor (core, true); // WTF? - r_config_set_i (core->config, "scr.interactive", true); - r_core_visual_define (core, "", 0); + rz_config_set_i (core->config, "scr.interactive", true); + rz_core_visual_define (core, "", 0); get_bbupdate (g, core, fcn); showcursor (core, false); } @@ -4621,10 +4621,10 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int g->is_dis = !g->is_dis; break; case 'n': - r_core_seek_next (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_next (core, rz_config_get (core->config, "scr.nkey")); break; case 'N': - r_core_seek_previous (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_previous (core, rz_config_get (core->config, "scr.nkey")); break; case 'Y': agraph_toggle_tiny (g); @@ -4636,7 +4636,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int agraph_update_seek (g, get_anode (g->curnode), true); break; case 'v': - r_core_visual_anal (core, NULL); + rz_core_visual_anal (core, NULL); break; case 'J': // copypaste from 'j' @@ -4682,7 +4682,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case 'j': if (g->is_dis) { - r_core_cmd0 (core, "so 1"); + rz_core_cmd0 (core, "so 1"); } else { if (graphCursor) { int speed = (okey == 27)? PAGEKEY_SPEED: movspeed; @@ -4695,7 +4695,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case 'k': if (g->is_dis) { - r_core_cmd0 (core, "so -1"); + rz_core_cmd0 (core, "so -1"); } else { if (graphCursor) { int speed = (okey == 27)? PAGEKEY_SPEED: movspeed; @@ -4724,15 +4724,15 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case '^': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - r_core_seek (core, fcn->addr, false); + rz_core_seek (core, fcn->addr, false); } } agraph_update_seek (g, get_anode (g->curnode), true); break; case ',': - r_config_toggle (core->config, "graph.few"); + rz_config_toggle (core->config, "graph.few"); g->need_reload_nodes = true; agraph_update_seek (g, get_anode (g->curnode), true); break; @@ -4742,19 +4742,19 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case 'i': agraph_follow_innodes (g, true); - if (r_config_get_i (core->config, "graph.few")) { + if (rz_config_get_i (core->config, "graph.few")) { g->need_reload_nodes = true; } break; case 'I': agraph_follow_innodes (g, false); - if (r_config_get_i (core->config, "graph.few")) { + if (rz_config_get_i (core->config, "graph.few")) { g->need_reload_nodes = true; } break; case 't': agraph_follow_true (g); - if (r_config_get_i (core->config, "graph.few")) { + if (rz_config_get_i (core->config, "graph.few")) { g->need_reload_nodes = true; } break; @@ -4763,7 +4763,7 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; case 'f': agraph_follow_false (g); - if (r_config_get_i (core->config, "graph.few")) { + if (rz_config_get_i (core->config, "graph.few")) { g->need_reload_nodes = true; } break; @@ -4774,18 +4774,18 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int g->update_seek_on = get_anode (gn); } else { // agraph_merge_child (g, 1); - r_core_visual_trackflags (core); + rz_core_visual_trackflags (core); } break; case '/': showcursor (core, true); - r_config_set_i (core->config, "scr.interactive", true); - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); - r_config_set_i (core->config, "scr.interactive", false); + rz_config_set_i (core->config, "scr.interactive", true); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_config_set_i (core->config, "scr.interactive", false); showcursor (core, false); break; case ':': - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); if (!g) { g->need_reload_nodes = true; // maybe too slow and unnecessary sometimes? better be safe and reload get_bbupdate (g, core, fcn); @@ -4795,86 +4795,86 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int agraph_toggle_speed (g, core); break; case '_': - r_core_visual_hudstuff (core); + rz_core_visual_hudstuff (core); break; case R_CONS_KEY_F1: - cmd = r_config_get (core->config, "key.f1"); + cmd = rz_config_get (core->config, "key.f1"); if (cmd && *cmd) { - (void) r_core_cmd0 (core, cmd); + (void) rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F2: - cmd = r_config_get (core->config, "key.f2"); + cmd = rz_config_get (core->config, "key.f2"); if (cmd && *cmd) { - (void) r_core_cmd0 (core, cmd); + (void) rz_core_cmd0 (core, cmd); } else { graph_breakpoint (core); } break; case R_CONS_KEY_F3: - cmd = r_config_get (core->config, "key.f3"); + cmd = rz_config_get (core->config, "key.f3"); if (cmd && *cmd) { - (void) r_core_cmd0 (core, cmd); + (void) rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F4: - cmd = r_config_get (core->config, "key.f4"); + cmd = rz_config_get (core->config, "key.f4"); if (cmd && *cmd) { - (void) r_core_cmd0 (core, cmd); + (void) rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F5: - cmd = r_config_get (core->config, "key.f5"); + cmd = rz_config_get (core->config, "key.f5"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F6: - cmd = r_config_get (core->config, "key.f6"); + cmd = rz_config_get (core->config, "key.f6"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F7: - cmd = r_config_get (core->config, "key.f7"); + cmd = rz_config_get (core->config, "key.f7"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { graph_single_step_in (core, g); } break; case R_CONS_KEY_F8: - cmd = r_config_get (core->config, "key.f8"); + cmd = rz_config_get (core->config, "key.f8"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { graph_single_step_over (core, g); } break; case R_CONS_KEY_F9: - cmd = r_config_get (core->config, "key.f9"); + cmd = rz_config_get (core->config, "key.f9"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { graph_continue (core); } break; case R_CONS_KEY_F10: - cmd = r_config_get (core->config, "key.f10"); + cmd = rz_config_get (core->config, "key.f10"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F11: - cmd = r_config_get (core->config, "key.f11"); + cmd = rz_config_get (core->config, "key.f11"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F12: - cmd = r_config_get (core->config, "key.f12"); + cmd = rz_config_get (core->config, "key.f12"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case -1: // EOF @@ -4888,8 +4888,8 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int } break; case 27: // ESC - if (r_cons_readchar () == 91) { - if (r_cons_readchar () == 90) { + if (rz_cons_readchar () == 91) { + if (rz_cons_readchar () == 90) { agraph_prev_node (g); } } @@ -4898,9 +4898,9 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int break; } } - r_vector_fini (&g->ghits.word_list); - r_cons_break_pop (); - r_config_set (core->config, "asm.comments", r_str_bool (asm_comments)); + rz_vector_fini (&g->ghits.word_list); + rz_cons_break_pop (); + rz_config_set (core->config, "asm.comments", rz_str_bool (asm_comments)); core->cons->event_resize = NULL; core->cons->event_data = NULL; core->vmode = o_vmode; @@ -4909,13 +4909,13 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int free (grd); if (graph_allocated) { - r_agraph_free (g); - r_config_set_i (core->config, "scr.interactive", o_scrinteractive); + rz_agraph_free (g); + rz_config_set_i (core->config, "scr.interactive", o_scrinteractive); } else { g->can = o_can; } - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); if (update_seek) { return -1; } @@ -4923,31 +4923,31 @@ R_API int r_core_visual_graph(RCore *core, RAGraph *g, RAnalFunction *_fcn, int } /** - * @brief Create RAGraph from generic RGraph with RGraphNodeInfo as node data + * @brief Create RzAGraph from generic RGraph with RGraphNodeInfo as node data * * @param graph - * @return RAGraph* NULL if failure + * @return RzAGraph* NULL if failure */ -R_API RAGraph *create_agraph_from_graph(const RGraph/**/ *graph) { - r_return_val_if_fail (graph, NULL); +RZ_API RzAGraph *create_agraph_from_graph(const RGraph/**/ *graph) { + rz_return_val_if_fail (graph, NULL); - RAGraph *result_agraph = r_agraph_new (r_cons_canvas_new (1, 1)); + RzAGraph *result_agraph = rz_agraph_new (rz_cons_canvas_new (1, 1)); if (!result_agraph) { return NULL; } // Cache lookup to build edges - HtPP /**/ *hashmap = ht_pp_new0 (); + HtPP /**/ *hashmap = ht_pp_new0 (); if (!hashmap) { - r_agraph_free (result_agraph); + rz_agraph_free (result_agraph); return NULL; } - // List of the new RANodes - RListIter *iter; + // List of the new RzANodes + RzListIter *iter; RGraphNode *node; // Traverse the list, create new ANode for each Node - r_list_foreach (graph->nodes, iter, node) { + rz_list_foreach (graph->nodes, iter, node) { RGraphNodeInfo *info = node->data; - RANode *a_node = r_agraph_add_node (result_agraph, info->title, info->body); + RzANode *a_node = rz_agraph_add_node (result_agraph, info->title, info->body); if (!a_node) { goto failure; } @@ -4955,20 +4955,20 @@ R_API RAGraph *create_agraph_from_graph(const RGraph/**/ *graph) } // Traverse the nodes again, now build up the edges - r_list_foreach (graph->nodes, iter, node) { - RANode *a_node = ht_pp_find (hashmap, node, NULL); + rz_list_foreach (graph->nodes, iter, node) { + RzANode *a_node = ht_pp_find (hashmap, node, NULL); if (!a_node) { goto failure; // shouldn't happen in correct graph state } - RListIter *neighbour_iter; + RzListIter *neighbour_iter; RGraphNode *neighbour; - r_list_foreach (node->in_nodes, neighbour_iter, neighbour) { - RANode *a_neighbour = ht_pp_find (hashmap, neighbour, NULL); + rz_list_foreach (node->in_nodes, neighbour_iter, neighbour) { + RzANode *a_neighbour = ht_pp_find (hashmap, neighbour, NULL); if (!a_neighbour) { goto failure; } - r_agraph_add_edge (result_agraph, a_neighbour, a_node); + rz_agraph_add_edge (result_agraph, a_neighbour, a_node); } } @@ -4976,6 +4976,6 @@ R_API RAGraph *create_agraph_from_graph(const RGraph/**/ *graph) return result_agraph; failure: ht_pp_free (hashmap); - r_agraph_free (result_agraph); + rz_agraph_free (result_agraph); return NULL; } diff --git a/libr/core/anal_objc.c b/librz/core/anal_objc.c similarity index 66% rename from libr/core/anal_objc.c rename to librz/core/anal_objc.c index 3c24e4ece2..edb7bf2f88 100644 --- a/libr/core/anal_objc.c +++ b/librz/core/anal_objc.c @@ -1,23 +1,23 @@ -/* radare2 - LGPL - Copyright 2019-2020 - pancake */ +/* rizin - LGPL - Copyright 2019-2020 - pancake */ /* This code has been written by pancake which has been based on Alvaro's - * r2pipe-python script which was based on FireEye script for IDA Pro. + * rzpipe-python script which was based on FireEye script for IDA Pro. * * https://www.fireeye.com/blog/threat-research/2017/03/introduction_to_reve.html */ -#include +#include typedef struct { - RCore *core; + RzCore *core; HtUP *up; size_t word_size; RBinSection *_selrefs; RBinSection *_msgrefs; RBinSection *_const; RBinSection *_data; -} RCoreObjc; +} RzCoreObjc; const size_t objc2ClassSize = 0x28; @@ -26,25 +26,25 @@ const size_t objc2ClassMethSize = 0x18; const size_t objc2ClassBaseMethsOffs = 0x20; const size_t objc2ClassMethImpOffs = 0x10; -static void array_add(RCoreObjc *o, ut64 va, ut64 xrefs_to) { +static void array_add(RzCoreObjc *o, ut64 va, ut64 xrefs_to) { bool found = false; - RVector *vec = ht_up_find (o->up, va, &found); + RzVector *vec = ht_up_find (o->up, va, &found); if (!found || !vec) { - vec = r_vector_new (sizeof (ut64), NULL, NULL); + vec = rz_vector_new (sizeof (ut64), NULL, NULL); ht_up_insert (o->up, va, vec); } ut64 *addr; - r_vector_foreach (vec, addr) { + rz_vector_foreach (vec, addr) { if (xrefs_to == *addr) { return; } } // extend vector and insert new element - r_vector_push (vec, &xrefs_to); + rz_vector_push (vec, &xrefs_to); } static void kv_array_free(HtUPKv *kv) { - r_vector_free (kv->value); + rz_vector_free (kv->value); } static inline bool isValid(ut64 addr) { @@ -64,31 +64,31 @@ static inline bool inBetween(RBinSection *s, ut64 addr) { return R_BETWEEN (from, addr, to); } -static ut32 readDword(RCoreObjc *objc, ut64 addr, bool *success) { +static ut32 readDword(RzCoreObjc *objc, ut64 addr, bool *success) { ut8 buf[4]; - *success = r_io_read_at (objc->core->io, addr, buf, sizeof (buf)); - return r_read_le32 (buf); + *success = rz_io_read_at (objc->core->io, addr, buf, sizeof (buf)); + return rz_read_le32 (buf); } -static ut64 readQword(RCoreObjc *objc, ut64 addr, bool *success) { +static ut64 readQword(RzCoreObjc *objc, ut64 addr, bool *success) { ut8 buf[8] = {0}; - *success = r_io_read_at (objc->core->io, addr, buf, sizeof (buf)); - return r_read_le64 (buf); + *success = rz_io_read_at (objc->core->io, addr, buf, sizeof (buf)); + return rz_read_le64 (buf); } -static void objc_analyze(RCore *core) { - const char *oldstr = r_print_rowlog (core->print, "Analyzing code to find selref references"); - r_core_cmd0 (core, "aar"); - if (!strcmp ("arm", r_config_get (core->config, "asm.arch"))) { - const bool emu_lazy = r_config_get_i (core->config, "emu.lazy"); - r_config_set_i (core->config, "emu.lazy", true); - r_core_cmd0 (core, "aae"); - r_config_set_i (core->config, "emu.lazy", emu_lazy); +static void objc_analyze(RzCore *core) { + const char *oldstr = rz_print_rowlog (core->print, "Analyzing code to find selref references"); + rz_core_cmd0 (core, "aar"); + if (!strcmp ("arm", rz_config_get (core->config, "asm.arch"))) { + const bool emu_lazy = rz_config_get_i (core->config, "emu.lazy"); + rz_config_set_i (core->config, "emu.lazy", true); + rz_core_cmd0 (core, "aae"); + rz_config_set_i (core->config, "emu.lazy", emu_lazy); } - r_print_rowlog_done (core->print, oldstr); + rz_print_rowlog_done (core->print, oldstr); } -static ut64 getRefPtr(RCoreObjc *o, ut64 classMethodsVA, bool *rfound) { +static ut64 getRefPtr(RzCoreObjc *o, ut64 classMethodsVA, bool *rfound) { *rfound = false; bool readSuccess; @@ -101,13 +101,13 @@ static ut64 getRefPtr(RCoreObjc *o, ut64 classMethodsVA, bool *rfound) { ut64 ref = UT64_MAX; bool isMsgRef = false; - RVector *vec = ht_up_find (o->up, namePtr, rfound); + RzVector *vec = ht_up_find (o->up, namePtr, rfound); if (!*rfound || !vec) { *rfound = false; return false; } ut64 *addr; - r_vector_foreach (vec, addr) { + rz_vector_foreach (vec, addr) { const ut64 at = *addr; if (inBetween (o->_selrefs, at)) { isMsgRef = false; @@ -126,9 +126,9 @@ static ut64 getRefPtr(RCoreObjc *o, ut64 classMethodsVA, bool *rfound) { return isMsgRef? ref - 8: ref; } -static bool objc_build_refs(RCoreObjc *objc) { +static bool objc_build_refs(RzCoreObjc *objc) { ut64 off; - r_return_val_if_fail (objc->_const && objc->_selrefs, false); + rz_return_val_if_fail (objc->_const && objc->_selrefs, false); const ut64 va_const = objc->_const->vaddr; size_t ss_const = objc->_const->vsize; @@ -142,24 +142,24 @@ static bool objc_build_refs(RCoreObjc *objc) { return false; } const size_t word_size = objc->word_size; // assuming 8 because of the read_le64 - if (!r_io_read_at (objc->core->io, objc->_const->vaddr, buf, ss_const)) { + if (!rz_io_read_at (objc->core->io, objc->_const->vaddr, buf, ss_const)) { eprintf ("aao: Cannot read the whole const section %zu\n", ss_const); return false; } for (off = 0; off + word_size < ss_const; off += word_size) { ut64 va = va_const + off; - ut64 xrefs_to = r_read_le64 (buf + off); + ut64 xrefs_to = rz_read_le64 (buf + off); if (isValid (xrefs_to)) { array_add (objc, va, xrefs_to); } } - if (!r_io_read_at (objc->core->io, va_selrefs, buf, ss_selrefs)) { + if (!rz_io_read_at (objc->core->io, va_selrefs, buf, ss_selrefs)) { eprintf ("aao: Cannot read the whole selrefs section\n"); return false; } for (off = 0; off + word_size < ss_selrefs; off += word_size) { ut64 va = va_selrefs + off; - ut64 xrefs_to = r_read_le64 (buf + off); + ut64 xrefs_to = rz_read_le64 (buf + off); if (isValid (xrefs_to)) { array_add (objc, xrefs_to, va); } @@ -168,12 +168,12 @@ static bool objc_build_refs(RCoreObjc *objc) { return true; } -static RCoreObjc *core_objc_new(RCore *core) { - RList *sections = r_bin_get_sections (core->bin); +static RzCoreObjc *core_objc_new(RzCore *core) { + RzList *sections = rz_bin_get_sections (core->bin); if (!sections) { return false; } - RCoreObjc *o = R_NEW0 (RCoreObjc); + RzCoreObjc *o = R_NEW0 (RzCoreObjc); o->core = core; o->word_size = (core->rasm->bits == 64)? 8: 4; if (o->word_size != 8) { @@ -181,8 +181,8 @@ static RCoreObjc *core_objc_new(RCore *core) { } RBinSection *s; - RListIter *iter; - r_list_foreach (sections, iter, s) { + RzListIter *iter; + rz_list_foreach (sections, iter, s) { const char *name = s->name; if (strstr (name, "__objc_data")) { o->_data = s; @@ -203,15 +203,15 @@ static RCoreObjc *core_objc_new(RCore *core) { return o; } -static void core_objc_free(RCoreObjc *o) { +static void core_objc_free(RzCoreObjc *o) { if (o) { ht_up_free (o->up); free (o); } } -static bool objc_find_refs(RCore *core) { - RCoreObjc *objc = core_objc_new (core); +static bool objc_find_refs(RzCore *core) { + RzCoreObjc *objc = core_objc_new (core); if (!objc) { if (core->anal->verbose) { eprintf ("Could not find necessary Objective-C sections...\n"); @@ -223,19 +223,19 @@ static bool objc_find_refs(RCore *core) { core_objc_free (objc); return false; } - const char *oldstr = r_print_rowlog (core->print, "Parsing metadata in ObjC to find hidden xrefs"); - r_print_rowlog_done (core->print, oldstr); + const char *oldstr = rz_print_rowlog (core->print, "Parsing metadata in ObjC to find hidden xrefs"); + rz_print_rowlog_done (core->print, oldstr); ut64 off; size_t total_xrefs = 0; bool readSuccess = true; for (off = 0; off < objc->_data->vsize && readSuccess; off += objc2ClassSize) { - if (!readSuccess || r_cons_is_breaked ()) { + if (!readSuccess || rz_cons_is_breaked ()) { break; } ut64 va = objc->_data->vaddr + off; - // XXX do a single r_io_read_at() and just r_read_le64() here + // XXX do a single rz_io_read_at() and just rz_read_le64() here ut64 classRoVA = readQword (objc, va + objc2ClassInfoOffs, &readSuccess); if (!readSuccess || isInvalid (classRoVA)) { continue; @@ -257,7 +257,7 @@ static bool objc_find_refs(RCore *core) { continue; } for (va = classMethodsVA; va < to; va += objc2ClassMethSize) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } bool found = false; @@ -271,12 +271,12 @@ static bool objc_find_refs(RCore *core) { break; } - RList *list = r_anal_xrefs_get (core->anal, selRefVA); + RzList *list = rz_anal_xrefs_get (core->anal, selRefVA); if (list) { - RListIter *iter; - RAnalRef *ref; - r_list_foreach (list, iter, ref) { - r_anal_xrefs_set (core->anal, ref->addr, funcVA, R_ANAL_REF_TYPE_CODE); + RzListIter *iter; + RzAnalRef *ref; + rz_list_foreach (list, iter, ref) { + rz_anal_xrefs_set (core->anal, ref->addr, funcVA, R_ANAL_REF_TYPE_CODE); total_xrefs++; } } @@ -288,22 +288,22 @@ static bool objc_find_refs(RCore *core) { char rs[128]; snprintf (rs, sizeof (rs), "Found %zu objc xrefs...", total_xrefs); - r_print_rowlog (core->print, rs); + rz_print_rowlog (core->print, rs); size_t total_words = 0; ut64 a; const size_t word_size = objc->word_size; for (a = va_selrefs; a < ss_selrefs; a += word_size) { - r_meta_set (core->anal, R_META_TYPE_DATA, a, word_size, NULL); + rz_meta_set (core->anal, R_META_TYPE_DATA, a, word_size, NULL); total_words++; } snprintf (rs, sizeof (rs), "Found %zu objc xrefs in %zu dwords.", total_xrefs, total_words); - r_print_rowlog_done (core->print, rs); + rz_print_rowlog_done (core->print, rs); core_objc_free (objc); return true; } -R_API bool cmd_anal_objc(RCore *core, const char *input, bool auto_anal) { - r_return_val_if_fail (core && input, 0); +RZ_API bool cmd_anal_objc(RzCore *core, const char *input, bool auto_anal) { + rz_return_val_if_fail (core && input, 0); if (!auto_anal) { objc_analyze (core); } diff --git a/libr/core/anal_tp.c b/librz/core/anal_tp.c similarity index 64% rename from libr/core/anal_tp.c rename to librz/core/anal_tp.c index 9a4eb308e7..0c9cda7dbc 100644 --- a/libr/core/anal_tp.c +++ b/librz/core/anal_tp.c @@ -1,28 +1,28 @@ /* radare - LGPL - Copyright 2016-2020 - oddcoder, sivaramaaa */ /* type matching - type propagation */ -#include -#include -#include +#include +#include +#include #define LOOP_MAX 10 -static bool anal_emul_init(RCore *core, RConfigHold *hc, RDebugTrace **dt, RAnalEsilTrace **et) { +static bool anal_emul_init(RzCore *core, RConfigHold *hc, RzDebugTrace **dt, RzAnalEsilTrace **et) { if (!core->anal->esil) { return false; } *dt = core->dbg->trace; *et = core->anal->esil->trace; - core->dbg->trace = r_debug_trace_new (); - core->anal->esil->trace = r_anal_esil_trace_new (core->anal->esil); - r_config_hold_i (hc, "esil.romem", "dbg.trace", + core->dbg->trace = rz_debug_trace_new (); + core->anal->esil->trace = rz_anal_esil_trace_new (core->anal->esil); + rz_config_hold_i (hc, "esil.romem", "dbg.trace", "esil.nonull", "dbg.follow", NULL); - r_config_set (core->config, "esil.romem", "true"); - r_config_set (core->config, "dbg.trace", "true"); - r_config_set (core->config, "esil.nonull", "true"); - r_config_set_i (core->config, "dbg.follow", false); - const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP); - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - if ((bp && !r_reg_getv (core->anal->reg, bp)) && (sp && !r_reg_getv (core->anal->reg, sp))) { + rz_config_set (core->config, "esil.romem", "true"); + rz_config_set (core->config, "dbg.trace", "true"); + rz_config_set (core->config, "esil.nonull", "true"); + rz_config_set_i (core->config, "dbg.follow", false); + const char *bp = rz_reg_get_name (core->anal->reg, R_REG_NAME_BP); + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + if ((bp && !rz_reg_getv (core->anal->reg, bp)) && (sp && !rz_reg_getv (core->anal->reg, sp))) { eprintf ("Stack isn't initialized.\n"); eprintf ("Try running aei and aeim commands before aft for default stack initialization\n"); return false; @@ -30,36 +30,36 @@ static bool anal_emul_init(RCore *core, RConfigHold *hc, RDebugTrace **dt, RAnal return (core->dbg->trace && core->anal->esil->trace); } -static void anal_emul_restore(RCore *core, RConfigHold *hc, RDebugTrace *dt, RAnalEsilTrace *et) { - r_config_hold_restore (hc); - r_config_hold_free (hc); - r_debug_trace_free (core->dbg->trace); - r_anal_esil_trace_free (core->anal->esil->trace); +static void anal_emul_restore(RzCore *core, RConfigHold *hc, RzDebugTrace *dt, RzAnalEsilTrace *et) { + rz_config_hold_restore (hc); + rz_config_hold_free (hc); + rz_debug_trace_free (core->dbg->trace); + rz_anal_esil_trace_free (core->anal->esil->trace); core->anal->esil->trace = et; core->dbg->trace = dt; } #define SDB_CONTAINS(i,s) sdb_array_contains (trace, sdb_fmt ("%d.reg.write", i), s, 0) -static bool type_pos_hit(RAnal *anal, Sdb *trace, bool in_stack, int idx, int size, const char *place) { +static bool type_pos_hit(RzAnal *anal, Sdb *trace, bool in_stack, int idx, int size, const char *place) { if (in_stack) { - const char *sp_name = r_reg_get_name (anal->reg, R_REG_NAME_SP); - ut64 sp = r_reg_getv (anal->reg, sp_name); + const char *sp_name = rz_reg_get_name (anal->reg, R_REG_NAME_SP); + ut64 sp = rz_reg_getv (anal->reg, sp_name); ut64 write_addr = sdb_num_get (trace, sdb_fmt ("%d.mem.write", idx), 0); return (write_addr == sp + size); } return SDB_CONTAINS (idx, place); } -static void __var_rename(RAnal *anal, RAnalVar *v, const char *name, ut64 addr) { +static void __var_rename(RzAnal *anal, RzAnalVar *v, const char *name, ut64 addr) { if (!name || !v) { return; } if (!*name || !strcmp (name , "...")) { return; } - bool is_default = (r_str_startswith (v->name, VARPREFIX) - || r_str_startswith (v->name, ARGPREFIX)); + bool is_default = (rz_str_startswith (v->name, VARPREFIX) + || rz_str_startswith (v->name, ARGPREFIX)); if (*name == '*') { name++; } @@ -67,17 +67,17 @@ static void __var_rename(RAnal *anal, RAnalVar *v, const char *name, ut64 addr) if (!is_default && (strlen (v->name) > strlen (name))) { return; } - RAnalFunction *fcn = r_anal_get_fcn_in (anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, addr, 0); if (!fcn) { return; } - r_anal_var_rename (v, name, false); + rz_anal_var_rename (v, name, false); } -static void __var_retype(RAnal *anal, RAnalVar *var, const char *vname, const char *type, bool ref, bool pfx) { - r_return_if_fail (anal && var && type); +static void __var_retype(RzAnal *anal, RzAnalVar *var, const char *vname, const char *type, bool ref, bool pfx) { + rz_return_if_fail (anal && var && type); // XXX types should be passed without spaces to trim - type = r_str_trim_head_ro (type); + type = rz_str_trim_head_ro (type); // default type if none is provided if (!*type) { type = "int"; @@ -103,63 +103,63 @@ static void __var_retype(RAnal *anal, RAnalVar *var, const char *vname, const ch // except for "void *", since "void *" => "char *" is possible return; } - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); if (pfx) { if (is_default && strncmp (var->type, "signed", 6)) { - r_strbuf_setf (sb, "%s %s", type, tmp); + rz_strbuf_setf (sb, "%s %s", type, tmp); } else { - r_strbuf_free (sb); + rz_strbuf_free (sb); return; } } else { - r_strbuf_set (sb, type); + rz_strbuf_set (sb, type); } - if (!strncmp (r_strbuf_get (sb), "const ", 6)) { + if (!strncmp (rz_strbuf_get (sb), "const ", 6)) { // Dropping const from type //TODO: Inferring const type - r_strbuf_setf (sb, "%s", type + 6); + rz_strbuf_setf (sb, "%s", type + 6); } if (is_ptr) { //type *ptr => type * - r_strbuf_append (sb, " *"); + rz_strbuf_append (sb, " *"); } if (ref) { - if (r_str_endswith (r_strbuf_get (sb), "*")) { // type * => type ** - r_strbuf_append (sb, "*"); + if (rz_str_endswith (rz_strbuf_get (sb), "*")) { // type * => type ** + rz_strbuf_append (sb, "*"); } else { // type => type * - r_strbuf_append (sb, " *"); + rz_strbuf_append (sb, " *"); } } - char* tmp1 = r_strbuf_get (sb); - if (r_str_startswith (tmp1, "unsigned long long")) { - r_strbuf_set (sb, "uint64_t"); - } else if (r_str_startswith (tmp1, "unsigned")) { - r_strbuf_set (sb, "uint32_t"); - } else if (r_str_startswith (tmp1, "int")) { - r_strbuf_set (sb, "int32_t"); + char* tmp1 = rz_strbuf_get (sb); + if (rz_str_startswith (tmp1, "unsigned long long")) { + rz_strbuf_set (sb, "uint64_t"); + } else if (rz_str_startswith (tmp1, "unsigned")) { + rz_strbuf_set (sb, "uint32_t"); + } else if (rz_str_startswith (tmp1, "int")) { + rz_strbuf_set (sb, "int32_t"); } - r_anal_var_set_type (var, r_strbuf_get (sb)); - r_strbuf_free (sb); + rz_anal_var_set_type (var, rz_strbuf_get (sb)); + rz_strbuf_free (sb); } -static void get_src_regname(RCore *core, ut64 addr, char *regname, int size) { - RAnal *anal = core->anal; - RAnalOp *op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_ESIL); - if (!op || r_strbuf_is_empty (&op->esil)) { - r_anal_op_free (op); +static void get_src_regname(RzCore *core, ut64 addr, char *regname, int size) { + RzAnal *anal = core->anal; + RzAnalOp *op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_ESIL); + if (!op || rz_strbuf_is_empty (&op->esil)) { + rz_anal_op_free (op); return; } - char *op_esil = strdup (r_strbuf_get (&op->esil)); + char *op_esil = strdup (rz_strbuf_get (&op->esil)); char *tmp = strchr (op_esil, ','); if (tmp) { *tmp = '\0'; } memset (regname, 0, size); - RRegItem *ri = r_reg_get (anal->reg, op_esil, -1); + RzRegItem *ri = rz_reg_get (anal->reg, op_esil, -1); if (ri) { if ((anal->bits == 64) && (ri->size == 32)) { - const char *reg = r_reg_32_to_64 (anal->reg, op_esil); + const char *reg = rz_reg_32_to_64 (anal->reg, op_esil); if (reg) { free (op_esil); op_esil = strdup (reg); @@ -168,7 +168,7 @@ static void get_src_regname(RCore *core, ut64 addr, char *regname, int size) { strncpy (regname, op_esil, size - 1); } free (op_esil); - r_anal_op_free (op); + rz_anal_op_free (op); } static ut64 get_addr(Sdb *trace, const char *regname, int idx) { @@ -176,10 +176,10 @@ static ut64 get_addr(Sdb *trace, const char *regname, int idx) { return UT64_MAX; } const char *query = sdb_fmt ("%d.reg.read.%s", idx, regname); - return r_num_math (NULL, sdb_const_get (trace, query, 0)); + return rz_num_math (NULL, sdb_const_get (trace, query, 0)); } -static _RAnalCond cond_invert(RAnal *anal, _RAnalCond cond) { +static _RzAnalCond cond_invert(RzAnal *anal, _RzAnalCond cond) { switch (cond) { case R_ANAL_COND_LE: return R_ANAL_COND_GT; @@ -200,16 +200,16 @@ static _RAnalCond cond_invert(RAnal *anal, _RAnalCond cond) { the opposite of any condition not in the list above is "always"? */ } -static RList *parse_format(RCore *core, char *fmt) { +static RzList *parse_format(RzCore *core, char *fmt) { if (!fmt || !*fmt) { return NULL; } - RList *ret = r_list_new (); + RzList *ret = rz_list_new (); if (!ret) { return NULL; } Sdb *s = core->anal->sdb_fmts; - const char *spec = r_config_get (core->config, "anal.types.spec"); + const char *spec = rz_config_get (core->config, "anal.types.spec"); char arr[10] = {0}; char *ptr = strchr (fmt, '%'); fmt[strlen (fmt) - 1] = '\0'; @@ -219,7 +219,7 @@ static RList *parse_format(RCore *core, char *fmt) { while (IS_DIGIT (*ptr)) { ptr++; } - r_str_ncpy (arr, ptr, sizeof (arr) - 1); + rz_str_ncpy (arr, ptr, sizeof (arr) - 1); char *tmp = arr; while (tmp && (IS_LOWER (*tmp) || IS_UPPER (*tmp))) { tmp++; @@ -228,35 +228,35 @@ static RList *parse_format(RCore *core, char *fmt) { const char *query = sdb_fmt ("spec.%s.%s", spec, arr); char *type = (char *) sdb_const_get (s, query, 0); if (type) { - r_list_append (ret, type); + rz_list_append (ret, type); } ptr = strchr (ptr, '%'); } return ret; } -static void retype_callee_arg(RAnal *anal, const char *callee_name, bool in_stack, const char *place, int size, const char *type) { - RAnalFunction *fcn = r_anal_get_function_byname (anal, callee_name); +static void retype_callee_arg(RzAnal *anal, const char *callee_name, bool in_stack, const char *place, int size, const char *type) { + RzAnalFunction *fcn = rz_anal_get_function_byname (anal, callee_name); if (!fcn) { return; } if (in_stack) { - RAnalVar *var = r_anal_function_get_var (fcn, R_ANAL_VAR_KIND_BPV, size - fcn->bp_off + 8); + RzAnalVar *var = rz_anal_function_get_var (fcn, R_ANAL_VAR_KIND_BPV, size - fcn->bp_off + 8); if (!var) { return; } __var_retype (anal, var, NULL, type, false, false); } else { - RRegItem *item = r_reg_get (anal->reg, place, -1); + RzRegItem *item = rz_reg_get (anal->reg, place, -1); if (!item) { return; } - RAnalVar *rvar = r_anal_function_get_var (fcn, R_ANAL_VAR_KIND_REG, item->index); + RzAnalVar *rvar = rz_anal_function_get_var (fcn, R_ANAL_VAR_KIND_REG, item->index); if (!rvar) { return; } __var_retype (anal, rvar, NULL, type, false, false); - RAnalVar *lvar = r_anal_var_get_dst_var (rvar); + RzAnalVar *lvar = rz_anal_var_get_dst_var (rvar); if (lvar) { __var_retype (anal, lvar, NULL, type, false, false); } @@ -278,28 +278,28 @@ static void retype_callee_arg(RAnal *anal, const char *callee_name, bool in_stac * \param userfnc whether the callee is a user function (affects propagation direction) * \param caddr addr of the callee */ -static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const char* cc, +static void type_match(RzCore *core, char *fcn_name, ut64 addr, ut64 baddr, const char* cc, int prev_idx, bool userfnc, ut64 caddr) { Sdb *trace = core->anal->esil->trace->db; Sdb *TDB = core->anal->sdb_types; - RAnal *anal = core->anal; - RList *types = NULL; + RzAnal *anal = core->anal; + RzList *types = NULL; int idx = sdb_num_get (trace, "idx", 0); - bool verbose = r_config_get_i (core->config, "anal.types.verbose"); + bool verbose = rz_config_get_i (core->config, "anal.types.verbose"); bool stack_rev = false, in_stack = false, format = false; if (!fcn_name || !cc) { return; } - int i, j, pos = 0, size = 0, max = r_type_func_args_count (TDB, fcn_name); - const char *place = r_anal_cc_arg (anal, cc, ST32_MAX); - r_cons_break_push (NULL, NULL); + int i, j, pos = 0, size = 0, max = rz_type_func_args_count (TDB, fcn_name); + const char *place = rz_anal_cc_arg (anal, cc, ST32_MAX); + rz_cons_break_push (NULL, NULL); if (place && !strcmp (place, "stack_rev")) { stack_rev = true; } - place = r_anal_cc_arg (anal, cc, 0); - if (place && r_str_startswith ("stack", place)) { + place = rz_anal_cc_arg (anal, cc, 0); + if (place && rz_str_startswith ("stack", place)) { in_stack = true; } if (verbose && !strncmp (fcn_name, "sym.imp.", 8)) { @@ -307,7 +307,7 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const } if (!max) { if (!in_stack) { - max = r_anal_cc_max_arg (anal, cc); + max = rz_anal_cc_max_arg (anal, cc); } else { max = DEFAULT_MAX; } @@ -317,21 +317,21 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const char *type = NULL; const char *name = NULL; if (format) { - if (r_list_empty (types)) { + if (rz_list_empty (types)) { break; } - type = r_str_new (r_list_get_n (types, pos++)); + type = rz_str_new (rz_list_get_n (types, pos++)); } else { - type = r_type_func_args_type (TDB, fcn_name, arg_num); - name = r_type_func_args_name (TDB, fcn_name, arg_num); + type = rz_type_func_args_type (TDB, fcn_name, arg_num); + name = rz_type_func_args_name (TDB, fcn_name, arg_num); } if (!type && !userfnc) { continue; } if (!in_stack) { //XXX: param arg_num must be fixed to support floating point register - place = r_anal_cc_arg (anal, cc, arg_num); - if (place && r_str_startswith ("stack", place)) { + place = rz_anal_cc_arg (anal, cc, arg_num); + if (place && rz_str_startswith ("stack", place)) { in_stack = true; } } @@ -346,19 +346,19 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const if (instr_addr < baddr) { break; } - RAnalOp *op = r_core_anal_op (core, instr_addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); + RzAnalOp *op = rz_core_anal_op (core, instr_addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); if (!op) { - r_anal_op_free (op); + rz_anal_op_free (op); break; } - RAnalOp *next_op = r_core_anal_op (core, instr_addr + op->size, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); + RzAnalOp *next_op = rz_core_anal_op (core, instr_addr + op->size, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); if (!next_op || (j != idx && (next_op->type == R_ANAL_OP_TYPE_CALL || next_op->type == R_ANAL_OP_TYPE_JMP))) { - r_anal_op_free (op); - r_anal_op_free (next_op); + rz_anal_op_free (op); + rz_anal_op_free (next_op); break; } - RAnalVar *var = r_anal_get_used_function_var (anal, op->addr); + RzAnalVar *var = rz_anal_get_used_function_var (anal, op->addr); const char *query = sdb_fmt ("%d.mem.read", j); if (op->type == R_ANAL_OP_TYPE_MOV && sdb_const_get (trace, query, 0)) { memref = ! (!memref && var && (var->kind != R_ANAL_VAR_KIND_REG)); @@ -366,18 +366,18 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const // Match type from function param to instr if (type_pos_hit (anal, trace, in_stack, j, size, place)) { if (!cmt_set && type && name) { - r_meta_set_string (anal, R_META_TYPE_VARTYPE, instr_addr, - sdb_fmt ("%s%s%s", type, r_str_endswith (type, "*") ? "" : " ", name)); + rz_meta_set_string (anal, R_META_TYPE_VARTYPE, instr_addr, + sdb_fmt ("%s%s%s", type, rz_str_endswith (type, "*") ? "" : " ", name)); cmt_set = true; if ((op->ptr && op->ptr != UT64_MAX) && !strcmp (name, "format")) { - RFlagItem *f = r_flag_get_by_spaces (core->flags, op->ptr, R_FLAGS_FS_STRINGS, NULL); + RzFlagItem *f = rz_flag_get_by_spaces (core->flags, op->ptr, R_FLAGS_FS_STRINGS, NULL); if (f) { char formatstr[0x200]; - int read = r_io_nread_at (core->io, f->offset, (ut8 *)formatstr, R_MIN (sizeof (formatstr) - 1, f->size)); + int read = rz_io_nread_at (core->io, f->offset, (ut8 *)formatstr, R_MIN (sizeof (formatstr) - 1, f->size)); if (read > 0) { formatstr[read] = '\0'; if ((types = parse_format (core, formatstr))) { - max += r_list_length (types); + max += rz_list_length (types); } format = true; } @@ -432,47 +432,47 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const __var_retype (anal, var, name, type? type: "int", memref, false); } } - r_anal_op_free (op); - r_anal_op_free (next_op); + rz_anal_op_free (op); + rz_anal_op_free (next_op); } size += anal->bits / 8; free (type); } - r_list_free (types); - r_cons_break_pop (); + rz_list_free (types); + rz_cons_break_pop (); } static int bb_cmpaddr(const void *_a, const void *_b) { - const RAnalBlock *a = _a, *b = _b; + const RzAnalBlock *a = _a, *b = _b; return a->addr > b->addr ? 1 : (a->addr < b->addr ? -1 : 0); } -R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *it; - RAnalOp aop = {0}; +RZ_API void rz_core_anal_type_match(RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *it; + RzAnalOp aop = {0}; bool resolved = false; - r_return_if_fail (core && core->anal && fcn); + rz_return_if_fail (core && core->anal && fcn); if (!core->anal->esil) { eprintf ("Please run aeim\n"); return; } - RAnal *anal = core->anal; + RzAnal *anal = core->anal; Sdb *TDB = anal->sdb_types; - bool chk_constraint = r_config_get_i (core->config, "anal.types.constraint"); + bool chk_constraint = rz_config_get_i (core->config, "anal.types.constraint"); int ret, bsize = R_MAX (64, core->blocksize); - const int mininstrsz = r_anal_archinfo (anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + const int mininstrsz = rz_anal_archinfo (anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); int cur_idx , prev_idx = 0; - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { return; } - RDebugTrace *dt; - RAnalEsilTrace *et; + RzDebugTrace *dt; + RzAnalEsilTrace *et; if (!anal_emul_init (core, hc, &dt, &et) || !fcn) { anal_emul_restore (core, hc, dt, et); return; @@ -489,7 +489,7 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { ht_pp_free (etracedb->ht); etracedb->ht = ht_pp_new_size (fcn->ninstr * 0xf, opt.dupvalue, opt.freefn, opt.calcsizeV); etracedb->ht->opt = opt; - RDebugTrace *dtrace = core->dbg->trace; + RzDebugTrace *dtrace = core->dbg->trace; opt = dtrace->ht->opt; ht_pp_free (dtrace->ht); dtrace->ht = ht_pp_new_size (fcn->ninstr, opt.dupvalue, opt.freefn, opt.calcsizeV); @@ -503,96 +503,96 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { char prev_type[256] = {0}; const char *prev_dest = NULL; char *ret_reg = NULL; - const char *pc = r_reg_get_name (core->dbg->reg, R_REG_NAME_PC); + const char *pc = rz_reg_get_name (core->dbg->reg, R_REG_NAME_PC); if (!pc) { return; } - RRegItem *r = r_reg_get (core->dbg->reg, pc, -1); + RzRegItem *r = rz_reg_get (core->dbg->reg, pc, -1); if (!r) { return; } - r_cons_break_push (NULL, NULL); - r_list_sort (fcn->bbs, bb_cmpaddr); // TODO: The algorithm can be more accurate if blocks are followed by their jmp/fail, not just by address - r_list_foreach (fcn->bbs, it, bb) { + rz_cons_break_push (NULL, NULL); + rz_list_sort (fcn->bbs, bb_cmpaddr); // TODO: The algorithm can be more accurate if blocks are followed by their jmp/fail, not just by address + rz_list_foreach (fcn->bbs, it, bb) { ut64 addr = bb->addr; int i = 0; - r_reg_set_value (core->dbg->reg, r, addr); + rz_reg_set_value (core->dbg->reg, r, addr); while (1) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto out_function; } if (i >= (bsize - 32)) { i = 0; } - ut64 pcval = r_reg_getv (anal->reg, pc); + ut64 pcval = rz_reg_getv (anal->reg, pc); if ((addr >= bb->addr + bb->size) || (addr < bb->addr) || pcval != addr) { break; } if (!i) { - r_io_read_at (core->io, addr, buf, bsize); + rz_io_read_at (core->io, addr, buf, bsize); } - ret = r_anal_op (anal, &aop, addr, buf + i, bsize - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); + ret = rz_anal_op (anal, &aop, addr, buf + i, bsize - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_VAL); if (ret <= 0) { i += minopcode; addr += minopcode; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); continue; } int loop_count = sdb_num_get (anal->esil->trace->db, sdb_fmt ("0x%"PFMT64x".count", addr), 0); if (loop_count > LOOP_MAX || aop.type == R_ANAL_OP_TYPE_RET) { - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); break; } sdb_num_set (anal->esil->trace->db, sdb_fmt ("0x%"PFMT64x".count", addr), loop_count + 1, 0); - if (r_anal_op_nonlinear (aop.type)) { // skip the instr - r_reg_set_value (core->dbg->reg, r, addr + ret); + if (rz_anal_op_nonlinear (aop.type)) { // skip the instr + rz_reg_set_value (core->dbg->reg, r, addr + ret); } else { - r_core_esil_step (core, UT64_MAX, NULL, NULL, false); + rz_core_esil_step (core, UT64_MAX, NULL, NULL, false); } bool userfnc = false; Sdb *trace = anal->esil->trace->db; cur_idx = sdb_num_get (trace, "idx", 0); - RAnalVar *var = r_anal_get_used_function_var (anal, aop.addr); - RAnalOp *next_op = r_core_anal_op (core, addr + ret, R_ANAL_OP_MASK_BASIC); // | _VAL ? + RzAnalVar *var = rz_anal_get_used_function_var (anal, aop.addr); + RzAnalOp *next_op = rz_core_anal_op (core, addr + ret, R_ANAL_OP_MASK_BASIC); // | _VAL ? ut32 type = aop.type & R_ANAL_OP_TYPE_MASK; if (aop.type == R_ANAL_OP_TYPE_CALL || aop.type & R_ANAL_OP_TYPE_UCALL) { char *full_name = NULL; ut64 callee_addr; if (aop.type == R_ANAL_OP_TYPE_CALL) { - RAnalFunction *fcn_call = r_anal_get_fcn_in (anal, aop.jump, -1); + RzAnalFunction *fcn_call = rz_anal_get_fcn_in (anal, aop.jump, -1); if (fcn_call) { full_name = fcn_call->name; callee_addr = fcn_call->addr; } } else if (aop.ptr != UT64_MAX) { - RFlagItem *flag = r_flag_get_by_spaces (core->flags, aop.ptr, R_FLAGS_FS_IMPORTS, NULL); + RzFlagItem *flag = rz_flag_get_by_spaces (core->flags, aop.ptr, R_FLAGS_FS_IMPORTS, NULL); if (flag && flag->realname) { full_name = flag->realname; callee_addr = aop.ptr; } } if (full_name) { - if (r_type_func_exist (TDB, full_name)) { + if (rz_type_func_exist (TDB, full_name)) { fcn_name = strdup (full_name); } else { - fcn_name = r_type_func_guess (TDB, full_name); + fcn_name = rz_type_func_guess (TDB, full_name); } if (!fcn_name) { fcn_name = strdup (full_name); userfnc = true; } - const char* Cc = r_anal_cc_func (anal, fcn_name); - if (Cc && r_anal_cc_exist (anal, Cc)) { + const char* Cc = rz_anal_cc_func (anal, fcn_name); + if (Cc && rz_anal_cc_exist (anal, Cc)) { char *cc = strdup (Cc); type_match (core, fcn_name, addr, bb->addr, cc, prev_idx, userfnc, callee_addr); prev_idx = cur_idx; R_FREE (ret_type); - const char *rt = r_type_func_ret (TDB, fcn_name); + const char *rt = rz_type_func_ret (TDB, fcn_name); if (rt) { ret_type = strdup (rt); } R_FREE (ret_reg); - const char *rr = r_anal_cc_ret (anal, cc); + const char *rr = rz_anal_cc_ret (anal, cc); if (rr) { ret_reg = strdup (rr); } @@ -602,15 +602,15 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { if (!strcmp (fcn_name, "__stack_chk_fail")) { const char *query = sdb_fmt ("%d.addr", cur_idx - 1); ut64 mov_addr = sdb_num_get (trace, query, 0); - RAnalOp *mop = r_core_anal_op (core, mov_addr, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_BASIC); + RzAnalOp *mop = rz_core_anal_op (core, mov_addr, R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_BASIC); if (mop) { - RAnalVar *mopvar = r_anal_get_used_function_var (anal, mop->addr); + RzAnalVar *mopvar = rz_anal_get_used_function_var (anal, mop->addr); ut32 type = mop->type & R_ANAL_OP_TYPE_MASK; if (type == R_ANAL_OP_TYPE_MOV) { __var_rename (anal, mopvar, "canary", addr); } } - r_anal_op_free (mop); + rz_anal_op_free (mop); } free (fcn_name); } @@ -684,30 +684,30 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { if (chk_constraint && var && (type == R_ANAL_OP_TYPE_CMP && aop.disp != UT64_MAX) && next_op && next_op->type == R_ANAL_OP_TYPE_CJMP) { bool jmp = false; - RAnalOp *jmp_op = {0}; + RzAnalOp *jmp_op = {0}; ut64 jmp_addr = next_op->jump; - RAnalBlock *jmpbb = r_anal_fcn_bbget_in (anal, fcn, jmp_addr); + RzAnalBlock *jmpbb = rz_anal_fcn_bbget_in (anal, fcn, jmp_addr); // Check exit status of jmp branch for (i = 0; i < MAX_INSTR ; i++) { - jmp_op = r_core_anal_op (core, jmp_addr, R_ANAL_OP_MASK_BASIC); + jmp_op = rz_core_anal_op (core, jmp_addr, R_ANAL_OP_MASK_BASIC); if (!jmp_op) { break; } - if ((jmp_op->type == R_ANAL_OP_TYPE_RET && r_anal_block_contains (jmpbb, jmp_addr)) + if ((jmp_op->type == R_ANAL_OP_TYPE_RET && rz_anal_block_contains (jmpbb, jmp_addr)) || jmp_op->type == R_ANAL_OP_TYPE_CJMP) { jmp = true; - r_anal_op_free (jmp_op); + rz_anal_op_free (jmp_op); break; } jmp_addr += jmp_op->size; - r_anal_op_free (jmp_op); + rz_anal_op_free (jmp_op); } - RAnalVarConstraint constr = { + RzAnalVarConstraint constr = { .cond = jmp? cond_invert (anal, next_op->cond): next_op->cond, .val = aop.val }; - r_anal_var_add_constraint (var, &constr); + rz_anal_var_add_constraint (var, &constr); } } prev_var = (var && aop.direction == R_ANAL_OP_DIR_READ); @@ -721,15 +721,15 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { if (aop.ptr && aop.refptr && aop.ptr != UT64_MAX) { if (type == R_ANAL_OP_TYPE_LOAD) { ut8 buf[256] = {0}; - r_io_read_at (core->io, aop.ptr, buf, sizeof (buf) - 1); - ut64 ptr = r_read_ble (buf, core->print->big_endian, aop.refptr * 8); + rz_io_read_at (core->io, aop.ptr, buf, sizeof (buf) - 1); + ut64 ptr = rz_read_ble (buf, core->print->big_endian, aop.refptr * 8); if (ptr && ptr != UT64_MAX) { - RFlagItem *f = r_flag_get_by_spaces (core->flags, ptr, R_FLAGS_FS_STRINGS, NULL); + RzFlagItem *f = rz_flag_get_by_spaces (core->flags, ptr, R_FLAGS_FS_STRINGS, NULL); if (f) { str_flag = true; } } - } else if (r_flag_exist_at (core->flags, "str", 3, aop.ptr)) { + } else if (rz_flag_exist_at (core->flags, "str", 3, aop.ptr)) { str_flag = true; } } @@ -746,18 +746,18 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { } i += ret; addr += ret; - r_anal_op_free (next_op); - r_anal_op_fini (&aop); + rz_anal_op_free (next_op); + rz_anal_op_fini (&aop); } } // Type propgation for register based args - RList *list = r_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); - RAnalVar *rvar; - RListIter *iter; - r_list_foreach (list, iter, rvar) { - RAnalVar *lvar = r_anal_var_get_dst_var (rvar); - RRegItem *i = r_reg_index_get (anal->reg, rvar->delta); + RzList *list = rz_anal_var_list (anal, fcn, R_ANAL_VAR_KIND_REG); + RzAnalVar *rvar; + RzListIter *iter; + rz_list_foreach (list, iter, rvar) { + RzAnalVar *lvar = rz_anal_var_get_dst_var (rvar); + RzRegItem *i = rz_reg_index_get (anal->reg, rvar->delta); if (!i) { continue; } @@ -768,11 +768,11 @@ R_API void r_core_anal_type_match(RCore *core, RAnalFunction *fcn) { __var_retype (anal, lvar, NULL, rvar->type, false, false); } } - r_list_free (list); + rz_list_free (list); out_function: R_FREE (ret_reg); R_FREE (ret_type); free (buf); - r_cons_break_pop(); + rz_cons_break_pop(); anal_emul_restore (core, hc, dt, et); } diff --git a/libr/core/blaze.c b/librz/core/blaze.c similarity index 78% rename from libr/core/blaze.c rename to librz/core/blaze.c index 742af9b48f..ddcc2fbcfa 100644 --- a/libr/core/blaze.c +++ b/librz/core/blaze.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2017 - pancake, defragger */ -#include +#include typedef enum bb_type { TRAP, @@ -25,36 +25,36 @@ typedef struct bb { typedef struct fcn { ut64 addr; ut64 size; - RList *bbs; + RzList *bbs; st64 score; ut64 ends; } fcn_t; -static bool __is_data_block_cb(RAnalBlock *block, void *user) { +static bool __is_data_block_cb(RzAnalBlock *block, void *user) { bool *block_exists = user; *block_exists = true; return false; } -static int __isdata(RCore *core, ut64 addr) { - if (!r_io_is_valid_offset (core->io, addr, false)) { +static int __isdata(RzCore *core, ut64 addr) { + if (!rz_io_is_valid_offset (core->io, addr, false)) { // eprintf ("Warning: Invalid memory address at 0x%08"PFMT64x"\n", addr); return 4; } bool block_exists = false; // This will just set block_exists = true if there is any basic block at this addr - r_anal_blocks_foreach_in (core->anal, addr, __is_data_block_cb, &block_exists); + rz_anal_blocks_foreach_in (core->anal, addr, __is_data_block_cb, &block_exists); if (block_exists) { return 1; } - RPVector *list = r_meta_get_all_in (core->anal, addr, R_META_TYPE_ANY); + RPVector *list = rz_meta_get_all_in (core->anal, addr, R_META_TYPE_ANY); void **it; int result = 0; - r_pvector_foreach (list, it) { + rz_pvector_foreach (list, it) { RIntervalNode *node = *it; - RAnalMetaItem *meta = node->data; + RzAnalMetaItem *meta = node->data; switch (meta->type) { case R_META_TYPE_DATA: case R_META_TYPE_STRING: @@ -66,7 +66,7 @@ static int __isdata(RCore *core, ut64 addr) { } } exit: - r_pvector_free (list); + rz_pvector_free (list); return result; } @@ -84,7 +84,7 @@ static bool fcnAddBB (fcn_t *fcn, bb_t* block) { eprintf ("Block list not initialized\n"); return false; } - r_list_append (fcn->bbs, block); + rz_list_append (fcn->bbs, block); return true; } @@ -95,7 +95,7 @@ static fcn_t* fcnNew (bb_t *block) { return NULL; } fcn->addr = block->start; - fcn->bbs = r_list_new (); + fcn->bbs = rz_list_new (); if (!fcnAddBB (fcn, block)) { eprintf ("Failed to add block to function\n"); } @@ -103,7 +103,7 @@ static fcn_t* fcnNew (bb_t *block) { } static void fcnFree (fcn_t *fcn) { - r_list_free (fcn->bbs); + rz_list_free (fcn->bbs); free (fcn); } @@ -126,7 +126,7 @@ static void initBB (bb_t *bb, ut64 start, ut64 end, ut64 jump, ut64 fail, bb_typ } } -static bool addBB(RList *block_list, ut64 start, ut64 end, ut64 jump, ut64 fail, bb_type_t type, int score) { +static bool addBB(RzList *block_list, ut64 start, ut64 end, ut64 jump, ut64 fail, bb_type_t type, int score) { bb_t *bb = (bb_t*) R_NEW0 (bb_t); if (!bb) { eprintf ("Failed to calloc mem for new basic block!\n"); @@ -145,7 +145,7 @@ static bool addBB(RList *block_list, ut64 start, ut64 end, ut64 jump, ut64 fail, } else { initBB (jump_bb, jump, UT64_MAX, UT64_MAX, UT64_MAX, JUMP, 0, 1, 0); } - r_list_append (block_list, jump_bb); + rz_list_append (block_list, jump_bb); } if (fail < UT64_MAX) { bb_t *fail_bb = (bb_t*) R_NEW0 (bb_t); @@ -155,9 +155,9 @@ static bool addBB(RList *block_list, ut64 start, ut64 end, ut64 jump, ut64 fail, return false; } initBB (fail_bb, fail, UT64_MAX, UT64_MAX, UT64_MAX, FAIL, 0, 1, 0); - r_list_append (block_list, fail_bb); + rz_list_append (block_list, fail_bb); } - r_list_append (block_list, bb); + rz_list_append (block_list, bb); return true; } @@ -166,10 +166,10 @@ void dump_block(bb_t *block) { , block->start, block->end, block->jump, block->fail, block->type); } -void dump_blocks (RList* list) { - RListIter *iter; +void dump_blocks (RzList* list) { + RzListIter *iter; bb_t *block = NULL; - r_list_foreach (list, iter, block) { + rz_list_foreach (list, iter, block) { dump_block(block); } } @@ -182,89 +182,89 @@ static bool checkFunction(fcn_t *fcn) { return false; } -static void printFunctionCommands(RCore *core, fcn_t* fcn, const char *name) { +static void printFunctionCommands(RzCore *core, fcn_t* fcn, const char *name) { if (!fcn) { eprintf ("No function given to print\n"); return; } - RListIter *fcn_iter; + RzListIter *fcn_iter; bb_t *cur = NULL; - const char *pfx = r_config_get (core->config, "anal.fcnprefix"); + const char *pfx = rz_config_get (core->config, "anal.fcnprefix"); if (!pfx) { pfx = "fcn"; } - char *_name = name? (char *) name: r_str_newf ("%s.%" PFMT64x, pfx, fcn->addr); - r_cons_printf ("af+ 0x%08" PFMT64x " %s\n", fcn->addr, _name); + char *_name = name? (char *) name: rz_str_newf ("%s.%" PFMT64x, pfx, fcn->addr); + rz_cons_printf ("af+ 0x%08" PFMT64x " %s\n", fcn->addr, _name); if (!name) { free (_name); } - r_list_foreach (fcn->bbs, fcn_iter, cur) { - r_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %llu 0x%08"PFMT64x" 0x%08"PFMT64x"\n" + rz_list_foreach (fcn->bbs, fcn_iter, cur) { + rz_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %llu 0x%08"PFMT64x" 0x%08"PFMT64x"\n" , fcn->addr, cur->start, cur->end - cur->start, cur->jump, cur->fail); } } -static void createFunction(RCore *core, fcn_t* fcn, const char *name) { +static void createFunction(RzCore *core, fcn_t* fcn, const char *name) { if (!fcn) { eprintf ("No function given to create\n"); return; } - RListIter *fcn_iter; + RzListIter *fcn_iter; bb_t *cur = NULL; - const char *pfx = r_config_get (core->config, "anal.fcnprefix"); + const char *pfx = rz_config_get (core->config, "anal.fcnprefix"); if (!pfx) { pfx = "fcn"; } - RAnalFunction *f = r_anal_function_new (core->anal); + RzAnalFunction *f = rz_anal_function_new (core->anal); if (!f) { eprintf ("Failed to create new function\n"); return; } - f->name = name? strdup (name): r_str_newf ("%s.%" PFMT64x, pfx, fcn->addr); + f->name = name? strdup (name): rz_str_newf ("%s.%" PFMT64x, pfx, fcn->addr); f->addr = fcn->addr; f->bits = core->anal->bits; - f->cc = r_str_constpool_get (&core->anal->constpool, r_anal_cc_default (core->anal)); + f->cc = rz_str_constpool_get (&core->anal->constpool, rz_anal_cc_default (core->anal)); f->type = R_ANAL_FCN_TYPE_FCN; - r_list_foreach (fcn->bbs, fcn_iter, cur) { + rz_list_foreach (fcn->bbs, fcn_iter, cur) { if (__isdata (core, cur->start)) { continue; } - r_anal_fcn_add_bb (core->anal, f, cur->start, (cur->end - cur->start), cur->jump, cur->fail, NULL); + rz_anal_fcn_add_bb (core->anal, f, cur->start, (cur->end - cur->start), cur->jump, cur->fail, NULL); } - if (!r_anal_add_function (core->anal, f)) { + if (!rz_anal_add_function (core->anal, f)) { // eprintf ("Failed to insert function\n"); - r_anal_function_free (f); + rz_anal_function_free (f); return; } } #define Fhandled(x) sdb_fmt("handled.%"PFMT64x"", x) -R_API bool core_anal_bbs(RCore *core, const char* input) { - if (!r_io_is_valid_offset (core->io, core->offset, false)) { +RZ_API bool core_anal_bbs(RzCore *core, const char* input) { + if (!rz_io_is_valid_offset (core->io, core->offset, false)) { eprintf ("No valid offset given to analyze\n"); return false; } Sdb *sdb = NULL; const ut64 start = core->offset; - ut64 size = input[0] ? r_num_math (core->num, input + 1) : core->blocksize; + ut64 size = input[0] ? rz_num_math (core->num, input + 1) : core->blocksize; ut64 b_start = start; - RListIter *iter; + RzListIter *iter; int block_score = 0; - RList *block_list; + RzList *block_list; bb_t *block = NULL; int invalid_instruction_barrier = -20000; - bool debug = r_config_get_i (core->config, "cfg.debug"); - bool nopskip = r_config_get_i (core->config, "anal.nopskip"); + bool debug = rz_config_get_i (core->config, "cfg.debug"); + bool nopskip = rz_config_get_i (core->config, "anal.nopskip"); - block_list = r_list_new (); + block_list = rz_list_new (); if (!block_list) { eprintf ("Failed to create block_list\n"); } @@ -275,7 +275,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { } ut64 cur = 0, base = 0; while (cur >= base && cur < size) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // magic number to fix huge section of invalid code fuzz files @@ -293,7 +293,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { cur += dsize; continue; } - RAnalOp *const op = r_core_anal_op (core, dst, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + RzAnalOp *const op = rz_core_anal_op (core, dst, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (!op || !op->mnemonic) { block_score -= 10; @@ -315,7 +315,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { } break; case R_ANAL_OP_TYPE_CALL: - if (r_anal_noreturn_at (core->anal, op->jump)) { + if (rz_anal_noreturn_at (core->anal, op->jump)) { addBB (block_list, b_start, dst + op->size, UT64_MAX, UT64_MAX, END, block_score); b_start = dst + op->size; block_score = 0; @@ -354,16 +354,16 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { break; } cur += op->size; - r_anal_op_free (op); + rz_anal_op_free (op); } if (debug) { eprintf ("Found %d basic blocks\n", block_list->length); } - RList *result = r_list_newf (free); + RzList *result = rz_list_newf (free); if (!result) { - r_list_free (block_list); + rz_list_free (block_list); eprintf ("Failed to create resulting list\n"); return false; } @@ -371,12 +371,12 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { sdb = sdb_new0 (); if (!sdb) { eprintf ("Failed to initialize sdb db\n"); - r_list_free (block_list); - r_list_free (result); + rz_list_free (block_list); + rz_list_free (result); return false; } - r_list_sort (block_list, (RListComparator)bbCMP); + rz_list_sort (block_list, (RzListComparator)bbCMP); if (debug) { eprintf ("Sorting all blocks done\n"); @@ -384,17 +384,17 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { } while (block_list->length > 0) { - block = r_list_pop (block_list); + block = rz_list_pop (block_list); if (!block) { eprintf ("Failed to get next block from list\n"); continue; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (block_list->length > 0) { - bb_t *next_block = (bb_t*) r_list_iter_get_data (block_list->tail); + bb_t *next_block = (bb_t*) rz_list_iter_get_data (block_list->tail); if (!next_block) { eprintf ("No next block to compare with!\n"); } @@ -440,7 +440,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { } sdb_ptr_set (sdb, sdb_fmt ("bb.0x%08"PFMT64x, block->start), block, 0); - r_list_append (result, block); + rz_list_append (result, block); } // finally search for functions @@ -450,23 +450,23 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { eprintf ("Trying to create functions\n"); } - r_list_foreach (result, iter, block) { - if (r_cons_is_breaked ()) { + rz_list_foreach (result, iter, block) { + if (rz_cons_is_breaked ()) { break; } if (block && (block->reached == 0 || block->called >= 1)) { fcn_t* current_function = fcnNew (block); - RStack *stack = r_stack_new (100); + RStack *stack = rz_stack_new (100); bb_t *jump = NULL; bb_t *fail = NULL; bb_t *cur = NULL; - if (!r_stack_push (stack, (void*)block)) { + if (!rz_stack_push (stack, (void*)block)) { eprintf ("Failed to push initial block\n"); } - while (!r_stack_is_empty (stack)) { - cur = (bb_t*) r_stack_pop (stack); + while (!rz_stack_is_empty (stack)) { + cur = (bb_t*) rz_stack_pop (stack); if (!cur) { continue; } @@ -489,7 +489,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { eprintf ("Failed to get jump block at 0x%"PFMT64x"\n", cur->jump); continue; } - if (!r_stack_push (stack, (void*)jump)) { + if (!rz_stack_push (stack, (void*)jump)) { eprintf ("Failed to push jump block to stack\n"); } } @@ -500,7 +500,7 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { eprintf ("Failed to get fail block at 0x%"PFMT64x"\n", cur->fail); continue; } - if (!r_stack_push (stack, (void*)fail)) { + if (!rz_stack_push (stack, (void*)fail)) { eprintf ("Failed to push jump block to stack\n"); } } @@ -518,18 +518,18 @@ R_API bool core_anal_bbs(RCore *core, const char* input) { fcnFree (current_function); } - r_stack_free (stack); + rz_stack_free (stack); } } sdb_free (sdb); - r_list_free (result); - r_list_free (block_list); + rz_list_free (result); + rz_list_free (block_list); return true; } -R_API bool core_anal_bbs_range (RCore *core, const char* input) { - if (!r_io_is_valid_offset (core->io, core->offset, false)) { +RZ_API bool core_anal_bbs_range (RzCore *core, const char* input) { + if (!rz_io_is_valid_offset (core->io, core->offset, false)) { eprintf ("No valid offset given to analyze\n"); return false; } @@ -537,20 +537,20 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { Sdb *sdb = NULL; ut64 cur = 0; ut64 start = core->offset; - ut64 size = input[0] ? r_num_math (core->num, input + 1) : core->blocksize; + ut64 size = input[0] ? rz_num_math (core->num, input + 1) : core->blocksize; ut64 b_start = start; - RAnalOp *op; - RListIter *iter; + RzAnalOp *op; + RzListIter *iter; int block_score = 0; - RList *block_list; + RzList *block_list; bb_t *block = NULL; int invalid_instruction_barrier = -20000; - bool debug = r_config_get_i (core->config, "cfg.debug"); + bool debug = rz_config_get_i (core->config, "cfg.debug"); ut64 lista[1024] = { 0 }; int idx = 0; int x; - block_list = r_list_new (); + block_list = rz_list_new (); if (!block_list) { eprintf ("Failed to create block_list\n"); } @@ -565,7 +565,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { b_start = lista[x]; lista[x] = 0; while (cur < size) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // magic number to fix huge section of invalid code fuzz files @@ -575,7 +575,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { bool bFound = false; // check if offset don't have into block_list, to end branch analisys - r_list_foreach (block_list, iter, block) { + rz_list_foreach (block_list, iter, block) { if ( (block->type == END || block->type == NORMAL) && b_start + cur == block->start ) { bFound = true; break; @@ -583,7 +583,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { } if (!bFound) { - op = r_core_anal_op (core, b_start + cur, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + op = rz_core_anal_op (core, b_start + cur, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (!op || !op->mnemonic) { block_score -= 10; @@ -635,7 +635,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { cur += op->size; break; } - r_anal_op_free (op); + rz_anal_op_free (op); op = NULL; } else { @@ -649,9 +649,9 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { eprintf ("Found %d basic blocks\n", block_list->length); } - RList *result = r_list_newf (free); + RzList *result = rz_list_newf (free); if (!result) { - r_list_free (block_list); + rz_list_free (block_list); eprintf ("Failed to create resulting list\n"); return false; } @@ -659,12 +659,12 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { sdb = sdb_new0 (); if (!sdb) { eprintf ("Failed to initialize sdb db\n"); - r_list_free (block_list); - r_list_free (result); + rz_list_free (block_list); + rz_list_free (result); return false; } - r_list_sort (block_list, (RListComparator)bbCMP); + rz_list_sort (block_list, (RzListComparator)bbCMP); if (debug) { eprintf ("Sorting all blocks done\n"); @@ -672,17 +672,17 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { } while (block_list->length > 0) { - block = r_list_pop (block_list); + block = rz_list_pop (block_list); if (!block) { eprintf ("Failed to get next block from list\n"); continue; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (block_list->length > 0) { - bb_t *next_block = (bb_t*)r_list_iter_get_data (block_list->tail); + bb_t *next_block = (bb_t*)rz_list_iter_get_data (block_list->tail); if (!next_block) { eprintf ("No next block to compare with!\n"); } @@ -728,7 +728,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { } sdb_ptr_set (sdb, sdb_fmt ("bb.0x%08"PFMT64x, block->start), block, 0); - r_list_append (result, block); + rz_list_append (result, block); } // finally add bb to function @@ -738,23 +738,23 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { eprintf ("Trying to create functions\n"); } - r_list_foreach (result, iter, block) { - if (r_cons_is_breaked ()) { + rz_list_foreach (result, iter, block) { + if (rz_cons_is_breaked ()) { break; } if (block && (block->reached == 0)) { fcn_t* current_function = fcnNew (block); - RStack *stack = r_stack_new (100); + RStack *stack = rz_stack_new (100); bb_t *jump = NULL; bb_t *fail = NULL; bb_t *cur = NULL; - if (!r_stack_push (stack, (void*)block)) { + if (!rz_stack_push (stack, (void*)block)) { eprintf ("Failed to push initial block\n"); } - while (!r_stack_is_empty (stack)) { - cur = (bb_t*)r_stack_pop (stack); + while (!rz_stack_is_empty (stack)) { + cur = (bb_t*)rz_stack_pop (stack); if (!cur) { continue; } @@ -777,7 +777,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { eprintf ("Failed to get jump block at 0x%"PFMT64x"\n", cur->jump); continue; } - if (!r_stack_push (stack, (void*)jump)) { + if (!rz_stack_push (stack, (void*)jump)) { eprintf ("Failed to push jump block to stack\n"); } } @@ -788,7 +788,7 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { eprintf ("Failed to get fail block at 0x%"PFMT64x"\n", cur->fail); continue; } - if (!r_stack_push (stack, (void*)fail)) { + if (!rz_stack_push (stack, (void*)fail)) { eprintf ("Failed to push jump block to stack\n"); } } @@ -808,18 +808,18 @@ R_API bool core_anal_bbs_range (RCore *core, const char* input) { createFunction (core, current_function, NULL); } fcnFree (current_function); - r_stack_free (stack); + rz_stack_free (stack); break; } } fcnFree (current_function); } - r_stack_free (stack); + rz_stack_free (stack); } } sdb_free (sdb); - r_list_free (result); - r_list_free (block_list); + rz_list_free (result); + rz_list_free (block_list); return true; } diff --git a/libr/core/canal.c b/librz/core/canal.c similarity index 59% rename from libr/core/canal.c rename to librz/core/canal.c index dadcf90788..2c59fc3056 100644 --- a/libr/core/canal.c +++ b/librz/core/canal.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -22,97 +22,97 @@ enum { #define MAX_SCAN_SIZE 0x7ffffff static void loganal(ut64 from, ut64 to, int depth) { - r_cons_clear_line (1); + rz_cons_clear_line (1); eprintf ("0x%08"PFMT64x" > 0x%08"PFMT64x" %d\r", from, to, depth); } static int cmpsize (const void *a, const void *b) { - ut64 as = r_anal_function_linear_size ((RAnalFunction *) a); - ut64 bs = r_anal_function_linear_size ((RAnalFunction *) b); + ut64 as = rz_anal_function_linear_size ((RzAnalFunction *) a); + ut64 bs = rz_anal_function_linear_size ((RzAnalFunction *) b); return (as> bs)? 1: (as< bs)? -1: 0; } static int cmpfcncc(const void *_a, const void *_b) { - RAnalFunction *a = (RAnalFunction *)_a; - RAnalFunction *b = (RAnalFunction *)_b; - ut64 as = r_anal_function_complexity (a); - ut64 bs = r_anal_function_complexity (b); + RzAnalFunction *a = (RzAnalFunction *)_a; + RzAnalFunction *b = (RzAnalFunction *)_b; + ut64 as = rz_anal_function_complexity (a); + ut64 bs = rz_anal_function_complexity (b); return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpedges(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; int as, bs; - r_anal_function_count_edges (a, &as); - r_anal_function_count_edges (b, &bs); + rz_anal_function_count_edges (a, &as); + rz_anal_function_count_edges (b, &bs); return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpframe(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; int as = a->maxstack; int bs = b->maxstack; return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpxrefs(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; int as = a->meta.numrefs; int bs = b->meta.numrefs; return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpname(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; int as = strcmp (a->name, b->name); int bs = strcmp (b->name, a->name); return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpcalls(const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; int as = a->meta.numcallrefs; int bs = b->meta.numcallrefs; return (as > bs)? 1: (as < bs)? -1: 0; } static int cmpnbbs (const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; - ut64 as = r_list_length (a->bbs); - ut64 bs = r_list_length (b->bbs); + const RzAnalFunction *a = _a, *b = _b; + ut64 as = rz_list_length (a->bbs); + ut64 bs = rz_list_length (b->bbs); return (as> bs)? 1: (as< bs)? -1: 0; } static int cmpaddr (const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; return (a->addr > b->addr)? 1: (a->addr < b->addr)? -1: 0; } -static char *getFunctionName(RCore *core, ut64 addr) { - RBinFile *bf = r_bin_cur (core->bin); +static char *getFunctionName(RzCore *core, ut64 addr) { + RBinFile *bf = rz_bin_cur (core->bin); if (bf && bf->o) { - Sdb *kv = bf->o->addr2klassmethod; + Sdb *kv = bf->o->addrzklassmethod; char *at = sdb_fmt ("0x%08"PFMT64x, addr); char *res = sdb_get (kv, at, 0); if (res) { return res; } } - RListIter *iter; - RFlagItem *flag; - const RList* flags = r_flag_get_list (core->flags, addr); + RzListIter *iter; + RzFlagItem *flag; + const RzList* flags = rz_flag_get_list (core->flags, addr); const char *name = NULL; - r_list_foreach (flags, iter, flag) { + rz_list_foreach (flags, iter, flag) { name = flag->name; - if (r_str_startswith (name, "sym.")) { + if (rz_str_startswith (name, "sym.")) { break; } } return name ? strdup (name) : NULL; } -static RCore *mycore = NULL; +static RzCore *mycore = NULL; // XXX: copypaste from anal/data.c #define MINLEN 1 @@ -149,7 +149,7 @@ static int is_string(const ut8 *buf, int size, int *len) { return 1; } -static char *is_string_at(RCore *core, ut64 addr, int *olen) { +static char *is_string_at(RzCore *core, ut64 addr, int *olen) { ut8 rstr[128] = {0}; int ret = 0, len = 0; ut8 *str = calloc (256, 1); @@ -159,7 +159,7 @@ static char *is_string_at(RCore *core, ut64 addr, int *olen) { } return NULL; } - r_io_read_at (core->io, addr, str, 255); + rz_io_read_at (core->io, addr, str, 255); str[255] = 0; if (is_string (str, 256, &len)) { @@ -181,7 +181,7 @@ static char *is_string_at(RCore *core, ut64 addr, int *olen) { ptr &= UT32_MAX; } if (ptr) { - r_io_read_at (core->io, ptr, rstr, sizeof (rstr)); + rz_io_read_at (core->io, ptr, rstr, sizeof (rstr)); rstr[127] = 0; ret = is_string (rstr, 128, &len); if (ret) { @@ -194,7 +194,7 @@ static char *is_string_at(RCore *core, ut64 addr, int *olen) { } } else { // pstring - r_io_read_at (core->io, lowptr, rstr, sizeof (rstr)); + rz_io_read_at (core->io, lowptr, rstr, sizeof (rstr)); rstr[127] = 0; ret = is_string (rstr, sizeof (rstr), &len); if (ret) { @@ -218,21 +218,21 @@ static char *is_string_at(RCore *core, ut64 addr, int *olen) { } /* returns the R_ANAL_ADDR_TYPE_* of the address 'addr' */ -R_API ut64 r_core_anal_address(RCore *core, ut64 addr) { +RZ_API ut64 rz_core_anal_address(RzCore *core, ut64 addr) { ut64 types = 0; - RRegSet *rs = NULL; + RzRegSet *rs = NULL; if (!core) { return 0; } if (core->dbg && core->dbg->reg) { - rs = r_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); + rs = rz_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); } if (rs) { - RRegItem *r; - RListIter *iter; - r_list_foreach (rs->regs, iter, r) { + RzRegItem *r; + RzListIter *iter; + rz_list_foreach (rs->regs, iter, r) { if (r->type == R_REG_TYPE_GPR) { - ut64 val = r_reg_getv(core->dbg->reg, r->name); + ut64 val = rz_reg_getv(core->dbg->reg, r->name); if (addr == val) { types |= R_ANAL_ADDR_TYPE_REG; break; @@ -240,20 +240,20 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) { } } } - if (r_flag_get_i (core->flags, addr)) { + if (rz_flag_get_i (core->flags, addr)) { types |= R_ANAL_ADDR_TYPE_FLAG; } - if (r_anal_get_fcn_in (core->anal, addr, 0)) { + if (rz_anal_get_fcn_in (core->anal, addr, 0)) { types |= R_ANAL_ADDR_TYPE_FUNC; } // check registers if (core->bin && core->bin->is_debugger && core->dbg) { // TODO: if cfg.debug here - RDebugMap *map; - RListIter *iter; + RzDebugMap *map; + RzListIter *iter; // use 'dm' // XXX: this line makes r2 debugging MUCH slower - // r_debug_map_sync (core->dbg); - r_list_foreach (core->dbg->maps, iter, map) { + // rz_debug_map_sync (core->dbg); + rz_list_foreach (core->dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { if (map->name && map->name[0] == '/') { if (core->io && core->io->desc && @@ -289,8 +289,8 @@ R_API ut64 r_core_anal_address(RCore *core, ut64 addr) { if (core->io) { // sections void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *s = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *s = *it; if (addr >= s->itv.addr && addr < (s->itv.addr + s->itv.size)) { // sections overlap, so we want to get the one with lower perms _perm = (_perm != -1) ? R_MIN (_perm, s->perm) : s->perm; @@ -371,22 +371,22 @@ static bool blacklisted_word(char* name) { return false; } -static char *anal_fcn_autoname(RCore *core, RAnalFunction *fcn, int dump, int mode) { +static char *anal_fcn_autoname(RzCore *core, RzAnalFunction *fcn, int dump, int mode) { int use_getopt = 0; int use_isatty = 0; PJ *pj = NULL; char *do_call = NULL; - RAnalRef *ref; - RListIter *iter; - RList *refs = r_anal_function_get_refs (fcn); + RzAnalRef *ref; + RzListIter *iter; + RzList *refs = rz_anal_function_get_refs (fcn); if (mode == 'j') { // start a new JSON object pj = pj_new (); pj_a (pj); } if (refs) { - r_list_foreach (refs, iter, ref) { - RFlagItem *f = r_flag_get_i (core->flags, ref->addr); + rz_list_foreach (refs, iter, ref) { + RzFlagItem *f = rz_flag_get_i (core->flags, ref->addr); if (f) { // If dump is true, print all strings referenced by the function if (dump) { @@ -400,7 +400,7 @@ static char *anal_fcn_autoname(RCore *core, RAnalFunction *fcn, int dump, int mo pj_ks (pj, "flag", f->name); pj_end (pj); } else { - r_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", ref->at, ref->addr, f->name); + rz_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", ref->at, ref->addr, f->name); } } } else if (do_call) { // break if a proper autoname found and not in dump mode @@ -440,18 +440,18 @@ static char *anal_fcn_autoname(RCore *core, RAnalFunction *fcn, int dump, int mo } } } - r_list_free (refs); + rz_list_free (refs); } if (mode == 'j') { pj_end (pj); } if (pj) { - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } // TODO: append counter if name already exists if (use_getopt) { - RFlagItem *item = r_flag_get (core->flags, "main"); + RzFlagItem *item = rz_flag_get (core->flags, "main"); free (do_call); // if referenced from entrypoint. this should be main if (item && item->offset == fcn->addr) { @@ -460,12 +460,12 @@ static char *anal_fcn_autoname(RCore *core, RAnalFunction *fcn, int dump, int mo return strdup ("parse_args"); // main? } if (use_isatty) { - char *ret = r_str_newf ("sub.setup_tty_%s_%"PFMT64x, do_call, fcn->addr); + char *ret = rz_str_newf ("sub.setup_tty_%s_%"PFMT64x, do_call, fcn->addr); free (do_call); return ret; } if (do_call) { - char *ret = r_str_newf ("sub.%s_%"PFMT64x, do_call, fcn->addr); + char *ret = rz_str_newf ("sub.%s_%"PFMT64x, do_call, fcn->addr); free (do_call); return ret; } @@ -473,23 +473,23 @@ static char *anal_fcn_autoname(RCore *core, RAnalFunction *fcn, int dump, int mo } /*this only autoname those function that start with fcn.* or sym.func.* */ -R_API void r_core_anal_autoname_all_fcns(RCore *core) { - RListIter *it; - RAnalFunction *fcn; +RZ_API void rz_core_anal_autoname_all_fcns(RzCore *core) { + RzListIter *it; + RzAnalFunction *fcn; - r_list_foreach (core->anal->fcns, it, fcn) { + rz_list_foreach (core->anal->fcns, it, fcn) { if (!strncmp (fcn->name, "fcn.", 4) || !strncmp (fcn->name, "sym.func.", 9)) { - RFlagItem *item = r_flag_get (core->flags, fcn->name); + RzFlagItem *item = rz_flag_get (core->flags, fcn->name); if (item) { char *name = anal_fcn_autoname (core, fcn, 0, 0); if (name) { - r_flag_rename (core->flags, item, name); + rz_flag_rename (core->flags, item, name); free (fcn->name); fcn->name = name; } } else { // there should always be a flag for a function - r_warn_if_reached (); + rz_warn_if_reached (); } } } @@ -497,74 +497,74 @@ R_API void r_core_anal_autoname_all_fcns(RCore *core) { /* reads .gopclntab section in go binaries to recover function names and adds them as sym.go.* flags */ -R_API void r_core_anal_autoname_all_golang_fcns(RCore *core) { - RList* section_list = r_bin_get_sections (core->bin); - RListIter *iter; +RZ_API void rz_core_anal_autoname_all_golang_fcns(RzCore *core) { + RzList* section_list = rz_bin_get_sections (core->bin); + RzListIter *iter; const char* oldstr = NULL; RBinSection *section; ut64 gopclntab = 0; - r_list_foreach (section_list, iter, section) { + rz_list_foreach (section_list, iter, section) { if (strstr (section->name, ".gopclntab")) { gopclntab = section->vaddr; break; } } if (!gopclntab) { - oldstr = r_print_rowlog (core->print, "Could not find .gopclntab section"); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Could not find .gopclntab section"); + rz_print_rowlog_done (core->print, oldstr); return; } int ptr_size = core->anal->bits / 8; ut64 offset = gopclntab + 2 * ptr_size; ut64 size_offset = gopclntab + 3 * ptr_size ; ut8 temp_size[4] = {0}; - if (!r_io_nread_at (core->io, size_offset, temp_size, 4)) { + if (!rz_io_nread_at (core->io, size_offset, temp_size, 4)) { return; } - ut32 size = r_read_le32 (temp_size); + ut32 size = rz_read_le32 (temp_size); int num_syms = 0; - //r_cons_print ("[x] Reading .gopclntab...\n"); - r_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS); + //rz_cons_print ("[x] Reading .gopclntab...\n"); + rz_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS); while (offset < gopclntab + size) { ut8 temp_delta[4] = {0}; ut8 temp_func_addr[4] = {0}; ut8 temp_func_name[4] = {0}; - if (!r_io_nread_at (core->io, offset + ptr_size, temp_delta, 4)) { + if (!rz_io_nread_at (core->io, offset + ptr_size, temp_delta, 4)) { break; } - ut32 delta = r_read_le32 (temp_delta); + ut32 delta = rz_read_le32 (temp_delta); ut64 func_offset = gopclntab + delta; - if (!r_io_nread_at (core->io, func_offset, temp_func_addr, 4) || - !r_io_nread_at (core->io, func_offset + ptr_size, temp_func_name, 4)) { + if (!rz_io_nread_at (core->io, func_offset, temp_func_addr, 4) || + !rz_io_nread_at (core->io, func_offset + ptr_size, temp_func_name, 4)) { break; } - ut32 func_addr = r_read_le32 (temp_func_addr); - ut32 func_name_offset = r_read_le32 (temp_func_name); + ut32 func_addr = rz_read_le32 (temp_func_addr); + ut32 func_name_offset = rz_read_le32 (temp_func_name); ut8 func_name[64] = {0}; - r_io_read_at (core->io, gopclntab + func_name_offset, func_name, 63); + rz_io_read_at (core->io, gopclntab + func_name_offset, func_name, 63); if (func_name[0] == 0xff) { break; } - r_name_filter ((char *)func_name, 0); - //r_cons_printf ("[x] Found symbol %s at 0x%x\n", func_name, func_addr); - r_flag_set (core->flags, sdb_fmt ("sym.go.%s", func_name), func_addr, 1); + rz_name_filter ((char *)func_name, 0); + //rz_cons_printf ("[x] Found symbol %s at 0x%x\n", func_name, func_addr); + rz_flag_set (core->flags, sdb_fmt ("sym.go.%s", func_name), func_addr, 1); offset += 2 * ptr_size; num_syms++; } - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); if (num_syms) { - oldstr = r_print_rowlog (core->print, sdb_fmt ("Found %d symbols and saved them at sym.go.*", num_syms)); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, sdb_fmt ("Found %d symbols and saved them at sym.go.*", num_syms)); + rz_print_rowlog_done (core->print, oldstr); } else { - oldstr = r_print_rowlog (core->print, "Found no symbols."); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Found no symbols."); + rz_print_rowlog_done (core->print, oldstr); } } /* suggest a name for the function at the address 'addr'. * If dump is true, every strings associated with the function is printed */ -R_API char *r_core_anal_fcn_autoname(RCore *core, ut64 addr, int dump, int mode) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); +RZ_API char *rz_core_anal_fcn_autoname(RzCore *core, ut64 addr, int dump, int mode) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { return anal_fcn_autoname (core, fcn, dump, mode); } @@ -582,32 +582,32 @@ static ut64 *next_append(ut64 *next, int *nexti, ut64 v) { return next; } -static void r_anal_set_stringrefs(RCore *core, RAnalFunction *fcn) { - RListIter *iter; - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { +static void rz_anal_set_stringrefs(RzCore *core, RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { if (ref->type == R_ANAL_REF_TYPE_DATA && - r_bin_is_string (core->bin, ref->addr)) { - r_anal_xrefs_set (core->anal, ref->at, ref->addr, R_ANAL_REF_TYPE_STRING); + rz_bin_is_string (core->bin, ref->addr)) { + rz_anal_xrefs_set (core->anal, ref->at, ref->addr, R_ANAL_REF_TYPE_STRING); } } - r_list_free (refs); + rz_list_free (refs); } -static bool r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int refdepth) { +static bool rz_anal_try_get_fcn(RzCore *core, RzAnalRef *ref, int fcndepth, int refdepth) { if (!refdepth) { return false; } - RIOMap *map = r_io_map_get (core->io, ref->addr); + RzIOMap *map = rz_io_map_get (core->io, ref->addr); if (!map) { return false; } if (map->perm & R_PERM_X) { ut8 buf[64]; - r_io_read_at (core->io, ref->addr, buf, sizeof (buf)); - bool looksLikeAFunction = r_anal_check_fcn (core->anal, buf, sizeof (buf), ref->addr, map->itv.addr, + rz_io_read_at (core->io, ref->addr, buf, sizeof (buf)); + bool looksLikeAFunction = rz_anal_check_fcn (core->anal, buf, sizeof (buf), ref->addr, map->itv.addr, map->itv.addr + map->itv.size); if (looksLikeAFunction) { if (core->anal->limit) { @@ -616,12 +616,12 @@ static bool r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int ref return 1; } } - r_core_anal_fcn (core, ref->addr, ref->at, ref->type, fcndepth - 1); + rz_core_anal_fcn (core, ref->addr, ref->at, ref->type, fcndepth - 1); } } else { ut64 offs = 0; ut64 sz = core->anal->bits >> 3; - RAnalRef ref1; + RzAnalRef ref1; ref1.type = R_ANAL_REF_TYPE_DATA; ref1.at = ref->addr; ref1.addr = 0; @@ -631,131 +631,131 @@ static bool r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int ref ut64 offe = offs + 1024; for (offs = 0; offs < offe; offs += sz, ref1.at += sz) { ut8 bo[8]; - r_io_read_at (core->io, ref->addr + offs, bo, R_MIN (sizeof (bo), sz)); + rz_io_read_at (core->io, ref->addr + offs, bo, R_MIN (sizeof (bo), sz)); bool be = core->anal->big_endian; switch (sz) { case 1: - i8 = r_read_ble8 (bo); + i8 = rz_read_ble8 (bo); ref1.addr = (ut64)i8; break; case 2: - i16 = r_read_ble16 (bo, be); + i16 = rz_read_ble16 (bo, be); ref1.addr = (ut64)i16; break; case 4: - i32 = r_read_ble32 (bo, be); + i32 = rz_read_ble32 (bo, be); ref1.addr = (ut64)i32; break; case 8: - ref1.addr = r_read_ble64 (bo, be); + ref1.addr = rz_read_ble64 (bo, be); break; } - r_anal_try_get_fcn (core, &ref1, fcndepth, refdepth - 1); + rz_anal_try_get_fcn (core, &ref1, fcndepth, refdepth - 1); } } return 1; } -static int r_anal_analyze_fcn_refs(RCore *core, RAnalFunction *fcn, int depth) { - RListIter *iter; - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); +static int rz_anal_analyze_fcn_refs(RzCore *core, RzAnalFunction *fcn, int depth) { + RzListIter *iter; + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { if (ref->addr == UT64_MAX) { continue; } switch (ref->type) { case R_ANAL_REF_TYPE_DATA: if (core->anal->opt.followdatarefs) { - r_anal_try_get_fcn (core, ref, depth, 2); + rz_anal_try_get_fcn (core, ref, depth, 2); } break; case R_ANAL_REF_TYPE_CODE: case R_ANAL_REF_TYPE_CALL: - r_core_anal_fcn (core, ref->addr, ref->at, ref->type, depth - 1); + rz_core_anal_fcn (core, ref->addr, ref->at, ref->type, depth - 1); break; default: break; } // TODO: fix memleak here, fcn not freed even though it is - // added in core->anal->fcns which is freed in r_anal_free() + // added in core->anal->fcns which is freed in rz_anal_free() } - r_list_free (refs); + rz_list_free (refs); return 1; } -static void function_rename(RFlag *flags, RAnalFunction *fcn) { +static void function_rename(RzFlag *flags, RzAnalFunction *fcn) { const char *locname = "loc."; const size_t locsize = strlen (locname); char *fcnname = fcn->name; if (strncmp (fcn->name, locname, locsize) == 0) { const char *fcnpfx, *restofname; - RFlagItem *f; + RzFlagItem *f; fcn->type = R_ANAL_FCN_TYPE_FCN; - fcnpfx = r_anal_fcntype_tostring (fcn->type); + fcnpfx = rz_anal_fcntype_tostring (fcn->type); restofname = fcn->name + locsize; - fcn->name = r_str_newf ("%s.%s", fcnpfx, restofname); + fcn->name = rz_str_newf ("%s.%s", fcnpfx, restofname); - f = r_flag_get_i (flags, fcn->addr); - r_flag_rename (flags, f, fcn->name); + f = rz_flag_get_i (flags, fcn->addr); + rz_flag_rename (flags, f, fcn->name); free (fcnname); } } -static void autoname_imp_trampoline(RCore *core, RAnalFunction *fcn) { - if (r_list_length (fcn->bbs) == 1 && ((RAnalBlock *) r_list_first (fcn->bbs))->ninstr == 1) { - RList *refs = r_anal_function_get_refs (fcn); - if (refs && r_list_length (refs) == 1) { - RAnalRef *ref = r_list_first (refs); +static void autoname_imp_trampoline(RzCore *core, RzAnalFunction *fcn) { + if (rz_list_length (fcn->bbs) == 1 && ((RzAnalBlock *) rz_list_first (fcn->bbs))->ninstr == 1) { + RzList *refs = rz_anal_function_get_refs (fcn); + if (refs && rz_list_length (refs) == 1) { + RzAnalRef *ref = rz_list_first (refs); if (ref->type != R_ANAL_REF_TYPE_CALL) { /* Some fcns don't return */ - RFlagItem *flg = r_flag_get_i (core->flags, ref->addr); - if (flg && r_str_startswith (flg->name, "sym.imp.")) { + RzFlagItem *flg = rz_flag_get_i (core->flags, ref->addr); + if (flg && rz_str_startswith (flg->name, "sym.imp.")) { R_FREE (fcn->name); - fcn->name = r_str_newf ("sub.%s", flg->name + 8); + fcn->name = rz_str_newf ("sub.%s", flg->name + 8); } } } - r_list_free (refs); + rz_list_free (refs); } } -static void set_fcn_name_from_flag(RAnalFunction *fcn, RFlagItem *f, const char *fcnpfx) { +static void set_fcn_name_from_flag(RzAnalFunction *fcn, RzFlagItem *f, const char *fcnpfx) { bool nameChanged = false; if (f && f->name) { if (!strncmp (fcn->name, "loc.", 4) || !strncmp (fcn->name, "fcn.", 4)) { - r_anal_function_rename (fcn, f->name); + rz_anal_function_rename (fcn, f->name); nameChanged = true; } else if (strncmp (f->name, "sect", 4)) { - r_anal_function_rename (fcn, f->name); + rz_anal_function_rename (fcn, f->name); nameChanged = true; } } if (!nameChanged) { - r_anal_function_rename (fcn, sdb_fmt ("%s.%08" PFMT64x, fcnpfx, fcn->addr)); + rz_anal_function_rename (fcn, sdb_fmt ("%s.%08" PFMT64x, fcnpfx, fcn->addr)); } } -static bool is_entry_flag(RFlagItem *f) { - return f->space && !strcmp (f->space->name, R_FLAGS_FS_SYMBOLS) && r_str_startswith (f->name, "entry."); +static bool is_entry_flag(RzFlagItem *f) { + return f->space && !strcmp (f->space->name, R_FLAGS_FS_SYMBOLS) && rz_str_startswith (f->name, "entry."); } -static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth) { +static int __core_anal_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth) { if (depth < 0) { // printf ("Too deep for 0x%08"PFMT64x"\n", at); -// r_sys_backtrace (); +// rz_sys_backtrace (); return false; } - int has_next = r_config_get_i (core->config, "anal.hasnext"); - RAnalHint *hint = NULL; + int has_next = rz_config_get_i (core->config, "anal.hasnext"); + RzAnalHint *hint = NULL; int i, nexti = 0; ut64 *next = NULL; int fcnlen; - RAnalFunction *fcn = r_anal_function_new (core->anal); - const char *fcnpfx = r_config_get (core->config, "anal.fcnprefix"); + RzAnalFunction *fcn = rz_anal_function_new (core->anal); + const char *fcnpfx = rz_config_get (core->config, "anal.fcnprefix"); if (!fcnpfx) { fcnpfx = "fcn"; } @@ -763,9 +763,9 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep eprintf ("Error: new (fcn)\n"); return false; } - fcn->cc = r_str_constpool_get (&core->anal->constpool, r_anal_cc_default (core->anal)); - r_warn_if_fail (!core->anal->sdb_cc->path || fcn->cc); - hint = r_anal_hint_get (core->anal, at); + fcn->cc = rz_str_constpool_get (&core->anal->constpool, rz_anal_cc_default (core->anal)); + rz_warn_if_fail (!core->anal->sdb_cc->path || fcn->cc); + hint = rz_anal_hint_get (core->anal, at); if (hint && hint->bits == 16) { // expand 16bit for function fcn->bits = 16; @@ -776,21 +776,21 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep fcn->name = getFunctionName (core, at); if (!fcn->name) { - fcn->name = r_str_newf ("%s.%08"PFMT64x, fcnpfx, at); + fcn->name = rz_str_newf ("%s.%08"PFMT64x, fcnpfx, at); } - r_anal_fcn_invalidate_read_ahead_cache (); + rz_anal_fcn_invalidate_read_ahead_cache (); do { - RFlagItem *f; - ut64 delta = r_anal_function_linear_size (fcn); - if (!r_io_is_valid_offset (core->io, at + delta, !core->anal->opt.noncode)) { + RzFlagItem *f; + ut64 delta = rz_anal_function_linear_size (fcn); + if (!rz_io_is_valid_offset (core->io, at + delta, !core->anal->opt.noncode)) { goto error; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - fcnlen = r_anal_fcn (core->anal, fcn, at + delta, core->anal->opt.bb_max_size, reftype); + fcnlen = rz_anal_fcn (core->anal, fcn, at + delta, core->anal->opt.bb_max_size, reftype); if (core->anal->opt.searchstringrefs) { - r_anal_set_stringrefs (core, fcn); + rz_anal_set_stringrefs (core, fcn); } if (fcnlen == 0) { if (core->anal->verbose) { @@ -810,28 +810,28 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep continue; } } - f = r_core_flag_get_by_spaces (core->flags, fcn->addr); + f = rz_core_flag_get_by_spaces (core->flags, fcn->addr); set_fcn_name_from_flag (fcn, f, fcnpfx); if (fcnlen == R_ANAL_RET_ERROR || - (fcnlen == R_ANAL_RET_END && !r_anal_function_realsize (fcn))) { /* Error analyzing function */ + (fcnlen == R_ANAL_RET_END && !rz_anal_function_realsize (fcn))) { /* Error analyzing function */ if (core->anal->opt.followbrokenfcnsrefs) { - r_anal_analyze_fcn_refs (core, fcn, depth); + rz_anal_analyze_fcn_refs (core, fcn, depth); } goto error; } else if (fcnlen == R_ANAL_RET_END) { /* Function analysis complete */ - f = r_core_flag_get_by_spaces (core->flags, fcn->addr); + f = rz_core_flag_get_by_spaces (core->flags, fcn->addr); if (f && f->name && strncmp (f->name, "sect", 4)) { /* Check if it's already flagged */ char *new_name = strdup (f->name); if (is_entry_flag (f)) { - RListIter *iter; + RzListIter *iter; RBinSymbol *sym; - const RList *syms = r_bin_get_symbols (core->bin); - ut64 baddr = r_config_get_i (core->config, "bin.baddr"); - r_list_foreach (syms, iter, sym) { + const RzList *syms = rz_bin_get_symbols (core->bin); + ut64 baddr = rz_config_get_i (core->config, "bin.baddr"); + rz_list_foreach (syms, iter, sym) { if ((sym->paddr + baddr) == fcn->addr && !strcmp (sym->type, R_BIN_TYPE_FUNC_STR)) { free (new_name); - new_name = r_str_newf ("sym.%s", sym->name); + new_name = rz_str_newf ("sym.%s", sym->name); break; } } @@ -840,27 +840,27 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep fcn->name = new_name; } else { R_FREE (fcn->name); - const char *fcnpfx = r_anal_fcntype_tostring (fcn->type); + const char *fcnpfx = rz_anal_fcntype_tostring (fcn->type); if (!fcnpfx || !*fcnpfx || !strcmp (fcnpfx, "fcn")) { - fcnpfx = r_config_get (core->config, "anal.fcnprefix"); + fcnpfx = rz_config_get (core->config, "anal.fcnprefix"); } - fcn->name = r_str_newf ("%s.%08"PFMT64x, fcnpfx, fcn->addr); + fcn->name = rz_str_newf ("%s.%08"PFMT64x, fcnpfx, fcn->addr); autoname_imp_trampoline (core, fcn); /* Add flag */ - r_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); - r_flag_set (core->flags, fcn->name, fcn->addr, r_anal_function_linear_size (fcn)); - r_flag_space_pop (core->flags); + rz_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); + rz_flag_set (core->flags, fcn->name, fcn->addr, rz_anal_function_linear_size (fcn)); + rz_flag_space_pop (core->flags); } /* New function: Add initial xref */ if (from != UT64_MAX) { - r_anal_xrefs_set (core->anal, from, fcn->addr, reftype); + rz_anal_xrefs_set (core->anal, from, fcn->addr, reftype); } // XXX: this is wrong. See CID 1134565 - r_anal_add_function (core->anal, fcn); + rz_anal_add_function (core->anal, fcn); if (has_next) { - ut64 addr = r_anal_function_max_addr (fcn); - RIOMap *map = r_io_map_get (core->io, addr); + ut64 addr = rz_anal_function_max_addr (fcn); + RzIOMap *map = rz_io_map_get (core->io, addr); // only get next if found on an executable section if (!map || (map && map->perm & R_PERM_X)) { for (i = 0; i < nexti; i++) { @@ -869,10 +869,10 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep } } if (i == nexti) { - ut64 at = r_anal_function_max_addr (fcn); + ut64 at = rz_anal_function_max_addr (fcn); while (true) { ut64 size; - RAnalMetaItem *mi = r_meta_get_at (core->anal, at, R_META_TYPE_ANY, &size); + RzAnalMetaItem *mi = rz_meta_get_at (core->anal, at, R_META_TYPE_ANY, &size); if (!mi) { break; } @@ -880,100 +880,100 @@ static int __core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dep } // TODO: ensure next address is function after padding (nop or trap or wat) // XXX noisy for test cases because we want to clear the stderr - r_cons_clear_line (1); + rz_cons_clear_line (1); loganal (fcn->addr, at, 10000 - depth); next = next_append (next, &nexti, at); } } } - if (!r_anal_analyze_fcn_refs (core, fcn, depth)) { + if (!rz_anal_analyze_fcn_refs (core, fcn, depth)) { goto error; } } } while (fcnlen != R_ANAL_RET_END); - r_list_free (core->anal->leaddrs); + rz_list_free (core->anal->leaddrs); core->anal->leaddrs = NULL; if (has_next) { for (i = 0; i < nexti; i++) { - if (!next[i] || r_anal_get_fcn_in (core->anal, next[i], 0)) { + if (!next[i] || rz_anal_get_fcn_in (core->anal, next[i], 0)) { continue; } - r_core_anal_fcn (core, next[i], from, 0, depth - 1); + rz_core_anal_fcn (core, next[i], from, 0, depth - 1); } free (next); } if (core->anal->cur && core->anal->cur->arch && !strcmp (core->anal->cur->arch, "x86")) { - r_anal_function_check_bp_use (fcn); + rz_anal_function_check_bp_use (fcn); if (fcn && !fcn->bp_frame) { - r_anal_function_delete_vars_by_kind (fcn, R_ANAL_VAR_KIND_BPV); + rz_anal_function_delete_vars_by_kind (fcn, R_ANAL_VAR_KIND_BPV); } } - r_anal_hint_free (hint); + rz_anal_hint_free (hint); return true; error: - r_list_free (core->anal->leaddrs); + rz_list_free (core->anal->leaddrs); core->anal->leaddrs = NULL; // ugly hack to free fcn if (fcn) { - if (!r_anal_function_realsize (fcn) || fcn->addr == UT64_MAX) { - r_anal_function_free (fcn); + if (!rz_anal_function_realsize (fcn) || fcn->addr == UT64_MAX) { + rz_anal_function_free (fcn); fcn = NULL; } else { // TODO: mark this function as not properly analyzed if (!fcn->name) { // XXX dupped code. - fcn->name = r_str_newf ( + fcn->name = rz_str_newf ( "%s.%08" PFMT64x, - r_anal_fcntype_tostring (fcn->type), + rz_anal_fcntype_tostring (fcn->type), at); /* Add flag */ - r_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); - r_flag_set (core->flags, fcn->name, at, r_anal_function_linear_size (fcn)); - r_flag_space_pop (core->flags); + rz_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); + rz_flag_set (core->flags, fcn->name, at, rz_anal_function_linear_size (fcn)); + rz_flag_space_pop (core->flags); } - r_anal_add_function (core->anal, fcn); + rz_anal_add_function (core->anal, fcn); } if (fcn && has_next) { - ut64 newaddr = r_anal_function_max_addr (fcn); - RIOMap *map = r_io_map_get (core->io, newaddr); + ut64 newaddr = rz_anal_function_max_addr (fcn); + RzIOMap *map = rz_io_map_get (core->io, newaddr); if (!map || (map && (map->perm & R_PERM_X))) { next = next_append (next, &nexti, newaddr); for (i = 0; i < nexti; i++) { if (!next[i]) { continue; } - r_core_anal_fcn (core, next[i], next[i], 0, depth - 1); + rz_core_anal_fcn (core, next[i], next[i], 0, depth - 1); } free (next); } } } if (fcn && core->anal->cur && core->anal->cur->arch && !strcmp (core->anal->cur->arch, "x86")) { - r_anal_function_check_bp_use (fcn); + rz_anal_function_check_bp_use (fcn); if (!fcn->bp_frame) { - r_anal_function_delete_vars_by_kind (fcn, R_ANAL_VAR_KIND_BPV); + rz_anal_function_delete_vars_by_kind (fcn, R_ANAL_VAR_KIND_BPV); } } - r_anal_hint_free (hint); + rz_anal_hint_free (hint); return false; } static char *get_title(ut64 addr) { - return r_str_newf ("0x%"PFMT64x, addr); + return rz_str_newf ("0x%"PFMT64x, addr); } -/* decode and return the RAnalOp at the address addr */ -R_API RAnalOp* r_core_anal_op(RCore *core, ut64 addr, int mask) { +/* decode and return the RzAnalOp at the address addr */ +RZ_API RzAnalOp* rz_core_anal_op(RzCore *core, ut64 addr, int mask) { int len; ut8 buf[32]; ut8 *ptr; - r_return_val_if_fail (core, NULL); + rz_return_val_if_fail (core, NULL); if (addr == UT64_MAX) { return NULL; } - RAnalOp *op = R_NEW0 (RAnalOp); + RzAnalOp *op = R_NEW0 (RzAnalOp); if (!op) { return NULL; } @@ -986,27 +986,27 @@ R_API RAnalOp* r_core_anal_op(RCore *core, ut64 addr, int mask) { goto err_op; } } else { - if (!r_io_read_at (core->io, addr, buf, sizeof (buf))) { + if (!rz_io_read_at (core->io, addr, buf, sizeof (buf))) { goto err_op; } ptr = buf; len = sizeof (buf); } - if (r_anal_op (core->anal, op, addr, ptr, len, mask) < 1) { + if (rz_anal_op (core->anal, op, addr, ptr, len, mask) < 1) { goto err_op; } // TODO This code block must be deleted when all the anal plugs support disasm if (!op->mnemonic && mask & R_ANAL_OP_MASK_DISASM) { - RAsmOp asmop; + RzAsmOp asmop; if (core->anal->verbose) { - eprintf ("WARNING: Implement RAnalOp.MASK_DISASM for current anal.arch. Using the sluggish RAsmOp fallback for now.\n"); + eprintf ("WARNING: Implement RzAnalOp.MASK_DISASM for current anal.arch. Using the sluggish RzAsmOp fallback for now.\n"); } - r_asm_set_pc (core->rasm, addr); - r_asm_op_init (&asmop); - if (r_asm_disassemble (core->rasm, &asmop, ptr, len) > 0) { - op->mnemonic = strdup (r_strbuf_get (&asmop.buf_asm)); + rz_asm_set_pc (core->rasm, addr); + rz_asm_op_init (&asmop); + if (rz_asm_disassemble (core->rasm, &asmop, ptr, len) > 0) { + op->mnemonic = strdup (rz_strbuf_get (&asmop.buf_asm)); } - r_asm_op_fini (&asmop); + rz_asm_op_fini (&asmop); } return op; err_op: @@ -1024,7 +1024,7 @@ typedef struct { HINT_NODE_BITS } type; union { - const RVector/**/ *addr_hints; + const RzVector/**/ *addr_hints; const char *arch; int bits; }; @@ -1033,60 +1033,60 @@ typedef struct { static void print_hint_h_format(HintNode *node) { switch (node->type) { case HINT_NODE_ADDR: { - const RAnalAddrHintRecord *record; - r_vector_foreach (node->addr_hints, record) { + const RzAnalAddrHintRecord *record; + rz_vector_foreach (node->addr_hints, record) { switch (record->type) { case R_ANAL_ADDR_HINT_TYPE_IMMBASE: - r_cons_printf (" immbase=%d", record->immbase); + rz_cons_printf (" immbase=%d", record->immbase); break; case R_ANAL_ADDR_HINT_TYPE_JUMP: - r_cons_printf (" jump=0x%08"PFMT64x, record->jump); + rz_cons_printf (" jump=0x%08"PFMT64x, record->jump); break; case R_ANAL_ADDR_HINT_TYPE_FAIL: - r_cons_printf (" fail=0x%08"PFMT64x, record->fail); + rz_cons_printf (" fail=0x%08"PFMT64x, record->fail); break; case R_ANAL_ADDR_HINT_TYPE_STACKFRAME: - r_cons_printf (" stackframe=0x%"PFMT64x, record->stackframe); + rz_cons_printf (" stackframe=0x%"PFMT64x, record->stackframe); break; case R_ANAL_ADDR_HINT_TYPE_PTR: - r_cons_printf (" ptr=0x%"PFMT64x, record->ptr); + rz_cons_printf (" ptr=0x%"PFMT64x, record->ptr); break; case R_ANAL_ADDR_HINT_TYPE_NWORD: - r_cons_printf (" nword=%d", record->nword); + rz_cons_printf (" nword=%d", record->nword); break; case R_ANAL_ADDR_HINT_TYPE_RET: - r_cons_printf (" ret=0x%08"PFMT64x, record->retval); + rz_cons_printf (" ret=0x%08"PFMT64x, record->retval); break; case R_ANAL_ADDR_HINT_TYPE_NEW_BITS: - r_cons_printf (" newbits=%d", record->newbits); + rz_cons_printf (" newbits=%d", record->newbits); break; case R_ANAL_ADDR_HINT_TYPE_SIZE: - r_cons_printf (" size=%"PFMT64u, record->size); + rz_cons_printf (" size=%"PFMT64u, record->size); break; case R_ANAL_ADDR_HINT_TYPE_SYNTAX: - r_cons_printf (" syntax='%s'", record->syntax); + rz_cons_printf (" syntax='%s'", record->syntax); break; case R_ANAL_ADDR_HINT_TYPE_OPTYPE: { - const char *type = r_anal_optype_to_string (record->optype); + const char *type = rz_anal_optype_to_string (record->optype); if (type) { - r_cons_printf (" type='%s'", type); + rz_cons_printf (" type='%s'", type); } break; } case R_ANAL_ADDR_HINT_TYPE_OPCODE: - r_cons_printf (" opcode='%s'", record->opcode); + rz_cons_printf (" opcode='%s'", record->opcode); break; case R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET: - r_cons_printf (" offset='%s'", record->type_offset); + rz_cons_printf (" offset='%s'", record->type_offset); break; case R_ANAL_ADDR_HINT_TYPE_ESIL: - r_cons_printf (" esil='%s'", record->esil); + rz_cons_printf (" esil='%s'", record->esil); break; case R_ANAL_ADDR_HINT_TYPE_HIGH: - r_cons_printf (" high=true"); + rz_cons_printf (" high=true"); break; case R_ANAL_ADDR_HINT_TYPE_VAL: - r_cons_printf (" val=0x%08"PFMT64x, record->val); + rz_cons_printf (" val=0x%08"PFMT64x, record->val); break; } } @@ -1094,16 +1094,16 @@ static void print_hint_h_format(HintNode *node) { } case HINT_NODE_ARCH: if (node->arch) { - r_cons_printf (" arch='%s'", node->arch); + rz_cons_printf (" arch='%s'", node->arch); } else { - r_cons_print (" arch=RESET"); + rz_cons_print (" arch=RESET"); } break; case HINT_NODE_BITS: if (node->bits) { - r_cons_printf (" bits=%d", node->bits); + rz_cons_printf (" bits=%d", node->bits); } else { - r_cons_print (" bits=RESET"); + rz_cons_print (" bits=RESET"); } break; } @@ -1113,11 +1113,11 @@ static void print_hint_h_format(HintNode *node) { static void hint_node_print(HintNode *node, int mode, PJ *pj) { switch (mode) { case '*': -#define HINTCMD_ADDR(hint,fmt,x) r_cons_printf (fmt" @ 0x%"PFMT64x"\n", x, (hint)->addr) +#define HINTCMD_ADDR(hint,fmt,x) rz_cons_printf (fmt" @ 0x%"PFMT64x"\n", x, (hint)->addr) switch (node->type) { case HINT_NODE_ADDR: { - const RAnalAddrHintRecord *record; - r_vector_foreach (node->addr_hints, record) { + const RzAnalAddrHintRecord *record; + rz_vector_foreach (node->addr_hints, record) { switch (record->type) { case R_ANAL_ADDR_HINT_TYPE_IMMBASE: HINTCMD_ADDR (node, "ahi %d", record->immbase); @@ -1150,7 +1150,7 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { HINTCMD_ADDR (node, "ahS %s", record->syntax); // TODO: escape for newcmd break; case R_ANAL_ADDR_HINT_TYPE_OPTYPE: { - const char *type = r_anal_optype_to_string (record->optype); + const char *type = rz_anal_optype_to_string (record->optype); if (type) { HINTCMD_ADDR (node, "aho %s", type); // TODO: escape for newcmd } @@ -1166,7 +1166,7 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { HINTCMD_ADDR (node, "ahe %s", record->esil); // TODO: escape for newcmd break; case R_ANAL_ADDR_HINT_TYPE_HIGH: - r_cons_printf ("ahh @ 0x%"PFMT64x"\n", node->addr); + rz_cons_printf ("ahh @ 0x%"PFMT64x"\n", node->addr); break; case R_ANAL_ADDR_HINT_TYPE_VAL: // no command for this @@ -1187,8 +1187,8 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { case 'j': switch (node->type) { case HINT_NODE_ADDR: { - const RAnalAddrHintRecord *record; - r_vector_foreach (node->addr_hints, record) { + const RzAnalAddrHintRecord *record; + rz_vector_foreach (node->addr_hints, record) { switch (record->type) { case R_ANAL_ADDR_HINT_TYPE_IMMBASE: pj_ki (pj, "immbase", record->immbase); @@ -1221,7 +1221,7 @@ static void hint_node_print(HintNode *node, int mode, PJ *pj) { pj_ks (pj, "syntax", record->syntax); break; case R_ANAL_ADDR_HINT_TYPE_OPTYPE: { - const char *type = r_anal_optype_to_string (record->optype); + const char *type = rz_anal_optype_to_string (record->optype); if (type) { pj_ks (pj, "type", type); } @@ -1279,7 +1279,7 @@ int hint_node_cmp(const void *incoming, const RBNode *in_tree, void *user) { return 0; } -bool print_addr_hint_cb(ut64 addr, const RVector/**/ *records, void *user) { +bool print_addr_hint_cb(ut64 addr, const RzVector/**/ *records, void *user) { HintNode *node = R_NEW0 (HintNode); if (!node) { return false; @@ -1287,7 +1287,7 @@ bool print_addr_hint_cb(ut64 addr, const RVector/**/ node->addr = addr; node->type = HINT_NODE_ADDR; node->addr_hints = records; - r_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); + rz_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); return true; } @@ -1299,7 +1299,7 @@ bool print_arch_hint_cb(ut64 addr, R_NULLABLE const char *arch, void *user) { node->addr = addr; node->type = HINT_NODE_ARCH; node->arch = arch; - r_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); + rz_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); return true; } @@ -1311,7 +1311,7 @@ bool print_bits_hint_cb(ut64 addr, int bits, void *user) { node->addr = addr; node->type = HINT_NODE_BITS; node->bits = bits; - r_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); + rz_rbtree_insert (user, &addr, &node->rb, hint_node_cmp, NULL); return true; } @@ -1325,13 +1325,13 @@ static void print_hint_tree(RBTree tree, int mode) { if (pj) { \ pj_end (pj); \ } else if (mode != '*') { \ - r_cons_newline (); \ + rz_cons_newline (); \ } RBIter it; HintNode *node; ut64 last_addr = 0; bool in_addr = false; - r_rbtree_foreach (tree, it, node, HintNode, rb) { + rz_rbtree_foreach (tree, it, node, HintNode, rb) { if (!in_addr || last_addr != node->addr) { if (in_addr) { END_ADDR @@ -1342,7 +1342,7 @@ static void print_hint_tree(RBTree tree, int mode) { pj_o (pj); pj_kn (pj, "addr", node->addr); } else if (mode != '*') { - r_cons_printf (" 0x%08"PFMT64x" =>", node->addr); + rz_cons_printf (" 0x%08"PFMT64x" =>", node->addr); } } hint_node_print (node, mode, pj); @@ -1354,42 +1354,42 @@ static void print_hint_tree(RBTree tree, int mode) { #undef END_ADDR if (pj) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } -R_API void r_core_anal_hint_list(RAnal *a, int mode) { +RZ_API void rz_core_anal_hint_list(RzAnal *a, int mode) { RBTree tree = NULL; // Collect all hints in the tree to sort them - r_anal_arch_hints_foreach (a, print_arch_hint_cb, &tree); - r_anal_bits_hints_foreach (a, print_bits_hint_cb, &tree); - r_anal_addr_hints_foreach (a, print_addr_hint_cb, &tree); + rz_anal_arch_hints_foreach (a, print_arch_hint_cb, &tree); + rz_anal_bits_hints_foreach (a, print_bits_hint_cb, &tree); + rz_anal_addr_hints_foreach (a, print_addr_hint_cb, &tree); print_hint_tree (tree, mode); - r_rbtree_free (tree, hint_node_free, NULL); + rz_rbtree_free (tree, hint_node_free, NULL); } -R_API void r_core_anal_hint_print(RAnal* a, ut64 addr, int mode) { +RZ_API void rz_core_anal_hint_print(RzAnal* a, ut64 addr, int mode) { RBTree tree = NULL; ut64 hint_addr = UT64_MAX; - const char *arch = r_anal_hint_arch_at(a, addr, &hint_addr); + const char *arch = rz_anal_hint_arch_at(a, addr, &hint_addr); if (hint_addr != UT64_MAX) { print_arch_hint_cb (hint_addr, arch, &tree); } - int bits = r_anal_hint_bits_at (a, addr, &hint_addr); + int bits = rz_anal_hint_bits_at (a, addr, &hint_addr); if (hint_addr != UT64_MAX) { print_bits_hint_cb (hint_addr, bits, &tree); } - const RVector *addr_hints = r_anal_addr_hints_at (a, addr); + const RzVector *addr_hints = rz_anal_addr_hints_at (a, addr); if (addr_hints) { print_addr_hint_cb (addr, addr_hints, &tree); } print_hint_tree (tree, mode); - r_rbtree_free (tree, hint_node_free, NULL); + rz_rbtree_free (tree, hint_node_free, NULL); } -static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { - int is_html = r_cons_singleton ()->is_html; +static char *core_anal_graph_label(RzCore *core, RzAnalBlock *bb, int opts) { + int is_html = rz_cons_singleton ()->is_html; int is_json = opts & R_CORE_ANAL_JSON; char cmd[1024], file[1024], *cmdstr = NULL, *filestr = NULL, *str = NULL; int line = 0, oline = 0, idx = 0; @@ -1397,9 +1397,9 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { if (opts & R_CORE_ANAL_GRAPHLINES) { for (at = bb->addr; at < bb->addr + bb->size; at += 2) { - r_bin_addr2line (core->bin, at, file, sizeof (file) - 1, &line); + rz_bin_addr2line (core->bin, at, file, sizeof (file) - 1, &line); if (line != 0 && line != oline && strcmp (file, "??")) { - filestr = r_file_slurp_line (file, line, 0); + filestr = rz_file_slurp_line (file, line, 0); if (filestr) { int flen = strlen (filestr); cmdstr = realloc (cmdstr, idx + flen + 8); @@ -1422,56 +1422,56 @@ static char *core_anal_graph_label(RCore *core, RAnalBlock *bb, int opts) { } } else if (opts & R_CORE_ANAL_STAR) { snprintf (cmd, sizeof (cmd), "pdb %"PFMT64u" @ 0x%08" PFMT64x, bb->size, bb->addr); - str = r_core_cmd_str (core, cmd); + str = rz_core_cmd_str (core, cmd); } else if (opts & R_CORE_ANAL_GRAPHBODY) { - const bool scrColor = r_config_get (core->config, "scr.color"); - const bool scrUtf8 = r_config_get (core->config, "scr.utf8"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); - r_config_set (core->config, "scr.utf8", "false"); + const bool scrColor = rz_config_get (core->config, "scr.color"); + const bool scrUtf8 = rz_config_get (core->config, "scr.utf8"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set (core->config, "scr.utf8", "false"); snprintf (cmd, sizeof (cmd), "pD %"PFMT64u" @ 0x%08" PFMT64x, bb->size, bb->addr); - cmdstr = r_core_cmd_str (core, cmd); - r_config_set_i (core->config, "scr.color", scrColor); - r_config_set_i (core->config, "scr.utf8", scrUtf8); + cmdstr = rz_core_cmd_str (core, cmd); + rz_config_set_i (core->config, "scr.color", scrColor); + rz_config_set_i (core->config, "scr.utf8", scrUtf8); } if (cmdstr) { - str = r_str_escape_dot (cmdstr); + str = rz_str_escape_dot (cmdstr); free (cmdstr); } return str; } static char *palColorFor(const char *k) { - if (!r_cons_singleton ()) { + if (!rz_cons_singleton ()) { return NULL; } - RColor rcolor = r_cons_pal_get (k); - return r_cons_rgb_tostring (rcolor.r, rcolor.g, rcolor.b); + RColor rcolor = rz_cons_pal_get (k); + return rz_cons_rgb_tostring (rcolor.r, rcolor.g, rcolor.b); } -static void core_anal_color_curr_node(RCore *core, RAnalBlock *bbi) { - bool color_current = r_config_get_i (core->config, "graph.gv.current"); +static void core_anal_color_curr_node(RzCore *core, RzAnalBlock *bbi) { + bool color_current = rz_config_get_i (core->config, "graph.gv.current"); char *pal_curr = palColorFor ("graph.current"); - bool current = r_anal_block_contains (bbi, core->offset); + bool current = rz_anal_block_contains (bbi, core->offset); if (current && color_current) { - r_cons_printf ("\t\"0x%08"PFMT64x"\" ", bbi->addr); - r_cons_printf ("\t[fillcolor=%s style=filled shape=box];\n", pal_curr); + rz_cons_printf ("\t\"0x%08"PFMT64x"\" ", bbi->addr); + rz_cons_printf ("\t[fillcolor=%s style=filled shape=box];\n", pal_curr); } free (pal_curr); } -static int core_anal_graph_construct_edges (RCore *core, RAnalFunction *fcn, int opts, PJ *pj, Sdb *DB) { - RAnalBlock *bbi; - RListIter *iter; +static int core_anal_graph_construct_edges (RzCore *core, RzAnalFunction *fcn, int opts, PJ *pj, Sdb *DB) { + RzAnalBlock *bbi; + RzListIter *iter; int is_keva = opts & R_CORE_ANAL_KEYVALUE; int is_star = opts & R_CORE_ANAL_STAR; int is_json = opts & R_CORE_ANAL_JSON; - int is_html = r_cons_singleton ()->is_html; + int is_html = rz_cons_singleton ()->is_html; char *pal_jump = palColorFor ("graph.true"); char *pal_fail = palColorFor ("graph.false"); char *pal_trfa = palColorFor ("graph.trufae"); int nodes = 0; - r_list_foreach (fcn->bbs, iter, bbi) { + rz_list_foreach (fcn->bbs, iter, bbi) { if (bbi->jump != UT64_MAX) { nodes++; if (is_keva) { @@ -1487,18 +1487,18 @@ static int core_anal_graph_construct_edges (RCore *core, RAnalFunction *fcn, int // bb..to=, sdb_set (DB, key, val, 0); } else if (is_html) { - r_cons_printf ("
\n" + rz_cons_printf ("
\n" "
\n", bbi->addr, bbi->jump); } else if (!is_json && !is_keva) { if (is_star) { char *from = get_title (bbi->addr); char *to = get_title (bbi->jump); - r_cons_printf ("age %s %s\n", from, to); + rz_cons_printf ("age %s %s\n", from, to); free(from); free(to); } else { - r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " "[color=\"%s\"];\n", bbi->addr, bbi->jump, bbi->fail != -1 ? pal_jump : pal_trfa); core_anal_color_curr_node (core, bbi); @@ -1508,47 +1508,47 @@ static int core_anal_graph_construct_edges (RCore *core, RAnalFunction *fcn, int if (bbi->fail != -1) { nodes++; if (is_html) { - r_cons_printf ("
\n" + rz_cons_printf ("
\n" "
\n", bbi->addr, bbi->fail); } else if (!is_keva && !is_json) { if (is_star) { char *from = get_title (bbi->addr); char *to = get_title (bbi->fail); - r_cons_printf ("age %s %s\n", from, to); + rz_cons_printf ("age %s %s\n", from, to); free(from); free(to); } else { - r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " "[color=\"%s\"];\n", bbi->addr, bbi->fail, pal_fail); core_anal_color_curr_node (core, bbi); } } } if (bbi->switch_op) { - RAnalCaseOp *caseop; - RListIter *iter; + RzAnalCaseOp *caseop; + RzListIter *iter; if (bbi->fail != UT64_MAX) { if (is_html) { - r_cons_printf ("
\n" + rz_cons_printf ("
\n" "
\n", bbi->addr, bbi->fail); } else if (!is_keva && !is_json) { if (is_star) { char *from = get_title (bbi->addr); char *to = get_title (bbi->fail); - r_cons_printf ("%age %s %s\n", from, to); + rz_cons_printf ("%age %s %s\n", from, to); free(from); free(to); } else { - r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " "[color=\"%s\"];\n", bbi->addr, bbi->fail, pal_fail); core_anal_color_curr_node (core, bbi); } } } - r_list_foreach (bbi->switch_op->cases, iter, caseop) { + rz_list_foreach (bbi->switch_op->cases, iter, caseop) { nodes++; if (is_keva) { char key[128]; @@ -1560,18 +1560,18 @@ static int core_anal_graph_construct_edges (RCore *core, RAnalFunction *fcn, int "bb.0x%08"PFMT64x".switch", bbi->addr); sdb_array_add_num (DB, key, caseop->value, 0); } else if (is_html) { - r_cons_printf ("
\n" + rz_cons_printf ("
\n" "
\n", caseop->addr, caseop->jump); } else if (!is_json && !is_keva){ if (is_star) { char *from = get_title (caseop->addr); char *to = get_title (caseop->jump); - r_cons_printf ("age %s %s\n", from ,to); + rz_cons_printf ("age %s %s\n", from ,to); free(from); free(to); } else { - r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " \ + rz_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " \ "[color2=\"%s\"];\n", caseop->addr, caseop->jump, pal_fail); core_anal_color_curr_node (core, bbi); } @@ -1585,13 +1585,13 @@ static int core_anal_graph_construct_edges (RCore *core, RAnalFunction *fcn, int return nodes; } -static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int opts, PJ *pj, Sdb *DB) { - RAnalBlock *bbi; - RListIter *iter; +static int core_anal_graph_construct_nodes (RzCore *core, RzAnalFunction *fcn, int opts, PJ *pj, Sdb *DB) { + RzAnalBlock *bbi; + RzListIter *iter; int is_keva = opts & R_CORE_ANAL_KEYVALUE; int is_star = opts & R_CORE_ANAL_STAR; int is_json = opts & R_CORE_ANAL_JSON; - int is_html = r_cons_singleton ()->is_html; + int is_html = rz_cons_singleton ()->is_html; int left = 300; int top = 0; @@ -1599,18 +1599,18 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int char *pal_curr = palColorFor ("graph.current"); char *pal_traced = palColorFor ("graph.traced"); char *pal_box4 = palColorFor ("graph.box4"); - const char *font = r_config_get (core->config, "graph.font"); - bool color_current = r_config_get_i (core->config, "graph.gv.current"); + const char *font = rz_config_get (core->config, "graph.font"); + bool color_current = rz_config_get_i (core->config, "graph.gv.current"); char *str; int nodes = 0; - r_list_foreach (fcn->bbs, iter, bbi) { + rz_list_foreach (fcn->bbs, iter, bbi) { if (is_keva) { char key[128]; sdb_array_push_num (DB, "bbs", bbi->addr, 0); snprintf (key, sizeof (key), "bb.0x%08"PFMT64x".size", bbi->addr); sdb_num_set (DB, key, bbi->size, 0); // bb..size= } else if (is_json) { - RDebugTracepoint *t = r_debug_trace_get (core->dbg, bbi->addr); + RzDebugTracepoint *t = rz_debug_trace_get (core->dbg, bbi->addr); ut8 *buf = malloc (bbi->size); pj_o (pj); pj_kn (pj, "offset", bbi->addr); @@ -1622,7 +1622,7 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int pj_kn (pj, "fail", bbi->fail); } if (bbi->switch_op) { - RAnalSwitchOp *op = bbi->switch_op; + RzAnalSwitchOp *op = bbi->switch_op; pj_k (pj, "switchop"); pj_o (pj); pj_kn (pj, "offset", op->addr); @@ -1631,9 +1631,9 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int pj_kn (pj, "minval", op->min_val); pj_k (pj, "cases"); pj_a (pj); - RAnalCaseOp *case_op; - RListIter *case_iter; - r_list_foreach (op->cases, case_iter, case_op) { + RzAnalCaseOp *case_op; + RzListIter *case_iter; + rz_list_foreach (op->cases, case_iter, case_op) { pj_o (pj); pj_kn (pj, "offset", case_op->addr); pj_kn (pj, "value", case_op->value); @@ -1654,11 +1654,11 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int pj_k (pj, "ops"); pj_a (pj); if (buf) { - r_io_read_at (core->io, bbi->addr, buf, bbi->size); + rz_io_read_at (core->io, bbi->addr, buf, bbi->size); if (is_json_format_disasm) { - r_core_print_disasm (core->print, core, bbi->addr, buf, bbi->size, bbi->size, 0, 1, true, pj, NULL); + rz_core_print_disasm (core->print, core, bbi->addr, buf, bbi->size, bbi->size, 0, 1, true, pj, NULL); } else { - r_core_print_disasm_json (core, bbi->addr, buf, bbi->size, 0, pj); + rz_core_print_disasm_json (core, bbi->addr, buf, bbi->size, 0, pj); } free (buf); } else { @@ -1681,28 +1681,28 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int sdb_set (DB, "label", str, 0); } else if (!is_json) { nodes++; - RConfigHold *hc = r_config_hold_new (core->config); - r_config_hold_i (hc, "scr.color", "scr.utf8", "asm.offset", "asm.lines", + RConfigHold *hc = rz_config_hold_new (core->config); + rz_config_hold_i (hc, "scr.color", "scr.utf8", "asm.offset", "asm.lines", "asm.cmt.right", "asm.lines.fcn", "asm.bytes", NULL); - RDiff *d = r_diff_new (); - r_config_set_i (core->config, "scr.utf8", 0); - r_config_set_i (core->config, "asm.offset", 0); - r_config_set_i (core->config, "asm.lines", 0); - r_config_set_i (core->config, "asm.cmt.right", 0); - r_config_set_i (core->config, "asm.lines.fcn", 0); - r_config_set_i (core->config, "asm.bytes", 0); + RzDiff *d = rz_diff_new (); + rz_config_set_i (core->config, "scr.utf8", 0); + rz_config_set_i (core->config, "asm.offset", 0); + rz_config_set_i (core->config, "asm.lines", 0); + rz_config_set_i (core->config, "asm.cmt.right", 0); + rz_config_set_i (core->config, "asm.lines.fcn", 0); + rz_config_set_i (core->config, "asm.bytes", 0); if (!is_star) { - r_config_set_i (core->config, "scr.color", 0); // disable color for dot + rz_config_set_i (core->config, "scr.color", 0); // disable color for dot } if (bbi->diff && bbi->diff->type != R_ANAL_DIFF_TYPE_MATCH && core->c2) { - RCore *c = core->c2; + RzCore *c = core->c2; RConfig *oc = c->config; - char *str = r_core_cmd_strf (core, "pdb @ 0x%08"PFMT64x, bbi->addr); + char *str = rz_core_cmd_strf (core, "pdb @ 0x%08"PFMT64x, bbi->addr); c->config = core->config; // XXX. the bbi->addr doesnt needs to be in the same address in core2 - char *str2 = r_core_cmd_strf (c, "pdb @ 0x%08"PFMT64x, bbi->diff->addr); - char *diffstr = r_diff_buffers_to_string (d, + char *str2 = rz_core_cmd_strf (c, "pdb @ 0x%08"PFMT64x, bbi->diff->addr); + char *diffstr = rz_diff_buffers_to_string (d, (const ut8*)str, strlen (str), (const ut8*)str2, strlen (str2)); @@ -1713,7 +1713,7 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int if (nl) { nl = strchr (nl + 1, '\n'); if (nl) { - r_str_cpy (diffstr, nl + 1); + rz_str_cpy (diffstr, nl + 1); } } } @@ -1721,21 +1721,21 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int if (is_star) { char *title = get_title (bbi->addr); - char *body_b64 = r_base64_encode_dyn (diffstr, -1); + char *body_b64 = rz_base64_encode_dyn (diffstr, -1); if (!title || !body_b64) { free (body_b64); free (title); - r_diff_free (d); + rz_diff_free (d); return false; } - body_b64 = r_str_prepend (body_b64, "base64:"); - r_cons_printf ("agn %s %s %d\n", title, body_b64, bbi->diff->type); + body_b64 = rz_str_prepend (body_b64, "base64:"); + rz_cons_printf ("agn %s %s %d\n", title, body_b64, bbi->diff->type); free (body_b64); free (title); } else { - diffstr = r_str_replace (diffstr, "\n", "\\l", 1); - diffstr = r_str_replace (diffstr, "\"", "'", 1); - r_cons_printf(" \"0x%08"PFMT64x"\" [fillcolor=\"%s\"," + diffstr = rz_str_replace (diffstr, "\n", "\\l", 1); + diffstr = rz_str_replace (diffstr, "\"", "'", 1); + rz_cons_printf(" \"0x%08"PFMT64x"\" [fillcolor=\"%s\"," "color=\"black\", fontname=\"Courier\"," " label=\"%s\", URL=\"%s/0x%08"PFMT64x"\"]\n", bbi->addr, difftype, diffstr, fcn->name, @@ -1746,33 +1746,33 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int } else { if (is_star) { char *title = get_title (bbi->addr); - char *body_b64 = r_base64_encode_dyn (str, -1); + char *body_b64 = rz_base64_encode_dyn (str, -1); int color = (bbi && bbi->diff) ? bbi->diff->type : 0; if (!title || !body_b64) { free (body_b64); free (title); - r_diff_free (d); + rz_diff_free (d); return false; } - body_b64 = r_str_prepend (body_b64, "base64:"); - r_cons_printf ("agn %s %s %d\n", title, body_b64, color); + body_b64 = rz_str_prepend (body_b64, "base64:"); + rz_cons_printf ("agn %s %s %d\n", title, body_b64, color); free (body_b64); free (title); } else { - r_cons_printf(" \"0x%08"PFMT64x"\" [fillcolor=\"%s\"," + rz_cons_printf(" \"0x%08"PFMT64x"\" [fillcolor=\"%s\"," "color=\"black\", fontname=\"Courier\"," " label=\"%s\", URL=\"%s/0x%08"PFMT64x"\"]\n", bbi->addr, difftype, str, fcn->name, bbi->addr); } } - r_diff_free (d); - r_config_set_i (core->config, "scr.color", 1); - r_config_hold_free (hc); + rz_diff_free (d); + rz_config_set_i (core->config, "scr.color", 1); + rz_config_hold_free (hc); } } else { if (is_html) { nodes++; - r_cons_printf ("

\n%s

\n", top, left, bbi->addr, str); @@ -1781,7 +1781,7 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int top += 250; } } else if (!is_json && !is_keva) { - bool current = r_anal_block_contains (bbi, core->offset); + bool current = rz_anal_block_contains (bbi, core->offset); const char *label_color = bbi->traced ? pal_traced : (current && color_current) @@ -1791,19 +1791,19 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int nodes++; if (is_star) { char *title = get_title (bbi->addr); - char *body_b64 = r_base64_encode_dyn (str, -1); + char *body_b64 = rz_base64_encode_dyn (str, -1); int color = (bbi && bbi->diff) ? bbi->diff->type : 0; if (!title || !body_b64) { free (body_b64); free (title); return false; } - body_b64 = r_str_prepend (body_b64, "base64:"); - r_cons_printf ("agn %s %s %d\n", title, body_b64, color); + body_b64 = rz_str_prepend (body_b64, "base64:"); + rz_cons_printf ("agn %s %s %d\n", title, body_b64, color); free (body_b64); free (title); } else { - r_cons_printf ("\t\"0x%08"PFMT64x"\" [" + rz_cons_printf ("\t\"0x%08"PFMT64x"\" [" "URL=\"%s/0x%08"PFMT64x"\", fillcolor=\"%s\"," "color=\"%s\", fontname=\"%s\"," "label=\"%s\"]\n", @@ -1818,7 +1818,7 @@ static int core_anal_graph_construct_nodes (RCore *core, RAnalFunction *fcn, int return nodes; } -static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ *pj) { +static int core_anal_graph_nodes(RzCore *core, RzAnalFunction *fcn, int opts, PJ *pj) { int is_json = opts & R_CORE_ANAL_JSON; int is_keva = opts & R_CORE_ANAL_KEYVALUE; int nodes = 0; @@ -1846,31 +1846,31 @@ static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ * sdb_set (DB, "name", fcn->name, 0); sdb_set (DB, "ename", ename, 0); free (ename); - sdb_num_set (DB, "size", r_anal_function_linear_size (fcn), 0); + sdb_num_set (DB, "size", rz_anal_function_linear_size (fcn), 0); if (fcn->maxstack > 0) { sdb_num_set (DB, "stack", fcn->maxstack, 0); } sdb_set (DB, "pos", "0,0", 0); // needs to run layout - sdb_set (DB, "type", r_anal_fcntype_tostring (fcn->type), 0); + sdb_set (DB, "type", rz_anal_fcntype_tostring (fcn->type), 0); } else if (is_json) { // TODO: show vars, refs and xrefs - char *fcn_name_escaped = r_str_escape_utf8_for_json (fcn->name, -1); + char *fcn_name_escaped = rz_str_escape_utf8_for_json (fcn->name, -1); pj_o (pj); - pj_ks (pj, "name", r_str_get (fcn_name_escaped)); + pj_ks (pj, "name", rz_str_get (fcn_name_escaped)); free (fcn_name_escaped); pj_kn (pj, "offset", fcn->addr); pj_ki (pj, "ninstr", fcn->ninstr); pj_ki (pj, "nargs", - r_anal_var_count (core->anal, fcn, 'r', 1) + - r_anal_var_count (core->anal, fcn, 's', 1) + - r_anal_var_count (core->anal, fcn, 'b', 1)); + rz_anal_var_count (core->anal, fcn, 'r', 1) + + rz_anal_var_count (core->anal, fcn, 's', 1) + + rz_anal_var_count (core->anal, fcn, 'b', 1)); pj_ki (pj, "nlocals", - r_anal_var_count (core->anal, fcn, 'r', 0) + - r_anal_var_count (core->anal, fcn, 's', 0) + - r_anal_var_count (core->anal, fcn, 'b', 0)); - pj_kn (pj, "size", r_anal_function_linear_size (fcn)); + rz_anal_var_count (core->anal, fcn, 'r', 0) + + rz_anal_var_count (core->anal, fcn, 's', 0) + + rz_anal_var_count (core->anal, fcn, 'b', 0)); + pj_kn (pj, "size", rz_anal_function_linear_size (fcn)); pj_ki (pj, "stack", fcn->maxstack); - pj_ks (pj, "type", r_anal_fcntype_tostring (fcn->type)); + pj_ks (pj, "type", rz_anal_fcntype_tostring (fcn->type)); pj_k (pj, "blocks"); pj_a (pj); } @@ -1891,21 +1891,21 @@ static int core_anal_graph_nodes(RCore *core, RAnalFunction *fcn, int opts, PJ * /* seek basic block that contains address addr or just addr if there's no such * basic block */ -R_API bool r_core_anal_bb_seek(RCore *core, ut64 addr) { - ut64 bbaddr = r_anal_get_bbaddr (core->anal, addr); +RZ_API bool rz_core_anal_bb_seek(RzCore *core, ut64 addr) { + ut64 bbaddr = rz_anal_get_bbaddr (core->anal, addr); if (bbaddr != UT64_MAX) { - r_core_seek (core, bbaddr, false); + rz_core_seek (core, bbaddr, false); return true; } return false; } -R_API int r_core_anal_esil_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth) { +RZ_API int rz_core_anal_esil_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth) { const char *esil; eprintf ("TODO\n"); while (1) { // TODO: Implement the proper logic for doing esil analysis - RAnalOp *op = r_core_anal_op (core, at, R_ANAL_OP_MASK_ESIL); + RzAnalOp *op = rz_core_anal_op (core, at, R_ANAL_OP_MASK_ESIL); if (!op) { break; } @@ -1915,34 +1915,34 @@ R_API int r_core_anal_esil_fcn(RCore *core, ut64 at, ut64 from, int reftype, int // esilIsRet() // esilIsCall() // esilIsJmp() - r_anal_op_free (op); + rz_anal_op_free (op); break; } return 0; } static int find_sym_flag(const void *a1, const void *a2) { - const RFlagItem *f = (const RFlagItem *)a2; + const RzFlagItem *f = (const RzFlagItem *)a2; return f->space && !strcmp (f->space->name, R_FLAGS_FS_SYMBOLS)? 0: 1; } -static bool is_skippable_addr(RCore *core, ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); +static bool is_skippable_addr(RzCore *core, ut64 addr) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (!fcn) { return false; } if (fcn->addr == addr) { return true; } - const RList *flags = r_flag_get_list (core->flags, addr); - return !(flags && r_list_find (flags, fcn, find_sym_flag)); + const RzList *flags = rz_flag_get_list (core->flags, addr); + return !(flags && rz_list_find (flags, fcn, find_sym_flag)); } // XXX: This function takes sometimes forever -/* analyze a RAnalFunction at the address 'at'. +/* analyze a RzAnalFunction at the address 'at'. * If the function has been already analyzed, it adds a * reference to that fcn */ -R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth) { +RZ_API int rz_core_anal_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth) { if (from == UT64_MAX && is_skippable_addr (core, at)) { if (core->anal->verbose) { eprintf ("Message: Invalid address for function 0x%08"PFMT64x"\n", at); @@ -1950,27 +1950,27 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept return 0; } - const bool use_esil = r_config_get_i (core->config, "anal.esil"); - RAnalFunction *fcn; + const bool use_esil = rz_config_get_i (core->config, "anal.esil"); + RzAnalFunction *fcn; //update bits based on the core->offset otherwise we could have the //last value set and blow everything up - r_core_seek_arch_bits (core, at); + rz_core_seek_arch_bits (core, at); if (core->io->va) { - if (!r_io_is_valid_offset (core->io, at, !core->anal->opt.noncode)) { + if (!rz_io_is_valid_offset (core->io, at, !core->anal->opt.noncode)) { if (core->anal->verbose) { eprintf ("Warning: Address not mapped or not executable at 0x%08"PFMT64x"\n", at); } return false; } } - if (r_config_get_i (core->config, "anal.a2f")) { - r_core_cmd0 (core, ".a2f"); + if (rz_config_get_i (core->config, "anal.a2f")) { + rz_core_cmd0 (core, ".a2f"); return 0; } if (use_esil) { - return r_core_anal_esil_fcn (core, at, from, reftype, depth); + return rz_core_anal_esil_fcn (core, at, from, reftype, depth); } if ((from != UT64_MAX && !at) || at == UT64_MAX) { @@ -1983,10 +1983,10 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept } return false; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { return false; } - fcn = r_anal_get_fcn_in (core->anal, at, 0); + fcn = rz_anal_get_fcn_in (core->anal, at, 0); if (fcn) { if (fcn->addr == at) { // if the function was already analyzed as a "loc.", @@ -1998,17 +1998,17 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept return 0; // already analyzed function } - if (r_anal_function_contains (fcn, from)) { // inner function - RList *l = r_anal_xrefs_get (core->anal, from); - if (l && !r_list_empty (l)) { - r_list_free (l); + if (rz_anal_function_contains (fcn, from)) { // inner function + RzList *l = rz_anal_xrefs_get (core->anal, from); + if (l && !rz_list_empty (l)) { + rz_list_free (l); return true; } - r_list_free (l); + rz_list_free (l); // we should analyze and add code ref otherwise aaa != aac if (from != UT64_MAX) { - r_anal_xrefs_set (core->anal, from, at, reftype); + rz_anal_xrefs_set (core->anal, from, at, reftype); } return true; } @@ -2016,7 +2016,7 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept if (__core_anal_fcn (core, at, from, reftype, depth - 1)) { // split function if overlaps if (fcn) { - r_anal_function_resize (fcn, at - fcn->addr); + rz_anal_function_resize (fcn, at - fcn->addr); } return true; } @@ -2025,91 +2025,91 @@ R_API int r_core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int dept /* if addr is 0, remove all functions * otherwise remove the function addr falls into */ -R_API int r_core_anal_fcn_clean(RCore *core, ut64 addr) { - RAnalFunction *fcni; - RListIter *iter, *iter_tmp; +RZ_API int rz_core_anal_fcn_clean(RzCore *core, ut64 addr) { + RzAnalFunction *fcni; + RzListIter *iter, *iter_tmp; if (!addr) { - r_list_purge (core->anal->fcns); - if (!(core->anal->fcns = r_list_new ())) { + rz_list_purge (core->anal->fcns); + if (!(core->anal->fcns = rz_list_new ())) { return false; } } else { - r_list_foreach_safe (core->anal->fcns, iter, iter_tmp, fcni) { - if (r_anal_function_contains (fcni, addr)) { - r_anal_function_delete (fcni); + rz_list_foreach_safe (core->anal->fcns, iter, iter_tmp, fcni) { + if (rz_anal_function_contains (fcni, addr)) { + rz_anal_function_delete (fcni); } } } return true; } -R_API int r_core_print_bb_custom(RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *iter; +RZ_API int rz_core_print_bb_custom(RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *iter; if (!fcn) { return false; } - RConfigHold *hc = r_config_hold_new (core->config); - r_config_hold_i (hc, "scr.color", "scr.utf8", "asm.marks", "asm.offset", "asm.lines", + RConfigHold *hc = rz_config_hold_new (core->config); + rz_config_hold_i (hc, "scr.color", "scr.utf8", "asm.marks", "asm.offset", "asm.lines", "asm.cmt.right", "asm.cmt.col", "asm.lines.fcn", "asm.bytes", NULL); - /*r_config_set_i (core->config, "scr.color", 0);*/ - r_config_set_i (core->config, "scr.utf8", 0); - r_config_set_i (core->config, "asm.marks", 0); - r_config_set_i (core->config, "asm.offset", 0); - r_config_set_i (core->config, "asm.lines", 0); - r_config_set_i (core->config, "asm.cmt.right", 0); - r_config_set_i (core->config, "asm.cmt.col", 0); - r_config_set_i (core->config, "asm.lines.fcn", 0); - r_config_set_i (core->config, "asm.bytes", 0); + /*rz_config_set_i (core->config, "scr.color", 0);*/ + rz_config_set_i (core->config, "scr.utf8", 0); + rz_config_set_i (core->config, "asm.marks", 0); + rz_config_set_i (core->config, "asm.offset", 0); + rz_config_set_i (core->config, "asm.lines", 0); + rz_config_set_i (core->config, "asm.cmt.right", 0); + rz_config_set_i (core->config, "asm.cmt.col", 0); + rz_config_set_i (core->config, "asm.lines.fcn", 0); + rz_config_set_i (core->config, "asm.bytes", 0); - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } char *title = get_title (bb->addr); - char *body = r_core_cmd_strf (core, "pdb @ 0x%08"PFMT64x, bb->addr); - char *body_b64 = r_base64_encode_dyn (body, -1); + char *body = rz_core_cmd_strf (core, "pdb @ 0x%08"PFMT64x, bb->addr); + char *body_b64 = rz_base64_encode_dyn (body, -1); if (!title || !body || !body_b64) { free (body_b64); free (body); free (title); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return false; } - body_b64 = r_str_prepend (body_b64, "base64:"); - r_cons_printf ("agn %s %s\n", title, body_b64); + body_b64 = rz_str_prepend (body_b64, "base64:"); + rz_cons_printf ("agn %s %s\n", title, body_b64); free (body); free (body_b64); free (title); } - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } char *u = get_title (bb->addr), *v = NULL; if (bb->jump != UT64_MAX) { v = get_title (bb->jump); - r_cons_printf ("age %s %s\n", u, v); + rz_cons_printf ("age %s %s\n", u, v); free (v); } if (bb->fail != UT64_MAX) { v = get_title (bb->fail); - r_cons_printf ("age %s %s\n", u, v); + rz_cons_printf ("age %s %s\n", u, v); free (v); } if (bb->switch_op) { - RListIter *it; - RAnalCaseOp *cop; - r_list_foreach (bb->switch_op->cases, it, cop) { + RzListIter *it; + RzAnalCaseOp *cop; + rz_list_foreach (bb->switch_op->cases, it, cop) { v = get_title (cop->addr); - r_cons_printf ("age %s %s\n", u, v); + rz_cons_printf ("age %s %s\n", u, v); free (v); } } @@ -2119,9 +2119,9 @@ R_API int r_core_print_bb_custom(RCore *core, RAnalFunction *fcn) { } #define USE_ID 1 -R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *iter; +RZ_API int rz_core_print_bb_gml(RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *iter; if (!fcn) { return false; } @@ -2129,20 +2129,20 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { HtUUOptions opt = { 0 }; HtUU *ht = ht_uu_new_opt (&opt); - r_cons_printf ("graph\n[\n" "hierarchic 1\n" "label \"\"\n" "directed 1\n"); + rz_cons_printf ("graph\n[\n" "hierarchic 1\n" "label \"\"\n" "directed 1\n"); - r_list_foreach (fcn->bbs, iter, bb) { - RFlagItem *flag = r_flag_get_i (core->flags, bb->addr); - char *msg = flag? strdup (flag->name): r_str_newf ("0x%08"PFMT64x, bb->addr); + rz_list_foreach (fcn->bbs, iter, bb) { + RzFlagItem *flag = rz_flag_get_i (core->flags, bb->addr); + char *msg = flag? strdup (flag->name): rz_str_newf ("0x%08"PFMT64x, bb->addr); #if USE_ID ht_uu_insert (ht, bb->addr, id); - r_cons_printf (" node [\n" + rz_cons_printf (" node [\n" " id %d\n" " label \"%s\"\n" " ]\n", id, msg); id++; #else - r_cons_printf (" node [\n" + rz_cons_printf (" node [\n" " id %"PFMT64d"\n" " label \"%s\"\n" " ]\n", bb->addr, msg); @@ -2150,7 +2150,7 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { free (msg); } - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (bb->addr == UT64_MAX) { continue; } @@ -2162,7 +2162,7 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { if (found) { int i2 = ht_uu_find (ht, bb->jump, &found); if (found) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %d\n" " target %d\n" " ]\n", i, i2); @@ -2175,7 +2175,7 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { if (found) { int i2 = ht_uu_find (ht, bb->fail, &found); if (found) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %d\n" " target %d\n" " ]\n", i, i2); @@ -2183,15 +2183,15 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { } } if (bb->switch_op) { - RListIter *it; - RAnalCaseOp *cop; - r_list_foreach (bb->switch_op->cases, it, cop) { + RzListIter *it; + RzAnalCaseOp *cop; + rz_list_foreach (bb->switch_op->cases, it, cop) { bool found; int i = ht_uu_find (ht, bb->addr, &found); if (found) { int i2 = ht_uu_find (ht, cop->addr, &found); if (found) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %d\n" " target %d\n" " ]\n", i, i2); @@ -2201,24 +2201,24 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { } #else if (bb->jump != UT64_MAX) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %"PFMT64d"\n" " target %"PFMT64d"\n" " ]\n", bb->addr, bb->jump ); } if (bb->fail != UT64_MAX) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %"PFMT64d"\n" " target %"PFMT64d"\n" " ]\n", bb->addr, bb->fail ); } if (bb->switch_op) { - RListIter *it; - RAnalCaseOp *cop; - r_list_foreach (bb->switch_op->cases, it, cop) { - r_cons_printf (" edge [\n" + RzListIter *it; + RzAnalCaseOp *cop; + rz_list_foreach (bb->switch_op->cases, it, cop) { + rz_cons_printf (" edge [\n" " source %"PFMT64d"\n" " target %"PFMT64d"\n" " ]\n", bb->addr, cop->addr @@ -2227,133 +2227,133 @@ R_API int r_core_print_bb_gml(RCore *core, RAnalFunction *fcn) { } #endif } - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); ht_uu_free (ht); return true; } -R_API void r_core_anal_datarefs(RCore *core, ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1); +RZ_API void rz_core_anal_datarefs(RzCore *core, ut64 addr) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, -1); if (fcn) { bool found = false; const char *me = fcn->name; - RListIter *iter; - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { - RBinObject *obj = r_bin_cur_object (core->bin); - RBinSection *binsec = r_bin_get_section_at (obj, ref->addr, true); + RzListIter *iter; + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { + RBinObject *obj = rz_bin_cur_object (core->bin); + RBinSection *binsec = rz_bin_get_section_at (obj, ref->addr, true); if (binsec && binsec->is_data) { if (!found) { - r_cons_printf ("agn %s\n", me); + rz_cons_printf ("agn %s\n", me); found = true; } - RFlagItem *item = r_flag_get_i (core->flags, ref->addr); + RzFlagItem *item = rz_flag_get_i (core->flags, ref->addr); const char *dst = item? item->name: sdb_fmt ("0x%08"PFMT64x, ref->addr); - r_cons_printf ("agn %s\n", dst); - r_cons_printf ("age %s %s\n", me, dst); + rz_cons_printf ("agn %s\n", dst); + rz_cons_printf ("age %s %s\n", me, dst); } } - r_list_free (refs); + rz_list_free (refs); } else { eprintf ("Not in a function. Use 'df' to define it.\n"); } } -R_API void r_core_anal_coderefs(RCore *core, ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1); +RZ_API void rz_core_anal_coderefs(RzCore *core, ut64 addr) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, -1); if (fcn) { const char *me = fcn->name; - RListIter *iter; - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); - r_cons_printf ("agn %s\n", me); - r_list_foreach (refs, iter, ref) { - RFlagItem *item = r_flag_get_i (core->flags, ref->addr); + RzListIter *iter; + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_cons_printf ("agn %s\n", me); + rz_list_foreach (refs, iter, ref) { + RzFlagItem *item = rz_flag_get_i (core->flags, ref->addr); const char *dst = item? item->name: sdb_fmt ("0x%08"PFMT64x, ref->addr); - r_cons_printf ("agn %s\n", dst); - r_cons_printf ("age %s %s\n", me, dst); + rz_cons_printf ("agn %s\n", dst); + rz_cons_printf ("age %s %s\n", me, dst); } - r_list_free (refs); + rz_list_free (refs); } else { eprintf("Not in a function. Use 'df' to define it.\n"); } } -R_API void r_core_anal_importxrefs(RCore *core) { - RBinInfo *info = r_bin_get_info (core->bin); - RBinObject *obj = r_bin_cur_object (core->bin); +RZ_API void rz_core_anal_importxrefs(RzCore *core) { + RBinInfo *info = rz_bin_get_info (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); bool lit = info ? info->has_lit: false; bool va = core->io->va || core->bin->is_debugger; - RListIter *iter; + RzListIter *iter; RBinImport *imp; if (!obj) { return; } - r_list_foreach (obj->imports, iter, imp) { - ut64 addr = lit ? r_core_bin_impaddr (core->bin, va, imp->name): 0; + rz_list_foreach (obj->imports, iter, imp) { + ut64 addr = lit ? rz_core_bin_impaddr (core->bin, va, imp->name): 0; if (addr) { - r_core_anal_codexrefs (core, addr); + rz_core_anal_codexrefs (core, addr); } else { - r_cons_printf ("agn %s\n", imp->name); + rz_cons_printf ("agn %s\n", imp->name); } } } -R_API void r_core_anal_codexrefs(RCore *core, ut64 addr) { - RFlagItem *f = r_flag_get_at (core->flags, addr, false); +RZ_API void rz_core_anal_codexrefs(RzCore *core, ut64 addr) { + RzFlagItem *f = rz_flag_get_at (core->flags, addr, false); char *me = (f && f->offset == addr) - ? r_str_new (f->name) : r_str_newf ("0x%"PFMT64x, addr); - r_cons_printf ("agn %s\n", me); - RListIter *iter; - RAnalRef *ref; - RList *list = r_anal_xrefs_get (core->anal, addr); - r_list_foreach (list, iter, ref) { - RFlagItem *item = r_flag_get_i (core->flags, ref->addr); + ? rz_str_new (f->name) : rz_str_newf ("0x%"PFMT64x, addr); + rz_cons_printf ("agn %s\n", me); + RzListIter *iter; + RzAnalRef *ref; + RzList *list = rz_anal_xrefs_get (core->anal, addr); + rz_list_foreach (list, iter, ref) { + RzFlagItem *item = rz_flag_get_i (core->flags, ref->addr); const char *src = item? item->name: sdb_fmt ("0x%08"PFMT64x, ref->addr); - r_cons_printf ("agn %s\n", src); - r_cons_printf ("age %s %s\n", src, me); + rz_cons_printf ("agn %s\n", src); + rz_cons_printf ("age %s %s\n", src, me); } - r_list_free (list); + rz_list_free (list); free (me); } -static int RAnalRef_cmp(const RAnalRef* ref1, const RAnalRef* ref2) { +static int RzAnalRef_cmp(const RzAnalRef* ref1, const RzAnalRef* ref2) { return ref1->addr != ref2->addr; } -R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt) { - const char *font = r_config_get (core->config, "graph.font"); - int is_html = r_cons_singleton ()->is_html; - bool refgraph = r_config_get_i (core->config, "graph.refs"); +RZ_API void rz_core_anal_callgraph(RzCore *core, ut64 addr, int fmt) { + const char *font = rz_config_get (core->config, "graph.font"); + int is_html = rz_cons_singleton ()->is_html; + bool refgraph = rz_config_get_i (core->config, "graph.refs"); int first, first2; - RListIter *iter, *iter2; - int usenames = r_config_get_i (core->config, "graph.json.usenames");; - RAnalFunction *fcni; - RAnalRef *fcnr; + RzListIter *iter, *iter2; + int usenames = rz_config_get_i (core->config, "graph.json.usenames");; + RzAnalFunction *fcni; + RzAnalRef *fcnr; - ut64 from = r_config_get_i (core->config, "graph.from"); - ut64 to = r_config_get_i (core->config, "graph.to"); + ut64 from = rz_config_get_i (core->config, "graph.from"); + ut64 to = rz_config_get_i (core->config, "graph.to"); switch (fmt) { case R_GRAPH_FORMAT_JSON: - r_cons_printf ("["); + rz_cons_printf ("["); break; case R_GRAPH_FORMAT_GML: case R_GRAPH_FORMAT_GMLFCN: - r_cons_printf ("graph\n[\n" + rz_cons_printf ("graph\n[\n" "hierarchic 1\n" "label \"\"\n" "directed 1\n"); break; case R_GRAPH_FORMAT_DOT: if (!is_html) { - const char * gv_edge = r_config_get (core->config, "graph.gv.edge"); - const char * gv_node = r_config_get (core->config, "graph.gv.node"); - const char * gv_grph = r_config_get (core->config, "graph.gv.graph"); - const char * gv_spline = r_config_get (core->config, "graph.gv.spline"); + const char * gv_edge = rz_config_get (core->config, "graph.gv.edge"); + const char * gv_node = rz_config_get (core->config, "graph.gv.node"); + const char * gv_grph = rz_config_get (core->config, "graph.gv.graph"); + const char * gv_spline = rz_config_get (core->config, "graph.gv.spline"); if (!gv_edge || !*gv_edge) { gv_edge = "arrowhead=\"normal\" style=bold weight=2"; } @@ -2367,7 +2367,7 @@ R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt) { // ortho for bbgraph and curved for callgraph gv_spline = "splines=\"curved\""; } - r_cons_printf ("digraph code {\n" + rz_cons_printf ("digraph code {\n" "rankdir=LR;\n" "outputorder=edgesfirst;\n" "graph [%s fontname=\"%s\" %s];\n" @@ -2381,7 +2381,7 @@ R_API void r_core_anal_callgraph(RCore *core, ut64 addr, int fmt) { ut64 base = UT64_MAX; int iteration = 0; repeat: - r_list_foreach (core->anal->fcns, iter, fcni) { + rz_list_foreach (core->anal->fcns, iter, fcni) { if (base == UT64_MAX) { base = fcni->addr; } @@ -2394,30 +2394,30 @@ repeat: if (addr != UT64_MAX && addr != fcni->addr) { continue; } - RList *refs = r_anal_function_get_refs (fcni); - RList *calls = r_list_new (); + RzList *refs = rz_anal_function_get_refs (fcni); + RzList *calls = rz_list_new (); // TODO: maybe fcni->calls instead ? - r_list_foreach (refs, iter2, fcnr) { + rz_list_foreach (refs, iter2, fcnr) { // TODO: tail calll jumps are also calls - if (fcnr->type == 'C' && r_list_find(calls, fcnr, (RListComparator)RAnalRef_cmp) == NULL) { - r_list_append (calls, fcnr); + if (fcnr->type == 'C' && rz_list_find(calls, fcnr, (RzListComparator)RzAnalRef_cmp) == NULL) { + rz_list_append (calls, fcnr); } } - if (r_list_empty(calls)) { - r_list_free (refs); - r_list_free (calls); + if (rz_list_empty(calls)) { + rz_list_free (refs); + rz_list_free (calls); continue; } switch (fmt) { case R_GRAPH_FORMAT_NO: - r_cons_printf ("0x%08"PFMT64x"\n", fcni->addr); + rz_cons_printf ("0x%08"PFMT64x"\n", fcni->addr); break; case R_GRAPH_FORMAT_GML: case R_GRAPH_FORMAT_GMLFCN: { - RFlagItem *flag = r_flag_get_i (core->flags, fcni->addr); + RzFlagItem *flag = rz_flag_get_i (core->flags, fcni->addr); if (iteration == 0) { - char *msg = flag? strdup (flag->name): r_str_newf ("0x%08"PFMT64x, fcni->addr); - r_cons_printf (" node [\n" + char *msg = flag? strdup (flag->name): rz_str_newf ("0x%08"PFMT64x, fcni->addr); + rz_cons_printf (" node [\n" " id %"PFMT64d"\n" " label \"%s\"\n" " ]\n", fcni->addr - base, msg); @@ -2427,59 +2427,59 @@ repeat: } case R_GRAPH_FORMAT_JSON: if (usenames) { - r_cons_printf ("%s{\"name\":\"%s\", " + rz_cons_printf ("%s{\"name\":\"%s\", " "\"size\":%d,\"imports\":[", first ? "," : "", fcni->name, - r_anal_function_linear_size (fcni)); + rz_anal_function_linear_size (fcni)); } else { - r_cons_printf ("%s{\"name\":\"0x%08" PFMT64x + rz_cons_printf ("%s{\"name\":\"0x%08" PFMT64x "\", \"size\":%d,\"imports\":[", first ? "," : "", fcni->addr, - r_anal_function_linear_size (fcni)); + rz_anal_function_linear_size (fcni)); } first = 1; break; case R_GRAPH_FORMAT_DOT: - r_cons_printf (" \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" " "[label=\"%s\"" " URL=\"%s/0x%08"PFMT64x"\"];\n", fcni->addr, fcni->name, fcni->name, fcni->addr); } first2 = 0; - r_list_foreach (calls, iter2, fcnr) { + rz_list_foreach (calls, iter2, fcnr) { // TODO: display only code or data refs? - RFlagItem *flag = r_flag_get_i (core->flags, fcnr->addr); - char *fcnr_name = (flag && flag->name) ? flag->name : r_str_newf ("unk.0x%"PFMT64x, fcnr->addr); + RzFlagItem *flag = rz_flag_get_i (core->flags, fcnr->addr); + char *fcnr_name = (flag && flag->name) ? flag->name : rz_str_newf ("unk.0x%"PFMT64x, fcnr->addr); switch(fmt) { case R_GRAPH_FORMAT_GMLFCN: if (iteration == 0) { - r_cons_printf (" node [\n" + rz_cons_printf (" node [\n" " id %"PFMT64d"\n" " label \"%s\"\n" " ]\n", fcnr->addr - base, fcnr_name); - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %"PFMT64d"\n" " target %"PFMT64d"\n" " ]\n", fcni->addr-base, fcnr->addr-base); } case R_GRAPH_FORMAT_GML: if (iteration != 0) { - r_cons_printf (" edge [\n" + rz_cons_printf (" edge [\n" " source %"PFMT64d"\n" " target %"PFMT64d"\n" " ]\n", fcni->addr-base, fcnr->addr-base); //, "#000000" } break; case R_GRAPH_FORMAT_DOT: - r_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" " "[color=\"%s\" URL=\"%s/0x%08"PFMT64x"\"];\n", //"[label=\"%s\" color=\"%s\" URL=\"%s/0x%08"PFMT64x"\"];\n", fcni->addr, fcnr->addr, //, fcnr_name, "#61afef", fcnr_name, fcnr->addr); - r_cons_printf (" \"0x%08"PFMT64x"\" " + rz_cons_printf (" \"0x%08"PFMT64x"\" " "[label=\"%s\"" " URL=\"%s/0x%08"PFMT64x"\"];\n", fcnr->addr, fcnr_name, @@ -2487,20 +2487,20 @@ repeat: break; case R_GRAPH_FORMAT_JSON: if (usenames) { - r_cons_printf ("%s\"%s\"", first2?",":"", fcnr_name); + rz_cons_printf ("%s\"%s\"", first2?",":"", fcnr_name); } else { - r_cons_printf ("%s\"0x%08"PFMT64x"\"", first2?",":"", fcnr_name); + rz_cons_printf ("%s\"0x%08"PFMT64x"\"", first2?",":"", fcnr_name); } break; default: if (refgraph || fcnr->type == R_ANAL_REF_TYPE_CALL) { // TODO: avoid recreating nodes unnecessarily - r_cons_printf ("agn %s\n", fcni->name); - r_cons_printf ("agn %s\n", fcnr_name); - r_cons_printf ("age %s %s\n", fcni->name, fcnr_name); + rz_cons_printf ("agn %s\n", fcni->name); + rz_cons_printf ("agn %s\n", fcnr_name); + rz_cons_printf ("age %s %s\n", fcni->name, fcnr_name); } else { - r_cons_printf ("# - 0x%08"PFMT64x" (%c)\n", fcnr->addr, fcnr->type); + rz_cons_printf ("# - 0x%08"PFMT64x" (%c)\n", fcnr->addr, fcnr->type); } } if (!(flag && flag->name)) { @@ -2508,10 +2508,10 @@ repeat: } first2 = 1; } - r_list_free (refs); - r_list_free (calls); + rz_list_free (refs); + rz_list_free (calls); if (fmt == R_GRAPH_FORMAT_JSON) { - r_cons_printf ("]}"); + rz_cons_printf ("]}"); } } if (iteration == 0 && fmt == R_GRAPH_FORMAT_GML) { @@ -2526,82 +2526,82 @@ repeat: case R_GRAPH_FORMAT_GML: case R_GRAPH_FORMAT_GMLFCN: case R_GRAPH_FORMAT_JSON: - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); break; case R_GRAPH_FORMAT_DOT: - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); break; } } -static void fcn_list_bbs(RAnalFunction *fcn) { - RAnalBlock *bbi; - RListIter *iter; +static void fcn_list_bbs(RzAnalFunction *fcn) { + RzAnalBlock *bbi; + RzListIter *iter; - r_list_foreach (fcn->bbs, iter, bbi) { - r_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %d ", + rz_list_foreach (fcn->bbs, iter, bbi) { + rz_cons_printf ("afb+ 0x%08" PFMT64x " 0x%08" PFMT64x " %d ", fcn->addr, bbi->addr, bbi->size); - r_cons_printf ("0x%08"PFMT64x" ", bbi->jump); - r_cons_printf ("0x%08"PFMT64x, bbi->fail); + rz_cons_printf ("0x%08"PFMT64x" ", bbi->jump); + rz_cons_printf ("0x%08"PFMT64x, bbi->fail); if (bbi->diff) { if (bbi->diff->type == R_ANAL_DIFF_TYPE_MATCH) { - r_cons_printf (" m"); + rz_cons_printf (" m"); } else if (bbi->diff->type == R_ANAL_DIFF_TYPE_UNMATCH) { - r_cons_printf (" u"); + rz_cons_printf (" u"); } else { - r_cons_printf (" n"); + rz_cons_printf (" n"); } } - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } } -R_API ut64 r_core_anal_fcn_list_size(RCore *core) { - RAnalFunction *fcn; - RListIter *iter; +RZ_API ut64 rz_core_anal_fcn_list_size(RzCore *core) { + RzAnalFunction *fcn; + RzListIter *iter; ut64 total = 0; - r_list_foreach (core->anal->fcns, iter, fcn) { - total += r_anal_function_realsize (fcn); + rz_list_foreach (core->anal->fcns, iter, fcn) { + total += rz_anal_function_realsize (fcn); } - r_cons_printf ("%"PFMT64u"\n", total); + rz_cons_printf ("%"PFMT64u"\n", total); return total; } /* Fill out metadata struct of functions */ -static int fcnlist_gather_metadata(RAnal *anal, RList *fcns) { - RListIter *iter; - RAnalFunction *fcn; - RList *xrefs; +static int fcnlist_gather_metadata(RzAnal *anal, RzList *fcns) { + RzListIter *iter; + RzAnalFunction *fcn; + RzList *xrefs; - r_list_foreach (fcns, iter, fcn) { + rz_list_foreach (fcns, iter, fcn) { // Count the number of references and number of calls - RListIter *callrefiter; - RAnalRef *ref; - RList *refs = r_anal_function_get_refs (fcn); + RzListIter *callrefiter; + RzAnalRef *ref; + RzList *refs = rz_anal_function_get_refs (fcn); int numcallrefs = 0; - r_list_foreach (refs, callrefiter, ref) { + rz_list_foreach (refs, callrefiter, ref) { if (ref->type == R_ANAL_REF_TYPE_CALL) { numcallrefs++; } } - r_list_free (refs); + rz_list_free (refs); fcn->meta.numcallrefs = numcallrefs; - xrefs = r_anal_xrefs_get (anal, fcn->addr); + xrefs = rz_anal_xrefs_get (anal, fcn->addr); fcn->meta.numrefs = xrefs? xrefs->length: 0; - r_list_free (xrefs); + rz_list_free (xrefs); } // TODO: Determine sgnc, sgec return 0; } -R_API char *r_core_anal_fcn_name(RCore *core, RAnalFunction *fcn) { - bool demangle = r_config_get_i (core->config, "bin.demangle"); - const char *lang = demangle ? r_config_get (core->config, "bin.lang") : NULL; - bool keep_lib = r_config_get_i (core->config, "bin.demangle.libs"); +RZ_API char *rz_core_anal_fcn_name(RzCore *core, RzAnalFunction *fcn) { + bool demangle = rz_config_get_i (core->config, "bin.demangle"); + const char *lang = demangle ? rz_config_get (core->config, "bin.lang") : NULL; + bool keep_lib = rz_config_get_i (core->config, "bin.demangle.libs"); char *name = strdup (fcn->name ? fcn->name : ""); if (demangle) { - char *tmp = r_bin_demangle (core->bin->cur, lang, name, fcn->addr, keep_lib); + char *tmp = rz_bin_demangle (core->bin->cur, lang, name, fcn->addr, keep_lib); if (tmp) { free (name); name = tmp; @@ -2611,8 +2611,8 @@ R_API char *r_core_anal_fcn_name(RCore *core, RAnalFunction *fcn) { } #define FCN_LIST_VERBOSE_ENTRY "%s0x%0*"PFMT64x" %4d %5d %5d %5d %4d 0x%0*"PFMT64x" %5d 0x%0*"PFMT64x" %5d %4d %6d %4d %5d %s%s\n" -static int fcn_print_verbose(RCore *core, RAnalFunction *fcn, bool use_color) { - char *name = r_core_anal_fcn_name (core, fcn); +static int fcn_print_verbose(RzCore *core, RzAnalFunction *fcn, bool use_color) { + char *name = rz_core_anal_fcn_name (core, fcn); int ebbs = 0; int addrwidth = 8; const char *color = ""; @@ -2632,23 +2632,23 @@ static int fcn_print_verbose(RCore *core, RAnalFunction *fcn, bool use_color) { addrwidth = 16; } - r_cons_printf (FCN_LIST_VERBOSE_ENTRY, color, + rz_cons_printf (FCN_LIST_VERBOSE_ENTRY, color, addrwidth, fcn->addr, - r_anal_function_realsize (fcn), - r_list_length (fcn->bbs), - r_anal_function_count_edges (fcn, &ebbs), - r_anal_function_complexity (fcn), - r_anal_function_cost (fcn), - addrwidth, r_anal_function_min_addr (fcn), - r_anal_function_linear_size (fcn), - addrwidth, r_anal_function_max_addr (fcn), + rz_anal_function_realsize (fcn), + rz_list_length (fcn->bbs), + rz_anal_function_count_edges (fcn, &ebbs), + rz_anal_function_complexity (fcn), + rz_anal_function_cost (fcn), + addrwidth, rz_anal_function_min_addr (fcn), + rz_anal_function_linear_size (fcn), + addrwidth, rz_anal_function_max_addr (fcn), fcn->meta.numcallrefs, - r_anal_var_count (core->anal, fcn, 's', 0) + - r_anal_var_count (core->anal, fcn, 'b', 0) + - r_anal_var_count (core->anal, fcn, 'r', 0), - r_anal_var_count (core->anal, fcn, 's', 1) + - r_anal_var_count (core->anal, fcn, 'b', 1) + - r_anal_var_count (core->anal, fcn, 'r', 1), + rz_anal_var_count (core->anal, fcn, 's', 0) + + rz_anal_var_count (core->anal, fcn, 'b', 0) + + rz_anal_var_count (core->anal, fcn, 'r', 0), + rz_anal_var_count (core->anal, fcn, 's', 1) + + rz_anal_var_count (core->anal, fcn, 'b', 1) + + rz_anal_var_count (core->anal, fcn, 'r', 1), fcn->meta.numrefs, fcn->maxstack, name, @@ -2657,8 +2657,8 @@ static int fcn_print_verbose(RCore *core, RAnalFunction *fcn, bool use_color) { return 0; } -static int fcn_list_verbose(RCore *core, RList *fcns, const char *sortby) { - bool use_color = r_config_get_i (core->config, "scr.color"); +static int fcn_list_verbose(RzCore *core, RzList *fcns, const char *sortby) { + bool use_color = rz_config_get_i (core->config, "scr.color"); int headeraddr_width = 10; char *headeraddr = "=========="; @@ -2669,85 +2669,85 @@ static int fcn_list_verbose(RCore *core, RList *fcns, const char *sortby) { if (sortby) { if (!strcmp (sortby, "size")) { - r_list_sort (fcns, cmpsize); + rz_list_sort (fcns, cmpsize); } else if (!strcmp (sortby, "addr")) { - r_list_sort (fcns, cmpaddr); + rz_list_sort (fcns, cmpaddr); } else if (!strcmp (sortby, "cc")) { - r_list_sort (fcns, cmpfcncc); + rz_list_sort (fcns, cmpfcncc); } else if (!strcmp (sortby, "edges")) { - r_list_sort (fcns, cmpedges); + rz_list_sort (fcns, cmpedges); } else if (!strcmp (sortby, "calls")) { - r_list_sort (fcns, cmpcalls); + rz_list_sort (fcns, cmpcalls); } else if (strstr (sortby, "name")) { - r_list_sort (fcns, cmpname); + rz_list_sort (fcns, cmpname); } else if (strstr (sortby, "frame")) { - r_list_sort (fcns, cmpframe); + rz_list_sort (fcns, cmpframe); } else if (strstr (sortby, "ref")) { - r_list_sort (fcns, cmpxrefs); + rz_list_sort (fcns, cmpxrefs); } else if (!strcmp (sortby, "nbbs")) { - r_list_sort (fcns, cmpnbbs); + rz_list_sort (fcns, cmpnbbs); } } - r_cons_printf ("%-*s %4s %5s %5s %5s %4s %*s range %-*s %s %s %s %s %s %s\n", + rz_cons_printf ("%-*s %4s %5s %5s %5s %4s %*s range %-*s %s %s %s %s %s %s\n", headeraddr_width, "address", "size", "nbbs", "edges", "cc", "cost", headeraddr_width, "min bound", headeraddr_width, "max bound", "calls", "locals", "args", "xref", "frame", "name"); - r_cons_printf ("%s ==== ===== ===== ===== ==== %s ===== %s ===== ====== ==== ==== ===== ====\n", + rz_cons_printf ("%s ==== ===== ===== ===== ==== %s ===== %s ===== ====== ==== ==== ===== ====\n", headeraddr, headeraddr, headeraddr); - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (fcns, iter, fcn) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (fcns, iter, fcn) { fcn_print_verbose (core, fcn, use_color); } return 0; } -static void __fcn_print_default(RCore *core, RAnalFunction *fcn, bool quiet) { +static void __fcn_print_default(RzCore *core, RzAnalFunction *fcn, bool quiet) { if (quiet) { - r_cons_printf ("0x%08"PFMT64x" ", fcn->addr); + rz_cons_printf ("0x%08"PFMT64x" ", fcn->addr); } else { - char *msg, *name = r_core_anal_fcn_name (core, fcn); - ut64 realsize = r_anal_function_realsize (fcn); - ut64 size = r_anal_function_linear_size (fcn); + char *msg, *name = rz_core_anal_fcn_name (core, fcn); + ut64 realsize = rz_anal_function_realsize (fcn); + ut64 size = rz_anal_function_linear_size (fcn); if (realsize == size) { - msg = r_str_newf ("%-12"PFMT64u, size); + msg = rz_str_newf ("%-12"PFMT64u, size); } else { - msg = r_str_newf ("%-4"PFMT64u" -> %-4"PFMT64u, size, realsize); + msg = rz_str_newf ("%-4"PFMT64u" -> %-4"PFMT64u, size, realsize); } - r_cons_printf ("0x%08"PFMT64x" %4d %4s %s\n", - fcn->addr, r_list_length (fcn->bbs), msg, name); + rz_cons_printf ("0x%08"PFMT64x" %4d %4s %s\n", + fcn->addr, rz_list_length (fcn->bbs), msg, name); free (name); free (msg); } } -static int fcn_list_default(RCore *core, RList *fcns, bool quiet) { - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (fcns, iter, fcn) { +static int fcn_list_default(RzCore *core, RzList *fcns, bool quiet) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (fcns, iter, fcn) { __fcn_print_default (core, fcn, quiet); if (quiet) { - r_cons_newline (); + rz_cons_newline (); } } return 0; } -// for a given function returns an RList of all functions that were called in it -R_API RList *r_core_anal_fcn_get_calls (RCore *core, RAnalFunction *fcn) { - RAnalRef *refi; - RListIter *iter, *iter2; +// for a given function returns an RzList of all functions that were called in it +RZ_API RzList *rz_core_anal_fcn_get_calls (RzCore *core, RzAnalFunction *fcn) { + RzAnalRef *refi; + RzListIter *iter, *iter2; // get all references from this function - RList *refs = r_anal_function_get_refs (fcn); + RzList *refs = rz_anal_function_get_refs (fcn); // sanity check - if (!r_list_empty (refs)) { + if (!rz_list_empty (refs)) { // iterate over all the references and remove these which aren't of type call - r_list_foreach_safe (refs, iter, iter2, refi) { + rz_list_foreach_safe (refs, iter, iter2, refi) { if (refi->type != R_ANAL_REF_TYPE_CALL) { - r_list_delete (refs, iter); + rz_list_delete (refs, iter); } } } @@ -2755,12 +2755,12 @@ R_API RList *r_core_anal_fcn_get_calls (RCore *core, RAnalFunction *fcn) { } // Lists function names and their calls (uniqified) -static int fcn_print_makestyle(RCore *core, RList *fcns, char mode) { - RListIter *refiter; - RListIter *fcniter; - RAnalFunction *fcn; - RAnalRef *refi; - RList *refs = NULL; +static int fcn_print_makestyle(RzCore *core, RzList *fcns, char mode) { + RzListIter *refiter; + RzListIter *fcniter; + RzAnalFunction *fcn; + RzAnalRef *refi; + RzList *refs = NULL; PJ *pj = NULL; if (mode == 'j') { @@ -2769,14 +2769,14 @@ static int fcn_print_makestyle(RCore *core, RList *fcns, char mode) { } // Iterate over all functions - r_list_foreach (fcns, fcniter, fcn) { + rz_list_foreach (fcns, fcniter, fcn) { // Get all refs for a function - refs = r_core_anal_fcn_get_calls (core, fcn); + refs = rz_core_anal_fcn_get_calls (core, fcn); // Uniquify the list by ref->addr - refs = r_list_uniq (refs, (RListComparator)RAnalRef_cmp); + refs = rz_list_uniq (refs, (RzListComparator)RzAnalRef_cmp); // don't enter for functions with 0 refs - if (!r_list_empty (refs)) { + if (!rz_list_empty (refs)) { if (pj) { // begin json output of function pj_o (pj); pj_ks (pj, "name", fcn->name); @@ -2784,41 +2784,41 @@ static int fcn_print_makestyle(RCore *core, RList *fcns, char mode) { pj_k (pj, "calls"); pj_a (pj); } else { - r_cons_printf ("%s", fcn->name); + rz_cons_printf ("%s", fcn->name); } if (mode == 'm') { - r_cons_printf (":\n"); + rz_cons_printf (":\n"); } else if (mode == 'q') { - r_cons_printf (" -> "); + rz_cons_printf (" -> "); } // Iterate over all refs from a function - r_list_foreach (refs, refiter, refi) { - RFlagItem *f = r_flag_get_i (core->flags, refi->addr); - char *dst = r_str_newf ((f? f->name: "0x%08"PFMT64x), refi->addr); + rz_list_foreach (refs, refiter, refi) { + RzFlagItem *f = rz_flag_get_i (core->flags, refi->addr); + char *dst = rz_str_newf ((f? f->name: "0x%08"PFMT64x), refi->addr); if (pj) { // Append calee json item pj_o (pj); pj_ks (pj, "name", dst); pj_kn (pj, "addr", refi->addr); pj_end (pj); // close referenced item } else if (mode == 'q') { - r_cons_printf ("%s ", dst); + rz_cons_printf ("%s ", dst); } else { - r_cons_printf (" %s\n", dst); + rz_cons_printf (" %s\n", dst); } } if (pj) { pj_end (pj); // close list of calls pj_end (pj); // close function item } else { - r_cons_newline(); + rz_cons_newline(); } } } if (mode == 'j') { pj_end (pj); // close json output - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); } if (pj) { pj_free (pj); @@ -2826,53 +2826,53 @@ static int fcn_print_makestyle(RCore *core, RList *fcns, char mode) { return 0; } -static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) { - RListIter *iter; - RAnalRef *refi; - RList *refs, *xrefs; +static int fcn_print_json(RzCore *core, RzAnalFunction *fcn, PJ *pj) { + RzListIter *iter; + RzAnalRef *refi; + RzList *refs, *xrefs; if (!pj) { return -1; } int ebbs = 0; pj_o (pj); pj_kn (pj, "offset", fcn->addr); - char *name = r_core_anal_fcn_name (core, fcn); + char *name = rz_core_anal_fcn_name (core, fcn); if (name) { pj_ks (pj, "name", name); } - pj_kn (pj, "size", r_anal_function_linear_size (fcn)); - pj_ks (pj, "is-pure", r_str_bool (r_anal_function_purity (fcn))); - pj_kn (pj, "realsz", r_anal_function_realsize (fcn)); + pj_kn (pj, "size", rz_anal_function_linear_size (fcn)); + pj_ks (pj, "is-pure", rz_str_bool (rz_anal_function_purity (fcn))); + pj_kn (pj, "realsz", rz_anal_function_realsize (fcn)); pj_kb (pj, "noreturn", fcn->is_noreturn); pj_ki (pj, "stackframe", fcn->maxstack); if (fcn->cc) { pj_ks (pj, "calltype", fcn->cc); // calling conventions } - pj_ki (pj, "cost", r_anal_function_cost (fcn)); // execution cost - pj_ki (pj, "cc", r_anal_function_complexity (fcn)); // cyclic cost + pj_ki (pj, "cost", rz_anal_function_cost (fcn)); // execution cost + pj_ki (pj, "cc", rz_anal_function_complexity (fcn)); // cyclic cost pj_ki (pj, "bits", fcn->bits); - pj_ks (pj, "type", r_anal_fcntype_tostring (fcn->type)); - pj_ki (pj, "nbbs", r_list_length (fcn->bbs)); - pj_ki (pj, "edges", r_anal_function_count_edges (fcn, &ebbs)); + pj_ks (pj, "type", rz_anal_fcntype_tostring (fcn->type)); + pj_ki (pj, "nbbs", rz_list_length (fcn->bbs)); + pj_ki (pj, "edges", rz_anal_function_count_edges (fcn, &ebbs)); pj_ki (pj, "ebbs", ebbs); { - char *sig = r_core_cmd_strf (core, "afcf @ 0x%"PFMT64x, fcn->addr); + char *sig = rz_core_cmd_strf (core, "afcf @ 0x%"PFMT64x, fcn->addr); if (sig) { - r_str_trim (sig); + rz_str_trim (sig); pj_ks (pj, "signature", sig); free (sig); } } - pj_kn (pj, "minbound", r_anal_function_min_addr (fcn)); - pj_kn (pj, "maxbound", r_anal_function_max_addr (fcn)); + pj_kn (pj, "minbound", rz_anal_function_min_addr (fcn)); + pj_kn (pj, "maxbound", rz_anal_function_max_addr (fcn)); int outdegree = 0; - refs = r_anal_function_get_refs (fcn); - if (!r_list_empty (refs)) { + refs = rz_anal_function_get_refs (fcn); + if (!rz_list_empty (refs)) { pj_k (pj, "callrefs"); pj_a (pj); - r_list_foreach (refs, iter, refi) { + rz_list_foreach (refs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CALL) { outdegree++; } @@ -2880,7 +2880,7 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) { refi->type == R_ANAL_REF_TYPE_CALL) { pj_o (pj); pj_kn (pj, "addr", refi->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (refi->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (refi->type)); pj_kn (pj, "at", refi->at); pj_end (pj); } @@ -2889,27 +2889,27 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) { pj_k (pj, "datarefs"); pj_a (pj); - r_list_foreach (refs, iter, refi) { + rz_list_foreach (refs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_DATA) { pj_n (pj, refi->addr); } } pj_end (pj); } - r_list_free (refs); + rz_list_free (refs); int indegree = 0; - xrefs = r_anal_function_get_xrefs (fcn); - if (!r_list_empty (xrefs)) { + xrefs = rz_anal_function_get_xrefs (fcn); + if (!rz_list_empty (xrefs)) { pj_k (pj, "codexrefs"); pj_a (pj); - r_list_foreach (xrefs, iter, refi) { + rz_list_foreach (xrefs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) { indegree++; pj_o (pj); pj_kn (pj, "addr", refi->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (refi->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (refi->type)); pj_kn (pj, "at", refi->at); pj_end (pj); } @@ -2919,32 +2919,32 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) { pj_k (pj, "dataxrefs"); pj_a (pj); - r_list_foreach (xrefs, iter, refi) { + rz_list_foreach (xrefs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_DATA) { pj_n (pj, refi->addr); } } pj_end (pj); } - r_list_free (xrefs); + rz_list_free (xrefs); pj_ki (pj, "indegree", indegree); pj_ki (pj, "outdegree", outdegree); if (fcn->type == R_ANAL_FCN_TYPE_FCN || fcn->type == R_ANAL_FCN_TYPE_SYM) { - pj_ki (pj, "nlocals", r_anal_var_count (core->anal, fcn, 'b', 0) + - r_anal_var_count (core->anal, fcn, 'r', 0) + - r_anal_var_count (core->anal, fcn, 's', 0)); - pj_ki (pj, "nargs", r_anal_var_count (core->anal, fcn, 'b', 1) + - r_anal_var_count (core->anal, fcn, 'r', 1) + - r_anal_var_count (core->anal, fcn, 's', 1)); + pj_ki (pj, "nlocals", rz_anal_var_count (core->anal, fcn, 'b', 0) + + rz_anal_var_count (core->anal, fcn, 'r', 0) + + rz_anal_var_count (core->anal, fcn, 's', 0)); + pj_ki (pj, "nargs", rz_anal_var_count (core->anal, fcn, 'b', 1) + + rz_anal_var_count (core->anal, fcn, 'r', 1) + + rz_anal_var_count (core->anal, fcn, 's', 1)); pj_k (pj, "bpvars"); - r_anal_var_list_show (core->anal, fcn, 'b', 'j', pj); + rz_anal_var_list_show (core->anal, fcn, 'b', 'j', pj); pj_k (pj, "spvars"); - r_anal_var_list_show (core->anal, fcn, 's', 'j', pj); + rz_anal_var_list_show (core->anal, fcn, 's', 'j', pj); pj_k (pj, "regvars"); - r_anal_var_list_show (core->anal, fcn, 'r', 'j', pj); + rz_anal_var_list_show (core->anal, fcn, 'r', 'j', pj); pj_ks (pj, "difftype", fcn->diff->type == R_ANAL_DIFF_TYPE_MATCH?"match": fcn->diff->type == R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new"); @@ -2960,15 +2960,15 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, PJ *pj) { return 0; } -static int fcn_list_json(RCore *core, RList *fcns, bool quiet) { - RListIter *iter; - RAnalFunction *fcn; +static int fcn_list_json(RzCore *core, RzList *fcns, bool quiet) { + RzListIter *iter; + RzAnalFunction *fcn; PJ *pj = pj_new (); if (!pj) { return -1; } pj_a (pj); - r_list_foreach (fcns, iter, fcn) { + rz_list_foreach (fcns, iter, fcn) { if (quiet) { pj_n (pj, fcn->addr); } else { @@ -2976,21 +2976,21 @@ static int fcn_list_json(RCore *core, RList *fcns, bool quiet) { } } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); return 0; } -static int fcn_list_verbose_json(RCore *core, RList *fcns) { +static int fcn_list_verbose_json(RzCore *core, RzList *fcns) { return fcn_list_json (core, fcns, false); } -static int fcn_print_detail(RCore *core, RAnalFunction *fcn) { - const char *defaultCC = r_anal_cc_default (core->anal); - char *name = r_core_anal_fcn_name (core, fcn); - r_cons_printf ("\"f %s %"PFMT64u" 0x%08"PFMT64x"\"\n", name, r_anal_function_linear_size (fcn), fcn->addr); - r_cons_printf ("\"af+ 0x%08"PFMT64x" %s %c %c\"\n", - fcn->addr, name, //r_anal_fcn_size (fcn), name, +static int fcn_print_detail(RzCore *core, RzAnalFunction *fcn) { + const char *defaultCC = rz_anal_cc_default (core->anal); + char *name = rz_core_anal_fcn_name (core, fcn); + rz_cons_printf ("\"f %s %"PFMT64u" 0x%08"PFMT64x"\"\n", name, rz_anal_function_linear_size (fcn), fcn->addr); + rz_cons_printf ("\"af+ 0x%08"PFMT64x" %s %c %c\"\n", + fcn->addr, name, //rz_anal_fcn_size (fcn), name, fcn->type == R_ANAL_FCN_TYPE_LOC?'l': fcn->type == R_ANAL_FCN_TYPE_SYM?'s': fcn->type == R_ANAL_FCN_TYPE_IMP?'i':'f', @@ -2999,61 +2999,61 @@ static int fcn_print_detail(RCore *core, RAnalFunction *fcn) { // FIXME: this command prints something annoying. Does it have important side-effects? fcn_list_bbs (fcn); if (fcn->bits != 0) { - r_cons_printf ("afB %d @ 0x%08"PFMT64x"\n", fcn->bits, fcn->addr); + rz_cons_printf ("afB %d @ 0x%08"PFMT64x"\n", fcn->bits, fcn->addr); } // FIXME command injection vuln here if (fcn->cc || defaultCC) { - r_cons_printf ("afc %s @ 0x%08"PFMT64x"\n", fcn->cc?fcn->cc: defaultCC, fcn->addr); + rz_cons_printf ("afc %s @ 0x%08"PFMT64x"\n", fcn->cc?fcn->cc: defaultCC, fcn->addr); } if (fcn->folded) { - r_cons_printf ("afF @ 0x%08"PFMT64x"\n", fcn->addr); + rz_cons_printf ("afF @ 0x%08"PFMT64x"\n", fcn->addr); } if (fcn) { /* show variables and arguments */ - r_core_cmdf (core, "afvb* @ 0x%"PFMT64x"\n", fcn->addr); - r_core_cmdf (core, "afvr* @ 0x%"PFMT64x"\n", fcn->addr); - r_core_cmdf (core, "afvs* @ 0x%"PFMT64x"\n", fcn->addr); + rz_core_cmdf (core, "afvb* @ 0x%"PFMT64x"\n", fcn->addr); + rz_core_cmdf (core, "afvr* @ 0x%"PFMT64x"\n", fcn->addr); + rz_core_cmdf (core, "afvs* @ 0x%"PFMT64x"\n", fcn->addr); } /* Show references */ - RListIter *refiter; - RAnalRef *refi; - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, refiter, refi) { + RzListIter *refiter; + RzAnalRef *refi; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, refiter, refi) { switch (refi->type) { case R_ANAL_REF_TYPE_CALL: - r_cons_printf ("axC 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); + rz_cons_printf ("axC 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); break; case R_ANAL_REF_TYPE_DATA: - r_cons_printf ("axd 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); + rz_cons_printf ("axd 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); break; case R_ANAL_REF_TYPE_CODE: - r_cons_printf ("axc 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); + rz_cons_printf ("axc 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); break; case R_ANAL_REF_TYPE_STRING: - r_cons_printf ("axs 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); + rz_cons_printf ("axs 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); break; case R_ANAL_REF_TYPE_NULL: default: - r_cons_printf ("ax 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); + rz_cons_printf ("ax 0x%"PFMT64x" 0x%"PFMT64x"\n", refi->addr, refi->at); break; } } - r_list_free (refs); + rz_list_free (refs); /*Saving Function stack frame*/ - r_cons_printf ("afS %"PFMT64d" @ 0x%"PFMT64x"\n", fcn->maxstack, fcn->addr); + rz_cons_printf ("afS %"PFMT64d" @ 0x%"PFMT64x"\n", fcn->maxstack, fcn->addr); free (name); return 0; } -static bool is_fcn_traced(RDebugTrace *traced, RAnalFunction *fcn) { +static bool is_fcn_traced(RzDebugTrace *traced, RzAnalFunction *fcn) { int tag = traced->tag; - RListIter *iter; - RDebugTracepoint *trace; + RzListIter *iter; + RzDebugTracepoint *trace; - r_list_foreach (traced->traces, iter, trace) { + rz_list_foreach (traced->traces, iter, trace) { if (!trace->tag || (tag & trace->tag)) { - if (r_anal_function_contains (fcn, trace->addr)) { - r_cons_printf ("\ntraced: %d\n", trace->times); + if (rz_anal_function_contains (fcn, trace->addr)) { + rz_cons_printf ("\ntraced: %d\n", trace->times); return true; } } @@ -3061,95 +3061,95 @@ static bool is_fcn_traced(RDebugTrace *traced, RAnalFunction *fcn) { return false; } -static int fcn_print_legacy(RCore *core, RAnalFunction *fcn) { - RListIter *iter; - RAnalRef *refi; - RList *refs, *xrefs; +static int fcn_print_legacy(RzCore *core, RzAnalFunction *fcn) { + RzListIter *iter; + RzAnalRef *refi; + RzList *refs, *xrefs; int ebbs = 0; - char *name = r_core_anal_fcn_name (core, fcn); + char *name = rz_core_anal_fcn_name (core, fcn); - r_cons_printf ("#\noffset: 0x%08"PFMT64x"\nname: %s\nsize: %"PFMT64u, - fcn->addr, name, r_anal_function_linear_size (fcn)); - r_cons_printf ("\nis-pure: %s", r_str_bool (r_anal_function_purity (fcn))); - r_cons_printf ("\nrealsz: %d", r_anal_function_realsize (fcn)); - r_cons_printf ("\nstackframe: %d", fcn->maxstack); + rz_cons_printf ("#\noffset: 0x%08"PFMT64x"\nname: %s\nsize: %"PFMT64u, + fcn->addr, name, rz_anal_function_linear_size (fcn)); + rz_cons_printf ("\nis-pure: %s", rz_str_bool (rz_anal_function_purity (fcn))); + rz_cons_printf ("\nrealsz: %d", rz_anal_function_realsize (fcn)); + rz_cons_printf ("\nstackframe: %d", fcn->maxstack); if (fcn->cc) { - r_cons_printf ("\ncall-convention: %s", fcn->cc); + rz_cons_printf ("\ncall-convention: %s", fcn->cc); } - r_cons_printf ("\ncyclomatic-cost: %d", r_anal_function_cost (fcn)); - r_cons_printf ("\ncyclomatic-complexity: %d", r_anal_function_complexity (fcn)); - r_cons_printf ("\nbits: %d", fcn->bits); - r_cons_printf ("\ntype: %s", r_anal_fcntype_tostring (fcn->type)); + rz_cons_printf ("\ncyclomatic-cost: %d", rz_anal_function_cost (fcn)); + rz_cons_printf ("\ncyclomatic-complexity: %d", rz_anal_function_complexity (fcn)); + rz_cons_printf ("\nbits: %d", fcn->bits); + rz_cons_printf ("\ntype: %s", rz_anal_fcntype_tostring (fcn->type)); if (fcn->type == R_ANAL_FCN_TYPE_FCN || fcn->type == R_ANAL_FCN_TYPE_SYM) { - r_cons_printf (" [%s]", + rz_cons_printf (" [%s]", fcn->diff->type == R_ANAL_DIFF_TYPE_MATCH?"MATCH": fcn->diff->type == R_ANAL_DIFF_TYPE_UNMATCH?"UNMATCH":"NEW"); } - r_cons_printf ("\nnum-bbs: %d", r_list_length (fcn->bbs)); - r_cons_printf ("\nedges: %d", r_anal_function_count_edges (fcn, &ebbs)); - r_cons_printf ("\nend-bbs: %d", ebbs); - r_cons_printf ("\ncall-refs:"); + rz_cons_printf ("\nnum-bbs: %d", rz_list_length (fcn->bbs)); + rz_cons_printf ("\nedges: %d", rz_anal_function_count_edges (fcn, &ebbs)); + rz_cons_printf ("\nend-bbs: %d", ebbs); + rz_cons_printf ("\ncall-refs:"); int outdegree = 0; - refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, refi) { + refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CALL) { outdegree++; } if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) { - r_cons_printf (" 0x%08"PFMT64x" %c", refi->addr, + rz_cons_printf (" 0x%08"PFMT64x" %c", refi->addr, refi->type == R_ANAL_REF_TYPE_CALL?'C':'J'); } } - r_cons_printf ("\ndata-refs:"); - r_list_foreach (refs, iter, refi) { + rz_cons_printf ("\ndata-refs:"); + rz_list_foreach (refs, iter, refi) { // global or local? if (refi->type == R_ANAL_REF_TYPE_DATA) { - r_cons_printf (" 0x%08"PFMT64x, refi->addr); + rz_cons_printf (" 0x%08"PFMT64x, refi->addr); } } - r_list_free (refs); + rz_list_free (refs); int indegree = 0; - r_cons_printf ("\ncode-xrefs:"); - xrefs = r_anal_function_get_xrefs (fcn); - r_list_foreach (xrefs, iter, refi) { + rz_cons_printf ("\ncode-xrefs:"); + xrefs = rz_anal_function_get_xrefs (fcn); + rz_list_foreach (xrefs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CODE || refi->type == R_ANAL_REF_TYPE_CALL) { indegree++; - r_cons_printf (" 0x%08"PFMT64x" %c", refi->addr, + rz_cons_printf (" 0x%08"PFMT64x" %c", refi->addr, refi->type == R_ANAL_REF_TYPE_CALL?'C':'J'); } } - r_cons_printf ("\nnoreturn: %s", r_str_bool (fcn->is_noreturn)); - r_cons_printf ("\nin-degree: %d", indegree); - r_cons_printf ("\nout-degree: %d", outdegree); - r_cons_printf ("\ndata-xrefs:"); - r_list_foreach (xrefs, iter, refi) { + rz_cons_printf ("\nnoreturn: %s", rz_str_bool (fcn->is_noreturn)); + rz_cons_printf ("\nin-degree: %d", indegree); + rz_cons_printf ("\nout-degree: %d", outdegree); + rz_cons_printf ("\ndata-xrefs:"); + rz_list_foreach (xrefs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_DATA) { - r_cons_printf (" 0x%08"PFMT64x, refi->addr); + rz_cons_printf (" 0x%08"PFMT64x, refi->addr); } } - r_list_free (xrefs); + rz_list_free (xrefs); if (fcn->type == R_ANAL_FCN_TYPE_FCN || fcn->type == R_ANAL_FCN_TYPE_SYM) { - int args_count = r_anal_var_count (core->anal, fcn, 'b', 1); - args_count += r_anal_var_count (core->anal, fcn, 's', 1); - args_count += r_anal_var_count (core->anal, fcn, 'r', 1); - int var_count = r_anal_var_count (core->anal, fcn, 'b', 0); - var_count += r_anal_var_count (core->anal, fcn, 's', 0); - var_count += r_anal_var_count (core->anal, fcn, 'r', 0); + int args_count = rz_anal_var_count (core->anal, fcn, 'b', 1); + args_count += rz_anal_var_count (core->anal, fcn, 's', 1); + args_count += rz_anal_var_count (core->anal, fcn, 'r', 1); + int var_count = rz_anal_var_count (core->anal, fcn, 'b', 0); + var_count += rz_anal_var_count (core->anal, fcn, 's', 0); + var_count += rz_anal_var_count (core->anal, fcn, 'r', 0); - r_cons_printf ("\nlocals: %d\nargs: %d\n", var_count, args_count); - r_anal_var_list_show (core->anal, fcn, 'b', 0, NULL); - r_anal_var_list_show (core->anal, fcn, 's', 0, NULL); - r_anal_var_list_show (core->anal, fcn, 'r', 0, NULL); - r_cons_printf ("diff: type: %s", + rz_cons_printf ("\nlocals: %d\nargs: %d\n", var_count, args_count); + rz_anal_var_list_show (core->anal, fcn, 'b', 0, NULL); + rz_anal_var_list_show (core->anal, fcn, 's', 0, NULL); + rz_anal_var_list_show (core->anal, fcn, 'r', 0, NULL); + rz_cons_printf ("diff: type: %s", fcn->diff->type == R_ANAL_DIFF_TYPE_MATCH?"match": fcn->diff->type == R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new"); if (fcn->diff->addr != -1) { - r_cons_printf ("addr: 0x%"PFMT64x, fcn->diff->addr); + rz_cons_printf ("addr: 0x%"PFMT64x, fcn->diff->addr); } if (fcn->diff->name) { - r_cons_printf ("function: %s", fcn->diff->name); + rz_cons_printf ("function: %s", fcn->diff->name); } } free (name); @@ -3161,77 +3161,77 @@ static int fcn_print_legacy(RCore *core, RAnalFunction *fcn) { return 0; } -static int fcn_list_detail(RCore *core, RList *fcns) { - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (fcns, iter, fcn) { +static int fcn_list_detail(RzCore *core, RzList *fcns) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (fcns, iter, fcn) { fcn_print_detail (core, fcn); } - r_cons_newline (); + rz_cons_newline (); return 0; } -static int fcn_list_table(RCore *core, const char *q, int fmt) { - RAnalFunction *fcn; - RListIter *iter; - RTable *t = r_core_table (core); - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - r_table_add_column (t, typeNumber, "addr", 0); - r_table_add_column (t, typeNumber, "size", 0); - r_table_add_column (t, typeString, "name", 0); - r_table_add_column (t, typeNumber, "nbbs", 0); - r_table_add_column (t, typeNumber, "xref", 0); - r_table_add_column (t, typeNumber, "calls", 0); - r_table_add_column (t, typeNumber, "cc", 0); - r_list_foreach (core->anal->fcns, iter, fcn) { +static int fcn_list_table(RzCore *core, const char *q, int fmt) { + RzAnalFunction *fcn; + RzListIter *iter; + RTable *t = rz_core_table (core); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + rz_table_add_column (t, typeNumber, "addr", 0); + rz_table_add_column (t, typeNumber, "size", 0); + rz_table_add_column (t, typeString, "name", 0); + rz_table_add_column (t, typeNumber, "nbbs", 0); + rz_table_add_column (t, typeNumber, "xref", 0); + rz_table_add_column (t, typeNumber, "calls", 0); + rz_table_add_column (t, typeNumber, "cc", 0); + rz_list_foreach (core->anal->fcns, iter, fcn) { const char *fcnAddr = sdb_fmt ("0x%08"PFMT64x, fcn->addr); - const char *fcnSize = sdb_fmt ("%"PFMT64u, r_anal_function_linear_size (fcn)); - const char *nbbs = sdb_fmt ("%d", r_list_length (fcn->bbs)); // r_anal_fcn_size (fcn)); - RList *xrefs = r_anal_function_get_xrefs (fcn); + const char *fcnSize = sdb_fmt ("%"PFMT64u, rz_anal_function_linear_size (fcn)); + const char *nbbs = sdb_fmt ("%d", rz_list_length (fcn->bbs)); // rz_anal_fcn_size (fcn)); + RzList *xrefs = rz_anal_function_get_xrefs (fcn); char xref[128], ccstr[128]; - snprintf (xref, sizeof (xref), "%d", r_list_length (xrefs)); - r_list_free (xrefs); + snprintf (xref, sizeof (xref), "%d", rz_list_length (xrefs)); + rz_list_free (xrefs); - RList * calls = r_core_anal_fcn_get_calls (core, fcn); + RzList * calls = rz_core_anal_fcn_get_calls (core, fcn); // Uniquify the list by ref->addr - calls = r_list_uniq (calls, (RListComparator)RAnalRef_cmp); - const char *callstr = sdb_fmt ("%d", r_list_length (calls)); - r_list_free (calls); - snprintf (ccstr, sizeof (ccstr), "%d", r_anal_function_complexity (fcn)); + calls = rz_list_uniq (calls, (RzListComparator)RzAnalRef_cmp); + const char *callstr = sdb_fmt ("%d", rz_list_length (calls)); + rz_list_free (calls); + snprintf (ccstr, sizeof (ccstr), "%d", rz_anal_function_complexity (fcn)); - r_table_add_row (t, fcnAddr, fcnSize, fcn->name, nbbs, xref, callstr, ccstr, NULL); + rz_table_add_row (t, fcnAddr, fcnSize, fcn->name, nbbs, xref, callstr, ccstr, NULL); } - if (r_table_query (t, q)) { + if (rz_table_query (t, q)) { char *s = (fmt== 'j') - ? r_table_tojson (t) - : r_table_tofancystring (t); - // char *s = r_table_tostring (t); - r_cons_printf ("%s\n", s); + ? rz_table_tojson (t) + : rz_table_tofancystring (t); + // char *s = rz_table_tostring (t); + rz_cons_printf ("%s\n", s); free (s); } - r_table_free (t); + rz_table_free (t); return 0; } -static int fcn_list_legacy(RCore *core, RList *fcns) { - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (fcns, iter, fcn) { +static int fcn_list_legacy(RzCore *core, RzList *fcns) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (fcns, iter, fcn) { fcn_print_legacy (core, fcn); } - r_cons_newline (); + rz_cons_newline (); return 0; } -R_API int r_core_anal_fcn_list(RCore *core, const char *input, const char *rad) { +RZ_API int rz_core_anal_fcn_list(RzCore *core, const char *input, const char *rad) { char temp[64]; - r_return_val_if_fail (core && core->anal, 0); - if (r_list_empty (core->anal->fcns)) { + rz_return_val_if_fail (core && core->anal, 0); + if (rz_list_empty (core->anal->fcns)) { return 0; } if (*rad == '.') { - RAnalFunction *fcn = r_anal_get_function_at (core->anal, core->offset); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, core->offset); __fcn_print_default (core, fcn, false); return 0; } @@ -3244,59 +3244,59 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, const char *rad) ut64 addr = core->offset; if (input && *input) { name = input + 1; - addr = r_num_math (core->num, name); + addr = rz_num_math (core->num, name); } - RList *fcns = r_list_newf (NULL); + RzList *fcns = rz_list_newf (NULL); if (!fcns) { return -1; } - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (core->anal->fcns, iter, fcn) { - if (!input || r_anal_function_contains (fcn, addr) || (!strcmp (name, fcn->name))) { - r_list_append (fcns, fcn); + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (core->anal->fcns, iter, fcn) { + if (!input || rz_anal_function_contains (fcn, addr) || (!strcmp (name, fcn->name))) { + rz_list_append (fcns, fcn); } } - // r_list_sort (fcns, &cmpfcn); + // rz_list_sort (fcns, &cmpfcn); if (!rad) { fcn_list_default (core, fcns, false); - r_list_free (fcns); + rz_list_free (fcns); return 0; } switch (*rad) { case '+': - r_core_anal_fcn_list_size (core); + rz_core_anal_fcn_list_size (core); break; case '=': { // afl= - r_list_sort (fcns, cmpaddr); - RList *flist = r_list_newf ((RListFree) r_listinfo_free); + rz_list_sort (fcns, cmpaddr); + RzList *flist = rz_list_newf ((RzListFree) rz_listinfo_free); if (!flist) { - r_list_free (fcns); + rz_list_free (fcns); return -1; } ls_foreach (fcns, iter, fcn) { - RInterval inter = {r_anal_function_min_addr (fcn), r_anal_function_linear_size (fcn) }; - RListInfo *info = r_listinfo_new (r_core_anal_fcn_name (core, fcn), inter, inter, -1, sdb_itoa (fcn->bits, temp, 10)); + RInterval inter = {rz_anal_function_min_addr (fcn), rz_anal_function_linear_size (fcn) }; + RzListInfo *info = rz_listinfo_new (rz_core_anal_fcn_name (core, fcn), inter, inter, -1, sdb_itoa (fcn->bits, temp, 10)); if (!info) { break; } - r_list_append (flist, info); + rz_list_append (flist, info); } - RTable *table = r_core_table (core); - r_table_visual_list (table, flist, core->offset, core->blocksize, - r_cons_get_size (NULL), r_config_get_i (core->config, "scr.color")); - r_cons_printf ("\n%s\n", r_table_tostring (table)); - r_table_free (table); - r_list_free (flist); + RTable *table = rz_core_table (core); + rz_table_visual_list (table, flist, core->offset, core->blocksize, + rz_cons_get_size (NULL), rz_config_get_i (core->config, "scr.color")); + rz_cons_printf ("\n%s\n", rz_table_tostring (table)); + rz_table_free (table); + rz_list_free (flist); break; } case 't': // "aflt" "afltj" if (rad[1] == 'j') { - fcn_list_table (core, r_str_trim_head_ro (rad+ 2), 'j'); + fcn_list_table (core, rz_str_trim_head_ro (rad+ 2), 'j'); } else { - fcn_list_table (core, r_str_trim_head_ro (rad + 1), rad[1]); + fcn_list_table (core, rz_str_trim_head_ro (rad + 1), rad[1]); } break; case 'l': // "afll" "afllj" @@ -3340,23 +3340,23 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, const char *rad) fcn_list_default (core, fcns, false); break; } - r_list_free (fcns); + rz_list_free (fcns); return 0; } -static RList *recurse_bb(RCore *core, ut64 addr, RAnalBlock *dest); +static RzList *recurse_bb(RzCore *core, ut64 addr, RzAnalBlock *dest); -static RList *recurse(RCore *core, RAnalBlock *from, RAnalBlock *dest) { +static RzList *recurse(RzCore *core, RzAnalBlock *from, RzAnalBlock *dest) { recurse_bb (core, from->jump, dest); recurse_bb (core, from->fail, dest); /* same for all calls */ - // TODO: RAnalBlock must contain a linked list of calls + // TODO: RzAnalBlock must contain a linked list of calls return NULL; } -static RList *recurse_bb(RCore *core, ut64 addr, RAnalBlock *dest) { - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, addr); +static RzList *recurse_bb(RzCore *core, ut64 addr, RzAnalBlock *dest) { + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, addr); if (bb == dest) { eprintf ("path found!"); return NULL; @@ -3370,13 +3370,13 @@ typedef struct { int count; RPVector reg_set; bool argonly; - RAnalFunction *fcn; - RCore *core; + RzAnalFunction *fcn; + RzCore *core; } BlockRecurseCtx; -static bool anal_block_on_exit(RAnalBlock *bb, BlockRecurseCtx *ctx) { - int *cur_regset = r_pvector_pop (&ctx->reg_set); - int *prev_regset = r_pvector_at (&ctx->reg_set, r_pvector_len (&ctx->reg_set) - 1); +static bool anal_block_on_exit(RzAnalBlock *bb, BlockRecurseCtx *ctx) { + int *cur_regset = rz_pvector_pop (&ctx->reg_set); + int *prev_regset = rz_pvector_at (&ctx->reg_set, rz_pvector_len (&ctx->reg_set) - 1); size_t i; for (i = 0; i < REG_SET_SIZE; i++) { if (!prev_regset[i] && cur_regset[i] == 1) { @@ -3387,8 +3387,8 @@ static bool anal_block_on_exit(RAnalBlock *bb, BlockRecurseCtx *ctx) { return true; } -static bool anal_block_cb(RAnalBlock *bb, BlockRecurseCtx *ctx) { - if (r_cons_is_breaked ()) { +static bool anal_block_cb(RzAnalBlock *bb, BlockRecurseCtx *ctx) { + if (rz_cons_is_breaked ()) { return false; } if (bb->size < 1) { @@ -3397,41 +3397,41 @@ static bool anal_block_cb(RAnalBlock *bb, BlockRecurseCtx *ctx) { if (bb->size > ctx->core->anal->opt.bb_max_size) { return true; } - int *parent_reg_set = r_pvector_at (&ctx->reg_set, r_pvector_len (&ctx->reg_set) - 1); + int *parent_reg_set = rz_pvector_at (&ctx->reg_set, rz_pvector_len (&ctx->reg_set) - 1); int *reg_set = R_NEWS (int, REG_SET_SIZE); memcpy (reg_set, parent_reg_set, REG_SET_SIZE * sizeof (int)); - r_pvector_push (&ctx->reg_set, reg_set); - RCore *core = ctx->core; - RAnalFunction *fcn = ctx->fcn; + rz_pvector_push (&ctx->reg_set, reg_set); + RzCore *core = ctx->core; + RzAnalFunction *fcn = ctx->fcn; fcn->stack = bb->parent_stackptr; ut64 pos = bb->addr; while (pos < bb->addr + bb->size) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - RAnalOp *op = r_core_anal_op (core, pos, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT); + RzAnalOp *op = rz_core_anal_op (core, pos, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT); if (!op) { //eprintf ("Cannot get op\n"); break; } - r_anal_extract_rarg (core->anal, op, fcn, reg_set, &ctx->count); + rz_anal_extract_rarg (core->anal, op, fcn, reg_set, &ctx->count); if (!ctx->argonly) { if (op->stackop == R_ANAL_STACK_INC) { fcn->stack += op->stackptr; } else if (op->stackop == R_ANAL_STACK_RESET) { fcn->stack = 0; } - r_anal_extract_vars (core->anal, fcn, op); + rz_anal_extract_vars (core->anal, fcn, op); } int opsize = op->size; int optype = op->type; - r_anal_op_free (op); + rz_anal_op_free (op); if (opsize < 1) { break; } if (optype == R_ANAL_OP_TYPE_CALL) { size_t i; - int max_count = fcn->cc ? r_anal_cc_max_arg (core->anal, fcn->cc) : 0; + int max_count = fcn->cc ? rz_anal_cc_max_arg (core->anal, fcn->cc) : 0; for (i = 0; i < max_count; i++) { reg_set[i] = 2; } @@ -3442,27 +3442,27 @@ static bool anal_block_cb(RAnalBlock *bb, BlockRecurseCtx *ctx) { } // TODO: move this logic into the main anal loop -R_API void r_core_recover_vars(RCore *core, RAnalFunction *fcn, bool argonly) { - r_return_if_fail (core && core->anal && fcn); +RZ_API void rz_core_recover_vars(RzCore *core, RzAnalFunction *fcn, bool argonly) { + rz_return_if_fail (core && core->anal && fcn); if (core->anal->opt.bb_max_size < 1) { return; } BlockRecurseCtx ctx = { 0, {{ 0 }}, argonly, fcn, core }; - r_pvector_init (&ctx.reg_set, free); + rz_pvector_init (&ctx.reg_set, free); int *reg_set = R_NEWS0 (int, REG_SET_SIZE); - r_pvector_push (&ctx.reg_set, reg_set); + rz_pvector_push (&ctx.reg_set, reg_set); int saved_stack = fcn->stack; - RAnalBlock *first_bb = r_anal_get_block_at (fcn->anal, fcn->addr); - r_anal_block_recurse_depth_first (first_bb, (RAnalBlockCb)anal_block_cb, (RAnalBlockCb)anal_block_on_exit, &ctx); - r_pvector_fini (&ctx.reg_set); + RzAnalBlock *first_bb = rz_anal_get_block_at (fcn->anal, fcn->addr); + rz_anal_block_recurse_depth_first (first_bb, (RzAnalBlockCb)anal_block_cb, (RzAnalBlockCb)anal_block_on_exit, &ctx); + rz_pvector_fini (&ctx.reg_set); fcn->stack = saved_stack; } -static bool anal_path_exists(RCore *core, ut64 from, ut64 to, RList *bbs, int depth, HtUP *state, HtUP *avoid) { - r_return_val_if_fail (bbs, false); - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, from); - RListIter *iter = NULL; - RAnalRef *refi; +static bool anal_path_exists(RzCore *core, ut64 from, ut64 to, RzList *bbs, int depth, HtUP *state, HtUP *avoid) { + rz_return_val_if_fail (bbs, false); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, from); + RzListIter *iter = NULL; + RzAnalRef *refi; if (depth < 1) { eprintf ("going too deep\n"); @@ -3476,49 +3476,49 @@ static bool anal_path_exists(RCore *core, ut64 from, ut64 to, RList *bbs, int de ht_up_update (state, from, bb); // try to find the target in the current function - if (r_anal_block_contains (bb, to) || + if (rz_anal_block_contains (bb, to) || ((!ht_up_find (avoid, bb->jump, NULL) && !ht_up_find (state, bb->jump, NULL) && anal_path_exists (core, bb->jump, to, bbs, depth - 1, state, avoid))) || ((!ht_up_find (avoid, bb->fail, NULL) && !ht_up_find (state, bb->fail, NULL) && anal_path_exists (core, bb->fail, to, bbs, depth - 1, state, avoid)))) { - r_list_prepend (bbs, bb); + rz_list_prepend (bbs, bb); return true; } // find our current function - RAnalFunction *cur_fcn = r_anal_get_fcn_in (core->anal, from, 0); + RzAnalFunction *cur_fcn = rz_anal_get_fcn_in (core->anal, from, 0); // get call refs from current basic block and find a path from them if (cur_fcn) { - RList *refs = r_anal_function_get_refs (cur_fcn); + RzList *refs = rz_anal_function_get_refs (cur_fcn); if (refs) { - r_list_foreach (refs, iter, refi) { + rz_list_foreach (refs, iter, refi) { if (refi->type == R_ANAL_REF_TYPE_CALL) { - if (r_anal_block_contains (bb, refi->at)) { + if (rz_anal_block_contains (bb, refi->at)) { if ((refi->at != refi->addr) && !ht_up_find (state, refi->addr, NULL) && anal_path_exists (core, refi->addr, to, bbs, depth - 1, state, avoid)) { - r_list_prepend (bbs, bb); - r_list_free (refs); + rz_list_prepend (bbs, bb); + rz_list_free (refs); return true; } } } } } - r_list_free (refs); + rz_list_free (refs); } return false; } -static RList *anal_graph_to(RCore *core, ut64 addr, int depth, HtUP *avoid) { - RAnalFunction *cur_fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - RList *list = r_list_new (); +static RzList *anal_graph_to(RzCore *core, ut64 addr, int depth, HtUP *avoid) { + RzAnalFunction *cur_fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + RzList *list = rz_list_new (); HtUP *state = ht_up_new0 (); if (!list || !state || !cur_fcn) { - r_list_free (list); + rz_list_free (list); ht_up_free (state); return NULL; } @@ -3530,19 +3530,19 @@ static RList *anal_graph_to(RCore *core, ut64 addr, int depth, HtUP *avoid) { } // backward search - RList *xrefs = r_anal_xrefs_get (core->anal, cur_fcn->addr); + RzList *xrefs = rz_anal_xrefs_get (core->anal, cur_fcn->addr); if (xrefs) { - RListIter *iter; - RAnalRef *xref = NULL; - r_list_foreach (xrefs, iter, xref) { + RzListIter *iter; + RzAnalRef *xref = NULL; + rz_list_foreach (xrefs, iter, xref) { if (xref->type == R_ANAL_REF_TYPE_CALL) { ut64 offset = core->offset; core->offset = xref->addr; - r_list_free (list); + rz_list_free (list); list = anal_graph_to (core, addr, depth - 1, avoid); core->offset = offset; - if (list && r_list_length (list)) { - r_list_free (xrefs); + if (list && rz_list_length (list)) { + rz_list_free (xrefs); ht_up_free (state); return list; } @@ -3550,22 +3550,22 @@ static RList *anal_graph_to(RCore *core, ut64 addr, int depth, HtUP *avoid) { } } - r_list_free (xrefs); + rz_list_free (xrefs); ht_up_free (state); - r_list_free (list); + rz_list_free (list); return NULL; } -R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n) { - int depth = r_config_get_i (core->config, "anal.graph_depth"); - RList *path, *paths = r_list_new (); +RZ_API RzList* rz_core_anal_graph_to(RzCore *core, ut64 addr, int n) { + int depth = rz_config_get_i (core->config, "anal.graph_depth"); + RzList *path, *paths = rz_list_new (); HtUP *avoid = ht_up_new0 (); while (n) { path = anal_graph_to (core, addr, depth, avoid); if (path) { - r_list_append (paths, path); - if (r_list_length (path) >= 2) { - RAnalBlock *last = r_list_get_n (path, r_list_length (path) - 2); + rz_list_append (paths, path); + if (rz_list_length (path) >= 2) { + RzAnalBlock *last = rz_list_get_n (path, rz_list_length (path) - 2); ht_up_update (avoid, last->addr, last); n--; continue; @@ -3578,44 +3578,44 @@ R_API RList* r_core_anal_graph_to(RCore *core, ut64 addr, int n) { return paths; } -R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) { - ut64 from = r_config_get_i (core->config, "graph.from"); - ut64 to = r_config_get_i (core->config, "graph.to"); - const char *font = r_config_get (core->config, "graph.font"); - int is_html = r_cons_singleton ()->is_html; +RZ_API int rz_core_anal_graph(RzCore *core, ut64 addr, int opts) { + ut64 from = rz_config_get_i (core->config, "graph.from"); + ut64 to = rz_config_get_i (core->config, "graph.to"); + const char *font = rz_config_get (core->config, "graph.font"); + int is_html = rz_cons_singleton ()->is_html; int is_json = opts & R_CORE_ANAL_JSON; int is_json_format_disasm = opts & R_CORE_ANAL_JSON_FORMAT_DISASM; int is_keva = opts & R_CORE_ANAL_KEYVALUE; int is_star = opts & R_CORE_ANAL_STAR; RConfigHold *hc; - RAnalFunction *fcni; - RListIter *iter; + RzAnalFunction *fcni; + RzListIter *iter; int nodes = 0; PJ *pj = NULL; if (!addr) { addr = core->offset; } - if (r_list_empty (core->anal->fcns)) { + if (rz_list_empty (core->anal->fcns)) { return false; } - hc = r_config_hold_new (core->config); + hc = rz_config_hold_new (core->config); if (!hc) { return false; } - r_config_hold_i (hc, "asm.lines", "asm.bytes", "asm.dwarf", NULL); + rz_config_hold_i (hc, "asm.lines", "asm.bytes", "asm.dwarf", NULL); //opts |= R_CORE_ANAL_GRAPHBODY; - r_config_set_i (core->config, "asm.lines", 0); - r_config_set_i (core->config, "asm.dwarf", 0); + rz_config_set_i (core->config, "asm.lines", 0); + rz_config_set_i (core->config, "asm.dwarf", 0); if (!is_json_format_disasm) { - r_config_hold_i (hc, "asm.bytes", NULL); - r_config_set_i (core->config, "asm.bytes", 0); + rz_config_hold_i (hc, "asm.bytes", NULL); + rz_config_set_i (core->config, "asm.bytes", 0); } if (!is_html && !is_json && !is_keva && !is_star) { - const char * gv_edge = r_config_get (core->config, "graph.gv.edge"); - const char * gv_node = r_config_get (core->config, "graph.gv.node"); - const char * gv_spline = r_config_get (core->config, "graph.gv.spline"); + const char * gv_edge = rz_config_get (core->config, "graph.gv.edge"); + const char * gv_node = rz_config_get (core->config, "graph.gv.node"); + const char * gv_spline = rz_config_get (core->config, "graph.gv.spline"); if (!gv_edge || !*gv_edge) { gv_edge = "arrowhead=\"normal\""; } @@ -3625,7 +3625,7 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) { if (!gv_spline || !*gv_spline) { gv_spline = "splines=\"ortho\""; } - r_cons_printf ("digraph code {\n" + rz_cons_printf ("digraph code {\n" "\tgraph [bgcolor=azure fontsize=8 fontname=\"%s\" %s];\n" "\tnode [%s];\n" "\tedge [%s];\n", font, gv_spline, gv_node, gv_edge); @@ -3633,16 +3633,16 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) { if (is_json) { pj = pj_new (); if (!pj) { - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return false; } pj_a (pj); } - r_list_foreach (core->anal->fcns, iter, fcni) { + rz_list_foreach (core->anal->fcns, iter, fcni) { if (fcni->type & (R_ANAL_FCN_TYPE_SYM | R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_LOC) && - (addr == UT64_MAX || r_anal_get_fcn_in (core->anal, addr, 0) == fcni)) { + (addr == UT64_MAX || rz_anal_get_fcn_in (core->anal, addr, 0) == fcni)) { if (addr == UT64_MAX && (from != UT64_MAX && to != UT64_MAX)) { if (fcni->addr < from || fcni->addr > to) { continue; @@ -3656,36 +3656,36 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) { } if (!nodes) { if (!is_html && !is_json && !is_keva) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (is_star) { char *name = get_title(fcn ? fcn->addr: addr); - r_cons_printf ("agn %s;", name); + rz_cons_printf ("agn %s;", name); }else { - r_cons_printf ("\t\"0x%08"PFMT64x"\";\n", fcn? fcn->addr: addr); + rz_cons_printf ("\t\"0x%08"PFMT64x"\";\n", fcn? fcn->addr: addr); } } } if (!is_keva && !is_html && !is_json && !is_star && !is_json_format_disasm) { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } if (is_json) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return true; } -static int core_anal_followptr(RCore *core, int type, ut64 at, ut64 ptr, ut64 ref, int code, int depth) { +static int core_anal_followptr(RzCore *core, int type, ut64 at, ut64 ptr, ut64 ref, int code, int depth) { // SLOW Operation try to reduce as much as possible if (!ptr) { return false; } if (ref == UT64_MAX || ptr == ref) { - const RAnalRefType t = code? type? type: R_ANAL_REF_TYPE_CODE: R_ANAL_REF_TYPE_DATA; - r_anal_xrefs_set (core->anal, at, ptr, t); + const RzAnalRefType t = code? type? type: R_ANAL_REF_TYPE_CODE: R_ANAL_REF_TYPE_DATA; + rz_anal_xrefs_set (core->anal, at, ptr, t); return true; } if (depth < 1) { @@ -3693,14 +3693,14 @@ static int core_anal_followptr(RCore *core, int type, ut64 at, ut64 ptr, ut64 re } int wordsize = (int)(core->anal->bits / 8); ut64 dataptr; - if (!r_io_read_i (core->io, ptr, &dataptr, wordsize, false)) { + if (!rz_io_read_i (core->io, ptr, &dataptr, wordsize, false)) { // eprintf ("core_anal_followptr: Cannot read word at destination\n"); return false; } return core_anal_followptr (core, type, at, dataptr, ref, code, depth - 1); } -static bool opiscall(RCore *core, RAnalOp *aop, ut64 addr, const ut8* buf, int len, int arch) { +static bool opiscall(RzCore *core, RzAnalOp *aop, ut64 addr, const ut8* buf, int len, int arch) { switch (arch) { case R2_ARCH_ARM64: aop->size = 4; @@ -3712,14 +3712,14 @@ static bool opiscall(RCore *core, RAnalOp *aop, ut64 addr, const ut8* buf, int l } //if is not bl do not analyze if (buf[3] == 0x94) { - if (r_anal_op (core->anal, aop, addr, buf, len, R_ANAL_OP_MASK_BASIC)) { + if (rz_anal_op (core->anal, aop, addr, buf, len, R_ANAL_OP_MASK_BASIC)) { return true; } } break; default: aop->size = 1; - if (r_anal_op (core->anal, aop, addr, buf, len, R_ANAL_OP_MASK_BASIC)) { + if (rz_anal_op (core->anal, aop, addr, buf, len, R_ANAL_OP_MASK_BASIC)) { switch (aop->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_CALL: case R_ANAL_OP_TYPE_CCALL: @@ -3733,14 +3733,14 @@ static bool opiscall(RCore *core, RAnalOp *aop, ut64 addr, const ut8* buf, int l // TODO(maskray) RAddrInterval API #define OPSZ 8 -R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode) { +RZ_API int rz_core_anal_search(RzCore *core, ut64 from, ut64 to, ut64 ref, int mode) { ut8 *buf = (ut8 *)malloc (core->blocksize); if (!buf) { return -1; } - int ptrdepth = r_config_get_i (core->config, "anal.ptrdepth"); + int ptrdepth = rz_config_get_i (core->config, "anal.ptrdepth"); int i, count = 0; - RAnalOp op = R_EMPTY; + RzAnalOp op = R_EMPTY; ut64 at; char bckwrds, do_bckwrd_srch; int arch = -1; @@ -3755,14 +3755,14 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode // XXX must read bytes correctly do_bckwrd_srch = bckwrds = core->search->bckwrds; if (core->file) { - r_io_use_fd (core->io, core->file->fd); + rz_io_use_fd (core->io, core->file->fd); } if (!ref) { eprintf ("Null reference search is not supported\n"); free (buf); return -1; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); if (core->blocksize > OPSZ) { if (bckwrds) { if (from + core->blocksize > to) { @@ -3776,11 +3776,11 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode } while ((!bckwrds && at < to) || bckwrds) { eprintf ("\r[0x%08"PFMT64x"-0x%08"PFMT64x"] ", at, to); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // TODO: this can be probably enhanced - if (!r_io_read_at (core->io, at, buf, core->blocksize)) { + if (!rz_io_read_at (core->io, at, buf, core->blocksize)) { eprintf ("Failed to read at 0x%08" PFMT64x "\n", at); break; } @@ -3789,7 +3789,7 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode (bckwrds && i > 0); bckwrds ? i-- : i++) { // TODO: honor anal.align - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } switch (mode) { @@ -3803,18 +3803,18 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode case 'w': case 'x': { - r_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC); + rz_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC); int mask = mode=='r' ? 1 : mode == 'w' ? 2: mode == 'x' ? 4: 0; if (op.direction == mask) { i += op.size; } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); continue; } break; default: - if (!r_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC)) { - r_anal_op_fini (&op); + if (!rz_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC)) { + rz_anal_op_fini (&op); continue; } } @@ -3851,8 +3851,8 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode break; default: { - if (!r_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC)) { - r_anal_op_fini (&op); + if (!rz_anal_op (core->anal, &op, at + i, buf + i, core->blocksize - i, R_ANAL_OP_MASK_BASIC)) { + rz_anal_op_fini (&op); continue; } } @@ -3866,7 +3866,7 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode op.size = 1; } i += op.size - 1; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } if (bckwrds) { if (!do_bckwrd_srch) { @@ -3885,13 +3885,13 @@ R_API int r_core_anal_search(RCore *core, ut64 from, ut64 to, ut64 ref, int mode } else { eprintf ("error: block size too small\n"); } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); - r_anal_op_fini (&op); + rz_anal_op_fini (&op); return count; } -static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, int count, int rad, int cfg_debug, bool cfg_anal_strings) { +static bool found_xref(RzCore *core, ut64 at, ut64 xref_to, RzAnalRefType type, int count, int rad, int cfg_debug, bool cfg_anal_strings) { // Validate the reference. If virtual addressing is enabled, we // allow only references to virtual addresses in order to reduce // the number of false positives. In debugger mode, the reference @@ -3900,11 +3900,11 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, in return false; } if (cfg_debug) { - if (!r_debug_map_get (core->dbg, xref_to)) { + if (!rz_debug_map_get (core->dbg, xref_to)) { return false; } } else if (core->io->va) { - if (!r_io_is_valid_offset (core->io, xref_to, 0)) { + if (!rz_io_is_valid_offset (core->io, xref_to, 0)) { return false; } } @@ -3913,14 +3913,14 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, in int len = 0; char *str_string = is_string_at (core, xref_to, &len); if (str_string) { - r_name_filter (str_string, -1); - char *str_flagname = r_str_newf ("str.%s", str_string); - r_flag_space_push (core->flags, R_FLAGS_FS_STRINGS); - (void)r_flag_set (core->flags, str_flagname, xref_to, 1); - r_flag_space_pop (core->flags); + rz_name_filter (str_string, -1); + char *str_flagname = rz_str_newf ("str.%s", str_string); + rz_flag_space_push (core->flags, R_FLAGS_FS_STRINGS); + (void)rz_flag_set (core->flags, str_flagname, xref_to, 1); + rz_flag_space_pop (core->flags); free (str_flagname); if (len > 0) { - r_meta_set (core->anal, R_META_TYPE_STRING, xref_to, + rz_meta_set (core->anal, R_META_TYPE_STRING, xref_to, len, (const char *) str_string); } free (str_string); @@ -3928,14 +3928,14 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, in } // Add to SDB if (xref_to) { - r_anal_xrefs_set (core->anal, at, xref_to, type); + rz_anal_xrefs_set (core->anal, at, xref_to, type); } } else if (rad == 'j') { // Output JSON if (count > 0) { - r_cons_printf (","); + rz_cons_printf (","); } - r_cons_printf ("\"0x%"PFMT64x"\":\"0x%"PFMT64x"\"", xref_to, at); + rz_cons_printf ("\"0x%"PFMT64x"\":\"0x%"PFMT64x"\"", xref_to, at); } else { int len = 0; // Display in radare commands format @@ -3946,14 +3946,14 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, in case R_ANAL_REF_TYPE_DATA: cmd = "axd"; break; default: cmd = "ax"; break; } - r_cons_printf ("%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n", cmd, xref_to, at); + rz_cons_printf ("%s 0x%08"PFMT64x" 0x%08"PFMT64x"\n", cmd, xref_to, at); if (cfg_anal_strings && type == R_ANAL_REF_TYPE_DATA) { char *str_flagname = is_string_at (core, xref_to, &len); if (str_flagname) { ut64 str_addr = xref_to; - r_name_filter (str_flagname, -1); - r_cons_printf ("f str.%s=0x%"PFMT64x"\n", str_flagname, str_addr); - r_cons_printf ("Cs %d @ 0x%"PFMT64x"\n", len, str_addr); + rz_name_filter (str_flagname, -1); + rz_cons_printf ("f str.%s=0x%"PFMT64x"\n", str_flagname, str_addr); + rz_cons_printf ("Cs %d @ 0x%"PFMT64x"\n", len, str_addr); free (str_flagname); } } @@ -3961,13 +3961,13 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, in return true; } -R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad) { - int cfg_debug = r_config_get_i (core->config, "cfg.debug"); - bool cfg_anal_strings = r_config_get_i (core->config, "anal.strings"); +RZ_API int rz_core_anal_search_xrefs(RzCore *core, ut64 from, ut64 to, int rad) { + int cfg_debug = rz_config_get_i (core->config, "cfg.debug"); + bool cfg_anal_strings = rz_config_get_i (core->config, "anal.strings"); ut64 at; int count = 0; const int bsz = 8096; - RAnalOp op = { 0 }; + RzAnalOp op = { 0 }; if (from == to) { return -1; @@ -3993,15 +3993,15 @@ R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad) { free (buf); return -1; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); at = from; - st64 asm_sub_varmin = r_config_get_i (core->config, "asm.sub.varmin"); - while (at < to && !r_cons_is_breaked ()) { + st64 asm_sub_varmin = rz_config_get_i (core->config, "asm.sub.varmin"); + while (at < to && !rz_cons_is_breaked ()) { int i = 0, ret = bsz; - if (!r_io_is_valid_offset (core->io, at, R_PERM_X)) { + if (!rz_io_is_valid_offset (core->io, at, R_PERM_X)) { break; } - (void)r_io_read_at (core->io, at, buf, bsz); + (void)rz_io_read_at (core->io, at, buf, bsz); memset (block, -1, bsz); if (!memcmp (buf, block, bsz)) { // eprintf ("Error: skipping uninitialized block \n"); @@ -4014,8 +4014,8 @@ R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad) { at += ret; continue; } - while (i < bsz && !r_cons_is_breaked ()) { - ret = r_anal_op (core->anal, &op, at + i, buf + i, bsz - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); + while (i < bsz && !rz_cons_is_breaked ()) { + ret = rz_anal_op (core->anal, &op, at + i, buf + i, bsz - i, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); ret = ret > 0 ? ret : 1; i += ret; if (ret <= 0 || i > bsz) { @@ -4074,12 +4074,12 @@ R_API int r_core_anal_search_xrefs(RCore *core, ut64 from, ut64 to, int rad) { default: break; } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } at += bsz; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); free (block); return count; @@ -4095,7 +4095,7 @@ static bool isValidSymbol(RBinSymbol *symbol) { static bool isSkippable(RBinSymbol *s) { if (s && s->name && s->bind) { - if (r_str_startswith (s->name, "radr://")) { + if (rz_str_startswith (s->name, "radr://")) { return true; } if (!strcmp (s->name, "__mh_execute_header")) { @@ -4110,34 +4110,34 @@ static bool isSkippable(RBinSymbol *s) { return false; } -R_API int r_core_anal_all(RCore *core) { - RList *list; - RListIter *iter; - RFlagItem *item; - RAnalFunction *fcni; +RZ_API int rz_core_anal_all(RzCore *core) { + RzList *list; + RzListIter *iter; + RzFlagItem *item; + RzAnalFunction *fcni; RBinAddr *binmain; RBinAddr *entry; RBinSymbol *symbol; int depth = core->anal->opt.depth; - bool anal_vars = r_config_get_i (core->config, "anal.vars"); + bool anal_vars = rz_config_get_i (core->config, "anal.vars"); /* Analyze Functions */ /* Entries */ - item = r_flag_get (core->flags, "entry0"); + item = rz_flag_get (core->flags, "entry0"); if (item) { - r_core_anal_fcn (core, item->offset, -1, R_ANAL_REF_TYPE_NULL, depth - 1); - r_core_cmdf (core, "afn entry0 0x%08"PFMT64x, item->offset); + rz_core_anal_fcn (core, item->offset, -1, R_ANAL_REF_TYPE_NULL, depth - 1); + rz_core_cmdf (core, "afn entry0 0x%08"PFMT64x, item->offset); } else { - r_core_cmd0 (core, "af"); + rz_core_cmd0 (core, "af"); } - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); - r_cons_break_push (NULL, NULL); - /* Symbols (Imports are already analyzed by rabin2 on init) */ - if ((list = r_bin_get_symbols (core->bin)) != NULL) { - r_list_foreach (list, iter, symbol) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + /* Symbols (Imports are already analyzed by rz_bin on init) */ + if ((list = rz_bin_get_symbols (core->bin)) != NULL) { + rz_list_foreach (list, iter, symbol) { + if (rz_cons_is_breaked ()) { break; } // Stop analyzing PE imports further @@ -4145,49 +4145,49 @@ R_API int r_core_anal_all(RCore *core) { continue; } if (isValidSymbol (symbol)) { - ut64 addr = r_bin_get_vaddr (core->bin, symbol->paddr, + ut64 addr = rz_bin_get_vaddr (core->bin, symbol->paddr, symbol->vaddr); - r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); + rz_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); } } } - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); /* Main */ - if ((binmain = r_bin_get_sym (core->bin, R_BIN_SYM_MAIN))) { + if ((binmain = rz_bin_get_sym (core->bin, R_BIN_SYM_MAIN))) { if (binmain->paddr != UT64_MAX) { - ut64 addr = r_bin_get_vaddr (core->bin, binmain->paddr, binmain->vaddr); - r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); + ut64 addr = rz_bin_get_vaddr (core->bin, binmain->paddr, binmain->vaddr); + rz_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); } } - r_core_task_yield (&core->tasks); - if ((list = r_bin_get_entries (core->bin))) { - r_list_foreach (list, iter, entry) { + rz_core_task_yield (&core->tasks); + if ((list = rz_bin_get_entries (core->bin))) { + rz_list_foreach (list, iter, entry) { if (entry->paddr == UT64_MAX) { continue; } - ut64 addr = r_bin_get_vaddr (core->bin, entry->paddr, entry->vaddr); - r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); + ut64 addr = rz_bin_get_vaddr (core->bin, entry->paddr, entry->vaddr); + rz_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth - 1); } } - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); if (anal_vars) { /* Set fcn type to R_ANAL_FCN_TYPE_SYM for symbols */ - r_list_foreach_prev (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + rz_list_foreach_prev (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } - r_core_recover_vars (core, fcni, true); + rz_core_recover_vars (core, fcni, true); if (!strncmp (fcni->name, "sym.", 4) || !strncmp (fcni->name, "main", 4)) { fcni->type = R_ANAL_FCN_TYPE_SYM; } } } - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -R_API int r_core_anal_data(RCore *core, ut64 addr, int count, int depth, int wordsize) { - RAnalData *d; +RZ_API int rz_core_anal_data(RzCore *core, ut64 addr, int count, int depth, int wordsize) { + RzAnalData *d; ut64 dstaddr = 0LL; ut8 *buf = core->block; int len = core->blocksize; @@ -4201,32 +4201,32 @@ R_API int r_core_anal_data(RCore *core, ut64 addr, int count, int depth, int wor return false; } memset (buf, 0xff, len); - r_io_read_at (core->io, addr, buf, len); + rz_io_read_at (core->io, addr, buf, len); buf[len - 1] = 0; - RConsPrintablePalette *pal = r_config_get_i (core->config, "scr.color")? &r_cons_singleton ()->context->pal: NULL; + RzConsPrintablePalette *pal = rz_config_get_i (core->config, "scr.color")? &rz_cons_singleton ()->context->pal: NULL; for (i = j = 0; j < count; j++) { if (i >= len) { - r_io_read_at (core->io, addr + i, buf, len); + rz_io_read_at (core->io, addr + i, buf, len); buf[len] = 0; addr += i; i = 0; continue; } - /* r_anal_data requires null-terminated buffer according to coverity */ + /* rz_anal_data requires null-terminated buffer according to coverity */ /* but it should not.. so this must be fixed in anal/data.c instead of */ /* null terminating here */ - d = r_anal_data (core->anal, addr + i, buf + i, len - i, wordsize); - str = r_anal_data_to_string (d, pal); - r_cons_println (str); + d = rz_anal_data (core->anal, addr + i, buf + i, len - i, wordsize); + str = rz_anal_data_to_string (d, pal); + rz_cons_println (str); if (d) { switch (d->type) { case R_ANAL_DATA_TYPE_POINTER: - r_cons_printf ("`- "); - dstaddr = r_mem_get_num (buf + i, word); + rz_cons_printf ("`- "); + dstaddr = rz_mem_get_num (buf + i, word); if (depth > 0) { - r_core_anal_data (core, dstaddr, 1, depth - 1, wordsize); + rz_core_anal_data (core, dstaddr, 1, depth - 1, wordsize); } i += word; break; @@ -4242,7 +4242,7 @@ R_API int r_core_anal_data(RCore *core, ut64 addr, int count, int depth, int wor i += word; } free (str); - r_anal_data_free (d); + rz_anal_data_free (d); } free (buf); return true; @@ -4251,10 +4251,10 @@ R_API int r_core_anal_data(RCore *core, ut64 addr, int count, int depth, int wor struct block_flags_stat_t { ut64 step; ut64 from; - RCoreAnalStats *as; + RzCoreAnalStats *as; }; -static bool block_flags_stat(RFlagItem *fi, void *user) { +static bool block_flags_stat(RzFlagItem *fi, void *user) { struct block_flags_stat_t *u = (struct block_flags_stat_t *)user; int piece = (fi->offset - u->from) / u->step; u->as->block[piece].flags++; @@ -4263,12 +4263,12 @@ static bool block_flags_stat(RFlagItem *fi, void *user) { /* core analysis stats */ /* stats --- colorful bar */ -R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut64 step) { - RAnalFunction *F; - RAnalBlock *B; +RZ_API RzCoreAnalStats* rz_core_anal_get_stats(RzCore *core, ut64 from, ut64 to, ut64 step) { + RzAnalFunction *F; + RzAnalBlock *B; RBinSymbol *S; - RListIter *iter, *iter2; - RCoreAnalStats *as = NULL; + RzListIter *iter, *iter2; + RzCoreAnalStats *as = NULL; int piece, as_size, blocks; ut64 at; @@ -4276,7 +4276,7 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6 eprintf ("Cannot alloc for this range\n"); return NULL; } - as = R_NEW0 (RCoreAnalStats); + as = R_NEW0 (RzCoreAnalStats); if (!as) { return NULL; } @@ -4284,7 +4284,7 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6 step = 1; } blocks = (to - from) / step; - as_size = (1 + blocks) * sizeof (RCoreAnalStatsItem); + as_size = (1 + blocks) * sizeof (RzCoreAnalStatsItem); as->block = malloc (as_size); if (!as->block) { free (as); @@ -4292,26 +4292,26 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6 } memset (as->block, 0, as_size); for (at = from; at < to; at += step) { - RIOMap *map = r_io_map_get (core->io, at); + RzIOMap *map = rz_io_map_get (core->io, at); piece = (at - from) / step; as->block[piece].perm = map ? map->perm: (core->io->desc ? core->io->desc->perm: 0); } // iter all flags struct block_flags_stat_t u = { .step = step, .from = from, .as = as }; - r_flag_foreach_range (core->flags, from, to + 1, block_flags_stat, &u); + rz_flag_foreach_range (core->flags, from, to + 1, block_flags_stat, &u); // iter all functions - r_list_foreach (core->anal->fcns, iter, F) { + rz_list_foreach (core->anal->fcns, iter, F) { if (F->addr < from || F->addr > to) { continue; } piece = (F->addr - from) / step; as->block[piece].functions++; - ut64 last_piece = R_MIN ((F->addr + r_anal_function_linear_size (F) - 1) / step, blocks - 1); + ut64 last_piece = R_MIN ((F->addr + rz_anal_function_linear_size (F) - 1) / step, blocks - 1); for (; piece <= last_piece; piece++) { as->block[piece].in_functions++; } // iter all basic blocks - r_list_foreach (F->bbs, iter2, B) { + rz_list_foreach (F->bbs, iter2, B) { if (B->addr < from || B->addr > to) { continue; } @@ -4320,19 +4320,19 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6 } } // iter all symbols - r_list_foreach (r_bin_get_symbols (core->bin), iter, S) { + rz_list_foreach (rz_bin_get_symbols (core->bin), iter, S) { if (S->vaddr < from || S->vaddr > to) { continue; } piece = (S->vaddr - from) / step; as->block[piece].symbols++; } - RPVector *metas = to > from ? r_meta_get_all_intersect (core->anal, from, to - from, R_META_TYPE_ANY) : NULL; + RPVector *metas = to > from ? rz_meta_get_all_intersect (core->anal, from, to - from, R_META_TYPE_ANY) : NULL; if (metas) { void **it; - r_pvector_foreach (metas, it) { + rz_pvector_foreach (metas, it) { RIntervalNode *node = *it; - RAnalMetaItem *mi = node->data; + RzAnalMetaItem *mi = node->data; if (node->start < from || node->end > to) { continue; } @@ -4348,33 +4348,33 @@ R_API RCoreAnalStats* r_core_anal_get_stats(RCore *core, ut64 from, ut64 to, ut6 break; } } - r_pvector_free (metas); + rz_pvector_free (metas); } return as; } -R_API void r_core_anal_stats_free(RCoreAnalStats *s) { +RZ_API void rz_core_anal_stats_free(RzCoreAnalStats *s) { if (s) { free (s->block); } free (s); } -R_API RList* r_core_anal_cycles(RCore *core, int ccl) { +RZ_API RzList* rz_core_anal_cycles(RzCore *core, int ccl) { ut64 addr = core->offset; int depth = 0; - RAnalOp *op = NULL; - RAnalCycleFrame *prev = NULL, *cf = NULL; - RAnalCycleHook *ch; - RList *hooks = r_list_new (); + RzAnalOp *op = NULL; + RzAnalCycleFrame *prev = NULL, *cf = NULL; + RzAnalCycleHook *ch; + RzList *hooks = rz_list_new (); if (!hooks) { return NULL; } - cf = r_anal_cycle_frame_new (); - r_cons_break_push (NULL, NULL); - while (cf && !r_cons_is_breaked ()) { - if ((op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC)) && (op->cycles) && (ccl > 0)) { - r_cons_clear_line (1); + cf = rz_anal_cycle_frame_new (); + rz_cons_break_push (NULL, NULL); + while (cf && !rz_cons_is_breaked ()) { + if ((op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC)) && (op->cycles) && (ccl > 0)) { + rz_cons_clear_line (1); eprintf ("%i -- ", ccl); addr += op->size; switch (op->type) { @@ -4389,20 +4389,20 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { case R_ANAL_OP_TYPE_ICALL: case R_ANAL_OP_TYPE_RCALL: case R_ANAL_OP_TYPE_IRCALL: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); ch->addr = op->addr; eprintf ("0x%08"PFMT64x" > ?\r", op->addr); ch->cycles = ccl; - r_list_append (hooks, ch); + rz_list_append (hooks, ch); ch = NULL; while (!ch && cf) { - ch = r_list_pop (cf->hooks); + ch = rz_list_pop (cf->hooks); if (ch) { addr = ch->addr; ccl = ch->cycles; free (ch); } else { - r_anal_cycle_frame_free (cf); + rz_anal_cycle_frame_free (cf); cf = prev; if (cf) { prev = cf->prev; @@ -4411,35 +4411,35 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { } break; case R_ANAL_OP_TYPE_CJMP: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); ch->addr = addr; ch->cycles = ccl - op->failcycles; - r_list_push (cf->hooks, ch); + rz_list_push (cf->hooks, ch); ch = NULL; addr = op->jump; loganal (op->addr, addr, depth); break; case R_ANAL_OP_TYPE_UCJMP: case R_ANAL_OP_TYPE_UCCALL: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); ch->addr = op->addr; ch->cycles = ccl; - r_list_append (hooks, ch); + rz_list_append (hooks, ch); ch = NULL; ccl -= op->failcycles; eprintf ("0x%08"PFMT64x" > ?\r", op->addr); break; case R_ANAL_OP_TYPE_CCALL: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); ch->addr = addr; ch->cycles = ccl - op->failcycles; - r_list_push (cf->hooks, ch); + rz_list_push (cf->hooks, ch); ch = NULL; case R_ANAL_OP_TYPE_CALL: if (op->addr != op->jump) { //no selfies cf->naddr = addr; prev = cf; - cf = r_anal_cycle_frame_new (); + cf = rz_anal_cycle_frame_new (); cf->prev = prev; } ccl -= op->cycles; @@ -4447,28 +4447,28 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { loganal (op->addr, addr, depth - 1); break; case R_ANAL_OP_TYPE_RET: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); if (prev) { ch->addr = prev->naddr; ccl -= op->cycles; ch->cycles = ccl; - r_list_push (prev->hooks, ch); + rz_list_push (prev->hooks, ch); eprintf ("0x%08"PFMT64x" < 0x%08"PFMT64x"\r", prev->naddr, op->addr); } else { ch->addr = op->addr; ch->cycles = ccl; - r_list_append (hooks, ch); + rz_list_append (hooks, ch); eprintf ("? < 0x%08"PFMT64x"\r", op->addr); } ch = NULL; while (!ch && cf) { - ch = r_list_pop (cf->hooks); + ch = rz_list_pop (cf->hooks); if (ch) { addr = ch->addr; ccl = ch->cycles; free (ch); } else { - r_anal_cycle_frame_free (cf); + rz_anal_cycle_frame_free (cf); cf = prev; if (cf) { prev = cf->prev; @@ -4477,16 +4477,16 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { } break; case R_ANAL_OP_TYPE_CRET: - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); if (prev) { ch->addr = prev->naddr; ch->cycles = ccl - op->cycles; - r_list_push (prev->hooks, ch); + rz_list_push (prev->hooks, ch); eprintf ("0x%08"PFMT64x" < 0x%08"PFMT64x"\r", prev->naddr, op->addr); } else { ch->addr = op->addr; ch->cycles = ccl - op->cycles; - r_list_append (hooks, ch); + rz_list_append (hooks, ch); eprintf ("? < 0x%08"PFMT64x"\r", op->addr); } ccl -= op->failcycles; @@ -4497,24 +4497,24 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { break; } } else { - ch = R_NEW0 (RAnalCycleHook); + ch = R_NEW0 (RzAnalCycleHook); if (!ch) { - r_anal_cycle_frame_free (cf); - r_list_free (hooks); + rz_anal_cycle_frame_free (cf); + rz_list_free (hooks); return NULL; } ch->addr = addr; ch->cycles = ccl; - r_list_append (hooks, ch); + rz_list_append (hooks, ch); ch = NULL; while (!ch && cf) { - ch = r_list_pop (cf->hooks); + ch = rz_list_pop (cf->hooks); if (ch) { addr = ch->addr; ccl = ch->cycles; free (ch); } else { - r_anal_cycle_frame_free (cf); + rz_anal_cycle_frame_free (cf); cf = prev; if (cf) { prev = cf->prev; @@ -4522,46 +4522,46 @@ R_API RList* r_core_anal_cycles(RCore *core, int ccl) { } } } - r_anal_op_free (op); + rz_anal_op_free (op); } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { while (cf) { - ch = r_list_pop (cf->hooks); + ch = rz_list_pop (cf->hooks); while (ch) { free (ch); - ch = r_list_pop (cf->hooks); + ch = rz_list_pop (cf->hooks); } prev = cf->prev; - r_anal_cycle_frame_free (cf); + rz_anal_cycle_frame_free (cf); cf = prev; } } - r_cons_break_pop (); + rz_cons_break_pop (); return hooks; } -R_API void r_core_anal_undefine(RCore *core, ut64 off) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, off, -1); +RZ_API void rz_core_anal_undefine(RzCore *core, ut64 off) { + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, off, -1); if (f) { if (!strncmp (f->name, "fcn.", 4)) { - r_flag_unset_name (core->flags, f->name); + rz_flag_unset_name (core->flags, f->name); } - r_meta_del (core->anal, R_META_TYPE_ANY, r_anal_function_min_addr (f), r_anal_function_linear_size (f)); + rz_meta_del (core->anal, R_META_TYPE_ANY, rz_anal_function_min_addr (f), rz_anal_function_linear_size (f)); } - r_anal_fcn_del_locs (core->anal, off); - r_anal_fcn_del (core->anal, off); + rz_anal_fcn_del_locs (core->anal, off); + rz_anal_fcn_del (core->anal, off); } /* Join function at addr2 into function at addr */ // addr use to be core->offset -R_API void r_core_anal_fcn_merge(RCore *core, ut64 addr, ut64 addr2) { - RListIter *iter; +RZ_API void rz_core_anal_fcn_merge(RzCore *core, ut64 addr, ut64 addr2) { + RzListIter *iter; ut64 min = 0; ut64 max = 0; int first = 1; - RAnalBlock *bb; - RAnalFunction *f1 = r_anal_get_function_at (core->anal, addr); - RAnalFunction *f2 = r_anal_get_function_at (core->anal, addr2); + RzAnalBlock *bb; + RzAnalFunction *f1 = rz_anal_get_function_at (core->anal, addr); + RzAnalFunction *f2 = rz_anal_get_function_at (core->anal, addr2); if (!f1 || !f2) { eprintf ("Cannot find function\n"); return; @@ -4573,7 +4573,7 @@ R_API void r_core_anal_fcn_merge(RCore *core, ut64 addr, ut64 addr2) { // join all basic blocks from f1 into f2 if they are not // delete f2 eprintf ("Merge 0x%08"PFMT64x" into 0x%08"PFMT64x"\n", addr, addr2); - r_list_foreach (f1->bbs, iter, bb) { + rz_list_foreach (f1->bbs, iter, bb) { if (first) { min = bb->addr; max = bb->addr + bb->size; @@ -4587,7 +4587,7 @@ R_API void r_core_anal_fcn_merge(RCore *core, ut64 addr, ut64 addr2) { } } } - r_list_foreach (f2->bbs, iter, bb) { + rz_list_foreach (f2->bbs, iter, bb) { if (first) { min = bb->addr; max = bb->addr + bb->size; @@ -4600,12 +4600,12 @@ R_API void r_core_anal_fcn_merge(RCore *core, ut64 addr, ut64 addr2) { max = bb->addr + bb->size; } } - r_anal_function_add_block (f1, bb); + rz_anal_function_add_block (f1, bb); } // TODO: import data/code/refs - r_anal_function_delete (f2); + rz_anal_function_delete (f2); // update size - r_anal_function_relocate (f2, R_MIN (addr, addr2)); + rz_anal_function_relocate (f2, R_MIN (addr, addr2)); } static bool esil_anal_stop = false; @@ -4614,7 +4614,7 @@ static void cccb(void *u) { eprintf ("^C\n"); } -static void add_string_ref(RCore *core, ut64 xref_from, ut64 xref_to) { +static void add_string_ref(RzCore *core, ut64 xref_from, ut64 xref_to) { int len = 0; if (xref_to == UT64_MAX || !xref_to) { return; @@ -4624,40 +4624,40 @@ static void add_string_ref(RCore *core, ut64 xref_from, ut64 xref_to) { } char *str_flagname = is_string_at (core, xref_to, &len); if (str_flagname) { - r_anal_xrefs_set (core->anal, xref_from, xref_to, R_ANAL_REF_TYPE_DATA); - r_name_filter (str_flagname, -1); + rz_anal_xrefs_set (core->anal, xref_from, xref_to, R_ANAL_REF_TYPE_DATA); + rz_name_filter (str_flagname, -1); char *flagname = sdb_fmt ("str.%s", str_flagname); - r_flag_space_push (core->flags, R_FLAGS_FS_STRINGS); - r_flag_set (core->flags, flagname, xref_to, len); - r_flag_space_pop (core->flags); - r_meta_set (core->anal, 's', xref_to, len, str_flagname); + rz_flag_space_push (core->flags, R_FLAGS_FS_STRINGS); + rz_flag_set (core->flags, flagname, xref_to, len); + rz_flag_space_pop (core->flags); + rz_meta_set (core->anal, 's', xref_to, len, str_flagname); free (str_flagname); } } // dup with isValidAddress wtf -static bool myvalid(RIO *io, ut64 addr) { +static bool myvalid(RzIO *io, ut64 addr) { if (addr < 0x100) { return false; } if (addr == UT32_MAX || addr == UT64_MAX) { //the best of the best of the best :( return false; } - if (!r_io_is_valid_offset (io, addr, 0)) { + if (!rz_io_is_valid_offset (io, addr, 0)) { return false; } return true; } typedef struct { - RAnalOp *op; - RAnalFunction *fcn; + RzAnalOp *op; + RzAnalFunction *fcn; const char *spname; ut64 initial_sp; } EsilBreakCtx; -static const char *reg_name_for_access(RAnalOp* op, RAnalVarAccessType type) { +static const char *reg_name_for_access(RzAnalOp* op, RzAnalVarAccessType type) { if (type == R_ANAL_VAR_ACCESS_TYPE_READ) { if (op->src[0] && op->src[0]->reg) { return op->src[0]->reg->name; @@ -4668,7 +4668,7 @@ static const char *reg_name_for_access(RAnalOp* op, RAnalVarAccessType type) { return NULL; } -static ut64 delta_for_access(RAnalOp *op, RAnalVarAccessType type) { +static ut64 delta_for_access(RzAnalOp *op, RzAnalVarAccessType type) { if (type == R_ANAL_VAR_ACCESS_TYPE_READ) { if (op->src[1] && op->src[1]->imm) { return op->src[1]->imm; @@ -4682,66 +4682,66 @@ static ut64 delta_for_access(RAnalOp *op, RAnalVarAccessType type) { return 0; } -static void handle_var_stack_access(RAnalEsil *esil, ut64 addr, RAnalVarAccessType type, int len) { +static void handle_var_stack_access(RzAnalEsil *esil, ut64 addr, RzAnalVarAccessType type, int len) { EsilBreakCtx *ctx = esil->user; const char *regname = reg_name_for_access (ctx->op, type); if (ctx->fcn && regname) { - ut64 spaddr = r_reg_getv (esil->anal->reg, ctx->spname); + ut64 spaddr = rz_reg_getv (esil->anal->reg, ctx->spname); if (addr >= spaddr && addr < ctx->initial_sp) { int stack_off = addr - ctx->initial_sp; - RAnalVar *var = r_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, stack_off); + RzAnalVar *var = rz_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, stack_off); if (!var) { - var = r_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_BPV, stack_off); + var = rz_anal_function_get_var (ctx->fcn, R_ANAL_VAR_KIND_BPV, stack_off); } if (!var && stack_off > -ctx->fcn->maxstack) { char *varname; varname = ctx->fcn->anal->opt.varname_stack - ? r_str_newf ("var_%xh", R_ABS (stack_off)) - : r_anal_function_autoname_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, "var", delta_for_access (ctx->op, type)); - var = r_anal_function_set_var (ctx->fcn, stack_off, R_ANAL_VAR_KIND_SPV, NULL, len, false, varname); + ? rz_str_newf ("var_%xh", R_ABS (stack_off)) + : rz_anal_function_autoname_var (ctx->fcn, R_ANAL_VAR_KIND_SPV, "var", delta_for_access (ctx->op, type)); + var = rz_anal_function_set_var (ctx->fcn, stack_off, R_ANAL_VAR_KIND_SPV, NULL, len, false, varname); free (varname); } if (var) { - r_anal_var_set_access (var, regname, ctx->op->addr, type, delta_for_access (ctx->op, type)); + rz_anal_var_set_access (var, regname, ctx->op->addr, type, delta_for_access (ctx->op, type)); } } } } -static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int esilbreak_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { handle_var_stack_access (esil, addr, R_ANAL_VAR_ACCESS_TYPE_WRITE, len); return 1; } -/* TODO: move into RCore? */ +/* TODO: move into RzCore? */ static ut64 esilbreak_last_read = UT64_MAX; static ut64 esilbreak_last_data = UT64_MAX; static ut64 ntarget = UT64_MAX; // TODO differentiate endian-aware mem_read with other reads; move ntarget handling to another function -static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +static int esilbreak_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { ut8 str[128]; if (addr != UT64_MAX) { esilbreak_last_read = addr; } handle_var_stack_access (esil, addr, R_ANAL_VAR_ACCESS_TYPE_READ, len); - if (myvalid (mycore->io, addr) && r_io_read_at (mycore->io, addr, (ut8*)buf, len)) { + if (myvalid (mycore->io, addr) && rz_io_read_at (mycore->io, addr, (ut8*)buf, len)) { ut64 refptr; bool trace = true; switch (len) { case 2: - esilbreak_last_data = refptr = (ut64)r_read_ble16 (buf, esil->anal->big_endian); + esilbreak_last_data = refptr = (ut64)rz_read_ble16 (buf, esil->anal->big_endian); break; case 4: - esilbreak_last_data = refptr = (ut64)r_read_ble32 (buf, esil->anal->big_endian); + esilbreak_last_data = refptr = (ut64)rz_read_ble32 (buf, esil->anal->big_endian); break; case 8: - esilbreak_last_data = refptr = r_read_ble64 (buf, esil->anal->big_endian); + esilbreak_last_data = refptr = rz_read_ble64 (buf, esil->anal->big_endian); break; default: trace = false; - r_io_read_at (mycore->io, addr, (ut8*)buf, len); + rz_io_read_at (mycore->io, addr, (ut8*)buf, len); break; } // TODO incorrect @@ -4749,12 +4749,12 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { if (trace && myvalid (mycore->io, refptr)) { if (ntarget == UT64_MAX || ntarget == refptr) { str[0] = 0; - if (r_io_read_at (mycore->io, refptr, str, sizeof (str)) < 1) { + if (rz_io_read_at (mycore->io, refptr, str, sizeof (str)) < 1) { //eprintf ("Invalid read\n"); str[0] = 0; validRef = false; } else { - r_anal_xrefs_set (mycore->anal, esil->address, refptr, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (mycore->anal, esil->address, refptr, R_ANAL_REF_TYPE_DATA); str[sizeof (str) - 1] = 0; add_string_ref (mycore, esil->address, refptr); esilbreak_last_data = UT64_MAX; @@ -4765,20 +4765,20 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { /** resolve ptr */ if (ntarget == UT64_MAX || ntarget == addr || (ntarget == UT64_MAX && !validRef)) { - r_anal_xrefs_set (mycore->anal, esil->address, addr, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (mycore->anal, esil->address, addr, R_ANAL_REF_TYPE_DATA); } } return 0; // fallback } -static int esilbreak_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { +static int esilbreak_reg_write(RzAnalEsil *esil, const char *name, ut64 *val) { if (!esil) { return 0; } - RAnal *anal = esil->anal; + RzAnal *anal = esil->anal; EsilBreakCtx *ctx = esil->user; - RAnalOp *op = ctx->op; - RCore *core = anal->coreb.core; + RzAnalOp *op = ctx->op; + RzCore *core = anal->coreb.core; handle_var_stack_access (esil, *val, R_ANAL_VAR_ACCESS_TYPE_READ, esil->anal->bits / 8); //specific case to handle blx/bx cases in arm through emulation // XXX this thing creates a lot of false positives @@ -4791,12 +4791,12 @@ static int esilbreak_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { case R_ANAL_OP_TYPE_UJMP: // BX // maybe UJMP/UCALL is enough here if (!(*val & 1)) { - r_anal_hint_set_bits (anal, *val, 32); + rz_anal_hint_set_bits (anal, *val, 32); } else { - ut64 snv = r_reg_getv (anal->reg, "pc"); + ut64 snv = rz_reg_getv (anal->reg, "pc"); if (snv != UT32_MAX && snv != UT64_MAX) { - if (r_io_is_valid_offset (anal->iob.io, *val, 1)) { - r_anal_hint_set_bits (anal, *val - 1, 16); + if (rz_io_is_valid_offset (anal->iob.io, *val, 1)) { + rz_anal_hint_set_bits (anal, *val - 1, 16); } } } @@ -4807,21 +4807,21 @@ static int esilbreak_reg_write(RAnalEsil *esil, const char *name, ut64 *val) { } } if (core->rasm->bits == 32 && strstr (core->rasm->cur->name, "arm")) { - if ((!(at & 1)) && r_io_is_valid_offset (anal->iob.io, at, 0)) { // !core->anal->opt.noncode)) { + if ((!(at & 1)) && rz_io_is_valid_offset (anal->iob.io, at, 0)) { // !core->anal->opt.noncode)) { add_string_ref (anal->coreb.core, esil->address, at); } } return 0; } -static void getpcfromstack(RCore *core, RAnalEsil *esil) { +static void getpcfromstack(RzCore *core, RzAnalEsil *esil) { ut64 cur; ut64 addr; ut64 size; int idx; - RAnalEsil esil_cpy; - RAnalOp op = R_EMPTY; - RAnalFunction *fcn = NULL; + RzAnalEsil esil_cpy; + RzAnalOp op = R_EMPTY; + RzAnalFunction *fcn = NULL; ut8 *buf = NULL; char *tmp_esil_str = NULL; int tmp_esil_str_len; @@ -4834,12 +4834,12 @@ static void getpcfromstack(RCore *core, RAnalEsil *esil) { memcpy (&esil_cpy, esil, sizeof (esil_cpy)); addr = cur = esil_cpy.cur; - fcn = r_anal_get_fcn_in (core->anal, addr, 0); + fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (!fcn) { return; } - size = r_anal_function_linear_size (fcn); + size = rz_anal_function_linear_size (fcn); if (size <= 0) { return; } @@ -4850,24 +4850,24 @@ static void getpcfromstack(RCore *core, RAnalEsil *esil) { return; } - r_io_read_at (core->io, addr, buf, size + 1); + rz_io_read_at (core->io, addr, buf, size + 1); // TODO Hardcoding for 2 instructions (mov e_p,[esp];ret). More work needed idx = 0; - if (r_anal_op (core->anal, &op, cur, buf + idx, size - idx, R_ANAL_OP_MASK_ESIL) <= 0 || + if (rz_anal_op (core->anal, &op, cur, buf + idx, size - idx, R_ANAL_OP_MASK_ESIL) <= 0 || op.size <= 0 || (op.type != R_ANAL_OP_TYPE_MOV && op.type != R_ANAL_OP_TYPE_CMOV)) { goto err_anal_op; } - r_asm_set_pc (core->rasm, cur); + rz_asm_set_pc (core->rasm, cur); esilstr = R_STRBUF_SAFEGET (&op.esil); if (!esilstr) { goto err_anal_op; } // Ugly code // This is a hack, since ESIL doesn't always preserve values pushed on the stack. That probably needs to be rectified - spname = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); + spname = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); if (!spname || !*spname) { goto err_anal_op; } @@ -4884,46 +4884,46 @@ static void getpcfromstack(RCore *core, RAnalEsil *esil) { } snprintf (tmp_esil_str, tmp_esil_str_len - 1, "%20" PFMT64u "%s", esil_cpy.old, &esilstr[strlen (spname) + 4]); - r_str_trim (tmp_esil_str); + rz_str_trim (tmp_esil_str); idx += op.size; - r_anal_esil_set_pc (&esil_cpy, cur); - r_anal_esil_parse (&esil_cpy, tmp_esil_str); - r_anal_esil_stack_free (&esil_cpy); + rz_anal_esil_set_pc (&esil_cpy, cur); + rz_anal_esil_parse (&esil_cpy, tmp_esil_str); + rz_anal_esil_stack_free (&esil_cpy); free (tmp_esil_str); cur = addr + idx; - r_anal_op_fini (&op); - if (r_anal_op (core->anal, &op, cur, buf + idx, size - idx, R_ANAL_OP_MASK_ESIL) <= 0 || + rz_anal_op_fini (&op); + if (rz_anal_op (core->anal, &op, cur, buf + idx, size - idx, R_ANAL_OP_MASK_ESIL) <= 0 || op.size <= 0 || (op.type != R_ANAL_OP_TYPE_RET && op.type != R_ANAL_OP_TYPE_CRET)) { goto err_anal_op; } - r_asm_set_pc (core->rasm, cur); + rz_asm_set_pc (core->rasm, cur); esilstr = R_STRBUF_SAFEGET (&op.esil); - r_anal_esil_set_pc (&esil_cpy, cur); + rz_anal_esil_set_pc (&esil_cpy, cur); if (!esilstr || !*esilstr) { goto err_anal_op; } - r_anal_esil_parse (&esil_cpy, esilstr); - r_anal_esil_stack_free (&esil_cpy); + rz_anal_esil_parse (&esil_cpy, esilstr); + rz_anal_esil_stack_free (&esil_cpy); memcpy (esil, &esil_cpy, sizeof (esil_cpy)); err_anal_op: - r_anal_op_fini (&op); + rz_anal_op_fini (&op); free (buf); } typedef struct { ut64 start_addr; ut64 end_addr; - RAnalFunction *fcn; - RAnalBlock *cur_bb; - RList *bbl, *path, *switch_path; + RzAnalFunction *fcn; + RzAnalBlock *cur_bb; + RzList *bbl, *path, *switch_path; } IterCtx; -static int find_bb(ut64 *addr, RAnalBlock *bb) { +static int find_bb(ut64 *addr, RzAnalBlock *bb) { return *addr != bb->addr; } @@ -4932,66 +4932,66 @@ static inline bool get_next_i(IterCtx *ctx, size_t *next_i) { ut64 cur_addr = *next_i + ctx->start_addr; if (ctx->fcn) { if (!ctx->cur_bb) { - ctx->path = r_list_new (); - ctx->switch_path = r_list_new (); - ctx->bbl = r_list_clone (ctx->fcn->bbs); - ctx->cur_bb = r_anal_get_block_at (ctx->fcn->anal, ctx->fcn->addr); - r_list_push (ctx->path, ctx->cur_bb); + ctx->path = rz_list_new (); + ctx->switch_path = rz_list_new (); + ctx->bbl = rz_list_clone (ctx->fcn->bbs); + ctx->cur_bb = rz_anal_get_block_at (ctx->fcn->anal, ctx->fcn->addr); + rz_list_push (ctx->path, ctx->cur_bb); } - RAnalBlock *bb = ctx->cur_bb; + RzAnalBlock *bb = ctx->cur_bb; if (cur_addr >= bb->addr + bb->size) { - r_reg_arena_push (ctx->fcn->anal->reg); - RListIter *bbit = NULL; + rz_reg_arena_push (ctx->fcn->anal->reg); + RzListIter *bbit = NULL; if (bb->switch_op) { - RAnalCaseOp *cop = r_list_first (bb->switch_op->cases); - bbit = r_list_find (ctx->bbl, &cop->jump, (RListComparator)find_bb); + RzAnalCaseOp *cop = rz_list_first (bb->switch_op->cases); + bbit = rz_list_find (ctx->bbl, &cop->jump, (RzListComparator)find_bb); if (bbit) { - r_list_push (ctx->switch_path, bb->switch_op->cases->head); + rz_list_push (ctx->switch_path, bb->switch_op->cases->head); } } else { - bbit = r_list_find (ctx->bbl, &bb->jump, (RListComparator)find_bb); + bbit = rz_list_find (ctx->bbl, &bb->jump, (RzListComparator)find_bb); if (!bbit && bb->fail != UT64_MAX) { - bbit = r_list_find (ctx->bbl, &bb->fail, (RListComparator)find_bb); + bbit = rz_list_find (ctx->bbl, &bb->fail, (RzListComparator)find_bb); } } if (!bbit) { - RListIter *cop_it = r_list_last (ctx->switch_path); - RAnalBlock *prev_bb = NULL; + RzListIter *cop_it = rz_list_last (ctx->switch_path); + RzAnalBlock *prev_bb = NULL; do { - r_reg_arena_pop (ctx->fcn->anal->reg); - prev_bb = r_list_pop (ctx->path); + rz_reg_arena_pop (ctx->fcn->anal->reg); + prev_bb = rz_list_pop (ctx->path); if (prev_bb->fail != UT64_MAX) { - bbit = r_list_find (ctx->bbl, &prev_bb->fail, (RListComparator)find_bb); + bbit = rz_list_find (ctx->bbl, &prev_bb->fail, (RzListComparator)find_bb); if (bbit) { - r_reg_arena_push (ctx->fcn->anal->reg); - r_list_push (ctx->path, prev_bb); + rz_reg_arena_push (ctx->fcn->anal->reg); + rz_list_push (ctx->path, prev_bb); } } if (!bbit && cop_it) { - RAnalCaseOp *cop = cop_it->data; + RzAnalCaseOp *cop = cop_it->data; if (cop->jump == prev_bb->addr && cop_it->n) { cop = cop_it->n->data; - r_list_pop (ctx->switch_path); - r_list_push (ctx->switch_path, cop_it->n); + rz_list_pop (ctx->switch_path); + rz_list_push (ctx->switch_path, cop_it->n); cop_it = cop_it->n; - bbit = r_list_find (ctx->bbl, &cop->jump, (RListComparator)find_bb); + bbit = rz_list_find (ctx->bbl, &cop->jump, (RzListComparator)find_bb); } } if (cop_it && !cop_it->n) { - r_list_pop (ctx->switch_path); - cop_it = r_list_last (ctx->switch_path); + rz_list_pop (ctx->switch_path); + cop_it = rz_list_last (ctx->switch_path); } - } while (!bbit && !r_list_empty (ctx->path)); + } while (!bbit && !rz_list_empty (ctx->path)); } if (!bbit) { - r_list_free (ctx->path); - r_list_free (ctx->switch_path); - r_list_free (ctx->bbl); + rz_list_free (ctx->path); + rz_list_free (ctx->switch_path); + rz_list_free (ctx->bbl); return false; } ctx->cur_bb = bbit->data; - r_list_push (ctx->path, ctx->cur_bb); - r_list_delete (ctx->bbl, bbit); + rz_list_push (ctx->path, ctx->cur_bb); + rz_list_delete (ctx->bbl, bbit); *next_i = ctx->cur_bb->addr - ctx->start_addr; } } else if (cur_addr >= ctx->end_addr) { @@ -5000,14 +5000,14 @@ static inline bool get_next_i(IterCtx *ctx, size_t *next_i) { return true; } -R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { - bool cfg_anal_strings = r_config_get_i (core->config, "anal.strings"); - bool emu_lazy = r_config_get_i (core->config, "emu.lazy"); - bool gp_fixed = r_config_get_i (core->config, "anal.gpfixed"); - RAnalEsil *ESIL = core->anal->esil; +RZ_API void rz_core_anal_esil(RzCore *core, const char *str, const char *target) { + bool cfg_anal_strings = rz_config_get_i (core->config, "anal.strings"); + bool emu_lazy = rz_config_get_i (core->config, "emu.lazy"); + bool gp_fixed = rz_config_get_i (core->config, "anal.gpfixed"); + RzAnalEsil *ESIL = core->anal->esil; ut64 refptr = 0LL; const char *pcname; - RAnalOp op = R_EMPTY; + RzAnalOp op = R_EMPTY; ut8 *buf = NULL; bool end_address_set = false; int iend; @@ -5028,9 +5028,9 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { } #define CHECKREF(x) ((refptr && (x) == refptr) || !refptr) if (target) { - const char *expr = r_str_trim_head_ro (target); + const char *expr = rz_str_trim_head_ro (target); if (*expr) { - refptr = ntarget = r_num_math (core->num, expr); + refptr = ntarget = rz_num_math (core->num, expr); if (!refptr) { ntarget = refptr = addr; } @@ -5042,22 +5042,22 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ntarget = UT64_MAX; refptr = 0LL; } - RAnalFunction *fcn = NULL; + RzAnalFunction *fcn = NULL; if (!strcmp (str, "f")) { - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - start = r_anal_function_min_addr (fcn); + start = rz_anal_function_min_addr (fcn); addr = fcn->addr; - end = r_anal_function_max_addr (fcn); + end = rz_anal_function_max_addr (fcn); end_address_set = true; } } if (!end_address_set) { if (str[0] == ' ') { - end = addr + r_num_math (core->num, str + 1); + end = addr + rz_num_math (core->num, str + 1); } else { - RIOMap *map = r_io_map_get (core->io, addr); + RzIOMap *map = rz_io_map_get (core->io, addr); if (map) { end = map->itv.addr + map->itv.size; } else { @@ -5080,21 +5080,21 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { return; } esilbreak_last_read = UT64_MAX; - r_io_read_at (core->io, start, buf, iend + 1); + rz_io_read_at (core->io, start, buf, iend + 1); if (!ESIL) { - r_core_cmd0 (core, "aei"); + rz_core_cmd0 (core, "aei"); ESIL = core->anal->esil; if (!ESIL) { eprintf ("ESIL not initialized\n"); return; } - r_core_cmd0 (core, "aeim"); + rz_core_cmd0 (core, "aeim"); } EsilBreakCtx ctx = { &op, fcn, - r_reg_get_name (core->anal->reg, R_REG_NAME_SP), - r_reg_getv (core->anal->reg, ctx.spname) + rz_reg_get_name (core->anal->reg, R_REG_NAME_SP), + rz_reg_getv (core->anal->reg, ctx.spname) }; ESIL->cb.hook_reg_write = &esilbreak_reg_write; //this is necessary for the hook to read the id of analop @@ -5103,17 +5103,17 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ESIL->cb.hook_mem_write = &esilbreak_mem_write; if (fcn && fcn->reg_save_area) { - r_reg_setv (core->anal->reg, ctx.spname, ctx.initial_sp - fcn->reg_save_area); + rz_reg_setv (core->anal->reg, ctx.spname, ctx.initial_sp - fcn->reg_save_area); } //eprintf ("Analyzing ESIL refs from 0x%"PFMT64x" - 0x%"PFMT64x"\n", addr, end); // TODO: backup/restore register state before/after analysis - pcname = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + pcname = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); if (!pcname || !*pcname) { eprintf ("Cannot find program counter register in the current profile.\n"); return; } esil_anal_stop = false; - r_cons_break_push (cccb, core); + rz_cons_break_push (cccb, core); int arch = -1; if (!strcmp (core->anal->cur->arch, "arm")) { @@ -5125,65 +5125,65 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { archIsArm = true; } - ut64 gp = r_config_get_i (core->config, "anal.gp"); + ut64 gp = rz_config_get_i (core->config, "anal.gp"); const char *gp_reg = NULL; if (!strcmp (core->anal->cur->arch, "mips")) { gp_reg = "gp"; arch = R2_ARCH_MIPS; } - const char *sn = r_reg_get_name (core->anal->reg, R_REG_NAME_SN); + const char *sn = rz_reg_get_name (core->anal->reg, R_REG_NAME_SN); if (!sn) { eprintf ("Warning: No SN reg alias for current architecture.\n"); } - r_reg_arena_push (core->anal->reg); + rz_reg_arena_push (core->anal->reg); IterCtx ictx = { start, end, fcn, NULL}; size_t i = addr - start; do { - if (esil_anal_stop || r_cons_is_breaked ()) { + if (esil_anal_stop || rz_cons_is_breaked ()) { break; } cur = start + i; - if (!r_io_is_valid_offset (core->io, cur, 0)) { + if (!rz_io_is_valid_offset (core->io, cur, 0)) { break; } { - RPVector *list = r_meta_get_all_in (core->anal, cur, R_META_TYPE_ANY); + RPVector *list = rz_meta_get_all_in (core->anal, cur, R_META_TYPE_ANY); void **it; - r_pvector_foreach (list, it) { + rz_pvector_foreach (list, it) { RIntervalNode *node = *it; - RAnalMetaItem *meta = node->data; + RzAnalMetaItem *meta = node->data; switch (meta->type) { case R_META_TYPE_DATA: case R_META_TYPE_STRING: case R_META_TYPE_FORMAT: i += 4; - r_pvector_free (list); + rz_pvector_free (list); goto repeat; default: break; } } - r_pvector_free (list); + rz_pvector_free (list); } /* realign address if needed */ - r_core_seek_arch_bits (core, cur); + rz_core_seek_arch_bits (core, cur); int opalign = core->anal->pcalign; if (opalign > 0) { cur -= (cur % opalign); } - r_anal_op_fini (&op); - r_asm_set_pc (core->rasm, cur); - if (!r_anal_op (core->anal, &op, cur, buf + i, iend - i, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) { + rz_anal_op_fini (&op); + rz_asm_set_pc (core->rasm, cur); + if (!rz_anal_op (core->anal, &op, cur, buf + i, iend - i, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_VAL | R_ANAL_OP_MASK_HINT)) { i += minopsize - 1; // XXX dupe in op.size below } // if (op.type & 0x80000000 || op.type == 0) { if (op.type == R_ANAL_OP_TYPE_ILL || op.type == R_ANAL_OP_TYPE_UNK) { // i += 2 - r_anal_op_fini (&op); + rz_anal_op_fini (&op); continue; } //we need to check again i because buf+i may goes beyond its boundaries @@ -5229,47 +5229,47 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { } } if (sn && op.type == R_ANAL_OP_TYPE_SWI) { - r_flag_space_set (core->flags, R_FLAGS_FS_SYSCALLS); - int snv = (arch == R2_ARCH_THUMB)? op.val: (int)r_reg_getv (core->anal->reg, sn); - RSyscallItem *si = r_syscall_get (core->anal->syscall, snv, -1); + rz_flag_space_set (core->flags, R_FLAGS_FS_SYSCALLS); + int snv = (arch == R2_ARCH_THUMB)? op.val: (int)rz_reg_getv (core->anal->reg, sn); + RzSyscallItem *si = rz_syscall_get (core->anal->syscall, snv, -1); if (si) { // eprintf ("0x%08"PFMT64x" SYSCALL %-4d %s\n", cur, snv, si->name); - r_flag_set_next (core->flags, sdb_fmt ("syscall.%s", si->name), cur, 1); + rz_flag_set_next (core->flags, sdb_fmt ("syscall.%s", si->name), cur, 1); } else { //todo were doing less filtering up top because we can't match against 80 on all platforms // might get too many of this path now.. // eprintf ("0x%08"PFMT64x" SYSCALL %d\n", cur, snv); - r_flag_set_next (core->flags, sdb_fmt ("syscall.%d", snv), cur, 1); + rz_flag_set_next (core->flags, sdb_fmt ("syscall.%d", snv), cur, 1); } - r_flag_space_set (core->flags, NULL); + rz_flag_space_set (core->flags, NULL); } const char *esilstr = R_STRBUF_SAFEGET (&op.esil); i += op.size - 1; if (!esilstr || !*esilstr) { continue; } - r_anal_esil_set_pc (ESIL, cur); - r_reg_setv (core->anal->reg, pcname, cur + op.size); + rz_anal_esil_set_pc (ESIL, cur); + rz_reg_setv (core->anal->reg, pcname, cur + op.size); if (gp_fixed && gp_reg) { - r_reg_setv (core->anal->reg, gp_reg, gp); + rz_reg_setv (core->anal->reg, gp_reg, gp); } - (void)r_anal_esil_parse (ESIL, esilstr); + (void)rz_anal_esil_parse (ESIL, esilstr); // looks like ^C is handled by esil_parse !!!! - //r_anal_esil_dumpstack (ESIL); - //r_anal_esil_stack_free (ESIL); + //rz_anal_esil_dumpstack (ESIL); + //rz_anal_esil_stack_free (ESIL); switch (op.type) { case R_ANAL_OP_TYPE_LEA: // arm64 if (core->anal->cur && arch == R2_ARCH_ARM64) { if (CHECKREF (ESIL->cur)) { - r_anal_xrefs_set (core->anal, cur, ESIL->cur, R_ANAL_REF_TYPE_STRING); + rz_anal_xrefs_set (core->anal, cur, ESIL->cur, R_ANAL_REF_TYPE_STRING); } } else if ((target && op.ptr == ntarget) || !target) { if (CHECKREF (ESIL->cur)) { - if (op.ptr && r_io_is_valid_offset (core->io, op.ptr, !core->anal->opt.noncode)) { - r_anal_xrefs_set (core->anal, cur, op.ptr, R_ANAL_REF_TYPE_STRING); + if (op.ptr && rz_io_is_valid_offset (core->io, op.ptr, !core->anal->opt.noncode)) { + rz_anal_xrefs_set (core->anal, cur, op.ptr, R_ANAL_REF_TYPE_STRING); } else { - r_anal_xrefs_set (core->anal, cur, ESIL->cur, R_ANAL_REF_TYPE_STRING); + rz_anal_xrefs_set (core->anal, cur, ESIL->cur, R_ANAL_REF_TYPE_STRING); } } } @@ -5284,7 +5284,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ut64 dst = ESIL->cur; if ((target && dst == ntarget) || !target) { if (CHECKREF (dst)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); } } if (cfg_anal_strings) { @@ -5303,22 +5303,22 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { } if ((target && dst == ntarget) || !target) { if (dst > 0xffff && op.src[1] && (dst & 0xffff) == (op.src[1]->imm & 0xffff) && myvalid (mycore->io, dst)) { - RFlagItem *f; + RzFlagItem *f; char *str; if (CHECKREF (dst) || CHECKREF (cur)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); if (cfg_anal_strings) { add_string_ref (core, op.addr, dst); } - if ((f = r_core_flag_get_by_spaces (core->flags, dst))) { - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, cur, f->name); + if ((f = rz_core_flag_get_by_spaces (core->flags, dst))) { + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, cur, f->name); } else if ((str = is_string_at (mycore, dst, NULL))) { char *str2 = sdb_fmt ("esilref: '%s'", str); // HACK avoid format string inside string used later as format // string crashes disasm inside agf under some conditions. - // https://github.com/radareorg/radare2/issues/6937 - r_str_replace_char (str2, '%', '&'); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, cur, str2); + // https://github.com/rizinorg/rizin/issues/6937 + rz_str_replace_char (str2, '%', '&'); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, cur, str2); free (str); } } @@ -5331,7 +5331,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ut64 dst = esilbreak_last_read; if (dst != UT64_MAX && CHECKREF (dst)) { if (myvalid (mycore->io, dst)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); if (cfg_anal_strings) { add_string_ref (core, op.addr, dst); } @@ -5340,7 +5340,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { dst = esilbreak_last_data; if (dst != UT64_MAX && CHECKREF (dst)) { if (myvalid (mycore->io, dst)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_DATA); if (cfg_anal_strings) { add_string_ref (core, op.addr, dst); } @@ -5353,7 +5353,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ut64 dst = op.jump; if (CHECKREF (dst)) { if (myvalid (core->io, dst)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_CODE); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_CODE); } } } @@ -5363,7 +5363,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { ut64 dst = op.jump; if (CHECKREF (dst)) { if (myvalid (core->io, dst)) { - r_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_CALL); + rz_anal_xrefs_set (core->anal, cur, dst, R_ANAL_REF_TYPE_CALL); } ESIL->old = cur + op.size; getpcfromstack (core, ESIL); @@ -5379,16 +5379,16 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { { ut64 dst = core->anal->esil->jump_target; if (dst == 0 || dst == UT64_MAX) { - dst = r_reg_getv (core->anal->reg, pcname); + dst = rz_reg_getv (core->anal->reg, pcname); } if (CHECKREF (dst)) { if (myvalid (core->io, dst)) { - RAnalRefType ref = + RzAnalRefType ref = (op.type & R_ANAL_OP_TYPE_MASK) == R_ANAL_OP_TYPE_UCALL ? R_ANAL_REF_TYPE_CALL : R_ANAL_REF_TYPE_CODE; - r_anal_xrefs_set (core->anal, cur, dst, ref); - r_core_anal_fcn (core, dst, UT64_MAX, R_ANAL_REF_TYPE_NULL, 1); + rz_anal_xrefs_set (core->anal, cur, dst, ref); + rz_core_anal_fcn (core, dst, UT64_MAX, R_ANAL_REF_TYPE_NULL, 1); // analyze function here #if 0 if (op.type == R_ANAL_OP_TYPE_UCALL || op.type == R_ANAL_OP_TYPE_RCALL) { @@ -5402,7 +5402,7 @@ R_API void r_core_anal_esil(RCore *core, const char *str, const char *target) { default: break; } - r_anal_esil_stack_free (ESIL); + rz_anal_esil_stack_free (ESIL); repeat:; } while (get_next_i (&ictx, &i)); free (buf); @@ -5410,24 +5410,24 @@ repeat:; ESIL->cb.hook_mem_write = NULL; ESIL->cb.hook_reg_write = NULL; ESIL->user = NULL; - r_anal_op_fini (&op); - r_cons_break_pop (); + rz_anal_op_fini (&op); + rz_cons_break_pop (); // restore register - r_reg_arena_pop (core->anal->reg); + rz_reg_arena_pop (core->anal->reg); } -static bool isValidAddress (RCore *core, ut64 addr) { +static bool isValidAddress (RzCore *core, ut64 addr) { // check if address is mapped - RIOMap* map = r_io_map_get (core->io, addr); + RzIOMap* map = rz_io_map_get (core->io, addr); if (!map) { return false; } - st64 fdsz = (st64)r_io_fd_size (core->io, map->fd); + st64 fdsz = (st64)rz_io_fd_size (core->io, map->fd); if (fdsz > 0 && map->delta > fdsz) { return false; } // check if associated file is opened - RIODesc *desc = r_io_desc_get (core->io, map->fd); + RzIODesc *desc = rz_io_desc_get (core->io, map->fd); if (!desc) { return false; } @@ -5438,9 +5438,9 @@ static bool isValidAddress (RCore *core, ut64 addr) { return true; } -static bool stringAt(RCore *core, ut64 addr) { +static bool stringAt(RzCore *core, ut64 addr) { ut8 buf[32]; - r_io_read_at (core->io, addr - 1, buf, sizeof (buf)); + rz_io_read_at (core->io, addr - 1, buf, sizeof (buf)); // check if previous byte is a null byte, all strings, except pascal ones should be like this if (buf[0] != 0) { return false; @@ -5448,16 +5448,16 @@ static bool stringAt(RCore *core, ut64 addr) { return is_string (buf + 1, 31, NULL); } -R_API int r_core_search_value_in_range(RCore *core, RInterval search_itv, ut64 vmin, +RZ_API int rz_core_search_value_in_range(RzCore *core, RInterval search_itv, ut64 vmin, ut64 vmax, int vsize, inRangeCb cb, void *cb_user) { int i, align = core->search->align, hitctr = 0; - bool vinfun = r_config_get_i (core->config, "anal.vinfun"); - bool vinfunr = r_config_get_i (core->config, "anal.vinfunrange"); - bool analStrings = r_config_get_i (core->config, "anal.strings"); + bool vinfun = rz_config_get_i (core->config, "anal.vinfun"); + bool vinfunr = rz_config_get_i (core->config, "anal.vinfunrange"); + bool analStrings = rz_config_get_i (core->config, "anal.strings"); mycore = core; ut8 buf[4096]; ut64 v64, value = 0, size; - ut64 from = search_itv.addr, to = r_itv_end (search_itv); + ut64 from = search_itv.addr, to = rz_itv_end (search_itv); ut32 v32; ut16 v16; if (from >= to) { @@ -5479,21 +5479,21 @@ R_API int r_core_search_value_in_range(RCore *core, RInterval search_itv, ut64 v eprintf ("Error: Invalid destination boundary\n"); return -1; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); - if (!r_io_is_valid_offset (core->io, from, 0)) { + if (!rz_io_is_valid_offset (core->io, from, 0)) { return -1; } while (from < to) { size = R_MIN (to - from, sizeof (buf)); memset (buf, 0xff, sizeof (buf)); // probably unnecessary - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto beach; } - bool res = r_io_read_at_mapped (core->io, from, buf, size); + bool res = rz_io_read_at_mapped (core->io, from, buf, size); if (!res || !memcmp (buf, "\xff\xff\xff\xff", 4) || !memcmp (buf, "\x00\x00\x00\x00", 4)) { if (!isValidAddress (core, from)) { - ut64 next = r_io_map_next_address (core->io, from); + ut64 next = rz_io_map_next_address (core->io, from); if (next == UT64_MAX) { from += sizeof (buf); } else { @@ -5505,7 +5505,7 @@ R_API int r_core_search_value_in_range(RCore *core, RInterval search_itv, ut64 v for (i = 0; i <= (size - vsize); i++) { void *v = (buf + i); ut64 addr = from + i; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto beach; } if (align && (addr) % align) { @@ -5525,11 +5525,11 @@ R_API int r_core_search_value_in_range(RCore *core, RInterval search_itv, ut64 v } if (match && !vinfun) { if (vinfunr) { - if (r_anal_get_fcn_in_bounds (core->anal, addr, R_ANAL_FCN_TYPE_NULL)) { + if (rz_anal_get_fcn_in_bounds (core->anal, addr, R_ANAL_FCN_TYPE_NULL)) { match = false; } } else { - if (r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL)) { + if (rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL)) { match = false; } } @@ -5558,73 +5558,73 @@ R_API int r_core_search_value_in_range(RCore *core, RInterval search_itv, ut64 v from += size-vsize+1; } beach: - r_cons_break_pop (); + rz_cons_break_pop (); return hitctr; } typedef struct { dict visited; - RList *path; - RCore *core; + RzList *path; + RzCore *core; ut64 from; - RAnalBlock *fromBB; + RzAnalBlock *fromBB; ut64 to; - RAnalBlock *toBB; - RAnalBlock *cur; + RzAnalBlock *toBB; + RzAnalBlock *cur; bool followCalls; int followDepth; int count; // max number of results -} RCoreAnalPaths; +} RzCoreAnalPaths; -static bool printAnalPaths(RCoreAnalPaths *p, PJ *pj) { - RListIter *iter; - RAnalBlock *path; +static bool printAnalPaths(RzCoreAnalPaths *p, PJ *pj) { + RzListIter *iter; + RzAnalBlock *path; if (pj) { pj_a (pj); } else { - r_cons_printf ("pdb @@= "); + rz_cons_printf ("pdb @@= "); } - r_list_foreach (p->path, iter, path) { + rz_list_foreach (p->path, iter, path) { if (pj) { pj_n (pj, path->addr); } else { - r_cons_printf ("0x%08"PFMT64x" ", path->addr); + rz_cons_printf ("0x%08"PFMT64x" ", path->addr); } } if(pj) { pj_end (pj); } else { - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } return (p->count < 1 || --p->count > 0); } -static void analPaths(RCoreAnalPaths *p, PJ *pj); +static void analPaths(RzCoreAnalPaths *p, PJ *pj); -static void analPathFollow(RCoreAnalPaths *p, ut64 addr, PJ *pj) { +static void analPathFollow(RzCoreAnalPaths *p, ut64 addr, PJ *pj) { if (addr == UT64_MAX) { return; } if (!dict_get (&p->visited, addr)) { - p->cur = r_anal_bb_from_offset (p->core->anal, addr); + p->cur = rz_anal_bb_from_offset (p->core->anal, addr); analPaths (p, pj); } } -static void analPaths(RCoreAnalPaths *p, PJ *pj) { - RAnalBlock *cur = p->cur; +static void analPaths(RzCoreAnalPaths *p, PJ *pj) { + RzAnalBlock *cur = p->cur; if (!cur) { // eprintf ("eof\n"); return; } /* handle ^C */ - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { return; } dict_set (&p->visited, cur->addr, 1, NULL); - r_list_append (p->path, cur); + rz_list_append (p->path, cur); if (p->followDepth && --p->followDepth == 0) { return; } @@ -5633,7 +5633,7 @@ static void analPaths(RCoreAnalPaths *p, PJ *pj) { return; } } else { - RAnalBlock *c = cur; + RzAnalBlock *c = cur; ut64 j = cur->jump; ut64 f = cur->fail; analPathFollow (p, j, pj); @@ -5643,25 +5643,25 @@ static void analPaths(RCoreAnalPaths *p, PJ *pj) { int i; for (i = 0; i < cur->op_pos_size; i++) { ut64 addr = cur->addr + cur->op_pos[i]; - RAnalOp *op = r_core_anal_op (p->core, addr, R_ANAL_OP_MASK_BASIC); + RzAnalOp *op = rz_core_anal_op (p->core, addr, R_ANAL_OP_MASK_BASIC); if (op && op->type == R_ANAL_OP_TYPE_CALL) { analPathFollow (p, op->jump, pj); } cur = c; - r_anal_op_free (op); + rz_anal_op_free (op); } } } - p->cur = r_list_pop (p->path); + p->cur = rz_list_pop (p->path); dict_del (&p->visited, cur->addr); if (p->followDepth) { p->followDepth++; } } -R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json) { - RAnalBlock *b0 = r_anal_bb_from_offset (core->anal, from); - RAnalBlock *b1 = r_anal_bb_from_offset (core->anal, to); +RZ_API void rz_core_anal_paths(RzCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json) { + RzAnalBlock *b0 = rz_anal_bb_from_offset (core->anal, from); + RzAnalBlock *b1 = rz_anal_bb_from_offset (core->anal, to); PJ *pj = NULL; if (!b0) { eprintf ("Cannot find basic block for 0x%08"PFMT64x"\n", from); @@ -5671,16 +5671,16 @@ R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, eprintf ("Cannot find basic block for 0x%08"PFMT64x"\n", to); return; } - RCoreAnalPaths rcap = {{0}}; + RzCoreAnalPaths rcap = {{0}}; dict_init (&rcap.visited, 32, free); - rcap.path = r_list_new (); + rcap.path = rz_list_new (); rcap.core = core; rcap.from = from; rcap.fromBB = b0; rcap.to = to; rcap.toBB = b1; rcap.cur = b0; - rcap.count = r_config_get_i (core->config, "search.maxhits");; + rcap.count = rz_config_get_i (core->config, "search.maxhits");; rcap.followCalls = followCalls; rcap.followDepth = followDepth; @@ -5694,7 +5694,7 @@ R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, if (is_json) { pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); } if (pj) { @@ -5702,17 +5702,17 @@ R_API void r_core_anal_paths(RCore *core, ut64 from, ut64 to, bool followCalls, } dict_fini (&rcap.visited); - r_list_free (rcap.path); + rz_list_free (rcap.path); } -static bool __cb(RFlagItem *fi, void *user) { - r_list_append (user, r_str_newf ("0x%08"PFMT64x, fi->offset)); +static bool __cb(RzFlagItem *fi, void *user) { + rz_list_append (user, rz_str_newf ("0x%08"PFMT64x, fi->offset)); return true; } static int __addrs_cmp(void *_a, void *_b) { - ut64 a = r_num_get (NULL, _a); - ut64 b = r_num_get (NULL, _b); + ut64 a = rz_num_get (NULL, _a); + ut64 b = rz_num_get (NULL, _b); if (a > b) { return 1; } @@ -5722,29 +5722,29 @@ static int __addrs_cmp(void *_a, void *_b) { return 0; } -R_API void r_core_anal_inflags(RCore *core, const char *glob) { - RList *addrs = r_list_newf (free); - RListIter *iter; - bool a2f = r_config_get_i (core->config, "anal.a2f"); - char *anal_in = strdup (r_config_get (core->config, "anal.in")); - r_config_set (core->config, "anal.in", "block"); +RZ_API void rz_core_anal_inflags(RzCore *core, const char *glob) { + RzList *addrs = rz_list_newf (free); + RzListIter *iter; + bool a2f = rz_config_get_i (core->config, "anal.a2f"); + char *anal_in = strdup (rz_config_get (core->config, "anal.in")); + rz_config_set (core->config, "anal.in", "block"); // aaFa = use a2f instead of af+ bool simple = (!glob || *glob != 'a'); - glob = r_str_trim_head_ro (glob); + glob = rz_str_trim_head_ro (glob); char *addr; - r_flag_foreach_glob (core->flags, glob, __cb, addrs); + rz_flag_foreach_glob (core->flags, glob, __cb, addrs); // should be sorted already - r_list_sort (addrs, (RListComparator)__addrs_cmp); - r_list_foreach (addrs, iter, addr) { - if (!iter->n || r_cons_is_breaked ()) { + rz_list_sort (addrs, (RzListComparator)__addrs_cmp); + rz_list_foreach (addrs, iter, addr) { + if (!iter->n || rz_cons_is_breaked ()) { break; } char *addr2 = iter->n->data; if (!addr || !addr2) { break; } - ut64 a0 = r_num_get (NULL, addr); - ut64 a1 = r_num_get (NULL, addr2); + ut64 a0 = rz_num_get (NULL, addr); + ut64 a1 = rz_num_get (NULL, addr2); if (a0 == a1) { // ignore continue; @@ -5759,41 +5759,41 @@ R_API void r_core_anal_inflags(RCore *core, const char *glob) { continue; } if (simple) { - RFlagItem *fi = r_flag_get_at (core->flags, a0, 0); - r_core_cmdf (core, "af+ %s fcn.%s", addr, fi? fi->name: addr); - r_core_cmdf (core, "afb+ %s %s %d", addr, addr, (int)sz); + RzFlagItem *fi = rz_flag_get_at (core->flags, a0, 0); + rz_core_cmdf (core, "af+ %s fcn.%s", addr, fi? fi->name: addr); + rz_core_cmdf (core, "afb+ %s %s %d", addr, addr, (int)sz); } else { - r_core_cmdf (core, "aab@%s!%s-%s\n", addr, addr2, addr); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, r_num_math (core->num, addr), 0); + rz_core_cmdf (core, "aab@%s!%s-%s\n", addr, addr2, addr); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, rz_num_math (core->num, addr), 0); if (fcn) { eprintf ("%s %s %"PFMT64d" # %s\n", addr, "af", sz, fcn->name); } else { if (a2f) { - r_core_cmdf (core, "a2f@%s!%s-%s\n", addr, addr2, addr); + rz_core_cmdf (core, "a2f@%s!%s-%s\n", addr, addr2, addr); } else { - r_core_cmdf (core, "af@%s!%s-%s\n", addr, addr2, addr); + rz_core_cmdf (core, "af@%s!%s-%s\n", addr, addr2, addr); } - fcn = r_anal_get_fcn_in (core->anal, r_num_math (core->num, addr), 0); + fcn = rz_anal_get_fcn_in (core->anal, rz_num_math (core->num, addr), 0); eprintf ("%s %s %.4"PFMT64d" # %s\n", addr, "aab", sz, fcn?fcn->name: ""); } } } - r_list_free (addrs); - r_config_set (core->config, "anal.in", anal_in); + rz_list_free (addrs); + rz_config_set (core->config, "anal.in", anal_in); free (anal_in); } -static bool analyze_noreturn_function(RCore *core, RAnalFunction *f) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (f->bbs, iter, bb) { - ut64 opaddr = r_anal_bb_opaddr_i (bb, bb->ninstr - 1); +static bool analyze_noreturn_function(RzCore *core, RzAnalFunction *f) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (f->bbs, iter, bb) { + ut64 opaddr = rz_anal_bb_opaddr_i (bb, bb->ninstr - 1); if (opaddr == UT64_MAX) { return false; } // get last opcode - RAnalOp *op = r_core_op_anal (core, opaddr, R_ANAL_OP_MASK_HINT); + RzAnalOp *op = rz_core_op_anal (core, opaddr, R_ANAL_OP_MASK_HINT); if (!op) { eprintf ("Cannot analyze opcode at 0x%08" PFMT64x "\n", opaddr); return false; @@ -5802,158 +5802,158 @@ static bool analyze_noreturn_function(RCore *core, RAnalFunction *f) { switch (op->type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_ILL: case R_ANAL_OP_TYPE_RET: - r_anal_op_free (op); + rz_anal_op_free (op); return false; case R_ANAL_OP_TYPE_JMP: - if (!r_anal_function_contains (f, op->jump)) { - r_anal_op_free (op); + if (!rz_anal_function_contains (f, op->jump)) { + rz_anal_op_free (op); return false; } break; } - r_anal_op_free (op); + rz_anal_op_free (op); } return true; } -R_API void r_core_anal_propagate_noreturn(RCore *core, ut64 addr) { - RList *todo = r_list_newf (free); +RZ_API void rz_core_anal_propagate_noreturn(RzCore *core, ut64 addr) { + RzList *todo = rz_list_newf (free); if (!todo) { return; } HtUU *done = ht_uu_new0 (); if (!done) { - r_list_free (todo); + rz_list_free (todo); return; } - RAnalFunction *request_fcn = NULL; + RzAnalFunction *request_fcn = NULL; if (addr != UT64_MAX) { - request_fcn = r_anal_get_function_at (core->anal, addr); + request_fcn = rz_anal_get_function_at (core->anal, addr); if (!request_fcn) { - r_list_free (todo); + rz_list_free (todo); ht_uu_free (done); return; } } // find known noreturn functions to propagate - RListIter *iter; - RAnalFunction *f; - r_list_foreach (core->anal->fcns, iter, f) { + RzListIter *iter; + RzAnalFunction *f; + rz_list_foreach (core->anal->fcns, iter, f) { if (f->is_noreturn) { ut64 *n = ut64_new (f->addr); - r_list_append (todo, n); + rz_list_append (todo, n); } } - while (!r_list_empty (todo)) { - ut64 *paddr = (ut64*)r_list_pop (todo); + while (!rz_list_empty (todo)) { + ut64 *paddr = (ut64*)rz_list_pop (todo); ut64 noret_addr = *paddr; free (paddr); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - RList *xrefs = r_anal_xrefs_get (core->anal, noret_addr); - RAnalRef *xref; - r_list_foreach (xrefs, iter, xref) { - RAnalOp *xrefop = r_core_op_anal (core, xref->addr, R_ANAL_OP_MASK_ALL); + RzList *xrefs = rz_anal_xrefs_get (core->anal, noret_addr); + RzAnalRef *xref; + rz_list_foreach (xrefs, iter, xref) { + RzAnalOp *xrefop = rz_core_op_anal (core, xref->addr, R_ANAL_OP_MASK_ALL); if (!xrefop) { eprintf ("Cannot analyze opcode at 0x%08" PFMT64x "\n", xref->addr); continue; } ut64 call_addr = xref->addr; ut64 chop_addr = call_addr + xrefop->size; - r_anal_op_free (xrefop); + rz_anal_op_free (xrefop); if (xref->type != R_ANAL_REF_TYPE_CALL) { continue; } // Find the block that has an instruction at exactly the xref addr - RList *blocks = r_anal_get_blocks_in (core->anal, call_addr); + RzList *blocks = rz_anal_get_blocks_in (core->anal, call_addr); if (!blocks) { continue; } - RAnalBlock *block = NULL; - RListIter *bit; - RAnalBlock *block_cur; - r_list_foreach (blocks, bit, block_cur) { - if (r_anal_block_op_starts_at (block_cur, call_addr)) { + RzAnalBlock *block = NULL; + RzListIter *bit; + RzAnalBlock *block_cur; + rz_list_foreach (blocks, bit, block_cur) { + if (rz_anal_block_op_starts_at (block_cur, call_addr)) { block = block_cur; break; } } if (block) { - r_anal_block_ref (block); + rz_anal_block_ref (block); } - r_list_free (blocks); + rz_list_free (blocks); if (!block) { continue; } - RList *block_fcns = r_list_clone (block->fcns); + RzList *block_fcns = rz_list_clone (block->fcns); if (request_fcn) { // specific function requested, check if it contains the bb - if (!r_list_contains (block->fcns, request_fcn)) { + if (!rz_list_contains (block->fcns, request_fcn)) { goto kontinue; } } else { - // r_anal_block_chop_noreturn() might free the block! - block = r_anal_block_chop_noreturn (block, chop_addr); + // rz_anal_block_chop_noreturn() might free the block! + block = rz_anal_block_chop_noreturn (block, chop_addr); } - RListIter *fit; - r_list_foreach (block_fcns, fit, f) { + RzListIter *fit; + rz_list_foreach (block_fcns, fit, f) { bool found = ht_uu_find (done, f->addr, NULL) != 0; if (f->addr && !found && analyze_noreturn_function (core, f)) { f->is_noreturn = true; - r_anal_noreturn_add (core->anal, NULL, f->addr); + rz_anal_noreturn_add (core->anal, NULL, f->addr); ut64 *n = malloc (sizeof (ut64)); *n = f->addr; - r_list_append (todo, n); + rz_list_append (todo, n); ht_uu_insert (done, *n, 1); } } kontinue: if (block) { - r_anal_block_unref (block); + rz_anal_block_unref (block); } - r_list_free (block_fcns); + rz_list_free (block_fcns); } - r_list_free (xrefs); + rz_list_free (xrefs); } - r_list_free (todo); + rz_list_free (todo); ht_uu_free (done); } -R_API void r_core_anal_esil_graph(RCore *core, const char *expr) { - RAnalEsilDFG * edf = r_anal_esil_dfg_expr(core->anal, NULL, expr); - RListIter *iter, *ator; +RZ_API void rz_core_anal_esil_graph(RzCore *core, const char *expr) { + RzAnalEsilDFG * edf = rz_anal_esil_dfg_expr(core->anal, NULL, expr); + RzListIter *iter, *ator; RGraphNode *node, *edon; - RStrBuf *buf = r_strbuf_new (""); - r_cons_printf ("ag-\n"); - r_list_foreach (r_graph_get_nodes (edf->flow), iter, node) { - const RAnalEsilDFGNode *enode = (RAnalEsilDFGNode *)node->data; - char *esc_str = r_str_escape (r_strbuf_get (enode->content)); - r_strbuf_set (buf, esc_str); + RStrBuf *buf = rz_strbuf_new (""); + rz_cons_printf ("ag-\n"); + rz_list_foreach (rz_graph_get_nodes (edf->flow), iter, node) { + const RzAnalEsilDFGNode *enode = (RzAnalEsilDFGNode *)node->data; + char *esc_str = rz_str_escape (rz_strbuf_get (enode->content)); + rz_strbuf_set (buf, esc_str); if (enode->type == R_ANAL_ESIL_DFG_BLOCK_GENERATIVE) { - r_strbuf_prepend (buf, "generative:"); + rz_strbuf_prepend (buf, "generative:"); } - char *b64_buf = r_base64_encode_dyn (r_strbuf_get (buf), buf->len); - r_cons_printf ("agn %d base64:%s\n", enode->idx, b64_buf); + char *b64_buf = rz_base64_encode_dyn (rz_strbuf_get (buf), buf->len); + rz_cons_printf ("agn %d base64:%s\n", enode->idx, b64_buf); free (b64_buf); free (esc_str); } - r_strbuf_free (buf); + rz_strbuf_free (buf); - r_list_foreach (r_graph_get_nodes (edf->flow), iter, node) { - const RAnalEsilDFGNode *enode = (RAnalEsilDFGNode *)node->data; - r_list_foreach (r_graph_get_neighbours (edf->flow, node), ator, edon) { - const RAnalEsilDFGNode *edone = (RAnalEsilDFGNode *)edon->data; - r_cons_printf ("age %d %d\n", enode->idx, edone->idx); + rz_list_foreach (rz_graph_get_nodes (edf->flow), iter, node) { + const RzAnalEsilDFGNode *enode = (RzAnalEsilDFGNode *)node->data; + rz_list_foreach (rz_graph_get_neighbours (edf->flow, node), ator, edon) { + const RzAnalEsilDFGNode *edone = (RzAnalEsilDFGNode *)edon->data; + rz_cons_printf ("age %d %d\n", enode->idx, edone->idx); } } - r_anal_esil_dfg_free (edf); + rz_anal_esil_dfg_free (edf); } diff --git a/libr/core/cannotated_code.c b/librz/core/cannotated_code.c similarity index 82% rename from libr/core/cannotated_code.c rename to librz/core/cannotated_code.c index 836ca85ead..a0808dbd89 100644 --- a/libr/core/cannotated_code.c +++ b/librz/core/cannotated_code.c @@ -1,11 +1,11 @@ -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include -R_API void r_core_annotated_code_print_json(RAnnotatedCode *code) { +RZ_API void rz_core_annotated_code_print_json(RAnnotatedCode *code) { PJ *pj = pj_new (); if (!pj) { return; @@ -19,7 +19,7 @@ R_API void r_core_annotated_code_print_json(RAnnotatedCode *code) { char *type_str; RCodeAnnotation *annotation; - r_vector_foreach (&code->annotations, annotation) { + rz_vector_foreach (&code->annotations, annotation) { pj_o (pj); pj_kn (pj, "start", (ut64)annotation->start); pj_kn (pj, "end", (ut64)annotation->end); @@ -85,7 +85,7 @@ R_API void r_core_annotated_code_print_json(RAnnotatedCode *code) { pj_end (pj); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } @@ -93,7 +93,7 @@ R_API void r_core_annotated_code_print_json(RAnnotatedCode *code) { #define PRINT_COLOR(x) \ do { \ if (cons->context->color_mode) { \ - r_cons_printf ("%s", (x)); \ + rz_cons_printf ("%s", (x)); \ } \ } while (0) @@ -120,26 +120,26 @@ static void print_offset_in_binary_line_bar(RAnnotatedCode *code, ut64 offset, s } width -= 8; - RCons *cons = r_cons_singleton (); - r_cons_printf (" "); + RzCons *cons = rz_cons_singleton (); + rz_cons_printf (" "); if (offset == UT64_MAX) { - r_cons_print (" "); + rz_cons_print (" "); while (width > 0) { - r_cons_print (" "); + rz_cons_print (" "); width--; } } else { PRINT_COLOR (PALETTE (offset) : Color_GREEN); - r_cons_printf (fmt[width], offset); + rz_cons_printf (fmt[width], offset); PRINT_COLOR (Color_RESET); } - r_cons_printf (" |"); + rz_cons_printf (" |"); } -R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offsets) { +RZ_API void rz_core_annotated_code_print(RAnnotatedCode *code, RzVector *line_offsets) { if (code->annotations.len == 0) { - r_cons_printf ("%s\n", code->code); + rz_cons_printf ("%s\n", code->code); return; } @@ -151,7 +151,7 @@ R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offse if (line_offsets) { ut64 *offset; ut64 offset_max = 0; - r_vector_foreach (line_offsets, offset) { + rz_vector_foreach (line_offsets, offset) { if (*offset != UT64_MAX && *offset > offset_max) { offset_max = *offset; } @@ -165,9 +165,9 @@ R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offse } } - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); RCodeAnnotation *annotation; - r_vector_foreach (&code->annotations, annotation) { + rz_vector_foreach (&code->annotations, annotation) { if (annotation->type != R_CODE_ANNOTATION_TYPE_SYNTAX_HIGHLIGHT) { continue; } @@ -208,12 +208,12 @@ R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offse if (line_offsets && (cur == 0 || code->code[cur - 1] == '\n')) { ut64 offset = 0; if (line_idx < line_offsets->len) { - offset = *(ut64 *)r_vector_index_ptr (line_offsets, line_idx); + offset = *(ut64 *)rz_vector_index_ptr (line_offsets, line_idx); } print_offset_in_binary_line_bar (code, offset, offset_width); line_idx++; } - r_cons_printf ("%c", code->code[cur]); + rz_cons_printf ("%c", code->code[cur]); } // (3/3) @@ -225,14 +225,14 @@ R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offse if (line_offsets && (cur == 0 || code->code[cur - 1] == '\n')) { ut64 offset = 0; if (line_idx < line_offsets->len) { - offset = *(ut64 *)r_vector_index_ptr (line_offsets, line_idx); + offset = *(ut64 *)rz_vector_index_ptr (line_offsets, line_idx); } PRINT_COLOR (Color_RESET); print_offset_in_binary_line_bar (code, offset, offset_width); PRINT_COLOR (color); line_idx++; } - r_cons_printf ("%c", code->code[cur]); + rz_cons_printf ("%c", code->code[cur]); } PRINT_COLOR (Color_RESET); } @@ -244,28 +244,28 @@ R_API void r_core_annotated_code_print(RAnnotatedCode *code, RVector *line_offse if (line_offsets && (cur == 0 || code->code[cur - 1] == '\n')) { ut64 offset = 0; if (line_idx < line_offsets->len) { - offset = *(ut64 *)r_vector_index_ptr (line_offsets, line_idx); + offset = *(ut64 *)rz_vector_index_ptr (line_offsets, line_idx); } print_offset_in_binary_line_bar (code, offset, offset_width); line_idx++; } - r_cons_printf ("%c", code->code[cur]); + rz_cons_printf ("%c", code->code[cur]); } } static bool foreach_offset_annotation(void *user, const ut64 offset, const void *val) { RAnnotatedCode *code = user; const RCodeAnnotation *annotation = val; - char *b64statement = r_base64_encode_dyn (code->code + annotation->start, annotation->end - annotation->start); - r_cons_printf ("CCu base64:%s @ 0x%" PFMT64x "\n", b64statement, annotation->offset.offset); + char *b64statement = rz_base64_encode_dyn (code->code + annotation->start, annotation->end - annotation->start); + rz_cons_printf ("CCu base64:%s @ 0x%" PFMT64x "\n", b64statement, annotation->offset.offset); free (b64statement); return true; } -R_API void r_core_annotated_code_print_comment_cmds(RAnnotatedCode *code) { +RZ_API void rz_core_annotated_code_print_comment_cmds(RAnnotatedCode *code) { RCodeAnnotation *annotation; HtUP *ht = ht_up_new0 (); - r_vector_foreach (&code->annotations, annotation) { + rz_vector_foreach (&code->annotations, annotation) { if (annotation->type != R_CODE_ANNOTATION_TYPE_OFFSET) { continue; } diff --git a/libr/core/carg.c b/librz/core/carg.c similarity index 54% rename from libr/core/carg.c rename to librz/core/carg.c index 9b887d1122..fe7cfb1d65 100644 --- a/libr/core/carg.c +++ b/librz/core/carg.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include +#include #define MAXSTRLEN 50 -static void set_fcn_args_info(RAnalFuncArg *arg, RAnal *anal, const char *fcn_name, const char *cc, int arg_num) { +static void set_fcn_args_info(RzAnalFuncArg *arg, RzAnal *anal, const char *fcn_name, const char *cc, int arg_num) { if (!fcn_name || !arg || !anal) { return; } Sdb *TDB = anal->sdb_types; - arg->name = r_type_func_args_name (TDB, fcn_name, arg_num); - arg->orig_c_type = r_type_func_args_type (TDB, fcn_name, arg_num); + arg->name = rz_type_func_args_name (TDB, fcn_name, arg_num); + arg->orig_c_type = rz_type_func_args_type (TDB, fcn_name, arg_num); if (!arg->name || !arg->orig_c_type) { eprintf ("Missing type for function argument (%s)\n", fcn_name); return; @@ -24,39 +24,39 @@ static void set_fcn_args_info(RAnalFuncArg *arg, RAnal *anal, const char *fcn_na arg->fmt = sdb_const_get (TDB, query, 0); const char *t_query = sdb_fmt ("type.%s.size", arg->c_type); arg->size = sdb_num_get (TDB, t_query, 0) / 8; - arg->cc_source = r_anal_cc_arg (anal, cc, arg_num); + arg->cc_source = rz_anal_cc_arg (anal, cc, arg_num); } -R_API char *resolve_fcn_name(RAnal *anal, const char *func_name) { +RZ_API char *resolve_fcn_name(RzAnal *anal, const char *func_name) { const char *str = func_name; const char *name = func_name; - if (r_type_func_exist (anal->sdb_types, func_name)) { + if (rz_type_func_exist (anal->sdb_types, func_name)) { return strdup (func_name); } while ((str = strchr (str, '.'))) { name = str + 1; str++; } - if (r_type_func_exist (anal->sdb_types, name)) { + if (rz_type_func_exist (anal->sdb_types, name)) { return strdup (name); } - return r_type_func_guess (anal->sdb_types, (char*)func_name); + return rz_type_func_guess (anal->sdb_types, (char*)func_name); } static ut64 get_buf_val(ut8 *buf, int endian, int width) { - return (width == 8)? r_read_ble64 (buf, endian) : (ut64) r_read_ble32 (buf,endian); + return (width == 8)? rz_read_ble64 (buf, endian) : (ut64) rz_read_ble32 (buf,endian); } static void print_arg_str(int argcnt, const char *name, bool color) { if (color) { - r_cons_printf (Color_BYELLOW" arg [%d]"Color_RESET" -"Color_BCYAN" %s"Color_RESET" : ", + rz_cons_printf (Color_BYELLOW" arg [%d]"Color_RESET" -"Color_BCYAN" %s"Color_RESET" : ", argcnt, name); } else { - r_cons_printf (" arg [%d] - %s : ", argcnt, name); + rz_cons_printf (" arg [%d] - %s : ", argcnt, name); } } -static void print_format_values(RCore *core, const char *fmt, bool onstack, ut64 src, bool color) { +static void print_format_values(RzCore *core, const char *fmt, bool onstack, ut64 src, bool color) { char opt; ut64 bval = src; int i; @@ -77,112 +77,112 @@ static void print_format_values(RCore *core, const char *fmt, bool onstack, ut64 } if (onstack || ((opt != 'd' && opt != 'x') && !onstack)) { if (color) { - r_cons_printf (Color_BGREEN"0x%08"PFMT64x Color_RESET" --> ", bval); + rz_cons_printf (Color_BGREEN"0x%08"PFMT64x Color_RESET" --> ", bval); } else { - r_cons_printf ("0x%08"PFMT64x" --> ", bval); + rz_cons_printf ("0x%08"PFMT64x" --> ", bval); } - r_io_read_at (core->io, bval, buf, bsize); + rz_io_read_at (core->io, bval, buf, bsize); } if (onstack) { // Fetch value from stack bval = get_buf_val (buf, endian, width); if (opt != 'd' && opt != 'x') { - r_io_read_at (core->io, bval, buf, bsize); // update buf with val from stack + rz_io_read_at (core->io, bval, buf, bsize); // update buf with val from stack } } - r_cons_print (color? Color_BGREEN: ""); + rz_cons_print (color? Color_BGREEN: ""); switch (opt) { case 'z' : // Null terminated string - r_cons_print (color ?Color_RESET Color_BWHITE:""); - r_cons_print ("\""); + rz_cons_print (color ?Color_RESET Color_BWHITE:""); + rz_cons_print ("\""); for (i = 0; i < MAXSTRLEN; i++) { if (buf[i] == '\0') { break; } ut8 b = buf[i]; if (IS_PRINTABLE (b)) { - r_cons_printf ("%c", b); + rz_cons_printf ("%c", b); } else { - r_cons_printf ("\\x%02x", b); + rz_cons_printf ("\\x%02x", b); } if (i == MAXSTRLEN - 1) { - r_cons_print ("..."); // To show string is truncated + rz_cons_print ("..."); // To show string is truncated } } - r_cons_print ("\""); - r_cons_newline (); + rz_cons_print ("\""); + rz_cons_newline (); break; case 'd' : // integer case 'x' : - r_cons_printf ("0x%08" PFMT64x, bval); - r_cons_newline (); + rz_cons_printf ("0x%08" PFMT64x, bval); + rz_cons_newline (); break; case 'c' : // char - r_cons_print ("\'"); + rz_cons_print ("\'"); ut8 ch = buf[0]; if (IS_PRINTABLE (ch)) { - r_cons_printf ("%c", ch); + rz_cons_printf ("%c", ch); } else { - r_cons_printf ("\\x%02x", ch); + rz_cons_printf ("\\x%02x", ch); } - r_cons_print ("\'"); - r_cons_newline (); + rz_cons_print ("\'"); + rz_cons_newline (); break; case 'p' : // pointer { // Try to deref the pointer once again - r_cons_printf ("0x%08"PFMT64x, get_buf_val (buf, endian, width)); - r_cons_newline (); + rz_cons_printf ("0x%08"PFMT64x, get_buf_val (buf, endian, width)); + rz_cons_newline (); break; } default: //TODO: support types like structs and unions - r_cons_println ("unk_format"); + rz_cons_println ("unk_format"); } - r_cons_print (Color_RESET); + rz_cons_print (Color_RESET); free (buf); } /* This function display list of arg with some colors */ -R_API void r_core_print_func_args(RCore *core) { - RListIter *iter; - bool color = r_config_get_i (core->config, "scr.color"); +RZ_API void rz_core_print_func_args(RzCore *core) { + RzListIter *iter; + bool color = rz_config_get_i (core->config, "scr.color"); if (!core->anal) { return; } if (!core->anal->reg) { return; } - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - ut64 cur_addr = r_reg_getv (core->anal->reg, pc); - RAnalOp *op = r_core_anal_op (core, cur_addr, R_ANAL_OP_MASK_BASIC); + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + ut64 cur_addr = rz_reg_getv (core->anal->reg, pc); + RzAnalOp *op = rz_core_anal_op (core, cur_addr, R_ANAL_OP_MASK_BASIC); if (!op) { return; } if (op->type == R_ANAL_OP_TYPE_CALL) { - RAnalFunction *fcn; - RAnalFuncArg *arg; + RzAnalFunction *fcn; + RzAnalFuncArg *arg; bool onstack = false; const char *fcn_name = NULL; ut64 pcv = op->jump; if (pcv == UT64_MAX) { pcv = op->ptr; } - fcn = r_anal_get_function_at (core->anal, pcv); + fcn = rz_anal_get_function_at (core->anal, pcv); if (fcn) { fcn_name = fcn->name; } else { if (core->flags) { - RFlagItem *item = r_flag_get_i (core->flags, pcv); + RzFlagItem *item = rz_flag_get_i (core->flags, pcv); if (item) { fcn_name = item->name; } } } - RList *list = r_core_get_func_args (core, fcn_name); - if (!r_list_empty (list)) { + RzList *list = rz_core_get_func_args (core, fcn_name); + if (!rz_list_empty (list)) { int argcnt = 0; - r_list_foreach (list, iter, arg) { + rz_list_foreach (list, iter, arg) { if (arg->cc_source && !strncmp (arg->cc_source, "stack", 5)) { onstack = true; } @@ -195,20 +195,20 @@ R_API void r_core_print_func_args(RCore *core) { //if (nargs > 0) { int i; for (i = 0; i < nargs; i++) { - ut64 v = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_STDCALL, i); + ut64 v = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_STDCALL, i); print_arg_str (i, "", color); - r_cons_printf ("0x%08" PFMT64x, v); - r_cons_newline (); + rz_cons_printf ("0x%08" PFMT64x, v); + rz_cons_newline (); } //} else { // print_arg_str (0, "void", color); //} } } - r_anal_op_fini (op); + rz_anal_op_fini (op); } -static void r_anal_fcn_arg_free(RAnalFuncArg *arg) { +static void rz_anal_fcn_arg_free(RzAnalFuncArg *arg) { if (!arg) { return; } @@ -216,43 +216,43 @@ static void r_anal_fcn_arg_free(RAnalFuncArg *arg) { free (arg); } -/* Returns a list of RAnalFuncArg */ -R_API RList *r_core_get_func_args(RCore *core, const char *fcn_name) { +/* Returns a list of RzAnalFuncArg */ +RZ_API RzList *rz_core_get_func_args(RzCore *core, const char *fcn_name) { if (!fcn_name || !core->anal) { return NULL; } Sdb *TDB = core->anal->sdb_types; - RList *list = r_list_newf ((RListFree)r_anal_fcn_arg_free); + RzList *list = rz_list_newf ((RzListFree)rz_anal_fcn_arg_free); char *key = resolve_fcn_name (core->anal, fcn_name); if (!key) { return NULL; } - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - int nargs = r_type_func_args_count (TDB, key); - if (!r_anal_cc_func (core->anal, key)){ + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + int nargs = rz_type_func_args_count (TDB, key); + if (!rz_anal_cc_func (core->anal, key)){ return NULL; } - char *cc = strdup (r_anal_cc_func (core->anal, key)); - const char *src = r_anal_cc_arg (core->anal, cc, 0); // src of first argument + char *cc = strdup (rz_anal_cc_func (core->anal, key)); + const char *src = rz_anal_cc_arg (core->anal, cc, 0); // src of first argument if (!cc) { // unsupported calling convention free (key); return NULL; } int i; - ut64 spv = r_reg_getv (core->anal->reg, sp); + ut64 spv = rz_reg_getv (core->anal->reg, sp); ut64 s_width = (core->anal->bits == 64)? 8: 4; if (src && !strcmp (src, "stack_rev")) { for (i = nargs - 1; i >= 0; i--) { - RAnalFuncArg *arg = R_NEW0 (RAnalFuncArg); + RzAnalFuncArg *arg = R_NEW0 (RzAnalFuncArg); set_fcn_args_info (arg, core->anal, key, cc, i); arg->src = spv; spv += arg->size? arg->size : s_width; - r_list_append (list, arg); + rz_list_append (list, arg); } } else { for (i = 0; i < nargs; i++) { - RAnalFuncArg *arg = R_NEW0 (RAnalFuncArg); + RzAnalFuncArg *arg = R_NEW0 (RzAnalFuncArg); if (!arg) { return NULL; } @@ -266,13 +266,13 @@ R_API RList *r_core_get_func_args(RCore *core, const char *fcn_name) { } else { const char *cs = arg->cc_source; if (!cs) { - cs = r_anal_cc_default (core->anal); + cs = rz_anal_cc_default (core->anal); } if (cs) { - arg->src = r_reg_getv (core->anal->reg, cs); + arg->src = rz_reg_getv (core->anal->reg, cs); } } - r_list_append (list, arg); + rz_list_append (list, arg); } } free (key); diff --git a/libr/core/casm.c b/librz/core/casm.c similarity index 67% rename from libr/core/casm.c rename to librz/core/casm.c index ce43abb324..d06efad5d7 100644 --- a/libr/core/casm.c +++ b/librz/core/casm.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2009-2019 - nibble, pancake */ -#include -#include -#include +#include +#include +#include #define IFDBG if (0) -static RCoreAsmHit * find_addr(RList *hits, ut64 addr); -static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit); -static int is_hit_inrange(RCoreAsmHit *hit, ut64 start_range, ut64 end_range); +static RzCoreAsmHit * find_addr(RzList *hits, ut64 addr); +static int prune_hits_in_hit_range(RzList *hits, RzCoreAsmHit *hit); +static int is_hit_inrange(RzCoreAsmHit *hit, ut64 start_range, ut64 end_range); static int is_addr_in_range(ut64 start, ut64 end, ut64 start_range, ut64 end_range); -static void add_hit_to_sorted_hits(RList* hits, ut64 addr, int len, ut8 is_valid); -static int prune_hits_in_addr_range(RList *hits, ut64 addr, ut64 len, ut8 is_valid); +static void add_hit_to_sorted_hits(RzList* hits, ut64 addr, int len, ut8 is_valid); +static int prune_hits_in_addr_range(RzList *hits, ut64 addr, ut64 len, ut8 is_valid); -static int rcoreasm_address_comparator(RCoreAsmHit *a, RCoreAsmHit *b){ +static int rcoreasm_address_comparator(RzCoreAsmHit *a, RzCoreAsmHit *b){ if (a->addr == b->addr) { return 0; } @@ -23,8 +23,8 @@ static int rcoreasm_address_comparator(RCoreAsmHit *a, RCoreAsmHit *b){ return 1; /* a->addr > b->addr */ } -R_API RCoreAsmHit *r_core_asm_hit_new(void) { - RCoreAsmHit *hit = R_NEW0 (RCoreAsmHit); +RZ_API RzCoreAsmHit *rz_core_asm_hit_new(void) { + RzCoreAsmHit *hit = R_NEW0 (RzCoreAsmHit); if (!hit) { return NULL; } @@ -33,16 +33,16 @@ R_API RCoreAsmHit *r_core_asm_hit_new(void) { return hit; } -R_API RList *r_core_asm_hit_list_new(void) { - RList *list = r_list_new (); +RZ_API RzList *rz_core_asm_hit_list_new(void) { + RzList *list = rz_list_new (); if (list) { - list->free = &r_core_asm_hit_free; + list->free = &rz_core_asm_hit_free; } return list; } -R_API void r_core_asm_hit_free(void *_hit) { - RCoreAsmHit *hit = _hit; +RZ_API void rz_core_asm_hit_free(void *_hit) { + RzCoreAsmHit *hit = _hit; if (hit) { if (hit->code) { free (hit->code); @@ -51,26 +51,26 @@ R_API void r_core_asm_hit_free(void *_hit) { } } -R_API char* r_core_asm_search(RCore *core, const char *input) { - RAsmCode *acode; +RZ_API char* rz_core_asm_search(RzCore *core, const char *input) { + RzAsmCode *acode; char *ret; - if (!(acode = r_asm_massemble (core->rasm, input))) { + if (!(acode = rz_asm_massemble (core->rasm, input))) { return NULL; } - ret = r_asm_code_get_hex (acode); - r_asm_code_free (acode); + ret = rz_asm_code_get_hex (acode); + rz_asm_code_free (acode); return ret; } // TODO: add support for byte-per-byte opcode search -R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode) { - RCoreAsmHit *hit; - RAsmOp op; - RList *hits; +RZ_API RzList *rz_core_asm_strsearch(RzCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode) { + RzCoreAsmHit *hit; + RzAsmOp op; + RzList *hits; ut64 at, toff = core->offset; ut8 *buf; int align = core->search->align; - RRegex* rx = NULL; + RzRegex* rx = NULL; char *tok, *tokens[1024], *code = NULL, *ptr; int idx, tidx = 0, len = 0; int tokcount, matchcount, count = 0; @@ -81,13 +81,13 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 return NULL; } - char *inp = r_str_trim_dup (input + 1); + char *inp = rz_str_trim_dup (input + 1); char *inp_arg = strchr (inp, ' '); if (inp_arg) { *inp_arg++ = 0; } - ut64 usrimm = r_num_math (core->num, inp); - ut64 usrimm2 = inp_arg? r_num_math (core->num, inp_arg): usrimm; + ut64 usrimm = rz_num_math (core->num, inp); + ut64 usrimm2 = inp_arg? rz_num_math (core->num, inp_arg): usrimm; if (usrimm > usrimm2) { eprintf ("Error: /ci : Invalid range\n"); return NULL; @@ -104,7 +104,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 free (buf); return NULL; } - if (!(hits = r_core_asm_hit_list_new ())) { + if (!(hits = rz_core_asm_hit_list_new ())) { free (buf); free (ptr); return NULL; @@ -115,31 +115,31 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 if (!tok) { break; } - r_str_trim (tok); + rz_str_trim (tok); tokens[tokcount] = tok; } tokens[tokcount] = NULL; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); char *opst = NULL; for (at = from, matchcount = 0; at < to; at += core->blocksize) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - if (!r_io_is_valid_offset (core->io, at, 0)) { + if (!rz_io_is_valid_offset (core->io, at, 0)) { break; } - (void)r_io_read_at (core->io, at, buf, core->blocksize); + (void)rz_io_read_at (core->io, at, buf, core->blocksize); idx = 0, matchcount = 0; while (addrbytes * (idx + 1) <= core->blocksize) { ut64 addr = at + idx; if (addr >= to) { break; } - r_asm_set_pc (core->rasm, addr); + rz_asm_set_pc (core->rasm, addr); if (mode == 'i') { - RAnalOp analop = {0}; + RzAnalOp analop = {0}; ut64 len = R_MIN (15, core->blocksize - idx); - if (r_anal_op (core->anal, &analop, addr, buf + idx, len, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM) < 1) { + if (rz_anal_op (core->anal, &analop, addr, buf + idx, len, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM) < 1) { idx ++; // TODO: honor mininstrsz continue; } @@ -154,39 +154,39 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 match = (val != UT64_MAX && val >= usrimm && val <= usrimm2); } if (match) { - if (!(hit = r_core_asm_hit_new ())) { - r_list_purge (hits); + if (!(hit = rz_core_asm_hit_new ())) { + rz_list_purge (hits); R_FREE (hits); goto beach; } hit->addr = addr; hit->len = analop.size; // idx + len - tidx; if (hit->len == -1) { - r_core_asm_hit_free (hit); + rz_core_asm_hit_free (hit); goto beach; } - r_asm_disassemble (core->rasm, &op, buf + addrbytes * idx, + rz_asm_disassemble (core->rasm, &op, buf + addrbytes * idx, core->blocksize - addrbytes * idx); - hit->code = r_str_newf (r_strbuf_get (&op.buf_asm)); + hit->code = rz_str_newf (rz_strbuf_get (&op.buf_asm)); idx = (matchcount)? tidx + 1: idx + 1; matchcount = 0; - r_list_append (hits, hit); + rz_list_append (hits, hit); continue; } - r_anal_op_fini (&analop); + rz_anal_op_fini (&analop); idx ++; // TODO: honor mininstrsz continue; } else if (mode == 'e') { - RAnalOp analop = {0}; - if (r_anal_op (core->anal, &analop, addr, buf + idx, 15, R_ANAL_OP_MASK_ESIL) < 1) { + RzAnalOp analop = {0}; + if (rz_anal_op (core->anal, &analop, addr, buf + idx, 15, R_ANAL_OP_MASK_ESIL) < 1) { idx ++; // TODO: honor mininstrsz continue; } //opsz = analop.size; - opst = strdup (r_strbuf_get (&analop.esil)); - r_anal_op_fini (&analop); + opst = strdup (rz_strbuf_get (&analop.esil)); + rz_anal_op_fini (&analop); } else { - if (!(len = r_asm_disassemble ( + if (!(len = rz_asm_disassemble ( core->rasm, &op, buf + addrbytes * idx, core->blocksize - addrbytes * idx))) { @@ -195,20 +195,20 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 continue; } //opsz = op.size; - opst = strdup (r_strbuf_get (&op.buf_asm)); + opst = strdup (rz_strbuf_get (&op.buf_asm)); } if (opst) { matches = strcmp (opst, "invalid") && strcmp (opst, "unaligned"); } if (matches && tokens[matchcount]) { if (mode == 'a') { // check for case sensitive - matches = !r_str_ncasecmp (opst, tokens[matchcount], strlen (tokens[matchcount])); + matches = !rz_str_ncasecmp (opst, tokens[matchcount], strlen (tokens[matchcount])); } else if (!regexp) { matches = strstr (opst, tokens[matchcount]) != NULL; } else { - rx = r_regex_new (tokens[matchcount], "es"); - matches = r_regex_exec (rx, opst, 0, 0, 0) == 0; - r_regex_free (rx); + rx = rz_regex_new (tokens[matchcount], "es"); + matches = rz_regex_exec (rx, opst, 0, 0, 0) == 0; + rz_regex_free (rx); } } if (align && align > 1) { @@ -217,25 +217,25 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 } } if (matches) { - code = r_str_appendf (code, "%s; ", opst); + code = rz_str_appendf (code, "%s; ", opst); if (matchcount == tokcount - 1) { if (tokcount == 1) { tidx = idx; } - if (!(hit = r_core_asm_hit_new ())) { - r_list_purge (hits); + if (!(hit = rz_core_asm_hit_new ())) { + rz_list_purge (hits); R_FREE (hits); goto beach; } hit->addr = addr; hit->len = idx + len - tidx; if (hit->len == -1) { - r_core_asm_hit_free (hit); + rz_core_asm_hit_free (hit); goto beach; } code[strlen (code) - 2] = 0; hit->code = strdup (code); - r_list_append (hits, hit); + rz_list_append (hits, hit); R_FREE (code); matchcount = 0; idx = tidx + 1; @@ -266,54 +266,54 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 R_FREE (opst); } } - r_cons_break_pop (); - r_asm_set_pc (core->rasm, toff); + rz_cons_break_pop (); + rz_asm_set_pc (core->rasm, toff); beach: free (buf); free (ptr); free (code); R_FREE (opst); - r_cons_break_pop (); + rz_cons_break_pop (); return hits; } -static void add_hit_to_sorted_hits(RList* hits, ut64 addr, int len, ut8 is_valid) { - RCoreAsmHit *hit = r_core_asm_hit_new(); +static void add_hit_to_sorted_hits(RzList* hits, ut64 addr, int len, ut8 is_valid) { + RzCoreAsmHit *hit = rz_core_asm_hit_new(); if (hit) { IFDBG eprintf("*** Inserting instruction (valid?: %d): instr_addr: 0x%"PFMT64x" instr_len: %d\n", is_valid, addr, len ); hit->addr = addr; hit->len = len; hit->valid = is_valid; hit->code = NULL; - r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator)); + rz_list_add_sorted (hits, hit, ((RzListComparator)rcoreasm_address_comparator)); } } -static void add_hit_to_hits(RList* hits, ut64 addr, int len, ut8 is_valid) { - RCoreAsmHit *hit = r_core_asm_hit_new(); +static void add_hit_to_hits(RzList* hits, ut64 addr, int len, ut8 is_valid) { + RzCoreAsmHit *hit = rz_core_asm_hit_new(); if (hit) { IFDBG eprintf("*** Inserting instruction (valid?: %d): instr_addr: 0x%"PFMT64x" instr_len: %d\n", is_valid, addr, len); hit->addr = addr; hit->len = len; hit->valid = is_valid; hit->code = NULL; - if (!r_list_append (hits, hit)){ + if (!rz_list_append (hits, hit)){ free (hit); } } } -static int prune_hits_in_addr_range(RList *hits, ut64 addr, ut64 len, ut8 is_valid) { - RCoreAsmHit hit = R_EMPTY; +static int prune_hits_in_addr_range(RzList *hits, ut64 addr, ut64 len, ut8 is_valid) { + RzCoreAsmHit hit = R_EMPTY; hit.addr = addr; hit.len = len; hit.valid = is_valid; return prune_hits_in_hit_range(hits, &hit); } -static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){ - RListIter *iter, *iter_tmp; - RCoreAsmHit *to_check_hit; +static int prune_hits_in_hit_range(RzList *hits, RzCoreAsmHit *hit){ + RzListIter *iter, *iter_tmp; + RzCoreAsmHit *to_check_hit; int result = 0; ut64 start_range, end_range; if (!hit || !hits) { @@ -321,7 +321,7 @@ static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){ } start_range = hit->addr; end_range = hit->addr + hit->len; - r_list_foreach_safe (hits, iter, iter_tmp, to_check_hit){ + rz_list_foreach_safe (hits, iter, iter_tmp, to_check_hit){ if (to_check_hit && is_hit_inrange(to_check_hit, start_range, end_range)) { IFDBG eprintf ("Found hit that clashed (start: 0x%"PFMT64x " - end: 0x%"PFMT64x" ), 0x%"PFMT64x" len: %d (valid: %d 0x%"PFMT64x @@ -329,7 +329,7 @@ static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){ to_check_hit->len, to_check_hit->valid, to_check_hit->addr, to_check_hit->addr+to_check_hit->len); // XXX - could this be a valid decode instruction we are deleting? - r_list_delete (hits, iter); + rz_list_delete (hits, iter); //iter->data = NULL; to_check_hit = NULL; result ++; @@ -338,17 +338,17 @@ static int prune_hits_in_hit_range(RList *hits, RCoreAsmHit *hit){ return result; } -static RCoreAsmHit * find_addr(RList *hits, ut64 addr) { +static RzCoreAsmHit * find_addr(RzList *hits, ut64 addr) { // Find an address in the list of hits - RListIter *addr_iter = NULL; - RCoreAsmHit dummy_value; + RzListIter *addr_iter = NULL; + RzCoreAsmHit dummy_value; dummy_value.addr = addr; - addr_iter = r_list_find (hits, &dummy_value, ((RListComparator)rcoreasm_address_comparator)); - return r_list_iter_get_data(addr_iter); + addr_iter = rz_list_find (hits, &dummy_value, ((RzListComparator)rcoreasm_address_comparator)); + return rz_list_iter_get_data(addr_iter); } -static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 len, ut64 current_buf_pos, ut64 current_instr_addr, ut64 end_addr){ - RCoreAsmHit *hit = NULL, *found_addr = NULL; +static int handle_forward_disassemble(RzCore* core, RzList *hits, ut8* buf, ut64 len, ut64 current_buf_pos, ut64 current_instr_addr, ut64 end_addr){ + RzCoreAsmHit *hit = NULL, *found_addr = NULL; // forward disassemble from the current instruction up to the end address ut64 temp_instr_addr = current_instr_addr; ut64 tmp_current_buf_pos = current_buf_pos; @@ -357,17 +357,17 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l ut64 temp_instr_len = 0; ut64 start = 0, end = 0; ut8 is_valid = false; - RAsmOp op; + RzAsmOp op; if (end_addr < current_instr_addr) { return end_addr; } - r_asm_set_pc (core->rasm, current_instr_addr); + rz_asm_set_pc (core->rasm, current_instr_addr); while (tmp_current_buf_pos < len && temp_instr_addr < end_addr) { temp_instr_len = len - tmp_current_buf_pos; IFDBG eprintf("Current position: %"PFMT64d" instr_addr: 0x%"PFMT64x"\n", tmp_current_buf_pos, temp_instr_addr); - temp_instr_len = r_asm_disassemble (core->rasm, &op, buf+tmp_current_buf_pos, temp_instr_len); + temp_instr_len = rz_asm_disassemble (core->rasm, &op, buf+tmp_current_buf_pos, temp_instr_len); if (temp_instr_len == 0){ is_valid = false; @@ -388,7 +388,7 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l prune_results = prune_hits_in_addr_range(hits, temp_instr_addr, temp_instr_len, is_valid); add_hit_to_sorted_hits(hits, temp_instr_addr, temp_instr_len, is_valid); if (prune_results) { - r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator)); + rz_list_add_sorted (hits, hit, ((RzListComparator)rcoreasm_address_comparator)); IFDBG eprintf("Pruned %u hits from list in fwd sweep.\n", prune_results); } else { R_FREE (hit); @@ -402,7 +402,7 @@ static int handle_forward_disassemble(RCore* core, RList *hits, ut8* buf, ut64 l } #if 0 -static int handle_disassembly_overlap(RCore* core, RList *hits, ut8* buf, int len, ut64 current_buf_pos, ut64 current_instr_addr ) { +static int handle_disassembly_overlap(RzCore* core, RzList *hits, ut8* buf, int len, ut64 current_buf_pos, ut64 current_instr_addr ) { // disassemble over lap means the current instruction decoded using the bytes in a previously decoded instruction ut64 next_buf_pos = current_buf_pos, end_addr = current_instr_addr + ( len - current_buf_pos - 1); @@ -465,7 +465,7 @@ static int is_addr_in_range(ut64 start, ut64 end, ut64 start_range, ut64 end_ran return result; } -static int is_hit_inrange(RCoreAsmHit *hit, ut64 start_range, ut64 end_range){ +static int is_hit_inrange(RzCoreAsmHit *hit, ut64 start_range, ut64 end_range){ int result = false; if (hit) { result = is_addr_in_range (hit->addr, @@ -475,46 +475,46 @@ static int is_hit_inrange(RCoreAsmHit *hit, ut64 start_range, ut64 end_range){ return result; } -R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { - RAsmOp op; +RZ_API RzList *rz_core_asm_bwdisassemble(RzCore *core, ut64 addr, int n, int len) { + RzAsmOp op; // if (n > core->blocksize) n = core->blocksize; ut64 at; ut32 idx = 0, hit_count; int numinstr, asmlen, ii; const int addrbytes = core->io->addrbytes; - RAsmCode *c; - RList *hits = r_core_asm_hit_list_new (); + RzAsmCode *c; + RzList *hits = rz_core_asm_hit_list_new (); if (!hits) { return NULL; } len = R_MIN (len - len % addrbytes, addrbytes * addr); if (len < 1) { - r_list_free (hits); + rz_list_free (hits); return NULL; } ut8 *buf = (ut8 *)malloc (len); if (!buf) { - r_list_free (hits); + rz_list_free (hits); return NULL; } else if (!hits) { free (buf); return NULL; } - if (!r_io_read_at (core->io, addr - len / addrbytes, buf, len)) { - r_list_free (hits); + if (!rz_io_read_at (core->io, addr - len / addrbytes, buf, len)) { + rz_list_free (hits); free (buf); return NULL; } for (idx = addrbytes; idx < len; idx += addrbytes) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - c = r_asm_mdisassemble (core->rasm, buf + len - idx, idx); + c = rz_asm_mdisassemble (core->rasm, buf + len - idx, idx); if (strstr (c->assembly, "invalid") || strstr (c->assembly, ".byte")) { - r_asm_code_free(c); + rz_asm_code_free(c); continue; } numinstr = 0; @@ -524,15 +524,15 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { ++numinstr; } } - r_asm_code_free(c); + rz_asm_code_free(c); if (numinstr >= n || idx > 16 * n) { // assume average instruction length <= 16 break; } } at = addr - idx / addrbytes; - r_asm_set_pc (core->rasm, at); + rz_asm_set_pc (core->rasm, at); for (hit_count = 0; hit_count < n; hit_count++) { - int instrlen = r_asm_disassemble (core->rasm, &op, + int instrlen = rz_asm_disassemble (core->rasm, &op, buf + len - addrbytes * (addr - at), addrbytes * (addr - at)); add_hit_to_hits (hits, at, instrlen, true); at += instrlen; @@ -541,30 +541,30 @@ R_API RList *r_core_asm_bwdisassemble(RCore *core, ut64 addr, int n, int len) { return hits; } -static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len, ut64 max_hit_count, ut32 extra_padding){ - RList *hits = r_core_asm_hit_list_new (); - RCoreAsmHit dummy_value; - RCoreAsmHit *hit = NULL; - RAsmOp op; +static RzList * rz_core_asm_back_disassemble_all(RzCore *core, ut64 addr, ut64 len, ut64 max_hit_count, ut32 extra_padding){ + RzList *hits = rz_core_asm_hit_list_new (); + RzCoreAsmHit dummy_value; + RzCoreAsmHit *hit = NULL; + RzAsmOp op; ut8 *buf = (ut8 *)malloc (len + extra_padding); int current_instr_len = 0; ut64 current_instr_addr = addr, current_buf_pos = len - 1, hit_count = 0; - memset (&dummy_value, 0, sizeof (RCoreAsmHit)); + memset (&dummy_value, 0, sizeof (RzCoreAsmHit)); if (!hits || !buf ){ if (hits) { - r_list_purge (hits); + rz_list_purge (hits); free (hits); } free (buf); return NULL; } - if (!r_io_read_at (core->io, addr-(len+extra_padding), buf, len + extra_padding)) { - r_list_purge (hits); + if (!rz_io_read_at (core->io, addr-(len+extra_padding), buf, len + extra_padding)) { + rz_list_purge (hits); free (hits); free (buf); return NULL; @@ -575,19 +575,19 @@ static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len, } do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // reset assembler - r_asm_set_pc (core->rasm, current_instr_addr); + rz_asm_set_pc (core->rasm, current_instr_addr); current_instr_len = len - current_buf_pos + extra_padding; IFDBG eprintf("current_buf_pos: 0x%"PFMT64x", current_instr_len: %d\n", current_buf_pos, current_instr_len); - current_instr_len = r_asm_disassemble (core->rasm, &op, buf+current_buf_pos, current_instr_len); - hit = r_core_asm_hit_new (); + current_instr_len = rz_asm_disassemble (core->rasm, &op, buf+current_buf_pos, current_instr_len); + hit = rz_core_asm_hit_new (); hit->addr = current_instr_addr; hit->len = current_instr_len; hit->code = NULL; - r_list_add_sorted (hits, hit, ((RListComparator)rcoreasm_address_comparator)); + rz_list_add_sorted (hits, hit, ((RzListComparator)rcoreasm_address_comparator)); current_buf_pos--; current_instr_addr--; @@ -598,9 +598,9 @@ static RList * r_core_asm_back_disassemble_all(RCore *core, ut64 addr, ut64 len, return hits; } -static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 max_hit_count, ut8 disassmble_each_addr, ut32 extra_padding) { - RList *hits;; - RAsmOp op; +static RzList *rz_core_asm_back_disassemble (RzCore *core, ut64 addr, int len, ut64 max_hit_count, ut8 disassmble_each_addr, ut32 extra_padding) { + RzList *hits;; + RzAsmOp op; ut8 *buf = NULL; ut8 max_invalid_b4_exit = 4, last_num_invalid = 0; @@ -609,26 +609,26 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 current_buf_pos = 0, next_buf_pos = len; - RCoreAsmHit dummy_value; + RzCoreAsmHit dummy_value; ut32 hit_count = 0; if (disassmble_each_addr) { - return r_core_asm_back_disassemble_all(core, addr, len, max_hit_count, extra_padding+1); + return rz_core_asm_back_disassemble_all(core, addr, len, max_hit_count, extra_padding+1); } - hits = r_core_asm_hit_list_new (); + hits = rz_core_asm_hit_list_new (); buf = malloc (len + extra_padding); if (!hits || !buf) { if (hits) { - r_list_purge (hits); + rz_list_purge (hits); free (hits); } free (buf); return NULL; } - if (!r_io_read_at (core->io, (addr + extra_padding) - len, buf, len + extra_padding)) { - r_list_purge (hits); + if (!rz_io_read_at (core->io, (addr + extra_padding) - len, buf, len + extra_padding)) { + rz_list_purge (hits); free (hits); free (buf); return NULL; @@ -638,7 +638,7 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 // XXX - This is a heavy handed approach without a // an appropriate btree or hash table for storing // hits, because are using: - // 1) Sorted RList with many inserts and searches + // 1) Sorted RzList with many inserts and searches // 2) Pruning hits to find the most optimal disassembly // greedy approach @@ -648,36 +648,36 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 // 1c) Disasm is underlap (disasm(current_instr_addr, next_instr_addr - current_instr_addr) short some bytes) // 1d) Disasm is overlap (disasm(current_instr_addr, next_instr_addr - current_instr_addr) over some bytes) - memset (&dummy_value, 0, sizeof (RCoreAsmHit)); + memset (&dummy_value, 0, sizeof (RzCoreAsmHit)); // disassemble instructions previous to current address, extra_padding can move the location of addr // so we need to account for that with current_buf_pos current_buf_pos = len - extra_padding - 1; next_buf_pos = len + extra_padding - 1; current_instr_addr = addr - 1; do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // reset assembler - r_asm_set_pc (core->rasm, current_instr_addr); + rz_asm_set_pc (core->rasm, current_instr_addr); current_instr_len = next_buf_pos - current_buf_pos; - current_instr_len = r_asm_disassemble (core->rasm, &op, buf+current_buf_pos, current_instr_len); + current_instr_len = rz_asm_disassemble (core->rasm, &op, buf+current_buf_pos, current_instr_len); IFDBG { ut32 byte_cnt = current_instr_len ? current_instr_len : 1; eprintf("current_instr_addr: 0x%"PFMT64x", current_buf_pos: 0x%"PFMT64x", current_instr_len: %d \n", current_instr_addr, current_buf_pos, current_instr_len); - ut8 *hex_str = (ut8*)r_hex_bin2strdup(buf+current_buf_pos, byte_cnt); + ut8 *hex_str = (ut8*)rz_hex_bin2strdup(buf+current_buf_pos, byte_cnt); eprintf ("==== current_instr_bytes: %s ",hex_str); if (current_instr_len > 0) { - eprintf("op.buf_asm: %s\n", r_strbuf_get (&op.buf_asm)); + eprintf("op.buf_asm: %s\n", rz_strbuf_get (&op.buf_asm)); } else { eprintf("op.buf_asm: \n"); } free (hex_str); } // disassembly invalid - if (current_instr_len == 0 || strstr (r_strbuf_get (&op.buf_asm), "invalid")) { + if (current_instr_len == 0 || strstr (rz_strbuf_get (&op.buf_asm), "invalid")) { if (current_instr_len == 0) { current_instr_len = 1; } @@ -696,7 +696,7 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 purge_results = prune_hits_in_addr_range(hits, current_instr_addr, current_instr_len, /* is_valid */ true); if (purge_results) { handle_forward_disassemble(core, hits, buf, len, current_buf_pos+current_instr_len, current_instr_addr+current_instr_len, addr); - hit_count = r_list_length(hits); + hit_count = rz_list_length(hits); } add_hit_to_sorted_hits(hits, current_instr_addr, current_instr_len, is_valid); //handle_forward_disassemble(core, hits, buf, len, current_buf_pos+current_instr_len, current_instr_addr+current_instr_len, addr/*end_addr*/); @@ -718,13 +718,13 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 next_buf_pos = current_buf_pos; handle_forward_disassemble(core, hits, buf, len - extra_padding, current_buf_pos+current_instr_len, current_instr_addr+current_instr_len, addr); - hit_count = r_list_length(hits); + hit_count = rz_list_length(hits); last_num_invalid = 0; // disassembly overlap } else if (current_buf_pos + current_instr_len > next_buf_pos) { //ut64 value = handle_disassembly_overlap(core, hits, buf, len, current_buf_pos, current_instr_addr); next_buf_pos = current_buf_pos; - hit_count = r_list_length (hits); + hit_count = rz_list_length (hits); last_num_invalid = 0; } @@ -741,46 +741,46 @@ static RList *r_core_asm_back_disassemble (RCore *core, ut64 addr, int len, ut64 } } while (((int) current_buf_pos >= 0) && (int)(len - current_buf_pos) >= 0); - r_asm_set_pc (core->rasm, addr); + rz_asm_set_pc (core->rasm, addr); free (buf); return hits; } -R_API RList *r_core_asm_back_disassemble_instr (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding){ +RZ_API RzList *rz_core_asm_back_disassemble_instr (RzCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding){ // extra padding to allow for additional disassembly on border buffer cases ut8 disassmble_each_addr = false; - return r_core_asm_back_disassemble (core, addr, len, hit_count, disassmble_each_addr, extra_padding); + return rz_core_asm_back_disassemble (core, addr, len, hit_count, disassmble_each_addr, extra_padding); } -R_API RList *r_core_asm_back_disassemble_byte (RCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding){ +RZ_API RzList *rz_core_asm_back_disassemble_byte (RzCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding){ // extra padding to allow for additional disassembly on border buffer cases ut8 disassmble_each_addr = true; - return r_core_asm_back_disassemble (core, addr, len, hit_count, disassmble_each_addr, extra_padding); + return rz_core_asm_back_disassemble (core, addr, len, hit_count, disassmble_each_addr, extra_padding); } /* Compute the len and the starting address * when disassembling `nb` opcodes backward. */ -R_API ut32 r_core_asm_bwdis_len(RCore* core, int* instr_len, ut64* start_addr, ut32 nb) { +RZ_API ut32 rz_core_asm_bwdis_len(RzCore* core, int* instr_len, ut64* start_addr, ut32 nb) { ut32 instr_run = 0; - RCoreAsmHit *hit; - RListIter *iter = NULL; + RzCoreAsmHit *hit; + RzListIter *iter = NULL; // TODO if length of nb instructions is larger than blocksize - RList* hits = r_core_asm_bwdisassemble (core, core->offset, nb, core->blocksize); + RzList* hits = rz_core_asm_bwdisassemble (core, core->offset, nb, core->blocksize); if (instr_len) { *instr_len = 0; } - if (hits && r_list_length (hits) > 0) { - hit = r_list_get_bottom (hits); + if (hits && rz_list_length (hits) > 0) { + hit = rz_list_get_bottom (hits); if (start_addr) { *start_addr = hit->addr; } - r_list_foreach (hits, iter, hit) { + rz_list_foreach (hits, iter, hit) { instr_run += hit->len; } if (instr_len) { *instr_len = instr_run; } } - r_list_free (hits); + rz_list_free (hits); return instr_run; } diff --git a/libr/core/cbin.c b/librz/core/cbin.c similarity index 62% rename from libr/core/cbin.c rename to librz/core/cbin.c index d200bed9f4..4c5436df1c 100644 --- a/libr/core/cbin.c +++ b/librz/core/cbin.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2011-2020 - earada, pancake */ -#include -#include -#include "r_util.h" -#include "r_util/r_time.h" +#include +#include +#include "rz_util.h" +#include "rz_util/rz_time.h" #define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz))) @@ -33,19 +33,19 @@ static void pair(const char *key, const char *val, int mode, bool last) { } if (IS_MODE_JSON (mode)) { const char *lst = last ? "" : ","; - r_cons_printf ("\"%s\":%s%s", key, val, lst); + rz_cons_printf ("\"%s\":%s%s", key, val, lst); } else { char ws[16]; const int keyl = strlen (key); const int wl = (keyl > PAIR_WIDTH) ? 0 : PAIR_WIDTH - keyl; memset (ws, ' ', wl); ws[wl] = 0; - r_cons_printf ("%s%s%s\n", key, ws, val); + rz_cons_printf ("%s%s%s\n", key, ws, val); } } static void pair_bool(const char *key, bool val, int mode, bool last) { - pair (key, r_str_bool (val), mode, last); + pair (key, rz_str_bool (val), mode, last); } static void pair_int(const char *key, int val, int mode, bool last) { @@ -57,7 +57,7 @@ static void pair_ut64(const char *key, ut64 val, int mode, bool last) { } static char *__filterQuotedShell(const char *arg) { - r_return_val_if_fail (arg, NULL); + rz_return_val_if_fail (arg, NULL); char *a = malloc (strlen (arg) + 1); if (!a) { return NULL; @@ -81,9 +81,9 @@ static char *__filterQuotedShell(const char *arg) { *b = 0; return a; } -// TODO: move into libr/util/name.c +// TODO: move into librz/util/name.c static char *__filterShell(const char *arg) { - r_return_val_if_fail (arg, NULL); + rz_return_val_if_fail (arg, NULL); char *a = malloc (strlen (arg) + 1); if (!a) { return NULL; @@ -119,9 +119,9 @@ static void pair_str(const char *key, const char *val, int mode, int last) { if (!val) { val = ""; } - char *encval = r_str_escape_utf8_for_json (val, -1); + char *encval = rz_str_escape_utf8_for_json (val, -1); if (encval) { - char *qs = r_str_newf ("\"%s\"", encval); + char *qs = rz_str_newf ("\"%s\"", encval); pair (key, qs, mode, last); free (encval); free (qs); @@ -132,12 +132,12 @@ static void pair_str(const char *key, const char *val, int mode, int last) { } #define STR(x) (x)? (x): "" -R_API int r_core_bin_set_cur(RCore *core, RBinFile *binfile); +RZ_API int rz_core_bin_set_cur(RzCore *core, RBinFile *binfile); static ut64 rva(RBin *bin, ut64 paddr, ut64 vaddr, int va) { if (va == VA_TRUE) { if (paddr != UT64_MAX) { - return r_bin_get_vaddr (bin, paddr, vaddr); + return rz_bin_get_vaddr (bin, paddr, vaddr); } } if (va == VA_NOREBASE) { @@ -146,17 +146,17 @@ static ut64 rva(RBin *bin, ut64 paddr, ut64 vaddr, int va) { return paddr; } -R_API int r_core_bin_set_by_fd(RCore *core, ut64 bin_fd) { - if (r_bin_file_set_cur_by_fd (core->bin, bin_fd)) { - r_core_bin_set_cur (core, r_bin_cur (core->bin)); +RZ_API int rz_core_bin_set_by_fd(RzCore *core, ut64 bin_fd) { + if (rz_bin_file_set_cur_by_fd (core->bin, bin_fd)) { + rz_core_bin_set_cur (core, rz_bin_cur (core->bin)); return true; } return false; } -R_API void r_core_bin_export_info(RCore *core, int mode) { +RZ_API void rz_core_bin_export_info(RzCore *core, int mode) { char *flagname = NULL, *offset = NULL; - RBinFile *bf = r_bin_cur (core->bin); + RBinFile *bf = rz_bin_cur (core->bin); if (!bf) { return; } @@ -167,9 +167,9 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { SdbListIter *iter; SdbKv *kv; if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs format\n"); + rz_cons_printf ("fs format\n"); } else if (IS_MODE_SET (mode)) { - r_flag_space_push (core->flags, "format"); + rz_flag_space_push (core->flags, "format"); } // iterate over all keys SdbList *ls = sdb_foreach_list (db, false); @@ -182,28 +182,28 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { *flagname = 0; flagname = dup; if (IS_MODE_RAD (mode)) { - r_cons_printf ("f %s @ %s\n", flagname, v); + rz_cons_printf ("f %s @ %s\n", flagname, v); } else if (IS_MODE_SET (mode)) { - ut64 nv = r_num_math (core->num, v); - r_flag_set (core->flags, flagname, nv, 0); + ut64 nv = rz_num_math (core->num, v); + rz_flag_set (core->flags, flagname, nv, 0); } free (offset); offset = strdup (v); } if ((flagname = strstr (dup, ".cparse"))) { if (IS_MODE_RAD (mode)) { - r_cons_printf ("\"td %s\"\n", v); + rz_cons_printf ("\"td %s\"\n", v); } else if (IS_MODE_SET (mode)) { - char *code = r_str_newf ("%s;", v); + char *code = rz_str_newf ("%s;", v); char *error_msg = NULL; - char *out = r_parse_c_string (core->anal, code, &error_msg); + char *out = rz_parse_c_string (core->anal, code, &error_msg); free (code); if (error_msg) { eprintf ("%s", error_msg); free (error_msg); } if (out) { - r_anal_save_parsed_type (core->anal, out); + rz_anal_save_parsed_type (core->anal, out); free (out); } } @@ -222,7 +222,7 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { } flagname = dup; if (IS_MODE_RAD (mode)) { - r_cons_printf ("pf.%s %s\n", flagname, v); + rz_cons_printf ("pf.%s %s\n", flagname, v); } else if (IS_MODE_SET (mode)) { sdb_set (core->print->formats, flagname, v, 0); } @@ -239,19 +239,19 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { offset = strdup ("0"); } flagname = dup; - int fmtsize = r_print_format_struct_size (core->print, v, 0, 0); - char *offset_key = r_str_newf ("%s.offset", flagname); + int fmtsize = rz_print_format_struct_size (core->print, v, 0, 0); + char *offset_key = rz_str_newf ("%s.offset", flagname); const char *off = sdb_const_get (db, offset_key, 0); free (offset_key); if (off) { if (IS_MODE_RAD (mode)) { - r_cons_printf ("Cf %d %s @ %s\n", fmtsize, v, off); + rz_cons_printf ("Cf %d %s @ %s\n", fmtsize, v, off); } else if (IS_MODE_SET (mode)) { - ut64 addr = r_num_get (NULL, off); + ut64 addr = rz_num_get (NULL, off); ut8 *buf = malloc (fmtsize); if (buf) { - r_io_read_at (core->io, addr, buf, fmtsize); - int res = r_print_format (core->print, addr, buf, + rz_io_read_at (core->io, addr, buf, fmtsize); + int res = rz_print_format (core->print, addr, buf, fmtsize, v, 0, NULL, NULL); free (buf); if (res < 0) { @@ -265,11 +265,11 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { *flagname = 0; flagname = dup; if (IS_MODE_RAD (mode)) { - r_cons_printf ("fl %s %s\n", flagname, v); + rz_cons_printf ("fl %s %s\n", flagname, v); } else if (IS_MODE_SET (mode)) { - RFlagItem *fi = r_flag_get (core->flags, flagname); + RzFlagItem *fi = rz_flag_get (core->flags, flagname); if (fi) { - fi->size = r_num_math (core->num, v); + fi->size = rz_num_math (core->num, v); } else { eprintf ("Cannot find flag named '%s'\n", flagname); } @@ -279,16 +279,16 @@ R_API void r_core_bin_export_info(RCore *core, int mode) { } free (offset); if (IS_MODE_SET (mode)) { - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); } } -R_API bool r_core_bin_load_structs(RCore *core, const char *file) { - r_return_val_if_fail (core && file && core->io, false); +RZ_API bool rz_core_bin_load_structs(RzCore *core, const char *file) { + rz_return_val_if_fail (core && file && core->io, false); if (!file) { - int fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + int fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { file = desc->name; } @@ -301,27 +301,27 @@ R_API bool r_core_bin_load_structs(RCore *core, const char *file) { return false; } RBinOptions opt = { 0 }; - r_bin_open (core->bin, file, &opt); - RBinFile *bf = r_bin_cur (core->bin); + rz_bin_open (core->bin, file, &opt); + RBinFile *bf = rz_bin_cur (core->bin); if (bf) { - r_core_bin_export_info (core, R_MODE_SET); - r_bin_file_delete (core->bin, bf->id); + rz_core_bin_export_info (core, R_MODE_SET); + rz_bin_file_delete (core->bin, bf->id); return true; } eprintf ("Cannot open bin '%s'\n", file); return false; } -R_API int r_core_bin_set_by_name(RCore *core, const char * name) { - if (r_bin_file_set_cur_by_name (core->bin, name)) { - r_core_bin_set_cur (core, r_bin_cur (core->bin)); +RZ_API int rz_core_bin_set_by_name(RzCore *core, const char * name) { + if (rz_bin_file_set_cur_by_name (core->bin, name)) { + rz_core_bin_set_cur (core, rz_bin_cur (core->bin)); return true; } return false; } -R_API int r_core_bin_set_env(RCore *r, RBinFile *binfile) { - r_return_val_if_fail (r, false); +RZ_API int rz_core_bin_set_env(RzCore *r, RBinFile *binfile) { + rz_return_val_if_fail (r, false); RBinObject *binobj = binfile? binfile->o: NULL; RBinInfo *info = binobj? binobj->info: NULL; @@ -329,53 +329,53 @@ R_API int r_core_bin_set_env(RCore *r, RBinFile *binfile) { int va = info->has_va; const char *arch = info->arch; ut16 bits = info->bits; - ut64 baseaddr = r_bin_get_baddr (r->bin); - r_config_set_i (r->config, "bin.baddr", baseaddr); + ut64 baseaddr = rz_bin_get_baddr (r->bin); + rz_config_set_i (r->config, "bin.baddr", baseaddr); sdb_num_add (r->sdb, "orig_baddr", baseaddr, 0); r->dbg->bp->baddr = baseaddr; - r_config_set (r->config, "asm.arch", arch); - r_config_set_i (r->config, "asm.bits", bits); - r_config_set (r->config, "anal.arch", arch); + rz_config_set (r->config, "asm.arch", arch); + rz_config_set_i (r->config, "asm.bits", bits); + rz_config_set (r->config, "anal.arch", arch); if (info->cpu && *info->cpu) { - r_config_set (r->config, "anal.cpu", info->cpu); + rz_config_set (r->config, "anal.cpu", info->cpu); } else { - r_config_set (r->config, "anal.cpu", arch); + rz_config_set (r->config, "anal.cpu", arch); } - r_asm_use (r->rasm, arch); - r_core_bin_info (r, R_CORE_BIN_ACC_ALL, R_MODE_SET, va, NULL, NULL); - r_core_bin_set_cur (r, binfile); + rz_asm_use (r->rasm, arch); + rz_core_bin_info (r, R_CORE_BIN_ACC_ALL, R_MODE_SET, va, NULL, NULL); + rz_core_bin_set_cur (r, binfile); return true; } return false; } -R_API int r_core_bin_set_cur(RCore *core, RBinFile *binfile) { +RZ_API int rz_core_bin_set_cur(RzCore *core, RBinFile *binfile) { if (!core->bin) { return false; } if (!binfile) { // Find first available binfile - ut32 fd = r_core_file_cur_fd (core); + ut32 fd = rz_core_file_cur_fd (core); binfile = fd != (ut32)-1 - ? r_bin_file_find_by_fd (core->bin, fd) + ? rz_bin_file_find_by_fd (core->bin, fd) : NULL; if (!binfile) { return false; } } - r_bin_file_set_cur_binfile (core->bin, binfile); + rz_bin_file_set_cur_binfile (core->bin, binfile); return true; } -static void _print_strings(RCore *r, RList *list, int mode, int va) { - bool b64str = r_config_get_i (r->config, "bin.b64str"); - int minstr = r_config_get_i (r->config, "bin.minstr"); - int maxstr = r_config_get_i (r->config, "bin.maxstr"); - RTable *table = r_core_table (r); - r_return_if_fail (table); +static void _print_strings(RzCore *r, RzList *list, int mode, int va) { + bool b64str = rz_config_get_i (r->config, "bin.b64str"); + int minstr = rz_config_get_i (r->config, "bin.minstr"); + int maxstr = rz_config_get_i (r->config, "bin.maxstr"); + RTable *table = rz_core_table (r); + rz_return_if_fail (table); RBin *bin = r->bin; - RBinObject *obj = r_bin_cur_object (bin); - RListIter *iter; + RBinObject *obj = rz_bin_cur_object (bin); + RzListIter *iter; RBinString *string; RBinSection *section; PJ *pj = NULL; @@ -386,21 +386,21 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { pj = pj_new (); pj_a (pj); } else if (IS_MODE_RAD (mode)) { - r_cons_println ("fs strings"); - } else if (IS_MODE_SET (mode) && r_config_get_i (r->config, "bin.strings")) { - r_flag_space_set (r->flags, R_FLAGS_FS_STRINGS); - r_cons_break_push (NULL, NULL); + rz_cons_println ("fs strings"); + } else if (IS_MODE_SET (mode) && rz_config_get_i (r->config, "bin.strings")) { + rz_flag_space_set (r->flags, R_FLAGS_FS_STRINGS); + rz_cons_break_push (NULL, NULL); } else if (IS_MODE_NORMAL (mode)) { - r_cons_printf ("[Strings]\n"); - r_table_set_columnsf (table, "nXXnnsss", "nth", "paddr", "vaddr", "len", "size", "section", "type", "string"); + rz_cons_printf ("[Strings]\n"); + rz_table_set_columnsf (table, "nXXnnsss", "nth", "paddr", "vaddr", "len", "size", "section", "type", "string"); } RBinString b64 = { 0 }; - r_list_foreach (list, iter, string) { + rz_list_foreach (list, iter, string) { const char *section_name, *type_string; ut64 paddr, vaddr; paddr = string->paddr; vaddr = rva (r->bin, paddr, string->vaddr, va); - if (!r_bin_string_filter (bin, string->string, vaddr)) { + if (!rz_bin_string_filter (bin, string->string, vaddr)) { continue; } if (string->length < minstr) { @@ -410,11 +410,11 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { continue; } - section = obj? r_bin_get_section_at (obj, paddr, 0): NULL; + section = obj? rz_bin_get_section_at (obj, paddr, 0): NULL; section_name = section ? section->name : ""; - type_string = r_bin_string_type (string->type); + type_string = rz_bin_string_type (string->type); if (b64str) { - ut8 *s = r_base64_decode_dyn (string->string, -1); + ut8 *s = rz_base64_decode_dyn (string->string, -1); if (s && *s && IS_PRINTABLE (*s)) { // TODO: add more checks free (b64.string); @@ -426,25 +426,25 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { } if (IS_MODE_SET (mode)) { char *f_name, *str; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_meta_set (r->anal, R_META_TYPE_STRING, vaddr, string->size, string->string); + rz_meta_set (r->anal, R_META_TYPE_STRING, vaddr, string->size, string->string); f_name = strdup (string->string); - r_name_filter (f_name, -1); + rz_name_filter (f_name, -1); if (r->bin->prefix) { - str = r_str_newf ("%s.str.%s", r->bin->prefix, f_name); + str = rz_str_newf ("%s.str.%s", r->bin->prefix, f_name); } else { - str = r_str_newf ("str.%s", f_name); + str = rz_str_newf ("str.%s", f_name); } - (void)r_flag_set (r->flags, str, vaddr, string->size); + (void)rz_flag_set (r->flags, str, vaddr, string->size); free (str); free (f_name); } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("0x%"PFMT64x" %d %d %s\n", vaddr, + rz_cons_printf ("0x%"PFMT64x" %d %d %s\n", vaddr, string->size, string->length, string->string); } else if (IS_MODE_SIMPLEST (mode)) { - r_cons_println (string->string); + rz_cons_println (string->string); } else if (IS_MODE_JSON (mode)) { int *block_list; pj_o (pj); @@ -460,7 +460,7 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { case R_STRING_TYPE_UTF8: case R_STRING_TYPE_WIDE: case R_STRING_TYPE_WIDE32: - block_list = r_utf_block_list ((const ut8*)string->string, -1, NULL); + block_list = rz_utf_block_list ((const ut8*)string->string, -1, NULL); if (block_list) { if (block_list[0] == 0 && block_list[1] == -1) { /* Don't include block list if @@ -472,7 +472,7 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { pj_k (pj, "blocks"); pj_a (pj); for (; *block_ptr != -1; block_ptr++) { - const char *utfName = r_utf_block_name (*block_ptr); + const char *utfName = rz_utf_block_name (*block_ptr); pj_s (pj, utfName? utfName: ""); } pj_end (pj); @@ -482,11 +482,11 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { pj_end (pj); } else if (IS_MODE_RAD (mode)) { char *f_name = strdup (string->string); - r_name_filter (f_name, R_FLAG_NAME_SIZE); + rz_name_filter (f_name, R_FLAG_NAME_SIZE); char *str = (r->bin->prefix) - ? r_str_newf ("%s.str.%s", r->bin->prefix, f_name) - : r_str_newf ("str.%s", f_name); - r_cons_printf ("f %s %"PFMT64d" 0x%08"PFMT64x"\n" + ? rz_str_newf ("%s.str.%s", r->bin->prefix, f_name) + : rz_str_newf ("str.%s", f_name); + rz_cons_printf ("f %s %"PFMT64d" 0x%08"PFMT64x"\n" "Cs %"PFMT64d" @ 0x%08"PFMT64x"\n", str, string->size, vaddr, string->size, vaddr); @@ -518,12 +518,12 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { } } - RStrBuf *buf = r_strbuf_new (str); + RStrBuf *buf = rz_strbuf_new (str); switch (string->type) { case R_STRING_TYPE_UTF8: case R_STRING_TYPE_WIDE: case R_STRING_TYPE_WIDE32: - block_list = r_utf_block_list ((const ut8*)string->string, -1, NULL); + block_list = rz_utf_block_list ((const ut8*)string->string, -1, NULL); if (block_list) { if (block_list[0] == 0 && block_list[1] == -1) { /* Don't show block list if @@ -531,20 +531,20 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { break; } int *block_ptr = block_list; - r_strbuf_append (buf, " blocks="); + rz_strbuf_append (buf, " blocks="); for (; *block_ptr != -1; block_ptr++) { if (block_ptr != block_list) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } - const char *name = r_utf_block_name (*block_ptr); - r_strbuf_appendf (buf,"%s", name? name: ""); + const char *name = rz_utf_block_name (*block_ptr); + rz_strbuf_appendf (buf,"%s", name? name: ""); } free (block_list); } break; } - char *bufstr = r_strbuf_drain (buf); - r_table_add_rowf (table, "nXXddsss", (ut64)string->ordinal, paddr, vaddr, + char *bufstr = rz_strbuf_drain (buf); + rz_table_add_rowf (table, "nXXddsss", (ut64)string->ordinal, paddr, vaddr, (int)string->length, (int)string->size, section_name, type_string, bufstr); free (bufstr); @@ -554,27 +554,27 @@ static void _print_strings(RCore *r, RList *list, int mode, int va) { R_FREE (b64.string); if (IS_MODE_JSON (mode)) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); pj = NULL; } else if (IS_MODE_SET (mode)) { - r_cons_break_pop (); + rz_cons_break_pop (); } else if (IS_MODE_NORMAL (mode)) { if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } - char *s = r_table_tostring (table); + char *s = rz_table_tostring (table); if (s) { - r_cons_printf ("%s", s); + rz_cons_printf ("%s", s); free (s); } } - r_table_free (table); + rz_table_free (table); } -static bool bin_raw_strings(RCore *r, int mode, int va) { - RBinFile *bf = r_bin_cur (r->bin); +static bool bin_raw_strings(RzCore *r, int mode, int va) { + RBinFile *bf = rz_bin_cur (r->bin); bool new_bf = false; if (bf && strstr (bf->file, "malloc://")) { //sync bf->buf to search string on it @@ -582,13 +582,13 @@ static bool bin_raw_strings(RCore *r, int mode, int va) { if (!tmp) { return false; } - r_io_read_at (r->io, 0, tmp, bf->size); - r_buf_write_at (bf->buf, 0, tmp, bf->size); + rz_io_read_at (r->io, 0, tmp, bf->size); + rz_buf_write_at (bf->buf, 0, tmp, bf->size); } if (!r->file) { eprintf ("Core file not open\n"); if (IS_MODE_JSON (mode)) { - r_cons_print ("[]"); + rz_cons_print ("[]"); return true; } return false; @@ -598,56 +598,56 @@ static bool bin_raw_strings(RCore *r, int mode, int va) { if (!bf) { return false; } - RIODesc *desc = r_io_desc_get (r->io, r->file->fd); + RzIODesc *desc = rz_io_desc_get (r->io, r->file->fd); if (!desc) { free (bf); return false; } bf->file = strdup (desc->name); - bf->size = r_io_desc_size (desc); + bf->size = rz_io_desc_size (desc); if (bf->size == UT64_MAX) { free (bf); return false; } - bf->buf = r_buf_new_with_io (&r->bin->iob, r->file->fd); + bf->buf = rz_buf_new_with_io (&r->bin->iob, r->file->fd); bf->o = NULL; bf->rbin = r->bin; new_bf = true; va = false; } - RList *l = r_bin_raw_strings (bf, 0); + RzList *l = rz_bin_raw_strings (bf, 0); _print_strings (r, l, mode, va); - r_list_free (l); + rz_list_free (l); if (new_bf) { - r_buf_free (bf->buf); + rz_buf_free (bf->buf); bf->buf = NULL; bf->id = -1; - r_bin_file_free (bf); + rz_bin_file_free (bf); } return true; } -static bool bin_strings(RCore *r, int mode, int va) { - RList *list; - RBinFile *binfile = r_bin_cur (r->bin); - RBinPlugin *plugin = r_bin_file_cur_plugin (binfile); - int rawstr = r_config_get_i (r->config, "bin.rawstr"); +static bool bin_strings(RzCore *r, int mode, int va) { + RzList *list; + RBinFile *binfile = rz_bin_cur (r->bin); + RBinPlugin *plugin = rz_bin_file_cur_plugin (binfile); + int rawstr = rz_config_get_i (r->config, "bin.rawstr"); if (!binfile || !plugin) { return false; } - if (!r_config_get_i (r->config, "bin.strings")) { + if (!rz_config_get_i (r->config, "bin.strings")) { return false; } if (plugin->info && plugin->name) { if (strcmp (plugin->name, "any") == 0 && !rawstr) { if (IS_MODE_JSON (mode)) { - r_cons_print ("[]\n"); + rz_cons_print ("[]\n"); return true; } return false; } } - if (!(list = r_bin_get_strings (r->bin))) { + if (!(list = rz_bin_get_strings (r->bin))) { return false; } _print_strings (r, list, mode, va); @@ -662,13 +662,13 @@ static const char* get_compile_time(Sdb *binFileSdb) { } static bool is_executable(RBinObject *obj) { - RListIter *it; + RzListIter *it; RBinSection* sec; - r_return_val_if_fail (obj, false); + rz_return_val_if_fail (obj, false); if (obj->info && obj->info->arch) { return true; } - r_list_foreach (obj->sections, it, sec) { + rz_list_foreach (obj->sections, it, sec) { if (sec->perm & R_PERM_X) { return true; } @@ -683,67 +683,67 @@ static void sdb_concat_by_path(Sdb *s, const char *path) { sdb_free (db); } -R_API void r_core_anal_type_init(RCore *core) { - r_return_if_fail (core && core->anal); - const char *dir_prefix = r_config_get (core->config, "dir.prefix"); +RZ_API void rz_core_anal_type_init(RzCore *core) { + rz_return_if_fail (core && core->anal); + const char *dir_prefix = rz_config_get (core->config, "dir.prefix"); int bits = core->rasm->bits; Sdb *types = core->anal->sdb_types; // make sure they are empty this is initializing sdb_reset (types); - const char *anal_arch = r_config_get (core->config, "anal.arch"); - const char *os = r_config_get (core->config, "asm.os"); + const char *anal_arch = rz_config_get (core->config, "anal.arch"); + const char *os = rz_config_get (core->config, "asm.os"); // spaguetti ahead const char *dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types.sdb"), dir_prefix); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s.sdb"), dir_prefix, anal_arch); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s.sdb"), dir_prefix, os); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%d.sdb"), dir_prefix, bits); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s-%d.sdb"), dir_prefix, os, bits); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s-%d.sdb"), dir_prefix, anal_arch, bits); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s-%s.sdb"), dir_prefix, anal_arch, os); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } dbpath = sdb_fmt (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "types-%s-%s-%d.sdb"), dir_prefix, anal_arch, os, bits); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (types, dbpath); } } -R_API void r_core_anal_cc_init(RCore *core) { - const char *dir_prefix = r_config_get (core->config, "dir.prefix"); - const char *anal_arch = r_config_get (core->config, "anal.arch"); +RZ_API void rz_core_anal_cc_init(RzCore *core) { + const char *dir_prefix = rz_config_get (core->config, "dir.prefix"); + const char *anal_arch = rz_config_get (core->config, "anal.arch"); int bits = core->anal->bits; Sdb *cc = core->anal->sdb_cc; - char *dbpath = r_str_newf (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "cc-%s-%d.sdb"), + char *dbpath = rz_str_newf (R_JOIN_3_PATHS ("%s", R2_SDB_FCNSIGN, "cc-%s-%d.sdb"), dir_prefix, anal_arch, bits); - char *dbhomepath = r_str_newf (R_JOIN_3_PATHS ("~", R2_HOME_SDB_FCNSIGN, "cc-%s-%d.sdb"), + char *dbhomepath = rz_str_newf (R_JOIN_3_PATHS ("~", R2_HOME_SDB_FCNSIGN, "cc-%s-%d.sdb"), anal_arch, bits); // Avoid sdb reloading if (cc->path && !strcmp (cc->path, dbpath) && !strcmp (cc->path, dbhomepath)) { @@ -751,18 +751,18 @@ R_API void r_core_anal_cc_init(RCore *core) { } sdb_reset (cc); R_FREE (cc->path); - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { sdb_concat_by_path (cc, dbpath); cc->path = strdup (dbpath); } - if (r_file_exists (dbhomepath)) { + if (rz_file_exists (dbhomepath)) { sdb_concat_by_path (cc, dbhomepath); cc->path = strdup (dbhomepath); } // same as "tcc `arcc`" - char *s = r_reg_profile_to_cc (core->anal->reg); + char *s = rz_reg_profile_to_cc (core->anal->reg); if (s) { - if (!r_anal_cc_set (core->anal, s)) { + if (!rz_anal_cc_set (core->anal, s)) { eprintf ("Warning: Invalid CC from reg profile.\n"); } free (s); @@ -774,14 +774,14 @@ R_API void r_core_anal_cc_init(RCore *core) { } } -static int bin_info(RCore *r, int mode, ut64 laddr) { +static int bin_info(RzCore *r, int mode, ut64 laddr) { int i, j, v; char str[R_FLAG_NAME_SIZE]; - RBinInfo *info = r_bin_get_info (r->bin); - RBinFile *bf = r_bin_cur (r->bin); + RBinInfo *info = rz_bin_get_info (r->bin); + RBinFile *bf = rz_bin_cur (r->bin); if (!bf) { if (IS_MODE_JSON (mode)) { - r_cons_printf ("{}\n"); + rz_cons_printf ("{}\n"); } return false; } @@ -791,7 +791,7 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { if (!bf || !info || !obj) { if (mode & R_MODE_JSON) { - r_cons_printf ("{}\n"); + rz_cons_printf ("{}\n"); return true; } return false; @@ -800,108 +800,108 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { compiled = get_compile_time (bf->sdb); if (IS_MODE_SET (mode)) { - r_config_set (r->config, "file.type", info->rclass); - r_config_set (r->config, "cfg.bigendian", + rz_config_set (r->config, "file.type", info->rclass); + rz_config_set (r->config, "cfg.bigendian", info->big_endian ? "true" : "false"); if (!info->rclass || strcmp (info->rclass, "fs")) { if (info->lang) { - r_config_set (r->config, "bin.lang", info->lang); + rz_config_set (r->config, "bin.lang", info->lang); } - r_config_set (r->config, "asm.os", info->os); + rz_config_set (r->config, "asm.os", info->os); if (info->rclass && !strcmp (info->rclass, "pe")) { - r_config_set (r->config, "anal.cpp.abi", "msvc"); + rz_config_set (r->config, "anal.cpp.abi", "msvc"); } else { - r_config_set (r->config, "anal.cpp.abi", "itanium"); + rz_config_set (r->config, "anal.cpp.abi", "itanium"); } - r_config_set (r->config, "asm.arch", info->arch); + rz_config_set (r->config, "asm.arch", info->arch); if (info->cpu && *info->cpu) { - r_config_set (r->config, "asm.cpu", info->cpu); + rz_config_set (r->config, "asm.cpu", info->cpu); } if (info->features && *info->features) { - r_config_set (r->config, "asm.features", info->features); + rz_config_set (r->config, "asm.features", info->features); } - r_config_set (r->config, "anal.arch", info->arch); + rz_config_set (r->config, "anal.arch", info->arch); snprintf (str, R_FLAG_NAME_SIZE, "%i", info->bits); - r_config_set (r->config, "asm.bits", str); - r_config_set (r->config, "asm.dwarf", + rz_config_set (r->config, "asm.bits", str); + rz_config_set (r->config, "asm.dwarf", (R_BIN_DBG_STRIPPED & info->dbg_info) ? "false" : "true"); - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { - r_config_set_i (r->config, "asm.pcalign", v); + rz_config_set_i (r->config, "asm.pcalign", v); } } - r_core_anal_type_init (r); - r_core_anal_cc_init (r); - if (info->default_cc && r_anal_cc_exist (r->anal, info->default_cc)) { - r_core_cmdf (r, "k anal/cc/default.cc=%s", info->default_cc); + rz_core_anal_type_init (r); + rz_core_anal_cc_init (r); + if (info->default_cc && rz_anal_cc_exist (r->anal, info->default_cc)) { + rz_core_cmdf (r, "k anal/cc/default.cc=%s", info->default_cc); } } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("arch %s\n", info->arch); + rz_cons_printf ("arch %s\n", info->arch); if (info->cpu && *info->cpu) { - r_cons_printf ("cpu %s\n", info->cpu); + rz_cons_printf ("cpu %s\n", info->cpu); } - r_cons_printf ("bits %d\n", info->bits); - r_cons_printf ("os %s\n", info->os); - r_cons_printf ("endian %s\n", info->big_endian? "big": "little"); - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + rz_cons_printf ("bits %d\n", info->bits); + rz_cons_printf ("os %s\n", info->os); + rz_cons_printf ("endian %s\n", info->big_endian? "big": "little"); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); if (v != -1) { - r_cons_printf ("minopsz %d\n", v); + rz_cons_printf ("minopsz %d\n", v); } - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); if (v != -1) { - r_cons_printf ("maxopsz %d\n", v); + rz_cons_printf ("maxopsz %d\n", v); } - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { - r_cons_printf ("pcalign %d\n", v); + rz_cons_printf ("pcalign %d\n", v); } } else if (IS_MODE_RAD (mode)) { if (info->type && !strcmp (info->type, "fs")) { - r_cons_printf ("e file.type=fs\n"); - r_cons_printf ("m /root %s 0\n", info->arch); + rz_cons_printf ("e file.type=fs\n"); + rz_cons_printf ("m /root %s 0\n", info->arch); } else { - r_cons_printf ("e cfg.bigendian=%s\n" + rz_cons_printf ("e cfg.bigendian=%s\n" "e asm.bits=%i\n" "e asm.dwarf=%s\n", - r_str_bool (info->big_endian), + rz_str_bool (info->big_endian), info->bits, - r_str_bool (R_BIN_DBG_STRIPPED &info->dbg_info)); + rz_str_bool (R_BIN_DBG_STRIPPED &info->dbg_info)); if (info->lang && *info->lang) { - r_cons_printf ("e bin.lang=%s\n", info->lang); + rz_cons_printf ("e bin.lang=%s\n", info->lang); } if (info->rclass && *info->rclass) { - r_cons_printf ("e file.type=%s\n", + rz_cons_printf ("e file.type=%s\n", info->rclass); } if (info->os) { - r_cons_printf ("e asm.os=%s\n", info->os); + rz_cons_printf ("e asm.os=%s\n", info->os); } if (info->arch) { - r_cons_printf ("e asm.arch=%s\n", info->arch); + rz_cons_printf ("e asm.arch=%s\n", info->arch); } if (info->cpu && *info->cpu) { - r_cons_printf ("e asm.cpu=%s\n", info->cpu); + rz_cons_printf ("e asm.cpu=%s\n", info->cpu); } if (info->default_cc) { - r_cons_printf ("k anal/cc/default.cc=%s", info->default_cc); + rz_cons_printf ("k anal/cc/default.cc=%s", info->default_cc); } - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { - r_cons_printf ("e asm.pcalign=%d\n", v); + rz_cons_printf ("e asm.pcalign=%d\n", v); } } } else { // XXX: if type is 'fs' show something different? char *tmp_buf; if (IS_MODE_JSON (mode)) { - r_cons_printf ("{"); + rz_cons_printf ("{"); } pair_str ("arch", info->arch, mode, false); if (info->cpu && *info->cpu) { pair_str ("cpu", info->cpu, mode, false); } - pair_ut64x ("baddr", r_bin_get_baddr (r->bin), mode, false); - pair_ut64 ("binsz", r_bin_get_size (r->bin), mode, false); + pair_ut64x ("baddr", rz_bin_get_baddr (r->bin), mode, false); + pair_ut64 ("binsz", rz_bin_get_size (r->bin), mode, false); pair_str ("bintype", info->rclass, mode, false); pair_int ("bits", info->bits, mode, false); pair_bool ("canary", info->has_canary, mode, false); @@ -937,11 +937,11 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { pair_bool ("linenum", R_BIN_DBG_LINENUMS & info->dbg_info, mode, false); pair_bool ("lsyms", R_BIN_DBG_SYMS & info->dbg_info, mode, false); pair_str ("machine", info->machine, mode, false); - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); if (v != -1) { pair_int ("maxopsz", v, mode, false); } - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); if (v != -1) { pair_int ("minopsz", v, mode, false); } @@ -951,7 +951,7 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { pair_bool ("overlay", info->pe_overlay, mode, false); } pair_str ("cc", info->default_cc, mode, false); - v = r_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); + v = rz_anal_archinfo (r->anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { pair_int ("pcalign", v, mode, false); } @@ -969,7 +969,7 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { pair_bool ("signed", info->signature, mode, false); } pair_bool ("sanitiz", info->has_sanitizers, mode, false); - pair_bool ("static", r_bin_is_static (r->bin), mode, false); + pair_bool ("static", rz_bin_is_static (r->bin), mode, false); if (info->rclass && !strcmp (info->rclass, "mdmp")) { v = sdb_num_get (bf->sdb, "mdmp.streams", 0); if (v != -1) { @@ -980,60 +980,60 @@ static int bin_info(RCore *r, int mode, ut64 laddr) { pair_str ("subsys", info->subsystem, mode, false); pair_bool ("va", info->has_va, mode, true); if (IS_MODE_JSON (mode)) { - r_cons_printf (",\"checksums\":{"); + rz_cons_printf (",\"checksums\":{"); for (i = 0; info->sum[i].type; i++) { RBinHash *h = &info->sum[i]; - ut64 hash = r_hash_name_to_bits (h->type); - RHash *rh = r_hash_new (true, hash); + ut64 hash = rz_hash_name_to_bits (h->type); + RzHash *rh = rz_hash_new (true, hash); ut8 *tmp = R_NEWS (ut8, h->to); if (!tmp) { return false; } - r_buf_read_at (bf->buf, h->from, tmp, h->to); - int len = r_hash_calculate (rh, hash, tmp, h->to); + rz_buf_read_at (bf->buf, h->from, tmp, h->to); + int len = rz_hash_calculate (rh, hash, tmp, h->to); free (tmp); if (len < 1) { eprintf ("Invalid checksum length\n"); } - r_hash_free (rh); - r_cons_printf ("%s\"%s\":{\"hex\":\"", i?",": "", h->type); - // r_cons_printf ("%s\t%d-%dc\t", h->type, h->from, h->to+h->from); + rz_hash_free (rh); + rz_cons_printf ("%s\"%s\":{\"hex\":\"", i?",": "", h->type); + // rz_cons_printf ("%s\t%d-%dc\t", h->type, h->from, h->to+h->from); for (j = 0; j < h->len; j++) { - r_cons_printf ("%02x", h->buf[j]); + rz_cons_printf ("%02x", h->buf[j]); } - r_cons_printf ("\"}"); + rz_cons_printf ("\"}"); } - r_cons_printf ("}"); + rz_cons_printf ("}"); } else { for (i = 0; info->sum[i].type; i++) { RBinHash *h = &info->sum[i]; - ut64 hash = r_hash_name_to_bits (h->type); - RHash *rh = r_hash_new (true, hash); + ut64 hash = rz_hash_name_to_bits (h->type); + RzHash *rh = rz_hash_new (true, hash); ut8 *tmp = R_NEWS (ut8, h->to); if (!tmp) { return false; } - r_buf_read_at (bf->buf, h->from, tmp, h->to); - int len = r_hash_calculate (rh, hash, tmp, h->to); + rz_buf_read_at (bf->buf, h->from, tmp, h->to); + int len = rz_hash_calculate (rh, hash, tmp, h->to); free (tmp); if (len < 1) { eprintf ("Invalid wtf\n"); } - r_hash_free (rh); - r_cons_printf ("%s %d-%dc ", h->type, h->from, h->to+h->from); + rz_hash_free (rh); + rz_cons_printf ("%s %d-%dc ", h->type, h->from, h->to+h->from); for (j = 0; j < h->len; j++) { - r_cons_printf ("%02x", h->buf[j]); + rz_cons_printf ("%02x", h->buf[j]); } - r_cons_newline (); + rz_cons_newline (); } } if (IS_MODE_JSON (mode)) { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } } - const char *dir_prefix = r_config_get (r->config, "dir.prefix"); + const char *dir_prefix = rz_config_get (r->config, "dir.prefix"); char *spath = sdb_fmt ("%s/"R2_SDB_FCNSIGN"/spec.sdb", dir_prefix); - if (r_file_exists (spath)) { + if (rz_file_exists (spath)) { sdb_concat_by_path (r->anal->sdb_fmts, spath); } return true; @@ -1059,9 +1059,9 @@ FileLines *read_file_lines(const char *path) { if (!result) { return result; } - result->content = r_file_slurp (path, NULL); + result->content = rz_file_slurp (path, NULL); if (result->content) { - result->line_starts = r_str_split_lines (result->content, &result->line_count); + result->line_starts = rz_str_split_lines (result->content, &result->line_count); } if (!result->content || !result->line_starts) { R_FREE (result); @@ -1074,53 +1074,53 @@ static void file_lines_free_kv(HtPPKv *kv) { file_lines_free (kv->value); } -static int bin_dwarf(RCore *core, int mode) { +static int bin_dwarf(RzCore *core, int mode) { RBinDwarfRow *row; - RListIter *iter; - if (!r_config_get_i (core->config, "bin.dbginfo")) { + RzListIter *iter; + if (!rz_config_get_i (core->config, "bin.dbginfo")) { return false; } - RBinFile *binfile = r_bin_cur (core->bin); - RBinPlugin * plugin = r_bin_file_cur_plugin (binfile); + RBinFile *binfile = rz_bin_cur (core->bin); + RBinPlugin * plugin = rz_bin_file_cur_plugin (binfile); if (!binfile) { return false; } - RList *list = NULL; - RList *ownlist = NULL; + RzList *list = NULL; + RzList *ownlist = NULL; if (plugin && plugin->lines) { // list is not cloned to improve speed. avoid use after free list = plugin->lines (binfile); } else if (core->bin) { // TODO: complete and speed-up support for dwarf RBinDwarfDebugAbbrev *da = NULL; - da = r_bin_dwarf_parse_abbrev (core->bin, mode); - RBinDwarfDebugInfo *info = r_bin_dwarf_parse_info (da, core->bin, mode); - HtUP /**/ *loc_table = r_bin_dwarf_parse_loc (core->bin, core->anal->bits / 8); + da = rz_bin_dwarf_parse_abbrev (core->bin, mode); + RBinDwarfDebugInfo *info = rz_bin_dwarf_parse_info (da, core->bin, mode); + HtUP /**/ *loc_table = rz_bin_dwarf_parse_loc (core->bin, core->anal->bits / 8); // I suppose there is no reason the parse it for a printing purposes if (info && mode != R_MODE_PRINT) { /* Should we do this by default? */ - RAnalDwarfContext ctx = { + RzAnalDwarfContext ctx = { .info = info, .loc = loc_table }; - r_anal_dwarf_process_info (core->anal, &ctx); + rz_anal_dwarf_process_info (core->anal, &ctx); } if (loc_table) { if (mode == R_MODE_PRINT) { - r_bin_dwarf_print_loc (loc_table, core->anal->bits / 8, r_cons_printf); + rz_bin_dwarf_print_loc (loc_table, core->anal->bits / 8, rz_cons_printf); } - r_bin_dwarf_free_loc (loc_table); + rz_bin_dwarf_free_loc (loc_table); } - r_bin_dwarf_free_debug_info (info); - r_bin_dwarf_parse_aranges (core->bin, mode); - list = ownlist = r_bin_dwarf_parse_line (core->bin, mode); - r_bin_dwarf_free_debug_abbrev (da); + rz_bin_dwarf_free_debug_info (info); + rz_bin_dwarf_parse_aranges (core->bin, mode); + list = ownlist = rz_bin_dwarf_parse_line (core->bin, mode); + rz_bin_dwarf_free_debug_abbrev (da); } if (!list) { return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); /* cache file:line contents */ HtPP* file_lines = ht_pp_new (NULL, file_lines_free_kv, NULL); @@ -1130,10 +1130,10 @@ static int bin_dwarf(RCore *core, int mode) { pj_a (j); } - //TODO we should need to store all this in sdb, or do a filecontentscache in libr/util + //TODO we should need to store all this in sdb, or do a filecontentscache in librz/util //XXX this whole thing has leaks - r_list_foreach (list, iter, row) { - if (r_cons_is_breaked ()) { + rz_list_foreach (list, iter, row) { + if (rz_cons_is_breaked ()) { break; } if (mode) { @@ -1156,14 +1156,14 @@ static int bin_dwarf(RCore *core, int mode) { } } if (line) { - r_str_filter (line, strlen (line)); - line = r_str_replace (line, "\"", "\\\"", 1); - line = r_str_replace (line, "\\\\", "\\", 1); + rz_str_filter (line, strlen (line)); + line = rz_str_replace (line, "\"", "\\\"", 1); + line = rz_str_replace (line, "\\\\", "\\", 1); } - bool chopPath = !r_config_get_i (core->config, "dir.dwarf.abspath"); + bool chopPath = !rz_config_get_i (core->config, "dir.dwarf.abspath"); char *file = strdup (row->file); if (chopPath) { - const char *slash = r_str_lchr (file, '/'); + const char *slash = rz_str_lchr (file, '/'); if (slash) { memmove (file, slash + 1, strlen (slash)); } @@ -1171,10 +1171,10 @@ static int bin_dwarf(RCore *core, int mode) { // TODO: implement internal : if ((mode & R_MODE_SET)) if ((mode & R_MODE_SET)) { // TODO: use CL here.. but its not necessary.. so better not do anything imho - // r_core_cmdf (core, "CL %s:%d 0x%08"PFMT64x, file, (int)row->line, row->address); + // rz_core_cmdf (core, "CL %s:%d 0x%08"PFMT64x, file, (int)row->line, row->address); #if 0 - char *cmt = r_str_newf ("%s:%d %s", file, (int)row->line, line? line: ""); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, row->address, cmt); + char *cmt = rz_str_newf ("%s:%d %s", file, (int)row->line, line? line: ""); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, row->address, cmt); free (cmt); #endif } else if(IS_MODE_JSON(mode)) { @@ -1197,10 +1197,10 @@ static int bin_dwarf(RCore *core, int mode) { pj_end (j); } else { - r_cons_printf ("CL %s:%d 0x%08" PFMT64x "\n", + rz_cons_printf ("CL %s:%d 0x%08" PFMT64x "\n", file, (int)row->line, row->address); - r_cons_printf ("\"CC %s:%d %s\"@0x%" PFMT64x + rz_cons_printf ("\"CC %s:%d %s\"@0x%" PFMT64x "\n", file, row->line, line ? line : "", row->address); @@ -1208,26 +1208,26 @@ static int bin_dwarf(RCore *core, int mode) { free (file); free (line); } else { - r_cons_printf ("0x%08" PFMT64x "\t%s\t%d\n", + rz_cons_printf ("0x%08" PFMT64x "\t%s\t%d\n", row->address, row->file, row->line); } } if (IS_MODE_JSON(mode)) { pj_end (j); - r_cons_printf ("%s", pj_string (j)); + rz_cons_printf ("%s", pj_string (j)); pj_free (j); j = NULL; } - r_cons_break_pop (); + rz_cons_break_pop (); ht_pp_free (file_lines); - r_list_free (ownlist); + rz_list_free (ownlist); return true; } -R_API bool r_core_pdb_info(RCore *core, const char *file, int mode) { - r_return_val_if_fail (core && file, false); +RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, int mode) { + rz_return_val_if_fail (core && file, false); - ut64 baddr = r_config_get_i (core->config, "bin.baddr"); + ut64 baddr = rz_config_get_i (core->config, "bin.baddr"); if (core->bin->cur && core->bin->cur->o && core->bin->cur->o->baddr) { baddr = core->bin->cur->o->baddr; } else { @@ -1236,7 +1236,7 @@ R_API bool r_core_pdb_info(RCore *core, const char *file, int mode) { RPdb pdb = R_EMPTY; - pdb.cb_printf = r_cons_printf; + pdb.cb_printf = rz_cons_printf; if (!init_pdb_parser (&pdb, file)) { return false; } @@ -1249,7 +1249,7 @@ R_API bool r_core_pdb_info(RCore *core, const char *file, int mode) { switch (mode) { case R_MODE_SET: mode = 's'; - r_core_cmd0 (core, ".iP*"); + rz_core_cmd0 (core, ".iP*"); return true; case R_MODE_JSON: mode = 'j'; @@ -1267,78 +1267,78 @@ R_API bool r_core_pdb_info(RCore *core, const char *file, int mode) { pdb.print_types (&pdb, pj, mode); pdb.print_gvars (&pdb, baddr, pj, mode); // Save compound types into SDB - r_parse_pdb_types (core->anal, &pdb); + rz_parse_pdb_types (core->anal, &pdb); pdb.finish_pdb_parse (&pdb); if (mode == 'j') { - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); } pj_free (pj); return true; } static int srclineCmp(const void *a, const void *b) { - return r_str_cmp (a, b, -1); + return rz_str_cmp (a, b, -1); } -static int bin_source(RCore *r, int mode) { - RList *final_list = r_list_new (); +static int bin_source(RzCore *r, int mode) { + RzList *final_list = rz_list_new (); RBinFile * binfile = r->bin->cur; if (!binfile) { bprintf ("[Error bin file]\n"); - r_list_free (final_list); + rz_list_free (final_list); return false; } SdbListIter *iter; - RListIter *iter2; + RzListIter *iter2; char* srcline; SdbKv *kv; SdbList *ls = sdb_foreach_list (binfile->sdb_addrinfo, false); ls_foreach (ls, iter, kv) { char *v = sdbkv_value (kv); - RList *list = r_str_split_list (v, "|", 0); - srcline = r_list_get_bottom (list); + RzList *list = rz_str_split_list (v, "|", 0); + srcline = rz_list_get_bottom (list); if (srcline) { if (!strstr (srcline, "0x")){ - r_list_append (final_list, srcline); + rz_list_append (final_list, srcline); } } - r_list_free (list); + rz_list_free (list); } - r_cons_printf ("[Source file]\n"); - RList *uniqlist = r_list_uniq (final_list, srclineCmp); - r_list_foreach (uniqlist, iter2, srcline) { - r_cons_printf ("%s\n", srcline); + rz_cons_printf ("[Source file]\n"); + RzList *uniqlist = rz_list_uniq (final_list, srclineCmp); + rz_list_foreach (uniqlist, iter2, srcline) { + rz_cons_printf ("%s\n", srcline); } - r_list_free (uniqlist); - r_list_free (final_list); + rz_list_free (uniqlist); + rz_list_free (final_list); return true; } -static int bin_main(RCore *r, int mode, int va) { - RBinAddr *binmain = r_bin_get_sym (r->bin, R_BIN_SYM_MAIN); +static int bin_main(RzCore *r, int mode, int va) { + RBinAddr *binmain = rz_bin_get_sym (r->bin, R_BIN_SYM_MAIN); ut64 addr; if (!binmain) { return false; } - addr = va ? r_bin_a2b (r->bin, binmain->vaddr) : binmain->paddr; + addr = va ? rz_bin_a2b (r->bin, binmain->vaddr) : binmain->paddr; if (IS_MODE_SET (mode)) { - r_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); - r_flag_set (r->flags, "main", addr, r->blocksize); + rz_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); + rz_flag_set (r->flags, "main", addr, r->blocksize); } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("%"PFMT64d, addr); + rz_cons_printf ("%"PFMT64d, addr); } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs symbols\n"); - r_cons_printf ("f main @ 0x%08"PFMT64x"\n", addr); + rz_cons_printf ("fs symbols\n"); + rz_cons_printf ("f main @ 0x%08"PFMT64x"\n", addr); } else if (IS_MODE_JSON (mode)) { - r_cons_printf ("{\"vaddr\":%" PFMT64d + rz_cons_printf ("{\"vaddr\":%" PFMT64d ",\"paddr\":%" PFMT64d "}", addr, binmain->paddr); } else { - r_cons_printf ("[Main]\n"); - r_cons_printf ("vaddr=0x%08"PFMT64x" paddr=0x%08"PFMT64x"\n", + rz_cons_printf ("[Main]\n"); + rz_cons_printf ("vaddr=0x%08"PFMT64x" paddr=0x%08"PFMT64x"\n", addr, binmain->paddr); } return true; @@ -1355,28 +1355,28 @@ static inline bool is_initfini(RBinAddr *entry) { } } -static int bin_entry(RCore *r, int mode, ut64 laddr, int va, bool inifin) { +static int bin_entry(RzCore *r, int mode, ut64 laddr, int va, bool inifin) { char str[R_FLAG_NAME_SIZE]; - RList *entries = r_bin_get_entries (r->bin); - RListIter *iter; - RListIter *last_processed = NULL; + RzList *entries = rz_bin_get_entries (r->bin); + RzListIter *iter; + RzListIter *last_processed = NULL; RBinAddr *entry = NULL; int i = 0, init_i = 0, fini_i = 0, preinit_i = 0; - ut64 baddr = r_bin_get_baddr (r->bin); + ut64 baddr = rz_bin_get_baddr (r->bin); if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs symbols\n"); + rz_cons_printf ("fs symbols\n"); } else if (IS_MODE_JSON (mode)) { - r_cons_printf ("["); + rz_cons_printf ("["); } else if (IS_MODE_NORMAL (mode)) { if (inifin) { - r_cons_printf ("[Constructors]\n"); + rz_cons_printf ("[Constructors]\n"); } else { - r_cons_printf ("[Entrypoints]\n"); + rz_cons_printf ("[Entrypoints]\n"); } } - r_list_foreach (entries, iter, entry) { + rz_list_foreach (entries, iter, entry) { ut64 paddr = entry->paddr; ut64 hpaddr = UT64_MAX; ut64 hvaddr = UT64_MAX; @@ -1398,14 +1398,14 @@ static int bin_entry(RCore *r, int mode, ut64 laddr, int va, bool inifin) { } } ut64 at = rva (r->bin, paddr, entry->vaddr, va); - const char *type = r_bin_entry_type_string (entry->type); + const char *type = rz_bin_entry_type_string (entry->type); if (!type) { type = "unknown"; } const char *hpaddr_key = (entry->type == R_BIN_ENTRY_TYPE_PROGRAM) ? "haddr" : "hpaddr"; if (IS_MODE_SET (mode)) { - r_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); + rz_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); if (entry->type == R_BIN_ENTRY_TYPE_INIT) { snprintf (str, R_FLAG_NAME_SIZE, "entry.init%i", init_i); } else if (entry->type == R_BIN_ENTRY_TYPE_FINI) { @@ -1415,56 +1415,56 @@ static int bin_entry(RCore *r, int mode, ut64 laddr, int va, bool inifin) { } else { snprintf (str, R_FLAG_NAME_SIZE, "entry%i", i); } - r_flag_set (r->flags, str, at, 1); + rz_flag_set (r->flags, str, at, 1); if (is_initfini (entry) && hvaddr != UT64_MAX) { - r_meta_set (r->anal, R_META_TYPE_DATA, hvaddr, entry->bits / 8, NULL); + rz_meta_set (r->anal, R_META_TYPE_DATA, hvaddr, entry->bits / 8, NULL); } } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("0x%08"PFMT64x"\n", at); + rz_cons_printf ("0x%08"PFMT64x"\n", at); } else if (IS_MODE_JSON (mode)) { - r_cons_printf ("%s{\"vaddr\":%" PFMT64u "," + rz_cons_printf ("%s{\"vaddr\":%" PFMT64u "," "\"paddr\":%" PFMT64u "," "\"baddr\":%" PFMT64u "," "\"laddr\":%" PFMT64u ",", last_processed ? "," : "", at, paddr, baddr, laddr); if (hvaddr != UT64_MAX) { - r_cons_printf ("\"hvaddr\":%" PFMT64u ",", hvaddr); + rz_cons_printf ("\"hvaddr\":%" PFMT64u ",", hvaddr); } - r_cons_printf ("\"%s\":%" PFMT64u "," + rz_cons_printf ("\"%s\":%" PFMT64u "," "\"type\":\"%s\"}", hpaddr_key, hpaddr, type); } else if (IS_MODE_RAD (mode)) { char *name = NULL; if (entry->type == R_BIN_ENTRY_TYPE_INIT) { - name = r_str_newf ("entry.init%i", init_i); + name = rz_str_newf ("entry.init%i", init_i); } else if (entry->type == R_BIN_ENTRY_TYPE_FINI) { - name = r_str_newf ("entry.fini%i", fini_i); + name = rz_str_newf ("entry.fini%i", fini_i); } else if (entry->type == R_BIN_ENTRY_TYPE_PREINIT) { - name = r_str_newf ("entry.preinit%i", preinit_i); + name = rz_str_newf ("entry.preinit%i", preinit_i); } else { - name = r_str_newf ("entry%i", i); + name = rz_str_newf ("entry%i", i); } char *n = __filterQuotedShell (name); - r_cons_printf ("\"f %s 1 0x%08"PFMT64x"\"\n", n, at); - r_cons_printf ("\"f %s_%s 1 0x%08"PFMT64x"\"\n", n, hpaddr_key, hpaddr); - r_cons_printf ("\"s %s\"\n", n); + rz_cons_printf ("\"f %s 1 0x%08"PFMT64x"\"\n", n, at); + rz_cons_printf ("\"f %s_%s 1 0x%08"PFMT64x"\"\n", n, hpaddr_key, hpaddr); + rz_cons_printf ("\"s %s\"\n", n); free (n); free (name); } else { - r_cons_printf ("vaddr=0x%08"PFMT64x" paddr=0x%08"PFMT64x, at, paddr); + rz_cons_printf ("vaddr=0x%08"PFMT64x" paddr=0x%08"PFMT64x, at, paddr); if (is_initfini (entry) && hvaddr != UT64_MAX) { - r_cons_printf (" hvaddr=0x%08"PFMT64x, hvaddr); + rz_cons_printf (" hvaddr=0x%08"PFMT64x, hvaddr); } - r_cons_printf (" %s=", hpaddr_key); + rz_cons_printf (" %s=", hpaddr_key); if (hpaddr == UT64_MAX) { - r_cons_printf ("%"PFMT64d, hpaddr); + rz_cons_printf ("%"PFMT64d, hpaddr); } else { - r_cons_printf ("0x%08"PFMT64x, hpaddr); + rz_cons_printf ("0x%08"PFMT64x, hpaddr); } if (entry->type == R_BIN_ENTRY_TYPE_PROGRAM && hvaddr != UT64_MAX) { - r_cons_printf (" hvaddr=0x%08"PFMT64x, hvaddr); + rz_cons_printf (" hvaddr=0x%08"PFMT64x, hvaddr); } - r_cons_printf (" type=%s\n", type); + rz_cons_printf (" type=%s\n", type); } if (entry->type == R_BIN_ENTRY_TYPE_INIT) { init_i++; @@ -1480,13 +1480,13 @@ static int bin_entry(RCore *r, int mode, ut64 laddr, int va, bool inifin) { if (IS_MODE_SET (mode)) { if (entry) { ut64 at = rva (r->bin, entry->paddr, entry->vaddr, va); - r_core_seek (r, at, false); + rz_core_seek (r, at, false); } } else if (IS_MODE_JSON (mode)) { - r_cons_printf ("]"); - r_cons_newline (); + rz_cons_printf ("]"); + rz_cons_newline (); } else if (IS_MODE_NORMAL (mode)) { - r_cons_printf ("\n%i entrypoints\n", init_i + fini_i + preinit_i + i); + rz_cons_printf ("\n%i entrypoints\n", init_i + fini_i + preinit_i + i); } return true; } @@ -1523,45 +1523,45 @@ static char *resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal) { // name can be optionally used to explicitly set the used base name (for example for demangling), otherwise the import name will be used. static char *construct_reloc_name(R_NONNULL RBinReloc *reloc, R_NULLABLE const char *name) { - RStrBuf *buf = r_strbuf_new (""); + RStrBuf *buf = rz_strbuf_new (""); // (optional) libname_ if (reloc->import && reloc->import->libname) { - r_strbuf_appendf (buf, "%s_", reloc->import->libname); + rz_strbuf_appendf (buf, "%s_", reloc->import->libname); } else if (reloc->symbol && reloc->symbol->libname) { - r_strbuf_appendf (buf, "%s_", reloc->symbol->libname); + rz_strbuf_appendf (buf, "%s_", reloc->symbol->libname); } // actual name if (name) { - r_strbuf_append (buf, name); + rz_strbuf_append (buf, name); } else if (reloc->import && reloc->import->name && *reloc->import->name) { - r_strbuf_append (buf, reloc->import->name); + rz_strbuf_append (buf, reloc->import->name); } else if (reloc->symbol && reloc->symbol->name && *reloc->symbol->name) { - r_strbuf_appendf (buf, "%s", reloc->symbol->name); + rz_strbuf_appendf (buf, "%s", reloc->symbol->name); } else if (reloc->is_ifunc) { // addend is the function pointer for the resolving ifunc - r_strbuf_appendf (buf, "ifunc_%"PFMT64x, reloc->addend); + rz_strbuf_appendf (buf, "ifunc_%"PFMT64x, reloc->addend); } else { // TODO(eddyb) implement constant relocs. - r_strbuf_set (buf, ""); + rz_strbuf_set (buf, ""); } - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } -static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char **sdb_module) { - int bin_demangle = r_config_get_i (r->config, "bin.demangle"); - bool keep_lib = r_config_get_i (r->config, "bin.demangle.libs"); - const char *lang = r_config_get (r->config, "bin.lang"); +static void set_bin_relocs(RzCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char **sdb_module) { + int bin_demangle = rz_config_get_i (r->config, "bin.demangle"); + bool keep_lib = rz_config_get_i (r->config, "bin.demangle.libs"); + const char *lang = rz_config_get (r->config, "bin.lang"); bool is_pe = true; - int is_sandbox = r_sandbox_enable (0); + int is_sandbox = rz_sandbox_enable (0); if (is_pe && !is_sandbox && reloc->import && reloc->import->name && reloc->import->libname - && r_str_startswith (reloc->import->name, "Ordinal_")) { + && rz_str_startswith (reloc->import->name, "Ordinal_")) { char *module = reloc->import->libname; - r_str_case (module, false); + rz_str_case (module, false); // strip trailing ".dll" size_t module_len = strlen (module); @@ -1580,14 +1580,14 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char *sdb_module = strdup (module); /* always lowercase */ filename = sdb_fmt ("%s.sdb", module); - r_str_case (filename, false); - if (r_file_exists (filename)) { + rz_str_case (filename, false); + if (rz_file_exists (filename)) { *db = sdb_new (NULL, filename, 0); } else { - const char *dirPrefix = r_sys_prefix (NULL); + const char *dirPrefix = rz_sys_prefix (NULL); filename = sdb_fmt (R_JOIN_4_PATHS ("%s", R2_SDB_FORMAT, "dll", "%s.sdb"), dirPrefix, module); - if (r_file_exists (filename)) { + if (rz_file_exists (filename)) { *db = sdb_new (NULL, filename, 0); } } @@ -1597,7 +1597,7 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char char *symname = resolveModuleOrdinal (*db, module, ordinal - 1); // uses sdb_get if (symname) { if (r->bin->prefix) { - reloc->import->name = r_str_newf + reloc->import->name = rz_str_newf ("%s.%s", r->bin->prefix, symname); R_FREE (symname); } else { @@ -1606,8 +1606,8 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char } } } - r_anal_hint_set_size (r->anal, reloc->vaddr, 4); - r_meta_set (r->anal, R_META_TYPE_DATA, reloc->vaddr, 4, NULL); + rz_anal_hint_set_size (r->anal, reloc->vaddr, 4); + rz_meta_set (r->anal, R_META_TYPE_DATA, reloc->vaddr, 4, NULL); } char flagname[R_FLAG_NAME_SIZE]; @@ -1624,13 +1624,13 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char free (reloc_name); char *demname = NULL; if (bin_demangle) { - demname = r_bin_demangle (r->bin->cur, lang, flagname, addr, keep_lib); + demname = rz_bin_demangle (r->bin->cur, lang, flagname, addr, keep_lib); if (demname) { snprintf (flagname, R_FLAG_NAME_SIZE, "reloc.%s", demname); } } - r_name_filter (flagname, 0); - RFlagItem *fi = r_flag_set (r->flags, flagname, addr, bin_reloc_size (reloc)); + rz_name_filter (flagname, 0); + RzFlagItem *fi = rz_flag_set (r->flags, flagname, addr, bin_reloc_size (reloc)); if (demname) { char *realname; if (r->bin->prefix) { @@ -1638,13 +1638,13 @@ static void set_bin_relocs(RCore *r, RBinReloc *reloc, ut64 addr, Sdb **db, char } else { realname = sdb_fmt ("reloc.%s", demname); } - r_flag_item_set_realname (fi, realname); + rz_flag_item_set_realname (fi, realname); } free (demname); } /* Define new data at relocation address if it's not in an executable section */ -static void add_metadata(RCore *r, RBinReloc *reloc, ut64 addr, int mode) { +static void add_metadata(RzCore *r, RBinReloc *reloc, ut64 addr, int mode) { RBinFile * binfile = r->bin->cur; RBinObject *binobj = binfile ? binfile->o: NULL; RBinInfo *info = binobj ? binobj->info: NULL; @@ -1654,14 +1654,14 @@ static void add_metadata(RCore *r, RBinReloc *reloc, ut64 addr, int mode) { return; } - RIOMap *map = r_io_map_get (r->io, addr); + RzIOMap *map = rz_io_map_get (r->io, addr); if (!map || map ->perm & R_PERM_X) { return; } if (IS_MODE_SET (mode)) { - r_meta_set (r->anal, R_META_TYPE_DATA, reloc->vaddr, cdsz, NULL); + rz_meta_set (r->anal, R_META_TYPE_DATA, reloc->vaddr, cdsz, NULL); } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("Cd %d @ 0x%08" PFMT64x "\n", cdsz, addr); + rz_cons_printf ("Cd %d @ 0x%08" PFMT64x "\n", cdsz, addr); } } @@ -1690,12 +1690,12 @@ static bool is_file_reloc(RBinReloc *r) { return is_file_symbol (r->symbol); } -static int bin_relocs(RCore *r, int mode, int va) { - bool bin_demangle = r_config_get_i (r->config, "bin.demangle"); - bool keep_lib = r_config_get_i (r->config, "bin.demangle.libs"); - const char *lang = r_config_get (r->config, "bin.lang"); - RTable *table = r_core_table (r); - r_return_val_if_fail (table, false); +static int bin_relocs(RzCore *r, int mode, int va) { + bool bin_demangle = rz_config_get_i (r->config, "bin.demangle"); + bool keep_lib = rz_config_get_i (r->config, "bin.demangle.libs"); + const char *lang = rz_config_get (r->config, "bin.lang"); + RTable *table = rz_core_table (r); + rz_return_val_if_fail (table, false); RBIter iter; RBinReloc *reloc = NULL; Sdb *db = NULL; @@ -1707,16 +1707,16 @@ static int bin_relocs(RCore *r, int mode, int va) { va = VA_TRUE; // XXX relocs always vaddr? //this has been created for reloc object files - RBNode *relocs = r_bin_patch_relocs (r->bin); + RBNode *relocs = rz_bin_patch_relocs (r->bin); if (!relocs) { - relocs = r_bin_get_relocs (r->bin); + relocs = rz_bin_get_relocs (r->bin); } if (IS_MODE_RAD (mode)) { - r_cons_println ("fs relocs"); + rz_cons_println ("fs relocs"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_println ("[Relocations]"); - r_table_set_columnsf (table, "XXss", "vaddr", "paddr", "type", "name"); + rz_cons_println ("[Relocations]"); + rz_table_set_columnsf (table, "XXss", "vaddr", "paddr", "type", "name"); } else if (IS_MODE_JSON (mode)) { // start a new JSON object pj = pj_new (); @@ -1724,10 +1724,10 @@ static int bin_relocs(RCore *r, int mode, int va) { pj_a (pj); } } else if (IS_MODE_SET (mode)) { - r_flag_space_set (r->flags, R_FLAGS_FS_RELOCS); + rz_flag_space_set (r->flags, R_FLAGS_FS_RELOCS); } - r_rbtree_foreach (relocs, iter, reloc, RBinReloc, vrb) { + rz_rbtree_foreach (relocs, iter, reloc, RBinReloc, vrb) { ut64 addr = rva (r->bin, reloc->paddr, reloc->vaddr, va); if (IS_MODE_SET (mode) && (is_section_reloc (reloc) || is_file_reloc (reloc))) { /* @@ -1738,13 +1738,13 @@ static int bin_relocs(RCore *r, int mode, int va) { set_bin_relocs (r, reloc, addr, &db, &sdb_module); add_metadata (r, reloc, addr, mode); } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("0x%08"PFMT64x" %s\n", addr, reloc->import ? reloc->import->name : ""); + rz_cons_printf ("0x%08"PFMT64x" %s\n", addr, reloc->import ? reloc->import->name : ""); } else if (IS_MODE_RAD (mode)) { char *name = reloc->import ? strdup (reloc->import->name) : (reloc->symbol ? strdup (reloc->symbol->name) : NULL); if (name && bin_demangle) { - char *mn = r_bin_demangle (r->bin->cur, NULL, name, addr, keep_lib); + char *mn = rz_bin_demangle (r->bin->cur, NULL, name, addr, keep_lib); if (mn) { free (name); name = mn; @@ -1753,7 +1753,7 @@ static int bin_relocs(RCore *r, int mode, int va) { if (name) { int reloc_size = 4; char *n = __filterQuotedShell (name); - r_cons_printf ("\"f %s%s%s %d 0x%08"PFMT64x"\"\n", + rz_cons_printf ("\"f %s%s%s %d 0x%08"PFMT64x"\"\n", r->bin->prefix ? r->bin->prefix : "reloc.", r->bin->prefix ? "." : "", n, reloc_size, addr); add_metadata (r, reloc, addr, mode); @@ -1768,10 +1768,10 @@ static int bin_relocs(RCore *r, int mode, int va) { // take care with very long symbol names! do not use sdb_fmt or similar if (reloc->import) { - mn = r_bin_demangle (r->bin->cur, lang, reloc->import->name, addr, keep_lib); + mn = rz_bin_demangle (r->bin->cur, lang, reloc->import->name, addr, keep_lib); relname = strdup (reloc->import->name); } else if (reloc->symbol) { - mn = r_bin_demangle (r->bin->cur, lang, reloc->symbol->name, addr, keep_lib); + mn = rz_bin_demangle (r->bin->cur, lang, reloc->symbol->name, addr, keep_lib); relname = strdup (reloc->symbol->name); } @@ -1802,31 +1802,31 @@ static int bin_relocs(RCore *r, int mode, int va) { ? strdup (reloc->symbol->name) : NULL; if (bin_demangle) { - char *mn = r_bin_demangle (r->bin->cur, NULL, name, addr, keep_lib); + char *mn = rz_bin_demangle (r->bin->cur, NULL, name, addr, keep_lib); if (mn && *mn) { free (name); name = mn; } } char *reloc_name = construct_reloc_name (reloc, name); - RStrBuf *buf = r_strbuf_new (reloc_name ? reloc_name : ""); + RStrBuf *buf = rz_strbuf_new (reloc_name ? reloc_name : ""); free (reloc_name); R_FREE (name); if (reloc->addend) { - if ((reloc->import || reloc->symbol) && !r_strbuf_is_empty (buf) && reloc->addend > 0) { - r_strbuf_append (buf," +"); + if ((reloc->import || reloc->symbol) && !rz_strbuf_is_empty (buf) && reloc->addend > 0) { + rz_strbuf_append (buf," +"); } if (reloc->addend < 0) { - r_strbuf_appendf (buf," - 0x%08"PFMT64x, -reloc->addend); + rz_strbuf_appendf (buf," - 0x%08"PFMT64x, -reloc->addend); } else { - r_strbuf_appendf (buf," 0x%08"PFMT64x, reloc->addend); + rz_strbuf_appendf (buf," 0x%08"PFMT64x, reloc->addend); } } if (reloc->is_ifunc) { - r_strbuf_append (buf, " (ifunc)"); + rz_strbuf_append (buf, " (ifunc)"); } - char *res = r_strbuf_drain (buf); - r_table_add_rowf (table, "XXss", addr, reloc->paddr, + char *res = rz_strbuf_drain (buf); + rz_table_add_rowf (table, "XXss", addr, reloc->paddr, bin_reloc_type_name (reloc), res); free (res); } @@ -1835,16 +1835,16 @@ static int bin_relocs(RCore *r, int mode, int va) { if (IS_MODE_JSON (mode)) { // close Json output pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } if (IS_MODE_NORMAL (mode)) { if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } - char *s = r_table_tostring (table); - r_cons_printf ("\n%s\n", s); + char *s = rz_table_tostring (table); + rz_cons_printf ("\n%s\n", s); free (s); - r_cons_printf ("\n%i relocations\n", i); + rz_cons_printf ("\n%i relocations\n", i); } @@ -1852,7 +1852,7 @@ static int bin_relocs(RCore *r, int mode, int va) { if (pj) { pj_free (pj); } - r_table_free (table); + rz_table_free (table); R_FREE (sdb_module); sdb_free (db); db = NULL; @@ -1868,11 +1868,11 @@ static int bin_relocs(RCore *r, int mode, int va) { /* this is a VERY VERY VERY hacky and bad workaround that needs proper refactoring in Rbin to use Sdb */ #if MYDB R_DEPRECATE static Sdb *mydb = NULL; -R_DEPRECATE static RList *osymbols = NULL; +R_DEPRECATE static RzList *osymbols = NULL; -R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RList *symbols, const char *name, ut64 addr) { +R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RzList *symbols, const char *name, ut64 addr) { RBinSymbol *symbol, *res = NULL; - RListIter *iter; + RzListIter *iter; if (mydb && symbols && symbols != osymbols) { sdb_free (mydb); mydb = NULL; @@ -1888,7 +1888,7 @@ R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RList *symbols, const char } } else { mydb = sdb_new0 (); - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (!symbol->name || !symbol->is_imported) { continue; } @@ -1915,12 +1915,12 @@ R_DEPRECATE static RBinSymbol *get_import(RBin *bin, RList *symbols, const char return res; } #else -static RList *osymbols = NULL; -static RBinSymbol *get_symbol(RBin *bin, RList *symbols, const char *name, ut64 addr) { +static RzList *osymbols = NULL; +static RBinSymbol *get_symbol(RBin *bin, RzList *symbols, const char *name, ut64 addr) { RBinSymbol *symbol; - RListIter *iter; + RzListIter *iter; // XXX this is slow, we should use a hashtable here - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (name) { if (!strcmp (symbol->name, name)) return symbol; @@ -1934,14 +1934,14 @@ static RBinSymbol *get_symbol(RBin *bin, RList *symbols, const char *name, ut64 } #endif -/* XXX: This is a hack to get PLT references in rabin2 -i */ -R_API ut64 r_core_bin_impaddr(RBin *bin, int va, const char *name) { - RList *symbols; +/* XXX: This is a hack to get PLT references in rz_bin -i */ +RZ_API ut64 rz_core_bin_impaddr(RBin *bin, int va, const char *name) { + RzList *symbols; if (!name || !*name) { return false; } - if (!(symbols = r_bin_get_symbols (bin))) { + if (!(symbols = rz_bin_get_symbols (bin))) { return false; } RBinSymbol *s = get_import (bin, symbols, name, 0LL); @@ -1952,7 +1952,7 @@ R_API ut64 r_core_bin_impaddr(RBin *bin, int va, const char *name) { if (s->paddr == UT64_MAX) { addr = s->vaddr; } else { - addr = r_bin_get_vaddr (bin, s->paddr, s->vaddr); + addr = rz_bin_get_vaddr (bin, s->paddr, s->vaddr); } } else { addr = s->paddr; @@ -1961,14 +1961,14 @@ R_API ut64 r_core_bin_impaddr(RBin *bin, int va, const char *name) { return addr; } -static int bin_imports(RCore *r, int mode, int va, const char *name) { - RBinInfo *info = r_bin_get_info (r->bin); - int bin_demangle = r_config_get_i (r->config, "bin.demangle"); - bool keep_lib = r_config_get_i (r->config, "bin.demangle.libs"); - RTable *table = r_core_table (r); - r_return_val_if_fail (table, false); +static int bin_imports(RzCore *r, int mode, int va, const char *name) { + RBinInfo *info = rz_bin_get_info (r->bin); + int bin_demangle = rz_config_get_i (r->config, "bin.demangle"); + bool keep_lib = rz_config_get_i (r->config, "bin.demangle.libs"); + RTable *table = rz_core_table (r); + rz_return_val_if_fail (table, false); RBinImport *import; - RListIter *iter; + RzListIter *iter; bool lit = info ? info->has_lit: false; char *str; int i = 0; @@ -1976,39 +1976,39 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) { if (!info) { if (IS_MODE_JSON (mode)) { - r_cons_printf ("[]"); + rz_cons_printf ("[]"); } return false; } - RList *imports = r_bin_get_imports (r->bin); + RzList *imports = rz_bin_get_imports (r->bin); int cdsz = info? (info->bits == 64? 8: info->bits == 32? 4: info->bits == 16 ? 4: 0): 0; if (IS_MODE_JSON (mode)) { pj = pj_new (); pj_a (pj); } else if (IS_MODE_RAD (mode)) { - r_cons_println ("fs imports"); + rz_cons_println ("fs imports"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_println ("[Imports]"); - r_table_set_columnsf (table, "nXssss", "nth", "vaddr", "bind", "type", "lib", "name"); + rz_cons_println ("[Imports]"); + rz_table_set_columnsf (table, "nXssss", "nth", "vaddr", "bind", "type", "lib", "name"); } - r_list_foreach (imports, iter, import) { + rz_list_foreach (imports, iter, import) { if (name && strcmp (import->name, name)) { continue; } char *symname = strdup (import->name); char *libname = import->libname ? strdup (import->libname) : NULL; - ut64 addr = lit ? r_core_bin_impaddr (r->bin, va, symname): 0; + ut64 addr = lit ? rz_core_bin_impaddr (r->bin, va, symname): 0; if (bin_demangle) { - char *dname = r_bin_demangle (r->bin->cur, NULL, symname, addr, keep_lib); + char *dname = rz_bin_demangle (r->bin->cur, NULL, symname, addr, keep_lib); if (dname) { free (symname); - symname = r_str_newf ("sym.imp.%s", dname); + symname = rz_str_newf ("sym.imp.%s", dname); free (dname); } } if (r->bin->prefix) { - char *prname = r_str_newf ("%s.%s", r->bin->prefix, symname); + char *prname = rz_str_newf ("%s.%s", r->bin->prefix, symname); free (symname); symname = prname; } @@ -2016,19 +2016,19 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) { // TODO(eddyb) symbols that are imports. // Add a dword/qword for PE imports if (libname && strstr (libname, ".dll") && cdsz) { - r_meta_set (r->anal, R_META_TYPE_DATA, addr, cdsz, NULL); + rz_meta_set (r->anal, R_META_TYPE_DATA, addr, cdsz, NULL); } } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("%s%s%s\n", + rz_cons_printf ("%s%s%s\n", libname ? libname : "", libname ? " " : "", symname); } else if (IS_MODE_SIMPLEST (mode)) { - r_cons_println (symname); + rz_cons_println (symname); } else if (IS_MODE_JSON (mode)) { pj_o (pj); - str = r_str_escape_utf8_for_json (symname, -1); - str = r_str_replace (str, "\"", "\\\"", 1); + str = rz_str_escape_utf8_for_json (symname, -1); + str = rz_str_replace (str, "\"", "\\\"", 1); pj_ki (pj, "ordinal", import->ordinal); if (import->bind) { @@ -2054,17 +2054,17 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) { const char *bind = import->bind? import->bind: "NONE"; const char *type = import->type? import->type: "NONE"; if (import->classname && import->classname[0]) { - r_table_add_rowf (table, "nXssss", (ut64)import->ordinal, addr, bind, type, libname ? libname : "", sdb_fmt ("%s.%s", import->classname, symname)); + rz_table_add_rowf (table, "nXssss", (ut64)import->ordinal, addr, bind, type, libname ? libname : "", sdb_fmt ("%s.%s", import->classname, symname)); } else { - r_table_add_rowf (table, "nXssss", (ut64)import->ordinal, addr, bind, type, libname ? libname : "", symname); + rz_table_add_rowf (table, "nXssss", (ut64)import->ordinal, addr, bind, type, libname ? libname : "", symname); } if (import->descriptor && import->descriptor[0]) { // Uh? - r_cons_printf (" descriptor=%s", import->descriptor); + rz_cons_printf (" descriptor=%s", import->descriptor); } if (!IS_MODE_NORMAL (mode)) { - r_cons_newline (); + rz_cons_newline (); } } R_FREE (symname); @@ -2076,20 +2076,20 @@ static int bin_imports(RCore *r, int mode, int va, const char *name) { pj_end (pj); } else if (IS_MODE_NORMAL (mode)) { if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } - char *s = r_table_tostring (table); - r_cons_printf ("%s\n", s); + char *s = rz_table_tostring (table); + rz_cons_printf ("%s\n", s); free (s); } if (pj) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } - r_table_free (table); + rz_table_free (table); #if MYDB // NOTE: if we comment out this, it will leak.. but it will be faster // because it will keep the cache across multiple RBin calls @@ -2119,9 +2119,9 @@ static const char *getPrefixFor(RBinSymbol *sym) { #define MAXFLAG_LEN_DEFAULT 128 static char *construct_symbol_flagname(const char *pfx, const char *libname, const char *symname, int len) { - char *r = r_str_newf ("%s.%s%s%s", pfx, libname ? libname : "", libname ? "_" : "", symname); + char *r = rz_str_newf ("%s.%s%s%s", pfx, libname ? libname : "", libname ? "_" : "", symname); if (r) { - r_name_filter (r, len); // maybe unnecessary.. + rz_name_filter (r, len); // maybe unnecessary.. char *R = __filterQuotedShell (r); free (r); return R; @@ -2142,24 +2142,24 @@ typedef struct { char *methflag; // methods flag sym.[class].[method] } SymName; -static void snInit(RCore *r, SymName *sn, RBinSymbol *sym, const char *lang) { +static void snInit(RzCore *r, SymName *sn, RBinSymbol *sym, const char *lang) { int bin_demangle = lang != NULL; - bool keep_lib = r_config_get_i (r->config, "bin.demangle.libs"); + bool keep_lib = rz_config_get_i (r->config, "bin.demangle.libs"); if (!r || !sym || !sym->name) { return; } - sn->name = r_str_newf ("%s%s", sym->is_imported ? "imp." : "", sym->name); + sn->name = rz_str_newf ("%s%s", sym->is_imported ? "imp." : "", sym->name); sn->libname = sym->libname ? strdup (sym->libname) : NULL; const char *pfx = getPrefixFor (sym); - sn->nameflag = construct_symbol_flagname (pfx, sym->libname, r_bin_symbol_name (sym), MAXFLAG_LEN_DEFAULT); + sn->nameflag = construct_symbol_flagname (pfx, sym->libname, rz_bin_symbol_name (sym), MAXFLAG_LEN_DEFAULT); if (sym->classname && sym->classname[0]) { sn->classname = strdup (sym->classname); - sn->classflag = r_str_newf ("sym.%s.%s", sn->classname, sn->name); - r_name_filter (sn->classflag, MAXFLAG_LEN_DEFAULT); + sn->classflag = rz_str_newf ("sym.%s.%s", sn->classname, sn->name); + rz_name_filter (sn->classflag, MAXFLAG_LEN_DEFAULT); const char *name = sym->dname? sym->dname: sym->name; - sn->methname = r_str_newf ("%s::%s", sn->classname, name); - sn->methflag = r_str_newf ("sym.%s.%s", sn->classname, name); - r_name_filter (sn->methflag, strlen (sn->methflag)); + sn->methname = rz_str_newf ("%s::%s", sn->classname, name); + sn->methflag = rz_str_newf ("sym.%s.%s", sn->classname, name); + rz_name_filter (sn->methflag, strlen (sn->methflag)); } else { sn->classname = NULL; sn->classflag = NULL; @@ -2169,7 +2169,7 @@ static void snInit(RCore *r, SymName *sn, RBinSymbol *sym, const char *lang) { sn->demname = NULL; sn->demflag = NULL; if (bin_demangle && sym->paddr) { - sn->demname = r_bin_demangle (r->bin->cur, lang, sn->name, sym->vaddr, keep_lib); + sn->demname = rz_bin_demangle (r->bin->cur, lang, sn->name, sym->vaddr, keep_lib); if (sn->demname) { sn->demflag = construct_symbol_flagname (pfx, sym->libname, sn->demname, -1); } @@ -2200,14 +2200,14 @@ static ut64 compute_addr(RBin *bin, ut64 paddr, ut64 vaddr, int va) { return paddr == UT64_MAX? vaddr: rva (bin, paddr, vaddr, va); } -static void handle_arm_special_symbol(RCore *core, RBinSymbol *symbol, int va) { +static void handle_arm_special_symbol(RzCore *core, RBinSymbol *symbol, int va) { ut64 addr = compute_addr (core->bin, symbol->paddr, symbol->vaddr, va); if (!strcmp (symbol->name, "$a")) { - r_anal_hint_set_bits (core->anal, addr, 32); + rz_anal_hint_set_bits (core->anal, addr, 32); } else if (!strcmp (symbol->name, "$x")) { - r_anal_hint_set_bits (core->anal, addr, 64); + rz_anal_hint_set_bits (core->anal, addr, 64); } else if (!strcmp (symbol->name, "$t")) { - r_anal_hint_set_bits (core->anal, addr, 16); + rz_anal_hint_set_bits (core->anal, addr, 16); } else if (!strcmp (symbol->name, "$d")) { // TODO: we could add data meta type at addr, but sometimes $d // is in the middle of the code and it would make the code less @@ -2219,7 +2219,7 @@ static void handle_arm_special_symbol(RCore *core, RBinSymbol *symbol, int va) { } } -static void handle_arm_hint(RCore *core, RBinInfo *info, ut64 paddr, ut64 vaddr, int bits, int va) { +static void handle_arm_hint(RzCore *core, RBinInfo *info, ut64 paddr, ut64 vaddr, int bits, int va) { if (info->bits > 32) { // we look at 16 or 32 bit only return; } @@ -2234,78 +2234,78 @@ static void handle_arm_hint(RCore *core, RBinInfo *info, ut64 paddr, ut64 vaddr, force_bits = 32; } if (force_bits) { - r_anal_hint_set_bits (core->anal, addr, force_bits); + rz_anal_hint_set_bits (core->anal, addr, force_bits); } } -static void handle_arm_symbol(RCore *core, RBinSymbol *symbol, RBinInfo *info, int va) { +static void handle_arm_symbol(RzCore *core, RBinSymbol *symbol, RBinInfo *info, int va) { return handle_arm_hint (core, info, symbol->paddr, symbol->vaddr, symbol->bits, va); } -static void handle_arm_entry(RCore *core, RBinAddr *entry, RBinInfo *info, int va) { +static void handle_arm_entry(RzCore *core, RBinAddr *entry, RBinInfo *info, int va) { return handle_arm_hint (core, info, entry->paddr, entry->vaddr, entry->bits, va); } -static void select_flag_space(RCore *core, RBinSymbol *symbol) { +static void select_flag_space(RzCore *core, RBinSymbol *symbol) { if (symbol->is_imported) { - r_flag_space_push (core->flags, R_FLAGS_FS_IMPORTS); + rz_flag_space_push (core->flags, R_FLAGS_FS_IMPORTS); } else if (symbol->type && !strcmp (symbol->type, R_BIN_TYPE_SECTION_STR)) { - r_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS_SECTIONS); + rz_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS_SECTIONS); } else { - r_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS); + rz_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS); } } -static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const char *name, bool exponly, const char *args) { - RBinInfo *info = r_bin_get_info (r->bin); - RList *entries = r_bin_get_entries (r->bin); +static int bin_symbols(RzCore *r, int mode, ut64 laddr, int va, ut64 at, const char *name, bool exponly, const char *args) { + RBinInfo *info = rz_bin_get_info (r->bin); + RzList *entries = rz_bin_get_entries (r->bin); RBinSymbol *symbol; RBinAddr *entry; - RListIter *iter; + RzListIter *iter; bool firstexp = true; bool printHere = (args && *args == '.'); int i = 0, lastfs = 's'; - RTable *table = r_core_table (r); - bool bin_demangle = r_config_get_i (r->config, "bin.demangle"); + RTable *table = rz_core_table (r); + bool bin_demangle = rz_config_get_i (r->config, "bin.demangle"); if (!info) { if (IS_MODE_JSON (mode)) { - r_cons_printf (printHere? "{}": "[]\n"); + rz_cons_printf (printHere? "{}": "[]\n"); } - r_table_free (table); + rz_table_free (table); return 0; } PJ *pj = pj_new (); bool is_arm = info && info->arch && !strncmp (info->arch, "arm", 3); - const char *lang = bin_demangle ? r_config_get (r->config, "bin.lang") : NULL; + const char *lang = bin_demangle ? rz_config_get (r->config, "bin.lang") : NULL; - RList *symbols = r_bin_get_symbols (r->bin); - r_spaces_push (&r->anal->meta_spaces, "bin"); + RzList *symbols = rz_bin_get_symbols (r->bin); + rz_spaces_push (&r->anal->meta_spaces, "bin"); if (IS_MODE_JSON (mode) && !printHere) { pj_a (pj); } else if (IS_MODE_SET (mode)) { - r_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); + rz_flag_space_set (r->flags, R_FLAGS_FS_SYMBOLS); } else if (at == UT64_MAX && exponly) { if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs exports\n"); + rz_cons_printf ("fs exports\n"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_printf (printHere ? "" : "[Exports]\n"); + rz_cons_printf (printHere ? "" : "[Exports]\n"); } } else if (at == UT64_MAX && !exponly) { if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs symbols\n"); + rz_cons_printf ("fs symbols\n"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_printf (printHere ? "" : "[Symbols]\n"); + rz_cons_printf (printHere ? "" : "[Symbols]\n"); } } if (IS_MODE_NORMAL (mode)) { - r_table_set_columnsf (table, "dssssdss", "nth", "paddr","vaddr","bind", "type", "size", "lib", "name"); + rz_table_set_columnsf (table, "dssssdss", "nth", "paddr","vaddr","bind", "type", "size", "lib", "name"); } size_t count = 0; - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (!symbol->name) { continue; } @@ -2327,7 +2327,7 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch SymName sn = {0}; count ++; snInit (r, &sn, symbol, lang); - char *r_symbol_name = r_str_escape_utf8 (sn.name, false, true); + char *rz_symbol_name = rz_str_escape_utf8 (sn.name, false, true); if (IS_MODE_SET (mode) && (is_section_symbol (symbol) || is_file_symbol (symbol))) { /* @@ -2346,24 +2346,24 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch select_flag_space (r, symbol); /* If that's a Classed symbol (method or so) */ if (sn.classname) { - RFlagItem *fi = r_flag_get (r->flags, sn.methflag); + RzFlagItem *fi = rz_flag_get (r->flags, sn.methflag); if (r->bin->prefix) { - char *prname = r_str_newf ("%s.%s", r->bin->prefix, sn.methflag); - r_name_filter (sn.methflag, -1); + char *prname = rz_str_newf ("%s.%s", r->bin->prefix, sn.methflag); + rz_name_filter (sn.methflag, -1); free (sn.methflag); sn.methflag = prname; } if (fi) { - r_flag_item_set_realname (fi, sn.methname); + rz_flag_item_set_realname (fi, sn.methname); if ((fi->offset - r->flags->base) == addr) { // char *comment = fi->comment ? strdup (fi->comment) : NULL; - r_flag_unset (r->flags, fi); + rz_flag_unset (r->flags, fi); } } else { - fi = r_flag_set (r->flags, sn.methflag, addr, symbol->size); + fi = rz_flag_set (r->flags, sn.methflag, addr, symbol->size); char *comment = fi->comment ? strdup (fi->comment) : NULL; if (comment) { - r_flag_item_set_comment (fi, comment); + rz_flag_item_set_comment (fi, comment); R_FREE (comment); } } @@ -2371,11 +2371,11 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch const char *n = sn.demname ? sn.demname : symbol->name; const char *fn = sn.demflag ? sn.demflag : sn.nameflag; char *fnp = (r->bin->prefix) ? - r_str_newf ("%s.%s", r->bin->prefix, fn): + rz_str_newf ("%s.%s", r->bin->prefix, fn): strdup (fn? fn: ""); - RFlagItem *fi = r_flag_set (r->flags, fnp, addr, symbol->size); + RzFlagItem *fi = rz_flag_set (r->flags, fnp, addr, symbol->size); if (fi) { - r_flag_item_set_realname (fi, n); + rz_flag_item_set_realname (fi, n); fi->demangled = (bool)(size_t)sn.demname; } else { if (fn) { @@ -2386,12 +2386,12 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch } if (sn.demname) { ut64 size = symbol->size? symbol->size: 1; - r_meta_set (r->anal, R_META_TYPE_COMMENT, + rz_meta_set (r->anal, R_META_TYPE_COMMENT, addr, size, sn.demname); } - r_flag_space_pop (r->flags); + rz_flag_space_pop (r->flags); } else if (IS_MODE_JSON (mode)) { - char *str = r_str_escape_utf8_for_json (r_symbol_name, -1); + char *str = rz_str_escape_utf8_for_json (rz_symbol_name, -1); pj_o (pj); pj_ks (pj, "name", str); if (sn.demname) { @@ -2409,14 +2409,14 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch pj_end (pj); free (str); } else if (IS_MODE_SIMPLE (mode)) { - const char *name = sn.demname? sn.demname: r_symbol_name; - r_cons_printf ("0x%08"PFMT64x" %d %s%s%s\n", + const char *name = sn.demname? sn.demname: rz_symbol_name; + rz_cons_printf ("0x%08"PFMT64x" %d %s%s%s\n", addr, (int)symbol->size, sn.libname ? sn.libname : "", sn.libname ? " " : "", name); } else if (IS_MODE_SIMPLEST (mode)) { - const char *name = sn.demname? sn.demname: r_symbol_name; - r_cons_printf ("%s\n", name); + const char *name = sn.demname? sn.demname: rz_symbol_name; + rz_cons_printf ("%s\n", name); } else if (IS_MODE_RAD (mode)) { /* Skip special symbols because we do not flag them and * they shouldn't be printed in the rad format either */ @@ -2425,19 +2425,19 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch } RBinFile *binfile; RBinPlugin *plugin; - const char *name = sn.demname? sn.demname: r_symbol_name; + const char *name = sn.demname? sn.demname: rz_symbol_name; if (!name) { goto next; } if (symbol->is_imported) { if (lastfs != 'i') { - r_cons_printf ("fs imports\n"); + rz_cons_printf ("fs imports\n"); } lastfs = 'i'; } else { if (lastfs != 's') { const char *fs = exponly? "exports": "symbols"; - r_cons_printf ("fs %s\n", fs); + rz_cons_printf ("fs %s\n", fs); } lastfs = 's'; } @@ -2446,26 +2446,26 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch if (!flagname) { goto next; } - r_cons_printf ("\"f %s%s%s %u 0x%08" PFMT64x "\"\n", + rz_cons_printf ("\"f %s%s%s %u 0x%08" PFMT64x "\"\n", r->bin->prefix ? r->bin->prefix : "", r->bin->prefix ? "." : "", flagname, symbol->size, addr); free (flagname); } - binfile = r_bin_cur (r->bin); - plugin = r_bin_file_cur_plugin (binfile); + binfile = rz_bin_cur (r->bin); + plugin = rz_bin_file_cur_plugin (binfile); if (plugin && plugin->name) { - if (r_str_startswith (plugin->name, "pe")) { - char *module = strdup (r_symbol_name); + if (rz_str_startswith (plugin->name, "pe")) { + char *module = strdup (rz_symbol_name); char *p = strstr (module, ".dll_"); if (p && symbol->is_imported) { char *symname = __filterShell (p + 5); char *m = __filterShell (module); *p = 0; if (r->bin->prefix) { - r_cons_printf ("\"k bin/pe/%s/%d=%s.%s\"\n", + rz_cons_printf ("\"k bin/pe/%s/%d=%s.%s\"\n", module, symbol->ordinal, r->bin->prefix, symname); } else { - r_cons_printf ("\"k bin/pe/%s/%d=%s\"\n", + rz_cons_printf ("\"k bin/pe/%s/%d=%s\"\n", module, symbol->ordinal, symname); } free (symname); @@ -2477,9 +2477,9 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch } else { const char *bind = symbol->bind? symbol->bind: "NONE"; const char *type = symbol->type? symbol->type: "NONE"; - const char *name = r_str_get (sn.demname? sn.demname: sn.name); - // const char *fwd = r_str_get (symbol->forwarder); - r_table_add_rowf (table, "dssssdss", + const char *name = rz_str_get (sn.demname? sn.demname: sn.name); + // const char *fwd = rz_str_get (symbol->forwarder); + rz_table_add_rowf (table, "dssssdss", symbol->ordinal, symbol->paddr == UT64_MAX ? " ----------": sdb_fmt (" 0x%08"PFMT64x, symbol->paddr), sdb_fmt("0x%08"PFMT64x, addr), @@ -2492,7 +2492,7 @@ static int bin_symbols(RCore *r, int mode, ut64 laddr, int va, ut64 at, const ch next: snFini (&sn); i++; - free (r_symbol_name); + free (rz_symbol_name); if (exponly && firstexp) { firstexp = false; } @@ -2502,16 +2502,16 @@ next: } if (IS_MODE_NORMAL (mode)){ if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } - char *s = r_table_tostring (table); - r_cons_printf ("\n%s", s); + char *s = rz_table_tostring (table); + rz_cons_printf ("\n%s", s); free (s); } //handle thumb and arm for entry point since they are not present in symbols if (is_arm) { - r_list_foreach (entries, iter, entry) { + rz_list_foreach (entries, iter, entry) { if (IS_MODE_SET (mode)) { handle_arm_entry (r, entry, info, va); } @@ -2522,37 +2522,37 @@ next: pj_end (pj); } const char *js = pj_string (pj); - r_cons_printf ("%s\n", (js && *js)? js: "{}"); + rz_cons_printf ("%s\n", (js && *js)? js: "{}"); } pj_free (pj); - r_spaces_pop (&r->anal->meta_spaces); - r_table_free (table); + rz_spaces_pop (&r->anal->meta_spaces); + rz_table_free (table); return true; } static char *build_hash_string(int mode, const char *chksum, ut8 *data, ut32 datalen) { char *chkstr = NULL, *aux, *ret = NULL; - RList *hashlist = r_str_split_duplist (chksum, ",", true); - RListIter *iter; + RzList *hashlist = rz_str_split_duplist (chksum, ",", true); + RzListIter *iter; char *hashname; - r_list_foreach (hashlist, iter, hashname) { - chkstr = r_hash_to_string (NULL, hashname, data, datalen); + rz_list_foreach (hashlist, iter, hashname) { + chkstr = rz_hash_to_string (NULL, hashname, data, datalen); if (!chkstr) { continue; } if (IS_MODE_SIMPLE (mode) || IS_MODE_NORMAL (mode)) { - aux = r_str_newf (iter->n? "%s " : "%s", chkstr); + aux = rz_str_newf (iter->n? "%s " : "%s", chkstr); } else if (IS_MODE_JSON (mode)) { - aux = r_str_newf ("\"%s\":\"%s\",", hashname, chkstr); + aux = rz_str_newf ("\"%s\":\"%s\",", hashname, chkstr); } else { - aux = r_str_newf ("%s=%s ", hashname, chkstr); + aux = rz_str_newf ("%s=%s ", hashname, chkstr); } - ret = r_str_append (ret, aux); + ret = rz_str_append (ret, aux); free (chkstr); free (aux); } - r_list_free (hashlist); + rz_list_free (hashlist); return ret; } @@ -2563,32 +2563,32 @@ static char *filter_hash_string(const char *chksum) { char *aux, *ret = NULL; bool isFirst = true; - RList *hashlist = r_str_split_duplist (chksum, ",", true); - RListIter *iter; + RzList *hashlist = rz_str_split_duplist (chksum, ",", true); + RzListIter *iter; char *hashname; - r_list_foreach (hashlist, iter, hashname) { - if (r_hash_name_to_bits (hashname)) { - aux = r_str_newf (isFirst? "%s" : ", %s", hashname); - ret = r_str_append (ret, aux); + rz_list_foreach (hashlist, iter, hashname) { + if (rz_hash_name_to_bits (hashname)) { + aux = rz_str_newf (isFirst? "%s" : ", %s", hashname); + ret = rz_str_append (ret, aux); free (aux); if (isFirst) { isFirst = false; } } } - r_list_free (hashlist); + rz_list_free (hashlist); return ret; } typedef struct { const char *uri; int perm; - RIODesc *desc; + RzIODesc *desc; } FindFile; static bool findFile(void *user, void *data, ut32 id) { FindFile *res = (FindFile*)user; - RIODesc *desc = (RIODesc*)data; + RzIODesc *desc = (RzIODesc*)data; if (desc->perm && res->perm && !strcmp (desc->uri, res->uri)) { res->desc = desc; return false; @@ -2596,54 +2596,54 @@ static bool findFile(void *user, void *data, ut32 id) { return true; } -static RIODesc *findReusableFile(RIO *io, const char *uri, int perm) { +static RzIODesc *findReusableFile(RzIO *io, const char *uri, int perm) { FindFile arg = { .uri = uri, .perm = perm, .desc = NULL, }; - r_id_storage_foreach (io->files, findFile, &arg); + rz_id_storage_foreach (io->files, findFile, &arg); return arg.desc; } -static bool io_create_mem_map(RIO *io, RBinSection *sec, ut64 at) { - r_return_val_if_fail (io && sec, false); +static bool io_create_mem_map(RzIO *io, RBinSection *sec, ut64 at) { + rz_return_val_if_fail (io && sec, false); bool reused = false; ut64 gap = sec->vsize - sec->size; - char *uri = r_str_newf ("null://%"PFMT64u, gap); - RIODesc *desc = findReusableFile (io, uri, sec->perm); + char *uri = rz_str_newf ("null://%"PFMT64u, gap); + RzIODesc *desc = findReusableFile (io, uri, sec->perm); if (desc) { - RIOMap *map = r_io_map_get (io, at); + RzIOMap *map = rz_io_map_get (io, at); if (!map) { - r_io_map_add_batch (io, desc->fd, desc->perm, 0LL, at, gap); + rz_io_map_add_batch (io, desc->fd, desc->perm, 0LL, at, gap); } reused = true; } if (!desc) { - desc = r_io_open_at (io, uri, sec->perm, 0664, at); + desc = rz_io_open_at (io, uri, sec->perm, 0664, at); } free (uri); if (!desc) { return false; } // this works, because new maps are always born on the top - RIOMap *map = r_io_map_get (io, at); + RzIOMap *map = rz_io_map_get (io, at); // check if the mapping failed if (!map) { if (!reused) { - r_io_desc_close (desc); + rz_io_desc_close (desc); } return false; } // let the section refere to the map as a memory-map free (map->name); - map->name = r_str_newf ("mmap.%s", sec->name); + map->name = rz_str_newf ("mmap.%s", sec->name); return true; } -static void add_section(RCore *core, RBinSection *sec, ut64 addr, int fd) { - if (!r_io_desc_get (core->io, fd) || UT64_ADD_OVFCHK (sec->size, sec->paddr) || +static void add_section(RzCore *core, RBinSection *sec, ut64 addr, int fd) { + if (!rz_io_desc_get (core->io, fd) || UT64_ADD_OVFCHK (sec->size, sec->paddr) || UT64_ADD_OVFCHK (sec->size, addr) || !sec->vsize) { return; } @@ -2660,7 +2660,7 @@ static void add_section(RCore *core, RBinSection *sec, ut64 addr, int fd) { } // then we map the part of the section that comes from the physical file - char *map_name = r_str_newf ("fmap.%s", sec->name); + char *map_name = rz_str_newf ("fmap.%s", sec->name); if (!map_name) { return; } @@ -2671,7 +2671,7 @@ static void add_section(RCore *core, RBinSection *sec, ut64 addr, int fd) { perm |= R_PERM_X; } - RIOMap *map = r_io_map_add_batch (core->io, fd, perm, sec->paddr, addr, size); + RzIOMap *map = rz_io_map_add_batch (core->io, fd, perm, sec->paddr, addr, size); if (!map) { free (map_name); return; @@ -2686,80 +2686,80 @@ struct io_bin_section_info_t { int fd; }; -/* Map Sections to Segments https://github.com/radareorg/radare2/issues/14647 */ +/* Map Sections to Segments https://github.com/rizinorg/rizin/issues/14647 */ static int bin_map_sections_to_segments (RBin *bin, int mode) { - RListIter *iter, *iter2; + RzListIter *iter, *iter2; RBinSection *section = NULL, *segment = NULL; - RList *sections = r_list_new (); - RList *segments = r_list_new (); - RList *tmp = r_bin_get_sections (bin); - char *json_output = r_str_new (""); - RTable *table = r_table_new (); - RTableColumnType *typeString = r_table_type ("string"); + RzList *sections = rz_list_new (); + RzList *segments = rz_list_new (); + RzList *tmp = rz_bin_get_sections (bin); + char *json_output = rz_str_new (""); + RTable *table = rz_table_new (); + RTableColumnType *typeString = rz_table_type ("string"); - r_table_add_column (table, typeString, "Segment", 0); - r_table_add_column (table, typeString, "Section", 0); + rz_table_add_column (table, typeString, "Segment", 0); + rz_table_add_column (table, typeString, "Section", 0); - r_list_foreach (tmp, iter, section) { - RList *list = section->is_segment? segments: sections; - r_list_append (list, section); + rz_list_foreach (tmp, iter, section) { + RzList *list = section->is_segment? segments: sections; + rz_list_append (list, section); } - r_list_foreach (segments, iter, segment) { + rz_list_foreach (segments, iter, segment) { RInterval segment_itv = (RInterval){segment->vaddr, segment->size}; - char *tmp2 = r_str_new (""); - r_list_foreach (sections, iter2, section) { + char *tmp2 = rz_str_new (""); + rz_list_foreach (sections, iter2, section) { RInterval section_itv = (RInterval){section->vaddr, section->size}; - if (r_itv_begin (section_itv) >= r_itv_begin (segment_itv) && r_itv_end (section_itv) <= r_itv_end (segment_itv) && section->name[0]) { - tmp2 = r_str_appendf (tmp2, "%s ", section->name); + if (rz_itv_begin (section_itv) >= rz_itv_begin (segment_itv) && rz_itv_end (section_itv) <= rz_itv_end (segment_itv) && section->name[0]) { + tmp2 = rz_str_appendf (tmp2, "%s ", section->name); } } - r_table_add_row (table, segment->name, tmp2, 0); + rz_table_add_row (table, segment->name, tmp2, 0); /*output to json*/ - json_output = r_str_appendf (json_output, "\"%s\": \"%s\",", segment->name, tmp2); + json_output = rz_str_appendf (json_output, "\"%s\": \"%s\",", segment->name, tmp2); free (tmp2); } // remove last , json_output [strlen (json_output) - 1] = 0; - char *jo = r_str_newf ("[{%s}]", json_output); + char *jo = rz_str_newf ("[{%s}]", json_output); free (json_output); json_output = jo; if (IS_MODE_JSON (mode)){ - r_cons_printf ("%s", json_output); + rz_cons_printf ("%s", json_output); } else if (IS_MODE_NORMAL (mode)){ - r_cons_printf ("Section to Segment mapping:\n"); - char *s = r_table_tostring (table); - r_cons_printf ("%s\n", s); + rz_cons_printf ("Section to Segment mapping:\n"); + char *s = rz_table_tostring (table); + rz_cons_printf ("%s\n", s); free (s); } free (json_output); - r_list_free (segments); - r_table_free (table); + rz_list_free (segments); + rz_table_free (table); return true; } -static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const char *name, const char *chksum, bool print_segments) { +static int bin_sections(RzCore *r, int mode, ut64 laddr, int va, ut64 at, const char *name, const char *chksum, bool print_segments) { char *str = NULL; RBinSection *section; RBinInfo *info = NULL; - RList *sections; - RListIter *iter; - RListIter *last_processed = NULL; - RTable *table = r_core_table (r); - r_return_val_if_fail (table, false); + RzList *sections; + RzListIter *iter; + RzListIter *last_processed = NULL; + RTable *table = rz_core_table (r); + rz_return_val_if_fail (table, false); int i = 0; int fd = -1; bool printHere = false; - sections = r_bin_get_sections (r->bin); + sections = rz_bin_get_sections (r->bin); #if LOAD_BSS_MALLOC - bool inDebugger = r_config_get_i (r->config, "cfg.debug"); + bool inDebugger = rz_config_get_i (r->config, "cfg.debug"); #endif HtPP *dup_chk_ht = ht_pp_new0 (); bool ret = false; const char *type = print_segments ? "segment" : "section"; bool segments_only = true; - RList *io_section_info = NULL; + RzList *io_section_info = NULL; if (!dup_chk_ht) { return false; @@ -2771,73 +2771,73 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c } char *hashtypes = filter_hash_string (chksum); if (IS_MODE_EQUAL (mode)) { - int cols = r_cons_get_size (NULL); - RList *list = r_list_newf ((RListFree) r_listinfo_free); + int cols = rz_cons_get_size (NULL); + RzList *list = rz_list_newf ((RzListFree) rz_listinfo_free); if (!list) { free (hashtypes); return false; } RBinSection *s; - r_list_foreach (sections, iter, s) { + rz_list_foreach (sections, iter, s) { char humansz[8]; if (print_segments != s->is_segment) { continue; } RInterval pitv = (RInterval){s->paddr, s->size}; RInterval vitv = (RInterval){s->vaddr, s->vsize}; - r_num_units (humansz, sizeof (humansz), s->size); - RListInfo *info = r_listinfo_new (s->name, pitv, vitv, s->perm, strdup (humansz)); - r_list_append (list, info); + rz_num_units (humansz, sizeof (humansz), s->size); + RzListInfo *info = rz_listinfo_new (s->name, pitv, vitv, s->perm, strdup (humansz)); + rz_list_append (list, info); } - RTable *table = r_core_table (r); - r_table_visual_list (table, list, r->offset, -1, cols, r->io->va); + RTable *table = rz_core_table (r); + rz_table_visual_list (table, list, r->offset, -1, cols, r->io->va); if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } { - char *s = r_table_tostring (table); - r_cons_printf ("\n%s\n", s); + char *s = rz_table_tostring (table); + rz_cons_printf ("\n%s\n", s); free (s); } - r_table_free (table); - r_list_free (list); + rz_table_free (table); + rz_list_free (list); goto out; } if (IS_MODE_JSON (mode) && !printHere) { - r_cons_printf ("["); + rz_cons_printf ("["); } else if (IS_MODE_RAD (mode) && at == UT64_MAX) { - r_cons_printf ("fs %ss\n", type); + rz_cons_printf ("fs %ss\n", type); } else if (IS_MODE_NORMAL (mode) && at == UT64_MAX && !printHere) { - r_cons_printf ("[%s]\n", print_segments ? "Segments" : "Sections"); + rz_cons_printf ("[%s]\n", print_segments ? "Segments" : "Sections"); } else if (IS_MODE_NORMAL (mode) && printHere) { - r_cons_printf ("Current section\n"); + rz_cons_printf ("Current section\n"); } else if (IS_MODE_SET (mode)) { - fd = r_core_file_cur_fd (r); - r_flag_space_set (r->flags, print_segments? R_FLAGS_FS_SEGMENTS: R_FLAGS_FS_SECTIONS); + fd = rz_core_file_cur_fd (r); + rz_flag_space_set (r->flags, print_segments? R_FLAGS_FS_SEGMENTS: R_FLAGS_FS_SECTIONS); } if (IS_MODE_NORMAL (mode)) { if (hashtypes) { - r_table_set_columnsf (table, "dXxXxsss", + rz_table_set_columnsf (table, "dXxXxsss", "nth", "paddr", "size", "vaddr", "vsize", "perm", hashtypes, "name"); } else { - r_table_set_columnsf (table, "dXxXxss", + rz_table_set_columnsf (table, "dXxXxss", "nth", "paddr", "size", "vaddr", "vsize", "perm", "name"); } - // r_table_align (table, 0, R_TABLE_ALIGN_CENTER); - r_table_align (table, 2, R_TABLE_ALIGN_RIGHT); - r_table_align (table, 4, R_TABLE_ALIGN_RIGHT); + // rz_table_align (table, 0, R_TABLE_ALIGN_CENTER); + rz_table_align (table, 2, R_TABLE_ALIGN_RIGHT); + rz_table_align (table, 4, R_TABLE_ALIGN_RIGHT); } if (IS_MODE_SET (mode)) { - r_list_foreach (sections, iter, section) { + rz_list_foreach (sections, iter, section) { if (!section->is_segment) { segments_only = false; break; } } - io_section_info = r_list_newf ((RListFree)free); + io_section_info = rz_list_newf ((RzListFree)free); } - r_list_foreach (sections, iter, section) { + rz_list_foreach (sections, iter, section) { char perms[] = "----"; int va_sect = va; ut64 addr; @@ -2856,7 +2856,7 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c continue; } - r_name_filter (section->name, strlen (section->name) + 1); + rz_name_filter (section->name, strlen (section->name) + 1); if (at != UT64_MAX && (!section->size || !is_in_range (at, addr, section->size))) { continue; } @@ -2864,7 +2864,7 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c if (section->is_segment != print_segments) { continue; } - // XXX use r_str_perm instead of doing it here imho + // XXX use rz_str_perm instead of doing it here imho if (section->perm & R_PERM_SHAR) { perms[0] = 's'; } @@ -2892,29 +2892,29 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c } } if (!arch) { - arch = r_config_get (r->config, "asm.arch"); + arch = rz_config_get (r->config, "asm.arch"); } if (!bits) { bits = R_SYS_BITS; } if (IS_MODE_RAD (mode)) { char *n = __filterQuotedShell (section->name); - r_cons_printf ("\"f %s.%s 1 0x%08"PFMT64x"\"\n", type, n, section->vaddr); + rz_cons_printf ("\"f %s.%s 1 0x%08"PFMT64x"\"\n", type, n, section->vaddr); free (n); } else if (IS_MODE_SET (mode)) { #if LOAD_BSS_MALLOC if (!strcmp (section->name, ".bss")) { // check if there's already a file opened there int loaded = 0; - RListIter *iter; - RIOMap *m; - r_list_foreach (r->io->maps, iter, m) { + RzListIter *iter; + RzIOMap *m; + rz_list_foreach (r->io->maps, iter, m) { if (m->from == addr) { loaded = 1; } } if (!loaded && !inDebugger) { - r_core_cmdf (r, "on malloc://%d 0x%"PFMT64x" # bss\n", + rz_core_cmdf (r, "on malloc://%d 0x%"PFMT64x" # bss\n", section->vsize, addr); } } @@ -2922,30 +2922,30 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c if (section->format) { // This is damn slow if section vsize is HUGE if (section->vsize < 1024 * 1024 * 2) { - r_core_cmdf (r, "%s @ 0x%"PFMT64x, section->format, section->vaddr); + rz_core_cmdf (r, "%s @ 0x%"PFMT64x, section->format, section->vaddr); } } if (r->bin->prefix) { - str = r_str_newf ("%s.%s.%s", r->bin->prefix, type, section->name); + str = rz_str_newf ("%s.%s.%s", r->bin->prefix, type, section->name); } else { - str = r_str_newf ("%s.%s", type, section->name); + str = rz_str_newf ("%s.%s", type, section->name); } ut64 size = r->io->va? section->vsize: section->size; - r_flag_set (r->flags, str, addr, size); + rz_flag_set (r->flags, str, addr, size); R_FREE (str); if (!section->is_segment || segments_only) { char *pfx = r->bin->prefix; - str = r_str_newf ("[%02d] %s %s size %" PFMT64d" named %s%s%s", + str = rz_str_newf ("[%02d] %s %s size %" PFMT64d" named %s%s%s", i, perms, type, size, pfx? pfx: "", pfx? ".": "", section->name); - r_meta_set (r->anal, R_META_TYPE_COMMENT, addr, 1, str); + rz_meta_set (r->anal, R_META_TYPE_COMMENT, addr, 1, str); R_FREE (str); } if (section->add) { bool found; - str = r_str_newf ("%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT32u".%s.%"PFMT32u".%d", + str = rz_str_newf ("%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT64x".%"PFMT32u".%s.%"PFMT32u".%d", section->paddr, addr, section->size, section->vsize, section->perm, section->name, r->bin->cur->id, fd); ht_pp_find (dup_chk_ht, str, &found); if (!found) { @@ -2962,7 +2962,7 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c ibs->sec = section; ibs->addr = addr; ibs->fd = fd; - r_list_append (io_section_info, ibs); + rz_list_append (io_section_info, ibs); ht_pp_insert (dup_chk_ht, str, NULL); } R_FREE (str); @@ -2975,11 +2975,11 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c goto out; } ut32 datalen = section->size; - r_io_pread_at (r->io, section->paddr, data, datalen); + rz_io_pread_at (r->io, section->paddr, data, datalen); hashstr = build_hash_string (mode, hashtypes, data, datalen); free (data); } - r_cons_printf ("0x%"PFMT64x" 0x%"PFMT64x" %s %s%s%s\n", + rz_cons_printf ("0x%"PFMT64x" 0x%"PFMT64x" %s %s%s%s\n", addr, addr + section->size, perms, hashstr ? hashstr : "", hashstr ? " " : "", @@ -2994,12 +2994,12 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c goto out; } ut32 datalen = section->size; - r_io_pread_at (r->io, section->paddr, data, datalen); + rz_io_pread_at (r->io, section->paddr, data, datalen); hashstr = build_hash_string (mode, hashtypes, data, datalen); free (data); } - r_cons_printf ("%s{\"name\":\"%s\"," + rz_cons_printf ("%s{\"name\":\"%s\"," "\"size\":%"PFMT64d"," "\"vsize\":%"PFMT64d"," "\"perm\":\"%s\"," @@ -3025,14 +3025,14 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c ut32 datalen = section->size; // VA READ IS BROKEN? if (datalen > 0) { - r_io_pread_at (r->io, section->paddr, data, datalen); + rz_io_pread_at (r->io, section->paddr, data, datalen); } hashstr = build_hash_string (mode, hashtypes, data, datalen); free (data); } if (section->arch || section->bits) { snprintf (str, sizeof (str), "arch=%s bits=%d ", - r_str_get2 (arch), bits); + rz_str_get2 (arch), bits); } else { str[0] = 0; } @@ -3040,14 +3040,14 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c ? sdb_fmt ("%s.%s", r->bin->prefix, section->name) : section->name; // seems like asm.bits is a bitmask that seems to be always 32,64 - // const char *asmbits = r_str_sysbits (bits); + // const char *asmbits = rz_str_sysbits (bits); if (hashtypes) { - r_table_add_rowf (table, "dXxXxsss", i, + rz_table_add_rowf (table, "dXxXxsss", i, (ut64)section->paddr, (ut64)section->size, (ut64)addr, (ut64)section->vsize, perms, hashstr, section_name); } else { - r_table_add_rowf (table, "dXxXxss", i, + rz_table_add_rowf (table, "dXxXxss", i, (ut64)section->paddr, (ut64)section->size, (ut64)addr, (ut64)section->vsize, perms, section_name); @@ -3058,81 +3058,81 @@ static int bin_sections(RCore *r, int mode, ut64 laddr, int va, ut64 at, const c last_processed = iter; if (printHere) { if (IS_MODE_JSON (mode)) { - r_cons_print ("\n"); + rz_cons_print ("\n"); } break; } } - if (IS_MODE_SET (mode) && !r_io_desc_is_dbg (r->io->desc)) { - RListIter *it; + if (IS_MODE_SET (mode) && !rz_io_desc_is_dbg (r->io->desc)) { + RzListIter *it; struct io_bin_section_info_t *ibs; - r_list_foreach_prev (io_section_info, it, ibs) { + rz_list_foreach_prev (io_section_info, it, ibs) { add_section (r, ibs->sec, ibs->addr, ibs->fd); } - r_io_update (r->io); - r_list_free (io_section_info); + rz_io_update (r->io); + rz_list_free (io_section_info); io_section_info = NULL; } if (IS_MODE_JSON (mode) && !printHere) { - r_cons_println ("]"); + rz_cons_println ("]"); } else if (IS_MODE_NORMAL (mode) && at == UT64_MAX && !printHere) { - // r_cons_printf ("\n%i sections\n", i); + // rz_cons_printf ("\n%i sections\n", i); } ret = true; out: if (IS_MODE_NORMAL (mode)) { if (r->table_query) { - r_table_query (table, r->table_query); + rz_table_query (table, r->table_query); } - char *s = r_table_tostring (table); - r_cons_printf ("\n%s\n", s); + char *s = rz_table_tostring (table); + rz_cons_printf ("\n%s\n", s); free (s); } free (hashtypes); - r_table_free (table); + rz_table_free (table); ht_pp_free (dup_chk_ht); return ret; } -static int bin_fields(RCore *r, int mode, int va) { - RList *fields; - RListIter *iter; +static int bin_fields(RzCore *r, int mode, int va) { + RzList *fields; + RzListIter *iter; RBinField *field; int i = 0; RBin *bin = r->bin; - if (!(fields = r_bin_get_fields (bin))) { + if (!(fields = rz_bin_get_fields (bin))) { return false; } if (IS_MODE_JSON (mode)) { - r_cons_print ("["); + rz_cons_print ("["); } else if (IS_MODE_RAD (mode)) { - r_cons_println ("fs header"); + rz_cons_println ("fs header"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_println ("[Header fields]"); + rz_cons_println ("[Header fields]"); } - r_list_foreach (fields, iter, field) { + rz_list_foreach (fields, iter, field) { ut64 addr = rva (bin, field->paddr, field->vaddr, va); if (IS_MODE_RAD (mode)) { char *n = __filterQuotedShell (field->name); - r_name_filter (n, -1); - r_cons_printf ("\"f header.%s 1 0x%08"PFMT64x"\"\n", n, addr); + rz_name_filter (n, -1); + rz_cons_printf ("\"f header.%s 1 0x%08"PFMT64x"\"\n", n, addr); if (field->comment && *field->comment) { char *e = sdb_encode ((const ut8*)field->comment, -1); - r_cons_printf ("CCu %s @ 0x%"PFMT64x"\n", e, addr); + rz_cons_printf ("CCu %s @ 0x%"PFMT64x"\n", e, addr); free (e); char *f = __filterShell (field->format); - r_cons_printf ("Cf %d %s @ 0x%"PFMT64x"\n", field->size, f, addr); + rz_cons_printf ("Cf %d %s @ 0x%"PFMT64x"\n", field->size, f, addr); free (f); } if (field->format && *field->format && !field->format_named) { - r_cons_printf ("pf.%s %s\n", n, field->format); + rz_cons_printf ("pf.%s %s\n", n, field->format); } free (n); } else if (IS_MODE_JSON (mode)) { - r_cons_printf ("%s{\"name\":\"%s\"," + rz_cons_printf ("%s{\"name\":\"%s\"," "\"vaddr\":%"PFMT64d"," "\"paddr\":%"PFMT64d, iter->p? ",": "", @@ -3142,22 +3142,22 @@ static int bin_fields(RCore *r, int mode, int va) { ); if (field->comment && *field->comment) { // TODO: filter comment before json - r_cons_printf (",\"comment\":\"%s\"", field->comment); + rz_cons_printf (",\"comment\":\"%s\"", field->comment); } if (field->format && *field->format) { // TODO: filter comment before json - r_cons_printf (",\"format\":\"%s\"", field->format); + rz_cons_printf (",\"format\":\"%s\"", field->format); } - char *o = r_core_cmd_strf (r, "pfj%c%s@0x%"PFMT64x, + char *o = rz_core_cmd_strf (r, "pfj%c%s@0x%"PFMT64x, field->format_named ? '.' : ' ', field->format, field->vaddr); if (o && *o) { - r_cons_printf (",\"pf\":%s", o); + rz_cons_printf (",\"pf\":%s", o); } free (o); - r_cons_printf ("}"); + rz_cons_printf ("}"); } else if (IS_MODE_NORMAL (mode)) { const bool haveComment = (field->comment && *field->comment); - r_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s%s%s\n", + rz_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s%s%s\n", field->vaddr, field->paddr, field->name, haveComment? "; ": "", haveComment? field->comment: ""); @@ -3165,9 +3165,9 @@ static int bin_fields(RCore *r, int mode, int va) { i++; } if (IS_MODE_JSON (mode)) { - r_cons_printf ("]"); + rz_cons_printf ("]"); } else if (IS_MODE_NORMAL (mode)) { - r_cons_printf ("\n%i fields\n", i); + rz_cons_printf ("\n%i fields\n", i); } return true; @@ -3231,16 +3231,16 @@ static char *get_rp(const char *rtype) { return rp; } -static int bin_trycatch(RCore *core, int mode) { - RBinFile *bf = r_bin_cur (core->bin); - RListIter *iter; +static int bin_trycatch(RzCore *core, int mode) { + RBinFile *bf = rz_bin_cur (core->bin); + RzListIter *iter; RBinTrycatch *tc; - RList *trycatch = r_bin_file_get_trycatch (bf); + RzList *trycatch = rz_bin_file_get_trycatch (bf); int idx = 0; - r_list_foreach (trycatch, iter, tc) { - r_cons_printf ("f try.%d.%"PFMT64x".from=0x%08"PFMT64x"\n", idx, tc->source, tc->from); - r_cons_printf ("f try.%d.%"PFMT64x".to=0x%08"PFMT64x"\n", idx, tc->source, tc->to); - r_cons_printf ("f try.%d.%"PFMT64x".catch=0x%08"PFMT64x"\n", idx, tc->source, tc->handler); + rz_list_foreach (trycatch, iter, tc) { + rz_cons_printf ("f try.%d.%"PFMT64x".from=0x%08"PFMT64x"\n", idx, tc->source, tc->from); + rz_cons_printf ("f try.%d.%"PFMT64x".to=0x%08"PFMT64x"\n", idx, tc->source, tc->to); + rz_cons_printf ("f try.%d.%"PFMT64x".catch=0x%08"PFMT64x"\n", idx, tc->source, tc->handler); idx++; } return true; @@ -3285,8 +3285,8 @@ static char *objc_type_toc(const char *objc_type) { if (strlen (objc_type) == 1) { eprintf ("Unknown objc type '%s'\n", objc_type); } - if (r_str_startswith (objc_type, "@\"")) { - char *s = r_str_newf ("struct %s", objc_type + 2); + if (rz_str_startswith (objc_type, "@\"")) { + char *s = rz_str_newf ("struct %s", objc_type + 2); s[strlen (s) - 1] = '*'; return s; } @@ -3294,7 +3294,7 @@ static char *objc_type_toc(const char *objc_type) { } static char *objc_name_toc(const char *objc_name) { - const char *n = r_str_lchr (objc_name, ')'); + const char *n = rz_str_lchr (objc_name, ')'); char *s = strdup (n? n + 1: objc_name); char *p = strchr (s, '('); if (p) { @@ -3303,119 +3303,119 @@ static char *objc_name_toc(const char *objc_name) { return s; } -static void classdump_c(RCore *r, RBinClass *c) { - r_cons_printf ("typedef struct class_%s {\n", c->name); - RListIter *iter2; +static void classdump_c(RzCore *r, RBinClass *c) { + rz_cons_printf ("typedef struct class_%s {\n", c->name); + RzListIter *iter2; RBinField *f; - r_list_foreach (c->fields, iter2, f) { + rz_list_foreach (c->fields, iter2, f) { if (f->type && f->name) { char *n = objc_name_toc (f->name); char *t = objc_type_toc (f->type); - r_cons_printf (" %s %s; // %d\n", t, n, f->offset); + rz_cons_printf (" %s %s; // %d\n", t, n, f->offset); free (t); free (n); } } - r_cons_printf ("} %s;\n", c->name); + rz_cons_printf ("} %s;\n", c->name); } -static void classdump_objc(RCore *r, RBinClass *c) { +static void classdump_objc(RzCore *r, RBinClass *c) { if (c->super) { - r_cons_printf ("@interface %s : %s\n{\n", c->name, c->super); + rz_cons_printf ("@interface %s : %s\n{\n", c->name, c->super); } else { - r_cons_printf ("@interface %s\n{\n", c->name); + rz_cons_printf ("@interface %s\n{\n", c->name); } - RListIter *iter2, *iter3; + RzListIter *iter2, *iter3; RBinField *f; RBinSymbol *sym; - r_list_foreach (c->fields, iter2, f) { - if (f->name && r_regex_match ("ivar","e", f->name)) { - r_cons_printf (" %s %s\n", f->type, f->name); + rz_list_foreach (c->fields, iter2, f) { + if (f->name && rz_regex_match ("ivar","e", f->name)) { + rz_cons_printf (" %s %s\n", f->type, f->name); } } - r_cons_printf ("}\n"); - r_list_foreach (c->methods, iter3, sym) { + rz_cons_printf ("}\n"); + rz_list_foreach (c->methods, iter3, sym) { if (sym->rtype && sym->rtype[0] != '@') { char *rp = get_rp (sym->rtype); - r_cons_printf ("%s (%s) %s\n", + rz_cons_printf ("%s (%s) %s\n", strncmp (sym->type, R_BIN_TYPE_METH_STR, 4)? "+": "-", rp, sym->dname? sym->dname: sym->name); free (rp); } else if (sym->type) { - r_cons_printf ("%s (id) %s\n", + rz_cons_printf ("%s (id) %s\n", strncmp (sym->type, R_BIN_TYPE_METH_STR, 4)? "+": "-", sym->dname? sym->dname: sym->name); } } - r_cons_printf ("@end\n"); + rz_cons_printf ("@end\n"); } -static void classdump_java(RCore *r, RBinClass *c) { +static void classdump_java(RzCore *r, RBinClass *c) { RBinField *f; - RListIter *iter2, *iter3; + RzListIter *iter2, *iter3; RBinSymbol *sym; char *pn = strdup (c->name); - char *cn = (char *)r_str_rchr (pn, NULL, '/'); + char *cn = (char *)rz_str_rchr (pn, NULL, '/'); if (cn) { *cn = 0; cn++; - r_str_replace_char (pn, '/', '.'); + rz_str_replace_char (pn, '/', '.'); } - r_cons_printf ("package %s;\n\n", pn); - r_cons_printf ("public class %s {\n", cn); + rz_cons_printf ("package %s;\n\n", pn); + rz_cons_printf ("public class %s {\n", cn); free (pn); - r_list_foreach (c->fields, iter2, f) { - if (f->name && r_regex_match ("ivar","e", f->name)) { - r_cons_printf (" public %s %s\n", f->type, f->name); + rz_list_foreach (c->fields, iter2, f) { + if (f->name && rz_regex_match ("ivar","e", f->name)) { + rz_cons_printf (" public %s %s\n", f->type, f->name); } } - r_list_foreach (c->methods, iter3, sym) { + rz_list_foreach (c->methods, iter3, sym) { const char *mn = sym->dname? sym->dname: sym->name; const char *ms = strstr (mn, "method."); if (ms) { mn = ms + strlen ("method."); } - r_cons_printf (" public %s ();\n", mn); + rz_cons_printf (" public %s ();\n", mn); } - r_cons_printf ("}\n\n"); + rz_cons_printf ("}\n\n"); } -static int bin_classes(RCore *r, int mode) { - RListIter *iter, *iter2, *iter3; +static int bin_classes(RzCore *r, int mode) { + RzListIter *iter, *iter2, *iter3; RBinSymbol *sym; RBinClass *c; RBinField *f; char *name; - RList *cs = r_bin_get_classes (r->bin); + RzList *cs = rz_bin_get_classes (r->bin); if (!cs) { if (IS_MODE_JSON (mode)) { - r_cons_print ("[]\n"); + rz_cons_print ("[]\n"); return true; } return false; } // XXX: support for classes is broken and needs more love if (IS_MODE_JSON (mode)) { - r_cons_print ("["); + rz_cons_print ("["); } else if (IS_MODE_SET (mode)) { - if (!r_config_get_i (r->config, "bin.classes")) { + if (!rz_config_get_i (r->config, "bin.classes")) { return false; } - r_flag_space_set (r->flags, R_FLAGS_FS_CLASSES); + rz_flag_space_set (r->flags, R_FLAGS_FS_CLASSES); } else if (IS_MODE_RAD (mode) && !IS_MODE_CLASSDUMP (mode)) { - r_cons_println ("fs classes"); + rz_cons_println ("fs classes"); } - r_list_foreach (cs, iter, c) { + rz_list_foreach (cs, iter, c) { if (!c || !c->name || !c->name[0]) { continue; } name = strdup (c->name); - r_name_filter (name, 0); + rz_name_filter (name, 0); ut64 at_min = UT64_MAX; ut64 at_max = 0LL; - r_list_foreach (c->methods, iter2, sym) { + rz_list_foreach (c->methods, iter2, sym) { if (sym->vaddr) { if (sym->vaddr < at_min) { at_min = sym->vaddr; @@ -3432,32 +3432,32 @@ static int bin_classes(RCore *r, int mode) { if (IS_MODE_SET (mode)) { const char *classname = sdb_fmt ("class.%s", name); - r_flag_set (r->flags, classname, c->addr, 1); - r_list_foreach (c->methods, iter2, sym) { - char *mflags = r_core_bin_method_flags_str (sym->method_flags, mode); + rz_flag_set (r->flags, classname, c->addr, 1); + rz_list_foreach (c->methods, iter2, sym) { + char *mflags = rz_core_bin_method_flags_str (sym->method_flags, mode); char *method = sdb_fmt ("method%s.%s.%s", mflags, c->name, sym->name); R_FREE (mflags); - r_name_filter (method, -1); - r_flag_set (r->flags, method, sym->vaddr, 1); + rz_name_filter (method, -1); + rz_flag_set (r->flags, method, sym->vaddr, 1); } #if 0 - r_list_foreach (c->fields, iter2, f) { - char *fn = r_str_newf ("field.%s.%s", classname, f->name); + rz_list_foreach (c->fields, iter2, f) { + char *fn = rz_str_newf ("field.%s.%s", classname, f->name); ut64 at = f->vaddr; // sym->vaddr + (f->vaddr & 0xffff); - r_flag_set (r->flags, fn, at, 1); + rz_flag_set (r->flags, fn, at, 1); free (fn); } #endif } else if (IS_MODE_SIMPLEST (mode)) { - r_cons_printf ("%s\n", c->name); + rz_cons_printf ("%s\n", c->name); } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("0x%08"PFMT64x" [0x%08"PFMT64x" - 0x%08"PFMT64x"] %s%s%s\n", + rz_cons_printf ("0x%08"PFMT64x" [0x%08"PFMT64x" - 0x%08"PFMT64x"] %s%s%s\n", c->addr, at_min, at_max, c->name, c->super ? " " : "", c->super ? c->super : ""); } else if (IS_MODE_CLASSDUMP (mode)) { if (c) { - RBinFile *bf = r_bin_cur (r->bin); + RBinFile *bf = rz_bin_cur (r->bin); if (bf && bf->o) { if (IS_MODE_RAD (mode)) { classdump_c (r, c); @@ -3472,107 +3472,107 @@ static int bin_classes(RCore *r, int mode) { } } else if (IS_MODE_RAD (mode)) { char *n = __filterShell (name); - r_cons_printf ("\"f class.%s = 0x%"PFMT64x"\"\n", n, at_min); + rz_cons_printf ("\"f class.%s = 0x%"PFMT64x"\"\n", n, at_min); free (n); if (c->super) { char *cn = c->name; // __filterShell (c->name); char *su = c->super; // __filterShell (c->super); - r_cons_printf ("\"f super.%s.%s = %d\"\n", + rz_cons_printf ("\"f super.%s.%s = %d\"\n", cn, su, c->index); // free (cn); // free (su); } - r_list_foreach (c->methods, iter2, sym) { - char *mflags = r_core_bin_method_flags_str (sym->method_flags, mode); + rz_list_foreach (c->methods, iter2, sym) { + char *mflags = rz_core_bin_method_flags_str (sym->method_flags, mode); char *n = c->name; // __filterShell (c->name); char *sn = sym->name; //__filterShell (sym->name); - char *cmd = r_str_newf ("\"f method%s.%s.%s = 0x%"PFMT64x"\"\n", mflags, n, sn, sym->vaddr); + char *cmd = rz_str_newf ("\"f method%s.%s.%s = 0x%"PFMT64x"\"\n", mflags, n, sn, sym->vaddr); // free (n); // free (sn); if (cmd) { - r_str_replace_char (cmd, ' ', '_'); + rz_str_replace_char (cmd, ' ', '_'); if (strlen (cmd) > 2) { cmd[2] = ' '; } - char *eq = (char *)r_str_rchr (cmd, NULL, '='); + char *eq = (char *)rz_str_rchr (cmd, NULL, '='); if (eq && eq != cmd) { eq[-1] = eq[1] = ' '; } - r_str_replace_char (cmd, '\n', 0); - r_cons_printf ("%s\n", cmd); + rz_str_replace_char (cmd, '\n', 0); + rz_cons_printf ("%s\n", cmd); free (cmd); } R_FREE (mflags); } - r_list_foreach (c->fields, iter2, f) { - char *fn = r_str_newf ("field.%s.%s", c->name, f->name); + rz_list_foreach (c->fields, iter2, f) { + char *fn = rz_str_newf ("field.%s.%s", c->name, f->name); ut64 at = f->vaddr; // sym->vaddr + (f->vaddr & 0xffff); - r_cons_printf ("\"f %s = 0x%08"PFMT64x"\"\n", fn, at); + rz_cons_printf ("\"f %s = 0x%08"PFMT64x"\"\n", fn, at); free (fn); } // C struct - r_cons_printf ("\"td struct %s {", c->name); - if (r_list_empty (c->fields)) { + rz_cons_printf ("\"td struct %s {", c->name); + if (rz_list_empty (c->fields)) { // XXX workaround because we cant register empty structs yet - // XXX https://github.com/radareorg/radare2/issues/16342 - r_cons_printf (" char empty[0];"); + // XXX https://github.com/rizinorg/rizin/issues/16342 + rz_cons_printf (" char empty[0];"); } else { - r_list_foreach (c->fields, iter2, f) { + rz_list_foreach (c->fields, iter2, f) { char *n = objc_name_toc (f->name); char *t = objc_type_toc (f->type); - r_cons_printf (" %s %s;", t, n); + rz_cons_printf (" %s %s;", t, n); free (t); free (n); } } - r_cons_printf ("};\"\n"); + rz_cons_printf ("};\"\n"); } else if (IS_MODE_JSON (mode)) { if (c->super) { - r_cons_printf ("%s{\"classname\":\"%s\",\"addr\":%"PFMT64d",\"index\":%d,\"visibility\":\"%s\",\"super\":\"%s\",\"methods\":[", + rz_cons_printf ("%s{\"classname\":\"%s\",\"addr\":%"PFMT64d",\"index\":%d,\"visibility\":\"%s\",\"super\":\"%s\",\"methods\":[", iter->p ? "," : "", c->name, c->addr, c->index, c->visibility_str? c->visibility_str: "", c->super); } else { - r_cons_printf ("%s{\"classname\":\"%s\",\"addr\":%"PFMT64d",\"index\":%d,\"methods\":[", + rz_cons_printf ("%s{\"classname\":\"%s\",\"addr\":%"PFMT64d",\"index\":%d,\"methods\":[", iter->p ? "," : "", c->name, c->addr, c->index); } - r_list_foreach (c->methods, iter2, sym) { + rz_list_foreach (c->methods, iter2, sym) { if (sym->method_flags) { - char *mflags = r_core_bin_method_flags_str (sym->method_flags, mode); - r_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"addr\":%"PFMT64d"}", + char *mflags = rz_core_bin_method_flags_str (sym->method_flags, mode); + rz_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"addr\":%"PFMT64d"}", iter2->p? ",": "", sym->name, mflags, sym->vaddr); R_FREE (mflags); } else { - r_cons_printf ("%s{\"name\":\"%s\",\"addr\":%"PFMT64d"}", + rz_cons_printf ("%s{\"name\":\"%s\",\"addr\":%"PFMT64d"}", iter2->p? ",": "", sym->name, sym->vaddr); } } - r_cons_printf ("], \"fields\":["); - r_list_foreach (c->fields, iter3, f) { + rz_cons_printf ("], \"fields\":["); + rz_list_foreach (c->fields, iter3, f) { if (f->flags) { - char *mflags = r_core_bin_method_flags_str (f->flags, mode); - r_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"addr\":%"PFMT64d"}", + char *mflags = rz_core_bin_method_flags_str (f->flags, mode); + rz_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"addr\":%"PFMT64d"}", iter3->p? ",": "", f->name, mflags, f->vaddr); R_FREE (mflags); } else { - r_cons_printf ("%s{\"name\":\"%s\",\"addr\":%"PFMT64d"}", + rz_cons_printf ("%s{\"name\":\"%s\",\"addr\":%"PFMT64d"}", iter3->p? ",": "", f->name, f->vaddr); } } - r_cons_printf ("]}"); + rz_cons_printf ("]}"); } else { int m = 0; - r_cons_printf ("0x%08"PFMT64x" [0x%08"PFMT64x" - 0x%08"PFMT64x"] %6"PFMT64d" class %d %s", + rz_cons_printf ("0x%08"PFMT64x" [0x%08"PFMT64x" - 0x%08"PFMT64x"] %6"PFMT64d" class %d %s", c->addr, at_min, at_max, (at_max - at_min), c->index, c->name); if (c->super) { - r_cons_printf (" :: %s\n", c->super); + rz_cons_printf (" :: %s\n", c->super); } else { - r_cons_newline (); + rz_cons_newline (); } - r_list_foreach (c->methods, iter2, sym) { - char *mflags = r_core_bin_method_flags_str (sym->method_flags, mode); - r_cons_printf ("0x%08"PFMT64x" method %d %s %s\n", + rz_list_foreach (c->methods, iter2, sym) { + char *mflags = rz_core_bin_method_flags_str (sym->method_flags, mode); + rz_cons_printf ("0x%08"PFMT64x" method %d %s %s\n", sym->vaddr, m, mflags, sym->dname? sym->dname: sym->name); R_FREE (mflags); m++; @@ -3581,33 +3581,33 @@ static int bin_classes(RCore *r, int mode) { free (name); } if (IS_MODE_JSON (mode)) { - r_cons_print ("]\n"); + rz_cons_print ("]\n"); } return true; } -static int bin_size(RCore *r, int mode) { - ut64 size = r_bin_get_size (r->bin); +static int bin_size(RzCore *r, int mode) { + ut64 size = rz_bin_get_size (r->bin); if (IS_MODE_SIMPLE (mode) || IS_MODE_JSON (mode)) { - r_cons_printf ("%"PFMT64u"\n", size); + rz_cons_printf ("%"PFMT64u"\n", size); } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("f bin_size @ %"PFMT64u"\n", size); + rz_cons_printf ("f bin_size @ %"PFMT64u"\n", size); } else if (IS_MODE_SET (mode)) { - r_core_cmdf (r, "f bin_size @ %"PFMT64u"\n", size); + rz_core_cmdf (r, "f bin_size @ %"PFMT64u"\n", size); } else { - r_cons_printf ("%"PFMT64u"\n", size); + rz_cons_printf ("%"PFMT64u"\n", size); } return true; } -static int bin_libs(RCore *r, int mode) { - RListIter *iter; +static int bin_libs(RzCore *r, int mode) { + RzListIter *iter; char* lib; int i = 0; PJ *pj = NULL; - RList *libs = r_bin_get_libs (r->bin); + RzList *libs = rz_bin_get_libs (r->bin); if (IS_MODE_JSON (mode)) { pj = pj_new (); pj_a (pj); @@ -3616,88 +3616,88 @@ static int bin_libs(RCore *r, int mode) { return false; } if (IS_MODE_NORMAL (mode)) { - r_cons_println ("[Linked libraries]"); + rz_cons_println ("[Linked libraries]"); } } - r_list_foreach (libs, iter, lib) { + rz_list_foreach (libs, iter, lib) { if (IS_MODE_SET (mode)) { // Nothing to set. // TODO: load libraries with iomaps? } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("\"CCa entry0 %s\"\n", lib); + rz_cons_printf ("\"CCa entry0 %s\"\n", lib); } else if (IS_MODE_JSON (mode)) { pj_s (pj, lib); } else { // simple and normal print mode - r_cons_println (lib); + rz_cons_println (lib); } i++; } if (IS_MODE_JSON (mode)) { pj_end (pj); char *s = pj_drain (pj); - r_cons_printf ("%s", s); + rz_cons_printf ("%s", s); free (s); } else if (IS_MODE_NORMAL (mode)) { const char *libstr = (i > 1)? "libraries": "library"; - r_cons_printf ("\n%i %s\n", i, libstr); + rz_cons_printf ("\n%i %s\n", i, libstr); } return true; } -static void bin_mem_print(RList *mems, int perms, int depth, int mode) { +static void bin_mem_print(RzList *mems, int perms, int depth, int mode) { RBinMem *mem; - RListIter *iter; + RzListIter *iter; if (!mems) { return; } - r_list_foreach (mems, iter, mem) { + rz_list_foreach (mems, iter, mem) { if (IS_MODE_JSON (mode)) { - r_cons_printf ("{\"name\":\"%s\",\"size\":%d,\"address\":%d," + rz_cons_printf ("{\"name\":\"%s\",\"size\":%d,\"address\":%d," "\"flags\":\"%s\"}", mem->name, mem->size, - mem->addr, r_str_rwx_i (mem->perms & perms)); + mem->addr, rz_str_rwx_i (mem->perms & perms)); } else if (IS_MODE_SIMPLE (mode)) { - r_cons_printf ("0x%08"PFMT64x"\n", mem->addr); + rz_cons_printf ("0x%08"PFMT64x"\n", mem->addr); } else { - r_cons_printf ("0x%08"PFMT64x" +0x%04x %s %*s%-*s\n", - mem->addr, mem->size, r_str_rwx_i (mem->perms & perms), + rz_cons_printf ("0x%08"PFMT64x" +0x%04x %s %*s%-*s\n", + mem->addr, mem->size, rz_str_rwx_i (mem->perms & perms), depth, "", 20-depth, mem->name); } if (mem->mirrors) { if (IS_MODE_JSON (mode)) { - r_cons_printf (","); + rz_cons_printf (","); } bin_mem_print (mem->mirrors, mem->perms & perms, depth + 1, mode); } if (IS_MODE_JSON (mode)) { if (iter->n) { - r_cons_printf (","); + rz_cons_printf (","); } } } } -static int bin_mem(RCore *r, int mode) { - RList *mem = NULL; +static int bin_mem(RzCore *r, int mode) { + RzList *mem = NULL; if (!r) { return false; } if (!IS_MODE_JSON (mode)) { if (!(IS_MODE_RAD (mode) || IS_MODE_SET (mode))) { - r_cons_println ("[Memory]\n"); + rz_cons_println ("[Memory]\n"); } } - if (!(mem = r_bin_get_mem (r->bin))) { + if (!(mem = rz_bin_get_mem (r->bin))) { if (IS_MODE_JSON (mode)) { - r_cons_print("[]"); + rz_cons_print("[]"); return true; } return false; } if (IS_MODE_JSON (mode)) { - r_cons_print ("["); + rz_cons_print ("["); bin_mem_print (mem, 7, 0, R_MODE_JSON); - r_cons_println ("]"); + rz_cons_println ("]"); return true; } else if (!(IS_MODE_RAD (mode) || IS_MODE_SET (mode))) { bin_mem_print (mem, 7, 0, mode); @@ -3705,7 +3705,7 @@ static int bin_mem(RCore *r, int mode) { return true; } -static void bin_pe_versioninfo(RCore *r, int mode) { +static void bin_pe_versioninfo(RzCore *r, int mode) { Sdb *sdb = NULL; int num_version = 0; int num_stringtable = 0; @@ -3714,9 +3714,9 @@ static void bin_pe_versioninfo(RCore *r, int mode) { const char *format_stringtable = "%s/string_file_info/stringtable%d"; const char *format_string = "%s/string%d"; if (!IS_MODE_JSON (mode)) { - r_cons_printf ("=== VS_VERSIONINFO ===\n\n"); + rz_cons_printf ("=== VS_VERSIONINFO ===\n\n"); } else { - r_cons_print ("{"); + rz_cons_print ("{"); } bool firstit_dowhile = true; do { @@ -3725,95 +3725,95 @@ static void bin_pe_versioninfo(RCore *r, int mode) { break; } if (!firstit_dowhile && IS_MODE_JSON (mode)) { - r_cons_printf (","); + rz_cons_printf (","); } if (IS_MODE_JSON (mode)) { - r_cons_printf ("\"VS_FIXEDFILEINFO\":{"); + rz_cons_printf ("\"VS_FIXEDFILEINFO\":{"); } else { - r_cons_printf ("# VS_FIXEDFILEINFO\n\n"); + rz_cons_printf ("# VS_FIXEDFILEINFO\n\n"); } const char *path_fixedfileinfo = sdb_fmt ("%s/fixed_file_info", path_version); if (!(sdb = sdb_ns_path (r->sdb, path_fixedfileinfo, 0))) { - r_cons_printf ("}"); + rz_cons_printf ("}"); break; } if (IS_MODE_JSON (mode)) { - r_cons_printf ("\"Signature\":%"PFMT64u",", sdb_num_get (sdb, "Signature", 0)); - r_cons_printf ("\"StrucVersion\":%"PFMT64u",", sdb_num_get (sdb, "StrucVersion", 0)); - r_cons_printf ("\"FileVersion\":\"%"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\",", + rz_cons_printf ("\"Signature\":%"PFMT64u",", sdb_num_get (sdb, "Signature", 0)); + rz_cons_printf ("\"StrucVersion\":%"PFMT64u",", sdb_num_get (sdb, "StrucVersion", 0)); + rz_cons_printf ("\"FileVersion\":\"%"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\",", sdb_num_get (sdb, "FileVersionMS", 0) >> 16, sdb_num_get (sdb, "FileVersionMS", 0) & 0xFFFF, sdb_num_get (sdb, "FileVersionLS", 0) >> 16, sdb_num_get (sdb, "FileVersionLS", 0) & 0xFFFF); - r_cons_printf ("\"ProductVersion\":\"%"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\",", + rz_cons_printf ("\"ProductVersion\":\"%"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\",", sdb_num_get (sdb, "ProductVersionMS", 0) >> 16, sdb_num_get (sdb, "ProductVersionMS", 0) & 0xFFFF, sdb_num_get (sdb, "ProductVersionLS", 0) >> 16, sdb_num_get (sdb, "ProductVersionLS", 0) & 0xFFFF); - r_cons_printf ("\"FileFlagsMask\":%"PFMT64u",", sdb_num_get (sdb, "FileFlagsMask", 0)); - r_cons_printf ("\"FileFlags\":%"PFMT64u",", sdb_num_get (sdb, "FileFlags", 0)); - r_cons_printf ("\"FileOS\":%"PFMT64u",", sdb_num_get (sdb, "FileOS", 0)); - r_cons_printf ("\"FileType\":%"PFMT64u",", sdb_num_get (sdb, "FileType", 0)); - r_cons_printf ("\"FileSubType\":%"PFMT64u, sdb_num_get (sdb, "FileSubType", 0)); - r_cons_printf ("},"); + rz_cons_printf ("\"FileFlagsMask\":%"PFMT64u",", sdb_num_get (sdb, "FileFlagsMask", 0)); + rz_cons_printf ("\"FileFlags\":%"PFMT64u",", sdb_num_get (sdb, "FileFlags", 0)); + rz_cons_printf ("\"FileOS\":%"PFMT64u",", sdb_num_get (sdb, "FileOS", 0)); + rz_cons_printf ("\"FileType\":%"PFMT64u",", sdb_num_get (sdb, "FileType", 0)); + rz_cons_printf ("\"FileSubType\":%"PFMT64u, sdb_num_get (sdb, "FileSubType", 0)); + rz_cons_printf ("},"); } else { - r_cons_printf (" Signature: 0x%"PFMT64x"\n", sdb_num_get (sdb, "Signature", 0)); - r_cons_printf (" StrucVersion: 0x%"PFMT64x"\n", sdb_num_get (sdb, "StrucVersion", 0)); - r_cons_printf (" FileVersion: %"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\n", + rz_cons_printf (" Signature: 0x%"PFMT64x"\n", sdb_num_get (sdb, "Signature", 0)); + rz_cons_printf (" StrucVersion: 0x%"PFMT64x"\n", sdb_num_get (sdb, "StrucVersion", 0)); + rz_cons_printf (" FileVersion: %"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\n", sdb_num_get (sdb, "FileVersionMS", 0) >> 16, sdb_num_get (sdb, "FileVersionMS", 0) & 0xFFFF, sdb_num_get (sdb, "FileVersionLS", 0) >> 16, sdb_num_get (sdb, "FileVersionLS", 0) & 0xFFFF); - r_cons_printf (" ProductVersion: %"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\n", + rz_cons_printf (" ProductVersion: %"PFMT64d".%"PFMT64d".%"PFMT64d".%"PFMT64d"\n", sdb_num_get (sdb, "ProductVersionMS", 0) >> 16, sdb_num_get (sdb, "ProductVersionMS", 0) & 0xFFFF, sdb_num_get (sdb, "ProductVersionLS", 0) >> 16, sdb_num_get (sdb, "ProductVersionLS", 0) & 0xFFFF); - r_cons_printf (" FileFlagsMask: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileFlagsMask", 0)); - r_cons_printf (" FileFlags: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileFlags", 0)); - r_cons_printf (" FileOS: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileOS", 0)); - r_cons_printf (" FileType: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileType", 0)); - r_cons_printf (" FileSubType: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileSubType", 0)); - r_cons_newline (); + rz_cons_printf (" FileFlagsMask: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileFlagsMask", 0)); + rz_cons_printf (" FileFlags: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileFlags", 0)); + rz_cons_printf (" FileOS: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileOS", 0)); + rz_cons_printf (" FileType: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileType", 0)); + rz_cons_printf (" FileSubType: 0x%"PFMT64x"\n", sdb_num_get (sdb, "FileSubType", 0)); + rz_cons_newline (); } #if 0 - r_cons_printf (" FileDate: %d.%d.%d.%d\n", + rz_cons_printf (" FileDate: %d.%d.%d.%d\n", sdb_num_get (sdb, "FileDateMS", 0) >> 16, sdb_num_get (sdb, "FileDateMS", 0) & 0xFFFF, sdb_num_get (sdb, "FileDateLS", 0) >> 16, sdb_num_get (sdb, "FileDateLS", 0) & 0xFFFF); #endif if (IS_MODE_JSON (mode)) { - r_cons_printf ("\"StringTable\":{"); + rz_cons_printf ("\"StringTable\":{"); } else { - r_cons_printf ("# StringTable\n\n"); + rz_cons_printf ("# StringTable\n\n"); } for (num_stringtable = 0; sdb; num_stringtable++) { - char *path_stringtable = r_str_newf (format_stringtable, path_version, num_stringtable); + char *path_stringtable = rz_str_newf (format_stringtable, path_version, num_stringtable); sdb = sdb_ns_path (r->sdb, path_stringtable, 0); bool firstit_for = true; for (num_string = 0; sdb; num_string++) { - char *path_string = r_str_newf (format_string, path_stringtable, num_string); + char *path_string = rz_str_newf (format_string, path_stringtable, num_string); sdb = sdb_ns_path (r->sdb, path_string, 0); if (sdb) { - if (!firstit_for && IS_MODE_JSON (mode)) { r_cons_printf (","); } + if (!firstit_for && IS_MODE_JSON (mode)) { rz_cons_printf (","); } int lenkey = 0; int lenval = 0; ut8 *key_utf16 = sdb_decode (sdb_const_get (sdb, "key", 0), &lenkey); ut8 *val_utf16 = sdb_decode (sdb_const_get (sdb, "value", 0), &lenval); ut8 *key_utf8 = calloc (lenkey * 2, 1); ut8 *val_utf8 = calloc (lenval * 2, 1); - if (r_str_utf16_to_utf8 (key_utf8, lenkey * 2, key_utf16, lenkey, true) < 0 - || r_str_utf16_to_utf8 (val_utf8, lenval * 2, val_utf16, lenval, true) < 0) { + if (rz_str_utf16_to_utf8 (key_utf8, lenkey * 2, key_utf16, lenkey, true) < 0 + || rz_str_utf16_to_utf8 (val_utf8, lenval * 2, val_utf16, lenval, true) < 0) { eprintf ("Warning: Cannot decode utf16 to utf8\n"); } else if (IS_MODE_JSON (mode)) { - char *escaped_key_utf8 = r_str_escape ((char*)key_utf8); - char *escaped_val_utf8 = r_str_escape ((char*)val_utf8); - r_cons_printf ("\"%s\":\"%s\"", escaped_key_utf8, escaped_val_utf8); + char *escaped_key_utf8 = rz_str_escape ((char*)key_utf8); + char *escaped_val_utf8 = rz_str_escape ((char*)val_utf8); + rz_cons_printf ("\"%s\":\"%s\"", escaped_key_utf8, escaped_val_utf8); free (escaped_key_utf8); free (escaped_val_utf8); } else { - r_cons_printf (" %s: %s\n", (char*)key_utf8, (char*)val_utf8); + rz_cons_printf (" %s: %s\n", (char*)key_utf8, (char*)val_utf8); } free (key_utf8); free (val_utf8); @@ -3826,17 +3826,17 @@ static void bin_pe_versioninfo(RCore *r, int mode) { free (path_stringtable); } if (IS_MODE_JSON (mode)) { - r_cons_printf ("}"); + rz_cons_printf ("}"); } num_version++; firstit_dowhile = false; } while (sdb); if (IS_MODE_JSON (mode)) { - r_cons_printf ("}"); + rz_cons_printf ("}"); } } -static void bin_elf_versioninfo(RCore *r, int mode) { +static void bin_elf_versioninfo(RzCore *r, int mode) { const char *format = "bin/cur/info/versioninfo/%s%d"; int num_versym; int num_verneed = 0; @@ -3873,8 +3873,8 @@ static void bin_elf_versioninfo(RCore *r, int mode) { pj_ks (pj, "link_section_name", link_section_name); pj_ka (pj, "entries"); } else { - r_cons_printf ("Version symbols section '%s' contains %"PFMT64u" entries:\n", section_name, num_entries); - r_cons_printf (" Addr: 0x%08"PFMT64x" Offset: 0x%08"PFMT64x" Link: %x (%s)\n", + rz_cons_printf ("Version symbols section '%s' contains %"PFMT64u" entries:\n", section_name, num_entries); + rz_cons_printf (" Addr: 0x%08"PFMT64x" Offset: 0x%08"PFMT64x" Link: %x (%s)\n", (ut64)addr, (ut64)offset, (ut32)link, link_section_name); } int i; @@ -3886,15 +3886,15 @@ static void bin_elf_versioninfo(RCore *r, int mode) { continue; } if (IS_MODE_JSON (mode)) { - char *escaped_value = r_str_escape (value); + char *escaped_value = rz_str_escape (value); pj_o (pj); pj_kn (pj, "idx", (ut64)i); pj_ks (pj, "value", escaped_value); pj_end (pj); free (escaped_value); } else { - r_cons_printf (" 0x%08"PFMT64x": ", (ut64) i); - r_cons_printf ("%s\n", value); + rz_cons_printf (" 0x%08"PFMT64x": ", (ut64) i); + rz_cons_printf ("%s\n", value); } oValue = value; } @@ -3903,7 +3903,7 @@ static void bin_elf_versioninfo(RCore *r, int mode) { pj_end (pj); pj_end (pj); } else { - r_cons_printf ("\n\n"); + rz_cons_printf ("\n\n"); } } if (IS_MODE_JSON (mode)) { @@ -3912,7 +3912,7 @@ static void bin_elf_versioninfo(RCore *r, int mode) { } do { - char *verneed_path = r_str_newf (format, "verneed", num_verneed++); + char *verneed_path = rz_str_newf (format, "verneed", num_verneed++); if (!(sdb = sdb_ns_path (r->sdb, verneed_path, 0))) { break; } @@ -3930,12 +3930,12 @@ static void bin_elf_versioninfo(RCore *r, int mode) { pj_ks (pj, "link_section_name", link_section_name); pj_ka (pj, "entries"); } else { - r_cons_printf ("Version need section '%s' contains %d entries:\n", + rz_cons_printf ("Version need section '%s' contains %d entries:\n", section_name, (int)sdb_num_get (sdb, "num_entries", 0)); - r_cons_printf (" Addr: 0x%08"PFMT64x, address); + rz_cons_printf (" Addr: 0x%08"PFMT64x, address); - r_cons_printf (" Offset: 0x%08"PFMT64x" Link to section: %"PFMT64d" (%s)\n", + rz_cons_printf (" Offset: 0x%08"PFMT64x" Link to section: %"PFMT64d" (%s)\n", offset, link, link_section_name); } for (num_version = 0;; num_version++) { @@ -3951,24 +3951,24 @@ static void bin_elf_versioninfo(RCore *r, int mode) { pj_kn (pj, "idx", sdb_num_get (sdb, "idx", 0)); pj_ki (pj, "vn_version", (int)sdb_num_get (sdb, "vn_version", 0)); } else { - r_cons_printf (" 0x%08"PFMT64x": Version: %d", + rz_cons_printf (" 0x%08"PFMT64x": Version: %d", sdb_num_get (sdb, "idx", 0), (int)sdb_num_get (sdb, "vn_version", 0)); } if ((filename = sdb_const_get (sdb, "file_name", 0))) { if (IS_MODE_JSON (mode)) { - char *escaped_filename = r_str_escape (filename); + char *escaped_filename = rz_str_escape (filename); pj_ks (pj, "file_name", escaped_filename); free (escaped_filename); } else { - r_cons_printf (" File: %s", filename); + rz_cons_printf (" File: %s", filename); } } const int cnt = (int)sdb_num_get (sdb, "cnt", 0); if (IS_MODE_JSON (mode)) { pj_ki (pj, "cnt", cnt); } else { - r_cons_printf (" Cnt: %d\n", cnt); + rz_cons_printf (" Cnt: %d\n", cnt); } if (IS_MODE_JSON (mode)) { pj_ka (pj, "vernaux"); @@ -3990,8 +3990,8 @@ static void bin_elf_versioninfo(RCore *r, int mode) { pj_ki (pj, "version", version); pj_end (pj); } else { - r_cons_printf (" 0x%08"PFMT64x": Name: %s", idx, name); - r_cons_printf (" Flags: %s Version: %d\n", flags, version); + rz_cons_printf (" 0x%08"PFMT64x": Name: %s", idx, name); + rz_cons_printf (" Flags: %s Version: %d\n", flags, version); } } while (sdb); if (IS_MODE_JSON (mode)) { @@ -4008,16 +4008,16 @@ static void bin_elf_versioninfo(RCore *r, int mode) { if (IS_MODE_JSON (mode)) { pj_end (pj); pj_end (pj); - r_cons_print (pj_string (pj)); + rz_cons_print (pj_string (pj)); pj_free (pj); } } -static void bin_mach0_versioninfo(RCore *r) { +static void bin_mach0_versioninfo(RzCore *r) { /* TODO */ } -static void bin_pe_resources(RCore *r, int mode) { +static void bin_pe_resources(RzCore *r, int mode) { Sdb *sdb = NULL; int index = 0; PJ *pj = NULL; @@ -4026,9 +4026,9 @@ static void bin_pe_resources(RCore *r, int mode) { return; } if (IS_MODE_SET (mode)) { - r_flag_space_set (r->flags, R_FLAGS_FS_RESOURCES); + rz_flag_space_set (r->flags, R_FLAGS_FS_RESOURCES); } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("fs resources\n"); + rz_cons_printf ("fs resources\n"); } else if (IS_MODE_JSON (mode)) { pj = pj_new (); pj_a (pj); @@ -4052,9 +4052,9 @@ static void bin_pe_resources(RCore *r, int mode) { if (IS_MODE_SET (mode)) { const char *name = sdb_fmt ("resource.%d", index); - r_flag_set (r->flags, name, vaddr, size); + rz_flag_set (r->flags, name, vaddr, size); } else if (IS_MODE_RAD (mode)) { - r_cons_printf ("f resource.%d %d 0x%08"PFMT32x"\n", index, size, vaddr); + rz_cons_printf ("f resource.%d %d 0x%08"PFMT32x"\n", index, size, vaddr); } else if (IS_MODE_JSON (mode)) { pj_o (pj); pj_ks (pj, "name", name); @@ -4067,14 +4067,14 @@ static void bin_pe_resources(RCore *r, int mode) { pj_end (pj); } else { char humansz[8]; - r_num_units (humansz, sizeof (humansz), size); - r_cons_printf ("Resource %d\n", index); - r_cons_printf (" name: %s\n", name); - r_cons_printf (" timestamp: %s\n", timestr); - r_cons_printf (" vaddr: 0x%08"PFMT64x"\n", vaddr); - r_cons_printf (" size: %s\n", humansz); - r_cons_printf (" type: %s\n", type); - r_cons_printf (" language: %s\n", lang); + rz_num_units (humansz, sizeof (humansz), size); + rz_cons_printf ("Resource %d\n", index); + rz_cons_printf (" name: %s\n", name); + rz_cons_printf (" timestamp: %s\n", timestr); + rz_cons_printf (" vaddr: 0x%08"PFMT64x"\n", vaddr); + rz_cons_printf (" size: %s\n", humansz); + rz_cons_printf (" type: %s\n", type); + rz_cons_printf (" language: %s\n", lang); } R_FREE (timestr); @@ -4086,21 +4086,21 @@ static void bin_pe_resources(RCore *r, int mode) { } if (IS_MODE_JSON (mode)) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } else if (IS_MODE_RAD (mode)) { - r_cons_println ("fs *"); + rz_cons_println ("fs *"); } } -static void bin_no_resources(RCore *r, int mode) { +static void bin_no_resources(RzCore *r, int mode) { if (IS_MODE_JSON (mode)) { - r_cons_printf ("[]"); + rz_cons_printf ("[]"); } } -static int bin_resources(RCore *r, int mode) { - const RBinInfo *info = r_bin_get_info (r->bin); +static int bin_resources(RzCore *r, int mode) { + const RBinInfo *info = rz_bin_get_info (r->bin); if (!info || !info->rclass) { return false; } @@ -4112,8 +4112,8 @@ static int bin_resources(RCore *r, int mode) { return true; } -static int bin_versioninfo(RCore *r, int mode) { - const RBinInfo *info = r_bin_get_info (r->bin); +static int bin_versioninfo(RzCore *r, int mode) { + const RBinInfo *info = rz_bin_get_info (r->bin); if (!info || !info->rclass) { return false; } @@ -4124,21 +4124,21 @@ static int bin_versioninfo(RCore *r, int mode) { } else if (!strncmp ("mach0", info->rclass, 5)) { bin_mach0_versioninfo (r); } else { - r_cons_println ("Unknown format"); + rz_cons_println ("Unknown format"); return false; } return true; } -static int bin_signature(RCore *r, int mode) { - RBinFile *cur = r_bin_cur (r->bin); - RBinPlugin *plg = r_bin_file_cur_plugin (cur); +static int bin_signature(RzCore *r, int mode) { + RBinFile *cur = rz_bin_cur (r->bin); + RBinPlugin *plg = rz_bin_file_cur_plugin (cur); if (plg && plg->signature) { const char *signature = plg->signature (cur, IS_MODE_JSON (mode)); if (IS_MODE_JSON (mode)) { - r_cons_printf ("{\"signature\":%s}\n", signature); + rz_cons_printf ("{\"signature\":%s}\n", signature); } else { - r_cons_println (signature); + rz_cons_println (signature); } free ((char*) signature); return true; @@ -4146,9 +4146,9 @@ static int bin_signature(RCore *r, int mode) { return false; } -static int bin_header(RCore *r, int mode) { - RBinFile *cur = r_bin_cur (r->bin); - RBinPlugin *plg = r_bin_file_cur_plugin (cur); +static int bin_header(RzCore *r, int mode) { + RBinFile *cur = rz_bin_cur (r->bin); + RBinPlugin *plg = rz_bin_file_cur_plugin (cur); if (plg && plg->header) { plg->header (cur); return true; @@ -4156,10 +4156,10 @@ static int bin_header(RCore *r, int mode) { return false; } -R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFilter *filter, const char *chksum) { +RZ_API int rz_core_bin_info(RzCore *core, int action, int mode, int va, RzCoreBinFilter *filter, const char *chksum) { int ret = true; const char *name = NULL; - ut64 at = UT64_MAX, loadaddr = r_bin_get_laddr (core->bin); + ut64 at = UT64_MAX, loadaddr = rz_bin_get_laddr (core->bin); if (filter && filter->offset) { at = filter->offset; } @@ -4170,8 +4170,8 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil // use our internal values for va va = va ? VA_TRUE : VA_FALSE; #if 0 - if (r_config_get_i (core->config, "anal.strings")) { - r_core_cmd0 (core, "aar"); + if (rz_config_get_i (core->config, "anal.strings")) { + rz_core_cmd0 (core, "aar"); } #endif if ((action & R_CORE_BIN_ACC_RAW_STRINGS)) { @@ -4189,7 +4189,7 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil ret &= bin_dwarf (core, mode); } if ((action & R_CORE_BIN_ACC_PDB)) { - ret &= r_core_pdb_info (core, core->bin->file, mode); + ret &= rz_core_pdb_info (core, core->bin->file, mode); } if ((action & R_CORE_BIN_ACC_SOURCE)) { ret &= bin_source (core, mode); @@ -4209,7 +4209,7 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil if ((action & R_CORE_BIN_ACC_SECTIONS_MAPPING)) { ret &= bin_map_sections_to_segments (core->bin, mode); } - if (r_config_get_i (core->config, "bin.relocs")) { + if (rz_config_get_i (core->config, "bin.relocs")) { if ((action & R_CORE_BIN_ACC_RELOCS)) { ret &= bin_relocs (core, mode, va); } @@ -4266,9 +4266,9 @@ R_API int r_core_bin_info(RCore *core, int action, int mode, int va, RCoreBinFil return ret; } -R_API int r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch, ut16 bits) { - int fd = r_io_fd_get_current (r->io); - RIODesc *desc = r_io_desc_get (r->io, fd); +RZ_API int rz_core_bin_set_arch_bits(RzCore *r, const char *name, const char * arch, ut16 bits) { + int fd = rz_io_fd_get_current (r->io); + RzIODesc *desc = rz_io_desc_get (r->io, fd); RBinFile *curfile, *binfile = NULL; if (!name) { if (!desc || !desc->name) { @@ -4277,27 +4277,27 @@ R_API int r_core_bin_set_arch_bits(RCore *r, const char *name, const char * arch name = desc->name; } /* Check if the arch name is a valid name */ - if (!r_asm_is_valid (r->rasm, arch)) { + if (!rz_asm_is_valid (r->rasm, arch)) { return false; } /* Find a file with the requested name/arch/bits */ - binfile = r_bin_file_find_by_arch_bits (r->bin, arch, bits); + binfile = rz_bin_file_find_by_arch_bits (r->bin, arch, bits); if (!binfile) { return false; } - if (!r_bin_use_arch (r->bin, arch, bits, name)) { + if (!rz_bin_use_arch (r->bin, arch, bits, name)) { return false; } - curfile = r_bin_cur (r->bin); + curfile = rz_bin_cur (r->bin); //set env if the binfile changed or we are dealing with xtr if (curfile != binfile || binfile->curxtr) { - r_core_bin_set_cur (r, binfile); - return r_core_bin_set_env (r, binfile); + rz_core_bin_set_cur (r, binfile); + return rz_core_bin_set_env (r, binfile); } return true; } -R_API int r_core_bin_update_arch_bits(RCore *r) { +RZ_API int rz_core_bin_update_arch_bits(RzCore *r) { RBinFile *binfile = NULL; const char *name = NULL, *arch = NULL; ut16 bits = 0; @@ -4310,44 +4310,44 @@ R_API int r_core_bin_update_arch_bits(RCore *r) { arch = r->rasm->cur->arch; } } - binfile = r_bin_cur (r->bin); + binfile = rz_bin_cur (r->bin); name = binfile ? binfile->file : NULL; if (binfile && binfile->curxtr) { - r_anal_hint_clear (r->anal); + rz_anal_hint_clear (r->anal); } - return r_core_bin_set_arch_bits (r, name, arch, bits); + return rz_core_bin_set_arch_bits (r, name, arch, bits); } -R_API bool r_core_bin_raise(RCore *core, ut32 bfid) { - if (!r_bin_select_bfid (core->bin, bfid)) { +RZ_API bool rz_core_bin_raise(RzCore *core, ut32 bfid) { + if (!rz_bin_select_bfid (core->bin, bfid)) { return false; } - RBinFile *bf = r_bin_cur (core->bin); + RBinFile *bf = rz_bin_cur (core->bin); if (bf) { - r_io_use_fd (core->io, bf->fd); + rz_io_use_fd (core->io, bf->fd); } - // it should be 0 to use r_io_use_fd in r_core_block_read + // it should be 0 to use rz_io_use_fd in rz_core_block_read core->switch_file_view = 0; - return bf && r_core_bin_set_env (core, bf) && r_core_block_read (core); + return bf && rz_core_bin_set_env (core, bf) && rz_core_block_read (core); } -R_API bool r_core_bin_delete(RCore *core, ut32 bf_id) { +RZ_API bool rz_core_bin_delete(RzCore *core, ut32 bf_id) { if (bf_id == UT32_MAX) { return false; } - r_bin_file_delete (core->bin, bf_id); - RBinFile *bf = r_bin_file_at (core->bin, core->offset); + rz_bin_file_delete (core->bin, bf_id); + RBinFile *bf = rz_bin_file_at (core->bin, core->offset); if (bf) { - r_io_use_fd (core->io, bf->fd); + rz_io_use_fd (core->io, bf->fd); } core->switch_file_view = 0; - return bf && r_core_bin_set_env (core, bf) && r_core_block_read (core); + return bf && rz_core_bin_set_env (core, bf) && rz_core_block_read (core); } -static bool r_core_bin_file_print(RCore *core, RBinFile *bf, int mode) { - r_return_val_if_fail (core && bf && bf->o, NULL); +static bool rz_core_bin_file_print(RzCore *core, RBinFile *bf, int mode) { + rz_return_val_if_fail (core && bf && bf->o, NULL); const char *name = bf ? bf->file : NULL; - (void)r_bin_get_info (core->bin); // XXX is this necssary for proper iniitialization + (void)rz_bin_get_info (core->bin); // XXX is this necssary for proper iniitialization ut32 bin_sz = bf ? bf->size : 0; // TODO: handle mode to print in json and r2 commands @@ -4355,37 +4355,37 @@ static bool r_core_bin_file_print(RCore *core, RBinFile *bf, int mode) { case '*': { char *n = __filterShell (name); - r_cons_printf ("oba 0x%08"PFMT64x" %s # %d\n", bf->o->boffset, n, bf->id); + rz_cons_printf ("oba 0x%08"PFMT64x" %s # %d\n", bf->o->boffset, n, bf->id); free (n); } break; case 'q': - r_cons_printf ("%d\n", bf->id); + rz_cons_printf ("%d\n", bf->id); break; case 'j': // XXX there's only one binobj for each bf...so we should change that json // TODO: use pj API - r_cons_printf ("{\"name\":\"%s\",\"iofd\":%d,\"bfid\":%d,\"size\":%d,\"objs\":[", + rz_cons_printf ("{\"name\":\"%s\",\"iofd\":%d,\"bfid\":%d,\"size\":%d,\"objs\":[", name? name: "", bf->fd, bf->id, bin_sz); { RBinObject *obj = bf->o; RBinInfo *info = obj->info; ut8 bits = info ? info->bits : 0; - const char *asmarch = r_config_get (core->config, "asm.arch"); + const char *asmarch = rz_config_get (core->config, "asm.arch"); const char *arch = info ? info->arch ? info->arch: asmarch : "unknown"; - r_cons_printf ("{\"arch\":\"%s\",\"bits\":%d,\"binoffset\":%" + rz_cons_printf ("{\"arch\":\"%s\",\"bits\":%d,\"binoffset\":%" PFMT64d",\"objsize\":%"PFMT64d"}", arch, bits, obj->boffset, obj->obj_size); } - r_cons_print ("]}"); + rz_cons_print ("]}"); break; default: { RBinInfo *info = bf->o->info; ut8 bits = info ? info->bits : 0; - const char *asmarch = r_config_get (core->config, "asm.arch"); + const char *asmarch = rz_config_get (core->config, "asm.arch"); const char *arch = info ? info->arch ? info->arch: asmarch: "unknown"; - r_cons_printf ("%d %d %s-%d ba:0x%08"PFMT64x" sz:%"PFMT64d" %s\n", + rz_cons_printf ("%d %d %s-%d ba:0x%08"PFMT64x" sz:%"PFMT64d" %s\n", bf->id, bf->fd, arch, bits, bf->o->baddr, bf->o->size, name); } break; @@ -4393,35 +4393,35 @@ static bool r_core_bin_file_print(RCore *core, RBinFile *bf, int mode) { return true; } -R_API int r_core_bin_list(RCore *core, int mode) { +RZ_API int rz_core_bin_list(RzCore *core, int mode) { // list all binfiles and there objects and there archs int count = 0; - RListIter *iter; - RBinFile *binfile = NULL; //, *cur_bf = r_bin_cur (core->bin) ; + RzListIter *iter; + RBinFile *binfile = NULL; //, *cur_bf = rz_bin_cur (core->bin) ; RBin *bin = core->bin; - const RList *binfiles = bin ? bin->binfiles: NULL; + const RzList *binfiles = bin ? bin->binfiles: NULL; if (!binfiles) { return false; } if (mode == 'j') { - r_cons_print ("["); + rz_cons_print ("["); } - r_list_foreach (binfiles, iter, binfile) { - r_core_bin_file_print (core, binfile, mode); + rz_list_foreach (binfiles, iter, binfile) { + rz_core_bin_file_print (core, binfile, mode); if (iter->n && mode == 'j') { - r_cons_print (","); + rz_cons_print (","); } } if (mode == 'j') { - r_cons_println ("]"); + rz_cons_println ("]"); } return count; } -R_API char *r_core_bin_method_flags_str(ut64 flags, int mode) { +RZ_API char *rz_core_bin_method_flags_str(ut64 flags, int mode) { int i, len = 0; - RStrBuf *buf = r_strbuf_new (""); + RStrBuf *buf = rz_strbuf_new (""); if (IS_MODE_SET (mode) || IS_MODE_RAD (mode)) { if (!flags) { goto out; @@ -4430,37 +4430,37 @@ R_API char *r_core_bin_method_flags_str(ut64 flags, int mode) { for (i = 0; i < 64; i++) { ut64 flag = flags & (1ULL << i); if (flag) { - const char *flag_string = r_bin_get_meth_flag_string (flag, false); + const char *flag_string = rz_bin_get_meth_flag_string (flag, false); if (flag_string) { - r_strbuf_appendf (buf, ".%s", flag_string); + rz_strbuf_appendf (buf, ".%s", flag_string); } } } } else if (IS_MODE_JSON (mode)) { if (!flags) { - r_strbuf_append (buf, "[]"); + rz_strbuf_append (buf, "[]"); goto out; } - r_strbuf_append (buf, "["); + rz_strbuf_append (buf, "["); for (i = 0; i < 64; i++) { ut64 flag = flags & (1ULL << i); if (flag) { - const char *flag_string = r_bin_get_meth_flag_string (flag, false); + const char *flag_string = rz_bin_get_meth_flag_string (flag, false); if (len != 0) { - r_strbuf_append (buf, ","); + rz_strbuf_append (buf, ","); } if (flag_string) { - r_strbuf_appendf (buf, "\"%s\"", flag_string); + rz_strbuf_appendf (buf, "\"%s\"", flag_string); } else { - r_strbuf_appendf (buf, "\"0x%08"PFMT64x"\"", flag); + rz_strbuf_appendf (buf, "\"0x%08"PFMT64x"\"", flag); } len++; } } - r_strbuf_append (buf, "]"); + rz_strbuf_append (buf, "]"); } else { int pad_len = 4; //TODO: move to a config variable @@ -4470,20 +4470,20 @@ R_API char *r_core_bin_method_flags_str(ut64 flags, int mode) { for (i = 0; i < 64; i++) { ut64 flag = flags & (1ULL << i); if (flag) { - const char *flag_string = r_bin_get_meth_flag_string (flag, true); + const char *flag_string = rz_bin_get_meth_flag_string (flag, true); if (flag_string) { - r_strbuf_append (buf, flag_string); + rz_strbuf_append (buf, flag_string); } else { - r_strbuf_append (buf, "?"); + rz_strbuf_append (buf, "?"); } len++; } } padding: for ( ; len < pad_len; len++) { - r_strbuf_append (buf, " "); + rz_strbuf_append (buf, " "); } } out: - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } diff --git a/libr/core/cconfig.c b/librz/core/cconfig.c similarity index 81% rename from libr/core/cconfig.c rename to librz/core/cconfig.c index 6e75455c64..c557308bf7 100644 --- a/libr/core/cconfig.c +++ b/librz/core/cconfig.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include -#define NODECB(w,x,y) r_config_set_cb (cfg,w,x,y) -#define NODEICB(w,x,y) r_config_set_i_cb (cfg,w,x,y) -#define SETDESC(x,y) r_config_node_desc (x,y) +#define NODECB(w,x,y) rz_config_set_cb (cfg,w,x,y) +#define NODEICB(w,x,y) rz_config_set_i_cb (cfg,w,x,y) +#define SETDESC(x,y) rz_config_node_desc (x,y) #define SETOPTIONS(x, ...) set_options (x, __VA_ARGS__) -#define SETI(x,y,z) SETDESC (r_config_set_i (cfg,x,y), z) +#define SETI(x,y,z) SETDESC (rz_config_set_i (cfg,x,y), z) #define SETICB(w,x,y,z) SETDESC (NODEICB (w,x,y), z) -#define SETPREF(x,y,z) SETDESC (r_config_set (cfg,x,y), z) +#define SETPREF(x,y,z) SETDESC (rz_config_set (cfg,x,y), z) #define SETCB(w,x,y,z) SETDESC (NODECB (w,x,y), z) #define SETBPREF(x,y,z) SETDESC (NODECB (x,y,boolify_var_cb), z) static bool boolify_var_cb(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - if (node->i_value || r_str_is_false (node->value)) { + if (node->i_value || rz_str_is_false (node->value)) { free (node->value); - node->value = strdup (r_str_bool (node->i_value)); + node->value = strdup (rz_str_bool (node->i_value)); } return true; } @@ -27,13 +27,13 @@ static void set_options(RConfigNode *node, ...) { va_start (argp, node); option = va_arg (argp, char *); while (option) { - r_list_append (node->options, option); + rz_list_append (node->options, option); option = va_arg (argp, char *); } va_end (argp); } -static bool isGdbPlugin(RCore *core) { +static bool isGdbPlugin(RzCore *core) { if (core->io && core->io->desc && core->io->desc->plugin) { if (core->io->desc->plugin->name && !strcmp (core->io->desc->plugin->name, "gdb")) { return true; @@ -43,18 +43,18 @@ static bool isGdbPlugin(RCore *core) { } static void print_node_options(RConfigNode *node) { - RListIter *iter; + RzListIter *iter; char *option; - r_list_foreach (node->options, iter, option) { - r_cons_printf ("%s\n", option); + rz_list_foreach (node->options, iter, option) { + rz_cons_printf ("%s\n", option); } } -static int compareName(const RAnalFunction *a, const RAnalFunction *b) { +static int compareName(const RzAnalFunction *a, const RzAnalFunction *b) { return (a && b && a->name && b->name ? strcmp (a->name, b->name) : 0); } -static int compareNameLen(const RAnalFunction *a, const RAnalFunction *b) { +static int compareNameLen(const RzAnalFunction *a, const RzAnalFunction *b) { size_t la, lb; if (!a || !b || !a->name || !b->name) { return 0; @@ -64,27 +64,27 @@ static int compareNameLen(const RAnalFunction *a, const RAnalFunction *b) { return (la > lb) - (la < lb); } -static int compareAddress(const RAnalFunction *a, const RAnalFunction *b) { +static int compareAddress(const RzAnalFunction *a, const RzAnalFunction *b) { return (a && b && a->addr && b->addr ? (a->addr > b->addr) - (a->addr < b->addr) : 0); } -static int compareType(const RAnalFunction *a, const RAnalFunction *b) { +static int compareType(const RzAnalFunction *a, const RzAnalFunction *b) { return (a && b && a->diff->type && b->diff->type ? (a->diff->type > b->diff->type) - (a->diff->type < b->diff->type) : 0); } -static int compareSize(const RAnalFunction *a, const RAnalFunction *b) { +static int compareSize(const RzAnalFunction *a, const RzAnalFunction *b) { ut64 sa, sb; // return a && b && a->_size < b->_size; if (!a || !b) { return 0; } - sa = r_anal_function_realsize (a); - sb = r_anal_function_realsize (b); + sa = rz_anal_function_realsize (a); + sb = rz_anal_function_realsize (b); return (sa > sb) - (sa < sb); } -static int compareDist(const RAnalFunction *a, const RAnalFunction *b) { +static int compareDist(const RzAnalFunction *a, const RzAnalFunction *b) { return (a && b && a->diff->dist && b->diff->dist ? (a->diff->dist > b->diff->dist) - (a->diff->dist < b->diff->dist) : 0); } @@ -92,20 +92,20 @@ static int compareDist(const RAnalFunction *a, const RAnalFunction *b) { static bool cb_diff_sort(void *_core, void *_node) { RConfigNode *node = _node; const char *column = node->value; - RCore *core = _core; + RzCore *core = _core; if (column && strcmp (column, "?")) { if (!strcmp (column, "name")) { - core->anal->columnSort = (RListComparator)compareName; + core->anal->columnSort = (RzListComparator)compareName; } else if (!strcmp (column, "namelen")) { - core->anal->columnSort = (RListComparator)compareNameLen; + core->anal->columnSort = (RzListComparator)compareNameLen; } else if (!strcmp (column, "addr")) { - core->anal->columnSort = (RListComparator)compareAddress; + core->anal->columnSort = (RzListComparator)compareAddress; } else if (!strcmp (column, "type")) { - core->anal->columnSort = (RListComparator)compareType; + core->anal->columnSort = (RzListComparator)compareType; } else if (!strcmp (column, "size")) { - core->anal->columnSort = (RListComparator)compareSize; + core->anal->columnSort = (RzListComparator)compareSize; } else if (!strcmp (column, "dist")) { - core->anal->columnSort = (RListComparator)compareDist; + core->anal->columnSort = (RzListComparator)compareDist; } else { goto fail; } @@ -116,11 +116,11 @@ fail: return false; } -static const char *has_esil(RCore *core, const char *name) { - RListIter *iter; - RAnalPlugin *h; - r_return_val_if_fail (core && core->anal && name, NULL); - r_list_foreach (core->anal->plugins, iter, h) { +static const char *has_esil(RzCore *core, const char *name) { + RzListIter *iter; + RzAnalPlugin *h; + rz_return_val_if_fail (core && core->anal && name, NULL); + rz_list_foreach (core->anal->plugins, iter, h) { if (h->name && !strcmp (name, h->name)) { return h->esil? "Ae": "A_"; } @@ -128,14 +128,14 @@ static const char *has_esil(RCore *core, const char *name) { return "__"; } -// copypasta from binr/rasm2/rasm2.c -static void rasm2_list(RCore *core, const char *arch, int fmt) { +// copypasta from binrz/rz_asm/rz_asm.c +static void rz_asm_list(RzCore *core, const char *arch, int fmt) { int i; const char *feat2, *feat; - RAsm *a = core->rasm; + RzAsm *a = core->rasm; char bits[32]; - RAsmPlugin *h; - RListIter *iter; + RzAsmPlugin *h; + RzListIter *iter; PJ *pj = NULL; if (fmt == 'j') { pj = pj_new (); @@ -144,13 +144,13 @@ static void rasm2_list(RCore *core, const char *arch, int fmt) { } pj_o (pj); } - r_list_foreach (a->plugins, iter, h) { + rz_list_foreach (a->plugins, iter, h) { if (arch && *arch) { if (h->cpus && !strcmp (arch, h->name)) { char *c = strdup (h->cpus); - int n = r_str_split (c, ','); + int n = rz_str_split (c, ','); for (i = 0; i < n; i++) { - r_cons_println (r_str_word_get0 (c, i)); + rz_cons_println (rz_str_word_get0 (c, i)); } free (c); break; @@ -186,7 +186,7 @@ static void rasm2_list(RCore *core, const char *arch, int fmt) { } feat2 = has_esil (core, h->name); if (fmt == 'q') { - r_cons_println (h->name); + rz_cons_println (h->name); } else if (fmt == 'j') { const char *license = "GPL"; pj_k (pj, h->name); @@ -201,7 +201,7 @@ static void rasm2_list(RCore *core, const char *arch, int fmt) { pj_ks (pj, "features", feat); pj_end (pj); } else { - r_cons_printf ("%s%s %-9s %-11s %-7s %s\n", + rz_cons_printf ("%s%s %-9s %-11s %-7s %s\n", feat, feat2, bits, h->name, h->license?h->license:"unknown", h->desc); } @@ -209,163 +209,163 @@ static void rasm2_list(RCore *core, const char *arch, int fmt) { } if (fmt == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } } static inline void __setsegoff(RConfig *cfg, const char *asmarch, int asmbits) { int autoseg = (!strncmp (asmarch, "x86", 3) && asmbits == 16); - r_config_set (cfg, "asm.segoff", r_str_bool (autoseg)); + rz_config_set (cfg, "asm.segoff", rz_str_bool (autoseg)); } static bool cb_debug_hitinfo(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->dbg->hitinfo = node->i_value; return true; } static bool cb_anal_jmpretpoline(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.retpoline = node->i_value; return true; } static bool cb_anal_jmptailcall(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.tailcall = node->i_value; return true; } static bool cb_analarmthumb(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.armthumb = node->i_value; return true; } static bool cb_analdepth(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.depth = node->i_value; return true; } static bool cb_analgraphdepth(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; core->anal->opt.graph_depth = node->i_value; return true; } static bool cb_analafterjmp(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.afterjmp = node->i_value; return true; } static bool cb_anal_delay(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.delay = node->i_value; return true; } static bool cb_anal_endsize(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.endsize = node->i_value; return true; } static bool cb_analvars(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.vars = node->i_value; return true; } static bool cb_analvars_stackname(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; core->anal->opt.varname_stack = node->i_value; return true; } static bool cb_anal_nonull(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.nonull = node->i_value; return true; } static bool cb_analstrings(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->i_value) { - r_config_set (core->config, "bin.strings", "false"); + rz_config_set (core->config, "bin.strings", "false"); } return true; } static bool cb_anal_ignbithints(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.ignbithints = node->i_value; return true; } static bool cb_analsleep(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->sleep = node->i_value; return true; } static bool cb_analmaxrefs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->maxreflines = node->i_value; return true; } static bool cb_analnorevisit(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.norevisit = node->i_value; return true; } static bool cb_analnopskip(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.nopskip = node->i_value; return true; } static bool cb_analhpskip(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.hpskip = node->i_value; return true; } -static void update_analarch_options(RCore *core, RConfigNode *node) { - RAnalPlugin *h; - RListIter *it; +static void update_analarch_options(RzCore *core, RConfigNode *node) { + RzAnalPlugin *h; + RzListIter *it; if (core && core->anal && node) { - r_list_purge (node->options); - r_list_foreach (core->anal->plugins, it, h) { + rz_list_purge (node->options); + rz_list_foreach (core->anal->plugins, it, h) { SETOPTIONS (node, h->name, NULL); } } } static bool cb_analarch(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { update_analarch_options (core, node); @@ -373,14 +373,14 @@ static bool cb_analarch(void *user, void *data) { return false; } if (*node->value) { - if (r_anal_use (core->anal, node->value)) { + if (rz_anal_use (core->anal, node->value)) { return true; } - const char *aa = r_config_get (core->config, "asm.arch"); + const char *aa = rz_config_get (core->config, "asm.arch"); if (!aa || strcmp (aa, node->value)) { eprintf ("anal.arch: cannot find '%s'\n", node->value); } else { - r_config_set (core->config, "anal.arch", "null"); + rz_config_set (core->config, "anal.arch", "null"); return true; } } @@ -388,40 +388,40 @@ static bool cb_analarch(void *user, void *data) { } static bool cb_analcpu(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; - r_anal_set_cpu (core->anal, node->value); + rz_anal_set_cpu (core->anal, node->value); /* set pcalign */ { - int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - r_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0); + int v = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); + rz_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0); } return true; } static bool cb_analrecont(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.recont = node->i_value; return true; } static bool cb_analijmp(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.ijmp = node->i_value; return true; } static bool cb_asmsubvarmin(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->parser->minval = node->i_value; return true; } static bool cb_asmsubtail(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->parser->subtail = node->i_value; return true; @@ -429,101 +429,101 @@ static bool cb_asmsubtail(void *user, void *data) { static bool cb_scrlast(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->context->lastEnabled = node->i_value; + rz_cons_singleton ()->context->lastEnabled = node->i_value; return true; } static bool cb_scr_vi(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->line->enable_vi_mode = node->i_value; return true; } static bool cb_scr_prompt_mode(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->line->prompt_mode = node->i_value; return true; } static bool cb_scr_wideoff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->wide_offsets = node->i_value; return true; } static bool cb_scrrainbow(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_RAINBOW; - r_core_cmd0 (core, "ecr"); + rz_core_cmd0 (core, "ecr"); } else { core->print->flags &= (~R_PRINT_FLAGS_RAINBOW); - r_core_cmd0 (core, "ecoo"); + rz_core_cmd0 (core, "ecoo"); } - r_print_set_flags (core->print, core->print->flags); + rz_print_set_flags (core->print, core->print->flags); return true; } static bool cb_asmpseudo (void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->pseudo = node->i_value; return true; } static bool cb_asmsubsec(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_SECSUB; } else { core->print->flags &= (~R_PRINT_FLAGS_SECSUB); } - r_print_set_flags (core->print, core->print->flags); + rz_print_set_flags (core->print, core->print->flags); return true; } static bool cb_asmassembler(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; - r_asm_use_assembler (core->rasm, node->value); + rz_asm_use_assembler (core->rasm, node->value); return true; } -static void update_cmdpdc_options(RCore *core, RConfigNode *node) { - r_return_if_fail (core && core->rasm && node); - RListIter *iter; - r_list_purge (node->options); - char *opts = r_core_cmd_str (core, "e cmd.pdc=?"); - RList *optl = r_str_split_list (opts, "\n", 0); +static void update_cmdpdc_options(RzCore *core, RConfigNode *node) { + rz_return_if_fail (core && core->rasm && node); + RzListIter *iter; + rz_list_purge (node->options); + char *opts = rz_core_cmd_str (core, "e cmd.pdc=?"); + RzList *optl = rz_str_split_list (opts, "\n", 0); char *opt; node->options->free = free; - r_list_foreach (optl, iter, opt) { + rz_list_foreach (optl, iter, opt) { SETOPTIONS (node, strdup (opt), NULL); } - r_list_free (optl); + rz_list_free (optl); free (opts); } -static void update_asmcpu_options(RCore *core, RConfigNode *node) { - RAsmPlugin *h; - RListIter *iter; - r_return_if_fail (core && core->rasm); - const char *arch = r_config_get (core->config, "asm.arch"); +static void update_asmcpu_options(RzCore *core, RConfigNode *node) { + RzAsmPlugin *h; + RzListIter *iter; + rz_return_if_fail (core && core->rasm); + const char *arch = rz_config_get (core->config, "asm.arch"); if (!arch || !*arch) { return; } - r_list_purge (node->options); - r_list_foreach (core->rasm->plugins, iter, h) { + rz_list_purge (node->options); + rz_list_foreach (core->rasm->plugins, iter, h) { if (h->cpus && !strcmp (arch, h->name)) { char *c = strdup (h->cpus); - int i, n = r_str_split (c, ','); + int i, n = rz_str_split (c, ','); for (i = 0; i < n; i++) { - const char *word = r_str_word_get0 (c, i); + const char *word = rz_str_word_get0 (c, i); if (word && *word) { SETOPTIONS (node, strdup (word), NULL); } @@ -534,25 +534,25 @@ static void update_asmcpu_options(RCore *core, RConfigNode *node) { } static bool cb_asmcpu(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (*node->value == '?') { update_asmcpu_options (core, node); /* print verbose help instead of plain option listing */ - rasm2_list (core, r_config_get (core->config, "asm.arch"), node->value[1]); + rz_asm_list (core, rz_config_get (core->config, "asm.arch"), node->value[1]); return 0; } - r_asm_set_cpu (core->rasm, node->value); - r_config_set (core->config, "anal.cpu", node->value); + rz_asm_set_cpu (core->rasm, node->value); + rz_config_set (core->config, "anal.cpu", node->value); return true; } -static void update_asmarch_options(RCore *core, RConfigNode *node) { - RAsmPlugin *h; - RListIter *iter; +static void update_asmarch_options(RzCore *core, RConfigNode *node) { + RzAsmPlugin *h; + RzListIter *iter; if (core && node && core->rasm) { - r_list_purge (node->options); - r_list_foreach (core->rasm->plugins, iter, h) { + rz_list_purge (node->options); + rz_list_foreach (core->rasm->plugins, iter, h) { SETOPTIONS (node, h->name, NULL); } } @@ -560,14 +560,14 @@ static void update_asmarch_options(RCore *core, RConfigNode *node) { static bool cb_asmarch(void *user, void *data) { char asmparser[32]; - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; const char *asmos = NULL; int bits = R_SYS_BITS; if (!*node->value || !core || !core->rasm) { return false; } - asmos = r_config_get (core->config, "asm.os"); + asmos = rz_config_get (core->config, "asm.os"); if (core && core->anal && core->anal->bits) { bits = core->anal->bits; } @@ -575,22 +575,22 @@ static bool cb_asmarch(void *user, void *data) { update_asmarch_options (core, node); if (strlen (node->value) > 1 && node->value[1] == '?') { /* print more verbose help instead of plain option values */ - rasm2_list (core, NULL, node->value[1]); + rz_asm_list (core, NULL, node->value[1]); return false; } else { print_node_options (node); return false; } } - r_egg_setup (core->egg, node->value, bits, 0, R_SYS_OS); + rz_egg_setup (core->egg, node->value, bits, 0, R_SYS_OS); - if (!r_asm_use (core->rasm, node->value)) { + if (!rz_asm_use (core->rasm, node->value)) { eprintf ("asm.arch: cannot find (%s)\n", node->value); return false; } - //we should strdup here otherwise will crash if any r_config_set + //we should strdup here otherwise will crash if any rz_config_set //free the old value - char *asm_cpu = strdup (r_config_get (core->config, "asm.cpu")); + char *asm_cpu = strdup (rz_config_get (core->config, "asm.cpu")); if (core->rasm->cur) { const char *newAsmCPU = core->rasm->cur->cpus; if (newAsmCPU) { @@ -600,12 +600,12 @@ static bool cb_asmarch(void *user, void *data) { if (comma) { if (!*asm_cpu || (*asm_cpu && !strstr(nac, asm_cpu))) { *comma = 0; - r_config_set (core->config, "asm.cpu", nac); + rz_config_set (core->config, "asm.cpu", nac); } } free (nac); } else { - r_config_set (core->config, "asm.cpu", ""); + rz_config_set (core->config, "asm.cpu", ""); } } bits = core->rasm->cur->bits; @@ -620,63 +620,63 @@ static bool cb_asmarch(void *user, void *data) { } } snprintf (asmparser, sizeof (asmparser), "%s.pseudo", node->value); - r_config_set (core->config, "asm.parser", asmparser); + rz_config_set (core->config, "asm.parser", asmparser); if (core->rasm->cur && core->anal && !(core->rasm->cur->bits & core->anal->bits)) { - r_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "asm.bits", bits); } - //r_debug_set_arch (core->dbg, r_sys_arch_id (node->value), bits); - r_debug_set_arch (core->dbg, node->value, bits); - if (!r_config_set (core->config, "anal.arch", node->value)) { + //rz_debug_set_arch (core->dbg, rz_sys_arch_id (node->value), bits); + rz_debug_set_arch (core->dbg, node->value, bits); + if (!rz_config_set (core->config, "anal.arch", node->value)) { char *p, *s = strdup (node->value); if (s) { p = strchr (s, '.'); if (p) { *p = 0; } - if (!r_config_set (core->config, "anal.arch", s)) { + if (!rz_config_set (core->config, "anal.arch", s)) { /* fall back to the anal.null plugin */ - r_config_set (core->config, "anal.arch", "null"); + rz_config_set (core->config, "anal.arch", "null"); } free (s); } } // set pcalign if (core->anal) { - const char *asmcpu = r_config_get (core->config, "asm.cpu"); - if (!r_syscall_setup (core->anal->syscall, node->value, core->anal->bits, asmcpu, asmos)) { + const char *asmcpu = rz_config_get (core->config, "asm.cpu"); + if (!rz_syscall_setup (core->anal->syscall, node->value, core->anal->bits, asmcpu, asmos)) { //eprintf ("asm.arch: Cannot setup syscall '%s/%s' from '%s'\n", - // node->value, asmos, R2_LIBDIR"/radare2/"R2_VERSION"/syscall"); + // node->value, asmos, R2_LIBDIR"/rizin/"R2_VERSION"/syscall"); } } //if (!strcmp (node->value, "bf")) - // r_config_set (core->config, "dbg.backend", "bf"); + // rz_config_set (core->config, "dbg.backend", "bf"); __setsegoff (core->config, node->value, core->rasm->bits); // set a default endianness - int bigbin = r_bin_is_big_endian (core->bin); + int bigbin = rz_bin_is_big_endian (core->bin); if (bigbin == -1 /* error: no endianness detected in binary */) { - bigbin = r_config_get_i (core->config, "cfg.bigendian"); + bigbin = rz_config_get_i (core->config, "cfg.bigendian"); } - // try to set endian of RAsm to match binary - r_asm_set_big_endian (core->rasm, bigbin); + // try to set endian of RzAsm to match binary + rz_asm_set_big_endian (core->rasm, bigbin); // set endian of display to match binary core->print->big_endian = bigbin; - r_asm_set_cpu (core->rasm, asm_cpu); + rz_asm_set_cpu (core->rasm, asm_cpu); free (asm_cpu); - RConfigNode *asmcpu = r_config_node_get (core->config, "asm.cpu"); + RConfigNode *asmcpu = rz_config_node_get (core->config, "asm.cpu"); if (asmcpu) { update_asmcpu_options (core, asmcpu); } { - int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); + int v = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); if (v != -1) { - r_config_set_i (core->config, "asm.pcalign", v); + rz_config_set_i (core->config, "asm.pcalign", v); } else { - r_config_set_i (core->config, "asm.pcalign", 0); + rz_config_set_i (core->config, "asm.pcalign", 0); } } /* reload types and cc info */ @@ -685,29 +685,29 @@ static bool cb_asmarch(void *user, void *data) { // so ressetting is redundant and may lead to bugs // 1 case this is usefull is when sdb_types is null if (!core->anal || !core->anal->sdb_types) { - r_core_anal_type_init (core); + rz_core_anal_type_init (core); } - r_core_anal_cc_init (core); + rz_core_anal_cc_init (core); return true; } static bool cb_dbgbpsize(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->bpsize = node->i_value; return true; } static bool cb_dbgbtdepth(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->btdepth = node->i_value; return true; } static bool cb_asmbits(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; bool ret = false; if (!core) { @@ -724,16 +724,16 @@ static bool cb_asmbits(void *user, void *data) { } #endif if (bits > 0) { - ret = r_asm_set_bits (core->rasm, bits); + ret = rz_asm_set_bits (core->rasm, bits); if (!ret) { - RAsmPlugin *h = core->rasm->cur; + RzAsmPlugin *h = core->rasm->cur; if (!h) { eprintf ("e asm.bits: Cannot set value, no plugins defined yet\n"); ret = true; } // else { eprintf ("Cannot set bits %d to '%s'\n", bits, h->name); } } - if (!r_anal_set_bits (core->anal, bits)) { + if (!rz_anal_set_bits (core->anal, bits)) { eprintf ("asm.arch: Cannot setup '%d' bits analysis engine\n", bits); } else { ret = true; @@ -741,8 +741,8 @@ static bool cb_asmbits(void *user, void *data) { core->print->bits = bits; } if (core->dbg && core->anal && core->anal->cur) { - r_debug_set_arch (core->dbg, core->anal->cur->arch, bits); - bool load_from_debug = r_config_get_i (core->config, "cfg.debug"); + rz_debug_set_arch (core->dbg, core->anal->cur->arch, bits); + bool load_from_debug = rz_config_get_i (core->config, "cfg.debug"); if (load_from_debug) { if (core->dbg->h && core->dbg->h->reg_profile) { // XXX. that should depend on the plugin, not the host os @@ -754,47 +754,47 @@ static bool cb_asmbits(void *user, void *data) { #endif #endif char *rp = core->dbg->h->reg_profile (core->dbg); - r_reg_set_profile_string (core->dbg->reg, rp); - r_reg_set_profile_string (core->anal->reg, rp); + rz_reg_set_profile_string (core->dbg->reg, rp); + rz_reg_set_profile_string (core->anal->reg, rp); free (rp); } } else { - (void)r_anal_set_reg_profile (core->anal); + (void)rz_anal_set_reg_profile (core->anal); } } - r_core_anal_cc_init (core); - const char *asmos = r_config_get (core->config, "asm.os"); - const char *asmarch = r_config_get (core->config, "asm.arch"); - const char *asmcpu = r_config_get (core->config, "asm.cpu"); + rz_core_anal_cc_init (core); + const char *asmos = rz_config_get (core->config, "asm.os"); + const char *asmarch = rz_config_get (core->config, "asm.arch"); + const char *asmcpu = rz_config_get (core->config, "asm.cpu"); if (core->anal) { - if (!r_syscall_setup (core->anal->syscall, asmarch, bits, asmcpu, asmos)) { + if (!rz_syscall_setup (core->anal->syscall, asmarch, bits, asmcpu, asmos)) { //eprintf ("asm.arch: Cannot setup syscall '%s/%s' from '%s'\n", - // node->value, asmos, R2_LIBDIR"/radare2/"R2_VERSION"/syscall"); + // node->value, asmos, R2_LIBDIR"/rizin/"R2_VERSION"/syscall"); } __setsegoff (core->config, asmarch, core->anal->bits); if (core->dbg) { - r_bp_use (core->dbg->bp, asmarch, core->anal->bits); - r_config_set_i (core->config, "dbg.bpsize", r_bp_size (core->dbg->bp)); + rz_bp_use (core->dbg->bp, asmarch, core->anal->bits); + rz_config_set_i (core->config, "dbg.bpsize", rz_bp_size (core->dbg->bp)); } /* set pcalign */ - int v = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - r_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0); + int v = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); + rz_config_set_i (core->config, "asm.pcalign", (v != -1)? v: 0); } return ret; } -static void update_asmfeatures_options(RCore *core, RConfigNode *node) { +static void update_asmfeatures_options(RzCore *core, RConfigNode *node) { int i, argc; if (core && core->rasm && core->rasm->cur) { if (core->rasm->cur->features) { char *features = strdup (core->rasm->cur->features); - argc = r_str_split (features, ','); + argc = rz_str_split (features, ','); for (i = 0; i < argc; i++) { node->options->free = free; - const char *feature = r_str_word_get0 (features, i); + const char *feature = rz_str_word_get0 (features, i); if (feature) { - r_list_append (node->options, strdup (feature)); + rz_list_append (node->options, strdup (feature)); } } free (features); @@ -803,14 +803,14 @@ static void update_asmfeatures_options(RCore *core, RConfigNode *node) { } static bool cb_flag_realnames(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->flags->realnames = node->i_value; return true; } static bool cb_asmfeatures(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (*node->value == '?') { update_asmfeatures_options (core, node); @@ -825,17 +825,17 @@ static bool cb_asmfeatures(void *user, void *data) { } static bool cb_asmlineswidth(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->anal->lineswidth = node->i_value; return true; } static bool cb_emustr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { - r_config_set (core->config, "asm.emu", "true"); + rz_config_set (core->config, "asm.emu", "true"); } return true; } @@ -844,7 +844,7 @@ static bool cb_emuskip(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { if (strlen (node->value) > 1 && node->value[1] == '?') { - r_cons_printf ("Concatenation of meta types encoded as characters:\n" \ + rz_cons_printf ("Concatenation of meta types encoded as characters:\n" \ "'d': data\n'c': code\n's': string\n'f': format\n'm': magic\n" \ "'h': hide\n'C': comment\n'r': run\n" \ "(default is 'ds' to skip data and strings)\n"); @@ -857,21 +857,21 @@ static bool cb_emuskip(void *user, void *data) { } static bool cb_asm_armimm(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->immdisp = node->i_value ? true : false; return true; } static bool cb_asm_invhex(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->invhex = node->i_value; return true; } static bool cb_asm_pcalign(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; int align = node->i_value; if (align < 0) { @@ -883,8 +883,8 @@ static bool cb_asm_pcalign(void *user, void *data) { } static bool cb_asmos(void *user, void *data) { - RCore *core = (RCore*) user; - int asmbits = r_config_get_i (core->config, "asm.bits"); + RzCore *core = (RzCore*) user; + int asmbits = rz_config_get_i (core->config, "asm.bits"); RConfigNode *asmarch, *node = (RConfigNode*) data; if (*node->value == '?') { @@ -895,21 +895,21 @@ static bool cb_asmos(void *user, void *data) { free (node->value); node->value = strdup (R_SYS_OS); } - asmarch = r_config_node_get (core->config, "asm.arch"); + asmarch = rz_config_node_get (core->config, "asm.arch"); if (asmarch) { - const char *asmcpu = r_config_get (core->config, "asm.cpu"); - r_syscall_setup (core->anal->syscall, asmarch->value, core->anal->bits, asmcpu, node->value); + const char *asmcpu = rz_config_get (core->config, "asm.cpu"); + rz_syscall_setup (core->anal->syscall, asmarch->value, core->anal->bits, asmcpu, node->value); __setsegoff (core->config, asmarch->value, asmbits); } - r_anal_set_os (core->anal, node->value); - r_core_anal_cc_init (core); + rz_anal_set_os (core->anal, node->value); + rz_core_anal_cc_init (core); return true; } static bool cb_asmparser(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; - return r_parse_use (core->parser, node->value); + return rz_parse_use (core->parser, node->value); } typedef struct { @@ -918,11 +918,11 @@ typedef struct { } namealiases_pair; static bool cb_binstrenc (void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode *)data; if (node->value[0] == '?') { print_node_options (node); - r_cons_printf (" -- if string's 2nd & 4th bytes are 0 then utf16le else " + rz_cons_printf (" -- if string's 2nd & 4th bytes are 0 then utf16le else " "if 2nd - 4th & 6th bytes are 0 & no char > 0x10ffff then utf32le else " "if utf8 char detected then utf8 else latin1\n"); return false; @@ -940,17 +940,17 @@ static bool cb_binstrenc (void *user, void *data) { if (!enc) { return false; } - r_str_case (enc, false); + rz_str_case (enc, false); for (i = 0; i < R_ARRAY_SIZE (names); i++) { const namealiases_pair *pair = &names[i]; - if (!strcmp (pair->name, enc) || r_str_cmp_list (pair->aliases, enc, ',')) { + if (!strcmp (pair->name, enc) || rz_str_cmp_list (pair->aliases, enc, ',')) { free (node->value); node->value = strdup (pair->name); free (enc); if (core->bin) { free (core->bin->strenc); core->bin->strenc = !strcmp (node->value, "guess") ? NULL : strdup (node->value); - r_bin_reset_strings (core->bin); + rz_bin_reset_strings (core->bin); } return true; } @@ -961,7 +961,7 @@ static bool cb_binstrenc (void *user, void *data) { } static bool cb_binfilter(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->bin->filter = node->i_value; return true; @@ -969,38 +969,38 @@ static bool cb_binfilter(void *user, void *data) { /* BinDemangleCmd */ static bool cb_bdc(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->bin->demanglercmd = node->i_value; return true; } static bool cb_useldr(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->bin->use_ldr = node->i_value; return true; } static bool cb_binat(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->binat = node->i_value; return true; } static bool cb_usextr(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->bin->use_xtr = node->i_value; return true; } static bool cb_strpurge(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { - r_cons_printf ( + rz_cons_printf ( "There can be multiple entries separated by commas. No whitespace before/after entries.\n" "Possible entries:\n" " all : purge all strings\n" @@ -1027,7 +1027,7 @@ static bool cb_strpurge(void *user, void *data) { static bool cb_maxname (void *user, void *data) { RConfigNode *node = (RConfigNode *)data; - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; core->parser->maxflagnamelen = node->i_value; return true; } @@ -1042,11 +1042,11 @@ static bool cb_midflags (void *user, void *data) { } static bool cb_strfilter(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->value[0] == '?') { if (strlen (node->value) > 1 && node->value[1] == '?') { - r_cons_printf ("Valid values for bin.str.filter:\n" + rz_cons_printf ("Valid values for bin.str.filter:\n" "a only alphanumeric printable\n" "8 only strings with utf8 chars\n" "p file/directory paths\n" @@ -1066,30 +1066,30 @@ static bool cb_strfilter(void *user, void *data) { } static bool cb_binforce(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; - r_bin_force_plugin (core->bin, node->value); + rz_bin_force_plugin (core->bin, node->value); return true; } static bool cb_asmsyntax(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { print_node_options (node); return false; } else { - int syntax = r_asm_syntax_from_string (node->value); + int syntax = rz_asm_syntax_from_string (node->value); if (syntax == -1) { return false; } - r_asm_set_syntax (core->rasm, syntax); + rz_asm_set_syntax (core->rasm, syntax); } return true; } static bool cb_dirzigns(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; free (core->anal->zign_path); core->anal->zign_path = strdup (node->value); @@ -1097,12 +1097,12 @@ static bool cb_dirzigns(void *user, void *data) { } static bool cb_bigendian(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; - // Try to set endian based on preference, restrict by RAsmPlugin - bool isbig = r_asm_set_big_endian (core->rasm, node->i_value); + // Try to set endian based on preference, restrict by RzAsmPlugin + bool isbig = rz_asm_set_big_endian (core->rasm, node->i_value); // Set anal endianness the same as asm - r_anal_set_big_endian (core->anal, isbig); + rz_anal_set_big_endian (core->anal, isbig); // the big endian should also be assigned to dbg->bp->endian if (core->dbg && core->dbg->bp) { core->dbg->bp->endian = isbig; @@ -1113,28 +1113,28 @@ static bool cb_bigendian(void *user, void *data) { } static bool cb_cfgdatefmt(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; snprintf (core->print->datefmt, 32, "%s", node->value); return true; } static bool cb_timezone(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->print->datezone = node->i_value; return true; } static bool cb_cfgcorelog(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cfglog = node->i_value; return true; } static bool cb_cfgdebug(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (!core) { return false; @@ -1143,21 +1143,21 @@ static bool cb_cfgdebug(void *user, void *data) { core->io->va = !node->i_value; } if (core->dbg && node->i_value) { - const char *dbgbackend = r_config_get (core->config, "dbg.backend"); + const char *dbgbackend = rz_config_get (core->config, "dbg.backend"); core->bin->is_debugger = true; - r_debug_use (core->dbg, dbgbackend); - if (!strcmp (r_config_get (core->config, "cmd.prompt"), "")) { - r_config_set (core->config, "cmd.prompt", ".dr*"); + rz_debug_use (core->dbg, dbgbackend); + if (!strcmp (rz_config_get (core->config, "cmd.prompt"), "")) { + rz_config_set (core->config, "cmd.prompt", ".dr*"); } if (!strcmp (dbgbackend, "bf")) { - r_config_set (core->config, "asm.arch", "bf"); + rz_config_set (core->config, "asm.arch", "bf"); } if (core->file) { - r_debug_select (core->dbg, r_io_fd_get_pid (core->io, core->file->fd), - r_io_fd_get_tid (core->io, core->file->fd)); + rz_debug_select (core->dbg, rz_io_fd_get_pid (core->io, core->file->fd), + rz_io_fd_get_tid (core->io, core->file->fd)); } } else { - r_debug_use (core->dbg, NULL); + rz_debug_use (core->dbg, NULL); core->bin->is_debugger = false; } return true; @@ -1166,7 +1166,7 @@ static bool cb_cfgdebug(void *user, void *data) { static bool cb_dirhome(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; if (node->value) { - r_sys_setenv (R_SYS_HOME, node->value); + rz_sys_setenv (R_SYS_HOME, node->value); } return true; } @@ -1174,13 +1174,13 @@ static bool cb_dirhome(void *user, void *data) { static bool cb_dirtmp(void *user, void *data) { RConfigNode *node = (RConfigNode *)data; char *value = R_STR_ISNOTEMPTY (node->value)? node->value: NULL; - r_sys_setenv (R_SYS_TMP, value); + rz_sys_setenv (R_SYS_TMP, value); return true; } static bool cb_dirsrc(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; free (core->bin->srcdir); core->bin->srcdir = strdup (node->value); return true; @@ -1188,7 +1188,7 @@ static bool cb_dirsrc(void *user, void *data) { static bool cb_cfgsanbox(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; - int ret = r_sandbox_enable (node->i_value); + int ret = rz_sandbox_enable (node->i_value); if (node->i_value != ret) { eprintf ("Cannot disable sandbox\n"); } @@ -1196,25 +1196,25 @@ static bool cb_cfgsanbox(void *user, void *data) { } static bool cb_str_escbslash(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->print->esc_bslash = node->i_value; return true; } static bool cb_completion_maxtab (void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->cons->line->completion.args_limit = node->i_value; return true; } static bool cb_cfg_fortunes(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; // TODO CN_BOOL option does not receive the right hand side of assignment as an argument if (node->value[0] == '?') { - r_core_fortune_list (core); + rz_core_fortune_list (core); return false; } return true; @@ -1223,40 +1223,40 @@ static bool cb_cfg_fortunes(void *user, void *data) { static bool cb_cfg_fortunes_type(void *user, void *data) { RConfigNode *node = (RConfigNode *)data; if (node->value[0] == '?') { - r_core_fortune_list_types (); + rz_core_fortune_list_types (); return false; } return true; } static void check_decompiler(const char* name) { - char *path = r_file_path (name); + char *path = rz_file_path (name); if (path && path[0] == '/') { - r_cons_printf ("!*%s\n", name); + rz_cons_printf ("!*%s\n", name); } free (path); } static bool cb_cmdpdc(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *)data; if (node->value[0] == '?') { - r_cons_printf ("pdc\n"); + rz_cons_printf ("pdc\n"); // spaguetti check_decompiler ("r2retdec"); - RListIter *iter; - RCorePlugin *cp; - r_list_foreach (core->rcmd->plist, iter, cp) { + RzListIter *iter; + RzCorePlugin *cp; + rz_list_foreach (core->rcmd->plist, iter, cp) { if (!strcmp (cp->name, "r2ghidra")) { - r_cons_printf ("pdg\n"); + rz_cons_printf ("pdg\n"); } } check_decompiler ("r2ghidra"); check_decompiler ("r2jadx"); check_decompiler ("r2snow"); - RConfigNode *r2dec = r_config_node_get (core->config, "r2dec.asm"); + RConfigNode *r2dec = rz_config_node_get (core->config, "r2dec.asm"); if (r2dec) { - r_cons_printf ("pdd\n"); + rz_cons_printf ("pdd\n"); } return false; } @@ -1264,7 +1264,7 @@ static bool cb_cmdpdc(void *user, void *data) { } static bool cb_cmdlog(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; R_FREE (core->cmdlog); core->cmdlog = strdup (node->value); @@ -1272,28 +1272,28 @@ static bool cb_cmdlog(void *user, void *data) { } static bool cb_cmdtimes(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cmdtimes = node->value; return true; } static bool cb_cmdrepeat(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cmdrepeat = node->i_value; return true; } static bool cb_scrnull(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->null = node->i_value; return true; } static bool cb_color(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_COLOR; @@ -1305,18 +1305,18 @@ static bool cb_color(void *user, void *data) { } else if (!strcmp (node->value, "false")) { node->i_value = 0; } - r_cons_singleton ()->context->color_mode = (node->i_value > COLOR_MODE_16M) + rz_cons_singleton ()->context->color_mode = (node->i_value > COLOR_MODE_16M) ? COLOR_MODE_16M: node->i_value; - r_cons_pal_update_event (); - r_print_set_flags (core->print, core->print->flags); + rz_cons_pal_update_event (); + rz_print_set_flags (core->print, core->print->flags); return true; } static bool cb_color_getter(void *user, RConfigNode *node) { (void)user; - node->i_value = r_cons_singleton ()->context->color_mode; + node->i_value = rz_cons_singleton ()->context->color_mode; char buf[128]; - r_config_node_value_format_i (buf, sizeof (buf), r_cons_singleton ()->context->color_mode, node); + rz_config_node_value_format_i (buf, sizeof (buf), rz_cons_singleton ()->context->color_mode, node); if (!node->value || strcmp (node->value, buf) != 0) { free (node->value); node->value = strdup (buf); @@ -1325,14 +1325,14 @@ static bool cb_color_getter(void *user, RConfigNode *node) { } static bool cb_decoff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_ADDRDEC; } else { core->print->flags &= (~R_PRINT_FLAGS_ADDRDEC); } - r_print_set_flags (core->print, core->print->flags); + rz_print_set_flags (core->print, core->print->flags); return true; } @@ -1346,7 +1346,7 @@ static bool cb_dbgbep(void *user, void *data) { } static bool cb_dbg_btalgo(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { print_node_options (node); @@ -1358,7 +1358,7 @@ static bool cb_dbg_btalgo(void *user, void *data) { } static bool cb_dbg_libs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; free (core->dbg->glob_libs); core->dbg->glob_libs = strdup (node->value); @@ -1366,7 +1366,7 @@ static bool cb_dbg_libs(void *user, void *data) { } static bool cb_dbg_unlibs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; free (core->dbg->glob_unlibs); core->dbg->glob_unlibs = strdup (node->value); @@ -1374,24 +1374,24 @@ static bool cb_dbg_unlibs(void *user, void *data) { } static bool cb_dbg_bpinmaps(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->bp->bpinmaps = node->i_value; return true; } static bool cb_dbg_forks(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->dbg->trace_forks = node->i_value; if (core->bin->is_debugger) { - r_debug_attach (core->dbg, core->dbg->pid); + rz_debug_attach (core->dbg, core->dbg->pid); } return true; } static bool cb_dbg_gdb_page_size(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->i_value < 64) { // 64 is hardcoded min packet size return false; @@ -1399,13 +1399,13 @@ static bool cb_dbg_gdb_page_size(void *user, void *data) { if (isGdbPlugin (core)) { char cmd[64]; snprintf (cmd, sizeof (cmd), "page_size %"PFMT64d, node->i_value); - free (r_io_system (core->io, cmd)); + free (rz_io_system (core->io, cmd)); } return true; } static bool cb_dbg_gdb_retries(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->i_value <= 0) { return false; @@ -1413,7 +1413,7 @@ static bool cb_dbg_gdb_retries(void *user, void *data) { if (isGdbPlugin (core)) { char cmd[64]; snprintf (cmd, sizeof (cmd), "retries %"PFMT64d, node->i_value); - free (r_io_system (core->io, cmd)); + free (rz_io_system (core->io, cmd)); } return true; } @@ -1421,10 +1421,10 @@ static bool cb_dbg_gdb_retries(void *user, void *data) { static bool cb_dbg_execs(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; #if __linux__ - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; core->dbg->trace_execs = node->i_value; if (core->bin->is_debugger) { - r_debug_attach (core->dbg, core->dbg->pid); + rz_debug_attach (core->dbg, core->dbg->pid); } #else if (node->i_value) { @@ -1435,41 +1435,41 @@ static bool cb_dbg_execs(void *user, void *data) { } static bool cb_dbg_clone(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->dbg->trace_clone = node->i_value; if (core->bin->is_debugger) { - r_debug_attach (core->dbg, core->dbg->pid); + rz_debug_attach (core->dbg, core->dbg->pid); } return true; } static bool cb_dbg_follow_child(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->dbg->follow_child = node->i_value; return true; } static bool cb_dbg_trace_continue(void *user, void *data) { - RCore *core = (RCore*)user; + RzCore *core = (RzCore*)user; RConfigNode *node = (RConfigNode*)data; core->dbg->trace_continue = node->i_value; return true; } static bool cb_dbg_aftersc(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->dbg->trace_aftersyscall = node->i_value; if (core->bin->is_debugger) { - r_debug_attach (core->dbg, core->dbg->pid); + rz_debug_attach (core->dbg, core->dbg->pid); } return true; } static bool cb_runprofile(void *user, void *data) { - RCore *r = (RCore*) user; + RzCore *r = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; free ((void*)r->io->runprofile); if (!node || !*(node->value)) { @@ -1481,7 +1481,7 @@ static bool cb_runprofile(void *user, void *data) { } static bool cb_dbg_args(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode*) data; if (!node || !*(node->value)) { core->io->args = NULL; @@ -1492,38 +1492,38 @@ static bool cb_dbg_args(void *user, void *data) { } static bool cb_dbgstatus(void *user, void *data) { - RCore *r = (RCore*) user; + RzCore *r = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; - if (r_config_get_i (r->config, "cfg.debug")) { + if (rz_config_get_i (r->config, "cfg.debug")) { if (node->i_value) { - r_config_set (r->config, "cmd.prompt", + rz_config_set (r->config, "cmd.prompt", ".dr*; drd; sr PC;pi 1;s-"); } else { - r_config_set (r->config, "cmd.prompt", ".dr*"); + rz_config_set (r->config, "cmd.prompt", ".dr*"); } } return true; } static bool cb_dbgbackend(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (!strcmp (node->value, "?")) { - r_debug_plugin_list (core->dbg, 'q'); + rz_debug_plugin_list (core->dbg, 'q'); return false; } if (!strcmp (node->value, "bf")) { // hack - r_config_set (core->config, "asm.arch", "bf"); + rz_config_set (core->config, "asm.arch", "bf"); } - r_debug_use (core->dbg, node->value); + rz_debug_use (core->dbg, node->value); return true; } static bool cb_gotolimit(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode*) data; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("Cannot change gotolimit\n"); return false; } @@ -1534,7 +1534,7 @@ static bool cb_gotolimit(void *user, void *data) { } static bool cb_esilverbose (void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode*) data; if (core->anal->esil) { core->anal->esil->verbose = node->i_value; @@ -1553,31 +1553,31 @@ static bool cb_esilstackdepth (void *user, void *data) { static bool cb_fixrows(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->fix_rows = (int)node->i_value; + rz_cons_singleton ()->fix_rows = (int)node->i_value; return true; } static bool cb_fixcolumns(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->fix_columns = atoi (node->value); + rz_cons_singleton ()->fix_columns = atoi (node->value); return true; } static bool cb_rows(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->force_rows = node->i_value; + rz_cons_singleton ()->force_rows = node->i_value; return true; } static bool cb_cmd_hexcursor(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->cfmt = node->value; return true; } static bool cb_hexcompact(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_COMPACT; @@ -1588,14 +1588,14 @@ static bool cb_hexcompact(void *user, void *data) { } static bool cb_hex_pairs(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->pairs = node->i_value; return true; } static bool cb_hex_section(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_SECTION; @@ -1606,7 +1606,7 @@ static bool cb_hex_section(void *user, void *data) { } static bool cb_hex_align(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_ALIGN; @@ -1617,7 +1617,7 @@ static bool cb_hex_align(void *user, void *data) { } static bool cb_io_unalloc(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_UNALLOC; @@ -1628,14 +1628,14 @@ static bool cb_io_unalloc(void *user, void *data) { } static bool cb_io_unalloc_ch(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->io_unalloc_ch = *node->value ? node->value[0] : ' '; return true; } static bool cb_hex_header(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_HEADER; @@ -1646,7 +1646,7 @@ static bool cb_hex_header(void *user, void *data) { } static bool cb_hex_bytes(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags &= ~R_PRINT_FLAGS_NONHEX; @@ -1657,7 +1657,7 @@ static bool cb_hex_bytes(void *user, void *data) { } static bool cb_hex_ascii(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags &= ~R_PRINT_FLAGS_NONASCII; @@ -1668,7 +1668,7 @@ static bool cb_hex_ascii(void *user, void *data) { } static bool cb_hex_style(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_STYLE; @@ -1679,7 +1679,7 @@ static bool cb_hex_style(void *user, void *data) { } static bool cb_hex_hdroff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_HDROFF; @@ -1690,14 +1690,14 @@ static bool cb_hex_hdroff(void *user, void *data) { } static bool cb_log_events (void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->log_events = node->i_value; return true; } static bool cb_hexcomments(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_COMMENT; @@ -1708,25 +1708,25 @@ static bool cb_hexcomments(void *user, void *data) { } static bool cb_iopcache(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if ((bool)node->i_value) { if (core) { - r_config_set_i (core->config, "io.pcache.read", true); - r_config_set_i (core->config, "io.pcache.write", true); + rz_config_set_i (core->config, "io.pcache.read", true); + rz_config_set_i (core->config, "io.pcache.write", true); } } else { if (core && core->io) { - r_io_desc_cache_fini_all (core->io); - r_config_set_i (core->config, "io.pcache.read", false); - r_config_set_i (core->config, "io.pcache.write", false); + rz_io_desc_cache_fini_all (core->io); + rz_config_set_i (core->config, "io.pcache.read", false); + rz_config_set_i (core->config, "io.pcache.write", false); } } return true; } static bool cb_iopcacheread(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if ((bool)node->i_value) { if (core && core->io) { @@ -1736,8 +1736,8 @@ static bool cb_iopcacheread(void *user, void *data) { if (core && core->io && core->io->p_cache) { core->io->p_cache &= 2; if (!(core->io->p_cache & 2)) { - r_io_desc_cache_fini_all (core->io); - r_config_set_i (core->config, "io.pcache", false); + rz_io_desc_cache_fini_all (core->io); + rz_config_set_i (core->config, "io.pcache", false); } } } @@ -1745,7 +1745,7 @@ static bool cb_iopcacheread(void *user, void *data) { } static bool cb_iopcachewrite(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if ((bool)node->i_value) { if (core && core->io) { @@ -1755,28 +1755,28 @@ static bool cb_iopcachewrite(void *user, void *data) { if (core && core->io && core->io->p_cache) { core->io->p_cache &= 1; if (!(core->io->p_cache & 1)) { - r_io_desc_cache_fini_all (core->io); - r_config_set_i (core->config, "io.pcache", false); + rz_io_desc_cache_fini_all (core->io); + rz_config_set_i (core->config, "io.pcache", false); } } } return true; } -R_API bool r_core_esil_cmd(RAnalEsil *esil, const char *cmd, ut64 a1, ut64 a2) { +RZ_API bool rz_core_esil_cmd(RzAnalEsil *esil, const char *cmd, ut64 a1, ut64 a2) { if (cmd && *cmd) { - RCore *core = esil->anal->user; - r_core_cmdf (core, "%s %"PFMT64d" %" PFMT64d, cmd, a1, a2); + RzCore *core = esil->anal->user; + rz_core_cmdf (core, "%s %"PFMT64d" %" PFMT64d, cmd, a1, a2); return core->num->value; } return false; } static bool cb_cmd_esil_ioer(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_ioer); core->anal->esil->cmd_ioer = strdup (node->value); } @@ -1784,10 +1784,10 @@ static bool cb_cmd_esil_ioer(void *user, void *data) { } static bool cb_cmd_esil_todo(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_todo); core->anal->esil->cmd_todo = strdup (node->value); } @@ -1795,10 +1795,10 @@ static bool cb_cmd_esil_todo(void *user, void *data) { } static bool cb_cmd_esil_intr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_intr); core->anal->esil->cmd_intr = strdup (node->value); } @@ -1806,10 +1806,10 @@ static bool cb_cmd_esil_intr(void *user, void *data) { } static bool cb_mdevrange(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->mdev_range); core->anal->esil->mdev_range = strdup (node->value); } @@ -1817,10 +1817,10 @@ static bool cb_mdevrange(void *user, void *data) { } static bool cb_cmd_esil_step(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_step); core->anal->esil->cmd_step = strdup (node->value); } @@ -1828,10 +1828,10 @@ static bool cb_cmd_esil_step(void *user, void *data) { } static bool cb_cmd_esil_step_out(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_step_out); core->anal->esil->cmd_step_out = strdup (node->value); } @@ -1839,10 +1839,10 @@ static bool cb_cmd_esil_step_out(void *user, void *data) { } static bool cb_cmd_esil_mdev(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; free (core->anal->esil->cmd_mdev); core->anal->esil->cmd_mdev = strdup (node->value); } @@ -1850,10 +1850,10 @@ static bool cb_cmd_esil_mdev(void *user, void *data) { } static bool cb_cmd_esil_trap(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core && core->anal && core->anal->esil) { - core->anal->esil->cmd = r_core_esil_cmd; + core->anal->esil->cmd = rz_core_esil_cmd; core->anal->esil->cmd_trap = strdup (node->value); } return true; @@ -1861,7 +1861,7 @@ static bool cb_cmd_esil_trap(void *user, void *data) { static bool cb_fsview(void *user, void *data) { int type = R_FS_VIEW_NORMAL; - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (*node->value == '?') { print_node_options (node); @@ -1876,12 +1876,12 @@ static bool cb_fsview(void *user, void *data) { if (!strstr (node->value, "spe")) { type |= R_FS_VIEW_SPECIAL; } - r_fs_view (core->fs, type); + rz_fs_view (core->fs, type); return true; } static bool cb_cmddepth(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; int c = R_MAX (((RConfigNode*)data)->i_value, 0); core->max_cmd_depth = c; core->cons->context->cmd_depth = c; @@ -1889,7 +1889,7 @@ static bool cb_cmddepth(void *user, void *data) { } static bool cb_hexcols(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; int c = R_MIN (1024, R_MAX (((RConfigNode*)data)->i_value, 0)); core->print->cols = c; // & ~1; core->dbg->regcols = c/4; @@ -1898,19 +1898,19 @@ static bool cb_hexcols(void *user, void *data) { static bool cb_hexstride(void *user, void *data) { RConfigNode *node = (RConfigNode*) data; - ((RCore *)user)->print->stride = node->i_value; + ((RzCore *)user)->print->stride = node->i_value; return true; } static bool cb_search_kwidx(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->search->n_kws = node->i_value; return true; } static bool cb_io_cache_mode(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; if (node->i_value) { core->io->cachemode = true; @@ -1921,7 +1921,7 @@ static bool cb_io_cache_mode(void *user, void *data) { } static bool cb_io_cache_read(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; if (node->i_value) { core->io->cached |= R_PERM_R; @@ -1932,7 +1932,7 @@ static bool cb_io_cache_read(void *user, void *data) { } static bool cb_io_cache_write(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; if (node->i_value) { core->io->cached |= R_PERM_W; @@ -1949,7 +1949,7 @@ static bool cb_io_cache(void *user, void *data) { } static bool cb_ioaslr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value != core->io->aslr) { core->io->aslr = node->i_value; @@ -1958,7 +1958,7 @@ static bool cb_ioaslr(void *user, void *data) { } static bool cb_io_pava(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->pava = node->i_value; if (node->i_value && core->io->va) { @@ -1968,18 +1968,18 @@ static bool cb_io_pava(void *user, void *data) { } static bool cb_iova(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value != core->io->va) { core->io->va = node->i_value; /* ugly fix for r2 -d ... "r2 is going to die soon ..." */ if (core->io->desc) { - r_core_block_read (core); + rz_core_block_read (core); } #if 0 /* reload symbol information */ - if (r_list_length (r_bin_get_sections (core->bin)) > 0) { - r_core_cmd0 (core, ".ia*"); + if (rz_list_length (rz_bin_get_sections (core->bin)) > 0) { + rz_core_cmd0 (core, ".ia*"); } #endif } @@ -1987,26 +1987,26 @@ static bool cb_iova(void *user, void *data) { } static bool cb_ioff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->io->ff = node->i_value; return true; } static bool cb_io_oxff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->io->Oxff = node->i_value; return true; } static bool cb_filepath(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; char *pikaboo = strstr (node->value, "://"); if (pikaboo) { if (pikaboo[3] == '/') { - r_config_set (core->config, "file.lastpath", node->value); + rz_config_set (core->config, "file.lastpath", node->value); char *ovalue = node->value; node->value = strdup (pikaboo + 3); free (ovalue); @@ -2014,19 +2014,19 @@ static bool cb_filepath(void *user, void *data) { } return false; } - r_config_set (core->config, "file.lastpath", node->value); + rz_config_set (core->config, "file.lastpath", node->value); return true; } static bool cb_ioautofd(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->io->autofd = node->i_value; return true; } static bool cb_scr_color_grep(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; /* Let cons know we have a new pager. */ @@ -2035,14 +2035,14 @@ static bool cb_scr_color_grep(void *user, void *data) { } static bool cb_scr_color_grep_highlight(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->grep_highlight = node->i_value; return true; } static bool cb_pager(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (!strcmp (node->value, "?")) { eprintf ("Usage: scr.pager must be '..' for internal less, or the path to a program in $PATH"); @@ -2056,12 +2056,12 @@ static bool cb_pager(void *user, void *data) { static bool cb_breaklines(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->break_lines = node->i_value; + rz_cons_singleton ()->break_lines = node->i_value; return true; } static bool cb_scr_gadgets(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode *) data; core->scr_gadgets = node->i_value; return true; @@ -2069,23 +2069,23 @@ static bool cb_scr_gadgets(void *user, void *data) { static bool cb_fps(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->fps = node->i_value; + rz_cons_singleton ()->fps = node->i_value; return true; } static bool cb_scrbreakword(void* user, void* data) { RConfigNode *node = (RConfigNode*) data; if (*node->value) { - r_cons_breakword (node->value); + rz_cons_breakword (node->value); } else { - r_cons_breakword (NULL); + rz_cons_breakword (NULL); } return true; } static bool cb_scrcolumns(void* user, void* data) { RConfigNode *node = (RConfigNode*) data; - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; int n = atoi (node->value); core->cons->force_columns = n; core->dbg->regcols = n / 20; @@ -2093,51 +2093,51 @@ static bool cb_scrcolumns(void* user, void* data) { } static bool cb_scrfgets(void* user, void* data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode*) data; core->cons->user_fgets = node->i_value - ? NULL : (void *)r_core_fgets; + ? NULL : (void *)rz_core_fgets; return true; } static bool cb_scrhtml(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->is_html = node->i_value; + rz_cons_singleton ()->is_html = node->i_value; // TODO: control error and restore old value (return false?) show errormsg? return true; } static bool cb_newshell(void *user, void *data) { RConfigNode *node = (RConfigNode *)data; - RCore *core = (RCore *)user; - core->use_tree_sitter_r2cmd = node->i_value; + RzCore *core = (RzCore *)user; + core->use_tree_sitter_rzcmd = node->i_value; return true; } static bool cb_scrhighlight(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_highlight (node->value); + rz_cons_highlight (node->value); return true; } #if __WINDOWS__ static bool scr_vtmode(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - if (r_str_is_true (node->value)) { + if (rz_str_is_true (node->value)) { node->i_value = 1; } node->i_value = node->i_value > 2 ? 2 : node->i_value; - r_line_singleton ()->vtmode = r_cons_singleton ()->vtmode = node->i_value; + rz_line_singleton ()->vtmode = rz_cons_singleton ()->vtmode = node->i_value; DWORD mode; HANDLE input = GetStdHandle (STD_INPUT_HANDLE); GetConsoleMode (input, &mode); if (node->i_value == 2) { SetConsoleMode (input, mode & ENABLE_VIRTUAL_TERMINAL_INPUT); - r_cons_singleton ()->term_raw = ENABLE_VIRTUAL_TERMINAL_INPUT; + rz_cons_singleton ()->term_raw = ENABLE_VIRTUAL_TERMINAL_INPUT; } else { SetConsoleMode (input, mode & ~ENABLE_VIRTUAL_TERMINAL_INPUT); - r_cons_singleton ()->term_raw = 0; + rz_cons_singleton ()->term_raw = 0; } HANDLE streams[] = { GetStdHandle (STD_OUTPUT_HANDLE), GetStdHandle (STD_ERROR_HANDLE) }; int i; @@ -2160,34 +2160,34 @@ static bool scr_vtmode(void *user, void *data) { static bool cb_screcho(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->echo = node->i_value; + rz_cons_singleton ()->echo = node->i_value; return true; } static bool cb_scrlinesleep(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->linesleep = node->i_value; + rz_cons_singleton ()->linesleep = node->i_value; return true; } static bool cb_scrpagesize(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->pagesize= node->i_value; + rz_cons_singleton ()->pagesize= node->i_value; return true; } static bool cb_scrflush(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->flush = node->i_value; + rz_cons_singleton ()->flush = node->i_value; return true; } static bool cb_scrstrconv(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->value[0] == '?') { if (strlen (node->value) > 1 && node->value[1] == '?') { - r_cons_printf ("Valid values for scr.strconv:\n" + rz_cons_printf ("Valid values for scr.strconv:\n" " asciiesc convert to ascii with non-ascii chars escaped\n" " asciidot convert to ascii with non-ascii chars turned into a dot (except control chars stated below)\n" "\n" @@ -2209,7 +2209,7 @@ static bool cb_scrstrconv(void *user, void *data) { static bool cb_graphformat(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; if (!strcmp (node->value, "?")) { - r_cons_printf ("png\njpg\npdf\nps\nsvg\njson\n"); + rz_cons_printf ("png\njpg\npdf\nps\nsvg\njson\n"); return false; } return true; @@ -2218,7 +2218,7 @@ static bool cb_graphformat(void *user, void *data) { static bool cb_exectrap(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; if (core->anal && core->anal->esil) { core->anal->esil->exectrap = node->i_value; } @@ -2227,7 +2227,7 @@ static bool cb_exectrap(void *user, void *data) { static bool cb_iotrap(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; if (core->anal && core->anal->esil) { core->anal->esil->iotrap = node->i_value; } @@ -2235,23 +2235,23 @@ static bool cb_iotrap(void *user, void *data) { } static bool cb_scr_bgfill(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_BGFILL; } else { core->print->flags &= (~R_PRINT_FLAGS_BGFILL); } - r_print_set_flags (core->print, core->print->flags); + rz_print_set_flags (core->print, core->print->flags); return true; } static bool cb_scrint(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - if (node->i_value && r_sandbox_enable (0)) { + if (node->i_value && rz_sandbox_enable (0)) { return false; } - r_cons_singleton ()->context->is_interactive = node->i_value; + rz_cons_singleton ()->context->is_interactive = node->i_value; return true; } @@ -2265,36 +2265,36 @@ static bool cb_scrnkey(void *user, void *data) { } static bool cb_scr_histblock(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->print->histblock = node->i_value; return true; } static bool cb_scrprompt(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *) data; core->print->scr_prompt = node->i_value; - r_line_singleton ()->echo = node->i_value; + rz_line_singleton ()->echo = node->i_value; return true; } static bool cb_scrrows(void* user, void* data) { RConfigNode *node = (RConfigNode*) data; int n = atoi (node->value); - ((RCore *)user)->cons->force_rows = n; + ((RzCore *)user)->cons->force_rows = n; return true; } static bool cb_contiguous(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *) data; core->search->contiguous = node->i_value; return true; } static bool cb_searchalign(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *) data; core->search->align = node->i_value; core->print->addrmod = node->i_value; @@ -2302,7 +2302,7 @@ static bool cb_searchalign(void *user, void *data) { } static bool cb_segoff(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->print->flags |= R_PRINT_FLAGS_SEGOFF; @@ -2313,7 +2313,7 @@ static bool cb_segoff(void *user, void *data) { } static bool cb_seggrn(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->rasm->seggrn = node->i_value; core->anal->seggrn = node->i_value; @@ -2322,28 +2322,28 @@ static bool cb_seggrn(void *user, void *data) { } static bool cb_stopthreads(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->stop_all_threads = node->i_value; return true; } static bool cb_scr_prompt_popup(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->show_autocomplete_widget = node->i_value; return true; } static bool cb_swstep(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->swstep = node->i_value; return true; } static bool cb_consbreak(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->consbreak = node->i_value; return true; @@ -2351,19 +2351,19 @@ static bool cb_consbreak(void *user, void *data) { static bool cb_teefile(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_singleton ()->teefile = node->value; + rz_cons_singleton ()->teefile = node->value; return true; } static bool cb_trace(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->trace->enabled = node->i_value; return true; } static bool cb_tracetag(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->dbg->trace->tag = node->i_value; return true; @@ -2371,26 +2371,26 @@ static bool cb_tracetag(void *user, void *data) { static bool cb_utf8(void *user, void *data) { RConfigNode *node = (RConfigNode *) data; - r_cons_set_utf8 ((bool)node->i_value); + rz_cons_set_utf8 ((bool)node->i_value); return true; } static bool cb_utf8_curvy(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->use_utf8_curvy = node->i_value; return true; } static bool cb_dotted(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->cons->dotted_lines = node->i_value; return true; } static bool cb_zoombyte(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; switch (*node->value) { case 'p': case 'f': case 's': case '0': @@ -2399,35 +2399,35 @@ static bool cb_zoombyte(void *user, void *data) { break; default: eprintf ("Invalid zoom.byte value. See pz? for help\n"); - r_cons_printf ("pzp\npzf\npzs\npz0\npzF\npze\npzh\n"); + rz_cons_printf ("pzp\npzf\npzs\npz0\npzF\npze\npzh\n"); return false; } return true; } static bool cb_analverbose(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->anal->verbose = node->i_value; return true; } static bool cb_binverbose(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->bin->verbose = node->i_value; return true; } static bool cb_rawstr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->bin->rawstr = node->i_value; return true; } static bool cb_debase64(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; core->bin->debase64 = node->i_value; return true; @@ -2435,7 +2435,7 @@ static bool cb_debase64(void *user, void *data) { static bool cb_binstrings(void *user, void *data) { const ut32 req = R_BIN_REQ_STRINGS; - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (node->i_value) { core->bin->filter_rules |= req; @@ -2446,7 +2446,7 @@ static bool cb_binstrings(void *user, void *data) { } static bool cb_bindbginfo(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (!core || !core->bin) { return false; @@ -2456,7 +2456,7 @@ static bool cb_bindbginfo(void *user, void *data) { } static bool cb_binprefix(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (!core || !core->bin) { return false; @@ -2466,10 +2466,10 @@ static bool cb_binprefix(void *user, void *data) { if (!core->bin->file) { return false; } - char *name = (char *)r_file_basename (core->bin->file); + char *name = (char *)rz_file_basename (core->bin->file); if (name) { - r_name_filter (name, strlen (name)); - r_str_filter (name, strlen (name)); + rz_name_filter (name, strlen (name)); + rz_str_filter (name, strlen (name)); core->bin->prefix = strdup (name); free (name); } @@ -2481,7 +2481,7 @@ static bool cb_binprefix(void *user, void *data) { } static bool cb_binmaxstrbuf(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core->bin) { int v = node->i_value; @@ -2491,7 +2491,7 @@ static bool cb_binmaxstrbuf(void *user, void *data) { } core->bin->maxstrbuf = v; if (v>old_v) { - r_bin_reset_strings (core->bin); + rz_bin_reset_strings (core->bin); } return true; } @@ -2499,7 +2499,7 @@ static bool cb_binmaxstrbuf(void *user, void *data) { } static bool cb_binmaxstr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core->bin) { int v = node->i_value; @@ -2507,14 +2507,14 @@ static bool cb_binmaxstr(void *user, void *data) { v = 4; // HACK } core->bin->maxstrlen = v; - r_bin_reset_strings (core->bin); + rz_bin_reset_strings (core->bin); return true; } return true; } static bool cb_binminstr(void *user, void *data) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; RConfigNode *node = (RConfigNode *) data; if (core->bin) { int v = node->i_value; @@ -2522,18 +2522,18 @@ static bool cb_binminstr(void *user, void *data) { v = 4; // HACK } core->bin->minstrlen = v; - r_bin_reset_strings (core->bin); + rz_bin_reset_strings (core->bin); return true; } return true; } static bool cb_searchin(void *user, void *data) { - RCore *core = (RCore*)user; + RzCore *core = (RzCore*)user; RConfigNode *node = (RConfigNode*) data; if (node->value[0] == '?') { if (strlen (node->value) > 1 && node->value[1] == '?') { - r_cons_printf ("Valid values for search.in (depends on .from/.to and io.va):\n" + rz_cons_printf ("Valid values for search.in (depends on .from/.to and io.va):\n" "raw search in raw io (ignoring bounds)\n" "block search in the current block\n" "io.map search in current map\n" @@ -2559,149 +2559,149 @@ static bool cb_searchin(void *user, void *data) { return false; } // Set anal.noncode if exec bit set in anal.in - if (r_str_startswith (node->name, "anal")) { + if (rz_str_startswith (node->name, "anal")) { core->anal->opt.noncode = (strchr (node->value, 'x') == NULL); } return true; } static int __dbg_swstep_getter(void *user, RConfigNode *node) { - RCore *core = (RCore*)user; + RzCore *core = (RzCore*)user; node->i_value = core->dbg->swstep; return true; } -static bool cb_dirpfx(RCore *core, RConfigNode *node) { - r_sys_prefix (node->value); +static bool cb_dirpfx(RzCore *core, RConfigNode *node) { + rz_sys_prefix (node->value); return true; } -static bool cb_anal_roregs(RCore *core, RConfigNode *node) { +static bool cb_anal_roregs(RzCore *core, RConfigNode *node) { if (core && core->anal && core->anal->reg) { - r_list_free (core->anal->reg->roregs); - core->anal->reg->roregs = r_str_split_duplist (node->value, ",", true); + rz_list_free (core->anal->reg->roregs); + core->anal->reg->roregs = rz_str_split_duplist (node->value, ",", true); } return true; } -static bool cb_anal_gp(RCore *core, RConfigNode *node) { +static bool cb_anal_gp(RzCore *core, RConfigNode *node) { core->anal->gp = node->i_value; return true; } -static bool cb_anal_from(RCore *core, RConfigNode *node) { - if (r_config_get_i (core->config, "anal.limits")) { - r_anal_set_limits (core->anal, - r_config_get_i (core->config, "anal.from"), - r_config_get_i (core->config, "anal.to")); +static bool cb_anal_from(RzCore *core, RConfigNode *node) { + if (rz_config_get_i (core->config, "anal.limits")) { + rz_anal_set_limits (core->anal, + rz_config_get_i (core->config, "anal.from"), + rz_config_get_i (core->config, "anal.to")); } return true; } static bool cb_anal_limits(void *user, RConfigNode *node) { - RCore *core = (RCore*)user; + RzCore *core = (RzCore*)user; if (node->i_value) { - r_anal_set_limits (core->anal, - r_config_get_i (core->config, "anal.from"), - r_config_get_i (core->config, "anal.to")); + rz_anal_set_limits (core->anal, + rz_config_get_i (core->config, "anal.from"), + rz_config_get_i (core->config, "anal.to")); } else { - r_anal_unset_limits (core->anal); + rz_anal_unset_limits (core->anal); } return 1; } static bool cb_anal_rnr(void *user, RConfigNode *node) { - RCore *core = (RCore*)user; + RzCore *core = (RzCore*)user; core->anal->recursive_noreturn = node->i_value; return 1; } static bool cb_anal_jmptbl(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.jmptbl = node->i_value; return true; } static bool cb_anal_cjmpref(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.cjmpref = node->i_value; return true; } static bool cb_anal_jmpref(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.jmpref = node->i_value; return true; } static bool cb_anal_jmpabove(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.jmpabove = node->i_value; return true; } static bool cb_anal_loads(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.loads = node->i_value; return true; } static bool cb_anal_followdatarefs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.followdatarefs = node->i_value; return true; } static bool cb_anal_jmpmid(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.jmpmid = node->i_value; return true; } static bool cb_anal_searchstringrefs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.searchstringrefs = node->i_value; return true; } static bool cb_anal_pushret(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.pushret = node->i_value; return true; } static bool cb_anal_brokenrefs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.followbrokenfcnsrefs = node->i_value; return true; } static bool cb_anal_trycatch(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.trycatch = node->i_value; return true; } static bool cb_anal_bb_max_size(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->anal->opt.bb_max_size = node->i_value; return true; } static bool cb_anal_cpp_abi(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (*node->value == '?') { @@ -2723,13 +2723,13 @@ static bool cb_anal_cpp_abi(void *user, void *data) { } static bool cb_linesto(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; - ut64 from = (ut64)r_config_get_i (core->config, "lines.from"); - int io_sz = r_io_size (core->io); - ut64 to = r_num_math (core->num, node->value); + ut64 from = (ut64)rz_config_get_i (core->config, "lines.from"); + int io_sz = rz_io_size (core->io); + ut64 to = rz_num_math (core->num, node->value); if (to == 0) { - core->print->lines_cache_sz = -1; //r_core_lines_initcache (core, from, to); + core->print->lines_cache_sz = -1; //rz_core_lines_initcache (core, from, to); return true; } if (to > from + io_sz) { @@ -2738,7 +2738,7 @@ static bool cb_linesto(void *user, void *data) { return true; } if (to > from) { - core->print->lines_cache_sz = r_core_lines_initcache (core, from, to); + core->print->lines_cache_sz = rz_core_lines_initcache (core, from, to); //if (core->print->lines_cache_sz == -1) { eprintf ("ERROR: Can't allocate memory\n"); } } else { eprintf ("Invalid range 0x%08"PFMT64x" .. 0x%08"PFMT64x"\n", from, to); @@ -2747,14 +2747,14 @@ static bool cb_linesto(void *user, void *data) { } static bool cb_linesabs(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; core->print->lines_abs = node->i_value; if (core->print->lines_abs && core->print->lines_cache_sz <= 0) { - ut64 from = (ut64)r_config_get_i (core->config, "lines.from"); - const char *to_str = r_config_get (core->config, "lines.to"); - ut64 to = r_num_math (core->num, (to_str && *to_str) ? to_str : "$s"); - core->print->lines_cache_sz = r_core_lines_initcache (core, from, to); + ut64 from = (ut64)rz_config_get_i (core->config, "lines.from"); + const char *to_str = rz_config_get (core->config, "lines.to"); + ut64 to = rz_num_math (core->num, (to_str && *to_str) ? to_str : "$s"); + core->print->lines_cache_sz = rz_core_lines_initcache (core, from, to); if (core->print->lines_cache_sz == -1) { eprintf ("ERROR: \"lines.from\" and \"lines.to\" must be set\n"); } else { @@ -2765,7 +2765,7 @@ static bool cb_linesabs(void *user, void *data) { } static bool cb_malloc(void *user, void *data) { - RCore *core = (RCore*) user; + RzCore *core = (RzCore*) user; RConfigNode *node = (RConfigNode*) data; if (node->value) { @@ -2781,20 +2781,20 @@ static bool cb_malloc(void *user, void *data) { static bool cb_log_config_level(void *coreptr, void *nodeptr) { RConfigNode *node = (RConfigNode *)nodeptr; - r_log_set_level (node->i_value); + rz_log_set_level (node->i_value); return true; } static bool cb_log_config_traplevel(void *coreptr, void *nodeptr) { RConfigNode *node = (RConfigNode *)nodeptr; - r_log_set_traplevel (node->i_value); + rz_log_set_traplevel (node->i_value); return true; } static bool cb_log_config_file(void *coreptr, void *nodeptr) { RConfigNode *node = (RConfigNode *)nodeptr; const char *value = node->value; - r_log_set_file (value); + rz_log_set_file (value); return true; } @@ -2804,10 +2804,10 @@ static bool cb_log_config_srcinfo(void *coreptr, void *nodeptr) { switch (value[0]) { case 't': case 'T': - r_log_set_srcinfo (true); + rz_log_set_srcinfo (true); break; default: - r_log_set_srcinfo (false); + rz_log_set_srcinfo (false); } return true; } @@ -2818,16 +2818,16 @@ static bool cb_log_config_colors(void *coreptr, void *nodeptr) { switch (value[0]) { case 't': case 'T': - r_log_set_colors (true); + rz_log_set_colors (true); break; default: - r_log_set_colors (false); + rz_log_set_colors (false); } return true; } static bool cb_dbg_verbose(void *user, void *data) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RConfigNode *node = (RConfigNode *)data; const char *value = node->value; switch (value[0]) { @@ -2841,21 +2841,21 @@ static bool cb_dbg_verbose(void *user, void *data) { return true; } -R_API int r_core_config_init(RCore *core) { +RZ_API int rz_core_config_init(RzCore *core) { int i; char buf[128], *p, *tmpdir; RConfigNode *n; - RConfig *cfg = core->config = r_config_new (core); + RConfig *cfg = core->config = rz_config_new (core); if (!cfg) { return 0; } - cfg->cb_printf = r_cons_printf; + cfg->cb_printf = rz_cons_printf; cfg->num = core->num; /* dir.prefix is used in other modules, set it first */ { - char *pfx = r_sys_getenv("R2_PREFIX"); + char *pfx = rz_sys_getenv("R2_PREFIX"); #if __WINDOWS__ - const char *invoke_dir = r_sys_prefix (NULL); + const char *invoke_dir = rz_sys_prefix (NULL); if (!pfx && invoke_dir) { pfx = strdup (invoke_dir); } @@ -2868,10 +2868,10 @@ R_API int r_core_config_init(RCore *core) { } #if __ANDROID__ { // use dir.home and also adjust check for permissions in directory before choosing a home - char *h = r_sys_getenv (R_SYS_HOME); + char *h = rz_sys_getenv (R_SYS_HOME); if (h) { if (!strcmp (h, "/")) { - r_sys_setenv (R_SYS_HOME, "/data/local/tmp"); + rz_sys_setenv (R_SYS_HOME, "/data/local/tmp"); } free (h); } @@ -2882,7 +2882,7 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("pdb.useragent", "Microsoft-Symbol-Server/6.11.0001.402", "User agent for Microsoft symbol server"); SETPREF ("pdb.server", "https://msdl.microsoft.com/download/symbols", "Semi-colon separated list of base URLs for Microsoft symbol servers"); { - char *pdb_path = r_str_home (R2_HOME_PDB); + char *pdb_path = rz_str_home (R2_HOME_PDB); SETPREF ("pdb.symstore", pdb_path, "Path to downstream symbol store"); R_FREE(pdb_path); } @@ -2891,7 +2891,7 @@ R_API int r_core_config_init(RCore *core) { /* anal */ SETPREF ("anal.fcnprefix", "fcn", "Prefix new function names with this"); - SETCB ("anal.verbose", "false", &cb_analverbose, "Show RAnal warnings when analyzing code"); + SETCB ("anal.verbose", "false", &cb_analverbose, "Show RzAnal warnings when analyzing code"); SETBPREF ("anal.a2f", "false", "Use the new WIP analysis algorithm (core/p/a2f), anal.depth ignored atm"); SETCB ("anal.roregs", "gp,zero", (RConfigCallback)&cb_anal_roregs, "Comma separated list of register names to be readonly"); SETICB ("anal.gp", 0, (RConfigCallback)&cb_anal_gp, "Set the value of the GP register (MIPS)"); @@ -3172,7 +3172,7 @@ R_API int r_core_config_init(RCore *core) { SETCB ("bin.useldr", "true", &cb_useldr, "Use loader plugins when loading files"); SETCB ("bin.str.purge", "", &cb_strpurge, "Purge strings (e bin.str.purge=? provides more detail)"); SETBPREF ("bin.b64str", "false", "Try to debase64 the strings"); - SETCB ("bin.at", "false", &cb_binat, "RBin.cur depends on RCore.offset"); + SETCB ("bin.at", "false", &cb_binat, "RBin.cur depends on RzCore.offset"); SETBPREF ("bin.libs", "false", "Try to load libraries after loading main binary"); n = NODECB ("bin.str.filter", "", &cb_strfilter); SETDESC (n, "Filter strings"); @@ -3186,8 +3186,8 @@ R_API int r_core_config_init(RCore *core) { SETI ("bin.laddr", 0, "Base address for loading library ('*.so')"); SETCB ("bin.dbginfo", "true", &cb_bindbginfo, "Load debug information at startup if available"); SETBPREF ("bin.relocs", "true", "Load relocs information at startup if available"); - SETICB ("bin.minstr", 0, &cb_binminstr, "Minimum string length for r_bin"); - SETICB ("bin.maxstr", 0, &cb_binmaxstr, "Maximum string length for r_bin"); + SETICB ("bin.minstr", 0, &cb_binminstr, "Minimum string length for rz_bin"); + SETICB ("bin.maxstr", 0, &cb_binmaxstr, "Maximum string length for rz_bin"); SETICB ("bin.maxstrbuf", 1024*1024*10, & cb_binmaxstrbuf, "Maximum size of range to load strings from"); n = NODECB ("bin.str.enc", "guess", &cb_binstrenc); SETDESC (n, "Default string encoding of binary"); @@ -3215,15 +3215,15 @@ R_API int r_core_config_init(RCore *core) { SETCB ("cfg.corelog", "false", &cb_cfgcorelog, "Log changes using the T api needed for realtime syncing"); SETBPREF ("cfg.newtab", "false", "Show descriptions in command completion"); SETCB ("cfg.debug", "false", &cb_cfgdebug, "Debugger mode"); - p = r_sys_getenv ("EDITOR"); + p = rz_sys_getenv ("EDITOR"); #if __WINDOWS__ - r_config_set (cfg, "cfg.editor", p? p: "notepad"); + rz_config_set (cfg, "cfg.editor", p? p: "notepad"); #else - r_config_set (cfg, "cfg.editor", p? p: "vi"); + rz_config_set (cfg, "cfg.editor", p? p: "vi"); #endif free (p); - r_config_desc (cfg, "cfg.editor", "Select default editor program"); - SETPREF ("cfg.user", r_sys_whoami (buf), "Set current username/pid"); + rz_config_desc (cfg, "cfg.editor", "Select default editor program"); + SETPREF ("cfg.user", rz_sys_whoami (buf), "Set current username/pid"); SETCB ("cfg.fortunes", "true", &cb_cfg_fortunes, "If enabled show tips at start"); SETCB ("cfg.fortunes.type", "tips,fun", &cb_cfg_fortunes_type, "Type of fortunes to show (tips, fun, nsfw, creepy)"); SETBPREF ("cfg.fortunes.clippy", "false", "Use ?E instead of ?e"); @@ -3232,34 +3232,34 @@ R_API int r_core_config_init(RCore *core) { SETCB ("cfg.sandbox", "false", &cb_cfgsanbox, "Sandbox mode disables systems and open on upper directories"); SETBPREF ("cfg.wseek", "false", "Seek after write"); SETCB ("cfg.bigendian", "false", &cb_bigendian, "Use little (false) or big (true) endianness"); - p = r_sys_getenv ("R2_CFG_NEWSHELL"); + p = rz_sys_getenv ("R2_CFG_NEWSHELL"); SETCB ("cfg.newshell", p? "true": "false", &cb_newshell, "Use new commands parser"); free (p); SETI ("cfg.cpuaffinity", 0, "Run on cpuid"); /* log */ // R2_LOGLEVEL / log.level - p = r_sys_getenv ("R2_LOGLEVEL"); + p = rz_sys_getenv ("R2_LOGLEVEL"); SETICB ("log.level", p? atoi(p): R_DEFAULT_LOGLVL, cb_log_config_level, "Target log level/severity"\ " (0:SILLY, 1:DEBUG, 2:VERBOSE, 3:INFO, 4:WARN, 5:ERROR, 6:FATAL)" ); free (p); // R2_LOGTRAP_LEVEL / log.traplevel - p = r_sys_getenv ("R2_LOGTRAPLEVEL"); + p = rz_sys_getenv ("R2_LOGTRAPLEVEL"); SETICB ("log.traplevel", p ? atoi(p) : R_LOGLVL_FATAL, cb_log_config_traplevel, "Log level for trapping R2 when hit"\ " (0:SILLY, 1:VERBOSE, 2:DEBUG, 3:INFO, 4:WARN, 5:ERROR, 6:FATAL)" ); free (p); // R2_LOGFILE / log.file - p = r_sys_getenv ("R2_LOGFILE"); + p = rz_sys_getenv ("R2_LOGFILE"); SETCB ("log.file", p ? p : "", cb_log_config_file, "Logging output filename / path"); free (p); // R2_LOGSRCINFO / log.srcinfo - p = r_sys_getenv ("R2_LOGSRCINFO"); + p = rz_sys_getenv ("R2_LOGSRCINFO"); SETCB ("log.srcinfo", p ? p : "false", cb_log_config_srcinfo, "Should the log output contain src info (filename:lineno)"); free (p); // R2_LOGCOLORS / log.colors - p = r_sys_getenv ("R2_LOGCOLORS"); + p = rz_sys_getenv ("R2_LOGCOLORS"); SETCB ("log.colors", p ? p : "false", cb_log_config_colors, "Should the log output use colors (TODO)"); free (p); @@ -3291,24 +3291,24 @@ R_API int r_core_config_init(RCore *core) { /* dir */ SETI ("dir.depth", 10, "Maximum depth when searching recursively for files"); { - char *path = r_str_newf (R_JOIN_2_PATHS ("%s", R2_SDB_MAGIC), r_config_get (core->config, "dir.prefix")); - SETPREF ("dir.magic", path, "Path to r_magic files"); + char *path = rz_str_newf (R_JOIN_2_PATHS ("%s", R2_SDB_MAGIC), rz_config_get (core->config, "dir.prefix")); + SETPREF ("dir.magic", path, "Path to rz_magic files"); free (path); - path = r_str_newf (R_JOIN_2_PATHS ("%s", R2_PLUGINS), r_config_get (core->config, "dir.prefix")); + path = rz_str_newf (R_JOIN_2_PATHS ("%s", R2_PLUGINS), rz_config_get (core->config, "dir.prefix")); SETPREF ("dir.plugins", path, "Path to plugin files to be loaded at startup"); free (path); } SETCB ("dir.source", "", &cb_dirsrc, "Path to find source files"); SETPREF ("dir.types", "/usr/include", "Default path to look for cparse type files"); SETPREF ("dir.libs", "", "Specify path to find libraries to load when bin.libs=true"); - p = r_sys_getenv (R_SYS_HOME); + p = rz_sys_getenv (R_SYS_HOME); SETCB ("dir.home", p? p: "/", &cb_dirhome, "Path for the home directory"); free (p); - p = r_sys_getenv (R_SYS_TMP); + p = rz_sys_getenv (R_SYS_TMP); SETCB ("dir.tmp", p? p: "", &cb_dirtmp, "Path of the tmp directory"); free (p); #if __ANDROID__ - SETPREF ("dir.projects", "/data/data/org.radare.radare2installer/radare2/projects", "Default path for projects"); + SETPREF ("dir.projects", "/data/data/org.radare.rizininstaller/rizin/projects", "Default path for projects"); #else SETPREF ("dir.projects", R_JOIN_2_PATHS ("~", R2_HOME_PROJECTS), "Default path for projects"); #endif @@ -3350,11 +3350,11 @@ R_API int r_core_config_init(RCore *core) { SETDESC (n, "Break on entrypoint"); SETOPTIONS (n, "loader", "entry", "constructor", "main", NULL); if (core->cons->rows > 30) { // HACKY - r_config_set_i (cfg, "dbg.follow", 64); + rz_config_set_i (cfg, "dbg.follow", 64); } else { - r_config_set_i (cfg, "dbg.follow", 32); + rz_config_set_i (cfg, "dbg.follow", 32); } - r_config_desc (cfg, "dbg.follow", "Follow program counter when pc > core->offset + dbg.follow"); + rz_config_desc (cfg, "dbg.follow", "Follow program counter when pc > core->offset + dbg.follow"); SETBPREF ("dbg.rebase", "true", "Rebase anal/meta/comments/flags when reopening file in debugger"); SETCB ("dbg.swstep", "false", &cb_swstep, "Force use of software steps (code analysis+breakpoint)"); SETBPREF ("dbg.trace.inrange", "false", "While tracing, avoid following calls outside specified range"); @@ -3366,7 +3366,7 @@ R_API int r_core_config_init(RCore *core) { SETICB ("dbg.gdb.retries", 10, &cb_dbg_gdb_retries, "Number of retries before gdb packet read times out"); SETCB ("dbg.consbreak", "false", &cb_consbreak, "SIGINT handle for attached processes"); - r_config_set_getter (cfg, "dbg.swstep", (RConfigCallback)__dbg_swstep_getter); + rz_config_set_getter (cfg, "dbg.swstep", (RConfigCallback)__dbg_swstep_getter); // TODO: This should be specified at first by the debug backend when attaching #if __arm__ || __mips__ @@ -3446,21 +3446,21 @@ R_API int r_core_config_init(RCore *core) { SETBPREF ("http.dirlist", "false", "Enable directory listing"); SETPREF ("http.allow", "", "Only accept clients from the comma separated IP list"); #if __WINDOWS__ - r_config_set (cfg, "http.browser", "start"); + rz_config_set (cfg, "http.browser", "start"); #else - if (r_file_exists ("/usr/bin/openURL")) { // iOS ericautils - r_config_set (cfg, "http.browser", "/usr/bin/openURL"); - } else if (r_file_exists ("/system/bin/toolbox")) { - r_config_set (cfg, "http.browser", + if (rz_file_exists ("/usr/bin/openURL")) { // iOS ericautils + rz_config_set (cfg, "http.browser", "/usr/bin/openURL"); + } else if (rz_file_exists ("/system/bin/toolbox")) { + rz_config_set (cfg, "http.browser", "LD_LIBRARY_PATH=/system/lib am start -a android.intent.action.VIEW -d"); - } else if (r_file_exists ("/usr/bin/xdg-open")) { - r_config_set (cfg, "http.browser", "xdg-open"); - } else if (r_file_exists ("/usr/bin/open")) { - r_config_set (cfg, "http.browser", "open"); + } else if (rz_file_exists ("/usr/bin/xdg-open")) { + rz_config_set (cfg, "http.browser", "xdg-open"); + } else if (rz_file_exists ("/usr/bin/open")) { + rz_config_set (cfg, "http.browser", "open"); } else { - r_config_set (cfg, "http.browser", "firefox"); + rz_config_set (cfg, "http.browser", "firefox"); } - r_config_desc (cfg, "http.browser", "Command to open HTTP URLs"); + rz_config_desc (cfg, "http.browser", "Command to open HTTP URLs"); #endif SETI ("http.maxsize", 0, "Maximum file size for upload"); SETPREF ("http.index", "index.html", "Main html file to check in directory"); @@ -3468,12 +3468,12 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("http.homeroot", R_JOIN_2_PATHS ("~", R2_HOME_WWWROOT), "http home root directory"); #if __WINDOWS__ { - char *wwwroot = r_str_newf ("%s\\share\\www", r_sys_prefix (NULL)); + char *wwwroot = rz_str_newf ("%s\\share\\www", rz_sys_prefix (NULL)); SETPREF ("http.root", wwwroot, "http root directory"); free (wwwroot); } #elif __ANDROID__ - SETPREF ("http.root", "/data/data/org.radare.radare2installer/www", "http root directory"); + SETPREF ("http.root", "/data/data/org.radare.rizininstaller/www", "http root directory"); #else SETPREF ("http.root", R2_WWWROOT, "http root directory"); #endif @@ -3489,12 +3489,12 @@ R_API int r_core_config_init(RCore *core) { SETPREF ("http.uri", "", "Address of HTTP proxy"); SETBPREF ("http.auth", "false", "Enable/Disable HTTP Authentification"); SETPREF ("http.authtok", "r2admin:r2admin", "HTTP Authentification user:password token"); - p = r_sys_getenv ("R2_HTTP_AUTHFILE"); + p = rz_sys_getenv ("R2_HTTP_AUTHFILE"); SETPREF ("http.authfile", p? p : "", "HTTP Authentification user file"); - tmpdir = r_file_tmpdir (); - r_config_set (cfg, "http.uproot", tmpdir); + tmpdir = rz_file_tmpdir (); + rz_config_set (cfg, "http.uproot", tmpdir); free (tmpdir); - r_config_desc (cfg, "http.uproot", "Path where files are uploaded"); + rz_config_desc (cfg, "http.uproot", "Path where files are uploaded"); /* tcp */ SETBPREF ("tcp.islocal", "false", "Bind a loopback for tcp command server"); @@ -3545,20 +3545,20 @@ R_API int r_core_config_init(RCore *core) { /* scr */ #if __EMSCRIPTEN__ - r_config_set_cb (cfg, "scr.fgets", "true", cb_scrfgets); + rz_config_set_cb (cfg, "scr.fgets", "true", cb_scrfgets); #else - r_config_set_cb (cfg, "scr.fgets", "false", cb_scrfgets); + rz_config_set_cb (cfg, "scr.fgets", "false", cb_scrfgets); #endif - r_config_desc (cfg, "scr.fgets", "Use fgets() instead of dietline for prompt input"); + rz_config_desc (cfg, "scr.fgets", "Use fgets() instead of dietline for prompt input"); SETCB ("scr.echo", "false", &cb_screcho, "Show rcons output in realtime to stderr and buffer"); SETICB ("scr.linesleep", 0, &cb_scrlinesleep, "Flush sleeping some ms in every line"); SETICB ("scr.maxtab", 4096, &cb_completion_maxtab, "Change max number of auto completion suggestions"); SETICB ("scr.pagesize", 1, &cb_scrpagesize, "Flush in pages when scr.linesleep is != 0"); SETCB ("scr.flush", "false", &cb_scrflush, "Force flush to console in realtime (breaks scripting)"); - SETBPREF ("scr.slow", "true", "Do slow stuff on visual mode like RFlag.get_at(true)"); + SETBPREF ("scr.slow", "true", "Do slow stuff on visual mode like RzFlag.get_at(true)"); SETCB ("scr.prompt.popup", "false", &cb_scr_prompt_popup, "Show widget dropdown for autocomplete"); #if __WINDOWS__ - SETICB ("scr.vtmode", r_cons_singleton ()->vtmode, + SETICB ("scr.vtmode", rz_cons_singleton ()->vtmode, &scr_vtmode, "Use VT sequences on Windows (0: Disable, 1: Output, 2: Input & Output)"); #endif #if __ANDROID__ @@ -3584,7 +3584,7 @@ R_API int r_core_config_init(RCore *core) { SETCB ("scr.fps", "false", &cb_fps, "Show FPS in Visual"); SETICB ("scr.fix.rows", 0, &cb_fixrows, "Workaround for Linux TTY"); SETICB ("scr.fix.columns", 0, &cb_fixcolumns, "Workaround for Prompt iOS SSH client"); - SETCB ("scr.highlight", "", &cb_scrhighlight, "Highlight that word at RCons level"); + SETCB ("scr.highlight", "", &cb_scrhighlight, "Highlight that word at RzCons level"); SETCB ("scr.interactive", "true", &cb_scrint, "Start in interactive mode"); SETCB ("scr.bgfill", "false", &cb_scr_bgfill, "Fill background for ascii art when possible"); SETI ("scr.feedback", 1, "Set visual feedback level (1=arrow on jump, 2=every key (useful for videos))"); @@ -3605,14 +3605,14 @@ R_API int r_core_config_init(RCore *core) { SETCB ("scr.tee", "", &cb_teefile, "Pipe output to file of this name"); SETPREF ("scr.seek", "", "Seek to the specified address on startup"); SETICB ("scr.color", (core->print->flags&R_PRINT_FLAGS_COLOR)?COLOR_MODE_16:COLOR_MODE_DISABLED, &cb_color, "Enable colors (0: none, 1: ansi, 2: 256 colors, 3: truecolor)"); - r_config_set_getter (cfg, "scr.color", (RConfigCallback)cb_color_getter); + rz_config_set_getter (cfg, "scr.color", (RConfigCallback)cb_color_getter); SETCB ("scr.color.grep", "false", &cb_scr_color_grep, "Enable colors when using ~grep"); SETBPREF ("scr.color.pipe", "false", "Enable colors when using pipes"); SETBPREF ("scr.color.ops", "true", "Colorize numbers and registers in opcodes"); SETBPREF ("scr.color.args", "true", "Colorize arguments and variables of functions"); SETBPREF ("scr.color.bytes", "true", "Colorize bytes that represent the opcodes of the instruction"); SETCB ("scr.null", "false", &cb_scrnull, "Show no output"); - SETCB ("scr.utf8", r_str_bool (r_cons_is_utf8()), &cb_utf8, "Show UTF-8 characters instead of ANSI"); + SETCB ("scr.utf8", rz_str_bool (rz_cons_is_utf8()), &cb_utf8, "Show UTF-8 characters instead of ANSI"); SETCB ("scr.utf8.curvy", "false", &cb_utf8_curvy, "Show curved UTF-8 corners (requires scr.utf8)"); SETBPREF ("scr.demo", "false", "Use demoscene effects if available"); SETBPREF ("scr.histsave", "true", "Always save history on exit"); @@ -3701,8 +3701,8 @@ R_API int r_core_config_init(RCore *core) { switch (i) { default: p = ""; break; } - r_config_set (cfg, buf, p); - r_config_desc (cfg, buf, buf+10); + rz_config_set (cfg, buf, p); + rz_config_desc (cfg, buf, buf+10); } /* zoom */ @@ -3724,60 +3724,60 @@ R_API int r_core_config_init(RCore *core) { SETCB ("lines.to", "$s", &cb_linesto, "End address for line seek"); SETCB ("lines.abs", "false", &cb_linesabs, "Enable absolute line numbers"); - r_config_lock (cfg, true); + rz_config_lock (cfg, true); return true; } -R_API void r_core_parse_radare2rc(RCore *r) { - bool has_debug = r_sys_getenv_asbool ("R2_DEBUG"); - char *rcfile = r_sys_getenv ("R2_RCFILE"); +RZ_API void rz_core_parse_rizinrc(RzCore *r) { + bool has_debug = rz_sys_getenv_asbool ("R2_DEBUG"); + char *rcfile = rz_sys_getenv ("R2_RCFILE"); char *homerc = NULL; if (!R_STR_ISEMPTY (rcfile)) { homerc = rcfile; } else { free (rcfile); - homerc = r_str_home (".radare2rc"); + homerc = rz_str_home (".rizinrc"); } - if (homerc && r_file_is_regular (homerc)) { + if (homerc && rz_file_is_regular (homerc)) { if (has_debug) { eprintf ("USER CONFIG loaded from %s\n", homerc); } - r_core_cmd_file (r, homerc); + rz_core_cmd_file (r, homerc); } free (homerc); - homerc = r_str_home (R2_HOME_RC); - if (homerc && r_file_is_regular (homerc)) { + homerc = rz_str_home (R2_HOME_RC); + if (homerc && rz_file_is_regular (homerc)) { if (has_debug) { eprintf ("USER CONFIG loaded from %s\n", homerc); } - r_core_cmd_file (r, homerc); + rz_core_cmd_file (r, homerc); } free (homerc); - homerc = r_str_home (R2_HOME_RC_DIR); + homerc = rz_str_home (R2_HOME_RC_DIR); if (homerc) { - if (r_file_is_directory (homerc)) { + if (rz_file_is_directory (homerc)) { char *file; - RListIter *iter; - RList *files = r_sys_dir (homerc); - r_list_foreach (files, iter, file) { + RzListIter *iter; + RzList *files = rz_sys_dir (homerc); + rz_list_foreach (files, iter, file) { if (*file != '.') { - char *path = r_str_newf ("%s/%s", homerc, file); - if (r_file_is_regular (path)) { + char *path = rz_str_newf ("%s/%s", homerc, file); + if (rz_file_is_regular (path)) { if (has_debug) { eprintf ("USER CONFIG loaded from %s\n", homerc); } - r_core_cmd_file (r, path); + rz_core_cmd_file (r, path); } free (path); } } - r_list_free (files); + rz_list_free (files); } free (homerc); } } -R_API void r_core_config_update(RCore *core) { - RConfigNode *cmdpdc = r_config_node_get (core->config, "cmd.pdc"); +RZ_API void rz_core_config_update(RzCore *core) { + RConfigNode *cmdpdc = rz_config_node_get (core->config, "cmd.pdc"); update_cmdpdc_options (core, cmdpdc); } diff --git a/librz/core/cfile.c b/librz/core/cfile.c new file mode 100644 index 0000000000..8bd6b03936 --- /dev/null +++ b/librz/core/cfile.c @@ -0,0 +1,1303 @@ +/* radare - LGPL - Copyright 2009-2019 - pancake */ + +#include +#include +#include + +#define UPDATE_TIME(a) (r->times->file_open_time = rz_time_now_mono () - (a)) + +static int rz_core_file_do_load_for_debug(RzCore *r, ut64 loadaddr, const char *filenameuri); +static int rz_core_file_do_load_for_io_plugin(RzCore *r, ut64 baseaddr, ut64 loadaddr); + +static bool __isMips (RzAsm *a) { + return a && a->cur && a->cur->arch && strstr (a->cur->arch, "mips"); +} + +static void loadGP(RzCore *core) { + if (__isMips (core->rasm)) { + ut64 gp = rz_num_math (core->num, "loc._gp"); + if (!gp || gp == UT64_MAX) { + rz_config_set (core->config, "anal.roregs", "zero"); + rz_core_cmd0 (core, "10aes@entry0"); + rz_config_set (core->config, "anal.roregs", "zero,gp"); + gp = rz_reg_getv (core->anal->reg, "gp"); + } + // eprintf ("[mips] gp: 0x%08"PFMT64x"\n", gp); + rz_config_set_i (core->config, "anal.gp", gp); + } +} + + +RZ_API int rz_core_file_reopen(RzCore *core, const char *args, int perm, int loadbin) { + int isdebug = rz_config_get_i (core->config, "cfg.debug"); + char *path; + ut64 laddr = rz_config_get_i (core->config, "bin.laddr"); + RzCoreFile *file = NULL; + RzCoreFile *ofile = core->file; + RBinFile *bf = ofile ? rz_bin_file_find_by_fd (core->bin, ofile->fd) + : NULL; + RzIODesc *odesc = (core->io && ofile) ? rz_io_desc_get (core->io, ofile->fd) : NULL; + char *ofilepath = NULL, *obinfilepath = (bf && bf->file)? strdup (bf->file): NULL; + int ret = false; + ut64 origoff = core->offset; + if (odesc) { + if (odesc->referer) { + ofilepath = odesc->referer; + } else if (odesc->uri) { + ofilepath = odesc->uri; + } + } + + ut64 new_baddr = UT64_MAX; + if (args) { + new_baddr = rz_num_math (core->num, args); + if (new_baddr && new_baddr != UT64_MAX) { + rz_config_set_i (core->config, "bin.baddr", new_baddr); + } else { + new_baddr = UT64_MAX; + } + } + if (new_baddr == UT64_MAX) { + new_baddr = rz_config_get_i (core->config, "bin.baddr"); + } + + if (rz_sandbox_enable (0)) { + eprintf ("Cannot reopen in sandbox\n"); + free (obinfilepath); + return false; + } + if (!core->file) { + eprintf ("No file opened to reopen\n"); + free (ofilepath); + free (obinfilepath); + return false; + } + int newpid = odesc? odesc->fd: -1; + + if (isdebug) { + rz_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, 9); // SIGKILL + do { + rz_debug_continue (core->dbg); + } while (!rz_debug_is_dead (core->dbg)); + rz_debug_detach (core->dbg, core->dbg->pid); + perm = 7; + } else { + if (!perm) { + perm = 4; //R_PERM_R; + } + } + if (!ofilepath) { + eprintf ("Unknown file path"); + free (obinfilepath); + return false; + } + + // HACK: move last mapped address to higher place + // XXX - why does this hack work? + // when the new memory maps are created. + path = strdup (ofilepath); + free (obinfilepath); + obinfilepath = strdup (ofilepath); + + // rz_str_trim (path); + file = rz_core_file_open (core, path, perm, laddr); + + if (isdebug) { + int newtid = newpid; + // XXX - select the right backend + if (core->file) { + newpid = rz_io_fd_get_pid (core->io, core->file->fd); + newtid = rz_io_fd_get_tid (core->io, core->file->fd); +#if __linux__ + core->dbg->main_pid = newpid; + newtid = newpid; +#endif + } + // Reset previous pid and tid + core->dbg->pid = -1; + core->dbg->tid = -1; + core->dbg->recoil_mode = R_DBG_RECOIL_NONE; + memset (&core->dbg->reason, 0, sizeof (core->dbg->reason)); + // Reopen and attach + rz_core_setup_debugger (core, "native", true); + rz_debug_select (core->dbg, newpid, newtid); + } + + if (file) { + bool had_rbin_info = false; + + if (ofile && bf) { + if (rz_bin_file_delete (core->bin, bf->id)) { + had_rbin_info = true; + } + } + rz_core_file_close (core, ofile); + rz_core_file_set_by_file (core, file); + ofile = NULL; + odesc = NULL; + // core->file = file; + eprintf ("File %s reopened in %s mode\n", path, + (perm & R_PERM_W)? "read-write": "read-only"); + + if (loadbin && (loadbin == 2 || had_rbin_info)) { + ut64 baddr; + if (isdebug) { + baddr = rz_debug_get_baddr (core->dbg, path); + } else if (new_baddr != UT64_MAX) { + baddr = new_baddr; + } else { + baddr = rz_config_get_i (core->config, "bin.baddr"); + } + ret = rz_core_bin_load (core, obinfilepath, baddr); + rz_core_bin_update_arch_bits (core); + if (!ret) { + eprintf ("Error: Failed to reload rbin for: %s", path); + } + origoff = rz_num_math (core->num, "entry0"); + } + + if (core->bin->cur && core->io && rz_io_desc_get (core->io, file->fd) && !loadbin) { + //force here NULL because is causing uaf look this better in future XXX @alvarofe + core->bin->cur = NULL; + } + // close old file + } else if (ofile) { + eprintf ("rz_core_file_reopen: Cannot reopen file: %s with perms 0x%x," + " attempting to open read-only.\n", path, perm); + // lower it down back + //ofile = rz_core_file_open (core, path, R_PERM_R, addr); + rz_core_file_set_by_file (core, ofile); + } else { + eprintf ("Cannot reopen\n"); + } + if (core->file) { + rz_io_use_fd (core->io, core->file->fd); + core->switch_file_view = 1; + rz_core_block_read (core); +#if 0 + else { + const char *name = (cf && cf->desc)? cf->desc->name: "ERROR"; + eprintf ("Error: Unable to switch the view to file: %s\n", name); + } +#endif + } + rz_core_seek (core, origoff, true); + if (isdebug) { + rz_core_cmd0 (core, ".dm*"); + rz_core_cmd0 (core, ".dr*"); + rz_core_cmd0 (core, "sr PC"); + } else { + loadGP (core); + } + // update anal io bind + rz_io_bind (core->io, &(core->anal->iob)); + if (core->file && core->file->fd >= 0) { + rz_core_cmd0 (core, "o-!"); + } + rz_core_file_close_all_but (core); + // This is done to ensure that the file is correctly + // loaded into the view + free (obinfilepath); + //free (ofilepath); + free (path); + return ret; +} + +RZ_API void rz_core_sysenv_end(RzCore *core, const char *cmd) { + // TODO: remove tmpfilez + if (strstr (cmd, "R2_BLOCK")) { + // remove temporary BLOCK file + char *f = rz_sys_getenv ("R2_BLOCK"); + if (f) { + rz_file_rm (f); + rz_sys_setenv ("R2_BLOCK", NULL); + free (f); + } + } + rz_sys_setenv ("R2_FILE", NULL); + rz_sys_setenv ("R2_BYTES", NULL); + rz_sys_setenv ("R2_OFFSET", NULL); + + // remove temporary R2_CONFIG file + char *r2_config = rz_sys_getenv ("R2_CONFIG"); + if (r2_config) { + rz_file_rm (r2_config); + rz_sys_setenv ("R2_CONFIG", NULL); + free (r2_config); + } +} + +#if DISCUSS +EDITOR rz_sys_setenv ("EDITOR", rz_config_get (core->config, "cfg.editor")); +CURSOR cursor position (offset from curseek) +VERBOSE cfg.verbose +#endif + +RZ_API char *rz_core_sysenv_begin(RzCore * core, const char *cmd) { + char *f, *ret = cmd? strdup (cmd): NULL; + RzIODesc *desc = core->file ? rz_io_desc_get (core->io, core->file->fd) : NULL; + if (cmd && strstr (cmd, "R2_BYTES")) { + char *s = rz_hex_bin2strdup (core->block, core->blocksize); + rz_sys_setenv ("R2_BYTES", s); + free (s); + } + rz_sys_setenv ("RABIN2_PDBSERVER", rz_config_get (core->config, "pdb.server")); + if (desc && desc->name) { + rz_sys_setenv ("R2_FILE", desc->name); + rz_sys_setenv ("R2_SIZE", sdb_fmt ("%"PFMT64d, rz_io_desc_size (desc))); + if (cmd && strstr (cmd, "R2_BLOCK")) { + // replace BLOCK in RET string + if ((f = rz_file_temp ("r2block"))) { + if (rz_file_dump (f, core->block, core->blocksize, 0)) { + rz_sys_setenv ("R2_BLOCK", f); + } + free (f); + } + } + } + rz_sys_setenv ("R2_OFFSET", sdb_fmt ("%"PFMT64d, core->offset)); + rz_sys_setenv ("R2_XOFFSET", sdb_fmt ("0x%08"PFMT64x, core->offset)); + rz_sys_setenv ("R2_ENDIAN", core->rasm->big_endian? "big": "little"); + rz_sys_setenv ("R2_BSIZE", sdb_fmt ("%d", core->blocksize)); + + // dump current config file so other r2 tools can use the same options + char *config_sdb_path = NULL; + int config_sdb_fd = rz_file_mkstemp (NULL, &config_sdb_path); + if (config_sdb_fd >= 0) { + close (config_sdb_fd); + } + + Sdb *config_sdb = sdb_new (NULL, config_sdb_path, 0); + rz_config_serialize (core->config, config_sdb); + sdb_sync (config_sdb); + sdb_free (config_sdb); + rz_sys_setenv ("R2_CONFIG", config_sdb_path); + + rz_sys_setenv ("RABIN2_LANG", rz_config_get (core->config, "bin.lang")); + rz_sys_setenv ("RABIN2_DEMANGLE", rz_config_get (core->config, "bin.demangle")); + rz_sys_setenv ("R2_ARCH", rz_config_get (core->config, "asm.arch")); + rz_sys_setenv ("R2_BITS", sdb_fmt ("%d", rz_config_get_i (core->config, "asm.bits"))); + rz_sys_setenv ("R2_COLOR", rz_config_get_i (core->config, "scr.color")? "1": "0"); + rz_sys_setenv ("R2_DEBUG", rz_config_get_i (core->config, "cfg.debug")? "1": "0"); + rz_sys_setenv ("R2_IOVA", rz_config_get_i (core->config, "io.va")? "1": "0"); + free (config_sdb_path); + return ret; +} + +#if !__linux__ && !__WINDOWS__ +static ut64 get_base_from_maps(RzCore *core, const char *file) { + RzDebugMap *map; + RzListIter *iter; + ut64 b = 0LL; + + rz_debug_map_sync (core->dbg); // update process memory maps + rz_list_foreach (core->dbg->maps, iter, map) { + if ((map->perm & 5) == 5) { + // TODO: make this more flexible + // XXX - why "copy/" here? + if (map->name && strstr (map->name, "copy/")) { + return map->addr; + } + if (map->file && !strcmp (map->file, file)) { + return map->addr; + } + if (map->name && !strcmp (map->name, file)) { + return map->addr; + } + // XXX - Commented out, as this could unexpected results + //b = map->addr; + } + } + // fallback resolution copied from cmd_debug.c:rz_debug_get_baddr + rz_list_foreach (core->dbg->maps, iter, map) { + if (map->perm == 5) { // r-x + return map->addr; + } + } + + return b; +} +#endif + +#if __linux__ || __APPLE__ +static bool setbpint(RzCore *r, const char *mode, const char *sym) { + RBreakpointItem *bp; + RzFlagItem *fi = rz_flag_get (r->flags, sym); + if (!fi) { + return false; + } + bp = rz_bp_add_sw (r->dbg->bp, fi->offset, 1, R_BP_PROT_EXEC); + if (bp) { + bp->internal = true; +#if __linux__ + bp->data = rz_str_newf ("?e %s: %s", mode, sym); +#else + bp->data = rz_str_newf ("?e %s: %s;ps@rdi", mode, sym); +#endif + return true; + } + eprintf ("Cannot set breakpoint at %s\n", sym); + return false; +} +#endif + +// XXX - need to handle index selection during debugging +static int rz_core_file_do_load_for_debug(RzCore *r, ut64 baseaddr, const char *filenameuri) { + RzCoreFile *cf = rz_core_file_cur (r); + RzIODesc *desc = cf ? rz_io_desc_get (r->io, cf->fd) : NULL; + RBinFile *binfile = NULL; + RBinPlugin *plugin; + int xtr_idx = 0; // if 0, load all if xtr is used + + // TODO : Honor file.path eval var too? + if (!strncmp ("dbg://", filenameuri, 6)) { + filenameuri += 6; + } + if (!desc) { + return false; + } + if (cf) { + rz_debug_select (r->dbg, rz_io_fd_get_pid (r->io, cf->fd), + rz_io_fd_get_tid (r->io, cf->fd)); + } +#if !__linux__ +#if !__WINDOWS__ + baseaddr = get_base_from_maps (r, filenameuri); +#endif + if (baseaddr != UT64_MAX) { + rz_config_set_i (r->config, "bin.baddr", baseaddr); + } +#endif + int fd = cf? cf->fd: -1; + RBinOptions opt; + rz_bin_options_init (&opt, fd, baseaddr, UT64_MAX, false); + opt.xtr_idx = xtr_idx; + if (!rz_bin_open (r->bin, filenameuri, &opt)) { + eprintf ("RBinLoad: Cannot open %s\n", filenameuri); + if (rz_config_get_i (r->config, "bin.rawstr")) { + rz_bin_options_init (&opt, fd, baseaddr, UT64_MAX, true); + opt.xtr_idx = xtr_idx; + if (!rz_bin_open (r->bin, filenameuri, &opt)) { + return false; + } + } + } + + if (*rz_config_get (r->config, "dbg.libs")) { + rz_core_cmd0 (r, ".dmm*"); +#if __linux__ + setbpint (r, "dbg.libs", "sym.imp.dlopen"); + setbpint (r, "dbg.libs", "sym.imp.dlmopen"); + setbpint (r, "dbg.unlibs", "sym.imp.dlclose"); +#elif __APPLE__ + setbpint (r, "dbg.libs", "sym._dlopen"); + setbpint (r, "dbg.libs", "sym._dlclose"); +#endif + } + binfile = rz_bin_cur (r->bin); + rz_core_bin_set_env (r, binfile); + plugin = rz_bin_file_cur_plugin (binfile); + if (plugin && !strncmp (plugin->name, "any", 5)) { + // set use of raw strings + // rz_config_set_i (r->config, "io.va", false); + //\\ rz_config_set (r->config, "bin.rawstr", "true"); + // get bin.minstr + r->bin->minstrlen = rz_config_get_i (r->config, "bin.minstr"); + r->bin->maxstrbuf = rz_config_get_i (r->config, "bin.maxstrbuf"); + } else if (binfile) { + RBinObject *obj = rz_bin_cur_object (r->bin); + RBinInfo *info = obj? obj->info: NULL; + if (plugin && strcmp (plugin->name, "any") && info) { + rz_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); + } + } + + if (plugin && !strcmp (plugin->name, "dex")) { + rz_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ; wx `ph adler32 $s-12 @12` @8)\"\n"); + } + + return true; +} + +static int rz_core_file_do_load_for_io_plugin(RzCore *r, ut64 baseaddr, ut64 loadaddr) { + RzCoreFile *cf = rz_core_file_cur (r); + int fd = cf ? cf->fd : -1; + RBinFile *binfile = NULL; + int xtr_idx = 0; // if 0, load all if xtr is used + RBinPlugin *plugin; + + if (fd < 0) { + return false; + } + rz_io_use_fd (r->io, fd); + RBinOptions opt; + rz_bin_options_init (&opt, fd, baseaddr, loadaddr, r->bin->rawstr); + opt.xtr_idx = xtr_idx; + if (!rz_bin_open_io (r->bin, &opt)) { + //eprintf ("Failed to load the bin with an IO Plugin.\n"); + return false; + } + binfile = rz_bin_cur (r->bin); + if (rz_core_bin_set_env (r, binfile)) { + if (!r->anal->sdb_cc->path) { + R_LOG_WARN ("No calling convention defined for this file, analysis may be inaccurate.\n"); + } + } + plugin = rz_bin_file_cur_plugin (binfile); + if (plugin && !strcmp (plugin->name, "any")) { + RBinObject *obj = rz_bin_cur_object (r->bin); + RBinInfo *info = obj? obj->info: NULL; + if (!info) { + return false; + } + // set use of raw strings + rz_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); + // rz_config_set_i (r->config, "io.va", false); + // rz_config_set (r->config, "bin.rawstr", "true"); + // get bin.minstr + r->bin->minstrlen = rz_config_get_i (r->config, "bin.minstr"); + r->bin->maxstrbuf = rz_config_get_i (r->config, "bin.maxstrbuf"); + } else if (binfile) { + RBinObject *obj = rz_bin_cur_object (r->bin); + RBinInfo *info = obj? obj->info: NULL; + if (!info) { + return false; + } + if (plugin && strcmp (plugin->name, "any") && info) { + rz_core_bin_set_arch_bits (r, binfile->file, + info->arch, info->bits); + } + } + + if (plugin && !strcmp (plugin->name, "dex")) { + rz_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ; wx `ph adler32 $s-12 @12` @8)\"\n"); + } + return true; +} + +static bool try_loadlib(RzCore *core, const char *lib, ut64 addr) { + if (rz_core_file_open (core, lib, 0, addr) != NULL) { + rz_core_bin_load (core, lib, addr); + return true; + } + return false; +} + +RZ_API bool rz_core_file_loadlib(RzCore *core, const char *lib, ut64 libaddr) { + const char *dirlibs = rz_config_get (core->config, "dir.libs"); + bool free_libdir = true; +#ifdef __WINDOWS__ + char *libdir = rz_str_rz_prefix (R2_LIBDIR); +#else + char *libdir = strdup (R2_LIBDIR); +#endif + if (!libdir) { + libdir = R2_LIBDIR; + free_libdir = false; + } + if (!dirlibs || !*dirlibs) { + dirlibs = "." R_SYS_DIR; + } + const char *ldlibrarypath[] = { + dirlibs, + libdir, +#ifndef __WINDOWS__ + "/usr/local/lib", + "/usr/lib", + "/lib", +#endif + "." R_SYS_DIR, + NULL + }; + const char * *libpath = (const char * *) &ldlibrarypath; + + bool ret = false; +#ifdef __WINDOWS__ + if (strlen (lib) >= 3 && lib[1] == ':' && lib[2] == '\\') { +#else + if (*lib == '/') { +#endif + if (try_loadlib (core, lib, libaddr)) { + ret = true; + } + } else { + while (*libpath) { + char *s = rz_str_newf ("%s" R_SYS_DIR "%s", *libpath, lib); + if (try_loadlib (core, s, libaddr)) { + ret = true; + } + free (s); + if (ret) { + break; + } + libpath++; + } + } + if (free_libdir) { + free (libdir); + } + return ret; +} + +RZ_API int rz_core_bin_rebase(RzCore *core, ut64 baddr) { + if (!core || !core->bin || !core->bin->cur) { + return 0; + } + if (baddr == UT64_MAX) { + return 0; + } + RBinFile *bf = core->bin->cur; + bf->o->baddr = baddr; + bf->o->loadaddr = baddr; + rz_bin_object_set_items (bf, bf->o); + return 1; +} + +static void load_scripts_for(RzCore *core, const char *name) { + // TODO: + char *file; + RzListIter *iter; + char *hdir = rz_str_newf (R_JOIN_2_PATHS (R2_HOME_BINRC, "bin-%s"), name); + char *path = rz_str_home (hdir); + RzList *files = rz_sys_dir (path); + if (!rz_list_empty (files)) { + eprintf ("[binrc] path: %s\n", path); + } + rz_list_foreach (files, iter, file) { + if (*file && *file != '.') { + eprintf ("[binrc] loading %s\n", file); + rz_core_cmdf (core, ". %s/%s", path, file); + } + } + rz_list_free (files); + free (path); + free (hdir); +} + +typedef struct { + const char *name; + bool found; +} RzCoreFileData; + +static bool filecb(void *user, void *data, ut32 id) { + RzCoreFileData *fd = user; + RzIODesc *desc = (RzIODesc *)data; + if (!strcmp (desc->name, fd->name)) { + fd->found = true; + } + return true; +} + +typedef struct { + const char *name; + ut64 addr; + RBin *bin; +} RzCoreLinkData; + +static bool linkcb(void *user, void *data, ut32 id) { + RzCoreLinkData *ld = user; + RzIODesc *desc = (RzIODesc *)data; + + RBinFile *bf = rz_bin_file_find_by_fd (ld->bin, desc->fd); + if (bf) { + RzListIter *iter; + RBinSymbol *sym; + RzList *symbols = rz_bin_file_get_symbols (bf); + rz_list_foreach (symbols, iter, sym) { + if (!strcmp (sym->name, ld->name)) { + ld->addr = sym->vaddr; + return false; + } + } + } + return true; +} + + +RZ_API bool rz_core_bin_load(RzCore *r, const char *filenameuri, ut64 baddr) { + RzCoreFile *cf = rz_core_file_cur (r); + RzIODesc *desc = cf ? rz_io_desc_get (r->io, cf->fd) : NULL; + ut64 laddr = rz_config_get_i (r->config, "bin.laddr"); + RBinFile *binfile = NULL; + RBinPlugin *plugin = NULL; + bool is_io_load; + const char *cmd_load; + if (!cf) { + return false; + } + // NULL deref guard + if (desc) { + is_io_load = desc && desc->plugin; + if (!filenameuri || !*filenameuri) { + filenameuri = desc->name; + } + } else { + is_io_load = false; + } + + if (!filenameuri) { + eprintf ("rz_core_bin_load: no file specified\n"); + return false; + } + + r->bin->minstrlen = rz_config_get_i (r->config, "bin.minstr"); + r->bin->maxstrbuf = rz_config_get_i (r->config, "bin.maxstrbuf"); + if (is_io_load) { + // TODO? necessary to restore the desc back? + // Fix to select pid before trying to load the binary + if ((desc->plugin && desc->plugin->isdbg) || rz_config_get_i (r->config, "cfg.debug")) { + rz_core_file_do_load_for_debug (r, baddr, filenameuri); + } else { + rz_core_file_do_load_for_io_plugin (r, baddr, 0LL); + } + rz_io_use_fd (r->io, desc->fd); + // Restore original desc + } + if (cf && binfile && desc) { + binfile->fd = desc->fd; + } + binfile = rz_bin_cur (r->bin); + if (r->bin->cur && r->bin->cur->o && r->bin->cur->o->plugin && r->bin->cur->o->plugin->strfilter) { + char msg[2]; + msg[0] = r->bin->cur->o->plugin->strfilter; + msg[1] = 0; + rz_config_set (r->config, "bin.str.filter", msg); + } + //rz_core_bin_set_env (r, binfile); + plugin = rz_bin_file_cur_plugin (binfile); + if (plugin && plugin->name) { + load_scripts_for (r, plugin->name); + } + cmd_load = rz_config_get (r->config, "cmd.load"); + if (cmd_load && *cmd_load) { + rz_core_cmd (r, cmd_load, 0); + } + + if (plugin && plugin->name) { + if (!strcmp (plugin->name, "any")) { + if (rz_str_startswith (desc->name, "rap") && strstr (desc->name, "://")) { + rz_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, UT64_MAX); + } else { + rz_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, rz_io_desc_size (desc)); + } + // set use of raw strings + //rz_config_set (r->config, "bin.rawstr", "true"); + // rz_config_set_i (r->config, "io.va", false); + // get bin.minstr + r->bin->minstrlen = rz_config_get_i (r->config, "bin.minstr"); + r->bin->maxstrbuf = rz_config_get_i (r->config, "bin.maxstrbuf"); + } else if (binfile) { + RBinObject *obj = rz_bin_cur_object (r->bin); + if (obj) { + bool va = obj->info ? obj->info->has_va : 0; + if (!va) { + rz_config_set_i (r->config, "io.va", 0); + } + //workaround to map correctly malloc:// and raw binaries + if (rz_io_desc_is_dbg (desc) || (!obj->sections || !va)) { + rz_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, rz_io_desc_size (desc)); + } + RBinInfo *info = obj->info; + if (info) { + rz_core_bin_set_arch_bits (r, binfile->file, info->arch, info->bits); + } else { + rz_core_bin_set_arch_bits (r, binfile->file, + rz_config_get (r->config, "asm.arch"), + rz_config_get_i (r->config, "asm.bits")); + } + } + } + } else { + if (desc) { + rz_io_map_new (r->io, desc->fd, desc->perm, 0, laddr, rz_io_desc_size (desc)); + } + if (binfile) { + rz_core_bin_set_arch_bits (r, binfile->file, + rz_config_get (r->config, "asm.arch"), + rz_config_get_i (r->config, "asm.bits")); + } + } + if (desc && rz_config_get_i (r->config, "io.exec")) { + desc->perm |= R_PERM_X; + } + if (plugin && plugin->name && !strcmp (plugin->name, "dex")) { + rz_core_cmd0 (r, "\"(fix-dex,wx `ph sha1 $s-32 @32` @12 ;" + " wx `ph adler32 $s-12 @12` @8)\"\n"); + } + if (!rz_config_get_i (r->config, "cfg.debug")) { + loadGP (r); + } + if (rz_config_get_i (r->config, "bin.libs")) { + const char *lib; + RzListIter *iter; + RzList *libs = rz_bin_get_libs (r->bin); + rz_list_foreach (libs, iter, lib) { + eprintf ("[bin.libs] Opening %s\n", lib); + RzCoreFileData filedata = {lib, false}; + rz_id_storage_foreach (r->io->files, filecb, &filedata); + if (filedata.found) { + eprintf ("Already opened\n"); + continue; + } + ut64 baddr = rz_io_map_location (r->io, 0x200000); + if (baddr != UT64_MAX) { + rz_core_file_loadlib (r, lib, baddr); + } + } + rz_core_cmd0 (r, "obb 0;s entry0"); + rz_config_set_i (r->config, "bin.at", true); + eprintf ("[bin.libs] Linking imports...\n"); + RBinImport *imp; + RzList *imports = rz_bin_get_imports (r->bin); + rz_list_foreach (imports, iter, imp) { + // PLT finding + RzFlagItem *impsym = rz_flag_get (r->flags, sdb_fmt ("sym.imp.%s", imp->name)); + if (!impsym) { + //eprintf ("Cannot find '%s' import in the PLT\n", imp->name); + continue; + } + ut64 imp_addr = impsym->offset; + eprintf ("Resolving %s... ", imp->name); + RzCoreLinkData linkdata = {imp->name, UT64_MAX, r->bin}; + rz_id_storage_foreach (r->io->files, linkcb, &linkdata); + if (linkdata.addr != UT64_MAX) { + eprintf ("0x%08"PFMT64x"\n", linkdata.addr); + ut64 a = linkdata.addr; + ut64 b = imp_addr; + rz_core_cmdf (r, "ax 0x%08"PFMT64x" 0x%08"PFMT64x, a, b); + } else { + eprintf ("NO\n"); + } + } + } + + //If type == R_BIN_TYPE_CORE, we need to create all the maps + if (plugin && binfile && plugin->file_type + && plugin->file_type (binfile) == R_BIN_TYPE_CORE) { + ut64 sp_addr = (ut64)-1; + RzIOMap *stack_map = NULL; + + // Setting the right arch and bits, so regstate will be shown correctly + if (plugin->info) { + RBinInfo *inf = plugin->info (binfile); + eprintf ("Setting up coredump arch-bits to: %s-%d\n", inf->arch, inf->bits); + rz_config_set (r->config, "asm.arch", inf->arch); + rz_config_set_i (r->config, "asm.bits", inf->bits); + rz_bin_info_free (inf); + } + if (binfile->o->regstate) { + if (rz_reg_arena_set_bytes (r->anal->reg, binfile->o->regstate)) { + eprintf ("Setting up coredump: Problem while setting the registers\n"); + } else { + eprintf ("Setting up coredump: Registers have been set\n"); + const char *regname = rz_reg_get_name (r->anal->reg, R_REG_NAME_SP); + if (regname) { + RzRegItem *reg = rz_reg_get (r->anal->reg, regname, -1); + if (reg) { + sp_addr = rz_reg_get_value (r->anal->reg, reg); + stack_map = rz_io_map_get (r->io, sp_addr); + } + } + regname = rz_reg_get_name (r->anal->reg, R_REG_NAME_PC); + if (regname) { + RzRegItem *reg = rz_reg_get (r->anal->reg, regname, -1); + if (reg) { + ut64 seek = rz_reg_get_value (r->anal->reg, reg); + rz_core_seek (r, seek, true); + } + } + } + } + + RBinObject *o = binfile->o; + int map = 0; + if (o && o->maps) { + RzList *maps = o->maps; + RzListIter *iter; + RBinMap *mapcore; + + rz_list_foreach (maps, iter, mapcore) { + RzIOMap *iomap = rz_io_map_get (r->io, mapcore->addr); + if (iomap && (mapcore->file || stack_map == iomap)) { + rz_io_map_set_name (iomap, mapcore->file ? mapcore->file : "[stack]"); + } + map++; + } + rz_list_free (maps); + o->maps = NULL; + } + eprintf ("Setting up coredump: %d maps have been found and created\n", map); + goto beach; + } +beach: + return true; +} + +RZ_API RzCoreFile *rz_core_file_open_many(RzCore *r, const char *file, int perm, ut64 loadaddr) { + const bool openmany = rz_config_get_i (r->config, "file.openmany"); + int opened_count = 0; + RzListIter *fd_iter, *iter2; + RzIODesc *fd; + + RzList *list_fds = rz_io_open_many (r->io, file, perm, 0644); + + if (!list_fds || rz_list_length (list_fds) == 0) { + rz_list_free (list_fds); + return NULL; + } + + rz_list_foreach_safe (list_fds, fd_iter, iter2, fd) { + opened_count++; + if (openmany && opened_count > 1) { + // XXX - Open Many should limit the number of files + // loaded in io plugin area this needs to be more premptive + // like down in the io plugin layer. + // start closing down descriptors + rz_list_delete (list_fds, fd_iter); + continue; + } + RzCoreFile *fh = R_NEW0 (RzCoreFile); + if (fh) { + fh->alive = 1; + fh->core = r; + fh->fd = fd->fd; + r->file = fh; + rz_bin_bind (r->bin, &(fh->binb)); + rz_list_append (r->files, fh); + rz_core_bin_load (r, fd->name, loadaddr); + } + } + return NULL; +} + +/* loadaddr is r2 -m (mapaddr) */ +RZ_API RzCoreFile *rz_core_file_open(RzCore *r, const char *file, int flags, ut64 loadaddr) { + rz_return_val_if_fail (r && file, NULL); + ut64 prev = rz_time_now_mono (); + const bool openmany = rz_config_get_i (r->config, "file.openmany"); + RzCoreFile *fh = NULL; + + if (!strcmp (file, "-")) { + file = "malloc://512"; + } + //if not flags was passed open it with -r-- + if (!flags) { + flags = R_PERM_R; + } + r->io->bits = r->rasm->bits; // TODO: we need an api for this + RzIODesc *fd = rz_io_open_nomap (r->io, file, flags, 0644); + if (rz_cons_is_breaked()) { + goto beach; + } + if (!fd && openmany) { + // XXX - make this an actual option somewhere? + fh = rz_core_file_open_many (r, file, flags, loadaddr); + if (fh) { + goto beach; + } + } + if (!fd) { + if (flags & R_PERM_W) { + // flags |= R_IO_CREAT; + if (!(fd = rz_io_open_nomap (r->io, file, flags, 0644))) { + goto beach; + } + } else { + goto beach; + } + } + if (rz_io_is_listener (r->io)) { + rz_core_serve (r, fd); + rz_io_desc_free (fd); + goto beach; + } + + fh = R_NEW0 (RzCoreFile); + if (!fh) { + eprintf ("core/file.c: rz_core_open failed to allocate RzCoreFile.\n"); + goto beach; + } + fh->alive = 1; + fh->core = r; + fh->fd = fd->fd; + { + const char *cp = rz_config_get (r->config, "cmd.open"); + if (cp && *cp) { + rz_core_cmd (r, cp, 0); + } + char *absfile = rz_file_abspath (file); + rz_config_set (r->config, "file.path", absfile); + free (absfile); + } + // check load addr to make sure its still valid + rz_bin_bind (r->bin, &(fh->binb)); + + if (!r->files) { + r->files = rz_list_newf ((RzListFree)rz_core_file_free); + } + + r->file = fh; + rz_io_use_fd (r->io, fd->fd); + + rz_list_append (r->files, fh); + if (rz_config_get_i (r->config, "cfg.debug")) { + bool swstep = true; + if (r->dbg->h && r->dbg->h->canstep) { + swstep = false; + } + rz_config_set_i (r->config, "dbg.swstep", swstep); + // Set the correct debug handle + if (fd->plugin && fd->plugin->isdbg) { + char *dh = rz_str_ndup (file, (strstr (file, "://") - file)); + if (dh) { + rz_debug_use (r->dbg, dh); + free (dh); + } + } + } + //used by rz_core_bin_load otherwise won't load correctly + //this should be argument of rz_core_bin_load + if (loadaddr != UT64_MAX) { + rz_config_set_i (r->config, "bin.laddr", loadaddr); + } + rz_core_cmd0 (r, "=!"); +beach: + r->times->file_open_time = rz_time_now_mono () - prev; + return fh; +} + +RZ_API void rz_core_file_free(RzCoreFile *cf) { + int res = 1; + + rz_return_if_fail (cf); + + if (!cf->core) { + free (cf); + return; + } + res = rz_list_delete_data (cf->core->files, cf); + if (res && cf->alive) { + // double free librz/io/io.c:70 performs free + RzIO *io = cf->core->io; + if (io) { + RBin *bin = cf->binb.bin; + RBinFile *bf = rz_bin_cur (bin); + if (bf) { + rz_bin_file_deref (bin, bf); + } + rz_io_fd_close (io, cf->fd); + free (cf); + } + } +} + +RZ_API int rz_core_file_close(RzCore *r, RzCoreFile *fh) { + int ret; + RzIODesc *desc = fh && r ? rz_io_desc_get (r->io, fh->fd) : NULL; + RzCoreFile *prev_cf = r && r->file != fh? r->file: NULL; + + // TODO: This is not correctly done. because map and iodesc are + // still referenced // we need to fully clear all R_IO structs + // related to a file as well as the ones needed for RBin. + // + // XXX -these checks are intended to *try* and catch + // stale objects. Unfortunately, if the file handle + // (fh) is stale and freed, and there is more than 1 + // fh in the r->files list, we are hosed. (design flaw) + // TODO maybe using sdb to keep track of the allocated and + // deallocated files might be a good solutions + if (!r || !desc || rz_list_empty (r->files)) { + return false; + } + + if (fh == r->file) { + r->file = NULL; + } + + rz_core_file_set_by_fd (r, fh->fd); + rz_core_bin_set_by_fd (r, fh->fd); + + /* delete filedescriptor from io descs here */ + // rz_io_desc_del (r->io, fh->fd); + + // AVOID DOUBLE FREE HERE + r->files->free = NULL; + + ret = rz_list_delete_data (r->files, fh); + if (ret) { + if (!prev_cf && rz_list_length (r->files) > 0) { + prev_cf = (RzCoreFile *) rz_list_get_n (r->files, 0); + } + + if (prev_cf) { + RzIODesc *desc = prev_cf && r ? rz_io_desc_get (r->io, prev_cf->fd) : NULL; + if (!desc) { + eprintf ("Error: RzCoreFile's found with out a supporting RzIODesc.\n"); + } + ret = rz_core_file_set_by_file (r, prev_cf); + } + } + rz_io_desc_close (desc); + rz_core_file_free (fh); + return ret; +} + +RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd) { + RzCoreFile *file; + RzListIter *iter; + rz_list_foreach (core->files, iter, file) { + if (file->fd == fd) { + return file; + } + } + return NULL; +} + +RZ_API int rz_core_file_list(RzCore *core, int mode) { + int count = 0; + RzCoreFile *f; + RzIODesc *desc; + ut64 from; + RzListIter *it; + RBinFile *bf; + RzListIter *iter; + if (mode == 'j') { + rz_cons_printf ("["); + } + rz_list_foreach (core->files, iter, f) { + desc = rz_io_desc_get (core->io, f->fd); + if (!desc) { + // cannot find desc for this fd, RzCoreFile inconsistency!!!1 + continue; + } + from = 0LL; + switch (mode) { + case 'j': + rz_cons_printf ("{\"raised\":%s,\"fd\":%d,\"uri\":\"%s\",\"from\":%" + PFMT64d ",\"writable\":%s,\"size\":%d}%s", + rz_str_bool (core->io->desc->fd == f->fd), + (int) f->fd, desc->uri, (ut64) from, + rz_str_bool (desc->perm & R_PERM_W), + (int) rz_io_desc_size (desc), + iter->n? ",": ""); + break; + case '*': + case 'r': + // TODO: use a getter + { + bool fileHaveBin = false; + char *absfile = rz_file_abspath (desc->uri); + rz_list_foreach (core->bin->binfiles, it, bf) { + if (bf->fd == f->fd) { + rz_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from); + fileHaveBin = true; + } + } + if (!fileHaveBin && !strstr (absfile, "://")) { + rz_cons_printf ("o %s 0x%"PFMT64x "\n", absfile, (ut64) from); + } + free (absfile); + } + break; + case 'n': + { + bool header_loaded = false; + rz_list_foreach (core->bin->binfiles, it, bf) { + if (bf->fd == f->fd) { + header_loaded = true; + break; + } + } + if (!header_loaded) { + RzList* maps = rz_io_map_get_for_fd (core->io, f->fd); + RzListIter *iter; + RzIOMap* current_map; + char *absfile = rz_file_abspath (desc->uri); + rz_list_foreach (maps, iter, current_map) { + if (current_map) { + rz_cons_printf ("on %s 0x%"PFMT64x "\n", absfile, current_map->itv.addr); + } + } + rz_list_free (maps); + free(absfile); + + } + } + break; + default: + { + ut64 sz = rz_io_desc_size (desc); + const char *fmt; + if (sz == UT64_MAX) { + fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64d "\n"; + } else { + fmt = "%c %d %d %s @ 0x%"PFMT64x " ; %s size=%"PFMT64u "\n"; + } + rz_cons_printf (fmt, + core->io->desc->fd == f->fd ? '*': '-', + count, + (int) f->fd, desc->uri, (ut64) from, + desc->perm & R_PERM_W? "rw": "r", + rz_io_desc_size (desc)); + } + break; + } + count++; + } + if (mode == 'j') { + rz_cons_printf ("]\n"); + } + return count; +} + +// XXX - needs to account for binfile index and bin object index +RZ_API bool rz_core_file_bin_raise(RzCore *core, ut32 bfid) { + RBin *bin = core->bin; + RBinFile *bf = rz_list_get_n (bin->binfiles, bfid); + bool res = false; + if (bf) { + res = rz_bin_file_set_cur_binfile (bin, bf); + if (res) { + rz_io_use_fd (core->io, bf->fd); + } + res = res? rz_core_file_set_by_fd (core, bf->fd): res; + if (res) { + core->switch_file_view = 1; + } + } + return res; +} + +RZ_API int rz_core_file_binlist(RzCore *core) { + int count = 0; + RzListIter *iter; + RzCoreFile *cur_cf = core->file, *cf = NULL; + RBinFile *binfile = NULL; + RzIODesc *desc; + RBin *bin = core->bin; + const RzList *binfiles = bin? bin->binfiles: NULL; + + if (!binfiles) { + return false; + } + rz_list_foreach (binfiles, iter, binfile) { + int fd = binfile->fd; + cf = rz_core_file_get_by_fd (core, fd); + desc = rz_io_desc_get (core->io, fd); + if (cf) { + rz_cons_printf ("%c %d %s ; %s\n", + core->io->desc == desc ? '*': '-', + fd, desc->uri, desc->perm & R_PERM_W? "rw": "r"); + } + } + rz_core_file_set_by_file (core, cur_cf); + //rz_core_bin_bind (core, cur_bf); + return count; +} + +static bool close_but_cb(void *user, void *data, ut32 id) { + RzCore *core = (RzCore *)user; + RzIODesc *desc = (RzIODesc *)data; + if (core && desc && core->file) { + if (desc->fd != core->file->fd) { + // TODO: use the API + rz_core_cmdf (core, "o-%d", desc->fd); + } + } + return true; +} + +RZ_API bool rz_core_file_close_all_but(RzCore *core) { + rz_id_storage_foreach (core->io->files, close_but_cb, core); + return true; +} + +RZ_API bool rz_core_file_close_fd(RzCore *core, int fd) { + RzCoreFile *file; + RzListIter *iter; + if (fd == -1) { + // FIXME: Only closes files known to the core! + rz_list_free (core->files); + core->files = NULL; + core->file = NULL; + return true; + } + rz_list_foreach (core->files, iter, file) { + if (file->fd == fd) { + rz_core_file_close (core, file); + if (file == core->file) { + core->file = NULL; // deref + } + return true; + } + } + return rz_io_fd_close (core->io, fd); +} + +RZ_API RzCoreFile *rz_core_file_find_by_fd(RzCore *core, ut64 fd) { + RzListIter *iter; + RzCoreFile *cf = NULL; + rz_list_foreach (core->files, iter, cf) { + if (cf && cf->fd == fd) { + break; + } + cf = NULL; + } + return cf; +} + +RZ_API RzCoreFile *rz_core_file_find_by_name(RzCore *core, const char *name) { + RzListIter *iter; + RzCoreFile *cf = NULL; + RzIODesc *desc; + + if (!core) { + return NULL; + } + + rz_list_foreach (core->files, iter, cf) { + desc = rz_io_desc_get (core->io, cf->fd); + if (desc && !strcmp (desc->name, name)) { + break; + } + cf = NULL; + } + return cf; +} + +RZ_API int rz_core_file_set_by_fd(RzCore *core, ut64 fd) { + if (core) { + rz_io_use_fd (core->io, fd); + rz_core_bin_set_by_fd (core, fd); + return true; + } + return false; +} + +RZ_API int rz_core_file_set_by_name(RzCore *core, const char *name) { + RzCoreFile *cf = rz_core_file_find_by_name (core, name); + return rz_core_file_set_by_file (core, cf); +} + +RZ_API int rz_core_file_set_by_file(RzCore *core, RzCoreFile *cf) { + if (core && cf) { + if (!rz_core_file_set_by_fd (core, cf->fd)) { + return false; + } + core->file = cf; + return true; + } + return false; +} + +RZ_API ut32 rz_core_file_cur_fd(RzCore *core) { + if (core && core->file) { + return core->file->fd; + } + return UT32_MAX; +} + +RZ_API RzCoreFile *rz_core_file_cur(RzCore *r) { + // Add any locks here + return r->file; +} diff --git a/libr/core/cio.c b/librz/core/cio.c similarity index 61% rename from libr/core/cio.c rename to librz/core/cio.c index 6dc8977ed6..de7756cd10 100644 --- a/libr/core/cio.c +++ b/librz/core/cio.c @@ -1,76 +1,76 @@ -/* radare2 - LGPL - Copyright 2009-2019 - pancake */ +/* rizin - LGPL - Copyright 2009-2019 - pancake */ -#include "r_core.h" +#include "rz_core.h" -R_API int r_core_setup_debugger (RCore *r, const char *debugbackend, bool attach) { +RZ_API int rz_core_setup_debugger (RzCore *r, const char *debugbackend, bool attach) { int pid, *p = NULL; bool is_gdb = !strcmp (debugbackend, "gdb"); - RIODesc * fd = r->file ? r_io_desc_get (r->io, r->file->fd) : NULL; + RzIODesc * fd = r->file ? rz_io_desc_get (r->io, r->file->fd) : NULL; const char *prompt = NULL; p = fd ? fd->data : NULL; - r_config_set_i (r->config, "cfg.debug", 1); + rz_config_set_i (r->config, "cfg.debug", 1); if (!p) { eprintf ("Invalid debug io\n"); return false; } - r_config_set (r->config, "io.ff", "true"); - r_core_cmdf (r, "dL %s", debugbackend); + rz_config_set (r->config, "io.ff", "true"); + rz_core_cmdf (r, "dL %s", debugbackend); if (!is_gdb) { - pid = r_io_desc_get_pid (fd); - r_core_cmdf (r, "dp=%d", pid); + pid = rz_io_desc_get_pid (fd); + rz_core_cmdf (r, "dp=%d", pid); if (attach) { - r_core_cmdf (r, "dpa %d", pid); + rz_core_cmdf (r, "dpa %d", pid); } } //this makes to attach twice showing warnings in the output //we get "resource busy" so it seems isn't an issue - r_core_cmd (r, ".dr*", 0); + rz_core_cmd (r, ".dr*", 0); /* honor dbg.bep */ { - const char *bep = r_config_get (r->config, "dbg.bep"); + const char *bep = rz_config_get (r->config, "dbg.bep"); if (bep) { if (!strcmp (bep, "loader")) { /* do nothing here */ } else if (!strcmp (bep, "entry")) { - r_core_cmd (r, "dcu entry0", 0); + rz_core_cmd (r, "dcu entry0", 0); } else { - r_core_cmdf (r, "dcu %s", bep); + rz_core_cmdf (r, "dcu %s", bep); } } } - r_core_cmd (r, "sr PC", 0); + rz_core_cmd (r, "sr PC", 0); /* set the prompt if it's not been set already by the callbacks */ - prompt = r_config_get (r->config, "cmd.prompt"); + prompt = rz_config_get (r->config, "cmd.prompt"); if (prompt && !strcmp (prompt, "")) { - if (r_config_get_i (r->config, "dbg.status")) { - r_config_set (r->config, "cmd.prompt", ".dr*;drd;sr PC;pi 1;s-"); + if (rz_config_get_i (r->config, "dbg.status")) { + rz_config_set (r->config, "cmd.prompt", ".dr*;drd;sr PC;pi 1;s-"); } else { - r_config_set (r->config, "cmd.prompt", ".dr*"); + rz_config_set (r->config, "cmd.prompt", ".dr*"); } } - r_config_set (r->config, "cmd.vprompt", ".dr*"); - r_config_set (r->config, "cmd.gprompt", ".dr*"); + rz_config_set (r->config, "cmd.vprompt", ".dr*"); + rz_config_set (r->config, "cmd.gprompt", ".dr*"); return true; } -R_API int r_core_seek_base (RCore *core, const char *hex) { - ut64 addr = r_num_tail (core->num, core->offset, hex); - return r_core_seek (core, addr, true); +RZ_API int rz_core_seek_base (RzCore *core, const char *hex) { + ut64 addr = rz_num_tail (core->num, core->offset, hex); + return rz_core_seek (core, addr, true); } -R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int append) { +RZ_API bool rz_core_dump(RzCore *core, const char *file, ut64 addr, ut64 size, int append) { ut64 i; ut8 *buf; int bs = core->blocksize; FILE *fd; if (append) { - fd = r_sandbox_fopen (file, "ab"); + fd = rz_sandbox_fopen (file, "ab"); } else { - r_sys_truncate (file, 0); - fd = r_sandbox_fopen (file, "wb"); + rz_sys_truncate (file, 0); + fd = rz_sandbox_fopen (file, "wb"); } if (!fd) { eprintf ("Cannot open '%s' for writing\n", file); @@ -86,21 +86,21 @@ R_API bool r_core_dump(RCore *core, const char *file, ut64 addr, ut64 size, int fclose (fd); return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = 0; i < size; i += bs) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if ((i + bs) > size) { bs = size - i; } - r_io_read_at (core->io, addr + i, buf, bs); + rz_io_read_at (core->io, addr + i, buf, bs); if (fwrite (buf, bs, 1, fd) < 1) { eprintf ("write error\n"); break; } } - r_cons_break_pop (); + rz_cons_break_pop (); fclose (fd); free (buf); return true; @@ -121,23 +121,23 @@ static bool __endian_swap(ut8 *buf, ut32 blocksize, ut8 len) { for (i = 0; i < blocksize; i += len) { switch (len) { case 8: - v64 = r_read_at_be64 (buf, i); - r_write_at_le64 (buf, v64, i); + v64 = rz_read_at_be64 (buf, i); + rz_write_at_le64 (buf, v64, i); break; case 4: - v32 = r_read_at_be32 (buf, i); - r_write_at_le32 (buf, v32, i); + v32 = rz_read_at_be32 (buf, i); + rz_write_at_le32 (buf, v32, i); break; case 2: - v16 = r_read_at_be16 (buf, i); - r_write_at_le16 (buf, v16, i); + v16 = rz_read_at_be16 (buf, i); + rz_write_at_le16 (buf, v16, i); break; } } return true; } -R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { +RZ_API ut8* rz_core_transform_op(RzCore *core, const char *arg, char op) { int i, j; ut64 len; char *str = NULL; @@ -152,13 +152,13 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { if (op!='e') { // fill key buffer either from arg or from clipboard if (arg) { // parse arg for key - // r_hex_str2bin() is guaranteed to output maximum half the + // rz_hex_str2bin() is guaranteed to output maximum half the // input size, or 1 byte if there is just a single nibble. str = (char *)malloc (strlen (arg) / 2 + 1); if (!str) { goto beach; } - len = r_hex_str2bin (arg, (ut8 *)str); + len = rz_hex_str2bin (arg, (ut8 *)str); // Output is invalid if there was just a single nibble, // but in that case, len is negative (-1). if (len <= 0) { @@ -166,8 +166,8 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { goto beach; } } else { // use clipboard as key - const ut8 *tmp = r_buf_data (core->yank_buf, &len); - str = r_mem_dup (tmp, len); + const ut8 *tmp = rz_buf_data (core->yank_buf, &len); + str = rz_mem_dup (tmp, len); if (!str) { goto beach; } @@ -185,23 +185,23 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { p = strchr (s, ' '); if (p) { *p = 0; - from = r_num_math (core->num, s); + from = rz_num_math (core->num, s); s = p + 1; } p = strchr (s, ' '); if (p) { *p = 0; - to = r_num_math (core->num, s); + to = rz_num_math (core->num, s); s = p + 1; } p = strchr (s, ' '); if (p) { *p = 0; - step = r_num_math (core->num, s); + step = rz_num_math (core->num, s); s = p + 1; - wordsize = r_num_math (core->num, s); + wordsize = rz_num_math (core->num, s); } else { - step = r_num_math (core->num, s); + step = rz_num_math (core->num, s); } free (os); eprintf ("from %d to %d step %d size %d\n", from, to, step, wordsize); @@ -225,17 +225,17 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { } else if (wordsize == 2) { ut16 num16 = from; for (i = 0; i < core->blocksize; i += wordsize, num16 += step) { - r_write_le16 (buf + i, num16); + rz_write_le16 (buf + i, num16); } } else if (wordsize == 4) { ut32 num32 = from; for (i = 0; i < core->blocksize; i += wordsize, num32 += step) { - r_write_le32 (buf + i, num32); + rz_write_le32 (buf + i, num32); } } else if (wordsize == 8) { ut64 num64 = from; for (i = 0; i < core->blocksize; i += wordsize, num64 += step) { - r_write_le64 (buf + i, num64); + rz_write_le64 (buf + i, num64); } } else { eprintf ("Invalid word size. Use 1, 2, 4 or 8\n"); @@ -277,7 +277,7 @@ R_API ut8* r_core_transform_op(RCore *core, const char *arg, char op) { } } } else { - bool be = r_config_get_i (core->config, "cfg.bigendian"); + bool be = rz_config_get_i (core->config, "cfg.bigendian"); if (!be) { if (!__endian_swap ((ut8*)str, len, len)) { goto beach; @@ -311,23 +311,23 @@ beach: return NULL; } -R_API int r_core_write_op(RCore *core, const char *arg, char op) { - ut8 *buf = r_core_transform_op(core, arg, op); +RZ_API int rz_core_write_op(RzCore *core, const char *arg, char op) { + ut8 *buf = rz_core_transform_op(core, arg, op); if (!buf) { return false; } - int ret = r_core_write_at (core, core->offset, buf, core->blocksize); + int ret = rz_core_write_at (core, core->offset, buf, core->blocksize); free (buf); return ret; } // Get address-specific bits and arch at a certain address. // If there are no specific infos (i.e. asm.bits and asm.arch should apply), the bits and arch will be 0 or NULL respectively! -R_API void r_core_arch_bits_at(RCore *core, ut64 addr, R_OUT R_NULLABLE int *bits, R_OUT R_BORROW R_NULLABLE const char **arch) { +RZ_API void rz_core_arch_bits_at(RzCore *core, ut64 addr, R_OUT R_NULLABLE int *bits, R_OUT R_BORROW R_NULLABLE const char **arch) { int bitsval = 0; const char *archval = NULL; - RBinObject *o = r_bin_cur_object (core->bin); - RBinSection *s = o ? r_bin_get_section_at (o, addr, core->io->va) : NULL; + RBinObject *o = rz_bin_cur_object (core->bin); + RBinSection *s = o ? rz_bin_get_section_at (o, addr, core->io->va) : NULL; if (s) { if (!core->fixedarch) { archval = s->arch; @@ -345,10 +345,10 @@ R_API void r_core_arch_bits_at(RCore *core, ut64 addr, R_OUT R_NULLABLE int *bit } //if we found bits related with anal hints pick it up if (bits && !bitsval && !core->fixedbits) { - bitsval = r_anal_hint_bits_at (core->anal, addr, NULL); + bitsval = rz_anal_hint_bits_at (core->anal, addr, NULL); } if (arch && !archval && !core->fixedarch) { - archval = r_anal_hint_arch_at (core->anal, addr, NULL); + archval = rz_anal_hint_arch_at (core->anal, addr, NULL); } if (bits && bitsval) { *bits = bitsval; @@ -358,29 +358,29 @@ R_API void r_core_arch_bits_at(RCore *core, ut64 addr, R_OUT R_NULLABLE int *bit } } -R_API void r_core_seek_arch_bits(RCore *core, ut64 addr) { +RZ_API void rz_core_seek_arch_bits(RzCore *core, ut64 addr) { int bits = 0; const char *arch = NULL; - r_core_arch_bits_at (core, addr, &bits, &arch); + rz_core_arch_bits_at (core, addr, &bits, &arch); if (bits) { - r_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "asm.bits", bits); } if (arch) { - r_config_set (core->config, "asm.arch", arch); + rz_config_set (core->config, "asm.arch", arch); } } -R_API bool r_core_seek(RCore *core, ut64 addr, bool rb) { - core->offset = r_io_seek (core->io, addr, R_IO_SEEK_SET); +RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb) { + core->offset = rz_io_seek (core->io, addr, R_IO_SEEK_SET); if (rb) { - r_core_block_read (core); + rz_core_block_read (core); } if (core->binat) { - RBinFile *bf = r_bin_file_at (core->bin, core->offset); + RBinFile *bf = rz_bin_file_at (core->bin, core->offset); if (bf) { core->bin->cur = bf; - r_bin_select_bfid (core->bin, bf->id); - // XXX r_core_cmdf (core, "obb %d", bf->id); + rz_bin_select_bfid (core->bin, bf->id); + // XXX rz_core_cmdf (core, "obb %d", bf->id); } else { core->bin->cur = NULL; } @@ -388,7 +388,7 @@ R_API bool r_core_seek(RCore *core, ut64 addr, bool rb) { return core->offset == addr; } -R_API int r_core_seek_delta(RCore *core, st64 addr) { +RZ_API int rz_core_seek_delta(RzCore *core, st64 addr) { ut64 tmp = core->offset; if (addr == 0) { return true; @@ -405,43 +405,43 @@ R_API int r_core_seek_delta(RCore *core, st64 addr) { } } core->offset = addr; - return r_core_seek (core, addr, true); + return rz_core_seek (core, addr, true); } // TODO: kill this wrapper -R_API bool r_core_write_at(RCore *core, ut64 addr, const ut8 *buf, int size) { - r_return_val_if_fail (core && buf && addr != UT64_MAX, false); +RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size) { + rz_return_val_if_fail (core && buf && addr != UT64_MAX, false); if (size < 1) { return false; } - bool ret = r_io_write_at (core->io, addr, buf, size); + bool ret = rz_io_write_at (core->io, addr, buf, size); if (addr >= core->offset && addr <= core->offset + core->blocksize - 1) { - r_core_block_read (core); + rz_core_block_read (core); } return ret; } -R_API bool r_core_extend_at(RCore *core, ut64 addr, int size) { +RZ_API bool rz_core_extend_at(RzCore *core, ut64 addr, int size) { if (!core->io || !core->file || size < 1) { return false; } - int io_va = r_config_get_i (core->config, "io.va"); + int io_va = rz_config_get_i (core->config, "io.va"); if (io_va) { - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { addr = addr - map->itv.addr + map->delta; } - r_config_set_i (core->config, "io.va", false); + rz_config_set_i (core->config, "io.va", false); } - int ret = r_io_extend_at (core->io, addr, size); + int ret = rz_io_extend_at (core->io, addr, size); if (addr >= core->offset && addr <= core->offset+core->blocksize) { - r_core_block_read (core); + rz_core_block_read (core); } - r_config_set_i (core->config, "io.va", io_va); + rz_config_set_i (core->config, "io.va", io_va); return ret; } -R_API int r_core_shift_block(RCore *core, ut64 addr, ut64 b_size, st64 dist) { +RZ_API int rz_core_shift_block(RzCore *core, ut64 addr, ut64 b_size, st64 dist) { // bstart - block start, fstart file start ut64 fend = 0, fstart = 0, bstart = 0, file_sz = 0; ut8 * shift_buf = NULL; @@ -452,14 +452,14 @@ R_API int r_core_shift_block(RCore *core, ut64 addr, ut64 b_size, st64 dist) { } if (b_size == 0 || b_size == (ut64) -1) { - r_io_use_fd (core->io, core->file->fd); - file_sz = r_io_size (core->io); + rz_io_use_fd (core->io, core->file->fd); + file_sz = rz_io_size (core->io); if (file_sz == UT64_MAX) { file_sz = 0; } #if 0 - bstart = r_io_seek (core->io, addr, R_IO_SEEK_SET); - fend = r_io_seek (core->io, 0, R_IO_SEEK_END); + bstart = rz_io_seek (core->io, addr, R_IO_SEEK_SET); + fend = rz_io_seek (core->io, 0, R_IO_SEEK_END); if (fend < 1) { fend = 0; } @@ -496,28 +496,28 @@ R_API int r_core_shift_block(RCore *core, ut64 addr, ut64 b_size, st64 dist) { } else if ( (addr) + dist > fend) { res = false; } else { - r_io_use_fd (core->io, core->file->fd); - r_io_read_at (core->io, addr, shift_buf, b_size); - r_io_write_at (core->io, addr + dist, shift_buf, b_size); + rz_io_use_fd (core->io, core->file->fd); + rz_io_read_at (core->io, addr, shift_buf, b_size); + rz_io_write_at (core->io, addr + dist, shift_buf, b_size); res = true; } - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); free (shift_buf); return res; } -R_API int r_core_block_read(RCore *core) { +RZ_API int rz_core_block_read(RzCore *core) { if (core && core->block) { - return r_io_read_at (core->io, core->offset, core->block, core->blocksize); + return rz_io_read_at (core->io, core->offset, core->block, core->blocksize); } return -1; } -R_API int r_core_is_valid_offset (RCore *core, ut64 offset) { +RZ_API int rz_core_is_valid_offset (RzCore *core, ut64 offset) { if (!core) { - eprintf ("r_core_is_valid_offset: core is NULL\n"); - r_sys_backtrace (); + eprintf ("rz_core_is_valid_offset: core is NULL\n"); + rz_sys_backtrace (); return -1; } - return r_io_is_valid_offset (core->io, offset, 0); + return rz_io_is_valid_offset (core->io, offset, 0); } diff --git a/libr/core/citem.c b/librz/core/citem.c similarity index 52% rename from libr/core/citem.c rename to librz/core/citem.c index c0d74a3f45..4dcaff2a19 100644 --- a/libr/core/citem.c +++ b/librz/core/citem.c @@ -1,25 +1,25 @@ /* radare - LGPL - Copyright 2019 - pancake */ -#include +#include -R_API RCoreItem *r_core_item_at (RCore *core, ut64 addr) { - RCoreItem *ci = R_NEW0 (RCoreItem); +RZ_API RzCoreItem *rz_core_item_at (RzCore *core, ut64 addr) { + RzCoreItem *ci = R_NEW0 (RzCoreItem); ci->addr = addr; - RIOMap *map = r_io_map_get (core->io, addr); + RzIOMap *map = rz_io_map_get (core->io, addr); if (map) { ci->perm = map->perm; // TODO: honor section perms too? if (map->perm & R_PERM_X) { // if theres a meta consider it data ut64 size; - RAnalMetaItem *item = r_meta_get_at (core->anal, addr, R_META_TYPE_ANY, &size); + RzAnalMetaItem *item = rz_meta_get_at (core->anal, addr, R_META_TYPE_ANY, &size); if (item) { switch (item->type) { case R_META_TYPE_DATA: ci->type = "data"; ci->size = size; - ci->data = r_core_cmd_strf (core, "pdi 1 @e:asm.flags=0@e:asm.lines=0@e:scr.color=0@0x%08"PFMT64x, addr); - r_str_trim (ci->data); + ci->data = rz_core_cmd_strf (core, "pdi 1 @e:asm.flags=0@e:asm.lines=0@e:scr.color=0@0x%08"PFMT64x, addr); + rz_str_trim (ci->data); break; case R_META_TYPE_FORMAT: ci->type = "format"; // struct :? @@ -40,35 +40,35 @@ R_API RCoreItem *r_core_item_at (RCore *core, ut64 addr) { } } } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 1); if (fcn) { ci->fcnname = strdup (fcn->name); } - RBinObject *o = r_bin_cur_object (core->bin); - RBinSection *sec = r_bin_get_section_at (o, addr, core->io->va); + RBinObject *o = rz_bin_cur_object (core->bin); + RBinSection *sec = rz_bin_get_section_at (o, addr, core->io->va); if (sec) { ci->sectname = strdup (sec->name); } if (!ci->data) { - RAnalOp* op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); + RzAnalOp* op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); if (op) { if (!ci->data) { if (op->mnemonic) { ci->data = strdup (op->mnemonic); } else { - ci->data = r_core_cmd_strf (core, "pi 1 @e:scr.color=0@0x%08"PFMT64x, addr); - r_str_trim (ci->data); + ci->data = rz_core_cmd_strf (core, "pi 1 @e:scr.color=0@0x%08"PFMT64x, addr); + rz_str_trim (ci->data); } } ci->size = op->size; - r_anal_op_free (op); + rz_anal_op_free (op); } } - char *cmt = r_core_cmd_strf (core, "CC.@0x%08"PFMT64x, addr); + char *cmt = rz_core_cmd_strf (core, "CC.@0x%08"PFMT64x, addr); if (cmt) { if (*cmt) { ci->comment = strdup (cmt); - r_str_trim (ci->comment); + rz_str_trim (ci->comment); } free (cmt); } @@ -76,14 +76,14 @@ R_API RCoreItem *r_core_item_at (RCore *core, ut64 addr) { ci->type = "code"; } ci->next = ci->addr + ci->size; - char *prev = r_core_cmd_strf (core, "pd -1@e:asm.lines=0~[0]"); - r_str_trim (prev); - ci->prev = r_num_get (NULL, prev); + char *prev = rz_core_cmd_strf (core, "pd -1@e:asm.lines=0~[0]"); + rz_str_trim (prev); + ci->prev = rz_num_get (NULL, prev); free (prev); return ci; } -R_API void r_core_item_free (RCoreItem *ci) { +RZ_API void rz_core_item_free (RzCoreItem *ci) { free (ci->data); free (ci); } diff --git a/libr/core/cmd.c b/librz/core/cmd.c similarity index 63% rename from libr/core/cmd.c rename to librz/core/cmd.c index fcf3b37a1a..6fc2902cd7 100644 --- a/libr/core/cmd.c +++ b/librz/core/cmd.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, pancake */ #if 0 -* Use RList +* Use RzList * Support callback for null command (why?) * Show help of commands - long commands not yet tested at all - added interface to export command list into an autocompletable argc, argv for dietline -* r_cmd must provide a nesting char table indexing for commands +* rz_cmd must provide a nesting char table indexing for commands - this is already partially done - - this is pretty similar to r_db + - this is pretty similar to rz_db - every module can register their own commands - commands can be listed like in a tree #endif #define INTERACTIVE_MAX_REP 1024 -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include @@ -29,10 +29,10 @@ #endif #include -TSLanguage *tree_sitter_r2cmd (); +TSLanguage *tree_sitter_rzcmd (); // NOTE: this should be in sync with SPECIAL_CHARACTERS in -// radare2-shell-parser grammar, except for ", ' and +// rizin-shell-parser grammar, except for ", ' and // whitespaces, because we let cmd_substitution_arg create // new arguments static const char *SPECIAL_CHARS_REGULAR = "@;~$#|`\"'()<>"; @@ -40,11 +40,11 @@ static const char *SPECIAL_CHARS_PF = "@;~$#|`\"'<>"; static const char *SPECIAL_CHARS_DOUBLE_QUOTED = "\""; static const char *SPECIAL_CHARS_SINGLE_QUOTED = "'"; -R_API void r_save_panels_layout(RCore *core, const char *_name); -R_API bool r_load_panels_layout(RCore *core, const char *_name); +RZ_API void rz_save_panels_layout(RzCore *core, const char *_name); +RZ_API bool rz_load_panels_layout(RzCore *core, const char *_name); -static RCmdDescriptor *cmd_descriptor(const char *cmd, const char *help[]) { - RCmdDescriptor *d = R_NEW0 (RCmdDescriptor); +static RzCmdDescriptor *cmd_descriptor(const char *cmd, const char *help[]) { + RzCmdDescriptor *d = R_NEW0 (RzCmdDescriptor); if (d) { d->cmd = cmd; d->help_msg = help; @@ -54,49 +54,49 @@ static RCmdDescriptor *cmd_descriptor(const char *cmd, const char *help[]) { #define DEFINE_CMD_DESCRIPTOR(core, cmd_) \ { \ - RCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg_##cmd_); \ + RzCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg_##cmd_); \ if (d) { \ - r_list_append ((core)->cmd_descriptors, d); \ + rz_list_append ((core)->cmd_descriptors, d); \ } \ } #define DEFINE_CMD_DESCRIPTOR_WITH_DETAIL(core, cmd_) \ { \ - RCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg##cmd_); \ + RzCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg##cmd_); \ if (d) { \ d->help_detail = help_detail_##cmd_; \ - r_list_append ((core)->cmd_descriptors, d); \ + rz_list_append ((core)->cmd_descriptors, d); \ } \ } #define DEFINE_CMD_DESCRIPTOR_WITH_DETAIL2(core, cmd_) \ { \ - RCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg_##cmd_); \ + RzCmdDescriptor *d = cmd_descriptor (#cmd_, help_msg_##cmd_); \ if (d) { \ d->help_detail = help_detail_##cmd_; \ d->help_detail2 = help_detail2_##cmd_; \ - r_list_append ((core)->cmd_descriptors, d); \ + rz_list_append ((core)->cmd_descriptors, d); \ } \ } #define DEFINE_CMD_DESCRIPTOR_SPECIAL(core, cmd_, named_cmd) \ { \ - RCmdDescriptor *d = R_NEW0 (RCmdDescriptor); \ + RzCmdDescriptor *d = R_NEW0 (RzCmdDescriptor); \ if (d) { \ d->cmd = #cmd_; \ d->help_msg = help_msg_##named_cmd; \ - r_list_append ((core)->cmd_descriptors, d); \ + rz_list_append ((core)->cmd_descriptors, d); \ } \ } -static int r_core_cmd_subst_i(RCore *core, char *cmd, char* colon, bool *tmpseek); +static int rz_core_cmd_subst_i(RzCore *core, char *cmd, char* colon, bool *tmpseek); static int bb_cmpaddr(const void *_a, const void *_b) { - const RAnalBlock *a = _a, *b = _b; + const RzAnalBlock *a = _a, *b = _b; return a->addr > b->addr ? 1 : (a->addr < b->addr ? -1 : 0); } -static void cmd_debug_reg(RCore *core, const char *str); +static void cmd_debug_reg(RzCore *core, const char *str); #include "cmd_quit.c" #include "cmd_hash.c" @@ -154,7 +154,7 @@ static const char *help_msg_star[] = { }; static const char *help_msg_dot[] = { - "Usage:", ".[r2cmd] | [file] | [!command] | [(macro)]", "# define macro or interpret r2, r_lang,\n" + "Usage:", ".[r2cmd] | [file] | [!command] | [(macro)]", "# define macro or interpret r2, rz_lang,\n" " cparse, d, es6, exe, go, js, lsp, pl, py, rb, sh, vala or zig file", ".", "", "repeat last command backward", ".", "r2cmd", "interpret the output of the command as r2 commands", @@ -177,7 +177,7 @@ static const char *help_msg_equal[] = { "=", "", "list all open connections", "=<", "[fd] cmd", "send output of local command to remote fd", // XXX may not be a special char "=", "[fd] cmd", "exec cmd at remote 'fd' (last open is default one)", - "=!", " cmd", "run command via r_io_system", + "=!", " cmd", "run command via rz_io_system", "=+", " [proto://]host:port", "connect to remote host:port (*rap://, raps://, tcp://, udp://, http://)", "=-", "[fd]", "remove all hosts or host 'fd'", "==", "[fd]", "open remote session with host 'fd', 'q' to quit", @@ -275,7 +275,7 @@ static const char *help_msg_r[] = { "rb", "oldbase @ newbase", "rebase all flags, bin.info, breakpoints and analysis", "rm" ," [file]", "remove file", "rh" ,"", "show size in human format", - "r2" ," [file]", "launch r2 (same for rax2, rasm2, ...)", + "r2" ," [file]", "launch r2 (same for rz_ax, rz_asm, ...)", "reset" ,"", "reset console settings (clear --hard)", NULL }; @@ -339,39 +339,39 @@ static const char *help_msg_vertical_bar[] = { NULL }; -R_API void r_core_cmd_help(const RCore *core, const char *help[]) { - r_cons_cmd_help (help, core->print->flags & R_PRINT_FLAGS_COLOR); +RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[]) { + rz_cons_cmd_help (help, core->print->flags & R_PRINT_FLAGS_COLOR); } struct duplicate_flag_t { - RList *ret; + RzList *ret; const char *word; }; -static bool duplicate_flag(RFlagItem *flag, void *u) { +static bool duplicate_flag(RzFlagItem *flag, void *u) { struct duplicate_flag_t *user = (struct duplicate_flag_t *)u; /* filter per flag spaces */ - if (r_str_glob (flag->name, user->word)) { - RFlagItem *cloned_item = r_flag_item_clone (flag); + if (rz_str_glob (flag->name, user->word)) { + RzFlagItem *cloned_item = rz_flag_item_clone (flag); if (!cloned_item) { return false; } - r_list_append (user->ret, cloned_item); + rz_list_append (user->ret, cloned_item); } return true; } -static void recursive_help_go(RCore *core, int detail, RCmdDescriptor *desc) { +static void recursive_help_go(RzCore *core, int detail, RzCmdDescriptor *desc) { int i; if (desc->help_msg) { - r_core_cmd_help (core, desc->help_msg); + rz_core_cmd_help (core, desc->help_msg); } if (detail >= 1) { if (desc->help_detail) { - r_core_cmd_help (core, desc->help_detail); + rz_core_cmd_help (core, desc->help_detail); } if (detail >= 2 && desc->help_detail2) { - r_core_cmd_help (core, desc->help_detail2); + rz_core_cmd_help (core, desc->help_detail2); } } for (i = 32; i < R_ARRAY_SIZE (desc->sub); i++) { @@ -381,9 +381,9 @@ static void recursive_help_go(RCore *core, int detail, RCmdDescriptor *desc) { } } -static void recursive_help(RCore *core, int detail, const char *cmd_prefix) { +static void recursive_help(RzCore *core, int detail, const char *cmd_prefix) { const ut8 *p; - RCmdDescriptor *desc = &core->root_cmd_descriptor; + RzCmdDescriptor *desc = &core->root_cmd_descriptor; for (p = (const ut8 *)cmd_prefix; *p && *p < R_ARRAY_SIZE (desc->sub); p++) { if (!(desc = desc->sub[*p])) { return; @@ -392,7 +392,7 @@ static void recursive_help(RCore *core, int detail, const char *cmd_prefix) { recursive_help_go (core, detail, desc); } -static bool lastcmd_repeat(RCore *core, int next) { +static bool lastcmd_repeat(RzCore *core, int next) { int res = -1; // Fix for backtickbug px`~` if (!core->lastcmd || core->cons->context->cmd_depth < 1) { @@ -401,15 +401,15 @@ static bool lastcmd_repeat(RCore *core, int next) { switch (*core->lastcmd) { case '.': if (core->lastcmd[1] == '(') { // macro call - res = r_core_cmd0 (core, core->lastcmd); + res = rz_core_cmd0 (core, core->lastcmd); } break; case 'd': // debug - res = r_core_cmd0 (core, core->lastcmd); + res = rz_core_cmd0 (core, core->lastcmd); switch (core->lastcmd[1]) { case 's': case 'c': - r_core_cmd0 (core, "sr PC;pd 1"); + rz_core_cmd0 (core, "sr PC;pd 1"); } break; case 'p': // print @@ -417,29 +417,29 @@ static bool lastcmd_repeat(RCore *core, int next) { case '$': if (!strncmp (core->lastcmd, "pd", 2)) { if (core->lastcmd[2]== ' ') { - r_core_cmdf (core, "so %s", core->lastcmd + 3); + rz_core_cmdf (core, "so %s", core->lastcmd + 3); } else { - r_core_cmd0 (core, "so `pi~?`"); + rz_core_cmd0 (core, "so `pi~?`"); } } else { if (next) { - r_core_seek (core, core->offset + core->blocksize, true); + rz_core_seek (core, core->offset + core->blocksize, true); } else { if (core->blocksize > core->offset) { - r_core_seek (core, 0, true); + rz_core_seek (core, 0, true); } else { - r_core_seek (core, core->offset - core->blocksize, true); + rz_core_seek (core, core->offset - core->blocksize, true); } } } - res = r_core_cmd0 (core, core->lastcmd); + res = rz_core_cmd0 (core, core->lastcmd); break; } return res != -1; } -static int r_core_cmd_nullcallback(void *data) { - RCore *core = (RCore*) data; +static int rz_core_cmd_nullcallback(void *data) { + RzCore *core = (RzCore*) data; if (core->cons->context->breaked) { core->cons->context->breaked = false; return 0; @@ -452,23 +452,23 @@ static int r_core_cmd_nullcallback(void *data) { } static int cmd_uname(void *data, const char *input) { // "uniq" - RSysInfo *si = r_sys_info(); + RSysInfo *si = rz_sys_info(); if (si) { - r_cons_printf ("%s", si->sysname); + rz_cons_printf ("%s", si->sysname); if (strstr (input, "-r")) { - r_cons_printf (" %s", si->release); + rz_cons_printf (" %s", si->release); } - r_cons_newline (); - r_sys_info_free (si); + rz_cons_newline (); + rz_sys_info_free (si); } return 0; } static int cmd_uniq(void *data, const char *input) { // "uniq" - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; const char *arg = strchr (input, ' '); if (arg) { - arg = r_str_trim_head_ro (arg + 1); + arg = rz_str_trim_head_ro (arg + 1); } switch (*input) { case '?': // "uniq?" @@ -478,12 +478,12 @@ static int cmd_uniq(void *data, const char *input) { // "uniq" if (!arg) { arg = ""; } - if (r_fs_check (core->fs, arg)) { - r_core_cmdf (core, "md %s", arg); + if (rz_fs_check (core->fs, arg)) { + rz_core_cmdf (core, "md %s", arg); } else { - char *res = r_syscmd_uniq (arg); + char *res = rz_syscmd_uniq (arg); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -493,17 +493,17 @@ static int cmd_uniq(void *data, const char *input) { // "uniq" } static int cmd_head (void *data, const char *_input) { // "head" - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; int lines = 5; char *input = strdup (_input); char *arg = strchr (input, ' '); char *tmp, *count; if (arg) { - arg = (char *)r_str_trim_head_ro (arg + 1); // contains "count filename" + arg = (char *)rz_str_trim_head_ro (arg + 1); // contains "count filename" count = strchr (arg, ' '); if (count) { *count = 0; // split the count and file name - tmp = (char *)r_str_trim_head_ro (count + 1); + tmp = (char *)rz_str_trim_head_ro (count + 1); lines = atoi (arg); arg = tmp; } @@ -516,12 +516,12 @@ static int cmd_head (void *data, const char *_input) { // "head" if (!arg) { arg = ""; } - if (r_fs_check (core->fs, arg)) { - r_core_cmdf (core, "md %s", arg); + if (rz_fs_check (core->fs, arg)) { + rz_core_cmdf (core, "md %s", arg); } else { - char *res = r_syscmd_head (arg, lines); + char *res = rz_syscmd_head (arg, lines); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -532,10 +532,10 @@ static int cmd_head (void *data, const char *_input) { // "head" } static int cmd_undo(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (input[0]) { case '?': // "u?" - r_core_cmd_help (data, help_msg_u); + rz_core_cmd_help (data, help_msg_u); return 1; case 'c': // "uc" switch (input[1]) { @@ -544,8 +544,8 @@ static int cmd_undo(void *data, const char *input) { char *rcmd = strchr (cmd, ','); if (rcmd) { *rcmd++ = 0; - RCoreUndo *undo = r_core_undo_new (core->offset, cmd, rcmd); - r_core_undo_push (core, undo); + RzCoreUndo *undo = rz_core_undo_new (core->offset, cmd, rcmd); + rz_core_undo_push (core, undo); } else { eprintf ("Usage: uc [cmd] [revert-cmd]"); } @@ -560,29 +560,29 @@ static int cmd_undo(void *data, const char *input) { eprintf (" uc- - undo last action\n"); break; case '.': { - RCoreUndoCondition cond = { + RzCoreUndoCondition cond = { .addr = core->offset, .minstamp = 0, .glob = NULL }; - r_core_undo_print (core, 1, &cond); + rz_core_undo_print (core, 1, &cond); } break; case '*': - r_core_undo_print (core, 1, NULL); + rz_core_undo_print (core, 1, NULL); break; case '-': // "uc-" - r_core_undo_pop (core); + rz_core_undo_pop (core); break; default: - r_core_undo_print (core, 0, NULL); + rz_core_undo_print (core, 0, NULL); break; } return 1; case 's': // "us" - r_core_cmdf (data, "s-%s", input + 1); + rz_core_cmdf (data, "s-%s", input + 1); return 1; case 'w': // "uw" - r_core_cmdf (data, "wc%s", input + 1); + rz_core_cmdf (data, "wc%s", input + 1); return 1; case 'n': // "un" if (input[1] == 'a') { // "uname" @@ -595,20 +595,20 @@ static int cmd_undo(void *data, const char *input) { #if __UNIX__ struct utsname un; uname (&un); - r_cons_printf ("%s %s %s %s\n", un.sysname, + rz_cons_printf ("%s %s %s %s\n", un.sysname, un.nodename, un.release, un.machine); #elif __WINDOWS__ - r_cons_printf ("windows\n"); + rz_cons_printf ("windows\n"); #else - r_cons_printf ("unknown\n"); + rz_cons_printf ("unknown\n"); #endif return 0; } static int cmd_alias(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (*input == '?') { - r_core_cmd_help (core, help_msg_dollar); + rz_core_cmd_help (core, help_msg_dollar); return 0; } int i = strlen (input); @@ -647,18 +647,18 @@ static int cmd_alias(void *data, const char *input) { *def++ = 0; size_t len = strlen (def); if (defmode) { - ut64 at = r_num_math (core->num, def); + ut64 at = rz_num_math (core->num, def); switch (defmode) { case ':': - r_flag_set (core->flags, buf + 1, at, 1); + rz_flag_set (core->flags, buf + 1, at, 1); return 1; case '+': - at = r_num_get (core->num, buf + 1) + at; - r_flag_set (core->flags, buf + 1, at, 1); + at = rz_num_get (core->num, buf + 1) + at; + rz_flag_set (core->flags, buf + 1, at, 1); return 1; case '-': - at = r_num_get (core->num, buf + 1) - at; - r_flag_set (core->flags, buf + 1, at, 1); + at = rz_num_get (core->num, buf + 1) - at; + rz_flag_set (core->flags, buf + 1, at, 1); return 1; } } @@ -670,28 +670,28 @@ static int cmd_alias(void *data, const char *input) { if (!q || (q && q > def)) { if (*def) { if (!strcmp (def, "-")) { - char *v = r_cmd_alias_get (core->rcmd, buf, 0); - char *n = r_cons_editor (NULL, v); + char *v = rz_cmd_alias_get (core->rcmd, buf, 0); + char *n = rz_cons_editor (NULL, v); if (n) { - r_cmd_alias_set (core->rcmd, buf, n, 0); + rz_cmd_alias_set (core->rcmd, buf, n, 0); free (n); } } else { - r_cmd_alias_set (core->rcmd, buf, def, 0); + rz_cmd_alias_set (core->rcmd, buf, def, 0); } } else { - r_cmd_alias_del (core->rcmd, buf); + rz_cmd_alias_del (core->rcmd, buf); } } /* Show command for alias */ } else if (desc && !q) { *desc = 0; - char *v = r_cmd_alias_get (core->rcmd, buf, 0); + char *v = rz_cmd_alias_get (core->rcmd, buf, 0); if (v) { if (nonl == desc + 1) { - r_cons_print (v); + rz_cons_print (v); } else { - r_cons_println (v); + rz_cons_println (v); } free (buf); return 1; @@ -701,44 +701,44 @@ static int cmd_alias(void *data, const char *input) { } else if (buf[1] == '*') { /* Show aliases */ int i, count = 0; - char **keys = r_cmd_alias_keys (core->rcmd, &count); + char **keys = rz_cmd_alias_keys (core->rcmd, &count); for (i = 0; i < count; i++) { - char *v = r_cmd_alias_get (core->rcmd, keys[i], 0); - char *q = r_base64_encode_dyn (v, -1); + char *v = rz_cmd_alias_get (core->rcmd, keys[i], 0); + char *q = rz_base64_encode_dyn (v, -1); if (buf[2] == '*') { - r_cons_printf ("%s=%s\n", keys[i], v); + rz_cons_printf ("%s=%s\n", keys[i], v); } else { - r_cons_printf ("%s=base64:%s\n", keys[i], q); + rz_cons_printf ("%s=base64:%s\n", keys[i], q); } free (q); } } else if (!buf[1]) { int i, count = 0; - char **keys = r_cmd_alias_keys (core->rcmd, &count); + char **keys = rz_cmd_alias_keys (core->rcmd, &count); for (i = 0; i < count; i++) { - r_cons_println (keys[i]); + rz_cons_println (keys[i]); } } else { /* Execute alias */ if (q) { *q = 0; } - char *v = r_cmd_alias_get (core->rcmd, buf, 0); + char *v = rz_cmd_alias_get (core->rcmd, buf, 0); if (v) { if (*v == '$') { - r_cons_strcat (v + 1); - r_cons_newline (); + rz_cons_strcat (v + 1); + rz_cons_newline (); } else if (q) { - char *out = r_str_newf ("%s %s", v, q + 1); - r_core_cmd0 (core, out); + char *out = rz_str_newf ("%s %s", v, q + 1); + rz_core_cmd0 (core, out); free (out); } else { - r_core_cmd0 (core, v); + rz_core_cmd0 (core, v); } } else { - ut64 at = r_num_get (core->num, buf + 1); + ut64 at = rz_num_get (core->num, buf + 1); if (at != UT64_MAX) { - r_core_seek (core, at, true); + rz_core_seek (core, at, true); } else { eprintf ("Unknown alias '%s'\n", buf + 1); } @@ -758,17 +758,17 @@ static int getArg(char ch, int def) { } // wtf dupe for local vs remote? -static void aliascmd(RCore *core, const char *str) { +static void aliascmd(RzCore *core, const char *str) { switch (str[0]) { case '\0': // "=$" - r_core_cmd0 (core, "$"); + rz_core_cmd0 (core, "$"); break; case '-': // "=$-" if (str[1]) { - r_cmd_alias_del (core->rcmd, str + 2); + rz_cmd_alias_del (core->rcmd, str + 2); } else { - r_cmd_alias_del (core->rcmd, NULL); - // r_cmd_alias_reset (core->rcmd); + rz_cmd_alias_del (core->rcmd, NULL); + // rz_cmd_alias_reset (core->rcmd); } break; case '?': // "=$?" @@ -777,16 +777,16 @@ static void aliascmd(RCore *core, const char *str) { eprintf (" =$-dr # unset 'dr' alias\n"); break; default: - r_cmd_alias_set (core->rcmd, str, "", 1); + rz_cmd_alias_set (core->rcmd, str, "", 1); break; } } static int cmd_rap(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (*input) { case '\0': // "=" - r_core_rtr_list (core); + rz_core_rtr_list (core); break; case 'j': // "=j" eprintf ("TODO: list connections in json\n"); @@ -796,11 +796,11 @@ static int cmd_rap(void *data, const char *input) { R_FREE (core->cmdremote); } else if (input[1] == '=') { // =!=0 or =!= for iosystem R_FREE (core->cmdremote); - core->cmdremote = r_str_trim_dup (input + 2); + core->cmdremote = rz_str_trim_dup (input + 2); } else { - char *res = r_io_system (core->io, input + 1); + char *res = rz_io_system (core->io, input + 1); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } } @@ -810,53 +810,53 @@ static int cmd_rap(void *data, const char *input) { aliascmd (core, input + 1); break; case '+': // "=+" - r_core_rtr_add (core, input + 1); + rz_core_rtr_add (core, input + 1); break; case '-': // "=-" - r_core_rtr_remove (core, input + 1); + rz_core_rtr_remove (core, input + 1); break; - //case ':': r_core_rtr_cmds (core, input + 1); break; + //case ':': rz_core_rtr_cmds (core, input + 1); break; case '<': // "=<" - r_core_rtr_pushout (core, input + 1); + rz_core_rtr_pushout (core, input + 1); break; case '=': // "==" - r_core_rtr_session (core, input + 1); + rz_core_rtr_session (core, input + 1); break; case 'g': // "=g" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_equalg); + rz_core_cmd_help (core, help_msg_equalg); } else { - r_core_rtr_gdb (core, getArg (input[1], 'g'), input + 1); + rz_core_rtr_gdb (core, getArg (input[1], 'g'), input + 1); } break; case 'h': // "=h" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_equalh); + rz_core_cmd_help (core, help_msg_equalh); } else { - r_core_rtr_http (core, getArg (input[1], 'h'), 'h', input + 1); + rz_core_rtr_http (core, getArg (input[1], 'h'), 'h', input + 1); } break; case 'H': // "=H" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_equalh); + rz_core_cmd_help (core, help_msg_equalh); } else { - const char *arg = r_str_trim_head_ro (input + 1); - r_core_rtr_http (core, getArg (input[1], 'H'), 'H', arg); + const char *arg = rz_str_trim_head_ro (input + 1); + rz_core_rtr_http (core, getArg (input[1], 'H'), 'H', arg); } break; case '?': // "=?" - r_core_cmd_help (core, help_msg_equal); + rz_core_cmd_help (core, help_msg_equal); break; default: - r_core_rtr_cmd (core, input); + rz_core_rtr_cmd (core, input); break; } return 0; } static int cmd_rap_run(void *data, const char *input) { - RCore *core = (RCore *)data; - char *res = r_io_system (core->io, input); + RzCore *core = (RzCore *)data; + char *res = rz_io_system (core->io, input); if (res) { int ret = atoi (res); free (res); @@ -867,38 +867,38 @@ static int cmd_rap_run(void *data, const char *input) { static int cmd_yank(void *data, const char *input) { ut64 n; - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (input[0]) { case ' ': // "y " - r_core_yank (core, core->offset, r_num_math (core->num, input + 1)); + rz_core_yank (core, core->offset, rz_num_math (core->num, input + 1)); break; case 'l': // "yl" - core->num->value = r_buf_size (core->yank_buf); + core->num->value = rz_buf_size (core->yank_buf); break; case 'y': // "yy" while (input[1] == ' ') { input++; } - n = input[1]? r_num_math (core->num, input + 1): core->offset; - r_core_yank_paste (core, n, 0); + n = input[1]? rz_num_math (core->num, input + 1): core->offset; + rz_core_yank_paste (core, n, 0); break; case 'x': // "yx" - r_core_yank_hexdump (core, r_num_math (core->num, input + 1)); + rz_core_yank_hexdump (core, rz_num_math (core->num, input + 1)); break; case 'z': // "yz" - r_core_yank_string (core, core->offset, r_num_math (core->num, input + 1)); + rz_core_yank_string (core, core->offset, rz_num_math (core->num, input + 1)); break; case 'w': // "yw" ... we have yf which makes more sense than 'w' switch (input[1]) { case ' ': - r_core_yank_set (core, 0, (const ut8*)input + 2, strlen (input + 2)); + rz_core_yank_set (core, 0, (const ut8*)input + 2, strlen (input + 2)); break; case 'x': if (input[2] == ' ') { char *out = strdup (input + 3); - int len = r_hex_str2bin (input + 3, (ut8*)out); + int len = rz_hex_str2bin (input + 3, (ut8*)out); if (len > 0) { - r_core_yank_set (core, core->offset, (const ut8*)out, len); + rz_core_yank_set (core, core->offset, (const ut8*)out, len); } else { eprintf ("Invalid length\n"); } @@ -906,7 +906,7 @@ static int cmd_yank(void *data, const char *input) { } else { eprintf ("Usage: ywx [hexpairs]\n"); } - // r_core_yank_write_hex (core, input + 2); + // rz_core_yank_write_hex (core, input + 2); break; default: eprintf ("Usage: ywx [hexpairs]\n"); @@ -914,21 +914,21 @@ static int cmd_yank(void *data, const char *input) { } break; case 'p': // "yp" - r_core_yank_cat (core, r_num_math (core->num, input + 1)); + rz_core_yank_cat (core, rz_num_math (core->num, input + 1)); break; case 's': // "ys" - r_core_yank_cat_string (core, r_num_math (core->num, input + 1)); + rz_core_yank_cat_string (core, rz_num_math (core->num, input + 1)); break; case 't': // "wt" if (input[1] == 'f') { // "wtf" ut64 tmpsz; - const char *file = r_str_trim_head_ro (input + 2); - const ut8 *tmp = r_buf_data (core->yank_buf, &tmpsz); - if (!r_file_dump (file, tmp, tmpsz, false)) { + const char *file = rz_str_trim_head_ro (input + 2); + const ut8 *tmp = rz_buf_data (core->yank_buf, &tmpsz); + if (!rz_file_dump (file, tmp, tmpsz, false)) { eprintf ("Cannot dump to '%s'\n", file); } } else if (input[1] == ' ') { - r_core_yank_to (core, input + 1); + rz_core_yank_to (core, input + 1); } else { eprintf ("Usage: wt[f] [arg] ..\n"); } @@ -936,13 +936,13 @@ static int cmd_yank(void *data, const char *input) { case 'f': // "yf" switch (input[1]) { case ' ': // "yf" - r_core_yank_file_ex (core, input + 1); + rz_core_yank_file_ex (core, input + 1); break; case 'x': // "yfx" - r_core_yank_hexpair (core, input + 2); + rz_core_yank_hexpair (core, input + 2); break; case 'a': // "yfa" - r_core_yank_file_all (core, input + 2); + rz_core_yank_file_all (core, input + 2); break; default: eprintf ("Usage: yf[xa] [arg]\n"); @@ -954,14 +954,14 @@ static int cmd_yank(void *data, const char *input) { break; case '!': // "y!" { - char *sig = r_core_cmd_str (core, "y*"); + char *sig = rz_core_cmd_str (core, "y*"); if (!sig || !*sig) { free (sig); sig = strdup ("wx 10203040"); } - char *data = r_core_editor (core, NULL, sig); + char *data = rz_core_editor (core, NULL, sig); (void) strtok (data, ";\n"); - r_core_cmdf (core, "y%s", data); + rz_core_cmdf (core, "y%s", data); free (sig); free (data); } @@ -970,25 +970,25 @@ static int cmd_yank(void *data, const char *input) { case 'j': // "yj" case 'q': // "yq" case '\0': // "y" - r_core_yank_dump (core, 0, input[0]); + rz_core_yank_dump (core, 0, input[0]); break; default: - r_core_cmd_help (core, help_msg_y); + rz_core_cmd_help (core, help_msg_y); break; } return true; } -static int lang_run_file(RCore *core, RLang *lang, const char *file) { - r_core_sysenv_begin (core, NULL); - return r_lang_run_file (core->lang, file); +static int lang_run_file(RzCore *core, RzLang *lang, const char *file) { + rz_core_sysenv_begin (core, NULL); + return rz_lang_run_file (core->lang, file); } -static char *langFromHashbang(RCore *core, const char *file) { - int fd = r_sandbox_open (file, O_RDONLY, 0); +static char *langFromHashbang(RzCore *core, const char *file) { + int fd = rz_sandbox_open (file, O_RDONLY, 0); if (fd != -1) { char firstLine[128] = {0}; - int len = r_sandbox_read (fd, (ut8*)firstLine, sizeof (firstLine) - 1); + int len = rz_sandbox_read (fd, (ut8*)firstLine, sizeof (firstLine) - 1); firstLine[len] = 0; if (!strncmp (firstLine, "#!/", 3)) { // I CAN HAS A HASHBANG @@ -1001,138 +1001,138 @@ static char *langFromHashbang(RCore *core, const char *file) { *nl = 0; } nl = strdup (firstLine + 2); - r_sandbox_close (fd); + rz_sandbox_close (fd); return nl; } - r_sandbox_close (fd); + rz_sandbox_close (fd); } return NULL; } -R_API bool r_core_run_script(RCore *core, const char *file) { +RZ_API bool rz_core_run_script(RzCore *core, const char *file) { bool ret = false; - RListIter *iter; - RLangPlugin *p; + RzListIter *iter; + RzLangPlugin *p; char *name; - r_list_foreach (core->scriptstack, iter, name) { + rz_list_foreach (core->scriptstack, iter, name) { if (!strcmp (file, name)) { eprintf ("WARNING: ignored nested source: %s\n", file); return false; } } - r_list_push (core->scriptstack, strdup (file)); + rz_list_push (core->scriptstack, strdup (file)); if (!strcmp (file, "-")) { - char *out = r_core_editor (core, NULL, NULL); + char *out = rz_core_editor (core, NULL, NULL); if (out) { - ret = r_core_cmd_lines (core, out); + ret = rz_core_cmd_lines (core, out); free (out); } - } else if (r_str_endswith (file, ".html")) { - const bool httpSandbox = r_config_get_i (core->config, "http.sandbox"); - char *httpIndex = strdup (r_config_get (core->config, "http.index")); - r_config_set_i (core->config, "http.sandbox", 0); - char *absfile = r_file_abspath (file); - r_config_set (core->config, "http.index", absfile); + } else if (rz_str_endswith (file, ".html")) { + const bool httpSandbox = rz_config_get_i (core->config, "http.sandbox"); + char *httpIndex = strdup (rz_config_get (core->config, "http.index")); + rz_config_set_i (core->config, "http.sandbox", 0); + char *absfile = rz_file_abspath (file); + rz_config_set (core->config, "http.index", absfile); free (absfile); - r_core_cmdf (core, "=H"); - r_config_set_i (core->config, "http.sandbox", httpSandbox); - r_config_set (core->config, "http.index", httpIndex); + rz_core_cmdf (core, "=H"); + rz_config_set_i (core->config, "http.sandbox", httpSandbox); + rz_config_set (core->config, "http.index", httpIndex); free (httpIndex); ret = true; - } else if (r_str_endswith (file, ".c")) { - r_core_cmd_strf (core, "#!c %s", file); + } else if (rz_str_endswith (file, ".c")) { + rz_core_cmd_strf (core, "#!c %s", file); ret = true; - } else if (r_file_is_c (file)) { - const char *dir = r_config_get (core->config, "dir.types"); - char *out = r_parse_c_file (core->anal, file, dir, NULL); + } else if (rz_file_is_c (file)) { + const char *dir = rz_config_get (core->config, "dir.types"); + char *out = rz_parse_c_file (core->anal, file, dir, NULL); if (out) { - r_cons_strcat (out); + rz_cons_strcat (out); sdb_query_lines (core->anal->sdb_types, out); free (out); } ret = out != NULL; } else { - p = r_lang_get_by_extension (core->lang, file); + p = rz_lang_get_by_extension (core->lang, file); if (p) { - r_lang_use (core->lang, p->name); + rz_lang_use (core->lang, p->name); ret = lang_run_file (core, core->lang, file); } else { // XXX this is an ugly hack, we need to use execve here and specify args properly #if __WINDOWS__ -#define cmdstr(x) r_str_newf (x" %s", file); +#define cmdstr(x) rz_str_newf (x" %s", file); #else -#define cmdstr(x) r_str_newf (x" '%s'", file); +#define cmdstr(x) rz_str_newf (x" '%s'", file); #endif - const char *p = r_str_lchr (file, '.'); + const char *p = rz_str_lchr (file, '.'); if (p) { const char *ext = p + 1; - /* TODO: handle this inside r_lang_pipe with new APIs */ + /* TODO: handle this inside rz_lang_pipe with new APIs */ if (!strcmp (ext, "js")) { char *cmd = cmdstr ("node"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "exe")) { #if __WINDOWS__ - char *cmd = r_str_newf ("%s", file); + char *cmd = rz_str_newf ("%s", file); #else char *cmd = cmdstr ("wine"); #endif - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "zig")) { char *cmd = cmdstr ("zig run"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "d")) { char *cmd = cmdstr ("dmd -run"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "lsp")) { char *cmd = cmdstr ("newlisp -n"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "go")) { char *cmd = cmdstr ("go run"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "es6")) { char *cmd = cmdstr ("babel-node"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "rb")) { char *cmd = cmdstr ("ruby"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "vala")) { - r_lang_use (core->lang, "vala"); + rz_lang_use (core->lang, "vala"); lang_run_file (core, core->lang, file); ret = 1; } else if (!strcmp (ext, "sh")) { - char *shell = r_sys_getenv ("SHELL"); + char *shell = rz_sys_getenv ("SHELL"); if (!shell) { shell = strdup ("sh"); } if (shell) { - r_lang_use (core->lang, "pipe"); - char *cmd = r_str_newf ("%s '%s'", shell, file); + rz_lang_use (core->lang, "pipe"); + char *cmd = rz_str_newf ("%s '%s'", shell, file); if (cmd) { lang_run_file (core, core->lang, cmd); free (cmd); @@ -1142,23 +1142,23 @@ R_API bool r_core_run_script(RCore *core, const char *file) { ret = 1; } else if (!strcmp (ext, "pl")) { char *cmd = cmdstr ("perl"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } else if (!strcmp (ext, "py")) { char *cmd = cmdstr ("python"); - r_lang_use (core->lang, "pipe"); + rz_lang_use (core->lang, "pipe"); lang_run_file (core, core->lang, cmd); free (cmd); ret = 1; } } else { - char *abspath = r_file_path (file); + char *abspath = rz_file_path (file); char *lang = langFromHashbang (core, file); if (lang) { - r_lang_use (core->lang, "pipe"); - char *cmd = r_str_newf ("%s '%s'", lang, file); + rz_lang_use (core->lang, "pipe"); + char *cmd = rz_str_newf ("%s '%s'", lang, file); lang_run_file (core, core->lang, cmd); free (lang); free (cmd); @@ -1167,19 +1167,19 @@ R_API bool r_core_run_script(RCore *core, const char *file) { free (abspath); } if (!ret) { - ret = r_core_cmd_file (core, file); + ret = rz_core_cmd_file (core, file); } } } - free (r_list_pop (core->scriptstack)); + free (rz_list_pop (core->scriptstack)); return ret; } static int cmd_ls(void *data, const char *input) { // "ls" - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; const char *arg = strchr (input, ' '); if (arg) { - arg = r_str_trim_head_ro (arg + 1); + arg = rz_str_trim_head_ro (arg + 1); } switch (*input) { case '?': // "l?" @@ -1187,7 +1187,7 @@ static int cmd_ls(void *data, const char *input) { // "ls" break; case 'e': // "le" if (arg) { - r_core_cmdf (core, "cat %s~..", arg); + rz_core_cmdf (core, "cat %s~..", arg); } else { eprintf ("Usage: less [file]\n"); } @@ -1196,12 +1196,12 @@ static int cmd_ls(void *data, const char *input) { // "ls" if (!arg) { arg = ""; } - if (r_fs_check (core->fs, arg)) { - r_core_cmdf (core, "md %s", arg); + if (rz_fs_check (core->fs, arg)) { + rz_core_cmdf (core, "md %s", arg); } else { - char *res = r_syscmd_ls (arg); + char *res = rz_syscmd_ls (arg); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -1211,13 +1211,13 @@ static int cmd_ls(void *data, const char *input) { // "ls" } static int cmd_join(void *data, const char *input) { // "join" - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; char *tmp = strdup (input); const char *arg1 = strchr (tmp, ' '); if (!arg1) { goto beach; } - arg1 = r_str_trim_head_ro (arg1); + arg1 = rz_str_trim_head_ro (arg1); if (!arg1) { goto beach; } @@ -1230,7 +1230,7 @@ static int cmd_join(void *data, const char *input) { // "join" if (!arg2) { goto beach; } - arg2 = r_str_trim_head_ro (arg2); + arg2 = rz_str_trim_head_ro (arg2); switch (*input) { case '?': // "join?" goto beach; @@ -1241,10 +1241,10 @@ static int cmd_join(void *data, const char *input) { // "join" if (!arg2) { arg2 = ""; } - if (!r_fs_check (core->fs, arg1) && !r_fs_check (core->fs, arg2)) { - char *res = r_syscmd_join (arg1, arg2); + if (!rz_fs_check (core->fs, arg1) && !rz_fs_check (core->fs, arg2)) { + char *res = rz_syscmd_join (arg1, arg2); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -1259,21 +1259,21 @@ beach: } static int cmd_stdin(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input[0] == '?') { - r_cons_printf ("Usage: '-' '.-' '. -' do the same\n"); + rz_cons_printf ("Usage: '-' '.-' '. -' do the same\n"); return false; } - return r_core_run_script (core, "-"); + return rz_core_run_script (core, "-"); } static int cmd_interpret(void *data, const char *input) { char *str, *ptr, *eol, *rbuf, *filter, *inp; const char *host, *port, *cmd; - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (!strcmp (input, "?")) { - r_core_cmd_help (core, help_msg_dot); + rz_core_cmd_help (core, help_msg_dot); return 0; } switch (*input) { @@ -1295,13 +1295,13 @@ static int cmd_interpret(void *data, const char *input) { host = "localhost"; port = input + ((input[1] == ':')? 2: 1); } - rbuf = r_core_rtr_cmds_query (core, host, port, cmd); + rbuf = rz_core_rtr_cmds_query (core, host, port, cmd); if (rbuf) { - r_cons_print (rbuf); + rz_cons_print (rbuf); free (rbuf); } } else { - r_core_rtr_cmds (core, input + 1); + rz_core_rtr_cmds (core, input + 1); } break; case '.': // ".." same as \n @@ -1309,9 +1309,9 @@ static int cmd_interpret(void *data, const char *input) { // same as \n with e cmd.repeat=true lastcmd_repeat (core, 1); } else if (input[1]) { - char *str = r_core_cmd_str_pipe (core, r_str_trim_head_ro (input)); + char *str = rz_core_cmd_str_pipe (core, rz_str_trim_head_ro (input)); if (str) { - r_core_cmd (core, str, 0); + rz_core_cmd (core, str, 0); free (str); } } else { @@ -1320,32 +1320,32 @@ static int cmd_interpret(void *data, const char *input) { break; case '*': // ".*" { - const char *a = r_str_trim_head_ro (input + 1); + const char *a = rz_str_trim_head_ro (input + 1); char *s = strdup (a); char *sp = strchr (s, ' '); if (sp) { *sp = 0; } if (R_STR_ISNOTEMPTY (s)) { - r_core_run_script (core, s); + rz_core_run_script (core, s); } free (s); } break; case '-': // ".-" if (input[1] == '?') { - r_cons_printf ("Usage: '-' '.-' '. -' do the same\n"); + rz_cons_printf ("Usage: '-' '.-' '. -' do the same\n"); } else { - r_core_run_script (core, "-"); + rz_core_run_script (core, "-"); } break; case ' ': // ". " { - const char *script_file = r_str_trim_head_ro (input + 1); + const char *script_file = rz_str_trim_head_ro (input + 1); if (*script_file == '$') { - r_core_cmd0 (core, script_file); + rz_core_cmd0 (core, script_file); } else { - if (!r_core_run_script (core, script_file)) { + if (!rz_core_run_script (core, script_file)) { eprintf ("Cannot find script '%s'\n", script_file); core->num->value = 1; } else { @@ -1356,10 +1356,10 @@ static int cmd_interpret(void *data, const char *input) { break; case '!': // ".!" /* from command */ - r_core_cmd_command (core, input + 1); + rz_core_cmd_command (core, input + 1); break; case '(': // ".(" - r_cmd_macro_call (&core->rcmd->macro, input + 1); + rz_cmd_macro_call (&core->rcmd->macro, input + 1); break; default: if (*input >= 0 && *input <= 9) { @@ -1371,18 +1371,18 @@ static int cmd_interpret(void *data, const char *input) { if (filter) { *filter = 0; } - int tmp_html = r_cons_singleton ()->is_html; - r_cons_singleton ()->is_html = 0; - ptr = str = r_core_cmd_str (core, inp); - r_cons_singleton ()->is_html = tmp_html; + int tmp_html = rz_cons_singleton ()->is_html; + rz_cons_singleton ()->is_html = 0; + ptr = str = rz_core_cmd_str (core, inp); + rz_cons_singleton ()->is_html = tmp_html; if (filter) { *filter = '~'; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); if (ptr) { for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } eol = strchr (ptr, '\n'); @@ -1390,8 +1390,8 @@ static int cmd_interpret(void *data, const char *input) { *eol = '\0'; } if (*ptr) { - char *p = r_str_append (strdup (ptr), filter); - r_core_cmd0 (core, p); + char *p = rz_str_append (strdup (ptr), filter); + rz_core_cmd0 (core, p); free (p); } if (!eol) { @@ -1400,7 +1400,7 @@ static int cmd_interpret(void *data, const char *input) { ptr = eol + 1; } } - r_cons_break_pop (); + rz_cons_break_pop (); free (str); free (inp); break; @@ -1409,11 +1409,11 @@ static int cmd_interpret(void *data, const char *input) { } static bool callback_foreach_kv(void *user, const char *k, const char *v) { - r_cons_printf ("%s=%s\n", k, v); + rz_cons_printf ("%s=%s\n", k, v); return true; } -R_API int r_line_hist_sdb_up(RLine *line) { +RZ_API int rz_line_hist_sdb_up(RLine *line) { if (!line->sdbshell_hist_iter || !line->sdbshell_hist_iter->n) { return false; } @@ -1423,7 +1423,7 @@ R_API int r_line_hist_sdb_up(RLine *line) { return true; } -R_API int r_line_hist_sdb_down(RLine *line) { +RZ_API int rz_line_hist_sdb_down(RLine *line) { if (!line->sdbshell_hist_iter || !line->sdbshell_hist_iter->p) { return false; } @@ -1435,7 +1435,7 @@ R_API int r_line_hist_sdb_down(RLine *line) { static int cmd_kuery(void *data, const char *input) { char buf[1024], *out; - RCore *core = (RCore*)data; + RzCore *core = (RzCore*)data; const char *sp, *p = "[sdb]> "; Sdb *s = core->sdb; @@ -1447,7 +1447,7 @@ static int cmd_kuery(void *data, const char *input) { case 'j': out = sdb_querys (s, NULL, 0, "anal/**"); if (!out) { - r_cons_println ("No Output from sdb"); + rz_cons_println ("No Output from sdb"); break; } PJ * pj = pj_new (); @@ -1464,12 +1464,12 @@ static int cmd_kuery(void *data, const char *input) { if (!cur_pos) { break; } - cur_cmd = r_str_ndup (out, cur_pos - out); + cur_cmd = rz_str_ndup (out, cur_pos - out); pj_s (pj, cur_cmd); free (next_cmd); - next_cmd = r_str_newf ("anal/%s/*", cur_cmd); + next_cmd = rz_str_newf ("anal/%s/*", cur_cmd); temp_storage = sdb_querys (s, NULL, 0, next_cmd); if (!temp_storage) { @@ -1482,7 +1482,7 @@ static int cmd_kuery(void *data, const char *input) { if (!temp_pos) { break; } - temp_cmd = r_str_ndup (temp_storage, temp_pos - temp_storage); + temp_cmd = rz_str_ndup (temp_storage, temp_pos - temp_storage); pj_s (pj, temp_cmd); temp_storage += temp_pos - temp_storage + 1; } @@ -1493,7 +1493,7 @@ static int cmd_kuery(void *data, const char *input) { pj_end (pj); char *a = pj_drain (pj); if (a) { - r_cons_println (a); + rz_cons_println (a); free (a); } R_FREE (next_cmd); @@ -1505,12 +1505,12 @@ static int cmd_kuery(void *data, const char *input) { case ' ': out = sdb_querys (s, NULL, 0, input + 1); if (out) { - r_cons_print (out); + rz_cons_print (out); } free (out); break; - //case 's': r_pair_save (s, input + 3); break; - //case 'l': r_pair_load (sdb, input + 3); break; + //case 's': rz_pair_save (s, input + 3); break; + //case 'l': rz_pair_load (sdb, input + 3); break; case '\0': sdb_foreach (s, callback_foreach_kv, NULL); break; @@ -1519,7 +1519,7 @@ static int cmd_kuery(void *data, const char *input) { if (core->http_up) { return false; } - if (!r_cons_is_interactive ()) { + if (!rz_cons_is_interactive ()) { return false; } if (input[1] == ' ') { @@ -1539,35 +1539,35 @@ static int cmd_kuery(void *data, const char *input) { } RLine *line = core->cons->line; if (!line->sdbshell_hist) { - line->sdbshell_hist = r_list_newf (free); - r_list_append (line->sdbshell_hist, r_str_new ("\0")); + line->sdbshell_hist = rz_list_newf (free); + rz_list_append (line->sdbshell_hist, rz_str_new ("\0")); } - RList *sdb_hist = line->sdbshell_hist; - r_line_set_hist_callback (line, &r_line_hist_sdb_up, &r_line_hist_sdb_down); + RzList *sdb_hist = line->sdbshell_hist; + rz_line_set_hist_callback (line, &rz_line_hist_sdb_up, &rz_line_hist_sdb_down); for (;;) { - r_line_set_prompt (p); - if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 1) { + rz_line_set_prompt (p); + if (rz_cons_fgets (buf, sizeof (buf), 0, NULL) < 1) { break; } if (!*buf) { break; } if (sdb_hist) { - if ((r_list_length (sdb_hist) == 1) || (r_list_length (sdb_hist) > 1 && strcmp (r_list_get_n (sdb_hist, 1), buf))) { - r_list_insert (sdb_hist, 1, strdup (buf)); + if ((rz_list_length (sdb_hist) == 1) || (rz_list_length (sdb_hist) > 1 && strcmp (rz_list_get_n (sdb_hist, 1), buf))) { + rz_list_insert (sdb_hist, 1, strdup (buf)); } line->sdbshell_hist_iter = sdb_hist->head; } out = sdb_querys (s, NULL, 0, buf); if (out) { - r_cons_println (out); - r_cons_flush (); + rz_cons_println (out); + rz_cons_flush (); } } - r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); break; case 'o': // "ko" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } @@ -1581,7 +1581,7 @@ static int cmd_kuery(void *data, const char *input) { if (ns) { Sdb *db; *ns++ = 0; - if (r_file_exists (fn)) { + if (rz_file_exists (fn)) { db = sdb_ns_path (core->sdb, ns, 1); if (db) { Sdb *newdb = sdb_new (NULL, fn, 0); @@ -1605,7 +1605,7 @@ static int cmd_kuery(void *data, const char *input) { } break; case 'd': // "kd" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } @@ -1630,7 +1630,7 @@ static int cmd_kuery(void *data, const char *input) { } break; case '?': - r_core_cmd_help (core, help_msg_k); + rz_core_cmd_help (core, help_msg_k); break; } @@ -1646,7 +1646,7 @@ static int cmd_kuery(void *data, const char *input) { s = sdb_ns (core->sdb, inp + 1, 1); out = sdb_querys (s, NULL, 0, sp + 1); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } free (inp); @@ -1657,30 +1657,30 @@ static int cmd_kuery(void *data, const char *input) { static int cmd_bsize(void *data, const char *input) { ut64 n; - RFlagItem *flag; - RCore *core = (RCore *)data; + RzFlagItem *flag; + RzCore *core = (RzCore *)data; switch (input[0]) { case 'm': // "bm" - n = r_num_math (core->num, input + 1); + n = rz_num_math (core->num, input + 1); if (n > 1) { core->blocksize_max = n; } else { - r_cons_printf ("0x%x\n", (ut32)core->blocksize_max); + rz_cons_printf ("0x%x\n", (ut32)core->blocksize_max); } break; case '+': // "b+" - n = r_num_math (core->num, input + 1); - r_core_block_size (core, core->blocksize + n); + n = rz_num_math (core->num, input + 1); + rz_core_block_size (core, core->blocksize + n); break; case '-': // "b-" - n = r_num_math (core->num, input + 1); - r_core_block_size (core, core->blocksize - n); + n = rz_num_math (core->num, input + 1); + rz_core_block_size (core, core->blocksize - n); break; case 'f': // "bf" if (input[1] == ' ') { - flag = r_flag_get (core->flags, input + 2); + flag = rz_flag_get (core->flags, input + 2); if (flag) { - r_core_block_size (core, flag->size); + rz_core_block_size (core, flag->size); } else { eprintf ("bf: cannot find flag named '%s'\n", input + 2); } @@ -1689,67 +1689,67 @@ static int cmd_bsize(void *data, const char *input) { } break; case 'j': // "bj" - r_cons_printf ("{\"blocksize\":%d,\"blocksize_limit\":%d}\n", core->blocksize, core->blocksize_max); + rz_cons_printf ("{\"blocksize\":%d,\"blocksize_limit\":%d}\n", core->blocksize, core->blocksize_max); break; case '*': // "b*" - r_cons_printf ("b 0x%x\n", core->blocksize); + rz_cons_printf ("b 0x%x\n", core->blocksize); break; case '\0': // "b" - r_cons_printf ("0x%x\n", core->blocksize); + rz_cons_printf ("0x%x\n", core->blocksize); break; case ' ': - r_core_block_size (core, r_num_math (core->num, input)); + rz_core_block_size (core, rz_num_math (core->num, input)); break; default: case '?': // "b?" - r_core_cmd_help (core, help_msg_b); + rz_core_cmd_help (core, help_msg_b); break; } return 0; } -static int __runMain(RMainCallback cb, const char *arg) { - char *a = r_str_trim_dup (arg); +static int __runMain(RzMainCallback cb, const char *arg) { + char *a = rz_str_trim_dup (arg); int argc = 0; - char **args = r_str_argv (a, &argc); + char **args = rz_str_argv (a, &argc); int res = cb (argc, (const char **)args); free (args); free (a); return res; } -static bool cmd_r2cmd(RCore *core, const char *_input) { - char *input = r_str_newf ("r%s", _input); +static bool cmd_rzcmd(RzCore *core, const char *_input) { + char *input = rz_str_newf ("r%s", _input); int rc = 0; - if (r_str_startswith (input, "rax2")) { - rc = __runMain (core->r_main_rax2, input); - } else if (r_str_startswith (input, "r2")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_radare2, input); - } else if (r_str_startswith (input, "radare2")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_radare2, input); - } else if (r_str_startswith (input, "rasm2")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_rasm2, input); - } else if (r_str_startswith (input, "rabin2")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_rabin2, input); - } else if (r_str_startswith (input, "ragg2")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_ragg2, input); - } else if (r_str_startswith (input, "r2pm")) { - r_sys_cmdf ("%s", input); - // rc = __runMain (core->r_main_r2pm, input); - } else if (r_str_startswith (input, "radiff2")) { - rc = __runMain (core->r_main_radiff2, input); + if (rz_str_startswith (input, "rz_ax")) { + rc = __runMain (core->rz_main_rz_ax, input); + } else if (rz_str_startswith (input, "r2")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rizin, input); + } else if (rz_str_startswith (input, "rizin")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rizin, input); + } else if (rz_str_startswith (input, "rz_asm")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rz_asm, input); + } else if (rz_str_startswith (input, "rz_bin")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rz_bin, input); + } else if (rz_str_startswith (input, "rz_gg")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rz_gg, input); + } else if (rz_str_startswith (input, "rz_pm")) { + rz_sys_cmdf ("%s", input); + // rc = __runMain (core->rz_main_rz_pm, input); + } else if (rz_str_startswith (input, "rz_diff")) { + rc = __runMain (core->rz_main_rz_diff, input); } else { const char *r2cmds[] = { - "rax2", "r2pm", "rasm2", "rabin2", "rahash2", "rafind2", "rarun2", "ragg2", "radare2", "r2", NULL + "rz_ax", "rz_pm", "rz_asm", "rz_bin", "rz_hash", "rz_find", "rz_run", "rz_gg", "rizin", "r2", NULL }; int i; for (i = 0; r2cmds[i]; i++) { - if (r_str_startswith (input, r2cmds[i])) { + if (rz_str_startswith (input, r2cmds[i])) { free (input); return true; } @@ -1762,57 +1762,57 @@ static bool cmd_r2cmd(RCore *core, const char *_input) { return true; } -static int cmd_rebase(RCore *core, const char *input) { - ut64 addr = r_num_math (core->num, input); +static int cmd_rebase(RzCore *core, const char *input) { + ut64 addr = rz_num_math (core->num, input); if (!addr) { - r_cons_printf ("Usage: rb oldbase @ newbase\n"); + rz_cons_printf ("Usage: rb oldbase @ newbase\n"); return 0; } // old base = addr // new base = core->offset - r_debug_bp_rebase (core->dbg, addr, core->offset); - r_bin_set_baddr (core->bin, core->offset); - r_flag_move (core->flags, addr, core->offset); - r_core_cmd0 (core, ".is*"); - r_core_cmd0 (core, ".iM*"); - r_core_cmd0 (core, ".ii*"); - r_core_cmd0 (core, ".iz*"); - // TODO: r_anal_move :?? + rz_debug_bp_rebase (core->dbg, addr, core->offset); + rz_bin_set_baddr (core->bin, core->offset); + rz_flag_move (core->flags, addr, core->offset); + rz_core_cmd0 (core, ".is*"); + rz_core_cmd0 (core, ".iM*"); + rz_core_cmd0 (core, ".ii*"); + rz_core_cmd0 (core, ".iz*"); + // TODO: rz_anal_move :?? // TODO: differentiate analysis by map ranges (associated with files or memory maps) return 0; } static int cmd_resize(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut64 newsize = 0; st64 delta = 0; int grow, ret; - if (cmd_r2cmd (core, input)) { + if (cmd_rzcmd (core, input)) { return true; } - ut64 oldsize = (core->file) ? r_io_fd_size (core->io, core->file->fd): 0; + ut64 oldsize = (core->file) ? rz_io_fd_size (core->io, core->file->fd): 0; switch (*input) { case 'a': // "r..." - if (r_str_startswith (input, "adare2")) { - __runMain (core->r_main_radare2, input - 1); + if (rz_str_startswith (input, "adare2")) { + __runMain (core->rz_main_rizin, input - 1); } return true; case 'b': // "rb" rebase return cmd_rebase (core, input + 1); - case '2': // "r2" // XXX should be handled already in cmd_r2cmd() - // TODO: use argv[0] instead of 'radare2' - // TODO: { char **argv = { "r2", NULL }; r_main_radare2 (1, argv); } - r_sys_cmdf ("radare%s", input); + case '2': // "r2" // XXX should be handled already in cmd_rzcmd() + // TODO: use argv[0] instead of 'rizin' + // TODO: { char **argv = { "r2", NULL }; rz_main_rizin (1, argv); } + rz_sys_cmdf ("radare%s", input); return true; case 'm': // "rm" if (input[1] == ' ') { - const char *file = r_str_trim_head_ro (input + 2); + const char *file = rz_str_trim_head_ro (input + 2); if (*file == '$') { - r_cmd_alias_del (core->rcmd, file); + rz_cmd_alias_del (core->rcmd, file); } else { - r_file_rm (file); + rz_file_rm (file); } } else { eprintf ("Usage: rm [file] # removes a file\n"); @@ -1821,7 +1821,7 @@ static int cmd_resize(void *data, const char *input) { case '\0': if (core->file) { if (oldsize != -1) { - r_cons_printf ("%"PFMT64d"\n", oldsize); + rz_cons_printf ("%"PFMT64d"\n", oldsize); } } return true; @@ -1833,7 +1833,7 @@ static int cmd_resize(void *data, const char *input) { } pj_end (pj); char *s = pj_drain (pj); - r_cons_println (s); + rz_cons_println (s); free (s); return true; } @@ -1841,18 +1841,18 @@ static int cmd_resize(void *data, const char *input) { if (core->file) { if (oldsize != -1) { char humansz[8]; - r_num_units (humansz, sizeof (humansz), oldsize); - r_cons_printf ("%s\n", humansz); + rz_num_units (humansz, sizeof (humansz), oldsize); + rz_cons_printf ("%s\n", humansz); } } return true; case '+': // "r+" case '-': // "r-" - delta = (st64)r_num_math (core->num, input); + delta = (st64)rz_num_math (core->num, input); newsize = oldsize + delta; break; case ' ': // "r " - newsize = r_num_math (core->num, input + 1); + newsize = rz_num_math (core->num, input + 1); if (newsize == 0) { if (input[1] == '0') { eprintf ("Invalid size\n"); @@ -1865,34 +1865,34 @@ static int cmd_resize(void *data, const char *input) { return true; case '?': // "r?" default: - r_core_cmd_help (core, help_msg_r); + rz_core_cmd_help (core, help_msg_r); return true; } grow = (newsize > oldsize); if (grow) { - ret = r_io_resize (core->io, newsize); + ret = rz_io_resize (core->io, newsize); if (ret < 1) { - eprintf ("r_io_resize: cannot resize\n"); + eprintf ("rz_io_resize: cannot resize\n"); } } if (delta && core->offset < newsize) { - r_io_shift (core->io, core->offset, grow?newsize:oldsize, delta); + rz_io_shift (core->io, core->offset, grow?newsize:oldsize, delta); } if (!grow) { - ret = r_io_resize (core->io, newsize); + ret = rz_io_resize (core->io, newsize); if (ret < 1) { - eprintf ("r_io_resize: cannot resize\n"); + eprintf ("rz_io_resize: cannot resize\n"); } } if (newsize < core->offset+core->blocksize || oldsize < core->offset + core->blocksize) { - r_core_block_read (core); + rz_core_block_read (core); } return true; } static int cmd_panels(void *data, const char *input) { - RCore *core = (RCore*) data; + RzCore *core = (RzCore*) data; if (core->vmode) { return false; } @@ -1903,96 +1903,96 @@ static int cmd_panels(void *data, const char *input) { eprintf ("vi ... # launch 'cfg.editor'\n"); return false; } - if (!r_cons_is_interactive ()) { + if (!rz_cons_is_interactive ()) { eprintf ("Panel mode requires scr.interactive=true.\n"); return false; } if (*input == ' ') { if (core->panels) { - r_load_panels_layout (core, input + 1); + rz_load_panels_layout (core, input + 1); } - r_config_set (core->config, "scr.layout", input + 1); + rz_config_set (core->config, "scr.layout", input + 1); return true; } if (*input == '=') { - r_save_panels_layout (core, input + 1); - r_config_set (core->config, "scr.layout", input + 1); + rz_save_panels_layout (core, input + 1); + rz_config_set (core->config, "scr.layout", input + 1); return true; } if (*input == 'i') { char *sp = strchr (input, ' '); if (sp) { - char *r = r_core_editor (core, sp + 1, NULL); + char *r = rz_core_editor (core, sp + 1, NULL); if (r) { free (r); } else { eprintf ("Cannot open file (%s)\n", sp + 1); } } - ////r_sys_cmdf ("v%s", input); + ////rz_sys_cmdf ("v%s", input); return false; } - r_core_visual_panels_root (core, core->panels_root); + rz_core_visual_panels_root (core, core->panels_root); return true; } static int cmd_visual(void *data, const char *input) { - RCore *core = (RCore*) data; + RzCore *core = (RzCore*) data; if (core->http_up) { return false; } - if (!r_cons_is_interactive ()) { + if (!rz_cons_is_interactive ()) { eprintf ("Visual mode requires scr.interactive=true.\n"); return false; } - return r_core_visual ((RCore *)data, input); + return rz_core_visual ((RzCore *)data, input); } static int cmd_pipein(void *user, const char *input) { char *buf = strdup (input); - int len = r_str_unescape (buf); - r_cons_readpush (buf, len); + int len = rz_str_unescape (buf); + rz_cons_readpush (buf, len); free (buf); return 0; } static int cmd_tasks(void *data, const char *input) { - RCore *core = (RCore*) data; + RzCore *core = (RzCore*) data; switch (input[0]) { case '\0': // "&" case 'j': // "&j" - r_core_task_list (core, *input); + rz_core_task_list (core, *input); break; case 'b': { // "&b" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } - int tid = r_num_math (core->num, input + 1); + int tid = rz_num_math (core->num, input + 1); if (tid) { - r_core_task_break (&core->tasks, tid); + rz_core_task_break (&core->tasks, tid); } break; } case '&': { // "&&" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } - int tid = r_num_math (core->num, input + 1); - r_core_task_join (&core->tasks, core->tasks.current_task, tid ? tid : -1); + int tid = rz_num_math (core->num, input + 1); + rz_core_task_join (&core->tasks, core->tasks.current_task, tid ? tid : -1); break; } case '=': { // "&=" - // r_core_task_list (core, '='); - int tid = r_num_math (core->num, input + 1); + // rz_core_task_list (core, '='); + int tid = rz_num_math (core->num, input + 1); if (tid) { - RCoreTask *task = r_core_task_get_incref (&core->tasks, tid); + RzCoreTask *task = rz_core_task_get_incref (&core->tasks, tid); if (task) { if (task->res) { - r_cons_println (task->res); + rz_cons_println (task->res); } - r_core_task_decref (task); + rz_core_task_decref (task); } else { eprintf ("Cannot find task\n"); } @@ -2000,14 +2000,14 @@ static int cmd_tasks(void *data, const char *input) { break; } case '-': // "&-" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } if (input[1] == '*') { - r_core_task_del_all_done (&core->tasks); + rz_core_task_del_all_done (&core->tasks); } else { - r_core_task_del (&core->tasks, r_num_math (core->num, input + 1)); + rz_core_task_del (&core->tasks, rz_num_math (core->num, input + 1)); } break; case '?': // "&?" @@ -2017,16 +2017,16 @@ static int cmd_tasks(void *data, const char *input) { case ' ': // "& " case '_': // "&_" case 't': { // "&t" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } - RCoreTask *task = r_core_task_new (core, true, input + 1, NULL, core); + RzCoreTask *task = rz_core_task_new (core, true, input + 1, NULL, core); if (!task) { break; } task->transient = input[0] == 't'; - r_core_task_enqueue (&core->tasks, task); + rz_core_task_enqueue (&core->tasks, task); break; } } @@ -2034,15 +2034,15 @@ static int cmd_tasks(void *data, const char *input) { } static int cmd_pointer(void *data, const char *input) { - RCore *core = (RCore*) data; + RzCore *core = (RzCore*) data; int ret = true; char *str, *eq; - input = r_str_trim_head_ro (input); + input = rz_str_trim_head_ro (input); while (*input == ' ') { input++; } if (!*input || *input == '?') { - r_core_cmd_help (core, help_msg_star); + rz_core_cmd_help (core, help_msg_star); return ret; } str = strdup (input); @@ -2050,26 +2050,26 @@ static int cmd_pointer(void *data, const char *input) { if (eq) { *eq++ = 0; if (!strncmp (eq, "0x", 2)) { - ret = r_core_cmdf (core, "wv %s@%s", eq, str); + ret = rz_core_cmdf (core, "wv %s@%s", eq, str); } else { - ret = r_core_cmdf (core, "wx %s@%s", eq, str); + ret = rz_core_cmdf (core, "wx %s@%s", eq, str); } } else { - ret = r_core_cmdf (core, "?v [%s]", input); + ret = rz_core_cmdf (core, "?v [%s]", input); } free (str); return ret; } static int cmd_env(void *data, const char *input) { - RCore *core = (RCore*)data; + RzCore *core = (RzCore*)data; int ret = true; switch (*input) { case '?': cmd_help_percent (core); break; default: - ret = r_core_cmdf (core, "env %s", input); + ret = rz_core_cmdf (core, "env %s", input); } return ret; } @@ -2096,14 +2096,14 @@ static struct autocomplete_flag_map_t { { NULL, NULL, 0 } }; -static inline void print_dict(RCoreAutocomplete* a, int sub) { +static inline void print_dict(RzCoreAutocomplete* a, int sub) { if (!a) { return; } int i, j; const char* name = "unknown"; for (i = 0; i < a->n_subcmds; i++) { - RCoreAutocomplete* b = a->subcmds[i]; + RzCoreAutocomplete* b = a->subcmds[i]; if (b->locked) { continue; } @@ -2129,21 +2129,21 @@ static int autocomplete_type(const char* strflag) { return R_CORE_AUTOCMPLT_END; } -static void cmd_autocomplete(RCore *core, const char *input) { - RCoreAutocomplete* b = core->autocomplete; - input = r_str_trim_head_ro (input); +static void cmd_autocomplete(RzCore *core, const char *input) { + RzCoreAutocomplete* b = core->autocomplete; + input = rz_str_trim_head_ro (input); char arg[256]; if (!*input) { print_dict (core->autocomplete, 0); return; } if (*input == '?') { - r_core_cmd_help (core, help_msg_triple_exclamation); + rz_core_cmd_help (core, help_msg_triple_exclamation); int i; - r_cons_printf ("|Types:\n"); + rz_cons_printf ("|Types:\n"); for (i = 0; i < R_CORE_AUTOCMPLT_END; i++) { if (autocomplete_flags[i].desc) { - r_cons_printf ("| %s %s\n", + rz_cons_printf ("| %s %s\n", autocomplete_flags[i].name, autocomplete_flags[i].desc); } @@ -2156,11 +2156,11 @@ static void cmd_autocomplete(RCore *core, const char *input) { eprintf ("Use !!!-* or !!!-\n"); return; } - r_core_autocomplete_remove (b, arg); + rz_core_autocomplete_remove (b, arg); return; } while (b) { - const char* end = r_str_trim_head_wp (input); + const char* end = rz_str_trim_head_wp (input); if (!end) { break; } @@ -2174,10 +2174,10 @@ static void cmd_autocomplete(RCore *core, const char *input) { } memcpy (arg, input, end - input); arg[end - input] = 0; - RCoreAutocomplete* a = r_core_autocomplete_find (b, arg, true); - input = r_str_trim_head_ro (end); + RzCoreAutocomplete* a = rz_core_autocomplete_find (b, arg, true); + input = rz_str_trim_head_ro (end); if (input && *input && !a) { - if (b->type == R_CORE_AUTOCMPLT_DFLT && !(b = r_core_autocomplete_add (b, arg, R_CORE_AUTOCMPLT_DFLT, false))) { + if (b->type == R_CORE_AUTOCMPLT_DFLT && !(b = rz_core_autocomplete_add (b, arg, R_CORE_AUTOCMPLT_DFLT, false))) { eprintf ("ENOMEM\n"); return; } else if (b->type != R_CORE_AUTOCMPLT_DFLT) { @@ -2196,7 +2196,7 @@ static void cmd_autocomplete(RCore *core, const char *input) { eprintf ("Changing type of '%s' is forbidden.\n", b->cmd); } } else { - if (!r_core_autocomplete_add (b, arg, R_CORE_AUTOCMPLT_DFLT, false)) { + if (!rz_core_autocomplete_add (b, arg, R_CORE_AUTOCMPLT_DFLT, false)) { eprintf ("ENOMEM\n"); return; } @@ -2215,7 +2215,7 @@ static void cmd_autocomplete(RCore *core, const char *input) { static int cmd_last(void *data, const char *input) { switch (*input) { case 0: - r_cons_last (); + rz_cons_last (); break; default: eprintf ("Usage: _ print last output\n"); @@ -2224,23 +2224,23 @@ static int cmd_last(void *data, const char *input) { } static int cmd_system(void *data, const char *input) { - RCore *core = (RCore*)data; + RzCore *core = (RzCore*)data; ut64 n; int ret = 0; switch (*input) { case '-': //!- if (input[1]) { - r_line_hist_free(); - r_line_hist_save (R2_HOME_HISTORY); + rz_line_hist_free(); + rz_line_hist_save (R2_HOME_HISTORY); } else { - r_line_hist_free(); + rz_line_hist_free(); } break; case '=': //!= if (input[1] == '?') { - r_cons_printf ("Usage: !=[!] - enable/disable remote commands\n"); + rz_cons_printf ("Usage: !=[!] - enable/disable remote commands\n"); } else { - if (!r_sandbox_enable (0)) { + if (!rz_sandbox_enable (0)) { R_FREE (core->cmdremote); } } @@ -2251,35 +2251,35 @@ static int cmd_system(void *data, const char *input) { } else if (input[1] == '?') { cmd_help_exclamation (core); } else if (input[1] == '*') { - char *cmd = r_str_trim_dup (input + 1); - (void)r_core_cmdf (core, "\"#!pipe %s\"", cmd); + char *cmd = rz_str_trim_dup (input + 1); + (void)rz_core_cmdf (core, "\"#!pipe %s\"", cmd); free (cmd); } else { - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } if (input[1]) { int olen; char *out = NULL; - char *cmd = r_core_sysenv_begin (core, input); + char *cmd = rz_core_sysenv_begin (core, input); if (cmd) { - void *bed = r_cons_sleep_begin (); - ret = r_sys_cmd_str_full (cmd + 1, NULL, &out, &olen, NULL); - r_cons_sleep_end (bed); - r_core_sysenv_end (core, input); - r_cons_memcat (out, olen); + void *bed = rz_cons_sleep_begin (); + ret = rz_sys_cmd_str_full (cmd + 1, NULL, &out, &olen, NULL); + rz_cons_sleep_end (bed); + rz_core_sysenv_end (core, input); + rz_cons_memcat (out, olen); free (out); free (cmd); } //else eprintf ("Error setting up system environment\n"); } else { eprintf ("History saved to "R2_HOME_HISTORY"\n"); - r_line_hist_save (R2_HOME_HISTORY); + rz_line_hist_save (R2_HOME_HISTORY); } } break; case '\0': - r_line_hist_list (); + rz_line_hist_list (); break; case '?': //!? cmd_help_exclamation (core); @@ -2287,29 +2287,29 @@ static int cmd_system(void *data, const char *input) { case '*': // TODO: use the api { - char *cmd = r_str_trim_dup (input + 1); - cmd = r_str_replace (cmd, " ", "\\ ", true); - cmd = r_str_replace (cmd, "\\ ", " ", false); - cmd = r_str_replace (cmd, "\"", "'", false); - ret = r_core_cmdf (core, "\"#!pipe %s\"", cmd); + char *cmd = rz_str_trim_dup (input + 1); + cmd = rz_str_replace (cmd, " ", "\\ ", true); + cmd = rz_str_replace (cmd, "\\ ", " ", false); + cmd = rz_str_replace (cmd, "\"", "'", false); + ret = rz_core_cmdf (core, "\"#!pipe %s\"", cmd); free (cmd); } break; default: n = atoi (input); if (*input == '0' || n > 0) { - const char *cmd = r_line_hist_get (n); + const char *cmd = rz_line_hist_get (n); if (cmd) { - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } //else eprintf ("Error setting up system environment\n"); } else { - char *cmd = r_core_sysenv_begin (core, input); + char *cmd = rz_core_sysenv_begin (core, input); if (cmd) { - void *bed = r_cons_sleep_begin (); - ret = r_sys_cmd (cmd); - r_cons_sleep_end (bed); - r_core_sysenv_end (core, input); + void *bed = rz_cons_sleep_begin (); + ret = rz_sys_cmd (cmd); + rz_cons_sleep_end (bed); + rz_core_sysenv_end (core, input); free (cmd); } else { eprintf ("Error setting up system environment\n"); @@ -2343,7 +2343,7 @@ static char *unescape_special_chars(const char *s, const char *special_chars) { close (fd_out); \ fd_out = -1; -static void r_w32_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { +static void rz_w32_cmd_pipe(RzCore *core, char *radare_cmd, char *shell_cmd) { STARTUPINFO si = {0}; PROCESS_INFORMATION pi = {0}; SECURITY_ATTRIBUTES sa; @@ -2359,11 +2359,11 @@ static void r_w32_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; if (!CreatePipe (&pipe[0], &pipe[1], &sa, 0)) { - r_sys_perror ("r_w32_cmd_pipe/CreatePipe"); + rz_sys_perror ("rz_w32_cmd_pipe/CreatePipe"); goto err_r_w32_cmd_pipe; } if (!SetHandleInformation (pipe[1], HANDLE_FLAG_INHERIT, 0)) { - r_sys_perror ("r_w32_cmd_pipe/SetHandleInformation"); + rz_sys_perror ("rz_w32_cmd_pipe/SetHandleInformation"); goto err_r_w32_cmd_pipe; } si.hStdError = GetStdHandle (STD_ERROR_HANDLE); @@ -2375,12 +2375,12 @@ static void r_w32_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { while (*_shell_cmd && isspace ((ut8)*_shell_cmd)) { _shell_cmd++; } - char *tmp = r_str_newf ("/Q /c \"%s\"", _shell_cmd); + char *tmp = rz_str_newf ("/Q /c \"%s\"", _shell_cmd); if (!tmp) { goto err_r_w32_cmd_pipe; } _shell_cmd = tmp; - _shell_cmd_ = r_sys_conv_utf8_to_win (_shell_cmd); + _shell_cmd_ = rz_sys_conv_utf8_to_win (_shell_cmd); free (tmp); if (!_shell_cmd_) { goto err_r_w32_cmd_pipe; @@ -2391,13 +2391,13 @@ static void r_w32_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { } int ret = GetSystemDirectory (systemdir, MAX_PATH); if (!ret) { - r_sys_perror ("r_w32_cmd_pipe/systemdir"); + rz_sys_perror ("rz_w32_cmd_pipe/systemdir"); goto err_r_w32_cmd_pipe; } _tcscat_s (systemdir, MAX_PATH, TEXT("\\cmd.exe")); // exec windows process if (!CreateProcess (systemdir, _shell_cmd_, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) { - r_sys_perror ("r_w32_cmd_pipe/CreateProcess"); + rz_sys_perror ("rz_w32_cmd_pipe/CreateProcess"); goto err_r_w32_cmd_pipe; } fd_out = _open_osfhandle ((intptr_t)pipe[1], _O_WRONLY|_O_TEXT); @@ -2408,9 +2408,9 @@ static void r_w32_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { cons_out = dup (1); dup2 (fd_out, 1); // exec radare command - r_core_cmd (core, radare_cmd, 0); + rz_core_cmd (core, radare_cmd, 0); - HANDLE th = CreateThread (NULL, 0,(LPTHREAD_START_ROUTINE) r_cons_flush, NULL, 0, NULL); + HANDLE th = CreateThread (NULL, 0,(LPTHREAD_START_ROUTINE) rz_cons_flush, NULL, 0, NULL); if (!th) { __CLOSE_DUPPED_PIPES (); goto err_r_w32_cmd_pipe; @@ -2460,7 +2460,7 @@ err_r_w32_cmd_pipe: #undef __CLOSE_DUPPED_PIPES #endif -R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { +RZ_API int rz_core_cmd_pipe(RzCore *core, char *radare_cmd, char *shell_cmd) { #if __UNIX__ int stdout_fd, fds[2]; int child; @@ -2468,37 +2468,37 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { int si, olen, ret = -1, pipecolor = -1; char *str, *out = NULL; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("Pipes are not allowed in sandbox mode\n"); return -1; } - si = r_cons_is_interactive (); - r_config_set_i (core->config, "scr.interactive", 0); - if (!r_config_get_i (core->config, "scr.color.pipe")) { - pipecolor = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + si = rz_cons_is_interactive (); + rz_config_set_i (core->config, "scr.interactive", 0); + if (!rz_config_get_i (core->config, "scr.color.pipe")) { + pipecolor = rz_config_get_i (core->config, "scr.color"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); } if (*shell_cmd=='!') { - r_cons_grep_parsecmd (shell_cmd, "\""); + rz_cons_grep_parsecmd (shell_cmd, "\""); olen = 0; out = NULL; // TODO: implement foo - str = r_core_cmd_str (core, radare_cmd); - r_sys_cmd_str_full (shell_cmd + 1, str, &out, &olen, NULL); + str = rz_core_cmd_str (core, radare_cmd); + rz_sys_cmd_str_full (shell_cmd + 1, str, &out, &olen, NULL); free (str); - r_cons_memcat (out, olen); + rz_cons_memcat (out, olen); free (out); ret = 0; } #if __UNIX__ - r_str_trim_head (radare_cmd); - r_str_trim_head (shell_cmd); + rz_str_trim_head (radare_cmd); + rz_str_trim_head (shell_cmd); - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); stdout_fd = dup (1); if (stdout_fd != -1) { if (pipe (fds) == 0) { - child = r_sys_fork (); + child = rz_sys_fork (); if (child == -1) { eprintf ("Cannot fork\n"); close (stdout_fd); @@ -2506,8 +2506,8 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { dup2 (fds[1], 1); close (fds[1]); close (fds[0]); - r_core_cmd (core, radare_cmd, 0); - r_cons_flush (); + rz_core_cmd (core, radare_cmd, 0); + rz_cons_flush (); close (1); wait (&ret); dup2 (stdout_fd, 1); @@ -2516,33 +2516,33 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) { close (fds[1]); dup2 (fds[0], 0); //dup2 (1, 2); // stderr goes to stdout - r_sandbox_system (shell_cmd, 0); + rz_sandbox_system (shell_cmd, 0); close (stdout_fd); } } else { - eprintf ("r_core_cmd_pipe: Could not pipe\n"); + eprintf ("rz_core_cmd_pipe: Could not pipe\n"); } } #elif __WINDOWS__ - r_w32_cmd_pipe (core, radare_cmd, shell_cmd); + rz_w32_cmd_pipe (core, radare_cmd, shell_cmd); #else #ifdef _MSC_VER -#pragma message ("r_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM") +#pragma message ("rz_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM") #else -#warning r_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM +#warning rz_core_cmd_pipe UNIMPLEMENTED FOR THIS PLATFORM #endif - eprintf ("r_core_cmd_pipe: unimplemented for this platform\n"); + eprintf ("rz_core_cmd_pipe: unimplemented for this platform\n"); #endif if (pipecolor != -1) { - r_config_set_i (core->config, "scr.color", pipecolor); + rz_config_set_i (core->config, "scr.color", pipecolor); } - r_config_set_i (core->config, "scr.interactive", si); + rz_config_set_i (core->config, "scr.interactive", si); return ret; } -static char *parse_tmp_evals(RCore *core, const char *str) { +static char *parse_tmp_evals(RzCore *core, const char *str) { char *s = strdup (str); - int i, argc = r_str_split (s, ','); + int i, argc = rz_str_split (s, ','); char *res = strdup (""); if (!s || !res) { free (s); @@ -2550,26 +2550,26 @@ static char *parse_tmp_evals(RCore *core, const char *str) { return NULL; } for (i = 0; i < argc; i++) { - char *eq, *kv = (char *)r_str_word_get0 (s, i); + char *eq, *kv = (char *)rz_str_word_get0 (s, i); if (!kv) { break; } eq = strchr (kv, '='); if (eq) { *eq = 0; - const char *ov = r_config_get (core->config, kv); + const char *ov = rz_config_get (core->config, kv); if (!ov) { continue; } - char *cmd = r_str_newf ("e %s=%s;", kv, ov); + char *cmd = rz_str_newf ("e %s=%s;", kv, ov); if (!cmd) { free (s); free (res); return NULL; } - res = r_str_prepend (res, cmd); + res = rz_str_prepend (res, cmd); free (cmd); - r_config_set (core->config, kv, eq + 1); + rz_config_set (core->config, kv, eq + 1); *eq = '='; } else { eprintf ("Missing '=' in e: expression (%s)\n", kv); @@ -2580,7 +2580,7 @@ static char *parse_tmp_evals(RCore *core, const char *str) { } static bool is_macro_command(const char *ptr) { - ptr = r_str_trim_head_ro (ptr); + ptr = rz_str_trim_head_ro (ptr); while (IS_DIGIT (*ptr)) { ptr++; } @@ -2603,14 +2603,14 @@ static char *find_ch_after_macro(char *ptr, char ch) { return NULL; } -static int r_core_cmd_subst(RCore *core, char *cmd) { +static int rz_core_cmd_subst(RzCore *core, char *cmd) { ut64 rep = strtoull (cmd, NULL, 10); int ret = 0, orep; char *colon = NULL, *icmd = NULL; bool tmpseek = false; bool original_tmpseek = core->tmpseek; - if (r_str_startswith (cmd, "GET /cmd/")) { + if (rz_str_startswith (cmd, "GET /cmd/")) { memmove (cmd, cmd + 9, strlen (cmd + 9) + 1); char *http = strstr (cmd, "HTTP"); if (http) { @@ -2620,10 +2620,10 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { *http = 0; } } - r_cons_printf ("HTTP/1.0 %d %s\r\n%s" + rz_cons_printf ("HTTP/1.0 %d %s\r\n%s" "Connection: close\r\nContent-Length: %d\r\n\r\n", 200, "OK", "", -1); - return r_core_cmd0 (core, cmd); + return rz_core_cmd0 (core, cmd); } /* must store a local orig_offset because there can be @@ -2637,13 +2637,13 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { if (core->max_cmd_depth - core->cons->context->cmd_depth == 1) { core->prompt_offset = core->offset; } - cmd = (char *)r_str_trim_head_ro (icmd); - r_str_trim_tail (cmd); + cmd = (char *)rz_str_trim_head_ro (icmd); + rz_str_trim_tail (cmd); // lines starting with # are ignored (never reach cmd_hash()), except #! and #? if (!*cmd) { if (core->cmdrepeat > 0) { lastcmd_repeat (core, true); - ret = r_core_cmd_nullcallback (core); + ret = rz_core_cmd_nullcallback (core); } goto beach; } @@ -2665,7 +2665,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { } if (hash && *hash) { *hash = 0; - r_str_trim_tail (icmd); + rz_str_trim_tail (icmd); } } if (*cmd != '"') { @@ -2695,13 +2695,13 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { rep = 1; } // XXX if output is a pipe then we don't want to be interactive - if (rep > 1 && r_sandbox_enable (0)) { + if (rep > 1 && rz_sandbox_enable (0)) { eprintf ("Command repeat sugar disabled in sandbox mode (%s)\n", cmd); goto beach; } else { if (rep > INTERACTIVE_MAX_REP) { - if (r_cons_is_interactive ()) { - if (!r_cons_yesno ('n', "Are you sure to repeat this %"PFMT64d" times? (y/N)", rep)) { + if (rz_cons_is_interactive ()) { + if (!rz_cons_yesno ('n', "Are you sure to repeat this %"PFMT64d" times? (y/N)", rep)) { goto beach; } } @@ -2711,7 +2711,7 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { const char *cmdrep = core->cmdtimes ? core->cmdtimes: ""; orep = rep; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); int ocur_enabled = core->print && core->print->cur_enabled; while (rep-- && *cmd) { @@ -2723,12 +2723,12 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { } } } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } char *cr = strdup (cmdrep); core->break_loop = false; - ret = r_core_cmd_subst_i (core, cmd, colon, (rep == orep - 1) ? &tmpseek : NULL); + ret = rz_core_cmd_subst_i (core, cmd, colon, (rep == orep - 1) ? &tmpseek : NULL); if (ret && *cmd == 'q') { free (cr); goto beach; @@ -2738,19 +2738,19 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { break; } if (cr && *cr && orep > 1) { - // XXX: do not flush here, we need r_cons_push () and r_cons_pop() - r_cons_flush (); + // XXX: do not flush here, we need rz_cons_push () and rz_cons_pop() + rz_cons_flush (); // XXX: we must import register flags in C - (void)r_core_cmd0 (core, ".dr*"); - (void)r_core_cmd0 (core, cr); + (void)rz_core_cmd0 (core, ".dr*"); + (void)rz_core_cmd0 (core, cr); } free (cr); } - r_cons_break_pop (); + rz_cons_break_pop (); if (tmpseek) { - r_core_seek (core, orig_offset, true); + rz_core_seek (core, orig_offset, true); core->tmpseek = original_tmpseek; } if (core->print) { @@ -2760,10 +2760,10 @@ static int r_core_cmd_subst(RCore *core, char *cmd) { for (++colon; *colon == ';'; colon++) { ; } - r_core_cmd_subst (core, colon); + rz_core_cmd_subst (core, colon); } else { if (!*icmd) { - r_core_cmd_nullcallback (core); + rz_core_cmd_nullcallback (core); } } beach: @@ -2792,37 +2792,37 @@ static char* findSeparator(char *p) { } static void tmpenvs_free(void *item) { - r_sys_setenv (item, NULL); + rz_sys_setenv (item, NULL); free (item); } -static bool set_tmp_arch(RCore *core, char *arch, char **tmparch) { - r_return_val_if_fail (tmparch, false); - *tmparch = strdup (r_config_get (core->config, "asm.arch")); - r_config_set (core->config, "asm.arch", arch); +static bool set_tmp_arch(RzCore *core, char *arch, char **tmparch) { + rz_return_val_if_fail (tmparch, false); + *tmparch = strdup (rz_config_get (core->config, "asm.arch")); + rz_config_set (core->config, "asm.arch", arch); core->fixedarch = true; return true; } -static bool set_tmp_bits(RCore *core, int bits, char **tmpbits, int *cmd_ignbithints) { - r_return_val_if_fail (tmpbits, false); - *tmpbits = strdup (r_config_get (core->config, "asm.bits")); - r_config_set_i (core->config, "asm.bits", bits); +static bool set_tmp_bits(RzCore *core, int bits, char **tmpbits, int *cmd_ignbithints) { + rz_return_val_if_fail (tmpbits, false); + *tmpbits = strdup (rz_config_get (core->config, "asm.bits")); + rz_config_set_i (core->config, "asm.bits", bits); core->fixedbits = true; // XXX: why? - *cmd_ignbithints = r_config_get_i (core->config, "anal.ignbithints"); - r_config_set_i (core->config, "anal.ignbithints", 1); + *cmd_ignbithints = rz_config_get_i (core->config, "anal.ignbithints"); + rz_config_set_i (core->config, "anal.ignbithints", 1); return true; } -static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek) { - RList *tmpenvs = r_list_newf (tmpenvs_free); +static int rz_core_cmd_subst_i(RzCore *core, char *cmd, char *colon, bool *tmpseek) { + RzList *tmpenvs = rz_list_newf (tmpenvs_free); const char *quotestr = "`"; const char *tick = NULL; char *ptr, *ptr2, *str; char *arroba = NULL; char *grep = NULL; - RIODesc *tmpdesc = NULL; + RzIODesc *tmpdesc = NULL; int pamode = !core->io->va; int i, ret = 0, pipefd; bool usemyblock = false; @@ -2837,10 +2837,10 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek int cmd_ignbithints = -1; if (!cmd) { - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return 0; } - r_str_trim (cmd); + rz_str_trim (cmd); char *$0 = strstr (cmd, "$("); if ($0) { @@ -2858,8 +2858,8 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek switch (*cmd) { case '.': if (cmd[1] == '"') { /* interpret */ - r_list_free (tmpenvs); - return r_cmd_call (core->rcmd, cmd); + rz_list_free (tmpenvs); + return rz_cmd_call (core->rcmd, cmd); } break; case '"': @@ -2873,7 +2873,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek p = *cmd ? find_eoq (cmd) : NULL; if (!p || !*p) { eprintf ("Missing \" in (%s).", cmd); - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return false; } *p++ = 0; @@ -2885,7 +2885,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek if (sc) { *sc = 0; } - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); if (!sc) { break; } @@ -2909,7 +2909,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek } haveQuote = q != NULL; oseek = core->offset; - r_core_seek (core, r_num_math(core->num, p + 2), true); + rz_core_seek (core, rz_num_math(core->num, p + 2), true); if (q) { *p = '"'; p = q; @@ -2922,27 +2922,27 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek while (*str == '>') { str++; } - str = (char *)r_str_trim_head_ro (str); - r_cons_flush (); + str = (char *)rz_str_trim_head_ro (str); + rz_cons_flush (); const bool append = p[2] == '>'; - pipefd = r_cons_pipe_open (str, 1, append); + pipefd = rz_cons_pipe_open (str, 1, append); } } line = strdup (cmd); - line = r_str_replace (line, "\\\"", "\"", true); + line = rz_str_replace (line, "\\\"", "\"", true); if (p && *p && p[1] == '|') { - str = (char *)r_str_trim_head_ro (p + 2); - r_core_cmd_pipe (core, cmd, str); + str = (char *)rz_str_trim_head_ro (p + 2); + rz_core_cmd_pipe (core, cmd, str); } else { - r_cmd_call (core->rcmd, line); + rz_cmd_call (core->rcmd, line); } free (line); if (oseek != UT64_MAX) { - r_core_seek (core, oseek, true); + rz_core_seek (core, oseek, true); } if (pipefd != -1) { - r_cons_flush (); - r_cons_pipe_close (pipefd); + rz_cons_flush (); + rz_cons_pipe_close (pipefd); } if (!p) { break; @@ -2965,18 +2965,18 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek cmd = p + 1; } } - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return true; case '(': if (cmd[1] != '*' && !strstr (cmd, ")()")) { - r_list_free (tmpenvs); - return r_cmd_call (core->rcmd, cmd); + rz_list_free (tmpenvs); + return rz_cmd_call (core->rcmd, cmd); } break; case '?': if (cmd[1] == '>') { - r_core_cmd_help (core, help_msg_greater_sign); - r_list_free (tmpenvs); + rz_core_cmd_help (core, help_msg_greater_sign); + rz_list_free (tmpenvs); return true; } } @@ -2984,7 +2984,7 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek // TODO must honor ` /* comments */ if (*cmd != '#') { - ptr = (char *)r_str_firstbut (cmd, '#', "`\""); // TODO: use quotestr here + ptr = (char *)rz_str_firstbut (cmd, '#', "`\""); // TODO: use quotestr here if (ptr && (ptr[1] == ' ' || ptr[1] == '\t')) { *ptr = '\0'; } @@ -2997,28 +2997,28 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek if (is_macro_command (cmd)) { ptr = find_ch_after_macro (cmd, ';'); } else { - ptr = (char *)r_str_lastbut (cmd, ';', quotestr); + ptr = (char *)rz_str_lastbut (cmd, ';', quotestr); } if (colon && ptr) { int ret ; *ptr = '\0'; - if (r_core_cmd_subst (core, cmd) == -1) { - r_list_free (tmpenvs); + if (rz_core_cmd_subst (core, cmd) == -1) { + rz_list_free (tmpenvs); return -1; } cmd = ptr + 1; - ret = r_core_cmd_subst (core, cmd); + ret = rz_core_cmd_subst (core, cmd); *ptr = ';'; - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return ret; - //r_cons_flush (); + //rz_cons_flush (); } } // TODO must honor " and ` /* pipe console to shell process */ //ptr = strchr (cmd, '|'); - ptr = (char *)r_str_lastbut (cmd, '|', quotestr); + ptr = (char *)rz_str_lastbut (cmd, '|', quotestr); if (ptr) { if (ptr > cmd) { char *ch = ptr - 1; @@ -3031,41 +3031,41 @@ static int r_core_cmd_subst_i(RCore *core, char *cmd, char *colon, bool *tmpseek if (!ptr2 || (ptr2 && ptr2 > ptr)) { if (!tick || (tick && tick > ptr)) { *ptr = '\0'; - cmd = r_str_trim_nc (cmd); + cmd = rz_str_trim_nc (cmd); if (!strcmp (ptr + 1, "?")) { // "|?" - r_core_cmd_help (core, help_msg_vertical_bar); - r_list_free (tmpenvs); + rz_core_cmd_help (core, help_msg_vertical_bar); + rz_list_free (tmpenvs); return ret; } else if (!strncmp (ptr + 1, "H", 1)) { // "|H" - scr_html = r_config_get_i (core->config, "scr.html"); - r_config_set_i (core->config, "scr.html", true); + scr_html = rz_config_get_i (core->config, "scr.html"); + rz_config_set_i (core->config, "scr.html", true); } else if (!strcmp (ptr + 1, "T")) { // "|T" - scr_color = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + scr_color = rz_config_get_i (core->config, "scr.color"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); core->cons->use_tts = true; } else if (!strcmp (ptr + 1, ".")) { // "|." - ret = *cmd ? r_core_cmdf (core, ".%s", cmd) : 0; - r_list_free (tmpenvs); + ret = *cmd ? rz_core_cmdf (core, ".%s", cmd) : 0; + rz_list_free (tmpenvs); return ret; } else if (ptr[1]) { // "| grep .." int value = core->num->value; if (*cmd) { - r_core_cmd_pipe (core, cmd, ptr + 1); + rz_core_cmd_pipe (core, cmd, ptr + 1); } else { - char *res = r_io_system (core->io, ptr + 1); + char *res = rz_io_system (core->io, ptr + 1); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } } core->num->value = value; - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return 0; } else { // "|" - scr_html = r_config_get_i (core->config, "scr.html"); - r_config_set_i (core->config, "scr.html", 0); - scr_color = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + scr_html = rz_config_get_i (core->config, "scr.html"); + rz_config_set_i (core->config, "scr.html", 0); + scr_color = rz_config_get_i (core->config, "scr.color"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); } } } @@ -3074,20 +3074,20 @@ escape_pipe: // TODO must honor " and ` /* bool conditions */ - ptr = (char *)r_str_lastbut (cmd, '&', quotestr); + ptr = (char *)rz_str_lastbut (cmd, '&', quotestr); //ptr = strchr (cmd, '&'); while (ptr && *ptr && ptr[1] == '&') { *ptr = '\0'; - ret = r_cmd_call (core->rcmd, cmd); + ret = rz_cmd_call (core->rcmd, cmd); if (ret == -1) { eprintf ("command error(%s)\n", cmd); if (scr_html != -1) { - r_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "scr.html", scr_html); } if (scr_color != -1) { - r_config_set_i (core->config, "scr.color", scr_color); + rz_config_set_i (core->config, "scr.color", scr_color); } - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return ret; } for (cmd = ptr + 2; cmd && *cmd == ' '; cmd++) { @@ -3107,23 +3107,23 @@ escape_pipe: detail++; } } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); recursive_help (core, detail, cmd); - r_cons_break_pop (); - r_cons_grep_parsecmd (ptr + 2, "`"); + rz_cons_break_pop (); + rz_cons_grep_parsecmd (ptr + 2, "`"); if (scr_html != -1) { - r_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "scr.html", scr_html); } if (scr_color != -1) { - r_config_set_i (core->config, "scr.color", scr_color); + rz_config_set_i (core->config, "scr.color", scr_color); } - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return 0; } } /* pipe console to file */ - ptr = (char *)r_str_firstbut (cmd, '>', "\""); + ptr = (char *)rz_str_firstbut (cmd, '>', "\""); // TODO honor ` if (ptr) { if (ptr > cmd) { @@ -3134,29 +3134,29 @@ escape_pipe: } } if (ptr[0] && ptr[1] == '?') { - r_core_cmd_help (core, help_msg_greater_sign); - r_list_free (tmpenvs); + rz_core_cmd_help (core, help_msg_greater_sign); + rz_list_free (tmpenvs); return true; } int fdn = 1; - int pipecolor = r_config_get_i (core->config, "scr.color.pipe"); + int pipecolor = rz_config_get_i (core->config, "scr.color.pipe"); int use_editor = false; - int ocolor = r_config_get_i (core->config, "scr.color"); + int ocolor = rz_config_get_i (core->config, "scr.color"); *ptr = '\0'; str = ptr + 1 + (ptr[1] == '>'); - r_str_trim (str); + rz_str_trim (str); if (!*str) { eprintf ("No output?\n"); goto next2; } - /* r_cons_flush() handles interactive output (to the terminal) + /* rz_cons_flush() handles interactive output (to the terminal) * differently (e.g. asking about too long output). This conflicts * with piping to a file. Disable it while piping. */ if (ptr > (cmd + 1) && IS_WHITECHAR (ptr[-2])) { char *fdnum = ptr - 1; if (*fdnum == 'H') { // "H>" - scr_html = r_config_get_i (core->config, "scr.html"); - r_config_set_i (core->config, "scr.html", true); + scr_html = rz_config_get_i (core->config, "scr.html"); + rz_config_set_i (core->config, "scr.html", true); pipecolor = true; *fdnum = 0; } else { @@ -3166,72 +3166,72 @@ escape_pipe: *fdnum = 0; } } - r_cons_set_interactive (false); + rz_cons_set_interactive (false); if (!strcmp (str, "-")) { use_editor = true; - str = r_file_temp ("dumpedit"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + str = rz_file_temp ("dumpedit"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); } const bool appendResult = (ptr[1] == '>'); if (*str == '$') { // pipe to alias variable // register output of command as an alias - char *o = r_core_cmd_str (core, cmd); + char *o = rz_core_cmd_str (core, cmd); if (appendResult) { - char *oldText = r_cmd_alias_get (core->rcmd, str, 1); + char *oldText = rz_cmd_alias_get (core->rcmd, str, 1); if (oldText) { - char *two = r_str_newf ("%s%s", oldText, o); + char *two = rz_str_newf ("%s%s", oldText, o); if (two) { - r_cmd_alias_set (core->rcmd, str, two, 1); + rz_cmd_alias_set (core->rcmd, str, two, 1); free (two); } } else { - char *n = r_str_newf ("$%s", o); - r_cmd_alias_set (core->rcmd, str, n, 1); + char *n = rz_str_newf ("$%s", o); + rz_cmd_alias_set (core->rcmd, str, n, 1); free (n); } } else { - char *n = r_str_newf ("$%s", o); - r_cmd_alias_set (core->rcmd, str, n, 1); + char *n = rz_str_newf ("$%s", o); + rz_cmd_alias_set (core->rcmd, str, n, 1); free (n); } ret = 0; free (o); } else if (fdn > 0) { // pipe to file (or append) - pipefd = r_cons_pipe_open (str, fdn, appendResult); + pipefd = rz_cons_pipe_open (str, fdn, appendResult); if (pipefd != -1) { if (!pipecolor) { - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); } - ret = r_core_cmd_subst (core, cmd); - r_cons_flush (); - r_cons_pipe_close (pipefd); + ret = rz_core_cmd_subst (core, cmd); + rz_cons_flush (); + rz_cons_pipe_close (pipefd); } } - r_cons_set_last_interactive (); + rz_cons_set_last_interactive (); if (!pipecolor) { - r_config_set_i (core->config, "scr.color", ocolor); + rz_config_set_i (core->config, "scr.color", ocolor); } if (use_editor) { - const char *editor = r_config_get (core->config, "cfg.editor"); + const char *editor = rz_config_get (core->config, "cfg.editor"); if (editor && *editor) { - r_sys_cmdf ("%s '%s'", editor, str); - r_file_rm (str); + rz_sys_cmdf ("%s '%s'", editor, str); + rz_file_rm (str); } else { eprintf ("No cfg.editor configured\n"); } - r_config_set_i (core->config, "scr.color", ocolor); + rz_config_set_i (core->config, "scr.color", ocolor); free (str); } if (scr_html != -1) { - r_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "scr.html", scr_html); } if (scr_color != -1) { - r_config_set_i (core->config, "scr.color", scr_color); + rz_config_set_i (core->config, "scr.color", scr_color); } core->cons->use_tts = false; - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return ret; } escape_redir: @@ -3264,22 +3264,22 @@ next2: *ptr = '\0'; *ptr2 = '\0'; if (ptr[1] == '!') { - str = r_core_cmd_str_pipe (core, ptr + 1); + str = rz_core_cmd_str_pipe (core, ptr + 1); } else { // Color disabled when doing backticks ?e `pi 1` - int ocolor = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", 0); + int ocolor = rz_config_get_i (core->config, "scr.color"); + rz_config_set_i (core->config, "scr.color", 0); core->cmd_in_backticks = true; - str = r_core_cmd_str (core, ptr + 1); + str = rz_core_cmd_str (core, ptr + 1); core->cmd_in_backticks = false; - r_config_set_i (core->config, "scr.color", ocolor); + rz_config_set_i (core->config, "scr.color", ocolor); } if (!str) { goto fail; } // ignore contents if first char is pipe or comment if (*str == '|' || *str == '*') { - eprintf ("r_core_cmd_subst_i: invalid backticked command\n"); + eprintf ("rz_core_cmd_subst_i: invalid backticked command\n"); free (str); goto fail; } @@ -3290,16 +3290,16 @@ next2: } } } - str = r_str_append (str, ptr2 + 1); - cmd = r_str_append (strdup (cmd), str); + str = rz_str_append (str, ptr2 + 1); + cmd = rz_str_append (strdup (cmd), str); core->num->value = value; - ret = r_core_cmd_subst (core, cmd); + ret = rz_core_cmd_subst (core, cmd); free (cmd); if (scr_html != -1) { - r_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "scr.html", scr_html); } free (str); - r_list_free (tmpenvs); + rz_list_free (tmpenvs); return ret; } } @@ -3321,14 +3321,14 @@ escape_backtick: } } if (showHelp) { - r_cons_grep_help (); - r_list_free (tmpenvs); + rz_cons_grep_help (); + rz_list_free (tmpenvs); return true; } } } if (*cmd != '.') { - grep = r_cons_grep_strip (cmd, quotestr); + grep = rz_cons_grep_strip (cmd, quotestr); } /* temporary seek commands */ @@ -3377,29 +3377,29 @@ repeat_arroba: ptr--; } - r_str_trim_tail (ptr); + rz_str_trim_tail (ptr); if (ptr[1] == '?') { - r_core_cmd_help (core, help_msg_at); + rz_core_cmd_help (core, help_msg_at); } else if (ptr[1] == '%') { // "@%" char *k = strdup (ptr + 2); char *v = strchr (k, '='); if (v) { *v++ = 0; - r_sys_setenv (k, v); - r_list_append (tmpenvs, k); + rz_sys_setenv (k, v); + rz_list_append (tmpenvs, k); } else { free (k); } } else if (ptr[1] == '.') { // "@." if (ptr[2] == '.') { // "@.." if (ptr[3] == '.') { // "@..." - ut64 addr = r_num_tail (core->num, core->offset, ptr + 4); - r_core_block_size (core, R_ABS ((st64)addr - (st64)core->offset)); + ut64 addr = rz_num_tail (core->num, core->offset, ptr + 4); + rz_core_block_size (core, R_ABS ((st64)addr - (st64)core->offset)); goto fuji; } else { - addr = r_num_tail (core->num, core->offset, ptr + 3); - r_core_seek (core, addr, true); + addr = rz_num_tail (core->num, core->offset, ptr + 3); + rz_core_seek (core, addr, true); cmd_tmpseek = core->tmpseek = true; goto fuji; } @@ -3410,12 +3410,12 @@ repeat_arroba: } else if (ptr[0] && ptr[1] == ':' && ptr[2]) { switch (ptr[0]) { case 'F': // "@F:" // temporary flag space - flgspc_changed = r_flag_space_push (core->flags, ptr + 2); + flgspc_changed = rz_flag_space_push (core->flags, ptr + 2); break; case 'B': // "@B:#" // seek to the last instruction in current bb { - int index = (int)r_num_math (core->num, ptr + 2); - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, core->offset); + int index = (int)rz_num_math (core->num, ptr + 2); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, core->offset); if (bb) { // handle negative indices if (index < 0) { @@ -3423,8 +3423,8 @@ repeat_arroba: } if (index >= 0 && index < bb->ninstr) { - ut16 inst_off = r_anal_bb_offset_inst (bb, index); - r_core_seek (core, bb->addr + inst_off, true); + ut16 inst_off = rz_anal_bb_offset_inst (bb, index); + rz_core_seek (core, bb->addr + inst_off, true); cmd_tmpseek = core->tmpseek = true; } else { eprintf ("The current basic block has %d instructions\n", bb->ninstr); @@ -3436,20 +3436,20 @@ repeat_arroba: } break; case 'f': // "@f:" // slurp file in block - f = r_file_slurp (ptr + 2, &sz); + f = rz_file_slurp (ptr + 2, &sz); if (f) { { - RBuffer *b = r_buf_new_with_bytes ((const ut8*)f, (ut64)sz); - RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0); + RBuffer *b = rz_buf_new_with_bytes ((const ut8*)f, (ut64)sz); + RzIODesc *d = rz_io_open_buffer (core->io, b, R_PERM_RWX, 0); if (d) { if (tmpdesc) { - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); } tmpdesc = d; if (pamode) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } - r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b)); + rz_io_map_new (core->io, d->fd, d->perm, 0, core->offset, rz_buf_size (b)); } } } else { @@ -3464,27 +3464,27 @@ repeat_arroba: if (sep) { char ch = *sep; *sep = 0; - regval = r_debug_reg_get (core->dbg, mander); + regval = rz_debug_reg_get (core->dbg, mander); *sep = ch; - char *numexpr = r_str_newf ("0x%"PFMT64x"%s", regval, sep); - regval = r_num_math (core->num, numexpr); + char *numexpr = rz_str_newf ("0x%"PFMT64x"%s", regval, sep); + regval = rz_num_math (core->num, numexpr); free (numexpr); } else { - regval = r_debug_reg_get (core->dbg, ptr + 2); + regval = rz_debug_reg_get (core->dbg, ptr + 2); } - r_core_seek (core, regval, true); + rz_core_seek (core, regval, true); cmd_tmpseek = core->tmpseek = true; free (mander); } break; case 'b': // "@b:" // bits - is_bits_set = set_tmp_bits (core, r_num_math (core->num, ptr + 2), &tmpbits, &cmd_ignbithints); + is_bits_set = set_tmp_bits (core, rz_num_math (core->num, ptr + 2), &tmpbits, &cmd_ignbithints); break; case 'i': // "@i:" { - ut64 addr = r_num_math (core->num, ptr + 2); + ut64 addr = rz_num_math (core->num, ptr + 2); if (addr) { - r_core_cmdf (core, "so %s", ptr + 2); + rz_core_cmdf (core, "so %s", ptr + 2); cmd_tmpseek = core->tmpseek = true; } } @@ -3495,7 +3495,7 @@ repeat_arroba: if (!tmpeval) { tmpeval = cmd; } else { - tmpeval = r_str_prepend (tmpeval, cmd); + tmpeval = rz_str_prepend (tmpeval, cmd); free (cmd); } } @@ -3503,30 +3503,30 @@ repeat_arroba: case 'v': // "@v:" // value (honors asm.bits and cfg.bigendian) if (ptr[1] == ':') { ut8 buf[8] = {0}; - ut64 v = r_num_math (core->num, ptr + 2); - int be = r_config_get_i (core->config, "cfg.bigendian"); - int bi = r_config_get_i (core->config, "asm.bits"); + ut64 v = rz_num_math (core->num, ptr + 2); + int be = rz_config_get_i (core->config, "cfg.bigendian"); + int bi = rz_config_get_i (core->config, "asm.bits"); if (bi == 64) { - r_write_ble64 (buf, v, be); + rz_write_ble64 (buf, v, be); len = 8; } else { - r_write_ble32 (buf, v, be); + rz_write_ble32 (buf, v, be); len = 4; } - r_core_block_size (core, R_ABS (len)); - RBuffer *b = r_buf_new_with_bytes (buf, len); - RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0); + rz_core_block_size (core, R_ABS (len)); + RBuffer *b = rz_buf_new_with_bytes (buf, len); + RzIODesc *d = rz_io_open_buffer (core->io, b, R_PERM_RWX, 0); if (d) { if (tmpdesc) { - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); } tmpdesc = d; if (pamode) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } - r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b)); - r_core_block_size (core, len); - r_core_block_read (core); + rz_io_map_new (core->io, d->fd, d->perm, 0, core->offset, rz_buf_size (b)); + rz_core_block_size (core, len); + rz_core_block_read (core); } } else { eprintf ("Invalid @v: syntax\n"); @@ -3536,22 +3536,22 @@ repeat_arroba: if (ptr[1] == ':') { buf = malloc (strlen (ptr + 2) + 1); if (buf) { - len = r_hex_str2bin (ptr + 2, buf); - r_core_block_size (core, R_ABS (len)); + len = rz_hex_str2bin (ptr + 2, buf); + rz_core_block_size (core, R_ABS (len)); if (len > 0) { - RBuffer *b = r_buf_new_with_bytes (buf, len); - RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0); + RBuffer *b = rz_buf_new_with_bytes (buf, len); + RzIODesc *d = rz_io_open_buffer (core->io, b, R_PERM_RWX, 0); if (d) { if (tmpdesc) { - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); } tmpdesc = d; if (pamode) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } - r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b)); - r_core_block_size (core, len); - r_core_block_read (core); + rz_io_map_new (core->io, d->fd, d->perm, 0, core->offset, rz_buf_size (b)); + rz_core_block_size (core, len); + rz_core_block_read (core); } } else { eprintf ("Error: Invalid hexpairs for @x:\n"); @@ -3568,7 +3568,7 @@ repeat_arroba: { char *out = sdb_querys (core->sdb, NULL, 0, ptr + ((ptr[1])? 2: 1)); if (out) { - r_core_seek (core, r_num_math(core->num, out), true); + rz_core_seek (core, rz_num_math(core->num, out), true); free (out); usemyblock = true; } @@ -3577,7 +3577,7 @@ repeat_arroba: case 'o': // "@o:3" if (ptr[1] == ':') { tmpfd = core->io->desc ? core->io->desc->fd : -1; - r_io_use_fd (core->io, atoi (ptr + 2)); + rz_io_use_fd (core->io, atoi (ptr + 2)); } break; case 'a': // "@a:" @@ -3585,7 +3585,7 @@ repeat_arroba: char *q = strchr (ptr + 2, ':'); if (q) { *q++ = 0; - int bits = r_num_math (core->num, q); + int bits = rz_num_math (core->num, q); is_bits_set = set_tmp_bits (core, bits, &tmpbits, &cmd_ignbithints); } is_arch_set = set_tmp_arch (core, ptr + 2, &tmpasm); @@ -3596,26 +3596,26 @@ repeat_arroba: case 's': // "@s:" // wtf syntax { len = strlen (ptr + 2); - r_core_block_size (core, len); - const ut8 *buf = (const ut8*)r_str_trim_head_ro (ptr + 2); + rz_core_block_size (core, len); + const ut8 *buf = (const ut8*)rz_str_trim_head_ro (ptr + 2); if (len > 0) { - RBuffer *b = r_buf_new_with_bytes (buf, len); - RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0); + RBuffer *b = rz_buf_new_with_bytes (buf, len); + RzIODesc *d = rz_io_open_buffer (core->io, b, R_PERM_RWX, 0); if (!core->io->va) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } if (d) { if (tmpdesc) { - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); } tmpdesc = d; if (pamode) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } - r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b)); - r_core_block_size (core, len); - // r_core_block_read (core); + rz_io_map_new (core->io, d->fd, d->perm, 0, core->offset, rz_buf_size (b)); + rz_core_block_size (core, len); + // rz_core_block_read (core); } } } @@ -3637,8 +3637,8 @@ break; goto next_arroba; } ignore: - r_str_trim_head (ptr + 1); - cmd = r_str_trim_nc (cmd); + rz_str_trim_head (ptr + 1); + cmd = rz_str_trim_nc (cmd); if (ptr2) { if (strlen (ptr + 1) == 13 && strlen (ptr2 + 1) == 6 && !memcmp (ptr + 1, "0x", 2) && @@ -3651,19 +3651,19 @@ ignore: if (!ptr2[1]) { goto fail; } - r_core_block_size ( - core, r_num_math (core->num, ptr2 + 1)); + rz_core_block_size ( + core, rz_num_math (core->num, ptr2 + 1)); } } - r_str_trim_head (ptr + 1); + rz_str_trim_head (ptr + 1); offstr = ptr + 1; - addr = (*offstr == '{')? core->offset: r_num_math (core->num, offstr); + addr = (*offstr == '{')? core->offset: rz_num_math (core->num, offstr); addr_is_set = true; if (isalpha ((ut8)ptr[1]) && !addr) { - if (!r_flag_get (core->flags, ptr + 1)) { + if (!rz_flag_get (core->flags, ptr + 1)) { eprintf ("Invalid address (%s)\n", ptr + 1); goto fail; } @@ -3675,9 +3675,9 @@ ignore: } // remap thhe tmpdesc if any if (addr) { - RIODesc *d = tmpdesc; + RzIODesc *d = tmpdesc; if (d) { - r_io_map_new (core->io, d->fd, d->perm, 0, addr, r_io_desc_size (d)); + rz_io_map_new (core->io, d->fd, d->perm, 0, addr, rz_io_desc_size (d)); } } next_arroba: @@ -3689,7 +3689,7 @@ next_arroba: } core->fixedblock = !!tmpdesc; if (core->fixedblock) { - r_core_block_read (core); + rz_core_block_read (core); } if (ptr[1] == '@') { if (ptr[2] == '@') { @@ -3697,9 +3697,9 @@ next_arroba: while (*rule && *rule == ' ') { rule++; } - ret = r_core_cmd_foreach3 (core, cmd, rule); + ret = rz_core_cmd_foreach3 (core, cmd, rule); } else { - ret = r_core_cmd_foreach (core, cmd, ptr + 2); + ret = rz_core_cmd_foreach (core, cmd, ptr + 2); } } else { bool tmpseek = false; @@ -3726,21 +3726,21 @@ next_arroba: arg[arg_len - 1] = 0; } *p = '\x00'; - ut64 from = r_num_math (core->num, range); - ut64 to = r_num_math (core->num, arg); + ut64 from = rz_num_math (core->num, range); + ut64 to = rz_num_math (core->num, arg); // save current ranges for (i = 0; fromvars[i]; i++) { - curfrom[i] = r_config_get_i (core->config, fromvars[i]); + curfrom[i] = rz_config_get_i (core->config, fromvars[i]); } for (i = 0; tovars[i]; i++) { - curto[i] = r_config_get_i (core->config, tovars[i]); + curto[i] = rz_config_get_i (core->config, tovars[i]); } // set new ranges for (i = 0; fromvars[i]; i++) { - r_config_set_i (core->config, fromvars[i], from); + rz_config_set_i (core->config, fromvars[i], from); } for (i = 0; tovars[i]; i++) { - r_config_set_i (core->config, tovars[i], to); + rz_config_set_i (core->config, tovars[i], to); } tmpseek = true; } @@ -3748,60 +3748,60 @@ next_arroba: if (addr_is_set) { core->offset = addr; } - ret = r_cmd_call (core->rcmd, r_str_trim_head_ro (cmd)); + ret = rz_cmd_call (core->rcmd, rz_str_trim_head_ro (cmd)); } else { if (addr_is_set) { if (ptr[1]) { - r_core_seek (core, addr, true); - r_core_block_read (core); + rz_core_seek (core, addr, true); + rz_core_block_read (core); } } - ret = r_cmd_call (core->rcmd, r_str_trim_head_ro (cmd)); + ret = rz_cmd_call (core->rcmd, rz_str_trim_head_ro (cmd)); } if (tmpseek) { // restore ranges for (i = 0; fromvars[i]; i++) { - r_config_set_i (core->config, fromvars[i], curfrom[i]); + rz_config_set_i (core->config, fromvars[i], curfrom[i]); } for (i = 0; tovars[i]; i++) { - r_config_set_i (core->config, tovars[i], curto[i]); + rz_config_set_i (core->config, tovars[i], curto[i]); } } } if (ptr2) { *ptr2 = '!'; - r_core_block_size (core, tmpbsz); + rz_core_block_size (core, tmpbsz); } if (is_arch_set) { core->fixedarch = oldfixedarch; - r_config_set (core->config, "asm.arch", tmpasm); + rz_config_set (core->config, "asm.arch", tmpasm); R_FREE (tmpasm); } if (tmpfd != -1) { // TODO: reuse tmpfd instead of - r_io_use_fd (core->io, tmpfd); + rz_io_use_fd (core->io, tmpfd); } if (tmpdesc) { if (pamode) { - r_config_set_i (core->config, "io.va", 0); + rz_config_set_i (core->config, "io.va", 0); } - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); tmpdesc = NULL; } if (is_bits_set) { - r_config_set (core->config, "asm.bits", tmpbits); + rz_config_set (core->config, "asm.bits", tmpbits); core->fixedbits = oldfixedbits; } if (tmpbsz != core->blocksize) { - r_core_block_size (core, tmpbsz); + rz_core_block_size (core, tmpbsz); } if (tmpeval) { - r_core_cmd0 (core, tmpeval); + rz_core_cmd0 (core, tmpeval); R_FREE (tmpeval); } if (flgspc_changed) { - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); } *ptr = '@'; rc = ret; @@ -3809,8 +3809,8 @@ next_arroba: } fuji: if (cmd) { - r_str_trim_head (cmd); - rc = r_cmd_call (core->rcmd, cmd); + rz_str_trim_head (cmd); + rc = rz_cmd_call (core->rcmd, cmd); } else { rc = false; } @@ -3820,17 +3820,17 @@ beach: grep = unescape_special_chars (old_grep, SPECIAL_CHARS_REGULAR); free (old_grep); } - r_cons_grep_process (grep); + rz_cons_grep_process (grep); if (scr_html != -1) { - r_cons_flush (); - r_config_set_i (core->config, "scr.html", scr_html); + rz_cons_flush (); + rz_config_set_i (core->config, "scr.html", scr_html); } if (scr_color != -1) { - r_config_set_i (core->config, "scr.color", scr_color); + rz_config_set_i (core->config, "scr.color", scr_color); } - r_list_free (tmpenvs); + rz_list_free (tmpenvs); if (tmpdesc) { - r_io_desc_close (tmpdesc); + rz_io_desc_close (tmpdesc); tmpdesc = NULL; } core->fixedarch = oldfixedarch; @@ -3839,7 +3839,7 @@ beach: *tmpseek = cmd_tmpseek; } if (cmd_ignbithints != -1) { - r_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); + rz_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); } return rc; fail: @@ -3848,17 +3848,17 @@ fail: } struct exec_command_t { - RCore *core; + RzCore *core; const char *cmd; }; -static bool copy_into_flagitem_list(RFlagItem *flg, void *u) { - RFlagItem *fi = r_mem_dup (flg, sizeof (RFlagItem)); - r_list_append (u, fi); +static bool copy_into_flagitem_list(RzFlagItem *flg, void *u) { + RzFlagItem *fi = rz_mem_dup (flg, sizeof (RzFlagItem)); + rz_list_append (u, fi); return true; } -static void foreach_pairs(RCore *core, const char *cmd, const char *each) { +static void foreach_pairs(RzCore *core, const char *cmd, const char *each) { const char *arg; int pair = 0; for (arg = each ; ; ) { @@ -3867,12 +3867,12 @@ static void foreach_pairs(RCore *core, const char *cmd, const char *each) { *next = 0; } if (arg && *arg) { - ut64 n = r_num_get (NULL, arg); + ut64 n = rz_num_get (NULL, arg); if (pair%2) { - r_core_block_size (core, n); - r_core_cmd0 (core, cmd); + rz_core_block_size (core, n); + rz_core_cmd0 (core, cmd); } else { - r_core_seek (core, n, true); + rz_core_seek (core, n, true); } pair++; } @@ -3883,10 +3883,10 @@ static void foreach_pairs(RCore *core, const char *cmd, const char *each) { } } -R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@@" - RDebug *dbg = core->dbg; - RList *list, *head; - RListIter *iter; +RZ_API int rz_core_cmd_foreach3(RzCore *core, const char *cmd, char *each) { // "@@@" + RzDebug *dbg = core->dbg; + RzList *list, *head; + RzListIter *iter; int i; const char *filter = NULL; @@ -3899,11 +3899,11 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ foreach_pairs (core, cmd, each + 1); break; case '?': - r_core_cmd_help (core, help_msg_at_at_at); + rz_core_cmd_help (core, help_msg_at_at_at); break; case 'c': if (filter) { - char *arg = r_core_cmd_str (core, filter); + char *arg = rz_core_cmd_str (core, filter); foreach_pairs (core, cmd, arg); free (arg); } else { @@ -3911,16 +3911,16 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ } break; case 'C': { - char *glob = filter ? r_str_trim_dup (filter): NULL; + char *glob = filter ? rz_str_trim_dup (filter): NULL; RIntervalTreeIter it; - RAnalMetaItem *meta; - r_interval_tree_foreach (&core->anal->meta, it, meta) { + RzAnalMetaItem *meta; + rz_interval_tree_foreach (&core->anal->meta, it, meta) { if (meta->type != R_META_TYPE_COMMENT) { continue; } - if (!glob || (meta->str && r_str_glob (meta->str, glob))) { - r_core_seek (core, r_interval_tree_iter_get (&it)->start, true); - r_core_cmd0 (core, cmd); + if (!glob || (meta->str && rz_str_glob (meta->str, glob))) { + rz_core_seek (core, rz_interval_tree_iter_get (&it)->start, true); + rz_core_cmd0 (core, cmd); } } free (glob); @@ -3928,28 +3928,28 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ } case 'm': { - int fd = r_io_fd_get_current (core->io); + int fd = rz_io_fd_get_current (core->io); // only iterate maps of current fd - RList *maps = r_io_map_get_for_fd (core->io, fd); - RIOMap *map; + RzList *maps = rz_io_map_get_for_fd (core->io, fd); + RzIOMap *map; if (maps) { - RListIter *iter; - r_list_foreach (maps, iter, map) { - r_core_seek (core, map->itv.addr, true); - r_core_block_size (core, map->itv.size); - r_core_cmd0 (core, cmd); + RzListIter *iter; + rz_list_foreach (maps, iter, map) { + rz_core_seek (core, map->itv.addr, true); + rz_core_block_size (core, map->itv.size); + rz_core_cmd0 (core, cmd); } - r_list_free (maps); + rz_list_free (maps); } } break; case 'M': if (dbg && dbg->h && dbg->maps) { - RDebugMap *map; - r_list_foreach (dbg->maps, iter, map) { - r_core_seek (core, map->addr, true); - //r_core_block_size (core, map->size); - r_core_cmd0 (core, cmd); + RzDebugMap *map; + rz_list_foreach (dbg->maps, iter, map) { + rz_core_seek (core, map->addr, true); + //rz_core_block_size (core, map->size); + rz_core_cmd0 (core, cmd); } } break; @@ -3957,179 +3957,179 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ // iterate over all threads if (dbg && dbg->h && dbg->h->threads) { int origpid = dbg->pid; - RDebugPid *p; + RzDebugPid *p; list = dbg->h->threads (dbg, dbg->pid); if (!list) { return false; } - r_list_foreach (list, iter, p) { - r_core_cmdf (core, "dp %d", p->pid); - r_cons_printf ("PID %d\n", p->pid); - r_core_cmd0 (core, cmd); + rz_list_foreach (list, iter, p) { + rz_core_cmdf (core, "dp %d", p->pid); + rz_cons_printf ("PID %d\n", p->pid); + rz_core_cmd0 (core, cmd); } - r_core_cmdf (core, "dp %d", origpid); - r_list_free (list); + rz_core_cmdf (core, "dp %d", origpid); + rz_list_free (list); } break; case 'r': // @@@r { ut64 offorig = core->offset; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegItem *item; + RzRegItem *item; ut64 value; - head = r_reg_get_list (core->dbg->reg, i); + head = rz_reg_get_list (core->dbg->reg, i); if (!head) { continue; } - RList *list = r_list_newf (free); - r_list_foreach (head, iter, item) { + RzList *list = rz_list_newf (free); + rz_list_foreach (head, iter, item) { if (item->size != core->anal->bits) { continue; } if (item->type != i) { continue; } - r_list_append (list, strdup (item->name)); + rz_list_append (list, strdup (item->name)); } const char *item_name; - r_list_foreach (list, iter, item_name) { - value = r_reg_getv (core->dbg->reg, item_name); - r_core_seek (core, value, true); - r_cons_printf ("%s: ", item_name); - r_core_cmd0 (core, cmd); + rz_list_foreach (list, iter, item_name) { + value = rz_reg_getv (core->dbg->reg, item_name); + rz_core_seek (core, value, true); + rz_cons_printf ("%s: ", item_name); + rz_core_cmd0 (core, cmd); } - r_list_free (list); + rz_list_free (list); } - r_core_seek (core, offorig, true); + rz_core_seek (core, offorig, true); } break; case 'i': // @@@i { RBinImport *imp; ut64 offorig = core->offset; - list = r_bin_get_imports (core->bin); - RList *lost = r_list_newf (free); - r_list_foreach (list, iter, imp) { - char *impflag = r_str_newf ("sym.imp.%s", imp->name); - ut64 addr = r_num_math (core->num, impflag); + list = rz_bin_get_imports (core->bin); + RzList *lost = rz_list_newf (free); + rz_list_foreach (list, iter, imp) { + char *impflag = rz_str_newf ("sym.imp.%s", imp->name); + ut64 addr = rz_num_math (core->num, impflag); ut64 *n = R_NEW (ut64); *n = addr; - r_list_append (lost, n); + rz_list_append (lost, n); free (impflag); } ut64 *naddr; - r_list_foreach (lost, iter, naddr) { + rz_list_foreach (lost, iter, naddr) { ut64 addr = *naddr; if (addr && addr != UT64_MAX) { - r_core_seek (core, addr, true); - r_core_cmd0 (core, cmd); + rz_core_seek (core, addr, true); + rz_core_cmd0 (core, cmd); } } - r_core_seek (core, offorig, true); - r_list_free (lost); + rz_core_seek (core, offorig, true); + rz_list_free (lost); } break; case 'S': // "@@@S" { - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { ut64 offorig = core->offset; ut64 bszorig = core->blocksize; RBinSection *sec; - RListIter *iter; - r_list_foreach (obj->sections, iter, sec) { - r_core_seek (core, sec->vaddr, true); - r_core_block_size (core, sec->vsize); - r_core_cmd0 (core, cmd); + RzListIter *iter; + rz_list_foreach (obj->sections, iter, sec) { + rz_core_seek (core, sec->vaddr, true); + rz_core_block_size (core, sec->vsize); + rz_core_cmd0 (core, cmd); } - r_core_block_size (core, bszorig); - r_core_seek (core, offorig, true); + rz_core_block_size (core, bszorig); + rz_core_seek (core, offorig, true); } } #if ATTIC if (each[1] == 'S') { - RListIter *it; + RzListIter *it; RBinSection *sec; - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); int cbsz = core->blocksize; - r_list_foreach (obj->sections, it, sec){ + rz_list_foreach (obj->sections, it, sec){ ut64 addr = sec->vaddr; ut64 size = sec->vsize; // TODO: //if (R_BIN_SCN_EXECUTABLE & sec->perm) { // continue; //} - r_core_seek_size (core, addr, size); - r_core_cmd (core, cmd, 0); + rz_core_seek_size (core, addr, size); + rz_core_cmd (core, cmd, 0); } - r_core_block_size (core, cbsz); + rz_core_block_size (core, cbsz); } #endif break; case 's': if (each[1] == 't') { // strings - list = r_bin_get_strings (core->bin); + list = rz_bin_get_strings (core->bin); if (list) { ut64 offorig = core->offset; ut64 obs = core->blocksize; RBinString *s; - RList *lost = r_list_newf (free); - r_list_foreach (list, iter, s) { - RBinString *bs = r_mem_dup (s, sizeof (RBinString)); - r_list_append (lost, bs); + RzList *lost = rz_list_newf (free); + rz_list_foreach (list, iter, s) { + RBinString *bs = rz_mem_dup (s, sizeof (RBinString)); + rz_list_append (lost, bs); } - r_list_foreach (lost, iter, s) { - r_core_block_size (core, s->size); - r_core_seek (core, s->vaddr, true); - r_core_cmd0 (core, cmd); + rz_list_foreach (lost, iter, s) { + rz_core_block_size (core, s->size); + rz_core_seek (core, s->vaddr, true); + rz_core_cmd0 (core, cmd); } - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); - r_list_free (lost); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); + rz_list_free (lost); } } else { // symbols RBinSymbol *sym; ut64 offorig = core->offset; ut64 obs = core->blocksize; - list = r_bin_get_symbols (core->bin); - r_cons_break_push (NULL, NULL); - RList *lost = r_list_newf (free); - r_list_foreach (list, iter, sym) { - RBinSymbol *bs = r_mem_dup (sym, sizeof (RBinSymbol)); - r_list_append (lost, bs); + list = rz_bin_get_symbols (core->bin); + rz_cons_break_push (NULL, NULL); + RzList *lost = rz_list_newf (free); + rz_list_foreach (list, iter, sym) { + RBinSymbol *bs = rz_mem_dup (sym, sizeof (RBinSymbol)); + rz_list_append (lost, bs); } - r_list_foreach (lost, iter, sym) { - if (r_cons_is_breaked ()) { + rz_list_foreach (lost, iter, sym) { + if (rz_cons_is_breaked ()) { break; } - r_core_block_size (core, sym->size); - r_core_seek (core, sym->vaddr, true); - r_core_cmd0 (core, cmd); + rz_core_block_size (core, sym->size); + rz_core_seek (core, sym->vaddr, true); + rz_core_cmd0 (core, cmd); } - r_cons_break_pop (); - r_list_free (lost); - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_cons_break_pop (); + rz_list_free (lost); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); } break; case 'f': // flags { // TODO: honor ^C - char *glob = filter? r_str_trim_dup (filter): NULL; + char *glob = filter? rz_str_trim_dup (filter): NULL; ut64 off = core->offset; ut64 obs = core->blocksize; - RList *flags = r_list_newf (free); - r_flag_foreach_glob (core->flags, glob, copy_into_flagitem_list, flags); - RListIter *iter; - RFlagItem *f; - r_list_foreach (flags, iter, f) { - r_core_block_size (core, f->size); - r_core_seek (core, f->offset, true); - r_core_cmd0 (core, cmd); + RzList *flags = rz_list_newf (free); + rz_flag_foreach_glob (core->flags, glob, copy_into_flagitem_list, flags); + RzListIter *iter; + RzFlagItem *f; + rz_list_foreach (flags, iter, f) { + rz_core_block_size (core, f->size); + rz_core_seek (core, f->offset, true); + rz_core_cmd0 (core, cmd); } - r_core_seek (core, off, false); - r_core_block_size (core, obs); + rz_core_seek (core, off, false); + rz_core_block_size (core, obs); free (glob); } break; @@ -4137,39 +4137,39 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ { ut64 obs = core->blocksize; ut64 offorig = core->offset; - RAnalFunction *fcn; + RzAnalFunction *fcn; list = core->anal->fcns; - r_cons_break_push (NULL, NULL); - r_list_foreach (list, iter, fcn) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (list, iter, fcn) { + if (rz_cons_is_breaked ()) { break; } - if (!filter || r_str_glob (fcn->name, filter)) { - r_core_seek (core, fcn->addr, true); - r_core_block_size (core, r_anal_function_linear_size (fcn)); - r_core_cmd0 (core, cmd); + if (!filter || rz_str_glob (fcn->name, filter)) { + rz_core_seek (core, fcn->addr, true); + rz_core_block_size (core, rz_anal_function_linear_size (fcn)); + rz_core_cmd0 (core, cmd); } } - r_cons_break_pop (); - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_cons_break_pop (); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); } break; case 'b': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); ut64 offorig = core->offset; ut64 obs = core->blocksize; if (fcn) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { - r_core_seek (core, bb->addr, true); - r_core_block_size (core, bb->size); - r_core_cmd0 (core, cmd); + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { + rz_core_seek (core, bb->addr, true); + rz_core_block_size (core, bb->size); + rz_core_cmd0 (core, cmd); } - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); } } break; @@ -4177,7 +4177,7 @@ R_API int r_core_cmd_foreach3(RCore *core, const char *cmd, char *each) { // "@@ return 0; } -static void foreachOffset(RCore *core, const char *_cmd, const char *each) { +static void foreachOffset(RzCore *core, const char *_cmd, const char *each) { char *cmd = strdup (_cmd); char *nextLine = NULL; ut64 addr; @@ -4213,32 +4213,32 @@ static void foreachOffset(RCore *core, const char *_cmd, const char *each) { char *str = strchr (each, ' '); if (str) { *str = '\0'; - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); *str = ' '; each = str + 1; } else { if (!*each) { break; } - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); each = NULL; } - r_core_seek (core, addr, true); - r_core_cmd (core, cmd, 0); - r_cons_flush (); + rz_core_seek (core, addr, true); + rz_core_cmd (core, cmd, 0); + rz_cons_flush (); } each = nextLine; } free (cmd); } -R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { +RZ_API int rz_core_cmd_foreach(RzCore *core, const char *cmd, char *each) { int i, j; char ch; char *word = NULL; char *str, *ostr = NULL; - RListIter *iter; - RFlagItem *flag; + RzListIter *iter; + RzFlagItem *flag; ut64 oseek, addr; for (; *cmd == ' '; cmd++) { @@ -4247,39 +4247,39 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { oseek = core->offset; ostr = str = strdup (each); - r_cons_break_push (NULL, NULL); //pop on return + rz_cons_break_push (NULL, NULL); //pop on return switch (each[0]) { case '/': // "@@/" { - char *cmdhit = strdup (r_config_get (core->config, "cmd.hit")); - r_config_set (core->config, "cmd.hit", cmd); - r_core_cmd0 (core, each); - r_config_set (core->config, "cmd.hit", cmdhit); + char *cmdhit = strdup (rz_config_get (core->config, "cmd.hit")); + rz_config_set (core->config, "cmd.hit", cmd); + rz_core_cmd0 (core, each); + rz_config_set (core->config, "cmd.hit", cmdhit); free (cmdhit); } free (ostr); return 0; case '?': // "@@?" - r_core_cmd_help (core, help_msg_at_at); + rz_core_cmd_help (core, help_msg_at_at); break; case 'b': // "@@b" - function basic blocks { - RListIter *iter; - RAnalBlock *bb; - RAnalFunction *fcn = r_anal_get_function_at (core->anal, core->offset); + RzListIter *iter; + RzAnalBlock *bb; + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, core->offset); int bs = core->blocksize; if (fcn) { - r_list_sort (fcn->bbs, bb_cmp); - r_list_foreach (fcn->bbs, iter, bb) { - r_core_block_size (core, bb->size); - r_core_seek (core, bb->addr, true); - r_core_cmd (core, cmd, 0); - if (r_cons_is_breaked ()) { + rz_list_sort (fcn->bbs, bb_cmp); + rz_list_foreach (fcn->bbs, iter, bb) { + rz_core_block_size (core, bb->size); + rz_core_seek (core, bb->addr, true); + rz_core_cmd (core, cmd, 0); + if (rz_cons_is_breaked ()) { break; } } } - r_core_block_size (core, bs); + rz_core_block_size (core, bs); goto out_finish; } break; @@ -4289,16 +4289,16 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { if (*str == ':' || *str == ' ') { str++; } - int count = r_str_split (str, ' '); + int count = rz_str_split (str, ' '); if (count == 3) { ut64 cur; - ut64 from = r_num_math (core->num, r_str_word_get0 (str, 0)); - ut64 to = r_num_math (core->num, r_str_word_get0 (str, 1)); - ut64 step = r_num_math (core->num, r_str_word_get0 (str, 2)); + ut64 from = rz_num_math (core->num, rz_str_word_get0 (str, 0)); + ut64 to = rz_num_math (core->num, rz_str_word_get0 (str, 1)); + ut64 step = rz_num_math (core->num, rz_str_word_get0 (str, 2)); for (cur = from; cur <= to; cur += step) { - (void) r_core_seek (core, cur, true); - r_core_cmd (core, cmd, 0); - if (r_cons_is_breaked ()) { + (void) rz_core_seek (core, cur, true); + rz_core_cmd (core, cmd, 0); + if (rz_cons_is_breaked ()) { break; } } @@ -4310,18 +4310,18 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { break; case 'i': // "@@i" - function instructions { - RListIter *iter; - RAnalBlock *bb; + RzListIter *iter; + RzAnalBlock *bb; int i; - RAnalFunction *fcn = r_anal_get_function_at (core->anal, core->offset); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, core->offset); if (fcn) { - r_list_sort (fcn->bbs, bb_cmp); - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_sort (fcn->bbs, bb_cmp); + rz_list_foreach (fcn->bbs, iter, bb) { for (i = 0; i < bb->op_pos_size; i++) { ut64 addr = bb->addr + bb->op_pos[i]; - r_core_seek (core, addr, true); - r_core_cmd (core, cmd, 0); - if (r_cons_is_breaked ()) { + rz_core_seek (core, addr, true); + rz_core_cmd (core, cmd, 0); + if (rz_cons_is_breaked ()) { break; } } @@ -4332,14 +4332,14 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { break; case 'f': // "@@f" if (each[1] == ':') { - RAnalFunction *fcn; - RListIter *iter; + RzAnalFunction *fcn; + RzListIter *iter; if (core->anal) { - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { if (each[2] && strstr (fcn->name, each + 2)) { - r_core_seek (core, fcn->addr, true); - r_core_cmd (core, cmd, 0); - if (r_cons_is_breaked ()) { + rz_core_seek (core, fcn->addr, true); + rz_core_cmd (core, cmd, 0); + if (rz_cons_is_breaked ()) { break; } } @@ -4347,23 +4347,23 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { } goto out_finish; } else { - RAnalFunction *fcn; - RListIter *iter; + RzAnalFunction *fcn; + RzListIter *iter; if (core->anal) { - RConsGrep grep = core->cons->context->grep; - r_list_foreach (core->anal->fcns, iter, fcn) { + RzConsGrep grep = core->cons->context->grep; + rz_list_foreach (core->anal->fcns, iter, fcn) { char *buf; - r_core_seek (core, fcn->addr, true); - r_cons_push (); - r_core_cmd (core, cmd, 0); - buf = (char *)r_cons_get_buffer (); + rz_core_seek (core, fcn->addr, true); + rz_cons_push (); + rz_core_cmd (core, cmd, 0); + buf = (char *)rz_cons_get_buffer (); if (buf) { buf = strdup (buf); } - r_cons_pop (); - r_cons_strcat (buf); + rz_cons_pop (); + rz_cons_strcat (buf); free (buf); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } @@ -4374,25 +4374,25 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { break; case 't': // "@@t" { - RDebugPid *p; + RzDebugPid *p; int pid = core->dbg->pid; if (core->dbg->h && core->dbg->h->pids) { - RList *list = core->dbg->h->pids (core->dbg, R_MAX (0, pid)); - r_list_foreach (list, iter, p) { - r_cons_printf ("# PID %d\n", p->pid); - r_debug_select (core->dbg, p->pid, p->pid); - r_core_cmd (core, cmd, 0); - r_cons_newline (); + RzList *list = core->dbg->h->pids (core->dbg, R_MAX (0, pid)); + rz_list_foreach (list, iter, p) { + rz_cons_printf ("# PID %d\n", p->pid); + rz_debug_select (core->dbg, p->pid, p->pid); + rz_core_cmd (core, cmd, 0); + rz_cons_newline (); } - r_list_free (list); + rz_list_free (list); } - r_debug_select (core->dbg, pid, pid); + rz_debug_select (core->dbg, pid, pid); goto out_finish; } break; case 'c': // "@@c:" if (each[1] == ':') { - char *arg = r_core_cmd_str (core, each + 2); + char *arg = rz_core_cmd_str (core, each + 2); if (arg) { foreachOffset (core, cmd, arg); free (arg); @@ -4405,30 +4405,30 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { case 'd': // "@@d" if (each[1] == 'b' && each[2] == 't') { ut64 oseek = core->offset; - RDebugFrame *frame; - RListIter *iter; - RList *list; - list = r_debug_frames (core->dbg, UT64_MAX); + RzDebugFrame *frame; + RzListIter *iter; + RzList *list; + list = rz_debug_frames (core->dbg, UT64_MAX); i = 0; - r_list_foreach (list, iter, frame) { + rz_list_foreach (list, iter, frame) { switch (each[3]) { case 'b': - r_core_seek (core, frame->bp, true); + rz_core_seek (core, frame->bp, true); break; case 's': - r_core_seek (core, frame->sp, true); + rz_core_seek (core, frame->sp, true); break; default: case 'a': - r_core_seek (core, frame->addr, true); + rz_core_seek (core, frame->addr, true); break; } - r_core_cmd (core, cmd, 0); - r_cons_newline (); + rz_core_cmd (core, cmd, 0); + rz_cons_newline (); i++; } - r_core_seek (core, oseek, false); - r_list_free (list); + rz_core_seek (core, oseek, false); + rz_list_free (list); } else { eprintf("Invalid for-each statement. Use @@=dbt[abs]\n"); } @@ -4449,16 +4449,16 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { str = strchr (each, ' '); if (str) { *str = '\0'; - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); *str = ' '; } else { - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); } //eprintf ("; 0x%08"PFMT64x":\n", addr); each = str + 1; - r_core_seek (core, addr, true); - r_core_cmd (core, cmd, 0); - r_cons_flush (); + rz_core_seek (core, addr, true); + rz_core_cmd (core, cmd, 0); + rz_cons_flush (); } while (str != NULL); free (out); } @@ -4470,24 +4470,24 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { // XXX what's this 999 ? i = 0; for (core->rcmd->macro.counter = 0; i < 999; core->rcmd->macro.counter++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_cmd_macro_call (&core->rcmd->macro, each + 2); + rz_cmd_macro_call (&core->rcmd->macro, each + 2); if (!core->rcmd->macro.brk_value) { break; } addr = core->rcmd->macro._brk_value; sprintf (cmd2, "%s @ 0x%08"PFMT64x"", cmd, addr); eprintf ("0x%08"PFMT64x" (%s)\n", addr, cmd2); - r_core_seek (core, addr, true); - r_core_cmd (core, cmd2, 0); + rz_core_seek (core, addr, true); + rz_core_cmd (core, cmd2, 0); i++; } } else { char buf[1024]; char cmd2[1024]; - FILE *fd = r_sandbox_fopen (each + 1, "r"); + FILE *fd = rz_sandbox_fopen (each + 1, "r"); if (fd) { core->rcmd->macro.counter = 0; while (!feof (fd)) { @@ -4495,11 +4495,11 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { if (!fgets (buf, sizeof (buf), fd)) { break; } - addr = r_num_math (core->num, buf); + addr = rz_num_math (core->num, buf); eprintf ("0x%08"PFMT64x": %s\n", addr, cmd); sprintf (cmd2, "%s @ 0x%08"PFMT64x"", cmd, addr); - r_core_seek (core, addr, true); // XXX - r_core_cmd (core, cmd2, 0); + rz_core_seek (core, addr, true); // XXX + rz_core_cmd (core, cmd2, 0); core->rcmd->macro.counter++; } fclose (fd); @@ -4530,8 +4530,8 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { } str[i] = ch; { - const RSpace *flagspace = r_flag_space_cur (core->flags); - RList *match_flag_items = r_list_newf ((RListFree)r_flag_item_free); + const RSpace *flagspace = rz_flag_space_cur (core->flags); + RzList *match_flag_items = rz_list_newf ((RzListFree)rz_flag_item_free); if (!match_flag_items) { break; } @@ -4544,35 +4544,35 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { .ret = match_flag_items, .word = word, }; - r_flag_foreach_space (core->flags, flagspace, duplicate_flag, &u); + rz_flag_foreach_space (core->flags, flagspace, duplicate_flag, &u); /* for all flags that match */ - r_list_foreach (match_flag_items, iter, flag) { - if (r_cons_is_breaked ()) { + rz_list_foreach (match_flag_items, iter, flag) { + if (rz_cons_is_breaked ()) { break; } char *buf = NULL; const char *tmp = NULL; - r_core_seek (core, flag->offset, true); - r_cons_push (); - r_core_cmd (core, cmd, 0); - tmp = r_cons_get_buffer (); + rz_core_seek (core, flag->offset, true); + rz_cons_push (); + rz_core_cmd (core, cmd, 0); + tmp = rz_cons_get_buffer (); buf = tmp? strdup (tmp): NULL; - r_cons_pop (); - r_cons_strcat (buf); + rz_cons_pop (); + rz_cons_strcat (buf); free (buf); - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); } - r_list_free (match_flag_items); + rz_list_free (match_flag_items); core->rcmd->macro.counter++ ; R_FREE (word); } } } - r_cons_break_pop (); - // XXX: use r_core_seek here + rz_cons_break_pop (); + // XXX: use rz_core_seek here core->offset = oseek; free (word); @@ -4580,15 +4580,15 @@ R_API int r_core_cmd_foreach(RCore *core, const char *cmd, char *each) { return true; out_finish: free (ostr); - r_cons_break_pop (); + rz_cons_break_pop (); return false; } -static int run_cmd_depth(RCore *core, char *cmd); +static int run_cmd_depth(RzCore *core, char *cmd); struct tsr2cmd_state { TSParser *parser; - RCore *core; + RzCore *core; char *input; char *saved_input; TSTree *tree; @@ -4608,7 +4608,7 @@ struct tsr2cmd_edit { TSPoint end_point; }; -typedef RCmdStatus (*ts_handler)(struct tsr2cmd_state *state, TSNode node); +typedef RzCmdStatus (*ts_handler)(struct tsr2cmd_state *state, TSNode node); struct ts_data_symbol_map { const char *name; @@ -4623,7 +4623,7 @@ struct ts_data_symbol_map { static char *ts_node_sub_string(TSNode node, const char *cstr) { ut32 start, end; TS_START_END (node, start, end); - return r_str_newf ("%.*s", end - start, cstr + start); + return rz_str_newf ("%.*s", end - start, cstr + start); } static char *ts_node_sub_parent_string(TSNode parent, TSNode node, const char *cstr) { @@ -4632,7 +4632,7 @@ static char *ts_node_sub_parent_string(TSNode parent, TSNode node, const char *c ut32 parent_start = ts_node_start_byte (parent); start -= parent_start; end -= parent_start; - return r_str_newf ("%.*s", end - start, cstr + start); + return rz_str_newf ("%.*s", end - start, cstr + start); } #define DEFINE_SYMBOL_TS_FCN(name) TSSymbol ts_##name##_symbol @@ -4647,15 +4647,15 @@ static char *ts_node_sub_parent_string(TSNode parent, TSNode node, const char *c DEFINE_IS_TS_FCN (name) #define DEFINE_HANDLE_TS_FCN(name) \ - static RCmdStatus handle_ts_##name##_internal(struct tsr2cmd_state *state, TSNode node, char *node_string); \ - static RCmdStatus handle_ts_##name(struct tsr2cmd_state *state, TSNode node) { \ + static RzCmdStatus handle_ts_##name##_internal(struct tsr2cmd_state *state, TSNode node, char *node_string); \ + static RzCmdStatus handle_ts_##name(struct tsr2cmd_state *state, TSNode node) { \ char *node_string = ts_node_sub_string (node, state->input); \ R_LOG_DEBUG (#name ": '%s'\n", node_string); \ - RCmdStatus res = handle_ts_##name##_internal (state, node, node_string); \ + RzCmdStatus res = handle_ts_##name##_internal (state, node, node_string); \ free (node_string); \ return res; \ } \ - static RCmdStatus handle_ts_##name##_internal(struct tsr2cmd_state *state, TSNode node, char *node_string) + static RzCmdStatus handle_ts_##name##_internal(struct tsr2cmd_state *state, TSNode node, char *node_string) #define DEFINE_HANDLE_TS_FCN_AND_SYMBOL(name) \ DEFINE_SYMBOL_TS_FCN (name); \ @@ -4667,9 +4667,9 @@ static char *ts_node_sub_parent_string(TSNode parent, TSNode node, const char *c goto label; \ } -static RCmdStatus handle_ts_command(struct tsr2cmd_state *state, TSNode node); -static RCmdStatus handle_ts_command_tmpseek(struct tsr2cmd_state *state, TSNode node); -static RCmdStatus core_cmd_tsr2cmd(RCore *core, const char *cstr, bool split_lines, bool log); +static RzCmdStatus handle_ts_command(struct tsr2cmd_state *state, TSNode node); +static RzCmdStatus handle_ts_command_tmpseek(struct tsr2cmd_state *state, TSNode node); +static RzCmdStatus core_cmd_tsr2cmd(RzCore *core, const char *cstr, bool split_lines, bool log); DEFINE_IS_TS_FCN_AND_SYMBOL(fdn_redirect_operator) DEFINE_IS_TS_FCN_AND_SYMBOL(fdn_append_operator) @@ -4748,29 +4748,29 @@ void free_tsr2cmd_edit(struct tsr2cmd_edit *edit) { } static char *do_handle_substitution_cmd(struct tsr2cmd_state *state, TSNode inn_cmd) { - RCore *core = state->core; + RzCore *core = state->core; int value = core->num->value; char *inn_str = ts_node_sub_parent_string (state->substitute_cmd, inn_cmd, state->input); // save current color and disable it - int ocolor = r_config_get_i (core->config, "scr.color"); - r_config_set_i (core->config, "scr.color", 0); + int ocolor = rz_config_get_i (core->config, "scr.color"); + rz_config_set_i (core->config, "scr.color", 0); core->cmd_in_backticks = true; // execute the sub command char *o_out = inn_str[0] == '!'? - r_core_cmd_str_pipe (core, inn_str): - r_core_cmd_str (core, inn_str); + rz_core_cmd_str_pipe (core, inn_str): + rz_core_cmd_str (core, inn_str); // restore color and cmd_in_backticks core->num->value = value; core->cmd_in_backticks = false; - r_config_set_i (core->config, "scr.color", ocolor); + rz_config_set_i (core->config, "scr.color", ocolor); free (inn_str); // replace the output of the sub command with the current argument char *out = strdup (o_out); - r_str_trim (out); + rz_str_trim (out); R_LOG_DEBUG ("output of inner command: '%s'\n", out); free (o_out); @@ -4779,9 +4779,9 @@ static char *do_handle_substitution_cmd(struct tsr2cmd_state *state, TSNode inn_ return out; } -static void handle_cmd_substitution_arg(struct tsr2cmd_state *state, TSNode arg, RList *edits) { +static void handle_cmd_substitution_arg(struct tsr2cmd_state *state, TSNode arg, RzList *edits) { TSNode inn_cmd = ts_node_child (arg, 1); - r_return_if_fail (!ts_node_is_null (inn_cmd)); + rz_return_if_fail (!ts_node_is_null (inn_cmd)); char *out = do_handle_substitution_cmd (state, inn_cmd); // escape special chars to prevent creation of new tokens when parsing again const char *special_chars; @@ -4794,7 +4794,7 @@ static void handle_cmd_substitution_arg(struct tsr2cmd_state *state, TSNode arg, } out = escape_special_chars (out, special_chars); struct tsr2cmd_edit *e = create_cmd_edit (state, arg, out); - r_list_append (edits, e); + rz_list_append (edits, e); } static bool is_group_of_args(TSNode args) { @@ -4814,7 +4814,7 @@ static bool is_handled_args(TSNode args) { is_ts_cmd_substitution_arg (args) || is_ts_grep_specifier (args); } -static void handle_substitution_args(struct tsr2cmd_state *state, TSNode args, RList *edits) { +static void handle_substitution_args(struct tsr2cmd_state *state, TSNode args, RzList *edits) { if (is_group_of_args (args)) { uint32_t n_children = ts_node_named_child_count (args); uint32_t i; @@ -4862,21 +4862,21 @@ static char *do_handle_ts_unescape_arg(struct tsr2cmd_state *state, TSNode arg, return res; } else if (is_ts_concatenation (arg)) { uint32_t i, n_children = ts_node_named_child_count (arg); - RStrBuf *sb = r_strbuf_new (NULL); + RStrBuf *sb = rz_strbuf_new (NULL); for (i = 0; i < n_children; i++) { TSNode sub_arg = ts_node_named_child (arg, i); char *s = do_handle_ts_unescape_arg (state, sub_arg, do_unwrap); - r_strbuf_append (sb, s); + rz_strbuf_append (sb, s); } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } else { return ts_node_sub_string (arg, state->input); } } -static RCmdParsedArgs *parse_args(struct tsr2cmd_state *state, TSNode args, bool do_unwrap) { +static RzCmdParsedArgs *parse_args(struct tsr2cmd_state *state, TSNode args, bool do_unwrap) { if (ts_node_is_null (args)) { - return r_cmd_parsed_args_newargs (0, NULL); + return rz_cmd_parsed_args_newargs (0, NULL); } else if (is_ts_args (args)) { uint32_t n_children = ts_node_named_child_count (args); uint32_t i; @@ -4885,7 +4885,7 @@ static RCmdParsedArgs *parse_args(struct tsr2cmd_state *state, TSNode args, bool TSNode arg = ts_node_named_child (args, i); unescaped_args[i] = do_handle_ts_unescape_arg (state, arg, do_unwrap); } - RCmdParsedArgs *res = r_cmd_parsed_args_newargs (n_children, unescaped_args); + RzCmdParsedArgs *res = rz_cmd_parsed_args_newargs (n_children, unescaped_args); for (i = 0; i < n_children; i++) { free (unescaped_args[i]); } @@ -4893,20 +4893,20 @@ static RCmdParsedArgs *parse_args(struct tsr2cmd_state *state, TSNode args, bool return res; } else { char *unescaped_args[] = { do_handle_ts_unescape_arg (state, args, do_unwrap) }; - RCmdParsedArgs *res = r_cmd_parsed_args_newargs (1, unescaped_args); + RzCmdParsedArgs *res = rz_cmd_parsed_args_newargs (1, unescaped_args); free (unescaped_args[0]); return res; } } -static TSTree *apply_edits(struct tsr2cmd_state *state, RList *edits) { +static TSTree *apply_edits(struct tsr2cmd_state *state, RzList *edits) { struct tsr2cmd_edit *edit; - RListIter *it; + RzListIter *it; R_LOG_DEBUG ("old input = '%s'\n", state->input); - r_list_foreach (edits, it, edit) { + rz_list_foreach (edits, it, edit) { R_LOG_DEBUG ("apply_edits: about to replace '%s' with '%s'\n", edit->old_text, edit->new_text); - state->input = r_str_replace (state->input, edit->old_text, edit->new_text, 0); + state->input = rz_str_replace (state->input, edit->old_text, edit->new_text, 0); } R_LOG_DEBUG ("new input = '%s'\n", state->input); return ts_parser_parse_string (state->parser, NULL, state->input, strlen (state->input)); @@ -4933,7 +4933,7 @@ static void substitute_args_init(struct tsr2cmd_state *state, TSNode command) { R_LOG_DEBUG ("Shrinking input to '%s'\n", state->input); } -static bool substitute_args_do(struct tsr2cmd_state *state, RList *edits, TSNode *new_command) { +static bool substitute_args_do(struct tsr2cmd_state *state, RzList *edits, TSNode *new_command) { TSTree *new_tree = apply_edits (state, edits); if (!new_tree) { return false; @@ -4950,19 +4950,19 @@ static bool substitute_args_do(struct tsr2cmd_state *state, RList *edits, TSNode } static bool substitute_args(struct tsr2cmd_state *state, TSNode args, TSNode *new_command) { - RList *edits = r_list_newf ((RListFree)free_tsr2cmd_edit); + RzList *edits = rz_list_newf ((RzListFree)free_tsr2cmd_edit); if (is_handled_args (args)) { handle_substitution_args (state, args, edits); } bool res = substitute_args_do (state, edits, new_command); - r_list_free (edits); + rz_list_free (edits); return res; } -static RCmdParsedArgs *ts_node_handle_arg_prargs(struct tsr2cmd_state *state, TSNode command, TSNode arg, uint32_t child_idx, bool do_unwrap) { - RCmdParsedArgs *res = NULL; +static RzCmdParsedArgs *ts_node_handle_arg_prargs(struct tsr2cmd_state *state, TSNode command, TSNode arg, uint32_t child_idx, bool do_unwrap) { + RzCmdParsedArgs *res = NULL; TSNode new_command; substitute_args_init (state, command); bool ok = substitute_args (state, arg, &new_command); @@ -4983,25 +4983,25 @@ err: } static char *ts_node_handle_arg(struct tsr2cmd_state *state, TSNode command, TSNode arg, uint32_t child_idx) { - RCmdParsedArgs *a = ts_node_handle_arg_prargs (state, command, arg, child_idx, true); - char *str = r_cmd_parsed_args_argstr (a); - r_cmd_parsed_args_free (a); + RzCmdParsedArgs *a = ts_node_handle_arg_prargs (state, command, arg, child_idx, true); + char *str = rz_cmd_parsed_args_argstr (a); + rz_cmd_parsed_args_free (a); return str; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(arged_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); - r_return_val_if_fail (!ts_node_is_null (command), false); + rz_return_val_if_fail (!ts_node_is_null (command), false); char *command_str = ts_node_sub_string (command, state->input); R_LOG_DEBUG ("arged_command command: '%s'\n", command_str); TSNode args = ts_node_child_by_field_name (node, "args", strlen ("args")); - RCmdStatus res = R_CMD_STATUS_INVALID; + RzCmdStatus res = R_CMD_STATUS_INVALID; // FIXME: this special handling should be removed once we have a proper // command tree if (!strcmp (command_str, "|.")) { char *cmd_str = ts_node_sub_string (args, state->input); - char *exec_string = r_str_newf (".%s", cmd_str); + char *exec_string = rz_str_newf (".%s", cmd_str); free (cmd_str); free (command_str); res = core_cmd_tsr2cmd (state->core, exec_string, state->split_lines, false); @@ -5009,17 +5009,17 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(arged_command) { return res; } - RCmdParsedArgs *pr_args = NULL; + RzCmdParsedArgs *pr_args = NULL; if (!ts_node_is_null (args)) { - RCmdDesc *cd = r_cmd_get_desc (state->core->rcmd, command_str); + RzCmdDesc *cd = rz_cmd_get_desc (state->core->rcmd, command_str); bool do_unwrap = cd && cd->type != R_CMD_DESC_TYPE_OLDINPUT; pr_args = ts_node_handle_arg_prargs (state, node, args, 1, do_unwrap); if (!pr_args) { goto err; } - r_cmd_parsed_args_setcmd (pr_args, command_str); + rz_cmd_parsed_args_setcmd (pr_args, command_str); } else { - pr_args = r_cmd_parsed_args_newcmd (command_str); + pr_args = rz_cmd_parsed_args_newcmd (command_str); if (!pr_args) { goto err; } @@ -5027,28 +5027,28 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(arged_command) { int i; const char *s; - r_cmd_parsed_args_foreach_arg (pr_args, i, s) { + rz_cmd_parsed_args_foreach_arg (pr_args, i, s) { R_LOG_DEBUG ("parsed_arg %d: '%s'\n", i, s); } pr_args->has_space_after_cmd = !ts_node_is_null (args) && ts_node_end_byte (command) < ts_node_start_byte (args); - res = r_cmd_call_parsed_args (state->core->rcmd, pr_args); + res = rz_cmd_call_parsed_args (state->core->rcmd, pr_args); if (res == R_CMD_STATUS_WRONG_ARGS) { - const char *cmdname = r_cmd_parsed_args_cmd (pr_args); + const char *cmdname = rz_cmd_parsed_args_cmd (pr_args); eprintf ("Wrong number of arguments passed to `%s`, see its help with `%s?`\n", cmdname, cmdname); } else if (res == R_CMD_STATUS_ERROR) { - const char *cmdname = r_cmd_parsed_args_cmd (pr_args); + const char *cmdname = rz_cmd_parsed_args_cmd (pr_args); R_LOG_DEBUG ("Something wrong during the execution of `%s` command.\n", cmdname); } err: - r_cmd_parsed_args_free (pr_args); + rz_cmd_parsed_args_free (pr_args); free (command_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(legacy_quoted_command) { - return r_cmd_int2status(run_cmd_depth (state->core, node_string)); + return rz_cmd_int2status(run_cmd_depth (state->core, node_string)); } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(repeat_command) { @@ -5058,20 +5058,20 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(repeat_command) { free (number_str); TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); - if (rep > 1 && r_sandbox_enable (0)) { + if (rep > 1 && rz_sandbox_enable (0)) { eprintf ("Command repeat sugar disabled in sandbox mode (%s)\n", node_string); return R_CMD_STATUS_INVALID; } - if (rep > INTERACTIVE_MAX_REP && r_cons_is_interactive ()) { - if (!r_cons_yesno ('n', "Are you sure to repeat this %" PFMT64d " times? (y/N)", rep)) { + if (rep > INTERACTIVE_MAX_REP && rz_cons_is_interactive ()) { + if (!rz_cons_yesno ('n', "Are you sure to repeat this %" PFMT64d " times? (y/N)", rep)) { return R_CMD_STATUS_INVALID; } } - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; size_t i; for (i = 0; i < rep; i++) { - RCmdStatus cmd_res = handle_ts_command (state, command); + RzCmdStatus cmd_res = handle_ts_command (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: @@ -5079,10 +5079,10 @@ err: } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_command) { - int pipecolor = r_config_get_i (state->core->config, "scr.color.pipe"); - int ocolor = r_config_get_i (state->core->config, "scr.color"); + int pipecolor = rz_config_get_i (state->core->config, "scr.color.pipe"); + int ocolor = rz_config_get_i (state->core->config, "scr.color"); int scr_html = -1; - RCmdStatus res = R_CMD_STATUS_INVALID, is_append = false, is_html = false; + RzCmdStatus res = R_CMD_STATUS_INVALID, is_append = false, is_html = false; int fdn = 1; TSNode redirect_op = ts_node_child_by_field_name (node, "redirect_operator", strlen ("redirect_operator")); @@ -5097,12 +5097,12 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_command) { is_append = true; } else { R_LOG_ERROR ("This should never happen, redirect_operator is no known type"); - r_warn_if_reached (); + rz_warn_if_reached (); } if (is_html) { - scr_html = r_config_get_i (state->core->config, "scr.html"); - r_config_set_i (state->core->config, "scr.html", true); + scr_html = rz_config_get_i (state->core->config, "scr.html"); + rz_config_set_i (state->core->config, "scr.html", true); pipecolor = true; } else { TSNode fd_desc = ts_node_named_child (redirect_op, 0); @@ -5113,7 +5113,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_command) { } } - r_cons_set_interactive (false); + rz_cons_set_interactive (false); // TODO: allow to use editor as the old behaviour // extract the string of the filename we need to write to @@ -5126,8 +5126,8 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); char *command_str = ts_node_sub_string (command, state->input); - char *output = r_core_cmd_str (state->core, command_str); - char *old_alias_value = r_cmd_alias_get (state->core->rcmd, arg_str, 1); + char *output = rz_core_cmd_str (state->core, command_str); + char *old_alias_value = rz_cmd_alias_get (state->core->rcmd, arg_str, 1); char *new_alias_value; const char *start_char = "$"; if (is_append && old_alias_value) { @@ -5135,34 +5135,34 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(redirect_command) { } else { old_alias_value = ""; } - new_alias_value = r_str_newf ("%s%s%s", start_char, old_alias_value, output); - r_cmd_alias_set (state->core->rcmd, arg_str, new_alias_value, 1); + new_alias_value = rz_str_newf ("%s%s%s", start_char, old_alias_value, output); + rz_cmd_alias_set (state->core->rcmd, arg_str, new_alias_value, 1); free (new_alias_value); free (command_str); res = R_CMD_STATUS_OK; } else { - r_cons_flush (); + rz_cons_flush (); R_LOG_DEBUG ("redirect_command: fdn = %d, is_append = %d\n", fdn, is_append); - int pipefd = r_cons_pipe_open (arg_str, fdn, is_append); + int pipefd = rz_cons_pipe_open (arg_str, fdn, is_append); if (pipefd != -1) { if (!pipecolor) { - r_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); } TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); res = handle_ts_command (state, command); - r_cons_flush (); - r_cons_pipe_close (pipefd); + rz_cons_flush (); + rz_cons_pipe_close (pipefd); } else { R_LOG_WARN ("Could not open pipe to %d", fdn); } } free (arg_str); - r_cons_set_last_interactive (); + rz_cons_set_last_interactive (); if (!pipecolor) { - r_config_set_i (state->core->config, "scr.color", ocolor); + rz_config_set_i (state->core->config, "scr.color", ocolor); } if (scr_html != -1) { - r_config_set_i (state->core->config, "scr.html", scr_html); + rz_config_set_i (state->core->config, "scr.html", scr_html); } state->core->cons->use_tts = false; return res; @@ -5173,17 +5173,17 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(help_command) { // FIXME: once we have a command tree, this special handling should be removed size_t node_str_len = strlen (node_string); if (!strcmp (node_string, "@?")) { - r_core_cmd_help (state->core, help_msg_at); + rz_core_cmd_help (state->core, help_msg_at); } else if (!strcmp (node_string, "@@?")) { - r_core_cmd_help (state->core, help_msg_at_at); + rz_core_cmd_help (state->core, help_msg_at_at); } else if (!strcmp (node_string, "@@@?")) { - r_core_cmd_help (state->core, help_msg_at_at_at); + rz_core_cmd_help (state->core, help_msg_at_at_at); } else if (!strcmp (node_string, "|?")) { - r_core_cmd_help (state->core, help_msg_vertical_bar); + rz_core_cmd_help (state->core, help_msg_vertical_bar); } else if (!strcmp (node_string, "~?")) { - r_cons_grep_help (); + rz_cons_grep_help (); } else if (!strcmp (node_string, ">?")) { - r_core_cmd_help (state->core, help_msg_greater_sign); + rz_core_cmd_help (state->core, help_msg_greater_sign); } else if (node_str_len >= 2 && !strcmp (node_string + node_str_len - 2, "?*")) { int detail = 0; if (node_str_len > 3 && node_string[node_str_len - 3] == '?') { @@ -5199,18 +5199,18 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(help_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); char *command_str = ts_node_sub_string (command, state->input); TSNode args = ts_node_child_by_field_name (node, "args", strlen ("args")); - RCmdParsedArgs *pr_args = NULL; - RCmdStatus res = R_CMD_STATUS_INVALID; + RzCmdParsedArgs *pr_args = NULL; + RzCmdStatus res = R_CMD_STATUS_INVALID; if (!ts_node_is_null (args)) { - RCmdDesc *cd = r_cmd_get_desc (state->core->rcmd, command_str); + RzCmdDesc *cd = rz_cmd_get_desc (state->core->rcmd, command_str); bool do_unwrap = cd && cd->type != R_CMD_DESC_TYPE_OLDINPUT; pr_args = ts_node_handle_arg_prargs (state, node, args, 1, do_unwrap); if (!pr_args) { goto err_else; } - r_cmd_parsed_args_setcmd (pr_args, command_str); + rz_cmd_parsed_args_setcmd (pr_args, command_str); } else { - pr_args = r_cmd_parsed_args_newcmd (command_str); + pr_args = rz_cmd_parsed_args_newcmd (command_str); if (!pr_args) { goto err_else; } @@ -5218,16 +5218,16 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(help_command) { // let's try first with the new auto-generated help, if // something fails fallback to old behaviour - char *help_msg = r_cmd_get_help (state->core->rcmd, pr_args, state->core->print->flags & R_PRINT_FLAGS_COLOR); + char *help_msg = rz_cmd_get_help (state->core->rcmd, pr_args, state->core->print->flags & R_PRINT_FLAGS_COLOR); if (help_msg) { - r_cons_printf ("%s", help_msg); + rz_cons_printf ("%s", help_msg); free (help_msg); res = R_CMD_STATUS_OK; } else { - res = r_cmd_call_parsed_args (state->core->rcmd, pr_args); + res = rz_cmd_call_parsed_args (state->core->rcmd, pr_args); } err_else: - r_cmd_parsed_args_free (pr_args); + rz_cmd_parsed_args_free (pr_args); free (command_str); return res; } @@ -5238,10 +5238,10 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_seek_command) { TSNode command = ts_node_named_child (node, 0); TSNode offset = ts_node_named_child (node, 1); char *offset_string = ts_node_handle_arg (state, node, offset, 1); - ut64 offset_val = r_num_math (state->core->num, offset_string); + ut64 offset_val = rz_num_math (state->core->num, offset_string); ut64 orig_offset = state->core->offset; if (!offset_val && isalpha ((int)offset_string[0])) { - if (!r_flag_get (state->core->flags, offset_string)) { + if (!rz_flag_get (state->core->flags, offset_string)) { eprintf ("Invalid address (%s)\n", offset_string); free (offset_string); return R_CMD_STATUS_INVALID; @@ -5251,9 +5251,9 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_seek_command) { offset_val += state->core->offset; } R_LOG_DEBUG ("tmp_seek_command, changing offset to %" PFMT64x "\n", offset_val); - r_core_seek (state->core, offset_val, true); - RCmdStatus res = handle_ts_command_tmpseek (state, command); - r_core_seek (state->core, orig_offset, true); + rz_core_seek (state->core, offset_val, true); + RzCmdStatus res = handle_ts_command_tmpseek (state, command); + rz_core_seek (state->core, orig_offset, true); free (offset_string); return res; } @@ -5264,15 +5264,15 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_blksz_command) { char *blksz_string = ts_node_handle_arg (state, node, blksz, 1); ut64 orig_blksz = state->core->blocksize; R_LOG_DEBUG ("tmp_blksz_command, changing blksz to %s\n", blksz_string); - r_core_block_size (state->core, r_num_math (state->core->num, blksz_string)); - RCmdStatus res = handle_ts_command (state, command); - r_core_block_size (state->core, orig_blksz); + rz_core_block_size (state->core, rz_num_math (state->core->num, blksz_string)); + RzCmdStatus res = handle_ts_command (state, command); + rz_core_block_size (state->core, orig_blksz); free (blksz_string); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_fromto_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode from = ts_node_named_child (node, 1); TSNode to = ts_node_named_child (node, 2); @@ -5283,33 +5283,33 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_fromto_command) { "io.buffer.from", "lines.from", "search.from", "zoom.from", NULL }; const char *tovars[] = { "anal.to", "diff.to", "graph.to", "io.buffer.to", "lines.to", "search.to", "zoom.to", NULL }; - ut64 from_val = r_num_math (core->num, from_str); - ut64 to_val = r_num_math (core->num, to_str); + ut64 from_val = rz_num_math (core->num, from_str); + ut64 to_val = rz_num_math (core->num, to_str); R_LOG_DEBUG ("tmp_fromto_command, changing fromto to (%" PFMT64x ", %" PFMT64x ")\n", from_val, to_val); - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); int i; for (i = 0; fromvars[i]; i++) { - r_config_hold_i (hc, fromvars[i], NULL); - r_config_set_i (core->config, fromvars[i], from_val); + rz_config_hold_i (hc, fromvars[i], NULL); + rz_config_set_i (core->config, fromvars[i], from_val); } for (i = 0; tovars[i]; i++) { - r_config_hold_i (hc, tovars[i], NULL); - r_config_set_i (core->config, tovars[i], to_val); + rz_config_hold_i (hc, tovars[i], NULL); + rz_config_set_i (core->config, tovars[i], to_val); } - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); - r_config_hold_restore (hc); + rz_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_free (hc); free (from_str); free (to_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_arch_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); @@ -5322,34 +5322,34 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_arch_command) { char *q = strchr (arg_str, ':'); if (q) { *q++ = '\0'; - int bits = r_num_math (core->num, q); + int bits = rz_num_math (core->num, q); is_bits_set = set_tmp_bits (core, bits, &tmpbits, &cmd_ignbithints); } is_arch_set = set_tmp_arch (core, arg_str, &tmparch); // execute command with changed settings - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); // restore original settings if (is_arch_set) { core->fixedarch = oldfixedarch; - r_config_set (core->config, "asm.arch", tmparch); + rz_config_set (core->config, "asm.arch", tmparch); free (tmparch); } if (is_bits_set) { - r_config_set (core->config, "asm.bits", tmpbits); + rz_config_set (core->config, "asm.bits", tmpbits); core->fixedbits = oldfixedbits; free (tmpbits); } if (cmd_ignbithints != -1) { - r_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); + rz_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); } free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_bits_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); @@ -5357,14 +5357,14 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_bits_command) { char *tmpbits; int cmd_ignbithints; - int bits = r_num_math (core->num, arg_str); + int bits = rz_num_math (core->num, arg_str); set_tmp_bits (core, bits, &tmpbits, &cmd_ignbithints); - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); - r_config_set (core->config, "asm.bits", tmpbits); + rz_config_set (core->config, "asm.bits", tmpbits); core->fixedbits = oldfixedbits; - r_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); + rz_config_set_i (core->config, "anal.ignbithints", cmd_ignbithints); free (tmpbits); free (arg_str); @@ -5372,14 +5372,14 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_bits_command) { } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_nthi_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); ut64 orig_offset = state->core->offset; - int index = r_num_math (core->num, arg_str); - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, core->offset); + int index = rz_num_math (core->num, arg_str); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, core->offset); if (bb) { // handle negative indices if (index < 0) { @@ -5387,8 +5387,8 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_nthi_command) { } if (index >= 0 && index < bb->ninstr) { - ut16 inst_off = r_anal_bb_offset_inst (bb, index); - r_core_seek (core, bb->addr + inst_off, true); + ut16 inst_off = rz_anal_bb_offset_inst (bb, index); + rz_core_seek (core, bb->addr + inst_off, true); } else { eprintf ("The current basic block has just %d instructions\n", bb->ninstr); } @@ -5396,9 +5396,9 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_nthi_command) { eprintf ("Can't find a basic block for 0x%08" PFMT64x "\n", core->offset); } - RCmdStatus res = handle_ts_command_tmpseek (state, command); + RzCmdStatus res = handle_ts_command_tmpseek (state, command); - r_core_seek (core, orig_offset, true); + rz_core_seek (core, orig_offset, true); free (arg_str); return res; @@ -5406,11 +5406,11 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_nthi_command) { DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_eval_command) { // TODO: support cmd_substitution in tmp_eval_args - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode args = ts_node_named_child (node, 1); - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); uint32_t i, n_args = ts_node_named_child_count (args); for (i = 0; i < n_args; i++) { TSNode arg = ts_node_named_child (args, i); @@ -5418,122 +5418,122 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_eval_command) { char *eq = strchr (arg_str, '='); if (eq) { *eq = 0; - r_config_hold_s (hc, arg_str, NULL); - r_config_set (core->config, arg_str, eq + 1); + rz_config_hold_s (hc, arg_str, NULL); + rz_config_set (core->config, arg_str, eq + 1); } else { eprintf ("Missing '=' in e: expression (%s)\n", arg_str); } free (arg_str); } - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_fs_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); - r_flag_space_push (core->flags, arg_str); - RCmdStatus res = handle_ts_command (state, command); - r_flag_space_pop (core->flags); + rz_flag_space_push (core->flags, arg_str); + RzCmdStatus res = handle_ts_command (state, command); + rz_flag_space_pop (core->flags); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_reli_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); ut64 orig_offset = state->core->offset; - ut64 addr = r_num_math (core->num, arg_str); + ut64 addr = rz_num_math (core->num, arg_str); if (addr) { - r_core_cmdf (core, "so %" PFMT64d, addr); + rz_core_cmdf (core, "so %" PFMT64d, addr); } - RCmdStatus res = handle_ts_command_tmpseek (state, command); - r_core_seek (state->core, orig_offset, true); + RzCmdStatus res = handle_ts_command_tmpseek (state, command); + rz_core_seek (state->core, orig_offset, true); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_kuery_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); ut64 orig_offset = state->core->offset; char *out = sdb_querys (core->sdb, NULL, 0, arg_str); if (out) { - r_core_seek (core, r_num_math(core->num, out), true); + rz_core_seek (core, rz_num_math(core->num, out), true); free (out); } - RCmdStatus res = handle_ts_command_tmpseek (state, command); - r_core_seek (state->core, orig_offset, true); + RzCmdStatus res = handle_ts_command_tmpseek (state, command); + rz_core_seek (state->core, orig_offset, true); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_fd_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); int tmpfd = core->io->desc? core->io->desc->fd: -1; - r_io_use_fd (core->io, atoi (arg_str)); - RCmdStatus res = handle_ts_command (state, command); - r_io_use_fd (core->io, tmpfd); + rz_io_use_fd (core->io, atoi (arg_str)); + RzCmdStatus res = handle_ts_command (state, command); + rz_io_use_fd (core->io, tmpfd); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_reg_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); ut64 orig_offset = state->core->offset; // TODO: add support for operations (e.g. @r:PC+10) - ut64 regval = r_debug_reg_get (core->dbg, arg_str); - r_core_seek (core, regval, true); - RCmdStatus res = handle_ts_command_tmpseek (state, command); - r_core_seek (core, orig_offset, true); + ut64 regval = rz_debug_reg_get (core->dbg, arg_str); + rz_core_seek (core, regval, true); + RzCmdStatus res = handle_ts_command_tmpseek (state, command); + rz_core_seek (core, orig_offset, true); free (arg_str); return res; } static bool handle_tmp_desc(struct tsr2cmd_state *state, TSNode command, const ut8 *buf, int sz) { - RCore *core = state->core; + RzCore *core = state->core; int pamode = !core->io->va; - RCmdStatus res = R_CMD_STATUS_INVALID, o_fixedblock = core->fixedblock; - RBuffer *b = r_buf_new_with_bytes (buf, sz); - RIODesc *d = r_io_open_buffer (core->io, b, R_PERM_RWX, 0); + RzCmdStatus res = R_CMD_STATUS_INVALID, o_fixedblock = core->fixedblock; + RBuffer *b = rz_buf_new_with_bytes (buf, sz); + RzIODesc *d = rz_io_open_buffer (core->io, b, R_PERM_RWX, 0); if (!d) { eprintf ("Cannot open io buffer\n"); goto out_buf; } if (pamode) { - r_config_set_i (core->config, "io.va", 1); + rz_config_set_i (core->config, "io.va", 1); } - r_io_map_new (core->io, d->fd, d->perm, 0, core->offset, r_buf_size (b)); - r_core_block_size (core, r_buf_size (b)); + rz_io_map_new (core->io, d->fd, d->perm, 0, core->offset, rz_buf_size (b)); + rz_core_block_size (core, rz_buf_size (b)); core->fixedblock = true; - r_core_block_read (core); + rz_core_block_read (core); res = handle_ts_command (state, command); core->fixedblock = o_fixedblock; if (pamode) { - r_config_set_i (core->config, "io.va", 0); + rz_config_set_i (core->config, "io.va", 0); } - r_io_desc_close (d); + rz_io_desc_close (d); out_buf: - r_buf_free (b); + rz_buf_free (b); return res; } @@ -5542,9 +5542,9 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_file_command) { TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); size_t sz; - RCmdStatus res = R_CMD_STATUS_INVALID; + RzCmdStatus res = R_CMD_STATUS_INVALID; - char *f = r_file_slurp (arg_str, &sz); + char *f = rz_file_slurp (arg_str, &sz); if (!f) { eprintf ("Cannot open '%s'\n", arg_str); goto out; @@ -5567,7 +5567,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_string_command) { sz = strlen (arg_str); const ut8 *buf = (const ut8 *)arg_str; - RCmdStatus res = handle_tmp_desc (state, command, buf, sz); + RzCmdStatus res = handle_tmp_desc (state, command, buf, sz); free (arg_str); return res; @@ -5581,9 +5581,9 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_hex_command) { size_t len = strlen (arg_str); ut8 *buf = R_NEWS (ut8, len + 1); - sz = r_hex_str2bin (arg_str, buf); + sz = rz_hex_str2bin (arg_str, buf); - RCmdStatus res = handle_tmp_desc (state, command, buf, sz); + RzCmdStatus res = handle_tmp_desc (state, command, buf, sz); free (buf); free (arg_str); @@ -5591,15 +5591,15 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(tmp_hex_command) { } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_flags_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg(state, node, arg, 1); - const RSpace *flagspace = r_flag_space_cur (core->flags); - RFlagItem *flag; - RListIter *iter; - RCmdStatus ret = R_CMD_STATUS_OK; - RList *match_flag_items = r_list_newf ((RListFree)r_flag_item_free); + const RSpace *flagspace = rz_flag_space_cur (core->flags); + RzFlagItem *flag; + RzListIter *iter; + RzCmdStatus ret = R_CMD_STATUS_OK; + RzList *match_flag_items = rz_list_newf ((RzListFree)rz_flag_item_free); if (!match_flag_items) { return R_CMD_STATUS_OK; } @@ -5611,31 +5611,31 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_flags_command) { .ret = match_flag_items, .word = arg_str, }; - r_flag_foreach_space (core->flags, flagspace, duplicate_flag, &u); + rz_flag_foreach_space (core->flags, flagspace, duplicate_flag, &u); /* for all flags that match */ - r_list_foreach (match_flag_items, iter, flag) { - if (r_cons_is_breaked ()) { + rz_list_foreach (match_flag_items, iter, flag) { + if (rz_cons_is_breaked ()) { break; } char *buf = NULL; const char *tmp = NULL; R_LOG_DEBUG ("iter_flags_command: seek to %" PFMT64x "\n", flag->offset); - r_core_seek (core, flag->offset, true); - r_cons_push (); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - tmp = r_cons_get_buffer (); + rz_core_seek (core, flag->offset, true); + rz_cons_push (); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + tmp = rz_cons_get_buffer (); buf = tmp? strdup (tmp): NULL; - r_cons_pop (); - r_cons_strcat (buf); + rz_cons_pop (); + rz_cons_strcat (buf); free (buf); - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); UPDATE_CMD_STATUS_RES (ret, cmd_res, err); } err: - r_list_free (match_flag_items); + rz_list_free (match_flag_items); free (arg_str); return ret; } @@ -5647,36 +5647,36 @@ enum dbt_commands_mode { }; static bool iter_dbt_commands(struct tsr2cmd_state *state, TSNode node, enum dbt_commands_mode mode) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RList *list = r_debug_frames (core->dbg, UT64_MAX); + RzList *list = rz_debug_frames (core->dbg, UT64_MAX); ut64 orig_offset = core->offset; - RDebugFrame *frame; - RListIter *iter; - RCmdStatus res = R_CMD_STATUS_OK; + RzDebugFrame *frame; + RzListIter *iter; + RzCmdStatus res = R_CMD_STATUS_OK; - r_list_foreach (list, iter, frame) { + rz_list_foreach (list, iter, frame) { switch (mode) { case DBT_COMMANDS_MODE_ADDR: - r_core_seek (core, frame->addr, true); + rz_core_seek (core, frame->addr, true); break; case DBT_COMMANDS_MODE_SP: - r_core_seek (core, frame->sp, true); + rz_core_seek (core, frame->sp, true); break; case DBT_COMMANDS_MODE_BP: - r_core_seek (core, frame->bp, true); + rz_core_seek (core, frame->bp, true); break; default: - r_warn_if_reached (); + rz_warn_if_reached (); return R_CMD_STATUS_INVALID; } - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - r_cons_newline (); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_cons_newline (); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_seek (core, orig_offset, true); - r_list_free (list); + rz_core_seek (core, orig_offset, true); + rz_list_free (list); return res; } @@ -5694,13 +5694,13 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_dbts_command) { DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_file_lines_command) { // TODO: old implementation has some unknown check on '(' - RCore *core = state->core; - RCmdStatus res = R_CMD_STATUS_OK; + RzCore *core = state->core; + RzCmdStatus res = R_CMD_STATUS_OK; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg(state, node, arg, 1); ut64 orig_offset = core->offset; - FILE *fd = r_sandbox_fopen (arg_str, "r"); + FILE *fd = rz_sandbox_fopen (arg_str, "r"); if (!fd) { res = R_CMD_STATUS_INVALID; goto arg_out; @@ -5713,14 +5713,14 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_file_lines_command) { if (!fgets (buf, sizeof (buf), fd)) { break; } - ut64 addr = r_num_math (core->num, buf); - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + ut64 addr = rz_num_math (core->num, buf); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); core->rcmd->macro.counter++; UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_seek (core, orig_offset, true); + rz_core_seek (core, orig_offset, true); fclose (fd); arg_out: @@ -5729,8 +5729,8 @@ arg_out: } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_offsets_command) { - RCore *core = state->core; - RCmdStatus res = R_CMD_STATUS_OK; + RzCore *core = state->core; + RzCmdStatus res = R_CMD_STATUS_OK; TSNode command = ts_node_named_child (node, 0); if (ts_node_named_child_count (node) < 2) { // no offsets provided, all's good. @@ -5740,7 +5740,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_offsets_command) { TSNode args = ts_node_named_child (node, 1); ut64 orig_offset = core->offset; - RCmdParsedArgs *a = ts_node_handle_arg_prargs (state, node, args, 1, true); + RzCmdParsedArgs *a = ts_node_handle_arg_prargs (state, node, args, 1, true); if (!a) { R_LOG_ERROR ("Cannot parse args\n"); return R_CMD_STATUS_INVALID; @@ -5748,23 +5748,23 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_offsets_command) { const char *s; int i; - r_cmd_parsed_args_foreach_arg (a, i, s) { - ut64 addr = r_num_math (core->num, s); + rz_cmd_parsed_args_foreach_arg (a, i, s) { + ut64 addr = rz_num_math (core->num, s); R_LOG_DEBUG ("iter_offsets_command: seek to %" PFMT64x "\n", addr); - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - r_cons_flush (); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_cons_flush (); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_seek (core, orig_offset, true); - r_cmd_parsed_args_free (a); + rz_core_seek (core, orig_offset, true); + rz_cmd_parsed_args_free (a); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_sdbquery_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = ts_node_handle_arg (state, node, arg, 1); @@ -5776,7 +5776,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_sdbquery_command) { } char *str, *each = out; ut64 addr; - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; do { while (*each == ' ') { each++; @@ -5787,110 +5787,110 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_sdbquery_command) { str = strchr (each, ' '); if (str) { *str = '\0'; - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); *str = ' '; } else { - addr = r_num_math (core->num, each); + addr = rz_num_math (core->num, each); } each = str + 1; - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - r_cons_flush (); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_cons_flush (); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } while (str != NULL); err: - r_core_seek (core, orig_offset, true); + rz_core_seek (core, orig_offset, true); free (out); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_threads_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); int pid = core->dbg->pid; if (!core->dbg->h || !core->dbg->h->pids) { return R_CMD_STATUS_INVALID; } - RCmdStatus res = R_CMD_STATUS_OK; - RList *list = core->dbg->h->pids (core->dbg, R_MAX (0, pid)); - RListIter *iter; - RDebugPid *p; - r_list_foreach (list, iter, p) { - r_cons_printf ("# PID %d\n", p->pid); - r_debug_select (core->dbg, p->pid, p->pid); - RCmdStatus cmd_res = handle_ts_command (state, command); + RzCmdStatus res = R_CMD_STATUS_OK; + RzList *list = core->dbg->h->pids (core->dbg, R_MAX (0, pid)); + RzListIter *iter; + RzDebugPid *p; + rz_list_foreach (list, iter, p) { + rz_cons_printf ("# PID %d\n", p->pid); + rz_debug_select (core->dbg, p->pid, p->pid); + RzCmdStatus cmd_res = handle_ts_command (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); - r_cons_newline (); + rz_cons_newline (); } err: - r_list_free (list); - r_debug_select (core->dbg, pid, pid); + rz_list_free (list); + rz_debug_select (core->dbg, pid, pid); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_bbs_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RListIter *iter; - RAnalBlock *bb; + RzListIter *iter; + RzAnalBlock *bb; int bs = core->blocksize; ut64 orig_offset = core->offset; - RCmdStatus res = R_CMD_STATUS_OK; - RAnalFunction *fcn = r_anal_get_function_at (core->anal, core->offset); + RzCmdStatus res = R_CMD_STATUS_OK; + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, core->offset); if (!fcn) { eprintf ("No function at current address\n"); return R_CMD_STATUS_INVALID; } - r_list_sort (fcn->bbs, bb_cmp); - r_list_foreach (fcn->bbs, iter, bb) { - r_core_block_size (core, bb->size); - r_core_seek (core, bb->addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_list_sort (fcn->bbs, bb_cmp); + rz_list_foreach (fcn->bbs, iter, bb) { + rz_core_block_size (core, bb->size); + rz_core_seek (core, bb->addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } err: - r_core_block_size (core, bs); - r_core_seek (core, orig_offset, true); + rz_core_block_size (core, bs); + rz_core_seek (core, orig_offset, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_instrs_command) { TSNode command = ts_node_named_child (node, 0); - RCore *core = state->core; - RListIter *iter; - RAnalBlock *bb; + RzCore *core = state->core; + RzListIter *iter; + RzAnalBlock *bb; int i; - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; ut64 orig_offset = core->offset; int bs = core->blocksize; - RAnalFunction *fcn = r_anal_get_function_at (core->anal, core->offset); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, core->offset); if (!fcn) { eprintf ("No function at current address\n"); return R_CMD_STATUS_INVALID; } - r_list_sort (fcn->bbs, bb_cmp); - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_sort (fcn->bbs, bb_cmp); + rz_list_foreach (fcn->bbs, iter, bb) { for (i = 0; i < bb->ninstr; i++) { - ut64 addr = bb->addr + r_anal_bb_offset_inst (bb, i); - int sz = r_anal_bb_size_i (bb, i); - r_core_block_size (core, sz); - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + ut64 addr = bb->addr + rz_anal_bb_offset_inst (bb, i); + int sz = rz_anal_bb_size_i (bb, i); + rz_core_block_size (core, sz); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } } err: - r_core_block_size (core, bs); - r_core_seek (core, orig_offset, true); + rz_core_block_size (core, bs); + rz_core_seek (core, orig_offset, true); return res; } @@ -5898,42 +5898,42 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_functions_command) { TSNode command = ts_node_named_child (node, 0); TSNode arg = ts_node_named_child (node, 1); char *arg_str = NULL; - RCore *core = state->core; - RCmdStatus res = R_CMD_STATUS_OK; + RzCore *core = state->core; + RzCmdStatus res = R_CMD_STATUS_OK; ut64 orig_offset = core->offset; int bs = core->blocksize; - RAnalFunction *fcn; - RListIter *iter; + RzAnalFunction *fcn; + RzListIter *iter; if (!ts_node_is_null (arg)) { arg_str = ts_node_handle_arg (state, node, arg, 1); } - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { if (arg_str && !strstr (fcn->name, arg_str)) { continue; } char *buf; - r_core_block_size (core, r_anal_function_linear_size (fcn)); - r_core_seek (core, fcn->addr, true); - r_cons_push (); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - buf = (char *)r_cons_get_buffer (); + rz_core_block_size (core, rz_anal_function_linear_size (fcn)); + rz_core_seek (core, fcn->addr, true); + rz_cons_push (); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + buf = (char *)rz_cons_get_buffer (); if (buf) { buf = strdup (buf); } - r_cons_pop (); - r_cons_strcat (buf); + rz_cons_pop (); + rz_cons_strcat (buf); free (buf); UPDATE_CMD_STATUS_RES (res, cmd_res, err); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } err: - r_core_block_size (core, bs); - r_core_seek (core, orig_offset, true); + rz_core_block_size (core, bs); + rz_core_seek (core, orig_offset, true); free (arg_str); return res; } @@ -5943,110 +5943,110 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_step_command) { TSNode from_n = ts_node_named_child (node, 1); TSNode to_n = ts_node_named_child (node, 2); TSNode step_n = ts_node_named_child (node, 3); - RCore *core = state->core; - RCmdStatus res = R_CMD_STATUS_OK; + RzCore *core = state->core; + RzCmdStatus res = R_CMD_STATUS_OK; ut64 orig_offset = core->offset; int bs = core->blocksize; char *from_str = ts_node_handle_arg (state, node, from_n, 1); char *to_str = ts_node_handle_arg (state, node, to_n, 2); char *step_str = ts_node_handle_arg (state, node, step_n, 3); - ut64 from = r_num_math (core->num, from_str); - ut64 to = r_num_math (core->num, to_str); - ut64 step = r_num_math (core->num, step_str); + ut64 from = rz_num_math (core->num, from_str); + ut64 to = rz_num_math (core->num, to_str); + ut64 step = rz_num_math (core->num, step_str); free (from_str); free (to_str); free (step_str); ut64 cur; for (cur = from; cur <= to; cur += step) { - r_core_seek (core, cur, true); - r_core_block_size (core, step); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_core_seek (core, cur, true); + rz_core_block_size (core, step); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } err: - r_core_block_size (core, bs); - r_core_seek (core, orig_offset, true); + rz_core_block_size (core, bs); + rz_core_seek (core, orig_offset, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_interpret_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode in_cmd = ts_node_named_child (node, 1); substitute_args_init (state, node); - RList *edits = r_list_newf ((RListFree)free_tsr2cmd_edit); + RzList *edits = rz_list_newf ((RzListFree)free_tsr2cmd_edit); char *in_cmd_out = do_handle_substitution_cmd (state, in_cmd); in_cmd_out = escape_special_chars (in_cmd_out, SPECIAL_CHARS_REGULAR); struct tsr2cmd_edit *e = create_cmd_edit (state, in_cmd, in_cmd_out); - r_list_append (edits, e); + rz_list_append (edits, e); TSNode op = ts_node_child (node, 1); e = create_cmd_edit (state, op, strdup ("@@=")); - r_list_append (edits, e); + rz_list_append (edits, e); TSNode new_command; bool ok = substitute_args_do (state, edits, &new_command); if (!ok) { - r_list_free (edits); + rz_list_free (edits); substitute_args_fini (state); return R_CMD_STATUS_INVALID; } TSNode args = ts_node_named_child (new_command, 1); - RCmdParsedArgs *a = parse_args (state, args, true); + RzCmdParsedArgs *a = parse_args (state, args, true); if (!a) { - r_list_free (edits); + rz_list_free (edits); substitute_args_fini (state); return R_CMD_STATUS_INVALID; } - r_list_free (edits); + rz_list_free (edits); substitute_args_fini (state); const char *s; int i; ut64 orig_offset = core->offset; - RCmdStatus res = R_CMD_STATUS_OK; - r_cmd_parsed_args_foreach_arg (a, i, s) { - ut64 addr = r_num_math (core->num, s); + RzCmdStatus res = R_CMD_STATUS_OK; + rz_cmd_parsed_args_foreach_arg (a, i, s) { + ut64 addr = rz_num_math (core->num, s); R_LOG_DEBUG ("iter_interpret_command: seek to %" PFMT64x "\n", addr); - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); - r_cons_flush (); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_cons_flush (); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_seek (core, orig_offset, true); - r_cmd_parsed_args_free (a); + rz_core_seek (core, orig_offset, true); + rz_cmd_parsed_args_free (a); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(iter_hit_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode search_cmd = ts_node_named_child (node, 1); char *command_str = ts_node_sub_string (command, state->input); - char *cmdhit = strdup (r_config_get (core->config, "cmd.hit")); - r_config_set (core->config, "cmd.hit", command_str); - RCmdStatus res = handle_ts_command (state, search_cmd); - r_config_set (core->config, "cmd.hit", cmdhit); + char *cmdhit = strdup (rz_config_get (core->config, "cmd.hit")); + rz_config_set (core->config, "cmd.hit", command_str); + RzCmdStatus res = handle_ts_command (state, search_cmd); + rz_config_set (core->config, "cmd.hit", cmdhit); free (command_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_addrsize_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); uint32_t i = 1; - RCmdStatus ret = R_CMD_STATUS_OK; + RzCmdStatus ret = R_CMD_STATUS_OK; TSNode seek_addr_node = ts_node_named_child (node, i); TSNode blk_sz_node = ts_node_named_child (node, i + 1); ut64 orig_offset = core->offset; @@ -6054,46 +6054,46 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_addrsize_command) { while (!ts_node_is_null (seek_addr_node)) { char *seek_addr_str = ts_node_handle_arg (state, node, seek_addr_node, i); char *blk_sz_str = ts_node_handle_arg (state, node, blk_sz_node, i + 1); - ut64 seek_addr_val = r_num_get (core->num, seek_addr_str); - ut64 blk_sz_val = r_num_get (core->num, blk_sz_str); + ut64 seek_addr_val = rz_num_get (core->num, seek_addr_str); + ut64 blk_sz_val = rz_num_get (core->num, blk_sz_str); free (seek_addr_str); free (blk_sz_str); - r_core_seek (core, seek_addr_val, true); - r_core_block_size (core, blk_sz_val); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_core_seek (core, seek_addr_val, true); + rz_core_block_size (core, blk_sz_val); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (ret, cmd_res, err); i += 2; seek_addr_node = ts_node_named_child (node, i); blk_sz_node = ts_node_named_child (node, i + 1); } err: - r_core_block_size (core, orig_blksz); - r_core_seek (core, orig_offset, true); + rz_core_block_size (core, orig_blksz); + rz_core_seek (core, orig_offset, true); return ret; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_bb_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); ut64 offorig = core->offset; ut64 obs = core->blocksize; if (!fcn) { return R_CMD_STATUS_INVALID; } - RListIter *iter; - RAnalBlock *bb; - RCmdStatus ret = R_CMD_STATUS_OK; - r_list_foreach (fcn->bbs, iter, bb) { - r_core_seek (core, bb->addr, true); - r_core_block_size (core, bb->size); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + RzListIter *iter; + RzAnalBlock *bb; + RzCmdStatus ret = R_CMD_STATUS_OK; + rz_list_foreach (fcn->bbs, iter, bb) { + rz_core_seek (core, bb->addr, true); + rz_core_block_size (core, bb->size); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (ret, cmd_res, err); } err: - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); return ret; } @@ -6103,7 +6103,7 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_cmd_command) { TSNode in_cmd = ts_node_named_child (node, 1); substitute_args_init (state, node); - RList *edits = r_list_newf ((RListFree)free_tsr2cmd_edit); + RzList *edits = rz_list_newf ((RzListFree)free_tsr2cmd_edit); if (!edits) { substitute_args_fini (state); return R_CMD_STATUS_INVALID; @@ -6112,244 +6112,244 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_cmd_command) { char *in_cmd_out = do_handle_substitution_cmd (state, in_cmd); in_cmd_out = escape_special_chars (in_cmd_out, SPECIAL_CHARS_REGULAR); struct tsr2cmd_edit *e = create_cmd_edit (state, in_cmd, in_cmd_out); - r_list_append (edits, e); + rz_list_append (edits, e); TSNode op = ts_node_child (node, 1); e = create_cmd_edit (state, op, strdup ("@@@=")); - r_list_append (edits, e); + rz_list_append (edits, e); TSNode new_command; if (!substitute_args_do (state, edits, &new_command)) { - r_list_free (edits); + rz_list_free (edits); substitute_args_fini (state); return R_CMD_STATUS_INVALID; } - RCmdStatus res = handle_ts_command (state, new_command); - r_list_free (edits); + RzCmdStatus res = handle_ts_command (state, new_command); + rz_list_free (edits); substitute_args_fini (state); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_comment_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode filter_node = ts_node_named_child (node, 1); char *glob = !ts_node_is_null (filter_node) ? ts_node_sub_string (filter_node, state->input) : NULL; ut64 off = core->offset; - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; RIntervalTreeIter it; - RAnalMetaItem *meta; - r_interval_tree_foreach (&core->anal->meta, it, meta) { + RzAnalMetaItem *meta; + rz_interval_tree_foreach (&core->anal->meta, it, meta) { if (meta->type != R_META_TYPE_COMMENT) { continue; } - if (!glob || (meta->str && r_str_glob (meta->str, glob))) { - r_core_seek (core, r_interval_tree_iter_get (&it)->start, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + if (!glob || (meta->str && rz_str_glob (meta->str, glob))) { + rz_core_seek (core, rz_interval_tree_iter_get (&it)->start, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } } err: - r_core_seek (core, off, false); + rz_core_seek (core, off, false); free (glob); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_import_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); RBinImport *imp; ut64 offorig = core->offset; - RList *list = r_bin_get_imports (core->bin); + RzList *list = rz_bin_get_imports (core->bin); if (!list) { return R_CMD_STATUS_OK; } - RList *lost = r_list_newf (free); - RListIter *iter; - r_list_foreach (list, iter, imp) { - char *impflag = r_str_newf ("sym.imp.%s", imp->name); - ut64 addr = r_num_math (core->num, impflag); + RzList *lost = rz_list_newf (free); + RzListIter *iter; + rz_list_foreach (list, iter, imp) { + char *impflag = rz_str_newf ("sym.imp.%s", imp->name); + ut64 addr = rz_num_math (core->num, impflag); ut64 *n = R_NEW (ut64); *n = addr; - r_list_append (lost, n); + rz_list_append (lost, n); free (impflag); } ut64 *naddr; - RCmdStatus res = R_CMD_STATUS_OK; - r_list_foreach (lost, iter, naddr) { + RzCmdStatus res = R_CMD_STATUS_OK; + rz_list_foreach (lost, iter, naddr) { ut64 addr = *naddr; if (addr && addr != UT64_MAX) { - r_core_seek (core, addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_core_seek (core, addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } } err: - r_core_seek (core, offorig, true); - r_list_free (lost); + rz_core_seek (core, offorig, true); + rz_list_free (lost); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_register_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); ut64 offorig = core->offset; int i; - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegItem *item; + RzRegItem *item; ut64 value; - RList *head = r_reg_get_list (core->dbg->reg, i); + RzList *head = rz_reg_get_list (core->dbg->reg, i); if (!head) { continue; } - RList *list = r_list_newf (free); - RListIter *iter; - r_list_foreach (head, iter, item) { + RzList *list = rz_list_newf (free); + RzListIter *iter; + rz_list_foreach (head, iter, item) { if (item->size != core->anal->bits) { continue; } if (item->type != i) { continue; } - r_list_append (list, strdup (item->name)); + rz_list_append (list, strdup (item->name)); } const char *item_name; - r_list_foreach (list, iter, item_name) { - value = r_reg_getv (core->dbg->reg, item_name); - r_core_seek (core, value, true); - r_cons_printf ("%s: ", item_name); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_list_foreach (list, iter, item_name) { + value = rz_reg_getv (core->dbg->reg, item_name); + rz_core_seek (core, value, true); + rz_cons_printf ("%s: ", item_name); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_list_free (list); + rz_list_free (list); } - r_core_seek (core, offorig, true); + rz_core_seek (core, offorig, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_symbol_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); RBinSymbol *sym; ut64 offorig = core->offset; ut64 obs = core->blocksize; - RList *list = r_bin_get_symbols (core->bin); - RListIter *iter; - r_cons_break_push (NULL, NULL); - RList *lost = r_list_newf (free); - r_list_foreach (list, iter, sym) { - RBinSymbol *bs = r_mem_dup (sym, sizeof (RBinSymbol)); - r_list_append (lost, bs); + RzList *list = rz_bin_get_symbols (core->bin); + RzListIter *iter; + rz_cons_break_push (NULL, NULL); + RzList *lost = rz_list_newf (free); + rz_list_foreach (list, iter, sym) { + RBinSymbol *bs = rz_mem_dup (sym, sizeof (RBinSymbol)); + rz_list_append (lost, bs); } - RCmdStatus res = R_CMD_STATUS_OK; - r_list_foreach (lost, iter, sym) { - if (r_cons_is_breaked ()) { + RzCmdStatus res = R_CMD_STATUS_OK; + rz_list_foreach (lost, iter, sym) { + if (rz_cons_is_breaked ()) { break; } - r_core_block_size (core, sym->size); - r_core_seek (core, sym->vaddr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_core_block_size (core, sym->size); + rz_core_seek (core, sym->vaddr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_cons_break_pop (); - r_list_free (lost); - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_cons_break_pop (); + rz_list_free (lost); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_string_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RList *list = r_bin_get_strings (core->bin); - RCmdStatus res = R_CMD_STATUS_OK; + RzList *list = rz_bin_get_strings (core->bin); + RzCmdStatus res = R_CMD_STATUS_OK; if (list) { ut64 offorig = core->offset; ut64 obs = core->blocksize; RBinString *s; - RList *lost = r_list_newf (free); - RListIter *iter; - r_list_foreach (list, iter, s) { - RBinString *bs = r_mem_dup (s, sizeof (RBinString)); - r_list_append (lost, bs); + RzList *lost = rz_list_newf (free); + RzListIter *iter; + rz_list_foreach (list, iter, s) { + RBinString *bs = rz_mem_dup (s, sizeof (RBinString)); + rz_list_append (lost, bs); } - r_list_foreach (lost, iter, s) { - r_core_block_size (core, s->size); - r_core_seek (core, s->vaddr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + rz_list_foreach (lost, iter, s) { + rz_core_block_size (core, s->size); + rz_core_seek (core, s->vaddr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); - r_list_free (lost); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); + rz_list_free (lost); } return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_section_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (!obj) { return false; } - RCmdStatus res = R_CMD_STATUS_OK; + RzCmdStatus res = R_CMD_STATUS_OK; ut64 offorig = core->offset; ut64 bszorig = core->blocksize; RBinSection *sec; - RListIter *iter; - r_list_foreach (obj->sections, iter, sec) { - r_core_seek (core, sec->vaddr, true); - r_core_block_size (core, sec->vsize); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + RzListIter *iter; + rz_list_foreach (obj->sections, iter, sec) { + rz_core_seek (core, sec->vaddr, true); + rz_core_block_size (core, sec->vsize); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_block_size (core, bszorig); - r_core_seek (core, offorig, true); + rz_core_block_size (core, bszorig); + rz_core_seek (core, offorig, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_iomap_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - int fd = r_io_fd_get_current (core->io); + int fd = rz_io_fd_get_current (core->io); // only iterate maps of current fd - RList *maps = r_io_map_get_for_fd (core->io, fd); - RIOMap *map; - RCmdStatus res = R_CMD_STATUS_OK; + RzList *maps = rz_io_map_get_for_fd (core->io, fd); + RzIOMap *map; + RzCmdStatus res = R_CMD_STATUS_OK; if (maps) { - RListIter *iter; - r_list_foreach (maps, iter, map) { - r_core_seek (core, map->itv.addr, true); - r_core_block_size (core, map->itv.size); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + RzListIter *iter; + rz_list_foreach (maps, iter, map) { + rz_core_seek (core, map->itv.addr, true); + rz_core_block_size (core, map->itv.size); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_list_free (maps); + rz_list_free (maps); } return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_dbgmap_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RDebug *dbg = core->dbg; - RCmdStatus res = R_CMD_STATUS_OK; + RzDebug *dbg = core->dbg; + RzCmdStatus res = R_CMD_STATUS_OK; if (dbg && dbg->h && dbg->maps) { - RDebugMap *map; - RListIter *iter; - r_list_foreach (dbg->maps, iter, map) { - r_core_seek (core, map->addr, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + RzDebugMap *map; + RzListIter *iter; + rz_list_foreach (dbg->maps, iter, map) { + rz_core_seek (core, map->addr, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } } @@ -6358,7 +6358,7 @@ err: } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_flag_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode filter_node = ts_node_named_child (node, 1); char *glob = NULL; @@ -6367,26 +6367,26 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_flag_command) { } ut64 off = core->offset; ut64 obs = core->blocksize; - RList *flags = r_list_newf (free); - r_flag_foreach_glob (core->flags, glob, copy_into_flagitem_list, flags); - RListIter *iter; - RFlagItem *f; - RCmdStatus res = R_CMD_STATUS_OK; - r_list_foreach (flags, iter, f) { - r_core_block_size (core, f->size); - r_core_seek (core, f->offset, true); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + RzList *flags = rz_list_newf (free); + rz_flag_foreach_glob (core->flags, glob, copy_into_flagitem_list, flags); + RzListIter *iter; + RzFlagItem *f; + RzCmdStatus res = R_CMD_STATUS_OK; + rz_list_foreach (flags, iter, f) { + rz_core_block_size (core, f->size); + rz_core_seek (core, f->offset, true); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_core_seek (core, off, false); - r_core_block_size (core, obs); + rz_core_seek (core, off, false); + rz_core_block_size (core, obs); free (glob); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_function_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); TSNode filter_node = ts_node_named_child (node, 1); char *filter = NULL; @@ -6395,51 +6395,51 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_function_command) { } ut64 obs = core->blocksize; ut64 offorig = core->offset; - RAnalFunction *fcn; - RList *list = core->anal->fcns; - RListIter *iter; - RCmdStatus res = R_CMD_STATUS_OK; - r_cons_break_push (NULL, NULL); - r_list_foreach (list, iter, fcn) { - if (r_cons_is_breaked ()) { + RzAnalFunction *fcn; + RzList *list = core->anal->fcns; + RzListIter *iter; + RzCmdStatus res = R_CMD_STATUS_OK; + rz_cons_break_push (NULL, NULL); + rz_list_foreach (list, iter, fcn) { + if (rz_cons_is_breaked ()) { break; } - if (!filter || r_str_glob (fcn->name, filter)) { - r_core_seek (core, fcn->addr, true); - r_core_block_size (core, r_anal_function_linear_size (fcn)); - RCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); + if (!filter || rz_str_glob (fcn->name, filter)) { + rz_core_seek (core, fcn->addr, true); + rz_core_block_size (core, rz_anal_function_linear_size (fcn)); + RzCmdStatus cmd_res = handle_ts_command_tmpseek (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } } err: - r_cons_break_pop (); - r_core_block_size (core, obs); - r_core_seek (core, offorig, true); + rz_cons_break_pop (); + rz_core_block_size (core, obs); + rz_core_seek (core, offorig, true); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_thread_command) { - RCore *core = state->core; + RzCore *core = state->core; TSNode command = ts_node_named_child (node, 0); - RDebug *dbg = core->dbg; - RCmdStatus res = R_CMD_STATUS_OK; + RzDebug *dbg = core->dbg; + RzCmdStatus res = R_CMD_STATUS_OK; if (dbg && dbg->h && dbg->h->threads) { int origtid = dbg->tid; - RDebugPid *p; - RList *list = dbg->h->threads (dbg, dbg->pid); + RzDebugPid *p; + RzList *list = dbg->h->threads (dbg, dbg->pid); if (!list) { return R_CMD_STATUS_INVALID; } - RListIter *iter; - r_list_foreach (list, iter, p) { - r_debug_select (dbg, dbg->pid, p->pid); - r_cons_printf ("PID %d\n", p->pid); - RCmdStatus cmd_res = handle_ts_command (state, command); + RzListIter *iter; + rz_list_foreach (list, iter, p) { + rz_debug_select (dbg, dbg->pid, p->pid); + rz_cons_printf ("PID %d\n", p->pid); + RzCmdStatus cmd_res = handle_ts_command (state, command); UPDATE_CMD_STATUS_RES (res, cmd_res, err); } err: - r_debug_select (dbg, dbg->pid, origtid); - r_list_free (list); + rz_debug_select (dbg, dbg->pid, origtid); + rz_list_free (list); } return res; } @@ -6447,14 +6447,14 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(foreach_thread_command) { DEFINE_HANDLE_TS_FCN_AND_SYMBOL(last_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); char *command_str = ts_node_sub_string (command, state->input); - RCmdStatus res = R_CMD_STATUS_INVALID; + RzCmdStatus res = R_CMD_STATUS_INVALID; state->is_last_cmd = true; if (!strcmp (command_str, ".")) { res = lastcmd_repeat (state->core, 0); } else if (!strcmp (command_str, "...")) { res = lastcmd_repeat (state->core, 1); } else { - r_warn_if_reached (); + rz_warn_if_reached (); } free (command_str); return res; @@ -6464,57 +6464,57 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(grep_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); TSNode arg = ts_node_child_by_field_name (node, "specifier", strlen ("specifier")); char *arg_str = ts_node_handle_arg (state, node, arg, 1); - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); R_LOG_DEBUG ("grep_command specifier: '%s'\n", arg_str); - RStrBuf *sb = r_strbuf_new (arg_str); - r_strbuf_prepend (sb, "~"); - char *specifier_str = r_cons_grep_strip (r_strbuf_get (sb), "`"); - r_strbuf_free (sb); + RStrBuf *sb = rz_strbuf_new (arg_str); + rz_strbuf_prepend (sb, "~"); + char *specifier_str = rz_cons_grep_strip (rz_strbuf_get (sb), "`"); + rz_strbuf_free (sb); specifier_str = unescape_special_chars (specifier_str, SPECIAL_CHARS_REGULAR); R_LOG_DEBUG ("grep_command processed specifier: '%s'\n", specifier_str); - r_cons_grep_process (specifier_str); + rz_cons_grep_process (specifier_str); free (arg_str); return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(html_disable_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); - int scr_html = r_config_get_i (state->core->config, "scr.html"); - r_config_set_i (state->core->config, "scr.html", 0); - int scr_color = r_config_get_i (state->core->config, "scr.color"); - r_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); - RCmdStatus res = handle_ts_command (state, command); + int scr_html = rz_config_get_i (state->core->config, "scr.html"); + rz_config_set_i (state->core->config, "scr.html", 0); + int scr_color = rz_config_get_i (state->core->config, "scr.color"); + rz_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); + RzCmdStatus res = handle_ts_command (state, command); if (scr_html != -1) { - r_cons_flush (); - r_config_set_i (state->core->config, "scr.html", scr_html); + rz_cons_flush (); + rz_config_set_i (state->core->config, "scr.html", scr_html); } if (scr_color != -1) { - r_config_set_i (state->core->config, "scr.color", scr_color); + rz_config_set_i (state->core->config, "scr.color", scr_color); } return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(html_enable_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); - int scr_html = r_config_get_i (state->core->config, "scr.html"); - r_config_set_i (state->core->config, "scr.html", true); - RCmdStatus res = handle_ts_command (state, command); + int scr_html = rz_config_get_i (state->core->config, "scr.html"); + rz_config_set_i (state->core->config, "scr.html", true); + RzCmdStatus res = handle_ts_command (state, command); if (scr_html != -1) { - r_cons_flush (); - r_config_set_i (state->core->config, "scr.html", scr_html); + rz_cons_flush (); + rz_config_set_i (state->core->config, "scr.html", scr_html); } return res; } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(pipe_command) { TSNode first_cmd = ts_node_named_child (node, 0); - r_return_val_if_fail (!ts_node_is_null (first_cmd), false); + rz_return_val_if_fail (!ts_node_is_null (first_cmd), false); TSNode second_cmd = ts_node_named_child (node, 1); - r_return_val_if_fail (!ts_node_is_null (second_cmd), false); + rz_return_val_if_fail (!ts_node_is_null (second_cmd), false); char *first_str = ts_node_sub_string (first_cmd, state->input); char *second_str = ts_node_sub_string (second_cmd, state->input); int value = state->core->num->value; - RCmdStatus res = r_cmd_int2status (r_core_cmd_pipe (state->core, first_str, second_str)); + RzCmdStatus res = rz_cmd_int2status (rz_core_cmd_pipe (state->core, first_str, second_str)); state->core->num->value = value; free (first_str); free (second_str); @@ -6523,12 +6523,12 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(pipe_command) { DEFINE_HANDLE_TS_FCN_AND_SYMBOL(scr_tts_command) { TSNode command = ts_node_child_by_field_name (node, "command", strlen ("command")); - int scr_color = r_config_get_i (state->core->config, "scr.color"); - r_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); + int scr_color = rz_config_get_i (state->core->config, "scr.color"); + rz_config_set_i (state->core->config, "scr.color", COLOR_MODE_DISABLED); state->core->cons->use_tts = true; - RCmdStatus res = handle_ts_command (state, command); + RzCmdStatus res = handle_ts_command (state, command); if (scr_color != -1) { - r_config_set_i (state->core->config, "scr.color", scr_color); + rz_config_set_i (state->core->config, "scr.color", scr_color); } return res; } @@ -6540,14 +6540,14 @@ DEFINE_HANDLE_TS_FCN_AND_SYMBOL(task_command) { } DEFINE_HANDLE_TS_FCN_AND_SYMBOL(number_command) { - ut64 addr = r_num_math (state->core->num, node_string); - r_core_seek (state->core, addr, true); + ut64 addr = rz_num_math (state->core->num, node_string); + rz_core_seek (state->core, addr, true); return R_CMD_STATUS_OK; } -static RCmdStatus handle_ts_command(struct tsr2cmd_state *state, TSNode node) { - RCmdStatus ret = R_CMD_STATUS_INVALID; - RCmd *cmd = state->core->rcmd; +static RzCmdStatus handle_ts_command(struct tsr2cmd_state *state, TSNode node) { + RzCmdStatus ret = R_CMD_STATUS_INVALID; + RzCmd *cmd = state->core->rcmd; TSSymbol node_symbol = ts_node_symbol (node); ts_handler handler = ht_up_find (cmd->ts_symbols_ht, node_symbol, NULL); @@ -6565,18 +6565,18 @@ static RCmdStatus handle_ts_command(struct tsr2cmd_state *state, TSNode node) { return ret; } -static RCmdStatus handle_ts_command_tmpseek(struct tsr2cmd_state *state, TSNode node) { - RCore *core = state->core; +static RzCmdStatus handle_ts_command_tmpseek(struct tsr2cmd_state *state, TSNode node) { + RzCore *core = state->core; bool saved_tmpseek = core->tmpseek; core->tmpseek = true; - RCmdStatus ret = handle_ts_command (state, node); + RzCmdStatus ret = handle_ts_command (state, node); core->tmpseek = saved_tmpseek; return ret; } DEFINE_HANDLE_TS_FCN(commands) { - RCore *core = state->core; - RCmdStatus res = R_CMD_STATUS_OK; + RzCore *core = state->core; + RzCmdStatus res = R_CMD_STATUS_OK; ut32 child_count = ts_node_named_child_count (node); int i; @@ -6592,7 +6592,7 @@ DEFINE_HANDLE_TS_FCN(commands) { return lastcmd_repeat (core, true)? R_CMD_STATUS_OK: R_CMD_STATUS_INVALID; } if (state->split_lines) { - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); } for (i = 0; i < child_count; i++) { if (core->cons->context->cmd_depth < 1) { @@ -6604,15 +6604,15 @@ DEFINE_HANDLE_TS_FCN(commands) { core->prompt_offset = core->offset; } - if (state->split_lines && r_cons_is_breaked ()) { - r_cons_break_pop (); + if (state->split_lines && rz_cons_is_breaked ()) { + rz_cons_break_pop (); return res; } TSNode command = ts_node_named_child (node, i); - RCmdStatus cmd_res = handle_ts_command (state, command); + RzCmdStatus cmd_res = handle_ts_command (state, command); if (state->split_lines) { - r_cons_flush (); - r_core_task_yield (&core->tasks); + rz_cons_flush (); + rz_core_task_yield (&core->tasks); } core->cons->context->cmd_depth++; if (cmd_res == R_CMD_STATUS_INVALID) { @@ -6628,7 +6628,7 @@ DEFINE_HANDLE_TS_FCN(commands) { } err: if (state->split_lines) { - r_cons_break_pop (); + rz_cons_break_pop (); } return res; } @@ -6637,7 +6637,7 @@ err: #define RULE_OP(name) struct ts_data_symbol_map map_ts_command_handlers[] = { - #include "r2-shell-parser-cmds.inc" + #include "rz-shell-parser-cmds.inc" { NULL, NULL }, }; @@ -6645,15 +6645,15 @@ struct ts_data_symbol_map map_ts_command_handlers[] = { #define HANDLER_RULE_OP(name) RULE_OP(name) struct ts_data_symbol_map map_ts_symbols[] = { - #include "r2-shell-parser-cmds.inc" + #include "rz-shell-parser-cmds.inc" { NULL, NULL }, }; -static void ts_symbols_init(RCmd *cmd) { +static void ts_symbols_init(RzCmd *cmd) { if (cmd->language) { return; } - TSLanguage *lang = tree_sitter_r2cmd (); + TSLanguage *lang = tree_sitter_rzcmd (); cmd->language = lang; cmd->ts_symbols_ht = ht_up_new0 (); struct ts_data_symbol_map *entry = map_ts_command_handlers; @@ -6671,8 +6671,8 @@ static void ts_symbols_init(RCmd *cmd) { } } -static RCmdStatus core_cmd_tsr2cmd(RCore *core, const char *cstr, bool split_lines, bool log) { - char *input = strdup (r_str_trim_head_ro (cstr)); +static RzCmdStatus core_cmd_tsr2cmd(RzCore *core, const char *cstr, bool split_lines, bool log) { + char *input = strdup (rz_str_trim_head_ro (cstr)); ts_symbols_init (core->rcmd); @@ -6682,7 +6682,7 @@ static RCmdStatus core_cmd_tsr2cmd(RCore *core, const char *cstr, bool split_lin TSTree *tree = ts_parser_parse_string (parser, NULL, input, strlen (input)); TSNode root = ts_tree_root_node (tree); - RCmdStatus res = R_CMD_STATUS_INVALID; + RzCmdStatus res = R_CMD_STATUS_INVALID; struct tsr2cmd_state state; state.parser = parser; state.core = core; @@ -6692,7 +6692,7 @@ static RCmdStatus core_cmd_tsr2cmd(RCore *core, const char *cstr, bool split_lin state.split_lines = split_lines; if (state.log) { - r_line_hist_add (state.input); + rz_line_hist_add (state.input); } char *ts_str = ts_node_string (root); @@ -6713,12 +6713,12 @@ static RCmdStatus core_cmd_tsr2cmd(RCore *core, const char *cstr, bool split_lin return res; } -static int run_cmd_depth(RCore *core, char *cmd) { +static int run_cmd_depth(RzCore *core, char *cmd) { char *rcmd; int ret = false; if (core->cons->context->cmd_depth < 1) { - eprintf ("r_core_cmd: That was too deep (%s)...\n", cmd); + eprintf ("rz_core_cmd: That was too deep (%s)...\n", cmd); return false; } core->cons->context->cmd_depth--; @@ -6727,7 +6727,7 @@ static int run_cmd_depth(RCore *core, char *cmd) { if (ptr) { *ptr = '\0'; } - ret = r_core_cmd_subst (core, rcmd); + ret = rz_core_cmd_subst (core, rcmd); if (ret == -1) { eprintf ("|ERROR| Invalid command '%s' (0x%02x)\n", rcmd, *rcmd); break; @@ -6741,9 +6741,9 @@ static int run_cmd_depth(RCore *core, char *cmd) { return ret; } -R_API int r_core_cmd(RCore *core, const char *cstr, int log) { - if (core->use_tree_sitter_r2cmd) { - return r_cmd_status2int(core_cmd_tsr2cmd (core, cstr, false, log)); +RZ_API int rz_core_cmd(RzCore *core, const char *cstr, int log) { + if (core->use_tree_sitter_rzcmd) { + return rz_cmd_status2int(core_cmd_tsr2cmd (core, cstr, false, log)); } int ret = false, i; @@ -6767,18 +6767,18 @@ R_API int r_core_cmd(RCore *core, const char *cstr, int log) { goto beach; // false } else if (*cstr != '=' && strncmp (cstr, "!=", 2)) { if (core->cmdremote[0]) { - char *s = r_str_newf ("%s %s", core->cmdremote, cstr); - r_core_rtr_cmd (core, s); + char *s = rz_str_newf ("%s %s", core->cmdremote, cstr); + rz_core_rtr_cmd (core, s); free (s); } else { - char *res = r_io_system (core->io, cstr); + char *res = rz_io_system (core->io, cstr); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } } if (log) { - r_line_hist_add (cstr); + rz_line_hist_add (cstr); } goto beach; // false } @@ -6789,7 +6789,7 @@ R_API int r_core_cmd(RCore *core, const char *cstr, int log) { goto beach; // false; } if (!strncmp (cstr, "/*", 2)) { - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); goto beach; // false } @@ -6810,9 +6810,9 @@ R_API int r_core_cmd(RCore *core, const char *cstr, int log) { if (!cmd) { goto beach; } - r_str_cpy (cmd, cstr); + rz_str_cpy (cmd, cstr); if (log) { - r_line_hist_add (cstr); + rz_line_hist_add (cstr); } ret = run_cmd_depth (core, cmd); @@ -6821,9 +6821,9 @@ beach: return ret; } -R_API int r_core_cmd_lines(RCore *core, const char *lines) { - if (core->use_tree_sitter_r2cmd) { - RCmdStatus status = core_cmd_tsr2cmd (core, lines, true, false); +RZ_API int rz_core_cmd_lines(RzCore *core, const char *lines) { + if (core->use_tree_sitter_rzcmd) { + RzCmdStatus status = core_cmd_tsr2cmd (core, lines, true, false); return status == R_CMD_STATUS_OK; } int r, ret = true; @@ -6838,21 +6838,21 @@ R_API int r_core_cmd_lines(RCore *core, const char *lines) { } nl = strchr (odata, '\n'); if (nl) { - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { free (odata); - r_cons_break_pop (); + rz_cons_break_pop (); return ret; } *nl = '\0'; - r = r_core_cmd (core, data, 0); + r = rz_core_cmd (core, data, 0); if (r < 0) { //== -1) { data = nl + 1; ret = -1; //r; //false; break; } - r_cons_flush (); + rz_cons_flush (); if (data[0] == 'q') { if (data[1] == '!') { ret = -1; @@ -6863,30 +6863,30 @@ R_API int r_core_cmd_lines(RCore *core, const char *lines) { break; } data = nl + 1; - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); } while ((nl = strchr (data, '\n'))); - r_cons_break_pop (); + rz_cons_break_pop (); } if (ret >= 0 && data && *data) { - r_core_cmd (core, data, 0); - r_cons_flush (); - r_core_task_yield (&core->tasks); + rz_core_cmd (core, data, 0); + rz_cons_flush (); + rz_core_task_yield (&core->tasks); } free (odata); return ret; } -R_API int r_core_cmd_file(RCore *core, const char *file) { - char *data = r_file_abspath (file); +RZ_API int rz_core_cmd_file(RzCore *core, const char *file) { + char *data = rz_file_abspath (file); if (!data) { return false; } - char *odata = r_file_slurp (data, NULL); + char *odata = rz_file_slurp (data, NULL); free (data); if (!odata) { return false; } - if (!r_core_cmd_lines (core, odata)) { + if (!rz_core_cmd_lines (core, odata)) { eprintf ("Failed to run script '%s'\n", file); free (odata); return false; @@ -6895,43 +6895,43 @@ R_API int r_core_cmd_file(RCore *core, const char *file) { return true; } -R_API int r_core_cmd_command(RCore *core, const char *command) { +RZ_API int rz_core_cmd_command(RzCore *core, const char *command) { int ret, len; char *buf, *rcmd, *ptr; - char *cmd = r_core_sysenv_begin (core, command); - rcmd = ptr = buf = r_sys_cmd_str (cmd, 0, &len); + char *cmd = rz_core_sysenv_begin (core, command); + rcmd = ptr = buf = rz_sys_cmd_str (cmd, 0, &len); if (!buf) { free (cmd); return -1; } - ret = r_core_cmd (core, rcmd, 0); - r_core_sysenv_end (core, command); + ret = rz_core_cmd (core, rcmd, 0); + rz_core_sysenv_end (core, command); free (buf); return ret; } //TODO: Fix disasm loop is mandatory -R_API char *r_core_disassemble_instr(RCore *core, ut64 addr, int l) { +RZ_API char *rz_core_disassemble_instr(RzCore *core, ut64 addr, int l) { char *cmd, *ret = NULL; - cmd = r_str_newf ("pd %i @ 0x%08"PFMT64x, l, addr); + cmd = rz_str_newf ("pd %i @ 0x%08"PFMT64x, l, addr); if (cmd) { - ret = r_core_cmd_str (core, cmd); + ret = rz_core_cmd_str (core, cmd); free (cmd); } return ret; } -R_API char *r_core_disassemble_bytes(RCore *core, ut64 addr, int b) { +RZ_API char *rz_core_disassemble_bytes(RzCore *core, ut64 addr, int b) { char *cmd, *ret = NULL; - cmd = r_str_newf ("pD %i @ 0x%08"PFMT64x, b, addr); + cmd = rz_str_newf ("pD %i @ 0x%08"PFMT64x, b, addr); if (cmd) { - ret = r_core_cmd_str (core, cmd); + ret = rz_core_cmd_str (core, cmd); free (cmd); } return ret; } -R_API int r_core_cmd_buffer(RCore *core, const char *buf) { +RZ_API int rz_core_cmd_buffer(RzCore *core, const char *buf) { char *ptr, *optr, *str = strdup (buf); if (!str) { return false; @@ -6940,110 +6940,110 @@ R_API int r_core_cmd_buffer(RCore *core, const char *buf) { ptr = strchr (str, '\n'); while (ptr) { *ptr = '\0'; - r_core_cmd (core, optr, 0); + rz_core_cmd (core, optr, 0); optr = ptr + 1; ptr = strchr (str, '\n'); } - r_core_cmd (core, optr, 0); + rz_core_cmd (core, optr, 0); free (str); return true; } -R_API int r_core_cmdf(RCore *core, const char *fmt, ...) { +RZ_API int rz_core_cmdf(RzCore *core, const char *fmt, ...) { char string[4096]; int ret; va_list ap; va_start (ap, fmt); vsnprintf (string, sizeof (string), fmt, ap); - ret = r_core_cmd (core, string, 0); + ret = rz_core_cmd (core, string, 0); va_end (ap); return ret; } -R_API int r_core_cmd0(RCore *core, const char *cmd) { - return r_core_cmd (core, cmd, 0); +RZ_API int rz_core_cmd0(RzCore *core, const char *cmd) { + return rz_core_cmd (core, cmd, 0); } -R_API int r_core_flush(RCore *core, const char *cmd) { - int ret = r_core_cmd (core, cmd, 0); - r_cons_flush (); +RZ_API int rz_core_flush(RzCore *core, const char *cmd) { + int ret = rz_core_cmd (core, cmd, 0); + rz_cons_flush (); return ret; } -R_API char *r_core_cmd_str_pipe(RCore *core, const char *cmd) { +RZ_API char *rz_core_cmd_str_pipe(RzCore *core, const char *cmd) { char *tmp = NULL; char *p = (*cmd != '"')? strchr (cmd, '|'): NULL; if (!p && *cmd != '!' && *cmd != '.') { - return r_core_cmd_str (core, cmd); + return rz_core_cmd_str (core, cmd); } - r_cons_reset (); - r_sandbox_disable (true); - if (r_file_mkstemp ("cmd", &tmp) != -1) { - int pipefd = r_cons_pipe_open (tmp, 1, 0); + rz_cons_reset (); + rz_sandbox_disable (true); + if (rz_file_mkstemp ("cmd", &tmp) != -1) { + int pipefd = rz_cons_pipe_open (tmp, 1, 0); if (pipefd == -1) { - r_file_rm (tmp); - r_sandbox_disable (false); + rz_file_rm (tmp); + rz_sandbox_disable (false); free (tmp); - return r_core_cmd_str (core, cmd); + return rz_core_cmd_str (core, cmd); } char *_cmd = strdup (cmd); - if (core->use_tree_sitter_r2cmd) { - r_core_cmd (core, _cmd, 0); + if (core->use_tree_sitter_rzcmd) { + rz_core_cmd (core, _cmd, 0); } else { - r_core_cmd_subst (core, _cmd); + rz_core_cmd_subst (core, _cmd); } - r_cons_flush (); - r_cons_pipe_close (pipefd); - if (r_file_exists (tmp)) { - char *s = r_file_slurp (tmp, NULL); - r_file_rm (tmp); - r_sandbox_disable (false); + rz_cons_flush (); + rz_cons_pipe_close (pipefd); + if (rz_file_exists (tmp)) { + char *s = rz_file_slurp (tmp, NULL); + rz_file_rm (tmp); + rz_sandbox_disable (false); free (tmp); free (_cmd); return s? s: strdup (""); } eprintf ("slurp %s fails\n", tmp); - r_file_rm (tmp); + rz_file_rm (tmp); free (tmp); free (_cmd); - r_sandbox_disable (false); - return r_core_cmd_str (core, cmd); + rz_sandbox_disable (false); + return rz_core_cmd_str (core, cmd); } - r_sandbox_disable (0); + rz_sandbox_disable (0); return NULL; } -R_API char *r_core_cmd_strf(RCore *core, const char *fmt, ...) { +RZ_API char *rz_core_cmd_strf(RzCore *core, const char *fmt, ...) { char string[4096]; char *ret; va_list ap; va_start (ap, fmt); vsnprintf (string, sizeof (string), fmt, ap); - ret = r_core_cmd_str (core, string); + ret = rz_core_cmd_str (core, string); va_end (ap); return ret; } /* return: pointer to a buffer with the output of the command */ -R_API char *r_core_cmd_str(RCore *core, const char *cmd) { +RZ_API char *rz_core_cmd_str(RzCore *core, const char *cmd) { const char *static_str; char *retstr = NULL; - r_cons_push (); - if (r_core_cmd (core, cmd, 0) == -1) { + rz_cons_push (); + if (rz_core_cmd (core, cmd, 0) == -1) { //eprintf ("Invalid command: %s\n", cmd); return NULL; } - r_cons_filter (); - static_str = r_cons_get_buffer (); + rz_cons_filter (); + static_str = rz_cons_get_buffer (); retstr = strdup (static_str? static_str: ""); - r_cons_pop (); - r_cons_echo (NULL); + rz_cons_pop (); + rz_cons_echo (NULL); return retstr; } /* run cmd in the main task synchronously */ -R_API int r_core_cmd_task_sync(RCore *core, const char *cmd, bool log) { - RCoreTask *task = core->tasks.main_task; +RZ_API int rz_core_cmd_task_sync(RzCore *core, const char *cmd, bool log) { + RzCoreTask *task = core->tasks.main_task; char *s = strdup (cmd); if (!s) { return 0; @@ -7051,26 +7051,26 @@ R_API int r_core_cmd_task_sync(RCore *core, const char *cmd, bool log) { task->cmd = s; task->cmd_log = log; task->state = R_CORE_TASK_STATE_BEFORE_START; - int res = r_core_task_run_sync (&core->tasks, task); + int res = rz_core_task_run_sync (&core->tasks, task); free (s); return res; } static int cmd_ox(void *data, const char *input) { - return r_core_cmdf ((RCore*)data, "s 0%s", input); + return rz_core_cmdf ((RzCore*)data, "s 0%s", input); } static int compare_cmd_descriptor_name(const void *a, const void *b) { - return strcmp (((RCmdDescriptor *)a)->cmd, ((RCmdDescriptor *)b)->cmd); + return strcmp (((RzCmdDescriptor *)a)->cmd, ((RzCmdDescriptor *)b)->cmd); } -static void cmd_descriptor_init(RCore *core) { +static void cmd_descriptor_init(RzCore *core) { const ut8 *p; - RListIter *iter; - RCmdDescriptor *x, *y; + RzListIter *iter; + RzCmdDescriptor *x, *y; int n = core->cmd_descriptors->length; - r_list_sort (core->cmd_descriptors, compare_cmd_descriptor_name); - r_list_foreach (core->cmd_descriptors, iter, y) { + rz_list_sort (core->cmd_descriptors, compare_cmd_descriptor_name); + rz_list_foreach (core->cmd_descriptors, iter, y) { if (--n < 0) { break; } @@ -7078,8 +7078,8 @@ static void cmd_descriptor_init(RCore *core) { for (p = (const ut8 *)y->cmd; *p; p++) { if (!x->sub[*p]) { if (p[1]) { - RCmdDescriptor *d = R_NEW0 (RCmdDescriptor); - r_list_append (core->cmd_descriptors, d); + RzCmdDescriptor *d = R_NEW0 (RzCmdDescriptor); + rz_list_append (core->cmd_descriptors, d); x->sub[*p] = d; } else { x->sub[*p] = y; @@ -7093,19 +7093,19 @@ static void cmd_descriptor_init(RCore *core) { } static int core_cmd0_wrapper(void *core, const char *cmd) { - return r_core_cmd0 ((RCore *)core, cmd); + return rz_core_cmd0 ((RzCore *)core, cmd); } -R_API void r_core_cmd_init(RCore *core) { +RZ_API void rz_core_cmd_init(RzCore *core) { struct { const char *cmd; const char *description; - RCmdCb cb; - void (*descriptor_init)(RCore *core, RCmdDesc *parent); - const RCmdDescHelp *help; - const RCmdDescHelp *group_help; - RCmdDescType type; - RCmdArgvCb argv_cb; + RzCmdCb cb; + void (*descriptor_init)(RzCore *core, RzCmdDesc *parent); + const RzCmdDescHelp *help; + const RzCmdDescHelp *group_help; + RzCmdDescType type; + RzCmdArgvCb argv_cb; } cmds[] = { {"!", "run system command", cmd_system, NULL, &system_help}, {"_", "print last output", cmd_last, NULL, &underscore_help}, @@ -7144,12 +7144,12 @@ R_API void r_core_cmd_init(RCore *core) { {"q", "exit program session", cmd_quit, cmd_quit_init, &q_help}, {"Q", "alias for q!", cmd_Quit, NULL, &Q_help}, {":", "long commands starting with :", cmd_colon, NULL, &colon_help}, - {"r", "change file size", cmd_resize, NULL, &r_help}, + {"r", "change file size", cmd_resize, NULL, &rz_help}, {"s", "seek to an offset", cmd_seek, cmd_seek_init, &s_help}, {"t", "type information (cparse)", cmd_type, cmd_type_init, &t_help}, {"T", "Text log utility", cmd_log, cmd_log_init, &T_help}, {"u", "uname/undo", cmd_undo, NULL, &u_help}, - {"<", "pipe into RCons.readChar", cmd_pipein, NULL, &pipein_help}, + {"<", "pipe into RzCons.readChar", cmd_pipein, NULL, &pipein_help}, {"V", "enter visual mode", cmd_visual, NULL, &V_help}, {"v", "enter visual mode", cmd_panels, NULL, &v_help}, {"w", "write bytes", cmd_write, cmd_write_init, &w_help, &w_group_help, R_CMD_DESC_TYPE_GROUP, w_handler}, @@ -7158,33 +7158,33 @@ R_API void r_core_cmd_init(RCore *core) { {"z", "zignatures", cmd_zign, cmd_zign_init, &z_help}, }; - core->rcmd = r_cmd_new (); + core->rcmd = rz_cmd_new (); core->rcmd->macro.user = core; core->rcmd->macro.num = core->num; core->rcmd->macro.cmd = core_cmd0_wrapper; - core->rcmd->nullcallback = r_core_cmd_nullcallback; - core->rcmd->macro.cb_printf = (PrintfCallback)r_cons_printf; - r_cmd_set_data (core->rcmd, core); - core->cmd_descriptors = r_list_newf (free); + core->rcmd->nullcallback = rz_core_cmd_nullcallback; + core->rcmd->macro.cb_printf = (PrintfCallback)rz_cons_printf; + rz_cmd_set_data (core->rcmd, core); + core->cmd_descriptors = rz_list_newf (free); - RCmdDesc *root = r_cmd_get_root (core->rcmd); + RzCmdDesc *root = rz_cmd_get_root (core->rcmd); size_t i; for (i = 0; i < R_ARRAY_SIZE (cmds); i++) { - r_cmd_add (core->rcmd, cmds[i].cmd, cmds[i].cb); + rz_cmd_add (core->rcmd, cmds[i].cmd, cmds[i].cb); - RCmdDesc *cd; + RzCmdDesc *cd; switch (cmds[i].type) { case R_CMD_DESC_TYPE_OLDINPUT: - cd = r_cmd_desc_oldinput_new (core->rcmd, root, cmds[i].cmd, cmds[i].cb, cmds[i].help); + cd = rz_cmd_desc_oldinput_new (core->rcmd, root, cmds[i].cmd, cmds[i].cb, cmds[i].help); break; case R_CMD_DESC_TYPE_ARGV: - cd = r_cmd_desc_argv_new (core->rcmd, root, cmds[i].cmd, cmds[i].argv_cb, cmds[i].help); + cd = rz_cmd_desc_argv_new (core->rcmd, root, cmds[i].cmd, cmds[i].argv_cb, cmds[i].help); break; case R_CMD_DESC_TYPE_INNER: - cd = r_cmd_desc_inner_new (core->rcmd, root, cmds[i].cmd, cmds[i].help); + cd = rz_cmd_desc_inner_new (core->rcmd, root, cmds[i].cmd, cmds[i].help); break; case R_CMD_DESC_TYPE_GROUP: - cd = r_cmd_desc_group_new (core->rcmd, root, cmds[i].cmd, cmds[i].argv_cb, cmds[i].help, cmds[i].group_help); + cd = rz_cmd_desc_group_new (core->rcmd, root, cmds[i].cmd, cmds[i].argv_cb, cmds[i].help, cmds[i].group_help); break; } if (cmds[i].descriptor_init) { diff --git a/libr/core/cmd_anal.c b/librz/core/cmd_anal.c similarity index 57% rename from libr/core/cmd_anal.c rename to librz/core/cmd_anal.c index 3989a66786..8f51d6b2c7 100644 --- a/libr/core/cmd_anal.c +++ b/librz/core/cmd_anal.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, maijin */ -#include +#include #define MAX_SCAN_SIZE 0x7ffffff @@ -751,7 +751,7 @@ static const char *help_msg_axt[]= { NULL }; -static void cmd_anal_init(RCore *core, RCmdDesc *parent) { +static void cmd_anal_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, a); DEFINE_CMD_DESCRIPTOR (core, aa); DEFINE_CMD_DESCRIPTOR (core, aar); @@ -789,30 +789,30 @@ static void cmd_anal_init(RCore *core, RCmdDesc *parent) { } static int cmpname (const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; return (int)strcmp (a->name, b->name); } static int cmpsize (const void *a, const void *b) { - ut64 sa = (int) r_anal_function_linear_size ((RAnalFunction *) a); - ut64 sb = (int) r_anal_function_linear_size ((RAnalFunction *) b); + ut64 sa = (int) rz_anal_function_linear_size ((RzAnalFunction *) a); + ut64 sb = (int) rz_anal_function_linear_size ((RzAnalFunction *) b); return (sa > sb)? -1: (sa < sb)? 1 : 0; } static int cmpbbs (const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; - int la = (int)r_list_length (a->bbs); - int lb = (int)r_list_length (b->bbs); + const RzAnalFunction *a = _a, *b = _b; + int la = (int)rz_list_length (a->bbs); + int lb = (int)rz_list_length (b->bbs); return (la > lb)? -1: (la < lb)? 1 : 0; } static int cmpaddr (const void *_a, const void *_b) { - const RAnalFunction *a = _a, *b = _b; + const RzAnalFunction *a = _a, *b = _b; return (a->addr > b->addr)? 1: (a->addr addr)? -1: 0; } static bool listOpDescriptions(void *_core, const char *k, const char *v) { - r_cons_printf ("%s=%s\n", k, v); + rz_cons_printf ("%s=%s\n", k, v); return true; } @@ -821,7 +821,7 @@ static bool listOpDescriptions(void *_core, const char *k, const char *v) { #if JAYRO_03 -static bool anal_is_bad_call(RCore *core, ut64 from, ut64 to, ut64 addr, ut8 *buf, int bufi) { +static bool anal_is_bad_call(RzCore *core, ut64 from, ut64 to, ut64 addr, ut8 *buf, int bufi) { ut64 align = R_ABS (addr % PE_ALIGN); ut32 call_bytes; @@ -853,114 +853,114 @@ static bool anal_is_bad_call(RCore *core, ut64 from, ut64 to, ut64 addr, ut8 *bu #endif // function argument types and names into anal/types -static void __add_vars_sdb(RCore *core, RAnalFunction *fcn) { - RAnalFcnVarsCache cache; - r_anal_fcn_vars_cache_init (core->anal, &cache, fcn); - RListIter *iter; - RAnalVar *var; +static void __add_vars_sdb(RzCore *core, RzAnalFunction *fcn) { + RzAnalFcnVarsCache cache; + rz_anal_fcn_vars_cache_init (core->anal, &cache, fcn); + RzListIter *iter; + RzAnalVar *var; int arg_count = 0; - RList *all_vars = cache.rvars; - r_list_join (all_vars, cache.bvars); - r_list_join (all_vars, cache.svars); + RzList *all_vars = cache.rvars; + rz_list_join (all_vars, cache.bvars); + rz_list_join (all_vars, cache.svars); RStrBuf key, value; - r_strbuf_init (&key); - r_strbuf_init (&value); + rz_strbuf_init (&key); + rz_strbuf_init (&value); - r_list_foreach (all_vars, iter, var) { + rz_list_foreach (all_vars, iter, var) { if (var->isarg) { - if (!r_strbuf_setf (&key, "func.%s.arg.%d", fcn->name, arg_count) || - !r_strbuf_setf (&value, "%s,%s", var->type, var->name)) { + if (!rz_strbuf_setf (&key, "func.%s.arg.%d", fcn->name, arg_count) || + !rz_strbuf_setf (&value, "%s,%s", var->type, var->name)) { goto exit; } - sdb_set (core->anal->sdb_types, r_strbuf_get (&key), r_strbuf_get (&value), 0); + sdb_set (core->anal->sdb_types, rz_strbuf_get (&key), rz_strbuf_get (&value), 0); arg_count++; } } if (arg_count > 0) { - if (!r_strbuf_setf (&key, "func.%s.args", fcn->name) || - !r_strbuf_setf (&value, "%d", arg_count)) { + if (!rz_strbuf_setf (&key, "func.%s.args", fcn->name) || + !rz_strbuf_setf (&value, "%d", arg_count)) { goto exit; } - sdb_set (core->anal->sdb_types, r_strbuf_get (&key), r_strbuf_get (&value), 0); + sdb_set (core->anal->sdb_types, rz_strbuf_get (&key), rz_strbuf_get (&value), 0); } exit: - r_strbuf_fini (&key); - r_strbuf_fini (&value); - r_anal_fcn_vars_cache_fini (&cache); + rz_strbuf_fini (&key); + rz_strbuf_fini (&value); + rz_anal_fcn_vars_cache_fini (&cache); } -static bool cmd_anal_aaft(RCore *core) { - RListIter *it; - RAnalFunction *fcn; +static bool cmd_anal_aaft(RzCore *core) { + RzListIter *it; + RzAnalFunction *fcn; ut64 seek; const char *io_cache_key = "io.pcache.write"; - bool io_cache = r_config_get_i (core->config, io_cache_key); - if (r_config_get_i (core->config, "cfg.debug")) { + bool io_cache = rz_config_get_i (core->config, io_cache_key); + if (rz_config_get_i (core->config, "cfg.debug")) { eprintf ("TOFIX: aaft can't run in debugger mode.\n"); return false; } if (!io_cache) { // XXX. we shouldnt need this, but it breaks 'r2 -c aaa -w ls' - r_config_set_i (core->config, io_cache_key, true); + rz_config_set_i (core->config, io_cache_key, true); } seek = core->offset; - r_reg_arena_push (core->anal->reg); - r_reg_arena_zero (core->anal->reg); - r_core_cmd0 (core, "aei;aeim"); - ut8 *saved_arena = r_reg_arena_peek (core->anal->reg); + rz_reg_arena_push (core->anal->reg); + rz_reg_arena_zero (core->anal->reg); + rz_core_cmd0 (core, "aei;aeim"); + ut8 *saved_arena = rz_reg_arena_peek (core->anal->reg); // Iterating Reverse so that we get function in top-bottom call order - r_list_foreach_prev (core->anal->fcns, it, fcn) { - int ret = r_core_seek (core, fcn->addr, true); + rz_list_foreach_prev (core->anal->fcns, it, fcn) { + int ret = rz_core_seek (core, fcn->addr, true); if (!ret) { continue; } - r_reg_arena_poke (core->anal->reg, saved_arena); - r_anal_esil_set_pc (core->anal->esil, fcn->addr); - r_core_anal_type_match (core, fcn); - if (r_cons_is_breaked ()) { + rz_reg_arena_poke (core->anal->reg, saved_arena); + rz_anal_esil_set_pc (core->anal->esil, fcn->addr); + rz_core_anal_type_match (core, fcn); + if (rz_cons_is_breaked ()) { break; } __add_vars_sdb (core, fcn); } - r_core_seek (core, seek, true); - r_reg_arena_pop (core->anal->reg); - r_config_set_i (core->config, io_cache_key, io_cache); + rz_core_seek (core, seek, true); + rz_reg_arena_pop (core->anal->reg); + rz_config_set_i (core->config, io_cache_key, io_cache); free (saved_arena); return true; } -static void type_cmd(RCore *core, const char *input) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); +static void type_cmd(RzCore *core, const char *input) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (!fcn && *input != '?') { eprintf ("cant find function here\n"); return; } ut64 seek; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); switch (*input) { case '\0': // "aft" seek = core->offset; - r_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); - r_core_anal_type_match (core, fcn); - r_core_seek (core, seek, true); + rz_anal_esil_set_pc (core->anal->esil, fcn? fcn->addr: core->offset); + rz_core_anal_type_match (core, fcn); + rz_core_seek (core, seek, true); break; case '?': - r_core_cmd_help (core, help_msg_aft); + rz_core_cmd_help (core, help_msg_aft); break; } - r_cons_break_pop (); + rz_cons_break_pop (); } static bool cc_print(void *p, const char *k, const char *v) { if (!strcmp (v, "cc")) { - r_cons_println (k); + rz_cons_println (k); } return true; } -static void find_refs(RCore *core, const char *glob) { +static void find_refs(RzCore *core, const char *glob) { char cmd[128]; ut64 curseek = core->offset; while (*glob == ' ') glob++; @@ -973,54 +973,54 @@ static void find_refs(RCore *core, const char *glob) { } eprintf ("Finding references of flags matching '%s'...\n", glob); snprintf (cmd, sizeof (cmd) - 1, ".(findstref) @@= `f~%s[0]`", glob); - r_core_cmd0 (core, "(findstref;f here=$$;s entry0;/r here;f-here)"); - r_core_cmd0 (core, cmd); - r_core_cmd0 (core, "(-findstref)"); - r_core_seek (core, curseek, true); + rz_core_cmd0 (core, "(findstref;f here=$$;s entry0;/r here;f-here)"); + rz_core_cmd0 (core, cmd); + rz_core_cmd0 (core, "(-findstref)"); + rz_core_seek (core, curseek, true); } /* set flags for every function */ -static void flag_every_function(RCore *core) { - RListIter *iter; - RAnalFunction *fcn; - r_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); - r_list_foreach (core->anal->fcns, iter, fcn) { - r_flag_set (core->flags, fcn->name, - fcn->addr, r_anal_function_size_from_entry (fcn)); +static void flag_every_function(RzCore *core) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); + rz_list_foreach (core->anal->fcns, iter, fcn) { + rz_flag_set (core->flags, fcn->name, + fcn->addr, rz_anal_function_size_from_entry (fcn)); } - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); } -static void var_help(RCore *core, char ch) { +static void var_help(RzCore *core, char ch) { switch (ch) { case 'b': - r_core_cmd_help (core, help_msg_afvb); + rz_core_cmd_help (core, help_msg_afvb); break; case 's': - r_core_cmd_help (core, help_msg_afvs); + rz_core_cmd_help (core, help_msg_afvs); break; case 'r': - r_core_cmd_help (core, help_msg_afvr); + rz_core_cmd_help (core, help_msg_afvr); break; case '?': - r_core_cmd_help (core, help_msg_afv); + rz_core_cmd_help (core, help_msg_afv); break; default: eprintf ("See afv?, afvb?, afvr? and afvs?\n"); } } -static void var_accesses_list(RAnalFunction *fcn, RAnalVar *var, PJ *pj, int access_type, const char *name) { - RAnalVarAccess *acc; +static void var_accesses_list(RzAnalFunction *fcn, RzAnalVar *var, PJ *pj, int access_type, const char *name) { + RzAnalVarAccess *acc; bool first = true; if (pj) { pj_o (pj); pj_ks (pj, "name", name); pj_ka (pj, "addrs"); } else { - r_cons_printf ("%10s", name); + rz_cons_printf ("%10s", name); } - r_vector_foreach (&var->accesses, acc) { + rz_vector_foreach (&var->accesses, acc) { if (!(acc->type & access_type)) { continue; } @@ -1028,7 +1028,7 @@ static void var_accesses_list(RAnalFunction *fcn, RAnalVar *var, PJ *pj, int acc if (pj) { pj_n (pj, addr); } else { - r_cons_printf ("%s0x%" PFMT64x, first ? " " : ",", addr); + rz_cons_printf ("%s0x%" PFMT64x, first ? " " : ",", addr); } first = false; } @@ -1036,44 +1036,44 @@ static void var_accesses_list(RAnalFunction *fcn, RAnalVar *var, PJ *pj, int acc pj_end (pj); pj_end (pj); } else { - r_cons_newline (); + rz_cons_newline (); } } -static void list_vars(RCore *core, RAnalFunction *fcn, PJ *pj, int type, const char *name) { - RAnalVar *var = NULL; - RListIter *iter; - RList *list = r_anal_var_all_list (core->anal, fcn); +static void list_vars(RzCore *core, RzAnalFunction *fcn, PJ *pj, int type, const char *name) { + RzAnalVar *var = NULL; + RzListIter *iter; + RzList *list = rz_anal_var_all_list (core->anal, fcn); if (type == '=') { ut64 oaddr = core->offset; - r_list_foreach (list, iter, var) { - r_cons_printf ("* %s\n", var->name); - RAnalVarAccess *acc; - r_vector_foreach (&var->accesses, acc) { + rz_list_foreach (list, iter, var) { + rz_cons_printf ("* %s\n", var->name); + RzAnalVarAccess *acc; + rz_vector_foreach (&var->accesses, acc) { if (!(acc->type & R_ANAL_VAR_ACCESS_TYPE_READ)) { continue; } - r_cons_printf ("R 0x%"PFMT64x" ", fcn->addr + acc->offset); - r_core_seek (core, fcn->addr + acc->offset, 1); - r_core_print_disasm_instructions (core, 0, 1); + rz_cons_printf ("R 0x%"PFMT64x" ", fcn->addr + acc->offset); + rz_core_seek (core, fcn->addr + acc->offset, 1); + rz_core_print_disasm_instructions (core, 0, 1); } - r_vector_foreach (&var->accesses, acc) { + rz_vector_foreach (&var->accesses, acc) { if (!(acc->type & R_ANAL_VAR_ACCESS_TYPE_WRITE)) { continue; } - r_cons_printf ("W 0x%"PFMT64x" ", fcn->addr + acc->offset); - r_core_seek (core, fcn->addr + acc->offset, 1); - r_core_print_disasm_instructions (core, 0, 1); + rz_cons_printf ("W 0x%"PFMT64x" ", fcn->addr + acc->offset); + rz_core_seek (core, fcn->addr + acc->offset, 1); + rz_core_print_disasm_instructions (core, 0, 1); } } - r_core_seek (core, oaddr, 0); + rz_core_seek (core, oaddr, 0); return; } if (type == '*') { - const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP); - r_cons_printf ("f-fcnvar*\n"); - r_list_foreach (list, iter, var) { - r_cons_printf ("f fcnvar.%s @ %s%s%d\n", var->name, bp, + const char *bp = rz_reg_get_name (core->anal->reg, R_REG_NAME_BP); + rz_cons_printf ("f-fcnvar*\n"); + rz_list_foreach (list, iter, var) { + rz_cons_printf ("f fcnvar.%s @ %s%s%d\n", var->name, bp, var->delta>=0? "+":"", var->delta); } return; @@ -1086,12 +1086,12 @@ static void list_vars(RCore *core, RAnalFunction *fcn, PJ *pj, int type, const c pj_a (pj); } if (name && *name) { - var = r_anal_function_get_var_byname (fcn, name); + var = rz_anal_function_get_var_byname (fcn, name); if (var) { var_accesses_list (fcn, var, pj, access_type, var->name); } } else { - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { var_accesses_list (fcn, var, pj, access_type, var->name); } } @@ -1100,10 +1100,10 @@ static void list_vars(RCore *core, RAnalFunction *fcn, PJ *pj, int type, const c } } -static void cmd_afvx(RCore *core, RAnalFunction *fcn, bool json) { - r_return_if_fail (core); +static void cmd_afvx(RzCore *core, RzAnalFunction *fcn, bool json) { + rz_return_if_fail (core); if (!fcn) { - fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ANY); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ANY); } if (fcn) { PJ *pj = NULL; @@ -1112,28 +1112,28 @@ static void cmd_afvx(RCore *core, RAnalFunction *fcn, bool json) { pj_o (pj); pj_k (pj, "reads"); } else { - r_cons_printf ("afvR\n"); + rz_cons_printf ("afvR\n"); } list_vars (core, fcn, pj, 'R', NULL); if (json) { pj_k (pj, "writes"); } else { - r_cons_printf ("afvW\n"); + rz_cons_printf ("afvW\n"); } list_vars (core, fcn, pj, 'W', NULL); if (json) { pj_end (pj); char *j = pj_drain (pj); - r_cons_printf ("%s\n", j); + rz_cons_printf ("%s\n", j); free (j); } } } -static int cmd_an(RCore *core, bool use_json, const char *name) { +static int cmd_an(RzCore *core, bool use_json, const char *name) { int ret = 0; ut64 off = core->offset; - RAnalOp op; + RzAnalOp op; PJ *pj = NULL; ut64 tgt_addr = UT64_MAX; @@ -1142,14 +1142,14 @@ static int cmd_an(RCore *core, bool use_json, const char *name) { pj_a (pj); } - r_anal_op (core->anal, &op, off, + rz_anal_op (core->anal, &op, off, core->block + off - core->offset, 32, R_ANAL_OP_MASK_BASIC); - RAnalVar *var = r_anal_get_used_function_var (core->anal, op.addr); + RzAnalVar *var = rz_anal_get_used_function_var (core->anal, op.addr); tgt_addr = op.jump != UT64_MAX? op.jump: op.ptr; if (var) { if (name) { - ret = r_anal_var_rename (var, name, true) + ret = rz_anal_var_rename (var, name, true) ? 0 : -1; } else if (use_json) { @@ -1159,16 +1159,16 @@ static int cmd_an(RCore *core, bool use_json, const char *name) { pj_kn (pj, "offset", tgt_addr); pj_end (pj); } else { - r_cons_println (var->name); + rz_cons_println (var->name); } } else if (tgt_addr != UT64_MAX) { - RAnalFunction *fcn = r_anal_get_function_at (core->anal, tgt_addr); - RFlagItem *f = r_flag_get_i (core->flags, tgt_addr); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, tgt_addr); + RzFlagItem *f = rz_flag_get_i (core->flags, tgt_addr); if (fcn) { if (name) { - ret = r_anal_function_rename (fcn, name)? 0: -1; + ret = rz_anal_function_rename (fcn, name)? 0: -1; } else if (!use_json) { - r_cons_println (fcn->name); + rz_cons_println (fcn->name); } else { pj_o (pj); pj_ks (pj, "name", fcn->name); @@ -1178,9 +1178,9 @@ static int cmd_an(RCore *core, bool use_json, const char *name) { } } else if (f) { if (name) { - ret = r_flag_rename (core->flags, f, name)? 0: -1; + ret = rz_flag_rename (core->flags, f, name)? 0: -1; } else if (!use_json) { - r_cons_println (f->name); + rz_cons_println (f->name); } else { pj_o (pj); if (name) { @@ -1198,9 +1198,9 @@ static int cmd_an(RCore *core, bool use_json, const char *name) { } } else { if (name) { - ret = r_flag_set (core->flags, name, tgt_addr, 1)? 0: -1; + ret = rz_flag_set (core->flags, name, tgt_addr, 1)? 0: -1; } else if (!use_json) { - r_cons_printf ("0x%" PFMT64x "\n", tgt_addr); + rz_cons_printf ("0x%" PFMT64x "\n", tgt_addr); } else { pj_o (pj); pj_ks (pj, "name", name); @@ -1216,62 +1216,62 @@ static int cmd_an(RCore *core, bool use_json, const char *name) { } if (pj) { - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); return ret; } // EBP BASED static int delta_cmp(const void *a, const void *b) { - const RAnalVar *va = a; - const RAnalVar *vb = b; + const RzAnalVar *va = a; + const RzAnalVar *vb = b; return vb->delta - va->delta; } static int delta_cmp2(const void *a, const void *b) { - const RAnalVar *va = a; - const RAnalVar *vb = b; + const RzAnalVar *va = a; + const RzAnalVar *vb = b; return va->delta - vb->delta; } -static void __cmd_afvf(RCore *core, const char *input) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); - RListIter *iter; - RAnalVar *p; - RList *list = r_anal_var_all_list (core->anal, fcn); - r_list_sort (list, delta_cmp2); - r_list_foreach (list, iter, p) { +static void __cmd_afvf(RzCore *core, const char *input) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); + RzListIter *iter; + RzAnalVar *p; + RzList *list = rz_anal_var_all_list (core->anal, fcn); + rz_list_sort (list, delta_cmp2); + rz_list_foreach (list, iter, p) { if (p->isarg || p->delta > 0) { continue; } - const char *pad = r_str_pad (' ', 10 - strlen (p->name)); - r_cons_printf ("0x%08"PFMT64x" %s:%s%s\n", (ut64)-p->delta, p->name, pad, p->type); + const char *pad = rz_str_pad (' ', 10 - strlen (p->name)); + rz_cons_printf ("0x%08"PFMT64x" %s:%s%s\n", (ut64)-p->delta, p->name, pad, p->type); } - r_list_sort (list, delta_cmp); - r_list_foreach (list, iter, p) { + rz_list_sort (list, delta_cmp); + rz_list_foreach (list, iter, p) { if (!p->isarg && p->delta < 0) { continue; } // TODO: only stack vars if (p->kind == 's') { } - const char *pad = r_str_pad (' ', 10 - strlen (p->name)); + const char *pad = rz_str_pad (' ', 10 - strlen (p->name)); // XXX this 0x6a is a hack - r_cons_printf ("0x%08"PFMT64x" %s:%s%s\n", ((ut64)p->delta) - 0x6a, p->name, pad, p->type); + rz_cons_printf ("0x%08"PFMT64x" %s:%s%s\n", ((ut64)p->delta) - 0x6a, p->name, pad, p->type); } - r_list_free (list); + rz_list_free (list); } -static int var_cmd(RCore *core, const char *str) { +static int var_cmd(RzCore *core, const char *str) { int delta, type = *str, res = true; - RAnalVar *v1; + RzAnalVar *v1; if (!str[0]) { // "afv" - r_core_cmd0 (core, "afvs"); - r_core_cmd0 (core, "afvb"); - r_core_cmd0 (core, "afvr"); + rz_core_cmd0 (core, "afvs"); + rz_core_cmd0 (core, "afvb"); + rz_core_cmd0 (core, "afvr"); return true; } if (!str[0] || str[1] == '?'|| str[0] == '?') { @@ -1280,24 +1280,24 @@ static int var_cmd(RCore *core, const char *str) { } if (str[0] == 'j') { // "afvj" - r_cons_printf ("{\"sp\":"); - r_core_cmd0 (core, "afvsj"); - r_cons_printf (",\"bp\":"); - r_core_cmd0 (core, "afvbj"); - r_cons_printf (",\"reg\":"); - r_core_cmd0 (core, "afvrj"); - r_cons_printf ("}\n"); + rz_cons_printf ("{\"sp\":"); + rz_core_cmd0 (core, "afvsj"); + rz_cons_printf (",\"bp\":"); + rz_core_cmd0 (core, "afvbj"); + rz_cons_printf (",\"reg\":"); + rz_core_cmd0 (core, "afvrj"); + rz_cons_printf ("}\n"); return true; } char *p = strdup (str); char *ostr = p; - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); /* Variable access CFvs = set fun var */ switch (str[0]) { case '-': // "afv-" - r_core_cmdf (core, "afvs-%s", str + 1); - r_core_cmdf (core, "afvb-%s", str + 1); - r_core_cmdf (core, "afvr-%s", str + 1); + rz_core_cmdf (core, "afvs-%s", str + 1); + rz_core_cmdf (core, "afvb-%s", str + 1); + rz_core_cmdf (core, "afvr-%s", str + 1); return true; case 'x': // "afvx" if (fcn) { @@ -1313,7 +1313,7 @@ static int var_cmd(RCore *core, const char *str) { if (fcn) { const char *name = strchr (ostr, ' '); if (name) { - name = r_str_trim_head_ro (name); + name = rz_str_trim_head_ro (name); } PJ *pj = NULL; if (str[1] == 'j') { @@ -1323,7 +1323,7 @@ static int var_cmd(RCore *core, const char *str) { if (str[1] == 'j') { pj_end (pj); char *j = pj_drain (pj); - r_cons_printf ("%s\n", j); + rz_cons_printf ("%s\n", j); free (j); } return true; @@ -1333,8 +1333,8 @@ static int var_cmd(RCore *core, const char *str) { } case 'a': // "afva" if (fcn) { - r_anal_function_delete_all_vars (fcn); - r_core_recover_vars (core, fcn, false); + rz_anal_function_delete_all_vars (fcn); + rz_core_recover_vars (core, fcn, false); free (p); return true; } else { @@ -1343,51 +1343,51 @@ static int var_cmd(RCore *core, const char *str) { } case 'n': if (str[1]) { // "afvn" - RAnalOp *op = r_core_anal_op (core, core->offset, R_ANAL_OP_MASK_BASIC); - const char *new_name = r_str_trim_head_ro (strchr (ostr, ' ')); + RzAnalOp *op = rz_core_anal_op (core, core->offset, R_ANAL_OP_MASK_BASIC); + const char *new_name = rz_str_trim_head_ro (strchr (ostr, ' ')); if (!new_name) { - r_anal_op_free (op); + rz_anal_op_free (op); free (ostr); return false; } char *old_name = strchr (new_name, ' '); if (!old_name) { - RAnalVar *var = op ? r_anal_get_used_function_var (core->anal, op->addr) : NULL; + RzAnalVar *var = op ? rz_anal_get_used_function_var (core->anal, op->addr) : NULL; if (var) { old_name = var->name; } else { eprintf ("Cannot find var @ 0x%08"PFMT64x"\n", core->offset); - r_anal_op_free (op); + rz_anal_op_free (op); free (ostr); return false; } } else { *old_name++ = 0; - r_str_trim (old_name); + rz_str_trim (old_name); } if (fcn) { - v1 = r_anal_function_get_var_byname (fcn, old_name); + v1 = rz_anal_function_get_var_byname (fcn, old_name); if (v1) { - r_anal_var_rename (v1, new_name, true); + rz_anal_var_rename (v1, new_name, true); } else { eprintf ("Cant find var by name\n"); } } else { eprintf ("afv: Cannot find function in 0x%08"PFMT64x"\n", core->offset); - r_anal_op_free (op); + rz_anal_op_free (op); free (ostr); return false; } - r_anal_op_free (op); + rz_anal_op_free (op); free (ostr); } else { - RListIter *iter; - RAnalVar *v; - RList *list = r_anal_var_all_list (core->anal, fcn); - r_list_foreach (list, iter, v) { - r_cons_printf ("%s\n", v->name); + RzListIter *iter; + RzAnalVar *v; + RzList *list = rz_anal_var_all_list (core->anal, fcn); + rz_list_foreach (list, iter, v) { + rz_cons_printf ("%s\n", v->name); } - r_list_free (list); + rz_list_free (list); } return true; case 'd': // "afvd" @@ -1399,28 +1399,28 @@ static int var_cmd(RCore *core, const char *str) { free (ostr); return false; } - r_str_trim (p); - v1 = r_anal_function_get_var_byname (fcn, p); + rz_str_trim (p); + v1 = rz_anal_function_get_var_byname (fcn, p); if (!v1) { free (ostr); return false; } - r_anal_var_display (core->anal, v1); + rz_anal_var_display (core->anal, v1); free (ostr); } else { - RListIter *iter; - RAnalVar *p; - RList *list = r_anal_var_all_list (core->anal, fcn); - r_list_foreach (list, iter, p) { - char *a = r_core_cmd_strf (core, ".afvd %s", p->name); + RzListIter *iter; + RzAnalVar *p; + RzList *list = rz_anal_var_all_list (core->anal, fcn); + rz_list_foreach (list, iter, p) { + char *a = rz_core_cmd_strf (core, ".afvd %s", p->name); if ((a && !*a) || !a) { free (a); a = strdup ("\n"); } - r_cons_printf ("%s %s = %s", p->isarg ? "arg": "var", p->name, a); + rz_cons_printf ("%s %s = %s", p->isarg ? "arg": "var", p->name, a); free (a); } - r_list_free (list); + rz_list_free (list); } return true; case 'f': // "afvf" @@ -1440,13 +1440,13 @@ static int var_cmd(RCore *core, const char *str) { return false; } *type++ = 0; - v1 = r_anal_function_get_var_byname (fcn, p); + v1 = rz_anal_function_get_var_byname (fcn, p); if (!v1) { eprintf ("Cant find get by name %s\n", p); free (ostr); return false; } - r_anal_var_set_type (v1, type); + rz_anal_var_set_type (v1, type); free (ostr); return true; } else { @@ -1457,20 +1457,20 @@ static int var_cmd(RCore *core, const char *str) { switch (str[1]) { // afv[bsr] case '\0': case '*': // "afv[bsr]*" - r_anal_var_list_show (core->anal, fcn, type, str[1], NULL); + rz_anal_var_list_show (core->anal, fcn, type, str[1], NULL); break; case 'j': { // "afv[bsr]j" PJ *pj = pj_new (); if (!pj) { return -1; } - r_anal_var_list_show (core->anal, fcn, type, str[1], pj); - r_cons_println (pj_string (pj)); + rz_anal_var_list_show (core->anal, fcn, type, str[1], pj); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; case '.': // "afv[bsr]." - r_anal_var_list_show (core->anal, fcn, core->offset, 0, NULL); + rz_anal_var_list_show (core->anal, fcn, core->offset, 0, NULL); break; case '-': // "afv[bsr]-" if (!fcn) { @@ -1478,20 +1478,20 @@ static int var_cmd(RCore *core, const char *str) { return false; } if (str[2] == '*') { - r_anal_function_delete_vars_by_kind (fcn, type); + rz_anal_function_delete_vars_by_kind (fcn, type); } else { - RAnalVar *var = NULL; + RzAnalVar *var = NULL; if (IS_DIGIT (str[2])) { - var = r_anal_function_get_var (fcn, type, (int)r_num_math (core->num, str + 1)); + var = rz_anal_function_get_var (fcn, type, (int)rz_num_math (core->num, str + 1)); } else { - char *name = r_str_trim_dup (str + 2); + char *name = rz_str_trim_dup (str + 2); if (name) { - var = r_anal_function_get_var_byname (fcn, name); - r_free (name); + var = rz_anal_function_get_var_byname (fcn, name); + rz_free (name); } } if (var) { - r_anal_var_delete (var); + rz_anal_var_delete (var); } } break; @@ -1504,19 +1504,19 @@ static int var_cmd(RCore *core, const char *str) { case 's': // "afv[bsr]s" case 'g': // "afv[bsr]g" if (str[2] != '\0') { - int idx = r_num_math (core->num, str + 2); + int idx = rz_num_math (core->num, str + 2); char *vaddr; p = strchr (ostr, ' '); if (!p) { var_help (core, type); break; } - r_str_trim (p); + rz_str_trim (p); ut64 addr = core->offset; if ((vaddr = strchr (p , ' '))) { - addr = r_num_math (core->num, vaddr); + addr = rz_num_math (core->num, vaddr); } - RAnalVar *var = r_anal_function_get_var (fcn, str[0], idx); + RzAnalVar *var = rz_anal_function_get_var (fcn, str[0], idx); if (!var) { eprintf ("Cannot find variable with delta %d\n", idx); res = false; @@ -1524,10 +1524,10 @@ static int var_cmd(RCore *core, const char *str) { } int rw = (str[1] == 'g') ? R_ANAL_VAR_ACCESS_TYPE_READ : R_ANAL_VAR_ACCESS_TYPE_WRITE; int ptr = *var->type == 's' ? idx - fcn->maxstack : idx; - RAnalOp *op = r_core_anal_op (core, addr, 0); + RzAnalOp *op = rz_core_anal_op (core, addr, 0); const char *ireg = op ? op->ireg : NULL; - r_anal_var_set_access (var, ireg, addr, rw, ptr); - r_anal_op_free (op); + rz_anal_var_set_access (var, ireg, addr, rw, ptr); + rz_anal_op_free (op); } else { eprintf ("Missing argument\n"); } @@ -1545,17 +1545,17 @@ static int var_cmd(RCore *core, const char *str) { break; } *p++ = 0; - r_str_trim_head (p); + rz_str_trim_head (p); char *name = strchr (p, ' '); if (!name) { eprintf ("Missing name\n"); break; } *name++ = 0; - r_str_trim_head (name); + rz_str_trim_head (name); if (type == 'r') { //registers - RRegItem *i = r_reg_get (core->anal->reg, p, -1); + RzRegItem *i = rz_reg_get (core->anal->reg, p, -1); if (!i) { eprintf ("Register not found"); break; @@ -1563,7 +1563,7 @@ static int var_cmd(RCore *core, const char *str) { delta = i->index; isarg = true; } else { - delta = r_num_math (core->num, p); + delta = rz_num_math (core->num, p); } char *vartype = strchr (name, ' '); @@ -1571,7 +1571,7 @@ static int var_cmd(RCore *core, const char *str) { vartype = "int"; } else { *vartype++ = 0; - r_str_trim (vartype); + rz_str_trim (vartype); } if (type == 'b') { delta -= fcn->bp_off; @@ -1581,7 +1581,7 @@ static int var_cmd(RCore *core, const char *str) { } else if (type == 's' && delta > fcn->maxstack) { isarg = true; } - r_anal_function_set_var (fcn, delta, type, vartype, size, isarg, name); + rz_anal_function_set_var (fcn, delta, type, vartype, size, isarg, name); } break; } @@ -1589,32 +1589,32 @@ static int var_cmd(RCore *core, const char *str) { return res; } -static void print_trampolines(RCore *core, ut64 a, ut64 b, size_t element_size) { +static void print_trampolines(RzCore *core, ut64 a, ut64 b, size_t element_size) { int i; for (i = 0; i < core->blocksize; i += element_size) { ut32 n; memcpy (&n, core->block + i, sizeof (ut32)); if (n >= a && n <= b) { if (element_size == 4) { - r_cons_printf ("f trampoline.%x @ 0x%" PFMT64x "\n", n, core->offset + i); + rz_cons_printf ("f trampoline.%x @ 0x%" PFMT64x "\n", n, core->offset + i); } else { - r_cons_printf ("f trampoline.%" PFMT64x " @ 0x%" PFMT64x "\n", n, core->offset + i); + rz_cons_printf ("f trampoline.%" PFMT64x " @ 0x%" PFMT64x "\n", n, core->offset + i); } - r_cons_printf ("Cd %u @ 0x%" PFMT64x ":%u\n", element_size, core->offset + i, element_size); + rz_cons_printf ("Cd %u @ 0x%" PFMT64x ":%u\n", element_size, core->offset + i, element_size); // TODO: add data xrefs } } } -static void cmd_anal_trampoline(RCore *core, const char *input) { - int bits = r_config_get_i (core->config, "asm.bits"); +static void cmd_anal_trampoline(RzCore *core, const char *input) { + int bits = rz_config_get_i (core->config, "asm.bits"); char *p, *inp = strdup (input); p = strchr (inp, ' '); if (p) { *p = 0; } - ut64 a = r_num_math (core->num, inp); - ut64 b = p? r_num_math (core->num, p + 1): 0; + ut64 a = rz_num_math (core->num, inp); + ut64 b = p? rz_num_math (core->num, p + 1): 0; free (inp); switch (bits) { @@ -1631,30 +1631,30 @@ static const char *syscallNumber(int n) { return sdb_fmt (n > 1000 ? "0x%x" : "%d", n); } -R_API char *cmd_syscall_dostr(RCore *core, st64 n, ut64 addr) { +RZ_API char *cmd_syscall_dostr(RzCore *core, st64 n, ut64 addr) { int i; char str[64]; st64 N = n; - int defVector = r_syscall_get_swi (core->anal->syscall); + int defVector = rz_syscall_get_swi (core->anal->syscall); if (defVector > 0) { n = -1; } if (n == -1 || defVector > 0) { - n = (int)r_debug_reg_get (core->dbg, "oeax"); + n = (int)rz_debug_reg_get (core->dbg, "oeax"); if (!n || n == -1) { - const char *a0 = r_reg_get_name (core->anal->reg, R_REG_NAME_SN); - n = (a0 == NULL)? -1: (int)r_debug_reg_get (core->dbg, a0); + const char *a0 = rz_reg_get_name (core->anal->reg, R_REG_NAME_SN); + n = (a0 == NULL)? -1: (int)rz_debug_reg_get (core->dbg, a0); } } - RSyscallItem *item = r_syscall_get (core->anal->syscall, n, defVector); + RzSyscallItem *item = rz_syscall_get (core->anal->syscall, n, defVector); if (!item) { - item = r_syscall_get (core->anal->syscall, N, -1); + item = rz_syscall_get (core->anal->syscall, N, -1); } if (!item) { - return r_str_newf ("%s = unknown ()", syscallNumber (n)); + return rz_str_newf ("%s = unknown ()", syscallNumber (n)); } - char *res = r_str_newf ("%s = %s (", syscallNumber (item->num), item->name); - // TODO: move this to r_syscall + char *res = rz_str_newf ("%s = %s (", syscallNumber (item->num), item->name); + // TODO: move this to rz_syscall //TODO replace the hardcoded CC with the sdb ones for (i = 0; i < item->args; i++) { // XXX this is a hack to make syscall args work on x86-32 and x86-64 @@ -1663,103 +1663,103 @@ R_API char *cmd_syscall_dostr(RCore *core, st64 n, ut64 addr) { if (core->rasm->bits == 32 && !strcmp (core->rasm->cpu, "x86")) { regidx++; } - ut64 arg = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, regidx); - //r_cons_printf ("(%d:0x%"PFMT64x")\n", i, arg); + ut64 arg = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, regidx); + //rz_cons_printf ("(%d:0x%"PFMT64x")\n", i, arg); if (item->sargs) { switch (item->sargs[i]) { case 'p': // pointer - res = r_str_appendf (res, "0x%08" PFMT64x "", arg); + res = rz_str_appendf (res, "0x%08" PFMT64x "", arg); break; case 'i': - res = r_str_appendf (res, "%" PFMT64u "", arg); + res = rz_str_appendf (res, "%" PFMT64u "", arg); break; case 'z': memset (str, 0, sizeof (str)); - r_io_read_at (core->io, arg, (ut8 *)str, sizeof (str) - 1); - r_str_filter (str, strlen (str)); - res = r_str_appendf (res, "\"%s\"", str); + rz_io_read_at (core->io, arg, (ut8 *)str, sizeof (str) - 1); + rz_str_filter (str, strlen (str)); + res = rz_str_appendf (res, "\"%s\"", str); break; case 'Z': { //TODO replace the hardcoded CC with the sdb ones - ut64 len = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i + 2); + ut64 len = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i + 2); len = R_MIN (len + 1, sizeof (str) - 1); if (len == 0) { len = 16; // override default } - (void)r_io_read_at (core->io, arg, (ut8 *)str, len); + (void)rz_io_read_at (core->io, arg, (ut8 *)str, len); str[len] = 0; - r_str_filter (str, -1); - res = r_str_appendf (res, "\"%s\"", str); + rz_str_filter (str, -1); + res = rz_str_appendf (res, "\"%s\"", str); } break; default: - res = r_str_appendf (res, "0x%08" PFMT64x "", arg); + res = rz_str_appendf (res, "0x%08" PFMT64x "", arg); break; } } else { - res = r_str_appendf (res, "0x%08" PFMT64x "", arg); + res = rz_str_appendf (res, "0x%08" PFMT64x "", arg); } if (i + 1 < item->args) { - res = r_str_appendf (res, ", "); + res = rz_str_appendf (res, ", "); } } - r_syscall_item_free (item); - return r_str_appendf (res, ")"); + rz_syscall_item_free (item); + return rz_str_appendf (res, ")"); } -static int mw(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int mw(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { int *ec = (int*)esil->user; *ec += (len * 2); return 1; } -static int mr(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +static int mr(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { int *ec = (int*)esil->user; *ec += len; return 1; } -static int esil_cost(RCore *core, ut64 addr, const char *expr) { +static int esil_cost(RzCore *core, ut64 addr, const char *expr) { if (R_STR_ISEMPTY (expr)) { return 0; } int ec = 0; - RAnalEsil *e = r_anal_esil_new (256, 0, 0); - r_anal_esil_setup (e, core->anal, false, false, false); + RzAnalEsil *e = rz_anal_esil_new (256, 0, 0); + rz_anal_esil_setup (e, core->anal, false, false, false); e->user = &ec; e->cb.mem_read = mr; e->cb.mem_write = mw; - r_anal_esil_parse (e, expr); - r_anal_esil_free (e); + rz_anal_esil_parse (e, expr); + rz_anal_esil_free (e); return ec; } -static void cmd_syscall_do(RCore *core, st64 n, ut64 addr) { +static void cmd_syscall_do(RzCore *core, st64 n, ut64 addr) { char *msg = cmd_syscall_dostr (core, n, addr); if (msg) { - r_cons_println (msg); + rz_cons_println (msg); free (msg); } } -static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int fmt) { - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - bool iotrap = r_config_get_i (core->config, "esil.iotrap"); - bool romem = r_config_get_i (core->config, "esil.romem"); - bool stats = r_config_get_i (core->config, "esil.stats"); +static void core_anal_bytes(RzCore *core, const ut8 *buf, int len, int nops, int fmt) { + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + bool iotrap = rz_config_get_i (core->config, "esil.iotrap"); + bool romem = rz_config_get_i (core->config, "esil.romem"); + bool stats = rz_config_get_i (core->config, "esil.stats"); bool be = core->print->big_endian; bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - core->parser->subrel = r_config_get_i (core->config, "asm.sub.rel"); + core->parser->subrel = rz_config_get_i (core->config, "asm.sub.rel"); int ret, i, j, idx, size; const char *color = ""; const char *esilstr; const char *opexstr; - RAnalHint *hint; - RAnalEsil *esil = NULL; - RAsmOp asmop; - RAnalOp op = {0}; + RzAnalHint *hint; + RzAnalEsil *esil = NULL; + RzAsmOp asmop; + RzAnalOp op = {0}; ut64 addr; PJ *pj = NULL; - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); int totalsize = 0; // Variables required for setting up ESIL to REIL conversion @@ -1776,24 +1776,24 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } break; case 'r': // Setup for ESIL to REIL conversion - esil = r_anal_esil_new (stacksize, iotrap, addrsize); + esil = rz_anal_esil_new (stacksize, iotrap, addrsize); if (!esil) { return; } - r_anal_esil_to_reil_setup (esil, core->anal, romem, stats); - r_anal_esil_set_pc (esil, core->offset); + rz_anal_esil_to_reil_setup (esil, core->anal, romem, stats); + rz_anal_esil_set_pc (esil, core->offset); break; } for (i = idx = ret = 0; idx < len && (!nops || (nops && i < nops)); i++, idx += ret) { addr = core->offset + idx; - r_asm_set_pc (core->rasm, addr); - hint = r_anal_hint_get (core->anal, addr); - ret = r_anal_op (core->anal, &op, addr, buf + idx, len - idx, + rz_asm_set_pc (core->rasm, addr); + hint = rz_anal_hint_get (core->anal, addr); + ret = rz_anal_op (core->anal, &op, addr, buf + idx, len - idx, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_OPEX | R_ANAL_OP_MASK_HINT); - (void)r_asm_disassemble (core->rasm, &asmop, buf + idx, len - idx); + (void)rz_asm_disassemble (core->rasm, &asmop, buf + idx, len - idx); esilstr = R_STRBUF_SAFEGET (&op.esil); opexstr = R_STRBUF_SAFEGET (&op.opex); - char *mnem = strdup (r_asm_op_get_asm (&asmop)); + char *mnem = strdup (rz_asm_op_get_asm (&asmop)); char *sp = strchr (mnem, ' '); if (sp) { *sp = 0; @@ -1818,12 +1818,12 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } size = op.size; if (fmt == 'd') { - char *opname = strdup (r_asm_op_get_asm (&asmop)); + char *opname = strdup (rz_asm_op_get_asm (&asmop)); if (opname) { - r_str_split (opname, ' '); - char *d = r_asm_describe (core->rasm, opname); + rz_str_split (opname, ' '); + char *d = rz_asm_describe (core->rasm, opname); if (d && *d) { - r_cons_printf ("%s: %s\n", opname, d); + rz_cons_printf ("%s: %s\n", opname, d); free (d); } else { eprintf ("Unknown opcode\n"); @@ -1833,9 +1833,9 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } else if (fmt == 'e') { if (R_STR_ISNOTEMPTY (esilstr)) { if (use_color) { - r_cons_printf ("%s0x%" PFMT64x Color_RESET " %s\n", color, core->offset + idx, esilstr); + rz_cons_printf ("%s0x%" PFMT64x Color_RESET " %s\n", color, core->offset + idx, esilstr); } else { - r_cons_printf ("0x%" PFMT64x " %s\n", core->offset + idx, esilstr); + rz_cons_printf ("0x%" PFMT64x " %s\n", core->offset + idx, esilstr); } } } else if (fmt == 's') { @@ -1845,30 +1845,30 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } else if (fmt == 'j') { char strsub[128] = { 0 }; // pc+33 - r_parse_subvar (core->parser, NULL, + rz_parse_subvar (core->parser, NULL, core->offset + idx, - asmop.size, r_asm_op_get_asm (&asmop), + asmop.size, rz_asm_op_get_asm (&asmop), strsub, sizeof (strsub)); ut64 killme = UT64_MAX; - if (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { + if (rz_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { core->parser->subrel_addr = killme; } // 0x33->sym.xx char *p = strdup (strsub); if (p) { - r_parse_filter (core->parser, addr, core->flags, hint, p, + rz_parse_filter (core->parser, addr, core->flags, hint, p, strsub, sizeof (strsub), be); free (p); } pj_o (pj); - pj_ks (pj, "opcode", r_asm_op_get_asm (&asmop)); + pj_ks (pj, "opcode", rz_asm_op_get_asm (&asmop)); if (!*strsub) { - r_str_ncpy (strsub, r_asm_op_get_asm (&asmop), sizeof (strsub) -1 ); + rz_str_ncpy (strsub, rz_asm_op_get_asm (&asmop), sizeof (strsub) -1 ); } { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_parse_subvar (core->parser, fcn, addr, asmop.size, + rz_parse_subvar (core->parser, fcn, addr, asmop.size, strsub, strsub, sizeof (strsub)); } } @@ -1876,7 +1876,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int // apply pseudo if needed { char *pseudo = calloc (128 + strlen (strsub), 3); - r_parse_parse (core->parser, strsub, pseudo); + rz_parse_parse (core->parser, strsub, pseudo); if (pseudo && *pseudo) { pj_ks (pj, "pseudo", pseudo); } @@ -1888,7 +1888,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int if (sp) { *sp = 0; } - char *d = r_asm_describe (core->rasm, opname); + char *d = rz_asm_describe (core->rasm, opname); if (d && *d) { pj_ks (pj, "description", d); } @@ -1897,8 +1897,8 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } pj_ks (pj, "mnemonic", mnem); { - ut8 *mask = r_anal_mask (core->anal, len - idx, buf + idx, core->offset + idx); - char *maskstr = r_hex_bin2strdup (mask, size); + ut8 *mask = rz_anal_mask (core->anal, len - idx, buf + idx, core->offset + idx); + char *maskstr = rz_hex_bin2strdup (mask, size); pj_ks (pj, "mask", maskstr); free (mask); free (maskstr); @@ -1931,7 +1931,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int } pj_kn (pj, "addr", core->offset + idx); { - char *bytes = r_hex_bin2strdup (buf + idx, size); + char *bytes = rz_hex_bin2strdup (buf + idx, size); pj_ks (pj, "bytes", bytes); free (bytes); } @@ -1945,9 +1945,9 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int pj_kn (pj, "ptr", op.ptr); } pj_ki (pj, "size", size); - pj_ks (pj, "type", r_anal_optype_to_string (op.type)); + pj_ks (pj, "type", rz_anal_optype_to_string (op.type)); { - const char *datatype = r_anal_datatype_to_string (op.datatype); + const char *datatype = rz_anal_datatype_to_string (op.datatype); if (datatype) { pj_ks (pj, "datatype", datatype); } @@ -1970,62 +1970,62 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int pj_ki (pj, "cycles", op.cycles); pj_ki (pj, "failcycles", op.failcycles); pj_ki (pj, "delay", op.delay); - const char *p1 = r_anal_stackop_tostring (op.stackop); + const char *p1 = rz_anal_stackop_tostring (op.stackop); if (strcmp (p1, "null")) { pj_ks (pj, "stack", p1); } pj_kn (pj, "stackptr", op.stackptr); const char *arg = (op.type & R_ANAL_OP_TYPE_COND) - ? r_anal_cond_tostring (op.cond): NULL; + ? rz_anal_cond_tostring (op.cond): NULL; if (arg) { pj_ks (pj, "cond", arg); } - pj_ks (pj, "family", r_anal_op_family_to_string (op.family)); + pj_ks (pj, "family", rz_anal_op_family_to_string (op.family)); pj_end (pj); } else if (fmt == 'r') { if (R_STR_ISNOTEMPTY (esilstr)) { if (use_color) { - r_cons_printf ("%s0x%" PFMT64x Color_RESET "\n", color, core->offset + idx); + rz_cons_printf ("%s0x%" PFMT64x Color_RESET "\n", color, core->offset + idx); } else { - r_cons_printf ("0x%" PFMT64x "\n", core->offset + idx); + rz_cons_printf ("0x%" PFMT64x "\n", core->offset + idx); } - r_anal_esil_parse (esil, esilstr); - r_anal_esil_dumpstack (esil); - r_anal_esil_stack_free (esil); + rz_anal_esil_parse (esil, esilstr); + rz_anal_esil_dumpstack (esil); + rz_anal_esil_stack_free (esil); } } else { char disasm[128] = { 0 }; - r_parse_subvar (core->parser, NULL, + rz_parse_subvar (core->parser, NULL, core->offset + idx, - asmop.size, r_asm_op_get_asm (&asmop), + asmop.size, rz_asm_op_get_asm (&asmop), disasm, sizeof (disasm)); ut64 killme = UT64_MAX; - if (r_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { + if (rz_io_read_i (core->io, op.ptr, &killme, op.refptr, be)) { core->parser->subrel_addr = killme; } char *p = strdup (disasm); if (p) { - r_parse_filter (core->parser, addr, core->flags, hint, p, + rz_parse_filter (core->parser, addr, core->flags, hint, p, disasm, sizeof (disasm), be); free (p); } #define printline(k, fmt, arg)\ { \ if (use_color)\ - r_cons_printf ("%s%s: " Color_RESET, color, k);\ + rz_cons_printf ("%s%s: " Color_RESET, color, k);\ else\ - r_cons_printf ("%s: ", k);\ - if (fmt) r_cons_printf (fmt, arg);\ + rz_cons_printf ("%s: ", k);\ + if (fmt) rz_cons_printf (fmt, arg);\ } printline ("address", "0x%" PFMT64x "\n", core->offset + idx); - printline ("opcode", "%s\n", r_asm_op_get_asm (&asmop)); + printline ("opcode", "%s\n", rz_asm_op_get_asm (&asmop)); if (!*disasm) { - r_str_ncpy (disasm, r_asm_op_get_asm (&asmop), sizeof (disasm) - 1); + rz_str_ncpy (disasm, rz_asm_op_get_asm (&asmop), sizeof (disasm) - 1); } { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_parse_subvar (core->parser, fcn, addr, asmop.size, + rz_parse_subvar (core->parser, fcn, addr, asmop.size, disasm, disasm, sizeof (disasm)); } } @@ -2036,7 +2036,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int printline ("disasm", "%s\n", disasm); { char *pseudo = calloc (128 + strlen (disasm), 3); - r_parse_parse (core->parser, disasm, pseudo); + rz_parse_parse (core->parser, disasm, pseudo); if (pseudo && *pseudo) { printline ("pseudo", "%s\n", pseudo); } @@ -2049,7 +2049,7 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int if (sp) { *sp = 0; } - char *d = r_asm_describe (core->rasm, opname); + char *d = rz_asm_describe (core->rasm, opname); if (d && *d) { printline ("description", "%s\n", d); } @@ -2057,8 +2057,8 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int free (opname); } { - ut8 *mask = r_anal_mask (core->anal, len - idx, buf + idx, core->offset + idx); - char *maskstr = r_hex_bin2strdup (mask, size); + ut8 *mask = rz_anal_mask (core->anal, len - idx, buf + idx, core->offset + idx); + char *maskstr = rz_hex_bin2strdup (mask, size); printline ("mask", "%s\n", maskstr); free (mask); free (maskstr); @@ -2080,9 +2080,9 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int int minsz = R_MIN (len, size); minsz = R_MAX (minsz, 0); for (j = 0; j < minsz; j++) { - r_cons_printf ("%02x", buf[idx + j]); + rz_cons_printf ("%02x", buf[idx + j]); } - r_cons_newline (); + rz_cons_newline (); if (op.val != UT64_MAX) { printline ("val", "0x%08" PFMT64x "\n", op.val); } @@ -2096,9 +2096,9 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int printline ("refptr", "%d\n", op.refptr); } printline ("size", "%d\n", size); - printline ("sign", "%s\n", r_str_bool (op.sign)); - printline ("type", "%s\n", r_anal_optype_to_string (op.type)); - const char *datatype = r_anal_datatype_to_string (op.datatype); + printline ("sign", "%s\n", rz_str_bool (op.sign)); + printline ("type", "%s\n", rz_anal_optype_to_string (op.type)); + const char *datatype = rz_anal_datatype_to_string (op.datatype); if (datatype) { printline ("datatype", "%s\n", datatype); } @@ -2146,54 +2146,54 @@ static void core_anal_bytes(RCore *core, const ut8 *buf, int len, int nops, int printline ("delay", "%d\n", op.delay); } { - const char *arg = (op.type & R_ANAL_OP_TYPE_COND)? r_anal_cond_tostring (op.cond): NULL; + const char *arg = (op.type & R_ANAL_OP_TYPE_COND)? rz_anal_cond_tostring (op.cond): NULL; if (arg) { printline ("cond", "%s\n", arg); } } - printline ("family", "%s\n", r_anal_op_family_to_string (op.family)); + printline ("family", "%s\n", rz_anal_op_family_to_string (op.family)); if (op.stackop != R_ANAL_STACK_NULL) { - printline ("stackop", "%s\n", r_anal_stackop_tostring (op.stackop)); + printline ("stackop", "%s\n", rz_anal_stackop_tostring (op.stackop)); } if (op.stackptr) { printline ("stackptr", "%"PFMT64u"\n", op.stackptr); } } - //r_cons_printf ("false: 0x%08"PFMT64x"\n", core->offset+idx); + //rz_cons_printf ("false: 0x%08"PFMT64x"\n", core->offset+idx); //free (hint); free (mnem); - r_anal_hint_free (hint); - r_anal_op_fini (&op); + rz_anal_hint_free (hint); + rz_anal_op_fini (&op); } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); if (fmt == 's') { - r_cons_printf ("%d\n", totalsize); + rz_cons_printf ("%d\n", totalsize); } else if (fmt == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } - r_anal_esil_free (esil); + rz_anal_esil_free (esil); } static int bb_cmp(const void *a, const void *b) { - const RAnalBlock *ba = a; - const RAnalBlock *bb = b; + const RzAnalBlock *ba = a; + const RzAnalBlock *bb = b; return ba->addr - bb->addr; } static int casecmp(const void* _a, const void * _b) { - const RAnalCaseOp* a = _a; - const RAnalCaseOp* b = _b; + const RzAnalCaseOp* a = _a; + const RzAnalCaseOp* b = _b; return a->addr != b->addr; } -static ut64 __opaddr(RAnalBlock *b, ut64 addr) { +static ut64 __opaddr(RzAnalBlock *b, ut64 addr) { int i; if (addr >= b->addr && addr < (b->addr + b->size)) { for (i = 0; i < b->ninstr; i++) { - ut64 aa = b->addr + r_anal_bb_offset_inst (b, i); - ut64 ab = b->addr + r_anal_bb_offset_inst (b, i + 1); + ut64 aa = b->addr + rz_anal_bb_offset_inst (b, i); + ut64 ab = b->addr + rz_anal_bb_offset_inst (b, i + 1); if (addr >= aa && addr < ab) { return aa; } @@ -2202,69 +2202,69 @@ static ut64 __opaddr(RAnalBlock *b, ut64 addr) { return UT64_MAX; } -static RList *get_xrefs(RAnalBlock *block) { - RListIter *iter; - RAnalRef *ref; - RList *list = NULL; +static RzList *get_xrefs(RzAnalBlock *block) { + RzListIter *iter; + RzAnalRef *ref; + RzList *list = NULL; size_t i; for (i = 0; i < block->ninstr; i++) { ut64 ia = block->addr + block->op_pos[i]; - RList *xrefs = r_anal_xrefs_get (block->anal, ia); - r_list_foreach (xrefs, iter, ref) { + RzList *xrefs = rz_anal_xrefs_get (block->anal, ia); + rz_list_foreach (xrefs, iter, ref) { if (!list) { - list = r_list_newf (free); + list = rz_list_newf (free); } - r_list_push (list, ut64_new (ref->addr)); + rz_list_push (list, ut64_new (ref->addr)); } } return list; } -static char *fcnjoin(RList *list) { - RAnalFunction *n; - RListIter *iter; +static char *fcnjoin(RzList *list) { + RzAnalFunction *n; + RzListIter *iter; RStrBuf buf; - r_strbuf_init (&buf); - r_list_foreach (list, iter, n) { - r_strbuf_appendf (&buf, " 0x%08" PFMT64x, n->addr); + rz_strbuf_init (&buf); + rz_list_foreach (list, iter, n) { + rz_strbuf_appendf (&buf, " 0x%08" PFMT64x, n->addr); } - char *s = strdup (r_strbuf_get (&buf)); - r_strbuf_fini (&buf); + char *s = strdup (rz_strbuf_get (&buf)); + rz_strbuf_fini (&buf); return s; } -static char *ut64join(RList *list) { +static char *ut64join(RzList *list) { ut64 *n; - RListIter *iter; + RzListIter *iter; RStrBuf buf; - r_strbuf_init (&buf); - r_list_foreach (list, iter, n) { - r_strbuf_appendf (&buf, " 0x%08" PFMT64x, *n); + rz_strbuf_init (&buf); + rz_list_foreach (list, iter, n) { + rz_strbuf_appendf (&buf, " 0x%08" PFMT64x, *n); } - char *s = strdup (r_strbuf_get (&buf)); - r_strbuf_fini (&buf); + char *s = strdup (rz_strbuf_get (&buf)); + rz_strbuf_fini (&buf); return s; } -static RList *get_calls(RAnalBlock *block) { - RList *list = NULL; - RAnalOp op; +static RzList *get_calls(RzAnalBlock *block) { + RzList *list = NULL; + RzAnalOp op; ut8 *data = malloc (block->size); if (data) { block->anal->iob.read_at (block->anal->iob.io, block->addr, data, block->size); size_t i; for (i = 0; i < block->size; i++) { - int ret = r_anal_op (block->anal, &op, block->addr + i, data + i, block->size - i, R_ANAL_OP_MASK_HINT); + int ret = rz_anal_op (block->anal, &op, block->addr + i, data + i, block->size - i, R_ANAL_OP_MASK_HINT); if (ret < 1) { continue; } if (op.type == R_ANAL_OP_TYPE_CALL) { if (!list) { - list = r_list_newf (free); + list = rz_list_newf (free); } - r_list_push (list, ut64_new (op.jump)); + rz_list_push (list, ut64_new (op.jump)); } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); if (op.size > 0) { i += op.size - 1; } @@ -2274,38 +2274,38 @@ static RList *get_calls(RAnalBlock *block) { return list; } -static void anal_bb_list(RCore *core, const char *input) { +static void anal_bb_list(RzCore *core, const char *input) { const int mode = *input; PJ *pj = NULL; RTable *table = NULL; RBIter iter; - RAnalBlock *block; + RzAnalBlock *block; if (mode == 'j') { pj = pj_new (); pj_o (pj); pj_ka (pj, "blocks"); } else if (mode == ',' || mode == 't') { - table = r_table_new (); - RTableColumnType *s = r_table_type ("string"); - RTableColumnType *n = r_table_type ("number"); - r_table_add_column (table, n, "addr", 0); - r_table_add_column (table, n, "size", 0); - r_table_add_column (table, n, "traced", 0); - r_table_add_column (table, n, "ninstr", 0); - r_table_add_column (table, s, "jump", 0); - r_table_add_column (table, s, "fail", 0); - r_table_add_column (table, s, "fcns", 0); - r_table_add_column (table, s, "calls", 0); - r_table_add_column (table, s, "xrefs", 0); + table = rz_table_new (); + RTableColumnType *s = rz_table_type ("string"); + RTableColumnType *n = rz_table_type ("number"); + rz_table_add_column (table, n, "addr", 0); + rz_table_add_column (table, n, "size", 0); + rz_table_add_column (table, n, "traced", 0); + rz_table_add_column (table, n, "ninstr", 0); + rz_table_add_column (table, s, "jump", 0); + rz_table_add_column (table, s, "fail", 0); + rz_table_add_column (table, s, "fcns", 0); + rz_table_add_column (table, s, "calls", 0); + rz_table_add_column (table, s, "xrefs", 0); } - r_rbtree_foreach (core->anal->bb_tree, iter, block, RAnalBlock, _rb) { - RList *xrefs = get_xrefs (block); - RList *calls = get_calls (block); + rz_rbtree_foreach (core->anal->bb_tree, iter, block, RzAnalBlock, _rb) { + RzList *xrefs = get_xrefs (block); + RzList *calls = get_calls (block); switch (mode) { case 'j': pj_o (pj); - char *addr = r_str_newf ("0x%" PFMT64x, block->addr); + char *addr = rz_str_newf ("0x%" PFMT64x, block->addr); pj_ks (pj, "addr", addr); free (addr); pj_kb (pj, "traced", block->traced); @@ -2319,26 +2319,26 @@ static void anal_bb_list(RCore *core, const char *input) { } if (xrefs) { pj_ka (pj, "xrefs"); - RListIter *iter2; + RzListIter *iter2; ut64 *addr; - r_list_foreach (xrefs, iter2, addr) { + rz_list_foreach (xrefs, iter2, addr) { pj_n (pj, *addr); } pj_end (pj); } if (calls) { pj_ka (pj, "calls"); - RListIter *iter2; + RzListIter *iter2; ut64 *addr; - r_list_foreach (calls, iter2, addr) { + rz_list_foreach (calls, iter2, addr) { pj_n (pj, *addr); } pj_end (pj); } pj_ka (pj, "fcns"); - RListIter *iter2; - RAnalFunction *fcn; - r_list_foreach (block->fcns, iter2, fcn) { + RzListIter *iter2; + RzAnalFunction *fcn; + rz_list_foreach (block->fcns, iter2, fcn) { pj_n (pj, fcn->addr); } pj_end (pj); @@ -2347,12 +2347,12 @@ static void anal_bb_list(RCore *core, const char *input) { case ',': case 't': { - char *jump = block->jump != UT64_MAX? r_str_newf ("0x%08" PFMT64x, block->jump): strdup (""); - char *fail = block->fail != UT64_MAX? r_str_newf ("0x%08" PFMT64x, block->fail): strdup (""); + char *jump = block->jump != UT64_MAX? rz_str_newf ("0x%08" PFMT64x, block->jump): strdup (""); + char *fail = block->fail != UT64_MAX? rz_str_newf ("0x%08" PFMT64x, block->fail): strdup (""); char *call = ut64join (calls); char *xref = ut64join (calls); char *fcns = fcnjoin (block->fcns); - r_table_add_rowf (table, "xdddsssss", + rz_table_add_rowf (table, "xdddsssss", block->addr, block->size, block->traced, @@ -2371,65 +2371,65 @@ static void anal_bb_list(RCore *core, const char *input) { } break; case 'q': - r_cons_printf ("0x%08" PFMT64x"\n", block->addr); + rz_cons_printf ("0x%08" PFMT64x"\n", block->addr); break; default: - r_cons_printf ("0x%08" PFMT64x , block->addr); + rz_cons_printf ("0x%08" PFMT64x , block->addr); if (block->jump != UT64_MAX) { - r_cons_printf (" .j 0x%08" PFMT64x, block->jump); + rz_cons_printf (" .j 0x%08" PFMT64x, block->jump); } if (block->fail != UT64_MAX) { - r_cons_printf (" .f 0x%08" PFMT64x, block->fail); + rz_cons_printf (" .f 0x%08" PFMT64x, block->fail); } if (xrefs) { - RListIter *iter2; - r_cons_printf (" .x"); + RzListIter *iter2; + rz_cons_printf (" .x"); ut64 *addr; - r_list_foreach (xrefs, iter2, addr) { - r_cons_printf (" 0x%08" PFMT64x, *addr); + rz_list_foreach (xrefs, iter2, addr) { + rz_cons_printf (" 0x%08" PFMT64x, *addr); } } if (calls) { - r_cons_printf (" .c"); - RListIter *iter2; + rz_cons_printf (" .c"); + RzListIter *iter2; ut64 *addr; - r_list_foreach (calls, iter2, addr) { - r_cons_printf (" 0x%08" PFMT64x, *addr); + rz_list_foreach (calls, iter2, addr) { + rz_cons_printf (" 0x%08" PFMT64x, *addr); } } if (block->fcns) { - RListIter *iter2; - RAnalFunction *fcn; - r_list_foreach (block->fcns, iter2, fcn) { - r_cons_printf (" .u 0x%" PFMT64x, fcn->addr); + RzListIter *iter2; + RzAnalFunction *fcn; + rz_list_foreach (block->fcns, iter2, fcn) { + rz_cons_printf (" .u 0x%" PFMT64x, fcn->addr); } } - r_cons_printf (" .s %" PFMT64d "\n", block->size); + rz_cons_printf (" .s %" PFMT64d "\n", block->size); } - r_list_free (calls); + rz_list_free (calls); } if (mode == 'j') { pj_end (pj); pj_end (pj); char *j = pj_drain (pj); - r_cons_println (j); + rz_cons_println (j); free (j); } else if (mode == 't' || mode == ',') { char *q = strchr (input, ' '); if (q) { - r_table_query (table, q + 1); + rz_table_query (table, q + 1); } - char *s = r_table_tofancystring (table); - r_cons_println (s); + char *s = rz_table_tofancystring (table); + rz_cons_println (s); free (s); - r_table_free (table); + rz_table_free (table); } } -static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { - RDebugTracepoint *tp = NULL; - RListIter *iter; - RAnalBlock *b; +static bool anal_fcn_list_bb(RzCore *core, const char *input, bool one) { + RzDebugTracepoint *tp = NULL; + RzListIter *iter; + RzAnalBlock *b; int mode = 0; ut64 addr, bbaddr = UT64_MAX; PJ *pj = NULL; @@ -2447,14 +2447,14 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { input++; } if (input && *input) { - addr = bbaddr = r_num_math (core->num, input); + addr = bbaddr = rz_num_math (core->num, input); if (!addr && *input != '0') { addr = core->offset; } } else { addr = core->offset; } - input = r_str_trim_head_ro (input); + input = rz_str_trim_head_ro (input); if (one) { bbaddr = addr; } @@ -2465,51 +2465,51 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { } pj_a (pj); } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (!fcn) { if (mode == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } eprintf ("Cannot find function in 0x%08"PFMT64x"\n", addr); return false; } if (mode == '*') { - r_cons_printf ("fs blocks\n"); + rz_cons_printf ("fs blocks\n"); } if (fcn->bbs) { - r_list_sort (fcn->bbs, bb_cmp); + rz_list_sort (fcn->bbs, bb_cmp); } if (mode == '=') { // afb - RList *flist = r_list_newf ((RListFree) r_listinfo_free); + RzList *flist = rz_list_newf ((RzListFree) rz_listinfo_free); if (!flist) { return false; } ls_foreach (fcn->bbs, iter, b) { RInterval inter = (RInterval) {b->addr, b->size}; - RListInfo *info = r_listinfo_new (NULL, inter, inter, -1, NULL); + RzListInfo *info = rz_listinfo_new (NULL, inter, inter, -1, NULL); if (!info) { break; } - r_list_append (flist, info); + rz_list_append (flist, info); } - RTable *table = r_core_table (core); - r_table_visual_list (table, flist, core->offset, core->blocksize, - r_cons_get_size (NULL), r_config_get_i (core->config, "scr.color")); - r_cons_printf ("\n%s\n", r_table_tostring (table)); - r_table_free (table); - r_list_free (flist); + RTable *table = rz_core_table (core); + rz_table_visual_list (table, flist, core->offset, core->blocksize, + rz_cons_get_size (NULL), rz_config_get_i (core->config, "scr.color")); + rz_cons_printf ("\n%s\n", rz_table_tostring (table)); + rz_table_free (table); + rz_list_free (flist); return true; } RTable *t = NULL; if (mode == 't') { - t = r_table_new (); - r_table_set_columnsf (t, "xdxx", "addr", "size", "jump", "fail"); + t = rz_table_new (); + rz_table_set_columnsf (t, "xdxx", "addr", "size", "jump", "fail"); } if (fcn->bbs) { - r_list_foreach (fcn->bbs, iter, b) { + rz_list_foreach (fcn->bbs, iter, b) { if (one) { if (bbaddr != UT64_MAX && (bbaddr < b->addr || bbaddr >= (b->addr + b->size))) { continue; @@ -2517,39 +2517,39 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { } switch (mode) { case 't': - r_table_add_rowf (t, "xdxx", b->addr, b->size, b->jump, b->fail); + rz_table_add_rowf (t, "xdxx", b->addr, b->size, b->jump, b->fail); break; case 'r': if (b->jump == UT64_MAX) { - ut64 retaddr = r_anal_bb_opaddr_i (b, b->ninstr - 1); + ut64 retaddr = rz_anal_bb_opaddr_i (b, b->ninstr - 1); if (retaddr == UT64_MAX) { break; } if (!strcmp (input, "*")) { - r_cons_printf ("db 0x%08"PFMT64x"\n", retaddr); + rz_cons_printf ("db 0x%08"PFMT64x"\n", retaddr); } else if (!strcmp (input, "-*")) { - r_cons_printf ("db-0x%08"PFMT64x"\n", retaddr); + rz_cons_printf ("db-0x%08"PFMT64x"\n", retaddr); } else { - r_cons_printf ("0x%08"PFMT64x"\n", retaddr); + rz_cons_printf ("0x%08"PFMT64x"\n", retaddr); } } break; case '*': - r_cons_printf ("f bb.%05" PFMT64x " = 0x%08" PFMT64x "\n", + rz_cons_printf ("f bb.%05" PFMT64x " = 0x%08" PFMT64x "\n", b->addr & 0xFFFFF, b->addr); break; case 'q': - r_cons_printf ("0x%08" PFMT64x "\n", b->addr); + rz_cons_printf ("0x%08" PFMT64x "\n", b->addr); break; case 'j': - //r_cons_printf ("%" PFMT64u "%s", b->addr, iter->n? ",": ""); + //rz_cons_printf ("%" PFMT64u "%s", b->addr, iter->n? ",": ""); { - RListIter *iter2; - RAnalBlock *b2; + RzListIter *iter2; + RzAnalBlock *b2; int inputs = 0; int outputs = 0; - r_list_foreach (fcn->bbs, iter2, b2) { + rz_list_foreach (fcn->bbs, iter2, b2) { if (b2->jump == b->addr) { inputs++; } @@ -2581,9 +2581,9 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { pj_k (pj, "cases"); pj_a (pj); { - RListIter *case_op_iter; - RAnalCaseOp *case_op; - r_list_foreach (b->switch_op->cases, case_op_iter, case_op) { + RzListIter *case_op_iter; + RzAnalCaseOp *case_op; + rz_list_foreach (b->switch_op->cases, case_op_iter, case_op) { pj_o (pj); pj_kn (pj, "addr", case_op->addr); pj_kn (pj, "jump", case_op->jump); @@ -2609,11 +2609,11 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { break; case 'i': { - RListIter *iter2; - RAnalBlock *b2; + RzListIter *iter2; + RzAnalBlock *b2; int inputs = 0; int outputs = 0; - r_list_foreach (fcn->bbs, iter2, b2) { + rz_list_foreach (fcn->bbs, iter2, b2) { if (b2->jump == b->addr) { inputs++; } @@ -2628,103 +2628,103 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) { outputs ++; } if (b->switch_op) { - RList *unique_cases = r_list_uniq (b->switch_op->cases, casecmp); - outputs += r_list_length (unique_cases); - r_list_free (unique_cases); + RzList *unique_cases = rz_list_uniq (b->switch_op->cases, casecmp); + outputs += rz_list_length (unique_cases); + rz_list_free (unique_cases); } if (b->jump != UT64_MAX) { - r_cons_printf ("jump: 0x%08"PFMT64x"\n", b->jump); + rz_cons_printf ("jump: 0x%08"PFMT64x"\n", b->jump); } if (b->fail != UT64_MAX) { - r_cons_printf ("fail: 0x%08"PFMT64x"\n", b->fail); + rz_cons_printf ("fail: 0x%08"PFMT64x"\n", b->fail); } { ut64 opaddr = __opaddr (b, addr); - r_cons_printf ("opaddr: 0x%08"PFMT64x"\n", opaddr); + rz_cons_printf ("opaddr: 0x%08"PFMT64x"\n", opaddr); } - r_cons_printf ("addr: 0x%08"PFMT64x"\nsize: %d\ninputs: %d\noutputs: %d\nninstr: %d\ntraced: %s\n", - b->addr, b->size, inputs, outputs, b->ninstr, r_str_bool (b->traced)); + rz_cons_printf ("addr: 0x%08"PFMT64x"\nsize: %d\ninputs: %d\noutputs: %d\nninstr: %d\ntraced: %s\n", + b->addr, b->size, inputs, outputs, b->ninstr, rz_str_bool (b->traced)); } break; default: - tp = r_debug_trace_get (core->dbg, b->addr); - r_cons_printf ("0x%08" PFMT64x " 0x%08" PFMT64x " %02X:%04X %d", + tp = rz_debug_trace_get (core->dbg, b->addr); + rz_cons_printf ("0x%08" PFMT64x " 0x%08" PFMT64x " %02X:%04X %d", b->addr, b->addr + b->size, tp? tp->times: 0, tp? tp->count: 0, b->size); if (b->jump != UT64_MAX) { - r_cons_printf (" j 0x%08" PFMT64x, b->jump); + rz_cons_printf (" j 0x%08" PFMT64x, b->jump); } if (b->fail != UT64_MAX) { - r_cons_printf (" f 0x%08" PFMT64x, b->fail); + rz_cons_printf (" f 0x%08" PFMT64x, b->fail); } if (b->switch_op) { - RAnalCaseOp *cop; - RListIter *iter; - RList *unique_cases = r_list_uniq (b->switch_op->cases, casecmp); - r_list_foreach (unique_cases, iter, cop) { - r_cons_printf (" s 0x%08" PFMT64x, cop->addr); + RzAnalCaseOp *cop; + RzListIter *iter; + RzList *unique_cases = rz_list_uniq (b->switch_op->cases, casecmp); + rz_list_foreach (unique_cases, iter, cop) { + rz_cons_printf (" s 0x%08" PFMT64x, cop->addr); } - r_list_free (unique_cases); + rz_list_free (unique_cases); } - r_cons_newline (); + rz_cons_newline (); break; } } } if (mode == 't') { const char *arg = input; - if (r_table_query (t, arg)) { - char *ts = r_table_tofancystring (t); - r_cons_printf ("%s", ts); + if (rz_table_query (t, arg)) { + char *ts = rz_table_tofancystring (t); + rz_cons_printf ("%s", ts); free (ts); } - r_table_free (t); + rz_table_free (t); } else if (mode == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } return true; } -static bool anal_bb_edge (RCore *core, const char *input) { +static bool anal_bb_edge (RzCore *core, const char *input) { // "afbe" switch-bb-addr case-bb-addr - char *arg = strdup (r_str_trim_head_ro (input)); + char *arg = strdup (rz_str_trim_head_ro (input)); char *sp = strchr (arg, ' '); bool ret = false; if (sp) { *sp++ = 0; - ut64 switch_addr = r_num_math (core->num, arg); - ut64 case_addr = r_num_math (core->num, sp); - RList *blocks = r_anal_get_blocks_in (core->anal, switch_addr); - if (blocks && !r_list_empty (blocks)) { - r_anal_block_add_switch_case (r_list_first (blocks), switch_addr, 0, case_addr); + ut64 switch_addr = rz_num_math (core->num, arg); + ut64 case_addr = rz_num_math (core->num, sp); + RzList *blocks = rz_anal_get_blocks_in (core->anal, switch_addr); + if (blocks && !rz_list_empty (blocks)) { + rz_anal_block_add_switch_case (rz_list_first (blocks), switch_addr, 0, case_addr); ret = true; } - r_list_free (blocks); + rz_list_free (blocks); } free (arg); return ret; } -static bool anal_fcn_del_bb(RCore *core, const char *input) { - ut64 addr = r_num_math (core->num, input); +static bool anal_fcn_del_bb(RzCore *core, const char *input) { + ut64 addr = rz_num_math (core->num, input); if (!addr) { addr = core->offset; } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, -1); if (fcn) { if (!strcmp (input, "*")) { - while (!r_list_empty (fcn->bbs)) { - r_anal_function_remove_block (fcn, r_list_first (fcn->bbs)); + while (!rz_list_empty (fcn->bbs)) { + rz_anal_function_remove_block (fcn, rz_list_first (fcn->bbs)); } } else { - RAnalBlock *b; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, b) { + RzAnalBlock *b; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, b) { if (b->addr == addr) { - r_anal_function_remove_block (fcn, b); + rz_anal_function_remove_block (fcn, b); return true; } } @@ -2736,7 +2736,7 @@ static bool anal_fcn_del_bb(RCore *core, const char *input) { return false; } -static int anal_fcn_add_bb(RCore *core, const char *input) { +static int anal_fcn_add_bb(RzCore *core, const char *input) { // fcn_addr bb_addr bb_size [jump] [fail] char *ptr; const char *ptr2 = NULL; @@ -2744,17 +2744,17 @@ static int anal_fcn_add_bb(RCore *core, const char *input) { ut64 size = 0LL; ut64 jump = UT64_MAX; ut64 fail = UT64_MAX; - RAnalFunction *fcn = NULL; - RAnalDiff *diff = NULL; + RzAnalFunction *fcn = NULL; + RzAnalDiff *diff = NULL; while (*input == ' ') input++; ptr = strdup (input); - switch (r_str_word_set0 (ptr)) { + switch (rz_str_word_set0 (ptr)) { case 6: - ptr2 = r_str_word_get0 (ptr, 6); - if (!(diff = r_anal_diff_new ())) { - eprintf ("error: Cannot init RAnalDiff\n"); + ptr2 = rz_str_word_get0 (ptr, 6); + if (!(diff = rz_anal_diff_new ())) { + eprintf ("error: Cannot init RzAnalDiff\n"); free (ptr); return false; } @@ -2764,20 +2764,20 @@ static int anal_fcn_add_bb(RCore *core, const char *input) { diff->type = R_ANAL_DIFF_TYPE_UNMATCH; } case 5: // get fail - fail = r_num_math (core->num, r_str_word_get0 (ptr, 4)); + fail = rz_num_math (core->num, rz_str_word_get0 (ptr, 4)); case 4: // get jump - jump = r_num_math (core->num, r_str_word_get0 (ptr, 3)); + jump = rz_num_math (core->num, rz_str_word_get0 (ptr, 3)); case 3: // get size - size = r_num_math (core->num, r_str_word_get0 (ptr, 2)); + size = rz_num_math (core->num, rz_str_word_get0 (ptr, 2)); case 2: // get addr - addr = r_num_math (core->num, r_str_word_get0 (ptr, 1)); + addr = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); case 1: // get fcnaddr - fcnaddr = r_num_math (core->num, r_str_word_get0 (ptr, 0)); + fcnaddr = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); } - fcn = r_anal_get_function_at (core->anal, fcnaddr); + fcn = rz_anal_get_function_at (core->anal, fcnaddr); if (fcn) { - if (!r_anal_fcn_add_bb (core->anal, fcn, addr, size, jump, fail, diff)) - //if (!r_anal_fcn_add_bb_raw (core->anal, fcn, addr, size, jump, fail, type, diff)) + if (!rz_anal_fcn_add_bb (core->anal, fcn, addr, size, jump, fail, diff)) + //if (!rz_anal_fcn_add_bb_raw (core->anal, fcn, addr, size, jump, fail, type, diff)) { eprintf ("afb+: Cannot add basic block at 0x%08"PFMT64x"\n", addr); } @@ -2785,19 +2785,19 @@ static int anal_fcn_add_bb(RCore *core, const char *input) { eprintf ("afb+ Cannot find function at 0x%" PFMT64x " from 0x%08"PFMT64x" -> 0x%08"PFMT64x"\n", fcnaddr, addr, jump); } - r_anal_diff_free (diff); + rz_anal_diff_free (diff); free (ptr); return true; } -static void r_core_anal_nofunclist (RCore *core, const char *input) { - int minlen = (int)(input[0]==' ') ? r_num_math (core->num, input + 1): 16; - ut64 code_size = r_num_get (core->num, "$SS"); - ut64 base_addr = r_num_get (core->num, "$S"); +static void rz_core_anal_nofunclist (RzCore *core, const char *input) { + int minlen = (int)(input[0]==' ') ? rz_num_math (core->num, input + 1): 16; + ut64 code_size = rz_num_get (core->num, "$SS"); + ut64 base_addr = rz_num_get (core->num, "$S"); ut64 chunk_size, chunk_offset, i; - RListIter *iter, *iter2; - RAnalFunction *fcn; - RAnalBlock *b; + RzListIter *iter, *iter2; + RzAnalFunction *fcn; + RzAnalBlock *b; char* bitmap; int counter; @@ -2813,9 +2813,9 @@ static void r_core_anal_nofunclist (RCore *core, const char *input) { } // for each function - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { // for each basic block in the function - r_list_foreach (fcn->bbs, iter2, b) { + rz_list_foreach (fcn->bbs, iter2, b) { // if it is not withing range, continue if ((fcn->addr < base_addr) || (fcn->addr >= base_addr+code_size)) continue; @@ -2836,11 +2836,11 @@ static void r_core_anal_nofunclist (RCore *core, const char *input) { if (bitmap[i]){ // We only print a region is its size is bigger than 15 bytes if (chunk_size >= minlen){ - fcn = r_anal_get_fcn_in (core->anal, base_addr+chunk_offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); + fcn = rz_anal_get_fcn_in (core->anal, base_addr+chunk_offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (fcn) { - r_cons_printf ("0x%08"PFMT64x" %6d %s\n", base_addr+chunk_offset, chunk_size, fcn->name); + rz_cons_printf ("0x%08"PFMT64x" %6d %s\n", base_addr+chunk_offset, chunk_size, fcn->name); } else { - r_cons_printf ("0x%08"PFMT64x" %6d\n", base_addr+chunk_offset, chunk_size); + rz_cons_printf ("0x%08"PFMT64x" %6d\n", base_addr+chunk_offset, chunk_size); } } chunk_size = 0; @@ -2850,24 +2850,24 @@ static void r_core_anal_nofunclist (RCore *core, const char *input) { chunk_size+=1; } if (chunk_size >= 16) { - fcn = r_anal_get_fcn_in (core->anal, base_addr+chunk_offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); + fcn = rz_anal_get_fcn_in (core->anal, base_addr+chunk_offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (fcn) { - r_cons_printf ("0x%08"PFMT64x" %6d %s\n", base_addr+chunk_offset, chunk_size, fcn->name); + rz_cons_printf ("0x%08"PFMT64x" %6d %s\n", base_addr+chunk_offset, chunk_size, fcn->name); } else { - r_cons_printf ("0x%08"PFMT64x" %6d\n", base_addr+chunk_offset, chunk_size); + rz_cons_printf ("0x%08"PFMT64x" %6d\n", base_addr+chunk_offset, chunk_size); } } free(bitmap); } -static void r_core_anal_fmap (RCore *core, const char *input) { - int show_color = r_config_get_i (core->config, "scr.color"); - int cols = r_config_get_i (core->config, "hex.cols") * 4; - ut64 code_size = r_num_get (core->num, "$SS"); - ut64 base_addr = r_num_get (core->num, "$S"); - RListIter *iter, *iter2; - RAnalFunction *fcn; - RAnalBlock *b; +static void rz_core_anal_fmap (RzCore *core, const char *input) { + int show_color = rz_config_get_i (core->config, "scr.color"); + int cols = rz_config_get_i (core->config, "hex.cols") * 4; + ut64 code_size = rz_num_get (core->num, "$SS"); + ut64 base_addr = rz_num_get (core->num, "$S"); + RzListIter *iter, *iter2; + RzAnalFunction *fcn; + RzAnalBlock *b; char* bitmap; int assigned; ut64 i; @@ -2881,9 +2881,9 @@ static void r_core_anal_fmap (RCore *core, const char *input) { } // for each function - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { // for each basic block in the function - r_list_foreach (fcn->bbs, iter2, b) { + rz_list_foreach (fcn->bbs, iter2, b) { // if it is not within range, continue if ((fcn->addr < base_addr) || (fcn->addr >= base_addr+code_size)) continue; @@ -2902,22 +2902,22 @@ static void r_core_anal_fmap (RCore *core, const char *input) { } for (i = 0; i < code_size; i += 1) { if (!(i % cols)) { - r_cons_printf ("\n0x%08"PFMT64x" ", base_addr+i); + rz_cons_printf ("\n0x%08"PFMT64x" ", base_addr+i); } if (bitmap[i]) { assigned++; } if (show_color) { if (bitmap[i]) { - r_cons_printf ("%s%c\x1b[0m", Color_GREEN, bitmap[i]); + rz_cons_printf ("%s%c\x1b[0m", Color_GREEN, bitmap[i]); } else { - r_cons_printf ("."); + rz_cons_printf ("."); } } else { - r_cons_printf ("%c", bitmap[i] ? bitmap[i] : '.' ); + rz_cons_printf ("%c", bitmap[i] ? bitmap[i] : '.' ); } } - r_cons_printf ("\n%d / %d (%.2lf%%) bytes assigned to a function\n", assigned, code_size, 100.0*( (float) assigned) / code_size); + rz_cons_printf ("\n%d / %d (%.2lf%%) bytes assigned to a function\n", assigned, code_size, 100.0*( (float) assigned) / code_size); free(bitmap); } @@ -2931,40 +2931,40 @@ static bool fcnNeedsPrefix(const char *name) { return (!strchr (name, '.')); } -static char * getFunctionName (RCore *core, ut64 off, const char *name, bool prefix) { +static char * getFunctionName (RzCore *core, ut64 off, const char *name, bool prefix) { const char *fcnpfx = ""; if (prefix) { if (fcnNeedsPrefix (name) && (!fcnpfx || !*fcnpfx)) { fcnpfx = "fcn"; } else { - fcnpfx = r_config_get (core->config, "anal.fcnprefix"); + fcnpfx = rz_config_get (core->config, "anal.fcnprefix"); } } - if (r_reg_get (core->anal->reg, name, -1)) { - return r_str_newf ("%s.%08"PFMT64x, "fcn", off); + if (rz_reg_get (core->anal->reg, name, -1)) { + return rz_str_newf ("%s.%08"PFMT64x, "fcn", off); } - return strdup (name); // r_str_newf ("%s%s%s", fcnpfx, *fcnpfx? ".": "", name); + return strdup (name); // rz_str_newf ("%s%s%s", fcnpfx, *fcnpfx? ".": "", name); } -/* TODO: move into r_anal_function_rename (); */ -static bool __setFunctionName(RCore *core, ut64 addr, const char *_name, bool prefix) { - r_return_val_if_fail (core && _name, false); - _name = r_str_trim_head_ro (_name); +/* TODO: move into rz_anal_function_rename (); */ +static bool __setFunctionName(RzCore *core, ut64 addr, const char *_name, bool prefix) { + rz_return_val_if_fail (core && _name, false); + _name = rz_str_trim_head_ro (_name); char *name = getFunctionName (core, addr, _name, prefix); - // RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_ANY); - RAnalFunction *fcn = r_anal_get_function_at (core->anal, addr); + // RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_ANY); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, addr); if (fcn) { - RFlagItem *flag = r_flag_get (core->flags, fcn->name); + RzFlagItem *flag = rz_flag_get (core->flags, fcn->name); if (flag && flag->space && strcmp (flag->space->name, R_FLAGS_FS_FUNCTIONS) == 0) { // Only flags in the functions fs should be renamed, e.g. we don't want to rename symbol flags. - r_flag_rename (core->flags, flag, name); + rz_flag_rename (core->flags, flag, name); } else { // No flag or not specific to the function, create a new one. - r_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); - r_flag_set (core->flags, name, fcn->addr, r_anal_function_size_from_entry (fcn)); - r_flag_space_pop (core->flags); + rz_flag_space_push (core->flags, R_FLAGS_FS_FUNCTIONS); + rz_flag_set (core->flags, name, fcn->addr, rz_anal_function_size_from_entry (fcn)); + rz_flag_space_pop (core->flags); } - r_anal_function_rename (fcn, name); + rz_anal_function_rename (fcn, name); if (core->anal->cb.on_fcn_rename) { core->anal->cb.on_fcn_rename (core->anal, core->anal->user, fcn, name); } @@ -2975,41 +2975,41 @@ static bool __setFunctionName(RCore *core, ut64 addr, const char *_name, bool pr return false; } -static void afCc(RCore *core, const char *input) { +static void afCc(RzCore *core, const char *input) { ut64 addr; - RAnalFunction *fcn; + RzAnalFunction *fcn; if (*input == ' ') { - addr = r_num_math (core->num, input); + addr = rz_num_math (core->num, input); } else { addr = core->offset; } if (addr == 0LL) { - fcn = r_anal_get_function_byname (core->anal, input + 3); + fcn = rz_anal_get_function_byname (core->anal, input + 3); } else { - fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); } if (fcn) { - ut32 totalCycles = r_anal_function_cost (fcn); + ut32 totalCycles = rz_anal_function_cost (fcn); // FIXME: This defeats the purpose of the function, but afC is used in project files. // cf. canal.c - r_cons_printf ("%d\n", totalCycles); + rz_cons_printf ("%d\n", totalCycles); } else { eprintf ("afCc: Cannot find function\n"); } } -static void cmd_anal_fcn_sig(RCore *core, const char *input) { +static void cmd_anal_fcn_sig(RzCore *core, const char *input) { bool json = (input[0] == 'j'); char *p = strchr (input, ' '); - char *fcn_name = p ? r_str_trim_dup (p): NULL; - RListIter *iter; - RAnalFuncArg *arg; + char *fcn_name = p ? rz_str_trim_dup (p): NULL; + RzListIter *iter; + RzAnalFuncArg *arg; - RAnalFunction *fcn; + RzAnalFunction *fcn; if (fcn_name) { - fcn = r_anal_get_function_byname (core->anal, fcn_name); + fcn = rz_anal_get_function_byname (core->anal, fcn_name); } else { - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { fcn_name = fcn->name; } @@ -3031,24 +3031,24 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) { } if (key) { - const char *fcn_type = r_type_func_ret (core->anal->sdb_types, key); - int nargs = r_type_func_args_count (core->anal->sdb_types, key); + const char *fcn_type = rz_type_func_ret (core->anal->sdb_types, key); + int nargs = rz_type_func_args_count (core->anal->sdb_types, key); if (fcn_type) { pj_o (j); - pj_ks (j, "name", r_str_get (key)); - pj_ks (j, "return", r_str_get (fcn_type)); + pj_ks (j, "name", rz_str_get (key)); + pj_ks (j, "return", rz_str_get (fcn_type)); pj_k (j, "args"); pj_a (j); if (nargs) { - RList *list = r_core_get_func_args (core, fcn_name); - r_list_foreach (list, iter, arg) { + RzList *list = rz_core_get_func_args (core, fcn_name); + rz_list_foreach (list, iter, arg) { char *type = arg->orig_c_type; pj_o (j); pj_ks (j, "name", arg->name); pj_ks (j, "type", type); pj_end (j); } - r_list_free (list); + rz_list_free (list); } pj_end (j); pj_ki (j, "count", nargs); @@ -3057,22 +3057,22 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) { free (key); } else { pj_o (j); - pj_ks (j, "name", r_str_get (fcn_name)); + pj_ks (j, "name", rz_str_get (fcn_name)); pj_k (j, "args"); pj_a (j); - RAnalFcnVarsCache cache; - r_anal_fcn_vars_cache_init (core->anal, &cache, fcn); + RzAnalFcnVarsCache cache; + rz_anal_fcn_vars_cache_init (core->anal, &cache, fcn); int nargs = 0; - RAnalVar *var; - r_list_foreach (cache.rvars, iter, var) { + RzAnalVar *var; + rz_list_foreach (cache.rvars, iter, var) { nargs++; pj_o (j); pj_ks (j, "name", var->name); pj_ks (j, "type", var->type); pj_end (j); } - r_list_foreach (cache.bvars, iter, var) { + rz_list_foreach (cache.bvars, iter, var) { if (var->delta <= 0) { continue; } @@ -3082,7 +3082,7 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) { pj_ks (j, "type", var->type); pj_end (j); } - r_list_foreach (cache.svars, iter, var) { + rz_list_foreach (cache.svars, iter, var) { if (!var->isarg) { continue; } @@ -3092,7 +3092,7 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) { pj_ks (j, "type", var->type); pj_end (j); } - r_anal_fcn_vars_cache_fini (&cache); + rz_anal_fcn_vars_cache_fini (&cache); pj_end (j); pj_ki (j, "count", nargs); @@ -3101,28 +3101,28 @@ static void cmd_anal_fcn_sig(RCore *core, const char *input) { pj_end (j); const char *s = pj_string (j); if (s) { - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); } pj_free (j); } else { - char *sig = r_anal_fcn_format_sig (core->anal, fcn, fcn_name, NULL, NULL, NULL); + char *sig = rz_anal_fcn_format_sig (core->anal, fcn, fcn_name, NULL, NULL, NULL); if (sig) { - r_cons_printf ("%s\n", sig); + rz_cons_printf ("%s\n", sig); free (sig); } } } -static void __updateStats(RCore *core, Sdb *db, ut64 addr, int statsMode) { - RAnalOp *op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_DISASM); +static void __updateStats(RzCore *core, Sdb *db, ut64 addr, int statsMode) { + RzAnalOp *op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_DISASM); if (!op) { return; } if (statsMode == 'f') { - const char *family = r_anal_op_family_to_string (op->family); + const char *family = rz_anal_op_family_to_string (op->family); sdb_num_inc (db, family, 1, 0); } else if (statsMode == 'o') { - const char *type = r_anal_optype_to_string (op->type); + const char *type = rz_anal_optype_to_string (op->type); sdb_num_inc (db, type, 1, 0); } else { char *mnem = strdup (op->mnemonic); @@ -3134,13 +3134,13 @@ static void __updateStats(RCore *core, Sdb *db, ut64 addr, int statsMode) { sdb_num_inc (db, mnem, 1, 0); } //sdb_set (db, family, "1", 0); - //r_cons_printf ("0x%08"PFMT64x" %s\n", addr, family); - r_anal_op_free (op); - // r_core_cmdf (core, "pd 1 @ 0x%08"PFMT64x"\n", addr); + //rz_cons_printf ("0x%08"PFMT64x" %s\n", addr, family); + rz_anal_op_free (op); + // rz_core_cmdf (core, "pd 1 @ 0x%08"PFMT64x"\n", addr); } -static Sdb *__core_cmd_anal_fcn_stats (RCore *core, const char *input) { +static Sdb *__core_cmd_anal_fcn_stats (RzCore *core, const char *input) { bool silentMode = false; int statsMode = 0; if (*input == '*') { @@ -3163,15 +3163,15 @@ static Sdb *__core_cmd_anal_fcn_stats (RCore *core, const char *input) { break; } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (!fcn) { eprintf ("Cannot find any function at 0x%08"PFMT64x"\n", core->offset); return NULL; } Sdb *db = sdb_new0 (); - RAnalBlock *bb; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, bb) { + RzAnalBlock *bb; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, bb) { int i; __updateStats (core, db, bb->addr, statsMode); for (i = 0; i< bb->op_pos_size; i++) { @@ -3184,28 +3184,28 @@ static Sdb *__core_cmd_anal_fcn_stats (RCore *core, const char *input) { } else if (*input == 't') { SdbList *ls = sdb_foreach_list (db, true); SdbListIter *it; - RTable *t = r_table_new (); + RTable *t = rz_table_new (); SdbKv *kv; - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - r_table_add_column (t, typeString, "name", 0); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + rz_table_add_column (t, typeString, "name", 0); ls_foreach (ls, it, kv) { const char *key = sdbkv_key (kv); - r_table_add_column (t, typeNumber, key, 0); + rz_table_add_column (t, typeNumber, key, 0); } - RList *items = r_list_newf (free); - r_list_append (items, fcn->name); + RzList *items = rz_list_newf (free); + rz_list_append (items, fcn->name); ls_foreach (ls, it, kv) { const char *value = sdbkv_value (kv); - int nv = (int)r_num_get (NULL, value); - r_list_append (items, r_str_newf ("%d", nv)); + int nv = (int)rz_num_get (NULL, value); + rz_list_append (items, rz_str_newf ("%d", nv)); } - r_table_add_row_list (t, items); - r_table_query (t, input + 1); - char *ts = r_table_tostring (t); - r_cons_printf ("%s", ts); + rz_table_add_row_list (t, items); + rz_table_query (t, input + 1); + char *ts = rz_table_tostring (t); + rz_cons_printf ("%s", ts); free (ts); - r_table_free (t); + rz_table_free (t); } else { SdbList *ls = sdb_foreach_list (db, true); SdbListIter *it; @@ -3213,33 +3213,33 @@ static Sdb *__core_cmd_anal_fcn_stats (RCore *core, const char *input) { ls_foreach (ls, it, kv) { const char *key = sdbkv_key(kv); const char *value = sdbkv_value(kv); - r_cons_printf ("%4d %s\n", (int)r_num_get (NULL, value), key); + rz_cons_printf ("%4d %s\n", (int)rz_num_get (NULL, value), key); } } return db; //sdb_free (db); } -static void __core_cmd_anal_fcn_allstats(RCore *core, const char *input) { - RAnalFunction *fcn; +static void __core_cmd_anal_fcn_allstats(RzCore *core, const char *input) { + RzAnalFunction *fcn; SdbKv *kv; - RListIter *iter; + RzListIter *iter; SdbListIter *it; - RList *dbs = r_list_newf ((RListFree)sdb_free); + RzList *dbs = rz_list_newf ((RzListFree)sdb_free); Sdb *d = sdb_new0 (); ut64 oseek = core->offset; bool isJson = strchr (input, 'j') != NULL; - char *inp = r_str_newf ("*%s", input); - r_list_foreach (core->anal->fcns, iter, fcn) { - r_core_seek (core, fcn->addr, true); + char *inp = rz_str_newf ("*%s", input); + rz_list_foreach (core->anal->fcns, iter, fcn) { + rz_core_seek (core, fcn->addr, true); Sdb *db = __core_cmd_anal_fcn_stats (core, inp); sdb_num_set (db, ".addr", fcn->addr, 0); - r_list_append (dbs, db); + rz_list_append (dbs, db); } free (inp); Sdb *db; - r_list_foreach (dbs, iter, db) { + rz_list_foreach (dbs, iter, db) { SdbList *ls = sdb_foreach_list (db, true); ls_foreach (ls, it, kv) { const char *name = sdbkv_key(kv); @@ -3247,20 +3247,20 @@ static void __core_cmd_anal_fcn_allstats(RCore *core, const char *input) { } ls_free (ls); } - RTable *t = r_table_new (); + RTable *t = rz_table_new (); SdbList *ls = sdb_foreach_list (d, true); - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - r_table_add_column (t, typeString, "name", 0); - r_table_add_column (t, typeNumber, "addr", 0); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + rz_table_add_column (t, typeString, "name", 0); + rz_table_add_column (t, typeNumber, "addr", 0); ls_foreach (ls, it, kv) { const char *key = sdbkv_key (kv); if (*key == '.') continue; - r_table_add_column (t, typeNumber, key, 0); + rz_table_add_column (t, typeNumber, key, 0); } sdb_free (d); - r_list_foreach (dbs, iter, db) { + rz_list_foreach (dbs, iter, db) { SdbList *ls = sdb_foreach_list (db, false); SdbListIter *it; SdbKv *kv; @@ -3275,104 +3275,104 @@ static void __core_cmd_anal_fcn_allstats(RCore *core, const char *input) { if (*key == '.') { continue; } - int idx = r_table_column_nth (t, key); + int idx = rz_table_column_nth (t, key); if (idx != -1) { - ut64 nv = r_num_get (NULL, value); - names[idx] = r_str_newf ("%d", (int)nv); + ut64 nv = rz_num_get (NULL, value); + names[idx] = rz_str_newf ("%d", (int)nv); } else { eprintf ("Invalid column name (%s) %c", key, 10); } } - RList *items = r_list_newf (free); + RzList *items = rz_list_newf (free); ut64 fcnAddr = sdb_num_get (db, ".addr", 0); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, fcnAddr, 0); - r_list_append (items, fcn?strdup (fcn->name):strdup ("")); - r_list_append (items, fcn?r_str_newf ("0x%08"PFMT64x, fcnAddr): strdup ("0")); - int cols = r_list_length (t->cols); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, fcnAddr, 0); + rz_list_append (items, fcn?strdup (fcn->name):strdup ("")); + rz_list_append (items, fcn?rz_str_newf ("0x%08"PFMT64x, fcnAddr): strdup ("0")); + int cols = rz_list_length (t->cols); for (i = 2; i < cols; i++) { if (names[i]) { if (names[i][0] != '.') { - r_list_append (items, strdup (names[i])); + rz_list_append (items, strdup (names[i])); } R_FREE (names[i]); } else { - r_list_append (items, strdup ("0")); + rz_list_append (items, strdup ("0")); } } - r_table_add_row_list (t, items); + rz_table_add_row_list (t, items); } - r_table_query (t, (*input)?input + 1: ""); - char *ts = isJson? r_table_tojson(t): r_table_tostring (t); - r_cons_printf ("%s", ts); + rz_table_query (t, (*input)?input + 1: ""); + char *ts = isJson? rz_table_tojson(t): rz_table_tostring (t); + rz_cons_printf ("%s", ts); free (ts); - r_table_free (t); - r_core_seek (core, oseek, true); - r_list_free (dbs); + rz_table_free (t); + rz_core_seek (core, oseek, true); + rz_list_free (dbs); } -static void cmd_afsj(RCore *core, const char *arg) { - ut64 a = r_num_math (core->num, arg); +static void cmd_afsj(RzCore *core, const char *arg) { + ut64 a = rz_num_math (core->num, arg); const ut64 addr = a? a: core->offset; - RAnalFunction *f = r_anal_get_fcn_in (core->anal, addr, -1); + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, addr, -1); if (f) { - char *s = r_anal_function_get_json (f); - r_cons_printf ("%s\n", s); + char *s = rz_anal_function_get_json (f); + rz_cons_printf ("%s\n", s); free (s); } else { eprintf ("Cannot find function in 0x%08"PFMT64x"\n", addr); } } -static int cmd_anal_fcn(RCore *core, const char *input) { +static int cmd_anal_fcn(RzCore *core, const char *input) { char i; - r_cons_break_timeout (r_config_get_i (core->config, "anal.timeout")); + rz_cons_break_timeout (rz_config_get_i (core->config, "anal.timeout")); switch (input[1]) { case '-': // "af-" if (!input[2]) { cmd_anal_fcn (core, "f-$$"); - r_core_anal_undefine (core, core->offset); + rz_core_anal_undefine (core, core->offset); } else if (!strcmp (input + 2, "*")) { - RAnalFunction *f; - RListIter *iter; - r_list_foreach (core->anal->fcns, iter, f) { - r_anal_del_jmprefs (core->anal, f); + RzAnalFunction *f; + RzListIter *iter; + rz_list_foreach (core->anal->fcns, iter, f) { + rz_anal_del_jmprefs (core->anal, f); } - r_list_purge (core->anal->fcns); + rz_list_purge (core->anal->fcns); } else { ut64 addr = input[2] - ? r_num_math (core->num, input + 2) + ? rz_num_math (core->num, input + 2) : core->offset; - r_core_anal_undefine (core, addr); - r_anal_fcn_del_locs (core->anal, addr); - r_anal_fcn_del (core->anal, addr); + rz_core_anal_undefine (core, addr); + rz_anal_fcn_del_locs (core->anal, addr); + rz_anal_fcn_del (core->anal, addr); } break; case 'j': // "afj" { - RList *blocks = r_anal_get_blocks_in (core->anal, core->offset); - RAnalBlock *block = r_list_first (blocks); - if (block && !r_list_empty (block->fcns)) { + RzList *blocks = rz_anal_get_blocks_in (core->anal, core->offset); + RzAnalBlock *block = rz_list_first (blocks); + if (block && !rz_list_empty (block->fcns)) { char *args = strdup (input + 2); - RList *argv = r_str_split_list (args, " ", 0); - ut64 table = r_num_math (core->num, r_list_get_n (argv, 0)); - ut64 elements = r_num_math (core->num, r_list_get_n (argv, 1)); - r_anal_jmptbl (core->anal, r_list_first (block->fcns), block, core->offset, table, elements, UT64_MAX); + RzList *argv = rz_str_split_list (args, " ", 0); + ut64 table = rz_num_math (core->num, rz_list_get_n (argv, 0)); + ut64 elements = rz_num_math (core->num, rz_list_get_n (argv, 1)); + rz_anal_jmptbl (core->anal, rz_list_first (block->fcns), block, core->offset, table, elements, UT64_MAX); } else { eprintf ("No function defined here\n"); } - r_list_free (blocks); + rz_list_free (blocks); } break; case 'a': // "afa" if (input[2] == 'l') { // "afal" : list function call arguments - int show_args = r_config_get_i (core->config, "dbg.funcarg"); + int show_args = rz_config_get_i (core->config, "dbg.funcarg"); if (show_args) { - r_core_print_func_args (core); + rz_core_print_func_args (core); } } else { - r_core_print_func_args (core); + rz_core_print_func_args (core); } break; case 'd': // "afd" @@ -3381,11 +3381,11 @@ static int cmd_anal_fcn(RCore *core, const char *input) { if (input[2] == '?') { eprintf ("afd [offset]\n"); } else if (input[2] == ' ') { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } else { addr = core->offset; } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (input[2] == 'j') { // afdj PJ *pj = pj_new (); if (!pj) { @@ -3397,15 +3397,15 @@ static int cmd_anal_fcn(RCore *core, const char *input) { pj_ki (pj, "offset", (int)(addr - fcn->addr)); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else { if (fcn) { if (fcn->addr != addr) { - r_cons_printf ("%s + %d\n", fcn->name, + rz_cons_printf ("%s + %d\n", fcn->name, (int)(addr - fcn->addr)); } else { - r_cons_println (fcn->name); + rz_cons_println (fcn->name); } } else { eprintf ("afd: Cannot find function\n"); @@ -3421,33 +3421,33 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } ut64 addr = core->offset; - ut64 addr_end = r_num_math (core->num, input + 2); + ut64 addr_end = rz_num_math (core->num, input + 2); if (addr_end < addr) { eprintf ("Invalid address ranges\n"); } else { int depth = 1; ut64 a, b; const char *c; - a = r_config_get_i (core->config, "anal.from"); - b = r_config_get_i (core->config, "anal.to"); - c = r_config_get (core->config, "anal.limits"); - r_config_set_i (core->config, "anal.from", addr); - r_config_set_i (core->config, "anal.to", addr_end); - r_config_set (core->config, "anal.limits", "true"); + a = rz_config_get_i (core->config, "anal.from"); + b = rz_config_get_i (core->config, "anal.to"); + c = rz_config_get (core->config, "anal.limits"); + rz_config_set_i (core->config, "anal.from", addr); + rz_config_set_i (core->config, "anal.to", addr_end); + rz_config_set (core->config, "anal.limits", "true"); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_anal_function_resize (fcn, addr_end - addr); + rz_anal_function_resize (fcn, addr_end - addr); } - r_core_anal_fcn (core, addr, UT64_MAX, + rz_core_anal_fcn (core, addr, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - fcn = r_anal_get_fcn_in (core->anal, addr, 0); + fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { - r_anal_function_resize (fcn, addr_end - addr); + rz_anal_function_resize (fcn, addr_end - addr); } - r_config_set_i (core->config, "anal.from", a); - r_config_set_i (core->config, "anal.to", b); - r_config_set (core->config, "anal.limits", c? c: ""); + rz_config_set_i (core->config, "anal.from", a); + rz_config_set_i (core->config, "anal.to", b); + rz_config_set (core->config, "anal.limits", c? c: ""); } } break; @@ -3458,17 +3458,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } char *ptr = strdup (input + 3); const char *ptr2; - int n = r_str_word_set0 (ptr); + int n = rz_str_word_set0 (ptr); const char *name = NULL; ut64 addr = UT64_MAX; - RAnalDiff *diff = NULL; + RzAnalDiff *diff = NULL; int type = R_ANAL_FCN_TYPE_FCN; if (n > 1) { switch (n) { case 4: - ptr2 = r_str_word_get0 (ptr, 3); - if (!(diff = r_anal_diff_new ())) { - eprintf ("error: Cannot init RAnalDiff\n"); + ptr2 = rz_str_word_get0 (ptr, 3); + if (!(diff = rz_anal_diff_new ())) { + eprintf ("error: Cannot init RzAnalDiff\n"); free (ptr); return false; } @@ -3478,7 +3478,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) { diff->type = R_ANAL_DIFF_TYPE_UNMATCH; } case 3: - ptr2 = r_str_word_get0 (ptr, 2); + ptr2 = rz_str_word_get0 (ptr, 2); if (strchr (ptr2, 'l')) { type = R_ANAL_FCN_TYPE_LOC; } else if (strchr (ptr2, 'i')) { @@ -3489,16 +3489,16 @@ static int cmd_anal_fcn(RCore *core, const char *input) { type = R_ANAL_FCN_TYPE_FCN; } case 2: - name = r_str_word_get0 (ptr, 1); + name = rz_str_word_get0 (ptr, 1); case 1: - addr = r_num_math (core->num, r_str_word_get0 (ptr, 0)); + addr = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); } - RAnalFunction *fcn = r_anal_create_function (core->anal, name, addr, type, diff); + RzAnalFunction *fcn = rz_anal_create_function (core->anal, name, addr, type, diff); if (!fcn) { eprintf ("Cannot add function (duplicated)\n"); } } - r_anal_diff_free (diff); + rz_anal_diff_free (diff); free (ptr); } break; @@ -3509,7 +3509,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case 'j': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); PJ *pj = pj_new (); if (!pj) { return false; @@ -3519,41 +3519,41 @@ static int cmd_anal_fcn(RCore *core, const char *input) { pj_ki (pj, "address", fcn->addr); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; case '\0': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - r_cons_printf ("0x%08" PFMT64x "\n", fcn->addr); + rz_cons_printf ("0x%08" PFMT64x "\n", fcn->addr); } } break; case 's': // "afos" { ut64 addr = core->offset; - RListIter *iter; - RList *list = r_anal_get_functions_in (core->anal, addr); - RAnalFunction *fcn; - r_list_foreach (list, iter, fcn) { - r_cons_printf ("= 0x%08" PFMT64x "\n", fcn->addr); + RzListIter *iter; + RzList *list = rz_anal_get_functions_in (core->anal, addr); + RzAnalFunction *fcn; + rz_list_foreach (list, iter, fcn) { + rz_cons_printf ("= 0x%08" PFMT64x "\n", fcn->addr); } - r_list_free (list); + rz_list_free (list); } break; case ' ': { - RAnalFunction *fcn; - ut64 addr = r_num_math (core->num, input + 3); + RzAnalFunction *fcn; + ut64 addr = rz_num_math (core->num, input + 3); if (addr == 0LL) { - fcn = r_anal_get_function_byname (core->anal, input + 3); + fcn = rz_anal_get_function_byname (core->anal, input + 3); } else { - fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); } if (fcn) { - r_cons_printf ("0x%08" PFMT64x "\n", fcn->addr); + rz_cons_printf ("0x%08" PFMT64x "\n", fcn->addr); } } break; @@ -3562,17 +3562,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { case 'i': // "afi" switch (input[2]) { case '?': - r_core_cmd_help (core, help_msg_afi); + rz_core_cmd_help (core, help_msg_afi); break; case '.': // "afi." { ut64 addr = core->offset; if (input[3] == ' ') { - addr = r_num_math (core->num, input + 3); + addr = rz_num_math (core->num, input + 3); } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fcn) { - r_cons_printf ("%s\n", fcn->name); + rz_cons_printf ("%s\n", fcn->name); } } break; @@ -3580,34 +3580,34 @@ static int cmd_anal_fcn(RCore *core, const char *input) { if (input[3] == '?') { // TODO #7967 help refactor help_msg_afll[1] = "afil"; - r_core_cmd_help (core, help_msg_afll); + rz_core_cmd_help (core, help_msg_afll); break; } /* fallthrough */ case 'i': // "afii" if (input[3] == '-') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - r_list_free (fcn->imports); + rz_list_free (fcn->imports); fcn->imports = NULL; } } else if (input[3] == ' ') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { if (!fcn->imports) { - fcn->imports = r_list_newf ((RListFree)free); + fcn->imports = rz_list_newf ((RzListFree)free); } - r_list_append (fcn->imports, r_str_trim_dup (input + 4)); + rz_list_append (fcn->imports, rz_str_trim_dup (input + 4)); } else { eprintf ("No function found\n"); } } else { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn && fcn->imports) { char *imp; - RListIter *iter; - r_list_foreach (fcn->imports, iter, imp) { - r_cons_printf ("%s\n", imp); + RzListIter *iter; + rz_list_foreach (fcn->imports, iter, imp) { + rz_cons_printf ("%s\n", imp); } } } @@ -3621,51 +3621,51 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case 'j': // "afij" case '*': // "afi*" - r_core_anal_fcn_list (core, input + 3, input + 2); + rz_core_anal_fcn_list (core, input + 3, input + 2); break; case 'p': // "afip" { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - r_cons_printf ("is-pure: %s\n", r_str_bool (r_anal_function_purity (fcn))); + rz_cons_printf ("is-pure: %s\n", rz_str_bool (rz_anal_function_purity (fcn))); } } break; default: i = 1; - r_core_anal_fcn_list (core, input + 2, &i); + rz_core_anal_fcn_list (core, input + 2, &i); break; } break; case 'l': // "afl" switch (input[2]) { case '?': - r_core_cmd_help (core, help_msg_afl); + rz_core_cmd_help (core, help_msg_afl); break; case 's': // "afls" switch (input[3]) { case '?': - r_core_cmd_help (core, help_msg_afls); + rz_core_cmd_help (core, help_msg_afls); break; case 'a': // "aflsa" core->anal->fcns->sorted = false; - r_list_sort (core->anal->fcns, cmpaddr); + rz_list_sort (core->anal->fcns, cmpaddr); break; case 'b': // "aflsb" core->anal->fcns->sorted = false; - r_list_sort (core->anal->fcns, cmpbbs); + rz_list_sort (core->anal->fcns, cmpbbs); break; case 's': // "aflss" core->anal->fcns->sorted = false; - r_list_sort (core->anal->fcns, cmpsize); + rz_list_sort (core->anal->fcns, cmpsize); break; case 'n': // "aflsn" core->anal->fcns->sorted = false; - r_list_sort (core->anal->fcns, cmpname); + rz_list_sort (core->anal->fcns, cmpname); break; default: core->anal->fcns->sorted = false; - r_list_sort (core->anal->fcns, cmpaddr); + rz_list_sort (core->anal->fcns, cmpaddr); break; } break; @@ -3673,7 +3673,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) { if (input[3] == '?') { // TODO #7967 help refactor help_msg_afll[1] = "afll"; - r_core_cmd_help (core, help_msg_afll); + rz_core_cmd_help (core, help_msg_afll); break; } /* fallthrough */ @@ -3685,34 +3685,34 @@ static int cmd_anal_fcn(RCore *core, const char *input) { case '=': // "afl=" case '*': // "afl*" case '.': // "afl*" - r_core_anal_fcn_list (core, NULL, input + 2); + rz_core_anal_fcn_list (core, NULL, input + 2); break; case 'c': // "aflc" - r_cons_printf ("%d\n", r_list_length (core->anal->fcns)); + rz_cons_printf ("%d\n", rz_list_length (core->anal->fcns)); break; default: // "afl " - r_core_anal_fcn_list (core, NULL, "o"); + rz_core_anal_fcn_list (core, NULL, "o"); break; } break; case 's': // "afs" switch (input[2]) { case '!': { // "afs!" - char *sig = r_core_cmd_str (core, "afs"); - char *data = r_core_editor (core, NULL, sig); + char *sig = rz_core_cmd_str (core, "afs"); + char *data = rz_core_editor (core, NULL, sig); if (sig && data) { - r_core_cmdf (core, "\"afs %s\"", data); + rz_core_cmdf (core, "\"afs %s\"", data); } free (sig); free (data); break; } case 'r': { // "afsr" - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (fcn) { - char *type = r_str_newf ("type.%s", input + 4); + char *type = rz_str_newf ("type.%s", input + 4); if (sdb_exists (core->anal->sdb_types, type)) { - char *query = r_str_newf ("anal/types/func.%s.ret=%s", fcn->name, input + 4); + char *query = rz_str_newf ("anal/types/func.%s.ret=%s", fcn->name, input + 4); sdb_querys (core->sdb, NULL, 0, query); free (query); } @@ -3731,32 +3731,32 @@ static int cmd_anal_fcn(RCore *core, const char *input) { case 0: case ' ': { // "afs" ut64 addr = core->offset; - RAnalFunction *f; - const char *arg = r_str_trim_head_ro (input + 2); - if ((f = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL))) { + RzAnalFunction *f; + const char *arg = rz_str_trim_head_ro (input + 2); + if ((f = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL))) { if (arg && *arg) { // parse function signature here - char *fcnstr = r_str_newf ("%s;", arg), *fcnstr_copy = strdup (fcnstr); + char *fcnstr = rz_str_newf ("%s;", arg), *fcnstr_copy = strdup (fcnstr); char *fcnname_aux = strtok (fcnstr_copy, "("); - r_str_trim_tail (fcnname_aux); + rz_str_trim_tail (fcnname_aux); char *fcnname = NULL; - const char *ls = r_str_lchr (fcnname_aux, ' '); + const char *ls = rz_str_lchr (fcnname_aux, ' '); fcnname = strdup (ls? ls: fcnname_aux); if (fcnname) { - // TODO: move this into r_anal_str_to_fcn() + // TODO: move this into rz_anal_str_to_fcn() if (strcmp (f->name, fcnname)) { (void)__setFunctionName (core, addr, fcnname, false); - f = r_anal_get_fcn_in (core->anal, addr, -1); + f = rz_anal_get_fcn_in (core->anal, addr, -1); } - r_anal_str_to_fcn (core->anal, f, fcnstr); + rz_anal_str_to_fcn (core->anal, f, fcnstr); } free (fcnname); free (fcnstr_copy); free (fcnstr); } else { - char *str = r_anal_function_get_signature (f); + char *str = rz_anal_function_get_signature (f); if (str) { - r_cons_println (str); + rz_cons_println (str); free (str); } } @@ -3767,15 +3767,15 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } default: // case '?': // "afs?" - r_core_cmd_help (core, help_msg_afs); + rz_core_cmd_help (core, help_msg_afs); break; } break; case 'm': // "afm" - merge two functions - r_core_anal_fcn_merge (core, core->offset, r_num_math (core->num, input + 2)); + rz_core_anal_fcn_merge (core, core->offset, rz_num_math (core->num, input + 2)); break; case 'M': // "afM" - print functions map - r_core_anal_fmap (core, input + 1); + rz_core_anal_fmap (core, input + 1); break; case 'v': // "afv" var_cmd (core, input + 2); @@ -3785,29 +3785,29 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case 'C': // "afC" if (input[2] == 'c') { - RAnalFunction *fcn; - if ((fcn = r_anal_get_fcn_in (core->anal, core->offset, 0)) != NULL) { - r_cons_printf ("%i\n", r_anal_function_complexity (fcn)); + RzAnalFunction *fcn; + if ((fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0)) != NULL) { + rz_cons_printf ("%i\n", rz_anal_function_complexity (fcn)); } else { eprintf ("Error: Cannot find function at 0x08%" PFMT64x "\n", core->offset); } } else if (input[2] == 'l') { - RAnalFunction *fcn; - if ((fcn = r_anal_get_fcn_in (core->anal, core->offset, 0)) != NULL) { - r_cons_printf ("%d\n", r_anal_function_loops (fcn)); + RzAnalFunction *fcn; + if ((fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0)) != NULL) { + rz_cons_printf ("%d\n", rz_anal_function_loops (fcn)); } else { eprintf ("Error: Cannot find function at 0x08%" PFMT64x "\n", core->offset); } } else if (input[2] == '?') { - r_core_cmd_help (core, help_msg_afC); + rz_core_cmd_help (core, help_msg_afC); } else { - afCc (core, r_str_trim_head_ro (input + 2)); + afCc (core, rz_str_trim_head_ro (input + 2)); } break; case 'c':{ // "afc" - RAnalFunction *fcn = NULL; + RzAnalFunction *fcn = NULL; if (!input[2] || input[2] == ' ' || input[2] == 'r' || input[2] == 'a') { - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (!fcn) { eprintf ("afc: Cannot find function here\n"); break; @@ -3815,18 +3815,18 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } switch (input[2]) { case '\0': // "afc" - r_cons_println (fcn->cc); + rz_cons_println (fcn->cc); break; case ' ': { // "afc " char *argument = strdup (input + 3); char *cc = argument; - r_str_trim (cc); - if (!r_anal_cc_exist (core->anal, cc)) { - const char *asmOs = r_config_get (core->config, "asm.os"); + rz_str_trim (cc); + if (!rz_anal_cc_exist (core->anal, cc)) { + const char *asmOs = rz_config_get (core->config, "asm.os"); eprintf ("afc: Unknown calling convention '%s' for '%s'\n" "See afcl for available types\n", cc, asmOs); } else { - fcn->cc = r_str_constpool_get (&core->anal->constpool, cc); + fcn->cc = rz_str_constpool_get (&core->anal->constpool, cc); } free (argument); break; @@ -3835,12 +3835,12 @@ static int cmd_anal_fcn(RCore *core, const char *input) { if (input[3]) { char *argument = strdup (input + 3); char *cc = argument; - r_str_trim (cc); - r_core_cmdf (core, "k anal/cc/default.cc=%s", cc); - r_anal_set_reg_profile (core->anal); + rz_str_trim (cc); + rz_core_cmdf (core, "k anal/cc/default.cc=%s", cc); + rz_anal_set_reg_profile (core->anal); free (argument); } else { - r_core_cmd0 (core, "k anal/cc/default.cc"); + rz_core_cmd0 (core, "k anal/cc/default.cc"); } break; case 'a': // "afca" @@ -3850,14 +3850,14 @@ static int cmd_anal_fcn(RCore *core, const char *input) { cmd_anal_fcn_sig (core, input + 3); break; case 'k': // "afck" - r_core_cmd0 (core, "k anal/cc/*"); + rz_core_cmd0 (core, "k anal/cc/*"); break; case 'l': // "afcl" list all function Calling conventions. sdb_foreach (core->anal->sdb_cc, cc_print, NULL); break; case 'o': { // "afco" - char *dbpath = r_str_trim_dup (input + 3); - if (r_file_exists (dbpath)) { + char *dbpath = rz_str_trim_dup (input + 3); + if (rz_file_exists (dbpath)) { Sdb *db = sdb_new (0, dbpath, 0); sdb_merge (core->anal->sdb_cc, db); sdb_close (db); @@ -3868,80 +3868,80 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } case 'r': { // "afcr" int i; - RStrBuf *json_buf = r_strbuf_new ("{"); + RStrBuf *json_buf = rz_strbuf_new ("{"); bool json = input[3] == 'j'; - char *cmd = r_str_newf ("cc.%s.ret", fcn->cc); + char *cmd = rz_str_newf ("cc.%s.ret", fcn->cc); const char *regname = sdb_const_get (core->anal->sdb_cc, cmd, 0); if (regname) { if (json) { - r_strbuf_appendf (json_buf, "\"ret\":\"%s\"", regname); + rz_strbuf_appendf (json_buf, "\"ret\":\"%s\"", regname); } else { - r_cons_printf ("%s: %s\n", cmd, regname); + rz_cons_printf ("%s: %s\n", cmd, regname); } } free (cmd); bool isFirst = true; for (i = 0; i < R_ANAL_CC_MAXARG; i++) { - cmd = r_str_newf ("cc.%s.arg%d", fcn->cc, i); + cmd = rz_str_newf ("cc.%s.arg%d", fcn->cc, i); regname = sdb_const_get (core->anal->sdb_cc, cmd, 0); if (regname) { if (json) { if (isFirst) { - r_strbuf_appendf (json_buf, ",\"args\":[\"%s\"", regname); + rz_strbuf_appendf (json_buf, ",\"args\":[\"%s\"", regname); isFirst = false; } else { - r_strbuf_appendf (json_buf, ",\"%s\"", regname); + rz_strbuf_appendf (json_buf, ",\"%s\"", regname); } } else { - r_cons_printf ("%s: %s\n", cmd, regname); + rz_cons_printf ("%s: %s\n", cmd, regname); } } free (cmd); } if (!isFirst) { - r_strbuf_append (json_buf, "]"); + rz_strbuf_append (json_buf, "]"); } - cmd = r_str_newf ("cc.%s.self", fcn->cc); + cmd = rz_str_newf ("cc.%s.self", fcn->cc); regname = sdb_const_get (core->anal->sdb_cc, cmd, 0); if (regname) { if (json) { - r_strbuf_appendf (json_buf, ",\"self\":\"%s\"", regname); + rz_strbuf_appendf (json_buf, ",\"self\":\"%s\"", regname); } else { - r_cons_printf ("%s: %s\n", cmd, regname); + rz_cons_printf ("%s: %s\n", cmd, regname); } } free (cmd); - cmd = r_str_newf ("cc.%s.error", fcn->cc); + cmd = rz_str_newf ("cc.%s.error", fcn->cc); regname = sdb_const_get (core->anal->sdb_cc, cmd, 0); if (regname) { if (json) { - r_strbuf_appendf (json_buf, ",\"error\":\"%s\"", regname); + rz_strbuf_appendf (json_buf, ",\"error\":\"%s\"", regname); } else { - r_cons_printf ("%s: %s\n", cmd, regname); + rz_cons_printf ("%s: %s\n", cmd, regname); } } free (cmd); - r_strbuf_append (json_buf, "}"); + rz_strbuf_append (json_buf, "}"); if (json) { - r_cons_printf ("%s\n", r_strbuf_drain (json_buf)); + rz_cons_printf ("%s\n", rz_strbuf_drain (json_buf)); } } break; case 'R': { // "afcR" /* very slow, but im tired of waiting for having this, so this is the quickest implementation */ int i; - char *cc = r_core_cmd_str (core, "k anal/cc/default.cc"); - r_str_trim (cc); + char *cc = rz_core_cmd_str (core, "k anal/cc/default.cc"); + rz_str_trim (cc); for (i = 0; i < 6; i++) { - char *res = r_core_cmd_strf (core, "k anal/cc/cc.%s.arg%d", cc, i); - r_str_trim_nc (res); + char *res = rz_core_cmd_strf (core, "k anal/cc/cc.%s.arg%d", cc, i); + rz_str_trim_nc (res); if (*res) { - char *row = r_core_cmd_strf (core, "drr~%s 0x", res); - r_str_trim (row); - r_cons_printf ("arg[%d] %s\n", i, row); + char *row = rz_core_cmd_strf (core, "drr~%s 0x", res); + rz_str_trim (row); + rz_cons_printf ("arg[%d] %s\n", i, row); free (row); } free (res); @@ -3951,17 +3951,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case '?': // "afc?" default: - r_core_cmd_help (core, help_msg_afc); + rz_core_cmd_help (core, help_msg_afc); } } break; case 'B': // "afB" // set function bits if (input[2] == ' ') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { int bits = atoi (input + 3); - r_anal_hint_set_bits (core->anal, r_anal_function_min_addr (fcn), bits); - r_anal_hint_set_bits (core->anal, r_anal_function_max_addr (fcn), core->anal->bits); + rz_anal_hint_set_bits (core->anal, rz_anal_function_min_addr (fcn), bits); + rz_anal_hint_set_bits (core->anal, rz_anal_function_max_addr (fcn), core->anal->bits); fcn->bits = bits; } else { eprintf ("afB: Cannot find function to set bits at 0x%08"PFMT64x"\n", core->offset); @@ -3980,9 +3980,9 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case 'F': // "afbF" { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, core->offset); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, fcn, core->offset); if (bb) { if (input[3]) { int n = atoi (input + 3); @@ -3991,7 +3991,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) { bb->folded = !bb->folded; } } else { - r_warn_if_reached (); + rz_warn_if_reached (); } } } @@ -4018,17 +4018,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { case 'c': // "afbc" { const char *ptr = input + 3; - ut64 addr = r_num_math (core->num, ptr); + ut64 addr = rz_num_math (core->num, ptr); ut32 color; ptr = strchr (ptr, ' '); if (ptr) { ptr = strchr (ptr + 1, ' '); if (ptr) { - color = r_num_math (core->num, ptr + 1); - RAnalOp *op = r_core_op_anal (core, addr, R_ANAL_OP_MASK_ALL); + color = rz_num_math (core->num, ptr + 1); + RzAnalOp *op = rz_core_op_anal (core, addr, R_ANAL_OP_MASK_ALL); if (op) { - r_anal_colorize_bb (core->anal, addr, color); - r_anal_op_free (op); + rz_anal_colorize_bb (core->anal, addr, color); + rz_anal_op_free (op); } else { eprintf ("Cannot analyze opcode at 0x%08" PFMT64x "\n", addr); } @@ -4038,7 +4038,7 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; default: case '?': - r_core_cmd_help (core, help_msg_afb); + rz_core_cmd_help (core, help_msg_afb); break; } break; @@ -4046,16 +4046,16 @@ static int cmd_anal_fcn(RCore *core, const char *input) { switch (input[2]) { case 's': // "afns" if (input[3] == 'j') { // "afnsj" - free (r_core_anal_fcn_autoname (core, core->offset, 1, input[3])); + free (rz_core_anal_fcn_autoname (core, core->offset, 1, input[3])); } else { - free (r_core_anal_fcn_autoname (core, core->offset, 1, 0)); + free (rz_core_anal_fcn_autoname (core, core->offset, 1, 0)); } break; case 'a': // "afna" { - char *name = r_core_anal_fcn_autoname (core, core->offset, 0, 0); + char *name = rz_core_anal_fcn_autoname (core, core->offset, 0, 0); if (name) { - r_cons_printf ("afn %s 0x%08" PFMT64x "\n", name, core->offset); + rz_cons_printf ("afn %s 0x%08" PFMT64x "\n", name, core->offset); free (name); } } @@ -4063,25 +4063,25 @@ static int cmd_anal_fcn(RCore *core, const char *input) { case '.': // "afn." case 0: // "afn" { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (fcn) { - r_cons_printf ("%s\n", fcn->name); + rz_cons_printf ("%s\n", fcn->name); } } break; case ' ': // "afn " { ut64 off = core->offset; - char *p, *name = strdup (r_str_trim_head_ro (input + 3)); + char *p, *name = strdup (rz_str_trim_head_ro (input + 3)); if ((p = strchr (name, ' '))) { *p++ = 0; - off = r_num_math (core->num, p); + off = rz_num_math (core->num, p); } if (*name == '?') { eprintf ("Usage: afn newname [off] # set new name to given function\n"); } else { - if (r_str_startswith (name, "base64:")) { - char *res = (char *)r_base64_decode_dyn (name + 7, -1); + if (rz_str_startswith (name, "base64:")) { + char *res = (char *)rz_base64_decode_dyn (name + 7, -1); if (res) { free (name); name = res; @@ -4095,15 +4095,15 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } break; default: - r_core_cmd_help (core, help_msg_afn); + rz_core_cmd_help (core, help_msg_afn); break; } break; case 'S': // afS" { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (fcn) { - fcn->maxstack = r_num_math (core->num, input + 3); + fcn->maxstack = rz_num_math (core->num, input + 3); //fcn->stack = fcn->maxstack; } } @@ -4112,28 +4112,28 @@ static int cmd_anal_fcn(RCore *core, const char *input) { /* this is undocumented and probably have no uses. plz discuss */ case 'e': // "afe" { - RAnalFunction *fcn; + RzAnalFunction *fcn; ut64 off = core->offset; char *p, *name = strdup ((input[2]&&input[3])? input + 3: ""); if ((p = strchr (name, ' '))) { *p = 0; - off = r_num_math (core->num, p + 1); + off = rz_num_math (core->num, p + 1); } - fcn = r_anal_get_fcn_in (core->anal, off, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); + fcn = rz_anal_get_fcn_in (core->anal, off, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (fcn) { - RAnalBlock *b; - RListIter *iter; - RAnalRef *r; - r_list_foreach (fcn->refs, iter, r) { - r_cons_printf ("0x%08" PFMT64x " -%c 0x%08" PFMT64x "\n", r->at, r->type, r->addr); + RzAnalBlock *b; + RzListIter *iter; + RzAnalRef *r; + rz_list_foreach (fcn->refs, iter, r) { + rz_cons_printf ("0x%08" PFMT64x " -%c 0x%08" PFMT64x "\n", r->at, r->type, r->addr); } - r_list_foreach (fcn->bbs, iter, b) { + rz_list_foreach (fcn->bbs, iter, b) { int ok = 0; if (b->type == R_ANAL_BB_TYPE_LAST) ok = 1; if (b->type == R_ANAL_BB_TYPE_FOOT) ok = 1; if (b->jump == UT64_MAX && b->fail == UT64_MAX) ok = 1; if (ok) { - r_cons_printf ("0x%08" PFMT64x " -r\n", b->addr); + rz_cons_printf ("0x%08" PFMT64x " -r\n", b->addr); // TODO: check if destination is outside the function boundaries } } @@ -4157,56 +4157,56 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } // list xrefs from current address { - ut64 addr = input[2]==' '? r_num_math (core->num, input + 2): core->offset; - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + ut64 addr = input[2]==' '? rz_num_math (core->num, input + 2): core->offset; + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fcn) { ut64 oaddr = core->offset; - RAnalRef *ref; - RListIter *iter; - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { + RzAnalRef *ref; + RzListIter *iter; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { if (input[2] == 'j') { pj_o (pj); - pj_ks (pj, "type", r_anal_ref_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_ref_type_tostring (ref->type)); pj_kn (pj, "from", ref->at); pj_kn (pj, "to", ref->addr); pj_end (pj); } else { - r_cons_printf ("%c 0x%08" PFMT64x " -> ", ref->type, ref->at); + rz_cons_printf ("%c 0x%08" PFMT64x " -> ", ref->type, ref->at); switch (ref->type) { case R_ANAL_REF_TYPE_NULL: - r_cons_printf ("0x%08" PFMT64x " ", ref->addr); + rz_cons_printf ("0x%08" PFMT64x " ", ref->addr); break; case R_ANAL_REF_TYPE_CODE: case R_ANAL_REF_TYPE_CALL: case R_ANAL_REF_TYPE_DATA: - r_cons_printf ("0x%08" PFMT64x " ", ref->addr); - r_core_seek (core, ref->at, 1); - r_core_print_disasm_instructions (core, 0, 1); + rz_cons_printf ("0x%08" PFMT64x " ", ref->addr); + rz_core_seek (core, ref->at, 1); + rz_core_print_disasm_instructions (core, 0, 1); break; case R_ANAL_REF_TYPE_STRING: { - char *s = r_core_cmd_strf (core, "pxr 8 @ 0x%08"PFMT64x, ref->addr); + char *s = rz_core_cmd_strf (core, "pxr 8 @ 0x%08"PFMT64x, ref->addr); char *nl = strchr (s, '\n'); if (nl) { *nl = 0; } - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); } break; } } } - r_list_free (refs); - r_core_seek (core, oaddr, 1); + rz_list_free (refs); + rz_core_seek (core, oaddr, 1); } else { eprintf ("afx: Cannot find function at 0x%08"PFMT64x"\n", addr); } } if (input[2] == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } pj_free (pj); break; @@ -4218,24 +4218,24 @@ static int cmd_anal_fcn(RCore *core, const char *input) { break; case 'F': // "afF" { - int val = input[2] && r_num_math (core->num, input + 2); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + int val = input[2] && rz_num_math (core->num, input + 2); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { fcn->folded = input[2]? val: !fcn->folded; } } break; case '?': // "af?" - r_core_cmd_help (core, help_msg_af); + rz_core_cmd_help (core, help_msg_af); break; case 'r': // "afr" // analyze function recursively case ' ': // "af " case '\0': // "af" { char *uaddr = NULL, *name = NULL; - int depth = r_config_get_i (core->config, "anal.depth"); - bool analyze_recursively = r_config_get_i (core->config, "anal.calls"); - RAnalFunction *fcn = NULL; + int depth = rz_config_get_i (core->config, "anal.depth"); + bool analyze_recursively = rz_config_get_i (core->config, "anal.calls"); + RzAnalFunction *fcn = NULL; ut64 addr = core->offset; if (input[1] == 'r') { input++; @@ -4244,23 +4244,23 @@ static int cmd_anal_fcn(RCore *core, const char *input) { // first undefine if (input[0] && input[1] == ' ') { - name = strdup (r_str_trim_head_ro (input + 2)); + name = strdup (rz_str_trim_head_ro (input + 2)); uaddr = strchr (name, ' '); if (uaddr) { *uaddr++ = 0; - addr = r_num_math (core->num, uaddr); + addr = rz_num_math (core->num, uaddr); } // depth = 1; // or 1? // disable hasnext } - //r_core_anal_undefine (core, core->offset); - r_core_anal_fcn (core, addr, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - fcn = r_anal_get_fcn_in (core->anal, addr, 0); + //rz_core_anal_undefine (core, core->offset); + rz_core_anal_fcn (core, addr, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); + fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { /* ensure we use a proper name */ __setFunctionName (core, addr, fcn->name, false); if (core->anal->opt.vars) { - r_core_recover_vars (core, fcn, true); + rz_core_recover_vars (core, fcn, true); } __add_vars_sdb (core, fcn); } else { @@ -4269,12 +4269,12 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } } if (analyze_recursively) { - fcn = r_anal_get_fcn_in (core->anal, addr, 0); /// XXX wrong in case of nopskip + fcn = rz_anal_get_fcn_in (core->anal, addr, 0); /// XXX wrong in case of nopskip if (fcn) { - RAnalRef *ref; - RListIter *iter; - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, ref) { + RzAnalRef *ref; + RzListIter *iter; + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { if (ref->addr == UT64_MAX) { //eprintf ("Warning: ignore 0x%08"PFMT64x" call 0x%08"PFMT64x"\n", ref->at, ref->addr); continue; @@ -4283,36 +4283,36 @@ static int cmd_anal_fcn(RCore *core, const char *input) { /* only follow code/call references */ continue; } - if (!r_io_is_valid_offset (core->io, ref->addr, !core->anal->opt.noncode)) { + if (!rz_io_is_valid_offset (core->io, ref->addr, !core->anal->opt.noncode)) { continue; } - r_core_anal_fcn (core, ref->addr, fcn->addr, R_ANAL_REF_TYPE_CALL, depth); + rz_core_anal_fcn (core, ref->addr, fcn->addr, R_ANAL_REF_TYPE_CALL, depth); /* use recursivity here */ #if 1 - RAnalFunction *f = r_anal_get_function_at (core->anal, ref->addr); + RzAnalFunction *f = rz_anal_get_function_at (core->anal, ref->addr); if (f) { - RListIter *iter; - RAnalRef *ref; - RList *refs1 = r_anal_function_get_refs (f); - r_list_foreach (refs1, iter, ref) { - if (!r_io_is_valid_offset (core->io, ref->addr, !core->anal->opt.noncode)) { + RzListIter *iter; + RzAnalRef *ref; + RzList *refs1 = rz_anal_function_get_refs (f); + rz_list_foreach (refs1, iter, ref) { + if (!rz_io_is_valid_offset (core->io, ref->addr, !core->anal->opt.noncode)) { continue; } if (ref->type != 'c' && ref->type != 'C') { continue; } - r_core_anal_fcn (core, ref->addr, f->addr, R_ANAL_REF_TYPE_CALL, depth); + rz_core_anal_fcn (core, ref->addr, f->addr, R_ANAL_REF_TYPE_CALL, depth); // recursively follow fcn->refs again and again } - r_list_free (refs1); + rz_list_free (refs1); } else { - f = r_anal_get_fcn_in (core->anal, fcn->addr, 0); + f = rz_anal_get_fcn_in (core->anal, fcn->addr, 0); if (f) { /* cut function */ - r_anal_function_resize (f, addr - fcn->addr); - r_core_anal_fcn (core, ref->addr, fcn->addr, + rz_anal_function_resize (f, addr - fcn->addr); + rz_core_anal_fcn (core, ref->addr, fcn->addr, R_ANAL_REF_TYPE_CALL, depth); - f = r_anal_get_function_at (core->anal, fcn->addr); + f = rz_anal_get_function_at (core->anal, fcn->addr); } if (!f) { eprintf ("af: Cannot find function at 0x%08" PFMT64x "\n", fcn->addr); @@ -4320,9 +4320,9 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } #endif } - r_list_free (refs); + rz_list_free (refs); if (core->anal->opt.vars) { - r_core_recover_vars (core, fcn, true); + rz_core_recover_vars (core, fcn, true); } } } @@ -4332,17 +4332,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } free (name); } - r_core_anal_propagate_noreturn (core, addr); + rz_core_anal_propagate_noreturn (core, addr); #if 0 // XXX THIS IS VERY SLOW if (core->anal->opt.vars) { - RListIter *iter; - RAnalFunction *fcni = NULL; - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + RzListIter *iter; + RzAnalFunction *fcni = NULL; + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } - r_core_recover_vars (core, fcni, true); + rz_core_recover_vars (core, fcni, true); } } #endif @@ -4357,14 +4357,14 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } // size: 0: bits; -1: any; >0: exact size -static void __anal_reg_list(RCore *core, int type, int bits, char mode) { +static void __anal_reg_list(RzCore *core, int type, int bits, char mode) { if (mode == 'i') { - r_core_debug_ri (core, core->anal->reg, 0); + rz_core_debug_ri (core, core->anal->reg, 0); return; } - RReg *hack = core->dbg->reg; + RzReg *hack = core->dbg->reg; const char *use_color; - int use_colors = r_config_get_i (core->config, "scr.color"); + int use_colors = rz_config_get_i (core->config, "scr.color"); if (use_colors) { #undef ConsP #define ConsP(x) (core->cons && core->cons->context->pal.x)? core->cons->context->pal.x @@ -4373,7 +4373,7 @@ static void __anal_reg_list(RCore *core, int type, int bits, char mode) { use_color = NULL; } if (bits < 0) { - // TODO Change the `size` argument of r_debug_reg_list to use -1 for any and 0 for anal->bits + // TODO Change the `size` argument of rz_debug_reg_list to use -1 for any and 0 for anal->bits bits = 0; } else if (!bits) { bits = core->anal->bits; @@ -4390,21 +4390,21 @@ static void __anal_reg_list(RCore *core, int type, int bits, char mode) { if (!strcmp (core->anal->cur->arch, "6502") && bits == 8) { mode2 = mode == 'j' ? 'J' : mode; if (mode == 'j') { - r_cons_printf ("{"); + rz_cons_printf ("{"); } - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, 16, mode2, use_color); // XXX detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, 16, mode2, use_color); // XXX detect which one is current usage if (mode == 'j') { - r_cons_printf (","); + rz_cons_printf (","); } } if (!strcmp (core->anal->cur->arch, "avr") && bits == 8) { mode2 = mode == 'j' ? 'J' : mode; if (mode == 'j') { - r_cons_printf ("{"); + rz_cons_printf ("{"); } - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, 16, mode2, use_color); // XXX detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, 16, mode2, use_color); // XXX detect which one is current usage if (mode == 'j') { - r_cons_printf (","); + rz_cons_printf (","); } } } @@ -4412,31 +4412,31 @@ static void __anal_reg_list(RCore *core, int type, int bits, char mode) { if (mode == '=') { int pcbits = 0; - const char *pcname = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + const char *pcname = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); if (pcname) { - RRegItem *reg = r_reg_get (core->anal->reg, pcname, 0); + RzRegItem *reg = rz_reg_get (core->anal->reg, pcname, 0); if (reg && bits != reg->size) { pcbits = reg->size; } if (pcbits) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, mode, use_color); // XXX detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, mode, use_color); // XXX detect which one is current usage } } } - r_debug_reg_list (core->dbg, type, bits, mode2, use_color); + rz_debug_reg_list (core->dbg, type, bits, mode2, use_color); if (mode2 == 'J') { - r_cons_print ("}\n"); + rz_cons_print ("}\n"); } core->dbg->reg = hack; } // XXX dup from drp :OOO -void cmd_anal_reg(RCore *core, const char *str) { +void cmd_anal_reg(RzCore *core, const char *str) { if (0) { /* enable this block when dr and ar use the same code but just using core->dbg->reg or core->anal->reg and removing all the debugger dependent code */ - RReg *reg = core->dbg->reg; + RzReg *reg = core->dbg->reg; core->dbg->reg = core->anal->reg; cmd_debug_reg (core, str); core->dbg->reg = reg; @@ -4445,8 +4445,8 @@ void cmd_anal_reg(RCore *core, const char *str) { int size = 0, i, type = R_REG_TYPE_GPR; int bits = (core->anal->bits & R_SYS_BITS_64)? 64: 32; - int use_colors = r_config_get_i (core->config, "scr.color"); - RRegItem *r; + int use_colors = rz_config_get_i (core->config, "scr.color"); + RzRegItem *r; const char *use_color; const char *name; char *arg; @@ -4462,23 +4462,23 @@ void cmd_anal_reg(RCore *core, const char *str) { case 'l': // "arl" { const bool use_json = str[1] == 'j'; - RRegSet *rs = r_reg_regset_get (core->anal->reg, R_REG_TYPE_GPR); + RzRegSet *rs = rz_reg_regset_get (core->anal->reg, R_REG_TYPE_GPR); if (rs) { - RRegItem *r; - RListIter *iter; + RzRegItem *r; + RzListIter *iter; PJ *pj = pj_new (); pj_a (pj); - r_list_foreach (rs->regs, iter, r) { + rz_list_foreach (rs->regs, iter, r) { if (use_json) { pj_s (pj, r->name); } else { - r_cons_println (r->name); + rz_cons_println (r->name); } } if (use_json) { pj_end (pj); const char *s = pj_string (pj); - r_cons_println (s); + rz_cons_println (s); } pj_free (pj); } @@ -4487,74 +4487,74 @@ void cmd_anal_reg(RCore *core, const char *str) { __tableRegList (core, core->anal->reg, str + 1); break; case '0': // "ar0" - r_reg_arena_zero (core->anal->reg); + rz_reg_arena_zero (core->anal->reg); break; case 'A': // "arA" { int nargs = 4; - RReg *reg = core->anal->reg; + RzReg *reg = core->anal->reg; for (i = 0; i < nargs; i++) { - const char *name = r_reg_get_name (reg, r_reg_get_name_idx (sdb_fmt ("A%d", i))); - ut64 off = r_reg_getv (core->anal->reg, name); - r_cons_printf ("0x%08"PFMT64x" ", off); + const char *name = rz_reg_get_name (reg, rz_reg_get_name_idx (sdb_fmt ("A%d", i))); + ut64 off = rz_reg_getv (core->anal->reg, name); + rz_cons_printf ("0x%08"PFMT64x" ", off); // XXX very ugly hack - char *s = r_core_cmd_strf (core, "pxr 32 @ 0x%08"PFMT64x, off); + char *s = rz_core_cmd_strf (core, "pxr 32 @ 0x%08"PFMT64x, off); if (s) { char *nl = strchr (s, '\n'); if (nl) { *nl = 0; - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); } free (s); } -// r_core_cmd0 (core, "ar A0,A1,A2,A3"); +// rz_core_cmd0 (core, "ar A0,A1,A2,A3"); } } break; case 'C': // "arC" if (core->anal->reg->reg_profile_cmt) { - r_cons_println (core->anal->reg->reg_profile_cmt); + rz_cons_println (core->anal->reg->reg_profile_cmt); } break; case 'w': // "arw" switch (str[1]) { case '?': { - r_core_cmd_help (core, help_msg_arw); + rz_core_cmd_help (core, help_msg_arw); break; } case ' ': - r_reg_arena_set_bytes (core->anal->reg, str + 1); + rz_reg_arena_set_bytes (core->anal->reg, str + 1); break; default: - r_core_cmd_help (core, help_msg_arw); + rz_core_cmd_help (core, help_msg_arw); break; } break; case 'a': // "ara" switch (str[1]) { case '?': // "ara?" - r_core_cmd_help (core, help_msg_ara); + rz_core_cmd_help (core, help_msg_ara); break; case 's': // "aras" - r_reg_arena_swap (core->anal->reg, false); + rz_reg_arena_swap (core->anal->reg, false); break; case '+': // "ara+" - r_reg_arena_push (core->anal->reg); + rz_reg_arena_push (core->anal->reg); break; case '-': // "ara-" - r_reg_arena_pop (core->anal->reg); + rz_reg_arena_pop (core->anal->reg); break; default: { int i, j; - RRegArena *a; - RListIter *iter; + RzRegArena *a; + RzListIter *iter; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegSet *rs = &core->anal->reg->regset[i]; + RzRegSet *rs = &core->anal->reg->regset[i]; j = 0; - r_list_foreach (rs->pool, iter, a) { - r_cons_printf ("%s %p %d %d %s %d\n", + rz_list_foreach (rs->pool, iter, a) { + rz_cons_printf ("%s %p %d %d %s %d\n", (a == rs->arena)? "*": ".", a, - i, j, r_reg_get_type (i), a->size); + i, j, rz_reg_get_type (i), a->size); j++; } } @@ -4563,92 +4563,92 @@ void cmd_anal_reg(RCore *core, const char *str) { break; case '?': // "ar?" if (str[1]) { - ut64 off = r_reg_getv (core->anal->reg, str + 1); - r_cons_printf ("0x%08" PFMT64x "\n", off); + ut64 off = rz_reg_getv (core->anal->reg, str + 1); + rz_cons_printf ("0x%08" PFMT64x "\n", off); } else { - r_core_cmd_help (core, help_msg_ar); + rz_core_cmd_help (core, help_msg_ar); } break; case 'r': // "arr" switch (str[1]) { case 'j': // "arrj" - r_core_debug_rr (core, core->anal->reg, 'j'); + rz_core_debug_rr (core, core->anal->reg, 'j'); break; default: - r_core_debug_rr (core, core->anal->reg, 0); + rz_core_debug_rr (core, core->anal->reg, 0); break; } break; case 'S': { // "arS" int sz; - ut8 *buf = r_reg_get_bytes (core->anal->reg, R_REG_TYPE_GPR, &sz); - r_cons_printf ("%d\n", sz); + ut8 *buf = rz_reg_get_bytes (core->anal->reg, R_REG_TYPE_GPR, &sz); + rz_cons_printf ("%d\n", sz); free (buf); } break; case 'b': { // "arb" WORK IN PROGRESS // DEBUG COMMAND int len, type = R_REG_TYPE_GPR; arg = strchr (str, ' '); if (arg) { - char *string = r_str_trim_dup (arg + 1); + char *string = rz_str_trim_dup (arg + 1); if (string) { - type = r_reg_type_by_name (string); + type = rz_reg_type_by_name (string); if (type == -1 && string[0] != 'a') { type = R_REG_TYPE_GPR; } free (string); } } - ut8 *buf = r_reg_get_bytes (core->dbg->reg, type, &len); + ut8 *buf = rz_reg_get_bytes (core->dbg->reg, type, &len); if (buf) { - r_print_hexdump (core->print, 0LL, buf, len, 32, 4, 1); + rz_print_hexdump (core->print, 0LL, buf, len, 32, 4, 1); free (buf); } } break; case 'c': // "arc" // TODO: set flag values with drc zf=1 if (str[1] == 'c') { // "arcc" - char *s = r_reg_profile_to_cc (core->anal->reg); + char *s = rz_reg_profile_to_cc (core->anal->reg); if (s) { - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); } } else { - RRegItem *r; - const char *name = r_str_trim_head_ro (str + 1); + RzRegItem *r; + const char *name = rz_str_trim_head_ro (str + 1); if (*name && name[1]) { - r = r_reg_cond_get (core->dbg->reg, name); + r = rz_reg_cond_get (core->dbg->reg, name); if (r) { - r_cons_println (r->name); + rz_cons_println (r->name); } else { - int id = r_reg_cond_from_string (name); - RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + int id = rz_reg_cond_from_string (name); + RzRegFlags *rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { - int o = r_reg_cond_bits (core->dbg->reg, id, rf); + int o = rz_reg_cond_bits (core->dbg->reg, id, rf); core->num->value = o; // ORLY? - r_cons_printf ("%d\n", o); + rz_cons_printf ("%d\n", o); free (rf); } else { eprintf ("unknown conditional or flag register\n"); } } } else { - RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + RzRegFlags *rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { - r_cons_printf ("| s:%d z:%d c:%d o:%d p:%d\n", + rz_cons_printf ("| s:%d z:%d c:%d o:%d p:%d\n", rf->s, rf->z, rf->c, rf->o, rf->p); if (*name == '=') { for (i = 0; i < R_REG_COND_LAST; i++) { - r_cons_printf ("%s:%d ", - r_reg_cond_to_string (i), - r_reg_cond_bits (core->dbg->reg, i, rf)); + rz_cons_printf ("%s:%d ", + rz_reg_cond_to_string (i), + rz_reg_cond_bits (core->dbg->reg, i, rf)); } - r_cons_newline (); + rz_cons_newline (); } else { for (i = 0; i < R_REG_COND_LAST; i++) { - r_cons_printf ("%d %s\n", - r_reg_cond_bits (core->dbg->reg, i, rf), - r_reg_cond_to_string (i)); + rz_cons_printf ("%d %s\n", + rz_reg_cond_bits (core->dbg->reg, i, rf), + rz_reg_cond_to_string (i)); } } free (rf); @@ -4659,12 +4659,12 @@ void cmd_anal_reg(RCore *core, const char *str) { case 's': // "ars" switch (str[1]) { case '-': // "ars-" - r_reg_arena_pop (core->dbg->reg); + rz_reg_arena_pop (core->dbg->reg); // restore debug registers if in debugger mode - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); break; case '+': // "ars+" - r_reg_arena_push (core->dbg->reg); + rz_reg_arena_push (core->dbg->reg); break; case '?': { // "ars?" // TODO #7967 help refactor: dup from drp @@ -4674,10 +4674,10 @@ void cmd_anal_reg(RCore *core, const char *str) { "drs+", "", "Push register state", "drs-", "", "Pop register state", NULL }; - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); } break; default: - r_cons_printf ("%d\n", r_list_length ( + rz_cons_printf ("%d\n", rz_list_length ( core->dbg->reg->regset[0].pool)); break; } @@ -4687,8 +4687,8 @@ void cmd_anal_reg(RCore *core, const char *str) { cmd_reg_profile (core, 'a', str); break; case 't': // "art" - for (i = 0; (name = r_reg_get_type (i)); i++) { - r_cons_println (name); + for (i = 0; (name = rz_reg_get_type (i)); i++) { + rz_cons_println (name); } break; case 'n': // "arn" @@ -4696,20 +4696,20 @@ void cmd_anal_reg(RCore *core, const char *str) { eprintf ("Oops. try arn [PC|SP|BP|A0|A1|A2|A3|A4|R0|R1|ZF|SF|NF|OF]\n"); break; } - name = r_reg_get_name (core->dbg->reg, r_reg_get_name_idx (str + 2)); + name = rz_reg_get_name (core->dbg->reg, rz_reg_get_name_idx (str + 2)); if (name && *name) { - r_cons_println (name); + rz_cons_println (name); } else { eprintf ("Oops. try arn [PC|SP|BP|A0|A1|A2|A3|A4|R0|R1|ZF|SF|NF|OF]\n"); } break; case 'd': // "ard" - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 3, use_color); // XXX detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 3, use_color); // XXX detect which one is current usage break; case 'o': // "aro" - r_reg_arena_swap (core->dbg->reg, false); - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 0, use_color); // XXX detect which one is current usage - r_reg_arena_swap (core->dbg->reg, false); + rz_reg_arena_swap (core->dbg->reg, false); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 0, use_color); // XXX detect which one is current usage + rz_reg_arena_swap (core->dbg->reg, false); break; case '=': // "ar=" { @@ -4720,13 +4720,13 @@ void cmd_anal_reg(RCore *core, const char *str) { if (str[1] != ':') { // Bits were specified bits = strtok (p, ":"); - if (r_str_isnumber (bits)) { - st64 sz = r_num_math (core->num, bits); + if (rz_str_isnumber (bits)) { + st64 sz = rz_num_math (core->num, bits); if (sz > 0) { size = sz; } } else { - r_core_cmd_help (core, help_msg_ar); + rz_core_cmd_help (core, help_msg_ar); break; } } @@ -4735,10 +4735,10 @@ void cmd_anal_reg(RCore *core, const char *str) { // We have some regs char *regs = bits ? strtok (NULL, ":") : strtok ((char *)str + 1, ":"); char *reg = strtok (regs, " "); - RList *q_regs = r_list_new (); + RzList *q_regs = rz_list_new (); if (q_regs) { while (reg) { - r_list_append (q_regs, reg); + rz_list_append (q_regs, reg); reg = strtok (NULL, " "); } core->dbg->q_regs = q_regs; @@ -4746,8 +4746,8 @@ void cmd_anal_reg(RCore *core, const char *str) { } } __anal_reg_list (core, type, size, str[0]); - if (!r_list_empty (core->dbg->q_regs)) { - r_list_free (core->dbg->q_regs); + if (!rz_list_empty (core->dbg->q_regs)) { + rz_list_free (core->dbg->q_regs); } core->dbg->q_regs = NULL; free (p); @@ -4766,27 +4766,27 @@ void cmd_anal_reg(RCore *core, const char *str) { arg = strchr (str + 1, '='); if (arg) { *arg = 0; - char *ostr = r_str_trim_dup (str + 1); - char *regname = r_str_trim_nc (ostr); - r = r_reg_get (core->dbg->reg, regname, -1); + char *ostr = rz_str_trim_dup (str + 1); + char *regname = rz_str_trim_nc (ostr); + r = rz_reg_get (core->dbg->reg, regname, -1); if (!r) { - int role = r_reg_get_name_idx (regname); + int role = rz_reg_get_name_idx (regname); if (role != -1) { - const char *alias = r_reg_get_name (core->dbg->reg, role); + const char *alias = rz_reg_get_name (core->dbg->reg, role); if (alias) { - r = r_reg_get (core->dbg->reg, alias, -1); + r = rz_reg_get (core->dbg->reg, alias, -1); } } } if (r) { //eprintf ("%s 0x%08"PFMT64x" -> ", str, - // r_reg_get_value (core->dbg->reg, r)); - r_reg_set_value (core->dbg->reg, r, - r_num_math (core->num, arg + 1)); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); + // rz_reg_get_value (core->dbg->reg, r)); + rz_reg_set_value (core->dbg->reg, r, + rz_num_math (core->num, arg + 1)); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); //eprintf ("0x%08"PFMT64x"\n", - // r_reg_get_value (core->dbg->reg, r)); - r_core_cmdf (core, ".dr*%d", bits); + // rz_reg_get_value (core->dbg->reg, r)); + rz_core_cmdf (core, ".dr*%d", bits); } else { eprintf ("ar: Unknown register '%s'\n", regname); } @@ -4801,12 +4801,12 @@ void cmd_anal_reg(RCore *core, const char *str) { } else { for (j = i; str[++j] && str[j] != ','; ); if (j - i + 1 <= sizeof name) { - r_str_ncpy (name, str + i, j - i + 1); + rz_str_ncpy (name, str + i, j - i + 1); if (IS_DIGIT (name[0])) { // e.g. ar 32 __anal_reg_list (core, R_REG_TYPE_GPR, atoi (name), '\0'); } else if (showreg (core, name) > 0) { // e.g. ar rax } else { // e.g. ar gpr ; ar all - type = r_reg_type_by_name (name); + type = rz_reg_type_by_name (name); // TODO differentiate ALL and illegal register types and print error message for the latter __anal_reg_list (core, type, -1, '\0'); } @@ -4818,51 +4818,51 @@ void cmd_anal_reg(RCore *core, const char *str) { } } -static ut64 initializeEsil(RCore *core) { - int romem = r_config_get_i (core->config, "esil.romem"); - int stats = r_config_get_i (core->config, "esil.stats"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int exectrap = r_config_get_i (core->config, "esil.exectrap"); - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int noNULL = r_config_get_i (core->config, "esil.noNULL"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { +static ut64 initializeEsil(RzCore *core) { + int romem = rz_config_get_i (core->config, "esil.romem"); + int stats = rz_config_get_i (core->config, "esil.stats"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int exectrap = rz_config_get_i (core->config, "esil.exectrap"); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int noNULL = rz_config_get_i (core->config, "esil.noNULL"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + if (!(core->anal->esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return UT64_MAX; } ut64 addr; - RAnalEsil *esil = core->anal->esil; - esil->verbose = r_config_get_i (core->config, "esil.verbose"); - esil->cmd = r_core_esil_cmd; - r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io + RzAnalEsil *esil = core->anal->esil; + esil->verbose = rz_config_get_i (core->config, "esil.verbose"); + esil->cmd = rz_core_esil_cmd; + rz_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io { - const char *cmd_esil_step = r_config_get (core->config, "cmd.esil.step"); + const char *cmd_esil_step = rz_config_get (core->config, "cmd.esil.step"); if (cmd_esil_step && *cmd_esil_step) { esil->cmd_step = strdup (cmd_esil_step); } - const char *cmd_esil_step_out = r_config_get (core->config, "cmd.esil.stepout"); + const char *cmd_esil_step_out = rz_config_get (core->config, "cmd.esil.stepout"); if (cmd_esil_step_out && *cmd_esil_step_out) { esil->cmd_step_out = strdup (cmd_esil_step_out); } { - const char *s = r_config_get (core->config, "cmd.esil.intr"); + const char *s = rz_config_get (core->config, "cmd.esil.intr"); if (s) { char *my = strdup (s); if (my) { - r_config_set (core->config, "cmd.esil.intr", my); + rz_config_set (core->config, "cmd.esil.intr", my); free (my); } } } } esil->exectrap = exectrap; - RList *entries = r_bin_get_entries (core->bin); + RzList *entries = rz_bin_get_entries (core->bin); RBinAddr *entry = NULL; RBinInfo *info = NULL; - if (entries && !r_list_empty (entries)) { - entry = (RBinAddr *)r_list_pop_head (entries); - info = r_bin_get_info (core->bin); + if (entries && !rz_list_empty (entries)) { + entry = (RBinAddr *)rz_list_pop_head (entries); + info = rz_bin_get_info (core->bin); addr = info->has_va? entry->vaddr: entry->paddr; - r_list_push (entries, entry); + rz_list_push (entries, entry); } else { addr = core->offset; } @@ -4870,31 +4870,31 @@ static ut64 initializeEsil(RCore *core) { return addr; } -R_API int r_core_esil_step(RCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver) { +RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver) { #define return_tail(x) { tail_return_value = x; goto tail_return; } int tail_return_value = 0; int ret; ut8 code[32]; - RAnalOp op = {0}; - RAnalEsil *esil = core->anal->esil; - const char *name = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + RzAnalOp op = {0}; + RzAnalEsil *esil = core->anal->esil; + const char *name = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); ut64 addr; - bool breakoninvalid = r_config_get_i (core->config, "esil.breakoninvalid"); - int esiltimeout = r_config_get_i (core->config, "esil.timeout"); + bool breakoninvalid = rz_config_get_i (core->config, "esil.breakoninvalid"); + int esiltimeout = rz_config_get_i (core->config, "esil.timeout"); ut64 startTime; if (esiltimeout > 0) { - startTime = r_time_now_mono (); + startTime = rz_time_now_mono (); } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); repeat: - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { eprintf ("[+] ESIL emulation interrupted at 0x%08" PFMT64x "\n", addr); return_tail (0); } //Break if we have exceeded esil.timeout if (esiltimeout > 0) { - ut64 elapsedTime = r_time_now_mono () - startTime; + ut64 elapsedTime = rz_time_now_mono () - startTime; elapsedTime >>= 20; if (elapsedTime >= esiltimeout) { eprintf ("[ESIL] Timeout exceeded.\n"); @@ -4909,47 +4909,47 @@ repeat: } } else { esil->trap = 0; - addr = r_reg_getv (core->anal->reg, name); + addr = rz_reg_getv (core->anal->reg, name); //eprintf ("PC=0x%"PFMT64x"\n", (ut64)addr); } if (prev_addr) { *prev_addr = addr; } if (esil->exectrap) { - if (!r_io_is_valid_offset (core->io, addr, R_PERM_X)) { + if (!rz_io_is_valid_offset (core->io, addr, R_PERM_X)) { esil->trap = R_ANAL_TRAP_EXEC_ERR; esil->trap_code = addr; eprintf ("[ESIL] Trap, trying to execute on non-executable memory\n"); return_tail (1); } } - r_asm_set_pc (core->rasm, addr); + rz_asm_set_pc (core->rasm, addr); // run esil pin command here - const char *pincmd = r_anal_pin_call (core->anal, addr); + const char *pincmd = rz_anal_pin_call (core->anal, addr); if (pincmd) { - r_core_cmd0 (core, pincmd); - ut64 pc = r_debug_reg_get (core->dbg, "PC"); + rz_core_cmd0 (core, pincmd); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); if (addr != pc) { return_tail (1); } } - int dataAlign = r_anal_archinfo (esil->anal, R_ANAL_ARCHINFO_DATA_ALIGN); + int dataAlign = rz_anal_archinfo (esil->anal, R_ANAL_ARCHINFO_DATA_ALIGN); if (dataAlign > 1) { if (addr % dataAlign) { if (esil->cmd && esil->cmd_trap) { esil->cmd (esil, esil->cmd_trap, addr, R_ANAL_TRAP_UNALIGNED); } if (breakoninvalid) { - r_cons_printf ("[ESIL] Stopped execution in an unaligned instruction (see e??esil.breakoninvalid)\n"); + rz_cons_printf ("[ESIL] Stopped execution in an unaligned instruction (see e??esil.breakoninvalid)\n"); return_tail (0); } } } - (void) r_io_read_at_mapped (core->io, addr, code, sizeof (code)); + (void) rz_io_read_at_mapped (core->io, addr, code, sizeof (code)); // TODO: sometimes this is dupe - ret = r_anal_op (core->anal, &op, addr, code, sizeof (code), R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); + ret = rz_anal_op (core->anal, &op, addr, code, sizeof (code), R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); // if type is JMP then we execute the next N instructions - // update the esil pointer because RAnal.op() can change it + // update the esil pointer because RzAnal.op() can change it esil = core->anal->esil; if (op.size < 1 || ret < 1) { if (esil->cmd && esil->cmd_trap) { @@ -4976,15 +4976,15 @@ repeat: if (addr == until_addr) { return_tail (0); } else { - r_reg_setv (core->anal->reg, "PC", op.addr + op.size); - r_reg_setv (core->dbg->reg, "PC", op.addr + op.size); + rz_reg_setv (core->anal->reg, "PC", op.addr + op.size); + rz_reg_setv (core->dbg->reg, "PC", op.addr + op.size); } return 1; } } - if (r_config_get_i (core->config, "cfg.r2wars")) { + if (rz_config_get_i (core->config, "cfg.r2wars")) { // this is x86 and r2wars specific, shouldnt hurt outside x86 - ut64 vECX = r_reg_getv (core->anal->reg, "ecx"); + ut64 vECX = rz_reg_getv (core->anal->reg, "ecx"); if (op.prefix & R_ANAL_OP_PREFIX_REP && vECX > 1) { char *tmp = strstr (op.esil.ptr, ",ecx,?{,5,GOTO,}"); if (tmp) { @@ -4992,29 +4992,29 @@ repeat: } op.esil.len -= 16; } else { - r_reg_setv (core->anal->reg, name, addr + op.size); + rz_reg_setv (core->anal->reg, name, addr + op.size); } } else { - r_reg_setv (core->anal->reg, name, addr + op.size); + rz_reg_setv (core->anal->reg, name, addr + op.size); } if (ret) { - r_anal_esil_set_pc (esil, addr); + rz_anal_esil_set_pc (esil, addr); const char *e = R_STRBUF_SAFEGET (&op.esil); if (core->dbg->trace->enabled) { - RReg *reg = core->dbg->reg; + RzReg *reg = core->dbg->reg; core->dbg->reg = core->anal->reg; - r_debug_trace_op (core->dbg, &op); + rz_debug_trace_op (core->dbg, &op); core->dbg->reg = reg; } else if (R_STR_ISNOTEMPTY (e)) { - r_anal_esil_parse (esil, e); + rz_anal_esil_parse (esil, e); if (core->anal->cur && core->anal->cur->esil_post_loop) { core->anal->cur->esil_post_loop (esil, &op); } - r_anal_esil_stack_free (esil); + rz_anal_esil_stack_free (esil); } bool isNextFall = false; if (op.type == R_ANAL_OP_TYPE_CJMP) { - ut64 pc = r_debug_reg_get (core->dbg, "PC"); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); if (pc == addr + op.size) { // do not opdelay here isNextFall = true; @@ -5024,12 +5024,12 @@ repeat: if (op.delay && !isNextFall) { ut8 code2[32]; ut64 naddr = addr + op.size; - RAnalOp op2 = {0}; + RzAnalOp op2 = {0}; // emulate only 1 instruction - r_anal_esil_set_pc (esil, naddr); - (void)r_io_read_at (core->io, naddr, code2, sizeof (code2)); + rz_anal_esil_set_pc (esil, naddr); + (void)rz_io_read_at (core->io, naddr, code2, sizeof (code2)); // TODO: sometimes this is dupe - ret = r_anal_op (core->anal, &op2, naddr, code2, sizeof (code2), R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); + ret = rz_anal_op (core->anal, &op2, naddr, code2, sizeof (code2), R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); if (ret > 0) { switch (op2.type) { case R_ANAL_OP_TYPE_CJMP: @@ -5045,35 +5045,35 @@ repeat: } const char *e = R_STRBUF_SAFEGET (&op2.esil); if (R_STR_ISNOTEMPTY (e)) { - r_anal_esil_parse (esil, e); + rz_anal_esil_parse (esil, e); } } else { eprintf ("Invalid instruction at 0x%08"PFMT64x"\n", naddr); } - r_anal_op_fini (&op2); + rz_anal_op_fini (&op2); } tail_return_value = 1; } // esil->verbose ? - // eprintf ("REPE 0x%llx %s => 0x%llx\n", addr, R_STRBUF_SAFEGET (&op.esil), r_reg_getv (core->anal->reg, "PC")); + // eprintf ("REPE 0x%llx %s => 0x%llx\n", addr, R_STRBUF_SAFEGET (&op.esil), rz_reg_getv (core->anal->reg, "PC")); - ut64 pc = r_reg_getv (core->anal->reg, name); + ut64 pc = rz_reg_getv (core->anal->reg, name); if (core->anal->pcalign > 0) { pc -= (pc % core->anal->pcalign); - r_reg_setv (core->anal->reg, name, pc); - r_reg_setv (core->dbg->reg, name, pc); + rz_reg_setv (core->anal->reg, name, pc); + rz_reg_setv (core->dbg->reg, name, pc); } - st64 follow = (st64)r_config_get_i (core->config, "dbg.follow"); + st64 follow = (st64)rz_config_get_i (core->config, "dbg.follow"); if (follow > 0) { - ut64 pc = r_debug_reg_get (core->dbg, "PC"); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); if ((pc < core->offset) || (pc > (core->offset + follow))) { - r_core_cmd0 (core, "sr PC"); + rz_core_cmd0 (core, "sr PC"); } } // check breakpoints - if (r_bp_get_at (core->dbg->bp, pc)) { - r_cons_printf ("[ESIL] hit breakpoint at 0x%"PFMT64x "\n", pc); + if (rz_bp_get_at (core->dbg->bp, pc)) { + rz_cons_printf ("[ESIL] hit breakpoint at 0x%"PFMT64x "\n", pc); return_tail (0); } // check addr @@ -5091,7 +5091,7 @@ repeat: return_tail (0); } if (until_expr) { - if (r_anal_esil_condition (core->anal->esil, until_expr)) { + if (rz_anal_esil_condition (core->anal->esil, until_expr)) { if (core->anal->esil->verbose) { eprintf ("ESIL BREAK!\n"); } @@ -5100,29 +5100,29 @@ repeat: goto repeat; } tail_return: - r_anal_op_fini (&op); - r_cons_break_pop (); + rz_anal_op_fini (&op); + rz_cons_break_pop (); return tail_return_value; } -R_API int r_core_esil_step_back(RCore *core) { - r_return_val_if_fail (core->anal->esil && core->anal->esil->trace, -1); - RAnalEsil *esil = core->anal->esil; +RZ_API int rz_core_esil_step_back(RzCore *core) { + rz_return_val_if_fail (core->anal->esil && core->anal->esil->trace, -1); + RzAnalEsil *esil = core->anal->esil; if (esil->trace->idx > 0) { - r_anal_esil_trace_restore (esil, esil->trace->idx - 1); + rz_anal_esil_trace_restore (esil, esil->trace->idx - 1); return 1; } return -1; } -static void cmd_address_info(RCore *core, const char *addrstr, int fmt) { +static void cmd_address_info(RzCore *core, const char *addrstr, int fmt) { ut64 addr, type; if (!addrstr || !*addrstr) { addr = core->offset; } else { - addr = r_num_math (core->num, addrstr); + addr = rz_num_math (core->num, addrstr); } - type = r_core_anal_address (core, addr); + type = rz_core_anal_address (core, addr); switch (fmt) { case 'j': { PJ *pj = pj_new (); @@ -5155,43 +5155,43 @@ static void cmd_address_info(RCore *core, const char *addrstr, int fmt) { if (type & R_ANAL_ADDR_TYPE_SEQUENCE) pj_ks (pj, "sequence", "true"); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; default: if (type & R_ANAL_ADDR_TYPE_PROGRAM) - r_cons_printf ("program\n"); + rz_cons_printf ("program\n"); if (type & R_ANAL_ADDR_TYPE_LIBRARY) - r_cons_printf ("library\n"); + rz_cons_printf ("library\n"); if (type & R_ANAL_ADDR_TYPE_EXEC) - r_cons_printf ("exec\n"); + rz_cons_printf ("exec\n"); if (type & R_ANAL_ADDR_TYPE_READ) - r_cons_printf ("read\n"); + rz_cons_printf ("read\n"); if (type & R_ANAL_ADDR_TYPE_WRITE) - r_cons_printf ("write\n"); + rz_cons_printf ("write\n"); if (type & R_ANAL_ADDR_TYPE_FLAG) - r_cons_printf ("flag\n"); + rz_cons_printf ("flag\n"); if (type & R_ANAL_ADDR_TYPE_FUNC) - r_cons_printf ("func\n"); + rz_cons_printf ("func\n"); if (type & R_ANAL_ADDR_TYPE_STACK) - r_cons_printf ("stack\n"); + rz_cons_printf ("stack\n"); if (type & R_ANAL_ADDR_TYPE_HEAP) - r_cons_printf ("heap\n"); + rz_cons_printf ("heap\n"); if (type & R_ANAL_ADDR_TYPE_REG) - r_cons_printf ("reg\n"); + rz_cons_printf ("reg\n"); if (type & R_ANAL_ADDR_TYPE_ASCII) - r_cons_printf ("ascii\n"); + rz_cons_printf ("ascii\n"); if (type & R_ANAL_ADDR_TYPE_SEQUENCE) - r_cons_printf ("sequence\n"); + rz_cons_printf ("sequence\n"); break; } } -static void cmd_anal_info(RCore *core, const char *input) { +static void cmd_anal_info(RzCore *core, const char *input) { switch (input[0]) { case '?': - r_core_cmd_help (core, help_msg_ai); + rz_core_cmd_help (core, help_msg_ai); break; case ' ': cmd_address_info (core, input, 0); @@ -5200,22 +5200,22 @@ static void cmd_anal_info(RCore *core, const char *input) { // global imports if (input[1]) { if (input[1] == ' ') { - char *s = r_str_trim_dup (input + 1); + char *s = rz_str_trim_dup (input + 1); if (s) { - r_anal_add_import (core->anal, s); + rz_anal_add_import (core->anal, s); free (s); } } else if (input[1] == '-') { - r_anal_purge_imports (core->anal); + rz_anal_purge_imports (core->anal); } else { eprintf ("Usagae: aii [namespace] # see afii - imports\n"); } } else { if (core->anal->imports) { char *imp; - RListIter *iter; - r_list_foreach (core->anal->imports, iter, imp) { - r_cons_printf ("%s\n", imp); + RzListIter *iter; + rz_list_foreach (core->anal->imports, iter, imp) { + rz_cons_printf ("%s\n", imp); } } } @@ -5229,68 +5229,68 @@ static void cmd_anal_info(RCore *core, const char *input) { } } -static void initialize_stack (RCore *core, ut64 addr, ut64 size) { - const char *mode = r_config_get (core->config, "esil.fillstack"); +static void initialize_stack (RzCore *core, ut64 addr, ut64 size) { + const char *mode = rz_config_get (core->config, "esil.fillstack"); if (mode && *mode && *mode != '0') { const ut64 bs = 4096 * 32; ut64 i; for (i = 0; i < size; i += bs) { ut64 left = R_MIN (bs, size - i); - // r_core_cmdf (core, "wx 10203040 @ 0x%llx", addr); + // rz_core_cmdf (core, "wx 10203040 @ 0x%llx", addr); switch (*mode) { case 'd': // "debrujn" - r_core_cmdf (core, "wopD %"PFMT64u" @ 0x%"PFMT64x, left, addr + i); + rz_core_cmdf (core, "wopD %"PFMT64u" @ 0x%"PFMT64x, left, addr + i); break; case 's': // "seq" - r_core_cmdf (core, "woe 1 0xff 1 4 @ 0x%"PFMT64x"!0x%"PFMT64x, addr + i, left); + rz_core_cmdf (core, "woe 1 0xff 1 4 @ 0x%"PFMT64x"!0x%"PFMT64x, addr + i, left); break; case 'r': // "random" - r_core_cmdf (core, "woR %"PFMT64u" @ 0x%"PFMT64x"!0x%"PFMT64x, left, addr + i, left); + rz_core_cmdf (core, "woR %"PFMT64u" @ 0x%"PFMT64x"!0x%"PFMT64x, left, addr + i, left); break; case 'z': // "zero" case '0': - r_core_cmdf (core, "wow 00 @ 0x%"PFMT64x"!0x%"PFMT64x, addr + i, left); + rz_core_cmdf (core, "wow 00 @ 0x%"PFMT64x"!0x%"PFMT64x, addr + i, left); break; } } // eprintf ("[*] Initializing ESIL stack with pattern\n"); - // r_core_cmdf (core, "woe 0 10 4 @ 0x%"PFMT64x, size, addr); + // rz_core_cmdf (core, "woe 0 10 4 @ 0x%"PFMT64x, size, addr); } } -static void cmd_esil_mem(RCore *core, const char *input) { - RAnalEsil *esil = core->anal->esil; - RIOMap *stack_map; +static void cmd_esil_mem(RzCore *core, const char *input) { + RzAnalEsil *esil = core->anal->esil; + RzIOMap *stack_map; ut64 curoff = core->offset; const char *patt = ""; ut64 addr = 0x100000; ut32 size = 0xf0000; char name[128]; - RFlagItem *fi; + RzFlagItem *fi; const char *sp, *bp, *pc; char uri[32]; char nomalloc[256]; char *p; if (!esil) { - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int romem = r_config_get_i (core->config, "esil.romem"); - int stats = r_config_get_i (core->config, "esil.stats"); - int noNULL = r_config_get_i (core->config, "esil.noNULL"); - int verbose = r_config_get_i (core->config, "esil.verbose"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int romem = rz_config_get_i (core->config, "esil.romem"); + int stats = rz_config_get_i (core->config, "esil.stats"); + int noNULL = rz_config_get_i (core->config, "esil.noNULL"); + int verbose = rz_config_get_i (core->config, "esil.verbose"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + if (!(esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } - r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io + rz_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io core->anal->esil = esil; esil->verbose = verbose; { - const char *s = r_config_get (core->config, "cmd.esil.intr"); + const char *s = rz_config_get (core->config, "cmd.esil.intr"); if (s) { char *my = strdup (s); if (my) { - r_config_set (core->config, "cmd.esil.intr", my); + rz_config_set (core->config, "cmd.esil.intr", my); free (my); } } @@ -5304,7 +5304,7 @@ static void cmd_esil_mem(RCore *core, const char *input) { } if (input[0] == 'p') { - fi = r_flag_get (core->flags, "aeim.stack"); + fi = rz_flag_get (core->flags, "aeim.stack"); if (fi) { addr = fi->offset; size = fi->size; @@ -5324,14 +5324,14 @@ static void cmd_esil_mem(RCore *core, const char *input) { if (fi) { // Close the fd associated with the aeim stack ut64 fd = sdb_atoi (fi); - (void)r_io_fd_close (core->io, fd); + (void)rz_io_fd_close (core->io, fd); } } - size = r_config_get_i (core->config, "esil.stack.size"); - addr = r_config_get_i (core->config, "esil.stack.addr"); + size = rz_config_get_i (core->config, "esil.stack.size"); + addr = rz_config_get_i (core->config, "esil.stack.addr"); { - RIOMap *map = r_io_map_get (core->io, addr); + RzIOMap *map = rz_io_map_get (core->io, addr); if (map) { addr = UT64_MAX; } @@ -5339,16 +5339,16 @@ static void cmd_esil_mem(RCore *core, const char *input) { if (addr == UT64_MAX) { const ut64 align = 0x10000000; - addr = r_io_map_next_available (core->io, core->offset, size, align); + addr = rz_io_map_next_available (core->io, core->offset, size, align); } - patt = r_config_get (core->config, "esil.stack.pattern"); + patt = rz_config_get (core->config, "esil.stack.pattern"); p = strncpy (nomalloc, input, 255); if ((p = strchr (p, ' '))) { while (*p == ' ') p++; - addr = r_num_math (core->num, p); + addr = rz_num_math (core->num, p); if ((p = strchr (p, ' '))) { while (*p == ' ') p++; - size = (ut32)r_num_math (core->num, p); + size = (ut32)rz_num_math (core->num, p); if (size < 1) { size = 0xf0000; } @@ -5368,121 +5368,121 @@ static void cmd_esil_mem(RCore *core, const char *input) { } if (*input == '-') { if (esil->stack_fd > 2) { //0, 1, 2 are reserved for stdio/stderr - r_io_fd_close (core->io, esil->stack_fd); - // no need to kill the maps, r_io_map_cleanup does that for us in the close + rz_io_fd_close (core->io, esil->stack_fd); + // no need to kill the maps, rz_io_map_cleanup does that for us in the close esil->stack_fd = 0; } else { eprintf ("Cannot deinitialize %s\n", name); } - r_flag_unset_name (core->flags, name); - r_flag_unset_name (core->flags, "aeim.stack"); + rz_flag_unset_name (core->flags, name); + rz_flag_unset_name (core->flags, "aeim.stack"); sdb_unset(core->sdb, "aeim.fd", 0); // eprintf ("Deinitialized %s\n", name); return; } snprintf (uri, sizeof (uri), "malloc://%d", (int)size); - esil->stack_fd = r_io_fd_open (core->io, uri, R_PERM_RW, 0); - if (!(stack_map = r_io_map_add (core->io, esil->stack_fd, R_PERM_RW, 0LL, addr, size))) { - r_io_fd_close (core->io, esil->stack_fd); + esil->stack_fd = rz_io_fd_open (core->io, uri, R_PERM_RW, 0); + if (!(stack_map = rz_io_map_add (core->io, esil->stack_fd, R_PERM_RW, 0LL, addr, size))) { + rz_io_fd_close (core->io, esil->stack_fd); eprintf ("Cannot create map for tha stack, fd %d got closed again\n", esil->stack_fd); esil->stack_fd = 0; return; } - r_io_map_set_name (stack_map, name); - // r_flag_set (core->flags, name, addr, size); //why is this here? + rz_io_map_set_name (stack_map, name); + // rz_flag_set (core->flags, name, addr, size); //why is this here? char val[128], *v; v = sdb_itoa (esil->stack_fd, val, 10); sdb_set(core->sdb, "aeim.fd", v, 0); - r_config_set_i (core->config, "io.va", true); + rz_config_set_i (core->config, "io.va", true); if (patt && *patt) { switch (*patt) { case '0': // do nothing break; case 'd': - r_core_cmdf (core, "wopD %d @ 0x%"PFMT64x, size, addr); + rz_core_cmdf (core, "wopD %d @ 0x%"PFMT64x, size, addr); break; case 'i': - r_core_cmdf (core, "woe 0 255 1 @ 0x%"PFMT64x"!%d",addr, size); + rz_core_cmdf (core, "woe 0 255 1 @ 0x%"PFMT64x"!%d",addr, size); break; case 'w': - r_core_cmdf (core, "woe 0 0xffff 1 4 @ 0x%"PFMT64x"!%d",addr, size); + rz_core_cmdf (core, "woe 0 0xffff 1 4 @ 0x%"PFMT64x"!%d",addr, size); break; } } // SP - sp = r_reg_get_name (core->dbg->reg, R_REG_NAME_SP); + sp = rz_reg_get_name (core->dbg->reg, R_REG_NAME_SP); if (sp) { - r_debug_reg_set (core->dbg, sp, addr + (size / 2)); + rz_debug_reg_set (core->dbg, sp, addr + (size / 2)); } // BP - bp = r_reg_get_name (core->dbg->reg, R_REG_NAME_BP); + bp = rz_reg_get_name (core->dbg->reg, R_REG_NAME_BP); if (bp) { - r_debug_reg_set (core->dbg, bp, addr + (size / 2)); + rz_debug_reg_set (core->dbg, bp, addr + (size / 2)); } // PC - pc = r_reg_get_name (core->dbg->reg, R_REG_NAME_PC); + pc = rz_reg_get_name (core->dbg->reg, R_REG_NAME_PC); if (pc) { - r_debug_reg_set (core->dbg, pc, curoff); + rz_debug_reg_set (core->dbg, pc, curoff); } - r_core_cmd0 (core, ".ar*"); + rz_core_cmd0 (core, ".ar*"); if (esil) { esil->stack_addr = addr; esil->stack_size = size; } initialize_stack (core, addr, size); - r_core_seek (core, curoff, false); + rz_core_seek (core, curoff, false); } #if 0 static ut64 opc = UT64_MAX; static ut8 *regstate = NULL; -static void esil_init (RCore *core) { - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - int noNULL = r_config_get_i (core->config, "esil.noNULL"); - opc = r_reg_getv (core->anal->reg, pc); +static void esil_init (RzCore *core) { + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + int noNULL = rz_config_get_i (core->config, "esil.noNULL"); + opc = rz_reg_getv (core->anal->reg, pc); if (!opc || opc==UT64_MAX) { opc = core->offset; } if (!core->anal->esil) { - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - ut64 stackSize = r_config_get_i (core->config, "esil.stack.size"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - if (!(core->anal->esil = r_anal_esil_new (stackSize, iotrap, addrsize))) { + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + ut64 stackSize = rz_config_get_i (core->config, "esil.stack.size"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + if (!(core->anal->esil = rz_anal_esil_new (stackSize, iotrap, addrsize))) { R_FREE (regstate); return; } - r_anal_esil_setup (core->anal->esil, core->anal, 0, 0, noNULL); + rz_anal_esil_setup (core->anal->esil, core->anal, 0, 0, noNULL); } free (regstate); - regstate = r_reg_arena_peek (core->anal->reg); + regstate = rz_reg_arena_peek (core->anal->reg); } -static void esil_fini(RCore *core) { - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - r_reg_arena_poke (core->anal->reg, regstate); - r_reg_setv (core->anal->reg, pc, opc); +static void esil_fini(RzCore *core) { + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + rz_reg_arena_poke (core->anal->reg, regstate); + rz_reg_setv (core->anal->reg, pc, opc); R_FREE (regstate); } #endif typedef struct { - RList *regs; - RList *regread; - RList *regwrite; - RList *regvalues; - RList *inputregs; + RzList *regs; + RzList *regread; + RzList *regwrite; + RzList *regvalues; + RzList *inputregs; } AeaStats; static void aea_stats_init (AeaStats *stats) { - stats->regs = r_list_newf (free); - stats->regread = r_list_newf (free); - stats->regwrite = r_list_newf (free); - stats->regvalues = r_list_newf (free); - stats->inputregs = r_list_newf (free); + stats->regs = rz_list_newf (free); + stats->regread = rz_list_newf (free); + stats->regwrite = rz_list_newf (free); + stats->regvalues = rz_list_newf (free); + stats->inputregs = rz_list_newf (free); } static void aea_stats_fini (AeaStats *stats) { @@ -5492,10 +5492,10 @@ static void aea_stats_fini (AeaStats *stats) { R_FREE (stats->inputregs); } -static bool contains(RList *list, const char *name) { - RListIter *iter; +static bool contains(RzList *list, const char *name) { + RzListIter *iter; const char *n; - r_list_foreach (list, iter, n) { + rz_list_foreach (list, iter, n) { if (!strcmp (name, n)) return true; } @@ -5503,8 +5503,8 @@ static bool contains(RList *list, const char *name) { } static char *oldregread = NULL; -static RList *mymemxsr = NULL; -static RList *mymemxsw = NULL; +static RzList *mymemxsr = NULL; +static RzList *mymemxsw = NULL; #define R_NEW_DUP(x) memcpy((void*)malloc(sizeof(x)), &(x), sizeof(x)) typedef struct { @@ -5512,131 +5512,131 @@ typedef struct { int size; } AeaMemItem; -static int mymemwrite(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { - RListIter *iter; +static int mymemwrite(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { + RzListIter *iter; AeaMemItem *n; - r_list_foreach (mymemxsw, iter, n) { + rz_list_foreach (mymemxsw, iter, n) { if (addr == n->addr) { return len; } } - if (!r_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { + if (!rz_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { return false; } n = R_NEW (AeaMemItem); if (n) { n->addr = addr; n->size = len; - r_list_push (mymemxsw, n); + rz_list_push (mymemxsw, n); } return len; } -static int mymemread(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { - RListIter *iter; +static int mymemread(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { + RzListIter *iter; AeaMemItem *n; - r_list_foreach (mymemxsr, iter, n) { + rz_list_foreach (mymemxsr, iter, n) { if (addr == n->addr) { return len; } } - if (!r_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { + if (!rz_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { return false; } n = R_NEW (AeaMemItem); if (n) { n->addr = addr; n->size = len; - r_list_push (mymemxsr, n); + rz_list_push (mymemxsr, n); } return len; } -static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { +static int myregwrite(RzAnalEsil *esil, const char *name, ut64 *val) { AeaStats *stats = esil->user; if (oldregread && !strcmp (name, oldregread)) { - r_list_pop (stats->regread); + rz_list_pop (stats->regread); R_FREE (oldregread) } if (!IS_DIGIT (*name)) { if (!contains (stats->regs, name)) { - r_list_push (stats->regs, strdup (name)); + rz_list_push (stats->regs, strdup (name)); } if (!contains (stats->regwrite, name)) { - r_list_push (stats->regwrite, strdup (name)); + rz_list_push (stats->regwrite, strdup (name)); } - char *v = r_str_newf ("%"PFMT64d, *val); + char *v = rz_str_newf ("%"PFMT64d, *val); if (!contains (stats->regvalues, v)) { - r_list_push (stats->regvalues, strdup (v)); + rz_list_push (stats->regvalues, strdup (v)); } free (v); } return 0; } -static int myregread(RAnalEsil *esil, const char *name, ut64 *val, int *len) { +static int myregread(RzAnalEsil *esil, const char *name, ut64 *val, int *len) { AeaStats *stats = esil->user; if (!IS_DIGIT (*name)) { if (!contains (stats->inputregs, name)) { if (!contains (stats->regwrite, name)) { - r_list_push (stats->inputregs, strdup (name)); + rz_list_push (stats->inputregs, strdup (name)); } } if (!contains (stats->regs, name)) { - r_list_push (stats->regs, strdup (name)); + rz_list_push (stats->regs, strdup (name)); } if (!contains (stats->regread, name)) { - r_list_push (stats->regread, strdup (name)); + rz_list_push (stats->regread, strdup (name)); } } return 0; } -static void showregs (RList *list) { - if (!r_list_empty (list)) { +static void showregs (RzList *list) { + if (!rz_list_empty (list)) { char *reg; - RListIter *iter; - r_list_foreach (list, iter, reg) { - r_cons_print (reg); + RzListIter *iter; + rz_list_foreach (list, iter, reg) { + rz_cons_print (reg); if (iter->n) { - r_cons_printf (" "); + rz_cons_printf (" "); } } } - r_cons_newline(); + rz_cons_newline(); } -static void showmem (RList *list) { - if (!r_list_empty (list)) { +static void showmem (RzList *list) { + if (!rz_list_empty (list)) { AeaMemItem *item; - RListIter *iter; - r_list_foreach (list, iter, item) { - r_cons_printf (" 0x%08"PFMT64x, item->addr); + RzListIter *iter; + rz_list_foreach (list, iter, item) { + rz_cons_printf (" 0x%08"PFMT64x, item->addr); } } - r_cons_newline (); + rz_cons_newline (); } -static void showregs_json (RList *list, PJ *pj) { +static void showregs_json (RzList *list, PJ *pj) { pj_a (pj); - if (!r_list_empty (list)) { + if (!rz_list_empty (list)) { char *reg; - RListIter *iter; + RzListIter *iter; - r_list_foreach (list, iter, reg) { + rz_list_foreach (list, iter, reg) { pj_s (pj, reg); } } pj_end (pj); } -static void showmem_json (RList *list, PJ *pj) { +static void showmem_json (RzList *list, PJ *pj) { pj_a (pj); - if (!r_list_empty (list)) { - RListIter *iter; + if (!rz_list_empty (list)) { + RzListIter *iter; AeaMemItem *item; - r_list_foreach (list, iter, item) { + rz_list_foreach (list, iter, item) { pj_n (pj, item->addr); } } @@ -5644,20 +5644,20 @@ static void showmem_json (RList *list, PJ *pj) { pj_end (pj); } -static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { - RAnalEsil *esil; +static bool cmd_aea(RzCore* core, int mode, ut64 addr, int length) { + RzAnalEsil *esil; int ptr, ops, ops_end = 0, len, buf_sz, maxopsize; ut64 addr_end; AeaStats stats; const char *esilstr; - RAnalOp aop = R_EMPTY; + RzAnalOp aop = R_EMPTY; ut8 *buf; - RList* regnow; + RzList* regnow; PJ *pj = NULL; if (!core) { return false; } - maxopsize = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + maxopsize = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); if (maxopsize < 1) { maxopsize = 16; } @@ -5680,24 +5680,24 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { if (!buf) { return false; } - (void)r_io_read_at (core->io, addr, (ut8 *)buf, buf_sz); + (void)rz_io_read_at (core->io, addr, (ut8 *)buf, buf_sz); aea_stats_init (&stats); //esil_init (core); //esil = core->anal->esil; - r_reg_arena_push (core->anal->reg); - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - bool iotrap = r_config_get_i (core->config, "esil.iotrap"); - int romem = r_config_get_i (core->config, "esil.romem"); - int stats1 = r_config_get_i (core->config, "esil.stats"); - int noNULL = r_config_get_i (core->config, "esil.noNULL"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - esil = r_anal_esil_new (stacksize, iotrap, addrsize); - r_anal_esil_setup (esil, core->anal, romem, stats1, noNULL); // setup io + rz_reg_arena_push (core->anal->reg); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + bool iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int romem = rz_config_get_i (core->config, "esil.romem"); + int stats1 = rz_config_get_i (core->config, "esil.stats"); + int noNULL = rz_config_get_i (core->config, "esil.noNULL"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + esil = rz_anal_esil_new (stacksize, iotrap, addrsize); + rz_anal_esil_setup (esil, core->anal, romem, stats1, noNULL); // setup io # define hasNext(x) (x&1) ? (addruser = &stats; esil->cb.hook_reg_write = myregwrite; esil->cb.hook_reg_read = myregread; @@ -5705,7 +5705,7 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { esil->cb.hook_mem_read = mymemread; esil->nowrite = true; for (ops = ptr = 0; ptr < buf_sz && hasNext (mode); ops++, ptr += len) { - len = r_anal_op (core->anal, &aop, addr + ptr, buf + ptr, buf_sz - ptr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); + len = rz_anal_op (core->anal, &aop, addr + ptr, buf + ptr, buf_sz - ptr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); esilstr = R_STRBUF_SAFEGET (&aop.esil); if (R_STR_ISNOTEMPTY (esilstr)) { if (len < 1) { @@ -5713,7 +5713,7 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { addr + ptr, buf[ptr], buf[ptr + 1]); break; } - if (r_config_get_i (core->config, "cfg.r2wars")) { + if (rz_config_get_i (core->config, "cfg.r2wars")) { if (aop.prefix & R_ANAL_OP_PREFIX_REP) { char * tmp = strstr (esilstr, ",ecx,?{,5,GOTO,}"); if (tmp) { @@ -5721,38 +5721,38 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { } } } - r_anal_esil_parse (esil, esilstr); - r_anal_esil_stack_free (esil); + rz_anal_esil_parse (esil, esilstr); + rz_anal_esil_stack_free (esil); } - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } esil->nowrite = false; esil->cb.hook_reg_write = NULL; esil->cb.hook_reg_read = NULL; //esil_fini (core); - r_anal_esil_free (esil); - r_reg_arena_pop (core->anal->reg); - regnow = r_list_newf (free); + rz_anal_esil_free (esil); + rz_reg_arena_pop (core->anal->reg); + regnow = rz_list_newf (free); { - RListIter *iter; + RzListIter *iter; char *reg; - r_list_foreach (stats.regs, iter, reg) { + rz_list_foreach (stats.regs, iter, reg) { if (!contains (stats.regwrite, reg)) { - r_list_push (regnow, strdup (reg)); + rz_list_push (regnow, strdup (reg)); } } } if ((mode >> 5) & 1) { - RListIter *iter; + RzListIter *iter; AeaMemItem *n; int c = 0; - r_cons_printf ("f-mem.*\n"); - r_list_foreach (mymemxsr, iter, n) { - r_cons_printf ("f mem.read.%d 0x%08x @ 0x%08"PFMT64x"\n", c++, n->size, n->addr); + rz_cons_printf ("f-mem.*\n"); + rz_list_foreach (mymemxsr, iter, n) { + rz_cons_printf ("f mem.read.%d 0x%08x @ 0x%08"PFMT64x"\n", c++, n->size, n->addr); } c = 0; - r_list_foreach (mymemxsw, iter, n) { - r_cons_printf ("f mem.write.%d 0x%08x @ 0x%08"PFMT64x"\n", c++, n->size, n->addr); + rz_list_foreach (mymemxsw, iter, n) { + rz_cons_printf ("f mem.write.%d 0x%08x @ 0x%08"PFMT64x"\n", c++, n->size, n->addr); } } @@ -5777,65 +5777,65 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { showregs_json (stats.regread, pj); pj_k (pj, "W"); showregs_json (stats.regwrite, pj); - if (!r_list_empty (stats.regvalues)) { + if (!rz_list_empty (stats.regvalues)) { pj_k (pj, "V"); showregs_json (stats.regvalues, pj); } - if (!r_list_empty (regnow)){ + if (!rz_list_empty (regnow)){ pj_k (pj, "N"); showregs_json (regnow, pj); } - if (!r_list_empty (mymemxsr)){ + if (!rz_list_empty (mymemxsr)){ pj_k (pj, "@R"); showmem_json (mymemxsr, pj); } - if (!r_list_empty (mymemxsw)){ + if (!rz_list_empty (mymemxsw)){ pj_k (pj, "@W"); showmem_json (mymemxsw, pj); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else if ((mode >> 5) & 1) { // nothing } else { - if (!r_list_empty (stats.inputregs)) { - r_cons_printf (" I: "); + if (!rz_list_empty (stats.inputregs)) { + rz_cons_printf (" I: "); showregs (stats.inputregs); } - if (!r_list_empty (stats.regs)) { - r_cons_printf (" A: "); + if (!rz_list_empty (stats.regs)) { + rz_cons_printf (" A: "); showregs (stats.regs); } - if (!r_list_empty (stats.regread)) { - r_cons_printf (" R: "); + if (!rz_list_empty (stats.regread)) { + rz_cons_printf (" R: "); showregs (stats.regread); } - if (!r_list_empty (stats.regwrite)) { - r_cons_printf (" W: "); + if (!rz_list_empty (stats.regwrite)) { + rz_cons_printf (" W: "); showregs (stats.regwrite); } - if (!r_list_empty (stats.regvalues)) { - r_cons_printf (" V: "); + if (!rz_list_empty (stats.regvalues)) { + rz_cons_printf (" V: "); showregs (stats.regvalues); } - if (!r_list_empty (regnow)){ - r_cons_printf (" N: "); + if (!rz_list_empty (regnow)){ + rz_cons_printf (" N: "); showregs (regnow); } - if (!r_list_empty (mymemxsr)){ - r_cons_printf ("@R:"); + if (!rz_list_empty (mymemxsr)){ + rz_cons_printf ("@R:"); showmem (mymemxsr); } - if (!r_list_empty (mymemxsw)){ - r_cons_printf ("@W:"); + if (!rz_list_empty (mymemxsw)){ + rz_cons_printf ("@W:"); showmem (mymemxsw); } } - r_list_free (mymemxsr); - r_list_free (mymemxsw); + rz_list_free (mymemxsr); + rz_list_free (mymemxsw); mymemxsr = NULL; mymemxsw = NULL; aea_stats_fini (&stats); @@ -5844,23 +5844,23 @@ static bool cmd_aea(RCore* core, int mode, ut64 addr, int length) { return true; } -static void cmd_aespc(RCore *core, ut64 addr, ut64 until_addr, int off) { - RAnalEsil *esil = core->anal->esil; +static void cmd_aespc(RzCore *core, ut64 addr, ut64 until_addr, int off) { + RzAnalEsil *esil = core->anal->esil; int i, j = 0; ut8 *buf; - RAnalOp aop = {0}; + RzAnalOp aop = {0}; int ret , bsize = R_MAX (4096, core->blocksize); - const int mininstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + const int mininstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); - const char *pc = r_reg_get_name (core->dbg->reg, R_REG_NAME_PC); - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - ut64 addrsize = r_config_get_i (core->config, "esil.addr.size"); + const char *pc = rz_reg_get_name (core->dbg->reg, R_REG_NAME_PC); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + ut64 addrsize = rz_config_get_i (core->config, "esil.addr.size"); // eprintf (" aesB %llx %llx %d\n", addr, until_addr, off); // 0x%08llx %d %s\n", aop.addr, ret, aop.mnemonic); if (!esil) { eprintf ("Warning: cmd_espc: creating new esil instance\n"); - if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + if (!(esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } core->anal->esil = esil; @@ -5872,14 +5872,14 @@ static void cmd_aespc(RCore *core, ut64 addr, ut64 until_addr, int off) { return; } if (addr == -1) { - addr = r_reg_getv (core->dbg->reg, pc); + addr = rz_reg_getv (core->dbg->reg, pc); } - (void)r_anal_esil_setup (core->anal->esil, core->anal, 0, 0, 0); // int romem, int stats, int nonull) { - ut64 cursp = r_reg_getv (core->dbg->reg, "SP"); + (void)rz_anal_esil_setup (core->anal->esil, core->anal, 0, 0, 0); // int romem, int stats, int nonull) { + ut64 cursp = rz_reg_getv (core->dbg->reg, "SP"); ut64 oldoff = core->offset; const ut64 flags = R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_DISASM; for (i = 0, j = 0; j < off ; i++, j++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (i >= (bsize - 32)) { @@ -5887,12 +5887,12 @@ static void cmd_aespc(RCore *core, ut64 addr, ut64 until_addr, int off) { eprintf ("Warning: Chomp\n"); } if (!i) { - r_io_read_at (core->io, addr, buf, bsize); + rz_io_read_at (core->io, addr, buf, bsize); } if (addr == until_addr) { break; } - ret = r_anal_op (core->anal, &aop, addr, buf + i, bsize - i, flags); + ret = rz_anal_op (core->anal, &aop, addr, buf + i, bsize - i, flags); if (ret < 1) { eprintf ("Failed analysis at 0x%08"PFMT64x"\n", addr); break; @@ -5901,12 +5901,12 @@ static void cmd_aespc(RCore *core, ut64 addr, ut64 until_addr, int off) { if (aop.type == R_ANAL_OP_TYPE_CALL) { // nothing } else { - r_reg_setv (core->anal->reg, "PC", aop.addr + aop.size); - r_reg_setv (core->dbg->reg, "PC", aop.addr + aop.size); + rz_reg_setv (core->anal->reg, "PC", aop.addr + aop.size); + rz_reg_setv (core->dbg->reg, "PC", aop.addr + aop.size); const char *e = R_STRBUF_SAFEGET (&aop.esil); if (e && *e) { // eprintf (" 0x%08llx %d %s\n", aop.addr, ret, aop.mnemonic); - (void)r_anal_esil_parse (esil, e); + (void)rz_anal_esil_parse (esil, e); } } int inc = (core->search->align > 0)? core->search->align - 1: ret - 1; @@ -5915,23 +5915,23 @@ static void cmd_aespc(RCore *core, ut64 addr, ut64 until_addr, int off) { } i += inc; addr += ret; // aop.size; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } - r_core_seek (core, oldoff, true); - r_reg_setv (core->dbg->reg, "SP", cursp); + rz_core_seek (core, oldoff, true); + rz_reg_setv (core->dbg->reg, "SP", cursp); } static const char _handler_no_name[] = ""; static int _aeli_iter(dictkv* kv, void* ud) { - RAnalEsilInterrupt* interrupt = kv->u; - r_cons_printf ("%3x: %s\n", kv->k, interrupt->handler->name ? interrupt->handler->name : _handler_no_name); + RzAnalEsilInterrupt* interrupt = kv->u; + rz_cons_printf ("%3x: %s\n", kv->k, interrupt->handler->name ? interrupt->handler->name : _handler_no_name); return 0; } -static void r_anal_aefa(RCore *core, const char *arg) { - ut64 to = r_num_math (core->num, arg); +static void rz_anal_aefa(RzCore *core, const char *arg) { + ut64 to = rz_num_math (core->num, arg); ut64 at, from = core->offset; - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, to, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, to, -1); if (!from || from == UT64_MAX) { if (fcn) { from = fcn->addr; @@ -5945,82 +5945,82 @@ static void r_anal_aefa(RCore *core, const char *arg) { // emulate // XXX do not use commands, here, just use the api - r_core_cmd0 (core, "aeim"); // XXX + rz_core_cmd0 (core, "aeim"); // XXX ut64 off = core->offset; for (at = from; at < to ; at++) { - r_core_cmdf (core, "aepc 0x%08"PFMT64x, at); - r_core_cmd0 (core, "aeso"); - r_core_seek (core, at, true); - int delta = r_num_get (core->num, "$l"); + rz_core_cmdf (core, "aepc 0x%08"PFMT64x, at); + rz_core_cmd0 (core, "aeso"); + rz_core_seek (core, at, true); + int delta = rz_num_get (core->num, "$l"); if (delta < 1) { break; } at += delta - 1; } - r_core_seek (core, off, true); + rz_core_seek (core, off, true); // the logic of identifying args by function types and // show json format and arg name goes into arA - r_core_cmd0 (core, "arA"); + rz_core_cmd0 (core, "arA"); #if 0 // get results - const char *fcn_type = r_type_func_ret (core->anal->sdb_types, fcn->name); + const char *fcn_type = rz_type_func_ret (core->anal->sdb_types, fcn->name); const char *key = resolve_fcn_name (core->anal, fcn->name); - RList *list = r_core_get_func_args (core, key); - if (!r_list_empty (list)) { + RzList *list = rz_core_get_func_args (core, key); + if (!rz_list_empty (list)) { eprintf ("HAS signature\n"); } - int i, nargs = 3; // r_type_func_args_count (core->anal->sdb_types, fcn->name); + int i, nargs = 3; // rz_type_func_args_count (core->anal->sdb_types, fcn->name); if (nargs > 0) { int i; eprintf ("NARGS %d (%s)\n", nargs, key); for (i = 0; i < nargs; i++) { - ut64 v = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_STDCALL, i); + ut64 v = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_STDCALL, i); eprintf ("arg: 0x%08"PFMT64x"\n", v); } } #endif } -static void __core_anal_appcall(RCore *core, const char *input) { -// r_reg_arena_push (core->dbg->reg); - RListIter *iter; +static void __core_anal_appcall(RzCore *core, const char *input) { +// rz_reg_arena_push (core->dbg->reg); + RzListIter *iter; char *arg; char *inp = strdup (input); - RList *args = r_str_split_list (inp, " ", 0); + RzList *args = rz_str_split_list (inp, " ", 0); int i = 0; - r_list_foreach (args, iter, arg) { + rz_list_foreach (args, iter, arg) { const char *alias = sdb_fmt ("A%d", i); - r_reg_setv (core->anal->reg, alias, r_num_math (core->num, arg)); + rz_reg_setv (core->anal->reg, alias, rz_num_math (core->num, arg)); i++; } - ut64 sp = r_reg_getv (core->anal->reg, "SP"); - r_reg_setv (core->anal->reg, "SP", 0); + ut64 sp = rz_reg_getv (core->anal->reg, "SP"); + rz_reg_setv (core->anal->reg, "SP", 0); - r_reg_setv (core->anal->reg, "PC", core->offset); - r_core_cmd0 (core, "aesu 0"); + rz_reg_setv (core->anal->reg, "PC", core->offset); + rz_core_cmd0 (core, "aesu 0"); - r_reg_setv (core->anal->reg, "SP", sp); + rz_reg_setv (core->anal->reg, "SP", sp); free (inp); -// r_reg_arena_pop (core->dbg->reg); +// rz_reg_arena_pop (core->dbg->reg); } -static void __anal_esil_function(RCore *core, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; +static void __anal_esil_function(RzCore *core, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; if (!core->anal->esil) { - r_core_cmd0 (core, "aeim"); - // core->anal->esil = r_anal_esil_new (stacksize, 0, addrsize); + rz_core_cmd0 (core, "aeim"); + // core->anal->esil = rz_anal_esil_new (stacksize, 0, addrsize); } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (fcn) { // emulate every instruction in the function recursively across all the basic blocks - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { ut64 pc = bb->addr; ut64 end = bb->addr + bb->size; - RAnalOp op; + RzAnalOp op; int ret, bbs = end - pc; if (bbs < 1 || bbs > 0xfffff || pc >= end) { eprintf ("Invalid block size\n"); @@ -6031,13 +6031,13 @@ static void __anal_esil_function(RCore *core, ut64 addr) { if (!buf) { break; } - r_io_read_at (core->io, pc, buf, bbs); + rz_io_read_at (core->io, pc, buf, bbs); int left; bool opskip; while (pc < end) { left = R_MIN (end - pc, 32); - // r_asm_set_pc (core->rasm, pc); - ret = r_anal_op (core->anal, &op, pc, buf + pc - bb->addr, left, R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_ESIL); // read overflow + // rz_asm_set_pc (core->rasm, pc); + ret = rz_anal_op (core->anal, &op, pc, buf + pc - bb->addr, left, R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_ESIL); // read overflow opskip = false; switch (op.type) { case R_ANAL_OP_TYPE_CALL: @@ -6047,41 +6047,41 @@ static void __anal_esil_function(RCore *core, ut64 addr) { } if (ret) { if (opskip) { - r_reg_set_value_by_role (core->anal->reg, R_REG_NAME_PC, pc); - r_anal_esil_parse (core->anal->esil, R_STRBUF_SAFEGET (&op.esil)); - r_anal_esil_dumpstack (core->anal->esil); - r_anal_esil_stack_free (core->anal->esil); + rz_reg_set_value_by_role (core->anal->reg, R_REG_NAME_PC, pc); + rz_anal_esil_parse (core->anal->esil, R_STRBUF_SAFEGET (&op.esil)); + rz_anal_esil_dumpstack (core->anal->esil); + rz_anal_esil_stack_free (core->anal->esil); } pc += op.size; } else { pc += 4; // XXX } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } free (buf); } } else { eprintf ("Cannot find function at 0x%08" PFMT64x "\n", addr); } - r_anal_esil_free (core->anal->esil); + rz_anal_esil_free (core->anal->esil); } -static void cmd_anal_esil(RCore *core, const char *input) { - RAnalEsil *esil = core->anal->esil; +static void cmd_anal_esil(RzCore *core, const char *input) { + RzAnalEsil *esil = core->anal->esil; ut64 addr = core->offset; ut64 adr ; char *n, *n1; int off; - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int romem = r_config_get_i (core->config, "esil.romem"); - int stats = r_config_get_i (core->config, "esil.stats"); - int noNULL = r_config_get_i (core->config, "esil.noNULL"); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int romem = rz_config_get_i (core->config, "esil.romem"); + int stats = rz_config_get_i (core->config, "esil.stats"); + int noNULL = rz_config_get_i (core->config, "esil.noNULL"); ut64 until_addr = UT64_MAX; - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); const char *until_expr = NULL; - RAnalOp *op = NULL; + RzAnalOp *op = NULL; switch (input[0]) { case 'p': // "aep" @@ -6089,26 +6089,26 @@ static void cmd_anal_esil(RCore *core, const char *input) { case 'c': // "aepc" if (input[2] == ' ' || input[2] == '=') { // seek to this address - r_core_cmdf (core, "ar PC=%s", r_str_trim_head_ro (input + 3)); - r_core_cmd0 (core, ".ar*"); + rz_core_cmdf (core, "ar PC=%s", rz_str_trim_head_ro (input + 3)); + rz_core_cmd0 (core, ".ar*"); } else { eprintf ("Missing argument\n"); } break; case 0: - r_anal_pin_list (core->anal); + rz_anal_pin_list (core->anal); break; case '-': if (input[2]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } - r_anal_pin_unset (core->anal, addr); + rz_anal_pin_unset (core->anal, addr); break; case ' ': - r_anal_pin (core->anal, addr, input + 2); + rz_anal_pin (core->anal, addr, input + 2); break; default: - r_core_cmd_help (core, help_msg_aep); + rz_core_cmd_help (core, help_msg_aep); break; } break; @@ -6119,22 +6119,22 @@ static void cmd_anal_esil(RCore *core, const char *input) { case '*': // XXX: this is wip, not working atm if (core->anal->esil) { - r_cons_printf ("trap: %d\n", core->anal->esil->trap); - r_cons_printf ("trap-code: %d\n", core->anal->esil->trap_code); + rz_cons_printf ("trap: %d\n", core->anal->esil->trap); + rz_cons_printf ("trap-code: %d\n", core->anal->esil->trap_code); } else { eprintf ("esil vm not initialized. run `aei`\n"); } break; case ' ': - //r_anal_esil_eval (core->anal, input+1); - if (!esil && !(core->anal->esil = esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + //rz_anal_esil_eval (core->anal, input+1); + if (!esil && !(core->anal->esil = esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } - r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io - r_anal_esil_set_pc (esil, core->offset); - r_anal_esil_parse (esil, input + 1); - r_anal_esil_dumpstack (esil); - r_anal_esil_stack_free (esil); + rz_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io + rz_anal_esil_set_pc (esil, core->offset); + rz_anal_esil_parse (esil, input + 1); + rz_anal_esil_dumpstack (esil); + rz_anal_esil_stack_free (esil); break; case 's': // "aes" // "aes" "aeso" "aesu" "aesue" @@ -6145,42 +6145,42 @@ static void cmd_anal_esil(RCore *core, const char *input) { // aesue -> until esil expression switch (input[1]) { case '?': - r_core_cmd0 (core, "ae?~aes"); + rz_core_cmd0 (core, "ae?~aes"); break; case 'l': // "aesl" { - ut64 pc = r_debug_reg_get (core->dbg, "PC"); - RAnalOp *op = r_core_anal_op (core, pc, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); + RzAnalOp *op = rz_core_anal_op (core, pc, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); // TODO: honor hint if (!op) { break; } - r_core_esil_step (core, UT64_MAX, NULL, NULL, false); - r_debug_reg_set (core->dbg, "PC", pc + op->size); - r_anal_esil_set_pc (esil, pc + op->size); - r_core_cmd0 (core, ".ar*"); - r_anal_op_free (op); + rz_core_esil_step (core, UT64_MAX, NULL, NULL, false); + rz_debug_reg_set (core->dbg, "PC", pc + op->size); + rz_anal_esil_set_pc (esil, pc + op->size); + rz_core_cmd0 (core, ".ar*"); + rz_anal_op_free (op); } break; case 'b': // "aesb" - if (!r_core_esil_step_back (core)) { + if (!rz_core_esil_step_back (core)) { eprintf ("cannnot step back\n"); } - r_core_cmd0 (core, ".ar*"); + rz_core_cmd0 (core, ".ar*"); break; case 'B': // "aesB" { n = strchr (input + 2, ' '); char *n2 = NULL; if (n) { - n = (char *)r_str_trim_head_ro (n + 1); + n = (char *)rz_str_trim_head_ro (n + 1); } if (n) { n2 = strchr (n, ' '); if (n2) { *n2++ = 0; } - ut64 off = r_num_math (core->num, n); - ut64 nth = n2? r_num_math (core->num, n2): 1; + ut64 off = rz_num_math (core->num, n); + ut64 nth = n2? rz_num_math (core->num, n2): 1; cmd_aespc (core, core->offset, off, (int)nth); } else { eprintf ("Usage: aesB [until-addr] [nth-opcodes] @ [from-addr]\n"); @@ -6190,59 +6190,59 @@ static void cmd_anal_esil(RCore *core, const char *input) { case 'u': // "aesu" until_expr = NULL; until_addr = UT64_MAX; - if (r_str_endswith (input, "?")) { - r_core_cmd0 (core, "ae?~aesu"); + if (rz_str_endswith (input, "?")) { + rz_core_cmd0 (core, "ae?~aesu"); } else switch (input[2]) { case 'e': // "aesue" until_expr = input + 3; break; case ' ': // "aesu" - until_addr = r_num_math (core->num, input + 2); + until_addr = rz_num_math (core->num, input + 2); break; case 'o': // "aesuo" - step_until_optype (core, r_str_trim_head_ro (input + 3)); + step_until_optype (core, rz_str_trim_head_ro (input + 3)); break; default: - r_core_cmd0 (core, "ae?~aesu"); + rz_core_cmd0 (core, "ae?~aesu"); break; } if (until_expr || until_addr != UT64_MAX) { - r_core_esil_step (core, until_addr, until_expr, NULL, false); + rz_core_esil_step (core, until_addr, until_expr, NULL, false); } - r_core_cmd0 (core, ".ar*"); + rz_core_cmd0 (core, ".ar*"); break; case 's': // "aess" if (input[2] == 'u') { // "aessu" if (input[3] == 'e') { until_expr = input + 3; } else { - until_addr = r_num_math (core->num, input + 2); + until_addr = rz_num_math (core->num, input + 2); } - r_core_esil_step (core, until_addr, until_expr, NULL, true); + rz_core_esil_step (core, until_addr, until_expr, NULL, true); } else { - r_core_esil_step (core, UT64_MAX, NULL, NULL, true); + rz_core_esil_step (core, UT64_MAX, NULL, NULL, true); } - r_core_cmd0 (core, ".ar*"); + rz_core_cmd0 (core, ".ar*"); break; case 'o': // "aeso" if (input[2] == 'u') { // "aesou" if (input[3] == 'e') { until_expr = input + 3; } else { - until_addr = r_num_math (core->num, input + 2); + until_addr = rz_num_math (core->num, input + 2); } - r_core_esil_step (core, until_addr, until_expr, NULL, true); - r_core_cmd0 (core, ".ar*"); + rz_core_esil_step (core, until_addr, until_expr, NULL, true); + rz_core_cmd0 (core, ".ar*"); } else if (!input[2] || input[2] == ' ') { // "aeso [addr]" // step over - op = r_core_anal_op (core, r_reg_getv (core->anal->reg, - r_reg_get_name (core->anal->reg, R_REG_NAME_PC)), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); + op = rz_core_anal_op (core, rz_reg_getv (core->anal->reg, + rz_reg_get_name (core->anal->reg, R_REG_NAME_PC)), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); if (op && op->type == R_ANAL_OP_TYPE_CALL) { until_addr = op->addr + op->size; } - r_core_esil_step (core, until_addr, until_expr, NULL, false); - r_anal_op_free (op); - r_core_cmd0 (core, ".ar*"); + rz_core_esil_step (core, until_addr, until_expr, NULL, false); + rz_anal_op_free (op); + rz_core_cmd0 (core, ".ar*"); } else { eprintf ("Usage: aesou [addr] # step over until given address\n"); } @@ -6254,44 +6254,44 @@ static void cmd_anal_esil(RCore *core, const char *input) { eprintf ("aesp [offset] [num]\n"); break; } - adr = r_num_math (core->num, n + 1); - off = r_num_math (core->num, n1 + 1); + adr = rz_num_math (core->num, n + 1); + off = rz_num_math (core->num, n1 + 1); cmd_aespc (core, adr, -1, off); break; case ' ': n = strchr (input, ' '); if (!(n + 1)) { - r_core_esil_step (core, until_addr, until_expr, NULL, false); + rz_core_esil_step (core, until_addr, until_expr, NULL, false); break; } - off = r_num_math (core->num, n + 1); + off = rz_num_math (core->num, n + 1); cmd_aespc (core, -1, -1, off); break; default: - r_core_esil_step (core, until_addr, until_expr, NULL, false); - r_core_cmd0 (core, ".ar*"); + rz_core_esil_step (core, until_addr, until_expr, NULL, false); + rz_core_cmd0 (core, ".ar*"); break; } break; case 'C': // "aeC" if (input[1] == '?') { // "aec?" - r_core_cmd_help (core, help_msg_aeC); + rz_core_cmd_help (core, help_msg_aeC); } else { - __core_anal_appcall (core, r_str_trim_head_ro (input + 1)); + __core_anal_appcall (core, rz_str_trim_head_ro (input + 1)); } break; case 'c': // "aec" if (input[1] == '?') { // "aec?" - r_core_cmd_help (core, help_msg_aec); + rz_core_cmd_help (core, help_msg_aec); } else if (input[1] == 's') { // "aecs" - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); for (;;) { - if (!r_core_esil_step (core, UT64_MAX, NULL, NULL, false)) { + if (!rz_core_esil_step (core, UT64_MAX, NULL, NULL, false)) { break; } - r_core_cmd0 (core, ".ar*"); - addr = r_num_get (core->num, pc); - op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); + rz_core_cmd0 (core, ".ar*"); + addr = rz_num_get (core->num, pc); + op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT); if (!op) { break; } @@ -6302,25 +6302,25 @@ static void cmd_anal_esil(RCore *core, const char *input) { eprintf ("trap at 0x%08" PFMT64x "\n", addr); break; } - r_anal_op_free (op); + rz_anal_op_free (op); op = NULL; if (core->anal->esil->trap || core->anal->esil->trap_code) { break; } } if (op) { - r_anal_op_free (op); + rz_anal_op_free (op); op = NULL; } } else if (input[1] == 'c') { // "aecc" - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); for (;;) { - if (!r_core_esil_step (core, UT64_MAX, NULL, NULL, false)) { + if (!rz_core_esil_step (core, UT64_MAX, NULL, NULL, false)) { break; } - r_core_cmd0 (core, ".ar*"); - addr = r_num_get (core->num, pc); - op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC); + rz_core_cmd0 (core, ".ar*"); + addr = rz_num_get (core->num, pc); + op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC); if (!op) { break; } @@ -6328,14 +6328,14 @@ static void cmd_anal_esil(RCore *core, const char *input) { eprintf ("call at 0x%08" PFMT64x "\n", addr); break; } - r_anal_op_free (op); + rz_anal_op_free (op); op = NULL; if (core->anal->esil->trap || core->anal->esil->trap_code) { break; } } if (op) { - r_anal_op_free (op); + rz_anal_op_free (op); } } else { // "aec" -> continue until ^C @@ -6344,12 +6344,12 @@ static void cmd_anal_esil(RCore *core, const char *input) { if (input[1] == 'u' && input[2] == 'e') { until_expr = input + 3; } else if (input[1] == 'u') { - until_addr = r_num_math (core->num, input + 2); + until_addr = rz_num_math (core->num, input + 2); } else { until_expr = "0"; } - r_core_esil_step (core, until_addr, until_expr, NULL, false); - r_core_cmd0 (core, ".ar*"); + rz_core_esil_step (core, until_addr, until_expr, NULL, false); + rz_core_cmd0 (core, ".ar*"); } break; case 'i': // "aei" @@ -6359,7 +6359,7 @@ static void cmd_anal_esil(RCore *core, const char *input) { cmd_esil_mem (core, input + 2); break; case 'p': // "aeip" // initialize pc = $$ - r_core_cmd0 (core, "ar PC=$$"); + rz_core_cmd0 (core, "ar PC=$$"); break; case '?': cmd_esil_mem (core, "?"); @@ -6368,30 +6368,30 @@ static void cmd_anal_esil(RCore *core, const char *input) { if (esil) { sdb_reset (esil->stats); } - r_anal_esil_free (esil); + rz_anal_esil_free (esil); core->anal->esil = NULL; break; case 0: //lolololol - r_anal_esil_free (esil); + rz_anal_esil_free (esil); // reinitialize { - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - if (pc && r_reg_getv (core->anal->reg, pc) == 0LL) { - r_core_cmd0 (core, "ar PC=$$"); + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + if (pc && rz_reg_getv (core->anal->reg, pc) == 0LL) { + rz_core_cmd0 (core, "ar PC=$$"); } } - if (!(esil = core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + if (!(esil = core->anal->esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } - r_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io - esil->verbose = (int)r_config_get_i (core->config, "esil.verbose"); + rz_anal_esil_setup (esil, core->anal, romem, stats, noNULL); // setup io + esil->verbose = (int)rz_config_get_i (core->config, "esil.verbose"); /* restore user settings for interrupt handling */ { - const char *s = r_config_get (core->config, "cmd.esil.intr"); + const char *s = rz_config_get (core->config, "cmd.esil.intr"); if (s) { char *my = strdup (s); if (my) { - r_config_set (core->config, "cmd.esil.intr", my); + rz_config_set (core->config, "cmd.esil.intr", my); free (my); } } @@ -6408,7 +6408,7 @@ static void cmd_anal_esil(RCore *core, const char *input) { if (esil && esil->stats) { char *out = sdb_querys (esil->stats, NULL, 0, input + 2); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else { @@ -6427,7 +6427,7 @@ static void cmd_anal_esil(RCore *core, const char *input) { case 'i': // aeli interrupts switch (input[2]) { case ' ': // "aeli" with arguments - if (!r_anal_esil_load_interrupts_from_lib (esil, input + 3)) { + if (!rz_anal_esil_load_interrupts_from_lib (esil, input + 3)) { eprintf ("Failed to load interrupts from '%s'.", input + 3); } break; @@ -6438,8 +6438,8 @@ static void cmd_anal_esil(RCore *core, const char *input) { break; case 'r': // "aelir" if (esil && esil->interrupts) { - RAnalEsilInterrupt* interrupt = dict_getu (esil->interrupts, r_num_math (core->num, input + 3)); - r_anal_esil_interrupt_free (esil, interrupt); + RzAnalEsilInterrupt* interrupt = dict_getu (esil->interrupts, rz_num_math (core->num, input + 3)); + rz_anal_esil_interrupt_free (esil, interrupt); } break; } @@ -6447,37 +6447,37 @@ static void cmd_anal_esil(RCore *core, const char *input) { break; case 'g': // "aeg" if (input[1] == 'i' || input[1] == 'v') { - char *oprompt = strdup (r_config_get (core->config, "cmd.gprompt")); - r_config_set (core->config, "cmd.gprompt", "pi 1"); - r_core_cmd0 (core, ".aeg*;aggv"); - r_config_set (core->config, "cmd.gprompt", oprompt); + char *oprompt = strdup (rz_config_get (core->config, "cmd.gprompt")); + rz_config_set (core->config, "cmd.gprompt", "pi 1"); + rz_core_cmd0 (core, ".aeg*;aggv"); + rz_config_set (core->config, "cmd.gprompt", oprompt); free (oprompt); } else if (!input[1]) { - r_core_cmd0 (core, ".aeg*;agg"); + rz_core_cmd0 (core, ".aeg*;agg"); } else if (input[1] == ' ') { - r_core_anal_esil_graph (core, input + 2); + rz_core_anal_esil_graph (core, input + 2); } else if (input[1] == '*') { - RAnalOp *aop = r_core_anal_op (core, core->offset, R_ANAL_OP_MASK_ESIL); + RzAnalOp *aop = rz_core_anal_op (core, core->offset, R_ANAL_OP_MASK_ESIL); if (aop) { - const char *esilstr = r_strbuf_get (&aop->esil); + const char *esilstr = rz_strbuf_get (&aop->esil); if (R_STR_ISNOTEMPTY (esilstr)) { - r_core_anal_esil_graph (core, esilstr); + rz_core_anal_esil_graph (core, esilstr); } } } else { - r_cons_printf ("Usage: aeg[iv*]\n"); - r_cons_printf (" aeg analyze current instruction as an esil graph\n"); - r_cons_printf (" aeg* analyze current instruction as an esil graph\n"); - r_cons_printf (" aegv and launch the visual interactive mode (.aeg*;aggv == aegv)\n"); + rz_cons_printf ("Usage: aeg[iv*]\n"); + rz_cons_printf (" aeg analyze current instruction as an esil graph\n"); + rz_cons_printf (" aeg* analyze current instruction as an esil graph\n"); + rz_cons_printf (" aegv and launch the visual interactive mode (.aeg*;aggv == aegv)\n"); } break; case 'b': // "aeb" // ab~ninstr[1] - r_core_cmdf (core, "aesp `ab~addr[1]` `ab~ninstr[1]`"); + rz_core_cmdf (core, "aesp `ab~addr[1]` `ab~ninstr[1]`"); break; case 'f': // "aef" if (input[1] == 'a') { // "aefa" - r_anal_aefa (core, r_str_trim_head_ro (input + 2)); + rz_anal_aefa (core, rz_str_trim_head_ro (input + 2)); } else { // This should be aefb -> because its emulating all the bbs // anal ESIL to REIL. __anal_esil_function (core, core->offset); @@ -6487,15 +6487,15 @@ static void cmd_anal_esil(RCore *core, const char *input) { case 'r': // "aetr" { // anal ESIL to REIL. - RAnalEsil *esil = r_anal_esil_new (stacksize, iotrap, addrsize); + RzAnalEsil *esil = rz_anal_esil_new (stacksize, iotrap, addrsize); if (!esil) { return; } - r_anal_esil_to_reil_setup (esil, core->anal, romem, stats); - r_anal_esil_set_pc (esil, core->offset); - r_anal_esil_parse (esil, input + 2); - r_anal_esil_dumpstack (esil); - r_anal_esil_free (esil); + rz_anal_esil_to_reil_setup (esil, core->anal, romem, stats); + rz_anal_esil_set_pc (esil, core->offset); + rz_anal_esil_parse (esil, input + 2); + rz_anal_esil_dumpstack (esil); + rz_anal_esil_free (esil); break; } case 's': // "aets" @@ -6509,11 +6509,11 @@ static void cmd_anal_esil(RCore *core, const char *input) { eprintf ("ESIL trace already started\n"); break; } - esil->trace = r_anal_esil_trace_new (esil); + esil->trace = rz_anal_esil_trace_new (esil); if (!esil->trace) { break; } - r_config_set_i (core->config, "dbg.trace", true); + rz_config_set_i (core->config, "dbg.trace", true); break; case '-': // "aets-" if (!esil) { @@ -6524,12 +6524,12 @@ static void cmd_anal_esil(RCore *core, const char *input) { eprintf ("No ESIL trace started\n"); break; } - r_anal_esil_trace_free (esil->trace); + rz_anal_esil_trace_free (esil->trace); esil->trace = NULL; - r_config_set_i (core->config, "dbg.trace", false); + rz_config_set_i (core->config, "dbg.trace", false); break; default: - r_core_cmd_help (core, help_msg_aets); + rz_core_cmd_help (core, help_msg_aets); break; } break; @@ -6540,76 +6540,76 @@ static void cmd_anal_esil(RCore *core, const char *input) { break; case 'A': // "aeA" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_aea); + rz_core_cmd_help (core, help_msg_aea); } else if (input[1] == 'r') { - cmd_aea (core, 1 + (1<<1), core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1 + (1<<1), core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'w') { - cmd_aea (core, 1 + (1<<2), core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1 + (1<<2), core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'n') { - cmd_aea (core, 1 + (1<<3), core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1 + (1<<3), core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'j') { - cmd_aea (core, 1 + (1<<4), core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1 + (1<<4), core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == '*') { - cmd_aea (core, 1 + (1<<5), core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1 + (1<<5), core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'f') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (fcn) { - cmd_aea (core, 1, r_anal_function_min_addr (fcn), r_anal_function_linear_size (fcn)); + cmd_aea (core, 1, rz_anal_function_min_addr (fcn), rz_anal_function_linear_size (fcn)); } } else { - cmd_aea (core, 1, core->offset, (int)r_num_math (core->num, input+2)); + cmd_aea (core, 1, core->offset, (int)rz_num_math (core->num, input+2)); } break; case 'a': // "aea" { - RReg *reg = core->anal->reg; - ut64 pc = r_reg_getv (reg, "PC"); - RAnalOp *op = r_core_anal_op (core, pc, 0); + RzReg *reg = core->anal->reg; + ut64 pc = rz_reg_getv (reg, "PC"); + RzAnalOp *op = rz_core_anal_op (core, pc, 0); if (!op) { break; } ut64 newPC = core->offset + op->size; - r_reg_setv (reg, "PC", newPC); + rz_reg_setv (reg, "PC", newPC); if (input[1] == '?') { - r_core_cmd_help (core, help_msg_aea); + rz_core_cmd_help (core, help_msg_aea); } else if (input[1] == 'r') { - cmd_aea (core, 1<<1, core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1<<1, core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'w') { - cmd_aea (core, 1<<2, core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1<<2, core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'n') { - cmd_aea (core, 1<<3, core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1<<3, core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'j') { - cmd_aea (core, 1<<4, core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1<<4, core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == '*') { - cmd_aea (core, 1<<5, core->offset, r_num_math (core->num, input+2)); + cmd_aea (core, 1<<5, core->offset, rz_num_math (core->num, input+2)); } else if (input[1] == 'b') { // "aeab" bool json = input[2] == 'j'; int a = json? 3: 2; - ut64 addr = (input[a] == ' ')? r_num_math (core->num, input + a): core->offset; - RList *l = r_anal_get_blocks_in (core->anal, addr); - RAnalBlock *b; - RListIter *iter; - r_list_foreach (l, iter, b) { + ut64 addr = (input[a] == ' ')? rz_num_math (core->num, input + a): core->offset; + RzList *l = rz_anal_get_blocks_in (core->anal, addr); + RzAnalBlock *b; + RzListIter *iter; + rz_list_foreach (l, iter, b) { int mode = json? (1<<4): 1; cmd_aea (core, mode, b->addr, b->size); break; } } else if (input[1] == 'f') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); // "aeafj" if (fcn) { switch (input[2]) { case 'j': // "aeafj" - cmd_aea (core, 1<<4, r_anal_function_min_addr (fcn), r_anal_function_linear_size (fcn)); + cmd_aea (core, 1<<4, rz_anal_function_min_addr (fcn), rz_anal_function_linear_size (fcn)); break; default: - cmd_aea (core, 1, r_anal_function_min_addr (fcn), r_anal_function_linear_size (fcn)); + cmd_aea (core, 1, rz_anal_function_min_addr (fcn), rz_anal_function_linear_size (fcn)); break; } break; } } else if (input[1] == 'b') { // "aeab" - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, core->offset); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, core->offset); if (bb) { switch (input[2]) { case 'j': // "aeabj" @@ -6622,66 +6622,66 @@ static void cmd_anal_esil(RCore *core, const char *input) { } } else { const char *arg = input[1]? input + 2: ""; - ut64 len = r_num_math (core->num, arg); + ut64 len = rz_num_math (core->num, arg); cmd_aea (core, 0, core->offset, len); } - r_reg_setv (reg, "PC", pc); + rz_reg_setv (reg, "PC", pc); } break; case 'x': { // "aex" char *hex; int ret, bufsz; - input = r_str_trim_head_ro (input + 1); + input = rz_str_trim_head_ro (input + 1); hex = strdup (input); if (!hex) { break; } - RAnalOp aop = R_EMPTY; - bufsz = r_hex_str2bin (hex, (ut8*)hex); - ret = r_anal_op (core->anal, &aop, core->offset, + RzAnalOp aop = R_EMPTY; + bufsz = rz_hex_str2bin (hex, (ut8*)hex); + ret = rz_anal_op (core->anal, &aop, core->offset, (const ut8*)hex, bufsz, R_ANAL_OP_MASK_ESIL); if (ret>0) { const char *str = R_STRBUF_SAFEGET (&aop.esil); - char *str2 = r_str_newf (" %s", str); + char *str2 = rz_str_newf (" %s", str); cmd_anal_esil (core, str2); free (str2); } - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); break; } case '?': // "ae?" if (input[1] == '?') { - r_core_cmd_help (core, help_detail_ae); + rz_core_cmd_help (core, help_detail_ae); break; } /* fallthrough */ default: - r_core_cmd_help (core, help_msg_ae); + rz_core_cmd_help (core, help_msg_ae); break; } } -static void cmd_anal_bytes(RCore *core, const char *input) { +static void cmd_anal_bytes(RzCore *core, const char *input) { int len = core->blocksize; int tbs = len; if (input[0]) { - len = (int)r_num_get (core->num, input + 1); + len = (int)rz_num_get (core->num, input + 1); if (len > tbs) { - r_core_block_size (core, len); + rz_core_block_size (core, len); } } core_anal_bytes (core, core->block, len, 0, input[0]); if (tbs != core->blocksize) { - r_core_block_size (core, tbs); + rz_core_block_size (core, tbs); } } -static void cmd_anal_opcode(RCore *core, const char *input) { +static void cmd_anal_opcode(RzCore *core, const char *input) { int l, len = core->blocksize; ut32 tbs = core->blocksize; - r_core_block_read (core); + rz_core_block_read (core); switch (input[0]) { case 's': // "aos" case 'j': // "aoj" @@ -6690,43 +6690,43 @@ static void cmd_anal_opcode(RCore *core, const char *input) { int count = 1; int obs = core->blocksize; if (input[1] && input[2]) { - l = (int)r_num_get (core->num, input + 1); + l = (int)rz_num_get (core->num, input + 1); if (l > 0) { count = l; } l *= 8; if (l > obs) { - r_core_block_size (core, l); + rz_core_block_size (core, l); } } else { count = 1; } core_anal_bytes (core, core->block, core->blocksize, count, input[0]); if (obs != core->blocksize) { - r_core_block_size (core, obs); + rz_core_block_size (core, obs); } } break; case 'm': // "aom" if (input[1] == '?') { - r_cons_printf ("Usage: aom[ljd] [arg] .. list mnemonics for asm.arch\n"); - r_cons_printf (". = current, l = list, d = describe, j=json)\n"); + rz_cons_printf ("Usage: aom[ljd] [arg] .. list mnemonics for asm.arch\n"); + rz_cons_printf (". = current, l = list, d = describe, j=json)\n"); } else if (input[1] == 'd') { const int id = (input[2]==' ') - ?(int)r_num_math (core->num, input + 2): -1; - char *ops = r_asm_mnemonics (core->rasm, id, false); + ?(int)rz_num_math (core->num, input + 2): -1; + char *ops = rz_asm_mnemonics (core->rasm, id, false); if (ops) { char *ptr = ops; char *nl = strchr (ptr, '\n'); while (nl) { *nl = 0; - char *desc = r_asm_describe (core->rasm, ptr); + char *desc = rz_asm_describe (core->rasm, ptr); if (desc) { - const char *pad = r_str_pad (' ', 16 - strlen (ptr)); - r_cons_printf ("%s%s%s\n", ptr, pad, desc); + const char *pad = rz_str_pad (' ', 16 - strlen (ptr)); + rz_cons_printf ("%s%s%s\n", ptr, pad, desc); free (desc); } else { - r_cons_printf ("%s\n", ptr); + rz_cons_printf ("%s\n", ptr); } ptr = nl + 1; nl = strchr (ptr, '\n'); @@ -6735,51 +6735,51 @@ static void cmd_anal_opcode(RCore *core, const char *input) { } } else if (input[1] == 'l' || input[1] == '=' || input[1] == ' ' || input[1] == 'j') { if (input[1] == ' ' && !IS_DIGIT (input[2])) { - r_cons_printf ("%d\n", r_asm_mnemonics_byname (core->rasm, input + 2)); + rz_cons_printf ("%d\n", rz_asm_mnemonics_byname (core->rasm, input + 2)); } else { const int id = (input[1] == ' ') - ?(int)r_num_math (core->num, input + 2): -1; - char *ops = r_asm_mnemonics (core->rasm, id, input[1] == 'j'); + ?(int)rz_num_math (core->num, input + 2): -1; + char *ops = rz_asm_mnemonics (core->rasm, id, input[1] == 'j'); if (ops) { - r_cons_println (ops); + rz_cons_println (ops); free (ops); } } } else { - r_core_cmd0 (core, "ao~mnemonic[1]"); + rz_core_cmd0 (core, "ao~mnemonic[1]"); } break; case 'c': // "aoc" { - RList *hooks; - RListIter *iter; - RAnalCycleHook *hook; + RzList *hooks; + RzListIter *iter; + RzAnalCycleHook *hook; char *instr_tmp = NULL; - int ccl = input[1]? r_num_math (core->num, &input[2]): 0; //get cycles to look for - int cr = r_config_get_i (core->config, "asm.cmt.right"); - int fun = r_config_get_i (core->config, "asm.functions"); - int li = r_config_get_i (core->config, "asm.lines"); - int xr = r_config_get_i (core->config, "asm.xrefs"); + int ccl = input[1]? rz_num_math (core->num, &input[2]): 0; //get cycles to look for + int cr = rz_config_get_i (core->config, "asm.cmt.right"); + int fun = rz_config_get_i (core->config, "asm.functions"); + int li = rz_config_get_i (core->config, "asm.lines"); + int xr = rz_config_get_i (core->config, "asm.xrefs"); - r_config_set_i (core->config, "asm.cmt.right", true); - r_config_set_i (core->config, "asm.functions", false); - r_config_set_i (core->config, "asm.lines", false); - r_config_set_i (core->config, "asm.xrefs", false); + rz_config_set_i (core->config, "asm.cmt.right", true); + rz_config_set_i (core->config, "asm.functions", false); + rz_config_set_i (core->config, "asm.lines", false); + rz_config_set_i (core->config, "asm.xrefs", false); - hooks = r_core_anal_cycles (core, ccl); //analyse - r_cons_clear_line (1); - r_list_foreach (hooks, iter, hook) { - instr_tmp = r_core_disassemble_instr (core, hook->addr, 1); - r_cons_printf ("After %4i cycles:\t%s", (ccl - hook->cycles), instr_tmp); - r_cons_flush (); + hooks = rz_core_anal_cycles (core, ccl); //analyse + rz_cons_clear_line (1); + rz_list_foreach (hooks, iter, hook) { + instr_tmp = rz_core_disassemble_instr (core, hook->addr, 1); + rz_cons_printf ("After %4i cycles:\t%s", (ccl - hook->cycles), instr_tmp); + rz_cons_flush (); free (instr_tmp); } - r_list_free (hooks); + rz_list_free (hooks); - r_config_set_i (core->config, "asm.cmt.right", cr); //reset settings - r_config_set_i (core->config, "asm.functions", fun); - r_config_set_i (core->config, "asm.lines", li); - r_config_set_i (core->config, "asm.xrefs", xr); + rz_config_set_i (core->config, "asm.cmt.right", cr); //reset settings + rz_config_set_i (core->config, "asm.functions", fun); + rz_config_set_i (core->config, "asm.lines", li); + rz_config_set_i (core->config, "asm.xrefs", xr); } break; case 'd': // "aod" @@ -6791,9 +6791,9 @@ static void cmd_anal_opcode(RCore *core, const char *input) { // XXX: we need cmd_xxx.h (cmd_anal.h) core_anal_bytes (core, core->block + cur, core->blocksize, 1, 'd'); } else if (input[1] == ' ') { - char *d = r_asm_describe (core->rasm, input + 2); + char *d = rz_asm_describe (core->rasm, input + 2); if (d && *d) { - r_cons_println (d); + rz_cons_println (d); free (d); } else { eprintf ("Unknown mnemonic\n"); @@ -6803,18 +6803,18 @@ static void cmd_anal_opcode(RCore *core, const char *input) { } break; case '*': - r_core_anal_hint_list (core->anal, input[0]); + rz_core_anal_hint_list (core->anal, input[0]); break; case 0: case ' ': { int count = 0; if (input[0]) { - l = (int)r_num_get (core->num, input + 1); + l = (int)rz_num_get (core->num, input + 1); if (l > 0) { count = l; } if (l > tbs) { - r_core_block_size (core, l * 4); + rz_core_block_size (core, l * 4); //len = l; } } else { @@ -6826,17 +6826,17 @@ static void cmd_anal_opcode(RCore *core, const char *input) { break; case 'f': { - RAnalOp aop = R_EMPTY; + RzAnalOp aop = R_EMPTY; ut8 data[32]; - r_io_read_at (core->io, core->offset, data, sizeof (data)); - int ret = r_anal_op (core->anal, &aop, core->offset, data, sizeof (data), R_ANAL_OP_MASK_ESIL); + rz_io_read_at (core->io, core->offset, data, sizeof (data)); + int ret = rz_anal_op (core->anal, &aop, core->offset, data, sizeof (data), R_ANAL_OP_MASK_ESIL); if (ret > 0) { const char *arg = input + 2; const char *expr = R_STRBUF_SAFEGET (&aop.esil); - RStrBuf *b = r_anal_esil_dfg_filter_expr (core->anal, expr, arg); + RStrBuf *b = rz_anal_esil_dfg_filter_expr (core->anal, expr, arg); if (b) { - char *s = r_strbuf_drain (b); - r_cons_printf ("%s\n", s); + char *s = rz_strbuf_drain (b); + rz_cons_printf ("%s\n", s); free (s); } } else { @@ -6846,34 +6846,34 @@ static void cmd_anal_opcode(RCore *core, const char *input) { break; default: case '?': - r_core_cmd_help (core, help_msg_ao); + rz_core_cmd_help (core, help_msg_ao); break; } } -static void cmd_anal_jumps(RCore *core, const char *input) { - r_core_cmdf (core, "af @@= `ax~ref.code.jmp[1]`"); +static void cmd_anal_jumps(RzCore *core, const char *input) { + rz_core_cmdf (core, "af @@= `ax~ref.code.jmp[1]`"); } // TODO: cleanup to reuse code -static void cmd_anal_aftertraps(RCore *core, const char *input) { +static void cmd_anal_aftertraps(RzCore *core, const char *input) { int bufi, minop = 1; // 4 ut8 *buf; - RAnalOp op = {0}; + RzAnalOp op = {0}; ut64 addr, addr_end; - ut64 len = r_num_math (core->num, input); + ut64 len = rz_num_math (core->num, input); if (len > 0xffffff) { eprintf ("Too big\n"); return; } - RBinFile *bf = r_bin_cur (core->bin); + RBinFile *bf = rz_bin_cur (core->bin); if (!bf) { return; } addr = core->offset; if (!len) { // ignore search.in to avoid problems. analysis != search - RIOMap *map = r_io_map_get (core->io, addr); + RzIOMap *map = rz_io_map_get (core->io, addr); if (map && (map->perm & R_PERM_X)) { // search in current section if (map->itv.size > bf->size) { @@ -6908,9 +6908,9 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) { bufi = 0; int trapcount = 0; int nopcount = 0; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); while (addr < addr_end) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } // TODO: too many ioreads here @@ -6918,9 +6918,9 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) { bufi = 0; } if (!bufi) { - r_io_read_at (core->io, addr, buf, 4096); + rz_io_read_at (core->io, addr, buf, 4096); } - if (r_anal_op (core->anal, &op, addr, buf + bufi, 4096 - bufi, R_ANAL_OP_MASK_BASIC)) { + if (rz_anal_op (core->anal, &op, addr, buf + bufi, 4096 - bufi, R_ANAL_OP_MASK_BASIC)) { if (op.size < 1) { // XXX must be +4 on arm/mips/.. like we do in disasm.c op.size = minop; @@ -6931,11 +6931,11 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) { nopcount ++; } else { if (nopcount > 1) { - r_cons_printf ("af @ 0x%08"PFMT64x"\n", addr); + rz_cons_printf ("af @ 0x%08"PFMT64x"\n", addr); nopcount = 0; } if (trapcount > 0) { - r_cons_printf ("af @ 0x%08"PFMT64x"\n", addr); + rz_cons_printf ("af @ 0x%08"PFMT64x"\n", addr); trapcount = 0; } } @@ -6944,27 +6944,27 @@ static void cmd_anal_aftertraps(RCore *core, const char *input) { } addr += (op.size > 0)? op.size : 1; bufi += (op.size > 0)? op.size : 1; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); } -static void cmd_anal_blocks(RCore *core, const char *input) { +static void cmd_anal_blocks(RzCore *core, const char *input) { ut64 from , to; char *arg = strchr (input, ' '); - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); if (!arg) { - RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); - RListIter *iter; - RIOMap* map; + RzList *list = rz_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); + RzListIter *iter; + RzIOMap* map; if (!list) { goto ctrl_c; } - r_list_foreach (list, iter, map) { + rz_list_foreach (list, iter, map) { from = map->itv.addr; - to = r_itv_end (map->itv); - if (r_cons_is_breaked ()) { + to = rz_itv_end (map->itv); + if (rz_cons_is_breaked ()) { goto ctrl_c; } if (!from && !to) { @@ -6972,24 +6972,24 @@ static void cmd_anal_blocks(RCore *core, const char *input) { } else if (to - from > UT32_MAX) { eprintf ("Skipping huge range\n"); } else { - r_core_cmdf (core, "abb 0x%08"PFMT64x" @ 0x%08"PFMT64x, (to - from), from); + rz_core_cmdf (core, "abb 0x%08"PFMT64x" @ 0x%08"PFMT64x, (to - from), from); } } } else { - st64 sz = r_num_math (core->num, arg + 1); + st64 sz = rz_num_math (core->num, arg + 1); if (sz < 1) { eprintf ("Invalid range\n"); return; } - r_core_cmdf (core, "abb 0x%08"PFMT64x" @ 0x%08"PFMT64x, sz, core->offset); + rz_core_cmdf (core, "abb 0x%08"PFMT64x" @ 0x%08"PFMT64x, sz, core->offset); } ctrl_c: - r_cons_break_pop (); + rz_cons_break_pop (); } -static void _anal_calls(RCore *core, ut64 addr, ut64 addr_end, bool printCommands, bool importsOnly) { - RAnalOp op; - int depth = r_config_get_i (core->config, "anal.depth"); +static void _anal_calls(RzCore *core, ut64 addr, ut64 addr_end, bool printCommands, bool importsOnly) { + RzAnalOp op; + int depth = rz_config_get_i (core->config, "anal.depth"); const int addrbytes = core->io->addrbytes; const int bsz = 4096; int bufi = 0; @@ -7008,71 +7008,71 @@ static void _anal_calls(RCore *core, ut64 addr, ut64 addr_end, bool printCommand return; } memset (block1, -1, bsz); - int minop = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + int minop = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); if (minop < 1) { minop = 1; } - int setBits = r_config_get_i (core->config, "asm.bits"); - r_cons_break_push (NULL, NULL); - while (addr < addr_end && !r_cons_is_breaked ()) { + int setBits = rz_config_get_i (core->config, "asm.bits"); + rz_cons_break_push (NULL, NULL); + while (addr < addr_end && !rz_cons_is_breaked ()) { // TODO: too many ioreads here if (bufi > bufi_max) { bufi = 0; } if (!bufi) { - (void)r_io_read_at (core->io, addr, buf, bsz); + (void)rz_io_read_at (core->io, addr, buf, bsz); } if (!memcmp (buf, block0, bsz) || !memcmp (buf, block1, bsz)) { //eprintf ("Error: skipping uninitialized block \n"); addr += bsz; continue; } - RAnalHint *hint = r_anal_hint_get (core->anal, addr); + RzAnalHint *hint = rz_anal_hint_get (core->anal, addr); if (hint && hint->bits) { setBits = hint->bits; } - r_anal_hint_free (hint); + rz_anal_hint_free (hint); if (setBits != core->rasm->bits) { - r_config_set_i (core->config, "asm.bits", setBits); + rz_config_set_i (core->config, "asm.bits", setBits); } - if (r_anal_op (core->anal, &op, addr, buf + bufi, bsz - bufi, 0) > 0) { + if (rz_anal_op (core->anal, &op, addr, buf + bufi, bsz - bufi, 0) > 0) { if (op.size < 1) { op.size = minop; } if (op.type == R_ANAL_OP_TYPE_CALL) { bool isValidCall = true; if (importsOnly) { - RFlagItem *f = r_flag_get_i (core->flags, op.jump); + RzFlagItem *f = rz_flag_get_i (core->flags, op.jump); if (!f || !strstr (f->name, "imp.")) { isValidCall = false; } } - RBinReloc *rel = r_core_getreloc (core, addr, op.size); + RBinReloc *rel = rz_core_getreloc (core, addr, op.size); if (rel && (rel->import || rel->symbol)) { isValidCall = false; } if (isValidCall) { ut8 buf[4]; - r_io_read_at (core->io, op.jump, buf, 4); + rz_io_read_at (core->io, op.jump, buf, 4); isValidCall = memcmp (buf, "\x00\x00\x00\x00", 4); } if (isValidCall) { #if JAYRO_03 if (!anal_is_bad_call (core, from, to, addr, buf, bufi)) { - fcn = r_anal_get_fcn_in (core->anal, op.jump, R_ANAL_FCN_TYPE_ROOT); + fcn = rz_anal_get_fcn_in (core->anal, op.jump, R_ANAL_FCN_TYPE_ROOT); if (!fcn) { - r_core_anal_fcn (core, op.jump, addr, R_ANAL_REF_TYPE_CALL, depth); + rz_core_anal_fcn (core, op.jump, addr, R_ANAL_REF_TYPE_CALL, depth); } } #else if (printCommands) { - r_cons_printf ("ax 0x%08" PFMT64x " 0x%08" PFMT64x "\n", op.jump, addr); - r_cons_printf ("af @ 0x%08" PFMT64x"\n", op.jump); + rz_cons_printf ("ax 0x%08" PFMT64x " 0x%08" PFMT64x "\n", op.jump, addr); + rz_cons_printf ("af @ 0x%08" PFMT64x"\n", op.jump); } else { // add xref here - r_anal_xrefs_set (core->anal, addr, op.jump, R_ANAL_REF_TYPE_CALL); - if (r_io_is_valid_offset (core->io, op.jump, 1)) { - r_core_anal_fcn (core, op.jump, addr, R_ANAL_REF_TYPE_CALL, depth); + rz_anal_xrefs_set (core->anal, addr, op.jump, R_ANAL_REF_TYPE_CALL); + if (rz_io_is_valid_offset (core->io, op.jump, 1)) { + rz_core_anal_fcn (core, op.jump, addr, R_ANAL_REF_TYPE_CALL, depth); } } #endif @@ -7086,64 +7086,64 @@ static void _anal_calls(RCore *core, ut64 addr, ut64 addr_end, bool printCommand } addr += op.size; bufi += addrbytes * op.size; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); free (block0); free (block1); } -static void cmd_anal_calls(RCore *core, const char *input, bool printCommands, bool importsOnly) { - RList *ranges = NULL; - RIOMap *r; +static void cmd_anal_calls(RzCore *core, const char *input, bool printCommands, bool importsOnly) { + RzList *ranges = NULL; + RzIOMap *r; ut64 addr; - ut64 len = r_num_math (core->num, input); + ut64 len = rz_num_math (core->num, input); if (len > 0xffffff) { eprintf ("Too big\n"); return; } - RBinFile *binfile = r_bin_cur (core->bin); + RBinFile *binfile = rz_bin_cur (core->bin); addr = core->offset; if (binfile) { if (len) { - RIOMap *m = R_NEW0 (RIOMap); + RzIOMap *m = R_NEW0 (RzIOMap); m->itv.addr = addr; m->itv.size = len; - ranges = r_list_newf ((RListFree)free); - r_list_append (ranges, m); + ranges = rz_list_newf ((RzListFree)free); + rz_list_append (ranges, m); } else { - ranges = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); + ranges = rz_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); } } - r_cons_break_push (NULL, NULL); - if (!binfile || (ranges && !r_list_length (ranges))) { - RListIter *iter; - RIOMap *map; - r_list_free (ranges); - ranges = r_core_get_boundaries_prot (core, 0, NULL, "anal"); + rz_cons_break_push (NULL, NULL); + if (!binfile || (ranges && !rz_list_length (ranges))) { + RzListIter *iter; + RzIOMap *map; + rz_list_free (ranges); + ranges = rz_core_get_boundaries_prot (core, 0, NULL, "anal"); if (ranges) { - r_list_foreach (ranges, iter, map) { + rz_list_foreach (ranges, iter, map) { ut64 addr = map->itv.addr; - _anal_calls (core, addr, r_itv_end (map->itv), printCommands, importsOnly); + _anal_calls (core, addr, rz_itv_end (map->itv), printCommands, importsOnly); } } } else { - RListIter *iter; + RzListIter *iter; if (binfile) { - r_list_foreach (ranges, iter, r) { + rz_list_foreach (ranges, iter, r) { addr = r->itv.addr; //this normally will happen on fuzzed binaries, dunno if with huge //binaries as well - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - _anal_calls (core, addr, r_itv_end (r->itv), printCommands, importsOnly); + _anal_calls (core, addr, rz_itv_end (r->itv), printCommands, importsOnly); } } } - r_cons_break_pop (); - r_list_free (ranges); + rz_cons_break_pop (); + rz_list_free (ranges); } static void cmd_sdbk(Sdb *db, const char *input) { @@ -7151,18 +7151,18 @@ static void cmd_sdbk(Sdb *db, const char *input) { ? sdb_querys (db, NULL, 0, input + 1) : sdb_querys (db, NULL, 0, "*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } else { eprintf ("|ERROR| Usage: ask [query]\n"); } } -static void cmd_anal_syscall(RCore *core, const char *input) { +static void cmd_anal_syscall(RzCore *core, const char *input) { PJ *pj = NULL; - RSyscallItem *si; - RListIter *iter; - RList *list; + RzSyscallItem *si; + RzListIter *iter; + RzList *list; RNum *num = NULL; int n; @@ -7170,51 +7170,51 @@ static void cmd_anal_syscall(RCore *core, const char *input) { case 'c': // "asc" if (input[1] == 'a') { if (input[2] == ' ') { - if (!isalpha ((ut8)input[3]) && (n = r_num_math (num, input + 3)) >= 0 ) { - si = r_syscall_get (core->anal->syscall, n, -1); + if (!isalpha ((ut8)input[3]) && (n = rz_num_math (num, input + 3)) >= 0 ) { + si = rz_syscall_get (core->anal->syscall, n, -1); if (si) { - r_cons_printf (".equ SYS_%s %s\n", si->name, syscallNumber (n)); + rz_cons_printf (".equ SYS_%s %s\n", si->name, syscallNumber (n)); } else eprintf ("Unknown syscall number\n"); } else { - n = r_syscall_get_num (core->anal->syscall, input + 3); + n = rz_syscall_get_num (core->anal->syscall, input + 3); if (n != -1) { - r_cons_printf (".equ SYS_%s %s\n", input + 3, syscallNumber (n)); + rz_cons_printf (".equ SYS_%s %s\n", input + 3, syscallNumber (n)); } else { eprintf ("Unknown syscall name\n"); } } } else { - list = r_syscall_list (core->anal->syscall); - r_list_foreach (list, iter, si) { - r_cons_printf (".equ SYS_%s %s\n", + list = rz_syscall_list (core->anal->syscall); + rz_list_foreach (list, iter, si) { + rz_cons_printf (".equ SYS_%s %s\n", si->name, syscallNumber (si->num)); } - r_list_free (list); + rz_list_free (list); } } else { if (input[1] == ' ') { - if (!isalpha ((ut8)input[2]) && (n = r_num_math (num, input + 2)) >= 0 ) { - si = r_syscall_get (core->anal->syscall, n, -1); + if (!isalpha ((ut8)input[2]) && (n = rz_num_math (num, input + 2)) >= 0 ) { + si = rz_syscall_get (core->anal->syscall, n, -1); if (si) { - r_cons_printf ("#define SYS_%s %s\n", si->name, syscallNumber (n)); + rz_cons_printf ("#define SYS_%s %s\n", si->name, syscallNumber (n)); } else eprintf ("Unknown syscall number\n"); } else { - n = r_syscall_get_num (core->anal->syscall, input + 2); + n = rz_syscall_get_num (core->anal->syscall, input + 2); if (n != -1) { - r_cons_printf ("#define SYS_%s %s\n", input + 2, syscallNumber (n)); + rz_cons_printf ("#define SYS_%s %s\n", input + 2, syscallNumber (n)); } else { eprintf ("Unknown syscall name\n"); } } } else { - list = r_syscall_list (core->anal->syscall); - r_list_foreach (list, iter, si) { - r_cons_printf ("#define SYS_%s %d\n", + list = rz_syscall_list (core->anal->syscall); + rz_list_foreach (list, iter, si) { + rz_cons_printf ("#define SYS_%s %d\n", si->name, syscallNumber (si->num)); } - r_list_free (list); + rz_list_free (list); } } break; @@ -7223,33 +7223,33 @@ static void cmd_anal_syscall(RCore *core, const char *input) { break; case 'l': // "asl" if (input[1] == ' ') { - if (!isalpha ((ut8)input[2]) && (n = r_num_math (num, input + 2)) >= 0 ) { - si = r_syscall_get (core->anal->syscall, n, -1); + if (!isalpha ((ut8)input[2]) && (n = rz_num_math (num, input + 2)) >= 0 ) { + si = rz_syscall_get (core->anal->syscall, n, -1); if (si) - r_cons_println (si->name); + rz_cons_println (si->name); else eprintf ("Unknown syscall number\n"); } else { - n = r_syscall_get_num (core->anal->syscall, input + 2); + n = rz_syscall_get_num (core->anal->syscall, input + 2); if (n != -1) { - r_cons_printf ("%s\n", syscallNumber (n)); + rz_cons_printf ("%s\n", syscallNumber (n)); } else { eprintf ("Unknown syscall name\n"); } } } else { - list = r_syscall_list (core->anal->syscall); - r_list_foreach (list, iter, si) { - r_cons_printf ("%s = 0x%02x.%s\n", + list = rz_syscall_list (core->anal->syscall); + rz_list_foreach (list, iter, si) { + rz_cons_printf ("%s = 0x%02x.%s\n", si->name, si->swi, syscallNumber (si->num)); } - r_list_free (list); + rz_list_free (list); } break; case 'j': // "asj" pj = pj_new (); pj_a (pj); - list = r_syscall_list (core->anal->syscall); - r_list_foreach (list, iter, si) { + list = rz_syscall_list (core->anal->syscall); + rz_list_foreach (list, iter, si) { pj_o (pj); pj_ks (pj, "name", si->name); pj_ki (pj, "swi", si->swi); @@ -7258,7 +7258,7 @@ static void cmd_anal_syscall(RCore *core, const char *input) { } pj_end (pj); if (pj) { - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; @@ -7267,33 +7267,33 @@ static void cmd_anal_syscall(RCore *core, const char *input) { break; case ' ': { - const char *sn = r_str_trim_head_ro (input + 1); - st64 num = r_syscall_get_num (core->anal->syscall, sn); + const char *sn = rz_str_trim_head_ro (input + 1); + st64 num = rz_syscall_get_num (core->anal->syscall, sn); if (num < 1) { - num = (int)r_num_get (core->num, sn); + num = (int)rz_num_get (core->num, sn); } cmd_syscall_do (core, num, -1); } break; default: case '?': - r_core_cmd_help (core, help_msg_as); + rz_core_cmd_help (core, help_msg_as); break; } } -static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opts, PJ* pj) { +static void anal_axg(RzCore *core, const char *input, int level, Sdb *db, int opts, PJ* pj) { char arg[32], pre[128]; - RListIter *iter; - RAnalRef *ref; + RzListIter *iter; + RzAnalRef *ref; ut64 addr = core->offset; bool is_json = opts & R_CORE_ANAL_JSON; - bool is_r2 = opts & R_CORE_ANAL_GRAPHBODY; + bool is_rz = opts & R_CORE_ANAL_GRAPHBODY; if (is_json && !pj) { return; } if (input && *input) { - addr = r_num_math (core->num, input); + addr = rz_num_math (core->num, input); } // eprintf ("Path between 0x%08"PFMT64x" .. 0x%08"PFMT64x"\n", core->offset, addr); int spaces = (level + 1) * 2; @@ -7303,13 +7303,13 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt memset (pre, ' ', sizeof (pre)); strcpy (pre + spaces, "- "); - RList *xrefs = r_anal_xrefs_get (core->anal, addr); + RzList *xrefs = rz_anal_xrefs_get (core->anal, addr); bool open_object = false; - if (!r_list_empty (xrefs)) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, -1); + if (!rz_list_empty (xrefs)) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, -1); if (fcn) { - if (is_r2) { - r_cons_printf ("agn 0x%08"PFMT64x" %s\n", fcn->addr, fcn->name); + if (is_rz) { + rz_cons_printf ("agn 0x%08"PFMT64x" %s\n", fcn->addr, fcn->name); } else if (is_json) { char taddr[64]; pj_o (pj); @@ -7323,13 +7323,13 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt open_object = true; } else { //if (sdb_add (db, fcn->name, "1", 0)) { - r_cons_printf ("%s0x%08"PFMT64x" fcn 0x%08"PFMT64x" %s\n", + rz_cons_printf ("%s0x%08"PFMT64x" fcn 0x%08"PFMT64x" %s\n", pre + 2, addr, fcn->addr, fcn->name); //} } } else { - if (is_r2) { - r_cons_printf ("age 0x%08"PFMT64x"\n", addr); + if (is_rz) { + rz_cons_printf ("age 0x%08"PFMT64x"\n", addr); } else if (is_json) { char taddr[64]; pj_o (pj); @@ -7341,17 +7341,17 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt } else { //snprintf (arg, sizeof (arg), "0x%08"PFMT64x, addr); //if (sdb_add (db, arg, "1", 0)) { - r_cons_printf ("%s0x%08"PFMT64x"\n", pre+2, addr); + rz_cons_printf ("%s0x%08"PFMT64x"\n", pre+2, addr); //} } } } - r_list_foreach (xrefs, iter, ref) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, ref->addr, -1); + rz_list_foreach (xrefs, iter, ref) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, ref->addr, -1); if (fcn) { - if (is_r2) { - r_cons_printf ("agn 0x%08"PFMT64x" %s\n", fcn->addr, fcn->name); - r_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", fcn->addr, addr); + if (is_rz) { + rz_cons_printf ("agn 0x%08"PFMT64x" %s\n", fcn->addr, fcn->name); + rz_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", fcn->addr, addr); } else if (is_json) { if (level == 0) { char taddr[64]; @@ -7380,7 +7380,7 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt } } else { - r_cons_printf ("%s0x%08"PFMT64x" fcn 0x%08"PFMT64x" %s\n", pre, ref->addr, fcn->addr, fcn->name); + rz_cons_printf ("%s0x%08"PFMT64x" fcn 0x%08"PFMT64x" %s\n", pre, ref->addr, fcn->addr, fcn->name); } if (sdb_add (db, fcn->name, "1", 0)) { snprintf (arg, sizeof (arg), "0x%08"PFMT64x, fcn->addr); @@ -7394,9 +7394,9 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt } } } else { - if (is_r2) { - r_cons_printf ("agn 0x%08"PFMT64x" ???\n", ref->addr); - r_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", ref->addr, addr); + if (is_rz) { + rz_cons_printf ("agn 0x%08"PFMT64x" ???\n", ref->addr); + rz_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", ref->addr, addr); } else if (is_json) { char taddr[64]; pj_o (pj); @@ -7407,7 +7407,7 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt pj_a (pj); open_object = true; } else { - r_cons_printf ("%s0x%08"PFMT64x" ???\n", pre, ref->addr); + rz_cons_printf ("%s0x%08"PFMT64x" ???\n", pre, ref->addr); } snprintf (arg, sizeof (arg), "0x%08"PFMT64x, ref->addr); if (sdb_add (db, arg, "1", 0)) { @@ -7436,68 +7436,68 @@ static void anal_axg(RCore *core, const char *input, int level, Sdb *db, int opt } } } - r_list_free (xrefs); + rz_list_free (xrefs); } -static void cmd_anal_ucall_ref (RCore *core, ut64 addr) { - RAnalFunction * fcn = r_anal_get_function_at (core->anal, addr); +static void cmd_anal_ucall_ref (RzCore *core, ut64 addr) { + RzAnalFunction * fcn = rz_anal_get_function_at (core->anal, addr); if (fcn) { - r_cons_printf (" ; %s", fcn->name); + rz_cons_printf (" ; %s", fcn->name); } else { - r_cons_printf (" ; 0x%" PFMT64x, addr); + rz_cons_printf (" ; 0x%" PFMT64x, addr); } } static char *get_op_ireg(void *user, ut64 addr) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *res = NULL; - RAnalOp *op = r_core_anal_op (core, addr, 0); + RzAnalOp *op = rz_core_anal_op (core, addr, 0); if (op && op->ireg) { res = strdup (op->ireg); } - r_anal_op_free (op); + rz_anal_op_free (op); return res; } -static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, bool color) { +static char *get_buf_asm(RzCore *core, ut64 from, ut64 addr, RzAnalFunction *fcn, bool color) { int has_color = core->print->flags & R_PRINT_FLAGS_COLOR; char str[512]; const int size = 12; ut8 buf[12]; - RAsmOp asmop = {0}; + RzAsmOp asmop = {0}; char *buf_asm = NULL; - bool asm_subvar = r_config_get_i (core->config, "asm.sub.var"); - core->parser->pseudo = r_config_get_i (core->config, "asm.pseudo"); - core->parser->subrel = r_config_get_i (core->config, "asm.sub.rel"); - core->parser->localvar_only = r_config_get_i (core->config, "asm.sub.varonly"); + bool asm_subvar = rz_config_get_i (core->config, "asm.sub.var"); + core->parser->pseudo = rz_config_get_i (core->config, "asm.pseudo"); + core->parser->subrel = rz_config_get_i (core->config, "asm.sub.rel"); + core->parser->localvar_only = rz_config_get_i (core->config, "asm.sub.varonly"); if (core->parser->subrel) { core->parser->subrel_addr = from; } - r_io_read_at (core->io, addr, buf, size); - r_asm_set_pc (core->rasm, addr); - r_asm_disassemble (core->rasm, &asmop, buf, size); - int ba_len = r_strbuf_length (&asmop.buf_asm) + 128; + rz_io_read_at (core->io, addr, buf, size); + rz_asm_set_pc (core->rasm, addr); + rz_asm_disassemble (core->rasm, &asmop, buf, size); + int ba_len = rz_strbuf_length (&asmop.buf_asm) + 128; char *ba = malloc (ba_len); - strcpy (ba, r_strbuf_get (&asmop.buf_asm)); + strcpy (ba, rz_strbuf_get (&asmop.buf_asm)); if (asm_subvar) { - core->parser->get_ptr_at = r_anal_function_get_var_stackptr_at; - core->parser->get_reg_at = r_anal_function_get_var_reg_at; + core->parser->get_ptr_at = rz_anal_function_get_var_stackptr_at; + core->parser->get_reg_at = rz_anal_function_get_var_reg_at; core->parser->get_op_ireg = get_op_ireg; - r_parse_subvar (core->parser, fcn, addr, asmop.size, + rz_parse_subvar (core->parser, fcn, addr, asmop.size, ba, ba, sizeof (asmop.buf_asm)); } - RAnalHint *hint = r_anal_hint_get (core->anal, addr); - r_parse_filter (core->parser, addr, core->flags, hint, + RzAnalHint *hint = rz_anal_hint_get (core->anal, addr); + rz_parse_filter (core->parser, addr, core->flags, hint, ba, str, sizeof (str), core->print->big_endian); - r_anal_hint_free (hint); - r_asm_op_set_asm (&asmop, ba); + rz_anal_hint_free (hint); + rz_asm_op_set_asm (&asmop, ba); free (ba); if (color && has_color) { - buf_asm = r_print_colorize_opcode (core->print, str, + buf_asm = rz_print_colorize_opcode (core->print, str, core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0); } else { - buf_asm = r_str_new (str); + buf_asm = rz_str_new (str); } return buf_asm; } @@ -7505,44 +7505,44 @@ static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, #define var_ref_list(a,d,t) sdb_fmt ("var.0x%"PFMT64x".%d.%d.%s",\ a, 1, d, (t == 'R')?"reads":"writes"); -static bool cmd_anal_refs(RCore *core, const char *input) { +static bool cmd_anal_refs(RzCore *core, const char *input) { ut64 addr = core->offset; switch (input[0]) { case '-': { // "ax-" - RList *list; - RListIter *iter; - RAnalRef *ref; + RzList *list; + RzListIter *iter; + RzAnalRef *ref; char *cp_inp = strdup (input + 1); char *ptr = cp_inp; - r_str_trim_head (ptr); + rz_str_trim_head (ptr); if (!strcmp (ptr, "*")) { // "ax-*" - r_anal_xrefs_init (core->anal); + rz_anal_xrefs_init (core->anal); } else { - int n = r_str_word_set0 (ptr); + int n = rz_str_word_set0 (ptr); ut64 from = UT64_MAX, to = UT64_MAX; switch (n) { case 2: - from = r_num_math (core->num, r_str_word_get0 (ptr, 1)); + from = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); //fall through case 1: // get addr - to = r_num_math (core->num, r_str_word_get0 (ptr, 0)); + to = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); break; default: to = core->offset; break; } - list = r_anal_xrefs_get (core->anal, to); + list = rz_anal_xrefs_get (core->anal, to); if (list) { - r_list_foreach (list, iter, ref) { + rz_list_foreach (list, iter, ref) { if (from != UT64_MAX && from == ref->addr) { - r_anal_xref_del (core->anal, ref->addr, ref->at); + rz_anal_xref_del (core->anal, ref->addr, ref->at); } if (from == UT64_MAX) { - r_anal_xref_del (core->anal, ref->addr, ref->at); + rz_anal_xref_del (core->anal, ref->addr, ref->at); } } } - r_list_free (list); + rz_list_free (list); } free (cp_inp); } break; @@ -7554,7 +7554,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } else if (input[1] == 'j') { PJ *pj = pj_new (); anal_axg (core, input + 2, 0, db, R_CORE_ANAL_JSON, pj); - r_cons_printf("%s\n", pj_string (pj)); + rz_cons_printf("%s\n", pj_string (pj)); pj_free (pj); } else { anal_axg (core, input[1] ? input + 2 : NULL, 0, db, 0, NULL); @@ -7566,46 +7566,46 @@ static bool cmd_anal_refs(RCore *core, const char *input) { case 'j': // "axj" case 'q': // "axq" case '*': // "ax*" - r_anal_xrefs_list (core->anal, input[0]); + rz_anal_xrefs_list (core->anal, input[0]); break; case '.': { // "ax." char *tInput = strdup (input); - if (r_str_replace_ch (tInput, '.', 't', false)) { + if (rz_str_replace_ch (tInput, '.', 't', false)) { cmd_anal_refs (core, tInput); } char *fInput = strdup (input); - if (r_str_replace_ch (fInput, '.', 'f', false)) { + if (rz_str_replace_ch (fInput, '.', 'f', false)) { cmd_anal_refs (core, fInput); } free (tInput); free (fInput); } break; case 'm': { // "axm" - RList *list; - RAnalRef *ref; - RListIter *iter; - char *ptr = strdup (r_str_trim_head_ro (input + 1)); - int n = r_str_word_set0 (ptr); + RzList *list; + RzAnalRef *ref; + RzListIter *iter; + char *ptr = strdup (rz_str_trim_head_ro (input + 1)); + int n = rz_str_word_set0 (ptr); ut64 at = core->offset; ut64 addr = UT64_MAX; switch (n) { case 2: // get at - at = r_num_math (core->num, r_str_word_get0 (ptr, 1)); + at = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); /* fall through */ case 1: // get addr - addr = r_num_math (core->num, r_str_word_get0 (ptr, 0)); + addr = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); break; default: free (ptr); return false; } //get all xrefs pointing to addr - list = r_anal_xrefs_get (core->anal, addr); - r_list_foreach (list, iter, ref) { - r_cons_printf ("0x%"PFMT64x" %s\n", ref->addr, r_anal_xrefs_type_tostring (ref->type)); - r_anal_xrefs_set (core->anal, ref->addr, at, ref->type); + list = rz_anal_xrefs_get (core->anal, addr); + rz_list_foreach (list, iter, ref) { + rz_cons_printf ("0x%"PFMT64x" %s\n", ref->addr, rz_anal_xrefs_type_tostring (ref->type)); + rz_anal_xrefs_set (core->anal, ref->addr, at, ref->type); } - r_list_free (list); + rz_list_free (list); free (ptr); } break; case 'v': // "axv" @@ -7613,26 +7613,26 @@ static bool cmd_anal_refs(RCore *core, const char *input) { break; case 't': { // "axt" if (input[1] == '?') { // axt? - r_core_cmd_help (core, help_msg_axt); + rz_core_cmd_help (core, help_msg_axt); break; } - RList *list = NULL; - RAnalFunction *fcn; - RAnalRef *ref; - RListIter *iter; + RzList *list = NULL; + RzAnalFunction *fcn; + RzAnalRef *ref; + RzListIter *iter; char *space = strchr (input, ' '); char *tmp = NULL; char *name = space ? strdup (space + 1): NULL; if (space) { - addr = r_num_math (core->num, space + 1); + addr = rz_num_math (core->num, space + 1); } else { addr = core->offset; } - list = r_anal_xrefs_get (core->anal, addr); + list = rz_anal_xrefs_get (core->anal, addr); if (list) { if (input[1] == 'q') { // "axtq" - r_list_foreach (list, iter, ref) { - r_cons_printf ("0x%" PFMT64x "\n", ref->addr); + rz_list_foreach (list, iter, ref) { + rz_cons_printf ("0x%" PFMT64x "\n", ref->addr); } } else if (input[1] == 'j') { // "axtj" PJ *pj = pj_new (); @@ -7640,18 +7640,18 @@ static bool cmd_anal_refs(RCore *core, const char *input) { return false; } pj_a (pj); - r_list_foreach (list, iter, ref) { - fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0); + rz_list_foreach (list, iter, ref) { + fcn = rz_anal_get_fcn_in (core->anal, ref->addr, 0); char *str = get_buf_asm (core, addr, ref->addr, fcn, false); pj_o (pj); pj_kn (pj, "from", ref->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (ref->type)); pj_ks (pj, "opcode", str); if (fcn) { pj_kn (pj, "fcn_addr", fcn->addr); pj_ks (pj, "fcn_name", fcn->name); } - RFlagItem *fi = r_flag_get_at (core->flags, fcn? fcn->addr: ref->addr, true); + RzFlagItem *fi = rz_flag_get_at (core->flags, fcn? fcn->addr: ref->addr, true); if (fi) { if (fcn) { if (strcmp (fcn->name, fi->name)) { @@ -7661,7 +7661,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) { pj_k (pj, "name"); if (fi->offset != ref->addr) { int delta = (int)(ref->addr - fi->offset); - char *name_ref = r_str_newf ("%s+%d", fi->name, delta); + char *name_ref = rz_str_newf ("%s+%d", fi->name, delta); pj_s (pj, name_ref); free (name_ref); } else { @@ -7669,7 +7669,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } } if (fi->realname && strcmp (fi->name, fi->realname)) { - char *escaped = r_str_escape (fi->realname); + char *escaped = rz_str_escape (fi->realname); if (escaped) { pj_ks (pj, "realname", escaped); free (escaped); @@ -7678,7 +7678,7 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } char *refname = core->anal->coreb.getNameDelta (core, ref->at); if (refname) { - r_str_replace_ch (refname, ' ', 0, true); + rz_str_replace_ch (refname, ' ', 0, true); pj_ks (pj, "refname", refname); free (refname); } @@ -7686,48 +7686,48 @@ static bool cmd_anal_refs(RCore *core, const char *input) { free (str); } pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); - r_cons_newline (); + rz_cons_newline (); } else if (input[1] == 'g') { // axtg - r_list_foreach (list, iter, ref) { - char *str = r_core_cmd_strf (core, "fd 0x%"PFMT64x, ref->addr); + rz_list_foreach (list, iter, ref) { + char *str = rz_core_cmd_strf (core, "fd 0x%"PFMT64x, ref->addr); if (!str) { str = strdup ("?\n"); } - r_str_trim_tail (str); - r_cons_printf ("agn 0x%" PFMT64x " \"%s\"\n", ref->addr, str); + rz_str_trim_tail (str); + rz_cons_printf ("agn 0x%" PFMT64x " \"%s\"\n", ref->addr, str); free (str); } if (input[2] != '*') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); - r_cons_printf ("agn 0x%" PFMT64x " \"%s\"\n", addr, fcn?fcn->name: "$$"); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); + rz_cons_printf ("agn 0x%" PFMT64x " \"%s\"\n", addr, fcn?fcn->name: "$$"); } - r_list_foreach (list, iter, ref) { - r_cons_printf ("age 0x%" PFMT64x " 0x%"PFMT64x"\n", ref->addr, addr); + rz_list_foreach (list, iter, ref) { + rz_cons_printf ("age 0x%" PFMT64x " 0x%"PFMT64x"\n", ref->addr, addr); } } else if (input[1] == '*') { // axt* // TODO: implement multi-line comments - r_list_foreach (list, iter, ref) - r_cons_printf ("CCa 0x%" PFMT64x " \"XREF type %d at 0x%" PFMT64x"%s\n", + rz_list_foreach (list, iter, ref) + rz_cons_printf ("CCa 0x%" PFMT64x " \"XREF type %d at 0x%" PFMT64x"%s\n", ref->addr, ref->type, addr, iter->n? ",": ""); } else { // axt - RAnalFunction *fcn; - r_list_foreach (list, iter, ref) { - fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0); + RzAnalFunction *fcn; + rz_list_foreach (list, iter, ref) { + fcn = rz_anal_get_fcn_in (core->anal, ref->addr, 0); char *buf_asm = get_buf_asm (core, addr, ref->addr, fcn, true); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr); char *print_comment = NULL; const char *nl = comment ? strchr (comment, '\n') : NULL; if (nl) { // display only until the first newline - comment = print_comment = r_str_ndup (comment, nl - comment); + comment = print_comment = rz_str_ndup (comment, nl - comment); } char *buf_fcn = comment - ? r_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", comment) - : r_str_newf ("%s", fcn ? fcn->name : "(nofunc)"); + ? rz_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", comment) + : rz_str_newf ("%s", fcn ? fcn->name : "(nofunc)"); free (print_comment); - r_cons_printf ("%s 0x%" PFMT64x " [%s] %s\n", - buf_fcn, ref->addr, r_anal_xrefs_type_tostring (ref->type), buf_asm); + rz_cons_printf ("%s 0x%" PFMT64x " [%s] %s\n", + buf_fcn, ref->addr, rz_anal_xrefs_type_tostring (ref->type), buf_asm); free (buf_asm); free (buf_fcn); } @@ -7740,73 +7740,73 @@ static bool cmd_anal_refs(RCore *core, const char *input) { } pj_a (pj); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } } - r_list_free (list); + rz_list_free (list); } break; case 'f': if (input[1] == 'f') { // "axff" - RAnalFunction * fcn = r_anal_get_fcn_in (core->anal, addr, 0); - RListIter *iter; + RzAnalFunction * fcn = rz_anal_get_fcn_in (core->anal, addr, 0); + RzListIter *iter; PJ *pj = NULL; - RAnalRef *refi; + RzAnalRef *refi; if (input[2] == 'j') { // "axffj" // start a new JSON object pj = pj_new (); pj_a (pj); } if (fcn) { - RList *refs = r_anal_function_get_refs (fcn); - r_list_foreach (refs, iter, refi) { - RFlagItem *f = r_flag_get_at (core->flags, refi->addr, true); + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, refi) { + RzFlagItem *f = rz_flag_get_at (core->flags, refi->addr, true); const char *name = f ? f->name: ""; if (pj) { pj_o (pj); - pj_ks (pj, "type", r_anal_xrefs_type_tostring(refi->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring(refi->type)); pj_kn (pj, "at", refi->at); pj_kn (pj, "ref", refi->addr); pj_ks (pj, "name", name); pj_end (pj); } else { - r_cons_printf ("%s 0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", - r_anal_xrefs_type_tostring(refi->type), refi->at, refi->addr, name); + rz_cons_printf ("%s 0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", + rz_anal_xrefs_type_tostring(refi->type), refi->at, refi->addr, name); } } if (pj) { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } } else { eprintf ("Cannot find any function\n"); } pj_free (pj); } else { // "axf" - RAsmOp asmop; - RList *list, *list_ = NULL; - RAnalRef *ref; - RListIter *iter; + RzAsmOp asmop; + RzList *list, *list_ = NULL; + RzAnalRef *ref; + RzListIter *iter; char *space = strchr (input, ' '); if (space) { - addr = r_num_math (core->num, space + 1); + addr = rz_num_math (core->num, space + 1); } else { addr = core->offset; } - RAnalFunction * fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction * fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (input[1] == '.') { // "axf." - list = list_ = r_anal_xrefs_get_from (core->anal, addr); + list = list_ = rz_anal_xrefs_get_from (core->anal, addr); if (!list) { - list = r_anal_function_get_refs (fcn); + list = rz_anal_function_get_refs (fcn); } } else { - list = r_anal_refs_get (core->anal, addr); + list = rz_anal_refs_get (core->anal, addr); } if (list) { if (input[1] == 'q') { // "axfq" - r_list_foreach (list, iter, ref) { - r_cons_printf ("0x%" PFMT64x "\n", ref->at); + rz_list_foreach (list, iter, ref) { + rz_cons_printf ("0x%" PFMT64x "\n", ref->at); } } else if (input[1] == 'j') { // "axfj" PJ *pj = pj_new (); @@ -7814,73 +7814,73 @@ static bool cmd_anal_refs(RCore *core, const char *input) { return false; } pj_a (pj); - r_list_foreach (list, iter, ref) { - // TODO: Use r_core_anal_op(DISASM) instead of all those 4 lines + rz_list_foreach (list, iter, ref) { + // TODO: Use rz_core_anal_op(DISASM) instead of all those 4 lines ut8 buf[16]; - r_io_read_at (core->io, ref->addr, buf, sizeof (buf)); - r_asm_set_pc (core->rasm, ref->addr); - r_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)); + rz_io_read_at (core->io, ref->addr, buf, sizeof (buf)); + rz_asm_set_pc (core->rasm, ref->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)); pj_o (pj); pj_kn (pj, "from", ref->at); pj_kn (pj, "to", ref->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (ref->type)); - pj_ks (pj, "opcode", r_asm_op_get_asm (&asmop)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (ref->type)); + pj_ks (pj, "opcode", rz_asm_op_get_asm (&asmop)); pj_end (pj); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else if (input[1] == '*') { // "axf*" // TODO: implement multi-line comments - r_list_foreach (list, iter, ref) { - r_cons_printf ("CCa 0x%" PFMT64x " \"XREF from 0x%" PFMT64x "\n", - ref->at, ref->type, r_asm_op_get_asm (&asmop), iter->n? ",": ""); + rz_list_foreach (list, iter, ref) { + rz_cons_printf ("CCa 0x%" PFMT64x " \"XREF from 0x%" PFMT64x "\n", + ref->at, ref->type, rz_asm_op_get_asm (&asmop), iter->n? ",": ""); } } else { // "axf" char str[512]; int has_color = core->print->flags & R_PRINT_FLAGS_COLOR; - r_list_foreach (list, iter, ref) { + rz_list_foreach (list, iter, ref) { ut8 buf[16]; char *desc; char *desc_to_free = NULL; - RFlagItem *flag = r_flag_get_at (core->flags, ref->addr, false); + RzFlagItem *flag = rz_flag_get_at (core->flags, ref->addr, false); if (flag) { desc = flag->name; } else { - r_io_read_at (core->io, ref->addr, buf, sizeof (buf)); - r_asm_set_pc (core->rasm, ref->addr); - r_asm_disassemble (core->rasm, &asmop, buf, sizeof(buf)); - RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr); - r_parse_filter (core->parser, ref->addr, core->flags, hint, r_asm_op_get_asm (&asmop), + rz_io_read_at (core->io, ref->addr, buf, sizeof (buf)); + rz_asm_set_pc (core->rasm, ref->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, sizeof(buf)); + RzAnalHint *hint = rz_anal_hint_get (core->anal, ref->addr); + rz_parse_filter (core->parser, ref->addr, core->flags, hint, rz_asm_op_get_asm (&asmop), str, sizeof (str), core->print->big_endian); - r_anal_hint_free (hint); + rz_anal_hint_free (hint); if (has_color) { - desc = desc_to_free = r_print_colorize_opcode (core->print, str, + desc = desc_to_free = rz_print_colorize_opcode (core->print, str, core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0); } else { desc = str; } } - r_cons_printf ("%c 0x%" PFMT64x " %s", + rz_cons_printf ("%c 0x%" PFMT64x " %s", ref->type ? ref->type : ' ', ref->addr, desc); if (ref->type == R_ANAL_REF_TYPE_CALL) { - RAnalOp aop; - r_anal_op (core->anal, &aop, ref->addr, buf, sizeof(buf), R_ANAL_OP_MASK_BASIC); + RzAnalOp aop; + rz_anal_op (core->anal, &aop, ref->addr, buf, sizeof(buf), R_ANAL_OP_MASK_BASIC); if (aop.type == R_ANAL_OP_TYPE_UCALL) { cmd_anal_ucall_ref (core, ref->addr); } } - r_cons_newline (); + rz_cons_newline (); free (desc_to_free); } } } else { if (input[1] == 'j') { // "axfj" - r_cons_print ("[]\n"); + rz_cons_print ("[]\n"); } } - r_list_free (list); + rz_list_free (list); } break; case 'F': // "axF" @@ -7892,65 +7892,65 @@ static bool cmd_anal_refs(RCore *core, const char *input) { case 's': // "axs" case ' ': // "ax " { - char *ptr = strdup (r_str_trim_head_ro ((char *)input + 1)); - int n = r_str_word_set0 (ptr); + char *ptr = strdup (rz_str_trim_head_ro ((char *)input + 1)); + int n = rz_str_word_set0 (ptr); ut64 at = core->offset; ut64 addr = UT64_MAX; - RAnalRefType reftype = r_anal_xrefs_type (input[0]); + RzAnalRefType reftype = rz_anal_xrefs_type (input[0]); switch (n) { case 2: // get at - at = r_num_math (core->num, r_str_word_get0 (ptr, 1)); + at = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); /* fall through */ case 1: // get addr - addr = r_num_math (core->num, r_str_word_get0 (ptr, 0)); + addr = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); break; default: free (ptr); return false; } - r_anal_xrefs_set (core->anal, at, addr, reftype); + rz_anal_xrefs_set (core->anal, at, addr, reftype); free (ptr); } break; default: case '?': - r_core_cmd_help (core, help_msg_ax); + rz_core_cmd_help (core, help_msg_ax); break; } return true; } -static void cmd_anal_hint(RCore *core, const char *input) { +static void cmd_anal_hint(RzCore *core, const char *input) { switch (input[0]) { case '?': if (input[1]) { - ut64 addr = r_num_math (core->num, input + 1); - r_core_anal_hint_print (core->anal, addr, 0); + ut64 addr = rz_num_math (core->num, input + 1); + rz_core_anal_hint_print (core->anal, addr, 0); } else { - r_core_cmd_help (core, help_msg_ah); + rz_core_cmd_help (core, help_msg_ah); } break; case '.': // "ah." - r_core_anal_hint_print (core->anal, core->offset, 0); + rz_core_anal_hint_print (core->anal, core->offset, 0); break; case 'a': // "aha" set arch if (input[1] == ' ') { char *ptr = strdup (input + 2); - r_str_word_set0 (ptr); - const char *arch = r_str_word_get0 (ptr, 0); - r_anal_hint_set_arch (core->anal, core->offset, !arch || strcmp (arch, "0") == 0 ? NULL : arch); + rz_str_word_set0 (ptr); + const char *arch = rz_str_word_get0 (ptr, 0); + rz_anal_hint_set_arch (core->anal, core->offset, !arch || strcmp (arch, "0") == 0 ? NULL : arch); free (ptr); } else if (input[1] == '-') { - r_anal_hint_unset_arch (core->anal, core->offset); + rz_anal_hint_unset_arch (core->anal, core->offset); } else { eprintf ("Missing argument\n"); } break; case 'o': // "aho" if (input[1] == ' ') { - const char *arg = r_str_trim_head_ro (input + 1); - int type = r_anal_optype_from_string (arg); - r_anal_hint_set_type (core->anal, core->offset, type); + const char *arg = rz_str_trim_head_ro (input + 1); + int type = rz_anal_optype_from_string (arg); + rz_anal_hint_set_type (core->anal, core->offset, type); } else { eprintf ("Usage: aho [type] # can be mov, jmp, call, ...\n"); } @@ -7959,32 +7959,32 @@ static void cmd_anal_hint(RCore *core, const char *input) { if (input[1] == ' ') { char *ptr = strdup (input + 2); int bits; - int i = r_str_word_set0 (ptr); + int i = rz_str_word_set0 (ptr); if (i == 2) { - r_num_math (core->num, r_str_word_get0 (ptr, 1)); + rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); } - bits = r_num_math (core->num, r_str_word_get0 (ptr, 0)); - r_anal_hint_set_bits (core->anal, core->offset, bits); + bits = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); + rz_anal_hint_set_bits (core->anal, core->offset, bits); free (ptr); } else if (input[1] == '-') { - r_anal_hint_unset_bits (core->anal, core->offset); + rz_anal_hint_unset_bits (core->anal, core->offset); } else { eprintf ("Missing argument\n"); } break; case 'i': // "ahi" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_ahi); + rz_core_cmd_help (core, help_msg_ahi); } else if (isdigit (input[1])) { - r_anal_hint_set_nword (core->anal, core->offset, input[1] - '0'); + rz_anal_hint_set_nword (core->anal, core->offset, input[1] - '0'); input++; } else if (input[1] == '-') { // "ahi-" - r_anal_hint_set_immbase (core->anal, core->offset, 0); + rz_anal_hint_set_immbase (core->anal, core->offset, 0); } if (input[1] == ' ') { // You can either specify immbase with letters, or numbers int base; - if (r_str_startswith (input + 2, "10u") || r_str_startswith (input + 2, "du")) { + if (rz_str_startswith (input + 2, "10u") || rz_str_startswith (input + 2, "du")) { base = 11; } else { base = (input[2] == 's') ? 1 : @@ -7995,81 +7995,81 @@ static void cmd_anal_hint(RCore *core, const char *input) { (input[2] == 'h') ? 16 : (input[2] == 'i') ? 32 : // ip address (input[2] == 'S') ? 80 : // syscall - (int) r_num_math (core->num, input + 1); + (int) rz_num_math (core->num, input + 1); } - r_anal_hint_set_immbase (core->anal, core->offset, base); + rz_anal_hint_set_immbase (core->anal, core->offset, base); } else if (input[1] != '?' && input[1] != '-') { eprintf ("|ERROR| Usage: ahi \n"); } break; case 'h': // "ahh" if (input[1] == '-') { - r_anal_hint_unset_high (core->anal, core->offset); + rz_anal_hint_unset_high (core->anal, core->offset); } else if (input[1] == ' ') { - r_anal_hint_set_high (core->anal, r_num_math (core->num, input + 1)); + rz_anal_hint_set_high (core->anal, rz_num_math (core->num, input + 1)); } else { - r_anal_hint_set_high (core->anal, core->offset); + rz_anal_hint_set_high (core->anal, core->offset); } break; case 'c': // "ahc" if (input[1] == ' ') { - r_anal_hint_set_jump ( + rz_anal_hint_set_jump ( core->anal, core->offset, - r_num_math (core->num, input + 1)); + rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_jump (core->anal, core->offset); + rz_anal_hint_unset_jump (core->anal, core->offset); } break; case 'f': // "ahf" if (input[1] == ' ') { - r_anal_hint_set_fail ( + rz_anal_hint_set_fail ( core->anal, core->offset, - r_num_math (core->num, input + 1)); + rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_fail (core->anal, core->offset); + rz_anal_hint_unset_fail (core->anal, core->offset); } break; case 'F': // "ahF" set stackframe size if (input[1] == ' ') { - r_anal_hint_set_stackframe ( + rz_anal_hint_set_stackframe ( core->anal, core->offset, - r_num_math (core->num, input + 1)); + rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_stackframe (core->anal, core->offset); + rz_anal_hint_unset_stackframe (core->anal, core->offset); } break; case 's': // "ahs" set size (opcode length) if (input[1] == ' ') { - r_anal_hint_set_size (core->anal, core->offset, atoi (input + 1)); + rz_anal_hint_set_size (core->anal, core->offset, atoi (input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_size (core->anal, core->offset); + rz_anal_hint_unset_size (core->anal, core->offset); } else { eprintf ("Usage: ahs 16\n"); } break; case 'S': // "ahS" set asm.syntax if (input[1] == ' ') { - r_anal_hint_set_syntax (core->anal, core->offset, input + 2); + rz_anal_hint_set_syntax (core->anal, core->offset, input + 2); } else if (input[1] == '-') { - r_anal_hint_unset_syntax (core->anal, core->offset); + rz_anal_hint_unset_syntax (core->anal, core->offset); } else { eprintf ("Usage: ahS att\n"); } break; case 'd': // "ahd" set opcode string if (input[1] == ' ') { - r_anal_hint_set_opcode (core->anal, core->offset, input + 2); + rz_anal_hint_set_opcode (core->anal, core->offset, input + 2); } else if (input[1] == '-') { - r_anal_hint_unset_opcode (core->anal, core->offset); + rz_anal_hint_unset_opcode (core->anal, core->offset); } else { eprintf ("Usage: ahd popall\n"); } break; case 'e': // "ahe" set ESIL string if (input[1] == ' ') { - r_anal_hint_set_esil (core->anal, core->offset, input + 2); + rz_anal_hint_set_esil (core->anal, core->offset, input + 2); } else if (input[1] == '-') { - r_anal_hint_unset_esil (core->anal, core->offset); + rz_anal_hint_unset_esil (core->anal, core->offset); } else { eprintf ("Usage: ahe r0,pc,=\n"); } @@ -8077,93 +8077,93 @@ static void cmd_anal_hint(RCore *core, const char *input) { #if 0 case 'e': // set endian if (input[1] == ' ') { - r_anal_hint_set_opcode (core->anal, core->offset, atoi (input + 1)); + rz_anal_hint_set_opcode (core->anal, core->offset, atoi (input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_opcode (core->anal, core->offset); + rz_anal_hint_unset_opcode (core->anal, core->offset); } break; #endif case 'p': // "ahp" if (input[1] == ' ') { - r_anal_hint_set_pointer (core->anal, core->offset, r_num_math (core->num, input + 1)); + rz_anal_hint_set_pointer (core->anal, core->offset, rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { // "ahp-" - r_anal_hint_unset_pointer (core->anal, core->offset); + rz_anal_hint_unset_pointer (core->anal, core->offset); } break; case 'r': // "ahr" if (input[1] == ' ') { - r_anal_hint_set_ret (core->anal, core->offset, r_num_math (core->num, input + 1)); + rz_anal_hint_set_ret (core->anal, core->offset, rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { // "ahr-" - r_anal_hint_unset_ret (core->anal, core->offset); + rz_anal_hint_unset_ret (core->anal, core->offset); } case '*': // "ah*" case 'j': // "ahj" case '\0': // "ah" if (input[0] && input[1] == ' ') { - char *ptr = strdup (r_str_trim_head_ro (input + 2)); - r_str_word_set0 (ptr); - ut64 addr = r_num_math (core->num, r_str_word_get0 (ptr, 0)); - r_core_anal_hint_print (core->anal, addr, input[0]); + char *ptr = strdup (rz_str_trim_head_ro (input + 2)); + rz_str_word_set0 (ptr); + ut64 addr = rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); + rz_core_anal_hint_print (core->anal, addr, input[0]); free (ptr); } else { - r_core_anal_hint_list (core->anal, input[0]); + rz_core_anal_hint_list (core->anal, input[0]); } break; case 'v': // "ahv" if (input[1] == ' ') { - r_anal_hint_set_val ( + rz_anal_hint_set_val ( core->anal, core->offset, - r_num_math (core->num, input + 1)); + rz_num_math (core->num, input + 1)); } else if (input[1] == '-') { - r_anal_hint_unset_val (core->anal, core->offset); + rz_anal_hint_unset_val (core->anal, core->offset); } break; case '-': // "ah-" if (input[1]) { if (input[1] == '*') { - r_anal_hint_clear (core->anal); + rz_anal_hint_clear (core->anal); } else { - char *ptr = strdup (r_str_trim_head_ro (input + 1)); + char *ptr = strdup (rz_str_trim_head_ro (input + 1)); ut64 addr; int size = 1; - int i = r_str_word_set0 (ptr); + int i = rz_str_word_set0 (ptr); if (i == 2) { - size = r_num_math (core->num, r_str_word_get0 (ptr, 1)); + size = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); } - const char *a0 = r_str_word_get0 (ptr, 0); + const char *a0 = rz_str_word_get0 (ptr, 0); if (a0 && *a0) { - addr = r_num_math (core->num, a0); + addr = rz_num_math (core->num, a0); } else { addr = core->offset; } - r_anal_hint_del (core->anal, addr, size); + rz_anal_hint_del (core->anal, addr, size); free (ptr); } } else { - r_anal_hint_clear (core->anal); + rz_anal_hint_clear (core->anal); } break; case 't': // "aht" switch (input[1]) { case 's': { // "ahts" char *off = strdup (input + 2); - r_str_trim (off); - int toff = r_num_math (NULL, off); + rz_str_trim (off); + int toff = rz_num_math (NULL, off); if (toff) { - RList *typeoffs = r_type_get_by_offset (core->anal->sdb_types, toff); - RListIter *iter; + RzList *typeoffs = rz_type_get_by_offset (core->anal->sdb_types, toff); + RzListIter *iter; char *ty; - r_list_foreach (typeoffs, iter, ty) { - r_cons_printf ("%s\n", ty); + rz_list_foreach (typeoffs, iter, ty) { + rz_cons_printf ("%s\n", ty); } - r_list_free (typeoffs); + rz_list_free (typeoffs); } free (off); break; } case ' ': { - // r_anal_hint_set_opcode (core->anal, core->offset, input + 2); + // rz_anal_hint_set_opcode (core->anal, core->offset, input + 2); const char *off = NULL; - char *type = strdup (r_str_trim_head_ro (input + 2)); + char *type = strdup (rz_str_trim_head_ro (input + 2)); char *idx = strchr (type, ' '); if (idx) { *idx++ = 0; @@ -8176,9 +8176,9 @@ static void cmd_anal_hint(RCore *core, const char *input) { if (ptr) { *ptr++ = 0; - r_str_trim (ptr); + rz_str_trim (ptr); if (ptr && *ptr) { - addr = r_num_math (core->num, ptr); + addr = rz_num_math (core->num, ptr); } else { eprintf ("address is unvalid\n"); free (type); @@ -8187,14 +8187,14 @@ static void cmd_anal_hint(RCore *core, const char *input) { } else { addr = core->offset; } - r_str_trim (type); - RAsmOp asmop; - RAnalOp op = { 0 }; + rz_str_trim (type); + RzAsmOp asmop; + RzAnalOp op = { 0 }; ut8 code[128] = { 0 }; - (void)r_io_read_at (core->io, core->offset, code, sizeof (code)); - r_asm_set_pc (core->rasm, addr); - (void)r_asm_disassemble (core->rasm, &asmop, code, core->blocksize); - int ret = r_anal_op (core->anal, &op, core->offset, code, core->blocksize, R_ANAL_OP_MASK_VAL); + (void)rz_io_read_at (core->io, core->offset, code, sizeof (code)); + rz_asm_set_pc (core->rasm, addr); + (void)rz_asm_disassemble (core->rasm, &asmop, code, core->blocksize); + int ret = rz_anal_op (core->anal, &op, core->offset, code, core->blocksize, R_ANAL_OP_MASK_VAL); if (ret >= 0) { // HACK: Just convert only the first imm seen for (i = 0; i < 3; i++) { @@ -8215,75 +8215,75 @@ static void cmd_anal_hint(RCore *core, const char *input) { } if (offimm != 0) { if (off) { - offimm += r_num_math (NULL, off); + offimm += rz_num_math (NULL, off); } // TODO: Allow to select from multiple choices - RList *otypes = r_type_get_by_offset (core->anal->sdb_types, offimm); - RListIter *iter; + RzList *otypes = rz_type_get_by_offset (core->anal->sdb_types, offimm); + RzListIter *iter; char *otype = NULL; - r_list_foreach (otypes, iter, otype) { + rz_list_foreach (otypes, iter, otype) { // TODO: I don't think we should silently error, it is confusing if (!strcmp (type, otype)) { //eprintf ("Adding type offset %s\n", type); - r_type_link_offset (core->anal->sdb_types, type, addr); - r_anal_hint_set_offset (core->anal, addr, otype); + rz_type_link_offset (core->anal->sdb_types, type, addr); + rz_anal_hint_set_offset (core->anal, addr, otype); break; } } if (!otype) { eprintf ("wrong type for opcode offset\n"); } - r_list_free (otypes); + rz_list_free (otypes); } } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); free (type); } break; case '?': - r_core_cmd_help (core, help_msg_aht); + rz_core_cmd_help (core, help_msg_aht); break; } } } -static void agraph_print_node_gml(RANode *n, void *user) { - r_cons_printf (" node [\n" +static void agraph_print_node_gml(RzANode *n, void *user) { + rz_cons_printf (" node [\n" " id %d\n" " label \"%s\"\n" " ]\n", n->gnode->idx, n->title); } -static void agraph_print_edge_gml(RANode *from, RANode *to, void *user) { - r_cons_printf (" edge [\n" +static void agraph_print_edge_gml(RzANode *from, RzANode *to, void *user) { + rz_cons_printf (" edge [\n" " source %d\n" " target %d\n" " ]\n", from->gnode->idx, to->gnode->idx ); } -static void agraph_print_node_dot(RANode *n, void *user) { +static void agraph_print_node_dot(RzANode *n, void *user) { char *label = strdup (n->body); - //label = r_str_replace (label, "\n", "\\l", 1); + //label = rz_str_replace (label, "\n", "\\l", 1); if (!label || !*label) { - r_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\"]\n", + rz_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\"]\n", n->title, n->title, n->title); } else { - r_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\\n%s\"]\n", + rz_cons_printf ("\"%s\" [URL=\"%s\", color=\"lightgray\", label=\"%s\\n%s\"]\n", n->title, n->title, n->title, label); } free (label); } -static void agraph_print_node(RANode *n, void *user) { +static void agraph_print_node(RzANode *n, void *user) { char *encbody, *cmd; int len = strlen (n->body); if (len > 0 && n->body[len - 1] == '\n') { len--; } - encbody = r_base64_encode_dyn (n->body, len); - cmd = r_str_newf ("agn \"%s\" base64:%s\n", n->title, encbody); - r_cons_printf (cmd); + encbody = rz_base64_encode_dyn (n->body, len); + cmd = rz_str_newf ("agn \"%s\" base64:%s\n", n->title, encbody); + rz_cons_printf (cmd); free (cmd); free (encbody); } @@ -8303,7 +8303,7 @@ static char *getViewerPath(void) { NULL }; for (i = 0; viewers[i]; i++) { - char *viewerPath = r_file_path (viewers[i]); + char *viewerPath = rz_file_path (viewers[i]); if (viewerPath && strcmp (viewerPath, viewers[i])) { return viewerPath; } @@ -8312,27 +8312,27 @@ static char *getViewerPath(void) { return NULL; } -static char* graph_cmd(RCore *core, char *r2_cmd, const char *save_path) { +static char* graph_cmd(RzCore *core, char *r2_cmd, const char *save_path) { const char *dot = "dot"; char *cmd = NULL; - const char *ext = r_config_get (core->config, "graph.gv.format"); - char *dotPath = r_file_path (dot); + const char *ext = rz_config_get (core->config, "graph.gv.format"); + char *dotPath = rz_file_path (dot); if (!strcmp (dotPath, dot)) { free (dotPath); dot = "xdot"; - dotPath = r_file_path (dot); + dotPath = rz_file_path (dot); if (!strcmp (dotPath, dot)) { free (dotPath); - return r_str_new ("agf"); + return rz_str_new ("agf"); } } if (save_path && *save_path) { - cmd = r_str_newf ("%s > a.dot;!%s -T%s -o%s a.dot;", + cmd = rz_str_newf ("%s > a.dot;!%s -T%s -o%s a.dot;", r2_cmd, dot, ext, save_path); } else { char *viewer = getViewerPath(); if (viewer) { - cmd = r_str_newf ("%s > a.dot;!%s -T%s -oa.%s a.dot;!%s a.%s", + cmd = rz_str_newf ("%s > a.dot;!%s -T%s -oa.%s a.dot;!%s a.%s", r2_cmd, dot, ext, ext, viewer, ext); free (viewer); } else { @@ -8343,15 +8343,15 @@ static char* graph_cmd(RCore *core, char *r2_cmd, const char *save_path) { return cmd; } -static void agraph_print_edge_dot(RANode *from, RANode *to, void *user) { - r_cons_printf ("\"%s\" -> \"%s\"\n", from->title, to->title); +static void agraph_print_edge_dot(RzANode *from, RzANode *to, void *user) { + rz_cons_printf ("\"%s\" -> \"%s\"\n", from->title, to->title); } -static void agraph_print_edge(RANode *from, RANode *to, void *user) { - r_cons_printf ("age \"%s\" \"%s\"\n", from->title, to->title); +static void agraph_print_edge(RzANode *from, RzANode *to, void *user) { + rz_cons_printf ("age \"%s\" \"%s\"\n", from->title, to->title); } -static void cmd_agraph_node(RCore *core, const char *input) { +static void cmd_agraph_node(RzCore *core, const char *input) { switch (*input) { case ' ': { // "agn" char *newbody = NULL; @@ -8359,37 +8359,37 @@ static void cmd_agraph_node(RCore *core, const char *input) { int n_args, B_LEN = strlen ("base64:"); int color = -1; input++; - args = r_str_argv (input, &n_args); + args = rz_str_argv (input, &n_args); if (n_args < 1 || n_args > 3) { - r_cons_printf ("Wrong arguments\n"); - r_str_argv_free (args); + rz_cons_printf ("Wrong arguments\n"); + rz_str_argv_free (args); break; } - // strdup cause there is double free in r_str_argv_free due to a realloc call + // strdup cause there is double free in rz_str_argv_free due to a realloc call if (n_args > 1) { body = strdup (args[1]); if (strncmp (body, "base64:", B_LEN) == 0) { - body = r_str_replace (body, "\\n", "", true); - newbody = (char *)r_base64_decode_dyn (body + B_LEN, -1); + body = rz_str_replace (body, "\\n", "", true); + newbody = (char *)rz_base64_decode_dyn (body + B_LEN, -1); free (body); if (!newbody) { eprintf ("Cannot allocate buffer\n"); - r_str_argv_free (args); + rz_str_argv_free (args); break; } body = newbody; } - body = r_str_append (body, "\n"); + body = rz_str_append (body, "\n"); if (n_args > 2) { color = atoi(args[2]); } } else { body = strdup (""); } - r_agraph_add_node_with_color (core->graph, args[0], body, color); - r_str_argv_free (args); + rz_agraph_add_node_with_color (core->graph, args[0], body, color); + rz_str_argv_free (args); free (body); - //free newbody it's not necessary since r_str_append reallocate the space + //free newbody it's not necessary since rz_str_append reallocate the space break; } case '-': { // "agn-" @@ -8397,112 +8397,112 @@ static void cmd_agraph_node(RCore *core, const char *input) { int n_args; input++; - args = r_str_argv (input, &n_args); + args = rz_str_argv (input, &n_args); if (n_args != 1) { - r_cons_printf ("Wrong arguments\n"); - r_str_argv_free (args); + rz_cons_printf ("Wrong arguments\n"); + rz_str_argv_free (args); break; } - r_agraph_del_node (core->graph, args[0]); - r_str_argv_free (args); + rz_agraph_del_node (core->graph, args[0]); + rz_str_argv_free (args); break; } case '?': default: - r_core_cmd_help (core, help_msg_agn); + rz_core_cmd_help (core, help_msg_agn); break; } } -static void cmd_agraph_edge(RCore *core, const char *input) { +static void cmd_agraph_edge(RzCore *core, const char *input) { switch (*input) { case ' ': // "age" case '-': { // "age-" - RANode *u, *v; + RzANode *u, *v; char **args; int n_args; - args = r_str_argv (input + 1, &n_args); + args = rz_str_argv (input + 1, &n_args); if (n_args != 2) { - r_cons_printf ("Wrong arguments\n"); - r_str_argv_free (args); + rz_cons_printf ("Wrong arguments\n"); + rz_str_argv_free (args); break; } - u = r_agraph_get_node (core->graph, args[0]); - v = r_agraph_get_node (core->graph, args[1]); + u = rz_agraph_get_node (core->graph, args[0]); + v = rz_agraph_get_node (core->graph, args[1]); if (!u || !v) { if (!u) { - r_cons_printf ("Node %s not found!\n", args[0]); + rz_cons_printf ("Node %s not found!\n", args[0]); } else { - r_cons_printf ("Node %s not found!\n", args[1]); + rz_cons_printf ("Node %s not found!\n", args[1]); } - r_str_argv_free (args); + rz_str_argv_free (args); break; } if (*input == ' ') { - r_agraph_add_edge (core->graph, u, v); + rz_agraph_add_edge (core->graph, u, v); } else { - r_agraph_del_edge (core->graph, u, v); + rz_agraph_del_edge (core->graph, u, v); } - r_str_argv_free (args); + rz_str_argv_free (args); break; } case '?': default: - r_core_cmd_help (core, help_msg_age); + rz_core_cmd_help (core, help_msg_age); break; } } -R_API void r_core_agraph_print (RCore *core, int use_utf, const char *input) { +RZ_API void rz_core_agraph_print (RzCore *core, int use_utf, const char *input) { if (use_utf != -1) { - r_config_set_i (core->config, "scr.utf8", use_utf); + rz_config_set_i (core->config, "scr.utf8", use_utf); } switch (*input) { case 0: - core->graph->can->linemode = r_config_get_i (core->config, "graph.linemode"); - core->graph->can->color = r_config_get_i (core->config, "scr.color"); - r_agraph_set_title (core->graph, - r_config_get (core->config, "graph.title")); - r_agraph_print (core->graph); + core->graph->can->linemode = rz_config_get_i (core->config, "graph.linemode"); + core->graph->can->color = rz_config_get_i (core->config, "scr.color"); + rz_agraph_set_title (core->graph, + rz_config_get (core->config, "graph.title")); + rz_agraph_print (core->graph); break; case 't':{ // "aggt" - tiny graph core->graph->is_tiny = true; - int e = r_config_get_i (core->config, "graph.edges"); - r_config_set_i (core->config, "graph.edges", 0); - r_core_visual_graph (core, core->graph, NULL, false); - r_config_set_i (core->config, "graph.edges", e); + int e = rz_config_get_i (core->config, "graph.edges"); + rz_config_set_i (core->config, "graph.edges", 0); + rz_core_visual_graph (core, core->graph, NULL, false); + rz_config_set_i (core->config, "graph.edges", e); core->graph->is_tiny = false; break; } case 'k': // "aggk" { - Sdb *db = r_agraph_get_sdb (core->graph); + Sdb *db = rz_agraph_get_sdb (core->graph); char *o = sdb_querys (db, "null", 0, "*"); - r_cons_print (o); + rz_cons_print (o); free (o); break; } case 'v': // "aggv" case 'i': // "aggi" - open current core->graph in interactive mode { - RANode *ran = r_agraph_get_first_node (core->graph); + RzANode *ran = rz_agraph_get_first_node (core->graph); if (ran) { ut64 oseek = core->offset; - r_agraph_set_title (core->graph, r_config_get (core->config, "graph.title")); - r_agraph_set_curnode (core->graph, ran); + rz_agraph_set_title (core->graph, rz_config_get (core->config, "graph.title")); + rz_agraph_set_curnode (core->graph, ran); core->graph->force_update_seek = true; core->graph->need_set_layout = true; - core->graph->layout = r_config_get_i (core->config, "graph.layout"); - int ov = r_cons_is_interactive (); + core->graph->layout = rz_config_get_i (core->config, "graph.layout"); + int ov = rz_cons_is_interactive (); core->graph->need_update_dim = true; - int update_seek = r_core_visual_graph (core, core->graph, NULL, true); - r_config_set_i (core->config, "scr.interactive", ov); - r_cons_show_cursor (true); - r_cons_enable_mouse (false); + int update_seek = rz_core_visual_graph (core, core->graph, NULL, true); + rz_config_set_i (core->config, "scr.interactive", ov); + rz_cons_show_cursor (true); + rz_cons_enable_mouse (false); if (update_seek != -1) { - r_core_seek (core, oseek, false); + rz_core_seek (core, oseek, false); } } else { eprintf ("This graph contains no nodes\n"); @@ -8510,19 +8510,19 @@ R_API void r_core_agraph_print (RCore *core, int use_utf, const char *input) { break; } case 'd': { // "aggd" - dot format - const char *font = r_config_get (core->config, "graph.font"); - r_cons_printf ("digraph code {\nrankdir=LR;\noutputorder=edgesfirst\ngraph [bgcolor=azure];\n" + const char *font = rz_config_get (core->config, "graph.font"); + rz_cons_printf ("digraph code {\nrankdir=LR;\noutputorder=edgesfirst\ngraph [bgcolor=azure];\n" "edge [arrowhead=normal, color=\"#3030c0\" style=bold weight=2];\n" "node [fillcolor=white, style=filled shape=box " "fontname=\"%s\" fontsize=\"8\"];\n", font); - r_agraph_foreach (core->graph, agraph_print_node_dot, NULL); - r_agraph_foreach_edge (core->graph, agraph_print_edge_dot, NULL); - r_cons_printf ("}\n"); + rz_agraph_foreach (core->graph, agraph_print_node_dot, NULL); + rz_agraph_foreach_edge (core->graph, agraph_print_edge_dot, NULL); + rz_cons_printf ("}\n"); break; } case '*': // "agg*" - - r_agraph_foreach (core->graph, agraph_print_node, NULL); - r_agraph_foreach_edge (core->graph, agraph_print_edge, NULL); + rz_agraph_foreach (core->graph, agraph_print_node, NULL); + rz_agraph_foreach_edge (core->graph, agraph_print_edge, NULL); break; case 'J': case 'j': { @@ -8533,30 +8533,30 @@ R_API void r_core_agraph_print (RCore *core, int use_utf, const char *input) { pj_o (pj); pj_k (pj, "nodes"); pj_a (pj); - r_agraph_print_json (core->graph, pj); + rz_agraph_print_json (core->graph, pj); pj_end (pj); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; case 'g': - r_cons_printf ("graph\n[\n" "hierarchic 1\n" "label \"\"\n" "directed 1\n"); - r_agraph_foreach (core->graph, agraph_print_node_gml, NULL); - r_agraph_foreach_edge (core->graph, agraph_print_edge_gml, NULL); - r_cons_print ("]\n"); + rz_cons_printf ("graph\n[\n" "hierarchic 1\n" "label \"\"\n" "directed 1\n"); + rz_agraph_foreach (core->graph, agraph_print_node_gml, NULL); + rz_agraph_foreach_edge (core->graph, agraph_print_edge_gml, NULL); + rz_cons_print ("]\n"); break; case 'w':{ // "aggw" - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "=H /graph/"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "=H /graph/"); } else { - const char *filename = r_str_trim_head_ro (input + 1); + const char *filename = rz_str_trim_head_ro (input + 1); char *cmd = graph_cmd (core, "aggd", filename); if (cmd && *cmd) { if (input[1] == ' ') { - r_cons_printf ("Saving to file '%s'...\n", filename); - r_cons_flush (); + rz_cons_printf ("Saving to file '%s'...\n", filename); + rz_cons_flush (); } - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } free (cmd); } @@ -8567,87 +8567,87 @@ R_API void r_core_agraph_print (RCore *core, int use_utf, const char *input) { } } -static void cmd_anal_graph(RCore *core, const char *input) { - core->graph->show_node_titles = r_config_get_i (core->config, "graph.ntitles"); - r_cons_enable_highlight (false); +static void cmd_anal_graph(RzCore *core, const char *input) { + core->graph->show_node_titles = rz_config_get_i (core->config, "graph.ntitles"); + rz_cons_enable_highlight (false); switch (input[0]) { case 'f': // "agf" switch (input[1]) { case 0: // "agf" - r_core_visual_graph (core, NULL, NULL, false); + rz_core_visual_graph (core, NULL, NULL, false); break; case ' ':{ // "agf " - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - r_core_visual_graph (core, NULL, fcn, false); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + rz_core_visual_graph (core, NULL, fcn, false); break; } case 'v': // "agfv" eprintf ("\rRendering graph..."); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ROOT); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ROOT); if (fcn) { - r_core_visual_graph (core, NULL, fcn, 1); + rz_core_visual_graph (core, NULL, fcn, 1); } - r_cons_enable_mouse (false); - r_cons_show_cursor (true); + rz_cons_enable_mouse (false); + rz_cons_show_cursor (true); break; case 't': { // "agft" - tiny graph - int e = r_config_get_i (core->config, "graph.edges"); - r_config_set_i (core->config, "graph.edges", 0); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - r_core_visual_graph (core, NULL, fcn, 2); - r_config_set_i (core->config, "graph.edges", e); + int e = rz_config_get_i (core->config, "graph.edges"); + rz_config_set_i (core->config, "graph.edges", 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + rz_core_visual_graph (core, NULL, fcn, 2); + rz_config_set_i (core->config, "graph.edges", e); break; } case 'd': // "agfd" if (input[2] == 'm') { - r_core_anal_graph (core, r_num_math (core->num, input + 3), + rz_core_anal_graph (core, rz_num_math (core->num, input + 3), R_CORE_ANAL_GRAPHLINES); } else { - r_core_anal_graph (core, r_num_math (core->num, input + 2), + rz_core_anal_graph (core, rz_num_math (core->num, input + 2), R_CORE_ANAL_GRAPHBODY); } break; case 'j': // "agfj" - r_core_anal_graph (core, r_num_math (core->num, input + 2), R_CORE_ANAL_JSON); + rz_core_anal_graph (core, rz_num_math (core->num, input + 2), R_CORE_ANAL_JSON); break; case 'J': {// "agfJ" // Honor asm.graph=false in json as well - RConfigHold *hc = r_config_hold_new (core->config); - r_config_hold_i (hc, "asm.offset", NULL); - const bool o_graph_offset = r_config_get_i (core->config, "graph.offset"); - r_config_set_i (core->config, "asm.offset", o_graph_offset); - r_core_anal_graph (core, r_num_math (core->num, input + 2), + RConfigHold *hc = rz_config_hold_new (core->config); + rz_config_hold_i (hc, "asm.offset", NULL); + const bool o_graph_offset = rz_config_get_i (core->config, "graph.offset"); + rz_config_set_i (core->config, "asm.offset", o_graph_offset); + rz_core_anal_graph (core, rz_num_math (core->num, input + 2), R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); break; } case 'g':{ // "agfg" - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - r_core_print_bb_gml (core, fcn); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + rz_core_print_bb_gml (core, fcn); break; } case 'k':{ // "agfk" - r_core_cmdf (core, "ag-; .agf* @ %"PFMT64u"; aggk", core->offset); + rz_core_cmdf (core, "ag-; .agf* @ %"PFMT64u"; aggk", core->offset); break; } case '*':{// "agf*" - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - r_core_print_bb_custom (core, fcn); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + rz_core_print_bb_custom (core, fcn); break; } case 'w': // "agfw" - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "=H /graph/"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "=H /graph/"); } else { - char *cmdargs = r_str_newf ("agfd @ 0x%"PFMT64x, core->offset); + char *cmdargs = rz_str_newf ("agfd @ 0x%"PFMT64x, core->offset); char *cmd = graph_cmd (core, cmdargs, input + 2); if (cmd && *cmd) { if (*(input + 2)) { - r_cons_printf ("Saving to file %s ...\n", input + 2); - r_cons_flush (); + rz_cons_printf ("Saving to file %s ...\n", input + 2); + rz_cons_flush (); } - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } free (cmd); free (cmdargs); @@ -8659,7 +8659,7 @@ static void cmd_anal_graph(RCore *core, const char *input) { } break; case '-': // "ag-" - r_agraph_reset (core->graph); + rz_agraph_reset (core->graph); break; case 'n': // "agn" cmd_agraph_node (core, input + 1); @@ -8668,10 +8668,10 @@ static void cmd_anal_graph(RCore *core, const char *input) { cmd_agraph_edge (core, input + 1); break; case 'g': // "agg" - r_core_agraph_print (core, -1, input + 1); + rz_core_agraph_print (core, -1, input + 1); break; case 's': // "ags" - r_core_anal_graph (core, r_num_math (core->num, input + 1), 0); + rz_core_anal_graph (core, rz_num_math (core->num, input + 1), 0); break; case 'C': // "agC" switch (input[1]) { @@ -8682,23 +8682,23 @@ static void cmd_anal_graph(RCore *core, const char *input) { case ' ': case 0: { core->graph->is_callgraph = true; - r_core_cmdf (core, "ag-; .agC*;"); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agC*;"); + rz_core_agraph_print(core, -1, input + 1); core->graph->is_callgraph = false; break; } case 'J': case 'j': - r_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_JSON); + rz_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_JSON); break; case 'g': - r_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_GML); + rz_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_GML); break; case 'd': - r_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_DOT); + rz_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_DOT); break; case '*': - r_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_CMD); + rz_core_anal_callgraph (core, UT64_MAX, R_GRAPH_FORMAT_CMD); break; default: eprintf ("Usage: see ag?\n"); @@ -8708,13 +8708,13 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'r': // "agr" references graph switch (input[1]) { case '*': { - r_core_anal_coderefs (core, core->offset); + rz_core_anal_coderefs (core, core->offset); } break; default: { core->graph->is_callgraph = true; - r_core_cmdf (core, "ag-; .agr* @ %"PFMT64u";", core->offset); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agr* @ %"PFMT64u";", core->offset); + rz_core_agraph_print(core, -1, input + 1); core->graph->is_callgraph = false; break; } @@ -8723,21 +8723,21 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'R': // "agR" global refs switch (input[1]) { case '*': { - ut64 from = r_config_get_i (core->config, "graph.from"); - ut64 to = r_config_get_i (core->config, "graph.to"); - RListIter *it; - RAnalFunction *fcn; - r_list_foreach (core->anal->fcns, it, fcn) { + ut64 from = rz_config_get_i (core->config, "graph.from"); + ut64 to = rz_config_get_i (core->config, "graph.to"); + RzListIter *it; + RzAnalFunction *fcn; + rz_list_foreach (core->anal->fcns, it, fcn) { if ((from == UT64_MAX && to == UT64_MAX) || R_BETWEEN (from, fcn->addr, to)) { - r_core_anal_coderefs (core, fcn->addr); + rz_core_anal_coderefs (core, fcn->addr); } } break; } default: { core->graph->is_callgraph = true; - r_core_cmdf (core, "ag-; .agR*;"); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agR*;"); + rz_core_agraph_print(core, -1, input + 1); core->graph->is_callgraph = false; break; } @@ -8746,12 +8746,12 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'x': // "agx" cross refs switch (input[1]) { case '*': { - r_core_anal_codexrefs (core, core->offset); + rz_core_anal_codexrefs (core, core->offset); } break; default: { - r_core_cmdf (core, "ag-; .agx* @ %"PFMT64u";", core->offset); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agx* @ %"PFMT64u";", core->offset); + rz_core_agraph_print(core, -1, input + 1); break; } } @@ -8759,11 +8759,11 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'i': // "agi" import graph switch (input[1]) { case '*': - r_core_anal_importxrefs (core); + rz_core_anal_importxrefs (core); break; default: - r_core_cmdf (core, "ag-; .agi*;"); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agi*;"); + rz_core_agraph_print(core, -1, input + 1); break; } break; @@ -8775,30 +8775,30 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'w': case ' ': { core->graph->is_callgraph = true; - r_core_cmdf (core, "ag-; .agc* @ %"PFMT64u"; agg%s;", core->offset, input + 1); + rz_core_cmdf (core, "ag-; .agc* @ %"PFMT64u"; agg%s;", core->offset, input + 1); core->graph->is_callgraph = false; break; } case 0: core->graph->is_callgraph = true; - r_core_cmd0 (core, "ag-; .agc* $$; agg;"); + rz_core_cmd0 (core, "ag-; .agc* $$; agg;"); core->graph->is_callgraph = false; break; case 'g': { - r_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_GMLFCN); + rz_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_GMLFCN); break; } case 'd': { - r_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_DOT); + rz_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_DOT); break; } case 'J': case 'j': { - r_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_JSON); + rz_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_JSON); break; } case '*': { - r_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_CMD); + rz_core_anal_callgraph (core, core->offset, R_GRAPH_FORMAT_CMD); break; } default: @@ -8807,46 +8807,46 @@ static void cmd_anal_graph(RCore *core, const char *input) { } break; case 'j': // "agj" alias for agfj - r_core_cmdf (core, "agfj%s", input + 1); + rz_core_cmdf (core, "agfj%s", input + 1); break; case 'J': // "agJ" alias for agfJ - r_core_cmdf (core, "agfJ%s", input + 1); + rz_core_cmdf (core, "agfJ%s", input + 1); break; case 'k': // "agk" alias for agfk - r_core_cmdf (core, "agfk%s", input + 1); + rz_core_cmdf (core, "agfk%s", input + 1); break; case 'l': // "agl" - r_core_anal_graph (core, r_num_math (core->num, input + 1), R_CORE_ANAL_GRAPHLINES); + rz_core_anal_graph (core, rz_num_math (core->num, input + 1), R_CORE_ANAL_GRAPHLINES); break; case 'a': // "aga" switch (input[1]) { case '*': { - r_core_anal_datarefs (core, core->offset); + rz_core_anal_datarefs (core, core->offset); break; } default: - r_core_cmdf (core, "ag-; .aga* @ %"PFMT64u";", core->offset); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .aga* @ %"PFMT64u";", core->offset); + rz_core_agraph_print(core, -1, input + 1); break; } break; case 'A': // "agA" global data refs switch (input[1]) { case '*': { - ut64 from = r_config_get_i (core->config, "graph.from"); - ut64 to = r_config_get_i (core->config, "graph.to"); - RListIter *it; - RAnalFunction *fcn; - r_list_foreach (core->anal->fcns, it, fcn) { + ut64 from = rz_config_get_i (core->config, "graph.from"); + ut64 to = rz_config_get_i (core->config, "graph.to"); + RzListIter *it; + RzAnalFunction *fcn; + rz_list_foreach (core->anal->fcns, it, fcn) { if ((from == UT64_MAX && to == UT64_MAX) || R_BETWEEN (from, fcn->addr, to)) { - r_core_anal_datarefs (core, fcn->addr); + rz_core_anal_datarefs (core, fcn->addr); } } break; } default: - r_core_cmdf (core, "ag-; .agA*;"); - r_core_agraph_print(core, -1, input + 1); + rz_core_cmdf (core, "ag-; .agA*;"); + rz_core_agraph_print(core, -1, input + 1); break; } break; @@ -8854,21 +8854,21 @@ static void cmd_anal_graph(RCore *core, const char *input) { int diff_opt = R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF; switch (input[1]) { case 'j': { - ut64 addr = input[2] ? r_num_math (core->num, input + 2) : core->offset; - r_core_gdiff_fcn (core, addr, core->offset); - r_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_JSON); + ut64 addr = input[2] ? rz_num_math (core->num, input + 2) : core->offset; + rz_core_gdiff_fcn (core, addr, core->offset); + rz_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_JSON); break; } case 'J': { - ut64 addr = input[2] ? r_num_math (core->num, input + 2) : core->offset; - r_core_gdiff_fcn (core, addr, core->offset); - r_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); + ut64 addr = input[2] ? rz_num_math (core->num, input + 2) : core->offset; + rz_core_gdiff_fcn (core, addr, core->offset); + rz_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); break; } case '*': { - ut64 addr = input[2] ? r_num_math (core->num, input + 2) : core->offset; - r_core_gdiff_fcn (core, addr, core->offset); - r_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_STAR); + ut64 addr = input[2] ? rz_num_math (core->num, input + 2) : core->offset; + rz_core_gdiff_fcn (core, addr, core->offset); + rz_core_anal_graph (core, addr, diff_opt | R_CORE_ANAL_STAR); break; } case ' ': @@ -8877,21 +8877,21 @@ static void cmd_anal_graph(RCore *core, const char *input) { case 'k': case 'v': case 'g': { - ut64 addr = input[2] ? r_num_math (core->num, input + 2) : core->offset; - r_core_cmdf (core, "ag-; .agd* @ %"PFMT64u"; agg%s;", addr, input + 1); + ut64 addr = input[2] ? rz_num_math (core->num, input + 2) : core->offset; + rz_core_cmdf (core, "ag-; .agd* @ %"PFMT64u"; agg%s;", addr, input + 1); break; } case 'd': { - ut64 addr = input[2] ? r_num_math (core->num, input + 2) : core->offset; - r_core_gdiff_fcn (core, addr, core->offset); - r_core_anal_graph (core, addr, diff_opt); + ut64 addr = input[2] ? rz_num_math (core->num, input + 2) : core->offset; + rz_core_gdiff_fcn (core, addr, core->offset); + rz_core_anal_graph (core, addr, diff_opt); break; } case 'w': { - char *cmdargs = r_str_newf ("agdd 0x%"PFMT64x, core->offset); + char *cmdargs = rz_str_newf ("agdd 0x%"PFMT64x, core->offset); char *cmd = graph_cmd (core, cmdargs, input + 2); if (cmd && *cmd) { - r_core_cmd0(core, cmd); + rz_core_cmd0(core, cmd); } free(cmd); free(cmdargs); @@ -8901,37 +8901,37 @@ static void cmd_anal_graph(RCore *core, const char *input) { break; } case 'v': // "agv" alias for "agfv" - r_core_cmdf (core, "agfv%s", input + 1); + rz_core_cmdf (core, "agfv%s", input + 1); break; case 'w':// "agw" - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "=H /graph/"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "=H /graph/"); } else { - char *cmdargs = r_str_newf ("agfd @ 0x%"PFMT64x, core->offset); + char *cmdargs = rz_str_newf ("agfd @ 0x%"PFMT64x, core->offset); char *cmd = graph_cmd (core, cmdargs, input + 1); if (cmd && *cmd) { if (input[1]) { - r_cons_printf ("Saving to file %s ...\n", input + 1); - r_cons_flush (); + rz_cons_printf ("Saving to file %s ...\n", input + 1); + rz_cons_flush (); } - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } free (cmd); free (cmdargs); } break; default: - r_core_cmd_help (core, help_msg_ag); + rz_core_cmd_help (core, help_msg_ag); break; } } -R_API int r_core_anal_refs(RCore *core, const char *input) { - int cfg_debug = r_config_get_i (core->config, "cfg.debug"); +RZ_API int rz_core_anal_refs(RzCore *core, const char *input) { + int cfg_debug = rz_config_get_i (core->config, "cfg.debug"); ut64 from, to; int rad; if (*input == '?') { - r_core_cmd_help (core, help_msg_aar); + rz_core_cmd_help (core, help_msg_aar); return 0; } @@ -8943,31 +8943,31 @@ R_API int r_core_anal_refs(RCore *core, const char *input) { } from = to = 0; - char *ptr = r_str_trim_dup (input); - int n = r_str_word_set0 (ptr); + char *ptr = rz_str_trim_dup (input); + int n = rz_str_word_set0 (ptr); if (!n) { // get boundaries of current memory map, section or io map if (cfg_debug) { - RDebugMap *map = r_debug_map_get (core->dbg, core->offset); + RzDebugMap *map = rz_debug_map_get (core->dbg, core->offset); if (map) { from = map->addr; to = map->addr_end; } } else { - RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); - RListIter *iter; - RIOMap* map; + RzList *list = rz_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); + RzListIter *iter; + RzIOMap* map; if (!list) { return 0; } if (rad == 'j') { - r_cons_printf ("{"); + rz_cons_printf ("{"); } int nth = 0; - r_list_foreach (list, iter, map) { + rz_list_foreach (list, iter, map) { from = map->itv.addr; - to = r_itv_end (map->itv); - if (r_cons_is_breaked ()) { + to = rz_itv_end (map->itv); + if (rz_cons_is_breaked ()) { break; } if (!from && !to) { @@ -8976,25 +8976,25 @@ R_API int r_core_anal_refs(RCore *core, const char *input) { eprintf ("Skipping huge range\n"); } else { if (rad == 'j') { - r_cons_printf ("%s\"mapid\":\"%d\",\"refs\":{", nth? ",": "", map->id); + rz_cons_printf ("%s\"mapid\":\"%d\",\"refs\":{", nth? ",": "", map->id); } - r_core_anal_search_xrefs (core, from, to, rad); + rz_core_anal_search_xrefs (core, from, to, rad); if (rad == 'j') { - r_cons_printf ("}"); + rz_cons_printf ("}"); } nth++; } } if (rad == 'j') { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } free (ptr); - r_list_free (list); + rz_list_free (list); return 1; } } else if (n == 1) { from = core->offset; - to = core->offset + r_num_math (core->num, r_str_word_get0 (ptr, 0)); + to = core->offset + rz_num_math (core->num, rz_str_word_get0 (ptr, 0)); } else { eprintf ("Invalid number of arguments\n"); } @@ -9006,33 +9006,33 @@ R_API int r_core_anal_refs(RCore *core, const char *input) { if (!from && !to) { return false; } - if (to - from > r_io_size (core->io)) { + if (to - from > rz_io_size (core->io)) { return false; } if (rad == 'j') { - r_cons_printf ("{"); + rz_cons_printf ("{"); } - bool res = r_core_anal_search_xrefs (core, from, to, rad); + bool res = rz_core_anal_search_xrefs (core, from, to, rad); if (rad == 'j') { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } return res; } static const char *oldstr = NULL; -static int compute_coverage(RCore *core) { - RListIter *iter; - RAnalFunction *fcn; +static int compute_coverage(RzCore *core) { + RzListIter *iter; + RzAnalFunction *fcn; int cov = 0; - cov += r_meta_get_size(core->anal, R_META_TYPE_DATA); - r_list_foreach (core->anal->fcns, iter, fcn) { + cov += rz_meta_get_size(core->anal, R_META_TYPE_DATA); + rz_list_foreach (core->anal->fcns, iter, fcn) { void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; if (map->perm & R_PERM_X) { ut64 section_end = map->itv.addr + map->itv.size; - ut64 s = r_anal_function_realsize (fcn); + ut64 s = rz_anal_function_realsize (fcn); if (fcn->addr >= map->itv.addr && (fcn->addr + s) < section_end) { cov += s; } @@ -9042,11 +9042,11 @@ static int compute_coverage(RCore *core) { return cov; } -static int compute_code (RCore* core) { +static int compute_code (RzCore* core) { int code = 0; void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; if (map->perm & R_PERM_X) { code += map->itv.size; } @@ -9054,31 +9054,31 @@ static int compute_code (RCore* core) { return code; } -static int compute_calls(RCore *core) { - RListIter *iter; - RAnalFunction *fcn; - RList *xrefs; +static int compute_calls(RzCore *core) { + RzListIter *iter; + RzAnalFunction *fcn; + RzList *xrefs; int cov = 0; - r_list_foreach (core->anal->fcns, iter, fcn) { - xrefs = r_anal_function_get_xrefs (fcn); + rz_list_foreach (core->anal->fcns, iter, fcn) { + xrefs = rz_anal_function_get_xrefs (fcn); if (xrefs) { - cov += r_list_length (xrefs); - r_list_free (xrefs); + cov += rz_list_length (xrefs); + rz_list_free (xrefs); xrefs = NULL; } } return cov; } -static void r_core_anal_info (RCore *core, const char *input) { - int fcns = r_list_length (core->anal->fcns); - int strs = r_flag_count (core->flags, "str.*"); - int syms = r_flag_count (core->flags, "sym.*"); - int imps = r_flag_count (core->flags, "sym.imp.*"); +static void rz_core_anal_info (RzCore *core, const char *input) { + int fcns = rz_list_length (core->anal->fcns); + int strs = rz_flag_count (core->flags, "str.*"); + int syms = rz_flag_count (core->flags, "sym.*"); + int imps = rz_flag_count (core->flags, "sym.imp.*"); int code = compute_code (core); int covr = compute_coverage (core); int call = compute_calls (core); - int xrfs = r_anal_xrefs_count (core->anal); + int xrfs = rz_anal_xrefs_count (core->anal); int cvpc = (code > 0)? (covr * 100.0 / code): 0; if (*input == 'j') { PJ *pj = pj_new (); @@ -9096,47 +9096,47 @@ static void r_core_anal_info (RCore *core, const char *input) { pj_ki (pj, "codesz", code); pj_ki (pj, "percent", cvpc); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else { - r_cons_printf ("fcns %d\n", fcns); - r_cons_printf ("xrefs %d\n", xrfs); - r_cons_printf ("calls %d\n", call); - r_cons_printf ("strings %d\n", strs); - r_cons_printf ("symbols %d\n", syms); - r_cons_printf ("imports %d\n", imps); - r_cons_printf ("covrage %d\n", covr); - r_cons_printf ("codesz %d\n", code); - r_cons_printf ("percent %d%%\n", cvpc); + rz_cons_printf ("fcns %d\n", fcns); + rz_cons_printf ("xrefs %d\n", xrfs); + rz_cons_printf ("calls %d\n", call); + rz_cons_printf ("strings %d\n", strs); + rz_cons_printf ("symbols %d\n", syms); + rz_cons_printf ("imports %d\n", imps); + rz_cons_printf ("covrage %d\n", covr); + rz_cons_printf ("codesz %d\n", code); + rz_cons_printf ("percent %d%%\n", cvpc); } } -static void cmd_anal_aad(RCore *core, const char *input) { - RListIter *iter; - RAnalRef *ref; - RList *list = r_list_newf (NULL); - r_anal_xrefs_from (core->anal, list, "xref", R_ANAL_REF_TYPE_DATA, UT64_MAX); - r_list_foreach (list, iter, ref) { - if (r_io_is_valid_offset (core->io, ref->addr, false)) { - r_core_anal_fcn (core, ref->at, ref->addr, R_ANAL_REF_TYPE_NULL, 1); +static void cmd_anal_aad(RzCore *core, const char *input) { + RzListIter *iter; + RzAnalRef *ref; + RzList *list = rz_list_newf (NULL); + rz_anal_xrefs_from (core->anal, list, "xref", R_ANAL_REF_TYPE_DATA, UT64_MAX); + rz_list_foreach (list, iter, ref) { + if (rz_io_is_valid_offset (core->io, ref->addr, false)) { + rz_core_anal_fcn (core, ref->at, ref->addr, R_ANAL_REF_TYPE_NULL, 1); } } - r_list_free (list); + rz_list_free (list); } -static bool archIsThumbable(RCore *core) { - RAsm *as = core ? core->rasm : NULL; +static bool archIsThumbable(RzCore *core) { + RzAsm *as = core ? core->rasm : NULL; if (as && as->cur && as->bits <= 32 && as->cur->name) { return strstr (as->cur->name, "arm"); } return false; } -static void _CbInRangeAav(RCore *core, ut64 from, ut64 to, int vsize, int count, void *user) { +static void _CbInRangeAav(RzCore *core, ut64 from, ut64 to, int vsize, int count, void *user) { bool asterisk = user != NULL; - int arch_align = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); - bool vinfun = r_config_get_i (core->config, "anal.vinfun"); - int searchAlign = r_config_get_i (core->config, "search.align"); + int arch_align = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); + bool vinfun = rz_config_get_i (core->config, "anal.vinfun"); + int searchAlign = rz_config_get_i (core->config, "search.align"); int align = (searchAlign > 0)? searchAlign: arch_align; if (align > 1) { if ((from % align) || (to % align)) { @@ -9155,41 +9155,41 @@ static void _CbInRangeAav(RCore *core, ut64 from, ut64 to, int vsize, int count, } } if (!vinfun) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, from, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, from, -1); if (fcn) { return; } } if (asterisk) { - r_cons_printf ("ax 0x%"PFMT64x " 0x%"PFMT64x "\n", to, from); - r_cons_printf ("Cd %d @ 0x%"PFMT64x "\n", vsize, from); - r_cons_printf ("f+ aav.0x%08"PFMT64x "= 0x%08"PFMT64x, to, to); + rz_cons_printf ("ax 0x%"PFMT64x " 0x%"PFMT64x "\n", to, from); + rz_cons_printf ("Cd %d @ 0x%"PFMT64x "\n", vsize, from); + rz_cons_printf ("f+ aav.0x%08"PFMT64x "= 0x%08"PFMT64x, to, to); } else { - r_anal_xrefs_set (core->anal, from, to, R_ANAL_REF_TYPE_NULL); - // r_meta_set (core->anal, 'd', from, from + vsize, NULL); - r_core_cmdf (core, "Cd %d @ 0x%"PFMT64x "\n", vsize, from); - if (!r_flag_get_at (core->flags, to, false)) { - char *name = r_str_newf ("aav.0x%08"PFMT64x, to); - r_flag_set (core->flags, name, to, vsize); + rz_anal_xrefs_set (core->anal, from, to, R_ANAL_REF_TYPE_NULL); + // rz_meta_set (core->anal, 'd', from, from + vsize, NULL); + rz_core_cmdf (core, "Cd %d @ 0x%"PFMT64x "\n", vsize, from); + if (!rz_flag_get_at (core->flags, to, false)) { + char *name = rz_str_newf ("aav.0x%08"PFMT64x, to); + rz_flag_set (core->flags, name, to, vsize); free (name); } } } -static void cmd_anal_aav(RCore *core, const char *input) { -#define seti(x,y) r_config_set_i(core->config, x, y); -#define geti(x) r_config_get_i(core->config, x); - r_return_if_fail (*input == 'v'); +static void cmd_anal_aav(RzCore *core, const char *input) { +#define seti(x,y) rz_config_set_i(core->config, x, y); +#define geti(x) rz_config_get_i(core->config, x); + rz_return_if_fail (*input == 'v'); ut64 o_align = geti ("search.align"); - const char *analin = r_config_get (core->config, "anal.in"); + const char *analin = rz_config_get (core->config, "anal.in"); char *tmp = strdup (analin); bool asterisk = strchr (input, '*'); - bool is_debug = r_config_get_i (core->config, "cfg.debug"); - int archAlign = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); + bool is_debug = rz_config_get_i (core->config, "cfg.debug"); + int archAlign = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_ALIGN); seti ("search.align", archAlign); - r_config_set (core->config, "anal.in", "io.maps.x"); - oldstr = r_print_rowlog (core->print, "Finding xrefs in noncode section with anal.in=io.maps"); - r_print_rowlog_done (core->print, oldstr); + rz_config_set (core->config, "anal.in", "io.maps.x"); + oldstr = rz_print_rowlog (core->print, "Finding xrefs in noncode section with anal.in=io.maps"); + rz_print_rowlog_done (core->print, oldstr); int vsize = 4; // 32bit dword if (core->rasm->bits == 64) { @@ -9197,76 +9197,76 @@ static void cmd_anal_aav(RCore *core, const char *input) { } // body - oldstr = r_print_rowlog (core->print, "Analyze value pointers (aav)"); - r_print_rowlog_done (core->print, oldstr); - r_cons_break_push (NULL, NULL); + oldstr = rz_print_rowlog (core->print, "Analyze value pointers (aav)"); + rz_print_rowlog_done (core->print, oldstr); + rz_cons_break_push (NULL, NULL); if (is_debug) { - RList *list = r_core_get_boundaries_prot (core, 0, "dbg.map", "anal"); - RListIter *iter; - RIOMap *map; + RzList *list = rz_core_get_boundaries_prot (core, 0, "dbg.map", "anal"); + RzListIter *iter; + RzIOMap *map; if (!list) { goto beach; } - r_list_foreach (list, iter, map) { - if (r_cons_is_breaked ()) { + rz_list_foreach (list, iter, map) { + if (rz_cons_is_breaked ()) { break; } - oldstr = r_print_rowlog (core->print, sdb_fmt ("from 0x%"PFMT64x" to 0x%"PFMT64x" (aav)", map->itv.addr, r_itv_end (map->itv))); - r_print_rowlog_done (core->print, oldstr); - (void)r_core_search_value_in_range (core, map->itv, - map->itv.addr, r_itv_end (map->itv), vsize, _CbInRangeAav, (void *)asterisk); + oldstr = rz_print_rowlog (core->print, sdb_fmt ("from 0x%"PFMT64x" to 0x%"PFMT64x" (aav)", map->itv.addr, rz_itv_end (map->itv))); + rz_print_rowlog_done (core->print, oldstr); + (void)rz_core_search_value_in_range (core, map->itv, + map->itv.addr, rz_itv_end (map->itv), vsize, _CbInRangeAav, (void *)asterisk); } - r_list_free (list); + rz_list_free (list); } else { - RList *list = r_core_get_boundaries_prot (core, 0, NULL, "anal"); + RzList *list = rz_core_get_boundaries_prot (core, 0, NULL, "anal"); if (!list) { goto beach; } - RListIter *iter, *iter2; - RIOMap *map, *map2; + RzListIter *iter, *iter2; + RzIOMap *map, *map2; ut64 from = UT64_MAX; ut64 to = UT64_MAX; // find values pointing to non-executable regions - r_list_foreach (list, iter2, map2) { - if (r_cons_is_breaked ()) { + rz_list_foreach (list, iter2, map2) { + if (rz_cons_is_breaked ()) { break; } //TODO: Reduce multiple hits for same addr - from = r_itv_begin (map2->itv); - to = r_itv_end (map2->itv); - oldstr = r_print_rowlog (core->print, sdb_fmt ("Value from 0x%08"PFMT64x " to 0x%08" PFMT64x " (aav)", from, to)); + from = rz_itv_begin (map2->itv); + to = rz_itv_end (map2->itv); + oldstr = rz_print_rowlog (core->print, sdb_fmt ("Value from 0x%08"PFMT64x " to 0x%08" PFMT64x " (aav)", from, to)); if ((to - from) > MAX_SCAN_SIZE) { eprintf ("Warning: Skipping large region\n"); continue; } - r_print_rowlog_done (core->print, oldstr); - r_list_foreach (list, iter, map) { + rz_print_rowlog_done (core->print, oldstr); + rz_list_foreach (list, iter, map) { ut64 begin = map->itv.addr; - ut64 end = r_itv_end (map->itv); - if (r_cons_is_breaked ()) { + ut64 end = rz_itv_end (map->itv); + if (rz_cons_is_breaked ()) { break; } if (end - begin > UT32_MAX) { - oldstr = r_print_rowlog (core->print, "Skipping huge range"); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Skipping huge range"); + rz_print_rowlog_done (core->print, oldstr); continue; } - oldstr = r_print_rowlog (core->print, sdb_fmt ("0x%08"PFMT64x"-0x%08"PFMT64x" in 0x%"PFMT64x"-0x%"PFMT64x" (aav)", from, to, begin, end)); - r_print_rowlog_done (core->print, oldstr); - (void)r_core_search_value_in_range (core, map->itv, from, to, vsize, _CbInRangeAav, (void *)asterisk); + oldstr = rz_print_rowlog (core->print, sdb_fmt ("0x%08"PFMT64x"-0x%08"PFMT64x" in 0x%"PFMT64x"-0x%"PFMT64x" (aav)", from, to, begin, end)); + rz_print_rowlog_done (core->print, oldstr); + (void)rz_core_search_value_in_range (core, map->itv, from, to, vsize, _CbInRangeAav, (void *)asterisk); } } - r_list_free (list); + rz_list_free (list); } beach: - r_cons_break_pop (); + rz_cons_break_pop (); // end - r_config_set (core->config, "anal.in", tmp); + rz_config_set (core->config, "anal.in", tmp); free (tmp); seti ("search.align", o_align); } -static void cmd_anal_abt(RCore *core, const char *input) { +static void cmd_anal_abt(RzCore *core, const char *input) { switch (*input) { case 'e': { @@ -9276,141 +9276,141 @@ static void cmd_anal_abt(RCore *core, const char *input) { eprintf ("Usage: abte [addr] # emulate from beginning of function to the given address.\n"); return; } - ut64 addr = r_num_math (core->num, p + 1); - RList *paths = r_core_anal_graph_to (core, addr, n); + ut64 addr = rz_num_math (core->num, p + 1); + RzList *paths = rz_core_anal_graph_to (core, addr, n); if (paths) { - RAnalBlock *bb; - RList *path; - RListIter *pathi; - RListIter *bbi; - r_cons_printf ("f orip=`dr?PC`\n"); - r_list_foreach (paths, pathi, path) { - r_list_foreach (path, bbi, bb) { - r_cons_printf ("# 0x%08" PFMT64x "\n", bb->addr); + RzAnalBlock *bb; + RzList *path; + RzListIter *pathi; + RzListIter *bbi; + rz_cons_printf ("f orip=`dr?PC`\n"); + rz_list_foreach (paths, pathi, path) { + rz_list_foreach (path, bbi, bb) { + rz_cons_printf ("# 0x%08" PFMT64x "\n", bb->addr); if (addr >= bb->addr && addr < bb->addr + bb->size) { - r_cons_printf ("aepc 0x%08"PFMT64x"\n", bb->addr); - r_cons_printf ("aesou 0x%08"PFMT64x"\n", addr); + rz_cons_printf ("aepc 0x%08"PFMT64x"\n", bb->addr); + rz_cons_printf ("aesou 0x%08"PFMT64x"\n", addr); } else { - r_cons_printf ("aepc 0x%08"PFMT64x"\n", bb->addr); - r_cons_printf ("aesou 0x%08"PFMT64x"\n", bb->addr + bb->size); + rz_cons_printf ("aepc 0x%08"PFMT64x"\n", bb->addr); + rz_cons_printf ("aesou 0x%08"PFMT64x"\n", bb->addr + bb->size); } } - r_cons_newline (); - r_list_purge (path); + rz_cons_newline (); + rz_list_purge (path); free (path); } - r_list_purge (paths); - r_cons_printf ("aepc orip\n"); + rz_list_purge (paths); + rz_cons_printf ("aepc orip\n"); free (paths); } } break; case '?': - r_core_cmd_help (core, help_msg_abt); + rz_core_cmd_help (core, help_msg_abt); break; case 'j': { - ut64 addr = r_num_math (core->num, input + 1); - RAnalBlock *block = r_anal_get_block_at (core->anal, core->offset); + ut64 addr = rz_num_math (core->num, input + 1); + RzAnalBlock *block = rz_anal_get_block_at (core->anal, core->offset); if (!block) { break; } - RList *path = r_anal_block_shortest_path (block, addr); + RzList *path = rz_anal_block_shortest_path (block, addr); PJ *pj = pj_new (); if (pj) { pj_a (pj); if (path) { - RListIter *it; - r_list_foreach (path, it, block) { + RzListIter *it; + rz_list_foreach (path, it, block) { pj_n (pj, block->addr); } } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } - r_list_free (path); + rz_list_free (path); break; } case ' ': { - ut64 addr = r_num_math (core->num, input + 1); - RAnalBlock *block = r_anal_get_block_at (core->anal, core->offset); + ut64 addr = rz_num_math (core->num, input + 1); + RzAnalBlock *block = rz_anal_get_block_at (core->anal, core->offset); if (!block) { break; } - RList *path = r_anal_block_shortest_path (block, addr); + RzList *path = rz_anal_block_shortest_path (block, addr); if (path) { - RListIter *it; - r_list_foreach (path, it, block) { - r_cons_printf ("0x%08" PFMT64x "\n", block->addr); + RzListIter *it; + rz_list_foreach (path, it, block) { + rz_cons_printf ("0x%08" PFMT64x "\n", block->addr); } - r_list_free (path); + rz_list_free (path); } break; } case '\0': - r_core_cmdf (core, "abl, addr/eq/0x%08"PFMT64x, core->offset); + rz_core_cmdf (core, "abl, addr/eq/0x%08"PFMT64x, core->offset); break; } } -static bool is_unknown_file(RCore *core) { +static bool is_unknown_file(RzCore *core) { if (core->bin->cur && core->bin->cur->o) { - return (r_list_empty (core->bin->cur->o->sections)); + return (rz_list_empty (core->bin->cur->o->sections)); } return true; } -static bool is_apple_target(RCore *core) { - const char *arch = r_config_get (core->config, "asm.arch"); +static bool is_apple_target(RzCore *core) { + const char *arch = rz_config_get (core->config, "asm.arch"); if (!strstr (arch, "ppc") && !strstr (arch, "arm") && !strstr (arch, "x86")) { return false; } - RBinObject *bo = r_bin_cur_object (core->bin); - r_return_val_if_fail (!bo || (bo->plugin && bo->plugin->name), false); + RBinObject *bo = rz_bin_cur_object (core->bin); + rz_return_val_if_fail (!bo || (bo->plugin && bo->plugin->name), false); return bo? strstr (bo->plugin->name, "mach"): false; } -static int cmd_anal_all(RCore *core, const char *input) { +static int cmd_anal_all(RzCore *core, const char *input) { switch (*input) { case '?': - r_core_cmd_help (core, help_msg_aa); + rz_core_cmd_help (core, help_msg_aa); break; case 'b': // "aab" cmd_anal_blocks (core, input + 1); break; case 'f': if (input[1] == 'e') { // "aafe" - r_core_cmd0 (core, "aef@@f"); + rz_core_cmd0 (core, "aef@@f"); } else if (input[1] == 'r') { ut64 cur = core->offset; - bool hasnext = r_config_get_i (core->config, "anal.hasnext"); - RListIter *iter; - RIOMap *map; - RList *list = r_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); + bool hasnext = rz_config_get_i (core->config, "anal.hasnext"); + RzListIter *iter; + RzIOMap *map; + RzList *list = rz_core_get_boundaries_prot (core, R_PERM_X, NULL, "anal"); if (!list) { break; } - r_list_foreach (list, iter, map) { - r_core_seek (core, map->itv.addr, true); - r_config_set_i (core->config, "anal.hasnext", 1); - r_core_cmd0 (core, "afr"); - r_config_set_i (core->config, "anal.hasnext", hasnext); + rz_list_foreach (list, iter, map) { + rz_core_seek (core, map->itv.addr, true); + rz_config_set_i (core->config, "anal.hasnext", 1); + rz_core_cmd0 (core, "afr"); + rz_config_set_i (core->config, "anal.hasnext", hasnext); } - r_list_free (list); - r_core_seek (core, cur, true); + rz_list_free (list); + rz_core_seek (core, cur, true); } else if (input[1] == 't') { // "aaft" cmd_anal_aaft (core); } else if (input[1] == 0) { // "aaf" - const bool analHasnext = r_config_get_i (core->config, "anal.hasnext"); - r_config_set_i (core->config, "anal.hasnext", true); - r_core_cmd0 (core, "afr@@c:isq"); - r_config_set_i (core->config, "anal.hasnext", analHasnext); + const bool analHasnext = rz_config_get_i (core->config, "anal.hasnext"); + rz_config_set_i (core->config, "anal.hasnext", true); + rz_core_cmd0 (core, "afr@@c:isq"); + rz_config_set_i (core->config, "anal.hasnext", analHasnext); } else { - r_cons_printf ("Usage: aaf[e|r|t] - analyze all functions again\n"); - r_cons_printf (" aafe = aef@@f\n"); - r_cons_printf ("aafr [len] = analyze all consecutive functions in section\n"); - r_cons_printf (" aaft = recursive type matching in all functions\n"); - r_cons_printf (" aaf = afr@@c:isq\n"); + rz_cons_printf ("Usage: aaf[e|r|t] - analyze all functions again\n"); + rz_cons_printf (" aafe = aef@@f\n"); + rz_cons_printf ("aafr [len] = analyze all consecutive functions in section\n"); + rz_cons_printf (" aaft = recursive type matching in all functions\n"); + rz_cons_printf (" aaf = afr@@c:isq\n"); } break; case 'c': // "aac" @@ -9438,22 +9438,22 @@ static int cmd_anal_all(RCore *core, const char *input) { cmd_anal_aav (core, input); break; case 'u': // "aau" - print areas not covered by functions - r_core_anal_nofunclist (core, input + 1); + rz_core_anal_nofunclist (core, input + 1); break; case 'i': // "aai" - r_core_anal_info (core, input + 1); + rz_core_anal_info (core, input + 1); break; case 's': // "aas" - r_core_cmd0 (core, "af @@= `isq~[0]`"); - r_core_cmd0 (core, "af @@ entry*"); + rz_core_cmd0 (core, "af @@= `isq~[0]`"); + rz_core_cmd0 (core, "af @@ entry*"); break; case 'S': // "aaS" - r_core_cmd0 (core, "af @@ sym.*"); - r_core_cmd0 (core, "af @@ entry*"); + rz_core_cmd0 (core, "af @@ sym.*"); + rz_core_cmd0 (core, "af @@ entry*"); break; case 'F': // "aaF" "aaFa" if (!input[1] || input[1] == ' ' || input[1] == 'a') { - r_core_anal_inflags (core, input + 1); + rz_core_anal_inflags (core, input + 1); } else { eprintf ("Usage: aaF[a] - analyze functions in flag bounds (aaFa uses af/a2f instead of af+/afb+)\n"); } @@ -9461,10 +9461,10 @@ static int cmd_anal_all(RCore *core, const char *input) { case 'n': // "aan" switch (input[1]) { case 'r': // "aanr" // all noreturn propagation - r_core_anal_propagate_noreturn (core, UT64_MAX); + rz_core_anal_propagate_noreturn (core, UT64_MAX); break; case 'g': // "aang" - r_core_anal_autoname_all_golang_fcns (core); + rz_core_anal_autoname_all_golang_fcns (core); break; case '?': eprintf ("Usage: aan[rg]\n"); @@ -9473,7 +9473,7 @@ static int cmd_anal_all(RCore *core, const char *input) { eprintf ("aanr : auto-noreturn propagation\n"); break; default: // "aan" - r_core_anal_autoname_all_fcns (core); + rz_core_anal_autoname_all_fcns (core); } break; case 'p': // "aap" @@ -9481,30 +9481,30 @@ static int cmd_anal_all(RCore *core, const char *input) { // TODO: accept parameters for ranges eprintf ("Usage: /aap ; find in memory for function preludes"); } else { - r_core_search_preludes (core, true); + rz_core_search_preludes (core, true); } break; case '\0': // "aa" case 'a': if (input[0] && (input[1] == '?' || (input[1] && input[2] == '?'))) { - r_cons_println ("Usage: See aa? for more help"); + rz_cons_println ("Usage: See aa? for more help"); } else { bool didAap = false; char *dh_orig = NULL; if (!strncmp (input, "aaaaa", 5)) { eprintf ("An r2 developer is coming to your place to manually analyze this program. Please wait for it\n"); - if (r_cons_is_interactive ()) { - r_cons_any_key (NULL); + if (rz_cons_is_interactive ()) { + rz_cons_any_key (NULL); } goto jacuzzi; } ut64 curseek = core->offset; - oldstr = r_print_rowlog (core->print, "Analyze all flags starting with sym. and entry0 (aa)"); - r_cons_break_push (NULL, NULL); - r_cons_break_timeout (r_config_get_i (core->config, "anal.timeout")); - r_core_anal_all (core); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Analyze all flags starting with sym. and entry0 (aa)"); + rz_cons_break_push (NULL, NULL); + rz_cons_break_timeout (rz_config_get_i (core->config, "anal.timeout")); + rz_core_anal_all (core); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); // Run pending analysis immediately after analysis // Usefull when running commands with ";" or via r2 -c,-i dh_orig = core->dbg->h @@ -9514,197 +9514,197 @@ static int cmd_anal_all(RCore *core, const char *input) { //use dh_origin if we are debugging R_FREE (dh_orig); } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto jacuzzi; } - r_cons_clear_line (1); - bool cfg_debug = r_config_get_i (core->config, "cfg.debug"); + rz_cons_clear_line (1); + bool cfg_debug = rz_config_get_i (core->config, "cfg.debug"); if (*input == 'a') { // "aaa" - if (r_str_startswith (r_config_get (core->config, "bin.lang"), "go")) { - oldstr = r_print_rowlog (core->print, "Find function and symbol names from golang binaries (aang)"); - r_print_rowlog_done (core->print, oldstr); - r_core_anal_autoname_all_golang_fcns (core); - oldstr = r_print_rowlog (core->print, "Analyze all flags starting with sym.go. (aF @@ sym.go.*)"); - r_core_cmd0 (core, "aF @@ sym.go.*"); - r_print_rowlog_done (core->print, oldstr); + if (rz_str_startswith (rz_config_get (core->config, "bin.lang"), "go")) { + oldstr = rz_print_rowlog (core->print, "Find function and symbol names from golang binaries (aang)"); + rz_print_rowlog_done (core->print, oldstr); + rz_core_anal_autoname_all_golang_fcns (core); + oldstr = rz_print_rowlog (core->print, "Analyze all flags starting with sym.go. (aF @@ sym.go.*)"); + rz_core_cmd0 (core, "aF @@ sym.go.*"); + rz_print_rowlog_done (core->print, oldstr); } - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); if (!cfg_debug) { if (dh_orig && strcmp (dh_orig, "esil")) { - r_core_cmd0 (core, "dL esil"); - r_core_task_yield (&core->tasks); + rz_core_cmd0 (core, "dL esil"); + rz_core_task_yield (&core->tasks); } } - int c = r_config_get_i (core->config, "anal.calls"); - r_config_set_i (core->config, "anal.calls", 1); - r_core_cmd0 (core, "s $S"); - if (r_cons_is_breaked ()) { + int c = rz_config_get_i (core->config, "anal.calls"); + rz_config_set_i (core->config, "anal.calls", 1); + rz_core_cmd0 (core, "s $S"); + if (rz_cons_is_breaked ()) { goto jacuzzi; } - oldstr = r_print_rowlog (core->print, "Analyze function calls (aac)"); + oldstr = rz_print_rowlog (core->print, "Analyze function calls (aac)"); (void)cmd_anal_calls (core, "", false, false); // "aac" - r_core_seek (core, curseek, true); - // oldstr = r_print_rowlog (core->print, "Analyze data refs as code (LEA)"); + rz_core_seek (core, curseek, true); + // oldstr = rz_print_rowlog (core->print, "Analyze data refs as code (LEA)"); // (void) cmd_anal_aad (core, NULL); // "aad" - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); - if (r_cons_is_breaked ()) { + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); + if (rz_cons_is_breaked ()) { goto jacuzzi; } if (is_unknown_file (core)) { - oldstr = r_print_rowlog (core->print, "find and analyze function preludes (aap)"); - (void)r_core_search_preludes (core, false); // "aap" + oldstr = rz_print_rowlog (core->print, "find and analyze function preludes (aap)"); + (void)rz_core_search_preludes (core, false); // "aap" didAap = true; - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); - if (r_cons_is_breaked ()) { + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); + if (rz_cons_is_breaked ()) { goto jacuzzi; } } - oldstr = r_print_rowlog (core->print, "Analyze len bytes of instructions for references (aar)"); - (void)r_core_anal_refs (core, ""); // "aar" - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); - if (r_cons_is_breaked ()) { + oldstr = rz_print_rowlog (core->print, "Analyze len bytes of instructions for references (aar)"); + (void)rz_core_anal_refs (core, ""); // "aar" + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); + if (rz_cons_is_breaked ()) { goto jacuzzi; } if (is_apple_target (core)) { - oldstr = r_print_rowlog (core->print, "Check for objc references"); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Check for objc references"); + rz_print_rowlog_done (core->print, oldstr); cmd_anal_objc (core, input + 1, true); } - r_core_task_yield (&core->tasks); - oldstr = r_print_rowlog (core->print, "Check for vtables"); - r_core_cmd0 (core, "avrr"); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); - r_config_set_i (core->config, "anal.calls", c); - r_core_task_yield (&core->tasks); - if (r_cons_is_breaked ()) { + rz_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Check for vtables"); + rz_core_cmd0 (core, "avrr"); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); + rz_config_set_i (core->config, "anal.calls", c); + rz_core_task_yield (&core->tasks); + if (rz_cons_is_breaked ()) { goto jacuzzi; } - if (!r_str_startswith (r_config_get (core->config, "asm.arch"), "x86")) { - r_core_cmd0 (core, "aav"); - r_core_task_yield (&core->tasks); - bool ioCache = r_config_get_i (core->config, "io.pcache"); - r_config_set_i (core->config, "io.pcache", 1); - oldstr = r_print_rowlog (core->print, "Emulate functions to find computed references (aaef)"); - r_core_cmd0 (core, "aaef"); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + if (!rz_str_startswith (rz_config_get (core->config, "asm.arch"), "x86")) { + rz_core_cmd0 (core, "aav"); + rz_core_task_yield (&core->tasks); + bool ioCache = rz_config_get_i (core->config, "io.pcache"); + rz_config_set_i (core->config, "io.pcache", 1); + oldstr = rz_print_rowlog (core->print, "Emulate functions to find computed references (aaef)"); + rz_core_cmd0 (core, "aaef"); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); if (!ioCache) { - r_core_cmd0 (core, "wc-*"); - r_core_task_yield (&core->tasks); + rz_core_cmd0 (core, "wc-*"); + rz_core_task_yield (&core->tasks); } - r_config_set_i (core->config, "io.pcache", ioCache); - if (r_cons_is_breaked ()) { + rz_config_set_i (core->config, "io.pcache", ioCache); + if (rz_cons_is_breaked ()) { goto jacuzzi; } } - if (r_config_get_i (core->config, "anal.autoname")) { - oldstr = r_print_rowlog (core->print, "Speculatively constructing a function name " + if (rz_config_get_i (core->config, "anal.autoname")) { + oldstr = rz_print_rowlog (core->print, "Speculatively constructing a function name " "for fcn.* and sym.func.* functions (aan)"); - r_core_anal_autoname_all_fcns (core); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + rz_core_anal_autoname_all_fcns (core); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); } if (core->anal->opt.vars) { - RAnalFunction *fcni; - RListIter *iter; - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + RzAnalFunction *fcni; + RzListIter *iter; + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } - RList *list = r_anal_var_list (core->anal, fcni, 'r'); - if (!r_list_empty (list)) { - r_list_free (list); + RzList *list = rz_anal_var_list (core->anal, fcni, 'r'); + if (!rz_list_empty (list)) { + rz_list_free (list); continue; } //extract only reg based var here - r_core_recover_vars (core, fcni, true); - r_list_free (list); + rz_core_recover_vars (core, fcni, true); + rz_list_free (list); } - r_core_task_yield (&core->tasks); + rz_core_task_yield (&core->tasks); } if (!sdb_isempty (core->anal->sdb_zigns)) { - oldstr = r_print_rowlog (core->print, "Check for zignature from zigns folder (z/)"); - r_core_cmd0 (core, "z/"); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Check for zignature from zigns folder (z/)"); + rz_core_cmd0 (core, "z/"); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); } - oldstr = r_print_rowlog (core->print, "Type matching analysis for all functions (aaft)"); - r_core_cmd0 (core, "aaft"); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Type matching analysis for all functions (aaft)"); + rz_core_cmd0 (core, "aaft"); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); - oldstr = r_print_rowlog (core->print, "Propagate noreturn information"); - r_core_anal_propagate_noreturn (core, UT64_MAX); - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Propagate noreturn information"); + rz_core_anal_propagate_noreturn (core, UT64_MAX); + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); // apply dwarf function information Sdb *dwarf_sdb = sdb_ns (core->anal->sdb, "dwarf", 0); if (dwarf_sdb) { - oldstr = r_print_rowlog (core->print, "Integrate dwarf function information."); - r_anal_dwarf_integrate_functions (core->anal, core->flags, dwarf_sdb); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Integrate dwarf function information."); + rz_anal_dwarf_integrate_functions (core->anal, core->flags, dwarf_sdb); + rz_print_rowlog_done (core->print, oldstr); } - oldstr = r_print_rowlog (core->print, "Use -AA or aaaa to perform additional experimental analysis."); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Use -AA or aaaa to perform additional experimental analysis."); + rz_print_rowlog_done (core->print, oldstr); if (input[1] == 'a') { // "aaaa" if (!didAap) { - oldstr = r_print_rowlog (core->print, "Finding function preludes"); - (void)r_core_search_preludes (core, false); // "aap" - r_print_rowlog_done (core->print, oldstr); - r_core_task_yield (&core->tasks); + oldstr = rz_print_rowlog (core->print, "Finding function preludes"); + (void)rz_core_search_preludes (core, false); // "aap" + rz_print_rowlog_done (core->print, oldstr); + rz_core_task_yield (&core->tasks); } - oldstr = r_print_rowlog (core->print, "Enable constraint types analysis for variables"); - r_config_set (core->config, "anal.types.constraint", "true"); - r_print_rowlog_done (core->print, oldstr); + oldstr = rz_print_rowlog (core->print, "Enable constraint types analysis for variables"); + rz_config_set (core->config, "anal.types.constraint", "true"); + rz_print_rowlog_done (core->print, oldstr); } - r_core_cmd0 (core, "s-"); + rz_core_cmd0 (core, "s-"); if (dh_orig) { - r_core_cmdf (core, "dL %s", dh_orig); - r_core_task_yield (&core->tasks); + rz_core_cmdf (core, "dL %s", dh_orig); + rz_core_task_yield (&core->tasks); } } - r_core_seek (core, curseek, true); + rz_core_seek (core, curseek, true); jacuzzi: // XXX this shouldnt be called. flags muts be created wheen the function is registered flag_every_function (core); - r_cons_break_pop (); + rz_cons_break_pop (); R_FREE (dh_orig); } break; case 't': { // "aat" - char *off = input[1]? r_str_trim_dup (input + 2): NULL; - RAnalFunction *fcn; - RListIter *it; + char *off = input[1]? rz_str_trim_dup (input + 2): NULL; + RzAnalFunction *fcn; + RzListIter *it; if (off && *off) { - ut64 addr = r_num_math (NULL, off); - fcn = r_anal_get_function_at (core->anal, core->offset); + ut64 addr = rz_num_math (NULL, off); + fcn = rz_anal_get_function_at (core->anal, core->offset); if (fcn) { - r_core_link_stroff (core, fcn); + rz_core_link_stroff (core, fcn); } else { eprintf ("Cannot find function at %08" PFMT64x "\n", addr); } } else { - if (r_list_empty (core->anal->fcns)) { + if (rz_list_empty (core->anal->fcns)) { eprintf ("Couldn't find any functions\n"); break; } - r_list_foreach (core->anal->fcns, it, fcn) { - if (r_cons_is_breaked ()) { + rz_list_foreach (core->anal->fcns, it, fcn) { + if (rz_cons_is_breaked ()) { break; } - r_core_link_stroff (core, fcn); + rz_core_link_stroff (core, fcn); } } free (off); @@ -9718,77 +9718,77 @@ static int cmd_anal_all(RCore *core, const char *input) { break; case 'e': // "aae" if (input[1] == 'f') { // "aaef" - RListIter *it; - RAnalFunction *fcn; + RzListIter *it; + RzAnalFunction *fcn; ut64 cur_seek = core->offset; - r_list_foreach (core->anal->fcns, it, fcn) { - r_core_seek (core, fcn->addr, true); - r_core_anal_esil (core, "f", NULL); + rz_list_foreach (core->anal->fcns, it, fcn) { + rz_core_seek (core, fcn->addr, true); + rz_core_anal_esil (core, "f", NULL); } - r_core_seek (core, cur_seek, true); + rz_core_seek (core, cur_seek, true); } else if (input[1] == ' ') { const char *len = (char *)input + 1; char *addr = strchr (input + 2, ' '); if (addr) { *addr++ = 0; } - r_core_anal_esil (core, len, addr); + rz_core_anal_esil (core, len, addr); } else { ut64 at = core->offset; - RIOMap *map; - RListIter *iter; - RList *list = r_core_get_boundaries_prot (core, -1, NULL, "anal"); + RzIOMap *map; + RzListIter *iter; + RzList *list = rz_core_get_boundaries_prot (core, -1, NULL, "anal"); if (!list) { break; } - if (!strcmp ("range", r_config_get (core->config, "anal.in"))) { - ut64 from = r_config_get_i (core->config, "anal.from"); - ut64 to = r_config_get_i (core->config, "anal.to"); + if (!strcmp ("range", rz_config_get (core->config, "anal.in"))) { + ut64 from = rz_config_get_i (core->config, "anal.from"); + ut64 to = rz_config_get_i (core->config, "anal.to"); if (to > from) { - char *len = r_str_newf (" 0x%"PFMT64x, to - from); - r_core_seek (core, from, true); - r_core_anal_esil (core, len, NULL); + char *len = rz_str_newf (" 0x%"PFMT64x, to - from); + rz_core_seek (core, from, true); + rz_core_anal_esil (core, len, NULL); free (len); } else { eprintf ("Assert: anal.from > anal.to\n"); } } else { - r_list_foreach (list, iter, map) { + rz_list_foreach (list, iter, map) { if (map->perm & R_PERM_X) { - char *ss = r_str_newf (" 0x%"PFMT64x, map->itv.size); - r_core_seek (core, map->itv.addr, true); - r_core_anal_esil (core, ss, NULL); + char *ss = rz_str_newf (" 0x%"PFMT64x, map->itv.size); + rz_core_seek (core, map->itv.addr, true); + rz_core_anal_esil (core, ss, NULL); free (ss); } } - r_list_free (list); + rz_list_free (list); } - r_core_seek (core, at, true); + rz_core_seek (core, at, true); } break; case 'r': - (void)r_core_anal_refs (core, input + 1); + (void)rz_core_anal_refs (core, input + 1); break; default: - r_core_cmd_help (core, help_msg_aa); + rz_core_cmd_help (core, help_msg_aa); break; } return true; } -static bool anal_fcn_data (RCore *core, const char *input) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ANY); +static bool anal_fcn_data (RzCore *core, const char *input) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ANY); if (fcn) { int i; bool gap = false; ut64 gap_addr = UT64_MAX; - ut32 fcn_size = r_anal_function_size_from_entry (fcn); + ut32 fcn_size = rz_anal_function_size_from_entry (fcn); char *bitmap = calloc (1, fcn_size); if (bitmap) { - RAnalBlock *b; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, b) { + RzAnalBlock *b; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, b) { int f = b->addr - fcn->addr; int t = R_MIN (f + b->size, fcn_size); if (f >= 0) { @@ -9802,7 +9802,7 @@ static bool anal_fcn_data (RCore *core, const char *input) { ut64 here = fcn->addr + i; if (bitmap && bitmap[i]) { if (gap) { - r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", here - gap_addr, gap_addr); + rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", here - gap_addr, gap_addr); gap = false; } gap_addr = UT64_MAX; @@ -9814,7 +9814,7 @@ static bool anal_fcn_data (RCore *core, const char *input) { } } if (gap) { - r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", fcn->addr + fcn_size - gap_addr, gap_addr); + rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", fcn->addr + fcn_size - gap_addr, gap_addr); } free (bitmap); return true; @@ -9822,82 +9822,82 @@ static bool anal_fcn_data (RCore *core, const char *input) { return false; } -static bool anal_fcn_data_gaps (RCore *core, const char *input) { +static bool anal_fcn_data_gaps (RzCore *core, const char *input) { ut64 end = UT64_MAX; - RAnalFunction *fcn; - RListIter *iter; + RzAnalFunction *fcn; + RzListIter *iter; int i, wordsize = (core->rasm->bits == 64)? 8: 4; - r_list_sort (core->anal->fcns, cmpaddr); - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_sort (core->anal->fcns, cmpaddr); + rz_list_foreach (core->anal->fcns, iter, fcn) { if (end != UT64_MAX) { int range = fcn->addr - end; if (range > 0) { for (i = 0; i + wordsize < range; i+= wordsize) { - r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", wordsize, end + i); + rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", wordsize, end + i); } - r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", range - i, end + i); - //r_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", range, end); + rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", range - i, end + i); + //rz_cons_printf ("Cd %d @ 0x%08"PFMT64x"\n", range, end); } } - end = fcn->addr + r_anal_function_size_from_entry (fcn); + end = fcn->addr + rz_anal_function_size_from_entry (fcn); } return true; } -static void cmd_anal_rtti(RCore *core, const char *input) { +static void cmd_anal_rtti(RzCore *core, const char *input) { switch (input[0]) { case '\0': // "avr" case 'j': // "avrj" - r_anal_rtti_print_at_vtable (core->anal, core->offset, input[0]); + rz_anal_rtti_print_at_vtable (core->anal, core->offset, input[0]); break; case 'a': // "avra" - r_anal_rtti_print_all (core->anal, input[1]); + rz_anal_rtti_print_all (core->anal, input[1]); break; case 'r': // "avrr" - r_anal_rtti_recover_all (core->anal); + rz_anal_rtti_recover_all (core->anal); break; case 'D': { // "avrD" - char *name = r_str_trim_dup (input + 1); - char *demangled = r_anal_rtti_demangle_class_name (core->anal, name); + char *name = rz_str_trim_dup (input + 1); + char *demangled = rz_anal_rtti_demangle_class_name (core->anal, name); free (name); if (demangled) { - r_cons_println (demangled); + rz_cons_println (demangled); free (demangled); } break; } default : - r_core_cmd_help (core, help_msg_av); + rz_core_cmd_help (core, help_msg_av); break; } } -static void cmd_anal_virtual_functions(RCore *core, const char* input) { +static void cmd_anal_virtual_functions(RzCore *core, const char* input) { switch (input[0]) { case '\0': // "av" case '*': // "av*" case 'j': // "avj" - r_anal_list_vtables (core->anal, input[0]); + rz_anal_list_vtables (core->anal, input[0]); break; case 'r': // "avr" cmd_anal_rtti (core, input + 1); break; default : - r_core_cmd_help (core, help_msg_av); + rz_core_cmd_help (core, help_msg_av); break; } } -static void cmd_anal_class_method(RCore *core, const char *input) { - RAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; +static void cmd_anal_class_method(RzCore *core, const char *input) { + RzAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; char c = input[0]; switch (c) { case ' ': // "acm" case '-': // "acm-" case 'n': { // "acmn" - const char *str = r_str_trim_head_ro (input + 1); + const char *str = rz_str_trim_head_ro (input + 1); if (!*str) { eprintf ("No class name given.\n"); break; @@ -9936,14 +9936,14 @@ static void cmd_anal_class_method(RCore *core, const char *input) { *end = '\0'; } - RAnalMethod meth; + RzAnalMethod meth; meth.name = name_str; - meth.addr = r_num_get (core->num, addr_str); + meth.addr = rz_num_get (core->num, addr_str); meth.vtable_offset = -1; if (end) { - meth.vtable_offset = (int)r_num_get (core->num, end + 1); + meth.vtable_offset = (int)rz_num_get (core->num, end + 1); } - err = r_anal_class_method_set (core->anal, cstr, &meth); + err = rz_anal_class_method_set (core->anal, cstr, &meth); } else if (c == 'n') { char *new_name_str = end + 1; end = strchr (new_name_str, ' '); @@ -9951,16 +9951,16 @@ static void cmd_anal_class_method(RCore *core, const char *input) { *end = '\0'; } - err = r_anal_class_method_rename (core->anal, cstr, name_str, new_name_str); + err = rz_anal_class_method_rename (core->anal, cstr, name_str, new_name_str); } else if (c == '-') { - err = r_anal_class_method_delete (core->anal, cstr, name_str); + err = rz_anal_class_method_delete (core->anal, cstr, name_str); } free (cstr); break; } default: - r_core_cmd_help (core, help_msg_ac); + rz_core_cmd_help (core, help_msg_ac); break; } @@ -9976,13 +9976,13 @@ static void cmd_anal_class_method(RCore *core, const char *input) { } } -static void cmd_anal_class_base(RCore *core, const char *input) { - RAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; +static void cmd_anal_class_base(RzCore *core, const char *input) { + RzAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; char c = input[0]; switch (c) { case ' ': // "acb" case '-': { // "acb-" - const char *str = r_str_trim_head_ro (input + 1); + const char *str = rz_str_trim_head_ro (input + 1); if (!*str) { eprintf ("No class name given.\n"); return; @@ -9999,7 +9999,7 @@ static void cmd_anal_class_base(RCore *core, const char *input) { if (!end || *end == '\0') { if (c == ' ') { - r_anal_class_list_bases (core->anal, cstr); + rz_anal_class_list_bases (core->anal, cstr); } else /*if (c == '-')*/ { eprintf ("No base id given.\n"); } @@ -10014,27 +10014,27 @@ static void cmd_anal_class_base(RCore *core, const char *input) { } if (c == '-') { - err = r_anal_class_base_delete (core->anal, cstr, base_str); + err = rz_anal_class_base_delete (core->anal, cstr, base_str); free (cstr); break; } - RAnalBaseClass base; + RzAnalBaseClass base; base.id = NULL; base.offset = 0; base.class_name = base_str; if (end) { - base.offset = r_num_get (core->num, end + 1); + base.offset = rz_num_get (core->num, end + 1); } - err = r_anal_class_base_set (core->anal, cstr, &base); + err = rz_anal_class_base_set (core->anal, cstr, &base); free (base.id); free (cstr); break; } default: - r_core_cmd_help (core, help_msg_ac); + rz_core_cmd_help (core, help_msg_ac); break; } @@ -10043,12 +10043,12 @@ static void cmd_anal_class_base(RCore *core, const char *input) { } } -static void cmd_anal_class_vtable(RCore *core, const char *input) { - RAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; +static void cmd_anal_class_vtable(RzCore *core, const char *input) { + RzAnalClassErr err = R_ANAL_CLASS_ERR_SUCCESS; char c = input[0]; switch (c) { case 'f': {// "acvf" [offset] ([class_name]) - const char *str = r_str_trim_head_ro (input + 1); + const char *str = rz_str_trim_head_ro (input + 1); if (!*str) { eprintf ("No offset given\n"); return; @@ -10062,24 +10062,24 @@ static void cmd_anal_class_vtable(RCore *core, const char *input) { *end = '\0'; end++; } - ut64 offset_arg = r_num_get (core->num, cstr); // Should I allow negative offset? + ut64 offset_arg = rz_num_get (core->num, cstr); // Should I allow negative offset? char *class_arg = NULL; if (end) { - class_arg = (char *)r_str_trim_head_ro (end); + class_arg = (char *)rz_str_trim_head_ro (end); } if (class_arg) { - end = (char *)r_str_trim_head_wp (class_arg); // in case of extra unwanted stuff at the cmd end + end = (char *)rz_str_trim_head_wp (class_arg); // in case of extra unwanted stuff at the cmd end *end = '\0'; } - r_anal_class_list_vtable_offset_functions (core->anal, class_arg, offset_arg); + rz_anal_class_list_vtable_offset_functions (core->anal, class_arg, offset_arg); free (cstr); break; } case ' ': // "acv" case '-': { // "acv-" - const char *str = r_str_trim_head_ro (input + 1); + const char *str = rz_str_trim_head_ro (input + 1); if (!*str) { eprintf ("No class name given.\n"); return; @@ -10096,7 +10096,7 @@ static void cmd_anal_class_vtable(RCore *core, const char *input) { if (!end || *end == '\0') { if (c == ' ') { - r_anal_class_list_vtables (core->anal, cstr); + rz_anal_class_list_vtables (core->anal, cstr); } else /*if (c == '-')*/ { eprintf ("No vtable id given. See acv [class name].\n"); } @@ -10107,7 +10107,7 @@ static void cmd_anal_class_vtable(RCore *core, const char *input) { char *arg1_str = end; if (c == '-') { - err = r_anal_class_vtable_delete (core->anal, cstr, arg1_str); + err = rz_anal_class_vtable_delete (core->anal, cstr, arg1_str); free (cstr); break; } @@ -10117,30 +10117,30 @@ static void cmd_anal_class_vtable(RCore *core, const char *input) { *end = '\0'; } - RAnalVTable vtable; + RzAnalVTable vtable; vtable.id = NULL; - vtable.addr = r_num_get (core->num, arg1_str); + vtable.addr = rz_num_get (core->num, arg1_str); vtable.offset = 0; vtable.size = 0; char *arg3_str = NULL; if (end) { - vtable.offset = r_num_get (core->num, end + 1); + vtable.offset = rz_num_get (core->num, end + 1); // end + 1 won't work on extra whitespace between arguments, TODO arg3_str = strchr (end+1, ' '); } if (arg3_str) { - vtable.size = r_num_get (core->num, arg3_str + 1); + vtable.size = rz_num_get (core->num, arg3_str + 1); } - err = r_anal_class_vtable_set (core->anal, cstr, &vtable); + err = rz_anal_class_vtable_set (core->anal, cstr, &vtable); free (vtable.id); free (cstr); break; } default: - r_core_cmd_help (core, help_msg_ac); + rz_core_cmd_help (core, help_msg_ac); break; } @@ -10149,7 +10149,7 @@ static void cmd_anal_class_vtable(RCore *core, const char *input) { } } -static void cmd_anal_classes(RCore *core, const char *input) { +static void cmd_anal_classes(RzCore *core, const char *input) { switch (input[0]) { case 'l': // "acl" if (input[1] == 'l') { // "acll" (name) @@ -10159,32 +10159,32 @@ static void cmd_anal_classes(RCore *core, const char *input) { arg_offset++; mode = 'j'; } - const char *arg = r_str_trim_head_ro (input + arg_offset); + const char *arg = rz_str_trim_head_ro (input + arg_offset); if (*arg) { // if there is an argument char *class_name = strdup (arg); if (!class_name) { break; } - char *name_end = (char *)r_str_trim_head_wp (class_name); + char *name_end = (char *)rz_str_trim_head_wp (class_name); *name_end = 0; // trim the whitespace around the name if (mode == 'j') { PJ *pj = pj_new (); - r_anal_class_json (core->anal, pj, class_name); - r_cons_printf ("%s\n", pj_string (pj)); + rz_anal_class_json (core->anal, pj, class_name); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } else { - r_anal_class_print (core->anal, class_name, true); + rz_anal_class_print (core->anal, class_name, true); } free (class_name); break; } } - r_anal_class_list (core->anal, input[1]); + rz_anal_class_list (core->anal, input[1]); break; case ' ': // "ac" case '-': // "ac-" case 'n': { // "acn" - const char *str = r_str_trim_head_ro (input + 1); + const char *str = rz_str_trim_head_ro (input + 1); if (!*str) { break; } @@ -10197,7 +10197,7 @@ static void cmd_anal_classes(RCore *core, const char *input) { *end = '\0'; } if (input[0] == '-') { - r_anal_class_delete (core->anal, cstr); + rz_anal_class_delete (core->anal, cstr); } else if(input[0] == 'n') { if (!end) { eprintf ("No new class name given.\n"); @@ -10207,7 +10207,7 @@ static void cmd_anal_classes(RCore *core, const char *input) { if (end) { *end = '\0'; } - RAnalClassErr err = r_anal_class_rename (core->anal, cstr, new_name); + RzAnalClassErr err = rz_anal_class_rename (core->anal, cstr, new_name); if (err == R_ANAL_CLASS_ERR_NONEXISTENT_CLASS) { eprintf ("Class does not exist.\n"); } else if (err == R_ANAL_CLASS_ERR_CLASH) { @@ -10215,7 +10215,7 @@ static void cmd_anal_classes(RCore *core, const char *input) { } } } else { - r_anal_class_create (core->anal, cstr); + rz_anal_class_create (core->anal, cstr); } free (cstr); break; @@ -10230,28 +10230,28 @@ static void cmd_anal_classes(RCore *core, const char *input) { cmd_anal_class_method (core, input + 1); break; case 'g': { // "acg" - RGraph *graph = r_anal_class_get_inheritance_graph (core->anal); + RGraph *graph = rz_anal_class_get_inheritance_graph (core->anal); if (!graph) { eprintf ("Couldn't create graph"); break; } - RAGraph *agraph = create_agraph_from_graph (graph); + RzAGraph *agraph = create_agraph_from_graph (graph); if (!agraph) { - r_graph_free (graph); + rz_graph_free (graph); eprintf ("Couldn't create graph"); break; } - r_agraph_print (agraph); - r_graph_free (graph); - r_agraph_free (agraph); + rz_agraph_print (agraph); + rz_graph_free (graph); + rz_agraph_free (agraph); } break; default: // "ac?" - r_core_cmd_help (core, help_msg_ac); + rz_core_cmd_help (core, help_msg_ac); break; } } -static void show_reg_args(RCore *core, int nargs, RStrBuf *sb) { +static void show_reg_args(RzCore *core, int nargs, RStrBuf *sb) { int i; char regname[8]; if (nargs < 0) { @@ -10259,26 +10259,26 @@ static void show_reg_args(RCore *core, int nargs, RStrBuf *sb) { } for (i = 0; i < nargs; i++) { snprintf (regname, sizeof (regname), "A%d", i); - ut64 v = r_reg_getv (core->anal->reg, regname); + ut64 v = rz_reg_getv (core->anal->reg, regname); if (sb) { - r_strbuf_appendf (sb, "%s0x%08"PFMT64x, i?", ":"", v); + rz_strbuf_appendf (sb, "%s0x%08"PFMT64x, i?", ":"", v); } else { - r_cons_printf ("A%d 0x%08"PFMT64x"\n", i, v); + rz_cons_printf ("A%d 0x%08"PFMT64x"\n", i, v); } } } // ripped from disasm.c: dupe code from there // TODO: Implement aC* and aCj -static void cmd_anal_aC(RCore *core, const char *input) { +static void cmd_anal_aC(RzCore *core, const char *input) { bool is_aCer = false; - RAnalFuncArg *arg; - RListIter *iter; - RListIter *nextele; + RzAnalFuncArg *arg; + RzListIter *iter; + RzListIter *nextele; const char *iarg = strchr (input, ' '); if (input[0] == 'e' && input[1] == 'f') { // "aCf" // hacky :D - r_core_cmdf (core, ".aCe* $$ @@=`pdr~call`"); + rz_core_cmdf (core, ".aCe* $$ @@=`pdr~call`"); return; } if (iarg) { @@ -10288,15 +10288,15 @@ static void cmd_anal_aC(RCore *core, const char *input) { eprintf ("Usage: aC[e] [addr-of-call] # analyze call args (aCe does esil emulation with abte)\n"); return; } - RStrBuf *sb = r_strbuf_new (""); - ut64 pcv = r_num_math (core->num, iarg); + RStrBuf *sb = rz_strbuf_new (""); + ut64 pcv = rz_num_math (core->num, iarg); if (input[0] == 'e') { // "aCe" is_aCer = (input[1] == '*'); - r_core_cmdf (core, ".abte 0x%08"PFMT64x, pcv); + rz_core_cmdf (core, ".abte 0x%08"PFMT64x, pcv); } - RAnalOp* op = r_core_anal_op (core, pcv, -1); + RzAnalOp* op = rz_core_anal_op (core, pcv, -1); if (!op) { - r_strbuf_free (sb); + rz_strbuf_free (sb); return; } bool go_on = true; @@ -10305,28 +10305,28 @@ bool go_on = true; go_on = false; } const char *fcn_name = NULL; - RAnalFunction *fcn; + RzAnalFunction *fcn; if (go_on) { - fcn = r_anal_get_function_at (core->anal, pcv); + fcn = rz_anal_get_function_at (core->anal, pcv); if (fcn) { fcn_name = fcn->name; } else { - RFlagItem *item = r_flag_get_i (core->flags, op->jump); + RzFlagItem *item = rz_flag_get_i (core->flags, op->jump); if (item) { fcn_name = item->name; } } char *key = (fcn_name)? resolve_fcn_name (core->anal, fcn_name): NULL; if (key) { - const char *fcn_type = r_type_func_ret (core->anal->sdb_types, key); - int nargs = r_type_func_args_count (core->anal->sdb_types, key); + const char *fcn_type = rz_type_func_ret (core->anal->sdb_types, key); + int nargs = rz_type_func_args_count (core->anal->sdb_types, key); // remove other comments if (fcn_type) { - r_strbuf_appendf (sb, "%s%s%s(", r_str_get (fcn_type), + rz_strbuf_appendf (sb, "%s%s%s(", rz_str_get (fcn_type), (*fcn_type && fcn_type[strlen (fcn_type) - 1] == '*') ? "" : " ", - r_str_get (key)); + rz_str_get (key)); if (!nargs) { - r_strbuf_appendf (sb, "void)\n"); + rz_strbuf_appendf (sb, "void)\n"); } } else { eprintf ("Cannot find any function type..lets just use some standards?\n"); @@ -10343,79 +10343,79 @@ bool go_on = true; } if (go_on) { ut64 s_width = (core->anal->bits == 64)? 8: 4; - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - ut64 spv = r_reg_getv (core->anal->reg, sp); - r_reg_setv (core->anal->reg, sp, spv + s_width); // temporarily set stack ptr to sync with carg.c - RList *list = r_core_get_func_args (core, fcn_name); - if (!r_list_empty (list)) { + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + ut64 spv = rz_reg_getv (core->anal->reg, sp); + rz_reg_setv (core->anal->reg, sp, spv + s_width); // temporarily set stack ptr to sync with carg.c + RzList *list = rz_core_get_func_args (core, fcn_name); + if (!rz_list_empty (list)) { #if 0 bool warning = false; bool on_stack = false; - r_list_foreach (list, iter, arg) { - if (r_str_startswith (arg->cc_source, "stack")) { + rz_list_foreach (list, iter, arg) { + if (rz_str_startswith (arg->cc_source, "stack")) { on_stack = true; } if (!arg->size) { - r_cons_printf ("%s: unk_size", arg->c_type); + rz_cons_printf ("%s: unk_size", arg->c_type); warning = true; } #endif - r_list_foreach (list, iter, arg) { - nextele = r_list_iter_get_next (iter); + rz_list_foreach (list, iter, arg) { + nextele = rz_list_iter_get_next (iter); if (!arg->fmt) { - r_strbuf_appendf (sb, "?%s", nextele? ", ": ""); + rz_strbuf_appendf (sb, "?%s", nextele? ", ": ""); } else { // print_fcn_arg (core, arg->orig_c_type, arg->name, arg->fmt, arg->src, on_stack, 0); // const char *fmt = arg->orig_c_type; ut64 addr = arg->src; - char *res = r_core_cmd_strf (core, "pfq %s @ 0x%08" PFMT64x, arg->fmt, addr); - // r_cons_printf ("pfq *%s @ 0x%08" PFMT64x"\n", arg->fmt, addr); - r_str_trim (res); - r_strbuf_appendf (sb, "%s", res); + char *res = rz_core_cmd_strf (core, "pfq %s @ 0x%08" PFMT64x, arg->fmt, addr); + // rz_cons_printf ("pfq *%s @ 0x%08" PFMT64x"\n", arg->fmt, addr); + rz_str_trim (res); + rz_strbuf_appendf (sb, "%s", res); free (res); } } - r_strbuf_appendf (sb, ")"); + rz_strbuf_appendf (sb, ")"); } else { // function name not resolved int i, nargs = 4; // DEFAULT_NARGS; if (fcn) { // @TODO: fcn->nargs should be updated somewhere and used here instead - nargs = r_anal_var_count (core->anal, fcn, 's', 1) + - r_anal_var_count (core->anal, fcn, 'b', 1) + - r_anal_var_count (core->anal, fcn, 'r', 1); + nargs = rz_anal_var_count (core->anal, fcn, 's', 1) + + rz_anal_var_count (core->anal, fcn, 'b', 1) + + rz_anal_var_count (core->anal, fcn, 'r', 1); } if (nargs > 0) { if (fcn_name) { - r_strbuf_appendf (sb, "; %s(", fcn_name); + rz_strbuf_appendf (sb, "; %s(", fcn_name); } else { - r_strbuf_appendf (sb, "; 0x%"PFMT64x"(", pcv); + rz_strbuf_appendf (sb, "; 0x%"PFMT64x"(", pcv); } for (i = 0; i < nargs; i++) { - ut64 v = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i); - r_strbuf_appendf (sb, "%s0x%"PFMT64x, i?", ":"", v); + ut64 v = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i); + rz_strbuf_appendf (sb, "%s0x%"PFMT64x, i?", ":"", v); } - r_strbuf_appendf (sb, ")"); + rz_strbuf_appendf (sb, ")"); } } - r_reg_setv (core->anal->reg, sp, spv); // reset stack ptr + rz_reg_setv (core->anal->reg, sp, spv); // reset stack ptr } - char *s = r_strbuf_drain (sb); + char *s = rz_strbuf_drain (sb); if (is_aCer) { - char *u = r_base64_encode_dyn (s, -1); + char *u = rz_base64_encode_dyn (s, -1); if (u) { - r_cons_printf ("CCu base64:%s\n", u); + rz_cons_printf ("CCu base64:%s\n", u); free (u); } } else { - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); } free (s); } static int cmd_anal(void *data, const char *input) { const char *r; - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut32 tbs = core->blocksize; switch (input[0]) { case 'p': // "ap" @@ -10426,20 +10426,20 @@ static int cmd_anal(void *data, const char *input) { ut8 *buf = calloc (1, bufsz); ut64 off = core->offset; if (input[1] == ' ') { - off = r_num_math (core->num, input+1); - r_io_read_at (core->io, off - bufsz + prelude_sz, buf, bufsz); + off = rz_num_math (core->num, input+1); + rz_io_read_at (core->io, off - bufsz + prelude_sz, buf, bufsz); } else { - r_io_read_at (core->io, off - bufsz + prelude_sz, buf, bufsz); + rz_io_read_at (core->io, off - bufsz + prelude_sz, buf, bufsz); } //const char *prelude = "\x2d\xe9\xf0\x47"; //:fffff000"; - r_mem_reverse (buf, bufsz); - //r_print_hexdump (NULL, off, buf, bufsz, 16, -16); - const ut8 *pos = r_mem_mem (buf, bufsz, prelude, prelude_sz); + rz_mem_reverse (buf, bufsz); + //rz_print_hexdump (NULL, off, buf, bufsz, 16, -16); + const ut8 *pos = rz_mem_mem (buf, bufsz, prelude, prelude_sz); if (pos) { int delta = (size_t)(pos - buf); eprintf ("POS = %d\n", delta); eprintf ("HIT = 0x%"PFMT64x"\n", off - delta); - r_cons_printf ("0x%08"PFMT64x"\n", off - delta); + rz_cons_printf ("0x%08"PFMT64x"\n", off - delta); } else { eprintf ("Cannot find prelude\n"); } @@ -10450,7 +10450,7 @@ static int cmd_anal(void *data, const char *input) { { ut8 *buf = malloc (strlen (input) + 1); if (buf) { - int len = r_hex_str2bin (input + 1, buf); + int len = rz_hex_str2bin (input + 1, buf); if (len > 0) { core_anal_bytes (core, buf, len, 0, input[1]); } @@ -10461,10 +10461,10 @@ static int cmd_anal(void *data, const char *input) { case 'b': // "ab" switch (input[1]) { case '.': // "ab." - r_core_cmd0 (core, "ab $$"); + rz_core_cmd0 (core, "ab $$"); break; case 'a': // "aba" - r_core_cmdf (core, "aeab%s", input + 1); + rz_core_cmdf (core, "aeab%s", input + 1); break; case 'b': // "abb" core_anal_bbs (core, input + 2); @@ -10478,7 +10478,7 @@ static int cmd_anal(void *data, const char *input) { break; case 'l': // "abl" if (input[2] == '?') { - r_core_cmd_help (core, help_msg_abl); + rz_core_cmd_help (core, help_msg_abl); } else { anal_bb_list (core, input + 2); } @@ -10492,13 +10492,13 @@ static int cmd_anal(void *data, const char *input) { { ut64 addr = core->offset; if (input[1] && input[1] != '.') { - addr = r_num_math (core->num, input + 1); + addr = rz_num_math (core->num, input + 1); } - r_core_cmdf (core, "afbi @ 0x%"PFMT64x, addr); + rz_core_cmdf (core, "afbi @ 0x%"PFMT64x, addr); } break; default: - r_core_cmd_help (core, help_msg_ab); + rz_core_cmd_help (core, help_msg_ab); break; } break; @@ -10511,11 +10511,11 @@ static int cmd_anal(void *data, const char *input) { case 'i': cmd_anal_info (core, input + 1); break; // "ai" case 'r': cmd_anal_reg (core, input + 1); break; // "ar" case 'e': cmd_anal_esil (core, input + 1); break; // "ae" - case 'L': return r_core_cmd0 (core, "e asm.arch=??"); break; + case 'L': return rz_core_cmd0 (core, "e asm.arch=??"); break; case 'o': cmd_anal_opcode (core, input + 1); break; // "ao" case 'O': cmd_anal_bytes (core, input + 1); break; // "aO" case 'F': // "aF" - r_core_anal_fcn (core, core->offset, UT64_MAX, R_ANAL_REF_TYPE_NULL, 1); + rz_core_anal_fcn (core, core->offset, UT64_MAX, R_ANAL_REF_TYPE_NULL, 1); break; case 'f': // "af" { @@ -10567,9 +10567,9 @@ static int cmd_anal(void *data, const char *input) { } break; case '*': // "a*" - r_core_cmd0 (core, "afl*"); - r_core_cmd0 (core, "ah*"); - r_core_cmd0 (core, "ax*"); + rz_core_cmd0 (core, "afl*"); + rz_core_cmd0 (core, "ah*"); + rz_core_cmd0 (core, "ax*"); break; case 'a': // "aa" if (!cmd_anal_all (core, input + 1)) { @@ -10580,7 +10580,7 @@ static int cmd_anal(void *data, const char *input) { switch (input[1]) { case 'f': // "adf" if (input[2] == 'g') { - anal_fcn_data_gaps (core, r_str_trim_head_ro (input + 1)); + anal_fcn_data_gaps (core, rz_str_trim_head_ro (input + 1)); } else { anal_fcn_data (core, input + 1); } @@ -10592,33 +10592,33 @@ static int cmd_anal(void *data, const char *input) { const int default_depth = 1; const char *p; int a, b; - a = r_num_math (core->num, input + 2); + a = rz_num_math (core->num, input + 2); p = strchr (input + 2, ' '); - b = p? r_num_math (core->num, p + 1): default_depth; + b = p? rz_num_math (core->num, p + 1): default_depth; if (a < 1) { a = 1; } if (b < 1) { b = 1; } - r_core_anal_data (core, core->offset, a, b, 0); + rz_core_anal_data (core, core->offset, a, b, 0); } break; case 'k': // "adk" - r = r_anal_data_kind (core->anal, + r = rz_anal_data_kind (core->anal, core->offset, core->block, core->blocksize); - r_cons_println (r); + rz_cons_println (r); break; case '\0': // "ad" - r_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 0); + rz_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 0); break; case '4': // "ad4" - r_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 4); + rz_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 4); break; case '8': // "ad8" - r_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 8); + rz_core_anal_data (core, core->offset, 2 + (core->blocksize / 4), 1, 8); break; default: - r_core_cmd_help (core, help_msg_ad); + rz_core_cmd_help (core, help_msg_ad); break; } break; @@ -10629,19 +10629,19 @@ static int cmd_anal(void *data, const char *input) { if (core->anal && core->anal->cur && core->anal->cur->cmd_ext) { return core->anal->cur->cmd_ext (core->anal, input + 1); } else { - r_cons_printf ("No plugins for this analysis plugin\n"); + rz_cons_printf ("No plugins for this analysis plugin\n"); } break; case 'j': // "aj" - r_core_cmd0 (core, "aflj"); + rz_core_cmd0 (core, "aflj"); break; case 0: // "a" - r_core_cmd0 (core, "aai"); + rz_core_cmd0 (core, "aai"); break; default: - r_core_cmd_help (core, help_msg_a); + rz_core_cmd_help (core, help_msg_a); #if 0 - r_cons_printf ("Examples:\n" + rz_cons_printf ("Examples:\n" " f ts @ `S*~text:0[3]`; f t @ section..text\n" " f ds @ `S*~data:0[3]`; f d @ section..data\n" " .ad t t+ts @ d:ds\n", @@ -10650,10 +10650,10 @@ static int cmd_anal(void *data, const char *input) { break; } if (tbs != core->blocksize) { - r_core_block_size (core, tbs); + rz_core_block_size (core, tbs); } - if (r_cons_is_breaked ()) { - r_cons_clear_line (1); + if (rz_cons_is_breaked ()) { + rz_cons_clear_line (1); } return 0; } diff --git a/libr/core/cmd_api.c b/librz/core/cmd_api.c similarity index 62% rename from libr/core/cmd_api.c rename to librz/core/cmd_api.c index fd437cd5ab..989e766c78 100644 --- a/libr/core/cmd_api.c +++ b/librz/core/cmd_api.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #include -#include -#include -#include +#include +#include +#include /*! * Number of sub-commands to show as options when displaying the help of a @@ -27,13 +27,13 @@ */ #define MAX_CHILDREN_SHOW 7 -static const RCmdDescHelp not_defined_help = { +static const RzCmdDescHelp not_defined_help = { .usage = "Usage not defined", .summary = "Help summary not defined", .description = "Help description not defined.", }; -static const RCmdDescHelp root_help = { +static const RzCmdDescHelp root_help = { .usage = "[.][times][cmd][~grep][@[@iter]addr!size][|>pipe] ; ...", .description = "", }; @@ -41,48 +41,48 @@ static const RCmdDescHelp root_help = { static int value = 0; #define NCMDS (sizeof (cmd->cmds)/sizeof(*cmd->cmds)) -R_LIB_VERSION (r_cmd); +R_LIB_VERSION (rz_cmd); -static bool cmd_desc_set_parent(RCmdDesc *cd, RCmdDesc *parent) { - r_return_val_if_fail (cd && !cd->parent, false); +static bool cmd_desc_set_parent(RzCmdDesc *cd, RzCmdDesc *parent) { + rz_return_val_if_fail (cd && !cd->parent, false); if (parent) { cd->parent = parent; - r_pvector_push (&parent->children, cd); + rz_pvector_push (&parent->children, cd); parent->n_children++; } return true; } -static void cmd_desc_unset_parent(RCmdDesc *cd) { - r_return_if_fail (cd && cd->parent); - RCmdDesc *parent = cd->parent; - r_pvector_remove_data (&parent->children, cd); +static void cmd_desc_unset_parent(RzCmdDesc *cd) { + rz_return_if_fail (cd && cd->parent); + RzCmdDesc *parent = cd->parent; + rz_pvector_remove_data (&parent->children, cd); parent->n_children--; cd->parent = NULL; } -static void cmd_desc_remove_from_ht_cmds(RCmd *cmd, RCmdDesc *cd) { +static void cmd_desc_remove_from_ht_cmds(RzCmd *cmd, RzCmdDesc *cd) { void **it_cd; bool res = ht_pp_delete (cmd->ht_cmds, cd->name); - r_return_if_fail (res); - r_cmd_desc_children_foreach (cd, it_cd) { - RCmdDesc *child_cd = *it_cd; + rz_return_if_fail (res); + rz_cmd_desc_children_foreach (cd, it_cd) { + RzCmdDesc *child_cd = *it_cd; cmd_desc_remove_from_ht_cmds (cmd, child_cd); } } -static void cmd_desc_free(RCmdDesc *cd) { +static void cmd_desc_free(RzCmdDesc *cd) { if (!cd) { return; } - r_pvector_clear (&cd->children); + rz_pvector_clear (&cd->children); free (cd->name); free (cd); } -static RCmdDesc *create_cmd_desc(RCmd *cmd, RCmdDesc *parent, RCmdDescType type, const char *name, const RCmdDescHelp *help, bool ht_insert) { - RCmdDesc *res = R_NEW0 (RCmdDesc); +static RzCmdDesc *create_cmd_desc(RzCmd *cmd, RzCmdDesc *parent, RzCmdDescType type, const char *name, const RzCmdDescHelp *help, bool ht_insert) { + RzCmdDesc *res = R_NEW0 (RzCmdDesc); if (!res) { return NULL; } @@ -93,7 +93,7 @@ static RCmdDesc *create_cmd_desc(RCmd *cmd, RCmdDesc *parent, RCmdDescType type, } res->n_children = 0; res->help = help? help: ¬_defined_help; - r_pvector_init (&res->children, (RPVectorFree)cmd_desc_free); + rz_pvector_init (&res->children, (RPVectorFree)cmd_desc_free); if (ht_insert && !ht_pp_insert (cmd->ht_cmds, name, res)) { goto err; } @@ -104,44 +104,44 @@ err: return NULL; } -R_API void r_cmd_alias_init(RCmd *cmd) { +RZ_API void rz_cmd_alias_init(RzCmd *cmd) { cmd->aliases.count = 0; cmd->aliases.keys = NULL; cmd->aliases.values = NULL; } -R_API RCmd *r_cmd_new(void) { +RZ_API RzCmd *rz_cmd_new(void) { int i; - RCmd *cmd = R_NEW0 (RCmd); + RzCmd *cmd = R_NEW0 (RzCmd); if (!cmd) { return cmd; } - cmd->lcmds = r_list_new (); + cmd->lcmds = rz_list_new (); for (i = 0; i < NCMDS; i++) { cmd->cmds[i] = NULL; } cmd->nullcallback = cmd->data = NULL; cmd->ht_cmds = ht_pp_new0 (); cmd->root_cmd_desc = create_cmd_desc (cmd, NULL, R_CMD_DESC_TYPE_ARGV, "", &root_help, true); - r_core_plugin_init (cmd); - r_cmd_macro_init (&cmd->macro); - r_cmd_alias_init (cmd); + rz_core_plugin_init (cmd); + rz_cmd_macro_init (&cmd->macro); + rz_cmd_alias_init (cmd); return cmd; } -R_API RCmd *r_cmd_free(RCmd *cmd) { +RZ_API RzCmd *rz_cmd_free(RzCmd *cmd) { int i; if (!cmd) { return NULL; } ht_up_free (cmd->ts_symbols_ht); - r_cmd_alias_free (cmd); - r_cmd_macro_fini (&cmd->macro); + rz_cmd_alias_free (cmd); + rz_cmd_macro_fini (&cmd->macro); ht_pp_free (cmd->ht_cmds); // dinitialize plugin commands - r_core_plugin_fini (cmd); - r_list_free (cmd->plist); - r_list_free (cmd->lcmds); + rz_core_plugin_fini (cmd); + rz_list_free (cmd->plist); + rz_list_free (cmd->lcmds); for (i = 0; i < NCMDS; i++) { if (cmd->cmds[i]) { R_FREE (cmd->cmds[i]); @@ -152,19 +152,19 @@ R_API RCmd *r_cmd_free(RCmd *cmd) { return NULL; } -R_API RCmdDesc *r_cmd_get_root(RCmd *cmd) { +RZ_API RzCmdDesc *rz_cmd_get_root(RzCmd *cmd) { return cmd->root_cmd_desc; } -R_API RCmdDesc *r_cmd_get_desc(RCmd *cmd, const char *cmd_identifier) { - r_return_val_if_fail (cmd && cmd_identifier, NULL); +RZ_API RzCmdDesc *rz_cmd_get_desc(RzCmd *cmd, const char *cmd_identifier) { + rz_return_val_if_fail (cmd && cmd_identifier, NULL); char *cmdid = strdup (cmd_identifier); char *end_cmdid = cmdid + strlen (cmdid); - RCmdDesc *res = NULL; + RzCmdDesc *res = NULL; bool is_exact_match = true; // match longer commands first while (*cmdid) { - RCmdDesc *cd = ht_pp_find (cmd->ht_cmds, cmdid, NULL); + RzCmdDesc *cd = ht_pp_find (cmd->ht_cmds, cmdid, NULL); if (cd) { switch (cd->type) { case R_CMD_DESC_TYPE_ARGV: @@ -189,14 +189,14 @@ out: return res; } -R_API char **r_cmd_alias_keys(RCmd *cmd, int *sz) { +RZ_API char **rz_cmd_alias_keys(RzCmd *cmd, int *sz) { if (sz) { *sz = cmd->aliases.count; } return cmd->aliases.keys; } -R_API void r_cmd_alias_free (RCmd *cmd) { +RZ_API void rz_cmd_alias_free (RzCmd *cmd) { int i; // find for (i = 0; i < cmd->aliases.count; i++) { free (cmd->aliases.keys[i]); @@ -208,7 +208,7 @@ R_API void r_cmd_alias_free (RCmd *cmd) { free (cmd->aliases.remote); } -R_API bool r_cmd_alias_del (RCmd *cmd, const char *k) { +RZ_API bool rz_cmd_alias_del (RzCmd *cmd, const char *k) { int i; // find for (i = 0; i < cmd->aliases.count; i++) { if (!k || !strcmp (k, cmd->aliases.keys[i])) { @@ -235,10 +235,10 @@ R_API bool r_cmd_alias_del (RCmd *cmd, const char *k) { } // XXX: use a hashtable or any other standard data structure -R_API int r_cmd_alias_set (RCmd *cmd, const char *k, const char *v, int remote) { +RZ_API int rz_cmd_alias_set (RzCmd *cmd, const char *k, const char *v, int remote) { void *tofree = NULL; if (!strncmp (v, "base64:", 7)) { - ut8 *s = r_base64_decode_dyn (v + 7, -1); + ut8 *s = rz_base64_decode_dyn (v + 7, -1); if (s) { tofree = s; v = (const char *)s; @@ -278,7 +278,7 @@ R_API int r_cmd_alias_set (RCmd *cmd, const char *k, const char *v, int remote) return 0; } -R_API char *r_cmd_alias_get (RCmd *cmd, const char *k, int remote) { +RZ_API char *rz_cmd_alias_get (RzCmd *cmd, const char *k, int remote) { int matches, i; if (!cmd || !k) { return NULL; @@ -300,16 +300,16 @@ R_API char *r_cmd_alias_get (RCmd *cmd, const char *k, int remote) { return NULL; } -R_API int r_cmd_set_data(RCmd *cmd, void *data) { +RZ_API int rz_cmd_set_data(RzCmd *cmd, void *data) { cmd->data = data; return 1; } -R_API int r_cmd_add(RCmd *c, const char *cmd, RCmdCb cb) { +RZ_API int rz_cmd_add(RzCmd *c, const char *cmd, RzCmdCb cb) { int idx = (ut8)cmd[0]; - RCmdItem *item = c->cmds[idx]; + RzCmdItem *item = c->cmds[idx]; if (!item) { - item = R_NEW0 (RCmdItem); + item = R_NEW0 (RzCmdItem); c->cmds[idx] = item; } strncpy (item->cmd, cmd, sizeof (item->cmd)-1); @@ -317,35 +317,35 @@ R_API int r_cmd_add(RCmd *c, const char *cmd, RCmdCb cb) { return true; } -R_API int r_cmd_del(RCmd *cmd, const char *command) { +RZ_API int rz_cmd_del(RzCmd *cmd, const char *command) { int idx = (ut8)command[0]; R_FREE (cmd->cmds[idx]); return 0; } -R_API int r_cmd_call(RCmd *cmd, const char *input) { - struct r_cmd_item_t *c; +RZ_API int rz_cmd_call(RzCmd *cmd, const char *input) { + struct rz_cmd_item_t *c; int ret = -1; - RListIter *iter; - RCorePlugin *cp; - r_return_val_if_fail (cmd && input, -1); + RzListIter *iter; + RzCorePlugin *cp; + rz_return_val_if_fail (cmd && input, -1); if (!*input) { if (cmd->nullcallback) { ret = cmd->nullcallback (cmd->data); } } else { char *nstr = NULL; - const char *ji = r_cmd_alias_get (cmd, input, 1); + const char *ji = rz_cmd_alias_get (cmd, input, 1); if (ji) { if (*ji == '$') { - r_cons_strcat (ji + 1); + rz_cons_strcat (ji + 1); return true; } else { - nstr = r_str_newf ("=!%s", input); + nstr = rz_str_newf ("=!%s", input); input = nstr; } } - r_list_foreach (cmd->plist, iter, cp) { + rz_list_foreach (cmd->plist, iter, cp) { if (cp->call (cmd->data, input)) { free (nstr); return true; @@ -367,7 +367,7 @@ R_API int r_cmd_call(RCmd *cmd, const char *input) { return ret; } -static RCmdStatus int2cmdstatus(int v) { +static RzCmdStatus int2cmdstatus(int v) { if (v == -2) { return R_CMD_STATUS_EXIT; } else if (v < 0) { @@ -377,17 +377,17 @@ static RCmdStatus int2cmdstatus(int v) { } } -R_API RCmdStatus r_cmd_call_parsed_args(RCmd *cmd, RCmdParsedArgs *args) { - RCmdStatus res = R_CMD_STATUS_INVALID; +RZ_API RzCmdStatus rz_cmd_call_parsed_args(RzCmd *cmd, RzCmdParsedArgs *args) { + RzCmdStatus res = R_CMD_STATUS_INVALID; - // As old RCorePlugin do not register new commands in RCmd, we have no + // As old RzCorePlugin do not register new commands in RzCmd, we have no // way of knowing if one of those is able to handle the input, so we // have to pass the input to all of them before looking into the - // RCmdDesc tree - RListIter *iter; - RCorePlugin *cp; - char *exec_string = r_cmd_parsed_args_execstr (args); - r_list_foreach (cmd->plist, iter, cp) { + // RzCmdDesc tree + RzListIter *iter; + RzCorePlugin *cp; + char *exec_string = rz_cmd_parsed_args_execstr (args); + rz_list_foreach (cmd->plist, iter, cp) { if (cp->call && cp->call (cmd->data, exec_string)) { res = R_CMD_STATUS_OK; break; @@ -398,7 +398,7 @@ R_API RCmdStatus r_cmd_call_parsed_args(RCmd *cmd, RCmdParsedArgs *args) { return res; } - RCmdDesc *cd = r_cmd_get_desc (cmd, r_cmd_parsed_args_cmd (args)); + RzCmdDesc *cd = rz_cmd_get_desc (cmd, rz_cmd_parsed_args_cmd (args)); if (!cd) { return R_CMD_STATUS_INVALID; } @@ -417,13 +417,13 @@ R_API RCmdStatus r_cmd_call_parsed_args(RCmd *cmd, RCmdParsedArgs *args) { } break; case R_CMD_DESC_TYPE_OLDINPUT: - exec_string = r_cmd_parsed_args_execstr (args); + exec_string = rz_cmd_parsed_args_execstr (args); res = int2cmdstatus (cd->d.oldinput_data.cb (cmd->data, exec_string + strlen (cd->name))); R_FREE (exec_string); break; default: res = R_CMD_STATUS_INVALID; - R_LOG_ERROR ("RCmdDesc type not handled\n"); + R_LOG_ERROR ("RzCmdDesc type not handled\n"); break; } return res; @@ -433,79 +433,79 @@ static size_t strlen0(const char *s) { return s? strlen (s): 0; } -static void fill_children_chars(RStrBuf *sb, RCmdDesc *cd) { +static void fill_children_chars(RStrBuf *sb, RzCmdDesc *cd) { if (cd->help->options) { - r_strbuf_append (sb, cd->help->options); + rz_strbuf_append (sb, cd->help->options); return; } RStrBuf csb; - r_strbuf_init (&csb); + rz_strbuf_init (&csb); void **it; - r_cmd_desc_children_foreach (cd, it) { - RCmdDesc *child = *(RCmdDesc **)it; - if (r_str_startswith (child->name, cd->name) && strlen (child->name) == strlen (cd->name) + 1) { - r_strbuf_appendf (&csb, "%c", child->name[strlen (cd->name)]); + rz_cmd_desc_children_foreach (cd, it) { + RzCmdDesc *child = *(RzCmdDesc **)it; + if (rz_str_startswith (child->name, cd->name) && strlen (child->name) == strlen (cd->name) + 1) { + rz_strbuf_appendf (&csb, "%c", child->name[strlen (cd->name)]); } } - if (r_strbuf_is_empty (&csb) || r_strbuf_length (&csb) >= MAX_CHILDREN_SHOW) { - r_strbuf_fini (&csb); - r_strbuf_set (&csb, "?"); + if (rz_strbuf_is_empty (&csb) || rz_strbuf_length (&csb) >= MAX_CHILDREN_SHOW) { + rz_strbuf_fini (&csb); + rz_strbuf_set (&csb, "?"); } - if (!cd->n_children || r_cmd_desc_has_handler (cd)) { - r_strbuf_prepend (&csb, "["); - r_strbuf_append (&csb, "]"); + if (!cd->n_children || rz_cmd_desc_has_handler (cd)) { + rz_strbuf_prepend (&csb, "["); + rz_strbuf_append (&csb, "]"); } else { - r_strbuf_prepend (&csb, "<"); - r_strbuf_append (&csb, ">"); + rz_strbuf_prepend (&csb, "<"); + rz_strbuf_append (&csb, ">"); } - r_strbuf_append (sb, r_strbuf_drain_nofree (&csb)); + rz_strbuf_append (sb, rz_strbuf_drain_nofree (&csb)); } -static bool show_children_shortcut(RCmdDesc *cd) { +static bool show_children_shortcut(RzCmdDesc *cd) { return cd->n_children || cd->help->options || cd->type == R_CMD_DESC_TYPE_OLDINPUT; } -static void fill_usage_strbuf(RStrBuf *sb, RCmdDesc *cd, bool use_color) { - RCons *cons = r_cons_singleton (); +static void fill_usage_strbuf(RStrBuf *sb, RzCmdDesc *cd, bool use_color) { + RzCons *cons = rz_cons_singleton (); const char *pal_label_color = use_color? cons->context->pal.label: "", *pal_args_color = use_color? cons->context->pal.args: "", *pal_input_color = use_color? cons->context->pal.input: "", *pal_help_color = use_color? cons->context->pal.help: "", *pal_reset = use_color? cons->context->pal.reset: ""; - r_strbuf_appendf (sb, "%sUsage: %s", pal_label_color, pal_reset); + rz_strbuf_appendf (sb, "%sUsage: %s", pal_label_color, pal_reset); if (cd->help->usage) { - r_strbuf_appendf (sb, "%s%s%s", cd->help->usage, pal_args_color, pal_reset); + rz_strbuf_appendf (sb, "%s%s%s", cd->help->usage, pal_args_color, pal_reset); } else { - r_strbuf_appendf (sb, "%s%s", pal_input_color, cd->name); + rz_strbuf_appendf (sb, "%s%s", pal_input_color, cd->name); if (show_children_shortcut (cd)) { - r_strbuf_append (sb, pal_reset); + rz_strbuf_append (sb, pal_reset); fill_children_chars (sb, cd); } if (R_STR_ISNOTEMPTY (cd->help->args_str)) { - r_strbuf_appendf (sb, "%s%s%s", pal_args_color, cd->help->args_str, pal_reset); + rz_strbuf_appendf (sb, "%s%s%s", pal_args_color, cd->help->args_str, pal_reset); } } if (cd->help->summary) { - r_strbuf_appendf (sb, " %s# %s%s", pal_help_color, cd->help->summary, pal_reset); + rz_strbuf_appendf (sb, " %s# %s%s", pal_help_color, cd->help->summary, pal_reset); } - r_strbuf_append (sb, "\n"); + rz_strbuf_append (sb, "\n"); } -static size_t calc_padding_len(RCmdDesc *cd) { +static size_t calc_padding_len(RzCmdDesc *cd) { size_t name_len = strlen (cd->name); size_t args_len = 0; size_t children_length = 0; if (show_children_shortcut (cd)) { RStrBuf sb; - r_strbuf_init (&sb); + rz_strbuf_init (&sb); fill_children_chars (&sb, cd); - children_length += r_strbuf_length (&sb); - r_strbuf_fini (&sb); + children_length += rz_strbuf_length (&sb); + rz_strbuf_fini (&sb); } if (R_STR_ISNOTEMPTY (cd->help->args_str)) { args_len = strlen0 (cd->help->args_str); @@ -513,102 +513,102 @@ static size_t calc_padding_len(RCmdDesc *cd) { return name_len + args_len + children_length; } -static size_t update_max_len(RCmdDesc *cd, size_t max_len) { +static size_t update_max_len(RzCmdDesc *cd, size_t max_len) { size_t val = calc_padding_len (cd); return val > max_len? val: max_len; } -static void print_child_help(RStrBuf *sb, RCmdDesc *cd, size_t max_len, bool use_color) { +static void print_child_help(RStrBuf *sb, RzCmdDesc *cd, size_t max_len, bool use_color) { size_t str_len = calc_padding_len (cd); size_t padding = str_len < max_len? max_len - str_len: 0; const char *cd_summary = cd->help->summary? cd->help->summary: ""; - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); const char *pal_args_color = use_color? cons->context->pal.args: "", *pal_opt_color = use_color? cons->context->pal.reset: "", *pal_help_color = use_color? cons->context->pal.help: "", *pal_input_color = use_color? cons->context->pal.input: "", *pal_reset = use_color? cons->context->pal.reset: ""; - r_strbuf_appendf (sb, "| %s%s", pal_input_color, cd->name); + rz_strbuf_appendf (sb, "| %s%s", pal_input_color, cd->name); if (show_children_shortcut (cd)) { - r_strbuf_append (sb, pal_opt_color); + rz_strbuf_append (sb, pal_opt_color); fill_children_chars (sb, cd); } if (R_STR_ISNOTEMPTY (cd->help->args_str)) { - r_strbuf_appendf (sb, "%s%s", pal_args_color, cd->help->args_str); + rz_strbuf_appendf (sb, "%s%s", pal_args_color, cd->help->args_str); } - r_strbuf_appendf (sb, " %*s%s# %s%s\n", padding, "", pal_help_color, cd_summary, pal_reset); + rz_strbuf_appendf (sb, " %*s%s# %s%s\n", padding, "", pal_help_color, cd_summary, pal_reset); } -static char *argv_group_get_help(RCmd *cmd, RCmdDesc *cd, bool use_color) { - RStrBuf *sb = r_strbuf_new (NULL); +static char *argv_group_get_help(RzCmd *cmd, RzCmdDesc *cd, bool use_color) { + RStrBuf *sb = rz_strbuf_new (NULL); fill_usage_strbuf (sb, cd, use_color); void **it_cd; size_t max_len = 0; - r_cmd_desc_children_foreach (cd, it_cd) { - RCmdDesc *child = *(RCmdDesc **)it_cd; + rz_cmd_desc_children_foreach (cd, it_cd) { + RzCmdDesc *child = *(RzCmdDesc **)it_cd; max_len = update_max_len (child, max_len); } - r_cmd_desc_children_foreach (cd, it_cd) { - RCmdDesc *child = *(RCmdDesc **)it_cd; + rz_cmd_desc_children_foreach (cd, it_cd) { + RzCmdDesc *child = *(RzCmdDesc **)it_cd; print_child_help (sb, child, max_len, use_color); } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -static char *argv_get_help(RCmd *cmd, RCmdDesc *cd, RCmdParsedArgs *a, size_t detail, bool use_color) { - RCons *cons = r_cons_singleton (); +static char *argv_get_help(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *a, size_t detail, bool use_color) { + RzCons *cons = rz_cons_singleton (); const char *pal_help_color = use_color? cons->context->pal.help: "", *pal_input_color = use_color? cons->context->pal.input: "", *pal_label_color = use_color? cons->context->pal.label: "", *pal_reset = use_color? cons->context->pal.reset: ""; - RStrBuf *sb = r_strbuf_new (NULL); + RStrBuf *sb = rz_strbuf_new (NULL); fill_usage_strbuf (sb, cd, use_color); switch (detail) { case 1: - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); case 2: if (cd->help->description) { - r_strbuf_appendf (sb, "\n%s\n", cd->help->description); + rz_strbuf_appendf (sb, "\n%s\n", cd->help->description); } if (cd->help->examples) { - r_strbuf_appendf (sb, "\n%sExamples:%s\n", pal_label_color, pal_reset); - const RCmdDescExample *it = cd->help->examples; + rz_strbuf_appendf (sb, "\n%sExamples:%s\n", pal_label_color, pal_reset); + const RzCmdDescExample *it = cd->help->examples; while (it->example) { - r_strbuf_appendf (sb, "| %s%s%s %s# %s%s\n", pal_input_color, + rz_strbuf_appendf (sb, "| %s%s%s %s# %s%s\n", pal_input_color, it->example, pal_reset, pal_help_color, it->comment, pal_reset); it++; } } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); default: - r_strbuf_free (sb); + rz_strbuf_free (sb); return NULL; } } -static char *oldinput_get_help(RCmd *cmd, RCmdDesc *cd, RCmdParsedArgs *a) { +static char *oldinput_get_help(RzCmd *cmd, RzCmdDesc *cd, RzCmdParsedArgs *a) { const char *s = NULL; - r_cons_push (); - RCmdStatus status = r_cmd_call_parsed_args (cmd, a); + rz_cons_push (); + RzCmdStatus status = rz_cmd_call_parsed_args (cmd, a); if (status == R_CMD_STATUS_OK) { - r_cons_filter (); - s = r_cons_get_buffer (); + rz_cons_filter (); + s = rz_cons_get_buffer (); } char *res = strdup (s? s: ""); - r_cons_pop (); + rz_cons_pop (); return res; } -R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color) { - char *cmdid = strdup (r_cmd_parsed_args_cmd (args)); +RZ_API char *rz_cmd_get_help(RzCmd *cmd, RzCmdParsedArgs *args, bool use_color) { + char *cmdid = strdup (rz_cmd_parsed_args_cmd (args)); char *cmdid_p = cmdid + strlen (cmdid) - 1; size_t detail = 0; while (cmdid_p >= cmdid && *cmdid_p == '?') { @@ -623,7 +623,7 @@ R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color) { return NULL; } - RCmdDesc *cd = cmdid_p >= cmdid? r_cmd_get_desc (cmd, cmdid): r_cmd_get_root (cmd); + RzCmdDesc *cd = cmdid_p >= cmdid? rz_cmd_get_desc (cmd, cmdid): rz_cmd_get_root (cmd); free (cmdid); if (!cd || !cd->help) { return NULL; @@ -636,7 +636,7 @@ R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color) { } // fallthrough case R_CMD_DESC_TYPE_ARGV: - if (detail == 1 && !r_pvector_empty (&cd->children)) { + if (detail == 1 && !rz_pvector_empty (&cd->children)) { if (args->argc > 1) { return NULL; } @@ -646,7 +646,7 @@ R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color) { case R_CMD_DESC_TYPE_OLDINPUT: return oldinput_get_help (cmd, cd, args); case R_CMD_DESC_TYPE_INNER: - r_warn_if_reached (); + rz_warn_if_reached (); return NULL; } return NULL; @@ -654,11 +654,11 @@ R_API char *r_cmd_get_help(RCmd *cmd, RCmdParsedArgs *args, bool use_color) { /** macro.c **/ -R_API RCmdMacroItem *r_cmd_macro_item_new(void) { - return R_NEW0 (RCmdMacroItem); +RZ_API RzCmdMacroItem *rz_cmd_macro_item_new(void) { + return R_NEW0 (RzCmdMacroItem); } -R_API void r_cmd_macro_item_free(RCmdMacroItem *item) { +RZ_API void rz_cmd_macro_item_free(RzCmdMacroItem *item) { if (!item) { return; } @@ -668,7 +668,7 @@ R_API void r_cmd_macro_item_free(RCmdMacroItem *item) { free (item); } -R_API void r_cmd_macro_init(RCmdMacro *mac) { +RZ_API void rz_cmd_macro_init(RzCmdMacro *mac) { mac->counter = 0; mac->_brk_value = 0; mac->brk_value = &mac->_brk_value; @@ -676,30 +676,30 @@ R_API void r_cmd_macro_init(RCmdMacro *mac) { mac->num = NULL; mac->user = NULL; mac->cmd = NULL; - mac->macros = r_list_newf ((RListFree)r_cmd_macro_item_free); + mac->macros = rz_list_newf ((RzListFree)rz_cmd_macro_item_free); } -R_API void r_cmd_macro_fini(RCmdMacro *mac) { - r_list_free (mac->macros); +RZ_API void rz_cmd_macro_fini(RzCmdMacro *mac) { + rz_list_free (mac->macros); mac->macros = NULL; } // XXX add support single line function definitions // XXX add support for single name multiple nargs macros -R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { - struct r_cmd_macro_item_t *macro; +RZ_API int rz_cmd_macro_add(RzCmdMacro *mac, const char *oname) { + struct rz_cmd_macro_item_t *macro; char *name, *args = NULL; //char buf[R_CMD_MAXLEN]; - RCmdMacroItem *m; + RzCmdMacroItem *m; int macro_update; - RListIter *iter; + RzListIter *iter; char *pbody; // char *bufp; char *ptr; int lidx; if (!*oname) { - r_cmd_macro_list (mac); + rz_cmd_macro_list (mac); return 0; } @@ -719,7 +719,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { pbody++; if (*name && name[1] && name[strlen (name)-1]==')') { - eprintf ("r_cmd_macro_add: missing macro body?\n"); + eprintf ("rz_cmd_macro_add: missing macro body?\n"); free (name); return -1; } @@ -731,7 +731,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { args = ptr +1; } macro_update = 0; - r_list_foreach (mac->macros, iter, m) { + rz_list_foreach (mac->macros, iter, m) { if (!strcmp (name, m->name)) { macro = m; // keep macro->name @@ -745,7 +745,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { *ptr = ' '; } if (!macro) { - macro = r_cmd_macro_item_new (); + macro = rz_cmd_macro_item_new (); if (!macro) { free (name); return 0; @@ -764,7 +764,7 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { ptr = strchr (macro->name, ' '); if (ptr != NULL) { *ptr = '\0'; - macro->nargs = r_str_word_set0 (ptr+1); + macro->nargs = rz_str_word_set0 (ptr+1); } for (lidx = 0; pbody[lidx]; lidx++) { @@ -777,15 +777,15 @@ R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) { strncpy (macro->code, pbody, macro->codelen); macro->code[macro->codelen-1] = 0; if (macro_update == 0) { - r_list_append (mac->macros, macro); + rz_list_append (mac->macros, macro); } free (name); return 0; } -R_API int r_cmd_macro_rm(RCmdMacro *mac, const char *_name) { - RListIter *iter; - RCmdMacroItem *m; +RZ_API int rz_cmd_macro_rm(RzCmdMacro *mac, const char *_name) { + RzListIter *iter; + RzCmdMacroItem *m; char *name = strdup (_name); if (!name) { return false; @@ -795,9 +795,9 @@ R_API int r_cmd_macro_rm(RCmdMacro *mac, const char *_name) { *ptr = '\0'; } bool ret = false; - r_list_foreach (mac->macros, iter, m) { + rz_list_foreach (mac->macros, iter, m) { if (!strcmp (m->name, name)) { - r_list_delete (mac->macros, iter); + rz_list_delete (mac->macros, iter); eprintf ("Macro '%s' removed.\n", name); ret = true; break; @@ -807,12 +807,12 @@ R_API int r_cmd_macro_rm(RCmdMacro *mac, const char *_name) { return ret; } -// TODO: use mac->cb_printf which is r_cons_printf at the end -R_API void r_cmd_macro_list(RCmdMacro *mac) { - RCmdMacroItem *m; +// TODO: use mac->cb_printf which is rz_cons_printf at the end +RZ_API void rz_cmd_macro_list(RzCmdMacro *mac) { + RzCmdMacroItem *m; int j, idx = 0; - RListIter *iter; - r_list_foreach (mac->macros, iter, m) { + RzListIter *iter; + rz_list_foreach (mac->macros, iter, m) { mac->cb_printf ("%d (%s %s; ", idx, m->name, m->args); for (j=0; m->code[j]; j++) { if (m->code[j] == '\n') { @@ -826,12 +826,12 @@ R_API void r_cmd_macro_list(RCmdMacro *mac) { } } -// TODO: use mac->cb_printf which is r_cons_printf at the end -R_API void r_cmd_macro_meta(RCmdMacro *mac) { - RCmdMacroItem *m; +// TODO: use mac->cb_printf which is rz_cons_printf at the end +RZ_API void rz_cmd_macro_meta(RzCmdMacro *mac) { + RzCmdMacroItem *m; int j; - RListIter *iter; - r_list_foreach (mac->macros, iter, m) { + RzListIter *iter; + rz_list_foreach (mac->macros, iter, m) { mac->cb_printf ("(%s %s, ", m->name, m->args); for (j=0; m->code[j]; j++) { if (m->code[j] == '\n') { @@ -857,7 +857,7 @@ R_API void r_cmd_macro_meta(RCmdMacro *mac) { .(define patata 3) #endif -R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args, int nargs) { +RZ_API int rz_cmd_macro_cmd_args(RzCmdMacro *mac, const char *ptr, const char *args, int nargs) { int i, j; char *pcmd, cmd[R_CMD_MAXLEN]; const char *arg = args; @@ -867,7 +867,7 @@ R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args if (ptr[j+1]>='0' && ptr[j+1]<='9') { int wordlen; int w = ptr[j+1]-'0'; - const char *word = r_str_word_get0 (arg, w); + const char *word = rz_str_word_get0 (arg, w); if (word && *word) { wordlen = strlen (word); if ((i + wordlen + 1) >= sizeof (cmd)) { @@ -909,7 +909,7 @@ R_API int r_cmd_macro_cmd_args(RCmdMacro *mac, const char *ptr, const char *args return xx; } -R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, int *labels_n, char *ptr) { +RZ_API char *rz_cmd_macro_label_process(RzCmdMacro *mac, RzCmdMacroLabel *labels, int *labels_n, char *ptr) { int i; for (; *ptr == ' '; ptr++) { ; @@ -982,16 +982,16 @@ R_API char *r_cmd_macro_label_process(RCmdMacro *mac, RCmdMacroLabel *labels, in } /* TODO: add support for spaced arguments */ -R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { +RZ_API int rz_cmd_macro_call(RzCmdMacro *mac, const char *name) { char *args; int nargs = 0; char *str, *ptr, *ptr2; - RListIter *iter; + RzListIter *iter; static int macro_level = 0; - RCmdMacroItem *m; + RzCmdMacroItem *m; /* labels */ int labels_n = 0; - struct r_cmd_macro_label_t labels[MACRO_LABELS]; + struct rz_cmd_macro_label_t labels[MACRO_LABELS]; str = strdup (name); if (!str) { @@ -1011,7 +1011,7 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { if (args) { *args = '\0'; args++; - nargs = r_str_word_set0 (args); + nargs = rz_str_word_set0 (args); } macro_level++; @@ -1026,8 +1026,8 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { *ptr = 0; } - r_cons_break_push (NULL, NULL); - r_list_foreach (mac->macros, iter, m) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (mac->macros, iter, m) { if (!strcmp (str, m->name)) { char *ptr = m->code; char *end = strchr (ptr, '\n'); @@ -1035,7 +1035,7 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { eprintf ("Macro '%s' expects %d args, not %d\n", m->name, m->nargs, nargs); macro_level --; free (str); - r_cons_break_pop (); + rz_cons_break_pop (); return false; } mac->brk = 0; @@ -1043,18 +1043,18 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { if (end) { *end = '\0'; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { eprintf ("Interrupted at (%s)\n", ptr); if (end) { *end = '\n'; } free (str); - r_cons_break_pop (); + rz_cons_break_pop (); return false; } - r_cons_flush (); + rz_cons_flush (); /* Label handling */ - ptr2 = r_cmd_macro_label_process (mac, &(labels[0]), &labels_n, ptr); + ptr2 = rz_cmd_macro_label_process (mac, &(labels[0]), &labels_n, ptr); if (!ptr2) { eprintf ("Oops. invalid label name\n"); break; @@ -1069,13 +1069,13 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { /* Command execution */ if (*ptr) { mac->num->value = value; - int r = r_cmd_macro_cmd_args (mac, ptr, args, nargs); + int r = rz_cmd_macro_cmd_args (mac, ptr, args, nargs); // TODO: handle quit? r == 0?? // quit, exits the macro. like a break value = mac->num->value; if (r < 0) { free (str); - r_cons_break_pop (); + rz_cons_break_pop (); return r; } } @@ -1102,25 +1102,25 @@ R_API int r_cmd_macro_call(RCmdMacro *mac, const char *name) { macro_level--; free (str); out_clean: - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -R_API int r_cmd_macro_break(RCmdMacro *mac, const char *value) { +RZ_API int rz_cmd_macro_break(RzCmdMacro *mac, const char *value) { mac->brk = 1; mac->brk_value = NULL; - mac->_brk_value = (ut64)r_num_math (mac->num, value); + mac->_brk_value = (ut64)rz_num_math (mac->num, value); if (value && *value) { mac->brk_value = &mac->_brk_value; } return 0; } -/* RCmdParsedArgs */ +/* RzCmdParsedArgs */ -R_API RCmdParsedArgs *r_cmd_parsed_args_new(const char *cmd, int n_args, char **args) { - r_return_val_if_fail (cmd && n_args >= 0, NULL); - RCmdParsedArgs *res = R_NEW0 (RCmdParsedArgs); +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_new(const char *cmd, int n_args, char **args) { + rz_return_val_if_fail (cmd && n_args >= 0, NULL); + RzCmdParsedArgs *res = R_NEW0 (RzCmdParsedArgs); res->has_space_after_cmd = true; res->argc = n_args + 1; res->argv = R_NEWS0 (char *, res->argc); @@ -1132,15 +1132,15 @@ R_API RCmdParsedArgs *r_cmd_parsed_args_new(const char *cmd, int n_args, char ** return res; } -R_API RCmdParsedArgs *r_cmd_parsed_args_newcmd(const char *cmd) { - return r_cmd_parsed_args_new (cmd, 0, NULL); +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_newcmd(const char *cmd) { + return rz_cmd_parsed_args_new (cmd, 0, NULL); } -R_API RCmdParsedArgs *r_cmd_parsed_args_newargs(int n_args, char **args) { - return r_cmd_parsed_args_new ("", n_args, args); +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_newargs(int n_args, char **args) { + return rz_cmd_parsed_args_new ("", n_args, args); } -R_API void r_cmd_parsed_args_free(RCmdParsedArgs *a) { +RZ_API void rz_cmd_parsed_args_free(RzCmdParsedArgs *a) { if (!a) { return; } @@ -1161,8 +1161,8 @@ static void free_array(char **arr, int n) { free (arr); } -R_API bool r_cmd_parsed_args_setargs(RCmdParsedArgs *a, int n_args, char **args) { - r_return_val_if_fail (a && a->argv && a->argv[0], false); +RZ_API bool rz_cmd_parsed_args_setargs(RzCmdParsedArgs *a, int n_args, char **args) { + rz_return_val_if_fail (a && a->argv && a->argv[0], false); char **tmp = R_NEWS0 (char *, n_args + 1); if (!tmp) { return false; @@ -1184,8 +1184,8 @@ err: return false; } -R_API bool r_cmd_parsed_args_setcmd(RCmdParsedArgs *a, const char *cmd) { - r_return_val_if_fail (a && a->argv && a->argv[0], false); +RZ_API bool rz_cmd_parsed_args_setcmd(RzCmdParsedArgs *a, const char *cmd) { + rz_return_val_if_fail (a && a->argv && a->argv[0], false); char *tmp = strdup (cmd); if (!tmp) { return false; @@ -1195,42 +1195,42 @@ R_API bool r_cmd_parsed_args_setcmd(RCmdParsedArgs *a, const char *cmd) { return true; } -static void parsed_args_iterateargs(RCmdParsedArgs *a, RStrBuf *sb) { +static void parsed_args_iterateargs(RzCmdParsedArgs *a, RStrBuf *sb) { int i; for (i = 1; i < a->argc; i++) { if (i > 1) { - r_strbuf_append (sb, " "); + rz_strbuf_append (sb, " "); } - r_strbuf_append (sb, a->argv[i]); + rz_strbuf_append (sb, a->argv[i]); } } -R_API char *r_cmd_parsed_args_argstr(RCmdParsedArgs *a) { - r_return_val_if_fail (a && a->argv && a->argv[0], NULL); - RStrBuf *sb = r_strbuf_new (""); +RZ_API char *rz_cmd_parsed_args_argstr(RzCmdParsedArgs *a) { + rz_return_val_if_fail (a && a->argv && a->argv[0], NULL); + RStrBuf *sb = rz_strbuf_new (""); parsed_args_iterateargs (a, sb); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_cmd_parsed_args_execstr(RCmdParsedArgs *a) { - r_return_val_if_fail (a && a->argv && a->argv[0], NULL); - RStrBuf *sb = r_strbuf_new (a->argv[0]); +RZ_API char *rz_cmd_parsed_args_execstr(RzCmdParsedArgs *a) { + rz_return_val_if_fail (a && a->argv && a->argv[0], NULL); + RStrBuf *sb = rz_strbuf_new (a->argv[0]); if (a->argc > 1 && a->has_space_after_cmd) { - r_strbuf_append (sb, " "); + rz_strbuf_append (sb, " "); } parsed_args_iterateargs (a, sb); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API const char *r_cmd_parsed_args_cmd(RCmdParsedArgs *a) { - r_return_val_if_fail (a && a->argv && a->argv[0], NULL); +RZ_API const char *rz_cmd_parsed_args_cmd(RzCmdParsedArgs *a) { + rz_return_val_if_fail (a && a->argv && a->argv[0], NULL); return a->argv[0]; } -/* RCmdDescriptor */ +/* RzCmdDescriptor */ -static RCmdDesc *argv_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArgvCb cb, const RCmdDescHelp *help, bool ht_insert) { - RCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_ARGV, name, help, ht_insert); +static RzCmdDesc *argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, bool ht_insert) { + RzCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_ARGV, name, help, ht_insert); if (!res) { return NULL; } @@ -1239,28 +1239,28 @@ static RCmdDesc *argv_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArg return res; } -R_API RCmdDesc *r_cmd_desc_argv_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArgvCb cb, const RCmdDescHelp *help) { - r_return_val_if_fail (cmd && parent && name, NULL); +RZ_API RzCmdDesc *rz_cmd_desc_argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help) { + rz_return_val_if_fail (cmd && parent && name, NULL); return argv_new (cmd, parent, name, cb, help, true); } -R_API RCmdDesc *r_cmd_desc_inner_new(RCmd *cmd, RCmdDesc *parent, const char *name, const RCmdDescHelp *help) { - r_return_val_if_fail (cmd && parent && name, NULL); +RZ_API RzCmdDesc *rz_cmd_desc_inner_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help) { + rz_return_val_if_fail (cmd && parent && name, NULL); return create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_INNER, name, help, false); } -R_API RCmdDesc *r_cmd_desc_group_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdArgvCb cb, const RCmdDescHelp *help, const RCmdDescHelp *group_help) { - r_return_val_if_fail (cmd && parent && name, NULL); - RCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_GROUP, name, group_help, true); +RZ_API RzCmdDesc *rz_cmd_desc_group_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help) { + rz_return_val_if_fail (cmd && parent && name, NULL); + RzCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_GROUP, name, group_help, true); if (!res) { return NULL; } - RCmdDesc *exec_cd = NULL; + RzCmdDesc *exec_cd = NULL; if (cb && help) { exec_cd = argv_new (cmd, res, name, cb, help, false); if (!exec_cd) { - r_cmd_desc_remove (cmd, res); + rz_cmd_desc_remove (cmd, res); return NULL; } } @@ -1269,9 +1269,9 @@ R_API RCmdDesc *r_cmd_desc_group_new(RCmd *cmd, RCmdDesc *parent, const char *na return res; } -R_API RCmdDesc *r_cmd_desc_oldinput_new(RCmd *cmd, RCmdDesc *parent, const char *name, RCmdCb cb, const RCmdDescHelp *help) { - r_return_val_if_fail (cmd && parent && name && cb, NULL); - RCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_OLDINPUT, name, help, true); +RZ_API RzCmdDesc *rz_cmd_desc_oldinput_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdCb cb, const RzCmdDescHelp *help) { + rz_return_val_if_fail (cmd && parent && name && cb, NULL); + RzCmdDesc *res = create_cmd_desc (cmd, parent, R_CMD_DESC_TYPE_OLDINPUT, name, help, true); if (!res) { return NULL; } @@ -1279,13 +1279,13 @@ R_API RCmdDesc *r_cmd_desc_oldinput_new(RCmd *cmd, RCmdDesc *parent, const char return res; } -R_API RCmdDesc *r_cmd_desc_parent(RCmdDesc *cd) { - r_return_val_if_fail (cd, NULL); +RZ_API RzCmdDesc *rz_cmd_desc_parent(RzCmdDesc *cd) { + rz_return_val_if_fail (cd, NULL); return cd->parent; } -R_API bool r_cmd_desc_has_handler(RCmdDesc *cd) { - r_return_val_if_fail (cd, false); +RZ_API bool rz_cmd_desc_has_handler(RzCmdDesc *cd) { + rz_return_val_if_fail (cd, false); switch (cd->type) { case R_CMD_DESC_TYPE_ARGV: return cd->d.argv_data.cb; @@ -1294,13 +1294,13 @@ R_API bool r_cmd_desc_has_handler(RCmdDesc *cd) { case R_CMD_DESC_TYPE_INNER: return false; case R_CMD_DESC_TYPE_GROUP: - return cd->d.group_data.exec_cd && r_cmd_desc_has_handler (cd->d.group_data.exec_cd); + return cd->d.group_data.exec_cd && rz_cmd_desc_has_handler (cd->d.group_data.exec_cd); } return false; } -R_API bool r_cmd_desc_remove(RCmd *cmd, RCmdDesc *cd) { - r_return_val_if_fail (cmd && cd, false); +RZ_API bool rz_cmd_desc_remove(RzCmd *cmd, RzCmdDesc *cd) { + rz_return_val_if_fail (cmd && cd, false); if (cd->parent) { cmd_desc_unset_parent (cd); } diff --git a/libr/core/cmd_cmp.c b/librz/core/cmd_cmp.c similarity index 61% rename from libr/core/cmd_cmp.c rename to librz/core/cmd_cmp.c index e7b875b0d7..be18345469 100644 --- a/libr/core/cmd_cmp.c +++ b/librz/core/cmd_cmp.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include "r_core.h" +#include "rz_core.h" static const char *help_msg_c[] = { "Usage:", "c[?dfx] [argument]", " # Compare", @@ -32,20 +32,20 @@ static const char *help_msg_c[] = { NULL }; -static void cmd_cmp_init(RCore *core, RCmdDesc *parent) { +static void cmd_cmp_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, c); } -R_API void r_core_cmpwatch_free(RCoreCmpWatcher *w) { +RZ_API void rz_core_cmpwatch_free(RzCoreCmpWatcher *w) { free (w->ndata); free (w->odata); free (w); } -R_API RCoreCmpWatcher *r_core_cmpwatch_get(RCore *core, ut64 addr) { - RListIter *iter; - RCoreCmpWatcher *w; - r_list_foreach (core->watchers, iter, w) { +RZ_API RzCoreCmpWatcher *rz_core_cmpwatch_get(RzCore *core, ut64 addr) { + RzListIter *iter; + RzCoreCmpWatcher *w; + rz_list_foreach (core->watchers, iter, w) { if (addr == w->addr) { return w; } @@ -53,14 +53,14 @@ R_API RCoreCmpWatcher *r_core_cmpwatch_get(RCore *core, ut64 addr) { return NULL; } -R_API int r_core_cmpwatch_add(RCore *core, ut64 addr, int size, const char *cmd) { - RCoreCmpWatcher *cmpw; +RZ_API int rz_core_cmpwatch_add(RzCore *core, ut64 addr, int size, const char *cmd) { + RzCoreCmpWatcher *cmpw; if (size < 1) { return false; } - cmpw = r_core_cmpwatch_get (core, addr); + cmpw = rz_core_cmpwatch_get (core, addr); if (!cmpw) { - cmpw = R_NEW (RCoreCmpWatcher); + cmpw = R_NEW (RzCoreCmpWatcher); if (!cmpw) { return false; } @@ -74,72 +74,72 @@ R_API int r_core_cmpwatch_add(RCore *core, ut64 addr, int size, const char *cmd) free (cmpw); return false; } - r_io_read_at (core->io, addr, cmpw->ndata, size); - r_list_append (core->watchers, cmpw); + rz_io_read_at (core->io, addr, cmpw->ndata, size); + rz_list_append (core->watchers, cmpw); return true; } -R_API int r_core_cmpwatch_del(RCore *core, ut64 addr) { +RZ_API int rz_core_cmpwatch_del(RzCore *core, ut64 addr) { int ret = false; - RCoreCmpWatcher *w; - RListIter *iter, *iter2; - r_list_foreach_safe (core->watchers, iter, iter2, w) { + RzCoreCmpWatcher *w; + RzListIter *iter, *iter2; + rz_list_foreach_safe (core->watchers, iter, iter2, w) { if (w->addr == addr || addr == UT64_MAX) { - r_list_delete (core->watchers, iter); + rz_list_delete (core->watchers, iter); ret = true; } } return ret; } -R_API int r_core_cmpwatch_show(RCore *core, ut64 addr, int mode) { +RZ_API int rz_core_cmpwatch_show(RzCore *core, ut64 addr, int mode) { char cmd[128]; - RListIter *iter; - RCoreCmpWatcher *w; - r_list_foreach (core->watchers, iter, w) { + RzListIter *iter; + RzCoreCmpWatcher *w; + rz_list_foreach (core->watchers, iter, w) { int is_diff = w->odata? memcmp (w->odata, w->ndata, w->size): 0; switch (mode) { case '*': - r_cons_printf ("cw 0x%08"PFMT64x " %d %s%s\n", + rz_cons_printf ("cw 0x%08"PFMT64x " %d %s%s\n", w->addr, w->size, w->cmd, is_diff? " # differs": ""); break; case 'd': // diff if (is_diff) { - r_cons_printf ("0x%08"PFMT64x " has changed\n", w->addr); + rz_cons_printf ("0x%08"PFMT64x " has changed\n", w->addr); } case 'o': // old contents // use tmpblocksize default: - r_cons_printf ("0x%08"PFMT64x "%s\n", w->addr, is_diff? " modified": ""); + rz_cons_printf ("0x%08"PFMT64x "%s\n", w->addr, is_diff? " modified": ""); snprintf (cmd, sizeof (cmd), "%s@%"PFMT64d "!%d", w->cmd, w->addr, w->size); - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); break; } } return false; } -R_API int r_core_cmpwatch_update(RCore *core, ut64 addr) { - RCoreCmpWatcher *w; - RListIter *iter; - r_list_foreach (core->watchers, iter, w) { +RZ_API int rz_core_cmpwatch_update(RzCore *core, ut64 addr) { + RzCoreCmpWatcher *w; + RzListIter *iter; + rz_list_foreach (core->watchers, iter, w) { free (w->odata); w->odata = w->ndata; w->ndata = malloc (w->size); if (!w->ndata) { return false; } - r_io_read_at (core->io, w->addr, w->ndata, w->size); + rz_io_read_at (core->io, w->addr, w->ndata, w->size); } - return !r_list_empty (core->watchers); + return !rz_list_empty (core->watchers); } -R_API int r_core_cmpwatch_revert(RCore *core, ut64 addr) { - RCoreCmpWatcher *w; +RZ_API int rz_core_cmpwatch_revert(RzCore *core, ut64 addr) { + RzCoreCmpWatcher *w; int ret = false; - RListIter *iter; - r_list_foreach (core->watchers, iter, w) { + RzListIter *iter; + rz_list_foreach (core->watchers, iter, w) { if (w->addr == addr || addr == UT64_MAX) { if (w->odata) { free (w->ndata); @@ -152,48 +152,48 @@ R_API int r_core_cmpwatch_revert(RCore *core, ut64 addr) { return ret; } -static int radare_compare_words(RCore *core, ut64 of, ut64 od, int len, int ws) { +static int radare_compare_words(RzCore *core, ut64 of, ut64 od, int len, int ws) { int i; - bool useColor = r_config_get_i (core->config, "scr.color") != 0; + bool useColor = rz_config_get_i (core->config, "scr.color") != 0; utAny v0, v1; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; for (i = 0; i < len; i+=ws) { memset (&v0, 0, sizeof (v0)); memset (&v1, 0, sizeof (v1)); - r_io_read_at (core->io, of + i, (ut8*)&v0, ws); - r_io_read_at (core->io, od + i, (ut8*)&v1, ws); + rz_io_read_at (core->io, of + i, (ut8*)&v0, ws); + rz_io_read_at (core->io, od + i, (ut8*)&v1, ws); char ch = (v0.v64 == v1.v64)? '=': '!'; const char *color = useColor? ch == '='? "": pal->graph_false: ""; const char *colorEnd = useColor? Color_RESET: ""; if (useColor) { - r_cons_printf ("%s0x%08" PFMT64x" "Color_RESET, pal->offset, of + i); + rz_cons_printf ("%s0x%08" PFMT64x" "Color_RESET, pal->offset, of + i); } else { - r_cons_printf ("0x%08" PFMT64x" ", of + i); + rz_cons_printf ("0x%08" PFMT64x" ", of + i); } switch (ws) { case 1: - r_cons_printf ("%s0x%02x %c 0x%02x%s\n", color, + rz_cons_printf ("%s0x%02x %c 0x%02x%s\n", color, (ut32)(v0.v8 & 0xff), ch, (ut32)(v1.v8 & 0xff), colorEnd); break; case 2: - r_cons_printf ("%s0x%04hx %c 0x%04hx%s\n", color, + rz_cons_printf ("%s0x%04hx %c 0x%04hx%s\n", color, v0.v16, ch, v1.v16, colorEnd); break; case 4: - r_cons_printf ("%s0x%08"PFMT32x" %c 0x%08"PFMT32x"%s\n", color, + rz_cons_printf ("%s0x%08"PFMT32x" %c 0x%08"PFMT32x"%s\n", color, v0.v32, ch, v1.v32, colorEnd); - //r_core_cmdf (core, "fd@0x%"PFMT64x, v0.v32); + //rz_core_cmdf (core, "fd@0x%"PFMT64x, v0.v32); if (v0.v32 != v1.v32) { - // r_core_cmdf (core, "fd@0x%"PFMT64x, v1.v32); + // rz_core_cmdf (core, "fd@0x%"PFMT64x, v1.v32); } break; case 8: - r_cons_printf ("%s0x%016"PFMT64x" %c 0x%016"PFMT64x"%s\n", + rz_cons_printf ("%s0x%016"PFMT64x" %c 0x%016"PFMT64x"%s\n", color, v0.v64, ch, v1.v64, colorEnd); - //r_core_cmdf (core, "fd@0x%"PFMT64x, v0.v64); + //rz_core_cmdf (core, "fd@0x%"PFMT64x, v0.v64); if (v0.v64 != v1.v64) { - // r_core_cmdf (core, "fd@0x%"PFMT64x, v1.v64); + // rz_core_cmdf (core, "fd@0x%"PFMT64x, v1.v64); } break; } @@ -201,7 +201,7 @@ static int radare_compare_words(RCore *core, ut64 of, ut64 od, int len, int ws) return 0; } -static int radare_compare_unified(RCore *core, ut64 of, ut64 od, int len) { +static int radare_compare_unified(RzCore *core, ut64 of, ut64 od, int len) { int i, min, inc = 16; ut8 *f, *d; if (len < 1) { @@ -216,8 +216,8 @@ static int radare_compare_unified(RCore *core, ut64 of, ut64 od, int len) { free (f); return false; } - r_io_read_at (core->io, of, f, len); - r_io_read_at (core->io, od, d, len); + rz_io_read_at (core->io, of, f, len); + rz_io_read_at (core->io, od, d, len); int headers = B_IS_SET (core->print->flags, R_PRINT_FLAGS_HEADER); if (headers) { B_UNSET (core->print->flags, R_PRINT_FLAGS_HEADER); @@ -225,13 +225,13 @@ static int radare_compare_unified(RCore *core, ut64 of, ut64 od, int len) { for (i = 0; i < len; i += inc) { min = R_MIN (16, (len - i)); if (!memcmp (f + i, d + i, min)) { - r_cons_printf (" "); - r_print_hexdiff (core->print, of + i, f + i, of + i, f + i, min, 0); + rz_cons_printf (" "); + rz_print_hexdiff (core->print, of + i, f + i, of + i, f + i, min, 0); } else { - r_cons_printf ("- "); - r_print_hexdiff (core->print, of + i, f + i, od + i, d + i, min, 0); - r_cons_printf ("+ "); - r_print_hexdiff (core->print, od + i, d + i, of + i, f + i, min, 0); + rz_cons_printf ("- "); + rz_print_hexdiff (core->print, of + i, f + i, od + i, d + i, min, 0); + rz_cons_printf ("+ "); + rz_print_hexdiff (core->print, od + i, d + i, of + i, f + i, min, 0); } } if (headers) { @@ -240,7 +240,7 @@ static int radare_compare_unified(RCore *core, ut64 of, ut64 od, int len) { return true; } -static int radare_compare(RCore *core, const ut8 *f, const ut8 *d, int len, int mode) { +static int radare_compare(RzCore *core, const ut8 *f, const ut8 *d, int len, int mode) { int i, eq = 0; PJ *pj = NULL; if (len < 1) { @@ -263,13 +263,13 @@ static int radare_compare(RCore *core, const ut8 *f, const ut8 *d, int len, int switch (mode) { case 0: - r_cons_printf ("0x%08"PFMT64x " (byte=%.2d) %02x '%c' -> %02x '%c'\n", + rz_cons_printf ("0x%08"PFMT64x " (byte=%.2d) %02x '%c' -> %02x '%c'\n", core->offset + i, i + 1, f[i], (IS_PRINTABLE (f[i]))? f[i]: ' ', d[i], (IS_PRINTABLE (d[i]))? d[i]: ' '); break; case '*': - r_cons_printf ("wx %02x @ 0x%08"PFMT64x "\n", + rz_cons_printf ("wx %02x @ 0x%08"PFMT64x "\n", d[i], core->offset + i); break; @@ -292,12 +292,12 @@ static int radare_compare(RCore *core, const ut8 *f, const ut8 *d, int len, int pj_ki (pj, "total_bytes", len); pj_end (pj); // End array pj_end (pj); // End object - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } return len - eq; } -static void cmd_cmp_watcher(RCore *core, const char *input) { +static void cmd_cmp_watcher(RzCore *core, const char *input) { char *p, *q, *r = NULL; int size = 0; ut64 addr = 0; @@ -307,13 +307,13 @@ static void cmd_cmp_watcher(RCore *core, const char *input) { q = strchr (p, ' '); if (q) { *q++ = 0; - addr = r_num_math (core->num, p); + addr = rz_num_math (core->num, p); r = strchr (q, ' '); if (r) { *r++ = 0; size = atoi (q); } - r_core_cmpwatch_add (core, addr, size, r); + rz_core_cmpwatch_add (core, addr, size, r); // eprintf ("ADD (%llx) %d (%s)\n", addr, size, r); } else { eprintf ("Missing parameters\n"); @@ -321,18 +321,18 @@ static void cmd_cmp_watcher(RCore *core, const char *input) { free (p); break; case 'r': - addr = input[1]? r_num_math (core->num, input + 1): UT64_MAX; - r_core_cmpwatch_revert (core, addr); + addr = input[1]? rz_num_math (core->num, input + 1): UT64_MAX; + rz_core_cmpwatch_revert (core, addr); break; case 'u': - addr = input[1]? r_num_math (core->num, input + 1): UT64_MAX; - r_core_cmpwatch_update (core, addr); + addr = input[1]? rz_num_math (core->num, input + 1): UT64_MAX; + rz_core_cmpwatch_update (core, addr); break; case '*': - r_core_cmpwatch_show (core, UT64_MAX, '*'); + rz_core_cmpwatch_show (core, UT64_MAX, '*'); break; case '\0': - r_core_cmpwatch_show (core, UT64_MAX, 0); + rz_core_cmpwatch_show (core, UT64_MAX, 0); break; case '?': { const char *help_message[] = { @@ -346,74 +346,74 @@ static void cmd_cmp_watcher(RCore *core, const char *input) { "cwu", " [addr]", "Update watchers", NULL }; - r_core_cmd_help (core, help_message); + rz_core_cmd_help (core, help_message); } break; } } -static int cmd_cmp_disasm(RCore *core, const char *input, int mode) { - RAsmOp op, op2; +static int cmd_cmp_disasm(RzCore *core, const char *input, int mode) { + RzAsmOp op, op2; int i, j; char colpad[80]; - int hascolor = r_config_get_i (core->config, "scr.color"); - int cols = r_config_get_i (core->config, "hex.cols") * 2; - ut64 off = r_num_math (core->num, input); + int hascolor = rz_config_get_i (core->config, "scr.color"); + int cols = rz_config_get_i (core->config, "hex.cols") * 2; + ut64 off = rz_num_math (core->num, input); ut8 *buf = calloc (core->blocksize + 32, 1); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (!buf) { return false; } - r_io_read_at (core->io, off, buf, core->blocksize + 32); + rz_io_read_at (core->io, off, buf, core->blocksize + 32); switch (mode) { case 'd': // decompiler { #if 0 - char *a = r_core_cmd_strf (core, "pdc @ 0x%"PFMT64x, off); - char *b = r_core_cmd_strf (core, "pdc @ 0x%"PFMT64x, core->offset); - RDiff *d = r_diff_new (); - char *s = r_diff_buffers_unified (d, a, strlen(a), b, strlen(b)); - r_cons_printf ("%s\n", s); + char *a = rz_core_cmd_strf (core, "pdc @ 0x%"PFMT64x, off); + char *b = rz_core_cmd_strf (core, "pdc @ 0x%"PFMT64x, core->offset); + RzDiff *d = rz_diff_new (); + char *s = rz_diff_buffers_unified (d, a, strlen(a), b, strlen(b)); + rz_cons_printf ("%s\n", s); free (a); free (b); free (s); - r_diff_free (d); + rz_diff_free (d); #else - r_core_cmdf (core, "pdc @ 0x%"PFMT64x">$a", off); - r_core_cmdf (core, "pdc @ 0x%"PFMT64x">$b", core->offset); - r_core_cmd0 (core, "diff $a $b;rm $a;rm $b"); + rz_core_cmdf (core, "pdc @ 0x%"PFMT64x">$a", off); + rz_core_cmdf (core, "pdc @ 0x%"PFMT64x">$b", core->offset); + rz_core_cmd0 (core, "diff $a $b;rm $a;rm $b"); #endif } break; case 'c': // columns for (i = j = 0; i < core->blocksize && j < core->blocksize;) { // dis A - r_asm_set_pc (core->rasm, core->offset + i); - (void) r_asm_disassemble (core->rasm, &op, + rz_asm_set_pc (core->rasm, core->offset + i); + (void) rz_asm_disassemble (core->rasm, &op, core->block + i, core->blocksize - i); // dis B - r_asm_set_pc (core->rasm, off + i); - (void) r_asm_disassemble (core->rasm, &op2, + rz_asm_set_pc (core->rasm, off + i); + (void) rz_asm_disassemble (core->rasm, &op2, buf + j, core->blocksize - j); // show output - bool iseq = r_strbuf_equals (&op.buf_asm, &op2.buf_asm); + bool iseq = rz_strbuf_equals (&op.buf_asm, &op2.buf_asm); memset (colpad, ' ', sizeof (colpad)); { - int pos = strlen (r_strbuf_get (&op.buf_asm)); + int pos = strlen (rz_strbuf_get (&op.buf_asm)); pos = (pos > cols)? 0: cols - pos; colpad[pos] = 0; } if (hascolor) { - r_cons_printf (iseq? pal->graph_true: pal->graph_false); + rz_cons_printf (iseq? pal->graph_true: pal->graph_false); } - r_cons_printf (" 0x%08"PFMT64x " %s %s", - core->offset + i, r_strbuf_get (&op.buf_asm), colpad); - r_cons_printf ("%c 0x%08"PFMT64x " %s\n", - iseq? '=': '!', off + j, r_strbuf_get (&op2.buf_asm)); + rz_cons_printf (" 0x%08"PFMT64x " %s %s", + core->offset + i, rz_strbuf_get (&op.buf_asm), colpad); + rz_cons_printf ("%c 0x%08"PFMT64x " %s\n", + iseq? '=': '!', off + j, rz_strbuf_get (&op2.buf_asm)); if (hascolor) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } if (op.size < 1) { op.size = 1; @@ -428,33 +428,33 @@ static int cmd_cmp_disasm(RCore *core, const char *input, int mode) { case 'u': // unified for (i = j = 0; i < core->blocksize && j < core->blocksize;) { // dis A - r_asm_set_pc (core->rasm, core->offset + i); - (void) r_asm_disassemble (core->rasm, &op, + rz_asm_set_pc (core->rasm, core->offset + i); + (void) rz_asm_disassemble (core->rasm, &op, core->block + i, core->blocksize - i); // dis B - r_asm_set_pc (core->rasm, off + i); - (void) r_asm_disassemble (core->rasm, &op2, + rz_asm_set_pc (core->rasm, off + i); + (void) rz_asm_disassemble (core->rasm, &op2, buf + j, core->blocksize - j); // show output - bool iseq = r_strbuf_equals (&op.buf_asm, &op2.buf_asm); // (!strcmp (op.buf_asm, op2.buf_asm)); + bool iseq = rz_strbuf_equals (&op.buf_asm, &op2.buf_asm); // (!strcmp (op.buf_asm, op2.buf_asm)); if (iseq) { - r_cons_printf (" 0x%08"PFMT64x " %s\n", - core->offset + i, r_strbuf_get (&op.buf_asm)); + rz_cons_printf (" 0x%08"PFMT64x " %s\n", + core->offset + i, rz_strbuf_get (&op.buf_asm)); } else { if (hascolor) { - r_cons_printf (pal->graph_false); + rz_cons_printf (pal->graph_false); } - r_cons_printf ("-0x%08"PFMT64x " %s\n", - core->offset + i, r_strbuf_get (&op.buf_asm)); + rz_cons_printf ("-0x%08"PFMT64x " %s\n", + core->offset + i, rz_strbuf_get (&op.buf_asm)); if (hascolor) { - r_cons_printf (pal->graph_true); + rz_cons_printf (pal->graph_true); } - r_cons_printf ("+0x%08"PFMT64x " %s\n", - off + j, r_strbuf_get (&op2.buf_asm)); + rz_cons_printf ("+0x%08"PFMT64x " %s\n", + off + j, rz_strbuf_get (&op2.buf_asm)); if (hascolor) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } if (op.size < 1) { @@ -472,12 +472,12 @@ static int cmd_cmp_disasm(RCore *core, const char *input, int mode) { } static int cmd_cp(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input[1] == '.') { - char *file = r_core_cmd_strf (core, "ij~{core.file}"); - r_str_trim (file); - char *newfile = r_str_newf ("%s.%s", file, input + 2); - r_file_copy (file, newfile); + char *file = rz_core_cmd_strf (core, "ij~{core.file}"); + rz_str_trim (file); + char *newfile = rz_str_newf ("%s.%s", file, input + 2); + rz_file_copy (file, newfile); free (file); free (newfile); return true; @@ -489,62 +489,62 @@ static int cmd_cp(void *data, const char *input) { } char *cmd = strdup (input + 2); if (cmd) { - char **files = r_str_argv (cmd, NULL); + char **files = rz_str_argv (cmd, NULL); if (files[0] && files[1]) { - bool rc = r_file_copy (files[0], files[1]); + bool rc = rz_file_copy (files[0], files[1]); free (cmd); - r_str_argv_free (files); + rz_str_argv_free (files); return rc; } - r_str_argv_free (files); + rz_str_argv_free (files); } eprintf ("Usage: cp src dst\n"); return false; } -static void __core_cmp_bits (RCore *core, ut64 addr) { - const bool scr_color = r_config_get_i (core->config, "scr.color"); +static void __core_cmp_bits (RzCore *core, ut64 addr) { + const bool scr_color = rz_config_get_i (core->config, "scr.color"); int i; ut8 a, b; - r_io_read_at (core->io, core->offset, &a, 1); - r_io_read_at (core->io, addr, &b, 1); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + rz_io_read_at (core->io, core->offset, &a, 1); + rz_io_read_at (core->io, addr, &b, 1); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; const char *color = scr_color? pal->offset: ""; const char *color_end = scr_color? Color_RESET: ""; - if (r_config_get_i (core->config, "hex.header")) { - char *n = r_str_newf ("0x%08"PFMT64x, core->offset); - const char *extra = r_str_pad (' ', strlen (n) - 10); + if (rz_config_get_i (core->config, "hex.header")) { + char *n = rz_str_newf ("0x%08"PFMT64x, core->offset); + const char *extra = rz_str_pad (' ', strlen (n) - 10); free (n); - r_cons_printf ("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, extra, color_end); + rz_cons_printf ("%s- offset -%s 7 6 5 4 3 2 1 0%s\n", color, extra, color_end); } color = scr_color? pal->graph_false: ""; color_end = scr_color? Color_RESET: ""; - r_cons_printf ("%s0x%08"PFMT64x"%s ", color, core->offset, color_end); + rz_cons_printf ("%s0x%08"PFMT64x"%s ", color, core->offset, color_end); for (i = 7; i >= 0; i--) { bool b0 = (a & 1<graph_true:pal->graph_false: ""; color_end = scr_color ? Color_RESET: ""; - r_cons_printf ("%s%d%s ", color, b0, color_end); + rz_cons_printf ("%s%d%s ", color, b0, color_end); } color = scr_color? pal->graph_true: ""; color_end = scr_color? Color_RESET: ""; - r_cons_printf ("\n%s0x%08"PFMT64x"%s ", color, addr, color_end); + rz_cons_printf ("\n%s0x%08"PFMT64x"%s ", color, addr, color_end); for (i = 7; i >= 0; i--) { bool b0 = (a & 1<graph_true: pal->graph_false: ""; color_end = scr_color ? Color_RESET: ""; - r_cons_printf ("%s%d%s ", color, b1, color_end); + rz_cons_printf ("%s%d%s ", color, b1, color_end); } - r_cons_newline (); + rz_cons_newline (); } static int cmd_cmp(void *data, const char *input) { static char *oldcwd = NULL; int ret = 0, i, mode = 0; - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut64 val = UT64_MAX; char *filled; ut8 *buf; @@ -560,19 +560,19 @@ static int cmd_cmp(void *data, const char *input) { break; case 'a': // "cat" if (input[1] == 't') { - const char *path = r_str_trim_head_ro (input + 2); + const char *path = rz_str_trim_head_ro (input + 2); if (*path == '$') { - const char *oldText = r_cmd_alias_get (core->rcmd, path, 1); + const char *oldText = rz_cmd_alias_get (core->rcmd, path, 1); if (oldText) { - r_cons_printf ("%s\n", oldText + 1); + rz_cons_printf ("%s\n", oldText + 1); } } else { - if (r_fs_check (core->fs, path)) { - r_core_cmdf (core, "mg %s", path); + if (rz_fs_check (core->fs, path)) { + rz_core_cmdf (core, "mg %s", path); } else { - char *res = r_syscmd_cat (path); + char *res = rz_syscmd_cat (path); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -594,7 +594,7 @@ static int cmd_cmp(void *data, const char *input) { case ' ': { char *str = strdup (input + 1); - int len = r_str_unescape (str); + int len = rz_str_unescape (str); val = radare_compare (core, block, (ut8 *) str, len, 0); free (str); } @@ -605,7 +605,7 @@ static int cmd_cmp(void *data, const char *input) { eprintf ("Usage: cj [string]\n"); } else { char *str = strdup (input + 2); - int len = r_str_unescape (str); + int len = rz_str_unescape (str); val = radare_compare (core, block, (ut8 *) str, len, 'j'); free (str); } @@ -637,14 +637,14 @@ static int cmd_cmp(void *data, const char *input) { free (filled); return false; } - ret = r_hex_bin2str (block, strlen (input) / 2, (char *) buf); + ret = rz_hex_bin2str (block, strlen (input) / 2, (char *) buf); for (i = 0; i < ret * 2; i++) { if (filled[i] == '.') { filled[i] = buf[i]; } } - ret = r_hex_str2bin (filled, buf); + ret = rz_hex_str2bin (filled, buf); if (ret < 1) { eprintf ("Cannot parse hexpair\n"); } else { @@ -656,7 +656,7 @@ static int cmd_cmp(void *data, const char *input) { case 'X': buf = malloc (core->blocksize); if (buf) { - if (!r_io_read_at (core->io, r_num_math (core->num, + if (!rz_io_read_at (core->io, rz_num_math (core->num, input + 1), buf, core->blocksize)) { eprintf ("Cannot read hexdump\n"); } else { @@ -671,7 +671,7 @@ static int cmd_cmp(void *data, const char *input) { eprintf ("Please. use 'cf [file]'\n"); return false; } - fd = r_sandbox_fopen (input + 2, "rb"); + fd = rz_sandbox_fopen (input + 2, "rb"); if (!fd) { eprintf ("Cannot open file '%s'\n", input + 2); return false; @@ -696,8 +696,8 @@ static int cmd_cmp(void *data, const char *input) { if (!strcmp (input + 1, "-")) { if (oldcwd) { char *newdir = oldcwd; - oldcwd = r_sys_getdir (); - if (r_sandbox_chdir (newdir) == -1) { + oldcwd = rz_sys_getdir (); + if (rz_sandbox_chdir (newdir) == -1) { eprintf ("Cannot chdir to %s\n", newdir); free (oldcwd); oldcwd = newdir; @@ -708,12 +708,12 @@ static int cmd_cmp(void *data, const char *input) { // nothing to do here } } else if (input[1] == '~' && input[2] == '/') { - char *homepath = r_str_home (input + 3); + char *homepath = rz_str_home (input + 3); if (homepath) { if (*homepath) { free (oldcwd); - oldcwd = r_sys_getdir (); - if (r_sandbox_chdir (homepath) == -1) { + oldcwd = rz_sys_getdir (); + if (rz_sandbox_chdir (homepath) == -1) { eprintf ("Cannot chdir to %s\n", homepath); } } @@ -723,37 +723,37 @@ static int cmd_cmp(void *data, const char *input) { } } else { free (oldcwd); - oldcwd = r_sys_getdir (); - if (r_sandbox_chdir (input + 1) == -1) { + oldcwd = rz_sys_getdir (); + if (rz_sandbox_chdir (input + 1) == -1) { eprintf ("Cannot chdir to %s\n", input + 1); } } } else { - char *home = r_sys_getenv (R_SYS_HOME); - if (!home || r_sandbox_chdir (home) == -1) { + char *home = rz_sys_getenv (R_SYS_HOME); + if (!home || rz_sandbox_chdir (home) == -1) { eprintf ("Cannot find home.\n"); } free (home); } break; case '1': // "c1" - __core_cmp_bits (core, r_num_math (core->num, input + 1)); + __core_cmp_bits (core, rz_num_math (core->num, input + 1)); break; case '2': // "c2" - v16 = (ut16) r_num_math (core->num, input + 1); + v16 = (ut16) rz_num_math (core->num, input + 1); val = radare_compare (core, block, (ut8 *) &v16, sizeof (v16), 0); break; case '4': // "c4" - v32 = (ut32) r_num_math (core->num, input + 1); + v32 = (ut32) rz_num_math (core->num, input + 1); val = radare_compare (core, block, (ut8 *) &v32, sizeof (v32), 0); break; case '8': // "c8" - v64 = (ut64) r_num_math (core->num, input + 1); + v64 = (ut64) rz_num_math (core->num, input + 1); val = radare_compare (core, block, (ut8 *) &v64, sizeof (v64), 0); break; case 'c': // "cc" if (input[1] == '?') { // "cc?" - r_core_cmd0 (core, "c?~cc"); + rz_core_cmd0 (core, "c?~cc"); } else if (input[1] == 'd') { // "ccd" if (input[2] == 'd') { // "ccdd" cmd_cmp_disasm (core, input + 3, 'd'); @@ -765,18 +765,18 @@ static int cmd_cmp(void *data, const char *input) { ut64 addr = 0; // TOTHINK: Not sure what default address should be if (input[1] == 'c') { // "ccc" core->print->flags |= R_PRINT_FLAGS_DIFFOUT; - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } else { if (*input && input[1]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } } int col = core->cons->columns > 123; ut8 *b = malloc (core->blocksize); if (b != NULL) { memset (b, 0xff, core->blocksize); - r_io_read_at (core->io, addr, b, core->blocksize); - r_print_hexdiff (core->print, core->offset, block, + rz_io_read_at (core->io, addr, b, core->blocksize); + rz_print_hexdiff (core->print, core->offset, block, addr, b, core->blocksize, col); free (b); } @@ -786,22 +786,22 @@ static int cmd_cmp(void *data, const char *input) { case 'g': // "cg" { // XXX: this is broken int diffops = 0; - RCore *core2; + RzCore *core2; char *file2 = NULL; switch (input[1]) { case 'o': // "cgo" - file2 = (char *) r_str_trim_head_ro (input + 2); - r_anal_diff_setup (core->anal, true, -1, -1); + file2 = (char *) rz_str_trim_head_ro (input + 2); + rz_anal_diff_setup (core->anal, true, -1, -1); break; case 'f': // "cgf" eprintf ("TODO: agf is experimental\n"); - r_anal_diff_setup (core->anal, true, -1, -1); - r_core_gdiff_fcn (core, core->offset, - r_num_math (core->num, input + 2)); + rz_anal_diff_setup (core->anal, true, -1, -1); + rz_core_gdiff_fcn (core, core->offset, + rz_num_math (core->num, input + 2)); return false; case ' ': - file2 = (char *) r_str_trim_head_ro (input + 2); - r_anal_diff_setup (core->anal, false, -1, -1); + file2 = (char *) rz_str_trim_head_ro (input + 2); + rz_anal_diff_setup (core->anal, false, -1, -1); break; default: { const char *help_message[] = { @@ -811,41 +811,41 @@ static int cmd_cmp(void *data, const char *input) { "cgo", "", "Opcode-bytes code graph diff", NULL }; - r_core_cmd_help (core, help_message); + rz_core_cmd_help (core, help_message); return false; } } - if (r_file_size (file2) <= 0) { + if (rz_file_size (file2) <= 0) { eprintf ("Cannot compare with file %s\n", file2); return false; } - if (!(core2 = r_core_new ())) { + if (!(core2 = rz_core_new ())) { eprintf ("Cannot init diff core\n"); return false; } - r_core_loadlibs (core2, R_CORE_LOADLIBS_ALL, NULL); + rz_core_loadlibs (core2, R_CORE_LOADLIBS_ALL, NULL); core2->io->va = core->io->va; - if (!r_core_file_open (core2, file2, 0, 0LL)) { + if (!rz_core_file_open (core2, file2, 0, 0LL)) { eprintf ("Cannot open diff file '%s'\n", file2); - r_core_free (core2); - r_core_bind_cons (core); + rz_core_free (core2); + rz_core_bind_cons (core); return false; } // TODO: must replicate on core1 too - r_config_set_i (core2->config, "io.va", true); - r_anal_diff_setup (core->anal, diffops, -1, -1); - r_anal_diff_setup (core2->anal, diffops, -1, -1); + rz_config_set_i (core2->config, "io.va", true); + rz_anal_diff_setup (core->anal, diffops, -1, -1); + rz_anal_diff_setup (core2->anal, diffops, -1, -1); - r_core_bin_load (core2, file2, - r_config_get_i (core->config, "bin.baddr")); - r_core_gdiff (core, core2); - r_core_diff_show (core, core2); + rz_core_bin_load (core2, file2, + rz_config_get_i (core->config, "bin.baddr")); + rz_core_gdiff (core, core2); + rz_core_diff_show (core, core2); /* exchange a segfault with a memleak */ core2->config = NULL; - r_core_free (core2); - r_core_bind_cons (core); + rz_core_free (core2); + rz_core_bind_cons (core); } break; case 'u': // "cu" @@ -853,7 +853,7 @@ static int cmd_cmp(void *data, const char *input) { case '.': case ' ': radare_compare_unified (core, core->offset, - r_num_math (core->num, input + 2), + rz_num_math (core->num, input + 2), core->blocksize); break; case '1': @@ -861,7 +861,7 @@ static int cmd_cmp(void *data, const char *input) { case '4': case '8': radare_compare_words (core, core->offset, - r_num_math (core->num, input + 2), + rz_num_math (core->num, input + 2), core->blocksize, input[1] - '0'); break; case 'd': @@ -879,17 +879,17 @@ static int cmd_cmp(void *data, const char *input) { "wu", " p", "Apply unified hex patch (see output of cu)", NULL }; - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); } } break; case '?': - r_core_cmd_help (core, help_msg_c); + rz_core_cmd_help (core, help_msg_c); break; case 'v': { // "cv" int sz = input[1]; if (sz == ' ') { - switch (r_config_get_i (core->config, "asm.bits")) { + switch (rz_config_get_i (core->config, "asm.bits")) { case 8: sz = '1'; break; case 16: sz = '2'; break; case 32: sz = '4'; break; @@ -900,37 +900,37 @@ static int cmd_cmp(void *data, const char *input) { // TODO: honor endian switch (sz) { case '1': { // "cv1" - ut8 n = (ut8) r_num_math (core->num, input + 2); + ut8 n = (ut8) rz_num_math (core->num, input + 2); core->num->value = 1; if (block[0] == n) { - r_cons_printf ("0x%08"PFMT64x "\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x "\n", core->offset); core->num->value = 0; } break; } case '2': { // "cv2" - ut16 n = (ut16) r_num_math (core->num, input + 2); + ut16 n = (ut16) rz_num_math (core->num, input + 2); core->num->value = 1; if (core->blocksize >= 2 && *(ut16*)block == n) { - r_cons_printf ("0x%08"PFMT64x "\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x "\n", core->offset); core->num->value = 0; } break; } case '4': { // "cv4" - ut32 n = (ut32) r_num_math (core->num, input + 2); + ut32 n = (ut32) rz_num_math (core->num, input + 2); core->num->value = 1; if (core->blocksize >= 4 && *(ut32*)block == n) { - r_cons_printf ("0x%08"PFMT64x "\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x "\n", core->offset); core->num->value = 0; } break; } case '8': { // "cv8" - ut64 n = (ut64) r_num_math (core->num, input + 2); + ut64 n = (ut64) rz_num_math (core->num, input + 2); core->num->value = 1; if (core->blocksize >= 8 && *(ut64*)block == n) { - r_cons_printf ("0x%08"PFMT64x "\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x "\n", core->offset); core->num->value = 0; } break; @@ -950,7 +950,7 @@ static int cmd_cmp(void *data, const char *input) { case 'V': { // "cV" int sz = input[1]; if (sz == ' ') { - switch (r_config_get_i (core->config, "asm.bits")) { + switch (rz_config_get_i (core->config, "asm.bits")) { case 8: sz = '1'; break; case 16: sz = '2'; break; case 32: sz = '4'; break; @@ -963,25 +963,25 @@ static int cmd_cmp(void *data, const char *input) { } sz -= '0'; if (sz > 0) { - ut64 at = r_num_math (core->num, input + 2); + ut64 at = rz_num_math (core->num, input + 2); ut8 buf[8] = {0}; - r_io_read_at (core->io, at, buf, sizeof (buf)); + rz_io_read_at (core->io, at, buf, sizeof (buf)); core->num->value = memcmp (buf, core->block, sz)? 1: 0; } break; } case 'l': // "cl" if (strchr (input, 'f')) { - r_cons_flush (); + rz_cons_flush (); } else if (input[1] == 0) { - r_cons_fill_line (); - // r_cons_clear_line (0); + rz_cons_fill_line (); + // rz_cons_clear_line (0); } else if (!strchr (input, '0')) { - r_cons_clear00 (); + rz_cons_clear00 (); } break; default: - r_core_cmd_help (core, help_msg_c); + rz_core_cmd_help (core, help_msg_c); } if (val != UT64_MAX) { core->num->value = val; diff --git a/libr/core/cmd_colon.c b/librz/core/cmd_colon.c similarity index 81% rename from libr/core/cmd_colon.c rename to librz/core/cmd_colon.c index 5ae3c49616..f13e1f091f 100644 --- a/libr/core/cmd_colon.c +++ b/librz/core/cmd_colon.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2019 - pancake */ -#include +#include static int cmd_colon(void *_core, const char *cmd) { - // RCore *core = (RCore*)_core; + // RzCore *core = (RzCore*)_core; if (*cmd == '{') { // parse json here, and retrieve arguments return 1; @@ -21,8 +21,8 @@ static int cmd_colon(void *_core, const char *cmd) { const char *space = strchr (cmd, ' '); if (space) { int len = space - cmd; - char *action = r_str_ndup (cmd, len); - r_cons_printf ("-> %s\n", action); + char *action = rz_str_ndup (cmd, len); + rz_cons_printf ("-> %s\n", action); free (action); return 1; } diff --git a/libr/core/cmd_debug.c b/librz/core/cmd_debug.c similarity index 60% rename from libr/core/cmd_debug.c rename to librz/core/cmd_debug.c index 1e44778287..12741326a3 100644 --- a/libr/core/cmd_debug.c +++ b/librz/core/cmd_debug.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #include #define TN_KEY_LEN 32 #define TN_KEY_FMT "%"PFMT64u @@ -10,15 +10,15 @@ #endif #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ -#include "r_heap_glibc.h" +#include "rz_heap_glibc.h" #endif #if HAVE_JEMALLOC -#include "r_heap_jemalloc.h" +#include "rz_heap_jemalloc.h" #include "linux_heap_jemalloc.c" #endif -void cmd_anal_reg (RCore *core, const char *str); +void cmd_anal_reg (RzCore *core, const char *str); static const char *help_msg_d[] = { "Usage:", "d", " # Debug commands", @@ -277,9 +277,9 @@ static const char *help_msg_dmp[] = { static const char *help_msg_do[] = { "Usage:", "do", " # Debug (re)open commands", "do", "", "Open process (reload, alias for 'oo')", - "dor", " [rarun2]", "Comma separated list of k=v rarun2 profile options (e dbg.profile)", - "doe", "", "Show rarun2 startup profile", - "doe!", "", "Edit rarun2 startup profile with $EDITOR", + "dor", " [rz_run]", "Comma separated list of k=v rz_run profile options (e dbg.profile)", + "doe", "", "Show rz_run startup profile", + "doe!", "", "Edit rz_run startup profile with $EDITOR", "doo", " [args]", "Reopen in debug mode with args (alias for 'ood')", "doof", " [args]", "Reopen in debug mode from file (alias for 'oodf')", "doc", "", "Close debug session", @@ -510,7 +510,7 @@ struct trace_node { int refs; }; -static void cmd_debug_init(RCore *core, RCmdDesc *parent) { +static void cmd_debug_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, d); DEFINE_CMD_DESCRIPTOR (core, db); DEFINE_CMD_DESCRIPTOR (core, dbt); @@ -542,31 +542,31 @@ static void cmd_debug_init(RCore *core, RCmdDesc *parent) { } // XXX those tmp files are never removed and we shuoldnt use files for this -static void setRarunProfileString(RCore *core, const char *str) { - char *file = r_file_temp ("rarun2"); +static void setRarunProfileString(RzCore *core, const char *str) { + char *file = rz_file_temp ("rz_run"); char *s = strdup (str); - r_config_set (core->config, "dbg.profile", file); - r_str_replace_char (s, ',', '\n'); - r_file_dump (file, (const ut8*)s, strlen (s), 0); - r_file_dump (file, (const ut8*)"\n", 1, 1); + rz_config_set (core->config, "dbg.profile", file); + rz_str_replace_char (s, ',', '\n'); + rz_file_dump (file, (const ut8*)s, strlen (s), 0); + rz_file_dump (file, (const ut8*)"\n", 1, 1); free (file); } -static void cmd_debug_cont_syscall (RCore *core, const char *_str) { +static void cmd_debug_cont_syscall (RzCore *core, const char *_str) { // TODO : handle more than one stopping syscall int i, *syscalls = NULL; int count = 0; if (_str && *_str) { char *str = strdup (_str); - count = r_str_word_set0 (str); + count = rz_str_word_set0 (str); syscalls = calloc (sizeof (int), count); for (i = 0; i < count; i++) { - const char *sysnumstr = r_str_word_get0 (str, i); - int sig = (int)r_num_math (core->num, sysnumstr); + const char *sysnumstr = rz_str_word_get0 (str, i); + int sig = (int)rz_num_math (core->num, sysnumstr); if (sig == -1) { // trace ALL syscalls syscalls[i] = -1; } else if (sig == 0) { - sig = r_syscall_get_num (core->anal->syscall, sysnumstr); + sig = rz_syscall_get_num (core->anal->syscall, sysnumstr); if (sig == -1) { eprintf ("Unknown syscall number\n"); free (str); @@ -585,46 +585,46 @@ static void cmd_debug_cont_syscall (RCore *core, const char *_str) { } else { eprintf ("Running child until next syscall\n"); } - r_reg_arena_swap (core->dbg->reg, true); - r_debug_continue_syscalls (core->dbg, syscalls, count); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_continue_syscalls (core->dbg, syscalls, count); free (syscalls); } -static int showreg(RCore *core, const char *str) { +static int showreg(RzCore *core, const char *str) { int size = 0; - RRegItem *r = 0; + RzRegItem *r = 0; const char *rname = str; // check for alias reg - int role = r_reg_get_name_idx (str); + int role = rz_reg_get_name_idx (str); if (role != -1) { - rname = r_reg_get_name (core->dbg->reg, role); + rname = rz_reg_get_name (core->dbg->reg, role); } - r = r_reg_get (core->dbg->reg, rname , -1); + r = rz_reg_get (core->dbg->reg, rname , -1); if (r) { ut64 off; utX value; if (r->size > 64) { - off = r_reg_get_value_big (core->dbg->reg, r, &value); + off = rz_reg_get_value_big (core->dbg->reg, r, &value); switch (r->size) { case 80: - r_cons_printf ("0x%04x%016"PFMT64x"\n", value.v80.High, value.v80.Low); + rz_cons_printf ("0x%04x%016"PFMT64x"\n", value.v80.High, value.v80.Low); break; case 96: - r_cons_printf ("0x%08x%016"PFMT64x"\n", value.v96.High, value.v96.Low); + rz_cons_printf ("0x%08x%016"PFMT64x"\n", value.v96.High, value.v96.Low); break; case 128: - r_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"\n", value.v128.High, value.v128.Low); + rz_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"\n", value.v128.High, value.v128.Low); break; case 256: - r_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"%016"PFMT64x"%016"PFMT64x"\n", + rz_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"%016"PFMT64x"%016"PFMT64x"\n", value.v256.High.High, value.v256.High.Low, value.v256.Low.High, value.v256.Low.Low); break; default: - r_cons_printf ("Error while retrieving reg '%s' of %i bits\n", str +1, r->size); + rz_cons_printf ("Error while retrieving reg '%s' of %i bits\n", str +1, r->size); } } else { - off = r_reg_get_value (core->dbg->reg, r); - r_cons_printf ("0x%08"PFMT64x "\n", off); + off = rz_reg_get_value (core->dbg->reg, r); + rz_cons_printf ("0x%08"PFMT64x "\n", off); } return r->size; } @@ -644,7 +644,7 @@ static RGraphNode *get_graphtrace_node (RGraph *g, Sdb *nodes, struct trace_node snprintf (tn_key, TN_KEY_LEN, TN_KEY_FMT, tn->addr); gn = (RGraphNode *)(size_t)sdb_num_get (nodes, tn_key, NULL); if (!gn) { - gn = r_graph_add_node (g, tn); + gn = rz_graph_add_node (g, tn); sdb_num_set (nodes, tn_key, (ut64)(size_t)gn, 0); } return gn; @@ -668,72 +668,72 @@ static void dot_trace_discover_child (RTreeNode *n, RTreeVisitor *vis) { RGraphNode *gn = get_graphtrace_node (g, gnodes, tn); RGraphNode *gn_parent = get_graphtrace_node (g, gnodes, tn_parent); - if (!r_graph_adjacent (g, gn_parent, gn)) - r_graph_add_edge (g, gn_parent, gn); + if (!rz_graph_adjacent (g, gn_parent, gn)) + rz_graph_add_edge (g, gn_parent, gn); } } -static void dot_trace_traverse(RCore *core, RTree *t, int fmt) { - const char *gfont = r_config_get (core->config, "graph.font"); +static void dot_trace_traverse(RzCore *core, RTree *t, int fmt) { + const char *gfont = rz_config_get (core->config, "graph.font"); struct dot_trace_ght aux_data; RTreeVisitor vis = { 0 }; - const RList *nodes; - RListIter *iter; + const RzList *nodes; + RzListIter *iter; RGraphNode *n; if (fmt == 'i') { - r_core_cmd0 (core, "ag-;.dtg*;aggi"); + rz_core_cmd0 (core, "ag-;.dtg*;aggi"); return; } - aux_data.graph = r_graph_new (); + aux_data.graph = rz_graph_new (); aux_data.graphnodes = sdb_new0 (); /* build a callgraph from the execution trace */ vis.data = &aux_data; vis.pre_visit = (RTreeNodeVisitCb)dot_trace_create_node; vis.discover_child = (RTreeNodeVisitCb)dot_trace_discover_child; - r_tree_bfs (t, &vis); + rz_tree_bfs (t, &vis); /* traverse the callgraph to print the dot file */ - nodes = r_graph_get_nodes (aux_data.graph); + nodes = rz_graph_get_nodes (aux_data.graph); if (fmt == 0) { - r_cons_printf ("digraph code {\n" + rz_cons_printf ("digraph code {\n" "graph [bgcolor=white];\n" " node [color=lightgray, style=filled" " shape=box fontname=\"%s\" fontsize=\"8\"];\n", gfont); } - r_list_foreach (nodes, iter, n) { + rz_list_foreach (nodes, iter, n) { struct trace_node *tn = (struct trace_node *)n->data; - const RList *neighbours = r_graph_get_neighbours (aux_data.graph, n); - RListIter *it_n; + const RzList *neighbours = rz_graph_get_neighbours (aux_data.graph, n); + RzListIter *it_n; RGraphNode *w; if (!fmt && tn) { - r_cons_printf ("\"0x%08"PFMT64x"\" [URL=\"0x%08"PFMT64x + rz_cons_printf ("\"0x%08"PFMT64x"\" [URL=\"0x%08"PFMT64x "\" color=\"lightgray\" label=\"0x%08"PFMT64x " (%d)\"]\n", tn->addr, tn->addr, tn->addr, tn->refs); } - r_list_foreach (neighbours, it_n, w) { + rz_list_foreach (neighbours, it_n, w) { struct trace_node *tv = (struct trace_node *)w->data; if (tv && tn) { if (fmt) { - r_cons_printf ("agn 0x%08"PFMT64x"\n", tn->addr); - r_cons_printf ("agn 0x%08"PFMT64x"\n", tv->addr); - r_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", + rz_cons_printf ("agn 0x%08"PFMT64x"\n", tn->addr); + rz_cons_printf ("agn 0x%08"PFMT64x"\n", tv->addr); + rz_cons_printf ("age 0x%08"PFMT64x" 0x%08"PFMT64x"\n", tn->addr, tv->addr); } else { - r_cons_printf ("\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x + rz_cons_printf ("\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x "\" [color=\"red\"];\n", tn->addr, tv->addr); } } } } if (!fmt) { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } - r_graph_free (aux_data.graph); + rz_graph_free (aux_data.graph); sdb_free (aux_data.graphnodes); } @@ -741,8 +741,8 @@ static void dot_trace_traverse(RCore *core, RTree *t, int fmt) { * TODO: handle when the process is dead * TODO: handle ^C */ -static int step_until(RCore *core, ut64 addr) { - ut64 off = r_debug_reg_get (core->dbg, "PC"); +static int step_until(RzCore *core, ut64 addr) { + ut64 off = rz_debug_reg_get (core->dbg, "PC"); if (!off) { eprintf ("Cannot 'drn PC'\n"); return false; @@ -751,97 +751,97 @@ static int step_until(RCore *core, ut64 addr) { eprintf ("Cannot continue until address 0\n"); return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { core->break_loop = true; break; } - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { core->break_loop = true; break; } - r_debug_step (core->dbg, 1); - off = r_debug_reg_get (core->dbg, "PC"); + rz_debug_step (core->dbg, 1); + off = rz_debug_reg_get (core->dbg, "PC"); // check breakpoint here } while (off != addr); - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -static int step_until_esil(RCore *core, const char *esilstr) { +static int step_until_esil(RzCore *core, const char *esilstr) { if (!core || !esilstr || !core->dbg || !core->dbg->anal \ || !core->dbg->anal->esil) { eprintf ("Not initialized %p. Run 'aei' first.\n", core->anal->esil); return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { core->break_loop = true; break; } - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { core->break_loop = true; break; } - r_debug_step (core->dbg, 1); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); - if (r_anal_esil_condition (core->anal->esil, esilstr)) { + rz_debug_step (core->dbg, 1); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); + if (rz_anal_esil_condition (core->anal->esil, esilstr)) { eprintf ("ESIL BREAK!\n"); break; } } - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -static bool is_repeatable_inst(RCore *core, ut64 addr) { +static bool is_repeatable_inst(RzCore *core, ut64 addr) { // we have read the bytes already - RAnalOp *op = r_core_op_anal (core, addr, R_ANAL_OP_MASK_ALL); + RzAnalOp *op = rz_core_op_anal (core, addr, R_ANAL_OP_MASK_ALL); bool ret = op && ((op->prefix & R_ANAL_OP_PREFIX_REP) || (op->prefix & R_ANAL_OP_PREFIX_REPNE)); - r_anal_op_free (op); + rz_anal_op_free (op); return ret; } -static int step_until_inst(RCore *core, const char *instr, bool regex) { - RAsmOp asmop; +static int step_until_inst(RzCore *core, const char *instr, bool regex) { + RzAsmOp asmop; ut8 buf[32]; ut64 pc; int ret; - bool is_x86 = r_str_startswith (r_config_get (core->config, "asm.arch"), "x86"); + bool is_x86 = rz_str_startswith (rz_config_get (core->config, "asm.arch"), "x86"); - instr = r_str_trim_head_ro (instr); + instr = rz_str_trim_head_ro (instr); if (!core || !instr|| !core->dbg) { eprintf ("Wrong state\n"); return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { break; } - pc = r_debug_reg_get (core->dbg, "PC"); + pc = rz_debug_reg_get (core->dbg, "PC"); if (is_x86 && is_repeatable_inst (core, pc)) { - r_debug_step_over (core->dbg, 1); + rz_debug_step_over (core->dbg, 1); } else { - r_debug_step (core->dbg, 1); + rz_debug_step (core->dbg, 1); } - pc = r_debug_reg_get (core->dbg, "PC"); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); + pc = rz_debug_reg_get (core->dbg, "PC"); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); /* TODO: disassemble instruction and strstr */ - r_asm_set_pc (core->rasm, pc); + rz_asm_set_pc (core->rasm, pc); // TODO: speedup if instructions are in the same block as the previous - r_io_read_at (core->io, pc, buf, sizeof (buf)); - ret = r_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)); - eprintf ("0x%08"PFMT64x" %d %s\n", pc, ret, r_asm_op_get_asm (&asmop)); // asmop.buf_asm); + rz_io_read_at (core->io, pc, buf, sizeof (buf)); + ret = rz_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)); + eprintf ("0x%08"PFMT64x" %d %s\n", pc, ret, rz_asm_op_get_asm (&asmop)); // asmop.buf_asm); if (ret > 0) { - const char *buf_asm = r_asm_op_get_asm (&asmop); + const char *buf_asm = rz_asm_op_get_asm (&asmop); if (regex) { - if (r_regex_match (instr, "e", buf_asm)) { + if (rz_regex_match (instr, "e", buf_asm)) { eprintf ("Stop.\n"); break; } @@ -853,19 +853,19 @@ static int step_until_inst(RCore *core, const char *instr, bool regex) { } } } - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -static int step_until_optype(RCore *core, const char *_optypes) { - RAnalOp op; +static int step_until_optype(RzCore *core, const char *_optypes) { + RzAnalOp op; ut8 buf[32]; ut64 pc; int res = true; - RList *optypes_list = NULL; - RListIter *iter; - char *optype, *optypes = strdup (r_str_trim_head_ro ((char *) _optypes)); + RzList *optypes_list = NULL; + RzListIter *iter; + char *optype, *optypes = strdup (rz_str_trim_head_ro ((char *) _optypes)); if (!core || !core->dbg) { eprintf ("Wrong state\n"); @@ -878,23 +878,23 @@ static int step_until_optype(RCore *core, const char *_optypes) { goto end; } - bool debugMode = r_config_get_i (core->config, "cfg.debug"); - optypes_list = r_str_split_list (optypes, " ", 0); + bool debugMode = rz_config_get_i (core->config, "cfg.debug"); + optypes_list = rz_str_split_list (optypes, " ", 0); - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { core->break_loop = true; break; } if (debugMode) { - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { core->break_loop = true; break; } - r_debug_step (core->dbg, 1); - pc = r_debug_reg_get (core->dbg, core->dbg->reg->name[R_REG_NAME_PC]); - // 'Copy' from r_debug_step_soft + rz_debug_step (core->dbg, 1); + pc = rz_debug_reg_get (core->dbg, core->dbg->reg->name[R_REG_NAME_PC]); + // 'Copy' from rz_debug_step_soft if (!core->dbg->iob.read_at) { eprintf ("ERROR\n"); res = false; @@ -906,22 +906,22 @@ static int step_until_optype(RCore *core, const char *_optypes) { goto cleanup_after_push; } } else { - r_core_esil_step (core, UT64_MAX, NULL, NULL, false); - pc = r_reg_getv (core->anal->reg, "PC"); + rz_core_esil_step (core, UT64_MAX, NULL, NULL, false); + pc = rz_reg_getv (core->anal->reg, "PC"); } - r_io_read_at (core->io, pc, buf, sizeof (buf)); + rz_io_read_at (core->io, pc, buf, sizeof (buf)); - if (!r_anal_op (core->dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC)) { - eprintf ("Error: r_anal_op failed\n"); + if (!rz_anal_op (core->dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC)) { + eprintf ("Error: rz_anal_op failed\n"); res = false; goto cleanup_after_push; } // This is slow because we do lots of strcmp's. - // To improve this, the function r_anal_optype_string_to_int should be implemented + // To improve this, the function rz_anal_optype_string_to_int should be implemented // I also don't check if the opcode type exists. - const char *optype_str = r_anal_optype_to_string (op.type); - r_list_foreach (optypes_list, iter, optype) { + const char *optype_str = rz_anal_optype_to_string (op.type); + rz_list_foreach (optypes_list, iter, optype) { if (!strcmp (optype_str, optype)) { goto cleanup_after_push; } @@ -929,81 +929,81 @@ static int step_until_optype(RCore *core, const char *_optypes) { } cleanup_after_push: - r_cons_break_pop (); + rz_cons_break_pop (); end: free (optypes); - r_list_free (optypes_list); + rz_list_free (optypes_list); return res; } -static int step_until_flag(RCore *core, const char *instr) { - const RList *list; - RListIter *iter; - RFlagItem *f; +static int step_until_flag(RzCore *core, const char *instr) { + const RzList *list; + RzListIter *iter; + RzFlagItem *f; ut64 pc; - instr = r_str_trim_head_ro (instr); + instr = rz_str_trim_head_ro (instr); if (!core || !instr || !core->dbg) { eprintf ("Wrong state\n"); return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { break; } - r_debug_step (core->dbg, 1); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); - pc = r_debug_reg_get (core->dbg, "PC"); - list = r_flag_get_list (core->flags, pc); - r_list_foreach (list, iter, f) { + rz_debug_step (core->dbg, 1); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); + pc = rz_debug_reg_get (core->dbg, "PC"); + list = rz_flag_get_list (core->flags, pc); + rz_list_foreach (list, iter, f) { if (!instr|| !*instr || (f->realname && strstr(f->realname, instr))) { - r_cons_printf ("[ 0x%08"PFMT64x" ] %s\n", + rz_cons_printf ("[ 0x%08"PFMT64x" ] %s\n", f->offset, f->realname); goto beach; } } } beach: - r_cons_break_pop (); + rz_cons_break_pop (); return true; } /* until end of frame */ -static int step_until_eof(RCore *core) { +static int step_until_eof(RzCore *core) { int maxLoops = 200000; - ut64 off, now = r_debug_reg_get (core->dbg, "SP"); - r_cons_break_push (NULL, NULL); + ut64 off, now = rz_debug_reg_get (core->dbg, "SP"); + rz_cons_break_push (NULL, NULL); do { // XXX (HACK!) - r_debug_step_over (core->dbg, 1); - off = r_debug_reg_get (core->dbg, "SP"); + rz_debug_step_over (core->dbg, 1); + off = rz_debug_reg_get (core->dbg, "SP"); // check breakpoint here if (--maxLoops < 0) { eprintf ("Step loop limit exceeded\n"); break; } } while (off <= now); - r_cons_break_pop (); + rz_cons_break_pop (); return true; } -static int step_line(RCore *core, int times) { +static int step_line(RzCore *core, int times) { char file[512], file2[512]; int find_meta, line = -1, line2 = -1; char *tmp_ptr = NULL; - ut64 off = r_debug_reg_get (core->dbg, "PC"); + ut64 off = rz_debug_reg_get (core->dbg, "PC"); if (off == 0LL) { eprintf ("Cannot 'drn PC'\n"); return false; } file[0] = 0; file2[0] = 0; - if (r_bin_addr2line (core->bin, off, file, sizeof (file), &line)) { - char* ptr = r_file_slurp_line (file, line, 0); + if (rz_bin_addr2line (core->bin, off, file, sizeof (file), &line)) { + char* ptr = rz_file_slurp_line (file, line, 0); eprintf ("--> 0x%08"PFMT64x" %s : %d\n", off, file, line); eprintf ("--> %s\n", ptr); find_meta = false; @@ -1013,9 +1013,9 @@ static int step_line(RCore *core, int times) { find_meta = true; } do { - r_debug_step (core->dbg, 1); - off = r_debug_reg_get (core->dbg, "PC"); - if (!r_bin_addr2line (core->bin, off, file2, sizeof (file2), &line2)) { + rz_debug_step (core->dbg, 1); + off = rz_debug_reg_get (core->dbg, "PC"); + if (!rz_bin_addr2line (core->bin, off, file2, sizeof (file2), &line2)) { if (find_meta) continue; eprintf ("Cannot retrieve dwarf info at 0x%08"PFMT64x"\n", off); @@ -1024,26 +1024,26 @@ static int step_line(RCore *core, int times) { } while (!strcmp (file, file2) && line == line2); eprintf ("--> 0x%08"PFMT64x" %s : %d\n", off, file2, line2); - tmp_ptr = r_file_slurp_line (file2, line2, 0); + tmp_ptr = rz_file_slurp_line (file2, line2, 0); eprintf ("--> %s\n", tmp_ptr); free (tmp_ptr); return true; } -static void cmd_debug_pid(RCore *core, const char *input) { +static void cmd_debug_pid(RzCore *core, const char *input) { int pid, sig; const char *ptr; switch (input[1]) { case '\0': // "dp" eprintf ("Selected: %d %d\n", core->dbg->pid, core->dbg->tid); - r_debug_pid_list (core->dbg, core->dbg->pid, 0); + rz_debug_pid_list (core->dbg, core->dbg->pid, 0); break; case '-': // "dp-" if (input[2]== ' ') { - r_debug_detach (core->dbg, r_num_math (core->num, input + 2)); + rz_debug_detach (core->dbg, rz_num_math (core->num, input + 2)); } else { - r_debug_detach (core->dbg, core->dbg->pid); + rz_debug_detach (core->dbg, core->dbg->pid); } break; case 'c': // "dpc" @@ -1051,7 +1051,7 @@ static void cmd_debug_pid(RCore *core, const char *input) { if (input[2] == '*') { eprintf ("dp %d\n", core->dbg->forked_pid); } else { - r_debug_select (core->dbg, core->dbg->forked_pid, core->dbg->tid); + rz_debug_select (core->dbg, core->dbg->forked_pid, core->dbg->tid); core->dbg->main_pid = core->dbg->forked_pid; core->dbg->n_threads = 0; core->dbg->forked_pid = -1; @@ -1066,129 +1066,129 @@ static void cmd_debug_pid(RCore *core, const char *input) { /* XXX: but we want fine-grained access to process resources */ pid = atoi (input + 2); if (pid > 0) { - ptr = r_str_trim_head_ro (input + 2); + ptr = rz_str_trim_head_ro (input + 2); ptr = strchr (ptr, ' '); sig = ptr? atoi (ptr + 1): 0; eprintf ("Sending signal '%d' to pid '%d'\n", sig, pid); - r_debug_kill (core->dbg, pid, false, sig); + rz_debug_kill (core->dbg, pid, false, sig); } else eprintf ("cmd_debug_pid: Invalid arguments (%s)\n", input); break; case 'n': // "dpn" - eprintf ("TODO: debug_fork: %d\n", r_debug_child_fork (core->dbg)); + eprintf ("TODO: debug_fork: %d\n", rz_debug_child_fork (core->dbg)); break; case 't': // "dpt" switch (input[2]) { case '\0': // "dpt" - r_debug_thread_list (core->dbg, core->dbg->pid, 0); + rz_debug_thread_list (core->dbg, core->dbg->pid, 0); break; case 'j': // "dptj" if (input[3] != ' ') { // "dptj" - r_debug_thread_list (core->dbg, core->dbg->pid, 'j'); + rz_debug_thread_list (core->dbg, core->dbg->pid, 'j'); } else { // "dptj " - r_debug_thread_list (core->dbg, atoi (input + 3), 'j'); + rz_debug_thread_list (core->dbg, atoi (input + 3), 'j'); } break; case ' ': // "dpt " - r_debug_thread_list (core->dbg, atoi (input + 2), 0); + rz_debug_thread_list (core->dbg, atoi (input + 2), 0); break; case '=': // "dpt=" - r_debug_select (core->dbg, core->dbg->pid, - (int) r_num_math (core->num, input + 3)); + rz_debug_select (core->dbg, core->dbg->pid, + (int) rz_num_math (core->num, input + 3)); break; case 'n': // "dptn" - eprintf ("TODO: debug_clone: %d\n", r_debug_child_clone (core->dbg)); + eprintf ("TODO: debug_clone: %d\n", rz_debug_child_clone (core->dbg)); break; case '?': // "dpt?" default: - r_core_cmd_help (core, help_msg_dp); + rz_core_cmd_help (core, help_msg_dp); break; } break; case 'a': // "dpa" if (input[2]) { - r_debug_attach (core->dbg, (int) r_num_math ( + rz_debug_attach (core->dbg, (int) rz_num_math ( core->num, input + 2)); } else { if (core->file && core->io) { - r_debug_attach (core->dbg, - r_io_fd_get_pid (core->io, core->file->fd)); + rz_debug_attach (core->dbg, + rz_io_fd_get_pid (core->io, core->file->fd)); } } - r_debug_select (core->dbg, core->dbg->pid, core->dbg->tid); - r_config_set_i (core->config, "dbg.swstep", + rz_debug_select (core->dbg, core->dbg->pid, core->dbg->tid); + rz_config_set_i (core->config, "dbg.swstep", (core->dbg->h && !core->dbg->h->canstep)); - r_core_cmdf (core, "=!pid %d", core->dbg->pid); + rz_core_cmdf (core, "=!pid %d", core->dbg->pid); break; case 'f': // "dpf" if (core->file && core->io) { - r_debug_select (core->dbg, r_io_fd_get_pid (core->io, core->file->fd), - r_io_fd_get_tid (core->io, core->file->fd)); + rz_debug_select (core->dbg, rz_io_fd_get_pid (core->io, core->file->fd), + rz_io_fd_get_tid (core->io, core->file->fd)); } break; case '=': // "dp=" - r_debug_select (core->dbg, - (int) r_num_math (core->num, input + 2), core->dbg->tid); - core->dbg->main_pid = r_num_math (core->num, input + 2); + rz_debug_select (core->dbg, + (int) rz_num_math (core->num, input + 2), core->dbg->tid); + core->dbg->main_pid = rz_num_math (core->num, input + 2); break; case 'l': // "dpl" switch (input[2]) { case '\0': // "dpl" - r_debug_pid_list (core->dbg, 0, 0); + rz_debug_pid_list (core->dbg, 0, 0); break; case 'j': // "dplj" - r_debug_pid_list (core->dbg, 0, 'j'); + rz_debug_pid_list (core->dbg, 0, 'j'); break; } break; case 'j': // "dpj" switch (input[2]) { case '\0': // "dpj" - r_debug_pid_list (core->dbg, core->dbg->pid, 'j'); + rz_debug_pid_list (core->dbg, core->dbg->pid, 'j'); break; case ' ': // "dpj " - r_debug_pid_list (core->dbg, - (int) R_MAX (0, (int)r_num_math (core->num, input + 2)), 'j'); + rz_debug_pid_list (core->dbg, + (int) R_MAX (0, (int)rz_num_math (core->num, input + 2)), 'j'); break; } break; case 'e': // "dpe" { int pid = (input[2] == ' ')? atoi (input + 2): core->dbg->pid; - char *exe = r_sys_pid_to_path (pid); + char *exe = rz_sys_pid_to_path (pid); if (exe) { - r_cons_println (exe); + rz_cons_println (exe); free (exe); } } break; case ' ': // "dp " - r_debug_pid_list (core->dbg, - (int) R_MAX (0, (int)r_num_math (core->num, input + 2)), 0); + rz_debug_pid_list (core->dbg, + (int) R_MAX (0, (int)rz_num_math (core->num, input + 2)), 0); break; case '?': // "dp?" default: - r_core_cmd_help (core, help_msg_dp); + rz_core_cmd_help (core, help_msg_dp); break; } } -static void cmd_debug_backtrace(RCore *core, const char *input) { - RAnalOp analop; - ut64 addr, len = r_num_math (core->num, input); +static void cmd_debug_backtrace(RzCore *core, const char *input) { + RzAnalOp analop; + ut64 addr, len = rz_num_math (core->num, input); if (!len) { - r_bp_traptrace_list (core->dbg->bp); + rz_bp_traptrace_list (core->dbg->bp); } else { ut64 oaddr = 0LL; eprintf ("Trap tracing 0x%08"PFMT64x"-0x%08"PFMT64x"\n", core->offset, core->offset+len); - r_reg_arena_swap (core->dbg->reg, true); - r_bp_traptrace_reset (core->dbg->bp, true); - r_bp_traptrace_add (core->dbg->bp, core->offset, core->offset+len); - r_bp_traptrace_enable (core->dbg->bp, true); + rz_reg_arena_swap (core->dbg->reg, true); + rz_bp_traptrace_reset (core->dbg->bp, true); + rz_bp_traptrace_add (core->dbg->bp, core->offset, core->offset+len); + rz_bp_traptrace_enable (core->dbg->bp, true); do { ut8 buf[32]; - r_debug_continue (core->dbg); - addr = r_debug_reg_get (core->dbg, "PC"); + rz_debug_continue (core->dbg); + addr = rz_debug_reg_get (core->dbg, "PC"); if (!addr) { eprintf ("pc=0\n"); break; @@ -1200,27 +1200,27 @@ static void cmd_debug_backtrace(RCore *core, const char *input) { oaddr = addr; /* XXX Bottleneck..we need to reuse the bytes read by traptrace */ // XXX Do asm.arch should define the max size of opcode? - r_io_read_at (core->io, addr, buf, 32); // XXX longer opcodes? - r_anal_op (core->anal, &analop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); - } while (r_bp_traptrace_at (core->dbg->bp, addr, analop.size)); - r_bp_traptrace_enable (core->dbg->bp, false); + rz_io_read_at (core->io, addr, buf, 32); // XXX longer opcodes? + rz_anal_op (core->anal, &analop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + } while (rz_bp_traptrace_at (core->dbg->bp, addr, analop.size)); + rz_bp_traptrace_enable (core->dbg->bp, false); } } -static int grab_bits(RCore *core, const char *arg, int *pcbits2) { +static int grab_bits(RzCore *core, const char *arg, int *pcbits2) { int pcbits = atoi (arg); if (pcbits2) { *pcbits2 = 0; } if (pcbits < 1) { - if (!strcmp (r_config_get (core->config, "asm.arch"), "avr")) { + if (!strcmp (rz_config_get (core->config, "asm.arch"), "avr")) { pcbits = 8; if (pcbits2) { *pcbits2 = 32; } } else { - const char *pcname = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - RRegItem *reg = r_reg_get (core->anal->reg, pcname, 0); + const char *pcname = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + RzRegItem *reg = rz_reg_get (core->anal->reg, pcname, 0); if (reg) { if (core->rasm->bits != reg->size) pcbits = reg->size; @@ -1231,14 +1231,14 @@ static int grab_bits(RCore *core, const char *arg, int *pcbits2) { } #define MAX_MAP_SIZE 1024*1024*512 -static int dump_maps(RCore *core, int perm, const char *filename) { - RDebugMap *map; - RListIter *iter; - r_debug_map_sync (core->dbg); // update process memory maps +static int dump_maps(RzCore *core, int perm, const char *filename) { + RzDebugMap *map; + RzListIter *iter; + rz_debug_map_sync (core->dbg); // update process memory maps ut64 addr = core->offset; int do_dump = false; - int ret = !r_list_empty (core->dbg->maps); - r_list_foreach (core->dbg->maps, iter, map) { + int ret = !rz_list_empty (core->dbg->maps); + rz_list_foreach (core->dbg->maps, iter, map) { do_dump = false; if (perm == -1) { if (addr >= map->addr && addr < map->addr_end) { @@ -1263,12 +1263,12 @@ static int dump_maps(RCore *core, int perm, const char *filename) { free (buf); continue; } - r_io_read_at (core->io, map->addr, buf, map->size); + rz_io_read_at (core->io, map->addr, buf, map->size); char *file = filename ? strdup (filename) - : r_str_newf ("0x%08"PFMT64x"-0x%08"PFMT64x"-%s.dmp", - map->addr, map->addr_end, r_str_rwx_i (map->perm)); - if (!r_file_dump (file, buf, map->size, 0)) { + : rz_str_newf ("0x%08"PFMT64x"-0x%08"PFMT64x"-%s.dmp", + map->addr, map->addr_end, rz_str_rwx_i (map->perm)); + if (!rz_file_dump (file, buf, map->size, 0)) { eprintf ("Cannot write '%s'\n", file); ret = 0; } else { @@ -1282,16 +1282,16 @@ static int dump_maps(RCore *core, int perm, const char *filename) { return ret; } -static void cmd_debug_modules(RCore *core, int mode) { // "dmm" +static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" ut64 addr = core->offset; - RDebugMap *map; - RList *list; - RListIter *iter; + RzDebugMap *map; + RzList *list; + RzListIter *iter; /* avoid processing the list if the user only wants help */ if (mode == '?') { show_help: - r_core_cmd_help (core, help_msg_dmm); + rz_core_cmd_help (core, help_msg_dmm); return; } PJ *pj = pj_new (); @@ -1299,15 +1299,15 @@ show_help: pj_a (pj); } // TODO: honor mode - list = r_debug_modules_list (core->dbg); - r_list_foreach (list, iter, map) { + list = rz_debug_modules_list (core->dbg); + rz_list_foreach (list, iter, map) { switch (mode) { case 0: - r_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", map->addr, map->addr_end, map->file); + rz_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", map->addr, map->addr_end, map->file); break; case '.': if (addr >= map->addr && addr < map->addr_end) { - r_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", map->addr, map->addr_end, map->file); + rz_cons_printf ("0x%08"PFMT64x" 0x%08"PFMT64x" %s\n", map->addr, map->addr_end, map->file); goto beach; } break; @@ -1327,20 +1327,20 @@ show_help: if (mode == '*' || (mode == ':' && \ addr>=map->addr && addr < map->addr_end)) { /* Escape backslashes (e.g. for Windows). */ - char *escaped_path = r_str_escape (map->file); + char *escaped_path = rz_str_escape (map->file); char *filtered_name = strdup (map->name); - r_name_filter (filtered_name, 0); - r_cons_printf ("f mod.%s = 0x%08"PFMT64x"\n", + rz_name_filter (filtered_name, 0); + rz_cons_printf ("f mod.%s = 0x%08"PFMT64x"\n", filtered_name, map->addr); - r_cons_printf ("oba 0x%08"PFMT64x" %s\n", map->addr, escaped_path); - // r_cons_printf (".!rabin2 -rsB 0x%08"PFMT64x" \"%s\"\n", map->addr, escaped_path); + rz_cons_printf ("oba 0x%08"PFMT64x" %s\n", map->addr, escaped_path); + // rz_cons_printf (".!rz_bin -rsB 0x%08"PFMT64x" \"%s\"\n", map->addr, escaped_path); free (escaped_path); free (filtered_name); } break; default: pj_free (pj); - r_list_free (list); + rz_list_free (list); goto show_help; /* not reached */ } @@ -1348,56 +1348,56 @@ show_help: beach: if (mode == 'j') { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); } pj_free (pj); - r_list_free (list); + rz_list_free (list); } #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ -static int cmd_dbg_map_heap_glibc_32(RCore *core, const char *input); -static int cmd_dbg_map_heap_glibc_64(RCore *core, const char *input); +static int cmd_dbg_map_heap_glibc_32(RzCore *core, const char *input); +static int cmd_dbg_map_heap_glibc_64(RzCore *core, const char *input); #endif // __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ #if __WINDOWS__ -static int cmd_debug_map_heap_win(RCore *core, const char *input); +static int cmd_debug_map_heap_win(RzCore *core, const char *input); #endif // __WINDOWS__ -static ut64 addroflib(RCore *core, const char *libname) { - RListIter *iter; - RDebugMap *map; +static ut64 addroflib(RzCore *core, const char *libname) { + RzListIter *iter; + RzDebugMap *map; if (!core || !libname) { return UT64_MAX; } - r_debug_map_sync (core->dbg); - // RList *list = r_debug_native_modules_get (core->dbg); - RList *list = r_debug_modules_list (core->dbg); - r_list_foreach (list, iter, map) { - if (strstr (r_file_basename(map->name), libname)) { + rz_debug_map_sync (core->dbg); + // RzList *list = rz_debug_native_modules_get (core->dbg); + RzList *list = rz_debug_modules_list (core->dbg); + rz_list_foreach (list, iter, map) { + if (strstr (rz_file_basename(map->name), libname)) { return map->addr; } } - r_list_foreach (core->dbg->maps, iter, map) { - if (strstr (r_file_basename(map->name), libname)) { + rz_list_foreach (core->dbg->maps, iter, map) { + if (strstr (rz_file_basename(map->name), libname)) { return map->addr; } } return UT64_MAX; } -static RDebugMap *get_closest_map(RCore *core, ut64 addr) { - RListIter *iter; - RDebugMap *map; +static RzDebugMap *get_closest_map(RzCore *core, ut64 addr) { + RzListIter *iter; + RzDebugMap *map; - r_debug_map_sync (core->dbg); - RList *list = r_debug_modules_list (core->dbg); - r_list_foreach (list, iter, map) { + rz_debug_map_sync (core->dbg); + RzList *list = rz_debug_modules_list (core->dbg); + rz_list_foreach (list, iter, map) { if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) { return map; } } - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) { return map; } @@ -1405,8 +1405,8 @@ static RDebugMap *get_closest_map(RCore *core, ut64 addr) { return NULL; } -static int r_debug_heap(RCore *core, const char *input) { - const char *m = r_config_get (core->config, "dbg.malloc"); +static int rz_debug_heap(RzCore *core, const char *input) { + const char *m = rz_config_get (core->config, "dbg.malloc"); if (m && !strcmp ("glibc", m)) { #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ if (core->rasm->bits == 64) { @@ -1436,18 +1436,18 @@ static int r_debug_heap(RCore *core, const char *input) { return true; } -static bool get_bin_info(RCore *core, const char *file, ut64 baseaddr, int mode, bool symbols_only, RCoreBinFilter *filter) { +static bool get_bin_info(RzCore *core, const char *file, ut64 baseaddr, int mode, bool symbols_only, RzCoreBinFilter *filter) { int fd; - if ((fd = r_io_fd_open (core->io, file, R_PERM_R, 0)) == -1) { + if ((fd = rz_io_fd_open (core->io, file, R_PERM_R, 0)) == -1) { return false; } RBinOptions opt = { 0 }; opt.fd = fd; - opt.sz = r_io_fd_size (core->io, fd); + opt.sz = rz_io_fd_size (core->io, fd); opt.baseaddr = baseaddr; - RBinFile *obf = r_bin_cur (core->bin); - if (!r_bin_open_io (core->bin, &opt)) { - r_io_fd_close (core->io, fd); + RBinFile *obf = rz_bin_cur (core->bin); + if (!rz_bin_open_io (core->bin, &opt)) { + rz_io_fd_close (core->io, fd); return false; } int action = R_CORE_BIN_ACC_ALL & ~R_CORE_BIN_ACC_INFO; @@ -1456,22 +1456,22 @@ static bool get_bin_info(RCore *core, const char *file, ut64 baseaddr, int mode, } else if (mode == R_MODE_SET || mode == R_MODE_RADARE) { action &= ~R_CORE_BIN_ACC_ENTRIES & ~R_CORE_BIN_ACC_MAIN; } - r_core_bin_info (core, action, mode, 1, filter, NULL); - RBinFile *bf = r_bin_cur (core->bin); - r_bin_file_delete (core->bin, bf->id); - r_bin_file_set_cur_binfile (core->bin, obf); - r_io_fd_close (core->io, fd); + rz_core_bin_info (core, action, mode, 1, filter, NULL); + RBinFile *bf = rz_bin_cur (core->bin); + rz_bin_file_delete (core->bin, bf->id); + rz_bin_file_set_cur_binfile (core->bin, obf); + rz_io_fd_close (core->io, fd); return true; } -static int cmd_debug_map(RCore *core, const char *input) { - RListIter *iter; - RDebugMap *map; +static int cmd_debug_map(RzCore *core, const char *input) { + RzListIter *iter; + RzDebugMap *map; ut64 addr = core->offset; switch (input[0]) { case '.': // "dm." - r_debug_map_list (core->dbg, addr, input); + rz_debug_map_list (core->dbg, addr, input); break; case 'm': // "dmm" if (!strcmp (input + 1, ".*")) { @@ -1479,11 +1479,11 @@ static int cmd_debug_map(RCore *core, const char *input) { } else cmd_debug_modules (core, input[1]); break; case '?': // "dm?" - r_core_cmd_help (core, help_msg_dm); + rz_core_cmd_help (core, help_msg_dm); break; case 'p': // "dmp" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_dmp); + rz_core_cmd_help (core, help_msg_dmp); } else if (input[1] == ' ') { int perms; char *p, *q; @@ -1494,26 +1494,26 @@ static int cmd_debug_map(RCore *core, const char *input) { q = strchr (p, ' '); if (q) { *q++ = 0; - addr = r_num_math (core->num, input + 2); - size = r_num_math (core->num, p); - perms = r_str_rwx (q); + addr = rz_num_math (core->num, input + 2); + size = rz_num_math (core->num, p); + perms = rz_str_rwx (q); // eprintf ("(%s)(%s)(%s)\n", input + 2, p, q); // eprintf ("0x%08"PFMT64x" %d %o\n", addr, (int) size, perms); - r_debug_map_protect (core->dbg, addr, size, perms); + rz_debug_map_protect (core->dbg, addr, size, perms); } else eprintf ("See dmp?\n"); } else { - r_debug_map_sync (core->dbg); // update process memory maps + rz_debug_map_sync (core->dbg); // update process memory maps addr = UT64_MAX; - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (core->offset >= map->addr && core->offset < map->addr_end) { addr = map->addr; size = map->size; break; } } - perms = r_str_rwx (input + 2); + perms = rz_str_rwx (input + 2); if (addr != UT64_MAX && perms >= 0) { - r_debug_map_protect (core->dbg, addr, size, perms); + rz_debug_map_protect (core->dbg, addr, size, perms); } else { eprintf ("See dmp?\n"); } @@ -1539,17 +1539,17 @@ static int cmd_debug_map(RCore *core, const char *input) { eprintf ("Usage: dml [file]\n"); return false; } - r_debug_map_sync (core->dbg); // update process memory maps - r_list_foreach (core->dbg->maps, iter, map) { + rz_debug_map_sync (core->dbg); // update process memory maps + rz_list_foreach (core->dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { size_t sz; - char *buf = r_file_slurp (input + 2, &sz); + char *buf = rz_file_slurp (input + 2, &sz); //TODO: use mmap here. we need a portable implementation if (!buf) { eprintf ("Cannot allocate 0x%08"PFMT64x" byte(s)\n", map->size); return false; } - r_io_write_at (core->io, map->addr, (const ut8*)buf, sz); + rz_io_write_at (core->io, map->addr, (const ut8*)buf, sz); if (sz != map->size) eprintf ("File size differs from region size (%"PFMT64u" vs %"PFMT64d")\n", (ut64)sz, map->size); @@ -1564,7 +1564,7 @@ static int cmd_debug_map(RCore *core, const char *input) { case 'i': // "dmi" switch (input[1]) { case '\0': // "dmi" alias of "dmm" - r_core_cmd (core, "dmm", 0); + rz_core_cmd (core, "dmm", 0); break; case ' ': // "dmi " case '*': // "dmi*" @@ -1600,36 +1600,36 @@ static int cmd_debug_map(RCore *core, const char *input) { mode = R_MODE_PRINT; break; } - ptr = strdup (r_str_trim_head_ro (input + 2)); + ptr = strdup (rz_str_trim_head_ro (input + 2)); if (!ptr || !*ptr) { - r_core_cmd (core, "dmm", 0); + rz_core_cmd (core, "dmm", 0); free (ptr); break; } if (symbols_only) { - i = r_str_word_set0 (ptr); + i = rz_str_word_set0 (ptr); } switch (i) { case 2: - symname = r_str_word_get0 (ptr, 1); + symname = rz_str_word_get0 (ptr, 1); // fall through case 1: - a0 = r_str_word_get0 (ptr, 0); - addr = r_num_get (core->num, a0); + a0 = rz_str_word_get0 (ptr, 0); + addr = rz_num_get (core->num, a0); if (!addr || addr == UT64_MAX) { - libname = r_str_word_get0 (ptr, 0); + libname = rz_str_word_get0 (ptr, 0); } break; } if (libname && !addr) { - addr = addroflib (core, r_file_basename (libname)); + addr = addroflib (core, rz_file_basename (libname)); if (addr == UT64_MAX) { eprintf ("Unknown library, or not found in dm\n"); } } map = get_closest_map (core, addr); if (map) { - RCoreBinFilter filter; + RzCoreBinFilter filter; filter.offset = 0LL; filter.name = (char *)symname; baddr = map->addr; @@ -1637,25 +1637,25 @@ static int cmd_debug_map(RCore *core, const char *input) { if (libname) { const char *file = map->file? map->file: map->name; char *newfile = NULL; - if (!r_file_exists (file)) { - newfile = r_file_temp ("memlib"); + if (!rz_file_exists (file)) { + newfile = rz_file_temp ("memlib"); if (newfile) { file = newfile; - r_core_cmdf (core, "wtf %s 0x%"PFMT64x" @ 0x%"PFMT64x" 2> %s", + rz_core_cmdf (core, "wtf %s 0x%"PFMT64x" @ 0x%"PFMT64x" 2> %s", file, map->size, baddr, R_SYS_DEVNULL); } } get_bin_info (core, file, baddr, mode, symbols_only, &filter); if (newfile) { - if (!r_file_rm (newfile)) { + if (!rz_file_rm (newfile)) { eprintf ("Error when removing %s\n", newfile); } free (newfile); } } else { - r_bin_set_baddr (core->bin, map->addr); - r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, (input[1]=='*'), true, &filter, NULL); - r_bin_set_baddr (core->bin, baddr); + rz_bin_set_baddr (core->bin, map->addr); + rz_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, (input[1]=='*'), true, &filter, NULL); + rz_bin_set_baddr (core->bin, baddr); } } free (ptr); @@ -1666,10 +1666,10 @@ static int cmd_debug_map(RCore *core, const char *input) { map = get_closest_map (core, addr); if (map) { ut64 closest_addr = UT64_MAX; - RList *symbols = r_bin_get_symbols (core->bin); + RzList *symbols = rz_bin_get_symbols (core->bin); RBinSymbol *symbol, *closest_symbol = NULL; - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (symbol->vaddr > addr) { if (symbol->vaddr - addr < closest_addr) { closest_addr = symbol->vaddr - addr; @@ -1683,18 +1683,18 @@ static int cmd_debug_map(RCore *core, const char *input) { } } if (closest_symbol) { - RCoreBinFilter filter; + RzCoreBinFilter filter; filter.offset = 0LL; filter.name = (char *) closest_symbol->name; - r_bin_set_baddr (core->bin, map->addr); - r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, false, true, &filter, NULL); + rz_bin_set_baddr (core->bin, map->addr); + rz_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, false, true, &filter, NULL); } } } break; default: - r_core_cmd_help (core, help_msg_dmi); + rz_core_cmd_help (core, help_msg_dmi); break; } break; @@ -1706,53 +1706,53 @@ static int cmd_debug_map(RCore *core, const char *input) { int i; if (input[1]=='*') { - ptr = strdup (r_str_trim_head_ro ((char*)input + 2)); + ptr = strdup (rz_str_trim_head_ro ((char*)input + 2)); mode = "-r "; } else { - ptr = strdup (r_str_trim_head_ro ((char*)input + 1)); + ptr = strdup (rz_str_trim_head_ro ((char*)input + 1)); } - i = r_str_word_set0 (ptr); + i = rz_str_word_set0 (ptr); addr = UT64_MAX; switch (i) { case 2: // get section name - sectname = r_str_word_get0 (ptr, 1); + sectname = rz_str_word_get0 (ptr, 1); /* fallthrou */ case 1: // get addr|libname if (IS_DIGIT (*ptr)) { - const char *a0 = r_str_word_get0 (ptr, 0); - addr = r_num_math (core->num, a0); + const char *a0 = rz_str_word_get0 (ptr, 0); + addr = rz_num_math (core->num, a0); } else { addr = UT64_MAX; } if (!addr || addr == UT64_MAX) { - libname = r_str_word_get0 (ptr, 0); + libname = rz_str_word_get0 (ptr, 0); } break; } - r_debug_map_sync (core->dbg); // update process memory maps - RList *list = r_debug_modules_list (core->dbg); - r_list_foreach (list, iter, map) { + rz_debug_map_sync (core->dbg); // update process memory maps + RzList *list = rz_debug_modules_list (core->dbg); + rz_list_foreach (list, iter, map) { if ((!libname || (addr != UT64_MAX && (addr >= map->addr && addr < map->addr_end)) || (libname != NULL && (strstr (map->name, libname))))) { baddr = map->addr; char *res; const char *file = map->file? map->file: map->name; - char *name = r_str_escape ((char *)r_file_basename (file)); - char *filesc = r_str_escape (file); + char *name = rz_str_escape ((char *)rz_file_basename (file)); + char *filesc = rz_str_escape (file); /* TODO: do not spawn. use RBin API */ if (sectname) { - char *sect = r_str_escape (sectname); - res = r_sys_cmd_strf ("env RABIN2_PREFIX=\"%s\" rabin2 %s-B 0x%08" + char *sect = rz_str_escape (sectname); + res = rz_sys_cmd_strf ("env RABIN2_PREFIX=\"%s\" rz_bin %s-B 0x%08" PFMT64x" -S \"%s\" | grep \"%s\"", name, mode, baddr, filesc, sect); free (sect); } else { - res = r_sys_cmd_strf ("env RABIN2_PREFIX=\"%s\" rabin2 %s-B 0x%08" + res = rz_sys_cmd_strf ("env RABIN2_PREFIX=\"%s\" rz_bin %s-B 0x%08" PFMT64x" -S \"%s\"", name, mode, baddr, filesc); } free (filesc); - r_cons_println (res); + rz_cons_println (res); free(name); free (res); if (libname || addr != UT64_MAX) { //only single match requested @@ -1769,9 +1769,9 @@ static int cmd_debug_map(RCore *core, const char *input) { char *p = strchr (input + 2, ' '); if (p) { *p++ = 0; - addr = r_num_math (core->num, input + 1); - size = r_num_math (core->num, p); - r_debug_map_alloc (core->dbg, addr, size, false); + addr = rz_num_math (core->num, input + 1); + size = rz_num_math (core->num, p); + rz_debug_map_alloc (core->dbg, addr, size, false); } else { eprintf ("Usage: dm addr size\n"); return false; @@ -1783,11 +1783,11 @@ static int cmd_debug_map(RCore *core, const char *input) { eprintf ("|ERROR| Usage: dm- [addr]\n"); break; } - addr = r_num_math (core->num, input + 2); - r_list_foreach (core->dbg->maps, iter, map) { + addr = rz_num_math (core->num, input + 2); + rz_list_foreach (core->dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { - r_debug_map_dealloc(core->dbg, map); - r_debug_map_sync (core->dbg); + rz_debug_map_dealloc(core->dbg, map); + rz_debug_map_sync (core->dbg); return true; } } @@ -1799,9 +1799,9 @@ static int cmd_debug_map(RCore *core, const char *input) { char *p = strchr (input + 2, ' '); if (p) { *p++ = 0; - addr = r_num_math (core->num, input + 1); - size = r_num_math (core->num, p); - r_debug_map_alloc (core->dbg, addr, size, true); + addr = rz_num_math (core->num, input + 1); + size = rz_num_math (core->num, p); + rz_debug_map_alloc (core->dbg, addr, size, true); } else { eprintf ("Usage: dmL addr size\n"); return false; @@ -1812,16 +1812,16 @@ static int cmd_debug_map(RCore *core, const char *input) { case '*': // "dm*" case 'j': // "dmj" case 'q': // "dmq" - r_debug_map_sync (core->dbg); // update process memory maps - r_debug_map_list (core->dbg, core->offset, input); + rz_debug_map_sync (core->dbg); // update process memory maps + rz_debug_map_list (core->dbg, core->offset, input); break; case '=': // "dm=" - r_debug_map_sync (core->dbg); - r_debug_map_list_visual (core->dbg, core->offset, input, - r_config_get_i (core->config, "scr.color")); + rz_debug_map_sync (core->dbg); + rz_debug_map_list_visual (core->dbg, core->offset, input, + rz_config_get_i (core->config, "scr.color")); break; case 'h': // "dmh" - (void)r_debug_heap (core, input); + (void)rz_debug_heap (core, input); break; } return true; @@ -1848,79 +1848,79 @@ static int regcmp(const void *a, const void *b) { } static bool regcb(void *u, const ut64 k, const void *v) { - RList *sorted = (RList*) u; + RzList *sorted = (RzList*) u; ut64 *n = ut64_new (k); - r_list_add_sorted (sorted, n, regcmp); + rz_list_add_sorted (sorted, n, regcmp); return true; } -R_API void r_core_debug_ri(RCore *core, RReg *reg, int mode) { - RList *list = r_reg_get_list (reg, R_REG_TYPE_GPR); - RListIter *iter; - RRegItem *r; +RZ_API void rz_core_debug_ri(RzCore *core, RzReg *reg, int mode) { + RzList *list = rz_reg_get_list (reg, R_REG_TYPE_GPR); + RzListIter *iter; + RzRegItem *r; HtUP *db = ht_up_new0 (); - r_list_foreach (list, iter, r) { + rz_list_foreach (list, iter, r) { if (r->size != core->rasm->bits) { continue; } - ut64 value = r_reg_get_value (reg, r); - RList *list = ht_up_find (db, value, NULL); + ut64 value = rz_reg_get_value (reg, r); + RzList *list = ht_up_find (db, value, NULL); if (!list) { - list = r_list_newf (NULL); + list = rz_list_newf (NULL); ht_up_update (db, value, list); } - r_list_append (list, r->name); + rz_list_append (list, r->name); } - RList *sorted = r_list_newf (free); + RzList *sorted = rz_list_newf (free); ht_up_foreach (db, regcb, sorted); ut64 *addr; - r_list_foreach (sorted, iter, addr) { + rz_list_foreach (sorted, iter, addr) { int rwx = 0; - RDebugMap *map = r_debug_map_get (core->dbg, *addr); + RzDebugMap *map = rz_debug_map_get (core->dbg, *addr); if (map) { rwx = map->perm; } - r_cons_printf (" %s ", r_str_rwx_i (rwx)); + rz_cons_printf (" %s ", rz_str_rwx_i (rwx)); - r_cons_printf ("0x%08"PFMT64x" ", *addr); - RList *list = ht_up_find (db, *addr, NULL); + rz_cons_printf ("0x%08"PFMT64x" ", *addr); + RzList *list = ht_up_find (db, *addr, NULL); if (list) { - RListIter *iter; + RzListIter *iter; const char *r; - r_cons_strcat (Color_YELLOW); - r_list_foreach (list, iter, r) { - r_cons_printf (" %s", r); + rz_cons_strcat (Color_YELLOW); + rz_list_foreach (list, iter, r) { + rz_cons_printf (" %s", r); } - r_cons_strcat (Color_RESET); - char *rrstr = r_core_anal_hasrefs (core, *addr, true); + rz_cons_strcat (Color_RESET); + char *rrstr = rz_core_anal_hasrefs (core, *addr, true); if (rrstr && *rrstr && strchr (rrstr, 'R')) { - r_cons_printf (" ;%s"Color_RESET, rrstr); + rz_cons_printf (" ;%s"Color_RESET, rrstr); } - r_cons_newline (); + rz_cons_newline (); } } - r_list_free (sorted); + rz_list_free (sorted); ht_up_free (db); } -R_API void r_core_debug_rr(RCore *core, RReg *reg, int mode) { +RZ_API void rz_core_debug_rr(RzCore *core, RzReg *reg, int mode) { char *color = ""; char *colorend = ""; - int had_colors = r_config_get_i (core->config, "scr.color"); + int had_colors = rz_config_get_i (core->config, "scr.color"); bool use_colors = had_colors != 0; int delta = 0; ut64 diff, value; int bits = core->rasm->bits; - //XXX: support other RRegisterType - RList *list = r_reg_get_list (reg, R_REG_TYPE_GPR); - RListIter *iter; - RRegItem *r; - RTable *t = r_core_table (core); + //XXX: support other RzRegisterType + RzList *list = rz_reg_get_list (reg, R_REG_TYPE_GPR); + RzListIter *iter; + RzRegItem *r; + RTable *t = rz_core_table (core); if (mode == 'j') { - r_config_set_i (core->config, "scr.color", false); + rz_config_set_i (core->config, "scr.color", false); use_colors = 0; } @@ -1931,110 +1931,110 @@ R_API void r_core_debug_rr(RCore *core, RReg *reg, int mode) { colorend = Color_RESET; } - r_table_set_columnsf (t, "ssss", "role", "reg", "value", "ref"); - r_list_foreach (list, iter, r) { + rz_table_set_columnsf (t, "ssss", "role", "reg", "value", "ref"); + rz_list_foreach (list, iter, r) { if (r->size != bits) { continue; } - value = r_reg_get_value (core->dbg->reg, r); + value = rz_reg_get_value (core->dbg->reg, r); delta = 0; int regSize = r->size; //XXX: support larger regSize if (regSize < 80) { - r_reg_arena_swap (core->dbg->reg, false); - diff = r_reg_get_value (core->dbg->reg, r); - r_reg_arena_swap (core->dbg->reg, false); + rz_reg_arena_swap (core->dbg->reg, false); + diff = rz_reg_get_value (core->dbg->reg, r); + rz_reg_arena_swap (core->dbg->reg, false); delta = value-diff; } const char *role = ""; int i; for (i = 0; i < R_REG_NAME_LAST; i++) { - const char *t = r_reg_get_name (reg, i); + const char *t = rz_reg_get_name (reg, i); if (t && !strcmp (t, r->name)) { - role = r_reg_get_role (i); + role = rz_reg_get_role (i); } } char *namestr = NULL; char *valuestr = NULL; if (delta && use_colors) { - namestr = r_str_newf ("%s%s%s", color, r->name, colorend); - valuestr = r_str_newf ("%s%"PFMT64x"%s", color, value, colorend); + namestr = rz_str_newf ("%s%s%s", color, r->name, colorend); + valuestr = rz_str_newf ("%s%"PFMT64x"%s", color, value, colorend); } else { - namestr = r_str_new (r->name); - valuestr = r_str_newf ("%"PFMT64x, value); + namestr = rz_str_new (r->name); + valuestr = rz_str_newf ("%"PFMT64x, value); } - char *rrstr = r_core_anal_hasrefs (core, value, true); + char *rrstr = rz_core_anal_hasrefs (core, value, true); if (!rrstr) { rrstr = strdup (""); } - r_table_add_rowf (t, "ssss", role, namestr, valuestr, rrstr); + rz_table_add_rowf (t, "ssss", role, namestr, valuestr, rrstr); free (namestr); free (valuestr); free (rrstr); } - char *s = (mode == 'j')? r_table_tojson(t): r_table_tostring(t); - r_cons_print (s); + char *s = (mode == 'j')? rz_table_tojson(t): rz_table_tostring(t); + rz_cons_print (s); free (s); - r_table_free (t); + rz_table_free (t); if (had_colors) { - r_config_set_i (core->config, "scr.color", had_colors); + rz_config_set_i (core->config, "scr.color", had_colors); } } -static void show_drpi(RCore *core) { +static void show_drpi(RzCore *core) { int i; - RListIter *iter; - RRegItem *ri; - r_cons_printf ("Aliases (Reg->name)\n"); + RzListIter *iter; + RzRegItem *ri; + rz_cons_printf ("Aliases (Reg->name)\n"); for (i = 0; i < R_REG_NAME_LAST; i++) { - r_cons_printf ("%d %s %s\n", i, r_reg_get_role (i), core->anal->reg->name[i]); + rz_cons_printf ("%d %s %s\n", i, rz_reg_get_role (i), core->anal->reg->name[i]); } for (i = 0; i < R_REG_TYPE_LAST; i++) { - const char *nmi = r_reg_get_type (i); - r_cons_printf ("regset %d (%s)\n", i, nmi); - RRegSet *rs = &core->anal->reg->regset[i]; - r_cons_printf ("* arena %s size %d\n", r_reg_get_type (i), rs->arena->size); - r_list_foreach (rs->regs, iter, ri) { - const char *tpe = r_reg_get_type (ri->type); - const char *arn = r_reg_get_type (ri->arena); - r_cons_printf (" %s %s @ %s (offset: %d size: %d)", ri->name, tpe, arn, ri->offset / 8, ri->size / 8); + const char *nmi = rz_reg_get_type (i); + rz_cons_printf ("regset %d (%s)\n", i, nmi); + RzRegSet *rs = &core->anal->reg->regset[i]; + rz_cons_printf ("* arena %s size %d\n", rz_reg_get_type (i), rs->arena->size); + rz_list_foreach (rs->regs, iter, ri) { + const char *tpe = rz_reg_get_type (ri->type); + const char *arn = rz_reg_get_type (ri->arena); + rz_cons_printf (" %s %s @ %s (offset: %d size: %d)", ri->name, tpe, arn, ri->offset / 8, ri->size / 8); if ((ri->offset / 8) + (ri->size / 8) > rs->arena->size) { - r_cons_printf (" *OVERFLOW*"); + rz_cons_printf (" *OVERFLOW*"); } - r_cons_newline (); + rz_cons_newline (); } } } -static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" and "drp" +static void cmd_reg_profile(RzCore *core, char from, const char *str) { // "arp" and "drp" const char *ptr; - RReg *r = r_config_get_i (core->config, "cfg.debug")? core->dbg->reg: core->anal->reg; + RzReg *r = rz_config_get_i (core->config, "cfg.debug")? core->dbg->reg: core->anal->reg; switch (str[1]) { case '\0': // "drp" "arp" if (r->reg_profile_str) { - r_cons_println (r->reg_profile_str); + rz_cons_println (r->reg_profile_str); } else { eprintf ("No register profile defined. Try 'dr.'\n"); } break; case 'c': // "drpc" "arpc" if (core->dbg->reg->reg_profile_cmt) { - r_cons_println (r->reg_profile_cmt); + rz_cons_println (r->reg_profile_cmt); } break; case 'g': // "drpg" "arpg" - ptr = r_str_trim_head_ro (str + 2); + ptr = rz_str_trim_head_ro (str + 2); if (!R_STR_ISEMPTY (ptr)) { - char *r2profile = r_reg_parse_gdb_profile (ptr); + char *r2profile = rz_reg_parse_gdb_profile (ptr); if (r2profile) { - r_cons_println (r2profile); + rz_cons_println (r2profile); core->num->value = 0; free (r2profile); } else { @@ -2046,12 +2046,12 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" } break; case ' ': // "drp " "arp " - ptr = r_str_trim_head_ro (str + 2); - r_reg_set_profile (r, ptr); - r_debug_plugin_set_reg_profile (core->dbg, ptr); + ptr = rz_str_trim_head_ro (str + 2); + rz_reg_set_profile (r, ptr); + rz_debug_plugin_set_reg_profile (core->dbg, ptr); break; case '.': { // "drp." - RRegSet *rs = r_reg_regset_get (r, R_REG_TYPE_GPR); + RzRegSet *rs = rz_reg_regset_get (r, R_REG_TYPE_GPR); if (rs) { eprintf ("size = %d\n", rs->arena->size); } @@ -2062,13 +2062,13 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" break; case 's': // "drps" "arps" if (str[2] == ' ') { - ut64 n = r_num_math (core->num, str+2); - // TODO: move this thing into the r_reg API - RRegSet *rs = r_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); + ut64 n = rz_num_math (core->num, str+2); + // TODO: move this thing into the rz_reg API + RzRegSet *rs = rz_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); if (rs && n>0) { - RListIter *iter; - RRegArena *arena; - r_list_foreach (rs->pool, iter, arena) { + RzListIter *iter; + RzRegArena *arena; + rz_list_foreach (rs->pool, iter, arena) { ut8 *newbytes = calloc (1, n); if (newbytes) { free (arena->bytes); @@ -2082,17 +2082,17 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" eprintf ("Invalid arena size\n"); } } else { - RRegSet *rs = r_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); + RzRegSet *rs = rz_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); if (rs) { - r_cons_printf ("%d\n", rs->arena->size); + rz_cons_printf ("%d\n", rs->arena->size); } else eprintf ("Cannot find GPR register arena.\n"); } break; case 'j': // "drpj" "arpj" { // "drpj" .. dup from "arpj" - RListIter *iter; - RRegItem *r; + RzListIter *iter; + RzRegItem *r; int i; PJ *pj = pj_new (); pj_o (pj); @@ -2102,7 +2102,7 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" if (core->dbg->reg->name[i]) { pj_o (pj); pj_kn (pj, "role", i); - pj_ks (pj, "role_str", r_reg_get_role (i)); + pj_ks (pj, "role_str", rz_reg_get_role (i)); pj_ks (pj, "reg", core->dbg->reg->name[i]); pj_end (pj); } @@ -2111,10 +2111,10 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" pj_k (pj, "reg_info"); pj_a (pj); for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (core->dbg->reg->regset[i].regs, iter, r) { + rz_list_foreach (core->dbg->reg->regset[i].regs, iter, r) { pj_o (pj); pj_kn (pj, "type", r->type); - pj_ks (pj, "type_str", r_reg_get_type (r->type)); + pj_ks (pj, "type_str", rz_reg_get_type (r->type)); pj_ks (pj, "name", r->name); pj_kn (pj, "size", r->size); pj_kn (pj, "offset", r->offset); @@ -2123,7 +2123,7 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" } pj_end (pj); // "]" pj_end (pj); // "}" - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); } break; @@ -2140,7 +2140,7 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" help_msg[18] = from_a[3]; help_msg[21] = from_a[4]; } - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); break; } } @@ -2148,35 +2148,35 @@ static void cmd_reg_profile(RCore *core, char from, const char *str) { // "arp" #if 0 -static int showreg(RCore *core, const char *str, bool use_color) { +static int showreg(RzCore *core, const char *str, bool use_color) { ut64 off; utX value; int err; int bits = atoi (str); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); //R_REG_TYPE_GPR, false); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); //R_REG_TYPE_GPR, false); if (bits) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color? Color_GREEN: NULL); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color? Color_GREEN: NULL); } else { - off = r_debug_reg_get_err (core->dbg, str + 1, &err, &value); + off = rz_debug_reg_get_err (core->dbg, str + 1, &err, &value); core->num->value = off; switch (err) { case 0: - r_cons_printf ("0x%08"PFMT64x"\n", off); + rz_cons_printf ("0x%08"PFMT64x"\n", off); break; case 1: - r_cons_printf ("Unknown register '%s'\n", str + 1); + rz_cons_printf ("Unknown register '%s'\n", str + 1); break; case 80: - r_cons_printf ("0x%04x%016"PFMT64x"\n", value.v80.High, value.v80.Low); + rz_cons_printf ("0x%04x%016"PFMT64x"\n", value.v80.High, value.v80.Low); break; case 96: - r_cons_printf ("0x%08x%016"PFMT64x"\n", value.v96.High, value.v96.Low); + rz_cons_printf ("0x%08x%016"PFMT64x"\n", value.v96.High, value.v96.Low); break; case 128: - r_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"\n", value.v128.High, value.v128.Low); + rz_cons_printf ("0x%016"PFMT64x"%016"PFMT64x"\n", value.v128.High, value.v128.Low); break; default: - r_cons_printf ("Error %i while retrieving '%s' \n", err, str + 1); + rz_cons_printf ("Error %i while retrieving '%s' \n", err, str + 1); core->num->value = 0; } } @@ -2190,14 +2190,14 @@ static int showreg(RCore *core, const char *str, bool use_color) { int pack_sizes[NUM_PACK_TYPES] = { 8, 16, 32, 64, 32, 64 }; char *pack_format[NUM_PACK_TYPES] = { "%s0x%02" PFMT64x, "%s0x%04" PFMT64x, "%s0x%08" PFMT64x, "%s0x%016" PFMT64x, "%s%lf" , "%s%lf" }; -#define pack_print(i, reg, pack_type_index) r_cons_printf (pack_format[pack_type_index], i != 0 ? " " : "", reg); +#define pack_print(i, reg, pack_type_index) rz_cons_printf (pack_format[pack_type_index], i != 0 ? " " : "", reg); -static void cmd_debug_reg_print_packed_reg(RCore *core, RRegItem *item, char explicit_size, char* pack_show) { +static void cmd_debug_reg_print_packed_reg(RzCore *core, RzRegItem *item, char explicit_size, char* pack_show) { int pi, i; for (pi = 0; pi < NUM_PACK_TYPES; pi++) { if (!explicit_size || pack_show[pi]) { for (i = 0; i < item->packed_size / pack_sizes[pi]; i++) { - ut64 res = r_reg_get_pack(core->dbg->reg, item, i, pack_sizes[pi]); + ut64 res = rz_reg_get_pack(core->dbg->reg, item, i, pack_sizes[pi]); if( pi > NUM_INT_PACK_TYPES-1) { // are we printing int or double? if (pack_sizes[pi] == 64) { double dres; @@ -2212,47 +2212,47 @@ static void cmd_debug_reg_print_packed_reg(RCore *core, RRegItem *item, char exp pack_print (i, res, pi); } } - r_cons_newline (); + rz_cons_newline (); } } } static char *__table_format_string(RTable *t, int fmt) { switch (fmt) { - case 'j': return r_table_tojson (t); - case 's': return r_table_tostring (t); + case 'j': return rz_table_tojson (t); + case 's': return rz_table_tostring (t); } - return r_table_tofancystring (t); + return rz_table_tofancystring (t); } -static void __tableRegList (RCore *core, RReg *reg, const char *str) { +static void __tableRegList (RzCore *core, RzReg *reg, const char *str) { int i; - RRegItem *e; - RTable *t = r_core_table (core); - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - RTableColumnType *typeBoolean = r_table_type ("boolean"); - r_table_add_column (t, typeNumber, "offset", 0); - r_table_add_column (t, typeNumber, "size", 0); - r_table_add_column (t, typeNumber, "psize", 0); - r_table_add_column (t, typeNumber, "index", 0); - r_table_add_column (t, typeNumber, "arena", 0); - r_table_add_column (t, typeBoolean, "float", 0); - r_table_add_column (t, typeString, "name", 0); - r_table_add_column (t, typeString, "flags", 0); - r_table_add_column (t, typeString, "comment", 0); + RzRegItem *e; + RTable *t = rz_core_table (core); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + RTableColumnType *typeBoolean = rz_table_type ("boolean"); + rz_table_add_column (t, typeNumber, "offset", 0); + rz_table_add_column (t, typeNumber, "size", 0); + rz_table_add_column (t, typeNumber, "psize", 0); + rz_table_add_column (t, typeNumber, "index", 0); + rz_table_add_column (t, typeNumber, "arena", 0); + rz_table_add_column (t, typeBoolean, "float", 0); + rz_table_add_column (t, typeString, "name", 0); + rz_table_add_column (t, typeString, "flags", 0); + rz_table_add_column (t, typeString, "comment", 0); for (i = 0; i < R_REG_TYPE_LAST; i++) { - RList *list = r_reg_get_list (reg, i); - RListIter *iter; - r_list_foreach (list, iter, e) { + RzList *list = rz_reg_get_list (reg, i); + RzListIter *iter; + rz_list_foreach (list, iter, e) { // sdb_fmt is not thread safe - r_table_add_row (t, + rz_table_add_row (t, sdb_fmt ("%d", e->offset), sdb_fmt ("%d", e->size), sdb_fmt ("%d", e->packed_size), sdb_fmt ("%d", e->index), sdb_fmt ("%d", i), - r_str_bool (e->is_float), + rz_str_bool (e->is_float), e->name? e->name: "", e->flags? e->flags: "", e->comment? e->comment: "", @@ -2262,22 +2262,22 @@ static void __tableRegList (RCore *core, RReg *reg, const char *str) { } const char fmt = *str++; const char *q = str; - if (r_table_query (t, q)) { + if (rz_table_query (t, q)) { char *s = __table_format_string (t, fmt); - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); } - r_table_free (t); + rz_table_free (t); } -static void cmd_debug_reg(RCore *core, const char *str) { +static void cmd_debug_reg(RzCore *core, const char *str) { char *arg; - struct r_reg_item_t *r; + struct rz_reg_item_t *r; const char *name, *use_color; size_t i; int size, type = R_REG_TYPE_GPR; int bits = (core->dbg->bits & R_SYS_BITS_64)? 64: 32; - int use_colors = r_config_get_i (core->config, "scr.color"); + int use_colors = rz_config_get_i (core->config, "scr.color"); int newbits = atoi ((str&&*str)? str + 1: ""); if (newbits > 0) { bits = newbits; @@ -2296,9 +2296,9 @@ static void cmd_debug_reg(RCore *core, const char *str) { case 'C': // "drC" { const bool json_out = str[1] == 'j'; - name = r_str_trim_head_ro (json_out ? str + 3 : str + 2); + name = rz_str_trim_head_ro (json_out ? str + 3 : str + 2); if (name) { - r = r_reg_get (core->dbg->reg, name , -1); + r = rz_reg_get (core->dbg->reg, name , -1); if (r) { if (json_out) { PJ *pj = pj_new (); @@ -2310,11 +2310,11 @@ static void cmd_debug_reg(RCore *core, const char *str) { } pj_end (pj); const char *s = pj_string (pj); - r_cons_println (s); + rz_cons_println (s); pj_free (pj); } else { if (r->comment) { - r_cons_printf ("%s\n", r->comment); + rz_cons_printf ("%s\n", r->comment); } else { eprintf ("Register %s doesn't have any comments\n", name); } @@ -2328,67 +2328,67 @@ static void cmd_debug_reg(RCore *core, const char *str) { } break; case '-': // "dr-" - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, '-', 0); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, '-', 0); break; case '?': // "dr?" if (str[1]) { - RListIter *iter; - char *all = (char *)r_str_trim_head_ro (str + 1); + RzListIter *iter; + char *all = (char *)rz_str_trim_head_ro (str + 1); if (!strcmp (all, "?")) { // "dr??" - all = r_core_cmd_str (core, "drp~=[0]"); - all = r_str_replace (all, "\n", " ", 1); + all = rz_core_cmd_str (core, "drp~=[0]"); + all = rz_str_replace (all, "\n", " ", 1); } else { all = strdup (all); } char *arg; - RList *args = r_str_split_list (all, " ", 0); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); //R_REG_TYPE_GPR, false); - int count = r_list_length (args); - r_list_foreach (args, iter, arg) { - ut64 off = r_debug_reg_get (core->dbg, arg); + RzList *args = rz_str_split_list (all, " ", 0); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); //R_REG_TYPE_GPR, false); + int count = rz_list_length (args); + rz_list_foreach (args, iter, arg) { + ut64 off = rz_debug_reg_get (core->dbg, arg); if (count == 1) { - r_cons_printf ("0x%08"PFMT64x"\n", off); + rz_cons_printf ("0x%08"PFMT64x"\n", off); } else { - int type = r_reg_get_name_idx (arg); + int type = rz_reg_get_name_idx (arg); const char *r = arg; if (type != -1) { - r = r_reg_get_name (core->dbg->reg, type); + r = rz_reg_get_name (core->dbg->reg, type); } - r_cons_printf ("%3s %3s 0x%08"PFMT64x"\n", arg, r, off); + rz_cons_printf ("%3s %3s 0x%08"PFMT64x"\n", arg, r, off); } core->num->value = off; } free (all); - r_list_free (args); + rz_list_free (args); } else { - r_core_cmd_help (core, help_msg_dr); + rz_core_cmd_help (core, help_msg_dr); } break; case 'l': // "drl[j]" { const bool json_out = str[1] == 'j'; - RRegSet *rs = r_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); + RzRegSet *rs = rz_reg_regset_get (core->dbg->reg, R_REG_TYPE_GPR); if (rs) { - RRegItem *r; - RListIter *iter; + RzRegItem *r; + RzListIter *iter; i = 0; PJ *pj = NULL; if (json_out) { pj = pj_new (); pj_a (pj); } - r_list_foreach (rs->regs, iter, r) { + rz_list_foreach (rs->regs, iter, r) { if (json_out) { pj_s (pj, r->name); i++; } else { - r_cons_println (r->name); + rz_cons_println (r->name); } } if (json_out) { pj_end (pj); const char *s = pj_string (pj); - r_cons_println (s); + rz_cons_println (s); pj_free (pj); } } @@ -2400,37 +2400,37 @@ static void cmd_debug_reg(RCore *core, const char *str) { int len, type = R_REG_TYPE_GPR; arg = strchr (str, ' '); if (arg) { - char *string = r_str_trim_dup (arg + 1); + char *string = rz_str_trim_dup (arg + 1); if (string) { - type = r_reg_type_by_name (string); + type = rz_reg_type_by_name (string); if (type == -1 && string[0] != 'a') { type = R_REG_TYPE_GPR; } free (string); } } - ut8 *buf = r_reg_get_bytes (core->dbg->reg, type, &len); + ut8 *buf = rz_reg_get_bytes (core->dbg->reg, type, &len); if (str[0] == '8') { - r_print_bytes (core->print, buf, len, "%02x"); + rz_print_bytes (core->print, buf, len, "%02x"); } else { switch (str[1]) { case '1': - r_print_hexdump (core->print, 0ll, buf, len, 8, 1, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 8, 1, 1); break; case '2': - r_print_hexdump (core->print, 0ll, buf, len, 16, 2, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 16, 2, 1); break; case '4': - r_print_hexdump (core->print, 0ll, buf, len, 32, 4, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 32, 4, 1); break; case '8': - r_print_hexdump (core->print, 0ll, buf, len, 64, 8, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 64, 8, 1); break; default: if (core->rasm->bits == 64) { - r_print_hexdump (core->print, 0ll, buf, len, 64, 8, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 64, 8, 1); } else { - r_print_hexdump (core->print, 0ll, buf, len, 32, 4, 1); + rz_print_hexdump (core->print, 0ll, buf, len, 32, 4, 1); } break; } @@ -2441,27 +2441,27 @@ static void cmd_debug_reg(RCore *core, const char *str) { case 'c': // "drc" // todo: set flag values with drc zf=1 if (str[1] == '=') { - RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + RzRegFlags *rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { - r_cons_printf ("s:%d z:%d c:%d o:%d p:%d\n", + rz_cons_printf ("s:%d z:%d c:%d o:%d p:%d\n", rf->s, rf->z, rf->c, rf->o, rf->p); free (rf); } } else if (strchr (str, '=')) { - char *a = strdup (r_str_trim_head_ro (str + 1)); + char *a = strdup (rz_str_trim_head_ro (str + 1)); char *eq = strchr (a, '='); if (eq) { *eq++ = 0; char *k = a; - r_str_trim (a); + rz_str_trim (a); bool v = !strcmp (eq, "true") || atoi (eq); - int type = r_reg_cond_from_string (k); + int type = rz_reg_cond_from_string (k); if (type != -1) { - RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + RzRegFlags *rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { - r_reg_cond_bits_set (core->dbg->reg, type, rf, v); - r_reg_cond_apply (core->dbg->reg, rf); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); + rz_reg_cond_bits_set (core->dbg->reg, type, rf, v); + rz_reg_cond_apply (core->dbg->reg, rf); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); free (rf); } } else { @@ -2470,38 +2470,38 @@ static void cmd_debug_reg(RCore *core, const char *str) { } free (a); } else { - RRegItem *r; - const char *name = r_str_trim_head_ro (str + 1); + RzRegItem *r; + const char *name = rz_str_trim_head_ro (str + 1); if (*name && name[1]) { - r = r_reg_cond_get (core->dbg->reg, name); + r = rz_reg_cond_get (core->dbg->reg, name); if (r) { - r_cons_println (r->name); + rz_cons_println (r->name); } else { - int id = r_reg_cond_from_string (name); - RRegFlags* rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + int id = rz_reg_cond_from_string (name); + RzRegFlags* rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { - int o = r_reg_cond_bits (core->dbg->reg, id, rf); + int o = rz_reg_cond_bits (core->dbg->reg, id, rf); core->num->value = o; // orly? - r_cons_printf ("%d\n", o); + rz_cons_printf ("%d\n", o); free (rf); } else eprintf ("unknown conditional or flag register\n"); } } else { - RRegFlags *rf = r_reg_cond_retrieve (core->dbg->reg, NULL); + RzRegFlags *rf = rz_reg_cond_retrieve (core->dbg->reg, NULL); if (rf) { if (*name=='=') { for (i=0; idbg->reg, i, rf)); + rz_cons_printf ("%s:%d ", + rz_reg_cond_to_string (i), + rz_reg_cond_bits (core->dbg->reg, i, rf)); } - r_cons_newline (); + rz_cons_newline (); } else { for (i=0; idbg->reg, i, rf), - r_reg_cond_to_string (i)); + rz_cons_printf ("%d %s\n", + rz_reg_cond_bits (core->dbg->reg, i, rf), + rz_reg_cond_to_string (i)); } } free (rf); @@ -2512,13 +2512,13 @@ static void cmd_debug_reg(RCore *core, const char *str) { case 'x': // "drx" switch (str[1]) { case '\0': - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); - r_debug_drx_list (core->dbg); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_list (core->dbg); break; case '-': - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); - r_debug_drx_unset (core->dbg, atoi (str + 2)); - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_unset (core->dbg, atoi (str + 2)); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); break; case ' ': { char *s = strdup (str+2); @@ -2526,21 +2526,21 @@ static void cmd_debug_reg(RCore *core, const char *str) { int len; ut64 off; - sl = r_str_word_set0 (s); + sl = rz_str_word_set0 (s); if (sl == 4) { -#define arg(x) r_str_word_get0(s,x) - n = (char)r_num_math (core->num, arg(0)); - off = r_num_math (core->num, arg(1)); - len = (int)r_num_math (core->num, arg(2)); - perm = (char)r_str_rwx (arg (3)); +#define arg(x) rz_str_word_get0(s,x) + n = (char)rz_num_math (core->num, arg(0)); + off = rz_num_math (core->num, arg(1)); + len = (int)rz_num_math (core->num, arg(2)); + perm = (char)rz_str_rwx (arg (3)); if (len == -1) { - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); - r_debug_drx_set (core->dbg, n, 0, 0, 0, 0); - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_set (core->dbg, n, 0, 0, 0, 0); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); } else { - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); - r_debug_drx_set (core->dbg, n, off, len, perm, 0); - r_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_set (core->dbg, n, off, len, perm, 0); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_DRX, true); } } else { eprintf ("|usage: drx n [address] [length] [perm]\n"); @@ -2549,33 +2549,33 @@ static void cmd_debug_reg(RCore *core, const char *str) { } break; case '?': default: - r_core_cmd_help (core, help_msg_drx); + rz_core_cmd_help (core, help_msg_drx); break; } break; case 's': // "drs" switch (str[1]) { case '\0': // "drs" - r_cons_printf ("%d\n", r_list_length ( + rz_cons_printf ("%d\n", rz_list_length ( core->dbg->reg->regset[0].pool)); break; case '-': // "drs-" - r_reg_arena_pop (core->dbg->reg); + rz_reg_arena_pop (core->dbg->reg); // restore debug registers if in debugger mode - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); break; case '+': // "drs+" - r_reg_arena_push (core->dbg->reg); + rz_reg_arena_push (core->dbg->reg); break; case '?': // "drs?" default: - r_core_cmd_help (core, help_msg_drs); + rz_core_cmd_help (core, help_msg_drs); break; } break; case 'm': // "drm" if (str[1]=='?') { - r_core_cmd_help (core, help_msg_drm); + rz_core_cmd_help (core, help_msg_drm); } else if (str[1] == ' ' || str[1] == 'b' || str[1] == 'd' || str[1] == 'w' || str[1] == 'q' || str[1] == 'l' || str[1] == 'f' || (str[1] == 'y' && str[2] != '\x00')) { char explicit_index = 0; @@ -2586,7 +2586,7 @@ static void cmd_debug_reg(RCore *core, const char *str) { int size = 0; // auto char *q, *p, *name; char *eq = NULL; - RRegisterType reg_type = R_REG_TYPE_XMM; + RzRegisterType reg_type = R_REG_TYPE_XMM; if ((str[1] == ' ' && str[2] != '\x00') || (str[1] == 'y' && str[2] == ' ' && str[3] != '\x00')) { if (str[1] == 'y') { // support `drmy ymm0` and `drm ymm0` str = str + 1; @@ -2604,11 +2604,11 @@ static void cmd_debug_reg(RCore *core, const char *str) { if (p[0] != '*') { // do not show whole register explicit_index = 1; - index = r_num_math (core->num, p); + index = rz_num_math (core->num, p); } if (q) { *q++ = 0; - size = r_num_math (core->num, q); + size = rz_num_math (core->num, q); for (i = 0; i < NUM_PACK_TYPES; i++) { if (size == pack_sizes[i]) { explicit_size = 1; @@ -2662,25 +2662,25 @@ static void cmd_debug_reg(RCore *core, const char *str) { } } if (explicit_name) { - RRegItem *item = r_reg_get (core->dbg->reg, name, -1); + RzRegItem *item = rz_reg_get (core->dbg->reg, name, -1); if (item) { if (eq) { // TODO: support setting YMM registers if (reg_type == R_REG_TYPE_YMM) { eprintf ("Setting ymm registers not supported yet!\n"); } else { - ut64 val = r_num_math (core->num, eq); - r_reg_set_pack (core->dbg->reg, item, index, size, val); - r_debug_reg_sync (core->dbg, reg_type, true); + ut64 val = rz_num_math (core->num, eq); + rz_reg_set_pack (core->dbg->reg, item, index, size, val); + rz_debug_reg_sync (core->dbg, reg_type, true); } } else { - r_debug_reg_sync (core->dbg, reg_type, false); + rz_debug_reg_sync (core->dbg, reg_type, false); if (!explicit_index) { cmd_debug_reg_print_packed_reg (core, item, explicit_size, pack_show); } else { - ut64 res = r_reg_get_pack (core->dbg->reg, item, index, size); + ut64 res = rz_reg_get_pack (core->dbg->reg, item, index, size); // print selected index / wordsize - r_cons_printf ("0x%08" PFMT64x "\n", res); + rz_cons_printf ("0x%08" PFMT64x "\n", res); } } } else { @@ -2689,34 +2689,34 @@ static void cmd_debug_reg(RCore *core, const char *str) { free (name); } else { // explicit size no name - RListIter *iter; - RRegItem *item; - RList *head; - r_debug_reg_sync (core->dbg, reg_type, false); - head = r_reg_get_list (core->dbg->reg, reg_type); + RzListIter *iter; + RzRegItem *item; + RzList *head; + rz_debug_reg_sync (core->dbg, reg_type, false); + head = rz_reg_get_list (core->dbg->reg, reg_type); if (head) { - r_list_foreach (head, iter, item) { + rz_list_foreach (head, iter, item) { if (item->type != reg_type) { continue; } - r_cons_printf ("%-5s = ", item->name); + rz_cons_printf ("%-5s = ", item->name); cmd_debug_reg_print_packed_reg (core, item, explicit_size, pack_show); } } } } else { // drm # no arg if (str[1] == 'y') { // drmy - r_debug_reg_sync (core->dbg, R_REG_TYPE_YMM, false); - r_debug_reg_list (core->dbg, R_REG_TYPE_YMM, 256, 0, 0); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_YMM, false); + rz_debug_reg_list (core->dbg, R_REG_TYPE_YMM, 256, 0, 0); } else { // drm - r_debug_reg_sync (core->dbg, R_REG_TYPE_XMM, false); - r_debug_reg_list (core->dbg, R_REG_TYPE_XMM, 128, 0, 0); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_XMM, false); + rz_debug_reg_list (core->dbg, R_REG_TYPE_XMM, 128, 0, 0); } } - //r_debug_drx_list (core->dbg); + //rz_debug_drx_list (core->dbg); break; case 'f': // "drf" - //r_debug_drx_list (core->dbg); + //rz_debug_drx_list (core->dbg); if (str[1]=='?') { eprintf ("usage: drf [fpureg] [= value]\n"); } else if (str[1]==' ') { @@ -2729,7 +2729,7 @@ static void cmd_debug_reg(RCore *core, const char *str) { if (p) { *p++ = 0; } - RRegItem *item = r_reg_get (core->dbg->reg, name, -1); + RzRegItem *item = rz_reg_get (core->dbg->reg, name, -1); if (item) { if (eq) { long double val = 0.0f; @@ -2740,14 +2740,14 @@ static void cmd_debug_reg(RCore *core, const char *str) { #else sscanf (eq, "%Lf", &val); #endif - r_reg_set_double (core->dbg->reg, item, val); - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); - r_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, true); + rz_reg_set_double (core->dbg->reg, item, val); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, true); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, true); } else { - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - r_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, false); - long double res = r_reg_get_longdouble (core->dbg->reg, item); - r_cons_printf ("%Lf\n", res); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_FPU, false); + long double res = rz_reg_get_longdouble (core->dbg->reg, item); + rz_cons_printf ("%Lf\n", res); } } else { /* note, that negative type forces sync to print the regs from the backend */ @@ -2756,7 +2756,7 @@ static void cmd_debug_reg(RCore *core, const char *str) { free (name); } else { //TODO: Do not use this hack to print fpu register - r_debug_reg_sync (core->dbg, -R_REG_TYPE_FPU, false); + rz_debug_reg_sync (core->dbg, -R_REG_TYPE_FPU, false); } break; case 'p': // "drp" @@ -2766,8 +2766,8 @@ static void cmd_debug_reg(RCore *core, const char *str) { char rad = 0; switch (str[1]) { case '\0': // "drt" - for (i = 0; (name = r_reg_get_type (i)); i++) { - r_cons_println (name); + for (i = 0; (name = rz_reg_get_type (i)); i++) { + rz_cons_println (name); } break; case 'j': // "drtj" @@ -2780,19 +2780,19 @@ static void cmd_debug_reg(RCore *core, const char *str) { break; } pj_a (pj); - for (i = 0; (name = r_reg_get_type (i)); i++) { + for (i = 0; (name = rz_reg_get_type (i)); i++) { pj_s (pj, name); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); break; } // fallthrough case ' ': // "drt " { - int role = r_reg_get_name_idx (str+2); - const char *regname = r_reg_get_name (core->dbg->reg, role); + int role = rz_reg_get_name_idx (str+2); + const char *regname = rz_reg_get_name (core->dbg->reg, role); if (!regname) { regname = str + 2; } @@ -2804,13 +2804,13 @@ static void cmd_debug_reg(RCore *core, const char *str) { *arg++ = 0; size = atoi (arg); } - type = r_reg_type_by_name (str + 2); - r_debug_reg_sync (core->dbg, type, false); - r_debug_reg_list (core->dbg, type, size, rad, use_color); + type = rz_reg_type_by_name (str + 2); + rz_debug_reg_sync (core->dbg, type, false); + rz_debug_reg_list (core->dbg, type, size, rad, use_color); } else { if (type != R_REG_TYPE_LAST) { - r_debug_reg_sync (core->dbg, type, false); - r_debug_reg_list (core->dbg, type, size, rad, use_color); + rz_debug_reg_sync (core->dbg, type, false); + rz_debug_reg_list (core->dbg, type, size, rad, use_color); } else { eprintf ("cmd_debug_reg: unknown type\n"); } @@ -2819,7 +2819,7 @@ static void cmd_debug_reg(RCore *core, const char *str) { } case '?': // "drt?" default: - r_core_cmd_help (core, help_msg_drt); + rz_core_cmd_help (core, help_msg_drt); break; } } @@ -2827,24 +2827,24 @@ static void cmd_debug_reg(RCore *core, const char *str) { case 'n': // "drn" { char *foo = strdup (str+2); - r_str_case (foo, true); - name = r_reg_get_name (core->dbg->reg, r_reg_get_name_idx (foo)); + rz_str_case (foo, true); + name = rz_reg_get_name (core->dbg->reg, rz_reg_get_name_idx (foo)); if (name && *name) { - r_cons_println (name); + rz_cons_println (name); } else eprintf ("oops. try drn [pc|sp|bp|a0|a1|a2|a3|a4|r0|r1|zf|sf|nf|of]\n"); free (foo); } break; case 'd': // "drd" - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 3, use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 3, use_color); // xxx detect which one is current usage break; case 'o': // "dro" - r_reg_arena_swap (core->dbg->reg, false); - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 0, use_color); // xxx detect which one is current usage - r_reg_arena_swap (core->dbg->reg, false); + rz_reg_arena_swap (core->dbg->reg, false); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, 0, use_color); // xxx detect which one is current usage + rz_reg_arena_swap (core->dbg->reg, false); break; case ',': // "dr," - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { __tableRegList (core, core->dbg->reg, str + 1); } else { eprintf ("cannot retrieve registers from pid %d\n", core->dbg->pid); @@ -2853,72 +2853,72 @@ static void cmd_debug_reg(RCore *core, const char *str) { case '=': // "dr=" { int pcbits2, pcbits = grab_bits (core, str + 1, &pcbits2); - if (r_config_get_i (core->config, "cfg.debug")) { - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + if (rz_config_get_i (core->config, "cfg.debug")) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { if (pcbits && pcbits != bits) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); // xxx detect which one is current usage } - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color); // xxx detect which one is current usage if (pcbits2) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, str[0], use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, str[0], use_color); // xxx detect which one is current usage } } //else eprintf ("cannot retrieve registers from pid %d\n", core->dbg->pid); } else { - RReg *orig = core->dbg->reg; + RzReg *orig = core->dbg->reg; core->dbg->reg = core->anal->reg; if (pcbits && pcbits != bits) - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); // xxx detect which one is current usage - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); // xxx detect which one is current usage + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, bits, str[0], use_color); // xxx detect which one is current usage core->dbg->reg = orig; } } break; case '.': - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { int pcbits2, pcbits = grab_bits (core, str + 1, &pcbits2); - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, '.', use_color); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, '.', use_color); if (pcbits2) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, '.', use_color); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, '.', use_color); } } break; case '*': // "dr*" - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { int pcbits2, pcbits = grab_bits (core, str + 1, &pcbits2); - r_cons_printf ("fs+regs\n"); - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, '*', use_color); + rz_cons_printf ("fs+regs\n"); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, '*', use_color); if (pcbits2) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, '*', use_color); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits2, '*', use_color); } - r_flag_space_pop (core->flags); - r_cons_printf ("fs-\n"); + rz_flag_space_pop (core->flags); + rz_cons_printf ("fs-\n"); } break; case 'i': // "dri" - r_core_debug_ri (core, core->dbg->reg, 0); + rz_core_debug_ri (core, core->dbg->reg, 0); break; case 'r': // "drr" switch (str[1]) { case 'j': // "drrj" - r_core_debug_rr (core, core->dbg->reg, 'j'); + rz_core_debug_rr (core, core->dbg->reg, 'j'); break; default: - r_core_debug_rr (core, core->dbg->reg, 0); + rz_core_debug_rr (core, core->dbg->reg, 0); break; } break; case 'j': // "drj" case '\0': // "dr" - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { int pcbits = core->anal->bits; - const char *pcname = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - RRegItem *reg = r_reg_get (core->anal->reg, pcname, 0); + const char *pcname = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + RzRegItem *reg = rz_reg_get (core->anal->reg, pcname, 0); if (reg) { if (core->rasm->bits != reg->size) { pcbits = reg->size; } } - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, pcbits, str[0], use_color); } else { eprintf ("cannot retrieve registers from pid %d\n", core->dbg->pid); } @@ -2927,48 +2927,48 @@ static void cmd_debug_reg(RCore *core, const char *str) { arg = strchr (str + 1, '='); if (arg) { *arg = 0; - char *string = r_str_trim_dup (str + 1); - const char *regname = r_reg_get_name (core->dbg->reg, r_reg_get_name_idx (string)); + char *string = rz_str_trim_dup (str + 1); + const char *regname = rz_reg_get_name (core->dbg->reg, rz_reg_get_name_idx (string)); if (!regname) { regname = string; } - r = r_reg_get (core->dbg->reg, regname, -1); //R_REG_TYPE_GPR); + r = rz_reg_get (core->dbg->reg, regname, -1); //R_REG_TYPE_GPR); if (r) { if (r->flags) { - r_cons_printf ("0x%08"PFMT64x" ->", - r_reg_get_value (core->dbg->reg, r)); - r_reg_set_bvalue (core->dbg->reg, r, arg+1); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); - r_cons_printf ("0x%08"PFMT64x"\n", - r_reg_get_value (core->dbg->reg, r)); + rz_cons_printf ("0x%08"PFMT64x" ->", + rz_reg_get_value (core->dbg->reg, r)); + rz_reg_set_bvalue (core->dbg->reg, r, arg+1); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); + rz_cons_printf ("0x%08"PFMT64x"\n", + rz_reg_get_value (core->dbg->reg, r)); } else { - r_cons_printf ("0x%08"PFMT64x" ->", - r_reg_get_value (core->dbg->reg, r)); - r_reg_set_value (core->dbg->reg, r, - r_num_math (core->num, arg+1)); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); - r_cons_printf ("0x%08"PFMT64x"\n", - r_reg_get_value (core->dbg->reg, r)); + rz_cons_printf ("0x%08"PFMT64x" ->", + rz_reg_get_value (core->dbg->reg, r)); + rz_reg_set_value (core->dbg->reg, r, + rz_num_math (core->num, arg+1)); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); + rz_cons_printf ("0x%08"PFMT64x"\n", + rz_reg_get_value (core->dbg->reg, r)); } } else { eprintf ("unknown register '%s'\n", string); } free (string); // update flags here - r_core_cmdf (core, ".dr*%d", bits); + rz_core_cmdf (core, ".dr*%d", bits); return; } size = atoi (str + 1); if (size) { - r_debug_reg_list (core->dbg, R_REG_TYPE_GPR, size, str[0], use_color); + rz_debug_reg_list (core->dbg, R_REG_TYPE_GPR, size, str[0], use_color); } else { char *comma = strchr (str + 1, ','); if (comma) { char *args = strdup (str + 1); - char argc = r_str_split (args, ','); + char argc = rz_str_split (args, ','); for (i = 0; i < argc; i++) { - showreg (core, r_str_word_get0 (args, i)); + showreg (core, rz_str_word_get0 (args, i)); } free (args); } else { @@ -2978,30 +2978,30 @@ static void cmd_debug_reg(RCore *core, const char *str) { } } -static void backtrace_vars(RCore *core, RList *frames) { - RDebugFrame *f; - RListIter *iter; +static void backtrace_vars(RzCore *core, RzList *frames) { + RzDebugFrame *f; + RzListIter *iter; // anal vs debug ? - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP); + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + const char *bp = rz_reg_get_name (core->anal->reg, R_REG_NAME_BP); if (!sp) { sp = "SP"; } if (!bp) { bp = "BP"; } - RReg *r = core->anal->reg; - ut64 dsp = r_reg_getv (r, sp); - ut64 dbp = r_reg_getv (r, bp); + RzReg *r = core->anal->reg; + ut64 dsp = rz_reg_getv (r, sp); + ut64 dbp = rz_reg_getv (r, bp); int n = 0; - r_list_foreach (frames, iter, f) { + rz_list_foreach (frames, iter, f) { ut64 s = f->sp ? f->sp : dsp; ut64 b = f->bp ? f->bp : dbp; - r_reg_setv (r, bp, s); - r_reg_setv (r, sp, b); + rz_reg_setv (r, bp, s); + rz_reg_setv (r, sp, b); ////////// char flagdesc[1024], flagdesc2[1024]; - RFlagItem *fi = r_flag_get_at (core->flags, f->addr, true); + RzFlagItem *fi = rz_flag_get_at (core->flags, f->addr, true); flagdesc[0] = flagdesc2[0] = 0; if (fi) { if (fi->offset != f->addr) { @@ -3022,195 +3022,195 @@ static void backtrace_vars(RCore *core, RList *frames) { } } ////////// - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, f->addr, 0); - // char *str = r_str_newf ("[frame %d]", n); - r_cons_printf ("%d 0x%08"PFMT64x" sp: 0x%08"PFMT64x" %-5d" + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, f->addr, 0); + // char *str = rz_str_newf ("[frame %d]", n); + rz_cons_printf ("%d 0x%08"PFMT64x" sp: 0x%08"PFMT64x" %-5d" "[%s] %s %s\n", n, f->addr, f->sp, (int)f->size, fcn ? fcn->name : "??", flagdesc, flagdesc2); eprintf ("afvd @ 0x%"PFMT64x"\n", f->addr); - r_cons_push(); - char *res = r_core_cmd_strf (core, "afvd@0x%"PFMT64x, f->addr); - r_cons_pop(); - r_cons_printf ("%s", res); + rz_cons_push(); + char *res = rz_core_cmd_strf (core, "afvd@0x%"PFMT64x, f->addr); + rz_cons_pop(); + rz_cons_printf ("%s", res); free (res); n++; } - r_reg_setv (r, bp, dbp); - r_reg_setv (r, sp, dsp); + rz_reg_setv (r, bp, dbp); + rz_reg_setv (r, sp, dsp); } -static void asciiart_backtrace(RCore *core, RList *frames) { +static void asciiart_backtrace(RzCore *core, RzList *frames) { // TODO: show local variables // TODO: show function/flags/symbols related // TODO: show contents of stack // TODO: honor scr.color - RDebugFrame *f; - RListIter *iter; + RzDebugFrame *f; + RzListIter *iter; bool mymap = false; // anal vs debug ? - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - const char *bp = r_reg_get_name (core->anal->reg, R_REG_NAME_BP); + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + const char *bp = rz_reg_get_name (core->anal->reg, R_REG_NAME_BP); if (!sp) { sp = "SP"; } if (!bp) { bp = "BP"; } - ut64 dsp = r_reg_getv (core->anal->reg, sp); - ut64 dbp = r_reg_getv (core->anal->reg, bp); - RDebugMap *map = r_debug_map_get (core->dbg, dsp); + ut64 dsp = rz_reg_getv (core->anal->reg, sp); + ut64 dbp = rz_reg_getv (core->anal->reg, bp); + RzDebugMap *map = rz_debug_map_get (core->dbg, dsp); if (!map) { mymap = true; - map = R_NEW0 (RDebugMap); + map = R_NEW0 (RzDebugMap); map->addr = UT64_MAX; map->addr_end = UT64_MAX; } - r_cons_printf ("0x%016"PFMT64x" STACK END ^^^\n", map->addr); - r_cons_printf ("0x%016"PFMT64x" STACK POINTER: %s\n", dsp, sp); - r_cons_printf (" .------------------------.\n"); + rz_cons_printf ("0x%016"PFMT64x" STACK END ^^^\n", map->addr); + rz_cons_printf ("0x%016"PFMT64x" STACK POINTER: %s\n", dsp, sp); + rz_cons_printf (" .------------------------.\n"); int n = 0; - r_list_foreach (frames, iter, f) { + rz_list_foreach (frames, iter, f) { ut64 s = f->sp ? f->sp : dsp; ut64 b = f->bp ? f->bp : dbp; - char *str = r_str_newf ("[frame %d]", n); - r_cons_printf ("0x%016"PFMT64x" |%4s %10s | ; size %d\n", s, sp, str, s - b); + char *str = rz_str_newf ("[frame %d]", n); + rz_cons_printf ("0x%016"PFMT64x" |%4s %10s | ; size %d\n", s, sp, str, s - b); free (str); - r_cons_printf (" | ... |\n"); - r_cons_printf ("0x%016"PFMT64x" |%4s 0x%016"PFMT64x" | %s\n", b, bp, f->addr, "; return address"); - r_cons_printf (" )------------------------(\n"); + rz_cons_printf (" | ... |\n"); + rz_cons_printf ("0x%016"PFMT64x" |%4s 0x%016"PFMT64x" | %s\n", b, bp, f->addr, "; return address"); + rz_cons_printf (" )------------------------(\n"); // eprintf ("0x%08llx 0x%08llx 0x%08llx\n", f->addr, s, b); n++; } - r_cons_printf (" | ... |\n"); - r_cons_printf (" `------------------------'\n"); - r_cons_printf ("0x%016"PFMT64x" STACK BOTTOM\n", map->addr_end); + rz_cons_printf (" | ... |\n"); + rz_cons_printf (" `------------------------'\n"); + rz_cons_printf ("0x%016"PFMT64x" STACK BOTTOM\n", map->addr_end); if (mymap) { - r_debug_map_free (map); + rz_debug_map_free (map); } } -static void get_backtrace_info(RCore* core, RDebugFrame* frame, ut64 addr, char** flagdesc, char** flagdesc2, char** pcstr, char** spstr, bool hex_format) { - RFlagItem *f = r_flag_get_at (core->flags, frame->addr, true); +static void get_backtrace_info(RzCore* core, RzDebugFrame* frame, ut64 addr, char** flagdesc, char** flagdesc2, char** pcstr, char** spstr, bool hex_format) { + RzFlagItem *f = rz_flag_get_at (core->flags, frame->addr, true); *flagdesc = NULL; *flagdesc2 = NULL; if (f) { if (f->offset != addr) { int delta = (int)(frame->addr - f->offset); if (delta > 0) { - *flagdesc = r_str_newf ("%s+%d", f->name, delta); + *flagdesc = rz_str_newf ("%s+%d", f->name, delta); } else if (delta < 0) { - *flagdesc = r_str_newf ("%s%d", f->name, delta); + *flagdesc = rz_str_newf ("%s%d", f->name, delta); } else { - *flagdesc = r_str_newf ("%s", f->name); + *flagdesc = rz_str_newf ("%s", f->name); } } else { - *flagdesc = r_str_newf ("%s", f->name); + *flagdesc = rz_str_newf ("%s", f->name); } } - f = r_flag_get_at (core->flags, frame->addr, true); + f = rz_flag_get_at (core->flags, frame->addr, true); if (f && !strchr (f->name, '.')) { - f = r_flag_get_at (core->flags, frame->addr - 1, true); + f = rz_flag_get_at (core->flags, frame->addr - 1, true); } if (f) { if (f->offset != addr) { int delta = (int)(frame->addr - 1 - f->offset); if (delta > 0) { - *flagdesc2 = r_str_newf ("%s+%d", f->name, delta + 1); + *flagdesc2 = rz_str_newf ("%s+%d", f->name, delta + 1); } else if (delta < 0) { - *flagdesc2 = r_str_newf ("%s%d", f->name, delta + 1); + *flagdesc2 = rz_str_newf ("%s%d", f->name, delta + 1); } else { - *flagdesc2 = r_str_newf ("%s+1", f->name); + *flagdesc2 = rz_str_newf ("%s+1", f->name); } } else { - *flagdesc2 = r_str_newf ("%s", f->name); + *flagdesc2 = rz_str_newf ("%s", f->name); } } - if (!r_str_cmp (*flagdesc, *flagdesc2, -1)) { + if (!rz_str_cmp (*flagdesc, *flagdesc2, -1)) { free (*flagdesc2); *flagdesc2 = NULL; } if (hex_format) { if (core->dbg->bits & R_SYS_BITS_64) { - *pcstr = r_str_newf ("0x%-16" PFMT64x, frame->addr); - *spstr = r_str_newf ("0x%-16" PFMT64x, frame->sp); + *pcstr = rz_str_newf ("0x%-16" PFMT64x, frame->addr); + *spstr = rz_str_newf ("0x%-16" PFMT64x, frame->sp); } else if (core->dbg->bits & R_SYS_BITS_32) { - *pcstr = r_str_newf ("0x%-8" PFMT64x, frame->addr); - *spstr = r_str_newf ("0x%-8" PFMT64x, frame->sp); + *pcstr = rz_str_newf ("0x%-8" PFMT64x, frame->addr); + *spstr = rz_str_newf ("0x%-8" PFMT64x, frame->sp); } else { - *pcstr = r_str_newf ("0x%" PFMT64x, frame->addr); - *spstr = r_str_newf ("0x%" PFMT64x, frame->sp); + *pcstr = rz_str_newf ("0x%" PFMT64x, frame->addr); + *spstr = rz_str_newf ("0x%" PFMT64x, frame->sp); } } else { if (core->dbg->bits & R_SYS_BITS_64) { - *pcstr = r_str_newf ("%" PFMT64d, frame->addr); - *spstr = r_str_newf ("%" PFMT64d, frame->sp); + *pcstr = rz_str_newf ("%" PFMT64d, frame->addr); + *spstr = rz_str_newf ("%" PFMT64d, frame->sp); } else if (core->dbg->bits & R_SYS_BITS_32) { - *pcstr = r_str_newf ("%" PFMT64d, frame->addr); - *spstr = r_str_newf ("%" PFMT64d, frame->sp); + *pcstr = rz_str_newf ("%" PFMT64d, frame->addr); + *spstr = rz_str_newf ("%" PFMT64d, frame->sp); } else { - *pcstr = r_str_newf ("%" PFMT64d, frame->addr); - *spstr = r_str_newf ("%" PFMT64d, frame->sp); + *pcstr = rz_str_newf ("%" PFMT64d, frame->addr); + *spstr = rz_str_newf ("%" PFMT64d, frame->sp); } } } static void static_debug_stop(void *u) { - RDebug *dbg = (RDebug *)u; - r_debug_stop (dbg); + RzDebug *dbg = (RzDebug *)u; + rz_debug_stop (dbg); } -static void core_cmd_dbi(RCore *core, const char *input, const ut64 idx) { +static void core_cmd_dbi(RzCore *core, const char *input, const ut64 idx) { int i; char *p; RBreakpointItem *bpi; switch (input[2]) { case ' ': // "dbi." { - const int index = r_bp_get_index_at (core->dbg->bp, idx); + const int index = rz_bp_get_index_at (core->dbg->bp, idx); if (index != -1) { - r_cons_printf ("%d\n", index); + rz_cons_printf ("%d\n", index); } } break; case '-': // "dbi-" { - if (!r_bp_del_index (core->dbg->bp, idx)) { + if (!rz_bp_del_index (core->dbg->bp, idx)) { eprintf ("Breakpoint with index %d not found\n", (int)idx); } } break; case '.': // "dbi." { - const int index = r_bp_get_index_at (core->dbg->bp, core->offset); + const int index = rz_bp_get_index_at (core->dbg->bp, core->offset); if (index != -1) { - r_cons_printf ("%d\n", index); + rz_cons_printf ("%d\n", index); } } break; case 0: // "dbi" for (i = 0; i < core->dbg->bp->bps_idx_count; i++) { if ((bpi = core->dbg->bp->bps_idx[i])) { - r_cons_printf ("%d 0x%08"PFMT64x" E:%d T:%d\n", + rz_cons_printf ("%d 0x%08"PFMT64x" E:%d T:%d\n", i, bpi->addr, bpi->enabled, bpi->trace); } } break; case 'x': // "dbix" if (input[3] == ' ') { - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { char *expr = strchr (input + 4, ' '); if (expr) { free (bpi->expr); bpi->expr = strdup (expr); } } - r_cons_printf ("%d\n", (int)idx); + rz_cons_printf ("%d\n", (int)idx); } else { for (i = 0; i < core->dbg->bp->bps_idx_count; i++) { RBreakpointItem *bp = core->dbg->bp->bps_idx[i]; if (bp) { - r_cons_printf ("%d 0x%08"PFMT64x" %s\n", i, bp->addr, bp->expr); + rz_cons_printf ("%d 0x%08"PFMT64x" %s\n", i, bp->addr, bp->expr); } } } @@ -3221,8 +3221,8 @@ static void core_cmd_dbi(RCore *core, const char *input, const ut64 idx) { char *q = strchr (p + 1, ' '); if (q) { *q++ = 0; - ut64 addr = r_num_math (core->num, p); - bpi = r_bp_get_index (core->dbg->bp, addr); + ut64 addr = rz_num_math (core->num, p); + bpi = rz_bp_get_index (core->dbg->bp, addr); if (bpi) { bpi->data = strdup (q); } else { @@ -3236,21 +3236,21 @@ static void core_cmd_dbi(RCore *core, const char *input, const ut64 idx) { } break; case 'e': // "dbie" - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->enabled = true; } else { eprintf ("Cannot unset tracepoint\n"); } break; case 'd': // "dbid" - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->enabled = false; } else { eprintf ("Cannot unset tracepoint\n"); } break; case 's': // "dbis" - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->enabled = !!!bpi->enabled; } else { eprintf ("Cannot unset tracepoint\n"); @@ -3259,19 +3259,19 @@ static void core_cmd_dbi(RCore *core, const char *input, const ut64 idx) { case 't': // "dbite" "dbitd" ... switch (input[3]) { case 'e': - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->trace = true; } else { eprintf ("Cannot unset tracepoint\n"); } break; case 'd': - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->trace = false; } else eprintf ("Cannot unset tracepoint\n"); break; case 's': - if ((bpi = r_bp_get_index (core->dbg->bp, idx))) { + if ((bpi = rz_bp_get_index (core->dbg->bp, idx))) { bpi->trace = !!!bpi->trace; } else { eprintf ("Cannot unset tracepoint\n"); @@ -3286,18 +3286,18 @@ static void core_cmd_dbi(RCore *core, const char *input, const ut64 idx) { #include "..\debug\p\native\windows\windows_message.h" #endif -#define DB_ARG(x) r_str_word_get0(str, x) -static void add_breakpoint(RCore *core, const char *input, bool hwbp, bool watch) { +#define DB_ARG(x) rz_str_word_get0(str, x) +static void add_breakpoint(RzCore *core, const char *input, bool hwbp, bool watch) { RBreakpointItem *bpi; ut64 addr; int i = 0; - char *str = strdup (r_str_trim_head_ro (input + 1)); - int sl = r_str_word_set0 (str); + char *str = strdup (rz_str_trim_head_ro (input + 1)); + int sl = rz_str_word_set0 (str); // For dbw every second argument is 'rw', so we need to skip it. for (; i < sl; i += 1 + (watch ? 1 : 0)) { if (*DB_ARG (i) == '-') { - r_bp_del (core->dbg->bp, r_num_math (core->num, DB_ARG (i) + 1)); + rz_bp_del (core->dbg->bp, rz_num_math (core->num, DB_ARG (i) + 1)); } else { int rw = 0; if (watch) { @@ -3309,28 +3309,28 @@ static void add_breakpoint(RCore *core, const char *input, bool hwbp, bool watch } else if (!strcmp (DB_ARG (i + 1), "rw")) { rw = R_BP_PROT_ACCESS; } else { - r_core_cmd_help (core, help_msg_dbw); + rz_core_cmd_help (core, help_msg_dbw); break; } } else { - r_core_cmd_help (core, help_msg_dbw); + rz_core_cmd_help (core, help_msg_dbw); break; } } - addr = r_num_math (core->num, DB_ARG (i)); - bpi = r_debug_bp_add (core->dbg, addr, hwbp, watch, rw, NULL, 0); + addr = rz_num_math (core->num, DB_ARG (i)); + bpi = rz_debug_bp_add (core->dbg, addr, hwbp, watch, rw, NULL, 0); if (bpi) { free (bpi->name); if (!strcmp (DB_ARG (i), "$$")) { - RFlagItem *f = r_core_flag_get_by_spaces (core->flags, addr); + RzFlagItem *f = rz_core_flag_get_by_spaces (core->flags, addr); if (f) { if (addr > f->offset) { - bpi->name = r_str_newf ("%s+0x%" PFMT64x, f->name, addr - f->offset); + bpi->name = rz_str_newf ("%s+0x%" PFMT64x, f->name, addr - f->offset); } else { bpi->name = strdup (f->name); } } else { - bpi->name = r_str_newf ("0x%08" PFMT64x, addr); + bpi->name = rz_str_newf ("0x%08" PFMT64x, addr); } } else { bpi->name = strdup (DB_ARG (i)); @@ -3344,18 +3344,18 @@ static void add_breakpoint(RCore *core, const char *input, bool hwbp, bool watch free (str); } -static void r_core_cmd_bp(RCore *core, const char *input) { +static void rz_core_cmd_bp(RzCore *core, const char *input) { RBreakpointItem *bpi; - int i, hwbp = r_config_get_i (core->config, "dbg.hwbp"); - RDebugFrame *frame; - RListIter *iter; + int i, hwbp = rz_config_get_i (core->config, "dbg.hwbp"); + RzDebugFrame *frame; + RzListIter *iter; const char *p; bool hex_format; bool watch = false; - RList *list; + RzList *list; ut64 addr, idx; p = strchr (input, ' '); - addr = p? r_num_math (core->num, p + 1): UT64_MAX; + addr = p? rz_num_math (core->num, p + 1): UT64_MAX; idx = addr; // 0 is valid index if (!addr) { addr = UT64_MAX; @@ -3365,16 +3365,16 @@ static void r_core_cmd_bp(RCore *core, const char *input) { switch (input[1]) { case '.': if (input[2]) { - ut64 addr = r_num_tail (core->num, core->offset, input + 2); - bpi = r_debug_bp_add (core->dbg, addr, hwbp, false, 0, NULL, 0); + ut64 addr = rz_num_tail (core->num, core->offset, input + 2); + bpi = rz_debug_bp_add (core->dbg, addr, hwbp, false, 0, NULL, 0); if (!bpi) { eprintf ("Unable to add breakpoint (%s)\n", input + 2); } } else { - bpi = r_bp_get_at (core->dbg->bp, core->offset); + bpi = rz_bp_get_at (core->dbg->bp, core->offset); if (bpi) { - r_cons_printf ("breakpoint %s %s %s\n", - r_str_rwx_i (bpi->perm), + rz_cons_printf ("breakpoint %s %s %s\n", + rz_str_rwx_i (bpi->perm), bpi->enabled ? "enabled" : "disabled", bpi->name ? bpi->name : ""); } @@ -3382,14 +3382,14 @@ static void r_core_cmd_bp(RCore *core, const char *input) { break; case 'f': { - RList *symbols = r_bin_get_symbols (core->bin); + RzList *symbols = rz_bin_get_symbols (core->bin); RBinSymbol *symbol; - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (symbol->type && !strcmp (symbol->type, R_BIN_TYPE_FUNC_STR)) { - if (r_anal_noreturn_at (core->anal, symbol->vaddr)) { - bpi = r_debug_bp_add (core->dbg, symbol->vaddr, hwbp, false, 0, NULL, 0); + if (rz_anal_noreturn_at (core->anal, symbol->vaddr)) { + bpi = rz_debug_bp_add (core->dbg, symbol->vaddr, hwbp, false, 0, NULL, 0); if (bpi) { - bpi->name = r_str_newf ("%s.%s", "sym", symbol->name); + bpi->name = rz_str_newf ("%s.%s", "sym", symbol->name); } else { eprintf ("Unable to add a breakpoint" "into a noreturn function %s at addr 0x%"PFMT64x"\n", @@ -3405,37 +3405,37 @@ static void r_core_cmd_bp(RCore *core, const char *input) { if (addr == UT64_MAX) { addr = core->offset; } - bpi = r_bp_get_at (core->dbg->bp, addr); + bpi = rz_bp_get_at (core->dbg->bp, addr); if (bpi) { free (bpi->expr); bpi->expr = strdup (input + 3); } } else { RBreakpointItem *bp; - r_list_foreach (core->dbg->bp->bps, iter, bp) { - r_cons_printf ("0x%08"PFMT64x" %s\n", bp->addr, r_str_get2 (bp->expr)); + rz_list_foreach (core->dbg->bp->bps, iter, bp) { + rz_cons_printf ("0x%08"PFMT64x" %s\n", bp->addr, rz_str_get2 (bp->expr)); } } break; case 't': // "dbt" switch (input[2]) { case 'v': // "dbtv" - list = r_debug_frames (core->dbg, addr); + list = rz_debug_frames (core->dbg, addr); backtrace_vars (core, list); - r_list_free (list); + rz_list_free (list); break; case 'a': // "dbta" - list = r_debug_frames (core->dbg, addr); + list = rz_debug_frames (core->dbg, addr); asciiart_backtrace (core, list); - r_list_free (list); + rz_list_free (list); break; case 'e': // "dbte" for (p = input + 3; *p == ' '; p++) { /* nothing to do here */ } if (*p == '*') { - r_bp_set_trace_all (core->dbg->bp,true); - } else if (!r_bp_set_trace (core->dbg->bp, addr, true)) { + rz_bp_set_trace_all (core->dbg->bp,true); + } else if (!rz_bp_set_trace (core->dbg->bp, addr, true)) { eprintf ("Cannot set tracepoint\n"); } break; @@ -3444,13 +3444,13 @@ static void r_core_cmd_bp(RCore *core, const char *input) { //nothing to see here } if (*p == '*') { - r_bp_set_trace_all (core->dbg->bp, false); - } else if (!r_bp_set_trace (core->dbg->bp, addr, false)) { + rz_bp_set_trace_all (core->dbg->bp, false); + } else if (!rz_bp_set_trace (core->dbg->bp, addr, false)) { eprintf ("Cannot unset tracepoint\n"); } break; case 's': // "dbts" - bpi = r_bp_get_at (core->dbg->bp, addr); + bpi = rz_bp_get_at (core->dbg->bp, addr); if (bpi) { bpi->trace = !!!bpi->trace; } else { @@ -3460,17 +3460,17 @@ static void r_core_cmd_bp(RCore *core, const char *input) { case 'j': // "dbtj" addr = UT64_MAX; if (input[2] == ' ' && input[3]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } i = 0; - list = r_debug_frames (core->dbg, addr); + list = rz_debug_frames (core->dbg, addr); hex_format = false; - r_cons_printf ("["); - r_list_foreach (list, iter, frame) { + rz_cons_printf ("["); + rz_list_foreach (list, iter, frame) { char *flagdesc, *flagdesc2, *pcstr, *spstr; get_backtrace_info (core, frame, addr, &flagdesc, &flagdesc2, &pcstr, &spstr, hex_format); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, frame->addr, 0); - r_cons_printf ("%s{\"idx\":%d,\"pc\":%s,\"sp\":%s,\"frame_size\":%d," + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, frame->addr, 0); + rz_cons_printf ("%s{\"idx\":%d,\"pc\":%s,\"sp\":%s,\"frame_size\":%d," "\"fname\":\"%s\",\"desc\":\"%s%s\"}", (i ? " ," : ""), i, pcstr, spstr, @@ -3484,70 +3484,70 @@ static void r_core_cmd_bp(RCore *core, const char *input) { free (pcstr); free (spstr); } - r_cons_printf ("]\n"); - r_list_free (list); + rz_cons_printf ("]\n"); + rz_list_free (list); break; case '=': // dbt= addr = UT64_MAX; if (input[2] == ' ' && input[3]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } i = 0; - list = r_debug_frames (core->dbg, addr); - r_list_reverse (list); - r_list_foreach (list, iter, frame) { + list = rz_debug_frames (core->dbg, addr); + rz_list_reverse (list); + rz_list_foreach (list, iter, frame) { switch (input[3]) { case 0: - r_cons_printf ("%s0x%08"PFMT64x, + rz_cons_printf ("%s0x%08"PFMT64x, (i ? " " : ""), frame->addr); break; case 's': - r_cons_printf ("%s0x%08"PFMT64x, + rz_cons_printf ("%s0x%08"PFMT64x, (i ? " " : ""), frame->sp); break; case 'b': - r_cons_printf ("%s0x%08"PFMT64x, + rz_cons_printf ("%s0x%08"PFMT64x, (i ? " " : ""), frame->bp); break; case '?': default: - r_core_cmd0 (core, "db?~dbt"); + rz_core_cmd0 (core, "db?~dbt"); break; } i++; } - r_cons_newline (); - r_list_free (list); + rz_cons_newline (); + rz_list_free (list); break; case '*': // dbt* addr = UT64_MAX; if (input[2] == ' ' && input[3]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } i = 0; - list = r_debug_frames (core->dbg, addr); - r_list_reverse (list); - r_cons_printf ("f-bt.*\n"); - r_list_foreach (list, iter, frame) { - r_cons_printf ("f bt.frame%d = 0x%08"PFMT64x"\n", i, frame->addr); - r_cons_printf ("f bt.frame%d.stack %d 0x%08"PFMT64x"\n", i, frame->size, frame->sp); + list = rz_debug_frames (core->dbg, addr); + rz_list_reverse (list); + rz_cons_printf ("f-bt.*\n"); + rz_list_foreach (list, iter, frame) { + rz_cons_printf ("f bt.frame%d = 0x%08"PFMT64x"\n", i, frame->addr); + rz_cons_printf ("f bt.frame%d.stack %d 0x%08"PFMT64x"\n", i, frame->size, frame->sp); i++; } - r_list_free (list); + rz_list_free (list); break; case 0: // "dbt" -- backtrace addr = UT64_MAX; if (input[2] == ' ' && input[3]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } i = 0; - list = r_debug_frames (core->dbg, addr); + list = rz_debug_frames (core->dbg, addr); hex_format = true; - r_list_foreach (list, iter, frame) { + rz_list_foreach (list, iter, frame) { char *flagdesc, *flagdesc2, *pcstr, *spstr; get_backtrace_info (core, frame, addr, &flagdesc, &flagdesc2, &pcstr, &spstr, hex_format); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, frame->addr, 0); - r_cons_printf ("%d %s sp: %s %-5d" + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, frame->addr, 0); + rz_cons_printf ("%d %s sp: %s %-5d" "[%s] %s %s\n", i++, pcstr, spstr, (int)frame->size, @@ -3559,19 +3559,19 @@ static void r_core_cmd_bp(RCore *core, const char *input) { free (pcstr); free (spstr); } - r_list_free (list); + rz_list_free (list); break; case '?': default: - r_core_cmd_help (core, help_msg_dbt); + rz_core_cmd_help (core, help_msg_dbt); break; } break; case 'b': // "dbb" if (input[2]) { - core->dbg->bp->delta = (st64)r_num_math (core->num, input + 2); + core->dbg->bp->delta = (st64)rz_num_math (core->num, input + 2); } else { - r_cons_printf ("%"PFMT64d"\n", core->dbg->bp->delta); + rz_cons_printf ("%"PFMT64d"\n", core->dbg->bp->delta); } break; case 'm': // "dbm" @@ -3581,28 +3581,28 @@ static void r_core_cmd_bp(RCore *core, const char *input) { st64 delta = 0; module = strtok (string, " "); - delta = (ut64)r_num_math (core->num, strtok (NULL, "")); - bpi = r_debug_bp_add (core->dbg, 0, hwbp, false, 0, module, delta); + delta = (ut64)rz_num_math (core->num, strtok (NULL, "")); + bpi = rz_debug_bp_add (core->dbg, 0, hwbp, false, 0, module, delta); if (!bpi) { eprintf ("Cannot set breakpoint.\n"); } free (string); } break; - case 'j': r_bp_list (core->dbg->bp, 'j'); break; - case '*': r_bp_list (core->dbg->bp, 1); break; - case '\0': r_bp_list (core->dbg->bp, 0); break; + case 'j': rz_bp_list (core->dbg->bp, 'j'); break; + case '*': rz_bp_list (core->dbg->bp, 1); break; + case '\0': rz_bp_list (core->dbg->bp, 0); break; case '-': // "db-" if (input[2] == '*') { - r_bp_del_all (core->dbg->bp); + rz_bp_del_all (core->dbg->bp); } else { - #define DB_ARG(x) r_str_word_get0(str, x) - char *str = strdup (r_str_trim_head_ro (input +2)); + #define DB_ARG(x) rz_str_word_get0(str, x) + char *str = strdup (rz_str_trim_head_ro (input +2)); int i = 0; - int sl = r_str_word_set0 (str); + int sl = rz_str_word_set0 (str); for ( ; i < sl; i++) { - const ut64 addr = r_num_math (core->num, DB_ARG (i)); - r_bp_del (core->dbg->bp, addr); + const ut64 addr = rz_num_math (core->num, DB_ARG (i)); + rz_bp_del (core->dbg->bp, addr); } free (str); } @@ -3614,8 +3614,8 @@ static void r_core_cmd_bp(RCore *core, const char *input) { char *arg = strchr (inp, ' '); if (arg) { *arg++ = 0; - addr = r_num_math (core->num, inp); - bpi = r_bp_get_at (core->dbg->bp, addr); + addr = rz_num_math (core->num, inp); + bpi = rz_bp_get_at (core->dbg->bp, addr); if (bpi) { free (bpi->data); bpi->data = strdup (arg); @@ -3640,8 +3640,8 @@ static void r_core_cmd_bp(RCore *core, const char *input) { char *arg = strchr (inp, ' '); if (arg) { *arg++ = 0; - addr = r_num_math (core->num, inp); - bpi = r_bp_get_at (core->dbg->bp, addr); + addr = rz_num_math (core->num, inp); + bpi = rz_bp_get_at (core->dbg->bp, addr); if (bpi) { free (bpi->cond); bpi->cond = strdup (arg); @@ -3660,23 +3660,23 @@ static void r_core_cmd_bp(RCore *core, const char *input) { } break; case 's': // "dbs" - addr = r_num_math (core->num, input + 2); - bpi = r_bp_get_at (core->dbg->bp, addr); + addr = rz_num_math (core->num, input + 2); + bpi = rz_bp_get_at (core->dbg->bp, addr); if (bpi) { //bp->enabled = !bp->enabled; // XXX(jjd): this ^^ is what I would think toggling means... - r_bp_del (core->dbg->bp, addr); + rz_bp_del (core->dbg->bp, addr); } else { // XXX(jjd): does t his need an address validity check?? - bpi = r_debug_bp_add (core->dbg, addr, hwbp, false, 0, NULL, 0); + bpi = rz_debug_bp_add (core->dbg, addr, hwbp, false, 0, NULL, 0); if (!bpi) { eprintf ("Cannot set breakpoint (%s)\n", input + 2); } } - r_bp_enable (core->dbg->bp, r_num_math (core->num, input + 2), true, 0); + rz_bp_enable (core->dbg->bp, rz_num_math (core->num, input + 2), true, 0); break; case 'n': // "dbn" - bpi = r_bp_get_at (core->dbg->bp, core->offset); + bpi = rz_bp_get_at (core->dbg->bp, core->offset); if (input[2] == ' ') { if (bpi) { free (bpi->name); @@ -3687,41 +3687,41 @@ static void r_core_cmd_bp(RCore *core, const char *input) { } } else { if (bpi && bpi->name) { - r_cons_println (bpi->name); + rz_cons_println (bpi->name); } } break; case 'e': // "dbe" for (p = input + 2; *p == ' '; p++); - if (*p == '*') r_bp_enable_all (core->dbg->bp,true); + if (*p == '*') rz_bp_enable_all (core->dbg->bp,true); else { for (; *p && *p != ' '; p++); - r_bp_enable (core->dbg->bp, r_num_math (core->num, input + 2), true, r_num_math (core->num, p)); + rz_bp_enable (core->dbg->bp, rz_num_math (core->num, input + 2), true, rz_num_math (core->num, p)); } break; case 'd': // "dbd" for (p = input + 2; *p == ' '; p++); - if (*p == '*') r_bp_enable_all (core->dbg->bp, false); + if (*p == '*') rz_bp_enable_all (core->dbg->bp, false); else { for (; *p && *p != ' '; p++); - r_bp_enable (core->dbg->bp, r_num_math (core->num, input + 2), false, r_num_math (core->num, p)); + rz_bp_enable (core->dbg->bp, rz_num_math (core->num, input + 2), false, rz_num_math (core->num, p)); } break; case 'h': // "dbh" switch (input[2]) { case 0: - r_bp_plugin_list (core->dbg->bp); + rz_bp_plugin_list (core->dbg->bp); break; case ' ': if (input[3]) { - if (!r_bp_use (core->dbg->bp, input + 3, core->anal->bits)) { + if (!rz_bp_use (core->dbg->bp, input + 3, core->anal->bits)) { eprintf ("Invalid name: '%s'.\n", input + 3); } } break; case '-': if (input[3]) { - if (!r_bp_plugin_del (core->dbg->bp, input + 3)) { + if (!rz_bp_plugin_del (core->dbg->bp, input + 3)) { eprintf ("Invalid name: '%s'.\n", input + 3); } } @@ -3735,10 +3735,10 @@ static void r_core_cmd_bp(RCore *core, const char *input) { #if __WINDOWS__ case 'W': // "dbW" if (input[2] == ' ') { - if (r_w32_add_winmsg_breakpoint (core->dbg, input + 3)) { - r_cons_print ("Breakpoint set.\n"); + if (rz_w32_add_winmsg_breakpoint (core->dbg, input + 3)) { + rz_cons_print ("Breakpoint set.\n"); } else { - r_cons_print ("Breakpoint not set.\n"); + rz_cons_print ("Breakpoint not set.\n"); } } break; @@ -3757,7 +3757,7 @@ static void r_core_cmd_bp(RCore *core, const char *input) { break; case '?': default: - r_core_cmd_help (core, help_msg_db); + rz_core_cmd_help (core, help_msg_db); break; } free (str); @@ -3777,10 +3777,10 @@ static RTreeNode *add_trace_tree_child (Sdb *db, RTree *t, RTreeNode *cur, ut64 } else { t_node->refs++; } - return r_tree_add_node (t, cur, t_node); + return rz_tree_add_node (t, cur, t_node); } -static RCore *_core = NULL; +static RzCore *_core = NULL; static void trace_traverse_pre (RTreeNode *n, RTreeVisitor *vis) { const char *name = ""; @@ -3788,15 +3788,15 @@ static void trace_traverse_pre (RTreeNode *n, RTreeVisitor *vis) { unsigned int i; if (!tn) return; for (i = 0; i < n->depth - 1; i++) { - r_cons_printf (" "); + rz_cons_printf (" "); } if (_core) { - RFlagItem *f = r_flag_get_at (_core->flags, tn->addr, true); + RzFlagItem *f = rz_flag_get_at (_core->flags, tn->addr, true); if (f) { name = f->name; } } - r_cons_printf (" 0x%08"PFMT64x" refs %d %s\n", tn->addr, tn->refs, name); + rz_cons_printf (" 0x%08"PFMT64x" refs %d %s\n", tn->addr, tn->refs, name); } static void trace_traverse (RTree *t) { @@ -3806,15 +3806,15 @@ static void trace_traverse (RTree *t) { fprintf (stderr, "\x1b[2K\r"); fflush (stderr); vis.pre_visit = (RTreeNodeVisitCb)trace_traverse_pre; - r_tree_dfs (t, &vis); + rz_tree_dfs (t, &vis); } -static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_addr) { - bool trace_libs = r_config_get_i (core->config, "dbg.trace.libs"); - bool shallow_trace = r_config_get_i (core->config, "dbg.trace.inrange"); +static void do_debug_trace_calls(RzCore *core, ut64 from, ut64 to, ut64 final_addr) { + bool trace_libs = rz_config_get_i (core->config, "dbg.trace.libs"); + bool shallow_trace = rz_config_get_i (core->config, "dbg.trace.inrange"); Sdb *tracenodes = core->dbg->tracenodes; RTree *tr = core->dbg->tree; - RDebug *dbg = core->dbg; + RzDebug *dbg = core->dbg; ut64 debug_to = UT64_MAX; RTreeNode *cur; ut64 addr = 0; @@ -3822,45 +3822,45 @@ static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_add if (!trace_libs) { #if NOOP - RList *bounds = r_core_get_boundaries_prot (core, -1, "dbg.program", "search"); - r_list_free (bounds); + RzList *bounds = rz_core_get_boundaries_prot (core, -1, "dbg.program", "search"); + rz_list_free (bounds); #endif } /* set root if not already present */ - r_tree_add_node (tr, NULL, NULL); + rz_tree_add_node (tr, NULL, NULL); cur = tr->root; while (true) { ut8 buf[32]; - RAnalOp aop; + RzAnalOp aop; int addr_in_range; - if (r_cons_is_breaked()) { + if (rz_cons_is_breaked()) { break; } - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { break; } - if (debug_to != UT64_MAX && !r_debug_continue_until (dbg, debug_to)) { + if (debug_to != UT64_MAX && !rz_debug_continue_until (dbg, debug_to)) { break; } - if (!r_debug_step (dbg, 1)) { + if (!rz_debug_step (dbg, 1)) { break; } debug_to = UT64_MAX; - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { break; } - addr = r_debug_reg_get (dbg, "PC"); + addr = rz_debug_reg_get (dbg, "PC"); if (addr == final_addr) { //we finished the tracing so break the loop break; } addr_in_range = addr >= from && addr < to; - r_io_read_at (core->io, addr, buf, sizeof (buf)); - r_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + rz_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); eprintf ("%d %"PFMT64x"\r", n++, addr); switch (aop.type) { case R_ANAL_OP_TYPE_UCALL: @@ -3873,9 +3873,9 @@ static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_add // store regs // step into // get pc - r_debug_step (dbg, 1); - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - called_addr = r_debug_reg_get (dbg, "PC"); + rz_debug_step (dbg, 1); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + called_addr = rz_debug_reg_get (dbg, "PC"); called_in_range = called_addr >= from && called_addr < to; if (!called_in_range && addr_in_range && !shallow_trace) { debug_to = addr + aop.size; @@ -3906,9 +3906,9 @@ static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_add case R_ANAL_OP_TYPE_RET: #if 0 // TODO: we must store ret value for each call in the graph path to do this check - r_debug_step (dbg, 1); - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - addr = r_debug_reg_get (dbg, "PC"); + rz_debug_step (dbg, 1); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + addr = rz_debug_reg_get (dbg, "PC"); // TODO: step into and check return address if correct // if not correct we are hijacking the control flow (exploit!) #endif @@ -3926,57 +3926,57 @@ static void do_debug_trace_calls(RCore *core, ut64 from, ut64 to, ut64 final_add } } -static void debug_trace_calls(RCore *core, const char *input) { +static void debug_trace_calls(RzCore *core, const char *input) { RBreakpointItem *bp_final = NULL; int t = core->dbg->trace->enabled; ut64 from = 0, to = UT64_MAX, final_addr = UT64_MAX; - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { eprintf ("No process to debug."); return; } if (*input == ' ') { - input = r_str_trim_head_ro (input); - ut64 first_n = r_num_math (core->num, input); + input = rz_str_trim_head_ro (input); + ut64 first_n = rz_num_math (core->num, input); input = strchr (input, ' '); if (input) { - input = r_str_trim_head_ro (input); + input = rz_str_trim_head_ro (input); from = first_n; - to = r_num_math (core->num, input); + to = rz_num_math (core->num, input); input = strchr (input, ' '); if (input) { - input = r_str_trim_head_ro (input); - final_addr = r_num_math (core->num, input); + input = rz_str_trim_head_ro (input); + final_addr = rz_num_math (core->num, input); } } else { final_addr = first_n; } } core->dbg->trace->enabled = 0; - r_cons_break_push (static_debug_stop, core->dbg); - r_reg_arena_swap (core->dbg->reg, true); + rz_cons_break_push (static_debug_stop, core->dbg); + rz_reg_arena_swap (core->dbg->reg, true); if (final_addr != UT64_MAX) { - int hwbp = r_config_get_i (core->config, "dbg.hwbp"); - bp_final = r_debug_bp_add (core->dbg, final_addr, hwbp, false, 0, NULL, 0); + int hwbp = rz_config_get_i (core->config, "dbg.hwbp"); + bp_final = rz_debug_bp_add (core->dbg, final_addr, hwbp, false, 0, NULL, 0); if (!bp_final) { eprintf ("Cannot set breakpoint at final address (%"PFMT64x")\n", final_addr); } } do_debug_trace_calls (core, from, to, final_addr); if (bp_final) { - r_bp_del (core->dbg->bp, final_addr); + rz_bp_del (core->dbg->bp, final_addr); } _core = core; trace_traverse (core->dbg->tree); core->dbg->trace->enabled = t; - r_cons_break_pop (); + rz_cons_break_pop (); } -static void r_core_debug_esil (RCore *core, const char *input) { +static void rz_core_debug_esil (RzCore *core, const char *input) { switch (input[0]) { case '\0': // "de" // list - r_debug_esil_watch_list (core->dbg); + rz_debug_esil_watch_list (core->dbg); break; case ' ': // "de " { @@ -3995,7 +3995,7 @@ static void r_core_debug_esil (RCore *core, const char *input) { *q++ = 0; dev = p[0]; if (q) { - r_debug_esil_watch (core->dbg, perm, dev, q); + rz_debug_esil_watch (core->dbg, perm, dev, q); done = 1; } } @@ -4005,33 +4005,33 @@ static void r_core_debug_esil (RCore *core, const char *input) { "Usage:", "de", " [perm] [reg|mem] [expr]", NULL }; - r_core_cmd_help (core, help_de_msg); + rz_core_cmd_help (core, help_de_msg); } free (line); } break; case '-': // "de-" - r_debug_esil_watch_reset (core->dbg); + rz_debug_esil_watch_reset (core->dbg); break; case 'c': // "dec" - if (r_debug_esil_watch_empty (core->dbg)) { + if (rz_debug_esil_watch_empty (core->dbg)) { eprintf ("Error: no esil watchpoints defined\n"); } else { - r_core_cmd0 (core, "aei"); - r_debug_esil_prestep (core->dbg, r_config_get_i (core->config, "esil.prestep")); - r_debug_esil_continue (core->dbg); + rz_core_cmd0 (core, "aei"); + rz_debug_esil_prestep (core->dbg, rz_config_get_i (core->config, "esil.prestep")); + rz_debug_esil_continue (core->dbg); } break; case 's': // "des" if (input[1] == 'u' && input[2] == ' ') { // "desu" - ut64 addr, naddr, fin = r_num_math (core->num, input + 2); - r_core_cmd0 (core, "aei"); - addr = r_debug_reg_get (core->dbg, "PC"); + ut64 addr, naddr, fin = rz_num_math (core->num, input + 2); + rz_core_cmd0 (core, "aei"); + addr = rz_debug_reg_get (core->dbg, "PC"); while (addr != fin) { - r_debug_esil_prestep (core->dbg, r_config_get_i ( + rz_debug_esil_prestep (core->dbg, rz_config_get_i ( core->config, "esil.prestep")); - r_debug_esil_step (core->dbg, 1); - naddr = r_debug_reg_get (core->dbg, "PC"); + rz_debug_esil_step (core->dbg, 1); + naddr = rz_debug_reg_get (core->dbg, "PC"); if (naddr == addr) { eprintf ("Detected loophole\n"); break; @@ -4039,20 +4039,20 @@ static void r_core_debug_esil (RCore *core, const char *input) { addr = naddr; } } else if (input[1] == '?' || !input[1]) { - r_core_cmd_help (core, help_msg_des); + rz_core_cmd_help (core, help_msg_des); } else { - r_core_cmd0 (core, "aei"); - r_debug_esil_prestep (core->dbg, r_config_get_i (core->config, "esil.prestep")); + rz_core_cmd0 (core, "aei"); + rz_debug_esil_prestep (core->dbg, rz_config_get_i (core->config, "esil.prestep")); // continue - r_debug_esil_step (core->dbg, r_num_math (core->num, input + 1)); + rz_debug_esil_step (core->dbg, rz_num_math (core->num, input + 1)); } break; case '?': // "de?" default: { - r_core_cmd_help (core, help_msg_de); + rz_core_cmd_help (core, help_msg_de); // TODO #7967 help refactor: move to detail - r_cons_printf ("Examples:\n" + rz_cons_printf ("Examples:\n" " de r r rip # stop when reads rip\n" " de rw m ADDR # stop when read or write in ADDR\n" " de w r rdx # stop when rdx register is modified\n" @@ -4062,28 +4062,28 @@ static void r_core_debug_esil (RCore *core, const char *input) { } } -static void r_core_debug_kill (RCore *core, const char *input) { +static void rz_core_debug_kill (RzCore *core, const char *input) { if (!input || *input=='?') { if (input && input[1]) { const char *signame, *arg = input + 1; int signum = atoi (arg); if (signum > 0) { - signame = r_signal_to_string (signum); + signame = rz_signal_to_string (signum); if (signame) - r_cons_println (signame); + rz_cons_println (signame); } else { - signum = r_signal_from_string (arg); + signum = rz_signal_from_string (arg); if (signum > 0) { - r_cons_printf ("%d\n", signum); + rz_cons_printf ("%d\n", signum); } } } else { - r_core_cmd_help (core, help_msg_dk); + rz_core_cmd_help (core, help_msg_dk); } } else if (*input=='o') { switch (input[1]) { case 0: // "dko" - list signal skip/conts - r_debug_signal_list (core->dbg, 1); + rz_debug_signal_list (core->dbg, 1); break; case ' ': // dko SIGNAL if (input[2]) { @@ -4095,14 +4095,14 @@ static void r_core_debug_kill (RCore *core, const char *input) { // - pass // - trace // - stop - if (signum<1) signum = r_signal_from_string (name); + if (signum<1) signum = rz_signal_from_string (name); if (signum>0) { if (!p || !p[0]) { // stop (the usual) - r_debug_signal_setup (core->dbg, signum, 0); + rz_debug_signal_setup (core->dbg, signum, 0); } else if (*p == 's') { // skip - r_debug_signal_setup (core->dbg, signum, R_DBG_SIGNAL_SKIP); + rz_debug_signal_setup (core->dbg, signum, R_DBG_SIGNAL_SKIP); } else if (*p == 'c') { // cont - r_debug_signal_setup (core->dbg, signum, R_DBG_SIGNAL_CONT); + rz_debug_signal_setup (core->dbg, signum, R_DBG_SIGNAL_CONT); } else { eprintf ("Invalid option: %s\n", p); } @@ -4116,40 +4116,40 @@ static void r_core_debug_kill (RCore *core, const char *input) { case '?': default: { - r_core_cmd_help (core, help_msg_dko); + rz_core_cmd_help (core, help_msg_dko); // TODO #7967 help refactor: move to detail - r_cons_println ("NOTE: [signal] can be a number or a string that resolves with dk?\n" + rz_cons_println ("NOTE: [signal] can be a number or a string that resolves with dk?\n" " skip means do not enter into the signal handler\n" " continue means enter into the signal handler"); } } } else if (*input == 'j') { - r_debug_signal_list (core->dbg, 2); + rz_debug_signal_list (core->dbg, 2); } else if (!*input) { - r_debug_signal_list (core->dbg, 0); + rz_debug_signal_list (core->dbg, 0); #if 0 - RListIter *iter; - RDebugSignal *ds; + RzListIter *iter; + RzDebugSignal *ds; eprintf ("TODO: list signal handlers of child\n"); - RList *list = r_debug_kill_list (core->dbg); - r_list_foreach (list, iter, ds) { + RzList *list = rz_debug_kill_list (core->dbg); + rz_list_foreach (list, iter, ds) { // TODO: resolve signal name by number and show handler offset eprintf ("--> %d\n", ds->num); } - r_list_free (list); + rz_list_free (list); #endif } else { int sig = atoi (input); char *p = strchr (input, '='); if (p) { - r_debug_kill_setup (core->dbg, sig, r_num_math (core->num, p+1)); + rz_debug_kill_setup (core->dbg, sig, rz_num_math (core->num, p+1)); } else { - r_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, sig); + rz_debug_kill (core->dbg, core->dbg->pid, core->dbg->tid, sig); } } } -static bool is_x86_call(RDebug *dbg, ut64 addr) { +static bool is_x86_call(RzDebug *dbg, ut64 addr) { ut8 buf[3]; ut8 *op = buf; (void)dbg->iob.read_at (dbg->iob.io, addr, buf, R_ARRAY_SIZE (buf)); @@ -4173,7 +4173,7 @@ static bool is_x86_call(RDebug *dbg, ut64 addr) { return false; } -static bool is_x86_ret(RDebug *dbg, ut64 addr) { +static bool is_x86_ret(RzDebug *dbg, ut64 addr) { ut8 buf[1]; (void)dbg->iob.read_at (dbg->iob.io, addr, buf, R_ARRAY_SIZE (buf)); switch (buf[0]) { @@ -4188,44 +4188,44 @@ static bool is_x86_ret(RDebug *dbg, ut64 addr) { /* Possibly incomplete with regard to instruction prefixes */ } -static bool cmd_dcu (RCore *core, const char *input) { +static bool cmd_dcu (RzCore *core, const char *input) { const char *ptr = NULL; ut64 from, to, pc; bool dcu_range = false; bool invalid = (!input[0] || !input[1] || !input[2]); if (invalid || (input[2] != ' ' && input[2] != '.')) { - r_core_cmd_help (core, help_msg_dcu); + rz_core_cmd_help (core, help_msg_dcu); return false; } to = UT64_MAX; if (input[2] == '.') { ptr = strchr (input + 3, ' '); if (ptr) { // TODO: put '\0' in *ptr to avoid - from = r_num_tail (core->num, core->offset, input + 2); + from = rz_num_tail (core->num, core->offset, input + 2); if (ptr[1]=='.') { - to = r_num_tail (core->num, core->offset, ptr+2); + to = rz_num_tail (core->num, core->offset, ptr+2); } else { - to = r_num_math (core->num, ptr+1); + to = rz_num_math (core->num, ptr+1); } dcu_range = true; } else { - from = r_num_tail (core->num, core->offset, input + 2); + from = rz_num_tail (core->num, core->offset, input + 2); } } else { ptr = strchr (input + 3, ' '); if (ptr) { // TODO: put '\0' in *ptr to avoid - from = r_num_math (core->num, input + 3); + from = rz_num_math (core->num, input + 3); if (ptr[1]=='.') { - to = r_num_tail (core->num, core->offset, ptr+2); + to = rz_num_tail (core->num, core->offset, ptr+2); } else { - to = r_num_math (core->num, ptr+1); + to = rz_num_math (core->num, ptr+1); } dcu_range = true; } else { - from = r_num_math (core->num, input + 3); + from = rz_num_math (core->num, input + 3); } } - if (core->num->nc.errors && r_cons_is_interactive ()) { + if (core->num->nc.errors && rz_cons_is_interactive ()) { eprintf ("Cannot continue until unknown address '%s'\n", core->num->nc.calc_buf); return false; } @@ -4233,18 +4233,18 @@ static bool cmd_dcu (RCore *core, const char *input) { to = from; } if (dcu_range) { - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_debug_step (core->dbg, 1); - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - pc = r_debug_reg_get (core->dbg, "PC"); + rz_debug_step (core->dbg, 1); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + pc = rz_debug_reg_get (core->dbg, "PC"); eprintf ("Continue 0x%08"PFMT64x" > 0x%08"PFMT64x" < 0x%08"PFMT64x"\n", from, pc, to); } while (pc < from || pc > to); - r_cons_break_pop (); + rz_cons_break_pop (); } else { ut64 addr = from; if (!strcmp (core->dbg->btalgo, "trace") && core->dbg->arch @@ -4257,37 +4257,37 @@ static bool cmd_dcu (RCore *core, const char *input) { bool prev_ret = false; const char *sp_name = core->dbg->reg->name[R_REG_NAME_SP]; ut64 old_sp, cur_sp; - r_cons_break_push (NULL, NULL); - r_list_free (core->dbg->call_frames); - core->dbg->call_frames = r_list_new (); + rz_cons_break_push (NULL, NULL); + rz_list_free (core->dbg->call_frames); + core->dbg->call_frames = rz_list_new (); core->dbg->call_frames->free = free; - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - old_sp = r_debug_reg_get (core->dbg, sp_name); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + old_sp = rz_debug_reg_get (core->dbg, sp_name); while (true) { - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - pc = r_debug_reg_get (core->dbg, pc_name); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + pc = rz_debug_reg_get (core->dbg, pc_name); if (prev_call) { ut32 ret_addr; - RDebugFrame *frame = R_NEW0 (RDebugFrame); - cur_sp = r_debug_reg_get (core->dbg, sp_name); + RzDebugFrame *frame = R_NEW0 (RzDebugFrame); + cur_sp = rz_debug_reg_get (core->dbg, sp_name); (void)core->dbg->iob.read_at (core->dbg->iob.io, cur_sp, (ut8 *)&ret_addr, sizeof (ret_addr)); frame->addr = ret_addr; frame->size = old_sp - cur_sp; frame->sp = cur_sp; frame->bp = old_sp; - r_list_prepend (core->dbg->call_frames, frame); + rz_list_prepend (core->dbg->call_frames, frame); eprintf ("%ld Call from 0x%08"PFMT64x" to 0x%08"PFMT64x" ret 0x%08"PFMT32x"\n", level, prev_pc, pc, ret_addr); level++; old_sp = cur_sp; prev_call = false; } else if (prev_ret) { - RDebugFrame *head = r_list_get_bottom (core->dbg->call_frames); + RzDebugFrame *head = rz_list_get_bottom (core->dbg->call_frames); if (head && head->addr != pc) { eprintf ("*"); } else { - r_list_pop_head (core->dbg->call_frames); + rz_list_pop_head (core->dbg->call_frames); eprintf ("%ld", level); level--; } @@ -4298,7 +4298,7 @@ static bool cmd_dcu (RCore *core, const char *input) { if (steps % 500 == 0 || pc == addr) { eprintf ("At 0x%08"PFMT64x" after %lu steps\n", pc, steps); } - if (r_cons_is_breaked () || r_debug_is_dead (core->dbg) || pc == addr) { + if (rz_cons_is_breaked () || rz_debug_is_dead (core->dbg) || pc == addr) { break; } if (is_x86_call (core->dbg, pc)) { @@ -4308,21 +4308,21 @@ static bool cmd_dcu (RCore *core, const char *input) { prev_pc = pc; prev_ret = true; } - r_debug_step (core->dbg, 1); + rz_debug_step (core->dbg, 1); steps++; } - r_cons_break_pop (); + rz_cons_break_pop (); return true; } eprintf ("Continue until 0x%08"PFMT64x" using %d bpsize\n", addr, core->dbg->bpsize); - r_reg_arena_swap (core->dbg->reg, true); - if (r_bp_add_sw (core->dbg->bp, addr, core->dbg->bpsize, R_BP_PROT_EXEC)) { - if (r_debug_is_dead (core->dbg)) { + rz_reg_arena_swap (core->dbg->reg, true); + if (rz_bp_add_sw (core->dbg->bp, addr, core->dbg->bpsize, R_BP_PROT_EXEC)) { + if (rz_debug_is_dead (core->dbg)) { eprintf ("Cannot continue, run ood?\n"); } else { - r_debug_continue (core->dbg); + rz_debug_continue (core->dbg); } - r_bp_del (core->dbg->bp, addr); + rz_bp_del (core->dbg->bp, addr); } else { eprintf ("Cannot set breakpoint of size %d at 0x%08"PFMT64x"\n", core->dbg->bpsize, addr); @@ -4331,21 +4331,21 @@ static bool cmd_dcu (RCore *core, const char *input) { return true; } -static int cmd_debug_continue (RCore *core, const char *input) { +static int cmd_debug_continue (RzCore *core, const char *input) { int pid, old_pid, signum; char *ptr; // TODO: we must use this for step 'ds' too maybe... switch (input[1]) { case 0: // "dc" - r_reg_arena_swap (core->dbg->reg, true); + rz_reg_arena_swap (core->dbg->reg, true); #if __linux__ core->dbg->continue_all_threads = true; #endif - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { eprintf ("Cannot continue, run ood?\n"); break; } - r_debug_continue (core->dbg); + rz_debug_continue (core->dbg); break; case 'a': // "dca" eprintf ("TODO: dca\n"); @@ -4356,40 +4356,40 @@ static int cmd_debug_continue (RCore *core, const char *input) { eprintf ("Error: Session has not started\n"); break; } - if (!r_debug_continue_back (core->dbg)) { + if (!rz_debug_continue_back (core->dbg)) { eprintf ("cannot continue back\n"); } break; } #if __WINDOWS__ case 'e': // "dce" - r_reg_arena_swap (core->dbg->reg, true); - r_debug_continue_pass_exception (core->dbg); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_continue_pass_exception (core->dbg); break; #endif case 'f': // "dcf" eprintf ("[+] Running 'dcs vfork fork clone' behind the scenes...\n"); // we should stop in fork and vfork syscalls //TODO: multiple syscalls not handled yet - // r_core_cmd0 (core, "dcs vfork fork"); - r_core_cmd0 (core, "dcs vfork fork clone"); + // rz_core_cmd0 (core, "dcs vfork fork"); + rz_core_cmd0 (core, "dcs vfork fork clone"); break; case 'c': // "dcc" - r_reg_arena_swap (core->dbg->reg, true); + rz_reg_arena_swap (core->dbg->reg, true); if (input[2] == 'u') { - r_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_UCALL, 0); + rz_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_UCALL, 0); } else { - r_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_CALL, 0); + rz_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_CALL, 0); } break; case 'r': - r_reg_arena_swap (core->dbg->reg, true); - r_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_RET, 1); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_continue_until_optype (core->dbg, R_ANAL_OP_TYPE_RET, 1); break; case 'k': - // select pid and r_debug_continue_kill (core->dbg, - r_reg_arena_swap (core->dbg->reg, true); - signum = r_num_math (core->num, input + 2); + // select pid and rz_debug_continue_kill (core->dbg, + rz_reg_arena_swap (core->dbg->reg, true); + signum = rz_num_math (core->num, input + 2); ptr = strchr (input + 3, ' '); if (ptr) { int old_pid = core->dbg->pid; @@ -4397,11 +4397,11 @@ static int cmd_debug_continue (RCore *core, const char *input) { int pid = atoi (ptr+1); int tid = pid; // XXX *ptr = 0; - r_debug_select (core->dbg, pid, tid); - r_debug_continue_kill (core->dbg, signum); - r_debug_select (core->dbg, old_pid, old_tid); + rz_debug_select (core->dbg, pid, tid); + rz_debug_continue_kill (core->dbg, signum); + rz_debug_select (core->dbg, old_pid, old_tid); } else { - r_debug_continue_kill (core->dbg, signum); + rz_debug_continue_kill (core->dbg, signum); } break; case 's': // "dcs" @@ -4417,36 +4417,36 @@ static int cmd_debug_continue (RCore *core, const char *input) { break; default: case '?': - r_core_cmd_help (core, help_msg_dcs); + rz_core_cmd_help (core, help_msg_dcs); break; } break; case 'p': // "dcp" { // XXX: this is very slow - RIOMap *s; + RzIOMap *s; ut64 pc; int n = 0; bool t = core->dbg->trace->enabled; core->dbg->trace->enabled = false; - r_cons_break_push (static_debug_stop, core->dbg); + rz_cons_break_push (static_debug_stop, core->dbg); do { - r_debug_step (core->dbg, 1); - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - pc = r_debug_reg_get (core->dbg, "PC"); + rz_debug_step (core->dbg, 1); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + pc = rz_debug_reg_get (core->dbg, "PC"); eprintf (" %d %"PFMT64x"\r", n++, pc); - s = r_io_map_get (core->io, pc); - if (r_cons_is_breaked ()) { + s = rz_io_map_get (core->io, pc); + if (rz_cons_is_breaked ()) { break; } } while (!s); eprintf ("\n"); core->dbg->trace->enabled = t; - r_cons_break_pop (); + rz_cons_break_pop (); return 1; } case 'u': // "dcu" if (input[2] == '?') { - r_core_cmd_help (core, help_msg_dcu); + rz_core_cmd_help (core, help_msg_dcu); } else if (input[2] == '.') { cmd_dcu (core, "cu $$"); } else { @@ -4456,17 +4456,17 @@ static int cmd_debug_continue (RCore *core, const char *input) { case ' ': old_pid = core->dbg->pid; pid = atoi (input + 2); - r_reg_arena_swap (core->dbg->reg, true); - r_debug_select (core->dbg, pid, core->dbg->tid); - r_debug_continue (core->dbg); - r_debug_select (core->dbg, old_pid, core->dbg->tid); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_select (core->dbg, pid, core->dbg->tid); + rz_debug_continue (core->dbg); + rz_debug_select (core->dbg, old_pid, core->dbg->tid); break; case 't': cmd_debug_backtrace (core, input + 2); break; case '?': // "dc?" default: - r_core_cmd_help (core, help_msg_dc); + rz_core_cmd_help (core, help_msg_dc); return 0; } return 1; @@ -4474,18 +4474,18 @@ static int cmd_debug_continue (RCore *core, const char *input) { static char *get_corefile_name (const char *raw_name, int pid) { return (!*raw_name)? - r_str_newf ("core.%u", pid) : - r_str_trim_dup (raw_name); + rz_str_newf ("core.%u", pid) : + rz_str_trim_dup (raw_name); } -static int cmd_debug_step (RCore *core, const char *input) { +static int cmd_debug_step (RzCore *core, const char *input) { ut64 addr = core->offset;; ut8 buf[64]; - RAnalOp aop; + RzAnalOp aop; int i, times = 1; char *ptr = strchr (input, ' '); if (ptr) { - times = r_num_math (core->num, ptr + 1); + times = rz_num_math (core->num, ptr + 1); } if (times < 1) { times = 1; @@ -4493,38 +4493,38 @@ static int cmd_debug_step (RCore *core, const char *input) { switch (input[1]) { case 0: // "ds" case ' ': - if (r_config_get_i (core->config, "cfg.debug")) { - r_reg_arena_swap (core->dbg->reg, true); + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_reg_arena_swap (core->dbg->reg, true); // sync registers for BSD PT_STEP/PT_CONT // XXX(jjd): is this necessary? - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - ut64 pc = r_debug_reg_get (core->dbg, "PC"); - r_debug_trace_pc (core->dbg, pc); - if (!r_debug_step (core->dbg, times)) { + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); + rz_debug_trace_pc (core->dbg, pc); + if (!rz_debug_step (core->dbg, times)) { eprintf ("Step failed\n"); core->break_loop = true; } } else { - r_core_cmdf (core, "%daes", R_MAX (1, times)); + rz_core_cmdf (core, "%daes", R_MAX (1, times)); } break; case 'i': // "dsi" if (input[2] == ' ') { int n = 0; - r_cons_break_push (static_debug_stop, core->dbg); + rz_cons_break_push (static_debug_stop, core->dbg); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_debug_step (core->dbg, 1); - if (r_debug_is_dead (core->dbg)) { + rz_debug_step (core->dbg, 1); + if (rz_debug_is_dead (core->dbg)) { core->break_loop = true; break; } - r_core_cmd0 (core, ".dr*"); + rz_core_cmd0 (core, ".dr*"); n++; - } while (!r_num_conditional (core->num, input + 3)); - r_cons_break_pop (); + } while (!rz_num_conditional (core->num, input + 3)); + rz_cons_break_pop (); eprintf ("Stopped after %d instructions\n", n); } else { eprintf ("3 Missing argument\n"); @@ -4553,155 +4553,155 @@ static int cmd_debug_step (RCore *core, const char *input) { step_until_optype (core, input + 3); break; case ' ': // dsu
- r_reg_arena_swap (core->dbg->reg, true); - step_until (core, r_num_math (core->num, input + 2)); // XXX dupped by times + rz_reg_arena_swap (core->dbg->reg, true); + step_until (core, rz_num_math (core->num, input + 2)); // XXX dupped by times break; default: - r_core_cmd_help (core, help_msg_dsu); + rz_core_cmd_help (core, help_msg_dsu); return 0; } break; case 'p': // "dsp" - r_reg_arena_swap (core->dbg->reg, true); + rz_reg_arena_swap (core->dbg->reg, true); for (i = 0; i < times; i++) { ut8 buf[64]; ut64 addr; - RAnalOp aop; - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - addr = r_debug_reg_get (core->dbg, "PC"); - r_io_read_at (core->io, addr, buf, sizeof (buf)); - r_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + RzAnalOp aop; + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + addr = rz_debug_reg_get (core->dbg, "PC"); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + rz_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); if (aop.type == R_ANAL_OP_TYPE_CALL) { - RBinObject *o = r_bin_cur_object (core->bin); - RBinSection *s = r_bin_get_section_at (o, aop.jump, true); + RBinObject *o = rz_bin_cur_object (core->bin); + RBinSection *s = rz_bin_get_section_at (o, aop.jump, true); if (!s) { - r_debug_step_over (core->dbg, times); + rz_debug_step_over (core->dbg, times); continue; } } - r_debug_step (core->dbg, 1); + rz_debug_step (core->dbg, 1); } break; case 's': // "dss" { char delb[128] = R_EMPTY; - addr = r_debug_reg_get (core->dbg, "PC"); - RBreakpointItem *bpi = r_bp_get_at (core->dbg->bp, addr); + addr = rz_debug_reg_get (core->dbg, "PC"); + RBreakpointItem *bpi = rz_bp_get_at (core->dbg->bp, addr); sprintf(delb, "db 0x%"PFMT64x"", addr); - r_reg_arena_swap (core->dbg->reg, true); + rz_reg_arena_swap (core->dbg->reg, true); for (i = 0; i < times; i++) { - r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); - r_io_read_at (core->io, addr, buf, sizeof (buf)); - r_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + rz_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); #if 0 if (aop.jump != UT64_MAX && aop.fail != UT64_MAX) { eprintf ("Don't know how to skip this instruction\n"); - if (bpi) r_core_cmd0 (core, delb); + if (bpi) rz_core_cmd0 (core, delb); break; } #endif addr += aop.size; } - r_debug_reg_set (core->dbg, "PC", addr); - r_reg_setv (core->anal->reg, "PC", addr); - r_core_cmd0 (core, ".dr*"); + rz_debug_reg_set (core->dbg, "PC", addr); + rz_reg_setv (core->anal->reg, "PC", addr); + rz_core_cmd0 (core, ".dr*"); if (bpi) { - r_core_cmd0 (core, delb); + rz_core_cmd0 (core, delb); } break; } case 'o': // "dso" - if (r_config_get_i (core->config, "dbg.skipover")) { - r_core_cmdf (core, "dss%s", input + 2); + if (rz_config_get_i (core->config, "dbg.skipover")) { + rz_core_cmdf (core, "dss%s", input + 2); } else { - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { char delb[128] = R_EMPTY; - addr = r_debug_reg_get (core->dbg, "PC"); - RBreakpointItem *bpi = r_bp_get_at (core->dbg->bp, addr); + addr = rz_debug_reg_get (core->dbg, "PC"); + RBreakpointItem *bpi = rz_bp_get_at (core->dbg->bp, addr); sprintf(delb, "db 0x%"PFMT64x"", addr); - r_bp_del (core->dbg->bp, addr); - r_reg_arena_swap (core->dbg->reg, true); - r_debug_step_over (core->dbg, times); - if (bpi) r_core_cmd0 (core, delb); + rz_bp_del (core->dbg->bp, addr); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_step_over (core->dbg, times); + if (bpi) rz_core_cmd0 (core, delb); } else { - r_core_cmdf (core, "aeso%s", input + 2); + rz_core_cmdf (core, "aeso%s", input + 2); } } break; case 'b': // "dsb" - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { if (!core->dbg->session) { eprintf ("Session has not started\n"); - } else if (r_debug_step_back (core->dbg, times) < 0) { + } else if (rz_debug_step_back (core->dbg, times) < 0) { eprintf ("Error: stepping back failed\n"); } } else { - if (r_core_esil_step_back (core)) { - r_core_cmd0 (core, ".dr*"); + if (rz_core_esil_step_back (core)) { + rz_core_cmd0 (core, ".dr*"); } else { eprintf ("cannot step back\n"); } } break; case 'l': // "dsl" - r_reg_arena_swap (core->dbg->reg, true); + rz_reg_arena_swap (core->dbg->reg, true); step_line (core, times); break; case '?': // "ds?" default: - r_core_cmd_help (core, help_msg_ds); + rz_core_cmd_help (core, help_msg_ds); return 0; } return 1; } -static ut8*getFileData(RCore *core, const char *arg) { +static ut8*getFileData(RzCore *core, const char *arg) { if (*arg == '$') { - return (ut8*) r_cmd_alias_get (core->rcmd, arg, 1); + return (ut8*) rz_cmd_alias_get (core->rcmd, arg, 1); } - return (ut8*)r_file_slurp (arg, NULL); + return (ut8*)rz_file_slurp (arg, NULL); } static void consumeBuffer(RBuffer *buf, const char *cmd, const char *errmsg) { if (!buf) { if (errmsg) { - r_cons_printf ("%s\n", errmsg); + rz_cons_printf ("%s\n", errmsg); } return; } if (cmd) { - r_cons_printf ("%s", cmd); + rz_cons_printf ("%s", cmd); } int i; - r_buf_seek (buf, 0, R_BUF_SET); - for (i = 0; i < r_buf_size (buf); i++) { - r_cons_printf ("%02x", r_buf_read8 (buf)); + rz_buf_seek (buf, 0, R_BUF_SET); + for (i = 0; i < rz_buf_size (buf); i++) { + rz_cons_printf ("%02x", rz_buf_read8 (buf)); } - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } static int cmd_debug(void *data, const char *input) { - RCore *core = (RCore *)data; - RDebugTracepoint *t; + RzCore *core = (RzCore *)data; + RzDebugTracepoint *t; int follow = 0; const char *ptr; ut64 addr; int min; - RListIter *iter; - RList *list; - RDebugPid *p; - RDebugTracepoint *trace; - RAnalOp *op; + RzListIter *iter; + RzList *list; + RzDebugPid *p; + RzDebugTracepoint *trace; + RzAnalOp *op; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("Debugger commands disabled in sandbox mode\n"); return 0; } if (!strncmp (input, "ate", 3)) { char str[128]; str[0] = 0; - r_print_date_get_now (core->print, str); - r_cons_println (str); + rz_print_date_get_now (core->print, str); + rz_cons_println (str); return 0; } @@ -4710,79 +4710,79 @@ static int cmd_debug(void *data, const char *input) { // TODO: define ranges? to display only some traces, allow to scroll on this disasm? ~.. ? switch (input[1]) { case '\0': // "dt" - r_debug_trace_list (core->dbg, 0, core->offset); + rz_debug_trace_list (core->dbg, 0, core->offset); break; case '=': // "dt=" - r_debug_trace_list (core->dbg, '=', core->offset); + rz_debug_trace_list (core->dbg, '=', core->offset); break; case 'q': // "dtq" - r_debug_trace_list (core->dbg, 'q', core->offset); + rz_debug_trace_list (core->dbg, 'q', core->offset); break; case '*': // "dt*" - r_debug_trace_list (core->dbg, 1, core->offset); + rz_debug_trace_list (core->dbg, 1, core->offset); break; case ' ': // "dt [addr]" - if ((t = r_debug_trace_get (core->dbg, - r_num_math (core->num, input + 3)))) { - r_cons_printf ("offset = 0x%" PFMT64x "\n", t->addr); - r_cons_printf ("opsize = %d\n", t->size); - r_cons_printf ("times = %d\n", t->times); - r_cons_printf ("count = %d\n", t->count); + if ((t = rz_debug_trace_get (core->dbg, + rz_num_math (core->num, input + 3)))) { + rz_cons_printf ("offset = 0x%" PFMT64x "\n", t->addr); + rz_cons_printf ("opsize = %d\n", t->size); + rz_cons_printf ("times = %d\n", t->times); + rz_cons_printf ("count = %d\n", t->count); //TODO cons_printf("time = %d\n", t->tm); } break; case 'a': // "dta" - r_debug_trace_at (core->dbg, input + 3); + rz_debug_trace_at (core->dbg, input + 3); break; case 't': // "dtt" - r_debug_trace_tag (core->dbg, atoi (input + 3)); + rz_debug_trace_tag (core->dbg, atoi (input + 3)); break; case 'c': // "dtc" if (input[2] == '?') { - r_cons_println ("Usage: dtc [addr] ([from] [to] [addr]) - trace calls in debugger"); + rz_cons_println ("Usage: dtc [addr] ([from] [to] [addr]) - trace calls in debugger"); } else { debug_trace_calls (core, input + 2); } break; case 'd': // "dtd" - min = r_num_math (core->num, input + 3); + min = rz_num_math (core->num, input + 3); if (input[2] == 'q') { // "dtdq" int n = 0; - r_list_foreach (core->dbg->trace->traces, iter, trace) { + rz_list_foreach (core->dbg->trace->traces, iter, trace) { if (n >= min) { - r_cons_printf ("%d ", trace->count); - r_cons_printf ("0x%08"PFMT64x"\n", trace->addr); + rz_cons_printf ("%d ", trace->count); + rz_cons_printf ("0x%08"PFMT64x"\n", trace->addr); break; } n++; } } else if (input[2] == 'i') { int n = 0; - r_list_foreach (core->dbg->trace->traces, iter, trace) { - op = r_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + rz_list_foreach (core->dbg->trace->traces, iter, trace) { + op = rz_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (n >= min) { - r_cons_printf ("%d %s\n", trace->count, op->mnemonic); + rz_cons_printf ("%d %s\n", trace->count, op->mnemonic); } n++; - r_anal_op_free (op); + rz_anal_op_free (op); } } else if (input[2] == ' ') { int n = 0; - r_list_foreach (core->dbg->trace->traces, iter, trace) { - op = r_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + rz_list_foreach (core->dbg->trace->traces, iter, trace) { + op = rz_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (n >= min) { - r_cons_printf ("0x%08"PFMT64x" %s\n", trace->addr, op->mnemonic); + rz_cons_printf ("0x%08"PFMT64x" %s\n", trace->addr, op->mnemonic); } n++; - r_anal_op_free (op); + rz_anal_op_free (op); } } else { // TODO: reimplement using the api - //r_core_cmd0 (core, "pd 1 @@= `dtq`"); - r_list_foreach (core->dbg->trace->traces, iter, trace) { - op = r_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); - r_cons_printf ("0x%08"PFMT64x" %s\n", trace->addr, op->mnemonic); - r_anal_op_free (op); + //rz_core_cmd0 (core, "pd 1 @@= `dtq`"); + rz_list_foreach (core->dbg->trace->traces, iter, trace) { + op = rz_core_anal_op (core, trace->addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + rz_cons_printf ("0x%08"PFMT64x" %s\n", trace->addr, op->mnemonic); + rz_anal_op_free (op); } } break; @@ -4790,40 +4790,40 @@ static int cmd_debug(void *data, const char *input) { dot_trace_traverse (core, core->dbg->tree, input[2]); break; case '-': // "dt-" - r_tree_reset (core->dbg->tree); - r_debug_trace_free (core->dbg->trace); - r_debug_tracenodes_reset (core->dbg); - core->dbg->trace = r_debug_trace_new (); + rz_tree_reset (core->dbg->tree); + rz_debug_trace_free (core->dbg->trace); + rz_debug_tracenodes_reset (core->dbg); + core->dbg->trace = rz_debug_trace_new (); break; case '+': // "dt+" if (input[2] == '+') { // "dt++" - char *a, *s = r_str_trim_dup (input + 3); - RList *args = r_str_split_list (s, " ", 0); - RListIter *iter; - r_list_foreach (args, iter, a) { - ut64 addr = r_num_get (NULL, a); - (void)r_debug_trace_add (core->dbg, addr, 1); + char *a, *s = rz_str_trim_dup (input + 3); + RzList *args = rz_str_split_list (s, " ", 0); + RzListIter *iter; + rz_list_foreach (args, iter, a) { + ut64 addr = rz_num_get (NULL, a); + (void)rz_debug_trace_add (core->dbg, addr, 1); } - r_list_free (args); + rz_list_free (args); free (s); } else { ptr = input + 2; - addr = r_num_math (core->num, ptr); + addr = rz_num_math (core->num, ptr); ptr = strchr (ptr, ' '); int count = 1; if (ptr) { - count = r_num_math (core->num, ptr + 1); + count = rz_num_math (core->num, ptr + 1); } - RAnalOp *op = r_core_op_anal (core, addr, R_ANAL_OP_MASK_HINT); + RzAnalOp *op = rz_core_op_anal (core, addr, R_ANAL_OP_MASK_HINT); if (op) { - RDebugTracepoint *tp = r_debug_trace_add (core->dbg, addr, op->size); + RzDebugTracepoint *tp = rz_debug_trace_add (core->dbg, addr, op->size); if (!tp) { - r_anal_op_free (op); + rz_anal_op_free (op); break; } tp->count = count; - r_anal_trace_bb (core->anal, addr); - r_anal_op_free (op); + rz_anal_trace_bb (core->anal, addr); + rz_anal_op_free (op); } else { eprintf ("Cannot analyze opcode at 0x%08" PFMT64x "\n", addr); } @@ -4831,31 +4831,31 @@ static int cmd_debug(void *data, const char *input) { break; case 'e': // "dte" if (!core->anal->esil) { - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int romem = r_config_get_i (core->config, "esil.romem"); - int stats = r_config_get_i (core->config, "esil.stats"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int nonull = r_config_get_i (core->config, "esil.nonull"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - if (!(core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int romem = rz_config_get_i (core->config, "esil.romem"); + int stats = rz_config_get_i (core->config, "esil.stats"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int nonull = rz_config_get_i (core->config, "esil.nonull"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + if (!(core->anal->esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return 0; } - r_anal_esil_setup (core->anal->esil, core->anal, romem, stats, nonull); + rz_anal_esil_setup (core->anal->esil, core->anal, romem, stats, nonull); } switch (input[2]) { case 0: // "dte" - r_anal_esil_trace_list (core->anal->esil); + rz_anal_esil_trace_list (core->anal->esil); break; case 'i': { // "dtei" - ut64 addr = r_num_math (core->num, input + 3); + ut64 addr = rz_num_math (core->num, input + 3); if (!addr) { addr = core->offset; } - RAnalOp *op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_ESIL); + RzAnalOp *op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_ESIL); if (op) { - r_anal_esil_trace_op (core->anal->esil, op); + rz_anal_esil_trace_op (core->anal->esil, op); } - r_anal_op_free (op); + rz_anal_op_free (op); } break; case '-': // "dte-" if (!strcmp (input + 3, "*")) { @@ -4869,27 +4869,27 @@ static int cmd_debug(void *data, const char *input) { break; case ' ': { // "dte " int idx = atoi (input + 3); - r_anal_esil_trace_show ( + rz_anal_esil_trace_show ( core->anal->esil, idx); } break; case 'k': // "dtek" if (input[3] == ' ') { char *s = sdb_querys (core->anal->esil->trace->db, NULL, 0, input + 4); - r_cons_println (s); + rz_cons_println (s); free (s); } else { eprintf ("Usage: dtek [query]\n"); } break; default: - r_core_cmd_help (core, help_msg_dte); + rz_core_cmd_help (core, help_msg_dte); } break; case 's': // "dts" switch (input[2]) { case '+': // "dts+" - if (r_debug_is_dead (core->dbg)) { + if (rz_debug_is_dead (core->dbg)) { eprintf ("Cannot start session outside of debug mode, run ood?\n"); break; } @@ -4897,15 +4897,15 @@ static int cmd_debug(void *data, const char *input) { eprintf ("Session already started\n"); break; } - core->dbg->session = r_debug_session_new (); - r_debug_add_checkpoint (core->dbg); + core->dbg->session = rz_debug_session_new (); + rz_debug_add_checkpoint (core->dbg); break; case '-': // "dts-" if (!core->dbg->session) { eprintf ("No session started\n"); break; } - r_debug_session_free (core->dbg->session); + rz_debug_session_free (core->dbg->session); core->dbg->session = NULL; break; case 't': // "dtst" @@ -4913,30 +4913,30 @@ static int cmd_debug(void *data, const char *input) { eprintf ("No session started\n"); break; } - r_debug_session_save (core->dbg->session, input + 4); + rz_debug_session_save (core->dbg->session, input + 4); break; case 'f': // "dtsf" if (core->dbg->session) { - r_debug_session_free (core->dbg->session); + rz_debug_session_free (core->dbg->session); core->dbg->session = NULL; } - core->dbg->session = r_debug_session_new (); - r_debug_session_load (core->dbg, input + 4); + core->dbg->session = rz_debug_session_new (); + rz_debug_session_load (core->dbg, input + 4); break; case 'm': // "dtsm" if (core->dbg->session) { - r_debug_session_list_memory (core->dbg); + rz_debug_session_list_memory (core->dbg); } break; default: - r_core_cmd_help (core, help_msg_dts); + rz_core_cmd_help (core, help_msg_dts); } break; case '?': default: { - r_core_cmd_help (core, help_msg_dt); - r_cons_printf ("Current Tag: %d\n", core->dbg->trace->tag); + rz_core_cmd_help (core, help_msg_dt); + rz_cons_printf ("Current Tag: %d\n", core->dbg->trace->tag); } break; } @@ -4944,34 +4944,34 @@ static int cmd_debug(void *data, const char *input) { case 'd': // "ddd" switch (input[1]) { case '\0': // "ddd" - r_debug_desc_list (core->dbg, 0); + rz_debug_desc_list (core->dbg, 0); break; case '*': // "dtd*" - r_debug_desc_list (core->dbg, 1); + rz_debug_desc_list (core->dbg, 1); break; case 's': // "dtds" { ut64 off = UT64_MAX; int fd = atoi (input + 2); char *str = strchr (input + 2, ' '); - if (str) off = r_num_math (core->num, str+1); - if (off == UT64_MAX || !r_debug_desc_seek (core->dbg, fd, off)) { - RBuffer *buf = r_core_syscallf (core, "lseek", "%d, 0x%"PFMT64x", %d", fd, off, 0); + if (str) off = rz_num_math (core->num, str+1); + if (off == UT64_MAX || !rz_debug_desc_seek (core->dbg, fd, off)) { + RBuffer *buf = rz_core_syscallf (core, "lseek", "%d, 0x%"PFMT64x", %d", fd, off, 0); consumeBuffer (buf, "dx ", "Cannot seek"); } } break; case 't': // "ddt" - r_core_cmdf (core, "dd-0"); + rz_core_cmdf (core, "dd-0"); break; case 'd': // "ddd" { ut64 newfd = UT64_MAX; int fd = atoi (input + 2); char *str = strchr (input + 3, ' '); - if (str) newfd = r_num_math (core->num, str+1); - if (newfd == UT64_MAX || !r_debug_desc_dup (core->dbg, fd, newfd)) { - RBuffer *buf = r_core_syscallf (core, "dup2", "%d, %d", fd, (int)newfd); + if (str) newfd = rz_num_math (core->num, str+1); + if (newfd == UT64_MAX || !rz_debug_desc_dup (core->dbg, fd, newfd)) { + RBuffer *buf = rz_core_syscallf (core, "dup2", "%d, %d", fd, (int)newfd); if (buf) { consumeBuffer (buf, "dx ", NULL); } else { @@ -4986,12 +4986,12 @@ static int cmd_debug(void *data, const char *input) { ut64 len = UT64_MAX; int fd = atoi (input + 2); char *str = strchr (input + 2, ' '); - if (str) off = r_num_math (core->num, str+1); + if (str) off = rz_num_math (core->num, str+1); if (str) str = strchr (str+1, ' '); - if (str) len = r_num_math (core->num, str+1); + if (str) len = rz_num_math (core->num, str+1); if (len == UT64_MAX || off == UT64_MAX || \ - !r_debug_desc_read (core->dbg, fd, off, len)) { - consumeBuffer (r_core_syscallf (core, "read", "%d, 0x%"PFMT64x", %d", + !rz_debug_desc_read (core->dbg, fd, off, len)) { + consumeBuffer (rz_core_syscallf (core, "read", "%d, 0x%"PFMT64x", %d", fd, off, (int)len), "dx ", "Cannot read"); } } @@ -5002,56 +5002,56 @@ static int cmd_debug(void *data, const char *input) { ut64 len = UT64_MAX; int fd = atoi (input + 2); char *str = strchr (input + 2, ' '); - if (str) off = r_num_math (core->num, str+1); + if (str) off = rz_num_math (core->num, str+1); if (str) str = strchr (str+1, ' '); - if (str) len = r_num_math (core->num, str+1); + if (str) len = rz_num_math (core->num, str+1); if (len == UT64_MAX || off == UT64_MAX || \ - !r_debug_desc_write (core->dbg, fd, off, len)) { - RBuffer *buf = r_core_syscallf (core, "write", "%d, 0x%"PFMT64x", %d", fd, off, (int)len); + !rz_debug_desc_write (core->dbg, fd, off, len)) { + RBuffer *buf = rz_core_syscallf (core, "write", "%d, 0x%"PFMT64x", %d", fd, off, (int)len); consumeBuffer (buf, "dx ", "Cannot write"); } } break; case '-': // "dd-" // close file - //r_core_syscallf (core, "close", "%d", atoi (input + 2)); + //rz_core_syscallf (core, "close", "%d", atoi (input + 2)); { int fd = atoi (input + 2); - //r_core_cmdf (core, "dxs close %d", (int)r_num_math ( core->num, input + 2)); - RBuffer *buf = r_core_syscallf (core, "close", "%d", fd); + //rz_core_cmdf (core, "dxs close %d", (int)rz_num_math ( core->num, input + 2)); + RBuffer *buf = rz_core_syscallf (core, "close", "%d", fd); consumeBuffer (buf, "dx ", "Cannot close"); } break; case ' ': // "dd" // TODO: handle read, readwrite, append { - RBuffer *buf = r_core_syscallf (core, "open", "%s, %d, %d", input + 2, 2, 0644); + RBuffer *buf = rz_core_syscallf (core, "open", "%s, %d, %d", input + 2, 2, 0644); consumeBuffer (buf, "dx ", "Cannot open"); } // open file break; case '?': default: - r_core_cmd_help (core, help_msg_dd); + rz_core_cmd_help (core, help_msg_dd); break; } break; case 's': if (cmd_debug_step (core, input)) { - follow = r_config_get_i (core->config, "dbg.follow"); + follow = rz_config_get_i (core->config, "dbg.follow"); } break; case 'b': - r_core_cmd_bp (core, input); + rz_core_cmd_bp (core, input); break; case 'H': eprintf ("TODO: transplant process\n"); break; case 'c': // "dc" - r_cons_break_push (static_debug_stop, core->dbg); + rz_cons_break_push (static_debug_stop, core->dbg); (void)cmd_debug_continue (core, input); - follow = r_config_get_i (core->config, "dbg.follow"); - r_cons_break_pop (); + follow = rz_config_get_i (core->config, "dbg.follow"); + rz_cons_break_pop (); break; case 'm': // "dm" cmd_debug_map (core, input + 1); @@ -5062,7 +5062,7 @@ static int cmd_debug(void *data, const char *input) { } else { cmd_anal_reg (core, input + 1); } - //r_core_cmd (core, "|reg", 0); + //rz_core_cmd (core, "|reg", 0); break; case 'p': // "dp" cmd_debug_pid (core, input); @@ -5070,45 +5070,45 @@ static int cmd_debug(void *data, const char *input) { case 'L': // "dL" switch (input[1]) { case 'q': - r_debug_plugin_list (core->dbg, 'q'); + rz_debug_plugin_list (core->dbg, 'q'); break; case 'j': - r_debug_plugin_list (core->dbg, 'j'); + rz_debug_plugin_list (core->dbg, 'j'); break; case '?': - r_core_cmd_help (core, help_msg_dL); + rz_core_cmd_help (core, help_msg_dL); break; case ' ': { - char *str = r_str_trim_dup (input + 2); - r_config_set (core->config, "dbg.backend", str); - // implicit by config.set r_debug_use (core->dbg, str); + char *str = rz_str_trim_dup (input + 2); + rz_config_set (core->config, "dbg.backend", str); + // implicit by config.set rz_debug_use (core->dbg, str); free (str); } break; default: - r_debug_plugin_list (core->dbg, 0); + rz_debug_plugin_list (core->dbg, 0); break; } break; case 'i': // "di" { - RDebugInfo *rdi = r_debug_info (core->dbg, input + 2); - RDebugReasonType stop = r_debug_stop_reason (core->dbg); + RzDebugInfo *rdi = rz_debug_info (core->dbg, input + 2); + RzDebugReasonType stop = rz_debug_stop_reason (core->dbg); char *escaped_str; switch (input[1]) { case '\0': // "di" -#define P r_cons_printf -#define PS(X, Y) {escaped_str = r_str_escape (Y);r_cons_printf(X, escaped_str);free(escaped_str);} +#define P rz_cons_printf +#define PS(X, Y) {escaped_str = rz_str_escape (Y);rz_cons_printf(X, escaped_str);free(escaped_str);} if (rdi) { - const char *s = r_signal_to_string (core->dbg->reason.signum); - P ("type=%s\n", r_debug_reason_to_string (core->dbg->reason.type)); + const char *s = rz_signal_to_string (core->dbg->reason.signum); + P ("type=%s\n", rz_debug_reason_to_string (core->dbg->reason.type)); P ("signal=%s\n", s? s: "none"); P ("signum=%d\n", core->dbg->reason.signum); P ("sigpid=%d\n", core->dbg->reason.tid); P ("addr=0x%"PFMT64x"\n", core->dbg->reason.addr); P ("bp_addr=0x%"PFMT64x"\n", core->dbg->reason.bp_addr); - P ("inbp=%s\n", r_str_bool (core->dbg->reason.bp_addr)); - P ("baddr=0x%"PFMT64x"\n", r_debug_get_baddr (core->dbg, NULL)); + P ("inbp=%s\n", rz_str_bool (core->dbg->reason.bp_addr)); + P ("baddr=0x%"PFMT64x"\n", rz_debug_get_baddr (core->dbg, NULL)); P ("pid=%d\n", rdi->pid); P ("tid=%d\n", rdi->tid); P ("stopaddr=0x%"PFMT64x"\n", core->dbg->stopaddr); @@ -5144,7 +5144,7 @@ static int cmd_debug(void *data, const char *input) { } else { char *arg = strchr (input, ' '); if (arg) { - arg = strdup (r_str_trim_head_ro (arg + 1)); + arg = strdup (rz_str_trim_head_ro (arg + 1)); char *arg2 = strchr (arg, ' '); if (arg2) { *arg2++ = 0; @@ -5153,10 +5153,10 @@ static int cmd_debug(void *data, const char *input) { if (a && b) { int al = strlen ((const char*)a); int bl = strlen ((const char*)b); - RDiff *d = r_diff_new (); - char *uni = r_diff_buffers_to_string (d, a, al, b, bl); - r_cons_printf ("%s\n", uni); - r_diff_free (d); + RzDiff *d = rz_diff_new (); + char *uni = rz_diff_buffers_to_string (d, a, al, b, bl); + rz_cons_printf ("%s\n", uni); + rz_diff_free (d); free (uni); } else { eprintf ("Cannot open those alias files\n"); @@ -5170,28 +5170,28 @@ static int cmd_debug(void *data, const char *input) { break; case '*': // "di*" if (rdi) { - r_cons_printf ("f dbg.signal = %d\n", core->dbg->reason.signum); - r_cons_printf ("f dbg.sigpid = %d\n", core->dbg->reason.tid); - r_cons_printf ("f dbg.inbp = %d\n", core->dbg->reason.bp_addr? 1: 0); - r_cons_printf ("f dbg.sigaddr = 0x%"PFMT64x"\n", core->dbg->reason.addr); - r_cons_printf ("f dbg.baddr = 0x%"PFMT64x"\n", r_debug_get_baddr (core->dbg, NULL)); - r_cons_printf ("f dbg.pid = %d\n", rdi->pid); - r_cons_printf ("f dbg.tid = %d\n", rdi->tid); - r_cons_printf ("f dbg.uid = %d\n", rdi->uid); - r_cons_printf ("f dbg.gid = %d\n", rdi->gid); + rz_cons_printf ("f dbg.signal = %d\n", core->dbg->reason.signum); + rz_cons_printf ("f dbg.sigpid = %d\n", core->dbg->reason.tid); + rz_cons_printf ("f dbg.inbp = %d\n", core->dbg->reason.bp_addr? 1: 0); + rz_cons_printf ("f dbg.sigaddr = 0x%"PFMT64x"\n", core->dbg->reason.addr); + rz_cons_printf ("f dbg.baddr = 0x%"PFMT64x"\n", rz_debug_get_baddr (core->dbg, NULL)); + rz_cons_printf ("f dbg.pid = %d\n", rdi->pid); + rz_cons_printf ("f dbg.tid = %d\n", rdi->tid); + rz_cons_printf ("f dbg.uid = %d\n", rdi->uid); + rz_cons_printf ("f dbg.gid = %d\n", rdi->gid); } break; case 'j': // "dij" P ("{"); if (rdi) { - const char *s = r_signal_to_string (core->dbg->reason.signum); - P ("\"type\":\"%s\",", r_debug_reason_to_string (core->dbg->reason.type)); + const char *s = rz_signal_to_string (core->dbg->reason.signum); + P ("\"type\":\"%s\",", rz_debug_reason_to_string (core->dbg->reason.type)); P ("\"signal\":\"%s\",", s? s: "none"); P ("\"signum\":%d,", core->dbg->reason.signum); P ("\"sigpid\":%d,", core->dbg->reason.tid); P ("\"addr\":%"PFMT64d",", core->dbg->reason.addr); - P ("\"inbp\":%s,", r_str_bool (core->dbg->reason.bp_addr)); - P ("\"baddr\":%"PFMT64d",", r_debug_get_baddr (core->dbg, NULL)); + P ("\"inbp\":%s,", rz_str_bool (core->dbg->reason.bp_addr)); + P ("\"baddr\":%"PFMT64d",", rz_debug_get_baddr (core->dbg, NULL)); P ("\"stopaddr\":%"PFMT64d",", core->dbg->stopaddr); P ("\"pid\":%d,", rdi->pid); P ("\"tid\":%d,", rdi->tid); @@ -5216,23 +5216,23 @@ static int cmd_debug(void *data, const char *input) { #undef PS case 'q': { - const char *r = r_debug_reason_to_string (core->dbg->reason.type); + const char *r = rz_debug_reason_to_string (core->dbg->reason.type); if (!r) { r = "none"; } - r_cons_printf ("%s at 0x%08"PFMT64x"\n", r, core->dbg->stopaddr); + rz_cons_printf ("%s at 0x%08"PFMT64x"\n", r, core->dbg->stopaddr); } break; case '?': // "di?" default: - r_core_cmd_help (core, help_msg_di); + rz_core_cmd_help (core, help_msg_di); break; } - r_debug_info_free (rdi); + rz_debug_info_free (rdi); } break; case 'e': // "de" - r_core_debug_esil (core, input + 1); + rz_core_debug_esil (core, input + 1); break; case 'g': // "dg" if (core->dbg->h && core->dbg->h->gcore) { @@ -5242,37 +5242,37 @@ static int cmd_debug(void *data, const char *input) { } char *corefile = get_corefile_name (input + 1, core->dbg->pid); eprintf ("Writing to file '%s'\n", corefile); - r_file_rm (corefile); - RBuffer *dst = r_buf_new_file (corefile, O_RDWR | O_CREAT, 0644); + rz_file_rm (corefile); + RBuffer *dst = rz_buf_new_file (corefile, O_RDWR | O_CREAT, 0644); if (dst) { if (!core->dbg->h->gcore (core->dbg, dst)) { eprintf ("dg: coredump failed\n"); } - r_buf_free (dst); + rz_buf_free (dst); } else { - perror ("r_buf_new_file"); + perror ("rz_buf_new_file"); } free (corefile); } break; case 'k': // "dk" - r_core_debug_kill (core, input + 1); + rz_core_debug_kill (core, input + 1); break; case 'o': // "do" switch (input[1]) { case '\0': // "do" - r_core_file_reopen (core, input[1] ? input + 2: NULL, 0, 1); + rz_core_file_reopen (core, input[1] ? input + 2: NULL, 0, 1); break; case 'e': // "doe" switch (input[2]) { case '\0': // "doe" if (core->io->envprofile) { - r_cons_println (core->io->envprofile); + rz_cons_println (core->io->envprofile); } break; case '!': // "doe!" { - char *out = r_core_editor (core, NULL, core->io->envprofile); + char *out = rz_core_editor (core, NULL, core->io->envprofile); if (out) { free (core->io->envprofile); core->io->envprofile = out; @@ -5288,19 +5288,19 @@ static int cmd_debug(void *data, const char *input) { setRarunProfileString (core, input + 3); } else { // TODO use the api - r_sys_cmd ("rarun2 -h"); + rz_sys_cmd ("rz_run -h"); } break; case 'o': // "doo" : reopen in debug mode if (input[2] == 'f') { // "doof" : reopen in debug mode from the given file - r_config_set_i (core->config, "cfg.debug", true); - r_core_cmd0 (core, sdb_fmt ("oodf %s", input + 3)); + rz_config_set_i (core->config, "cfg.debug", true); + rz_core_cmd0 (core, sdb_fmt ("oodf %s", input + 3)); } else { - r_core_file_reopen_debug (core, input + 2); + rz_core_file_reopen_debug (core, input + 2); } break; case 'c': // "doc" : close current debug session - if (!core || !core->io || !core->io->desc || !r_config_get_i (core->config, "cfg.debug")) { + if (!core || !core->io || !core->io->desc || !rz_config_get_i (core->config, "cfg.debug")) { eprintf ("No open debug session\n"); break; } @@ -5308,100 +5308,100 @@ static int cmd_debug(void *data, const char *input) { if (core->dbg && core->dbg->h && core->dbg->h->pids && core->dbg->pid != -1) { list = core->dbg->h->pids (core->dbg, core->dbg->pid); if (list) { - r_list_foreach (list, iter, p) { - r_debug_kill (core->dbg, p->pid, p->pid, SIGKILL); - r_debug_detach (core->dbg, p->pid); + rz_list_foreach (list, iter, p) { + rz_debug_kill (core->dbg, p->pid, p->pid, SIGKILL); + rz_debug_detach (core->dbg, p->pid); } } else { - r_debug_kill (core->dbg, core->dbg->pid, core->dbg->pid, SIGKILL); - r_debug_detach (core->dbg, core->dbg->pid); + rz_debug_kill (core->dbg, core->dbg->pid, core->dbg->pid, SIGKILL); + rz_debug_detach (core->dbg, core->dbg->pid); } } // Reopen and rebase the original file - r_core_cmd0 (core, "oo"); + rz_core_cmd0 (core, "oo"); // Remove registers from the flag list - r_core_cmd0 (core, "~dr-"); + rz_core_cmd0 (core, "~dr-"); break; case '?': // "do?" default: - r_core_cmd_help (core, help_msg_do); + rz_core_cmd_help (core, help_msg_do); break; } break; #if __WINDOWS__ case 'W': // "dW" if (input[1] == 'i') { - r_w32_identify_window (); + rz_w32_identify_window (); } else { - r_w32_print_windows (core->dbg); + rz_w32_print_windows (core->dbg); } break; #endif case 'w': // "dw" - r_cons_break_push (static_debug_stop, core->dbg); - for (;!r_cons_is_breaked ();) { + rz_cons_break_push (static_debug_stop, core->dbg); + for (;!rz_cons_is_breaked ();) { int pid = atoi (input + 1); //int opid = core->dbg->pid = pid; - int res = r_debug_kill (core->dbg, pid, 0, 0); + int res = rz_debug_kill (core->dbg, pid, 0, 0); if (!res) { break; } - r_sys_usleep (200); + rz_sys_usleep (200); } - r_cons_break_pop (); + rz_cons_break_pop (); break; case 'x': // "dx" switch (input[1]) { case ' ': { // "dx " ut8 bytes[4096]; if (strlen (input + 2) < 4096){ - int bytes_len = r_hex_str2bin (input + 2, bytes); - if (bytes_len>0) r_debug_execute (core->dbg, + int bytes_len = rz_hex_str2bin (input + 2, bytes); + if (bytes_len>0) rz_debug_execute (core->dbg, bytes, bytes_len, 0); else eprintf ("Invalid hexpairs\n"); } else eprintf ("Injection opcodes so long\n"); break; } case 'a': { // "dxa" - RAsmCode *acode; - r_asm_set_pc (core->rasm, core->offset); - acode = r_asm_massemble (core->rasm, input + 2); + RzAsmCode *acode; + rz_asm_set_pc (core->rasm, core->offset); + acode = rz_asm_massemble (core->rasm, input + 2); if (acode) { - r_reg_arena_push (core->dbg->reg); - r_debug_execute (core->dbg, acode->bytes, acode->len, 0); - r_reg_arena_pop (core->dbg->reg); + rz_reg_arena_push (core->dbg->reg); + rz_debug_execute (core->dbg, acode->bytes, acode->len, 0); + rz_reg_arena_pop (core->dbg->reg); } - r_asm_code_free (acode); + rz_asm_code_free (acode); break; } case 'e': { // "dxe" - REgg *egg = core->egg; + RzEgg *egg = core->egg; RBuffer *b; - const char *asm_arch = r_config_get (core->config, "asm.arch"); - int asm_bits = r_config_get_i (core->config, "asm.bits"); - const char *asm_os = r_config_get (core->config, "asm.os"); - r_egg_setup (egg, asm_arch, asm_bits, 0, asm_os); - r_egg_reset (egg); - r_egg_load (egg, input + 1, 0); - r_egg_compile (egg); - b = r_egg_get_bin (egg); - r_asm_set_pc (core->rasm, core->offset); - r_reg_arena_push (core->dbg->reg); + const char *asm_arch = rz_config_get (core->config, "asm.arch"); + int asm_bits = rz_config_get_i (core->config, "asm.bits"); + const char *asm_os = rz_config_get (core->config, "asm.os"); + rz_egg_setup (egg, asm_arch, asm_bits, 0, asm_os); + rz_egg_reset (egg); + rz_egg_load (egg, input + 1, 0); + rz_egg_compile (egg); + b = rz_egg_get_bin (egg); + rz_asm_set_pc (core->rasm, core->offset); + rz_reg_arena_push (core->dbg->reg); ut64 tmpsz; - const ut8 *tmp = r_buf_data (b, &tmpsz); - r_debug_execute (core->dbg, tmp, tmpsz, 0); - r_reg_arena_pop (core->dbg->reg); + const ut8 *tmp = rz_buf_data (b, &tmpsz); + rz_debug_execute (core->dbg, tmp, tmpsz, 0); + rz_reg_arena_pop (core->dbg->reg); break; } case 'r': // "dxr" - r_reg_arena_push (core->dbg->reg); + rz_reg_arena_push (core->dbg->reg); if (input[2] == ' ') { ut8 bytes[4096]; if (strlen (input + 2) < 4096){ - int bytes_len = r_hex_str2bin (input + 2, + int bytes_len = rz_hex_str2bin (input + 2, bytes); if (bytes_len > 0) { - r_debug_execute (core->dbg, + rz_debug_execute (core->dbg, bytes, bytes_len, 0); } else { @@ -5409,15 +5409,15 @@ static int cmd_debug(void *data, const char *input) { } } else eprintf ("Injection opcodes so long\n"); } - r_reg_arena_pop (core->dbg->reg); + rz_reg_arena_pop (core->dbg->reg); break; case 's': // "dxs" if (input[2]) { char *str; - r_cons_push (); - str = r_core_cmd_str (core, sdb_fmt ("gs %s", input + 2)); - r_cons_pop (); - r_core_cmdf (core, "dx %s", str); //`gs %s`", input + 2); + rz_cons_push (); + str = rz_core_cmd_str (core, sdb_fmt ("gs %s", input + 2)); + rz_cons_pop (); + rz_core_cmdf (core, "dx %s", str); //`gs %s`", input + 2); free (str); } else { eprintf ("Missing parameter used in gs by dxs\n"); @@ -5425,19 +5425,19 @@ static int cmd_debug(void *data, const char *input) { break; case '?': // "dx?" default: - r_core_cmd_help (core, help_msg_dx); + rz_core_cmd_help (core, help_msg_dx); break; } break; case '?': // "d?" default: - r_core_cmd_help (core, help_msg_d); + rz_core_cmd_help (core, help_msg_d); break; } if (follow > 0) { - ut64 pc = r_debug_reg_get (core->dbg, "PC"); + ut64 pc = rz_debug_reg_get (core->dbg, "PC"); if ((pc < core->offset) || (pc > (core->offset + follow))) { - r_core_cmd0 (core, "sr PC"); + rz_core_cmd0 (core, "sr PC"); } } return 0; diff --git a/libr/core/cmd_egg.c b/librz/core/cmd_egg.c similarity index 57% rename from libr/core/cmd_egg.c rename to librz/core/cmd_egg.c index a6ac27489a..eaad298597 100644 --- a/libr/core/cmd_egg.c +++ b/librz/core/cmd_egg.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include "r_cons.h" -#include "r_core.h" -#include "r_egg.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_egg.h" static const char *help_msg_g[] = { "Usage:", "g[wcilper] [arg]", "Go compile shellcodes", "g", " ", "Compile the shellcode", - "g", " foo.r", "Compile r_egg source file", + "g", " foo.r", "Compile rz_egg source file", "gw", "", "Compile and write", "gc", " cmd=/bin/ls", "Set config option for shellcodes and encoders", "gc", "", "List all config options", @@ -16,79 +16,79 @@ static const char *help_msg_g[] = { "gi", " [type]", "Define the shellcode type", "gp", " padding", "Define padding for command", "ge", " [encoder] [key]", "Specify an encoder and a key", - "gr", "", "Reset r_egg", + "gr", "", "Reset rz_egg", "gS", "", "Show the current configuration", "EVAL VARS:", "", "asm.arch, asm.bits, asm.os", NULL }; -static void cmd_egg_init(RCore *core, RCmdDesc *parent) { +static void cmd_egg_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, g); } -static void cmd_egg_option(REgg *egg, const char *key, const char *input) { +static void cmd_egg_option(RzEgg *egg, const char *key, const char *input) { if (!*input) { return; } if (input[1] != ' ') { - char *a = r_egg_option_get (egg, key); + char *a = rz_egg_option_get (egg, key); if (a) { - r_cons_println (a); + rz_cons_println (a); free (a); } } else { - r_egg_option_set (egg, key, input + 2); + rz_egg_option_set (egg, key, input + 2); } } static void showBuffer(RBuffer *b) { int i; - if (b && r_buf_size (b) > 0) { - r_buf_seek (b, 0, R_BUF_SET); - for (i = 0; i < r_buf_size (b); i++) { - r_cons_printf ("%02x", r_buf_read8 (b)); + if (b && rz_buf_size (b) > 0) { + rz_buf_seek (b, 0, R_BUF_SET); + for (i = 0; i < rz_buf_size (b); i++) { + rz_cons_printf ("%02x", rz_buf_read8 (b)); } - r_cons_newline (); + rz_cons_newline (); } } #if 0 -static int compileShellcode(REgg *egg, const char *input){ +static int compileShellcode(RzEgg *egg, const char *input){ int i = 0; RBuffer *b; - if (!r_egg_shellcode (egg, input)) { + if (!rz_egg_shellcode (egg, input)) { eprintf ("Unknown shellcode '%s'\n", input); return 1; } - if (!r_egg_assemble (egg)) { - eprintf ("r_egg_assemble : invalid assembly\n"); - r_egg_reset (egg); + if (!rz_egg_assemble (egg)) { + eprintf ("rz_egg_assemble : invalid assembly\n"); + rz_egg_reset (egg); return 1; } if (!egg->bin) { - egg->bin = r_buf_new (); + egg->bin = rz_buf_new (); } - if (!(b = r_egg_get_bin (egg))) { - eprintf ("r_egg_get_bin: invalid egg :(\n"); - r_egg_reset (egg); + if (!(b = rz_egg_get_bin (egg))) { + eprintf ("rz_egg_get_bin: invalid egg :(\n"); + rz_egg_reset (egg); return 1; } - r_egg_finalize (egg); + rz_egg_finalize (egg); for (i = 0; i < b->length; i++) { - r_cons_printf ("%02x", b->buf[i]); + rz_cons_printf ("%02x", b->buf[i]); } - r_cons_newline (); - r_egg_reset (egg); + rz_cons_newline (); + rz_egg_reset (egg); return 0; } #endif -static int cmd_egg_compile(REgg *egg) { +static int cmd_egg_compile(RzEgg *egg) { RBuffer *b; int ret = false; - char *p = r_egg_option_get (egg, "egg.shellcode"); + char *p = rz_egg_option_get (egg, "egg.shellcode"); if (p && *p) { - if (!r_egg_shellcode (egg, p)) { + if (!rz_egg_shellcode (egg, p)) { eprintf ("Unknown shellcode '%s'\n", p); free (p); return false; @@ -100,47 +100,47 @@ static int cmd_egg_compile(REgg *egg) { return false; } - r_egg_compile (egg); - if (!r_egg_assemble (egg)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + rz_egg_compile (egg); + if (!rz_egg_assemble (egg)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); return false; } - p = r_egg_option_get (egg, "egg.padding"); + p = rz_egg_option_get (egg, "egg.padding"); if (p && *p) { - r_egg_padding (egg, p); + rz_egg_padding (egg, p); free (p); } - p = r_egg_option_get (egg, "egg.encoder"); + p = rz_egg_option_get (egg, "egg.encoder"); if (p && *p) { - r_egg_encode (egg, p); + rz_egg_encode (egg, p); free (p); } - if ((b = r_egg_get_bin (egg))) { + if ((b = rz_egg_get_bin (egg))) { showBuffer (b); ret = true; } // we do not own this buffer!! - // r_buf_free (b); - r_egg_option_set (egg, "egg.shellcode", ""); - r_egg_option_set (egg, "egg.padding", ""); - r_egg_option_set (egg, "egg.encoder", ""); - r_egg_option_set (egg, "key", ""); + // rz_buf_free (b); + rz_egg_option_set (egg, "egg.shellcode", ""); + rz_egg_option_set (egg, "egg.padding", ""); + rz_egg_option_set (egg, "egg.encoder", ""); + rz_egg_option_set (egg, "key", ""); - r_egg_reset (egg); + rz_egg_reset (egg); return ret; } static int cmd_egg(void *data, const char *input) { - RCore *core = (RCore *) data; - REgg *egg = core->egg; + RzCore *core = (RzCore *) data; + RzEgg *egg = core->egg; char *oa, *p; - r_egg_setup (egg, - r_config_get (core->config, "asm.arch"), + rz_egg_setup (egg, + rz_config_get (core->config, "asm.arch"), core->rasm->bits, 0, - r_config_get (core->config, "asm.os")); // XXX + rz_config_get (core->config, "asm.os")); // XXX switch (*input) { case 's': // "gs" - // TODO: pass args to r_core_syscall without vararg + // TODO: pass args to rz_core_syscall without vararg if (input[1] == ' ') { RBuffer *buf = NULL; const char *ooaa = input + 2; @@ -149,9 +149,9 @@ static int cmd_egg(void *data, const char *input) { p = strchr (oa + 1, ' '); if (p) { *p = 0; - buf = r_core_syscall (core, oa, p + 1); + buf = rz_core_syscall (core, oa, p + 1); } else { - buf = r_core_syscall (core, oa, ""); + buf = rz_core_syscall (core, oa, ""); } free (oa); if (buf) { @@ -164,7 +164,7 @@ static int cmd_egg(void *data, const char *input) { break; case ' ': // "g " if (input[1] && input[2]) { - r_egg_load (egg, input + 2, 0); + rz_egg_load (egg, input + 2, 0); if (!cmd_egg_compile (egg)) { eprintf ("Cannot compile '%s'\n", input + 2); } @@ -180,7 +180,7 @@ static int cmd_egg(void *data, const char *input) { case 'p': // "gp" if (input[1] == ' ') { if (input[0] && input[2]) { - r_egg_option_set (egg, "egg.padding", input + 2); + rz_egg_option_set (egg, "egg.padding", input + 2); } } else { eprintf ("Usage: gp [padding]\n"); @@ -198,8 +198,8 @@ static int cmd_egg(void *data, const char *input) { if (p) { *p = 0; - r_egg_option_set (egg, "key", p + 1); - r_egg_option_set (egg, "egg.encoder", oa); + rz_egg_option_set (egg, "key", p + 1); + rz_egg_option_set (egg, "egg.encoder", oa); } else { eprintf ("Usage: ge [encoder] [key]\n"); } @@ -211,7 +211,7 @@ static int cmd_egg(void *data, const char *input) { case 'i': // "gi" if (input[1] == ' ') { if (input[0] && input[2]) { - r_egg_option_set (egg, "egg.shellcode", input + 2); + rz_egg_option_set (egg, "egg.shellcode", input + 2); } else { eprintf ("Usage: gi [shellcode-type]\n"); } @@ -221,10 +221,10 @@ static int cmd_egg(void *data, const char *input) { break; case 'l': // "gl" { - RListIter *iter; - REggPlugin *p; - r_list_foreach (egg->plugins, iter, p) { - r_cons_printf ("%s %6s : %s\n", + RzListIter *iter; + RzEggPlugin *p; + rz_list_foreach (egg->plugins, iter, p) { + rz_cons_printf ("%s %6s : %s\n", (p->type == R_EGG_PLUGIN_SHELLCODE)? "shc": "enc", p->name, p->desc); } @@ -241,20 +241,20 @@ static int cmd_egg(void *data, const char *input) { "suid", NULL }; - r_cons_printf ("Configuration options\n"); + rz_cons_printf ("Configuration options\n"); int i; for (i = 0; configList[i]; i++) { const char *p = configList[i]; - if (r_egg_option_get (egg, p)) { - r_cons_printf ("%s : %s\n", p, r_egg_option_get (egg, p)); + if (rz_egg_option_get (egg, p)) { + rz_cons_printf ("%s : %s\n", p, rz_egg_option_get (egg, p)); } else { - r_cons_printf ("%s : %s\n", p, ""); + rz_cons_printf ("%s : %s\n", p, ""); } } - r_cons_printf ("\nTarget options\n"); - r_cons_printf ("arch : %s\n", core->anal->cpu); - r_cons_printf ("os : %s\n", core->anal->os); - r_cons_printf ("bits : %d\n", core->anal->bits); + rz_cons_printf ("\nTarget options\n"); + rz_cons_printf ("arch : %s\n", core->anal->cpu); + rz_cons_printf ("os : %s\n", core->anal->os); + rz_cons_printf ("bits : %d\n", core->anal->bits); } break; case 'r': // "gr" @@ -270,18 +270,18 @@ static int cmd_egg(void *data, const char *input) { p = strchr (oa, '='); if (p) { *p = 0; - r_egg_option_set (egg, oa, p + 1); + rz_egg_option_set (egg, oa, p + 1); } else { - char *o = r_egg_option_get (egg, oa); + char *o = rz_egg_option_get (egg, oa); if (o) { - r_cons_printf (o); + rz_cons_printf (o); free (o); } } free (oa); break; case '\0': - // r_pair_list (egg->pair,NULL); + // rz_pair_list (egg->pair,NULL); eprintf ("TODO: list options\n"); break; default: @@ -290,7 +290,7 @@ static int cmd_egg(void *data, const char *input) { } break; case '?': - r_core_cmd_help (core, help_msg_g); + rz_core_cmd_help (core, help_msg_g); break; } return true; diff --git a/libr/core/cmd_eval.c b/librz/core/cmd_eval.c similarity index 57% rename from libr/core/cmd_eval.c rename to librz/core/cmd_eval.c index 93d708f4fb..064847348e 100644 --- a/libr/core/cmd_eval.c +++ b/librz/core/cmd_eval.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake */ +/* rizin - LGPL - Copyright 2009-2020 - pancake */ #include #include -#include "r_core.h" +#include "rz_core.h" static const char *help_msg_e[] = { "Usage:", "e [var[=value]]", "Evaluable vars", @@ -19,7 +19,7 @@ static const char *help_msg_e[] = { "e!", "a", "invert the boolean value of 'a' var", "ec", " [k] [color]", "set color for given key (prompt, offset, ...)", "ee", "var", "open editor to change the value of var", - "ed", "", "open editor to change the ~/.radare2rc", + "ed", "", "open editor to change the ~/.rizinrc", "ej", "", "list config vars in JSON", "env", " [k[=v]]", "get/set environment variable", "er", " [key]", "set config key as readonly. no way back", @@ -48,7 +48,7 @@ static const char *help_msg_ec[] = { "Vars:", "", "", "colors:", "", "rgb:000, red, green, blue, #ff0000, ...", "e scr.color", "=0", "use more colors (0: no color 1: ansi 16, 2: 256, 3: 16M)", - "$DATADIR/radare2/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./", + "$DATADIR/rizin/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./", NULL }; @@ -60,47 +60,47 @@ static const char *help_msg_eco[] = { "ecoq", "", "list available themes without showing the current one", "ecoj", "", "list available themes in JSON", "Path:", "", "", - "$DATADIR/radare2/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./", + "$DATADIR/rizin/cons", "", R_JOIN_2_PATHS ("~", R2_HOME_THEMES) " ./", NULL }; static char *curtheme = "default"; static bool getNext = false; -static void cmd_eval_init(RCore *core, RCmdDesc *parent) { +static void cmd_eval_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, e); DEFINE_CMD_DESCRIPTOR (core, ec); } -static bool load_theme(RCore *core, const char *path) { - if (!r_file_exists (path)) { +static bool load_theme(RzCore *core, const char *path) { + if (!rz_file_exists (path)) { return false; } core->cmdfilter = "ec "; - bool res = r_core_cmd_file (core, path); + bool res = rz_core_cmd_file (core, path); if (res) { - r_cons_pal_update_event (); + rz_cons_pal_update_event (); } core->cmdfilter = NULL; return res; } -static bool nextpal_item(RCore *core, int mode, const char *file, int ctr) { - const char *fn = r_str_lchr (file, '/'); +static bool nextpal_item(RzCore *core, int mode, const char *file, int ctr) { + const char *fn = rz_str_lchr (file, '/'); if (!fn) fn = file; switch (mode) { case 'j': // json - r_cons_printf ("%s\"%s\"", ctr?",":"", fn); + rz_cons_printf ("%s\"%s\"", ctr?",":"", fn); break; case 'l': // list - r_cons_println (fn); + rz_cons_println (fn); break; case 'p': // previous // TODO: move logic here break; case 'n': // next if (getNext) { - curtheme = r_str_dup (curtheme, fn); + curtheme = rz_str_dup (curtheme, fn); getNext = false; return false; } else if (curtheme) { @@ -108,7 +108,7 @@ static bool nextpal_item(RCore *core, int mode, const char *file, int ctr) { getNext = true; } } else { - curtheme = r_str_dup (curtheme, fn); + curtheme = rz_str_dup (curtheme, fn); return false; } break; @@ -116,35 +116,35 @@ static bool nextpal_item(RCore *core, int mode, const char *file, int ctr) { return true; } -static bool cmd_load_theme(RCore *core, const char *_arg) { +static bool cmd_load_theme(RzCore *core, const char *_arg) { bool failed = false; char *path; if (!_arg || !*_arg) { return false; } - if (!r_str_cmp (_arg, "default", strlen (_arg))) { + if (!rz_str_cmp (_arg, "default", strlen (_arg))) { curtheme = strdup (_arg); - r_cons_pal_init (core->cons->context); + rz_cons_pal_init (core->cons->context); return true; } char *arg = strdup (_arg); - char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_HOME_THEMES, "%s"), arg); - char *home = tmp ? r_str_home (tmp) : NULL; + char *tmp = rz_str_newf (R_JOIN_2_PATHS (R2_HOME_THEMES, "%s"), arg); + char *home = tmp ? rz_str_home (tmp) : NULL; free (tmp); - tmp = r_str_newf (R_JOIN_2_PATHS (R2_THEMES, "%s"), arg); - path = tmp ? r_str_r2_prefix (tmp) : NULL; + tmp = rz_str_newf (R_JOIN_2_PATHS (R2_THEMES, "%s"), arg); + path = tmp ? rz_str_rz_prefix (tmp) : NULL; free (tmp); if (!load_theme (core, home)) { if (load_theme (core, path)) { - curtheme = r_str_dup (curtheme, arg); + curtheme = rz_str_dup (curtheme, arg); } else { if (load_theme (core, arg)) { - curtheme = r_str_dup (curtheme, arg); + curtheme = rz_str_dup (curtheme, arg); } else { - char *absfile = r_file_abspath (arg); + char *absfile = rz_file_abspath (arg); eprintf ("eco: cannot open colorscheme profile (%s)\n", absfile); free (absfile); failed = true; @@ -157,34 +157,34 @@ static bool cmd_load_theme(RCore *core, const char *_arg) { return !failed; } -static void list_themes_in_path(RList *list, const char *path) { - RListIter *iter; +static void list_themes_in_path(RzList *list, const char *path) { + RzListIter *iter; const char *fn; - RList *files = r_sys_dir (path); - r_list_foreach (files, iter, fn) { + RzList *files = rz_sys_dir (path); + rz_list_foreach (files, iter, fn) { if (*fn && *fn != '.') { - r_list_append (list, strdup (fn)); + rz_list_append (list, strdup (fn)); } } - r_list_free (files); + rz_list_free (files); } -R_API char *r_core_get_theme (void) { +RZ_API char *rz_core_get_theme (void) { return curtheme; } -R_API RList *r_core_list_themes(RCore *core) { - RList *list = r_list_newf (free); +RZ_API RzList *rz_core_list_themes(RzCore *core) { + RzList *list = rz_list_newf (free); getNext = false; char *tmp = strdup ("default"); - r_list_append (list, tmp); - char *path = r_str_home (R2_HOME_THEMES R_SYS_DIR); + rz_list_append (list, tmp); + char *path = rz_str_home (R2_HOME_THEMES R_SYS_DIR); if (path) { list_themes_in_path (list, path); R_FREE (path); } - path = r_str_r2_prefix (R2_THEMES R_SYS_DIR); + path = rz_str_rz_prefix (R2_THEMES R_SYS_DIR); if (path) { list_themes_in_path (list, path); R_FREE (path); @@ -193,33 +193,33 @@ R_API RList *r_core_list_themes(RCore *core) { return list; } -static void nextpal(RCore *core, int mode) { -// TODO: use r_core_list_themes() here instead of rewalking all the time - RList *files = NULL; - RListIter *iter; +static void nextpal(RzCore *core, int mode) { +// TODO: use rz_core_list_themes() here instead of rewalking all the time + RzList *files = NULL; + RzListIter *iter; const char *fn; char *path = NULL; int ctr = 0; - char *home = r_str_home (R2_HOME_THEMES R_SYS_DIR); + char *home = rz_str_home (R2_HOME_THEMES R_SYS_DIR); getNext = false; if (mode == 'j') { - r_cons_printf ("["); + rz_cons_printf ("["); } if (home) { - files = r_sys_dir (home); - r_list_foreach (files, iter, fn) { + files = rz_sys_dir (home); + rz_list_foreach (files, iter, fn) { if (*fn && *fn != '.') { if (mode == 'p') { const char *nfn = iter->n? iter->n->data: NULL; if (!curtheme) { free (home); - r_list_free (files); + rz_list_free (files); return; } eprintf ("%s %s %s\n", nfn, curtheme, fn); if (nfn && !strcmp (nfn, curtheme)) { - r_list_free (files); + rz_list_free (files); files = NULL; free (curtheme); curtheme = strdup (fn); @@ -228,7 +228,7 @@ static void nextpal(RCore *core, int mode) { } } else { if (!nextpal_item (core, mode, fn, ctr++)) { - r_list_free (files); + rz_list_free (files); files = NULL; R_FREE (home); goto done; @@ -236,20 +236,20 @@ static void nextpal(RCore *core, int mode) { } } } - r_list_free (files); + rz_list_free (files); R_FREE (home); } - path = r_str_r2_prefix (R2_THEMES R_SYS_DIR); + path = rz_str_rz_prefix (R2_THEMES R_SYS_DIR); if (path) { - files = r_sys_dir (path); - r_list_foreach (files, iter, fn) { + files = rz_sys_dir (path); + rz_list_foreach (files, iter, fn) { if (*fn && *fn != '.') { if (mode == 'p') { const char *nfn = iter->n? iter->n->data: NULL; if (!curtheme) { free (home); - r_list_free (files); + rz_list_free (files); return; } eprintf ("%s %s %s\n", nfn, curtheme, fn); @@ -274,60 +274,60 @@ done: nextpal (core, mode); return; } - if (mode == 'l' && !curtheme && !r_list_empty (files)) { + if (mode == 'l' && !curtheme && !rz_list_empty (files)) { //nextpal (core, mode); } else if (mode == 'n' || mode == 'p') { if (curtheme) { - r_core_cmdf (core, "eco %s", curtheme); + rz_core_cmdf (core, "eco %s", curtheme); } } - r_list_free (files); + rz_list_free (files); files = NULL; if (mode == 'j') { - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); } } -R_API void r_core_echo(RCore *core, const char *input) { +RZ_API void rz_core_echo(RzCore *core, const char *input) { if (!strncmp (input, "64 ", 3)) { char *buf = strdup (input); - r_base64_decode ((ut8*)buf, input + 3, -1); + rz_base64_decode ((ut8*)buf, input + 3, -1); if (*buf) { - r_cons_echo (buf); + rz_cons_echo (buf); } free (buf); } else { char *p = strchr (input, ' '); if (p) { - r_cons_strcat (p + 1); - r_cons_newline (); + rz_cons_strcat (p + 1); + rz_cons_newline (); } } } static int cmd_eval(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (input[0]) { case '\0': // "e" - r_config_list (core->config, NULL, 0); + rz_config_list (core->config, NULL, 0); break; case '?': // "e?" default: switch (input[1]) { - case '\0': r_core_cmd_help (core, help_msg_e); break; - case '?': r_config_list (core->config, input + 2, 2); break; - default: r_config_list (core->config, input + 1, 2); break; + case '\0': rz_core_cmd_help (core, help_msg_e); break; + case '?': rz_config_list (core->config, input + 2, 2); break; + default: rz_config_list (core->config, input + 1, 2); break; } break; case 't': // "et" if (input[1] == 'a') { - r_cons_printf ("%s\n", (r_num_rand (10) % 2)? "wen": "son"); + rz_cons_printf ("%s\n", (rz_num_rand (10) % 2)? "wen": "son"); } else if (input[1]==' ' && input[2]) { - RConfigNode *node = r_config_node_get (core->config, input+2); + RConfigNode *node = rz_config_node_get (core->config, input+2); if (node) { - const char *type = r_config_node_type (node); + const char *type = rz_config_node_type (node); if (type && *type) { - r_cons_println (type); + rz_cons_println (type); } } } else { @@ -339,14 +339,14 @@ static int cmd_eval(void *data, const char *input) { char *var, *p; var = strchr (input, ' '); if (var) while (*var==' ') var++; - p = r_sys_getenv (var); + p = rz_sys_getenv (var); if (p) { - r_cons_println (p); + rz_cons_println (p); free (p); } else { - char **e = r_sys_get_environ (); + char **e = rz_sys_get_environ (); while (e && *e) { - r_cons_println (*e); + rz_cons_println (*e); e++; } } @@ -356,9 +356,9 @@ static int cmd_eval(void *data, const char *input) { v = strchr (k, '='); if (v) { *v++ = 0; - r_str_trim (k); - r_str_trim (v); - r_sys_setenv (k, v); + rz_str_trim (k); + rz_str_trim (v); + rz_sys_setenv (k, v); } free (k); } @@ -367,21 +367,21 @@ static int cmd_eval(void *data, const char *input) { // XXX we need headers for the cmd_xxx files. return cmd_quit (data, ""); case 'j': // json - r_config_list (core->config, NULL, 'j'); + rz_config_list (core->config, NULL, 'j'); break; case 'v': // verbose - r_config_list (core->config, input + 1, 'v'); + rz_config_list (core->config, input + 1, 'v'); break; case 'q': // quiet list of eval keys - r_config_list (core->config, NULL, 'q'); + rz_config_list (core->config, NULL, 'q'); break; case 'c': // "ec" switch (input[1]) { case 'd': // "ecd" - r_cons_pal_init (core->cons->context); + rz_cons_pal_init (core->cons->context); break; case '?': - r_core_cmd_help (core, help_msg_ec); + rz_core_cmd_help (core, help_msg_ec); break; case 'o': // "eco" if (input[2] == 'j') { @@ -389,51 +389,51 @@ static int cmd_eval(void *data, const char *input) { } else if (input[2] == ' ') { cmd_load_theme (core, input + 3); } else if (input[2] == 'o') { - cmd_load_theme (core, r_core_get_theme ()); + cmd_load_theme (core, rz_core_get_theme ()); } else if (input[2] == 'c' || input[2] == '.') { - r_cons_printf ("%s\n", r_core_get_theme ()); + rz_cons_printf ("%s\n", rz_core_get_theme ()); } else if (input[2] == '?') { - r_core_cmd_help (core, help_msg_eco); + rz_core_cmd_help (core, help_msg_eco); } else if (input[2] == 'q') { - RList *themes_list = r_core_list_themes (core); - RListIter *th_iter; + RzList *themes_list = rz_core_list_themes (core); + RzListIter *th_iter; const char *th; - r_list_foreach (themes_list, th_iter, th) { - r_cons_printf ("%s\n", th); + rz_list_foreach (themes_list, th_iter, th) { + rz_cons_printf ("%s\n", th); } } else { - RList *themes_list = r_core_list_themes (core); - RListIter *th_iter; + RzList *themes_list = rz_core_list_themes (core); + RzListIter *th_iter; const char *th; - r_list_foreach (themes_list, th_iter, th) { + rz_list_foreach (themes_list, th_iter, th) { if (curtheme && !strcmp (curtheme, th)) { - r_cons_printf ("> %s\n", th); + rz_cons_printf ("> %s\n", th); } else { - r_cons_printf (" %s\n", th); + rz_cons_printf (" %s\n", th); } } } break; - case 's': r_cons_pal_show (); break; // "ecs" - case '*': r_cons_pal_list (1, NULL); break; // "ec*" + case 's': rz_cons_pal_show (); break; // "ecs" + case '*': rz_cons_pal_list (1, NULL); break; // "ec*" case 'h': // echo if (input[2] == 'o') { - r_core_echo (core, input + 3); + rz_core_echo (core, input + 3); } else { - r_cons_pal_list ('h', NULL); + rz_cons_pal_list ('h', NULL); } break; case 'j': // "ecj" - r_cons_pal_list ('j', NULL); + rz_cons_pal_list ('j', NULL); break; case 'c': // "ecc" - r_cons_pal_list ('c', input + 2); + rz_cons_pal_list ('c', input + 2); break; case '\0': // "ec" - r_cons_pal_list (0, NULL); + rz_cons_pal_list (0, NULL); break; case 'r': // "ecr" - r_cons_pal_random (); + rz_cons_pal_random (); break; case 'n': // "ecn" nextpal (core, 'n'); @@ -446,7 +446,7 @@ static int cmd_eval(void *data, const char *input) { char *word = NULL; int argc = 0; int delta = (input[2])? 3: 2; - char** argv = r_str_argv (r_str_trim_head_ro (input + delta), &argc); + char** argv = rz_str_argv (rz_str_trim_head_ro (input + delta), &argc); switch (input[2]) { case '?': { const char *helpmsg[] = { @@ -459,44 +459,44 @@ static int cmd_eval(void *data, const char *input) { "ecH-","","remove all highlights on current instruction", NULL }; - r_core_cmd_help (core, helpmsg); + rz_core_cmd_help (core, helpmsg); } - r_str_argv_free (argv); + rz_str_argv_free (argv); return false; case '-': // ecH- if (input[3] == '*') { - r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, 0, UT64_MAX); + rz_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, 0, UT64_MAX); } else { - r_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, 1); - // r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, ""); + rz_meta_del (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, 1); + // rz_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, ""); } - r_str_argv_free (argv); + rz_str_argv_free (argv); return false; case '.': - r_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset); - r_str_argv_free (argv); + rz_meta_print_list_in_function (core->anal, R_META_TYPE_HIGHLIGHT, 0, core->offset); + rz_str_argv_free (argv); return false; case '\0': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0); - r_str_argv_free (argv); + rz_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 0); + rz_str_argv_free (argv); return false; case 'j': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j'); - r_str_argv_free (argv); + rz_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, 'j'); + rz_str_argv_free (argv); return false; case '*': - r_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*'); - r_str_argv_free (argv); + rz_meta_print_list_all (core->anal, R_META_TYPE_HIGHLIGHT, '*'); + rz_str_argv_free (argv); return false; case ' ': case 'i': // "ecHi" if (argc) { - char *dup = r_str_newf ("bgonly %s", argv[0]); - color_code = r_cons_pal_parse (dup, NULL); + char *dup = rz_str_newf ("bgonly %s", argv[0]); + color_code = rz_cons_pal_parse (dup, NULL); R_FREE (dup); if (!color_code) { eprintf ("Unknown color %s\n", argv[0]); - r_str_argv_free (argv); + rz_str_argv_free (argv); return true; } } @@ -504,17 +504,17 @@ static int cmd_eval(void *data, const char *input) { case 'w': // "ecHw" if (!argc) { eprintf ("Usage: ecHw word [color]\n"); - r_str_argv_free (argv); + rz_str_argv_free (argv); return true; } word = strdup (argv[0]); if (argc > 1) { - char *dup = r_str_newf ("bgonly %s", argv[1]); - color_code = r_cons_pal_parse (dup, NULL); + char *dup = rz_str_newf ("bgonly %s", argv[1]); + color_code = rz_cons_pal_parse (dup, NULL); R_FREE (dup); if (!color_code) { eprintf ("Unknown color %s\n", argv[1]); - r_str_argv_free (argv); + rz_str_argv_free (argv); free (word); return true; } @@ -522,14 +522,14 @@ static int cmd_eval(void *data, const char *input) { break; default: eprintf ("See ecH?\n"); - r_str_argv_free (argv); + rz_str_argv_free (argv); return true; } - r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, ""); - const char *str = r_meta_get_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset); - char *dup = r_str_newf ("%s \"%s%s\"", str?str:"", word?word:"", color_code?color_code:r_cons_singleton ()->context->pal.wordhl); - r_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, dup); - r_str_argv_free (argv); + rz_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, ""); + const char *str = rz_meta_get_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset); + char *dup = rz_str_newf ("%s \"%s%s\"", str?str:"", word?word:"", color_code?color_code:rz_cons_singleton ()->context->pal.wordhl); + rz_meta_set_string (core->anal, R_META_TYPE_HIGHLIGHT, core->offset, dup); + rz_str_argv_free (argv); R_FREE (word); R_FREE (dup); break; @@ -543,13 +543,13 @@ static int cmd_eval(void *data, const char *input) { if (q) { // Set color *q++ = 0; - if (r_cons_pal_set (p, q)) { - r_cons_pal_update_event (); + if (rz_cons_pal_set (p, q)) { + rz_cons_pal_update_event (); } } else { char color[32]; - RColor rcolor = r_cons_pal_get (p); - r_cons_rgb_str (color, sizeof (color), &rcolor); + RColor rcolor = rz_cons_pal_get (p); + rz_cons_rgb_str (color, sizeof (color), &rcolor); eprintf ("(%s)(%sCOLOR"Color_RESET")\n", p, color); } free (p); @@ -558,27 +558,27 @@ static int cmd_eval(void *data, const char *input) { break; case 'd': // "ed" if (input[1] == '?') { - eprintf ("Usage: ed[-][?] - edit ~/.radare2rc with cfg.editor\n"); + eprintf ("Usage: ed[-][?] - edit ~/.rizinrc with cfg.editor\n"); eprintf ("NOTE: ~ is HOME and this can be changed with %%HOME=/tmp\n"); - eprintf (" ed : ${cfg.editor} ~/.radare2rc\n"); - eprintf (" ed- : rm ~/.radare2rc\n"); + eprintf (" ed : ${cfg.editor} ~/.rizinrc\n"); + eprintf (" ed- : rm ~/.rizinrc\n"); } else if (input[1] == '-') { - char *file = r_str_home (".radare2rc"); - r_cons_printf ("rm %s\n", file); - // r_file_rm (file); + char *file = rz_str_home (".rizinrc"); + rz_cons_printf ("rm %s\n", file); + // rz_file_rm (file); free (file); } else { - char *file = r_str_home (".radare2rc"); - if (r_cons_is_interactive ()) { - r_file_touch (file); - char * res = r_cons_editor (file, NULL); + char *file = rz_str_home (".rizinrc"); + if (rz_cons_is_interactive ()) { + rz_file_touch (file); + char * res = rz_cons_editor (file, NULL); if (res) { - if (r_cons_yesno ('y', "Reload? (Y/n)")) { - r_core_run_script (core, file); + if (rz_cons_yesno ('y', "Reload? (Y/n)")) { + rz_core_run_script (core, file); } } } else { - r_core_run_script (core, file); + rz_core_run_script (core, file); } free (file); } @@ -588,36 +588,36 @@ static int cmd_eval(void *data, const char *input) { char *p; const char *input2 = strchr (input + 2, ' '); input2 = (input2) ? input2 + 1 : input + 2; - const char *val = r_config_get (core->config, input2); - p = r_core_editor (core, NULL, val); + const char *val = rz_config_get (core->config, input2); + p = rz_core_editor (core, NULL, val); if (p) { - r_str_replace_char (p, '\n', ';'); - r_config_set (core->config, input2, p); + rz_str_replace_char (p, '\n', ';'); + rz_config_set (core->config, input2, p); } } else { eprintf ("Usage: ee varname # use $EDITOR to edit this config value\n"); } break; case '!': // "e!" - input = r_str_trim_head_ro (input + 1); - if (!r_config_toggle (core->config, input)) { - eprintf ("r_config: '%s' is not a boolean variable.\n", input); + input = rz_str_trim_head_ro (input + 1); + if (!rz_config_toggle (core->config, input)) { + eprintf ("rz_config: '%s' is not a boolean variable.\n", input); } break; case 's': // "es" - r_config_list (core->config, (input[1])? input + 1: NULL, 's'); + rz_config_list (core->config, (input[1])? input + 1: NULL, 's'); break; case '-': // "e-" - r_core_config_init (core); + rz_core_config_init (core); //eprintf ("BUG: 'e-' command locks the eval hashtable. patches are welcome :)\n"); break; case '*': // "e*" - r_config_list (core->config, NULL, 1); + rz_config_list (core->config, NULL, 1); break; case 'r': // "er" if (input[1]) { const char *key = input + ((input[1] == ' ')? 2: 1); - if (!r_config_readonly (core->config, key)) { + if (!rz_config_readonly (core->config, key)) { eprintf ("cannot find key '%s'\n", key); } } else { @@ -625,15 +625,15 @@ static int cmd_eval(void *data, const char *input) { } break; case ',': // "e." - r_config_eval (core->config, input + 1, true); + rz_config_eval (core->config, input + 1, true); break; case '.': // "e " case ' ': // "e " - if (r_str_endswith (input, ".")) { - r_config_list (core->config, input + 1, 0); + if (rz_str_endswith (input, ".")) { + rz_config_list (core->config, input + 1, 0); } else { // XXX we cant do "e cmd.gprompt=dr=", because the '=' is a token, and quotes dont affect him - r_config_eval (core->config, input + 1, false); + rz_config_eval (core->config, input + 1, false); } break; } diff --git a/libr/core/cmd_flag.c b/librz/core/cmd_flag.c similarity index 64% rename from libr/core/cmd_flag.c rename to librz/core/cmd_flag.c index 1fd1995ac0..519ef346d5 100644 --- a/libr/core/cmd_flag.c +++ b/librz/core/cmd_flag.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ #include -#include "r_cons.h" -#include "r_core.h" +#include "rz_cons.h" +#include "rz_core.h" static const char *help_msg_f[] = { "Usage: f","[?] [flagname]", " # Manage offset-name flags", @@ -102,7 +102,7 @@ static const char *help_msg_fz[] = { NULL }; -static void cmd_flag_init(RCore *core, RCmdDesc *parent) { +static void cmd_flag_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, f); DEFINE_CMD_DESCRIPTOR (core, fc); DEFINE_CMD_DESCRIPTOR (core, fd); @@ -110,8 +110,8 @@ static void cmd_flag_init(RCore *core, RCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, fz); } -static bool listFlag(RFlagItem *flag, void *user) { - r_list_append (user, flag); +static bool listFlag(RzFlagItem *flag, void *user) { + rz_list_append (user, flag); return true; } @@ -126,13 +126,13 @@ static size_t countMatching (const char *a, const char *b) { return matches; } -static const char *__isOnlySon(RCore *core, RList *flags, const char *kw) { - RListIter *iter; - RFlagItem *f; +static const char *__isOnlySon(RzCore *core, RzList *flags, const char *kw) { + RzListIter *iter; + RzFlagItem *f; size_t count = 0; char *fname = NULL; - r_list_foreach (flags, iter, f) { + rz_list_foreach (flags, iter, f) { if (!strncmp (f->name, kw, strlen (kw))) { count++; if (count > 1) { @@ -144,26 +144,26 @@ static const char *__isOnlySon(RCore *core, RList *flags, const char *kw) { return fname; } -static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { - RList *list = r_list_newf (free); - RListIter *iter, *iter2; - RFlagItem *f, *f2; +static RzList *__childrenFlagsOf(RzCore *core, RzList *flags, const char *prefix) { + RzList *list = rz_list_newf (free); + RzListIter *iter, *iter2; + RzFlagItem *f, *f2; char *fn; const size_t prefix_len = strlen (prefix); - r_list_foreach (flags, iter, f) { + rz_list_foreach (flags, iter, f) { if (prefix_len > 0 && strncmp (f->name, prefix, prefix_len)) { continue; } if (prefix_len > strlen (f->name)) { continue; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } const char *name = f->name; int name_len = strlen (name); - r_list_foreach (flags, iter2, f2) { + rz_list_foreach (flags, iter2, f2) { if (prefix_len > strlen (f2->name)) { continue; } @@ -181,7 +181,7 @@ static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { name_len = matching; } } - char *kw = r_str_ndup (name, name_len + 1); + char *kw = rz_str_ndup (name, name_len + 1); const int kw_len = strlen (kw); const char *only = __isOnlySon (core, flags, kw); if (only) { @@ -190,7 +190,7 @@ static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { } else { const char *fname = NULL; size_t fname_len = 0; - r_list_foreach (flags, iter2, f2) { + rz_list_foreach (flags, iter2, f2) { if (strncmp (f2->name, kw, kw_len)) { continue; } @@ -209,12 +209,12 @@ static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { } if (fname_len > 0) { free (kw); - kw = r_str_ndup (fname, fname_len); + kw = rz_str_ndup (fname, fname_len); } } bool found = false; - r_list_foreach (list, iter2, fn) { + rz_list_foreach (list, iter2, fn) { if (!strcmp (fn, kw)) { found = true; break; @@ -224,7 +224,7 @@ static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { free (kw); } else { if (strcmp (prefix, kw)) { - r_list_append (list, kw); + rz_list_append (list, kw); } else { free (kw); } @@ -233,54 +233,54 @@ static RList *__childrenFlagsOf(RCore *core, RList *flags, const char *prefix) { return list; } -static void __printRecursive (RCore *core, RList *list, const char *prefix, int mode, int depth); +static void __printRecursive (RzCore *core, RzList *list, const char *prefix, int mode, int depth); -static void __printRecursive (RCore *core, RList *flags, const char *prefix, int mode, int depth) { +static void __printRecursive (RzCore *core, RzList *flags, const char *prefix, int mode, int depth) { char *fn; - RListIter *iter; + RzListIter *iter; const int prefix_len = strlen (prefix); // eprintf ("# fg %s\n", prefix); if (mode == '*' && !*prefix) { - r_cons_printf ("agn root\n"); + rz_cons_printf ("agn root\n"); } - if (r_flag_get (core->flags, prefix)) { + if (rz_flag_get (core->flags, prefix)) { return; } - RList *children = __childrenFlagsOf (core, flags, prefix); - r_list_foreach (children, iter, fn) { + RzList *children = __childrenFlagsOf (core, flags, prefix); + rz_list_foreach (children, iter, fn) { if (!strcmp (fn, prefix)) { continue; } if (mode == '*') { - r_cons_printf ("agn %s %s\n", fn, fn + prefix_len); - r_cons_printf ("age %s %s\n", *prefix? prefix: "root", fn); + rz_cons_printf ("agn %s %s\n", fn, fn + prefix_len); + rz_cons_printf ("age %s %s\n", *prefix? prefix: "root", fn); } else { - r_cons_printf ("%s %s\n", r_str_pad (' ', prefix_len), fn + prefix_len); + rz_cons_printf ("%s %s\n", rz_str_pad (' ', prefix_len), fn + prefix_len); } - //r_cons_printf (".fg %s\n", fn); + //rz_cons_printf (".fg %s\n", fn); __printRecursive (core, flags, fn, mode, depth+1); } - r_list_free (children); + rz_list_free (children); } -static void __flag_graph (RCore *core, const char *input, int mode) { - RList *flags = r_list_newf (NULL); - r_flag_foreach_space (core->flags, r_flag_space_cur (core->flags), listFlag, flags); +static void __flag_graph (RzCore *core, const char *input, int mode) { + RzList *flags = rz_list_newf (NULL); + rz_flag_foreach_space (core->flags, rz_flag_space_cur (core->flags), listFlag, flags); __printRecursive (core, flags, input, mode, 0); - r_list_free (flags); + rz_list_free (flags); } static void spaces_list(RSpaces *sp, int mode) { RSpaceIter it; RSpace *s; - const RSpace *cur = r_spaces_current (sp); + const RSpace *cur = rz_spaces_current (sp); PJ *pj = NULL; if (mode == 'j') { pj = pj_new (); pj_a (pj); } - r_spaces_foreach (sp, it, s) { - int count = r_spaces_count (sp, s->name); + rz_spaces_foreach (sp, it, s) { + int count = rz_spaces_count (sp, s->name); if (mode == 'j') { pj_o (pj); pj_ks (pj, "name", s->name); @@ -288,113 +288,113 @@ static void spaces_list(RSpaces *sp, int mode) { pj_kb (pj, "selected", cur == s); pj_end (pj); } else if (mode == 'q') { - r_cons_printf ("%s\n", s->name); + rz_cons_printf ("%s\n", s->name); } else if (mode == '*') { - r_cons_printf ("%s %s\n", sp->name, s->name); + rz_cons_printf ("%s %s\n", sp->name, s->name); } else { - r_cons_printf ("%5d %c %s\n", count, (!cur || cur == s)? '*': '.', + rz_cons_printf ("%5d %c %s\n", count, (!cur || cur == s)? '*': '.', s->name); } } - if (mode == '*' && r_spaces_current (sp)) { - r_cons_printf ("%s %s # current\n", sp->name, r_spaces_current_name (sp)); + if (mode == '*' && rz_spaces_current (sp)) { + rz_cons_printf ("%s %s # current\n", sp->name, rz_spaces_current_name (sp)); } if (mode == 'j') { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } -static void cmd_fz(RCore *core, const char *input) { +static void cmd_fz(RzCore *core, const char *input) { switch (*input) { case '?': // "fz?" - r_core_cmd_help (core, help_msg_fz); + rz_core_cmd_help (core, help_msg_fz); break; case '.': // "fz." { const char *a = NULL, *b = NULL; - r_flag_zone_around (core->flags, core->offset, &a, &b); - r_cons_printf ("%s %s\n", a?a:"~", b?b:"~"); + rz_flag_zone_around (core->flags, core->offset, &a, &b); + rz_cons_printf ("%s %s\n", a?a:"~", b?b:"~"); } break; case ':': // "fz:" { const char *a, *b; int a_len = 0; - int w = r_cons_get_size (NULL); - r_flag_zone_around (core->flags, core->offset, &a, &b); + int w = rz_cons_get_size (NULL); + rz_flag_zone_around (core->flags, core->offset, &a, &b); if (a) { - r_cons_printf ("[<< %s]", a); + rz_cons_printf ("[<< %s]", a); a_len = strlen (a) + 4; } int padsize = (w / 2) - a_len; int title_size = 12; if (a || b) { - char *title = r_str_newf ("[ 0x%08"PFMT64x" ]", core->offset); + char *title = rz_str_newf ("[ 0x%08"PFMT64x" ]", core->offset); title_size = strlen (title); padsize -= strlen (title) / 2; - const char *halfpad = r_str_pad (' ', padsize); - r_cons_printf ("%s%s", halfpad, title); + const char *halfpad = rz_str_pad (' ', padsize); + rz_cons_printf ("%s%s", halfpad, title); free (title); } if (b) { padsize = (w / 2) - title_size - strlen (b) - 4; - const char *halfpad = padsize > 1? r_str_pad (' ', padsize): ""; - r_cons_printf ("%s[%s >>]", halfpad, b); + const char *halfpad = padsize > 1? rz_str_pad (' ', padsize): ""; + rz_cons_printf ("%s[%s >>]", halfpad, b); } if (a || b) { - r_cons_newline(); + rz_cons_newline(); } } break; case ' ': - r_flag_zone_add (core->flags, r_str_trim_head_ro (input + 1), core->offset); + rz_flag_zone_add (core->flags, rz_str_trim_head_ro (input + 1), core->offset); break; case '-': if (input[1] == '*') { - r_flag_zone_reset (core->flags); + rz_flag_zone_reset (core->flags); } else { - r_flag_zone_del (core->flags, input + 1); + rz_flag_zone_del (core->flags, input + 1); } break; case '*': - r_flag_zone_list (core->flags, '*'); + rz_flag_zone_list (core->flags, '*'); break; case 0: - r_flag_zone_list (core->flags, 0); + rz_flag_zone_list (core->flags, 0); break; } } struct flagbar_t { - RCore *core; + RzCore *core; int cols; }; -static bool flagbar_foreach(RFlagItem *fi, void *user) { +static bool flagbar_foreach(RzFlagItem *fi, void *user) { struct flagbar_t *u = (struct flagbar_t *)user; - ut64 min = 0, max = r_io_size (u->core->io); - RIOMap *m = r_io_map_get (u->core->io, fi->offset); + ut64 min = 0, max = rz_io_size (u->core->io); + RzIOMap *m = rz_io_map_get (u->core->io, fi->offset); if (m) { min = m->itv.addr; max = m->itv.addr + m->itv.size; } - r_cons_printf ("0x%08"PFMT64x" ", fi->offset); - r_print_rangebar (u->core->print, fi->offset, fi->offset + fi->size, min, max, u->cols); - r_cons_printf (" %s\n", fi->name); + rz_cons_printf ("0x%08"PFMT64x" ", fi->offset); + rz_print_rangebar (u->core->print, fi->offset, fi->offset + fi->size, min, max, u->cols); + rz_cons_printf (" %s\n", fi->name); return true; } -static void flagbars(RCore *core, const char *glob) { - int cols = r_cons_get_size (NULL); +static void flagbars(RzCore *core, const char *glob) { + int cols = rz_cons_get_size (NULL); cols -= 80; if (cols < 0) { cols += 80; } struct flagbar_t u = { .core = core, .cols = cols }; - r_flag_foreach_space_glob (core->flags, glob, r_flag_space_cur (core->flags), flagbar_foreach, &u); + rz_flag_foreach_space_glob (core->flags, glob, rz_flag_space_cur (core->flags), flagbar_foreach, &u); } struct flag_to_flag_t { @@ -402,7 +402,7 @@ struct flag_to_flag_t { ut64 offset; }; -static bool flag_to_flag_foreach(RFlagItem *fi, void *user) { +static bool flag_to_flag_foreach(RzFlagItem *fi, void *user) { struct flag_to_flag_t *u = (struct flag_to_flag_t *)user; if (fi->offset < u->next && fi->offset > u->offset) { u->next = fi->offset; @@ -410,11 +410,11 @@ static bool flag_to_flag_foreach(RFlagItem *fi, void *user) { return true; } -static int flag_to_flag(RCore *core, const char *glob) { - r_return_val_if_fail (glob, 0); - glob = r_str_trim_head_ro (glob); +static int flag_to_flag(RzCore *core, const char *glob) { + rz_return_val_if_fail (glob, 0); + glob = rz_str_trim_head_ro (glob); struct flag_to_flag_t u = { .next = UT64_MAX, .offset = core->offset }; - r_flag_foreach_glob (core->flags, glob, flag_to_flag_foreach, &u); + rz_flag_foreach_glob (core->flags, glob, flag_to_flag_foreach, &u); if (u.next != UT64_MAX && u.next > core->offset) { return u.next - core->offset; } @@ -425,56 +425,56 @@ typedef struct { RTable *t; } FlagTableData; -static bool __tableItemCallback(RFlagItem *flag, void *user) { +static bool __tableItemCallback(RzFlagItem *flag, void *user) { FlagTableData *ftd = user; if (!R_STR_ISEMPTY (flag->name)) { RTable *t = ftd->t; const char *spaceName = (flag->space && flag->space->name)? flag->space->name: ""; const char *addr = sdb_fmt ("0x%08"PFMT64x, flag->offset); - r_table_add_row (t, addr, sdb_fmt ("%d", flag->size), spaceName, flag->name, NULL); + rz_table_add_row (t, addr, sdb_fmt ("%d", flag->size), spaceName, flag->name, NULL); } return true; } -static void cmd_flag_table(RCore *core, const char *input) { +static void cmd_flag_table(RzCore *core, const char *input) { const char fmt = *input++; const char *q = input; FlagTableData ftd = {0}; - RTable *t = r_core_table (core); + RTable *t = rz_core_table (core); ftd.t = t; - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - r_table_add_column (t, typeNumber, "addr", 0); - r_table_add_column (t, typeNumber, "size", 0); - r_table_add_column (t, typeString, "space", 0); - r_table_add_column (t, typeString, "name", 0); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + rz_table_add_column (t, typeNumber, "addr", 0); + rz_table_add_column (t, typeNumber, "size", 0); + rz_table_add_column (t, typeString, "space", 0); + rz_table_add_column (t, typeString, "name", 0); - RSpace *curSpace = r_flag_space_cur (core->flags); - r_flag_foreach_space (core->flags, curSpace, __tableItemCallback, &ftd); - if (r_table_query (t, q)) { + RSpace *curSpace = rz_flag_space_cur (core->flags); + rz_flag_foreach_space (core->flags, curSpace, __tableItemCallback, &ftd); + if (rz_table_query (t, q)) { char *s = (fmt == 'j') - ? r_table_tojson (t) - : r_table_tostring (t); - r_cons_printf ("%s\n", s); + ? rz_table_tojson (t) + : rz_table_tostring (t); + rz_cons_printf ("%s\n", s); free (s); } - r_table_free (t); + rz_table_free (t); } -static void cmd_flag_tags(RCore *core, const char *input) { +static void cmd_flag_tags(RzCore *core, const char *input) { char mode = input[1]; for (; *input && !IS_WHITESPACE (*input); input++) {} char *inp = strdup (input); char *arg = inp; - r_str_trim (arg); + rz_str_trim (arg); if (!*arg && !mode) { const char *tag; - RListIter *iter; - RList *list = r_flag_tags_list (core->flags, NULL); - r_list_foreach (list, iter, tag) { - r_cons_printf ("%s\n", tag); + RzListIter *iter; + RzList *list = rz_flag_tags_list (core->flags, NULL); + rz_list_foreach (list, iter, tag) { + rz_cons_printf ("%s\n", tag); } - r_list_free (list); + rz_list_free (list); free (inp); return; } @@ -492,70 +492,70 @@ static void cmd_flag_tags(RCore *core, const char *input) { } if (mode == 'w') { // "ftw" const char *tag; - RListIter *iter; - RList *list = r_flag_tags_list (core->flags, NULL); - r_list_foreach (list, iter, tag) { - r_cons_printf ("%s:\n", tag); - r_core_cmdf (core, "ftn %s", tag); + RzListIter *iter; + RzList *list = rz_flag_tags_list (core->flags, NULL); + rz_list_foreach (list, iter, tag) { + rz_cons_printf ("%s:\n", tag); + rz_core_cmdf (core, "ftn %s", tag); } - r_list_free (list); + rz_list_free (list); free (inp); return; } if (mode == '*') { - RListIter *iter; + RzListIter *iter; const char *tag; - RList *list = r_flag_tags_list (core->flags, NULL); - r_list_foreach (list, iter, tag) { + RzList *list = rz_flag_tags_list (core->flags, NULL); + rz_list_foreach (list, iter, tag) { const char *flags = sdb_get (core->flags->tags, sdb_fmt ("tag.%s", tag), NULL); - r_cons_printf ("ft %s %s\n", tag, flags); + rz_cons_printf ("ft %s %s\n", tag, flags); } - r_list_free (list); + rz_list_free (list); free (inp); return; } if (mode == 'j') { // "ftj" - RListIter *iter, *iter2; + RzListIter *iter, *iter2; const char *tag, *flg; PJ *pj = pj_new (); pj_o (pj); - RList *list = r_flag_tags_list (core->flags, NULL); - r_list_foreach (list, iter, tag) { + RzList *list = rz_flag_tags_list (core->flags, NULL); + rz_list_foreach (list, iter, tag) { pj_k (pj, tag); pj_a (pj); - RList *flags = r_flag_tags_list (core->flags, tag); - r_list_foreach (flags, iter2, flg) { + RzList *flags = rz_flag_tags_list (core->flags, tag); + rz_list_foreach (flags, iter2, flg) { pj_s (pj, flg); } pj_end (pj); - r_list_free (flags); + rz_list_free (flags); } pj_end (pj); - r_list_free (list); + rz_list_free (list); free (inp); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); return; } char *arg1 = strchr (arg, ' '); if (arg1) { *arg1 = 0; - const char *a1 = r_str_trim_head_ro (arg1 + 1); - r_flag_tags_set (core->flags, arg, a1); + const char *a1 = rz_str_trim_head_ro (arg1 + 1); + rz_flag_tags_set (core->flags, arg, a1); } else { - RListIter *iter; - RFlagItem *flag; - RList *flags = r_flag_tags_get (core->flags, arg); + RzListIter *iter; + RzFlagItem *flag; + RzList *flags = rz_flag_tags_get (core->flags, arg); switch (mode) { case 'n': - r_list_foreach (flags, iter, flag) { - // r_cons_printf ("0x%08"PFMT64x"\n", flag->offset); - r_cons_printf ("0x%08"PFMT64x" %s\n", flag->offset, flag->name); + rz_list_foreach (flags, iter, flag) { + // rz_cons_printf ("0x%08"PFMT64x"\n", flag->offset); + rz_cons_printf ("0x%08"PFMT64x" %s\n", flag->offset, flag->name); } break; default: - r_list_foreach (flags, iter, flag) { - r_cons_printf ("0x%08"PFMT64x"\n", flag->offset); + rz_list_foreach (flags, iter, flag) { + rz_cons_printf ("0x%08"PFMT64x"\n", flag->offset); } break; } @@ -564,24 +564,24 @@ static void cmd_flag_tags(RCore *core, const char *input) { } struct rename_flag_t { - RCore *core; + RzCore *core; const char *pfx; int count; }; -static bool rename_flag_ordinal(RFlagItem *fi, void *user) { +static bool rename_flag_ordinal(RzFlagItem *fi, void *user) { struct rename_flag_t *u = (struct rename_flag_t *)user; - char *newName = r_str_newf ("%s%d", u->pfx, u->count++); + char *newName = rz_str_newf ("%s%d", u->pfx, u->count++); if (!newName) { return false; } - r_flag_rename (u->core->flags, fi, newName); + rz_flag_rename (u->core->flags, fi, newName); free (newName); return true; } -static void flag_ordinals(RCore *core, const char *str) { - const char *glob = r_str_trim_head_ro (str); +static void flag_ordinals(RzCore *core, const char *str) { + const char *glob = rz_str_trim_head_ro (str); char *pfx = strdup (glob); char *p = strchr (pfx, '*'); if (p) { @@ -589,21 +589,21 @@ static void flag_ordinals(RCore *core, const char *str) { } struct rename_flag_t u = { .core = core, .pfx = pfx, .count = 0 }; - r_flag_foreach_glob (core->flags, glob, rename_flag_ordinal, &u); + rz_flag_foreach_glob (core->flags, glob, rename_flag_ordinal, &u); free (pfx); } static int cmpflag(const void *_a, const void *_b) { - const RFlagItem *flag1 = _a , *flag2 = _b; + const RzFlagItem *flag1 = _a , *flag2 = _b; return (flag1->offset - flag2->offset); } struct find_flag_t { - RFlagItem *win; + RzFlagItem *win; ut64 at; }; -static bool find_flag_after(RFlagItem *flag, void *user) { +static bool find_flag_after(RzFlagItem *flag, void *user) { struct find_flag_t *u = (struct find_flag_t *)user; if (flag->offset > u->at && (!u->win || flag->offset < u->win->offset)) { u->win = flag; @@ -611,31 +611,31 @@ static bool find_flag_after(RFlagItem *flag, void *user) { return true; } -static bool find_flag_after_foreach(RFlagItem *flag, void *user) { +static bool find_flag_after_foreach(RzFlagItem *flag, void *user) { if (flag->size != 0) { return true; } - RFlag *flags = (RFlag *)user; + RzFlag *flags = (RzFlag *)user; struct find_flag_t u = { .win = NULL, .at = flag->offset }; - r_flag_foreach (flags, find_flag_after, &u); + rz_flag_foreach (flags, find_flag_after, &u); if (u.win) { flag->size = u.win->offset - flag->offset; } return true; } -static bool adjust_offset(RFlagItem *flag, void *user) { +static bool adjust_offset(RzFlagItem *flag, void *user) { st64 base = *(st64 *)user; flag->offset += base; return true; } -static void print_space_stack(RFlag *f, int ordinal, const char *name, bool selected, PJ *pj, int mode) { +static void print_space_stack(RzFlag *f, int ordinal, const char *name, bool selected, PJ *pj, int mode) { bool first = ordinal == 0; switch (mode) { case 'j': { - char *ename = r_str_escape (name); + char *ename = rz_str_escape (name); if (!ename) { return; } @@ -650,17 +650,17 @@ static void print_space_stack(RFlag *f, int ordinal, const char *name, bool sele } case '*': { const char *fmt = first? "fs %s\n": "fs+%s\n"; - r_cons_printf (fmt, name); + rz_cons_printf (fmt, name); break; } default: - r_cons_printf ("%-2d %s%s\n", ordinal, name, selected? " (selected)": ""); + rz_cons_printf ("%-2d %s%s\n", ordinal, name, selected? " (selected)": ""); break; } } -static int flag_space_stack_list(RFlag *f, int mode) { - RListIter *iter; +static int flag_space_stack_list(RzFlag *f, int mode) { + RzListIter *iter; char *space; int i = 0; PJ *pj = NULL; @@ -668,14 +668,14 @@ static int flag_space_stack_list(RFlag *f, int mode) { pj = pj_new (); pj_a (pj); } - r_list_foreach (f->spaces.spacestack, iter, space) { + rz_list_foreach (f->spaces.spacestack, iter, space) { print_space_stack (f, i++, space, false, pj, mode); } - const char *cur_name = r_flag_space_cur_name (f); + const char *cur_name = rz_flag_space_cur_name (f); print_space_stack (f, i++, cur_name, true, pj, mode); if (mode == 'j') { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } return i; @@ -684,7 +684,7 @@ static int flag_space_stack_list(RFlag *f, int mode) { typedef struct { int rad; PJ *pj; - RAnalFunction *fcn; + RzAnalFunction *fcn; } PrintFcnLabelsCtx; static bool print_function_labels_cb(void *user, const ut64 addr, const void *v) { @@ -693,13 +693,13 @@ static bool print_function_labels_cb(void *user, const ut64 addr, const void *v) switch (ctx->rad) { case '*': case 1: - r_cons_printf ("f.%s@0x%08"PFMT64x"\n", name, addr); + rz_cons_printf ("f.%s@0x%08"PFMT64x"\n", name, addr); break; case 'j': pj_kn (ctx->pj, name, addr); break; default: - r_cons_printf ("0x%08"PFMT64x" %s [%s + %"PFMT64d"]\n", + rz_cons_printf ("0x%08"PFMT64x" %s [%s + %"PFMT64d"]\n", addr, name, ctx->fcn->name, addr - ctx->fcn->addr, addr); @@ -708,8 +708,8 @@ static bool print_function_labels_cb(void *user, const ut64 addr, const void *v) } -static void print_function_labels_for(RAnalFunction *fcn, int rad, PJ *pj) { - r_return_if_fail (fcn && (rad != 'j' || pj)); +static void print_function_labels_for(RzAnalFunction *fcn, int rad, PJ *pj) { + rz_return_if_fail (fcn && (rad != 'j' || pj)); bool json = rad == 'j'; if (json) { pj_o (pj); @@ -721,8 +721,8 @@ static void print_function_labels_for(RAnalFunction *fcn, int rad, PJ *pj) { } } -static void print_function_labels(RAnal *anal, RAnalFunction *fcn, int rad) { - r_return_if_fail (anal || fcn); +static void print_function_labels(RzAnal *anal, RzAnalFunction *fcn, int rad) { + rz_return_if_fail (anal || fcn); PJ *pj = NULL; bool json = rad == 'j'; if (json) { @@ -734,9 +734,9 @@ static void print_function_labels(RAnal *anal, RAnalFunction *fcn, int rad) { if (json) { pj_o (pj); } - RAnalFunction *f; - RListIter *iter; - r_list_foreach (anal->fcns, iter, f) { + RzAnalFunction *f; + RzListIter *iter; + rz_list_foreach (anal->fcns, iter, f) { if (!f->labels->count) { continue; } @@ -750,17 +750,17 @@ static void print_function_labels(RAnal *anal, RAnalFunction *fcn, int rad) { } } if (json) { - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } } static int cmd_flag(void *data, const char *input) { static int flagenum = 0; - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut64 off = core->offset; char *ptr, *str = NULL; - RFlagItem *item; + RzFlagItem *item; char *name = NULL; st64 base; @@ -774,17 +774,17 @@ rep: if (input[1] == 's') { // "ffs" int delta = flag_to_flag (core, input + 2); if (delta > 0) { - r_cons_printf ("0x%08"PFMT64x"\n", core->offset + delta); + rz_cons_printf ("0x%08"PFMT64x"\n", core->offset + delta); } } else { - r_cons_printf ("%d\n", flag_to_flag (core, input + 1)); + rz_cons_printf ("%d\n", flag_to_flag (core, input + 1)); } break; case 'e': // "fe" switch (input[1]) { case ' ': - ptr = r_str_newf ("%s.%d", input + 2, flagenum); - (void)r_flag_set (core->flags, ptr, core->offset, 1); + ptr = rz_str_newf ("%s.%d", input + 2, flagenum); + (void)rz_flag_set (core->flags, ptr, core->offset, 1); flagenum++; free (ptr); break; @@ -812,21 +812,21 @@ rep: break; case 'a': if (input[1] == ' '){ - RFlagItem *fi; + RzFlagItem *fi; R_FREE (str); str = strdup (input+2); ptr = strchr (str, '='); if (!ptr) ptr = strchr (str, ' '); if (ptr) *ptr++ = 0; - name = (char *)r_str_trim_head_ro (str); - ptr = (char *)r_str_trim_head_ro (ptr); - fi = r_flag_get (core->flags, name); + name = (char *)rz_str_trim_head_ro (str); + ptr = (char *)rz_str_trim_head_ro (ptr); + fi = rz_flag_get (core->flags, name); if (!fi) - fi = r_flag_set (core->flags, name, + fi = rz_flag_set (core->flags, name, core->offset, 1); if (fi) { - r_flag_item_set_alias (fi, ptr); + rz_flag_item_set_alias (fi, ptr); } else { eprintf ("Cannot find flag '%s'\n", name); } @@ -837,15 +837,15 @@ rep: case 'V': // visual marks switch(input[1]) { case '-': - r_core_visual_mark_reset (core); + rz_core_visual_mark_reset (core); break; case ' ': { const int n = atoi (input + 1); if (n + ST8_MAX + 1 < UT8_MAX) { const char *arg = strchr (input + 2, ' '); - ut64 addr = arg? r_num_math (core->num, arg): core->offset; - r_core_visual_mark_set (core, n + ST8_MAX + 1, addr); + ut64 addr = arg? rz_num_math (core->num, arg): core->offset; + rz_core_visual_mark_set (core, n + ST8_MAX + 1, addr); } } break; @@ -854,12 +854,12 @@ rep: eprintf ("Dump/Restore visual marks (mK/'K)\n"); break; default: - r_core_visual_mark_dump (core); + rz_core_visual_mark_dump (core); break; } break; case 'm': // "fm" - r_flag_move (core->flags, core->offset, r_num_math (core->num, input+1)); + rz_flag_move (core->flags, core->offset, rz_num_math (core->num, input+1)); break; case 'R': // "fR" switch(*str) { @@ -869,8 +869,8 @@ rep: " > fR entry0 `dm~:1[1]`\n"); break; case '?': - r_cons_println ("Usage: fR [from] [to] ([mask])"); - r_cons_println ("Example to relocate PIE flags on debugger:\n" + rz_cons_println ("Usage: fR [from] [to] ([mask])"); + rz_cons_println ("Example to relocate PIE flags on debugger:\n" " > fR entry0 `dm~:1[1]`"); break; default: @@ -883,11 +883,11 @@ rep: *p = 0; if (q) { *q = 0; - mask = r_num_math (core->num, q+1); + mask = rz_num_math (core->num, q+1); } - from = r_num_math (core->num, str+1); - to = r_num_math (core->num, p+1); - ret = r_flag_relocate (core->flags, from, mask, to); + from = rz_num_math (core->num, str+1); + to = rz_num_math (core->num, p+1); + ret = rz_flag_relocate (core->flags, from, mask, to); eprintf ("Relocated %d flags\n", ret); } else { eprintf ("Usage: fR [from] [to] ([mask])\n"); @@ -904,17 +904,17 @@ rep: str = strdup (input + 2); ptr = strchr (str, ' '); if (ptr) { - RFlag *f = core->flags; + RzFlag *f = core->flags; *ptr = 0; - base = r_num_math (core->num, str); - r_flag_foreach_glob (f, ptr + 1, adjust_offset, &base); + base = rz_num_math (core->num, str); + rz_flag_foreach_glob (f, ptr + 1, adjust_offset, &base); } else { - core->flags->base = r_num_math (core->num, input+1); + core->flags->base = rz_num_math (core->num, input+1); } R_FREE (str); break; case '\0': - r_cons_printf ("%"PFMT64d" 0x%"PFMT64x"\n", + rz_cons_printf ("%"PFMT64d" 0x%"PFMT64x"\n", core->flags->base, core->flags->base); break; @@ -925,7 +925,7 @@ rep: break; case '+': // "f+' case ' ': { - const char *cstr = r_str_trim_head_ro (str); + const char *cstr = rz_str_trim_head_ro (str); char* eq = strchr (cstr, '='); char* b64 = strstr (cstr, "base64:"); char* s = strchr (cstr, ' '); @@ -955,8 +955,8 @@ rep: // Check base64 padding if (eq && !(b64 && eq > b64 && (eq[1] == '\0' || (eq[1] == '=' && eq[2] == '\0')))) { *eq = 0; - ut64 arg = r_num_math (core->num, eq + 1); - RFlagItem *item = r_flag_get (core->flags, cstr); + ut64 arg = rz_num_math (core->num, eq + 1); + RzFlagItem *item = rz_flag_get (core->flags, cstr); if (eqdir && item) { off = item->offset + (arg * eqdir); } else { @@ -969,33 +969,33 @@ rep: if (s2) { *s2 = '\0'; if (s2[1] && s2[2]) { - off = r_num_math (core->num, s2 + 1); + off = rz_num_math (core->num, s2 + 1); } s3 = strchr (s2 + 1, ' '); if (s3) { *s3 = '\0'; if (!strncmp (s3 + 1, "base64:", 7)) { - comment = (char *) r_base64_decode_dyn (s3 + 8, -1); + comment = (char *) rz_base64_decode_dyn (s3 + 8, -1); comment_needs_free = true; } else if (s3[1]) { comment = s3 + 1; } } } - bsze = (s[1] == '=') ? 1 : r_num_math (core->num, s + 1); + bsze = (s[1] == '=') ? 1 : rz_num_math (core->num, s + 1); } bool addFlag = true; if (input[0] == '+') { - if ((item = r_flag_get_at (core->flags, off, false))) { + if ((item = rz_flag_get_at (core->flags, off, false))) { addFlag = false; } } if (addFlag) { - item = r_flag_set (core->flags, cstr, off, bsze); + item = rz_flag_set (core->flags, cstr, off, bsze); } if (item && comment) { - r_flag_item_set_comment (item, comment); + rz_flag_item_set_comment (item, comment); if (comment_needs_free) { free (comment); } @@ -1004,38 +1004,38 @@ rep: break; case '-': if (input[1] == '-') { - r_flag_unset_all (core->flags); + rz_flag_unset_all (core->flags); } else if (input[1]) { - const char *flagname = r_str_trim_head_ro (input + 1); + const char *flagname = rz_str_trim_head_ro (input + 1); while (*flagname==' ') { flagname++; } if (*flagname == '.') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off, 0); if (fcn) { - r_anal_function_delete_label_at (fcn, off); + rz_anal_function_delete_label_at (fcn, off); } else { eprintf ("Cannot find function at 0x%08"PFMT64x"\n", off); } } else { if (strchr (flagname, '*')) { - r_flag_unset_glob (core->flags, flagname); + rz_flag_unset_glob (core->flags, flagname); } else { - r_flag_unset_name (core->flags, flagname); + rz_flag_unset_name (core->flags, flagname); } } } else { - r_flag_unset_off (core->flags, off); + rz_flag_unset_off (core->flags, off); } break; case '.': // "f." - input = r_str_trim_head_ro (input + 1) - 1; + input = rz_str_trim_head_ro (input + 1) - 1; if (input[1]) { if (input[1] == '*' || input[1] == 'j') { if (input[2] == '*') { print_function_labels (core->anal, NULL, input[1]); } else { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off, 0); if (fcn) { print_function_labels (core->anal, fcn, input[1]); } else { @@ -1044,19 +1044,19 @@ rep: } } else { char *name = strdup (input + ((input[2] == ' ')? 2: 1)); - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off, 0); if (name) { char *eq = strchr (name, '='); if (eq) { *eq = 0; - off = r_num_math (core->num, eq + 1); + off = rz_num_math (core->num, eq + 1); } - r_str_trim (name); + rz_str_trim (name); if (fcn) { if (*name=='-') { - r_anal_function_delete_label (fcn, name + 1); + rz_anal_function_delete_label (fcn, name + 1); } else { - r_anal_function_set_label (fcn, name, off); + rz_anal_function_set_label (fcn, name, off); } } else { eprintf ("Cannot find function at 0x%08"PFMT64x"\n", off); @@ -1065,7 +1065,7 @@ rep: } } } else { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off, 0); if (fcn) { print_function_labels (core->anal, fcn, 0); } else { @@ -1082,48 +1082,48 @@ rep: if (glob) { glob++; } - r_flag_foreach_glob (core->flags, glob, find_flag_after_foreach, core->flags); + rz_flag_foreach_glob (core->flags, glob, find_flag_after_foreach, core->flags); } else if (input[1] == ' ') { // "fl ..." char *p, *arg = strdup (input + 2); - r_str_trim (arg); + rz_str_trim (arg); p = strchr (arg, ' '); if (p) { *p++ = 0; - item = r_flag_get_i (core->flags, - r_num_math (core->num, arg)); + item = rz_flag_get_i (core->flags, + rz_num_math (core->num, arg)); if (item) - item->size = r_num_math (core->num, p); + item->size = rz_num_math (core->num, p); } else { if (*arg) { - item = r_flag_get_i (core->flags, core->offset); + item = rz_flag_get_i (core->flags, core->offset); if (item) { - item->size = r_num_math (core->num, arg); + item->size = rz_num_math (core->num, arg); } } else { - item = r_flag_get_i (core->flags, r_num_math (core->num, arg)); + item = rz_flag_get_i (core->flags, rz_num_math (core->num, arg)); if (item) { - r_cons_printf ("0x%08"PFMT64x"\n", item->size); + rz_cons_printf ("0x%08"PFMT64x"\n", item->size); } } } free (arg); } else { // "fl" - item = r_flag_get_i (core->flags, core->offset); + item = rz_flag_get_i (core->flags, core->offset); if (item) - r_cons_printf ("0x%08"PFMT64x"\n", item->size); + rz_cons_printf ("0x%08"PFMT64x"\n", item->size); } break; #if 0 case 'd': if (input[1] == ' ') { char cmd[128]; - RFlagItem *item = r_flag_get_i (core->flags, - r_num_math (core->num, input+2)); + RzFlagItem *item = rz_flag_get_i (core->flags, + rz_num_math (core->num, input+2)); if (item) { - r_cons_printf ("0x%08"PFMT64x"\n", item->offset); + rz_cons_printf ("0x%08"PFMT64x"\n", item->offset); snprintf (cmd, sizeof (cmd), "pD@%"PFMT64d":%"PFMT64d, item->offset, item->size); - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } } else eprintf ("Missing arguments\n"); break; @@ -1134,13 +1134,13 @@ rep: case 'x': if (input[1] == ' ') { char cmd[128]; - RFlagItem *item = r_flag_get_i (core->flags, - r_num_math (core->num, input+2)); + RzFlagItem *item = rz_flag_get_i (core->flags, + rz_num_math (core->num, input+2)); if (item) { - r_cons_printf ("0x%08"PFMT64x"\n", item->offset); + rz_cons_printf ("0x%08"PFMT64x"\n", item->offset); snprintf (cmd, sizeof (cmd), "px@%"PFMT64d":%"PFMT64d, item->offset, item->size); - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } } else { eprintf ("Missing arguments\n"); @@ -1155,16 +1155,16 @@ rep: case 's': // "fs" switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_fs); + rz_core_cmd_help (core, help_msg_fs); break; case '+': - r_flag_space_push (core->flags, input+2); + rz_flag_space_push (core->flags, input+2); break; case 'r': if (input[2] ==' ') { char *newname = strdup (input + 3); - r_str_trim (newname); - r_flag_space_rename (core->flags, NULL, newname); + rz_str_trim (newname); + rz_flag_space_rename (core->flags, NULL, newname); free (newname); } else { eprintf ("Usage: fsr [newname]\n"); @@ -1176,40 +1176,40 @@ rep: case '-': switch (input[2]) { case '*': - r_flag_space_unset (core->flags, NULL); + rz_flag_space_unset (core->flags, NULL); break; case '.': { - const RSpace *sp = r_flag_space_cur (core->flags); + const RSpace *sp = rz_flag_space_cur (core->flags); if (sp) { - r_flag_space_unset (core->flags, sp->name); + rz_flag_space_unset (core->flags, sp->name); } break; } case 0: - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); break; default: - r_flag_space_unset (core->flags, input+2); + rz_flag_space_unset (core->flags, input+2); break; } break; case ' ': { char *name = strdup (input + 2); - r_str_trim (name); - r_flag_space_set (core->flags, name); + rz_str_trim (name); + rz_flag_space_set (core->flags, name); free (name); break; } case 'm': - { RFlagItem *f; + { RzFlagItem *f; ut64 off = core->offset; if (input[2] == ' ') { - off = r_num_math (core->num, input+2); + off = rz_num_math (core->num, input+2); } - f = r_flag_get_i (core->flags, off); + f = rz_flag_get_i (core->flags, off); if (f) { - f->space = r_flag_space_cur (core->flags); + f->space = rz_flag_space_cur (core->flags); } else { eprintf ("Cannot find any flag at 0x%"PFMT64x".\n", off); } @@ -1229,13 +1229,13 @@ rep: case 'g': // "fg" switch (input[1]) { case '*': - __flag_graph (core, r_str_trim_head_ro (input + 2), '*'); + __flag_graph (core, rz_str_trim_head_ro (input + 2), '*'); break; case ' ': - __flag_graph (core, r_str_trim_head_ro (input + 2), ' '); + __flag_graph (core, rz_str_trim_head_ro (input + 2), ' '); break; case 0: - __flag_graph (core, r_str_trim_head_ro (input + 1), 0); + __flag_graph (core, rz_str_trim_head_ro (input + 1), 0); break; default: eprintf ("Usage: fg[*] ([prefix])\n"); @@ -1244,20 +1244,20 @@ rep: break; case 'c': // "fc" if (input[1]=='?' || input[1] != ' ') { - r_core_cmd_help (core, help_msg_fc); + rz_core_cmd_help (core, help_msg_fc); } else { - RFlagItem *fi; + RzFlagItem *fi; const char *ret; - char *arg = r_str_trim_dup (input + 2); + char *arg = rz_str_trim_dup (input + 2); char *color = strchr (arg, ' '); if (color && color[1]) { *color++ = 0; } - fi = r_flag_get (core->flags, arg); + fi = rz_flag_get (core->flags, arg); if (fi) { - ret = r_flag_item_set_color (fi, color); + ret = rz_flag_item_set_color (fi, color); if (!color && ret) - r_cons_println (ret); + rz_cons_println (ret); } else { eprintf ("Unknown flag '%s'\n", arg); } @@ -1266,31 +1266,31 @@ rep: break; case 'C': // "fC" if (input[1] == ' ') { - RFlagItem *item; + RzFlagItem *item; char *q, *p = strdup (input + 2), *dec = NULL; q = strchr (p, ' '); if (q) { *q = 0; - item = r_flag_get (core->flags, p); + item = rz_flag_get (core->flags, p); if (item) { if (!strncmp (q + 1, "base64:", 7)) { - dec = (char *) r_base64_decode_dyn (q + 8, -1); + dec = (char *) rz_base64_decode_dyn (q + 8, -1); if (dec) { - r_flag_item_set_comment (item, dec); + rz_flag_item_set_comment (item, dec); free (dec); } else { eprintf ("Failed to decode base64-encoded string\n"); } } else { - r_flag_item_set_comment (item, q + 1); + rz_flag_item_set_comment (item, q + 1); } } else { eprintf ("Cannot find flag with name '%s'\n", p); } } else { - item = r_flag_get_i (core->flags, r_num_math (core->num, p)); + item = rz_flag_get_i (core->flags, rz_num_math (core->num, p)); if (item && item->comment) { - r_cons_println (item->comment); + rz_cons_println (item->comment); } else { eprintf ("Cannot find item\n"); } @@ -1299,29 +1299,29 @@ rep: } else eprintf ("Usage: fC [name] [comment]\n"); break; case 'o': // "fo" - r_core_fortune_print_random (core); + rz_core_fortune_print_random (core); break; case 'O': // "fO" flag_ordinals (core, input + 1); break; case 'r': if (input[1] == ' ' && input[2]) { - RFlagItem *item; + RzFlagItem *item; char *old = str + 1; char *new = strchr (old, ' '); if (new) { *new = 0; new++; - item = r_flag_get (core->flags, old); + item = rz_flag_get (core->flags, old); if (!item && !strncmp (old, "fcn.", 4)) { - item = r_flag_get (core->flags, old+4); + item = rz_flag_get (core->flags, old+4); } } else { new = old; - item = r_flag_get_i (core->flags, core->offset); + item = rz_flag_get_i (core->flags, core->offset); } if (item) { - if (!r_flag_rename (core->flags, item, new)) { + if (!rz_flag_rename (core->flags, item, new)) { eprintf ("Invalid name\n"); } } else { @@ -1331,28 +1331,28 @@ rep: break; case 'N': if (!input[1]) { - RFlagItem *item = r_flag_get_i (core->flags, core->offset); + RzFlagItem *item = rz_flag_get_i (core->flags, core->offset); if (item) { - r_cons_printf ("%s\n", item->realname); + rz_cons_printf ("%s\n", item->realname); } break; } else if (input[1] == ' ' && input[2]) { - RFlagItem *item; + RzFlagItem *item; char *name = str + 1; char *realname = strchr (name, ' '); if (realname) { *realname = 0; realname++; - item = r_flag_get (core->flags, name); + item = rz_flag_get (core->flags, name); if (!item && !strncmp (name, "fcn.", 4)) { - item = r_flag_get (core->flags, name+4); + item = rz_flag_get (core->flags, name+4); } } else { realname = name; - item = r_flag_get_i (core->flags, core->offset); + item = rz_flag_get_i (core->flags, core->offset); } if (item) { - r_flag_item_set_realname (item, realname); + rz_flag_item_set_realname (item, realname); } break; } @@ -1375,18 +1375,18 @@ rep: } if (input[0] && input[1] == '.') { const int mode = input[2]; - const RList *list = r_flag_get_list (core->flags, core->offset); + const RzList *list = rz_flag_get_list (core->flags, core->offset); PJ *pj = NULL; if (mode == 'j') { pj = pj_new (); pj_a (pj); } - RListIter *iter; - RFlagItem *item; - r_list_foreach (list, iter, item) { + RzListIter *iter; + RzFlagItem *item; + rz_list_foreach (list, iter, item) { switch (mode) { case '*': - r_cons_printf ("f %s = 0x%08"PFMT64x"\n", item->name, item->offset); + rz_cons_printf ("f %s = 0x%08"PFMT64x"\n", item->name, item->offset); break; case 'j': { @@ -1399,48 +1399,48 @@ rep: } break; default: - r_cons_printf ("%s\n", item->name); + rz_cons_printf ("%s\n", item->name); break; } } if (mode == 'j') { pj_end (pj); char *s = pj_drain (pj); - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); } } else { - r_flag_list (core->flags, *input, input[0]? input + 1: ""); + rz_flag_list (core->flags, *input, input[0]? input + 1: ""); } break; case 'i': // "fi" if (input[1] == ' ' || (input[1] && input[2] == ' ')) { - char *arg = strdup (r_str_trim_head_ro (input + 2)); + char *arg = strdup (rz_str_trim_head_ro (input + 2)); if (*arg) { - arg = strdup (r_str_trim_head_ro (input + 2)); + arg = strdup (rz_str_trim_head_ro (input + 2)); char *sp = strchr (arg, ' '); if (!sp) { - char *newarg = r_str_newf ("%c0x%"PFMT64x" %s+0x%"PFMT64x, + char *newarg = rz_str_newf ("%c0x%"PFMT64x" %s+0x%"PFMT64x, input[1], core->offset, arg, core->offset); free (arg); arg = newarg; } else { - char *newarg = r_str_newf ("%c%s", input[1], arg); + char *newarg = rz_str_newf ("%c%s", input[1], arg); free (arg); arg = newarg; } } else { free (arg); - arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x, + arg = rz_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x, core->offset, core->offset + core->blocksize); } - r_flag_list (core->flags, 'i', arg); + rz_flag_list (core->flags, 'i', arg); free (arg); } else { // XXX dupe for prev case - char *arg = r_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x, + char *arg = rz_str_newf (" 0x%"PFMT64x" 0x%"PFMT64x, core->offset, core->offset + core->blocksize); - r_flag_list (core->flags, 'i', arg); + rz_flag_list (core->flags, 'i', arg); free (arg); } break; @@ -1448,11 +1448,11 @@ rep: { ut64 addr = core->offset; char *arg = NULL; - RFlagItem *f = NULL; + RzFlagItem *f = NULL; bool strict_offset = false; switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_fd); + rz_core_cmd_help (core, help_msg_fd); if (str) { free (str); } @@ -1463,20 +1463,20 @@ rep: case 'd': arg = strchr (input, ' '); if (arg) { - addr = r_num_math (core->num, arg + 1); + addr = rz_num_math (core->num, arg + 1); } break; case '.': // "fd." list all flags at given offset { - RFlagItem *flag; - RListIter *iter; + RzFlagItem *flag; + RzListIter *iter; bool isJson = false; - const RList *flaglist; + const RzList *flaglist; arg = strchr (input, ' '); if (arg) { - addr = r_num_math (core->num, arg + 1); + addr = rz_num_math (core->num, arg + 1); } - flaglist = r_flag_get_list (core->flags, addr); + flaglist = rz_flag_get_list (core->flags, addr); isJson = strchr (input, 'j'); PJ *pj = pj_new (); if (isJson) { @@ -1484,7 +1484,7 @@ rep: } // Sometime an address has multiple flags assigned to, show them all - r_list_foreach (flaglist, iter, flag) { + rz_list_foreach (flaglist, iter, flag) { if (flag) { if (isJson) { pj_o (pj); @@ -1497,9 +1497,9 @@ rep: } else { // Print realname if exists and asm.flags.real is enabled if (core->flags->realnames && flag->realname) { - r_cons_println (flag->realname); + rz_cons_println (flag->realname); } else { - r_cons_println (flag->name); + rz_cons_println (flag->name); } } } @@ -1507,7 +1507,7 @@ rep: if (isJson) { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } if (pj) { @@ -1526,16 +1526,16 @@ rep: return 0; } - RFlag *f = core->flags; - RList *temp = r_flag_all_list (f, true); + RzFlag *f = core->flags; + RzList *temp = rz_flag_all_list (f, true); ut64 loff = 0; ut64 uoff = 0; ut64 curseek = core->offset; char *lmatch = NULL , *umatch = NULL; - RFlagItem *flag; - RListIter *iter; - r_list_sort (temp, &cmpflag); - r_list_foreach (temp, iter, flag) { + RzFlagItem *flag; + RzListIter *iter; + rz_list_sort (temp, &cmpflag); + rz_list_foreach (temp, iter, flag) { if (strstr (flag->name , arg) != NULL) { if (flag->offset < core->offset) { loff = flag->offset; @@ -1550,20 +1550,20 @@ rep: char *match = (curseek - loff) < (uoff - curseek) ? lmatch : umatch ; if (match) { if (*match) { - r_cons_println (match); + rz_cons_println (match); } } - r_list_free (temp); + rz_list_free (temp); return 0; } default: arg = strchr (input, ' '); if (arg) { - addr = r_num_math (core->num, arg + 1); + addr = rz_num_math (core->num, arg + 1); } break; } - f = r_flag_get_at (core->flags, addr, !strict_offset); + f = rz_flag_get_at (core->flags, addr, !strict_offset); if (f) { if (f->offset != addr) { // if input contains 'j' print json @@ -1577,17 +1577,17 @@ rep: pj_ks (pj, "realname", f->realname); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); if (pj) { pj_free (pj); } } else { // Print realname if exists and asm.flags.real is enabled if (core->flags->realnames && f->realname) { - r_cons_printf ("%s + %d\n", f->realname, + rz_cons_printf ("%s + %d\n", f->realname, (int)(addr - f->offset)); } else { - r_cons_printf ("%s + %d\n", f->name, + rz_cons_printf ("%s + %d\n", f->name, (int)(addr - f->offset)); } } @@ -1601,14 +1601,14 @@ rep: pj_ks (pj, "realname", f->realname); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else { // Print realname if exists and asm.flags.real is enabled if (core->flags->realnames && f->realname) { - r_cons_println (f->realname); + rz_cons_println (f->realname); } else { - r_cons_println (f->name); + rz_cons_println (f->name); } } } @@ -1618,9 +1618,9 @@ rep: case '?': default: if (input[1]) { - core->num->value = r_flag_get (core->flags, input + 1)? 1: 0; + core->num->value = rz_flag_get (core->flags, input + 1)? 1: 0; } else { - r_core_cmd_help (core, help_msg_f); + rz_core_cmd_help (core, help_msg_f); break; } } diff --git a/libr/core/cmd_hash.c b/librz/core/cmd_hash.c similarity index 64% rename from libr/core/cmd_hash.c rename to librz/core/cmd_hash.c index 50c21fbd24..4ab49f8eed 100644 --- a/libr/core/cmd_hash.c +++ b/librz/core/cmd_hash.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2015 - pancake, nibble */ #include -#include "r_cons.h" -#include "r_core.h" -#include "r_hash.h" -#include "r_types_base.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_hash.h" +#include "rz_types_base.h" typedef void (*HashHandler)(const ut8 *block, int len); @@ -96,9 +96,9 @@ static void handle_crc64_iso (const ut8 * block, int len); typedef struct { const char *name; HashHandler handler; -} RHashHashHandlers; +} RzHashHashHandlers; -static RHashHashHandlers hash_handlers[] = { +static RzHashHashHandlers hash_handlers[] = { {"md4", handle_md4}, {"md5", handle_md5}, {"sha1", handle_sha1}, @@ -190,347 +190,347 @@ static RHashHashHandlers hash_handlers[] = { static void handle_md4 (const ut8 *block, int len) { int i = 0; - RHash *ctx = r_hash_new (true, R_HASH_MD4); - const ut8 *c = r_hash_do_md4 (ctx, block, len); - for (i=0; i 0) { - RLangPlugin *p = r_lang_get_by_name (core->lang, av[0]); + RzLangPlugin *p = rz_lang_get_by_name (core->lang, av[0]); if (p) { - // I see no point in using r_lang_use here, as we already haz a ptr to the pluging in our handz - // Maybe add r_lang_use_plugin in r_lang api? + // I see no point in using rz_lang_use here, as we already haz a ptr to the pluging in our handz + // Maybe add rz_lang_use_plugin in rz_lang api? core->lang->cur = p; if (ac > 1) { if (!strcmp (av[1], "-e")) { char *run_str = strstr (input + 2, "-e") + 2; - r_lang_run_string (core->lang, run_str); + rz_lang_run_string (core->lang, run_str); } else { - if (r_lang_set_argv (core->lang, ac - 1, &av[1])) { - r_lang_run_file (core->lang, av[1]); + if (rz_lang_set_argv (core->lang, ac - 1, &av[1])) { + rz_lang_run_file (core->lang, av[1]); } else { char *run_str = strstr (input + 2, av[1]); - r_lang_run_file (core->lang, run_str); + rz_lang_run_file (core->lang, run_str); } } } else { - if (r_cons_is_interactive ()) { - r_lang_prompt (core->lang); + if (rz_cons_is_interactive ()) { + rz_lang_prompt (core->lang); } else { eprintf ("Error: scr.interactive required to run the rlang prompt\n"); } } } else if (av[0][0]=='?' || av[0][0]=='*') { - r_lang_list (core->lang); + rz_lang_list (core->lang); } } else { - r_lang_list (core->lang); + rz_lang_list (core->lang); } - r_str_argv_free(av); + rz_str_argv_free(av); return true; } static int cmd_hash(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (*input == '!') { return cmd_hash_bang (core, input); @@ -545,10 +545,10 @@ static int cmd_hash(void *data, const char *input) { //" #!python < #include // required for signbit -#include "r_cons.h" -#include "r_core.h" -#include "r_util.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_util.h" static ut32 vernum(const char *s) { // XXX this is known to be buggy, only works for strings like "x.x.x" // XXX anything like "x.xx.x" will break the parsing // XXX -git is ignored, maybe we should shift for it char *a = strdup (s); - a = r_str_replace (a, ".", "0", 1); + a = rz_str_replace (a, ".", "0", 1); char *dash = strchr (a, '-'); if (dash) { *dash = 0; @@ -57,12 +57,12 @@ static const char *help_msg_exclamation[] = { "Usage:", "!", " Run given command as in system(3)", "!", "", "list all historic commands", "!", "ls", "execute 'ls' in shell", - "!*", "r2p x", "run r2 command via r2pipe in current session", + "!*", "r2p x", "run r2 command via rzpipe in current session", "!!", "", "save command history to hist file", "!!", "ls~txt", "print output of 'ls' and grep for 'txt'", "!!!", "cmd [args|$type]", "adds the autocomplete value", "!!!-", "cmd [args]", "removes the autocomplete value", - ".!", "rabin2 -rpsei ${FILE}", "run each output line as a r2 cmd", + ".!", "rz_bin -rpsei ${FILE}", "run each output line as a r2 cmd", "!", "echo $R2_SIZE", "display file size", "!-", "", "clear history in current session", "!-*", "", "clear and save empty history log", @@ -78,7 +78,7 @@ static const char *help_msg_root[] = { ".", "[?] [-|(m)|f|!sh|cmd]", "Define macro or load r2, cparse or rlang file", "_", "[?]", "Print last output", "=","[?] [cmd]", "send/listen for remote commands (rap://, raps://, udp://, http://, )", - "<","[...]", "push escaped string into the RCons.readChar buffer", + "<","[...]", "push escaped string into the RzCons.readChar buffer", "/","[?]", "search for bytes, regexps, patterns, ..", "!","[?] [cmd]", "run given command as in system(3)", "#","[?] !lang [..]", "Hashbang to run an rlang script", @@ -89,8 +89,8 @@ static const char *help_msg_root[] = { "d","[?]", "debugger commands", "e","[?] [a[=b]]", "list/get/set config evaluable vars", "f","[?] [name][sz][at]", "add flag at current address", - "g","[?] [arg]", "generate shellcodes with r_egg", - "i","[?] [file]", "get info about opened file from r_bin", + "g","[?] [arg]", "generate shellcodes with rz_egg", + "i","[?] [file]", "get info about opened file from rz_bin", "k","[?] [sdb-query]", "run sdb-query. see k? for help, 'k *', 'k **' ...", "l"," [filepattern]", "list files and directories", "L","[?] [-] [plugin]", "list, unload load r2 plugins", @@ -158,7 +158,7 @@ static const char *help_msg_question[] = { "?u", " num", "get value in human units (KB, MB, GB, TB)", "?v", " eip-0x804800", "show hex value of math expr", "?vi", " rsp-rbp", "show decimal value of math expr", - "?V", "", "show library version of r_core", + "?V", "", "show library version of rz_core", "?w", " addr", "show what's in this address (like pxr/pxq does)", "?x", " str", "returns the hexpair of number or string", "?x", "+num", "like ?v, but in hexpairs honoring cfg.bigendian", @@ -253,17 +253,17 @@ static const char *help_msg_intro[] = { NULL }; -static void cmd_help_exclamation(RCore *core) { - r_core_cmd_help (core, help_msg_exclamation); - r_core_cmd_help (core, help_msg_env); +static void cmd_help_exclamation(RzCore *core) { + rz_core_cmd_help (core, help_msg_exclamation); + rz_core_cmd_help (core, help_msg_env); } -static void cmd_help_percent(RCore *core) { - r_core_cmd_help (core, help_msg_percent); - r_core_cmd_help (core, help_msg_env); +static void cmd_help_percent(RzCore *core) { + rz_core_cmd_help (core, help_msg_percent); + rz_core_cmd_help (core, help_msg_env); } -static void cmd_help_init(RCore *core, RCmdDesc *parent) { +static void cmd_help_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR_SPECIAL (core, ?, question); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, ?v, question_v); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, ?V, question_V); @@ -271,7 +271,7 @@ static void cmd_help_init(RCore *core, RCmdDesc *parent) { static const char* findBreakChar(const char *s) { while (*s) { - if (!r_name_validate_char (*s)) { + if (!rz_name_validate_char (*s)) { break; } s++; @@ -279,7 +279,7 @@ static const char* findBreakChar(const char *s) { return s; } -static char *filterFlags(RCore *core, const char *msg) { +static char *filterFlags(RzCore *core, const char *msg) { const char *dollar, *end; char *word, *buf = NULL; for (;;) { @@ -287,16 +287,16 @@ static char *filterFlags(RCore *core, const char *msg) { if (!dollar) { break; } - buf = r_str_appendlen (buf, msg, dollar-msg); + buf = rz_str_appendlen (buf, msg, dollar-msg); if (dollar[1]=='{') { // find } end = strchr (dollar+2, '}'); if (end) { - word = r_str_newlen (dollar+2, end-dollar-2); + word = rz_str_newlen (dollar+2, end-dollar-2); end++; } else { msg = dollar+1; - buf = r_str_append (buf, "$"); + buf = rz_str_append (buf, "$"); continue; } } else { @@ -304,20 +304,20 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - word = r_str_newlen (dollar+1, end-dollar-1); + word = rz_str_newlen (dollar+1, end-dollar-1); } if (end && word) { - ut64 val = r_num_math (core->num, word); + ut64 val = rz_num_math (core->num, word); char num[32]; snprintf (num, sizeof (num), "0x%"PFMT64x, val); - buf = r_str_append (buf, num); + buf = rz_str_append (buf, num); msg = end; } else { break; } free (word); } - buf = r_str_append (buf, msg); + buf = rz_str_append (buf, msg); return buf; } @@ -405,7 +405,7 @@ enum { R_AVATAR_CLIPPY, }; -R_API void r_core_clippy(RCore *core, const char *msg) { +RZ_API void rz_core_clippy(RzCore *core, const char *msg) { int type = R_AVATAR_CLIPPY; if (*msg == '+' || *msg == '3') { char *space = strchr (msg, ' '); @@ -416,39 +416,39 @@ R_API void r_core_clippy(RCore *core, const char *msg) { msg = space + 1; } const char *f; - int msglen = r_str_len_utf8 (msg); - char *s = strdup (r_str_pad (' ', msglen)); + int msglen = rz_str_len_utf8 (msg); + char *s = strdup (rz_str_pad (' ', msglen)); char *l; if (type == R_AVATAR_ORANGG) { - l = strdup (r_str_pad ('-', msglen)); + l = strdup (rz_str_pad ('-', msglen)); f = avatar_orangg[0]; } else if (type == R_AVATAR_CYBCAT) { - l = strdup (r_str_pad ('-', msglen)); - f = avatar_cybcat[r_num_rand (R_ARRAY_SIZE (avatar_cybcat))]; - } else if (r_config_get_i (core->config, "scr.utf8")) { - l = (char *)r_str_repeat ("─", msglen); - f = avatar_clippy_utf8[r_num_rand (R_ARRAY_SIZE (avatar_clippy_utf8))]; + l = strdup (rz_str_pad ('-', msglen)); + f = avatar_cybcat[rz_num_rand (R_ARRAY_SIZE (avatar_cybcat))]; + } else if (rz_config_get_i (core->config, "scr.utf8")) { + l = (char *)rz_str_repeat ("─", msglen); + f = avatar_clippy_utf8[rz_num_rand (R_ARRAY_SIZE (avatar_clippy_utf8))]; } else { - l = strdup (r_str_pad ('-', msglen)); - f = avatar_clippy[r_num_rand (R_ARRAY_SIZE (avatar_clippy))]; + l = strdup (rz_str_pad ('-', msglen)); + f = avatar_clippy[rz_num_rand (R_ARRAY_SIZE (avatar_clippy))]; } - r_cons_printf (f, l, s, msg, s, l); + rz_cons_printf (f, l, s, msg, s, l); free (l); free (s); } static int cmd_help(void *data, const char *input) { - RCore *core = (RCore *)data; - RIOMap *map; + RzCore *core = (RzCore *)data; + RzIOMap *map; const char *k; - RListIter *iter; + RzListIter *iter; char *p, out[128] = R_EMPTY; ut64 n; int i; - RList *tmp; + RzList *tmp; switch (input[0]) { case '0': // "?0" @@ -469,10 +469,10 @@ static int cmd_help(void *data, const char *input) { p = strchr (out + 1, ' '); if (p) { *p = 0; - b = (ut32)r_num_math (core->num, out); - r = (ut32)r_num_math (core->num, p+1)-b; + b = (ut32)rz_num_math (core->num, out); + r = (ut32)rz_num_math (core->num, p+1)-b; } else { - r = (ut32)r_num_math (core->num, out); + r = (ut32)rz_num_math (core->num, out); } } else { r = 0LL; @@ -480,12 +480,12 @@ static int cmd_help(void *data, const char *input) { if (!r) { r = UT32_MAX >> 1; } - core->num->value = (ut64) (b + r_num_rand (r)); - r_cons_printf ("0x%"PFMT64x"\n", core->num->value); + core->num->value = (ut64) (b + rz_num_rand (r)); + rz_cons_printf ("0x%"PFMT64x"\n", core->num->value); } break; case 'a': // "?a" - r_cons_printf ("%s", ret_ascii_table()); + rz_cons_printf ("%s", ret_ascii_table()); break; case 'b': // "?b" if (input[1] == '6' && input[2] == '4') { @@ -496,42 +496,42 @@ static int cmd_help(void *data, const char *input) { return false; } if (input[3] == '-') { - r_base64_decode ((ut8*)buf, input + 4, -1); + rz_base64_decode ((ut8*)buf, input + 4, -1); } else if (input[3] == ' ') { - r_base64_encode (buf, (const ut8*)input + 4, -1); + rz_base64_encode (buf, (const ut8*)input + 4, -1); } - r_cons_println (buf); + rz_cons_println (buf); free (buf); } else if (input[1] == 't' && input[2] == 'w') { // "?btw" - if (r_num_between (core->num, input + 3) == -1) { + if (rz_num_between (core->num, input + 3) == -1) { eprintf ("Usage: ?btw num|(expr) num|(expr) num|(expr)\n"); } } else { - n = r_num_get (core->num, input+1); - r_num_to_bits (out, n); - r_cons_printf ("%sb\n", out); + n = rz_num_get (core->num, input+1); + rz_num_to_bits (out, n); + rz_cons_printf ("%sb\n", out); } break; case 'B': // "?B" - k = r_str_trim_head_ro (input + 1); - tmp = r_core_get_boundaries_prot (core, -1, k, "search"); + k = rz_str_trim_head_ro (input + 1); + tmp = rz_core_get_boundaries_prot (core, -1, k, "search"); if (!tmp) { return false; } - r_list_foreach (tmp, iter, map) { - r_cons_printf ("0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); + rz_list_foreach (tmp, iter, map) { + rz_cons_printf ("0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); } - r_list_free (tmp); + rz_list_free (tmp); break; case 'h': // "?h" if (input[1] == ' ') { - r_cons_printf ("0x%08x\n", (ut32)r_str_hash (input + 2)); + rz_cons_printf ("0x%08x\n", (ut32)rz_str_hash (input + 2)); } else { eprintf ("Usage: ?h [string-to-hash]\n"); } break; case 'F': // "?F" - r_cons_flush (); + rz_cons_flush (); break; case 'f': // "?f" if (input[1] == ' ') { @@ -543,9 +543,9 @@ static int cmd_help(void *data, const char *input) { q = strchr (p, ' '); if (q) { *q = 0; - n = r_num_get (core->num, p); - r_str_bits (out, (const ut8*)&n, sizeof (n) * 8, q + 1); - r_cons_println (out); + n = rz_num_get (core->num, p); + rz_str_bits (out, (const ut8*)&n, sizeof (n) * 8, q + 1); + rz_cons_println (out); } else { eprintf ("Usage: \"?b value bitstring\"\n"); } @@ -555,11 +555,11 @@ static int cmd_help(void *data, const char *input) { } break; case 'o': // "?o" - n = r_num_math (core->num, input+1); - r_cons_printf ("0%"PFMT64o"\n", n); + n = rz_num_math (core->num, input+1); + rz_cons_printf ("0%"PFMT64o"\n", n); break; case 'T': // "?T" - r_cons_printf("plug.init = %"PFMT64d"\n" + rz_cons_printf("plug.init = %"PFMT64d"\n" "plug.load = %"PFMT64d"\n" "file.load = %"PFMT64d"\n", core->times->loadlibs_init_time, @@ -569,9 +569,9 @@ static int cmd_help(void *data, const char *input) { case 'u': // "?u" { char unit[8]; - n = r_num_math (core->num, input+1); - r_num_units (unit, sizeof (unit), n); - r_cons_println (unit); + n = rz_num_math (core->num, input+1); + rz_num_units (unit, sizeof (unit), n); + rz_cons_println (unit); } break; case 'j': // "?j" @@ -582,27 +582,27 @@ static int cmd_help(void *data, const char *input) { double d; float f; char * const inputs = strdup (input + 1); - RList *list = r_num_str_split_list (inputs); - const int list_len = r_list_length (list); + RzList *list = rz_num_str_split_list (inputs); + const int list_len = rz_list_length (list); PJ *pj = NULL; if (*input == 'j') { pj = pj_new (); pj_o (pj); } for (i = 0; i < list_len; i++) { - const char *str = r_list_pop_head (list); + const char *str = rz_list_pop_head (list); if (!*str) { continue; } - n = r_num_math (core->num, str); + n = rz_num_math (core->num, str); if (core->num->dbz) { eprintf ("RNum ERROR: Division by Zero\n"); } - asnum = r_num_as_string (NULL, n, false); + asnum = rz_num_as_string (NULL, n, false); /* decimal, hexa, octal */ s = n >> 16 << 12; a = n & 0x0fff; - r_num_units (unit, sizeof (unit), n); + rz_num_units (unit, sizeof (unit), n); if (*input == 'j') { pj_ks (pj, "int32", sdb_fmt ("%d", (st32)(n & UT32_MAX))); pj_ks (pj, "uint32", sdb_fmt ("%u", (ut32)n)); @@ -615,24 +615,24 @@ static int cmd_help(void *data, const char *input) { } else { if (n >> 32) { - r_cons_printf ("int64 %"PFMT64d"\n", (st64)n); - r_cons_printf ("uint64 %"PFMT64u"\n", (ut64)n); + rz_cons_printf ("int64 %"PFMT64d"\n", (st64)n); + rz_cons_printf ("uint64 %"PFMT64u"\n", (ut64)n); } else { - r_cons_printf ("int32 %d\n", (st32)n); - r_cons_printf ("uint32 %u\n", (ut32)n); + rz_cons_printf ("int32 %d\n", (st32)n); + rz_cons_printf ("uint32 %u\n", (ut32)n); } - r_cons_printf ("hex 0x%"PFMT64x"\n", n); - r_cons_printf ("octal 0%"PFMT64o"\n", n); - r_cons_printf ("unit %s\n", unit); - r_cons_printf ("segment %04x:%04x\n", s, a); + rz_cons_printf ("hex 0x%"PFMT64x"\n", n); + rz_cons_printf ("octal 0%"PFMT64o"\n", n); + rz_cons_printf ("unit %s\n", unit); + rz_cons_printf ("segment %04x:%04x\n", s, a); if (asnum) { - r_cons_printf ("string \"%s\"\n", asnum); + rz_cons_printf ("string \"%s\"\n", asnum); free (asnum); } } /* binary and floating point */ - r_str_bits64 (out, n); + rz_str_bits64 (out, n); f = d = core->num->fvalue; memcpy (&f, &n, sizeof (f)); memcpy (&d, &n, sizeof (d)); @@ -648,26 +648,26 @@ static int cmd_help(void *data, const char *input) { pj_ks (pj, "float", sdb_fmt ("%ff", f)); pj_ks (pj, "double", sdb_fmt ("%lf", d)); pj_ks (pj, "binary", sdb_fmt ("0b%s", out)); - r_num_to_trits (out, n); + rz_num_to_trits (out, n); pj_ks (pj, "trits", sdb_fmt ("0t%s", out)); } else { - r_cons_printf ("fvalue: %.1lf\n", core->num->fvalue); - r_cons_printf ("float: %ff\n", f); - r_cons_printf ("double: %lf\n", d); - r_cons_printf ("binary 0b%s\n", out); + rz_cons_printf ("fvalue: %.1lf\n", core->num->fvalue); + rz_cons_printf ("float: %ff\n", f); + rz_cons_printf ("double: %lf\n", d); + rz_cons_printf ("binary 0b%s\n", out); /* ternary */ - r_num_to_trits (out, n); - r_cons_printf ("trits 0t%s\n", out); + rz_num_to_trits (out, n); + rz_cons_printf ("trits 0t%s\n", out); } } if (*input == 'j') { pj_end (pj); } free (inputs); - r_list_free (list); + rz_list_free (list); if (pj) { - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } @@ -677,14 +677,14 @@ static int cmd_help(void *data, const char *input) { eprintf ("RNum ERROR: Division by Zero\n"); } if (input[1] == '?') { - r_cons_printf ("|Usage: ?q [num] # Update $? without printing anything\n" + rz_cons_printf ("|Usage: ?q [num] # Update $? without printing anything\n" "|?q 123; ?? x # hexdump if 123 != 0"); } else { const char *space = strchr (input, ' '); if (space) { - n = r_num_math (core->num, space + 1); + n = rz_num_math (core->num, space + 1); } else { - n = r_num_math (core->num, "$?"); + n = rz_num_math (core->num, "$?"); } core->num->value = n; // redundant } @@ -693,9 +693,9 @@ static int cmd_help(void *data, const char *input) { { const char *space = strchr (input, ' '); if (space) { - n = r_num_math (core->num, space + 1); + n = rz_num_math (core->num, space + 1); } else { - n = r_num_math (core->num, "$?"); + n = rz_num_math (core->num, "$?"); } } if (core->num->dbz) { @@ -703,7 +703,7 @@ static int cmd_help(void *data, const char *input) { } switch (input[1]) { case '?': - r_cons_printf ("|Usage: ?v[id][ num] # Show value\n" + rz_cons_printf ("|Usage: ?v[id][ num] # Show value\n" "|?vx number -> show 8 digit padding in hex\n" "|?vi1 200 -> 1 byte size value (char)\n" "|?vi2 0xffff -> 2 byte size value (short)\n" @@ -713,35 +713,35 @@ static int cmd_help(void *data, const char *input) { "|?vi will show in decimal instead of hex\n"); break; case '\0': - r_cons_printf ("%d\n", (st32)n); + rz_cons_printf ("%d\n", (st32)n); break; case 'x': // "?vx" - r_cons_printf ("0x%08"PFMT64x"\n", n); + rz_cons_printf ("0x%08"PFMT64x"\n", n); break; case 'i': // "?vi" switch (input[2]) { case '1': // byte - r_cons_printf ("%d\n", (st8)(n & UT8_MAX)); + rz_cons_printf ("%d\n", (st8)(n & UT8_MAX)); break; case '2': // word - r_cons_printf ("%d\n", (st16)(n & UT16_MAX)); + rz_cons_printf ("%d\n", (st16)(n & UT16_MAX)); break; case '4': // dword - r_cons_printf ("%d\n", (st32)(n & UT32_MAX)); + rz_cons_printf ("%d\n", (st32)(n & UT32_MAX)); break; case '8': // qword - r_cons_printf ("%"PFMT64d"\n", (st64)(n & UT64_MAX)); + rz_cons_printf ("%"PFMT64d"\n", (st64)(n & UT64_MAX)); break; default: - r_cons_printf ("%"PFMT64d"\n", n); + rz_cons_printf ("%"PFMT64d"\n", n); break; } break; case 'd': - r_cons_printf ("%"PFMT64d"\n", n); + rz_cons_printf ("%"PFMT64d"\n", n); break; default: - r_cons_printf ("0x%"PFMT64x"\n", n); + rz_cons_printf ("0x%"PFMT64x"\n", n); } core->num->value = n; // redundant break; @@ -762,9 +762,9 @@ static int cmd_help(void *data, const char *input) { } } else { if (input[1]) { // ?= - r_num_math (core->num, input+1); + rz_num_math (core->num, input+1); } else { - r_cons_printf ("0x%"PFMT64x"\n", core->num->value); + rz_cons_printf ("0x%"PFMT64x"\n", core->num->value); } } break; @@ -772,20 +772,20 @@ static int cmd_help(void *data, const char *input) { if (input[1]) { st64 n = (st64)core->num->value; if (n > 0) { - r_core_cmd (core, input + 1, 0); + rz_core_cmd (core, input + 1, 0); } } else { - r_cons_printf ("0x%"PFMT64x"\n", core->num->value); + rz_cons_printf ("0x%"PFMT64x"\n", core->num->value); } break; case '-': // "?-" if (input[1]) { st64 n = (st64)core->num->value; if (n < 0) { - r_core_cmd (core, input + 1, 0); + rz_core_cmd (core, input + 1, 0); } } else { - r_cons_printf ("0x%"PFMT64x"\n", core->num->value); + rz_cons_printf ("0x%"PFMT64x"\n", core->num->value); } break; case '!': // "?!" @@ -795,21 +795,21 @@ static int cmd_help(void *data, const char *input) { cmd_help_exclamation (core); return 0; } - return core->num->value = r_core_cmd (core, input+1, 0); + return core->num->value = rz_core_cmd (core, input+1, 0); } } else { - r_cons_printf ("0x%"PFMT64x"\n", core->num->value); + rz_cons_printf ("0x%"PFMT64x"\n", core->num->value); } break; case '@': // "?@" if (input[1] == '@') { if (input[2] == '@') { - r_core_cmd_help (core, help_msg_at_at_at); + rz_core_cmd_help (core, help_msg_at_at_at); } else { - r_core_cmd_help (core, help_msg_at_at); + rz_core_cmd_help (core, help_msg_at_at); } } else { - r_core_cmd_help (core, help_msg_at); + rz_core_cmd_help (core, help_msg_at); } break; case '&': // "?&" @@ -822,7 +822,7 @@ static int cmd_help(void *data, const char *input) { break; case '$': // "?$" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_question_v); + rz_core_cmd_help (core, help_msg_question_v); } else { int i = 0; const char *vars[] = { @@ -830,13 +830,13 @@ static int cmd_help(void *data, const char *input) { "$FI", "$c", "$r", "$D", "$DD", "$e", "$f", "$j", "$Ja", "$l", "$m", "$M", "$MM", "$o", "$p", "$P", "$s", "$S", "$SS", "$v", "$w", NULL }; - const bool wideOffsets = r_config_get_i (core->config, "scr.wideoff"); + const bool wideOffsets = rz_config_get_i (core->config, "scr.wideoff"); while (vars[i]) { - const char *pad = r_str_pad (' ', 6 - strlen (vars[i])); + const char *pad = rz_str_pad (' ', 6 - strlen (vars[i])); if (wideOffsets) { - eprintf ("%s %s 0x%016"PFMT64x"\n", vars[i], pad, r_num_math (core->num, vars[i])); + eprintf ("%s %s 0x%016"PFMT64x"\n", vars[i], pad, rz_num_math (core->num, vars[i])); } else { - eprintf ("%s %s 0x%08"PFMT64x"\n", vars[i], pad, r_num_math (core->num, vars[i])); + eprintf ("%s %s 0x%08"PFMT64x"\n", vars[i], pad, rz_num_math (core->num, vars[i])); } i++; } @@ -845,21 +845,21 @@ static int cmd_help(void *data, const char *input) { case 'V': // "?V" switch (input[1]) { case '?': // "?V?" - r_core_cmd_help (core, help_msg_question_V); + rz_core_cmd_help (core, help_msg_question_V); break; case 0: // "?V" #if R2_VERSION_COMMIT == 0 - r_cons_printf ("%s release\n", R2_VERSION); + rz_cons_printf ("%s release\n", R2_VERSION); #else if (!strcmp (R2_VERSION, R2_GITTAP)) { - r_cons_printf ("%s %d\n", R2_VERSION, R2_VERSION_COMMIT); + rz_cons_printf ("%s %d\n", R2_VERSION, R2_VERSION_COMMIT); } else { - r_cons_printf ("%s aka %s commit %d\n", R2_VERSION, R2_GITTAP, R2_VERSION_COMMIT); + rz_cons_printf ("%s aka %s commit %d\n", R2_VERSION, R2_GITTAP, R2_VERSION_COMMIT); } #endif break; case 'c': // "?Vc" - r_cons_printf ("%d\n", vernum (R2_VERSION)); + rz_cons_printf ("%d\n", vernum (R2_VERSION)); break; case 'j': // "?Vj" { @@ -877,24 +877,24 @@ static int cmd_help(void *data, const char *input) { pj_ki (pj, "nversion", vernum (R2_VERSION)); pj_ks (pj, "version", R2_VERSION); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } break; case 'n': // "?Vn" - r_cons_printf ("%d\n", R2_VERSION_NUMBER); + rz_cons_printf ("%d\n", R2_VERSION_NUMBER); break; case 'q': // "?Vq" - r_cons_println (R2_VERSION); + rz_cons_println (R2_VERSION); break; case '0': - r_cons_printf ("%d\n", R2_VERSION_MAJOR); + rz_cons_printf ("%d\n", R2_VERSION_MAJOR); break; case '1': - r_cons_printf ("%d\n", R2_VERSION_MINOR); + rz_cons_printf ("%d\n", R2_VERSION_MINOR); break; case '2': - r_cons_printf ("%d\n", R2_VERSION_PATCH); + rz_cons_printf ("%d\n", R2_VERSION_PATCH); break; } break; @@ -905,159 +905,159 @@ static int cmd_help(void *data, const char *input) { } else { for (input++; input[0] == ' '; input++); core->num->value = strlen (input); - r_cons_printf ("%d\n", core->num->value); + rz_cons_printf ("%d\n", core->num->value); } break; case 'X': // "?X" for (input++; input[0] == ' '; input++); - n = r_num_math (core->num, input); - r_cons_printf ("%"PFMT64x"\n", n); + n = rz_num_math (core->num, input); + rz_cons_printf ("%"PFMT64x"\n", n); break; case 'x': // "?x" for (input++; input[0] == ' '; input++); if (*input == '-') { ut8 *out = malloc (strlen (input) + 1); if (out) { - int len = r_hex_str2bin (input + 1, out); + int len = rz_hex_str2bin (input + 1, out); if (len >= 0) { out[len] = 0; - r_cons_println ((const char*)out); + rz_cons_println ((const char*)out); } else { eprintf ("Error parsing the hexpair string\n"); } free (out); } } else if (*input == '+') { - ut64 n = r_num_math (core->num, input); - int bits = r_num_to_bits (NULL, n) / 8; + ut64 n = rz_num_math (core->num, input); + int bits = rz_num_to_bits (NULL, n) / 8; for (i = 0; i < bits; i++) { - r_cons_printf ("%02x", (ut8)((n >> (i * 8)) &0xff)); + rz_cons_printf ("%02x", (ut8)((n >> (i * 8)) &0xff)); } - r_cons_newline (); + rz_cons_newline (); } else { if (*input == ' ') { input++; } for (i = 0; input[i]; i++) { - r_cons_printf ("%02x", input[i]); + rz_cons_printf ("%02x", input[i]); } - r_cons_newline (); + rz_cons_newline (); } break; case 'E': // "?E" clippy echo - r_core_clippy (core, r_str_trim_head_ro (input + 1)); + rz_core_clippy (core, rz_str_trim_head_ro (input + 1)); break; case 'e': // "?e" echo switch (input[1]) { case 't': // "?e=t newtitle" - r_cons_set_title (r_str_trim_head_ro (input + 2)); + rz_cons_set_title (rz_str_trim_head_ro (input + 2)); break; case '=': { // "?e=" - ut64 pc = r_num_math (core->num, input + 2); - r_print_progressbar (core->print, pc, 80); - r_cons_newline (); + ut64 pc = rz_num_math (core->num, input + 2); + rz_print_progressbar (core->print, pc, 80); + rz_cons_newline (); break; } case 'b': { // "?eb" - char *arg = strdup (r_str_trim_head_ro (input + 2)); - int n = r_str_split (arg, ' '); + char *arg = strdup (rz_str_trim_head_ro (input + 2)); + int n = rz_str_split (arg, ' '); ut64 *portions = calloc (n, sizeof (ut64)); for (i = 0; i < n; i++) { - portions[i] = r_num_math (core->num, r_str_word_get0 (arg, i)); + portions[i] = rz_num_math (core->num, rz_str_word_get0 (arg, i)); } - r_print_portionbar (core->print, portions, n); + rz_print_portionbar (core->print, portions, n); free (arg); break; } case 's': { // "?es" char *msg = strdup (input + 2); - r_str_trim (msg); + rz_str_trim (msg); char *p = strchr (msg, '&'); if (p) *p = 0; - r_sys_tts (msg, p != NULL); + rz_sys_tts (msg, p != NULL); free (msg); break; } case 'c': // "?ec" column - r_cons_column (r_num_math (core->num, input + 2)); + rz_cons_column (rz_num_math (core->num, input + 2)); break; case 'g': { // "?eg" gotoxy int x = atoi (input + 2); char *arg = strchr (input + 2, ' '); int y = arg? atoi (arg + 1): 0; - r_cons_gotoxy (x, y); + rz_cons_gotoxy (x, y); } break; case 'n': { // "?en" echo -n - const char *msg = r_str_trim_head_ro (input + 2); + const char *msg = rz_str_trim_head_ro (input + 2); // TODO: replace all ${flagname} by its value in hexa char *newmsg = filterFlags (core, msg); - r_str_unescape (newmsg); - r_cons_print (newmsg); + rz_str_unescape (newmsg); + rz_cons_print (newmsg); free (newmsg); break; } case 'd': // "?ed" if (input[2] == 'd') { int i,j; - r_cons_show_cursor (0); - r_cons_clear00 (); + rz_cons_show_cursor (0); + rz_cons_clear00 (); for (i = 1; i < 100; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } for (j = 0; j < 20; j++) { - char *d = r_str_donut (i); - r_cons_gotoxy (0,0); - r_str_trim_tail (d); - r_cons_clear_line (0); - r_cons_printf ("Downloading the Gibson...\n\n"); - r_core_cmdf (core, "?e=%d", i); - r_cons_strcat (d); - r_cons_clear_line (0); - r_cons_newline (); + char *d = rz_str_donut (i); + rz_cons_gotoxy (0,0); + rz_str_trim_tail (d); + rz_cons_clear_line (0); + rz_cons_printf ("Downloading the Gibson...\n\n"); + rz_core_cmdf (core, "?e=%d", i); + rz_cons_strcat (d); + rz_cons_clear_line (0); + rz_cons_newline (); free (d); - r_cons_flush (); - r_sys_usleep (2000); + rz_cons_flush (); + rz_sys_usleep (2000); } } - r_cons_clear00(); - r_cons_printf ("\nPayload installed. Thanks for your patience.\n\n"); + rz_cons_clear00(); + rz_cons_printf ("\nPayload installed. Thanks for your patience.\n\n"); } else { - char *d = r_str_donut (r_num_math (core->num, input + 2)); - r_str_trim_tail (d); + char *d = rz_str_donut (rz_num_math (core->num, input + 2)); + rz_str_trim_tail (d); const char *color = (core->cons && core->cons->context->pal.flag)? core->cons->context->pal.flag: ""; - r_cons_printf ("%s%s", color, d); - r_cons_newline (); + rz_cons_printf ("%s%s", color, d); + rz_cons_newline (); free (d); } break; case 'p': { char *word, *str = strdup (input + 2); - RList *list = r_str_split_list (str, " ", 0); - ut64 *nums = calloc (sizeof (ut64), r_list_length (list)); + RzList *list = rz_str_split_list (str, " ", 0); + ut64 *nums = calloc (sizeof (ut64), rz_list_length (list)); int i = 0; - r_list_foreach (list, iter, word) { - nums[i] = r_num_math (core->num, word);; + rz_list_foreach (list, iter, word) { + nums[i] = rz_num_math (core->num, word);; i++; } - int size = r_config_get_i (core->config, "hex.cols"); - r_print_pie (core->print, nums, r_list_length (list), size); - r_list_free (list); + int size = rz_config_get_i (core->config, "hex.cols"); + rz_print_pie (core->print, nums, rz_list_length (list), size); + rz_list_free (list); } break; case ' ': { - const char *msg = r_str_trim_head_ro (input+1); + const char *msg = rz_str_trim_head_ro (input+1); // TODO: replace all ${flagname} by its value in hexa char *newmsg = filterFlags (core, msg); - r_str_unescape (newmsg); - r_cons_println (newmsg); + rz_str_unescape (newmsg); + rz_cons_println (newmsg); free (newmsg); } break; case 0: - r_cons_newline (); + rz_cons_newline (); break; default: eprintf ("Usage: ?e[...]\n" @@ -1080,115 +1080,115 @@ static int cmd_help(void *data, const char *input) { p = strchr (input, ' '); if (p) { *p = '\0'; - from = r_num_math (core->num, input); + from = rz_num_math (core->num, input); p2 = strchr (p+1, ' '); if (p2) { *p2 = '\0'; - step = r_num_math (core->num, p2 + 1); + step = rz_num_math (core->num, p2 + 1); } else { step = 1; } - to = r_num_math (core->num, p + 1); + to = rz_num_math (core->num, p + 1); for (;from <= to; from += step) - r_cons_printf ("%"PFMT64d" ", from); - r_cons_newline (); + rz_cons_printf ("%"PFMT64d" ", from); + rz_cons_newline (); } break; } case 'P': // "?P" if (core->io->va) { ut64 o, n = (input[0] && input[1])? - r_num_math (core->num, input+2): core->offset; - RIOMap *map = r_io_map_get_paddr (core->io, n); + rz_num_math (core->num, input+2): core->offset; + RzIOMap *map = rz_io_map_get_paddr (core->io, n); if (map) { o = n + map->itv.addr - map->delta; - r_cons_printf ("0x%08"PFMT64x"\n", o); + rz_cons_printf ("0x%08"PFMT64x"\n", o); } else { - r_cons_printf ("no map at 0x%08"PFMT64x"\n", n); + rz_cons_printf ("no map at 0x%08"PFMT64x"\n", n); } } else { - r_cons_printf ("0x%08"PFMT64x"\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x"\n", core->offset); } break; case 'p': // "?p" if (core->io->va) { // physical address ut64 o, n = (input[0] && input[1])? - r_num_math (core->num, input + 2): core->offset; - RIOMap *map = r_io_map_get (core->io, n); + rz_num_math (core->num, input + 2): core->offset; + RzIOMap *map = rz_io_map_get (core->io, n); if (map) { o = n - map->itv.addr + map->delta; - r_cons_printf ("0x%08"PFMT64x"\n", o); + rz_cons_printf ("0x%08"PFMT64x"\n", o); } else { - r_cons_printf ("no map at 0x%08"PFMT64x"\n", n); + rz_cons_printf ("no map at 0x%08"PFMT64x"\n", n); } } else { - r_cons_printf ("0x%08"PFMT64x"\n", core->offset); + rz_cons_printf ("0x%08"PFMT64x"\n", core->offset); } break; case '_': // "?_" hud input - r_core_yank_hud_file (core, input+1); + rz_core_yank_hud_file (core, input+1); break; case 'i': // "?i" input num - r_cons_set_raw(0); - if (!r_cons_is_interactive ()) { + rz_cons_set_raw(0); + if (!rz_cons_is_interactive ()) { eprintf ("Not running in interactive mode\n"); } else { switch (input[1]) { case 'f': // "?if" - core->num->value = !r_num_conditional (core->num, input + 2); - eprintf ("%s\n", r_str_bool (!core->num->value)); + core->num->value = !rz_num_conditional (core->num, input + 2); + eprintf ("%s\n", rz_str_bool (!core->num->value)); break; case 'm': // "?im" - r_cons_message (input + 2); + rz_cons_message (input + 2); break; case 'p': // "?ip" - core->num->value = r_core_yank_hud_path (core, input + 2, 0) == true; + core->num->value = rz_core_yank_hud_path (core, input + 2, 0) == true; break; case 'k': // "?ik" - r_cons_any_key (NULL); + rz_cons_any_key (NULL); break; case 'y': // "?iy" for (input += 2; *input==' '; input++); - core->num->value = r_cons_yesno (1, "%s? (Y/n)", input); + core->num->value = rz_cons_yesno (1, "%s? (Y/n)", input); break; case 'n': // "?in" for (input += 2; *input==' '; input++); - core->num->value = r_cons_yesno (0, "%s? (y/N)", input); + core->num->value = rz_cons_yesno (0, "%s? (y/N)", input); break; default: { char foo[1024]; - r_cons_flush (); + rz_cons_flush (); for (input++; *input == ' '; input++); - // TODO: r_cons_input() + // TODO: rz_cons_input() snprintf (foo, sizeof (foo) - 1, "%s: ", input); - r_line_set_prompt (foo); - r_cons_fgets (foo, sizeof (foo), 0, NULL); + rz_line_set_prompt (foo); + rz_cons_fgets (foo, sizeof (foo), 0, NULL); foo[sizeof (foo) - 1] = 0; - r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, foo, strlen (foo) + 1); - core->num->value = r_num_math (core->num, foo); + rz_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, foo, strlen (foo) + 1); + core->num->value = rz_num_math (core->num, foo); } break; } } - r_cons_set_raw (0); + rz_cons_set_raw (0); break; case 'w': { // "?w" - ut64 addr = r_num_math (core->num, input + 1); + ut64 addr = rz_num_math (core->num, input + 1); char *rstr = core->print->hasrefs (core->print->user, addr, true); if (!rstr) { eprintf ("Cannot get refs\n"); break; } - r_cons_println (rstr); + rz_cons_println (rstr); free (rstr); break; } case 't': { // "?t" - struct r_prof_t prof; - r_prof_start (&prof); - r_core_cmd (core, input + 1, 0); - r_prof_end (&prof); + struct rz_prof_t prof; + rz_prof_start (&prof); + rz_core_cmd (core, input + 1, 0); + rz_prof_end (&prof); core->num->value = (ut64)(int)prof.result; eprintf ("%lf\n", prof.result); break; @@ -1196,33 +1196,33 @@ static int cmd_help(void *data, const char *input) { case '?': // "??" if (input[1] == '?') { if (input[2] == '?') { // "???" - r_core_clippy (core, "What are you doing?"); + rz_core_clippy (core, "What are you doing?"); return 0; } if (input[2]) { if (core->num->value) { - r_core_cmd (core, input + 1, 0); + rz_core_cmd (core, input + 1, 0); } break; } - r_core_cmd_help (core, help_msg_question); + rz_core_cmd_help (core, help_msg_question); return 0; } else if (input[1]) { if (core->num->value) { - core->num->value = r_core_cmd (core, input+1, 0); + core->num->value = rz_core_cmd (core, input+1, 0); } } else { if (core->num->dbz) { eprintf ("RNum ERROR: Division by Zero\n"); } - r_cons_printf ("%"PFMT64d"\n", core->num->value); + rz_cons_printf ("%"PFMT64d"\n", core->num->value); } break; case '\0': // "?" default: // TODO #7967 help refactor - r_core_cmd_help (core, help_msg_intro); - r_core_cmd_help (core, help_msg_root); + rz_core_cmd_help (core, help_msg_intro); + rz_core_cmd_help (core, help_msg_root); break; } return 0; diff --git a/libr/core/cmd_helps.c b/librz/core/cmd_helps.c similarity index 72% rename from libr/core/cmd_helps.c rename to librz/core/cmd_helps.c index b88a86d000..4bd9f925de 100644 --- a/libr/core/cmd_helps.c +++ b/librz/core/cmd_helps.c @@ -2,205 +2,205 @@ // root helps -const RCmdDescHelp system_help = { +const RzCmdDescHelp system_help = { .summary = "run given command as in system(3)", }; -const RCmdDescHelp underscore_help = { +const RzCmdDescHelp underscore_help = { .summary = "Print last output", }; -const RCmdDescHelp hash_help = { +const RzCmdDescHelp hash_help = { .summary = "Hashbang to run an rlang script", }; -const RCmdDescHelp alias_help = { +const RzCmdDescHelp alias_help = { .summary = "Alias commands and strings", }; -const RCmdDescHelp env_help = { +const RzCmdDescHelp env_help = { .summary = "get/set environment variable", }; -const RCmdDescHelp tasks_help = { +const RzCmdDescHelp tasks_help = { .summary = "Manage tasks (WARNING: Experimental. Use with caution!)", }; -const RCmdDescHelp macro_help = { +const RzCmdDescHelp macro_help = { .summary = "manage scripting macros", }; -const RCmdDescHelp pointer_help = { +const RzCmdDescHelp pointer_help = { .summary = "alias for 'env' command", }; -const RCmdDescHelp stdin_help = { +const RzCmdDescHelp stdin_help = { .summary = "", }; -const RCmdDescHelp interpret_help = { +const RzCmdDescHelp interpret_help = { .summary = "Define macro or load r2, cparse or rlang file", }; -const RCmdDescHelp search_help = { +const RzCmdDescHelp search_help = { .summary = "search for bytes, regexps, patterns, ..", }; -const RCmdDescHelp rap_help = { +const RzCmdDescHelp rap_help = { .summary = "connect with other instances of r2", }; -const RCmdDescHelp help_help = { +const RzCmdDescHelp help_help = { .summary = "Help or evaluate math expression", }; -const RCmdDescHelp rap_run_help = { +const RzCmdDescHelp rap_run_help = { .summary = "alias for =!", }; -const RCmdDescHelp zero_help = { +const RzCmdDescHelp zero_help = { .summary = "alias for `s 0x...`", }; -const RCmdDescHelp anal_help = { +const RzCmdDescHelp anal_help = { .summary = "analysis commands", }; -const RCmdDescHelp b_help = { +const RzCmdDescHelp b_help = { .summary = "display or change the block size", }; -const RCmdDescHelp c_help = { +const RzCmdDescHelp c_help = { .summary = "compare block with given data", }; -const RCmdDescHelp C_help = { +const RzCmdDescHelp C_help = { .summary = "code metadata (comments, format, hints, ..)", }; -const RCmdDescHelp d_help = { +const RzCmdDescHelp d_help = { .summary = "debugger commands", }; -const RCmdDescHelp e_help = { +const RzCmdDescHelp e_help = { .summary = "list/get/set config evaluable vars", }; -const RCmdDescHelp f_help = { +const RzCmdDescHelp f_help = { .summary = "add flag at current address", }; -const RCmdDescHelp g_help = { - .summary = "generate shellcodes with r_egg", +const RzCmdDescHelp g_help = { + .summary = "generate shellcodes with rz_egg", }; -const RCmdDescHelp i_help = { - .summary = "get info about opened file from r_bin", +const RzCmdDescHelp i_help = { + .summary = "get info about opened file from rz_bin", }; -const RCmdDescHelp k_help = { +const RzCmdDescHelp k_help = { .summary = "run sdb-query", }; -const RCmdDescHelp l_help = { +const RzCmdDescHelp l_help = { .summary = "list files and directories", }; -const RCmdDescHelp j_help = { +const RzCmdDescHelp j_help = { .summary = "join the contents of the two files", }; -const RCmdDescHelp h_help = { +const RzCmdDescHelp h_help = { .summary = "show the top n number of line in file", }; -const RCmdDescHelp L_help = { +const RzCmdDescHelp L_help = { .summary = "list, unload, load r2 plugins", }; -const RCmdDescHelp m_help = { +const RzCmdDescHelp m_help = { .summary = "mountpoints commands", }; -const RCmdDescHelp o_help = { +const RzCmdDescHelp o_help = { .summary = "open file at optional address", }; -const RCmdDescHelp p_help = { +const RzCmdDescHelp p_help = { .summary = "print commands", }; -const RCmdDescHelp P_help = { +const RzCmdDescHelp P_help = { .summary = "project management utilities", }; -const RCmdDescHelp q_help = { +const RzCmdDescHelp q_help = { .summary = "quit program with a return value", }; -const RCmdDescHelp Q_help = { +const RzCmdDescHelp Q_help = { .summary = "quick quit", }; -const RCmdDescHelp colon_help = { +const RzCmdDescHelp colon_help = { .summary = "long commands (experimental)", }; -const RCmdDescHelp r_help = { +const RzCmdDescHelp rz_help = { .summary = "resize file", }; -const RCmdDescHelp s_help = { +const RzCmdDescHelp s_help = { .summary = "seek to address", }; -const RCmdDescHelp t_help = { +const RzCmdDescHelp t_help = { .summary = "types, noreturn, signatures, C parser and more", }; -const RCmdDescHelp T_help = { +const RzCmdDescHelp T_help = { .summary = "Text log utility (used to chat, sync, log, ...)", }; -const RCmdDescHelp u_help = { +const RzCmdDescHelp u_help = { .summary = "uname/undo seek/write", }; -const RCmdDescHelp pipein_help = { - .summary = "push escaped string into the RCons.readChar buffer", +const RzCmdDescHelp pipein_help = { + .summary = "push escaped string into the RzCons.readChar buffer", }; -const RCmdDescHelp V_help = { +const RzCmdDescHelp V_help = { .summary = "enter visual mode", }; -const RCmdDescHelp v_help = { +const RzCmdDescHelp v_help = { .summary = "enter visual panels mode", }; -const RCmdDescHelp w_group_help = { +const RzCmdDescHelp w_group_help = { .summary = "write commands", }; -const RCmdDescHelp w_help = { +const RzCmdDescHelp w_help = { .args_str = " ", .summary = "write string", }; -const RCmdDescHelp x_help = { +const RzCmdDescHelp x_help = { .summary = "alias for 'px' (print hexadecimal)", }; -const RCmdDescHelp y_help = { +const RzCmdDescHelp y_help = { .summary = "Yank/paste bytes from/to memory", }; -const RCmdDescHelp z_help = { +const RzCmdDescHelp z_help = { .summary = "zignatures management", }; // w0 helps -const RCmdDescHelp w0_help = { +const RzCmdDescHelp w0_help = { .summary = "Write 'len' bytes with value 0x00", .args_str = " [len]", .description = "Fill len bytes starting from the current offset with the value 0.", @@ -208,7 +208,7 @@ const RCmdDescHelp w0_help = { // w[1248][+-] helps -const RCmdDescExample w_incdec_help_examples[] = { +const RzCmdDescExample w_incdec_help_examples[] = { { .example = "w1+", .comment = "Add 1 to the byte at the current offset." }, { .example = "w2-", .comment = "Subtract 1 to the word at the current offset." }, { .example = "w4+ 0xdeadbeef", .comment = "Add 0xdeadbeef to the dword at the current offset." }, @@ -216,13 +216,13 @@ const RCmdDescExample w_incdec_help_examples[] = { { 0 }, }; -const RCmdDescHelp w_incdec_help = { +const RzCmdDescHelp w_incdec_help = { .summary = "increment/decrement byte,word..", .args_str = " [n]", .options = "<1248><+->", }; -const RCmdDescHelp w1_incdec_help = { +const RzCmdDescHelp w1_incdec_help = { .summary = "Increment/decrement a byte", .options = "<+->", .args_str = " [n]", @@ -230,21 +230,21 @@ const RCmdDescHelp w1_incdec_help = { .examples = w_incdec_help_examples, }; -const RCmdDescHelp w1_inc_help = { +const RzCmdDescHelp w1_inc_help = { .summary = "Increment a byte", .args_str = " [n]", .description = "Increment a byte at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w1_dec_help = { +const RzCmdDescHelp w1_dec_help = { .summary = "Decrement a byte", .args_str = " [n]", .description = "Decrement a byte at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w2_incdec_help = { +const RzCmdDescHelp w2_incdec_help = { .summary = "Increment/decrement a word", .options = "<+->", .args_str = " [n]", @@ -252,21 +252,21 @@ const RCmdDescHelp w2_incdec_help = { .examples = w_incdec_help_examples, }; -const RCmdDescHelp w2_inc_help = { +const RzCmdDescHelp w2_inc_help = { .summary = "Increment a word", .args_str = " [n]", .description = "Increment a word at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w2_dec_help = { +const RzCmdDescHelp w2_dec_help = { .summary = "Decrement a word", .args_str = " [n]", .description = "Decrement a word at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w4_incdec_help = { +const RzCmdDescHelp w4_incdec_help = { .summary = "Increment/decrement a dword", .options = "<+->", .args_str = " [n]", @@ -274,21 +274,21 @@ const RCmdDescHelp w4_incdec_help = { .examples = w_incdec_help_examples, }; -const RCmdDescHelp w4_inc_help = { +const RzCmdDescHelp w4_inc_help = { .summary = "Increment a dword", .args_str = " [n]", .description = "Increment a dword at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w4_dec_help = { +const RzCmdDescHelp w4_dec_help = { .summary = "Decrement a dword", .args_str = " [n]", .description = "Decrement a dword at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w8_incdec_help = { +const RzCmdDescHelp w8_incdec_help = { .summary = "Increment/decrement a qword", .options = "<+->", .args_str = " [n]", @@ -296,14 +296,14 @@ const RCmdDescHelp w8_incdec_help = { .examples = w_incdec_help_examples, }; -const RCmdDescHelp w8_inc_help = { +const RzCmdDescHelp w8_inc_help = { .summary = "Increment a qword", .args_str = " [n]", .description = "Increment a qword at the current offset by 1 or n, if specified", .examples = w_incdec_help_examples, }; -const RCmdDescHelp w8_dec_help = { +const RzCmdDescHelp w8_dec_help = { .summary = "Decrement a qword", .args_str = " [n]", .description = "Decrement a qword at the current offset by 1 or n, if specified", @@ -312,24 +312,24 @@ const RCmdDescHelp w8_dec_help = { // wB helps -const RCmdDescExample wB_help_examples[] = { +const RzCmdDescExample wB_help_examples[] = { { .example = "wB 0x20", .comment = "Sets the 5th bit at current offset, leaving all other bits intact." }, { 0 }, }; -const RCmdDescHelp wB_group_help = { +const RzCmdDescHelp wB_group_help = { .args_str = " [value]", .summary = "Set or unset bits with given value", }; -const RCmdDescHelp wB_help = { +const RzCmdDescHelp wB_help = { .summary = "Set bits with given value", .args_str = " [value]", .description = "Set the bits that are set in the value passed as arguments. 0 bits in the value argument are ignored, while the others are set at the current offset", .examples = wB_help_examples, }; -const RCmdDescHelp wB_minus_help = { +const RzCmdDescHelp wB_minus_help = { .summary = "Unset bits with given value", .args_str = " [value]", .description = "Unset the bits that are set in the value passed as arguments. 0 bits in the value argument are ignored, while the others are unset at the current offset" @@ -337,126 +337,126 @@ const RCmdDescHelp wB_minus_help = { // wv helps -const RCmdDescExample wv_help_examples[] = { +const RzCmdDescExample wv_help_examples[] = { { .example = "wv 0xdeadbeef", .comment = "Write the value 0xdeadbeef at current offset" }, { 0 }, }; -const RCmdDescHelp wv_group_help = { +const RzCmdDescHelp wv_group_help = { .args_str = " [value]", .summary = "Write value of given size", }; -const RCmdDescHelp wv_help = { +const RzCmdDescHelp wv_help = { .summary = "Write value as 4 - bytes / 8 - bytes based on value", .args_str = " [value]", .description = "Write the number passed as argument at the current offset as a 4 - bytes value or 8 - bytes value if the input is bigger than UT32_MAX, respecting the cfg.bigendian variable", .examples = wv_help_examples, }; -const RCmdDescHelp wv1_help = { +const RzCmdDescHelp wv1_help = { .summary = "Write value of 1 byte", .args_str = " [value]", .description = "Write the number passed as argument at the current offset as 1 - byte, respecting the cfg.bigendian variable", }; -const RCmdDescHelp wv2_help = { +const RzCmdDescHelp wv2_help = { .summary = "Write value of 2 bytes", .args_str = " [value]", .description = "Write the number passed as argument at the current offset as 2 - bytes, respecting the cfg.bigendian variable", }; -const RCmdDescHelp wv4_help = { +const RzCmdDescHelp wv4_help = { .summary = "Write value of 4 bytes", .args_str = " [value]", .description = "Write the number passed as argument at the current offset as 4 - bytes, respecting the cfg.bigendian variable", }; -const RCmdDescHelp wv8_help = { +const RzCmdDescHelp wv8_help = { .summary = "Write value of 8 byte", .args_str = " [value]", .description = "Write the number passed as argument at the current offset as 8 - bytes, respecting the cfg.bigendian variable", }; -const RCmdDescHelp w6_help = { +const RzCmdDescHelp w6_help = { .args_str = " |", .summary = "write base64 [d]ecoded or [e]ncoded string", }; -const RCmdDescHelp wh_help = { +const RzCmdDescHelp wh_help = { .args_str = " ", .summary = "whereis/which shell command", }; -const RCmdDescHelp we_help = { +const RzCmdDescHelp we_help = { .summary = "extend write operations (insert bytes instead of replacing)", }; -const RCmdDescHelp wp_help = { +const RzCmdDescHelp wp_help = { .args_str = " -|", .summary = "apply radare patch file. See wp? fmi", }; -const RCmdDescHelp wu_help = { +const RzCmdDescHelp wu_help = { .summary = "Apply unified hex patch (see output of cu)", }; -const RCmdDescHelp wr_help = { +const RzCmdDescHelp wr_help = { .args_str = " ", .summary = "write random bytes", }; -const RCmdDescHelp wA_help = { +const RzCmdDescHelp wA_help = { .args_str = " ", .summary = "alter/modify opcode at current seek (see wA?)", }; -const RCmdDescHelp wc_help = { +const RzCmdDescHelp wc_help = { .summary = "write cache commands", }; -const RCmdDescHelp wz_help = { +const RzCmdDescHelp wz_help = { .args_str = " ", .summary = "write zero terminated string (like w + \x00)", }; -const RCmdDescHelp wt_help = { +const RzCmdDescHelp wt_help = { .summary = "write to file (from current seek, blocksize or sz bytes)", }; -const RCmdDescHelp wf_help = { +const RzCmdDescHelp wf_help = { .summary = "write data from file, socket, offset", }; -const RCmdDescHelp ww_help = { +const RzCmdDescHelp ww_help = { .args_str = " ", .summary = "write wide string", }; -const RCmdDescHelp wx_help = { +const RzCmdDescHelp wx_help = { .args_str = " ", .summary = "write two intel nops (from wxfile or wxseek)", }; -const RCmdDescHelp wa_help = { +const RzCmdDescHelp wa_help = { .summary = "write opcode, separated by ';' (use '\"' around the command)", }; -const RCmdDescHelp wb_help = { +const RzCmdDescHelp wb_help = { .args_str = " ", .summary = "fill current block with cyclic hexstring", }; -const RCmdDescHelp wm_help = { +const RzCmdDescHelp wm_help = { .args_str = " ", .summary = "set binary mask hexpair to be used as cyclic write mask", }; -const RCmdDescHelp wo_help = { +const RzCmdDescHelp wo_help = { .summary = "write in block with operation. 'wo?' fmi", }; -const RCmdDescHelp wd_help = { +const RzCmdDescHelp wd_help = { .summary = "duplicate N bytes from offset at current seek (memcpy) (see y?)", }; -const RCmdDescHelp ws_help = { +const RzCmdDescHelp ws_help = { .summary = "write 1 byte for length and then the string", }; diff --git a/librz/core/cmd_helps.h b/librz/core/cmd_helps.h new file mode 100644 index 0000000000..62911f6740 --- /dev/null +++ b/librz/core/cmd_helps.h @@ -0,0 +1,110 @@ +#ifndef R_CMD_HELPS_H_ +#define R_CMD_HELPS_H_ + +#include + +extern const RzCmdDescHelp system_help; +extern const RzCmdDescHelp underscore_help; +extern const RzCmdDescHelp hash_help; +extern const RzCmdDescHelp alias_help; +extern const RzCmdDescHelp env_help; +extern const RzCmdDescHelp tasks_help; +extern const RzCmdDescHelp macro_help; +extern const RzCmdDescHelp pointer_help; +extern const RzCmdDescHelp stdin_help; +extern const RzCmdDescHelp interpret_help; +extern const RzCmdDescHelp search_help; +extern const RzCmdDescHelp rap_help; +extern const RzCmdDescHelp help_help; +extern const RzCmdDescHelp rap_run_help; +extern const RzCmdDescHelp zero_help; +extern const RzCmdDescHelp anal_help; +extern const RzCmdDescHelp b_help; +extern const RzCmdDescHelp c_help; +extern const RzCmdDescHelp C_help; +extern const RzCmdDescHelp d_help; +extern const RzCmdDescHelp e_help; +extern const RzCmdDescHelp f_help; +extern const RzCmdDescHelp g_help; +extern const RzCmdDescHelp i_help; +extern const RzCmdDescHelp k_help; +extern const RzCmdDescHelp l_help; +extern const RzCmdDescHelp j_help; +extern const RzCmdDescHelp h_help; +extern const RzCmdDescHelp L_help; +extern const RzCmdDescHelp m_help; +extern const RzCmdDescHelp o_help; +extern const RzCmdDescHelp p_help; +extern const RzCmdDescHelp P_help; +extern const RzCmdDescHelp q_help; +extern const RzCmdDescHelp Q_help; +extern const RzCmdDescHelp colon_help; +extern const RzCmdDescHelp rz_help; +extern const RzCmdDescHelp s_help; +extern const RzCmdDescHelp t_help; +extern const RzCmdDescHelp T_help; +extern const RzCmdDescHelp u_help; +extern const RzCmdDescHelp pipein_help; +extern const RzCmdDescHelp V_help; +extern const RzCmdDescHelp v_help; +extern const RzCmdDescHelp w_help; +extern const RzCmdDescHelp w_group_help; +extern const RzCmdDescHelp x_help; +extern const RzCmdDescHelp y_help; +extern const RzCmdDescHelp z_help; + +// w0 helps + +extern const RzCmdDescHelp w0_help; + +// w[1248][+-] helps + +extern const RzCmdDescHelp w_incdec_help; +extern const RzCmdDescHelp w1_incdec_help; +extern const RzCmdDescHelp w1_inc_help; +extern const RzCmdDescHelp w1_dec_help; +extern const RzCmdDescHelp w2_incdec_help; +extern const RzCmdDescHelp w2_inc_help; +extern const RzCmdDescHelp w2_dec_help; +extern const RzCmdDescHelp w4_incdec_help; +extern const RzCmdDescHelp w4_inc_help; +extern const RzCmdDescHelp w4_dec_help; +extern const RzCmdDescHelp w8_incdec_help; +extern const RzCmdDescHelp w8_inc_help; +extern const RzCmdDescHelp w8_dec_help; + +// wB helps + +extern const RzCmdDescHelp wB_group_help; +extern const RzCmdDescHelp wB_help; +extern const RzCmdDescHelp wB_minus_help; + +// wv helps + +extern const RzCmdDescHelp wv_group_help; +extern const RzCmdDescHelp wv_help; +extern const RzCmdDescHelp wv1_help; +extern const RzCmdDescHelp wv2_help; +extern const RzCmdDescHelp wv4_help; +extern const RzCmdDescHelp wv8_help; + +extern const RzCmdDescHelp w6_help; +extern const RzCmdDescHelp wh_help; +extern const RzCmdDescHelp we_help; +extern const RzCmdDescHelp wp_help; +extern const RzCmdDescHelp wu_help; +extern const RzCmdDescHelp wr_help; +extern const RzCmdDescHelp wA_help; +extern const RzCmdDescHelp wc_help; +extern const RzCmdDescHelp wz_help; +extern const RzCmdDescHelp wt_help; +extern const RzCmdDescHelp wf_help; +extern const RzCmdDescHelp ww_help; +extern const RzCmdDescHelp wx_help; +extern const RzCmdDescHelp wa_help; +extern const RzCmdDescHelp wb_help; +extern const RzCmdDescHelp wm_help; +extern const RzCmdDescHelp wo_help; +extern const RzCmdDescHelp wd_help; +extern const RzCmdDescHelp ws_help; +#endif diff --git a/libr/core/cmd_info.c b/librz/core/cmd_info.c similarity index 64% rename from libr/core/cmd_info.c rename to librz/core/cmd_info.c index f8882ed88f..8787b5a712 100644 --- a/libr/core/cmd_info.c +++ b/librz/core/cmd_info.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ #include -#include "r_bin.h" -#include "r_config.h" -#include "r_cons.h" -#include "r_core.h" +#include "rz_bin.h" +#include "rz_config.h" +#include "rz_cons.h" +#include "rz_core.h" #include "../bin/pdb/pdb_downloader.h" static const char *help_msg_i[] = { - "Usage: i", "", "Get info from opened file (see rabin2's manpage)", + "Usage: i", "", "Get info from opened file (see rz_bin's manpage)", "Output mode:", "", "", "'*'", "", "Output in radare commands", "'j'", "", "Output in json", @@ -77,7 +77,7 @@ static const char *help_msg_id[] = { NULL }; -static void cmd_info_init(RCore *core, RCmdDesc *parent) { +static void cmd_info_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, i); DEFINE_CMD_DESCRIPTOR (core, id); } @@ -96,27 +96,27 @@ static void pair(const char *a, const char *b) { al = 0; } ws[al] = 0; - r_cons_printf ("%s%s%s\n", a, ws, b); + rz_cons_printf ("%s%s%s\n", a, ws, b); } -static bool demangle_internal(RCore *core, const char *lang, const char *s) { +static bool demangle_internal(RzCore *core, const char *lang, const char *s) { char *res = NULL; - int type = r_bin_demangle_type (lang); + int type = rz_bin_demangle_type (lang); switch (type) { - case R_BIN_NM_CXX: res = r_bin_demangle_cxx (core->bin->cur, s, 0); break; - case R_BIN_NM_JAVA: res = r_bin_demangle_java (s); break; - case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, s); break; - case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (s, core->bin->demanglercmd); break; - case R_BIN_NM_DLANG: res = r_bin_demangle_plugin (core->bin, "dlang", s); break; - case R_BIN_NM_MSVC: res = r_bin_demangle_msvc (s); break; - case R_BIN_NM_RUST: res = r_bin_demangle_rust (core->bin->cur, s, 0); break; + case R_BIN_NM_CXX: res = rz_bin_demangle_cxx (core->bin->cur, s, 0); break; + case R_BIN_NM_JAVA: res = rz_bin_demangle_java (s); break; + case R_BIN_NM_OBJC: res = rz_bin_demangle_objc (NULL, s); break; + case R_BIN_NM_SWIFT: res = rz_bin_demangle_swift (s, core->bin->demanglercmd); break; + case R_BIN_NM_DLANG: res = rz_bin_demangle_plugin (core->bin, "dlang", s); break; + case R_BIN_NM_MSVC: res = rz_bin_demangle_msvc (s); break; + case R_BIN_NM_RUST: res = rz_bin_demangle_rust (core->bin->cur, s, 0); break; default: - r_bin_demangle_list (core->bin); + rz_bin_demangle_list (core->bin); return true; } if (res) { if (*res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); } free (res); return false; @@ -124,14 +124,14 @@ static bool demangle_internal(RCore *core, const char *lang, const char *s) { return true; } -static bool demangle(RCore *core, const char *s) { - r_return_val_if_fail (core && s, false); +static bool demangle(RzCore *core, const char *s) { + rz_return_val_if_fail (core && s, false); const char *ss = strchr (s, ' '); if (!*s) { return false; } if (!ss) { - const char *lang = r_config_get (core->config, "bin.lang"); + const char *lang = rz_config_get (core->config, "bin.lang"); demangle_internal (core, lang, s); return true; } @@ -143,14 +143,14 @@ static bool demangle(RCore *core, const char *s) { return true; } -static void cmd_info_here(RCore *core, int mode) { - RCoreItem *item = r_core_item_at (core, core->offset); +static void cmd_info_here(RzCore *core, int mode) { + RzCoreItem *item = rz_core_item_at (core, core->offset); if (item) { PJ *pj = pj_new (); pj_o (pj); pj_ks (pj, "type", item->type); - pj_ks (pj, "perm", r_str_rwx_i (item->perm)); + pj_ks (pj, "perm", rz_str_rwx_i (item->perm)); pj_kn (pj, "size", item->size); pj_kn (pj, "addr", item->addr); pj_kn (pj, "next", item->next); @@ -164,19 +164,19 @@ static void cmd_info_here(RCore *core, int mode) { if (item->comment) { pj_ks (pj, "comment", item->comment); } - RListIter *iter; - RAnalRef *ref; + RzListIter *iter; + RzAnalRef *ref; if (item->data) { pj_ks (pj, "data", item->data); } { - RList *refs = r_anal_refs_get (core->anal, core->offset); - if (refs && r_list_length (refs) > 0) { + RzList *refs = rz_anal_refs_get (core->anal, core->offset); + if (refs && rz_list_length (refs) > 0) { pj_k (pj, "refs"); pj_a (pj); - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { pj_o (pj); - pj_ks (pj, "type", r_anal_ref_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_ref_type_tostring (ref->type)); pj_kn (pj, "addr", ref->addr); pj_end (pj); } @@ -184,13 +184,13 @@ static void cmd_info_here(RCore *core, int mode) { } } { - RList *refs = r_anal_xrefs_get (core->anal, core->offset); - if (refs && r_list_length (refs) > 0) { + RzList *refs = rz_anal_xrefs_get (core->anal, core->offset); + if (refs && rz_list_length (refs) > 0) { pj_k (pj, "xrefs"); pj_a (pj); - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { pj_o (pj); - pj_ks (pj, "type", r_anal_ref_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_ref_type_tostring (ref->type)); pj_kn (pj, "addr", ref->addr); pj_end (pj); } @@ -199,24 +199,24 @@ static void cmd_info_here(RCore *core, int mode) { } pj_end (pj); char *s = pj_drain (pj); - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); - r_core_item_free (item); + rz_core_item_free (item); } } #define STR(x) (x)? (x): "" -static void r_core_file_info(RCore *core, int mode) { +static void rz_core_file_info(RzCore *core, int mode) { const char *fn = NULL; - int dbg = r_config_get_i (core->config, "cfg.debug"); - bool io_cache = r_config_get_i (core->config, "io.cache"); - RBinInfo *info = r_bin_get_info (core->bin); - RBinFile *binfile = r_bin_cur (core->bin); - int fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); - RBinPlugin *plugin = r_bin_file_cur_plugin (binfile); + int dbg = rz_config_get_i (core->config, "cfg.debug"); + bool io_cache = rz_config_get_i (core->config, "io.cache"); + RBinInfo *info = rz_bin_get_info (core->bin); + RBinFile *binfile = rz_bin_cur (core->bin); + int fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); + RBinPlugin *plugin = rz_bin_file_cur_plugin (binfile); if (mode == R_MODE_JSON) { - r_cons_printf ("{"); + rz_cons_printf ("{"); } if (mode == R_MODE_RADARE) { return; @@ -229,7 +229,7 @@ static void r_core_file_info(RCore *core, int mode) { fn = info->file; if (mode == R_MODE_JSON) { comma = ","; - r_cons_printf ("\"type\":\"%s\"", STR (info->type)); + rz_cons_printf ("\"type\":\"%s\"", STR (info->type)); } } else { fn = desc ? desc->name: NULL; @@ -244,8 +244,8 @@ static void r_core_file_info(RCore *core, int mode) { } } { - char *escapedFile = r_str_escape_utf8_for_json (uri, -1); - r_cons_printf ("%s\"file\":\"%s\"", comma, escapedFile); + char *escapedFile = rz_str_escape_utf8_for_json (uri, -1); + rz_cons_printf ("%s\"file\":\"%s\"", comma, escapedFile); comma = ","; free (escapedFile); } @@ -253,35 +253,35 @@ static void r_core_file_info(RCore *core, int mode) { dbg = R_PERM_WX; } if (desc) { - ut64 fsz = r_io_desc_size (desc); - r_cons_printf ("%s\"fd\":%d", comma, desc->fd); + ut64 fsz = rz_io_desc_size (desc); + rz_cons_printf ("%s\"fd\":%d", comma, desc->fd); comma = ","; if (fsz != UT64_MAX) { char humansz[8]; - r_cons_printf (",\"size\":%"PFMT64d, fsz); - r_num_units (humansz, sizeof (humansz), fsz); - r_cons_printf (",\"humansz\":\"%s\"", humansz); + rz_cons_printf (",\"size\":%"PFMT64d, fsz); + rz_num_units (humansz, sizeof (humansz), fsz); + rz_cons_printf (",\"humansz\":\"%s\"", humansz); } - r_cons_printf (",\"iorw\":%s", r_str_bool ( io_cache || desc->perm & R_PERM_W)); - r_cons_printf (",\"mode\":\"%s\"", r_str_rwx_i (desc->perm & R_PERM_RWX)); + rz_cons_printf (",\"iorw\":%s", rz_str_bool ( io_cache || desc->perm & R_PERM_W)); + rz_cons_printf (",\"mode\":\"%s\"", rz_str_rwx_i (desc->perm & R_PERM_RWX)); if (desc->referer && *desc->referer) { - r_cons_printf (",\"referer\":\"%s\"", desc->referer); + rz_cons_printf (",\"referer\":\"%s\"", desc->referer); } } - r_cons_printf ("%s\"block\":%d", comma, core->blocksize); + rz_cons_printf ("%s\"block\":%d", comma, core->blocksize); if (binfile) { if (binfile->curxtr) { - r_cons_printf (",\"packet\":\"%s\"", + rz_cons_printf (",\"packet\":\"%s\"", binfile->curxtr->name); } if (plugin) { - r_cons_printf (",\"format\":\"%s\"", + rz_cons_printf (",\"format\":\"%s\"", plugin->name); } } - r_cons_printf ("}"); + rz_cons_printf ("}"); } else if (desc && mode != R_MODE_SIMPLE) { - //r_cons_printf ("# Core file info\n"); + //rz_cons_printf ("# Core file info\n"); if (dbg) { dbg = R_PERM_WX; } @@ -289,29 +289,29 @@ static void r_core_file_info(RCore *core, int mode) { pair ("fd", sdb_fmt ("%d", desc->fd)); } if (fn || (desc && desc->uri)) { - char *escaped = r_str_escape_utf8_keep_printable (fn? fn: desc->uri, false, false); + char *escaped = rz_str_escape_utf8_keep_printable (fn? fn: desc->uri, false, false); if (escaped) { pair ("file", escaped); free (escaped); } } if (desc) { - ut64 fsz = r_io_desc_size (desc); + ut64 fsz = rz_io_desc_size (desc); if (fsz != UT64_MAX) { char humansz[8]; pair ("size", sdb_itoca (fsz)); - r_num_units (humansz, sizeof (humansz), fsz); + rz_num_units (humansz, sizeof (humansz), fsz); pair ("humansz", humansz); } } if (desc) { - pair ("mode", r_str_rwx_i (desc->perm & R_PERM_RWX)); + pair ("mode", rz_str_rwx_i (desc->perm & R_PERM_RWX)); } if (plugin) { pair ("format", plugin->name); } if (desc) { - pair ("iorw", r_str_bool (io_cache || desc->perm & R_PERM_W)); + pair ("iorw", rz_str_bool (io_cache || desc->perm & R_PERM_W)); } pair ("block", sdb_fmt ("0x%x", core->blocksize)); @@ -329,13 +329,13 @@ static void r_core_file_info(RCore *core, int mode) { } static int bin_is_executable(RBinObject *obj){ - RListIter *it; + RzListIter *it; RBinSection *sec; if (obj) { if (obj->info && obj->info->arch) { return true; } - r_list_foreach (obj->sections, it, sec){ + rz_list_foreach (obj->sections, it, sec){ if (sec->perm & R_PERM_X) { return true; } @@ -344,58 +344,58 @@ static int bin_is_executable(RBinObject *obj){ return false; } -static void cmd_info_bin(RCore *core, int va, int mode) { - RBinObject *obj = r_bin_cur_object (core->bin); +static void cmd_info_bin(RzCore *core, int va, int mode) { + RBinObject *obj = rz_bin_cur_object (core->bin); int array = 0; if (core->file) { if ((mode & R_MODE_JSON) && !(mode & R_MODE_ARRAY)) { mode = R_MODE_JSON; - r_cons_strcat ("{\"core\":"); + rz_cons_strcat ("{\"core\":"); } if ((mode & R_MODE_JSON) && (mode & R_MODE_ARRAY)) { mode = R_MODE_JSON; array = 1; - r_cons_strcat (",\"core\":"); + rz_cons_strcat (",\"core\":"); } - r_core_file_info (core, mode); + rz_core_file_info (core, mode); if (bin_is_executable (obj)) { if ((mode & R_MODE_JSON)) { - r_cons_strcat (",\"bin\":"); + rz_cons_strcat (",\"bin\":"); } - r_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, NULL); + rz_core_bin_info (core, R_CORE_BIN_ACC_INFO, mode, va, NULL, NULL); } if ((mode & R_MODE_JSON) && array == 0) { - r_cons_strcat ("}\n"); + rz_cons_strcat ("}\n"); } } else { eprintf ("No file selected\n"); } } -static void playMsg(RCore *core, const char *n, int len) { - if (r_config_get_i (core->config, "scr.tts")) { +static void playMsg(RzCore *core, const char *n, int len) { + if (rz_config_get_i (core->config, "scr.tts")) { if (len > 0) { - char *s = r_str_newf ("%d %s", len, n); - r_sys_tts (s, true); + char *s = rz_str_newf ("%d %s", len, n); + rz_sys_tts (s, true); free (s); } else if (len == 0) { - char *s = r_str_newf ("there are no %s", n); - r_sys_tts (s, true); + char *s = rz_str_newf ("there are no %s", n); + rz_sys_tts (s, true); free (s); } } } -static bool is_equal_file_hashes(RList *lfile_hashes, RList *rfile_hashes, bool *equal) { - r_return_val_if_fail (lfile_hashes, false); - r_return_val_if_fail (rfile_hashes, false); - r_return_val_if_fail (equal, false); +static bool is_equal_file_hashes(RzList *lfile_hashes, RzList *rfile_hashes, bool *equal) { + rz_return_val_if_fail (lfile_hashes, false); + rz_return_val_if_fail (rfile_hashes, false); + rz_return_val_if_fail (equal, false); *equal = true; RBinFileHash *fh_l, *fh_r; - RListIter *hiter_l, *hiter_r; - r_list_foreach (lfile_hashes, hiter_l, fh_l) { - r_list_foreach (rfile_hashes, hiter_r, fh_r) { + RzListIter *hiter_l, *hiter_r; + rz_list_foreach (lfile_hashes, hiter_l, fh_l) { + rz_list_foreach (rfile_hashes, hiter_r, fh_r) { if (strcmp (fh_l->type, fh_r->type)) { continue; } @@ -408,37 +408,37 @@ static bool is_equal_file_hashes(RList *lfile_hashes, RList *rfile_hashes, bool return true; } -static int __r_core_bin_reload(RCore *r, const char *file, ut64 baseaddr) { +static int __r_core_bin_reload(RzCore *r, const char *file, ut64 baseaddr) { int result = 0; - RCoreFile *cf = r_core_file_cur (r); + RzCoreFile *cf = rz_core_file_cur (r); if (cf) { - RBinFile *bf = r_bin_file_find_by_fd (r->bin, cf->fd); + RBinFile *bf = rz_bin_file_find_by_fd (r->bin, cf->fd); if (bf) { - result = r_bin_reload (r->bin, bf->id, baseaddr); + result = rz_bin_reload (r->bin, bf->id, baseaddr); } } - r_core_bin_set_env (r, r_bin_cur (r->bin)); + rz_core_bin_set_env (r, rz_bin_cur (r->bin)); return result; } static bool isKnownPackage(const char *cn) { if (*cn == 'L') { - if (r_str_startswith (cn, "Lkotlin")) { + if (rz_str_startswith (cn, "Lkotlin")) { return true; } - if (r_str_startswith (cn, "Lcom/google")) { + if (rz_str_startswith (cn, "Lcom/google")) { return true; } - if (r_str_startswith (cn, "Lcom/facebook")) { + if (rz_str_startswith (cn, "Lcom/facebook")) { return true; } - if (r_str_startswith (cn, "Lokhttp")) { + if (rz_str_startswith (cn, "Lokhttp")) { return true; } - if (r_str_startswith (cn, "Landroid")) { + if (rz_str_startswith (cn, "Landroid")) { return true; } - if (r_str_startswith (cn, "Lokio")) { + if (rz_str_startswith (cn, "Lokio")) { return true; } } @@ -446,10 +446,10 @@ static bool isKnownPackage(const char *cn) { } static int cmd_info(void *data, const char *input) { - RCore *core = (RCore *) data; - bool newline = r_cons_is_interactive (); - int fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + RzCore *core = (RzCore *) data; + bool newline = rz_cons_is_interactive (); + int fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); int i, va = core->io->va || core->bin->is_debugger; int mode = 0; //R_MODE_SIMPLE; bool rdump = false; @@ -480,7 +480,7 @@ static int cmd_info(void *data, const char *input) { } } if (is_array && !is_izzzj) { - r_cons_printf ("{"); + rz_cons_printf ("{"); } if (!*input) { cmd_info_bin (core, va, mode); @@ -501,13 +501,13 @@ static int cmd_info(void *data, const char *input) { if (tmp) { *tmp = 0; } - r_core_cmdf (core, "i?~& i%s", prefix); + rz_core_cmdf (core, "i?~& i%s", prefix); free (prefix); goto done; } R_FREE (core->table_query); if (space && *space == ' ') { - core->table_query = r_str_trim_dup (space + 1); + core->table_query = rz_str_trim_dup (space + 1); } while (*input) { if (*input == ' ') { @@ -516,22 +516,22 @@ static int cmd_info(void *data, const char *input) { switch (*input) { case 'b': // "ib" { - ut64 baddr = r_config_get_i (core->config, "bin.baddr"); + ut64 baddr = rz_config_get_i (core->config, "bin.baddr"); if (input[1] == ' ') { - baddr = r_num_math (core->num, input + 1); + baddr = rz_num_math (core->num, input + 1); } // XXX: this will reload the bin using the buffer. // An assumption is made that assumes there is an underlying // plugin that will be used to load the bin (e.g. malloc://) // TODO: Might be nice to reload a bin at a specified offset? __r_core_bin_reload (core, NULL, baddr); - r_core_block_read (core); + rz_core_block_read (core); newline = false; } break; case 'k': // "ik" { - RBinObject *o = r_bin_cur_object (core->bin); + RBinObject *o = rz_bin_cur_object (core->bin); db = o? o->kv: NULL; //:eprintf ("db = %p\n", db); switch (input[1]) { @@ -539,20 +539,20 @@ static int cmd_info(void *data, const char *input) { if (db) { char *o = sdb_querys (db, NULL, 0, input + 3); if (o && *o) { - r_cons_print (o); + rz_cons_print (o); } free (o); } break; case '*': - r_core_bin_export_info (core, R_MODE_RADARE); + rz_core_bin_export_info (core, R_MODE_RADARE); break; case '.': case ' ': if (db) { char *o = sdb_querys (db, NULL, 0, input + 2); if (o && *o) { - r_cons_print (o); + rz_cons_print (o); } free (o); } @@ -561,7 +561,7 @@ static int cmd_info(void *data, const char *input) { if (db) { char *o = sdb_querys (db, NULL, 0, "*"); if (o && *o) { - r_cons_print (o); + rz_cons_print (o); } free (o); } @@ -581,23 +581,23 @@ static int cmd_info(void *data, const char *input) { return 0; } const char *fn = input[1] == ' '? input + 2: desc->name; - ut64 baddr = r_config_get_i (core->config, "bin.baddr"); - r_core_bin_load (core, fn, baddr); + ut64 baddr = rz_config_get_i (core->config, "bin.baddr"); + rz_core_bin_load (core, fn, baddr); } break; #define RBININFO(n,x,y,z)\ if (is_array) {\ if (is_array == 1) { is_array++;\ - } else { r_cons_printf (",");}\ - r_cons_printf ("\"%s\":",n);\ + } else { rz_cons_printf (",");}\ + rz_cons_printf ("\"%s\":",n);\ }\ if (z) { playMsg (core, n, z);}\ - r_core_bin_info (core, x, mode, va, NULL, y); + rz_core_bin_info (core, x, mode, va, NULL, y); case 'A': // "iA" newline = false; { int mode = (input[1] == 'j')? 'j': 1; - r_bin_list_archs (core->bin, mode); + rz_bin_list_archs (core->bin, mode); } break; case 'E': // "iE" @@ -614,56 +614,56 @@ static int cmd_info(void *data, const char *input) { } case 't': // "it" { - ut64 limit = r_config_get_i (core->config, "bin.hashlimit"); - RBinInfo *info = r_bin_get_info (core->bin); + ut64 limit = rz_config_get_i (core->config, "bin.hashlimit"); + RBinInfo *info = rz_bin_get_info (core->bin); if (!info) { - eprintf ("r_bin_get_info: Cannot get bin info\n"); + eprintf ("rz_bin_get_info: Cannot get bin info\n"); return 0; } - RList *new_hashes = r_bin_file_compute_hashes (core->bin, limit); - RList *old_hashes = r_bin_file_set_hashes (core->bin, new_hashes); + RzList *new_hashes = rz_bin_file_compute_hashes (core->bin, limit); + RzList *old_hashes = rz_bin_file_set_hashes (core->bin, new_hashes); bool equal = true; - if (!r_list_empty (new_hashes) && !r_list_empty (old_hashes)) { + if (!rz_list_empty (new_hashes) && !rz_list_empty (old_hashes)) { if (!is_equal_file_hashes (new_hashes, old_hashes, &equal)) { eprintf ("is_equal_file_hashes: Cannot compare file hashes\n"); - r_list_free (old_hashes); + rz_list_free (old_hashes); return 0; } } RBinFileHash *fh_old, *fh_new; - RListIter *hiter_old, *hiter_new; + RzListIter *hiter_old, *hiter_new; const bool is_json = input[1] == 'j'; // "itj" if (is_json) { // "itj" PJ *pj = pj_new (); if (!pj) { eprintf ("JSON mode failed\n"); - r_list_free (old_hashes); + rz_list_free (old_hashes); return 0; } pj_o (pj); - r_list_foreach (new_hashes, hiter_new, fh_new) { + rz_list_foreach (new_hashes, hiter_new, fh_new) { pj_ks (pj, fh_new->type, fh_new->hex); } if (!equal) { // print old hashes prefixed with `o` character like `omd5` and `isha1` - r_list_foreach (old_hashes, hiter_old, fh_old) { - char *key = r_str_newf ("o%s", fh_old->type); + rz_list_foreach (old_hashes, hiter_old, fh_old) { + char *key = rz_str_newf ("o%s", fh_old->type); pj_ks (pj, key, fh_old->hex); free (key); } } pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } else { // "it" if (!equal) { eprintf ("File has been modified.\n"); - hiter_new = r_list_iterator (new_hashes); - hiter_old = r_list_iterator (old_hashes); - while (r_list_iter_next (hiter_new) && r_list_iter_next (hiter_old)) { - fh_new = (RBinFileHash *)r_list_iter_get (hiter_new); - fh_old = (RBinFileHash *)r_list_iter_get (hiter_old); + hiter_new = rz_list_iterator (new_hashes); + hiter_old = rz_list_iterator (old_hashes); + while (rz_list_iter_next (hiter_new) && rz_list_iter_next (hiter_old)) { + fh_new = (RBinFileHash *)rz_list_iter_get (hiter_new); + fh_old = (RBinFileHash *)rz_list_iter_get (hiter_old); if (strcmp (fh_new->type, fh_old->type)) { eprintf ("Wrong file hashes structure"); } @@ -677,13 +677,13 @@ static int cmd_info(void *data, const char *input) { } } } else { // hashes are equal - r_list_foreach (new_hashes, hiter_new, fh_new) { - r_cons_printf ("%s %s\n", fh_new->type, fh_new->hex); + rz_list_foreach (new_hashes, hiter_new, fh_new) { + rz_cons_printf ("%s %s\n", fh_new->type, fh_new->hex); } } newline = false; } - r_list_free (old_hashes); + rz_list_free (old_hashes); } break; case 'Z': // "iZ" @@ -692,10 +692,10 @@ static int cmd_info(void *data, const char *input) { case 'O': // "iO" switch (input[1]) { case ' ': - r_sys_cmdf ("rabin2 -O \"%s\" \"%s\"", r_str_trim_head_ro (input + 1), desc->name); + rz_sys_cmdf ("rz_bin -O \"%s\" \"%s\"", rz_str_trim_head_ro (input + 1), desc->name); break; default: - r_sys_cmdf ("rabin2 -O help"); + rz_sys_cmdf ("rz_bin -O help"); break; } return 0; @@ -724,14 +724,14 @@ static int cmd_info(void *data, const char *input) { } else if (input[1] == 'j' && input[2] == '.') { mode = R_MODE_JSON; } - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (mode == R_MODE_RADARE || mode == R_MODE_JSON || mode == R_MODE_SIMPLE) { if (input[param_shift + 1]) { param_shift ++; } } RBININFO (name, action, input + 1 + param_shift, - (obj && obj->sections)? r_list_length (obj->sections): 0); + (obj && obj->sections)? rz_list_length (obj->sections): 0); } //we move input until get '\0' while (*(++input)) ; @@ -748,8 +748,8 @@ static int cmd_info(void *data, const char *input) { RBININFO ("fields", R_CORE_BIN_ACC_FIELDS, NULL, 0); break; case 'l': { // "il" - RBinObject *obj = r_bin_cur_object (core->bin); - RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL, (obj && obj->libs)? r_list_length (obj->libs): 0); + RBinObject *obj = rz_bin_cur_object (core->bin); + RBININFO ("libs", R_CORE_BIN_ACC_LIBS, NULL, (obj && obj->libs)? rz_list_length (obj->libs): 0); break; } case 'L': { // "iL" @@ -759,29 +759,29 @@ static int cmd_info(void *data, const char *input) { if (ptr && ptr[1]) { const char *plugin_name = ptr + 1; if (is_array) { - r_cons_printf ("\"plugin\": "); + rz_cons_printf ("\"plugin\": "); } - r_bin_list_plugin (core->bin, plugin_name, json); + rz_bin_list_plugin (core->bin, plugin_name, json); } else { - r_bin_list (core->bin, json); + rz_bin_list (core->bin, json); } newline = false; goto done; } case 's': { // "is" - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); // Case for isj. if (input[1] == 'j' && input[2] == '.') { mode = R_MODE_JSON; - RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, (obj && obj->symbols)? r_list_length (obj->symbols): 0); + RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, (obj && obj->symbols)? rz_list_length (obj->symbols): 0); } else if (input[1] == 'q' && input[2] == 'q') { mode = R_MODE_SIMPLEST; - RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? r_list_length (obj->symbols): 0); + RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? rz_list_length (obj->symbols): 0); } else if (input[1] == 'q' && input[2] == '.') { mode = R_MODE_SIMPLE; RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 2, 0); } else { - RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? r_list_length (obj->symbols): 0); + RBININFO ("symbols", R_CORE_BIN_ACC_SYMBOLS, input + 1, (obj && obj->symbols)? rz_list_length (obj->symbols): 0); } while (*(++input)) ; input--; @@ -810,26 +810,26 @@ static int cmd_info(void *data, const char *input) { switch (input[2]) { case ' ': // "idp file.pdb" - r_core_cmdf (core, ".idpi* %s", input + 3); + rz_core_cmdf (core, ".idpi* %s", input + 3); while (input[2]) { input++; } break; case '\0': // "idp" - r_core_cmd0 (core, ".idpi*"); + rz_core_cmd0 (core, ".idpi*"); break; case 'd': // "idpd" - pdbopts.user_agent = (char*) r_config_get (core->config, "pdb.useragent"); - pdbopts.extract = r_config_get_i (core->config, "pdb.extract"); - pdbopts.symbol_store_path = (char*) r_config_get (core->config, "pdb.symstore"); - char *str = strdup (r_config_get (core->config, "pdb.server")); - RList *server_l = r_str_split_list (str, ";", 0); - RListIter *it; + pdbopts.user_agent = (char*) rz_config_get (core->config, "pdb.useragent"); + pdbopts.extract = rz_config_get_i (core->config, "pdb.extract"); + pdbopts.symbol_store_path = (char*) rz_config_get (core->config, "pdb.symstore"); + char *str = strdup (rz_config_get (core->config, "pdb.server")); + RzList *server_l = rz_str_split_list (str, ";", 0); + RzListIter *it; char *server; int r = 1; - r_list_foreach (server_l, it, server) { + rz_list_foreach (server_l, it, server) { pdbopts.symbol_server = server; - r = r_bin_pdb_download (core, 0, NULL, &pdbopts); + r = rz_bin_pdb_download (core, 0, NULL, &pdbopts); if (!r) { break; } @@ -838,17 +838,17 @@ static int cmd_info(void *data, const char *input) { eprintf ("Error while downloading pdb file\n"); } free (str); - r_list_free (server_l); + rz_list_free (server_l); input++; break; case 'i': // "idpi" - info = r_bin_get_info (core->bin); + info = rz_bin_get_info (core->bin); filename = strchr (input, ' '); while (input[2]) input++; if (filename) { *filename++ = '\0'; filename = strdup (filename); - file_found = r_file_exists (filename); + file_found = rz_file_exists (filename); } else { /* Autodetect local file */ if (!info || !info->debug_file_name) { @@ -856,18 +856,18 @@ static int cmd_info(void *data, const char *input) { break; } // Check raw path for debug filename - file_found = r_file_exists (r_file_basename (info->debug_file_name)); + file_found = rz_file_exists (rz_file_basename (info->debug_file_name)); if (file_found) { - filename = strdup (r_file_basename (info->debug_file_name)); + filename = strdup (rz_file_basename (info->debug_file_name)); } else { // Check debug filename basename in current directory - char* basename = (char*) r_file_basename (info->debug_file_name); - file_found = r_file_exists (basename); + char* basename = (char*) rz_file_basename (info->debug_file_name); + file_found = rz_file_exists (basename); if (!file_found) { // Check if debug file is in file directory - char* dir = r_file_dirname (core->bin->cur->file); - filename = r_str_newf ("%s/%s", dir, basename); - file_found = r_file_exists (filename); + char* dir = rz_file_dirname (core->bin->cur->file); + filename = rz_str_newf ("%s/%s", dir, basename); + file_found = rz_file_exists (filename); } else { filename = strdup (basename); } @@ -875,11 +875,11 @@ static int cmd_info(void *data, const char *input) { // Last chance: Check if file is in downstream symbol store if (!file_found) { - const char* symstore_path = r_config_get (core->config, "pdb.symstore"); - const char *base_file = r_file_basename (info->debug_file_name); - char* pdb_path = r_str_newf ("%s" R_SYS_DIR "%s" R_SYS_DIR "%s" R_SYS_DIR "%s", + const char* symstore_path = rz_config_get (core->config, "pdb.symstore"); + const char *base_file = rz_file_basename (info->debug_file_name); + char* pdb_path = rz_str_newf ("%s" R_SYS_DIR "%s" R_SYS_DIR "%s" R_SYS_DIR "%s", symstore_path, base_file, info->guid, base_file); - file_found = r_file_exists (pdb_path); + file_found = rz_file_exists (pdb_path); if (file_found) { filename = pdb_path; } else { @@ -890,7 +890,7 @@ static int cmd_info(void *data, const char *input) { if (!file_found) { if (info->debug_file_name) { - const char *fn = r_file_basename (info->debug_file_name); + const char *fn = rz_file_basename (info->debug_file_name); eprintf ("File '%s' not found in file directory or symbol store\n", fn); } else { eprintf ("Cannot open file\n"); @@ -898,27 +898,27 @@ static int cmd_info(void *data, const char *input) { free (filename); break; } - r_core_pdb_info (core, filename, mode); + rz_core_pdb_info (core, filename, mode); free (filename); break; case '?': default: - r_core_cmd_help (core, help_msg_id); + rz_core_cmd_help (core, help_msg_id); input++; break; } input++; } else if (input[1] == '?') { // "id?" - r_core_cmd_help (core, help_msg_id); + rz_core_cmd_help (core, help_msg_id); input++; } else { // "id" RBININFO ("dwarf", R_CORE_BIN_ACC_DWARF, NULL, -1); } break; case 'i': { // "ii" - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); RBININFO ("imports", R_CORE_BIN_ACC_IMPORTS, NULL, - (obj && obj->imports)? r_list_length (obj->imports): 0); + (obj && obj->imports)? rz_list_length (obj->imports): 0); break; } case 'I': // "iI" @@ -945,7 +945,7 @@ static int cmd_info(void *data, const char *input) { RBININFO ("versioninfo", R_CORE_BIN_ACC_VERSIONINFO, NULL, 0); break; case 'T': // "iT" - case 'C': // "iC" // rabin2 -C create // should be deprecated and just use iT (or find a better name) + case 'C': // "iC" // rz_bin -C create // should be deprecated and just use iT (or find a better name) RBININFO ("signature", R_CORE_BIN_ACC_SIGNATURE, NULL, 0); break; case 'z': // "iz" @@ -955,15 +955,15 @@ static int cmd_info(void *data, const char *input) { bool old_tmpseek = core->tmpseek; input++; if (input[1] == ' ') { - const char *argstr = r_str_trim_head_ro (input + 2); - ut64 arg = r_num_get (NULL, argstr); + const char *argstr = rz_str_trim_head_ro (input + 2); + ut64 arg = rz_num_get (NULL, argstr); input++; if (arg != 0 || *argstr == '0') { addr = arg; } } core->tmpseek = false; - r_core_cmdf (core, "e bin.str.purge=%s%s0x%" PFMT64x, + rz_core_cmdf (core, "e bin.str.purge=%s%s0x%" PFMT64x, strpurge ? strpurge : "", strpurge && *strpurge ? "," : "", addr); @@ -994,17 +994,17 @@ static int cmd_info(void *data, const char *input) { } input++; if (rdump) { - RBinFile *bf = r_bin_cur (core->bin); - int min = r_config_get_i (core->config, "bin.minstr"); + RBinFile *bf = rz_bin_cur (core->bin); + int min = rz_config_get_i (core->config, "bin.minstr"); if (bf) { bf->strmode = mode; - r_bin_dump_strings (bf, min, 2); + rz_bin_dump_strings (bf, min, 2); } goto done; } RBININFO ("strings", R_CORE_BIN_ACC_RAW_STRINGS, NULL, 0); } else { - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (input[1] == 'q') { mode = (input[2] == 'q') ? R_MODE_SIMPLEST @@ -1013,7 +1013,7 @@ static int cmd_info(void *data, const char *input) { } if (obj) { RBININFO ("strings", R_CORE_BIN_ACC_STRINGS, NULL, - (obj && obj->strings)? r_list_length (obj->strings): 0); + (obj && obj->strings)? rz_list_length (obj->strings): 0); } } break; @@ -1023,28 +1023,28 @@ static int cmd_info(void *data, const char *input) { eprintf ("Usage: ic[gljqc**] [class-index or name]\n"); } else if (input[1] == 'g') { RBinClass *cls; - RListIter *iter; - RBinObject *obj = r_bin_cur_object (core->bin); + RzListIter *iter; + RBinObject *obj = rz_bin_cur_object (core->bin); if (!obj) { break; } bool fullGraph = true; if (fullGraph) { - r_list_foreach (obj->classes, iter, cls) { + rz_list_foreach (obj->classes, iter, cls) { if (cls->super) { - r_cons_printf ("agn %s\n", cls->super); - r_cons_printf ("agn %s\n", cls->name); - r_cons_printf ("age %s %s\n", cls->super, cls->name); + rz_cons_printf ("agn %s\n", cls->super); + rz_cons_printf ("agn %s\n", cls->name); + rz_cons_printf ("age %s %s\n", cls->super, cls->name); } else { - r_cons_printf ("agn %s\n", cls->name); + rz_cons_printf ("agn %s\n", cls->name); } } } else { - r_list_foreach (obj->classes, iter, cls) { + rz_list_foreach (obj->classes, iter, cls) { if (cls->super && !strstr (cls->super, "NSObject")) { - r_cons_printf ("agn %s\n", cls->super); - r_cons_printf ("agn %s\n", cls->name); - r_cons_printf ("age %s %s\n", cls->super, cls->name); + rz_cons_printf ("agn %s\n", cls->super); + rz_cons_printf ("agn %s\n", cls->name); + rz_cons_printf ("age %s %s\n", cls->super, cls->name); } } } @@ -1052,20 +1052,20 @@ static int cmd_info(void *data, const char *input) { } else if (input[1] == ' ' || input[1] == 'q' || input[1] == 'j' || input[1] == 'l' || input[1] == 'c' || input[1] == '*') { RBinClass *cls; RBinSymbol *sym; - RListIter *iter, *iter2; - RBinObject *obj = r_bin_cur_object (core->bin); + RzListIter *iter, *iter2; + RBinObject *obj = rz_bin_cur_object (core->bin); if (!obj) { break; } if (input[2] && input[2] != '*' && input[2] != 'j' && !strstr (input, "qq")) { - bool radare2 = strstr (input, "**") != NULL; + bool rizin = strstr (input, "**") != NULL; int idx = -1; const char * cls_name = NULL; - if (radare2) { + if (rizin) { input ++; } - if (r_num_is_valid_input (core->num, input + 2)) { - idx = r_num_math (core->num, input + 2); + if (rz_num_is_valid_input (core->num, input + 2)) { + idx = rz_num_math (core->num, input + 2); } else { const char * first_char = input + ((input[1] == ' ') ? 1 : 2); int not_space = strspn (first_char, " "); @@ -1073,16 +1073,16 @@ static int cmd_info(void *data, const char *input) { cls_name = first_char + not_space; } } - if (radare2) { + if (rizin) { input++; } int count = 0; int mode = input[1]; - r_list_foreach (obj->classes, iter, cls) { - if (radare2) { - r_cons_printf ("ac %s\n", cls->name); - r_list_foreach (cls->methods, iter2, sym) { - r_cons_printf ("ac %s %s 0x%08"PFMT64x"\n", cls->name, sym->name, sym->vaddr); + rz_list_foreach (obj->classes, iter, cls) { + if (rizin) { + rz_cons_printf ("ac %s\n", cls->name); + rz_list_foreach (cls->methods, iter2, sym) { + rz_cons_printf ("ac %s %s 0x%08"PFMT64x"\n", cls->name, sym->name, sym->vaddr); } continue; } @@ -1092,44 +1092,44 @@ static int cmd_info(void *data, const char *input) { } switch (mode) { case '*': - r_list_foreach (cls->methods, iter2, sym) { - r_cons_printf ("f sym.%s @ 0x%"PFMT64x "\n", + rz_list_foreach (cls->methods, iter2, sym) { + rz_cons_printf ("f sym.%s @ 0x%"PFMT64x "\n", sym->name, sym->vaddr); } input++; break; case 'l': - r_list_foreach (cls->methods, iter2, sym) { + rz_list_foreach (cls->methods, iter2, sym) { const char *comma = iter2->p? " ": ""; - r_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr); + rz_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr); } - r_cons_newline (); + rz_cons_newline (); input++; break; case 'j': input++; - r_cons_printf ("\"class\":\"%s\"", cls->name); - r_cons_printf (",\"methods\":["); - r_list_foreach (cls->methods, iter2, sym) { + rz_cons_printf ("\"class\":\"%s\"", cls->name); + rz_cons_printf (",\"methods\":["); + rz_list_foreach (cls->methods, iter2, sym) { const char *comma = iter2->p? ",": ""; if (sym->method_flags) { - char *flags = r_core_bin_method_flags_str (sym->method_flags, R_MODE_JSON); - r_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"vaddr\":%"PFMT64d "}", + char *flags = rz_core_bin_method_flags_str (sym->method_flags, R_MODE_JSON); + rz_cons_printf ("%s{\"name\":\"%s\",\"flags\":%s,\"vaddr\":%"PFMT64d "}", comma, sym->name, flags, sym->vaddr); R_FREE (flags); } else { - r_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d "}", + rz_cons_printf ("%s{\"name\":\"%s\",\"vaddr\":%"PFMT64d "}", comma, sym->name, sym->vaddr); } } - r_cons_printf ("]"); + rz_cons_printf ("]"); break; default: - r_cons_printf ("class %s\n", cls->name); - r_list_foreach (cls->methods, iter2, sym) { - char *flags = r_core_bin_method_flags_str (sym->method_flags, 0); - r_cons_printf ("0x%08"PFMT64x " method %s %s %s\n", + rz_cons_printf ("class %s\n", cls->name); + rz_list_foreach (cls->methods, iter2, sym) { + char *flags = rz_core_bin_method_flags_str (sym->method_flags, 0); + rz_cons_printf ("0x%08"PFMT64x " method %s %s %s\n", sym->vaddr, cls->name, flags, sym->name); R_FREE (flags); } @@ -1139,21 +1139,21 @@ static int cmd_info(void *data, const char *input) { } goto done; } else if (obj->classes) { - playMsg (core, "classes", r_list_length (obj->classes)); + playMsg (core, "classes", rz_list_length (obj->classes)); if (strstr (input, "qq")) { // "icqq" - r_list_foreach (obj->classes, iter, cls) { + rz_list_foreach (obj->classes, iter, cls) { if (!isKnownPackage (cls->name)) { - r_cons_printf ("%s\n", cls->name); + rz_cons_printf ("%s\n", cls->name); } } } else if (input[1] == 'l') { // "icl" - r_list_foreach (obj->classes, iter, cls) { - r_list_foreach (cls->methods, iter2, sym) { + rz_list_foreach (obj->classes, iter, cls) { + rz_list_foreach (cls->methods, iter2, sym) { const char *comma = iter2->p? " ": ""; - r_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr); + rz_cons_printf ("%s0x%"PFMT64d, comma, sym->vaddr); } - if (!r_list_empty (cls->methods)) { - r_cons_newline (); + if (!rz_list_empty (cls->methods)) { + rz_cons_newline (); } } } else if (input[1] == 'c') { // "icc" @@ -1161,20 +1161,20 @@ static int cmd_info(void *data, const char *input) { if (input[2] == '*') { mode |= R_MODE_RADARE; } - RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, r_list_length (obj->classes)); + RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, rz_list_length (obj->classes)); input = " "; } else { // "icq" if (input[2] == 'j') { mode |= R_MODE_JSON; // default mode is R_MODE_SIMPLE } - RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, r_list_length (obj->classes)); + RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, rz_list_length (obj->classes)); } goto done; } } else { // "ic" - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj && obj->classes) { - int len = r_list_length (obj->classes); + int len = rz_list_length (obj->classes); RBININFO ("classes", R_CORE_BIN_ACC_CLASSES, NULL, len); } } @@ -1193,7 +1193,7 @@ static int cmd_info(void *data, const char *input) { } break; case '?': // "i?" - r_core_cmd_help (core, help_msg_i); + rz_core_cmd_help (core, help_msg_i); goto redone; case '*': // "i*" if (mode == R_MODE_RADARE) { @@ -1233,10 +1233,10 @@ static int cmd_info(void *data, const char *input) { } done: if (is_array && !is_izzzj) { - r_cons_printf ("}\n"); + rz_cons_printf ("}\n"); } if (newline) { - r_cons_newline (); + rz_cons_newline (); } redone: return 0; diff --git a/libr/core/cmd_log.c b/librz/core/cmd_log.c similarity index 61% rename from libr/core/cmd_log.c rename to librz/core/cmd_log.c index 525659b738..b5e2fdfaf9 100644 --- a/libr/core/cmd_log.c +++ b/librz/core/cmd_log.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ #include -#include "r_config.h" -#include "r_cons.h" -#include "r_core.h" +#include "rz_config.h" +#include "rz_cons.h" +#include "rz_core.h" // TODO #7967 help refactor: move to another place static const char *help_msg_L[] = { @@ -44,18 +44,18 @@ static const char *help_msg_T[] = { }; // TODO #7967 help refactor: move L to another place -static void cmd_log_init(RCore *core, RCmdDesc *parent) { +static void cmd_log_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, L); DEFINE_CMD_DESCRIPTOR (core, T); } -static void screenlock(RCore *core) { - // char *pass = r_cons_input ("Enter new password: "); - char *pass = r_cons_password (Color_INVERT "Enter new password:"Color_INVERT_RESET); +static void screenlock(RzCore *core) { + // char *pass = rz_cons_input ("Enter new password: "); + char *pass = rz_cons_password (Color_INVERT "Enter new password:"Color_INVERT_RESET); if (!pass || !*pass) { return; } - char *again = r_cons_password (Color_INVERT "Type it again:"Color_INVERT_RESET); + char *again = rz_cons_password (Color_INVERT "Type it again:"Color_INVERT_RESET); if (!again || !*again) { free (pass); return; @@ -67,50 +67,50 @@ static void screenlock(RCore *core) { return; } bool running = true; - r_cons_clear_buffer (); - ut64 begin = r_time_now (); + rz_cons_clear_buffer (); + ut64 begin = rz_time_now (); ut64 last = UT64_MAX; ut64 tries = 0; do { - r_cons_clear00 (); - r_cons_printf ("Retries: %d\n", tries); - r_cons_printf ("Locked ts: %s\n", r_time_to_string (begin)); + rz_cons_clear00 (); + rz_cons_printf ("Retries: %d\n", tries); + rz_cons_printf ("Locked ts: %s\n", rz_time_to_string (begin)); if (last != UT64_MAX) { - r_cons_printf ("Last try: %s\n", r_time_to_string (last)); + rz_cons_printf ("Last try: %s\n", rz_time_to_string (last)); } - r_cons_newline (); - r_cons_flush (); - char *msg = r_cons_password ("radare2 password: "); + rz_cons_newline (); + rz_cons_flush (); + char *msg = rz_cons_password ("rizin password: "); if (msg && !strcmp (msg, pass)) { running = false; } else { eprintf ("\nInvalid password.\n"); - last = r_time_now (); + last = rz_time_now (); tries++; } free (msg); - int n = r_num_rand (10) + 1; - r_sys_usleep (n * 100000); + int n = rz_num_rand (10) + 1; + rz_sys_usleep (n * 100000); } while (running); - r_cons_set_cup (true); + rz_cons_set_cup (true); free (pass); eprintf ("Unlocked!\n"); } -static int textlog_chat(RCore *core) { +static int textlog_chat(RzCore *core) { char prompt[64]; char buf[1024]; int lastmsg = 0; - const char *me = r_config_get (core->config, "cfg.user"); + const char *me = rz_config_get (core->config, "cfg.user"); char msg[2048]; eprintf ("Type '/help' for commands:\n"); snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me); - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); for (;;) { - r_core_log_list (core, lastmsg, 0, 0); + rz_core_log_list (core, lastmsg, 0, 0); lastmsg = core->log->last; - if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { + if (rz_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { return 1; } if (!*buf) { @@ -123,18 +123,18 @@ static int textlog_chat(RCore *core) { eprintf ("/clear clear text log messages\n"); } else if (!strncmp (buf, "/name ", 6)) { snprintf (msg, sizeof (msg) - 1, "* '%s' is now known as '%s'", me, buf + 6); - r_core_log_add (core, msg); - r_config_set (core->config, "cfg.user", buf + 6); - me = r_config_get (core->config, "cfg.user"); + rz_core_log_add (core, msg); + rz_config_set (core->config, "cfg.user", buf + 6); + me = rz_config_get (core->config, "cfg.user"); snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me); - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); return 0; } else if (!strcmp (buf, "/log")) { - r_core_log_list (core, 0, 0, 0); + rz_core_log_list (core, 0, 0, 0); return 0; } else if (!strcmp (buf, "/clear")) { - // r_core_log_del (core, 0); - r_core_cmd0 (core, "T-"); + // rz_core_log_del (core, 0); + rz_core_cmd0 (core, "T-"); return 0; } else if (!strcmp (buf, "/quit")) { return 0; @@ -142,7 +142,7 @@ static int textlog_chat(RCore *core) { eprintf ("Unknown command: %s\n", buf); } else { snprintf (msg, sizeof (msg), "[%s] %s", me, buf); - r_core_log_add (core, msg); + rz_core_log_add (core, msg); } } return 1; @@ -166,7 +166,7 @@ static int getIndexFromLogString(const char *s) { return -1; } -static char *expr2cmd (RCoreLog *log, const char *line) { +static char *expr2cmd (RzCoreLog *log, const char *line) { if (!line || !*line) { return NULL; } @@ -177,40 +177,40 @@ static char *expr2cmd (RCoreLog *log, const char *line) { char *sp = strchr (line + 1, ' '); if (sp) { char *msg = sp + 1; - ut64 addr = r_num_get (NULL, line); - return r_str_newf ("CCu base64:%s @ 0x%"PFMT64x"\n", msg, addr); + ut64 addr = rz_num_get (NULL, line); + return rz_str_newf ("CCu base64:%s @ 0x%"PFMT64x"\n", msg, addr); } } eprintf ("add-comment parsing error\n"); } if (!strncmp (line, "del-comment", 11)) { if (line[11] == ' ') { - return r_str_newf ("CC-%s\n", line + 12); + return rz_str_newf ("CC-%s\n", line + 12); } eprintf ("add-comment parsing error\n"); } return NULL; } -static int log_callback_r2 (RCore *core, int count, const char *line) { +static int log_callback_rz (RzCore *core, int count, const char *line) { if (*line == ':') { char *cmd = expr2cmd (core->log, line); if (cmd) { - r_cons_printf ("%s\n", cmd); - r_core_cmd (core, cmd, 0); + rz_cons_printf ("%s\n", cmd); + rz_core_cmd (core, cmd, 0); free (cmd); } } return 0; } -static int log_callback_all (RCore *log, int count, const char *line) { - r_cons_printf ("%d %s\n", count, line); +static int log_callback_all (RzCore *log, int count, const char *line) { + rz_cons_printf ("%d %s\n", count, line); return 0; } static int cmd_log(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; const char *arg, *input2; int n, n2; @@ -228,9 +228,9 @@ static int cmd_log(void *data, const char *input) { { char *p = strchr (input, ' '); if (p) { - char *b = r_file_slurp (p + 1, NULL); + char *b = rz_file_slurp (p + 1, NULL); if (b) { - r_cons_less_str (b, NULL); + rz_cons_less_str (b, NULL); free (b); } else { eprintf ("File not found\n"); @@ -241,16 +241,16 @@ static int cmd_log(void *data, const char *input) { } break; case 'l': // "Tl" - r_cons_printf ("%d\n", core->log->last - 1); + rz_cons_printf ("%d\n", core->log->last - 1); break; case '-': // "T-" - r_core_log_del (core, n); + rz_core_log_del (core, n); break; case '?': // "T?" - r_core_cmd_help (core, help_msg_T); + rz_core_cmd_help (core, help_msg_T); break; case 'T': // "TT" Ts ? as ms? - if (r_cons_is_interactive ()) { + if (rz_cons_is_interactive ()) { textlog_chat (core); } else { eprintf ("Only available when the screen is interactive\n"); @@ -259,127 +259,127 @@ static int cmd_log(void *data, const char *input) { case '=': // "T=" if (input[1] == '&') { // "T=&" if (input[2] == '&') { // "T=&&" - r_cons_break_push (NULL, NULL); - while (!r_cons_is_breaked ()) { - r_core_cmd0 (core, "T="); - void *bed = r_cons_sleep_begin(); - r_sys_sleep (1); - r_cons_sleep_end (bed); + rz_cons_break_push (NULL, NULL); + while (!rz_cons_is_breaked ()) { + rz_core_cmd0 (core, "T="); + void *bed = rz_cons_sleep_begin(); + rz_sys_sleep (1); + rz_cons_sleep_end (bed); } - r_cons_break_pop (); + rz_cons_break_pop (); } else { // TODO: Sucks that we can't enqueue functions, only commands eprintf ("Background thread syncing with http.sync started.\n"); - RCoreTask *task = r_core_task_new (core, true, "T=&&", NULL, core); - r_core_task_enqueue (&core->tasks, task); + RzCoreTask *task = rz_core_task_new (core, true, "T=&&", NULL, core); + rz_core_task_enqueue (&core->tasks, task); } } else { if (atoi (input + 1) > 0 || (input[1] == '0')) { core->sync_index = 0; } else { - RCoreLogCallback log_callback = (input[1] == '*') - ? log_callback_all: log_callback_r2; - char *res = r_core_log_get (core, core->sync_index); + RzCoreLogCallback log_callback = (input[1] == '*') + ? log_callback_all: log_callback_rz; + char *res = rz_core_log_get (core, core->sync_index); if (res) { int idx = getIndexFromLogString (res); if (idx != -1) { core->sync_index = idx + 1; } - r_core_log_run (core, res, log_callback); + rz_core_log_run (core, res, log_callback); free (res); } else { - r_cons_printf ("Please check e http.sync\n"); + rz_cons_printf ("Please check e http.sync\n"); } } } break; case ' ': // "T " if (n > 0 || *input == '0') { - r_core_log_list (core, n, n2, *input); + rz_core_log_list (core, n, n2, *input); } else { - r_core_log_add (core, input + 1); + rz_core_log_add (core, input + 1); } break; case 'm': // "Tm" if (n > 0) { - r_core_log_list (core, n, 1, 't'); + rz_core_log_list (core, n, 1, 't'); } else { - r_core_log_list (core, n, 0, 't'); + rz_core_log_list (core, n, 0, 't'); } break; case 'j': // "Tj" case '*': case '\0': - r_core_log_list (core, n, n2, *input); + rz_core_log_list (core, n, n2, *input); break; } return 0; } static int cmd_plugins(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; switch (input[0]) { case 0: - r_core_cmd_help (core, help_msg_L); - // return r_core_cmd0 (core, "Lc"); + rz_core_cmd_help (core, help_msg_L); + // return rz_core_cmd0 (core, "Lc"); break; case '-': - r_lib_close (core->lib, r_str_trim_head_ro (input + 1)); + rz_lib_close (core->lib, rz_str_trim_head_ro (input + 1)); break; case ' ': - r_lib_open (core->lib, r_str_trim_head_ro (input + 1)); + rz_lib_open (core->lib, rz_str_trim_head_ro (input + 1)); break; case '?': - r_core_cmd_help (core, help_msg_L); + rz_core_cmd_help (core, help_msg_L); break; case 'm': // "Lm" - r_core_cmdf (core, "mL%s", input + 1); + rz_core_cmdf (core, "mL%s", input + 1); break; case 'd': // "Ld" - r_core_cmdf (core, "dL%s", input + 1); + rz_core_cmdf (core, "dL%s", input + 1); break; case 'h': // "Lh" - r_core_cmd0 (core, "ph"); // rahash2 -L is more verbose + rz_core_cmd0 (core, "ph"); // rz_hash -L is more verbose break; case 'a': // "La" - r_core_cmd0 (core, "e asm.arch=??"); + rz_core_cmd0 (core, "e asm.arch=??"); break; case 'D': // "LD" if (input[1] == ' ') { - r_core_cmdf (core, "e cmd.pdc=%s", r_str_trim_head_ro (input + 2)); + rz_core_cmdf (core, "e cmd.pdc=%s", rz_str_trim_head_ro (input + 2)); } else { - r_core_cmd0 (core, "e cmd.pdc=?"); + rz_core_cmd0 (core, "e cmd.pdc=?"); } break; case 'l': // "Ll" - r_core_cmd0 (core, "#!"); + rz_core_cmd0 (core, "#!"); break; case 'L': // "LL" screenlock (core); break; case 'o': // "Lo" case 'i': // "Li" - r_core_cmdf (core, "%cL", input[0]); + rz_core_cmdf (core, "%cL", input[0]); break; case 'c': { // "Lc" - RListIter *iter; - RCorePlugin *cp; + RzListIter *iter; + RzCorePlugin *cp; switch (input[1]) { case 'j': { - r_cons_printf ("["); + rz_cons_printf ("["); bool is_first_element = true; - r_list_foreach (core->rcmd->plist, iter, cp) { - r_cons_printf ("%s{\"Name\":\"%s\",\"Description\":\"%s\"}", + rz_list_foreach (core->rcmd->plist, iter, cp) { + rz_cons_printf ("%s{\"Name\":\"%s\",\"Description\":\"%s\"}", is_first_element? "" : ",", cp->name, cp->desc); is_first_element = false; } - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); break; } case 0: - r_lib_list (core->lib); - r_list_foreach (core->rcmd->plist, iter, cp) { - r_cons_printf ("%s: %s\n", cp->name, cp->desc); + rz_lib_list (core->lib); + rz_list_foreach (core->rcmd->plist, iter, cp) { + rz_cons_printf ("%s: %s\n", cp->name, cp->desc); } break; default: diff --git a/libr/core/cmd_macro.c b/librz/core/cmd_macro.c similarity index 74% rename from libr/core/cmd_macro.c rename to librz/core/cmd_macro.c index 33401b5873..7bf06e2f1d 100644 --- a/libr/core/cmd_macro.c +++ b/librz/core/cmd_macro.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2014 - pancake */ -#include "r_cmd.h" -#include "r_core.h" +#include "rz_cmd.h" +#include "rz_core.h" static const char *help_msg_lparen[] = { "Usage:", "(foo args;cmd1;cmd2;..)", "Aliases", @@ -19,35 +19,35 @@ static const char *help_msg_lparen[] = { NULL }; -static void cmd_macro_init(RCore *core, RCmdDesc *parent) { - RCmdDescriptor *d = R_NEW0 (RCmdDescriptor); +static void cmd_macro_init(RzCore *core, RzCmdDesc *parent) { + RzCmdDescriptor *d = R_NEW0 (RzCmdDescriptor); if (d) { d->cmd = "("; d->help_msg = help_msg_lparen; - r_list_append (core->cmd_descriptors, d); + rz_list_append (core->cmd_descriptors, d); } } static int cmd_macro(void *data, const char *input) { char *buf = NULL; - RCore *core = (RCore*)data; + RzCore *core = (RzCore*)data; switch (*input) { case ')': - r_cmd_macro_break (&core->rcmd->macro, input + 1); + rz_cmd_macro_break (&core->rcmd->macro, input + 1); break; case '-': - r_cmd_macro_rm (&core->rcmd->macro, input + 1); + rz_cmd_macro_rm (&core->rcmd->macro, input + 1); break; case '*': - r_cmd_macro_meta (&core->rcmd->macro); + rz_cmd_macro_meta (&core->rcmd->macro); break; case '\0': - r_cmd_macro_list (&core->rcmd->macro); + rz_cmd_macro_list (&core->rcmd->macro); break; case '(': case '?': - r_core_cmd_help (core, help_msg_lparen); + rz_core_cmd_help (core, help_msg_lparen); break; default: { // XXX: stop at first ')'. if next is '(' and last @@ -71,7 +71,7 @@ static int cmd_macro(void *data, const char *input) { } } buf[strlen (buf) - 1]=0; - r_cmd_macro_add (&core->rcmd->macro, buf); + rz_cmd_macro_add (&core->rcmd->macro, buf); if (mustcall) { char *comma = strchr (buf, ' '); if (!comma) { @@ -80,7 +80,7 @@ static int cmd_macro(void *data, const char *input) { if (comma) { *comma = ' '; memmove (comma + 1, buf + mustcall, strlen (buf + mustcall) + 1); - r_cmd_macro_call (&core->rcmd->macro, buf); + rz_cmd_macro_call (&core->rcmd->macro, buf); } else { eprintf ("Invalid syntax for macro\n"); } diff --git a/libr/core/cmd_magic.c b/librz/core/cmd_magic.c similarity index 62% rename from libr/core/cmd_magic.c rename to librz/core/cmd_magic.c index 2462b1a664..b8bef06ee8 100644 --- a/libr/core/cmd_magic.c +++ b/librz/core/cmd_magic.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include /* ugly global vars */ static int magicdepth = 99; //XXX: do not use global var here -static RMagic *ck = NULL; // XXX: Use RCore->magic +static RzMagic *ck = NULL; // XXX: Use RzCore->magic static char *ofile = NULL; static int kw_count = 0; -static void r_core_magic_reset(RCore *core) { +static void rz_core_magic_reset(RzCore *core) { kw_count = 0; } -static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, int v, bool json, int *hits) { +static int rz_core_magic_at(RzCore *core, const char *file, ut64 addr, int depth, int v, bool json, int *hits) { const char *fmt; char *q, *p; const char *str; int found = 0, delta = 0, adelta = 0, ret; ut64 curoffset = core->offset; - int maxHits = r_config_get_i (core->config, "search.maxhits"); + int maxHits = rz_config_get_i (core->config, "search.maxhits"); if (maxHits > 0 && *hits >= maxHits) { return 0; } @@ -33,7 +33,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, if (addr >= core->offset && (addr+NAH) < (core->offset + core->blocksize)) { delta = addr - core->offset; } else { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } #endif } @@ -55,42 +55,42 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, } if (file && ofile && file != ofile) { if (strcmp (file, ofile)) { - r_magic_free (ck); + rz_magic_free (ck); ck = NULL; } } if (!ck) { - // TODO: Move RMagic into RCore - r_magic_free (ck); + // TODO: Move RzMagic into RzCore + rz_magic_free (ck); // allocate once - ck = r_magic_new (0); + ck = rz_magic_new (0); if (file) { free (ofile); ofile = strdup (file); - if (!r_magic_load (ck, file)) { - eprintf ("failed r_magic_load (\"%s\") %s\n", file, r_magic_error (ck)); + if (!rz_magic_load (ck, file)) { + eprintf ("failed rz_magic_load (\"%s\") %s\n", file, rz_magic_error (ck)); ck = NULL; ret = -1; goto seek_exit; } } else { - const char *magicpath = r_config_get (core->config, "dir.magic"); - if (!r_magic_load (ck, magicpath)) { + const char *magicpath = rz_config_get (core->config, "dir.magic"); + if (!rz_magic_load (ck, magicpath)) { ck = NULL; - eprintf ("failed r_magic_load (dir.magic) %s\n", r_magic_error (ck)); + eprintf ("failed rz_magic_load (dir.magic) %s\n", rz_magic_error (ck)); ret = -1; goto seek_exit; } } } //repeat: - //if (v) r_cons_printf (" %d # pm %s @ 0x%"PFMT64x"\n", depth, file? file: "", addr); + //if (v) rz_cons_printf (" %d # pm %s @ 0x%"PFMT64x"\n", depth, file? file: "", addr); if (delta + 2 > core->blocksize) { eprintf ("EOB\n"); ret = -1; goto seek_exit; } - str = r_magic_buffer (ck, core->block+delta, core->blocksize - delta); + str = rz_magic_buffer (ck, core->block+delta, core->blocksize - delta); if (str) { const char *cmdhit; #if USE_LIB_MAGIC @@ -102,7 +102,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, if (mod < 1) { mod = 1; } - //r_magic_free (ck); + //rz_magic_free (ck); //ck = NULL; //return -1; ret = mod + 1; @@ -118,26 +118,26 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, } } (*hits)++; - cmdhit = r_config_get (core->config, "cmd.hit"); + cmdhit = rz_config_get (core->config, "cmd.hit"); if (cmdhit && *cmdhit) { - r_core_cmd0 (core, cmdhit); + rz_core_cmd0 (core, cmdhit); } { - const char *searchprefix = r_config_get (core->config, "search.prefix"); + const char *searchprefix = rz_config_get (core->config, "search.prefix"); const char *flag = sdb_fmt ("%s%d_%d", searchprefix, 0, kw_count++); - r_flag_set (core->flags, flag, addr + adelta, 1); + rz_flag_set (core->flags, flag, addr + adelta, 1); } - // TODO: This must be a callback .. move this into RSearch? + // TODO: This must be a callback .. move this into RzSearch? if (!json) { - r_cons_printf ("0x%08"PFMT64x" %d %s\n", addr + adelta, magicdepth-depth, p); + rz_cons_printf ("0x%08"PFMT64x" %d %s\n", addr + adelta, magicdepth-depth, p); } else { if (found >= 1) { - r_cons_printf (","); + rz_cons_printf (","); } - r_cons_printf ("{\"offset\":%"PFMT64d ",\"depth\":%d,\"info\":\"%s\"}", + rz_cons_printf ("{\"offset\":%"PFMT64d ",\"depth\":%d,\"info\":\"%s\"}", addr + adelta, magicdepth-depth, p); } - r_cons_clear_line (1); + rz_cons_clear_line (1); //eprintf ("0x%08"PFMT64x" 0x%08"PFMT64x" %d %s\n", addr+adelta, addr+adelta, magicdepth-depth, p); // walking children for (q = p; *q; q++) { @@ -157,14 +157,14 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, if (!fmt || !*fmt) { fmt = file; } - r_core_magic_at (core, fmt, addr, depth, 1, json, hits); + rz_core_magic_at (core, fmt, addr, depth, 1, json, hits); *q = '@'; } break; } } free (p); - r_magic_free (ck); + rz_magic_free (ck); ck = NULL; found ++; @@ -173,7 +173,7 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, adelta ++; delta ++; #if 0 - r_magic_free (ck); + rz_magic_free (ck); ck = NULL; #endif { @@ -186,19 +186,19 @@ static int r_core_magic_at(RCore *core, const char *file, ut64 addr, int depth, ret = adelta; //found; seek_exit: - r_core_seek (core, curoffset, true); + rz_core_seek (core, curoffset, true); return ret; } -static void r_core_magic(RCore *core, const char *file, int v, int json) { +static void rz_core_magic(RzCore *core, const char *file, int v, int json) { ut64 addr = core->offset; int hits = 0; - magicdepth = r_config_get_i (core->config, "magic.depth"); // TODO: do not use global var here - r_core_magic_at (core, file, addr, magicdepth, v, json, &hits); + magicdepth = rz_config_get_i (core->config, "magic.depth"); // TODO: do not use global var here + rz_core_magic_at (core, file, addr, magicdepth, v, json, &hits); if (json) { - r_cons_newline (); + rz_cons_newline (); } if (addr != core->offset) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } } diff --git a/libr/core/cmd_meta.c b/librz/core/cmd_meta.c similarity index 67% rename from libr/core/cmd_meta.c rename to librz/core/cmd_meta.c index a05d723f01..baf9abe839 100644 --- a/libr/core/cmd_meta.c +++ b/librz/core/cmd_meta.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake */ +/* rizin - LGPL - Copyright 2009-2020 - pancake */ -#include "r_anal.h" -#include "r_bin.h" -#include "r_cons.h" -#include "r_core.h" -#include "r_util.h" -#include "r_types.h" +#include "rz_anal.h" +#include "rz_bin.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_util.h" +#include "rz_types.h" #include -char *getcommapath(RCore *core); +char *getcommapath(RzCore *core); static const char *help_msg_C[] = { "Usage:", "C[-LCvsdfm*?][*?] [...]", " # Metadata management", @@ -134,7 +134,7 @@ static const char *help_msg_Cvs[] = { NULL }; -static void cmd_meta_init(RCore *core, RCmdDesc *parent) { +static void cmd_meta_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, C); DEFINE_CMD_DESCRIPTOR (core, CC); DEFINE_CMD_DESCRIPTOR (core, CS); @@ -144,7 +144,7 @@ static void cmd_meta_init(RCore *core, RCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, Cvs); } -static int remove_meta_offset(RCore *core, ut64 offset) { +static int remove_meta_offset(RzCore *core, ut64 offset) { char aoffset[64]; char *aoffsetptr = sdb_itoa (offset, aoffset, 16); if (!aoffsetptr) { @@ -154,22 +154,22 @@ static int remove_meta_offset(RCore *core, ut64 offset) { return sdb_unset (core->bin->cur->sdb_addrinfo, aoffsetptr, 0); } -static bool print_meta_offset(RCore *core, ut64 addr) { +static bool print_meta_offset(RzCore *core, ut64 addr) { int line, line_old, i; char file[1024]; - int ret = r_bin_addr2line (core->bin, addr, file, sizeof (file) - 1, &line); + int ret = rz_bin_addr2line (core->bin, addr, file, sizeof (file) - 1, &line); if (ret) { - r_cons_printf ("file: %s\nline: %d\n", file, line); + rz_cons_printf ("file: %s\nline: %d\n", file, line); line_old = line; if (line >= 2) { line -= 2; } - if (r_file_exists (file)) { + if (rz_file_exists (file)) { for (i = 0; i < 5; i++) { - char *row = r_file_slurp_line (file, line + i, 0); + char *row = rz_file_slurp_line (file, line + i, 0); if (row) { - r_cons_printf ("%c %.3x %s\n", line+i == line_old ? '>' : ' ', line+i, row); + rz_cons_printf ("%c %.3x %s\n", line+i == line_old ? '>' : ' ', line+i, row); free (row); } } @@ -181,16 +181,16 @@ static bool print_meta_offset(RCore *core, ut64 addr) { } #if 0 -static int remove_meta_fileline(RCore *core, const char *file_line) { +static int remove_meta_fileline(RzCore *core, const char *file_line) { return sdb_unset (core->bin->cur->sdb_addrinfo, file_line, 0); } -static int print_meta_fileline(RCore *core, const char *file_line) { +static int print_meta_fileline(RzCore *core, const char *file_line) { char *meta_info = sdb_get (core->bin->cur->sdb_addrinfo, file_line, 0); if (meta_info) { - r_cons_printf ("Meta info %s\n", meta_info); + rz_cons_printf ("Meta info %s\n", meta_info); } else { - r_cons_printf ("No meta info for %s found\n", file_line); + rz_cons_printf ("No meta info for %s found\n", file_line); } return 0; } @@ -211,15 +211,15 @@ static bool print_addrinfo (void *user, const char *k, const char *v) { colonpos = strchr (subst, ':'); } if (!colonpos) { - r_cons_printf ("%s\n", subst); + rz_cons_printf ("%s\n", subst); } if (colonpos && (filter_offset == UT64_MAX || filter_offset == offset)) { if (filter_format) { *colonpos = ':'; - r_cons_printf ("CL %s %s\n", k, subst); + rz_cons_printf ("CL %s %s\n", k, subst); } else { *colonpos = 0; - r_cons_printf ("file: %s\nline: %s\n", subst, colonpos + 1); + rz_cons_printf ("file: %s\nline: %s\n", subst, colonpos + 1); } filter_count++; } @@ -244,7 +244,7 @@ static int cmd_meta_add_fileline(Sdb *s, char *fileline, ut64 offset) { return 0; } -static int cmd_meta_lineinfo(RCore *core, const char *input) { +static int cmd_meta_lineinfo(RzCore *core, const char *input) { int ret; ut64 offset = UT64_MAX; // use this as error value bool remove = false; @@ -268,10 +268,10 @@ static int cmd_meta_lineinfo(RCore *core, const char *input) { offset = core->offset; } if (*p == ' ') { - p = r_str_trim_head_ro (p + 1); + p = rz_str_trim_head_ro (p + 1); char *arg = strchr (p, ' '); if (!arg) { - offset = r_num_math (core->num, p); + offset = rz_num_math (core->num, p); p = ""; } } else if (*p == '*') { @@ -292,14 +292,14 @@ static int cmd_meta_lineinfo(RCore *core, const char *input) { return 0; } - p = r_str_trim_head_ro (p); + p = rz_str_trim_head_ro (p); char *myp = strdup (p); char *sp = strchr (myp, ' '); if (sp) { *sp = 0; sp++; if (offset == UT64_MAX) { - offset = r_num_math (core->num, myp); + offset = rz_num_math (core->num, myp); } if (!strncmp (sp, "base64:", 7)) { @@ -311,7 +311,7 @@ static int cmd_meta_lineinfo(RCore *core, const char *input) { } sp = pheap = (char *)o; } - RBinFile *bf = r_bin_cur (core->bin); + RBinFile *bf = rz_bin_cur (core->bin); ret = 0; if (bf && bf->sdb_addrinfo) { ret = cmd_meta_add_fileline (bf->sdb_addrinfo, sp, offset); @@ -339,36 +339,36 @@ static int cmd_meta_lineinfo(RCore *core, const char *input) { return 0; } -static int cmd_meta_comment(RCore *core, const char *input) { +static int cmd_meta_comment(RzCore *core, const char *input) { ut64 addr = core->offset; switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_CC); + rz_core_cmd_help (core, help_msg_CC); break; case ',': // "CC," if (input[2]=='?') { eprintf ("Usage: CC, [file]\n"); } else if (input[2] == ' ') { const char *fn = input+2; - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); while (*fn== ' ')fn++; if (comment && *comment) { // append filename in current comment - char *nc = r_str_newf ("%s ,(%s)", comment, fn); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); + char *nc = rz_str_newf ("%s ,(%s)", comment, fn); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); free (nc); } else { - char *newcomment = r_str_newf (",(%s)", fn); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, newcomment); + char *newcomment = rz_str_newf (",(%s)", fn); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, newcomment); free (newcomment); } } else { - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); if (comment && *comment) { - char *cmtfile = r_str_between (comment, ",(", ")"); + char *cmtfile = rz_str_between (comment, ",(", ")"); if (cmtfile && *cmtfile) { char *cwd = getcommapath (core); - r_cons_printf ("%s"R_SYS_DIR"%s\n", cwd, cmtfile); + rz_cons_printf ("%s"R_SYS_DIR"%s\n", cwd, cmtfile); free (cwd); } free (cmtfile); @@ -377,62 +377,62 @@ static int cmd_meta_comment(RCore *core, const char *input) { break; case '.': { - ut64 at = input[2]? r_num_math (core->num, input + 2): addr; - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, at); + ut64 at = input[2]? rz_num_math (core->num, input + 2): addr; + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, at); if (comment) { - r_cons_println (comment); + rz_cons_println (comment); } } break; case 0: // "CC" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 0); + rz_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 0); break; case 'f': // "CCf" switch (input[2]) { case '-': // "CCf-" { - ut64 arg = r_num_math (core->num, input + 2); + ut64 arg = rz_num_math (core->num, input + 2); if (!arg) { arg = core->offset; } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, arg, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, arg, 0); if (fcn) { - RAnalBlock *bb; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, bb) { + RzAnalBlock *bb; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, bb) { int i; for (i = 0; i < bb->size; i++) { ut64 addr = bb->addr + i; - r_meta_del (core->anal, R_META_TYPE_COMMENT, addr, 1); + rz_meta_del (core->anal, R_META_TYPE_COMMENT, addr, 1); } } } } break; case 'j': // "CCfj" - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 'j', core->offset); + rz_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 'j', core->offset); break; case '*': // "CCf*" - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 1, core->offset); + rz_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 1, core->offset); break; default: - r_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 0, core->offset); + rz_meta_print_list_in_function (core->anal, R_META_TYPE_COMMENT, 0, core->offset); break; } break; case 'j': // "CCj" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 'j'); + rz_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 'j'); break; case '!': { char *out; - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); - out = r_core_editor (core, NULL, comment); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + out = rz_core_editor (core, NULL, comment); if (out) { - //r_meta_set (core->anal->meta, R_META_TYPE_COMMENT, addr, 0, out); - r_core_cmdf (core, "CC-@0x%08"PFMT64x, addr); - //r_meta_del (core->anal->meta, input[0], addr, addr+1); - r_meta_set_string (core->anal, + //rz_meta_set (core->anal->meta, R_META_TYPE_COMMENT, addr, 0, out); + rz_core_cmdf (core, "CC-@0x%08"PFMT64x, addr); + //rz_meta_del (core->anal->meta, input[0], addr, addr+1); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, out); free (out); } @@ -441,39 +441,39 @@ static int cmd_meta_comment(RCore *core, const char *input) { case '+': case ' ': { - const char *newcomment = r_str_trim_head_ro (input + 2); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *newcomment = rz_str_trim_head_ro (input + 2); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); char *text; char *nc = strdup (newcomment); - r_str_unescape (nc); + rz_str_unescape (nc); if (comment) { text = malloc (strlen (comment) + strlen (newcomment) + 2); if (text) { strcpy (text, comment); strcat (text, " "); strcat (text, nc); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, text); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, text); free (text); } else { - r_sys_perror ("malloc"); + rz_sys_perror ("malloc"); } } else { - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); } free (nc); } break; case '*': // "CC*" - r_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 1); + rz_meta_print_list_all (core->anal, R_META_TYPE_COMMENT, 1); break; case '-': // "CC-" if (input[2] == '*') { // "CC-*" - r_meta_del (core->anal, R_META_TYPE_COMMENT, UT64_MAX, UT64_MAX); + rz_meta_del (core->anal, R_META_TYPE_COMMENT, UT64_MAX, UT64_MAX); } else if (input[2]) { // "CC-$$+32" - ut64 arg = r_num_math (core->num, input + 2); - r_meta_del (core->anal, R_META_TYPE_COMMENT, arg, 1); + ut64 arg = rz_num_math (core->num, input + 2); + rz_meta_del (core->anal, R_META_TYPE_COMMENT, arg, 1); } else { // "CC-" - r_meta_del (core->anal, R_META_TYPE_COMMENT, core->offset, 1); + rz_meta_del (core->anal, R_META_TYPE_COMMENT, core->offset, 1); } break; case 'u': // "CCu" @@ -493,9 +493,9 @@ static int cmd_meta_comment(RCore *core, const char *input) { newcomment = strdup (arg); } if (newcomment) { - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); if (!comment || (comment && !strstr (comment, newcomment))) { - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, newcomment); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, newcomment); } free (newcomment); } @@ -518,28 +518,28 @@ static int cmd_meta_comment(RCore *core, const char *input) { ut64 addr; if (input[2]=='-') { if (input[3]) { - addr = r_num_math (core->num, input+3); - r_meta_del (core->anal, + addr = rz_num_math (core->num, input+3); + rz_meta_del (core->anal, R_META_TYPE_COMMENT, addr, 1); } else eprintf ("Usage: CCa-[address]\n"); free (s); return true; } - addr = r_num_math (core->num, s); + addr = rz_num_math (core->num, s); // Comment at if (p) { if (input[2]=='+') { - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); if (comment) { - char *text = r_str_newf ("%s\n%s", comment, p); - r_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, text); + char *text = rz_str_newf ("%s\n%s", comment, p); + rz_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, text); free (text); } else { - r_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, p); + rz_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, p); } } else { - r_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, p); + rz_meta_set (core->anal, R_META_TYPE_COMMENT, addr, 1, p); } } else { eprintf ("Usage: CCa [address] [comment]\n"); @@ -551,56 +551,56 @@ static int cmd_meta_comment(RCore *core, const char *input) { return true; } -static int cmd_meta_vartype_comment(RCore *core, const char *input) { +static int cmd_meta_vartype_comment(RzCore *core, const char *input) { ut64 addr = core->offset; switch (input[1]) { case '?': // "Ct?" - r_core_cmd_help (core, help_msg_Ct); + rz_core_cmd_help (core, help_msg_Ct); break; case 0: // "Ct" - r_meta_print_list_all (core->anal, R_META_TYPE_VARTYPE, 0); + rz_meta_print_list_all (core->anal, R_META_TYPE_VARTYPE, 0); break; case ' ': // "Ct @ addr" { - const char* newcomment = r_str_trim_head_ro (input + 2); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, addr); + const char* newcomment = rz_str_trim_head_ro (input + 2); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_VARTYPE, addr); char *nc = strdup (newcomment); - r_str_unescape (nc); + rz_str_unescape (nc); if (comment) { - char *text = r_str_newf ("%s %s", comment, nc); + char *text = rz_str_newf ("%s %s", comment, nc); if (text) { - r_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, text); + rz_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, text); free (text); } else { - r_sys_perror ("malloc"); + rz_sys_perror ("malloc"); } } else { - r_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, nc); + rz_meta_set_string (core->anal, R_META_TYPE_VARTYPE, addr, nc); } free (nc); } break; case '.': // "Ct. @ addr" { - ut64 at = input[2]? r_num_math (core->num, input + 2): addr; - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, at); + ut64 at = input[2]? rz_num_math (core->num, input + 2): addr; + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_VARTYPE, at); if (comment) { - r_cons_println (comment); + rz_cons_println (comment); } } break; case '-': // "Ct-" - r_meta_del (core->anal, R_META_TYPE_VARTYPE, core->offset, 1); + rz_meta_del (core->anal, R_META_TYPE_VARTYPE, core->offset, 1); break; default: - r_core_cmd_help (core, help_msg_Ct); + rz_core_cmd_help (core, help_msg_Ct); break; } return true; } -static int cmd_meta_others(RCore *core, const char *input) { +static int cmd_meta_others(RzCore *core, const char *input) { int n, type = input[0], subtype; char *t = 0, *p, *p2, name[256]; int repeat = 1; @@ -614,7 +614,7 @@ static int cmd_meta_others(RCore *core, const char *input) { case '?': switch (input[0]) { case 'f': // "Cf?" - r_cons_println( + rz_cons_println( "Usage: Cf[-] [sz] [fmt..] [@addr]\n\n" "'sz' indicates the byte size taken up by struct.\n" "'fmt' is a 'pf?' style format string. It controls only the display format.\n\n" @@ -624,57 +624,57 @@ static int cmd_meta_others(RCore *core, const char *input) { "to match the total struct size in mem.\n"); break; case 's': // "Cs?" - r_core_cmd_help (core, help_msg_Cs); + rz_core_cmd_help (core, help_msg_Cs); break; default: - r_cons_println ("See C?"); + rz_cons_println ("See C?"); break; } break; case '-': // "Cf-", "Cd-", ... switch (input[2]) { case '*': // "Cf-*", "Cd-*", ... - r_meta_del (core->anal, input[0], 0, UT64_MAX); + rz_meta_del (core->anal, input[0], 0, UT64_MAX); break; case ' ': p2 = strchr (input + 3, ' '); if (p2) { ut64 i; - ut64 size = r_num_math (core->num, input + 3); - ut64 rep = r_num_math (core->num, p2 + 1); + ut64 size = rz_num_math (core->num, input + 3); + ut64 rep = rz_num_math (core->num, p2 + 1); ut64 cur_addr = addr; if (!size) { break; } for (i = 0; i < rep && UT64_MAX - cur_addr > size; i++, cur_addr += size) { - r_meta_del (core->anal, input[0], cur_addr, size); + rz_meta_del (core->anal, input[0], cur_addr, size); } break; } else { - addr = r_num_math (core->num, input + 3); + addr = rz_num_math (core->num, input + 3); /* fallthrough */ } default: - r_meta_del (core->anal, input[0], addr, 1); + rz_meta_del (core->anal, input[0], addr, 1); break; } break; case '*': // "Cf*", "Cd*", ... - r_meta_print_list_all (core->anal, input[0], 1); + rz_meta_print_list_all (core->anal, input[0], 1); break; case 'j': // "Cfj", "Cdj", ... - r_meta_print_list_all (core->anal, input[0], 'j'); + rz_meta_print_list_all (core->anal, input[0], 'j'); break; case '!': // "Cf!", "Cd!", ... { char *out; - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); - out = r_core_editor (core, NULL, comment); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + out = rz_core_editor (core, NULL, comment); if (out) { - //r_meta_set (core->anal->meta, R_META_TYPE_COMMENT, addr, 0, out); - r_core_cmdf (core, "CC-@0x%08"PFMT64x, addr); - //r_meta_del (core->anal->meta, input[0], addr, addr+1); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, out); + //rz_meta_set (core->anal->meta, R_META_TYPE_COMMENT, addr, 0, out); + rz_core_cmdf (core, "CC-@0x%08"PFMT64x, addr); + //rz_meta_del (core->anal->meta, input[0], addr, addr+1); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, out); free (out); } } @@ -682,22 +682,22 @@ static int cmd_meta_others(RCore *core, const char *input) { case '.': // "Cf.", "Cd.", ... if (input[2] == '.') { // "Cs.." ut64 size; - RAnalMetaItem *mi = r_meta_get_at (core->anal, addr, type, &size); + RzAnalMetaItem *mi = rz_meta_get_at (core->anal, addr, type, &size); if (mi) { - r_meta_print (core->anal, mi, addr, size, input[3], NULL, false); + rz_meta_print (core->anal, mi, addr, size, input[3], NULL, false); } break; } else if (input[2] == 'j') { // "Cs.j" ut64 size; - RAnalMetaItem *mi = r_meta_get_at (core->anal, addr, type, &size); + RzAnalMetaItem *mi = rz_meta_get_at (core->anal, addr, type, &size); if (mi) { - r_meta_print (core->anal, mi, addr, size, input[2], NULL, false); - r_cons_newline (); + rz_meta_print (core->anal, mi, addr, size, input[2], NULL, false); + rz_cons_newline (); } break; } ut64 size; - RAnalMetaItem *mi = r_meta_get_at (core->anal, addr, type, &size); + RzAnalMetaItem *mi = rz_meta_get_at (core->anal, addr, type, &size); if (!mi) { break; } @@ -706,23 +706,23 @@ static int cmd_meta_others(RCore *core, const char *input) { bool esc_bslash = core->print->esc_bslash; switch (mi->subtype) { case R_STRING_ENC_UTF8: - esc_str = r_str_escape_utf8 (mi->str, false, esc_bslash); + esc_str = rz_str_escape_utf8 (mi->str, false, esc_bslash); break; case 0: /* temporary legacy workaround */ esc_bslash = false; default: - esc_str = r_str_escape_latin1 (mi->str, false, esc_bslash, false); + esc_str = rz_str_escape_latin1 (mi->str, false, esc_bslash, false); } if (esc_str) { - r_cons_printf ("\"%s\"\n", esc_str); + rz_cons_printf ("\"%s\"\n", esc_str); free (esc_str); } else { - r_cons_println (""); + rz_cons_println (""); } } else if (type == 'd') { - r_cons_printf ("%"PFMT64u"\n", size); + rz_cons_printf ("%"PFMT64u"\n", size); } else { - r_cons_println (mi->str); + rz_cons_println (mi->str); } break; case ' ': // "Cf", "Cd", ... @@ -731,7 +731,7 @@ static int cmd_meta_others(RCore *core, const char *input) { case 'a': case '8': if (type != 'z' && !input[1] && !core->tmpseek) { - r_meta_print_list_all (core->anal, type, 0); + rz_meta_print_list_all (core->anal, type, 0); break; } if (type == 'z') { @@ -745,7 +745,7 @@ static int cmd_meta_others(RCore *core, const char *input) { } if (*input == 'd') { if (rep) { - repeat = r_num_math (core->num, rep + 1); + repeat = rz_num_math (core->num, rep + 1); } } } @@ -755,18 +755,18 @@ static int cmd_meta_others(RCore *core, const char *input) { } while (repcnt < repeat) { int off = (!input[1] || input[1] == ' ') ? 1 : 2; - t = strdup (r_str_trim_head_ro (input + off)); + t = strdup (rz_str_trim_head_ro (input + off)); p = NULL; n = 0; strncpy (name, t, sizeof (name) - 1); if (type != 'C') { - n = r_num_math (core->num, t); + n = rz_num_math (core->num, t); if (type == 'f') { // "Cf" p = strchr (t, ' '); if (p) { - p = (char *)r_str_trim_head_ro (p); + p = (char *)rz_str_trim_head_ro (p); if (*p == '.') { - const char *realformat = r_print_format_byname (core->print, p + 1); + const char *realformat = rz_print_format_byname (core->print, p + 1); if (realformat) { p = (char *)realformat; } else { @@ -775,17 +775,17 @@ static int cmd_meta_others(RCore *core, const char *input) { } } if (n < 1) { - n = r_print_format_struct_size (core->print, p, 0, 0); + n = rz_print_format_struct_size (core->print, p, 0, 0); if (n < 1) { eprintf ("Warning: Cannot resolve struct size for '%s'\n", p); n = 32; // } } - //make sure we do not overflow on r_print_format + //make sure we do not overflow on rz_print_format if (n > core->blocksize) { n = core->blocksize; } - int r = r_print_format (core->print, addr, core->block, + int r = rz_print_format (core->print, addr, core->block, n, p, 0, NULL, NULL); if (r < 0) { n = -1; @@ -798,12 +798,12 @@ static int cmd_meta_others(RCore *core, const char *input) { char tmp[256] = R_EMPTY; int i, j, name_len = 0; if (input[1] == 'a' || input[1] == '8') { - (void)r_io_read_at (core->io, addr, (ut8*)name, sizeof (name) - 1); + (void)rz_io_read_at (core->io, addr, (ut8*)name, sizeof (name) - 1); name[sizeof (name) - 1] = '\0'; name_len = strlen (name); } else { - (void)r_io_read_at (core->io, addr, (ut8*)tmp, sizeof (tmp) - 3); - name_len = r_str_nlen_w (tmp, sizeof (tmp) - 3); + (void)rz_io_read_at (core->io, addr, (ut8*)tmp, sizeof (tmp) - 3); + name_len = rz_str_nlen_w (tmp, sizeof (tmp) - 3); //handle wide strings for (i = 0, j = 0; i < sizeof (name); i++, j++) { name[i] = tmp[j]; @@ -834,15 +834,15 @@ static int cmd_meta_others(RCore *core, const char *input) { return false; } if (!*t || n > 0) { - RFlagItem *fi; + RzFlagItem *fi; p = strchr (t, ' '); if (p) { *p++ = '\0'; - p = (char *)r_str_trim_head_ro (p); + p = (char *)rz_str_trim_head_ro (p); strncpy (name, p, sizeof (name)-1); } else { if (type != 's') { - fi = r_flag_get_i (core->flags, addr); + fi = rz_flag_get_i (core->flags, addr); if (fi) { strncpy (name, fi->name, sizeof (name)-1); } @@ -862,15 +862,15 @@ static int cmd_meta_others(RCore *core, const char *input) { default: subtype = R_STRING_ENC_GUESS; } - r_meta_set_with_subtype (core->anal, type, subtype, addr, n, name); + rz_meta_set_with_subtype (core->anal, type, subtype, addr, n, name); } else { - r_meta_set (core->anal, type, addr, n, name); + rz_meta_set (core->anal, type, addr, n, name); } free (t); repcnt ++; addr += n; } - //r_meta_cleanup (core->anal->meta, 0LL, UT64_MAX); + //rz_meta_cleanup (core->anal->meta, 0LL, UT64_MAX); break; default: eprintf ("Missing space after CC\n"); @@ -880,54 +880,54 @@ static int cmd_meta_others(RCore *core, const char *input) { return true; } -void r_comment_var_help(RCore *core, char type) { +void rz_comment_var_help(RzCore *core, char type) { switch (type) { case 'b': - r_core_cmd_help (core, help_msg_Cvb); + rz_core_cmd_help (core, help_msg_Cvb); break; case 's': - r_core_cmd_help (core, help_msg_Cvs); + rz_core_cmd_help (core, help_msg_Cvs); break; case 'r': - r_core_cmd_help (core, help_msg_Cvr); + rz_core_cmd_help (core, help_msg_Cvr); break; case '?': - r_cons_printf("See Cvb?, Cvs? and Cvr?\n"); + rz_cons_printf("See Cvb?, Cvs? and Cvr?\n"); } } -void r_comment_vars(RCore *core, const char *input) { +void rz_comment_vars(RzCore *core, const char *input) { //TODO enable base64 and make it the default for C* - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); char *oname = NULL, *name = NULL; if (!input[0] || input[1] == '?' || (input[0] != 'b' && input[0] != 'r' && input[0] != 's')) { - r_comment_var_help (core, input[0]); + rz_comment_var_help (core, input[0]); return; } if (!fcn) { eprintf ("Can't find function here\n"); return; } - oname = name = r_str_trim_dup (input + 1); + oname = name = rz_str_trim_dup (input + 1); switch (input[1]) { case '*': // "Cv*" case '\0': { // "Cv" void **it; char kind = input[0]; - r_pvector_foreach (&fcn->vars, it) { - RAnalVar *var = *it; + rz_pvector_foreach (&fcn->vars, it) { + RzAnalVar *var = *it; if (var->kind != kind || !var->comment) { continue; } if (!input[1]) { - r_cons_printf ("%s : %s\n", var->name, var->comment); + rz_cons_printf ("%s : %s\n", var->name, var->comment); } else { char *b64 = sdb_encode ((const ut8 *)var->comment, strlen (var->comment)); if (!b64) { continue; } - r_cons_printf ("\"Cv%c %s base64:%s @ 0x%08"PFMT64x"\"\n", kind, var->name, b64, fcn->addr); + rz_cons_printf ("\"Cv%c %s base64:%s @ 0x%08"PFMT64x"\"\n", kind, var->name, b64, fcn->addr); } } } @@ -944,21 +944,21 @@ void r_comment_vars(RCore *core, const char *input) { comment = heap_comment; } } - RAnalVar *var = r_anal_function_get_var_byname (fcn, name); + RzAnalVar *var = rz_anal_function_get_var_byname (fcn, name); if (!var) { int idx = (int)strtol (name, NULL, 0); - var = r_anal_function_get_var (fcn, input[0], idx); + var = rz_anal_function_get_var (fcn, input[0], idx); } if (!var) { eprintf ("can't find variable at given offset\n"); } else { if (var->comment) { if (comment && *comment) { - char *text = r_str_newf ("%s\n%s", var->comment, comment); + char *text = rz_str_newf ("%s\n%s", var->comment, comment); free (var->comment); var->comment = text; } else { - r_cons_println (var->comment); + rz_cons_println (var->comment); } } else { var->comment = strdup (comment); @@ -969,11 +969,11 @@ void r_comment_vars(RCore *core, const char *input) { break; case '-': { // "Cv-" name++; - r_str_trim (name); - RAnalVar *var = r_anal_function_get_var_byname (fcn, name); + rz_str_trim (name); + RzAnalVar *var = rz_anal_function_get_var_byname (fcn, name); if (!var) { int idx = (int)strtol (name, NULL, 0); - var = r_anal_function_get_var (fcn, input[0], idx); + var = rz_anal_function_get_var (fcn, input[0], idx); } if (!var) { eprintf ("can't find variable at given offset\n"); @@ -986,13 +986,13 @@ void r_comment_vars(RCore *core, const char *input) { case '!': { // "Cv!" char *comment; name++; - r_str_trim (name); - RAnalVar *var = r_anal_function_get_var_byname (fcn, name); + rz_str_trim (name); + RzAnalVar *var = rz_anal_function_get_var_byname (fcn, name); if (!var) { eprintf ("can't find variable named `%s`\n", name); break; } - comment = r_core_editor (core, NULL, var->comment); + comment = rz_core_editor (core, NULL, var->comment); if (comment) { free (var->comment); var->comment = comment; @@ -1004,29 +1004,29 @@ void r_comment_vars(RCore *core, const char *input) { } static int cmd_meta(void *data, const char *input) { - RCore *core = (RCore*)data; - RAnalFunction *f; + RzCore *core = (RzCore*)data; + RzAnalFunction *f; RSpaces *ms; int i; switch (*input) { case 'v': // "Cv" - r_comment_vars (core, input + 1); + rz_comment_vars (core, input + 1); break; case '\0': // "C" - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, 0); + rz_meta_print_list_all (core->anal, R_META_TYPE_ANY, 0); break; case 'j': // "Cj" case '*': { // "C*" if (!input[0] || input[1] == '.') { - r_meta_print_list_at (core->anal, core->offset, *input); + rz_meta_print_list_at (core->anal, core->offset, *input); } else { - r_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input); + rz_meta_print_list_all (core->anal, R_META_TYPE_ANY, *input); } break; } case '.': { // "C." - r_meta_print_list_at (core->anal, core->offset, 0); + rz_meta_print_list_at (core->anal, core->offset, 0); break; } case 'L': // "CL" @@ -1049,20 +1049,20 @@ static int cmd_meta(void *data, const char *input) { break; case '-': // "C-" if (input[1] != '*') { - i = input[1] ? r_num_math (core->num, input + (input[1] == ' ' ? 2 : 1)) : 1; - r_meta_del (core->anal, R_META_TYPE_ANY, core->offset, i); + i = input[1] ? rz_num_math (core->num, input + (input[1] == ' ' ? 2 : 1)) : 1; + rz_meta_del (core->anal, R_META_TYPE_ANY, core->offset, i); } else { - r_meta_del (core->anal, R_META_TYPE_ANY, 0, UT64_MAX); + rz_meta_del (core->anal, R_META_TYPE_ANY, 0, UT64_MAX); } break; case '?': // "C?" - r_core_cmd_help (core, help_msg_C); + rz_core_cmd_help (core, help_msg_C); break; case 'F': // "CF" - f = r_anal_get_fcn_in (core->anal, core->offset, + f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM); if (f) { - r_anal_str_to_fcn (core->anal, f, input + 2); + rz_anal_str_to_fcn (core->anal, f, input + 2); } else { eprintf ("Cannot find function here\n"); } @@ -1072,14 +1072,14 @@ static int cmd_meta(void *data, const char *input) { /** copypasta from `fs`.. this must be refactorized to be shared */ switch (input[1]) { case '?': // "CS?" - r_core_cmd_help (core, help_msg_CS); + rz_core_cmd_help (core, help_msg_CS); break; case '+': // "CS+" - r_spaces_push (ms, input + 2); + rz_spaces_push (ms, input + 2); break; case 'r': // "CSr" if (input[2] == ' ') { - r_spaces_rename (ms, NULL, input+2); + rz_spaces_rename (ms, NULL, input+2); } else { eprintf ("Usage: CSr [newname]\n"); } @@ -1087,12 +1087,12 @@ static int cmd_meta(void *data, const char *input) { case '-': // "CS-" if (input[2]) { if (input[2]=='*') { - r_spaces_unset (ms, NULL); + rz_spaces_unset (ms, NULL); } else { - r_spaces_unset (ms, input+2); + rz_spaces_unset (ms, input+2); } } else { - r_spaces_pop (ms); + rz_spaces_pop (ms); } break; case 'j': // "CSj" @@ -1101,7 +1101,7 @@ static int cmd_meta(void *data, const char *input) { spaces_list (ms, input[1]); break; case ' ': // "CS " - r_spaces_set (ms, input + 2); + rz_spaces_set (ms, input + 2); break; default: spaces_list (ms, 0); diff --git a/libr/core/cmd_mount.c b/librz/core/cmd_mount.c similarity index 62% rename from libr/core/cmd_mount.c rename to librz/core/cmd_mount.c index 4a52f3ed80..c40d8767fc 100644 --- a/libr/core/cmd_mount.c +++ b/librz/core/cmd_mount.c @@ -24,21 +24,21 @@ static const char *help_msg_m[] = { NULL }; -static void cmd_mount_init(RCore *core, RCmdDesc *parent) { +static void cmd_mount_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, m); } static int cmd_mkdir(void *data, const char *input) { - char *res = r_syscmd_mkdir (input); + char *res = rz_syscmd_mkdir (input); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } return 0; } static int cmd_mv(void *data, const char *input) { - return r_syscmd_mv (input)? 1: 0; + return rz_syscmd_mv (input)? 1: 0; } static char *cwd = NULL; @@ -53,37 +53,37 @@ static const char *t2s(const char ch) { return "unknown"; } -static void cmd_mount_ls (RCore *core, const char *input) { +static void cmd_mount_ls (RzCore *core, const char *input) { bool isJSON = *input == 'j'; - RListIter *iter; - RFSFile *file; - RFSRoot *root; - input = r_str_trim_head_ro (input + isJSON); - RList *list = r_fs_dir (core->fs, input); + RzListIter *iter; + RzFSFile *file; + RzFSRoot *root; + input = rz_str_trim_head_ro (input + isJSON); + RzList *list = rz_fs_dir (core->fs, input); PJ *pj = NULL; if (isJSON) { pj = pj_new (); pj_a (pj); } if (list) { - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { if (isJSON) { pj_o (pj); pj_ks (pj, "type", t2s(file->type)); pj_ks (pj, "name", file->name); pj_end (pj); } else { - r_cons_printf ("%c %s\n", file->type, file->name); + rz_cons_printf ("%c %s\n", file->type, file->name); } } - r_list_free (list); + rz_list_free (list); } const char *path = *input? input: "/"; - r_list_foreach (core->fs->roots, iter, root) { + rz_list_foreach (core->fs->roots, iter, root) { // TODO: adjust contents between // if (!strncmp (path, root->path, strlen (path))) { char *base = strdup (root->path); - char *ls = (char *)r_str_lchr (base, '/'); + char *ls = (char *)rz_str_lchr (base, '/'); if (ls) { ls++; *ls = 0; @@ -96,7 +96,7 @@ static void cmd_mount_ls (RCore *core, const char *input) { pj_ks (pj, "type", "mountpoint"); pj_end (pj); } else { - r_cons_printf ("m %s\n", root->path); // (root->path && root->path[0]) ? root->path + 1: ""); + rz_cons_printf ("m %s\n", root->path); // (root->path && root->path[0]) ? root->path + 1: ""); } } free (base); @@ -104,7 +104,7 @@ static void cmd_mount_ls (RCore *core, const char *input) { } if (isJSON) { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } @@ -112,13 +112,13 @@ static void cmd_mount_ls (RCore *core, const char *input) { static int cmd_mount(void *data, const char *_input) { ut64 off = 0; char *input, *oinput, *ptr, *ptr2; - RList *list; - RListIter *iter; - RFSFile *file; - RFSRoot *root; - RFSPlugin *plug; - RFSPartition *part; - RCore *core = (RCore *)data; + RzList *list; + RzListIter *iter; + RzFSFile *file; + RzFSRoot *root; + RzFSPlugin *plug; + RzFSPartition *part; + RzCore *core = (RzCore *)data; if (!strncmp ("kdir", _input, 4)) { return cmd_mkdir (data, _input); @@ -130,18 +130,18 @@ static int cmd_mount(void *data, const char *_input) { switch (*input) { case ' ': - input = (char *)r_str_trim_head_ro (input + 1); + input = (char *)rz_str_trim_head_ro (input + 1); ptr = strchr (input, ' '); if (ptr) { *ptr = 0; - ptr = (char *)r_str_trim_head_ro (ptr + 1); + ptr = (char *)rz_str_trim_head_ro (ptr + 1); ptr2 = strchr (ptr, ' '); if (ptr2) { *ptr2 = 0; - off = r_num_math (core->num, ptr2+1); + off = rz_num_math (core->num, ptr2+1); } - input = (char *)r_str_trim_head_ro (input); - ptr = (char*)r_str_trim_head_ro (ptr); + input = (char *)rz_str_trim_head_ro (input); + ptr = (char*)rz_str_trim_head_ro (ptr); const char *mountp = input; const char *fstype = ptr; @@ -154,21 +154,21 @@ static int cmd_mount(void *data, const char *_input) { fstype = input; } - if (!r_fs_mount (core->fs, fstype, mountp, off)) { + if (!rz_fs_mount (core->fs, fstype, mountp, off)) { eprintf ("Cannot mount %s\n", input); } } else { - if (!(ptr = r_fs_name (core->fs, core->offset))) { + if (!(ptr = rz_fs_name (core->fs, core->offset))) { eprintf ("Unknown filesystem type\n"); } - if (!r_fs_mount (core->fs, ptr, input, core->offset)) { + if (!rz_fs_mount (core->fs, ptr, input, core->offset)) { eprintf ("Cannot mount %s\n", input); } free (ptr); } break; case '-': - r_fs_umount (core->fs, input+1); + rz_fs_umount (core->fs, input+1); break; case 'j': { @@ -176,7 +176,7 @@ static int cmd_mount(void *data, const char *_input) { pj_o (pj); pj_k (pj, "mountpoints"); pj_a (pj); - r_list_foreach (core->fs->roots, iter, root) { + rz_list_foreach (core->fs->roots, iter, root) { pj_o (pj); pj_ks (pj, "path", root->path); pj_ks (pj, "plugin", root->p->name); @@ -186,7 +186,7 @@ static int cmd_mount(void *data, const char *_input) { pj_end (pj); pj_k (pj, "plugins"); pj_a (pj); - r_list_foreach (core->fs->plugins, iter, plug) { + rz_list_foreach (core->fs->plugins, iter, plug) { pj_o (pj); pj_ks (pj, "name", plug->name); pj_ks (pj, "description", plug->desc); @@ -195,25 +195,25 @@ static int cmd_mount(void *data, const char *_input) { pj_end (pj); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } break; case '*': - r_list_foreach (core->fs->roots, iter, root) { - r_cons_printf ("m %s %s 0x%"PFMT64x"\n", + rz_list_foreach (core->fs->roots, iter, root) { + rz_cons_printf ("m %s %s 0x%"PFMT64x"\n", root-> path, root->p->name, root->delta); } break; case '\0': - r_list_foreach (core->fs->roots, iter, root) { - r_cons_printf ("%s\t0x%"PFMT64x"\t%s\n", + rz_list_foreach (core->fs->roots, iter, root) { + rz_cons_printf ("%s\t0x%"PFMT64x"\t%s\n", root->p->name, root->delta, root->path); } break; case 'L': // "mL" list of plugins - r_list_foreach (core->fs->plugins, iter, plug) { - r_cons_printf ("%10s %s\n", plug->name, plug->desc); + rz_list_foreach (core->fs->plugins, iter, plug) { + rz_cons_printf ("%10s %s\n", plug->name, plug->desc); } break; case 'l': // "ml" @@ -228,16 +228,16 @@ static int cmd_mount(void *data, const char *_input) { ptr = strchr (input, ' '); if (ptr) { *ptr = 0; - off = r_num_math (core->num, ptr+1); + off = rz_num_math (core->num, ptr+1); } - list = r_fs_partitions (core->fs, input, off); + list = rz_fs_partitions (core->fs, input, off); if (list) { - r_list_foreach (list, iter, part) { - r_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n", + rz_list_foreach (list, iter, part) { + rz_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n", part->number, part->type, part->start, part->start+part->length); } - r_list_free (list); + rz_list_free (list); } else { eprintf ("Cannot read partition\n"); } @@ -247,13 +247,13 @@ static int cmd_mount(void *data, const char *_input) { if (input[0]==' ') { input++; } - file = r_fs_open (core->fs, input, false); + file = rz_fs_open (core->fs, input, false); if (file) { - r_fs_read (core->fs, file, 0, file->size); - char *uri = r_str_newf ("malloc://%d", file->size); - RIODesc *fd = r_io_open (core->io, uri, R_PERM_RW, 0); + rz_fs_read (core->fs, file, 0, file->size); + char *uri = rz_str_newf ("malloc://%d", file->size); + RzIODesc *fd = rz_io_open (core->io, uri, R_PERM_RW, 0); if (fd) { - r_io_desc_write (fd, file->data, file->size); + rz_io_desc_write (fd, file->data, file->size); } } else { eprintf ("Cannot open file\n"); @@ -264,12 +264,12 @@ static int cmd_mount(void *data, const char *_input) { if (input[0]==' ') { input++; } - file = r_fs_open (core->fs, input, false); + file = rz_fs_open (core->fs, input, false); if (file) { // XXX: dump to file or just pipe? - r_fs_read (core->fs, file, 0, file->size); - r_cons_printf ("f file %d 0x%08"PFMT64x"\n", file->size, file->off); - r_fs_close (core->fs, file); + rz_fs_read (core->fs, file, 0, file->size); + rz_cons_printf ("f file %d 0x%08"PFMT64x"\n", file->size, file->off); + rz_fs_close (core->fs, file); } else { eprintf ("Cannot open file\n"); } @@ -285,13 +285,13 @@ static int cmd_mount(void *data, const char *_input) { } else { ptr = "./"; } - file = r_fs_open (core->fs, input, false); + file = rz_fs_open (core->fs, input, false); if (file) { - r_fs_read (core->fs, file, 0, file->size); - r_cons_memcat ((const char *)file->data, file->size); - r_fs_close (core->fs, file); - r_cons_memcat ("\n", 1); - } else if (!r_fs_dir_dump (core->fs, input, ptr)) { + rz_fs_read (core->fs, file, 0, file->size); + rz_cons_memcat ((const char *)file->data, file->size); + rz_fs_close (core->fs, file); + rz_cons_memcat ("\n", 1); + } else if (!rz_fs_dir_dump (core->fs, input, ptr)) { eprintf ("Cannot open file\n"); } break; @@ -306,19 +306,19 @@ static int cmd_mount(void *data, const char *_input) { } else { ptr = "./"; } - file = r_fs_open (core->fs, input, false); + file = rz_fs_open (core->fs, input, false); if (file) { char *localFile = strdup (input); - char *slash = (char *)r_str_rchr (localFile, NULL, '/'); + char *slash = (char *)rz_str_rchr (localFile, NULL, '/'); if (slash) { memmove (localFile, slash + 1, strlen (slash)); } - r_fs_read (core->fs, file, 0, file->size); - r_file_dump (localFile, file->data, file->size, false); - r_fs_close (core->fs, file); + rz_fs_read (core->fs, file, 0, file->size); + rz_file_dump (localFile, file->data, file->size, false); + rz_fs_close (core->fs, file); eprintf ("File '%s' created.\n", localFile); free (localFile); - } else if (!r_fs_dir_dump (core->fs, input, ptr)) { + } else if (!rz_fs_dir_dump (core->fs, input, ptr)) { eprintf ("Cannot open file\n"); } break; @@ -326,7 +326,7 @@ static int cmd_mount(void *data, const char *_input) { input++; switch (*input) { case '?': - r_cons_printf ( + rz_cons_printf ( "Usage: mf[no] [...]\n" " mfn /foo *.c ; search files by name in /foo path\n" " mfo /foo 0x5e91 ; search files by offset in /foo path\n" @@ -339,12 +339,12 @@ static int cmd_mount(void *data, const char *_input) { ptr = strchr (input, ' '); if (ptr) { *ptr++ = 0; - list = r_fs_find_name (core->fs, input, ptr); - r_list_foreach (list, iter, ptr) { - r_str_trim_path (ptr); + list = rz_fs_find_name (core->fs, input, ptr); + rz_list_foreach (list, iter, ptr) { + rz_str_trim_path (ptr); printf ("%s\n", ptr); } - //XXX: r_list_purge (list); + //XXX: rz_list_purge (list); } else eprintf ("Unknown store path\n"); break; case 'o': @@ -354,13 +354,13 @@ static int cmd_mount(void *data, const char *_input) { ptr = strchr (input, ' '); if (ptr) { *ptr++ = 0; - ut64 off = r_num_math (core->num, ptr); - list = r_fs_find_off (core->fs, input, off); - r_list_foreach (list, iter, ptr) { - r_str_trim_path (ptr); + ut64 off = rz_num_math (core->num, ptr); + list = rz_fs_find_off (core->fs, input, off); + rz_list_foreach (list, iter, ptr) { + rz_str_trim_path (ptr); printf ("%s\n", ptr); } - //XXX: r_list_purge (list); + //XXX: rz_list_purge (list); } else eprintf ("Unknown store path\n"); break; } @@ -374,26 +374,26 @@ static int cmd_mount(void *data, const char *_input) { if (input[0] == ' ') { input++; } - r_cons_set_raw (false); + rz_cons_set_raw (false); { - RFSShell shell = { + RzFSShell shell = { .cwd = &cwd, - .set_prompt = r_line_set_prompt, - .readline = r_line_readline, - .hist_add = r_line_hist_add + .set_prompt = rz_line_set_prompt, + .readline = rz_line_readline, + .hist_add = rz_line_hist_add }; core->rfs = &shell; core->autocomplete_type = AUTOCOMPLETE_MS; - r_core_autocomplete_reload (core); - r_fs_shell_prompt (&shell, core->fs, input); + rz_core_autocomplete_reload (core); + rz_fs_shell_prompt (&shell, core->fs, input); core->autocomplete_type = AUTOCOMPLETE_DEFAULT; - r_core_autocomplete_reload (core); + rz_core_autocomplete_reload (core); R_FREE (cwd); } break; case 'w': if (input[1] == ' ') { - char *args = r_str_trim_dup (input + 1); + char *args = rz_str_trim_dup (input + 1); char *arg = strchr (args, ' '); if (arg) { data = arg + 1; @@ -401,11 +401,11 @@ static int cmd_mount(void *data, const char *_input) { data = ""; // touch and truncate } - RFSFile *f = r_fs_open (core->fs, args, true); + RzFSFile *f = rz_fs_open (core->fs, args, true); if (f) { - r_fs_write (core->fs, f, 0, (const ut8 *)data, strlen (data)); - r_fs_close (core->fs, f); - r_fs_file_free (f); + rz_fs_write (core->fs, f, 0, (const ut8 *)data, strlen (data)); + rz_fs_close (core->fs, f); + rz_fs_file_free (f); } free (args); } else { @@ -416,7 +416,7 @@ static int cmd_mount(void *data, const char *_input) { eprintf ("TODO\n"); break; case '?': - r_core_cmd_help (core, help_msg_m); + rz_core_cmd_help (core, help_msg_m); break; } free (oinput); diff --git a/libr/core/cmd_open.c b/librz/core/cmd_open.c similarity index 58% rename from libr/core/cmd_open.c rename to librz/core/cmd_open.c index 937ef9ca59..2529e4cb9e 100644 --- a/libr/core/cmd_open.c +++ b/librz/core/cmd_open.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include "r_list.h" -#include "r_config.h" -#include "r_core.h" -#include "r_util.h" -#include "r_bin.h" -#include "r_debug.h" +#include "rz_list.h" +#include "rz_config.h" +#include "rz_core.h" +#include "rz_util.h" +#include "rz_bin.h" +#include "rz_debug.h" static const char *help_msg_o[] = { "Usage: o","[com- ] [file] ([offset])","", @@ -28,7 +28,7 @@ static const char *help_msg_o[] = { "oi","[-|idx]","alias for o, but using index instead of fd", "oj","[?] ","list opened files in JSON format", "om","[?]","create, list, remove IO maps", - "on"," [file] 0x4000","map raw file at 0x4000 (no r_bin involved)", + "on"," [file] 0x4000","map raw file at 0x4000 (no rz_bin involved)", "oo","[?+bcdnm]","reopen current file (see oo?) (reload in rw or debugger)", "op"," [fd]", "select the given fd as current file (see also ob)", "oq","","list all open files", @@ -145,7 +145,7 @@ static const char *help_msg_ood[] = { "Usage:", "ood", " # Debug (re)open commands", "ood", " [args]", " # reopen in debug mode (with args)", "oodf", " [file]", " # reopen in debug mode using the given file", - "oodr", " [rarun2]", " # same as dor ..;ood", + "oodr", " [rz_run]", " # same as dor ..;ood", NULL }; @@ -163,7 +163,7 @@ static const char *help_msg_oonn[] = { NULL }; -static void cmd_open_init(RCore *core, RCmdDesc *parent) { +static void cmd_open_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, o); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, o*, o_star); DEFINE_CMD_DESCRIPTOR (core, oa); @@ -179,111 +179,111 @@ static void cmd_open_init(RCore *core, RCmdDesc *parent) { } // HONOR bin.at -static void cmd_open_bin(RCore *core, const char *input) { +static void cmd_open_bin(RzCore *core, const char *input) { const char *value = NULL; ut32 binfile_num = -1; switch (input[1]) { case 'L': // "obL" - r_core_cmd0 (core, "iL"); + rz_core_cmd0 (core, "iL"); break; case '\0': // "ob" case 'q': // "obj" case 'j': // "obj" case '*': // "ob*" - r_core_bin_list (core, input[1]); + rz_core_bin_list (core, input[1]); break; case '.': // "ob." { - const char *arg = r_str_trim_head_ro (input + 2); + const char *arg = rz_str_trim_head_ro (input + 2); ut64 at = core->offset; if (*arg) { - at = r_num_math (core->num, arg); + at = rz_num_math (core->num, arg); if (at == 0 && *arg != '0') { at = core->offset; } } - RBinFile *bf = r_bin_file_at (core->bin, at); + RBinFile *bf = rz_bin_file_at (core->bin, at); if (bf) { - r_cons_printf ("%d\n", bf->id); + rz_cons_printf ("%d\n", bf->id); } } break; case 'a': // "oba" if ('?' == input[2]) { - r_core_cmd_help (core, help_msg_oa); + rz_core_cmd_help (core, help_msg_oa); break; } if (input[2] && input[3]) { char *arg = strdup (input + 3); char *filename = strchr (arg, ' '); if (filename && *filename && (filename[1] == '/' || filename[1] == '.')) { - int saved_fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_open (core->io, filename + 1, R_PERM_R, 0); + int saved_fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_open (core->io, filename + 1, R_PERM_R, 0); if (desc) { *filename = 0; - ut64 addr = r_num_math (core->num, arg); + ut64 addr = rz_num_math (core->num, arg); RBinOptions opt; - r_bin_options_init (&opt, desc->fd, addr, 0, core->bin->rawstr); - r_bin_open_io (core->bin, &opt); - r_io_desc_close (desc); - r_core_cmd0 (core, ".is*"); - r_io_use_fd (core->io, saved_fd); + rz_bin_options_init (&opt, desc->fd, addr, 0, core->bin->rawstr); + rz_bin_open_io (core->bin, &opt); + rz_io_desc_close (desc); + rz_core_cmd0 (core, ".is*"); + rz_io_use_fd (core->io, saved_fd); } else { eprintf ("Cannot open %s\n", filename + 1); } } else if (filename && *filename) { - ut64 baddr = r_num_math (core->num, filename); - ut64 addr = r_num_math (core->num, input + 2); // mapaddr - int fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + ut64 baddr = rz_num_math (core->num, filename); + ut64 addr = rz_num_math (core->num, input + 2); // mapaddr + int fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { RBinOptions opt; opt.baseaddr = baddr; opt.loadaddr = addr; opt.sz = 1024*1024*1; - r_bin_options_init (&opt, desc->fd, baddr, addr, core->bin->rawstr); - r_bin_open_io (core->bin, &opt); - r_core_cmd0 (core, ".is*"); + rz_bin_options_init (&opt, desc->fd, baddr, addr, core->bin->rawstr); + rz_bin_open_io (core->bin, &opt); + rz_core_cmd0 (core, ".is*"); } else { eprintf ("No file to load bin from?\n"); } } else { - ut64 addr = r_num_math (core->num, input + 2); - int fd = r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + ut64 addr = rz_num_math (core->num, input + 2); + int fd = rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { RBinOptions opt; opt.baseaddr = addr; opt.loadaddr = addr; opt.sz = 1024 * 1024 * 1; - r_bin_options_init (&opt, desc->fd, addr, addr, core->bin->rawstr); - r_bin_open_io (core->bin, &opt); - r_core_cmd0 (core, ".is*"); + rz_bin_options_init (&opt, desc->fd, addr, addr, core->bin->rawstr); + rz_bin_open_io (core->bin, &opt); + rz_core_cmd0 (core, ".is*"); } else { eprintf ("No file to load bin from?\n"); } } free (arg); } else { - RList *ofiles = r_id_storage_list (core->io->files); - RIODesc *desc; - RListIter *iter; - RList *files = r_list_newf (NULL); - r_list_foreach (ofiles, iter, desc) { - r_list_append (files, (void*)(size_t)desc->fd); + RzList *ofiles = rz_id_storage_list (core->io->files); + RzIODesc *desc; + RzListIter *iter; + RzList *files = rz_list_newf (NULL); + rz_list_foreach (ofiles, iter, desc) { + rz_list_append (files, (void*)(size_t)desc->fd); } void *_fd; - r_list_foreach (files, iter, _fd) { + rz_list_foreach (files, iter, _fd) { int fd = (size_t)_fd; RBinOptions opt; - r_bin_options_init (&opt, fd, core->offset, 0, core->bin->rawstr); - r_bin_open_io (core->bin, &opt); - r_core_cmd0 (core, ".ies*"); + rz_bin_options_init (&opt, fd, core->offset, 0, core->bin->rawstr); + rz_bin_open_io (core->bin, &opt); + rz_core_cmd0 (core, ".ies*"); break; } - r_list_free (files); + rz_list_free (files); } break; case ' ': // "ob " @@ -297,41 +297,41 @@ static void cmd_open_bin(RCore *core, const char *input) { eprintf ("Invalid arguments"); break; } - n = r_str_word_set0 (v); + n = rz_str_word_set0 (v); if (n < 1 || n > 2) { eprintf ("Usage: ob [file|objid]\n"); free (v); break; } - tmp = r_str_word_get0 (v, 0); - id = *v && r_is_valid_input_num_value (core->num, tmp) - ? r_get_input_num_value (core->num, tmp): UT32_MAX; + tmp = rz_str_word_get0 (v, 0); + id = *v && rz_is_valid_input_num_value (core->num, tmp) + ? rz_get_input_num_value (core->num, tmp): UT32_MAX; if (n == 2) { - tmp = r_str_word_get0 (v, 1); + tmp = rz_str_word_get0 (v, 1); } else { binfile_num = id; } - r_core_bin_raise (core, binfile_num); + rz_core_bin_raise (core, binfile_num); free (v); break; } case 'r': // "obr" - r_core_bin_rebase (core, r_num_math (core->num, input + 3)); - r_core_cmd0 (core, ".is*"); + rz_core_bin_rebase (core, rz_num_math (core->num, input + 3)); + rz_core_cmd0 (core, ".is*"); break; case 'f': if (input[2] == ' ') { - r_core_cmdf (core, "oba 0 %s", input + 3); + rz_core_cmdf (core, "oba 0 %s", input + 3); } else { - r_core_bin_load (core, NULL, UT64_MAX); + rz_core_bin_load (core, NULL, UT64_MAX); value = input[2] ? input + 2 : NULL; } break; case 'o': // "obo" if (input[2] == ' ') { - ut32 fd = r_num_math (core->num, input + 3); - RBinFile *bf = r_bin_file_find_by_fd (core->bin, fd); - if (!bf || !r_core_bin_raise (core, bf->id)) { + ut32 fd = rz_num_math (core->num, input + 3); + RBinFile *bf = rz_bin_file_find_by_fd (core->bin, fd); + if (!bf || !rz_core_bin_raise (core, bf->id)) { eprintf ("Invalid RBinFile.id number.\n"); } } else { @@ -340,61 +340,61 @@ static void cmd_open_bin(RCore *core, const char *input) { break; case '-': // "ob-" if (input[2] == '*') { - r_bin_file_delete_all (core->bin); + rz_bin_file_delete_all (core->bin); } else { ut32 id; - value = r_str_trim_head_ro (input + 2); + value = rz_str_trim_head_ro (input + 2); if (!value) { eprintf ("Invalid argument\n"); break; } - id = (*value && r_is_valid_input_num_value (core->num, value)) ? - r_get_input_num_value (core->num, value) : UT32_MAX; - RBinFile *bf = r_bin_file_find_by_id (core->bin, id); + id = (*value && rz_is_valid_input_num_value (core->num, value)) ? + rz_get_input_num_value (core->num, value) : UT32_MAX; + RBinFile *bf = rz_bin_file_find_by_id (core->bin, id); if (!bf) { eprintf ("Invalid binid\n"); break; } - if (!r_core_bin_delete (core, bf->id)) { + if (!rz_core_bin_delete (core, bf->id)) { eprintf ("Cannot find an RBinFile associated with that id.\n"); } } break; case '=': // "ob=" { - RListIter *iter; - RList *list = r_list_newf ((RListFree) r_listinfo_free); + RzListIter *iter; + RzList *list = rz_list_newf ((RzListFree) rz_listinfo_free); RBinFile *bf = NULL; RBin *bin = core->bin; if (!bin) { return; } - r_list_foreach (bin->binfiles, iter, bf) { + rz_list_foreach (bin->binfiles, iter, bf) { char temp[4]; RInterval inter = (RInterval) {bf->o->baddr, bf->o->size}; - RListInfo *info = r_listinfo_new (bf->file, inter, inter, -1, sdb_itoa (bf->fd, temp, 10)); + RzListInfo *info = rz_listinfo_new (bf->file, inter, inter, -1, sdb_itoa (bf->fd, temp, 10)); if (!info) { break; } - r_list_append (list, info); + rz_list_append (list, info); } - RTable *table = r_core_table (core); - r_table_visual_list (table, list, core->offset, core->blocksize, - r_cons_get_size (NULL), r_config_get_i (core->config, "scr.color")); - char *table_text = r_table_tostring (table); - r_cons_printf ("\n%s\n", table_text); - r_free (table_text); - r_table_free (table); - r_list_free (list); + RTable *table = rz_core_table (core); + rz_table_visual_list (table, list, core->offset, core->blocksize, + rz_cons_get_size (NULL), rz_config_get_i (core->config, "scr.color")); + char *table_text = rz_table_tostring (table); + rz_cons_printf ("\n%s\n", table_text); + rz_free (table_text); + rz_table_free (table); + rz_list_free (list); } break; case '?': // "ob?" - r_core_cmd_help (core, help_msg_ob); + rz_core_cmd_help (core, help_msg_ob); break; } } // TODO: discuss the output format -static void map_list(RIO *io, int mode, RPrint *print, int fd) { +static void map_list(RzIO *io, int mode, RPrint *print, int fd) { if (!io || !print || !print->cb_printf) { return; } @@ -405,8 +405,8 @@ static void map_list(RIO *io, int mode, RPrint *print, int fd) { char *om_cmds = NULL; void **it; - r_pvector_foreach_prev (&io->maps, it) { //this must be prev (LIFO) - RIOMap *map = *it; + rz_pvector_foreach_prev (&io->maps, it) { //this must be prev (LIFO) + RzIOMap *map = *it; if (fd >= 0 && map->fd != fd) { continue; } @@ -425,18 +425,18 @@ static void map_list(RIO *io, int mode, RPrint *print, int fd) { first = false; print->cb_printf ("{\"map\":%i,\"fd\":%d,\"delta\":%"PFMT64u",\"from\":%"PFMT64u ",\"to\":%"PFMT64u",\"perm\":\"%s\",\"name\":\"%s\"}", map->id, map->fd, - map->delta, map->itv.addr, r_itv_end (map->itv), - r_str_rwx_i (map->perm), (map->name ? map->name : "")); + map->delta, map->itv.addr, rz_itv_end (map->itv), + rz_str_rwx_i (map->perm), (map->name ? map->name : "")); break; case 1: case '*': case 'r': { // Need FIFO order here - char *om_cmd = r_str_newf ("om %d 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s%s%s\n", - map->fd, map->itv.addr, map->itv.size, map->delta, r_str_rwx_i(map->perm), + char *om_cmd = rz_str_newf ("om %d 0x%08"PFMT64x" 0x%08"PFMT64x" 0x%08"PFMT64x" %s%s%s\n", + map->fd, map->itv.addr, map->itv.size, map->delta, rz_str_rwx_i(map->perm), map->name ? " " : "", map->name ? map->name : ""); if (om_cmd) { - om_cmds = r_str_prepend (om_cmds, om_cmd); + om_cmds = rz_str_prepend (om_cmds, om_cmd); free (om_cmd); } break; @@ -444,8 +444,8 @@ static void map_list(RIO *io, int mode, RPrint *print, int fd) { default: print->cb_printf ("%2d fd: %i +0x%08"PFMT64x" 0x%08"PFMT64x " - 0x%08"PFMT64x" %s %s\n", map->id, map->fd, - map->delta, map->itv.addr, r_itv_end (map->itv) - 1, - r_str_rwx_i (map->perm), (map->name ? map->name : "")); + map->delta, map->itv.addr, rz_itv_end (map->itv) - 1, + rz_str_rwx_i (map->perm), (map->name ? map->name : "")); break; } } @@ -458,31 +458,31 @@ static void map_list(RIO *io, int mode, RPrint *print, int fd) { } } -static void cmd_omfg(RCore *core, const char *input) { - input = r_str_trim_head_ro (input); +static void cmd_omfg(RzCore *core, const char *input) { + input = rz_str_trim_head_ro (input); if (input) { int perm = *input ? (*input == '+' || *input == '-') - ? r_str_rwx (input + 1) - : r_str_rwx (input) + ? rz_str_rwx (input + 1) + : rz_str_rwx (input) : 7; void **it; switch (*input) { case '+': - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; map->perm |= perm; } break; case '-': - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; map->perm &= ~perm; } break; default: - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; map->perm = perm; } break; @@ -490,8 +490,8 @@ static void cmd_omfg(RCore *core, const char *input) { } } -static void cmd_omf(RCore *core, const char *input) { - char *arg = strdup (r_str_trim_head_ro (input)); +static void cmd_omf(RzCore *core, const char *input) { + char *arg = strdup (rz_str_trim_head_ro (input)); if (!arg) { return; } @@ -499,11 +499,11 @@ static void cmd_omf(RCore *core, const char *input) { if (sp) { // change perms of Nth map *sp++ = 0; - int id = r_num_math (core->num, arg); - int perm = (*sp)? r_str_rwx (sp): R_PERM_RWX; + int id = rz_num_math (core->num, arg); + int perm = (*sp)? rz_str_rwx (sp): R_PERM_RWX; void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; if (map->id == id) { map->perm = perm; break; @@ -511,11 +511,11 @@ static void cmd_omf(RCore *core, const char *input) { } } else { // change perms of current map - int perm = (arg && *arg)? r_str_rwx (arg): R_PERM_RWX; + int perm = (arg && *arg)? rz_str_rwx (arg): R_PERM_RWX; void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; - if (r_itv_contain (map->itv, core->offset)) { + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; + if (rz_itv_contain (map->itv, core->offset)) { map->perm = perm; } } @@ -523,48 +523,48 @@ static void cmd_omf(RCore *core, const char *input) { free (arg); } -static void r_core_cmd_omt(RCore *core, const char *arg) { - RTable *t = r_table_new (); +static void rz_core_cmd_omt(RzCore *core, const char *arg) { + RTable *t = rz_table_new (); - r_table_set_columnsf (t, "nnnnnnnss", "id", "fd", "pa", "pa_end", "size", "va", "va_end", "perm", "name", NULL); + rz_table_set_columnsf (t, "nnnnnnnss", "id", "fd", "pa", "pa_end", "size", "va", "va_end", "perm", "name", NULL); void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *m = *it; - ut64 va = r_itv_begin (m->itv); - ut64 va_end = r_itv_end (m->itv); + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *m = *it; + ut64 va = rz_itv_begin (m->itv); + ut64 va_end = rz_itv_end (m->itv); ut64 pa = m->delta; - ut64 pa_size = r_itv_size (m->itv); + ut64 pa_size = rz_itv_size (m->itv); ut64 pa_end = pa + pa_size; const char *name = m->name? m->name: ""; - r_table_add_rowf (t, "ddxxxxxss", m->id, m->fd, pa, pa_end, pa_size, va, va_end, r_str_rwx_i (m->perm), name); + rz_table_add_rowf (t, "ddxxxxxss", m->id, m->fd, pa, pa_end, pa_size, va, va_end, rz_str_rwx_i (m->perm), name); } - if (r_table_query (t, arg)) { - char *ts = r_table_tofancystring (t); - r_cons_printf ("%s", ts); + if (rz_table_query (t, arg)) { + char *ts = rz_table_tofancystring (t); + rz_cons_printf ("%s", ts); free (ts); } - r_table_free (t); + rz_table_free (t); } -static void cmd_open_map(RCore *core, const char *input) { +static void cmd_open_map(RzCore *core, const char *input) { ut64 fd = 0LL; ut32 id = 0; ut64 addr = 0; char *s = NULL, *p = NULL, *q = NULL; ut64 new; - RIOMap *map = NULL; + RzIOMap *map = NULL; const char *P; switch (input[1]) { case '.': // "om." - map = r_io_map_get (core->io, core->offset); + map = rz_io_map_get (core->io, core->offset); if (map) { core->print->cb_printf ("map: %i fd: %i +0x%"PFMT64x" 0x%"PFMT64x " - 0x%"PFMT64x" ; %s : %s\n", map->id, map->fd, - map->delta, map->itv.addr, r_itv_end (map->itv), - r_str_rwx_i (map->perm), map->name ? map->name : ""); + map->delta, map->itv.addr, rz_itv_end (map->itv), + rz_str_rwx_i (map->perm), map->name ? map->name : ""); } break; case 'r': // "omr" @@ -573,17 +573,17 @@ static void cmd_open_map(RCore *core, const char *input) { } P = strchr (input+3, ' '); if (P) { - id = (ut32)r_num_math (core->num, input+3); //mapid - new = r_num_math (core->num, P+1); - r_io_map_resize (core->io, id, new); + id = (ut32)rz_num_math (core->num, input+3); //mapid + new = rz_num_math (core->num, P+1); + rz_io_map_resize (core->io, id, new); } break; case 'b': // "omb" if (input[2] == '.') { - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { - ut64 dst = r_num_math (core->num, input + 3); - r_io_map_remap (core->io, map->id, dst); + ut64 dst = rz_num_math (core->num, input + 3); + rz_io_map_remap (core->io, map->id, dst); } } else { if (input[2] != ' ') { @@ -591,47 +591,47 @@ static void cmd_open_map(RCore *core, const char *input) { } P = strchr (input + 3, ' '); if (P) { - id = (ut32)r_num_math (core->num, input+3); //mapid - new = r_num_math (core->num, P + 1); - r_io_map_remap (core->io, id, new); + id = (ut32)rz_num_math (core->num, input+3); //mapid + new = rz_num_math (core->num, P + 1); + rz_io_map_remap (core->io, id, new); } } break; case 'o': // "omo" if (input[2] == ' ') { - r_core_cmdf (core, "om %s 0x%08" PFMT64x " $s r omo", input + 2, core->offset); + rz_core_cmdf (core, "om %s 0x%08" PFMT64x " $s r omo", input + 2, core->offset); } else { - r_core_cmd0 (core, "om `oq.` $B $s r"); + rz_core_cmd0 (core, "om `oq.` $B $s r"); } - r_core_cmd0 (core, "ompd `omq.`"); + rz_core_cmd0 (core, "ompd `omq.`"); break; case 'p': switch (input[2]) { case 'd': // "ompf" - id = r_num_math (core->num, input + 3); //mapid - if (r_io_map_exists_for_id (core->io, id)) { - r_io_map_depriorize (core->io, id); + id = rz_num_math (core->num, input + 3); //mapid + if (rz_io_map_exists_for_id (core->io, id)) { + rz_io_map_depriorize (core->io, id); } else { eprintf ("Cannot find any map with mapid %d\n", id); } break; case 'f': // "ompf" - fd = r_num_math (core->num, input + 3); - if (!r_io_map_priorize_for_fd (core->io, (int)fd)) { + fd = rz_num_math (core->num, input + 3); + if (!rz_io_map_priorize_for_fd (core->io, (int)fd)) { eprintf ("Cannot prioritize any map for fd %d\n", (int)fd); } break; case 'b': // "ompb" - id = (ut32)r_num_math (core->num, input + 4); - if (!r_bin_file_set_cur_by_id (core->bin, id)) { + id = (ut32)rz_num_math (core->num, input + 4); + if (!rz_bin_file_set_cur_by_id (core->bin, id)) { eprintf ("Cannot prioritize bin with fd %d\n", id); } break; case ' ': // "omp" - id = r_num_math (core->num, input + 3); //mapid - if (r_io_map_exists_for_id (core->io, id)) { - r_io_map_priorize (core->io, id); - r_core_block_read (core); + id = rz_num_math (core->num, input + 3); //mapid + if (rz_io_map_exists_for_id (core->io, id)) { + rz_io_map_priorize (core->io, id); + rz_core_block_read (core); } else { eprintf ("Cannot find any map with mapid %d\n", id); } @@ -639,7 +639,7 @@ static void cmd_open_map(RCore *core, const char *input) { } break; case 't': // "omt" - r_core_cmd_omt (core, input + 2); + rz_core_cmd_omt (core, input + 2); break; case ' ': // "om" s = strdup (input + 2); @@ -651,38 +651,38 @@ static void cmd_open_map(RCore *core, const char *input) { ut64 size = 0, vaddr = 0, paddr = 0; const char *name = NULL; bool rwx_arg = false; - RIODesc *desc = NULL; - int words = r_str_word_set0 (s); + RzIODesc *desc = NULL; + int words = rz_str_word_set0 (s); switch (words) { case 6: - name = r_str_word_get0 (s, 5); + name = rz_str_word_get0 (s, 5); case 5: //this sucks - rwx = r_str_rwx (r_str_word_get0 (s, 4)); + rwx = rz_str_rwx (rz_str_word_get0 (s, 4)); rwx_arg = true; case 4: - paddr = r_num_math (core->num, r_str_word_get0 (s, 3)); + paddr = rz_num_math (core->num, rz_str_word_get0 (s, 3)); case 3: - size = r_num_math (core->num, r_str_word_get0 (s, 2)); + size = rz_num_math (core->num, rz_str_word_get0 (s, 2)); case 2: - vaddr = r_num_math (core->num, r_str_word_get0 (s, 1)); + vaddr = rz_num_math (core->num, rz_str_word_get0 (s, 1)); case 1: - fd = r_num_math (core->num, r_str_word_get0 (s, 0)); + fd = rz_num_math (core->num, rz_str_word_get0 (s, 0)); } if (fd < 3) { eprintf ("wrong fd, it must be greater than 3\n"); break; } - desc = r_io_desc_get (core->io, fd); + desc = rz_io_desc_get (core->io, fd); if (desc) { if (!size) { - size = r_io_fd_size (core->io, fd); + size = rz_io_fd_size (core->io, fd); } - map = r_io_map_add (core->io, fd, rwx_arg ? rwx : desc->perm, paddr, vaddr, size); - r_io_map_set_name (map, name); + map = rz_io_map_add (core->io, fd, rwx_arg ? rwx : desc->perm, paddr, vaddr, size); + rz_io_map_set_name (map, name); } } else { - int fd = r_io_fd_get_current (core->io); - if (r_io_desc_get (core->io, fd)) { + int fd = rz_io_fd_get_current (core->io); + if (rz_io_desc_get (core->io, fd)) { map_list (core->io, 0, core->print, fd); } else { eprintf ("Invalid fd %d\n", (int)fd); @@ -692,17 +692,17 @@ static void cmd_open_map(RCore *core, const char *input) { break; case 'n': // "omn" if (input[2] == '.') { // "omn." - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { switch (input[3]) { case '-': - r_io_map_del_name (map); + rz_io_map_del_name (map); break; case 0: - r_cons_printf ("%s\n", map->name); + rz_cons_printf ("%s\n", map->name); break; default: - r_io_map_set_name (map, r_str_trim_head_ro (input + 3)); + rz_io_map_set_name (map, rz_str_trim_head_ro (input + 3)); break; } } @@ -723,40 +723,40 @@ static void cmd_open_map(RCore *core, const char *input) { } if (!(q = strchr (s, ' '))) { if (use_id) { - id = (ut32)r_num_math (core->num, s); - map = r_io_map_resolve (core->io, id); + id = (ut32)rz_num_math (core->num, s); + map = rz_io_map_resolve (core->io, id); } else { - addr = r_num_math (core->num, s); - map = r_io_map_get (core->io, addr); + addr = rz_num_math (core->num, s); + map = rz_io_map_get (core->io, addr); } - r_io_map_del_name (map); + rz_io_map_del_name (map); s = p; break; } *q = '\0'; q++; if (use_id) { - id = (ut32)r_num_math (core->num, s); - map = r_io_map_resolve (core->io, id); + id = (ut32)rz_num_math (core->num, s); + map = rz_io_map_resolve (core->io, id); } else { - addr = r_num_math (core->num, s); - map = r_io_map_get (core->io, addr); + addr = rz_num_math (core->num, s); + map = rz_io_map_get (core->io, addr); } if (*q) { - r_io_map_set_name (map, q); + rz_io_map_set_name (map, q); } else { - r_io_map_del_name (map); + rz_io_map_del_name (map); } s = p; } break; case 'a': // "oma" { - ut32 fd = input[2]? r_num_math (core->num, input + 2): r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + ut32 fd = input[2]? rz_num_math (core->num, input + 2): rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { - map = r_io_map_add (core->io, fd, desc->perm, 0, 0, UT64_MAX); - r_io_map_set_name (map, desc->name); + map = rz_io_map_add (core->io, fd, desc->perm, 0, 0, UT64_MAX); + rz_io_map_set_name (map, desc->name); } else { eprintf ("Usage: omm [fd]\n"); } @@ -764,12 +764,12 @@ static void cmd_open_map(RCore *core, const char *input) { break; case 'm': // "omm" { - ut32 fd = input[2]? r_num_math (core->num, input + 2): r_io_fd_get_current (core->io); - RIODesc *desc = r_io_desc_get (core->io, fd); + ut32 fd = input[2]? rz_num_math (core->num, input + 2): rz_io_fd_get_current (core->io); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { - ut64 size = r_io_desc_size (desc); - map = r_io_map_add (core->io, fd, desc->perm, 0, 0, size); - r_io_map_set_name (map, desc->name); + ut64 size = rz_io_desc_size (desc); + map = rz_io_map_add (core->io, fd, desc->perm, 0, 0, size); + rz_io_map_set_name (map, desc->name); } else { eprintf ("Usage: omm [fd]\n"); } @@ -777,11 +777,11 @@ static void cmd_open_map(RCore *core, const char *input) { break; case '-': // "om-" if (!strcmp (input + 2, "..")) { - r_core_cmd0 (core, "om-`om~...`~[0]"); + rz_core_cmd0 (core, "om-`om~...`~[0]"); } else if (input[2] == '*') { - r_io_map_reset (core->io); + rz_io_map_reset (core->io); } else { - r_io_map_del (core->io, r_num_math (core->num, input + 2)); + rz_io_map_del (core->io, rz_num_math (core->num, input + 2)); } break; case 'f': // "omf" @@ -793,7 +793,7 @@ static void cmd_open_map(RCore *core, const char *input) { cmd_omf (core, input + 3); break; default: - r_core_cmd_help (core, help_msg_om); + rz_core_cmd_help (core, help_msg_om); break; } break; @@ -802,7 +802,7 @@ static void cmd_open_map(RCore *core, const char *input) { case '*': // "om*" case 'q': // "omq" if (input[1] && input[2] == '.') { - map = r_io_map_get (core->io, core->offset); + map = rz_io_map_get (core->io, core->offset); if (map) { core->print->cb_printf ("%i\n", map->id); } @@ -816,44 +816,44 @@ static void cmd_open_map(RCore *core, const char *input) { break; case '=': // "om=" { - RList *list = r_list_newf ((RListFree) r_listinfo_free); + RzList *list = rz_list_newf ((RzListFree) rz_listinfo_free); if (!list) { return; } void **it; - r_pvector_foreach_prev (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach_prev (&core->io->maps, it) { + RzIOMap *map = *it; char temp[32]; snprintf (temp, sizeof (temp), "%d", map->fd); - RListInfo *info = r_listinfo_new (map->name, map->itv, map->itv, map->perm, temp); + RzListInfo *info = rz_listinfo_new (map->name, map->itv, map->itv, map->perm, temp); if (!info) { break; } - r_list_append (list, info); + rz_list_append (list, info); } - RTable *table = r_core_table (core); - r_table_visual_list (table, list, core->offset, core->blocksize, - r_cons_get_size (NULL), r_config_get_i (core->config, "scr.color")); - char *tablestr = r_table_tostring (table); - r_cons_printf ("\n%s\n", tablestr); - r_table_free (table); - r_list_free (list); + RTable *table = rz_core_table (core); + rz_table_visual_list (table, list, core->offset, core->blocksize, + rz_cons_get_size (NULL), rz_config_get_i (core->config, "scr.color")); + char *tablestr = rz_table_tostring (table); + rz_cons_printf ("\n%s\n", tablestr); + rz_table_free (table); + rz_list_free (list); free (tablestr); } break; default: case '?': - r_core_cmd_help (core, help_msg_om); + rz_core_cmd_help (core, help_msg_om); break; } R_FREE (s); - r_core_block_read (core); + rz_core_block_read (core); } static bool reopen_in_malloc_cb(void *user, void *data, ut32 id) { - RIO *io = (RIO *)user; - RIODesc *desc = (RIODesc *)data; + RzIO *io = (RzIO *)user; + RzIODesc *desc = (RzIODesc *)data; - if (r_io_desc_is_blockdevice (desc) || r_io_desc_is_dbg (desc)) { + if (rz_io_desc_is_blockdevice (desc) || rz_io_desc_is_dbg (desc)) { return true; } @@ -861,9 +861,9 @@ static bool reopen_in_malloc_cb(void *user, void *data, ut32 id) { return true; } - ut64 size = r_io_desc_size (desc); + ut64 size = rz_io_desc_size (desc); - char *uri = r_str_newf ("malloc://%"PFMT64u, size); + char *uri = rz_str_newf ("malloc://%"PFMT64u, size); if (!uri) { return false; } @@ -875,33 +875,33 @@ static bool reopen_in_malloc_cb(void *user, void *data, ut32 id) { return false; } - RIODesc *ndesc = r_io_open_nomap (io, uri, R_PERM_RW, 0); + RzIODesc *ndesc = rz_io_open_nomap (io, uri, R_PERM_RW, 0); free (uri); if (!ndesc) { free (buf); return false; } - r_io_desc_read_at (desc, 0LL, buf, (int)size); //that cast o_O - r_io_desc_write_at (ndesc, 0LL, buf, (int)size); + rz_io_desc_read_at (desc, 0LL, buf, (int)size); //that cast o_O + rz_io_desc_write_at (ndesc, 0LL, buf, (int)size); free (buf); - r_io_desc_exchange (io, desc->fd, ndesc->fd); + rz_io_desc_exchange (io, desc->fd, ndesc->fd); - r_io_desc_close (desc); + rz_io_desc_close (desc); return true; } -R_API void r_core_file_reopen_in_malloc(RCore *core) { +RZ_API void rz_core_file_reopen_in_malloc(RzCore *core) { if (core && core->io && core->io->files) { - r_id_storage_foreach (core->io->files, reopen_in_malloc_cb, core->io); + rz_id_storage_foreach (core->io->files, reopen_in_malloc_cb, core->io); } } -static RList *__save_old_sections(RCore *core) { - RList *sections = r_bin_get_sections (core->bin); - RListIter *it; +static RzList *__save_old_sections(RzCore *core) { + RzList *sections = rz_bin_get_sections (core->bin); + RzListIter *it; RBinSection *sec; - RList *old_sections = r_list_new (); + RzList *old_sections = rz_list_new (); // Return an empty list if (!sections) { @@ -910,7 +910,7 @@ static RList *__save_old_sections(RCore *core) { } old_sections->free = sections->free; - r_list_foreach (sections, it, sec) { + rz_list_foreach (sections, it, sec) { RBinSection *old_sec = R_NEW0 (RBinSection); if (!old_sec) { break; @@ -918,14 +918,14 @@ static RList *__save_old_sections(RCore *core) { *old_sec = *sec; old_sec->name = strdup (sec->name); old_sec->format = NULL; - r_list_append (old_sections, old_sec); + rz_list_append (old_sections, old_sec); } return old_sections; } struct __rebase_struct { - RCore *core; - RList *old_sections; + RzCore *core; + RzList *old_sections; ut64 old_base; ut64 diff; int type; @@ -934,15 +934,15 @@ struct __rebase_struct { #define __is_inside_section(item_addr, section)\ (item_addr >= old_base + section->vaddr && item_addr <= old_base + section->vaddr + section->vsize) -static bool __rebase_flags(RFlagItem *flag, void *user) { +static bool __rebase_flags(RzFlagItem *flag, void *user) { struct __rebase_struct *reb = user; ut64 old_base = reb->old_base; - RListIter *it; + RzListIter *it; RBinSection *sec; // Only rebase flags that were in the rebased sections, otherwise it will take too long - r_list_foreach (reb->old_sections, it, sec) { + rz_list_foreach (reb->old_sections, it, sec) { if (__is_inside_section (flag->offset, sec)) { - r_flag_set (reb->core->flags, flag->name, flag->offset + reb->diff, flag->size); + rz_flag_set (reb->core->flags, flag->name, flag->offset + reb->diff, flag->size); break; } } @@ -951,13 +951,13 @@ static bool __rebase_flags(RFlagItem *flag, void *user) { static bool __rebase_refs_i(void *user, const ut64 k, const void *v) { struct __rebase_struct *reb = (void *)user; - RAnalRef *ref = (RAnalRef *)v; + RzAnalRef *ref = (RzAnalRef *)v; ref->addr += reb->diff; ref->at += reb->diff; if (reb->type) { - r_anal_xrefs_set (reb->core->anal, ref->addr, ref->at, ref->type); + rz_anal_xrefs_set (reb->core->anal, ref->addr, ref->at, ref->type); } else { - r_anal_xrefs_set (reb->core->anal, ref->at, ref->addr, ref->type); + rz_anal_xrefs_set (reb->core->anal, ref->at, ref->addr, ref->type); } return true; } @@ -968,9 +968,9 @@ static bool __rebase_refs(void *user, const ut64 k, const void *v) { return true; } -static void __rebase_everything(RCore *core, RList *old_sections, ut64 old_base) { - RListIter *it, *itit, *ititit; - RAnalFunction *fcn; +static void __rebase_everything(RzCore *core, RzList *old_sections, ut64 old_base) { + RzListIter *it, *itit, *ititit; + RzAnalFunction *fcn; ut64 new_base = core->bin->cur->o->baddr_shift; RBinSection *old_section; ut64 diff = new_base - old_base; @@ -978,21 +978,21 @@ static void __rebase_everything(RCore *core, RList *old_sections, ut64 old_base) return; } // FUNCTIONS - r_list_foreach (core->anal->fcns, it, fcn) { - r_list_foreach (old_sections, itit, old_section) { + rz_list_foreach (core->anal->fcns, it, fcn) { + rz_list_foreach (old_sections, itit, old_section) { if (!__is_inside_section (fcn->addr, old_section)) { continue; } - r_anal_function_rebase_vars (core->anal, fcn); - r_anal_function_relocate (fcn, fcn->addr + diff); - RAnalBlock *bb; + rz_anal_function_rebase_vars (core->anal, fcn); + rz_anal_function_relocate (fcn, fcn->addr + diff); + RzAnalBlock *bb; ut64 new_sec_addr = new_base + old_section->vaddr; - r_list_foreach (fcn->bbs, ititit, bb) { + rz_list_foreach (fcn->bbs, ititit, bb) { if (bb->addr >= new_sec_addr && bb->addr <= new_sec_addr + old_section->vsize) { // Todo: Find better way to check if bb was already rebased continue; } - r_anal_block_relocate (bb, bb->addr + diff, bb->size); + rz_anal_block_relocate (bb, bb->addr + diff, bb->size); if (bb->jump != UT64_MAX) { bb->jump += diff; } @@ -1011,17 +1011,17 @@ static void __rebase_everything(RCore *core, RList *old_sections, ut64 old_base) old_base, diff }; - r_flag_foreach (core->flags, __rebase_flags, &reb); + rz_flag_foreach (core->flags, __rebase_flags, &reb); // META - r_meta_rebase (core->anal, diff); + rz_meta_rebase (core->anal, diff); // REFS HtUP *old_refs = core->anal->dict_refs; HtUP *old_xrefs = core->anal->dict_xrefs; core->anal->dict_refs = NULL; core->anal->dict_xrefs = NULL; - r_anal_xrefs_init (core->anal); + rz_anal_xrefs_init (core->anal); reb.type = 0; ht_up_foreach (old_refs, __rebase_refs, &reb); reb.type = 1; @@ -1030,60 +1030,60 @@ static void __rebase_everything(RCore *core, RList *old_sections, ut64 old_base) ht_up_free (old_xrefs); // BREAKPOINTS - r_debug_bp_rebase (core->dbg, old_base, new_base); + rz_debug_bp_rebase (core->dbg, old_base, new_base); } -R_API void r_core_file_reopen_remote_debug(RCore *core, char *uri, ut64 addr) { - RCoreFile *ofile = core->file; - RIODesc *desc; - RCoreFile *file; +RZ_API void rz_core_file_reopen_remote_debug(RzCore *core, char *uri, ut64 addr) { + RzCoreFile *ofile = core->file; + RzIODesc *desc; + RzCoreFile *file; int fd; - if (!ofile || !(desc = r_io_desc_get (core->io, ofile->fd)) || !desc->uri) { + if (!ofile || !(desc = rz_io_desc_get (core->io, ofile->fd)) || !desc->uri) { eprintf ("No file open?\n"); return; } - RList *old_sections = __save_old_sections (core); + RzList *old_sections = __save_old_sections (core); ut64 old_base = core->bin->cur->o->baddr_shift; int bits = core->rasm->bits; - r_config_set_i (core->config, "asm.bits", bits); - r_config_set_i (core->config, "cfg.debug", true); + rz_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "cfg.debug", true); // Set referer as the original uri so we could return to it with `oo` desc->referer = desc->uri; desc->uri = strdup (uri); - if ((file = r_core_file_open (core, uri, R_PERM_R | R_PERM_W, addr))) { + if ((file = rz_core_file_open (core, uri, R_PERM_R | R_PERM_W, addr))) { fd = file->fd; core->num->value = fd; // if no baddr is defined, use the one provided by the file if (addr == 0) { - desc = r_io_desc_get (core->io, file->fd); + desc = rz_io_desc_get (core->io, file->fd); if (desc->plugin->isdbg) { - addr = r_debug_get_baddr(core->dbg, desc->name); + addr = rz_debug_get_baddr(core->dbg, desc->name); } else { - addr = r_bin_get_baddr (file->binb.bin); + addr = rz_bin_get_baddr (file->binb.bin); } } - r_core_bin_load (core, uri, addr); + rz_core_bin_load (core, uri, addr); } else { eprintf ("cannot open file %s\n", uri); - r_list_free (old_sections); + rz_list_free (old_sections); return; } - r_core_block_read (core); - if (r_config_get_i (core->config, "dbg.rebase")) { + rz_core_block_read (core); + if (rz_config_get_i (core->config, "dbg.rebase")) { __rebase_everything (core, old_sections, old_base); } - r_list_free (old_sections); - r_core_cmd0 (core, "sr PC"); + rz_list_free (old_sections); + rz_core_cmd0 (core, "sr PC"); } -R_API void r_core_file_reopen_debug(RCore *core, const char *args) { - RCoreFile *ofile = core->file; - RIODesc *desc; +RZ_API void rz_core_file_reopen_debug(RzCore *core, const char *args) { + RzCoreFile *ofile = core->file; + RzIODesc *desc; - if (!ofile || !(desc = r_io_desc_get (core->io, ofile->fd)) || !desc->uri) { + if (!ofile || !(desc = rz_io_desc_get (core->io, ofile->fd)) || !desc->uri) { eprintf ("No file open?\n"); return; } @@ -1093,39 +1093,39 @@ R_API void r_core_file_reopen_debug(RCore *core, const char *args) { if (!(desc->plugin && desc->plugin->isdbg) && (desc->perm & R_PERM_W)) { eprintf ("Cannot debug file (%s) with permissions set to 0x%x.\n" "Reopening the original file in read-only mode.\n", desc->name, desc->perm); - r_io_reopen (core->io, ofile->fd, R_PERM_R, 644); - desc = r_io_desc_get (core->io, ofile->fd); + rz_io_reopen (core->io, ofile->fd, R_PERM_R, 644); + desc = rz_io_desc_get (core->io, ofile->fd); } - RBinFile *bf = r_bin_file_find_by_fd (core->bin, ofile->fd); + RBinFile *bf = rz_bin_file_find_by_fd (core->bin, ofile->fd); char *binpath = (bf && bf->file) ? strdup (bf->file) : NULL; if (!binpath) { - if (r_file_exists (desc->name)) { + if (rz_file_exists (desc->name)) { binpath = strdup (desc->name); } } if (!binpath) { /* fallback to oo */ - (void)r_core_cmd0 (core, "oo"); + (void)rz_core_cmd0 (core, "oo"); return; } - RList *old_sections = __save_old_sections (core); + RzList *old_sections = __save_old_sections (core); ut64 old_base = core->bin->cur->o->baddr_shift; int bits = core->rasm->bits; - char *bin_abspath = r_file_abspath (binpath); - char *escaped_path = r_str_arg_escape (bin_abspath); - char *newfile = r_str_newf ("dbg://%s %s", escaped_path, args); + char *bin_abspath = rz_file_abspath (binpath); + char *escaped_path = rz_str_arg_escape (bin_abspath); + char *newfile = rz_str_newf ("dbg://%s %s", escaped_path, args); desc->uri = newfile; desc->referer = NULL; - r_config_set_i (core->config, "asm.bits", bits); - r_config_set_i (core->config, "cfg.debug", true); - r_core_file_reopen (core, newfile, 0, 2); - if (r_config_get_i (core->config, "dbg.rebase")) { + rz_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "cfg.debug", true); + rz_core_file_reopen (core, newfile, 0, 2); + if (rz_config_get_i (core->config, "dbg.rebase")) { __rebase_everything (core, old_sections, old_base); } - r_list_free (old_sections); - r_core_cmd0 (core, "sr PC"); + rz_list_free (old_sections); + rz_core_cmd0 (core, "sr PC"); free (bin_abspath); free (escaped_path); free (binpath); @@ -1134,8 +1134,8 @@ R_API void r_core_file_reopen_debug(RCore *core, const char *args) { static int fdsz = 0; static bool init_desc_list_visual_cb(void *user, void *data, ut32 id) { - RIODesc *desc = (RIODesc *)data; - ut64 sz = r_io_desc_size (desc); + RzIODesc *desc = (RzIODesc *)data; + ut64 sz = rz_io_desc_size (desc); if (sz > fdsz) { fdsz = sz; } @@ -1144,24 +1144,24 @@ static bool init_desc_list_visual_cb(void *user, void *data, ut32 id) { static bool desc_list_visual_cb(void *user, void *data, ut32 id) { RPrint *p = (RPrint *)user; - RIODesc *desc = (RIODesc *)data; - ut64 sz = r_io_desc_size (desc); - r_cons_printf ("%2d %c %s 0x%08"PFMT64x" ", desc->fd, - (desc->io && (desc->io->desc == desc)) ? '*' : '-', r_str_rwx_i (desc->perm), sz); + RzIODesc *desc = (RzIODesc *)data; + ut64 sz = rz_io_desc_size (desc); + rz_cons_printf ("%2d %c %s 0x%08"PFMT64x" ", desc->fd, + (desc->io && (desc->io->desc == desc)) ? '*' : '-', rz_str_rwx_i (desc->perm), sz); int flags = p->flags; p->flags &= ~R_PRINT_FLAGS_HEADER; - r_print_progressbar (p, sz * 100 / fdsz, r_cons_get_size (NULL) - 40); + rz_print_progressbar (p, sz * 100 / fdsz, rz_cons_get_size (NULL) - 40); p->flags = flags; - r_cons_printf (" %s\n", desc->uri); + rz_cons_printf (" %s\n", desc->uri); #if 0 - RIOMap *map; + RzIOMap *map; SdbListIter *iter; if (desc->io && desc->io->va && desc->io->maps) { ls_foreach_prev (desc->io->maps, iter, map) { if (map->fd == desc->fd) { p->cb_printf (" +0x%"PFMT64x" 0x%"PFMT64x " - 0x%"PFMT64x" : %s : %s : %s\n", map->delta, - map->from, map->to, r_str_rwx_i (map->flags), "", + map->from, map->to, rz_str_rwx_i (map->flags), "", map->name ? map->name : ""); } } @@ -1172,31 +1172,31 @@ static bool desc_list_visual_cb(void *user, void *data, ut32 id) { static bool desc_list_quiet2_cb(void *user, void *data, ut32 id) { RPrint *p = (RPrint *)user; - RIODesc *desc = (RIODesc *)data; + RzIODesc *desc = (RzIODesc *)data; p->cb_printf ("%d\n", desc->fd); return false; } static bool desc_list_quiet_cb(void *user, void *data, ut32 id) { RPrint *p = (RPrint *)user; - RIODesc *desc = (RIODesc *)data; + RzIODesc *desc = (RzIODesc *)data; p->cb_printf ("%d\n", desc->fd); return true; } static bool desc_list_cb(void *user, void *data, ut32 id) { RPrint *p = (RPrint *)user; - RIODesc *desc = (RIODesc *)data; + RzIODesc *desc = (RzIODesc *)data; p->cb_printf ("%2d %c %s 0x%08"PFMT64x" %s\n", desc->fd, (desc->io && (desc->io->desc == desc)) ? '*' : '-', - r_str_rwx_i (desc->perm), r_io_desc_size (desc), desc->uri); + rz_str_rwx_i (desc->perm), rz_io_desc_size (desc), desc->uri); return true; } static bool desc_list_json_cb(void *user, void *data, ut32 id) { PJ *pj = (PJ *)user; - RIODesc *desc = (RIODesc *)data; - // TODO: from is always 0? See libr/core/file.c:945 + RzIODesc *desc = (RzIODesc *)data; + // TODO: from is always 0? See librz/core/file.c:945 ut64 from = 0LL; pj_o (pj); pj_kb (pj, "raised", desc->io && (desc->io->desc == desc)); @@ -1204,19 +1204,19 @@ static bool desc_list_json_cb(void *user, void *data, ut32 id) { pj_ks (pj, "uri", desc->uri); pj_kn (pj, "from", from); pj_kb (pj, "writable", desc->perm & R_PERM_W); - pj_kN (pj, "size", r_io_desc_size (desc)); + pj_kN (pj, "size", rz_io_desc_size (desc)); pj_end (pj); return true; } static int cmd_open(void *data, const char *input) { - RCore *core = (RCore*)data; + RzCore *core = (RzCore*)data; int perms = R_PERM_R; - ut64 baddr = r_config_get_i (core->config, "bin.baddr"); + ut64 baddr = rz_config_get_i (core->config, "bin.baddr"); ut64 addr = 0LL; int argc, fd = -1; - RCoreFile *file; - RIODesc *desc; + RzCoreFile *file; + RzIODesc *desc; bool write = false; const char *ptr = NULL; char **argv = NULL; @@ -1226,9 +1226,9 @@ static int cmd_open(void *data, const char *input) { switch (input[1]) { case '*': // "oa*" { - RListIter *iter; + RzListIter *iter; RBinFile *bf = NULL; - r_list_foreach (core->bin->binfiles, iter, bf) { + rz_list_foreach (core->bin->binfiles, iter, bf) { if (bf && bf->o && bf->o->info) { eprintf ("oa %s %d %s\n", bf->o->info->arch, bf->o->info->bits, bf->file); } @@ -1243,19 +1243,19 @@ static int cmd_open(void *data, const char *input) { const char *arch = NULL; ut16 bits = 0; const char *filename = NULL; - i = r_str_word_set0 (ptr); + i = rz_str_word_set0 (ptr); if (i < 2) { eprintf ("Missing argument\n"); free (ptr); return 0; } if (i == 3) { - filename = r_str_word_get0 (ptr, 2); + filename = rz_str_word_get0 (ptr, 2); } - bits = r_num_math (core->num, r_str_word_get0 (ptr, 1)); - arch = r_str_word_get0 (ptr, 0); - r_core_bin_set_arch_bits (core, filename, arch, bits); - RBinFile *file = r_bin_file_find_by_name (core->bin, filename); + bits = rz_num_math (core->num, rz_str_word_get0 (ptr, 1)); + arch = rz_str_word_get0 (ptr, 0); + rz_core_bin_set_arch_bits (core, filename, arch, bits); + RBinFile *file = rz_bin_file_find_by_name (core->bin, filename); if (!file) { eprintf ("Cannot find file %s\n", filename); free (ptr); @@ -1264,7 +1264,7 @@ static int cmd_open(void *data, const char *input) { if (file->o && file->o->info) { file->o->info->arch = strdup(arch); file->o->info->bits = bits; - r_core_bin_set_env (core, file); + rz_core_bin_set_env (core, file); } free (ptr); return 1; @@ -1276,7 +1276,7 @@ static int cmd_open(void *data, const char *input) { } case 'n': // "on" if (input[1] == '*') { - r_core_file_list (core, 'n'); + rz_core_file_list (core, 'n'); return 0; } if (input[1] == '+') { // "on+" @@ -1293,52 +1293,52 @@ static int cmd_open(void *data, const char *input) { eprintf ("Usage: on file [addr] [rwx]\n"); return 0; } - argv = r_str_argv (ptr, &argc); + argv = rz_str_argv (ptr, &argc); if (!argc) { eprintf ("Usage: on%s file [addr] [rwx]\n", write?"+":""); - r_str_argv_free (argv); + rz_str_argv_free (argv); return 0; } ptr = argv[0]; if (argc == 2) { - if (r_num_is_valid_input (core->num, argv[1])) { - addr = r_num_math (core->num, argv[1]); + if (rz_num_is_valid_input (core->num, argv[1])) { + addr = rz_num_math (core->num, argv[1]); } else { - perms = r_str_rwx (argv[1]); + perms = rz_str_rwx (argv[1]); } } if (argc == 3) { - addr = r_num_math (core->num, argv[1]); - perms = r_str_rwx (argv[2]); + addr = rz_num_math (core->num, argv[1]); + perms = rz_str_rwx (argv[2]); } if (!strcmp (ptr, "-")) { ptr = "malloc://512"; } - if ((desc = r_io_open_at (core->io, ptr, perms, 0644, addr))) { + if ((desc = rz_io_open_at (core->io, ptr, perms, 0644, addr))) { fd = desc->fd; } if (fd == -1) { eprintf ("Cannot open file '%s'\n", ptr); } - r_str_argv_free (argv); + rz_str_argv_free (argv); core->num->value = fd; - r_core_block_read (core); + rz_core_block_read (core); return 0; #if 1 // XXX projects use the of command, but i think we should deprecate it... keeping it for now case 'f': // "of" - ptr = r_str_trim_head_ro (input + 2); - argv = r_str_argv (ptr, &argc); + ptr = rz_str_trim_head_ro (input + 2); + argv = rz_str_argv (ptr, &argc); if (argc == 0) { eprintf ("Usage: of [filename] (rwx)\n"); - r_str_argv_free (argv); + rz_str_argv_free (argv); return 0; } else if (argc == 2) { - perms = r_str_rwx (argv[1]); + perms = rz_str_rwx (argv[1]); } - fd = r_io_fd_open (core->io, argv[0], perms, 0); + fd = rz_io_fd_open (core->io, argv[0], perms, 0); core->num->value = fd; - r_str_argv_free (argv); + rz_str_argv_free (argv); return 0; #else { @@ -1347,34 +1347,34 @@ static int cmd_open(void *data, const char *input) { input++; } addr = 0; // honor bin.baddr ? - const char *argv0 = r_str_trim_head_ro (input + 2); - if ((file = r_core_file_open (core, argv0, perms, addr))) { + const char *argv0 = rz_str_trim_head_ro (input + 2); + if ((file = rz_core_file_open (core, argv0, perms, addr))) { fd = file->fd; if (!silence) { eprintf ("%d\n", fd); } - r_core_bin_load (core, argv0, baddr); + rz_core_bin_load (core, argv0, baddr); } else { eprintf ("cannot open file %s\n", argv0); } - r_str_argv_free (argv); + rz_str_argv_free (argv); } - r_core_block_read (core); + rz_core_block_read (core); return 0; break; #endif case 'p': // "op" /* handle prioritize */ if (input[1]) { - int fd = r_num_math (core->num, input + 1); + int fd = rz_num_math (core->num, input + 1); if (fd >= 0 || input[1] == '0') { - RIODesc *desc = r_io_desc_get (core->io, fd); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { // only useful for io.va=0 // load bininfo for given fd - r_core_cmdf (core, "obo %d", fd); + rz_core_cmdf (core, "obo %d", fd); core->io->desc = desc; // XXX we should use fd here, not *pointer - r_core_block_read (core); + rz_core_block_read (core); } else { eprintf ("Cannot find RBinFile associated with fd %d\n", fd); } @@ -1383,7 +1383,7 @@ static int cmd_open(void *data, const char *input) { } } else { if (core->io && core->io->desc) { - r_cons_printf ("%d\n", core->io->desc->fd); + rz_cons_printf ("%d\n", core->io->desc->fd); } } return 0; @@ -1393,42 +1393,42 @@ static int cmd_open(void *data, const char *input) { /* fallthrough */ case ' ': // "o" "o " ptr = input + 1; - argv = r_str_argv (ptr, &argc); + argv = rz_str_argv (ptr, &argc); if (argc == 0) { eprintf ("Usage: o (uri://)[/path/to/file] (addr)\n"); - r_str_argv_free (argv); + rz_str_argv_free (argv); return 0; } if (argv) { // Unescape spaces from the path - r_str_path_unescape (argv[0]); + rz_str_path_unescape (argv[0]); if (argc == 2) { - if (r_num_is_valid_input (core->num, argv[1])) { - addr = r_num_math (core->num, argv[1]); + if (rz_num_is_valid_input (core->num, argv[1])) { + addr = rz_num_math (core->num, argv[1]); } else { - perms = r_str_rwx (argv[1]); + perms = rz_str_rwx (argv[1]); } } if (argc == 3) { - addr = r_num_math (core->num, argv[1]); - perms = r_str_rwx (argv[2]); + addr = rz_num_math (core->num, argv[1]); + perms = rz_str_rwx (argv[2]); } } { const char *argv0 = argv ? argv[0] : ptr; - if ((file = r_core_file_open (core, argv0, perms, addr))) { + if ((file = rz_core_file_open (core, argv0, perms, addr))) { fd = file->fd; core->num->value = fd; if (addr == 0) { // if no baddr defined, use the one provided by the file addr = UT64_MAX; } - r_core_bin_load (core, argv0, addr); + rz_core_bin_load (core, argv0, addr); if (*input == '+') { // "o+" - RIODesc *desc = r_io_desc_get (core->io, fd); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc && (desc->perm & R_PERM_W)) { void **it; - r_pvector_foreach_prev (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach_prev (&core->io->maps, it) { + RzIOMap *map = *it; if (map->fd == fd) { map->perm |= R_PERM_WX; } @@ -1440,61 +1440,61 @@ static int cmd_open(void *data, const char *input) { } else { eprintf ("cannot open file %s\n", argv0); } - r_str_argv_free (argv); + rz_str_argv_free (argv); } - r_core_block_read (core); + rz_core_block_read (core); return 0; } switch (*input) { case '=': // "o=" fdsz = 0; - r_id_storage_foreach (core->io->files, init_desc_list_visual_cb, core->print); - r_id_storage_foreach (core->io->files, desc_list_visual_cb, core->print); + rz_id_storage_foreach (core->io->files, init_desc_list_visual_cb, core->print); + rz_id_storage_foreach (core->io->files, desc_list_visual_cb, core->print); break; case 'q': // "oq" if (input[1] == '.') { - r_id_storage_foreach (core->io->files, desc_list_quiet2_cb, core->print); + rz_id_storage_foreach (core->io->files, desc_list_quiet2_cb, core->print); } else { - r_id_storage_foreach (core->io->files, desc_list_quiet_cb, core->print); + rz_id_storage_foreach (core->io->files, desc_list_quiet_cb, core->print); } break; case '\0': // "o" - r_id_storage_foreach (core->io->files, desc_list_cb, core->print); + rz_id_storage_foreach (core->io->files, desc_list_cb, core->print); break; case '*': // "o*" if ('?' == input[1]) { - r_core_cmd_help (core, help_msg_o_star); + rz_core_cmd_help (core, help_msg_o_star); break; } - r_core_file_list (core, (int)(*input)); + rz_core_file_list (core, (int)(*input)); break; case 'j': // "oj" if ('?' == input[1]) { - r_core_cmd_help (core, help_msg_oj); + rz_core_cmd_help (core, help_msg_oj); break; } PJ *pj = pj_new (); pj_a (pj); - r_id_storage_foreach (core->io->files, desc_list_json_cb, pj); + rz_id_storage_foreach (core->io->files, desc_list_json_cb, pj); pj_end (pj); core->print->cb_printf ("%s\n", pj_string (pj)); pj_free (pj); break; case 'L': // "oL" - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } if (input[1] == ' ') { - if (r_lib_open (core->lib, input + 2) == -1) { + if (rz_lib_open (core->lib, input + 2) == -1) { eprintf ("Oops\n"); } } else { if ('j' == input[1]) { - r_io_plugin_list_json (core->io); + rz_io_plugin_list_json (core->io); } else { - r_io_plugin_list (core->io); + rz_io_plugin_list (core->io); } } break; @@ -1502,13 +1502,13 @@ static int cmd_open(void *data, const char *input) { switch (input[1]) { case ' ': // "oi " { - RListIter *iter = NULL; - RCoreFile *f; - int nth = r_num_math (core->num, input + 2); + RzListIter *iter = NULL; + RzCoreFile *f; + int nth = rz_num_math (core->num, input + 2); int count = 0; - r_list_foreach (core->files, iter, f) { + rz_list_foreach (core->files, iter, f) { if (count == nth) { - r_io_use_fd (core->io, f->fd); + rz_io_use_fd (core->io, f->fd); break; } count++; @@ -1517,13 +1517,13 @@ static int cmd_open(void *data, const char *input) { break; case '-': // "oi-" { - RListIter *iter = NULL; - RCoreFile *f; - int nth = r_num_math (core->num, input + 2); + RzListIter *iter = NULL; + RzCoreFile *f; + int nth = rz_num_math (core->num, input + 2); int count = 0; - r_list_foreach (core->files, iter, f) { + rz_list_foreach (core->files, iter, f) { if (count == nth) { - r_core_file_close_fd (core, f->fd); + rz_core_file_close_fd (core, f->fd); break; } count++; @@ -1533,26 +1533,26 @@ static int cmd_open(void *data, const char *input) { case 'j': // "oij" case '*': // "oi*" case 0: // "oi" - r_core_file_list (core, input[1]); + rz_core_file_list (core, input[1]); break; } break; case 'u': { // "ou" - RListIter *iter = NULL; - RCoreFile *f; + RzListIter *iter = NULL; + RzCoreFile *f; core->switch_file_view = 0; int num = atoi (input + 2); - r_list_foreach (core->files, iter, f) { + rz_list_foreach (core->files, iter, f) { if (f->fd == num) { core->file = f; } } - r_io_use_fd (core->io, num); - RBinFile *bf = r_bin_file_find_by_fd (core->bin, num); + rz_io_use_fd (core->io, num); + RBinFile *bf = rz_bin_file_find_by_fd (core->bin, num); if (bf) { - r_core_bin_raise (core, bf->id); - r_core_block_read (core); + rz_core_bin_raise (core, bf->id); + rz_core_block_read (core); } break; } @@ -1562,74 +1562,74 @@ static int cmd_open(void *data, const char *input) { case '-': // "o-" switch (input[1]) { case '!': // "o-!" - r_core_file_close_all_but (core); + rz_core_file_close_all_but (core); break; case '*': // "o-*" - r_core_file_close_fd (core, -1); - r_io_close_all (core->io); - r_bin_file_delete_all (core->bin); + rz_core_file_close_fd (core, -1); + rz_io_close_all (core->io); + rz_bin_file_delete_all (core->bin); if (core->files) { - r_list_purge (core->files); + rz_list_purge (core->files); } break; case '-': // "o--" eprintf ("All core files, io, anal and flags info purged.\n"); - r_core_file_close_fd (core, -1); - r_io_close_all (core->io); - r_bin_file_delete_all (core->bin); + rz_core_file_close_fd (core, -1); + rz_io_close_all (core->io); + rz_bin_file_delete_all (core->bin); // TODO: Move to a-- ? - r_anal_purge (core->anal); + rz_anal_purge (core->anal); // TODO: Move to f-- ? - r_flag_unset_all (core->flags); + rz_flag_unset_all (core->flags); // TODO: rbin? break; default: { - int fd = (int)r_num_math (core->num, input + 1); - if (!r_core_file_close_fd (core, fd)) { + int fd = (int)rz_num_math (core->num, input + 1); + if (!rz_core_file_close_fd (core, fd)) { eprintf ("Unable to find file descriptor %d\n", fd); } } break; case 0: case '?': - r_core_cmd_help (core, help_msg_o_); + rz_core_cmd_help (core, help_msg_o_); } break; case '.': // "o." if (input[1] == 'q') { // "o.q" // same as oq - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { - r_cons_printf ("%d\n", map->fd); + rz_cons_printf ("%d\n", map->fd); } } else { - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { - RIODesc *desc = r_io_desc_get (core->io, map->fd); + RzIODesc *desc = rz_io_desc_get (core->io, map->fd); if (desc) { - r_cons_printf ("%s\n", desc->uri); + rz_cons_printf ("%s\n", desc->uri); } } } break; case ':': // "o:" { - int len = r_num_math (core->num, input + 1); + int len = rz_num_math (core->num, input + 1); if (len < 1) { len = core->blocksize; } - char *uri = r_str_newf ("malloc://%d", len); + char *uri = rz_str_newf ("malloc://%d", len); ut8 *data = calloc (len, 1); - r_io_read_at (core->io, core->offset, data, len); - if ((file = r_core_file_open (core, uri, R_PERM_RWX, 0))) { + rz_io_read_at (core->io, core->offset, data, len); + if ((file = rz_core_file_open (core, uri, R_PERM_RWX, 0))) { fd = file->fd; core->num->value = fd; - r_core_bin_load (core, uri, 0); - RIODesc *desc = r_io_desc_get (core->io, fd); + rz_core_bin_load (core, uri, 0); + RzIODesc *desc = rz_io_desc_get (core->io, fd); if (desc) { - // TODO: why r_io_desc_write() fails? - r_io_desc_write_at (desc, 0, data, len); + // TODO: why rz_io_desc_write() fails? + rz_io_desc_write_at (desc, 0, data, len); } } else { eprintf ("Cannot %s\n", uri); @@ -1644,58 +1644,58 @@ static int cmd_open(void *data, const char *input) { case 'o': // "oo" switch (input[1]) { case 'm': // "oom" - r_core_file_reopen_in_malloc (core); + rz_core_file_reopen_in_malloc (core); break; case 'd': // "ood" : reopen in debugger if (input[2] == 'r') { // "oodr" - r_core_cmdf (core, "dor %s", input + 3); - r_core_file_reopen_debug (core, ""); + rz_core_cmdf (core, "dor %s", input + 3); + rz_core_file_reopen_debug (core, ""); } else if (input[2] == 'f') { // "oodf" char **argv = NULL; int addr = 0; - argv = r_str_argv (input + 3, &argc); + argv = rz_str_argv (input + 3, &argc); if (argc == 0) { eprintf ("Usage: oodf (uri://)[/path/to/file] (addr)\n"); - r_str_argv_free (argv); + rz_str_argv_free (argv); return 0; } if (argc == 2) { - if (r_num_is_valid_input (core->num, argv[1])) { - addr = r_num_math (core->num, argv[1]); + if (rz_num_is_valid_input (core->num, argv[1])) { + addr = rz_num_math (core->num, argv[1]); } } - r_core_file_reopen_remote_debug (core, argv[0], addr); - r_str_argv_free (argv); + rz_core_file_reopen_remote_debug (core, argv[0], addr); + rz_str_argv_free (argv); } else if ('?' == input[2]) { - r_core_cmd_help (core, help_msg_ood); + rz_core_cmd_help (core, help_msg_ood); } else { - r_core_file_reopen_debug (core, input + 2); + rz_core_file_reopen_debug (core, input + 2); } break; case 'c': // "oob" : reopen with bin info - r_core_cmd0 (core, "oc `o.`"); + rz_core_cmd0 (core, "oc `o.`"); break; case 'b': // "oob" : reopen with bin info if ('?' == input[2]) { - r_core_cmd_help (core, help_msg_oob); + rz_core_cmd_help (core, help_msg_oob); } else { - r_core_file_reopen (core, input + 2, 0, 2); + rz_core_file_reopen (core, input + 2, 0, 2); } break; case 'n': // "oon" switch (input[2]) { case 0: // "oon" - r_core_file_reopen (core, NULL, 0, 0); + rz_core_file_reopen (core, NULL, 0, 0); break; case '+': // "oon+" - r_core_file_reopen (core, NULL, R_PERM_RW, 0); + rz_core_file_reopen (core, NULL, R_PERM_RW, 0); break; case 'n': // "oonn" if ('?' == input[3] || !core->file) { - r_core_cmd_help (core, help_msg_oonn); + rz_core_cmd_help (core, help_msg_oonn); break; } - RIODesc *desc = r_io_desc_get (core->io, core->file->fd); + RzIODesc *desc = rz_io_desc_get (core->io, core->file->fd); if (desc) { perms = core->io->desc->perm; if (input[3] == '+') { @@ -1703,8 +1703,8 @@ static int cmd_open(void *data, const char *input) { } char *fname = strdup (desc->name); if (fname) { - r_core_bin_load_structs (core, fname); - r_core_file_reopen (core, fname, perms, 0); + rz_core_bin_load_structs (core, fname); + rz_core_file_reopen (core, fname, perms, 0); free (fname); } break; @@ -1712,26 +1712,26 @@ static int cmd_open(void *data, const char *input) { break; case '?': default: - r_core_cmd_help (core, help_msg_oon); + rz_core_cmd_help (core, help_msg_oon); break; } break; case '+': // "oo+" if ('?' == input[2]) { - r_core_cmd_help (core, help_msg_oo_plus); + rz_core_cmd_help (core, help_msg_oo_plus); } else if (core && core->io && core->io->desc) { int fd; int perms = R_PERM_RW; if ((ptr = strrchr (input, ' ')) && ptr[1]) { - fd = (int)r_num_math (core->num, ptr + 1); + fd = (int)rz_num_math (core->num, ptr + 1); } else { fd = core->io->desc->fd; perms |= core->io->desc->perm; } - if (r_io_reopen (core->io, fd, perms, 644)) { + if (rz_io_reopen (core->io, fd, perms, 644)) { void **it; - r_pvector_foreach_prev (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach_prev (&core->io->maps, it) { + RzIOMap *map = *it; if (map->fd == fd) { map->perm |= R_PERM_WX; } @@ -1743,40 +1743,40 @@ static int cmd_open(void *data, const char *input) { if (core && core->io && core->io->desc) { int fd; if ((ptr = strrchr (input, ' ')) && ptr[1]) { - fd = (int)r_num_math (core->num, ptr + 1); + fd = (int)rz_num_math (core->num, ptr + 1); } else { fd = core->io->desc->fd; } - if (r_config_get_i (core->config, "cfg.debug")) { - RBinFile *bf = r_bin_cur (core->bin); - if (bf && r_file_exists (bf->file)) { + if (rz_config_get_i (core->config, "cfg.debug")) { + RBinFile *bf = rz_bin_cur (core->bin); + if (bf && rz_file_exists (bf->file)) { // Escape spaces so that o's argv parse will detect the path properly - char *file = r_str_path_escape (bf->file); + char *file = rz_str_path_escape (bf->file); // Backup the baddr and sections that were already rebased to // revert the rebase after the debug session is closed ut64 orig_baddr = core->bin->cur->o->baddr_shift; - RList *orig_sections = __save_old_sections (core); + RzList *orig_sections = __save_old_sections (core); - r_core_cmd0 (core, "ob-*"); - r_io_close_all (core->io); - r_config_set (core->config, "cfg.debug", "false"); - r_core_cmdf (core, "o %s", file); + rz_core_cmd0 (core, "ob-*"); + rz_io_close_all (core->io); + rz_config_set (core->config, "cfg.debug", "false"); + rz_core_cmdf (core, "o %s", file); - r_core_block_read (core); + rz_core_block_read (core); __rebase_everything (core, orig_sections, orig_baddr); - r_list_free (orig_sections); + rz_list_free (orig_sections); free (file); } else { eprintf ("Nothing to do.\n"); } } else { - r_io_reopen (core->io, fd, R_PERM_R, 644); + rz_io_reopen (core->io, fd, R_PERM_R, 644); } } break; case '?': default: - r_core_cmd_help (core, help_msg_oo); + rz_core_cmd_help (core, help_msg_oo); break; } break; @@ -1784,7 +1784,7 @@ static int cmd_open(void *data, const char *input) { if (input[1] == '?') { eprintf ("Usage: oc [file]\n"); } else if (input[1] && input[2]) { - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("This command is disabled in sandbox mode\n"); return 0; } @@ -1794,14 +1794,14 @@ static int cmd_open(void *data, const char *input) { } // memleak? lose all settings wtf // if load fails does not fallbacks to previous file - r_core_task_sync_end (&core->tasks); - r_core_fini (core); - r_core_init (core); - r_core_task_sync_begin (&core->tasks); - if (!r_core_file_open (core, input + 2, R_PERM_R, 0)) { + rz_core_task_sync_end (&core->tasks); + rz_core_fini (core); + rz_core_init (core); + rz_core_task_sync_begin (&core->tasks); + if (!rz_core_file_open (core, input + 2, R_PERM_R, 0)) { eprintf ("Cannot open file\n"); } - (void)r_core_bin_load (core, NULL, baddr); + (void)rz_core_bin_load (core, NULL, baddr); } else { eprintf ("Missing argument\n"); } @@ -1812,25 +1812,25 @@ static int cmd_open(void *data, const char *input) { fd = fdx = -1; char *ptr, *inp = strdup (input); if ((ptr = strrchr (inp, ' '))) { - fdx = (int)r_num_math (core->num, ptr + 1); + fdx = (int)rz_num_math (core->num, ptr + 1); *ptr = '\0'; if ((ptr = strchr (inp, ' '))) { - fd = r_num_math (core->num, ptr + 1); + fd = rz_num_math (core->num, ptr + 1); } } if ((fdx == -1) || (fd == -1) || (fdx == fd)) { free (inp); break; } - r_io_desc_exchange (core->io, fd, fdx); - r_core_block_read (core); + rz_io_desc_exchange (core->io, fd, fdx); + rz_core_block_read (core); } else { eprintf ("Usage: ox [fd] [fdx] - exchange two file descriptors\n"); } break; case '?': // "o?" default: - r_core_cmd_help (core, help_msg_o); + rz_core_cmd_help (core, help_msg_o); break; } return 0; diff --git a/libr/core/cmd_print.c b/librz/core/cmd_print.c similarity index 67% rename from libr/core/cmd_print.c rename to librz/core/cmd_print.c index 27e46b1fdc..25114ff6d9 100644 --- a/libr/core/cmd_print.c +++ b/librz/core/cmd_print.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include "r_asm.h" -#include "r_core.h" -#include "r_config.h" -#include "r_util.h" -#include "r_types.h" +#include "rz_asm.h" +#include "rz_core.h" +#include "rz_config.h" +#include "rz_util.h" +#include "rz_types.h" #include #define R_CORE_MAX_DISASM (1024 * 1024 * 8) @@ -36,7 +36,7 @@ static const char *help_msg_pp[] = { "pp4", "", "print incremental dword pattern", "pp8", "", "print incremental qword pattern", "ppa", "[lu]", "latin alphabet (lowercase, uppercases restrictions)", - "ppd", "", "print debruijn pattern (see ragg2 -P, -q and wopD)", + "ppd", "", "print debruijn pattern (see rz_gg -P, -q and wopD)", "ppf", "", "print buffer filled with 0xff", "ppn", "", "numeric pin patterns", NULL @@ -130,7 +130,7 @@ static const char *help_msg_at[] = { "*/", "", "end multiline comment", ".", "cmd", "execute output of command as r2 script", ".:", "8080", "wait for commands on port 8080", - ".!", "rabin2 -re $FILE", "run command output as r2 script", + ".!", "rz_bin -re $FILE", "run command output as r2 script", "*", "", "output of command in r2 script format (CC*)", "j", "", "output of command in JSON format (pdj)", "~", "?", "count number of lines (like wc -l)", @@ -591,7 +591,7 @@ static const ut32 colormap[256] = { 0x4c0032, 0x560039, 0x640042, 0x75004e, 0x87005a, 0x9b0067, 0xb00075, 0xc60084, 0xdd0093, 0xf500a3, 0xff0faf, 0xff28b7, 0xff43c0, 0xff5ec9, 0xff79d2, 0xffffff, }; -static void cmd_print_init(RCore *core, RCmdDesc *parent) { +static void cmd_print_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR_SPECIAL (core, &, amper); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, @, at); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, @@, at_at); @@ -609,33 +609,33 @@ static void cmd_print_init(RCore *core, RCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, pz); } -static void __cmd_pad(RCore *core, const char *arg) { +static void __cmd_pad(RzCore *core, const char *arg) { if (*arg == '?') { eprintf ("Usage: pad [hexpairs] # disassembly given bytes\n"); return; } - r_asm_set_pc (core->rasm, core->offset); - bool is_pseudo = r_config_get_i (core->config, "asm.pseudo"); - RAsmCode *acode = r_asm_mdisassemble_hexstr (core->rasm, is_pseudo ? core->parser : NULL, arg); + rz_asm_set_pc (core->rasm, core->offset); + bool is_pseudo = rz_config_get_i (core->config, "asm.pseudo"); + RzAsmCode *acode = rz_asm_mdisassemble_hexstr (core->rasm, is_pseudo ? core->parser : NULL, arg); if (acode) { - r_cons_print (acode->assembly); - r_asm_code_free (acode); + rz_cons_print (acode->assembly); + rz_asm_code_free (acode); } else { eprintf ("Invalid hexstr\n"); } } // colordump -static void cmd_prc(RCore *core, const ut8* block, int len) { +static void cmd_prc(RzCore *core, const ut8* block, int len) { const char *chars = " .,:;!O@#"; - bool square = r_config_get_i (core->config, "scr.square"); + bool square = rz_config_get_i (core->config, "scr.square"); int i, j; char ch, ch2, *color; - int cols = r_config_get_i (core->config, "hex.cols"); - bool show_color = r_config_get_i (core->config, "scr.color"); - bool show_flags = r_config_get_i (core->config, "asm.flags"); - bool show_section = r_config_get_i (core->config, "hex.section"); - bool show_offset = r_config_get_i (core->config, "hex.offset"); + int cols = rz_config_get_i (core->config, "hex.cols"); + bool show_color = rz_config_get_i (core->config, "scr.color"); + bool show_flags = rz_config_get_i (core->config, "asm.flags"); + bool show_section = rz_config_get_i (core->config, "hex.section"); + bool show_offset = rz_config_get_i (core->config, "hex.offset"); bool show_cursor = core->print->cur_enabled; bool show_unalloc = core->print->flags & R_PRINT_FLAGS_UNALLOC; if (cols < 1 || cols > 0xfffff) { @@ -643,11 +643,11 @@ static void cmd_prc(RCore *core, const ut8* block, int len) { } for (i = 0; i < len; i += cols) { if (show_section) { - const char * name = r_core_get_section_name (core, core->offset + i); - r_cons_printf ("%20s ", name? name: ""); + const char * name = rz_core_get_section_name (core, core->offset + i); + rz_cons_printf ("%20s ", name? name: ""); } if (show_offset) { - r_print_addr (core->print, core->offset + i); + rz_print_addr (core->print, core->offset + i); } for (j = i; j < i + cols; j ++) { if (j >= len) { @@ -657,9 +657,9 @@ static void cmd_prc(RCore *core, const ut8* block, int len) { ut32 color_val = colormap[block[j]]; int brightness = ((color_val & 0xff0000) >> 16) + 2 * ((color_val & 0xff00) >> 8) + (color_val & 0xff) / 2; - char *str = r_str_newf ("rgb:%s rgb:%06x", + char *str = rz_str_newf ("rgb:%s rgb:%06x", brightness <= 0x7f * 3 ? "fff" : "000", color_val); - color = r_cons_pal_parse (str, NULL); + color = rz_cons_pal_parse (str, NULL); free (str); if (show_cursor && core->print->cur == j) { ch = '_'; @@ -690,7 +690,7 @@ static void cmd_prc(RCore *core, const ut8* block, int len) { } if (square) { if (show_flags) { - RFlagItem *fi = r_flag_get_i (core->flags, core->offset + j); + RzFlagItem *fi = rz_flag_get_i (core->flags, core->offset + j); if (fi) { if (fi->name[1]) { ch = fi->name[0]; @@ -705,47 +705,47 @@ static void cmd_prc(RCore *core, const ut8* block, int len) { } else { ch2 = ch; } - r_cons_printf ("%s%c%c", color, ch, ch2); + rz_cons_printf ("%s%c%c", color, ch, ch2); } else { - r_cons_printf ("%s%c", color, ch); + rz_cons_printf ("%s%c", color, ch); } free (color); } if (show_color) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } - r_cons_newline (); + rz_cons_newline (); } } -static void cmd_prc_zoom(RCore *core, const char *input) { +static void cmd_prc_zoom(RzCore *core, const char *input) { const char *chars = " .,:;!O@#"; - bool square = r_config_get_i (core->config, "scr.square"); + bool square = rz_config_get_i (core->config, "scr.square"); int i, j; char ch, ch2, *color; - int cols = r_config_get_i (core->config, "hex.cols"); - bool show_color = r_config_get_i (core->config, "scr.color"); - bool show_flags = r_config_get_i (core->config, "asm.flags"); + int cols = rz_config_get_i (core->config, "hex.cols"); + bool show_color = rz_config_get_i (core->config, "scr.color"); + bool show_flags = rz_config_get_i (core->config, "asm.flags"); bool show_cursor = core->print->cur_enabled; - bool show_offset = r_config_get_i (core->config, "hex.offset"); + bool show_offset = rz_config_get_i (core->config, "hex.offset"); bool show_unalloc = core->print->flags & R_PRINT_FLAGS_UNALLOC; ut8 *block = core->block; int len = core->blocksize; ut64 from = 0; ut64 to = 0; - RIOMap* map; - RListIter *iter; + RzIOMap* map; + RzListIter *iter; if (cols < 1 || cols > 0xfffff) { cols = 32; } - RList *list = r_core_get_boundaries_prot (core, -1, NULL, "zoom"); - if (list && r_list_length (list) > 0) { - RListIter *iter1 = list->head; - RIOMap* map1 = iter1->data; + RzList *list = rz_core_get_boundaries_prot (core, -1, NULL, "zoom"); + if (list && rz_list_length (list) > 0) { + RzListIter *iter1 = list->head; + RzIOMap* map1 = iter1->data; from = map1->itv.addr; - r_list_foreach (list, iter, map) { - to = r_itv_end (map->itv); + rz_list_foreach (list, iter, map) { + to = rz_itv_end (map->itv); } } else { from = core->offset; @@ -753,7 +753,7 @@ static void cmd_prc_zoom(RCore *core, const char *input) { } core->print->zoom->mode = (input && *input)? input[1]: 'e'; - r_print_zoom_buf (core->print, core, printzoomcallback, from, to, len, len); + rz_print_zoom_buf (core->print, core, printzoomcallback, from, to, len, len); block = core->print->zoom->buf; switch (core->print->zoom->mode) { case 'f': @@ -767,15 +767,15 @@ static void cmd_prc_zoom(RCore *core, const char *input) { for (i = 0; i < len; i += cols) { ut64 ea = core->offset + i; if (show_offset) { - r_print_addr (core->print, ea); + rz_print_addr (core->print, ea); } for (j = i; j < i + cols; j ++) { if (j >= len) { break; } if (show_color) { - char *str = r_str_newf ("rgb:fff rgb:%06x", colormap[block[j]]); - color = r_cons_pal_parse (str, NULL); + char *str = rz_str_newf ("rgb:fff rgb:%06x", colormap[block[j]]); + color = rz_cons_pal_parse (str, NULL); free (str); if (show_cursor && core->print->cur == j) { ch = '_'; @@ -806,7 +806,7 @@ static void cmd_prc_zoom(RCore *core, const char *input) { } if (square) { if (show_flags) { - RFlagItem *fi = r_flag_get_i (core->flags, core->offset + j); + RzFlagItem *fi = rz_flag_get_i (core->flags, core->offset + j); if (fi) { if (fi->name[1]) { ch = fi->name[0]; @@ -821,75 +821,75 @@ static void cmd_prc_zoom(RCore *core, const char *input) { } else { ch2 = ch; } - r_cons_printf ("%s%c%c", color, ch, ch2); + rz_cons_printf ("%s%c%c", color, ch, ch2); } else { - r_cons_printf ("%s%c", color, ch); + rz_cons_printf ("%s%c", color, ch); } free (color); } if (show_color) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } - r_cons_newline (); + rz_cons_newline (); } } -static void cmd_pCd(RCore *core, const char *input) { - int h, w = r_cons_get_size (&h); - int colwidth = r_config_get_i (core->config, "hex.cols") * 2.5; +static void cmd_pCd(RzCore *core, const char *input) { + int h, w = rz_cons_get_size (&h); + int colwidth = rz_config_get_i (core->config, "hex.cols") * 2.5; if (colwidth < 1) { colwidth = 16; } int i, columns = w / colwidth; int rows = h - 2; int obsz = core->blocksize; - int user_rows = r_num_math (core->num, input); - bool asm_minicols = r_config_get_i (core->config, "asm.minicols"); - char *o_ao = strdup (r_config_get (core->config, "asm.offset")); - char *o_ab = strdup (r_config_get (core->config, "asm.bytes")); + int user_rows = rz_num_math (core->num, input); + bool asm_minicols = rz_config_get_i (core->config, "asm.minicols"); + char *o_ao = strdup (rz_config_get (core->config, "asm.offset")); + char *o_ab = strdup (rz_config_get (core->config, "asm.bytes")); if (asm_minicols) { - r_config_set (core->config, "asm.offset", "false"); -// r_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.offset", "false"); +// rz_config_set (core->config, "asm.bytes", "false"); } - r_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.bytes", "false"); if (user_rows > 0) { rows = user_rows + 1; } - r_cons_push (); - RConsCanvas *c = r_cons_canvas_new (w, rows); + rz_cons_push (); + RzConsCanvas *c = rz_cons_canvas_new (w, rows); ut64 osek = core->offset; - c->color = r_config_get_i (core->config, "scr.color"); - r_core_block_size (core, rows * 32); + c->color = rz_config_get_i (core->config, "scr.color"); + rz_core_block_size (core, rows * 32); for (i = 0; i < columns; i++) { - (void) r_cons_canvas_gotoxy (c, i * (w / columns), 0); - char *cmd = r_str_newf ("pid %d @i:%d", rows, rows * i); - char *dis = r_core_cmd_str (core, cmd); - r_cons_canvas_write (c, dis); + (void) rz_cons_canvas_gotoxy (c, i * (w / columns), 0); + char *cmd = rz_str_newf ("pid %d @i:%d", rows, rows * i); + char *dis = rz_core_cmd_str (core, cmd); + rz_cons_canvas_write (c, dis); free (cmd); free (dis); } - r_core_block_size (core, obsz); - r_core_seek (core, osek, true); + rz_core_block_size (core, obsz); + rz_core_seek (core, osek, true); - r_cons_pop (); - r_cons_canvas_print (c); - r_cons_canvas_free (c); + rz_cons_pop (); + rz_cons_canvas_print (c); + rz_cons_canvas_free (c); if (asm_minicols) { - r_config_set (core->config, "asm.offset", o_ao); - r_config_set (core->config, "asm.bytes", o_ab); + rz_config_set (core->config, "asm.offset", o_ao); + rz_config_set (core->config, "asm.bytes", o_ab); } - r_config_set (core->config, "asm.bytes", o_ab); + rz_config_set (core->config, "asm.bytes", o_ab); free (o_ao); free (o_ab); } -static void findMethodBounds(RList *methods, ut64 *min, ut64 *max) { +static void findMethodBounds(RzList *methods, ut64 *min, ut64 *max) { RBinSymbol *sym; - RListIter *iter; + RzListIter *iter; ut64 at_min = UT64_MAX; ut64 at_max = 0LL; - r_list_foreach (methods, iter, sym) { + rz_list_foreach (methods, iter, sym) { if (sym->vaddr) { if (sym->vaddr < at_min) { at_min = sym->vaddr; @@ -903,12 +903,12 @@ static void findMethodBounds(RList *methods, ut64 *min, ut64 *max) { *max = at_max; } -static ut64 findClassBounds(RCore *core, const char *input, int *len) { +static ut64 findClassBounds(RzCore *core, const char *input, int *len) { ut64 min = 0, max = 0; - RListIter *iter; + RzListIter *iter; RBinClass *c; - RList *cs = r_bin_get_classes (core->bin); - r_list_foreach (cs, iter, c) { + RzList *cs = rz_bin_get_classes (core->bin); + rz_list_foreach (cs, iter, c) { if (!c || !c->name || !c->name[0]) { continue; } @@ -921,101 +921,101 @@ static ut64 findClassBounds(RCore *core, const char *input, int *len) { return 0; } -static void cmd_pCD(RCore *core, const char *input) { - int h, w = r_cons_get_size (&h); +static void cmd_pCD(RzCore *core, const char *input) { + int h, w = rz_cons_get_size (&h); int i; int rows = h - 2; int obsz = core->blocksize; - int user_rows = r_num_math (core->num, input); - bool asm_minicols = r_config_get_i (core->config, "asm.minicols"); - char *o_ao = strdup (r_config_get (core->config, "asm.offset")); - char *o_ab = strdup (r_config_get (core->config, "asm.bytes")); + int user_rows = rz_num_math (core->num, input); + bool asm_minicols = rz_config_get_i (core->config, "asm.minicols"); + char *o_ao = strdup (rz_config_get (core->config, "asm.offset")); + char *o_ab = strdup (rz_config_get (core->config, "asm.bytes")); if (asm_minicols) { - r_config_set (core->config, "asm.offset", "false"); - r_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.offset", "false"); + rz_config_set (core->config, "asm.bytes", "false"); } - r_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.bytes", "false"); if (user_rows > 0) { rows = user_rows + 1; } - r_cons_push (); - RConsCanvas *c = r_cons_canvas_new (w, rows); + rz_cons_push (); + RzConsCanvas *c = rz_cons_canvas_new (w, rows); ut64 osek = core->offset; - c->color = r_config_get_i (core->config, "scr.color"); - r_core_block_size (core, rows * 32); + c->color = rz_config_get_i (core->config, "scr.color"); + rz_core_block_size (core, rows * 32); char *cmd = NULL; int columns = 2; for (i = 0; i < columns; i++) { switch (i) { case 0: - (void) r_cons_canvas_gotoxy (c, 0, 0); - cmd = r_str_newf ("dr;?e;?e backtrace:;dbt"); + (void) rz_cons_canvas_gotoxy (c, 0, 0); + cmd = rz_str_newf ("dr;?e;?e backtrace:;dbt"); break; case 1: - (void) r_cons_canvas_gotoxy (c, 28, 0); - // cmd = r_str_newf ("pxw 128@r:SP;pd@r:PC"); - cmd = r_str_newf ("%s 128@r:SP;pd@ 0x%"PFMT64x, core->stkcmd, osek); + (void) rz_cons_canvas_gotoxy (c, 28, 0); + // cmd = rz_str_newf ("pxw 128@r:SP;pd@r:PC"); + cmd = rz_str_newf ("%s 128@r:SP;pd@ 0x%"PFMT64x, core->stkcmd, osek); break; } - char *dis = r_core_cmd_str (core, cmd); - r_cons_canvas_write (c, dis); + char *dis = rz_core_cmd_str (core, cmd); + rz_cons_canvas_write (c, dis); free (cmd); free (dis); } - r_core_block_size (core, obsz); - r_core_seek (core, osek, true); + rz_core_block_size (core, obsz); + rz_core_seek (core, osek, true); - r_cons_pop (); - r_cons_canvas_print (c); - r_cons_canvas_free (c); + rz_cons_pop (); + rz_cons_canvas_print (c); + rz_cons_canvas_free (c); if (asm_minicols) { - r_config_set (core->config, "asm.offset", o_ao); - r_config_set (core->config, "asm.bytes", o_ab); + rz_config_set (core->config, "asm.offset", o_ao); + rz_config_set (core->config, "asm.bytes", o_ab); } - r_config_set (core->config, "asm.bytes", o_ab); + rz_config_set (core->config, "asm.bytes", o_ab); free (o_ao); free (o_ab); } -static void cmd_pCx(RCore *core, const char *input, const char *xcmd) { - int h, w = r_cons_get_size (&h); - int hex_cols = r_config_get_i (core->config, "hex.cols"); +static void cmd_pCx(RzCore *core, const char *input, const char *xcmd) { + int h, w = rz_cons_get_size (&h); + int hex_cols = rz_config_get_i (core->config, "hex.cols"); int colwidth = hex_cols * 5; int i, columns = w / (colwidth * 0.9); int rows = h - 2; - int user_rows = r_num_math (core->num, input); - r_config_set_i (core->config, "hex.cols", colwidth / 5); + int user_rows = rz_num_math (core->num, input); + rz_config_set_i (core->config, "hex.cols", colwidth / 5); if (user_rows > 0) { rows = user_rows + 1; } - RConsCanvas *c = r_cons_canvas_new (w, rows); + RzConsCanvas *c = rz_cons_canvas_new (w, rows); if (!c) { eprintf ("Couldn't allocate a canvas with %d rows\n", rows); goto err; } ut64 tsek = core->offset; - c->color = r_config_get_i (core->config, "scr.color"); + c->color = rz_config_get_i (core->config, "scr.color"); int bsize = hex_cols * rows; if (!strcmp (xcmd, "pxA")) { bsize *= 12; } for (i = 0; i < columns; i++) { - (void) r_cons_canvas_gotoxy (c, i * (w / columns), 0); - char *cmd = r_str_newf ("%s %d @ %"PFMT64u, xcmd, bsize, tsek); - char *dis = r_core_cmd_str (core, cmd); + (void) rz_cons_canvas_gotoxy (c, i * (w / columns), 0); + char *cmd = rz_str_newf ("%s %d @ %"PFMT64u, xcmd, bsize, tsek); + char *dis = rz_core_cmd_str (core, cmd); if (dis) { - r_cons_canvas_write (c, dis); + rz_cons_canvas_write (c, dis); free (dis); } free (cmd); tsek += bsize - 32; } - r_cons_canvas_print (c); - r_cons_canvas_free (c); + rz_cons_canvas_print (c); + rz_cons_canvas_free (c); err: - r_config_set_i (core->config, "hex.cols", hex_cols); + rz_config_set_i (core->config, "hex.cols", hex_cols); } static char get_string_type(const ut8 *buf, ut64 len) { @@ -1027,7 +1027,7 @@ static char get_string_type(const ut8 *buf, ut64 len) { return '?'; } while (needle < len) { - rc = r_utf8_decode (buf + needle, len - needle, NULL); + rc = rz_utf8_decode (buf + needle, len - needle, NULL); if (!rc) { needle++; continue; @@ -1050,7 +1050,7 @@ static char get_string_type(const ut8 *buf, ut64 len) { break; } } else { - rc = r_utf8_decode (buf + needle, len - needle, &r); + rc = rz_utf8_decode (buf + needle, len - needle, &r); if (rc > 1) { str_type = 'u'; } @@ -1066,7 +1066,7 @@ static char get_string_type(const ut8 *buf, ut64 len) { return str_type; } -static void cmd_print_eq_dict(RCore *core, const ut8 *block, int bsz) { +static void cmd_print_eq_dict(RzCore *core, const ut8 *block, int bsz) { int i; int min = -1; int max = 0; @@ -1086,23 +1086,23 @@ static void cmd_print_eq_dict(RCore *core, const ut8 *block, int bsz) { } } range = max - min; - r_cons_printf ("min: %d 0x%x\n", min, min); - r_cons_printf ("max: %d 0x%x\n", max, max); - r_cons_printf ("unique (count): %d 0x%x\n", dict, dict); - r_cons_printf ("range (max-min): %d 0x%x\n", range, range); - r_cons_printf ("size (of block): %d 0x%x\n", bsz, bsz); + rz_cons_printf ("min: %d 0x%x\n", min, min); + rz_cons_printf ("max: %d 0x%x\n", max, max); + rz_cons_printf ("unique (count): %d 0x%x\n", dict, dict); + rz_cons_printf ("range (max-min): %d 0x%x\n", range, range); + rz_cons_printf ("size (of block): %d 0x%x\n", bsz, bsz); } -R_API void r_core_set_asm_configs(RCore *core, char *arch, ut32 bits, int segoff) { - r_config_set (core->config, "asm.arch", arch); - r_config_set_i (core->config, "asm.bits", bits); +RZ_API void rz_core_set_asm_configs(RzCore *core, char *arch, ut32 bits, int segoff) { + rz_config_set (core->config, "asm.arch", arch); + rz_config_set_i (core->config, "asm.bits", bits); // XXX - this needs to be done here, because // if arch == x86 and bits == 16, segoff automatically changes - r_config_set_i (core->config, "asm.segoff", segoff); + rz_config_set_i (core->config, "asm.segoff", segoff); } -static void cmd_pDj(RCore *core, const char *arg) { - int bsize = r_num_math (core->num, arg); +static void cmd_pDj(RzCore *core, const char *arg) { + int bsize = rz_num_math (core->num, arg); if (bsize < 0) { bsize = -bsize; } @@ -1113,75 +1113,75 @@ static void cmd_pDj(RCore *core, const char *arg) { pj_a (pj); ut8 *buf = malloc (bsize); if (buf) { - r_io_read_at (core->io, core->offset, buf, bsize); - r_core_print_disasm_json (core, core->offset, buf, bsize, 0, pj); + rz_io_read_at (core->io, core->offset, buf, bsize); + rz_core_print_disasm_json (core, core->offset, buf, bsize, 0, pj); free (buf); } else { eprintf ("cannot allocate %d byte(s)\n", bsize); } pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); } -static void cmd_pdj(RCore *core, const char *arg, ut8* block) { - int nblines = r_num_math (core->num, arg); +static void cmd_pdj(RzCore *core, const char *arg, ut8* block) { + int nblines = rz_num_math (core->num, arg); PJ *pj = pj_new (); if (!pj) { return; } pj_a (pj); - r_core_print_disasm_json (core, core->offset, block, core->blocksize, nblines, pj); + rz_core_print_disasm_json (core, core->offset, block, core->blocksize, nblines, pj); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } -static void cmd_p_minus_e(RCore *core, ut64 at, ut64 ate) { +static void cmd_p_minus_e(RzCore *core, ut64 at, ut64 ate) { ut8 *blockptr = malloc (ate - at); if (!blockptr) { return; } - if (r_io_read_at (core->io, at, blockptr, (ate - at))) { - ut8 entropy = (ut8)(r_hash_entropy_fraction (blockptr, (ate - at)) * 255); + if (rz_io_read_at (core->io, at, blockptr, (ate - at))) { + ut8 entropy = (ut8)(rz_hash_entropy_fraction (blockptr, (ate - at)) * 255); entropy = 9 * entropy / 200; // normalize entropy from 0 to 9 - if (r_config_get_i (core->config, "scr.color")) { + if (rz_config_get_i (core->config, "scr.color")) { const char *color = (entropy > 6) ? Color_BGRED : (entropy > 3) ? Color_BGGREEN : Color_BGBLUE; - r_cons_printf ("%s%d"Color_RESET, color, entropy); + rz_cons_printf ("%s%d"Color_RESET, color, entropy); } else { - r_cons_printf ("%d", entropy); + rz_cons_printf ("%d", entropy); } } free (blockptr); } -static void helpCmdTasks(RCore *core) { +static void helpCmdTasks(RzCore *core) { // TODO: integrate with =h& and bg anal/string/searches/.. - r_core_cmd_help (core, help_msg_amper); + rz_core_cmd_help (core, help_msg_amper); } -static void print_format_help_help_help_help(RCore *core) { +static void print_format_help_help_help_help(RzCore *core) { const char *help_msg[] = { " STAHP IT!!!", "", "", NULL }; - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); } -static void cmd_print_fromage(RCore *core, const char *input, const ut8* data, int size) { +static void cmd_print_fromage(RzCore *core, const char *input, const ut8* data, int size) { switch (*input) { case 'a': { asn1_setformat (input[1] != 'q'); - RASN1Object *asn1 = r_asn1_create_object (data, size, data); + RASN1Object *asn1 = rz_asn1_create_object (data, size, data); if (asn1) { - char *res = r_asn1_to_string (asn1, 0, NULL); - r_asn1_free_object (asn1); + char *res = rz_asn1_to_string (asn1, 0, NULL); + rz_asn1_free_object (asn1); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } } else { @@ -1191,16 +1191,16 @@ static void cmd_print_fromage(RCore *core, const char *input, const ut8* data, i break; case 'x': // "pFx" x509 { - RX509Certificate* x509 = r_x509_parse_certificate (r_asn1_create_object (data, size, data)); + RX509Certificate* x509 = rz_x509_parse_certificate (rz_asn1_create_object (data, size, data)); if (x509) { - RStrBuf *sb = r_strbuf_new (""); - r_x509_certificate_dump (x509, NULL, sb); - char *res = r_strbuf_drain (sb); + RStrBuf *sb = rz_strbuf_new (""); + rz_x509_certificate_dump (x509, NULL, sb); + char *res = rz_strbuf_drain (sb); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } - r_x509_free_certificate (x509); + rz_x509_free_certificate (x509); } else { eprintf ("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n"); } @@ -1208,14 +1208,14 @@ static void cmd_print_fromage(RCore *core, const char *input, const ut8* data, i break; case 'p': // "pFp" { - RCMS *cms = r_pkcs7_parse_cms (data, size); + RCMS *cms = rz_pkcs7_parse_cms (data, size); if (cms) { - char *res = r_pkcs7_cms_to_string (cms); + char *res = rz_pkcs7_cms_to_string (cms); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } - r_pkcs7_free_cms (cms); + rz_pkcs7_free_cms (cms); } else { eprintf ("Malformed object: did you supply enough data?\ntry to change the block size (see b?)\n"); } @@ -1223,21 +1223,21 @@ static void cmd_print_fromage(RCore *core, const char *input, const ut8* data, i break; case 'b': // "pFb" { - char *s = r_protobuf_decode(data, size, input[1] == 'v'); + char *s = rz_protobuf_decode(data, size, input[1] == 'v'); if (s) { - r_cons_printf ("%s", s); + rz_cons_printf ("%s", s); free (s); } } break; default: case '?': // "pF?" - r_core_cmd_help (core, help_msg_pF); + rz_core_cmd_help (core, help_msg_pF); break; } } -R_API void r_core_gadget_free(RCoreGadget *g) { +RZ_API void rz_core_gadget_free(RzCoreGadget *g) { free (g->cmd); free (g); } @@ -1251,26 +1251,26 @@ static const char *help_msg_pg[] = { NULL }; -static void cmd_print_gadget(RCore *core, const char *_input) { +static void cmd_print_gadget(RzCore *core, const char *_input) { if (*_input == '?') { // "pg?" - r_core_cmd_help (core, help_msg_pg); + rz_core_cmd_help (core, help_msg_pg); return; } if (*_input == '-') { // "pg-" // TODO support selecting one - r_list_free (core->gadgets); - core->gadgets = r_list_newf ((RListFree)r_core_gadget_free); + rz_list_free (core->gadgets); + core->gadgets = rz_list_newf ((RzListFree)rz_core_gadget_free); } else if (*_input == '*') { // "pg*" - RCoreGadget *g; - RListIter *iter; - r_list_foreach (core->gadgets, iter, g) { - r_cons_printf ("\"pg %d %d %d %d %s\"\n", g->x, g->y, g->w, g->h, g->cmd); + RzCoreGadget *g; + RzListIter *iter; + rz_list_foreach (core->gadgets, iter, g) { + rz_cons_printf ("\"pg %d %d %d %d %s\"\n", g->x, g->y, g->w, g->h, g->cmd); } } else if (*_input == 'b') { // "pgb" eprintf ("TODO: Change gadget background color\n"); } else if (*_input == 'm') { // "pgm" int nth = atoi (_input + 1); - RCoreGadget *g = r_list_get_n (core->gadgets, nth); + RzCoreGadget *g = rz_list_get_n (core->gadgets, nth); if (g) { char *input = strdup (_input); char *space = strchr (input, ' '); @@ -1279,62 +1279,62 @@ static void cmd_print_gadget(RCore *core, const char *_input) { } else { space = ""; } - RList *args = r_str_split_list (space, " ", 0); - char *x = r_list_pop_head (args); - char *y = r_list_pop_head (args); - char *w = r_list_pop_head (args); - char *h = r_list_pop_head (args); + RzList *args = rz_str_split_list (space, " ", 0); + char *x = rz_list_pop_head (args); + char *y = rz_list_pop_head (args); + char *w = rz_list_pop_head (args); + char *h = rz_list_pop_head (args); if (x && y && w && h) { - g->x = r_num_math (core->num, x); - g->y = r_num_math (core->num, y); - g->w = r_num_math (core->num, w); - g->h = r_num_math (core->num, h); + g->x = rz_num_math (core->num, x); + g->y = rz_num_math (core->num, y); + g->w = rz_num_math (core->num, w); + g->h = rz_num_math (core->num, h); } - r_list_free (args); + rz_list_free (args); free (input); } } else if (*_input == ' ') { // "pg " char *input = strdup (_input); - RList *args = r_str_split_list (input, " ", 0); - char *x = r_list_pop_head (args); - char *y = r_list_pop_head (args); - char *w = r_list_pop_head (args); - char *h = r_list_pop_head (args); + RzList *args = rz_str_split_list (input, " ", 0); + char *x = rz_list_pop_head (args); + char *y = rz_list_pop_head (args); + char *w = rz_list_pop_head (args); + char *h = rz_list_pop_head (args); if (x && y && w && h) { - int X = r_num_math (core->num, x); - int Y = r_num_math (core->num, y); - int W = r_num_math (core->num, w); - int H = r_num_math (core->num, h); - char *cmd = r_str_list_join (args, " "); + int X = rz_num_math (core->num, x); + int Y = rz_num_math (core->num, y); + int W = rz_num_math (core->num, w); + int H = rz_num_math (core->num, h); + char *cmd = rz_str_list_join (args, " "); if (cmd) { // eprintf ("%d %d %d %d (%s)\n", X, Y, W, H, cmd); - RCoreGadget *g = R_NEW0 (RCoreGadget); + RzCoreGadget *g = R_NEW0 (RzCoreGadget); g->x = X; g->y = Y; g->w = W; g->h = H; g->cmd = cmd; - r_list_append (core->gadgets, g); + rz_list_append (core->gadgets, g); } } - r_list_free (args); + rz_list_free (args); free (input); } else if (!*_input) { // "pg" - RCoreGadget *g; - RListIter *iter; - r_list_foreach (core->gadgets, iter, g) { - char *res = r_core_cmd_str (core, g->cmd); + RzCoreGadget *g; + RzListIter *iter; + rz_list_foreach (core->gadgets, iter, g) { + char *res = rz_core_cmd_str (core, g->cmd); if (res) { - r_cons_strcat_at (res, g->x, g->y, g->w, g->h); + rz_cons_strcat_at (res, g->x, g->y, g->w, g->h); free (res); } } } else { - r_core_cmd_help (core, help_msg_pg); + rz_core_cmd_help (core, help_msg_pg); } } -static void cmd_print_format(RCore *core, const char *_input, const ut8* block, int len) { +static void cmd_print_format(RzCore *core, const char *_input, const ut8* block, int len) { char *input = NULL; int mode = R_PRINT_MUSTSEE; switch (_input[1]) { @@ -1369,7 +1369,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, _input++; val = sdb_get (core->print->formats, _input, NULL); if (val) { - r_cons_printf ("%d\n", r_print_format_struct_size (core->print, val, mode, 0)); + rz_cons_printf ("%d\n", rz_print_format_struct_size (core->print, val, mode, 0)); } else { eprintf ("Struct %s not defined\nUsage: pfs.struct_name | pfs format\n", _input); } @@ -1378,7 +1378,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, _input++; } if (*_input) { - r_cons_printf ("%d\n", r_print_format_struct_size (core->print, _input, mode, 0)); + rz_cons_printf ("%d\n", rz_print_format_struct_size (core->print, _input, mode, 0)); } else { eprintf ("Struct %s not defined\nUsage: pfs.struct_name | pfs format\n", _input); } @@ -1397,22 +1397,22 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, if (_input && *_input == '?') { print_format_help_help_help_help (core); } else { - r_core_cmd_help (core, help_detail2_pf); + rz_core_cmd_help (core, help_detail2_pf); } } else { - r_core_cmd_help (core, help_detail_pf); + rz_core_cmd_help (core, help_detail_pf); } } else { - const char *struct_name = r_str_trim_head_ro (_input); + const char *struct_name = rz_str_trim_head_ro (_input); const char *val = sdb_get (core->print->formats, struct_name, NULL); if (val) { - r_cons_printf ("%s\n", val); + rz_cons_printf ("%s\n", val); } else { eprintf ("Struct %s is not defined\n", _input); } } } else { - r_core_cmd_help (core, help_msg_pf); + rz_core_cmd_help (core, help_msg_pf); } return; case 'o': // "pfo" @@ -1420,28 +1420,28 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, eprintf ("|Usage: pfo [format-file]\n" " " R_JOIN_3_PATHS ("~", R2_HOME_SDB_FORMAT, "") "\n" " " R_JOIN_3_PATHS ("%s", R2_SDB_FORMAT, "") "\n", - r_sys_prefix (NULL)); + rz_sys_prefix (NULL)); } else if (_input[2] == ' ') { - const char *fname = r_str_trim_head_ro (_input + 3); - char *tmp = r_str_newf (R_JOIN_2_PATHS (R2_HOME_SDB_FORMAT, "%s"), fname); - char *home = r_str_home (tmp); + const char *fname = rz_str_trim_head_ro (_input + 3); + char *tmp = rz_str_newf (R_JOIN_2_PATHS (R2_HOME_SDB_FORMAT, "%s"), fname); + char *home = rz_str_home (tmp); free (tmp); - tmp = r_str_newf (R_JOIN_2_PATHS (R2_SDB_FORMAT, "%s"), fname); - char *path = r_str_r2_prefix (tmp); - if (r_str_endswith (_input, ".h")) { + tmp = rz_str_newf (R_JOIN_2_PATHS (R2_SDB_FORMAT, "%s"), fname); + char *path = rz_str_rz_prefix (tmp); + if (rz_str_endswith (_input, ".h")) { char *error_msg = NULL; - const char *dir = r_config_get (core->config, "dir.types"); - char *out = r_parse_c_file (core->anal, path, dir, &error_msg); + const char *dir = rz_config_get (core->config, "dir.types"); + char *out = rz_parse_c_file (core->anal, path, dir, &error_msg); if (out) { - r_anal_save_parsed_type (core->anal, out); - r_core_cmd0 (core, ".ts*"); + rz_anal_save_parsed_type (core->anal, out); + rz_core_cmd0 (core, ".ts*"); free (out); } else { eprintf ("Parse error: %s\n", error_msg); } } else { - if (!r_core_cmd_file (core, home) && !r_core_cmd_file (core, path)) { - if (!r_core_cmd_file (core, _input + 3)) { + if (!rz_core_cmd_file (core, home) && !rz_core_cmd_file (core, path)) { + if (!rz_core_cmd_file (core, _input + 3)) { eprintf ("pfo: cannot open format file at '%s'\n", path); } } @@ -1450,29 +1450,29 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, free (path); free (tmp); } else { - RList *files; - RListIter *iter; + RzList *files; + RzListIter *iter; const char *fn; - char *home = r_str_home (R2_HOME_SDB_FORMAT R_SYS_DIR); + char *home = rz_str_home (R2_HOME_SDB_FORMAT R_SYS_DIR); if (home) { - files = r_sys_dir (home); - r_list_foreach (files, iter, fn) { + files = rz_sys_dir (home); + rz_list_foreach (files, iter, fn) { if (*fn && *fn != '.') { - r_cons_println (fn); + rz_cons_println (fn); } } - r_list_free (files); + rz_list_free (files); free (home); } - char *path = r_str_r2_prefix (R2_SDB_FORMAT R_SYS_DIR); + char *path = rz_str_rz_prefix (R2_SDB_FORMAT R_SYS_DIR); if (path) { - files = r_sys_dir (path); - r_list_foreach (files, iter, fn) { + files = rz_sys_dir (path); + rz_list_foreach (files, iter, fn) { if (*fn && *fn != '.') { - r_cons_println (fn); + rz_cons_println (fn); } } - r_list_free (files); + rz_list_free (files); free (path); } } @@ -1498,8 +1498,8 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, } core->print->reg = core->dbg->reg; - core->print->get_register = r_reg_get; - core->print->get_register_value = r_reg_get_value; + core->print->get_register = rz_reg_get; + core->print->get_register_value = rz_reg_get_value; int o_blocksize = core->blocksize; @@ -1511,7 +1511,7 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, SdbKv *kv; SdbList *sdbls = sdb_foreach_list (core->print->formats, true); ls_foreach (sdbls, iter, kv) { - r_cons_printf ("pf.%s %s\n", sdbkv_key (kv), sdbkv_value (kv)); + rz_cons_printf ("pf.%s %s\n", sdbkv_key (kv), sdbkv_value (kv)); } /* delete a format */ } else if (input[1] && input[2] == '-') { // "pf-" @@ -1568,9 +1568,9 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, const char *fmt = NULL; fmt = sdb_get (core->print->formats, name, NULL); if (fmt) { - int size = r_print_format_struct_size (core->print, fmt, mode, 0) + 10; + int size = rz_print_format_struct_size (core->print, fmt, mode, 0) + 10; if (size > core->blocksize) { - r_core_block_size (core, size); + rz_core_block_size (core, size); } } /* display a format */ @@ -1580,22 +1580,22 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, if (eq) { // Write mode (pf.field=value) *eq++ = 0; mode = R_PRINT_MUSTSET; - r_print_format (core->print, core->offset, + rz_print_format (core->print, core->offset, core->block, core->blocksize, name, mode, eq, dot); } else { - r_print_format (core->print, core->offset, + rz_print_format (core->print, core->offset, core->block, core->blocksize, name, mode, NULL, dot); } } else { - r_print_format (core->print, core->offset, + rz_print_format (core->print, core->offset, core->block, core->blocksize, name, mode, NULL, NULL); } free (name); } } else { /* This make sure the structure will be printed entirely */ - const char *fmt = r_str_trim_head_ro (input + 1); - int struct_sz = r_print_format_struct_size (core->print, fmt, mode, 0); + const char *fmt = rz_str_trim_head_ro (input + 1); + int struct_sz = rz_print_format_struct_size (core->print, fmt, mode, 0); int size = R_MAX (core->blocksize, struct_sz); ut8 *buf = calloc (1, size); if (!buf) { @@ -1607,25 +1607,25 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block, bool syntax_ok = true; char *args = strdup (fmt); if (!args) { - r_cons_printf ("Error: Mem Allocation."); + rz_cons_printf ("Error: Mem Allocation."); free (args); goto stage_left; } const char *arg1 = strtok (args, " "); - if (arg1 && r_str_isnumber (arg1)) { + if (arg1 && rz_str_isnumber (arg1)) { syntax_ok = false; - r_cons_printf ("Usage: pf [0|cnt][format-string]\n"); + rz_cons_printf ("Usage: pf [0|cnt][format-string]\n"); } free (args); if (syntax_ok) { - r_print_format (core->print, core->offset, + rz_print_format (core->print, core->offset, buf, size, fmt, mode, NULL, NULL); } free (buf); } stage_left: free (input); - r_core_block_size (core, o_blocksize); + rz_core_block_size (core, o_blocksize); } // > pxa @@ -1633,12 +1633,12 @@ stage_left: * the required length. This is because we supports colours, * that are 4 chars long. */ #define append(x, y) { strcat (x, y); x += strlen (y); } -static void annotated_hexdump(RCore *core, const char *str, int len) { - const int usecolor = r_config_get_i (core->config, "scr.color"); - int nb_cols = r_config_get_i (core->config, "hex.cols"); - core->print->use_comments = r_config_get_i (core->config, "hex.comments"); - int flagsz = r_config_get_i (core->config, "hex.flagsz"); - bool showSection = r_config_get_i (core->config, "hex.section"); +static void annotated_hexdump(RzCore *core, const char *str, int len) { + const int usecolor = rz_config_get_i (core->config, "scr.color"); + int nb_cols = rz_config_get_i (core->config, "hex.cols"); + core->print->use_comments = rz_config_get_i (core->config, "hex.comments"); + int flagsz = rz_config_get_i (core->config, "hex.flagsz"); + bool showSection = rz_config_get_i (core->config, "hex.section"); const ut8 *buf = core->block; ut64 addr = core->offset; int color_idx = 0; @@ -1650,12 +1650,12 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { ut8 ch = 0; char *colors[10] = {NULL}; for (i = 0; i < 10; i++) { - colors[i] = r_cons_rainbow_get (i, 10, false); + colors[i] = rz_cons_rainbow_get (i, 10, false); } const int col = core->print->col; - RFlagItem *flag, *current_flag = NULL; + RzFlagItem *flag, *current_flag = NULL; char **note; - int html = r_config_get_i (core->config, "scr.html"); + int html = rz_config_get_i (core->config, "scr.html"); int nb_cons_cols; bool compact = false; @@ -1710,13 +1710,13 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { sprintf (bytes + j + i, "%0X", i % 17); } if (usecolor) { - r_cons_strcat (Color_GREEN); - r_cons_strcat (bytes); - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_GREEN); + rz_cons_strcat (bytes); + rz_cons_strcat (Color_RESET); } else { - r_cons_strcat (bytes); + rz_cons_strcat (bytes); } - r_cons_newline (); + rz_cons_newline (); // hexdump for (i = 0; i < rows; i++) { @@ -1727,7 +1727,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { hascolor = false; ut64 ea = addr; if (core->print->pava) { - ut64 va = r_io_p2v (core->io, addr); + ut64 va = rz_io_p2v (core->io, addr); if (va != UT64_MAX) { ea = va; } @@ -1737,8 +1737,8 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { append (ebytes, core->cons->context->pal.offset); } if (showSection) { - const char * name = r_core_get_section_name (core, ea); - char *s = r_str_newf ("%20s ", name); + const char * name = rz_core_get_section_name (core, ea); + char *s = rz_str_newf ("%20s ", name); append (ebytes, s); free (s); } @@ -1753,12 +1753,12 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { R_FREE (note[j]); // TODO: in pava mode we should read addr or ea? // imho ea. but wat about hdrs and such - RIntervalNode *meta_node = r_meta_get_in (core->anal, ea + j, R_META_TYPE_FORMAT); - RAnalMetaItem *meta = meta_node ? meta_node->data : NULL; + RIntervalNode *meta_node = rz_meta_get_in (core->anal, ea + j, R_META_TYPE_FORMAT); + RzAnalMetaItem *meta = meta_node ? meta_node->data : NULL; if (meta && meta->type == R_META_TYPE_FORMAT && meta_node->start == addr + j) { - r_cons_printf (".format %s ; size=", meta->str); - r_core_cmdf (core, "pfs %s", meta->str); - r_core_cmdf (core, "pf %s @ 0x%08"PFMT64x, meta->str, meta_node->start); + rz_cons_printf (".format %s ; size=", meta->str); + rz_core_cmdf (core, "pfs %s", meta->str); + rz_core_cmdf (core, "pf %s @ 0x%08"PFMT64x, meta->str, meta_node->start); if (usecolor) { append (ebytes, Color_INVERT); append (echars, Color_INVERT); @@ -1769,14 +1769,14 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { meta = NULL; } // collect comments - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr + j); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr + j); if (comment) { - note[j] = r_str_newf (";", comment); + note[j] = rz_str_newf (";", comment); marks = true; } // collect flags - flag = r_flag_get_i (core->flags, addr + j); + flag = rz_flag_get_i (core->flags, addr + j); if (flag) { // Beginning of a flag if (flagsz) { fend = addr + flagsz; // core->blocksize; @@ -1784,13 +1784,13 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { fend = addr + j + flag->size; } free (note[j]); - note[j] = r_str_prepend (strdup (flag->name), "/"); + note[j] = rz_str_prepend (strdup (flag->name), "/"); marks = true; color_idx++; color_idx %= 10; current_flag = flag; if (showSection) { - r_cons_printf ("%20s ", ""); + rz_cons_printf ("%20s ", ""); } if (flag->offset == addr + j) { if (usecolor) { @@ -1812,7 +1812,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { } if (usecolor) { if (!setcolor) { - const char *bytecolor = r_print_byte_color (core->print, ch); + const char *bytecolor = rz_print_byte_color (core->print, ch); if (bytecolor) { append (ebytes, bytecolor); append (echars, bytecolor); @@ -1821,7 +1821,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { } else if (!hascolor) { hascolor = true; if (current_flag && current_flag->color) { - char *ansicolor = r_cons_pal_parse (current_flag->color, NULL); + char *ansicolor = rz_cons_pal_parse (current_flag->color, NULL); if (ansicolor) { append (ebytes, ansicolor); append (echars, ansicolor); @@ -1867,7 +1867,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { } } sprintf (ebytes, "%02x", ch); - // r_print_byte (core->print, "%02x ", j, ch); + // rz_print_byte (core->print, "%02x ", j, ch); ebytes += strlen (ebytes); if (hadflag) { if (usecolor) { @@ -1936,26 +1936,26 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { } out[out_sz - 1] = 0; if (hasline) { - r_cons_strcat (addrpad); - r_cons_strcat (out); - r_cons_newline (); + rz_cons_strcat (addrpad); + rz_cons_strcat (out); + rz_cons_newline (); } marks = false; free (out); } - r_cons_strcat (bytes); - r_cons_strcat (chars); + rz_cons_strcat (bytes); + rz_cons_strcat (chars); if (core->print->use_comments) { for (j = 0; j < nb_cols; j++) { const char *comment = core->print->get_comments (core->print->user, addr + j); if (comment) { - r_cons_printf (" ; %s", comment); + rz_cons_printf (" ; %s", comment); } } } - r_cons_newline (); + rz_cons_newline (); addr += nb_cols; } @@ -1970,7 +1970,7 @@ static void annotated_hexdump(RCore *core, const char *str, int len) { } } -R_API void r_core_print_examine(RCore *core, const char *str) { +RZ_API void rz_core_print_examine(RzCore *core, const char *str) { char cmd[128], *p; ut64 addr = core->offset; int size = (core->anal->bits / 4); @@ -1999,7 +1999,7 @@ R_API void r_core_print_examine(RCore *core, const char *str) { } if ((p = strchr (str, ' '))) { *p++ = 0; - addr = r_num_math (core->num, p); + addr = rz_num_math (core->num, p); } switch (*str) { case '?': @@ -2013,10 +2013,10 @@ R_API void r_core_print_examine(RCore *core, const char *str) { ); break; case 's': // "x/s" - r_core_cmdf (core, "psb %d @ 0x%"PFMT64x, count * size, addr); + rz_core_cmdf (core, "psb %d @ 0x%"PFMT64x, count * size, addr); break; case 'o': // "x/o" - r_core_cmdf (core, "pxo %d @ 0x%"PFMT64x, count * size, addr); + rz_core_cmdf (core, "pxo %d @ 0x%"PFMT64x, count * size, addr); break; case 'f': case 'A': // XXX (float in hex wtf) @@ -2028,34 +2028,34 @@ R_API void r_core_print_examine(RCore *core, const char *str) { cmd[n++] = 'f'; } cmd[n] = 0; - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); break; case 'x': switch (size) { default: case 1: - r_core_cmdf (core, "px %d @ 0x%"PFMT64x, count, addr); + rz_core_cmdf (core, "px %d @ 0x%"PFMT64x, count, addr); break; case 2: - r_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, + rz_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, 'h', count * 2, addr); break; case 4: - r_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, + rz_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, 'w', count * 4, addr); break; case 8: - r_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, + rz_core_cmdf (core, "px%c %d @ 0x%"PFMT64x, 'q', count * 8, addr); break; } break; case 'a': case 'd': - r_core_cmdf (core, "pxw %d @ 0x%"PFMT64x, count * size, addr); + rz_core_cmdf (core, "pxw %d @ 0x%"PFMT64x, count * size, addr); break; case 'i': - r_core_cmdf (core, "pid %d @ 0x%"PFMT64x, count, addr); + rz_core_cmdf (core, "pid %d @ 0x%"PFMT64x, count, addr); break; } } @@ -2067,7 +2067,7 @@ struct count_pz_t { int *ret; }; -static bool count_pzs(RFlagItem *fi, void *u) { +static bool count_pzs(RzFlagItem *fi, void *u) { struct count_pz_t *user = (struct count_pz_t *)u; if (fi->space == user->flagspace && ((user->addr <= fi->offset && fi->offset < user->addr + user->size) || @@ -2077,7 +2077,7 @@ static bool count_pzs(RFlagItem *fi, void *u) { return true; } -static bool count_pzf(RFlagItem *fi, void *u) { +static bool count_pzf(RzFlagItem *fi, void *u) { struct count_pz_t *user = (struct count_pz_t *)u; if (fi->offset <= user->addr && user->addr < fi->offset + fi->size) { (*user->ret)++; @@ -2086,24 +2086,24 @@ static bool count_pzf(RFlagItem *fi, void *u) { } static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size) { - RCore *core = (RCore *) user; + RzCore *core = (RzCore *) user; int j, ret = 0; struct count_pz_t u; switch (mode) { case 'a': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); int value = 0; if (fcn) { - value = r_list_length (fcn->bbs); + value = rz_list_length (fcn->bbs); } return value; } break; case 'A': { - RCoreAnalStats *as = r_core_anal_get_stats (core, addr, addr + size * 2, size); + RzCoreAnalStats *as = rz_core_anal_get_stats (core, addr, addr + size * 2, size); int i; int value = 0; for (i = 0; i < 1; i++) { @@ -2116,7 +2116,7 @@ static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 si value += as->block[i].blocks; value *= 20; } - r_core_anal_stats_free (as); + rz_core_anal_stats_free (as); return value; } break; @@ -2128,12 +2128,12 @@ static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 si } break; case 'e': // "pze" - ret = (ut8) (r_hash_entropy_fraction (bufz, size) * 255); + ret = (ut8) (rz_hash_entropy_fraction (bufz, size) * 255); break; case 'f': // "pzf" u.addr = addr; u.ret = &ret; - r_flag_foreach (core->flags, count_pzf, &u); + rz_flag_foreach (core->flags, count_pzf, &u); break; case 'F': // "pzF" for (j = 0; j < size; j++) { @@ -2150,11 +2150,11 @@ static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 si } break; case 's': // "pzs" - u.flagspace = r_flag_space_get (core->flags, R_FLAGS_FS_STRINGS); + u.flagspace = rz_flag_space_get (core->flags, R_FLAGS_FS_STRINGS); u.addr = addr; u.size = size; u.ret = &ret; - r_flag_foreach (core->flags, count_pzs, &u); + rz_flag_foreach (core->flags, count_pzs, &u); break; case 'h': // "pzh" head default: @@ -2163,42 +2163,42 @@ static int printzoomcallback(void *user, int mode, ut64 addr, ut8 *bufz, ut64 si return ret; } -R_API void r_core_print_cmp(RCore *core, ut64 from, ut64 to) { +RZ_API void rz_core_print_cmp(RzCore *core, ut64 from, ut64 to) { long int delta = 0; int col = core->cons->columns > 123; ut8 *b = malloc (core->blocksize); ut64 addr = core->offset; memset (b, 0xff, core->blocksize); delta = addr - from; - r_io_read_at (core->io, to + delta, b, core->blocksize); - r_print_hexdiff (core->print, core->offset, core->block, + rz_io_read_at (core->io, to + delta, b, core->blocksize); + rz_print_hexdiff (core->print, core->offset, core->block, to + delta, b, core->blocksize, col); free (b); } -static void cmd_print_pwn(const RCore *core) { - r_cons_printf ("easter egg license has expired\n"); +static void cmd_print_pwn(const RzCore *core) { + rz_cons_printf ("easter egg license has expired\n"); } -static int cmd_print_pxA(RCore *core, int len, const char *input) { - RConsPrintablePalette *pal = &core->cons->context->pal; +static int cmd_print_pxA(RzCore *core, int len, const char *input) { + RzConsPrintablePalette *pal = &core->cons->context->pal; int show_offset = true; - int cols = r_config_get_i (core->config, "hex.cols"); - int show_color = r_config_get_i (core->config, "scr.color"); - int onechar = r_config_get_i (core->config, "hex.onechar"); - bool hex_offset = r_config_get_i (core->config, "hex.offset"); + int cols = rz_config_get_i (core->config, "hex.cols"); + int show_color = rz_config_get_i (core->config, "scr.color"); + int onechar = rz_config_get_i (core->config, "hex.onechar"); + bool hex_offset = rz_config_get_i (core->config, "hex.offset"); int bgcolor_in_heap = false; bool show_cursor = core->print->cur_enabled; char buf[2]; char *bgcolor, *fgcolor, *text; ut64 i, c, oi; - RAnalOp op; + RzAnalOp op; ut8 *data; int datalen; if (*input == 'v') { datalen = cols * 8 * core->cons->rows; data = malloc (datalen); - r_io_read_at (core->io, core->offset, data, datalen); + rz_io_read_at (core->io, core->offset, data, datalen); len = datalen; } else { data = core->block; @@ -2227,11 +2227,11 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { for (oi = i = c = 0; i < len; c++) { if (i && (cols != 0) && !(c % cols)) { show_offset = true; - r_cons_printf (" %d\n", i - oi); + rz_cons_printf (" %d\n", i - oi); oi = i; } if (show_offset && hex_offset) { - r_cons_printf ("0x%08"PFMT64x " ", core->offset + i); + rz_cons_printf ("0x%08"PFMT64x " ", core->offset + i); show_offset = false; } if (bgcolor_in_heap) { @@ -2241,7 +2241,7 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { bgcolor = Color_BGBLACK; fgcolor = Color_WHITE; text = NULL; - if (r_anal_op (core->anal, &op, core->offset + i, data + i, len - i, R_ANAL_OP_MASK_BASIC) <= 0) { + if (rz_anal_op (core->anal, &op, core->offset + i, data + i, len - i, R_ANAL_OP_MASK_BASIC) <= 0) { op.type = 0; bgcolor = Color_BGRED; op.size = 1; @@ -2272,72 +2272,72 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { case R_ANAL_OP_TYPE_SWI: case R_ANAL_OP_TYPE_NEW: // bgcolor = Color_BGRED; - bgcolor = pal->trap; // r_cons_swap_ground (pal->trap); + bgcolor = pal->trap; // rz_cons_swap_ground (pal->trap); fgcolor = Color_WHITE; text = "$$"; break; case R_ANAL_OP_TYPE_POP: text = "<-"; - bgcolor = r_cons_swap_ground (pal->pop); + bgcolor = rz_cons_swap_ground (pal->pop); bgcolor_in_heap = true; fgcolor = Color_WHITE; break; case R_ANAL_OP_TYPE_NOP: fgcolor = Color_WHITE; - bgcolor = r_cons_swap_ground (pal->nop); + bgcolor = rz_cons_swap_ground (pal->nop); bgcolor_in_heap = true; text = ".."; break; case R_ANAL_OP_TYPE_MUL: fgcolor = Color_BLACK; - bgcolor = r_cons_swap_ground (pal->math); + bgcolor = rz_cons_swap_ground (pal->math); bgcolor_in_heap = true; text = "_*"; break; case R_ANAL_OP_TYPE_DIV: - bgcolor = r_cons_swap_ground (pal->math); + bgcolor = rz_cons_swap_ground (pal->math); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "_/"; break; case R_ANAL_OP_TYPE_AND: - bgcolor = r_cons_swap_ground (pal->bin); + bgcolor = rz_cons_swap_ground (pal->bin); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "_&"; break; case R_ANAL_OP_TYPE_XOR: - bgcolor = r_cons_swap_ground (pal->bin); + bgcolor = rz_cons_swap_ground (pal->bin); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "_^"; break; case R_ANAL_OP_TYPE_OR: - bgcolor = r_cons_swap_ground (pal->bin); + bgcolor = rz_cons_swap_ground (pal->bin); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "_|"; break; case R_ANAL_OP_TYPE_SHR: - bgcolor = r_cons_swap_ground (pal->bin); + bgcolor = rz_cons_swap_ground (pal->bin); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = ">>"; break; case R_ANAL_OP_TYPE_SHL: - bgcolor = r_cons_swap_ground (pal->bin); + bgcolor = rz_cons_swap_ground (pal->bin); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "<<"; break; case R_ANAL_OP_TYPE_SUB: - bgcolor = r_cons_swap_ground (pal->math); + bgcolor = rz_cons_swap_ground (pal->math); bgcolor_in_heap = true; fgcolor = Color_WHITE; text = "--"; break; case R_ANAL_OP_TYPE_ADD: - bgcolor = r_cons_swap_ground (pal->math); + bgcolor = rz_cons_swap_ground (pal->math); bgcolor_in_heap = true; fgcolor = Color_WHITE; text = "++"; @@ -2348,14 +2348,14 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { case R_ANAL_OP_TYPE_RJMP: case R_ANAL_OP_TYPE_IRJMP: case R_ANAL_OP_TYPE_MJMP: - bgcolor = r_cons_swap_ground (pal->jmp); + bgcolor = rz_cons_swap_ground (pal->jmp); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "_J"; break; case R_ANAL_OP_TYPE_CJMP: case R_ANAL_OP_TYPE_UCJMP: - bgcolor = r_cons_swap_ground (pal->cjmp); + bgcolor = rz_cons_swap_ground (pal->cjmp); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "cJ"; @@ -2366,20 +2366,20 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { case R_ANAL_OP_TYPE_RCALL: case R_ANAL_OP_TYPE_IRCALL: case R_ANAL_OP_TYPE_UCCALL: - bgcolor = r_cons_swap_ground (pal->call); + bgcolor = rz_cons_swap_ground (pal->call); bgcolor_in_heap = true; fgcolor = Color_WHITE; text = "_C"; break; case R_ANAL_OP_TYPE_ACMP: case R_ANAL_OP_TYPE_CMP: - bgcolor = r_cons_swap_ground (pal->cmp); + bgcolor = rz_cons_swap_ground (pal->cmp); bgcolor_in_heap = true; fgcolor = Color_BLACK; text = "=="; break; case R_ANAL_OP_TYPE_RET: - bgcolor = r_cons_swap_ground (pal->ret); + bgcolor = rz_cons_swap_ground (pal->ret); bgcolor_in_heap = true; fgcolor = Color_WHITE; text = "_R"; @@ -2387,7 +2387,7 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { case -1: case R_ANAL_OP_TYPE_ILL: case R_ANAL_OP_TYPE_UNK: - bgcolor = r_cons_swap_ground (pal->invalid); + bgcolor = rz_cons_swap_ground (pal->invalid); bgcolor_in_heap = true; fgcolor = Color_WHITE; text = "XX"; @@ -2402,7 +2402,7 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { int opsz = R_MAX (op.size, 1); if (show_cursor) { if (core->print->cur >= i && core->print->cur < i + opsz) { - r_cons_invert (1, 1); + rz_cons_invert (1, 1); } } if (onechar) { @@ -2422,23 +2422,23 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { if (!text) { text = " "; } - r_cons_printf ("%s%s%s\x1b[0m", bgcolor, fgcolor, text); + rz_cons_printf ("%s%s%s\x1b[0m", bgcolor, fgcolor, text); } else { if (text) { - r_cons_print (text); + rz_cons_print (text); } else { - r_cons_print (" "); + rz_cons_print (" "); } } if (show_cursor) { if (core->print->cur >= i && core->print->cur < i + opsz) { - r_cons_invert (0, 1); + rz_cons_invert (0, 1); } } i += opsz; - r_anal_op_fini (&op); + rz_anal_op_fini (&op); } - r_cons_printf (" %d\n", i - oi); + rz_cons_printf (" %d\n", i - oi); if (bgcolor_in_heap) { free (bgcolor); } @@ -2449,7 +2449,7 @@ static int cmd_print_pxA(RCore *core, int len, const char *input) { return true; } -static void cmd_print_op(RCore *core, const char *input) { +static void cmd_print_op(RzCore *core, const char *input) { ut8 *buf; if (!input[0]) return; @@ -2466,46 +2466,46 @@ static void cmd_print_op(RCore *core, const char *input) { case '2': case '4': if (input[2]) { // parse val from arg - buf = r_core_transform_op (core, input+3, input[1]); + buf = rz_core_transform_op (core, input+3, input[1]); } else { // use clipboard instead of val - buf = r_core_transform_op (core, NULL, input[1]); + buf = rz_core_transform_op (core, NULL, input[1]); } break; case 'n': - buf = r_core_transform_op (core, "ff", 'x'); + buf = rz_core_transform_op (core, "ff", 'x'); break; case '\0': case '?': default: - r_core_cmd_help (core, help_msg_po); + rz_core_cmd_help (core, help_msg_po); return; } if (buf) { - r_print_hexdump(core->print, core->offset, buf, + rz_print_hexdump(core->print, core->offset, buf, core->blocksize, 16, 1, 1); free (buf); } } -static void printraw(RCore *core, int len, int mode) { +static void printraw(RzCore *core, int len, int mode) { int obsz = core->blocksize; int restore_obsz = 0; if (len != obsz) { - if (!r_core_block_size (core, len)) { + if (!rz_core_block_size (core, len)) { len = core->blocksize; } else { restore_obsz = 1; } } - r_print_raw (core->print, core->offset, core->block, len, mode); + rz_print_raw (core->print, core->offset, core->block, len, mode); if (restore_obsz) { - (void) r_core_block_size (core, obsz); + (void) rz_core_block_size (core, obsz); } core->cons->newline = core->cmd_in_backticks ? false : true; } -static void _handle_call(RCore *core, char *line, char **str) { - r_return_if_fail (core && line && str && core->rasm && core->rasm->cur); +static void _handle_call(RzCore *core, char *line, char **str) { + rz_return_if_fail (core && line && str && core->rasm && core->rasm->cur); if (strstr (core->rasm->cur->arch, "x86")) { *str = strstr (line, "call "); } else if (strstr (core->rasm->cur->arch, "arm")) { @@ -2527,62 +2527,62 @@ static void _handle_call(RCore *core, char *line, char **str) { } // TODO: this is just a PoC, the disasm loop should be rewritten -// TODO: this is based on string matching, it should be written upon RAnalOp to know +// TODO: this is based on string matching, it should be written upon RzAnalOp to know // when we have a call and such -static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { +static void disasm_strings(RzCore *core, const char *input, RzAnalFunction *fcn) { const char *linecolor = NULL; char *ox, *qo, *string = NULL; char *line, *s, *str, *string2 = NULL; char *switchcmp = NULL; - int i, count, use_color = r_config_get_i (core->config, "scr.color"); - bool show_comments = r_config_get_i (core->config, "asm.comments"); - bool show_offset = r_config_get_i (core->config, "asm.offset"); - bool asm_tabs = r_config_get_i (core->config, "asm.tabs"); - bool scr_html = r_config_get_i (core->config, "scr.html"); - bool asm_dwarf = r_config_get_i (core->config, "asm.dwarf"); - bool asm_flags = r_config_get_i (core->config, "asm.flags"); - bool asm_cmt_right = r_config_get_i (core->config, "asm.cmt.right"); - bool asm_emu = r_config_get_i (core->config, "asm.emu"); - bool emu_str = r_config_get_i (core->config, "emu.str"); - r_config_set_i (core->config, "emu.str", true); - RConsPrintablePalette *pal = &core->cons->context->pal; + int i, count, use_color = rz_config_get_i (core->config, "scr.color"); + bool show_comments = rz_config_get_i (core->config, "asm.comments"); + bool show_offset = rz_config_get_i (core->config, "asm.offset"); + bool asm_tabs = rz_config_get_i (core->config, "asm.tabs"); + bool scr_html = rz_config_get_i (core->config, "scr.html"); + bool asm_dwarf = rz_config_get_i (core->config, "asm.dwarf"); + bool asm_flags = rz_config_get_i (core->config, "asm.flags"); + bool asm_cmt_right = rz_config_get_i (core->config, "asm.cmt.right"); + bool asm_emu = rz_config_get_i (core->config, "asm.emu"); + bool emu_str = rz_config_get_i (core->config, "emu.str"); + rz_config_set_i (core->config, "emu.str", true); + RzConsPrintablePalette *pal = &core->cons->context->pal; // force defaults - r_config_set_i (core->config, "asm.offset", true); - r_config_set_i (core->config, "asm.dwarf", true); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); - r_config_set_i (core->config, "asm.tabs", 0); - r_config_set_i (core->config, "scr.html", 0); - r_config_set_i (core->config, "asm.cmt.right", true); + rz_config_set_i (core->config, "asm.offset", true); + rz_config_set_i (core->config, "asm.dwarf", true); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (core->config, "asm.tabs", 0); + rz_config_set_i (core->config, "scr.html", 0); + rz_config_set_i (core->config, "asm.cmt.right", true); - r_cons_push (); + rz_cons_push (); line = NULL; s = NULL; if (!strncmp (input, "dsb", 3)) { - RAnalBlock *bb = r_anal_bb_from_offset (core->anal, core->offset); + RzAnalBlock *bb = rz_anal_bb_from_offset (core->anal, core->offset); if (bb) { - line = s = r_core_cmd_strf (core, "pD %"PFMT64u" @ 0x%08"PFMT64x, bb->size, bb->addr); + line = s = rz_core_cmd_strf (core, "pD %"PFMT64u" @ 0x%08"PFMT64x, bb->size, bb->addr); } } else if (!strncmp (input, "dsf", 3) || !strncmp (input, "dsr", 3)) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - line = s = r_core_cmd_str (core, "pdr"); + line = s = rz_core_cmd_str (core, "pdr"); } else { eprintf ("Cannot find function.\n"); - r_config_set_i (core->config, "scr.color", use_color); - r_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); + rz_config_set_i (core->config, "scr.color", use_color); + rz_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); goto restore_conf; } } else if (!strncmp (input, "ds ", 3)) { - line = s = r_core_cmd_strf (core, "pD %s", input + 3); + line = s = rz_core_cmd_strf (core, "pD %s", input + 3); } else { - line = s = r_core_cmd_str (core, "pd"); + line = s = rz_core_cmd_str (core, "pd"); } - r_cons_pop (); + rz_cons_pop (); - r_config_set_i (core->config, "scr.html", scr_html); - r_config_set_i (core->config, "scr.color", use_color); - r_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); - count = r_str_split (s, '\n'); + rz_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "scr.color", use_color); + rz_config_set_i (core->config, "asm.cmt.right", asm_cmt_right); + count = rz_str_split (s, '\n'); if (!line || !*line || count < 1) { // R_FREE (s); goto restore_conf; @@ -2593,7 +2593,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { qo = strchr (line, '\"'); R_FREE (string); if (ox) { - addr = r_num_get (NULL, ox); + addr = rz_num_get (NULL, ox); } if (qo) { char *qoe = strrchr (qo + 1, '"'); @@ -2624,7 +2624,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { actual_len++; } if (actual_len > 2) { - string = r_str_ndup (qo, raw_len + 2); + string = rz_str_ndup (qo, raw_len + 2); } linecolor = R_CONS_COLOR (comment); } @@ -2639,16 +2639,16 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { qoe = strchr (ox + 3, '\x1b'); } int len = qoe? qoe - ox: strlen (ox + 3); - string2 = r_str_ndup (ox + 2, len - 1); - if (r_num_get (NULL, string2) < 0x100) { + string2 = rz_str_ndup (ox + 2, len - 1); + if (rz_num_get (NULL, string2) < 0x100) { R_FREE (string2); } } if (asm_flags) { str = strstr (line, ";-- "); if (str) { - if (!r_str_startswith (str + 4, "case")) { - r_cons_printf ("%s\n", str); + if (!rz_str_startswith (str + 4, "case")) { + rz_cons_printf ("%s\n", str); } } } @@ -2670,9 +2670,9 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { } #else if (strchr (line, ';')) { - const char *dot = r_str_rchr (line, NULL, '.'); + const char *dot = rz_str_rchr (line, NULL, '.'); if (dot) { - const char *o = r_str_rchr (line, dot, ' '); + const char *o = rz_str_rchr (line, dot, ' '); if (o) { str = (char*)o; } else { @@ -2695,7 +2695,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { } if (qoe) { free (string2); - string2 = r_str_ndup (str + 1, qoe - str - 1); + string2 = rz_str_ndup (str + 1, qoe - str - 1); } else { free (string2); string2 = strdup (str + 1); @@ -2719,7 +2719,7 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { char *qoe = strchr (str, ';'); if (qoe) { char* t = str; - str = r_str_ndup (str, qoe - str); + str = rz_str_ndup (str, qoe - str); free (t); } } @@ -2737,23 +2737,23 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { if (addr != UT64_MAX) { const char *str = NULL; if (show_comments) { - char *comment = r_core_anal_get_comments (core, addr); + char *comment = rz_core_anal_get_comments (core, addr); if (comment) { if (switchcmp) { if (strcmp (comment, switchcmp)) { if (show_offset) { - r_cons_printf ("%s0x%08"PFMT64x" ", use_color? pal->offset: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x" ", use_color? pal->offset: "", addr); } - r_cons_printf ("%s%s\n", use_color? pal->comment: "", comment); + rz_cons_printf ("%s%s\n", use_color? pal->comment: "", comment); } } else { if (show_offset) { - r_cons_printf ("%s0x%08"PFMT64x" ", use_color? pal->offset: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x" ", use_color? pal->offset: "", addr); } - r_cons_printf ("%s%s\n", use_color? pal->comment: "", comment); + rz_cons_printf ("%s%s\n", use_color? pal->comment: "", comment); } - if (r_str_startswith (comment, "switch table")) { + if (rz_str_startswith (comment, "switch table")) { switchcmp = strdup (comment); } R_FREE (comment); @@ -2763,22 +2763,22 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { if (fcn) { bool label = false; /* show labels, basic blocks and (conditional) branches */ - RAnalBlock *bb; - RListIter *iter; - r_list_foreach (fcn->bbs, iter, bb) { + RzAnalBlock *bb; + RzListIter *iter; + rz_list_foreach (fcn->bbs, iter, bb) { if (addr == bb->jump) { if (show_offset) { - r_cons_printf ("%s0x%08"PFMT64x ":\n", use_color? Color_YELLOW: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x ":\n", use_color? Color_YELLOW: "", addr); } label = true; break; } } if (!label && strstr (line, "->")) { - r_cons_printf ("%s0x%08"PFMT64x ":\n", use_color? Color_YELLOW: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x ":\n", use_color? Color_YELLOW: "", addr); } if (strstr (line, "=<")) { - r_list_foreach (fcn->bbs, iter, bb) { + rz_list_foreach (fcn->bbs, iter, bb) { if (addr >= bb->addr && addr < bb->addr + bb->size) { const char *op; if (use_color) { @@ -2787,9 +2787,9 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { op = (bb->fail == UT64_MAX)? "jmp": "cjmp"; } if (show_offset) { - r_cons_printf ("%s0x%08"PFMT64x" "Color_RESET, use_color? pal->offset: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x" "Color_RESET, use_color? pal->offset: "", addr); } - r_cons_printf ("%s 0x%08"PFMT64x "%s\n", + rz_cons_printf ("%s 0x%08"PFMT64x "%s\n", op, bb->jump, use_color? Color_RESET: ""); break; } @@ -2803,10 +2803,10 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { if (string2 && !strncmp (string2, "0x", 2)) { str = string2; } - ut64 ptr = r_num_math (NULL, str); - RFlagItem *flag = NULL; + ut64 ptr = rz_num_math (NULL, str); + RzFlagItem *flag = NULL; if (str) { - flag = r_core_flag_get_by_spaces (core->flags, ptr); + flag = rz_core_flag_get_by_spaces (core->flags, ptr); } if (!flag) { if (string && !strncmp (string, "0x", 2)) { @@ -2817,25 +2817,25 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { } } if (string && addr != UT64_MAX && addr != UT32_MAX) { - r_str_trim (string); + rz_str_trim (string); if (string2) { - r_str_trim (string2); + rz_str_trim (string2); } //// TODO implememnt avoid duplicated strings // eprintf ("---> %s\n", string); if (use_color) { if (show_offset) { - r_cons_printf ("%s0x%08"PFMT64x" "Color_RESET, use_color? pal->offset: "", addr); + rz_cons_printf ("%s0x%08"PFMT64x" "Color_RESET, use_color? pal->offset: "", addr); } - r_cons_printf ("%s%s%s%s%s%s%s\n", + rz_cons_printf ("%s%s%s%s%s%s%s\n", linecolor? linecolor: "", string2? string2: "", string2? " ": "", string, flag? " ": "", flag? flag->name: "", Color_RESET); } else { if (show_offset) { - r_cons_printf ("0x%08"PFMT64x" ", addr); + rz_cons_printf ("0x%08"PFMT64x" ", addr); } - r_cons_printf ("%s%s%s%s%s\n", + rz_cons_printf ("%s%s%s%s%s\n", string2? string2: "", string2? " ": "", string, flag? " ": "", flag? flag->name: ""); } @@ -2844,40 +2844,40 @@ static void disasm_strings(RCore *core, const char *input, RAnalFunction *fcn) { } line += strlen (line) + 1; } - // r_cons_printf ("%s", s); + // rz_cons_printf ("%s", s); free (string2); free (string); free (s); free (str); free (switchcmp); restore_conf: - r_config_set_i (core->config, "asm.offset", show_offset); - r_config_set_i (core->config, "asm.dwarf", asm_dwarf); - r_config_set_i (core->config, "asm.tabs", asm_tabs); - r_config_set_i (core->config, "scr.html", scr_html); - r_config_set_i (core->config, "asm.emu", asm_emu); - r_config_set_i (core->config, "emu.str", emu_str); + rz_config_set_i (core->config, "asm.offset", show_offset); + rz_config_set_i (core->config, "asm.dwarf", asm_dwarf); + rz_config_set_i (core->config, "asm.tabs", asm_tabs); + rz_config_set_i (core->config, "scr.html", scr_html); + rz_config_set_i (core->config, "asm.emu", asm_emu); + rz_config_set_i (core->config, "emu.str", emu_str); } static void algolist(int mode) { int i; for (i = 0; i < R_HASH_NBITS; i++) { ut64 bits = 1ULL << i; - const char *name = r_hash_name (bits); + const char *name = rz_hash_name (bits); if (name && *name) { if (mode) { - r_cons_println (name); + rz_cons_println (name); } else { - r_cons_printf ("%s ", name); + rz_cons_printf ("%s ", name); } } } if (!mode) { - r_cons_newline (); + rz_cons_newline (); } } -static bool cmd_print_ph(RCore *core, const char *input) { +static bool cmd_print_ph(RzCore *core, const char *input) { char algo[128]; ut32 osize = 0, len = core->blocksize; const char *ptr; @@ -2891,30 +2891,30 @@ static bool cmd_print_ph(RCore *core, const char *input) { algolist (0); return true; } - input = r_str_trim_head_ro (input); + input = rz_str_trim_head_ro (input); ptr = strchr (input, ' '); sscanf (input, "%31s", algo); - if (ptr && ptr[1]) { // && r_num_is_valid_input (core->num, ptr + 1)) { - int nlen = r_num_math (core->num, ptr + 1); + if (ptr && ptr[1]) { // && rz_num_is_valid_input (core->num, ptr + 1)) { + int nlen = rz_num_math (core->num, ptr + 1); if (nlen > 0) { len = nlen; } osize = core->blocksize; if (nlen > core->blocksize) { - r_core_block_size (core, nlen); + rz_core_block_size (core, nlen); if (nlen != core->blocksize) { eprintf ("Invalid block size\n"); - r_core_block_size (core, osize); + rz_core_block_size (core, osize); return false; } - r_core_block_read (core); + rz_core_block_read (core); } } else if (!ptr || !*(ptr + 1)) { osize = len; } /* TODO: Simplify this spaguetti monster */ while (osize > 0 && hash_handlers[pos].name) { - if (!r_str_ccmp (hash_handlers[pos].name, input, ' ')) { + if (!rz_str_ccmp (hash_handlers[pos].name, input, ' ')) { hash_handlers[pos].handler (core->block, len); handled_cmd = true; break; @@ -2922,13 +2922,13 @@ static bool cmd_print_ph(RCore *core, const char *input) { pos++; } if (osize) { - r_core_block_size (core, osize); + rz_core_block_size (core, osize); } return handled_cmd; } // XXX blocksize is missing -static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { +static void cmd_print_pv(RzCore *core, const char *input, bool useBytes) { const char *stack[] = { "ret", "arg0", "arg1", "arg2", "arg3", "arg4", NULL }; @@ -2964,11 +2964,11 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { } const char *arg = strchr (input, ' '); if (arg) { - arg = r_str_trim_head_ro (arg + 1); + arg = rz_str_trim_head_ro (arg + 1); } else { arg = input; } - st64 repeat = r_num_math (core->num, arg); + st64 repeat = rz_num_math (core->num, arg); if (repeat < 0) { repeat = 1; } @@ -2985,7 +2985,7 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { if (input[1]) { input++; } else { - r_core_cmdf (core, "ps"); + rz_core_cmdf (core, "ps"); break; } /* fallthrough */ @@ -2993,9 +2993,9 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { for (i = 0; stack[i]; i++) { if (!strcmp (input + 1, stack[i])) { if (type == 'z') { - r_core_cmdf (core, "ps @ [`drn sp`+%d]", n * i); + rz_core_cmdf (core, "ps @ [`drn sp`+%d]", n * i); } else { - r_core_cmdf (core, "?v [`drn sp`+%d]", n * i); + rz_core_cmdf (core, "?v [`drn sp`+%d]", n * i); } } } @@ -3007,33 +3007,33 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { ut8 *b = block + (i * n); switch (n) { case 1: - r_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, r_read_ble8 (b)); + rz_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, rz_read_ble8 (b)); break; case 2: - r_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, r_read_ble16 (b, be)); + rz_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, rz_read_ble16 (b, be)); break; case 4: - r_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, r_read_ble32 (b, be)); + rz_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, rz_read_ble32 (b, be)); break; case 8: default: - r_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, r_read_ble64 (b, be)); + rz_cons_printf ("f pval.0x%08"PFMT64x"=%"PFMT64d"\n", at, rz_read_ble64 (b, be)); break; } } } break; case 'j': { // "pvj" - r_cons_printf ("["); + rz_cons_printf ("["); ut64 at = core->offset; ut64 oldAt = at; for (i = 0; i < repeat; i++) { if (i > 0) { - r_cons_printf (","); + rz_cons_printf (","); } - r_core_seek (core, at, false); - char *str = r_core_cmd_str (core, "ps"); - r_str_trim (str); + rz_core_seek (core, at, false); + char *str = rz_core_cmd_str (core, "ps"); + rz_str_trim (str); char *p = str; if (p) { while (*p) { @@ -3043,46 +3043,46 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { p++; } } - // r_num_get is gonna use a dangling pointer since the internal - // token that RNum holds ([$$]) has been already freed by r_core_cmd_str - // r_num_math reload a new token so the dangling pointer is gone + // rz_num_get is gonna use a dangling pointer since the internal + // token that RNum holds ([$$]) has been already freed by rz_core_cmd_str + // rz_num_math reload a new token so the dangling pointer is gone switch (n) { case 1: - pj_fmt (r_cons_printf, "{'value':%i,'string':%s}", - r_read_ble8 (block), str); + pj_fmt (rz_cons_printf, "{'value':%i,'string':%s}", + rz_read_ble8 (block), str); break; case 2: - pj_fmt (r_cons_printf, "{'value':%i,'string':%s}", - r_read_ble16 (block, core->print->big_endian), str); + pj_fmt (rz_cons_printf, "{'value':%i,'string':%s}", + rz_read_ble16 (block, core->print->big_endian), str); break; case 4: - pj_fmt (r_cons_printf, "{'value':%n,'string':%s}", - (ut64)r_read_ble32 (block, core->print->big_endian), str); + pj_fmt (rz_cons_printf, "{'value':%n,'string':%s}", + (ut64)rz_read_ble32 (block, core->print->big_endian), str); break; case 8: - pj_fmt (r_cons_printf, "{'value':%n,'string':%s}", - r_read_ble64 (block, core->print->big_endian), str); + pj_fmt (rz_cons_printf, "{'value':%n,'string':%s}", + rz_read_ble64 (block, core->print->big_endian), str); break; default: - pj_fmt (r_cons_printf, "{'value':%n,'string':%s}", - r_read_ble64 (block, core->print->big_endian), str); + pj_fmt (rz_cons_printf, "{'value':%n,'string':%s}", + rz_read_ble64 (block, core->print->big_endian), str); break; } free (str); at += n; } - r_cons_printf ("]\n"); - r_core_seek (core, oldAt, false); + rz_cons_printf ("]\n"); + rz_core_seek (core, oldAt, false); break; } case '?': // "pv?" - r_core_cmd_help (core, help_msg_pv); + rz_core_cmd_help (core, help_msg_pv); break; default: do { repeat--; if (block + 8 >= block_end) { - eprintf ("Truncated. TODO: use r_io_read apis insgtead of depending on blocksize\n"); + eprintf ("Truncated. TODO: use rz_io_read apis insgtead of depending on blocksize\n"); break; } ut64 v; @@ -3091,32 +3091,32 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { } switch (n) { case 1: - v = r_read_ble8 (block); - r_cons_printf ("0x%02" PFMT64x "\n", v); + v = rz_read_ble8 (block); + rz_cons_printf ("0x%02" PFMT64x "\n", v); block += 1; break; case 2: - v = r_read_ble16 (block, core->print->big_endian); - r_cons_printf ("0x%04" PFMT64x "\n", v); + v = rz_read_ble16 (block, core->print->big_endian); + rz_cons_printf ("0x%04" PFMT64x "\n", v); block += 2; break; case 4: - v = r_read_ble32 (block, core->print->big_endian); - r_cons_printf ("0x%08" PFMT64x "\n", v); + v = rz_read_ble32 (block, core->print->big_endian); + rz_cons_printf ("0x%08" PFMT64x "\n", v); block += 4; break; case 8: - v = r_read_ble64 (block, core->print->big_endian); - r_cons_printf ("0x%016" PFMT64x "\n", v); + v = rz_read_ble64 (block, core->print->big_endian); + rz_cons_printf ("0x%016" PFMT64x "\n", v); block += 8; break; default: - v = r_read_ble64 (block, core->print->big_endian); + v = rz_read_ble64 (block, core->print->big_endian); switch (core->rasm->bits / 8) { - case 1: r_cons_printf ("0x%02" PFMT64x "\n", v & UT8_MAX); break; - case 2: r_cons_printf ("0x%04" PFMT64x "\n", v & UT16_MAX); break; - case 4: r_cons_printf ("0x%08" PFMT64x "\n", v & UT32_MAX); break; - case 8: r_cons_printf ("0x%016" PFMT64x "\n", v & UT64_MAX); break; + case 1: rz_cons_printf ("0x%02" PFMT64x "\n", v & UT8_MAX); break; + case 2: rz_cons_printf ("0x%04" PFMT64x "\n", v & UT16_MAX); break; + case 4: rz_cons_printf ("0x%08" PFMT64x "\n", v & UT32_MAX); break; + case 8: rz_cons_printf ("0x%016" PFMT64x "\n", v & UT64_MAX); break; default: break; } block += core->rasm->bits / 8; @@ -3127,15 +3127,15 @@ static void cmd_print_pv(RCore *core, const char *input, bool useBytes) { } } -static bool cmd_print_blocks(RCore *core, const char *input) { +static bool cmd_print_blocks(RzCore *core, const char *input) { bool result = false; char mode = input[0]; - RList *list = NULL; - RCoreAnalStats *as = NULL; + RzList *list = NULL; + RzCoreAnalStats *as = NULL; RTable *t = NULL; PJ *pj = NULL; if (mode == '?') { - r_core_cmd_help (core, help_msg_p_minus); + rz_core_cmd_help (core, help_msg_p_minus); return false; } @@ -3144,29 +3144,29 @@ static bool cmd_print_blocks(RCore *core, const char *input) { } int w = (input[0] == ' ') - ? (int)r_num_math (core->num, input + 1) + ? (int)rz_num_math (core->num, input + 1) : (int)(core->print->cols * 2.7); if (w == 0) { - r_core_cmd_help (core, help_msg_p_minus); + rz_core_cmd_help (core, help_msg_p_minus); return false; } - int cols = r_config_get_i (core->config, "hex.cols"); - //int cols = r_cons_get_size (NULL) - 30; + int cols = rz_config_get_i (core->config, "hex.cols"); + //int cols = rz_cons_get_size (NULL) - 30; ut64 off = core->offset; ut64 from = UT64_MAX; ut64 to = 0; - list = r_core_get_boundaries_prot (core, -1, NULL, "search"); + list = rz_core_get_boundaries_prot (core, -1, NULL, "search"); if (!list) { result = true; goto cleanup; } - RListIter *iter; - RIOMap *map; - r_list_foreach (list, iter, map) { - ut64 f = r_itv_begin (map->itv); - ut64 t = r_itv_end (map->itv); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (list, iter, map) { + ut64 f = rz_itv_begin (map->itv); + ut64 t = rz_itv_end (map->itv); if (f < from) { from = f; } @@ -3174,10 +3174,10 @@ static bool cmd_print_blocks(RCore *core, const char *input) { to = t; } } - r_list_free (list); + rz_list_free (list); list = NULL; ut64 piece = R_MAX ((to - from) / R_MAX (cols, w), 1); - as = r_core_anal_get_stats (core, from, to, piece); + as = rz_core_anal_get_stats (core, from, to, piece); if (!as) { goto cleanup; } @@ -3196,20 +3196,20 @@ static bool cmd_print_blocks(RCore *core, const char *input) { pj_a (pj); break; case 'h': { // "p-h" - t = r_core_table (core); + t = rz_core_table (core); if (!t) { goto cleanup; } t->showSum = true; - r_table_set_columnsf (t, "sddddd", "offset", "flags", "funcs", "cmts", "syms", "str"); + rz_table_set_columnsf (t, "sddddd", "offset", "flags", "funcs", "cmts", "syms", "str"); break; } case 'e': default: - r_cons_printf ("0x%08"PFMT64x " [", from); + rz_cons_printf ("0x%08"PFMT64x " [", from); } - bool use_color = r_config_get_i (core->config, "scr.color"); + bool use_color = rz_config_get_i (core->config, "scr.color"); int len = 0; int i; for (i = 0; i < ((to - from) / piece); i++) { @@ -3247,7 +3247,7 @@ static bool cmd_print_blocks(RCore *core, const char *input) { pj_ki (pj, "strings", as->block[p].strings); } if (as->block[p].perm) { - pj_ks (pj, "perm", r_str_rwx_i (as->block[p].perm)); + pj_ks (pj, "perm", rz_str_rwx_i (as->block[p].perm)); } pj_end (pj); len++; @@ -3258,7 +3258,7 @@ static bool cmd_print_blocks(RCore *core, const char *input) { || (as->block[p].comments) || (as->block[p].symbols) || (as->block[p].strings)) { - r_table_add_rowf (t, "sddddd", sdb_fmt ("0x%09"PFMT64x"", at), as->block[p].flags, + rz_table_add_rowf (t, "sddddd", sdb_fmt ("0x%09"PFMT64x"", at), as->block[p].flags, as->block[p].functions, as->block[p].comments, as->block[p].symbols, as->block[p].strings); } break; @@ -3267,34 +3267,34 @@ static bool cmd_print_blocks(RCore *core, const char *input) { break; default:{ // p-- if (off >= at && off < ate) { - r_cons_memcat ("^", 1); + rz_cons_memcat ("^", 1); } else { - RIOMap *s = r_io_map_get (core->io, at); + RzIOMap *s = rz_io_map_get (core->io, at); if (use_color) { if (s) { if (s->perm & R_PERM_X) { - r_cons_print (r_cons_singleton ()->context->pal.graph_trufae); + rz_cons_print (rz_cons_singleton ()->context->pal.graph_trufae); } else { - r_cons_print (r_cons_singleton ()->context->pal.graph_true); + rz_cons_print (rz_cons_singleton ()->context->pal.graph_true); } } else { - r_cons_print (r_cons_singleton ()->context->pal.graph_false); + rz_cons_print (rz_cons_singleton ()->context->pal.graph_false); } } if (as->block[p].strings > 0) { - r_cons_memcat ("z", 1); + rz_cons_memcat ("z", 1); } else if (as->block[p].symbols > 0) { - r_cons_memcat ("s", 1); + rz_cons_memcat ("s", 1); } else if (as->block[p].functions > 0) { - r_cons_memcat ("F", 1); + rz_cons_memcat ("F", 1); } else if (as->block[p].comments > 0) { - r_cons_memcat ("c", 1); + rz_cons_memcat ("c", 1); } else if (as->block[p].flags > 0) { - r_cons_memcat (".", 1); + rz_cons_memcat (".", 1); } else if (as->block[p].in_functions > 0) { - r_cons_memcat ("f", 1); + rz_cons_memcat ("f", 1); } else { - r_cons_memcat ("_", 1); + rz_cons_memcat ("_", 1); } } } @@ -3305,36 +3305,36 @@ static bool cmd_print_blocks(RCore *core, const char *input) { case 'j': pj_end (pj); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); break; case 'h': { - char *table_string = r_table_tofancystring (t); + char *table_string = rz_table_tofancystring (t); if (!table_string) { goto cleanup; } - r_cons_printf ("\n%s\n", table_string); + rz_cons_printf ("\n%s\n", table_string); free (table_string); break; } case 'e': default: if (use_color) { - r_cons_print (Color_RESET); + rz_cons_print (Color_RESET); } - r_cons_printf ("] 0x%08"PFMT64x "\n", to); + rz_cons_printf ("] 0x%08"PFMT64x "\n", to); break; } result = true; cleanup: pj_free (pj); - r_table_free (t); - r_list_free (list); - r_core_anal_stats_free (as); + rz_table_free (t); + rz_list_free (list); + rz_core_anal_stats_free (as); return result; } -static bool checkAnalType(RAnalOp *op, int t) { +static bool checkAnalType(RzAnalOp *op, int t) { if (t == 'c') { switch (op->type) { case R_ANAL_OP_TYPE_RCALL: @@ -3376,7 +3376,7 @@ static inline void matchBar(ut8 *ptr, int i) { } } -static ut8 *analBars(RCore *core, size_t type, size_t nblocks, size_t blocksize, size_t skipblocks, ut64 from) { +static ut8 *analBars(RzCore *core, size_t type, size_t nblocks, size_t blocksize, size_t skipblocks, ut64 from) { size_t j, i = 0; ut8 *ptr = calloc (1, nblocks); if (!ptr) { @@ -3392,7 +3392,7 @@ static ut8 *analBars(RCore *core, size_t type, size_t nblocks, size_t blocksize, } if (type == 'A') { ut64 to = from + (blocksize * nblocks); - RCoreAnalStats *as = r_core_anal_get_stats (core, from, to, blocksize); + RzCoreAnalStats *as = rz_core_anal_get_stats (core, from, to, blocksize); for (i = 0; i < nblocks; i++) { int value = 0; value += as->block[i].functions; @@ -3404,24 +3404,24 @@ static ut8 *analBars(RCore *core, size_t type, size_t nblocks, size_t blocksize, value += as->block[i].blocks; ptr[i] = R_MIN (255, value); } - r_core_anal_stats_free (as); + rz_core_anal_stats_free (as); free (p); return ptr; } for (i = 0; i < nblocks; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } ut64 off = from + (i + skipblocks) * blocksize; for (j = 0; j < blocksize ; j++) { if (type == 'a') { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off + j, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off + j, 0); if (fcn) { - ptr[i] = r_list_length (fcn->bbs); + ptr[i] = rz_list_length (fcn->bbs); } continue; } - RAnalOp *op = r_core_anal_op (core, off + j, R_ANAL_OP_MASK_BASIC); + RzAnalOp *op = rz_core_anal_op (core, off + j, R_ANAL_OP_MASK_BASIC); if (op) { if (op->size < 1) { // do nothing @@ -3436,7 +3436,7 @@ static ut8 *analBars(RCore *core, size_t type, size_t nblocks, size_t blocksize, if (op->size > 0) { j += op->size - 1; } - r_anal_op_free (op); + rz_anal_op_free (op); } else { if (type == 'i') { matchBar (ptr, i); @@ -3448,17 +3448,17 @@ static ut8 *analBars(RCore *core, size_t type, size_t nblocks, size_t blocksize, return ptr; } -static void cmd_print_bars(RCore *core, const char *input) { +static void cmd_print_bars(RzCore *core, const char *input) { bool print_bars = false; ut8 *ptr = NULL; // p=e [nblocks] [totalsize] [skip] int nblocks = -1; ut64 totalsize = UT64_MAX; int skipblocks = -1; - RIOMap* map; - RListIter *iter; + RzIOMap* map; + RzListIter *iter; ut64 from = 0, to = 0; - RList *list = r_core_get_boundaries_prot (core, -1, NULL, "zoom"); + RzList *list = rz_core_get_boundaries_prot (core, -1, NULL, "zoom"); if (!list) { goto beach; } @@ -3470,16 +3470,16 @@ static void cmd_print_bars(RCore *core, const char *input) { if (input[0]) { char *spc = strchr (input, ' '); if (spc) { - nblocks = r_num_math (core->num, spc + 1); + nblocks = rz_num_math (core->num, spc + 1); if (nblocks < 1) { goto beach; } spc = strchr (spc + 1, ' '); if (spc) { - totalsize = r_num_math (core->num, spc + 1); + totalsize = rz_num_math (core->num, spc + 1); spc = strchr (spc + 1, ' '); if (spc) { - skipblocks = r_num_math (core->num, spc + 1); + skipblocks = rz_num_math (core->num, spc + 1); } } } @@ -3492,15 +3492,15 @@ static void cmd_print_bars(RCore *core, const char *input) { skipblocks = 0; } if (totalsize == UT64_MAX) { - if (r_config_get_i (core->config, "cfg.debug")) { - RDebugMap *map = r_debug_map_get (core->dbg, core->offset); + if (rz_config_get_i (core->config, "cfg.debug")) { + RzDebugMap *map = rz_debug_map_get (core->dbg, core->offset); if (map) { totalsize = map->addr_end - map->addr; from = map->addr; } } else { if (core->file && core->io) { - totalsize = r_io_fd_size (core->io, core->file->fd); + totalsize = rz_io_fd_size (core->io, core->file->fd); if ((st64) totalsize < 1) { totalsize = UT64_MAX; } @@ -3516,12 +3516,12 @@ static void cmd_print_bars(RCore *core, const char *input) { eprintf ("Invalid block size: %d\n", (int)blocksize); goto beach; } - if (!r_config_get_i (core->config, "cfg.debug")) { - RIOMap* map1 = r_list_first (list); + if (!rz_config_get_i (core->config, "cfg.debug")) { + RzIOMap* map1 = rz_list_first (list); if (map1) { from = map1->itv.addr; - r_list_foreach (list, iter, map) { - to = r_itv_end (map->itv); + rz_list_foreach (list, iter, map) { + to = rz_itv_end (map->itv); } totalsize = to - from; } else { @@ -3539,12 +3539,12 @@ static void cmd_print_bars(RCore *core, const char *input) { } switch (mode) { case '?': // bars - r_core_cmd_help (core, help_msg_p_equal); + rz_core_cmd_help (core, help_msg_p_equal); break; case '=': // "p==" switch (submode) { case '?': - r_core_cmd_help (core, help_msg_p_equal); + rz_core_cmd_help (core, help_msg_p_equal); break; case '0': // 0x00 bytes case 'f': // 0xff bytes @@ -3570,7 +3570,7 @@ static void cmd_print_bars(RCore *core, const char *input) { int len = 0; if (submode == 'A') { ut64 to = from + totalsize; // (blocksize * nblocks); - RCoreAnalStats *as = r_core_anal_get_stats (core, from, to, blocksize); + RzCoreAnalStats *as = rz_core_anal_get_stats (core, from, to, blocksize); for (i = 0; i < nblocks; i++) { int value = 0; value += as->block[i].functions; @@ -3583,17 +3583,17 @@ static void cmd_print_bars(RCore *core, const char *input) { ptr[i] = 256 * value / blocksize; ptr[i] *= 3; } - r_core_anal_stats_free (as); + rz_core_anal_stats_free (as); } else for (i = 0; i < nblocks; i++) { ut64 off = from + blocksize * (i + skipblocks); - r_io_read_at (core->io, off, p, blocksize); + rz_io_read_at (core->io, off, p, blocksize); for (j = k = 0; j < blocksize; j++) { switch (submode) { case 'a': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off + j, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off + j, 0); if (fcn) { - k += r_list_length (fcn->bbs); + k += rz_list_length (fcn->bbs); k = R_MAX (255, k); } } @@ -3630,7 +3630,7 @@ static void cmd_print_bars(RCore *core, const char *input) { } ptr[i] = 256 * k / blocksize; } - r_print_columns (core->print, ptr, nblocks, 14); + rz_print_columns (core->print, ptr, nblocks, 14); free (p); } break; @@ -3651,15 +3651,15 @@ static void cmd_print_bars(RCore *core, const char *input) { } for (i = 0; i < nblocks; i++) { ut64 off = from + (blocksize * (i + skipblocks)); - r_io_read_at (core->io, off, p, blocksize); - ptr[i] = (ut8) (255 * r_hash_entropy_fraction (p, blocksize)); + rz_io_read_at (core->io, off, p, blocksize); + ptr[i] = (ut8) (255 * rz_hash_entropy_fraction (p, blocksize)); } free (p); - r_print_columns (core->print, ptr, nblocks, 14); + rz_print_columns (core->print, ptr, nblocks, 14); } break; default: - r_print_columns (core->print, core->block, core->blocksize, 14); + rz_print_columns (core->print, core->block, core->blocksize, 14); break; } break; @@ -3667,15 +3667,15 @@ static void cmd_print_bars(RCore *core, const char *input) { { short *word = (short*) core->block; int i, words = core->blocksize / 2; - int step = r_num_math (core->num, input + 2); + int step = rz_num_math (core->num, input + 2); ut64 oldword = 0; for (i = 0; ioffset + (i *2), word[i]); - r_print_progressbar (core->print, word64 * 100 / UT16_MAX, 60); - r_cons_printf (" %d", word64 - oldword); + rz_cons_printf ("0x%08"PFMT64x" %8d ", core->offset + (i *2), word[i]); + rz_print_progressbar (core->print, word64 * 100 / UT16_MAX, 60); + rz_cons_printf (" %d", word64 - oldword); oldword = word64; - r_cons_newline (); + rz_cons_newline (); i += step; } } @@ -3683,18 +3683,18 @@ static void cmd_print_bars(RCore *core, const char *input) { case 'd': // "p=d" ptr = NULL; if (input[2]) { - ut64 bufsz = r_num_math (core->num, input + 3); + ut64 bufsz = rz_num_math (core->num, input + 3); ut64 curbsz = core->blocksize; if (bufsz < 1) { bufsz = curbsz; } if (bufsz > core->blocksize) { - r_core_block_size (core, bufsz); - r_core_block_read (core); + rz_core_block_size (core, bufsz); + rz_core_block_read (core); } cmd_print_eq_dict (core, core->block, bufsz); if (bufsz != curbsz) { - r_core_block_size (core, curbsz); + rz_core_block_size (core, curbsz); } } else { cmd_print_eq_dict (core, core->block, core->blocksize); @@ -3728,7 +3728,7 @@ static void cmd_print_bars(RCore *core, const char *input) { for (i = 0; i < nblocks; i++) { ut64 off = from + (blocksize * (i + skipblocks)); for (j = 0; j < blocksize; j++) { - if (r_flag_get_at (core->flags, off + j, false)) { + if (rz_flag_get_at (core->flags, off + j, false)) { matchBar (ptr, i); } } @@ -3754,8 +3754,8 @@ static void cmd_print_bars(RCore *core, const char *input) { } for (i = 0; i < nblocks; i++) { ut64 off = from + (blocksize * (i + skipblocks)); - r_io_read_at (core->io, off, p, blocksize); - ptr[i] = (ut8) (255 * r_hash_entropy_fraction (p, blocksize)); + rz_io_read_at (core->io, off, p, blocksize); + ptr[i] = (ut8) (255 * rz_hash_entropy_fraction (p, blocksize)); } free (p); print_bars = true; @@ -3782,7 +3782,7 @@ static void cmd_print_bars(RCore *core, const char *input) { int len = 0; for (i = 0; i < nblocks; i++) { ut64 off = from + blocksize * (i + skipblocks); - r_io_read_at (core->io, off, p, blocksize); + rz_io_read_at (core->io, off, p, blocksize); for (j = k = 0; j < blocksize; j++) { switch (mode) { case '0': @@ -3824,14 +3824,14 @@ static void cmd_print_bars(RCore *core, const char *input) { case 'b': // bytes case '\0': ptr = calloc (1, nblocks); - r_io_read_at (core->io, from, ptr, nblocks); + rz_io_read_at (core->io, from, ptr, nblocks); // TODO: support print_bars - r_print_fill (core->print, ptr, nblocks, from, blocksize); + rz_print_fill (core->print, ptr, nblocks, from, blocksize); R_FREE (ptr); break; } if (print_bars) { - bool hex_offset = r_config_get_i (core->config, "hex.offset"); + bool hex_offset = rz_config_get_i (core->config, "hex.offset"); if (hex_offset) { core->print->flags |= R_PRINT_FLAGS_OFFSET; } else { @@ -3864,7 +3864,7 @@ static void cmd_print_bars(RCore *core, const char *input) { } pj_end (pj); pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } break; case 'q': @@ -3872,99 +3872,99 @@ static void cmd_print_bars(RCore *core, const char *input) { ut64 off = from + (blocksize * i); if (core->print->cur_enabled) { if (i == core->print->cur) { - r_cons_printf ("> "); + rz_cons_printf ("> "); core->num->value = off; } else { - r_cons_printf (" "); + rz_cons_printf (" "); } } - r_cons_printf ("0x%08"PFMT64x " %d %d\n", off, i, ptr[i]); + rz_cons_printf ("0x%08"PFMT64x " %d %d\n", off, i, ptr[i]); } break; default: core->print->num = core->num; - r_print_fill (core->print, ptr, nblocks, from, blocksize); + rz_print_fill (core->print, ptr, nblocks, from, blocksize); break; } } beach: - r_list_free (list); + rz_list_free (list); free (ptr); } -static int bbcmp(RAnalBlock *a, RAnalBlock *b) { +static int bbcmp(RzAnalBlock *a, RzAnalBlock *b) { return a->addr - b->addr; } -/* TODO: integrate this into r_anal */ -static void _pointer_table(RCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, int mode) { +/* TODO: integrate this into rz_anal */ +static void _pointer_table(RzCore *core, ut64 origin, ut64 offset, const ut8 *buf, int len, int step, int mode) { int i; ut64 addr; st32 *delta; // only for step == 4 if (step < 1) { step = 4; } - if (!r_io_is_valid_offset (core->io, origin, 0) || - !r_io_is_valid_offset (core->io, offset, 0)) { + if (!rz_io_is_valid_offset (core->io, origin, 0) || + !rz_io_is_valid_offset (core->io, offset, 0)) { return; } if (origin != offset) { switch (mode) { case '*': - r_cons_printf ("CC-@ 0x%08"PFMT64x "\n", origin); - r_cons_printf ("CC switch table @ 0x%08"PFMT64x "\n", origin); - r_cons_printf ("axd 0x%"PFMT64x " 0x%08"PFMT64x "\n", origin, offset); + rz_cons_printf ("CC-@ 0x%08"PFMT64x "\n", origin); + rz_cons_printf ("CC switch table @ 0x%08"PFMT64x "\n", origin); + rz_cons_printf ("axd 0x%"PFMT64x " 0x%08"PFMT64x "\n", origin, offset); break; case '.': - r_core_cmdf (core, "CC-@ 0x%08"PFMT64x "\n", origin); - r_core_cmdf (core, "CC switch table @ 0x%08"PFMT64x "\n", origin); - r_core_cmdf (core, "f switch.0x%08"PFMT64x"=0x%08"PFMT64x"\n", origin, origin); - r_core_cmdf (core, "f jmptbl.0x%08"PFMT64x"=0x%08"PFMT64x"\n", offset, offset); //origin, origin); - r_core_cmdf (core, "axd 0x%"PFMT64x " 0x%08"PFMT64x "\n", origin, offset); + rz_core_cmdf (core, "CC-@ 0x%08"PFMT64x "\n", origin); + rz_core_cmdf (core, "CC switch table @ 0x%08"PFMT64x "\n", origin); + rz_core_cmdf (core, "f switch.0x%08"PFMT64x"=0x%08"PFMT64x"\n", origin, origin); + rz_core_cmdf (core, "f jmptbl.0x%08"PFMT64x"=0x%08"PFMT64x"\n", offset, offset); //origin, origin); + rz_core_cmdf (core, "axd 0x%"PFMT64x " 0x%08"PFMT64x "\n", origin, offset); break; } } else if (mode == '.') { - r_core_cmdf (core, "CC-@ 0x%08"PFMT64x "\n", origin); - r_core_cmdf (core, "CC switch basic block @ 0x%08"PFMT64x "\n", offset); - r_core_cmdf (core, "f switch.0x%08"PFMT64x"=0x%08"PFMT64x"\n", offset, offset); // basic block @ 0x%08"PFMT64x "\n", offset); + rz_core_cmdf (core, "CC-@ 0x%08"PFMT64x "\n", origin); + rz_core_cmdf (core, "CC switch basic block @ 0x%08"PFMT64x "\n", offset); + rz_core_cmdf (core, "f switch.0x%08"PFMT64x"=0x%08"PFMT64x"\n", offset, offset); // basic block @ 0x%08"PFMT64x "\n", offset); } int n = 0; for (i = 0; (i + sizeof (st32)) <= len; i += step, n++) { delta = (st32 *) (buf + i); addr = offset + *delta; - if (!r_io_is_valid_offset (core->io, addr, 0)) { + if (!rz_io_is_valid_offset (core->io, addr, 0)) { // Lets check for jmptbl with not relative addresses // Like: jmp dword [eax*4 + jmptbl.0x5435345] - if (!r_io_is_valid_offset (core->io, *delta, 0)) { + if (!rz_io_is_valid_offset (core->io, *delta, 0)) { break; } addr = *delta; } if (mode == '*') { - r_cons_printf ("af case.%d.0x%"PFMT64x " 0x%08"PFMT64x "\n", n, offset, addr); - r_cons_printf ("ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", offset, addr); - r_cons_printf ("ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :? - r_cons_printf ("aho case 0x%"PFMT64x " 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", (ut64)i, addr, offset + i); // wrong, but useful because forward xrefs dont work :? - r_cons_printf ("ahs %d @ 0x%08"PFMT64x "\n", step, offset + i); + rz_cons_printf ("af case.%d.0x%"PFMT64x " 0x%08"PFMT64x "\n", n, offset, addr); + rz_cons_printf ("ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", offset, addr); + rz_cons_printf ("ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :? + rz_cons_printf ("aho case 0x%"PFMT64x " 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", (ut64)i, addr, offset + i); // wrong, but useful because forward xrefs dont work :? + rz_cons_printf ("ahs %d @ 0x%08"PFMT64x "\n", step, offset + i); } else if (mode == '.') { - r_core_cmdf (core, "af case.%d.0x%"PFMT64x " @ 0x%08"PFMT64x "\n", n, offset, addr); - r_core_cmdf (core, "ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", offset, addr); - r_core_cmdf (core, "ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :? - // r_core_cmdf (core, "CC+ case %d: 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", i / step, addr, origin); - r_core_cmdf (core, "CCu case %d: @ 0x%08"PFMT64x "\n", n, addr); //, origin); - r_core_cmdf (core, "aho case %d 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", n, addr, offset + i); // wrong, but useful because forward xrefs dont work :? - r_core_cmdf (core, "ahs %d @ 0x%08"PFMT64x "\n", step, offset + i); + rz_core_cmdf (core, "af case.%d.0x%"PFMT64x " @ 0x%08"PFMT64x "\n", n, offset, addr); + rz_core_cmdf (core, "ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", offset, addr); + rz_core_cmdf (core, "ax 0x%"PFMT64x " 0x%08"PFMT64x "\n", addr, offset); // wrong, but useful because forward xrefs dont work :? + // rz_core_cmdf (core, "CC+ case %d: 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", i / step, addr, origin); + rz_core_cmdf (core, "CCu case %d: @ 0x%08"PFMT64x "\n", n, addr); //, origin); + rz_core_cmdf (core, "aho case %d 0x%08"PFMT64x " @ 0x%08"PFMT64x "\n", n, addr, offset + i); // wrong, but useful because forward xrefs dont work :? + rz_core_cmdf (core, "ahs %d @ 0x%08"PFMT64x "\n", step, offset + i); } else { - r_cons_printf ("0x%08"PFMT64x " -> 0x%08"PFMT64x "\n", offset + i, addr); + rz_cons_printf ("0x%08"PFMT64x " -> 0x%08"PFMT64x "\n", offset + i, addr); } } } -static void __printPattern(RCore *core, const char *_input) { +static void __printPattern(RzCore *core, const char *_input) { char *input = strdup (_input); - const char *arg = r_str_nextword (input, ' '); + const char *arg = rz_str_nextword (input, ' '); size_t i, j; - st64 len = arg? r_num_math (core->num, arg): core->blocksize; + st64 len = arg? rz_num_math (core->num, arg): core->blocksize; if (len < 1) { eprintf ("Invalid length\n"); return; @@ -3973,11 +3973,11 @@ static void __printPattern(RCore *core, const char *_input) { case 'd': // "ppd" // debruijn pattern { - ut8 *buf = (ut8*)r_debruijn_pattern (len, 0, NULL); + ut8 *buf = (ut8*)rz_debruijn_pattern (len, 0, NULL); for (i = 0; i < len; i++) { - r_cons_printf ("%02x", buf[i]); + rz_cons_printf ("%02x", buf[i]); } - r_cons_newline (); + rz_cons_newline (); free (buf); } break; @@ -3986,9 +3986,9 @@ static void __printPattern(RCore *core, const char *_input) { { int min = (core->offset & 0xff); for (i = 0; i < len; i++) { - r_cons_printf ("%02x", i + min); + rz_cons_printf ("%02x", i + min); } - r_cons_newline (); + rz_cons_newline (); } break; case '2': // "pp2" @@ -3997,9 +3997,9 @@ static void __printPattern(RCore *core, const char *_input) { // TODO: honor cfg.bigendian int min = (core->offset & 0xffff); for (i = 0; i < len; i++) { - r_cons_printf ("%04x", i + min); + rz_cons_printf ("%04x", i + min); } - r_cons_newline (); + rz_cons_newline (); } break; case '4': // "pp4" @@ -4008,9 +4008,9 @@ static void __printPattern(RCore *core, const char *_input) { // TODO: honor cfg.bigendian int min = (core->offset & UT32_MAX); for (i = 0; i < len; i++) { - r_cons_printf ("%08x", i + min); + rz_cons_printf ("%08x", i + min); } - r_cons_newline (); + rz_cons_newline (); } break; case '8': // "pp8" @@ -4019,30 +4019,30 @@ static void __printPattern(RCore *core, const char *_input) { // TODO: honor cfg.bigendian ut64 min = (core->offset); for (i = 0; i < len; i++) { - r_cons_printf ("%016"PFMT64x, i + min); + rz_cons_printf ("%016"PFMT64x, i + min); } - r_cons_newline (); + rz_cons_newline (); } break; case 'f': // "ppf" // zero ssled { - ut8 *buf = (ut8*)r_debruijn_pattern (len, 0, NULL); + ut8 *buf = (ut8*)rz_debruijn_pattern (len, 0, NULL); for (i = 0; i < len; i++) { - r_cons_printf ("%02x", 0xff); + rz_cons_printf ("%02x", 0xff); } - r_cons_newline (); + rz_cons_newline (); free (buf); } break; case '0': // "pp0" // zero ssled { - ut8 *buf = (ut8*)r_debruijn_pattern (len, 0, NULL); + ut8 *buf = (ut8*)rz_debruijn_pattern (len, 0, NULL); for (i = 0; i < len; i++) { - r_cons_printf ("%02x", 0); + rz_cons_printf ("%02x", 0); } - r_cons_newline (); + rz_cons_newline (); free (buf); } break; @@ -4056,11 +4056,11 @@ static void __printPattern(RCore *core, const char *_input) { for (i = 0; i < len; i++) { incAlphaBuffer (buf, bs); for (j = 0; j < bs; j++) { - r_cons_printf ("%c", buf[j]?buf[j]:'A'); + rz_cons_printf ("%c", buf[j]?buf[j]:'A'); } - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_newline (); + rz_cons_newline (); free (buf); } break; @@ -4073,24 +4073,24 @@ static void __printPattern(RCore *core, const char *_input) { for (i = 0; i < len; i++) { incDigitBuffer (buf, bs); for (j = 0; j < bs; j++) { - r_cons_printf ("%c", buf[j]?buf[j]:'0'); + rz_cons_printf ("%c", buf[j]?buf[j]:'0'); } - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_newline (); + rz_cons_newline (); free (buf); } break; default: - r_core_cmd_help (core, help_msg_pp); + rz_core_cmd_help (core, help_msg_pp); break; } free (input); } -static void pr_bb(RCore *core, RAnalFunction *fcn, RAnalBlock *b, bool emu, ut64 saved_gp, ut8 *saved_arena, char p_type, bool fromHere) { - bool show_flags = r_config_get_i (core->config, "asm.flags"); - const char *orig_bb_middle = r_config_get (core->config, "asm.bb.middle"); +static void pr_bb(RzCore *core, RzAnalFunction *fcn, RzAnalBlock *b, bool emu, ut64 saved_gp, ut8 *saved_arena, char p_type, bool fromHere) { + bool show_flags = rz_config_get_i (core->config, "asm.flags"); + const char *orig_bb_middle = rz_config_get (core->config, "asm.bb.middle"); core->anal->gp = saved_gp; if (fromHere) { if (b->addr < core->offset) { @@ -4102,31 +4102,31 @@ static void pr_bb(RCore *core, RAnalFunction *fcn, RAnalBlock *b, bool emu, ut64 if (emu) { if (b->parent_reg_arena) { ut64 gp; - r_reg_arena_poke (core->anal->reg, b->parent_reg_arena); + rz_reg_arena_poke (core->anal->reg, b->parent_reg_arena); R_FREE (b->parent_reg_arena); - gp = r_reg_getv (core->anal->reg, "gp"); + gp = rz_reg_getv (core->anal->reg, "gp"); if (gp) { core->anal->gp = gp; } } else { - r_reg_arena_poke (core->anal->reg, saved_arena); + rz_reg_arena_poke (core->anal->reg, saved_arena); } } if (b->parent_stackptr != INT_MAX) { core->anal->stackptr = b->parent_stackptr; } - r_config_set_i (core->config, "asm.bb.middle", false); + rz_config_set_i (core->config, "asm.bb.middle", false); p_type == 'D' - ? r_core_cmdf (core, "pD %"PFMT64u" @0x%"PFMT64x, b->size, b->addr) - : r_core_cmdf (core, "pI %"PFMT64u" @0x%"PFMT64x, b->size, b->addr); - r_config_set (core->config, "asm.bb.middle", orig_bb_middle); + ? rz_core_cmdf (core, "pD %"PFMT64u" @0x%"PFMT64x, b->size, b->addr) + : rz_core_cmdf (core, "pI %"PFMT64u" @0x%"PFMT64x, b->size, b->addr); + rz_config_set (core->config, "asm.bb.middle", orig_bb_middle); if (b->jump != UT64_MAX) { if (b->jump > b->addr) { - RAnalBlock *jumpbb = r_anal_get_block_at (b->anal, b->jump); - if (jumpbb && r_list_contains (jumpbb->fcns, fcn)) { + RzAnalBlock *jumpbb = rz_anal_get_block_at (b->anal, b->jump); + if (jumpbb && rz_list_contains (jumpbb->fcns, fcn)) { if (emu && core->anal->last_disasm_reg && !jumpbb->parent_reg_arena) { - jumpbb->parent_reg_arena = r_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); + jumpbb->parent_reg_arena = rz_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); } if (jumpbb->parent_stackptr == INT_MAX) { jumpbb->parent_stackptr = core->anal->stackptr + b->stackptr; @@ -4134,15 +4134,15 @@ static void pr_bb(RCore *core, RAnalFunction *fcn, RAnalBlock *b, bool emu, ut64 } } if (p_type == 'D' && show_flags) { - r_cons_printf ("| ----------- true: 0x%08"PFMT64x, b->jump); + rz_cons_printf ("| ----------- true: 0x%08"PFMT64x, b->jump); } } if (b->fail != UT64_MAX) { if (b->fail > b->addr) { - RAnalBlock *failbb = r_anal_get_block_at (b->anal, b->fail); - if (failbb && r_list_contains (failbb->fcns, fcn)) { + RzAnalBlock *failbb = rz_anal_get_block_at (b->anal, b->fail); + if (failbb && rz_list_contains (failbb->fcns, fcn)) { if (emu && core->anal->last_disasm_reg && !failbb->parent_reg_arena) { - failbb->parent_reg_arena = r_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); + failbb->parent_reg_arena = rz_reg_arena_dup (core->anal->reg, core->anal->last_disasm_reg); } if (failbb->parent_stackptr == INT_MAX) { failbb->parent_stackptr = core->anal->stackptr + b->stackptr; @@ -4150,17 +4150,17 @@ static void pr_bb(RCore *core, RAnalFunction *fcn, RAnalBlock *b, bool emu, ut64 } } if (p_type == 'D' && show_flags) { - r_cons_printf (" false: 0x%08"PFMT64x, b->fail); + rz_cons_printf (" false: 0x%08"PFMT64x, b->fail); } } if (p_type == 'D' && show_flags) { - r_cons_newline (); + rz_cons_newline (); } } #if 0 dsmap { - r_itv_t addr; + rz_itv_t addr; ut64 size; ut8 *dis; } @@ -4168,29 +4168,29 @@ dsmap { #define P(x) (core->cons && core->cons->context->pal.x)? core->cons->context->pal.x -static void disasm_until_ret(RCore *core, ut64 addr, char type_print, const char *arg) { +static void disasm_until_ret(RzCore *core, ut64 addr, char type_print, const char *arg) { int p = 0; const bool show_color = core->print->flags & R_PRINT_FLAGS_COLOR; int i, limit = 1024; if (arg && *arg && arg[1]) { - limit = r_num_math (core->num, arg + 1); + limit = rz_num_math (core->num, arg + 1); } for (i = 0; i < limit; i++) { - RAnalOp *op = r_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + RzAnalOp *op = rz_core_anal_op (core, addr, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (op) { char *mnem = op->mnemonic; char *m = malloc ((strlen (mnem) * 2) + 32); strcpy (m, mnem); - //r_parse_parse (core->parser, op->mnemonic, m); + //rz_parse_parse (core->parser, op->mnemonic, m); if (type_print == 'q') { - r_cons_printf ("%s\n", m); + rz_cons_printf ("%s\n", m); } else { if (show_color) { - const char *offsetColor = r_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache - r_cons_printf ("%s0x%08"PFMT64x""Color_RESET" %10s %s\n", + const char *offsetColor = rz_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache + rz_cons_printf ("%s0x%08"PFMT64x""Color_RESET" %10s %s\n", offsetColor, addr + p, "", m); } else { - r_cons_printf ("0x%08"PFMT64x" %10s %s\n", addr + p, "", m); + rz_cons_printf ("0x%08"PFMT64x" %10s %s\n", addr + p, "", m); } } switch (op->type & 0xfffff) { @@ -4207,29 +4207,29 @@ static void disasm_until_ret(RCore *core, ut64 addr, char type_print, const char } } else { eprintf ("[pdp] Cannot get op at 0x%08"PFMT64x"\n", addr + p); - r_anal_op_free (op); + rz_anal_op_free (op); break; } - //r_io_read_at (core->io, n, rbuf, 512); - r_anal_op_free (op); + //rz_io_read_at (core->io, n, rbuf, 512); + rz_anal_op_free (op); } beach: return; } -static void disasm_ropchain(RCore *core, ut64 addr, char type_print) { +static void disasm_ropchain(RzCore *core, ut64 addr, char type_print) { int p = 0; ut64 n = 0; ut8 *buf = calloc (core->blocksize, 1); - (void)r_io_read_at (core->io, addr, buf, core->blocksize); + (void)rz_io_read_at (core->io, addr, buf, core->blocksize); while (p + 4 < core->blocksize) { const bool be = core->print->big_endian; if (core->rasm->bits == 64) { - n = r_read_ble64 (buf + p, be); + n = rz_read_ble64 (buf + p, be); } else { - n = r_read_ble32 (buf + p, be); + n = rz_read_ble32 (buf + p, be); } - r_cons_printf ("[0x%08"PFMT64x"] 0x%08"PFMT64x"\n", addr + p, n); + rz_cons_printf ("[0x%08"PFMT64x"] 0x%08"PFMT64x"\n", addr + p, n); disasm_until_ret (core, n, type_print, NULL); if (core->rasm->bits == 64) { p += 8; @@ -4240,8 +4240,8 @@ static void disasm_ropchain(RCore *core, ut64 addr, char type_print) { free (buf); } -static void disasm_recursive(RCore *core, ut64 addr, int count, char type_print) { - RAnalOp aop = {0}; +static void disasm_recursive(RzCore *core, ut64 addr, int count, char type_print) { + RzAnalOp aop = {0}; int ret; ut8 buf[128]; PJ *pj = NULL; @@ -4253,18 +4253,18 @@ static void disasm_recursive(RCore *core, ut64 addr, int count, char type_print) pj_a (pj); } while (count-- > 0) { - r_io_read_at (core->io, addr, buf, sizeof (buf)); - r_anal_op_fini (&aop); - ret = r_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + rz_anal_op_fini (&aop); + ret = rz_anal_op (core->anal, &aop, addr, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); if (ret < 0 || aop.size < 1) { addr++; continue; } - // r_core_cmdf (core, "pD %d @ 0x%08"PFMT64x, aop.size, addr); + // rz_core_cmdf (core, "pD %d @ 0x%08"PFMT64x, aop.size, addr); if (type_print == 'j') { - r_core_print_disasm_json (core, addr, buf, sizeof (buf), 1, pj); + rz_core_print_disasm_json (core, addr, buf, sizeof (buf), 1, pj); } else { - r_core_cmdf (core, "pd 1 @ 0x%08"PFMT64x, addr); + rz_core_cmdf (core, "pd 1 @ 0x%08"PFMT64x, addr); } switch (aop.type) { case R_ANAL_OP_TYPE_JMP: @@ -4282,36 +4282,36 @@ static void disasm_recursive(RCore *core, ut64 addr, int count, char type_print) } if (type_print == 'j') { pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } } -static void func_walk_blocks(RCore *core, RAnalFunction *f, char input, char type_print, bool fromHere) { - RListIter *iter; - RAnalBlock *b = NULL; - const char *orig_bb_middle = r_config_get (core->config, "asm.bb.middle"); - r_config_set_i (core->config, "asm.bb.middle", false); +static void func_walk_blocks(RzCore *core, RzAnalFunction *f, char input, char type_print, bool fromHere) { + RzListIter *iter; + RzAnalBlock *b = NULL; + const char *orig_bb_middle = rz_config_get (core->config, "asm.bb.middle"); + rz_config_set_i (core->config, "asm.bb.middle", false); PJ *pj = NULL; // XXX: hack must be reviewed/fixed in code analysis if (!b) { - if (r_list_length (f->bbs) >= 1) { - ut32 fcn_size = r_anal_function_realsize (f); - b = r_list_get_top (f->bbs); + if (rz_list_length (f->bbs) >= 1) { + ut32 fcn_size = rz_anal_function_realsize (f); + b = rz_list_get_top (f->bbs); if (b->size > fcn_size) { b->size = fcn_size; } } } - r_list_sort (f->bbs, (RListComparator) bbcmp); + rz_list_sort (f->bbs, (RzListComparator) bbcmp); if (input == 'j' && b) { pj = pj_new (); if (!pj) { return; } pj_a (pj); - r_list_foreach (f->bbs, iter, b) { + rz_list_foreach (f->bbs, iter, b) { if (fromHere) { if (b->addr < core->offset) { core->cons->null = true; @@ -4321,41 +4321,41 @@ static void func_walk_blocks(RCore *core, RAnalFunction *f, char input, char typ } ut8 *buf = malloc (b->size); if (buf) { - r_io_read_at (core->io, b->addr, buf, b->size); - r_core_print_disasm_json (core, b->addr, buf, b->size, 0, pj); + rz_io_read_at (core->io, b->addr, buf, b->size); + rz_core_print_disasm_json (core, b->addr, buf, b->size, 0, pj); free (buf); } else { eprintf ("cannot allocate %"PFMT64u" byte(s)\n", b->size); } } pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } else { - bool asm_lines = r_config_get_i (core->config, "asm.lines.bb"); - bool emu = r_config_get_i (core->config, "asm.emu"); + bool asm_lines = rz_config_get_i (core->config, "asm.lines.bb"); + bool emu = rz_config_get_i (core->config, "asm.emu"); ut64 saved_gp = 0; ut8 *saved_arena = NULL; int saved_stackptr = core->anal->stackptr; if (emu) { saved_gp = core->anal->gp; - saved_arena = r_reg_arena_peek (core->anal->reg); + saved_arena = rz_reg_arena_peek (core->anal->reg); } - r_config_set_i (core->config, "asm.lines.bb", 0); - r_list_foreach (f->bbs, iter, b) { + rz_config_set_i (core->config, "asm.lines.bb", 0); + rz_list_foreach (f->bbs, iter, b) { pr_bb (core, f, b, emu, saved_gp, saved_arena, type_print, fromHere); } if (emu) { core->anal->gp = saved_gp; if (saved_arena) { - r_reg_arena_poke (core->anal->reg, saved_arena); + rz_reg_arena_poke (core->anal->reg, saved_arena); R_FREE (saved_arena); } } core->anal->stackptr = saved_stackptr; - r_config_set_i (core->config, "asm.lines.bb", asm_lines); + rz_config_set_i (core->config, "asm.lines.bb", asm_lines); } - r_config_set (core->config, "asm.bb.middle", orig_bb_middle); + rz_config_set (core->config, "asm.bb.middle", orig_bb_middle); } static inline char cmd_pxb_p(char input) { @@ -4366,13 +4366,13 @@ static inline int cmd_pxb_k(const ut8 *buffer, int x) { return buffer[3 - x] << (8 * x); } -static void print_json_string(RCore *core, const char* block, int len, const char* type) { - const char* section_name = r_core_get_section_name (core, core->offset); +static void print_json_string(RzCore *core, const char* block, int len, const char* type) { + const char* section_name = rz_core_get_section_name (core, core->offset); if (section_name && strlen (section_name) < 1) { section_name = "unknown"; } else { // cleaning useless spaces in section name in json data. - section_name = r_str_trim_head_ro (section_name); + section_name = rz_str_trim_head_ro (section_name); char* p; for (p = (char*) section_name; *p && *p != ' '; p++) {} *p = '\0'; @@ -4393,101 +4393,101 @@ static void print_json_string(RCore *core, const char* block, int len, const cha pj_kn (pj, "offset", core->offset); pj_ks (pj, "section", section_name); pj_ki (pj, "legnth", len); - r_cons_printf (",\"length\":%d", len); + rz_cons_printf (",\"length\":%d", len); pj_ks (pj, "type", type); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); #else - r_cons_printf ("{\"string\":"); - char *str = r_str_utf16_encode (block, len); // XXX just block + len should be fine, pj takes care of this - r_cons_printf ("\"%s\"", str); + rz_cons_printf ("{\"string\":"); + char *str = rz_str_utf16_encode (block, len); // XXX just block + len should be fine, pj takes care of this + rz_cons_printf ("\"%s\"", str); free (str); - r_cons_printf (",\"offset\":%"PFMT64u, core->offset); - r_cons_printf (",\"section\":\"%s\"", section_name); - r_cons_printf (",\"length\":%d", len); - r_cons_printf (",\"type\":\"%s\"}", type); + rz_cons_printf (",\"offset\":%"PFMT64u, core->offset); + rz_cons_printf (",\"section\":\"%s\"", section_name); + rz_cons_printf (",\"length\":%d", len); + rz_cons_printf (",\"type\":\"%s\"}", type); #endif } -static char *__op_refs(RCore *core, RAnalOp *op, int n) { - RStrBuf *sb = r_strbuf_new (""); +static char *__op_refs(RzCore *core, RzAnalOp *op, int n) { + RStrBuf *sb = rz_strbuf_new (""); if (n) { - // RList *list = r_anal_xrefs_get_from (core->anal, op->addr); - RList *list = r_anal_xrefs_get (core->anal, op->addr); - RAnalRef *ref; - RListIter *iter; - r_list_foreach (list, iter, ref) { - r_strbuf_appendf (sb, "0x%08"PFMT64x" ", ref->at); + // RzList *list = rz_anal_xrefs_get_from (core->anal, op->addr); + RzList *list = rz_anal_xrefs_get (core->anal, op->addr); + RzAnalRef *ref; + RzListIter *iter; + rz_list_foreach (list, iter, ref) { + rz_strbuf_appendf (sb, "0x%08"PFMT64x" ", ref->at); } } else { if (op->jump != UT64_MAX) { - r_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->jump); + rz_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->jump); } if (op->fail != UT64_MAX) { - r_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->fail); + rz_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->fail); } if (op->ptr != UT64_MAX) { - if (r_io_is_valid_offset (core->io, op->ptr, false)) { - r_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->ptr); + if (rz_io_is_valid_offset (core->io, op->ptr, false)) { + rz_strbuf_appendf (sb, "0x%08"PFMT64x" ", op->ptr); } } } - char *res = r_strbuf_drain (sb); - r_str_trim (res); + char *res = rz_strbuf_drain (sb); + rz_str_trim (res); return res; } -static void r_core_disasm_table(RCore * core, int l, const char *input) { +static void rz_core_disasm_table(RzCore * core, int l, const char *input) { int i; - RTable *t = r_core_table (core); + RTable *t = rz_core_table (core); char *arg = strchr (input, ' '); if (arg) { input = arg + 1; } - r_table_set_columnsf (t, "snssssss", "name", "addr", "bytes", "disasm", "comment", "esil", "refs", "xrefs"); + rz_table_set_columnsf (t, "snssssss", "name", "addr", "bytes", "disasm", "comment", "esil", "refs", "xrefs"); const int minopsz = 1; const int options = R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_HINT | R_ANAL_OP_MASK_DISASM | R_ANAL_OP_MASK_ESIL; ut64 ea = core->offset; for (i = 0; i < l; i++) { - RAnalOp *op = r_core_anal_op (core, ea, options); + RzAnalOp *op = rz_core_anal_op (core, ea, options); if (!op || op->size < 1) { i += minopsz; ea += minopsz; continue; } - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ea); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, ea); // TODO parse/filter op->mnemonic for better disasm ut8 *bytes = malloc (op->size); if (!bytes) { break; } - r_io_read_at (core->io, ea, bytes, op->size); // XXX ranalop should contain the bytes like rasmop do - char *sbytes = r_hex_bin2strdup(bytes, op->size); - RFlagItem *fi = r_flag_get_i (core->flags, ea); + rz_io_read_at (core->io, ea, bytes, op->size); // XXX ranalop should contain the bytes like rasmop do + char *sbytes = rz_hex_bin2strdup(bytes, op->size); + RzFlagItem *fi = rz_flag_get_i (core->flags, ea); char *fn = fi? fi->name: ""; const char *esil = R_STRBUF_SAFEGET (&op->esil); char *refs = __op_refs (core, op, 0); char *xrefs = __op_refs (core, op, 1); - r_table_add_rowf (t, "sXssssss", fn, ea, sbytes, op->mnemonic, comment? comment: "", esil, refs, xrefs); + rz_table_add_rowf (t, "sXssssss", fn, ea, sbytes, op->mnemonic, comment? comment: "", esil, refs, xrefs); free (sbytes); free (bytes); free (xrefs); free (refs); ea += op->size; - r_anal_op_free (op); + rz_anal_op_free (op); } if (input && *input) { - r_table_query (t, input); + rz_table_query (t, input); } - char *ts = r_table_tostring (t); - r_cons_printf ("%s", ts); // \n? + char *ts = rz_table_tostring (t); + rz_cons_printf ("%s", ts); // \n? free (ts); - r_table_free (t); + rz_table_free (t); } static int cmd_print(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; st64 l; int i, len, ret; ut8* block; @@ -4499,14 +4499,14 @@ static int cmd_print(void *data, const char *input) { n = off = from = to = at = ate = piece = 0; PJ *pj = NULL; - r_print_init_rowoffsets (core->print); + rz_print_init_rowoffsets (core->print); off = UT64_MAX; l = len = core->blocksize; if (input[0] && input[1]) { int idx = (input[0] == 'h')? 2: 1; const char *p = off? strchr (input + idx, ' '): NULL; if (p) { - l = (int) r_num_math (core->num, p + 1); + l = (int) rz_num_math (core->num, p + 1); /* except disasm and memoryfmt (pd, pm) and overlay (po) */ if (input[0] != 'd' && input[0] != 't' && input[0] != 'D' && input[0] != 'm' && input[0] != 'a' && input[0] != 'f' && input[0] != 'i' && @@ -4518,7 +4518,7 @@ static int cmd_print(void *data, const char *input) { } else { len = l; if (l > core->blocksize) { - if (!r_core_block_size (core, l)) { + if (!rz_core_block_size (core, l)) { goto beach; } } @@ -4548,7 +4548,7 @@ static int cmd_print(void *data, const char *input) { } if (input[0] == 'x' || input[0] == 'D') { if (l > 0 && tmpseek == UT64_MAX) { - if (!r_core_block_size (core, l)) { + if (!rz_core_block_size (core, l)) { eprintf ("This block size is too big. Did you mean 'p%c @ %s' instead?\n", *input, input + 2); goto beach; @@ -4557,10 +4557,10 @@ static int cmd_print(void *data, const char *input) { } if (input[0] && input[0] != 'z' && input[1] == 'f' && input[2]!='?') { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, 0); // R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM); if (f) { - len = r_anal_function_linear_size (f); + len = rz_anal_function_linear_size (f); if (len > core->blocksize) { len = core->blocksize; } @@ -4573,8 +4573,8 @@ static int cmd_print(void *data, const char *input) { // TODO figure out why `f eax=33; f test=eax; pa call test` misassembles if len is 0 core->num->value = len ? len : core->blocksize; if (off != UT64_MAX) { - r_core_seek (core, off, SEEK_SET); - r_core_block_read (core); + rz_core_seek (core, off, SEEK_SET); + rz_core_block_read (core); } // TODO After core->block is removed, this should be changed to a block read. block = core->block; @@ -4583,32 +4583,32 @@ static int cmd_print(void *data, const char *input) { if (input[1] == 'n') { cmd_print_pwn (core); } else if (input[1] == 'd') { - if (!r_sandbox_enable (0)) { - char *cwd = r_sys_getdir (); + if (!rz_sandbox_enable (0)) { + char *cwd = rz_sys_getdir (); if (cwd) { - r_cons_println (cwd); + rz_cons_println (cwd); free (cwd); } } } else { - r_cons_printf ("| pwd display current working directory\n"); + rz_cons_printf ("| pwd display current working directory\n"); } break; case 'j': // "pj" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_pj); + rz_core_cmd_help (core, help_msg_pj); } else if (input[1] == '.') { if (input[2] == '.') { ut8 *data = calloc (core->offset + 1, 1); if (data) { data[core->offset] = 0; - (void)r_io_read_at (core->io, 0, data, core->offset); - char *res = r_print_json_path ((const char *)data, core->offset); + (void)rz_io_read_at (core->io, 0, data, core->offset); + char *res = rz_print_json_path ((const char *)data, core->offset); if (res) { eprintf ("-> res(%s)\n", res); } /* - char *res = r_print_json_indent ((char*)data, false, " ", NULL); + char *res = rz_print_json_indent ((char*)data, false, " ", NULL); print_json_path (core, res); free (res); */ @@ -4616,14 +4616,14 @@ static int cmd_print(void *data, const char *input) { eprintf ("Cannot allocate %d\n", (int)(core->offset)); } } else { - r_core_cmdf (core, "pj %"PFMT64u" @ 0", core->offset); + rz_core_cmdf (core, "pj %"PFMT64u" @ 0", core->offset); } } else { if (core->blocksize < 4 || !memcmp (core->block, "\xff\xff\xff\xff", 4)) { eprintf ("Cannot read\n"); } else { - char *res = r_print_json_indent ((const char *)core->block, true, " ", NULL); - r_cons_printf ("%s\n", res); + char *res = rz_print_json_indent ((const char *)core->block, true, " ", NULL); + rz_cons_printf ("%s\n", res); free (res); } } @@ -4644,21 +4644,21 @@ static int cmd_print(void *data, const char *input) { break; case 'A': // "pA" { - const ut64 saved_from = r_config_get_i (core->config, "search.from"), - saved_to = r_config_get_i (core->config, "search.to"), - saved_maxhits = r_config_get_i (core->config, "search.maxhits"); + const ut64 saved_from = rz_config_get_i (core->config, "search.from"), + saved_to = rz_config_get_i (core->config, "search.to"), + saved_maxhits = rz_config_get_i (core->config, "search.maxhits"); - int want = r_num_math (core->num, input + 1); + int want = rz_num_math (core->num, input + 1); if (input[1] == '?') { - r_core_cmd0 (core, "/A?"); + rz_core_cmd0 (core, "/A?"); } else { - r_config_set_i (core->config, "search.maxhits", want); - r_config_set_i (core->config, "search.from", core->offset); - r_config_set_i (core->config, "search.to", core->offset + core->blocksize); - r_core_cmd0 (core, "/A"); - r_config_set_i (core->config, "search.maxhits", saved_maxhits); - r_config_set_i (core->config, "search.from", saved_from); - r_config_set_i (core->config, "search.to", saved_to); + rz_config_set_i (core->config, "search.maxhits", want); + rz_config_set_i (core->config, "search.from", core->offset); + rz_config_set_i (core->config, "search.to", core->offset + core->blocksize); + rz_core_cmd0 (core, "/A"); + rz_config_set_i (core->config, "search.maxhits", saved_maxhits); + rz_config_set_i (core->config, "search.from", saved_from); + rz_config_set_i (core->config, "search.to", saved_to); } } break; @@ -4666,25 +4666,25 @@ static int cmd_print(void *data, const char *input) { { const char *arg = NULL; if (input[1] != '\0') { - arg = r_str_trim_head_ro (input + 2); + arg = rz_str_trim_head_ro (input + 2); } if (input[1] == 'e') { // "pae" if (input[2] == '?') { - r_cons_printf ("|Usage: pae [asm] print ESIL expression of the given assembly expression\n"); + rz_cons_printf ("|Usage: pae [asm] print ESIL expression of the given assembly expression\n"); } else { int printed = 0; int bufsz; - RAnalOp aop = {0}; - r_asm_set_pc (core->rasm, core->offset); - RAsmCode *acode = r_asm_massemble (core->rasm, input + 2); + RzAnalOp aop = {0}; + rz_asm_set_pc (core->rasm, core->offset); + RzAsmCode *acode = rz_asm_massemble (core->rasm, input + 2); if (acode) { bufsz = acode->len; while (printed < bufsz) { aop.size = 0; - if (r_anal_op (core->anal, &aop, core->offset, + if (rz_anal_op (core->anal, &aop, core->offset, (const ut8 *)acode->bytes + printed, bufsz - printed, R_ANAL_OP_MASK_ESIL) > 0) { const char *str = R_STRBUF_SAFEGET (&aop.esil); - r_cons_println (str); + rz_cons_println (str); } else { eprintf ("Cannot decode instruction\n"); break; @@ -4694,34 +4694,34 @@ static int cmd_print(void *data, const char *input) { break; } printed += aop.size; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } } } } else if (input[1] == 'D') { // "paD" if (input[2] == '?') { - r_cons_printf ("|Usage: paD [hex] print assembly expression from hexpairs and show hexpairs\n"); + rz_cons_printf ("|Usage: paD [hex] print assembly expression from hexpairs and show hexpairs\n"); } else { - r_core_cmdf (core, "pdi@x:%s", input + 2); + rz_core_cmdf (core, "pdi@x:%s", input + 2); } } else if (input[1] == 'd') { // "pad*" switch (input[2]) { case 'e': // "pade" if (input[3] == '?') { - r_cons_printf ("|Usage: pade [hex] print ESIL expression from hexpairs\n"); + rz_cons_printf ("|Usage: pade [hex] print ESIL expression from hexpairs\n"); } else { int printed = 0; int bufsz; - RAnalOp aop = { 0 }; + RzAnalOp aop = { 0 }; char *hex_arg = calloc (1, strlen (arg) + 1); if (hex_arg) { - bufsz = r_hex_str2bin (arg + 1, (ut8 *)hex_arg); + bufsz = rz_hex_str2bin (arg + 1, (ut8 *)hex_arg); while (printed < bufsz) { aop.size = 0; - if (r_anal_op (core->anal, &aop, core->offset, + if (rz_anal_op (core->anal, &aop, core->offset, (const ut8 *)hex_arg + printed, bufsz - printed, R_ANAL_OP_MASK_ESIL) > 0) { const char *str = R_STRBUF_SAFEGET (&aop.esil); - r_cons_println (str); + rz_cons_println (str); } else { eprintf ("Cannot decode instruction\n"); break; @@ -4731,7 +4731,7 @@ static int cmd_print(void *data, const char *input) { break; } printed += aop.size; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } free (hex_arg); } @@ -4741,47 +4741,47 @@ static int cmd_print(void *data, const char *input) { __cmd_pad (core, arg); break; case '?': // "pad?" - r_cons_printf ("|Usage: pad [hex] print assembly expression from hexpairs\n"); + rz_cons_printf ("|Usage: pad [hex] print assembly expression from hexpairs\n"); break; default: - r_cons_printf ("|Usage: pa[edD] [asm|hex] print (dis)assembled\n"); + rz_cons_printf ("|Usage: pa[edD] [asm|hex] print (dis)assembled\n"); break; } } else if (input[1] == '?') { - r_core_cmd_help (core, help_msg_pa); + rz_core_cmd_help (core, help_msg_pa); } else { int i; int bytes; - r_asm_set_pc (core->rasm, core->offset); - RAsmCode *acode = r_asm_massemble (core->rasm, input + 1); + rz_asm_set_pc (core->rasm, core->offset); + RzAsmCode *acode = rz_asm_massemble (core->rasm, input + 1); if (acode) { bytes = acode->len; for (i = 0; i < bytes; i++) { ut8 b = acode->bytes[i]; // core->print->big_endian? (bytes - 1 - i): i ]; - r_cons_printf ("%02x", b); + rz_cons_printf ("%02x", b); } - r_cons_newline (); - r_asm_code_free (acode); + rz_cons_newline (); + rz_asm_code_free (acode); } } } break; case 'b': { // "pb" if (input[1] == '?') { - r_cons_printf ("|Usage: p[bB] [len] ([skip]) ; see also pB and pxb\n"); + rz_cons_printf ("|Usage: p[bB] [len] ([skip]) ; see also pB and pxb\n"); } else if (l != 0) { int from, to; const int size = len * 8; char *spc, *buf = malloc (size + 1); spc = strchr (input, ' '); if (spc) { - len = r_num_math (core->num, spc + 1); + len = rz_num_math (core->num, spc + 1); if (len < 1) { len = 1; } spc = strchr (spc + 1, ' '); if (spc) { - from = r_num_math (core->num, spc + 1); + from = rz_num_math (core->num, spc + 1); } else { from = 0; } @@ -4792,7 +4792,7 @@ static int cmd_print(void *data, const char *input) { } if (buf) { int buf_len; - r_str_bits (buf, block, size, NULL); + rz_str_bits (buf, block, size, NULL); buf_len = strlen (buf); if (from >= 0 && to >= 0) { if (from >= buf_len) { @@ -4802,7 +4802,7 @@ static int cmd_print(void *data, const char *input) { buf[to] = 0; //buf[buf_len - 1] = 0; } - r_cons_println (buf + from); + rz_cons_println (buf + from); } free (buf); } else { @@ -4813,18 +4813,18 @@ static int cmd_print(void *data, const char *input) { break; case 'B': { // "pB" if (input[1] == '?') { - r_cons_printf ("|Usage: p[bB] [len] bitstream of N bytes\n"); + rz_cons_printf ("|Usage: p[bB] [len] bitstream of N bytes\n"); } else if (l != 0) { int size; char *buf; - if (!r_core_block_size (core, len)) { + if (!rz_core_block_size (core, len)) { len = core->blocksize; } size = len * 8; buf = malloc (size + 1); if (buf) { - r_str_bits (buf, core->block, size, NULL); - r_cons_println (buf); + rz_str_bits (buf, core->block, size, NULL); + rz_cons_println (buf); free (buf); } else { eprintf ("ERROR: Cannot malloc %d byte(s)\n", size); @@ -4845,44 +4845,44 @@ static int cmd_print(void *data, const char *input) { break; case 'f': // "pIf" { - const RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + const RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { - r_core_print_disasm_instructions (core, - r_anal_function_linear_size ((RAnalFunction *) f), 0); + rz_core_print_disasm_instructions (core, + rz_anal_function_linear_size ((RzAnalFunction *) f), 0); break; } } case 'd': // "pId" is the same as pDi if (l) { - r_core_disasm_pdi (core, 0, l, 0); + rz_core_disasm_pdi (core, 0, l, 0); } break; case '?': // "pi?" - r_cons_printf ("|Usage: p[iI][df] [len] print N instructions/bytes" + rz_cons_printf ("|Usage: p[iI][df] [len] print N instructions/bytes" "(f=func) (see pi? and pdi)\n"); break; default: if (l) { - r_core_print_disasm_instructions (core, l, 0); + rz_core_print_disasm_instructions (core, l, 0); } } break; case 'i': // "pi" switch (input[1]) { case '?': - // r_cons_printf ("|Usage: pi[defj] [num]\n"); - r_core_cmd_help (core, help_msg_pi); + // rz_cons_printf ("|Usage: pi[defj] [num]\n"); + rz_core_cmd_help (core, help_msg_pi); break; case 'u': // "piu" disasm until ret/jmp . todo: accept arg to specify type disasm_until_ret (core, core->offset, input[2], input + 2); break; case 'x': // "pix" - __cmd_pad (core, r_str_trim_head_ro (input + 2)); + __cmd_pad (core, rz_str_trim_head_ro (input + 2)); break; case 'a': // "pia" is like "pda", but with "pi" output if (l != 0) { - r_core_print_disasm_all (core, core->offset, + rz_core_print_disasm_all (core, core->offset, l, len, 'i'); } break; @@ -4893,23 +4893,23 @@ static int cmd_print(void *data, const char *input) { break; case 'd': // "pid" is the same as pdi if (l != 0) { - r_core_disasm_pdi (core, l, 0, 0); + rz_core_disasm_pdi (core, l, 0, 0); } break; case 'e': // "pie" if (l != 0) { - r_core_disasm_pdi (core, l, 0, 'e'); + rz_core_disasm_pdi (core, l, 0, 'e'); } break; case 'f': // "pif" if (input[2] == '?') { // "pif?" - r_core_cmd_help(core, help_msg_pif); + rz_core_cmd_help(core, help_msg_pif); } else if (input[2] == 'j') { - r_core_cmdf (core, "pdfj%s", input + 3); + rz_core_cmdf (core, "pdfj%s", input + 3); } else if (input[2] == 'c') { // "pifc" - RListIter *iter; - RAnalRef *refi; - RList *refs = NULL; + RzListIter *iter; + RzAnalRef *refi; + RzList *refs = NULL; PJ *pj = NULL; // check for bounds @@ -4920,7 +4920,7 @@ static int cmd_print(void *data, const char *input) { } } // get function in current offset - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); // validate that a function was found in the given address @@ -4928,42 +4928,42 @@ static int cmd_print(void *data, const char *input) { // print empty json object if (pj) { pj_end (pj); - r_cons_println (pj_string(pj)); + rz_cons_println (pj_string(pj)); pj_free (pj); } break; } // get all the calls of the function - refs = r_core_anal_fcn_get_calls (core, f); + refs = rz_core_anal_fcn_get_calls (core, f); // sanity check - if (!r_list_empty (refs)) { + if (!rz_list_empty (refs)) { // store current configurations - RConfigHold *hc = r_config_hold_new (core->config); - r_config_hold_i (hc, "asm.offset", NULL); - r_config_hold_i (hc, "asm.comments", NULL); - r_config_hold_i (hc, "asm.tabs", NULL); - r_config_hold_i (hc, "asm.bytes", NULL); - r_config_hold_i (hc, "emu.str", NULL); + RConfigHold *hc = rz_config_hold_new (core->config); + rz_config_hold_i (hc, "asm.offset", NULL); + rz_config_hold_i (hc, "asm.comments", NULL); + rz_config_hold_i (hc, "asm.tabs", NULL); + rz_config_hold_i (hc, "asm.bytes", NULL); + rz_config_hold_i (hc, "emu.str", NULL); // temporarily replace configurations - r_config_set_i (core->config, "asm.offset", false); - r_config_set_i (core->config, "asm.comments", false); - r_config_set_i (core->config, "asm.tabs", 0); - r_config_set_i (core->config, "asm.bytes", false); - r_config_set_i (core->config, "emu.str", false); + rz_config_set_i (core->config, "asm.offset", false); + rz_config_set_i (core->config, "asm.comments", false); + rz_config_set_i (core->config, "asm.tabs", 0); + rz_config_set_i (core->config, "asm.bytes", false); + rz_config_set_i (core->config, "emu.str", false); // iterate over all call references - r_list_foreach (refs, iter, refi) { + rz_list_foreach (refs, iter, refi) { if (pj) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, refi->addr, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, refi->addr, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); - char *dst = r_str_newf ((f? f->name: "0x%08"PFMT64x), refi->addr); + char *dst = rz_str_newf ((f? f->name: "0x%08"PFMT64x), refi->addr); char *dst2 = NULL; - RAnalOp *op = r_core_anal_op (core, refi->addr, R_ANAL_OP_MASK_BASIC); - RBinReloc *rel = r_core_getreloc (core, refi->addr, op->size); + RzAnalOp *op = rz_core_anal_op (core, refi->addr, R_ANAL_OP_MASK_BASIC); + RBinReloc *rel = rz_core_getreloc (core, refi->addr, op->size); if (rel) { if (rel && rel->import && rel->import->name) { dst2 = rel->import->name; @@ -4978,42 +4978,42 @@ static int cmd_print(void *data, const char *input) { pj_kn (pj, "addr", refi->addr); pj_kn (pj, "at", refi->at); pj_end (pj); - r_anal_op_free (op); + rz_anal_op_free (op); } else { - char *s = r_core_cmd_strf (core, "pdi %i @ 0x%08"PFMT64x, 1, refi->at); - r_cons_printf ("%s", s); + char *s = rz_core_cmd_strf (core, "pdi %i @ 0x%08"PFMT64x, 1, refi->at); + rz_cons_printf ("%s", s); } } // restore saved configuration - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); } // print json object if (pj) { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } } else if (l != 0) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { ut32 bsz = core->blocksize; - // int fsz = r_anal_function_realsize (f); - int fsz = r_anal_function_linear_size (f); // we want max-min here - r_core_block_size (core, fsz); - r_core_print_disasm_instructions (core, fsz, 0); - r_core_block_size (core, bsz); + // int fsz = rz_anal_function_realsize (f); + int fsz = rz_anal_function_linear_size (f); // we want max-min here + rz_core_block_size (core, fsz); + rz_core_print_disasm_instructions (core, fsz, 0); + rz_core_block_size (core, bsz); } else { - r_core_print_disasm_instructions (core, + rz_core_print_disasm_instructions (core, core->blocksize, l); } } break; case 'r': // "pir" { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { func_walk_blocks (core, f, input[2], 'I', input[2] == '.'); @@ -5025,9 +5025,9 @@ static int cmd_print(void *data, const char *input) { break; case 'b': // "pib" { - RAnalBlock *b = r_anal_bb_from_offset (core->anal, core->offset); + RzAnalBlock *b = rz_anal_bb_from_offset (core->anal, core->offset); if (b) { - r_core_print_disasm_instructions (core, b->size - (core->offset - b->addr), 0); + rz_core_print_disasm_instructions (core, b->size - (core->offset - b->addr), 0); } else { eprintf ("Cannot find function at 0x%08"PFMT64x "\n", core->offset); core->num->value = 0; @@ -5036,7 +5036,7 @@ static int cmd_print(void *data, const char *input) { break; default: // "pi" if (l != 0) { - r_core_print_disasm_instructions (core, 0, l); + rz_core_print_disasm_instructions (core, 0, l); } break; } @@ -5051,16 +5051,16 @@ static int cmd_print(void *data, const char *input) { if (input[1] && input[2]) { // "pd--" // context disasm if (!strncmp (input + 1, "--", 2)) { - char *offs = r_str_newf ("%s", input + 2); + char *offs = rz_str_newf ("%s", input + 2); if (offs) { - ut64 sz = r_num_math (core->num, offs); + ut64 sz = rz_num_math (core->num, offs); char *fmt; if (((st64)sz * -1) > core->offset) { // the offset is smaller than the negative value // so only print -offset - fmt = r_str_newf ("d %"PFMT64d, -1 * core->offset); + fmt = rz_str_newf ("d %"PFMT64d, -1 * core->offset); } else { - fmt = r_str_newf ("d %s", input + 2); + fmt = rz_str_newf ("d %s", input + 2); } if (fmt) { cmd_print (core, fmt); @@ -5076,7 +5076,7 @@ static int cmd_print(void *data, const char *input) { } if (input[1] == 'x') { // pdx - __cmd_pad (core, r_str_trim_head_ro (input + 2)); + __cmd_pad (core, rz_str_trim_head_ro (input + 2)); return 0; } @@ -5090,7 +5090,7 @@ static int cmd_print(void *data, const char *input) { sp = input + 1; } if (sp) { - int n = (int) r_num_math (core->num, r_str_trim_head_ro (sp)); + int n = (int) rz_num_math (core->num, rz_str_trim_head_ro (sp)); if (!n) { goto beach; } @@ -5109,42 +5109,42 @@ static int cmd_print(void *data, const char *input) { l = use_blocksize; } // may be unnecessary, fixes 'pd 1;pdj 100;pd 1' bug - r_core_block_read (core); + rz_core_block_read (core); switch (input[1]) { case 'C': // "pdC" - r_core_disasm_pdi (core, l, 0, 'C'); + rz_core_disasm_pdi (core, l, 0, 'C'); pd_result = 0; processed_cmd = true; break; case 'c': // "pdc" // "pDc" - r_core_pseudo_code (core, input + 2); + rz_core_pseudo_code (core, input + 2); pd_result = 0; processed_cmd = true; break; case 't': // "pdt" - r_core_disasm_table (core, l, r_str_trim_head_ro (input + 2)); + rz_core_disasm_table (core, l, rz_str_trim_head_ro (input + 2)); pd_result = 0; processed_cmd = true; break; case 'k': // "pdk" -print class { int len = 0; - ut64 at = findClassBounds (core, r_str_trim_head_ro (input + 2), &len); - return r_core_cmdf (core, "pD %d @ %"PFMT64u, len, at); + ut64 at = findClassBounds (core, rz_str_trim_head_ro (input + 2), &len); + return rz_core_cmdf (core, "pD %d @ %"PFMT64u, len, at); } case 'i': // "pdi" // "pDi" processed_cmd = true; if (*input == 'D') { - r_core_disasm_pdi (core, 0, l, 0); + rz_core_disasm_pdi (core, 0, l, 0); } else { - r_core_disasm_pdi (core, l, 0, 0); + rz_core_disasm_pdi (core, l, 0, 0); } pd_result = 0; break; case 'a': // "pda" processed_cmd = true; - r_core_print_disasm_all (core, core->offset, l, len, input[2]); + rz_core_print_disasm_all (core, core->offset, l, len, input[2]); pd_result = true; break; case 'e': // "pde" @@ -5162,7 +5162,7 @@ static int cmd_print(void *data, const char *input) { mode = R_MODE_SIMPLE; // Like pdi } } - r_core_disasm_pde (core, l, mode); + rz_core_disasm_pde (core, l, mode); pd_result = true; break; case 'R': // "pdR" @@ -5177,7 +5177,7 @@ static int cmd_print(void *data, const char *input) { case 'r': // "pdr" processed_cmd = true; { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, 0); // R_ANAL_FCN_TYPE_FCN|R_ANAL_FCN_TYPE_SYM); if (f) { func_walk_blocks (core, f, input[2], 'D', input[2] == '.'); @@ -5190,13 +5190,13 @@ static int cmd_print(void *data, const char *input) { case 'b': // "pdb" processed_cmd = true; if (input[2] == '?') { - r_cons_printf ("Usage: pdb[j] - disassemble basic block\n"); + rz_cons_printf ("Usage: pdb[j] - disassemble basic block\n"); } else { - RAnalBlock *b = r_anal_bb_from_offset (core->anal, core->offset); + RzAnalBlock *b = rz_anal_bb_from_offset (core->anal, core->offset); if (b) { ut8 *block = malloc (b->size + 1); if (block) { - r_io_read_at (core->io, b->addr, block, b->size); + rz_io_read_at (core->io, b->addr, block, b->size); if (input[2] == 'j') { pj = pj_new (); @@ -5204,12 +5204,12 @@ static int cmd_print(void *data, const char *input) { break; } pj_a (pj); - r_core_print_disasm_json (core, b->addr, block, b->size, 0, pj); + rz_core_print_disasm_json (core, b->addr, block, b->size, 0, pj); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } else { - core->num->value = r_core_print_disasm ( + core->num->value = rz_core_print_disasm ( core->print, core, b->addr, block, b->size, 9999, 0, 2, input[2] == 'J', NULL, NULL); } @@ -5225,7 +5225,7 @@ static int cmd_print(void *data, const char *input) { case 's': // "pds" and "pdsf" processed_cmd = true; if (input[2] == '?') { - r_cons_printf ("Usage: pds[bf] - sumarize N bytes or function (pdfs)\n"); + rz_cons_printf ("Usage: pds[bf] - sumarize N bytes or function (pdfs)\n"); } else { disasm_strings (core, input, NULL); } @@ -5233,34 +5233,34 @@ static int cmd_print(void *data, const char *input) { case 'f': // "pdf" processed_cmd = true; if (input[2] == '?') { - r_core_cmd_help(core, help_msg_pdf); + rz_core_cmd_help(core, help_msg_pdf); } else if (input[2] == 's') { // "pdfs" ut64 oseek = core->offset; int oblock = core->blocksize; - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { - ut32 rs = r_anal_function_realsize (f); - ut32 fs = r_anal_function_linear_size (f); - r_core_seek (core, oseek, SEEK_SET); - r_core_block_size (core, R_MAX (rs, fs)); + ut32 rs = rz_anal_function_realsize (f); + ut32 fs = rz_anal_function_linear_size (f); + rz_core_seek (core, oseek, SEEK_SET); + rz_core_block_size (core, R_MAX (rs, fs)); disasm_strings (core, input, f); - r_core_block_size (core, oblock); - r_core_seek (core, oseek, SEEK_SET); + rz_core_block_size (core, oblock); + rz_core_seek (core, oseek, SEEK_SET); } processed_cmd = true; } else { ut32 bsz = core->blocksize; - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ROOT); + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_ROOT); if (!f) { - f = r_anal_get_fcn_in (core->anal, core->offset, 0); + f = rz_anal_get_fcn_in (core->anal, core->offset, 0); } - RListIter *locs_it = NULL; + RzListIter *locs_it = NULL; if (f && input[2] == 'j') { // "pdfj" - RAnalBlock *b; - ut32 fcn_size = r_anal_function_realsize (f); - const char *orig_bb_middle = r_config_get (core->config, "asm.bb.middle"); - r_config_set_i (core->config, "asm.bb.middle", false); + RzAnalBlock *b; + ut32 fcn_size = rz_anal_function_realsize (f); + const char *orig_bb_middle = rz_config_get (core->config, "asm.bb.middle"); + rz_config_set_i (core->config, "asm.bb.middle", false); pj = pj_new (); if (!pj) { break; @@ -5271,13 +5271,13 @@ static int cmd_print(void *data, const char *input) { pj_kn (pj, "addr", f->addr); pj_k (pj, "ops"); pj_a (pj); - r_list_sort (f->bbs, bb_cmpaddr); - r_list_foreach (f->bbs, locs_it, b) { + rz_list_sort (f->bbs, bb_cmpaddr); + rz_list_foreach (f->bbs, locs_it, b) { ut8 *buf = malloc (b->size); if (buf) { - r_io_read_at (core->io, b->addr, buf, b->size); - r_core_print_disasm_json (core, b->addr, buf, b->size, 0, pj); + rz_io_read_at (core->io, b->addr, buf, b->size); + rz_core_print_disasm_json (core, b->addr, buf, b->size, 0, pj); free (buf); } else { eprintf ("cannot allocate %"PFMT64u" byte(s)\n", b->size); @@ -5285,24 +5285,24 @@ static int cmd_print(void *data, const char *input) { } pj_end (pj); pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); pd_result = 0; - r_config_set (core->config, "asm.bb.middle", orig_bb_middle); + rz_config_set (core->config, "asm.bb.middle", orig_bb_middle); } else if (f) { - ut64 linearsz = r_anal_function_linear_size (f); - ut64 realsz = r_anal_function_realsize (f); + ut64 linearsz = rz_anal_function_linear_size (f); + ut64 realsz = rz_anal_function_realsize (f); if (realsz + 4096 < linearsz) { eprintf ("Linear size differs too much from the bbsum, please use pdr instead.\n"); } else { - ut64 at = f->addr; // TODO: should be min from r_anal_fcn_get_range()? + ut64 at = f->addr; // TODO: should be min from rz_anal_fcn_get_range()? ut64 sz = R_MAX (linearsz, realsz); ut8 *buf = calloc (sz, 1); if (buf) { - (void)r_io_read_at (core->io, at, buf, sz); - core->num->value = r_core_print_disasm (core->print, core, at, buf, sz, sz, 0, 1, 0, NULL, f); + (void)rz_io_read_at (core->io, at, buf, sz); + core->num->value = rz_core_print_disasm (core->print, core, at, buf, sz, sz, 0, 1, 0, NULL, f); free (buf); - // r_core_cmdf (core, "pD %d @ 0x%08" PFMT64x, f->_size > 0 ? f->_size: r_anal_function_realsize (f), f->addr); + // rz_core_cmdf (core, "pD %d @ 0x%08" PFMT64x, f->_size > 0 ? f->_size: rz_anal_function_realsize (f), f->addr); } } pd_result = 0; @@ -5312,7 +5312,7 @@ static int cmd_print(void *data, const char *input) { core->num->value = 0; } if (bsz != core->blocksize) { - r_core_block_size (core, bsz); + rz_core_block_size (core, bsz); } } l = 0; @@ -5325,23 +5325,23 @@ static int cmd_print(void *data, const char *input) { case 'l': // "pdl" processed_cmd = true; { - RAsmOp asmop; + RzAsmOp asmop; int j, ret; if (!l) { l = len; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = j = 0; i < core->blocksize && j < l; i += ret, j++) { - ret = r_asm_disassemble (core->rasm, &asmop, block + i, len - i); - if (r_cons_is_breaked ()) { + ret = rz_asm_disassemble (core->rasm, &asmop, block + i, len - i); + if (rz_cons_is_breaked ()) { break; } - r_cons_printf ("%d\n", ret); + rz_cons_printf ("%d\n", ret); if (ret < 1) { ret = 1; } } - r_cons_break_pop (); + rz_cons_break_pop (); pd_result = 0; } break; @@ -5352,7 +5352,7 @@ static int cmd_print(void *data, const char *input) { } else { cmd_pdj (core, input + 2, block); } - r_cons_newline (); + rz_cons_newline (); pd_result = 0; break; case 'J': // pdJ @@ -5366,13 +5366,13 @@ static int cmd_print(void *data, const char *input) { break; case '?': // "pd?" processed_cmd = true; - r_core_cmd_help (core, help_msg_pd); + rz_core_cmd_help (core, help_msg_pd); pd_result = 0; } if (formatted_json) { - if (r_cons_singleton ()->is_html) { - r_cons_singleton ()->is_html = false; - r_cons_singleton ()->was_html = true; + if (rz_cons_singleton ()->is_html) { + rz_cons_singleton ()->is_html = false; + rz_cons_singleton ()->was_html = true; } } if (!processed_cmd) { @@ -5391,13 +5391,13 @@ static int cmd_print(void *data, const char *input) { if (!(block1 = malloc (l))) { break; } - r_io_read_at (core->io, addr - l, block1, l); // core->blocksize); - core->num->value = r_core_print_disasm (core->print, core, addr - l, block1, l, l, 0, 1, formatted_json, NULL, NULL); + rz_io_read_at (core->io, addr - l, block1, l); // core->blocksize); + core->num->value = rz_core_print_disasm (core->print, core, addr - l, block1, l, l, 0, 1, formatted_json, NULL, NULL); } else { // pd int instr_len; - if (!r_core_prevop_addr (core, core->offset, l, &start)) { + if (!rz_core_prevop_addr (core, core->offset, l, &start)) { // anal ignorance. - start = r_core_prevop_addr_force (core, core->offset, l); + start = rz_core_prevop_addr_force (core, core->offset, l); } instr_len = core->offset - start; ut64 prevaddr = core->offset; @@ -5411,16 +5411,16 @@ static int cmd_print(void *data, const char *input) { } block1 = tmpblock; } - r_core_seek (core, prevaddr - instr_len, true); + rz_core_seek (core, prevaddr - instr_len, true); memcpy (block1, block, bs); if (bs1 > bs) { - r_io_read_at (core->io, addr + bs / addrbytes, + rz_io_read_at (core->io, addr + bs / addrbytes, block1 + (bs - bs % addrbytes), bs1 - (bs - bs % addrbytes)); } - core->num->value = r_core_print_disasm (core->print, + core->num->value = rz_core_print_disasm (core->print, core, core->offset, block1, R_MAX (bs, bs1), l, 0, 1, formatted_json, NULL, NULL); - r_core_seek (core, prevaddr, true); + rz_core_seek (core, prevaddr, true); } } } else { @@ -5433,8 +5433,8 @@ l = use_blocksize; } block1 = malloc (addrbytes * l); if (block1) { - r_io_read_at (core->io, addr, block1, addrbytes * l); - core->num->value = r_core_print_disasm (core->print, + rz_io_read_at (core->io, addr, block1, addrbytes * l); + core->num->value = rz_core_print_disasm (core->print, core, addr, block1, addrbytes * l, l, 0, 1, formatted_json, NULL, NULL); } else { eprintf ("Cannot allocate %" PFMT64d " byte(s)\n", addrbytes * l); @@ -5449,7 +5449,7 @@ l = use_blocksize; l /= 4; } } - core->num->value = r_core_print_disasm (core->print, + core->num->value = rz_core_print_disasm (core->print, core, addr, buf, buf_size, l, 0, 0, formatted_json, NULL, NULL); } @@ -5457,7 +5457,7 @@ l = use_blocksize; } free (block1); if (formatted_json) { - r_cons_newline (); + rz_cons_newline (); } } if (processed_cmd) { @@ -5472,16 +5472,16 @@ l = use_blocksize; case 's': // "ps" switch (input[1]) { case '?': // "ps?" - r_core_cmd_help (core, help_msg_ps); + rz_core_cmd_help (core, help_msg_ps); break; case 'j': // "psj" if (l > 0) { if (input[2] == ' ' && input[3]) { - len = r_num_math (core->num, input + 3); + len = rz_num_math (core->num, input + 3); len = R_MIN (len, core->blocksize); } print_json_string (core, (const char *) core->block, len, NULL); - r_cons_newline (); + rz_cons_newline (); } break; case 'i': // "psi" @@ -5497,7 +5497,7 @@ l = use_blocksize; delta = core->offset; } p = buf + delta; - r_io_read_at (core->io, core->offset - delta, buf, 1024); + rz_io_read_at (core->io, core->offset - delta, buf, 1024); for (b = p; b > buf; b--) { if (!IS_PRINTABLE (*b)) { b++; @@ -5511,16 +5511,16 @@ l = use_blocksize; break; } } - r_cons_strcat ((const char *) b); - r_cons_newline (); - // r_print_string (core->print, core->offset, b, + rz_cons_strcat ((const char *) b); + rz_cons_newline (); + // rz_print_string (core->print, core->offset, b, // (size_t)(e-b), 0); free (buf); } break; case 'x': // "psx" if (l > 0) { - r_print_string (core->print, core->offset, block, len, R_PRINT_STRING_ESC_NL); + rz_print_string (core->print, core->offset, block, len, R_PRINT_STRING_ESC_NL); } break; case 'b': // "psb" @@ -5530,7 +5530,7 @@ l = use_blocksize; int i, j, hasnl = 0; if (s) { if (!quiet) { - r_print_offset (core->print, core->offset, 0, 0, 0, 0, NULL); + rz_print_offset (core->print, core->offset, 0, 0, 0, 0, NULL); } // TODO: filter more chars? for (i = j = 0; i < core->blocksize; i++) { @@ -5539,9 +5539,9 @@ l = use_blocksize; if (!hasnl) { s[j] = 0; if (*s) { - r_cons_println (s); + rz_cons_println (s); if (!quiet) { - r_print_offset (core->print, core->offset + i, 0, 0, 0, 0, NULL); + rz_print_offset (core->print, core->offset + i, 0, 0, 0, 0, NULL); } } j = 0; @@ -5556,7 +5556,7 @@ l = use_blocksize; } } s[j] = 0; - r_cons_print (s); // TODO: missing newline? + rz_cons_print (s); // TODO: missing newline? free (s); } } @@ -5579,9 +5579,9 @@ l = use_blocksize; s[j] = '\0'; if (input[2] == 'j') { // pszj print_json_string (core, (const char *) s, j, NULL); - r_cons_newline (); + rz_cons_newline (); } else { - r_cons_println (s); + rz_cons_println (s); } free (s); } @@ -5594,9 +5594,9 @@ l = use_blocksize; if (mylen < core->blocksize) { if (input[2] == 'j') { // pspj print_json_string (core, (const char *) core->block + 1, mylen, NULL); - r_cons_newline (); + rz_cons_newline (); } else { - r_print_string (core->print, core->offset, + rz_print_string (core->print, core->offset, core->block + 1, mylen, R_PRINT_STRING_ZEROEND); } core->num->value = mylen; @@ -5609,9 +5609,9 @@ l = use_blocksize; if (l > 0) { if (input[2] == 'j') { // pswj print_json_string (core, (const char *) core->block, len, "wide"); - r_cons_newline (); + rz_cons_newline (); } else { - r_print_string (core->print, core->offset, core->block, len, + rz_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_WIDE | R_PRINT_STRING_ZEROEND); } } @@ -5620,15 +5620,15 @@ l = use_blocksize; if (l > 0) { if (input[2] == 'j') { // psWj print_json_string (core, (const char *) core->block, len, "wide32"); - r_cons_newline (); + rz_cons_newline (); } else { - r_print_string (core->print, core->offset, core->block, len, + rz_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_WIDE32 | R_PRINT_STRING_ZEROEND); } } break; case ' ': // "ps" - r_print_string (core->print, core->offset, core->block, l, 0); + rz_print_string (core->print, core->offset, core->block, l, 0); break; case 'u': // "psu" if (l > 0) { @@ -5648,58 +5648,58 @@ l = use_blocksize; } if (json) { // psuj print_json_string (core, (const char *) core->block, len, "utf16"); - r_cons_newline (); + rz_cons_newline (); } else { - char *str = r_str_utf16_encode ((const char *) core->block, len); - r_cons_println (str); + char *str = rz_str_utf16_encode ((const char *) core->block, len); + rz_cons_println (str); free (str); } } break; case 'q': // "psq" - r_core_cmd0 (core, "pqs"); + rz_core_cmd0 (core, "pqs"); break; case 's': // "pss" if (l > 0) { - int h, w = r_cons_get_size (&h); - int colwidth = r_config_get_i (core->config, "hex.cols") * 2; + int h, w = rz_cons_get_size (&h); + int colwidth = rz_config_get_i (core->config, "hex.cols") * 2; core->print->width = (colwidth == 32)?w: colwidth; // w; int bs = core->blocksize; if (len == bs) { len = (h * w) / 3; - r_core_block_size (core, len); + rz_core_block_size (core, len); } - r_print_string (core->print, core->offset, core->block, + rz_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_WRAP); - r_core_block_size (core, bs); + rz_core_block_size (core, bs); } break; case '+': // "ps+" if (l > 0) { const bool json = input[2] == 'j'; // ps+j - ut64 bitness = r_config_get_i (core->config, "asm.bits"); + ut64 bitness = rz_config_get_i (core->config, "asm.bits"); if (bitness != 32 && bitness != 64) { eprintf ("Error: bitness of %" PFMT64u " not supported\n", bitness); break; } if (*core->block & 0x1) { // "long" string if (bitness == 64) { - r_core_cmdf (core, "ps%c @ 0x%" PFMT64x, json ? 'j' : ' ', *((ut64 *)core->block + 2)); + rz_core_cmdf (core, "ps%c @ 0x%" PFMT64x, json ? 'j' : ' ', *((ut64 *)core->block + 2)); } else { - r_core_cmdf (core, "ps%c @ 0x%" PFMT32x, json ? 'j' : ' ', *((ut32 *)core->block + 2)); + rz_core_cmdf (core, "ps%c @ 0x%" PFMT32x, json ? 'j' : ' ', *((ut32 *)core->block + 2)); } } else if (json) { print_json_string (core, (const char *) core->block + 1, len, NULL); - r_cons_newline (); + rz_cons_newline (); } else { - r_print_string (core->print, core->offset, core->block + 1, + rz_print_string (core->print, core->offset, core->block + 1, len, R_PRINT_STRING_ZEROEND); } } break; default: if (l > 0) { - r_print_string (core->print, core->offset, core->block, + rz_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_ZEROEND); } break; @@ -5707,8 +5707,8 @@ l = use_blocksize; break; case 'm': // "pm" if (input[1] == '?') { - r_cons_printf ("|Usage: pm [file|directory]\n" - "| r_magic will use given file/dir as reference\n" + rz_cons_printf ("|Usage: pm [file|directory]\n" + "| rz_magic will use given file/dir as reference\n" "| output of those magic can contain expressions like:\n" "| foo@0x40 # use 'foo' magic file on address 0x40\n" "| @0x40 # use current magic file on address 0x40\n" @@ -5717,21 +5717,21 @@ l = use_blocksize; "| /m # search for magic signatures\n" ); } else if (input[1] == 'j') { // "pmj" - const char *filename = r_str_trim_head_ro (input + 2); - r_core_magic (core, filename, true, true); + const char *filename = rz_str_trim_head_ro (input + 2); + rz_core_magic (core, filename, true, true); } else { - // XXX: need cmd_magic header for r_core_magic - const char *filename = r_str_trim_head_ro (input + 1); - r_core_magic (core, filename, true, false); + // XXX: need cmd_magic header for rz_core_magic + const char *filename = rz_str_trim_head_ro (input + 1); + rz_core_magic (core, filename, true, false); } break; case 'u': // "pu" if (input[1] == '?') { - r_cons_printf ("|Usage: pu[w] [len] print N url" + rz_cons_printf ("|Usage: pu[w] [len] print N url" "encoded bytes (w=wide)\n"); } else { if (l > 0) { - r_print_string (core->print, core->offset, core->block, len, + rz_print_string (core->print, core->offset, core->block, len, R_PRINT_STRING_URLENCODE | ((input[1] == 'w')? R_PRINT_STRING_WIDE: 0)); } @@ -5739,33 +5739,33 @@ l = use_blocksize; break; case 'c': // "pc" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_pc); + rz_core_cmd_help (core, help_msg_pc); } else if (l) { const ut8 *buf = core->block; int i = 0; int j = 0; if (input[1] == 'A') { // "pcA" - r_cons_printf ("sub_0x%08"PFMT64x ":\n", core->offset); + rz_cons_printf ("sub_0x%08"PFMT64x ":\n", core->offset); for (i = 0; i < len; i++) { - RAsmOp asmop = { + RzAsmOp asmop = { 0 }; - (void) r_asm_disassemble (core->rasm, &asmop, buf + i, len - i); + (void) rz_asm_disassemble (core->rasm, &asmop, buf + i, len - i); int sz = asmop.size; if (sz < 1) { sz = 1; } - r_cons_printf (" .byte "); + rz_cons_printf (" .byte "); for (j = 0; j < sz; j++) { - r_cons_printf ("%s0x%02x", j? ", ": "", buf[i]); + rz_cons_printf ("%s0x%02x", j? ", ": "", buf[i]); i++; } - r_cons_printf (" // %s\n", r_strbuf_get (&asmop.buf_asm)); + rz_cons_printf (" // %s\n", rz_strbuf_get (&asmop.buf_asm)); i--; } - r_cons_printf (".equ shellcode_len, %d\n", len); + rz_cons_printf (".equ shellcode_len, %d\n", len); } else { - r_print_code (core->print, core->offset, core->block, len, input[1]); + rz_print_code (core->print, core->offset, core->block, len, input[1]); } } break; @@ -5807,20 +5807,20 @@ l = use_blocksize; { // TODO: do colormap and palette conversions here int mode = 0; - if (r_config_get (core->config, "scr.color") == 0) { + if (rz_config_get (core->config, "scr.color") == 0) { mode = 'a'; } - int cols = r_config_get_i (core->config, "hex.cols"); - r_cons_image (core->block, core->blocksize, cols, mode); + int cols = rz_config_get_i (core->config, "hex.cols"); + rz_cons_image (core->block, core->blocksize, cols, mode); } break; case 'c': // "prc" // color raw dump if (input[2] == '?') { - r_cons_printf ("prc=e # colorblocks of entropy\n"); - r_core_cmd0 (core, "pz?"); + rz_cons_printf ("prc=e # colorblocks of entropy\n"); + rz_core_cmd0 (core, "pz?"); } else if (input[2] == '=') { if (input[3] == '?') { - r_core_cmd_help (core, help_msg_p_equal); + rz_core_cmd_help (core, help_msg_p_equal); } else { cmd_prc_zoom (core, input + 2); } @@ -5829,20 +5829,20 @@ l = use_blocksize; } break; case '?': - r_core_cmd_help (core, help_msg_pr); + rz_core_cmd_help (core, help_msg_pr); break; case 'g': // "prg" // gunzip switch (input[2]) { case '?': - r_core_cmd_help (core, help_msg_prg); + rz_core_cmd_help (core, help_msg_prg); break; case 'i': // "prgi" { int outlen = 0; int inConsumed = 0; ut8 *out; - out = r_inflate (block, core->blocksize, &inConsumed, &outlen); - r_cons_printf ("%d\n", inConsumed); + out = rz_inflate (block, core->blocksize, &inConsumed, &outlen); + rz_cons_printf ("%d\n", inConsumed); free (out); } break; @@ -5850,8 +5850,8 @@ l = use_blocksize; { int outlen = 0; ut8 *out; - out = r_inflate (block, core->blocksize, NULL, &outlen); - r_cons_printf ("%d\n", outlen); + out = rz_inflate (block, core->blocksize, NULL, &outlen); + rz_cons_printf ("%d\n", outlen); free (out); } break; @@ -5859,9 +5859,9 @@ l = use_blocksize; { int outlen = 0; ut8 *out; - out = r_inflate (block, core->blocksize, NULL, &outlen); + out = rz_inflate (block, core->blocksize, NULL, &outlen); if (out) { - r_cons_memcat ((const char *) out, outlen); + rz_cons_memcat ((const char *) out, outlen); } free (out); } @@ -5880,10 +5880,10 @@ l = use_blocksize; } #else { - int a = r_config_get_i (core->config, "hex.bytes"); - r_config_set_i (core->config, "hex.bytes", false); - r_core_cmdf (core, "px%s", input + 1); - r_config_set_i (core->config, "hex.bytes", a); + int a = rz_config_get_i (core->config, "hex.bytes"); + rz_config_set_i (core->config, "hex.bytes", false); + rz_core_cmdf (core, "px%s", input + 1); + rz_config_set_i (core->config, "hex.bytes", a); } #endif break; @@ -5903,19 +5903,19 @@ l = use_blocksize; if (input[1] == '?') { eprintf ("Usage: p3 [file] - print 3D stereogram image of current block\n"); } else if (input[1] == ' ') { - char *data = r_file_slurp (input + 2, NULL); + char *data = rz_file_slurp (input + 2, NULL); if (!data) { eprintf ("Could not open '%s'.\n", input + 2); break; } - char *res = r_print_stereogram (data, 78, 20); - r_print_stereogram_print (core->print, res); + char *res = rz_print_stereogram (data, 78, 20); + rz_print_stereogram_print (core->print, res); // if (data) eprintf ("%s\n", data); free (res); free (data); } else { - char *res = r_print_stereogram_bytes (block, core->blocksize); - r_print_stereogram_print (core->print, res); + char *res = rz_print_stereogram_bytes (block, core->blocksize); + rz_print_stereogram_print (core->print, res); free (res); } break; @@ -5924,13 +5924,13 @@ l = use_blocksize; break; case 'x': // "px" { - bool show_offset = r_config_get_i (core->config, "hex.offset"); + bool show_offset = rz_config_get_i (core->config, "hex.offset"); if (show_offset) { core->print->flags |= R_PRINT_FLAGS_OFFSET; } else { core->print->flags &= ~R_PRINT_FLAGS_OFFSET; } - int show_header = r_config_get_i (core->config, "hex.header"); + int show_header = rz_config_get_i (core->config, "hex.header"); if (show_header) { core->print->flags |= R_PRINT_FLAGS_HEADER; } else { @@ -5939,21 +5939,21 @@ l = use_blocksize; /* Don't show comments in default case */ core->print->use_comments = false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); switch (input[1]) { case 'j': // "pxj" - r_print_jsondump (core->print, core->block, core->blocksize, 8); + rz_print_jsondump (core->print, core->block, core->blocksize, 8); break; case '/': // "px/" - r_core_print_examine (core, input + 2); + rz_core_print_examine (core, input + 2); break; case '?': - r_core_cmd_help (core, help_msg_px); + rz_core_cmd_help (core, help_msg_px); break; case '0': // "px0" if (l) { - int len = r_str_nlen ((const char *)core->block, core->blocksize); - r_print_bytes (core->print, core->block, len, "%02x"); + int len = rz_str_nlen ((const char *)core->block, core->blocksize); + rz_print_bytes (core->print, core->block, len, "%02x"); } break; case 'a': // "pxa" @@ -5967,7 +5967,7 @@ l = use_blocksize; case 'x': // "pxx" if (l != 0) { core->print->flags |= R_PRINT_FLAGS_NONHEX; - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, 8, 1, 1); core->print->flags &= ~R_PRINT_FLAGS_NONHEX; } @@ -5976,9 +5976,9 @@ l = use_blocksize; if (l != 0) { ut8 *buf = calloc (len, 4); if (buf) { - r_io_read_at (core->io, core->offset, buf, len * 4); + rz_io_read_at (core->io, core->offset, buf, len * 4); core->print->flags |= R_PRINT_FLAGS_NONHEX; - r_print_hexdump (core->print, core->offset, buf, len * 4, 8, 1, 1); + rz_print_hexdump (core->print, core->offset, buf, len * 4, 8, 1, 1); core->print->flags &= ~R_PRINT_FLAGS_NONHEX; free (buf); } @@ -5986,7 +5986,7 @@ l = use_blocksize; break; case 'A': // "pxA" if (input[2] == '?') { - r_core_cmd_help (core, help_msg_pxA); + rz_core_cmd_help (core, help_msg_pxA); } else if (l) { cmd_print_pxA (core, len, input + 2); } @@ -6000,30 +6000,30 @@ l = use_blocksize; if (c == 0) { ut64 ea = core->offset + i; if (core->print->pava) { - ut64 va = r_io_p2v (core->io, ea); + ut64 va = rz_io_p2v (core->io, ea); if (va != UT64_MAX) { ea = va; } } - r_print_section (core->print, ea); - r_print_offset (core->print, ea, 0, 0, 0, 0, NULL); + rz_print_section (core->print, ea); + rz_print_offset (core->print, ea, 0, 0, 0, 0, NULL); } - r_str_bits (buf, core->block + i, 8, NULL); + rz_str_bits (buf, core->block + i, 8, NULL); // split bits memmove (buf + 5, buf + 4, 5); buf[4] = 0; - r_print_cursor (core->print, i, 1, 1); - r_cons_printf ("%s.%s ", buf, buf + 5); - r_print_cursor (core->print, i, 1, 0); + rz_print_cursor (core->print, i, 1, 1); + rz_cons_printf ("%s.%s ", buf, buf + 5); + rz_print_cursor (core->print, i, 1, 0); if (c == 3) { const ut8 *b = core->block + i - 3; int (*k) (const ut8 *, int) = cmd_pxb_k; char (*p) (char) = cmd_pxb_p; n = k (b, 0) | k (b, 1) | k (b, 2) | k (b, 3); - r_cons_printf ("0x%08x %c%c%c%c\n", + rz_cons_printf ("0x%08x %c%c%c%c\n", n, p (b[0]), p (b[1]), p (b[2]), p (b[3])); c = -1; } @@ -6035,15 +6035,15 @@ l = use_blocksize; int ocomments = core->print->use_comments; core->print->use_comments = core->print->flags & R_PRINT_FLAGS_COMMENT; if (l) { - ut64 from = r_config_get_i (core->config, "diff.from"); - ut64 to = r_config_get_i (core->config, "diff.to"); + ut64 from = rz_config_get_i (core->config, "diff.from"); + ut64 to = rz_config_get_i (core->config, "diff.to"); if (from == to && !from) { - r_core_block_size (core, len); + rz_core_block_size (core, len); len = core->blocksize; - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, core->blocksize, 16, 1, 1); } else { - r_core_print_cmp (core, from, to); + rz_core_print_cmp (core, from, to); } core->num->value = len; } @@ -6052,14 +6052,14 @@ l = use_blocksize; break; case 'i': // "pxi" if (l != 0) { - core->print->show_offset = r_config_get_i (core->config, "hex.offset"); - r_print_hexii (core->print, core->offset, core->block, - core->blocksize, r_config_get_i (core->config, "hex.cols")); + core->print->show_offset = rz_config_get_i (core->config, "hex.offset"); + rz_print_hexii (core->print, core->offset, core->block, + core->blocksize, rz_config_get_i (core->config, "hex.cols")); } break; case 'o': // "pxo" if (l != 0) { - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, 8, 1, 1); } break; @@ -6068,9 +6068,9 @@ l = use_blocksize; ut64 origin = core->offset; const char *arg = strchr (input, ' '); if (arg) { - origin = r_num_math (core->num, arg + 1); + origin = rz_num_math (core->num, arg + 1); } - // _pointer_table does r_core_cmd with @, so it modifies core->block + // _pointer_table does rz_core_cmd with @, so it modifies core->block // and this results in an UAF access when iterating over the jmptable // so we do a new allocation to avoid that issue ut8 *block = calloc (len, 1); @@ -6083,32 +6083,32 @@ l = use_blocksize; break; case 'd': // "pxd" if (input[2] == '?') { - r_core_cmd_help (core, help_msg_pxd); + rz_core_cmd_help (core, help_msg_pxd); } else if (l != 0) { switch (input[2]) { case '1': // 1 byte signed words (byte) - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, -1, 4, 1); break; case '2': // 2 byte signed words (short) - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, -10, 2, 1); break; case '8': - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, -8, 4, 1); break; case '4': case ' ': case 0: // 4 byte signed words - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, 10, 4, 1); break; default: - r_core_cmd_help (core, help_msg_pxd); + rz_core_cmd_help (core, help_msg_pxd); break; } } @@ -6116,22 +6116,22 @@ l = use_blocksize; case 'w': // "pxw" if (l != 0) { if (input[2] == 'j') { - r_print_jsondump (core->print, core->block, len, 32); + rz_print_jsondump (core->print, core->block, len, 32); } else { - r_print_hexdump (core->print, core->offset, core->block, len, 32, 4, 1); + rz_print_hexdump (core->print, core->offset, core->block, len, 32, 4, 1); } } break; case 'W': // "pxW" if (l) { - bool printOffset = (input[2] != 'q' && r_config_get_i (core->config, "hex.offset")); + bool printOffset = (input[2] != 'q' && rz_config_get_i (core->config, "hex.offset")); len = len - (len % 4); for (i = 0; i < len; i += 4) { const char *a, *b; char *fn; RPrint *p = core->print; - RFlagItem *f; - ut32 v = r_read_ble32 (core->block + i, core->print->big_endian); + RzFlagItem *f; + ut32 v = rz_read_ble32 (core->block + i, core->print->big_endian); if (p && p->colorfor) { a = p->colorfor (p->user, v, true); if (a && *a) { @@ -6142,7 +6142,7 @@ l = use_blocksize; } else { a = b = ""; } - f = r_flag_get_at (core->flags, v, true); + f = rz_flag_get_at (core->flags, v, true); fn = NULL; if (f) { st64 delta = (v - f->offset); @@ -6150,18 +6150,18 @@ l = use_blocksize; if (v == f->offset) { fn = strdup (f->name); } else { - fn = r_str_newf ("%s+%d", + fn = rz_str_newf ("%s+%d", f->name, v - f->offset); } } } if (printOffset) { - r_print_section (core->print, core->offset +i); - r_cons_printf ("0x%08"PFMT64x " %s0x%08"PFMT64x "%s%s%s\n", + rz_print_section (core->print, core->offset +i); + rz_cons_printf ("0x%08"PFMT64x " %s0x%08"PFMT64x "%s%s%s\n", (ut64) core->offset + i, a, (ut64) v, b, fn? " ": "", fn? fn: ""); } else { - r_cons_printf ("%s0x%08"PFMT64x "%s\n", a, (ut64) v, b); + rz_cons_printf ("%s0x%08"PFMT64x "%s\n", a, (ut64) v, b); } free (fn); } @@ -6195,8 +6195,8 @@ l = use_blocksize; if (core->print->hasrefs) { char *rstr = core->print->hasrefs (core->print->user, val, true); if (rstr && *rstr) { - char *ns = r_str_escape (rstr); - pj_ks (pj, "ref", r_str_trim_head_ro (ns)); + char *ns = rz_str_escape (rstr); + pj_ks (pj, "ref", rz_str_trim_head_ro (ns)); pj_end (pj); free (ns); withref = 1; @@ -6208,7 +6208,7 @@ l = use_blocksize; } } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); } else { const int ocols = core->print->cols; @@ -6219,11 +6219,11 @@ l = use_blocksize; } core->print->cols = 1; core->print->flags |= R_PRINT_FLAGS_REFS; - r_cons_break_push (NULL, NULL); - r_print_hexdump (core->print, core->offset, + rz_cons_break_push (NULL, NULL); + rz_print_hexdump (core->print, core->offset, core->block, R_MIN (len, core->blocksize), bitsize, bitsize / 8, 1); - r_cons_break_pop (); + rz_cons_break_pop (); core->print->flags &= ~R_PRINT_FLAGS_REFS; core->print->cols = ocols; } @@ -6232,9 +6232,9 @@ l = use_blocksize; case 'h': // "pxh" if (l) { if (input[2] == 'j') { - r_print_jsondump (core->print, core->block, len, 16); + rz_print_jsondump (core->print, core->block, len, 16); } else { - r_print_hexdump (core->print, core->offset, + rz_print_hexdump (core->print, core->offset, core->block, len, 32, 2, 1); } } @@ -6246,8 +6246,8 @@ l = use_blocksize; const char *a, *b; char *fn; RPrint *p = core->print; - RFlagItem *f; - ut64 v = (ut64) r_read_ble16 (core->block + i, p->big_endian); + RzFlagItem *f; + ut64 v = (ut64) rz_read_ble16 (core->block + i, p->big_endian); if (p && p->colorfor) { a = p->colorfor (p->user, v, true); if (a && *a) { @@ -6258,7 +6258,7 @@ l = use_blocksize; } else { a = b = ""; } - f = r_flag_get_at (core->flags, v, true); + f = rz_flag_get_at (core->flags, v, true); fn = NULL; if (f) { st64 delta = (v - f->offset); @@ -6266,11 +6266,11 @@ l = use_blocksize; if (v == f->offset) { fn = strdup (f->name); } else { - fn = r_str_newf ("%s+%"PFMT64d, f->name, v - f->offset); + fn = rz_str_newf ("%s+%"PFMT64d, f->name, v - f->offset); } } } - r_cons_printf ("0x%08"PFMT64x " %s0x%04"PFMT64x "%s %s\n", + rz_cons_printf ("0x%08"PFMT64x " %s0x%04"PFMT64x "%s %s\n", (ut64) core->offset + i, a, v, b, fn? fn: ""); free (fn); } @@ -6279,23 +6279,23 @@ l = use_blocksize; case 'q': // "pxq" if (l) { if (input[2] == 'j') { - r_print_jsondump (core->print, core->block, len, 64); + rz_print_jsondump (core->print, core->block, len, 64); } else { - r_print_hexdump (core->print, core->offset, core->block, len, 64, 8, 1); + rz_print_hexdump (core->print, core->offset, core->block, len, 64, 8, 1); } } break; case 'Q': // "pxQ" // TODO. show if flag name, or inside function if (l) { - bool printOffset = (input[2] != 'q' && r_config_get_i (core->config, "hex.offset")); + bool printOffset = (input[2] != 'q' && rz_config_get_i (core->config, "hex.offset")); len = len - (len % 8); for (i = 0; i < len; i += 8) { const char *a, *b; char *fn; RPrint *p = core->print; - RFlagItem *f; - ut64 v = r_read_ble64 (core->block + i, p->big_endian); + RzFlagItem *f; + ut64 v = rz_read_ble64 (core->block + i, p->big_endian); if (p && p->colorfor) { a = p->colorfor (p->user, v, true); if (a && *a) { @@ -6306,7 +6306,7 @@ l = use_blocksize; } else { a = b = ""; } - f = r_flag_get_at (core->flags, v, true); + f = rz_flag_get_at (core->flags, v, true); fn = NULL; if (f) { st64 delta = (v - f->offset); @@ -6314,16 +6314,16 @@ l = use_blocksize; if (v == f->offset) { fn = strdup (f->name); } else { - fn = r_str_newf ("%s+%d", f->name, v - f->offset); + fn = rz_str_newf ("%s+%d", f->name, v - f->offset); } } } if (printOffset) { - r_print_section (core->print, core->offset +i); - r_cons_printf ("0x%08"PFMT64x " %s0x%016"PFMT64x "%s %s\n", + rz_print_section (core->print, core->offset +i); + rz_cons_printf ("0x%08"PFMT64x " %s0x%016"PFMT64x "%s %s\n", (ut64) core->offset + i, a, v, b, fn? fn: ""); } else { - r_cons_printf ("%s0x%016"PFMT64x "%s\n", a, v, b); + rz_cons_printf ("%s0x%016"PFMT64x "%s\n", a, v, b); } free (fn); } @@ -6332,7 +6332,7 @@ l = use_blocksize; case 's': // "pxs" if (l) { core->print->flags |= R_PRINT_FLAGS_SPARSE; - r_print_hexdump (core->print, core->offset, core->block, len, 16, 1, 1); + rz_print_hexdump (core->print, core->offset, core->block, len, 16, 1, 1); core->print->flags &= (((ut32) - 1) & (~R_PRINT_FLAGS_SPARSE)); } break; @@ -6410,21 +6410,21 @@ l = use_blocksize; cols = 1; } for (i = 0; i < len; i += cols) { - r_print_addr (core->print, core->offset + i); + rz_print_addr (core->print, core->offset + i); for (j = i; j < i + cols; j += 1) { ut8 *p = (ut8 *) core->block + j; if (j < len) { - r_cons_printf ("\xf0\x9f%c%c ", emoji[*p * 2], emoji[*p * 2 + 1]); + rz_cons_printf ("\xf0\x9f%c%c ", emoji[*p * 2], emoji[*p * 2 + 1]); } else { - r_cons_print (" "); + rz_cons_print (" "); } } - r_cons_print (" "); + rz_cons_print (" "); for (j = i; j < len && j < i + cols; j += 1) { ut8 *p = (ut8 *) core->block + j; - r_print_byte (core->print, "%c", j, *p); + rz_print_byte (core->print, "%c", j, *p); } - r_cons_newline (); + rz_cons_newline (); } } break; @@ -6433,8 +6433,8 @@ l = use_blocksize; /* fallthrough */ default: if (l) { - ut64 from = r_config_get_i (core->config, "diff.from"); - ut64 to = r_config_get_i (core->config, "diff.to"); + ut64 from = rz_config_get_i (core->config, "diff.from"); + ut64 to = rz_config_get_i (core->config, "diff.to"); if (from == to && !from) { const char *sp = NULL; if (input[1] == '.') { @@ -6444,34 +6444,34 @@ l = use_blocksize; sp = input + 1; } if (sp) { - int n = (int) r_num_math (core->num, r_str_trim_head_ro (sp)); + int n = (int) rz_num_math (core->num, rz_str_trim_head_ro (sp)); if (!n) { goto beach; } len = n; } - if (!r_core_block_size (core, len)) { + if (!rz_core_block_size (core, len)) { len = core->blocksize; } - r_core_block_read (core); - r_print_hexdump (core->print, r_core_pava (core, core->offset), + rz_core_block_read (core); + rz_print_hexdump (core->print, rz_core_pava (core, core->offset), core->block, len, 16, 1, 1); } else { - r_core_print_cmp (core, from, to); + rz_core_print_cmp (core, from, to); } core->num->value = len; } break; } - r_cons_break_pop (); + rz_cons_break_pop (); break; case '2': // "p2" if (l) { if (input[1] == '?') { - r_cons_printf ("|Usage: p2 [number of bytes representing tiles]\n" + rz_cons_printf ("|Usage: p2 [number of bytes representing tiles]\n" "NOTE: Only full tiles will be printed\n"); } else { - r_print_2bpp_tiles (core->print, core->block, len / 16); + rz_print_2bpp_tiles (core->print, core->block, len / 16); } } break; @@ -6485,20 +6485,20 @@ l = use_blocksize; memset (buf, 0, malen); switch (input[1]) { case 'd': // "p6d" - if (r_base64_decode (buf, (const char *) block, len)) { - r_cons_println ((const char *) buf); + if (rz_base64_decode (buf, (const char *) block, len)) { + rz_cons_println ((const char *) buf); } else { - eprintf ("r_base64_decode: invalid stream\n"); + eprintf ("rz_base64_decode: invalid stream\n"); } break; case 'e': // "p6e" len = len > core->blocksize? core->blocksize: len; - r_base64_encode ((char *) buf, block, len); - r_cons_println ((const char *) buf); + rz_base64_encode ((char *) buf, block, len); + rz_cons_println ((const char *) buf); break; case '?': default: - r_core_cmd_help(core, help_msg_p6); + rz_core_cmd_help(core, help_msg_p6); break; } free (buf); @@ -6506,22 +6506,22 @@ l = use_blocksize; break; case '8': // "p8" if (input[1] == '?') { - r_cons_printf ("|Usage: p8[fj] [len] 8bit hexpair list of bytes (see pcj)\n"); - r_cons_printf (" p8 : print hexpairs string\n"); - r_cons_printf (" p8f : print hexpairs of function (linear)\n"); - r_cons_printf (" p8j : print hexpairs in JSON array\n"); + rz_cons_printf ("|Usage: p8[fj] [len] 8bit hexpair list of bytes (see pcj)\n"); + rz_cons_printf (" p8 : print hexpairs string\n"); + rz_cons_printf (" p8f : print hexpairs of function (linear)\n"); + rz_cons_printf (" p8j : print hexpairs in JSON array\n"); } else if (l) { - if (!r_core_block_size (core, len)) { + if (!rz_core_block_size (core, len)) { len = core->blocksize; } if (input[1] == 'j') { // "p8j" - r_core_cmdf (core, "pcj %s", input + 2); + rz_core_cmdf (core, "pcj %s", input + 2); } else if (input[1] == 'f') { // "p8f" - r_core_cmdf (core, "p8 $FS @ $FB"); + rz_core_cmdf (core, "p8 $FS @ $FB"); } else { - r_core_block_read (core); + rz_core_block_read (core); block = core->block; - r_print_bytes (core->print, block, len, "%02x"); + rz_print_bytes (core->print, block, len, "%02x"); } } break; @@ -6536,38 +6536,38 @@ l = use_blocksize; break; case 'k': // "pk" if (input[1] == '?') { - r_cons_printf ("|Usage: pk [len] print key in randomart\n"); - r_cons_printf ("|Usage: pkill [process-name]\n"); + rz_cons_printf ("|Usage: pk [len] print key in randomart\n"); + rz_cons_printf ("|Usage: pkill [process-name]\n"); } else if (!strncmp (input, "kill", 4)) { - RListIter *iter; - RDebugPid *pid; + RzListIter *iter; + RzDebugPid *pid; const char *arg = strchr (input, ' '); - RList *pids = (core->dbg->h && core->dbg->h->pids) + RzList *pids = (core->dbg->h && core->dbg->h->pids) ? core->dbg->h->pids (core->dbg, 0): NULL; if (arg && *++arg) { - r_list_foreach (pids, iter, pid) { + rz_list_foreach (pids, iter, pid) { if (strstr (pid->path, arg)) { - r_cons_printf ("dk 9 %d\n", pid->pid); + rz_cons_printf ("dk 9 %d\n", pid->pid); } - // r_debug_kill (core->dbg, pid->pid, pid->pid, 9); // kill -9 + // rz_debug_kill (core->dbg, pid->pid, pid->pid, 9); // kill -9 } } - r_list_free (pids); + rz_list_free (pids); } else if (l > 0) { len = len > core->blocksize? core->blocksize: len; - char *s = r_print_randomart (block, len, core->offset); - r_cons_println (s); + char *s = rz_print_randomart (block, len, core->offset); + rz_cons_println (s); free (s); } break; case 'K': // "pK" if (input[1] == '?') { - r_cons_printf ("|Usage: pK [len] print key in randomart mosaic\n"); + rz_cons_printf ("|Usage: pK [len] print key in randomart mosaic\n"); } else if (l > 0) { len = len > core->blocksize? core->blocksize: len; int w, h; - RConsCanvas *c; - w = r_cons_get_size (&h); + RzConsCanvas *c; + w = rz_cons_get_size (&h); ut64 offset0 = core->offset; int cols = (w / 20); int rows = (h / 12); @@ -6576,22 +6576,22 @@ l = use_blocksize; if (rows < 1) { rows = 1; } - c = r_cons_canvas_new (w, rows * 11); + c = rz_cons_canvas_new (w, rows * 11); for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { - r_cons_canvas_gotoxy (c, j * 20, i * 11); + rz_cons_canvas_gotoxy (c, j * 20, i * 11); core->offset += len; - r_io_read_at (core->io, core->offset, core->block, len); - s = r_print_randomart (core->block, len, core->offset); - r_cons_canvas_write (c, s); + rz_io_read_at (core->io, core->offset, core->block, len); + s = rz_print_randomart (core->block, len, core->offset); + rz_cons_canvas_write (c, s); free (s); } } - r_cons_canvas_print (c); - r_cons_canvas_free (c); - r_io_read_at (core->io, offset0, core->block, len); + rz_cons_canvas_print (c); + rz_cons_canvas_free (c); + rz_io_read_at (core->io, offset0, core->block, len); core->offset = offset0; - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } break; case 'n': // easter @@ -6602,13 +6602,13 @@ l = use_blocksize; case '.': { char nowstr[64] = {0}; - r_print_date_get_now (core->print, nowstr); - r_cons_printf ("%s\n", nowstr); + rz_print_date_get_now (core->print, nowstr); + rz_cons_printf ("%s\n", nowstr); } break; case ' ': case '\0': - // len must be multiple of 4 since r_mem_copyendian move data in fours - sizeof(ut32) + // len must be multiple of 4 since rz_mem_copyendian move data in fours - sizeof(ut32) if (len < sizeof (ut32)) { eprintf ("You should change the block size: b %d\n", (int) sizeof (ut32)); } @@ -6616,11 +6616,11 @@ l = use_blocksize; len = len - (len % sizeof (ut32)); } for (l = 0; l < len; l += sizeof (ut32)) { - r_print_date_unix (core->print, block + l, sizeof (ut32)); + rz_print_date_unix (core->print, block + l, sizeof (ut32)); } break; case 'h': // "pth" - // len must be multiple of 4 since r_mem_copyendian move data in fours - sizeof(ut32) + // len must be multiple of 4 since rz_mem_copyendian move data in fours - sizeof(ut32) if (len < sizeof (ut32)) { eprintf ("You should change the block size: b %d\n", (int) sizeof (ut32)); } @@ -6628,11 +6628,11 @@ l = use_blocksize; len = len - (len % sizeof (ut32)); } for (l = 0; l < len; l += sizeof (ut32)) { - r_print_date_hfs (core->print, block + l, sizeof (ut32)); + rz_print_date_hfs (core->print, block + l, sizeof (ut32)); } break; case 'd': // "ptd" - // len must be multiple of 4 since r_print_date_dos read buf+3 + // len must be multiple of 4 since rz_print_date_dos read buf+3 // if block size is 1 or 5 for example it reads beyond the buffer if (len < sizeof (ut32)) { eprintf ("You should change the block size: b %d\n", (int) sizeof (ut32)); @@ -6641,7 +6641,7 @@ l = use_blocksize; len = len - (len % sizeof (ut32)); } for (l = 0; l < len; l += sizeof (ut32)) { - r_print_date_dos (core->print, block + l, sizeof (ut32)); + rz_print_date_dos (core->print, block + l, sizeof (ut32)); } break; case 'n': // "ptn" @@ -6652,11 +6652,11 @@ l = use_blocksize; len = len - (len % sizeof (ut64)); } for (l = 0; l < len; l += sizeof (ut64)) { - r_print_date_w32 (core->print, block + l, sizeof (ut64)); + rz_print_date_w32 (core->print, block + l, sizeof (ut64)); } break; case '?': - r_core_cmd_help (core, help_msg_pt); + rz_core_cmd_help (core, help_msg_pt); break; } break; @@ -6668,7 +6668,7 @@ l = use_blocksize; break; case 's': // "pqs" case 'z': // for backward compat - len = r_str_nlen ((const char *)block, core->blocksize); + len = rz_str_nlen ((const char *)block, core->blocksize); break; default: if (len < 1) { @@ -6681,66 +6681,66 @@ l = use_blocksize; } if (len > 0) { bool inverted = (input[1] == 'i'); // pqi -- inverted colors - char *res = r_qrcode_gen (block, len, r_config_get_i (core->config, "scr.utf8"), inverted); + char *res = rz_qrcode_gen (block, len, rz_config_get_i (core->config, "scr.utf8"), inverted); if (res) { - r_cons_printf ("%s\n", res); + rz_cons_printf ("%s\n", res); free (res); } } break; case 'z': // "pz" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_pz); + rz_core_cmd_help (core, help_msg_pz); } else { - RIOMap* map; - RListIter *iter; - RList *list = r_core_get_boundaries_prot (core, -1, NULL, "zoom"); - if (list && r_list_length (list) > 0) { - RListIter *iter1 = list->head; - RIOMap* map1 = iter1->data; + RzIOMap* map; + RzListIter *iter; + RzList *list = rz_core_get_boundaries_prot (core, -1, NULL, "zoom"); + if (list && rz_list_length (list) > 0) { + RzListIter *iter1 = list->head; + RzIOMap* map1 = iter1->data; from = map1->itv.addr; - r_list_foreach (list, iter, map) { - to = r_itv_end (map->itv); + rz_list_foreach (list, iter, map) { + to = rz_itv_end (map->itv); } } else { from = core->offset; to = from + core->blocksize; } - ut64 maxsize = r_config_get_i (core->config, "zoom.maxsz"); + ut64 maxsize = rz_config_get_i (core->config, "zoom.maxsz"); int oldva = core->io->va; char *oldmode = NULL; bool do_zoom = true; core->io->va = 0; if (input[1] && input[1] != ' ') { - oldmode = strdup (r_config_get (core->config, "zoom.byte")); - if (!r_config_set (core->config, "zoom.byte", input + 1)) { + oldmode = strdup (rz_config_get (core->config, "zoom.byte")); + if (!rz_config_set (core->config, "zoom.byte", input + 1)) { do_zoom = false; } } if (do_zoom && l > 0) { - r_print_zoom (core->print, core, printzoomcallback, + rz_print_zoom (core->print, core, printzoomcallback, from, to, l, (int) maxsize); } if (oldmode) { - r_config_set (core->config, "zoom.byte", oldmode); + rz_config_set (core->config, "zoom.byte", oldmode); } core->io->va = oldva; R_FREE (oldmode); - r_list_free (list); + rz_list_free (list); } break; default: - r_core_cmd_help (core, help_msg_p); + rz_core_cmd_help (core, help_msg_p); break; } beach: if (tmpseek != UT64_MAX) { - r_core_seek (core, tmpseek, SEEK_SET); - r_core_block_read (core); + rz_core_seek (core, tmpseek, SEEK_SET); + rz_core_block_read (core); } if (tbs != core->blocksize) { - r_core_block_size (core, tbs); + rz_core_block_size (core, tbs); } return ret; } @@ -6760,7 +6760,7 @@ static int lenof(ut64 off, int two) { return strlen (buf); } -R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label) { +RZ_API void rz_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label) { char space[32] = { 0 }; @@ -6769,10 +6769,10 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se bool show_color = p->flags & R_PRINT_FLAGS_COLOR; if (show_color) { char rgbstr[32]; - const char *k = r_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache + const char *k = rz_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache const char *inv = invert ? R_CONS_INVERT (true, true) : ""; if (p->flags & R_PRINT_FLAGS_RAINBOW) { - k = r_cons_rgb_str_off (rgbstr, sizeof (rgbstr), off); + k = rz_cons_rgb_str_off (rgbstr, sizeof (rgbstr), off); } if (offseg) { ut32 s, a; @@ -6780,10 +6780,10 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se s = (off - a) >> seggrn; if (offdec) { snprintf (space, sizeof (space), "%d:%d", s & 0xffff, a & 0xffff); - white = r_str_pad (' ', 9 - strlen (space)); - r_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset); + white = rz_str_pad (' ', 9 - strlen (space)); + rz_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset); } else { - r_cons_printf ("%s%s%04x:%04x%s", k, inv, s & 0xFFFF, a & 0xFFFF, reset); + rz_cons_printf ("%s%s%04x:%04x%s", k, inv, s & 0xFFFF, a & 0xFFFF, reset); } } else { int sz = lenof (off, 0); @@ -6793,39 +6793,39 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se const int label_padding = 10; if (delta > 0) { if (offdec) { - const char *pad = r_str_pad (' ', sz - sz2 + label_padding); - r_cons_printf ("%s%s%s%s+%d%s", k, inv, label, reset, delta, pad); + const char *pad = rz_str_pad (' ', sz - sz2 + label_padding); + rz_cons_printf ("%s%s%s%s+%d%s", k, inv, label, reset, delta, pad); } else { - const char *pad = r_str_pad (' ', sz - sz2 + label_padding); - r_cons_printf ("%s%s%s%s+0x%x%s", k, inv, label, reset, delta, pad); + const char *pad = rz_str_pad (' ', sz - sz2 + label_padding); + rz_cons_printf ("%s%s%s%s+0x%x%s", k, inv, label, reset, delta, pad); } } else { - const char *pad = r_str_pad (' ', sz + label_padding); - r_cons_printf ("%s%s%s%s%s", k, inv, label, reset, pad); + const char *pad = rz_str_pad (' ', sz + label_padding); + rz_cons_printf ("%s%s%s%s%s", k, inv, label, reset, pad); } } else { - const char *pad = r_str_pad (' ', sz - sz2); + const char *pad = rz_str_pad (' ', sz - sz2); if (offdec) { - r_cons_printf ("%s+%d%s", pad, delta, reset); + rz_cons_printf ("%s+%d%s", pad, delta, reset); } else { - r_cons_printf ("%s+0x%x%s", pad, delta, reset); + rz_cons_printf ("%s+0x%x%s", pad, delta, reset); } } } else { if (offdec) { snprintf (space, sizeof (space), "%"PFMT64u, off); - white = r_str_pad (' ', 10 - strlen (space)); - r_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset); + white = rz_str_pad (' ', 10 - strlen (space)); + rz_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset); } else { if (p->wide_offsets) { - r_cons_printf ("%s%s0x%016"PFMT64x "%s", k, inv, off, reset); + rz_cons_printf ("%s%s0x%016"PFMT64x "%s", k, inv, off, reset); } else { - r_cons_printf ("%s%s0x%08"PFMT64x "%s", k, inv, off, reset); + rz_cons_printf ("%s%s0x%08"PFMT64x "%s", k, inv, off, reset); } } } } - r_cons_print (" "); + rz_cons_print (" "); } else { if (offseg) { ut32 s, a; @@ -6833,36 +6833,36 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se s = (off - a) >> seggrn; if (offdec) { snprintf (space, sizeof (space), "%d:%d", s & 0xffff, a & 0xffff); - white = r_str_pad (' ', 9 - strlen (space)); - r_cons_printf ("%s%s%s", white, space, reset); + white = rz_str_pad (' ', 9 - strlen (space)); + rz_cons_printf ("%s%s%s", white, space, reset); } else { - r_cons_printf ("%04x:%04x", s & 0xFFFF, a & 0xFFFF); + rz_cons_printf ("%04x:%04x", s & 0xFFFF, a & 0xFFFF); } } else { int sz = lenof (off, 0); int sz2 = lenof (delta, 1); - const char *pad = r_str_pad (' ', sz - 5 - sz2 - 3); + const char *pad = rz_str_pad (' ', sz - 5 - sz2 - 3); if (delta > 0) { if (offdec) { - r_cons_printf ("%s+%d%s", pad, delta, reset); + rz_cons_printf ("%s+%d%s", pad, delta, reset); } else { - r_cons_printf ("%s+0x%x%s", pad, delta, reset); + rz_cons_printf ("%s+0x%x%s", pad, delta, reset); } } else { if (offdec) { snprintf (space, sizeof (space), "%"PFMT64u, off); - white = r_str_pad (' ', 10 - strlen (space)); - r_cons_printf ("%s%s", white, space); + white = rz_str_pad (' ', 10 - strlen (space)); + rz_cons_printf ("%s%s", white, space); } else { - r_cons_printf ("0x%08"PFMT64x " ", off); + rz_cons_printf ("0x%08"PFMT64x " ", off); } } } } } -// TODO : move to r_util? .. depends on r_cons... -// XXX: dupe of r_print_addr -R_API void r_print_offset(RPrint *p, ut64 off, int invert, int offseg, int offdec, int delta, const char *label) { - r_print_offset_sg(p, off, invert, offseg, 4, offdec, delta, label); +// TODO : move to rz_util? .. depends on rz_cons... +// XXX: dupe of rz_print_addr +RZ_API void rz_print_offset(RPrint *p, ut64 off, int invert, int offseg, int offdec, int delta, const char *label) { + rz_print_offset_sg(p, off, invert, offseg, 4, offdec, delta, label); } diff --git a/libr/core/cmd_project.c b/librz/core/cmd_project.c similarity index 64% rename from libr/core/cmd_project.c rename to librz/core/cmd_project.c index 4ec81ee165..8e50ef4f22 100644 --- a/libr/core/cmd_project.c +++ b/librz/core/cmd_project.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include "r_config.h" -#include "r_core.h" -#include "r_util.h" +#include "rz_config.h" +#include "rz_core.h" +#include "rz_util.h" static const char *help_msg_P[] = { "Usage:", "P[?osi] [file]", "Project management", @@ -35,15 +35,15 @@ static const char *help_msg_Pn[] = { NULL }; -static void cmd_project_init(RCore *core, RCmdDesc *parent) { +static void cmd_project_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, P); DEFINE_CMD_DESCRIPTOR (core, Pn); } static int cmd_project(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; const char *file, *arg; - const char *fileproject = r_config_get (core->config, "prj.name"); + const char *fileproject = rz_config_get (core->config, "prj.name"); char *str = NULL; if (!input) { @@ -65,45 +65,45 @@ static int cmd_project(void *data, const char *input) { switch (input[0]) { case 'c': if (input[1] == ' ') { - r_core_project_cat (core, input + 2); + rz_core_project_cat (core, input + 2); } else { eprintf ("Usage: Pc [prjname]\n"); } break; case 'o': - // if (r_file_is_regular (file)) + // if (rz_file_is_regular (file)) if (input[1] == '&') { - r_core_cmdf (core, "& Po %s", file); + rz_core_cmdf (core, "& Po %s", file); } else if (input[1]) { - r_core_project_open (core, file, false); + rz_core_project_open (core, file, false); } else { if (file && *file) { - r_cons_println (file); + rz_cons_println (file); } } break; case 'd': case '-': - r_core_project_delete (core, file); + rz_core_project_delete (core, file); break; case 's': if (!file || !file[0]) { /* if no argument specified use current project */ file = str; } - if (r_core_project_save (core, file)) { - r_cons_println (file); + if (rz_core_project_save (core, file)) { + rz_cons_println (file); } break; case 'S': if (input[1] == ' ') { - r_core_project_save_script (core, input + 2, R_CORE_PRJ_ALL); + rz_core_project_save_script (core, input + 2, R_CORE_PRJ_ALL); } else { eprintf ("Usage: PS [file]\n"); } break; case 'n': // "Pn" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_Pn); + rz_core_cmd_help (core, help_msg_Pn); } else if (!fileproject || !*fileproject) { eprintf ("No project\n"); } else { @@ -111,12 +111,12 @@ static int cmd_project(void *data, const char *input) { case '-': // "Pn-" /* remove lines containing specific words */ { - FILE *fd = r_sandbox_fopen (str, "w"); + FILE *fd = rz_sandbox_fopen (str, "w"); if (!fd) { eprintf ("Cannot open %s\n", str); } else { - char *str = r_core_project_notes_file (core, fileproject); - char *data = r_file_slurp (str, NULL); + char *str = rz_core_project_notes_file (core, fileproject); + char *data = rz_file_slurp (str, NULL); int del = 0; if (data) { char *ptr, *nl; @@ -143,21 +143,21 @@ static int cmd_project(void *data, const char *input) { break; case ' ': // "Pn " if (input[2] == '-') { - char *str = r_core_project_notes_file (core, fileproject); + char *str = rz_core_project_notes_file (core, fileproject); // edit with cfg.editor - const char *editor = r_config_get (core->config, "cfg.editor"); + const char *editor = rz_config_get (core->config, "cfg.editor"); if (str && *str && editor && *editor) { - r_sys_cmdf ("%s %s", editor, str); + rz_sys_cmdf ("%s %s", editor, str); } else { eprintf ("No cfg.editor configured\n"); } free (str); } else { - // char *str = r_core_project_notes_file (core, fileproject); + // char *str = rz_core_project_notes_file (core, fileproject); // append line to project notes - char *str = r_core_project_notes_file (core, fileproject); - char *data = r_file_slurp (str, NULL); - FILE *fd = r_sandbox_fopen (str, "a"); + char *str = rz_core_project_notes_file (core, fileproject); + char *data = rz_file_slurp (str, NULL); + FILE *fd = rz_sandbox_fopen (str, "a"); if (fd) { fprintf (fd, "%s\n", input + 2); fclose (fd); @@ -168,11 +168,11 @@ static int cmd_project(void *data, const char *input) { break; case '+': // "Pn+" { - char *str = r_core_project_notes_file (core, fileproject); - char *data = r_file_slurp (str, NULL); - data = r_str_append (data, input + 2); - data = r_str_append (data, "\n"); - r_file_dump (str, (const ut8*)data, strlen (data), false); + char *str = rz_core_project_notes_file (core, fileproject); + char *data = rz_file_slurp (str, NULL); + data = rz_str_append (data, input + 2); + data = rz_str_append (data, "\n"); + rz_file_dump (str, (const ut8*)data, strlen (data), false); free (data); free (str); } @@ -181,12 +181,12 @@ static int cmd_project(void *data, const char *input) { if (!input[2]) { size_t len = 0; /* get base64 string */ - char *str = r_core_project_notes_file (core, fileproject); + char *str = rz_core_project_notes_file (core, fileproject); if (str) { - char *data = r_file_slurp (str, &len); - char *res = r_base64_encode_dyn (data, (int)len); + char *data = rz_file_slurp (str, &len); + char *res = rz_base64_encode_dyn (data, (int)len); if (res) { - r_cons_println (res); + rz_cons_println (res); free (res); } free (data); @@ -194,11 +194,11 @@ static int cmd_project(void *data, const char *input) { } } else if (input[2] == ' ') { /* set base64 string */ - ut8 *data = r_base64_decode_dyn (input + 3, -1); + ut8 *data = rz_base64_decode_dyn (input + 3, -1); if (data) { - char *str = r_core_project_notes_file (core, fileproject); + char *str = rz_core_project_notes_file (core, fileproject); if (str) { - r_file_dump (str, data, strlen ((const char *) data), 0); + rz_file_dump (str, data, strlen ((const char *) data), 0); free (str); } free (data); @@ -208,14 +208,14 @@ static int cmd_project(void *data, const char *input) { } break; case 'x': // "Pnx" - r_core_project_execute_cmds (core, fileproject); + rz_core_project_execute_cmds (core, fileproject); break; case 0: // "Pn" { - char *str = r_core_project_notes_file (core, fileproject); - char *data = r_file_slurp (str, NULL); + char *str = rz_core_project_notes_file (core, fileproject); + char *data = rz_file_slurp (str, NULL); if (data) { - r_cons_println (data); + rz_cons_println (data); free (data); } free (str); @@ -226,17 +226,17 @@ static int cmd_project(void *data, const char *input) { break; case 'i': if (file && *file) { - char *prjName = r_core_project_info (core, file); - r_cons_println (prjName); + char *prjName = rz_core_project_info (core, file); + rz_cons_println (prjName); free (prjName); } break; case 0: case 'j': - r_core_project_list (core, input[0]); + rz_core_project_list (core, input[0]); break; default: - r_core_cmd_help (core, help_msg_P); + rz_core_cmd_help (core, help_msg_P); break; } free (str); diff --git a/libr/core/cmd_quit.c b/librz/core/cmd_quit.c similarity index 76% rename from libr/core/cmd_quit.c rename to librz/core/cmd_quit.c index b689f9152b..d4608f1858 100644 --- a/libr/core/cmd_quit.c +++ b/librz/core/cmd_quit.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2016 - pancake */ -#include "r_core.h" +#include "rz_core.h" static const char *help_msg_q[] = { "Usage:", "q[!][!] [retval]", "", @@ -15,23 +15,23 @@ static const char *help_msg_q[] = { NULL }; -static void cmd_quit_init(RCore *core, RCmdDesc *parent) { +static void cmd_quit_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, q); } static int cmd_Quit(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input[0] == '!') { if (input[1] == '!') { - if (!r_sandbox_enable (false)) { + if (!rz_sandbox_enable (false)) { exit (0); } return -2; } - r_config_set (core->config, "scr.histsave", "false"); + rz_config_set (core->config, "scr.histsave", "false"); } if (IS_DIGIT (input[0]) || input[0] == ' ') { - core->num->value = r_num_math (core->num, input); + core->num->value = rz_num_math (core->num, input); } else { core->num->value = -1; } @@ -39,11 +39,11 @@ static int cmd_Quit(void *data, const char *input) { } static int cmd_quit(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input) switch (*input) { case '?': - r_core_cmd_help (core, help_msg_q); + rz_core_cmd_help (core, help_msg_q); break; case '!': return cmd_Quit (core, input); @@ -55,7 +55,7 @@ static int cmd_quit(void *data, const char *input) { input++; } if (*input) { - r_num_math (core->num, input); + rz_num_math (core->num, input); } else { core->num->value = 0LL; } @@ -71,7 +71,7 @@ static int cmd_quit(void *data, const char *input) { } else if (input[1] == 'n') { core->num->value += 2; } - //exit (*input?r_num_math (core->num, input+1):0); + //exit (*input?rz_num_math (core->num, input+1):0); //if (core->http_up) return false; // cancel quit when http is running return -2; } diff --git a/libr/core/cmd_search.c b/librz/core/cmd_search.c similarity index 62% rename from libr/core/cmd_search.c rename to librz/core/cmd_search.c index 35682999f2..4e6997924f 100644 --- a/libr/core/cmd_search.c +++ b/librz/core/cmd_search.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2010-2019 - pancake */ #include -#include -#include -#include "r_io.h" -#include "r_list.h" -#include "r_types_base.h" +#include +#include +#include "rz_io.h" +#include "rz_list.h" +#include "rz_types_base.h" #include "cmd_search_rop.c" static int cmd_search(void *data, const char *input); @@ -157,8 +157,8 @@ static int searchshow = 0; static const char *searchprefix = NULL; struct search_parameters { - RCore *core; - RList *boundaries; + RzCore *core; + RzList *boundaries; const char *mode; const char *cmd_hit; int outmode; // 0 or R_MODE_RADARE or R_MODE_JSON @@ -172,7 +172,7 @@ struct endlist_pair { int delay_size; }; -static void cmd_search_init(RCore *core, RCmdDesc *parent) { +static void cmd_search_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR_SPECIAL (core, /, slash); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, /a, slash_a); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, /c, slash_c); @@ -182,11 +182,11 @@ static void cmd_search_init(RCore *core, RCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR_SPECIAL (core, /x, slash_x); } -static int search_hash(RCore *core, const char *hashname, const char *hashstr, ut32 minlen, ut32 maxlen, struct search_parameters *param) { - RIOMap *map; +static int search_hash(RzCore *core, const char *hashname, const char *hashstr, ut32 minlen, ut32 maxlen, struct search_parameters *param) { + RzIOMap *map; ut8 *buf; int i, j; - RListIter *iter; + RzListIter *iter; if (!minlen || minlen == UT32_MAX) { minlen = core->blocksize; @@ -195,15 +195,15 @@ static int search_hash(RCore *core, const char *hashname, const char *hashstr, u maxlen = minlen; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (j = minlen; j <= maxlen; j++) { ut32 len = j; eprintf ("Searching %s for %d byte length.\n", hashname, j); - r_list_foreach (param->boundaries, iter, map) { - if (r_cons_is_breaked ()) { + rz_list_foreach (param->boundaries, iter, map) { + if (rz_cons_is_breaked ()) { break; } - ut64 from = map->itv.addr, to = r_itv_end (map->itv); + ut64 from = map->itv.addr, to = rz_itv_end (map->itv); st64 bufsz; bufsz = to - from; if (len > bufsz) { @@ -218,12 +218,12 @@ static int search_hash(RCore *core, const char *hashname, const char *hashstr, u eprintf ("Search in range 0x%08"PFMT64x " and 0x%08"PFMT64x "\n", from, to); int blocks = (int) (to - from - len); eprintf ("Carving %d blocks...\n", blocks); - (void) r_io_read_at (core->io, from, buf, bufsz); + (void) rz_io_read_at (core->io, from, buf, bufsz); for (i = 0; (from + i + len) < to; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - char *s = r_hash_to_string (NULL, hashname, buf + i, len); + char *s = rz_hash_to_string (NULL, hashname, buf + i, len); if (!(i % 5)) { eprintf ("%d\r", i); } @@ -234,7 +234,7 @@ static int search_hash(RCore *core, const char *hashname, const char *hashstr, u // eprintf ("0x%08"PFMT64x" %s\n", from+i, s); if (!strcmp (s, hashstr)) { eprintf ("Found at 0x%"PFMT64x "\n", from + i); - r_cons_printf ("f hash.%s.%s = 0x%"PFMT64x "\n", + rz_cons_printf ("f hash.%s.%s = 0x%"PFMT64x "\n", hashname, hashstr, from + i); free (s); free (buf); @@ -245,28 +245,28 @@ static int search_hash(RCore *core, const char *hashname, const char *hashstr, u free (buf); } } - r_cons_break_pop (); + rz_cons_break_pop (); eprintf ("No hashes found\n"); return 0; hell: return -1; } -static void cmd_search_bin(RCore *core, RInterval itv) { - ut64 from = itv.addr, to = r_itv_end (itv); +static void cmd_search_bin(RzCore *core, RInterval itv) { + ut64 from = itv.addr, to = rz_itv_end (itv); int size; // , sz = sizeof (buf); int fd = core->file->fd; - RBuffer *b = r_buf_new_with_io (&core->anal->iob, fd); - r_cons_break_push (NULL, NULL); + RBuffer *b = rz_buf_new_with_io (&core->anal->iob, fd); + rz_cons_break_push (NULL, NULL); while (from < to) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - RBuffer *ref = r_buf_new_slice (b, from, to); - RBinPlugin *plug = r_bin_get_binplugin_by_buffer (core->bin, ref); + RBuffer *ref = rz_buf_new_slice (b, from, to); + RBinPlugin *plug = rz_bin_get_binplugin_by_buffer (core->bin, ref); if (plug) { - r_cons_printf ("0x%08" PFMT64x " %s\n", from, plug->name); + rz_cons_printf ("0x%08" PFMT64x " %s\n", from, plug->name); if (plug->size) { RBinOptions opt = { .pluginname = plug->name, @@ -277,30 +277,30 @@ static void cmd_search_bin(RCore *core, RInterval itv) { .rawstr = core->bin->rawstr, .fd = fd, }; - r_bin_open_io (core->bin, &opt); + rz_bin_open_io (core->bin, &opt); size = plug->size (core->bin->cur); if (size > 0) { - r_cons_printf ("size %d\n", size); + rz_cons_printf ("size %d\n", size); } } } - r_buf_free (ref); + rz_buf_free (ref); from++; } - r_buf_free (b); - r_cons_break_pop (); + rz_buf_free (b); + rz_cons_break_pop (); } -static int __prelude_cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { - RCore *core = (RCore *) user; - int depth = r_config_get_i (core->config, "anal.depth"); +static int __prelude_cb_hit(RzSearchKeyword *kw, void *user, ut64 addr) { + RzCore *core = (RzCore *) user; + int depth = rz_config_get_i (core->config, "anal.depth"); // eprintf ("ap: Found function prelude %d at 0x%08"PFMT64x"\n", preludecnt, addr); - r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth); + rz_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth); preludecnt++; return 1; } -R_API int r_core_search_prelude(RCore *core, ut64 from, ut64 to, const ut8 *buf, int blen, const ut8 *mask, int mlen) { +RZ_API int rz_core_search_prelude(RzCore *core, ut64 from, ut64 to, const ut8 *buf, int blen, const ut8 *mask, int mlen) { ut64 at; ut8 *b = (ut8 *) malloc (core->blocksize); if (!b) { @@ -312,75 +312,75 @@ R_API int r_core_search_prelude(RCore *core, ut64 from, ut64 to, const ut8 *buf, free (b); return 0; } - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_kw_add (core->search, r_search_keyword_new (buf, blen, mask, mlen, NULL)); - r_search_begin (core->search); - r_search_set_callback (core->search, &__prelude_cb_hit, core); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_kw_add (core->search, rz_search_keyword_new (buf, blen, mask, mlen, NULL)); + rz_search_begin (core->search); + rz_search_set_callback (core->search, &__prelude_cb_hit, core); preludecnt = 0; for (at = from; at < to; at += core->blocksize) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - if (!r_io_is_valid_offset (core->io, at, 0)) { + if (!rz_io_is_valid_offset (core->io, at, 0)) { break; } - (void)r_io_read_at (core->io, at, b, core->blocksize); - if (r_search_update (core->search, at, b, core->blocksize) == -1) { + (void)rz_io_read_at (core->io, at, b, core->blocksize); + if (rz_search_update (core->search, at, b, core->blocksize) == -1) { eprintf ("search: update read error at 0x%08"PFMT64x "\n", at); break; } } - // r_search_reset might also benifet from having an if(s->data) R_FREE(s->data), but im not sure. + // rz_search_reset might also benifet from having an if(s->data) R_FREE(s->data), but im not sure. //add a commit that puts it in there to this PR if it wouldn't break anything. (don't have to worry about this happening again, since all searches start by resetting core->search) - //For now we will just use r_search_kw_reset - r_search_kw_reset (core->search); + //For now we will just use rz_search_kw_reset + rz_search_kw_reset (core->search); free (b); return preludecnt; } -static int count_functions(RCore *core) { - return r_list_length (core->anal->fcns); +static int count_functions(RzCore *core) { + return rz_list_length (core->anal->fcns); } -R_API int r_core_search_preludes(RCore *core, bool log) { +RZ_API int rz_core_search_preludes(RzCore *core, bool log) { int ret = -1; - const char *prelude = r_config_get (core->config, "anal.prelude"); + const char *prelude = rz_config_get (core->config, "anal.prelude"); ut64 from = UT64_MAX; ut64 to = UT64_MAX; - const char *where = r_config_get (core->config, "anal.in"); + const char *where = rz_config_get (core->config, "anal.in"); - RList *list = r_core_get_boundaries_prot (core, R_PERM_X, where, "search"); - RListIter *iter; - RIOMap *p; + RzList *list = rz_core_get_boundaries_prot (core, R_PERM_X, where, "search"); + RzListIter *iter; + RzIOMap *p; if (!list) { return -1; } int fc0 = count_functions (core); - r_list_foreach (list, iter, p) { + rz_list_foreach (list, iter, p) { if (log) { eprintf ("\r[>] Scanning %s 0x%"PFMT64x " - 0x%"PFMT64x " ", - r_str_rwx_i (p->perm), p->itv.addr, r_itv_end (p->itv)); + rz_str_rwx_i (p->perm), p->itv.addr, rz_itv_end (p->itv)); if (!(p->perm & R_PERM_X)) { eprintf ("skip\n"); continue; } } from = p->itv.addr; - to = r_itv_end (p->itv); + to = rz_itv_end (p->itv); if (prelude && *prelude) { ut8 *kw = malloc (strlen (prelude) + 1); - int kwlen = r_hex_str2bin (prelude, kw); - ret = r_core_search_prelude (core, from, to, kw, kwlen, NULL, 0); + int kwlen = rz_hex_str2bin (prelude, kw); + ret = rz_core_search_prelude (core, from, to, kw, kwlen, NULL, 0); free (kw); } else { - RList *preds = r_anal_preludes (core->anal); + RzList *preds = rz_anal_preludes (core->anal); if (preds) { - RListIter *iter; - RSearchKeyword *kw; - r_list_foreach (preds, iter, kw) { - ret = r_core_search_prelude (core, from, to, + RzListIter *iter; + RzSearchKeyword *kw; + rz_list_foreach (preds, iter, kw) { + ret = rz_core_search_prelude (core, from, to, kw->bin_keyword, kw->keyword_length, kw->bin_binmask, kw->binmask_length); } @@ -402,7 +402,7 @@ R_API int r_core_search_preludes(RCore *core, bool log) { eprintf ("No executable section found, cannot analyze anything. Use 'S' to change or define permissions of sections\n"); } } - r_list_free (list); + rz_list_free (list); return ret; } @@ -422,10 +422,10 @@ static char *getstring(char *b, int l) { return res; } -static int _cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { +static int _cb_hit(RzSearchKeyword *kw, void *user, ut64 addr) { struct search_parameters *param = user; - RCore *core = param->core; - const RSearch *search = core->search; + RzCore *core = param->core; + const RzSearch *search = core->search; ut64 base_addr = 0; bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; int keyword_len = kw ? kw->keyword_length + (search->mode == R_SEARCH_DELTAKEY) : 0; @@ -449,26 +449,26 @@ static int _cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { const int len = keyword_len; char *buf = calloc (1, len + 32 + ctx * 2); type = "string"; - r_io_read_at (core->io, addr - prectx, (ut8 *) buf, len + (ctx * 2)); + rz_io_read_at (core->io, addr - prectx, (ut8 *) buf, len + (ctx * 2)); pre = getstring (buf, prectx); - wrd = r_str_utf16_encode (buf + prectx, len); + wrd = rz_str_utf16_encode (buf + prectx, len); pos = getstring (buf + prectx + len, ctx); if (!pos) { pos = strdup (""); } free (buf); if (param->outmode == R_MODE_JSON) { - char *pre_esc = r_str_escape (pre); - char *pos_esc = r_str_escape (pos); - s = r_str_newf ("%s%s%s", pre_esc, wrd, pos_esc); + char *pre_esc = rz_str_escape (pre); + char *pos_esc = rz_str_escape (pos); + s = rz_str_newf ("%s%s%s", pre_esc, wrd, pos_esc); escaped = true; free (pre_esc); free (pos_esc); } else if (use_color) { - s = r_str_newf (".%s"Color_YELLOW "%s"Color_RESET "%s.", pre, wrd, pos); + s = rz_str_newf (".%s"Color_YELLOW "%s"Color_RESET "%s.", pre, wrd, pos); } else { - // s = r_str_newf ("\"%s"Color_INVERT"%s"Color_RESET"%s\"", pre, wrd, pos); - s = r_str_newf ("\"%s%s%s\"", pre, wrd, pos); + // s = rz_str_newf ("\"%s"Color_INVERT"%s"Color_RESET"%s\"", pre, wrd, pos); + s = rz_str_newf ("\"%s%s%s\"", pre, wrd, pos); } free (pre); free (wrd); @@ -483,7 +483,7 @@ static int _cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { if (str) { p = str; memset (str, 0, len); - r_io_read_at (core->io, base_addr + addr, buf, keyword_len); + rz_io_read_at (core->io, base_addr + addr, buf, keyword_len); if (param->outmode == R_MODE_JSON) { p = str; } @@ -507,16 +507,16 @@ static int _cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { if (param->outmode == R_MODE_JSON) { if (core->search->nhits >= 1) { - r_cons_printf (","); + rz_cons_printf (","); } - char *es = escaped ? s : r_str_escape (s); - r_cons_printf ("{\"offset\":%"PFMT64d ",\"type\":\"%s\",\"data\":\"%s\"}", + char *es = escaped ? s : rz_str_escape (s); + rz_cons_printf ("{\"offset\":%"PFMT64d ",\"type\":\"%s\",\"data\":\"%s\"}", base_addr + addr, type, es); if (!escaped) { free (es); } } else { - r_cons_printf ("0x%08"PFMT64x " %s%d_%d %s\n", + rz_cons_printf ("0x%08"PFMT64x " %s%d_%d %s\n", base_addr + addr, searchprefix, kw->kwidx, kw->count, s); } free (s); @@ -525,28 +525,28 @@ static int _cb_hit(RSearchKeyword *kw, void *user, ut64 addr) { } else if (kw) { if (param->outmode == R_MODE_JSON) { if (core->search->nhits >= 1) { - r_cons_printf (","); + rz_cons_printf (","); } - r_cons_printf ("{\"offset\": %"PFMT64d ",\"len\":%d}", + rz_cons_printf ("{\"offset\": %"PFMT64d ",\"len\":%d}", base_addr + addr, kw->kwidx, keyword_len); } else { if (searchflags) { - r_cons_printf ("%s%d_%d\n", searchprefix, kw->kwidx, kw->count); + rz_cons_printf ("%s%d_%d\n", searchprefix, kw->kwidx, kw->count); } else { - r_cons_printf ("f %s%d_%d %d 0x%08"PFMT64x "\n", searchprefix, + rz_cons_printf ("f %s%d_%d %d 0x%08"PFMT64x "\n", searchprefix, kw->kwidx, kw->count, keyword_len, base_addr + addr); } } } if (searchflags && kw) { const char *flag = sdb_fmt ("%s%d_%d", searchprefix, kw->kwidx, kw->count); - r_flag_set (core->flags, flag, base_addr + addr, keyword_len); + rz_flag_set (core->flags, flag, base_addr + addr, keyword_len); } if (*param->cmd_hit) { ut64 here = core->offset; - r_core_seek (core, base_addr + addr, true); - r_core_cmd (core, param->cmd_hit, 0); - r_core_seek (core, here, true); + rz_core_seek (core, base_addr + addr, true); + rz_core_cmd (core, param->cmd_hit, 0); + rz_core_seek (core, here, true); } return true; } @@ -557,7 +557,7 @@ static inline void print_search_progress(ut64 at, ut64 to, int n, struct search_ if ((++c % 64) || (param->outmode == R_MODE_JSON)) { return; } - if (r_cons_singleton ()->columns < 50) { + if (rz_cons_singleton ()->columns < 50) { eprintf ("\r[ ] 0x%08"PFMT64x " hits = %d \r%s", at, n, (c % 2)? "[ #]": "[# ]"); } else { @@ -566,13 +566,13 @@ static inline void print_search_progress(ut64 at, ut64 to, int n, struct search_ } } -static void append_bound(RList *list, RIO *io, RInterval search_itv, ut64 from, ut64 size, int perms) { - RIOMap *map = R_NEW0 (RIOMap); +static void append_bound(RzList *list, RzIO *io, RInterval search_itv, ut64 from, ut64 size, int perms) { + RzIOMap *map = R_NEW0 (RzIOMap); if (!map) { return; } if (io && io->desc) { - map->fd = r_io_fd_get_current (io); + map->fd = rz_io_fd_get_current (io); } map->perm = perms; @@ -585,11 +585,11 @@ static void append_bound(RList *list, RIO *io, RInterval search_itv, ut64 from, // TODO UT64_MAX is a valid address. search.from and search.to are not specified if (search_itv.addr == UT64_MAX && !search_itv.size) { map->itv = itv; - r_list_append (list, map); - } else if (r_itv_overlap (itv, search_itv)) { - map->itv = r_itv_intersect (itv, search_itv); + rz_list_append (list, map); + } else if (rz_itv_overlap (itv, search_itv)) { + map->itv = rz_itv_intersect (itv, search_itv); if (map->itv.size) { - r_list_append (list, map); + rz_list_append (list, map); } else { free (map); } @@ -608,11 +608,11 @@ static bool maskMatches(int perm, int mask, bool only) { return false; } -// TODO(maskray) returns RList -R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, const char *prefix) { - r_return_val_if_fail (core, NULL); +// TODO(maskray) returns RzList +RZ_API RzList *rz_core_get_boundaries_prot(RzCore *core, int perm, const char *mode, const char *prefix) { + rz_return_val_if_fail (core, NULL); - RList *list = r_list_newf (free); // XXX r_io_map_free); + RzList *list = rz_list_newf (free); // XXX rz_io_map_free); if (!list) { return NULL; } @@ -623,47 +623,47 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, snprintf (bound_in, sizeof (bound_in), "%s.%s", prefix, "in"); snprintf (bound_from, sizeof (bound_from), "%s.%s", prefix, "from"); snprintf (bound_to, sizeof (bound_to), "%s.%s", prefix, "to"); - const ut64 search_from = r_config_get_i (core->config, bound_from), - search_to = r_config_get_i (core->config, bound_to); + const ut64 search_from = rz_config_get_i (core->config, bound_from), + search_to = rz_config_get_i (core->config, bound_to); const RInterval search_itv = {search_from, search_to - search_from}; if (!mode) { - mode = r_config_get (core->config, bound_in); + mode = rz_config_get (core->config, bound_in); } if (perm == -1) { perm = R_PERM_RWX; } - if (!r_config_get_i (core->config, "cfg.debug") && !core->io->va) { - append_bound (list, core->io, search_itv, 0, r_io_size (core->io), 7); + if (!rz_config_get_i (core->config, "cfg.debug") && !core->io->va) { + append_bound (list, core->io, search_itv, 0, rz_io_size (core->io), 7); } else if (!strcmp (mode, "file")) { - append_bound (list, core->io, search_itv, 0, r_io_size (core->io), 7); + append_bound (list, core->io, search_itv, 0, rz_io_size (core->io), 7); } else if (!strcmp (mode, "block")) { append_bound (list, core->io, search_itv, core->offset, core->blocksize, 7); } else if (!strcmp (mode, "io.map")) { - RIOMap *m = r_io_map_get (core->io, core->offset); + RzIOMap *m = rz_io_map_get (core->io, core->offset); if (m) { append_bound (list, core->io, search_itv, m->itv.addr, m->itv.size, m->perm); } - } else if (!strcmp (mode, "io.maps")) { // Non-overlapping RIOMap parts not overridden by others (skyline) + } else if (!strcmp (mode, "io.maps")) { // Non-overlapping RzIOMap parts not overridden by others (skyline) ut64 begin = UT64_MAX; ut64 end = UT64_MAX; #define USE_SKYLINE 0 #if USE_SKYLINE const RPVector *skyline = &core->io->map_skyline; size_t i; - for (i = 0; i < r_pvector_len (skyline); i++) { - const RIOMapSkyline *part = r_pvector_at (skyline, i); + for (i = 0; i < rz_pvector_len (skyline); i++) { + const RzIOMapSkyline *part = rz_pvector_at (skyline, i); // int perm = part->map->perm; - ut64 from = r_itv_begin (part->itv); - ut64 to = r_itv_end (part->itv); + ut64 from = rz_itv_begin (part->itv); + ut64 to = rz_itv_end (part->itv); // XXX skyline's fake map perms are wrong - RIOMap *m = r_io_map_get (core->io, from); + RzIOMap *m = rz_io_map_get (core->io, from); int rwx = m? m->perm: part->map->perm; #else void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; - ut64 from = r_itv_begin (map->itv); - ut64 to = r_itv_end (map->itv); + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; + ut64 from = rz_itv_begin (map->itv); + ut64 to = rz_itv_end (map->itv); int rwx = map->perm; #endif // eprintf ("--------- %llx %llx (%llx %llx)\n", from, to, begin, end); @@ -686,32 +686,32 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, if (end != UT64_MAX) { append_bound (list, NULL, search_itv, begin, end - begin, 7); } - } else if (r_str_startswith (mode, "io.maps.")) { + } else if (rz_str_startswith (mode, "io.maps.")) { int len = strlen ("io.maps."); - int mask = (mode[len - 1] == '.')? r_str_rwx (mode + len): 0; + int mask = (mode[len - 1] == '.')? rz_str_rwx (mode + len): 0; // bool only = (bool)(size_t)strstr (mode, ".only"); void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; - ut64 from = r_itv_begin (map->itv); - //ut64 to = r_itv_end (map->itv); + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; + ut64 from = rz_itv_begin (map->itv); + //ut64 to = rz_itv_end (map->itv); int rwx = map->perm; if ((rwx & mask) != mask) { continue; } - append_bound (list, core->io, search_itv, from, r_itv_size (map->itv), rwx); + append_bound (list, core->io, search_itv, from, rz_itv_size (map->itv), rwx); } - } else if (r_str_startswith (mode, "io.sky.")) { + } else if (rz_str_startswith (mode, "io.sky.")) { int len = strlen ("io.sky."); - int mask = (mode[len - 1] == '.')? r_str_rwx (mode + len): 0; + int mask = (mode[len - 1] == '.')? rz_str_rwx (mode + len): 0; bool only = (bool)(size_t)strstr (mode, ".only"); const RPVector *skyline = &core->io->map_skyline; ut64 begin = UT64_MAX; ut64 end = UT64_MAX; size_t i; - for (i = 0; i < r_pvector_len (skyline); i++) { - const RIOMapSkyline *part = r_pvector_at (skyline, i); + for (i = 0; i < rz_pvector_len (skyline); i++) { + const RzIOMapSkyline *part = rz_pvector_at (skyline, i); ut64 from = part->itv.addr; ut64 to = part->itv.addr + part->itv.size; int perm = part->map->perm; @@ -738,15 +738,15 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, if (end != UT64_MAX) { append_bound (list, NULL, search_itv, begin, end - begin, 7); } - } else if (r_str_startswith (mode, "bin.segments")) { + } else if (rz_str_startswith (mode, "bin.segments")) { int len = strlen ("bin.segments."); - int mask = (mode[len - 1] == '.')? r_str_rwx (mode + len): 0; + int mask = (mode[len - 1] == '.')? rz_str_rwx (mode + len): 0; bool only = (bool)(size_t)strstr (mode, ".only"); - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { RBinSection *s; - RListIter *iter; - r_list_foreach (obj->sections, iter, s) { + RzListIter *iter; + rz_list_foreach (obj->sections, iter, s) { if (!s->is_segment) { continue; } @@ -758,14 +758,14 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, append_bound (list, core->io, search_itv, addr, size, s->perm); } } - } else if (r_str_startswith (mode, "code")) { - RBinObject *obj = r_bin_cur_object (core->bin); + } else if (rz_str_startswith (mode, "code")) { + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { ut64 from = UT64_MAX; ut64 to = 0; RBinSection *s; - RListIter *iter; - r_list_foreach (obj->sections, iter, s) { + RzListIter *iter; + rz_list_foreach (obj->sections, iter, s) { if (s->is_segment) { continue; } @@ -780,10 +780,10 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, if (from == UT64_MAX) { int mask = 1; void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; - ut64 from = r_itv_begin (map->itv); - ut64 size = r_itv_size (map->itv); + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; + ut64 from = rz_itv_begin (map->itv); + ut64 size = rz_itv_size (map->itv); int rwx = map->perm; if ((rwx & mask) != mask) { continue; @@ -793,15 +793,15 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } append_bound (list, core->io, search_itv, from, to-from, 1); } - } else if (r_str_startswith (mode, "bin.sections")) { + } else if (rz_str_startswith (mode, "bin.sections")) { int len = strlen ("bin.sections."); - int mask = (mode[len - 1] == '.')? r_str_rwx (mode + len): 0; + int mask = (mode[len - 1] == '.')? rz_str_rwx (mode + len): 0; bool only = (bool)(size_t)strstr (mode, ".only"); - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { RBinSection *s; - RListIter *iter; - r_list_foreach (obj->sections, iter, s) { + RzListIter *iter; + rz_list_foreach (obj->sections, iter, s) { if (s->is_segment) { continue; } @@ -814,11 +814,11 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } } } else if (!strcmp (mode, "bin.segment")) { - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { RBinSection *s; - RListIter *iter; - r_list_foreach (obj->sections, iter, s) { + RzListIter *iter; + rz_list_foreach (obj->sections, iter, s) { if (!s->is_segment) { continue; } @@ -830,11 +830,11 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } } } else if (!strcmp (mode, "bin.section")) { - RBinObject *obj = r_bin_cur_object (core->bin); + RBinObject *obj = rz_bin_cur_object (core->bin); if (obj) { RBinSection *s; - RListIter *iter; - r_list_foreach (obj->sections, iter, s) { + RzListIter *iter; + rz_list_foreach (obj->sections, iter, s) { if (s->is_segment) { continue; } @@ -846,17 +846,17 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } } } else if (!strcmp (mode, "anal.fcn") || !strcmp (mode, "anal.bb")) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM); if (f) { - ut64 from = f->addr, size = r_anal_function_size_from_entry (f); + ut64 from = f->addr, size = rz_anal_function_size_from_entry (f); /* Search only inside the basic block */ if (!strcmp (mode, "anal.bb")) { - RListIter *iter; - RAnalBlock *bb; + RzListIter *iter; + RzAnalBlock *bb; - r_list_foreach (f->bbs, iter, bb) { + rz_list_foreach (f->bbs, iter, bb) { ut64 at = core->offset; if ((at >= bb->addr) && (at < (bb->addr + bb->size))) { from = bb->addr; @@ -879,16 +879,16 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, bool stack = false; bool all = false; bool first = false; - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; - r_debug_map_sync (core->dbg); + rz_debug_map_sync (core->dbg); if (!strcmp (mode, "dbg.map")) { int perm = 0; ut64 from = core->offset; ut64 to = core->offset; - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (from >= map->addr && from < map->addr_end) { from = map->addr; to = map->addr_end; @@ -897,14 +897,14 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } } if (perm) { - RIOMap *nmap = R_NEW0 (RIOMap); + RzIOMap *nmap = R_NEW0 (RzIOMap); if (nmap) { // nmap->fd = core->io->desc->fd; nmap->itv.addr = from; nmap->itv.size = to - from; nmap->perm = perm; nmap->delta = 0; - r_list_append (list, nmap); + rz_list_append (list, nmap); } } } else { @@ -915,8 +915,8 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, mask = R_PERM_X; } else if (!strcmp (mode, "dbg.maps")) { all = true; - } else if (r_str_startswith (mode, "dbg.maps.")) { - mask = r_str_rwx (mode + 9); + } else if (rz_str_startswith (mode, "dbg.maps.")) { + mask = rz_str_rwx (mode + 9); only = (bool)(size_t)strstr (mode, ".only"); } else if (!strcmp (mode, "dbg.heap")) { heap = true; @@ -926,7 +926,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, ut64 from = UT64_MAX; ut64 to = 0; - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (!all && maskMatches (map->perm, mask, only)) { continue; } @@ -936,9 +936,9 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, } if ((mask && (map->perm & mask)) || add || all) { if (!list) { - list = r_list_newf (free); + list = rz_list_newf (free); } - RIOMap *nmap = R_NEW0 (RIOMap); + RzIOMap *nmap = R_NEW0 (RzIOMap); if (!nmap) { break; } @@ -946,11 +946,11 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, nmap->itv.size = map->addr_end - map->addr; if (nmap->itv.addr) { from = R_MIN (from, nmap->itv.addr); - to = R_MAX (to - 1, r_itv_end (nmap->itv) - 1) + 1; + to = R_MAX (to - 1, rz_itv_end (nmap->itv) - 1) + 1; } nmap->perm = map->perm; nmap->delta = 0; - r_list_append (list, nmap); + rz_list_append (list, nmap); if (first) { break; } @@ -964,17 +964,17 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, append_bound (list, core->io, search_itv, core->offset, core->blocksize, 5); } else { // TODO: repeat last search doesnt works for /a - ut64 from = r_config_get_i (core->config, bound_from); + ut64 from = rz_config_get_i (core->config, bound_from); if (from == UT64_MAX) { from = core->offset; } - ut64 to = r_config_get_i (core->config, bound_to); + ut64 to = rz_config_get_i (core->config, bound_to); if (to == UT64_MAX) { if (core->io->va) { /* TODO: section size? */ } else { if (core->file) { - to = r_io_fd_size (core->io, core->file->fd); + to = rz_io_fd_size (core->io, core->file->fd); } } } @@ -984,7 +984,7 @@ R_API RList *r_core_get_boundaries_prot(RCore *core, int perm, const char *mode, return list; } -static bool is_end_gadget(const RAnalOp *aop, const ut8 crop) { +static bool is_end_gadget(const RzAnalOp *aop, const ut8 crop) { if (aop->family == R_ANAL_OP_FAMILY_SECURITY) { return false; } @@ -1023,16 +1023,16 @@ static bool insert_into(void *user, const ut64 k, const ut64 v) { } // TODO: follow unconditional jumps -static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen, int idx, const char *grep, int regex, RList *rx_list, struct endlist_pair *end_gadget, HtUU *badstart) { +static RzList *construct_rop_gadget(RzCore *core, ut64 addr, ut8 *buf, int buflen, int idx, const char *grep, int regex, RzList *rx_list, struct endlist_pair *end_gadget, HtUU *badstart) { int endaddr = end_gadget->instr_offset; int branch_delay = end_gadget->delay_size; - RAnalOp aop = {0}; + RzAnalOp aop = {0}; const char *start = NULL, *end = NULL; char *grep_str = NULL; - RCoreAsmHit *hit = NULL; - RList *hitlist = r_core_asm_hit_list_new (); + RzCoreAsmHit *hit = NULL; + RzList *hitlist = rz_core_asm_hit_list_new (); ut8 nb_instr = 0; - const ut8 max_instr = r_config_get_i (core->config, "rop.len"); + const ut8 max_instr = rz_config_get_i (core->config, "rop.len"); bool valid = false; int grep_find; int search_hit; @@ -1051,8 +1051,8 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen, strncpy (grep_str, start, end - start); if (regex) { // get the first regexp. - if (r_list_length (rx_list) > 0) { - rx = r_list_get_n (rx_list, count++); + if (rz_list_length (rx_list) > 0) { + rx = rz_list_get_n (rx_list, count++); } } } @@ -1065,44 +1065,44 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen, } while (nb_instr < max_instr) { ht_uu_insert (localbadstart, idx, 1); - r_anal_op (core->anal, &aop, addr, buf + idx, buflen - idx, R_ANAL_OP_MASK_DISASM); + rz_anal_op (core->anal, &aop, addr, buf + idx, buflen - idx, R_ANAL_OP_MASK_DISASM); if (nb_instr == 0 && (is_end_gadget (&aop, 0) || aop.type == R_ANAL_OP_TYPE_NOP)) { valid = false; goto ret; } const int opsz = aop.size; - // opsz = r_strbuf_length (asmop.buf); + // opsz = rz_strbuf_length (asmop.buf); char *opst = aop.mnemonic; if (!opst) { R_LOG_WARN ("Anal plugin %s did not return disassembly\n", core->anal->cur->name); - RAsmOp asmop; - r_asm_set_pc (core->rasm, addr); - if (!r_asm_disassemble (core->rasm, &asmop, buf + idx, buflen - idx)) { + RzAsmOp asmop; + rz_asm_set_pc (core->rasm, addr); + if (!rz_asm_disassemble (core->rasm, &asmop, buf + idx, buflen - idx)) { valid = false; goto ret; } - opst = strdup (r_asm_op_get_asm (&asmop)); - r_asm_op_fini (&asmop); + opst = strdup (rz_asm_op_get_asm (&asmop)); + rz_asm_op_fini (&asmop); } - if (!r_str_ncasecmp (opst, "invalid", strlen ("invalid")) || - !r_str_ncasecmp (opst, ".byte", strlen (".byte"))) { + if (!rz_str_ncasecmp (opst, "invalid", strlen ("invalid")) || + !rz_str_ncasecmp (opst, ".byte", strlen (".byte"))) { valid = false; goto ret; } - hit = r_core_asm_hit_new (); + hit = rz_core_asm_hit_new (); if (hit) { hit->addr = addr; hit->len = opsz; - r_list_append (hitlist, hit); + rz_list_append (hitlist, hit); } // Move on to the next instruction idx += opsz; addr += opsz; if (rx) { - grep_find = !r_regex_match (rx, "e", opst); + grep_find = !rz_regex_match (rx, "e", opst); search_hit = (end && grep && (grep_find < 1)); } else { search_hit = (end && grep && strstr (opst, grep_str)); @@ -1123,7 +1123,7 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen, end = NULL; } if (regex) { - rx = r_list_get_n (rx_list, count++); + rx = rz_list_get_n (rx_list, count++); } } if (endaddr <= (idx - opsz)) { @@ -1138,46 +1138,46 @@ ret: free (aop.mnemonic); free (grep_str); if (regex && rx) { - r_list_free (hitlist); + rz_list_free (hitlist); ht_uu_free (localbadstart); return NULL; } if (!valid || (grep && end)) { - r_list_free (hitlist); + rz_list_free (hitlist); ht_uu_free (localbadstart); return NULL; } ht_uu_foreach (localbadstart, insert_into, badstart); ht_uu_free (localbadstart); // If our arch has bds then we better be including them - if (branch_delay && r_list_length (hitlist) < (1 + branch_delay)) { - r_list_free (hitlist); + if (branch_delay && rz_list_length (hitlist) < (1 + branch_delay)) { + rz_list_free (hitlist); return NULL; } return hitlist; } -static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first) { +static void print_rop(RzCore *core, RzList *hitlist, char mode, bool *json_first) { const char *otype; - RCoreAsmHit *hit = NULL; - RListIter *iter; - RList *ropList = NULL; + RzCoreAsmHit *hit = NULL; + RzListIter *iter; + RzList *ropList = NULL; char *buf_asm = NULL; unsigned int size = 0; - RAnalOp analop = R_EMPTY; - RAsmOp asmop; + RzAnalOp analop = R_EMPTY; + RzAsmOp asmop; Sdb *db = NULL; - const bool colorize = r_config_get_i (core->config, "scr.color"); - const bool rop_comments = r_config_get_i (core->config, "rop.comments"); - const bool esil = r_config_get_i (core->config, "asm.esil"); - const bool rop_db = r_config_get_i (core->config, "rop.db"); + const bool colorize = rz_config_get_i (core->config, "scr.color"); + const bool rop_comments = rz_config_get_i (core->config, "rop.comments"); + const bool esil = rz_config_get_i (core->config, "asm.esil"); + const bool rop_db = rz_config_get_i (core->config, "rop.db"); if (rop_db) { db = sdb_ns (core->sdb, "rop", true); - ropList = r_list_newf (free); + ropList = rz_list_newf (free); if (!db) { eprintf ("Error: Could not create SDB 'rop' namespace\n"); - r_list_free (ropList); + rz_list_free (ropList); return; } } @@ -1188,76 +1188,76 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first) if (*json_first) { *json_first = 0; } else { - r_cons_strcat (","); + rz_cons_strcat (","); } - r_cons_printf ("{\"opcodes\":["); - r_list_foreach (hitlist, iter, hit) { + rz_cons_printf ("{\"opcodes\":["); + rz_list_foreach (hitlist, iter, hit) { ut8 *buf = malloc (hit->len); - r_io_read_at (core->io, hit->addr, buf, hit->len); - r_asm_set_pc (core->rasm, hit->addr); - r_asm_disassemble (core->rasm, &asmop, buf, hit->len); - r_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_ESIL); + rz_io_read_at (core->io, hit->addr, buf, hit->len); + rz_asm_set_pc (core->rasm, hit->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, hit->len); + rz_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_ESIL); size += hit->len; if (analop.type != R_ANAL_OP_TYPE_RET) { - char *opstr_n = r_str_newf (" %s", R_STRBUF_SAFEGET (&analop.esil)); - r_list_append (ropList, (void *) opstr_n); + char *opstr_n = rz_str_newf (" %s", R_STRBUF_SAFEGET (&analop.esil)); + rz_list_append (ropList, (void *) opstr_n); } - r_cons_printf ("{\"offset\":%"PFMT64d ",\"size\":%d," + rz_cons_printf ("{\"offset\":%"PFMT64d ",\"size\":%d," "\"opcode\":\"%s\",\"type\":\"%s\"}%s", - hit->addr, hit->len, r_asm_op_get_asm (&asmop), - r_anal_optype_to_string (analop.type), + hit->addr, hit->len, rz_asm_op_get_asm (&asmop), + rz_anal_optype_to_string (analop.type), iter->n? ",": ""); free (buf); } if (db && hit) { - const ut64 addr = ((RCoreAsmHit *) hitlist->head->data)->addr; - // r_cons_printf ("Gadget size: %d\n", (int)size); + const ut64 addr = ((RzCoreAsmHit *) hitlist->head->data)->addr; + // rz_cons_printf ("Gadget size: %d\n", (int)size); const char *key = sdb_fmt ("0x%08"PFMT64x, addr); rop_classify (core, db, ropList, key, size); - r_cons_printf ("],\"retaddr\":%"PFMT64d ",\"size\":%d}", hit->addr, size); + rz_cons_printf ("],\"retaddr\":%"PFMT64d ",\"size\":%d}", hit->addr, size); } else if (hit) { - r_cons_printf ("],\"retaddr\":%"PFMT64d ",\"size\":%d}", hit->addr, size); + rz_cons_printf ("],\"retaddr\":%"PFMT64d ",\"size\":%d}", hit->addr, size); } break; case 'q': // Print gadgets in a 'linear manner', each sequence // on one line. - r_cons_printf ("0x%08"PFMT64x ":", - ((RCoreAsmHit *) hitlist->head->data)->addr); - r_list_foreach (hitlist, iter, hit) { + rz_cons_printf ("0x%08"PFMT64x ":", + ((RzCoreAsmHit *) hitlist->head->data)->addr); + rz_list_foreach (hitlist, iter, hit) { ut8 *buf = malloc (hit->len); - r_io_read_at (core->io, hit->addr, buf, hit->len); - r_asm_set_pc (core->rasm, hit->addr); - r_asm_disassemble (core->rasm, &asmop, buf, hit->len); - r_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_BASIC); + rz_io_read_at (core->io, hit->addr, buf, hit->len); + rz_asm_set_pc (core->rasm, hit->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, hit->len); + rz_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_BASIC); size += hit->len; const char *opstr = R_STRBUF_SAFEGET (&analop.esil); if (analop.type != R_ANAL_OP_TYPE_RET) { - r_list_append (ropList, r_str_newf (" %s", opstr)); + rz_list_append (ropList, rz_str_newf (" %s", opstr)); } if (esil) { - r_cons_printf ("%s\n", opstr); + rz_cons_printf ("%s\n", opstr); } else if (colorize) { - buf_asm = r_print_colorize_opcode (core->print, r_asm_op_get_asm (&asmop), + buf_asm = rz_print_colorize_opcode (core->print, rz_asm_op_get_asm (&asmop), core->cons->context->pal.reg, core->cons->context->pal.num, false, 0); - r_cons_printf (" %s%s;", buf_asm, Color_RESET); + rz_cons_printf (" %s%s;", buf_asm, Color_RESET); free (buf_asm); } else { - r_cons_printf (" %s;", r_asm_op_get_asm (&asmop)); + rz_cons_printf (" %s;", rz_asm_op_get_asm (&asmop)); } free (buf); } if (db && hit) { - const ut64 addr = ((RCoreAsmHit *) hitlist->head->data)->addr; - // r_cons_printf ("Gadget size: %d\n", (int)size); + const ut64 addr = ((RzCoreAsmHit *) hitlist->head->data)->addr; + // rz_cons_printf ("Gadget size: %d\n", (int)size); const char *key = sdb_fmt ("0x%08"PFMT64x, addr); rop_classify (core, db, ropList, key, size); } break; default: // Print gadgets with new instruction on a new line. - r_list_foreach (hitlist, iter, hit) { - const char *comment = rop_comments? r_meta_get_string (core->anal, R_META_TYPE_COMMENT, hit->addr): NULL; + rz_list_foreach (hitlist, iter, hit) { + const char *comment = rop_comments? rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, hit->addr): NULL; if (hit->len < 0) { eprintf ("Invalid hit length here\n"); continue; @@ -1267,75 +1267,75 @@ static void print_rop(RCore *core, RList *hitlist, char mode, bool *json_first) break; } buf[hit->len] = 0; - r_io_read_at (core->io, hit->addr, buf, hit->len); - r_asm_set_pc (core->rasm, hit->addr); - r_asm_disassemble (core->rasm, &asmop, buf, hit->len); - r_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_ESIL); + rz_io_read_at (core->io, hit->addr, buf, hit->len); + rz_asm_set_pc (core->rasm, hit->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, hit->len); + rz_anal_op (core->anal, &analop, hit->addr, buf, hit->len, R_ANAL_OP_MASK_ESIL); size += hit->len; if (analop.type != R_ANAL_OP_TYPE_RET) { - char *opstr_n = r_str_newf (" %s", R_STRBUF_SAFEGET (&analop.esil)); - r_list_append (ropList, (void *) opstr_n); + char *opstr_n = rz_str_newf (" %s", R_STRBUF_SAFEGET (&analop.esil)); + rz_list_append (ropList, (void *) opstr_n); } - char *asm_op_hex = r_asm_op_get_hex (&asmop); + char *asm_op_hex = rz_asm_op_get_hex (&asmop); if (colorize) { - char *buf_asm = r_print_colorize_opcode (core->print, r_asm_op_get_asm (&asmop), + char *buf_asm = rz_print_colorize_opcode (core->print, rz_asm_op_get_asm (&asmop), core->cons->context->pal.reg, core->cons->context->pal.num, false, 0); - otype = r_print_color_op_type (core->print, analop.type); + otype = rz_print_color_op_type (core->print, analop.type); if (comment) { - r_cons_printf (" 0x%08"PFMT64x " %18s%s %s%s ; %s\n", + rz_cons_printf (" 0x%08"PFMT64x " %18s%s %s%s ; %s\n", hit->addr, asm_op_hex, otype, buf_asm, Color_RESET, comment); } else { - r_cons_printf (" 0x%08"PFMT64x " %18s%s %s%s\n", + rz_cons_printf (" 0x%08"PFMT64x " %18s%s %s%s\n", hit->addr, asm_op_hex, otype, buf_asm, Color_RESET); } free (buf_asm); } else { if (comment) { - r_cons_printf (" 0x%08"PFMT64x " %18s %s ; %s\n", - hit->addr, asm_op_hex, r_asm_op_get_asm (&asmop), comment); + rz_cons_printf (" 0x%08"PFMT64x " %18s %s ; %s\n", + hit->addr, asm_op_hex, rz_asm_op_get_asm (&asmop), comment); } else { - r_cons_printf (" 0x%08"PFMT64x " %18s %s\n", - hit->addr, asm_op_hex, r_asm_op_get_asm (&asmop)); + rz_cons_printf (" 0x%08"PFMT64x " %18s %s\n", + hit->addr, asm_op_hex, rz_asm_op_get_asm (&asmop)); } } free (asm_op_hex); free (buf); } if (db && hit) { - const ut64 addr = ((RCoreAsmHit *) hitlist->head->data)->addr; - // r_cons_printf ("Gadget size: %d\n", (int)size); + const ut64 addr = ((RzCoreAsmHit *) hitlist->head->data)->addr; + // rz_cons_printf ("Gadget size: %d\n", (int)size); const char *key = sdb_fmt ("0x%08"PFMT64x, addr); rop_classify (core, db, ropList, key, size); } } if (mode != 'j') { - r_cons_newline (); + rz_cons_newline (); } - r_list_free (ropList); + rz_list_free (ropList); } -static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const char *grep, int regexp, struct search_parameters *param) { - const ut8 crop = r_config_get_i (core->config, "rop.conditional"); // decide if cjmp, cret, and ccall should be used too for the gadget-search - const ut8 subchain = r_config_get_i (core->config, "rop.subchains"); - const ut8 max_instr = r_config_get_i (core->config, "rop.len"); - const char *arch = r_config_get (core->config, "asm.arch"); - int max_count = r_config_get_i (core->config, "search.maxhits"); +static int rz_core_search_rop(RzCore *core, RInterval search_itv, int opt, const char *grep, int regexp, struct search_parameters *param) { + const ut8 crop = rz_config_get_i (core->config, "rop.conditional"); // decide if cjmp, cret, and ccall should be used too for the gadget-search + const ut8 subchain = rz_config_get_i (core->config, "rop.subchains"); + const ut8 max_instr = rz_config_get_i (core->config, "rop.len"); + const char *arch = rz_config_get (core->config, "asm.arch"); + int max_count = rz_config_get_i (core->config, "search.maxhits"); int i = 0, end = 0, mode = 0, increment = 1, ret, result = true; - RList /**/ *end_list = r_list_newf (free); - RList /**/ *rx_list = NULL; + RzList /**/ *end_list = rz_list_newf (free); + RzList /**/ *rx_list = NULL; int align = core->search->align; - RListIter *itermap = NULL; + RzListIter *itermap = NULL; char *tok, *gregexp = NULL; char *grep_arg = NULL; bool json_first = true; char *rx = NULL; int delta = 0; ut8 *buf; - RIOMap *map; - RAsmOp asmop; + RzIOMap *map; + RzAsmOp asmop; Sdb *gadgetSdb = NULL; - if (r_config_get_i (core->config, "rop.sdb")) { + if (rz_config_get_i (core->config, "rop.sdb")) { if (!(gadgetSdb = sdb_ns (core->sdb, "gadget_sdb", false))) { gadgetSdb = sdb_ns (core->sdb, "gadget_sdb", true); } @@ -1344,7 +1344,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c max_count = -1; } if (max_instr <= 1) { - r_list_free (end_list); + rz_list_free (end_list); eprintf ("ROP length (rop.len) must be greater than 1.\n"); if (max_instr == 1) { eprintf ("For rop.len = 1, use /c to search for single " @@ -1356,7 +1356,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c if (!strcmp (arch, "mips")) { // MIPS has no jump-in-the-middle increment = 4; } else if (!strcmp (arch, "arm")) { // ARM has no jump-in-the-middle - increment = r_config_get_i (core->config, "asm.bits") == 16? 2: 4; + increment = rz_config_get_i (core->config, "asm.bits") == 16? 2: 4; } else if (!strcmp (arch, "avr")) { // AVR is halfword aligned. increment = 2; } @@ -1373,7 +1373,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c } if (grep_arg) { grep_arg = strdup (grep_arg); - grep_arg = r_str_replace (grep_arg, ",,", ";", true); + grep_arg = rz_str_replace (grep_arg, ",,", ";", true); grep = grep_arg; } @@ -1388,30 +1388,30 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c // Deal with the grep guy. if (grep && regexp) { if (!rx_list) { - rx_list = r_list_newf (free); + rx_list = rz_list_newf (free); } gregexp = strdup (grep); tok = strtok (gregexp, ";"); while (tok) { rx = strdup (tok); - r_list_append (rx_list, rx); + rz_list_append (rx_list, rx); tok = strtok (NULL, ";"); } } if (param->outmode == R_MODE_JSON) { - r_cons_printf ("["); + rz_cons_printf ("["); } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); - r_list_foreach (param->boundaries, itermap, map) { + rz_list_foreach (param->boundaries, itermap, map) { HtUUOptions opt = { 0 }; HtUU *badstart = ht_uu_new_opt (&opt); - if (!r_itv_overlap (search_itv, map->itv)) { + if (!rz_itv_overlap (search_itv, map->itv)) { continue; } - RInterval itv = r_itv_intersect (search_itv, map->itv); - ut64 from = itv.addr, to = r_itv_end (itv); - if (r_cons_is_breaked ()) { + RInterval itv = rz_itv_intersect (search_itv, map->itv); + ut64 from = itv.addr, to = rz_itv_end (itv); + if (rz_cons_is_breaked ()) { break; } delta = to - from; @@ -1420,22 +1420,22 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c result = false; goto bad; } - (void) r_io_read_at (core->io, from, buf, delta); + (void) rz_io_read_at (core->io, from, buf, delta); // Find the end gadgets. for (i = 0; i + 32 < delta; i += increment) { - RAnalOp end_gadget = R_EMPTY; + RzAnalOp end_gadget = R_EMPTY; // Disassemble one. - if (r_anal_op (core->anal, &end_gadget, from + i, buf + i, + if (rz_anal_op (core->anal, &end_gadget, from + i, buf + i, delta - i, R_ANAL_OP_MASK_BASIC) < 1) { - r_anal_op_fini (&end_gadget); + rz_anal_op_fini (&end_gadget); continue; } if (is_end_gadget (&end_gadget, crop)) { #if 0 - if (search->maxhits && r_list_length (end_list) >= search->maxhits) { + if (search->maxhits && rz_list_length (end_list) >= search->maxhits) { // limit number of high level rop gadget results - r_anal_op_fini (&end_gadget); + rz_anal_op_fini (&end_gadget); break; } #endif @@ -1449,19 +1449,19 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c epair->instr_offset = (intptr_t) i; epair->delay_size = end_gadget.delay; } - r_list_append (end_list, (void *) (intptr_t) epair); + rz_list_append (end_list, (void *) (intptr_t) epair); } } - r_anal_op_fini (&end_gadget); - if (r_cons_is_breaked ()) { + rz_anal_op_fini (&end_gadget); + if (rz_cons_is_breaked ()) { break; } // Right now we have a list of all of the end/stop gadgets. // We can just construct gadgets from a little bit before them. } - r_list_reverse (end_list); + rz_list_reverse (end_list); // If we have no end gadgets, just skip all of this search nonsense. - if (!r_list_empty (end_list)) { + if (!rz_list_empty (end_list)) { int prev, next, ropdepth; const int max_inst_size_x86 = 15; // Get the depth of rop search, should just be max_instr @@ -1470,10 +1470,10 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c ropdepth = increment == 1? max_instr * max_inst_size_x86 /* wow, x86 is long */: max_instr * increment; - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - struct endlist_pair *end_gadget = (struct endlist_pair *) r_list_pop (end_list); + struct endlist_pair *end_gadget = (struct endlist_pair *) rz_list_pop (end_list); next = end_gadget->instr_offset; prev = 0; // Start at just before the first end gadget. @@ -1491,16 +1491,16 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c if (i < 0) { i = 0; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (i >= next) { // We've exhausted the first end-gadget section, // move to the next one. free (end_gadget); - if (r_list_get_n (end_list, 0)) { + if (rz_list_get_n (end_list, 0)) { prev = i; - end_gadget = (struct endlist_pair *) r_list_pop (end_list); + end_gadget = (struct endlist_pair *) rz_list_pop (end_list); next = end_gadget->instr_offset; i = next - ropdepth; if (i < 0) { @@ -1511,14 +1511,14 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c } } if (i >= end) { // read by chunk of 4k - r_io_read_at (core->io, from + i, buf + i, + rz_io_read_at (core->io, from + i, buf + i, R_MIN ((delta - i), 4096)); end = i + 2048; } - ret = r_asm_disassemble (core->rasm, &asmop, buf + i, delta - i); + ret = rz_asm_disassemble (core->rasm, &asmop, buf + i, delta - i); if (ret) { - r_asm_set_pc (core->rasm, from + i); - RList *hitlist = construct_rop_gadget (core, + rz_asm_set_pc (core->rasm, from + i); + RzList *hitlist = construct_rop_gadget (core, from + i, buf, delta, i, grep, regexp, rx_list, end_gadget, badstart); if (!hitlist) { @@ -1528,17 +1528,17 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c continue; } if (gadgetSdb) { - RListIter *iter; + RzListIter *iter; - RCoreAsmHit *hit = (RCoreAsmHit *) hitlist->head->data; - char *headAddr = r_str_newf ("%"PFMT64x, hit->addr); + RzCoreAsmHit *hit = (RzCoreAsmHit *) hitlist->head->data; + char *headAddr = rz_str_newf ("%"PFMT64x, hit->addr); if (!headAddr) { result = false; goto bad; } - r_list_foreach (hitlist, iter, hit) { - char *addr = r_str_newf ("%"PFMT64x"(%"PFMT32d")", hit->addr, hit->len); + rz_list_foreach (hitlist, iter, hit) { + char *addr = rz_str_newf ("%"PFMT64x"(%"PFMT32d")", hit->addr, hit->len); if (!addr) { free (headAddr); result = false; @@ -1561,7 +1561,7 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c } else { print_rop (core, hitlist, mode, &json_first); } - r_list_free (hitlist); + rz_list_free (hitlist); if (max_count > 0) { max_count--; if (max_count < 1) { @@ -1576,29 +1576,29 @@ static int r_core_search_rop(RCore *core, RInterval search_itv, int opt, const c } free (buf); } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { eprintf ("\n"); } - r_cons_break_pop (); + rz_cons_break_pop (); if (param->outmode == R_MODE_JSON) { - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); } bad: - r_list_free (rx_list); - r_list_free (end_list); + rz_list_free (rx_list); + rz_list_free (end_list); free (grep_arg); free (gregexp); return result; } -static bool esil_addrinfo(RAnalEsil *esil) { - RCore *core = (RCore *) esil->cb.user; +static bool esil_addrinfo(RzAnalEsil *esil) { + RzCore *core = (RzCore *) esil->cb.user; ut64 num = 0; - char *src = r_anal_esil_pop (esil); - if (src && *src && r_anal_esil_get_parm (esil, src, &num)) { - num = r_core_anal_address (core, num); - r_anal_esil_pushnum (esil, num); + char *src = rz_anal_esil_pop (esil); + if (src && *src && rz_anal_esil_get_parm (esil, src, &num)) { + num = rz_core_anal_address (core, num); + rz_anal_esil_pushnum (esil, num); } else { // error. empty stack? return false; @@ -1607,11 +1607,11 @@ static bool esil_addrinfo(RAnalEsil *esil) { return true; } -static void do_esil_search(RCore *core, struct search_parameters *param, const char *input) { - const int hit_combo_limit = r_config_get_i (core->config, "search.esilcombo"); - const bool cfgDebug = r_config_get_i (core->config, "cfg.debug"); - RSearch *search = core->search; - RSearchKeyword kw = R_EMPTY; +static void do_esil_search(RzCore *core, struct search_parameters *param, const char *input) { + const int hit_combo_limit = rz_config_get_i (core->config, "search.esilcombo"); + const bool cfgDebug = rz_config_get_i (core->config, "cfg.debug"); + RzSearch *search = core->search; + RzSearchKeyword kw = R_EMPTY; if (input[0] != 'E') { return; } @@ -1623,42 +1623,42 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c input++; } if (input[1] != ' ') { // "/E?" - r_core_cmd_help (core, help_msg_search_esil); + rz_core_cmd_help (core, help_msg_search_esil); return; } if (!core->anal->esil) { // initialize esil vm - r_core_cmd0 (core, "aei"); + rz_core_cmd0 (core, "aei"); if (!core->anal->esil) { eprintf ("Cannot initialize the ESIL vm\n"); return; } } - RIOMap *map; - RListIter *iter; - r_list_foreach (param->boundaries, iter, map) { - const int iotrap = r_config_get_i (core->config, "esil.iotrap"); - const int stacksize = r_config_get_i (core->config, "esil.stacksize"); - int nonull = r_config_get_i (core->config, "esil.nonull"); + RzIOMap *map; + RzListIter *iter; + rz_list_foreach (param->boundaries, iter, map) { + const int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + const int stacksize = rz_config_get_i (core->config, "esil.stacksize"); + int nonull = rz_config_get_i (core->config, "esil.nonull"); bool hit_happens = false; size_t hit_combo = 0; char *res; ut64 nres, addr; ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + ut64 to = rz_itv_end (map->itv); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); if (!core->anal->esil) { - core->anal->esil = r_anal_esil_new (stacksize, iotrap, addrsize); + core->anal->esil = rz_anal_esil_new (stacksize, iotrap, addrsize); } /* hook addrinfo */ core->anal->esil->cb.user = core; - r_anal_esil_set_op (core->anal->esil, "AddrInfo", esil_addrinfo, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); + rz_anal_esil_set_op (core->anal->esil, "AddrInfo", esil_addrinfo, 1, 1, R_ANAL_ESIL_OP_TYPE_UNKNOWN); /* hook addrinfo */ - r_anal_esil_setup (core->anal->esil, core->anal, 1, 0, nonull); - r_anal_esil_stack_free (core->anal->esil); + rz_anal_esil_setup (core->anal->esil, core->anal, 1, 0, nonull); + rz_anal_esil_stack_free (core->anal->esil); core->anal->esil->verbose = 0; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (addr = from; addr < to; addr++) { if (core->search->align) { if ((addr % core->search->align)) { @@ -1674,21 +1674,21 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c // instack // inlibrary // inheap - r_anal_esil_set_op (core->anal->esil, "AddressInfo", esil_search_address_info); + rz_anal_esil_set_op (core->anal->esil, "AddressInfo", esil_search_address_info); #endif - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { eprintf ("Breaked at 0x%08"PFMT64x "\n", addr); break; } - r_anal_esil_set_pc (core->anal->esil, addr); - if (!r_anal_esil_parse (core->anal->esil, input + 2)) { + rz_anal_esil_set_pc (core->anal->esil, addr); + if (!rz_anal_esil_parse (core->anal->esil, input + 2)) { // XXX: return value doesnt seems to be correct here eprintf ("Cannot parse esil (%s)\n", input + 2); break; } hit_happens = false; - res = r_anal_esil_pop (core->anal->esil); - if (r_anal_esil_get_parm (core->anal->esil, res, &nres)) { + res = rz_anal_esil_pop (core->anal->esil); + if (rz_anal_esil_get_parm (core->anal->esil, res, &nres)) { if (cfgDebug) { eprintf ("RES 0x%08"PFMT64x" %"PFMT64d"\n", addr, nres); } @@ -1709,11 +1709,11 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c } } else { eprintf ("Cannot parse esil (%s)\n", input + 2); - r_anal_esil_stack_free (core->anal->esil); + rz_anal_esil_stack_free (core->anal->esil); free (res); break; } - r_anal_esil_stack_free (core->anal->esil); + rz_anal_esil_stack_free (core->anal->esil); free (res); if (hit_happens) { @@ -1732,14 +1732,14 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c hit_combo = 0; } } - r_config_set_i (core->config, "search.kwidx", search->n_kws); // TODO remove - r_cons_break_pop (); + rz_config_set_i (core->config, "search.kwidx", search->n_kws); // TODO remove + rz_cons_break_pop (); } - r_cons_clear_line (1); + rz_cons_clear_line (1); if (pj) { pj_end (pj); char *s = pj_drain (pj); - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); } } @@ -1749,16 +1749,16 @@ static void do_esil_search(RCore *core, struct search_parameters *param, const c #if USE_EMULATION // IMHO This code must be deleted -static int emulateSyscallPrelude(RCore *core, ut64 at, ut64 curpc) { +static int emulateSyscallPrelude(RzCore *core, ut64 at, ut64 curpc) { int i, inslen, bsize = R_MIN (64, core->blocksize); ut8 *arr; - RAnalOp aop; - const int mininstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + RzAnalOp aop; + const int mininstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); - const char *a0 = r_reg_get_name (core->anal->reg, R_REG_NAME_SN); - const char *pc = r_reg_get_name (core->dbg->reg, R_REG_NAME_PC); - RRegItem *r = r_reg_get (core->dbg->reg, pc, -1); - RRegItem *reg_a0 = r_reg_get (core->dbg->reg, a0, -1); + const char *a0 = rz_reg_get_name (core->anal->reg, R_REG_NAME_SN); + const char *pc = rz_reg_get_name (core->dbg->reg, R_REG_NAME_PC); + RzRegItem *r = rz_reg_get (core->dbg->reg, pc, -1); + RzRegItem *reg_a0 = rz_reg_get (core->dbg->reg, a0, -1); arr = malloc (bsize); if (!arr) { @@ -1766,15 +1766,15 @@ static int emulateSyscallPrelude(RCore *core, ut64 at, ut64 curpc) { free (arr); return -1; } - r_reg_set_value (core->dbg->reg, r, curpc); + rz_reg_set_value (core->dbg->reg, r, curpc); for (i = 0; curpc < at; curpc++, i++) { if (i >= (bsize - 32)) { i = 0; } if (!i) { - r_io_read_at (core->io, curpc, arr, bsize); + rz_io_read_at (core->io, curpc, arr, bsize); } - inslen = r_anal_op (core->anal, &aop, curpc, arr + i, bsize - i, R_ANAL_OP_MASK_BASIC); + inslen = rz_anal_op (core->anal, &aop, curpc, arr + i, bsize - i, R_ANAL_OP_MASK_BASIC); if (inslen) { int incr = (core->search->align > 0)? core->search->align - 1: inslen - 1; if (incr < 0) { @@ -1782,71 +1782,71 @@ static int emulateSyscallPrelude(RCore *core, ut64 at, ut64 curpc) { } i += incr; curpc += incr; - if (r_anal_op_nonlinear (aop.type)) { // skip the instr - r_reg_set_value (core->dbg->reg, r, curpc + 1); + if (rz_anal_op_nonlinear (aop.type)) { // skip the instr + rz_reg_set_value (core->dbg->reg, r, curpc + 1); } else { // step instr - r_core_esil_step (core, UT64_MAX, NULL, NULL); + rz_core_esil_step (core, UT64_MAX, NULL, NULL); } } } free (arr); - int sysno = r_debug_reg_get (core->dbg, a0); - r_reg_set_value (core->dbg->reg, reg_a0, -2); // clearing register A0 + int sysno = rz_debug_reg_get (core->dbg, a0); + rz_reg_set_value (core->dbg->reg, reg_a0, -2); // clearing register A0 return sysno; } #endif -static void do_syscall_search(RCore *core, struct search_parameters *param) { - RSearch *search = core->search; +static void do_syscall_search(RzCore *core, struct search_parameters *param) { + RzSearch *search = core->search; ut64 at; #if USE_EMULATION ut64 curpc; #endif ut8 *buf; int curpos, idx = 0, count = 0; - RAnalOp aop = {0}; + RzAnalOp aop = {0}; int i, ret, bsize = R_MAX (64, core->blocksize); int kwidx = core->search->n_kws; - RIOMap* map; - RListIter *iter; - const int mininstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + RzIOMap* map; + RzListIter *iter; + const int mininstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); - RAnalEsil *esil; + RzAnalEsil *esil; int align = core->search->align; - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); - if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + if (!(esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } int *previnstr = calloc (MAXINSTR + 1, sizeof (int)); if (!previnstr) { - r_anal_esil_free (esil); + rz_anal_esil_free (esil); return; } buf = malloc (bsize); if (!buf) { eprintf ("Cannot allocate %d byte(s)\n", bsize); - r_anal_esil_free (esil); + rz_anal_esil_free (esil); free (previnstr); return; } ut64 oldoff = core->offset; int syscallNumber = 0; - r_cons_break_push (NULL, NULL); - const char *a0 = r_reg_get_name (core->anal->reg, R_REG_NAME_SN); - char *esp = r_str_newf ("%s,=", a0); + rz_cons_break_push (NULL, NULL); + const char *a0 = rz_reg_get_name (core->anal->reg, R_REG_NAME_SN); + char *esp = rz_str_newf ("%s,=", a0); char *esp32 = NULL; if (core->anal->bits == 64) { - const char *reg = r_reg_64_to_32 (core->anal->reg, a0); + const char *reg = rz_reg_64_to_32 (core->anal->reg, a0); if (reg) { - esp32 = r_str_newf ("%s,=", reg); + esp32 = rz_str_newf ("%s,=", reg); } } - r_list_foreach (param->boundaries, iter, map) { + rz_list_foreach (param->boundaries, iter, map) { ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); + ut64 to = rz_itv_end (map->itv); if (from >= to) { eprintf ("Error: from must be lower than to\n"); goto beach; @@ -1856,7 +1856,7 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) { goto beach; } for (i = 0, at = from; at < to; at++, i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (i >= (bsize - 32)) { @@ -1866,9 +1866,9 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) { continue; } if (!i) { - r_io_read_at (core->io, at, buf, bsize); + rz_io_read_at (core->io, at, buf, bsize); } - ret = r_anal_op (core->anal, &aop, at, buf + i, bsize - i, R_ANAL_OP_MASK_ESIL); + ret = rz_anal_op (core->anal, &aop, at, buf + i, bsize - i, R_ANAL_OP_MASK_ESIL); curpos = idx++ % (MAXINSTR + 1); previnstr[curpos] = ret; // This array holds prev n instr size + cur instr size if (aop.type == R_ANAL_OP_TYPE_MOV) { @@ -1897,25 +1897,25 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) { scNumber = syscallNumber; #endif scVector = (aop.val > 0)? aop.val: -1; // int 0x80 (aop.val = 0x80) - RSyscallItem *item = r_syscall_get (core->anal->syscall, scNumber, scVector); + RzSyscallItem *item = rz_syscall_get (core->anal->syscall, scNumber, scVector); if (item) { - r_cons_printf ("0x%08"PFMT64x" %s\n", at, item->name); + rz_cons_printf ("0x%08"PFMT64x" %s\n", at, item->name); } memset (previnstr, 0, (MAXINSTR + 1) * sizeof (*previnstr)); // clearing the buffer if (searchflags) { - char *flag = r_str_newf ("%s%d_%d.%s", searchprefix, kwidx, count, item? item->name: "syscall"); - r_flag_set (core->flags, flag, at, ret); + char *flag = rz_str_newf ("%s%d_%d.%s", searchprefix, kwidx, count, item? item->name: "syscall"); + rz_flag_set (core->flags, flag, at, ret); free (flag); } if (*param->cmd_hit) { ut64 here = core->offset; - r_core_seek (core, at, true); - r_core_cmd (core, param->cmd_hit, 0); - r_core_seek (core, here, true); + rz_core_seek (core, at, true); + rz_core_cmd (core, param->cmd_hit, 0); + rz_core_seek (core, here, true); } count++; if (search->maxhits > 0 && count >= search->maxhits) { - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); break; } syscallNumber = 0; @@ -1926,68 +1926,68 @@ static void do_syscall_search(RCore *core, struct search_parameters *param) { } i += inc; at += inc; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } } beach: - r_core_seek (core, oldoff, true); - r_anal_esil_free (esil); - r_cons_break_pop (); + rz_core_seek (core, oldoff, true); + rz_anal_esil_free (esil); + rz_cons_break_pop (); free (buf); free (esp32); free (esp); free (previnstr); } -static void do_ref_search(RCore *core, ut64 addr,ut64 from, ut64 to, struct search_parameters *param) { +static void do_ref_search(RzCore *core, ut64 addr,ut64 from, ut64 to, struct search_parameters *param) { const int size = 12; char str[512]; - RAnalFunction *fcn; - RAnalRef *ref; - RListIter *iter; + RzAnalFunction *fcn; + RzAnalRef *ref; + RzListIter *iter; ut8 buf[12]; - RAsmOp asmop; - RList *list = r_anal_xrefs_get (core->anal, addr); + RzAsmOp asmop; + RzList *list = rz_anal_xrefs_get (core->anal, addr); if (list) { - r_list_foreach (list, iter, ref) { - r_io_read_at (core->io, ref->addr, buf, size); - r_asm_set_pc (core->rasm, ref->addr); - r_asm_disassemble (core->rasm, &asmop, buf, size); - fcn = r_anal_get_fcn_in (core->anal, ref->addr, 0); - RAnalHint *hint = r_anal_hint_get (core->anal, ref->addr); - r_parse_filter (core->parser, ref->addr, core->flags, hint, r_strbuf_get (&asmop.buf_asm), + rz_list_foreach (list, iter, ref) { + rz_io_read_at (core->io, ref->addr, buf, size); + rz_asm_set_pc (core->rasm, ref->addr); + rz_asm_disassemble (core->rasm, &asmop, buf, size); + fcn = rz_anal_get_fcn_in (core->anal, ref->addr, 0); + RzAnalHint *hint = rz_anal_hint_get (core->anal, ref->addr); + rz_parse_filter (core->parser, ref->addr, core->flags, hint, rz_strbuf_get (&asmop.buf_asm), str, sizeof (str), core->print->big_endian); - r_anal_hint_free (hint); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr); + rz_anal_hint_free (hint); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, ref->addr); char *print_comment = NULL; const char *nl = comment ? strchr (comment, '\n') : NULL; if (nl) { // display only until the first newline - comment = print_comment = r_str_ndup (comment, nl - comment); + comment = print_comment = rz_str_ndup (comment, nl - comment); } char *buf_fcn = comment - ? r_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", comment) - : r_str_newf ("%s", fcn ? fcn->name : "(nofunc)"); + ? rz_str_newf ("%s; %s", fcn ? fcn->name : "(nofunc)", comment) + : rz_str_newf ("%s", fcn ? fcn->name : "(nofunc)"); free (print_comment); if (from <= ref->addr && to >= ref->addr) { - r_cons_printf ("%s 0x%" PFMT64x " [%s] %s\n", - buf_fcn, ref->addr, r_anal_xrefs_type_tostring (ref->type), str); + rz_cons_printf ("%s 0x%" PFMT64x " [%s] %s\n", + buf_fcn, ref->addr, rz_anal_xrefs_type_tostring (ref->type), str); if (*param->cmd_hit) { ut64 here = core->offset; - r_core_seek (core, ref->addr, true); - r_core_cmd (core, param->cmd_hit, 0); - r_core_seek (core, here, true); + rz_core_seek (core, ref->addr, true); + rz_core_cmd (core, param->cmd_hit, 0); + rz_core_seek (core, here, true); } } free (buf_fcn); } } - r_list_free (list); + rz_list_free (list); } -static bool do_anal_search(RCore *core, struct search_parameters *param, const char *input) { - RSearch *search = core->search; +static bool do_anal_search(RzCore *core, struct search_parameters *param, const char *input) { + RzSearch *search = core->search; ut64 at; - RAnalOp aop; + RzAnalOp aop; int type = 0; int mode = 0; int kwidx = core->search->n_kws; @@ -2006,22 +2006,22 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c case 'f': // "/alf" for (i = 0; i < 64; i++) { const char *str = type == 'f' - ? r_anal_op_family_to_string (i) - : r_anal_optype_to_string (i); + ? rz_anal_op_family_to_string (i) + : rz_anal_optype_to_string (i); if (!str || !*str) { break; } if (!strcmp (str, "undefined")) { continue; } - r_cons_println (str); + rz_cons_println (str); } break; case 's': // "als" - r_core_cmd0 (core, "asl"); + rz_core_cmd0 (core, "asl"); break; case 0: - r_core_cmd0 (core, "aoml"); + rz_core_cmd0 (core, "aoml"); break; default: eprintf ("wat\n"); @@ -2038,7 +2038,7 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c case 0: case '?': default: - r_core_cmd_help (core, help_msg_slash_a); + rz_core_cmd_help (core, help_msg_slash_a); return false; } input++; @@ -2055,37 +2055,37 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c return true; } if (mode == 'j') { - r_cons_printf ("["); + rz_cons_printf ("["); } - input = r_str_trim_head_ro (input); - r_cons_break_push (NULL, NULL); - RIOMap* map; - RListIter *iter; - r_list_foreach (param->boundaries, iter, map) { + input = rz_str_trim_head_ro (input); + rz_cons_break_push (NULL, NULL); + RzIOMap* map; + RzListIter *iter; + rz_list_foreach (param->boundaries, iter, map) { ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); + ut64 to = rz_itv_end (map->itv); for (i = 0, at = from; at < to; i++, at++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } at = from + i; ut8 bufop[32]; - r_io_read_at (core->io, at, bufop, sizeof(bufop)); - ret = r_anal_op (core->anal, &aop, at, bufop, sizeof(bufop), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + rz_io_read_at (core->io, at, bufop, sizeof(bufop)); + ret = rz_anal_op (core->anal, &aop, at, bufop, sizeof(bufop), R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (ret) { bool match = false; if (type == 'm') { const char *fam = aop.mnemonic; - if (fam && (!*input || r_str_startswith (fam, input))) { + if (fam && (!*input || rz_str_startswith (fam, input))) { match = true; } } else if (type == 'f') { - const char *fam = r_anal_op_family_to_string (aop.family); + const char *fam = rz_anal_op_family_to_string (aop.family); if (fam && (!*input || !strcmp (input, fam))) { match = true; } } else { - const char *type = r_anal_optype_to_string (aop.type); + const char *type = rz_anal_optype_to_string (aop.type); if (type) { bool isCandidate = !*input; if (!strcmp (input, "cswi")) { @@ -2111,23 +2111,23 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c } } if (match) { - // char *opstr = r_core_disassemble_instr (core, at, 1); - char *opstr = r_core_op_str (core, at); + // char *opstr = rz_core_disassemble_instr (core, at, 1); + char *opstr = rz_core_op_str (core, at); switch (mode) { case 'j': - r_cons_printf ("%s{\"addr\":%"PFMT64d ",\"size\":%d,\"opstr\":\"%s\"}", + rz_cons_printf ("%s{\"addr\":%"PFMT64d ",\"size\":%d,\"opstr\":\"%s\"}", firstItem? "": ",", at, ret, opstr); break; case 'q': - r_cons_printf ("0x%08"PFMT64x "\n", at); + rz_cons_printf ("0x%08"PFMT64x "\n", at); break; default: if (type == 'f') { - const char *fam = r_anal_op_family_to_string (aop.family); - r_cons_printf ("0x%08"PFMT64x " %d %s %s\n", at, ret, fam, opstr); + const char *fam = rz_anal_op_family_to_string (aop.family); + rz_cons_printf ("0x%08"PFMT64x " %d %s %s\n", at, ret, fam, opstr); } else { - r_cons_printf ("0x%08"PFMT64x " %d %s\n", at, ret, opstr); + rz_cons_printf ("0x%08"PFMT64x " %d %s\n", at, ret, opstr); } break; } @@ -2136,13 +2136,13 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c char flag[64]; snprintf (flag, sizeof (flag), "%s%d_%d", searchprefix, kwidx, count); - r_flag_set (core->flags, flag, at, ret); + rz_flag_set (core->flags, flag, at, ret); } if (*param->cmd_hit) { ut64 here = core->offset; - r_core_seek (core, at, true); - r_core_cmd (core, param->cmd_hit, 0); - r_core_seek (core, here, true); + rz_core_seek (core, at, true); + rz_core_cmd (core, param->cmd_hit, 0); + rz_core_seek (core, here, true); } count++; if (search->maxhits && count >= search->maxhits) { @@ -2161,13 +2161,13 @@ static bool do_anal_search(RCore *core, struct search_parameters *param, const c } done: if (mode == 'j') { - r_cons_println ("]\n"); + rz_cons_println ("]\n"); } - r_cons_break_pop (); + rz_cons_break_pop (); return false; } -static void do_section_search(RCore *core, struct search_parameters *param, const char *input) { +static void do_section_search(RzCore *core, struct search_parameters *param, const char *input) { double threshold = 1; bool r2mode = false; if (input && *input) { @@ -2185,33 +2185,33 @@ static void do_section_search(RCore *core, struct search_parameters *param, cons return; } double oe = 0; - RListIter *iter; - RIOMap *map; + RzListIter *iter; + RzIOMap *map; ut64 begin = UT64_MAX; ut64 at, end = 0; int index = 0; bool lastBlock = true; - r_cons_break_push (NULL, NULL); - r_list_foreach (param->boundaries, iter, map) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (param->boundaries, iter, map) { ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); - if (r_cons_is_breaked ()) { + ut64 to = rz_itv_end (map->itv); + if (rz_cons_is_breaked ()) { break; } for (at = from; at < to; at += buf_size) { if (begin == UT64_MAX) { begin = at; } - r_io_read_at (core->io, at, buf, buf_size); - double e = r_hash_entropy (buf, buf_size); + rz_io_read_at (core->io, at, buf, buf_size); + double e = rz_hash_entropy (buf, buf_size); double diff = oe - e; diff = R_ABS (diff); end = at + buf_size; if (diff > threshold) { if (r2mode) { - r_cons_printf ("f entropy_section_%d 0x%08"PFMT64x" 0x%08"PFMT64x"\n", index, end - begin, begin); + rz_cons_printf ("f entropy_section_%d 0x%08"PFMT64x" 0x%08"PFMT64x"\n", index, end - begin, begin); } else { - r_cons_printf ("0x%08"PFMT64x" - 0x%08"PFMT64x" ~ %lf\n", begin, end, e); + rz_cons_printf ("0x%08"PFMT64x" - 0x%08"PFMT64x" ~ %lf\n", begin, end, e); } begin = UT64_MAX; index++; @@ -2225,23 +2225,23 @@ static void do_section_search(RCore *core, struct search_parameters *param, cons } if (begin != UT64_MAX && lastBlock) { if (r2mode) { - r_cons_printf ("f entropy_section_%d 0x%08"PFMT64x" 0x%08"PFMT64x"\n", index, end - begin, begin); + rz_cons_printf ("f entropy_section_%d 0x%08"PFMT64x" 0x%08"PFMT64x"\n", index, end - begin, begin); } else { - r_cons_printf ("0x%08"PFMT64x" - 0x%08"PFMT64x" ~ %lf .. last\n", begin, end, 0); + rz_cons_printf ("0x%08"PFMT64x" - 0x%08"PFMT64x" ~ %lf .. last\n", begin, end, 0); } index++; } - r_cons_break_pop(); + rz_cons_break_pop(); free (buf); } -static void do_asm_search(RCore *core, struct search_parameters *param, const char *input, int mode, RInterval search_itv) { - RCoreAsmHit *hit; - RListIter *iter, *itermap; +static void do_asm_search(RzCore *core, struct search_parameters *param, const char *input, int mode, RInterval search_itv) { + RzCoreAsmHit *hit; + RzListIter *iter, *itermap; int count = 0, maxhits = 0, filter = 0; - int kwidx = core->search->n_kws; // (int)r_config_get_i (core->config, "search.kwidx")-1; - RList *hits; - RIOMap *map; + int kwidx = core->search->n_kws; // (int)rz_config_get_i (core->config, "search.kwidx")-1; + RzList *hits; + RzIOMap *map; bool regexp = input[1] == '/'; // "/c/" bool everyByte = regexp && input[2] == 'a'; char *end_cmd = strchr (input, ' '); @@ -2259,49 +2259,49 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch everyByte = true; } - maxhits = (int) r_config_get_i (core->config, "search.maxhits"); - filter = (int) r_config_get_i (core->config, "asm.filter"); + maxhits = (int) rz_config_get_i (core->config, "search.maxhits"); + filter = (int) rz_config_get_i (core->config, "asm.filter"); if (param->outmode == R_MODE_JSON) { - r_cons_print ("["); + rz_cons_print ("["); } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); if (everyByte) { input ++; } - r_list_foreach (param->boundaries, itermap, map) { - if (!r_itv_overlap (search_itv, map->itv)) { + rz_list_foreach (param->boundaries, itermap, map) { + if (!rz_itv_overlap (search_itv, map->itv)) { continue; } ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); - if (r_cons_is_breaked ()) { + ut64 to = rz_itv_end (map->itv); + if (rz_cons_is_breaked ()) { break; } if (maxhits && count >= maxhits) { break; } - hits = r_core_asm_strsearch (core, end_cmd, + hits = rz_core_asm_strsearch (core, end_cmd, from, to, maxhits, regexp, everyByte, mode); if (hits) { - const char *cmdhit = r_config_get (core->config, "cmd.hit"); - r_list_foreach (hits, iter, hit) { - if (r_cons_is_breaked ()) { + const char *cmdhit = rz_config_get (core->config, "cmd.hit"); + rz_list_foreach (hits, iter, hit) { + if (rz_cons_is_breaked ()) { break; } if (cmdhit && *cmdhit) { - r_core_cmdf (core, "%s @ 0x%"PFMT64x, cmdhit, hit->addr); + rz_core_cmdf (core, "%s @ 0x%"PFMT64x, cmdhit, hit->addr); } switch (param->outmode) { case R_MODE_JSON: if (count > 0) { - r_cons_printf (","); + rz_cons_printf (","); } - r_cons_printf ( + rz_cons_printf ( "{\"offset\":%"PFMT64d ",\"len\":%d,\"code\":\"%s\"}", hit->addr, hit->len, hit->code); break; case R_MODE_RADARE: - r_cons_printf ("f %s%d_%i = 0x%08"PFMT64x "\n", + rz_cons_printf ("f %s%d_%i = 0x%08"PFMT64x "\n", searchprefix, kwidx, count, hit->addr); break; default: @@ -2309,14 +2309,14 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch char tmp[128] = { 0 }; - RAnalHint *hint = r_anal_hint_get (core->anal, hit->addr); - r_parse_filter (core->parser, hit->addr, core->flags, hint, hit->code, tmp, sizeof (tmp), + RzAnalHint *hint = rz_anal_hint_get (core->anal, hit->addr); + rz_parse_filter (core->parser, hit->addr, core->flags, hint, hit->code, tmp, sizeof (tmp), core->print->big_endian); - r_anal_hint_free (hint); - r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", + rz_anal_hint_free (hint); + rz_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, tmp); } else { - r_cons_printf ("0x%08"PFMT64x " # %i: %s\n", + rz_cons_printf ("0x%08"PFMT64x " # %i: %s\n", hit->addr, hit->len, hit->code); } break; @@ -2324,33 +2324,33 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch if (searchflags) { const char *flagname = sdb_fmt ("%s%d_%d", searchprefix, kwidx, count); if (flagname) { - r_flag_set (core->flags, flagname, hit->addr, hit->len); + rz_flag_set (core->flags, flagname, hit->addr, hit->len); } } count++; } - r_list_purge (hits); + rz_list_purge (hits); free (hits); } } if (param->outmode == R_MODE_JSON) { - r_cons_printf ("]"); + rz_cons_printf ("]"); } - r_cons_break_pop (); + rz_cons_break_pop (); } -static void do_string_search(RCore *core, RInterval search_itv, struct search_parameters *param) { +static void do_string_search(RzCore *core, RInterval search_itv, struct search_parameters *param) { ut64 at; ut8 *buf; - RSearch *search = core->search; + RzSearch *search = core->search; if (param->outmode == R_MODE_JSON) { - r_cons_printf ("["); + rz_cons_printf ("["); } - RListIter *iter; - RIOMap *map; + RzListIter *iter; + RzIOMap *map; if (!searchflags && param->outmode != R_MODE_JSON) { - r_cons_printf ("fs hits\n"); + rz_cons_printf ("fs hits\n"); } core->search->inverse = param->inverse; // TODO Bad but is to be compatible with the legacy behavior @@ -2362,69 +2362,69 @@ static void do_string_search(RCore *core, RInterval search_itv, struct search_pa /* TODO: handle last block of data */ /* TODO: handle ^C */ /* TODO: launch search in background support */ - // REMOVE OLD FLAGS r_core_cmdf (core, "f-%s*", r_config_get (core->config, "search.prefix")); - r_search_set_callback (core->search, &_cb_hit, param); + // REMOVE OLD FLAGS rz_core_cmdf (core, "f-%s*", rz_config_get (core->config, "search.prefix")); + rz_search_set_callback (core->search, &_cb_hit, param); if (!(buf = malloc (core->blocksize))) { return; } if (search->bckwrds) { - r_search_string_prepare_backward (search); + rz_search_string_prepare_backward (search); } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); // TODO search cross boundary - r_list_foreach (param->boundaries, iter, map) { - if (!r_itv_overlap (search_itv, map->itv)) { + rz_list_foreach (param->boundaries, iter, map) { + if (!rz_itv_overlap (search_itv, map->itv)) { continue; } const ut64 saved_nhits = search->nhits; - RInterval itv = r_itv_intersect (search_itv, map->itv); - if (r_cons_is_breaked ()) { + RInterval itv = rz_itv_intersect (search_itv, map->itv); + if (rz_cons_is_breaked ()) { break; } if (param->outmode != R_MODE_JSON) { - RSearchKeyword *kw = r_list_first (core->search->kws); + RzSearchKeyword *kw = rz_list_first (core->search->kws); int lenstr = kw? kw->keyword_length: 0; const char *bytestr = lenstr > 1? "bytes": "byte"; eprintf ("Searching %d %s in [0x%"PFMT64x "-0x%"PFMT64x "]\n", - kw? kw->keyword_length: 0, bytestr, itv.addr, r_itv_end (itv)); + kw? kw->keyword_length: 0, bytestr, itv.addr, rz_itv_end (itv)); } - if (r_sandbox_enable (0) && itv.size > 1024 * 64) { + if (rz_sandbox_enable (0) && itv.size > 1024 * 64) { eprintf ("Sandbox restricts search range\n"); break; } if (!core->search->bckwrds) { - RListIter* it; - RSearchKeyword* kw; - r_list_foreach (core->search->kws, it, kw) { + RzListIter* it; + RzSearchKeyword* kw; + rz_list_foreach (core->search->kws, it, kw) { kw->last = 0; } } - const ut64 from = itv.addr, to = r_itv_end (itv), + const ut64 from = itv.addr, to = rz_itv_end (itv), from1 = search->bckwrds? to: from, to1 = search->bckwrds? from: to; ut64 len; for (at = from1; at != to1; at = search->bckwrds? at - len: at + len) { print_search_progress (at, to1, search->nhits, param); - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { eprintf ("\n\n"); break; } if (search->bckwrds) { len = R_MIN (core->blocksize, at - from); // TODO prefix_read_at - if (!r_io_is_valid_offset (core->io, at - len, 0)) { + if (!rz_io_is_valid_offset (core->io, at - len, 0)) { break; } - (void)r_io_read_at (core->io, at - len, buf, len); + (void)rz_io_read_at (core->io, at - len, buf, len); } else { len = R_MIN (core->blocksize, to - at); - if (!r_io_is_valid_offset (core->io, at, 0)) { + if (!rz_io_is_valid_offset (core->io, at, 0)) { break; } - (void)r_io_read_at (core->io, at, buf, len); + (void)rz_io_read_at (core->io, at, buf, len); } - r_search_update (core->search, at, buf, len); + rz_search_update (core->search, at, buf, len); if (param->aes_search) { // Adjust length to search between blocks. if (len == core->blocksize) { @@ -2441,26 +2441,26 @@ static void do_string_search(RCore *core, RInterval search_itv, struct search_pa } } print_search_progress (at, to1, search->nhits, param); - r_cons_clear_line (1); + rz_cons_clear_line (1); core->num->value = search->nhits; if (param->outmode != R_MODE_JSON) { eprintf ("hits: %" PFMT64d "\n", search->nhits - saved_nhits); } } done: - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); } else { eprintf ("No keywords defined\n"); } if (param->outmode == R_MODE_JSON) { - r_cons_printf ("]"); + rz_cons_printf ("]"); } } static void rop_kuery(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; Sdb *db_rop = sdb_ns (core->sdb, "rop", false); bool json_first = true; SdbListIter *sdb_iter, *it; @@ -2479,12 +2479,12 @@ static void rop_kuery(void *data, const char *input) { ls_foreach (db_rop->ns, it, ns) { sdb_list = sdb_foreach_list (ns->sdb, false); ls_foreach (sdb_list, sdb_iter, kv) { - r_cons_printf ("%s ", sdbkv_key (kv)); + rz_cons_printf ("%s ", sdbkv_key (kv)); } } break; case 'j': - r_cons_print ("{\"gadgets\":["); + rz_cons_print ("{\"gadgets\":["); ls_foreach (db_rop->ns, it, ns) { sdb_list = sdb_foreach_list (ns->sdb, false); ls_foreach (sdb_list, sdb_iter, kv) { @@ -2499,9 +2499,9 @@ static void rop_kuery(void *data, const char *input) { if (json_first) { json_first = false; } else { - r_cons_print (","); + rz_cons_print (","); } - r_cons_printf ("{\"address\":%s, \"size\":%s, \"type\":\"%s\", \"effect\":\"%s\"}", + rz_cons_printf ("{\"address\":%s, \"size\":%s, \"type\":\"%s\", \"effect\":\"%s\"}", sdbkv_key (kv), size, ns->name, tok); free (dup); if (flag) { @@ -2509,37 +2509,37 @@ static void rop_kuery(void *data, const char *input) { } } } - r_cons_printf ("]}\n"); + rz_cons_printf ("]}\n"); break; case ' ': if (!strcmp (input + 1, "nop")) { out = sdb_querys (core->sdb, NULL, 0, "rop/nop/*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else if (!strcmp (input + 1, "mov")) { out = sdb_querys (core->sdb, NULL, 0, "rop/mov/*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else if (!strcmp (input + 1, "const")) { out = sdb_querys (core->sdb, NULL, 0, "rop/const/*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else if (!strcmp (input + 1, "arithm")) { out = sdb_querys (core->sdb, NULL, 0, "rop/arithm/*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else if (!strcmp (input + 1, "arithm_ct")) { out = sdb_querys (core->sdb, NULL, 0, "rop/arithm_ct/*"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } } else { @@ -2549,7 +2549,7 @@ static void rop_kuery(void *data, const char *input) { default: out = sdb_querys (core->sdb, NULL, 0, "rop/***"); if (out) { - r_cons_println (out); + rz_cons_println (out); free (out); } break; @@ -2568,47 +2568,47 @@ static int memcmpdiff(const ut8 *a, const ut8 *b, int len) { return diff; } -static void search_similar_pattern_in(RCore *core, int count, ut64 from, ut64 to) { +static void search_similar_pattern_in(RzCore *core, int count, ut64 from, ut64 to) { ut64 addr = from; ut8 *block = calloc (core->blocksize, 1); if (!block) { return; } while (addr < to) { - (void) r_io_read_at (core->io, addr, block, core->blocksize); - if (r_cons_is_breaked ()) { + (void) rz_io_read_at (core->io, addr, block, core->blocksize); + if (rz_cons_is_breaked ()) { break; } int diff = memcmpdiff (core->block, block, core->blocksize); int equal = core->blocksize - diff; if (equal >= count) { int pc = (equal * 100) / core->blocksize; - r_cons_printf ("0x%08"PFMT64x " %4d/%d %3d%% ", addr, equal, core->blocksize, pc); + rz_cons_printf ("0x%08"PFMT64x " %4d/%d %3d%% ", addr, equal, core->blocksize, pc); ut8 ptr[2] = { (ut8)(pc * 2.5), 0 }; - r_print_fill (core->print, ptr, 1, UT64_MAX, core->blocksize); + rz_print_fill (core->print, ptr, 1, UT64_MAX, core->blocksize); } addr += core->blocksize; } free (block); } -static void search_similar_pattern(RCore *core, int count, struct search_parameters *param) { - RIOMap *p; - RListIter *iter; +static void search_similar_pattern(RzCore *core, int count, struct search_parameters *param) { + RzIOMap *p; + RzListIter *iter; - r_cons_break_push (NULL, NULL); - r_list_foreach (param->boundaries, iter, p) { - search_similar_pattern_in (core, count, p->itv.addr, r_itv_end (p->itv)); + rz_cons_break_push (NULL, NULL); + rz_list_foreach (param->boundaries, iter, p) { + search_similar_pattern_in (core, count, p->itv.addr, rz_itv_end (p->itv)); } - r_cons_break_pop (); + rz_cons_break_pop (); } -static bool isArm(RCore *core) { - RAsm *as = core ? core->rasm : NULL; +static bool isArm(RzCore *core) { + RzAsm *as = core ? core->rasm : NULL; if (as && as->cur && as->cur->arch) { - if (r_str_startswith (as->cur->arch, "arm")) { + if (rz_str_startswith (as->cur->arch, "arm")) { if (as->cur->bits < 64) { return true; } @@ -2617,38 +2617,38 @@ static bool isArm(RCore *core) { return false; } -void _CbInRangeSearchV(RCore *core, ut64 from, ut64 to, int vsize, int count, void *user) { +void _CbInRangeSearchV(RzCore *core, ut64 from, ut64 to, int vsize, int count, void *user) { struct search_parameters *param = user; bool isarm = isArm (core); // this is expensive operation that could be cached but is a callback // and for not messing adding a new param - const char *prefix = r_config_get (core->config, "search.prefix"); + const char *prefix = rz_config_get (core->config, "search.prefix"); if (isarm) { if (to & 1) { to--; } } if (param->outmode != R_MODE_JSON) { - r_cons_printf ("0x%"PFMT64x ": 0x%"PFMT64x"\n", from, to); + rz_cons_printf ("0x%"PFMT64x ": 0x%"PFMT64x"\n", from, to); } else { if (count >= 1) { - r_cons_printf (","); + rz_cons_printf (","); } - r_cons_printf ("{\"offset\":%"PFMT64d ",\"value\":%"PFMT64d "}", + rz_cons_printf ("{\"offset\":%"PFMT64d ",\"value\":%"PFMT64d "}", from, to); } - r_core_cmdf (core, "f %s.value.0x%08"PFMT64x" %d = 0x%08"PFMT64x" \n", prefix, to, vsize, to); // flag at value of hit - r_core_cmdf (core, "f %s.offset.0x%08"PFMT64x" %d = 0x%08"PFMT64x " \n", prefix, from, vsize, from); // flag at offset of hit - const char *cmdHit = r_config_get (core->config, "cmd.hit"); + rz_core_cmdf (core, "f %s.value.0x%08"PFMT64x" %d = 0x%08"PFMT64x" \n", prefix, to, vsize, to); // flag at value of hit + rz_core_cmdf (core, "f %s.offset.0x%08"PFMT64x" %d = 0x%08"PFMT64x " \n", prefix, from, vsize, from); // flag at offset of hit + const char *cmdHit = rz_config_get (core->config, "cmd.hit"); if (cmdHit && *cmdHit) { ut64 addr = core->offset; - r_core_seek (core, from, true); - r_core_cmd (core, cmdHit, 0); - r_core_seek (core, addr, true); + rz_core_seek (core, from, true); + rz_core_cmd (core, cmdHit, 0); + rz_core_seek (core, addr, true); } } -static ut8 *v_writebuf(RCore *core, RList *nums, int len, char ch, int bsize) { +static ut8 *v_writebuf(RzCore *core, RzList *nums, int len, char ch, int bsize) { ut8 *ptr; ut64 n64; ut32 n32; @@ -2665,24 +2665,24 @@ static ut8 *v_writebuf(RCore *core, RList *nums, int len, char ch, int bsize) { for (i = 0; i < len; i++) { switch (ch) { case '1': - n8 = r_num_math (core->num, r_list_pop_head (nums)); - r_write_le8 (ptr, n8); + n8 = rz_num_math (core->num, rz_list_pop_head (nums)); + rz_write_le8 (ptr, n8); ptr = (ut8 *) ptr + sizeof (ut8); break; case '2': - n16 = r_num_math (core->num, r_list_pop_head (nums)); - r_write_le16 (ptr, n16); + n16 = rz_num_math (core->num, rz_list_pop_head (nums)); + rz_write_le16 (ptr, n16); ptr = (ut8 *) ptr + sizeof (ut16); break; case '4': - n32 = (ut32)r_num_math (core->num, r_list_pop_head (nums)); - r_write_le32 (ptr, n32); + n32 = (ut32)rz_num_math (core->num, rz_list_pop_head (nums)); + rz_write_le32 (ptr, n32); ptr = (ut8 *) ptr + sizeof (ut32); break; default: case '8': - n64 = r_num_math (core->num, r_list_pop_head (nums)); - r_write_le64 (ptr, n64); + n64 = rz_num_math (core->num, rz_list_pop_head (nums)); + rz_write_le64 (ptr, n64); ptr = (ut8 *) ptr + sizeof (ut64); break; } @@ -2779,7 +2779,7 @@ static void incDigitBuffer(ut8 *buf, int bufsz) { // may overflow/hang/end/stop/whatever here } -static void search_collisions(RCore *core, const char *hashName, const ut8 *hashValue, int hashLength, int mode) { +static void search_collisions(RzCore *core, const char *hashName, const ut8 *hashValue, int hashLength, int mode) { ut8 R_ALIGNED(8) cmphash[128]; int i, algoType = R_HASH_CRC32; int bufsz = core->blocksize; @@ -2795,26 +2795,26 @@ static void search_collisions(RCore *core, const char *hashName, const ut8 *hash } memcpy (cmphash, hashValue, hashLength); - ut64 hashBits = r_hash_name_to_bits (hashName); - int hashSize = r_hash_size (hashBits); + ut64 hashBits = rz_hash_name_to_bits (hashName); + int hashSize = rz_hash_size (hashBits); if (hashLength != hashSize) { eprintf ("Invalid hash size %d vs %d\n", hashLength, hashSize); free (buf); return; } - RHash *ctx = r_hash_new (true, algoType); + RzHash *ctx = rz_hash_new (true, algoType); if (!ctx) { free (buf); return; } - r_cons_break_push (NULL, NULL); - ut64 prev = r_time_now_mono (); + rz_cons_break_push (NULL, NULL); + ut64 prev = rz_time_now_mono (); ut64 inc = 0; int amount = 0; int mount = 0; - while (!r_cons_is_breaked ()) { - ut64 now = r_time_now_mono (); + while (!rz_cons_is_breaked ()) { + ut64 now = rz_time_now_mono (); if (now < (prev + 1000000)) { amount++; } else { @@ -2852,9 +2852,9 @@ static void search_collisions(RCore *core, const char *hashName, const ut8 *hash eprintf (" \"%s\"", buf); } - r_hash_do_begin (ctx, hashBits); - (void)r_hash_calculate (ctx, hashBits, buf, bufsz); - r_hash_do_end (ctx, hashBits); + rz_hash_do_begin (ctx, hashBits); + (void)rz_hash_calculate (ctx, hashBits, buf, bufsz); + rz_hash_do_end (ctx, hashBits); eprintf (" digest:"); for (i = 0; i < hashLength; i++) { @@ -2863,24 +2863,24 @@ static void search_collisions(RCore *core, const char *hashName, const ut8 *hash eprintf (" (%d h/s) \r", mount); if (!memcmp (hashValue, ctx->digest, hashLength)) { eprintf ("\nCOLLISION FOUND!\n"); - r_print_hexdump (core->print, core->offset, buf, bufsz, 0, 16, 0); - r_cons_flush (); + rz_print_hexdump (core->print, core->offset, buf, bufsz, 0, 16, 0); + rz_cons_flush (); } inc++; } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); - r_hash_free (ctx); + rz_hash_free (ctx); } -static void __core_cmd_search_asm_infinite (RCore *core, const char *arg) { - const char *search_in = r_config_get (core->config, "search.in"); - RList *boundaries = r_core_get_boundaries_prot (core, -1, search_in, "search"); - RListIter *iter; - RIOMap *map; - RAnalOp analop; +static void __core_cmd_search_asm_infinite (RzCore *core, const char *arg) { + const char *search_in = rz_config_get (core->config, "search.in"); + RzList *boundaries = rz_core_get_boundaries_prot (core, -1, search_in, "search"); + RzListIter *iter; + RzIOMap *map; + RzAnalOp analop; ut64 at; - r_list_foreach (boundaries, iter, map) { + rz_list_foreach (boundaries, iter, map) { ut64 map_begin = map->itv.addr; ut64 map_size = map->itv.size; ut64 map_end = map_begin + map_size; @@ -2888,33 +2888,33 @@ static void __core_cmd_search_asm_infinite (RCore *core, const char *arg) { if (!buf) { continue; } - (void) r_io_read_at (core->io, map_begin, buf, map_size); + (void) rz_io_read_at (core->io, map_begin, buf, map_size); for (at = map->itv.addr; at + 24< map_end; at += 1) { - r_anal_op (core->anal, &analop, at, buf + (at - map_begin), 24, R_ANAL_OP_MASK_HINT); + rz_anal_op (core->anal, &analop, at, buf + (at - map_begin), 24, R_ANAL_OP_MASK_HINT); if (at == analop.jump) { - r_cons_printf ("0x%08"PFMT64x"\n", at); + rz_cons_printf ("0x%08"PFMT64x"\n", at); } at += analop.size; - r_anal_op_fini (&analop); + rz_anal_op_fini (&analop); } free (buf); } } -static void __core_cmd_search_asm_byteswap (RCore *core, int nth) { - RAsmOp asmop; +static void __core_cmd_search_asm_byteswap (RzCore *core, int nth) { + RzAsmOp asmop; ut8 buf[32]; int i; - r_io_read_at (core->io, 0, buf, sizeof (buf)); + rz_io_read_at (core->io, 0, buf, sizeof (buf)); if (nth < 0 || nth >= sizeof (buf) - 1) { return; } for (i = 0; i <= 0xff; i++) { buf[nth] = i; - if (r_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)) > 0) { - const char *asmstr = r_strbuf_get (&asmop.buf_asm); + if (rz_asm_disassemble (core->rasm, &asmop, buf, sizeof (buf)) > 0) { + const char *asmstr = rz_strbuf_get (&asmop.buf_asm); if (!strstr (asmstr, "invalid") && !strstr (asmstr, "unaligned")) { - r_cons_printf ("%02x %s\n", i, asmstr); + rz_cons_printf ("%02x %s\n", i, asmstr); } } } @@ -2923,10 +2923,10 @@ static void __core_cmd_search_asm_byteswap (RCore *core, int nth) { static int cmd_search(void *data, const char *input) { bool dosearch = false; int ret = true; - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; struct search_parameters param = { .core = core, - .cmd_hit = r_config_get (core->config, "cmd.hit"), + .cmd_hit = rz_config_get (core->config, "cmd.hit"), .outmode = 0, .inverse = false, .aes_search = false, @@ -2935,7 +2935,7 @@ static int cmd_search(void *data, const char *input) { if (!param.cmd_hit) { param.cmd_hit = ""; } - RSearch *search = core->search; + RzSearch *search = core->search; int ignorecase = false; int param_offset = 2; char *inp; @@ -2960,9 +2960,9 @@ static int cmd_search(void *data, const char *input) { } core->in_search = true; - r_flag_space_push (core->flags, "search"); - const ut64 search_from = r_config_get_i (core->config, "search.from"), - search_to = r_config_get_i (core->config, "search.to"); + rz_flag_space_push (core->flags, "search"); + const ut64 search_from = rz_config_get_i (core->config, "search.from"), + search_to = rz_config_get_i (core->config, "search.to"); if (search_from > search_to && search_to) { eprintf ("search.from > search.to is not supported\n"); ret = false; @@ -2984,9 +2984,9 @@ static int cmd_search(void *data, const char *input) { c = 0; - searchshow = r_config_get_i (core->config, "search.show"); - param.mode = r_config_get (core->config, "search.in"); - param.boundaries = r_core_get_boundaries_prot (core, -1, param.mode, "search"); + searchshow = rz_config_get_i (core->config, "search.show"); + param.mode = rz_config_get (core->config, "search.in"); + param.boundaries = rz_core_get_boundaries_prot (core, -1, param.mode, "search"); /* this introduces a bug until we implement backwards search @@ -3000,11 +3000,11 @@ static int cmd_search(void *data, const char *input) { remove when everything is done */ - core->search->align = r_config_get_i (core->config, "search.align"); - searchflags = r_config_get_i (core->config, "search.flags"); - core->search->maxhits = r_config_get_i (core->config, "search.maxhits"); - searchprefix = r_config_get (core->config, "search.prefix"); - core->search->overlap = r_config_get_i (core->config, "search.overlap"); + core->search->align = rz_config_get_i (core->config, "search.align"); + searchflags = rz_config_get_i (core->config, "search.flags"); + core->search->maxhits = rz_config_get_i (core->config, "search.maxhits"); + searchprefix = rz_config_get (core->config, "search.prefix"); + core->search->overlap = rz_config_get_i (core->config, "search.overlap"); core->search->bckwrds = false; /* Quick & dirty check for json output */ @@ -3027,52 +3027,52 @@ reread: search->bckwrds = true; if (core->offset) { RInterval itv = {0, core->offset}; - if (!r_itv_overlap (search_itv, itv)) { + if (!rz_itv_overlap (search_itv, itv)) { ret = false; goto beach; } else { - search_itv = r_itv_intersect (search_itv, itv); + search_itv = rz_itv_intersect (search_itv, itv); } } goto reread; case 'o': { // "/o" print the offset of the Previous opcode - ut64 addr, n = input[param_offset - 1] ? r_num_math (core->num, input + param_offset) : 1; + ut64 addr, n = input[param_offset - 1] ? rz_num_math (core->num, input + param_offset) : 1; n = R_ABS((st64)n); if (((st64)n) < 1) { n = 1; } - if (!r_core_prevop_addr (core, core->offset, n, &addr)) { + if (!rz_core_prevop_addr (core, core->offset, n, &addr)) { addr = UT64_MAX; - (void)r_core_asm_bwdis_len (core, NULL, &addr, n); + (void)rz_core_asm_bwdis_len (core, NULL, &addr, n); } if (param.outmode == R_MODE_JSON) { - r_cons_printf ("[%"PFMT64u "]", addr); + rz_cons_printf ("[%"PFMT64u "]", addr); } else { - r_cons_printf ("0x%08"PFMT64x "\n", addr); + rz_cons_printf ("0x%08"PFMT64x "\n", addr); } break; } case 'O': { // "/O" alternative to "/o" - ut64 addr, n = input[param_offset - 1] ? r_num_math (core->num, input + param_offset) : 1; + ut64 addr, n = input[param_offset - 1] ? rz_num_math (core->num, input + param_offset) : 1; if (!n) { n = 1; } - addr = r_core_prevop_addr_force (core, core->offset, n); + addr = rz_core_prevop_addr_force (core, core->offset, n); if (param.outmode == R_MODE_JSON) { - r_cons_printf ("[%"PFMT64u "]", addr); + rz_cons_printf ("[%"PFMT64u "]", addr); } else { - r_cons_printf ("0x%08"PFMT64x "\n", addr); + rz_cons_printf ("0x%08"PFMT64x "\n", addr); } break; } case 'R': // "/R" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_slash_R); + rz_core_cmd_help (core, help_msg_slash_R); } else if (input[1] == '/') { - r_core_search_rop (core, search_itv, 0, input + 1, 1, ¶m); + rz_core_search_rop (core, search_itv, 0, input + 1, 1, ¶m); } else if (input[1] == 'k') { if (input[2] == '?') { - r_core_cmd_help (core, help_msg_slash_Rk); + rz_core_cmd_help (core, help_msg_slash_Rk); } else { rop_kuery (core, input + 2); } @@ -3080,14 +3080,14 @@ reread: Sdb *gadgetSdb = sdb_ns (core->sdb, "gadget_sdb", false); if (!gadgetSdb) { - r_core_search_rop (core, search_itv, 0, input + 1, 0, ¶m); + rz_core_search_rop (core, search_itv, 0, input + 1, 0, ¶m); } else { SdbKv *kv; SdbListIter *sdb_iter; SdbList *sdb_list = sdb_foreach_list (gadgetSdb, true); ls_foreach (sdb_list, sdb_iter, kv) { - RList *hitlist = r_core_asm_hit_list_new (); + RzList *hitlist = rz_core_asm_hit_list_new (); if (!hitlist) { goto beach; } @@ -3104,19 +3104,19 @@ reread: } do { - RCoreAsmHit *hit = r_core_asm_hit_new (); + RzCoreAsmHit *hit = rz_core_asm_hit_new (); if (!hit) { - r_list_free (hitlist); + rz_list_free (hitlist); goto beach; } sscanf (s, "%"PFMT64x"(%"PFMT32d")", &addr, &opsz); hit->addr = addr; hit->len = opsz; - r_list_append (hitlist, hit); + rz_list_append (hitlist, hit); } while (*(s = strchr (s, ')') + 1) != '\0'); print_rop (core, hitlist, mode, &json_first); - r_list_free (hitlist); + rz_list_free (hitlist); } } } @@ -3124,7 +3124,7 @@ reread: case 'r': // "/r" and "/re" { ut64 n = (input[1] == ' ' || (input[1] && input[2]==' ')) - ? r_num_math (core->num, input + 2): UT64_MAX; + ? rz_num_math (core->num, input + 2): UT64_MAX; if (n == 0LL) { eprintf ("Cannot find null references.\n"); break; @@ -3132,21 +3132,21 @@ reread: switch (input[1]) { case 'c': // "/rc" { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - r_core_anal_search (core, map->itv.addr, r_itv_end (map->itv), n, 'c'); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + rz_core_anal_search (core, map->itv.addr, rz_itv_end (map->itv), n, 'c'); } } break; case 'a': // "/ra" { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - r_core_anal_search (core, map->itv.addr, r_itv_end (map->itv), n, 0); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + rz_core_anal_search (core, map->itv.addr, rz_itv_end (map->itv), n, 0); } } break; @@ -3154,73 +3154,73 @@ reread: if (input[2] == '?') { eprintf ("Usage: /re $$ - to find references to current address\n"); } else { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - ut64 refptr = r_num_math (core->num, input + 2); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + ut64 refptr = rz_num_math (core->num, input + 2); ut64 curseek = core->offset; - r_core_seek (core, map->itv.addr, true); - char *arg = r_str_newf (" %"PFMT64d, r_itv_end (map->itv) - map->itv.addr); - char *trg = refptr? r_str_newf (" %"PFMT64d, refptr): strdup (""); - r_core_anal_esil (core, arg, trg); + rz_core_seek (core, map->itv.addr, true); + char *arg = rz_str_newf (" %"PFMT64d, rz_itv_end (map->itv) - map->itv.addr); + char *trg = refptr? rz_str_newf (" %"PFMT64d, refptr): strdup (""); + rz_core_anal_esil (core, arg, trg); free (arg); free (trg); - r_core_seek (core, curseek, true); + rz_core_seek (core, curseek, true); } } break; case 'r': // "/rr" - read refs { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - r_core_anal_search (core, map->itv.addr, r_itv_end (map->itv), n, 'r'); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + rz_core_anal_search (core, map->itv.addr, rz_itv_end (map->itv), n, 'r'); } } break; case 'w': // "/rw" - write refs { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - r_core_anal_search (core, map->itv.addr, r_itv_end (map->itv), n, 'w'); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- 0x%"PFMT64x" 0x%"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + rz_core_anal_search (core, map->itv.addr, rz_itv_end (map->itv), n, 'w'); } } break; case ' ': // "/r $$" case 0: // "/r" { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { ut64 from = map->itv.addr; - ut64 to = r_itv_end (map->itv); + ut64 to = rz_itv_end (map->itv); if (input[param_offset - 1] == ' ') { - r_core_anal_search (core, from, to, - r_num_math (core->num, input + 2), 0); - do_ref_search (core, r_num_math (core->num, input + 2), from, to, ¶m); + rz_core_anal_search (core, from, to, + rz_num_math (core->num, input + 2), 0); + do_ref_search (core, rz_num_math (core->num, input + 2), from, to, ¶m); } else { - r_core_anal_search (core, from, to, core->offset, 0); + rz_core_anal_search (core, from, to, core->offset, 0); do_ref_search (core, core->offset, from, to, ¶m); } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } } } break; case '?': - r_core_cmd_help (core, help_msg_slash_r); + rz_core_cmd_help (core, help_msg_slash_r); break; } } break; case 'a': // "/a" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_slash_a); + rz_core_cmd_help (core, help_msg_slash_a); } else if (input[1] == 'd') { // "ad" dosearch = 0; do_asm_search (core, ¶m, input + 1, 0, search_itv); @@ -3239,27 +3239,27 @@ reread: } else if (input[1] == 'i') { // "/ai" do_asm_search (core, ¶m, input + 2, 'i', search_itv); } else if (input[1] == '1') { // "a1" - __core_cmd_search_asm_byteswap (core, (int)r_num_math (core->num, input + 2)); + __core_cmd_search_asm_byteswap (core, (int)rz_num_math (core->num, input + 2)); } else if (input[1] == 'I') { // "/aI" - infinite - __core_cmd_search_asm_infinite (core, r_str_trim_head_ro (input + 1)); + __core_cmd_search_asm_infinite (core, rz_str_trim_head_ro (input + 1)); } else if (input[1] == ' ') { if (input[param_offset - 1]) { - char *kwd = r_core_asm_search (core, input + param_offset); + char *kwd = rz_core_asm_search (core, input + param_offset); if (!kwd) { ret = false; goto beach; } dosearch = true; - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); - r_search_kw_add (core->search, - r_search_keyword_new_hexmask (kwd, NULL)); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); + rz_search_kw_add (core->search, + rz_search_keyword_new_hexmask (kwd, NULL)); free (kwd); } } else if (input[1] == 's') { if (input[2] == 'l') { // "asl" - r_core_cmd0 (core, "asl"); + rz_core_cmd0 (core, "asl"); } else { // "as" do_syscall_search (core, ¶m); } @@ -3275,7 +3275,7 @@ reread: { ret = false; char *space = strchr (input, ' '); - const char *arg = space? r_str_trim_head_ro (space + 1): NULL; + const char *arg = space? rz_str_trim_head_ro (space + 1): NULL; if (!arg || input[2] == '?') { eprintf ("Usage: /cc[aAdlpb] [hashname] [hexpairhashvalue]\n"); eprintf (" /cca - lowercase alphabet chars only\n"); @@ -3295,14 +3295,14 @@ reread: char *hashName = s; ut8 *hashValue = (ut8*)strdup (sp); if (hashValue) { - if (!r_str_startswith ((const char *)hashValue, "0x")) { + if (!rz_str_startswith ((const char *)hashValue, "0x")) { // TODO: support bigger hashes int hashLength = 4; - ut32 n = (ut32)r_num_get (NULL, (const char *)hashValue); + ut32 n = (ut32)rz_num_get (NULL, (const char *)hashValue); memcpy (hashValue, (const ut8*)&n, sizeof (ut32)); search_collisions (core, hashName, hashValue, hashLength, mode); } else { - int hashLength = r_hex_str2bin (sp, hashValue); + int hashLength = rz_hex_str2bin (sp, hashValue); if (hashLength > 0) { search_collisions (core, hashName, hashValue, hashLength, mode); } else { @@ -3324,12 +3324,12 @@ reread: break; case 'd': // "cd" { - RSearchKeyword *kw; - kw = r_search_keyword_new_hex ("308200003082", "ffff0000ffff", NULL); + RzSearchKeyword *kw; + kw = rz_search_keyword_new_hex ("308200003082", "ffff0000ffff", NULL); if (kw) { - r_search_kw_add (core->search, kw); + rz_search_kw_add (core->search, kw); // eprintf ("Searching %d byte(s)...\n", kw->keyword_length); - r_search_begin (core->search); + rz_search_begin (core->search); } else { eprintf ("bad pointer\n"); dosearch = false; @@ -3338,97 +3338,97 @@ reread: break; case 'a': // "ca" { - RSearchKeyword *kw; - kw = r_search_keyword_new_hexmask ("00", NULL); + RzSearchKeyword *kw; + kw = rz_search_keyword_new_hexmask ("00", NULL); // AES search is done over 40 bytes kw->keyword_length = AES_SEARCH_LENGTH; - r_search_reset (core->search, R_SEARCH_AES); - r_search_kw_add (search, kw); - r_search_begin (core->search); + rz_search_reset (core->search, R_SEARCH_AES); + rz_search_kw_add (search, kw); + rz_search_begin (core->search); param.aes_search = true; break; } case 'r': // "cr" { - RSearchKeyword *kw; - kw = r_search_keyword_new_hexmask ("00", NULL); + RzSearchKeyword *kw; + kw = rz_search_keyword_new_hexmask ("00", NULL); // Private key search is at least 11 bytes kw->keyword_length = PRIVATE_KEY_SEARCH_LENGTH; - r_search_reset (core->search, R_SEARCH_PRIV_KEY); - r_search_kw_add (search, kw); - r_search_begin (core->search); + rz_search_reset (core->search, R_SEARCH_PRIV_KEY); + rz_search_kw_add (search, kw); + rz_search_begin (core->search); param.privkey_search = true; break; } default: { dosearch = false; - r_core_cmd_help (core, help_msg_slash_c); + rz_core_cmd_help (core, help_msg_slash_c); } } } break; case 'm': // "/m" dosearch = false; if (input[1] == '?') { // "/me" - r_core_cmd_help (core, help_msg_slash_m); + rz_core_cmd_help (core, help_msg_slash_m); } else if (input[1] == 'b') { // "/mb" - bool bin_verbose = r_config_get_i (core->config, "bin.verbose"); - r_config_set_i (core->config, "bin.verbose", false); + bool bin_verbose = rz_config_get_i (core->config, "bin.verbose"); + rz_config_set_i (core->config, "bin.verbose", false); // TODO : iter maps? cmd_search_bin (core, search_itv); - r_config_set_i (core->config, "bin.verbose", bin_verbose); + rz_config_set_i (core->config, "bin.verbose", bin_verbose); } else if (input[1] == 'm') { // "/mm" ut64 addr = search_itv.addr; - RListIter *iter; - RIOMap *map; + RzListIter *iter; + RzIOMap *map; int count = 0; const int align = core->search->align; - r_list_foreach (param.boundaries, iter, map) { - // eprintf ("-- %llx %llx\n", map->itv.addr, r_itv_end (map->itv)); - r_cons_break_push (NULL, NULL); - for (addr = map->itv.addr; addr < r_itv_end (map->itv); addr++) { - if (r_cons_is_breaked ()) { + rz_list_foreach (param.boundaries, iter, map) { + // eprintf ("-- %llx %llx\n", map->itv.addr, rz_itv_end (map->itv)); + rz_cons_break_push (NULL, NULL); + for (addr = map->itv.addr; addr < rz_itv_end (map->itv); addr++) { + if (rz_cons_is_breaked ()) { break; } if (align && (0 != (addr % align))) { addr += (addr % align) - 1; continue; } - char *mp = r_str_newf ("/mnt%d", count); + char *mp = rz_str_newf ("/mnt%d", count); eprintf ("[*] Trying to mount at 0x%08"PFMT64x"\r[", addr); - if (r_fs_mount (core->fs, NULL, mp, addr)) { + if (rz_fs_mount (core->fs, NULL, mp, addr)) { count ++; eprintf ("Mounted %s at 0x%08"PFMT64x"\n", mp, addr); } free (mp); } - r_cons_clear_line (1); - r_cons_break_pop (); + rz_cons_clear_line (1); + rz_cons_break_pop (); } eprintf ("\n"); } else if (input[1] == 'e') { // "/me" - r_cons_printf ("* r2 thinks%s\n", input + 2); + rz_cons_printf ("* r2 thinks%s\n", input + 2); } else if (input[1] == ' ' || input[1] == '\0' || param.outmode == R_MODE_JSON) { int ret; const char *file = input[param_offset - 1]? input + param_offset: NULL; ut64 addr = search_itv.addr; - RListIter *iter; - RIOMap *map; + RzListIter *iter; + RzIOMap *map; if (param.outmode == R_MODE_JSON) { - r_cons_printf ("["); + rz_cons_printf ("["); } - r_core_magic_reset (core); - int maxHits = r_config_get_i (core->config, "search.maxhits"); + rz_core_magic_reset (core); + int maxHits = rz_config_get_i (core->config, "search.maxhits"); int hits = 0; - r_list_foreach (param.boundaries, iter, map) { + rz_list_foreach (param.boundaries, iter, map) { if (param.outmode != R_MODE_JSON) { - eprintf ("-- %llx %llx\n", map->itv.addr, r_itv_end (map->itv)); + eprintf ("-- %llx %llx\n", map->itv.addr, rz_itv_end (map->itv)); } - r_cons_break_push (NULL, NULL); - for (addr = map->itv.addr; addr < r_itv_end (map->itv); addr++) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + for (addr = map->itv.addr; addr < rz_itv_end (map->itv); addr++) { + if (rz_cons_is_breaked ()) { break; } - ret = r_core_magic_at (core, file, addr, 99, false, param.outmode == R_MODE_JSON, &hits); + ret = rz_core_magic_at (core, file, addr, 99, false, param.outmode == R_MODE_JSON, &hits); if (ret == -1) { // something went terribly wrong. break; @@ -3438,30 +3438,30 @@ reread: } addr += ret - 1; } - r_cons_clear_line (1); - r_cons_break_pop (); + rz_cons_clear_line (1); + rz_cons_break_pop (); } if (param.outmode == R_MODE_JSON) { - r_cons_printf ("]"); + rz_cons_printf ("]"); } } else { eprintf ("Usage: /m [file]\n"); } - r_cons_clear_line (1); + rz_cons_clear_line (1); break; case 'p': // "/p" { if (input[param_offset - 1]) { int ps = atoi (input + param_offset); if (ps > 1) { - RListIter *iter; - RIOMap *map; - r_list_foreach (param.boundaries, iter, map) { - eprintf ("-- %llx %llx\n", map->itv.addr, r_itv_end (map->itv)); - r_cons_break_push (NULL, NULL); - r_search_pattern_size (core->search, ps); - r_search_pattern (core->search, map->itv.addr, r_itv_end (map->itv)); - r_cons_break_pop (); + RzListIter *iter; + RzIOMap *map; + rz_list_foreach (param.boundaries, iter, map) { + eprintf ("-- %llx %llx\n", map->itv.addr, rz_itv_end (map->itv)); + rz_cons_break_push (NULL, NULL); + rz_search_pattern_size (core->search, ps); + rz_search_pattern (core->search, map->itv.addr, rz_itv_end (map->itv)); + rz_cons_break_pop (); } break; } @@ -3484,19 +3484,19 @@ reread: const char *num_str = input + param_offset + 1; if (vsize && input[2] && num_str) { if (param.outmode == R_MODE_JSON) { - r_cons_printf ("["); + rz_cons_printf ("["); } char *w = strchr (num_str, ' '); if (w) { *w++ = 0; - ut64 vmin = r_num_math (core->num, num_str); - ut64 vmax = r_num_math (core->num, w); + ut64 vmin = rz_num_math (core->num, num_str); + ut64 vmax = rz_num_math (core->num, w); if (vsize > 0) { - RIOMap *map; - RListIter *iter; - r_list_foreach (param.boundaries, iter, map) { + RzIOMap *map; + RzListIter *iter; + rz_list_foreach (param.boundaries, iter, map) { err = 0; - int hits = r_core_search_value_in_range (core, map->itv, + int hits = rz_core_search_value_in_range (core, map->itv, vmin, vmax, vsize, _CbInRangeSearchV, ¶m); if (param.outmode != R_MODE_JSON) { @@ -3506,7 +3506,7 @@ reread: } } if (param.outmode == R_MODE_JSON) { - r_cons_printf ("]"); + rz_cons_printf ("]"); } } if (err) { @@ -3518,7 +3518,7 @@ reread: case 'v': // "/v" if (input[1]) { if (input[1] == '?') { - r_cons_print ("Usage: /v[1|2|4|8] [value]\n"); + rz_cons_print ("Usage: /v[1|2|4|8] [value]\n"); break; } if (input[2] == 'j') { @@ -3526,12 +3526,12 @@ reread: param_offset++; } } - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); - char *v_str = (char *)r_str_trim_head_ro (input + param_offset); - RList *nums = r_num_str_split_list (v_str); - int len = r_list_length (nums); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); + char *v_str = (char *)rz_str_trim_head_ro (input + param_offset); + RzList *nums = rz_num_str_split_list (v_str); + int len = rz_list_length (nums); int bsize = 0; ut8 *v_buf = NULL; switch (input[1]) { @@ -3572,11 +3572,11 @@ reread: break; } if (v_buf) { - r_search_kw_add (core->search, - r_search_keyword_new ((const ut8 *) v_buf, bsize, NULL, 0, NULL)); + rz_search_kw_add (core->search, + rz_search_keyword_new ((const ut8 *) v_buf, bsize, NULL, 0, NULL)); free (v_buf); } - r_search_begin (core->search); + rz_search_begin (core->search); dosearch = true; break; case 'w': // "/w" search wide string, includes ignorecase search functionality (/wi cmd)! @@ -3609,16 +3609,16 @@ reread: } p[1] = 0; } - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); - RSearchKeyword *skw; - skw = r_search_keyword_new ((const ut8 *) inp, len * 2, NULL, 0, NULL); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); + RzSearchKeyword *skw; + skw = rz_search_keyword_new ((const ut8 *) inp, len * 2, NULL, 0, NULL); free (inp); if (skw) { skw->icase = ignorecase; - r_search_kw_add (core->search, skw); - r_search_begin (core->search); + rz_search_kw_add (core->search, skw); + rz_search_begin (core->search); dosearch = true; } else { eprintf ("Invalid keyword\n"); @@ -3638,52 +3638,52 @@ reread: // fallthrough case ' ': // "/ " search string inp = strdup (input + 1 + ignorecase + (param.outmode == R_MODE_JSON ? 1 : 0)); - len = r_str_unescape (inp); + len = rz_str_unescape (inp); #if 0 if (!json) { eprintf ("Searching %d byte(s) from 0x%08"PFMT64x " to 0x%08"PFMT64x ": ", - len, search_itv.addr, r_itv_end (search_itv)); + len, search_itv.addr, rz_itv_end (search_itv)); for (i = 0; i < len; i++) { eprintf ("%02x ", (ut8) inp[i]); } eprintf ("\n"); } #endif - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); { - RSearchKeyword *skw; - skw = r_search_keyword_new ((const ut8 *) inp, len, NULL, 0, NULL); + RzSearchKeyword *skw; + skw = rz_search_keyword_new ((const ut8 *) inp, len, NULL, 0, NULL); free (inp); if (skw) { skw->icase = ignorecase; skw->type = R_SEARCH_KEYWORD_TYPE_STRING; - r_search_kw_add (core->search, skw); + rz_search_kw_add (core->search, skw); } else { eprintf ("Invalid keyword\n"); break; } } - r_search_begin (core->search); + rz_search_begin (core->search); dosearch = true; break; case 'e': // "/e" match regexp if (input[1] == '?') { eprintf ("Usage: /e /foo/i or /e/foo/i\n"); } else if (input[1]) { - RSearchKeyword *kw; - kw = r_search_keyword_new_regexp (input + 1, NULL); + RzSearchKeyword *kw; + kw = rz_search_keyword_new_regexp (input + 1, NULL); if (!kw) { eprintf ("Invalid regexp specified\n"); break; } - r_search_reset (core->search, R_SEARCH_REGEXP); + rz_search_reset (core->search, R_SEARCH_REGEXP); // TODO distance is unused - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); - r_search_kw_add (core->search, kw); - r_search_begin (core->search); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); + rz_search_kw_add (core->search, kw); + rz_search_begin (core->search); dosearch = true; } else { eprintf ("Missing regex\n"); @@ -3691,16 +3691,16 @@ reread: break; case 'E': // "/E" if (core->bin && core->bin->is_debugger) { - r_debug_map_sync (core->dbg); + rz_debug_map_sync (core->dbg); } do_esil_search (core, ¶m, input); goto beach; case 'd': // "/d" search delta key if (input[1]) { - r_search_reset (core->search, R_SEARCH_DELTAKEY); - r_search_kw_add (core->search, - r_search_keyword_new_hexmask (input + param_offset, NULL)); - r_search_begin (core->search); + rz_search_reset (core->search, R_SEARCH_DELTAKEY); + rz_search_kw_add (core->search, + rz_search_keyword_new_hexmask (input + param_offset, NULL)); + rz_search_begin (core->search); dosearch = true; } else { eprintf ("Missing delta\n"); @@ -3708,7 +3708,7 @@ reread: break; case 'h': // "/h" { - char *p, *arg = r_str_trim_dup (input + 1); + char *p, *arg = rz_str_trim_dup (input + 1); p = strchr (arg, ' '); if (p) { *p++ = 0; @@ -3723,9 +3723,9 @@ reread: pmax = strchr (pmin, ' '); if (pmax) { *pmax++ = 0; - max = r_num_math (core->num, pmax); + max = rz_num_math (core->num, pmax); } - min = r_num_math (core->num, pmin); + min = rz_num_math (core->num, pmin); } search_hash (core, arg, p, min, max, ¶m); } @@ -3738,84 +3738,84 @@ reread: case 'f': // "/f" forward search if (core->offset) { RInterval itv = {core->offset, -core->offset}; - if (!r_itv_overlap (search_itv, itv)) { + if (!rz_itv_overlap (search_itv, itv)) { ret = false; goto beach; } else { - search_itv = r_itv_intersect (search_itv, itv); + search_itv = rz_itv_intersect (search_itv, itv); } } break; case 'g': // "/g" graph search if (input[1] == '?') { - r_cons_printf ("Usage: /g[g] [fromaddr] @ [toaddr]\n"); - r_cons_printf ("(find all graph paths A to B (/gg follow jumps, see search.count and anal.depth)"); + rz_cons_printf ("Usage: /g[g] [fromaddr] @ [toaddr]\n"); + rz_cons_printf ("(find all graph paths A to B (/gg follow jumps, see search.count and anal.depth)"); } else { ut64 addr = UT64_MAX; if (input[1]) { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } else { - RAnalFunction *fcn = r_anal_get_function_at (core->anal, addr); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, addr); if (fcn) { addr = fcn->addr; } else { addr = core->offset; } } - const int depth = r_config_get_i (core->config, "anal.depth"); + const int depth = rz_config_get_i (core->config, "anal.depth"); // Va;ifate input length if (input[1] != '\0') { - r_core_anal_paths (core, addr, core->offset, input[1] == 'g', depth, (input[1] == 'j' || input[2] == 'j')); + rz_core_anal_paths (core, addr, core->offset, input[1] == 'g', depth, (input[1] == 'j' || input[2] == 'j')); } } break; case 'F': // "/F" search file /F [file] ([offset] ([sz])) if (input[param_offset - 1] == ' ') { int n_args; - char **args = r_str_argv (input + param_offset, &n_args); + char **args = rz_str_argv (input + param_offset, &n_args); ut8 *buf = NULL; ut64 offset = 0; size_t size; - buf = (ut8 *)r_file_slurp (args[0], &size); + buf = (ut8 *)rz_file_slurp (args[0], &size); if (!buf) { eprintf ("Cannot open '%s'\n", args[0]); - r_str_argv_free (args); + rz_str_argv_free (args); break; } if (n_args > 1) { - offset = r_num_math (core->num, args[1]); + offset = rz_num_math (core->num, args[1]); if (size <= offset) { eprintf ("size <= offset\n"); - r_str_argv_free (args); + rz_str_argv_free (args); free (buf); break; } } if (n_args > 2) { - len = r_num_math (core->num, args[2]); + len = rz_num_math (core->num, args[2]); if (len > size - offset) { eprintf ("len too large\n"); - r_str_argv_free (args); + rz_str_argv_free (args); free (buf); break; } } else { len = size - offset; } - RSearchKeyword *kw; - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int)r_config_get_i (core->config, "search.distance")); - kw = r_search_keyword_new (buf + offset, len, NULL, 0, NULL); + RzSearchKeyword *kw; + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int)rz_config_get_i (core->config, "search.distance")); + kw = rz_search_keyword_new (buf + offset, len, NULL, 0, NULL); if (kw) { - r_search_kw_add (core->search, kw); + rz_search_kw_add (core->search, kw); // eprintf ("Searching %d byte(s)...\n", kw->keyword_length); - r_search_begin (core->search); + rz_search_begin (core->search); dosearch = true; } else { eprintf ("no keyword\n"); } - r_str_argv_free (args); + rz_str_argv_free (args); free (buf); } else { eprintf ("Usage: /F[j] [file] ([offset] ([sz]))\n"); @@ -3823,23 +3823,23 @@ reread: break; case 'x': // "/x" search hex if (input[1] == '?') { - r_core_cmd_help (core, help_msg_slash_x); + rz_core_cmd_help (core, help_msg_slash_x); } else { - RSearchKeyword *kw; + RzSearchKeyword *kw; char *s, *p = strdup (input + param_offset); - r_search_reset (core->search, R_SEARCH_KEYWORD); - r_search_set_distance (core->search, (int)r_config_get_i (core->config, "search.distance")); + rz_search_reset (core->search, R_SEARCH_KEYWORD); + rz_search_set_distance (core->search, (int)rz_config_get_i (core->config, "search.distance")); s = strchr (p, ':'); if (s) { *s++ = 0; - kw = r_search_keyword_new_hex (p, s, NULL); + kw = rz_search_keyword_new_hex (p, s, NULL); } else { - kw = r_search_keyword_new_hexmask (p, NULL); + kw = rz_search_keyword_new_hexmask (p, NULL); } if (kw) { - r_search_kw_add (core->search, kw); + rz_search_kw_add (core->search, kw); // eprintf ("Searching %d byte(s)...\n", kw->keyword_length); - r_search_begin (core->search); + rz_search_begin (core->search); dosearch = true; } else { eprintf ("no keyword\n"); @@ -3856,20 +3856,20 @@ reread: char *buf = malloc (strlen (input) * 2); char *str = strdup (input + 2); int ochunksize; - int i, len, chunksize = r_config_get_i (core->config, "search.chunk"); + int i, len, chunksize = rz_config_get_i (core->config, "search.chunk"); if (chunksize < 1) { chunksize = core->rasm->bits / 8; } - len = r_str_unescape (str); + len = rz_str_unescape (str); ochunksize = chunksize = R_MIN (len, chunksize); eprintf ("Using chunksize: %d\n", chunksize); core->in_search = false; for (i = 0; i < len; i += chunksize) { chunksize = ochunksize; again: - r_hex_bin2str ((ut8 *) str + i, R_MIN (chunksize, len - i), buf); + rz_hex_bin2str ((ut8 *) str + i, R_MIN (chunksize, len - i), buf); eprintf ("/x %s\n", buf); - r_core_cmdf (core, "/x %s", buf); + rz_core_cmdf (core, "/x %s", buf); if (core->num->value == 0) { chunksize--; if (chunksize < 1) { @@ -3898,47 +3898,47 @@ again: } if ((p = strchr (input + 2, ' '))) { *p = 0; - max = r_num_math (core->num, p + 1); + max = rz_num_math (core->num, p + 1); } else { eprintf ("Usage: /z min max\n"); break; } - min = r_num_math (core->num, input + 2); - if (!r_search_set_string_limits (core->search, min, max)) { + min = rz_num_math (core->num, input + 2); + if (!rz_search_set_string_limits (core->search, min, max)) { eprintf ("Error: min must be lower than max\n"); break; } - r_search_reset (core->search, R_SEARCH_STRING); - r_search_set_distance (core->search, (int) - r_config_get_i (core->config, "search.distance")); + rz_search_reset (core->search, R_SEARCH_STRING); + rz_search_set_distance (core->search, (int) + rz_config_get_i (core->config, "search.distance")); { - RSearchKeyword *kw = r_search_keyword_new_hexmask ("00", NULL); + RzSearchKeyword *kw = rz_search_keyword_new_hexmask ("00", NULL); kw->type = R_SEARCH_KEYWORD_TYPE_STRING; - r_search_kw_add (search, kw); + rz_search_kw_add (search, kw); } - r_search_begin (search); + rz_search_begin (search); dosearch = true; } break; case '?': // "/?" - r_core_cmd_help (core, help_msg_slash); + rz_core_cmd_help (core, help_msg_slash); break; default: eprintf ("See /? for help.\n"); break; } - r_config_set_i (core->config, "search.kwidx", search->n_kws); + rz_config_set_i (core->config, "search.kwidx", search->n_kws); if (dosearch) { do_string_search (core, search_itv, ¶m); } beach: core->num->value = search->nhits; core->in_search = false; - r_flag_space_pop (core->flags); + rz_flag_space_pop (core->flags); if (param.outmode == R_MODE_JSON) { - r_cons_newline (); + rz_cons_newline (); } - r_list_free (param.boundaries); - r_search_kw_reset (search); + rz_list_free (param.boundaries); + rz_search_kw_reset (search); return ret; } diff --git a/libr/core/cmd_search_rop.c b/librz/core/cmd_search_rop.c similarity index 60% rename from libr/core/cmd_search_rop.c rename to librz/core/cmd_search_rop.c index e4587c1a9b..dfdcbadf39 100644 --- a/libr/core/cmd_search_rop.c +++ b/librz/core/cmd_search_rop.c @@ -2,13 +2,13 @@ #include -#include "r_core.h" -#include "r_io.h" -#include "r_list.h" -#include "r_types_base.h" +#include "rz_core.h" +#include "rz_io.h" +#include "rz_list.h" +#include "rz_types_base.h" -static RList* parse_list (const char *str) { - RList *list; +static RzList* parse_list (const char *str) { + RzList *list; char *line, *data, *p, *str_n; if (!str) { @@ -16,18 +16,18 @@ static RList* parse_list (const char *str) { } str_n = strdup (str); - list = r_list_newf (free); + list = rz_list_newf (free); if (!list) { free (str_n); return NULL; } line = strtok (str_n, "\n"); data = strchr (line, '='); - // TODO: use r_str_split() + // TODO: use rz_str_split() p = strtok (data + 1, ","); while (p) { - r_list_append (list, (void*)strdup (p)); + rz_list_append (list, (void*)strdup (p)); p = strtok (NULL, ","); } @@ -35,19 +35,19 @@ static RList* parse_list (const char *str) { return list; } -static RList* get_constants(const char *str) { - RList *list; +static RzList* get_constants(const char *str) { + RzList *list; char *p, *data; if (!str) { return NULL; } data = strdup (str); - list = r_list_newf (free); + list = rz_list_newf (free); p = strtok (data, ","); while (p) { if (strtol (p, NULL, 0)) { - r_list_append (list, (void*)strdup (p)); + rz_list_append (list, (void*)strdup (p)); } p = strtok (NULL, ","); } @@ -55,8 +55,8 @@ static RList* get_constants(const char *str) { return list; } -static bool isFlag (RRegItem *reg) { - const char *type = r_reg_get_type (reg->type); +static bool isFlag (RzRegItem *reg) { + const char *type = rz_reg_get_type (reg->type); if (!strcmp (type, "flg")) return true; @@ -164,20 +164,20 @@ static bool simulate_op (const char *op, ut64 src1, ut64 src2, ut64 old_src1, ut } // fill REGs with known values -static void fillRegisterValues (RCore *core) { - RListIter *iter_reg; - RList *regs; - RRegItem *reg_item; +static void fillRegisterValues (RzCore *core) { + RzListIter *iter_reg; + RzList *regs; + RzRegItem *reg_item; int nr = 10; - regs = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + regs = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!regs) { return; } - r_list_foreach (regs, iter_reg, reg_item) { - r_reg_arena_pop (core->dbg->reg); - r_reg_set_value (core->dbg->reg, reg_item, nr); - r_reg_arena_push (core->dbg->reg); + rz_list_foreach (regs, iter_reg, reg_item) { + rz_reg_arena_pop (core->dbg->reg); + rz_reg_set_value (core->dbg->reg, reg_item, nr); + rz_reg_arena_push (core->dbg->reg); nr += 3; } } @@ -198,7 +198,7 @@ static void esil_split_flg (char *esil_str, char **esil_main, char **esil_flg) { } } *esil_flg = strdup (++split); - *esil_main = r_str_ndup (esil_str, strlen (esil_str) - strlen (*esil_flg) - 1); + *esil_main = rz_str_ndup (esil_str, strlen (esil_str) - strlen (*esil_flg) - 1); } } @@ -206,48 +206,48 @@ static void esil_split_flg (char *esil_str, char **esil_main, char **esil_flg) { R_FREE (out); \ R_FREE (esil_flg); \ R_FREE (esil_main); \ - r_list_free (ops_list); \ + rz_list_free (ops_list); \ ops_list = NULL; \ - r_list_free (flg_read); \ + rz_list_free (flg_read); \ flg_read = NULL; \ - r_list_free (flg_write); \ + rz_list_free (flg_write); \ flg_write = NULL; \ - r_list_free (reg_read); \ + rz_list_free (reg_read); \ reg_read = NULL; \ - r_list_free (reg_write); \ + rz_list_free (reg_write); \ reg_write = NULL; \ - r_list_free (mem_read); \ + rz_list_free (mem_read); \ mem_read = NULL; \ - r_list_free (mem_write); \ + rz_list_free (mem_write); \ mem_write = NULL; \ } -static char* rop_classify_constant(RCore *core, RList *ropList) { +static char* rop_classify_constant(RzCore *core, RzList *ropList) { char *esil_str, *constant; char *ct = NULL, *esil_main = NULL, *esil_flg = NULL, *out = NULL; - RListIter *iter_r, *iter_dst, *iter_const; - RRegItem *item_dst; - RList *head, *constants; - RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, + RzListIter *iter_r, *iter_dst, *iter_const; + RzRegItem *item_dst; + RzList *head, *constants; + RzList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL, *reg_write = NULL, *mem_read = NULL, *mem_write = NULL; - const bool romem = r_config_get_i (core->config, "esil.romem"); - const bool stats = r_config_get_i (core->config, "esil.stats"); + const bool romem = rz_config_get_i (core->config, "esil.romem"); + const bool stats = rz_config_get_i (core->config, "esil.stats"); if (!romem || !stats) { // eprintf ("Error: esil.romem and esil.stats must be set TRUE"); return NULL; } - r_list_foreach (ropList, iter_r, esil_str) { + rz_list_foreach (ropList, iter_r, esil_str) { constants = get_constants (esil_str); // if there are no constants in the instruction continue - if (r_list_empty (constants)) { + if (rz_list_empty (constants)) { continue; } // init regs with known values fillRegisterValues (core); - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { ct = NULL; goto continue_error; @@ -265,31 +265,31 @@ static char* rop_classify_constant(RCore *core, RList *ropList) { reg_write = parse_list (strstr (out, "reg.write")); mem_read = parse_list (strstr (out, "mem.read")); mem_write = parse_list (strstr (out, "mem.write")); - if (!r_list_find (ops_list, "=", (RListComparator)strcmp)) { + if (!rz_list_find (ops_list, "=", (RzListComparator)strcmp)) { goto continue_error; } - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { goto out_error; } - r_list_foreach (head, iter_dst, item_dst) { + rz_list_foreach (head, iter_dst, item_dst) { ut64 diff_dst, value_dst; - if (!r_list_find (reg_write, item_dst->name, - (RListComparator)strcmp)) { + if (!rz_list_find (reg_write, item_dst->name, + (RzListComparator)strcmp)) { continue; } - value_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - diff_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); + value_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + diff_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); //restore initial value - r_reg_set_value (core->dbg->reg, item_dst, diff_dst); + rz_reg_set_value (core->dbg->reg, item_dst, diff_dst); if (value_dst != diff_dst) { - r_list_foreach (constants, iter_const, constant) { - if (value_dst == r_num_get (NULL, constant)) { - ct = r_str_appendf (ct, "%s <-- 0x%"PFMT64x";", item_dst->name, value_dst); + rz_list_foreach (constants, iter_const, constant) { + if (value_dst == rz_num_get (NULL, constant)) { + ct = rz_str_appendf (ct, "%s <-- 0x%"PFMT64x";", item_dst->name, value_dst); } } } @@ -298,36 +298,36 @@ continue_error: // coverity may complain here but as long as the pointer is set back to // NULL is safe that is why is used R_FREE FREE_ROP; - r_list_free (constants); + rz_list_free (constants); } return ct; out_error: FREE_ROP; - r_list_free (constants); + rz_list_free (constants); return NULL; } -static char* rop_classify_mov(RCore *core, RList *ropList) { +static char* rop_classify_mov(RzCore *core, RzList *ropList) { char *esil_str; char *mov = NULL, *esil_main = NULL, *esil_flg = NULL, *out = NULL; - RListIter *iter_src, *iter_r, *iter_dst; - RRegItem *item_src, *item_dst; - RList *head; - RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, + RzListIter *iter_src, *iter_r, *iter_dst; + RzRegItem *item_src, *item_dst; + RzList *head; + RzList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL, *reg_write = NULL, *mem_read = NULL, *mem_write = NULL; - const bool romem = r_config_get_i (core->config, "esil.romem"); - const bool stats = r_config_get_i (core->config, "esil.stats"); + const bool romem = rz_config_get_i (core->config, "esil.romem"); + const bool stats = rz_config_get_i (core->config, "esil.stats"); if (!romem || !stats) { // eprintf ("Error: esil.romem and esil.stats must be set TRUE"); return NULL; } - r_list_foreach (ropList, iter_r, esil_str) { + rz_list_foreach (ropList, iter_r, esil_str) { // init regs with known values fillRegisterValues (core); - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { goto out_error; } @@ -346,18 +346,18 @@ static char* rop_classify_mov(RCore *core, RList *ropList) { goto continue_error; } - if (!r_list_find (ops_list, "=", (RListComparator)strcmp)) { + if (!rz_list_find (ops_list, "=", (RzListComparator)strcmp)) { goto continue_error; } - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { goto out_error; } - r_list_foreach (head, iter_dst, item_dst) { + rz_list_foreach (head, iter_dst, item_dst) { ut64 diff_dst, value_dst; - if (!r_list_find (reg_write, item_dst->name, - (RListComparator)strcmp)) { + if (!rz_list_find (reg_write, item_dst->name, + (RzListComparator)strcmp)) { continue; } @@ -366,28 +366,28 @@ static char* rop_classify_mov(RCore *core, RList *ropList) { continue; } - value_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - diff_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - r_list_foreach (head, iter_src, item_src) { + value_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + diff_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + rz_list_foreach (head, iter_src, item_src) { ut64 diff_src, value_src; - if (!r_list_find (reg_read, item_src->name, - (RListComparator)strcmp)) { + if (!rz_list_find (reg_read, item_src->name, + (RzListComparator)strcmp)) { continue; } // you never mov from flags if (item_src == item_dst || isFlag (item_src)) { continue; } - value_src = r_reg_get_value (core->dbg->reg, item_src); - r_reg_arena_swap (core->dbg->reg, false); - diff_src = r_reg_get_value (core->dbg->reg, item_src); - r_reg_arena_swap (core->dbg->reg, false); + value_src = rz_reg_get_value (core->dbg->reg, item_src); + rz_reg_arena_swap (core->dbg->reg, false); + diff_src = rz_reg_get_value (core->dbg->reg, item_src); + rz_reg_arena_swap (core->dbg->reg, false); //restore initial value - r_reg_set_value (core->dbg->reg, item_src, diff_src); + rz_reg_set_value (core->dbg->reg, item_src, diff_src); if (value_dst == value_src && value_dst != diff_dst) { - mov = r_str_appendf (mov, "%s <-- %s;", + mov = rz_str_appendf (mov, "%s <-- %s;", item_dst->name, item_src->name); } } @@ -401,18 +401,18 @@ out_error: return NULL; } -static char* rop_classify_arithmetic(RCore *core, RList *ropList) { +static char* rop_classify_arithmetic(RzCore *core, RzList *ropList) { char *esil_str, *op; char *arithmetic = NULL, *esil_flg = NULL, *esil_main = NULL, *out = NULL; - RListIter *iter_src1, *iter_src2, *iter_r, *iter_dst, *iter_ops; - RRegItem *item_src1, *item_src2, *item_dst; - RList *head; - RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, + RzListIter *iter_src1, *iter_src2, *iter_r, *iter_dst, *iter_ops; + RzRegItem *item_src1, *item_src2, *item_dst; + RzList *head; + RzList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL, *reg_write = NULL, *mem_read = NULL, *mem_write = NULL; - const bool romem = r_config_get_i (core->config, "esil.romem"); - const bool stats = r_config_get_i (core->config, "esil.stats"); + const bool romem = rz_config_get_i (core->config, "esil.romem"); + const bool stats = rz_config_get_i (core->config, "esil.stats"); ut64 *op_result = R_NEW0 (ut64); ut64 *op_result_r = R_NEW0 (ut64); @@ -423,10 +423,10 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) { return NULL; } - r_list_foreach (ropList, iter_r, esil_str) { + rz_list_foreach (ropList, iter_r, esil_str) { // init regs with known values fillRegisterValues (core); - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { goto out_error; } @@ -437,7 +437,7 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) { cmd_anal_esil (core, esil_str); } out = sdb_querys (core->anal->esil->stats, NULL, 0, "*"); - // r_cons_println (out); + // rz_cons_println (out); if (!out) { goto continue_error; } @@ -449,27 +449,27 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) { mem_read = parse_list (strstr (out, "mem.read")); mem_write = parse_list (strstr (out, "mem.write")); - r_list_foreach (ops_list, iter_ops, op) { - r_list_foreach (head, iter_src1, item_src1) { + rz_list_foreach (ops_list, iter_ops, op) { + rz_list_foreach (head, iter_src1, item_src1) { ut64 value_src1, diff_src1; - value_src1 = r_reg_get_value (core->dbg->reg, item_src1); - r_reg_arena_swap (core->dbg->reg, false); - diff_src1 = r_reg_get_value (core->dbg->reg, item_src1); - r_reg_arena_swap (core->dbg->reg, false); - if (!r_list_find (reg_read, item_src1->name, - (RListComparator)strcmp)) { + value_src1 = rz_reg_get_value (core->dbg->reg, item_src1); + rz_reg_arena_swap (core->dbg->reg, false); + diff_src1 = rz_reg_get_value (core->dbg->reg, item_src1); + rz_reg_arena_swap (core->dbg->reg, false); + if (!rz_list_find (reg_read, item_src1->name, + (RzListComparator)strcmp)) { continue; } - r_list_foreach (head, iter_src2, item_src2) { + rz_list_foreach (head, iter_src2, item_src2) { ut64 value_src2, diff_src2; - value_src2 = r_reg_get_value (core->dbg->reg, item_src2); - r_reg_arena_swap (core->dbg->reg, false); - diff_src2 = r_reg_get_value (core->dbg->reg, item_src2); + value_src2 = rz_reg_get_value (core->dbg->reg, item_src2); + rz_reg_arena_swap (core->dbg->reg, false); + diff_src2 = rz_reg_get_value (core->dbg->reg, item_src2); - if (!r_list_find (reg_read, item_src2->name, - (RListComparator)strcmp)) { + if (!rz_list_find (reg_read, item_src2->name, + (RzListComparator)strcmp)) { continue; } // TODO check condition @@ -477,14 +477,14 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) { continue; } - r_list_foreach (head, iter_dst, item_dst) { + rz_list_foreach (head, iter_dst, item_dst) { ut64 value_dst; bool redundant = false, simulate, simulate_r; - value_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - if (!r_list_find (reg_write, item_dst->name, - (RListComparator)strcmp)) { + value_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + if (!rz_list_find (reg_write, item_dst->name, + (RzListComparator)strcmp)) { continue; } // don't check flags for arithmetic @@ -494,22 +494,22 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) { simulate = simulate_op (op, value_src1, value_src2, diff_src1, diff_src2, op_result, item_dst->size); simulate_r = simulate_op (op, value_src2, value_src1, diff_src2, diff_src1, op_result_r, item_dst->size); if (/*value_src1 != 0 && value_src2 != 0 && */simulate && value_dst == *op_result) { - // r_cons_println ("Debug: FOUND ONE !"); - char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, item_src2->name); + // rz_cons_println ("Debug: FOUND ONE !"); + char *tmp = rz_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, item_src2->name); if (arithmetic && !strstr (arithmetic, tmp)) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } else if (!arithmetic) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } free (tmp); redundant = true; } else if (!redundant /*&& value_src1 != 0 && value_src2 != 0*/ && simulate_r && value_dst == *op_result_r) { - // r_cons_println ("Debug: FOUND ONE reversed!"); - char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src2->name, op, item_src1->name); + // rz_cons_println ("Debug: FOUND ONE reversed!"); + char *tmp = rz_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src2->name, op, item_src1->name); if (arithmetic && !strstr (arithmetic, tmp)) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } else if (!arithmetic) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } free (tmp); } @@ -530,16 +530,16 @@ out_error: return NULL; } -static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { +static char* rop_classify_arithmetic_const(RzCore *core, RzList *ropList) { char *esil_str, *op, *constant; char *arithmetic = NULL, *esil_flg = NULL, *esil_main = NULL; - RListIter *iter_src1, *iter_r, *iter_dst, *iter_ops, *iter_const; - RRegItem *item_src1, *item_dst; - RList *head, *constants; - RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL, + RzListIter *iter_src1, *iter_r, *iter_dst, *iter_ops, *iter_const; + RzRegItem *item_src1, *item_dst; + RzList *head, *constants; + RzList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL, *reg_write = NULL, *mem_read = NULL, *mem_write = NULL; - const bool romem = r_config_get_i (core->config, "esil.romem"); - const bool stats = r_config_get_i (core->config, "esil.stats"); + const bool romem = rz_config_get_i (core->config, "esil.romem"); + const bool stats = rz_config_get_i (core->config, "esil.stats"); ut64 *op_result = R_NEW0 (ut64); ut64 *op_result_r = R_NEW0 (ut64); @@ -550,15 +550,15 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { return NULL; } - r_list_foreach (ropList, iter_r, esil_str) { + rz_list_foreach (ropList, iter_r, esil_str) { constants = get_constants (esil_str); // if there are no constants in the instruction continue - if (r_list_empty (constants)) { + if (rz_list_empty (constants)) { continue; } // init regs with known values fillRegisterValues (core); - head = r_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); + head = rz_reg_get_list (core->dbg->reg, R_REG_TYPE_GPR); if (!head) { arithmetic = NULL; continue; @@ -570,7 +570,7 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { cmd_anal_esil (core, esil_str); } char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*"); - // r_cons_println (out); + // rz_cons_println (out); if (out) { ops_list = parse_list (strstr (out, "ops.list")); flg_read = parse_list (strstr (out, "flg.read")); @@ -585,27 +585,27 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { goto continue_error; } - r_list_foreach (ops_list, iter_ops, op) { - r_list_foreach (head, iter_src1, item_src1) { + rz_list_foreach (ops_list, iter_ops, op) { + rz_list_foreach (head, iter_src1, item_src1) { ut64 value_src1, diff_src1; - value_src1 = r_reg_get_value (core->dbg->reg, item_src1); - r_reg_arena_swap (core->dbg->reg, false); - diff_src1 = r_reg_get_value (core->dbg->reg, item_src1); - r_reg_arena_swap (core->dbg->reg, false); + value_src1 = rz_reg_get_value (core->dbg->reg, item_src1); + rz_reg_arena_swap (core->dbg->reg, false); + diff_src1 = rz_reg_get_value (core->dbg->reg, item_src1); + rz_reg_arena_swap (core->dbg->reg, false); - if (!r_list_find (reg_read, item_src1->name, - (RListComparator)strcmp)) { + if (!rz_list_find (reg_read, item_src1->name, + (RzListComparator)strcmp)) { continue; } - r_list_foreach (head, iter_dst, item_dst) { + rz_list_foreach (head, iter_dst, item_dst) { ut64 value_dst, diff_dst; bool redundant = false, simulate, simulate_r; - value_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - diff_dst = r_reg_get_value (core->dbg->reg, item_dst); - r_reg_arena_swap (core->dbg->reg, false); - if (!r_list_find (reg_write, item_dst->name, - (RListComparator)strcmp)) { + value_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + diff_dst = rz_reg_get_value (core->dbg->reg, item_dst); + rz_reg_arena_swap (core->dbg->reg, false); + if (!rz_list_find (reg_write, item_dst->name, + (RzListComparator)strcmp)) { continue; } // don't check flags for arithmetic @@ -613,8 +613,8 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { continue; } if (value_dst != diff_dst) { - r_list_foreach (constants, iter_const, constant) { - ut64 value_ct = r_num_get (NULL, constant); + rz_list_foreach (constants, iter_const, constant) { + ut64 value_ct = rz_num_get (NULL, constant); simulate = simulate_op (op, value_src1, value_ct, diff_src1, value_ct, op_result, item_dst->size); @@ -622,20 +622,20 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { value_ct, diff_src1, op_result_r, item_dst->size); if (simulate && op_result && value_dst == *op_result) { - char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, constant); + char *tmp = rz_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, constant); if (arithmetic && !strstr (arithmetic, tmp)) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } else if (!arithmetic) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } free (tmp); redundant = true; } else if (!redundant && simulate_r && value_dst == *op_result_r) { - char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, constant, op, item_src1->name); + char *tmp = rz_str_newf ("%s <-- %s %s %s;", item_dst->name, constant, op, item_src1->name); if (arithmetic && !strstr (arithmetic, tmp)) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } else if (!arithmetic) { - arithmetic = r_str_append (arithmetic, tmp); + arithmetic = rz_str_append (arithmetic, tmp); } free (tmp); } @@ -646,32 +646,32 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) { } continue_error: FREE_ROP; - r_list_free (constants); + rz_list_free (constants); } free (op_result); free (op_result_r); return arithmetic; } -static int rop_classify_nops(RCore *core, RList *ropList) { +static int rop_classify_nops(RzCore *core, RzList *ropList) { char *esil_str; int changes = 1; - RListIter *iter_r; - const bool romem = r_config_get_i (core->config, "esil.romem"); - const bool stats = r_config_get_i (core->config, "esil.stats"); + RzListIter *iter_r; + const bool romem = rz_config_get_i (core->config, "esil.romem"); + const bool stats = rz_config_get_i (core->config, "esil.stats"); if (!romem || !stats) { // eprintf ("Error: esil.romem and esil.stats must be set TRUE\n"); return -2; } - r_list_foreach (ropList, iter_r, esil_str) { + rz_list_foreach (ropList, iter_r, esil_str) { fillRegisterValues (core); - // r_cons_printf ("Emulating nop:%s\n", esil_str); + // rz_cons_printf ("Emulating nop:%s\n", esil_str); cmd_anal_esil (core, esil_str); char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*"); - // r_cons_println (out); + // rz_cons_println (out); if (out) { free (out); return 0; @@ -683,7 +683,7 @@ static int rop_classify_nops(RCore *core, RList *ropList) { return changes; } -static void rop_classify (RCore *core, Sdb *db, RList *ropList, const char *key, unsigned int size) { +static void rop_classify (RzCore *core, Sdb *db, RzList *ropList, const char *key, unsigned int size) { int nop = 0; rop_classify_nops (core, ropList); char *mov, *ct, *arithm, *arithm_ct, *str; Sdb *db_nop = sdb_ns (db, "nop", true); @@ -701,33 +701,33 @@ static void rop_classify (RCore *core, Sdb *db, RList *ropList, const char *key, ct = rop_classify_constant (core, ropList); arithm = rop_classify_arithmetic (core, ropList); arithm_ct = rop_classify_arithmetic_const (core, ropList); - str = r_str_newf ("0x%"PFMT64x, size); + str = rz_str_newf ("0x%"PFMT64x, size); if (nop == 1) { - char *str_nop = r_str_newf ("%s NOP", str); + char *str_nop = rz_str_newf ("%s NOP", str); sdb_set (db_nop, key, str_nop, 0); free (str_nop); } else { if (mov) { - char *str_mov = r_str_newf ("%s MOV { %s }", str, mov); + char *str_mov = rz_str_newf ("%s MOV { %s }", str, mov); sdb_set (db_mov, key, str_mov, 0); free (str_mov); free (mov); } if (ct) { - char *str_ct = r_str_newf ("%s LOAD_CONST { %s }", str, ct); + char *str_ct = rz_str_newf ("%s LOAD_CONST { %s }", str, ct); sdb_set (db_ct, key, str_ct, 0); free (str_ct); free (ct); } if (arithm) { - char *str_arithm = r_str_newf ("%s ARITHMETIC { %s }", str, arithm); + char *str_arithm = rz_str_newf ("%s ARITHMETIC { %s }", str, arithm); sdb_set (db_aritm, key, str_arithm, 0); free (str_arithm); free (arithm); } if (arithm_ct) { - char *str_arithm_ct = r_str_newf ("%s ARITHMETIC_CONST { %s }", str, arithm_ct); + char *str_arithm_ct = rz_str_newf ("%s ARITHMETIC_CONST { %s }", str, arithm_ct); sdb_set (db_aritm_ct, key, str_arithm_ct, 0); free (str_arithm_ct); free (arithm_ct); diff --git a/libr/core/cmd_seek.c b/librz/core/cmd_seek.c similarity index 60% rename from libr/core/cmd_seek.c rename to librz/core/cmd_seek.c index 48d80ae549..cb98754ada 100644 --- a/libr/core/cmd_seek.c +++ b/librz/core/cmd_seek.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include "r_types.h" -#include "r_config.h" -#include "r_cons.h" -#include "r_core.h" -#include "r_debug.h" -#include "r_io.h" +#include "rz_types.h" +#include "rz_config.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_debug.h" +#include "rz_io.h" static const char *help_msg_s[] = { "Usage: s", "", " # Help for the seek commands. See ?$? to see all variables", @@ -62,68 +62,68 @@ static const char *help_msg_ss[] = { NULL }; -static void cmd_seek_init(RCore *core, RCmdDesc *parent) { +static void cmd_seek_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, s); DEFINE_CMD_DESCRIPTOR (core, sC); DEFINE_CMD_DESCRIPTOR (core, sl); DEFINE_CMD_DESCRIPTOR (core, ss); } -static void __init_seek_line(RCore *core) { +static void __init_seek_line(RzCore *core) { ut64 from, to; - r_config_bump (core->config, "lines.to"); - from = r_config_get_i (core->config, "lines.from"); - const char *to_str = r_config_get (core->config, "lines.to"); - to = r_num_math (core->num, (to_str && *to_str) ? to_str : "$s"); - if (r_core_lines_initcache (core, from, to) == -1) { + rz_config_bump (core->config, "lines.to"); + from = rz_config_get_i (core->config, "lines.from"); + const char *to_str = rz_config_get (core->config, "lines.to"); + to = rz_num_math (core->num, (to_str && *to_str) ? to_str : "$s"); + if (rz_core_lines_initcache (core, from, to) == -1) { eprintf ("ERROR: \"lines.from\" and \"lines.to\" must be set\n"); } } -static void printPadded(RCore *core, int pad) { +static void printPadded(RzCore *core, int pad) { if (pad < 1) { pad = 8; } - char *fmt = r_str_newf ("0x%%0%d" PFMT64x, pad); - char *off = r_str_newf (fmt, core->offset); - r_cons_printf ("%s\n", off); + char *fmt = rz_str_newf ("0x%%0%d" PFMT64x, pad); + char *off = rz_str_newf (fmt, core->offset); + rz_cons_printf ("%s\n", off); free (off); free (fmt); } -static void __get_current_line(RCore *core) { +static void __get_current_line(RzCore *core) { if (core->print->lines_cache_sz > 0) { - int curr = r_util_lines_getline (core->print->lines_cache, core->print->lines_cache_sz, core->offset); - r_cons_printf ("%d\n", curr); + int curr = rz_util_lines_getline (core->print->lines_cache, core->print->lines_cache_sz, core->offset); + rz_cons_printf ("%d\n", curr); } } -static void __seek_line_absolute(RCore *core, int numline) { +static void __seek_line_absolute(RzCore *core, int numline) { if (numline < 1 || numline > core->print->lines_cache_sz - 1) { eprintf ("ERROR: Line must be between 1 and %d\n", core->print->lines_cache_sz - 1); } else { - r_core_seek (core, core->print->lines_cache[numline - 1], true); + rz_core_seek (core, core->print->lines_cache[numline - 1], true); } } -static void __seek_line_relative(RCore *core, int numlines) { - int curr = r_util_lines_getline (core->print->lines_cache, core->print->lines_cache_sz, core->offset); +static void __seek_line_relative(RzCore *core, int numlines) { + int curr = rz_util_lines_getline (core->print->lines_cache, core->print->lines_cache_sz, core->offset); if (numlines > 0 && curr + numlines >= core->print->lines_cache_sz - 1) { eprintf ("ERROR: Line must be < %d\n", core->print->lines_cache_sz - 1); } else if (numlines < 0 && curr + numlines < 1) { eprintf ("ERROR: Line must be > 1\n"); } else { - r_core_seek (core, core->print->lines_cache[curr + numlines - 1], true); + rz_core_seek (core, core->print->lines_cache[curr + numlines - 1], true); } } -static void __clean_lines_cache(RCore *core) { +static void __clean_lines_cache(RzCore *core) { core->print->lines_cache_sz = -1; R_FREE (core->print->lines_cache); } -R_API int r_core_lines_currline(RCore *core) { // make priv8 again +RZ_API int rz_core_lines_currline(RzCore *core) { // make priv8 again int imin = 0; int imax = core->print->lines_cache_sz; int imid = 0; @@ -141,7 +141,7 @@ R_API int r_core_lines_currline(RCore *core) { // make priv8 again return imin; } -R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) { +RZ_API int rz_core_lines_initcache(RzCore *core, ut64 start_addr, ut64 end_addr) { int i, bsz = core->blocksize; ut64 off = start_addr; ut64 baddr; @@ -155,7 +155,7 @@ R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) { return -1; } - baddr = r_config_get_i (core->config, "bin.baddr"); + baddr = rz_config_get_i (core->config, "bin.baddr"); int line_count = start_addr? 0: 1; core->print->lines_cache[0] = start_addr? 0: baddr; @@ -163,12 +163,12 @@ R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) { if (!buf) { return -1; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); while (off < end_addr) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - r_io_read_at (core->io, off, (ut8 *) buf, bsz); + rz_io_read_at (core->io, off, (ut8 *) buf, bsz); for (i = 0; i < bsz; i++) { if (buf[i] != '\n') { continue; @@ -192,39 +192,39 @@ R_API int r_core_lines_initcache(RCore *core, ut64 start_addr, ut64 end_addr) { off += bsz; } free (buf); - r_cons_break_pop (); + rz_cons_break_pop (); return line_count; beach: free (buf); - r_cons_break_pop (); + rz_cons_break_pop (); return -1; } -static void seek_to_register(RCore *core, const char *input, bool is_silent) { +static void seek_to_register(RzCore *core, const char *input, bool is_silent) { ut64 off; if (core->bin->is_debugger) { - off = r_debug_reg_get (core->dbg, input); + off = rz_debug_reg_get (core->dbg, input); if (!is_silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek (core, off, true); + rz_core_seek (core, off, true); } else { - RReg *orig = core->dbg->reg; + RzReg *orig = core->dbg->reg; core->dbg->reg = core->anal->reg; - off = r_debug_reg_get (core->dbg, input); + off = rz_debug_reg_get (core->dbg, input); core->dbg->reg = orig; if (!is_silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek (core, off, true); + rz_core_seek (core, off, true); } } static int cmd_sort(void *data, const char *input) { // "sort" - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; const char *arg = strchr (input, ' '); if (arg) { - arg = r_str_trim_head_ro (arg + 1); + arg = rz_str_trim_head_ro (arg + 1); } switch (*input) { case '?': // "sort?" @@ -234,12 +234,12 @@ static int cmd_sort(void *data, const char *input) { // "sort" if (!arg) { arg = ""; } - if (r_fs_check (core->fs, arg)) { - r_core_cmdf (core, "md %s", arg); + if (rz_fs_check (core->fs, arg)) { + rz_core_cmdf (core, "md %s", arg); } else { - char *res = r_syscmd_sort (arg); + char *res = rz_syscmd_sort (arg); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -248,32 +248,32 @@ static int cmd_sort(void *data, const char *input) { // "sort" return 0; } -static int cmd_seek_opcode_backward(RCore *core, int numinstr) { +static int cmd_seek_opcode_backward(RzCore *core, int numinstr) { int i, val = 0; // N previous instructions ut64 addr = core->offset; int ret = 0; - if (r_core_prevop_addr (core, core->offset, numinstr, &addr)) { + if (rz_core_prevop_addr (core, core->offset, numinstr, &addr)) { ret = core->offset - addr; } else { #if 0 // core_asm_bwdis_len is buggy as hell we should kill it. seems like prevop_addr // works as expected, because is the one used from visual - ret = r_core_asm_bwdis_len (core, &instr_len, &addr, numinstr); + ret = rz_core_asm_bwdis_len (core, &instr_len, &addr, numinstr); #endif addr = core->offset; - const int mininstrsize = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + const int mininstrsize = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); for (i = 0; i < numinstr; i++) { - ut64 prev_addr = r_core_prevop_addr_force (core, addr, 1); + ut64 prev_addr = rz_core_prevop_addr_force (core, addr, 1); if (prev_addr == UT64_MAX) { prev_addr = addr - mininstrsize; } if (prev_addr == UT64_MAX || prev_addr >= core->offset) { break; } - RAsmOp op = {0}; - r_core_seek (core, prev_addr, true); - r_asm_disassemble (core->rasm, &op, core->block, 32); + RzAsmOp op = {0}; + rz_core_seek (core, prev_addr, true); + rz_asm_disassemble (core->rasm, &op, core->block, 32); if (op.size < mininstrsize) { op.size = mininstrsize; } @@ -281,29 +281,29 @@ static int cmd_seek_opcode_backward(RCore *core, int numinstr) { addr = prev_addr; } } - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); val += ret; return val; } -static int cmd_seek_opcode_forward (RCore *core, int n) { +static int cmd_seek_opcode_forward (RzCore *core, int n) { // N forward instructions int i, ret, val = 0; for (val = i = 0; i < n; i++) { - RAnalOp op; - ret = r_anal_op (core->anal, &op, core->offset, core->block, + RzAnalOp op; + ret = rz_anal_op (core->anal, &op, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC); if (ret < 1) { ret = 1; } - r_core_seek_delta (core, ret); - r_anal_op_fini (&op); + rz_core_seek_delta (core, ret); + rz_anal_op_fini (&op); val += ret; } return val; } -static void cmd_seek_opcode(RCore *core, const char *input) { +static void cmd_seek_opcode(RzCore *core, const char *input) { if (input[0] == '?') { eprintf ("Usage: so [-][n]\n"); return; @@ -311,7 +311,7 @@ static void cmd_seek_opcode(RCore *core, const char *input) { if (!strcmp (input, "-")) { input = "-1"; } - int n = r_num_math (core->num, input); + int n = rz_num_math (core->num, input); if (n == 0) { n = 1; } @@ -322,26 +322,26 @@ static void cmd_seek_opcode(RCore *core, const char *input) { } static int cmd_seek(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; char *cmd, *p; ut64 off = core->offset; if (!*input) { - r_cons_printf ("0x%"PFMT64x "\n", core->offset); + rz_cons_printf ("0x%"PFMT64x "\n", core->offset); return 0; } char *ptr; if ((ptr = strstr (input, "+.")) != NULL) { char *dup = strdup (input); dup[ptr - input] = '\x00'; - off = r_num_math (core->num, dup + 1); + off = rz_num_math (core->num, dup + 1); core->offset = off; free (dup); } const char *inputnum = strchr (input, ' '); - if (r_str_cmp (input, "ort", 3)) { // hack to handle Invalid Argument for sort + if (rz_str_cmp (input, "ort", 3)) { // hack to handle Invalid Argument for sort const char *u_num = inputnum? inputnum + 1: input + 1; - off = r_num_math (core->num, u_num); + off = rz_num_math (core->num, u_num); if (*u_num == '-') { off = -(st64)off; } @@ -364,7 +364,7 @@ static int cmd_seek(void *data, const char *input) { silent = true; input++; if (*input == '?') { - r_core_cmd_help (core, help_msg_ss); + rz_core_cmd_help (core, help_msg_ss); return 0; } } @@ -379,18 +379,18 @@ static int cmd_seek(void *data, const char *input) { break; case 'C': // "sC" if (input[1] == '*') { // "sC*" - r_core_cmd0 (core, "C*~^\"CC"); + rz_core_cmd0 (core, "C*~^\"CC"); } else if (input[1] == ' ') { RIntervalTreeIter it; - RAnalMetaItem *meta; + RzAnalMetaItem *meta; bool seeked = false; - r_interval_tree_foreach (&core->anal->meta, it, meta) { + rz_interval_tree_foreach (&core->anal->meta, it, meta) { if (meta->type == R_META_TYPE_COMMENT && !strcmp (meta->str, input + 2)) { if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek (core, off, true); - r_core_block_read (core); + rz_core_seek (core, off, true); + rz_core_block_read (core); seeked = true; break; } @@ -399,32 +399,32 @@ static int cmd_seek(void *data, const char *input) { eprintf ("No matching comment.\n"); } } else { - r_core_cmd_help (core, help_msg_sC); + rz_core_cmd_help (core, help_msg_sC); } break; case ' ': // "s " { - ut64 addr = r_num_math (core->num, input + 1); + ut64 addr = rz_num_math (core->num, input + 1); if (core->num->nc.errors) { - if (r_cons_singleton ()->context->is_interactive) { + if (rz_cons_singleton ()->context->is_interactive) { eprintf ("Cannot seek to unknown address '%s'\n", core->num->nc.calc_buf); } break; } if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek (core, addr, true); - r_core_block_read (core); + rz_core_seek (core, addr, true); + rz_core_block_read (core); } break; case '/': // "s/" { - const char *pfx = r_config_get (core->config, "search.prefix"); - const ut64 saved_from = r_config_get_i (core->config, "search.from"); - const ut64 saved_maxhits = r_config_get_i (core->config, "search.maxhits"); + const char *pfx = rz_config_get (core->config, "search.prefix"); + const ut64 saved_from = rz_config_get_i (core->config, "search.from"); + const ut64 saved_maxhits = rz_config_get_i (core->config, "search.maxhits"); // kwidx cfg var is ignored - int kwidx = core->search->n_kws; // (int)r_config_get_i (core->config, "search.kwidx")-1; + int kwidx = core->search->n_kws; // (int)rz_config_get_i (core->config, "search.kwidx")-1; if (kwidx < 0) { kwidx = 0; } @@ -445,16 +445,16 @@ static int cmd_seek(void *data, const char *input) { case 'r': case '/': case 'x': - r_config_set_i (core->config, "search.from", core->offset + 1); - r_config_set_i (core->config, "search.maxhits", 1); - r_core_cmdf (core, "s+1; %s; s-1; s %s%d_0; f-%s%d_0", + rz_config_set_i (core->config, "search.from", core->offset + 1); + rz_config_set_i (core->config, "search.maxhits", 1); + rz_core_cmdf (core, "s+1; %s; s-1; s %s%d_0; f-%s%d_0", input, pfx, kwidx, pfx, kwidx, pfx, kwidx); - r_config_set_i (core->config, "search.from", saved_from); - r_config_set_i (core->config, "search.maxhits", saved_maxhits); + rz_config_set_i (core->config, "search.from", saved_from); + rz_config_set_i (core->config, "search.maxhits", saved_maxhits); break; case '?': eprintf ("Usage: s/.. arg.\n"); - r_cons_printf ("/?\n"); + rz_cons_printf ("/?\n"); break; default: eprintf ("unknown search method\n"); @@ -466,26 +466,26 @@ static int cmd_seek(void *data, const char *input) { for (input++; *input == '.'; input++) { ; } - r_core_seek_base (core, input); - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_core_seek_base (core, input); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); break; case 'j': // "sj" { - RList /**/ *addrs = r_list_newf (free); - RList /**/ *names = r_list_newf (free); - RList *list = r_io_sundo_list (core->io, '!'); + RzList /**/ *addrs = rz_list_newf (free); + RzList /**/ *names = rz_list_newf (free); + RzList *list = rz_io_sundo_list (core->io, '!'); ut64 lsz = 0; ut64 i; - RListIter *iter; - RIOUndos *undo; + RzListIter *iter; + RzIOUndos *undo; if (list) { - r_list_foreach (list, iter, undo) { + rz_list_foreach (list, iter, undo) { char *name = NULL; - RFlagItem *f = r_flag_get_at (core->flags, undo->off, true); + RzFlagItem *f = rz_flag_get_at (core->flags, undo->off, true); if (f) { if (f->offset != undo->off) { - name = r_str_newf ("%s+%d", f->name, + name = rz_str_newf ("%s+%d", f->name, (int)(undo->off- f->offset)); } else { name = strdup (f->name); @@ -500,18 +500,18 @@ static int cmd_seek(void *data, const char *input) { break; } *val = undo->off; - r_list_append (addrs, val); - r_list_append (names, strdup (name)); + rz_list_append (addrs, val); + rz_list_append (names, strdup (name)); lsz++; free (name); } - r_list_free (list); + rz_list_free (list); } PJ *pj = pj_new (); pj_a (pj); for (i = 0; i < lsz; i++) { - ut64 *addr = r_list_get_n (addrs, i); - const char *name = r_list_get_n (names, i); + ut64 *addr = rz_list_get_n (addrs, i); + const char *name = rz_list_get_n (names, i); pj_o (pj); pj_kn (pj, "offset", *addr); if (name && *name) { @@ -524,10 +524,10 @@ static int cmd_seek(void *data, const char *input) { } pj_end (pj); char *s = pj_drain (pj); - r_cons_printf ("%s\n", s); + rz_cons_printf ("%s\n", s); free (s); - r_list_free (addrs); - r_list_free (names); + rz_list_free (addrs); + rz_list_free (names); } break; case '*': // "s*" @@ -538,35 +538,35 @@ static int cmd_seek(void *data, const char *input) { if (input[1] == '=') { mode = 0; } - RList *list = r_io_sundo_list (core->io, mode); + RzList *list = rz_io_sundo_list (core->io, mode); if (list) { - RListIter *iter; - RIOUndos *undo; - r_list_foreach (list, iter, undo) { + RzListIter *iter; + RzIOUndos *undo; + rz_list_foreach (list, iter, undo) { char *name = NULL; - RFlagItem *f = r_flag_get_at (core->flags, undo->off, true); + RzFlagItem *f = rz_flag_get_at (core->flags, undo->off, true); if (f) { if (f->offset != undo->off) { - name = r_str_newf ("%s + %d\n", f->name, + name = rz_str_newf ("%s + %d\n", f->name, (int)(undo->off - f->offset)); } else { name = strdup (f->name); } } if (mode) { - r_cons_printf ("0x%"PFMT64x" %s\n", undo->off, name? name: ""); + rz_cons_printf ("0x%"PFMT64x" %s\n", undo->off, name? name: ""); } else { if (!name) { - name = r_str_newf ("0x%"PFMT64x, undo->off); + name = rz_str_newf ("0x%"PFMT64x, undo->off); } - r_cons_printf ("%s%s", name, iter->n? " > ":""); + rz_cons_printf ("%s%s", name, iter->n? " > ":""); } free (name); } - r_list_free (list); + rz_list_free (list); if (!mode) { - r_cons_newline (); + rz_cons_newline (); } } } @@ -576,37 +576,37 @@ static int cmd_seek(void *data, const char *input) { int delta = off; if (input[1] == '+') { delta = core->blocksize; - int mult = r_num_math (core->num, input + 2); + int mult = rz_num_math (core->num, input + 2); if (mult > 0) { delta /= mult; } } // int delta = (input[1] == '+')? core->blocksize: off; if (!silent) { - r_io_sundo_push (core->io, core->offset, - r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, + rz_print_get_cursor (core->print)); } - r_core_seek_delta (core, delta); - r_core_block_read (core); + rz_core_seek_delta (core, delta); + rz_core_block_read (core); } else { - RIOUndos *undo = r_io_sundo_redo (core->io); + RzIOUndos *undo = rz_io_sundo_redo (core->io); if (undo) { - r_core_seek (core, undo->off, false); - r_core_block_read (core); + rz_core_seek (core, undo->off, false); + rz_core_block_read (core); } } break; case '-': // "s-" switch (input[1]) { case '*': // "s-*" - r_io_sundo_reset (core->io); + rz_io_sundo_reset (core->io); break; case 0: // "s-" { - RIOUndos *undo = r_io_sundo (core->io, core->offset); + RzIOUndos *undo = rz_io_sundo (core->io, core->offset); if (undo) { - r_core_seek (core, undo->off, false); - r_core_block_read (core); + rz_core_seek (core, undo->off, false); + rz_core_block_read (core); } } break; @@ -616,17 +616,17 @@ static int cmd_seek(void *data, const char *input) { int delta = -off; if (input[1] == '-') { delta = -core->blocksize; - int mult = r_num_math (core->num, input + 2); + int mult = rz_num_math (core->num, input + 2); if (mult > 0) { delta /= mult; } } if (!silent) { - r_io_sundo_push (core->io, core->offset, - r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, + rz_print_get_cursor (core->print)); } - r_core_seek_delta (core, delta); - r_core_block_read (core); + rz_core_seek_delta (core, delta); + rz_core_block_read (core); } break; } @@ -634,23 +634,23 @@ static int cmd_seek(void *data, const char *input) { case 'n': // "sn" { if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } const char *nkey = (input[1] == ' ') ? input + 2 - : r_config_get (core->config, "scr.nkey"); - r_core_seek_next (core, nkey); + : rz_config_get (core->config, "scr.nkey"); + rz_core_seek_next (core, nkey); } break; case 'p': // "sp" { if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } const char *nkey = (input[1] == ' ') ? input + 2 - : r_config_get (core->config, "scr.nkey"); - r_core_seek_previous (core, nkey); + : rz_config_get (core->config, "scr.nkey"); + rz_core_seek_previous (core, nkey); } break; case 'a': // "sa" @@ -659,47 +659,47 @@ static int cmd_seek(void *data, const char *input) { cmd = strdup (input); p = strchr (cmd + 2, ' '); if (p) { - off = r_num_math (core->num, p + 1);; + off = rz_num_math (core->num, p + 1);; *p = '\0'; } cmd[0] = 's'; // perform real seek if provided - r_cmd_call (core->rcmd, cmd); + rz_cmd_call (core->rcmd, cmd); free (cmd); } if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek_align (core, off, 0); + rz_core_seek_align (core, off, 0); break; case 'b': // "sb" if (off == 0) { off = core->offset; } if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_anal_bb_seek (core, off); + rz_core_anal_bb_seek (core, off); break; case 'f': { // "sf" - RAnalFunction *fcn; + RzAnalFunction *fcn; switch (input[1]) { case '\0': // "sf" - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - r_core_seek (core, r_anal_function_max_addr (fcn), true); + rz_core_seek (core, rz_anal_function_max_addr (fcn), true); } break; case ' ': // "sf " - fcn = r_anal_get_function_byname (core->anal, input + 2); + fcn = rz_anal_get_function_byname (core->anal, input + 2); if (fcn) { - r_core_seek (core, fcn->addr, true); + rz_core_seek (core, fcn->addr, true); } break; case '.': // "sf." - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - r_core_seek (core, fcn->addr, true); + rz_core_seek (core, fcn->addr, true); } break; } @@ -726,11 +726,11 @@ static int cmd_seek(void *data, const char *input) { break; case 'g': // "sg" { - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { - r_core_seek (core, map->itv.addr, true); + rz_core_seek (core, map->itv.addr, true); } else { - r_core_seek (core, 0, true); + rz_core_seek (core, 0, true); } } break; @@ -739,26 +739,26 @@ static int cmd_seek(void *data, const char *input) { if (!core->file) { break; } - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); // XXX: this +2 is a hack. must fix gap between sections if (map) { - r_core_seek (core, map->itv.addr + map->itv.size + 2, true); + rz_core_seek (core, map->itv.addr + map->itv.size + 2, true); } else { - r_core_seek (core, r_io_fd_size (core->io, core->file->fd), true); + rz_core_seek (core, rz_io_fd_size (core->io, core->file->fd), true); } } break; case 'l': // "sl" { - int sl_arg = r_num_math (core->num, input + 1); + int sl_arg = rz_num_math (core->num, input + 1); switch (input[1]) { case 'e': // "sleep" { const char *arg = strchr (input, ' '); if (arg) { - void *bed = r_cons_sleep_begin (); - r_sys_sleep (atoi (arg + 1)); - r_cons_sleep_end (bed); + void *bed = rz_cons_sleep_begin (); + rz_sys_sleep (atoi (arg + 1)); + rz_cons_sleep_end (bed); } else { eprintf ("Usage: sleep [seconds]\n"); } @@ -793,7 +793,7 @@ static int cmd_seek(void *data, const char *input) { eprintf ("%d lines\n", core->print->lines_cache_sz - 1); break; case '?': // "sl?" - r_core_cmd_help (core, help_msg_sl); + rz_core_cmd_help (core, help_msg_sl); break; } } @@ -802,17 +802,17 @@ static int cmd_seek(void *data, const char *input) { printPadded (core, atoi (input + 1)); break; case '?': // "s?" - r_core_cmd_help (core, help_msg_s); + rz_core_cmd_help (core, help_msg_s); break; default: { - ut64 n = r_num_math (core->num, input); + ut64 n = rz_num_math (core->num, input); if (n) { if (!silent) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } - r_core_seek (core, n, true); - r_core_block_read (core); + rz_core_seek (core, n, true); + rz_core_block_read (core); } } break; diff --git a/libr/core/cmd_type.c b/librz/core/cmd_type.c similarity index 65% rename from libr/core/cmd_type.c rename to librz/core/cmd_type.c index 8c88b3490f..40c48e1e46 100644 --- a/libr/core/cmd_type.c +++ b/librz/core/cmd_type.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, oddcoder, Anton Kochkov, Jody Frankowski */ #include -#include "r_anal.h" -#include "r_cons.h" -#include "r_core.h" +#include "rz_anal.h" +#include "rz_cons.h" +#include "rz_core.h" #include static const char *help_msg_t[] = { @@ -132,7 +132,7 @@ static const char *help_msg_tl[] = { "tls", " [address]", "show link at given address.", "tl-*", "", "delete all links.", "tl-", " [address]", "delete link at given address.", - "tl*", "", "list all links in radare2 command format.", + "tl*", "", "list all links in rizin command format.", "tlj", "", "list all links in JSON format.", NULL }; @@ -176,7 +176,7 @@ static const char *help_msg_tu[] = { NULL }; -static void cmd_type_init(RCore *core, RCmdDesc *parent) { +static void cmd_type_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, t); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, t-, t_minus); DEFINE_CMD_DESCRIPTOR (core, tc); @@ -189,92 +189,92 @@ static void cmd_type_init(RCore *core, RCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, tt); } -static void show_help(RCore *core) { - r_core_cmd_help (core, help_msg_t); +static void show_help(RzCore *core) { + rz_core_cmd_help (core, help_msg_t); } -static void __core_cmd_tcc(RCore *core, const char *input) { +static void __core_cmd_tcc(RzCore *core, const char *input) { switch (*input) { case '?': - r_core_cmd_help (core, help_msg_tcc); + rz_core_cmd_help (core, help_msg_tcc); break; case '-': if (input[1] == '*') { sdb_reset (core->anal->sdb_cc); } else { - r_anal_cc_del (core->anal, r_str_trim_head_ro (input + 1)); + rz_anal_cc_del (core->anal, rz_str_trim_head_ro (input + 1)); } break; case 0: - r_core_cmd0 (core, "afcl"); + rz_core_cmd0 (core, "afcl"); break; case 'j': { - char *ccs = r_core_cmd_strf (core, "afcl"); - r_str_trim (ccs); - RList *list = r_str_split_list (ccs, "\n", 0); - RListIter *iter; + char *ccs = rz_core_cmd_strf (core, "afcl"); + rz_str_trim (ccs); + RzList *list = rz_str_split_list (ccs, "\n", 0); + RzListIter *iter; const char *cc; PJ *pj = pj_new (); pj_a (pj); - r_list_foreach (list, iter, cc) { - char *ccexpr = r_anal_cc_get (core->anal, cc); + rz_list_foreach (list, iter, cc) { + char *ccexpr = rz_anal_cc_get (core->anal, cc); // TODO: expose this as an object, not just an array of strings pj_s (pj, ccexpr); free (ccexpr); } pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); - r_list_free (list); + rz_list_free (list); free (ccs); } break; case 'l': { - char *ccs = r_core_cmd_strf (core, "afcl"); - r_str_trim (ccs); - RList *list = r_str_split_list (ccs, "\n", 0); - RListIter *iter; + char *ccs = rz_core_cmd_strf (core, "afcl"); + rz_str_trim (ccs); + RzList *list = rz_str_split_list (ccs, "\n", 0); + RzListIter *iter; const char *cc; - r_list_foreach (list, iter, cc) { - char *ccexpr = r_anal_cc_get (core->anal, cc); - r_cons_printf ("%s\n", ccexpr); + rz_list_foreach (list, iter, cc) { + char *ccexpr = rz_anal_cc_get (core->anal, cc); + rz_cons_printf ("%s\n", ccexpr); free (ccexpr); } - r_list_free (list); + rz_list_free (list); free (ccs); } break; case '*': { - char *ccs = r_core_cmd_strf (core, "afcl"); - r_str_trim (ccs); - RList *list = r_str_split_list (ccs, "\n", 0); - RListIter *iter; + char *ccs = rz_core_cmd_strf (core, "afcl"); + rz_str_trim (ccs); + RzList *list = rz_str_split_list (ccs, "\n", 0); + RzListIter *iter; const char *cc; - r_list_foreach (list, iter, cc) { - char *ccexpr = r_anal_cc_get (core->anal, cc); - r_cons_printf ("tfc %s\n", ccexpr); + rz_list_foreach (list, iter, cc) { + char *ccexpr = rz_anal_cc_get (core->anal, cc); + rz_cons_printf ("tfc %s\n", ccexpr); free (ccexpr); } - r_list_free (list); + rz_list_free (list); free (ccs); } break; case 'k': - r_core_cmd0 (core, "afck"); + rz_core_cmd0 (core, "afck"); break; case ' ': if (strchr (input, '(')) { - if (!r_anal_cc_set (core->anal, input + 1)) { + if (!rz_anal_cc_set (core->anal, input + 1)) { eprintf ("Invalid syntax in cc signature."); } } else { - const char *ccname = r_str_trim_head_ro (input + 1); - char *cc = r_anal_cc_get (core->anal, ccname); + const char *ccname = rz_str_trim_head_ro (input + 1); + char *cc = rz_anal_cc_get (core->anal, ccname); if (cc) { - r_cons_printf ("%s\n", cc); + rz_cons_printf ("%s\n", cc); free (cc); } } @@ -282,14 +282,14 @@ static void __core_cmd_tcc(RCore *core, const char *input) { } } -static void showFormat(RCore *core, const char *name, int mode) { +static void showFormat(RzCore *core, const char *name, int mode) { const char *isenum = sdb_const_get (core->anal->sdb_types, name, 0); if (isenum && !strcmp (isenum, "enum")) { eprintf ("IS ENUM\n"); } else { - char *fmt = r_type_format (core->anal->sdb_types, name); + char *fmt = rz_type_format (core->anal->sdb_types, name); if (fmt) { - r_str_trim (fmt); + rz_str_trim (fmt); if (mode == 'j') { PJ *pj = pj_new (); if (!pj) { @@ -299,13 +299,13 @@ static void showFormat(RCore *core, const char *name, int mode) { pj_ks (pj, "name", name); pj_ks (pj, "format", fmt); pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); } else { if (mode) { - r_cons_printf ("pf.%s %s\n", name, fmt); + rz_cons_printf ("pf.%s %s\n", name, fmt); } else { - r_cons_printf ("pf %s\n", fmt); + rz_cons_printf ("pf %s\n", fmt); } } free (fmt); @@ -317,16 +317,16 @@ static void showFormat(RCore *core, const char *name, int mode) { static int cmd_tail(void *data, const char *_input) { // "tail" char *input = strdup (_input); - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; int lines = 5; char *arg = strchr (input, ' '); char *tmp, *count; if (arg) { - arg = (char *)r_str_trim_head_ro (arg + 1); // contains "count filename" + arg = (char *)rz_str_trim_head_ro (arg + 1); // contains "count filename" count = strchr (arg, ' '); if (count) { *count = 0; // split the count and file name - tmp = (char *)r_str_trim_head_ro (count + 1); + tmp = (char *)rz_str_trim_head_ro (count + 1); lines = atoi (arg); arg = tmp; } @@ -339,12 +339,12 @@ static int cmd_tail(void *data, const char *_input) { // "tail" if (!arg) { arg = ""; } - if (r_fs_check (core->fs, arg)) { - r_core_cmdf (core, "md %s", arg); + if (rz_fs_check (core->fs, arg)) { + rz_core_cmdf (core, "md %s", arg); } else { - char *res = r_syscmd_tail (arg, lines); + char *res = rz_syscmd_tail (arg, lines); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } } @@ -354,60 +354,60 @@ static int cmd_tail(void *data, const char *_input) { // "tail" return 0; } -static void cmd_type_noreturn(RCore *core, const char *input) { +static void cmd_type_noreturn(RzCore *core, const char *input) { switch (input[0]) { case '-': // "tn-" if (input[1] == '*') { - r_core_cmd0 (core, "tn- `tn`"); + rz_core_cmd0 (core, "tn- `tn`"); } else { - char *s = strdup (r_str_trim_head_ro (input + 1)); - RListIter *iter; + char *s = strdup (rz_str_trim_head_ro (input + 1)); + RzListIter *iter; char *k; - RList *list = r_str_split_list (s, " ", 0); - r_list_foreach (list, iter, k) { - r_anal_noreturn_drop (core->anal, k); + RzList *list = rz_str_split_list (s, " ", 0); + rz_list_foreach (list, iter, k) { + rz_anal_noreturn_drop (core->anal, k); } - r_list_free (list); + rz_list_free (list); free (s); } break; case ' ': // "tn" { - const char *arg = r_str_trim_head_ro (input + 1); - ut64 n = r_num_math (core->num, arg); + const char *arg = rz_str_trim_head_ro (input + 1); + ut64 n = rz_num_math (core->num, arg); if (n) { - r_anal_noreturn_add (core->anal, arg, n); + rz_anal_noreturn_add (core->anal, arg, n); } else { - r_anal_noreturn_add (core->anal, arg, UT64_MAX); + rz_anal_noreturn_add (core->anal, arg, UT64_MAX); } } break; case 'a': // "tna" if (input[1] == ' ') { - r_anal_noreturn_add (core->anal, NULL, - r_num_math (core->num, input + 1)); + rz_anal_noreturn_add (core->anal, NULL, + rz_num_math (core->num, input + 1)); } else { - r_core_cmd_help (core, help_msg_tn); + rz_core_cmd_help (core, help_msg_tn); } break; case 'n': // "tnn" if (input[1] == ' ') { /* do nothing? */ - r_anal_noreturn_add (core->anal, r_str_trim_head_ro (input + 2), UT64_MAX); + rz_anal_noreturn_add (core->anal, rz_str_trim_head_ro (input + 2), UT64_MAX); } else { - r_core_cmd_help (core, help_msg_tn); + rz_core_cmd_help (core, help_msg_tn); } break; case '*': case 'r': // "tn*" - r_anal_noreturn_list (core->anal, 1); + rz_anal_noreturn_list (core->anal, 1); break; case 0: // "tn" - r_anal_noreturn_list (core->anal, 0); + rz_anal_noreturn_list (core->anal, 0); break; default: case '?': - r_core_cmd_help (core, help_msg_tn); + rz_core_cmd_help (core, help_msg_tn); break; } } @@ -415,14 +415,14 @@ static void cmd_type_noreturn(RCore *core, const char *input) { static Sdb *TDB_ = NULL; // HACK static bool stdifstruct(void *user, const char *k, const char *v) { - r_return_val_if_fail (TDB_, false); - if (!strcmp (v, "struct") && !r_str_startswith (k, "typedef")) { + rz_return_val_if_fail (TDB_, false); + if (!strcmp (v, "struct") && !rz_str_startswith (k, "typedef")) { return true; } if (!strcmp (v, "typedef")) { const char *typedef_key = sdb_fmt ("typedef.%s", k); const char *type = sdb_const_get (TDB_, typedef_key, NULL); - if (type && r_str_startswith (type, "struct")) { + if (type && rz_str_startswith (type, "struct")) { return true; } } @@ -456,7 +456,7 @@ static int print_struct_union_list_json(Sdb *TDB, SdbForeachCallback filter) { } pj_end (pj); // ] - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); pj_free (pj); ls_free (l); return 1; @@ -484,25 +484,25 @@ static void print_struct_union_in_c_format(Sdb *TDB, SdbForeachCallback filter, continue; } } - r_cons_printf ("%s %s {%s", sdbkv_value (kv), name, multiline? "\n": ""); - char *p, *var = r_str_newf ("%s.%s", sdbkv_value (kv), name); + rz_cons_printf ("%s %s {%s", sdbkv_value (kv), name, multiline? "\n": ""); + char *p, *var = rz_str_newf ("%s.%s", sdbkv_value (kv), name); for (n = 0; (p = sdb_array_get (TDB, var, n, NULL)); n++) { - char *var2 = r_str_newf ("%s.%s", var, p); + char *var2 = rz_str_newf ("%s.%s", var, p); if (var2) { char *val = sdb_array_get (TDB, var2, 0, NULL); if (val) { if (multiline) { - r_cons_printf ("\t%s", val); + rz_cons_printf ("\t%s", val); if (p && p[0] != '\0') { - r_cons_printf ("%s%s", strstr (val, " *")? "": " ", p); + rz_cons_printf ("%s%s", strstr (val, " *")? "": " ", p); } } else { - r_cons_printf ("%s%s %s;", space, val, p); + rz_cons_printf ("%s%s %s;", space, val, p); space = " "; } } if (multiline) { - r_cons_println (";"); + rz_cons_println (";"); } free (val); } @@ -510,7 +510,7 @@ static void print_struct_union_in_c_format(Sdb *TDB, SdbForeachCallback filter, free (p); } free (var); - r_cons_println ("};"); + rz_cons_println ("};"); space = ""; if (match) { break; @@ -539,21 +539,21 @@ static void print_enum_in_c_format(Sdb *TDB, const char *arg, bool multiline) { continue; } } - r_cons_printf ("%s %s {%s", sdbkv_value (kv), name, multiline? "\n": ""); + rz_cons_printf ("%s %s {%s", sdbkv_value (kv), name, multiline? "\n": ""); { - RList *list = r_type_get_enum (TDB, name); - if (list && !r_list_empty (list)) { - RListIter *iter; + RzList *list = rz_type_get_enum (TDB, name); + if (list && !rz_list_empty (list)) { + RzListIter *iter; RTypeEnum *member; separator = multiline? "\t": ""; - r_list_foreach (list, iter, member) { - r_cons_printf ("%s%s = %d", separator, member->name, r_num_math (NULL, member->val)); + rz_list_foreach (list, iter, member) { + rz_cons_printf ("%s%s = %d", separator, member->name, rz_num_math (NULL, member->val)); separator = multiline? ",\n\t": ", "; } } - r_list_free (list); + rz_list_free (list); } - r_cons_println (multiline? "\n};": "};"); + rz_cons_println (multiline? "\n};": "};"); if (match) { break; } @@ -565,15 +565,15 @@ static void print_enum_in_c_format(Sdb *TDB, const char *arg, bool multiline) { } static bool printkey_cb(void *user, const char *k, const char *v) { - r_cons_println (k); + rz_cons_println (k); return true; } // maybe dupe?. should return char *instead of print for reusability -static void printFunctionTypeC(RCore *core, const char *input) { +static void printFunctionTypeC(RzCore *core, const char *input) { Sdb *TDB = core->anal->sdb_types; char *res = sdb_querys (TDB, NULL, -1, sdb_fmt ("func.%s.args", input)); - const char *name = r_str_trim_head_ro (input); + const char *name = rz_str_trim_head_ro (input); int i, args = sdb_num_get (TDB, sdb_fmt ("func.%s.args", name), 0); const char *ret = sdb_const_get (TDB, sdb_fmt ("func.%s.ret", name), 0); if (!ret) { @@ -584,20 +584,20 @@ static void printFunctionTypeC(RCore *core, const char *input) { return; } - r_cons_printf ("%s %s (", ret, name); + rz_cons_printf ("%s %s (", ret, name); for (i = 0; i < args; i++) { char *type = sdb_get (TDB, sdb_fmt ("func.%s.arg.%d", name, i), 0); char *name = strchr (type, ','); if (name) { *name++ = 0; } - r_cons_printf ("%s%s %s", i==0? "": ", ", type, name); + rz_cons_printf ("%s%s %s", i==0? "": ", ", type, name); } - r_cons_printf (");\n"); + rz_cons_printf (");\n"); free (res); } -static void printFunctionType(RCore *core, const char *input) { +static void printFunctionType(RzCore *core, const char *input) { Sdb *TDB = core->anal->sdb_types; PJ *pj = pj_new (); if (!pj) { @@ -605,7 +605,7 @@ static void printFunctionType(RCore *core, const char *input) { } pj_o (pj); char *res = sdb_querys (TDB, NULL, -1, sdb_fmt ("func.%s.args", input)); - const char *name = r_str_trim_head_ro (input); + const char *name = rz_str_trim_head_ro (input); int i, args = sdb_num_get (TDB, sdb_fmt ("func.%s.args", name), 0); pj_ks (pj, "name", name); const char *ret_type = sdb_const_get (TDB, sdb_fmt ("func.%s.ret", name), 0); @@ -632,13 +632,13 @@ static void printFunctionType(RCore *core, const char *input) { } pj_end (pj); pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); free (res); } static bool printfunc_json_cb(void *user, const char *k, const char *v) { - printFunctionType ((RCore *)user, k); + printFunctionType ((RzCore *)user, k); return true; } @@ -651,9 +651,9 @@ static bool stdifunion(void *p, const char *k, const char *v) { } static bool sdbdeletelink(void *p, const char *k, const char *v) { - RCore *core = (RCore *)p; + RzCore *core = (RzCore *)p; if (!strncmp (k, "link.", strlen ("link."))) { - r_type_del (core->anal->sdb_types, k); + rz_type_del (core->anal->sdb_types, k); } return true; } @@ -663,42 +663,42 @@ static bool stdiflink(void *p, const char *k, const char *v) { } static bool print_link_cb(void *p, const char *k, const char *v) { - r_cons_printf ("0x%s = %s\n", k + strlen ("link."), v); + rz_cons_printf ("0x%s = %s\n", k + strlen ("link."), v); return true; } static bool print_link_json_cb(void *p, const char *k, const char *v) { - r_cons_printf ("{\"0x%s\":\"%s\"}", k + strlen ("link."), v); + rz_cons_printf ("{\"0x%s\":\"%s\"}", k + strlen ("link."), v); return true; } static bool print_link_r_cb(void *p, const char *k, const char *v) { - r_cons_printf ("tl %s = 0x%s\n", v, k + strlen ("link.")); + rz_cons_printf ("tl %s = 0x%s\n", v, k + strlen ("link.")); return true; } static bool print_link_readable_cb(void *p, const char *k, const char *v) { - RCore *core = (RCore *)p; - char *fmt = r_type_format (core->anal->sdb_types, v); + RzCore *core = (RzCore *)p; + char *fmt = rz_type_format (core->anal->sdb_types, v); if (!fmt) { eprintf ("Can't fint type %s", v); return 1; } - r_cons_printf ("(%s)\n", v); - r_core_cmdf (core, "pf %s @ 0x%s\n", fmt, k + strlen ("link.")); + rz_cons_printf ("(%s)\n", v); + rz_core_cmdf (core, "pf %s @ 0x%s\n", fmt, k + strlen ("link.")); return true; } static bool print_link_readable_json_cb(void *p, const char *k, const char *v) { - RCore *core = (RCore *)p; - char *fmt = r_type_format (core->anal->sdb_types, v); + RzCore *core = (RzCore *)p; + char *fmt = rz_type_format (core->anal->sdb_types, v); if (!fmt) { eprintf ("Can't fint type %s", v); return true; } - r_cons_printf ("{\"%s\":", v); - r_core_cmdf (core, "pfj %s @ 0x%s\n", fmt, k + strlen ("link.")); - r_cons_printf ("}"); + rz_cons_printf ("{\"%s\":", v); + rz_core_cmdf (core, "pfj %s @ 0x%s\n", fmt, k + strlen ("link.")); + rz_cons_printf ("}"); return true; } @@ -707,25 +707,25 @@ static bool stdiftype(void *p, const char *k, const char *v) { } static bool print_typelist_r_cb(void *p, const char *k, const char *v) { - r_cons_printf ("tk %s=%s\n", k, v); + rz_cons_printf ("tk %s=%s\n", k, v); return true; } static bool print_typelist_json_cb(void *p, const char *k, const char *v) { - RCore *core = (RCore *)p; + RzCore *core = (RzCore *)p; PJ *pj = pj_new (); pj_o (pj); Sdb *sdb = core->anal->sdb_types; - char *sizecmd = r_str_newf ("type.%s.size", k); + char *sizecmd = rz_str_newf ("type.%s.size", k); char *size_s = sdb_querys (sdb, NULL, -1, sizecmd); - char *formatcmd = r_str_newf ("type.%s", k); + char *formatcmd = rz_str_newf ("type.%s", k); char *format_s = sdb_querys (sdb, NULL, -1, formatcmd); - r_str_trim (format_s); + rz_str_trim (format_s); pj_ks (pj, "type", k); pj_ki (pj, "size", size_s ? atoi (size_s) : -1); pj_ks (pj, "format", format_s); pj_end (pj); - r_cons_printf ("%s", pj_string (pj)); + rz_cons_printf ("%s", pj_string (pj)); pj_free (pj); free (size_s); free (format_s); @@ -734,14 +734,14 @@ static bool print_typelist_json_cb(void *p, const char *k, const char *v) { return true; } -static void print_keys(Sdb *TDB, RCore *core, SdbForeachCallback filter, SdbForeachCallback printfn_cb, bool json) { +static void print_keys(Sdb *TDB, RzCore *core, SdbForeachCallback filter, SdbForeachCallback printfn_cb, bool json) { SdbList *l = sdb_foreach_list_filter (TDB, filter, true); SdbListIter *it; SdbKv *kv; const char *comma = ""; if (json) { - r_cons_printf ("["); + rz_cons_printf ("["); } ls_foreach (l, it, kv) { const char *k = sdbkv_key (kv); @@ -749,18 +749,18 @@ static void print_keys(Sdb *TDB, RCore *core, SdbForeachCallback filter, SdbFore continue; } if (json) { - r_cons_printf ("%s", comma); + rz_cons_printf ("%s", comma); comma = ","; } printfn_cb (core, sdbkv_key (kv), sdbkv_value (kv)); } if (json) { - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); } ls_free (l); } -static void typesList(RCore *core, int mode) { +static void typesList(RzCore *core, int mode) { switch (mode) { case 1: case '*': @@ -775,31 +775,31 @@ static void typesList(RCore *core, int mode) { } } -static void set_offset_hint(RCore *core, RAnalOp *op, const char *type, ut64 laddr, ut64 at, int offimm) { - char *res = r_type_get_struct_memb (core->anal->sdb_types, type, offimm); +static void set_offset_hint(RzCore *core, RzAnalOp *op, const char *type, ut64 laddr, ut64 at, int offimm) { + char *res = rz_type_get_struct_memb (core->anal->sdb_types, type, offimm); const char *cmt = ((offimm == 0) && res)? res: type; if (offimm > 0) { // set hint only if link is present char* query = sdb_fmt ("link.%08"PFMT64x, laddr); if (res && sdb_const_get (core->anal->sdb_types, query, 0)) { - r_anal_hint_set_offset (core->anal, at, res); + rz_anal_hint_set_offset (core->anal, at, res); } - } else if (cmt && r_anal_op_ismemref (op->type)) { - r_meta_set_string (core->anal, R_META_TYPE_VARTYPE, at, cmt); + } else if (cmt && rz_anal_op_ismemref (op->type)) { + rz_meta_set_string (core->anal, R_META_TYPE_VARTYPE, at, cmt); } } -R_API int r_core_get_stacksz(RCore *core, ut64 from, ut64 to) { +RZ_API int rz_core_get_stacksz(RzCore *core, ut64 from, ut64 to) { int stack = 0, maxstack = 0; ut64 at = from; if (from >= to) { return 0; } - const int mininstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + const int mininstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); while (at < to) { - RAnalOp *op = r_core_anal_op (core, at, R_ANAL_OP_MASK_BASIC); + RzAnalOp *op = rz_core_anal_op (core, at, R_ANAL_OP_MASK_BASIC); if (!op || op->size <= 0) { at += minopcode; continue; @@ -811,15 +811,15 @@ R_API int r_core_get_stacksz(RCore *core, ut64 from, ut64 to) { } } at += op->size; - r_anal_op_free (op); + rz_anal_op_free (op); } return maxstack; } -static void set_retval(RCore *core, ut64 at) { - RAnal *anal = core->anal; - RAnalHint *hint = r_anal_hint_get (anal, at); - RAnalFunction *fcn = r_anal_get_fcn_in (anal, at, 0); +static void set_retval(RzCore *core, ut64 at) { + RzAnal *anal = core->anal; + RzAnalHint *hint = rz_anal_hint_get (anal, at); + RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, at, 0); if (!hint || !fcn || !fcn->name) { goto beach; @@ -827,83 +827,83 @@ static void set_retval(RCore *core, ut64 at) { if (hint->ret == UT64_MAX) { goto beach; } - const char *cc = r_anal_cc_func (core->anal, fcn->name); - const char *regname = r_anal_cc_ret (anal, cc); + const char *cc = rz_anal_cc_func (core->anal, fcn->name); + const char *regname = rz_anal_cc_ret (anal, cc); if (regname) { - RRegItem *reg = r_reg_get (anal->reg, regname, -1); + RzRegItem *reg = rz_reg_get (anal->reg, regname, -1); if (reg) { - r_reg_set_value (anal->reg, reg, hint->ret); + rz_reg_set_value (anal->reg, reg, hint->ret); } } beach: - r_anal_hint_free (hint); + rz_anal_hint_free (hint); return; } -R_API void r_core_link_stroff(RCore *core, RAnalFunction *fcn) { - RAnalBlock *bb; - RListIter *it; - RAnalOp aop = {0}; - bool ioCache = r_config_get_i (core->config, "io.cache"); +RZ_API void rz_core_link_stroff(RzCore *core, RzAnalFunction *fcn) { + RzAnalBlock *bb; + RzListIter *it; + RzAnalOp aop = {0}; + bool ioCache = rz_config_get_i (core->config, "io.cache"); bool stack_set = false; bool resolved = false; const char *varpfx; - int dbg_follow = r_config_get_i (core->config, "dbg.follow"); + int dbg_follow = rz_config_get_i (core->config, "dbg.follow"); Sdb *TDB = core->anal->sdb_types; - RAnalEsil *esil; - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int stacksize = r_config_get_i (core->config, "esil.stack.depth"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); - const char *pc_name = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - const char *sp_name = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - RRegItem *pc = r_reg_get (core->anal->reg, pc_name, -1); + RzAnalEsil *esil; + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int stacksize = rz_config_get_i (core->config, "esil.stack.depth"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); + const char *pc_name = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + const char *sp_name = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + RzRegItem *pc = rz_reg_get (core->anal->reg, pc_name, -1); if (!fcn) { return; } - if (!(esil = r_anal_esil_new (stacksize, iotrap, addrsize))) { + if (!(esil = rz_anal_esil_new (stacksize, iotrap, addrsize))) { return; } - r_anal_esil_setup (esil, core->anal, 0, 0, 0); + rz_anal_esil_setup (esil, core->anal, 0, 0, 0); int i, ret, bsize = R_MAX (64, core->blocksize); - const int mininstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); - const int maxinstrsz = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + const int mininstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + const int maxinstrsz = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); const int minopcode = R_MAX (1, mininstrsz); ut8 *buf = malloc (bsize); if (!buf) { free (buf); - r_anal_esil_free (esil); + rz_anal_esil_free (esil); return; } - r_reg_arena_push (core->anal->reg); - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); - ut64 spval = r_reg_getv (esil->anal->reg, sp_name); + rz_reg_arena_push (core->anal->reg); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, true); + ut64 spval = rz_reg_getv (esil->anal->reg, sp_name); if (spval) { // reset stack pointer to initial value - RRegItem *sp = r_reg_get (esil->anal->reg, sp_name, -1); - ut64 curpc = r_reg_getv (esil->anal->reg, pc_name); - int stacksz = r_core_get_stacksz (core, fcn->addr, curpc); + RzRegItem *sp = rz_reg_get (esil->anal->reg, sp_name, -1); + ut64 curpc = rz_reg_getv (esil->anal->reg, pc_name); + int stacksz = rz_core_get_stacksz (core, fcn->addr, curpc); if (stacksz > 0) { - r_reg_arena_zero (esil->anal->reg); // clear prev reg values - r_reg_set_value (esil->anal->reg, sp, spval + stacksz); + rz_reg_arena_zero (esil->anal->reg); // clear prev reg values + rz_reg_set_value (esil->anal->reg, sp, spval + stacksz); } } else { // initialize stack - r_core_cmd0 (core, "aeim"); + rz_core_cmd0 (core, "aeim"); stack_set = true; } - r_config_set_i (core->config, "io.cache", 1); - r_config_set_i (core->config, "dbg.follow", 0); + rz_config_set_i (core->config, "io.cache", 1); + rz_config_set_i (core->config, "dbg.follow", 0); ut64 oldoff = core->offset; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); // TODO: The algorithm can be more accurate if blocks are followed by their jmp/fail, not just by address - r_list_sort (fcn->bbs, bb_cmpaddr); - r_list_foreach (fcn->bbs, it, bb) { + rz_list_sort (fcn->bbs, bb_cmpaddr); + rz_list_foreach (fcn->bbs, it, bb) { ut64 at = bb->addr; ut64 to = bb->addr + bb->size; - r_reg_set_value (esil->anal->reg, pc, at); + rz_reg_set_value (esil->anal->reg, pc, at); for (i = 0; at < to; i++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto beach; } if (at < bb->addr) { @@ -913,46 +913,46 @@ R_API void r_core_link_stroff(RCore *core, RAnalFunction *fcn) { i = 0; } if (!i) { - r_io_read_at (core->io, at, buf, bsize); + rz_io_read_at (core->io, at, buf, bsize); } - ret = r_anal_op (core->anal, &aop, at, buf + i, bsize - i, R_ANAL_OP_MASK_VAL); + ret = rz_anal_op (core->anal, &aop, at, buf + i, bsize - i, R_ANAL_OP_MASK_VAL); if (ret <= 0) { i += minopcode; at += minopcode; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); continue; } i += ret - 1; at += ret; int index = 0; if (aop.ireg) { - index = r_reg_getv (esil->anal->reg, aop.ireg) * aop.scale; + index = rz_reg_getv (esil->anal->reg, aop.ireg) * aop.scale; } int j, src_imm = -1, dst_imm = -1; ut64 src_addr = UT64_MAX; ut64 dst_addr = UT64_MAX; for (j = 0; j < 3; j++) { if (aop.src[j] && aop.src[j]->reg && aop.src[j]->reg->name) { - src_addr = r_reg_getv (esil->anal->reg, aop.src[j]->reg->name) + index; + src_addr = rz_reg_getv (esil->anal->reg, aop.src[j]->reg->name) + index; src_imm = aop.src[j]->delta; } } if (aop.dst && aop.dst->reg && aop.dst->reg->name) { - dst_addr = r_reg_getv (esil->anal->reg, aop.dst->reg->name) + index; + dst_addr = rz_reg_getv (esil->anal->reg, aop.dst->reg->name) + index; dst_imm = aop.dst->delta; } - RAnalVar *var = r_anal_get_used_function_var (core->anal, aop.addr); + RzAnalVar *var = rz_anal_get_used_function_var (core->anal, aop.addr); if (false) { // src_addr != UT64_MAX || dst_addr != UT64_MAX) { // if (src_addr == UT64_MAX && dst_addr == UT64_MAX) { - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); continue; } - char *slink = r_type_link_at (TDB, src_addr); - char *vlink = r_type_link_at (TDB, src_addr + src_imm); - char *dlink = r_type_link_at (TDB, dst_addr); + char *slink = rz_type_link_at (TDB, src_addr); + char *vlink = rz_type_link_at (TDB, src_addr + src_imm); + char *dlink = rz_type_link_at (TDB, dst_addr); //TODO: Handle register based arg for struct offset propgation if (vlink && var && var->kind != 'r') { - if (r_type_kind (TDB, vlink) == R_TYPE_UNION) { + if (rz_type_kind (TDB, vlink) == R_TYPE_UNION) { varpfx = "union"; } else { varpfx = "struct"; @@ -961,43 +961,43 @@ R_API void r_core_link_stroff(RCore *core, RAnalFunction *fcn) { // var int local_e0h --> var struct foo if (strcmp (var->name , vlink) && !resolved) { resolved = true; - r_anal_var_set_type (var, varpfx); - r_anal_var_rename (var, vlink, false); + rz_anal_var_set_type (var, varpfx); + rz_anal_var_rename (var, vlink, false); } } else if (slink) { set_offset_hint (core, &aop, slink, src_addr, at - ret, src_imm); } else if (dlink) { set_offset_hint (core, &aop, dlink, dst_addr, at - ret, dst_imm); } - if (r_anal_op_nonlinear (aop.type)) { - r_reg_set_value (esil->anal->reg, pc, at); + if (rz_anal_op_nonlinear (aop.type)) { + rz_reg_set_value (esil->anal->reg, pc, at); set_retval (core, at - ret); } else { - r_core_esil_step (core, UT64_MAX, NULL, NULL, false); + rz_core_esil_step (core, UT64_MAX, NULL, NULL, false); } free (dlink); free (vlink); free (slink); - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } } beach: - r_core_cmd0 (core, "wc-*"); // drop cache writes - r_config_set_i (core->config, "io.cache", ioCache); - r_config_set_i (core->config, "dbg.follow", dbg_follow); + rz_core_cmd0 (core, "wc-*"); // drop cache writes + rz_config_set_i (core->config, "io.cache", ioCache); + rz_config_set_i (core->config, "dbg.follow", dbg_follow); if (stack_set) { - r_core_cmd0 (core, "aeim-"); + rz_core_cmd0 (core, "aeim-"); } - r_core_seek (core, oldoff, true); - r_anal_esil_free (esil); - r_reg_arena_pop (core->anal->reg); - r_core_cmd0 (core, ".ar*"); - r_cons_break_pop (); + rz_core_seek (core, oldoff, true); + rz_anal_esil_free (esil); + rz_reg_arena_pop (core->anal->reg); + rz_core_cmd0 (core, ".ar*"); + rz_cons_break_pop (); free (buf); } static int cmd_type(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; Sdb *TDB = core->anal->sdb_types; char *res; TDB_ = TDB; // HACK @@ -1010,11 +1010,11 @@ static int cmd_type(void *data, const char *input) { case 'u': { // "tu" switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_tu); + rz_core_cmd_help (core, help_msg_tu); break; case '*': if (input[2] == ' ') { - showFormat (core, r_str_trim_head_ro (input + 2), 1); + showFormat (core, rz_str_trim_head_ro (input + 2), 1); } else { SdbList *l = sdb_foreach_list_filter (TDB, stdifunion, true); SdbListIter *it; @@ -1027,20 +1027,20 @@ static int cmd_type(void *data, const char *input) { break; case 'j': // "tuj" if (input[2]) { - showFormat (core, r_str_trim_head_ro (input + 2), 'j'); - r_cons_newline (); + showFormat (core, rz_str_trim_head_ro (input + 2), 'j'); + rz_cons_newline (); } else { print_struct_union_list_json (TDB, stdifunion); } break; case 'c': - print_struct_union_in_c_format (TDB, stdifunion, r_str_trim_head_ro (input + 2), true); + print_struct_union_in_c_format (TDB, stdifunion, rz_str_trim_head_ro (input + 2), true); break; case 'd': - print_struct_union_in_c_format (TDB, stdifunion, r_str_trim_head_ro (input + 2), false); + print_struct_union_in_c_format (TDB, stdifunion, rz_str_trim_head_ro (input + 2), false); break; case ' ': - showFormat (core, r_str_trim_head_ro (input + 1), 0); + showFormat (core, rz_str_trim_head_ro (input + 1), 0); break; case 0: print_keys (TDB, core, stdifunion, printkey_cb, false); @@ -1052,7 +1052,7 @@ static int cmd_type(void *data, const char *input) { ? sdb_querys (TDB, NULL, -1, input + 2) : sdb_querys (TDB, NULL, -1, "*"); if (res) { - r_cons_print (res); + rz_cons_print (res); free (res); } break; @@ -1062,49 +1062,49 @@ static int cmd_type(void *data, const char *input) { __core_cmd_tcc (core, input + 2); break; case '?': //"tc?" - r_core_cmd_help (core, help_msg_tc); + rz_core_cmd_help (core, help_msg_tc); break; case ' ': { - const char *type = r_str_trim_head_ro (input + 1); + const char *type = rz_str_trim_head_ro (input + 1); const char *name = type ? strchr (type, '.') : NULL; if (name && type) { name++; // skip the '.' - if (r_str_startswith (type, "struct")) { - r_core_cmdf (core, "tsc %s", name); - } else if (r_str_startswith (type, "union")) { - r_core_cmdf (core, "tuc %s", name); - } else if (r_str_startswith (type, "enum")) { - r_core_cmdf (core, "tec %s", name); - } else if (r_str_startswith (type, "typedef")) { - r_core_cmdf (core, "ttc %s", name); - } else if (r_str_startswith (type, "func")) { - r_core_cmdf (core, "tfc %s", name); + if (rz_str_startswith (type, "struct")) { + rz_core_cmdf (core, "tsc %s", name); + } else if (rz_str_startswith (type, "union")) { + rz_core_cmdf (core, "tuc %s", name); + } else if (rz_str_startswith (type, "enum")) { + rz_core_cmdf (core, "tec %s", name); + } else if (rz_str_startswith (type, "typedef")) { + rz_core_cmdf (core, "ttc %s", name); + } else if (rz_str_startswith (type, "func")) { + rz_core_cmdf (core, "tfc %s", name); } } break; } case '*': - r_core_cmd0 (core, "ts*"); + rz_core_cmd0 (core, "ts*"); break; case 0: - r_core_cmd0 (core, "tfc;tuc;tsc;ttc;tec"); + rz_core_cmd0 (core, "tfc;tuc;tsc;ttc;tec"); break; case 'd': - r_core_cmd0 (core, "tud;tsd;ttc;ted"); + rz_core_cmd0 (core, "tud;tsd;ttc;ted"); break; default: - r_core_cmd_help (core, help_msg_tc); + rz_core_cmd_help (core, help_msg_tc); break; } break; case 's': { // "ts" switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_ts); + rz_core_cmd_help (core, help_msg_ts); break; case '*': if (input[2] == ' ') { - showFormat (core, r_str_trim_head_ro (input + 2), 1); + showFormat (core, rz_str_trim_head_ro (input + 2), 1); } else { SdbList *l = sdb_foreach_list_filter (TDB, stdifstruct, true); SdbListIter *it; @@ -1117,29 +1117,29 @@ static int cmd_type(void *data, const char *input) { } break; case ' ': - showFormat (core, r_str_trim_head_ro (input + 1), 0); + showFormat (core, rz_str_trim_head_ro (input + 1), 0); break; case 's': if (input[2] == ' ') { - r_cons_printf ("%d\n", (r_type_get_bitsize (TDB, input + 3) / 8)); + rz_cons_printf ("%d\n", (rz_type_get_bitsize (TDB, input + 3) / 8)); } else { - r_core_cmd_help (core, help_msg_ts); + rz_core_cmd_help (core, help_msg_ts); } break; case 0: print_keys (TDB, core, stdifstruct, printkey_cb, false); break; case 'c': // "tsc" - print_struct_union_in_c_format (TDB, stdifstruct, r_str_trim_head_ro (input + 2), true); + print_struct_union_in_c_format (TDB, stdifstruct, rz_str_trim_head_ro (input + 2), true); break; case 'd': // "tsd" - print_struct_union_in_c_format (TDB, stdifstruct, r_str_trim_head_ro (input + 2), false); + print_struct_union_in_c_format (TDB, stdifstruct, rz_str_trim_head_ro (input + 2), false); break; case 'j': // "tsj" // TODO: current output is a bit poor, will be good to improve if (input[2]) { - showFormat (core, r_str_trim_head_ro (input + 2), 'j'); - r_cons_newline (); + showFormat (core, rz_str_trim_head_ro (input + 2), 'j'); + rz_cons_newline (); } else { print_struct_union_list_json (TDB, stdifstruct); } @@ -1155,14 +1155,14 @@ static int cmd_type(void *data, const char *input) { if (member_name) { *member_name++ = 0; } - if (name && (r_type_kind (TDB, name) != R_TYPE_ENUM)) { + if (name && (rz_type_kind (TDB, name) != R_TYPE_ENUM)) { eprintf ("%s is not an enum\n", name); free (name); break; } switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_te); + rz_core_cmd_help (core, help_msg_te); break; case 'j': // "tej" if (input[2] == 0) { // "tej" @@ -1179,72 +1179,72 @@ static int cmd_type(void *data, const char *input) { name = strdup (sdbkv_key (kv)); pj_k (pj, name); { - RList *list = r_type_get_enum (TDB, name); - if (list && !r_list_empty (list)) { + RzList *list = rz_type_get_enum (TDB, name); + if (list && !rz_list_empty (list)) { pj_o (pj); - RListIter *iter; + RzListIter *iter; RTypeEnum *member; - r_list_foreach (list, iter, member) { - pj_kn (pj, member->name, r_num_math (NULL, member->val)); + rz_list_foreach (list, iter, member) { + pj_kn (pj, member->name, rz_num_math (NULL, member->val)); } pj_end (pj); } - r_list_free (list); + rz_list_free (list); } } } } pj_end (pj); - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); free (name); ls_free (l); } else { // "tej ENUM" - RListIter *iter; + RzListIter *iter; PJ *pj = pj_new (); RTypeEnum *member; pj_o (pj); if (member_name) { - res = r_type_enum_member (TDB, name, NULL, r_num_math (core->num, member_name)); + res = rz_type_enum_member (TDB, name, NULL, rz_num_math (core->num, member_name)); // NEVER REACHED } else { - RList *list = r_type_get_enum (TDB, name); - if (list && !r_list_empty (list)) { + RzList *list = rz_type_get_enum (TDB, name); + if (list && !rz_list_empty (list)) { pj_ks (pj, "name", name); pj_k (pj, "values"); pj_o (pj); - r_list_foreach (list, iter, member) { - pj_kn (pj, member->name, r_num_math (NULL, member->val)); + rz_list_foreach (list, iter, member) { + pj_kn (pj, member->name, rz_num_math (NULL, member->val)); } pj_end (pj); pj_end (pj); } - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); - r_list_free (list); + rz_list_free (list); } } break; case 'b': // "teb" - res = r_type_enum_member (TDB, name, member_name, 0); + res = rz_type_enum_member (TDB, name, member_name, 0); break; case 'c': // "tec" - print_enum_in_c_format(TDB, r_str_trim_head_ro (input + 2), true); + print_enum_in_c_format(TDB, rz_str_trim_head_ro (input + 2), true); break; case 'd': - print_enum_in_c_format(TDB, r_str_trim_head_ro (input + 2), false); + print_enum_in_c_format(TDB, rz_str_trim_head_ro (input + 2), false); break; case ' ': if (member_name) { - res = r_type_enum_member (TDB, name, NULL, r_num_math (core->num, member_name)); + res = rz_type_enum_member (TDB, name, NULL, rz_num_math (core->num, member_name)); } else { - RList *list = r_type_get_enum (TDB, name); - RListIter *iter; + RzList *list = rz_type_get_enum (TDB, name); + RzListIter *iter; RTypeEnum *member; - r_list_foreach (list, iter, member) { - r_cons_printf ("%s = %s\n", member->name, member->val); + rz_list_foreach (list, iter, member) { + rz_cons_printf ("%s = %s\n", member->name, member->val); } - r_list_free (list); + rz_list_free (list); } break; case '\0': { @@ -1257,7 +1257,7 @@ static int cmd_type(void *data, const char *input) { if (!name || strcmp (sdbkv_value (kv), name)) { free (name); name = strdup (sdbkv_key (kv)); - r_cons_println (name); + rz_cons_println (name); } } } @@ -1267,7 +1267,7 @@ static int cmd_type(void *data, const char *input) { } free (name); if (res) { - r_cons_println (res); + rz_cons_println (res); } else if (member_name) { eprintf ("Invalid enum member\n"); } @@ -1283,26 +1283,26 @@ static int cmd_type(void *data, const char *input) { break; case 'o': // "to" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_to); - } else if (!r_sandbox_enable (0)) { + rz_core_cmd_help (core, help_msg_to); + } else if (!rz_sandbox_enable (0)) { if (input[1] == ' ') { - const char *dir = r_config_get (core->config, "dir.types"); + const char *dir = rz_config_get (core->config, "dir.types"); const char *filename = input + 2; char *homefile = NULL; if (*filename == '~') { if (filename[1] && filename[2]) { - homefile = r_str_home (filename + 2); + homefile = rz_str_home (filename + 2); filename = homefile; } } if (!strcmp (filename, "-")) { - char *tmp = r_core_editor (core, "*.h", ""); + char *tmp = rz_core_editor (core, "*.h", ""); if (tmp) { char *error_msg = NULL; - char *out = r_parse_c_string (core->anal, tmp, &error_msg); + char *out = rz_parse_c_string (core->anal, tmp, &error_msg); if (out) { - // r_cons_strcat (out); - r_anal_save_parsed_type (core->anal, out); + // rz_cons_strcat (out); + rz_anal_save_parsed_type (core->anal, out); free (out); } if (error_msg) { @@ -1313,10 +1313,10 @@ static int cmd_type(void *data, const char *input) { } } else { char *error_msg = NULL; - char *out = r_parse_c_file (core->anal, filename, dir, &error_msg); + char *out = rz_parse_c_file (core->anal, filename, dir, &error_msg); if (out) { - //r_cons_strcat (out); - r_anal_save_parsed_type (core->anal, out); + //rz_cons_strcat (out); + rz_anal_save_parsed_type (core->anal, out); free (out); } if (error_msg) { @@ -1329,29 +1329,29 @@ static int cmd_type(void *data, const char *input) { // "tou" "touch" char *arg = strchr (input, ' '); if (arg) { - r_file_touch (arg + 1); + rz_file_touch (arg + 1); } else { eprintf ("Usage: touch [filename]"); } } else if (input[1] == 's') { const char *dbpath = input + 3; - if (r_file_exists (dbpath)) { + if (rz_file_exists (dbpath)) { Sdb *db_tmp = sdb_new (0, dbpath, 0); sdb_merge (TDB, db_tmp); sdb_close (db_tmp); sdb_free (db_tmp); } } else if (input[1] == 'e') { // "toe" - char *str = r_core_cmd_strf (core , "tc %s", input + 2); - char *tmp = r_core_editor (core, "*.h", str); + char *str = rz_core_cmd_strf (core , "tc %s", input + 2); + char *tmp = rz_core_editor (core, "*.h", str); if (tmp) { char *error_msg = NULL; - char *out = r_parse_c_string (core->anal, tmp, &error_msg); + char *out = rz_parse_c_string (core->anal, tmp, &error_msg); if (out) { // remove previous types and save new edited types sdb_reset (TDB); - r_parse_c_reset (core->parser); - r_anal_save_parsed_type (core->anal, out); + rz_parse_c_reset (core->parser); + rz_anal_save_parsed_type (core->anal, out); free (out); } if (error_msg) { @@ -1370,21 +1370,21 @@ static int cmd_type(void *data, const char *input) { case 'd': // "td" if (input[1] == '?') { // TODO #7967 help refactor: move to detail - r_core_cmd_help (core, help_msg_td); - r_cons_printf ("Note: The td command should be put between double quotes\n" + rz_core_cmd_help (core, help_msg_td); + rz_cons_printf ("Note: The td command should be put between double quotes\n" "Example: \"td struct foo {int bar;int cow;};\"" "\nt"); } else if (input[1] == ' ') { - char *tmp = r_str_newf ("%s;", input + 2); + char *tmp = rz_str_newf ("%s;", input + 2); if (!tmp) { break; } char *error_msg = NULL; - char *out = r_parse_c_string (core->anal, tmp, &error_msg); + char *out = rz_parse_c_string (core->anal, tmp, &error_msg); free (tmp); if (out) { - r_anal_save_parsed_type (core->anal, out); + rz_anal_save_parsed_type (core->anal, out); free (out); } if (error_msg) { @@ -1397,51 +1397,51 @@ static int cmd_type(void *data, const char *input) { break; case 'x': { char *type, *type2; - RListIter *iter, *iter2; - RAnalFunction *fcn; + RzListIter *iter, *iter2; + RzAnalFunction *fcn; switch (input[1]) { case '.': // "tx." type xrefs case 'f': // "txf" type xrefs { ut64 addr = core->offset; if (input[2] == ' ') { - addr = r_num_math (core->num, input + 2); + addr = rz_num_math (core->num, input + 2); } - fcn = r_anal_get_function_at (core->anal, addr); + fcn = rz_anal_get_function_at (core->anal, addr); if (fcn) { - RList *uniq = r_anal_types_from_fcn (core->anal, fcn); - r_list_foreach (uniq , iter , type) { - r_cons_println (type); + RzList *uniq = rz_anal_types_from_fcn (core->anal, fcn); + rz_list_foreach (uniq , iter , type) { + rz_cons_println (type); } - r_list_free (uniq); + rz_list_free (uniq); } else { eprintf ("cannot find function at 0x%08"PFMT64x"\n", addr); } } break; case 0: // "tx" - r_list_foreach (core->anal->fcns, iter, fcn) { - RList *uniq = r_anal_types_from_fcn (core->anal, fcn); - if (r_list_length (uniq)) { - r_cons_printf ("%s: ", fcn->name); + rz_list_foreach (core->anal->fcns, iter, fcn) { + RzList *uniq = rz_anal_types_from_fcn (core->anal, fcn); + if (rz_list_length (uniq)) { + rz_cons_printf ("%s: ", fcn->name); } - r_list_foreach (uniq , iter2, type) { - r_cons_printf ("%s%s", type, iter2->n ? ",":"\n"); + rz_list_foreach (uniq , iter2, type) { + rz_cons_printf ("%s%s", type, iter2->n ? ",":"\n"); } } break; case 'g': // "txg" { - r_list_foreach (core->anal->fcns, iter, fcn) { - RList *uniq = r_anal_types_from_fcn (core->anal, fcn); - if (r_list_length (uniq)) { - r_cons_printf ("agn %s\n", fcn->name); + rz_list_foreach (core->anal->fcns, iter, fcn) { + RzList *uniq = rz_anal_types_from_fcn (core->anal, fcn); + if (rz_list_length (uniq)) { + rz_cons_printf ("agn %s\n", fcn->name); } - r_list_foreach (uniq , iter2, type) { + rz_list_foreach (uniq , iter2, type) { char *myType = strdup (type); - r_str_replace_ch (myType, ' ', '_', true); - r_cons_printf ("agn %s\n", myType); - r_cons_printf ("age %s %s\n", myType, fcn->name); + rz_str_replace_ch (myType, ' ', '_', true); + rz_cons_printf ("agn %s\n", myType); + rz_cons_printf ("age %s %s\n", myType, fcn->name); free (myType); } } @@ -1449,30 +1449,30 @@ static int cmd_type(void *data, const char *input) { break; case 'l': // "txl" { - RList *uniqList = r_list_newf (free); - r_list_foreach (core->anal->fcns, iter, fcn) { - RList *uniq = r_anal_types_from_fcn (core->anal, fcn); - r_list_foreach (uniq , iter2, type) { - if (!r_list_find (uniqList, type, (RListComparator)strcmp)) { - r_list_push (uniqList, strdup (type)); + RzList *uniqList = rz_list_newf (free); + rz_list_foreach (core->anal->fcns, iter, fcn) { + RzList *uniq = rz_anal_types_from_fcn (core->anal, fcn); + rz_list_foreach (uniq , iter2, type) { + if (!rz_list_find (uniqList, type, (RzListComparator)strcmp)) { + rz_list_push (uniqList, strdup (type)); } } } - r_list_sort (uniqList, (RListComparator)strcmp); - r_list_foreach (uniqList, iter, type) { - r_cons_printf ("%s\n", type); + rz_list_sort (uniqList, (RzListComparator)strcmp); + rz_list_foreach (uniqList, iter, type) { + rz_cons_printf ("%s\n", type); } - r_list_free (uniqList); + rz_list_free (uniqList); } break; case 't': case ' ': // "tx " -- show which function use given type - type = (char *)r_str_trim_head_ro (input + 2); - r_list_foreach (core->anal->fcns, iter, fcn) { - RList *uniq = r_anal_types_from_fcn (core->anal, fcn); - r_list_foreach (uniq , iter2, type2) { + type = (char *)rz_str_trim_head_ro (input + 2); + rz_list_foreach (core->anal->fcns, iter, fcn) { + RzList *uniq = rz_anal_types_from_fcn (core->anal, fcn); + rz_list_foreach (uniq , iter2, type2) { if (!strcmp (type2, type)) { - r_cons_printf ("%s\n", fcn->name); + rz_cons_printf ("%s\n", fcn->name); break; } } @@ -1508,7 +1508,7 @@ static int cmd_type(void *data, const char *input) { case 'l': // "tl" switch (input[1]) { case '?': - r_core_cmd_help (core, help_msg_tl); + rz_core_cmd_help (core, help_msg_tl); break; case ' ': { char *type = strdup (input + 2); @@ -1517,29 +1517,29 @@ static int cmd_type(void *data, const char *input) { if (ptr) { *ptr++ = 0; - r_str_trim (ptr); + rz_str_trim (ptr); if (ptr && *ptr) { - addr = r_num_math (core->num, ptr); + addr = rz_num_math (core->num, ptr); } else { eprintf ("tl: Address is unvalid\n"); free (type); break; } } - r_str_trim (type); + rz_str_trim (type); char *tmp = sdb_get (TDB, type, 0); if (tmp && *tmp) { - r_type_set_link (TDB, type, addr); - RList *fcns = r_anal_get_functions_in (core->anal, core->offset); - if (r_list_length (fcns) > 1) { + rz_type_set_link (TDB, type, addr); + RzList *fcns = rz_anal_get_functions_in (core->anal, core->offset); + if (rz_list_length (fcns) > 1) { eprintf ("Multiple functions found in here.\n"); - } else if (r_list_length (fcns) == 1) { - RAnalFunction *fcn = r_list_first (fcns); - r_core_link_stroff (core, fcn); + } else if (rz_list_length (fcns) == 1) { + RzAnalFunction *fcn = rz_list_first (fcns); + rz_core_link_stroff (core, fcn); } else { eprintf ("Cannot find any function here\n"); } - r_list_free (fcns); + rz_list_free (fcns); free (tmp); } else { eprintf ("unknown type %s\n", type); @@ -1548,8 +1548,8 @@ static int cmd_type(void *data, const char *input) { break; } case 's': { - char *ptr = r_str_trim_dup (input + 2); - ut64 addr = r_num_math (NULL, ptr); + char *ptr = rz_str_trim_dup (input + 2); + ut64 addr = rz_num_math (NULL, ptr); const char *query = sdb_fmt ("link.%08" PFMT64x, addr); const char *link = sdb_const_get (TDB, query, 0); if (link) { @@ -1565,8 +1565,8 @@ static int cmd_type(void *data, const char *input) { break; case ' ': { const char *ptr = input + 3; - ut64 addr = r_num_math (core->num, ptr); - r_type_unlink (TDB, addr); + ut64 addr = rz_num_math (core->num, ptr); + rz_type_unlink (TDB, addr); break; } } @@ -1594,13 +1594,13 @@ static int cmd_type(void *data, const char *input) { break; case 'p': // "tp" if (input[1] == '?') { // "tp?" - r_core_cmd_help (core, help_msg_tp); + rz_core_cmd_help (core, help_msg_tp); } else if (input[1] == 'v') { // "tpv" - const char *type_name = r_str_trim_head_ro (input + 2); - char *fmt = r_type_format (TDB, type_name); + const char *type_name = rz_str_trim_head_ro (input + 2); + char *fmt = rz_type_format (TDB, type_name); if (fmt && *fmt) { ut64 val = core->offset; - r_core_cmdf (core, "pf %s @v:0x%08" PFMT64x "\n", fmt, val); + rz_core_cmdf (core, "pf %s @v:0x%08" PFMT64x "\n", fmt, val); } else { eprintf ("Usage: tpv [type] @ [value]\n"); } @@ -1608,8 +1608,8 @@ static int cmd_type(void *data, const char *input) { char *tmp = strdup (input); char *type_begin = strchr (tmp, ' '); if (type_begin) { - r_str_trim (type_begin); - const char *type_end = r_str_rchr (type_begin, NULL, ' '); + rz_str_trim (type_begin); + const char *type_end = rz_str_rchr (type_begin, NULL, ' '); int type_len = (type_end) ? (int)(type_end - type_begin) : strlen (type_begin); @@ -1620,7 +1620,7 @@ static int cmd_type(void *data, const char *input) { } snprintf (type, type_len + 1, "%s", type_begin); const char *arg = (type_end) ? type_end + 1 : NULL; - char *fmt = r_type_format (TDB, type); + char *fmt = rz_type_format (TDB, type); if (!fmt) { eprintf ("Cannot find '%s' type\n", type); free (tmp); @@ -1628,24 +1628,24 @@ static int cmd_type(void *data, const char *input) { break; } if (input[1] == 'x' && arg) { // "tpx" - r_core_cmdf (core, "pf %s @x:%s", fmt, arg); + rz_core_cmdf (core, "pf %s @x:%s", fmt, arg); // eprintf ("pf %s @x:%s", fmt, arg); } else { - ut64 addr = arg ? r_num_math (core->num, arg): core->offset; + ut64 addr = arg ? rz_num_math (core->num, arg): core->offset; ut64 original_addr = addr; if (!addr && arg) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, -1); if (fcn) { - RAnalVar *var = r_anal_function_get_var_byname (fcn, arg); + RzAnalVar *var = rz_anal_function_get_var_byname (fcn, arg); if (var) { - addr = r_anal_var_addr (var); + addr = rz_anal_var_addr (var); } } } if (addr != UT64_MAX) { - r_core_cmdf (core, "pf %s @ 0x%08" PFMT64x, fmt, addr); + rz_core_cmdf (core, "pf %s @ 0x%08" PFMT64x, fmt, addr); } else if (original_addr == 0) { - r_core_cmdf (core, "pf %s @ 0x%08" PFMT64x, fmt, original_addr); + rz_core_cmdf (core, "pf %s @ 0x%08" PFMT64x, fmt, original_addr); } } free (fmt); @@ -1660,14 +1660,14 @@ static int cmd_type(void *data, const char *input) { break; case '-': // "t-" if (input[1] == '?') { - r_core_cmd_help (core, help_msg_t_minus); + rz_core_cmd_help (core, help_msg_t_minus); } else if (input[1] == '*') { sdb_reset (TDB); - r_parse_c_reset (core->parser); + rz_parse_c_reset (core->parser); } else { - const char *name = r_str_trim_head_ro (input + 1); + const char *name = rz_str_trim_head_ro (input + 1); if (*name) { - r_anal_remove_parsed_type (core->anal, name); + rz_anal_remove_parsed_type (core->anal, name); } else { eprintf ("Invalid use of t- . See t-? for help.\n"); } @@ -1687,7 +1687,7 @@ static int cmd_type(void *data, const char *input) { case 'j': // "tfj" if (input[2] == ' ') { printFunctionType (core, input + 2); - r_cons_newline (); + rz_cons_newline (); } else { print_keys (TDB, core, stdiffunc, printfunc_json_cb, true); } @@ -1695,13 +1695,13 @@ static int cmd_type(void *data, const char *input) { case ' ': { char *res = sdb_querys (TDB, NULL, -1, sdb_fmt ("~~func.%s", input + 2)); if (res) { - r_cons_printf ("%s", res); + rz_cons_printf ("%s", res); free (res); } break; } default: - r_core_cmd_help (core, help_msg_tf); + rz_core_cmd_help (core, help_msg_tf); break; } break; @@ -1722,7 +1722,7 @@ static int cmd_type(void *data, const char *input) { free (name); name = strdup (sdbkv_key (kv)); if (!input[1]) { - r_cons_println (name); + rz_cons_println (name); } else { const char *q = sdb_fmt ("typedef.%s", name); const char *res = sdb_const_get (TDB, q, 0); @@ -1735,7 +1735,7 @@ static int cmd_type(void *data, const char *input) { pj_end (pj); } if (pj) { - r_cons_printf ("%s\n", pj_string (pj)); + rz_cons_printf ("%s\n", pj_string (pj)); pj_free (pj); } free (name); @@ -1747,7 +1747,7 @@ static int cmd_type(void *data, const char *input) { SdbKv *kv; SdbListIter *iter; SdbList *l = sdb_foreach_list (TDB, true); - const char *arg = r_str_trim_head_ro (input + 2); + const char *arg = rz_str_trim_head_ro (input + 2); bool match = false; ls_foreach (l, iter, kv) { if (!strcmp (sdbkv_value (kv), "typedef")) { @@ -1764,7 +1764,7 @@ static int cmd_type(void *data, const char *input) { const char *q = sdb_fmt ("typedef.%s", name); const char *res = sdb_const_get (TDB, q, 0); if (res) { - r_cons_printf ("%s %s %s;\n", sdbkv_value (kv), res, name); + rz_cons_printf ("%s %s %s;\n", sdbkv_value (kv), res, name); } if (match) { break; @@ -1777,7 +1777,7 @@ static int cmd_type(void *data, const char *input) { break; } if (input[1] == '?') { - r_core_cmd_help (core, help_msg_tt); + rz_core_cmd_help (core, help_msg_tt); break; } char *s = strdup (input + 2); @@ -1787,7 +1787,7 @@ static int cmd_type(void *data, const char *input) { const char *q = sdb_fmt ("typedef.%s", s); const char *res = sdb_const_get (TDB, q, 0); if (res) { - r_cons_println (res); + rz_cons_println (res); } } else { eprintf ("This is not an typedef\n"); diff --git a/libr/core/cmd_write.c b/librz/core/cmd_write.c similarity index 67% rename from libr/core/cmd_write.c rename to librz/core/cmd_write.c index 9137a53aea..771a3b8ed7 100644 --- a/libr/core/cmd_write.c +++ b/librz/core/cmd_write.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include "r_crypto.h" -#include "r_config.h" -#include "r_cons.h" -#include "r_core.h" -#include "r_io.h" +#include "rz_crypto.h" +#include "rz_config.h" +#include "rz_cons.h" +#include "rz_core.h" +#include "rz_io.h" #include "cmd_helps.h" static const char *help_msg_w[] = { @@ -171,18 +171,18 @@ static const char *help_msg_wx[] = { NULL }; -static void cmd_write_fail(RCore *core) { +static void cmd_write_fail(RzCore *core) { eprintf ("Failed to write\n"); core->num->value = 1; } -R_API int cmd_write_hexpair(RCore* core, const char* pairs) { - r_return_val_if_fail (core && pairs, 0); +RZ_API int cmd_write_hexpair(RzCore* core, const char* pairs) { + rz_return_val_if_fail (core && pairs, 0); ut8 *buf = malloc (strlen (pairs) + 1); if (!buf) { return 0; } - int len = r_hex_str2bin (pairs, buf); + int len = rz_hex_str2bin (pairs, buf); if (len != 0) { if (len < 0) { len = -len; @@ -191,14 +191,14 @@ R_API int cmd_write_hexpair(RCore* core, const char* pairs) { } } core->num->value = 0; - if (!r_core_write_at (core, core->offset, buf, len)) { + if (!rz_core_write_at (core, core->offset, buf, len)) { cmd_write_fail (core); core->num->value = 1; } - if (r_config_get_i (core->config, "cfg.wseek")) { - r_core_seek_delta (core, len); + if (rz_config_get_i (core->config, "cfg.wseek")) { + rz_core_seek_delta (core, len); } - r_core_block_read (core); + rz_core_block_read (core); } else { eprintf ("Error: invalid hexpair string\n"); core->num->value = 1; @@ -207,7 +207,7 @@ R_API int cmd_write_hexpair(RCore* core, const char* pairs) { return len; } -static bool encrypt_or_decrypt_block(RCore *core, const char *algo, const char *key, int direction, const char *iv) { +static bool encrypt_or_decrypt_block(RzCore *core, const char *algo, const char *key, int direction, const char *iv) { //TODO: generalise no_key_mode for all non key encoding/decoding. int keylen = 0; bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo); @@ -217,41 +217,41 @@ static bool encrypt_or_decrypt_block(RCore *core, const char *algo, const char * keylen = strlen (key + 2); } else { binkey = (ut8 *)strdup (key); - keylen = r_hex_str2bin (key, binkey); + keylen = rz_hex_str2bin (key, binkey); } if (!no_key_mode && keylen < 1) { eprintf ("%s key not defined. Use -S [key]\n", ((!direction) ? "Encryption" : "Decryption")); free (binkey); return false; } - RCrypto *cry = r_crypto_new (); - if (r_crypto_use (cry, algo)) { + RzCrypto *cry = rz_crypto_new (); + if (rz_crypto_use (cry, algo)) { if (!binkey) { eprintf ("Cannot allocate %d byte(s)\n", keylen); - r_crypto_free (cry); + rz_crypto_free (cry); return false; } - if (r_crypto_set_key (cry, binkey, keylen, 0, direction)) { + if (rz_crypto_set_key (cry, binkey, keylen, 0, direction)) { if (iv) { ut8 *biniv = malloc (strlen (iv) + 1); - int ivlen = r_hex_str2bin (iv, biniv); + int ivlen = rz_hex_str2bin (iv, biniv); if (ivlen < 1) { ivlen = strlen(iv); strcpy ((char *)biniv, iv); } - if (!r_crypto_set_iv (cry, biniv, ivlen)) { + if (!rz_crypto_set_iv (cry, biniv, ivlen)) { eprintf ("Invalid IV.\n"); return 0; } } - r_crypto_update (cry, (const ut8*)core->block, core->blocksize); - r_crypto_final (cry, NULL, 0); + rz_crypto_update (cry, (const ut8*)core->block, core->blocksize); + rz_crypto_final (cry, NULL, 0); int result_size = 0; - ut8 *result = r_crypto_get_output (cry, &result_size); + ut8 *result = rz_crypto_get_output (cry, &result_size); if (result) { - if (!r_core_write_at (core, core->offset, result, result_size)) { - eprintf ("r_core_write_at failed at 0x%08"PFMT64x"\n", core->offset); + if (!rz_core_write_at (core, core->offset, result, result_size)) { + eprintf ("rz_core_write_at failed at 0x%08"PFMT64x"\n", core->offset); } eprintf ("Written %d byte(s)\n", result_size); free (result); @@ -260,30 +260,30 @@ static bool encrypt_or_decrypt_block(RCore *core, const char *algo, const char * eprintf ("Invalid key\n"); } free (binkey); - r_crypto_free (cry); + rz_crypto_free (cry); return 0; } else { eprintf ("Unknown %s algorithm '%s'\n", ((!direction) ? "encryption" : "decryption") ,algo); } - r_crypto_free (cry); + rz_crypto_free (cry); return 1; } -static void cmd_write_bits(RCore *core, int set, ut64 val) { +static void cmd_write_bits(RzCore *core, int set, ut64 val) { ut64 ret, orig; // used to set/unset bit in current address - r_io_read_at (core->io, core->offset, (ut8*)&orig, sizeof (orig)); + rz_io_read_at (core->io, core->offset, (ut8*)&orig, sizeof (orig)); if (set) { ret = orig | val; } else { ret = orig & (~(val)); } - if (!r_core_write_at (core, core->offset, (const ut8*)&ret, sizeof (ret))) { + if (!rz_core_write_at (core, core->offset, (const ut8*)&ret, sizeof (ret))) { cmd_write_fail (core); } } -static void cmd_write_inc(RCore *core, int size, st64 num) { +static void cmd_write_inc(RzCore *core, int size, st64 num) { ut64 *v64; ut32 *v32; ut16 *v16; @@ -295,20 +295,20 @@ static void cmd_write_inc(RCore *core, int size, st64 num) { case 8: v64 = (ut64*)core->block; *v64 += num; break; } // TODO: obey endian here - if (!r_core_write_at (core, core->offset, core->block, size)) { + if (!rz_core_write_at (core, core->offset, core->block, size)) { cmd_write_fail (core); } } static int wo_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut8 *buf; int len; int value; switch (input[0]) { case 'e': if (input[1]!=' ') { - r_cons_printf ("Usage: 'woe from-to step'\n"); + rz_cons_printf ("Usage: 'woe from-to step'\n"); return -1; } /* fallthru */ @@ -326,18 +326,18 @@ static int wo_handler_old(void *data, const char *input) { case '4': // "wo4" case '8': // "wo8" if (input[1]) { // parse val from arg - r_core_write_op (core, input + 2, input[0]); + rz_core_write_op (core, input + 2, input[0]); } else { // use clipboard instead of val - r_core_write_op (core, NULL, input[0]); + rz_core_write_op (core, NULL, input[0]); } - r_core_block_read (core); + rz_core_block_read (core); break; case 'R': - r_core_cmd0 (core, "wr $b"); + rz_core_cmd0 (core, "wr $b"); break; case 'n': - r_core_write_op (core, "ff", 'x'); - r_core_block_read (core); + rz_core_write_op (core, "ff", 'x'); + rz_core_block_read (core); break; case 'E': // "woE" encrypt case 'D': // "woD" decrypt @@ -346,7 +346,7 @@ static int wo_handler_old(void *data, const char *input) { const char *algo = NULL; const char *key = NULL; const char *iv = NULL; - char *space, *args = strdup (r_str_trim_head_ro (input+1)); + char *space, *args = strdup (rz_str_trim_head_ro (input+1)); space = strchr (args, ' '); if (space) { *space++ = 0; @@ -367,7 +367,7 @@ static int wo_handler_old(void *data, const char *input) { int i; for (i = 0; ; i++) { bits = ((ut64)1) << i; - const char *name = r_hash_name (bits); + const char *name = rz_hash_name (bits); if R_STR_ISEMPTY (name) { break; } @@ -376,7 +376,7 @@ static int wo_handler_old(void *data, const char *input) { eprintf ("Available Encoders/Decoders: \n"); for (i = 0; ; i++) { bits = (1ULL) << i; - const char *name = r_crypto_codec_name ((const RCryptoSelector)bits); + const char *name = rz_crypto_codec_name ((const RzCryptoSelector)bits); if (R_STR_ISEMPTY (name)) { break; } @@ -385,7 +385,7 @@ static int wo_handler_old(void *data, const char *input) { eprintf ("Currently supported crypto algos:\n"); for (i = 0; ; i++) { bits = (1ULL) << i; - const char *name = r_crypto_name ((const RCryptoSelector)bits); + const char *name = rz_crypto_name ((const RzCryptoSelector)bits); if R_STR_ISEMPTY (name) { break; } @@ -400,23 +400,23 @@ static int wo_handler_old(void *data, const char *input) { case 'D': // "wopD" { char *sp = strchr (input, ' '); - len = sp? r_num_math (core->num, sp + 1): core->blocksize; + len = sp? rz_num_math (core->num, sp + 1): core->blocksize; } if (len > 0) { /* XXX This seems to fail at generating long patterns (wopD 512K) */ - buf = (ut8*)r_debruijn_pattern (len, 0, NULL); //debruijn_charset); + buf = (ut8*)rz_debruijn_pattern (len, 0, NULL); //debruijn_charset); if (buf) { const ut8 *ptr = buf; ut64 addr = core->offset; if (input[2] == '*') { int i; - r_cons_printf ("wx "); + rz_cons_printf ("wx "); for (i = 0; i < len; i++) { - r_cons_printf ("%02x", buf[i]); + rz_cons_printf ("%02x", buf[i]); } - r_cons_newline (); + rz_cons_newline (); } else { - if (!r_core_write_at (core, addr, ptr, len)) { + if (!rz_core_write_at (core, addr, ptr, len)) { cmd_write_fail (core); } } @@ -430,40 +430,40 @@ static int wo_handler_old(void *data, const char *input) { if (strlen (input) > 3 && strncmp (input + 3, "0x", 2)) { eprintf ("Need hex value with `0x' prefix e.g. 0x41414142\n"); } else if (input[2] == ' ') { - value = r_num_get (core->num, input + 3); - core->num->value = r_debruijn_offset (value, r_config_get_i (core->config, "cfg.bigendian")); - r_cons_printf ("%"PFMT64d"\n", core->num->value); + value = rz_num_get (core->num, input + 3); + core->num->value = rz_debruijn_offset (value, rz_config_get_i (core->config, "cfg.bigendian")); + rz_cons_printf ("%"PFMT64d"\n", core->num->value); } break; case '\0': case '?': default: - r_core_cmd_help (core, help_msg_wop); + rz_core_cmd_help (core, help_msg_wop); break; } break; case '\0': case '?': default: - r_core_cmd_help (core, help_msg_wo); + rz_core_cmd_help (core, help_msg_wo); break; } return 0; } -#define WSEEK(x,y) if (wseek)r_core_seek_delta (x,y) -static void cmd_write_value(RCore *core, const char *input) { +#define WSEEK(x,y) if (wseek)rz_core_seek_delta (x,y) +static void cmd_write_value(RzCore *core, const char *input) { int type = 0; ut64 off = 0LL; ut8 buf[sizeof(ut64)]; - int wseek = r_config_get_i (core->config, "cfg.wseek"); - bool be = r_config_get_i (core->config, "cfg.bigendian"); + int wseek = rz_config_get_i (core->config, "cfg.wseek"); + bool be = rz_config_get_i (core->config, "cfg.bigendian"); core->num->value = 0; switch (input[0]) { case '?': - r_core_cmd_help (core, help_msg_wv); + rz_core_cmd_help (core, help_msg_wv); return; case '1': type = 1; break; case '2': type = 2; break; @@ -471,69 +471,69 @@ static void cmd_write_value(RCore *core, const char *input) { case '8': type = 8; break; } if (input[0] && input[1]) { - off = r_num_math (core->num, input+1); + off = rz_num_math (core->num, input+1); } if (core->file) { - r_io_use_fd (core->io, core->file->fd); + rz_io_use_fd (core->io, core->file->fd); } - ut64 res = r_io_seek (core->io, core->offset, R_IO_SEEK_SET); + ut64 res = rz_io_seek (core->io, core->offset, R_IO_SEEK_SET); if (res == UT64_MAX) return; if (type == 0) type = (off&UT64_32U)? 8: 4; switch (type) { case 1: - r_write_ble8 (buf, (ut8)(off & UT8_MAX)); - if (!r_io_write (core->io, buf, 1)) { + rz_write_ble8 (buf, (ut8)(off & UT8_MAX)); + if (!rz_io_write (core->io, buf, 1)) { cmd_write_fail (core); } else { WSEEK (core, 1); } break; case 2: - r_write_ble16 (buf, (ut16)(off & UT16_MAX), be); - if (!r_io_write (core->io, buf, 2)) { + rz_write_ble16 (buf, (ut16)(off & UT16_MAX), be); + if (!rz_io_write (core->io, buf, 2)) { cmd_write_fail (core); } else { WSEEK (core, 2); } break; case 4: - r_write_ble32 (buf, (ut32)(off & UT32_MAX), be); - if (!r_io_write (core->io, buf, 4)) { + rz_write_ble32 (buf, (ut32)(off & UT32_MAX), be); + if (!rz_io_write (core->io, buf, 4)) { cmd_write_fail (core); } else { WSEEK (core, 4); } break; case 8: - r_write_ble64 (buf, off, be); - if (!r_io_write (core->io, buf, 8)) { + rz_write_ble64 (buf, off, be); + if (!rz_io_write (core->io, buf, 8)) { cmd_write_fail (core); } else { WSEEK (core, 8); } break; } - r_core_block_read (core); + rz_core_block_read (core); } -static RCmdStatus common_wv_handler(RCore *core, int argc, const char **argv, int type) { +static RzCmdStatus common_wv_handler(RzCore *core, int argc, const char **argv, int type) { ut64 off = 0LL; ut8 buf[sizeof(ut64)]; - int wseek = r_config_get_i (core->config, "cfg.wseek"); - bool be = r_config_get_i (core->config, "cfg.bigendian"); + int wseek = rz_config_get_i (core->config, "cfg.wseek"); + bool be = rz_config_get_i (core->config, "cfg.bigendian"); core->num->value = 0; if (argc != 2) { return R_CMD_STATUS_WRONG_ARGS; } - off = r_num_math (core->num, argv[1]); + off = rz_num_math (core->num, argv[1]); if (core->file) { - r_io_use_fd (core->io, core->file->fd); + rz_io_use_fd (core->io, core->file->fd); } - ut64 res = r_io_seek (core->io, core->offset, R_IO_SEEK_SET); + ut64 res = rz_io_seek (core->io, core->offset, R_IO_SEEK_SET); if (res == UT64_MAX) { return R_CMD_STATUS_ERROR; } @@ -543,56 +543,56 @@ static RCmdStatus common_wv_handler(RCore *core, int argc, const char **argv, in switch (type) { case 1: - r_write_ble8 (buf, (ut8)(off & UT8_MAX)); + rz_write_ble8 (buf, (ut8)(off & UT8_MAX)); break; case 2: - r_write_ble16 (buf, (ut16)(off & UT16_MAX), be); + rz_write_ble16 (buf, (ut16)(off & UT16_MAX), be); break; case 4: - r_write_ble32 (buf, (ut32)(off & UT32_MAX), be); + rz_write_ble32 (buf, (ut32)(off & UT32_MAX), be); break; case 8: - r_write_ble64 (buf, off, be); + rz_write_ble64 (buf, off, be); break; } - if (!r_io_write (core->io, buf, type)) { + if (!rz_io_write (core->io, buf, type)) { cmd_write_fail (core); } else if (wseek) { - r_core_seek_delta (core, type); + rz_core_seek_delta (core, type); } - r_core_block_read (core); + rz_core_block_read (core); return R_CMD_STATUS_OK; } -static RCmdStatus wv_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wv_handler(RzCore *core, int argc, const char **argv) { return common_wv_handler (core, argc, argv, 0); } -static RCmdStatus wv1_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wv1_handler(RzCore *core, int argc, const char **argv) { return common_wv_handler (core, argc, argv, 1); } -static RCmdStatus wv2_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wv2_handler(RzCore *core, int argc, const char **argv) { return common_wv_handler (core, argc, argv, 2); } -static RCmdStatus wv4_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wv4_handler(RzCore *core, int argc, const char **argv) { return common_wv_handler (core, argc, argv, 4); } -static RCmdStatus wv8_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wv8_handler(RzCore *core, int argc, const char **argv) { return common_wv_handler (core, argc, argv, 8); } -static bool cmd_wff(RCore *core, const char *input) { +static bool cmd_wff(RzCore *core, const char *input) { ut8 *buf; size_t size; // XXX: file names cannot contain spaces const char *arg = input + ((input[0] == ' ') ? 1 : 0); - int wseek = r_config_get_i (core->config, "cfg.wseek"); - char *p, *a = r_str_trim_dup (arg); + int wseek = rz_config_get_i (core->config, "cfg.wseek"); + char *p, *a = rz_str_trim_dup (arg); p = strchr (a, ' '); if (p) { *p++ = 0; @@ -602,56 +602,56 @@ static bool cmd_wff(RCore *core, const char *input) { eprintf ("Usage: wf [file] ([size] ([offset]))\n"); } if (!strcmp (arg, "-")) { - char *out = r_core_editor (core, NULL, NULL); + char *out = rz_core_editor (core, NULL, NULL); if (out) { - if (!r_io_write_at (core->io, core->offset, + if (!rz_io_write_at (core->io, core->offset, (ut8*)out, strlen (out))) { - eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); + eprintf ("rz_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); } - r_core_block_read (core); + rz_core_block_read (core); free (out); } } - if ((buf = (ut8*) r_file_slurp (a, &size))) { + if ((buf = (ut8*) rz_file_slurp (a, &size))) { int u_offset = 0; - ut64 u_size = r_num_math (core->num, p); + ut64 u_size = rz_num_math (core->num, p); if (u_size < 1) u_size = (ut64)size; if (p) { *p++ = 0; - u_offset = r_num_math (core->num, p); + u_offset = rz_num_math (core->num, p); if (u_offset > size) { eprintf ("Invalid offset\n"); free (buf); return false; } } - r_io_use_fd (core->io, core->file->fd); - if (!r_io_write_at (core->io, core->offset, buf + u_offset, (int)u_size)) { - eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); + rz_io_use_fd (core->io, core->file->fd); + if (!rz_io_write_at (core->io, core->offset, buf + u_offset, (int)u_size)) { + eprintf ("rz_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); } WSEEK (core, size); free (buf); - r_core_block_read (core); + rz_core_block_read (core); } else { eprintf ("Cannot open file '%s'\n", arg); } return true; } -static bool ioMemcpy (RCore *core, ut64 dst, ut64 src, int len) { +static bool ioMemcpy (RzCore *core, ut64 dst, ut64 src, int len) { bool ret = false; if (len > 0) { ut8 * buf = calloc (1, len); if (buf) { - if (r_io_read_at (core->io, src, buf, len)) { - if (r_io_write_at (core->io, dst, buf, len)) { - r_core_block_read (core); + if (rz_io_read_at (core->io, src, buf, len)) { + if (rz_io_write_at (core->io, dst, buf, len)) { + rz_core_block_read (core); ret = true; } else { - eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", dst); + eprintf ("rz_io_write_at failed at 0x%08"PFMT64x"\n", dst); } } else { - eprintf ("r_io_read_at failed at 0x%08"PFMT64x"\n", src); + eprintf ("rz_io_read_at failed at 0x%08"PFMT64x"\n", src); } free (buf); } @@ -659,24 +659,24 @@ static bool ioMemcpy (RCore *core, ut64 dst, ut64 src, int len) { return ret; } -static bool cmd_wfx(RCore *core, const char *input) { - char * args = r_str_trim_dup (input); +static bool cmd_wfx(RzCore *core, const char *input) { + char * args = rz_str_trim_dup (input); char *arg = strchr (args, ' '); int len = core->blocksize; if (arg) { *arg = 0; - len = r_num_math (core->num, arg + 1); + len = rz_num_math (core->num, arg + 1); } ut64 dst = core->offset; - ut64 src = r_num_math (core->num, args); + ut64 src = rz_num_math (core->num, args); if (len > 0) { // cache dest, memcpy, write cache ut8 *buf = calloc (1, len); if (buf) { - if (r_io_read_at (core->io, dst, buf, len)) { + if (rz_io_read_at (core->io, dst, buf, len)) { ioMemcpy (core, core->offset, src, len); - if (r_io_write_at (core->io, src, buf, len)) { - r_core_block_read (core); + if (rz_io_write_at (core->io, src, buf, len)) { + rz_core_block_read (core); } else { eprintf ("Failed to write at 0x%08"PFMT64x"\n", src); } @@ -690,7 +690,7 @@ static bool cmd_wfx(RCore *core, const char *input) { return true; } -static bool cmd_wfs(RCore *core, const char *input) { +static bool cmd_wfs(RzCore *core, const char *input) { char *str = strdup (input); if (str[0] != ' ') { eprintf ("Usage wfs host:port [sz]\n"); @@ -710,7 +710,7 @@ static bool cmd_wfs(RCore *core, const char *input) { char *space = strchr (port, ' '); if (space) { *space++ = 0; - sz = r_num_math (core->num, space); + sz = rz_num_math (core->num, space); addr = core->offset; } ut8 *buf = calloc (1, sz); @@ -718,48 +718,48 @@ static bool cmd_wfs(RCore *core, const char *input) { free (str); return false; } - r_io_read_at (core->io, addr, buf, sz); - RSocket *s = r_socket_new (false); - if (!r_socket_listen (s, port, NULL)) { + rz_io_read_at (core->io, addr, buf, sz); + RzSocket *s = rz_socket_new (false); + if (!rz_socket_listen (s, port, NULL)) { eprintf ("Cannot listen on port %s\n", port); - r_socket_free (s); + rz_socket_free (s); free (str); free (buf); return false; } int done = 0; - RSocket *c = r_socket_accept (s); + RzSocket *c = rz_socket_accept (s); if (c) { eprintf ("Receiving data from client...\n"); while (done < sz) { - int rc = r_socket_read (c, buf + done, sz - done); + int rc = rz_socket_read (c, buf + done, sz - done); if (rc < 1) { eprintf ("oops\n"); break; } done += rc; } - r_socket_free (c); - if (r_io_write_at (core->io, core->offset, buf, done)) { + rz_socket_free (c); + if (rz_io_write_at (core->io, core->offset, buf, done)) { eprintf ("Written %d bytes\n", done); } else { eprintf ("Cannot write\n"); } } - r_socket_free (s); + rz_socket_free (s); free (buf); free (str); return true; } static int wf_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (!core || !*input) { return -1; } if (input[0] == '?') { eprintf ("Usage: wf [file] ([size] ([offset]))\n"); - r_core_cmd_help (core, help_msg_wf); + rz_core_cmd_help (core, help_msg_wf); return -1; } if (input[0] == 's') { // "wfs" @@ -771,64 +771,64 @@ static int wf_handler_old(void *data, const char *input) { if (input[0] == 'f') { // "wff" return cmd_wff (core, input + 1); } - char *args = r_str_trim_dup (input); + char *args = rz_str_trim_dup (input); char *arg = strchr (args, ' '); int len = core->blocksize; if (arg) { *arg++ = 0; - len = r_num_math (core->num, arg); + len = rz_num_math (core->num, arg); } - ut64 addr = r_num_math (core->num, args); + ut64 addr = rz_num_math (core->num, args); ioMemcpy (core, core->offset, addr, len); free (args); - r_core_block_read (core); + rz_core_block_read (core); return 0; } -static void cmd_write_pcache(RCore *core, const char *input) { - RIODesc *desc; - RIOCache *c; - RList *caches; - RListIter *iter; +static void cmd_write_pcache(RzCore *core, const char *input) { + RzIODesc *desc; + RzIOCache *c; + RzList *caches; + RzListIter *iter; int fd, i; bool rad = false; if (core && core->io && core->io->p_cache && core->print && core->print->cb_printf) { switch (input[0]) { case 'i' : if (input[1]) { - fd = (int)r_num_math (core->num, input + 1); - desc = r_io_desc_get (core->io, fd); + fd = (int)rz_num_math (core->num, input + 1); + desc = rz_io_desc_get (core->io, fd); } else { desc = core->io->desc; } - r_io_desc_cache_commit (desc); + rz_io_desc_cache_commit (desc); break; case '*': rad = true; case ' ': //fall-o-through case '\0': if (input[0] && input[1]) { - fd = (int)r_num_math (core->num, input + 1); - desc = r_io_desc_get (core->io, fd); + fd = (int)rz_num_math (core->num, input + 1); + desc = rz_io_desc_get (core->io, fd); } else { desc = core->io->desc; } - if ((caches = r_io_desc_cache_list (desc))) { + if ((caches = rz_io_desc_cache_list (desc))) { if (rad) { core->print->cb_printf ("e io.va = false\n"); - r_list_foreach (caches, iter, c) { + rz_list_foreach (caches, iter, c) { core->print->cb_printf ("wx %02x", c->data[0]); - const int cacheSize = r_itv_size (c->itv); + const int cacheSize = rz_itv_size (c->itv); for (i = 1; i < cacheSize; i++) { core->print->cb_printf ("%02x", c->data[i]); } - core->print->cb_printf (" @ 0x%08"PFMT64x" \n", r_itv_begin (c->itv)); + core->print->cb_printf (" @ 0x%08"PFMT64x" \n", rz_itv_begin (c->itv)); } } else { - r_list_foreach (caches, iter, c) { + rz_list_foreach (caches, iter, c) { core->print->cb_printf ("0x%08"PFMT64x": %02x", - r_itv_begin (c->itv), c->odata[0]); - const int cacheSize = r_itv_size (c->itv); + rz_itv_begin (c->itv), c->odata[0]); + const int cacheSize = rz_itv_size (c->itv); for (i = 1; i < cacheSize; i++) { core->print->cb_printf ("%02x", c->odata[i]); } @@ -839,7 +839,7 @@ static void cmd_write_pcache(RCore *core, const char *input) { core->print->cb_printf ("\n"); } } - r_list_free (caches); + rz_list_free (caches); } break; default: @@ -849,13 +849,13 @@ static void cmd_write_pcache(RCore *core, const char *input) { } static int wB_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (input[0]) { case ' ': - cmd_write_bits (core, 1, r_num_math (core->num, input + 1)); + cmd_write_bits (core, 1, rz_num_math (core->num, input + 1)); break; case '-': - cmd_write_bits (core, 0, r_num_math (core->num, input + 1)); + cmd_write_bits (core, 0, rz_num_math (core->num, input + 1)); break; default: eprintf ("Usage: wB 0x2000 # or wB-0x2000\n"); @@ -864,32 +864,32 @@ static int wB_handler_old(void *data, const char *input) { return 0; } -static RCmdStatus wB_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wB_handler(RzCore *core, int argc, const char **argv) { if (argc != 2) { return R_CMD_STATUS_WRONG_ARGS; } - cmd_write_bits (core, 1, r_num_math (core->num, argv[1])); + cmd_write_bits (core, 1, rz_num_math (core->num, argv[1])); return R_CMD_STATUS_OK; } -static RCmdStatus wB_minus_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus wB_minus_handler(RzCore *core, int argc, const char **argv) { if (argc != 2) { return R_CMD_STATUS_WRONG_ARGS; } - cmd_write_bits (core, 0, r_num_math (core->num, argv[1])); + cmd_write_bits (core, 0, rz_num_math (core->num, argv[1])); return R_CMD_STATUS_OK; } -static int w0_handler_common(RCore *core, ut64 len) { +static int w0_handler_common(RzCore *core, ut64 len) { int res = 0; if (len > 0) { ut8 *buf = calloc (1, len); if (buf) { - if (!r_io_write_at (core->io, core->offset, buf, len)) { - eprintf ("r_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); + if (!rz_io_write_at (core->io, core->offset, buf, len)) { + eprintf ("rz_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); res = -1; } - r_core_block_read (core); + rz_core_block_read (core); free (buf); } else { eprintf ("Cannot allocate %d byte(s)\n", (int)len); @@ -900,24 +900,24 @@ static int w0_handler_common(RCore *core, ut64 len) { } static int w0_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - ut64 len = r_num_math (core->num, input); + RzCore *core = (RzCore *)data; + ut64 len = rz_num_math (core->num, input); return w0_handler_common (core, len); } -static RCmdStatus w0_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w0_handler(RzCore *core, int argc, const char **argv) { if (argc != 2) { return R_CMD_STATUS_WRONG_ARGS; } - ut64 len = r_num_math (core->num, argv[1]); - return r_cmd_int2status (w0_handler_common (core, len)); + ut64 len = rz_num_math (core->num, argv[1]); + return rz_cmd_int2status (w0_handler_common (core, len)); } static int w_incdec_handler_old(void *data, const char *input, int inc) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; st64 num = 1; if (input[0] && input[1]) { - num = r_num_math (core->num, input + 1); + num = rz_num_math (core->num, input + 1); } switch (input[0]) { case '+': @@ -932,11 +932,11 @@ static int w_incdec_handler_old(void *data, const char *input, int inc) { return 0; } -static RCmdStatus w_incdec_handler(RCore *core, int argc, const char **argv, int inc_size) { +static RzCmdStatus w_incdec_handler(RzCore *core, int argc, const char **argv, int inc_size) { if (argc > 2) { return R_CMD_STATUS_WRONG_ARGS; } - st64 num = argc > 1? r_num_math (core->num, argv[1]): 1; + st64 num = argc > 1? rz_num_math (core->num, argv[1]): 1; const char *command = argv[0]; if (command[strlen (command) - 1] == '-') { num *= -1; @@ -945,25 +945,25 @@ static RCmdStatus w_incdec_handler(RCore *core, int argc, const char **argv, int return R_CMD_STATUS_OK; } -static RCmdStatus w1_incdec_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w1_incdec_handler(RzCore *core, int argc, const char **argv) { return w_incdec_handler (core, argc, argv, 1); } -static RCmdStatus w2_incdec_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w2_incdec_handler(RzCore *core, int argc, const char **argv) { return w_incdec_handler (core, argc, argv, 2); } -static RCmdStatus w4_incdec_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w4_incdec_handler(RzCore *core, int argc, const char **argv) { return w_incdec_handler (core, argc, argv, 4); } -static RCmdStatus w8_incdec_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w8_incdec_handler(RzCore *core, int argc, const char **argv) { return w_incdec_handler (core, argc, argv, 8); } static int w6_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); int fail = 0; ut8 *buf = NULL; int len = 0, str_len; @@ -985,7 +985,7 @@ static int w6_handler_old(void *data, const char *input) { eprintf ("Error: failed to malloc memory"); break; } - len = r_base64_decode (buf, str, -1); + len = rz_base64_decode (buf, str, -1); if (len < 0) { free (buf); fail = 1; @@ -997,12 +997,12 @@ static int w6_handler_old(void *data, const char *input) { eprintf ("Error: failed to malloc memory"); break; } - const int bin_len = r_hex_str2bin (str, bin_buf); + const int bin_len = rz_hex_str2bin (str, bin_buf); if (bin_len <= 0) { fail = 1; } else { buf = calloc (str_len + 1, 4); - len = r_base64_encode ((char *)buf, bin_buf, bin_len); + len = rz_base64_encode ((char *)buf, bin_buf, bin_len); if(len == 0) { free (buf); fail = 1; @@ -1017,11 +1017,11 @@ static int w6_handler_old(void *data, const char *input) { } } if (!fail) { - if (!r_core_write_at (core, core->offset, buf, len)) { + if (!rz_core_write_at (core, core->offset, buf, len)) { cmd_write_fail (core); } WSEEK (core, len); - r_core_block_read (core); + rz_core_block_read (core); free (buf); } else { eprintf ("Usage: w6[de] base64/hex\n"); @@ -1034,9 +1034,9 @@ static int wh_handler_old(void *data, const char *input) { if (p) { while (*p == ' ') p++; - p = r_file_path (p); + p = rz_file_path (p); if (p) { - r_cons_println (p); + rz_cons_println (p); free (p); } } @@ -1044,7 +1044,7 @@ static int wh_handler_old(void *data, const char *input) { } static int we_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; ut64 addr = 0, len = 0, b_size = 0; st64 dist = 0; ut8* bytes = NULL; @@ -1054,15 +1054,15 @@ static int we_handler_old(void *data, const char *input) { switch (input[0]) { case 'n': // "wen" if (input[1] == ' ') { - len = *input ? r_num_math (core->num, input + 2) : 0; + len = *input ? rz_num_math (core->num, input + 2) : 0; if (len > 0) { const ut64 cur_off = core->offset; - cmd_suc = r_core_extend_at (core, core->offset, len); + cmd_suc = rz_core_extend_at (core, core->offset, len); if (cmd_suc) { core->offset = cur_off; - r_core_block_read (core); + rz_core_block_read (core); } else { - eprintf ("r_io_extend failed\n"); + eprintf ("rz_io_extend failed\n"); cmd_suc = true; } } @@ -1075,19 +1075,19 @@ static int we_handler_old(void *data, const char *input) { if (input[1] == ' ') { input += 2; while (*input && *input == ' ') input++; - addr = r_num_math (core->num, input); + addr = rz_num_math (core->num, input); while (*input && *input != ' ') input++; input++; - len = *input ? r_num_math (core->num, input) : 0; + len = *input ? rz_num_math (core->num, input) : 0; if (len > 0){ ut64 cur_off = core->offset; - cmd_suc = r_core_extend_at (core, addr, len); + cmd_suc = rz_core_extend_at (core, addr, len); if (cmd_suc) { - r_core_seek (core, cur_off, true); + rz_core_seek (core, cur_off, true); core->offset = addr; - r_core_block_read (core); + rz_core_block_read (core); } else { - eprintf ("r_io_extend failed\n"); + eprintf ("rz_io_extend failed\n"); } } cmd_suc = true; @@ -1098,17 +1098,17 @@ static int we_handler_old(void *data, const char *input) { input += 1; len = *input ? strlen (input) : 0; bytes = len > 1? malloc (len+1) : NULL; - len = bytes ? r_hex_str2bin (input, bytes) : 0; + len = bytes ? rz_hex_str2bin (input, bytes) : 0; if (len > 0) { ut64 cur_off = core->offset; - cmd_suc = r_core_extend_at (core, cur_off, len); + cmd_suc = rz_core_extend_at (core, cur_off, len); if (cmd_suc) { - if (!r_core_write_at (core, cur_off, bytes, len)) { + if (!rz_core_write_at (core, cur_off, bytes, len)) { cmd_write_fail (core); } } core->offset = cur_off; - r_core_block_read (core); + rz_core_block_read (core); } free (bytes); } @@ -1121,21 +1121,21 @@ static int we_handler_old(void *data, const char *input) { len = strlen (input); // since the distance can be negative, - // the r_num_math will perform an unwanted operation + // the rz_num_math will perform an unwanted operation // the solution is to tokenize the string :/ if (len > 0) { input_shadow = strdup (input); p = strtok (input_shadow, " "); - addr = p && *p ? r_num_math (core->num, p) : 0; + addr = p && *p ? rz_num_math (core->num, p) : 0; p = strtok (NULL, " "); - dist = p && *p ? r_num_math (core->num, p) : 0; + dist = p && *p ? rz_num_math (core->num, p) : 0; p = strtok (NULL, " "); - b_size = p && *p ? r_num_math (core->num, p) : 0; + b_size = p && *p ? rz_num_math (core->num, p) : 0; if (dist != 0){ - r_core_shift_block (core, addr, b_size, dist); - r_core_seek (core, addr, true); + rz_core_shift_block (core, addr, b_size, dist); + rz_core_seek (core, addr, true); cmd_suc = true; } } @@ -1143,25 +1143,25 @@ static int we_handler_old(void *data, const char *input) { break; case 'X': // "weX" if (input[1] == ' ') { - addr = r_num_math (core->num, input+2); + addr = rz_num_math (core->num, input+2); input += 2; while (*input && *input != ' ') input++; input++; len = *input ? strlen (input) : 0; bytes = len > 1? malloc (len+1) : NULL; - len = bytes ? r_hex_str2bin (input, bytes) : 0; + len = bytes ? rz_hex_str2bin (input, bytes) : 0; if (len > 0) { //ut64 cur_off = core->offset; - cmd_suc = r_core_extend_at (core, addr, len); + cmd_suc = rz_core_extend_at (core, addr, len); if (cmd_suc) { - if (!r_core_write_at (core, addr, bytes, len)) { + if (!rz_core_write_at (core, addr, bytes, len)) { cmd_write_fail (core); } } else { - eprintf ("r_io_extend failed\n"); + eprintf ("rz_io_extend failed\n"); } core->offset = addr; - r_core_block_read (core); + rz_core_block_read (core); } free (bytes); } @@ -1172,37 +1172,37 @@ static int we_handler_old(void *data, const char *input) { break; } if (cmd_suc == false) { - r_core_cmd_help (core, help_msg_we); + rz_core_cmd_help (core, help_msg_we); } return 0; } static int wp_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input[0] == '-' || (input[0] == ' ' && input[1] == '-')) { - char *out = r_core_editor (core, NULL, NULL); + char *out = rz_core_editor (core, NULL, NULL); if (out) { - r_core_patch (core, out); + rz_core_patch (core, out); free (out); } } else { if (input[0] == ' ' && input[1]) { - char *data = r_file_slurp (input + 1, NULL); + char *data = rz_file_slurp (input + 1, NULL); if (data) { - r_core_patch (core, data); + rz_core_patch (core, data); free (data); } } else { - r_core_cmd_help (core, help_msg_wp); + rz_core_cmd_help (core, help_msg_wp); } } return 0; } static int wu_handler_old(void *data, const char *input) { - // TODO: implement it in an API RCore.write_unified_hexpatch() is ETOOLONG + // TODO: implement it in an API RzCore.write_unified_hexpatch() is ETOOLONG if (input[0]==' ') { - char *data = r_file_slurp (input+1, NULL); + char *data = rz_file_slurp (input+1, NULL); if (data) { int i; char sign = ' '; @@ -1238,7 +1238,7 @@ static int wu_handler_old(void *data, const char *input) { hexa = 0; } else if (sign) { if (offs && hexa) { - r_cons_printf ("wx %s @ %s\n", data+hexa, data+offs); + rz_cons_printf ("wx %s @ %s\n", data+hexa, data+offs); } else eprintf ("food\n"); offs = 0; line = 0; @@ -1257,18 +1257,18 @@ static int wu_handler_old(void *data, const char *input) { } static int wr_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); - ut64 off = r_num_math (core->num, input); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); + ut64 off = rz_num_math (core->num, input); int len = (int)off; if (len > 0) { ut8 *buf = malloc (len); if (buf != NULL) { int i; - r_num_irand (); + rz_num_irand (); for (i = 0; i < len; i++) - buf[i] = r_num_rand (256); - if (!r_core_write_at (core, core->offset, buf, len)) { + buf[i] = rz_num_rand (256); + if (!rz_core_write_at (core, core->offset, buf, len)) { cmd_write_fail (core); } WSEEK (core, len); @@ -1280,60 +1280,60 @@ static int wr_handler_old(void *data, const char *input) { } static int wA_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); int len; switch (input[0]) { case ' ': if (input[1] && input[2] == ' ') { - r_asm_set_pc (core->rasm, core->offset); + rz_asm_set_pc (core->rasm, core->offset); eprintf ("modify (%c)=%s\n", input[1], input + 3); - len = r_asm_modify (core->rasm, core->block, input[1], - r_num_math (core->num, input + 3)); + len = rz_asm_modify (core->rasm, core->block, input[1], + rz_num_math (core->num, input + 3)); eprintf ("len=%d\n", len); if (len > 0) { - if (!r_core_write_at (core, core->offset, core->block, len)) { + if (!rz_core_write_at (core, core->offset, core->block, len)) { cmd_write_fail (core); } WSEEK (core, len); } else - eprintf ("r_asm_modify = %d\n", len); + eprintf ("rz_asm_modify = %d\n", len); } else eprintf ("Usage: wA [type] [value]\n"); break; case '?': default: - r_core_cmd_help (core, help_msg_wA); + rz_core_cmd_help (core, help_msg_wA); break; } return 0; } static int wc_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (input[0]) { case '\0': // "wc" - //if (!r_config_get_i (core->config, "io.cache")) + //if (!rz_config_get_i (core->config, "io.cache")) // eprintf ("[warning] e io.cache must be true\n"); - r_io_cache_list (core->io, 0); + rz_io_cache_list (core->io, 0); break; case '?': // "wc?" - r_core_cmd_help (core, help_msg_wc); + rz_core_cmd_help (core, help_msg_wc); break; case '*': // "wc*" - r_io_cache_list (core->io, 1); + rz_io_cache_list (core->io, 1); break; case '+': // "wc+" if (input[1]=='*') { // "wc+*" - //r_io_cache_reset (core->io, core->io->cached); + //rz_io_cache_reset (core->io, core->io->cached); eprintf ("TODO\n"); } else if (input[1]==' ') { // "wc+ " char *p = strchr (input+2, ' '); ut64 to, from; - from = r_num_math (core->num, input+2); + from = rz_num_math (core->num, input+2); if (p) { *p = 0; - to = r_num_math (core->num, input+2); + to = rz_num_math (core->num, input+2); if (toto)\n"); return 0; @@ -1341,15 +1341,15 @@ static int wc_handler_old(void *data, const char *input) { } else { to = from + core->blocksize; } - r_io_cache_commit (core->io, from, to); + rz_io_cache_commit (core->io, from, to); } else { eprintf ("Invalidate write cache at 0x%08"PFMT64x"\n", core->offset); - r_io_cache_commit (core->io, core->offset, core->offset+1); + rz_io_cache_commit (core->io, core->offset, core->offset+1); } break; case '-': { // "wc-" if (input[1]=='*') { // "wc-*" - r_io_cache_reset (core->io, core->io->cached); + rz_io_cache_reset (core->io, core->io->cached); break; } ut64 from, to; @@ -1357,14 +1357,14 @@ static int wc_handler_old(void *data, const char *input) { char *p = strchr (input+2, ' '); if (p) { *p = 0; - from = r_num_math (core->num, input+2); - to = r_num_math (core->num, p+1); + from = rz_num_math (core->num, input+2); + to = rz_num_math (core->num, p+1); if (to < from) { eprintf ("Invalid range (from>to)\n"); return 0; } } else { - from = r_num_math (core->num, input+2); + from = rz_num_math (core->num, input+2); to = from + core->blocksize; } } else { @@ -1373,67 +1373,67 @@ static int wc_handler_old(void *data, const char *input) { to = core->offset + core->blocksize; } eprintf("invalidated %d cache(s)\n", - r_io_cache_invalidate (core->io, from, to)); - r_core_block_read (core); + rz_io_cache_invalidate (core->io, from, to)); + rz_core_block_read (core); break; } case 'i': // "wci" - r_io_cache_commit (core->io, 0, UT64_MAX); - r_core_block_read (core); + rz_io_cache_commit (core->io, 0, UT64_MAX); + rz_core_block_read (core); break; case 'j': // "wcj" - r_io_cache_list (core->io, 2); + rz_io_cache_list (core->io, 2); break; case 'p': // "wcp" cmd_write_pcache (core, &input[1]); break; case 'r': // "wcr" - r_io_cache_reset (core->io, core->io->cached); + rz_io_cache_reset (core->io, core->io->cached); /* Before loading the core block we have to make sure that if * the cache wrote past the original EOF these changes are no * longer displayed. */ memset (core->block, 0xff, core->blocksize); - r_core_block_read (core); + rz_core_block_read (core); break; } return 0; } -static void w_handler_common(RCore *core, const char *input) { - int wseek = r_config_get_i (core->config, "cfg.wseek"); +static void w_handler_common(RzCore *core, const char *input) { + int wseek = rz_config_get_i (core->config, "cfg.wseek"); char *str = strdup (input); /* write string */ - int len = r_str_unescape (str); - if (!r_core_write_at (core, core->offset, (const ut8 *)str, len)) { + int len = rz_str_unescape (str); + if (!rz_core_write_at (core, core->offset, (const ut8 *)str, len)) { cmd_write_fail (core); } WSEEK (core, len); - r_core_block_read (core); + rz_core_block_read (core); } static int w_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; w_handler_common (core, input); return 0; } -static RCmdStatus w_handler(RCore *core, int argc, const char **argv) { +static RzCmdStatus w_handler(RzCore *core, int argc, const char **argv) { if (argc < 2) { return R_CMD_STATUS_WRONG_ARGS; } - char *s = r_str_array_join (argv + 1, argc - 1, " "); + char *s = rz_str_array_join (argv + 1, argc - 1, " "); w_handler_common (core, s); free (s); return R_CMD_STATUS_OK; } static int wz_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); char *str = strdup (input); /* write zero-terminated string */ - int len = r_str_unescape (str); - if (!r_core_write_at (core, core->offset, (const ut8 *)str + 1, len)) { + int len = rz_str_unescape (str); + if (!rz_core_write_at (core, core->offset, (const ut8 *)str + 1, len)) { cmd_write_fail (core); } if (len > 0) { @@ -1442,15 +1442,15 @@ static int wz_handler_old(void *data, const char *input) { core->num->value = 0; } #if 0 - r_io_use_desc (core->io, core->file->desc); + rz_io_use_desc (core->io, core->file->desc); #endif WSEEK (core, len + 1); - r_core_block_read (core); + rz_core_block_read (core); return 0; } static int wt_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; char *str = strdup (input); char *ostr = str; const char *filename = ""; @@ -1460,7 +1460,7 @@ static int wt_handler_old(void *data, const char *input) { if (*str == 's') { // "wts" if (str[1] == ' ') { eprintf ("Write to server\n"); - st64 sz = r_io_size (core->io); + st64 sz = rz_io_size (core->io); if (sz > 0) { ut64 addr = 0; char *host = str + 2; @@ -1470,17 +1470,17 @@ static int wt_handler_old(void *data, const char *input) { char *space = strchr (port, ' '); if (space) { *space++ = 0; - sz = r_num_math (core->num, space); + sz = rz_num_math (core->num, space); addr = core->offset; } ut8 *buf = calloc (1, sz); - r_io_read_at (core->io, addr, buf, sz); - RSocket *s = r_socket_new (false); - if (r_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { + rz_io_read_at (core->io, addr, buf, sz); + RzSocket *s = rz_socket_new (false); + if (rz_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { int done = 0; eprintf ("Transfering file to the end-point...\n"); while (done < sz) { - int rc = r_socket_write (s, buf + done, sz - done); + int rc = rz_socket_write (s, buf + done, sz - done); if (rc <1) { eprintf ("oops\n"); break; @@ -1490,7 +1490,7 @@ static int wt_handler_old(void *data, const char *input) { } else { eprintf ("Cannot connect\n"); } - r_socket_free (s); + rz_socket_free (s); free (buf); } else { eprintf ("Usage wts host:port [sz]\n"); @@ -1502,7 +1502,7 @@ static int wt_handler_old(void *data, const char *input) { eprintf ("Usage wts host:port [sz]\n"); } } else if (*str == '?' || *str == '\0') { - r_core_cmd_help (core, help_msg_wt); + rz_core_cmd_help (core, help_msg_wt); free (ostr); return 0; } else { @@ -1513,15 +1513,15 @@ static int wt_handler_old(void *data, const char *input) { if (*str == 'f') { // "wtf" str++; if (*str == '?') { - r_core_cmd_help (core, help_msg_wt); + rz_core_cmd_help (core, help_msg_wt); return 0; } if (*str == '!') { if (str[1] == '?') { - r_core_cmd_help (core, help_msg_wt); + rz_core_cmd_help (core, help_msg_wt); return 0; } - RIOMap *map = r_io_map_get (core->io, poff); + RzIOMap *map = rz_io_map_get (core->io, poff); toend = true; //use physical address poff = map ? poff - map->itv.addr + map->delta : poff; @@ -1529,22 +1529,22 @@ static int wt_handler_old(void *data, const char *input) { } if (*str == 'f') { // "wtff" if (str[1] == '?') { - r_core_cmd_help (core, help_msg_wt); + rz_core_cmd_help (core, help_msg_wt); return 0; } - const char *prefix = r_str_trim_head_ro (str + 2); + const char *prefix = rz_str_trim_head_ro (str + 2); if (!*prefix) { prefix = "dump"; } str++; - filename = r_str_newf ("%s-0x%08"PFMT64x, prefix, core->offset); + filename = rz_str_newf ("%s-0x%08"PFMT64x, prefix, core->offset); } else { if (*str) { if (str[1] == '?') { - r_core_cmd_help (core, help_msg_wt); + rz_core_cmd_help (core, help_msg_wt); return 0; } - filename = r_str_trim_head_ro (str); + filename = rz_str_trim_head_ro (str); } else { filename = ""; } @@ -1555,12 +1555,12 @@ static int wt_handler_old(void *data, const char *input) { if (str[0] == ' ') { filename = str + 1; } else { - const char* prefix = r_config_get (core->config, "cfg.prefixdump"); + const char* prefix = rz_config_get (core->config, "cfg.prefixdump"); snprintf (_fn, sizeof (_fn), "%s.0x%08"PFMT64x, prefix, poff); filename = _fn; } } else if (*str != ' ') { - const char* prefix = r_config_get (core->config, "cfg.prefixdump"); + const char* prefix = rz_config_get (core->config, "cfg.prefixdump"); snprintf (_fn, sizeof (_fn), "%s.0x%08"PFMT64x, prefix, poff); filename = _fn; } else { @@ -1568,35 +1568,35 @@ static int wt_handler_old(void *data, const char *input) { } tmp = *str? strchr (str + 1, ' ') : NULL; if (!filename || !*filename) { - const char* prefix = r_config_get (core->config, "cfg.prefixdump"); + const char* prefix = rz_config_get (core->config, "cfg.prefixdump"); snprintf (_fn, sizeof (_fn), "%s.0x%08"PFMT64x, prefix, poff); filename = _fn; } if (tmp) { if (toend) { - sz = r_io_fd_size (core->io, core->file->fd) - core->offset; + sz = rz_io_fd_size (core->io, core->file->fd) - core->offset; if (sz < 0) { eprintf ("Warning: File size is unknown."); } } else { - sz = (st64) r_num_math (core->num, tmp + 1); + sz = (st64) rz_num_math (core->num, tmp + 1); *tmp = 0; } if ((st64)sz < 1) { // wtf? sz = 0; - } else if (!r_core_dump (core, filename, poff, (ut64)sz, append)) { + } else if (!rz_core_dump (core, filename, poff, (ut64)sz, append)) { sz = -1; } } else { if (toend) { - sz = r_io_fd_size (core->io, core->file->fd); + sz = rz_io_fd_size (core->io, core->file->fd); if (sz < 0) { eprintf ("Warning: File size is unknown."); } if (sz != -1 && core->offset <= sz) { sz -= core->offset; - if (!r_core_dump (core, filename, core->offset, (ut64)sz, append)) { + if (!rz_core_dump (core, filename, core->offset, (ut64)sz, append)) { sz = -1; } } else { @@ -1604,7 +1604,7 @@ static int wt_handler_old(void *data, const char *input) { } } else { sz = core->blocksize; - if (!r_file_dump (filename, core->block, sz, append)) { + if (!rz_file_dump (filename, core->block, sz, append)) { sz = -1; } } @@ -1618,10 +1618,10 @@ static int wt_handler_old(void *data, const char *input) { } static int ww_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); char *str = strdup (input); - int len = r_str_unescape (str); + int len = rz_str_unescape (str); if (len < 1) { return 0; } @@ -1639,13 +1639,13 @@ static int ww_handler_old(void *data, const char *input) { } str = tmp; if (core->file) { - r_io_use_fd (core->io, core->file->fd); + rz_io_use_fd (core->io, core->file->fd); } - if (!r_io_write_at (core->io, core->offset, (const ut8 *)str, len)) { - eprintf ("r_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); + if (!rz_io_write_at (core->io, core->offset, (const ut8 *)str, len)) { + eprintf ("rz_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); } WSEEK (core, len); - r_core_block_read (core); + rz_core_block_read (core); free (tmp); } else { eprintf ("Cannot malloc %d\n", len); @@ -1654,8 +1654,8 @@ static int ww_handler_old(void *data, const char *input) { } static int wx_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); const char *arg; ut8 *buf; int size; @@ -1668,14 +1668,14 @@ static int wx_handler_old(void *data, const char *input) { if (!strcmp (arg, "-")) { int len; ut8 *out; - char *in = r_core_editor (core, NULL, NULL); + char *in = rz_core_editor (core, NULL, NULL); if (in) { out = (ut8 *)strdup (in); if (out) { - len = r_hex_str2bin (in, out); + len = rz_hex_str2bin (in, out); if (len > 0) { - if (!r_io_write_at (core->io, core->offset, out, len)) { - eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); + if (!rz_io_write_at (core->io, core->offset, out, len)) { + eprintf ("rz_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); } core->num->value = len; } else { @@ -1685,17 +1685,17 @@ static int wx_handler_old(void *data, const char *input) { } free (in); } - } else if (r_file_exists (arg)) { - if ((buf = r_file_slurp_hexpairs (arg, &size))) { - r_io_use_fd (core->io, core->file->fd); - if (r_io_write_at (core->io, core->offset, buf, size) > 0) { + } else if (rz_file_exists (arg)) { + if ((buf = rz_file_slurp_hexpairs (arg, &size))) { + rz_io_use_fd (core->io, core->file->fd); + if (rz_io_write_at (core->io, core->offset, buf, size) > 0) { core->num->value = size; WSEEK (core, size); } else { - eprintf ("r_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); + eprintf ("rz_io_write_at failed at 0x%08"PFMT64x"\n", core->offset); } free (buf); - r_core_block_read (core); + rz_core_block_read (core); } else { eprintf ("This file doesnt contains hexpairs\n"); } @@ -1707,7 +1707,7 @@ static int wx_handler_old(void *data, const char *input) { { int len = cmd_write_hexpair (core, input + 1); if (len > 0) { - r_core_seek_delta (core, len); + rz_core_seek_delta (core, len); core->num->value = len; } else { core->num->value = 0; @@ -1715,79 +1715,79 @@ static int wx_handler_old(void *data, const char *input) { } break; default: - r_core_cmd_help (core, help_msg_wx); + rz_core_cmd_help (core, help_msg_wx); break; } return 0; } static int wa_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); switch (input[0]) { case 'o': // "wao" if (input[1] == ' ') { - char *op = r_str_trim_dup (input + 2); + char *op = rz_str_trim_dup (input + 2); if (op) { - r_core_hack (core, op); + rz_core_hack (core, op); free (op); } } else { - r_core_hack_help (core); + rz_core_hack_help (core); } break; case ' ': case 'i': case '*': { - const char *file = r_str_trim_head_ro (input + 1); - RAsmCode *acode; - r_asm_set_pc (core->rasm, core->offset); - acode = r_asm_massemble (core->rasm, file); + const char *file = rz_str_trim_head_ro (input + 1); + RzAsmCode *acode; + rz_asm_set_pc (core->rasm, core->offset); + acode = rz_asm_massemble (core->rasm, file); if (acode) { if (input[0] == 'i') { // "wai" - RAnalOp analop; - if (!r_anal_op (core->anal, &analop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { + RzAnalOp analop; + if (!rz_anal_op (core->anal, &analop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { eprintf ("Invalid instruction?\n"); break; } if (analop.size < acode->len) { eprintf ("Doesnt fit\n"); - r_anal_op_fini (&analop); - r_asm_code_free (acode); + rz_anal_op_fini (&analop); + rz_asm_code_free (acode); break; } - r_anal_op_fini (&analop); - r_core_cmd0 (core, "wao nop"); + rz_anal_op_fini (&analop); + rz_core_cmd0 (core, "wao nop"); } if (acode->len > 0) { - char* hex = r_asm_code_get_hex (acode); + char* hex = rz_asm_code_get_hex (acode); if (input[0] == '*') { - r_cons_printf ("wx %s\n", hex); + rz_cons_printf ("wx %s\n", hex); } else { - if (!r_core_write_at (core, core->offset, acode->bytes, acode->len)) { + if (!rz_core_write_at (core, core->offset, acode->bytes, acode->len)) { cmd_write_fail (core); } else { - if (r_config_get_i (core->config, "scr.prompt")) { + if (rz_config_get_i (core->config, "scr.prompt")) { eprintf ("Written %d byte(s) (%s) = wx %s\n", acode->len, input+1, hex); } WSEEK (core, acode->len); } - r_core_block_read (core); + rz_core_block_read (core); } free (hex); } else { eprintf ("Nothing to do.\n"); } - r_asm_code_free (acode); + rz_asm_code_free (acode); } } break; case 'f': // "waf" if ((input[1] == ' ' || input[1] == '*')) { const char *file = input + ((input[1] == '*')? 3: 2); - r_asm_set_pc (core->rasm, core->offset); + rz_asm_set_pc (core->rasm, core->offset); - char *src = r_file_slurp (file, NULL); + char *src = rz_file_slurp (file, NULL); if (src) { ut64 addr = core->offset, nextaddr = addr; char *a, *b = src; @@ -1796,7 +1796,7 @@ static int wa_handler_old(void *data, const char *input) { if (a) { *a = 0; a += strlen (".offset "); - nextaddr = r_num_math (core->num, a); + nextaddr = rz_num_math (core->num, a); char *nl = strchr (a, '\n'); if (nl) { *nl = 0; @@ -1806,10 +1806,10 @@ static int wa_handler_old(void *data, const char *input) { } } if (*b) { - RAsmCode *ac = r_asm_massemble (core->rasm, b); + RzAsmCode *ac = rz_asm_massemble (core->rasm, b); if (ac) { - r_io_write_at (core->io, addr, ac->bytes, ac->len); - r_asm_code_free (ac); + rz_io_write_at (core->io, addr, ac->bytes, ac->len); + rz_asm_code_free (ac); } } b = a; @@ -1826,27 +1826,27 @@ static int wa_handler_old(void *data, const char *input) { case 'F': // "waF" if ((input[1] == ' ' || input[1] == '*')) { const char *file = input + ((input[1] == '*')? 3: 2); - r_asm_set_pc (core->rasm, core->offset); - char *f = r_file_slurp (file, NULL); + rz_asm_set_pc (core->rasm, core->offset); + char *f = rz_file_slurp (file, NULL); if (f) { - RAsmCode *acode = r_asm_massemble (core->rasm, f); + RzAsmCode *acode = rz_asm_massemble (core->rasm, f); if (acode) { - char* hex = r_asm_code_get_hex (acode); + char* hex = rz_asm_code_get_hex (acode); if (input[1] == '*') { - r_cons_printf ("wx %s\n", hex); + rz_cons_printf ("wx %s\n", hex); } else { - if (r_config_get_i (core->config, "scr.prompt")) { + if (rz_config_get_i (core->config, "scr.prompt")) { eprintf ("Written %d byte(s) (%s)=wx %s\n", acode->len, input, hex); } - if (!r_core_write_at (core, core->offset, acode->bytes, acode->len)) { + if (!rz_core_write_at (core, core->offset, acode->bytes, acode->len)) { cmd_write_fail (core); } else { WSEEK (core, acode->len); } - r_core_block_read (core); + rz_core_block_read (core); } free (hex); - r_asm_code_free (acode); + rz_asm_code_free (acode); } else { eprintf ("Cannot assemble file\n"); } @@ -1858,27 +1858,27 @@ static int wa_handler_old(void *data, const char *input) { } break; default: - r_core_cmd_help (core, help_msg_wa); + rz_core_cmd_help (core, help_msg_wa); break; } return 0; } static int wb_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; int len = strlen (input); ut8 *buf = malloc (len + 2); - int wseek = r_config_get_i (core->config, "cfg.wseek"); + int wseek = rz_config_get_i (core->config, "cfg.wseek"); if (buf) { - len = r_hex_str2bin (input, buf); + len = rz_hex_str2bin (input, buf); if (len > 0) { - r_mem_copyloop (core->block, buf, core->blocksize, len); - if (!r_core_write_at (core, core->offset, core->block, core->blocksize)) { + rz_mem_copyloop (core->block, buf, core->blocksize, len); + if (!rz_core_write_at (core, core->offset, core->block, core->blocksize)) { cmd_write_fail (core); } else { WSEEK (core, core->blocksize); } - r_core_block_read (core); + rz_core_block_read (core); } else eprintf ("Wrong argument\n"); free (buf); @@ -1889,10 +1889,10 @@ static int wb_handler_old(void *data, const char *input) { } static int wm_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; char *str = strdup (input); - int size = r_hex_str2bin (input, (ut8 *)str); - int wseek = r_config_get_i (core->config, "cfg.wseek"); + int size = rz_hex_str2bin (input, (ut8 *)str); + int wseek = rz_config_get_i (core->config, "cfg.wseek"); switch (input[0]) { case '\0': eprintf ("TODO: Display current write mask"); @@ -1900,13 +1900,13 @@ static int wm_handler_old(void *data, const char *input) { case '?': break; case '-': - r_io_set_write_mask (core->io, 0, 0); + rz_io_set_write_mask (core->io, 0, 0); eprintf ("Write mask disabled\n"); break; case ' ': if (size > 0) { - r_io_use_fd (core->io, core->file->fd); - r_io_set_write_mask (core->io, (const ut8 *)str, size); + rz_io_use_fd (core->io, core->file->fd); + rz_io_set_write_mask (core->io, (const ut8 *)str, size); WSEEK (core, size); eprintf ("Write mask set to '"); size_t i; @@ -1923,18 +1923,18 @@ static int wm_handler_old(void *data, const char *input) { } static int wd_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (input[0] && input[0] == ' ') { char *arg, *inp = strdup (input + 1); arg = strchr (inp, ' '); if (arg) { *arg = 0; - ut64 addr = r_num_math (core->num, input + 1); - ut64 len = r_num_math (core->num, arg + 1); + ut64 addr = rz_num_math (core->num, input + 1); + ut64 len = rz_num_math (core->num, arg + 1); ut8 *data = malloc (len); - r_io_read_at (core->io, addr, data, len); - if (!r_io_write_at (core->io, core->offset, data, len)) { - eprintf ("r_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); + rz_io_read_at (core->io, addr, data, len); + if (!rz_io_write_at (core->io, core->offset, data, len)) { + eprintf ("rz_io_write_at failed at 0x%08" PFMT64x "\n", core->offset); } free (data); } else { @@ -1947,22 +1947,22 @@ static int wd_handler_old(void *data, const char *input) { } static int ws_handler_old(void *data, const char *input) { - RCore *core = (RCore *)data; - int wseek = r_config_get_i (core->config, "cfg.wseek"); + RzCore *core = (RzCore *)data; + int wseek = rz_config_get_i (core->config, "cfg.wseek"); char *str = strdup (input); if (str && *str && str[1]) { - int len = r_str_unescape (str + 1); + int len = rz_str_unescape (str + 1); if (len > 255) { eprintf ("Too large\n"); } else { ut8 ulen = (ut8)len; - if (!r_core_write_at (core, core->offset, &ulen, 1) || - !r_core_write_at (core, core->offset + 1, (const ut8 *)str + 1, len)) { + if (!rz_core_write_at (core, core->offset, &ulen, 1) || + !rz_core_write_at (core, core->offset + 1, (const ut8 *)str + 1, len)) { cmd_write_fail (core); } else { WSEEK (core, len); } - r_core_block_read (core); + rz_core_block_read (core); } } else { eprintf ("Too short.\n"); @@ -1970,9 +1970,9 @@ static int ws_handler_old(void *data, const char *input) { return 0; } -/* TODO: simplify using r_write */ +/* TODO: simplify using rz_write */ static int cmd_write(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; if (!input) { return 0; @@ -2056,13 +2056,13 @@ static int cmd_write(void *data, const char *input) { break; default: case '?': // "w?" - r_core_cmd_help (core, help_msg_w); + rz_core_cmd_help (core, help_msg_w); break; } return 0; } -static void cmd_write_init(RCore *core, RCmdDesc *parent) { +static void cmd_write_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, w); DEFINE_CMD_DESCRIPTOR (core, wa); DEFINE_CMD_DESCRIPTOR (core, wA); diff --git a/libr/core/cmd_zign.c b/librz/core/cmd_zign.c similarity index 57% rename from libr/core/cmd_zign.c rename to librz/core/cmd_zign.c index b0441f22e5..8b1f34857c 100644 --- a/libr/core/cmd_zign.c +++ b/librz/core/cmd_zign.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include static const char *help_msg_z[] = { "Usage:", "z[*j-aof/cs] [args] ", "# Manage zignatures", @@ -90,7 +90,7 @@ static const char *help_msg_zc[] = { NULL }; -static void cmd_zign_init(RCore *core, RCmdDesc *parent) { +static void cmd_zign_init(RzCore *core, RzCmdDesc *parent) { DEFINE_CMD_DESCRIPTOR (core, z); DEFINE_CMD_DESCRIPTOR (core, zb); DEFINE_CMD_DESCRIPTOR_SPECIAL (core, z/, z_slash); @@ -102,9 +102,9 @@ static void cmd_zign_init(RCore *core, RCmdDesc *parent) { } #if 0 -static char *getFcnComments(RCore *core, RAnalFunction *fcn) { +static char *getFcnComments(RzCore *core, RzAnalFunction *fcn) { // XXX this is slow as hell on big binaries - char *r = r_core_cmd_strf (core, "CCf* @ 0x%08"PFMT64x, fcn->addr); + char *r = rz_core_cmd_strf (core, "CCf* @ 0x%08"PFMT64x, fcn->addr); if (r && *r) { return r; } @@ -113,132 +113,132 @@ static char *getFcnComments(RCore *core, RAnalFunction *fcn) { } #endif -static void addFcnZign(RCore *core, RAnalFunction *fcn, const char *name) { +static void addFcnZign(RzCore *core, RzAnalFunction *fcn, const char *name) { char *ptr = NULL; char *zignspace = NULL; char *zigname = NULL; - const RSpace *curspace = r_spaces_current (&core->anal->zign_spaces); + const RSpace *curspace = rz_spaces_current (&core->anal->zign_spaces); int len = 0; if (name) { - zigname = r_str_new (name); + zigname = rz_str_new (name); } else { // If the user has set funtion names containing a single ':' then we assume // ZIGNSPACE:FUNCTION, and for now we only support the 'zg' command if ((ptr = strchr (fcn->name, ':')) != NULL) { len = ptr - fcn->name; - zignspace = r_str_newlen (fcn->name, len); - r_spaces_push (&core->anal->zign_spaces, zignspace); + zignspace = rz_str_newlen (fcn->name, len); + rz_spaces_push (&core->anal->zign_spaces, zignspace); } else if (curspace) { - zigname = r_str_newf ("%s:", curspace->name); + zigname = rz_str_newf ("%s:", curspace->name); } - zigname = r_str_appendf (zigname, "%s", fcn->name); + zigname = rz_str_appendf (zigname, "%s", fcn->name); } // create empty item - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { free (zigname); return; } // add sig types info to item it->name = zigname; // will be free'd when item is free'd - it->space = r_spaces_current (&core->anal->zign_spaces); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_GRAPH); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_BYTES); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_XREFS); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_REFS); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_VARS); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_TYPES); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_BBHASH); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_OFFSET); - r_sign_addto_item (core->anal, it, fcn, R_SIGN_NAME); + it->space = rz_spaces_current (&core->anal->zign_spaces); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_GRAPH); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_BYTES); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_XREFS); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_REFS); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_VARS); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_TYPES); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_BBHASH); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_OFFSET); + rz_sign_addto_item (core->anal, it, fcn, R_SIGN_NAME); - /* r_sign_add_addr (core->anal, zigname, fcn->addr); */ + /* rz_sign_add_addr (core->anal, zigname, fcn->addr); */ // commit the item to anal - r_sign_add_item (core->anal, it); + rz_sign_add_item (core->anal, it); /* XXX this is very slow and poorly tested char *comments = getFcnComments (core, fcn); if (comments) { - r_sign_add_comment (core->anal, zigname, comments); + rz_sign_add_comment (core->anal, zigname, comments); } */ - r_sign_item_free (it); // causes zigname to be free'd + rz_sign_item_free (it); // causes zigname to be free'd if (zignspace) { - r_spaces_pop (&core->anal->zign_spaces); + rz_spaces_pop (&core->anal->zign_spaces); free (zignspace); } } -static bool addCommentZign(RCore *core, const char *name, RList *args) { - if (r_list_length (args) != 1) { +static bool addCommentZign(RzCore *core, const char *name, RzList *args) { + if (rz_list_length (args) != 1) { eprintf ("Invalid number of arguments\n"); return false; } - const char *comment = (const char *)r_list_get_top (args); - return r_sign_add_comment (core->anal, name, comment); + const char *comment = (const char *)rz_list_get_top (args); + return rz_sign_add_comment (core->anal, name, comment); } -static bool addNameZign(RCore *core, const char *name, RList *args) { - if (r_list_length (args) != 1) { +static bool addNameZign(RzCore *core, const char *name, RzList *args) { + if (rz_list_length (args) != 1) { eprintf ("Invalid number of arguments\n"); return false; } - const char *realname = (const char *)r_list_get_top (args); - return r_sign_add_name (core->anal, name, realname); + const char *realname = (const char *)rz_list_get_top (args); + return rz_sign_add_name (core->anal, name, realname); } -static bool addGraphZign(RCore *core, const char *name, RList *args) { - RSignGraph graph = { .cc = -1, .nbbs = -1, .edges = -1, .ebbs = -1, .bbsum = 0 }; +static bool addGraphZign(RzCore *core, const char *name, RzList *args) { + RzSignGraph graph = { .cc = -1, .nbbs = -1, .edges = -1, .ebbs = -1, .bbsum = 0 }; char *ptr; - RListIter *iter; - r_list_foreach (args, iter, ptr) { - if (r_str_startswith (ptr, "cc=")) { + RzListIter *iter; + rz_list_foreach (args, iter, ptr) { + if (rz_str_startswith (ptr, "cc=")) { graph.cc = atoi (ptr + 3); - } else if (r_str_startswith (ptr, "nbbs=")) { + } else if (rz_str_startswith (ptr, "nbbs=")) { graph.nbbs = atoi (ptr + 5); - } else if (r_str_startswith (ptr, "edges=")) { + } else if (rz_str_startswith (ptr, "edges=")) { graph.edges = atoi (ptr + 6); - } else if (r_str_startswith (ptr, "ebbs=")) { + } else if (rz_str_startswith (ptr, "ebbs=")) { graph.ebbs = atoi (ptr + 5); - } else if (r_str_startswith (ptr, "bbsum=")) { + } else if (rz_str_startswith (ptr, "bbsum=")) { graph.bbsum = atoi (ptr + 6); } else { return false; } } - return r_sign_add_graph (core->anal, name, graph); + return rz_sign_add_graph (core->anal, name, graph); } -static bool addHashZign(RCore *core, const char *name, int type, RList *args) { - if (r_list_length (args) != 1) { +static bool addHashZign(RzCore *core, const char *name, int type, RzList *args) { + if (rz_list_length (args) != 1) { eprintf ("error: invalid syntax\n"); return false; } - const char *hash = (const char *)r_list_get_top (args); + const char *hash = (const char *)rz_list_get_top (args); int len = strlen (hash); if (!len) { return false; } - return r_sign_add_hash (core->anal, name, type, hash, len); + return rz_sign_add_hash (core->anal, name, type, hash, len); } -static bool addBytesZign(RCore *core, const char *name, int type, RList *args) { +static bool addBytesZign(RzCore *core, const char *name, int type, RzList *args) { ut8 *mask = NULL, *bytes = NULL, *sep = NULL; int size = 0; bool retval = true; - if (r_list_length (args) != 1) { + if (rz_list_length (args) != 1) { eprintf ("error: invalid syntax\n"); return false; } - const char *hexbytes = (const char *)r_list_get_top (args); + const char *hexbytes = (const char *)rz_list_get_top (args); if ((sep = (ut8 *)strchr (hexbytes, ':'))) { size_t blen = sep - (ut8 *)hexbytes; sep++; @@ -250,8 +250,8 @@ static bool addBytesZign(RCore *core, const char *name, int type, RList *args) { mask = calloc (1, blen + 1); memcpy (bytes, hexbytes, blen); memcpy (mask, sep, blen); - size = r_hex_str2bin ((char*) bytes, bytes); - if (size != blen / 2 || r_hex_str2bin ((char*)mask, mask) != size) { + size = rz_hex_str2bin ((char*) bytes, bytes); + if (size != blen / 2 || rz_hex_str2bin ((char*)mask, mask) != size) { eprintf ("error: cannot parse hexpairs\n"); retval = false; goto out; @@ -261,7 +261,7 @@ static bool addBytesZign(RCore *core, const char *name, int type, RList *args) { bytes = malloc (blen); mask = malloc (blen); - size = r_hex_str2binmask (hexbytes, bytes, mask); + size = rz_hex_str2binmask (hexbytes, bytes, mask); if (size <= 0) { eprintf ("error: cannot parse hexpairs\n"); retval = false; @@ -271,10 +271,10 @@ static bool addBytesZign(RCore *core, const char *name, int type, RList *args) { switch (type) { case R_SIGN_BYTES: - retval = r_sign_add_bytes (core->anal, name, size, bytes, mask); + retval = rz_sign_add_bytes (core->anal, name, size, bytes, mask); break; case R_SIGN_ANAL: - retval = r_sign_add_anal (core->anal, name, size, bytes, 0); + retval = rz_sign_add_anal (core->anal, name, size, bytes, 0); break; } @@ -285,20 +285,20 @@ out: return retval; } -static bool addOffsetZign(RCore *core, const char *name, RList *args) { - if (r_list_length (args) != 1) { +static bool addOffsetZign(RzCore *core, const char *name, RzList *args) { + if (rz_list_length (args) != 1) { eprintf ("error: invalid syntax\n"); return false; } - const char *offstr = (const char *)r_list_get_top (args); + const char *offstr = (const char *)rz_list_get_top (args); if (!offstr) { return false; } - ut64 offset = r_num_get (core->num, offstr); - return r_sign_add_addr (core->anal, name, offset); + ut64 offset = rz_num_get (core->num, offstr); + return rz_sign_add_addr (core->anal, name, offset); } -static bool addZign(RCore *core, const char *name, int type, RList *args) { +static bool addZign(RzCore *core, const char *name, int type, RzList *args) { switch (type) { case R_SIGN_BYTES: case R_SIGN_ANAL: @@ -312,13 +312,13 @@ static bool addZign(RCore *core, const char *name, int type, RList *args) { case R_SIGN_OFFSET: return addOffsetZign (core, name, args); case R_SIGN_REFS: - return r_sign_add_refs (core->anal, name, args); + return rz_sign_add_refs (core->anal, name, args); case R_SIGN_XREFS: - return r_sign_add_xrefs (core->anal, name, args); + return rz_sign_add_xrefs (core->anal, name, args); case R_SIGN_VARS: - return r_sign_add_vars (core->anal, name, args); + return rz_sign_add_vars (core->anal, name, args); case R_SIGN_TYPES: - return r_sign_add_types (core->anal, name, args); + return rz_sign_add_types (core->anal, name, args); case R_SIGN_BBHASH: return addHashZign (core, name, type, args); default: @@ -329,27 +329,27 @@ static bool addZign(RCore *core, const char *name, int type, RList *args) { } static int cmdAdd(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (*input) { case ' ': { bool retval = true; - char *args = r_str_trim_dup (input + 1); + char *args = rz_str_trim_dup (input + 1); if (!args) { return false; } - RList *lst = r_str_split_list (args, " ", 0); + RzList *lst = rz_str_split_list (args, " ", 0); if (!lst) { goto out_case_manual; } - if (r_list_length (lst) < 3) { + if (rz_list_length (lst) < 3) { eprintf ("Usage: za zigname type params\n"); retval = false; goto out_case_manual; } - char *zigname = r_list_pop_head (lst); - char *type_str = r_list_pop_head (lst); + char *zigname = rz_list_pop_head (lst); + char *type_str = rz_list_pop_head (lst); if (strlen (type_str) != 1) { eprintf ("Usage: za zigname type params\n"); retval = false; @@ -362,22 +362,22 @@ static int cmdAdd(void *data, const char *input) { } out_case_manual: - r_list_free (lst); + rz_list_free (lst); free (args); return retval; } break; case 'f': // "zaf" { - RAnalFunction *fcni = NULL; - RListIter *iter = NULL; + RzAnalFunction *fcni = NULL; + RzListIter *iter = NULL; const char *fcnname = NULL, *zigname = NULL; char *args = NULL; int n = 0; bool retval = true; - args = r_str_trim_dup (input + 1); - n = r_str_word_set0 (args); + args = rz_str_trim_dup (input + 1); + n = rz_str_word_set0 (args); if (n > 2) { eprintf ("Usage: zaf [fcnname] [zigname]\n"); @@ -387,14 +387,14 @@ out_case_manual: switch (n) { case 2: - zigname = r_str_word_get0 (args, 1); + zigname = rz_str_word_get0 (args, 1); case 1: - fcnname = r_str_word_get0 (args, 0); + fcnname = rz_str_word_get0 (args, 0); } - r_cons_break_push (NULL, NULL); - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } if ((!fcnname && core->offset == fcni->addr) || @@ -403,7 +403,7 @@ out_case_manual: break; } } - r_cons_break_pop (); + rz_cons_break_pop (); out_case_fcn: free (args); @@ -412,26 +412,26 @@ out_case_fcn: break; case 'F': { - RAnalFunction *fcni = NULL; - RListIter *iter = NULL; + RzAnalFunction *fcni = NULL; + RzListIter *iter = NULL; int count = 0; - r_cons_break_push (NULL, NULL); - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } addFcnZign (core, fcni, NULL); count++; } - r_cons_break_pop (); + rz_cons_break_pop (); eprintf ("generated zignatures: %d\n", count); } break; case '?': if (input[1] == '?') { // TODO #7967 help refactor: move to detail - r_cons_printf ("Adding Zignatures (examples and documentation)\n\n" + rz_cons_printf ("Adding Zignatures (examples and documentation)\n\n" "Zignature types:\n" " a: bytes pattern (anal mask)\n" " b: bytes pattern\n" @@ -461,7 +461,7 @@ out_case_fcn: " za foo r sym.imp.strcpy sym.imp.sprintf sym.imp.strlen\n" " za foo h 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae\n"); } else { - r_core_cmd_help (core, help_msg_za); + rz_core_cmd_help (core, help_msg_za); } break; default: @@ -473,29 +473,29 @@ out_case_fcn: } static int cmdOpen(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (*input) { case ' ': if (input[1]) { - return r_sign_load (core->anal, input + 1); + return rz_sign_load (core->anal, input + 1); } eprintf ("Usage: zo filename\n"); return false; case 's': if (input[1] == ' ' && input[2]) { - return r_sign_save (core->anal, input + 2); + return rz_sign_save (core->anal, input + 2); } eprintf ("Usage: zos filename\n"); return false; case 'z': if (input[1] == ' ' && input[2]) { - return r_sign_load_gz (core->anal, input + 2); + return rz_sign_load_gz (core->anal, input + 2); } eprintf ("Usage: zoz filename\n"); return false; case '?': - r_core_cmd_help (core, help_msg_zo); + rz_core_cmd_help (core, help_msg_zo); break; default: eprintf ("Usage: zo[zs] filename\n"); @@ -506,7 +506,7 @@ static int cmdOpen(void *data, const char *input) { } static int cmdSpace(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; RSpaces *zs = &core->anal->zign_spaces; switch (*input) { @@ -515,22 +515,22 @@ static int cmdSpace(void *data, const char *input) { eprintf ("Usage: zs+zignspace\n"); return false; } - r_spaces_push (zs, input + 1); + rz_spaces_push (zs, input + 1); break; case 'r': if (input[1] != ' ' || !input[2]) { eprintf ("Usage: zsr newname\n"); return false; } - r_spaces_rename (zs, NULL, input + 2); + rz_spaces_rename (zs, NULL, input + 2); break; case '-': if (input[1] == '\x00') { - r_spaces_pop (zs); + rz_spaces_pop (zs); } else if (input[1] == '*') { - r_spaces_unset (zs, NULL); + rz_spaces_unset (zs, NULL); } else { - r_spaces_unset (zs, input + 1); + rz_spaces_unset (zs, input + 1); } break; case 'j': @@ -543,10 +543,10 @@ static int cmdSpace(void *data, const char *input) { eprintf ("Usage: zs zignspace\n"); return false; } - r_spaces_set (zs, input + 1); + rz_spaces_set (zs, input + 1); break; case '?': - r_core_cmd_help (core, help_msg_zs); + rz_core_cmd_help (core, help_msg_zs); break; default: eprintf ("Usage: zs[+-*] [namespace]\n"); @@ -557,7 +557,7 @@ static int cmdSpace(void *data, const char *input) { } static int cmdFlirt(void *data, const char *input) { - RCore *core = (RCore *)data; + RzCore *core = (RzCore *)data; switch (*input) { case 'd': @@ -566,7 +566,7 @@ static int cmdFlirt(void *data, const char *input) { eprintf ("Usage: zfd filename\n"); return false; } - r_sign_flirt_dump (core->anal, input + 2); + rz_sign_flirt_dump (core->anal, input + 2); break; case 's': // TODO @@ -574,20 +574,20 @@ static int cmdFlirt(void *data, const char *input) { eprintf ("Usage: zfs filename\n"); return false; } - int depth = r_config_get_i (core->config, "dir.depth"); + int depth = rz_config_get_i (core->config, "dir.depth"); char *file; - RListIter *iter; - RList *files = r_file_globsearch (input + 2, depth); - r_list_foreach (files, iter, file) { - r_sign_flirt_scan (core->anal, file); + RzListIter *iter; + RzList *files = rz_file_globsearch (input + 2, depth); + rz_list_foreach (files, iter, file) { + rz_sign_flirt_scan (core->anal, file); } - r_list_free (files); + rz_list_free (files); break; case 'z': // TODO break; case '?': - r_core_cmd_help (core, help_msg_zf); + rz_core_cmd_help (core, help_msg_zf); break; default: eprintf ("Usage: zf[dsz] filename\n"); @@ -597,84 +597,84 @@ static int cmdFlirt(void *data, const char *input) { } struct ctxSearchCB { - RCore *core; + RzCore *core; bool rad; int count; const char *prefix; }; -static void apply_name(RCore *core, RAnalFunction *fcn, RSignItem *it, bool rad) { - r_return_if_fail (core && fcn && it && it->name); +static void apply_name(RzCore *core, RzAnalFunction *fcn, RzSignItem *it, bool rad) { + rz_return_if_fail (core && fcn && it && it->name); const char *name = it->realname? it->realname: it->name; if (rad) { - char *tmp = r_name_filter2 (name); + char *tmp = rz_name_filter2 (name); if (tmp) { - r_cons_printf ("\"afn %s @ 0x%08" PFMT64x "\"\n", tmp, fcn->addr); + rz_cons_printf ("\"afn %s @ 0x%08" PFMT64x "\"\n", tmp, fcn->addr); free (tmp); } return; } - RFlagItem *flag = r_flag_get (core->flags, fcn->name); + RzFlagItem *flag = rz_flag_get (core->flags, fcn->name); if (flag && flag->space && strcmp (flag->space->name, R_FLAGS_FS_FUNCTIONS)) { - r_flag_rename (core->flags, flag, name); + rz_flag_rename (core->flags, flag, name); } - r_anal_function_rename (fcn, name); + rz_anal_function_rename (fcn, name); if (core->anal->cb.on_fcn_rename) { core->anal->cb.on_fcn_rename (core->anal, core->anal->user, fcn, name); } } -static void apply_types(RCore *core, RAnalFunction *fcn, RSignItem *it) { - r_return_if_fail (core && fcn && it && it->name); +static void apply_types(RzCore *core, RzAnalFunction *fcn, RzSignItem *it) { + rz_return_if_fail (core && fcn && it && it->name); if (!it->types) { return; } const char *name = it->realname? it->realname: it->name; - RListIter *iter; + RzListIter *iter; char *type; - char *start = r_str_newf ("func.%s.", name); + char *start = rz_str_newf ("func.%s.", name); size_t startlen = strlen (start); char *alltypes = NULL; - r_list_foreach (it->types, iter, type) { + rz_list_foreach (it->types, iter, type) { if (strncmp (start, type, startlen)) { eprintf ("Unexpected type: %s\n", type); free (alltypes); free (start); return; } - if (!(alltypes = r_str_appendf (alltypes, "%s\n", type))) { + if (!(alltypes = rz_str_appendf (alltypes, "%s\n", type))) { free (alltypes); free (start); return; } } - r_str_remove_char (alltypes, '"'); - r_anal_save_parsed_type (core->anal, alltypes); + rz_str_remove_char (alltypes, '"'); + rz_anal_save_parsed_type (core->anal, alltypes); free (start); free (alltypes); } -static void apply_flag(RCore *core, RSignItem *it, ut64 addr, int size, int count, const char *prefix, bool rad) { - const char *zign_prefix = r_config_get (core->config, "zign.prefix"); - char *name = r_str_newf ("%s.%s.%s_%d", zign_prefix, prefix, it->name, count); +static void apply_flag(RzCore *core, RzSignItem *it, ut64 addr, int size, int count, const char *prefix, bool rad) { + const char *zign_prefix = rz_config_get (core->config, "zign.prefix"); + char *name = rz_str_newf ("%s.%s.%s_%d", zign_prefix, prefix, it->name, count); if (name) { if (rad) { - char *tmp = r_name_filter2 (name); + char *tmp = rz_name_filter2 (name); if (tmp) { - r_cons_printf ("f %s %d @ 0x%08" PFMT64x "\n", tmp, size, addr); + rz_cons_printf ("f %s %d @ 0x%08" PFMT64x "\n", tmp, size, addr); free (tmp); } } else { - r_flag_set (core->flags, name, addr, size); + rz_flag_set (core->flags, name, addr, size); } free (name); } } -static int searchHitCB(RSignItem *it, RSearchKeyword *kw, ut64 addr, void *user) { +static int searchHitCB(RzSignItem *it, RzSearchKeyword *kw, ut64 addr, void *user) { struct ctxSearchCB *ctx = (struct ctxSearchCB *)user; apply_flag (ctx->core, it, addr, kw->keyword_length, kw->count, ctx->prefix, ctx->rad); - RAnalFunction *fcn = r_anal_get_fcn_in (ctx->core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (ctx->core->anal, addr, 0); // TODO: create fcn if it does not exist if (fcn) { apply_name (ctx->core, fcn, it, ctx->rad); @@ -684,10 +684,10 @@ static int searchHitCB(RSignItem *it, RSearchKeyword *kw, ut64 addr, void *user) return 1; } -static int fcnMatchCB(RSignItem *it, RAnalFunction *fcn, void *user) { +static int fcnMatchCB(RzSignItem *it, RzAnalFunction *fcn, void *user) { struct ctxSearchCB *ctx = (struct ctxSearchCB *)user; // TODO(nibble): use one counter per metric zign instead of ctx->count - ut64 sz = r_anal_function_realsize (fcn); + ut64 sz = rz_anal_function_realsize (fcn); apply_flag (ctx->core, it, fcn->addr, sz, ctx->count, ctx->prefix, ctx->rad); apply_name (ctx->core, fcn, it, ctx->rad); apply_types (ctx->core, fcn, it); @@ -695,46 +695,46 @@ static int fcnMatchCB(RSignItem *it, RAnalFunction *fcn, void *user) { return 1; } -static bool searchRange(RCore *core, ut64 from, ut64 to, bool rad, struct ctxSearchCB *ctx) { +static bool searchRange(RzCore *core, ut64 from, ut64 to, bool rad, struct ctxSearchCB *ctx) { ut8 *buf = malloc (core->blocksize); ut64 at; int rlen; bool retval = true; - int minsz = r_config_get_i (core->config, "zign.minsz"); + int minsz = rz_config_get_i (core->config, "zign.minsz"); if (!buf) { return false; } - RSignSearch *ss = r_sign_search_new (); - ss->search->align = r_config_get_i (core->config, "search.align"); - r_sign_search_init (core->anal, ss, minsz, searchHitCB, ctx); + RzSignSearch *ss = rz_sign_search_new (); + ss->search->align = rz_config_get_i (core->config, "search.align"); + rz_sign_search_init (core->anal, ss, minsz, searchHitCB, ctx); - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (at = from; at < to; at += core->blocksize) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { retval = false; break; } rlen = R_MIN (core->blocksize, to - at); - if (!r_io_is_valid_offset (core->io, at, 0)) { + if (!rz_io_is_valid_offset (core->io, at, 0)) { retval = false; break; } - (void)r_io_read_at (core->io, at, buf, rlen); - if (r_sign_search_update (core->anal, ss, &at, buf, rlen) == -1) { + (void)rz_io_read_at (core->io, at, buf, rlen); + if (rz_sign_search_update (core->anal, ss, &at, buf, rlen) == -1) { eprintf ("search: update read error at 0x%08" PFMT64x "\n", at); retval = false; break; } } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); - r_sign_search_free (ss); + rz_sign_search_free (ss); return retval; } -static bool searchRange2(RCore *core, RSignSearch *ss, ut64 from, ut64 to, bool rad, struct ctxSearchCB *ctx) { +static bool searchRange2(RzCore *core, RzSignSearch *ss, ut64 from, ut64 to, bool rad, struct ctxSearchCB *ctx) { ut8 *buf = malloc (core->blocksize); ut64 at; int rlen; @@ -743,35 +743,35 @@ static bool searchRange2(RCore *core, RSignSearch *ss, ut64 from, ut64 to, bool if (!buf) { return false; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (at = from; at < to; at += core->blocksize) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { retval = false; break; } rlen = R_MIN (core->blocksize, to - at); - if (!r_io_is_valid_offset (core->io, at, 0)) { + if (!rz_io_is_valid_offset (core->io, at, 0)) { retval = false; break; } - (void)r_io_read_at (core->io, at, buf, rlen); - if (r_sign_search_update (core->anal, ss, &at, buf, rlen) == -1) { + (void)rz_io_read_at (core->io, at, buf, rlen); + if (rz_sign_search_update (core->anal, ss, &at, buf, rlen) == -1) { eprintf ("search: update read error at 0x%08"PFMT64x"\n", at); retval = false; break; } } - r_cons_break_pop (); + rz_cons_break_pop (); free (buf); return retval; } -static bool search(RCore *core, bool rad, bool only_func) { - RList *list; - RListIter *iter; - RAnalFunction *fcni = NULL; - RIOMap *map; +static bool search(RzCore *core, bool rad, bool only_func) { + RzList *list; + RzListIter *iter; + RzAnalFunction *fcni = NULL; + RzIOMap *map; bool retval = true; int hits = 0; @@ -782,21 +782,21 @@ static bool search(RCore *core, bool rad, bool only_func) { struct ctxSearchCB hash_match_ctx = { core, rad, 0, "bbhash" }; struct ctxSearchCB types_match_ctx = { core, rad, 0, "types" }; - const char *zign_prefix = r_config_get (core->config, "zign.prefix"); - int mincc = r_config_get_i (core->config, "zign.mincc"); - const char *mode = r_config_get (core->config, "search.in"); - bool useBytes = r_config_get_i (core->config, "zign.bytes"); - bool useGraph = r_config_get_i (core->config, "zign.graph"); - bool useOffset = r_config_get_i (core->config, "zign.offset"); - bool useRefs = r_config_get_i (core->config, "zign.refs"); - bool useHash = r_config_get_i (core->config, "zign.hash"); - bool useTypes = r_config_get_i (core->config, "zign.types"); - int maxsz = r_config_get_i (core->config, "zign.maxsz"); + const char *zign_prefix = rz_config_get (core->config, "zign.prefix"); + int mincc = rz_config_get_i (core->config, "zign.mincc"); + const char *mode = rz_config_get (core->config, "search.in"); + bool useBytes = rz_config_get_i (core->config, "zign.bytes"); + bool useGraph = rz_config_get_i (core->config, "zign.graph"); + bool useOffset = rz_config_get_i (core->config, "zign.offset"); + bool useRefs = rz_config_get_i (core->config, "zign.refs"); + bool useHash = rz_config_get_i (core->config, "zign.hash"); + bool useTypes = rz_config_get_i (core->config, "zign.types"); + int maxsz = rz_config_get_i (core->config, "zign.maxsz"); if (rad) { - r_cons_printf ("fs+%s\n", zign_prefix); + rz_cons_printf ("fs+%s\n", zign_prefix); } else { - if (!r_flag_space_push (core->flags, zign_prefix)) { + if (!rz_flag_space_push (core->flags, zign_prefix)) { eprintf ("error: cannot create flagspace\n"); return false; } @@ -804,71 +804,71 @@ static bool search(RCore *core, bool rad, bool only_func) { // Bytes search if (useBytes && !only_func) { - list = r_core_get_boundaries_prot (core, -1, mode, "search"); + list = rz_core_get_boundaries_prot (core, -1, mode, "search"); if (!list) { return false; } - r_list_foreach (list, iter, map) { - eprintf ("[+] searching 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", map->itv.addr, r_itv_end (map->itv)); - retval &= searchRange (core, map->itv.addr, r_itv_end (map->itv), rad, &bytes_search_ctx); + rz_list_foreach (list, iter, map) { + eprintf ("[+] searching 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", map->itv.addr, rz_itv_end (map->itv)); + retval &= searchRange (core, map->itv.addr, rz_itv_end (map->itv), rad, &bytes_search_ctx); } - r_list_free (list); + rz_list_free (list); } // Function search // TODO (oxcabe): Refactor big conditional if (useGraph || useOffset || useRefs || useHash || (useBytes && only_func) || useTypes) { eprintf ("[+] searching function metrics\n"); - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); int count = 0; - RSignSearch *ss = NULL; + RzSignSearch *ss = NULL; if (useBytes && only_func) { - ss = r_sign_search_new (); - ss->search->align = r_config_get_i (core->config, "search.align"); - int minsz = r_config_get_i (core->config, "zign.minsz"); - r_sign_search_init (core->anal, ss, minsz, searchHitCB, &bytes_search_ctx); + ss = rz_sign_search_new (); + ss->search->align = rz_config_get_i (core->config, "search.align"); + int minsz = rz_config_get_i (core->config, "zign.minsz"); + rz_sign_search_init (core->anal, ss, minsz, searchHitCB, &bytes_search_ctx); } - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } if (useGraph) { - r_sign_match_graph (core->anal, fcni, mincc, fcnMatchCB, &graph_match_ctx); + rz_sign_match_graph (core->anal, fcni, mincc, fcnMatchCB, &graph_match_ctx); } if (useOffset) { - r_sign_match_addr (core->anal, fcni, fcnMatchCB, &offset_match_ctx); + rz_sign_match_addr (core->anal, fcni, fcnMatchCB, &offset_match_ctx); } if (useRefs) { - r_sign_match_refs (core->anal, fcni, fcnMatchCB, &refs_match_ctx); + rz_sign_match_refs (core->anal, fcni, fcnMatchCB, &refs_match_ctx); } if (useHash) { - r_sign_match_hash (core->anal, fcni, fcnMatchCB, &hash_match_ctx); + rz_sign_match_hash (core->anal, fcni, fcnMatchCB, &hash_match_ctx); } if (useBytes && only_func) { - eprintf ("Matching func %d / %d (hits %d)\n", count, r_list_length (core->anal->fcns), bytes_search_ctx.count); - int fcnlen = r_anal_function_realsize (fcni); + eprintf ("Matching func %d / %d (hits %d)\n", count, rz_list_length (core->anal->fcns), bytes_search_ctx.count); + int fcnlen = rz_anal_function_realsize (fcni); int len = R_MIN (core->io->addrbytes * fcnlen, maxsz); retval &= searchRange2 (core, ss, fcni->addr, fcni->addr + len, rad, &bytes_search_ctx); } if (useTypes) { - r_sign_match_types (core->anal, fcni, fcnMatchCB, &types_match_ctx); + rz_sign_match_types (core->anal, fcni, fcnMatchCB, &types_match_ctx); } count ++; #if 0 TODO: add useXRefs, useName #endif } - r_cons_break_pop (); - r_sign_search_free (ss); + rz_cons_break_pop (); + rz_sign_search_free (ss); } if (rad) { - r_cons_printf ("fs-\n"); + rz_cons_printf ("fs-\n"); } else { - if (!r_flag_space_pop (core->flags)) { + if (!rz_flag_space_pop (core->flags)) { eprintf ("error: cannot restore flagspace\n"); return false; } @@ -881,43 +881,43 @@ TODO: add useXRefs, useName return retval; } -static void print_possible_matches(RList *list) { - RListIter *itr; - RSignCloseMatch *row; - r_list_foreach (list, itr, row) { +static void print_possible_matches(RzList *list) { + RzListIter *itr; + RzSignCloseMatch *row; + rz_list_foreach (list, itr, row) { // total score if (row->bscore > 0.0 && row->gscore > 0.0) { - r_cons_printf ("%02.5lf ", row->score); + rz_cons_printf ("%02.5lf ", row->score); } if (row->bscore > 0.0) { - r_cons_printf ("%02.5lf B ", row->bscore); + rz_cons_printf ("%02.5lf B ", row->bscore); } if (row->gscore > 0.0) { - r_cons_printf ("%02.5lf G ", row->gscore); + rz_cons_printf ("%02.5lf G ", row->gscore); } - r_cons_printf (" %s\n", row->item->name); + rz_cons_printf (" %s\n", row->item->name); } } -static RSignItem *item_frm_signame(RAnal *a, const char *signame) { +static RzSignItem *item_frm_signame(RzAnal *a, const char *signame) { // example zign|*|sym.unlink_blk - const RSpace *space = r_spaces_current (&a->zign_spaces); - char *k = r_str_newf ("zign|%s|%s", space? space->name: "*", signame); + const RSpace *space = rz_spaces_current (&a->zign_spaces); + char *k = rz_str_newf ("zign|%s|%s", space? space->name: "*", signame); char *value = sdb_querys (a->sdb_zigns, NULL, 0, k); if (!value) { free (k); return NULL; } - RSignItem *it = r_sign_item_new (); + RzSignItem *it = rz_sign_item_new (); if (!it) { free (k); free (value); return NULL; } - if (!r_sign_deserialize (a, it, k, value)) { - r_sign_item_free (it); + if (!rz_sign_deserialize (a, it, k, value)) { + rz_sign_item_free (it); it = NULL; } free (k); @@ -925,9 +925,9 @@ static RSignItem *item_frm_signame(RAnal *a, const char *signame) { return it; } -static double get_zb_threshold(RCore *core) { - const char *th = r_config_get (core->config, "zign.threshold"); - double thresh = r_num_get_float (NULL, th); +static double get_zb_threshold(RzCore *core) { + const char *th = rz_config_get (core->config, "zign.threshold"); + double thresh = rz_num_get_float (NULL, th); if (thresh < 0.0 || thresh > 1.0) { eprintf ("Invalid zign.threshold %s, using 0.0\n", th); thresh = 0.0; @@ -935,10 +935,10 @@ static double get_zb_threshold(RCore *core) { return thresh; } -static bool bestmatch_fcn(RCore *core, const char *input) { - r_return_val_if_fail (input && core, false); +static bool bestmatch_fcn(RzCore *core, const char *input) { + rz_return_val_if_fail (input && core, false); - char *argv = r_str_new (input); + char *argv = rz_str_new (input); if (!argv) { return false; } @@ -963,7 +963,7 @@ static bool bestmatch_fcn(RCore *core, const char *input) { return false; } } - RSignItem *it = item_frm_signame (core->anal, zigname); + RzSignItem *it = item_frm_signame (core->anal, zigname); if (!it) { eprintf ("Couldn't get signature for %s\n", zigname); free (argv); @@ -971,29 +971,29 @@ static bool bestmatch_fcn(RCore *core, const char *input) { } free (argv); - if (!r_config_get_i (core->config, "zign.bytes")) { - r_sign_bytes_free (it->bytes); + if (!rz_config_get_i (core->config, "zign.bytes")) { + rz_sign_bytes_free (it->bytes); it->bytes = NULL; } - if (!r_config_get_i (core->config, "zign.graph")) { - r_sign_graph_free (it->graph); + if (!rz_config_get_i (core->config, "zign.graph")) { + rz_sign_graph_free (it->graph); it->graph = NULL; } double thresh = get_zb_threshold (core); - RList *list = r_sign_find_closest_fcn (core->anal, it, count, thresh); - r_sign_item_free (it); + RzList *list = rz_sign_find_closest_fcn (core->anal, it, count, thresh); + rz_sign_item_free (it); if (list) { print_possible_matches (list); - r_list_free (list); + rz_list_free (list); return true; } return false; } -static bool bestmatch_sig(RCore *core, const char *input) { - r_return_val_if_fail (input && core, false); +static bool bestmatch_sig(RzCore *core, const char *input) { + rz_return_val_if_fail (input && core, false); int count = 5; if (!R_STR_ISEMPTY (input)) { count = atoi (input); @@ -1003,53 +1003,53 @@ static bool bestmatch_sig(RCore *core, const char *input) { } } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (!fcn) { eprintf ("No function at 0x%08" PFMT64x "\n", core->offset); return false; } - RSignItem *item = r_sign_item_new (); + RzSignItem *item = rz_sign_item_new (); if (!item) { return false; } - if (r_config_get_i (core->config, "zign.bytes")) { - r_sign_addto_item (core->anal, item, fcn, R_SIGN_BYTES); - RSignBytes *b = item->bytes; - int minsz = r_config_get_i (core->config, "zign.minsz"); + if (rz_config_get_i (core->config, "zign.bytes")) { + rz_sign_addto_item (core->anal, item, fcn, R_SIGN_BYTES); + RzSignBytes *b = item->bytes; + int minsz = rz_config_get_i (core->config, "zign.minsz"); if (b && b->size < minsz) { eprintf ("Warning: Function signature is too small (%d < %d) See e zign.minsz", b->size, minsz); - r_sign_item_free (item); + rz_sign_item_free (item); return false; } } - if (r_config_get_i (core->config, "zign.graph")) { - r_sign_addto_item (core->anal, item, fcn, R_SIGN_GRAPH); + if (rz_config_get_i (core->config, "zign.graph")) { + rz_sign_addto_item (core->anal, item, fcn, R_SIGN_GRAPH); } double th = get_zb_threshold (core); bool found = false; if (item->graph || item->bytes) { - r_cons_break_push (NULL, NULL); - RList *list = r_sign_find_closest_sig (core->anal, item, count, th); + rz_cons_break_push (NULL, NULL); + RzList *list = rz_sign_find_closest_sig (core->anal, item, count, th); if (list) { found = true; print_possible_matches (list); - r_list_free (list); + rz_list_free (list); } - r_cons_break_pop (); + rz_cons_break_pop (); } else { eprintf ("Warning: no signatures types available for testing\n"); } - r_sign_item_free (item); + rz_sign_item_free (item); return found; } static bool bestmatch(void *data, const char *input) { - r_return_val_if_fail (data && input, false); - RCore *core = (RCore *)data; + rz_return_val_if_fail (data && input, false); + RzCore *core = (RzCore *)data; switch (input[0]) { case 'r': input++; @@ -1062,17 +1062,17 @@ static bool bestmatch(void *data, const char *input) { break; case '?': default: - r_core_cmd_help (core, help_msg_zb); + rz_core_cmd_help (core, help_msg_zb); return false; } } static int cmdCompare(void *data, const char *input) { int result = true; - RCore *core = (RCore *) data; - const char *raw_bytes_thresh = r_config_get (core->config, "zign.diff.bthresh"); - const char *raw_graph_thresh = r_config_get (core->config, "zign.diff.gthresh"); - RSignOptions *options = r_sign_options_new (raw_bytes_thresh, raw_graph_thresh); + RzCore *core = (RzCore *) data; + const char *raw_bytes_thresh = rz_config_get (core->config, "zign.diff.bthresh"); + const char *raw_graph_thresh = rz_config_get (core->config, "zign.diff.gthresh"); + RzSignOptions *options = rz_sign_options_new (raw_bytes_thresh, raw_graph_thresh); switch (*input) { case ' ': @@ -1081,7 +1081,7 @@ static int cmdCompare(void *data, const char *input) { result = false; break; } - result = r_sign_diff (core->anal, options, input + 1); + result = rz_sign_diff (core->anal, options, input + 1); break; case 'n': switch (input[1]) { @@ -1091,7 +1091,7 @@ static int cmdCompare(void *data, const char *input) { result = false; break; } - result = r_sign_diff_by_name (core->anal, options, input + 2, false); + result = rz_sign_diff_by_name (core->anal, options, input + 2, false); break; case '!': if (input[2] != ' ' || !input[3]) { @@ -1099,7 +1099,7 @@ static int cmdCompare(void *data, const char *input) { result = false; break; } - result = r_sign_diff_by_name (core->anal, options, input + 3, true); + result = rz_sign_diff_by_name (core->anal, options, input + 3, true); break; default: eprintf ("Usage: zcn! other_space\n"); @@ -1107,23 +1107,23 @@ static int cmdCompare(void *data, const char *input) { } break; case '?': - r_core_cmd_help (core, help_msg_zc); + rz_core_cmd_help (core, help_msg_zc); break; default: eprintf ("Usage: zc[?n!] other_space\n"); result = false; } - r_sign_options_free (options); + rz_sign_options_free (options); return result; } static int cmdCheck(void *data, const char *input) { - RCore *core = (RCore *) data; - RSignSearch *ss; - RListIter *iter; - RAnalFunction *fcni = NULL; + RzCore *core = (RzCore *) data; + RzSignSearch *ss; + RzListIter *iter; + RzAnalFunction *fcni = NULL; ut64 at = core->offset; bool retval = true; bool rad = input[0] == '*'; @@ -1136,20 +1136,20 @@ static int cmdCheck(void *data, const char *input) { struct ctxSearchCB hash_match_ctx = { core, rad, 0, "bbhash" }; struct ctxSearchCB types_match_ctx = { core, rad, 0, "types" }; - const char *zign_prefix = r_config_get (core->config, "zign.prefix"); - int minsz = r_config_get_i (core->config, "zign.minsz"); - int mincc = r_config_get_i (core->config, "zign.mincc"); - bool useBytes = r_config_get_i (core->config, "zign.bytes"); - bool useGraph = r_config_get_i (core->config, "zign.graph"); - bool useOffset = r_config_get_i (core->config, "zign.offset"); - bool useRefs = r_config_get_i (core->config, "zign.refs"); - bool useHash = r_config_get_i (core->config, "zign.hash"); - bool useTypes = r_config_get_i (core->config, "zign.types"); + const char *zign_prefix = rz_config_get (core->config, "zign.prefix"); + int minsz = rz_config_get_i (core->config, "zign.minsz"); + int mincc = rz_config_get_i (core->config, "zign.mincc"); + bool useBytes = rz_config_get_i (core->config, "zign.bytes"); + bool useGraph = rz_config_get_i (core->config, "zign.graph"); + bool useOffset = rz_config_get_i (core->config, "zign.offset"); + bool useRefs = rz_config_get_i (core->config, "zign.refs"); + bool useHash = rz_config_get_i (core->config, "zign.hash"); + bool useTypes = rz_config_get_i (core->config, "zign.types"); if (rad) { - r_cons_printf ("fs+%s\n", zign_prefix); + rz_cons_printf ("fs+%s\n", zign_prefix); } else { - if (!r_flag_space_push (core->flags, zign_prefix)) { + if (!rz_flag_space_push (core->flags, zign_prefix)) { eprintf ("error: cannot create flagspace\n"); return false; } @@ -1158,49 +1158,49 @@ static int cmdCheck(void *data, const char *input) { // Bytes search if (useBytes) { eprintf ("[+] searching 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", at, at + core->blocksize); - ss = r_sign_search_new (); - r_sign_search_init (core->anal, ss, minsz, searchHitCB, &bytes_search_ctx); - if (r_sign_search_update (core->anal, ss, &at, core->block, core->blocksize) == -1) { + ss = rz_sign_search_new (); + rz_sign_search_init (core->anal, ss, minsz, searchHitCB, &bytes_search_ctx); + if (rz_sign_search_update (core->anal, ss, &at, core->block, core->blocksize) == -1) { eprintf ("search: update read error at 0x%08"PFMT64x"\n", at); retval = false; } - r_sign_search_free (ss); + rz_sign_search_free (ss); } // Function search if (useGraph || useOffset || useRefs || useHash || useTypes) { eprintf ("[+] searching function metrics\n"); - r_cons_break_push (NULL, NULL); - r_list_foreach (core->anal->fcns, iter, fcni) { - if (r_cons_is_breaked ()) { + rz_cons_break_push (NULL, NULL); + rz_list_foreach (core->anal->fcns, iter, fcni) { + if (rz_cons_is_breaked ()) { break; } if (fcni->addr == core->offset) { if (useGraph) { - r_sign_match_graph (core->anal, fcni, mincc, fcnMatchCB, &graph_match_ctx); + rz_sign_match_graph (core->anal, fcni, mincc, fcnMatchCB, &graph_match_ctx); } if (useOffset) { - r_sign_match_addr (core->anal, fcni, fcnMatchCB, &offset_match_ctx); + rz_sign_match_addr (core->anal, fcni, fcnMatchCB, &offset_match_ctx); } if (useRefs){ - r_sign_match_refs (core->anal, fcni, fcnMatchCB, &refs_match_ctx); + rz_sign_match_refs (core->anal, fcni, fcnMatchCB, &refs_match_ctx); } if (useHash){ - r_sign_match_hash (core->anal, fcni, fcnMatchCB, &hash_match_ctx); + rz_sign_match_hash (core->anal, fcni, fcnMatchCB, &hash_match_ctx); } if (useTypes) { - r_sign_match_types (core->anal, fcni, fcnMatchCB, &types_match_ctx); + rz_sign_match_types (core->anal, fcni, fcnMatchCB, &types_match_ctx); } break; } } - r_cons_break_pop (); + rz_cons_break_pop (); } if (rad) { - r_cons_printf ("fs-\n"); + rz_cons_printf ("fs-\n"); } else { - if (!r_flag_space_pop (core->flags)) { + if (!rz_flag_space_pop (core->flags)) { eprintf ("error: cannot restore flagspace\n"); return false; } @@ -1214,7 +1214,7 @@ static int cmdCheck(void *data, const char *input) { } static int cmdSearch(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; switch (*input) { case 0: @@ -1230,7 +1230,7 @@ static int cmdSearch(void *data, const char *input) { return false; } case '?': - r_core_cmd_help (core, help_msg_z_slash); + rz_core_cmd_help (core, help_msg_z_slash); break; default: eprintf ("Usage: z/[*]\n"); @@ -1243,15 +1243,15 @@ static int cmdInfo(void *data, const char *input) { if (!data || !input) { return false; } - RCore *core = (RCore *) data; - r_flag_space_push (core->flags, R_FLAGS_FS_SIGNS); - r_flag_list (core->flags, *input, input[0] ? input + 1: ""); - r_flag_space_pop (core->flags); + RzCore *core = (RzCore *) data; + rz_flag_space_push (core->flags, R_FLAGS_FS_SIGNS); + rz_flag_list (core->flags, *input, input[0] ? input + 1: ""); + rz_flag_space_pop (core->flags); return true; } static int cmd_zign(void *data, const char *input) { - RCore *core = (RCore *) data; + RzCore *core = (RzCore *) data; const char *arg = input + 1; switch (*input) { @@ -1259,13 +1259,13 @@ static int cmd_zign(void *data, const char *input) { case '*': case 'q': case 'j': // "zj" - r_sign_list (core->anal, *input); + rz_sign_list (core->anal, *input); break; case 'k': // "zk" - r_core_cmd0 (core, "k anal/zigns/*"); + rz_core_cmd0 (core, "k anal/zigns/*"); break; case '-': // "z-" - r_sign_delete (core->anal, arg); + rz_sign_delete (core->anal, arg); break; case '.': // "z." return cmdCheck (data, arg); @@ -1288,10 +1288,10 @@ static int cmd_zign(void *data, const char *input) { case 'i': // "zi" return cmdInfo (data, arg); case '?': // "z?" - r_core_cmd_help (core, help_msg_z); + rz_core_cmd_help (core, help_msg_z); break; default: - r_core_cmd_help (core, help_msg_z); + rz_core_cmd_help (core, help_msg_z); return false; } diff --git a/libr/core/core.c b/librz/core/core.c similarity index 60% rename from libr/core/core.c rename to librz/core/core.c index 34c4e10af3..00329cbc30 100644 --- a/libr/core/core.c +++ b/librz/core/core.c @@ -1,16 +1,16 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake */ +/* rizin - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #include -#include +#include #if __UNIX__ #include #endif #define DB core->sdb -R_LIB_VERSION(r_core); +R_LIB_VERSION(rz_core); static ut64 letter_divs[R_CORE_ASMQJMPS_LEN_LETTERS - 1] = { R_CORE_ASMQJMPS_LETTERS * R_CORE_ASMQJMPS_LETTERS * R_CORE_ASMQJMPS_LETTERS * R_CORE_ASMQJMPS_LETTERS, @@ -19,74 +19,74 @@ static ut64 letter_divs[R_CORE_ASMQJMPS_LEN_LETTERS - 1] = { R_CORE_ASMQJMPS_LETTERS }; -extern bool r_core_is_project (RCore *core, const char *name); +extern bool rz_core_is_project (RzCore *core, const char *name); -static int on_fcn_new(RAnal *_anal, void* _user, RAnalFunction *fcn) { - RCore *core = (RCore*)_user; - const char *cmd = r_config_get (core->config, "cmd.fcn.new"); +static int on_fcn_new(RzAnal *_anal, void* _user, RzAnalFunction *fcn) { + RzCore *core = (RzCore*)_user; + const char *cmd = rz_config_get (core->config, "cmd.fcn.new"); if (cmd && *cmd) { ut64 oaddr = core->offset; ut64 addr = fcn->addr; - r_core_seek (core, addr, true); - r_core_cmd0 (core, cmd); - r_core_seek (core, oaddr, true); + rz_core_seek (core, addr, true); + rz_core_cmd0 (core, cmd); + rz_core_seek (core, oaddr, true); } return 0; } -static int on_fcn_delete (RAnal *_anal, void* _user, RAnalFunction *fcn) { - RCore *core = (RCore*)_user; - const char *cmd = r_config_get (core->config, "cmd.fcn.delete"); +static int on_fcn_delete (RzAnal *_anal, void* _user, RzAnalFunction *fcn) { + RzCore *core = (RzCore*)_user; + const char *cmd = rz_config_get (core->config, "cmd.fcn.delete"); if (cmd && *cmd) { ut64 oaddr = core->offset; ut64 addr = fcn->addr; - r_core_seek (core, addr, true); - r_core_cmd0 (core, cmd); - r_core_seek (core, oaddr, true); + rz_core_seek (core, addr, true); + rz_core_cmd0 (core, cmd); + rz_core_seek (core, oaddr, true); } return 0; } -static int on_fcn_rename(RAnal *_anal, void* _user, RAnalFunction *fcn, const char *oname) { - RCore *core = (RCore*)_user; - const char *cmd = r_config_get (core->config, "cmd.fcn.rename"); +static int on_fcn_rename(RzAnal *_anal, void* _user, RzAnalFunction *fcn, const char *oname) { + RzCore *core = (RzCore*)_user; + const char *cmd = rz_config_get (core->config, "cmd.fcn.rename"); if (cmd && *cmd) { // XXX: wat do with old name here? ut64 oaddr = core->offset; ut64 addr = fcn->addr; - r_core_seek (core, addr, true); - r_core_cmd0 (core, cmd); - r_core_seek (core, oaddr, true); + rz_core_seek (core, addr, true); + rz_core_cmd0 (core, cmd); + rz_core_seek (core, oaddr, true); } return 0; } -static void r_core_debug_breakpoint_hit(RCore *core, RBreakpointItem *bpi) { - const char *cmdbp = r_config_get (core->config, "cmd.bp"); +static void rz_core_debug_breakpoint_hit(RzCore *core, RBreakpointItem *bpi) { + const char *cmdbp = rz_config_get (core->config, "cmd.bp"); const bool cmdbp_exists = (cmdbp && *cmdbp); const bool bpcmd_exists = (bpi->data && bpi->data[0]); const bool may_output = (cmdbp_exists || bpcmd_exists); if (may_output) { - r_cons_push (); + rz_cons_push (); } if (cmdbp_exists) { - r_core_cmd0 (core, cmdbp); + rz_core_cmd0 (core, cmdbp); } if (bpcmd_exists) { - r_core_cmd0 (core, bpi->data); + rz_core_cmd0 (core, bpi->data); } if (may_output) { - r_cons_flush (); - r_cons_pop (); + rz_cons_flush (); + rz_cons_pop (); } } -static void r_core_debug_syscall_hit(RCore *core) { - const char *cmdhit = r_config_get (core->config, "cmd.onsyscall"); +static void rz_core_debug_syscall_hit(RzCore *core) { + const char *cmdhit = rz_config_get (core->config, "cmd.onsyscall"); if (cmdhit && cmdhit[0] != 0) { - r_core_cmd0 (core, cmdhit); - r_cons_flush (); + rz_core_cmd0 (core, cmdhit); + rz_cons_flush (); } } @@ -110,16 +110,16 @@ static int getreloc_tree(const void *user, const RBNode *n, void *user2) { return 0; } -R_API RBinReloc *r_core_getreloc(RCore *core, ut64 addr, int size) { +RZ_API RBinReloc *rz_core_getreloc(RzCore *core, ut64 addr, int size) { if (size < 1 || addr == UT64_MAX) { return NULL; } - RBNode *relocs = r_bin_get_relocs (core->bin); + RBNode *relocs = rz_bin_get_relocs (core->bin); if (!relocs) { return NULL; } struct getreloc_t gr = { .vaddr = addr, .size = size }; - RBNode *res = r_rbtree_find (relocs, &gr, getreloc_tree, NULL); + RBNode *res = rz_rbtree_find (relocs, &gr, getreloc_tree, NULL); return res? container_of (res, RBinReloc, vrb): NULL; } @@ -128,7 +128,7 @@ R_API RBinReloc *r_core_getreloc(RCore *core, ut64 addr, int size) { * should be of the form XYZWu, where XYZW are uppercase letters and u is a * lowercase one. If is_asmqjmps_letter is false, the string should be a number * between 1 and 9 included. */ -R_API ut64 r_core_get_asmqjmps(RCore *core, const char *str) { +RZ_API ut64 rz_core_get_asmqjmps(RzCore *core, const char *str) { if (!core->asmqjmps) { return UT64_MAX; } @@ -163,7 +163,7 @@ R_API ut64 r_core_get_asmqjmps(RCore *core, const char *str) { * Takes addr and returns already saved shortcut or a new one * The returned buffer needs to be freed */ -R_API char* r_core_add_asmqjmp(RCore *core, ut64 addr) { +RZ_API char* rz_core_add_asmqjmp(RzCore *core, ut64 addr) { bool found = false; if (!core->asmqjmps) { return NULL; @@ -197,7 +197,7 @@ R_API char* r_core_add_asmqjmp(RCore *core, ut64 addr) { if (i < 1) { return NULL; } - r_core_set_asmqjmps (core, t, sizeof (t), i); + rz_core_set_asmqjmps (core, t, sizeof (t), i); return strdup (t); } return NULL; @@ -205,9 +205,9 @@ R_API char* r_core_add_asmqjmp(RCore *core, ut64 addr) { /* returns in str a string that represents the shortcut to access the asmqjmp * at position pos. When is_asmqjmps_letter is true, pos is converted into a - * multiletter shortcut of the form XYWZu and returned (see r_core_get_asmqjmps + * multiletter shortcut of the form XYWZu and returned (see rz_core_get_asmqjmps * for more info). Otherwise, the shortcut is the string representation of pos. */ -R_API void r_core_set_asmqjmps(RCore *core, char *str, size_t len, int pos) { +RZ_API void rz_core_set_asmqjmps(RzCore *core, char *str, size_t len, int pos) { if (core->is_asmqjmps_letter) { int i, j = 0; // if (pos > 0) { @@ -230,17 +230,17 @@ R_API void r_core_set_asmqjmps(RCore *core, char *str, size_t len, int pos) { } } -static void setab(RCore *core, const char *arch, int bits) { +static void setab(RzCore *core, const char *arch, int bits) { if (arch) { - r_config_set (core->config, "asm.arch", arch); + rz_config_set (core->config, "asm.arch", arch); } if (bits > 0) { - r_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "asm.bits", bits); } } -static const char *getName(RCore *core, ut64 addr) { - RFlagItem *item = r_flag_get_i (core->flags, addr); +static const char *getName(RzCore *core, ut64 addr) { + RzFlagItem *item = rz_flag_get_i (core->flags, addr); if (item) { if (core->flags->realnames) { return item->realname @@ -251,40 +251,40 @@ static const char *getName(RCore *core, ut64 addr) { return NULL; } -static char *getNameDelta(RCore *core, ut64 addr) { - RFlagItem *item = r_flag_get_at (core->flags, addr, true); +static char *getNameDelta(RzCore *core, ut64 addr) { + RzFlagItem *item = rz_flag_get_at (core->flags, addr, true); if (item) { if (item->offset != addr) { - return r_str_newf ("%s + %d", item->name, (int)(addr - item->offset)); + return rz_str_newf ("%s + %d", item->name, (int)(addr - item->offset)); } return strdup (item->name); } return NULL; } -static void archbits(RCore *core, ut64 addr) { - r_core_seek_arch_bits (core, addr); +static void archbits(RzCore *core, ut64 addr) { + rz_core_seek_arch_bits (core, addr); } -static int cfggeti(RCore *core, const char *k) { - return r_config_get_i (core->config, k); +static int cfggeti(RzCore *core, const char *k) { + return rz_config_get_i (core->config, k); } -static const char *cfgget(RCore *core, const char *k) { - return r_config_get (core->config, k); +static const char *cfgget(RzCore *core, const char *k) { + return rz_config_get (core->config, k); } -static ut64 numget(RCore *core, const char *k) { - return r_num_math (core->num, k); +static ut64 numget(RzCore *core, const char *k) { + return rz_num_math (core->num, k); } -static bool __isMapped(RCore *core, ut64 addr, int perm) { - if (r_config_get_i (core->config, "cfg.debug")) { - // RList *maps = core->dbg->maps; - RDebugMap *map = NULL; - RListIter *iter = NULL; +static bool __isMapped(RzCore *core, ut64 addr, int perm) { + if (rz_config_get_i (core->config, "cfg.debug")) { + // RzList *maps = core->dbg->maps; + RzDebugMap *map = NULL; + RzListIter *iter = NULL; - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { if (perm > 0) { if (map->perm & perm) { @@ -299,78 +299,78 @@ static bool __isMapped(RCore *core, ut64 addr, int perm) { return false; } - return r_io_map_is_mapped (core->io, addr); + return rz_io_map_is_mapped (core->io, addr); } -static bool __syncDebugMaps(RCore *core) { - if (r_config_get_i (core->config, "cfg.debug")) { - return r_debug_map_sync (core->dbg); +static bool __syncDebugMaps(RzCore *core) { + if (rz_config_get_i (core->config, "cfg.debug")) { + return rz_debug_map_sync (core->dbg); } return false; } -R_API int r_core_bind(RCore *core, RCoreBind *bnd) { +RZ_API int rz_core_bind(RzCore *core, RzCoreBind *bnd) { bnd->core = core; - bnd->bphit = (RCoreDebugBpHit)r_core_debug_breakpoint_hit; - bnd->syshit = (RCoreDebugSyscallHit)r_core_debug_syscall_hit; - bnd->cmd = (RCoreCmd)r_core_cmd0; - bnd->cmdf = (RCoreCmdF)r_core_cmdf; - bnd->cmdstr = (RCoreCmdStr)r_core_cmd_str; - bnd->cmdstrf = (RCoreCmdStrF)r_core_cmd_strf; - bnd->puts = (RCorePuts)r_cons_strcat; - bnd->setab = (RCoreSetArchBits)setab; - bnd->getName = (RCoreGetName)getName; - bnd->getNameDelta = (RCoreGetNameDelta)getNameDelta; - bnd->archbits = (RCoreSeekArchBits)archbits; - bnd->cfggeti = (RCoreConfigGetI)cfggeti; - bnd->cfgGet = (RCoreConfigGet)cfgget; - bnd->numGet = (RCoreNumGet)numget; - bnd->isMapped = (RCoreIsMapped)__isMapped; - bnd->syncDebugMaps = (RCoreDebugMapsSync)__syncDebugMaps; + bnd->bphit = (RzCoreDebugBpHit)rz_core_debug_breakpoint_hit; + bnd->syshit = (RzCoreDebugSyscallHit)rz_core_debug_syscall_hit; + bnd->cmd = (RzCoreCmd)rz_core_cmd0; + bnd->cmdf = (RzCoreCmdF)rz_core_cmdf; + bnd->cmdstr = (RzCoreCmdStr)rz_core_cmd_str; + bnd->cmdstrf = (RzCoreCmdStrF)rz_core_cmd_strf; + bnd->puts = (RzCorePuts)rz_cons_strcat; + bnd->setab = (RzCoreSetArchBits)setab; + bnd->getName = (RzCoreGetName)getName; + bnd->getNameDelta = (RzCoreGetNameDelta)getNameDelta; + bnd->archbits = (RzCoreSeekArchBits)archbits; + bnd->cfggeti = (RzCoreConfigGetI)cfggeti; + bnd->cfgGet = (RzCoreConfigGet)cfgget; + bnd->numGet = (RzCoreNumGet)numget; + bnd->isMapped = (RzCoreIsMapped)__isMapped; + bnd->syncDebugMaps = (RzCoreDebugMapsSync)__syncDebugMaps; return true; } -R_API RCore *r_core_ncast(ut64 p) { - return (RCore*)(size_t)p; +RZ_API RzCore *rz_core_ncast(ut64 p) { + return (RzCore*)(size_t)p; } -R_API RCore *r_core_cast(void *p) { - return (RCore*)p; +RZ_API RzCore *rz_core_cast(void *p) { + return (RzCore*)p; } -static ut64 getref (RCore *core, int n, char t, int type) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - RListIter *iter; - RAnalRef *r; - RList *list; +static ut64 getref (RzCore *core, int n, char t, int type) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + RzListIter *iter; + RzAnalRef *r; + RzList *list; int i = 0; if (!fcn) { return UT64_MAX; } if (t == 'r') { - list = r_anal_function_get_refs (fcn); + list = rz_anal_function_get_refs (fcn); } else { - list = r_anal_function_get_xrefs (fcn); + list = rz_anal_function_get_xrefs (fcn); } - r_list_foreach (list, iter, r) { + rz_list_foreach (list, iter, r) { if (r->type == type) { if (i == n) { ut64 addr = r->addr; - r_list_free (list); + rz_list_free (list); return addr; } i++; } } - r_list_free (list); + rz_list_free (list); return UT64_MAX; } -static ut64 bbInstructions(RAnalFunction *fcn, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { +static ut64 bbInstructions(RzAnalFunction *fcn, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (R_BETWEEN (bb->addr, addr, bb->addr + bb->size - 1)) { return bb->ninstr; } @@ -378,10 +378,10 @@ static ut64 bbInstructions(RAnalFunction *fcn, ut64 addr) { return UT64_MAX; } -static ut64 bbBegin(RAnalFunction *fcn, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { +static ut64 bbBegin(RzAnalFunction *fcn, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (R_BETWEEN (bb->addr, addr, bb->addr + bb->size - 1)) { return bb->addr; } @@ -389,10 +389,10 @@ static ut64 bbBegin(RAnalFunction *fcn, ut64 addr) { return UT64_MAX; } -static ut64 bbJump(RAnalFunction *fcn, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { +static ut64 bbJump(RzAnalFunction *fcn, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (R_BETWEEN (bb->addr, addr, bb->addr + bb->size - 1)) { return bb->jump; } @@ -400,10 +400,10 @@ static ut64 bbJump(RAnalFunction *fcn, ut64 addr) { return UT64_MAX; } -static ut64 bbFail(RAnalFunction *fcn, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { +static ut64 bbFail(RzAnalFunction *fcn, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (R_BETWEEN (bb->addr, addr, bb->addr + bb->size - 1)) { return bb->fail; } @@ -411,10 +411,10 @@ static ut64 bbFail(RAnalFunction *fcn, ut64 addr) { return UT64_MAX; } -static ut64 bbSize(RAnalFunction *fcn, ut64 addr) { - RListIter *iter; - RAnalBlock *bb; - r_list_foreach (fcn->bbs, iter, bb) { +static ut64 bbSize(RzAnalFunction *fcn, ut64 addr) { + RzListIter *iter; + RzAnalBlock *bb; + rz_list_foreach (fcn->bbs, iter, bb) { if (R_BETWEEN (bb->addr, addr, bb->addr + bb->size - 1)) { return bb->size; } @@ -423,12 +423,12 @@ static ut64 bbSize(RAnalFunction *fcn, ut64 addr) { } static const char *str_callback(RNum *user, ut64 off, int *ok) { - RFlag *f = (RFlag*)user; + RzFlag *f = (RzFlag*)user; if (ok) { *ok = 0; } if (f) { - RFlagItem *item = r_flag_get_i (f, off); + RzFlagItem *item = rz_flag_get_i (f, off); if (item) { if (ok) { *ok = true; @@ -440,12 +440,12 @@ static const char *str_callback(RNum *user, ut64 off, int *ok) { } static ut64 num_callback(RNum *userptr, const char *str, int *ok) { - RCore *core = (RCore *)userptr; // XXX ? - RAnalFunction *fcn; + RzCore *core = (RzCore *)userptr; // XXX ? + RzAnalFunction *fcn; char *ptr, *bptr, *out = NULL; - RFlagItem *flag; + RzFlagItem *flag; RBinSection *s; - RAnalOp op; + RzAnalOp op; ut64 ret = 0; if (ok) { @@ -457,19 +457,19 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { if (ok) { *ok = true; } - return r_num_tail (core->num, core->offset, str + 2); + return rz_num_tail (core->num, core->offset, str + 2); } if (core->num->nc.curr_tok == '+') { ut64 off = core->num->nc.number_value.n; if (!off) { off = core->offset; } - RAnalFunction *fcn = r_anal_get_function_at (core->anal, off); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, off); if (fcn) { if (ok) { *ok = true; } - ut64 dst = r_anal_function_get_label (fcn, str + 1); + ut64 dst = rz_anal_function_get_label (fcn, str + 1); if (dst == UT64_MAX) { dst = fcn->addr; } @@ -499,14 +499,14 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { const char *q; char *o = strdup (str + 1); if (o) { - q = r_num_calc_index (core->num, NULL); + q = rz_num_calc_index (core->num, NULL); if (q) { - if (r_str_replace_char (o, ']', 0)>0) { - n = r_num_math (core->num, o); + if (rz_str_replace_char (o, ']', 0)>0) { + n = rz_num_math (core->num, o); if (core->num->nc.errors) { return 0; } - r_num_calc_index (core->num, q); + rz_num_calc_index (core->num, q); } } free (o); @@ -519,16 +519,16 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { *ok = 1; } ut8 buf[sizeof (ut64)] = R_EMPTY; - (void)r_io_read_at (core->io, n, buf, R_MIN (sizeof (buf), refsz)); + (void)rz_io_read_at (core->io, n, buf, R_MIN (sizeof (buf), refsz)); switch (refsz) { case 8: - return r_read_ble64 (buf, core->print->big_endian); + return rz_read_ble64 (buf, core->print->big_endian); case 4: - return r_read_ble32 (buf, core->print->big_endian); + return rz_read_ble32 (buf, core->print->big_endian); case 2: - return r_read_ble16 (buf, core->print->big_endian); + return rz_read_ble16 (buf, core->print->big_endian); case 1: - return r_read_ble8 (buf); + return rz_read_ble8 (buf); default: eprintf ("Invalid reference size: %d (%s)\n", refsz, str); return 0LL; @@ -540,12 +540,12 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { *ok = 1; } // TODO: group analop-dependant vars after a char, so i can filter - r_anal_op (core->anal, &op, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC); - r_anal_op_fini (&op); // we don't need strings or pointers, just values, which are not nullified in fini - // XXX the above line is assuming op after fini keeps jump, fail, ptr, val, size and r_anal_op_is_eob() + rz_anal_op (core->anal, &op, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC); + rz_anal_op_fini (&op); // we don't need strings or pointers, just values, which are not nullified in fini + // XXX the above line is assuming op after fini keeps jump, fail, ptr, val, size and rz_anal_op_is_eob() switch (str[1]) { case '.': // can use pc, sp, a0, a1, ... - return r_debug_reg_get (core->dbg, str + 2); + return rz_debug_reg_get (core->dbg, str + 2); case 'k': // $k{kv} if (str[2] != '{') { eprintf ("Expected '{' after 'k'.\n"); @@ -565,7 +565,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { if (strstr (out, "$k{")) { eprintf ("Recursivity is not permitted here\n"); } else { - ret = r_num_math (core->num, out); + ret = rz_num_math (core->num, out); } } free (bptr); @@ -577,7 +577,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { ptr = strchr (bptr, '}'); if (ptr) { ptr[0] = '\0'; - ut64 ret = r_config_get_i (core->config, bptr); + ut64 ret = rz_config_get_i (core->config, bptr); free (bptr); return ret; } @@ -585,7 +585,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { free (bptr); break; case 'c': // $c console width - return r_cons_get_size (NULL); + return rz_cons_get_size (NULL); case 'r': // $r if (str[2] == '{') { bptr = strdup (str + 3); @@ -595,26 +595,26 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { break; } *ptr = 0; - if (r_config_get_i (core->config, "cfg.debug")) { - if (r_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { - RRegItem *r = r_reg_get (core->dbg->reg, bptr, -1); + if (rz_config_get_i (core->config, "cfg.debug")) { + if (rz_debug_reg_sync (core->dbg, R_REG_TYPE_GPR, false)) { + RzRegItem *r = rz_reg_get (core->dbg->reg, bptr, -1); if (r) { free (bptr); - return r_reg_get_value (core->dbg->reg, r); + return rz_reg_get_value (core->dbg->reg, r); } } } else { - RRegItem *r = r_reg_get (core->anal->reg, bptr, -1); + RzRegItem *r = rz_reg_get (core->anal->reg, bptr, -1); if (r) { free (bptr); - return r_reg_get_value (core->anal->reg, r); + return rz_reg_get_value (core->anal->reg, r); } } free (bptr); return 0; // UT64_MAX; } else { int rows; - (void)r_cons_get_size (&rows); + (void)rz_cons_get_size (&rows); return rows; } break; @@ -625,23 +625,23 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { if (flagLength > 0) { flagName[flagLength - 1] = 0; } - RFlagItem *flag = r_flag_get (core->flags, flagName); + RzFlagItem *flag = rz_flag_get (core->flags, flagName); free (flagName); if (flag) { return flag->offset + flag->size; } return UT64_MAX; } - return r_anal_op_is_eob (&op); + return rz_anal_op_is_eob (&op); case 'j': // $j jump address return op.jump; case 'p': // $p - return r_sys_getpid (); + return rz_sys_getpid (); case 'P': // $P return core->dbg->pid > 0 ? core->dbg->pid : 0; case 'f': // $f jump fail address if (str[2] == 'l') { // $fl flag length - RFlagItem *fi = r_flag_get_i (core->flags, core->offset); + RzFlagItem *fi = rz_flag_get_i (core->flags, core->offset); if (fi) { return fi->size; } @@ -654,10 +654,10 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { case 'M': { // $M map address ut64 lower = UT64_MAX; ut64 size = 0LL; - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { - lower = r_itv_begin (map->itv); - size = r_itv_size (map->itv); + lower = rz_itv_begin (map->itv); + size = rz_itv_size (map->itv); } if (str[1] == 'B') { @@ -688,34 +688,34 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { break; } *ptr = '\0'; - RFlagItem *flag = r_flag_get (core->flags, bptr); + RzFlagItem *flag = rz_flag_get (core->flags, bptr); ret = flag? flag->size: 0LL; // flag free (bptr); free (out); return ret; } else if (core->file) { - return r_io_fd_size (core->io, core->file->fd); + return rz_io_fd_size (core->io, core->file->fd); } return 0LL; case 'w': // $w word size - return r_config_get_i (core->config, "asm.bits") / 8; + return rz_config_get_i (core->config, "asm.bits") / 8; case 'S': // $S section offset { - RBinObject *bo = r_bin_cur_object (core->bin); - if (bo && (s = r_bin_get_section_at (bo, core->offset, true))) { + RBinObject *bo = rz_bin_cur_object (core->bin); + if (bo && (s = rz_bin_get_section_at (bo, core->offset, true))) { return (str[2] == 'S'? s->size: s->vaddr); } } return 0LL; case 'D': // $D if (str[2] == 'B') { // $DD - return r_debug_get_baddr (core->dbg, NULL); + return rz_debug_get_baddr (core->dbg, NULL); } else if (IS_DIGIT (str[2])) { return getref (core, atoi (str + 2), 'r', R_ANAL_REF_TYPE_DATA); } else { - RDebugMap *map; - RListIter *iter; - r_list_foreach (core->dbg->maps, iter, map) { + RzDebugMap *map; + RzListIter *iter; + rz_list_foreach (core->dbg->maps, iter, map) { if (core->offset >= map->addr && core->offset < map->addr_end) { return (str[2] == 'D')? map->size: map->addr; } @@ -727,7 +727,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { case '$': // $$ offset return str[2] == '$' ? core->prompt_offset : core->offset; case 'o': { // $o - RBinSection *s = r_bin_get_section_at (r_bin_cur_object (core->bin), core->offset, true); + RBinSection *s = rz_bin_get_section_at (rz_bin_cur_object (core->bin), core->offset, true); return s ? core->offset - s->vaddr + s->paddr : core->offset; break; } @@ -743,13 +743,13 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { case 'X': // $X nth xref return getref (core, atoi (str + 2), 'x', R_ANAL_REF_TYPE_CALL); case 'F': // $F function size - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { switch (str[2]) { /* function bounds (uppercase) */ case 'B': return fcn->addr; // begin - case 'E': return r_anal_function_max_addr (fcn); // end - case 'S': return (str[3]=='S') ? r_anal_function_realsize (fcn) : r_anal_function_linear_size (fcn); + case 'E': return rz_anal_function_max_addr (fcn); // end + case 'S': return (str[3]=='S') ? rz_anal_function_realsize (fcn) : rz_anal_function_linear_size (fcn); case 'I': return fcn->ninstr; /* basic blocks (lowercase) */ case 'b': return bbBegin (fcn, core->offset); @@ -767,7 +767,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { default: if (*str >= 'A') { // NOTE: functions override flags - RAnalFunction *fcn = r_anal_get_function_byname (core->anal, str); + RzAnalFunction *fcn = rz_anal_get_function_byname (core->anal, str); if (fcn) { if (ok) { *ok = true; @@ -775,14 +775,14 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { return fcn->addr; } #if 0 - ut64 addr = r_anal_fcn_label_get (core->anal, core->offset, str); + ut64 addr = rz_anal_fcn_label_get (core->anal, core->offset, str); if (addr != 0) { ret = addr; } else { ... } #endif - if ((flag = r_flag_get (core->flags, str))) { + if ((flag = rz_flag_get (core->flags, str))) { ret = flag->offset; if (ok) { *ok = true; @@ -791,18 +791,18 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { } // check for reg alias - struct r_reg_item_t *r = r_reg_get (core->dbg->reg, str, -1); + struct rz_reg_item_t *r = rz_reg_get (core->dbg->reg, str, -1); if (!r) { - int role = r_reg_get_name_idx (str); + int role = rz_reg_get_name_idx (str); if (role != -1) { - const char *alias = r_reg_get_name (core->dbg->reg, role); + const char *alias = rz_reg_get_name (core->dbg->reg, role); if (alias) { - r = r_reg_get (core->dbg->reg, alias, -1); + r = rz_reg_get (core->dbg->reg, alias, -1); if (r) { if (ok) { *ok = true; } - ret = r_reg_get_value (core->dbg->reg, r); + ret = rz_reg_get_value (core->dbg->reg, r); return ret; } } @@ -811,7 +811,7 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { if (ok) { *ok = true; } - ret = r_reg_get_value (core->dbg->reg, r); + ret = rz_reg_get_value (core->dbg->reg, r); return ret; } } @@ -821,10 +821,10 @@ static ut64 num_callback(RNum *userptr, const char *str, int *ok) { return ret; } -R_API RCore *r_core_new(void) { - RCore *c = R_NEW0 (RCore); +RZ_API RzCore *rz_core_new(void) { + RzCore *c = R_NEW0 (RzCore); if (c) { - r_core_init (c); + rz_core_init (c); } return c; } @@ -1028,83 +1028,83 @@ static const char *radare_argv[] = { NULL }; -static void autocomplete_mount_point (RLineCompletion *completion, RCore *core, const char *path) { - RFSRoot *r; - RListIter *iter; - r_list_foreach (core->fs->roots, iter, r) { +static void autocomplete_mount_point (RLineCompletion *completion, RzCore *core, const char *path) { + RzFSRoot *r; + RzListIter *iter; + rz_list_foreach (core->fs->roots, iter, r) { char *base = strdup (r->path); - char *ls = (char *) r_str_lchr (base, '/'); + char *ls = (char *) rz_str_lchr (base, '/'); if (ls) { ls++; *ls = 0; } if (!strcmp (path, base)) { - r_line_completion_push (completion, r->path); + rz_line_completion_push (completion, r->path); } free (base); } } -static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const char *str, const char *path) { +static void autocomplete_ms_path(RLineCompletion *completion, RzCore *core, const char *str, const char *path) { char *lpath = NULL, *dirname = NULL , *basename = NULL; char *p = NULL; char *pwd = (core->rfs && *(core->rfs->cwd)) ? *(core->rfs->cwd): "."; int n = 0; - RList *list; - RListIter *iter; - RFSFile *file; - r_return_if_fail (path); - lpath = r_str_new (path); - p = (char *)r_str_last (lpath, R_SYS_DIR); + RzList *list; + RzListIter *iter; + RzFSFile *file; + rz_return_if_fail (path); + lpath = rz_str_new (path); + p = (char *)rz_str_last (lpath, R_SYS_DIR); if (p) { *p = 0; if (p == lpath) { // /xxx - dirname = r_str_new ("/"); + dirname = rz_str_new ("/"); } else if (lpath[0] == '.') { // ./xxx/yyy - dirname = r_str_newf ("%s%s", pwd, R_SYS_DIR); + dirname = rz_str_newf ("%s%s", pwd, R_SYS_DIR); } else if (lpath[0] == '/') { // /xxx/yyy - dirname = r_str_newf ("%s%s", lpath, R_SYS_DIR); + dirname = rz_str_newf ("%s%s", lpath, R_SYS_DIR); } else { // xxx/yyy if (strlen (pwd) == 1) { // if pwd is root - dirname = r_str_newf ("%s%s%s", R_SYS_DIR, lpath, R_SYS_DIR); + dirname = rz_str_newf ("%s%s%s", R_SYS_DIR, lpath, R_SYS_DIR); } else { - dirname = r_str_newf ("%s%s%s%s", pwd, R_SYS_DIR, lpath, R_SYS_DIR); + dirname = rz_str_newf ("%s%s%s%s", pwd, R_SYS_DIR, lpath, R_SYS_DIR); } } - basename = r_str_new (p + 1); + basename = rz_str_new (p + 1); } else { // xxx if (strlen (pwd) == 1) { - dirname = r_str_newf ("%s", R_SYS_DIR); + dirname = rz_str_newf ("%s", R_SYS_DIR); } else { - dirname = r_str_newf ("%s%s", pwd, R_SYS_DIR); + dirname = rz_str_newf ("%s%s", pwd, R_SYS_DIR); } - basename = r_str_new (lpath); + basename = rz_str_new (lpath); } if (!dirname || !basename) { goto out; } - list= r_fs_dir (core->fs, dirname); + list= rz_fs_dir (core->fs, dirname); n = strlen (basename); bool chgdir = !strncmp (str, "cd ", 3); if (list) { - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { if (!file) { continue; } if (!basename[0] || !strncmp (file->name, basename, n)) { - char *tmpstring = r_str_newf ("%s%s", dirname, file->name); - if (r_file_is_directory (tmpstring)) { - char *s = r_str_newf ("%s/", tmpstring); - r_line_completion_push (completion, s); + char *tmpstring = rz_str_newf ("%s%s", dirname, file->name); + if (rz_file_is_directory (tmpstring)) { + char *s = rz_str_newf ("%s/", tmpstring); + rz_line_completion_push (completion, s); free (s); } else if (!chgdir) { - r_line_completion_push (completion, tmpstring); + rz_line_completion_push (completion, tmpstring); } free (tmpstring); } } - r_list_free (list); + rz_list_free (list); } autocomplete_mount_point (completion, core, path); out: @@ -1117,36 +1117,36 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s char *lpath = NULL, *dirname = NULL , *basename = NULL; char *home = NULL, *filename = NULL, *p = NULL; int n = 0; - RList *list; - RListIter *iter; + RzList *list; + RzListIter *iter; if (!path) { goto out; } - lpath = r_str_new (path); + lpath = rz_str_new (path); #if __WINDOWS__ - r_str_replace_ch (lpath, '/', '\\', true); + rz_str_replace_ch (lpath, '/', '\\', true); #endif - p = (char *)r_str_last (lpath, R_SYS_DIR); + p = (char *)rz_str_last (lpath, R_SYS_DIR); if (p) { *p = 0; if (p == lpath) { // /xxx #if __WINDOWS__ dirname = strdup ("\\.\\"); #else - dirname = r_str_new (R_SYS_DIR); + dirname = rz_str_new (R_SYS_DIR); #endif } else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy - dirname = r_str_home (lpath + 2); + dirname = rz_str_home (lpath + 2); } else if (lpath[0] == '~') { // ~/xxx - if (!(home = r_str_home (NULL))) { + if (!(home = rz_str_home (NULL))) { goto out; } - dirname = r_str_newf ("%s%s", home, R_SYS_DIR); + dirname = rz_str_newf ("%s%s", home, R_SYS_DIR); free (home); } else if (lpath[0] == '.' || lpath[0] == R_SYS_DIR[0] ) { // ./xxx/yyy || /xxx/yyy - dirname = r_str_newf ("%s%s", lpath, R_SYS_DIR); + dirname = rz_str_newf ("%s%s", lpath, R_SYS_DIR); } else { // xxx/yyy char *fmt = ".%s%s%s"; #if __WINDOWS__ @@ -1154,39 +1154,39 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s fmt = "%.0s%s%s"; } #endif - dirname = r_str_newf (fmt, R_SYS_DIR, lpath, R_SYS_DIR); + dirname = rz_str_newf (fmt, R_SYS_DIR, lpath, R_SYS_DIR); } - basename = r_str_new (p + 1); + basename = rz_str_new (p + 1); } else { // xxx - dirname = r_str_newf (".%s", R_SYS_DIR); - basename = r_str_new (lpath); + dirname = rz_str_newf (".%s", R_SYS_DIR); + basename = rz_str_new (lpath); } if (!dirname || !basename) { goto out; } - list= r_sys_dir (dirname); + list= rz_sys_dir (dirname); n = strlen (basename); bool chgdir = !strncmp (str, "cd ", 3); if (list) { - r_list_foreach (list, iter, filename) { + rz_list_foreach (list, iter, filename) { if (*filename == '.') { continue; } if (!basename[0] || !strncmp (filename, basename, n)) { - char *tmpstring = r_str_newf ("%s%s", dirname, filename); - if (r_file_is_directory (tmpstring)) { - char *s = r_str_newf ("%s%s", tmpstring, R_SYS_DIR); - r_line_completion_push (completion, s); + char *tmpstring = rz_str_newf ("%s%s", dirname, filename); + if (rz_file_is_directory (tmpstring)) { + char *s = rz_str_newf ("%s%s", tmpstring, R_SYS_DIR); + rz_line_completion_push (completion, s); free (s); } else if (!chgdir) { - r_line_completion_push (completion, tmpstring); + rz_line_completion_push (completion, tmpstring); } free (tmpstring); } } - r_list_free (list); + rz_list_free (list); } out: free (lpath); @@ -1199,24 +1199,24 @@ static void autocompleteFilename(RLineCompletion *completion, RLineBuffer *buf, int n = 0, i = 0; char *pipe = strchr (buf->data, '>'); if (pipe) { - args = r_str_new (pipe + 1); + args = rz_str_new (pipe + 1); } else { - args = r_str_new (buf->data); + args = rz_str_new (buf->data); } if (!args) { goto out; } - n = r_str_word_set0 (args); + n = rz_str_word_set0 (args); if (n < narg) { goto out; } - input = r_str_new (r_str_word_get0 (args, narg)); + input = rz_str_new (rz_str_word_get0 (args, narg)); if (!input) { goto out; } - const char *tinput = r_str_trim_head_ro (input); + const char *tinput = rz_str_trim_head_ro (input); autocomplete_process_path (completion, buf->data, tinput); @@ -1225,7 +1225,7 @@ static void autocompleteFilename(RLineCompletion *completion, RLineBuffer *buf, } for (i = 0; extra_paths[i]; i ++) { - char *s = r_str_newf ("%s%s%s", extra_paths[i], R_SYS_DIR, tinput); + char *s = rz_str_newf ("%s%s%s", extra_paths[i], R_SYS_DIR, tinput); if (!s) { break; } @@ -1238,15 +1238,15 @@ out: } //TODO: make it recursive to handle nested struct -static int autocomplete_pfele (RCore *core, RLineCompletion *completion, char *key, char *pfx, int idx, char *ptr) { +static int autocomplete_pfele (RzCore *core, RLineCompletion *completion, char *key, char *pfx, int idx, char *ptr) { int i, ret = 0; int len = strlen (ptr); char* fmt = sdb_get (core->print->formats, key, NULL); if (fmt) { - int nargs = r_str_word_set0_stack (fmt); + int nargs = rz_str_word_set0_stack (fmt); if (nargs > 1) { for (i = 1; i < nargs; i++) { - const char *arg = r_str_word_get0 (fmt, i); + const char *arg = rz_str_word_get0 (fmt, i); char *p = strchr (arg, '('); char *p2 = strchr (arg, ')'); // remove '(' and ')' from fmt @@ -1255,8 +1255,8 @@ static int autocomplete_pfele (RCore *core, RLineCompletion *completion, char *k *p2 = '\0'; } if (!len || !strncmp (ptr, arg, len)) { - char *s = r_str_newf ("pf%s.%s.%s", pfx, key, arg); - r_line_completion_push (completion, s); + char *s = rz_str_newf ("pf%s.%s.%s", pfx, key, arg); + rz_line_completion_push (completion, s); free (s); } } @@ -1266,31 +1266,31 @@ static int autocomplete_pfele (RCore *core, RLineCompletion *completion, char *k return ret; } -#define ADDARG(x) if (!strncmp (buf->data+chr, x, strlen (buf->data+chr))) { r_line_completion_push (completion, x); } +#define ADDARG(x) if (!strncmp (buf->data+chr, x, strlen (buf->data+chr))) { rz_line_completion_push (completion, x); } -static void autocomplete_default(R_NULLABLE RCore *core, RLineCompletion *completion, RLineBuffer *buf) { - RCoreAutocomplete *a = core ? core->autocomplete : NULL; +static void autocomplete_default(R_NULLABLE RzCore *core, RLineCompletion *completion, RLineBuffer *buf) { + RzCoreAutocomplete *a = core ? core->autocomplete : NULL; int i; if (a) { for (i = 0; i < a->n_subcmds; i++) { if (buf->data[0] == 0 || !strncmp (a->subcmds[i]->cmd, buf->data, a->subcmds[i]->length)) { - r_line_completion_push (completion, a->subcmds[i]->cmd); + rz_line_completion_push (completion, a->subcmds[i]->cmd); } } } else { for (i = 0; i < radare_argc && radare_argv[i]; i++) { int length = strlen (radare_argv[i]); if (!strncmp (radare_argv[i], buf->data, length)) { - r_line_completion_push (completion, radare_argv[i]); + rz_line_completion_push (completion, radare_argv[i]); } } } } -static void autocomplete_evals(RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (str); +static void autocomplete_evals(RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (str); RConfigNode *bt; - RListIter *iter; + RzListIter *iter; char *tmp = strrchr (str, ' '); if (tmp) { str = tmp + 1; @@ -1299,87 +1299,87 @@ static void autocomplete_evals(RCore *core, RLineCompletion *completion, const c if (n < 1) { return; } - r_list_foreach (core->config->nodes, iter, bt) { + rz_list_foreach (core->config->nodes, iter, bt) { if (!strncmp (bt->name, str, n)) { - r_line_completion_push (completion, bt->name); + rz_line_completion_push (completion, bt->name); } } } -static void autocomplete_project(RCore *core, RLineCompletion *completion, const char* str) { - r_return_if_fail (str); - char *foo, *projects_path = r_file_abspath (r_config_get (core->config, "dir.projects")); - RList *list = r_sys_dir (projects_path); - RListIter *iter; +static void autocomplete_project(RzCore *core, RLineCompletion *completion, const char* str) { + rz_return_if_fail (str); + char *foo, *projects_path = rz_file_abspath (rz_config_get (core->config, "dir.projects")); + RzList *list = rz_sys_dir (projects_path); + RzListIter *iter; int n = strlen (str); if (projects_path) { - r_list_foreach (list, iter, foo) { - if (r_core_is_project (core, foo)) { + rz_list_foreach (list, iter, foo) { + if (rz_core_is_project (core, foo)) { if (!strncmp (foo, str, n)) { - r_line_completion_push (completion, foo); + rz_line_completion_push (completion, foo); } } } free (projects_path); - r_list_free (list); + rz_list_free (list); } } -static void autocomplete_minus(RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (str); +static void autocomplete_minus(RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (str); int count; int length = strlen (str); - char **keys = r_cmd_alias_keys(core->rcmd, &count); + char **keys = rz_cmd_alias_keys(core->rcmd, &count); if (!keys) { return; } int i; for (i = 0; i < count; i++) { if (!strncmp (keys[i], str, length)) { - r_line_completion_push (completion, keys[i]); + rz_line_completion_push (completion, keys[i]); } } } -static void autocomplete_breakpoints(RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (str); - RListIter *iter; +static void autocomplete_breakpoints(RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (str); + RzListIter *iter; RBreakpoint *bp = core->dbg->bp; RBreakpointItem *b; int n = strlen (str); - r_list_foreach (bp->bps, iter, b) { - char *addr = r_str_newf ("0x%"PFMT64x"", b->addr); + rz_list_foreach (bp->bps, iter, b) { + char *addr = rz_str_newf ("0x%"PFMT64x"", b->addr); if (!strncmp (addr, str, n)) { - r_line_completion_push (completion, addr); + rz_line_completion_push (completion, addr); } free (addr); } } -static bool add_argv(RFlagItem *fi, void *user) { +static bool add_argv(RzFlagItem *fi, void *user) { RLineCompletion *completion = user; - r_line_completion_push (completion, fi->name); + rz_line_completion_push (completion, fi->name); return true; } -static void autocomplete_flags(RCore *core, RLineCompletion *completion, const char* str) { - r_return_if_fail (str); +static void autocomplete_flags(RzCore *core, RLineCompletion *completion, const char* str) { + rz_return_if_fail (str); int n = strlen (str); - r_flag_foreach_prefix (core->flags, str, n, add_argv, completion); + rz_flag_foreach_prefix (core->flags, str, n, add_argv, completion); } // TODO: Should be refactored -static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (core && completion && str); +static void autocomplete_sdb (RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (core && completion && str); char *pipe = strchr (str, '>'); Sdb *sdb = core->sdb; char *lpath = NULL, *p1 = NULL, *out = NULL, *p2 = NULL; char *cur_pos = NULL, *cur_cmd = NULL, *next_cmd = NULL; char *temp_cmd = NULL, *temp_pos = NULL, *key = NULL; if (pipe) { - str = r_str_trim_head_ro (pipe + 1); + str = rz_str_trim_head_ro (pipe + 1); } - lpath = r_str_new (str); + lpath = rz_str_new (str); p1 = strchr (lpath, '/'); if (p1) { *p1 = 0; @@ -1397,10 +1397,10 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch if (!cur_pos) { break; } - cur_cmd = r_str_ndup (out, cur_pos - out); + cur_cmd = rz_str_ndup (out, cur_pos - out); if (!strncmp (tmp, cur_cmd, n)) { - char *cmplt = r_str_newf ("anal/%s/", cur_cmd); - r_line_completion_push (completion, cmplt); + char *cmplt = rz_str_newf ("anal/%s/", cur_cmd); + rz_line_completion_push (completion, cmplt); free (cmplt); } out += cur_pos - out + 1; @@ -1411,7 +1411,7 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch int n = strlen (tmp); char *spltr = strchr (ns, '/'); *spltr = 0; - next_cmd = r_str_newf ("anal/%s/*", ns); + next_cmd = rz_str_newf ("anal/%s/*", ns); out = sdb_querys (sdb, NULL, 0, next_cmd); if (!out) { free (lpath); @@ -1422,12 +1422,12 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch if (!temp_pos) { break; } - temp_cmd = r_str_ndup (out, temp_pos - out); // contains the key=value pair + temp_cmd = rz_str_ndup (out, temp_pos - out); // contains the key=value pair key = strchr (temp_cmd, '='); *key = 0; if (!strncmp (tmp, temp_cmd, n)) { - char *cmplt = r_str_newf ("anal/%s/%s", ns, temp_cmd); - r_line_completion_push (completion, cmplt); + char *cmplt = rz_str_newf ("anal/%s/%s", ns, temp_cmd); + rz_line_completion_push (completion, cmplt); free (cmplt); } out += temp_pos - out + 1; @@ -1436,71 +1436,71 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch } else { int n = strlen (lpath); if (!strncmp (lpath, "anal", n)) { - r_line_completion_push (completion, "anal/"); + rz_line_completion_push (completion, "anal/"); } } } -static void autocomplete_zignatures(RCore *core, RLineCompletion *completion, const char* msg) { - r_return_if_fail (msg); +static void autocomplete_zignatures(RzCore *core, RLineCompletion *completion, const char* msg) { + rz_return_if_fail (msg); int length = strlen (msg); RSpaces *zs = &core->anal->zign_spaces; RSpace *s; RSpaceIter it; - r_spaces_foreach (zs, it, s) { + rz_spaces_foreach (zs, it, s) { if (!strncmp (msg, s->name, length)) { - r_line_completion_push (completion, s->name); + rz_line_completion_push (completion, s->name); } } if (strlen (msg) == 0) { - r_line_completion_push (completion, "*"); + rz_line_completion_push (completion, "*"); } } -static void autocomplete_flagspaces(RCore *core, RLineCompletion *completion, const char* msg) { - r_return_if_fail (msg); +static void autocomplete_flagspaces(RzCore *core, RLineCompletion *completion, const char* msg) { + rz_return_if_fail (msg); int length = strlen (msg); - RFlag *flag = core->flags; + RzFlag *flag = core->flags; RSpaceIter it; RSpace *s; - r_flag_space_foreach (flag, it, s) { + rz_flag_space_foreach (flag, it, s) { if (!strncmp (msg, s->name, length)) { - r_line_completion_push (completion, s->name); + rz_line_completion_push (completion, s->name); } } if (strlen (msg) == 0) { - r_line_completion_push (completion, "*"); + rz_line_completion_push (completion, "*"); } } -static void autocomplete_functions (RCore *core, RLineCompletion *completion, const char* str) { - r_return_if_fail (str); - RListIter *iter; - RAnalFunction *fcn; +static void autocomplete_functions (RzCore *core, RLineCompletion *completion, const char* str) { + rz_return_if_fail (str); + RzListIter *iter; + RzAnalFunction *fcn; int n = strlen (str); - r_list_foreach (core->anal->fcns, iter, fcn) { - char *name = r_core_anal_fcn_name (core, fcn); + rz_list_foreach (core->anal->fcns, iter, fcn) { + char *name = rz_core_anal_fcn_name (core, fcn); if (!strncmp (name, str, n)) { - r_line_completion_push (completion, name); + rz_line_completion_push (completion, name); } free (name); } } -static void autocomplete_macro(RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (core && core->rcmd && completion && str); - RCmdMacroItem *item; - RListIter *iter; +static void autocomplete_macro(RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (core && core->rcmd && completion && str); + RzCmdMacroItem *item; + RzListIter *iter; size_t n = strlen (str); - r_list_foreach (core->rcmd->macro.macros, iter, item) { + rz_list_foreach (core->rcmd->macro.macros, iter, item) { char *p = item->name; if (!*str || !strncmp (str, p, n)) { - char *buf = r_str_newf ("%s%s)", str, p); + char *buf = rz_str_newf ("%s%s)", str, p); if (buf) { - r_line_completion_push (completion, buf); + rz_line_completion_push (completion, buf); free (buf); } } @@ -1508,11 +1508,11 @@ static void autocomplete_macro(RCore *core, RLineCompletion *completion, const c } static void autocomplete_file(RLineCompletion *completion, const char *str) { - r_return_if_fail (str); + rz_return_if_fail (str); char *pipe = strchr (str, '>'); if (pipe) { - str = r_str_trim_head_ro (pipe + 1); + str = rz_str_trim_head_ro (pipe + 1); } if (str && !*str) { autocomplete_process_path (completion, str, "./"); @@ -1522,12 +1522,12 @@ static void autocomplete_file(RLineCompletion *completion, const char *str) { } -static void autocomplete_ms_file(RCore* core, RLineCompletion *completion, const char *str) { - r_return_if_fail (str); +static void autocomplete_ms_file(RzCore* core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (str); char *pipe = strchr (str, '>'); char *path = (core->rfs && *(core->rfs->cwd)) ? *(core->rfs->cwd): "/"; if (pipe) { - str = r_str_trim_head_ro (pipe + 1); + str = rz_str_trim_head_ro (pipe + 1); } if (str && !*str) { autocomplete_ms_path (completion, core, str, path); @@ -1536,37 +1536,37 @@ static void autocomplete_ms_file(RCore* core, RLineCompletion *completion, const } } -static void autocomplete_theme(RCore *core, RLineCompletion *completion, const char *str) { - r_return_if_fail (str); +static void autocomplete_theme(RzCore *core, RLineCompletion *completion, const char *str) { + rz_return_if_fail (str); int len = strlen (str); char *theme; - RListIter *iter; - RList *themes = r_core_list_themes (core); - r_list_foreach (themes, iter, theme) { + RzListIter *iter; + RzList *themes = rz_core_list_themes (core); + rz_list_foreach (themes, iter, theme) { if (!len || !strncmp (str, theme, len)) { - r_line_completion_push (completion, theme); + rz_line_completion_push (completion, theme); } } - r_list_free (themes); + rz_list_free (themes); } -static bool find_e_opts(RCore *core, RLineCompletion *completion, RLineBuffer *buf) { +static bool find_e_opts(RzCore *core, RLineCompletion *completion, RLineBuffer *buf) { const char *pattern = "e (.*)="; - RRegex *rx = r_regex_new (pattern, "e"); + RzRegex *rx = rz_regex_new (pattern, "e"); const size_t nmatch = 2; - RRegexMatch pmatch[2]; + RzRegexMatch pmatch[2]; bool ret = false; // required to get the new list of items to autocomplete for cmd.pdc at least - r_core_config_update (core); + rz_core_config_update (core); - if (r_regex_exec (rx, buf->data, nmatch, pmatch, 1)) { + if (rz_regex_exec (rx, buf->data, nmatch, pmatch, 1)) { goto out; } int i; char *str = NULL, *sp; for (i = pmatch[1].rm_so; i < pmatch[1].rm_eo; i++) { - str = r_str_appendch (str, buf->data[i]); + str = rz_str_appendch (str, buf->data[i]); } if (!str) { goto out; @@ -1575,7 +1575,7 @@ static bool find_e_opts(RCore *core, RLineCompletion *completion, RLineBuffer *b // if the name contains a space, just null *sp = 0; } - RConfigNode *node = r_config_node_get (core->config, str); + RConfigNode *node = rz_config_node_get (core->config, str); if (sp) { // if nulled, then restore. *sp = ' '; @@ -1583,27 +1583,27 @@ static bool find_e_opts(RCore *core, RLineCompletion *completion, RLineBuffer *b if (!node) { return false; } - RListIter *iter; + RzListIter *iter; char *option; char *p = (char *) strchr (buf->data, '='); - p = r_str_ichr (p + 1, ' '); + p = rz_str_ichr (p + 1, ' '); int n = strlen (p); - r_list_foreach (node->options, iter, option) { + rz_list_foreach (node->options, iter, option) { if (!strncmp (option, p, n)) { - r_line_completion_push (completion, option); + rz_line_completion_push (completion, option); } } completion->opt = true; ret = true; out: - r_regex_free (rx); + rz_regex_free (rx); return ret; } -static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuffer *buf) { - RCoreAutocomplete* child = NULL; - RCoreAutocomplete* parent = core->autocomplete; +static bool find_autocomplete(RzCore *core, RLineCompletion *completion, RLineBuffer *buf) { + RzCoreAutocomplete* child = NULL; + RzCoreAutocomplete* parent = core->autocomplete; const char* p = buf->data; if (!*p) { return false; @@ -1611,17 +1611,17 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf char arg[256]; arg[0] = 0; while (*p) { - const char* e = r_str_trim_head_wp (p); + const char* e = rz_str_trim_head_wp (p); if (!e || (e - p) >= 256 || e == p) { return false; } memcpy (arg, p, e - p); arg[e - p] = 0; - child = r_core_autocomplete_find (parent, arg, false); + child = rz_core_autocomplete_find (parent, arg, false); if (child && child->length < buf->length && p[child->length] == ' ') { // if is spaced then i can provide the // next subtree as suggestion.. - p = r_str_trim_head_ro (p + child->length); + p = rz_str_trim_head_ro (p + child->length); if (child->type == R_CORE_AUTOCMPLT_OPTN) { continue; } @@ -1632,7 +1632,7 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf } int i; /* if something went wrong this will prevent bad behavior */ - r_line_completion_clear (completion); + rz_line_completion_clear (completion); switch (parent->type) { case R_CORE_AUTOCMPLT_SEEK: autocomplete_functions (core, completion, p); @@ -1679,15 +1679,15 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf // handled before break; default: - if (r_config_get_i (core->config, "cfg.newtab")) { - RCmdDescriptor *desc = &core->root_cmd_descriptor; + if (rz_config_get_i (core->config, "cfg.newtab")) { + RzCmdDescriptor *desc = &core->root_cmd_descriptor; for (i = 0; arg[i] && desc; i++) { ut8 c = arg[i]; desc = c < R_ARRAY_SIZE (desc->sub) ? desc->sub[c] : NULL; } if (desc && desc->help_msg) { - r_core_cmd_help (core, desc->help_msg); - r_cons_flush (); + rz_core_cmd_help (core, desc->help_msg); + rz_cons_flush (); return true; } // fallback to command listing @@ -1695,7 +1695,7 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf int length = strlen (arg); for (i = 0; i < parent->n_subcmds; i++) { if (!strncmp (arg, parent->subcmds[i]->cmd, length)) { - r_line_completion_push (completion, parent->subcmds[i]->cmd); + rz_line_completion_push (completion, parent->subcmds[i]->cmd); } } break; @@ -1703,22 +1703,22 @@ static bool find_autocomplete(RCore *core, RLineCompletion *completion, RLineBuf return true; } -R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type) { +RZ_API void rz_core_autocomplete(R_NULLABLE RzCore *core, RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type) { if (!core) { autocomplete_default (core, completion, buf); return; } - r_line_completion_clear (completion); + rz_line_completion_clear (completion); char *pipe = strchr (buf->data, '>'); char *ptr = strchr (buf->data, '@'); if (pipe && strchr (pipe + 1, ' ') && buf->data + buf->index >= pipe) { autocompleteFilename (completion, buf, NULL, 1); } else if (ptr && strchr (ptr + 1, ' ') && buf->data + buf->index >= ptr) { int sdelta, n; - ptr = (char *)r_str_trim_head_ro (ptr + 1); + ptr = (char *)rz_str_trim_head_ro (ptr + 1); n = strlen (ptr);//(buf->data+sdelta); sdelta = (int)(size_t)(ptr - buf->data); - r_flag_foreach_prefix (core->flags, buf->data + sdelta, n, add_argv, completion); + rz_flag_foreach_prefix (core->flags, buf->data + sdelta, n, add_argv, completion); } else if (!strncmp (buf->data, "#!pipe ", 7)) { if (strchr (buf->data + 7, ' ')) { autocompleteFilename (completion, buf, NULL, 2); @@ -1824,38 +1824,38 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi j += autocomplete_pfele (core, completion, sdbkv_key (kv), pfx, j, p + 1); break; } else { - char *s = r_str_newf ("pf%s.%s", pfx, sdbkv_key (kv)); - r_line_completion_push (completion, s); + char *s = rz_str_newf ("pf%s.%s", pfx, sdbkv_key (kv)); + rz_line_completion_push (completion, s); free (s); } } } } else if ((!strncmp (buf->data, "afvn ", 5)) || (!strncmp (buf->data, "afan ", 5))) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); - RList *vars; + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); + RzList *vars; if (!strncmp (buf->data, "afvn ", 5)) { - vars = r_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_BPV); + vars = rz_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_BPV); } else { - vars = r_list_new (); // TODO wtf r_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_ARG); + vars = rz_list_new (); // TODO wtf rz_anal_var_list (core->anal, fcn, R_ANAL_VAR_KIND_ARG); } const char *f_ptr, *l_ptr; - RAnalVar *var; + RzAnalVar *var; int len = strlen (buf->data); - f_ptr = r_sub_str_lchr (buf->data, 0, buf->index, ' '); + f_ptr = rz_sub_str_lchr (buf->data, 0, buf->index, ' '); f_ptr = f_ptr != NULL ? f_ptr + 1 : buf->data; - l_ptr = r_sub_str_rchr (buf->data, buf->index, len, ' '); + l_ptr = rz_sub_str_rchr (buf->data, buf->index, len, ' '); if (!l_ptr) { l_ptr = buf->data + len; } - RListIter *iter; - r_list_foreach (vars, iter, var) { + RzListIter *iter; + rz_list_foreach (vars, iter, var) { if (!strncmp (f_ptr, var->name, l_ptr - f_ptr)) { - r_line_completion_push (completion, var->name); + rz_line_completion_push (completion, var->name); } } - r_list_free (vars); + rz_list_free (vars); } else if (!strncmp (buf->data, "t ", 2) || !strncmp (buf->data, "t- ", 3)) { SdbList *l = sdb_foreach_list (core->anal->sdb_types, true); @@ -1867,7 +1867,7 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi if (!len || !strncmp (buf->data + chr, sdbkv_key (kv), len)) { if (!strcmp (sdbkv_value (kv), "type") || !strcmp (sdbkv_value (kv), "enum") || !strcmp (sdbkv_value (kv), "struct")) { - r_line_completion_push (completion, sdbkv_key (kv)); + rz_line_completion_push (completion, sdbkv_key (kv)); } } } @@ -1881,7 +1881,7 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi int len = strlen (buf->data + chr); if (!len || !strncmp (buf->data + chr, sdbkv_key (kv), len)) { if (!strcmp (sdbkv_value (kv), "enum")) { - r_line_completion_push (completion, sdbkv_key (kv)); + rz_line_completion_push (completion, sdbkv_key (kv)); } } } @@ -1892,7 +1892,7 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi const char *key = core->rcmd->aliases.keys[i]; int len = strlen (buf->data); if (!len || !strncmp (buf->data, key, len)) { - r_line_completion_push (completion, key); + rz_line_completion_push (completion, key); } } } else if (!strncmp (buf->data, "ts ", 3) @@ -1911,7 +1911,7 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi const char *key = sdbkv_key (kv); if (!len || !strncmp (buf->data + chr, key, len)) { if (!strncmp (sdbkv_value (kv), "struct", strlen ("struct") + 1)) { - r_line_completion_push (completion, key); + rz_line_completion_push (completion, key); } } } @@ -1919,7 +1919,7 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi } else if (!strncmp (buf->data, "zo ", 3) || !strncmp (buf->data, "zoz ", 4)) { if (core->anal->zign_path && core->anal->zign_path[0]) { - char *zignpath = r_file_abspath (core->anal->zign_path); + char *zignpath = rz_file_abspath (core->anal->zign_path); char *paths[2] = { zignpath, NULL }; autocompleteFilename (completion, buf, paths, 1); free (zignpath); @@ -1938,19 +1938,19 @@ R_API void r_core_autocomplete(R_NULLABLE RCore *core, RLineCompletion *completi } static int autocomplete(RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type, void *user) { - RCore *core = user; - r_core_autocomplete (core, completion, buf, prompt_type); + RzCore *core = user; + rz_core_autocomplete (core, completion, buf, prompt_type); return true; } -R_API int r_core_fgets(char *buf, int len) { +RZ_API int rz_core_fgets(char *buf, int len) { const char *ptr; - RLine *rli = r_line_singleton (); + RLine *rli = rz_line_singleton (); buf[0] = '\0'; - r_line_completion_set (&rli->completion, radare_argc, radare_argv); + rz_line_completion_set (&rli->completion, radare_argc, radare_argv); rli->completion.run = autocomplete; rli->completion.run_user = rli->user; - ptr = r_line_readline (); + ptr = rz_line_readline (); if (!ptr) { return -1; } @@ -1959,15 +1959,15 @@ R_API int r_core_fgets(char *buf, int len) { return strlen (buf); } -static const char *r_core_print_offname(void *p, ut64 addr) { - RCore *c = (RCore*)p; - RFlagItem *item = r_flag_get_i (c->flags, addr); +static const char *rz_core_print_offname(void *p, ut64 addr) { + RzCore *c = (RzCore*)p; + RzFlagItem *item = rz_flag_get_i (c->flags, addr); return item ? item->name : NULL; } -static int r_core_print_offsize(void *p, ut64 addr) { - RCore *c = (RCore*)p; - RFlagItem *item = r_flag_get_i (c->flags, addr); +static int rz_core_print_offsize(void *p, ut64 addr) { + RzCore *c = (RzCore*)p; + RzFlagItem *item = rz_flag_get_i (c->flags, addr); return item ? item->size: -1; } @@ -1975,17 +1975,17 @@ static int r_core_print_offsize(void *p, ut64 addr) { * Disassemble one instruction at specified address. */ static int __disasm(void *_core, ut64 addr) { - RCore *core = _core; + RzCore *core = _core; ut64 prevaddr = core->offset; - r_core_seek (core, addr, true); - int len = r_core_print_disasm_instructions (core, 0, 1); - r_core_seek (core, prevaddr, true); + rz_core_seek (core, addr, true); + int len = rz_core_print_disasm_instructions (core, 0, 1); + rz_core_seek (core, prevaddr, true); return len; } -static void update_sdb(RCore *core) { +static void update_sdb(RzCore *core) { Sdb *d; RBinObject *o; if (!core) { @@ -2000,7 +2000,7 @@ static void update_sdb(RCore *core) { sdb_ns_set (DB, "bin", core->bin->sdb); } //SDB// bin/info - o = r_bin_cur_object (core->bin); + o = rz_bin_cur_object (core->bin); if (o) { sdb_ns_set (sdb_ns (DB, "bin", 1), "info", o->kv); } @@ -2049,33 +2049,33 @@ static int is_string (const ut8 *buf, int size, int *len) { return 1; } -static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth); -R_API char *r_core_anal_hasrefs(RCore *core, ut64 value, bool verbose) { +static char *rz_core_anal_hasrefs_to_depth(RzCore *core, ut64 value, int depth); +RZ_API char *rz_core_anal_hasrefs(RzCore *core, ut64 value, bool verbose) { if (verbose) { - const int hex_depth = r_config_get_i (core->config, "hex.depth"); - return r_core_anal_hasrefs_to_depth (core, value, hex_depth); + const int hex_depth = rz_config_get_i (core->config, "hex.depth"); + return rz_core_anal_hasrefs_to_depth (core, value, hex_depth); } - RFlagItem *fi = r_flag_get_i (core->flags, value); + RzFlagItem *fi = rz_flag_get_i (core->flags, value); return fi? strdup (fi->name): NULL; } -static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { - r_return_val_if_fail (core, NULL); +static char *rz_core_anal_hasrefs_to_depth(RzCore *core, ut64 value, int depth) { + rz_return_val_if_fail (core, NULL); if (depth < 1 || value == UT64_MAX) { return NULL; } - RStrBuf *s = r_strbuf_new (NULL); + RStrBuf *s = rz_strbuf_new (NULL); char *mapname = NULL; - RFlagItem *fi = r_flag_get_i (core->flags, value); - ut64 type = r_core_anal_address (core, value); + RzFlagItem *fi = rz_flag_get_i (core->flags, value); + ut64 type = rz_core_anal_address (core, value); if (value && value != UT64_MAX) { - RDebugMap *map = r_debug_map_get (core->dbg, value); + RzDebugMap *map = rz_debug_map_get (core->dbg, value); if (map && map->name && map->name[0]) { mapname = strdup (map->name); } } if (mapname) { - r_strbuf_appendf (s, " (%s)", mapname); + rz_strbuf_appendf (s, " (%s)", mapname); R_FREE (mapname); } int bits = core->rasm->bits; @@ -2085,7 +2085,7 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { st16 v = (st16)(value & UT16_MAX); st16 h = UT16_MAX / 0x100; if (v > -h && v < h) { - r_strbuf_appendf (s," %hd", v); + rz_strbuf_appendf (s," %hd", v); } } break; @@ -2094,7 +2094,7 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { st32 v = (st32)(value & 0xffffffff); st32 h = UT32_MAX / 0x10000; if (v > -h && v < h) { - r_strbuf_appendf (s," %d", v); + rz_strbuf_appendf (s," %d", v); } } break; @@ -2103,75 +2103,75 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { st64 v = (st64)(value); st64 h = UT64_MAX / 0x1000000; if (v > -h && v < h) { - r_strbuf_appendf (s," %"PFMT64d, v); + rz_strbuf_appendf (s," %"PFMT64d, v); } } break; } - RBinSection *sect = value? r_bin_get_section_at (r_bin_cur_object (core->bin), value, true): NULL; + RBinSection *sect = value? rz_bin_get_section_at (rz_bin_cur_object (core->bin), value, true): NULL; if(! ((type&R_ANAL_ADDR_TYPE_HEAP)||(type&R_ANAL_ADDR_TYPE_STACK)) ) { // Do not repeat "stack" or "heap" words unnecessarily. if (sect && sect->name[0]) { - r_strbuf_appendf (s," (%s)", sect->name); + rz_strbuf_appendf (s," (%s)", sect->name); } } if (fi) { - RRegItem *r = r_reg_get (core->dbg->reg, fi->name, -1); + RzRegItem *r = rz_reg_get (core->dbg->reg, fi->name, -1); if (!r) { - r_strbuf_appendf (s, " %s", fi->name); + rz_strbuf_appendf (s, " %s", fi->name); } } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, value, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, value, 0); if (fcn) { - r_strbuf_appendf (s, " %s", fcn->name); + rz_strbuf_appendf (s, " %s", fcn->name); } if (type) { - const char *c = r_core_anal_optype_colorfor (core, value, true); + const char *c = rz_core_anal_optype_colorfor (core, value, true); const char *cend = (c && *c) ? Color_RESET: ""; if (!c) { c = ""; } if (type & R_ANAL_ADDR_TYPE_HEAP) { - r_strbuf_appendf (s, " %sheap%s", c, cend); + rz_strbuf_appendf (s, " %sheap%s", c, cend); } else if (type & R_ANAL_ADDR_TYPE_STACK) { - r_strbuf_appendf (s, " %sstack%s", c, cend); + rz_strbuf_appendf (s, " %sstack%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_PROGRAM) { - r_strbuf_appendf (s, " %sprogram%s", c, cend); + rz_strbuf_appendf (s, " %sprogram%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_LIBRARY) { - r_strbuf_appendf (s, " %slibrary%s", c, cend); + rz_strbuf_appendf (s, " %slibrary%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_ASCII) { - r_strbuf_appendf (s, " %sascii%s ('%c')", c, cend, value); + rz_strbuf_appendf (s, " %sascii%s ('%c')", c, cend, value); } if (type & R_ANAL_ADDR_TYPE_SEQUENCE) { - r_strbuf_appendf (s, " %ssequence%s", c, cend); + rz_strbuf_appendf (s, " %ssequence%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_READ) { - r_strbuf_appendf (s, " %sR%s", c, cend); + rz_strbuf_appendf (s, " %sR%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_WRITE) { - r_strbuf_appendf (s, " %sW%s", c, cend); + rz_strbuf_appendf (s, " %sW%s", c, cend); } if (type & R_ANAL_ADDR_TYPE_EXEC) { - RAsmOp op; + RzAsmOp op; ut8 buf[32]; - r_strbuf_appendf (s, " %sX%s", c, cend); + rz_strbuf_appendf (s, " %sX%s", c, cend); /* instruction disassembly */ - r_io_read_at (core->io, value, buf, sizeof (buf)); - r_asm_set_pc (core->rasm, value); - r_asm_disassemble (core->rasm, &op, buf, sizeof (buf)); - r_strbuf_appendf (s, " '%s'", r_asm_op_get_asm (&op)); + rz_io_read_at (core->io, value, buf, sizeof (buf)); + rz_asm_set_pc (core->rasm, value); + rz_asm_disassemble (core->rasm, &op, buf, sizeof (buf)); + rz_strbuf_appendf (s, " '%s'", rz_asm_op_get_asm (&op)); /* get library name */ { // NOTE: dup for mapname? - RDebugMap *map; - RListIter *iter; - r_list_foreach (core->dbg->maps, iter, map) { + RzDebugMap *map; + RzListIter *iter; + rz_list_foreach (core->dbg->maps, iter, map) { if ((value >= map->addr) && (valueaddr_end)) { - const char *lastslash = r_str_lchr (map->name, '/'); - r_strbuf_appendf (s, " '%s'", lastslash? + const char *lastslash = rz_str_lchr (map->name, '/'); + rz_strbuf_appendf (s, " '%s'", lastslash? lastslash+1:map->name); break; } @@ -2181,29 +2181,29 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { ut8 buf[32]; ut32 *n32 = (ut32 *)buf; ut64 *n64 = (ut64*)buf; - r_io_read_at (core->io, value, buf, sizeof (buf)); + rz_io_read_at (core->io, value, buf, sizeof (buf)); ut64 n = (core->rasm->bits == 64)? *n64: *n32; - r_strbuf_appendf (s, " 0x%"PFMT64x, n); + rz_strbuf_appendf (s, " 0x%"PFMT64x, n); } } { ut8 buf[128], widebuf[256]; - const char *c = r_config_get_i (core->config, "scr.color")? core->cons->context->pal.ai_ascii: ""; + const char *c = rz_config_get_i (core->config, "scr.color")? core->cons->context->pal.ai_ascii: ""; const char *cend = (c && *c) ? Color_RESET: ""; int len, r; - if (r_io_read_at (core->io, value, buf, sizeof (buf))) { + if (rz_io_read_at (core->io, value, buf, sizeof (buf))) { buf[sizeof (buf) - 1] = 0; switch (is_string (buf, sizeof(buf), &len)) { case 1: - r_strbuf_appendf (s, " (%s%s%s)", c, buf, cend); + rz_strbuf_appendf (s, " (%s%s%s)", c, buf, cend); break; case 2: - r = r_utf8_encode_str ((const RRune *)buf, widebuf, + r = rz_utf8_encode_str ((const RRune *)buf, widebuf, sizeof (widebuf) - 1); if (r == -1) { eprintf ("Something was wrong with refs\n"); } else { - r_strbuf_appendf (s, " (%s%s%s)", c, widebuf, cend); + rz_strbuf_appendf (s, " (%s%s%s)", c, widebuf, cend); } break; } @@ -2215,28 +2215,28 @@ static char *r_core_anal_hasrefs_to_depth(RCore *core, ut64 value, int depth) { ut8 buf[32]; ut32 *n32 = (ut32 *)buf; ut64 *n64 = (ut64*)buf; - r_io_read_at (core->io, value, buf, sizeof (buf)); + rz_io_read_at (core->io, value, buf, sizeof (buf)); ut64 n = (core->rasm->bits == 64)? *n64: *n32; if(n != value) { - char* rrstr = r_core_anal_hasrefs_to_depth (core, n, depth-1); + char* rrstr = rz_core_anal_hasrefs_to_depth (core, n, depth-1); if (rrstr) { if (rrstr[0]) { - r_strbuf_appendf (s, " --> %s", rrstr); + rz_strbuf_appendf (s, " --> %s", rrstr); } free (rrstr); } } } free (mapname); - return r_strbuf_drain (s); + return rz_strbuf_drain (s); } -R_API char *r_core_anal_get_comments(RCore *core, ut64 addr) { +RZ_API char *rz_core_anal_get_comments(RzCore *core, ut64 addr) { if (core) { - const char *type = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, addr); - const char *cmt = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *type = rz_meta_get_string (core->anal, R_META_TYPE_VARTYPE, addr); + const char *cmt = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); if (type && cmt) { - return r_str_newf ("%s %s", type, cmt); + return rz_str_newf ("%s %s", type, cmt); } else if (type) { return strdup (type); } else if (cmt) { @@ -2246,15 +2246,15 @@ R_API char *r_core_anal_get_comments(RCore *core, ut64 addr) { return NULL; } -R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbose) { +RZ_API const char *rz_core_anal_optype_colorfor(RzCore *core, ut64 addr, bool verbose) { ut64 type; if (!(core->print->flags & R_PRINT_FLAGS_COLOR)) { return NULL; } - if (!r_config_get_i (core->config, "scr.color")) { + if (!rz_config_get_i (core->config, "scr.color")) { return NULL; } - type = r_core_anal_address (core, addr); + type = rz_core_anal_address (core, addr); if (type & R_ANAL_ADDR_TYPE_EXEC) { return core->cons->context->pal.ai_exec; //Color_RED; } @@ -2273,67 +2273,67 @@ R_API const char *r_core_anal_optype_colorfor(RCore *core, ut64 addr, bool verbo return NULL; } -static void r_core_setenv (RCore *core) { - char *e = r_sys_getenv ("PATH"); - char *h = r_str_home (R2_HOME_BIN); - char *n = r_str_newf ("%s%s%s", h, R_SYS_ENVSEP, e); - r_sys_setenv ("PATH", n); +static void rz_core_setenv (RzCore *core) { + char *e = rz_sys_getenv ("PATH"); + char *h = rz_str_home (R2_HOME_BIN); + char *n = rz_str_newf ("%s%s%s", h, R_SYS_ENVSEP, e); + rz_sys_setenv ("PATH", n); free (n); free (h); free (e); } static int mywrite(const ut8 *buf, int len) { - return r_cons_memcat ((const char *)buf, len); + return rz_cons_memcat ((const char *)buf, len); } static bool exists_var(RPrint *print, ut64 func_addr, char *str) { - RAnal *anal = ((RCore*)(print->user))->anal; - RAnalFunction *fcn = r_anal_get_function_at (anal, func_addr); + RzAnal *anal = ((RzCore*)(print->user))->anal; + RzAnalFunction *fcn = rz_anal_get_function_at (anal, func_addr); if (!fcn) { return false; } - return !!r_anal_function_get_var_byname (fcn, str); + return !!rz_anal_function_get_var_byname (fcn, str); } -static bool r_core_anal_log(struct r_anal_t *anal, const char *msg) { - RCore *core = anal->user; +static bool rz_core_anal_log(struct rz_anal_t *anal, const char *msg) { + RzCore *core = anal->user; if (core->cfglog) { - r_core_log_add (core, msg); + rz_core_log_add (core, msg); } return true; } -static bool r_core_anal_read_at(struct r_anal_t *anal, ut64 addr, ut8 *buf, int len) { - return r_io_read_at (anal->iob.io, addr, buf, len); +static bool rz_core_anal_read_at(struct rz_anal_t *anal, ut64 addr, ut8 *buf, int len) { + return rz_io_read_at (anal->iob.io, addr, buf, len); } -static void r_core_break (RCore *core) { +static void rz_core_break (RzCore *core) { } -static void *r_core_sleep_begin (RCore *core) { - RCoreTask *task = r_core_task_self (&core->tasks); +static void *rz_core_sleep_begin (RzCore *core) { + RzCoreTask *task = rz_core_task_self (&core->tasks); if (task) { - r_core_task_sleep_begin (task); + rz_core_task_sleep_begin (task); } return task; } -static void r_core_sleep_end (RCore *core, void *user) { - RCoreTask *task = (RCoreTask *)user; +static void rz_core_sleep_end (RzCore *core, void *user) { + RzCoreTask *task = (RzCoreTask *)user; if (task) { - r_core_task_sleep_end (task); + rz_core_task_sleep_end (task); } } -static void __foreach(RCore *core, const char **cmds, int type) { +static void __foreach(RzCore *core, const char **cmds, int type) { int i; for (i = 0; cmds[i]; i++) { - r_core_autocomplete_add (core->autocomplete, cmds[i], type, true); + rz_core_autocomplete_add (core->autocomplete, cmds[i], type, true); } } -static void __init_autocomplete_default (RCore* core) { +static void __init_autocomplete_default (RzCore* core) { const char *fcns[] = { "afi", "afcf", "afn", NULL }; @@ -2354,8 +2354,8 @@ static void __init_autocomplete_default (RCore* core) { const char *files[] = { ".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!vala", "#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o", - "idp", "idpi", "L", "obf", "o+", "oc", "r2", "rabin2", "rasm2", "rahash2", "rax2", - "rafind2", "cd", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm", + "idp", "idpi", "L", "obf", "o+", "oc", "r2", "rz_bin", "rz_asm", "rz_hash", "rz_ax", + "rz_find", "cd", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm", "/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "vi", "less", "head", "tail", NULL }; @@ -2374,73 +2374,73 @@ static void __init_autocomplete_default (RCore* core) { __foreach (core, projs, R_CORE_AUTOCMPLT_PRJT); __foreach (core, mounts, R_CORE_AUTOCMPLT_MS); - r_core_autocomplete_add (core->autocomplete, "-", R_CORE_AUTOCMPLT_MINS, true); - r_core_autocomplete_add (core->autocomplete, "zs", R_CORE_AUTOCMPLT_ZIGN, true); - r_core_autocomplete_add (core->autocomplete, "fs", R_CORE_AUTOCMPLT_FLSP, true); - r_core_autocomplete_add ( - r_core_autocomplete_add (core->autocomplete, "ls", R_CORE_AUTOCMPLT_DFLT, true), + rz_core_autocomplete_add (core->autocomplete, "-", R_CORE_AUTOCMPLT_MINS, true); + rz_core_autocomplete_add (core->autocomplete, "zs", R_CORE_AUTOCMPLT_ZIGN, true); + rz_core_autocomplete_add (core->autocomplete, "fs", R_CORE_AUTOCMPLT_FLSP, true); + rz_core_autocomplete_add ( + rz_core_autocomplete_add (core->autocomplete, "ls", R_CORE_AUTOCMPLT_DFLT, true), "-l", R_CORE_AUTOCMPLT_FILE, true); - r_core_autocomplete_add (core->autocomplete, "eco", R_CORE_AUTOCMPLT_THME, true); - r_core_autocomplete_add (core->autocomplete, "k", R_CORE_AUTOCMPLT_SDB, true); + rz_core_autocomplete_add (core->autocomplete, "eco", R_CORE_AUTOCMPLT_THME, true); + rz_core_autocomplete_add (core->autocomplete, "k", R_CORE_AUTOCMPLT_SDB, true); /* macros */ - r_core_autocomplete_add (core->autocomplete, ".(", R_CORE_AUTOCMPLT_MACR, true); - r_core_autocomplete_add (core->autocomplete, "(-", R_CORE_AUTOCMPLT_MACR, true); + rz_core_autocomplete_add (core->autocomplete, ".(", R_CORE_AUTOCMPLT_MACR, true); + rz_core_autocomplete_add (core->autocomplete, "(-", R_CORE_AUTOCMPLT_MACR, true); /* just for hints */ int i; for (i = 0; i < radare_argc && radare_argv[i]; i++) { - if (!r_core_autocomplete_find (core->autocomplete, radare_argv[i], true)) { - r_core_autocomplete_add (core->autocomplete, radare_argv[i], R_CORE_AUTOCMPLT_DFLT, true); + if (!rz_core_autocomplete_find (core->autocomplete, radare_argv[i], true)) { + rz_core_autocomplete_add (core->autocomplete, radare_argv[i], R_CORE_AUTOCMPLT_DFLT, true); } } } -static void __init_autocomplete (RCore* core) { +static void __init_autocomplete (RzCore* core) { int i; - core->autocomplete = R_NEW0 (RCoreAutocomplete); + core->autocomplete = R_NEW0 (RzCoreAutocomplete); if (core->autocomplete_type == AUTOCOMPLETE_DEFAULT) { __init_autocomplete_default (core); } else if (core->autocomplete_type == AUTOCOMPLETE_MS) { - r_core_autocomplete_add (core->autocomplete, "ls", R_CORE_AUTOCMPLT_MS, true); - r_core_autocomplete_add (core->autocomplete, "cd", R_CORE_AUTOCMPLT_MS, true); - r_core_autocomplete_add (core->autocomplete, "cat", R_CORE_AUTOCMPLT_MS, true); - r_core_autocomplete_add (core->autocomplete, "get", R_CORE_AUTOCMPLT_MS, true); - r_core_autocomplete_add (core->autocomplete, "mount", R_CORE_AUTOCMPLT_MS, true); + rz_core_autocomplete_add (core->autocomplete, "ls", R_CORE_AUTOCMPLT_MS, true); + rz_core_autocomplete_add (core->autocomplete, "cd", R_CORE_AUTOCMPLT_MS, true); + rz_core_autocomplete_add (core->autocomplete, "cat", R_CORE_AUTOCMPLT_MS, true); + rz_core_autocomplete_add (core->autocomplete, "get", R_CORE_AUTOCMPLT_MS, true); + rz_core_autocomplete_add (core->autocomplete, "mount", R_CORE_AUTOCMPLT_MS, true); for (i = 0; i < ms_argc && ms_argv[i]; i++) { - if (!r_core_autocomplete_find (core->autocomplete, ms_argv[i], true)) { - r_core_autocomplete_add (core->autocomplete, ms_argv[i], R_CORE_AUTOCMPLT_MS, true); + if (!rz_core_autocomplete_find (core->autocomplete, ms_argv[i], true)) { + rz_core_autocomplete_add (core->autocomplete, ms_argv[i], R_CORE_AUTOCMPLT_MS, true); } } } } static const char *colorfor_cb(void *user, ut64 addr, bool verbose) { - return r_core_anal_optype_colorfor ((RCore *)user, addr, verbose); + return rz_core_anal_optype_colorfor ((RzCore *)user, addr, verbose); } static char *hasrefs_cb(void *user, ut64 addr, bool verbose) { - return r_core_anal_hasrefs ((RCore *)user, addr, verbose); + return rz_core_anal_hasrefs ((RzCore *)user, addr, verbose); } static const char *get_section_name(void *user, ut64 addr) { - return r_core_get_section_name ((RCore *)user, addr); + return rz_core_get_section_name ((RzCore *)user, addr); } static char *get_comments_cb(void *user, ut64 addr) { - return r_core_anal_get_comments ((RCore *)user, addr); + return rz_core_anal_get_comments ((RzCore *)user, addr); } static void cb_event_handler(REvent *ev, int event_type, void *user, void *data) { - RCore *core = (RCore *)ev->user; + RzCore *core = (RzCore *)ev->user; if (!core->log_events) { return; } REventMeta *rems = data; - char *str = r_base64_encode_dyn (rems->string, -1); + char *str = rz_base64_encode_dyn (rems->string, -1); switch (event_type) { case R_EVENT_META_SET: switch (rems->type) { case 'C': - r_core_log_add (ev->user, sdb_fmt (":add-comment 0x%08"PFMT64x" %s\n", rems->addr, str? str: "")); + rz_core_log_add (ev->user, sdb_fmt (":add-comment 0x%08"PFMT64x" %s\n", rems->addr, str? str: "")); break; default: break; @@ -2449,20 +2449,20 @@ static void cb_event_handler(REvent *ev, int event_type, void *user, void *data) case R_EVENT_META_DEL: switch (rems->type) { case 'C': - r_core_log_add (ev->user, sdb_fmt (":del-comment 0x%08"PFMT64x, rems->addr)); + rz_core_log_add (ev->user, sdb_fmt (":del-comment 0x%08"PFMT64x, rems->addr)); break; default: - r_core_log_add (ev->user, sdb_fmt (":del-comment 0x%08"PFMT64x, rems->addr)); + rz_core_log_add (ev->user, sdb_fmt (":del-comment 0x%08"PFMT64x, rems->addr)); break; } break; case R_EVENT_META_CLEAR: switch (rems->type) { case 'C': - r_core_log_add (ev->user, sdb_fmt (":clear-comments 0x%08"PFMT64x, rems->addr)); + rz_core_log_add (ev->user, sdb_fmt (":clear-comments 0x%08"PFMT64x, rems->addr)); break; default: - r_core_log_add (ev->user, sdb_fmt (":clear-comments 0x%08"PFMT64x, rems->addr)); + rz_core_log_add (ev->user, sdb_fmt (":clear-comments 0x%08"PFMT64x, rems->addr)); break; } break; @@ -2473,35 +2473,35 @@ static void cb_event_handler(REvent *ev, int event_type, void *user, void *data) free (str); } -static RFlagItem *core_flg_class_set(RFlag *f, const char *name, ut64 addr, ut32 size) { - r_flag_space_push (f, R_FLAGS_FS_CLASSES); - RFlagItem *res = r_flag_set (f, name, addr, size); - r_flag_space_pop (f); +static RzFlagItem *core_flg_class_set(RzFlag *f, const char *name, ut64 addr, ut32 size) { + rz_flag_space_push (f, R_FLAGS_FS_CLASSES); + RzFlagItem *res = rz_flag_set (f, name, addr, size); + rz_flag_space_pop (f); return res; } -static RFlagItem *core_flg_class_get(RFlag *f, const char *name) { - r_flag_space_push (f, R_FLAGS_FS_CLASSES); - RFlagItem *res = r_flag_get (f, name); - r_flag_space_pop (f); +static RzFlagItem *core_flg_class_get(RzFlag *f, const char *name) { + rz_flag_space_push (f, R_FLAGS_FS_CLASSES); + RzFlagItem *res = rz_flag_get (f, name); + rz_flag_space_pop (f); return res; } -static RFlagItem *core_flg_fcn_set(RFlag *f, const char *name, ut64 addr, ut32 size) { - r_flag_space_push (f, R_FLAGS_FS_FUNCTIONS); - RFlagItem *res = r_flag_set (f, name, addr, size); - r_flag_space_pop (f); +static RzFlagItem *core_flg_fcn_set(RzFlag *f, const char *name, ut64 addr, ut32 size) { + rz_flag_space_push (f, R_FLAGS_FS_FUNCTIONS); + RzFlagItem *res = rz_flag_set (f, name, addr, size); + rz_flag_space_pop (f); return res; } -R_API void r_core_autocomplete_reload (RCore *core) { - r_return_if_fail (core); - r_core_autocomplete_free (core->autocomplete); +RZ_API void rz_core_autocomplete_reload (RzCore *core) { + rz_return_if_fail (core); + rz_core_autocomplete_free (core->autocomplete); __init_autocomplete (core); } -R_API RFlagItem *r_core_flag_get_by_spaces(RFlag *f, ut64 off) { - return r_flag_get_by_spaces (f, off, +RZ_API RzFlagItem *rz_core_flag_get_by_spaces(RzFlag *f, ut64 off) { + return rz_flag_get_by_spaces (f, off, R_FLAGS_FS_FUNCTIONS, R_FLAGS_FS_SIGNS, R_FLAGS_FS_CLASSES, @@ -2521,13 +2521,13 @@ R_API RFlagItem *r_core_flag_get_by_spaces(RFlag *f, ut64 off) { static int win_eprintf(const char *format, ...) { va_list ap; va_start (ap, format); - r_cons_win_vhprintf (STD_ERROR_HANDLE, false, format, ap); + rz_cons_win_vhprintf (STD_ERROR_HANDLE, false, format, ap); va_end (ap); return 0; } #endif -R_API bool r_core_init(RCore *core) { +RZ_API bool rz_core_init(RzCore *core) { core->blocksize = R_CORE_BLOCKSIZE; core->block = (ut8 *)calloc (R_CORE_BLOCKSIZE + 1, 1); if (!core->block) { @@ -2535,11 +2535,11 @@ R_API bool r_core_init(RCore *core) { /* XXX memory leak */ return false; } - r_core_setenv (core); - core->ev = r_event_new (core); - r_event_hook (core->ev, R_EVENT_ALL, cb_event_handler, NULL); + rz_core_setenv (core); + core->ev = rz_event_new (core); + rz_event_hook (core->ev, R_EVENT_ALL, cb_event_handler, NULL); core->max_cmd_depth = R_CONS_CMD_DEPTH + 1; - core->sdb = sdb_new (NULL, "r2kv.sdb", 0); // XXX: path must be in home? + core->sdb = sdb_new (NULL, "rzkv.sdb", 0); // XXX: path must be in home? core->lastsearch = NULL; core->cmdfilter = NULL; core->switch_file_view = 0; @@ -2547,20 +2547,20 @@ R_API bool r_core_init(RCore *core) { core->incomment = false; core->config = NULL; core->http_up = false; - core->use_tree_sitter_r2cmd = false; + core->use_tree_sitter_rzcmd = false; ZERO_FILL (core->root_cmd_descriptor); - core->print = r_print_new (); - core->ropchain = r_list_newf ((RListFree)free); - r_core_bind (core, &(core->print->coreb)); + core->print = rz_print_new (); + core->ropchain = rz_list_newf ((RzListFree)free); + rz_core_bind (core, &(core->print->coreb)); core->print->user = core; core->print->num = core->num; - core->print->offname = r_core_print_offname; - core->print->offsize = r_core_print_offsize; - core->print->cb_printf = r_cons_printf; + core->print->offname = rz_core_print_offname; + core->print->offsize = rz_core_print_offsize; + core->print->cb_printf = rz_cons_printf; #if __WINDOWS__ core->print->cb_eprintf = win_eprintf; #endif - core->print->cb_color = r_cons_rainbow_get; + core->print->cb_color = rz_cons_rainbow_get; core->print->write = mywrite; core->print->exists_var = exists_var; core->print->disasm = __disasm; @@ -2571,13 +2571,13 @@ R_API bool r_core_init(RCore *core) { core->print->use_comments = false; core->rtr_n = 0; core->blocksize_max = R_CORE_BLOCKSIZE_MAX; - r_core_task_scheduler_init (&core->tasks, core); - core->watchers = r_list_new (); - core->watchers->free = (RListFree)r_core_cmpwatch_free; - core->scriptstack = r_list_new (); - core->scriptstack->free = (RListFree)free; - core->log = r_core_log_new (); - core->times = R_NEW0 (RCoreTimes); + rz_core_task_scheduler_init (&core->tasks, core); + core->watchers = rz_list_new (); + core->watchers->free = (RzListFree)rz_core_cmpwatch_free; + core->scriptstack = rz_list_new (); + core->scriptstack->free = (RzListFree)free; + core->log = rz_core_log_new (); + core->times = R_NEW0 (RzCoreTimes); core->vmode = false; core->printidx = 0; core->lastcmd = NULL; @@ -2585,78 +2585,78 @@ R_API bool r_core_init(RCore *core) { core->stkcmd = NULL; core->cmdqueue = NULL; core->cmdrepeat = true; - core->yank_buf = r_buf_new (); - core->num = r_num_new (&num_callback, &str_callback, core); - core->egg = r_egg_new (); - r_egg_setup (core->egg, R_SYS_ARCH, R_SYS_BITS, 0, R_SYS_OS); + core->yank_buf = rz_buf_new (); + core->num = rz_num_new (&num_callback, &str_callback, core); + core->egg = rz_egg_new (); + rz_egg_setup (core->egg, R_SYS_ARCH, R_SYS_BITS, 0, R_SYS_OS); - core->undos = r_list_newf ((RListFree)r_core_undo_free); + core->undos = rz_list_newf ((RzListFree)rz_core_undo_free); core->fixedarch = false; core->fixedbits = false; /* initialize libraries */ - core->cons = r_cons_new (); + core->cons = rz_cons_new (); if (core->cons->refcnt == 1) { - core->cons = r_cons_singleton (); + core->cons = rz_cons_singleton (); if (core->cons->line) { core->cons->line->user = core; core->cons->line->cb_editor = \ - (RLineEditorCb)&r_core_editor; + (RLineEditorCb)&rz_core_editor; core->cons->line->cb_fkey = core->cons->cb_fkey; } #if __EMSCRIPTEN__ core->cons->user_fgets = NULL; #else - core->cons->user_fgets = (void *)r_core_fgets; + core->cons->user_fgets = (void *)rz_core_fgets; #endif - //r_line_singleton ()->user = (void *)core; - r_line_hist_load (R2_HOME_HISTORY); + //rz_line_singleton ()->user = (void *)core; + rz_line_hist_load (R2_HOME_HISTORY); } core->print->cons = core->cons; - r_cons_bind (&core->print->consbind); + rz_cons_bind (&core->print->consbind); // We save the old num ad user, in order to restore it after free - core->lang = r_lang_new (); - core->lang->cmd_str = (char *(*)(void *, const char *))r_core_cmd_str; - core->lang->cmdf = (int (*)(void *, const char *, ...))r_core_cmdf; - r_core_bind_cons (core); - core->lang->cb_printf = r_cons_printf; - r_lang_define (core->lang, "RCore", "core", core); - r_lang_set_user_ptr (core->lang, core); - core->rasm = r_asm_new (); + core->lang = rz_lang_new (); + core->lang->cmd_str = (char *(*)(void *, const char *))rz_core_cmd_str; + core->lang->cmdf = (int (*)(void *, const char *, ...))rz_core_cmdf; + rz_core_bind_cons (core); + core->lang->cb_printf = rz_cons_printf; + rz_lang_define (core->lang, "RzCore", "core", core); + rz_lang_set_user_ptr (core->lang, core); + core->rasm = rz_asm_new (); core->rasm->num = core->num; - r_asm_set_user_ptr (core->rasm, core); - core->anal = r_anal_new (); - core->gadgets = r_list_newf ((RListFree)r_core_gadget_free); + rz_asm_set_user_ptr (core->rasm, core); + core->anal = rz_anal_new (); + core->gadgets = rz_list_newf ((RzListFree)rz_core_gadget_free); core->anal->ev = core->ev; - core->anal->log = r_core_anal_log; - core->anal->read_at = r_core_anal_read_at; - core->anal->flag_get = r_core_flag_get_by_spaces; + core->anal->log = rz_core_anal_log; + core->anal->read_at = rz_core_anal_read_at; + core->anal->flag_get = rz_core_flag_get_by_spaces; core->anal->cb.on_fcn_new = on_fcn_new; core->anal->cb.on_fcn_delete = on_fcn_delete; core->anal->cb.on_fcn_rename = on_fcn_rename; core->print->sdb_types = core->anal->sdb_types; - core->rasm->syscall = r_syscall_ref (core->anal->syscall); // BIND syscall anal/asm - r_anal_set_user_ptr (core->anal, core); - core->anal->cb_printf = (void *) r_cons_printf; - core->parser = r_parse_new (); - r_anal_bind (core->anal, &(core->parser->analb)); - core->parser->varlist = r_anal_function_get_var_fields; + core->rasm->syscall = rz_syscall_ref (core->anal->syscall); // BIND syscall anal/asm + rz_anal_set_user_ptr (core->anal, core); + core->anal->cb_printf = (void *) rz_cons_printf; + core->parser = rz_parse_new (); + rz_anal_bind (core->anal, &(core->parser->analb)); + core->parser->varlist = rz_anal_function_get_var_fields; /// XXX shouhld be using coreb - r_parse_set_user_ptr (core->parser, core); - core->bin = r_bin_new (); - r_cons_bind (&core->bin->consb); - // XXX we shuold use RConsBind instead of this hardcoded pointer - core->bin->cb_printf = (PrintfCallback) r_cons_printf; - r_bin_set_user_ptr (core->bin, core); - core->io = r_io_new (); + rz_parse_set_user_ptr (core->parser, core); + core->bin = rz_bin_new (); + rz_cons_bind (&core->bin->consb); + // XXX we shuold use RzConsBind instead of this hardcoded pointer + core->bin->cb_printf = (PrintfCallback) rz_cons_printf; + rz_bin_set_user_ptr (core->bin, core); + core->io = rz_io_new (); core->io->ff = 1; - core->search = r_search_new (R_SEARCH_KEYWORD); - r_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval - core->fs = r_fs_new (); - core->flags = r_flag_new (); - core->flags->cb_printf = r_cons_printf; - core->graph = r_agraph_new (r_cons_canvas_new (1, 1)); + core->search = rz_search_new (R_SEARCH_KEYWORD); + rz_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval + core->fs = rz_fs_new (); + core->flags = rz_flag_new (); + core->flags->cb_printf = rz_cons_printf; + core->graph = rz_agraph_new (rz_cons_canvas_new (1, 1)); core->graph->need_reload_nodes = false; core->asmqjmps_size = R_CORE_ASMQJMPS_NUM; if (sizeof (ut64) * core->asmqjmps_size < core->asmqjmps_size) { @@ -2666,193 +2666,193 @@ R_API bool r_core_init(RCore *core) { core->asmqjmps = R_NEWS (ut64, core->asmqjmps_size); } - r_bin_bind (core->bin, &(core->rasm->binb)); - r_bin_bind (core->bin, &(core->anal->binb)); - r_bin_bind (core->bin, &(core->anal->binb)); + rz_bin_bind (core->bin, &(core->rasm->binb)); + rz_bin_bind (core->bin, &(core->anal->binb)); + rz_bin_bind (core->bin, &(core->anal->binb)); - r_io_bind (core->io, &(core->search->iob)); - r_io_bind (core->io, &(core->print->iob)); - r_io_bind (core->io, &(core->anal->iob)); - r_io_bind (core->io, &(core->fs->iob)); - r_cons_bind (&(core->fs->csb)); - r_core_bind (core, &(core->fs->cob)); - r_io_bind (core->io, &(core->bin->iob)); - r_flag_bind (core->flags, &(core->anal->flb)); + rz_io_bind (core->io, &(core->search->iob)); + rz_io_bind (core->io, &(core->print->iob)); + rz_io_bind (core->io, &(core->anal->iob)); + rz_io_bind (core->io, &(core->fs->iob)); + rz_cons_bind (&(core->fs->csb)); + rz_core_bind (core, &(core->fs->cob)); + rz_io_bind (core->io, &(core->bin->iob)); + rz_flag_bind (core->flags, &(core->anal->flb)); core->anal->flg_class_set = core_flg_class_set; core->anal->flg_class_get = core_flg_class_get; core->anal->flg_fcn_set = core_flg_fcn_set; - r_anal_bind (core->anal, &(core->parser->analb)); - core->parser->flag_get = r_core_flag_get_by_spaces; - core->parser->label_get = r_anal_function_get_label_at; + rz_anal_bind (core->anal, &(core->parser->analb)); + core->parser->flag_get = rz_core_flag_get_by_spaces; + core->parser->label_get = rz_anal_function_get_label_at; - r_core_bind (core, &(core->anal->coreb)); + rz_core_bind (core, &(core->anal->coreb)); core->file = NULL; - core->files = r_list_newf ((RListFree)r_core_file_free); + core->files = rz_list_newf ((RzListFree)rz_core_file_free); core->offset = 0LL; core->prompt_offset = 0LL; - r_core_cmd_init (core); - core->dbg = r_debug_new (true); + rz_core_cmd_init (core); + core->dbg = rz_debug_new (true); - r_io_bind (core->io, &(core->dbg->iob)); - r_io_bind (core->io, &(core->dbg->bp->iob)); - r_core_bind (core, &core->dbg->corebind); - r_core_bind (core, &core->dbg->bp->corebind); - r_core_bind (core, &core->io->corebind); + rz_io_bind (core->io, &(core->dbg->iob)); + rz_io_bind (core->io, &(core->dbg->bp->iob)); + rz_core_bind (core, &core->dbg->corebind); + rz_core_bind (core, &core->dbg->bp->corebind); + rz_core_bind (core, &core->io->corebind); core->dbg->anal = core->anal; // XXX: dupped instance.. can cause lost pointerz - //r_debug_use (core->dbg, "native"); + //rz_debug_use (core->dbg, "native"); // XXX pushing uninitialized regstate results in trashed reg values -// r_reg_arena_push (core->dbg->reg); // create a 2 level register state stack +// rz_reg_arena_push (core->dbg->reg); // create a 2 level register state stack // core->dbg->anal->reg = core->anal->reg; // XXX: dupped instance.. can cause lost pointerz - core->io->cb_printf = r_cons_printf; - core->dbg->cb_printf = r_cons_printf; - core->dbg->bp->cb_printf = r_cons_printf; + core->io->cb_printf = rz_cons_printf; + core->dbg->cb_printf = rz_cons_printf; + core->dbg->bp->cb_printf = rz_cons_printf; core->dbg->ev = core->ev; // initialize config before any corebind - r_core_config_init (core); + rz_core_config_init (core); - r_core_loadlibs_init (core); - //r_core_loadlibs (core); + rz_core_loadlibs_init (core); + //rz_core_loadlibs (core); - // TODO: get arch from r_bin or from native arch - r_asm_use (core->rasm, R_SYS_ARCH); - r_anal_use (core->anal, R_SYS_ARCH); + // TODO: get arch from rz_bin or from native arch + rz_asm_use (core->rasm, R_SYS_ARCH); + rz_anal_use (core->anal, R_SYS_ARCH); if (R_SYS_BITS & R_SYS_BITS_64) { - r_config_set_i (core->config, "asm.bits", 64); + rz_config_set_i (core->config, "asm.bits", 64); } else { if (R_SYS_BITS & R_SYS_BITS_32) { - r_config_set_i (core->config, "asm.bits", 32); + rz_config_set_i (core->config, "asm.bits", 32); } } - r_config_set (core->config, "asm.arch", R_SYS_ARCH); - r_bp_use (core->dbg->bp, R_SYS_ARCH, core->anal->bits); + rz_config_set (core->config, "asm.arch", R_SYS_ARCH); + rz_bp_use (core->dbg->bp, R_SYS_ARCH, core->anal->bits); update_sdb (core); { - char *a = r_str_r2_prefix (R2_FLAGS); + char *a = rz_str_rz_prefix (R2_FLAGS); if (a) { - char *file = r_str_newf ("%s/tags.r2", a); - (void)r_core_run_script (core, file); + char *file = rz_str_newf ("%s/tags.r2", a); + (void)rz_core_run_script (core, file); free (file); free (a); } } - r_core_anal_type_init (core); + rz_core_anal_type_init (core); __init_autocomplete (core); return 0; } -R_API void __cons_cb_fkey(RCore *core, int fkey) { +RZ_API void __cons_cb_fkey(RzCore *core, int fkey) { char buf[32]; snprintf (buf, sizeof (buf), "key.f%d", fkey); - const char *v = r_config_get (core->config, buf); + const char *v = rz_config_get (core->config, buf); if (v && *v) { - r_cons_printf ("%s\n", v); - r_core_cmd0 (core, v); - r_cons_flush (); + rz_cons_printf ("%s\n", v); + rz_core_cmd0 (core, v); + rz_cons_flush (); } } -R_API void r_core_bind_cons(RCore *core) { +RZ_API void rz_core_bind_cons(RzCore *core) { core->cons->num = core->num; - core->cons->cb_fkey = (RConsFunctionKey)__cons_cb_fkey; - core->cons->cb_editor = (RConsEditorCallback)r_core_editor; - core->cons->cb_break = (RConsBreakCallback)r_core_break; - core->cons->cb_sleep_begin = (RConsSleepBeginCallback)r_core_sleep_begin; - core->cons->cb_sleep_end = (RConsSleepEndCallback)r_core_sleep_end; - core->cons->cb_task_oneshot = (RConsQueueTaskOneshot) r_core_task_enqueue_oneshot; + core->cons->cb_fkey = (RzConsFunctionKey)__cons_cb_fkey; + core->cons->cb_editor = (RzConsEditorCallback)rz_core_editor; + core->cons->cb_break = (RzConsBreakCallback)rz_core_break; + core->cons->cb_sleep_begin = (RzConsSleepBeginCallback)rz_core_sleep_begin; + core->cons->cb_sleep_end = (RzConsSleepEndCallback)rz_core_sleep_end; + core->cons->cb_task_oneshot = (RzConsQueueTaskOneshot) rz_core_task_enqueue_oneshot; core->cons->user = (void*)core; } -R_API void r_core_fini(RCore *c) { +RZ_API void rz_core_fini(RzCore *c) { if (!c) { return; } - r_core_task_break_all (&c->tasks); - r_core_task_join (&c->tasks, NULL, -1); - r_core_wait (c); + rz_core_task_break_all (&c->tasks); + rz_core_task_join (&c->tasks, NULL, -1); + rz_core_wait (c); /* TODO: it leaks as shit */ //update_sdb (c); // avoid double free - r_list_free (c->ropchain); - r_event_free (c->ev); + rz_list_free (c->ropchain); + rz_event_free (c->ev); free (c->cmdlog); free (c->lastsearch); R_FREE (c->cons->pager); free (c->cmdqueue); free (c->lastcmd); free (c->stkcmd); - r_list_free (c->visual.tabs); + rz_list_free (c->visual.tabs); free (c->block); - r_core_autocomplete_free (c->autocomplete); + rz_core_autocomplete_free (c->autocomplete); - r_list_free (c->gadgets); - r_list_free (c->undos); - r_num_free (c->num); + rz_list_free (c->gadgets); + rz_list_free (c->undos); + rz_num_free (c->num); // TODO: sync or not? sdb_sync (c->sdb); // TODO: sync all dbs? - //r_core_file_free (c->file); + //rz_core_file_free (c->file); //c->file = NULL; R_FREE (c->table_query); - r_list_free (c->files); - r_list_free (c->watchers); - r_list_free (c->scriptstack); - r_core_task_scheduler_fini (&c->tasks); - c->rcmd = r_cmd_free (c->rcmd); - r_list_free (c->cmd_descriptors); - c->anal = r_anal_free (c->anal); - r_asm_free (c->rasm); + rz_list_free (c->files); + rz_list_free (c->watchers); + rz_list_free (c->scriptstack); + rz_core_task_scheduler_fini (&c->tasks); + c->rcmd = rz_cmd_free (c->rcmd); + rz_list_free (c->cmd_descriptors); + c->anal = rz_anal_free (c->anal); + rz_asm_free (c->rasm); c->rasm = NULL; - c->print = r_print_free (c->print); - c->bin = (r_bin_free (c->bin), NULL); - c->lang = (r_lang_free (c->lang), NULL); - c->dbg = (r_debug_free (c->dbg), NULL); - r_io_free (c->io); - r_config_free (c->config); - /* after r_config_free, the value of I.teefile is trashed */ + c->print = rz_print_free (c->print); + c->bin = (rz_bin_free (c->bin), NULL); + c->lang = (rz_lang_free (c->lang), NULL); + c->dbg = (rz_debug_free (c->dbg), NULL); + rz_io_free (c->io); + rz_config_free (c->config); + /* after rz_config_free, the value of I.teefile is trashed */ /* rconfig doesnt knows how to deinitialize vars, so we - should probably need to add a r_config_free_payload callback */ - r_cons_free (); - r_cons_singleton ()->teefile = NULL; // HACK - r_search_free (c->search); - r_flag_free (c->flags); - r_fs_free (c->fs); - r_egg_free (c->egg); - r_lib_free (c->lib); - r_buf_free (c->yank_buf); - r_agraph_free (c->graph); + should probably need to add a rz_config_free_payload callback */ + rz_cons_free (); + rz_cons_singleton ()->teefile = NULL; // HACK + rz_search_free (c->search); + rz_flag_free (c->flags); + rz_fs_free (c->fs); + rz_egg_free (c->egg); + rz_lib_free (c->lib); + rz_buf_free (c->yank_buf); + rz_agraph_free (c->graph); free (c->asmqjmps); sdb_free (c->sdb); - r_core_log_free (c->log); - r_parse_free (c->parser); + rz_core_log_free (c->log); + rz_parse_free (c->parser); free (c->times); } -R_API void r_core_free(RCore *c) { +RZ_API void rz_core_free(RzCore *c) { if (c) { - r_core_fini (c); + rz_core_fini (c); free (c); } } -R_API void r_core_prompt_loop(RCore *r) { +RZ_API void rz_core_prompt_loop(RzCore *r) { int ret; do { - int err = r_core_prompt (r, false); + int err = rz_core_prompt (r, false); if (err < 1) { // handle ^D - r->num->value = 0; // r.num->value will be read by r_main_radare2() after calling this fcn + r->num->value = 0; // r.num->value will be read by rz_main_rizin() after calling this fcn break; } /* -1 means invalid command, -2 means quit prompt loop */ - if ((ret = r_core_prompt_exec (r)) == -2) { + if ((ret = rz_core_prompt_exec (r)) == -2) { break; } } while (ret != R_CORE_CMD_EXIT); } -static int prompt_flag (RCore *r, char *s, size_t maxlen) { +static int prompt_flag (RzCore *r, char *s, size_t maxlen) { const char DOTS[] = "..."; - const RFlagItem *f = r_flag_get_at (r->flags, r->offset, false); + const RzFlagItem *f = rz_flag_get_at (r->flags, r->offset, false); if (!f) { return false; } @@ -2868,12 +2868,12 @@ static int prompt_flag (RCore *r, char *s, size_t maxlen) { return true; } -static void prompt_sec(RCore *r, char *s, size_t maxlen) { - const RBinSection *sec = r_bin_get_section_at (r_bin_cur_object (r->bin), r->offset, true); +static void prompt_sec(RzCore *r, char *s, size_t maxlen) { + const RBinSection *sec = rz_bin_get_section_at (rz_bin_cur_object (r->bin), r->offset, true); if (!sec) { return; } - r_str_ncpy (s, sec->name, maxlen - 2); + rz_str_ncpy (s, sec->name, maxlen - 2); strcat (s, ":"); } @@ -2883,7 +2883,7 @@ static void chop_prompt (const char *filename, char *tmp, size_t max_tmp_size) { const char DOTS[] = "..."; int w, p_len; - w = r_cons_get_size (NULL); + w = rz_cons_get_size (NULL); file_len = strlen (filename); tmp_len = strlen (tmp); p_len = R_MAX (0, w - 6); @@ -2897,39 +2897,39 @@ static void chop_prompt (const char *filename, char *tmp, size_t max_tmp_size) { } } -static void set_prompt (RCore *r) { +static void set_prompt (RzCore *r) { char tmp[128]; char *filename = strdup (""); - const char *cmdprompt = r_config_get (r->config, "cmd.prompt"); + const char *cmdprompt = rz_config_get (r->config, "cmd.prompt"); const char *BEGIN = ""; const char *END = ""; const char *remote = ""; if (cmdprompt && *cmdprompt) { - r_core_cmd (r, cmdprompt, 0); + rz_core_cmd (r, cmdprompt, 0); } - if (r_config_get_i (r->config, "scr.prompt.file")) { + if (rz_config_get_i (r->config, "scr.prompt.file")) { free (filename); - filename = r_str_newf ("\"%s\"", - r->io->desc ? r_file_basename (r->io->desc->name) : ""); + filename = rz_str_newf ("\"%s\"", + r->io->desc ? rz_file_basename (r->io->desc->name) : ""); } if (r->cmdremote) { - char *s = r_core_cmd_str (r, "s"); - r->offset = r_num_math (NULL, s); + char *s = rz_core_cmd_str (r, "s"); + r->offset = rz_num_math (NULL, s); free (s); remote = "=!"; } - if (r_config_get_i (r->config, "scr.color")) { + if (rz_config_get_i (r->config, "scr.color")) { BEGIN = r->cons->context->pal.prompt; END = r->cons->context->pal.reset; } // TODO: also in visual prompt and disasm/hexdump ? - if (r_config_get_i (r->config, "asm.segoff")) { + if (rz_config_get_i (r->config, "asm.segoff")) { ut32 a, b; - unsigned int seggrn = r_config_get_i (r->config, "asm.seggrn"); + unsigned int seggrn = rz_config_get_i (r->config, "asm.seggrn"); a = ((r->offset >> 16) << (16 - seggrn)); b = (r->offset & 0xffff); @@ -2939,10 +2939,10 @@ static void set_prompt (RCore *r) { int promptset = false; sec[0] = '\0'; - if (r_config_get_i (r->config, "scr.prompt.flag")) { + if (rz_config_get_i (r->config, "scr.prompt.flag")) { promptset = prompt_flag (r, p, sizeof (p)); } - if (r_config_get_i (r->config, "scr.prompt.sect")) { + if (rz_config_get_i (r->config, "scr.prompt.sect")) { prompt_sec (r, sec, sizeof (sec)); } @@ -2957,20 +2957,20 @@ static void set_prompt (RCore *r) { } chop_prompt (filename, tmp, 128); - char *prompt = r_str_newf ("%s%s[%s%s]>%s ", filename, BEGIN, remote, + char *prompt = rz_str_newf ("%s%s[%s%s]>%s ", filename, BEGIN, remote, tmp, END); - r_line_set_prompt (prompt ? prompt : ""); + rz_line_set_prompt (prompt ? prompt : ""); R_FREE (filename); R_FREE (prompt); } -R_API int r_core_prompt(RCore *r, int sync) { +RZ_API int rz_core_prompt(RzCore *r, int sync) { char line[4096]; int rnv = r->num->value; set_prompt (r); - int ret = r_cons_fgets (line, sizeof (line), 0, NULL); + int ret = rz_cons_fgets (line, sizeof (line), 0, NULL); if (ret == -2) { return R_CORE_CMD_EXIT; // ^D } @@ -2979,37 +2979,37 @@ R_API int r_core_prompt(RCore *r, int sync) { } r->num->value = rnv; if (sync) { - return r_core_prompt_exec (r); + return rz_core_prompt_exec (r); } free (r->cmdqueue); r->cmdqueue = strdup (line); if (r->scr_gadgets && *line && *line != 'q') { - r_core_cmd0 (r, "pg"); + rz_core_cmd0 (r, "pg"); } r->num->value = r->rc; return true; } -extern void r_core_echo(RCore *core, const char *input); +extern void rz_core_echo(RzCore *core, const char *input); -R_API int r_core_prompt_exec(RCore *r) { - int ret = r_core_cmd (r, r->cmdqueue, true); +RZ_API int rz_core_prompt_exec(RzCore *r) { + int ret = rz_core_cmd (r, r->cmdqueue, true); r->rc = r->num->value; - //int ret = r_core_cmd (r, r->cmdqueue, true); + //int ret = rz_core_cmd (r, r->cmdqueue, true); if (r->cons && r->cons->use_tts) { - const char *buf = r_cons_get_buffer(); - r_sys_tts (buf, true); + const char *buf = rz_cons_get_buffer(); + rz_sys_tts (buf, true); r->cons->use_tts = false; } - r_cons_echo (NULL); - r_cons_flush (); + rz_cons_echo (NULL); + rz_cons_flush (); if (r->cons && r->cons->line && r->cons->line->zerosep) { - r_cons_zero (); + rz_cons_zero (); } return ret; } -R_API int r_core_seek_size(RCore *core, ut64 addr, int bsize) { +RZ_API int rz_core_seek_size(RzCore *core, ut64 addr, int bsize) { ut8 *bump; int ret = false; if (bsize < 0) { @@ -3018,7 +3018,7 @@ R_API int r_core_seek_size(RCore *core, ut64 addr, int bsize) { if (bsize == core->blocksize) { return true; } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { // TODO : restrict to filesize? if (bsize > 1024*32) { eprintf ("Sandbox mode restricts blocksize bigger than 32k\n"); @@ -3046,16 +3046,16 @@ R_API int r_core_seek_size(RCore *core, ut64 addr, int bsize) { core->block = bump; core->blocksize = bsize; memset (core->block, 0xff, core->blocksize); - r_core_block_read (core); + rz_core_block_read (core); } return ret; } -R_API int r_core_block_size(RCore *core, int bsize) { - return r_core_seek_size (core, core->offset, bsize); +RZ_API int rz_core_block_size(RzCore *core, int bsize) { + return rz_core_seek_size (core, core->offset, bsize); } -R_API int r_core_seek_align(RCore *core, ut64 align, int times) { +RZ_API int rz_core_seek_align(RzCore *core, ut64 align, int times) { int inc = (times >= 0)? 1: -1; ut64 seek = core->offset; if (!align) { @@ -3081,83 +3081,83 @@ R_API int r_core_seek_align(RCore *core, ut64 align, int times) { if (diff < 0 && -diff > seek) { seek = diff = 0; } - return r_core_seek (core, seek + diff, true); + return rz_core_seek (core, seek + diff, true); } -R_API char *r_core_op_str(RCore *core, ut64 addr) { - RAsmOp op = {0}; +RZ_API char *rz_core_op_str(RzCore *core, ut64 addr) { + RzAsmOp op = {0}; ut8 buf[64]; - r_asm_set_pc (core->rasm, addr); - r_io_read_at (core->io, addr, buf, sizeof (buf)); - int ret = r_asm_disassemble (core->rasm, &op, buf, sizeof (buf)); - char *str = (ret > 0)? strdup (r_strbuf_get (&op.buf_asm)): NULL; - r_asm_op_fini (&op); + rz_asm_set_pc (core->rasm, addr); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + int ret = rz_asm_disassemble (core->rasm, &op, buf, sizeof (buf)); + char *str = (ret > 0)? strdup (rz_strbuf_get (&op.buf_asm)): NULL; + rz_asm_op_fini (&op); return str; } -R_API RAnalOp *r_core_op_anal(RCore *core, ut64 addr, RAnalOpMask mask) { +RZ_API RzAnalOp *rz_core_op_anal(RzCore *core, ut64 addr, RzAnalOpMask mask) { ut8 buf[64]; - RAnalOp *op = R_NEW (RAnalOp); - r_io_read_at (core->io, addr, buf, sizeof (buf)); - r_anal_op (core->anal, op, addr, buf, sizeof (buf), mask); + RzAnalOp *op = R_NEW (RzAnalOp); + rz_io_read_at (core->io, addr, buf, sizeof (buf)); + rz_anal_op (core->anal, op, addr, buf, sizeof (buf), mask); return op; } static void rap_break (void *u) { - RIORap *rior = (RIORap*) u; + RzIORap *rior = (RzIORap*) u; if (u) { - r_socket_close (rior->fd); + rz_socket_close (rior->fd); rior->fd = NULL; } } // TODO: PLEASE move into core/io/rap? */ // TODO: use static buffer instead of mallocs all the time. it's network! -R_API bool r_core_serve(RCore *core, RIODesc *file) { - // TODO: use r_socket_rap_server API instead of duplicating the logic +RZ_API bool rz_core_serve(RzCore *core, RzIODesc *file) { + // TODO: use rz_socket_rap_server API instead of duplicating the logic ut8 cmd, flg, *ptr = NULL, buf[1024]; int i, pipefd = -1; ut64 x; - RIORap *rior = (RIORap *)file->data; + RzIORap *rior = (RzIORap *)file->data; if (!rior|| !rior->fd) { eprintf ("rap: cannot listen.\n"); return false; } - RSocket *fd = rior->fd; + RzSocket *fd = rior->fd; eprintf ("RAP Server started (rap.loop=%s)\n", - r_config_get (core->config, "rap.loop")); - r_cons_break_push (rap_break, rior); + rz_config_get (core->config, "rap.loop")); + rz_cons_break_push (rap_break, rior); reaccept: - while (!r_cons_is_breaked ()) { - RSocket *c = r_socket_accept (fd); + while (!rz_cons_is_breaked ()) { + RzSocket *c = rz_socket_accept (fd); if (!c) { break; } - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { goto out_of_function; } if (!c) { eprintf ("rap: cannot accept\n"); - r_socket_free (c); + rz_socket_free (c); goto out_of_function; } eprintf ("rap: client connected\n"); - for (;!r_cons_is_breaked ();) { - if (!r_socket_read_block (c, &cmd, 1)) { + for (;!rz_cons_is_breaked ();) { + if (!rz_socket_read_block (c, &cmd, 1)) { eprintf ("rap: connection closed\n"); - if (r_config_get_i (core->config, "rap.loop")) { + if (rz_config_get_i (core->config, "rap.loop")) { eprintf ("rap: waiting for new connection\n"); - r_socket_free (c); + rz_socket_free (c); goto reaccept; } goto out_of_function; } switch (cmd) { case RAP_PACKET_OPEN: - r_socket_read_block (c, &flg, 1); // flags + rz_socket_read_block (c, &flg, 1); // flags eprintf ("open (%d): ", cmd); - r_socket_read_block (c, &cmd, 1); // len + rz_socket_read_block (c, &cmd, 1); // len pipefd = -1; if (UT8_ADD_OVFCHK (cmd, 1)) { goto out_of_function; @@ -3166,17 +3166,17 @@ reaccept: if (!ptr) { eprintf ("Cannot malloc in rmt-open len = %d\n", cmd); } else { - ut64 baddr = r_config_get_i (core->config, "bin.laddr"); - r_socket_read_block (c, ptr, cmd); + ut64 baddr = rz_config_get_i (core->config, "bin.laddr"); + rz_socket_read_block (c, ptr, cmd); ptr[cmd] = 0; ut32 perm = R_PERM_R; if (flg & R_PERM_W) { perm |= R_PERM_W; } - if (r_core_file_open (core, (const char *)ptr, perm, 0)) { - int fd = r_io_fd_get_current (core->io); - r_core_bin_load (core, NULL, baddr); - r_io_map_add (core->io, fd, perm, 0, 0, r_io_fd_size (core->io, fd)); + if (rz_core_file_open (core, (const char *)ptr, perm, 0)) { + int fd = rz_io_fd_get_current (core->io); + rz_core_bin_load (core, NULL, baddr); + rz_io_map_add (core->io, fd, perm, 0, 0, rz_io_fd_size (core->io, fd)); if (core->file) { pipefd = fd; } else { @@ -3187,45 +3187,45 @@ reaccept: } else { pipefd = -1; eprintf ("Cannot open file (%s)\n", ptr); - r_socket_close (c); - if (r_config_get_i (core->config, "rap.loop")) { + rz_socket_close (c); + if (rz_config_get_i (core->config, "rap.loop")) { eprintf ("rap: waiting for new connection\n"); - r_socket_free (c); + rz_socket_free (c); goto reaccept; } goto out_of_function; //XXX: Close connection and goto accept } } buf[0] = RAP_PACKET_OPEN | RAP_PACKET_REPLY; - r_write_be32 (buf + 1, pipefd); - r_socket_write (c, buf, 5); - r_socket_flush (c); + rz_write_be32 (buf + 1, pipefd); + rz_socket_write (c, buf, 5); + rz_socket_flush (c); R_FREE (ptr); break; case RAP_PACKET_READ: - r_socket_read_block (c, (ut8*)&buf, 4); - i = r_read_be32 (buf); + rz_socket_read_block (c, (ut8*)&buf, 4); + i = rz_read_be32 (buf); ptr = (ut8 *)malloc (i + core->blocksize + 5); if (ptr) { - r_core_block_read (core); + rz_core_block_read (core); ptr[0] = RAP_PACKET_READ | RAP_PACKET_REPLY; if (i > RAP_PACKET_MAX) { i = RAP_PACKET_MAX; } if (i > core->blocksize) { - r_core_block_size (core, i); + rz_core_block_size (core, i); } if (i + 128 < core->blocksize) { - r_core_block_size (core, i); + rz_core_block_size (core, i); } - r_write_be32 (ptr + 1, i); + rz_write_be32 (ptr + 1, i); memcpy (ptr + 5, core->block, i); //core->blocksize); - r_socket_write (c, ptr, i + 5); - r_socket_flush (c); + rz_socket_write (c, ptr, i + 5); + rz_socket_flush (c); R_FREE (ptr); } else { eprintf ("Cannot read %d byte(s)\n", i); - r_socket_free (c); + rz_socket_free (c); // TODO: reply error here goto out_of_function; } @@ -3238,16 +3238,16 @@ reaccept: int i; /* read */ - r_socket_read_block (c, (ut8*)&bufr, 4); - i = r_read_be32 (bufr); + rz_socket_read_block (c, (ut8*)&bufr, 4); + i = rz_read_be32 (bufr); if (i > 0 && i < RAP_PACKET_MAX) { if ((cmd = malloc (i + 1))) { - r_socket_read_block (c, (ut8*)cmd, i); + rz_socket_read_block (c, (ut8*)cmd, i); cmd[i] = '\0'; - int scr_interactive = r_config_get_i (core->config, "scr.interactive"); - r_config_set_i (core->config, "scr.interactive", 0); - cmd_output = r_core_cmd_str (core, cmd); - r_config_set_i (core->config, "scr.interactive", scr_interactive); + int scr_interactive = rz_config_get_i (core->config, "scr.interactive"); + rz_config_set_i (core->config, "scr.interactive", 0); + cmd_output = rz_core_cmd_str (core, cmd); + rz_config_set_i (core->config, "scr.interactive", scr_interactive); free (cmd); } else { eprintf ("rap: cannot malloc\n"); @@ -3270,81 +3270,81 @@ reaccept: int cmd_len = strlen (cmd) + 1; ut8 *b = malloc (cmd_len + 5); b[0] = RAP_PACKET_CMD; - r_write_be32 (b + 1, cmd_len); + rz_write_be32 (b + 1, cmd_len); strcpy ((char *)b+ 5, cmd); - r_socket_write (c, b, 5 + cmd_len); - r_socket_flush (c); + rz_socket_write (c, b, 5 + cmd_len); + rz_socket_flush (c); /* read response */ - r_socket_read_block (c, b, 5); + rz_socket_read_block (c, b, 5); if (b[0] == (RAP_PACKET_CMD | RAP_PACKET_REPLY)) { - ut32 n = r_read_be32 (b + 1); + ut32 n = rz_read_be32 (b + 1); eprintf ("REPLY %d\n", n); if (n > 0) { ut8 *res = calloc (1, n); - r_socket_read_block (c, res, n); + rz_socket_read_block (c, res, n); eprintf ("RESPONSE(%s)\n", (const char *)res); free (res); } } - r_socket_flush (c); + rz_socket_flush (c); free (b); once = false; } #endif bufw = malloc (cmd_len + 5); bufw[0] = (ut8) (RAP_PACKET_CMD | RAP_PACKET_REPLY); - r_write_be32 (bufw + 1, cmd_len); + rz_write_be32 (bufw + 1, cmd_len); memcpy (bufw + 5, cmd_output, cmd_len); - r_socket_write (c, bufw, cmd_len+5); - r_socket_flush (c); + rz_socket_write (c, bufw, cmd_len+5); + rz_socket_flush (c); free (bufw); free (cmd_output); break; } case RAP_PACKET_WRITE: - r_socket_read_block (c, buf, 4); - x = r_read_at_be32 (buf, 0); + rz_socket_read_block (c, buf, 4); + x = rz_read_at_be32 (buf, 0); ptr = malloc (x); - r_socket_read_block (c, ptr, x); - int ret = r_core_write_at (core, core->offset, ptr, x); + rz_socket_read_block (c, ptr, x); + int ret = rz_core_write_at (core, core->offset, ptr, x); buf[0] = RAP_PACKET_WRITE | RAP_PACKET_REPLY; - r_write_be32 (buf + 1, ret); - r_socket_write (c, buf, 5); - r_socket_flush (c); + rz_write_be32 (buf + 1, ret); + rz_socket_write (c, buf, 5); + rz_socket_flush (c); R_FREE (ptr); break; case RAP_PACKET_SEEK: - r_socket_read_block (c, buf, 9); - x = r_read_at_be64 (buf, 1); + rz_socket_read_block (c, buf, 9); + x = rz_read_at_be64 (buf, 1); if (buf[0] == 2) { if (core->file) { - x = r_io_fd_size (core->io, core->file->fd); + x = rz_io_fd_size (core->io, core->file->fd); } else { x = 0; } } else { if (buf[0] == 0) { - r_core_seek (core, x, true); //buf[0]); + rz_core_seek (core, x, true); //buf[0]); } x = core->offset; } buf[0] = RAP_PACKET_SEEK | RAP_PACKET_REPLY; - r_write_be64 (buf + 1, x); - r_socket_write (c, buf, 9); - r_socket_flush (c); + rz_write_be64 (buf + 1, x); + rz_socket_write (c, buf, 9); + rz_socket_flush (c); break; case RAP_PACKET_CLOSE: // XXX : proper shutdown - r_socket_read_block (c, buf, 4); - i = r_read_be32 (buf); + rz_socket_read_block (c, buf, 4); + i = rz_read_be32 (buf); { - //FIXME: Use r_socket_close + //FIXME: Use rz_socket_close int ret = close (i); - r_write_be32 (buf + 1, ret); + rz_write_be32 (buf + 1, ret); buf[0] = RAP_PACKET_CLOSE | RAP_PACKET_REPLY; - r_socket_write (c, buf, 5); - r_socket_flush (c); + rz_socket_write (c, buf, 5); + rz_socket_flush (c); } break; default: @@ -3352,7 +3352,7 @@ reaccept: // silly http emulation over rap:// char line[256] = {0}; char *cmd = line; - r_socket_read_block (c, (ut8*)line, sizeof (line)); + rz_socket_read_block (c, (ut8*)line, sizeof (line)); if (!strncmp (line, "ET /cmd/", 8)) { cmd = line + 8; char *http = strstr (cmd, "HTTP"); @@ -3363,40 +3363,40 @@ reaccept: *http = 0; } } - r_str_uri_decode (cmd); - char *res = r_core_cmd_str (core, cmd); + rz_str_uri_decode (cmd); + char *res = rz_core_cmd_str (core, cmd); if (res) { - r_socket_printf (c, "HTTP/1.0 %d %s\r\n%s" + rz_socket_printf (c, "HTTP/1.0 %d %s\r\n%s" "Connection: close\r\nContent-Length: %d\r\n\r\n", 200, "OK", "", -1); // strlen (res)); - r_socket_write (c, res, strlen (res)); + rz_socket_write (c, res, strlen (res)); free (res); } - r_socket_flush (c); - r_socket_close (c); + rz_socket_flush (c); + rz_socket_close (c); } } else { eprintf ("[rap] unknown command 0x%02x\n", cmd); - r_socket_close (c); + rz_socket_close (c); R_FREE (ptr); } - if (r_config_get_i (core->config, "rap.loop")) { + if (rz_config_get_i (core->config, "rap.loop")) { eprintf ("rap: waiting for new connection\n"); - r_socket_free (c); + rz_socket_free (c); goto reaccept; } goto out_of_function; } } eprintf ("client: disconnected\n"); - r_socket_free (c); + rz_socket_free (c); } out_of_function: - r_cons_break_pop (); + rz_cons_break_pop (); return false; } -R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback cb) { +RZ_API int rz_core_search_cb(RzCore *core, ut64 from, ut64 to, RzCoreSearchCallback cb) { int ret, len = core->blocksize; ut8 *buf = malloc (len); if (!buf) { @@ -3408,7 +3408,7 @@ R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback if (delta < len) { len = (int)delta; } - if (!r_io_read_at (core->io, from, buf, len)) { + if (!rz_io_read_at (core->io, from, buf, len)) { eprintf ("Cannot read at 0x%"PFMT64x"\n", from); break; } @@ -3426,9 +3426,9 @@ R_API int r_core_search_cb(RCore *core, ut64 from, ut64 to, RCoreSearchCallback return true; } -R_API char *r_core_editor(const RCore *core, const char *file, const char *str) { - const bool interactive = r_cons_is_interactive (); - const char *editor = r_config_get (core->config, "cfg.editor"); +RZ_API char *rz_core_editor(const RzCore *core, const char *file, const char *str) { + const bool interactive = rz_cons_is_interactive (); + const char *editor = rz_config_get (core->config, "cfg.editor"); char *name = NULL, *ret = NULL; int fd; @@ -3438,16 +3438,16 @@ R_API char *r_core_editor(const RCore *core, const char *file, const char *str) bool readonly = false; if (file && *file != '*') { name = strdup (file); - fd = r_sandbox_open (file, O_RDWR, 0644); + fd = rz_sandbox_open (file, O_RDWR, 0644); if (fd == -1) { - fd = r_sandbox_open (file, O_RDWR | O_CREAT, 0644); + fd = rz_sandbox_open (file, O_RDWR | O_CREAT, 0644); if (fd == -1) { - fd = r_sandbox_open (file, O_RDONLY, 0644); + fd = rz_sandbox_open (file, O_RDONLY, 0644); readonly = true; } } } else { - fd = r_file_mkstemp (file, &name); + fd = rz_file_mkstemp (file, &name); } if (fd == -1) { free (name); @@ -3468,24 +3468,24 @@ R_API char *r_core_editor(const RCore *core, const char *file, const char *str) close (fd); if (name && (!editor || !*editor || !strcmp (editor, "-"))) { - RCons *cons = r_cons_singleton (); + RzCons *cons = rz_cons_singleton (); void *tmp = cons->cb_editor; cons->cb_editor = NULL; - r_cons_editor (name, NULL); + rz_cons_editor (name, NULL); cons->cb_editor = tmp; } else { if (editor && name) { - r_sys_cmdf ("%s '%s'", editor, name); + rz_sys_cmdf ("%s '%s'", editor, name); } } size_t len = 0; - ret = name? r_file_slurp (name, &len): 0; + ret = name? rz_file_slurp (name, &len): 0; if (ret) { if (len && ret[len - 1] == '\n') { ret[len - 1] = 0; // chop } if (!file) { - r_file_rm (name); + rz_file_rm (name); } } free (name); @@ -3493,32 +3493,32 @@ R_API char *r_core_editor(const RCore *core, const char *file, const char *str) } /* weak getters */ -R_API RCons *r_core_get_cons (RCore *core) { +RZ_API RzCons *rz_core_get_cons (RzCore *core) { return core->cons; } -R_API RConfig *r_core_get_config (RCore *core) { +RZ_API RConfig *rz_core_get_config (RzCore *core) { return core->config; } -R_API RBin *r_core_get_bin (RCore *core) { +RZ_API RBin *rz_core_get_bin (RzCore *core) { return core->bin; } -R_API RBuffer *r_core_syscallf (RCore *core, const char *name, const char *fmt, ...) { +RZ_API RBuffer *rz_core_syscallf (RzCore *core, const char *name, const char *fmt, ...) { char str[1024]; RBuffer *buf; va_list ap; va_start (ap, fmt); vsnprintf (str, sizeof (str), fmt, ap); - buf = r_core_syscall (core, name, str); + buf = rz_core_syscall (core, name, str); va_end (ap); return buf; } -R_API RBuffer *r_core_syscall (RCore *core, const char *name, const char *args) { +RZ_API RBuffer *rz_core_syscall (RzCore *core, const char *name, const char *args) { RBuffer *b = NULL; char code[1024]; int num; @@ -3529,7 +3529,7 @@ R_API RBuffer *r_core_syscall (RCore *core, const char *name, const char *args) return 0; } - num = r_syscall_get_num (core->anal->syscall, name); + num = rz_syscall_get_num (core->anal->syscall, name); //bits check switch (core->rasm->bits) { @@ -3555,38 +3555,38 @@ R_API RBuffer *r_core_syscall (RCore *core, const char *name, const char *args) "main@global(0) { sc(%s);\n" ":int3\n" /// XXX USE trap "}\n", num, args); - r_egg_reset (core->egg); + rz_egg_reset (core->egg); // TODO: setup arch/bits/os? - r_egg_load (core->egg, code, 0); + rz_egg_load (core->egg, code, 0); - if (!r_egg_compile (core->egg)) { + if (!rz_egg_compile (core->egg)) { eprintf ("Cannot compile.\n"); } - if (!r_egg_assemble (core->egg)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble (core->egg)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); } - if ((b = r_egg_get_bin (core->egg))) { + if ((b = rz_egg_get_bin (core->egg))) { #if 0 if (b->length > 0) { for (i = 0; i < b->length; i++) { - r_cons_printf ("%02x", b->buf[i]); + rz_cons_printf ("%02x", b->buf[i]); } - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } #endif } return b; } -R_API RCoreAutocomplete *r_core_autocomplete_add(RCoreAutocomplete *parent, const char* cmd, int type, bool lock) { +RZ_API RzCoreAutocomplete *rz_core_autocomplete_add(RzCoreAutocomplete *parent, const char* cmd, int type, bool lock) { if (!parent || !cmd || type < 0 || type >= R_CORE_AUTOCMPLT_END) { return NULL; } - RCoreAutocomplete *autocmpl = R_NEW0 (RCoreAutocomplete); + RzCoreAutocomplete *autocmpl = R_NEW0 (RzCoreAutocomplete); if (!autocmpl) { return NULL; } - RCoreAutocomplete **updated = realloc (parent->subcmds, (parent->n_subcmds + 1) * sizeof (RCoreAutocomplete*)); + RzCoreAutocomplete **updated = realloc (parent->subcmds, (parent->n_subcmds + 1) * sizeof (RzCoreAutocomplete*)); if (!updated) { free (autocmpl); return NULL; @@ -3601,13 +3601,13 @@ R_API RCoreAutocomplete *r_core_autocomplete_add(RCoreAutocomplete *parent, cons return autocmpl; } -R_API void r_core_autocomplete_free(RCoreAutocomplete *obj) { +RZ_API void rz_core_autocomplete_free(RzCoreAutocomplete *obj) { if (!obj) { return; } int i; for (i = 0; i < obj->n_subcmds; i++) { - r_core_autocomplete_free (obj->subcmds[i]); + rz_core_autocomplete_free (obj->subcmds[i]); obj->subcmds[i] = NULL; } free (obj->subcmds); @@ -3615,7 +3615,7 @@ R_API void r_core_autocomplete_free(RCoreAutocomplete *obj) { free (obj); } -R_API RCoreAutocomplete *r_core_autocomplete_find(RCoreAutocomplete *parent, const char* cmd, bool exact) { +RZ_API RzCoreAutocomplete *rz_core_autocomplete_find(RzCoreAutocomplete *parent, const char* cmd, bool exact) { if (!parent || !cmd) { return false; } @@ -3631,24 +3631,24 @@ R_API RCoreAutocomplete *r_core_autocomplete_find(RCoreAutocomplete *parent, con return NULL; } -R_API bool r_core_autocomplete_remove(RCoreAutocomplete *parent, const char* cmd) { +RZ_API bool rz_core_autocomplete_remove(RzCoreAutocomplete *parent, const char* cmd) { if (!parent || !cmd) { return false; } int i, j; for (i = 0; i < parent->n_subcmds; i++) { - RCoreAutocomplete *ac = parent->subcmds[i]; + RzCoreAutocomplete *ac = parent->subcmds[i]; if (ac->locked) { continue; } // if (!strncmp (parent->subcmds[i]->cmd, cmd, parent->subcmds[i]->length)) { - if (r_str_glob (ac->cmd, cmd)) { + if (rz_str_glob (ac->cmd, cmd)) { for (j = i + 1; j < parent->n_subcmds; j++) { parent->subcmds[j - 1] = parent->subcmds[j]; parent->subcmds[j] = NULL; } - r_core_autocomplete_free (ac); - RCoreAutocomplete **updated = realloc (parent->subcmds, (parent->n_subcmds - 1) * sizeof (RCoreAutocomplete*)); + rz_core_autocomplete_free (ac); + RzCoreAutocomplete **updated = realloc (parent->subcmds, (parent->n_subcmds - 1) * sizeof (RzCoreAutocomplete*)); if (!updated && (parent->n_subcmds - 1) > 0) { eprintf ("Something really bad has happen.. this should never ever happen..\n"); return false; @@ -3661,8 +3661,8 @@ R_API bool r_core_autocomplete_remove(RCoreAutocomplete *parent, const char* cmd return false; } -R_API RTable *r_core_table(RCore *core) { - RTable *table = r_table_new (); +RZ_API RTable *rz_core_table(RzCore *core) { + RTable *table = rz_table_new (); if (table) { table->cons = core->cons; } diff --git a/libr/core/corelog.c b/librz/core/corelog.c similarity index 55% rename from libr/core/corelog.c rename to librz/core/corelog.c index 6b3dec9b2a..0ad6cba887 100644 --- a/libr/core/corelog.c +++ b/librz/core/corelog.c @@ -1,31 +1,31 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include -R_API int r_core_log_list(RCore *core, int n, int nth, char fmt) { +RZ_API int rz_core_log_list(RzCore *core, int n, int nth, char fmt) { int printed = 0; int count = 0, i, idx, id = core->log->first; RStrpool *sp = core->log->sp; char *str = sp->str; if (fmt == 'j') { - r_cons_printf ("["); + rz_cons_printf ("["); } for (i = idx = 0; str && *str; i++, id++) { if ((n && n <= id) || !n) { switch (fmt) { case 'j': - r_cons_printf ("%s[%d,\"%s\"]", + rz_cons_printf ("%s[%d,\"%s\"]", printed? ",": "", id, str); break; case 't': - r_cons_println (str); + rz_cons_println (str); break; case '*': - r_cons_printf ("\"T %s\"\n", str); + rz_cons_printf ("\"T %s\"\n", str); break; default: - r_cons_printf ("%d %s\n", id, str); + rz_cons_printf ("%d %s\n", id, str); break; } printed++; @@ -33,40 +33,40 @@ R_API int r_core_log_list(RCore *core, int n, int nth, char fmt) { break; } } - str = r_strpool_next (sp, idx); + str = rz_strpool_next (sp, idx); if (!str) { break; } - idx = r_strpool_get_index (sp, str); + idx = rz_strpool_get_index (sp, str); count++; } if (fmt == 'j') { - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); } return count; } -R_API RCoreLog *r_core_log_new(void) { - RCoreLog *log = R_NEW0 (RCoreLog); +RZ_API RzCoreLog *rz_core_log_new(void) { + RzCoreLog *log = R_NEW0 (RzCoreLog); if (!log) { return NULL; } - r_core_log_init (log); + rz_core_log_init (log); return log; } -R_API void r_core_log_init(RCoreLog *log) { +RZ_API void rz_core_log_init(RzCoreLog *log) { log->first = 1; log->last = 1; - log->sp = r_strpool_new (0); + log->sp = rz_strpool_new (0); } -R_API void r_core_log_free(RCoreLog *log) { - r_strpool_free (log->sp); +RZ_API void rz_core_log_free(RzCoreLog *log) { + rz_strpool_free (log->sp); free (log); } -R_API bool r_core_log_run(RCore *core, const char *_buf, RCoreLogCallback runLine) { +RZ_API bool rz_core_log_run(RzCore *core, const char *_buf, RzCoreLogCallback runLine) { char *obuf = strdup (_buf); char *buf = obuf; while (buf) { @@ -88,22 +88,22 @@ R_API bool r_core_log_run(RCore *core, const char *_buf, RCoreLogCallback runLin return true; } -R_API char *r_core_log_get(RCore *core, int index) { - const char *host = r_config_get (core->config, "http.sync"); +RZ_API char *rz_core_log_get(RzCore *core, int index) { + const char *host = rz_config_get (core->config, "http.sync"); if (host && *host) { char *url = index > 0 - ? r_str_newf ("%s/cmd/T%%20%d", host, index) - : r_str_newf ("%s/cmd/T", host); - char *res = r_socket_http_get (url, NULL, NULL); + ? rz_str_newf ("%s/cmd/T%%20%d", host, index) + : rz_str_newf ("%s/cmd/T", host); + char *res = rz_socket_http_get (url, NULL, NULL); free (url); return res? res: strdup (""); } return NULL; } -R_API void r_core_log_add(RCore *core, const char *msg) { +RZ_API void rz_core_log_add(RzCore *core, const char *msg) { static bool inProcess = false; - r_strpool_append (core->log->sp, msg); + rz_strpool_append (core->log->sp, msg); core->log->last++; if (core->cmdlog && *core->cmdlog) { if (inProcess) { @@ -111,17 +111,17 @@ R_API void r_core_log_add(RCore *core, const char *msg) { return; } inProcess = true; - r_core_cmd0 (core, core->cmdlog); + rz_core_cmd0 (core, core->cmdlog); inProcess = false; } } -R_API void r_core_log_del(RCore *core, int n) { +RZ_API void rz_core_log_del(RzCore *core, int n) { int idx; if (n > 0) { if (n + 1 >= core->log->last) { core->log->first = core->log->last; - r_strpool_empty (core->log->sp); + rz_strpool_empty (core->log->sp); return; } if (n < core->log->first) { @@ -132,16 +132,16 @@ R_API void r_core_log_del(RCore *core, int n) { return; } core->log->first += idx + 1; - char *msg = r_strpool_get_i (core->log->sp, idx); + char *msg = rz_strpool_get_i (core->log->sp, idx); // if (idx >= core->log->last) { if (!msg || !*msg) { core->log->first = core->log->last; - r_strpool_empty (core->log->sp); + rz_strpool_empty (core->log->sp); } else { - r_strpool_slice (core->log->sp, idx); + rz_strpool_slice (core->log->sp, idx); } } else { core->log->first = core->log->last; - r_strpool_empty (core->log->sp); + rz_strpool_empty (core->log->sp); } } diff --git a/librz/core/cplugin.c b/librz/core/cplugin.c new file mode 100644 index 0000000000..5967834800 --- /dev/null +++ b/librz/core/cplugin.c @@ -0,0 +1,61 @@ +/* radare - LGPL - Copyright 2010-2018 - pancake */ + +/* covardly copied from rz_cmd */ + +#include +#include +#include +#include +#include + +static RzCorePlugin *cmd_static_plugins[] = { + R_CORE_STATIC_PLUGINS +}; + +RZ_API int rz_core_plugin_fini(RzCmd *cmd) { + RzListIter *iter; + RzCorePlugin *plugin; + if (!cmd->plist) { + return false; + } + rz_list_foreach (cmd->plist, iter, plugin) { + if (plugin && plugin->fini) { + plugin->fini (cmd, NULL); + } + } + /* empty the list */ + rz_list_free (cmd->plist); + cmd->plist = NULL; + return true; +} + +RZ_API int rz_core_plugin_add(RzCmd *cmd, RzCorePlugin *plugin) { + if (!cmd || (plugin && plugin->init && !plugin->init (cmd, NULL))) { + return false; + } + rz_list_append (cmd->plist, plugin); + return true; +} + +RZ_API int rz_core_plugin_init(RzCmd *cmd) { + int i; + cmd->plist = rz_list_newf (NULL); // memleak or dblfree + for (i = 0; cmd_static_plugins[i]; i++) { + if (!rz_core_plugin_add (cmd, cmd_static_plugins[i])) { + eprintf ("Error loading cmd plugin\n"); + return false; + } + } + return true; +} + +RZ_API int rz_core_plugin_check(RzCmd *cmd, const char *a0) { + RzListIter *iter; + RzCorePlugin *cp; + rz_list_foreach (cmd->plist, iter, cp) { + if (cp->call (NULL, a0)) { + return true; + } + } + return false; +} diff --git a/librz/core/cundo.c b/librz/core/cundo.c new file mode 100644 index 0000000000..8fea2dfe02 --- /dev/null +++ b/librz/core/cundo.c @@ -0,0 +1,76 @@ +/* rizin - LGPL - Copyright 2018-2019 - pancake */ + +#include + +#if 0 + +TODO: + +- add more methods to "undo according to some conditions" +- undo all comments in current offfset +#endif + +RZ_API RzCoreUndo *rz_core_undo_new(ut64 offset, const char *action, const char *revert) { + RzCoreUndo *cu = R_NEW (RzCoreUndo); + if (cu) { + cu->action = strdup (action); + cu->revert = strdup (revert); + cu->tstamp = rz_time_now (); + cu->offset = offset; + } + return cu; +} + +RZ_API void rz_core_undo_free(RzCoreUndo *cu) { + if (cu) { + free (cu->action); + free (cu->revert); + } + free (cu); +} + +RZ_API void rz_core_undo_push(RzCore *core, RzCoreUndo *cu) { + rz_list_append (core->undos, cu); +} + +RZ_API void rz_core_undo_pop(RzCore *core) { + RzCoreUndo *undo = rz_list_pop (core->undos); + if (undo) { + rz_core_cmd0 (core, undo->revert); + rz_core_undo_free (undo); + } +} + +RZ_API bool rz_core_undo_condition(RzCoreUndo *cu, RzCoreUndoCondition *cond) { + if (!cond) { + return true; + } + bool mustPrint = false; + if (cond->addr != UT64_MAX) { + mustPrint = (cu->offset == cond->addr); + } + if (cond->minstamp) { + mustPrint = (cu->tstamp >= cond->minstamp); + } + if (cond->glob) { + mustPrint = rz_str_glob (cu->action, cond->glob); + } + return mustPrint; +} + +RZ_API void rz_core_undo_print(RzCore *core, int mode, RzCoreUndoCondition *cond) { + RzCoreUndo *cu; + RzListIter *iter; + if (mode) { + rz_list_foreach (core->undos, iter, cu) { + if (rz_core_undo_condition (cu, cond)) { + rz_cons_printf ("%s @ 0x%"PFMT64x"\n", cu->revert, cu->offset); + } + } + } else { + rz_list_foreach (core->undos, iter, cu) { + rz_cons_printf ("0x%08"PFMT64x" %"PFMT64d" %s (revert: %s)\n", + cu->offset, cu->tstamp, cu->action, cu->revert); + } + } +} diff --git a/libr/core/disasm.c b/librz/core/disasm.c similarity index 66% rename from libr/core/disasm.c rename to librz/core/disasm.c index d1ef9cedc0..3318787304 100644 --- a/libr/core/disasm.c +++ b/librz/core/disasm.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - nibble, pancake, dso */ -#include "r_core.h" +#include "rz_core.h" #define HASRETRY 1 #define HAVE_LOCALS 1 @@ -16,7 +16,7 @@ static ut64 emustack_min = 0LL; static ut64 emustack_max = 0LL; -static const char* r_vline_a[] = { +static const char* rz_vline_a[] = { "|", // LINE_VERT "|-", // LINE_CROSS "-", // LINE_HORIZ @@ -29,7 +29,7 @@ static const char* r_vline_a[] = { "=<", // ARROW_LEFT }; -static const char* r_vline_u[] = { +static const char* rz_vline_u[] = { "│", // LINE_VERT "├", // LINE_CROSS "─", // LINE_HORIZ @@ -44,7 +44,7 @@ static const char* r_vline_u[] = { "<", // ARROW_LEFT }; -static const char* r_vline_uc[] = { +static const char* rz_vline_uc[] = { "│", // LINE_VERT "├", // LINE_CROSS "─", // LINE_HORIZ @@ -66,10 +66,10 @@ static const char* r_vline_uc[] = { #define DS_PRE_FCN_MIDDLE 3 #define DS_PRE_FCN_TAIL 4 -// TODO: what about using bit shifting and enum for keys? see libr/util/bitmap.c +// TODO: what about using bit shifting and enum for keys? see librz/util/bitmap.c // the problem of this is that the fields will be more opaque to bindings, but we will earn some bits typedef struct { - RCore *core; + RzCore *core; char str[1024], strsub[1024]; bool immtrim; bool immstr; @@ -114,7 +114,7 @@ typedef struct { int asm_demangle; bool asm_instr; bool show_offset; - bool show_offdec; // dupe for r_print->flags + bool show_offdec; // dupe for rz_print->flags bool show_bbline; bool show_emu; bool pre_emu; @@ -232,8 +232,8 @@ typedef struct { const char *color_func_var_type; const char *color_func_var_addr; - RFlagItem *lastflag; - RAnalHint *hint; + RzFlagItem *lastflag; + RzAnalHint *hint; RPrint *print; ut64 esil_old_pc; @@ -257,10 +257,10 @@ typedef struct { int tries, cbytes, idx; char chref; bool retry; - RAsmOp asmop; - RAnalOp analop; - RAnalFunction *fcn; - RAnalFunction *pdf; + RzAsmOp asmop; + RzAnalOp analop; + RzAnalFunction *fcn; + RzAnalFunction *pdf; const ut8 *buf; int len; int maxrefs; @@ -300,7 +300,7 @@ static void ds_begin_cont(RDisasmState *ds); static void ds_print_esil_anal(RDisasmState *ds); static void ds_reflines_init(RDisasmState *ds); static void ds_align_comment(RDisasmState *ds); -static RDisasmState * ds_init(RCore * core); +static RDisasmState * ds_init(RzCore * core); static void ds_build_op_str(RDisasmState *ds, bool print_color); static void ds_print_show_bytes(RDisasmState *ds); static void ds_pre_xrefs(RDisasmState *ds, bool no_fcnlines); @@ -325,7 +325,7 @@ static void ds_print_trace(RDisasmState *ds); static void ds_print_opstr(RDisasmState *ds); static void ds_print_color_reset(RDisasmState *ds); static int ds_print_middle(RDisasmState *ds, int ret); -static bool ds_print_labels(RDisasmState *ds, RAnalFunction *f); +static bool ds_print_labels(RDisasmState *ds, RzAnalFunction *f); static void ds_print_sysregs(RDisasmState *ds); static void ds_print_fcn_name(RDisasmState *ds); static void ds_print_as_string(RDisasmState *ds); @@ -342,9 +342,9 @@ static void ds_end_line_highlight(RDisasmState *ds); static bool line_highlighted(RDisasmState *ds); static int ds_print_shortcut(RDisasmState *ds, ut64 addr, int pos); -R_API ut64 r_core_pava (RCore *core, ut64 addr) { +RZ_API ut64 rz_core_pava (RzCore *core, ut64 addr) { if (core->print->pava) { - RIOMap *map = r_io_map_get_paddr (core->io, addr); + RzIOMap *map = rz_io_map_get_paddr (core->io, addr); if (map) { return addr - map->delta + map->itv.addr; } @@ -352,11 +352,11 @@ R_API ut64 r_core_pava (RCore *core, ut64 addr) { return addr; } -static RAnalFunction *fcnIn(RDisasmState *ds, ut64 at, int type) { - if (ds->fcn && r_anal_function_contains (ds->fcn, at)) { +static RzAnalFunction *fcnIn(RDisasmState *ds, ut64 at, int type) { + if (ds->fcn && rz_anal_function_contains (ds->fcn, at)) { return ds->fcn; } - return r_anal_get_fcn_in (ds->core->anal, at, type); + return rz_anal_get_fcn_in (ds->core->anal, at, type); } static const char *get_utf8_char(const char line, RDisasmState *ds) { @@ -381,43 +381,43 @@ static void ds_print_ref_lines(char *line, char *line_col, RDisasmState *ds) { if (ds->show_color) { for (i = 0; i < len; i++) { if (line[i] == ' ') { - r_cons_printf (" "); + rz_cons_printf (" "); continue; } if (line_col[i] == 'd') { - r_cons_printf ("%s%s%s", COLOR (ds, color_flow), get_utf8_char (line[i], ds), COLOR_RESET (ds)); + rz_cons_printf ("%s%s%s", COLOR (ds, color_flow), get_utf8_char (line[i], ds), COLOR_RESET (ds)); } else { - r_cons_printf ("%s%s%s", COLOR (ds, color_flow2), get_utf8_char (line[i], ds), COLOR_RESET (ds)); + rz_cons_printf ("%s%s%s", COLOR (ds, color_flow2), get_utf8_char (line[i], ds), COLOR_RESET (ds)); } } } else { len = strlen (line); for (i = 0; i < len; i++) { - r_cons_printf ("%s", get_utf8_char (line[i], ds)); + rz_cons_printf ("%s", get_utf8_char (line[i], ds)); } } } else { if (ds->show_color) { for (i = 0; i < len; i++) { if (line[i] == ' ') { - r_cons_printf (" "); + rz_cons_printf (" "); continue; } if (line_col[i] == 'd') { - r_cons_printf ("%s%c%s", COLOR (ds, color_flow), line[i], COLOR_RESET (ds)); + rz_cons_printf ("%s%c%s", COLOR (ds, color_flow), line[i], COLOR_RESET (ds)); } else { - r_cons_printf ("%s%c%s", COLOR (ds, color_flow2), line[i], COLOR_RESET (ds)); + rz_cons_printf ("%s%c%s", COLOR (ds, color_flow2), line[i], COLOR_RESET (ds)); } } } else { - r_cons_printf ("%s", line); + rz_cons_printf ("%s", line); } } } -static void get_bits_comment(RCore *core, RAnalFunction *f, char *cmt, int cmt_size) { +static void get_bits_comment(RzCore *core, RzAnalFunction *f, char *cmt, int cmt_size) { if (core && f && cmt && cmt_size > 0 && f->bits && f->bits != core->rasm->bits) { - const char *asm_arch = r_config_get (core->config, "asm.arch"); + const char *asm_arch = rz_config_get (core->config, "asm.arch"); if (asm_arch && *asm_arch && strstr (asm_arch, "arm")) { switch (f->bits) { case 16: strcpy (cmt, " (thumb)"); break; @@ -434,24 +434,24 @@ static void get_bits_comment(RCore *core, RAnalFunction *f, char *cmt, int cmt_s } } -R_API const char *r_core_get_section_name(RCore *core, ut64 addr) { +RZ_API const char *rz_core_get_section_name(RzCore *core, ut64 addr) { static char section[128] = ""; static ut64 oaddr = UT64_MAX; if (oaddr == addr) { return section; } - RBinObject *bo = r_bin_cur_object (core->bin); - RBinSection *s = bo? r_bin_get_section_at (bo, addr, core->io->va): NULL; + RBinObject *bo = rz_bin_cur_object (core->bin); + RBinSection *s = bo? rz_bin_get_section_at (bo, addr, core->io->va): NULL; if (s && s->name && *s->name) { snprintf (section, sizeof (section) - 1, "%10s ", s->name); } else { - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; *section = 0; - r_list_foreach (core->dbg->maps, iter, map) { + rz_list_foreach (core->dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { - const char *mn = r_str_lchr (map->name, '/'); - r_str_ncpy (section, mn? mn + 1: map->name, sizeof (section)); + const char *mn = rz_str_lchr (map->name, '/'); + rz_str_ncpy (section, mn? mn + 1: map->name, sizeof (section)); break; } } @@ -465,18 +465,18 @@ R_API const char *r_core_get_section_name(RCore *core, ut64 addr) { static void _ds_comment_align_(RDisasmState *ds, bool up, bool nl) { if (ds->show_comment_right) { if (ds->show_color) { - r_cons_printf (ds->pal_comment); + rz_cons_printf (ds->pal_comment); } return; } - const char *sn = ds->show_section ? r_core_get_section_name (ds->core, ds->at) : ""; + const char *sn = ds->show_section ? rz_core_get_section_name (ds->core, ds->at) : ""; ds_align_comment (ds); ds_align_comment (ds); - r_cons_print (COLOR_RESET (ds)); + rz_cons_print (COLOR_RESET (ds)); ds_print_pre (ds, true); - r_cons_printf ("%s%s", nl? "\n": "", sn); + rz_cons_printf ("%s%s", nl? "\n": "", sn); ds_print_ref_lines (ds->refline, ds->line_col, ds); - r_cons_printf (" %s %s",up? "": ".-", COLOR (ds, color_comment)); + rz_cons_printf (" %s %s",up? "": ".-", COLOR (ds, color_comment)); } #define _ALIGN _ds_comment_align_ (ds, true, false) @@ -489,11 +489,11 @@ static void ds_comment_(RDisasmState *ds, bool align, bool nl, const char *forma if (ds->show_comment_right && align) { ds_align_comment (ds); } else { - r_cons_printf ("%s", COLOR (ds, color_comment)); + rz_cons_printf ("%s", COLOR (ds, color_comment)); } } - r_cons_printf_list (format, ap); + rz_cons_printf_list (format, ap); if (!ds->show_comment_right && nl) { ds_newline (ds); } @@ -526,7 +526,7 @@ static void ds_comment_esil(RDisasmState *ds, bool up, bool end, const char *for if (ds->show_comments && up) { ds->show_comment_right ? ds_align_comment (ds) : ds_comment_lineup (ds); } - r_cons_printf_list (format, ap); + rz_cons_printf_list (format, ap); va_end (ap); if (ds->show_comments && !ds->show_comment_right) { @@ -537,16 +537,16 @@ static void ds_comment_esil(RDisasmState *ds, bool up, bool end, const char *for } static void ds_print_esil_anal_fini(RDisasmState *ds) { - RCore *core = ds->core; + RzCore *core = ds->core; if (ds->show_emu && ds->esil_regstate) { - RCore* core = ds->core; - core->anal->last_disasm_reg = r_reg_arena_peek (core->anal->reg); - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); - RRegSet *regset = r_reg_regset_get (ds->core->anal->reg, R_REG_TYPE_GPR); + RzCore* core = ds->core; + core->anal->last_disasm_reg = rz_reg_arena_peek (core->anal->reg); + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); + RzRegSet *regset = rz_reg_regset_get (ds->core->anal->reg, R_REG_TYPE_GPR); if (ds->esil_regstate_size == regset->arena->size) { - r_reg_arena_poke (core->anal->reg, ds->esil_regstate); + rz_reg_arena_poke (core->anal->reg, ds->esil_regstate); } - r_reg_setv (core->anal->reg, pc, ds->esil_old_pc); + rz_reg_setv (core->anal->reg, pc, ds->esil_old_pc); R_FREE (ds->esil_regstate); } if (core && core->anal && core->anal->esil) { @@ -555,13 +555,13 @@ static void ds_print_esil_anal_fini(RDisasmState *ds) { } } -static RDisasmState * ds_init(RCore *core) { +static RDisasmState * ds_init(RzCore *core) { RDisasmState *ds = R_NEW0 (RDisasmState); if (!ds) { return NULL; } ds->core = core; - ds->strip = r_config_get (core->config, "asm.strip"); + ds->strip = rz_config_get (core->config, "asm.strip"); ds->pal_comment = core->cons->context->pal.comment; #define P(x) (core->cons && core->cons->context->pal.x)? core->cons->context->pal.x ds->color_comment = P(comment): Color_CYAN; @@ -601,147 +601,147 @@ static RDisasmState * ds_init(RCore *core) { ds->color_func_var_type = P(func_var_type): Color_BLUE; ds->color_func_var_addr = P(func_var_addr): Color_CYAN; - ds->immstr = r_config_get_i (core->config, "asm.imm.str"); - ds->immtrim = r_config_get_i (core->config, "asm.imm.trim"); - ds->use_esil = r_config_get_i (core->config, "asm.esil"); - ds->pre_emu = r_config_get_i (core->config, "emu.pre"); - ds->show_flgoff = r_config_get_i (core->config, "asm.flags.offset"); - ds->show_nodup = r_config_get_i (core->config, "asm.nodup"); + ds->immstr = rz_config_get_i (core->config, "asm.imm.str"); + ds->immtrim = rz_config_get_i (core->config, "asm.imm.trim"); + ds->use_esil = rz_config_get_i (core->config, "asm.esil"); + ds->pre_emu = rz_config_get_i (core->config, "emu.pre"); + ds->show_flgoff = rz_config_get_i (core->config, "asm.flags.offset"); + ds->show_nodup = rz_config_get_i (core->config, "asm.nodup"); { - const char *ah = r_config_get (core->config, "asm.highlight"); - ds->asm_highlight = (ah && *ah)? r_num_math (core->num, ah): UT64_MAX; + const char *ah = rz_config_get (core->config, "asm.highlight"); + ds->asm_highlight = (ah && *ah)? rz_num_math (core->num, ah): UT64_MAX; } - ds->asm_anal = r_config_get_i (core->config, "asm.anal"); - ds->show_color = r_config_get_i (core->config, "scr.color"); - ds->show_color_bytes = r_config_get_i (core->config, "scr.color.bytes"); // maybe rename to asm.color.bytes - ds->show_color_args = r_config_get_i (core->config, "scr.color.args"); - ds->colorop = r_config_get_i (core->config, "scr.color.ops"); // XXX confusing name // asm.color.inst (mnemonic + operands) ? - ds->show_utf8 = r_config_get_i (core->config, "scr.utf8"); - ds->acase = r_config_get_i (core->config, "asm.ucase"); - ds->capitalize = r_config_get_i (core->config, "asm.capitalize"); - ds->atabs = r_config_get_i (core->config, "asm.tabs"); - ds->atabsonce = r_config_get_i (core->config, "asm.tabs.once"); - ds->atabsoff = r_config_get_i (core->config, "asm.tabs.off"); - ds->midflags = r_config_get_i (core->config, "asm.flags.middle"); - ds->midbb = r_config_get_i (core->config, "asm.bb.middle"); - ds->midcursor = r_config_get_i (core->config, "asm.midcursor"); - ds->decode = r_config_get_i (core->config, "asm.decode"); - core->parser->pseudo = ds->pseudo = r_config_get_i (core->config, "asm.pseudo"); + ds->asm_anal = rz_config_get_i (core->config, "asm.anal"); + ds->show_color = rz_config_get_i (core->config, "scr.color"); + ds->show_color_bytes = rz_config_get_i (core->config, "scr.color.bytes"); // maybe rename to asm.color.bytes + ds->show_color_args = rz_config_get_i (core->config, "scr.color.args"); + ds->colorop = rz_config_get_i (core->config, "scr.color.ops"); // XXX confusing name // asm.color.inst (mnemonic + operands) ? + ds->show_utf8 = rz_config_get_i (core->config, "scr.utf8"); + ds->acase = rz_config_get_i (core->config, "asm.ucase"); + ds->capitalize = rz_config_get_i (core->config, "asm.capitalize"); + ds->atabs = rz_config_get_i (core->config, "asm.tabs"); + ds->atabsonce = rz_config_get_i (core->config, "asm.tabs.once"); + ds->atabsoff = rz_config_get_i (core->config, "asm.tabs.off"); + ds->midflags = rz_config_get_i (core->config, "asm.flags.middle"); + ds->midbb = rz_config_get_i (core->config, "asm.bb.middle"); + ds->midcursor = rz_config_get_i (core->config, "asm.midcursor"); + ds->decode = rz_config_get_i (core->config, "asm.decode"); + core->parser->pseudo = ds->pseudo = rz_config_get_i (core->config, "asm.pseudo"); if (ds->pseudo) { ds->atabs = 0; } - ds->filter = r_config_get_i (core->config, "asm.filter"); - ds->interactive = r_cons_is_interactive (); - ds->subjmp = r_config_get_i (core->config, "asm.sub.jmp"); - ds->subvar = r_config_get_i (core->config, "asm.sub.var"); - core->parser->subrel = r_config_get_i (core->config, "asm.sub.rel"); - core->parser->subreg = r_config_get_i (core->config, "asm.sub.reg"); - core->parser->localvar_only = r_config_get_i (core->config, "asm.sub.varonly"); + ds->filter = rz_config_get_i (core->config, "asm.filter"); + ds->interactive = rz_cons_is_interactive (); + ds->subjmp = rz_config_get_i (core->config, "asm.sub.jmp"); + ds->subvar = rz_config_get_i (core->config, "asm.sub.var"); + core->parser->subrel = rz_config_get_i (core->config, "asm.sub.rel"); + core->parser->subreg = rz_config_get_i (core->config, "asm.sub.reg"); + core->parser->localvar_only = rz_config_get_i (core->config, "asm.sub.varonly"); core->parser->retleave_asm = NULL; - ds->show_fcnsig = r_config_get_i (core->config, "asm.fcnsig"); - ds->show_vars = r_config_get_i (core->config, "asm.var"); - ds->show_varsum = r_config_get_i (core->config, "asm.var.summary"); - ds->show_varaccess = r_config_get_i (core->config, "asm.var.access"); - ds->maxrefs = r_config_get_i (core->config, "asm.xrefs.max"); - ds->maxflags = r_config_get_i (core->config, "asm.flags.limit"); - ds->flags_inline = r_config_get_i (core->config, "asm.flags.inline"); - ds->asm_types = r_config_get_i (core->config, "asm.types"); - ds->foldxrefs = r_config_get_i (core->config, "asm.xrefs.fold"); - ds->show_lines = r_config_get_i (core->config, "asm.lines"); - ds->show_lines_bb = ds->show_lines ? r_config_get_i (core->config, "asm.lines.bb") : false; - ds->linesright = r_config_get_i (core->config, "asm.lines.right"); - ds->show_indent = r_config_get_i (core->config, "asm.indent"); - ds->indent_space = r_config_get_i (core->config, "asm.indentspace"); - ds->tracespace = r_config_get_i (core->config, "asm.tracespace"); - ds->cyclespace = r_config_get_i (core->config, "asm.cyclespace"); - ds->show_dwarf = r_config_get_i (core->config, "asm.dwarf"); - ds->dwarfFile = r_config_get_i (ds->core->config, "asm.dwarf.file"); - ds->dwarfAbspath = r_config_get_i (ds->core->config, "asm.dwarf.abspath"); - ds->show_lines_call = ds->show_lines ? r_config_get_i (core->config, "asm.lines.call") : false; - ds->show_lines_ret = ds->show_lines ? r_config_get_i (core->config, "asm.lines.ret") : false; - ds->show_size = r_config_get_i (core->config, "asm.size"); - ds->show_trace = r_config_get_i (core->config, "asm.trace"); - ds->linesout = r_config_get_i (core->config, "asm.lines.out"); - ds->adistrick = r_config_get_i (core->config, "asm.middle"); // TODO: find better name - ds->asm_demangle = r_config_get_i (core->config, "asm.demangle"); - ds->asm_describe = r_config_get_i (core->config, "asm.describe"); - ds->show_offset = r_config_get_i (core->config, "asm.offset"); - ds->show_offdec = r_config_get_i (core->config, "asm.decoff"); - ds->show_bbline = r_config_get_i (core->config, "asm.bb.line"); - ds->show_section = r_config_get_i (core->config, "asm.section"); - ds->show_section_col = r_config_get_i (core->config, "asm.section.col"); - ds->show_section_perm = r_config_get_i (core->config, "asm.section.perm"); - ds->show_section_name = r_config_get_i (core->config, "asm.section.name"); - ds->show_symbols = r_config_get_i (core->config, "asm.symbol"); - ds->show_symbols_col = r_config_get_i (core->config, "asm.symbol.col"); - ds->asm_instr = r_config_get_i (core->config, "asm.instr"); - ds->show_emu = r_config_get_i (core->config, "asm.emu"); - ds->show_emu_str = r_config_get_i (core->config, "emu.str"); - ds->show_emu_stroff = r_config_get_i (core->config, "emu.str.off"); - ds->show_emu_strinv = r_config_get_i (core->config, "emu.str.inv"); - ds->show_emu_strflag = r_config_get_i (core->config, "emu.str.flag"); - ds->show_emu_strlea = r_config_get_i (core->config, "emu.str.lea"); - ds->show_emu_write = r_config_get_i (core->config, "emu.write"); - ds->show_emu_ssa = r_config_get_i (core->config, "emu.ssa"); - ds->show_emu_stack = r_config_get_i (core->config, "emu.stack"); + ds->show_fcnsig = rz_config_get_i (core->config, "asm.fcnsig"); + ds->show_vars = rz_config_get_i (core->config, "asm.var"); + ds->show_varsum = rz_config_get_i (core->config, "asm.var.summary"); + ds->show_varaccess = rz_config_get_i (core->config, "asm.var.access"); + ds->maxrefs = rz_config_get_i (core->config, "asm.xrefs.max"); + ds->maxflags = rz_config_get_i (core->config, "asm.flags.limit"); + ds->flags_inline = rz_config_get_i (core->config, "asm.flags.inline"); + ds->asm_types = rz_config_get_i (core->config, "asm.types"); + ds->foldxrefs = rz_config_get_i (core->config, "asm.xrefs.fold"); + ds->show_lines = rz_config_get_i (core->config, "asm.lines"); + ds->show_lines_bb = ds->show_lines ? rz_config_get_i (core->config, "asm.lines.bb") : false; + ds->linesright = rz_config_get_i (core->config, "asm.lines.right"); + ds->show_indent = rz_config_get_i (core->config, "asm.indent"); + ds->indent_space = rz_config_get_i (core->config, "asm.indentspace"); + ds->tracespace = rz_config_get_i (core->config, "asm.tracespace"); + ds->cyclespace = rz_config_get_i (core->config, "asm.cyclespace"); + ds->show_dwarf = rz_config_get_i (core->config, "asm.dwarf"); + ds->dwarfFile = rz_config_get_i (ds->core->config, "asm.dwarf.file"); + ds->dwarfAbspath = rz_config_get_i (ds->core->config, "asm.dwarf.abspath"); + ds->show_lines_call = ds->show_lines ? rz_config_get_i (core->config, "asm.lines.call") : false; + ds->show_lines_ret = ds->show_lines ? rz_config_get_i (core->config, "asm.lines.ret") : false; + ds->show_size = rz_config_get_i (core->config, "asm.size"); + ds->show_trace = rz_config_get_i (core->config, "asm.trace"); + ds->linesout = rz_config_get_i (core->config, "asm.lines.out"); + ds->adistrick = rz_config_get_i (core->config, "asm.middle"); // TODO: find better name + ds->asm_demangle = rz_config_get_i (core->config, "asm.demangle"); + ds->asm_describe = rz_config_get_i (core->config, "asm.describe"); + ds->show_offset = rz_config_get_i (core->config, "asm.offset"); + ds->show_offdec = rz_config_get_i (core->config, "asm.decoff"); + ds->show_bbline = rz_config_get_i (core->config, "asm.bb.line"); + ds->show_section = rz_config_get_i (core->config, "asm.section"); + ds->show_section_col = rz_config_get_i (core->config, "asm.section.col"); + ds->show_section_perm = rz_config_get_i (core->config, "asm.section.perm"); + ds->show_section_name = rz_config_get_i (core->config, "asm.section.name"); + ds->show_symbols = rz_config_get_i (core->config, "asm.symbol"); + ds->show_symbols_col = rz_config_get_i (core->config, "asm.symbol.col"); + ds->asm_instr = rz_config_get_i (core->config, "asm.instr"); + ds->show_emu = rz_config_get_i (core->config, "asm.emu"); + ds->show_emu_str = rz_config_get_i (core->config, "emu.str"); + ds->show_emu_stroff = rz_config_get_i (core->config, "emu.str.off"); + ds->show_emu_strinv = rz_config_get_i (core->config, "emu.str.inv"); + ds->show_emu_strflag = rz_config_get_i (core->config, "emu.str.flag"); + ds->show_emu_strlea = rz_config_get_i (core->config, "emu.str.lea"); + ds->show_emu_write = rz_config_get_i (core->config, "emu.write"); + ds->show_emu_ssa = rz_config_get_i (core->config, "emu.ssa"); + ds->show_emu_stack = rz_config_get_i (core->config, "emu.stack"); ds->stackFd = -1; if (ds->show_emu_stack) { // TODO: initialize fake stack in here const char *uri = "malloc://32K"; - ut64 size = r_num_get (core->num, "32K"); - ut64 addr = r_reg_getv (core->anal->reg, "SP") - (size / 2); + ut64 size = rz_num_get (core->num, "32K"); + ut64 addr = rz_reg_getv (core->anal->reg, "SP") - (size / 2); emustack_min = addr; emustack_max = addr + size; - ds->stackFd = r_io_fd_open (core->io, uri, R_PERM_RW, 0); - RIOMap *map = r_io_map_add (core->io, ds->stackFd, R_PERM_RW, 0LL, addr, size); + ds->stackFd = rz_io_fd_open (core->io, uri, R_PERM_RW, 0); + RzIOMap *map = rz_io_map_add (core->io, ds->stackFd, R_PERM_RW, 0LL, addr, size); if (!map) { - r_io_fd_close (core->io, ds->stackFd); + rz_io_fd_close (core->io, ds->stackFd); eprintf ("Cannot create map for tha stack, fd %d got closed again\n", ds->stackFd); ds->stackFd = -1; } else { - r_io_map_set_name (map, "fake.stack"); + rz_io_map_set_name (map, "fake.stack"); } } ds->stackptr = core->anal->stackptr; - ds->show_offseg = r_config_get_i (core->config, "asm.segoff"); - ds->show_flags = r_config_get_i (core->config, "asm.flags"); - ds->show_bytes = r_config_get_i (core->config, "asm.bytes"); - ds->show_bytes_right = r_config_get_i (core->config, "asm.bytes.right"); - ds->show_optype = r_config_get_i (core->config, "asm.optype"); - ds->asm_meta = r_config_get_i (core->config, "asm.meta"); - ds->asm_xrefs_code = r_config_get_i (core->config, "asm.xrefs.code"); - ds->show_reloff = r_config_get_i (core->config, "asm.reloff"); - ds->show_reloff_flags = r_config_get_i (core->config, "asm.reloff.flags"); - ds->show_lines_fcn = ds->show_lines ? r_config_get_i (core->config, "asm.lines.fcn") : false; - ds->show_comments = r_config_get_i (core->config, "asm.comments"); - ds->show_usercomments = r_config_get_i (core->config, "asm.usercomments"); - ds->asm_hint_jmp = r_config_get_i (core->config, "asm.hint.jmp"); - ds->asm_hint_call = r_config_get_i (core->config, "asm.hint.call"); - ds->asm_hint_lea = r_config_get_i (core->config, "asm.hint.lea"); - ds->asm_hint_emu = r_config_get_i (core->config, "asm.hint.emu"); - ds->asm_hint_cdiv = r_config_get_i (core->config, "asm.hint.cdiv"); - ds->asm_hint_pos = r_config_get_i (core->config, "asm.hint.pos"); - ds->asm_hints = r_config_get_i (core->config, "asm.hints"); // only for cdiv wtf - ds->show_slow = r_config_get_i (core->config, "asm.slow"); - ds->show_refptr = r_config_get_i (core->config, "asm.refptr"); - ds->show_calls = r_config_get_i (core->config, "asm.calls"); - ds->show_family = r_config_get_i (core->config, "asm.family"); - ds->cmtcol = r_config_get_i (core->config, "asm.cmt.col"); - ds->show_cmtesil = r_config_get_i (core->config, "asm.cmt.esil"); - ds->show_cmtflgrefs = r_config_get_i (core->config, "asm.cmt.flgrefs"); - ds->show_cycles = r_config_get_i (core->config, "asm.cycles"); - ds->show_stackptr = r_config_get_i (core->config, "asm.stackptr"); - ds->show_xrefs = r_config_get_i (core->config, "asm.xrefs"); - ds->show_cmtrefs = r_config_get_i (core->config, "asm.cmt.refs"); - ds->cmtfold = r_config_get_i (core->config, "asm.cmt.fold"); - ds->show_cmtoff = r_config_get (core->config, "asm.cmt.off"); + ds->show_offseg = rz_config_get_i (core->config, "asm.segoff"); + ds->show_flags = rz_config_get_i (core->config, "asm.flags"); + ds->show_bytes = rz_config_get_i (core->config, "asm.bytes"); + ds->show_bytes_right = rz_config_get_i (core->config, "asm.bytes.right"); + ds->show_optype = rz_config_get_i (core->config, "asm.optype"); + ds->asm_meta = rz_config_get_i (core->config, "asm.meta"); + ds->asm_xrefs_code = rz_config_get_i (core->config, "asm.xrefs.code"); + ds->show_reloff = rz_config_get_i (core->config, "asm.reloff"); + ds->show_reloff_flags = rz_config_get_i (core->config, "asm.reloff.flags"); + ds->show_lines_fcn = ds->show_lines ? rz_config_get_i (core->config, "asm.lines.fcn") : false; + ds->show_comments = rz_config_get_i (core->config, "asm.comments"); + ds->show_usercomments = rz_config_get_i (core->config, "asm.usercomments"); + ds->asm_hint_jmp = rz_config_get_i (core->config, "asm.hint.jmp"); + ds->asm_hint_call = rz_config_get_i (core->config, "asm.hint.call"); + ds->asm_hint_lea = rz_config_get_i (core->config, "asm.hint.lea"); + ds->asm_hint_emu = rz_config_get_i (core->config, "asm.hint.emu"); + ds->asm_hint_cdiv = rz_config_get_i (core->config, "asm.hint.cdiv"); + ds->asm_hint_pos = rz_config_get_i (core->config, "asm.hint.pos"); + ds->asm_hints = rz_config_get_i (core->config, "asm.hints"); // only for cdiv wtf + ds->show_slow = rz_config_get_i (core->config, "asm.slow"); + ds->show_refptr = rz_config_get_i (core->config, "asm.refptr"); + ds->show_calls = rz_config_get_i (core->config, "asm.calls"); + ds->show_family = rz_config_get_i (core->config, "asm.family"); + ds->cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); + ds->show_cmtesil = rz_config_get_i (core->config, "asm.cmt.esil"); + ds->show_cmtflgrefs = rz_config_get_i (core->config, "asm.cmt.flgrefs"); + ds->show_cycles = rz_config_get_i (core->config, "asm.cycles"); + ds->show_stackptr = rz_config_get_i (core->config, "asm.stackptr"); + ds->show_xrefs = rz_config_get_i (core->config, "asm.xrefs"); + ds->show_cmtrefs = rz_config_get_i (core->config, "asm.cmt.refs"); + ds->cmtfold = rz_config_get_i (core->config, "asm.cmt.fold"); + ds->show_cmtoff = rz_config_get (core->config, "asm.cmt.off"); if (!ds->show_cmtoff) { ds->show_cmtoff = "nodup"; } - ds->show_functions = r_config_get_i (core->config, "asm.functions"); - ds->nbytes = r_config_get_i (core->config, "asm.nbytes"); + ds->show_functions = rz_config_get_i (core->config, "asm.functions"); + ds->nbytes = rz_config_get_i (core->config, "asm.nbytes"); ds->show_asciidot = !strcmp (core->print->strconv_mode, "asciidot"); - const char *strenc_str = r_config_get (core->config, "bin.str.enc"); + const char *strenc_str = rz_config_get (core->config, "bin.str.enc"); if (!strenc_str) { ds->strenc = R_STRING_ENC_GUESS; } else if (!strcmp (strenc_str, "latin1")) { @@ -759,16 +759,16 @@ static RDisasmState * ds_init(RCore *core) { } else { ds->strenc = R_STRING_ENC_GUESS; } - core->print->bytespace = r_config_get_i (core->config, "asm.bytes.space"); + core->print->bytespace = rz_config_get_i (core->config, "asm.bytes.space"); ds->cursor = 0; ds->nb = 0; - ds->flagspace_ports = r_flag_space_get (core->flags, "ports"); - ds->lbytes = r_config_get_i (core->config, "asm.lbytes"); - ds->show_comment_right_default = r_config_get_i (core->config, "asm.cmt.right"); + ds->flagspace_ports = rz_flag_space_get (core->flags, "ports"); + ds->lbytes = rz_config_get_i (core->config, "asm.lbytes"); + ds->show_comment_right_default = rz_config_get_i (core->config, "asm.cmt.right"); ds->show_comment_right = ds->show_comment_right_default; - ds->show_flag_in_bytes = r_config_get_i (core->config, "asm.flags.inbytes"); - ds->show_marks = r_config_get_i (core->config, "asm.marks"); - ds->show_noisy_comments = r_config_get_i (core->config, "asm.noisy"); + ds->show_flag_in_bytes = rz_config_get_i (core->config, "asm.flags.inbytes"); + ds->show_marks = rz_config_get_i (core->config, "asm.marks"); + ds->show_noisy_comments = rz_config_get_i (core->config, "asm.noisy"); ds->pre = DS_PRE_NONE; ds->ocomment = NULL; ds->linesopts = 0; @@ -782,14 +782,14 @@ static RDisasmState * ds_init(RCore *core) { ds->esil_regstate = NULL; ds->esil_likely = false; - ds->showpayloads = r_config_get_i (ds->core->config, "asm.payloads"); - ds->showrelocs = r_config_get_i (core->config, "bin.relocs"); - ds->min_ref_addr = r_config_get_i (core->config, "asm.sub.varmin"); + ds->showpayloads = rz_config_get_i (ds->core->config, "asm.payloads"); + ds->showrelocs = rz_config_get_i (core->config, "bin.relocs"); + ds->min_ref_addr = rz_config_get_i (core->config, "asm.sub.varmin"); if (ds->show_flag_in_bytes) { ds->show_flags = false; } - if (r_config_get_i (core->config, "asm.lines.wide")) { + if (rz_config_get_i (core->config, "asm.lines.wide")) { ds->linesopts |= R_ANAL_REFLINE_TYPE_WIDE; } if (core->cons->vline) { @@ -824,7 +824,7 @@ static RDisasmState * ds_init(RCore *core) { } else { ds->cursor = -1; } - if (r_config_get_i (core->config, "asm.lines.wide")) { + if (rz_config_get_i (core->config, "asm.lines.wide")) { ds->linesopts |= R_ANAL_REFLINE_TYPE_WIDE; } if (core->cons->vline) { @@ -838,8 +838,8 @@ static RDisasmState * ds_init(RCore *core) { static ut64 lastaddr = UT64_MAX; static void ds_reflines_fini(RDisasmState *ds) { - RAnal *anal = ds->core->anal; - r_list_free (anal->reflines); + RzAnal *anal = ds->core->anal; + rz_list_free (anal->reflines); anal->reflines = NULL; R_FREE (ds->refline); R_FREE (ds->refline2); @@ -847,17 +847,17 @@ static void ds_reflines_fini(RDisasmState *ds) { } static void ds_reflines_init(RDisasmState *ds) { - RAnal *anal = ds->core->anal; + RzAnal *anal = ds->core->anal; lastaddr = UT64_MAX; if (ds->show_lines_bb || ds->pj) { ds_reflines_fini (ds); - anal->reflines = r_anal_reflines_get (anal, + anal->reflines = rz_anal_reflines_get (anal, ds->addr, ds->buf, ds->len, ds->l, ds->linesout, ds->show_lines_call); } else { - r_list_free (anal->reflines); + rz_list_free (anal->reflines); anal->reflines = NULL; } } @@ -870,12 +870,12 @@ static void ds_free(RDisasmState *ds) { // TODO: destroy fake stack in here eprintf ("Free fake stack\n"); if (ds->stackFd != -1) { - r_io_fd_close (ds->core->io, ds->stackFd); + rz_io_fd_close (ds->core->io, ds->stackFd); } } - r_asm_op_fini (&ds->asmop); - r_anal_op_fini (&ds->analop); - r_anal_hint_free (ds->hint); + rz_asm_op_fini (&ds->asmop); + rz_anal_op_fini (&ds->analop); + rz_anal_hint_free (ds->hint); ds_print_esil_anal_fini (ds); ds_reflines_fini (ds); ds_print_esil_anal_fini (ds); @@ -893,29 +893,29 @@ static void ds_free(RDisasmState *ds) { R_FREE (ds); } -/* XXX move to r_print */ -static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color) { - char *source = ds->opstr? ds->opstr: r_asm_op_get_asm (&ds->asmop); - const char *hlstr = r_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at); +/* XXX move to rz_print */ +static char *colorize_asm_string(RzCore *core, RDisasmState *ds, bool print_color) { + char *source = ds->opstr? ds->opstr: rz_asm_op_get_asm (&ds->asmop); + const char *hlstr = rz_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at); bool partial_reset = line_highlighted (ds) ? true : ((hlstr && *hlstr) ? true : false); - RAnalFunction *f = ds->show_color_args ? fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL) : NULL; + RzAnalFunction *f = ds->show_color_args ? fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL) : NULL; if (!ds->show_color || !ds->colorop) { return strdup (source); } if (print_color) { - r_cons_strcat (r_print_color_op_type (core->print, ds->analop.type)); + rz_cons_strcat (rz_print_color_op_type (core->print, ds->analop.type)); } // workaround dummy colorizer in case of paired commands (tms320 & friends) char *spacer = strstr (source, "||"); if (spacer) { - char *scol1, *s1 = r_str_ndup (source, spacer - source); + char *scol1, *s1 = rz_str_ndup (source, spacer - source); char *scol2, *s2 = strdup (spacer + 2); - scol1 = r_print_colorize_opcode (ds->core->print, s1, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); + scol1 = rz_print_colorize_opcode (ds->core->print, s1, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); free (s1); - scol2 = r_print_colorize_opcode (ds->core->print, s2, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); + scol2 = rz_print_colorize_opcode (ds->core->print, s2, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); free (s2); if (!scol1) { scol1 = strdup (""); @@ -923,17 +923,17 @@ static char *colorize_asm_string(RCore *core, RDisasmState *ds, bool print_color if (!scol2) { scol2 = strdup (""); } - source = r_str_newf ("%s||%s", scol1, scol2); + source = rz_str_newf ("%s||%s", scol1, scol2); free (scol1); free (scol2); return source; } - return r_print_colorize_opcode (ds->core->print, source, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); + return rz_print_colorize_opcode (ds->core->print, source, ds->color_reg, ds->color_num, partial_reset, f ? f->addr : 0); } static bool ds_must_strip(RDisasmState *ds) { if (ds && ds->strip && *ds->strip) { - const char * optype = r_anal_optype_to_string (ds->analop.type); + const char * optype = rz_anal_optype_to_string (ds->analop.type); if (optype && *optype) { return strstr (ds->strip, optype); } @@ -942,50 +942,50 @@ static bool ds_must_strip(RDisasmState *ds) { } static void ds_highlight_word(RDisasmState * ds, char *word, char *color) { - char *source = ds->opstr? ds->opstr: r_asm_op_get_asm (&ds->asmop); + char *source = ds->opstr? ds->opstr: rz_asm_op_get_asm (&ds->asmop); const char *color_reset = line_highlighted (ds) ? ds->color_linehl : Color_RESET_BG; - char *asm_str = r_str_highlight (source, word, color, color_reset); + char *asm_str = rz_str_highlight (source, word, color, color_reset); ds->opstr = asm_str? asm_str: source; } static void __replaceImports(RDisasmState *ds) { if (ds->core->anal->imports) { char *imp; - RListIter *iter; - r_list_foreach (ds->core->anal->imports, iter, imp) { - ds->opstr = r_str_replace (ds->opstr, imp, ".", 1); + RzListIter *iter; + rz_list_foreach (ds->core->anal->imports, iter, imp) { + ds->opstr = rz_str_replace (ds->opstr, imp, ".", 1); } } if (ds->fcn && ds->fcn->imports) { char *imp; - RListIter *iter; - r_list_foreach (ds->fcn->imports, iter, imp) { - ds->opstr = r_str_replace (ds->opstr, imp, ".", 1); + RzListIter *iter; + rz_list_foreach (ds->fcn->imports, iter, imp) { + ds->opstr = rz_str_replace (ds->opstr, imp, ".", 1); } } } static char *get_op_ireg (void *user, ut64 addr) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *res = NULL; - RAnalOp *op = r_core_anal_op (core, addr, 0); + RzAnalOp *op = rz_core_anal_op (core, addr, 0); if (op && op->ireg) { res = strdup (op->ireg); } - r_anal_op_free (op); + rz_anal_op_free (op); return res; } -static st64 get_ptr_at(RAnalFunction *fcn, st64 delta, ut64 addr) { - return r_anal_function_get_var_stackptr_at (fcn, delta, addr); +static st64 get_ptr_at(RzAnalFunction *fcn, st64 delta, ut64 addr) { + return rz_anal_function_get_var_stackptr_at (fcn, delta, addr); } -static const char *get_reg_at(RAnalFunction *fcn, st64 delta, ut64 addr) { - return r_anal_function_get_var_reg_at (fcn, delta, addr); +static const char *get_reg_at(RzAnalFunction *fcn, st64 delta, ut64 addr) { + return rz_anal_function_get_var_reg_at (fcn, delta, addr); } static void ds_build_op_str(RDisasmState *ds, bool print_color) { - RCore *core = ds->core; + RzCore *core = ds->core; if (ds->use_esil) { free (ds->opstr); if (*R_STRBUF_SAFEGET (&ds->analop.esil)) { @@ -997,15 +997,15 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { } if (ds->decode) { free (ds->opstr); - ds->opstr = r_anal_op_to_string (core->anal, &ds->analop); + ds->opstr = rz_anal_op_to_string (core->anal, &ds->analop); return; } if (!ds->opstr) { - ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop)); + ds->opstr = strdup (rz_asm_op_get_asm (&ds->asmop)); } /* initialize */ - core->parser->subrel = r_config_get_i (core->config, "asm.sub.rel"); - core->parser->subreg = r_config_get_i (core->config, "asm.sub.reg"); + core->parser->subrel = rz_config_get_i (core->config, "asm.sub.rel"); + core->parser->subreg = rz_config_get_i (core->config, "asm.sub.reg"); core->parser->subrel_addr = 0; if (core->parser->subrel && (ds->analop.type == R_ANAL_OP_TYPE_LEA || ds->analop.type == R_ANAL_OP_TYPE_MOV @@ -1015,21 +1015,21 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { } if (ds->subvar && ds->opstr) { ut64 at = ds->vat; - RAnalFunction *f = fcnIn (ds, at, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *f = fcnIn (ds, at, R_ANAL_FCN_TYPE_NULL); core->parser->get_op_ireg = get_op_ireg; core->parser->get_ptr_at = get_ptr_at; core->parser->get_reg_at = get_reg_at; - r_parse_subvar (core->parser, f, at, ds->analop.size, + rz_parse_subvar (core->parser, f, at, ds->analop.size, ds->opstr, ds->strsub, sizeof (ds->strsub)); if (*ds->strsub) { free (ds->opstr); ds->opstr = strdup (ds->strsub); } if (core->parser->subrel) { - RList *list = r_anal_refs_get (core->anal, at); - RListIter *iter; - RAnalRef *ref; - r_list_foreach (list, iter, ref) { + RzList *list = rz_anal_refs_get (core->anal, at); + RzListIter *iter; + RzAnalRef *ref; + rz_list_foreach (list, iter, ref) { if ((ref->type == R_ANAL_REF_TYPE_DATA || ref->type == R_ANAL_REF_TYPE_STRING) && ds->analop.type == R_ANAL_OP_TYPE_LEA) { @@ -1037,19 +1037,19 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { break; } } - r_list_free (list); + rz_list_free (list); } } if (ds->pseudo) { - const char *opstr = ds->opstr ? ds->opstr : r_asm_op_get_asm (&ds->asmop); - r_parse_parse (core->parser, opstr, ds->str); + const char *opstr = ds->opstr ? ds->opstr : rz_asm_op_get_asm (&ds->asmop); + rz_parse_parse (core->parser, opstr, ds->str); free (ds->opstr); ds->opstr = strdup (ds->str); } ds->opstr = ds_sub_jumps (ds, ds->opstr); if (ds->immtrim) { - char *res = r_parse_immtrim (ds->opstr); + char *res = rz_parse_immtrim (ds->opstr); if (res) { free (ds->opstr); ds->opstr = res; @@ -1079,12 +1079,12 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { if (core->parser->subrel_addr == 0) { ut64 killme = UT64_MAX; const int be = core->rasm->big_endian; - r_io_read_i (core->io, ds->analop.ptr, &killme, ds->analop.refptr, be); + rz_io_read_i (core->io, ds->analop.ptr, &killme, ds->analop.refptr, be); core->parser->subrel_addr = killme; } } char *asm_str = colorize_asm_string (core, ds, print_color); - r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, asm_str, + rz_parse_filter (core->parser, ds->vat, core->flags, ds->hint, asm_str, ds->str, sizeof (ds->str), core->print->big_endian); free (asm_str); // subvar depends on filter @@ -1095,12 +1095,12 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { char *e = strchr (ox, ']'); if (e) { e = strdup (e); - ut64 addr = r_num_get (NULL, ox); + ut64 addr = rz_num_get (NULL, ox); if (addr > ds->min_ref_addr) { - RFlagItem *fi = r_flag_get_i (ds->core->flags, addr); + RzFlagItem *fi = rz_flag_get_i (ds->core->flags, addr); if (fi) { - r_str_cpy (ox, fi->name); - r_str_cat (ox, e); + rz_str_cpy (ox, fi->name); + rz_str_cat (ox, e); } } free (e); @@ -1111,54 +1111,54 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { free (ds->opstr); ds->opstr = strdup (ds->str); } else { - r_str_trim (ds->opstr); // trim before coloring git + rz_str_trim (ds->opstr); // trim before coloring git char *asm_str = colorize_asm_string (core, ds, print_color); free (ds->opstr); ds->opstr = asm_str; } - r_str_trim (ds->opstr); + rz_str_trim (ds->opstr); // updates ds->opstr __replaceImports (ds); if (ds->show_color) { int i = 0; char *word = NULL; char *bgcolor = NULL; - const char *wcdata = r_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at); + const char *wcdata = rz_meta_get_string (ds->core->anal, R_META_TYPE_HIGHLIGHT, ds->at); int argc = 0; - char **wc_array = r_str_argv (wcdata, &argc); + char **wc_array = rz_str_argv (wcdata, &argc); for (i = 0; i < argc; i++) { bgcolor = strchr (wc_array[i], '\x1b'); - word = r_str_newlen (wc_array[i], bgcolor - wc_array[i]); + word = rz_str_newlen (wc_array[i], bgcolor - wc_array[i]); ds_highlight_word (ds, word, bgcolor); } } } -R_API RAnalHint *r_core_hint_begin(RCore *core, RAnalHint* hint, ut64 at) { +RZ_API RzAnalHint *rz_core_hint_begin(RzCore *core, RzAnalHint* hint, ut64 at) { static char *hint_syntax = NULL; - r_anal_hint_free (hint); - hint = r_anal_hint_get (core->anal, at); + rz_anal_hint_free (hint); + hint = rz_anal_hint_get (core->anal, at); if (hint_syntax) { - r_config_set (core->config, "asm.syntax", hint_syntax); + rz_config_set (core->config, "asm.syntax", hint_syntax); hint_syntax = NULL; } if (hint) { /* syntax */ if (hint->syntax) { if (!hint_syntax) { - hint_syntax = strdup (r_config_get (core->config, "asm.syntax")); + hint_syntax = strdup (rz_config_get (core->config, "asm.syntax")); } - r_config_set (core->config, "asm.syntax", hint->syntax); + rz_config_set (core->config, "asm.syntax", hint->syntax); } if (hint->high) { /* TODO: do something here */ } } - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, at, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, at, 0); if (fcn) { if (fcn->bits == 16 || fcn->bits == 32) { if (!hint) { - hint = R_NEW0 (RAnalHint); + hint = R_NEW0 (RzAnalHint); } hint->bits = fcn->bits; hint->new_bits = fcn->bits; @@ -1184,10 +1184,10 @@ static void ds_begin_line(RDisasmState *ds) { pj_o (ds->pj); pj_kn (ds->pj, "offset", ds->vat); if (ds->core->anal->reflines) { - RAnalRefline *ref; - RListIter *iter; + RzAnalRefline *ref; + RzListIter *iter; // XXX Probably expensive - r_list_foreach (ds->core->anal->reflines, iter, ref) { + rz_list_foreach (ds->core->anal->reflines, iter, ref) { if (ref->from == ds->vat) { pj_kn (ds->pj, "arrow", ref->to); break; @@ -1196,28 +1196,28 @@ static void ds_begin_line(RDisasmState *ds) { } pj_k (ds->pj, "text"); } - ds->buf_line_begin = r_cons_get_buffer_len (); + ds->buf_line_begin = rz_cons_get_buffer_len (); if (!ds->pj && ds->asm_hint_pos == -1) { if (!ds_print_core_vmode (ds, ds->asm_hint_pos)) { - r_cons_printf (" "); + rz_cons_printf (" "); } } } static void ds_newline(RDisasmState *ds) { if (ds->pj) { - const bool is_html = r_config_get_i (ds->core->config, "scr.html"); + const bool is_html = rz_config_get_i (ds->core->config, "scr.html"); if (is_html) { - char *s = r_cons_html_filter (r_cons_get_buffer (), NULL); + char *s = rz_cons_html_filter (rz_cons_get_buffer (), NULL); pj_s (ds->pj, s); free (s); } else { - pj_s (ds->pj, r_cons_get_buffer ()); + pj_s (ds->pj, rz_cons_get_buffer ()); } - r_cons_reset (); + rz_cons_reset (); pj_end (ds->pj); } else { - r_cons_newline (); + rz_cons_newline (); } } @@ -1225,10 +1225,10 @@ static void ds_begin_cont(RDisasmState *ds) { ds_begin_line (ds); ds_setup_print_pre (ds, false, false); if (!ds->linesright && ds->show_lines_bb && ds->line) { - RAnalRefStr *refstr = r_anal_reflines_str (ds->core, ds->at, + RzAnalRefStr *refstr = rz_anal_reflines_str (ds->core, ds->at, ds->linesopts | R_ANAL_REFLINE_TYPE_MIDDLE_AFTER); ds_print_ref_lines (refstr->str, refstr->cols, ds); - r_anal_reflines_str_free (refstr); + rz_anal_reflines_str_free (refstr); } } @@ -1242,39 +1242,39 @@ static void ds_begin_comment(RDisasmState *ds) { } static void ds_show_refs(RDisasmState *ds) { - RAnalRef *ref; - RListIter *iter; + RzAnalRef *ref; + RzListIter *iter; if (!ds->show_cmtrefs) { return; } - RList *list = r_anal_xrefs_get_from (ds->core->anal, ds->at); + RzList *list = rz_anal_xrefs_get_from (ds->core->anal, ds->at); - r_list_foreach (list, iter, ref) { - const char *cmt = r_meta_get_string (ds->core->anal, R_META_TYPE_COMMENT, ref->addr); - const RList *fls = r_flag_get_list (ds->core->flags, ref->addr); - RListIter *iter2; - RFlagItem *fis; - r_list_foreach (fls, iter2, fis) { + rz_list_foreach (list, iter, ref) { + const char *cmt = rz_meta_get_string (ds->core->anal, R_META_TYPE_COMMENT, ref->addr); + const RzList *fls = rz_flag_get_list (ds->core->flags, ref->addr); + RzListIter *iter2; + RzFlagItem *fis; + rz_list_foreach (fls, iter2, fis) { ds_begin_comment (ds); ds_comment (ds, true, "; (%s)", fis->name); } // ds_align_comment (ds); if (ds->show_color) { - r_cons_strcat (ds->color_comment); + rz_cons_strcat (ds->color_comment); } if (cmt) { ds_begin_comment (ds); ds_comment (ds, true, "; (%s)", cmt); } if (ref->type & R_ANAL_REF_TYPE_CALL) { - RAnalOp aop; + RzAnalOp aop; ut8 buf[12]; - r_io_read_at (ds->core->io, ref->at, buf, sizeof (buf)); - r_anal_op (ds->core->anal, &aop, ref->at, buf, sizeof (buf), R_ANAL_OP_MASK_ALL); + rz_io_read_at (ds->core->io, ref->at, buf, sizeof (buf)); + rz_anal_op (ds->core->anal, &aop, ref->at, buf, sizeof (buf), R_ANAL_OP_MASK_ALL); if ((aop.type & R_ANAL_OP_TYPE_MASK) == R_ANAL_OP_TYPE_UCALL) { - RAnalFunction * fcn = r_anal_get_function_at (ds->core->anal, ref->addr); + RzAnalFunction * fcn = rz_anal_get_function_at (ds->core->anal, ref->addr); ds_begin_comment (ds); if (fcn) { ds_comment (ds, true, "; %s", fcn->name); @@ -1285,49 +1285,49 @@ static void ds_show_refs(RDisasmState *ds) { } ds_print_color_reset (ds); } - r_list_free (list); + rz_list_free (list); } static void ds_show_xrefs(RDisasmState *ds) { - RAnalRef *refi; - RListIter *iter, *it; - RCore *core = ds->core; + RzAnalRef *refi; + RzListIter *iter, *it; + RzCore *core = ds->core; char *name, *realname; int count = 0; if (!ds->show_xrefs || !ds->show_comments) { return; } /* show xrefs */ - RList *xrefs = r_anal_xrefs_get (core->anal, ds->at); + RzList *xrefs = rz_anal_xrefs_get (core->anal, ds->at); if (!xrefs) { return; } // only show fcnline in xrefs when addr is not the beginning of a function bool fcnlines = (ds->fcn && ds->fcn->addr == ds->at); - if (r_list_length (xrefs) > ds->maxrefs) { + if (rz_list_length (xrefs) > ds->maxrefs) { ds_begin_line (ds); ds_pre_xrefs (ds, fcnlines); ds_comment (ds, false, "%s; XREFS(%d)", ds->show_color? ds->pal_comment: "", - r_list_length (xrefs)); + rz_list_length (xrefs)); if (ds->show_color) { ds_print_color_reset (ds); } ds_newline (ds); - r_list_free (xrefs); + rz_list_free (xrefs); return; } - if (r_list_length (xrefs) > ds->foldxrefs) { - int cols = r_cons_get_size (NULL); + if (rz_list_length (xrefs) > ds->foldxrefs) { + int cols = rz_cons_get_size (NULL); cols -= 15; cols /= 23; cols = cols > 5 ? 5 : cols; ds_begin_line (ds); ds_pre_xrefs (ds, fcnlines); ds_comment (ds, false, "%s; XREFS: ", ds->show_color? ds->pal_comment: ""); - r_list_foreach (xrefs, iter, refi) { + rz_list_foreach (xrefs, iter, refi) { ds_comment (ds, false, "%s 0x%08"PFMT64x" ", - r_anal_xrefs_type_tostring (refi->type), refi->addr); + rz_anal_xrefs_type_tostring (refi->type), refi->addr); if (count == cols) { if (iter->n) { ds_print_color_reset (ds); @@ -1343,14 +1343,14 @@ static void ds_show_xrefs(RDisasmState *ds) { } ds_print_color_reset (ds); ds_newline (ds); - r_list_free (xrefs); + rz_list_free (xrefs); return; } - RList *addrs = r_list_newf (free); - RAnalFunction *fun, *next_fun; - RFlagItem *f, *next_f; - r_list_foreach (xrefs, iter, refi) { + RzList *addrs = rz_list_newf (free); + RzAnalFunction *fun, *next_fun; + RzFlagItem *f, *next_f; + rz_list_foreach (xrefs, iter, refi) { if (!ds->asm_xrefs_code && refi->type == R_ANAL_REF_TYPE_CODE) { continue; } @@ -1359,36 +1359,36 @@ static void ds_show_xrefs(RDisasmState *ds) { fun = fcnIn (ds, refi->addr, -1); if (fun) { if (iter != xrefs->tail) { - ut64 next_addr = ((RAnalRef *)(iter->n->data))->addr; - next_fun = r_anal_get_fcn_in (core->anal, next_addr, -1); + ut64 next_addr = ((RzAnalRef *)(iter->n->data))->addr; + next_fun = rz_anal_get_fcn_in (core->anal, next_addr, -1); if (next_fun && next_fun->addr == fun->addr) { - r_list_append (addrs, r_num_dup (refi->addr)); + rz_list_append (addrs, rz_num_dup (refi->addr)); continue; } } if (ds->asm_demangle) { - f = r_flag_get_by_spaces (core->flags, fun->addr, R_FLAGS_FS_SYMBOLS, NULL); + f = rz_flag_get_by_spaces (core->flags, fun->addr, R_FLAGS_FS_SYMBOLS, NULL); if (f && f->demangled && f->realname) { realname = strdup (f->realname); } } name = strdup (fun->name); - r_list_append (addrs, r_num_dup (refi->addr)); + rz_list_append (addrs, rz_num_dup (refi->addr)); } else { - f = r_flag_get_at (core->flags, refi->addr, true); + f = rz_flag_get_at (core->flags, refi->addr, true); if (f) { if (iter != xrefs->tail) { - ut64 next_addr = ((RAnalRef *)(iter->n->data))->addr; - next_f = r_flag_get_at (core->flags, next_addr, true); + ut64 next_addr = ((RzAnalRef *)(iter->n->data))->addr; + next_f = rz_flag_get_at (core->flags, next_addr, true); if (next_f && f->offset == next_f->offset) { - r_list_append (addrs, r_num_dup (refi->addr - f->offset)); + rz_list_append (addrs, rz_num_dup (refi->addr - f->offset)); continue; } } if (ds->asm_demangle) { - RFlagItem *f_sym = f; - if (!r_str_startswith (f_sym->name, "sym.")) { - f_sym = r_flag_get_by_spaces (core->flags, f->offset, + RzFlagItem *f_sym = f; + if (!rz_str_startswith (f_sym->name, "sym.")) { + f_sym = rz_flag_get_by_spaces (core->flags, f->offset, R_FLAGS_FS_SYMBOLS, NULL); } if (f_sym && f_sym->demangled && f_sym->realname) { @@ -1397,25 +1397,25 @@ static void ds_show_xrefs(RDisasmState *ds) { } } name = strdup (f->name); - r_list_append (addrs, r_num_dup (refi->addr - f->offset)); + rz_list_append (addrs, rz_num_dup (refi->addr - f->offset)); } else { name = strdup ("unk"); } } ds_begin_line (ds); ds_pre_xrefs (ds, fcnlines); - const char* plural = r_list_length (addrs) > 1 ? "S" : ""; + const char* plural = rz_list_length (addrs) > 1 ? "S" : ""; const char* plus = fun ? "" : "+"; ds_comment (ds, false, "%s; %s XREF%s from %s @ ", - COLOR (ds, pal_comment), r_anal_xrefs_type_tostring (refi->type), plural, + COLOR (ds, pal_comment), rz_anal_xrefs_type_tostring (refi->type), plural, realname ? realname : name); ut64 *addrptr; - r_list_foreach (addrs, it, addrptr) { + rz_list_foreach (addrs, it, addrptr) { if (addrptr && *addrptr) { ds_comment (ds, false, "%s%s0x%"PFMT64x, it == addrs->head ? "" : ", ", plus, *addrptr); } } - if (realname && (!fun || r_anal_get_function_at (core->anal, ds->at))) { + if (realname && (!fun || rz_anal_get_function_at (core->anal, ds->at))) { const char *pad = ds->show_comment_right ? "" : " "; if (!ds->show_comment_right) { ds_newline (ds); @@ -1426,15 +1426,15 @@ static void ds_show_xrefs(RDisasmState *ds) { } ds_comment (ds, false, "%s", COLOR_RESET (ds)); ds_newline (ds); - r_list_purge (addrs); + rz_list_purge (addrs); R_FREE (name); free (realname); } else { eprintf ("Corrupted database?\n"); } } - r_list_free (addrs); - r_list_free (xrefs); + rz_list_free (addrs); + rz_list_free (xrefs); } static void ds_atabs_option(RDisasmState *ds) { @@ -1444,7 +1444,7 @@ static void ds_atabs_option(RDisasmState *ds) { if (!ds || !ds->atabs) { return; } - int bufasm_len = r_strbuf_length (&ds->asmop.buf_asm); + int bufasm_len = rz_strbuf_length (&ds->asmop.buf_asm); int size = bufasm_len * (ds->atabs + 1) * 4; if (size < 1 || size < bufasm_len) { return; @@ -1453,7 +1453,7 @@ static void ds_atabs_option(RDisasmState *ds) { if (ds->opstr) { strcpy (b, ds->opstr); } else { - strcpy (b, r_asm_op_get_asm (&ds->asmop)); + strcpy (b, rz_asm_op_get_asm (&ds->asmop)); } if (!b) { return; @@ -1498,7 +1498,7 @@ static void ds_atabs_option(RDisasmState *ds) { } } -static int handleMidFlags(RCore *core, RDisasmState *ds, bool print) { +static int handleMidFlags(RzCore *core, RDisasmState *ds, bool print) { int i; ds->hasMidflag = false; @@ -1511,7 +1511,7 @@ static int handleMidFlags(RCore *core, RDisasmState *ds, bool print) { } } for (i = 1; i < ds->oplen; i++) { - RFlagItem *fi = r_flag_get_i (core->flags, ds->at + i); + RzFlagItem *fi = rz_flag_get_i (core->flags, ds->at + i); if (fi && fi->name) { if (ds->midflags == 2 && ((fi->name[0] == '$') || (fi->realname && fi->realname[0] == '$'))) { i = 0; @@ -1533,17 +1533,17 @@ static int handleMidFlags(RCore *core, RDisasmState *ds, bool print) { return 0; } -static int handleMidBB(RCore *core, RDisasmState *ds) { +static int handleMidBB(RzCore *core, RDisasmState *ds) { int i; ds->hasMidbb = false; - r_return_val_if_fail (core->anal, 0); + rz_return_val_if_fail (core->anal, 0); // Unfortunately, can't just check the addr of the last insn byte since // a bb (and fcn) can be as small as 1 byte, and advancing i based on // bb->size is unsound if basic blocks can nest or overlap for (i = 1; i < ds->oplen; i++) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, ds->at + i, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, ds->at + i, 0); if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, ds->at + i); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, fcn, ds->at + i); if (bb && bb->addr > ds->at) { ds->hasMidbb = true; return bb->addr - ds->at; @@ -1553,8 +1553,8 @@ static int handleMidBB(RCore *core, RDisasmState *ds) { return 0; } -R_API int r_core_flag_in_middle(RCore *core, ut64 at, int oplen, int *midflags) { - r_return_val_if_fail (midflags, 0); +RZ_API int rz_core_flag_in_middle(RzCore *core, ut64 at, int oplen, int *midflags) { + rz_return_val_if_fail (midflags, 0); RDisasmState ds = { .at = at, .oplen = oplen, @@ -1565,7 +1565,7 @@ R_API int r_core_flag_in_middle(RCore *core, ut64 at, int oplen, int *midflags) return ret; } -R_API int r_core_bb_starts_in_middle(RCore *core, ut64 at, int oplen) { +RZ_API int rz_core_bb_starts_in_middle(RzCore *core, ut64 at, int oplen) { RDisasmState ds = { .at = at, .oplen = oplen @@ -1574,7 +1574,7 @@ R_API int r_core_bb_starts_in_middle(RCore *core, ut64 at, int oplen) { } static void ds_print_show_cursor(RDisasmState *ds) { - RCore *core = ds->core; + RzCore *core = ds->core; char res[] = " "; if (!ds->show_marks) { return; @@ -1582,7 +1582,7 @@ static void ds_print_show_cursor(RDisasmState *ds) { int q = core->print->cur_enabled && ds->cursor >= ds->index && ds->cursor < (ds->index + ds->asmop.size); - RBreakpointItem *p = r_bp_get_at (core->dbg->bp, ds->at); + RBreakpointItem *p = rz_bp_get_at (core->dbg->bp, ds->at); if (ds->midflags) { (void)handleMidFlags (core, ds, false); } @@ -1606,7 +1606,7 @@ static void ds_print_show_cursor(RDisasmState *ds) { res[i] = '0' + (diff % 10); } } - r_cons_strcat (res); + rz_cons_strcat (res); } static void ds_pre_xrefs(RDisasmState *ds, bool no_fcnlines) { @@ -1628,38 +1628,38 @@ static void ds_pre_xrefs(RDisasmState *ds, bool no_fcnlines) { } //TODO: this function is a temporary fix. All analysis should be based on realsize. However, now for same architectures realisze is not used -static ut32 tmp_get_realsize (RAnalFunction *f) { - ut32 size = r_anal_function_realsize (f); - return (size > 0) ? size : r_anal_function_linear_size (f); +static ut32 tmp_get_realsize (RzAnalFunction *f) { + ut32 size = rz_anal_function_realsize (f); + return (size > 0) ? size : rz_anal_function_linear_size (f); } -static void ds_show_functions_argvar(RDisasmState *ds, RAnalFunction *fcn, RAnalVar *var, const char *base, bool is_var, char sign) { +static void ds_show_functions_argvar(RDisasmState *ds, RzAnalFunction *fcn, RzAnalVar *var, const char *base, bool is_var, char sign) { int delta = var->kind == 'b' ? R_ABS (var->delta + fcn->bp_off) : R_ABS (var->delta); const char *pfx = is_var ? "var" : "arg"; - char *constr = r_anal_var_get_constraints_readable (var); - r_cons_printf ("%s%s %s%s%s%s %s%s%s%s@ %s%c0x%x", COLOR_ARG (ds, color_func_var), pfx, + char *constr = rz_anal_var_get_constraints_readable (var); + rz_cons_printf ("%s%s %s%s%s%s %s%s%s%s@ %s%c0x%x", COLOR_ARG (ds, color_func_var), pfx, COLOR_ARG (ds, color_func_var_type), var->type, - r_str_endswith (var->type, "*") ? "" : " ", + rz_str_endswith (var->type, "*") ? "" : " ", var->name, COLOR_ARG (ds, color_func_var_addr), constr? " { ":"", constr? constr: "", constr? "} ":"", base, sign, delta); if (ds->show_varsum == -1) { - char *val = r_core_cmd_strf (ds->core, ".afvd %s", var->name); + char *val = rz_core_cmd_strf (ds->core, ".afvd %s", var->name); if (val) { - r_str_replace_char (val, '\n', '\0'); - r_cons_printf (" = %s", val); + rz_str_replace_char (val, '\n', '\0'); + rz_cons_printf (" = %s", val); free (val); } } free (constr); } -static void printVarSummary(RDisasmState *ds, RList *list) { +static void printVarSummary(RDisasmState *ds, RzList *list) { const char *numColor = ds->core->cons->context->pal.num; - RAnalVar *var; - RListIter *iter; + RzAnalVar *var; + RzListIter *iter; int bp_vars = 0; int sp_vars = 0; int rg_vars = 0; @@ -1672,7 +1672,7 @@ static void printVarSummary(RDisasmState *ds, RList *list) { const char *bp_args_color = COLOR_RESET (ds); const char *sp_args_color = COLOR_RESET (ds); const char *rg_args_color = COLOR_RESET (ds); - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { if (var->isarg) { switch (var->kind) { case 'b': @@ -1708,14 +1708,14 @@ static void printVarSummary(RDisasmState *ds, RList *list) { if (ds->show_varsum == 2) { ds_begin_line (ds); ds_print_pre (ds, true); - r_cons_printf ("vars: %s%d%s %s%d%s %s%d%s", + rz_cons_printf ("vars: %s%d%s %s%d%s %s%d%s", bp_vars_color, bp_vars, COLOR_RESET (ds), sp_vars_color, sp_vars, COLOR_RESET (ds), rg_vars_color, rg_vars, COLOR_RESET (ds)); ds_newline (ds); ds_begin_line (ds); ds_print_pre (ds, true); - r_cons_printf ("args: %s%d%s %s%d%s %s%d%s", + rz_cons_printf ("args: %s%d%s %s%d%s %s%d%s", bp_args_color, bp_args, COLOR_RESET (ds), sp_args_color, sp_args, COLOR_RESET (ds), rg_args_color, rg_args, COLOR_RESET (ds)); @@ -1724,21 +1724,21 @@ static void printVarSummary(RDisasmState *ds, RList *list) { } ds_begin_line (ds); ds_print_pre (ds, true); - r_cons_printf ("bp: %s%d%s (vars %s%d%s, args %s%d%s)", + rz_cons_printf ("bp: %s%d%s (vars %s%d%s, args %s%d%s)", bp_args || bp_vars ? numColor : COLOR_RESET (ds), bp_args + bp_vars, COLOR_RESET (ds), bp_vars_color, bp_vars, COLOR_RESET (ds), bp_args_color, bp_args, COLOR_RESET (ds)); ds_newline (ds); ds_begin_line (ds); ds_print_pre (ds, true); - r_cons_printf ("sp: %s%d%s (vars %s%d%s, args %s%d%s)", + rz_cons_printf ("sp: %s%d%s (vars %s%d%s, args %s%d%s)", sp_args || sp_vars ? numColor : COLOR_RESET (ds), sp_args+sp_vars, COLOR_RESET (ds), sp_vars_color, sp_vars, COLOR_RESET (ds), sp_args_color, sp_args, COLOR_RESET (ds)); ds_newline (ds); ds_begin_line (ds); ds_print_pre (ds, true); - r_cons_printf ("rg: %s%d%s (vars %s%d%s, args %s%d%s)", + rz_cons_printf ("rg: %s%d%s (vars %s%d%s, args %s%d%s)", rg_args || rg_vars ? numColor : COLOR_RESET (ds), rg_args+rg_vars, COLOR_RESET (ds), rg_vars_color, rg_vars, COLOR_RESET (ds), rg_args_color, rg_args, COLOR_RESET (ds)); @@ -1750,25 +1750,25 @@ static bool empty_signature(const char *s) { } static void ds_show_functions(RDisasmState *ds) { - RAnalFunction *f; - RCore *core = ds->core; + RzAnalFunction *f; + RzCore *core = ds->core; char *fcn_name; bool fcn_name_alloc = false; // whether fcn_name needs to be freed by this function if (!ds->show_functions) { return; } - bool demangle = r_config_get_i (core->config, "bin.demangle"); - bool keep_lib = r_config_get_i (core->config, "bin.demangle.libs"); + bool demangle = rz_config_get_i (core->config, "bin.demangle"); + bool keep_lib = rz_config_get_i (core->config, "bin.demangle.libs"); bool showSig = ds->show_fcnsig && ds->show_calls; - bool call = r_config_get_i (core->config, "asm.calls"); - const char *lang = demangle ? r_config_get (core->config, "bin.lang") : NULL; - f = r_anal_get_function_at (core->anal, ds->at); + bool call = rz_config_get_i (core->config, "asm.calls"); + const char *lang = demangle ? rz_config_get (core->config, "bin.lang") : NULL; + f = rz_anal_get_function_at (core->anal, ds->at); if (!f) { return; } if (demangle) { - fcn_name = r_bin_demangle (core->bin->cur, lang, f->name, f->addr, keep_lib); + fcn_name = rz_bin_demangle (core->bin->cur, lang, f->name, f->addr, keep_lib); if (fcn_name) { fcn_name_alloc = true; } else { @@ -1779,16 +1779,16 @@ static void ds_show_functions(RDisasmState *ds) { } ds_begin_line (ds); - char *sign = r_anal_function_get_signature (f); + char *sign = rz_anal_function_get_signature (f); if (empty_signature (sign)) { R_FREE (sign); } if (f->type == R_ANAL_FCN_TYPE_LOC) { - r_cons_printf ("%s%s ", COLOR (ds, color_fline), + rz_cons_printf ("%s%s ", COLOR (ds, color_fline), core->cons->vline[LINE_CROSS]); // |- if (!showSig) { - r_cons_printf ("%s%s%s %"PFMT64u, COLOR (ds, color_floc), - fcn_name, COLOR_RESET (ds), r_anal_function_linear_size (f)); + rz_cons_printf ("%s%s%s %"PFMT64u, COLOR (ds, color_floc), + fcn_name, COLOR_RESET (ds), rz_anal_function_linear_size (f)); ds_newline (ds); } } else { @@ -1818,7 +1818,7 @@ static void ds_show_functions(RDisasmState *ds) { ds_print_offset (ds); } if (!showSig) { - r_cons_printf ("%s(%s) %s%s%s %d", COLOR (ds, color_fname), + rz_cons_printf ("%s(%s) %s%s%s %d", COLOR (ds, color_fname), fcntype, fcn_name, cmt, COLOR_RESET (ds), tmp_get_realsize (f)); ds_newline (ds); } @@ -1826,7 +1826,7 @@ static void ds_show_functions(RDisasmState *ds) { if (!showSig) { if (sign) { ds_begin_line (ds); - r_cons_printf ("// %s", sign); + rz_cons_printf ("// %s", sign); ds_newline (ds); } } @@ -1835,8 +1835,8 @@ static void ds_show_functions(RDisasmState *ds) { ds->pre = DS_PRE_FCN_MIDDLE; } ds->stackptr = core->anal->stackptr; - RAnalFcnVarsCache vars_cache; - r_anal_fcn_vars_cache_init (core->anal, &vars_cache, f); + RzAnalFcnVarsCache vars_cache; + rz_anal_fcn_vars_cache_init (core->anal, &vars_cache, f); int o_varsum = ds->show_varsum; if (ds->interactive && !o_varsum) { @@ -1852,23 +1852,23 @@ static void ds_show_functions(RDisasmState *ds) { if (call) { if (!showSig) { ds_begin_line (ds); - r_cons_print (COLOR (ds, color_fline)); + rz_cons_print (COLOR (ds, color_fline)); ds_print_pre (ds, true); - r_cons_printf ("%s ", COLOR_RESET (ds)); + rz_cons_printf ("%s ", COLOR_RESET (ds)); } - r_cons_printf ("%d: ", r_anal_function_realsize (f)); + rz_cons_printf ("%d: ", rz_anal_function_realsize (f)); // show function's realname in the signature if realnames are enabled if (core->flags->realnames) { - RFlagItem *flag = r_flag_get (core->flags, fcn_name); + RzFlagItem *flag = rz_flag_get (core->flags, fcn_name); if (flag && flag->realname) { fcn_name = flag->realname; } } - char *sig = r_anal_fcn_format_sig (core->anal, f, fcn_name, &vars_cache, COLOR (ds, color_fname), COLOR_RESET (ds)); + char *sig = rz_anal_fcn_format_sig (core->anal, f, fcn_name, &vars_cache, COLOR (ds, color_fname), COLOR_RESET (ds)); if (sig) { - r_cons_print (sig); + rz_cons_print (sig); free (sig); } ds_newline (ds); @@ -1876,21 +1876,21 @@ static void ds_show_functions(RDisasmState *ds) { if (ds->show_vars) { if (ds->show_varsum && ds->show_varsum != -1) { - RList *all_vars = vars_cache.bvars; - r_list_join (all_vars, vars_cache.svars); - r_list_join (all_vars, vars_cache.rvars); + RzList *all_vars = vars_cache.bvars; + rz_list_join (all_vars, vars_cache.svars); + rz_list_join (all_vars, vars_cache.rvars); printVarSummary (ds, all_vars); } else { char spaces[32]; - RAnalVar *var; - RListIter *iter; - RList *all_vars = vars_cache.bvars; - r_list_join (all_vars, vars_cache.svars); - r_list_join (all_vars, vars_cache.rvars); - r_list_foreach (all_vars, iter, var) { + RzAnalVar *var; + RzListIter *iter; + RzList *all_vars = vars_cache.bvars; + rz_list_join (all_vars, vars_cache.svars); + rz_list_join (all_vars, vars_cache.rvars); + rz_list_foreach (all_vars, iter, var) { ds_begin_line (ds); int idx; - RAnal *anal = ds->core->anal; + RzAnal *anal = ds->core->anal; memset (spaces, ' ', sizeof(spaces)); idx = 12 - strlen (var->name); if (idx < 0) { @@ -1902,7 +1902,7 @@ static void ds_show_functions(RDisasmState *ds) { if (ds->show_flgoff) { ds_print_offset (ds); } - r_cons_printf ("%s; ", COLOR_ARG (ds, color_func_var)); + rz_cons_printf ("%s; ", COLOR_ARG (ds, color_func_var)); switch (var->kind) { case R_ANAL_VAR_KIND_BPV: { char sign = var->isarg || (-var->delta <= f->bp_off) ? '+' : '-'; @@ -1912,20 +1912,20 @@ static void ds_show_functions(RDisasmState *ds) { } break; case R_ANAL_VAR_KIND_REG: { - RRegItem *i = r_reg_index_get (anal->reg, var->delta); + RzRegItem *i = rz_reg_index_get (anal->reg, var->delta); if (!i) { eprintf ("Register not found"); break; } - r_cons_printf ("%sarg %s%s%s%s %s@ %s", COLOR_ARG (ds, color_func_var), + rz_cons_printf ("%sarg %s%s%s%s %s@ %s", COLOR_ARG (ds, color_func_var), COLOR_ARG (ds, color_func_var_type), - var->type, r_str_endswith (var->type, "*") ? "" : " ", + var->type, rz_str_endswith (var->type, "*") ? "" : " ", var->name, COLOR_ARG (ds, color_func_var_addr), i->name); if (ds->show_varsum == -1) { - char *val = r_core_cmd_strf (ds->core, ".afvd %s", var->name); + char *val = rz_core_cmd_strf (ds->core, ".afvd %s", var->name); if (val) { - r_str_replace_char (val, '\n', '\0'); - r_cons_printf ("%s", val); + rz_str_replace_char (val, '\n', '\0'); + rz_cons_printf ("%s", val); free (val); } } @@ -1944,33 +1944,33 @@ static void ds_show_functions(RDisasmState *ds) { break; } if (var->comment) { - r_cons_printf (" %s; %s", COLOR (ds, color_comment), var->comment); + rz_cons_printf (" %s; %s", COLOR (ds, color_comment), var->comment); } - r_cons_print (COLOR_RESET (ds)); + rz_cons_print (COLOR_RESET (ds)); ds_newline (ds); } } } ds->show_varsum = o_varsum; - r_anal_fcn_vars_cache_fini (&vars_cache); + rz_anal_fcn_vars_cache_fini (&vars_cache); if (fcn_name_alloc) { free (fcn_name); } { - RListIter *iter; + RzListIter *iter; char *imp; if (ds->fcn && ds->fcn->imports) { - r_list_foreach (ds->fcn->imports, iter, imp) { + rz_list_foreach (ds->fcn->imports, iter, imp) { ds_print_pre (ds, true); ds_print_lines_left(ds); - r_cons_printf (".import %s", imp); + rz_cons_printf (".import %s", imp); ds_newline (ds); } } - r_list_foreach (ds->core->anal->imports, iter, imp) { + rz_list_foreach (ds->core->anal->imports, iter, imp) { ds_print_pre (ds, true); ds_print_lines_left(ds); - r_cons_printf (".globalimport %s", imp); + rz_cons_printf (".globalimport %s", imp); ds_newline (ds); } } @@ -1988,17 +1988,17 @@ static void ds_setup_pre(RDisasmState *ds, bool tail, bool middle) { return; } ds->pre = DS_PRE_EMPTY; - RAnalFunction *f = fcnIn (ds, ds->at, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *f = fcnIn (ds, ds->at, R_ANAL_FCN_TYPE_NULL); if (f) { if (f->addr == ds->at) { - if (ds->analop.size == r_anal_function_linear_size (f) && !middle) { + if (ds->analop.size == rz_anal_function_linear_size (f) && !middle) { ds->pre = DS_PRE_FCN_TAIL; } else { ds->pre = DS_PRE_FCN_MIDDLE; } - } else if (r_anal_function_max_addr (f) - ds->analop.size == ds->at && f->addr == r_anal_function_min_addr (f)) { + } else if (rz_anal_function_max_addr (f) - ds->analop.size == ds->at && f->addr == rz_anal_function_min_addr (f)) { ds->pre = DS_PRE_FCN_TAIL; - } else if (r_anal_function_contains (f, ds->at)) { + } else if (rz_anal_function_contains (f, ds->at)) { ds->pre = DS_PRE_FCN_MIDDLE; } if (tail) { @@ -2013,7 +2013,7 @@ static void ds_setup_pre(RDisasmState *ds, bool tail, bool middle) { } static void ds_print_pre(RDisasmState *ds, bool fcnline) { - RCore *core = ds->core; + RzCore *core = ds->core; int pre = ds->pre; const char *c = NULL; if (!fcnline) { @@ -2030,14 +2030,14 @@ static void ds_print_pre(RDisasmState *ds, bool fcnline) { c = core->cons->vline[CORNER_BL]; break; case DS_PRE_EMPTY: - r_cons_print (" "); + rz_cons_print (" "); return; case DS_PRE_NONE: default: return; } - r_cons_printf ("%s%s%s ", + rz_cons_printf ("%s%s%s ", COLOR (ds, color_fline), c, COLOR_RESET (ds)); } @@ -2046,7 +2046,7 @@ static void ds_show_comments_describe(RDisasmState *ds) { /* respect asm.describe */ char *desc = NULL; if (ds->asm_describe && !ds->has_description) { - char *op, *locase = strdup (r_asm_op_get_asm (&ds->asmop)); + char *op, *locase = strdup (rz_asm_op_get_asm (&ds->asmop)); if (!locase) { return; } @@ -2054,18 +2054,18 @@ static void ds_show_comments_describe(RDisasmState *ds) { if (op) { *op = 0; } - r_str_case (locase, 0); - desc = r_asm_describe (ds->core->rasm, locase); + rz_str_case (locase, 0); + desc = rz_asm_describe (ds->core->rasm, locase); free (locase); } if (desc && *desc) { ds_begin_comment (ds); ds_align_comment (ds); if (ds->show_color) { - r_cons_strcat (ds->color_comment); + rz_cons_strcat (ds->color_comment); } - r_cons_strcat ("; "); - r_cons_strcat (desc); + rz_cons_strcat ("; "); + rz_cons_strcat (desc); ds_print_color_reset (ds); ds_newline (ds); free (desc); @@ -2075,26 +2075,26 @@ static void ds_show_comments_describe(RDisasmState *ds) { //XXX review this with asm.cmt.right static void ds_show_comments_right(RDisasmState *ds) { int linelen; - RCore *core = ds->core; + RzCore *core = ds->core; /* show comment at right? */ int scr = ds->show_comment_right; if (!ds->show_comments && !ds->show_usercomments) { return; } - RFlagItem *item = r_flag_get_i (core->flags, ds->at); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at); - const char *vartype = r_meta_get_string (core->anal, R_META_TYPE_VARTYPE, ds->at); + RzFlagItem *item = rz_flag_get_i (core->flags, ds->at); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at); + const char *vartype = rz_meta_get_string (core->anal, R_META_TYPE_VARTYPE, ds->at); if (!comment) { if (vartype) { - ds->comment = r_str_newf ("%s; %s", COLOR_ARG (ds, color_func_var_type), vartype); + ds->comment = rz_str_newf ("%s; %s", COLOR_ARG (ds, color_func_var_type), vartype); } else if (item && item->comment && *item->comment) { ds->ocomment = item->comment; ds->comment = strdup (item->comment); } } else if (vartype) { - ds->comment = r_str_newf ("%s; %s %s%s; %s", COLOR_ARG (ds, color_func_var_type), vartype, Color_RESET, COLOR (ds, color_usrcmt), comment); + ds->comment = rz_str_newf ("%s; %s %s%s; %s", COLOR_ARG (ds, color_func_var_type), vartype, Color_RESET, COLOR (ds, color_usrcmt), comment); } else { - ds->comment = r_str_newf ("%s; %s", COLOR_ARG (ds, color_usrcmt), comment); + ds->comment = rz_str_newf ("%s; %s", COLOR_ARG (ds, color_usrcmt), comment); } if (!ds->comment || !*ds->comment) { return; @@ -2115,7 +2115,7 @@ static void ds_show_comments_right(RDisasmState *ds) { } mycols /= 2; if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } /* print multiline comment */ if (ds->cmtfold) { @@ -2123,14 +2123,14 @@ static void ds_show_comments_right(RDisasmState *ds) { char *q = strchr (p, '\n'); if (q) { *q = 0; - r_cons_strcat (p); - r_cons_strcat (" ; [z] unfold"); + rz_cons_strcat (p); + rz_cons_strcat (" ; [z] unfold"); } free (p); } else { ds_pre_xrefs (ds, false); if (ds->show_color) { - r_cons_strcat (ds->color_usrcmt); + rz_cons_strcat (ds->color_usrcmt); } ds_comment (ds, false, "%s", ds->comment); } @@ -2143,12 +2143,12 @@ static void ds_show_comments_right(RDisasmState *ds) { if (item && item->comment && ds->ocomment != item->comment) { ds_begin_line (ds); if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } ds_newline (ds); ds_begin_line (ds); - r_cons_strcat (" ; "); - r_cons_strcat_justify (item->comment, mycols, ';'); + rz_cons_strcat (" ; "); + rz_cons_strcat_justify (item->comment, mycols, ';'); ds_newline (ds); if (ds->show_color) { ds_print_color_reset (ds); @@ -2159,61 +2159,61 @@ static void ds_show_comments_right(RDisasmState *ds) { } static int flagCmp(const void *a, const void *b) { - const RFlagItem *fa = a; - const RFlagItem *fb = b; + const RzFlagItem *fa = a; + const RzFlagItem *fb = b; if (fa->realname && fb->realname) { return strcmp (fa->realname, fb->realname); } return strcmp (fa->name, fb->name); } -static void __preline_flag(RDisasmState *ds, RFlagItem *flag) { +static void __preline_flag(RDisasmState *ds, RzFlagItem *flag) { ds_newline (ds); ds_begin_line (ds); ds_pre_line (ds); if (ds->show_color) { bool hasColor = false; if (flag->color) { - char *color = r_cons_pal_parse (flag->color, NULL); + char *color = rz_cons_pal_parse (flag->color, NULL); if (color) { - r_cons_strcat (color); + rz_cons_strcat (color); free (color); ds->lastflag = flag; hasColor = true; } } if (!hasColor) { - r_cons_strcat (ds->color_flag); + rz_cons_strcat (ds->color_flag); } } if (!ds->show_offset) { - r_cons_printf (" "); + rz_cons_printf (" "); } } #define printPre (outline || !*comma) static void ds_show_flags(RDisasmState *ds) { //const char *beginch; - RFlagItem *flag; - RListIter *iter; - RAnalFunction *f = NULL; + RzFlagItem *flag; + RzListIter *iter; + RzAnalFunction *f = NULL; if (!ds->show_flags) { return; } - RCore *core = ds->core; + RzCore *core = ds->core; char addr[64]; ut64 switch_addr = UT64_MAX; int case_start = -1, case_prev = 0, case_current = 0; - f = r_anal_get_function_at (ds->core->anal, ds->at); - const RList *flaglist = r_flag_get_list (core->flags, ds->at); - RList *uniqlist = flaglist? r_list_uniq (flaglist, flagCmp): NULL; + f = rz_anal_get_function_at (ds->core->anal, ds->at); + const RzList *flaglist = rz_flag_get_list (core->flags, ds->at); + RzList *uniqlist = flaglist? rz_list_uniq (flaglist, flagCmp): NULL; int count = 0; bool outline = !ds->flags_inline; const char *comma = ""; - bool keep_lib = r_config_get_i (core->config, "bin.demangle.libs"); + bool keep_lib = rz_config_get_i (core->config, "bin.demangle.libs"); bool docolon = true; int nth = 0; - r_list_foreach (uniqlist, iter, flag) { + rz_list_foreach (uniqlist, iter, flag) { if (f && f->addr == flag->offset && !strcmp (flag->name, f->name)) { // do not show flags that have the same name as the function continue; @@ -2223,13 +2223,13 @@ static void ds_show_flags(RDisasmState *ds) { if (printPre) { ds_pre_xrefs (ds, no_fcn_lines); } - r_cons_printf ("..."); + rz_cons_printf ("..."); break; } count++; if (!strncmp (flag->name, "case.", 5)) { sscanf (flag->name + 5, "%63[^.].%d", addr, &case_current); - ut64 saddr = r_num_math (core->num, addr); + ut64 saddr = rz_num_math (core->num, addr); if (case_start == -1) { switch_addr = saddr; case_prev = case_current; @@ -2255,7 +2255,7 @@ static void ds_show_flags(RDisasmState *ds) { ds_pre_line (ds); ds_print_offset (ds); if (!fake_flag_marks) { - r_cons_printf (" "); + rz_cons_printf (" "); } } else { ds_pre_xrefs (ds, no_fcn_lines); @@ -2265,48 +2265,48 @@ static void ds_show_flags(RDisasmState *ds) { if (ds->show_color) { bool hasColor = false; if (flag->color) { - char *color = r_cons_pal_parse (flag->color, NULL); + char *color = rz_cons_pal_parse (flag->color, NULL); if (color) { - r_cons_strcat (color); + rz_cons_strcat (color); free (color); ds->lastflag = flag; hasColor = true; } } if (!hasColor) { - r_cons_strcat (ds->color_flag); + rz_cons_strcat (ds->color_flag); } } if (ds->asm_demangle && flag->realname) { if (!strncmp (flag->name, "switch.", 7)) { - r_cons_printf (FLAG_PREFIX"switch"); + rz_cons_printf (FLAG_PREFIX"switch"); } else if (!strncmp (flag->name, "case.", 5)) { if (nth > 0) { __preline_flag (ds, flag); } if (!strncmp (flag->name + 5, "default", 7)) { - r_cons_printf (FLAG_PREFIX "default:"); // %s:", flag->name); - r_str_ncpy (addr, flag->name + 5 + strlen ("default."), sizeof (addr)); + rz_cons_printf (FLAG_PREFIX "default:"); // %s:", flag->name); + rz_str_ncpy (addr, flag->name + 5 + strlen ("default."), sizeof (addr)); nth = 0; } else if (case_prev != case_start) { - r_cons_printf (FLAG_PREFIX "case %d...%d:", case_start, case_prev); + rz_cons_printf (FLAG_PREFIX "case %d...%d:", case_start, case_prev); if (iter != uniqlist->head && iter != uniqlist->tail) { iter = iter->p; } case_start = case_current; } else { - r_cons_printf (FLAG_PREFIX "case %d:", case_prev); + rz_cons_printf (FLAG_PREFIX "case %d:", case_prev); case_start = -1; } case_prev = case_current; ds_align_comment (ds); - r_cons_printf ("%s; from %s", ds->show_color ? ds->pal_comment : "", addr); + rz_cons_printf ("%s; from %s", ds->show_color ? ds->pal_comment : "", addr); outline = false; docolon = false; } else { - const char *lang = r_config_get (core->config, "bin.lang"); - char *name = r_bin_demangle (core->bin->cur, lang, flag->realname, flag->offset, keep_lib); + const char *lang = rz_config_get (core->config, "bin.lang"); + char *name = rz_bin_demangle (core->bin->cur, lang, flag->realname, flag->offset, keep_lib); if (!name) { const char *n = flag->realname? flag->realname: flag->name; if (n) { @@ -2314,27 +2314,27 @@ static void ds_show_flags(RDisasmState *ds) { } } if (name) { - r_str_ansi_filter (name, NULL, NULL, -1); + rz_str_ansi_filter (name, NULL, NULL, -1); if (!ds->flags_inline || nth == 0) { - r_cons_printf (FLAG_PREFIX); + rz_cons_printf (FLAG_PREFIX); } if (outline) { - r_cons_printf ("%s:", name); + rz_cons_printf ("%s:", name); } else { - r_cons_printf ("%s%s", comma, flag->name); + rz_cons_printf ("%s%s", comma, flag->name); } R_FREE (name); } } } else { if (outline) { - r_cons_printf ("%s", flag->name); + rz_cons_printf ("%s", flag->name); } else { - r_cons_printf ("%s%s", comma, flag->name); + rz_cons_printf ("%s%s", comma, flag->name); } } if (ds->show_color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } if (outline) { ds_newline (ds); @@ -2345,18 +2345,18 @@ static void ds_show_flags(RDisasmState *ds) { } if (!outline && *comma) { if (nth > 0 && docolon) { - r_cons_printf (":"); + rz_cons_printf (":"); } ds_newline (ds); } - r_list_free (uniqlist); + rz_list_free (uniqlist); } static void ds_update_ref_lines(RDisasmState *ds) { if (ds->show_lines_bb) { free (ds->line); free (ds->line_col); - RAnalRefStr *line = r_anal_reflines_str (ds->core, ds->at, ds->linesopts); + RzAnalRefStr *line = rz_anal_reflines_str (ds->core, ds->at, ds->linesopts); ds->line = line->str; ds->line_col = line->cols; free (ds->refline); @@ -2364,7 +2364,7 @@ static void ds_update_ref_lines(RDisasmState *ds) { free (ds->refline2); free (ds->prev_line_col); free (line); - line = r_anal_reflines_str (ds->core, ds->at, + line = rz_anal_reflines_str (ds->core, ds->at, ds->linesopts | R_ANAL_REFLINE_TYPE_MIDDLE_BEFORE); ds->refline2 = line->str; ds->prev_line_col = line->cols; @@ -2393,18 +2393,18 @@ static void ds_update_ref_lines(RDisasmState *ds) { } static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { - RCore *core = ds->core; + RzCore *core = ds->core; int ret; // find the meta item at this offset if any - RPVector *metas = r_meta_get_all_at (ds->core->anal, ds->at); // TODO: do in range - RAnalMetaItem *meta = NULL; + RPVector *metas = rz_meta_get_all_at (ds->core->anal, ds->at); // TODO: do in range + RzAnalMetaItem *meta = NULL; ut64 meta_size = UT64_MAX; if (metas) { void **it; - r_pvector_foreach (metas, it) { + rz_pvector_foreach (metas, it) { RIntervalNode *node = *it; - RAnalMetaItem *mi = node->data; + RzAnalMetaItem *mi = node->data; switch (mi->type) { case R_META_TYPE_DATA: case R_META_TYPE_STRING: @@ -2413,17 +2413,17 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { case R_META_TYPE_HIDE: case R_META_TYPE_RUN: meta = mi; - meta_size = r_meta_item_size (node->start, node->end); + meta_size = rz_meta_item_size (node->start, node->end); break; default: break; } } - r_pvector_free (metas); + rz_pvector_free (metas); } if (ds->hint && ds->hint->bits) { if (!ds->core->anal->opt.ignbithints) { - r_config_set_i (core->config, "asm.bits", ds->hint->bits); + rz_config_set_i (core->config, "asm.bits", ds->hint->bits); } } if (ds->hint && ds->hint->size) { @@ -2433,8 +2433,8 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { free (ds->opstr); ds->opstr = strdup (ds->hint->opcode); } - r_asm_op_fini (&ds->asmop); - ret = r_asm_disassemble (core->rasm, &ds->asmop, buf, len); + rz_asm_op_fini (&ds->asmop); + ret = rz_asm_disassemble (core->rasm, &ds->asmop, buf, len); if (ds->asmop.size < 1) { ds->asmop.size = 1; } @@ -2446,7 +2446,7 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { switch (meta->type) { case R_META_TYPE_DATA: if (meta->str) { - r_cons_printf (".data: %s\n", meta->str); + rz_cons_printf (".data: %s\n", meta->str); } i += meta_size; break; @@ -2454,31 +2454,31 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { i += meta_size; break; case R_META_TYPE_FORMAT: - r_cons_printf (".format : %s\n", meta->str); + rz_cons_printf (".format : %s\n", meta->str); i += meta_size; break; case R_META_TYPE_MAGIC: - r_cons_printf (".magic : %s\n", meta->str); + rz_cons_printf (".magic : %s\n", meta->str); i += meta_size; break; case R_META_TYPE_RUN: - r_core_cmd0 (core, meta->str); + rz_core_cmd0 (core, meta->str); break; default: break; } int sz = R_MIN (16, meta_size); ds->asmop.size = sz; - r_asm_op_set_hexbuf (&ds->asmop, buf, sz); + rz_asm_op_set_hexbuf (&ds->asmop, buf, sz); switch (meta->type) { case R_META_TYPE_STRING: - r_asm_op_set_asm (&ds->asmop, sdb_fmt (".string \"%s\"", meta->str)); + rz_asm_op_set_asm (&ds->asmop, sdb_fmt (".string \"%s\"", meta->str)); break; // case R_META_TYPE_DATA: // break; default: { - char *op_hex = r_asm_op_get_hex (&ds->asmop); - r_asm_op_set_asm (&ds->asmop, sdb_fmt (".hex %s", op_hex)); + char *op_hex = rz_asm_op_get_hex (&ds->asmop); + rz_asm_op_set_asm (&ds->asmop, sdb_fmt (".hex %s", op_hex)); free (op_hex); break; } @@ -2489,24 +2489,24 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { } if (ds->show_nodup) { - const char *opname = (ret < 1)? "invalid": r_asm_op_get_asm (&ds->asmop); + const char *opname = (ret < 1)? "invalid": rz_asm_op_get_asm (&ds->asmop); if (ds->prev_ins && !strcmp (ds->prev_ins, opname)) { if (!ds->prev_ins_eq) { ds->prev_ins_eq = true; - r_cons_printf ("..."); + rz_cons_printf ("..."); } ds->prev_ins_count++; return -31337; } if (ds->prev_ins_eq) { - r_cons_printf ("dup (%d)\n", ds->prev_ins_count); + rz_cons_printf ("dup (%d)\n", ds->prev_ins_count); } ds->prev_ins_count = 0; ds->prev_ins_eq = false; if (ds->prev_ins) { R_FREE (ds->prev_ins); } - ds->prev_ins = strdup (r_asm_op_get_asm (&ds->asmop)); + ds->prev_ins = strdup (rz_asm_op_get_asm (&ds->asmop)); } ds->oplen = ds->asmop.size; @@ -2528,21 +2528,21 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { ds->lastfail = 0; ds->asmop.size = (ds->hint && ds->hint->size) ? ds->hint->size - : r_asm_op_get_size (&ds->asmop); + : rz_asm_op_get_size (&ds->asmop); ds->oplen = ds->asmop.size; } if (ds->pseudo) { - r_parse_parse (core->parser, ds->opstr + rz_parse_parse (core->parser, ds->opstr ? ds->opstr - : r_asm_op_get_asm (&ds->asmop), + : rz_asm_op_get_asm (&ds->asmop), ds->str); free (ds->opstr); ds->opstr = strdup (ds->str); } if (ds->acase) { - r_str_case (r_asm_op_get_asm (&ds->asmop), 1); + rz_str_case (rz_asm_op_get_asm (&ds->asmop), 1); } else if (ds->capitalize) { - char *ba = r_asm_op_get_asm (&ds->asmop); + char *ba = rz_asm_op_get_asm (&ds->asmop); *ba = toupper ((ut8)*ba); } if (meta && meta_size != UT64_MAX) { @@ -2553,11 +2553,11 @@ static int ds_disassemble(RDisasmState *ds, ut8 *buf, int len) { static void ds_control_flow_comments(RDisasmState *ds) { if (ds->show_comments && ds->show_cmtflgrefs) { - RFlagItem *item; + RzFlagItem *item; if (ds->asm_anal) { switch (ds->analop.type) { case R_ANAL_OP_TYPE_CALL: - r_core_cmdf (ds->core, "af @ 0x%"PFMT64x, ds->analop.jump); + rz_core_cmdf (ds->core, "af @ 0x%"PFMT64x, ds->analop.jump); break; } } @@ -2565,13 +2565,13 @@ static void ds_control_flow_comments(RDisasmState *ds) { case R_ANAL_OP_TYPE_JMP: case R_ANAL_OP_TYPE_CJMP: case R_ANAL_OP_TYPE_CALL: - item = r_flag_get_i (ds->core->flags, ds->analop.jump); + item = rz_flag_get_i (ds->core->flags, ds->analop.jump); if (item && item->comment) { if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } ds_align_comment (ds); - r_cons_printf (" ; ref to %s: %s\n", item->name, item->comment); + rz_cons_printf (" ; ref to %s: %s\n", item->name, item->comment); ds_print_color_reset (ds); } break; @@ -2610,10 +2610,10 @@ static void printCol(RDisasmState *ds, char *sect, int cols, const char *color) strcat (out, Color_RESET); out[outsz - 1] = 0; } else { - r_str_ncpy (out + 1, sect, outsz - 2); + rz_str_ncpy (out + 1, sect, outsz - 2); } strcat (out, " "); - r_cons_strcat (out); + rz_cons_strcat (out); free (out); } @@ -2621,23 +2621,23 @@ static void ds_print_lines_left(RDisasmState *ds) { if (ds->linesright) { return; } - RCore *core = ds->core; + RzCore *core = ds->core; if (ds->show_section) { char *str = NULL; if (ds->show_section_perm) { // iosections must die, this should be rbin_section_get - RIOMap *map = r_io_map_get (core->io, ds->at); - str = strdup (map? r_str_rwx_i (map->perm): "---"); + RzIOMap *map = rz_io_map_get (core->io, ds->at); + str = strdup (map? rz_str_rwx_i (map->perm): "---"); } if (ds->show_section_name) { - str = r_str_appendf (str, " %s", r_core_get_section_name (core, ds->at)); + str = rz_str_appendf (str, " %s", rz_core_get_section_name (core, ds->at)); } char *sect = str? str: strdup (""); printCol (ds, sect, ds->show_section_col, ds->color_reg); free (sect); } if (ds->show_symbols) { - static RFlagItem sfi = R_EMPTY; + static RzFlagItem sfi = R_EMPTY; const char *name = ""; int delta = 0; if (ds->fcn) { @@ -2645,7 +2645,7 @@ static void ds_print_lines_left(RDisasmState *ds) { sfi.name = ds->fcn->name; ds->lastflag = &sfi; } else { - RFlagItem *fi = r_flag_get_at (core->flags, ds->at, !ds->lastflag); + RzFlagItem *fi = rz_flag_get_at (core->flags, ds->at, !ds->lastflag); if (fi) { // && (!ds->lastflag || fi->offset != ds->at)) sfi.offset = fi->offset; sfi.name = fi->name; @@ -2657,7 +2657,7 @@ static void ds_print_lines_left(RDisasmState *ds) { delta = ds->at - ds->lastflag->offset; } { - char *str = r_str_newf ("%s + %-4d", name, delta); + char *str = rz_str_newf ("%s + %-4d", name, delta); printCol (ds, str, ds->show_symbols_col, ds->color_num); free (str); } @@ -2669,17 +2669,17 @@ static void ds_print_lines_left(RDisasmState *ds) { static void ds_print_family(RDisasmState *ds) { if (ds->show_family) { - const char *familystr = r_anal_op_family_to_string (ds->analop.family); - r_cons_printf ("%5s ", familystr? familystr: ""); + const char *familystr = rz_anal_op_family_to_string (ds->analop.family); + rz_cons_printf ("%5s ", familystr? familystr: ""); } } static void ds_print_cycles(RDisasmState *ds) { if (ds->show_cycles) { if (!ds->analop.failcycles) { - r_cons_printf ("%3d ", ds->analop.cycles); + rz_cons_printf ("%3d ", ds->analop.cycles); } else { - r_cons_printf ("%3d %3d ", ds->analop.cycles, ds->analop.failcycles); + rz_cons_printf ("%3d %3d ", ds->analop.cycles, ds->analop.failcycles); } } if (ds->cyclespace) { @@ -2687,46 +2687,46 @@ static void ds_print_cycles(RDisasmState *ds) { int times = R_MIN (ds->analop.cycles/4, 30); // limit to 30 memset (spaces, ' ', sizeof (spaces)); spaces[times] = 0; - r_cons_strcat (spaces); + rz_cons_strcat (spaces); } } #include "disasm_stackptr.inc" static void ds_print_offset(RDisasmState *ds) { - RCore *core = ds->core; + RzCore *core = ds->core; ut64 at = ds->vat; bool hasCustomColor = false; // probably tooslow - RFlagItem *f = r_flag_get_at (core->flags, at, 1); + RzFlagItem *f = rz_flag_get_at (core->flags, at, 1); if (ds->show_color && f) { // ds->lastflag) { const char *color = f->color; if (ds->at >= f->offset && ds->at < f->offset + f->size) { - // if (r_itv_inrange (f->itv, ds->at)) + // if (rz_itv_inrange (f->itv, ds->at)) if (color && *color) { - char *k = r_cons_pal_parse (f->color, NULL); + char *k = rz_cons_pal_parse (f->color, NULL); if (k) { - r_cons_printf ("%s", k); + rz_cons_printf ("%s", k); hasCustomColor = true; free (k); } } } } - r_print_set_screenbounds (core->print, at); + rz_print_set_screenbounds (core->print, at); if (ds->show_offset) { - static RFlagItem sfi = R_EMPTY; + static RzFlagItem sfi = R_EMPTY; const char *label = NULL; - RFlagItem *fi; + RzFlagItem *fi; int delta = -1; bool show_trace = false; - unsigned int seggrn = r_config_get_i (core->config, "asm.seggrn"); + unsigned int seggrn = rz_config_get_i (core->config, "asm.seggrn"); if (ds->show_reloff) { - RAnalFunction *f = r_anal_get_function_at (core->anal, at); + RzAnalFunction *f = rz_anal_get_function_at (core->anal, at); if (!f) { - f = fcnIn (ds, at, R_ANAL_FCN_TYPE_NULL); // r_anal_get_fcn_in (core->anal, at, R_ANAL_FCN_TYPE_NULL); + f = fcnIn (ds, at, R_ANAL_FCN_TYPE_NULL); // rz_anal_get_fcn_in (core->anal, at, R_ANAL_FCN_TYPE_NULL); } if (f) { delta = at - f->addr; @@ -2737,7 +2737,7 @@ static void ds_print_offset(RDisasmState *ds) { } else { if (ds->show_reloff_flags) { /* XXX: this is wrong if starting to disasm after a flag */ - fi = r_flag_get_i (core->flags, at); + fi = rz_flag_get_i (core->flags, at); if (fi) { ds->lastflag = fi; } @@ -2760,7 +2760,7 @@ static void ds_print_offset(RDisasmState *ds) { } } if (ds->show_trace) { - RDebugTracepoint *tp = r_debug_trace_get (ds->core->dbg, ds->at); + RzDebugTracepoint *tp = rz_debug_trace_get (ds->core->dbg, ds->at); show_trace = (tp? !!tp->count: false); } if (ds->hint && ds->hint->high) { @@ -2769,12 +2769,12 @@ static void ds_print_offset(RDisasmState *ds) { if (hasCustomColor) { int of = core->print->flags; core->print->flags = 0; - r_print_offset_sg (core->print, at, (at == ds->dest) || show_trace, + rz_print_offset_sg (core->print, at, (at == ds->dest) || show_trace, ds->show_offseg, seggrn, ds->show_offdec, delta, label); core->print->flags = of; - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } else { - r_print_offset_sg (core->print, at, (at == ds->dest) || show_trace, + rz_print_offset_sg (core->print, at, (at == ds->dest) || show_trace, ds->show_offseg, seggrn, ds->show_offdec, delta, label); } } @@ -2790,48 +2790,48 @@ static void ds_print_offset(RDisasmState *ds) { ds->_tabsoff = ds->atabsoff; } } - r_cons_strcat (ds->_tabsbuf); + rz_cons_strcat (ds->_tabsbuf); } } static void ds_print_op_size(RDisasmState *ds) { if (ds->show_size) { int size = ds->oplen; - r_cons_printf ("%d ", size); //ds->analop.size); + rz_cons_printf ("%d ", size); //ds->analop.size); } } static void ds_print_trace(RDisasmState *ds) { - RDebugTracepoint *tp = NULL; + RzDebugTracepoint *tp = NULL; if (ds->show_trace) { - tp = r_debug_trace_get (ds->core->dbg, ds->at); - r_cons_printf ("%02x:%04x ", tp?tp->times:0, tp?tp->count:0); + tp = rz_debug_trace_get (ds->core->dbg, ds->at); + rz_cons_printf ("%02x:%04x ", tp?tp->times:0, tp?tp->count:0); } if (ds->tracespace) { char spaces [32]; int times; if (!tp) { - tp = r_debug_trace_get (ds->core->dbg, ds->at); + tp = rz_debug_trace_get (ds->core->dbg, ds->at); } if (tp) { times = R_MIN (tp->times, 30); // limit to 30 memset (spaces, ' ', sizeof (spaces)); spaces[times] = 0; - r_cons_strcat (spaces); + rz_cons_strcat (spaces); } } } static void ds_adistrick_comments(RDisasmState *ds) { if (ds->adistrick) { - ds->middle = r_anal_reflines_middle (ds->core->anal, + ds->middle = rz_anal_reflines_middle (ds->core->anal, ds->core->anal->reflines, ds->at, ds->analop.size); } } -// TODO move into RAnal.meta +// TODO move into RzAnal.meta static bool ds_print_data_type(RDisasmState *ds, const ut8 *buf, int ib, int size) { - RCore *core = ds->core; + RzCore *core = ds->core; const char *type = NULL; char msg[64]; const int isSigned = (ib == 1 || ib == 8 || ib == 10)? 1: 0; @@ -2844,54 +2844,54 @@ static bool ds_print_data_type(RDisasmState *ds, const ut8 *buf, int ib, int siz default: return false; } // adjust alignment - ut64 n = r_read_ble (buf, core->print->big_endian, size * 8); - if (r_config_get_i (core->config, "asm.marks")) { - r_cons_printf (" "); + ut64 n = rz_read_ble (buf, core->print->big_endian, size * 8); + if (rz_config_get_i (core->config, "asm.marks")) { + rz_cons_printf (" "); int q = core->print->cur_enabled && ds->cursor >= ds->index && ds->cursor < (ds->index + size); if (q) { if (ds->cursor > ds->index) { int diff = ds->cursor - ds->index; - r_cons_printf ("%d ", diff); + rz_cons_printf ("%d ", diff); } else if (ds->cursor == ds->index) { - r_cons_printf ("* "); + rz_cons_printf ("* "); } else { - r_cons_printf (" "); + rz_cons_printf (" "); } } else { - r_cons_printf (" "); + rz_cons_printf (" "); } } - r_cons_strcat (ds->color_mov); + rz_cons_strcat (ds->color_mov); switch (ib) { case 1: - r_str_bits (msg, buf, size * 8, NULL); - r_cons_printf ("%s %sb", type, msg); + rz_str_bits (msg, buf, size * 8, NULL); + rz_cons_printf ("%s %sb", type, msg); break; case 3: - r_cons_printf ("%s %d", type, ntohs (n & 0xFFFF)); + rz_cons_printf ("%s %d", type, ntohs (n & 0xFFFF)); break; case 8: - r_cons_printf ("%s %oo", type, n); + rz_cons_printf ("%s %oo", type, n); break; case 10: - r_cons_printf ("%s %d", type, n); + rz_cons_printf ("%s %d", type, n); break; default: switch (size) { case 1: - r_cons_printf ("%s 0x%02x", type, n); + rz_cons_printf ("%s 0x%02x", type, n); break; case 2: - r_cons_printf ("%s 0x%04x", type, n); + rz_cons_printf ("%s 0x%04x", type, n); break; case 4: - r_cons_printf ("%s 0x%08x", type, n); + rz_cons_printf ("%s 0x%08x", type, n); break; case 8: - r_cons_printf ("%s 0x%016" PFMT64x, type, n); + rz_cons_printf ("%s 0x%016" PFMT64x, type, n); break; default: return false; @@ -2899,8 +2899,8 @@ static bool ds_print_data_type(RDisasmState *ds, const ut8 *buf, int ib, int siz } if (size == 4 || size == 8) { - if (r_str_startswith (r_config_get (core->config, "asm.arch"), "arm")) { - ut64 bits = r_config_get_i (core->config, "asm.bits"); + if (rz_str_startswith (rz_config_get (core->config, "asm.arch"), "arm")) { + ut64 bits = rz_config_get_i (core->config, "asm.bits"); //adjust address for arm/thumb address if (bits < 64) { if (n & 1) { @@ -2909,11 +2909,11 @@ static bool ds_print_data_type(RDisasmState *ds, const ut8 *buf, int ib, int siz } } if (n >= ds->min_ref_addr) { - const RList *flags = r_flag_get_list (core->flags, n); - RListIter *iter; - RFlagItem *fi; - r_list_foreach (flags, iter, fi) { - r_cons_printf (" ; %s", fi->name); + const RzList *flags = rz_flag_get_list (core->flags, n); + RzListIter *iter; + RzFlagItem *fi; + rz_list_foreach (flags, iter, fi) { + rz_cons_printf (" ; %s", fi->name); } } } @@ -2922,8 +2922,8 @@ static bool ds_print_data_type(RDisasmState *ds, const ut8 *buf, int ib, int siz static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, int *mi_type) { bool ret = false; - RAnalMetaItem *fmi; - RCore *core = ds->core; + RzAnalMetaItem *fmi; + RzCore *core = ds->core; if (!ds->asm_meta) { return false; } @@ -2934,16 +2934,16 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in snprintf (key, sizeof (key), "meta.0x%" PFMT64x, ds->at); const char *infos = sdb_const_get (s, key, 0); #endif - RPVector *metas = r_meta_get_all_in (core->anal, ds->at, R_META_TYPE_ANY); + RPVector *metas = rz_meta_get_all_in (core->anal, ds->at, R_META_TYPE_ANY); if (!metas) { return false; } bool once = true; fmi = NULL; void **it; - r_pvector_foreach (metas, it) { + rz_pvector_foreach (metas, it) { RIntervalNode *node = *it; - RAnalMetaItem *mi = node->data; + RzAnalMetaItem *mi = node->data; switch (mi->type) { case R_META_TYPE_DATA: if (once) { @@ -2951,7 +2951,7 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in if (ds->asm_hint_lea) { ds_print_shortcut (ds, node->start, 0); } else { - r_cons_strcat (" "); + rz_cons_strcat (" "); } } once = false; @@ -2964,10 +2964,10 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in break; } } - r_pvector_foreach (metas, it) { + rz_pvector_foreach (metas, it) { RIntervalNode *node = *it; - RAnalMetaItem *mi = node->data; - ut64 mi_size = r_meta_node_size (node); + RzAnalMetaItem *mi = node->data; + ut64 mi_size = rz_meta_node_size (node); char *out = NULL; int hexlen; int delta; @@ -2984,18 +2984,18 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in switch (mi->subtype) { case R_STRING_ENC_UTF8: - out = r_str_escape_utf8 (mi->str, false, esc_bslash); + out = rz_str_escape_utf8 (mi->str, false, esc_bslash); break; case 0: /* temporary legacy workaround */ esc_bslash = false; /* fallthrough */ default: - out = r_str_escape_latin1 (mi->str, false, esc_bslash, false); + out = rz_str_escape_latin1 (mi->str, false, esc_bslash, false); } if (!out) { break; } - r_cons_printf (" .string %s\"%s\"%s ; len=%"PFMT64d, + rz_cons_printf (" .string %s\"%s\"%s ; len=%"PFMT64d, COLOR (ds, color_btext), out, COLOR_RESET (ds), mi_size); free (out); @@ -3012,13 +3012,13 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in break; } case R_META_TYPE_HIDE: - r_cons_printf ("(%"PFMT64d" bytes hidden)", mi_size); + rz_cons_printf ("(%"PFMT64d" bytes hidden)", mi_size); ds->asmop.size = mi_size; ds->oplen = mi_size; ret = true; break; case R_META_TYPE_RUN: - r_core_cmdf (core, "%s @ 0x%"PFMT64x, mi->str, ds->at); + rz_core_cmdf (core, "%s @ 0x%"PFMT64x, mi->str, ds->at); ds->asmop.size = mi_size; ds->oplen = mi_size; ret = true; @@ -3035,8 +3035,8 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in // print operation int size = R_MIN (mi_size, len - idx); if (!ds_print_data_type (ds, buf + idx, ds->hint? ds->hint->immbase: 0, size)) { - r_cons_printf ("hex length=%" PFMT64d " delta=%d\n", size , delta); - r_print_hexdump (core->print, ds->at, buf+idx, hexlen-delta, 16, 1, 1); + rz_cons_printf ("hex length=%" PFMT64d " delta=%d\n", size , delta); + rz_print_hexdump (core->print, ds->at, buf+idx, hexlen-delta, 16, 1, 1); } core->print->flags |= R_PRINT_FLAGS_HEADER; ds->asmop.size = (int)mi_size; @@ -3049,14 +3049,14 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in break; case R_META_TYPE_FORMAT: { - r_cons_printf ("pf %s # size=%d\n", mi->str, mi_size); - int len_before = r_cons_get_buffer_len (); - r_print_format (core->print, ds->at, buf + idx, + rz_cons_printf ("pf %s # size=%d\n", mi->str, mi_size); + int len_before = rz_cons_get_buffer_len (); + rz_print_format (core->print, ds->at, buf + idx, len - idx, mi->str, R_PRINT_MUSTSEE, NULL, NULL); - int len_after = r_cons_get_buffer_len (); - const char *cons_buf = r_cons_get_buffer (); + int len_after = rz_cons_get_buffer_len (); + const char *cons_buf = rz_cons_get_buffer (); if (len_after > len_before && buf && cons_buf[len_after - 1] == '\n') { - r_cons_drop (1); + rz_cons_drop (1); } ds->oplen = ds->asmop.size = (int)mi_size; R_FREE (ds->line); @@ -3070,7 +3070,7 @@ static bool ds_print_meta_infos(RDisasmState *ds, ut8* buf, int len, int idx, in break; } } - r_pvector_free (metas); + rz_pvector_free (metas); return ret; } @@ -3119,7 +3119,7 @@ static void ds_cdiv_optimization(RDisasmState *ds) { if (comma && comma == end) { divisor = revert_cdiv_magic (imm); if (divisor) { - r_cons_printf (" ; CDIV: %lld * 2^n", divisor); + rz_cons_printf (" ; CDIV: %lld * 2^n", divisor); break; } } @@ -3130,7 +3130,7 @@ static void ds_cdiv_optimization(RDisasmState *ds) { } static void ds_print_show_bytes(RDisasmState *ds) { - RCore* core = ds->core; + RzCore* core = ds->core; char *nstr, *str = NULL, pad[64]; char *flagstr = NULL; int oldFlags = core->print->flags; @@ -3145,7 +3145,7 @@ static void ds_print_show_bytes(RDisasmState *ds) { } strcpy (extra, " "); if (ds->show_flag_in_bytes) { - flagstr = r_flag_get_liststr (core->flags, ds->at); + flagstr = rz_flag_get_liststr (core->flags, ds->at); } if (flagstr) { str = flagstr; @@ -3176,20 +3176,20 @@ static void ds_print_show_bytes(RDisasmState *ds) { pad[j] = '\0'; str = strdup (""); } else { - str = r_asm_op_get_hex (&ds->asmop); - if (r_str_ansi_len (str) > ds->nb) { - char *p = (char *)r_str_ansi_chrn (str, ds->nb); + str = rz_asm_op_get_hex (&ds->asmop); + if (rz_str_ansi_len (str) > ds->nb) { + char *p = (char *)rz_str_ansi_chrn (str, ds->nb); if (p) { p[0] = '.'; p[1] = '\0'; } } ds->print->cur_enabled = (ds->cursor != -1); - nstr = r_print_hexpair (ds->print, str, ds->index); + nstr = rz_print_hexpair (ds->print, str, ds->index); if (ds->print->bytespace) { - k = (ds->nb + (ds->nb / 2)) - r_str_ansi_len (nstr) + 2; + k = (ds->nb + (ds->nb / 2)) - rz_str_ansi_len (nstr) + 2; } else { - k = ds->nb - r_str_ansi_len (nstr) + 1; + k = ds->nb - rz_str_ansi_len (nstr) + 1; } if (k > 0) { // setting to sizeof screw up the disasm @@ -3212,7 +3212,7 @@ static void ds_print_show_bytes(RDisasmState *ds) { str = nstr; } } - r_cons_printf ("%s%s %s", pad, str, extra); + rz_cons_printf ("%s%s %s", pad, str, extra); free (str); core->print->flags = oldFlags; } @@ -3229,30 +3229,30 @@ static void ds_print_indent(RDisasmState *ds) { } memset (indent, ' ', num); indent[num] = 0; - r_cons_strcat (indent); + rz_cons_strcat (indent); } } static void ds_print_optype(RDisasmState *ds) { if (ds->show_optype) { - const char *optype = r_anal_optype_to_string (ds->analop.type); + const char *optype = rz_anal_optype_to_string (ds->analop.type); ds_print_color_reset (ds); - const char *pad = r_str_pad (' ', 8 - strlen (optype)); - r_cons_printf ("[%s]%s", optype, pad); + const char *pad = rz_str_pad (' ', 8 - strlen (optype)); + rz_cons_printf ("[%s]%s", optype, pad); } } static void ds_print_opstr(RDisasmState *ds) { ds_print_indent (ds); if (ds->asm_instr) { - r_cons_strcat (ds->opstr); + rz_cons_strcat (ds->opstr); ds_print_color_reset (ds); } } static void ds_print_color_reset(RDisasmState *ds) { if (ds->show_color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } } @@ -3261,60 +3261,60 @@ static int ds_print_middle(RDisasmState *ds, int ret) { ret -= ds->middle; ds_align_comment (ds); if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } - r_cons_printf (" ; *middle* %d", ret); + rz_cons_printf (" ; *middle* %d", ret); if (ds->show_color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } } return ret; } -static bool ds_print_labels(RDisasmState *ds, RAnalFunction *f) { +static bool ds_print_labels(RDisasmState *ds, RzAnalFunction *f) { const char *label; if (!f) { - // f = r_anal_get_fcn_in (core->anal, ds->at, 0); + // f = rz_anal_get_fcn_in (core->anal, ds->at, 0); f = fcnIn (ds, ds->at, 0); } if (!f) { return false; } - label = r_anal_function_get_label_at (f, ds->at); + label = rz_anal_function_get_label_at (f, ds->at); if (!label) { return false; } ds_pre_line (ds); if (ds->show_color) { - r_cons_strcat (ds->color_label); - r_cons_printf (" .%s:\n", label); + rz_cons_strcat (ds->color_label); + rz_cons_printf (" .%s:\n", label); ds_print_color_reset (ds); } else { - r_cons_printf (" .%s:\n", label); + rz_cons_printf (" .%s:\n", label); } return true; } #if 0 static void ds_print_import_name(RDisasmState *ds) { - RListIter *iter = NULL; + RzListIter *iter = NULL; RBinReloc *rel = NULL; - RCore * core = ds->core; + RzCore * core = ds->core; switch (ds->analop.type) { case R_ANAL_OP_TYPE_JMP: case R_ANAL_OP_TYPE_CJMP: case R_ANAL_OP_TYPE_CALL: if (core->bin->cur->o->imports && core->bin->cur->o->relocs) { - r_list_foreach (core->bin->cur->o->relocs, iter, rel) { + rz_list_foreach (core->bin->cur->o->relocs, iter, rel) { if ((rel->vaddr == ds->analop.jump) && (rel->import != NULL)) { if (ds->show_color) { - r_cons_strcat (ds->color_fname); + rz_cons_strcat (ds->color_fname); } // TODO: handle somehow ordinals import ds_align_comment (ds); - r_cons_printf (" ; (imp.%s)", rel->import->name); + rz_cons_printf (" ; (imp.%s)", rel->import->name); ds_print_color_reset (ds); } } @@ -3324,7 +3324,7 @@ static void ds_print_import_name(RDisasmState *ds) { #endif static void ds_print_sysregs(RDisasmState *ds) { - RCore *core = ds->core; + RzCore *core = ds->core; if (!ds->show_comments) { return; } @@ -3333,8 +3333,8 @@ static void ds_print_sysregs(RDisasmState *ds) { case R_ANAL_OP_TYPE_IO: { const int imm = (int)ds->analop.val; - RSyscall *sc = core->anal->syscall; - const char *ioname = r_syscall_get_io (sc, imm); + RzSyscall *sc = core->anal->syscall; + const char *ioname = rz_syscall_get_io (sc, imm); if (ioname && *ioname) { _ALIGN; ds_comment (ds, true, "; IO %s", ioname); @@ -3349,7 +3349,7 @@ static void ds_print_sysregs(RDisasmState *ds) { case R_ANAL_OP_TYPE_STORE: { const int imm = (int)ds->analop.ptr; - const char *sr = r_syscall_sysreg (core->anal->syscall, "reg", imm); + const char *sr = rz_syscall_sysreg (core->anal->syscall, "reg", imm); if (sr) { _ALIGN; ds_comment (ds, true, "; REG %s - %s", sr, ""); @@ -3370,18 +3370,18 @@ static void ds_print_fcn_name(RDisasmState *ds) { && ds->analop.type != R_ANAL_OP_TYPE_CALL) { return; } - RAnalFunction *f = fcnIn (ds, ds->analop.jump, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *f = fcnIn (ds, ds->analop.jump, R_ANAL_FCN_TYPE_NULL); if (!f && ds->core->flags && (!ds->core->vmode || (!ds->subjmp && !ds->filter))) { const char *arch; - RFlagItem *flag = r_flag_get_by_spaces (ds->core->flags, ds->analop.jump, + RzFlagItem *flag = rz_flag_get_by_spaces (ds->core->flags, ds->analop.jump, R_FLAGS_FS_CLASSES, R_FLAGS_FS_SYMBOLS, NULL); if (flag && flag->name && ds->opstr && !strstr (ds->opstr, flag->name) - && (r_str_startswith (flag->name, "sym.") || r_str_startswith (flag->name, "method.")) - && (arch = r_config_get (ds->core->config, "asm.arch")) && strcmp (arch, "dalvik")) { - RFlagItem *flag_sym = flag; + && (rz_str_startswith (flag->name, "sym.") || rz_str_startswith (flag->name, "method.")) + && (arch = rz_config_get (ds->core->config, "asm.arch")) && strcmp (arch, "dalvik")) { + RzFlagItem *flag_sym = flag; if (ds->core->vmode && ds->asm_demangle - && (r_str_startswith (flag->name, "sym.") - || (flag_sym = r_flag_get_by_spaces (ds->core->flags, ds->analop.jump, + && (rz_str_startswith (flag->name, "sym.") + || (flag_sym = rz_flag_get_by_spaces (ds->core->flags, ds->analop.jump, R_FLAGS_FS_SYMBOLS, NULL))) && flag_sym->demangled) { return; @@ -3395,12 +3395,12 @@ static void ds_print_fcn_name(RDisasmState *ds) { return; } st64 delta = ds->analop.jump - f->addr; - const char *label = r_anal_function_get_label_at (f, ds->analop.jump); + const char *label = rz_anal_function_get_label_at (f, ds->analop.jump); if (label) { ds_begin_comment (ds); ds_comment (ds, true, "; %s.%s", f->name, label); } else { - RAnalFunction *f2 = fcnIn (ds, ds->at, 0); + RzAnalFunction *f2 = fcnIn (ds, ds->at, 0); if (f == f2) { return; } @@ -3412,9 +3412,9 @@ static void ds_print_fcn_name(RDisasmState *ds) { ds_comment (ds, true, "; %s-0x%x", f->name, -delta); } else if ((!ds->core->vmode || (!ds->subjmp && !ds->filter)) && (!ds->opstr || !strstr (ds->opstr, f->name))) { - RFlagItem *flag_sym; + RzFlagItem *flag_sym; if (ds->core->vmode && ds->asm_demangle - && (flag_sym = r_flag_get_by_spaces (ds->core->flags, ds->analop.jump, + && (flag_sym = rz_flag_get_by_spaces (ds->core->flags, ds->analop.jump, R_FLAGS_FS_SYMBOLS, NULL)) && flag_sym->demangled) { return; @@ -3426,7 +3426,7 @@ static void ds_print_fcn_name(RDisasmState *ds) { } static int ds_print_shortcut(RDisasmState *ds, ut64 addr, int pos) { - char *shortcut = r_core_add_asmqjmp (ds->core, addr); + char *shortcut = rz_core_add_asmqjmp (ds->core, addr); int slen = shortcut? strlen (shortcut): 0; if (ds->asm_hint_pos > 0) { if (pos) { @@ -3438,27 +3438,27 @@ static int ds_print_shortcut(RDisasmState *ds, ut64 addr, int pos) { ch = " "; } if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } if (*ch) { slen++; } if (shortcut) { if (ds->core->is_asmqjmps_letter) { - r_cons_printf ("%s[o%s]", ch, shortcut); + rz_cons_printf ("%s[o%s]", ch, shortcut); slen++; } else { - r_cons_printf ("%s[%s]", ch, shortcut); + rz_cons_printf ("%s[%s]", ch, shortcut); } free (shortcut); } else { - r_cons_printf ("%s[?]", ch); + rz_cons_printf ("%s[?]", ch); } if (ds->show_color) { if (ds->core->print->resetbg) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } else { - r_cons_strcat (Color_RESET_NOBG); + rz_cons_strcat (Color_RESET_NOBG); } } slen++; @@ -3466,28 +3466,28 @@ static int ds_print_shortcut(RDisasmState *ds, ut64 addr, int pos) { } static bool ds_print_core_vmode_jump_hit(RDisasmState *ds, int pos) { - RCore *core = ds->core; - RAnal *a = core->anal; - RAnalHint *hint = r_anal_hint_get (a, ds->at); + RzCore *core = ds->core; + RzAnal *a = core->anal; + RzAnalHint *hint = rz_anal_hint_get (a, ds->at); bool res = false; if (hint) { if (hint->jump != UT64_MAX) { ds_print_shortcut (ds, hint->jump, pos); res = true; } - r_anal_hint_free (hint); + rz_anal_hint_free (hint); } return res; } static void getPtr(RDisasmState *ds, ut64 addr, int pos) { ut8 buf[sizeof (ut64)] = {0}; - r_io_read_at (ds->core->io, addr, buf, sizeof (buf)); + rz_io_read_at (ds->core->io, addr, buf, sizeof (buf)); if (ds->core->rasm->bits == 64) { - ut64 n64 = r_read_ble64 (buf, 0); + ut64 n64 = rz_read_ble64 (buf, 0); ds_print_shortcut (ds, n64, pos); } else { - ut32 n32 = r_read_ble32 (buf, 0); + ut32 n32 = rz_read_ble32 (buf, 0); ds_print_shortcut (ds, n32, pos); } } @@ -3496,19 +3496,19 @@ static ut64 get_ptr_ble(RDisasmState *ds, ut64 addr, int pos) { ut8 buf[sizeof (ut64)] = {0}; int endian = ds->core->rasm->big_endian; ut64 n64_32; - r_io_read_at (ds->core->io, addr, buf, sizeof (buf)); + rz_io_read_at (ds->core->io, addr, buf, sizeof (buf)); if (ds->core->rasm->bits == 64) { - n64_32 = r_read_ble64 (buf, endian); + n64_32 = rz_read_ble64 (buf, endian); ds_print_shortcut (ds, n64_32, pos); } else { - n64_32 = r_read_ble32 (buf, endian); + n64_32 = rz_read_ble32 (buf, endian); ds_print_shortcut (ds, n64_32, pos); } return n64_32; } static bool ds_print_core_vmode(RDisasmState *ds, int pos) { - RCore *core = ds->core; + RzCore *core = ds->core; bool gotShortcut = false; int i, slen = 0; @@ -3520,7 +3520,7 @@ static bool ds_print_core_vmode(RDisasmState *ds, int pos) { } if (ds->asm_hint_emu) { if (ds->emuptr) { - if (r_io_is_valid_offset (core->io, ds->emuptr, 0)) { + if (rz_io_is_valid_offset (core->io, ds->emuptr, 0)) { ds_print_shortcut (ds, ds->emuptr, pos); //getPtr (ds, ds->emuptr, pos); ds->emuptr = 0; @@ -3532,7 +3532,7 @@ static bool ds_print_core_vmode(RDisasmState *ds, int pos) { } if (ds->asm_hint_lea) { ut64 size; - RAnalMetaItem *mi = r_meta_get_at (ds->core->anal, ds->at, R_META_TYPE_ANY, &size); + RzAnalMetaItem *mi = rz_meta_get_at (ds->core->anal, ds->at, R_META_TYPE_ANY, &size); if (mi) { int obits = ds->core->rasm->bits; ds->core->rasm->bits = size * 8; @@ -3569,10 +3569,10 @@ static bool ds_print_core_vmode(RDisasmState *ds, int pos) { #if 0 if (ds->analop.jump == 0 && ds->analop.ptr) { ut8 buf[sizeof(ut64)] = {0}; - r_io_read_at (core->io, ds->analop.ptr, buf, sizeof (buf)); - ut32 n32 = r_read_ble32 (buf, 0); + rz_io_read_at (core->io, ds->analop.ptr, buf, sizeof (buf)); + ut32 n32 = rz_read_ble32 (buf, 0); // is valid address - // ut32 n64 = r_read_ble32 (buf, 0); + // ut32 n64 = rz_read_ble32 (buf, 0); ds_print_shortcut (ds, n32, pos); } else { // ds_print_shortcut (ds, ds->analop.jump, pos); @@ -3619,10 +3619,10 @@ beach: if (ds->asm_hint_pos > 0) { const int begin = gotShortcut ? 2: 3; for (i = begin - slen; i > 0; i--) { - r_cons_strcat (" "); + rz_cons_strcat (" "); } } else if (ds->asm_hint_pos == 0 && !gotShortcut) { - r_cons_strcat (" "); + rz_cons_strcat (" "); } ds->hinted_line = gotShortcut; return gotShortcut; @@ -3637,7 +3637,7 @@ static void ds_begin_nl_comment(RDisasmState *ds) { ds_pre_xrefs (ds, false); } if (ds->show_color && (ds->cmtcount > 0 || ds->show_comment_right)) { - r_cons_printf (ds->pal_comment); + rz_cons_printf (ds->pal_comment); } } @@ -3647,20 +3647,20 @@ static void ds_align_comment(RDisasmState *ds) { return; } const int cmtcol = ds->cmtcol - 1; - const char *ll = r_cons_get_buffer (); + const char *ll = rz_cons_get_buffer (); if (!ll) { return; } ll += ds->buf_line_begin; - int cells = r_str_len_utf8_ansi (ll); + int cells = rz_str_len_utf8_ansi (ll); int cols = ds->interactive ? ds->core->cons->columns : 1024; if (cells < cmtcol) { int len = cmtcol - cells; if (len < cols && len > 0) { - r_cons_memset (' ', len); + rz_cons_memset (' ', len); } } - r_cons_print (" "); + rz_cons_print (" "); } static void ds_print_dwarf(RDisasmState *ds) { @@ -3672,18 +3672,18 @@ static void ds_print_dwarf(RDisasmState *ds) { // TODO: cache value in ds int dwarfFile = (int)ds->dwarfFile + (int)ds->dwarfAbspath; free (ds->sl); - ds->sl = r_bin_addr2text (ds->core->bin, ds->at, dwarfFile); + ds->sl = rz_bin_addr2text (ds->core->bin, ds->at, dwarfFile); if (ds->sl) { if ((!ds->osl || (ds->osl && strcmp (ds->sl, ds->osl)))) { char *line = strdup (ds->sl); if (!line) { return; } - r_str_replace_char (line, '\t', ' '); - r_str_replace_char (line, '\x1b', ' '); - r_str_replace_char (line, '\r', ' '); - r_str_replace_char (line, '\n', '\x00'); - r_str_trim (line); + rz_str_replace_char (line, '\t', ' '); + rz_str_replace_char (line, '\x1b', ' '); + rz_str_replace_char (line, '\r', ' '); + rz_str_replace_char (line, '\n', '\x00'); + rz_str_trim (line); if (!*line) { free (line); return; @@ -3691,9 +3691,9 @@ static void ds_print_dwarf(RDisasmState *ds) { // handle_set_pre (ds, " "); ds_align_comment (ds); if (ds->show_color) { - r_cons_printf ("%s; %s"Color_RESET, ds->pal_comment, line); + rz_cons_printf ("%s; %s"Color_RESET, ds->pal_comment, line); } else { - r_cons_printf ("; %s", line); + rz_cons_printf ("; %s", line); } free (ds->osl); ds->osl = ds->sl; @@ -3707,21 +3707,21 @@ static void ds_print_dwarf(RDisasmState *ds) { static void ds_print_asmop_payload(RDisasmState *ds, const ut8 *buf) { if (ds->show_varaccess) { // XXX assume analop is filled - //r_anal_op (core->anal, &ds->analop, ds->at, core->block+i, core->blocksize-i); + //rz_anal_op (core->anal, &ds->analop, ds->at, core->block+i, core->blocksize-i); int v = ds->analop.ptr; switch (ds->analop.stackop) { case R_ANAL_STACK_GET: if (v < 0) { - r_cons_printf (" ; local.get %d", -v); + rz_cons_printf (" ; local.get %d", -v); } else { - r_cons_printf (" ; arg.get %d", v); + rz_cons_printf (" ; arg.get %d", v); } break; case R_ANAL_STACK_SET: if (v < 0) { - r_cons_printf (" ; local.set %d", -v); + rz_cons_printf (" ; local.set %d", -v); } else { - r_cons_printf (" ; arg.set %d", v); + rz_cons_printf (" ; arg.set %d", v); } break; default: @@ -3729,15 +3729,15 @@ static void ds_print_asmop_payload(RDisasmState *ds, const ut8 *buf) { } } if (ds->asmop.payload != 0) { - r_cons_printf ("\n; .. payload of %d byte(s)", ds->asmop.payload); + rz_cons_printf ("\n; .. payload of %d byte(s)", ds->asmop.payload); if (ds->showpayloads) { int mod = ds->asmop.payload % ds->core->rasm->dataalign; int x; for (x = 0; x < ds->asmop.payload; x++) { - r_cons_printf ("\n 0x%02x", buf[ds->oplen + x]); + rz_cons_printf ("\n 0x%02x", buf[ds->oplen + x]); } for (x = 0; x < mod; x++) { - r_cons_printf ("\n 0x%02x ; alignment", buf[ds->oplen + ds->asmop.payload + x]); + rz_cons_printf ("\n 0x%02x ; alignment", buf[ds->oplen + ds->asmop.payload + x]); } } } @@ -3751,69 +3751,69 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char * bool esc_bslash = ds->core->print->esc_bslash; RStrEnc strenc = ds->strenc; if (strenc == R_STRING_ENC_GUESS) { - strenc = r_utf_bom_encoding ((ut8 *)str, len); + strenc = rz_utf_bom_encoding ((ut8 *)str, len); } switch (strenc) { case R_STRING_ENC_LATIN1: - escstr = r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment); + escstr = rz_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment); break; case R_STRING_ENC_UTF8: - escstr = r_str_escape_utf8 (str, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf8 (str, ds->show_asciidot, esc_bslash); break; case R_STRING_ENC_UTF16LE: - escstr = r_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash); prefix = "u"; break; case R_STRING_ENC_UTF32LE: - escstr = r_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash); prefix = "U"; break; case R_STRING_ENC_UTF16BE: - escstr = r_str_escape_utf16be (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf16be (str, len, ds->show_asciidot, esc_bslash); prefix = "ub"; break; case R_STRING_ENC_UTF32BE: - escstr = r_str_escape_utf32be (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf32be (str, len, ds->show_asciidot, esc_bslash); prefix = "Ub"; break; default: str_len = strlen (str); if ((str_len == 1 && len > 3 && str[2] && !str[3]) || (str_len == 3 && len > 5 && !memcmp (str, "\xff\xfe", 2) && str[4] && !str[5])) { - escstr = r_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf16le (str, len, ds->show_asciidot, esc_bslash); prefix = "u"; } else if (str_len == 1 && len > 7 && !str[2] && !str[3] && str[4] && !str[5]) { RStrEnc enc = R_STRING_ENC_UTF32LE; RRune ch; const char *ptr, *end; - end = (const char *)r_mem_mem_aligned ((ut8 *)str, len, (ut8 *)"\0\0\0\0", 4, 4); + end = (const char *)rz_mem_mem_aligned ((ut8 *)str, len, (ut8 *)"\0\0\0\0", 4, 4); if (!end) { end = str + len - 1; } for (ptr = str; ptr < end; ptr += 4) { - if (r_utf32le_decode ((ut8 *)ptr, end - ptr, &ch) > 0 && ch > 0x10ffff) { + if (rz_utf32le_decode ((ut8 *)ptr, end - ptr, &ch) > 0 && ch > 0x10ffff) { enc = R_STRING_ENC_LATIN1; break; } } if (enc == R_STRING_ENC_UTF32LE) { - escstr = r_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash); + escstr = rz_str_escape_utf32le (str, len, ds->show_asciidot, esc_bslash); prefix = "U"; } else { - escstr = r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment); + escstr = rz_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment); } } else { RStrEnc enc = R_STRING_ENC_LATIN1; const char *ptr = str, *end = str + str_len; for (; ptr < end; ptr++) { - if (r_utf8_decode ((ut8 *)ptr, end - ptr, NULL) > 1) { + if (rz_utf8_decode ((ut8 *)ptr, end - ptr, NULL) > 1) { enc = R_STRING_ENC_UTF8; break; } } escstr = (enc == R_STRING_ENC_UTF8 ? - r_str_escape_utf8 (str, ds->show_asciidot, esc_bslash) : - r_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment)); + rz_str_escape_utf8 (str, ds->show_asciidot, esc_bslash) : + rz_str_escape_latin1 (str, ds->show_asciidot, esc_bslash, is_comment)); } } if (prefix_out) { @@ -3823,12 +3823,12 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char * } static void ds_print_str(RDisasmState *ds, const char *str, int len, ut64 refaddr) { - if (ds->core->flags->realnames || !r_bin_string_filter (ds->core->bin, str, refaddr)) { + if (ds->core->flags->realnames || !rz_bin_string_filter (ds->core->bin, str, refaddr)) { return; } // do not resolve strings on arm64 pointed with ADRP if (ds->analop.type == R_ANAL_OP_TYPE_LEA) { - if (ds->core->rasm->bits == 64 && r_str_startswith (r_config_get (ds->core->config, "asm.arch"), "arm")) { + if (ds->core->rasm->bits == 64 && rz_str_startswith (rz_config_get (ds->core->config, "asm.arch"), "arm")) { return; } } @@ -3849,11 +3849,11 @@ static inline bool is_filtered_flag(RDisasmState *ds, const char *name) { return false; } ut64 refaddr = ds->analop.ptr; - const char *anal_flag = r_meta_get_string (ds->core->anal, R_META_TYPE_STRING, refaddr); + const char *anal_flag = rz_meta_get_string (ds->core->anal, R_META_TYPE_STRING, refaddr); if (anal_flag) { char *dupped = strdup (anal_flag); if (dupped) { - r_name_filter (dupped, -1); + rz_name_filter (dupped, -1); if (!strcmp (&name[4], dupped)) { return true; } @@ -3864,13 +3864,13 @@ static inline bool is_filtered_flag(RDisasmState *ds, const char *name) { /* convert numeric value in opcode to ascii char or number */ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { - RCore *core = ds->core; + RzCore *core = ds->core; ut64 p = ds->analop.ptr; ut64 v = ds->analop.val; ut64 refaddr = p; bool aligned = false; int refptr = ds->analop.refptr; - RFlagItem *f = NULL, *f2 = NULL; + RzFlagItem *f = NULL, *f2 = NULL; bool f2_in_opstr = false; /* Also if true, f exists */ if (!ds->show_comments || !ds->show_slow) { return; @@ -3885,7 +3885,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { if ((char)v > 0 && v >= '!') { ds->chref = (char)v; if (ds->immstr) { - char *str = r_str_from_ut64 (r_read_ble64 (&v, core->print->big_endian)); + char *str = rz_str_from_ut64 (rz_read_ble64 (&v, core->print->big_endian)); if (str && *str) { const char *ptr = str; bool printable = true; @@ -3895,7 +3895,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { break; } } - if (r_flag_get_i (core->flags, v)) { + if (rz_flag_get_i (core->flags, v)) { printable = false; } if (canHaveChar && printable) { @@ -3912,23 +3912,23 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } } } - RList *list = NULL; - RListIter *iter; - RAnalRef *ref; - list = r_anal_refs_get (core->anal, ds->at); - r_list_foreach (list, iter, ref) { + RzList *list = NULL; + RzListIter *iter; + RzAnalRef *ref; + list = rz_anal_refs_get (core->anal, ds->at); + rz_list_foreach (list, iter, ref) { if (ref->type == R_ANAL_REF_TYPE_STRING || ref->type == R_ANAL_REF_TYPE_DATA) { - if ((f = r_flag_get_i (core->flags, ref->addr))) { + if ((f = rz_flag_get_i (core->flags, ref->addr))) { refaddr = ref->addr; break; } } } - r_list_free (list); + rz_list_free (list); if (ds->analop.type == (R_ANAL_OP_TYPE_MOV | R_ANAL_OP_TYPE_REG) && ds->analop.stackop == R_ANAL_STACK_SET && ds->analop.val != UT64_MAX && ds->analop.val > 10) { - const char *arch = r_config_get (core->config, "asm.arch"); + const char *arch = rz_config_get (core->config, "asm.arch"); if (arch && !strcmp (arch, "x86")) { p = refaddr = ds->analop.val; refptr = 0; @@ -3943,11 +3943,11 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { const char *kind; char *msg = calloc (sizeof (char), len); if (((st64)p) > 0) { - f = r_flag_get_i (core->flags, p); + f = rz_flag_get_i (core->flags, p); if (f) { ut64 subrel_addr = core->parser->subrel_addr; if (subrel_addr && subrel_addr != p) { - f2 = r_core_flag_get_by_spaces (core->flags, subrel_addr); + f2 = rz_core_flag_get_by_spaces (core->flags, subrel_addr); f2_in_opstr = f2 && ds->opstr && (strstr (ds->opstr, f2->name) || strstr (ds->opstr, f2->realname)) ; } refaddr = p; @@ -3961,19 +3961,19 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } } } - r_io_read_at (core->io, refaddr, (ut8*)msg, len - 1); + rz_io_read_at (core->io, refaddr, (ut8*)msg, len - 1); if (refptr && ds->show_refptr) { - ut64 num = r_read_ble (msg, core->print->big_endian, refptr * 8); + ut64 num = rz_read_ble (msg, core->print->big_endian, refptr * 8); st64 n = (st64)num; st32 n32 = (st32)(n & UT32_MAX); if (ds->analop.type == R_ANAL_OP_TYPE_LEA) { char str[128] = {0}; - f = r_flag_get_i (core->flags, refaddr); + f = rz_flag_get_i (core->flags, refaddr); if (!f && ds->show_slow) { - r_io_read_at (ds->core->io, ds->analop.ptr, + rz_io_read_at (ds->core->io, ds->analop.ptr, (ut8 *)str, sizeof (str) - 1); str[sizeof (str) - 1] = 0; - if (!string_printed && str[0] && r_str_is_printable_incl_newlines (str)) { + if (!string_printed && str[0] && rz_str_is_printable_incl_newlines (str)) { ds_print_str (ds, str, sizeof (str), ds->analop.ptr); string_printed = true; } @@ -3990,18 +3990,18 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } else { const char *kind, *flag = ""; char *msg2 = NULL; - RFlagItem *f2_ = r_flag_get_i (core->flags, n); + RzFlagItem *f2_ = rz_flag_get_i (core->flags, n); if (f2_) { flag = f2_->name; } else { msg2 = calloc (sizeof (char), len); - r_io_read_at (core->io, n, (ut8*)msg2, len - 1); + rz_io_read_at (core->io, n, (ut8*)msg2, len - 1); msg2[len - 1] = 0; - kind = r_anal_data_kind (core->anal, refaddr, (const ut8*)msg2, len - 1); + kind = rz_anal_data_kind (core->anal, refaddr, (const ut8*)msg2, len - 1); if (kind && !strcmp (kind, "text")) { - r_str_filter (msg2, 0); + rz_str_filter (msg2, 0); if (*msg2) { - char *lala = r_str_newf ("\"%s\"", msg2); + char *lala = rz_str_newf ("\"%s\"", msg2); free (msg2); flag = msg2 = lala; } @@ -4011,8 +4011,8 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { { const char *refptrstr = ""; if (core->print->flags & R_PRINT_FLAGS_SECSUB) { - RBinObject *bo = r_bin_cur_object (core->bin); - RBinSection *s = bo? r_bin_get_section_at (bo, n, core->io->va): NULL; + RBinObject *bo = rz_bin_cur_object (core->bin); + RBinSection *s = bo? rz_bin_get_section_at (bo, n, core->io->va): NULL; if (s) { refptrstr = s->name; } @@ -4064,19 +4064,19 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { bool print_msg = true; #if 1 if (ds->strenc == R_STRING_ENC_GUESS - && r_utf_bom_encoding ((ut8 *)msg, len) == R_STRING_ENC_GUESS + && rz_utf_bom_encoding ((ut8 *)msg, len) == R_STRING_ENC_GUESS && !(IS_PRINTABLE (*msg) || IS_WHITECHAR (*msg))) { print_msg = false; } else { msg[len - 1] = 0; } #endif - f = r_flag_get_i (core->flags, refaddr); + f = rz_flag_get_i (core->flags, refaddr); if (f) { if (strlen (msg) != 1) { - char *msg2 = r_str_new (msg); + char *msg2 = rz_str_new (msg); if (msg2) { - r_str_filter (msg2, 0); + rz_str_filter (msg2, 0); if (!strncmp (msg2, "UH..", 4)) { print_msg = false; } @@ -4108,8 +4108,8 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } else if (refaddr > 10) { if ((st64)refaddr < 0) { // resolve local var if possible - RAnalFunction *fcn = r_anal_get_function_at (core->anal, ds->at); - RAnalVar *v = fcn ? r_anal_function_get_var (fcn, 'v', (int)refaddr) : NULL; + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, ds->at); + RzAnalVar *v = fcn ? rz_anal_function_get_var (fcn, 'v', (int)refaddr) : NULL; ds_begin_comment (ds); if (v) { ds_comment (ds, true, "; var %s", v->name); @@ -4117,7 +4117,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { ds_comment (ds, true, "; var %d", -(int)refaddr); } } else { - if (r_core_anal_address (core, refaddr) & R_ANAL_ADDR_TYPE_ASCII) { + if (rz_core_anal_address (core, refaddr) & R_ANAL_ADDR_TYPE_ASCII) { if (!string_printed && print_msg) { ds_print_str (ds, msg, len, refaddr); string_printed = true; @@ -4126,7 +4126,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } } //XXX this should be refactored with along the above - kind = r_anal_data_kind (core->anal, refaddr, (const ut8*)msg, len - 1); + kind = rz_anal_data_kind (core->anal, refaddr, (const ut8*)msg, len - 1); if (kind) { if (!strcmp (kind, "text")) { if (!string_printed && print_msg) { @@ -4149,7 +4149,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } } } else { - // r_cons_printf (" ; %s", kind); + // rz_cons_printf (" ; %s", kind); } // TODO: check for more data kinds } @@ -4159,7 +4159,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { ds_print_as_string (ds); } if (!ds->show_comment_right && ds->cmtcount > 0) { - const char *p = r_cons_get_buffer (); + const char *p = rz_cons_get_buffer (); if (p) { int l = strlen (p); if (p[l - 1] != '\n') { @@ -4169,7 +4169,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { } #if DEADCODE if (aligned && ds->show_color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } #endif } @@ -4178,14 +4178,14 @@ static void ds_print_demangled(RDisasmState *ds) { if (!ds->show_comments || !ds->asm_demangle) { return; } - RCore *core = ds->core; - RFlagItem *f; + RzCore *core = ds->core; + RzFlagItem *f; int optype = ds->analop.type & 0xFFFF; switch (optype) { case R_ANAL_OP_TYPE_JMP: case R_ANAL_OP_TYPE_UJMP: case R_ANAL_OP_TYPE_CALL: - f = r_flag_get_by_spaces (core->flags, ds->analop.jump, R_FLAGS_FS_SYMBOLS, NULL); + f = rz_flag_get_by_spaces (core->flags, ds->analop.jump, R_FLAGS_FS_SYMBOLS, NULL); if (f && f->demangled && f->realname && ds->opstr && !strstr (ds->opstr, f->realname)) { ds_begin_nl_comment (ds); ds_comment (ds, true, "; %s", f->realname); @@ -4198,61 +4198,61 @@ static void ds_print_relocs(RDisasmState *ds) { if (!ds->showrelocs || !ds->show_slow) { return; } - RCore *core = ds->core; - const char *lang = r_config_get (core->config, "bin.lang"); - bool demangle = r_config_get_i (core->config, "asm.demangle"); - bool keep_lib = r_config_get_i (core->config, "bin.demangle.libs"); - RBinReloc *rel = r_core_getreloc (core, ds->at, ds->analop.size); + RzCore *core = ds->core; + const char *lang = rz_config_get (core->config, "bin.lang"); + bool demangle = rz_config_get_i (core->config, "asm.demangle"); + bool keep_lib = rz_config_get_i (core->config, "bin.demangle.libs"); + RBinReloc *rel = rz_core_getreloc (core, ds->at, ds->analop.size); if (rel) { int cstrlen = 0; - char *ll = r_cons_lastline (&cstrlen); + char *ll = rz_cons_lastline (&cstrlen); if (!ll) { return; } - int ansilen = r_str_ansi_len (ll); - int utf8len = r_utf8_strlen ((const ut8*)ll); + int ansilen = rz_str_ansi_len (ll); + int utf8len = rz_utf8_strlen ((const ut8*)ll); int cells = utf8len - (cstrlen - ansilen); int len = ds->cmtcol - cells; - r_cons_memset (' ', len); + rz_cons_memset (' ', len); if (rel->import) { if (demangle) { - demname = r_bin_demangle (core->bin->cur, lang, rel->import->name, rel->vaddr, keep_lib); + demname = rz_bin_demangle (core->bin->cur, lang, rel->import->name, rel->vaddr, keep_lib); } - r_cons_printf ("; RELOC %d %s", rel->type, demname ? demname : rel->import->name); + rz_cons_printf ("; RELOC %d %s", rel->type, demname ? demname : rel->import->name); } else if (rel->symbol) { if (demangle) { - demname = r_bin_demangle (core->bin->cur, lang, rel->symbol->name, rel->symbol->vaddr, keep_lib); + demname = rz_bin_demangle (core->bin->cur, lang, rel->symbol->name, rel->symbol->vaddr, keep_lib); } - r_cons_printf ("; RELOC %d %s @ 0x%08" PFMT64x, + rz_cons_printf ("; RELOC %d %s @ 0x%08" PFMT64x, rel->type, demname ? demname : rel->symbol->name, rel->symbol->vaddr); if (rel->addend) { if (rel->addend > 0) { - r_cons_printf (" + 0x%" PFMT64x, rel->addend); + rz_cons_printf (" + 0x%" PFMT64x, rel->addend); } else { - r_cons_printf (" - 0x%" PFMT64x, -rel->addend); + rz_cons_printf (" - 0x%" PFMT64x, -rel->addend); } } } else { - r_cons_printf ("; RELOC %d ", rel->type); + rz_cons_printf ("; RELOC %d ", rel->type); } free (demname); } } -static int mymemwrite0(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int mymemwrite0(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { return 0; } -static int mymemwrite1(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int mymemwrite1(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { return 1; } -static int mymemwrite2(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int mymemwrite2(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { return (addr >= emustack_min && addr < emustack_max); } -static char *ssa_get(RAnalEsil *esil, const char *reg) { +static char *ssa_get(RzAnalEsil *esil, const char *reg) { RDisasmState *ds = esil->user; if (isdigit (*reg)) { return strdup (reg); @@ -4261,16 +4261,16 @@ static char *ssa_get(RAnalEsil *esil, const char *reg) { ds->ssa = sdb_new0 (); } int n = sdb_num_get (ds->ssa, reg, NULL); - return r_str_newf ("%s_%d", reg, n); + return rz_str_newf ("%s_%d", reg, n); } -static void ssa_set(RAnalEsil *esil, const char *reg) { +static void ssa_set(RzAnalEsil *esil, const char *reg) { RDisasmState *ds = esil->user; (void)sdb_num_inc (ds->ssa, reg, 1, 0); } #define R_DISASM_MAX_STR 512 -static int myregread(RAnalEsil *esil, const char *name, ut64 *res, int *size) { +static int myregread(RzAnalEsil *esil, const char *name, ut64 *res, int *size) { RDisasmState *ds = esil->user; if (ds && ds->show_emu_ssa) { if (!isdigit (*name)) { @@ -4282,7 +4282,7 @@ static int myregread(RAnalEsil *esil, const char *name, ut64 *res, int *size) { return 0; } -static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { +static int myregwrite(RzAnalEsil *esil, const char *name, ut64 *val) { char str[64], *msg = NULL; ut32 *n32 = (ut32*)str; RDisasmState *ds = esil->user; @@ -4309,7 +4309,7 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { if (*val) { bool emu_str_printed = false; char *type = NULL; - (void)r_io_read_at (esil->anal->iob.io, *val, (ut8*)str, sizeof (str)-1); + (void)rz_io_read_at (esil->anal->iob.io, *val, (ut8*)str, sizeof (str)-1); str[sizeof (str) - 1] = 0; ds->emuptr = *val; // support cstring here @@ -4324,21 +4324,21 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { if (!(*val >> 32)) { addr = addr & UT32_MAX; } - (void)r_io_read_at (esil->anal->iob.io, addr, + (void)rz_io_read_at (esil->anal->iob.io, addr, (ut8*)str, sizeof (str)-1); // eprintf ("IS CSTRING 0x%llx %s\n", addr, str); - type = r_str_newf ("(cstr 0x%08"PFMT64x") ", addr); + type = rz_str_newf ("(cstr 0x%08"PFMT64x") ", addr); ds->printed_str_addr = cstr[2]; - } else if (r_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { + } else if (rz_io_is_valid_offset (esil->anal->iob.io, addr, 0)) { ds->printed_str_addr = cstr[0]; - type = r_str_newf ("(pstr 0x%08"PFMT64x") ", addr); - (void)r_io_read_at (esil->anal->iob.io, addr, + type = rz_str_newf ("(pstr 0x%08"PFMT64x") ", addr); + (void)rz_io_read_at (esil->anal->iob.io, addr, (ut8*)str, sizeof (str) - 1); // eprintf ("IS PSTRING 0x%llx %s\n", addr, str); } } - if (*str && !r_bin_strpurge (ds->core->bin, str, *val) && r_str_is_printable_incl_newlines (str) + if (*str && !rz_bin_strpurge (ds->core->bin, str, *val) && rz_str_is_printable_incl_newlines (str) && (ds->printed_str_addr == UT64_MAX || *val != ds->printed_str_addr)) { bool jump_op = false; bool ignored = false; @@ -4358,7 +4358,7 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { ignored = true; break; case R_ANAL_OP_TYPE_LEA: - if (ds->core->rasm->bits == 64 && r_str_startswith (r_config_get (ds->core->config, "asm.arch"), "arm")) { + if (ds->core->rasm->bits == 64 && rz_str_startswith (rz_config_get (ds->core->config, "asm.arch"), "arm")) { ignored = true; } break; @@ -4367,7 +4367,7 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { const char *prefix; ut32 len = sizeof (str) -1; #if 0 - RCore *core = ds->core; + RzCore *core = ds->core; ut32 len = core->blocksize + 256; if (len < core->blocksize || len > R_DISASM_MAX_STR) { len = R_DISASM_MAX_STR; @@ -4379,13 +4379,13 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { char *m; if (ds->show_color) { bool inv = ds->show_emu_strinv; - m = r_str_newf ("%s%s%s\"%s\"%s", + m = rz_str_newf ("%s%s%s\"%s\"%s", prefix, type ? type : "", inv ? Color_INVERT : "", escstr, inv ? Color_INVERT_RESET : ""); } else { - m = r_str_newf ("%s%s\"%s\"", prefix, type? type: "", escstr); + m = rz_str_newf ("%s%s\"%s\"", prefix, type? type: "", escstr); } - msg = r_str_append_owned (msg, m); + msg = rz_str_append_owned (msg, m); emu_str_printed = true; free (escstr); } @@ -4397,16 +4397,16 @@ static int myregwrite(RAnalEsil *esil, const char *name, ut64 *val) { /* nothing */ } else { if (!ds->show_emu_str) { - msg = r_str_appendf (msg, "-> 0x%x", *n32); + msg = rz_str_appendf (msg, "-> 0x%x", *n32); } } } R_FREE (type); if ((ds->printed_flag_addr == UT64_MAX || *val != ds->printed_flag_addr) && (ds->show_emu_strflag || !emu_str_printed)) { - RFlagItem *fi = r_flag_get_i (esil->anal->flb.f, *val); + RzFlagItem *fi = rz_flag_get_i (esil->anal->flb.f, *val); if (fi && (!ds->opstr || !strstr (ds->opstr, fi->name))) { - msg = r_str_appendf (msg, "%s%s", msg && *msg ? " " : "", fi->name); + msg = rz_str_appendf (msg, "%s%s", msg && *msg ? " " : "", fi->name); } } } @@ -4441,15 +4441,15 @@ static void ds_pre_emulation(RDisasmState *ds) { if (!ds->pre_emu) { return; } - RFlagItem *f = r_flag_get_at (ds->core->flags, ds->core->offset, true); + RzFlagItem *f = rz_flag_get_at (ds->core->flags, ds->core->offset, true); if (!f) { return; } ut64 base = f->offset; - RAnalEsil *esil = ds->core->anal->esil; + RzAnalEsil *esil = ds->core->anal->esil; int i, end = ds->core->offset - base; int maxemu = 1024 * 1024; - RAnalEsilHookRegWriteCB orig_cb = esil->cb.hook_reg_write; + RzAnalEsilHookRegWriteCB orig_cb = esil->cb.hook_reg_write; if (end < 0 || end > maxemu) { return; } @@ -4457,29 +4457,29 @@ static void ds_pre_emulation(RDisasmState *ds) { esil->cb.hook_reg_write = NULL; for (i = 0; i < end; i++) { ut64 addr = base + i; - RAnalOp* op = r_core_anal_op (ds->core, addr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); + RzAnalOp* op = rz_core_anal_op (ds->core, addr, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); if (op) { if (do_esil) { - r_anal_esil_set_pc (esil, addr); - r_anal_esil_parse (esil, R_STRBUF_SAFEGET (&op->esil)); + rz_anal_esil_set_pc (esil, addr); + rz_anal_esil_parse (esil, R_STRBUF_SAFEGET (&op->esil)); if (op->size > 0) { i += op->size - 1; } } ds_update_stackptr (ds, op); - r_anal_op_free (op); + rz_anal_op_free (op); } } esil->cb.hook_reg_write = orig_cb; } static void ds_print_esil_anal_init(RDisasmState *ds) { - RCore *core = ds->core; - const char *pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + RzCore *core = ds->core; + const char *pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); if (!pc) { return; } - ds->esil_old_pc = r_reg_getv (core->anal->reg, pc); + ds->esil_old_pc = rz_reg_getv (core->anal->reg, pc); if (!ds->esil_old_pc || ds->esil_old_pc == UT64_MAX) { ds->esil_old_pc = core->offset; } @@ -4488,24 +4488,24 @@ static void ds_print_esil_anal_init(RDisasmState *ds) { return; } if (!core->anal->esil) { - int iotrap = r_config_get_i (core->config, "esil.iotrap"); - int esd = r_config_get_i (core->config, "esil.stack.depth"); - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + int iotrap = rz_config_get_i (core->config, "esil.iotrap"); + int esd = rz_config_get_i (core->config, "esil.stack.depth"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); - if (!(core->anal->esil = r_anal_esil_new (esd, iotrap, addrsize))) { + if (!(core->anal->esil = rz_anal_esil_new (esd, iotrap, addrsize))) { R_FREE (ds->esil_regstate); return; } - r_anal_esil_setup (core->anal->esil, core->anal, 0, 0, 1); + rz_anal_esil_setup (core->anal->esil, core->anal, 0, 0, 1); } core->anal->esil->user = ds; free (ds->esil_regstate); R_FREE (core->anal->last_disasm_reg); if (core->anal->gp) { - r_reg_setv (core->anal->reg, "gp", core->anal->gp); + rz_reg_setv (core->anal->reg, "gp", core->anal->gp); } - ds->esil_regstate = r_reg_arena_peek (core->anal->reg); - RRegSet *regset = r_reg_regset_get (core->anal->reg, R_REG_TYPE_GPR); + ds->esil_regstate = rz_reg_arena_peek (core->anal->reg); + RzRegSet *regset = rz_reg_regset_get (core->anal->reg, R_REG_TYPE_GPR); if (ds->esil_regstate && regset) { ds->esil_regstate_size = regset->arena->size; } @@ -4516,10 +4516,10 @@ static void ds_print_esil_anal_init(RDisasmState *ds) { static void ds_print_bbline(RDisasmState *ds) { if (ds->show_bbline && ds->at) { - RAnalBlock *bb = NULL; - RAnalFunction *f_before = NULL; + RzAnalBlock *bb = NULL; + RzAnalFunction *f_before = NULL; if (ds->fcn) { - bb = r_anal_fcn_bbget_at (ds->core->anal, ds->fcn, ds->at); + bb = rz_anal_fcn_bbget_at (ds->core->anal, ds->fcn, ds->at); } else { f_before = fcnIn (ds, ds->at - 1, R_ANAL_FCN_TYPE_NULL); } @@ -4546,35 +4546,35 @@ static void ds_print_bbline(RDisasmState *ds) { reflinecol = ds->prev_line_col; ds_print_ref_lines (refline, reflinecol, ds); } - r_cons_printf ("|"); + rz_cons_printf ("|"); ds_newline (ds); } } } -static void print_fcn_arg(RCore *core, const char *type, const char *name, +static void print_fcn_arg(RzCore *core, const char *type, const char *name, const char *fmt, const ut64 addr, const int on_stack, int asm_types) { if (on_stack == 1 && asm_types > 1) { - r_cons_printf ("%s", type); + rz_cons_printf ("%s", type); } if (addr != UT32_MAX && addr != UT64_MAX && addr != 0) { - char *res = r_core_cmd_strf (core, "pf%s %s%s %s @ 0x%08" PFMT64x, + char *res = rz_core_cmd_strf (core, "pf%s %s%s %s @ 0x%08" PFMT64x, (asm_types==2)? "": "q", (on_stack == 1) ? "*" : "", fmt, name, addr); - r_str_trim (res); - r_cons_printf ("%s", res); + rz_str_trim (res); + rz_cons_printf ("%s", res); free (res); } else { - r_cons_printf ("-1"); + rz_cons_printf ("-1"); } - r_cons_chop (); + rz_cons_chop (); } static void delete_last_comment(RDisasmState *ds) { if (!ds->show_comment_right_default) { return; } - const char *ll = r_cons_get_buffer (); + const char *ll = rz_cons_get_buffer (); if (!ll) { return; } @@ -4586,43 +4586,43 @@ static void delete_last_comment(RDisasmState *ds) { } } -static bool can_emulate_metadata(RCore *core, ut64 at) { +static bool can_emulate_metadata(RzCore *core, ut64 at) { // check if there is a meta at the addr that is unemulateable - const char *emuskipmeta = r_config_get (core->config, "emu.skip"); + const char *emuskipmeta = rz_config_get (core->config, "emu.skip"); bool ret = true; - RPVector *metas = r_meta_get_all_at (core->anal, at); + RPVector *metas = rz_meta_get_all_at (core->anal, at); void **it; - r_pvector_foreach (metas, it) { - RAnalMetaItem *item = ((RIntervalNode *)*it)->data; + rz_pvector_foreach (metas, it) { + RzAnalMetaItem *item = ((RIntervalNode *)*it)->data; if (strchr (emuskipmeta, (char)item->type)) { ret = false; break; } } - r_pvector_free (metas); + rz_pvector_free (metas); return ret; } static void mipsTweak(RDisasmState *ds) { - RCore *core = ds->core; - const char *asm_arch = r_config_get (core->config, "asm.arch"); + RzCore *core = ds->core; + const char *asm_arch = rz_config_get (core->config, "asm.arch"); if (asm_arch && *asm_arch && strstr (asm_arch, "mips")) { - if (r_config_get_i (core->config, "anal.gpfixed")) { - ut64 gp = r_config_get_i (core->config, "anal.gp"); - r_reg_setv (core->anal->reg, "gp", gp); + if (rz_config_get_i (core->config, "anal.gpfixed")) { + ut64 gp = rz_config_get_i (core->config, "anal.gp"); + rz_reg_setv (core->anal->reg, "gp", gp); } } } // modifies anal register state static void ds_print_esil_anal(RDisasmState *ds) { - RCore *core = ds->core; - RAnalEsil *esil = core->anal->esil; + RzCore *core = ds->core; + RzAnalEsil *esil = core->anal->esil; const char *pc; - int (*hook_mem_write)(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) = NULL; + int (*hook_mem_write)(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) = NULL; int i, nargs; - ut64 at = r_core_pava (core, ds->at); - RConfigHold *hc = r_config_hold_new (core->config); + ut64 at = rz_core_pava (core, ds->at); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { return; } @@ -4637,12 +4637,12 @@ static void ds_print_esil_anal(RDisasmState *ds) { goto beach; } if (ds->show_color) { - r_cons_strcat (ds->pal_comment); + rz_cons_strcat (ds->pal_comment); } esil = core->anal->esil; - pc = r_reg_get_name (core->anal->reg, R_REG_NAME_PC); + pc = rz_reg_get_name (core->anal->reg, R_REG_NAME_PC); if (pc) { - r_reg_setv (core->anal->reg, pc, at + ds->analop.size); + rz_reg_setv (core->anal->reg, pc, at + ds->analop.size); esil->cb.user = ds; esil->cb.hook_reg_write = myregwrite; esil->cb.hook_reg_read = myregread; @@ -4661,12 +4661,12 @@ static void ds_print_esil_anal(RDisasmState *ds) { const char *esilstr = R_STRBUF_SAFEGET (&ds->analop.esil); if (R_STR_ISNOTEMPTY (esilstr)) { mipsTweak (ds); - r_anal_esil_set_pc (esil, at); - r_anal_esil_parse (esil, esilstr); + rz_anal_esil_set_pc (esil, at); + rz_anal_esil_parse (esil, esilstr); } - r_anal_esil_stack_free (esil); - r_config_hold_i (hc, "io.cache", NULL); - r_config_set (core->config, "io.cache", "true"); + rz_anal_esil_stack_free (esil); + rz_config_hold_i (hc, "io.cache", NULL); + rz_config_set (core->config, "io.cache", "true"); if (!ds->show_comments) { goto beach; } @@ -4684,8 +4684,8 @@ static void ds_print_esil_anal(RDisasmState *ds) { case R_ANAL_OP_TYPE_JMP: { ut64 addr = ds->analop.jump; - if (!r_anal_get_function_at (ds->core->anal, addr) - && !r_flag_get_at (core->flags, addr, false)) { + if (!rz_anal_get_function_at (ds->core->anal, addr) + && !rz_flag_get_at (core->flags, addr, false)) { break; } } @@ -4695,10 +4695,10 @@ static void ds_print_esil_anal(RDisasmState *ds) { case R_ANAL_OP_TYPE_IRCALL: case R_ANAL_OP_TYPE_CALL: { - RAnalFunction *fcn; - RAnalFuncArg *arg; - RListIter *iter; - RListIter *nextele; + RzAnalFunction *fcn; + RzAnalFuncArg *arg; + RzListIter *iter; + RzListIter *nextele; const char *fcn_name = NULL; char *key = NULL; ut64 pcv = ds->analop.jump; @@ -4708,17 +4708,17 @@ static void ds_print_esil_anal(RDisasmState *ds) { if (pcv == UT64_MAX) { pcv = ds->analop.ptr; // call [reloc-addr] // windows style if (pcv == UT64_MAX || !pcv) { - r_anal_esil_reg_read (esil, "$jt", &pcv, NULL); + rz_anal_esil_reg_read (esil, "$jt", &pcv, NULL); if (pcv == UT64_MAX || !pcv) { - pcv = r_reg_getv (core->anal->reg, pc); + pcv = rz_reg_getv (core->anal->reg, pc); } } } - fcn = r_anal_get_function_at (core->anal, pcv); + fcn = rz_anal_get_function_at (core->anal, pcv); if (fcn) { fcn_name = fcn->name; } else { - RFlagItem *item = r_flag_get_i (core->flags, pcv); + RzFlagItem *item = rz_flag_get_i (core->flags, pcv); if (item) { fcn_name = item->name; } @@ -4730,16 +4730,16 @@ static void ds_print_esil_anal(RDisasmState *ds) { if (ds->asm_types < 1) { break; } - const char *fcn_type = r_type_func_ret (core->anal->sdb_types, key); - int nargs = r_type_func_args_count (core->anal->sdb_types, key); + const char *fcn_type = rz_type_func_ret (core->anal->sdb_types, key); + int nargs = rz_type_func_args_count (core->anal->sdb_types, key); // remove other comments delete_last_comment (ds); // ds_comment_start (ds, ""); ds_comment_esil (ds, true, false, "%s", ds->show_color ? ds->pal_comment : ""); if (fcn_type) { - ds_comment_middle (ds, "; %s%s%s(", r_str_get (fcn_type), + ds_comment_middle (ds, "; %s%s%s(", rz_str_get (fcn_type), (*fcn_type && fcn_type[strlen (fcn_type) - 1] == '*') ? "" : " ", - r_str_get (key)); + rz_str_get (key)); if (!nargs) { ds_comment_end (ds, "void)"); break; @@ -4747,15 +4747,15 @@ static void ds_print_esil_anal(RDisasmState *ds) { } } ut64 s_width = (core->anal->bits == 64)? 8: 4; - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - ut64 spv = r_reg_getv (core->anal->reg, sp); - r_reg_setv (core->anal->reg, sp, spv + s_width); // temporarily set stack ptr to sync with carg.c - RList *list = r_core_get_func_args (core, fcn_name); - if (!r_list_empty (list)) { + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + ut64 spv = rz_reg_getv (core->anal->reg, sp); + rz_reg_setv (core->anal->reg, sp, spv + s_width); // temporarily set stack ptr to sync with carg.c + RzList *list = rz_core_get_func_args (core, fcn_name); + if (!rz_list_empty (list)) { bool warning = false; bool on_stack = false; - r_list_foreach (list, iter, arg) { - if (arg->cc_source && r_str_startswith (arg->cc_source, "stack")) { + rz_list_foreach (list, iter, arg) { + if (arg->cc_source && rz_str_startswith (arg->cc_source, "stack")) { on_stack = true; } if (!arg->size) { @@ -4764,7 +4764,7 @@ static void ds_print_esil_anal(RDisasmState *ds) { } warning = true; } - nextele = r_list_iter_get_next (iter); + nextele = rz_list_iter_get_next (iter); if (!arg->fmt) { if (ds->asm_types > 1) { if (warning) { @@ -4783,18 +4783,18 @@ static void ds_print_esil_anal(RDisasmState *ds) { } } ds_comment_end (ds, ""); - r_list_free (list); + rz_list_free (list); break; } else { - r_list_free (list); + rz_list_free (list); // function name not resolved - r_warn_if_fail (!key); + rz_warn_if_fail (!key); nargs = DEFAULT_NARGS; if (fcn) { // @TODO: fcn->nargs should be updated somewhere and used here instead - nargs = r_anal_var_count (core->anal, fcn, 's', 1) + - r_anal_var_count (core->anal, fcn, 'b', 1) + - r_anal_var_count (core->anal, fcn, 'r', 1); + nargs = rz_anal_var_count (core->anal, fcn, 's', 1) + + rz_anal_var_count (core->anal, fcn, 'b', 1) + + rz_anal_var_count (core->anal, fcn, 'r', 1); } if (nargs > 0) { ds_comment_esil (ds, true, false, "%s", ds->show_color ? ds->pal_comment : ""); @@ -4804,13 +4804,13 @@ static void ds_print_esil_anal(RDisasmState *ds) { ds_comment_middle (ds, "; 0x%"PFMT64x"(", pcv); } for (i = 0; i < nargs; i++) { - ut64 v = r_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i); + ut64 v = rz_debug_arg_get (core->dbg, R_ANAL_CC_TYPE_FASTCALL, i); ds_comment_middle (ds, "%s0x%"PFMT64x, i?", ":"", v); } ds_comment_end (ds, ")"); } } - r_reg_setv (core->anal->reg, sp, spv); // reset stack ptr + rz_reg_setv (core->anal->reg, sp, spv); // reset stack ptr } break; } @@ -4819,29 +4819,29 @@ beach: if (esil) { esil->cb.hook_mem_write = hook_mem_write; } - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); } static void ds_print_calls_hints(RDisasmState *ds) { - int emu = r_config_get_i (ds->core->config, "asm.emu"); - int emuwrite = r_config_get_i (ds->core->config, "emu.write"); + int emu = rz_config_get_i (ds->core->config, "asm.emu"); + int emuwrite = rz_config_get_i (ds->core->config, "emu.write"); if (emu && emuwrite) { // this is done by ESIL return; } - RAnal *anal = ds->core->anal; + RzAnal *anal = ds->core->anal; Sdb *TDB = anal->sdb_types; char *name; char *full_name = NULL; if (ds->analop.type == R_ANAL_OP_TYPE_CALL) { - // RAnalFunction *fcn = r_anal_get_fcn_in (anal, ds->analop.jump, -1); - RAnalFunction *fcn = fcnIn (ds, ds->analop.jump, -1); + // RzAnalFunction *fcn = rz_anal_get_fcn_in (anal, ds->analop.jump, -1); + RzAnalFunction *fcn = fcnIn (ds, ds->analop.jump, -1); if (fcn) { full_name = fcn->name; } } else if (ds->analop.ptr != UT64_MAX) { - RFlagItem *flag = r_flag_get_i (ds->core->flags, ds->analop.ptr); + RzFlagItem *flag = rz_flag_get_i (ds->core->flags, ds->analop.ptr); if (flag && flag->space && !strcmp (flag->space->name, R_FLAGS_FS_IMPORTS)) { full_name = flag->realname; } @@ -4849,33 +4849,33 @@ static void ds_print_calls_hints(RDisasmState *ds) { if (!full_name) { return; } - if (r_type_func_exist (TDB, full_name)) { + if (rz_type_func_exist (TDB, full_name)) { name = strdup (full_name); - } else if (!(name = r_type_func_guess (TDB, full_name))) { + } else if (!(name = rz_type_func_guess (TDB, full_name))) { return; } ds_begin_comment (ds); - const char *fcn_type = r_type_func_ret (TDB, name); + const char *fcn_type = rz_type_func_ret (TDB, name); if (!fcn_type || !*fcn_type) { free (name); return; } - char *cmt = r_str_newf ("; %s%s%s(", fcn_type, + char *cmt = rz_str_newf ("; %s%s%s(", fcn_type, fcn_type[strlen (fcn_type) - 1] == '*' ? "" : " ", name); - int i, arg_max = r_type_func_args_count (TDB, name); + int i, arg_max = rz_type_func_args_count (TDB, name); if (!arg_max) { - cmt = r_str_append (cmt, "void)"); + cmt = rz_str_append (cmt, "void)"); } else { for (i = 0; i < arg_max; i++) { - char *type = r_type_func_args_type (TDB, name, i); - const char *tname = r_type_func_args_name (TDB, name, i); + char *type = rz_type_func_args_type (TDB, name, i); + const char *tname = rz_type_func_args_name (TDB, name, i); if (type && *type) { - cmt = r_str_appendf (cmt, "%s%s%s%s%s", i == 0 ? "": " ", type, + cmt = rz_str_appendf (cmt, "%s%s%s%s%s", i == 0 ? "": " ", type, type[strlen (type) - 1] == '*' ? "": " ", tname, i == arg_max - 1 ? ")": ","); } else if (tname && !strcmp (tname, "...")) { - cmt = r_str_appendf (cmt, "%s%s%s", i == 0 ? "": " ", + cmt = rz_str_appendf (cmt, "%s%s%s", i == 0 ? "": " ", tname, i == arg_max - 1 ? ")": ","); } free (type); @@ -4889,16 +4889,16 @@ static void ds_print_calls_hints(RDisasmState *ds) { static void ds_print_comments_right(RDisasmState *ds) { char *desc = NULL; - RCore *core = ds->core; + RzCore *core = ds->core; ds_print_relocs (ds); bool is_code = (!ds->hint) || (ds->hint && ds->hint->type != 'd'); - RAnalMetaItem *mi = r_meta_get_at (ds->core->anal, ds->at, R_META_TYPE_ANY, NULL); + RzAnalMetaItem *mi = rz_meta_get_at (ds->core->anal, ds->at, R_META_TYPE_ANY, NULL); if (mi) { is_code = mi->type != 'd'; mi = NULL; } if (is_code && ds->asm_describe && !ds->has_description) { - char *op, *locase = strdup (r_asm_op_get_asm (&ds->asmop)); + char *op, *locase = strdup (rz_asm_op_get_asm (&ds->asmop)); if (!locase) { return; } @@ -4906,23 +4906,23 @@ static void ds_print_comments_right(RDisasmState *ds) { if (op) { *op = 0; } - r_str_case (locase, 0); - desc = r_asm_describe (core->rasm, locase); + rz_str_case (locase, 0); + desc = rz_asm_describe (core->rasm, locase); free (locase); } if (ds->show_usercomments || ds->show_comments) { if (desc && *desc) { ds_align_comment (ds); if (ds->show_color) { - r_cons_strcat (ds->color_comment); + rz_cons_strcat (ds->color_comment); } - r_cons_strcat ("; "); - r_cons_strcat (desc); + rz_cons_strcat ("; "); + rz_cons_strcat (desc); ds_print_color_reset (ds); } if (ds->show_comment_right && ds->comment) { char *comment = ds->comment; - r_str_trim (comment); + rz_str_trim (comment); if (*comment) { if (!desc) { ds_align_comment (ds); @@ -4933,16 +4933,16 @@ static void ds_print_comments_right(RDisasmState *ds) { ds_newline (ds); ds_begin_line (ds); size_t lines_count; - size_t *line_indexes = r_str_split_lines (comment, &lines_count); + size_t *line_indexes = rz_str_split_lines (comment, &lines_count); if (line_indexes) { int i; for (i = 0; i < lines_count; i++) { char *c = comment + line_indexes[i]; ds_print_pre (ds, true); if (ds->show_color) { - r_cons_strcat (ds->color_usrcmt); + rz_cons_strcat (ds->color_usrcmt); } - r_cons_printf (i == 0 ? "%s" : "; %s", c); + rz_cons_printf (i == 0 ? "%s" : "; %s", c); if (i < lines_count - 1) { ds_newline (ds); ds_begin_line (ds); @@ -4954,11 +4954,11 @@ static void ds_print_comments_right(RDisasmState *ds) { free (comment); } else { if (comment) { - r_cons_strcat (comment); + rz_cons_strcat (comment); } } } - //r_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';'); + //rz_cons_strcat_justify (comment, strlen (ds->refline) + 5, ';'); ds_print_color_reset (ds); R_FREE (ds->comment); } @@ -4970,7 +4970,7 @@ static void ds_print_comments_right(RDisasmState *ds) { } static void ds_print_as_string(RDisasmState *ds) { - char *str = r_num_as_string (NULL, ds->analop.ptr, true); + char *str = rz_num_as_string (NULL, ds->analop.ptr, true); if (str) { ds_comment (ds, false, "%s; \"%s\"%s", COLOR (ds, pal_comment), str, COLOR_RESET (ds)); @@ -5011,7 +5011,7 @@ static char *_find_next_number(char *op) { } static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, const char **name) { - RFlag *f = ds->core->flags; + RzFlag *f = ds->core->flags; if (!f) { return false; } @@ -5019,7 +5019,7 @@ static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, cons // nothing to do, neither demangled nor regular realnames should be shown return false; } - RFlagItem *flag_sym = r_flag_get_by_spaces (f, addr, R_FLAGS_FS_SYMBOLS, NULL); + RzFlagItem *flag_sym = rz_flag_get_by_spaces (f, addr, R_FLAGS_FS_SYMBOLS, NULL); if (!flag_sym || !flag_sym->realname) { // nothing to replace return false; @@ -5029,10 +5029,10 @@ static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, cons return false; } *name = flag_sym->realname; - RFlagItem *flag_mthd = r_flag_get_by_spaces (f, addr, R_FLAGS_FS_CLASSES, NULL); + RzFlagItem *flag_mthd = rz_flag_get_by_spaces (f, addr, R_FLAGS_FS_CLASSES, NULL); if (!f->realnames) { // for asm.flags.real, we don't want these prefixes - if (flag_mthd && flag_mthd->name && r_str_startswith (flag_mthd->name, "method.")) { + if (flag_mthd && flag_mthd->name && rz_str_startswith (flag_mthd->name, "method.")) { *kw = "method "; } else { *kw = "sym "; @@ -5041,10 +5041,10 @@ static bool set_jump_realname(RDisasmState *ds, ut64 addr, const char **kw, cons return true; } -// TODO: this should be moved into r_parse +// TODO: this should be moved into rz_parse static char *ds_sub_jumps(RDisasmState *ds, char *str) { - RAnal *anal = ds->core->anal; - RFlag *f = ds->core->flags; + RzAnal *anal = ds->core->anal; + RzFlag *f = ds->core->flags; const char *name = NULL; const char *kw = ""; if (!ds->subjmp || !anal) { @@ -5061,7 +5061,7 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { } ut64 addr = ds->analop.jump; - RAnalFunction *fcn = r_anal_get_function_at (anal, addr); + RzAnalFunction *fcn = rz_anal_get_function_at (anal, addr); if (fcn) { if (!set_jump_realname (ds, addr, &kw, &name)) { name = fcn->name; @@ -5069,10 +5069,10 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { } else if (f) { RBinReloc *rel = NULL; if (!ds->core->bin->is_reloc_patched) { - rel = r_core_getreloc (ds->core, ds->analop.addr, ds->analop.size); + rel = rz_core_getreloc (ds->core, ds->analop.addr, ds->analop.size); } if (!rel) { - rel = r_core_getreloc (ds->core, addr, ds->analop.size); + rel = rz_core_getreloc (ds->core, addr, ds->analop.size); } if (rel) { if (rel && rel->import && rel->import->name) { @@ -5082,7 +5082,7 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { } } else { if (!set_jump_realname (ds, addr, &kw, &name)) { - RFlagItem *flag = r_core_flag_get_by_spaces (f, addr); + RzFlagItem *flag = rz_core_flag_get_by_spaces (f, addr); if (flag) { if (strchr (flag->name, '.')) { name = flag->name; @@ -5100,16 +5100,16 @@ static char *ds_sub_jumps(RDisasmState *ds, char *str) { ptr = str; while ((nptr = _find_next_number (ptr))) { ptr = nptr; - numval = r_num_get (NULL, ptr); + numval = rz_num_get (NULL, ptr); if (numval == addr) { while (*nptr && !IS_SEPARATOR (*nptr) && *nptr != 0x1b) { nptr++; } - char *kwname = r_str_newf ("%s%s", kw, name); + char *kwname = rz_str_newf ("%s%s", kw, name); if (kwname) { - char* numstr = r_str_ndup (ptr, nptr-ptr); + char* numstr = rz_str_ndup (ptr, nptr-ptr); if (numstr) { - str = r_str_replace (str, numstr, kwname, 0); + str = rz_str_replace (str, numstr, kwname, 0); free (numstr); } free (kwname); @@ -5127,21 +5127,21 @@ static bool line_highlighted(RDisasmState *ds) { static void ds_start_line_highlight(RDisasmState *ds) { if (ds->show_color && line_highlighted (ds)) { - r_cons_strcat (ds->color_linehl); + rz_cons_strcat (ds->color_linehl); } } static void ds_end_line_highlight(RDisasmState *ds) { if (ds->show_color && line_highlighted (ds)) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } } // int l is for lines -R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int len, int l, int invbreak, int cbytes, bool json, PJ *pj, RAnalFunction *pdf) { +RZ_API int rz_core_print_disasm(RPrint *p, RzCore *core, ut64 addr, ut8 *buf, int len, int l, int invbreak, int cbytes, bool json, PJ *pj, RzAnalFunction *pdf) { int continueoninvbreak = (len == l) && invbreak; - RAnalFunction *of = NULL; - RAnalFunction *f = NULL; + RzAnalFunction *of = NULL; + RzAnalFunction *f = NULL; bool calc_row_offsets = p->calc_row_offsets; int ret, i, inc = 0, skip_bytes_flag = 0, skip_bytes_bb = 0, idx = 0; ut8 *nbuf = NULL; @@ -5165,7 +5165,7 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l ds_free (ds); return 0; } - r_cons_push (); + rz_cons_push (); } else { ds->pj = NULL; } @@ -5173,14 +5173,14 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l // disable row_offsets to prevent other commands to overwrite computed info p->calc_row_offsets = false; - //r_cons_printf ("len =%d l=%d ib=%d limit=%d\n", len, l, invbreak, p->limit); + //rz_cons_printf ("len =%d l=%d ib=%d limit=%d\n", len, l, invbreak, p->limit); // TODO: import values from debugger is possible // TODO: allow to get those register snapshots from traces // TODO: per-function register state trace // XXX - is there a better way to reset a the analysis counter so that // when code is disassembled, it can actually find the correct offsets { /* used by asm.emu */ - r_reg_arena_push (core->anal->reg); + rz_reg_arena_push (core->anal->reg); } ds_reflines_init (ds); @@ -5201,13 +5201,13 @@ R_API int r_core_print_disasm(RPrint *p, RCore *core, ut64 addr, ut8 *buf, int l } toro: // uhm... is this necessary? imho can be removed - r_asm_set_pc (core->rasm, r_core_pava (core, ds->addr + idx)); - core->cons->vline = r_config_get_i (core->config, "scr.utf8") ? (r_config_get_i (core->config, "scr.utf8.curvy") ? r_vline_uc : r_vline_u) : r_vline_a; + rz_asm_set_pc (core->rasm, rz_core_pava (core, ds->addr + idx)); + core->cons->vline = rz_config_get_i (core->config, "scr.utf8") ? (rz_config_get_i (core->config, "scr.utf8.curvy") ? rz_vline_uc : rz_vline_u) : rz_vline_a; if (core->print->cur_enabled) { // TODO: support in-the-middle-of-instruction too - r_anal_op_fini (&ds->analop); - if (r_anal_op (core->anal, &ds->analop, core->offset + core->print->cur, + rz_anal_op_fini (&ds->analop); + if (rz_anal_op (core->anal, &ds->analop, core->offset + core->print->cur, buf + core->print->cur, (int)(len - core->print->cur), R_ANAL_OP_MASK_ALL)) { // TODO: check for ds->analop.type and ret ds->dest = ds->analop.jump; @@ -5216,7 +5216,7 @@ toro: /* highlight eip */ const char *pc = core->anal->reg->name[R_REG_NAME_PC]; if (pc) { - RFlagItem *item = r_flag_get (core->flags, pc); + RzFlagItem *item = rz_flag_get (core->flags, pc); if (item) { ds->dest = item->offset; } @@ -5228,16 +5228,16 @@ toro: if (!ds->l) { ds->l = core->blocksize; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = idx = ret = 0; addrbytes * idx < len && ds->lines < ds->l; idx += inc, i++, ds->index += inc, ds->lines++) { ds->at = ds->addr + idx; - ds->vat = r_core_pava (core, ds->at); - if (r_cons_is_breaked ()) { + ds->vat = rz_core_pava (core, ds->at); + if (rz_cons_is_breaked ()) { R_FREE (nbuf); if (ds->pj) { - r_cons_pop (); + rz_cons_pop (); } - r_cons_break_pop (); + rz_cons_break_pop (); ds_free (ds); return 0; //break; } @@ -5250,7 +5250,7 @@ toro: core->print->resetbg = (ds->asm_highlight == UT64_MAX); ds_start_line_highlight (ds); ds_print_offset (ds); - r_cons_printf (" unmapped\n"); + rz_cons_printf (" unmapped\n"); inc = 1; continue; } @@ -5261,7 +5261,7 @@ toro: // ds_begin_line (ds); ds_pre_line (ds); ds_setup_print_pre (ds, false, false); - r_cons_strcat (" "); + rz_cons_strcat (" "); ds_print_lines_left (ds); ds_begin_comment (ds); if (ds->show_color) { @@ -5272,62 +5272,62 @@ toro: } } } - r_core_seek_arch_bits (core, ds->at); // slow but safe + rz_core_seek_arch_bits (core, ds->at); // slow but safe ds->has_description = false; - ds->hint = r_core_hint_begin (core, ds->hint, ds->at); + ds->hint = rz_core_hint_begin (core, ds->hint, ds->at); ds->printed_str_addr = UT64_MAX; ds->printed_flag_addr = UT64_MAX; // XXX. this must be done in ds_update_pc() // ds_update_pc (ds, ds->at); - r_asm_set_pc (core->rasm, ds->at); + rz_asm_set_pc (core->rasm, ds->at); ds_update_ref_lines (ds); - r_anal_op_fini (&ds->analop); - r_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), R_ANAL_OP_MASK_ALL); + rz_anal_op_fini (&ds->analop); + rz_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), R_ANAL_OP_MASK_ALL); if (ds_must_strip (ds)) { inc = ds->analop.size; // inc = ds->asmop.payload + (ds->asmop.payload % ds->core->rasm->dataalign); - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); continue; } - // f = r_anal_get_fcn_in (core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); + // f = rz_anal_get_fcn_in (core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); f = ds->fcn = fcnIn (ds, ds->at, R_ANAL_FCN_TYPE_NULL); - if (f && f->folded && r_anal_function_contains (f, ds->at)) { - int delta = (ds->at <= f->addr) ? (ds->at - r_anal_function_max_addr (f)) : 0; + if (f && f->folded && rz_anal_function_contains (f, ds->at)) { + int delta = (ds->at <= f->addr) ? (ds->at - rz_anal_function_max_addr (f)) : 0; if (of != f) { char cmt[32]; get_bits_comment (core, f, cmt, sizeof (cmt)); - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, ds->at); if (comment) { ds_pre_xrefs (ds, true); - r_cons_printf ("; %s\n", comment); + rz_cons_printf ("; %s\n", comment); } - r_cons_printf ("%s%s%s (fcn) %s%s%s\n", + rz_cons_printf ("%s%s%s (fcn) %s%s%s\n", COLOR (ds, color_fline), core->cons->vline[CORNER_TL], COLOR (ds, color_fname), f->name, cmt, COLOR_RESET (ds)); ds_setup_print_pre (ds, true, false); ds_print_lines_left (ds); ds_print_offset (ds); - r_cons_printf ("(%d byte folded function)\n", r_anal_function_linear_size (f)); - //r_cons_printf ("%s%s%s\n", COLOR (ds, color_fline), core->cons->vline[RDWN_CORNER], COLOR_RESET (ds)); + rz_cons_printf ("(%d byte folded function)\n", rz_anal_function_linear_size (f)); + //rz_cons_printf ("%s%s%s\n", COLOR (ds, color_fline), core->cons->vline[RDWN_CORNER], COLOR_RESET (ds)); if (delta < 0) { delta = -delta; } ds->addr += delta + idx; - r_io_read_at (core->io, ds->addr, buf, len); + rz_io_read_at (core->io, ds->addr, buf, len); inc = 0; //delta; idx = 0; of = f; - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); if (len == l) { break; } } else { ds->lines--; ds->addr += 1; - r_io_read_at (core->io, ds->addr, buf, len); + rz_io_read_at (core->io, ds->addr, buf, len); inc = 0; //delta; idx = 0; - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); } continue; } @@ -5336,16 +5336,16 @@ toro: char *link_key = sdb_fmt ("link.%08"PFMT64x, ds->addr + idx); const char *link_type = sdb_const_get (core->anal->sdb_types, link_key, 0); if (link_type) { - char *fmt = r_type_format (core->anal->sdb_types, link_type); + char *fmt = rz_type_format (core->anal->sdb_types, link_type); if (fmt) { - r_cons_printf ("(%s)\n", link_type); - r_core_cmdf (core, "pf %s @ 0x%08"PFMT64x"\n", fmt, ds->addr + idx); - const ut32 type_bitsize = r_type_get_bitsize (core->anal->sdb_types, link_type); + rz_cons_printf ("(%s)\n", link_type); + rz_core_cmdf (core, "pf %s @ 0x%08"PFMT64x"\n", fmt, ds->addr + idx); + const ut32 type_bitsize = rz_type_get_bitsize (core->anal->sdb_types, link_type); // always round up when calculating byte_size from bit_size of types // could be struct with a bitfield entry inc = (type_bitsize >> 3) + (!!(type_bitsize & 0x7)); free (fmt); - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); continue; } } else { @@ -5353,25 +5353,25 @@ toro: ret = ds_disassemble (ds, buf + addrbytes * idx, len - addrbytes * idx); if (ret == -31337) { inc = ds->oplen; - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); continue; } } } if (ds->retry) { ds->retry = false; - r_cons_break_pop (); - r_anal_op_fini (&ds->analop); + rz_cons_break_pop (); + rz_anal_op_fini (&ds->analop); goto retry; } ds_atabs_option (ds); if (ds->analop.addr != ds->at) { - r_anal_op_fini (&ds->analop); - r_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), R_ANAL_OP_MASK_ALL); + rz_anal_op_fini (&ds->analop); + rz_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), R_ANAL_OP_MASK_ALL); } if (ret < 1) { - r_strbuf_fini (&ds->analop.esil); - r_strbuf_init (&ds->analop.esil); + rz_strbuf_fini (&ds->analop.esil); + rz_strbuf_init (&ds->analop.esil); ds->analop.type = R_ANAL_OP_TYPE_ILL; } if (ds->hint) { @@ -5384,7 +5384,7 @@ toro: } ds_print_bbline (ds); if (ds->at >= addr) { - r_print_set_rowoff (core->print, ds->lines, ds->at - addr, calc_row_offsets); + rz_print_set_rowoff (core->print, ds->lines, ds->at - addr, calc_row_offsets); } if (ds->midflags) { skip_bytes_flag = handleMidFlags (core, ds, true); @@ -5402,17 +5402,17 @@ toro: } if (ds->pdf) { static bool sparse = false; - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, ds->pdf, ds->at); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, ds->pdf, ds->at); if (!bb) { for (inc = 1; inc < ds->oplen; inc++) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, ds->pdf, ds->at + inc); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, ds->pdf, ds->at + inc); if (bb) { break; } } - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); if (!sparse) { - r_cons_printf ("..\n"); + rz_cons_printf ("..\n"); sparse = true; } continue; @@ -5453,18 +5453,18 @@ toro: ds_start_line_highlight (ds); ds_print_offset (ds); //// - RAnalFunction *fcn = f; + RzAnalFunction *fcn = f; if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, ds->at); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, fcn, ds->at); if (!bb) { - fcn = r_anal_get_function_at (core->anal, ds->at); + fcn = rz_anal_get_function_at (core->anal, ds->at); if (fcn) { - bb = r_anal_fcn_bbget_in (core->anal, fcn, ds->at); + bb = rz_anal_fcn_bbget_in (core->anal, fcn, ds->at); } } if (bb) { if (bb->folded) { - r_cons_printf ("[+] Folded BB [..0x%08"PFMT64x"]\n", ds->at + bb->size); + rz_cons_printf ("[+] Folded BB [..0x%08"PFMT64x"]\n", ds->at + bb->size); inc = bb->size; continue; } @@ -5475,7 +5475,7 @@ toro: bool mi_found = ds_print_meta_infos (ds, buf, len, idx, &mi_type); if (ds->asm_hint_pos == 0) { if (mi_found) { - r_cons_printf (" "); + rz_cons_printf (" "); } else { ds_print_core_vmode (ds, ds->asm_hint_pos); } @@ -5491,12 +5491,12 @@ toro: ds_print_asmop_payload (ds, buf + addrbytes * idx); if (core->rasm->syntax != R_ASM_SYNTAX_INTEL) { - RAsmOp ao; /* disassemble for the vm .. */ + RzAsmOp ao; /* disassemble for the vm .. */ int os = core->rasm->syntax; - r_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL); - r_asm_disassemble (core->rasm, &ao, buf + addrbytes * idx, + rz_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL); + rz_asm_disassemble (core->rasm, &ao, buf + addrbytes * idx, len - addrbytes * idx + 5); - r_asm_set_syntax (core->rasm, os); + rz_asm_set_syntax (core->rasm, os); } if (mi_type == R_META_TYPE_FORMAT) { if ((ds->show_comments || ds->show_usercomments) && ds->show_comment_right) { @@ -5531,12 +5531,12 @@ toro: ds_print_asmop_payload (ds, buf + addrbytes * idx); if (core->rasm->syntax != R_ASM_SYNTAX_INTEL) { - RAsmOp ao; /* disassemble for the vm .. */ + RzAsmOp ao; /* disassemble for the vm .. */ int os = core->rasm->syntax; - r_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL); - r_asm_disassemble (core->rasm, &ao, buf + addrbytes * idx, + rz_asm_set_syntax (core->rasm, R_ASM_SYNTAX_INTEL); + rz_asm_disassemble (core->rasm, &ao, buf + addrbytes * idx, len - addrbytes * idx + 5); - r_asm_set_syntax (core->rasm, os); + rz_asm_set_syntax (core->rasm, os); } if (ds->show_bytes_right && ds->show_bytes) { ds_comment (ds, true, ""); @@ -5573,12 +5573,12 @@ toro: if (ds->line) { if (ds->show_lines_ret && ds->analop.type == R_ANAL_OP_TYPE_RET) { if (strchr (ds->line, '>')) { - memset (ds->line, ' ', r_str_len_utf8 (ds->line)); + memset (ds->line, ' ', rz_str_len_utf8 (ds->line)); } ds_begin_line (ds); ds_print_pre (ds, true); ds_print_ref_lines (ds->line, ds->line_col, ds); - r_cons_printf ("; --------------------------------------"); + rz_cons_printf ("; --------------------------------------"); ds_newline (ds); } R_FREE (ds->line); @@ -5601,10 +5601,10 @@ toro: } inc += ds->asmop.payload + (ds->asmop.payload % ds->core->rasm->dataalign); } - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); R_FREE (nbuf); - r_cons_break_pop (); + rz_cons_break_pop (); #if HASRETRY if (!ds->cbytes && ds->lines < ds->l) { @@ -5616,13 +5616,13 @@ toro: free (nbuf); buf = nbuf = malloc (len); if (ds->tries > 0) { - if (r_io_read_at (core->io, ds->addr, buf, len)) { + if (rz_io_read_at (core->io, ds->addr, buf, len)) { goto toro; } } if (ds->lines < ds->l) { //ds->addr += idx; - if (!r_io_read_at (core->io, ds->addr, buf, len)) { + if (!rz_io_read_at (core->io, ds->addr, buf, len)) { //ds->tries = -1; } goto toro; @@ -5634,15 +5634,15 @@ toro: } #endif if (ds->pj) { - r_cons_pop (); + rz_cons_pop (); if (!pj) { pj_end (ds->pj); - r_cons_printf ("%s", pj_string (ds->pj)); + rz_cons_printf ("%s", pj_string (ds->pj)); pj_free (ds->pj); } } - r_print_set_rowoff (core->print, ds->lines, ds->at - addr, calc_row_offsets); - r_print_set_rowoff (core->print, ds->lines + 1, UT32_MAX, calc_row_offsets); + rz_print_set_rowoff (core->print, ds->lines, ds->at - addr, calc_row_offsets); + rz_print_set_rowoff (core->print, ds->lines + 1, UT32_MAX, calc_row_offsets); // TODO: this too (must review) ds_print_esil_anal_fini (ds); ds_reflines_fini (ds); @@ -5650,7 +5650,7 @@ toro: R_FREE (nbuf); p->calc_row_offsets = calc_row_offsets; /* used by asm.emu */ - r_reg_arena_pop (core->anal->reg); + rz_reg_arena_pop (core->anal->reg); return addrbytes * idx; //-ds->lastfail; } @@ -5664,7 +5664,7 @@ static inline bool check_end(int nb_opcodes, int nb_bytes, int i, int j) { return i < nb_bytes; } -R_API int r_core_print_disasm_instructions_with_buf(RCore *core, ut64 address, ut8 *buf, int nb_bytes, int nb_opcodes) { +RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address, ut8 *buf, int nb_bytes, int nb_opcodes) { RDisasmState *ds = NULL; int i, j, ret, len = 0; char *tmpopstr; @@ -5677,37 +5677,37 @@ R_API int r_core_print_disasm_instructions_with_buf(RCore *core, ut64 address, u return 0; } - r_reg_arena_push (core->anal->reg); + rz_reg_arena_push (core->anal->reg); ds = ds_init (core); ds->l = nb_opcodes; ds->len = nb_opcodes * 8; if (!buf) { - r_core_seek (core, address, true); + rz_core_seek (core, address, true); buf = core->block; } core->offset = address; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); //build ranges to map addr with bits j = 0; toro: for (i = 0; check_end (nb_opcodes, nb_bytes, addrbytes * i, j); i += ret, j++) { ds->at = address + i; - ds->vat = r_core_pava (core, ds->at); + ds->vat = rz_core_pava (core, ds->at); hasanal = false; - r_core_seek_arch_bits (core, ds->at); - if (r_cons_is_breaked ()) { + rz_core_seek_arch_bits (core, ds->at); + if (rz_cons_is_breaked ()) { break; } - ds->hint = r_core_hint_begin (core, ds->hint, ds->at); + ds->hint = rz_core_hint_begin (core, ds->hint, ds->at); ds->has_description = false; - r_asm_set_pc (core->rasm, ds->at); + rz_asm_set_pc (core->rasm, ds->at); // XXX copypasta from main disassembler function - // r_anal_get_fcn_in (core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); - ret = r_asm_disassemble (core->rasm, &ds->asmop, + // rz_anal_get_fcn_in (core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); + ret = rz_asm_disassemble (core->rasm, &ds->asmop, buf + addrbytes * i, nb_bytes - addrbytes * i); ds->oplen = ret; if (ds->midflags) { @@ -5722,10 +5722,10 @@ toro: if (skip_bytes_bb && skip_bytes_bb < ret) { ret = skip_bytes_bb; } - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); if (!hasanal) { // XXX we probably don't need MASK_ALL - r_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * i, nb_bytes - addrbytes * i, R_ANAL_OP_MASK_ALL); + rz_anal_op (core->anal, &ds->analop, ds->at, buf + addrbytes * i, nb_bytes - addrbytes * i, R_ANAL_OP_MASK_ALL); hasanal = true; } if (ds_must_strip (ds)) { @@ -5750,18 +5750,18 @@ toro: if (ds->decode && !ds->immtrim) { R_FREE (ds->opstr); if (!hasanal) { - r_anal_op (core->anal, &ds->analop, ds->at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ALL); + rz_anal_op (core->anal, &ds->analop, ds->at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ALL); hasanal = true; } - tmpopstr = r_anal_op_to_string (core->anal, &ds->analop); - ds->opstr = (tmpopstr)? tmpopstr: strdup (r_asm_op_get_asm (&ds->asmop)); + tmpopstr = rz_anal_op_to_string (core->anal, &ds->analop); + ds->opstr = (tmpopstr)? tmpopstr: strdup (rz_asm_op_get_asm (&ds->asmop)); } else if (ds->immtrim) { free (ds->opstr); - ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop)); - r_parse_immtrim (ds->opstr); + ds->opstr = strdup (rz_asm_op_get_asm (&ds->asmop)); + rz_parse_immtrim (ds->opstr); } else if (ds->use_esil) { if (!hasanal) { - r_anal_op (core->anal, &ds->analop, + rz_anal_op (core->anal, &ds->analop, ds->at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ESIL | R_ANAL_OP_MASK_HINT); hasanal = true; @@ -5795,43 +5795,43 @@ toro: ds->opstr = asm_str; core->parser->flagspace = ofs; // ??? } else { - ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop)); + ds->opstr = strdup (rz_asm_op_get_asm (&ds->asmop)); } if (ds->immtrim) { free (ds->opstr); - ds->opstr = strdup (r_asm_op_get_asm (&ds->asmop)); - r_parse_immtrim (ds->opstr); + ds->opstr = strdup (rz_asm_op_get_asm (&ds->asmop)); + rz_parse_immtrim (ds->opstr); } } if (ds->asm_instr) { const char *opcolor = NULL; if (ds->show_color) { - opcolor = r_print_color_op_type (core->print, ds->analop.type); - r_cons_printf ("%s%s" Color_RESET "\n", opcolor, ds->opstr); + opcolor = rz_print_color_op_type (core->print, ds->analop.type); + rz_cons_printf ("%s%s" Color_RESET "\n", opcolor, ds->opstr); } else { - r_cons_println (ds->opstr); + rz_cons_println (ds->opstr); } R_FREE (ds->opstr); } if (ds->hint) { - r_anal_hint_free (ds->hint); + rz_anal_hint_free (ds->hint); ds->hint = NULL; } } if (buf == core->block && nb_opcodes > 0 && j < nb_opcodes) { - r_core_seek (core, core->offset + i, true); + rz_core_seek (core, core->offset + i, true); i = 0; goto toro; } - r_cons_break_pop (); + rz_cons_break_pop (); ds_free (ds); core->offset = old_offset; - r_reg_arena_pop (core->anal->reg); + rz_reg_arena_pop (core->anal->reg); return len; } -static bool handle_backwards_disasm(RCore *core, int *nb_opcodes, int *nb_bytes) { +static bool handle_backwards_disasm(RzCore *core, int *nb_opcodes, int *nb_bytes) { if (!*nb_opcodes && !*nb_bytes) { return false; } @@ -5847,17 +5847,17 @@ static bool handle_backwards_disasm(RCore *core, int *nb_opcodes, int *nb_bytes) int nbytes = 0; // We have some anal_info. - if (r_core_prevop_addr (core, core->offset, *nb_opcodes, &core->offset)) { + if (rz_core_prevop_addr (core, core->offset, *nb_opcodes, &core->offset)) { nbytes = old_offset - core->offset; } else { - // core->offset is modified by r_core_prevop_addr + // core->offset is modified by rz_core_prevop_addr core->offset = old_offset; - r_core_asm_bwdis_len (core, &nbytes, &core->offset, *nb_opcodes); + rz_core_asm_bwdis_len (core, &nbytes, &core->offset, *nb_opcodes); } if (nbytes > core->blocksize) { - r_core_block_size (core, nbytes); + rz_core_block_size (core, nbytes); } - r_io_read_at (core->io, core->offset, core->block, nbytes); + rz_io_read_at (core->io, core->offset, core->block, nbytes); } } else { if (*nb_bytes < 0) { // Disassemble backward `nb_bytes` bytes @@ -5865,22 +5865,22 @@ static bool handle_backwards_disasm(RCore *core, int *nb_opcodes, int *nb_bytes) core->offset -= *nb_bytes; if (*nb_bytes > core->blocksize) { ut64 obsz = core->blocksize; - r_core_block_size (core, *nb_bytes); + rz_core_block_size (core, *nb_bytes); if (core->blocksize == *nb_bytes) { - r_io_read_at (core->io, core->offset, core->block, *nb_bytes); + rz_io_read_at (core->io, core->offset, core->block, *nb_bytes); } else { eprintf ("Cannot read that much!\n"); - r_core_block_size (core, obsz); + rz_core_block_size (core, obsz); return false; } - r_core_block_size (core, obsz); + rz_core_block_size (core, obsz); } else { - r_io_read_at (core->io, core->offset, core->block, *nb_bytes); + rz_io_read_at (core->io, core->offset, core->block, *nb_bytes); } } else { if (*nb_bytes > core->blocksize) { - r_core_block_size (core, *nb_bytes); - r_io_read_at (core->io, core->offset, core->block, *nb_bytes); + rz_core_block_size (core, *nb_bytes); + rz_io_read_at (core->io, core->offset, core->block, *nb_bytes); } } } @@ -5890,20 +5890,20 @@ static bool handle_backwards_disasm(RCore *core, int *nb_opcodes, int *nb_bytes) /* Disassemble either `nb_opcodes` instructions, or * `nb_bytes` bytes; both can be negative. * Set to 0 the parameter you don't use */ -R_API int r_core_print_disasm_instructions(RCore *core, int nb_bytes, int nb_opcodes) { +RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes) { const ut64 ocore_offset = core->offset; int ret = -1; if (handle_backwards_disasm (core, &nb_opcodes, &nb_bytes)) { - ret = r_core_print_disasm_instructions_with_buf (core, core->offset, NULL, nb_bytes, nb_opcodes); + ret = rz_core_print_disasm_instructions_with_buf (core, core->offset, NULL, nb_bytes, nb_opcodes); } - r_core_seek (core, ocore_offset, true); + rz_core_seek (core, ocore_offset, true); return ret; } -R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_bytes, int nb_opcodes, PJ *pj) { - RAsmOp asmop; +RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int nb_bytes, int nb_opcodes, PJ *pj) { + RzAsmOp asmop; RDisasmState *ds; - RAnalFunction *f; + RzAnalFunction *f; int i, j, k, ret, line; ut64 old_offset = core->offset; ut64 at; @@ -5928,14 +5928,14 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte return false; } - if (r_core_prevop_addr (core, core->offset, nb_opcodes, &addr)) { + if (rz_core_prevop_addr (core, core->offset, nb_opcodes, &addr)) { nbytes = old_offset - addr; - } else if (!r_core_asm_bwdis_len (core, &nbytes, &addr, nb_opcodes)) { + } else if (!rz_core_asm_bwdis_len (core, &nbytes, &addr, nb_opcodes)) { /* workaround to avoid empty arrays */ #define BWRETRY 0 #if BWRETRY nb_opcodes ++; - if (!r_core_asm_bwdis_len (core, &nbytes, &addr, nb_opcodes)) { + if (!rz_core_asm_bwdis_len (core, &nbytes, &addr, nb_opcodes)) { #endif pj_end (pj); return false; @@ -5946,8 +5946,8 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } count = R_MIN (nb_bytes, nbytes); if (count > 0) { - r_io_read_at (core->io, addr, buf, count); - r_io_read_at (core->io, addr+count, buf+count, nb_bytes-count); + rz_io_read_at (core->io, addr, buf, count); + rz_io_read_at (core->io, addr+count, buf+count, nb_bytes-count); } else { if (nb_bytes > 0) { memset (buf, 0xff, nb_bytes); @@ -5960,14 +5960,14 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte // the equivalent addr and nb_size and scan a positive number of BYTES // so keep dis_opcodes = 0; dis_opcodes = 1; - r_io_read_at (core->io, addr, buf, nb_bytes); + rz_io_read_at (core->io, addr, buf, nb_bytes); } } else { // Disassemble `nb_bytes` bytes if (nb_bytes < 0) { //Backward disassembly of `nb_bytes` bytes nb_bytes = -nb_bytes; addr -= nb_bytes; - r_io_read_at (core->io, addr, buf, nb_bytes); + rz_io_read_at (core->io, addr, buf, nb_bytes); } } core->offset = addr; @@ -5988,13 +5988,13 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte int skip_bytes_flag = 0, skip_bytes_bb = 0; at = addr + k; - ds->hint = r_core_hint_begin (core, ds->hint, ds->at); - r_asm_set_pc (core->rasm, at); + ds->hint = rz_core_hint_begin (core, ds->hint, ds->at); + rz_asm_set_pc (core->rasm, at); // 32 is the biggest opcode length in intel // Make sure we have room for it if (dis_opcodes == 1 && i >= nb_bytes - 32) { // Read another nb_bytes bytes into buf from current offset - r_io_read_at (core->io, at, buf, nb_bytes); + rz_io_read_at (core->io, at, buf, nb_bytes); i = 0; } @@ -6005,8 +6005,8 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } else if (i >= nb_bytes) { break; } - memset (&asmop, 0, sizeof (RAsmOp)); - ret = r_asm_disassemble (core->rasm, &asmop, buf + i, nb_bytes - i); + memset (&asmop, 0, sizeof (RzAsmOp)); + ret = rz_asm_disassemble (core->rasm, &asmop, buf + i, nb_bytes - i); if (ret < 1) { pj_o (pj); pj_kn (pj, "offset", at); @@ -6021,30 +6021,30 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } char opstr[256]; - r_str_ncpy (opstr, r_asm_op_get_asm (&asmop), sizeof (opstr) - 1); + rz_str_ncpy (opstr, rz_asm_op_get_asm (&asmop), sizeof (opstr) - 1); ds->has_description = false; - r_anal_op_fini (&ds->analop); - r_anal_op (core->anal, &ds->analop, at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ALL); + rz_anal_op_fini (&ds->analop); + rz_anal_op (core->anal, &ds->analop, at, buf + i, nb_bytes - i, R_ANAL_OP_MASK_ALL); if (ds->pseudo) { - r_parse_parse (core->parser, opstr, opstr); + rz_parse_parse (core->parser, opstr, opstr); } - // f = r_anal_get_fcn_in (core->anal, at, + // f = rz_anal_get_fcn_in (core->anal, at, f = fcnIn (ds, at, R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM | R_ANAL_FCN_TYPE_LOC); if (ds->subvar && f) { - int ba_len = r_strbuf_length (&asmop.buf_asm) + 128; + int ba_len = rz_strbuf_length (&asmop.buf_asm) + 128; char *ba = malloc (ba_len); if (ba) { - strcpy (ba, r_asm_op_get_asm (&asmop)); - r_parse_subvar (core->parser, f, at, ds->analop.size, + strcpy (ba, rz_asm_op_get_asm (&asmop)); + rz_parse_subvar (core->parser, f, at, ds->analop.size, ba, ba, ba_len); - r_asm_op_set_asm (&asmop, ba); + rz_asm_op_set_asm (&asmop, ba); free (ba); } } - ds->oplen = r_asm_op_get_size (&asmop); + ds->oplen = rz_asm_op_get_size (&asmop); ds->at = at; if (ds->midflags) { skip_bytes_flag = handleMidFlags (core, ds, false); @@ -6061,20 +6061,20 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte { ut64 killme = UT64_MAX; bool be = core->print->big_endian; - if (r_io_read_i (core->io, ds->analop.ptr, &killme, ds->analop.refptr, be)) { + if (rz_io_read_i (core->io, ds->analop.ptr, &killme, ds->analop.refptr, be)) { core->parser->subrel_addr = killme; } } { - char *aop = r_asm_op_get_asm (&asmop); + char *aop = rz_asm_op_get_asm (&asmop); char *buf = malloc (strlen (aop) + 128); if (buf) { strcpy (buf, aop); buf = ds_sub_jumps (ds, buf); - r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, buf, + rz_parse_filter (core->parser, ds->vat, core->flags, ds->hint, buf, str, sizeof (str) - 1, core->print->big_endian); str[sizeof (str) - 1] = '\0'; - r_asm_op_set_asm (&asmop, buf); + rz_asm_op_set_asm (&asmop, buf); free (buf); } } @@ -6091,34 +6091,34 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte pj_s (pj, R_STRBUF_SAFEGET (&ds->analop.esil)); pj_kb (pj, "refptr", ds->analop.refptr); pj_kn (pj, "fcn_addr", f ? f->addr : 0); - pj_kn (pj, "fcn_last", f ? r_anal_function_max_addr (f) - ds->oplen : 0); + pj_kn (pj, "fcn_last", f ? rz_anal_function_max_addr (f) - ds->oplen : 0); pj_ki (pj, "size", ds->analop.size); pj_ks (pj, "opcode", opstr); pj_ks (pj, "disasm", str); { - char *hex = r_asm_op_get_hex (&asmop); + char *hex = rz_asm_op_get_hex (&asmop); pj_ks (pj, "bytes", hex); free (hex); } - pj_ks (pj, "family", r_anal_op_family_to_string (ds->analop.family)); - pj_ks (pj, "type", r_anal_optype_to_string (ds->analop.type)); + pj_ks (pj, "family", rz_anal_op_family_to_string (ds->analop.family)); + pj_ks (pj, "type", rz_anal_optype_to_string (ds->analop.type)); // indicate a relocated address - RBinReloc *rel = r_core_getreloc (core, ds->at, ds->analop.size); + RBinReloc *rel = rz_core_getreloc (core, ds->at, ds->analop.size); // reloc is true if address in reloc table pj_kb (pj, "reloc", rel); // wanted the numerical values of the type information pj_kn (pj, "type_num", (ut64)(ds->analop.type & UT64_MAX)); pj_kn (pj, "type2_num", (ut64)(ds->analop.type2 & UT64_MAX)); // handle switch statements - if (ds->analop.switch_op && r_list_length (ds->analop.switch_op->cases) > 0) { + if (ds->analop.switch_op && rz_list_length (ds->analop.switch_op->cases) > 0) { // XXX - the java caseop will still be reported in the assembly, // this is an artifact to make ensure the disassembly is properly // represented during the analysis - RListIter *iter; - RAnalCaseOp *caseop; + RzListIter *iter; + RzAnalCaseOp *caseop; pj_k (pj, "switch"); pj_a (pj); - r_list_foreach (ds->analop.switch_op->cases, iter, caseop ) { + rz_list_foreach (ds->analop.switch_op->cases, iter, caseop ) { pj_o (pj); pj_kn (pj, "addr", caseop->addr); pj_kN (pj, "value", (st64) caseop->value); @@ -6135,13 +6135,13 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } /* add flags */ { - const RList *flags = r_flag_get_list (core->flags, at); - RFlagItem *flag; - RListIter *iter; - if (flags && !r_list_empty (flags)) { + const RzList *flags = rz_flag_get_list (core->flags, at); + RzFlagItem *flag; + RzListIter *iter; + if (flags && !rz_list_empty (flags)) { pj_k (pj, "flags"); pj_a (pj); - r_list_foreach (flags, iter, flag) { + rz_list_foreach (flags, iter, flag) { pj_s (pj, flag->name); } pj_end (pj); @@ -6150,7 +6150,7 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte /* add comments */ { // TODO: slow because we are encoding b64 - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, at); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, at); if (comment) { char *b64comment = sdb_encode ((const ut8*)comment, -1); pj_ks (pj, "comment", b64comment); @@ -6159,39 +6159,39 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte } /* add refs */ { - RAnalRef *ref; - RListIter *iter; - RList *refs = r_anal_refs_get (core->anal, at); - if (refs && !r_list_empty (refs)) { + RzAnalRef *ref; + RzListIter *iter; + RzList *refs = rz_anal_refs_get (core->anal, at); + if (refs && !rz_list_empty (refs)) { pj_k (pj, "refs"); pj_a (pj); - r_list_foreach (refs, iter, ref) { + rz_list_foreach (refs, iter, ref) { pj_o (pj); pj_kn (pj, "addr", ref->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (ref->type)); pj_end (pj); } pj_end (pj); } - r_list_free (refs); + rz_list_free (refs); } /* add xrefs */ { - RAnalRef *ref; - RListIter *iter; - RList *xrefs = r_anal_xrefs_get (core->anal, at); - if (xrefs && !r_list_empty (xrefs)) { + RzAnalRef *ref; + RzListIter *iter; + RzList *xrefs = rz_anal_xrefs_get (core->anal, at); + if (xrefs && !rz_list_empty (xrefs)) { pj_k (pj, "xrefs"); pj_a (pj); - r_list_foreach (xrefs, iter, ref) { + rz_list_foreach (xrefs, iter, ref) { pj_o (pj); pj_kn (pj, "addr", ref->addr); - pj_ks (pj, "type", r_anal_xrefs_type_tostring (ref->type)); + pj_ks (pj, "type", rz_anal_xrefs_type_tostring (ref->type)); pj_end (pj); } pj_end (pj); } - r_list_free (xrefs); + rz_list_free (xrefs); } pj_end (pj); @@ -6207,9 +6207,9 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte break; } } - // r_cons_printf ("]"); + // rz_cons_printf ("]"); core->offset = old_offset; - r_anal_op_fini (&ds->analop); + rz_anal_op_fini (&ds->analop); ds_free (ds); if (!result) { pj_o (pj); @@ -6219,71 +6219,71 @@ R_API int r_core_print_disasm_json(RCore *core, ut64 addr, ut8 *buf, int nb_byte return result; } -R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mode) { - const bool scr_color = r_config_get_i (core->config, "scr.color"); +RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int mode) { + const bool scr_color = rz_config_get_i (core->config, "scr.color"); int i, ret, count = 0; ut8 *buf = core->block; char str[128]; - RAsmOp asmop; + RzAsmOp asmop; if (l < 1) { l = len; } RDisasmState *ds = ds_init (core); if (l > core->blocksize || addr != core->offset) { buf = malloc (l + 1); - r_io_read_at (core->io, addr, buf, l); + rz_io_read_at (core->io, addr, buf, l); } if (mode == 'j') { - r_cons_print ("["); + rz_cons_print ("["); } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = 0; i < l; i++) { ds->at = addr + i; - ds->vat = r_core_pava (core, ds->at); - r_asm_set_pc (core->rasm, ds->vat); - if (r_cons_is_breaked ()) { + ds->vat = rz_core_pava (core, ds->at); + rz_asm_set_pc (core->rasm, ds->vat); + if (rz_cons_is_breaked ()) { break; } - ret = r_asm_disassemble (core->rasm, &asmop, buf + i, l - i); + ret = rz_asm_disassemble (core->rasm, &asmop, buf + i, l - i); if (ret < 1) { switch (mode) { case 'j': case '=': break; case 'i': - r_cons_printf ("???\n"); + rz_cons_printf ("???\n"); break; default: - r_cons_printf ("0x%08"PFMT64x" ???\n", ds->vat); + rz_cons_printf ("0x%08"PFMT64x" ???\n", ds->vat); break; } } else { count ++; switch (mode) { case 'i': - r_parse_filter (core->parser, ds->vat, core->flags, ds->hint, r_asm_op_get_asm (&asmop), + rz_parse_filter (core->parser, ds->vat, core->flags, ds->hint, rz_asm_op_get_asm (&asmop), str, sizeof (str), core->print->big_endian); if (scr_color) { - RAnalOp aop; - RAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL); - r_anal_op (core->anal, &aop, addr, buf+i, l-i, R_ANAL_OP_MASK_ALL); - char *buf_asm = r_print_colorize_opcode (core->print, str, + RzAnalOp aop; + RzAnalFunction *f = fcnIn (ds, ds->vat, R_ANAL_FCN_TYPE_NULL); + rz_anal_op (core->anal, &aop, addr, buf+i, l-i, R_ANAL_OP_MASK_ALL); + char *buf_asm = rz_print_colorize_opcode (core->print, str, core->cons->context->pal.reg, core->cons->context->pal.num, false, f ? f->addr : 0); if (buf_asm) { - r_cons_printf ("%s%s\n", r_print_color_op_type (core->print, aop.type), buf_asm); + rz_cons_printf ("%s%s\n", rz_print_color_op_type (core->print, aop.type), buf_asm); free (buf_asm); } } else { - r_cons_println (r_asm_op_get_asm (&asmop)); + rz_cons_println (rz_asm_op_get_asm (&asmop)); } break; case '=': if (i < 28) { - char *str = r_str_newf ("0x%08"PFMT64x" %60s %s\n", ds->vat, "", r_asm_op_get_asm (&asmop)); + char *str = rz_str_newf ("0x%08"PFMT64x" %60s %s\n", ds->vat, "", rz_asm_op_get_asm (&asmop)); char *sp = strchr (str, ' '); if (sp) { char *end = sp + 60 + 1; - char *src = r_asm_op_get_hex (&asmop); + char *src = rz_asm_op_get_hex (&asmop); char *dst = sp + 1 + (i * 2); int len = strlen (src); if (dst < end) { @@ -6295,52 +6295,52 @@ R_API int r_core_print_disasm_all(RCore *core, ut64 addr, int l, int len, int mo } free (src); } - r_cons_strcat (str); + rz_cons_strcat (str); free (str); } break; case 'j': { - char *op_hex = r_asm_op_get_hex (&asmop); - r_cons_printf ("{\"addr\":%08"PFMT64d",\"bytes\":\"%s\",\"inst\":\"%s\"}%s", - addr + i, op_hex, r_asm_op_get_asm (&asmop), ","); + char *op_hex = rz_asm_op_get_hex (&asmop); + rz_cons_printf ("{\"addr\":%08"PFMT64d",\"bytes\":\"%s\",\"inst\":\"%s\"}%s", + addr + i, op_hex, rz_asm_op_get_asm (&asmop), ","); free (op_hex); break; } default: { - char *op_hex = r_asm_op_get_hex (&asmop); - r_cons_printf ("0x%08"PFMT64x" %20s %s\n", + char *op_hex = rz_asm_op_get_hex (&asmop); + rz_cons_printf ("0x%08"PFMT64x" %20s %s\n", addr + i, op_hex, - r_asm_op_get_asm (&asmop)); + rz_asm_op_get_asm (&asmop)); free (op_hex); } } } } - r_cons_break_pop (); + rz_cons_break_pop (); if (buf != core->block) { free (buf); } if (mode == 'j') { - r_cons_printf ("{}]\n"); + rz_cons_printf ("{}]\n"); } ds_free (ds); return count; } -R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 nb_opcodes, ut32 nb_bytes, int fmt) { - bool show_offset = r_config_get_i (core->config, "asm.offset"); - bool show_bytes = r_config_get_i (core->config, "asm.bytes"); - int decode = r_config_get_i (core->config, "asm.decode"); - int filter = r_config_get_i (core->config, "asm.filter"); - int show_color = r_config_get_i (core->config, "scr.color"); - bool asm_ucase = r_config_get_i (core->config, "asm.ucase"); - bool asm_instr = r_config_get_i (core->config, "asm.instr"); - int esil = r_config_get_i (core->config, "asm.esil"); - int flags = r_config_get_i (core->config, "asm.flags"); - bool asm_immtrim = r_config_get_i (core->config, "asm.imm.trim"); +RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut32 nb_opcodes, ut32 nb_bytes, int fmt) { + bool show_offset = rz_config_get_i (core->config, "asm.offset"); + bool show_bytes = rz_config_get_i (core->config, "asm.bytes"); + int decode = rz_config_get_i (core->config, "asm.decode"); + int filter = rz_config_get_i (core->config, "asm.filter"); + int show_color = rz_config_get_i (core->config, "scr.color"); + bool asm_ucase = rz_config_get_i (core->config, "asm.ucase"); + bool asm_instr = rz_config_get_i (core->config, "asm.instr"); + int esil = rz_config_get_i (core->config, "asm.esil"); + int flags = rz_config_get_i (core->config, "asm.flags"); + bool asm_immtrim = rz_config_get_i (core->config, "asm.imm.trim"); int i = 0, j, ret, err = 0; ut64 old_offset = core->offset; - RAsmOp asmop; + RzAsmOp asmop; const char *color_reg = R_CONS_COLOR_DEF (reg, Color_YELLOW); const char *color_num = R_CONS_COLOR_DEF (num, Color_CYAN); const size_t addrbytes = buf ? 1 : core->io->addrbytes; @@ -6355,53 +6355,53 @@ R_API int r_core_disasm_pdi_with_buf(RCore *core, ut64 address, ut8 *buf, ut32 n } if (!buf) { - r_core_seek (core, address, true); + rz_core_seek (core, address, true); buf = core->block; } - r_cons_break_push (NULL, NULL); - r_core_seek (core, address, false); - int midflags = r_config_get_i (core->config, "asm.flags.middle"); - int midbb = r_config_get_i (core->config, "asm.bb.middle"); - bool asmmarks = r_config_get_i (core->config, "asm.marks"); - r_config_set_i (core->config, "asm.marks", false); + rz_cons_break_push (NULL, NULL); + rz_core_seek (core, address, false); + int midflags = rz_config_get_i (core->config, "asm.flags.middle"); + int midbb = rz_config_get_i (core->config, "asm.bb.middle"); + bool asmmarks = rz_config_get_i (core->config, "asm.marks"); + rz_config_set_i (core->config, "asm.marks", false); i = 0; j = 0; - RAnalMetaItem *meta = NULL; + RzAnalMetaItem *meta = NULL; toro: for (; check_end (nb_opcodes, nb_bytes, addrbytes * i, j); j++) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { err = 1; break; } ut64 at = core->offset + i; if (flags) { if (fmt != 'e') { // pie - RFlagItem *item = r_flag_get_i (core->flags, at); + RzFlagItem *item = rz_flag_get_i (core->flags, at); if (item) { if (show_offset) { const int show_offseg = (core->print->flags & R_PRINT_FLAGS_SEGOFF) != 0; const int show_offdec = (core->print->flags & R_PRINT_FLAGS_ADDRDEC) != 0; - unsigned int seggrn = r_config_get_i (core->config, "asm.seggrn"); - r_print_offset_sg (core->print, at, 0, show_offseg, seggrn, show_offdec, 0, NULL); + unsigned int seggrn = rz_config_get_i (core->config, "asm.seggrn"); + rz_print_offset_sg (core->print, at, 0, show_offseg, seggrn, show_offdec, 0, NULL); } - r_cons_printf (" %s:\n", item->name); + rz_cons_printf (" %s:\n", item->name); } } // do not show flags in pie } if (show_offset) { const int show_offseg = (core->print->flags & R_PRINT_FLAGS_SEGOFF) != 0; const int show_offdec = (core->print->flags & R_PRINT_FLAGS_ADDRDEC) != 0; - unsigned int seggrn = r_config_get_i (core->config, "asm.seggrn"); - r_print_offset_sg (core->print, at, 0, show_offseg, seggrn, show_offdec, 0, NULL); + unsigned int seggrn = rz_config_get_i (core->config, "asm.seggrn"); + rz_print_offset_sg (core->print, at, 0, show_offseg, seggrn, show_offdec, 0, NULL); } ut64 meta_start = at; ut64 meta_size; - meta = r_meta_get_at (core->anal, meta_start, R_META_TYPE_ANY, &meta_size); + meta = rz_meta_get_at (core->anal, meta_start, R_META_TYPE_ANY, &meta_size); if (meta) { switch (meta->type) { case R_META_TYPE_DATA: - //r_cons_printf (".data: %s\n", meta->str); + //rz_cons_printf (".data: %s\n", meta->str); i += meta_size; { int idx = i; @@ -6419,24 +6419,24 @@ toro: RDisasmState ds = {0}; ds.core = core; if (!ds_print_data_type (&ds, buf + i, 0, size)) { - r_cons_printf ("hex length=%" PFMT64d " delta=%d\n", size, delta); - r_print_hexdump (core->print, at, buf + idx, hexlen - delta, 16, 1, 1); + rz_cons_printf ("hex length=%" PFMT64d " delta=%d\n", size, delta); + rz_print_hexdump (core->print, at, buf + idx, hexlen - delta, 16, 1, 1); } else { - r_cons_newline (); + rz_cons_newline (); } ret = true; } continue; case R_META_TYPE_STRING: - //r_cons_printf (".string: %s\n", meta->str); + //rz_cons_printf (".string: %s\n", meta->str); i += meta_size; continue; case R_META_TYPE_FORMAT: - //r_cons_printf (".format : %s\n", meta->str); + //rz_cons_printf (".format : %s\n", meta->str); i += meta_size; continue; case R_META_TYPE_MAGIC: - //r_cons_printf (".magic : %s\n", meta->str); + //rz_cons_printf (".magic : %s\n", meta->str); i += meta_size; continue; case R_META_TYPE_RUN: @@ -6446,8 +6446,8 @@ toro: break; } } - r_asm_set_pc (core->rasm, core->offset + i); - ret = r_asm_disassemble (core->rasm, &asmop, buf + addrbytes * i, + rz_asm_set_pc (core->rasm, core->offset + i); + ret = rz_asm_disassemble (core->rasm, &asmop, buf + addrbytes * i, nb_bytes - addrbytes * i); if (midflags || midbb) { RDisasmState ds = { @@ -6470,14 +6470,14 @@ toro: } } if (fmt == 'C') { - const char *comment = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, core->offset + i); + const char *comment = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, core->offset + i); if (comment) { - r_cons_printf ("0x%08" PFMT64x " %s\n", core->offset + i, comment); + rz_cons_printf ("0x%08" PFMT64x " %s\n", core->offset + i, comment); } i += ret; continue; } - // r_cons_printf ("0x%08"PFMT64x" ", core->offset+i); + // rz_cons_printf ("0x%08"PFMT64x" ", core->offset+i); if (ret < 1) { err = 1; ret = asmop.size; @@ -6485,101 +6485,101 @@ toro: ret = 1; } if (show_bytes) { - r_cons_printf ("%18s%02x ", "", buf[i]); + rz_cons_printf ("%18s%02x ", "", buf[i]); } - r_cons_println ("invalid"); // ???"); + rz_cons_println ("invalid"); // ???"); } else { if (show_bytes) { - char *op_hex = r_asm_op_get_hex (&asmop); - r_cons_printf ("%20s ", op_hex); + char *op_hex = rz_asm_op_get_hex (&asmop); + rz_cons_printf ("%20s ", op_hex); free (op_hex); } ret = asmop.size; if (!asm_instr) { - r_cons_newline (); + rz_cons_newline (); } else if (!asm_immtrim && (decode || esil)) { - RAnalOp analop = { + RzAnalOp analop = { 0 }; char *tmpopstr, *opstr = NULL; - r_anal_op (core->anal, &analop, core->offset + i, + rz_anal_op (core->anal, &analop, core->offset + i, buf + addrbytes * i, nb_bytes - addrbytes * i, R_ANAL_OP_MASK_ALL); - tmpopstr = r_anal_op_to_string (core->anal, &analop); + tmpopstr = rz_anal_op_to_string (core->anal, &analop); if (fmt == 'e') { // pie char *esil = (R_STRBUF_SAFEGET (&analop.esil)); - r_cons_println (esil); + rz_cons_println (esil); } else { if (decode) { - opstr = tmpopstr? tmpopstr: r_asm_op_get_asm (&(asmop)); + opstr = tmpopstr? tmpopstr: rz_asm_op_get_asm (&(asmop)); } else if (esil) { opstr = (R_STRBUF_SAFEGET (&analop.esil)); } if (asm_immtrim) { - r_parse_immtrim (opstr); + rz_parse_immtrim (opstr); } - r_cons_println (opstr); + rz_cons_println (opstr); } - r_anal_op_fini (&analop); + rz_anal_op_fini (&analop); } else { char opstr[128] = { 0 }; - char *asm_str = r_asm_op_get_asm (&asmop); + char *asm_str = rz_asm_op_get_asm (&asmop); if (asm_ucase) { - r_str_case (asm_str, 1); + rz_str_case (asm_str, 1); } if (asm_immtrim) { - r_parse_immtrim (asm_str); + rz_parse_immtrim (asm_str); } if (filter) { - RAnalHint *hint = r_anal_hint_get (core->anal, at); - r_parse_filter (core->parser, at, core->flags, hint, + RzAnalHint *hint = rz_anal_hint_get (core->anal, at); + rz_parse_filter (core->parser, at, core->flags, hint, asm_str, opstr, sizeof (opstr) - 1, core->print->big_endian); - r_anal_hint_free (hint); + rz_anal_hint_free (hint); asm_str = (char *)&opstr; } if (show_color) { - RAnalOp aop = { + RzAnalOp aop = { 0 }; - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset + i, R_ANAL_FCN_TYPE_NULL); - r_anal_op (core->anal, &aop, core->offset + i, + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset + i, R_ANAL_FCN_TYPE_NULL); + rz_anal_op (core->anal, &aop, core->offset + i, buf + addrbytes * i, nb_bytes - addrbytes * i, R_ANAL_OP_MASK_BASIC); - asm_str = r_print_colorize_opcode (core->print, asm_str, color_reg, color_num, false, f ? f->addr : 0); - r_cons_printf ("%s%s"Color_RESET "\n", - r_print_color_op_type (core->print, aop.type), + asm_str = rz_print_colorize_opcode (core->print, asm_str, color_reg, color_num, false, f ? f->addr : 0); + rz_cons_printf ("%s%s"Color_RESET "\n", + rz_print_color_op_type (core->print, aop.type), asm_str); free (asm_str); - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } else { - r_cons_println (asm_str); + rz_cons_println (asm_str); } } } i += ret; } if (buf == core->block && nb_opcodes > 0 && j < nb_opcodes) { - r_core_seek (core, core->offset + i, true); + rz_core_seek (core, core->offset + i, true); i = 0; goto toro; } - r_config_set_i (core->config, "asm.marks", asmmarks); - r_cons_break_pop (); - r_core_seek (core, old_offset, true); + rz_config_set_i (core->config, "asm.marks", asmmarks); + rz_cons_break_pop (); + rz_core_seek (core, old_offset, true); return err; } -R_API int r_core_disasm_pdi(RCore *core, int nb_opcodes, int nb_bytes, int fmt) { +RZ_API int rz_core_disasm_pdi(RzCore *core, int nb_opcodes, int nb_bytes, int fmt) { const ut64 ocore_offset = core->offset; int ret = -1; if (handle_backwards_disasm(core, &nb_opcodes, &nb_bytes)) { - ret = r_core_disasm_pdi_with_buf (core, core->offset, NULL, nb_opcodes, nb_bytes, fmt); + ret = rz_core_disasm_pdi_with_buf (core, core->offset, NULL, nb_opcodes, nb_bytes, fmt); } - r_core_seek (core, ocore_offset, true); + rz_core_seek (core, ocore_offset, true); return ret; } -static bool read_ahead(RIO *io, ut8 **buf, size_t *buf_sz, ut64 address, size_t offset_into_buf, size_t bytes_to_read) { +static bool read_ahead(RzIO *io, ut8 **buf, size_t *buf_sz, ut64 address, size_t offset_into_buf, size_t bytes_to_read) { if (offset_into_buf + bytes_to_read > *buf_sz) { const size_t new_sz = *buf_sz * 2; ut8 *tmp = realloc (*buf, new_sz); @@ -6589,15 +6589,15 @@ static bool read_ahead(RIO *io, ut8 **buf, size_t *buf_sz, ut64 address, size_t *buf_sz = new_sz; *buf = tmp; } - return r_io_read_at_mapped (io, address, *buf + offset_into_buf, bytes_to_read); + return rz_io_read_at_mapped (io, address, *buf + offset_into_buf, bytes_to_read); } -R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { +RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode) { if (nb_opcodes < 1) { return 0; } - RReg *reg = core->anal->reg; - RRegItem *pc = r_reg_get (reg, "PC", R_REG_TYPE_ALL); + RzReg *reg = core->anal->reg; + RzRegItem *pc = rz_reg_get (reg, "PC", R_REG_TYPE_ALL); if (!pc) { return -1; } @@ -6610,46 +6610,46 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { pj_a (pj); } if (!core->anal->esil) { - r_core_cmd0 (core, "aei"); - if (!r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd0 (core, "aeim"); + rz_core_cmd0 (core, "aei"); + if (!rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd0 (core, "aeim"); } } - RAnalEsil *esil = core->anal->esil; - RList *ocache = core->io->cache; + RzAnalEsil *esil = core->anal->esil; + RzList *ocache = core->io->cache; RCache *ocacheb = core->io->buffer; const int ocached = core->io->cached; if (ocache) { if (ocacheb && ocacheb->len) { - RCache *c = r_cache_new (); - r_cache_set (c, ocacheb->base, ocacheb->buf, ocacheb->len); + RCache *c = rz_cache_new (); + rz_cache_set (c, ocacheb->base, ocacheb->buf, ocacheb->len); core->io->buffer = c; } - core->io->cache = r_list_clone (ocache); + core->io->cache = rz_list_clone (ocache); } else { - r_io_cache_init (core->io); + rz_io_cache_init (core->io); } - r_reg_arena_push (reg); - RConfigHold *chold = r_config_hold_new (core->config); - r_config_hold_i (chold, "io.cache", "asm.lines", NULL); - r_config_set_i (core->config, "io.cache", true); - r_config_set_i (core->config, "asm.lines", false); - const char *strip = r_config_get (core->config, "asm.strip"); - const int max_op_size = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); - int min_op_size = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + rz_reg_arena_push (reg); + RConfigHold *chold = rz_config_hold_new (core->config); + rz_config_hold_i (chold, "io.cache", "asm.lines", NULL); + rz_config_set_i (core->config, "io.cache", true); + rz_config_set_i (core->config, "asm.lines", false); + const char *strip = rz_config_get (core->config, "asm.strip"); + const int max_op_size = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + int min_op_size = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); min_op_size = min_op_size > 0 ? min_op_size : 1; const ut64 read_len = max_op_size > 0 ? max_op_size : 32; size_t buf_sz = 0x100, block_sz = 0, block_instr = 0; - ut64 block_start = r_reg_get_value (reg, pc); + ut64 block_start = rz_reg_get_value (reg, pc); ut8 *buf = malloc (buf_sz); size_t i; for (i = 0; i < nb_opcodes; i++) { - const ut64 op_addr = r_reg_get_value (reg, pc); + const ut64 op_addr = rz_reg_get_value (reg, pc); if (!read_ahead (core->io, &buf, &buf_sz, op_addr, block_sz, read_len)) { break; } - RAnalOp op; - int ret = r_anal_op (core->anal, &op, op_addr, buf + block_sz, read_len, R_ANAL_OP_MASK_ESIL); + RzAnalOp op; + int ret = rz_anal_op (core->anal, &op, op_addr, buf + block_sz, read_len, R_ANAL_OP_MASK_ESIL); const bool invalid_instr = ret < 1 || op.size < 1 || op.type == R_ANAL_OP_TYPE_ILL; bool end_of_block = false; switch (op.type & R_ANAL_OP_TYPE_MASK & ~R_ANAL_OP_HINT_MASK) { @@ -6661,7 +6661,7 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { end_of_block = true; break; } - if (R_STR_ISNOTEMPTY (strip) && strstr (strip, r_anal_optype_to_string (op.type))) { + if (R_STR_ISNOTEMPTY (strip) && strstr (strip, rz_anal_optype_to_string (op.type))) { i--; } else { if (invalid_instr) { @@ -6688,16 +6688,16 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { if (block_instr) { switch (mode) { case R_MODE_JSON: - r_core_print_disasm_json (core, block_start, buf, block_sz, block_instr, pj); + rz_core_print_disasm_json (core, block_start, buf, block_sz, block_instr, pj); break; case R_MODE_SIMPLE: - r_core_disasm_pdi_with_buf (core, block_start, buf, block_instr, block_sz, 0); + rz_core_disasm_pdi_with_buf (core, block_start, buf, block_instr, block_sz, 0); break; case R_MODE_SIMPLEST: - r_core_print_disasm_instructions_with_buf (core, block_start, buf, block_sz, block_instr); + rz_core_print_disasm_instructions_with_buf (core, block_start, buf, block_sz, block_instr); break; default: - r_core_print_disasm (core->print, core, block_start, buf, block_sz, block_instr, 0, 0, false, NULL, NULL); + rz_core_print_disasm (core->print, core, block_start, buf, block_sz, block_instr, 0, 0, false, NULL, NULL); break; } } @@ -6707,40 +6707,40 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) { if (invalid_instr) { break; } - r_anal_esil_set_pc (core->anal->esil, op_addr); - r_reg_set_value (reg, pc, op_addr + op.size); - const char *e = r_strbuf_get (&op.esil); + rz_anal_esil_set_pc (core->anal->esil, op_addr); + rz_reg_set_value (reg, pc, op_addr + op.size); + const char *e = rz_strbuf_get (&op.esil); if (R_STR_ISNOTEMPTY (e)) { - r_anal_esil_parse (esil, e); + rz_anal_esil_parse (esil, e); } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); if (end_of_block) { - block_start = r_reg_get_value (reg, pc); - r_core_seek_arch_bits (core, block_start); + block_start = rz_reg_get_value (reg, pc); + rz_core_seek_arch_bits (core, block_start); } } if (mode == R_MODE_JSON) { pj_end (pj); - r_cons_print (pj_string (pj)); + rz_cons_print (pj_string (pj)); pj_free (pj); } free (buf); - r_reg_arena_pop (reg); - int len = r_list_length (ocache); - if (r_list_length (core->io->cache) > len) { + rz_reg_arena_pop (reg); + int len = rz_list_length (ocache); + if (rz_list_length (core->io->cache) > len) { // TODO: Implement push/pop for IO.cache while (len > 0) { - (void)r_list_pop_head (core->io->cache); + (void)rz_list_pop_head (core->io->cache); len--; } core->io->cache->free = ocache->free; } - r_io_cache_fini (core->io); + rz_io_cache_fini (core->io); core->io->cache = ocache; core->io->buffer = ocacheb; core->io->cached = ocached; - r_config_hold_restore (chold); - r_config_hold_free (chold); + rz_config_hold_restore (chold); + rz_config_hold_free (chold); return i; } diff --git a/libr/core/disasm_stackptr.inc b/librz/core/disasm_stackptr.inc similarity index 78% rename from libr/core/disasm_stackptr.inc rename to librz/core/disasm_stackptr.inc index b476fec0f3..7af8361328 100644 --- a/libr/core/disasm_stackptr.inc +++ b/librz/core/disasm_stackptr.inc @@ -3,7 +3,7 @@ #define USE_BB_STACKPTR 0 #define USE_BB_LINEAR 1 -static void ds_update_stackptr(RDisasmState *ds, RAnalOp *op) { +static void ds_update_stackptr(RDisasmState *ds, RzAnalOp *op) { if (!ds->show_stackptr) { return; } @@ -21,7 +21,7 @@ static void ds_update_stackptr(RDisasmState *ds, RAnalOp *op) { break; } /* XXX if we reset the stackptr 'ret 0x4' has not effect. - * Use RAnalFunction->RAnalOp->stackptr? */ + * Use RzAnalFunction->RzAnalOp->stackptr? */ if (op->type == R_ANAL_OP_TYPE_RET) { ds->stackptr = 0; } @@ -32,7 +32,7 @@ static int _stackptr_range(RDisasmState *ds, ut64 addr, ut64 addr_end, int stack ut64 end = addr_end; while (at < end) { int sz = 1; - RAnalOp* op = r_core_anal_op (ds->core, at, 0); + RzAnalOp* op = rz_core_anal_op (ds->core, at, 0); if (op) { *ostackptr = stackptr; switch (op->stackop) { @@ -49,7 +49,7 @@ static int _stackptr_range(RDisasmState *ds, ut64 addr, ut64 addr_end, int stack if (op->size > 0) { sz = op->size; } - r_anal_op_free (op); + rz_anal_op_free (op); } at += sz; } @@ -70,14 +70,14 @@ static int ds_ostackptr_atfcn(RDisasmState *ds, int *ostackptr) { // SLOW, recursive emulation is more correct, but slow to find paths // return stackptr; ut64 addr = ds->at; - RList *paths = r_core_anal_graph_to (ds->core, addr, 2); + RzList *paths = rz_core_anal_graph_to (ds->core, addr, 2); if (paths) { - RAnalBlock *bb; - RList *path; - RListIter *pathi; - RListIter *bbi; - r_list_foreach (paths, pathi, path) { - r_list_foreach (path, bbi, bb) { + RzAnalBlock *bb; + RzList *path; + RzListIter *pathi; + RzListIter *bbi; + rz_list_foreach (paths, pathi, path) { + rz_list_foreach (path, bbi, bb) { ut64 end = bb->addr + bb->size; if (addr >= bb->addr && addr < bb->addr + bb->size) { end = addr; @@ -85,7 +85,7 @@ static int ds_ostackptr_atfcn(RDisasmState *ds, int *ostackptr) { stackptr = _stackptr_range (ds, bb->addr, end, stackptr, ostackptr); } } - r_list_free (paths); + rz_list_free (paths); } return stackptr; #endif @@ -95,13 +95,13 @@ static int ds_ostackptr_at(RDisasmState *ds, int *ostackptr) { #if USE_BB_STACKPTR // XXX doesnt works because bb->stackptr returns the maximum increment of the bb instead of the initial stackptr value *ostackptr = ds->ostackptr; - RAnalFunction *fcn = r_anal_get_fcn_in (ds->core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (ds->core->anal, ds->at, R_ANAL_FCN_TYPE_NULL); if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (ds->core->anal, fcn, ds->at); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (ds->core->anal, fcn, ds->at); if (bb) { return bb->stackptr; } else { - r_warn_if_reached (); + rz_warn_if_reached (); } } return 0; @@ -117,7 +117,7 @@ static int ds_ostackptr_at(RDisasmState *ds, int *ostackptr) { static void ds_print_stackptr(RDisasmState *ds) { int ostackptr, stackptr = ds_ostackptr_at (ds, &ostackptr); if (ds->show_stackptr) { - r_cons_printf ("%5d%s", stackptr, + rz_cons_printf ("%5d%s", stackptr, ds->analop.type == R_ANAL_OP_TYPE_CALL?">": ds->analop.stackop == R_ANAL_STACK_ALIGN? "=": stackptr > ostackptr? "+": diff --git a/libr/core/fortune.c b/librz/core/fortune.c similarity index 52% rename from libr/core/fortune.c rename to librz/core/fortune.c index 64eb44a0d9..4265faa471 100644 --- a/libr/core/fortune.c +++ b/librz/core/fortune.c @@ -1,31 +1,31 @@ -/* radare2 - LGPL - Copyright 2009-2020 - pancake */ +/* rizin - LGPL - Copyright 2009-2020 - pancake */ -#include +#include static const char *fortunes[] = { "tips", "fun", "nsfw", "creepy" }; -static char *getFortuneFile(RCore *core, const char *type) { - return r_str_newf (R_JOIN_3_PATHS ("%s", R2_FORTUNES, "fortunes.%s"), - r_sys_prefix (NULL), type); +static char *getFortuneFile(RzCore *core, const char *type) { + return rz_str_newf (R_JOIN_3_PATHS ("%s", R2_FORTUNES, "fortunes.%s"), + rz_sys_prefix (NULL), type); } -R_API void r_core_fortune_list_types(void) { +RZ_API void rz_core_fortune_list_types(void) { size_t i; for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) { - r_cons_printf ("%s\n", fortunes[i]); + rz_cons_printf ("%s\n", fortunes[i]); } } -R_API void r_core_fortune_list(RCore *core) { +RZ_API void rz_core_fortune_list(RzCore *core) { // TODO: use file.fortunes // can be dangerous in sandbox mode - const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type"); + const char *types = (char *)rz_config_get (core->config, "cfg.fortunes.type"); size_t i, j; for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) { if (strstr (types, fortunes[i])) { char *file = getFortuneFile (core, fortunes[i]); - char *str = r_file_slurp (file, NULL); + char *str = rz_file_slurp (file, NULL); if (!str) { free (file); continue; @@ -34,7 +34,7 @@ R_API void r_core_fortune_list(RCore *core) { if (str[j] == '\n') { if (i < j) { str[j] = '\0'; - r_cons_printf ("%s\n", str + i); + rz_cons_printf ("%s\n", str + i); } i = j + 1; } @@ -45,15 +45,15 @@ R_API void r_core_fortune_list(RCore *core) { } } -static char *getrandomline(RCore *core) { +static char *getrandomline(RzCore *core) { size_t i; - const char *types = (char *)r_config_get (core->config, "cfg.fortunes.type"); + const char *types = (char *)rz_config_get (core->config, "cfg.fortunes.type"); char *line = NULL, *templine; for (i = 0; i < R_ARRAY_SIZE (fortunes); i++) { if (strstr (types, fortunes[i])) { int lines = 0; char *file = getFortuneFile(core, fortunes[i]); - templine = r_file_slurp_random_line_count (file, &lines); + templine = rz_file_slurp_random_line_count (file, &lines); if (templine && *templine) { free (line); line = templine; @@ -64,20 +64,20 @@ static char *getrandomline(RCore *core) { return line; } -R_API void r_core_fortune_print_random(RCore *core) { +RZ_API void rz_core_fortune_print_random(RzCore *core) { // TODO: use file.fortunes // can be dangerous in sandbox mode char *line = getrandomline (core); if (!line) { line = getrandomline (core); } if (line) { - if (r_config_get_i (core->config, "cfg.fortunes.clippy")) { - r_core_clippy (core, line); + if (rz_config_get_i (core->config, "cfg.fortunes.clippy")) { + rz_core_clippy (core, line); } else { - r_cons_printf (" -- %s\n", line); + rz_cons_printf (" -- %s\n", line); } - if (r_config_get_i (core->config, "cfg.fortunes.tts")) { - r_sys_tts (line, true); + if (rz_config_get_i (core->config, "cfg.fortunes.tts")) { + rz_sys_tts (line, true); } free (line); } diff --git a/libr/core/gdiff.c b/librz/core/gdiff.c similarity index 53% rename from libr/core/gdiff.c rename to librz/core/gdiff.c index 8151ef09ed..e33315a7b2 100644 --- a/libr/core/gdiff.c +++ b/librz/core/gdiff.c @@ -2,42 +2,42 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -R_API int r_core_gdiff_fcn(RCore *c, ut64 addr, ut64 addr2) { - RList *la, *lb; - RAnalFunction *fa = r_anal_get_function_at (c->anal, addr); - RAnalFunction *fb = r_anal_get_function_at (c->anal, addr2); +RZ_API int rz_core_gdiff_fcn(RzCore *c, ut64 addr, ut64 addr2) { + RzList *la, *lb; + RzAnalFunction *fa = rz_anal_get_function_at (c->anal, addr); + RzAnalFunction *fb = rz_anal_get_function_at (c->anal, addr2); if (!fa || !fb) { return false; } - RAnalBlock *bb; - RListIter *iter; - r_list_foreach (fa->bbs, iter, bb) { - r_anal_diff_fingerprint_bb (c->anal, bb); + RzAnalBlock *bb; + RzListIter *iter; + rz_list_foreach (fa->bbs, iter, bb) { + rz_anal_diff_fingerprint_bb (c->anal, bb); } - r_list_foreach (fb->bbs, iter, bb) { - r_anal_diff_fingerprint_bb (c->anal, bb); + rz_list_foreach (fb->bbs, iter, bb) { + rz_anal_diff_fingerprint_bb (c->anal, bb); } - la = r_list_new (); - r_list_append (la, fa); - lb = r_list_new (); - r_list_append (lb, fb); - r_anal_diff_fcn (c->anal, la, lb); - r_list_free (la); - r_list_free (lb); + la = rz_list_new (); + rz_list_append (la, fa); + lb = rz_list_new (); + rz_list_append (lb, fb); + rz_anal_diff_fcn (c->anal, la, lb); + rz_list_free (la); + rz_list_free (lb); return true; } /* Fingerprint functions and blocks, then diff. */ -R_API int r_core_gdiff(RCore *c, RCore *c2) { - RCore *cores[2] = {c, c2}; - RAnalFunction *fcn; - RAnalBlock *bb; - RListIter *iter, *iter2; +RZ_API int rz_core_gdiff(RzCore *c, RzCore *c2) { + RzCore *cores[2] = {c, c2}; + RzAnalFunction *fcn; + RzAnalBlock *bb; + RzListIter *iter, *iter2; int i; if (!c || !c2) { @@ -45,29 +45,29 @@ R_API int r_core_gdiff(RCore *c, RCore *c2) { } for (i = 0; i < 2; i++) { /* remove strings */ - r_list_foreach_safe (cores[i]->anal->fcns, iter, iter2, fcn) { + rz_list_foreach_safe (cores[i]->anal->fcns, iter, iter2, fcn) { if (!strncmp (fcn->name, "str.", 4)) { - r_anal_function_delete (fcn); + rz_anal_function_delete (fcn); } } /* Fingerprint fcn bbs (functions basic-blocks) */ - r_list_foreach (cores[i]->anal->fcns, iter, fcn) { - r_list_foreach (fcn->bbs, iter2, bb) { - r_anal_diff_fingerprint_bb (cores[i]->anal, bb); + rz_list_foreach (cores[i]->anal->fcns, iter, fcn) { + rz_list_foreach (fcn->bbs, iter2, bb) { + rz_anal_diff_fingerprint_bb (cores[i]->anal, bb); } } /* Fingerprint fcn */ - r_list_foreach (cores[i]->anal->fcns, iter, fcn) { - r_anal_diff_fingerprint_fcn (cores[i]->anal, fcn); + rz_list_foreach (cores[i]->anal->fcns, iter, fcn) { + rz_anal_diff_fingerprint_fcn (cores[i]->anal, fcn); } } /* Diff functions */ - r_anal_diff_fcn (cores[0]->anal, cores[0]->anal->fcns, cores[1]->anal->fcns); + rz_anal_diff_fcn (cores[0]->anal, cores[0]->anal->fcns, cores[1]->anal->fcns); return true; } -/* copypasta from radiff2 */ +/* copypasta from rz_diff */ static void diffrow(ut64 addr, const char *name, ut32 size, int maxnamelen, int digits, ut64 addr2, const char *name2, ut32 size2, const char *match, double dist, int bare) { @@ -89,32 +89,32 @@ static void diffrow(ut64 addr, const char *name, ut32 size, int maxnamelen, } } -R_API void r_core_diff_show(RCore *c, RCore *c2) { - bool bare = r_config_get_i (c->config, "diff.bare") || r_config_get_i (c2->config, "diff.bare"); - RList *fcns = r_anal_get_fcns (c->anal); +RZ_API void rz_core_diff_show(RzCore *c, RzCore *c2) { + bool bare = rz_config_get_i (c->config, "diff.bare") || rz_config_get_i (c2->config, "diff.bare"); + RzList *fcns = rz_anal_get_fcns (c->anal); const char *match; - RListIter *iter; - RAnalFunction *f; + RzListIter *iter; + RzAnalFunction *f; int maxnamelen = 0; ut64 maxsize = 0; int digits = 1; int len; - r_list_foreach (fcns, iter, f) { + rz_list_foreach (fcns, iter, f) { if (f->name && (len = strlen (f->name)) > maxnamelen) { maxnamelen = len; } - if (r_anal_function_linear_size (f) > maxsize) { - maxsize = r_anal_function_linear_size (f); + if (rz_anal_function_linear_size (f) > maxsize) { + maxsize = rz_anal_function_linear_size (f); } } - fcns = r_anal_get_fcns (c2->anal); - r_list_foreach (fcns, iter, f) { + fcns = rz_anal_get_fcns (c2->anal); + rz_list_foreach (fcns, iter, f) { if (f->name && (len = strlen (f->name)) > maxnamelen) { maxnamelen = len; } - if (r_anal_function_linear_size (f) > maxsize) { - maxsize = r_anal_function_linear_size (f); + if (rz_anal_function_linear_size (f) > maxsize) { + maxsize = rz_anal_function_linear_size (f); } } while (maxsize > 9) { @@ -122,14 +122,14 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) { digits++; } - fcns = r_anal_get_fcns (c->anal); - if (r_list_empty (fcns)) { + fcns = rz_anal_get_fcns (c->anal); + if (rz_list_empty (fcns)) { eprintf ("No functions found, try running with -A or load a project\n"); return; } - r_list_sort (fcns, c->anal->columnSort); + rz_list_sort (fcns, c->anal->columnSort); - r_list_foreach (fcns, iter, f) { + rz_list_foreach (fcns, iter, f) { switch (f->type) { case R_ANAL_FCN_TYPE_FCN: case R_ANAL_FCN_TYPE_SYM: @@ -144,20 +144,20 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) { match = "NEW"; f->diff->dist = 0; } - diffrow (f->addr, f->name, r_anal_function_linear_size (f), maxnamelen, digits, + diffrow (f->addr, f->name, rz_anal_function_linear_size (f), maxnamelen, digits, f->diff->addr, f->diff->name, f->diff->size, match, f->diff->dist, bare); break; } } - fcns = r_anal_get_fcns (c2->anal); - r_list_sort (fcns, c2->anal->columnSort); - r_list_foreach (fcns, iter, f) { + fcns = rz_anal_get_fcns (c2->anal); + rz_list_sort (fcns, c2->anal->columnSort); + rz_list_foreach (fcns, iter, f) { switch (f->type) { case R_ANAL_FCN_TYPE_FCN: case R_ANAL_FCN_TYPE_SYM: if (f->diff->type == R_ANAL_DIFF_TYPE_NULL) { - diffrow (f->addr, f->name, r_anal_function_linear_size (f), maxnamelen, + diffrow (f->addr, f->name, rz_anal_function_linear_size (f), maxnamelen, digits, f->diff->addr, f->diff->name, f->diff->size, "NEW", 0, bare); //f->diff->dist, bare); } diff --git a/libr/core/hack.c b/librz/core/hack.c similarity index 67% rename from libr/core/hack.c rename to librz/core/hack.c index 1d3dc94934..063672a417 100644 --- a/libr/core/hack.c +++ b/librz/core/hack.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include +#include /* We can not use some kind of structure type with * a string for each case, because some architectures (like ARM) * have several modes/alignment requirements. */ -void r_core_hack_help(const RCore *core) { +void rz_core_hack_help(const RzCore *core) { const char* help_msg[] = { "wao", " [op]", "performs a modification on current opcode", "wao", " nop", "nop current opcode", @@ -23,20 +23,20 @@ void r_core_hack_help(const RCore *core) { "WIP:", "", "not all archs are supported and not all commands work on all archs", NULL }; - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); } -R_API bool r_core_hack_dalvik(RCore *core, const char *op, const RAnalOp *analop) { +RZ_API bool rz_core_hack_dalvik(RzCore *core, const char *op, const RzAnalOp *analop) { if (!strcmp (op, "nop")) { - r_core_cmdf (core, "wx 0000"); + rz_core_cmdf (core, "wx 0000"); } else if (!strcmp (op, "ret2")) { - r_core_cmdf (core, "wx 12200f00"); // mov v0, 2;ret v0 + rz_core_cmdf (core, "wx 12200f00"); // mov v0, 2;ret v0 } else if (!strcmp (op, "jinf")) { - r_core_cmd0 (core, "wx 2800\n"); + rz_core_cmd0 (core, "wx 2800\n"); } else if (!strcmp (op, "ret1")) { - r_core_cmdf (core, "wx 12100f00"); // mov v0, 1;ret v0 + rz_core_cmdf (core, "wx 12100f00"); // mov v0, 1;ret v0 } else if (!strcmp (op, "ret0")) { - r_core_cmdf (core, "wx 12000f00"); // mov v0, 0;ret v0 + rz_core_cmdf (core, "wx 12000f00"); // mov v0, 0;ret v0 } else { eprintf ("Unsupported operation '%s'\n", op); return false; @@ -44,18 +44,18 @@ R_API bool r_core_hack_dalvik(RCore *core, const char *op, const RAnalOp *analop return true; } -R_API bool r_core_hack_arm64(RCore *core, const char *op, const RAnalOp *analop) { +RZ_API bool rz_core_hack_arm64(RzCore *core, const char *op, const RzAnalOp *analop) { if (!strcmp (op, "nop")) { - r_core_cmdf (core, "wx 1f2003d5"); + rz_core_cmdf (core, "wx 1f2003d5"); } else if (!strcmp (op, "ret")) { - r_core_cmdf (core, "wx c0035fd6t"); + rz_core_cmdf (core, "wx c0035fd6t"); } else if (!strcmp (op, "trap")) { - r_core_cmdf (core, "wx 000020d4"); + rz_core_cmdf (core, "wx 000020d4"); } else if (!strcmp (op, "jz")) { eprintf ("ARM jz hack not supported\n"); return false; } else if (!strcmp (op, "jinf")) { - r_core_cmdf (core, "wx 00000014"); + rz_core_cmdf (core, "wx 00000014"); } else if (!strcmp (op, "jnz")) { eprintf ("ARM jnz hack not supported\n"); return false; @@ -66,18 +66,18 @@ R_API bool r_core_hack_arm64(RCore *core, const char *op, const RAnalOp *analop) eprintf ("TODO: use jnz or jz\n"); return false; } else if (!strcmp (op, "ret1")) { - r_core_cmdf (core, "wa mov x0, 1,,ret"); + rz_core_cmdf (core, "wa mov x0, 1,,ret"); } else if (!strcmp (op, "ret0")) { - r_core_cmdf (core, "wa mov x0, 0,,ret"); + rz_core_cmdf (core, "wa mov x0, 0,,ret"); } else if (!strcmp (op, "retn")) { - r_core_cmdf (core, "wa mov x0, -1,,ret"); + rz_core_cmdf (core, "wa mov x0, -1,,ret"); } else { eprintf ("Invalid operation '%s'\n", op); return false; } return true; } -R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { +RZ_API bool rz_core_hack_arm(RzCore *core, const char *op, const RzAnalOp *analop) { const int bits = core->rasm->bits; const ut8 *b = core->block; @@ -101,24 +101,24 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { memcpy (str + i * 2, nopcode, nopsize*2); } str[len*2] = '\0'; - r_core_cmdf (core, "wx %s\n", str); + rz_core_cmdf (core, "wx %s\n", str); free (str); } else if (!strcmp (op, "jinf")) { - r_core_cmdf (core, "wx %s\n", (bits==16)? "fee7": "feffffea"); + rz_core_cmdf (core, "wx %s\n", (bits==16)? "fee7": "feffffea"); } else if (!strcmp (op, "trap")) { const char* trapcode = (bits==16)? "bebe": "fedeffe7"; - r_core_cmdf (core, "wx %s\n", trapcode); + rz_core_cmdf (core, "wx %s\n", trapcode); } else if (!strcmp (op, "jz")) { if (bits == 16) { switch (b[1]) { case 0xb9: // CBNZ - r_core_cmd0 (core, "wx b1 @@ $$+1\n"); //CBZ + rz_core_cmd0 (core, "wx b1 @@ $$+1\n"); //CBZ break; case 0xbb: // CBNZ - r_core_cmd0 (core, "wx b3 @@ $$+1\n"); //CBZ + rz_core_cmd0 (core, "wx b3 @@ $$+1\n"); //CBZ break; case 0xd1: // BNE - r_core_cmd0 (core, "wx d0 @@ $$+1\n"); //BEQ + rz_core_cmd0 (core, "wx d0 @@ $$+1\n"); //BEQ break; default: eprintf ("Current opcode is not conditional\n"); @@ -132,13 +132,13 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { if (bits == 16) { switch (b[1]) { case 0xb1: // CBZ - r_core_cmd0 (core, "wx b9 @@ $$+1\n"); //CBNZ + rz_core_cmd0 (core, "wx b9 @@ $$+1\n"); //CBNZ break; case 0xb3: // CBZ - r_core_cmd0 (core, "wx bb @@ $$+1\n"); //CBNZ + rz_core_cmd0 (core, "wx bb @@ $$+1\n"); //CBNZ break; case 0xd0: // BEQ - r_core_cmd0 (core, "wx d1 @@ $$+1\n"); //BNE + rz_core_cmd0 (core, "wx d1 @@ $$+1\n"); //BNE break; default: eprintf ("Current opcode is not conditional\n"); @@ -158,7 +158,7 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { case 0xb9: // CBNZ case 0xbb: // CBNZ case 0xd1: // BNE - r_core_cmd0 (core, "wx e0 @@ $$+1\n"); //BEQ + rz_core_cmd0 (core, "wx e0 @@ $$+1\n"); //BEQ break; default: eprintf ("Current opcode is not conditional\n"); @@ -173,21 +173,21 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { return false; } else if (!strcmp (op, "ret1")) { if (bits == 16) { - r_core_cmd0 (core, "wx 01207047 @@ $$+1\n"); // mov r0, 1; bx lr + rz_core_cmd0 (core, "wx 01207047 @@ $$+1\n"); // mov r0, 1; bx lr } else { - r_core_cmd0 (core, "wx 0100b0e31eff2fe1 @@ $$+1\n"); // movs r0, 1; bx lr + rz_core_cmd0 (core, "wx 0100b0e31eff2fe1 @@ $$+1\n"); // movs r0, 1; bx lr } } else if (!strcmp (op, "ret0")) { if (bits == 16) { - r_core_cmd0 (core, "wx 00207047 @@ $$+1\n"); // mov r0, 0; bx lr + rz_core_cmd0 (core, "wx 00207047 @@ $$+1\n"); // mov r0, 0; bx lr } else { - r_core_cmd0 (core, "wx 0000a0e31eff2fe1 @@ $$+1\n"); // movs r0, 0; bx lr + rz_core_cmd0 (core, "wx 0000a0e31eff2fe1 @@ $$+1\n"); // movs r0, 0; bx lr } } else if (!strcmp (op, "retn")) { if (bits == 16) { - r_core_cmd0 (core, "wx ff207047 @@ $$+1\n"); // mov r0, -1; bx lr + rz_core_cmd0 (core, "wx ff207047 @@ $$+1\n"); // mov r0, -1; bx lr } else { - r_core_cmd0 (core, "wx ff00a0e31eff2fe1 @@ $$+1\n"); // movs r0, -1; bx lr + rz_core_cmd0 (core, "wx ff00a0e31eff2fe1 @@ $$+1\n"); // movs r0, -1; bx lr } } else { eprintf ("Invalid operation\n"); @@ -196,7 +196,7 @@ R_API bool r_core_hack_arm(RCore *core, const char *op, const RAnalOp *analop) { return true; } -R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) { +RZ_API bool rz_core_hack_x86(RzCore *core, const char *op, const RzAnalOp *analop) { const ut8 *b = core->block; int i, size = analop->size; if (!strcmp (op, "nop")) { @@ -211,31 +211,31 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) { memcpy (str + (i * 2), "90", 2); } str[size*2] = '\0'; - r_core_cmdf (core, "wx %s\n", str); + rz_core_cmdf (core, "wx %s\n", str); free (str); } else if (!strcmp (op, "trap")) { - r_core_cmd0 (core, "wx cc\n"); + rz_core_cmd0 (core, "wx cc\n"); } else if (!strcmp (op, "jz")) { if (b[0] == 0x75) { - r_core_cmd0 (core, "wx 74\n"); + rz_core_cmd0 (core, "wx 74\n"); } else { eprintf ("Current opcode is not conditional\n"); return false; } } else if (!strcmp (op, "jinf")) { - r_core_cmd0 (core, "wx ebfe\n"); + rz_core_cmd0 (core, "wx ebfe\n"); } else if (!strcmp (op, "jnz")) { if (b[0] == 0x74) { - r_core_cmd0 (core, "wx 75\n"); + rz_core_cmd0 (core, "wx 75\n"); } else { eprintf ("Current opcode is not conditional\n"); return false; } } else if (!strcmp (op, "nocj")) { if (*b == 0xf) { - r_core_cmd0 (core, "wx 90e9"); + rz_core_cmd0 (core, "wx 90e9"); } else if (b[0] >= 0x70 && b[0] <= 0x7f) { - r_core_cmd0 (core, "wx eb"); + rz_core_cmd0 (core, "wx eb"); } else { eprintf ("Current opcode is not conditional\n"); return false; @@ -243,19 +243,19 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) { } else if (!strcmp (op, "recj")) { int is_near = (*b == 0xf); if (b[0] < 0x80 && b[0] >= 0x70) { // short jmps: jo, jno, jb, jae, je, jne, jbe, ja, js, jns - r_core_cmdf (core, "wx %x\n", (b[0]%2)? b[0] - 1: b[0] + 1); + rz_core_cmdf (core, "wx %x\n", (b[0]%2)? b[0] - 1: b[0] + 1); } else if (is_near && b[1] < 0x90 && b[1] >= 0x80) { // near jmps: jo, jno, jb, jae, je, jne, jbe, ja, js, jns - r_core_cmdf (core, "wx 0f%x\n", (b[1]%2)? b[1] - 1: b[1] + 1); + rz_core_cmdf (core, "wx 0f%x\n", (b[1]%2)? b[1] - 1: b[1] + 1); } else { eprintf ("Invalid conditional jump opcode\n"); return false; } } else if (!strcmp (op, "ret1")) { - r_core_cmd0 (core, "wx c20100\n"); + rz_core_cmd0 (core, "wx c20100\n"); } else if (!strcmp (op, "ret0")) { - r_core_cmd0 (core, "wx c20000\n"); + rz_core_cmd0 (core, "wx c20000\n"); } else if (!strcmp (op, "retn")) { - r_core_cmd0 (core, "wx c2ffff\n"); + rz_core_cmd0 (core, "wx c2ffff\n"); } else { eprintf ("Invalid operation '%s'\n", op); return false; @@ -263,30 +263,30 @@ R_API bool r_core_hack_x86(RCore *core, const char *op, const RAnalOp *analop) { return true; } -R_API int r_core_hack(RCore *core, const char *op) { - bool (*hack)(RCore *core, const char *op, const RAnalOp *analop) = NULL; - const char *asmarch = r_config_get (core->config, "asm.arch"); +RZ_API int rz_core_hack(RzCore *core, const char *op) { + bool (*hack)(RzCore *core, const char *op, const RzAnalOp *analop) = NULL; + const char *asmarch = rz_config_get (core->config, "asm.arch"); const int asmbits = core->rasm->bits; if (!asmarch) { return false; } if (strstr (asmarch, "x86")) { - hack = r_core_hack_x86; + hack = rz_core_hack_x86; } else if (strstr (asmarch, "dalvik")) { - hack = r_core_hack_dalvik; + hack = rz_core_hack_dalvik; } else if (strstr (asmarch, "arm")) { if (asmbits == 64) { - hack = r_core_hack_arm64; + hack = rz_core_hack_arm64; } else { - hack = r_core_hack_arm; + hack = rz_core_hack_arm; } } else { eprintf ("TODO: write hacks are only for x86\n"); } if (hack) { - RAnalOp analop; - if (!r_anal_op (core->anal, &analop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { + RzAnalOp analop; + if (!rz_anal_op (core->anal, &analop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { eprintf ("anal op fail\n"); return false; } diff --git a/librz/core/libs.c b/librz/core/libs.c new file mode 100644 index 0000000000..e71e23e35d --- /dev/null +++ b/librz/core/libs.c @@ -0,0 +1,148 @@ +/* radare - LGPL - Copyright 2009-2020 - pancake */ + +#include "rz_core.h" +#include "config.h" + +#define CB(x, y)\ + static int __lib_ ## x ## _cb (RzLibPlugin * pl, void *user, void *data) {\ + struct rz_ ## x ## _plugin_t *hand = (struct rz_ ## x ## _plugin_t *)data;\ + RzCore *core = (RzCore *) user;\ + pl->free = NULL; \ + rz_ ## x ## _add (core->y, hand);\ + return true;\ + }\ + static int __lib_ ## x ## _dt (RzLibPlugin * pl, void *p, void *u) { return true; } + +#define CB_COPY(x, y)\ + static int __lib_ ## x ## _cb (RzLibPlugin * pl, void *user, void *data) {\ + struct rz_ ## x ## _plugin_t *hand = (struct rz_ ## x ## _plugin_t *)data;\ + struct rz_ ## x ## _plugin_t *instance;\ + RzCore *core = (RzCore *) user;\ + instance = R_NEW (struct rz_ ## x ## _plugin_t);\ + memcpy (instance, hand, sizeof (struct rz_ ## x ## _plugin_t));\ + rz_ ## x ## _add (core->y, instance);\ + return true;\ + }\ + static int __lib_ ## x ## _dt (RzLibPlugin * pl, void *p, void *u) { return true; } + +// XXX api consistency issues +#define rz_io_add rz_io_plugin_add +CB_COPY (io, io) +#define rz_core_add rz_core_plugin_add +CB (core, rcmd) +#define rz_debug_add rz_debug_plugin_add +CB (debug, dbg) +#define rz_bp_add rz_bp_plugin_add +CB (bp, dbg->bp) +CB (lang, lang) +CB (anal, anal) +CB (asm, rasm) +CB (parse, parser) +CB (bin, bin) +CB (egg, egg) +CB (fs, fs) + +static void __openPluginsAt(RzCore *core, const char *arg, const char *user_path) { + if (arg && *arg) { + if (user_path) { + if (rz_str_endswith (user_path, arg)) { + return; + } + } + char *pdir = rz_str_rz_prefix (arg); + if (pdir) { + rz_lib_opendir (core->lib, pdir); + free (pdir); + } + } +} + +static void __loadSystemPlugins(RzCore *core, int where, const char *path) { +#if R2_LOADLIBS + if (!where) { + where = -1; + } + if (path) { + rz_lib_opendir (core->lib, path); + } + const char *dir_plugins = rz_config_get (core->config, "dir.plugins"); + if (where & R_CORE_LOADLIBS_CONFIG) { + rz_lib_opendir (core->lib, dir_plugins); + } + if (where & R_CORE_LOADLIBS_ENV) { + char *p = rz_sys_getenv (R_LIB_ENV); + if (p && *p) { + rz_lib_opendir (core->lib, p); + } + free (p); + } + if (where & R_CORE_LOADLIBS_HOME) { + char *hpd = rz_str_home (R2_HOME_PLUGINS); + if (hpd) { + rz_lib_opendir (core->lib, hpd); + free (hpd); + } + } + if (where & R_CORE_LOADLIBS_SYSTEM) { + __openPluginsAt (core, R2_PLUGINS, dir_plugins); + __openPluginsAt (core, R2_EXTRAS, dir_plugins); + __openPluginsAt (core, R2_BINDINGS, dir_plugins); + } +#endif +} + +RZ_API void rz_core_loadlibs_init(RzCore *core) { + ut64 prev = rz_time_now_mono (); +#define DF(x, y, z) rz_lib_add_handler (core->lib, R_LIB_TYPE_ ## x, y, &__lib_ ## z ## _cb, &__lib_ ## z ## _dt, core); + core->lib = rz_lib_new (NULL, NULL); + DF (IO, "io plugins", io); + DF (CORE, "core plugins", core); + DF (DBG, "debugger plugins", debug); + DF (BP, "debugger breakpoint plugins", bp); + DF (LANG, "language plugins", lang); + DF (ANAL, "analysis plugins", anal); + DF (ASM, "(dis)assembler plugins", asm); + DF (PARSE, "parsing plugins", parse); + DF (BIN, "bin plugins", bin); + DF (EGG, "egg plugins", egg); + DF (FS, "fs plugins", fs); + core->times->loadlibs_init_time = rz_time_now_mono () - prev; +} + +static bool __isScriptFilename(const char *name) { + const char *ext = rz_str_lchr (name, '.'); + if (ext) { + ext++; + if (!strcmp (ext, "py") + || !strcmp (ext, "js") + || !strcmp (ext, "lua")) { + return true; + } + } + return false; +} + +RZ_API int rz_core_loadlibs(RzCore *core, int where, const char *path) { + ut64 prev = rz_time_now_mono (); + __loadSystemPlugins (core, where, path); + /* TODO: all those default plugin paths should be defined in rz_lib */ + if (!rz_config_get_i (core->config, "cfg.plugins")) { + core->times->loadlibs_time = 0; + return false; + } + // load script plugins + char *homeplugindir = rz_str_home (R2_HOME_PLUGINS); + RzList *files = rz_sys_dir (homeplugindir); + RzListIter *iter; + char *file; + rz_list_foreach (files, iter, file) { + if (__isScriptFilename (file)) { + rz_core_cmdf (core, ". %s/%s", homeplugindir, file); + } + } + + free (homeplugindir); + core->times->loadlibs_time = rz_time_now_mono () - prev; + rz_list_free (files); + return true; +} diff --git a/libr/core/linux_heap_glibc.c b/librz/core/linux_heap_glibc.c similarity index 69% rename from libr/core/linux_heap_glibc.c rename to librz/core/linux_heap_glibc.c index f8f4977ba5..c349967a9c 100644 --- a/libr/core/linux_heap_glibc.c +++ b/librz/core/linux_heap_glibc.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2016-2020 - n4x0r, soez, pancake */ +/* rizin - LGPL - Copyright 2016-2020 - n4x0r, soez, pancake */ #ifndef INCLUDE_HEAP_GLIBC_C #define INCLUDE_HEAP_GLIBC_C -#include "r_config.h" +#include "rz_config.h" #define HEAP32 1 #include "linux_heap_glibc.c" #undef HEAP32 @@ -17,50 +17,50 @@ #define GH(x) x##_32 #define GHT ut32 #define GHT_MAX UT32_MAX -#define read_le(x) r_read_le##32(x) +#define read_le(x) rz_read_le##32(x) #else #define GH(x) x##_64 #define GHT ut64 #define GHT_MAX UT64_MAX -#define read_le(x) r_read_le##64(x) +#define read_le(x) rz_read_le##64(x) #endif /** * \brief Find the address of a given symbol - * \param core RCore Pointer to the r2's core + * \param core RzCore Pointer to the r2's core * \param path Pointer to the binary path in which to look for the symbol * \param sym_name Pointer to the symbol's name to search for * \return address * * Used to find the address of a given symbol inside a binary * - * TODO: Stop using deprecated functions like r_bin_cur + * TODO: Stop using deprecated functions like rz_bin_cur */ -static GHT GH(get_va_symbol)(RCore *core, const char *path, const char *sym_name) { +static GHT GH(get_va_symbol)(RzCore *core, const char *path, const char *sym_name) { GHT vaddr = GHT_MAX; RBin *bin = core->bin; - RBinFile *current_bf = r_bin_cur (bin); - RListIter *iter; + RBinFile *current_bf = rz_bin_cur (bin); + RzListIter *iter; RBinSymbol *s; RBinOptions opt; - r_bin_options_init (&opt, -1, 0, 0, false); - bool res = r_bin_open (bin, path, &opt); + rz_bin_options_init (&opt, -1, 0, 0, false); + bool res = rz_bin_open (bin, path, &opt); if (!res) { return vaddr; } - RList *syms = r_bin_get_symbols (bin); - r_list_foreach (syms, iter, s) { + RzList *syms = rz_bin_get_symbols (bin); + rz_list_foreach (syms, iter, s) { if (!strcmp (s->name, sym_name)) { vaddr = s->vaddr; break; } } - RBinFile *libc_bf = r_bin_cur (bin); - r_bin_file_delete (bin, libc_bf->id); - r_bin_file_set_cur_binfile (bin, current_bf); + RBinFile *libc_bf = rz_bin_cur (bin); + rz_bin_file_delete (bin, libc_bf->id); + rz_bin_file_set_cur_binfile (bin, current_bf); return vaddr; } @@ -68,19 +68,19 @@ static inline GHT GH(align_address_to_size)(ut64 addr, ut64 align) { return addr + ((align - (addr % align)) % align); } -static inline GHT GH(get_next_pointer)(RCore *core, GHT pos, GHT next) { +static inline GHT GH(get_next_pointer)(RzCore *core, GHT pos, GHT next) { return (core->dbg->glibc_version < 232) ? next : PROTECT_PTR (pos, next); } -static GHT GH(get_main_arena_with_symbol)(RCore *core, RDebugMap *map) { - r_return_val_if_fail (core && map, GHT_MAX); +static GHT GH(get_main_arena_with_symbol)(RzCore *core, RzDebugMap *map) { + rz_return_val_if_fail (core && map, GHT_MAX); GHT base_addr = map->addr; - r_return_val_if_fail (base_addr != GHT_MAX, GHT_MAX); + rz_return_val_if_fail (base_addr != GHT_MAX, GHT_MAX); GHT main_arena = GHT_MAX; GHT vaddr = GHT_MAX; char *path = strdup (map->name); - if (path && r_file_exists (path)) { + if (path && rz_file_exists (path)) { vaddr = GH (get_va_symbol) (core, path, "main_arena"); if (vaddr != GHT_MAX) { main_arena = base_addr + vaddr; @@ -89,7 +89,7 @@ static GHT GH(get_main_arena_with_symbol)(RCore *core, RDebugMap *map) { if (vaddr == GHT_MAX) { return main_arena; } - RBinInfo *info = r_bin_get_info (core->bin); + RBinInfo *info = rz_bin_get_info (core->bin); if (!strcmp (info->arch, "x86")) { main_arena = GH (align_address_to_size) (vaddr + base_addr + sizeof (GHT), 0x20); } else if (!strcmp (info->arch, "arm")) { @@ -101,14 +101,14 @@ static GHT GH(get_main_arena_with_symbol)(RCore *core, RDebugMap *map) { return main_arena; } -static bool GH(is_tcache)(RCore *core) { +static bool GH(is_tcache)(RzCore *core) { char *fp = NULL; double v = 0; - if (r_config_get_i (core->config, "cfg.debug")) { - RDebugMap *map; - RListIter *iter; - r_debug_map_sync (core->dbg); - r_list_foreach (core->dbg->maps, iter, map) { + if (rz_config_get_i (core->config, "cfg.debug")) { + RzDebugMap *map; + RzListIter *iter; + rz_debug_map_sync (core->dbg); + rz_list_foreach (core->dbg->maps, iter, map) { // In case the binary is named *libc-* if (strncmp (map->name, core->bin->file, strlen(map->name)) != 0) { fp = strstr (map->name, "libc-"); @@ -118,30 +118,30 @@ static bool GH(is_tcache)(RCore *core) { } } } else { - int tcv = r_config_get_i (core->config, "dbg.glibc.tcache"); + int tcv = rz_config_get_i (core->config, "dbg.glibc.tcache"); eprintf ("dbg.glibc.tcache = %i\n", tcv); return tcv != 0; } if (fp) { - v = r_num_get_float (NULL, fp + 5); + v = rz_num_get_float (NULL, fp + 5); core->dbg->glibc_version = (int) round((v * 100)); } return (v > 2.25); } -static GHT GH(tcache_chunk_size)(RCore *core, GHT brk_start) { +static GHT GH(tcache_chunk_size)(RzCore *core, GHT brk_start) { GHT sz = 0; - GH (RHeapChunk) *cnk = R_NEW0 (GH (RHeapChunk)); + GH (RzHeapChunk) *cnk = R_NEW0 (GH (RzHeapChunk)); if (!cnk) { return sz; } - r_io_read_at (core->io, brk_start, (ut8 *)cnk, sizeof (GH (RHeapChunk))); + rz_io_read_at (core->io, brk_start, (ut8 *)cnk, sizeof (GH (RzHeapChunk))); sz = (cnk->size >> 3) << 3; //clear chunk flag return sz; } -static void GH(update_arena_with_tc)(GH(RHeap_MallocState_tcache) *cmain_arena, MallocState *main_arena) { +static void GH(update_arena_with_tc)(GH(RzHeap_MallocState_tcache) *cmain_arena, MallocState *main_arena) { int i = 0; main_arena->mutex = cmain_arena->mutex; main_arena->flags = cmain_arena->flags; @@ -164,7 +164,7 @@ static void GH(update_arena_with_tc)(GH(RHeap_MallocState_tcache) *cmain_arena, main_arena->GH(max_system_mem) = cmain_arena->max_system_mem; } -static void GH(update_arena_without_tc)(GH(RHeap_MallocState) *cmain_arena, MallocState *main_arena) { +static void GH(update_arena_without_tc)(GH(RzHeap_MallocState) *cmain_arena, MallocState *main_arena) { int i = 0; main_arena->mutex = cmain_arena->mutex; main_arena->flags = cmain_arena->flags; @@ -186,32 +186,32 @@ static void GH(update_arena_without_tc)(GH(RHeap_MallocState) *cmain_arena, Mall main_arena->GH(max_system_mem) = cmain_arena->max_system_mem; } -static bool GH(update_main_arena)(RCore *core, GHT m_arena, MallocState *main_arena) { - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); +static bool GH(update_main_arena)(RzCore *core, GHT m_arena, MallocState *main_arena) { + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); if (tcache) { - GH(RHeap_MallocState_tcache) *cmain_arena = R_NEW0 (GH(RHeap_MallocState_tcache)); + GH(RzHeap_MallocState_tcache) *cmain_arena = R_NEW0 (GH(RzHeap_MallocState_tcache)); if (!cmain_arena) { return false; } - (void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState_tcache))); + (void)rz_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RzHeap_MallocState_tcache))); GH(update_arena_with_tc)(cmain_arena,main_arena); } else { - GH(RHeap_MallocState) *cmain_arena = R_NEW0 (GH(RHeap_MallocState)); + GH(RzHeap_MallocState) *cmain_arena = R_NEW0 (GH(RzHeap_MallocState)); if (!cmain_arena) { return false; } - (void)r_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RHeap_MallocState))); + (void)rz_io_read_at (core->io, m_arena, (ut8 *)cmain_arena, sizeof (GH(RzHeap_MallocState))); GH(update_arena_without_tc)(cmain_arena,main_arena); } return true; } -static void GH(get_brks)(RCore *core, GHT *brk_start, GHT *brk_end) { - if (r_config_get_i (core->config, "cfg.debug")) { - RListIter *iter; - RDebugMap *map; - r_debug_map_sync (core->dbg); - r_list_foreach (core->dbg->maps, iter, map) { +static void GH(get_brks)(RzCore *core, GHT *brk_start, GHT *brk_end) { + if (rz_config_get_i (core->config, "cfg.debug")) { + RzListIter *iter; + RzDebugMap *map; + rz_debug_map_sync (core->dbg); + rz_list_foreach (core->dbg->maps, iter, map) { if (map->name) { if (strstr (map->name, "[heap]")) { *brk_start = map->addr; @@ -222,8 +222,8 @@ static void GH(get_brks)(RCore *core, GHT *brk_start, GHT *brk_end) { } } else { void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; if (map->name) { if (strstr (map->name, "[heap]")) { *brk_start = map->itv.addr; @@ -235,11 +235,11 @@ static void GH(get_brks)(RCore *core, GHT *brk_start, GHT *brk_end) { } } -static void GH(print_arena_stats)(RCore *core, GHT m_arena, MallocState *main_arena, GHT global_max_fast, int format) { +static void GH(print_arena_stats)(RzCore *core, GHT m_arena, MallocState *main_arena, GHT global_max_fast, int format) { size_t i, j, k, start; GHT align = 12 * SZ + sizeof (int) * 2; - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (tcache) { align = 16; @@ -250,27 +250,27 @@ static void GH(print_arena_stats)(RCore *core, GHT m_arena, MallocState *main_ar for (i = 0; i < NBINS * 2 - 2; i += 2) { GHT addr = m_arena + align + SZ * i - SZ * 2; GHT bina = main_arena->GH(bins)[i]; - r_cons_printf ("f chunk.%d.bin = 0x%"PFMT64x"\n", i, (ut64)addr); - r_cons_printf ("f chunk.%d.fd = 0x%"PFMT64x"\n", i, (ut64)bina); + rz_cons_printf ("f chunk.%d.bin = 0x%"PFMT64x"\n", i, (ut64)addr); + rz_cons_printf ("f chunk.%d.fd = 0x%"PFMT64x"\n", i, (ut64)bina); bina = main_arena->GH(bins)[i + 1]; - r_cons_printf ("f chunk.%d.bk = 0x%"PFMT64x"\n", i, (ut64)bina); + rz_cons_printf ("f chunk.%d.bk = 0x%"PFMT64x"\n", i, (ut64)bina); } for (i = 0; i < BINMAPSIZE; i++) { - r_cons_printf ("f binmap.%d = 0x%"PFMT64x, i, (ut64)main_arena->binmap[i]); + rz_cons_printf ("f binmap.%d = 0x%"PFMT64x, i, (ut64)main_arena->binmap[i]); } { /* maybe use SDB instead of flags for this? */ char units[8]; - r_num_units (units, sizeof (units), main_arena->GH(max_system_mem)); - r_cons_printf ("f heap.maxmem = %s\n", units); + rz_num_units (units, sizeof (units), main_arena->GH(max_system_mem)); + rz_cons_printf ("f heap.maxmem = %s\n", units); - r_num_units (units, sizeof (units), main_arena->GH(system_mem)); - r_cons_printf ("f heap.sysmem = %s\n", units); + rz_num_units (units, sizeof (units), main_arena->GH(system_mem)); + rz_cons_printf ("f heap.sysmem = %s\n", units); - r_num_units (units, sizeof (units), main_arena->GH(next_free)); - r_cons_printf ("f heap.nextfree = %s\n", units); + rz_num_units (units, sizeof (units), main_arena->GH(next_free)); + rz_cons_printf ("f heap.nextfree = %s\n", units); - r_num_units (units, sizeof (units), main_arena->GH(next)); - r_cons_printf ("f heap.next= %s\n", units); + rz_num_units (units, sizeof (units), main_arena->GH(next)); + rz_cons_printf ("f heap.next= %s\n", units); } return; } @@ -358,7 +358,7 @@ static void GH(print_arena_stats)(RCore *core, GHT m_arena, MallocState *main_ar PRINTF_GA ("0x%"PFMT64x"->bk = ", (ut64)bin); PRINTF_BA ("0x%"PFMT64x, (ut64)main_arena->GH(bins)[i + 1] ); PRINT_GA (", "); - r_cons_newline (); + rz_cons_newline (); } PRINT_GA (" }\n"); @@ -386,8 +386,8 @@ static void GH(print_arena_stats)(RCore *core, GHT m_arena, MallocState *main_ar PRINT_GA ("}\n\n"); } -static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) { - r_return_val_if_fail (core && core->dbg && core->dbg->maps, false); +static bool GH(rz_resolve_main_arena)(RzCore *core, GHT *m_arena) { + rz_return_val_if_fail (core && core->dbg && core->dbg->maps, false); if (core->dbg->main_arena_resolved) { return true; @@ -397,14 +397,14 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) { GHT libc_addr_sta = GHT_MAX, libc_addr_end = 0; GHT addr_srch = GHT_MAX, heap_sz = GHT_MAX; GHT main_arena_sym = GHT_MAX; - bool is_debugged = r_config_get_i (core->config, "cfg.debug"); + bool is_debugged = rz_config_get_i (core->config, "cfg.debug"); bool first_libc = true; if (is_debugged) { - RListIter *iter; - RDebugMap *map; - r_debug_map_sync (core->dbg); - r_list_foreach (core->dbg->maps, iter, map) { + RzListIter *iter; + RzDebugMap *map; + rz_debug_map_sync (core->dbg); + rz_list_foreach (core->dbg->maps, iter, map) { /* Try to find the main arena address using the glibc's symbols. */ if (strstr (map->name, "/libc-") && first_libc && main_arena_sym == GHT_MAX) { first_libc = false; @@ -418,8 +418,8 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) { } } else { void **it; - r_pvector_foreach (&core->io->maps, it) { - RIOMap *map = *it; + rz_pvector_foreach (&core->io->maps, it) { + RzIOMap *map = *it; if (map->name && strstr (map->name, "arena")) { libc_addr_sta = map->itv.addr; libc_addr_end = map->itv.addr + map->itv.size; @@ -429,7 +429,7 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) { } if (libc_addr_sta == GHT_MAX || libc_addr_end == GHT_MAX) { - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { eprintf ("Warning: Can't find glibc mapped in memory (see dm)\n"); } else { eprintf ("Warning: Can't find arena mapped in memory (see om)\n"); @@ -476,16 +476,16 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena) { return false; } -void GH(print_heap_chunk)(RCore *core) { - GH(RHeapChunk) *cnk = R_NEW0 (GH(RHeapChunk)); +void GH(print_heap_chunk)(RzCore *core) { + GH(RzHeapChunk) *cnk = R_NEW0 (GH(RzHeapChunk)); GHT chunk = core->offset; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (!cnk) { return; } - (void) r_io_read_at (core->io, chunk, (ut8 *)cnk, sizeof (*cnk)); + (void) rz_io_read_at (core->io, chunk, (ut8 *)cnk, sizeof (*cnk)); PRINT_GA ("struct malloc_chunk @ "); PRINTF_BA ("0x%"PFMT64x, (ut64)chunk); @@ -522,15 +522,15 @@ void GH(print_heap_chunk)(RCore *core) { char *data = calloc (1, size); if (data) { - r_io_read_at (core->io, chunk + SZ * 2, (ut8 *)data, size); + rz_io_read_at (core->io, chunk + SZ * 2, (ut8 *)data, size); PRINT_GA ("chunk data = \n"); - r_print_hexdump (core->print, chunk + SZ * 2, (ut8 *)data, size, SZ * 8, SZ, 1); + rz_print_hexdump (core->print, chunk + SZ * 2, (ut8 *)data, size, SZ * 8, SZ, 1); free (data); } free (cnk); } -static bool GH(is_arena)(RCore *core, GHT m_arena, GHT m_state) { +static bool GH(is_arena)(RzCore *core, GHT m_arena, GHT m_state) { if (m_arena == m_state) { return true; } @@ -560,17 +560,17 @@ static bool GH(is_arena)(RCore *core, GHT m_arena, GHT m_state) { return false; } -static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, MallocState *main_arena, GHT brk_start) { +static int GH(print_double_linked_list_bin_simple)(RzCore *core, GHT bin, MallocState *main_arena, GHT brk_start) { GHT next = GHT_MAX; int ret = 1; - GH(RHeapChunk) *cnk = R_NEW0 (GH(RHeapChunk)); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + GH(RzHeapChunk) *cnk = R_NEW0 (GH(RzHeapChunk)); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (!cnk) { return -1; } - r_io_read_at (core->io, bin, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, bin, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); PRINTF_GA (" 0x%"PFMT64x, (ut64)bin); if (cnk->fd != bin) { @@ -584,7 +584,7 @@ static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, MallocS free (cnk); return -1; } - r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); } PRINTF_GA ("->fd = 0x%"PFMT64x, (ut64)cnk->fd); @@ -595,7 +595,7 @@ static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, MallocS free (cnk); return -1; } - (void)r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); PRINTF_GA ("\n 0x%"PFMT64x, (ut64)bin); while (cnk->bk != bin) { @@ -606,7 +606,7 @@ static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, MallocS free (cnk); return -1; } - (void)r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); } PRINTF_GA ("->bk = 0x%"PFMT64x, (ut64)cnk->bk); @@ -614,26 +614,26 @@ static int GH(print_double_linked_list_bin_simple)(RCore *core, GHT bin, MallocS return ret; } -static int GH(print_double_linked_list_bin_graph)(RCore *core, GHT bin, MallocState *main_arena, GHT brk_start) { - RAGraph *g = r_agraph_new (r_cons_canvas_new (1, 1)); +static int GH(print_double_linked_list_bin_graph)(RzCore *core, GHT bin, MallocState *main_arena, GHT brk_start) { + RzAGraph *g = rz_agraph_new (rz_cons_canvas_new (1, 1)); GHT next = GHT_MAX; char title[256], chunk[256]; - RANode *bin_node = NULL, *prev_node = NULL, *next_node = NULL; - GH(RHeapChunk) *cnk = R_NEW0 (GH(RHeapChunk)); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzANode *bin_node = NULL, *prev_node = NULL, *next_node = NULL; + GH(RzHeapChunk) *cnk = R_NEW0 (GH(RzHeapChunk)); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (!cnk || !g) { free (cnk); - r_agraph_free (g); + rz_agraph_free (g); return -1; } - g->can->color = r_config_get_i (core->config, "scr.color"); + g->can->color = rz_config_get_i (core->config, "scr.color"); - (void)r_io_read_at (core->io, bin, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, bin, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); snprintf (title, sizeof (title) - 1, "bin @ 0x%"PFMT64x"\n", (ut64)bin); snprintf (chunk, sizeof (chunk) - 1, "fd: 0x%"PFMT64x"\nbk: 0x%"PFMT64x"\n", (ut64)cnk->fd, (ut64)cnk->bk); - bin_node = r_agraph_add_node (g, title, chunk); + bin_node = rz_agraph_add_node (g, title, chunk); prev_node = bin_node; while (cnk->bk != bin) { @@ -645,32 +645,32 @@ static int GH(print_double_linked_list_bin_graph)(RCore *core, GHT bin, MallocSt return -1; } - r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); snprintf (title, sizeof (title) - 1, "Chunk @ 0x%"PFMT64x"\n", (ut64)next); snprintf (chunk, sizeof (chunk) - 1, "fd: 0x%"PFMT64x"\nbk: 0x%"PFMT64x"\n", (ut64)cnk->fd, (ut64)cnk->bk); - next_node = r_agraph_add_node (g, title, chunk); - r_agraph_add_edge (g, prev_node, next_node); - r_agraph_add_edge (g, next_node, prev_node); + next_node = rz_agraph_add_node (g, title, chunk); + rz_agraph_add_edge (g, prev_node, next_node); + rz_agraph_add_edge (g, next_node, prev_node); prev_node = next_node; } - r_agraph_add_edge (g, prev_node, bin_node); - r_agraph_add_edge (g, bin_node, prev_node); - r_agraph_print (g); + rz_agraph_add_edge (g, prev_node, bin_node); + rz_agraph_add_edge (g, bin_node, prev_node); + rz_agraph_print (g); free (cnk); - r_agraph_free (g); + rz_agraph_free (g); return 0; } -static int GH(print_double_linked_list_bin)(RCore *core, MallocState *main_arena, GHT m_arena, GHT offset, GHT num_bin, int graph) { +static int GH(print_double_linked_list_bin)(RzCore *core, MallocState *main_arena, GHT m_arena, GHT offset, GHT num_bin, int graph) { if (!core || !core->dbg || !core->dbg->maps) { return -1; } int ret = 0; GHT brk_start = GHT_MAX, brk_end = GHT_MAX, initial_brk = GHT_MAX; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (num_bin > 126) { return -1; @@ -687,9 +687,9 @@ static int GH(print_double_linked_list_bin)(RCore *core, MallocState *main_arena return -1; } - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); if (tcache) { - const int fc_offset = r_config_get_i (core->config, "dbg.glibc.fc_offset"); + const int fc_offset = rz_config_get_i (core->config, "dbg.glibc.fc_offset"); bin = m_arena + offset + SZ * num_bin * 2 + 10 * SZ; initial_brk = ( (brk_start >> 12) << 12 ) + fc_offset; } else { @@ -718,13 +718,13 @@ static int GH(print_double_linked_list_bin)(RCore *core, MallocState *main_arena return ret; } -static void GH(print_heap_bin)(RCore *core, GHT m_arena, MallocState *main_arena, const char *input) { +static void GH(print_heap_bin)(RzCore *core, GHT m_arena, MallocState *main_arena, const char *input) { int i, j = 2; GHT num_bin = GHT_MAX; GHT offset; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); if (tcache) { offset = 16; } else { @@ -744,7 +744,7 @@ static void GH(print_heap_bin)(RCore *core, GHT m_arena, MallocState *main_arena j--; // for spaces after input /* fallthu */ case 'g': // dmhbg [bin_num] - num_bin = r_num_get (NULL, input + j) - 1; + num_bin = rz_num_get (NULL, input + j) - 1; if (num_bin > NBINS - 2) { eprintf ("Error: 0 < bin <= %d\n", NBINS - 1); break; @@ -755,14 +755,14 @@ static void GH(print_heap_bin)(RCore *core, GHT m_arena, MallocState *main_arena } } -static int GH(print_single_linked_list_bin)(RCore *core, MallocState *main_arena, GHT m_arena, GHT offset, GHT bin_num, bool demangle) { +static int GH(print_single_linked_list_bin)(RzCore *core, MallocState *main_arena, GHT m_arena, GHT offset, GHT bin_num, bool demangle) { if (!core || !core->dbg || !core->dbg->maps) { return -1; } GHT next = GHT_MAX, brk_start = GHT_MAX, brk_end = GHT_MAX; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; - GH(RHeapChunk) *cnk = R_NEW0 (GH(RHeapChunk)); + GH(RzHeapChunk) *cnk = R_NEW0 (GH(RzHeapChunk)); if (!cnk) { return 0; } @@ -778,7 +778,7 @@ static int GH(print_single_linked_list_bin)(RCore *core, MallocState *main_arena } bin = m_arena + offset + SZ * bin_num; - r_io_read_at (core->io, bin, (ut8 *)&next, SZ); + rz_io_read_at (core->io, bin, (ut8 *)&next, SZ); GH(get_brks) (core, &brk_start, &brk_end); if (brk_start == GHT_MAX || brk_end == GHT_MAX) { @@ -796,7 +796,7 @@ static int GH(print_single_linked_list_bin)(RCore *core, MallocState *main_arena while (next && next >= brk_start && next < main_arena->GH(top)) { PRINTF_BA ("0x%"PFMT64x, (ut64)next); while (double_free == GHT_MAX && next_tmp && next_tmp >= brk_start && next_tmp <= main_arena->GH(top)) { - r_io_read_at (core->io, next_tmp, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, next_tmp, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); next_tmp = (!demangle) ? cnk->fd : PROTECT_PTR (next_tmp, cnk->fd); if (cnk->prev_size > size || ((cnk->size >> 3) << 3) > size) { break; @@ -806,7 +806,7 @@ static int GH(print_single_linked_list_bin)(RCore *core, MallocState *main_arena break; } } - r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); next = (!demangle) ? cnk->fd : PROTECT_PTR (next, cnk->fd); PRINTF_BA ("%s", next ? "->fd = " : ""); if (cnk->prev_size > size || ((cnk->size >> 3) << 3) > size) { @@ -840,11 +840,11 @@ static int GH(print_single_linked_list_bin)(RCore *core, MallocState *main_arena return 0; } -void GH(print_heap_fastbin)(RCore *core, GHT m_arena, MallocState *main_arena, GHT global_max_fast, const char *input, bool demangle) { +void GH(print_heap_fastbin)(RzCore *core, GHT m_arena, MallocState *main_arena, GHT global_max_fast, const char *input, bool demangle) { int i; GHT num_bin = GHT_MAX, offset = sizeof (int) * 2; - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (tcache) { offset = 16; @@ -870,7 +870,7 @@ void GH(print_heap_fastbin)(RCore *core, GHT m_arena, MallocState *main_arena, G PRINT_YA ("}\n"); break; case ' ': // dmhf [bin_num] - num_bin = r_num_get (NULL, input) - 1; + num_bin = rz_num_get (NULL, input) - 1; if (num_bin >= NFASTBINS) { eprintf ("Error: 0 < bin <= %d\n", NFASTBINS); break; @@ -883,53 +883,53 @@ void GH(print_heap_fastbin)(RCore *core, GHT m_arena, MallocState *main_arena, G } } -static GH (RTcache)* GH (tcache_new) (RCore *core) { - r_return_val_if_fail (core, NULL); +static GH (RTcache)* GH (tcache_new) (RzCore *core) { + rz_return_val_if_fail (core, NULL); GH (RTcache) *tcache = R_NEW0 (GH (RTcache)); if (core->dbg->glibc_version >= TCACHE_NEW_VERSION) { tcache->type = NEW; - tcache->RHeapTcache.heap_tcache = R_NEW0(GH (RHeapTcache)); + tcache->RzHeapTcache.heap_tcache = R_NEW0(GH (RzHeapTcache)); } else { tcache->type = OLD; - tcache->RHeapTcache.heap_tcache_pre_230 = R_NEW0(GH (RHeapTcachePre230)); + tcache->RzHeapTcache.heap_tcache_pre_230 = R_NEW0(GH (RzHeapTcachePre230)); } return tcache; } static void GH (tcache_free) (GH (RTcache)* tcache) { - r_return_if_fail (tcache); + rz_return_if_fail (tcache); tcache->type == NEW - ? free(tcache->RHeapTcache.heap_tcache) - : free(tcache->RHeapTcache.heap_tcache_pre_230); + ? free(tcache->RzHeapTcache.heap_tcache) + : free(tcache->RzHeapTcache.heap_tcache_pre_230); free(tcache); } -static bool GH (tcache_read) (RCore *core, GHT tcache_start, GH (RTcache)* tcache) { - r_return_val_if_fail (core && tcache, false); +static bool GH (tcache_read) (RzCore *core, GHT tcache_start, GH (RTcache)* tcache) { + rz_return_val_if_fail (core && tcache, false); return tcache->type == NEW - ? r_io_read_at (core->io, tcache_start, (ut8 *)tcache->RHeapTcache.heap_tcache, sizeof (GH (RHeapTcache))) - : r_io_read_at (core->io, tcache_start, (ut8 *)tcache->RHeapTcache.heap_tcache_pre_230, sizeof (GH (RHeapTcachePre230))); + ? rz_io_read_at (core->io, tcache_start, (ut8 *)tcache->RzHeapTcache.heap_tcache, sizeof (GH (RzHeapTcache))) + : rz_io_read_at (core->io, tcache_start, (ut8 *)tcache->RzHeapTcache.heap_tcache_pre_230, sizeof (GH (RzHeapTcachePre230))); } static int GH (tcache_get_count) (GH (RTcache)* tcache, int index) { - r_return_val_if_fail (tcache, 0); + rz_return_val_if_fail (tcache, 0); return tcache->type == NEW - ? tcache->RHeapTcache.heap_tcache->counts[index] - : tcache->RHeapTcache.heap_tcache_pre_230->counts[index]; + ? tcache->RzHeapTcache.heap_tcache->counts[index] + : tcache->RzHeapTcache.heap_tcache_pre_230->counts[index]; } static GHT GH (tcache_get_entry) (GH (RTcache)* tcache, int index) { - r_return_val_if_fail (tcache, 0); + rz_return_val_if_fail (tcache, 0); return tcache->type == NEW - ? tcache->RHeapTcache.heap_tcache->entries[index] - : tcache->RHeapTcache.heap_tcache_pre_230->entries[index]; + ? tcache->RzHeapTcache.heap_tcache->entries[index] + : tcache->RzHeapTcache.heap_tcache_pre_230->entries[index]; } -static void GH (tcache_print) (RCore *core, GH (RTcache)* tcache, bool demangle) { - r_return_if_fail (core && tcache); +static void GH (tcache_print) (RzCore *core, GH (RTcache)* tcache, bool demangle) { + rz_return_if_fail (core && tcache); GHT tcache_fd = GHT_MAX; GHT tcache_tmp = GHT_MAX; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; size_t i; for (i = 0; i < TCACHE_MAX_BINS; i++) { int count = GH (tcache_get_count) (tcache, i); @@ -946,7 +946,7 @@ static void GH (tcache_print) (RCore *core, GH (RTcache)* tcache, bool demangle) tcache_fd = entry; size_t n; for (n = 1; n < count; n++) { - bool r = r_io_read_at (core->io, tcache_fd, (ut8 *)&tcache_tmp, sizeof (GHT)); + bool r = rz_io_read_at (core->io, tcache_fd, (ut8 *)&tcache_tmp, sizeof (GHT)); if (!r) { break; } @@ -962,17 +962,17 @@ static void GH (tcache_print) (RCore *core, GH (RTcache)* tcache, bool demangle) } } -static void GH (print_tcache_instance)(RCore *core, GHT m_arena, MallocState *main_arena, bool demangle) { - r_return_if_fail (core && core->dbg && core->dbg->maps); +static void GH (print_tcache_instance)(RzCore *core, GHT m_arena, MallocState *main_arena, bool demangle) { + rz_return_if_fail (core && core->dbg && core->dbg->maps); - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); if (!tcache) { return; } GHT brk_start = GHT_MAX, brk_end = GHT_MAX, initial_brk = GHT_MAX; GH (get_brks) (core, &brk_start, &brk_end); GHT tcache_start = GHT_MAX; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; tcache_start = brk_start + 0x10; GHT fc_offset = GH (tcache_chunk_size) (core, brk_start); @@ -982,24 +982,24 @@ static void GH (print_tcache_instance)(RCore *core, GHT m_arena, MallocState *ma return; } - GH (RTcache)* r_tcache = GH (tcache_new) (core); - if (!r_tcache) { + GH (RTcache)* rz_tcache = GH (tcache_new) (core); + if (!rz_tcache) { return; } - if (!GH (tcache_read) (core, tcache_start, r_tcache)) { + if (!GH (tcache_read) (core, tcache_start, rz_tcache)) { return; } PRINT_GA("Tcache main arena @"); PRINTF_BA (" 0x%"PFMT64x"\n", (ut64)m_arena); - GH (tcache_print) (core, r_tcache, demangle); + GH (tcache_print) (core, rz_tcache, demangle); if (main_arena->GH (next) != m_arena) { GHT mmap_start = GHT_MAX, tcache_start = GHT_MAX; MallocState *ta = R_NEW0 (MallocState); if (!ta) { free(ta); - GH (tcache_free) (r_tcache); + GH (tcache_free) (rz_tcache); return; } ta->GH (next) = main_arena->GH (next); @@ -1007,27 +1007,27 @@ static void GH (print_tcache_instance)(RCore *core, GHT m_arena, MallocState *ma PRINT_YA ("Tcache thread arena @ "); PRINTF_BA (" 0x%"PFMT64x, (ut64)ta->GH (next)); mmap_start = ((ta->GH (next) >> 16) << 16); - tcache_start = mmap_start + sizeof (GH (RHeapInfo)) + sizeof (GH (RHeap_MallocState_tcache)) + GH (MMAP_ALIGN); + tcache_start = mmap_start + sizeof (GH (RzHeapInfo)) + sizeof (GH (RzHeap_MallocState_tcache)) + GH (MMAP_ALIGN); if (!GH (update_main_arena) (core, ta->GH (next), ta)) { free (ta); - GH (tcache_free) (r_tcache); + GH (tcache_free) (rz_tcache); return; } if (ta->attached_threads) { PRINT_BA ("\n"); - GH (tcache_read) (core, tcache_start, r_tcache); - GH (tcache_print) (core, r_tcache, demangle); + GH (tcache_read) (core, tcache_start, rz_tcache); + GH (tcache_print) (core, rz_tcache, demangle); } else { PRINT_GA (" free\n"); } } } - GH (tcache_free) (r_tcache); + GH (tcache_free) (rz_tcache); } -static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, +static void GH(print_heap_segment)(RzCore *core, MallocState *main_arena, GHT m_arena, GHT m_state, GHT global_max_fast, int format_out) { if (!core || !core->dbg || !core->dbg->maps) { @@ -1039,21 +1039,21 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, GHT tcache_fd = GHT_MAX, tcache_tmp = GHT_MAX; GHT initial_brk = GHT_MAX, tcache_initial_brk = GHT_MAX; - const int tcache = r_config_get_i (core->config, "dbg.glibc.tcache"); - const int offset = r_config_get_i (core->config, "dbg.glibc.fc_offset"); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + const int tcache = rz_config_get_i (core->config, "dbg.glibc.tcache"); + const int offset = rz_config_get_i (core->config, "dbg.glibc.fc_offset"); + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; int glibc_version = core->dbg->glibc_version; if (m_arena == m_state) { GH(get_brks) (core, &brk_start, &brk_end); if (tcache) { initial_brk = ((brk_start >> 12) << 12) + GH(HDR_SZ); - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { tcache_initial_brk = initial_brk; } initial_brk += (glibc_version < 230) - ? sizeof (GH (RHeapTcachePre230)) - : sizeof (GH (RHeapTcache)); + ? sizeof (GH (RzHeapTcachePre230)) + : sizeof (GH (RzHeapTcache)); } else { initial_brk = (brk_start >> 12) << 12; } @@ -1061,10 +1061,10 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, brk_start = ((m_state >> 16) << 16) ; brk_end = brk_start + main_arena->GH(system_mem); if (tcache) { - tcache_initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState_tcache)) + GH(MMAP_ALIGN); + tcache_initial_brk = brk_start + sizeof (GH(RzHeapInfo)) + sizeof (GH(RzHeap_MallocState_tcache)) + GH(MMAP_ALIGN); initial_brk = tcache_initial_brk + offset; } else { - initial_brk = brk_start + sizeof (GH(RHeapInfo)) + sizeof (GH(RHeap_MallocState)) + MMAP_OFFSET; + initial_brk = brk_start + sizeof (GH(RzHeapInfo)) + sizeof (GH(RzHeap_MallocState)) + MMAP_OFFSET; } } @@ -1074,68 +1074,68 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, } GHT next_chunk = initial_brk, prev_chunk = next_chunk; - GH(RHeapChunk) *cnk = R_NEW0 (GH(RHeapChunk)); + GH(RzHeapChunk) *cnk = R_NEW0 (GH(RzHeapChunk)); if (!cnk) { return; } - GH(RHeapChunk) *cnk_next = R_NEW0 (GH(RHeapChunk)); + GH(RzHeapChunk) *cnk_next = R_NEW0 (GH(RzHeapChunk)); if (!cnk_next) { free (cnk); return; } - RConfigHold *hc = r_config_hold_new (core->config); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { free (cnk); free (cnk_next); return; } - w = r_cons_get_size (&h); - RConsCanvas *can = r_cons_canvas_new (w, h); + w = rz_cons_get_size (&h); + RzConsCanvas *can = rz_cons_canvas_new (w, h); if (!can) { free (cnk); free (cnk_next); - r_config_hold_free (hc); + rz_config_hold_free (hc); return; } - RAGraph *g = r_agraph_new (can); + RzAGraph *g = rz_agraph_new (can); if (!g) { free (cnk); free (cnk_next); - r_cons_canvas_free (can); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); return; } - RANode *top = R_EMPTY, *chunk_node = R_EMPTY, *prev_node = R_EMPTY; + RzANode *top = R_EMPTY, *chunk_node = R_EMPTY, *prev_node = R_EMPTY; char *top_title, *top_data, *node_title, *node_data; bool first_node = true; - top_data = r_str_newf (""); - top_title = r_str_newf (""); + top_data = rz_str_newf (""); + top_title = rz_str_newf (""); - (void)r_io_read_at (core->io, next_chunk, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next_chunk, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); size_tmp = (cnk->size >> 3) << 3; ut64 prev_chunk_addr; ut64 prev_chunk_size; switch (format_out) { case 'j': - r_cons_printf ("{\"chunks\":["); + rz_cons_printf ("{\"chunks\":["); break; case '*': - r_cons_printf ("fs+heap.allocated\n"); + rz_cons_printf ("fs+heap.allocated\n"); break; case 'g': - can->linemode = r_config_get_i (core->config, "graph.linemode"); - can->color = r_config_get_i (core->config, "scr.color"); - core->cons->use_utf8 = r_config_get_i (core->config, "scr.utf8"); - g->layout = r_config_get_i (core->config, "graph.layout"); - r_agraph_set_title (g, "Heap Layout"); - top_title = r_str_newf ("Top chunk @ 0x%"PFMT64x"\n", (ut64)main_arena->GH(top)); + can->linemode = rz_config_get_i (core->config, "graph.linemode"); + can->color = rz_config_get_i (core->config, "scr.color"); + core->cons->use_utf8 = rz_config_get_i (core->config, "scr.utf8"); + g->layout = rz_config_get_i (core->config, "graph.layout"); + rz_agraph_set_title (g, "Heap Layout"); + top_title = rz_str_newf ("Top chunk @ 0x%"PFMT64x"\n", (ut64)main_arena->GH(top)); } const char *comma = ""; @@ -1151,21 +1151,21 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, (ut64)cnk->size, (ut64)cnk->fd, (ut64)cnk->bk); break; case 'j': - r_cons_printf ("%s{\"addr\":%"PFMT64d",\"size\":%"PFMT64d",\"status\":\"%s\",\"fd\":"PFMT64d",\"bk\":"PFMT64d"}", + rz_cons_printf ("%s{\"addr\":%"PFMT64d",\"size\":%"PFMT64d",\"status\":\"%s\",\"fd\":"PFMT64d",\"bk\":"PFMT64d"}", comma, (ut64)next_chunk, (ut64)cnk->size, status, (ut64)cnk->fd, (ut64)cnk->bk); comma = ","; break; case '*': - r_cons_printf ("fs heap.corrupted\n"); - char *name = r_str_newf ("chunk.corrupted.%06x", ((prev_chunk>>4) & 0xffff)); - r_cons_printf ("f %s %d 0x%"PFMT64x"\n", name, (int)cnk->size, prev_chunk); + rz_cons_printf ("fs heap.corrupted\n"); + char *name = rz_str_newf ("chunk.corrupted.%06x", ((prev_chunk>>4) & 0xffff)); + rz_cons_printf ("f %s %d 0x%"PFMT64x"\n", name, (int)cnk->size, prev_chunk); free (name); break; case 'g': - node_title = r_str_newf (" Malloc chunk @ 0x%"PFMT64x" ", (ut64)prev_chunk); - node_data = r_str_newf ("[corrupted] size: 0x%"PFMT64x"\n fd: 0x%"PFMT64x", bk: 0x%"PFMT64x + node_title = rz_str_newf (" Malloc chunk @ 0x%"PFMT64x" ", (ut64)prev_chunk); + node_data = rz_str_newf ("[corrupted] size: 0x%"PFMT64x"\n fd: 0x%"PFMT64x", bk: 0x%"PFMT64x "\nHeap graph could not be recovered\n", (ut64)cnk->size, (ut64)cnk->fd, (ut64)cnk->bk); - r_agraph_add_node (g, node_title, node_data); + rz_agraph_add_node (g, node_title, node_data); if (first_node) { first_node = false; } @@ -1183,7 +1183,7 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, if (fastbin) { int i = (size_tmp / (SZ * 2)) - 2; GHT idx = (GHT)main_arena->GH(fastbinsY)[i]; - (void)r_io_read_at (core->io, idx, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, idx, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); GHT next = GH (get_next_pointer) (core, idx, cnk->fd); if (prev_chunk == idx && idx && !next) { is_free = true; @@ -1195,7 +1195,7 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, double_free = true; break; } - (void)r_io_read_at (core->io, next, (ut8 *)cnk_next, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next, (ut8 *)cnk_next, sizeof (GH(RzHeapChunk))); GHT next_node = GH (get_next_pointer) (core, next, cnk_next->fd); // avoid triple while? while (next_node && next_node >= brk_start && next_node < main_arena->GH(top)) { @@ -1203,14 +1203,14 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, double_free = true; break; } - (void)r_io_read_at (core->io, next_node, (ut8 *)cnk_next, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next_node, (ut8 *)cnk_next, sizeof (GH(RzHeapChunk))); next_node = GH (get_next_pointer) (core, next_node, cnk_next->fd); } if (double_free) { break; } } - (void)r_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + (void)rz_io_read_at (core->io, next, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); next = GH (get_next_pointer) (core, next, cnk->fd); } if (double_free) { @@ -1223,9 +1223,9 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, if (tcache) { GH(RTcache)* tcache_heap = GH (tcache_new) (core); if (!tcache_heap) { - r_cons_canvas_free (can); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); free (g); free (cnk); free (cnk_next); @@ -1246,7 +1246,7 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, tcache_fd = entry; int n; for (n = 1; n < count; n++) { - bool r = r_io_read_at (core->io, tcache_fd, (ut8*)&tcache_tmp, sizeof (GHT)); + bool r = rz_io_read_at (core->io, tcache_fd, (ut8*)&tcache_tmp, sizeof (GHT)); if (!r) { break; } @@ -1266,7 +1266,7 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, next_chunk += size_tmp; prev_chunk = next_chunk; - r_io_read_at (core->io, next_chunk, (ut8 *)cnk, sizeof (GH(RHeapChunk))); + rz_io_read_at (core->io, next_chunk, (ut8 *)cnk, sizeof (GH(RzHeapChunk))); size_tmp = (cnk->size >> 3) << 3; const char *status = "allocated"; @@ -1293,24 +1293,24 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, PRINTF_GA ("][%s]",status); break; case 'j': - r_cons_printf ("%s{\"addr\":0x%"PFMT64x",\"size\":0x%"PFMT64x",\"status\":\"%s\"}", + rz_cons_printf ("%s{\"addr\":0x%"PFMT64x",\"size\":0x%"PFMT64x",\"status\":\"%s\"}", comma, prev_chunk_addr, prev_chunk_size, status); comma = ","; break; case '*': - r_cons_printf ("fs heap.%s\n", status); - char *name = r_str_newf ("chunk.%06x", ((prev_chunk_addr>>4) & 0xffff)); - r_cons_printf ("f %s %d 0x%"PFMT64x"\n", name, (int)prev_chunk_size, prev_chunk_addr); + rz_cons_printf ("fs heap.%s\n", status); + char *name = rz_str_newf ("chunk.%06x", ((prev_chunk_addr>>4) & 0xffff)); + rz_cons_printf ("f %s %d 0x%"PFMT64x"\n", name, (int)prev_chunk_size, prev_chunk_addr); free (name); break; case 'g': - node_title = r_str_newf (" Malloc chunk @ 0x%"PFMT64x" ", (ut64)prev_chunk_addr); - node_data = r_str_newf ("size: 0x%"PFMT64x" status: %s\n", (ut64)prev_chunk_size, status); - chunk_node = r_agraph_add_node (g, node_title, node_data); + node_title = rz_str_newf (" Malloc chunk @ 0x%"PFMT64x" ", (ut64)prev_chunk_addr); + node_data = rz_str_newf ("size: 0x%"PFMT64x" status: %s\n", (ut64)prev_chunk_size, status); + chunk_node = rz_agraph_add_node (g, node_title, node_data); if (first_node) { first_node = false; } else { - r_agraph_add_edge (g, prev_node, chunk_node); + rz_agraph_add_edge (g, prev_node, chunk_node); } prev_node = chunk_node; break; @@ -1328,33 +1328,33 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, PRINT_GA ("]\n"); break; case 'j': - r_cons_printf ("],"); - r_cons_printf ("\"top\":0x%"PFMT64x",", (ut64)main_arena->GH(top)); - r_cons_printf ("\"brk\":0x%"PFMT64x",", (ut64)brk_start); - r_cons_printf ("\"end\":0x%"PFMT64x, (ut64)brk_end); - r_cons_printf ("}\n"); + rz_cons_printf ("],"); + rz_cons_printf ("\"top\":0x%"PFMT64x",", (ut64)main_arena->GH(top)); + rz_cons_printf ("\"brk\":0x%"PFMT64x",", (ut64)brk_start); + rz_cons_printf ("\"end\":0x%"PFMT64x, (ut64)brk_end); + rz_cons_printf ("}\n"); break; case '*': - r_cons_printf ("fs-\n"); - r_cons_printf ("f heap.top = 0x%08"PFMT64x"\n", (ut64)main_arena->GH(top)); - r_cons_printf ("f heap.brk = 0x%08"PFMT64x"\n", (ut64)brk_start); - r_cons_printf ("f heap.end = 0x%08"PFMT64x"\n", (ut64)brk_end); + rz_cons_printf ("fs-\n"); + rz_cons_printf ("f heap.top = 0x%08"PFMT64x"\n", (ut64)main_arena->GH(top)); + rz_cons_printf ("f heap.brk = 0x%08"PFMT64x"\n", (ut64)brk_start); + rz_cons_printf ("f heap.end = 0x%08"PFMT64x"\n", (ut64)brk_end); break; case 'g': - top = r_agraph_add_node (g, top_title, top_data); + top = rz_agraph_add_node (g, top_title, top_data); if (!first_node) { - r_agraph_add_edge (g, prev_node, top); + rz_agraph_add_edge (g, prev_node, top); free (node_data); free (node_title); } - r_agraph_print (g); - r_cons_canvas_free (can); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_agraph_print (g); + rz_cons_canvas_free (can); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); break; } - r_cons_printf ("\n"); + rz_cons_printf ("\n"); free (g); free (top_data); free (top_title); @@ -1362,9 +1362,9 @@ static void GH(print_heap_segment)(RCore *core, MallocState *main_arena, free (cnk_next); } -void GH(print_malloc_states)( RCore *core, GHT m_arena, MallocState *main_arena) { +void GH(print_malloc_states)( RzCore *core, GHT m_arena, MallocState *main_arena) { MallocState *ta = R_NEW0 (MallocState); - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (!ta) { return; @@ -1390,8 +1390,8 @@ void GH(print_malloc_states)( RCore *core, GHT m_arena, MallocState *main_arena) free(ta); } -void GH(print_inst_minfo)(GH(RHeapInfo) *heap_info, GHT hinfo) { - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; +void GH(print_inst_minfo)(GH(RzHeapInfo) *heap_info, GHT hinfo) { + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; PRINT_YA ("malloc_info @ "); PRINTF_BA ("0x%"PFMT64x, (ut64)hinfo); @@ -1406,20 +1406,20 @@ void GH(print_inst_minfo)(GH(RHeapInfo) *heap_info, GHT hinfo) { PRINT_YA ("}\n\n"); } -void GH(print_malloc_info)(RCore *core, GHT m_state, GHT malloc_state) { +void GH(print_malloc_info)(RzCore *core, GHT m_state, GHT malloc_state) { GHT h_info; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (malloc_state == m_state) { PRINT_RA ("main_arena does not have an instance of malloc_info\n"); } else if (GH(is_arena) (core, malloc_state, m_state)) { h_info = (malloc_state >> 16) << 16; - GH(RHeapInfo) *heap_info = R_NEW0 (GH(RHeapInfo)); + GH(RzHeapInfo) *heap_info = R_NEW0 (GH(RzHeapInfo)); if (!heap_info) { return; } - r_io_read_at (core->io, h_info, (ut8*)heap_info, sizeof (GH(RHeapInfo))); + rz_io_read_at (core->io, h_info, (ut8*)heap_info, sizeof (GH(RzHeapInfo))); GH(print_inst_minfo) (heap_info, h_info); MallocState *ms = R_NEW0 (MallocState); if (!ms) { @@ -1435,7 +1435,7 @@ void GH(print_malloc_info)(RCore *core, GHT m_state, GHT malloc_state) { } if ((ms->GH(top) >> 16) << 16 != h_info) { h_info = (ms->GH(top) >> 16) << 16; - r_io_read_at (core->io, h_info, (ut8*)heap_info, sizeof (GH(RHeapInfo))); + rz_io_read_at (core->io, h_info, (ut8*)heap_info, sizeof (GH(RzHeapInfo))); GH(print_inst_minfo) (heap_info, h_info); } } @@ -1467,9 +1467,9 @@ static const char* GH(help_msg)[] = { NULL }; -static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { +static int GH(cmd_dbg_map_heap_glibc)(RzCore *core, const char *input) { static GHT m_arena = GHT_MAX, m_state = GHT_MAX; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; GHT global_max_fast = (64 * SZ / 4); @@ -1478,17 +1478,17 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { return false; } - r_config_set_i (core->config, "dbg.glibc.tcache", GH(is_tcache) (core)); + rz_config_set_i (core->config, "dbg.glibc.tcache", GH(is_tcache) (core)); int format = 'c'; bool get_state = false; switch (input[0]) { case ' ' : // dmh [malloc_state] - m_state = r_num_get (NULL, input); + m_state = rz_num_get (NULL, input); get_state = true; case '\0': // dmh - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { if (core->offset != core->prompt_offset) { m_state = core->offset; @@ -1510,7 +1510,7 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } break; case 'a': // dmha - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { if (!GH(update_main_arena) (core, m_arena, main_arena)) { break; } @@ -1518,7 +1518,7 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } break; case 'i': // dmhi - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { if (!GH(update_main_arena) (core, m_arena, main_arena)) { break; } @@ -1528,13 +1528,13 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { m_state = core->offset; } } else { - m_state = r_num_get (NULL, input); + m_state = rz_num_get (NULL, input); } GH(print_malloc_info) (core, m_arena, m_state); } break; case 'm': // "dmhm" - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { switch (input[1]) { case '*': @@ -1559,7 +1559,7 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } } } else { - m_arena = r_num_get (NULL, input); + m_arena = rz_num_get (NULL, input); if (!GH(update_main_arena) (core, m_arena, main_arena)) { break; } @@ -1568,12 +1568,12 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } break; case 'b': // "dmhb" - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { char *m_state_str, *dup = strdup (input + 1); if (*dup) { strtok (dup, ":"); m_state_str = strtok (NULL, ":"); - m_state = r_num_get (NULL, m_state_str); + m_state = rz_num_get (NULL, m_state_str); if (!m_state) { m_state = m_arena; } @@ -1599,18 +1599,18 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } break; case 'c': // "dmhc" - if (GH(r_resolve_main_arena)(core, &m_arena)) { + if (GH(rz_resolve_main_arena)(core, &m_arena)) { GH(print_heap_chunk) (core); } break; case 'f': // "dmhf" - if (GH(r_resolve_main_arena) (core, &m_arena)) { - bool demangle = r_config_get_i (core->config, "dbg.glibc.demangle"); + if (GH(rz_resolve_main_arena) (core, &m_arena)) { + bool demangle = rz_config_get_i (core->config, "dbg.glibc.demangle"); char *m_state_str, *dup = strdup (input + 1); if (*dup) { strtok (dup, ":"); m_state_str = strtok (NULL, ":"); - m_state = r_num_get (NULL, m_state_str); + m_state = rz_num_get (NULL, m_state_str); if (!m_state) { m_state = m_arena; } @@ -1647,7 +1647,7 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { if (input[0] == 'j') { format = 'j'; } - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { input += 1; if (!strcmp (input, "\0")) { @@ -1656,7 +1656,7 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { get_state = true; } } else { - m_state = r_num_get (NULL, input); + m_state = rz_num_get (NULL, input); get_state = true; } if (!get_state) { @@ -1673,16 +1673,16 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) { } break; case 't': - if (GH(r_resolve_main_arena) (core, &m_arena)) { + if (GH(rz_resolve_main_arena) (core, &m_arena)) { if (!GH(update_main_arena) (core, m_arena, main_arena)) { break; } - bool demangle = r_config_get_i (core->config, "dbg.glibc.demangle"); + bool demangle = rz_config_get_i (core->config, "dbg.glibc.demangle"); GH(print_tcache_instance) (core, m_arena, main_arena, demangle); } break; case '?': - r_core_cmd_help (core, GH(help_msg)); + rz_core_cmd_help (core, GH(help_msg)); break; } free (main_arena); diff --git a/libr/core/linux_heap_jemalloc.c b/librz/core/linux_heap_jemalloc.c similarity index 73% rename from libr/core/linux_heap_jemalloc.c rename to librz/core/linux_heap_jemalloc.c index 1808126d46..b7387c4132 100644 --- a/libr/core/linux_heap_jemalloc.c +++ b/librz/core/linux_heap_jemalloc.c @@ -26,9 +26,9 @@ // TODO: provide proper api in cbin to resolve symbols and load libraries from debug maps and such // this is, provide a programmatic api for the slow dmi command static GHT GH(je_get_va_symbol)(const char *path, const char *symname) { - RListIter *iter; + RzListIter *iter; RBinSymbol *s; - RCore *core = r_core_new (); + RzCore *core = rz_core_new (); GHT vaddr = 0LL; if (!core) { @@ -36,21 +36,21 @@ static GHT GH(je_get_va_symbol)(const char *path, const char *symname) { } RBinOptions opt; - r_bin_options_init (&opt, -1, 0, 0, false); - if (r_bin_open (core->bin, path, &opt)) { - RList *syms = r_bin_get_symbols (core->bin); + rz_bin_options_init (&opt, -1, 0, 0, false); + if (rz_bin_open (core->bin, path, &opt)) { + RzList *syms = rz_bin_get_symbols (core->bin); if (!syms) { - r_core_free (core); + rz_core_free (core); return GHT_MAX; } - r_list_foreach (syms, iter, s) { + rz_list_foreach (syms, iter, s) { if (!strcmp(s->name, symname)) { vaddr = s->vaddr; break; } } } - r_core_free (core); + rz_core_free (core); return vaddr; } @@ -60,17 +60,17 @@ static int GH(je_matched)(const char *ptr, const char *str) { } #endif -static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, ut64 *symbol) { - RListIter *iter; - RDebugMap *map; +static bool GH(rz_resolve_jemalloc)(RzCore *core, char *symname, ut64 *symbol) { + RzListIter *iter; + RzDebugMap *map; const char *jemalloc_ver_end = NULL; ut64 jemalloc_addr = UT64_MAX; if (!core || !core->dbg || !core->dbg->maps){ return false; } - r_debug_map_sync (core->dbg); - r_list_foreach (core->dbg->maps, iter, map) { + rz_debug_map_sync (core->dbg); + rz_list_foreach (core->dbg->maps, iter, map) { if (strstr (map->name, "libjemalloc.")) { jemalloc_addr = map->addr; jemalloc_ver_end = map->name; @@ -88,8 +88,8 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, ut64 *symbol) { eprintf ("Warning: Is libjemalloc.so.2 in /usr/local/lib path?\n"); return false; } - char *path = r_str_newf ("%s", jemalloc_ver_end); - if (r_file_exists (path)) { + char *path = rz_str_newf ("%s", jemalloc_ver_end); + if (rz_file_exists (path)) { ut64 vaddr = GH(je_get_va_symbol)(path, symname); if (jemalloc_addr != GHT_MAX && vaddr != 0) { *symbol = jemalloc_addr + vaddr; @@ -102,8 +102,8 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, ut64 *symbol) { #else eprintf ("[*] Resolving %s from libjemalloc.2... ", symname); // this is quite sloooow, we must optimize dmi - char *va = r_core_cmd_strf (core, "dmi libjemalloc.2 %s$~[1]", symname, symname); - ut64 n = r_num_get (NULL, va); + char *va = rz_core_cmd_strf (core, "dmi libjemalloc.2 %s$~[1]", symname, symname); + ut64 n = rz_num_get (NULL, va); if (n && n != UT64_MAX) { *symbol = n; eprintf ("0x%08"PFMT64x"\n", n); @@ -115,15 +115,15 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, ut64 *symbol) { #endif } -static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { +static void GH(jemalloc_get_chunks)(RzCore *core, const char *input) { ut64 cnksz; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; - if (!GH(r_resolve_jemalloc)(core, "je_chunksize", &cnksz)) { + if (!GH(rz_resolve_jemalloc)(core, "je_chunksize", &cnksz)) { eprintf ("Fail at read symbol je_chunksize\n"); return; } - r_io_read_at (core->io, cnksz, (ut8 *)&cnksz, sizeof (GHT)); + rz_io_read_at (core->io, cnksz, (ut8 *)&cnksz, sizeof (GHT)); switch (input[0]) { case '\0': @@ -135,11 +135,11 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { arena_t *ar = R_NEW0 (arena_t); extent_node_t *node = R_NEW0 (extent_node_t), *head = R_NEW0 (extent_node_t); input += 1; - arena = r_num_math (core->num, input); + arena = rz_num_math (core->num, input); if (arena) { - r_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); - r_io_read_at (core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t)); + rz_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); + rz_io_read_at (core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t)); if (head->en_addr) { PRINT_YA (" Chunk - start: "); PRINTF_BA ("0x%08"PFMT64x, (ut64)(size_t)head->en_addr); @@ -147,7 +147,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { PRINTF_BA ("0x%08"PFMT64x, (ut64)(size_t)((char *)head->en_addr + cnksz)); PRINT_YA (", size: "); PRINTF_BA ("0x%08"PFMT64x"\n", (ut64)cnksz); - r_io_read_at (core->io, (ut64)(size_t)head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); + rz_io_read_at (core->io, (ut64)(size_t)head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); while (node && node->en_addr != head->en_addr) { PRINT_YA (" Chunk - start: "); PRINTF_BA ("0x%08"PFMT64x, (ut64)(size_t)node->en_addr); @@ -155,7 +155,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { PRINTF_BA ("0x%"PFMTx, ((char *)node->en_addr + cnksz)); PRINT_YA (", size: "); PRINTF_BA ("0x%08"PFMTx"\n", cnksz); - r_io_read_at (core->io, (ut64)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); + rz_io_read_at (core->io, (ut64)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); } } } @@ -183,16 +183,16 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { input += 1; - if (GH(r_resolve_jemalloc) (core, "je_arenas", &sym)) { - r_io_read_at (core->io, sym, (ut8 *)&arenas, sizeof (GHT)); + if (GH(rz_resolve_jemalloc) (core, "je_arenas", &sym)) { + rz_io_read_at (core->io, sym, (ut8 *)&arenas, sizeof (GHT)); for (;;) { - r_io_read_at (core->io, arenas + i * sizeof (GHT), (ut8 *)&arena, sizeof (GHT)); + rz_io_read_at (core->io, arenas + i * sizeof (GHT), (ut8 *)&arena, sizeof (GHT)); if (!arena) { break; } PRINTF_GA ("arenas[%d]: @ 0x%"PFMTx" { \n", i++, (GHT)arena); - r_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); - r_io_read_at (core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t)); + rz_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); + rz_io_read_at (core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t)); if (head->en_addr != 0) { PRINT_YA (" Chunk - start: "); PRINTF_BA ("0x%08"PFMT64x, (ut64)(size_t)head->en_addr); @@ -201,7 +201,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { PRINT_YA (", size: "); PRINTF_BA ("0x%08"PFMT64x"\n", (ut64)cnksz); ut64 addr = (ut64) (size_t)head->ql_link.qre_next; - r_io_read_at (core->io, addr, (ut8 *)node, sizeof (extent_node_t)); + rz_io_read_at (core->io, addr, (ut8 *)node, sizeof (extent_node_t)); while (node && head && node->en_addr != head->en_addr) { PRINT_YA (" Chunk - start: "); PRINTF_BA ("0x%08"PFMT64x, (ut64)(size_t)node->en_addr); @@ -209,7 +209,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { PRINTF_BA ("0x%"PFMT64x, (ut64)(size_t)((char *)node->en_addr + cnksz)); PRINT_YA (", size: "); PRINTF_BA ("0x%"PFMT64x"\n", cnksz); - r_io_read_at (core->io, (GHT)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); + rz_io_read_at (core->io, (GHT)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); } } PRINT_GA ("}\n"); @@ -223,7 +223,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) { } } -static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { +static void GH(jemalloc_print_narenas)(RzCore *core, const char *input) { ut64 symaddr; ut64 arenas; GHT arena = GHT_MAX; @@ -238,12 +238,12 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { } int i = 0; GHT narenas = 0; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; switch (input[0]) { case '\0': - if (GH(r_resolve_jemalloc)(core, "narenas_total", &symaddr)) { - r_io_read_at (core->io, symaddr, (ut8 *)&narenas, sizeof (GHT)); + if (GH(rz_resolve_jemalloc)(core, "narenas_total", &symaddr)) { + rz_io_read_at (core->io, symaddr, (ut8 *)&narenas, sizeof (GHT)); PRINTF_GA ("narenas : %d\n", narenas); } if (narenas == 0) { @@ -259,12 +259,12 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { return; } - if (GH(r_resolve_jemalloc)(core, "je_arenas", &arenas)) { - r_io_read_at (core->io, arenas, (ut8 *)&arenas, sizeof (GHT)); + if (GH(rz_resolve_jemalloc)(core, "je_arenas", &arenas)) { + rz_io_read_at (core->io, arenas, (ut8 *)&arenas, sizeof (GHT)); PRINTF_GA ("arenas[%d] @ 0x%"PFMTx" {\n", narenas, (GHT)arenas); for (i = 0; i < narenas; i++) { ut64 at = arenas + (i * sizeof (GHT)); - r_io_read_at (core->io, at, (ut8 *)&arena, sizeof (GHT)); + rz_io_read_at (core->io, at, (ut8 *)&arena, sizeof (GHT)); if (!arena) { PRINTF_YA (" arenas[%d]: (empty)\n", i); continue; @@ -276,11 +276,11 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { PRINT_GA ("}\n"); break; case ' ': - arena = r_num_math (core->num, input + 1); - r_io_read_at (core->io, (GHT)arena, (ut8 *)ar, sizeof (arena_t)); + arena = rz_num_math (core->num, input + 1); + rz_io_read_at (core->io, (GHT)arena, (ut8 *)ar, sizeof (arena_t)); PRINT_GA ("struct arena_s {\n"); -#define OO(x) arena + r_offsetof (arena_t, x) +#define OO(x) arena + rz_offsetof (arena_t, x) PRINTF_BA (" ind = 0x%"PFMTx"\n", ar->ind); PRINTF_BA (" nthreads: application allocation = 0x%"PFMTx"\n", (ut32)ar->nthreads[0]); PRINTF_BA (" nthreads: internal metadata allocation = 0x%"PFMTx"\n", (ut32)ar->nthreads[1]); @@ -294,7 +294,7 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { PRINTF_BA (" extent_sn_next = 0x%"PFMTx"\n", (ut64)(size_t)ar->extent_sn_next); PRINTF_BA (" spare = 0x%"PFMT64x"\n", (ut64)(size_t)ar->spare); PRINTF_BA (" lg_dirty_mult = 0x%"PFMT64x"\n", (ut64)(ssize_t)ar->lg_dirty_mult); - PRINTF_BA (" purging = %s\n", r_str_bool (ar->purging)); + PRINTF_BA (" purging = %s\n", rz_str_bool (ar->purging)); PRINTF_BA (" nactive = 0x%"PFMT64x"\n", (ut64)(size_t)ar->nactive); PRINTF_BA (" ndirty = 0x%"PFMT64x"\n", (ut64)(size_t)ar->ndirty); @@ -321,14 +321,14 @@ static void GH(jemalloc_print_narenas)(RCore *core, const char *input) { free (stats); } -static void GH(jemalloc_get_bins)(RCore *core, const char *input) { +static void GH(jemalloc_get_bins)(RzCore *core, const char *input) { int i = 0, j; ut64 bin_info; ut64 arenas; GHT arena = GHT_MAX; //, bin = GHT_MAX; arena_t *ar = NULL; arena_bin_info_t *b = NULL; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; switch (input[0]) { case ' ': @@ -340,16 +340,16 @@ static void GH(jemalloc_get_bins)(RCore *core, const char *input) { if (!b) { break; } - if (!GH(r_resolve_jemalloc)(core, "je_arena_bin_info", &bin_info)) { + if (!GH(rz_resolve_jemalloc)(core, "je_arena_bin_info", &bin_info)) { eprintf ("Error resolving je_arena_bin_info\n"); R_FREE (b); break; } - if (GH(r_resolve_jemalloc)(core, "je_arenas", &arenas)) { - r_io_read_at (core->io, arenas, (ut8 *)&arenas, sizeof (GHT)); + if (GH(rz_resolve_jemalloc)(core, "je_arenas", &arenas)) { + rz_io_read_at (core->io, arenas, (ut8 *)&arenas, sizeof (GHT)); PRINTF_GA ("arenas @ 0x%"PFMTx" {\n", (GHT)arenas); for (;;) { - r_io_read_at (core->io, arenas + i * sizeof (GHT), (ut8 *)&arena, sizeof (GHT)); + rz_io_read_at (core->io, arenas + i * sizeof (GHT), (ut8 *)&arena, sizeof (GHT)); if (!arena) { R_FREE (b); break; @@ -357,9 +357,9 @@ static void GH(jemalloc_get_bins)(RCore *core, const char *input) { PRINTF_YA (" arenas[%d]: ", i++); PRINTF_BA ("@ 0x%"PFMTx, (GHT)arena); PRINT_YA (" {\n"); - r_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); + rz_io_read_at (core->io, arena, (ut8 *)ar, sizeof (arena_t)); for (j = 0; j < JM_NBINS; j++) { - r_io_read_at (core->io, (GHT)(bin_info + j * sizeof (arena_bin_info_t)), + rz_io_read_at (core->io, (GHT)(bin_info + j * sizeof (arena_bin_info_t)), (ut8*)b, sizeof (arena_bin_info_t)); PRINT_YA (" {\n"); PRINT_YA (" regsize : "); @@ -398,7 +398,7 @@ static void GH(jemalloc_get_bins)(RCore *core, const char *input) { } #if 0 -static void GH(jemalloc_get_runs)(RCore *core, const char *input) { +static void GH(jemalloc_get_runs)(RzCore *core, const char *input) { switch (input[0]) { case ' ': { @@ -412,40 +412,40 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) { } input += 1; - chunk = r_num_math (core->num, input); + chunk = rz_num_math (core->num, input); - if (!GH(r_resolve_jemalloc)(core, "je_chunk_npages", &npages)) { + if (!GH(rz_resolve_jemalloc)(core, "je_chunk_npages", &npages)) { eprintf ("Error resolving je_chunk_npages\n"); return; } - if (!GH(r_resolve_jemalloc)(core, "je_chunksize_mask", &chunksize_mask)) { + if (!GH(rz_resolve_jemalloc)(core, "je_chunksize_mask", &chunksize_mask)) { eprintf ("Error resolving je_chunksize_mask\n"); return; } - if (!GH(r_resolve_jemalloc)(core, "je_map_bias", &map_bias)) { + if (!GH(rz_resolve_jemalloc)(core, "je_map_bias", &map_bias)) { eprintf ("Error resolving je_map_bias"); return; } - if (!GH(r_resolve_jemalloc)(core, "je_map_misc_offset", &map_misc_offset)) { + if (!GH(rz_resolve_jemalloc)(core, "je_map_misc_offset", &map_misc_offset)) { eprintf ("Error resolving je_map_misc_offset"); return; } - r_io_read_at (core->io, npages, (ut8*)&npages, sizeof (GHT)); - r_io_read_at (core->io, chunksize_mask, (ut8*)&chunksize_mask, sizeof (GHT)); - r_io_read_at (core->io, map_bias, (ut8*)&map_bias, sizeof (GHT)); - r_io_read_at (core->io, map_misc_offset, (ut8*)&map_misc_offset, sizeof (GHT)); + rz_io_read_at (core->io, npages, (ut8*)&npages, sizeof (GHT)); + rz_io_read_at (core->io, chunksize_mask, (ut8*)&chunksize_mask, sizeof (GHT)); + rz_io_read_at (core->io, map_bias, (ut8*)&map_bias, sizeof (GHT)); + rz_io_read_at (core->io, map_misc_offset, (ut8*)&map_misc_offset, sizeof (GHT)); eprintf ("map_misc_offset 0x%08"PFMT64x"\n", (ut64)map_misc_offset); - r_io_read_at (core->io, chunk, (ut8 *)c, sizeof (arena_chunk_t)); + rz_io_read_at (core->io, chunk, (ut8 *)c, sizeof (arena_chunk_t)); mapbits = *(GHT *)&c->map_bits; eprintf ("map_bits: 0x%08"PFMT64x"\n", (ut64)mapbits); - uint32_t offset = r_offsetof (arena_chunk_t, map_bits); + uint32_t offset = rz_offsetof (arena_chunk_t, map_bits); arena_chunk_map_bits_t *dwords = (void *)calloc (sizeof (arena_chunk_map_bits_t), npages); - r_io_read_at (core->io, chunk + offset, (ut8*)dwords, sizeof (arena_chunk_map_bits_t) * npages); + rz_io_read_at (core->io, chunk + offset, (ut8*)dwords, sizeof (arena_chunk_map_bits_t) * npages); eprintf ("map_bits @ 0x%08"PFMT64x"\n", (ut64)(chunk + offset)); arena_run_t *r = R_NEW0 (arena_run_t); @@ -461,10 +461,10 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) { eprintf ("\nelm: 0x%"PFMT64x"\n", elm); arena_chunk_map_misc_t *m = R_NEW0 (arena_chunk_map_misc_t); if (m) { - ut64 run = elm + r_offsetof (arena_chunk_map_misc_t, run); - r_io_read_at (core->io, elm, (ut8*)m, sizeof (arena_chunk_map_misc_t)); + ut64 run = elm + rz_offsetof (arena_chunk_map_misc_t, run); + rz_io_read_at (core->io, elm, (ut8*)m, sizeof (arena_chunk_map_misc_t)); eprintf ("Small run @ 0x%08"PFMT64x"\n", (ut64)elm); - r_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t)); + rz_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t)); eprintf ("binind: 0x%08"PFMT64x"\n", (ut64)r->binind); eprintf ("nfree: 0x%08"PFMT64x"\n", (ut64)r->nfree); eprintf ("bitmap: 0x%08"PFMT64x"\n\n", (ut64)*(GHT*)r->bitmap); @@ -473,7 +473,7 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) { } else if (mapelm.bits & CHUNK_MAP_LARGE) { ut64 run = (ut64) (size_t) chunk + (pageind << LG_PAGE); eprintf ("Large run @ 0x%08"PFMT64x"\n", run); - r_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t)); + rz_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t)); eprintf ("binind: 0x%08"PFMT64x"\n", (ut64)r->binind); eprintf ("nfree: 0x%08"PFMT64x"\n", (ut64)r->nfree); eprintf ("bitmap: 0x%08"PFMT64x"\n\n", (ut64)*(GHT*)r->bitmap); @@ -487,7 +487,7 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) { } #endif -static int GH(cmd_dbg_map_jemalloc)(RCore *core, const char *input) { +static int GH(cmd_dbg_map_jemalloc)(RzCore *core, const char *input) { const char *help_msg[] = { "Usage:", "dmh", " # Memory map heap", "dmha", "[arena_t]", "show all arenas created, or print arena_t structure for given arena", @@ -499,7 +499,7 @@ static int GH(cmd_dbg_map_jemalloc)(RCore *core, const char *input) { switch (input[0]) { case '?': - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); break; case 'a': //dmha GH(jemalloc_print_narenas) (core, input + 1); diff --git a/libr/core/meson.build b/librz/core/meson.build similarity index 55% rename from libr/core/meson.build rename to librz/core/meson.build index 94ab722943..5ad23395f2 100644 --- a/libr/core/meson.build +++ b/librz/core/meson.build @@ -1,4 +1,4 @@ -r_core_sources = [ +rz_core_sources = [ 'anal_tp.c', 'anal_objc.c', 'casm.c', @@ -69,37 +69,37 @@ r_core_sources = [ 'cannotated_code.c' ] -r_core_inc = [] +rz_core_inc = [] if host_machine.system() != 'windows' - r_core_inc += ['../../shlr/heap/include'] + rz_core_inc += ['../../shlr/heap/include'] else - r_core_sources += 'windows_heap.c' - r_core_inc += ['../../shlr/heap/include/r_windows'] + rz_core_sources += 'windows_heap.c' + rz_core_inc += ['../../shlr/heap/include/rz_windows'] endif -r_core_inc = [platform_inc, include_directories(r_core_inc)] +rz_core_inc = [platform_inc, include_directories(rz_core_inc)] -r_core_deps = [ - r_util_dep, - r_reg_dep, - r_syscall_dep, - r_search_dep, - r_cons_dep, - r_anal_dep, - r_socket_dep, - r_io_dep, - r_fs_dep, - r_lang_dep, - r_magic_dep, - r_hash_dep, - r_flag_dep, - r_parse_dep, - r_egg_dep, - r_debug_dep, - r_crypto_dep, - r_config_dep, - r_bin_dep, - r_asm_dep, - r_bp_dep, +rz_core_deps = [ + rz_util_dep, + rz_reg_dep, + rz_syscall_dep, + rz_search_dep, + rz_cons_dep, + rz_anal_dep, + rz_socket_dep, + rz_io_dep, + rz_fs_dep, + rz_lang_dep, + rz_magic_dep, + rz_hash_dep, + rz_flag_dep, + rz_parse_dep, + rz_egg_dep, + rz_debug_dep, + rz_crypto_dep, + rz_config_dep, + rz_bin_dep, + rz_asm_dep, + rz_bp_dep, platform_deps, gdb_dep, java_dep, @@ -108,50 +108,50 @@ r_core_deps = [ ] if use_libuv - r_core_deps += libuv_dep + rz_core_deps += libuv_dep endif -r_core = library('r_core', r_core_sources, - include_directories: r_core_inc, +rz_core = library('rz_core', rz_core_sources, + include_directories: rz_core_inc, c_args: library_cflags, - dependencies: r_core_deps, + dependencies: rz_core_deps, install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_core_dep = declare_dependency(link_with: r_core, - include_directories: r_core_inc) +rz_core_dep = declare_dependency(link_with: rz_core, + include_directories: rz_core_inc) pkgconfig_mod.generate( - r_core, - subdirs: 'libr', + rz_core, + subdirs: 'librz', version: r2_version, - name: 'r_core', - filebase: 'r_core', + name: 'rz_core', + filebase: 'rz_core', libraries: pkgcfg_sanitize_libs, requires: pkgconfig_magic_requires + [ - 'r_util', - 'r_reg', - 'r_syscall', - 'r_search', - 'r_cons', - 'r_anal', - 'r_socket', - 'r_io', - 'r_fs', - 'r_lang', - 'r_hash', - 'r_flag', - 'r_parse', - 'r_egg', - 'r_debug', - 'r_crypto', - 'r_config', - 'r_bin', - 'r_asm', - 'r_bp' + 'rz_util', + 'rz_reg', + 'rz_syscall', + 'rz_search', + 'rz_cons', + 'rz_anal', + 'rz_socket', + 'rz_io', + 'rz_fs', + 'rz_lang', + 'rz_hash', + 'rz_flag', + 'rz_parse', + 'rz_egg', + 'rz_debug', + 'rz_crypto', + 'rz_config', + 'rz_bin', + 'rz_asm', + 'rz_bp' ], description: 'radare foundation libraries' ) diff --git a/libr/core/p/Makefile b/librz/core/p/Makefile similarity index 50% rename from libr/core/p/Makefile rename to librz/core/p/Makefile index 1140a99a0d..3277774cd3 100644 --- a/libr/core/p/Makefile +++ b/librz/core/p/Makefile @@ -4,15 +4,15 @@ include ../../../shlr/zip/deps.mk CFLAGS+=-I../../include -Wall -shared CFLAGS+=${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}.. -CFLAGS+=-L../../util -lr_util -L../../reg -lr_reg -L.. -lr_core -CFLAGS+=-L../../cons -lr_cons -L../../bin -lr_bin -CFLAGS+=-L../../parse -lr_parse -L../../io -lr_io -L../../fs -lr_fs -CFLAGS+=-L../../magic -lr_magic -L../../hash -lr_hash -CFLAGS+=-L../../config -lr_config -CFLAGS+=-L../../anal -lr_anal -L../../egg -lr_egg -L../../flag -lr_flag -CFLAGS+=-L../../syscall -lr_syscall -L../../socket -lr_socket -L../../search -lr_search -CFLAGS+= -L../../lang -lr_lang -L../../debug -lr_debug -CFLAGS+=-L../../bp -lr_bp -L../../reg -lr_reg -L../../asm -lr_asm +CFLAGS+=-L../../util -lrz_util -L../../reg -lrz_reg -L.. -lrz_core +CFLAGS+=-L../../cons -lrz_cons -L../../bin -lrz_bin +CFLAGS+=-L../../parse -lrz_parse -L../../io -lrz_io -L../../fs -lrz_fs +CFLAGS+=-L../../magic -lrz_magic -L../../hash -lrz_hash +CFLAGS+=-L../../config -lrz_config +CFLAGS+=-L../../anal -lrz_anal -L../../egg -lrz_egg -L../../flag -lrz_flag +CFLAGS+=-L../../syscall -lrz_syscall -L../../socket -lrz_socket -L../../search -lrz_search +CFLAGS+= -L../../lang -lrz_lang -L../../debug -lrz_debug +CFLAGS+=-L../../bp -lrz_bp -L../../reg -lrz_reg -L../../asm -lrz_asm LDFLAGS+=$(STOP)/sdb/src/libsdb.a diff --git a/libr/core/p/a2f.mk b/librz/core/p/a2f.mk similarity index 90% rename from libr/core/p/a2f.mk rename to librz/core/p/a2f.mk index af9831ef8f..c02253f17f 100644 --- a/libr/core/p/a2f.mk +++ b/librz/core/p/a2f.mk @@ -10,6 +10,6 @@ ${CORE_TARGET_A2F}: ${CORE_OBJ_A2F} ${CC} $(call libname,core_anal) ${CFLAGS} \ -o core_a2f.${EXT_SO} \ $(SHLR)/sdb/src/libsdb.a \ - -L$(LIBR)/crypto -lr_crypto \ + -L$(LIBR)/crypto -lrz_crypto \ ${CORE_OBJ_A2F} endif diff --git a/libr/core/p/core_a2f.c b/librz/core/p/core_a2f.c similarity index 81% rename from libr/core/p/core_a2f.c rename to librz/core/p/core_a2f.c index f4e093bd6c..b7421eea97 100644 --- a/libr/core/p/core_a2f.c +++ b/librz/core/p/core_a2f.c @@ -1,8 +1,8 @@ /* radare - Copyright 2014-2018 pancake, defragger */ -#include -#include -#include +#include +#include +#include #define MAXFCNSIZE 4096 @@ -95,7 +95,7 @@ static int bbAdd(Sdb *db, ut64 from, ut64 to, ut64 jump, ut64 fail) { return 0; } -void addTarget(RCore *core, RStack *stack, Sdb *db, ut64 addr) { +void addTarget(RzCore *core, RStack *stack, Sdb *db, ut64 addr) { if (!sdb_num_get (db, Fhandled(addr), NULL)) { ut64* value = (ut64*) malloc (1 * sizeof (ut64)); if (!value) { @@ -103,7 +103,7 @@ void addTarget(RCore *core, RStack *stack, Sdb *db, ut64 addr) { return; } *value = addr; - if (!r_stack_push (stack, (void*)value)) { + if (!rz_stack_push (stack, (void*)value)) { eprintf ("Failed to push address on stack\n"); free (value); return; @@ -112,7 +112,7 @@ void addTarget(RCore *core, RStack *stack, Sdb *db, ut64 addr) { } } -static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_commands) { +static ut64 analyzeStackBased(RzCore *core, Sdb *db, ut64 addr, RzList *delayed_commands) { #define addCall(x) sdb_array_add_num (db, "calls", x, 0); #define addUcall(x) sdb_array_add_num (db, "ucalls", x, 0); #define addUjmp(x) sdb_array_add_num (db, "ujmps", x, 0); @@ -121,16 +121,16 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co #define bbAddOpcode(x) sdb_array_insert_num (db, sdb_fmt ("bb.%"PFMT64x, addr+cur), -1, x, 0); ut64 oaddr = addr; ut64 *value = NULL; - RAnalOp *op; + RzAnalOp *op; int cur = 0; bool block_end = false; - RStack *stack = r_stack_newf (10, free); + RStack *stack = rz_stack_newf (10, free); addTarget (core, stack, db, addr); const ut64 maxfcnsize = 4096; - while (!r_stack_is_empty (stack)) { + while (!rz_stack_is_empty (stack)) { block_end = false; - value = (ut64*) r_stack_pop (stack); + value = (ut64*) rz_stack_pop (stack); if (!value) { eprintf ("Failed to pop next address from stack\n"); break; @@ -140,7 +140,7 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co free (value); cur = 0; while (!block_end && cur < maxfcnsize) { - op = r_core_anal_op (core, addr + cur, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); + op = rz_core_anal_op (core, addr + cur, R_ANAL_OP_MASK_BASIC | R_ANAL_OP_MASK_DISASM); if (!op || !op->mnemonic) { eprintf ("a2f: Cannot analyze opcode at 0x%"PFMT64x"\n", addr+cur); oaddr = UT64_MAX; @@ -167,7 +167,7 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co * is a new function unless the address is inside * the same range than the current function */ addCall (op->jump); - r_list_append (delayed_commands, r_str_newf ("axC %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); + rz_list_append (delayed_commands, rz_str_newf ("axC %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); break; case R_ANAL_OP_TYPE_UCALL: case R_ANAL_OP_TYPE_ICALL: @@ -179,7 +179,7 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co * there to record all possible destinations */ addUcall (addr+cur); if (op->ptr != UT64_MAX) { - r_list_append (delayed_commands, r_str_newf ("axC %"PFMT64d" %"PFMT64d, op->ptr, addr + cur)); + rz_list_append (delayed_commands, rz_str_newf ("axC %"PFMT64d" %"PFMT64d, op->ptr, addr + cur)); } break; case R_ANAL_OP_TYPE_UJMP: @@ -214,14 +214,14 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co addTarget (core, stack, db, op->jump); addTarget (core, stack, db, addr + cur + op->size); block_end = true; - r_list_append (delayed_commands, r_str_newf ("axc %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); + rz_list_append (delayed_commands, rz_str_newf ("axc %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); break; case R_ANAL_OP_TYPE_JMP: addUjmp (addr+cur); bbAdd (db, addr, addr + cur + op->size, op->jump, UT64_MAX); addTarget (core, stack, db, op->jump); block_end = true; - r_list_append (delayed_commands, r_str_newf ("axc %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); + rz_list_append (delayed_commands, rz_str_newf ("axc %"PFMT64d" %"PFMT64d, op->jump, addr + cur)); break; case R_ANAL_OP_TYPE_UNK: case R_ANAL_OP_TYPE_ILL: @@ -230,17 +230,17 @@ static ut64 analyzeStackBased(RCore *core, Sdb *db, ut64 addr, RList *delayed_co break; default: if (op->ptr != UT64_MAX) { - r_list_append (delayed_commands, r_str_newf ("axd %"PFMT64d" %"PFMT64d, op->ptr, addr + cur)); + rz_list_append (delayed_commands, rz_str_newf ("axd %"PFMT64d" %"PFMT64d, op->ptr, addr + cur)); } break; } cur += op->size; - r_anal_op_free (op); + rz_anal_op_free (op); op = NULL; } } - r_stack_free (stack); + rz_stack_free (stack); return oaddr; } @@ -269,21 +269,21 @@ static ut64 getFunctionSize(Sdb *db) { return max - min; } -static int analyzeFunction(RCore *core, ut64 addr) { +static int analyzeFunction(RzCore *core, ut64 addr) { Sdb *db = sdb_new0 (); - RFlagItem *fi; - RList *delayed_commands = NULL; - RListIter *iter; + RzFlagItem *fi; + RzList *delayed_commands = NULL; + RzListIter *iter; ut64 loc_addr = 0; char *command = NULL; char *function_label; - bool vars = r_config_get_i (core->config, "anal.vars"); + bool vars = rz_config_get_i (core->config, "anal.vars"); if (!db) { eprintf ("Cannot create db\n"); return false; } - delayed_commands = r_list_newf (free); + delayed_commands = rz_list_newf (free); if (!delayed_commands) { eprintf ("Failed to initialize the delayed command list\n"); sdb_free (db); @@ -314,16 +314,16 @@ static int analyzeFunction(RCore *core, ut64 addr) { sdb_num_set (db, "size", getFunctionSize (db), 0); // receiving a possible flag to label the new function - fi = r_flag_get_at (core->flags, addr, false); + fi = rz_flag_get_at (core->flags, addr, false); if (fi && fi->name && strncmp (fi->name, "sect", 4)) { function_label = strdup (fi->name); } else { - function_label = r_str_newf ("fcn2.%08"PFMT64x, addr); + function_label = rz_str_newf ("fcn2.%08"PFMT64x, addr); } // loc_addr = core->offset; // sdb_num_get (db, "addr", NULL); loc_addr = sdb_num_get (db, "addr", NULL); - // r_cons_printf ("af+ 0x%08"PFMT64x" %s\n", loc_addr, function_label); - r_core_cmdf (core, "af+ 0x%08"PFMT64x" %s", loc_addr, function_label); + // rz_cons_printf ("af+ 0x%08"PFMT64x" %s\n", loc_addr, function_label); + rz_core_cmdf (core, "af+ 0x%08"PFMT64x" %s", loc_addr, function_label); { char *c, *bbs = sdb_get (db, "bbs", NULL); sdb_aforeach (c, bbs) { @@ -333,23 +333,23 @@ static int analyzeFunction(RCore *core, ut64 addr) { ut64 jump = sdb_array_get_num (db, FbbTo (addr), 0, NULL); ut64 fail = sdb_array_get_num (db, FbbTo (addr), 1, NULL); - // r_cons_printf ("afb+ 0x%"PFMT64x" 0x%"PFMT64x" %d 0x%"PFMT64x" 0x%"PFMT64x"\n", + // rz_cons_printf ("afb+ 0x%"PFMT64x" 0x%"PFMT64x" %d 0x%"PFMT64x" 0x%"PFMT64x"\n", // loc_addr, addr, (int)(addr_end - addr), jump, fail); - r_core_cmdf (core, "afb+ 0x%"PFMT64x" 0x%"PFMT64x" %d 0x%"PFMT64x" 0x%"PFMT64x, + rz_core_cmdf (core, "afb+ 0x%"PFMT64x" 0x%"PFMT64x" %d 0x%"PFMT64x" 0x%"PFMT64x, loc_addr, addr, (int)(addr_end - addr), jump, fail); sdb_aforeach_next (c); } if (vars) { // handling arguments - r_core_cmdf (core, "afva @ 0x%"PFMT64x, addr); + rz_core_cmdf (core, "afva @ 0x%"PFMT64x, addr); } free (bbs); free (function_label); } - r_list_foreach (delayed_commands, iter, command) { + rz_list_foreach (delayed_commands, iter, command) { if (command) { - r_core_cmd0 (core, command); + rz_core_cmd0 (core, command); command = NULL; } } @@ -360,18 +360,18 @@ static int analyzeFunction(RCore *core, ut64 addr) { // char *c, *calls = sdb_get (db, "calls", NULL); // sdb_aforeach (c, calls) { // ut64 addr = sdb_atoi (c); - // r_cons_printf ("a2f @ 0x%"PFMT64x"\n", addr); + // rz_cons_printf ("a2f @ 0x%"PFMT64x"\n", addr); // sdb_aforeach_next (c); // } // free (calls); // } - r_list_free (delayed_commands); + rz_list_free (delayed_commands); sdb_free (db); return true; } -static int r_cmd_anal_call(void *user, const char *input) { - RCore *core = (RCore *) user; +static int rz_cmd_anal_call(void *user, const char *input) { + RzCore *core = (RzCore *) user; if (!strncmp (input, "a2", 2)) { switch (input[2]) { case 'f': @@ -391,17 +391,17 @@ static int r_cmd_anal_call(void *user, const char *input) { } // PLUGIN Definition Info -RCorePlugin r_core_plugin_a2f = { +RzCorePlugin rz_core_plugin_a2f = { .name = "a2f", .desc = "The reworked analysis from scratch thing", .license = "LGPL3", - .call = r_cmd_anal_call, + .call = rz_cmd_anal_call, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CORE, - .data = &r_core_plugin_a2f, + .data = &rz_core_plugin_a2f, .version = R2_VERSION }; #endif diff --git a/librz/core/p/core_java.c b/librz/core/p/core_java.c new file mode 100644 index 0000000000..e35ea63d73 --- /dev/null +++ b/librz/core/p/core_java.c @@ -0,0 +1,1976 @@ +/* radare - Apache - Copyright 2014-2019 - dso, pancake */ + +#include +#include +#include +#include +#include +#include +#include + +#include "../../../shlr/java/ops.h" +#include "../../../shlr/java/class.h" +#include "../../../shlr/java/code.h" +#include "../../../shlr/java/dsojson.h" + +#define DO_THE_DBG 0 +#undef IFDBG +#define IFDBG if (DO_THE_DBG) + + +typedef struct found_idx_t { + ut16 idx; + ut64 addr; + const RBinJavaCPTypeObj *obj; +} RzCmdJavaCPResult; + +typedef int (*RCMDJavaCmdHandler) (RzCore *core, const char *cmd); + +static const char * rz_cmd_java_strtok (const char *str1, const char b, size_t len); +static const char * rz_cmd_java_consumetok (const char *str1, const char b, size_t len); +static int rz_cmd_java_reload_bin_from_buf (RzCore *core, RBinJavaObj *obj, ut8* buffer, ut64 len); + +static int rz_cmd_java_print_json_definitions( RBinJavaObj *obj ); +static int rz_cmd_java_print_all_definitions( RzAnal *anal ); +static int rz_cmd_java_print_class_definitions( RBinJavaObj *obj ); +static int rz_cmd_java_print_field_definitions( RBinJavaObj *obj ); +static int rz_cmd_java_print_method_definitions( RBinJavaObj *obj ); +static int rz_cmd_java_print_import_definitions( RBinJavaObj *obj ); + +static int rz_cmd_java_resolve_cp_idx (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_resolve_cp_type (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_resolve_cp_idx_b64 (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_resolve_cp_address (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_resolve_cp_to_key (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_resolve_cp_summary (RBinJavaObj *obj, ut16 idx); + +static int rz_cmd_java_print_class_access_flags_value( const char * flags ); +static int rz_cmd_java_print_field_access_flags_value( const char * flags ); +static int rz_cmd_java_print_method_access_flags_value( const char * flags ); +static int rz_cmd_java_get_all_access_flags_value (const char *cmd); + +static int rz_cmd_java_set_acc_flags (RzCore *core, ut64 addr, ut16 num_acc_flag); + +#define _(x) UNUSED_FUNCTION(x) +static int rz_cmd_java_print_field_summary (RBinJavaObj *obj, ut16 idx); +static int _(rz_cmd_java_print_field_count) (RBinJavaObj *obj); +static int rz_cmd_java_print_field_name (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_print_field_num_name (RBinJavaObj *obj); +static int rz_cmd_java_print_method_summary (RBinJavaObj *obj, ut16 idx); +static int _(rz_cmd_java_print_method_count) (RBinJavaObj *obj); +static int rz_cmd_java_print_method_name (RBinJavaObj *obj, ut16 idx); +static int rz_cmd_java_print_method_num_name (RBinJavaObj *obj); + +static RBinJavaObj * rz_cmd_java_get_bin_obj(RzAnal *anal); +static RzList * rz_cmd_java_get_bin_obj_list(RzAnal *anal); +static ut64 rz_cmd_java_get_input_num_value(RzCore *core, const char *input_value); +static int rz_cmd_java_is_valid_input_num_value(RzCore *core, const char *input_value); + + +static int rz_cmd_java_call(void *user, const char *input); +static int rz_cmd_java_handle_help(RzCore * core, const char * input); +static int rz_cmd_java_handle_set_flags(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_prototypes(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_resolve_cp(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_calc_flags(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_flags_str(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_flags_str_at(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_field_info(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_method_info(RzCore *core, const char *cmd); + +static int rz_cmd_java_handle_find_cp_const(RzCore *core, const char *cmd); + +static RzList *cpfind_float(RBinJavaObj *obj, const char *cmd); +static RzList *cpfind_double(RBinJavaObj *obj, const char *cmd); +static RzList *cpfind_long(RzCore *core, RBinJavaObj *obj, const char *cmd); +static RzList *cpfind_int(RzCore *core, RBinJavaObj *obj, const char *cmd); +static RzList *cpfind_str(RBinJavaObj *obj, const char *cmd); + +static int cpfind(RzCore *core, const char *cmd); + +static int rz_cmd_java_get_cp_bytes_and_write(RzCore *core, RBinJavaObj *obj, ut16 idx, ut64 addr, const ut8 *buf, const ut64 len); +static int rz_cmd_java_handle_replace_cp_value_float(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); +static int rz_cmd_java_handle_replace_cp_value_double(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); +static int rz_cmd_java_handle_replace_cp_value_long(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); +static int rz_cmd_java_handle_replace_cp_value_int(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); +static int rz_cmd_java_handle_replace_cp_value_str(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr); +static int rz_cmd_java_handle_replace_cp_value(RzCore *core, const char *cmd); + +static int rz_cmd_java_handle_replace_classname_value(RzCore *core, const char *cmd); +static char *rz_cmd_replace_name_def(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len); +static char *rz_cmd_replace_name(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len); +static int rz_cmd_is_object_descriptor(const char *name, ut32 name_len); +static ut32 rz_cmd_get_num_classname_str_occ(const char *str, const char *match_me); +static const char *rz_cmd_get_next_classname_str(const char *str, const char *match_me); + +static int rz_cmd_java_handle_summary_info(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_reload_bin(RzCore *core, const char *cmd); + +static int rz_cmd_java_handle_print_exceptions(RzCore *core, const char *input); +static int rz_cmd_java_handle_insert_method_ref(RzCore *core, const char *input); +static int rz_cmd_java_handle_yara_code_extraction_refs(RzCore *core, const char *input); + +static int rz_cmd_java_handle_isvalid(RzCore *core, const char *cmd); +static int rz_cmd_java_handle_calc_class_sz(RzCore *core, const char *cmd); + +typedef struct rz_cmd_java_cms_t { + const char *name; + const char *args; + const char *desc; + const ut32 name_len; + RCMDJavaCmdHandler handler; +} RzCmdJavaCmd; + +/* XXX : Most of those command arguments are absurd, must be reviewed + changed */ + +#define CALC_SZ "calc_sz" +#define CALC_SZ_ARGS " " +#define CALC_SZ_DESC "calculate class file size at location" +#define CALC_SZ_LEN 7 + +#define ISVALID "is_valid" +#define ISVALID_ARGS " " +#define ISVALID_DESC "check buffer to see if it is a valid class file" +#define ISVALID_LEN 8 + +#define SET_ACC_FLAGS "set_flags" +#define SET_ACC_FLAGS_ARGS " [addr cmf ]" //[ ] | [ < c | m | f> ]" +#define SET_ACC_FLAGS_DESC "set the access flags attributes for a field or method" +#define SET_ACC_FLAGS_LEN 9 + +#define PROTOTYPES "prototypes" +#define PROTOTYPES_ARGS " " // < j | a | i | c | m | f> +#define PROTOTYPES_DESC "show in JSON, or All,Imports,Class,Methods,Fields" +#define PROTOTYPES_LEN 10 + +#define RESOLVE_CP "resolve_cp" +#define RESOLVE_CP_ARGS " [ idx]" +#define RESOLVE_CP_DESC "cp type or value @ idx. Summary,Type,b64Encode,Const,Addr,Dump,Gsumarize" +//d = dump all, g = summarize all, s = summary, a = address, t = type, c = get value, e = base64 enode the result" +#define RESOLVE_CP_LEN 10 + +#define CALC_FLAGS "calc_flags" +#define CALC_FLAGS_ARGS " [visib.]" +//[ > | | | ]" +#define CALC_FLAGS_DESC "value from access flags: ListAll, flags, Class, Field, Method" +#define CALC_FLAGS_LEN 10 + +#define FLAGS_STR_AT "flags_str_at" +#define FLAGS_STR_AT_ARGS " [addr]" +#define FLAGS_STR_AT_DESC "string value from access flags @ addr: Class, Field, Method" +#define FLAGS_STR_AT_LEN 12 + +#define FLAGS_STR "flags_str" +#define FLAGS_STR_ARGS " [ ]" //acc_flags_value>]" +#define FLAGS_STR_DESC "string value for the flags number: Class, Field, Method" +#define FLAGS_STR_LEN 9 + +#define METHOD_INFO "m_info" +#define METHOD_INFO_ARGS " [ | ]" +//#define METHOD_INFO_DESC "method index info: c = dump methods and ord , s = dump of all meta-data, n = method" +#define METHOD_INFO_DESC "method information at index (c:method+ord, s:metadata)" +#define METHOD_INFO_LEN 6 + +#define FIELD_INFO "f_info" +#define FIELD_INFO_ARGS " [ | #idx]" +#define FIELD_INFO_DESC "field information at index (c:field+ord, s:metadata)" +// : c = dump field and ord , s = dump of all meta-data, n = method" +#define FIELD_INFO_LEN 6 + +#define HELP "help" +#define HELP_DESC "displays this message" +#define HELP_ARGS "" +#define HELP_LEN 4 + +#define FIND_CP_CONST "find_cp_const" +#define FIND_CP_CONST_ARGS " [a|#idx]" +#define FIND_CP_CONST_DESC "find references to constant CP Object in code: AllReferences" +#define FIND_CP_CONST_LEN 13 + +#define FIND_CP_VALUE "find_cp_value" +#define FIND_CP_VALUE_ARGS " [ V]" +#define FIND_CP_VALUE_DESC "find references to CP constants by value" +#define FIND_CP_VALUE_LEN 13 + +#define REPLACE_CP_VALUE "replace_cp_value" +#define REPLACE_CP_VALUE_ARGS " [ V]" +#define REPLACE_CP_VALUE_DESC "replace CP constants with value if the no resizing is required" +#define REPLACE_CP_VALUE_LEN 16 + +#define REPLACE_CLASS_NAME "replace_classname_value" +#define REPLACE_CLASS_NAME_ARGS " " +#define REPLACE_CLASS_NAME_DESC "rename class name" //"replace CP constants with value if no resize needed" +#define REPLACE_CLASS_NAME_LEN 23 + +#define RELOAD_BIN "reload_bin" +#define RELOAD_BIN_ARGS " addr [size]" +#define RELOAD_BIN_DESC "reload and reanalyze the Java class file starting at address" +#define RELOAD_BIN_LEN 10 + +#define SUMMARY_INFO "summary" +#define SUMMARY_INFO_ARGS "" +#define SUMMARY_INFO_DESC "print summary information for the current java class file" +#define SUMMARY_INFO_LEN 7 + +#define LIST_CODE_REFS "lcr" +#define LIST_CODE_REFS_ARGS " [addr]" +#define LIST_CODE_REFS_DESC "list all references to fields and methods in code sections" +#define LIST_CODE_REFS_LEN 3 + +#define PRINT_EXC "exc" +#define PRINT_EXC_ARGS " []" +#define PRINT_EXC_DESC "list all exceptions to fields and methods in code sections" +#define PRINT_EXC_LEN 3 + +#define YARA_CODE_REFS "yc_w_refs" +#define YARA_CODE_REFS_ARGS " [name] [start] [count]" +#define YARA_CODE_REFS_DESC "yara code bytes extraction with a name starting at to " +#define YARA_CODE_REFS_LEN 9 + +#define INSERT_MREF "i_mref" +#define INSERT_MREF_ARGS " C M S" // " //descriptor in form of (Lpref;)Lref;" +#define INSERT_MREF_DESC "add Method to Class with given method signature" //append a method reference CP object to the end of the CP object array (creates all requisite objects)" +#define INSERT_MREF_LEN 6 + +static RzCmdJavaCmd JAVA_CMDS[] = { + { HELP, HELP_ARGS, HELP_DESC, HELP_LEN, rz_cmd_java_handle_help }, + { SET_ACC_FLAGS, SET_ACC_FLAGS_ARGS, SET_ACC_FLAGS_DESC, SET_ACC_FLAGS_LEN, rz_cmd_java_handle_set_flags }, + { PROTOTYPES, PROTOTYPES_ARGS, PROTOTYPES_DESC, PROTOTYPES_LEN, rz_cmd_java_handle_prototypes }, + { RESOLVE_CP, RESOLVE_CP_ARGS, RESOLVE_CP_DESC, RESOLVE_CP_LEN, rz_cmd_java_handle_resolve_cp }, + { CALC_FLAGS, CALC_FLAGS_ARGS, CALC_FLAGS_DESC, CALC_FLAGS_LEN, rz_cmd_java_handle_calc_flags }, + { FLAGS_STR_AT, FLAGS_STR_AT_ARGS, FLAGS_STR_AT_DESC, FLAGS_STR_AT_LEN, rz_cmd_java_handle_flags_str_at }, + { FLAGS_STR, FLAGS_STR_ARGS, FLAGS_STR_DESC, FLAGS_STR_LEN, rz_cmd_java_handle_flags_str }, + { METHOD_INFO, METHOD_INFO_ARGS, METHOD_INFO_DESC, METHOD_INFO_LEN, rz_cmd_java_handle_method_info }, + { FIELD_INFO, FIELD_INFO_ARGS, FIELD_INFO_DESC, FIELD_INFO_LEN, rz_cmd_java_handle_field_info }, + { FIND_CP_CONST, FIND_CP_CONST_ARGS, FIND_CP_CONST_DESC, FIND_CP_CONST_LEN, rz_cmd_java_handle_find_cp_const }, + { FIND_CP_VALUE, FIND_CP_VALUE_ARGS, FIND_CP_VALUE_DESC, FIND_CP_VALUE_LEN, cpfind }, + { REPLACE_CP_VALUE, REPLACE_CP_VALUE_ARGS, REPLACE_CP_VALUE_DESC, REPLACE_CP_VALUE_LEN, rz_cmd_java_handle_replace_cp_value }, + { REPLACE_CLASS_NAME, REPLACE_CLASS_NAME_ARGS, REPLACE_CLASS_NAME_DESC, REPLACE_CLASS_NAME_LEN, rz_cmd_java_handle_replace_classname_value }, + { RELOAD_BIN, RELOAD_BIN_ARGS, RELOAD_BIN_DESC, RELOAD_BIN_LEN, rz_cmd_java_handle_reload_bin }, + { SUMMARY_INFO, SUMMARY_INFO_ARGS, SUMMARY_INFO_DESC, SUMMARY_INFO_LEN, rz_cmd_java_handle_summary_info }, + { PRINT_EXC, PRINT_EXC_ARGS, PRINT_EXC_DESC, PRINT_EXC_LEN, rz_cmd_java_handle_print_exceptions }, + { YARA_CODE_REFS, YARA_CODE_REFS_ARGS, YARA_CODE_REFS_DESC, YARA_CODE_REFS_LEN, rz_cmd_java_handle_yara_code_extraction_refs }, + { INSERT_MREF, INSERT_MREF_ARGS, INSERT_MREF_DESC, INSERT_MREF_LEN, rz_cmd_java_handle_insert_method_ref }, + { CALC_SZ, CALC_SZ_ARGS, CALC_SZ_DESC, CALC_SZ_LEN, rz_cmd_java_handle_calc_class_sz }, + { ISVALID, ISVALID_ARGS, ISVALID_DESC, ISVALID_LEN, rz_cmd_java_handle_isvalid }, +}; + +enum { + HELP_IDX = 0, + SET_ACC_FLAGS_IDX = 1, + PROTOTYPES_IDX = 2, + RESOLVE_CP_IDX = 3, + CALC_FLAGS_IDX = 4, + FLAGS_STR_AT_IDX = 5, + FLAGS_STR_IDX = 6, + METHOD_INFO_IDX = 7, + FIELD_INFO_IDX = 8, + FIND_CP_CONST_IDX = 9, + FIND_CP_VALUE_IDX = 10, + REPLACE_CP_VALUE_IDX = 11, + REPLACE_CLASS_NAME_IDX = 12, + RELOAD_BIN_IDX = 13, + SUMMARY_INFO_IDX = 14, + LIST_CODE_REFS_IDX = 15, + PRINT_EXC_IDX = 16, + YARA_CODE_REFS_IDX = 17, + INSERT_MREF_IDX = 18, + CALC_SZ_IDX = 19, + ISVALID_IDX = 20, + END_CMDS = 21, +}; + +static ut8 _(rz_cmd_java_obj_ref)(const char *name, const char *class_name, ut32 len) { + if (!name || !class_name) { + return false; + } + if (strncmp (class_name, name, len)) { + return false; + } + if (*(name - 1) == 'L' && *(name + len) == ';') { + return true; + } + if (!strncmp (class_name, name, len) && !*(name + len)) { + return true; + } + return false; +} + +static const char *rz_cmd_get_next_classname_str(const char *str, const char *match_me) { + const char *result = NULL; + ut32 len = match_me && *match_me? strlen (match_me): 0; + if (len && str && *str) { + result = str; + while (result && *result && (result - str < len)) { + result = strstr (result, match_me); + if (result) { + break; + } + } + } + return result; +} + +static ut32 rz_cmd_get_num_classname_str_occ(const char *str, const char *match_me) { + const char *result = NULL; + ut32 len = match_me && *match_me? strlen (match_me): 0; + ut32 occ = 0; + + if (len == 0 || !str || !*str) { + return 0; + } + result = str; + while (result && *result && (result - str < len)) { + result = strstr (result, match_me); + if (result) { + IFDBG eprintf ("result: %s\n", result); + result += len; + occ++; + } + } + return occ; +} + +static const char *rz_cmd_java_consumetok(const char *str1, const char b, size_t len) { + const char *p = str1; + size_t i = 0; + if (!p) { + return p; + } + if (len == (size_t)-1) { + len = strlen (str1); + } + for (; i < len; i++, p++) { + if (*p != b) { + break; + } + } + return p; +} + +static const char *rz_cmd_java_strtok(const char *str1, const char b, size_t len) { + const char *p = str1; + size_t i = 0; + if (!p || !*p) { + return p; + } + if (len == (size_t)-1) { + len = strlen (str1); + } + IFDBG rz_cons_printf ("Looking for char (%c) in (%s) up to %d\n", b, p, len); + for (; i < len; i++, p++) { + if (*p == b) { + IFDBG rz_cons_printf ("Found? for char (%c) @ %d: (%s)\n", b, i, p); + break; + } + } + if (i == len) { + p = NULL; + } + IFDBG rz_cons_printf ("Found? for char (%c) @ %d: (%s)\n", b, len, p); + return p; +} + +static RzAnal *get_anal(RzCore *core) { + return core? core->anal: NULL; +} + +static void rz_cmd_java_print_cmd_help(RzCmdJavaCmd *cmd) { + eprintf ("[*] %s %s\n[+] %s\n\n", cmd->name, cmd->args, cmd->desc); +} + +static int rz_cmd_java_handle_help(RzCore *core, const char *input) { + ut32 i = 0; + const char **help_msg = (const char **)malloc (sizeof (char *) * END_CMDS * 4); + help_msg[0] = "Usage:"; + help_msg[1] = "java [cmd] [arg..] "; + help_msg[2] = rz_core_plugin_java.desc; + for (i = 0; i < END_CMDS; i++) { + RzCmdJavaCmd *cmd = &JAVA_CMDS[i]; + help_msg[3 + (i * 3) + 0] = cmd->name; + help_msg[3 + (i * 3) + 1] = cmd->args; + help_msg[3 + (i * 3) + 2] = cmd->desc; + } + help_msg[3 + (i * 3)] = NULL; + rz_core_cmd_help (core, help_msg); + free (help_msg); + return true; +} + +static int rz_cmd_java_handle_prototypes(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } + + switch (*(cmd)) { + case 'm': return rz_cmd_java_print_method_definitions (obj); + case 'f': return rz_cmd_java_print_field_definitions (obj); + case 'i': return rz_cmd_java_print_import_definitions (obj); + case 'c': return rz_cmd_java_print_class_definitions (obj); + case 'a': return rz_cmd_java_print_all_definitions (anal); + case 'j': return rz_cmd_java_print_json_definitions (obj); + } + return false; +} + +static int rz_cmd_java_handle_summary_info(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } + + rz_cons_printf ("Summary for %s:\n", obj->file); + rz_cons_printf (" Size 0x%" PFMT64x ":\n", obj->size); + rz_cons_printf (" Constants size: 0x%" PFMT64x " count: %d:\n", obj->cp_size, obj->cp_count); + rz_cons_printf (" Methods size: 0x%" PFMT64x " count: %d:\n", obj->methods_size, obj->methods_count); + rz_cons_printf (" Fields size: 0x%" PFMT64x " count: %d:\n", obj->fields_size, obj->fields_count); + rz_cons_printf (" Attributes size: 0x%" PFMT64x " count: %d:\n", obj->attrs_size, obj->attrs_count); + rz_cons_printf (" Interfaces size: 0x%" PFMT64x " count: %d:\n", obj->interfaces_size, obj->interfaces_count); + + return true; +} + +static int _(rz_cmd_java_check_op_idx)(const ut8 *op_bytes, ut16 idx) { + return R_BIN_JAVA_USHORT (op_bytes, 0) == idx; +} + +/* Find stuff in the constant pool */ +static RzList *cpfind_double(RBinJavaObj *obj, const char *cmd) { + double value = cmd && *cmd? strtod (cmd, NULL): 0.0; + if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) { + return rz_list_new (); + } + return rz_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 8, R_BIN_JAVA_CP_DOUBLE); +} + +static RzList *cpfind_float(RBinJavaObj *obj, const char *cmd) { + float value = cmd && *cmd? atof (cmd): 0.0; + if (value == 0.0 && !(cmd && cmd[0] == '0' && cmd[1] == '.' && cmd[2] == '0')) { + return rz_list_new (); + } + return rz_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 4, R_BIN_JAVA_CP_FLOAT); +} + +static RzList *cpfind_long(RzCore *core, RBinJavaObj *obj, const char *cmd) { + ut64 value = rz_cmd_java_get_input_num_value (core, cmd); + if (!rz_cmd_java_is_valid_input_num_value (core, cmd)) { + return rz_list_new (); + } + return rz_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 8, R_BIN_JAVA_CP_LONG); +} + +static RzList *cpfind_int(RzCore *core, RBinJavaObj *obj, const char *cmd) { + ut32 value = (ut32)rz_cmd_java_get_input_num_value (core, cmd); + if (!rz_cmd_java_is_valid_input_num_value (core, cmd)) { + return rz_list_new (); + } + return rz_bin_java_find_cp_const_by_val (obj, (const ut8 *)&value, 4, R_BIN_JAVA_CP_INTEGER); +} + +static RzList *cpfind_str(RBinJavaObj *obj, const char *cmd) { + if (!cmd) { + return rz_list_new (); + } + IFDBG rz_cons_printf ("Looking for str: %s (%d)\n", cmd, strlen (cmd)); + return rz_bin_java_find_cp_const_by_val (obj, (const ut8 *)cmd, strlen (cmd), R_BIN_JAVA_CP_UTF8); +} + +static int cpfind(RzCore *core, const char *cmd) { + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (get_anal (core)); + const char *p = cmd; + char f_type = 0; + RzList *find_list = NULL; + RzListIter *iter; + ut32 *idx; + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } + IFDBG rz_cons_printf ("Function call made: %s\n", p); + if (p && *p) { + p = rz_cmd_java_consumetok (cmd, ' ', -1); + f_type = *p; + p += 2; + } + IFDBG rz_cons_printf ("Function call made: %s\n", p); + switch (f_type) { + case 's': find_list = cpfind_str (obj, p); break; + case 'i': find_list = cpfind_int (core, obj, rz_cmd_java_consumetok (p, ' ', -1)); break; + case 'l': find_list = cpfind_long (core, obj, rz_cmd_java_consumetok (p, ' ', -1)); break; + case 'f': find_list = cpfind_float (obj, rz_cmd_java_consumetok (p, ' ', -1)); break; + case 'd': find_list = cpfind_double (obj, rz_cmd_java_consumetok (p, ' ', -1)); break; + default: + eprintf ("[-] rz_cmd_java: invalid java type to search for.\n"); + return true; + } + + rz_list_foreach (find_list, iter, idx) { + ut64 addr = rz_bin_java_resolve_cp_idx_address (obj, (ut16)*idx); + rz_cons_printf ("Offset: 0x%" PFMT64x " idx: %d\n", addr, *idx); + } + rz_list_free (find_list); + return true; +} + +static int rz_cmd_java_reload_bin_from_buf(RzCore *core, RBinJavaObj *obj, ut8 *buffer, ut64 len) { + if (!buffer || len < 10) { + return false; + } + int res = rz_bin_java_load_bin (obj, buffer, len); + + if (res == true) { + //RBinPlugin *cp = NULL; + RBinPlugin *tmp; + RzListIter *iter; + rz_list_foreach (core->bin->plugins, iter, tmp) { + if (!strncmp ("java", tmp->name, 4)) { + //cp = tmp; + break; + } + } + // XXX - this API is no longer valid. + // need a function that will re-read bin bytes + // and parse the file + //if (cp) rz_bin_update_items (core->bin, cp); + } + return res; +} + +static int rz_cmd_java_get_cp_bytes_and_write(RzCore *core, RBinJavaObj *obj, ut16 idx, ut64 addr, const ut8 *buf, const ut64 len) { + int res = false; + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (obj, idx); + ut64 c_file_sz = rz_io_size (core->io); + ut32 n_sz = 0, c_sz = obj? rz_bin_java_cp_get_size (obj, idx): (ut32)-1; + ut8 *bytes = NULL; + + if (c_sz == (ut32)-1) { + return res; + } + + bytes = rz_bin_java_cp_get_bytes (cp_obj->tag, &n_sz, buf, len); + + if (n_sz < c_sz) { + res = rz_core_shift_block (core, addr + c_sz, 0, (int)n_sz - (int)c_sz) && + rz_io_resize (core->io, c_file_sz + (int)n_sz - (int)c_sz); + } else if (n_sz > c_sz) { + res = rz_core_extend_at (core, addr, (int)n_sz - (int)c_sz); + } else { + eprintf ("[X] rz_cmd_java_get_cp_bytes_and_write: Failed to resize the file correctly aborting.\n"); + return res; + } + + if (n_sz > 0 && bytes) { + res = rz_core_write_at (core, addr, (const ut8 *)bytes, n_sz) && rz_core_seek (core, addr, true); + } + + if (res == false) { + eprintf ("[X] rz_cmd_java_get_cp_bytes_and_write: Failed to write the bytes to the file correctly aborting.\n"); + return res; + } + + R_FREE (bytes); + + if (res == true) { + ut64 n_file_sz = 0; + ut8 *bin_buffer = NULL; + res = rz_io_use_fd (core->io, core->file->fd); + n_file_sz = rz_io_size (core->io); + bin_buffer = n_file_sz > 0? malloc (n_file_sz): NULL; + if (bin_buffer) { + memset (bin_buffer, 0, n_file_sz); + res = n_file_sz == rz_io_read_at (core->io, obj->loadaddr, bin_buffer, n_file_sz)? true: false; + if (res == true) { + res = rz_cmd_java_reload_bin_from_buf ( + core, obj, bin_buffer, n_file_sz); + } else { + eprintf ("[X] rz_cmd_java_get_cp_bytes_and_write: Failed to read the file in aborted, bin reload.\n"); + } + free (bin_buffer); + } + } + return res; +} + +static int rz_cmd_java_handle_replace_cp_value_float(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { + float value = cmd && *cmd? atof (cmd): 0.0; + int res = false; + res = rz_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 4); + return res; +} + +static int rz_cmd_java_handle_replace_cp_value_double(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { + double value = cmd && *cmd? strtod (cmd, NULL): 0.0; + int res = false; + res = rz_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 8); + return res; +} + +static int rz_cmd_java_handle_replace_cp_value_long(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { + ut64 value = rz_cmd_java_get_input_num_value (core, cmd); + int res = false; + res = rz_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 8); + return res; +} + +static int rz_cmd_java_handle_replace_cp_value_int(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { + ut32 value = (ut32)rz_cmd_java_get_input_num_value (core, cmd); + int res = false; + res = rz_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)&value, 4); + return res; +} + +static int rz_cmd_java_handle_replace_cp_value_str(RzCore *core, RBinJavaObj *obj, const char *cmd, ut16 idx, ut64 addr) { + int res = false; + ut32 len = cmd && *cmd? strlen (cmd): 0; + if (len > 0 && cmd && *cmd == '"') { + cmd++; + len = cmd && *cmd? strlen (cmd): 0; + } + if (cmd && len > 0) { + res = rz_cmd_java_get_cp_bytes_and_write (core, obj, idx, addr, (ut8 *)cmd, len); + } + return res; +} + +static int rz_cmd_java_handle_replace_cp_value(RzCore *core, const char *cmd) { + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (get_anal (core)); + ut16 idx = -1; + ut64 addr = 0; + const char *p = cmd; + char cp_type = 0; + IFDBG rz_cons_printf ("Function call made: %s\n", p); + if (p && *p) { + p = rz_cmd_java_consumetok (cmd, ' ', -1); + if (rz_cmd_java_is_valid_input_num_value (core, p)) { + idx = rz_cmd_java_get_input_num_value (core, p); + p = rz_cmd_java_strtok (p, ' ', strlen (p)); + } + } + if (idx == (ut16)-1) { + eprintf ("[-] rz_cmd_java: Invalid index value.\n"); + } else if (!obj) { + eprintf ("[-] rz_cmd_java: The current binary is not a Java Bin Object.\n"); + } else if (!p || (p && !*p)) { + rz_cmd_java_print_cmd_help (JAVA_CMDS + REPLACE_CP_VALUE_IDX); + return true; + } else { + cp_type = rz_bin_java_resolve_cp_idx_tag (obj, idx); + addr = rz_bin_java_resolve_cp_idx_address (obj, idx); + IFDBG rz_cons_printf ("Function call made: %s\n", p); + switch (cp_type) { + case R_BIN_JAVA_CP_UTF8: return rz_cmd_java_handle_replace_cp_value_str ( + core, obj, rz_cmd_java_consumetok (p, ' ', -1), idx, addr); + case R_BIN_JAVA_CP_INTEGER: return rz_cmd_java_handle_replace_cp_value_int ( + core, obj, rz_cmd_java_consumetok (p, ' ', -1), idx, addr); + case R_BIN_JAVA_CP_LONG: return rz_cmd_java_handle_replace_cp_value_long ( + core, obj, rz_cmd_java_consumetok (p, ' ', -1), idx, addr); + case R_BIN_JAVA_CP_FLOAT: return rz_cmd_java_handle_replace_cp_value_float ( + core, obj, rz_cmd_java_consumetok (p, ' ', -1), idx, addr); + case R_BIN_JAVA_CP_DOUBLE: return rz_cmd_java_handle_replace_cp_value_double ( + core, obj, rz_cmd_java_consumetok (p, ' ', -1), idx, addr); + default: + eprintf ("[-] rz_cmd_java: invalid java type to search for.\n"); + return false; + } + return true; + } + return false; +} + +static char *rz_cmd_replace_name_def(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len) { + const char *fmt = "L%s;"; + char *s_new_ref = s_new && replace_len > 0? malloc (3 + replace_len): NULL; + char *s_old_ref = s_old && match_len > 0? malloc (3 + match_len): NULL; + char *result = NULL; + *res_len = 0; + if (s_new_ref && s_old_ref) { + snprintf (s_new_ref, replace_len + 3, fmt, s_new); + snprintf (s_old_ref, match_len + 3, fmt, s_old); + result = rz_cmd_replace_name (s_new_ref, replace_len + 2, s_old_ref, match_len + 2, buffer, buf_len, res_len); + } + free (s_new_ref); + free (s_old_ref); + return result; +} + +static int rz_cmd_is_object_descriptor(const char *name, ut32 name_len) { + int found_L = false, found_Semi = false; + ut32 idx = 0, L_pos = 0, Semi_pos = 0; + const char *p_name = name; + + for (idx = 0, L_pos = 0; idx < name_len; idx++, p_name++) { + if (*p_name == 'L') { + found_L = true; + L_pos = idx; + break; + } + } + + for (idx = 0, Semi_pos = 0; idx < name_len; idx++, p_name++) { + if (*p_name == ';') { + found_Semi = true; + Semi_pos = idx; + break; + } + } + + return true? found_L == found_Semi && found_L == true && L_pos < Semi_pos: false; +} + +static char *rz_cmd_replace_name(const char *s_new, ut32 replace_len, const char *s_old, ut32 match_len, const char *buffer, ut32 buf_len, ut32 *res_len) { + ut32 num_occurrences = 0, i = 0; + char *result = NULL, *p_result = NULL; + + num_occurrences = rz_cmd_get_num_classname_str_occ (buffer, s_old); + *res_len = 0; + if (num_occurrences > 0 && replace_len > 0 && s_old) { + ut32 consumed = 0; + const char *next = rz_cmd_get_next_classname_str (buffer + consumed, s_old); + IFDBG rz_cons_printf ("Replacing \"%s\" with \"%s\" in: %s\n", s_old, s_new, buffer); + result = malloc (num_occurrences * replace_len + buf_len); + memset (result, 0, num_occurrences * replace_len + buf_len); + p_result = result; + while (next && consumed < buf_len) { + // replace up to next + IFDBG rz_cons_printf ("next: \"%s\", len to: %d\n", next, next - buffer); + for (; buffer + consumed < next && consumed < buf_len; consumed++, p_result++) { + *p_result = *(buffer + consumed); + (*res_len)++; + } + + for (i = 0; i < replace_len; i++, p_result++) { + *p_result = *(s_new + i); + (*res_len)++; + } + consumed += match_len; + next = rz_cmd_get_next_classname_str (buffer + consumed, s_old); + } + IFDBG rz_cons_printf ("Found last occurrence of: \"%s\", remaining: %s\n", s_old, buffer + consumed); + IFDBG rz_cons_printf ("result is: \"%s\"\n", result); + for (; consumed < buf_len; consumed++, p_result++, (*res_len)++) { + *p_result = *(buffer + consumed); + } + IFDBG rz_cons_printf ("Old: %s\nNew: %s\n", buffer, result); + } + return result; +} + +static int rz_cmd_java_get_class_names_from_input(const char *input, char **class_name, ut32 *class_name_len, char **new_class_name, ut32 *new_class_name_len) { + const char *p = input; + + ut32 cmd_sz = input && *input? strlen (input): 0; + int res = false; + + if (!class_name || *class_name) { + return res; + } else if (!new_class_name || *new_class_name) { + return res; + } else if (!new_class_name_len || !class_name_len) { + return res; + } + + *new_class_name = NULL; + *class_name_len = 0; + + if (p && *p && cmd_sz > 1) { + const char *end; + p = rz_cmd_java_consumetok (p, ' ', cmd_sz); + end = p && *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + + if (p && end && p != end) { + *class_name_len = end - p + 1; + *class_name = malloc (*class_name_len); + snprintf (*class_name, *class_name_len, "%s", p); + cmd_sz = *class_name_len - 1 < cmd_sz? cmd_sz - *class_name_len: 0; + } + + if (*class_name && cmd_sz > 0) { + p = rz_cmd_java_consumetok (end + 1, ' ', cmd_sz); + end = p && *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + + if (!end && p && *p) { + end = p + cmd_sz; + } + + if (p && end && p != end) { + *new_class_name_len = end - p + 1; + *new_class_name = malloc (*new_class_name_len); + snprintf (*new_class_name, *new_class_name_len, "%s", p); + res = true; + } + } + } + return res; +} + +static int rz_cmd_java_handle_replace_classname_value(RzCore *core, const char *cmd) { + RBinJavaObj *obj; + char *class_name = NULL, *new_class_name = NULL; + ut32 class_name_len = 0, new_class_name_len = 0; + RzAnal *anal = get_anal (core); + const char *p = cmd; + int res = false; + ut32 idx = -1; + + if (!core || !anal || !cmd) { + return false; + } + IFDBG rz_cons_printf ("Function call made: %s\n", p); + obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + if (!obj) { + eprintf ("The current binary is not a Java Bin Object.\n"); + return true; + } + res = rz_cmd_java_get_class_names_from_input (cmd, &class_name, + &class_name_len, &new_class_name, &new_class_name_len); + + if (!res || !class_name || !new_class_name) { + rz_cmd_java_print_cmd_help (JAVA_CMDS + REPLACE_CLASS_NAME_IDX); + free (class_name); + free (new_class_name); + return true; + } + for (idx = 1; idx <= obj->cp_count; idx++) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (obj, idx); + char *name = NULL; + ut8 *buffer = NULL; + ut32 buffer_sz = 0; + ut16 len = 0; + if (cp_obj && cp_obj->tag == R_BIN_JAVA_CP_UTF8 && + cp_obj->info.cp_utf8.length && cp_obj->info.cp_utf8.length >= class_name_len - 1) { + ut32 num_occurrences = 0; + ut64 addr = cp_obj->file_offset + cp_obj->loadaddr; + buffer = rz_bin_java_cp_get_idx_bytes (obj, idx, &buffer_sz); + + if (!buffer) { + continue; + } + len = R_BIN_JAVA_USHORT (buffer, 1); + name = malloc (len + 3); + memcpy (name, buffer + 3, len); + name[len] = 0; + + num_occurrences = rz_cmd_get_num_classname_str_occ (name, class_name); + + if (num_occurrences > 0) { + // perform inplace replacement + ut32 res_len = 0; + char *result = NULL; + + if (rz_cmd_is_object_descriptor (name, len) == true) { + result = rz_cmd_replace_name_def (new_class_name, + new_class_name_len - 1, class_name, + class_name_len - 1, name, len, &res_len); + } else { + result = rz_cmd_replace_name (new_class_name, + new_class_name_len - 1, class_name, + class_name_len - 1, name, len, &res_len); + } + if (result) { + res = rz_cmd_java_get_cp_bytes_and_write ( + core, obj, idx, addr, + (const ut8 *)result, res_len); + if (res == false) { + eprintf ("ERROR: rz_cmd_java: Failed to write bytes or reload the binary.\n"); + } + } + free (result); + } + free (buffer); + free (name); + } + } + free (class_name); + free (new_class_name); + return true; +} + +static int rz_cmd_java_handle_reload_bin(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + const char *p = cmd; + ut64 addr = 0LL; //cur_offset = core->offset, addr = 0; + ut64 buf_size = 0; + ut8 *buf = NULL; + int res = false; + + if (*cmd == ' ') { + p = rz_cmd_java_consumetok (p, ' ', -1); + } + if (!*cmd) { + rz_cmd_java_print_cmd_help (JAVA_CMDS + RELOAD_BIN_IDX); + return true; + } + + addr = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut32)-1; + if (*cmd == ' ') { + p = rz_cmd_java_consumetok (p, ' ', -1); + } + buf_size = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut32)-1; + + // XXX this may cause problems cause the file we are looking at may not be the bin we want. + // lets pretend it is for now + if (buf_size == 0) { + res = rz_io_use_fd (core->io, core->file->fd); + buf_size = rz_io_size (core->io); + buf = malloc (buf_size); + memset (buf, 0, buf_size); + rz_io_read_at (core->io, addr, buf, buf_size); + } + if (buf && obj) { + res = rz_cmd_java_reload_bin_from_buf (core, obj, buf, buf_size); + } + free (buf); + return res; +} + +static int rz_cmd_java_handle_find_cp_const(RzCore *core, const char *cmd) { + const char *p = (cmd && *cmd == ' ')? rz_cmd_java_consumetok (cmd, ' ', -1): NULL; + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (get_anal (core)); + RzAnalFunction *fcn = NULL; + RzAnalBlock *bb = NULL; + RzListIter *bb_iter, *fn_iter, *iter; + RzCmdJavaCPResult *cp_res = NULL; + ut16 idx = -1; + RzList *find_list; + + if (p && *p == 'a') { + idx = -1; + } else { + idx = rz_cmd_java_get_input_num_value (core, p); + } + + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } + if (!cmd || !*cmd) { + eprintf ("[-] rz_cmd_java: invalid command syntax.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + FIND_CP_CONST_IDX); + return true; + } + if (idx == 0) { + eprintf ("[-] rz_cmd_java: invalid CP Obj Index Supplied.\n"); + return true; + } + find_list = rz_list_new (); + find_list->free = free; + // XXX - this will break once RzAnal moves to sdb + rz_list_foreach (core->anal->fcns, fn_iter, fcn) { + rz_list_foreach (fcn->bbs, bb_iter, bb) { + char op = bb->op_bytes[0]; + cp_res = NULL; + switch (op) { + case 0x12: + cp_res = (idx == (ut16)-1) || (bb->op_bytes[1] == idx)? R_NEW0 (RzCmdJavaCPResult): NULL; + if (cp_res) { + cp_res->idx = bb->op_bytes[1]; + } + break; + case 0x13: + case 0x14: + cp_res = (idx == (ut16)-1) || (R_BIN_JAVA_USHORT (bb->op_bytes, 1) == idx)? R_NEW0 (RzCmdJavaCPResult): NULL; + if (cp_res) { + cp_res->idx = R_BIN_JAVA_USHORT (bb->op_bytes, 1); + } + break; + } + if (cp_res) { + cp_res->addr = bb->addr; + cp_res->obj = rz_bin_java_get_item_from_cp (obj, cp_res->idx); + rz_list_append (find_list, cp_res); + } + } + } + if (idx == (ut16)-1) { + rz_list_foreach (find_list, iter, cp_res) { + const char *t = ((RBinJavaCPTypeMetas *)cp_res->obj->metas->type_info)->name; + rz_cons_printf ("@0x%" PFMT64x " idx = %d Type = %s\n", cp_res->addr, cp_res->idx, t); + } + + } else { + rz_list_foreach (find_list, iter, cp_res) { + rz_cons_printf ("@0x%" PFMT64x "\n", cp_res->addr); + } + } + rz_list_free (find_list); + return true; +} + +static int rz_cmd_java_handle_field_info(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + ut16 idx = -1; + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } else if (!cmd || !*cmd) { + eprintf ("[-] rz_cmd_java: invalid command syntax.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + FIELD_INFO_IDX); + return true; + } + + if (*(cmd) == 's' || *(cmd) == 'n') { + idx = rz_cmd_java_get_input_num_value (core, cmd + 1); + } + + switch (*(cmd)) { + case 'c': return rz_cmd_java_print_field_num_name (obj); + case 's': return rz_cmd_java_print_field_summary (obj, idx); + case 'n': return rz_cmd_java_print_field_name (obj, idx); + } + IFDBG rz_cons_printf ("Command is (%s)\n", cmd); + eprintf ("[-] rz_cmd_java: invalid command syntax.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + FIELD_INFO_IDX); + return false; +} + +static int rz_cmd_java_handle_method_info(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + RBinJavaObj *obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + IFDBG rz_cons_printf ("Command is (%s)\n", cmd); + ut16 idx = -1; + + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + return true; + } else if (!cmd || !*cmd) { + eprintf ("[-] rz_cmd_java: invalid command syntax.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + METHOD_INFO_IDX); + return false; + } + + if (*(cmd) == 's' || *(cmd) == 'n') { + idx = rz_cmd_java_get_input_num_value (core, cmd + 1); + } + + switch (*(cmd)) { + case 'c': return rz_cmd_java_print_method_num_name (obj); + case 's': return rz_cmd_java_print_method_summary (obj, idx); + case 'n': return rz_cmd_java_print_method_name (obj, idx); + } + + IFDBG rz_cons_printf ("Command is (%s)\n", cmd); + eprintf ("[-] rz_cmd_java: invalid command syntax.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + METHOD_INFO_IDX); + return false; +} + +static int rz_cmd_java_handle_calc_class_sz(RzCore *core, const char *cmd) { + int res = false; + ut64 sz = UT64_MAX; + ut64 addr = UT64_MAX; + ut64 res_size = UT64_MAX, + cur_fsz = rz_io_fd_size (core->io, rz_core_file_cur (core)->fd); + ut8 *tbuf, *buf = NULL; + ut32 init_size = (1 << 16); + const char *p = cmd? rz_cmd_java_consumetok (cmd, ' ', -1): NULL; + addr = p && *p && rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): UT64_MAX; + + // TODO add a size parameter to the command to skip the guessing part. + + if (addr != UT64_MAX && sz == UT64_MAX) { + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + IFDBG rz_cons_printf ("Attempting to calculate class file size @ : 0x%" PFMT64x ".\n", addr); + sz = cur_fsz < init_size? cur_fsz: init_size; + while (sz <= cur_fsz) { + tbuf = realloc (buf, sz); + if (!tbuf) { + eprintf ("Memory allocation failed.\n"); + free (buf); + break; + } + buf = tbuf; + ut64 rz_sz = rz_io_read_at (core->io, addr, buf, sz)? sz: 0LL; + // check the return read on the read + if (rz_sz == 0) { + break; + } + res_size = rz_bin_java_calc_class_size (buf, sz); + // if the data buffer contains a class starting + // at address, then the res_size will be the size + // if the rz_sz is less than the sz, then we are near + // the end of the core buffer, and there is no need + // to continue trying to find the class size. + if (res_size != UT64_MAX || + rz_sz < sz) { + res = rz_sz < sz? false: true; + free (buf); + break; + } else { + sz += (1 << 16); + } + } + if (res) { + rz_cons_printf ("%" PFMT64d, res_size); + } else { + rz_cons_printf ("-1\n"); + } + + //snprintf (cmd_buf, 50, fmt, num_acc_flag, addr); + //res = rz_core_cmd0(core, y); + } else { + rz_cmd_java_print_cmd_help (JAVA_CMDS + CALC_SZ_IDX); + } + return true; +} + +static int rz_cmd_java_handle_isvalid(RzCore *core, const char *cmd) { + int res = false; + ut64 res_size = UT64_MAX; + ut8 *tbuf, *buf = NULL; + ut32 cur_fsz = rz_io_fd_size (core->io, rz_core_file_cur (core)->fd); + ut64 sz = UT64_MAX; + const char *p = cmd? rz_cmd_java_consumetok (cmd, ' ', -1): NULL; + ut64 addr = UT64_MAX; + addr = p && *p && rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): UT64_MAX; + + // TODO add a size parameter to the command to skip the guessing part. + + if (addr != UT64_MAX && sz == UT64_MAX) { + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + IFDBG rz_cons_printf ("Attempting to calculate class file size @ : 0x%" PFMT64x ".\n", addr); + + while (sz <= cur_fsz) { + tbuf = realloc (buf, sz); + if (!tbuf) { + eprintf ("Memory allocation failed.\n"); + free (buf); + break; + } + buf = tbuf; + ut64 rz_sz = rz_io_read_at (core->io, addr, buf, sz)? sz: 0LL; + // check the return read on the read + if (rz_sz == 0) { + break; + } + res_size = rz_bin_java_calc_class_size (buf, sz); + // if the data buffer contains a class starting + // at address, then the res_size will be the size + // if the rz_sz is less than the sz, then we are near + // the end of the core buffer, and there is no need + // to continue trying to find the class size. + if (res_size != UT64_MAX || + rz_sz < sz) { + res = rz_sz < sz? false: true; + free (buf); + break; + } else { + sz <<= 1; + } + } + rz_cons_printf ("%s\n", rz_str_bool (res)); + } else { + rz_cmd_java_print_cmd_help (JAVA_CMDS + ISVALID_IDX); + } + return true; +} + +static int rz_cmd_java_handle_resolve_cp(RzCore *core, const char *cmd) { + RzAnal *anal = get_anal (core); + char c_type = cmd && *cmd? *cmd: 0; + RBinJavaObj *obj = rz_cmd_java_get_bin_obj (anal); + ut32 idx = rz_cmd_java_get_input_num_value (core, cmd + 2); + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + IFDBG rz_cons_printf ("Ctype: %d (%c) RBinJavaObj points to: %p and the idx is (%s): %d\n", c_type, c_type, obj, cmd + 2, idx); + int res = false; + if (idx > 0 && obj) { + switch (c_type) { + case 't': return rz_cmd_java_resolve_cp_type (obj, idx); + case 'c': return rz_cmd_java_resolve_cp_idx (obj, idx); + case 'e': return rz_cmd_java_resolve_cp_idx_b64 (obj, idx); + case 'a': return rz_cmd_java_resolve_cp_address (obj, idx); + case 's': return rz_cmd_java_resolve_cp_summary (obj, idx); + case 'k': return rz_cmd_java_resolve_cp_to_key (obj, idx); + } + } else if (obj && c_type == 'g') { + for (idx = 1; idx <= obj->cp_count; idx++) { + ut64 addr = rz_bin_java_resolve_cp_idx_address (obj, idx); + char *str = rz_bin_java_resolve_cp_idx_type (obj, idx); + rz_cons_printf ("CP_OBJ Type %d = %s @ 0x%" PFMT64x "\n", idx, str, addr); + free (str); + } + res = true; + } else if (obj && c_type == 'd') { + for (idx = 1; idx <= obj->cp_count; idx++) { + rz_cmd_java_resolve_cp_summary (obj, idx); + } + res = true; + } else { + if (!obj) { + eprintf ("[-] rz_cmd_java: no valid java bins found.\n"); + } else { + eprintf ("[-] rz_cmd_java: invalid cp index given, must idx > 1.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + RESOLVE_CP_IDX); + } + res = true; + } + return res; +} + +static int rz_cmd_java_get_all_access_flags_value(const char *cmd) { + RzList *the_list = NULL; + RzListIter *iter = NULL; + char *str = NULL; + + switch (*(cmd)) { + case 'f': the_list = retrieve_all_field_access_string_and_value (); break; + case 'm': the_list = retrieve_all_method_access_string_and_value (); break; + case 'c': the_list = retrieve_all_class_access_string_and_value (); break; + } + if (!the_list) { + eprintf ("[-] rz_cmd_java: incorrect syntax for the flags calculation.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + CALC_FLAGS_IDX); + return false; + } + switch (*(cmd)) { + case 'f': rz_cons_printf ("[=] Fields Access Flags List\n"); break; + case 'm': rz_cons_printf ("[=] Methods Access Flags List\n"); break; + case 'c': + rz_cons_printf ("[=] Class Access Flags List\n"); + ; + break; + } + + rz_list_foreach (the_list, iter, str) { + rz_cons_println (str); + } + rz_list_free (the_list); + return true; +} + +static int rz_cmd_java_handle_calc_flags(RzCore *core, const char *cmd) { + IFDBG rz_cons_printf ("Function call made: %s\n", cmd); + int res = false; + + switch (*(cmd)) { + case 'f': return rz_cmd_java_print_field_access_flags_value (cmd + 2); + case 'm': return rz_cmd_java_print_method_access_flags_value (cmd + 2); + case 'c': return rz_cmd_java_print_class_access_flags_value (cmd + 2); + } + + if (*(cmd) == 'l') { + const char *lcmd = *cmd + 1 == ' '? cmd + 2: cmd + 1; + IFDBG eprintf ("Seeing %s and accepting %s\n", cmd, lcmd); + switch (*(lcmd)) { + case 'f': + case 'm': + case 'c': res = rz_cmd_java_get_all_access_flags_value (lcmd); break; + } + // Just print them all out + if (res == false) { + rz_cmd_java_get_all_access_flags_value ("c"); + rz_cmd_java_get_all_access_flags_value ("m"); + res = rz_cmd_java_get_all_access_flags_value ("f"); + } + } + if (res == false) { + eprintf ("[-] rz_cmd_java: incorrect syntax for the flags calculation.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + CALC_FLAGS_IDX); + res = true; + } + return res; +} + +static int rz_cmd_java_handle_flags_str(RzCore *core, const char *cmd) { + + int res = false; + ut32 flag_value = -1; + const char f_type = cmd? *cmd: 0; + const char *p = cmd? cmd + 2: NULL; + char *flags_str = NULL; + + IFDBG rz_cons_printf ("rz_cmd_java_handle_flags_str: ftype = %c, idx = %s\n", f_type, p); + if (p) { + flag_value = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut32)-1; + } + + if (p && f_type) { + switch (f_type) { + case 'm': flags_str = retrieve_method_access_string ((ut16)flag_value); break; + case 'f': flags_str = retrieve_field_access_string ((ut16)flag_value); break; + case 'c': flags_str = retrieve_class_method_access_string ((ut16)flag_value); break; + default: flags_str = NULL; + } + } + + if (flags_str) { + switch (f_type) { + case 'm': rz_cons_printf ("Method Access Flags String: "); break; + case 'f': rz_cons_printf ("Field Access Flags String: "); break; + case 'c': rz_cons_printf ("Class Access Flags String: "); break; + } + rz_cons_println (flags_str); + free (flags_str); + res = true; + } + if (res == false) { + eprintf ("[-] rz_cmd_java: incorrect syntax for the flags calculation.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + FLAGS_STR_IDX); + res = true; + } + return res; +} + +static int rz_cmd_java_handle_flags_str_at(RzCore *core, const char *cmd) { + + int res = false; + ut64 flag_value_addr = -1; + ut32 flag_value = -1; + const char f_type = cmd? *rz_cmd_java_consumetok (cmd, ' ', -1): 0; + const char *p = cmd? cmd + 2: NULL; + char *flags_str = NULL; + + IFDBG rz_cons_printf ("rz_cmd_java_handle_flags_str_at: ftype = 0x%02x, idx = %s\n", f_type, p); + if (p) { + flag_value = 0; + ut64 cur_offset = core->offset; + flag_value_addr = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut32)-1; + rz_io_read_at (core->io, flag_value_addr, (ut8 *)&flag_value, 2); + IFDBG rz_cons_printf ("rz_cmd_java_handle_flags_str_at: read = 0x%04x\n", flag_value); + if (cur_offset != core->offset) { + rz_core_seek (core, cur_offset - 2, true); + } + flag_value = R_BIN_JAVA_USHORT (((ut8 *)&flag_value), 0); + } + + if (p && f_type) { + switch (f_type) { + case 'm': flags_str = retrieve_method_access_string ((ut16)flag_value); break; + case 'f': flags_str = retrieve_field_access_string ((ut16)flag_value); break; + case 'c': flags_str = retrieve_class_method_access_string ((ut16)flag_value); break; + default: flags_str = NULL; + } + } + + if (flags_str) { + switch (f_type) { + case 'm': rz_cons_printf ("Method Access Flags String: "); break; + case 'f': rz_cons_printf ("Field Access Flags String: "); break; + case 'c': rz_cons_printf ("Class Access Flags String: "); break; + } + rz_cons_println (flags_str); + free (flags_str); + res = true; + } + if (res == false) { + eprintf ("[-] rz_cmd_java: incorrect syntax for the flags calculation.\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + FLAGS_STR_IDX); + res = true; + } + return res; +} + +static char rz_cmd_java_is_valid_java_mcf(char b) { + char c = 0; + switch (b) { + case 'c': + case 'f': + case 'm': c = b; + } + return c; +} + +static int rz_cmd_java_handle_set_flags(RzCore *core, const char *input) { + //#define SET_ACC_FLAGS_ARGS "< c | m | f> >" + const char *p = rz_cmd_java_consumetok (input, ' ', -1); + ut64 addr = p && rz_cmd_java_is_valid_input_num_value (core, p) + ? rz_cmd_java_get_input_num_value (core, p) + : (ut64)-1; + p = rz_cmd_java_strtok (p + 1, ' ', -1); + if (!p || !*p) { + rz_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); + return true; + } + const char f_type = p && *p? rz_cmd_java_is_valid_java_mcf (*(++p)): '?'; + + int flag_value = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): -1; + + if (flag_value == 16 && f_type == 'f') { + flag_value = -1; + } + IFDBG rz_cons_printf ("Converting %s to flags\n", p); + + if (p) { + p += 2; + } + if (flag_value == -1) { + flag_value = rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): -1; + } + bool res = false; + if (!input) { + eprintf ("[-] rz_cmd_java: no address provided .\n"); + res = true; + } else if (addr == (ut64)-1) { + eprintf ("[-] rz_cmd_java: no address provided .\n"); + res = true; + } else if (f_type == '?' && flag_value == -1) { + eprintf ("[-] rz_cmd_java: no flag type provided .\n"); + res = true; + } + + if (res) { + rz_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); + return res; + } + + IFDBG rz_cons_printf ("Writing ftype '%c' to 0x%" PFMT64x ", %s.\n", f_type, addr, p); + + // handling string based access flags (otherwise skip ahead) + IFDBG rz_cons_printf ("Converting %s to flags\n", p); + if (f_type && flag_value != -1) { + switch (f_type) { + case 'f': flag_value = rz_bin_java_calculate_field_access_value (p); break; + case 'm': flag_value = rz_bin_java_calculate_method_access_value (p); break; + case 'c': flag_value = rz_bin_java_calculate_class_access_value (p); break; + default: flag_value = -1; + } + } + IFDBG rz_cons_printf ("Current args: (flag_value: 0x%04x addr: 0x%" PFMT64x ")\n.", flag_value, addr, res); + if (flag_value != -1) { + res = rz_cmd_java_set_acc_flags (core, addr, ((ut16)flag_value) & 0xffff); + IFDBG rz_cons_printf ("Writing 0x%04x to 0x%" PFMT64x ": %d.", flag_value, addr, res); + } else { + eprintf ("[-] rz_cmd_java: invalid flag value or type provided .\n"); + rz_cmd_java_print_cmd_help (JAVA_CMDS + SET_ACC_FLAGS_IDX); + res = true; + } + return res; +} + +static int rz_cmd_java_call(void *user, const char *input) { + RzCore *core = (RzCore *)user; + int res = false; + ut32 i = 0; + if (strncmp (input, "java", 4)) { + return false; + } + if (input[4] != ' ') { + return rz_cmd_java_handle_help (core, input); + } + for (; i < END_CMDS - 1; i++) { + //IFDBG rz_cons_printf ("Checking cmd: %s %d %s\n", JAVA_CMDS[i].name, JAVA_CMDS[i].name_len, p); + IFDBG rz_cons_printf ("Checking cmd: %s %d\n", JAVA_CMDS[i].name, + strncmp (input + 5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len)); + if (!strncmp (input + 5, JAVA_CMDS[i].name, JAVA_CMDS[i].name_len)) { + const char *cmd = input + 5 + JAVA_CMDS[i].name_len; + if (*cmd && *cmd == ' ') { + cmd++; + } + //IFDBG rz_cons_printf ("Executing cmd: %s (%s)\n", JAVA_CMDS[i].name, cmd+5+JAVA_CMDS[i].name_len ); + res = JAVA_CMDS[i].handler (core, cmd); + break; + } + } + if (!res) { + return rz_cmd_java_handle_help (core, input); + } + return true; +} + +static int rz_cmd_java_print_method_definitions(RBinJavaObj *obj) { + RzList *the_list = rz_bin_java_get_method_definitions (obj), + *off_list = rz_bin_java_get_method_offsets (obj); + char *str = NULL; + ut32 idx = 0, end = rz_list_length (the_list); + + while (idx < end) { + ut64 *addr = rz_list_get_n (off_list, idx); + str = rz_list_get_n (the_list, idx); + rz_cons_printf ("%s; // @0x%04" PFMT64x "\n", str, *addr); + idx++; + } + + rz_list_free (the_list); + rz_list_free (off_list); + return true; +} + +static int rz_cmd_java_print_field_definitions(RBinJavaObj *obj) { + RzList *the_list = rz_bin_java_get_field_definitions (obj), + *off_list = rz_bin_java_get_field_offsets (obj); + char *str = NULL; + ut32 idx = 0, end = rz_list_length (the_list); + + while (idx < end) { + ut64 *addr = rz_list_get_n (off_list, idx); + str = rz_list_get_n (the_list, idx); + rz_cons_printf ("%s; // @0x%04" PFMT64x "\n", str, *addr); + idx++; + } + + rz_list_free (the_list); + rz_list_free (off_list); + return true; +} + +static int rz_cmd_java_print_import_definitions(RBinJavaObj *obj) { + RzList *the_list = rz_bin_java_get_import_definitions (obj); + char *str = NULL; + RzListIter *iter; + rz_list_foreach (the_list, iter, str) { + rz_cons_printf ("import %s;\n", str); + } + rz_list_free (the_list); + return true; +} + +static int rz_cmd_java_print_all_definitions(RzAnal *anal) { + RzList *obj_list = rz_cmd_java_get_bin_obj_list (anal); + RzListIter *iter; + RBinJavaObj *obj; + + if (!obj_list) { + return 1; + } + rz_list_foreach (obj_list, iter, obj) { + rz_cmd_java_print_class_definitions (obj); + } + return true; +} + +static int rz_cmd_java_print_json_definitions(RBinJavaObj *obj) { + DsoJsonObj *json_obj = rz_bin_java_get_bin_obj_json (obj); + char *str = dso_json_obj_to_str (json_obj); + dso_json_obj_del (json_obj); // XXX memleak + rz_cons_println (str); + return true; +} + +static int rz_cmd_java_print_class_definitions(RBinJavaObj *obj) { + RzList *the_fields = rz_bin_java_get_field_definitions (obj), + *the_methods = rz_bin_java_get_method_definitions (obj), + *the_imports = rz_bin_java_get_import_definitions (obj), + *the_moffsets = rz_bin_java_get_method_offsets (obj), + *the_foffsets = rz_bin_java_get_field_offsets (obj); + + char *class_name = rz_bin_java_get_this_class_name (obj); + char *str = NULL; + + rz_cmd_java_print_import_definitions (obj); + rz_cons_printf ("\nclass %s { // @0x%04" PFMT64x "\n", class_name, obj->loadaddr); + + if (the_fields && the_foffsets && rz_list_length (the_fields) > 0) { + rz_cons_printf ("\n // Fields defined in the class\n"); + ut32 idx = 0, end = rz_list_length (the_fields); + + while (idx < end) { + ut64 *addr = rz_list_get_n (the_foffsets, idx); + str = rz_list_get_n (the_fields, idx); + rz_cons_printf (" %s; // @0x%04" PFMT64x "\n", str, *addr); + idx++; + } + } + + if (the_methods && the_moffsets && rz_list_length (the_methods) > 0) { + rz_cons_printf ("\n // Methods defined in the class\n"); + ut32 idx = 0, end = rz_list_length (the_methods); + + while (idx < end) { + ut64 *addr = rz_list_get_n (the_moffsets, idx); + str = rz_list_get_n (the_methods, idx); + rz_cons_printf (" %s; // @0x%04" PFMT64x "\n", str, *addr); + idx++; + } + } + rz_cons_printf ("}\n"); + + rz_list_free (the_imports); + rz_list_free (the_fields); + rz_list_free (the_methods); + rz_list_free (the_foffsets); + rz_list_free (the_moffsets); + + free (class_name); + return true; +} + +static RzList *rz_cmd_java_get_bin_obj_list(RzAnal *anal) { + RBinJavaObj *bin_obj = (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal); + // See librz/bin/p/bin_java.c to see what is happening here. The original intention + // was to use a shared global db variable from shlr/java/class.c, but the + // BIN_OBJS_ADDRS variable kept getting corrupted on Mac, so I (deeso) switched the + // way the access to the db was taking place by using the bin_obj as a proxy back + // to the BIN_OBJS_ADDRS which is instantiated in librz/bin/p/bin_java.c + // not the easiest way to make sausage, but its getting made. + return rz_bin_java_get_bin_obj_list_thru_obj (bin_obj); +} + +static RBinJavaObj *rz_cmd_java_get_bin_obj(RzAnal *anal) { + RBin *b; + int is_java; + RBinPlugin *plugin; + if (!anal || !anal->binb.bin) { + return NULL; + } + b = anal->binb.bin; + if (!b->cur || !b->cur->o) { + return NULL; + } + plugin = b->cur->o->plugin; + is_java = (plugin && strcmp (plugin->name, "java") == 0)? 1: 0; + return is_java? b->cur->o->bin_obj: NULL; +} + +static int rz_cmd_java_resolve_cp_idx(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + char *str = rz_bin_java_resolve_without_space (obj, idx); + rz_cons_println (str); + free (str); + } + return true; +} + +static int rz_cmd_java_resolve_cp_type(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + char *str = rz_bin_java_resolve_cp_idx_type (obj, idx); + rz_cons_println (str); + free (str); + } + return true; +} + +static int rz_cmd_java_resolve_cp_idx_b64(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + char *str = rz_bin_java_resolve_b64_encode (obj, idx); + rz_cons_println (str); + free (str); + } + return true; +} + +static int rz_cmd_java_resolve_cp_address(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + ut64 addr = rz_bin_java_resolve_cp_idx_address (obj, idx); + if (addr == (ut64)-1) { + rz_cons_printf ("Unable to resolve CP Object @ index: 0x%04x\n", idx); + } else { + rz_cons_printf ("0x%" PFMT64x "\n", addr); + } + } + return true; +} + +static int rz_cmd_java_resolve_cp_to_key(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + char *str = rz_bin_java_resolve_cp_idx_to_string (obj, idx); + rz_cons_println (str); + free (str); + } + return true; +} +static int rz_cmd_java_resolve_cp_summary(RBinJavaObj *obj, ut16 idx) { + if (obj && idx) { + rz_bin_java_resolve_cp_idx_print_summary (obj, idx); + } + return true; +} + +static int rz_cmd_java_is_valid_input_num_value(RzCore *core, const char *input_value) { + ut64 value = input_value? rz_num_math (core->num, input_value): 0; + return !(value == 0 && input_value && *input_value == '0'); +} + +static ut64 rz_cmd_java_get_input_num_value(RzCore *core, const char *input_value) { + ut64 value = input_value? rz_num_math (core->num, input_value): 0; + return value; +} + +static int rz_cmd_java_print_class_access_flags_value(const char *flags) { + ut16 result = rz_bin_java_calculate_class_access_value (flags); + rz_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); + return true; +} +static int rz_cmd_java_print_field_access_flags_value(const char *flags) { + ut16 result = rz_bin_java_calculate_field_access_value (flags); + rz_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); + return true; +} +static int rz_cmd_java_print_method_access_flags_value(const char *flags) { + ut16 result = rz_bin_java_calculate_method_access_value (flags); + rz_cons_printf ("Access Value for %s = 0x%04x\n", flags, result); + return true; +} + +static int rz_cmd_java_set_acc_flags(RzCore *core, ut64 addr, ut16 num_acc_flag) { + char cmd_buf[50]; + + int res = false; + num_acc_flag = R_BIN_JAVA_USHORT (((ut8 *)&num_acc_flag), 0); + res = rz_core_write_at (core, addr, (const ut8 *)&num_acc_flag, 2); + if (!res) { + eprintf ("[X] rz_cmd_java_set_acc_flags: Failed to write.\n"); + return res; + } + res = true; + IFDBG rz_cons_printf ("Executed cmd: %s == %d\n", cmd_buf, res); + return res; +} +static int rz_cmd_java_print_field_num_name(RBinJavaObj *obj) { + RzList *the_list = rz_bin_java_get_field_num_name (obj); + char *str; + RzListIter *iter = NULL; + rz_list_foreach (the_list, iter, str) { + rz_cons_println (str); + } + rz_list_free (the_list); + return true; +} + +static int rz_cmd_java_print_method_num_name(RBinJavaObj *obj) { + RzList *the_list = rz_bin_java_get_method_num_name (obj); + char *str; + RzListIter *iter = NULL; + rz_list_foreach (the_list, iter, str) { + rz_cons_println (str); + } + rz_list_free (the_list); + return true; +} + +static int rz_cmd_java_print_field_summary(RBinJavaObj *obj, ut16 idx) { + int res = rz_bin_java_print_field_idx_summary (obj, idx); + if (res == false) { + eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); + res = true; + } + return res; +} + +static int UNUSED_FUNCTION(rz_cmd_java_print_field_count)(RBinJavaObj *obj) { + ut32 res = rz_bin_java_get_field_count (obj); + rz_cons_printf ("%d\n", res); + rz_cons_flush (); + return true; +} + +static int rz_cmd_java_print_field_name(RBinJavaObj *obj, ut16 idx) { + char *res = rz_bin_java_get_field_name (obj, idx); + if (res) { + rz_cons_println (res); + } else { + eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); + } + free (res); + return true; +} + +static int rz_cmd_java_print_method_summary(RBinJavaObj *obj, ut16 idx) { + int res = rz_bin_java_print_method_idx_summary (obj, idx); + if (res == false) { + eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); + res = true; + } + return res; +} + +static int _(rz_cmd_java_print_method_count)(RBinJavaObj *obj) { + ut32 res = rz_bin_java_get_method_count (obj); + rz_cons_printf ("%d\n", res); + rz_cons_flush (); + return true; +} + +static int rz_cmd_java_print_method_name(RBinJavaObj *obj, ut16 idx) { + char *res = rz_bin_java_get_method_name (obj, idx); + if (res) { + rz_cons_println (res); + } else { + eprintf ("Error: Field or Method @ index (%d) not found in the RBinJavaObj.\n", idx); + } + free (res); + return true; +} + +static int rz_cmd_java_handle_yara_code_extraction_refs(RzCore *core, const char *input) { + RzAnal *anal = get_anal (core); + RBinJavaObj *bin = anal? (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal): NULL; + const char *p = input? rz_cmd_java_consumetok (input, ' ', -1): NULL, *n = NULL; + char *name = NULL; + ut64 addr = -1, count = -1; + int res = false; + + if (!bin) { + return res; + } else if (!anal || !anal->fcns || rz_list_length (anal->fcns) == 0) { + eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n"); + return true; + } + + if (!p) { + return res; + } + + n = *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + name = n && p && p != n? malloc (n - p + 2): NULL; + + if (!name) { + return res; + } + + memset (name, 0, n - p); + memcpy (name, p, n - p); + + p = rz_cmd_java_strtok (p, ' ', -1); + addr = p && *p && rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut64)-1; + + p = rz_cmd_java_strtok (p, ' ', -1); + count = p && *p && rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): (ut64)-1; + + if (name && count != (ut64)-1 && addr != (ut64)-1) { + // find function at addr + + // find the start basic block + + // read the bytes + + // hexlify the bytes + + // set the name = bytes + + // print t + } + free (name); + return res; +} + +static int rz_cmd_java_handle_insert_method_ref(RzCore *core, const char *input) { + RzAnal *anal = get_anal (core); + RBinJavaObj *bin = anal? (RBinJavaObj *)rz_cmd_java_get_bin_obj (anal): NULL; + const char *p = input? rz_cmd_java_consumetok (input, ' ', -1): NULL, *n = NULL; + char *classname = NULL, *name = NULL, *descriptor = NULL; + ut32 cn_sz = 0, n_sz = 0, d_sz = 0; + int res = false; + + if (!bin) { + return res; + } + if (!anal || !anal->fcns || rz_list_length (anal->fcns) == 0) { + eprintf ("Unable to access the current analysis, perform 'af' for function analysis.\n"); + return true; + } + if (!p) { + return res; + } + + n = p && *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + classname = n && p && p != n? malloc (n - p + 1): NULL; + cn_sz = n && p? n - p + 1: 0; + if (!classname) { + return res; + } + + snprintf (classname, cn_sz, "%s", p); + p = n + 1; + n = p && *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + name = n && p && p != n? malloc (n - p + 1): NULL; + n_sz = n && p? n - p + 1: 0; + if (!name) { + free (classname); + return res; + } + snprintf (name, n_sz, "%s", p); + + p = n + 1; + n = p && *p? rz_cmd_java_strtok (p, ' ', -1): NULL; + if (n) { + descriptor = n && p && p != n? malloc (n - p + 1): NULL; + d_sz = n - p + 1; + } else if (p && *p) { + d_sz = strlen (p) + 1; + descriptor = d_sz > 1? malloc (d_sz): NULL; + } + + if (!descriptor) { + free (classname); + free (name); + return res; + } + snprintf (descriptor, d_sz, "%s", p); + + rz_cons_printf ("Would be adding class name:%s, name: %s, descriptor: %s\n", classname, name, descriptor); + free (classname); + free (name); + free (descriptor); + res = true; + return res; +} + +static int rz_cmd_java_handle_print_exceptions(RzCore *core, const char *input) { + RzAnal *anal = get_anal (core); + RBinJavaObj *bin = (RBinJavaObj *) rz_cmd_java_get_bin_obj (anal); + RzListIter *exc_iter = NULL, *methods_iter=NULL; + RBinJavaField *method; + ut64 func_addr = -1; + RBinJavaExceptionEntry *exc_entry; + + const char *p = input? rz_cmd_java_consumetok (input, ' ', -1): NULL; + func_addr = p && *p && rz_cmd_java_is_valid_input_num_value (core, p)? rz_cmd_java_get_input_num_value (core, p): -1; + + if (!bin) { + return false; + } + + rz_list_foreach (bin->methods_list, methods_iter, method) { + ut64 start = rz_bin_java_get_method_start (bin, method), + end = rz_bin_java_get_method_end (bin, method); + ut8 do_this_one = start <= func_addr && func_addr <= end; + RzList *exc_table = NULL; + do_this_one = func_addr == (ut64)-1? 1: do_this_one; + if (!do_this_one) { + continue; + } + exc_table = rz_bin_java_get_method_exception_table_with_addr (bin, start); + + if (rz_list_length (exc_table) == 0){ + rz_cons_printf (" Exception table for %s @ 0x%"PFMT64x":\n", method->name, start); + rz_cons_printf (" [ NONE ]\n"); + } else { + rz_cons_printf (" Exception table for %s (%d entries) @ 0x%"PFMT64x":\n", method->name, + rz_list_length (exc_table) , start); + } + rz_list_foreach (exc_table, exc_iter, exc_entry) { + char *class_info = rz_bin_java_resolve_without_space (bin, exc_entry->catch_type); + rz_cons_printf (" Catch Type: %d, %s @ 0x%"PFMT64x"\n", exc_entry->catch_type, + class_info, exc_entry->file_offset+6); + rz_cons_printf (" Start PC: (0x%"PFMT64x") 0x%"PFMT64x" @ 0x%"PFMT64x"\n", + exc_entry->start_pc, exc_entry->start_pc+start, exc_entry->file_offset); + rz_cons_printf (" End PC: (0x%"PFMT64x") 0x%"PFMT64x" 0x%"PFMT64x"\n", + exc_entry->end_pc, exc_entry->end_pc+start, exc_entry->file_offset + 2); + rz_cons_printf (" Handler PC: (0x%"PFMT64x") 0x%"PFMT64x" 0x%"PFMT64x"\n", + exc_entry->handler_pc, exc_entry->handler_pc+start, exc_entry->file_offset+4); + free (class_info); + } + } + return true; +} + +// PLUGIN Definition Info +RzCorePlugin rz_core_plugin_java = { + .name = "java", + .desc = "Suite of java commands, java help for more info", + .license = "Apache", + .call = rz_cmd_java_call, +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_CORE, + .data = &rz_core_plugin_java, + .version = R2_VERSION +}; +#endif diff --git a/librz/core/p/core_test.c b/librz/core/p/core_test.c new file mode 100644 index 0000000000..e44a66f7c0 --- /dev/null +++ b/librz/core/p/core_test.c @@ -0,0 +1,39 @@ +/* radare - LGPL - Copyright 2014 - pancake */ +#if 0 +gcc -o core_test.so -fPIC `pkg-config --cflags --libs rz_core` core_test.c -shared +mkdir -p ~/.config/rizin/plugins +mv core_test.so ~/.config/rizin/plugins +#endif + +#include +#include +#include +#include +#include +#include +#include + +#undef RZ_API +#define RZ_API static +#undef R_IPI +#define R_IPI static + +static int rz_cmd_test_call(void) { + eprintf ("Dummy!\n"); + return false; +} + +RzCorePlugin rz_core_plugin_test = { + .name = "test", + .desc = "lalallala", + .license = "MIT", + .call = rz_cmd_test_call, +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_CORE, + .data = &rz_core_plugin_test, + .version = R2_VERSION +}; +#endif diff --git a/libr/core/p/java.mk b/librz/core/p/java.mk similarity index 88% rename from libr/core/p/java.mk rename to librz/core/p/java.mk index fd37829fce..9c37ee88d5 100644 --- a/libr/core/p/java.mk +++ b/librz/core/p/java.mk @@ -15,7 +15,7 @@ LDFLAGS+=$(LINK) ifeq ($(WITHPIC),1) ALL_TARGETS+=${CORE_TARGET_JAVA} -R2DEPS+=r_crypto +R2DEPS+=rz_crypto include $(STOP)/java/deps.mk ${CORE_TARGET_JAVA}: ${CORE_OBJ_JAVA} @@ -23,7 +23,7 @@ ${CORE_TARGET_JAVA}: ${CORE_OBJ_JAVA} ${CC} $(call libname,core_java) ${CFLAGS} $(LDFLAGS) \ -o core_java.${EXT_SO} \ ${CORE_OBJ_JAVA} ${CORE_SHARED2_JAVA} \ - $(SHLR)/java/libr_java.$(EXT_AR) \ + $(SHLR)/java/librz_java.$(EXT_AR) \ $(SHLR)/sdb/src/libsdb.$(EXT_AR) \ - -L$(LIBR)/crypto -lr_crypto + -L$(LIBR)/crypto -lrz_crypto endif diff --git a/libr/core/panels.c b/librz/core/panels.c similarity index 72% rename from libr/core/panels.c rename to librz/core/panels.c index ae1477e2c6..90eecb404d 100644 --- a/libr/core/panels.c +++ b/librz/core/panels.c @@ -1,6 +1,6 @@ -/* Copyright radare2 2014-2020 - Author: pancake, vane11ope */ +/* Copyright rizin 2014-2020 - Author: pancake, vane11ope */ -#include +#include #define PANEL_NUM_LIMIT 9 @@ -280,16 +280,16 @@ static const char *help_msg_panels_zoom[] = { }; /* init */ -static bool __init(RCore *core, RPanels *panels, int w, int h); -static void __init_sdb(RCore *core); -static void __init_rotate_db(RCore *core); -static void __init_almighty_db(RCore *core); -static bool __init_panels_menu(RCore *core); -static bool __init_panels(RCore *core, RPanels *panels); -static void __init_all_dbs(RCore *core); -static void __init_panel_param(RCore *core, RPanel *p, const char *title, const char *cmd); -static RPanels *__panels_new(RCore *core); -static void __init_new_panels_root(RCore *core); +static bool __init(RzCore *core, RPanels *panels, int w, int h); +static void __init_sdb(RzCore *core); +static void __init_rotate_db(RzCore *core); +static void __init_almighty_db(RzCore *core); +static bool __init_panels_menu(RzCore *core); +static bool __init_panels(RzCore *core, RPanels *panels); +static void __init_all_dbs(RzCore *core); +static void __init_panel_param(RzCore *core, RPanel *p, const char *title, const char *cmd); +static RPanels *__panels_new(RzCore *core); +static void __init_new_panels_root(RzCore *core); static void __init_menu_saved_layout(void *core, const char *parent); static void __init_menu_color_settings_layout(void *core, const char *parent); static void __init_menu_disasm_settings_layout(void *_core, const char *parent); @@ -297,8 +297,8 @@ static void __init_menu_disasm_asm_settings_layout(void *_core, const char *pare static void __init_menu_screen_settings_layout(void *_core, const char *parent); /* create */ -static void __create_default_panels(RCore *core); -static RConsCanvas *__create_new_canvas(RCore *core, int w, int h); +static void __create_default_panels(RzCore *core); +static RzConsCanvas *__create_new_canvas(RzCore *core, int w, int h); /* free */ static void __free_panel_model(RPanel *panel); @@ -307,168 +307,168 @@ static void __free_menu_item(RPanelsMenuItem *item); /* get */ static RPanel *__get_panel(RPanels *panels, int i); static RPanel *__get_cur_panel(RPanels *panels); -static int __get_panel_idx_in_pos(RCore *core, int x, int y); +static int __get_panel_idx_in_pos(RzCore *core, int x, int y); static RPanels *__get_panels(RPanelsRoot *panels_root, int i); -static char *get_word_from_canvas(RCore *core, RPanels *panels, int x, int y); -static char *get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x, int y); +static char *get_word_from_canvas(RzCore *core, RPanels *panels, int x, int y); +static char *get_word_from_canvas_for_menu(RzCore *core, RPanels *panels, int x, int y); /* set */ -static void __seek_all(RCore *core, ut64 addr); -static void __set_curnode(RCore *core, int idx); -static void __set_refresh_all(RCore *core, bool clearCache, bool force_refresh); -static void __set_addr_by_type(RCore *core, const char *cmd, ut64 addr); -static void __set_refresh_by_type(RCore *core, const char *cmd, bool clearCache); -static void __set_cursor(RCore *core, bool cur); -static void __set_dcb(RCore *core, RPanel *p); +static void __seek_all(RzCore *core, ut64 addr); +static void __set_curnode(RzCore *core, int idx); +static void __set_refresh_all(RzCore *core, bool clearCache, bool force_refresh); +static void __set_addr_by_type(RzCore *core, const char *cmd, ut64 addr); +static void __set_refresh_by_type(RzCore *core, const char *cmd, bool clearCache); +static void __set_cursor(RzCore *core, bool cur); +static void __set_dcb(RzCore *core, RPanel *p); static void __set_rcb(RPanels *ps, RPanel *p); static void __set_pcb(RPanel *p); -static void __set_read_only(RCore *core, RPanel *p, char *s); +static void __set_read_only(RzCore *core, RPanel *p, char *s); static void __set_pos(RPanelPos *pos, int x, int y); static void __set_size(RPanelPos *pos, int w, int h); static void __set_geometry(RPanelPos *pos, int x, int y, int w, int h); -static void __set_panel_addr(RCore *core, RPanel *panel, ut64 addr); -static void __set_root_state(RCore *core, RPanelsRootState state); +static void __set_panel_addr(RzCore *core, RPanel *panel, ut64 addr); +static void __set_root_state(RzCore *core, RPanelsRootState state); /* reset */ static void __reset_scroll_pos(RPanel *p); /* update */ -static void __update_disassembly_or_open(RCore *core); -static void __update_help(RCore *core, RPanels *ps); -static void __update_menu_contents(RCore *core, RPanelsMenu *menu, RPanelsMenuItem *parent); -static void __update_edge_x(RCore *core, int x); -static void __update_edge_y(RCore *core, int y); +static void __update_disassembly_or_open(RzCore *core); +static void __update_help(RzCore *core, RPanels *ps); +static void __update_menu_contents(RzCore *core, RPanelsMenu *menu, RPanelsMenuItem *parent); +static void __update_edge_x(RzCore *core, int x); +static void __update_edge_y(RzCore *core, int y); /* check */ static bool __check_panel_type(RPanel *panel, const char *type); -static void __panels_check_stackbase(RCore *core); -static bool __check_panel_num(RCore *core); -static bool __check_func(RCore *core); -static bool __check_func_diff(RCore *core, RPanel *p); -static bool __check_root_state(RCore *core, RPanelsRootState state); +static void __panels_check_stackbase(RzCore *core); +static bool __check_panel_num(RzCore *core); +static bool __check_func(RzCore *core); +static bool __check_func_diff(RzCore *core, RPanel *p); +static bool __check_root_state(RzCore *core, RPanelsRootState state); static bool __check_if_addr(const char *c, int len); -static bool __check_if_cur_panel(RCore *core, RPanel *panel); -static bool __check_if_mouse_x_illegal(RCore *core, int x); -static bool __check_if_mouse_y_illegal(RCore *core, int y); -static bool __check_if_mouse_x_on_edge(RCore *core, int x, int y); -static bool __check_if_mouse_y_on_edge(RCore *core, int x, int y); -static void __check_edge(RCore *core); +static bool __check_if_cur_panel(RzCore *core, RPanel *panel); +static bool __check_if_mouse_x_illegal(RzCore *core, int x); +static bool __check_if_mouse_y_illegal(RzCore *core, int y); +static bool __check_if_mouse_x_on_edge(RzCore *core, int x, int y); +static bool __check_if_mouse_y_on_edge(RzCore *core, int x, int y); +static void __check_edge(RzCore *core); /* add */ -static void __add_help_panel(RCore *core); -static void __add_visual_mark(RCore *core); -static void __add_menu(RCore *core, const char *parent, const char *base_name, RPanelsMenuCallback cb); -static void __update_menu(RCore *core, const char *parent, R_NULLABLE RPanelMenuUpdateCallback cb); +static void __add_help_panel(RzCore *core); +static void __add_visual_mark(RzCore *core); +static void __add_menu(RzCore *core, const char *parent, const char *base_name, RPanelsMenuCallback cb); +static void __update_menu(RzCore *core, const char *parent, R_NULLABLE RPanelMenuUpdateCallback cb); /* user input */ -static int __show_status(RCore *core, const char *msg); -static bool __show_status_yesno(RCore *core, int def, const char *msg); -static char *__show_status_input(RCore *core, const char *msg); +static int __show_status(RzCore *core, const char *msg); +static bool __show_status_yesno(RzCore *core, int def, const char *msg); +static char *__show_status_input(RzCore *core, const char *msg); static void __panel_prompt(const char *prompt, char *buf, int len); /* panel layout */ -static void __panels_layout_refresh(RCore *core); +static void __panels_layout_refresh(RzCore *core); static void __panels_layout(RPanels *panels); static void __layout_default(RPanels *panels); static void __layout_equal_hor(RPanels *panels); -R_API void r_save_panels_layout(RCore *core, const char *_name); -R_API bool r_load_panels_layout(RCore *core, const char *_name); -static void __split_panel_vertical(RCore *core, RPanel *p, const char *name, const char *cmd); -static void __split_panel_horizontal(RCore *core, RPanel *p, const char *name, const char *cmd); -static void __panel_print(RCore *core, RConsCanvas *can, RPanel *panel, int color); -static void __menu_panel_print(RConsCanvas *can, RPanel *panel, int x, int y, int w, int h); -static void __update_help_contents(RCore *core, RPanel *panel); -static void __update_help_title(RCore *core, RPanel *panel); -static void __update_panel_contents(RCore *core, RPanel *panel, const char *cmdstr); -static void __update_panel_title(RCore *core, RPanel *panel); -static void __update_pdc_contents(RCore *core, RPanel *panel, char *cmdstr); -static void __default_panel_print(RCore *core, RPanel *panel); +RZ_API void rz_save_panels_layout(RzCore *core, const char *_name); +RZ_API bool rz_load_panels_layout(RzCore *core, const char *_name); +static void __split_panel_vertical(RzCore *core, RPanel *p, const char *name, const char *cmd); +static void __split_panel_horizontal(RzCore *core, RPanel *p, const char *name, const char *cmd); +static void __panel_print(RzCore *core, RzConsCanvas *can, RPanel *panel, int color); +static void __menu_panel_print(RzConsCanvas *can, RPanel *panel, int x, int y, int w, int h); +static void __update_help_contents(RzCore *core, RPanel *panel); +static void __update_help_title(RzCore *core, RPanel *panel); +static void __update_panel_contents(RzCore *core, RPanel *panel, const char *cmdstr); +static void __update_panel_title(RzCore *core, RPanel *panel); +static void __update_pdc_contents(RzCore *core, RPanel *panel, char *cmdstr); +static void __default_panel_print(RzCore *core, RPanel *panel); static void __resize_panel_left(RPanels *panels); static void __resize_panel_right(RPanels *panels); static void __resize_panel_up(RPanels *panels); static void __resize_panel_down(RPanels *panels); -static void __adjust_side_panels(RCore *core); -static void __insert_panel(RCore *core, int n, const char *name, const char*cmd); -static void __dismantle_del_panel(RCore *core, RPanel *p, int pi); +static void __adjust_side_panels(RzCore *core); +static void __insert_panel(RzCore *core, int n, const char *name, const char*cmd); +static void __dismantle_del_panel(RzCore *core, RPanel *p, int pi); static void __dismantle_panel(RPanels *ps, RPanel *p); -static void __panels_refresh(RCore *core); -static void __do_panels_resize(RCore *core); -static void __do_panels_refresh(RCore *core); -static void __do_panels_refreshOneShot(RCore *core); +static void __panels_refresh(RzCore *core); +static void __do_panels_resize(RzCore *core); +static void __do_panels_refresh(RzCore *core); +static void __do_panels_refreshOneShot(RzCore *core); static void __panel_all_clear(RPanels *panels); -static void __del_panel(RCore *core, int pi); -static void __del_invalid_panels(RCore *core); +static void __del_panel(RzCore *core, int pi); +static void __del_invalid_panels(RzCore *core); static void __swap_panels(RPanels *panels, int p0, int p1); -static void __move_panel_to_dir(RCore *core, RPanel *panel, int src); -static void __move_panel_to_left(RCore *core, RPanel *panel, int src); -static void __move_panel_to_right(RCore *core, RPanel *panel, int src); -static void __move_panel_to_up(RCore *core, RPanel *panel, int src); -static void __move_panel_to_down(RCore *core, RPanel *panel, int src); -static void __shrink_panels_forward(RCore *core, int target); -static void __shrink_panels_backward(RCore *core, int target); -static void __fix_layout(RCore *core); -static void __fix_layout_w(RCore *core); -static void __fix_layout_h(RCore *core); -static bool __drag_and_resize(RCore *core); +static void __move_panel_to_dir(RzCore *core, RPanel *panel, int src); +static void __move_panel_to_left(RzCore *core, RPanel *panel, int src); +static void __move_panel_to_right(RzCore *core, RPanel *panel, int src); +static void __move_panel_to_up(RzCore *core, RPanel *panel, int src); +static void __move_panel_to_down(RzCore *core, RPanel *panel, int src); +static void __shrink_panels_forward(RzCore *core, int target); +static void __shrink_panels_backward(RzCore *core, int target); +static void __fix_layout(RzCore *core); +static void __fix_layout_w(RzCore *core); +static void __fix_layout_h(RzCore *core); +static bool __drag_and_resize(RzCore *core); /* cursor */ -static bool __is_abnormal_cursor_type(RCore *core, RPanel *panel); +static bool __is_abnormal_cursor_type(RzCore *core, RPanel *panel); static bool __is_normal_cursor_type(RPanel *panel); -static void __activate_cursor(RCore *core); -static ut64 __parse_string_on_cursor(RCore *core, RPanel *panel, int idx); -static void __cursor_left(RCore *core); -static void __cursor_right(RCore *core); -static void __cursor_down(RCore *core); -static void __cursor_up(RCore *core); -static void __fix_cursor_up(RCore *core); -static void __fix_cursor_down(RCore *core); -static void __jmp_to_cursor_addr(RCore *core, RPanel *panel); -static void __cursor_del_breakpoints(RCore *core, RPanel *panel); -static void __insert_value(RCore *core); -static void __set_breakpoints_on_cursor(RCore *core, RPanel *panel); +static void __activate_cursor(RzCore *core); +static ut64 __parse_string_on_cursor(RzCore *core, RPanel *panel, int idx); +static void __cursor_left(RzCore *core); +static void __cursor_right(RzCore *core); +static void __cursor_down(RzCore *core); +static void __cursor_up(RzCore *core); +static void __fix_cursor_up(RzCore *core); +static void __fix_cursor_down(RzCore *core); +static void __jmp_to_cursor_addr(RzCore *core, RPanel *panel); +static void __cursor_del_breakpoints(RzCore *core, RPanel *panel); +static void __insert_value(RzCore *core); +static void __set_breakpoints_on_cursor(RzCore *core, RPanel *panel); /* filter */ -static void __set_filter(RCore *core, RPanel *panel); -static void __reset_filter(RCore *core, RPanel *panel); +static void __set_filter(RzCore *core, RPanel *panel); +static void __reset_filter(RzCore *core, RPanel *panel); static void __renew_filter(RPanel *panel, int n); -static char *__apply_filter_cmd(RCore *core, RPanel *panel); +static char *__apply_filter_cmd(RzCore *core, RPanel *panel); /* cmd */ static int __add_cmd_panel(void *user); -static int __add_cmdf_panel(RCore *core, char *input, char *str); -static void __set_cmd_str_cache(RCore *core, RPanel *p, char *s); -static void __set_decompiler_cache(RCore *core, char *s); -static char *__handle_cmd_str_cache(RCore *core, RPanel *panel, bool force_cache); -static char *__find_cmd_str_cache(RCore *core, RPanel *panel); -static char *__load_cmdf(RCore *core, RPanel *p, char *input, char *str); -static void __replace_cmd(RCore *core, const char *title, const char *cmd); +static int __add_cmdf_panel(RzCore *core, char *input, char *str); +static void __set_cmd_str_cache(RzCore *core, RPanel *p, char *s); +static void __set_decompiler_cache(RzCore *core, char *s); +static char *__handle_cmd_str_cache(RzCore *core, RPanel *panel, bool force_cache); +static char *__find_cmd_str_cache(RzCore *core, RPanel *panel); +static char *__load_cmdf(RzCore *core, RPanel *p, char *input, char *str); +static void __replace_cmd(RzCore *core, const char *title, const char *cmd); /* rotate */ -static void __rotate_panels(RCore *core, bool rev); -static void __rotate_panel_cmds(RCore *core, const char **cmds, const int cmdslen, const char *prefix, bool rev); -static void __rotate_asmemu(RCore *core, RPanel *p); +static void __rotate_panels(RzCore *core, bool rev); +static void __rotate_panel_cmds(RzCore *core, const char **cmds, const int cmdslen, const char *prefix, bool rev); +static void __rotate_asmemu(RzCore *core, RPanel *p); /* mode */ -static void __set_mode(RCore *core, RPanelsMode mode); -static bool __handle_zoom_mode(RCore *core, const int key); -static bool __handle_window_mode(RCore *core, const int key); -static bool __handle_cursor_mode(RCore *core, const int key); -static void __toggle_zoom_mode(RCore *core); -static void __toggle_window_mode(RCore *core); +static void __set_mode(RzCore *core, RPanelsMode mode); +static bool __handle_zoom_mode(RzCore *core, const int key); +static bool __handle_window_mode(RzCore *core, const int key); +static bool __handle_cursor_mode(RzCore *core, const int key); +static void __toggle_zoom_mode(RzCore *core); +static void __toggle_window_mode(RzCore *core); /* mouse */ -static bool __handle_mouse(RCore *core, RPanel *panel, int *key); -static bool __handle_mouse_on_top(RCore *core, int x, int y); -static void __handle_mouse_on_menu(RCore *core, int x, int y); -static bool __handle_mouse_on_X(RCore *core, int x, int y); -static bool __handle_mouse_on_panel(RCore *core, RPanel *panel, int x, int y, int *key); +static bool __handle_mouse(RzCore *core, RPanel *panel, int *key); +static bool __handle_mouse_on_top(RzCore *core, int x, int y); +static void __handle_mouse_on_menu(RzCore *core, int x, int y); +static bool __handle_mouse_on_X(RzCore *core, int x, int y); +static bool __handle_mouse_on_panel(RzCore *core, RPanel *panel, int x, int y, int *key); /* modal */ -static void __exec_almighty(RCore *core, RPanel *panel, RModal *modal, Sdb *menu_db, RPanelLayout dir); -static void __delete_almighty(RCore *core, RModal *modal, Sdb *menu_db); -static void __create_almighty(RCore *core, RPanel *panel, Sdb *menu_db); -static void __update_modal(RCore *core, Sdb *menu_db, RModal *modal); -static bool __draw_modal(RCore *core, RModal *modal, int range_end, int start, const char *name); +static void __exec_almighty(RzCore *core, RPanel *panel, RModal *modal, Sdb *menu_db, RPanelLayout dir); +static void __delete_almighty(RzCore *core, RModal *modal, Sdb *menu_db); +static void __create_almighty(RzCore *core, RPanel *panel, Sdb *menu_db); +static void __update_modal(RzCore *core, Sdb *menu_db, RModal *modal); +static bool __draw_modal(RzCore *core, RModal *modal, int range_end, int start, const char *name); static RModal *__init_modal(void); static void __free_modal(RModal **modal); @@ -491,7 +491,7 @@ static int __fill_cb(void *user); static int __config_toggle_cb(void *user); static int __config_value_cb(void *user); static int __calculator_cb(void *user); -static int __r2_shell_cb(void *user); +static int __rz_shell_cb(void *user); static int __system_shell_cb(void *user); static int __string_whole_bin_cb(void *user); static int __string_data_sec_cb(void *user); @@ -552,13 +552,13 @@ static void __print_stack_cb(void *user, void *p); static void __print_hexdump_cb(void *user, void *p); /* almighty callback */ -static void __create_panel(RCore *core, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char* title, const char *cmd); +static void __create_panel(RzCore *core, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char* title, const char *cmd); static void __create_panel_db(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); static void __create_panel_input(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); static void __replace_current_panel_input(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); static void __search_strings_data_create(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); static void __search_strings_bin_create(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); -static char *__search_strings (RCore *core, bool whole); +static char *__search_strings (RzCore *core, bool whole); static void __put_breakpoints_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPanelLayout dir, R_UNUSED R_NULLABLE const char *title); static void __continue_almighty_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPanelLayout dir, R_UNUSED R_NULLABLE const char *title); static void __step_almighty_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPanelLayout dir, R_UNUSED R_NULLABLE const char *title); @@ -566,18 +566,18 @@ static void __step_over_almighty_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED static void __delegate_show_all_decompiler_cb(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title); /* menu */ -static void __del_menu(RCore *core); -static void __clear_panels_menu(RCore *core); +static void __del_menu(RzCore *core); +static void __clear_panels_menu(RzCore *core); static void __clear_panels_menuRec(RPanelsMenuItem *pmi); -static RStrBuf *__draw_menu(RCore *core, RPanelsMenuItem *item); -static void __handle_menu(RCore *core, const int key); +static RStrBuf *__draw_menu(RzCore *core, RPanelsMenuItem *item); +static void __handle_menu(RzCore *core, const int key); static int cmpstr(const void *_a, const void *_b); -static RList *__sorted_list(RCore *core, char *menu[], int count); +static RzList *__sorted_list(RzCore *core, char *menu[], int count); /* config */ static char *__get_panels_config_dir_path(void); static char *__create_panels_config_path(const char *file); -static void __load_config_menu(RCore *core); +static void __load_config_menu(RzCore *core); static char *__parse_panels_config(const char *cfg, int len); /* history */ @@ -585,17 +585,17 @@ static int __file_history_up(RLine *line); static int __file_history_down(RLine *line); /* hud */ -static void __hudstuff(RCore *core); +static void __hudstuff(RzCore *core); /* esil */ -static void __esil_init(RCore *core); -static void __esil_step_to(RCore *core, ut64 end); +static void __esil_init(RzCore *core); +static void __esil_step_to(RzCore *core, ut64 end); /* debug */ -static void __panel_breakpoint(RCore *core); -static void __panel_single_step_in(RCore *core); -static void __panel_single_step_over(RCore *core); -static void __panel_continue(RCore *core); +static void __panel_breakpoint(RzCore *core); +static void __panel_single_step_in(RzCore *core); +static void __panel_single_step_over(RzCore *core); +static void __panel_continue(RzCore *core); /* zoom mode */ static void __save_panel_pos(RPanel* panel); @@ -603,38 +603,38 @@ static void __restore_panel_pos(RPanel* panel); static void __maximize_panel_size(RPanels *panels); /* tab */ -static void __handle_tab(RCore *core); -static void __handle_tab_nth(RCore *core, int ch); -static void __handle_tab_next(RCore *core); -static void __handle_print_rotate(RCore *core); -static void __handle_tab_prev(RCore *core); -static void __handle_tab_name(RCore *core); -static void __handle_tab_new(RCore *core); -static void __handle_tab_new_with_cur_panel(RCore *core); -static void __del_panels(RCore *core); +static void __handle_tab(RzCore *core); +static void __handle_tab_nth(RzCore *core, int ch); +static void __handle_tab_next(RzCore *core); +static void __handle_print_rotate(RzCore *core); +static void __handle_tab_prev(RzCore *core); +static void __handle_tab_name(RzCore *core); +static void __handle_tab_new(RzCore *core); +static void __handle_tab_new_with_cur_panel(RzCore *core); +static void __del_panels(RzCore *core); /* hobby */ static void __print_snow(RPanels *panels); static void __reset_snow(RPanels *panels); /* other */ -static void __panels_process(RCore *core, RPanels *panels); -static bool __handle_console(RCore *core, RPanel *panel, const int key); -static void __toggle_cache (RCore *core, RPanel *p); -static bool __move_to_direction(RCore *core, Direction direction); -static void __toggle_help(RCore *core); -static void __call_visual_graph(RCore *core); -static void __refresh_core_offset (RCore *core); -static char *__search_db(RCore *core, const char *title); -static void __handle_visual_mark(RCore *core); -static void __handle_tab_key(RCore *core, bool shift); -static void __handle_refs(RCore *core, RPanel *panel, ut64 tmp); -static void __undo_seek(RCore *core); -static void __redo_seek(RCore *core); -static void __cache_white_list(RCore *core, RPanel *panel); -static bool search_db_check_panel_type (RCore *core, RPanel *panel, const char *ch); +static void __panels_process(RzCore *core, RPanels *panels); +static bool __handle_console(RzCore *core, RPanel *panel, const int key); +static void __toggle_cache (RzCore *core, RPanel *p); +static bool __move_to_direction(RzCore *core, Direction direction); +static void __toggle_help(RzCore *core); +static void __call_visual_graph(RzCore *core); +static void __refresh_core_offset (RzCore *core); +static char *__search_db(RzCore *core, const char *title); +static void __handle_visual_mark(RzCore *core); +static void __handle_tab_key(RzCore *core, bool shift); +static void __handle_refs(RzCore *core, RPanel *panel, ut64 tmp); +static void __undo_seek(RzCore *core); +static void __redo_seek(RzCore *core); +static void __cache_white_list(RzCore *core, RPanel *panel); +static bool search_db_check_panel_type (RzCore *core, RPanel *panel, const char *ch); -void __update_edge_x(RCore *core, int x) { +void __update_edge_x(RzCore *core, int x) { RPanels *panels = core->panels; int i, j; int tmp_x = 0; @@ -655,7 +655,7 @@ void __update_edge_x(RCore *core, int x) { } } -void __update_edge_y(RCore *core, int y) { +void __update_edge_y(RzCore *core, int y) { RPanels *panels = core->panels; int i, j; int tmp_y = 0; @@ -676,9 +676,9 @@ void __update_edge_y(RCore *core, int y) { } } -bool __check_if_mouse_x_illegal(RCore *core, int x) { +bool __check_if_mouse_x_illegal(RzCore *core, int x) { RPanels *panels = core->panels; - RConsCanvas *can = panels->can; + RzConsCanvas *can = panels->can; const int edge_x = 1; if (x <= edge_x || can->w - edge_x <= x) { return true; @@ -686,9 +686,9 @@ bool __check_if_mouse_x_illegal(RCore *core, int x) { return false; } -bool __check_if_mouse_y_illegal(RCore *core, int y) { +bool __check_if_mouse_y_illegal(RzCore *core, int y) { RPanels *panels = core->panels; - RConsCanvas *can = panels->can; + RzConsCanvas *can = panels->can; const int edge_y = 0; if (y <= edge_y || can->h - edge_y <= y) { return true; @@ -696,9 +696,9 @@ bool __check_if_mouse_y_illegal(RCore *core, int y) { return false; } -bool __check_if_mouse_x_on_edge(RCore *core, int x, int y) { +bool __check_if_mouse_x_on_edge(RzCore *core, int x, int y) { RPanels *panels = core->panels; - const int edge_x = r_config_get_i (core->config, "scr.panelborder")? 3: 1; + const int edge_x = rz_config_get_i (core->config, "scr.panelborder")? 3: 1; int i = 0; for (; i < panels->n_panels; i++) { RPanel *panel = __get_panel (panels, i); @@ -711,9 +711,9 @@ bool __check_if_mouse_x_on_edge(RCore *core, int x, int y) { return false; } -bool __check_if_mouse_y_on_edge(RCore *core, int x, int y) { +bool __check_if_mouse_y_on_edge(RzCore *core, int x, int y) { RPanels *panels = core->panels; - const int edge_y = r_config_get_i (core->config, "scr.panelborder")? 3: 1; + const int edge_y = rz_config_get_i (core->config, "scr.panelborder")? 3: 1; int i = 0; for (; i < panels->n_panels; i++) { RPanel *panel = __get_panel (panels, i); @@ -728,7 +728,7 @@ bool __check_if_mouse_y_on_edge(RCore *core, int x, int y) { return false; } -bool __check_if_cur_panel(RCore *core, RPanel *panel) { +bool __check_if_cur_panel(RzCore *core, RPanel *panel) { return __get_cur_panel (core->panels) == panel; } @@ -746,7 +746,7 @@ bool __check_if_addr(const char *c, int len) { return false; } -void __check_edge(RCore *core) { +void __check_edge(RzCore *core) { RPanels *panels = core->panels; int i; for (i = 0; i < panels->n_panels; i++) { @@ -764,7 +764,7 @@ void __check_edge(RCore *core) { } } -void __shrink_panels_forward(RCore *core, int target) { +void __shrink_panels_forward(RzCore *core, int target) { RPanels *panels = core->panels; int i = target; for (; i < panels->n_panels - 1; i++) { @@ -772,7 +772,7 @@ void __shrink_panels_forward(RCore *core, int target) { } } -void __shrink_panels_backward(RCore *core, int target) { +void __shrink_panels_backward(RzCore *core, int target) { RPanels *panels = core->panels; int i = target; for (; i > 0; i--) { @@ -780,7 +780,7 @@ void __shrink_panels_backward(RCore *core, int target) { } } -void __cache_white_list(RCore *core, RPanel *panel) { +void __cache_white_list(RzCore *core, RPanel *panel) { int i = 0; for (; i < COUNT (cache_white_list_cmds); i++) { if (!strcmp (panel->model->cmd, cache_white_list_cmds[i])) { @@ -791,7 +791,7 @@ void __cache_white_list(RCore *core, RPanel *panel) { panel->model->cache = false; } -char *__search_db(RCore *core, const char *title) { +char *__search_db(RzCore *core, const char *title) { RPanels *panels = core->panels; if (!panels->db) { return NULL; @@ -803,24 +803,24 @@ char *__search_db(RCore *core, const char *title) { return NULL; } -int __show_status(RCore *core, const char *msg) { - r_cons_gotoxy (0, 0); - r_cons_printf (R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); - r_cons_flush (); - return r_cons_readchar (); +int __show_status(RzCore *core, const char *msg) { + rz_cons_gotoxy (0, 0); + rz_cons_printf (R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); + rz_cons_flush (); + return rz_cons_readchar (); } -bool __show_status_yesno(RCore *core, int def, const char *msg) { - r_cons_gotoxy (0, 0); - r_cons_flush (); - return r_cons_yesno (def, R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); +bool __show_status_yesno(RzCore *core, int def, const char *msg) { + rz_cons_gotoxy (0, 0); + rz_cons_flush (); + return rz_cons_yesno (def, R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); } -char *__show_status_input(RCore *core, const char *msg) { - char *n_msg = r_str_newf (R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); - r_cons_gotoxy (0, 0); - r_cons_flush (); - char *out = r_cons_input (n_msg); +char *__show_status_input(RzCore *core, const char *msg) { + char *n_msg = rz_str_newf (R_CONS_CLEAR_LINE"%s[Status] %s"Color_RESET, core->cons->context->pal.graph_box2, msg); + rz_cons_gotoxy (0, 0); + rz_cons_flush (); + char *out = rz_cons_input (n_msg); free (n_msg); return out; } @@ -829,13 +829,13 @@ bool __check_panel_type(RPanel *panel, const char *type) { if (!panel->model->cmd || !type) { return false; } - char *tmp = r_str_new (panel->model->cmd); - int n = r_str_split (tmp, ' '); + char *tmp = rz_str_new (panel->model->cmd); + int n = rz_str_split (tmp, ' '); if (!n) { free (tmp); return false; } - const char *base = r_str_word_get0 (tmp, 0); + const char *base = rz_str_word_get0 (tmp, 0); if (R_STR_ISEMPTY (base)) { free (tmp); return false; @@ -875,11 +875,11 @@ bool __check_panel_type(RPanel *panel, const char *type) { return !strncmp (panel->model->cmd, type, len); } -bool __check_root_state(RCore *core, RPanelsRootState state) { +bool __check_root_state(RzCore *core, RPanelsRootState state) { return core->panels_root->root_state == state; } -bool search_db_check_panel_type (RCore *core, RPanel *panel, const char *ch) { +bool search_db_check_panel_type (RzCore *core, RPanel *panel, const char *ch) { char *str = __search_db (core, ch); bool ret = str && __check_panel_type (panel, str); free (str); @@ -887,7 +887,7 @@ bool search_db_check_panel_type (RCore *core, RPanel *panel, const char *ch) { } //TODO: Refactroing -bool __is_abnormal_cursor_type(RCore *core, RPanel *panel) { +bool __is_abnormal_cursor_type(RzCore *core, RPanel *panel) { if (__check_panel_type (panel, PANEL_CMD_SYMBOLS) || __check_panel_type (panel, PANEL_CMD_FUNCTION)) { return true; } @@ -922,33 +922,33 @@ bool __is_normal_cursor_type(RPanel *panel) { __check_panel_type (panel, PANEL_CMD_HEXDUMP)); } -void __set_cmd_str_cache(RCore *core, RPanel *p, char *s) { +void __set_cmd_str_cache(RzCore *core, RPanel *p, char *s) { free (p->model->cmdStrCache); p->model->cmdStrCache = s; __set_dcb (core, p); __set_pcb (p); } -void __set_decompiler_cache(RCore *core, char *s) { - RAnalFunction *func = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); +void __set_decompiler_cache(RzCore *core, char *s) { + RzAnalFunction *func = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (func) { if (core->panels_root->cur_pdc_cache) { - sdb_ptr_set (core->panels_root->cur_pdc_cache, r_num_as_string (NULL, func->addr, false), r_str_new (s), 0); + sdb_ptr_set (core->panels_root->cur_pdc_cache, rz_num_as_string (NULL, func->addr, false), rz_str_new (s), 0); } else { Sdb *sdb = sdb_new0 (); - const char *pdc_now = r_config_get (core->config, "cmd.pdc"); - sdb_ptr_set (sdb, r_num_as_string (NULL, func->addr, false), r_str_new (s), 0); + const char *pdc_now = rz_config_get (core->config, "cmd.pdc"); + sdb_ptr_set (sdb, rz_num_as_string (NULL, func->addr, false), rz_str_new (s), 0); core->panels_root->cur_pdc_cache = sdb; if (!sdb_exists (core->panels_root->pdc_caches, pdc_now)) { - sdb_ptr_set (core->panels_root->pdc_caches, r_str_new (pdc_now), sdb, 0); + sdb_ptr_set (core->panels_root->pdc_caches, rz_str_new (pdc_now), sdb, 0); } } } } -void __set_read_only(RCore *core, RPanel *p, char *s) { +void __set_read_only(RzCore *core, RPanel *p, char *s) { free (p->model->readOnly); - p->model->readOnly = r_str_new (s); + p->model->readOnly = rz_str_new (s); __set_dcb (core, p); __set_pcb (p); } @@ -968,7 +968,7 @@ void __set_geometry(RPanelPos *pos, int x, int y, int w, int h) { __set_size (pos, w, h); } -void __set_panel_addr(RCore *core, RPanel *panel, ut64 addr) { +void __set_panel_addr(RzCore *core, RPanel *panel, ut64 addr) { panel->model->addr = addr; } @@ -983,7 +983,7 @@ RPanel *__get_cur_panel(RPanels *panels) { return __get_panel (panels, panels->curnode); } -int __get_panel_idx_in_pos(RCore *core, int x, int y) { +int __get_panel_idx_in_pos(RzCore *core, int x, int y) { RPanels *panels = core->panels; int i = -1; for (i = 0; i < panels->n_panels; i++) { @@ -997,8 +997,8 @@ int __get_panel_idx_in_pos(RCore *core, int x, int y) { return i; } -void __handlePrompt(RCore *core, RPanels *panels) { - r_core_visual_prompt_input (core); +void __handlePrompt(RzCore *core, RPanels *panels) { + rz_core_visual_prompt_input (core); int i; for (i = 0; i < panels->n_panels; i++) { RPanel *p = __get_panel (panels, i); @@ -1009,7 +1009,7 @@ void __handlePrompt(RCore *core, RPanels *panels) { } } -void __panel_print(RCore *core, RConsCanvas *can, RPanel *panel, int color) { +void __panel_print(RzCore *core, RzConsCanvas *can, RPanel *panel, int color) { if (!can || !panel|| !panel->view->refresh) { return; } @@ -1017,7 +1017,7 @@ void __panel_print(RCore *core, RConsCanvas *can, RPanel *panel, int color) { return; } panel->view->refresh = panel->model->type == PANEL_TYPE_MENU; - r_cons_canvas_fill (can, panel->view->pos.x, panel->view->pos.y, panel->view->pos.w, panel->view->pos.h, ' '); + rz_cons_canvas_fill (can, panel->view->pos.x, panel->view->pos.y, panel->view->pos.w, panel->view->pos.h, ' '); if (panel->model->type == PANEL_TYPE_MENU) { __menu_panel_print (can, panel, panel->view->sx, panel->view->sy, panel->view->pos.w, panel->view->pos.h); } else { @@ -1027,24 +1027,24 @@ void __panel_print(RCore *core, RConsCanvas *can, RPanel *panel, int color) { w = R_MIN (panel->view->pos.w, can->w - panel->view->pos.x); h = R_MIN (panel->view->pos.h, can->h - panel->view->pos.y); if (color) { - r_cons_canvas_box (can, panel->view->pos.x, panel->view->pos.y, w, h, core->cons->context->pal.graph_box2); + rz_cons_canvas_box (can, panel->view->pos.x, panel->view->pos.y, w, h, core->cons->context->pal.graph_box2); } else { - r_cons_canvas_box (can, panel->view->pos.x, panel->view->pos.y, w, h, core->cons->context->pal.graph_box); + rz_cons_canvas_box (can, panel->view->pos.x, panel->view->pos.y, w, h, core->cons->context->pal.graph_box); } } -void __menu_panel_print(RConsCanvas *can, RPanel *panel, int x, int y, int w, int h) { - (void) r_cons_canvas_gotoxy (can, panel->view->pos.x + 2, panel->view->pos.y + 2); - char *text = r_str_ansi_crop (panel->model->title, x, y, w, h); +void __menu_panel_print(RzConsCanvas *can, RPanel *panel, int x, int y, int w, int h) { + (void) rz_cons_canvas_gotoxy (can, panel->view->pos.x + 2, panel->view->pos.y + 2); + char *text = rz_str_ansi_crop (panel->model->title, x, y, w, h); if (text) { - r_cons_canvas_write (can, text); + rz_cons_canvas_write (can, text); free (text); } else { - r_cons_canvas_write (can, panel->model->title); + rz_cons_canvas_write (can, panel->model->title); } } -void __update_help_contents(RCore *core, RPanel *panel) { +void __update_help_contents(RzCore *core, RPanel *panel) { char *read_only = panel->model->readOnly; char *text = NULL; int sx = panel->view->sx; @@ -1054,54 +1054,54 @@ void __update_help_contents(RCore *core, RPanel *panel) { int w = panel->view->pos.w; int h = panel->view->pos.h; RPanels *panels = core->panels; - RConsCanvas *can = panels->can; - (void) r_cons_canvas_gotoxy (can, x + 2, y + 2); + RzConsCanvas *can = panels->can; + (void) rz_cons_canvas_gotoxy (can, x + 2, y + 2); if (sx < 0) { - char *white = (char*)r_str_pad (' ', 128); + char *white = (char*)rz_str_pad (' ', 128); int idx = R_MIN (-sx, strlen (white) - 1); white[idx] = 0; - text = r_str_ansi_crop (read_only, + text = rz_str_ansi_crop (read_only, 0, sy, w + sx - 3, h - 2 + sy); - char *newText = r_str_prefix_all (text, white); + char *newText = rz_str_prefix_all (text, white); if (newText) { free (text); text = newText; } } else { - text = r_str_ansi_crop (read_only, + text = rz_str_ansi_crop (read_only, sx, sy, w + sx - 3, h - 2 + sy); } if (text) { - r_cons_canvas_write (can, text); + rz_cons_canvas_write (can, text); free (text); } } -void __update_help_title(RCore *core, RPanel *panel) { - RConsCanvas *can = core->panels->can; - RStrBuf *title = r_strbuf_new (NULL); - RStrBuf *cache_title = r_strbuf_new (NULL); +void __update_help_title(RzCore *core, RPanel *panel) { + RzConsCanvas *can = core->panels->can; + RStrBuf *title = rz_strbuf_new (NULL); + RStrBuf *cache_title = rz_strbuf_new (NULL); if (__check_if_cur_panel (core, panel)) { - r_strbuf_setf (title, "%s[X] %s"Color_RESET, + rz_strbuf_setf (title, "%s[X] %s"Color_RESET, core->cons->context->pal.graph_box2, panel->model->title); - r_strbuf_setf (cache_title, "%s[Cache] N/A"Color_RESET, + rz_strbuf_setf (cache_title, "%s[Cache] N/A"Color_RESET, core->cons->context->pal.graph_box2); } else { - r_strbuf_setf (title, "[X] %s ", panel->model->title); - r_strbuf_setf (cache_title, "[Cache] N/A"); + rz_strbuf_setf (title, "[X] %s ", panel->model->title); + rz_strbuf_setf (cache_title, "[Cache] N/A"); } - if (r_cons_canvas_gotoxy (can, panel->view->pos.x + 1, panel->view->pos.y + 1)) { - r_cons_canvas_write (can, r_strbuf_get (title)); + if (rz_cons_canvas_gotoxy (can, panel->view->pos.x + 1, panel->view->pos.y + 1)) { + rz_cons_canvas_write (can, rz_strbuf_get (title)); } - if (r_cons_canvas_gotoxy (can, panel->view->pos.x + panel->view->pos.w - - r_str_ansi_len (r_strbuf_get (cache_title)) - 2, panel->view->pos.y + 1)) { - r_cons_canvas_write (can, r_strbuf_get (cache_title)); + if (rz_cons_canvas_gotoxy (can, panel->view->pos.x + panel->view->pos.w + - rz_str_ansi_len (rz_strbuf_get (cache_title)) - 2, panel->view->pos.y + 1)) { + rz_cons_canvas_write (can, rz_strbuf_get (cache_title)); } - r_strbuf_free (cache_title); - r_strbuf_free (title); + rz_strbuf_free (cache_title); + rz_strbuf_free (title); } -void __update_panel_contents(RCore *core, RPanel *panel, const char *cmdstr) { +void __update_panel_contents(RzCore *core, RPanel *panel, const char *cmdstr) { bool b = __is_abnormal_cursor_type (core, panel) && core->print->cur_enabled; int sx = b ? -2 :panel->view->sx; int sy = R_MAX (panel->view->sy, 0); @@ -1118,70 +1118,70 @@ void __update_panel_contents(RCore *core, RPanel *panel, const char *cmdstr) { int graph_pad = __check_panel_type (panel, PANEL_CMD_GRAPH) ? 1 : 0; char *text = NULL; RPanels *panels = core->panels; - RConsCanvas *can = panels->can; - (void) r_cons_canvas_gotoxy (can, x + 2, y + 2); + RzConsCanvas *can = panels->can; + (void) rz_cons_canvas_gotoxy (can, x + 2, y + 2); if (sx < 0) { - char *white = (char*)r_str_pad (' ', 128); + char *white = (char*)rz_str_pad (' ', 128); int idx = R_MIN (-sx, strlen (white) - 1); white[idx] = 0; - text = r_str_ansi_crop (cmdstr, + text = rz_str_ansi_crop (cmdstr, 0, sy + graph_pad, w + sx - 3, h - 2 + sy); - char *newText = r_str_prefix_all (text, white); + char *newText = rz_str_prefix_all (text, white); if (newText) { free (text); text = newText; } } else { - text = r_str_ansi_crop (cmdstr, sx, sy + graph_pad, w + sx - 3, h - 2 + sy); + text = rz_str_ansi_crop (cmdstr, sx, sy + graph_pad, w + sx - 3, h - 2 + sy); } if (text) { - r_cons_canvas_write (can, text); + rz_cons_canvas_write (can, text); free (text); } if (b) { int sub = panel->view->curpos - panel->view->sy; - (void) r_cons_canvas_gotoxy (can, panel->view->pos.x + 2, panel->view->pos.y + 2 + sub); - r_cons_canvas_write (can, "*"); + (void) rz_cons_canvas_gotoxy (can, panel->view->pos.x + 2, panel->view->pos.y + 2 + sub); + rz_cons_canvas_write (can, "*"); } } -void __update_panel_title(RCore *core, RPanel *panel) { - RConsCanvas *can = core->panels->can; - RStrBuf *title = r_strbuf_new (NULL); - RStrBuf *cache_title = r_strbuf_new (NULL); +void __update_panel_title(RzCore *core, RPanel *panel) { + RzConsCanvas *can = core->panels->can; + RStrBuf *title = rz_strbuf_new (NULL); + RStrBuf *cache_title = rz_strbuf_new (NULL); char *cmd_title = __apply_filter_cmd (core, panel); if (__check_if_cur_panel (core, panel)) { if (!strcmp (panel->model->title, cmd_title)) { - r_strbuf_setf (title, "%s[X] %s"Color_RESET, core->cons->context->pal.graph_box2, panel->model->title); + rz_strbuf_setf (title, "%s[X] %s"Color_RESET, core->cons->context->pal.graph_box2, panel->model->title); } else { - r_strbuf_setf (title, "%s[X] %s (%s)"Color_RESET, core->cons->context->pal.graph_box2, panel->model->title, cmd_title); + rz_strbuf_setf (title, "%s[X] %s (%s)"Color_RESET, core->cons->context->pal.graph_box2, panel->model->title, cmd_title); } - r_strbuf_setf (cache_title, "%s[Cache] %s"Color_RESET, core->cons->context->pal.graph_box2, panel->model->cache ? "On" : "Off"); + rz_strbuf_setf (cache_title, "%s[Cache] %s"Color_RESET, core->cons->context->pal.graph_box2, panel->model->cache ? "On" : "Off"); } else { if (!strcmp (panel->model->title, cmd_title)) { - r_strbuf_setf (title, "[X] %s ", panel->model->title); + rz_strbuf_setf (title, "[X] %s ", panel->model->title); } else { - r_strbuf_setf (title, "[X] %s (%s) ", panel->model->title, cmd_title); + rz_strbuf_setf (title, "[X] %s (%s) ", panel->model->title, cmd_title); } - r_strbuf_setf (cache_title, "[Cache] %s", panel->model->cache ? "On" : "Off"); + rz_strbuf_setf (cache_title, "[Cache] %s", panel->model->cache ? "On" : "Off"); } - r_strbuf_slice (title, 0, panel->view->pos.w); - r_strbuf_slice (cache_title, 0, panel->view->pos.w); - if (r_cons_canvas_gotoxy (can, panel->view->pos.x + 1, panel->view->pos.y + 1)) { - r_cons_canvas_write (can, r_strbuf_get (title)); + rz_strbuf_slice (title, 0, panel->view->pos.w); + rz_strbuf_slice (cache_title, 0, panel->view->pos.w); + if (rz_cons_canvas_gotoxy (can, panel->view->pos.x + 1, panel->view->pos.y + 1)) { + rz_cons_canvas_write (can, rz_strbuf_get (title)); } - if (r_cons_canvas_gotoxy (can, panel->view->pos.x + panel->view->pos.w - r_str_ansi_len (r_strbuf_get (cache_title)) - 2, panel->view->pos.y + 1)) { - r_cons_canvas_write (can, r_strbuf_get (cache_title)); + if (rz_cons_canvas_gotoxy (can, panel->view->pos.x + panel->view->pos.w - rz_str_ansi_len (rz_strbuf_get (cache_title)) - 2, panel->view->pos.y + 1)) { + rz_cons_canvas_write (can, rz_strbuf_get (cache_title)); } - r_strbuf_free (title); - r_strbuf_free (cache_title); + rz_strbuf_free (title); + rz_strbuf_free (cache_title); free (cmd_title); } //TODO: make this a task -void __update_pdc_contents(RCore *core, RPanel *panel, char *cmdstr) { +void __update_pdc_contents(RzCore *core, RPanel *panel, char *cmdstr) { RPanels *panels = core->panels; - RConsCanvas *can = panels->can; + RzConsCanvas *can = panels->can; int sx = panel->view->sx; int sy = R_MAX (panel->view->sy, 0); int x = panel->view->pos.x; @@ -1190,28 +1190,28 @@ void __update_pdc_contents(RCore *core, RPanel *panel, char *cmdstr) { int h = panel->view->pos.h; char *text = NULL; - (void) r_cons_canvas_gotoxy (can, x + 2, y + 2); + (void) rz_cons_canvas_gotoxy (can, x + 2, y + 2); if (sx < 0) { - char *white = (char*)r_str_pad (' ', 128); + char *white = (char*)rz_str_pad (' ', 128); int idx = R_MIN (-sx, strlen (white) - 1); white[idx] = 0; - text = r_str_ansi_crop (cmdstr, 0, sy, w + sx - 3, h - 2 + sy); - char *newText = r_str_prefix_all (text, white); + text = rz_str_ansi_crop (cmdstr, 0, sy, w + sx - 3, h - 2 + sy); + char *newText = rz_str_prefix_all (text, white); if (newText) { free (text); text = newText; } } else { - text = r_str_ansi_crop (cmdstr, sx, sy, w + sx - 3, h - 2 + sy); + text = rz_str_ansi_crop (cmdstr, sx, sy, w + sx - 3, h - 2 + sy); } if (text) { - r_cons_canvas_write (can, text); + rz_cons_canvas_write (can, text); free (text); } } -void __default_panel_print(RCore *core, RPanel *panel) { +void __default_panel_print(RzCore *core, RPanel *panel) { bool o_cur = core->print->cur_enabled; core->print->cur_enabled = o_cur & (__get_cur_panel (core->panels) == panel); if (panel->model->readOnly) { @@ -1229,15 +1229,15 @@ void __reset_scroll_pos(RPanel *p) { p->view->sy = 0; } -char *__find_cmd_str_cache(RCore *core, RPanel* panel) { +char *__find_cmd_str_cache(RzCore *core, RPanel* panel) { if (panel->model->cache && panel->model->cmdStrCache) { return panel->model->cmdStrCache; } return NULL; } -char *__apply_filter_cmd(RCore *core, RPanel *panel) { - char *out = r_str_ndup (panel->model->cmd, strlen (panel->model->cmd) + 1024); +char *__apply_filter_cmd(RzCore *core, RPanel *panel) { + char *out = rz_str_ndup (panel->model->cmd, strlen (panel->model->cmd) + 1024); if (!panel->model->filter) { return out; } @@ -1254,14 +1254,14 @@ char *__apply_filter_cmd(RCore *core, RPanel *panel) { return out; } -char *__handle_cmd_str_cache(RCore *core, RPanel *panel, bool force_cache) { +char *__handle_cmd_str_cache(RzCore *core, RPanel *panel, bool force_cache) { char *cmd = __apply_filter_cmd (core, panel); bool b = core->print->cur_enabled && __get_cur_panel (core->panels) != panel; if (b) { core->print->cur_enabled = false; } - char *out = r_core_cmd_str (core, cmd); - r_cons_echo (NULL); + char *out = rz_core_cmd_str (core, cmd); + rz_cons_echo (NULL); if (force_cache) { panel->model->cache = true; } @@ -1285,10 +1285,10 @@ void __panel_all_clear(RPanels *panels) { RPanel *panel = NULL; for (i = 0; i < panels->n_panels; i++) { panel = __get_panel (panels, i); - r_cons_canvas_fill (panels->can, panel->view->pos.x, panel->view->pos.y, panel->view->pos.w, panel->view->pos.h, ' '); + rz_cons_canvas_fill (panels->can, panel->view->pos.x, panel->view->pos.y, panel->view->pos.w, panel->view->pos.h, ' '); } - r_cons_canvas_print (panels->can); - r_cons_flush (); + rz_cons_canvas_print (panels->can); + rz_cons_flush (); } void __panels_layout (RPanels *panels) { @@ -1299,7 +1299,7 @@ void __panels_layout (RPanels *panels) { void __layout_default(RPanels *panels) { RPanel *p0 = __get_panel (panels, 0); - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); if (panels->n_panels <= 1) { __set_geometry (&p0->view->pos, 0, 1, w, h - 1); return; @@ -1326,7 +1326,7 @@ void __layout_default(RPanels *panels) { } void __layout_equal_hor(RPanels *panels) { - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); int pw = w / panels->n_panels; int i, cw = 0; for (i = 0; i < panels->n_panels; i++) { @@ -1339,9 +1339,9 @@ void __layout_equal_hor(RPanels *panels) { } } -void __adjust_side_panels(RCore *core) { +void __adjust_side_panels(RzCore *core) { int i, h; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); RPanels *panels = core->panels; for (i = 0; i < panels->n_panels; i++) { RPanel *p = __get_panel (panels, i); @@ -1355,7 +1355,7 @@ void __adjust_side_panels(RCore *core) { } int __add_cmd_panel(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; if (!__check_panel_num (core)) { return 0; @@ -1368,7 +1368,7 @@ int __add_cmd_panel(void *user) { return 0; } int h; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); __adjust_side_panels (core); __insert_panel (core, 0, child->name, cmd); RPanel *p0 = __get_panel (panels, 0); @@ -1379,12 +1379,12 @@ int __add_cmd_panel(void *user) { return 0; } -void __add_help_panel(RCore *core) { +void __add_help_panel(RzCore *core) { //TODO: all these things done below are very hacky and refactoring needed RPanels *ps = core->panels; int h; const char *help = "Help"; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); __adjust_side_panels (core); __insert_panel (core, 0, help, help); RPanel *p0 = __get_panel (ps, 0); @@ -1392,24 +1392,24 @@ void __add_help_panel(RCore *core) { __set_curnode (core, 0); } -char *__load_cmdf(RCore *core, RPanel *p, char *input, char *str) { +char *__load_cmdf(RzCore *core, RPanel *p, char *input, char *str) { char *ret = NULL; char *res = __show_status_input (core, input); if (res) { - p->model->cmd = r_str_newf (str, res); - ret = r_core_cmd_str (core, p->model->cmd); + p->model->cmd = rz_str_newf (str, res); + ret = rz_core_cmd_str (core, p->model->cmd); free (res); } return ret; } -int __add_cmdf_panel(RCore *core, char *input, char *str) { +int __add_cmdf_panel(RzCore *core, char *input, char *str) { RPanels *panels = core->panels; if (!__check_panel_num (core)) { return 0; } int h; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; @@ -1423,7 +1423,7 @@ int __add_cmdf_panel(RCore *core, char *input, char *str) { return 0; } -void __split_panel_vertical(RCore *core, RPanel *p, const char *name, const char *cmd) { +void __split_panel_vertical(RzCore *core, RPanel *p, const char *name, const char *cmd) { RPanels *panels = core->panels; if (!__check_panel_num (core)) { return; @@ -1438,7 +1438,7 @@ void __split_panel_vertical(RCore *core, RPanel *p, const char *name, const char __set_refresh_all (core, false, true); } -void __split_panel_horizontal(RCore *core, RPanel *p, const char *name, const char *cmd) { +void __split_panel_horizontal(RzCore *core, RPanel *p, const char *name, const char *cmd) { RPanels *panels = core->panels; if (!__check_panel_num (core)) { return; @@ -1454,14 +1454,14 @@ void __split_panel_horizontal(RCore *core, RPanel *p, const char *name, const ch __set_refresh_all (core, false, true); } -void __panels_layout_refresh(RCore *core) { +void __panels_layout_refresh(RzCore *core) { __del_invalid_panels (core); __check_edge (core); __panels_check_stackbase (core); __panels_refresh (core); } -void __insert_panel(RCore *core, int n, const char *name, const char *cmd) { +void __insert_panel(RzCore *core, int n, const char *name, const char *cmd) { RPanels *panels = core->panels; if (panels->n_panels + 1 > PANEL_NUM_LIMIT) { return; @@ -1476,7 +1476,7 @@ void __insert_panel(RCore *core, int n, const char *name, const char *cmd) { __init_panel_param (core, panel[n], name, cmd); } -void __set_cursor(RCore *core, bool cur) { +void __set_cursor(RzCore *core, bool cur) { RPanel *p = __get_cur_panel (core->panels); RPrint *print = core->print; print->cur_enabled = cur; @@ -1491,7 +1491,7 @@ void __set_cursor(RCore *core, bool cur) { print->col = print->cur_enabled ? 1: 0; } -void __activate_cursor(RCore *core) { +void __activate_cursor(RzCore *core) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); bool normal = __is_normal_cursor_type (cur); @@ -1517,11 +1517,11 @@ void __activate_cursor(RCore *core) { } } -ut64 __parse_string_on_cursor(RCore *core, RPanel *panel, int idx) { +ut64 __parse_string_on_cursor(RzCore *core, RPanel *panel, int idx) { if (!panel->model->cmdStrCache) { return UT64_MAX; } - RStrBuf *buf = r_strbuf_new (NULL); + RStrBuf *buf = rz_strbuf_new (NULL); char *s = panel->model->cmdStrCache; int l = 0; while (R_STR_ISNOTEMPTY (s) && l != idx) { @@ -1532,22 +1532,22 @@ ut64 __parse_string_on_cursor(RCore *core, RPanel *panel, int idx) { } while (R_STR_ISNOTEMPTY (s) && R_STR_ISNOTEMPTY (s + 1)) { if (*s == '0' && *(s + 1) == 'x') { - r_strbuf_append_n (buf, s, 2); + rz_strbuf_append_n (buf, s, 2); while (*s != ' ') { - r_strbuf_append_n (buf, s, 1); + rz_strbuf_append_n (buf, s, 1); s++; } - ut64 ret = r_num_math (core->num, r_strbuf_get (buf)); - r_strbuf_free (buf); + ut64 ret = rz_num_math (core->num, rz_strbuf_get (buf)); + rz_strbuf_free (buf); return ret; } s++; } - r_strbuf_free (buf); + rz_strbuf_free (buf); return UT64_MAX; } -void __cursor_left(RCore *core) { +void __cursor_left(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); RPrint *print = core->print; if (__check_panel_type (cur, PANEL_CMD_REGISTERS) @@ -1564,7 +1564,7 @@ void __cursor_left(RCore *core) { } } -void __cursor_right(RCore *core) { +void __cursor_right(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); RPrint *print = core->print; if (__check_panel_type (cur, PANEL_CMD_STACK) && print->cur >= 15) { @@ -1582,10 +1582,10 @@ void __cursor_right(RCore *core) { } } -void __cursor_up(RCore *core) { +void __cursor_up(RzCore *core) { RPrint *print = core->print; ut64 addr, oaddr = core->offset + print->cur; - if (r_core_prevop_addr (core, oaddr, 1, &addr)) { + if (rz_core_prevop_addr (core, oaddr, 1, &addr)) { const int delta = oaddr - addr; print->cur -= delta; } else { @@ -1594,48 +1594,48 @@ void __cursor_up(RCore *core) { __fix_cursor_up (core); } -void __cursor_down(RCore *core) { +void __cursor_down(RzCore *core) { RPrint *print = core->print; - RAnalOp *aop = r_core_anal_op (core, core->offset + print->cur, R_ANAL_OP_MASK_BASIC); + RzAnalOp *aop = rz_core_anal_op (core, core->offset + print->cur, R_ANAL_OP_MASK_BASIC); if (aop) { print->cur += aop->size; - r_anal_op_free (aop); + rz_anal_op_free (aop); } else { print->cur += 4; } __fix_cursor_down (core); } -void __fix_cursor_up(RCore *core) { +void __fix_cursor_up(RzCore *core) { RPrint *print = core->print; if (print->cur >= 0) { return; } - int sz = r_core_visual_prevopsz (core, core->offset + print->cur); + int sz = rz_core_visual_prevopsz (core, core->offset + print->cur); if (sz < 1) { sz = 1; } - r_core_seek_delta (core, -sz); + rz_core_seek_delta (core, -sz); print->cur += sz; if (print->ocur != -1) { print->ocur += sz; } } -void __fix_cursor_down(RCore *core) { +void __fix_cursor_down(RzCore *core) { RPrint *print = core->print; bool cur_is_visible = core->offset + print->cur + 32 < print->screen_bounds; if (!cur_is_visible) { int i = 0; //XXX: ugly hack for (i = 0; i < 2; i++) { - RAsmOp op; - int sz = r_asm_disassemble (core->rasm, + RzAsmOp op; + int sz = rz_asm_disassemble (core->rasm, &op, core->block, 32); if (sz < 1) { sz = 1; } - r_core_seek_delta (core, sz); + rz_core_seek_delta (core, sz); print->cur = R_MAX (print->cur - sz, 0); if (print->ocur != -1) { print->ocur = R_MAX (print->ocur - sz, 0); @@ -1644,9 +1644,9 @@ void __fix_cursor_down(RCore *core) { } } -bool __handle_zoom_mode(RCore *core, const int key) { +bool __handle_zoom_mode(RzCore *core, const int key) { RPanels *panels = core->panels; - r_cons_switchbuf (false); + rz_cons_switchbuf (false); switch (key) { case 'Q': case 'q': @@ -1720,23 +1720,23 @@ bool __handle_zoom_mode(RCore *core, const int key) { return true; } -void __handleComment(RCore *core) { +void __handleComment(RzCore *core) { RPanel *p = __get_cur_panel (core->panels); if (!__check_panel_type (p, PANEL_CMD_DISASSEMBLY)) { return; } char buf[4095]; int i; - r_line_set_prompt ("[Comment]> "); + rz_line_set_prompt ("[Comment]> "); strcpy (buf, "\"CC "); i = strlen (buf); - if (r_cons_fgets (buf + i, sizeof (buf) - i, 0, NULL) > 0) { + if (rz_cons_fgets (buf + i, sizeof (buf) - i, 0, NULL) > 0) { ut64 addr, orig; addr = orig = core->offset; if (core->print->cur_enabled) { addr += core->print->cur; - r_core_seek (core, addr, false); - r_core_cmdf (core, "s 0x%"PFMT64x, addr); + rz_core_seek (core, addr, false); + rz_core_cmdf (core, "s 0x%"PFMT64x, addr); } if (!strcmp (buf + i, "-")) { strcpy (buf, "CC-"); @@ -1768,18 +1768,18 @@ void __handleComment(RCore *core) { } free (duped); } - r_core_cmd (core, buf, 1); + rz_core_cmd (core, buf, 1); if (core->print->cur_enabled) { - r_core_seek (core, orig, true); + rz_core_seek (core, orig, true); } } __set_refresh_by_type (core, p->model->cmd, true); } -bool __handle_window_mode(RCore *core, const int key) { +bool __handle_window_mode(RzCore *core, const int key) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); - r_cons_switchbuf (false); + rz_cons_switchbuf (false); switch (key) { case 'Q': case 'q': @@ -1829,19 +1829,19 @@ bool __handle_window_mode(RCore *core, const int key) { } break; case 'H': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); __resize_panel_left (panels); break; case 'L': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); __resize_panel_right (panels); break; case 'J': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); __resize_panel_down (panels); break; case 'K': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); __resize_panel_up (panels); break; case 'n': @@ -1871,7 +1871,7 @@ bool __handle_window_mode(RCore *core, const int key) { return true; } -bool __handle_cursor_mode(RCore *core, const int key) { +bool __handle_cursor_mode(RzCore *core, const int key) { RPanel *cur = __get_cur_panel (core->panels); RPrint *print = core->print; char *db_val; @@ -1897,20 +1897,20 @@ bool __handle_cursor_mode(RCore *core, const int key) { break; case ']': if (__check_panel_type (cur, PANEL_CMD_HEXDUMP)) { - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") + 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") + 1); } else { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); - r_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); } cur->view->refresh = true; break; case '[': if (__check_panel_type (cur, PANEL_CMD_HEXDUMP)) { - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") - 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") - 1); } else { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); if (cmtcol > 2) { - r_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); } } cur->view->refresh = true; @@ -1931,7 +1931,7 @@ bool __handle_cursor_mode(RCore *core, const int key) { break; case '*': if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { - r_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + print->cur); + rz_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + print->cur); __set_panel_addr (core, cur, core->offset + print->cur); } break; @@ -1961,7 +1961,7 @@ bool __handle_cursor_mode(RCore *core, const int key) { return true; } -bool __handle_mouse(RCore *core, RPanel *panel, int *key) { +bool __handle_mouse(RzCore *core, RPanel *panel, int *key) { const int MENU_Y = 1; RPanels *panels = core->panels; if (__drag_and_resize (core)) { @@ -1969,7 +1969,7 @@ bool __handle_mouse(RCore *core, RPanel *panel, int *key) { } if (!*key) { int x, y; - if (r_cons_get_click (&x, &y)) { + if (rz_cons_get_click (&x, &y)) { if (y == MENU_Y && __handle_mouse_on_top (core, x, y)) { return true; } @@ -1993,7 +1993,7 @@ bool __handle_mouse(RCore *core, RPanel *panel, int *key) { if (__handle_mouse_on_panel (core, panel, x, y, key)) { return true; } - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); if (y == h) { RPanel *p = __get_cur_panel (panels); __split_panel_horizontal (core, p, p->model->title, p->model->cmd); @@ -2012,7 +2012,7 @@ bool __handle_mouse(RCore *core, RPanel *panel, int *key) { return false; } -bool __handle_mouse_on_top (RCore *core, int x, int y) { +bool __handle_mouse_on_top (RzCore *core, int x, int y) { RPanels *panels = core->panels; char *word = get_word_from_canvas (core, panels, x, y); int i; @@ -2044,7 +2044,7 @@ bool __handle_mouse_on_top (RCore *core, int x, int y) { return false; } -static bool __handle_mouse_on_X(RCore *core, int x, int y) { +static bool __handle_mouse_on_X(RzCore *core, int x, int y) { RPanels *panels = core->panels; const int idx = __get_panel_idx_in_pos (core, x, y); char *word = get_word_from_canvas (core, panels, x, y); @@ -2073,10 +2073,10 @@ static bool __handle_mouse_on_X(RCore *core, int x, int y) { return false; } -static bool __handle_mouse_on_panel(RCore *core, RPanel *panel, int x, int y, int *key) { +static bool __handle_mouse_on_panel(RzCore *core, RPanel *panel, int x, int y, int *key) { RPanels *panels = core->panels; int h; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); const int idx = __get_panel_idx_in_pos (core, x, y); char *word = get_word_from_canvas (core, panels, x, y); if (idx == -1) { @@ -2086,18 +2086,18 @@ static bool __handle_mouse_on_panel(RCore *core, RPanel *panel, int x, int y, in __set_refresh_all (core, true, true); RPanel *ppos = __get_panel(panels, idx); if (word) { - const ut64 addr = r_num_math (core->num, word); + const ut64 addr = rz_num_math (core->num, word); if (__check_panel_type (panel, PANEL_CMD_FUNCTION) && __check_if_addr (word, strlen (word))) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); __set_addr_by_type (core, PANEL_CMD_DISASSEMBLY, addr); } - r_flag_set (core->flags, "panel.addr", addr, 1); - r_config_set (core->config, "scr.highlight", word); + rz_flag_set (core->flags, "panel.addr", addr, 1); + rz_config_set (core->config, "scr.highlight", word); #if 1 // TODO implement sync { - ut64 addr = r_num_math (core->num, word); + ut64 addr = rz_num_math (core->num, word); if (addr > 0) { // __set_panel_addr (core, cur, addr); __seek_all (core, addr); @@ -2113,7 +2113,7 @@ static bool __handle_mouse_on_panel(RCore *core, RPanel *panel, int x, int y, in return true; } -void __handle_mouse_on_menu(RCore *core, int x, int y) { +void __handle_mouse_on_menu(RzCore *core, int x, int y) { RPanels *panels = core->panels; char *word = get_word_from_canvas_for_menu (core, panels, x, y); RPanelsMenu *menu = panels->panels_menu; @@ -2137,11 +2137,11 @@ void __handle_mouse_on_menu(RCore *core, int x, int y) { free (word); } -bool __drag_and_resize(RCore *core) { +bool __drag_and_resize(RzCore *core) { RPanels *panels = core->panels; if (panels->mouse_on_edge_x || panels->mouse_on_edge_y) { int x, y; - if (r_cons_get_click (&x, &y)) { + if (rz_cons_get_click (&x, &y)) { if (panels->mouse_on_edge_x) { __update_edge_x (core, x - panels->mouse_orig_x); } @@ -2156,7 +2156,7 @@ bool __drag_and_resize(RCore *core) { return false; } -void __jmp_to_cursor_addr(RCore *core, RPanel *panel) { +void __jmp_to_cursor_addr(RzCore *core, RPanel *panel) { ut64 addr = __parse_string_on_cursor (core, panel, panel->view->curpos); if (addr == UT64_MAX) { return; @@ -2165,18 +2165,18 @@ void __jmp_to_cursor_addr(RCore *core, RPanel *panel) { __update_disassembly_or_open (core); } -void __cursor_del_breakpoints(RCore *core, RPanel *panel) { - RListIter *iter; +void __cursor_del_breakpoints(RzCore *core, RPanel *panel) { + RzListIter *iter; RBreakpointItem *b; int i = 0; - r_list_foreach (core->dbg->bp->bps, iter, b) { + rz_list_foreach (core->dbg->bp->bps, iter, b) { if (panel->view->curpos == i++) { - r_bp_del (core->dbg->bp, b->addr); + rz_bp_del (core->dbg->bp, b->addr); } } } -void __handle_visual_mark(RCore *core) { +void __handle_visual_mark(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); if (!__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { return; @@ -2187,37 +2187,37 @@ void __handle_visual_mark(RCore *core) { __add_visual_mark (core); break; case '-': - r_cons_gotoxy (0, 0); - if (r_core_visual_mark_dump (core)) { - r_cons_printf (R_CONS_CLEAR_LINE"Remove a shortcut key from the list\n"); - r_cons_flush (); - int ch = r_cons_readchar (); - r_core_visual_mark_del (core, ch); + rz_cons_gotoxy (0, 0); + if (rz_core_visual_mark_dump (core)) { + rz_cons_printf (R_CONS_CLEAR_LINE"Remove a shortcut key from the list\n"); + rz_cons_flush (); + int ch = rz_cons_readchar (); + rz_core_visual_mark_del (core, ch); } break; case '\'': - r_cons_gotoxy (0, 0); - if (r_core_visual_mark_dump (core)) { - r_cons_flush (); - int ch = r_cons_readchar (); - r_core_visual_mark_seek (core, ch); + rz_cons_gotoxy (0, 0); + if (rz_core_visual_mark_dump (core)) { + rz_cons_flush (); + int ch = rz_cons_readchar (); + rz_core_visual_mark_seek (core, ch); __set_panel_addr (core, cur, core->offset); } } return; } -void __handle_refs(RCore *core, RPanel *panel, ut64 tmp) { +void __handle_refs(RzCore *core, RPanel *panel, ut64 tmp) { if (tmp != UT64_MAX) { core->offset = tmp; } int key = __show_status(core, "xrefs:x refs:X "); switch (key) { case 'x': - (void)r_core_visual_refs (core, true, false); + (void)rz_core_visual_refs (core, true, false); break; case 'X': - (void)r_core_visual_refs (core, false, false); + (void)rz_core_visual_refs (core, false, false); break; default: break; @@ -2229,11 +2229,11 @@ void __handle_refs(RCore *core, RPanel *panel, ut64 tmp) { __set_addr_by_type (core, PANEL_CMD_DISASSEMBLY, core->offset); } -void __add_visual_mark(RCore *core) { - char *msg = r_str_newf (R_CONS_CLEAR_LINE"Set shortcut key for 0x%"PFMT64x": ", core->offset); +void __add_visual_mark(RzCore *core) { + char *msg = rz_str_newf (R_CONS_CLEAR_LINE"Set shortcut key for 0x%"PFMT64x": ", core->offset); int ch = __show_status (core, msg); free (msg); - r_core_visual_mark (core, ch); + rz_core_visual_mark (core, ch); } void __resize_panel_left(RPanels *panels) { @@ -2494,11 +2494,11 @@ beach: free (targets4); } -void __move_panel_to_dir(RCore *core, RPanel *panel, int src) { +void __move_panel_to_dir(RzCore *core, RPanel *panel, int src) { RPanels *panels = core->panels; __dismantle_panel (panels, panel); int key = __show_status (core, "Move the current panel to direction (h/j/k/l): "); - key = r_cons_arrow_to_hjkl (key); + key = rz_cons_arrow_to_hjkl (key); __set_refresh_all (core, false, true); switch (key) { case 'h': @@ -2518,11 +2518,11 @@ void __move_panel_to_dir(RCore *core, RPanel *panel, int src) { } } -void __move_panel_to_left(RCore *core, RPanel *panel, int src) { +void __move_panel_to_left(RzCore *core, RPanel *panel, int src) { RPanels *panels = core->panels; __shrink_panels_backward (core, src); panels->panel[0] = panel; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); int p_w = w - panels->columnWidth; p_w /= 2; int new_w = w - p_w; @@ -2538,11 +2538,11 @@ void __move_panel_to_left(RCore *core, RPanel *panel, int src) { __set_curnode (core, 0); } -void __move_panel_to_right(RCore *core, RPanel *panel, int src) { +void __move_panel_to_right(RzCore *core, RPanel *panel, int src) { RPanels *panels = core->panels; __shrink_panels_forward (core, src); panels->panel[panels->n_panels - 1] = panel; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); int p_w = w - panels->columnWidth; p_w /= 2; int p_x = w - p_w; @@ -2559,11 +2559,11 @@ void __move_panel_to_right(RCore *core, RPanel *panel, int src) { __set_curnode (core, panels->n_panels - 1); } -void __move_panel_to_up(RCore *core, RPanel *panel, int src) { +void __move_panel_to_up(RzCore *core, RPanel *panel, int src) { RPanels *panels = core->panels; __shrink_panels_backward (core, src); panels->panel[0] = panel; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); int p_h = h / 2; int new_h = h - p_h; __set_geometry (&panel->view->pos, 0, 1, w, p_h - 1); @@ -2578,11 +2578,11 @@ void __move_panel_to_up(RCore *core, RPanel *panel, int src) { __set_curnode (core, 0); } -void __move_panel_to_down(RCore *core, RPanel *panel, int src) { +void __move_panel_to_down(RzCore *core, RPanel *panel, int src) { RPanels *panels = core->panels; __shrink_panels_forward (core, src); panels->panel[panels->n_panels - 1] = panel; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); int p_h = h / 2; int new_h = h - p_h; __set_geometry (&panel->view->pos, 0, new_h, w, p_h); @@ -2597,21 +2597,21 @@ void __move_panel_to_down(RCore *core, RPanel *panel, int src) { __set_curnode (core, panels->n_panels - 1); } -void __fix_layout (RCore *core) { +void __fix_layout (RzCore *core) { __fix_layout_w (core); __fix_layout_h (core); } -void __fix_layout_w (RCore *core) { +void __fix_layout_w (RzCore *core) { RPanels *panels = core->panels; - RList *list = r_list_new (); + RzList *list = rz_list_new (); int i = 0; for (; i < panels->n_panels - 1; i++) { RPanel *p = __get_panel (panels, i); int64_t t = p->view->pos.x + p->view->pos.w; - r_list_append (list, (void *)(t)); + rz_list_append (list, (void *)(t)); } - RListIter *iter; + RzListIter *iter; for (i = 0; i < panels->n_panels; i++) { RPanel *p = __get_panel (panels, i); int tx = p->view->pos.x; @@ -2622,7 +2622,7 @@ void __fix_layout_w (RCore *core) { int target_num = INT8_MAX; bool found = false; void *num = NULL; - r_list_foreach (list, iter, num) { + rz_list_foreach (list, iter, num) { if ((int64_t)num - 1 == tx) { found = true; break; @@ -2641,18 +2641,18 @@ void __fix_layout_w (RCore *core) { } } -void __fix_layout_h (RCore *core) { +void __fix_layout_h (RzCore *core) { RPanels *panels = core->panels; - RList *list = r_list_new (); + RzList *list = rz_list_new (); int h; - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); int i = 0; for (; i < panels->n_panels - 1; i++) { RPanel *p = __get_panel (panels, i); int64_t t = p->view->pos.y + p->view->pos.h; - r_list_append (list, (void *)(t)); + rz_list_append (list, (void *)(t)); } - RListIter *iter; + RzListIter *iter; for (i = 0; i < panels->n_panels; i++) { RPanel *p = __get_panel (panels, i); int ty = p->view->pos.y; @@ -2664,7 +2664,7 @@ void __fix_layout_h (RCore *core) { int target_num = INT8_MAX; bool found = false; void *num = NULL; - r_list_foreach (list, iter, num) { + rz_list_foreach (list, iter, num) { if ((int64_t)num - 1 == ty) { found = true; break; @@ -2681,7 +2681,7 @@ void __fix_layout_h (RCore *core) { p->view->pos.h += t; } } - r_list_free (list); + rz_list_free (list); } void __resize_panel_down(RPanels *panels) { @@ -2770,7 +2770,7 @@ beach: free (targets4); } -void __del_panel(RCore *core, int pi) { +void __del_panel(RzCore *core, int pi) { int i; RPanels *panels = core->panels; RPanel *tmp = __get_panel (panels, pi); @@ -2785,7 +2785,7 @@ void __del_panel(RCore *core, int pi) { __set_curnode (core, panels->curnode); } -void __dismantle_del_panel(RCore *core, RPanel *p, int pi) { +void __dismantle_del_panel(RzCore *core, RPanel *p, int pi) { RPanels *panels = core->panels; if (panels->n_panels <= 1) { return; @@ -2794,7 +2794,7 @@ void __dismantle_del_panel(RCore *core, RPanel *p, int pi) { __del_panel (core, pi); } -void __del_invalid_panels(RCore *core) { +void __del_invalid_panels(RzCore *core) { RPanels *panels = core->panels; int i; for (i = 1; i < panels->n_panels; i++) { @@ -2925,13 +2925,13 @@ void __dismantle_panel(RPanels *ps, RPanel *p) { } } -void __replace_cmd(RCore *core, const char *title, const char *cmd) { +void __replace_cmd(RzCore *core, const char *title, const char *cmd) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); __free_panel_model (cur); cur->model = R_NEW0 (RPanelModel); - cur->model->title = r_str_dup (cur->model->title, title); - cur->model->cmd = r_str_dup (cur->model->cmd, cmd); + cur->model->title = rz_str_dup (cur->model->title, title); + cur->model->cmd = rz_str_dup (cur->model->cmd, cmd); __set_cmd_str_cache (core, cur, NULL); __set_panel_addr (core, cur, core->offset); cur->model->type = PANEL_TYPE_DEFAULT; @@ -2951,38 +2951,38 @@ void __swap_panels(RPanels *panels, int p0, int p1) { panel1->model = tmp; } -void __call_visual_graph(RCore *core) { +void __call_visual_graph(RzCore *core) { if (__check_func (core)) { RPanels *panels = core->panels; - r_cons_canvas_free (panels->can); + rz_cons_canvas_free (panels->can); panels->can = NULL; - int ocolor = r_config_get_i (core->config, "scr.color"); + int ocolor = rz_config_get_i (core->config, "scr.color"); - r_core_visual_graph (core, NULL, NULL, true); - r_config_set_i (core->config, "scr.color", ocolor); + rz_core_visual_graph (core, NULL, NULL, true); + rz_config_set_i (core->config, "scr.color", ocolor); - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); panels->can = __create_new_canvas (core, w, h); } } -bool __check_func(RCore *core) { - RAnalFunction *fun = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); +bool __check_func(RzCore *core) { + RzAnalFunction *fun = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (!fun) { - r_cons_message ("Not in a function. Type 'df' to define it here"); + rz_cons_message ("Not in a function. Type 'df' to define it here"); return false; } - if (r_list_empty (fun->bbs)) { - r_cons_message ("No basic blocks in this function. You may want to use 'afb+'."); + if (rz_list_empty (fun->bbs)) { + rz_cons_message ("No basic blocks in this function. You may want to use 'afb+'."); return false; } return true; } -bool __check_func_diff(RCore *core, RPanel *p) { - RAnalFunction *func = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); +bool __check_func_diff(RzCore *core, RPanel *p) { + RzAnalFunction *func = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (!func) { if (R_STR_ISEMPTY (p->model->funcName)) { return false; @@ -2991,13 +2991,13 @@ bool __check_func_diff(RCore *core, RPanel *p) { return true; } if (!p->model->funcName || strcmp (p->model->funcName, func->name)) { - p->model->funcName = r_str_dup (p->model->funcName, func->name); + p->model->funcName = rz_str_dup (p->model->funcName, func->name); return true; } return false; } -void __seek_all(RCore *core, ut64 addr) { +void __seek_all(RzCore *core, ut64 addr) { RPanels *panels = core->panels; int i; for (i = 0; i < panels->n_panels; i++) { @@ -3006,7 +3006,7 @@ void __seek_all(RCore *core, ut64 addr) { } } -void __set_refresh_all(RCore *core, bool clearCache, bool force_refresh) { +void __set_refresh_all(RzCore *core, bool clearCache, bool force_refresh) { RPanels *panels = core->panels; int i; for (i = 0; i < panels->n_panels; i++) { @@ -3021,7 +3021,7 @@ void __set_refresh_all(RCore *core, bool clearCache, bool force_refresh) { } } -void __set_refresh_by_type(RCore *core, const char *cmd, bool clearCache) { +void __set_refresh_by_type(RzCore *core, const char *cmd, bool clearCache) { RPanels *panels = core->panels; int i; for (i = 0; i < panels->n_panels; i++) { @@ -3036,7 +3036,7 @@ void __set_refresh_by_type(RCore *core, const char *cmd, bool clearCache) { } } -void __set_addr_by_type(RCore *core, const char *cmd, ut64 addr) { +void __set_addr_by_type(RzCore *core, const char *cmd, ut64 addr) { RPanels *panels = core->panels; int i; for (i = 0; i < panels->n_panels; i++) { @@ -3048,19 +3048,19 @@ void __set_addr_by_type(RCore *core, const char *cmd, ut64 addr) { } } -RConsCanvas *__create_new_canvas(RCore *core, int w, int h) { - RConsCanvas *can = r_cons_canvas_new (w, h); +RzConsCanvas *__create_new_canvas(RzCore *core, int w, int h) { + RzConsCanvas *can = rz_cons_canvas_new (w, h); if (!can) { - eprintf ("Cannot create RCons.canvas context\n"); + eprintf ("Cannot create RzCons.canvas context\n"); return false; } - r_cons_canvas_fill (can, 0, 0, w, h, ' '); - can->linemode = r_config_get_i (core->config, "graph.linemode"); - can->color = r_config_get_i (core->config, "scr.color"); + rz_cons_canvas_fill (can, 0, 0, w, h, ' '); + can->linemode = rz_config_get_i (core->config, "graph.linemode"); + can->color = rz_config_get_i (core->config, "scr.color"); return can; } -bool __check_panel_num(RCore *core) { +bool __check_panel_num(RzCore *core) { RPanels *panels = core->panels; if (panels->n_panels + 1 > PANEL_NUM_LIMIT) { const char *msg = "panel limit exceeded."; @@ -3070,7 +3070,7 @@ bool __check_panel_num(RCore *core) { return true; } -void __init_panel_param(RCore *core, RPanel *p, const char *title, const char *cmd) { +void __init_panel_param(RzCore *core, RPanel *p, const char *title, const char *cmd) { RPanelModel *m = p->model; RPanelView *v = p->view; m->type = PANEL_TYPE_DEFAULT; @@ -3084,28 +3084,28 @@ void __init_panel_param(RCore *core, RPanel *p, const char *title, const char *c v->refresh = true; v->edge = 0; if (title) { - m->title = r_str_dup (m->title, title); + m->title = rz_str_dup (m->title, title); if (cmd) { - m->cmd = r_str_dup (m->cmd, cmd); + m->cmd = rz_str_dup (m->cmd, cmd); } else { - m->cmd = r_str_dup (m->cmd, ""); + m->cmd = rz_str_dup (m->cmd, ""); } } else if (cmd) { - m->title = r_str_dup (m->title, cmd); - m->cmd = r_str_dup (m->cmd, cmd); + m->title = rz_str_dup (m->title, cmd); + m->cmd = rz_str_dup (m->cmd, cmd); } else { - m->title = r_str_dup (m->title, ""); - m->cmd = r_str_dup (m->cmd, ""); + m->title = rz_str_dup (m->title, ""); + m->cmd = rz_str_dup (m->cmd, ""); } __set_pcb (p); if (R_STR_ISNOTEMPTY (m->cmd)) { __set_dcb (core, p); __set_rcb (core->panels, p); if (__check_panel_type (p, PANEL_CMD_STACK)) { - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); - const ut64 stackbase = r_reg_getv (core->anal->reg, sp); + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); + const ut64 stackbase = rz_reg_getv (core->anal->reg, sp); m->baseAddr = stackbase; - __set_panel_addr (core, p, stackbase - r_config_get_i (core->config, "stack.delta")); + __set_panel_addr (core, p, stackbase - rz_config_get_i (core->config, "stack.delta")); } } core->panels->n_panels++; @@ -3113,7 +3113,7 @@ void __init_panel_param(RCore *core, RPanel *p, const char *title, const char *c return; } -void __set_dcb(RCore *core, RPanel *p) { +void __set_dcb(RzCore *core, RPanel *p) { if (__is_abnormal_cursor_type (core, p)) { p->model->cache = true; p->model->directionCb = __direction_panels_cursor_cb; @@ -3194,35 +3194,35 @@ void __set_pcb(RPanel *p) { } int __open_file_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; core->cons->line->prompt_type = R_LINE_PROMPT_FILE; - r_line_set_hist_callback (core->cons->line, &__file_history_up, &__file_history_down); + rz_line_set_hist_callback (core->cons->line, &__file_history_up, &__file_history_down); __add_cmdf_panel (core, "open file: ", "o %s"); core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT; - r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); return 0; } int __rw_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmd (core, "oo+", 0); + RzCore *core = (RzCore *)user; + rz_core_cmd (core, "oo+", 0); return 0; } int __debugger_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmd (core, "oo", 0); + RzCore *core = (RzCore *)user; + rz_core_cmd (core, "oo", 0); return 0; } int __settings_decompiler_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanelsRoot *root = core->panels_root; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; const char *pdc_next = child->name; - const char *pdc_now = r_config_get (core->config, "cmd.pdc"); + const char *pdc_now = rz_config_get (core->config, "cmd.pdc"); if (!strcmp (pdc_next, pdc_now)) { return 0; } @@ -3234,12 +3234,12 @@ int __settings_decompiler_cb(void *user) { root->cur_pdc_cache = sdb; } } - r_config_set (core->config, "cmd.pdc", pdc_next); + rz_config_set (core->config, "cmd.pdc", pdc_next); int j = 0; for (j = 0; j < core->panels->n_panels; j++) { RPanel *panel = __get_panel (core->panels, j); if (!strncmp (panel->model->cmd, "pdc", 3)) { - char *cmdstr = r_core_cmd_strf (core, "pdc@0x%08"PFMT64x, panel->model->addr); + char *cmdstr = rz_core_cmd_strf (core, "pdc@0x%08"PFMT64x, panel->model->addr); __update_panel_contents (core, panel, cmdstr); __reset_scroll_pos (panel); free (cmdstr); @@ -3251,45 +3251,45 @@ int __settings_decompiler_cb(void *user) { } int __show_all_decompiler_cb(void *user) { - RCore *core = (RCore *)user; - RAnalFunction *func = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzCore *core = (RzCore *)user; + RzAnalFunction *func = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (!func) { return 0; } RPanelsRoot *root = core->panels_root; - const char *pdc_now = r_config_get (core->config, "cmd.pdc"); - char *opts = r_core_cmd_str (core, "e cmd.pdc=?"); - RList *optl = r_str_split_list (opts, "\n", 0); - RListIter *iter; + const char *pdc_now = rz_config_get (core->config, "cmd.pdc"); + char *opts = rz_core_cmd_str (core, "e cmd.pdc=?"); + RzList *optl = rz_str_split_list (opts, "\n", 0); + RzListIter *iter; char *opt; int i = 0; __handle_tab_new (core); RPanels *panels = __get_panels (root, root->n_panels - 1); - r_list_foreach (optl, iter, opt) { + rz_list_foreach (optl, iter, opt) { if (R_STR_ISEMPTY (opt)) { continue; } - r_config_set (core->config, "cmd.pdc", opt); + rz_config_set (core->config, "cmd.pdc", opt); RPanel *panel = __get_panel (panels, i++); panels->n_panels = i; - panel->model->title = r_str_new (opt); - __set_read_only (core, panel, r_core_cmd_str (core, opt)); + panel->model->title = rz_str_new (opt); + __set_read_only (core, panel, rz_core_cmd_str (core, opt)); } __layout_equal_hor (panels); - r_list_free (optl); + rz_list_free (optl); free (opts); - r_config_set (core->config, "cmd.pdc", pdc_now); + rz_config_set (core->config, "cmd.pdc", pdc_now); root->cur_panels = root->n_panels - 1; __set_root_state (core, ROTATE); return 0; } int __load_layout_saved_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; - if (!r_load_panels_layout (core, child->name)) { + if (!rz_load_panels_layout (core, child->name)) { __create_default_panels (core); __panels_layout (core->panels); } @@ -3300,7 +3300,7 @@ int __load_layout_saved_cb(void *user) { } int __load_layout_default_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __init_panels (core, core->panels); __create_default_panels (core); __panels_layout (core->panels); @@ -3310,14 +3310,14 @@ int __load_layout_default_cb(void *user) { } int __close_file_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmd0 (core, "o-*"); + RzCore *core = (RzCore *)user; + rz_core_cmd0 (core, "o-*"); return 0; } int __save_layout_cb(void *user) { - RCore *core = (RCore *)user; - r_save_panels_layout (core, NULL); + RzCore *core = (RzCore *)user; + rz_save_panels_layout (core, NULL); __set_mode (core, PANEL_MODE_DEFAULT); __clear_panels_menu (core); __get_cur_panel (core->panels)->view->refresh = true; @@ -3325,25 +3325,25 @@ int __save_layout_cb(void *user) { } int __clear_layout_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; if (!__show_status_yesno (core, 0, "Clear all the saved layouts?(y/n): ")) { return 0; } char *dir_path = __get_panels_config_dir_path (); - RList *dir = r_sys_dir ((const char *)dir_path); + RzList *dir = rz_sys_dir ((const char *)dir_path); if (!dir) { free (dir_path); return 0; } - RListIter *it; + RzListIter *it; char *entry; - r_list_foreach (dir, it, entry) { - char *tmp = r_str_newf ("%s%s%s", dir_path, R_SYS_DIR, entry); - r_file_rm (tmp); + rz_list_foreach (dir, it, entry) { + char *tmp = rz_str_newf ("%s%s%s", dir_path, R_SYS_DIR, entry); + rz_file_rm (tmp); free (tmp); } - r_file_rm (dir_path); - r_list_free (dir); + rz_file_rm (dir_path); + rz_list_free (dir); free (dir_path); __update_menu (core, "File.Load Layout.Saved", __init_menu_saved_layout); @@ -3351,48 +3351,48 @@ int __clear_layout_cb(void *user) { } int __copy_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "How many bytes? ", "\"y %s\""); return 0; } int __paste_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmd0 (core, "yy"); + RzCore *core = (RzCore *)user; + rz_core_cmd0 (core, "yy"); return 0; } int __write_str_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "insert string: ", "\"w %s\""); return 0; } int __write_hex_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "insert hexpairs: ", "\"wx %s\""); return 0; } int __assemble_cb(void *user) { - RCore *core = (RCore *)user; - r_core_visual_asm (core, core->offset); + RzCore *core = (RzCore *)user; + rz_core_visual_asm (core, core->offset); return 0; } int __fill_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "Fill with: ", "wow %s"); return 0; } int __settings_colors_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; - r_str_ansi_filter (child->name, NULL, NULL, -1); - r_core_cmdf (core, "eco %s", child->name); + rz_str_ansi_filter (child->name, NULL, NULL, -1); + rz_core_cmdf (core, "eco %s", child->name); int i; for (i = 1; i < menu->depth; i++) { RPanel *p = menu->history[i]->p; @@ -3404,16 +3404,16 @@ int __settings_colors_cb(void *user) { } int __config_toggle_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; - RStrBuf *tmp = r_strbuf_new (child->name); - (void)r_str_split (r_strbuf_get (tmp), ':'); - r_config_toggle (core->config, r_strbuf_get (tmp)); - r_strbuf_free (tmp); + RStrBuf *tmp = rz_strbuf_new (child->name); + (void)rz_str_split (rz_strbuf_get (tmp), ':'); + rz_config_toggle (core->config, rz_strbuf_get (tmp)); + rz_strbuf_free (tmp); free (parent->p->model->title); - parent->p->model->title = r_strbuf_drain (__draw_menu (core, parent)); + parent->p->model->title = rz_strbuf_drain (__draw_menu (core, parent)); int i; for (i = 1; i < menu->depth; i++) { RPanel *p = menu->history[i]->p; @@ -3430,17 +3430,17 @@ int __config_toggle_cb(void *user) { } int __config_value_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; - RStrBuf *tmp = r_strbuf_new (child->name); - (void)r_str_split (r_strbuf_get(tmp), ':'); + RStrBuf *tmp = rz_strbuf_new (child->name); + (void)rz_str_split (rz_strbuf_get(tmp), ':'); const char *v = __show_status_input (core, "New value: "); - r_config_set (core->config, r_strbuf_get (tmp), v); - r_strbuf_free (tmp); + rz_config_set (core->config, rz_strbuf_get (tmp), v); + rz_strbuf_free (tmp); free (parent->p->model->title); - parent->p->model->title = r_strbuf_drain (__draw_menu (core, parent)); + parent->p->model->title = rz_strbuf_drain (__draw_menu (core, parent)); int i; for (i = 1; i < menu->depth; i++) { RPanel *p = menu->history[i]->p; @@ -3457,96 +3457,96 @@ int __config_value_cb(void *user) { } int __calculator_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; for (;;) { char *s = __show_status_input (core, "> "); if (!s || !*s) { free (s); break; } - r_core_cmdf (core, "? %s", s); - r_cons_flush (); + rz_core_cmdf (core, "? %s", s); + rz_cons_flush (); free (s); } return 0; } -int __r2_shell_cb(void *user) { - RCore *core = (RCore *)user; +int __rz_shell_cb(void *user) { + RzCore *core = (RzCore *)user; core->vmode = false; - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); core->vmode = true; return 0; } int __system_shell_cb(void *user) { - r_cons_set_raw (0); - r_cons_flush (); - r_sys_cmd ("$SHELL"); + rz_cons_set_raw (0); + rz_cons_flush (); + rz_sys_cmd ("$SHELL"); return 0; } int __string_whole_bin_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "search strings in the whole binary: ", "izzq~%s"); return 0; } int __string_data_sec_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "search string in data sections: ", "izq~%s"); return 0; } int __rop_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "rop grep: ", "\"/R %s\""); return 0; } int __code_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "search code: ", "\"/c %s\""); return 0; } int __hexpairs_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __add_cmdf_panel (core, "search hexpairs: ", "\"/x %s\""); return 0; } int __continue_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmd (core, "dc", 0); - r_cons_flush (); + RzCore *core = (RzCore *)user; + rz_core_cmd (core, "dc", 0); + rz_cons_flush (); return 0; } int __esil_init_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __esil_init (core); return 0; } int __esil_step_to_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *end = __show_status_input (core, "target addr: "); - __esil_step_to (core, r_num_math (core->num, end)); + __esil_step_to (core, rz_num_math (core->num, end)); return 0; } int __esil_step_range_cb(void *user) { - RStrBuf *rsb = r_strbuf_new (NULL); - RCore *core = (RCore *)user; - r_strbuf_append (rsb, "start addr: "); - char *s = __show_status_input (core, r_strbuf_get (rsb)); - r_strbuf_append (rsb, s); - r_strbuf_append (rsb, " end addr: "); - char *d = __show_status_input (core, r_strbuf_get (rsb)); - r_strbuf_free (rsb); - ut64 s_a = r_num_math (core->num, s); - ut64 d_a = r_num_math (core->num, d); + RStrBuf *rsb = rz_strbuf_new (NULL); + RzCore *core = (RzCore *)user; + rz_strbuf_append (rsb, "start addr: "); + char *s = __show_status_input (core, rz_strbuf_get (rsb)); + rz_strbuf_append (rsb, s); + rz_strbuf_append (rsb, " end addr: "); + char *d = __show_status_input (core, rz_strbuf_get (rsb)); + rz_strbuf_free (rsb); + ut64 s_a = rz_num_math (core->num, s); + ut64 d_a = rz_num_math (core->num, d); if (s_a >= d_a) { return 0; } @@ -3559,36 +3559,36 @@ int __esil_step_range_cb(void *user) { } int __step_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __panel_single_step_in (core); __update_disassembly_or_open (core); return 0; } int __step_over_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __panel_single_step_over (core); __update_disassembly_or_open (core); return 0; } int __io_cache_on_cb(void *user) { - RCore *core = (RCore *)user; - r_config_set_i (core->config, "io.cache", 1); + RzCore *core = (RzCore *)user; + rz_config_set_i (core->config, "io.cache", 1); (void)__show_status (core, "io.cache is on"); __set_mode (core, PANEL_MODE_DEFAULT); return 0; } int __io_cache_off_cb(void *user) { - RCore *core = (RCore *)user; - r_config_set_i (core->config, "io.cache", 0); + RzCore *core = (RzCore *)user; + rz_config_set_i (core->config, "io.cache", 0); (void)__show_status (core, "io.cache is off"); __set_mode (core, PANEL_MODE_DEFAULT); return 0; } -void __update_disassembly_or_open (RCore *core) { +void __update_disassembly_or_open (RzCore *core) { RPanels *panels = core->panels; int i; bool create_new = true; @@ -3621,7 +3621,7 @@ void __update_disassembly_or_open (RCore *core) { } } -void __set_curnode(RCore *core, int idx) { +void __set_curnode(RzCore *core, int idx) { RPanels *panels = core->panels; if (idx >= panels->n_panels) { idx = 0; @@ -3635,19 +3635,19 @@ void __set_curnode(RCore *core, int idx) { cur->view->curpos = cur->view->sy; } -void __set_mode(RCore *core, RPanelsMode mode) { +void __set_mode(RzCore *core, RPanelsMode mode) { RPanels *panels = core->panels; __set_cursor (core, false); panels->mode = mode; __update_help (core, panels); } -void __update_help(RCore *core, RPanels *ps) { +void __update_help(RzCore *core, RPanels *ps) { int i; for (i = 0; i < ps->n_panels; i++) { RPanel *p = __get_panel (ps, i); - if (r_str_endswith (p->model->cmd, "Help")) { - RStrBuf *rsb = r_strbuf_new (NULL); + if (rz_str_endswith (p->model->cmd, "Help")) { + RStrBuf *rsb = rz_strbuf_new (NULL); const char *title, *cmd; const char **msg; switch (ps->mode) { @@ -3667,13 +3667,13 @@ void __update_help(RCore *core, RPanels *ps) { msg = help_msg_panels; break; } - p->model->title = r_str_dup (p->model->title, cmd); - p->model->cmd = r_str_dup (p->model->cmd, cmd); - r_core_visual_append_help (rsb, title, msg); + p->model->title = rz_str_dup (p->model->title, cmd); + p->model->cmd = rz_str_dup (p->model->cmd, cmd); + rz_core_visual_append_help (rsb, title, msg); if (!rsb) { return; } - char *drained = r_strbuf_drain (rsb); + char *drained = rz_strbuf_drain (rsb); __set_read_only (core, p, drained); free (drained); p->view->refresh = true; @@ -3682,127 +3682,127 @@ void __update_help(RCore *core, RPanels *ps) { } int __reload_cb(void *user) { - RCore *core = (RCore *)user; - r_core_file_reopen_debug (core, ""); + RzCore *core = (RzCore *)user; + rz_core_file_reopen_debug (core, ""); __update_disassembly_or_open (core); return 0; } int __function_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "af"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "af"); return 0; } int __symbols_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "aa"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "aa"); return 0; } int __program_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "aaa"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "aaa"); return 0; } int __basic_blocks_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "aab"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "aab"); return 0; } int __calls_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "aac"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "aac"); return 0; } int __break_points_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char buf[128]; const char *prompt = "addr: "; core->cons->line->prompt_type = R_LINE_PROMPT_OFFSET; - r_line_set_hist_callback (core->cons->line, - &r_line_hist_offset_up, - &r_line_hist_offset_down); + rz_line_set_hist_callback (core->cons->line, + &rz_line_hist_offset_up, + &rz_line_hist_offset_down); __panel_prompt (prompt, buf, sizeof (buf)); - r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT; - ut64 addr = r_num_math (core->num, buf); - r_core_cmdf (core, "dbs 0x%08"PFMT64x, addr); + ut64 addr = rz_num_math (core->num, buf); + rz_core_cmdf (core, "dbs 0x%08"PFMT64x, addr); return 0; } int __watch_points_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char addrBuf[128], rw[128]; const char *addrPrompt = "addr: ", *rwPrompt = ": "; __panel_prompt (addrPrompt, addrBuf, sizeof (addrBuf)); __panel_prompt (rwPrompt, rw, sizeof (rw)); - ut64 addr = r_num_math (core->num, addrBuf); - r_core_cmdf (core, "dbw 0x%08"PFMT64x" %s", addr, rw); + ut64 addr = rz_num_math (core->num, addrBuf); + rz_core_cmdf (core, "dbw 0x%08"PFMT64x" %s", addr, rw); return 0; } int __references_cb(void *user) { - RCore *core = (RCore *)user; - r_core_cmdf (core, "aar"); + RzCore *core = (RzCore *)user; + rz_core_cmdf (core, "aar"); return 0; } int __fortune_cb(void *user) { - RCore *core = (RCore *)user; - char *s = r_core_cmd_str (core, "fo"); - r_cons_message (s); + RzCore *core = (RzCore *)user; + char *s = rz_core_cmd_str (core, "fo"); + rz_cons_message (s); free (s); return 0; } int __game_cb(void *user) { - RCore *core = (RCore *)user; - r_cons_2048 (core->panels->can->color); + RzCore *core = (RzCore *)user; + rz_cons_2048 (core->panels->can->color); return 0; } int __help_cb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __toggle_help (core); return 0; } int __license_cb(void *user) { - r_cons_message ("Copyright 2006-2020 - pancake - LGPL"); + rz_cons_message ("Copyright 2006-2020 - pancake - LGPL"); return 0; } int __version_cb(void *user) { - RCore *core = (RCore *)user; - char *s = r_core_cmd_str (core, "?V"); - r_cons_message (s); + RzCore *core = (RzCore *)user; + char *s = rz_core_cmd_str (core, "?V"); + rz_cons_message (s); free (s); return 0; } int __writeValueCb(void *user) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *res = __show_status_input (core, "insert number: "); if (res) { - r_core_cmdf (core, "\"wv %s\"", res); + rz_core_cmdf (core, "\"wv %s\"", res); free (res); } return 0; } int __quit_cb(void *user) { - __set_root_state ((RCore *)user, QUIT); + __set_root_state ((RzCore *)user, QUIT); return 0; } void __direction_default_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *cur = __get_cur_panel (core->panels); cur->view->refresh = true; switch ((Direction)direction) { @@ -3826,7 +3826,7 @@ void __direction_default_cb(void *user, int direction) { } void __direction_disassembly_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); int cols = core->print->cols; @@ -3835,7 +3835,7 @@ void __direction_disassembly_cb(void *user, int direction) { case LEFT: if (core->print->cur_enabled) { __cursor_left (core); - r_core_block_read (core); + rz_core_block_read (core); __set_panel_addr (core, cur, core->offset); } else if (panels->mode == PANEL_MODE_ZOOM) { cur->model->addr--; @@ -3846,7 +3846,7 @@ void __direction_disassembly_cb(void *user, int direction) { case RIGHT: if (core->print->cur_enabled) { __cursor_right (core); - r_core_block_read (core); + rz_core_block_read (core); __set_panel_addr (core, cur, core->offset); } else if (panels->mode == PANEL_MODE_ZOOM) { cur->model->addr++; @@ -3858,11 +3858,11 @@ void __direction_disassembly_cb(void *user, int direction) { core->offset = cur->model->addr; if (core->print->cur_enabled) { __cursor_up (core); - r_core_block_read (core); + rz_core_block_read (core); __set_panel_addr (core, cur, core->offset); } else { - r_core_visual_disasm_up (core, &cols); - r_core_seek_delta (core, -cols); + rz_core_visual_disasm_up (core, &cols); + rz_core_seek_delta (core, -cols); __set_panel_addr (core, cur, core->offset); } return; @@ -3870,12 +3870,12 @@ void __direction_disassembly_cb(void *user, int direction) { core->offset = cur->model->addr; if (core->print->cur_enabled) { __cursor_down (core); - r_core_block_read (core); + rz_core_block_read (core); __set_panel_addr (core, cur, core->offset); } else { - RAsmOp op; - r_core_visual_disasm_down (core, &op, &cols); - r_core_seek (core, core->offset + cols, true); + RzAsmOp op; + rz_core_visual_disasm_down (core, &op, &cols); + rz_core_seek (core, core->offset + cols, true); __set_panel_addr (core, cur, core->offset); } return; @@ -3883,11 +3883,11 @@ void __direction_disassembly_cb(void *user, int direction) { } void __direction_graph_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); cur->view->refresh = true; - const int speed = r_config_get_i (core->config, "graph.scroll") * 2; + const int speed = rz_config_get_i (core->config, "graph.scroll") * 2; switch ((Direction)direction) { case LEFT: if (cur->view->sx > 0) { @@ -3909,7 +3909,7 @@ void __direction_graph_cb(void *user, int direction) { } void __direction_register_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); int cols = core->dbg->regcols; @@ -3950,10 +3950,10 @@ void __direction_register_cb(void *user, int direction) { } void __direction_stack_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); - int cols = r_config_get_i (core->config, "hex.cols"); + int cols = rz_config_get_i (core->config, "hex.cols"); if (cols < 1) { cols = 16; } @@ -3976,23 +3976,23 @@ void __direction_stack_cb(void *user, int direction) { } return; case UP: - r_config_set_i (core->config, "stack.delta", - r_config_get_i (core->config, "stack.delta") + cols); + rz_config_set_i (core->config, "stack.delta", + rz_config_get_i (core->config, "stack.delta") + cols); cur->model->addr -= cols; return; case DOWN: - r_config_set_i (core->config, "stack.delta", - r_config_get_i (core->config, "stack.delta") - cols); + rz_config_set_i (core->config, "stack.delta", + rz_config_get_i (core->config, "stack.delta") - cols); cur->model->addr += cols; return; } } void __direction_hexdump_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); - int cols = r_config_get_i (core->config, "hex.cols"); + int cols = rz_config_get_i (core->config, "hex.cols"); if (cols < 1) { cols = 16; } @@ -4057,7 +4057,7 @@ void __direction_hexdump_cb(void *user, int direction) { } void __direction_panels_cursor_cb(void *user, int direction) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); cur->view->refresh = true; @@ -4069,14 +4069,14 @@ void __direction_panels_cursor_cb(void *user, int direction) { return; } if (cur->view->sx > 0) { - cur->view->sx -= r_config_get_i (core->config, "graph.scroll"); + cur->view->sx -= rz_config_get_i (core->config, "graph.scroll"); } return; case RIGHT: if (core->print->cur_enabled) { return; } - cur->view->sx += r_config_get_i (core->config, "graph.scroll"); + cur->view->sx += rz_config_get_i (core->config, "graph.scroll"); return; case UP: if (core->print->cur_enabled) { @@ -4113,7 +4113,7 @@ void __direction_panels_cursor_cb(void *user, int direction) { } void __print_default_cb(void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; bool update = core->panels->autoUpdate && __check_func_diff (core, panel); char *cmdstr = __find_cmd_str_cache (core, panel); @@ -4129,7 +4129,7 @@ void __print_default_cb(void *user, void *p) { void __print_decompiler_cb(void *user, void *p) { //TODO: Refactoring //TODO: Also, __check_func_diff should use addr not name - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; bool update = core->panels->autoUpdate && __check_func_diff (core, panel); char *cmdstr = NULL; @@ -4140,10 +4140,10 @@ void __print_decompiler_cb(void *user, void *p) { } return; } - RAnalFunction *func = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *func = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (func && core->panels_root->cur_pdc_cache) { - cmdstr = r_str_new ((char *)sdb_ptr_get (core->panels_root->cur_pdc_cache, - r_num_as_string (NULL, func->addr, false), 0)); + cmdstr = rz_str_new ((char *)sdb_ptr_get (core->panels_root->cur_pdc_cache, + rz_num_as_string (NULL, func->addr, false), 0)); if (cmdstr) { __set_cmd_str_cache (core, panel, cmdstr); __reset_scroll_pos (panel); @@ -4160,7 +4160,7 @@ void __print_decompiler_cb(void *user, void *p) { } void __print_disasmsummary_cb (void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; bool update = core->panels->autoUpdate && __check_func_diff (core, panel); char *cmdstr = __find_cmd_str_cache (core, panel); @@ -4174,7 +4174,7 @@ void __print_disasmsummary_cb (void *user, void *p) { } void __print_disassembly_cb(void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; core->print->screen_bounds = 1LL; char *cmdstr = __find_cmd_str_cache (core, panel); @@ -4183,12 +4183,12 @@ void __print_disassembly_cb(void *user, void *p) { return; } char *ocmd = panel->model->cmd; - panel->model->cmd = r_str_newf ("%s %d", panel->model->cmd, panel->view->pos.h - 3); + panel->model->cmd = rz_str_newf ("%s %d", panel->model->cmd, panel->view->pos.h - 3); ut64 o_offset = core->offset; core->offset = panel->model->addr; - r_core_seek (core, panel->model->addr, true); - if (r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd (core, ".dr*", 0); + rz_core_seek (core, panel->model->addr, true); + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd (core, ".dr*", 0); } cmdstr = __handle_cmd_str_cache (core, panel, false); core->offset = o_offset; @@ -4198,7 +4198,7 @@ void __print_disassembly_cb(void *user, void *p) { } void __print_graph_cb(void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; bool update = core->panels->autoUpdate && __check_func_diff (core, panel); char *cmdstr = __find_cmd_str_cache (core, panel); @@ -4207,53 +4207,53 @@ void __print_graph_cb(void *user, void *p) { } core->cons->event_resize = NULL; core->cons->event_data = core; - core->cons->event_resize = (RConsEvent) __do_panels_refreshOneShot; + core->cons->event_resize = (RzConsEvent) __do_panels_refreshOneShot; __update_panel_contents (core, panel, cmdstr); } void __print_stack_cb(void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; - const int delta = r_config_get_i (core->config, "stack.delta"); - const int bits = r_config_get_i (core->config, "asm.bits"); + const int delta = rz_config_get_i (core->config, "stack.delta"); + const int bits = rz_config_get_i (core->config, "asm.bits"); const char sign = (delta < 0)? '+': '-'; const int absdelta = R_ABS (delta); - char *cmd = r_str_newf ("%s%s ", PANEL_CMD_STACK, bits == 32 ? "w" : "q"); - int n = r_str_split (panel->model->cmd, ' '); + char *cmd = rz_str_newf ("%s%s ", PANEL_CMD_STACK, bits == 32 ? "w" : "q"); + int n = rz_str_split (panel->model->cmd, ' '); int i; for (i = 0; i < n; i++) { - const char *s = r_str_word_get0 (panel->model->cmd, i); + const char *s = rz_str_word_get0 (panel->model->cmd, i); if (!i) { continue; } - cmd = r_str_append (cmd, s); + cmd = rz_str_append (cmd, s); } panel->model->cmd = cmd; - const char *cmdstr = r_core_cmd_str (core, r_str_newf ("%s%c%d", cmd, sign, absdelta)); + const char *cmdstr = rz_core_cmd_str (core, rz_str_newf ("%s%c%d", cmd, sign, absdelta)); __update_panel_contents (core, panel, cmdstr); } void __print_hexdump_cb(void *user, void *p) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *panel = (RPanel *)p; char *cmdstr = __find_cmd_str_cache (core, panel); if (!cmdstr) { ut64 o_offset = core->offset; if (!panel->model->cache) { core->offset = panel->model->addr; - r_core_seek (core, core->offset, true); - r_core_block_read (core); + rz_core_seek (core, core->offset, true); + rz_core_block_read (core); } char *base = hexdump_rotate[R_ABS(panel->model->rotate) % COUNT (hexdump_rotate)]; - char *cmd = r_str_newf ("%s ", base); - int n = r_str_split (panel->model->cmd, ' '); + char *cmd = rz_str_newf ("%s ", base); + int n = rz_str_split (panel->model->cmd, ' '); int i; for (i = 0; i < n; i++) { - const char *s = r_str_word_get0 (panel->model->cmd, i); + const char *s = rz_str_word_get0 (panel->model->cmd, i); if (!i) { continue; } - cmd = r_str_append (cmd, s); + cmd = rz_str_append (cmd, s); } panel->model->cmd = cmd; cmdstr = __handle_cmd_str_cache (core, panel, false); @@ -4262,10 +4262,10 @@ void __print_hexdump_cb(void *user, void *p) { __update_panel_contents (core, panel, cmdstr); } -void __hudstuff(RCore *core) { +void __hudstuff(RzCore *core) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); - r_core_visual_hudstuff (core); + rz_core_visual_hudstuff (core); if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { __set_panel_addr (core, cur, core->offset); @@ -4281,48 +4281,48 @@ void __hudstuff(RCore *core) { } } -void __esil_init(RCore *core) { - r_core_cmd (core, "aeim", 0); - r_core_cmd (core, "aeip", 0); +void __esil_init(RzCore *core) { + rz_core_cmd (core, "aeim", 0); + rz_core_cmd (core, "aeip", 0); } -void __esil_step_to(RCore *core, ut64 end) { - r_core_cmdf (core, "aesu 0x%08"PFMT64x, end); +void __esil_step_to(RzCore *core, ut64 end) { + rz_core_cmdf (core, "aesu 0x%08"PFMT64x, end); } void __print_snow(RPanels *panels) { if (!panels->snows) { - panels->snows = r_list_newf (free); + panels->snows = rz_list_newf (free); } RPanel *cur = __get_cur_panel (panels); - int i, amount = r_num_rand (4); + int i, amount = rz_num_rand (4); if (amount > 0) { for (i = 0; i < amount; i++) { RPanelsSnow *snow = R_NEW (RPanelsSnow); - snow->x = r_num_rand (cur->view->pos.w) + cur->view->pos.x; + snow->x = rz_num_rand (cur->view->pos.w) + cur->view->pos.x; snow->y = cur->view->pos.y; - r_list_append (panels->snows, snow); + rz_list_append (panels->snows, snow); } } - RListIter *iter, *iter2; + RzListIter *iter, *iter2; RPanelsSnow *snow; - r_list_foreach_safe (panels->snows, iter, iter2, snow) { - int pos = r_num_rand (3) - 1; + rz_list_foreach_safe (panels->snows, iter, iter2, snow) { + int pos = rz_num_rand (3) - 1; snow->x += pos; snow->y++; if (snow->x >= cur->view->pos.w + cur->view->pos.x || snow->x <= cur->view->pos.x + 1) { - r_list_delete (panels->snows, iter); + rz_list_delete (panels->snows, iter); continue; } if (snow->y >= cur->view->pos.h + cur->view->pos.y - 1) { - r_list_delete (panels->snows, iter); + rz_list_delete (panels->snows, iter); continue; } - if (r_cons_canvas_gotoxy (panels->can, snow->x, snow->y)) { + if (rz_cons_canvas_gotoxy (panels->can, snow->x, snow->y)) { if (panels->fun == PANEL_FUN_SAKURA) { - r_cons_canvas_write (panels->can, Color_BMAGENTA","Color_RESET); + rz_cons_canvas_write (panels->can, Color_BMAGENTA","Color_RESET); } else { - r_cons_canvas_write (panels->can, "*"); + rz_cons_canvas_write (panels->can, "*"); } } } @@ -4330,13 +4330,13 @@ void __print_snow(RPanels *panels) { void __reset_snow(RPanels *panels) { RPanel *cur = __get_cur_panel (panels); - r_list_free (panels->snows); + rz_list_free (panels->snows); panels->snows = NULL; cur->view->refresh = true; } int __open_menu_cb (void *user) { - RCore* core = (RCore *)user; + RzCore* core = (RzCore *)user; RPanelsMenu *menu = core->panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; @@ -4353,8 +4353,8 @@ int __open_menu_cb (void *user) { return 0; } free (child->p->model->title); - child->p->model->title = r_strbuf_drain (buf); - child->p->view->pos.w = r_str_bounds (child->p->model->title, &child->p->view->pos.h); + child->p->model->title = rz_strbuf_drain (buf); + child->p->view->pos.w = rz_str_bounds (child->p->model->title, &child->p->view->pos.h); child->p->view->pos.h += 4; child->p->model->type = PANEL_TYPE_MENU; child->p->view->refresh = true; @@ -4363,7 +4363,7 @@ int __open_menu_cb (void *user) { return 0; } -void __add_menu(RCore *core, const char *parent, const char *name, RPanelsMenuCallback cb) { +void __add_menu(RzCore *core, const char *parent, const char *name, RPanelsMenuCallback cb) { RPanels *panels = core->panels; RPanelsMenuItem *p_item, *item = R_NEW0 (RPanelsMenuItem); if (!item) { @@ -4379,7 +4379,7 @@ void __add_menu(RCore *core, const char *parent, const char *name, RPanelsMenuCa } item->n_sub = 0; item->selectedIndex = 0; - item->name = name ? r_str_new (name) : NULL; + item->name = name ? rz_str_new (name) : NULL; item->sub = NULL; item->cb = cb; item->p = R_NEW0 (RPanel); @@ -4403,7 +4403,7 @@ void __add_menu(RCore *core, const char *parent, const char *name, RPanelsMenuCa } } -void __update_menu(RCore *core, const char *parent, R_NULLABLE RPanelMenuUpdateCallback cb) { +void __update_menu(RzCore *core, const char *parent, R_NULLABLE RPanelMenuUpdateCallback cb) { RPanels *panels = core->panels; void *addr = ht_pp_find (panels->mht, parent, NULL); RPanelsMenuItem *p_item = (RPanelsMenuItem *)addr; @@ -4421,7 +4421,7 @@ void __update_menu(RCore *core, const char *parent, R_NULLABLE RPanelMenuUpdateC __update_menu_contents (core, menu, p_item); } -void __del_menu(RCore *core) { +void __del_menu(RzCore *core) { RPanels *panels = core->panels; RPanelsMenu *menu = panels->panels_menu; int i; @@ -4433,33 +4433,33 @@ void __del_menu(RCore *core) { menu->n_refresh = menu->depth - 1; } -RStrBuf *__draw_menu(RCore *core, RPanelsMenuItem *item) { - RStrBuf *buf = r_strbuf_new (NULL); +RStrBuf *__draw_menu(RzCore *core, RPanelsMenuItem *item) { + RStrBuf *buf = rz_strbuf_new (NULL); if (!buf) { return NULL; } int i; for (i = 0; i < item->n_sub; i++) { if (i == item->selectedIndex) { - r_strbuf_appendf (buf, "%s> %s"Color_RESET, + rz_strbuf_appendf (buf, "%s> %s"Color_RESET, core->cons->context->pal.graph_box2, item->sub[i]->name); } else { - r_strbuf_appendf (buf, " %s", item->sub[i]->name); + rz_strbuf_appendf (buf, " %s", item->sub[i]->name); } - r_strbuf_append (buf, " \n"); + rz_strbuf_append (buf, " \n"); } return buf; } -void __update_menu_contents(RCore *core, RPanelsMenu *menu, RPanelsMenuItem *parent) { +void __update_menu_contents(RzCore *core, RPanelsMenu *menu, RPanelsMenuItem *parent) { RPanel *p = parent->p; RStrBuf *buf = __draw_menu (core, parent); if (!buf) { return; } free (p->model->title); - p->model->title = r_strbuf_drain (buf); - int new_w = r_str_bounds (p->model->title, &p->view->pos.h); + p->model->title = rz_strbuf_drain (buf); + int new_w = rz_str_bounds (p->model->title, &p->view->pos.h); p->view->pos.w = new_w; p->view->pos.h += 4; p->model->type = PANEL_TYPE_MENU; @@ -4469,112 +4469,112 @@ void __update_menu_contents(RCore *core, RPanelsMenu *menu, RPanelsMenuItem *par void __init_menu_saved_layout (void *_core, const char *parent) { char *dir_path = __get_panels_config_dir_path (); - RList *dir = r_sys_dir (dir_path); + RzList *dir = rz_sys_dir (dir_path); if (!dir) { free (dir_path); return; } - RCore *core = (RCore *)_core; - RListIter *it; + RzCore *core = (RzCore *)_core; + RzListIter *it; char *entry; - r_list_foreach (dir, it, entry) { + rz_list_foreach (dir, it, entry) { if (strcmp (entry, ".") && strcmp (entry, "..")) { __add_menu (core, parent, entry, __load_layout_saved_cb); } } - r_list_free (dir); + rz_list_free (dir); free (dir_path); } void __init_menu_color_settings_layout (void *_core, const char *parent) { - RCore *core = (RCore *)_core; + RzCore *core = (RzCore *)_core; const char *color = core->cons->context->pal.graph_box2; - char *now = r_core_cmd_str (core, "eco."); - r_str_split (now, '\n'); + char *now = rz_core_cmd_str (core, "eco."); + rz_str_split (now, '\n'); parent = "Settings.Colors"; - RList *list = __sorted_list (core, menus_Colors, COUNT (menus_Colors)); + RzList *list = __sorted_list (core, menus_Colors, COUNT (menus_Colors)); char *pos; - RListIter* iter; - RStrBuf *buf = r_strbuf_new (NULL); - r_list_foreach (list, iter, pos) { + RzListIter* iter; + RStrBuf *buf = rz_strbuf_new (NULL); + rz_list_foreach (list, iter, pos) { if (pos && !strcmp (now, pos)) { - r_strbuf_setf (buf, "%s%s", color, pos); - __add_menu (core, parent, r_strbuf_get (buf), __settings_colors_cb); + rz_strbuf_setf (buf, "%s%s", color, pos); + __add_menu (core, parent, rz_strbuf_get (buf), __settings_colors_cb); continue; } __add_menu (core, parent, pos, __settings_colors_cb); } free (now); - r_list_free (list); - r_strbuf_free (buf); + rz_list_free (list); + rz_strbuf_free (buf); } void __init_menu_disasm_settings_layout (void *_core, const char *parent) { - RCore *core = (RCore *)_core; + RzCore *core = (RzCore *)_core; int i = 0; - RList *list = __sorted_list (core, menus_settings_disassembly, COUNT (menus_settings_disassembly)); + RzList *list = __sorted_list (core, menus_settings_disassembly, COUNT (menus_settings_disassembly)); char *pos; - RListIter* iter; - RStrBuf *rsb = r_strbuf_new (NULL); - r_list_foreach (list, iter, pos) { + RzListIter* iter; + RStrBuf *rsb = rz_strbuf_new (NULL); + rz_list_foreach (list, iter, pos) { if (!strcmp (pos, "asm")) { __add_menu (core, parent, pos, __open_menu_cb); __init_menu_disasm_asm_settings_layout (core, "Settings.Disassembly.asm"); } else { - r_strbuf_set (rsb, pos); - r_strbuf_append (rsb, ": "); - r_strbuf_append (rsb, r_config_get (core->config, pos)); - __add_menu (core, parent, r_strbuf_get (rsb), __config_toggle_cb); + rz_strbuf_set (rsb, pos); + rz_strbuf_append (rsb, ": "); + rz_strbuf_append (rsb, rz_config_get (core->config, pos)); + __add_menu (core, parent, rz_strbuf_get (rsb), __config_toggle_cb); } i++; } - r_list_free (list); - r_strbuf_free (rsb); + rz_list_free (list); + rz_strbuf_free (rsb); } static void __init_menu_disasm_asm_settings_layout(void *_core, const char *parent) { - RCore *core = (RCore *)_core; - RList *list = __sorted_list (core, menus_settings_disassembly_asm, COUNT (menus_settings_disassembly_asm)); + RzCore *core = (RzCore *)_core; + RzList *list = __sorted_list (core, menus_settings_disassembly_asm, COUNT (menus_settings_disassembly_asm)); char *pos; - RListIter* iter; - RStrBuf *rsb = r_strbuf_new (NULL); - r_list_foreach (list, iter, pos) { - r_strbuf_set (rsb, pos); - r_strbuf_append (rsb, ": "); - r_strbuf_append (rsb, r_config_get (core->config, pos)); + RzListIter* iter; + RStrBuf *rsb = rz_strbuf_new (NULL); + rz_list_foreach (list, iter, pos) { + rz_strbuf_set (rsb, pos); + rz_strbuf_append (rsb, ": "); + rz_strbuf_append (rsb, rz_config_get (core->config, pos)); if (!strcmp (pos, "asm.var.summary") || !strcmp (pos, "asm.arch") || !strcmp (pos, "asm.bits") || !strcmp (pos, "asm.cpu")) { - __add_menu (core, parent, r_strbuf_get (rsb), __config_value_cb); + __add_menu (core, parent, rz_strbuf_get (rsb), __config_value_cb); } else { - __add_menu (core, parent, r_strbuf_get (rsb), __config_toggle_cb); + __add_menu (core, parent, rz_strbuf_get (rsb), __config_toggle_cb); } } - r_list_free (list); - r_strbuf_free (rsb); + rz_list_free (list); + rz_strbuf_free (rsb); } static void __init_menu_screen_settings_layout(void *_core, const char *parent) { - RCore *core = (RCore *)_core; - RStrBuf *rsb = r_strbuf_new (NULL); + RzCore *core = (RzCore *)_core; + RStrBuf *rsb = rz_strbuf_new (NULL); int i = 0; while (menus_settings_screen[i]) { const char *menu = menus_settings_screen[i]; - r_strbuf_set (rsb, menu); - r_strbuf_append (rsb, ": "); - r_strbuf_append (rsb, r_config_get (core->config, menu)); + rz_strbuf_set (rsb, menu); + rz_strbuf_append (rsb, ": "); + rz_strbuf_append (rsb, rz_config_get (core->config, menu)); if (!strcmp (menus_settings_screen[i], "scr.color")) { - __add_menu (core, parent, r_strbuf_get (rsb), __config_value_cb); + __add_menu (core, parent, rz_strbuf_get (rsb), __config_value_cb); } else { - __add_menu (core, parent, r_strbuf_get (rsb), __config_toggle_cb); + __add_menu (core, parent, rz_strbuf_get (rsb), __config_toggle_cb); } i++; } - r_strbuf_free (rsb); + rz_strbuf_free (rsb); } -bool __init_panels_menu(RCore *core) { +bool __init_panels_menu(RzCore *core) { RPanels *panels = core->panels; RPanelsMenu *panels_menu = R_NEW0 (RPanelsMenu); if (!panels_menu) { @@ -4655,10 +4655,10 @@ bool __init_panels_menu(RCore *core) { { parent = "View"; i = 0; - RList *list = __sorted_list (core, menus_View, COUNT (menus_View)); + RzList *list = __sorted_list (core, menus_View, COUNT (menus_View)); char *pos; - RListIter* iter; - r_list_foreach (list, iter, pos) { + RzListIter* iter; + rz_list_foreach (list, iter, pos) { if (!strcmp (pos, PANEL_TITLE_ALL_DECOMPILER)) { __add_menu (core, parent, pos, __show_all_decompiler_cb); } else { @@ -4673,7 +4673,7 @@ bool __init_panels_menu(RCore *core) { if (!strcmp (menus_Tools[i], "Calculator")) { __add_menu (core, parent, menus_Tools[i], __calculator_cb); } else if (!strcmp (menus_Tools[i], "R2 Shell")) { - __add_menu (core, parent, menus_Tools[i], __r2_shell_cb); + __add_menu (core, parent, menus_Tools[i], __rz_shell_cb); } else if (!strcmp (menus_Tools[i], "System Shell")) { __add_menu (core, parent, menus_Tools[i], __system_shell_cb); } @@ -4713,10 +4713,10 @@ bool __init_panels_menu(RCore *core) { { parent = "Debug"; i = 0; - RList *list = __sorted_list (core, menus_Debug, COUNT (menus_Debug)); + RzList *list = __sorted_list (core, menus_Debug, COUNT (menus_Debug)); char *pos; - RListIter* iter; - r_list_foreach (list, iter, pos) { + RzListIter* iter; + rz_list_foreach (list, iter, pos) { if (!strcmp (pos, "Breakpoints")) { __add_menu (core, parent, pos, __break_points_cb); } else if (!strcmp (pos, "Watchpoints")) { @@ -4798,14 +4798,14 @@ bool __init_panels_menu(RCore *core) { { parent = "Settings.Decompiler"; - char *opts = r_core_cmd_str (core, "e cmd.pdc=?"); - RList *optl = r_str_split_list (opts, "\n", 0); - RListIter *iter; + char *opts = rz_core_cmd_str (core, "e cmd.pdc=?"); + RzList *optl = rz_str_split_list (opts, "\n", 0); + RzListIter *iter; char *opt; - r_list_foreach (optl, iter, opt) { + rz_list_foreach (optl, iter, opt) { __add_menu (core, parent, strdup (opt), __settings_decompiler_cb); } - r_list_free (optl); + rz_list_free (optl); free (opts); } @@ -4834,15 +4834,15 @@ int cmpstr(const void *_a, const void *_b) { return strcmp (a, b); } -RList *__sorted_list(RCore *core, char *menu[], int count) { - RList *list = r_list_new (); +RzList *__sorted_list(RzCore *core, char *menu[], int count) { + RzList *list = rz_list_new (); int i; for (i = 0; i < count; i++) { if (menu[i]) { - (void)r_list_append (list, menu[i]); + (void)rz_list_append (list, menu[i]); } } - r_list_sort (list, cmpstr); + rz_list_sort (list, cmpstr); return list; } @@ -4857,7 +4857,7 @@ void __clear_panels_menuRec(RPanelsMenuItem *pmi) { } } -void __clear_panels_menu(RCore *core) { +void __clear_panels_menu(RzCore *core) { RPanels *p = core->panels; RPanelsMenu *pm = p->panels_menu; __clear_panels_menuRec (pm->root); @@ -4867,7 +4867,7 @@ void __clear_panels_menu(RCore *core) { pm->n_refresh = 0; } -bool __init_panels(RCore *core, RPanels *panels) { +bool __init_panels(RzCore *core, RPanels *panels) { panels->panel = calloc (sizeof (RPanel *), PANEL_NUM_LIMIT); if (!panels->panel) { return false; @@ -4925,7 +4925,7 @@ void __free_menu_item(RPanelsMenuItem *item) { free (item); } -void __refresh_core_offset (RCore *core) { +void __refresh_core_offset (RzCore *core) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { @@ -4933,74 +4933,74 @@ void __refresh_core_offset (RCore *core) { } } -static void demo_begin (RCore *core, RConsCanvas *can) { - char *s = r_cons_canvas_to_string (can); +static void demo_begin (RzCore *core, RzConsCanvas *can) { + char *s = rz_cons_canvas_to_string (can); if (s) { // TODO drop utf8!! - r_str_ansi_filter (s, NULL, NULL, -1); - int i, h, w = r_cons_get_size (&h); + rz_str_ansi_filter (s, NULL, NULL, -1); + int i, h, w = rz_cons_get_size (&h); for (i = 0; i < 40; i+= (1 + (i/30))) { int H = i * ((double)h / 40); - char *r = r_str_scale (s, w, H); - r_cons_clear00 (); - r_cons_gotoxy (0, (h / 2) - (H / 2)); - r_cons_strcat (r); - r_cons_flush (); + char *r = rz_str_scale (s, w, H); + rz_cons_clear00 (); + rz_cons_gotoxy (0, (h / 2) - (H / 2)); + rz_cons_strcat (r); + rz_cons_flush (); free (r); - r_sys_usleep (3000); + rz_sys_usleep (3000); } free (s); } } -static void demo_end (RCore *core, RConsCanvas *can) { - bool utf8 = r_config_get_i (core->config, "scr.utf8"); - r_config_set_i (core->config, "scr.utf8", 0); +static void demo_end (RzCore *core, RzConsCanvas *can) { + bool utf8 = rz_config_get_i (core->config, "scr.utf8"); + rz_config_set_i (core->config, "scr.utf8", 0); RPanel *cur = __get_cur_panel (core->panels); cur->view->refresh = true; firstRun= false; __panels_refresh (core); firstRun= true; - r_config_set_i (core->config, "scr.utf8", utf8); - char *s = r_cons_canvas_to_string (can); + rz_config_set_i (core->config, "scr.utf8", utf8); + char *s = rz_cons_canvas_to_string (can); if (s) { // TODO drop utf8!! - r_str_ansi_filter (s, NULL, NULL, -1); - int i, h, w = r_cons_get_size (&h); + rz_str_ansi_filter (s, NULL, NULL, -1); + int i, h, w = rz_cons_get_size (&h); for (i = h; i > 0; i--) { int H = i; - char *r = r_str_scale (s, w, H); - r_cons_clear00 (); - r_cons_gotoxy (0, (h / 2) - (H / 2)); // center - //r_cons_gotoxy (0, h-H); // bottom - r_cons_strcat (r); - r_cons_flush (); + char *r = rz_str_scale (s, w, H); + rz_cons_clear00 (); + rz_cons_gotoxy (0, (h / 2) - (H / 2)); // center + //rz_cons_gotoxy (0, h-H); // bottom + rz_cons_strcat (r); + rz_cons_flush (); free (r); - r_sys_usleep (3000); + rz_sys_usleep (3000); } - r_sys_usleep (100000); + rz_sys_usleep (100000); free (s); } } -void __panels_refresh(RCore *core) { +void __panels_refresh(RzCore *core) { RPanels *panels = core->panels; if (!panels) { return; } - RConsCanvas *can = panels->can; + RzConsCanvas *can = panels->can; if (!can) { return; } - r_cons_gotoxy (0, 0); - int i, h, w = r_cons_get_size (&h); - if (!r_cons_canvas_resize (can, w, h)) { + rz_cons_gotoxy (0, 0); + int i, h, w = rz_cons_get_size (&h); + if (!rz_cons_canvas_resize (can, w, h)) { return; } - RStrBuf *title = r_strbuf_new (" "); - bool utf8 = r_config_get_i (core->config, "scr.utf8"); + RStrBuf *title = rz_strbuf_new (" "); + bool utf8 = rz_config_get_i (core->config, "scr.utf8"); if (firstRun) { - r_config_set_i (core->config, "scr.utf8", 0); + rz_config_set_i (core->config, "scr.utf8", 0); } __refresh_core_offset (core); @@ -5020,36 +5020,36 @@ void __panels_refresh(RCore *core) { for (i = 0; i < panels->panels_menu->n_refresh; i++) { __panel_print (core, can, panels->panels_menu->refreshPanels[i], 1); } - (void) r_cons_canvas_gotoxy (can, -can->sx, -can->sy); - r_cons_canvas_fill (can, -can->sx, -can->sy, w, 1, ' '); + (void) rz_cons_canvas_gotoxy (can, -can->sx, -can->sy); + rz_cons_canvas_fill (can, -can->sx, -can->sy, w, 1, ' '); const char *color = core->cons->context->pal.graph_box2; if (panels->mode == PANEL_MODE_ZOOM) { - r_strbuf_appendf (title, "%s Zoom Mode | Press Enter or q to quit"Color_RESET, color); + rz_strbuf_appendf (title, "%s Zoom Mode | Press Enter or q to quit"Color_RESET, color); } else if (panels->mode == PANEL_MODE_WINDOW) { - r_strbuf_appendf (title, "%s Window Mode | hjkl: move around the panels | q: quit the mode | Enter: Zoom mode"Color_RESET, color); + rz_strbuf_appendf (title, "%s Window Mode | hjkl: move around the panels | q: quit the mode | Enter: Zoom mode"Color_RESET, color); } else { RPanelsMenuItem *parent = panels->panels_menu->root; for (i = 0; i < parent->n_sub; i++) { RPanelsMenuItem *item = parent->sub[i]; if (panels->mode == PANEL_MODE_MENU && i == parent->selectedIndex) { - r_strbuf_appendf (title, "%s[%s]"Color_RESET, color, item->name); + rz_strbuf_appendf (title, "%s[%s]"Color_RESET, color, item->name); } else { - r_strbuf_appendf (title, " %s ", item->name); + rz_strbuf_appendf (title, " %s ", item->name); } } } if (panels->mode == PANEL_MODE_MENU) { - r_cons_canvas_write (can, Color_BLUE); - r_cons_canvas_write (can, r_strbuf_get (title)); - r_cons_canvas_write (can, Color_RESET); + rz_cons_canvas_write (can, Color_BLUE); + rz_cons_canvas_write (can, rz_strbuf_get (title)); + rz_cons_canvas_write (can, Color_RESET); } else { - r_cons_canvas_write (can, Color_RESET); - r_cons_canvas_write (can, r_strbuf_get (title)); + rz_cons_canvas_write (can, Color_RESET); + rz_cons_canvas_write (can, rz_strbuf_get (title)); } - r_strbuf_setf (title, "[0x%08"PFMT64x "]", core->offset); - i = -can->sx + w - r_strbuf_length (title); - (void) r_cons_canvas_gotoxy (can, i, -can->sy); - r_cons_canvas_write (can, r_strbuf_get (title)); + rz_strbuf_setf (title, "[0x%08"PFMT64x "]", core->offset); + i = -can->sx + w - rz_strbuf_length (title); + (void) rz_cons_canvas_gotoxy (can, i, -can->sy); + rz_cons_canvas_write (can, rz_strbuf_get (title)); int tab_pos = i; for (i = core->panels_root->n_panels; i > 0; i--) { @@ -5060,27 +5060,27 @@ void __panels_refresh(RCore *core) { } if (i - 1 == core->panels_root->cur_panels) { if (!name) { - r_strbuf_setf (title, "%s[%d] "Color_RESET, color, i); + rz_strbuf_setf (title, "%s[%d] "Color_RESET, color, i); } else { - r_strbuf_setf (title, "%s[%s] "Color_RESET, color, name); + rz_strbuf_setf (title, "%s[%s] "Color_RESET, color, name); } - tab_pos -= r_str_ansi_len (r_strbuf_get (title)); + tab_pos -= rz_str_ansi_len (rz_strbuf_get (title)); } else { if (!name) { - r_strbuf_setf (title, "%d ", i); + rz_strbuf_setf (title, "%d ", i); } else { - r_strbuf_setf (title, "%s ", name); + rz_strbuf_setf (title, "%s ", name); } - tab_pos -= r_strbuf_length (title); + tab_pos -= rz_strbuf_length (title); } - (void) r_cons_canvas_gotoxy (can, tab_pos, -can->sy); - r_cons_canvas_write (can, r_strbuf_get (title)); + (void) rz_cons_canvas_gotoxy (can, tab_pos, -can->sy); + rz_cons_canvas_write (can, rz_strbuf_get (title)); } - r_strbuf_set (title, "Tab "); - tab_pos -= r_strbuf_length (title); - (void) r_cons_canvas_gotoxy (can, tab_pos, -can->sy); - r_cons_canvas_write (can, r_strbuf_get (title)); - r_strbuf_free (title); + rz_strbuf_set (title, "Tab "); + tab_pos -= rz_strbuf_length (title); + (void) rz_cons_canvas_gotoxy (can, tab_pos, -can->sy); + rz_cons_canvas_write (can, rz_strbuf_get (title)); + rz_strbuf_free (title); if (panels->fun == PANEL_FUN_SNOW || panels->fun == PANEL_FUN_SAKURA) { __print_snow (panels); @@ -5088,31 +5088,31 @@ void __panels_refresh(RCore *core) { if (firstRun) { if (core->panels_root->n_panels < 2) { - if (r_config_get_i (core->config, "scr.demo")) { + if (rz_config_get_i (core->config, "scr.demo")) { demo_begin (core, can); } } firstRun = false; - r_config_set_i (core->config, "scr.utf8", utf8); + rz_config_set_i (core->config, "scr.utf8", utf8); RPanel *cur = __get_cur_panel (core->panels); cur->view->refresh = true; __panels_refresh (core); return; } - r_cons_canvas_print (can); + rz_cons_canvas_print (can); if (core->scr_gadgets) { - r_core_cmd0 (core, "pg"); + rz_core_cmd0 (core, "pg"); } - r_cons_flush (); - if (r_cons_singleton ()->fps) { - r_cons_print_fps (40); + rz_cons_flush (); + if (rz_cons_singleton ()->fps) { + rz_cons_print_fps (40); } } -void __do_panels_resize(RCore *core) { +void __do_panels_resize(RzCore *core) { RPanels *panels = core->panels; int i; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); for (i = 0; i < panels->n_panels; i++) { RPanel *panel = __get_panel (panels, i); if ((panel->view->edge & (1 << PANEL_EDGE_BOTTOM)) @@ -5127,7 +5127,7 @@ void __do_panels_resize(RCore *core) { __do_panels_refresh (core); } -void __do_panels_refresh(RCore *core) { +void __do_panels_refresh(RzCore *core) { if (!core->panels) { return; } @@ -5135,66 +5135,66 @@ void __do_panels_refresh(RCore *core) { __panels_layout_refresh (core); } -void __do_panels_refreshOneShot(RCore *core) { - r_core_task_enqueue_oneshot (&core->tasks, (RCoreTaskOneShot) __do_panels_resize, core); +void __do_panels_refreshOneShot(RzCore *core) { + rz_core_task_enqueue_oneshot (&core->tasks, (RzCoreTaskOneShot) __do_panels_resize, core); } -void __panel_single_step_in(RCore *core) { - if (r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd (core, "ds", 0); - r_core_cmd (core, ".dr*", 0); +void __panel_single_step_in(RzCore *core) { + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd (core, "ds", 0); + rz_core_cmd (core, ".dr*", 0); } else { - r_core_cmd (core, "aes", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aes", 0); + rz_core_cmd (core, ".ar*", 0); } } -void __panel_single_step_over(RCore *core) { - bool io_cache = r_config_get_i (core->config, "io.cache"); - r_config_set_i (core->config, "io.cache", false); - if (r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd (core, "dso", 0); - r_core_cmd (core, ".dr*", 0); +void __panel_single_step_over(RzCore *core) { + bool io_cache = rz_config_get_i (core->config, "io.cache"); + rz_config_set_i (core->config, "io.cache", false); + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd (core, "dso", 0); + rz_core_cmd (core, ".dr*", 0); } else { - r_core_cmd (core, "aeso", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aeso", 0); + rz_core_cmd (core, ".ar*", 0); } - r_config_set_i (core->config, "io.cache", io_cache); + rz_config_set_i (core->config, "io.cache", io_cache); } -void __panel_breakpoint(RCore *core) { +void __panel_breakpoint(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { - r_core_cmd (core, "dbs $$", 0); + rz_core_cmd (core, "dbs $$", 0); cur->view->refresh = true; } } -void __panel_continue(RCore *core) { - r_core_cmd (core, "dc", 0); +void __panel_continue(RzCore *core) { + rz_core_cmd (core, "dc", 0); } -void __panels_check_stackbase(RCore *core) { +void __panels_check_stackbase(RzCore *core) { if (!core || !core->panels) { return; } int i; - const char *sp = r_reg_get_name (core->anal->reg, R_REG_NAME_SP); + const char *sp = rz_reg_get_name (core->anal->reg, R_REG_NAME_SP); if (!sp) { return; } - const ut64 stackbase = r_reg_getv (core->anal->reg, sp); + const ut64 stackbase = rz_reg_getv (core->anal->reg, sp); RPanels *panels = core->panels; for (i = 1; i < panels->n_panels; i++) { RPanel *panel = __get_panel (panels, i); if (panel->model->cmd && __check_panel_type (panel, PANEL_CMD_STACK) && panel->model->baseAddr != stackbase) { panel->model->baseAddr = stackbase; - __set_panel_addr (core, panel, stackbase - r_config_get_i (core->config, "stack.delta") + core->print->cur); + __set_panel_addr (core, panel, stackbase - rz_config_get_i (core->config, "stack.delta") + core->print->cur); } } } -void __init_rotate_db(RCore *core) { +void __init_rotate_db(RzCore *core) { Sdb *db = core->panels->rotate_db; sdb_ptr_set (db, "pd", &__rotate_disasm_cb, 0); sdb_ptr_set (db, "p==", &__rotate_entropy_h_cb, 0); @@ -5205,7 +5205,7 @@ void __init_rotate_db(RCore *core) { sdb_ptr_set (db, PANEL_CMD_HEXDUMP, &__rotate_hexdump_cb, 0); } -void __init_sdb(RCore *core) { +void __init_sdb(RzCore *core) { Sdb *db= core->panels->db; sdb_set (db, "Symbols", "isq", 0); sdb_set (db, "Stack" , "px 256@r:SP", 0); @@ -5251,21 +5251,21 @@ void __init_sdb(RCore *core) { sdb_set (db, "File Hashes", "it", 0); } -void __init_almighty_db(RCore *core) { +void __init_almighty_db(RzCore *core) { Sdb *db = core->panels->almighty_db; SdbKv *kv; SdbListIter *sdb_iter; SdbList *sdb_list = sdb_foreach_list (core->panels->db, true); ls_foreach (sdb_list, sdb_iter, kv) { const char *key = sdbkv_key (kv); - sdb_ptr_set (db, r_str_new (key), &__create_panel_db, 0); + sdb_ptr_set (db, rz_str_new (key), &__create_panel_db, 0); } sdb_ptr_set (db, "Search strings in data sections", &__search_strings_data_create, 0); sdb_ptr_set (db, "Search strings in the whole bin", &__search_strings_bin_create, 0); sdb_ptr_set (db, "Create New", &__create_panel_input, 0); sdb_ptr_set (db, "Change Command of Current Panel", &__replace_current_panel_input, 0); sdb_ptr_set (db, PANEL_TITLE_ALL_DECOMPILER, &__delegate_show_all_decompiler_cb, 0); - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { sdb_ptr_set (db, "Put Breakpoints", &__put_breakpoints_cb, 0); sdb_ptr_set (db, "Continue", &__continue_almighty_cb, 0); sdb_ptr_set (db, "Step", &__step_almighty_cb, 0); @@ -5273,18 +5273,18 @@ void __init_almighty_db(RCore *core) { } } -void __init_all_dbs(RCore *core) { +void __init_all_dbs(RzCore *core) { __init_sdb (core); __init_almighty_db (core); __init_rotate_db (core); } static void __delegate_show_all_decompiler_cb(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - (void)__show_all_decompiler_cb ((RCore *)user); + (void)__show_all_decompiler_cb ((RzCore *)user); } void __create_panel_db(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *cmd = sdb_get (core->panels->db, title, 0); if (!cmd) { return; @@ -5293,7 +5293,7 @@ void __create_panel_db(void *user, RPanel *panel, const RPanelLayout dir, R_NULL } void __replace_current_panel_input(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *cmd = __show_status_input (core, "New command: "); if (R_STR_ISNOTEMPTY (cmd)) { __replace_cmd (core, cmd, cmd); @@ -5302,7 +5302,7 @@ void __replace_current_panel_input(void *user, RPanel *panel, const RPanelLayout } void __create_panel_input(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; char *cmd = __show_status_input (core, "Command: "); if (!cmd) { return; @@ -5310,7 +5310,7 @@ void __create_panel_input(void *user, RPanel *panel, const RPanelLayout dir, R_N __create_panel (core, panel, dir, cmd, cmd); } -void __create_panel(RCore *core, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char* title, const char *cmd) { +void __create_panel(RzCore *core, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char* title, const char *cmd) { if (!__check_panel_num (core)) { return; } @@ -5328,20 +5328,20 @@ void __create_panel(RCore *core, RPanel *panel, const RPanelLayout dir, R_NULLAB } void __search_strings_data_create(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __create_panel (core, panel, dir, title, __search_strings (core, false)); } void __search_strings_bin_create(void *user, RPanel *panel, const RPanelLayout dir, R_NULLABLE const char *title) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __create_panel (core, panel, dir, title, __search_strings (core, true)); } -char *__search_strings (RCore *core, bool whole) { +char *__search_strings (RzCore *core, bool whole) { const char *title = whole ? PANEL_TITLE_STRINGS_BIN : PANEL_TITLE_STRINGS_DATA; const char *str = __show_status_input (core, "Search Strings: "); char *db_val = __search_db (core, title); - char *ret = r_str_newf ("%s~%s", db_val, str); + char *ret = rz_str_newf ("%s~%s", db_val, str); free (db_val); return ret; } @@ -5352,7 +5352,7 @@ void __put_breakpoints_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPa void __continue_almighty_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPanelLayout dir, R_UNUSED R_NULLABLE const char *title) { __continue_cb (user); - __update_disassembly_or_open ((RCore *)user); + __update_disassembly_or_open ((RzCore *)user); } void __step_almighty_cb(void *user, R_UNUSED RPanel *panel, R_UNUSED const RPanelLayout dir, R_UNUSED R_NULLABLE const char *title) { @@ -5368,11 +5368,11 @@ void __mht_free_kv(HtPPKv *kv) { __free_menu_item ((RPanelsMenuItem *)kv->value); } -bool __init(RCore *core, RPanels *panels, int w, int h) { +bool __init(RzCore *core, RPanels *panels, int w, int h) { panels->panel = NULL; panels->n_panels = 0; panels->columnWidth = 80; - if (r_config_get_i (core->config, "cfg.debug")) { + if (rz_config_get_i (core->config, "cfg.debug")) { panels->layout = PANEL_LAYOUT_DEFAULT_DYNAMIC; } else { panels->layout = PANEL_LAYOUT_DEFAULT_STATIC; @@ -5398,26 +5398,26 @@ bool __init(RCore *core, RPanels *panels, int w, int h) { } int __file_history_up(RLine *line) { - RCore *core = line->user; - RList *files = r_id_storage_list (core->io->files); - int num_files = r_list_length (files); + RzCore *core = line->user; + RzList *files = rz_id_storage_list (core->io->files); + int num_files = rz_list_length (files); if (line->file_hist_index >= num_files || line->file_hist_index < 0) { return false; } line->file_hist_index++; - RIODesc *desc = r_list_get_n (files, num_files - line->file_hist_index); + RzIODesc *desc = rz_list_get_n (files, num_files - line->file_hist_index); if (desc) { strncpy (line->buffer.data, desc->name, R_LINE_BUFSIZE - 1); line->buffer.index = line->buffer.length = strlen (line->buffer.data); } - r_list_free (files); + rz_list_free (files); return true; } int __file_history_down(RLine *line) { - RCore *core = line->user; - RList *files = r_id_storage_list (core->io->files); - int num_files = r_list_length (files); + RzCore *core = line->user; + RzList *files = rz_id_storage_list (core->io->files); + int num_files = rz_list_length (files); if (line->file_hist_index <= 0 || line->file_hist_index > num_files) { return false; } @@ -5427,21 +5427,21 @@ int __file_history_down(RLine *line) { line->buffer.index = line->buffer.length = 0; return false; } - RIODesc *desc = r_list_get_n (files, num_files - line->file_hist_index); + RzIODesc *desc = rz_list_get_n (files, num_files - line->file_hist_index); if (desc) { strncpy (line->buffer.data, desc->name, R_LINE_BUFSIZE - 1); line->buffer.index = line->buffer.length = strlen (line->buffer.data); } - r_list_free (files); + rz_list_free (files); return true; } -void __handle_menu(RCore *core, const int key) { +void __handle_menu(RzCore *core, const int key) { RPanels *panels = core->panels; RPanelsMenu *menu = panels->panels_menu; RPanelsMenuItem *parent = menu->history[menu->depth - 1]; RPanelsMenuItem *child = parent->sub[parent->selectedIndex]; - r_cons_switchbuf (false); + rz_cons_switchbuf (false); switch (key) { case 'h': if (menu->depth <= 2) { @@ -5514,7 +5514,7 @@ void __handle_menu(RCore *core, const int key) { } break; case '$': - r_core_cmd0 (core, "dr PC=$$"); + rz_core_cmd0 (core, "dr PC=$$"); break; case ' ': case '\r': @@ -5545,30 +5545,30 @@ void __handle_menu(RCore *core, const int key) { } } -bool __handle_console(RCore *core, RPanel *panel, const int key) { +bool __handle_console(RzCore *core, RPanel *panel, const int key) { if (!__check_panel_type (panel, PANEL_CMD_CONSOLE)) { return false; } - r_cons_switchbuf (false); + rz_cons_switchbuf (false); switch (key) { case 'i': { char cmd[128] = {0}; - char *prompt = r_str_newf ("[0x%08"PFMT64x"]) ", core->offset); + char *prompt = rz_str_newf ("[0x%08"PFMT64x"]) ", core->offset); __panel_prompt (prompt, cmd, sizeof (cmd)); if (*cmd) { if (!strcmp (cmd, "clear")) { - r_core_cmd0 (core, ":>$console"); + rz_core_cmd0 (core, ":>$console"); } else { - r_core_cmdf (core, "?e %s %s>>$console", prompt, cmd); - r_core_cmdf (core, "%s >>$console", cmd); + rz_core_cmdf (core, "?e %s %s>>$console", prompt, cmd); + rz_core_cmdf (core, "%s >>$console", cmd); } } panel->view->refresh = true; } return true; case 'l': - r_core_cmd0 (core, ":>$console"); + rz_core_cmd0 (core, ":>$console"); panel->view->refresh = true; return true; default: @@ -5578,11 +5578,11 @@ bool __handle_console(RCore *core, RPanel *panel, const int key) { return false; } -void __handle_tab_key(RCore *core, bool shift) { +void __handle_tab_key(RzCore *core, bool shift) { __set_cursor (core, false); RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); - r_cons_switchbuf (false); + rz_cons_switchbuf (false); cur->view->refresh = true; if (!shift) { if (panels->mode == PANEL_MODE_MENU) { @@ -5621,45 +5621,45 @@ void __restore_panel_pos(RPanel* panel) { } char *__get_panels_config_dir_path(void) { - return r_str_home (R_JOIN_2_PATHS (R2_HOME_DATADIR, ".r2panels")); + return rz_str_home (R_JOIN_2_PATHS (R2_HOME_DATADIR, ".r2panels")); } char *__create_panels_config_path(const char *file) { char *dir_path = __get_panels_config_dir_path (); - r_sys_mkdirp (dir_path); - char *file_path = r_str_newf (R_JOIN_2_PATHS ("%s", "%s"), dir_path, file); + rz_sys_mkdirp (dir_path); + char *file_path = rz_str_newf (R_JOIN_2_PATHS ("%s", "%s"), dir_path, file); R_FREE (dir_path); return file_path; } char *__get_panels_config_file_from_dir (const char *file) { char *dir_path = __get_panels_config_dir_path (); - RList *dir = r_sys_dir (dir_path); + RzList *dir = rz_sys_dir (dir_path); if (!dir_path || !dir) { free (dir_path); return NULL; } char *tmp = NULL; - RListIter *it; + RzListIter *it; char *entry; - r_list_foreach (dir, it, entry) { + rz_list_foreach (dir, it, entry) { if (!strcmp (entry, file)) { tmp = entry; break; } } if (!tmp) { - r_list_free (dir); + rz_list_free (dir); free (dir_path); return NULL; } - char *ret = r_str_newf (R_JOIN_2_PATHS ("%s", "%s"), dir_path, tmp); - r_list_free (dir); + char *ret = rz_str_newf (R_JOIN_2_PATHS ("%s", "%s"), dir_path, tmp); + rz_list_free (dir); free (dir_path); return ret; } -R_API void r_save_panels_layout(RCore *core, const char *oname) { +RZ_API void rz_save_panels_layout(RzCore *core, const char *oname) { int i; if (!core->panels) { return; @@ -5686,7 +5686,7 @@ R_API void r_save_panels_layout(RCore *core, const char *oname) { pj_kn (pj, "h", panel->view->pos.h); pj_end (pj); } - FILE *fd = r_sandbox_fopen (config_path, "w"); + FILE *fd = rz_sandbox_fopen (config_path, "w"); if (fd) { char *pjs = pj_drain (pj); fprintf (fd, "%s\n", pjs); @@ -5702,7 +5702,7 @@ char *__parse_panels_config(const char *cfg, int len) { if (R_STR_ISEMPTY (cfg) || len < 2) { return NULL; } - char *tmp = r_str_newlen (cfg, len + 1); + char *tmp = rz_str_newlen (cfg, len + 1); int i = 0; for (; i < len; i++) { if (tmp[i] == '}') { @@ -5718,31 +5718,31 @@ char *__parse_panels_config(const char *cfg, int len) { return tmp; } -void __load_config_menu(RCore *core) { - RList *themes_list = r_core_list_themes (core); - RListIter *th_iter; +void __load_config_menu(RzCore *core) { + RzList *themes_list = rz_core_list_themes (core); + RzListIter *th_iter; char *th; int i = 0; - r_list_foreach (themes_list, th_iter, th) { + rz_list_foreach (themes_list, th_iter, th) { menus_Colors[i++] = th; } } -R_API bool r_load_panels_layout(RCore *core, const char *_name) { +RZ_API bool rz_load_panels_layout(RzCore *core, const char *_name) { if (!core->panels) { return false; } char *config_path = __get_panels_config_file_from_dir (_name); if (!config_path) { - char *tmp = r_str_newf ("No saved layout found for the name: %s", _name); + char *tmp = rz_str_newf ("No saved layout found for the name: %s", _name); (void)__show_status (core, tmp); free (tmp); return false; } - char *panels_config = r_file_slurp (config_path, NULL); + char *panels_config = rz_file_slurp (config_path, NULL); free (config_path); if (!panels_config) { - char *tmp = r_str_newf ("Layout is empty: %s", _name); + char *tmp = rz_str_newf ("Layout is empty: %s", _name); (void)__show_status (core, tmp); free (tmp); return false; @@ -5754,14 +5754,14 @@ R_API bool r_load_panels_layout(RCore *core, const char *_name) { char *title, *cmd, *x, *y, *w, *h, *p_cfg = panels_config, *tmp_cfg; int i, tmp_count; tmp_cfg = __parse_panels_config (p_cfg, strlen (p_cfg)); - tmp_count = r_str_split (tmp_cfg, '\n'); + tmp_count = rz_str_split (tmp_cfg, '\n'); for (i = 0; i < tmp_count; i++) { if (R_STR_ISEMPTY (tmp_cfg)) { break; } title = sdb_json_get_str (tmp_cfg, "Title"); cmd = sdb_json_get_str (tmp_cfg, "Cmd"); - (void)r_str_arg_unescape (cmd); + (void)rz_str_arg_unescape (cmd); x = sdb_json_get_str (tmp_cfg, "x"); y = sdb_json_get_str (tmp_cfg, "y"); w = sdb_json_get_str (tmp_cfg, "w"); @@ -5769,15 +5769,15 @@ R_API bool r_load_panels_layout(RCore *core, const char *_name) { RPanel *p = __get_panel (panels, panels->n_panels); __set_geometry (&p->view->pos, atoi (x), atoi (y), atoi (w),atoi (h)); __init_panel_param (core, p, title, cmd); - if (r_str_endswith (cmd, "Help")) { - p->model->title = r_str_dup (p->model->title, "Help"); - p->model->cmd = r_str_dup (p->model->cmd, "Help"); - RStrBuf *rsb = r_strbuf_new (NULL); - r_core_visual_append_help (rsb, "Visual Ascii Art Panels", help_msg_panels); + if (rz_str_endswith (cmd, "Help")) { + p->model->title = rz_str_dup (p->model->title, "Help"); + p->model->cmd = rz_str_dup (p->model->cmd, "Help"); + RStrBuf *rsb = rz_strbuf_new (NULL); + rz_core_visual_append_help (rsb, "Visual Ascii Art Panels", help_msg_panels); if (!rsb) { return false; } - __set_read_only (core, p, r_strbuf_drain (rsb)); + __set_read_only (core, p, rz_strbuf_drain (rsb)); } tmp_cfg += strlen (tmp_cfg) + 1; } @@ -5797,7 +5797,7 @@ void __maximize_panel_size(RPanels *panels) { cur->view->refresh = true; } -void __toggle_zoom_mode(RCore *core) { +void __toggle_zoom_mode(RzCore *core) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); if (panels->mode != PANEL_MODE_ZOOM) { @@ -5815,7 +5815,7 @@ void __toggle_zoom_mode(RCore *core) { } } -void __toggle_window_mode(RCore *core) { +void __toggle_window_mode(RzCore *core) { RPanels *panels = core->panels; if (panels->mode != PANEL_MODE_WINDOW) { panels->prevMode = panels->mode; @@ -5826,18 +5826,18 @@ void __toggle_window_mode(RCore *core) { } } -void __toggle_cache (RCore *core, RPanel *p) { +void __toggle_cache (RzCore *core, RPanel *p) { p->model->cache = !p->model->cache; __set_cmd_str_cache (core, p, NULL); p->view->refresh = true; } -void __toggle_help(RCore *core) { +void __toggle_help(RzCore *core) { RPanels *ps = core->panels; int i; for (i = 0; i < ps->n_panels; i++) { RPanel *p = __get_panel (ps, i); - if (r_str_endswith (p->model->cmd, "Help")) { + if (rz_str_endswith (p->model->cmd, "Help")) { __dismantle_del_panel (core, p, i); if (ps->mode == PANEL_MODE_MENU) { __set_mode (core, PANEL_MODE_DEFAULT); @@ -5852,20 +5852,20 @@ void __toggle_help(RCore *core) { __update_help (core, ps); } -void __set_breakpoints_on_cursor(RCore *core, RPanel *panel) { - if (!r_config_get_i (core->config, "cfg.debug")) { +void __set_breakpoints_on_cursor(RzCore *core, RPanel *panel) { + if (!rz_config_get_i (core->config, "cfg.debug")) { return; } if (__check_panel_type (panel, PANEL_CMD_DISASSEMBLY)) { - r_core_cmdf (core, "dbs 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "dbs 0x%08"PFMT64x, core->offset + core->print->cur); panel->view->refresh = true; } } -void __insert_value(RCore *core) { - if (!r_config_get_i (core->config, "io.cache")) { +void __insert_value(RzCore *core) { + if (!rz_config_get_i (core->config, "io.cache")) { if (__show_status_yesno (core, 1, "Insert is not available because io.cache is off. Turn on now?(Y/n)")) { - r_config_set_i (core->config, "io.cache", 1); + rz_config_set_i (core->config, "io.cache", 1); (void)__show_status (core, "io.cache is on and insert is available now."); } else { (void)__show_status (core, "You can always turn on io.cache in Menu->Edit->io.cache"); @@ -5878,35 +5878,35 @@ void __insert_value(RCore *core) { if (__check_panel_type (cur, PANEL_CMD_STACK)) { const char *prompt = "insert hex: "; __panel_prompt (prompt, buf, sizeof (buf)); - r_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, cur->model->addr); + rz_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, cur->model->addr); cur->view->refresh = true; } else if (__check_panel_type (cur, PANEL_CMD_REGISTERS)) { const char *creg = core->dbg->creg; if (creg) { const char *prompt = "new-reg-value> "; __panel_prompt (prompt, buf, sizeof (buf)); - r_core_cmdf (core, "dr %s = %s", creg, buf); + rz_core_cmdf (core, "dr %s = %s", creg, buf); cur->view->refresh = true; } } else if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { const char *prompt = "insert hex: "; __panel_prompt (prompt, buf, sizeof (buf)); - r_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, core->offset + core->print->cur); + rz_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, core->offset + core->print->cur); cur->view->refresh = true; } else if (__check_panel_type (cur, PANEL_CMD_HEXDUMP)) { const char *prompt = "insert hex: "; __panel_prompt (prompt, buf, sizeof (buf)); - r_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, cur->model->addr + core->print->cur); + rz_core_cmdf (core, "wx %s @ 0x%08" PFMT64x, buf, cur->model->addr + core->print->cur); cur->view->refresh = true; } } -RPanels *__panels_new(RCore *core) { +RPanels *__panels_new(RzCore *core) { RPanels *panels = R_NEW0 (RPanels); if (!panels) { return NULL; } - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); firstRun = true; if (!__init (core, panels, w, h)) { free (panels); @@ -5925,7 +5925,7 @@ void __renew_filter(RPanel *panel, int n) { panel->model->filter = filter; } -bool __move_to_direction(RCore *core, Direction direction) { +bool __move_to_direction(RzCore *core, Direction direction) { RPanels *panels = core->panels; RPanel *cur = __get_cur_panel (panels); int cur_x0 = cur->view->pos.x, cur_x1 = cur->view->pos.x + cur->view->pos.w - 1, cur_y0 = cur->view->pos.y, cur_y1 = cur->view->pos.y + cur->view->pos.h - 1; @@ -5981,10 +5981,10 @@ bool __move_to_direction(RCore *core, Direction direction) { return false; } -void __update_modal(RCore *core, Sdb *menu_db, RModal *modal) { +void __update_modal(RzCore *core, Sdb *menu_db, RModal *modal) { RPanels *panels = core->panels; - RConsCanvas *can = panels->can; - modal->data = r_strbuf_new (NULL); + RzConsCanvas *can = panels->can; + modal->data = rz_strbuf_new (NULL); int count = sdb_count (menu_db); if (modal->idx >= count) { modal->idx = 0; @@ -6012,19 +6012,19 @@ void __update_modal(RCore *core, Sdb *menu_db, RModal *modal) { i++; } } - r_cons_gotoxy (0, 0); - r_cons_canvas_fill (can, modal->pos.x, modal->pos.y, modal->pos.w + 2, modal->pos.h + 2, ' '); - (void)r_cons_canvas_gotoxy (can, modal->pos.x + 2, modal->pos.y + 1); - r_cons_canvas_write (can, r_strbuf_get (modal->data)); - r_strbuf_free (modal->data); + rz_cons_gotoxy (0, 0); + rz_cons_canvas_fill (can, modal->pos.x, modal->pos.y, modal->pos.w + 2, modal->pos.h + 2, ' '); + (void)rz_cons_canvas_gotoxy (can, modal->pos.x + 2, modal->pos.y + 1); + rz_cons_canvas_write (can, rz_strbuf_get (modal->data)); + rz_strbuf_free (modal->data); - r_cons_canvas_box (can, modal->pos.x, modal->pos.y, modal->pos.w + 2, modal->pos.h + 2, core->cons->context->pal.graph_box2); + rz_cons_canvas_box (can, modal->pos.x, modal->pos.y, modal->pos.w + 2, modal->pos.h + 2, core->cons->context->pal.graph_box2); - r_cons_canvas_print (can); - r_cons_flush (); + rz_cons_canvas_print (can); + rz_cons_flush (); } -bool __draw_modal (RCore *core, RModal *modal, int range_end, int start, const char *name) { +bool __draw_modal (RzCore *core, RModal *modal, int range_end, int start, const char *name) { if (start < modal->offset) { return true; } @@ -6032,16 +6032,16 @@ bool __draw_modal (RCore *core, RModal *modal, int range_end, int start, const c return false; } if (start == modal->idx) { - r_strbuf_appendf (modal->data, "> %s%s"Color_RESET, core->cons->context->pal.graph_box2, name); + rz_strbuf_appendf (modal->data, "> %s%s"Color_RESET, core->cons->context->pal.graph_box2, name); } else { - r_strbuf_appendf (modal->data, " %s", name); + rz_strbuf_appendf (modal->data, " %s", name); } - r_strbuf_append (modal->data, " \n"); + rz_strbuf_append (modal->data, " \n"); return true; } // TODO: rename to modal -void __create_almighty(RCore *core, RPanel *panel, Sdb *menu_db) { +void __create_almighty(RzCore *core, RPanel *panel, Sdb *menu_db) { __set_cursor (core, false); const int w = 40; const int h = 20; @@ -6053,11 +6053,11 @@ void __create_almighty(RCore *core, RPanel *panel, Sdb *menu_db) { char *word = NULL; __update_modal (core, menu_db, modal); while (modal) { - okey = r_cons_readchar (); - key = r_cons_arrow_to_hjkl (okey); + okey = rz_cons_readchar (); + key = rz_cons_arrow_to_hjkl (okey); word = NULL; if (key == INT8_MAX - 1) { - if (r_cons_get_click (&cx, &cy)) { + if (rz_cons_get_click (&cx, &cy)) { if ((cx < x || x + w < cx) || ((cy < y || y + h < cy))) { key = 'q'; @@ -6119,7 +6119,7 @@ void __create_almighty(RCore *core, RPanel *panel, Sdb *menu_db) { } } -void __exec_almighty(RCore *core, RPanel *panel, RModal *modal, Sdb *menu_db, RPanelLayout dir) { +void __exec_almighty(RzCore *core, RPanel *panel, RModal *modal, Sdb *menu_db, RPanelLayout dir) { SdbList *l = sdb_foreach_list (menu_db, true); SdbKv *kv; SdbListIter *iter; @@ -6133,7 +6133,7 @@ void __exec_almighty(RCore *core, RPanel *panel, RModal *modal, Sdb *menu_db, RP } } -void __delete_almighty(RCore *core, RModal *modal, Sdb *menu_db) { +void __delete_almighty(RzCore *core, RModal *modal, Sdb *menu_db) { SdbList *l = sdb_foreach_list (menu_db, true); SdbKv *kv; SdbListIter *iter; @@ -6145,7 +6145,7 @@ void __delete_almighty(RCore *core, RModal *modal, Sdb *menu_db) { } } -void __create_default_panels(RCore *core) { +void __create_default_panels(RzCore *core) { RPanels *panels = core->panels; panels->n_panels = 0; __set_curnode (core, 0); @@ -6167,7 +6167,7 @@ void __create_default_panels(RCore *core) { } } -void __rotate_panels(RCore *core, bool rev) { +void __rotate_panels(RzCore *core, bool rev) { RPanels *panels = core->panels; RPanel *first = __get_panel (panels, 0); RPanel *last = __get_panel (panels, panels->n_panels - 1); @@ -6194,7 +6194,7 @@ void __rotate_panels(RCore *core, bool rev) { } void __rotate_disasm_cb(void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *p = __get_cur_panel (core->panels); //TODO: need to come up with a better solution but okay for now @@ -6212,11 +6212,11 @@ void __rotate_disasm_cb(void *user, bool rev) { } else { p->model->rotate++; } - r_core_visual_applyDisMode (core, p->model->rotate); + rz_core_visual_applyDisMode (core, p->model->rotate); __rotate_asmemu (core, p); } -void __rotate_panel_cmds(RCore *core, const char **cmds, const int cmdslen, const char *prefix, bool rev) { +void __rotate_panel_cmds(RzCore *core, const char **cmds, const int cmdslen, const char *prefix, bool rev) { if (!cmdslen) { return; } @@ -6234,30 +6234,30 @@ void __rotate_panel_cmds(RCore *core, const char **cmds, const int cmdslen, cons char tmp[64], *between; int i = p->model->rotate % cmdslen; snprintf (tmp, sizeof (tmp), "%s%s", prefix, cmds[i]); - between = r_str_between (p->model->cmd, prefix, " "); + between = rz_str_between (p->model->cmd, prefix, " "); if (between) { char replace[64]; snprintf (replace, sizeof (replace), "%s%s", prefix, between); - p->model->cmd = r_str_replace (p->model->cmd, replace, tmp, 1); + p->model->cmd = rz_str_replace (p->model->cmd, replace, tmp, 1); } else { - p->model->cmd = r_str_dup (p->model->cmd, tmp); + p->model->cmd = rz_str_dup (p->model->cmd, tmp); } __set_cmd_str_cache (core, p, NULL); p->view->refresh = true; } void __rotate_entropy_v_cb(void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __rotate_panel_cmds (core, entropy_rotate, COUNT (entropy_rotate), "p=", rev); } void __rotate_entropy_h_cb(void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __rotate_panel_cmds (core, entropy_rotate, COUNT (entropy_rotate), "p==", rev); } void __rotate_hexdump_cb (void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; RPanel *p = __get_cur_panel (core->panels); if (rev) { @@ -6265,33 +6265,33 @@ void __rotate_hexdump_cb (void *user, bool rev) { } else { p->model->rotate++; } - r_core_visual_applyHexMode (core, p->model->rotate); + rz_core_visual_applyHexMode (core, p->model->rotate); __rotate_asmemu (core, p); } void __rotate_register_cb (void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __rotate_panel_cmds (core, register_rotate, COUNT (register_rotate), "dr", rev); } void __rotate_function_cb (void *user, bool rev) { - RCore *core = (RCore *)user; + RzCore *core = (RzCore *)user; __rotate_panel_cmds (core, function_rotate, COUNT (function_rotate), "af", rev); } -void __undo_seek(RCore *core) { +void __undo_seek(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); if (!__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { return; } - RIOUndos *undo = r_io_sundo (core->io, core->offset); + RzIOUndos *undo = rz_io_sundo (core->io, core->offset); if (undo) { - r_core_visual_seek_animation (core, undo->off); + rz_core_visual_seek_animation (core, undo->off); __set_panel_addr (core, cur, core->offset); } } -void __set_filter(RCore *core, RPanel *panel) { +void __set_filter(RzCore *core, RPanel *panel) { if (!panel->model->filter) { return; } @@ -6304,7 +6304,7 @@ void __set_filter(RCore *core, RPanel *panel) { __reset_scroll_pos (panel); } -void __reset_filter(RCore *core, RPanel *panel) { +void __reset_filter(RzCore *core, RPanel *panel) { free (panel->model->filter); panel->model->filter = NULL; __renew_filter (panel, PANEL_NUM_LIMIT); @@ -6313,36 +6313,36 @@ void __reset_filter(RCore *core, RPanel *panel) { __reset_scroll_pos (panel); } -void __redo_seek(RCore *core) { +void __redo_seek(RzCore *core) { RPanel *cur = __get_cur_panel (core->panels); if (!__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { return; } - RIOUndos *undo = r_io_sundo_redo (core->io); + RzIOUndos *undo = rz_io_sundo_redo (core->io); if (undo) { - r_core_visual_seek_animation (core, undo->off); + rz_core_visual_seek_animation (core, undo->off); __set_panel_addr (core, cur, core->offset); } } -void __rotate_asmemu(RCore *core, RPanel *p) { - const bool isEmuStr = r_config_get_i (core->config, "emu.str"); - const bool isEmu = r_config_get_i (core->config, "asm.emu"); +void __rotate_asmemu(RzCore *core, RPanel *p) { + const bool isEmuStr = rz_config_get_i (core->config, "emu.str"); + const bool isEmu = rz_config_get_i (core->config, "asm.emu"); if (isEmu) { if (isEmuStr) { - r_config_set (core->config, "emu.str", "false"); + rz_config_set (core->config, "emu.str", "false"); } else { - r_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "asm.emu", "false"); } } else { - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "emu.str", "true"); } p->view->refresh = true; } static bool fromVisual = false; -R_API bool r_core_visual_panels_root(RCore *core, RPanelsRoot *panels_root) { +RZ_API bool rz_core_visual_panels_root(RzCore *core, RPanelsRoot *panels_root) { fromVisual = core->vmode; if (!panels_root) { panels_root = R_NEW0 (RPanelsRoot); @@ -6363,19 +6363,19 @@ R_API bool r_core_visual_panels_root(RCore *core, RPanelsRoot *panels_root) { panels_root->cur_panels = 0; __init_new_panels_root (core); } - const char *pdc_now = r_config_get (core->config, "cmd.pdc"); + const char *pdc_now = rz_config_get (core->config, "cmd.pdc"); if (sdb_exists (panels_root->pdc_caches, pdc_now)) { - panels_root->cur_pdc_cache = sdb_ptr_get (panels_root->pdc_caches, r_str_new (pdc_now), 0); + panels_root->cur_pdc_cache = sdb_ptr_get (panels_root->pdc_caches, rz_str_new (pdc_now), 0); } else { Sdb *sdb = sdb_new0(); - sdb_ptr_set (panels_root->pdc_caches, r_str_new (pdc_now), sdb, 0); + sdb_ptr_set (panels_root->pdc_caches, rz_str_new (pdc_now), sdb, 0); panels_root->cur_pdc_cache = sdb; } } { - const char *l = r_config_get (core->config, "scr.layout"); + const char *l = rz_config_get (core->config, "scr.layout"); if (l && *l) { - r_core_cmdf (core, "v %s", l); + rz_core_cmdf (core, "v %s", l); } } RPanels *panels = panels_root->panels[panels_root->cur_panels]; @@ -6398,14 +6398,14 @@ R_API bool r_core_visual_panels_root(RCore *core, RPanelsRoot *panels_root) { break; } } - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); if (fromVisual) { - r_core_cmdf (core, "V"); + rz_core_cmdf (core, "V"); } return true; } -void __init_new_panels_root(RCore *core) { +void __init_new_panels_root(RzCore *core) { RPanelsRoot *panels_root = core->panels_root; RPanels *panels = __panels_new (core); if (!panels) { @@ -6429,11 +6429,11 @@ void __init_new_panels_root(RCore *core) { core->panels = prev; } -void __set_root_state(RCore *core, RPanelsRootState state) { +void __set_root_state(RzCore *core, RPanelsRootState state) { core->panels_root->root_state = state; } -void __del_panels(RCore *core) { +void __del_panels(RzCore *core) { RPanelsRoot *panels_root = core->panels_root; if (panels_root->n_panels <= 1) { core->panels_root->root_state = QUIT; @@ -6456,17 +6456,17 @@ RPanels *__get_panels(RPanelsRoot *panels_root, int i) { return panels_root->panels[i]; } -void __handle_tab(RCore *core) { - r_cons_gotoxy (0, 0); +void __handle_tab(RzCore *core) { + rz_cons_gotoxy (0, 0); if (core->panels_root->n_panels <= 1) { - r_cons_printf (R_CONS_CLEAR_LINE"%s[Tab] t:new T:new with current panel -:del =:name"Color_RESET, core->cons->context->pal.graph_box2); + rz_cons_printf (R_CONS_CLEAR_LINE"%s[Tab] t:new T:new with current panel -:del =:name"Color_RESET, core->cons->context->pal.graph_box2); } else { int min = 1; int max = core->panels_root->n_panels; - r_cons_printf (R_CONS_CLEAR_LINE"%s[Tab] [%d..%d]:select; p:prev; n:next; t:new T:new with current panel -:del =:name"Color_RESET, core->cons->context->pal.graph_box2, min, max); + rz_cons_printf (R_CONS_CLEAR_LINE"%s[Tab] [%d..%d]:select; p:prev; n:next; t:new T:new with current panel -:del =:name"Color_RESET, core->cons->context->pal.graph_box2, min, max); } - r_cons_flush (); - int ch = r_cons_readchar (); + rz_cons_flush (); + int ch = rz_cons_readchar (); if (isdigit (ch)) { __handle_tab_nth (core, ch); @@ -6495,7 +6495,7 @@ void __handle_tab(RCore *core) { } } -void __handle_tab_nth(RCore *core, int ch) { +void __handle_tab_nth(RzCore *core, int ch) { ch -= '0' + 1; if (ch < 0) { return; @@ -6506,7 +6506,7 @@ void __handle_tab_nth(RCore *core, int ch) { } } -void __handle_tab_next(RCore *core) { +void __handle_tab_next(RzCore *core) { if (core->panels_root->n_panels > 1) { core->panels_root->cur_panels++; core->panels_root->cur_panels %= core->panels_root->n_panels; @@ -6514,18 +6514,18 @@ void __handle_tab_next(RCore *core) { } } -void __handle_print_rotate(RCore *core) { - if (r_config_get_i (core->config, "asm.pseudo")) { - r_config_toggle (core->config, "asm.pseudo"); - r_config_toggle (core->config, "asm.esil"); - } else if (r_config_get_i (core->config, "asm.esil")) { - r_config_toggle (core->config, "asm.esil"); +void __handle_print_rotate(RzCore *core) { + if (rz_config_get_i (core->config, "asm.pseudo")) { + rz_config_toggle (core->config, "asm.pseudo"); + rz_config_toggle (core->config, "asm.esil"); + } else if (rz_config_get_i (core->config, "asm.esil")) { + rz_config_toggle (core->config, "asm.esil"); } else { - r_config_toggle (core->config, "asm.pseudo"); + rz_config_toggle (core->config, "asm.pseudo"); } } -void __handle_tab_prev(RCore *core) { +void __handle_tab_prev(RzCore *core) { if (core->panels_root->n_panels > 1) { core->panels_root->cur_panels--; if (core->panels_root->cur_panels < 0) { @@ -6535,18 +6535,18 @@ void __handle_tab_prev(RCore *core) { } } -void __handle_tab_name(RCore *core) { +void __handle_tab_name(RzCore *core) { core->panels->name = __show_status_input (core, "tab name: "); } -void __handle_tab_new(RCore *core) { +void __handle_tab_new(RzCore *core) { if (core->panels_root->n_panels >= PANEL_NUM_LIMIT) { return; } __init_new_panels_root (core); } -void __handle_tab_new_with_cur_panel (RCore *core) { +void __handle_tab_new_with_cur_panel (RzCore *core) { RPanels *panels = core->panels; if (panels->n_panels <= 1) { return; @@ -6578,8 +6578,8 @@ void __handle_tab_new_with_cur_panel (RCore *core) { RPanel *new_panel = __get_panel (new_panels, 0); __init_panel_param (core, new_panel, cur->model->title, cur->model->cmd); new_panel->model->cache = cur->model->cache; - new_panel->model->funcName = r_str_new (cur->model->funcName); - __set_cmd_str_cache (core, new_panel, r_str_new (cur->model->cmdStrCache)); + new_panel->model->funcName = rz_str_new (cur->model->funcName); + __set_cmd_str_cache (core, new_panel, rz_str_new (cur->model->cmdStrCache)); __maximize_panel_size (new_panels); core->panels = prev; @@ -6592,32 +6592,32 @@ void __handle_tab_new_with_cur_panel (RCore *core) { } void __panel_prompt(const char *prompt, char *buf, int len) { - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); *buf = 0; - r_cons_fgets (buf, len, 0, NULL); + rz_cons_fgets (buf, len, 0, NULL); } -char *get_word_from_canvas(RCore *core, RPanels *panels, int x, int y) { +char *get_word_from_canvas(RzCore *core, RPanels *panels, int x, int y) { RStrBuf rsb; - r_strbuf_init (&rsb); - char *cs = r_cons_canvas_to_string (panels->can); - r_strbuf_setf (&rsb, " %s", cs); - char *R = r_str_ansi_crop (r_strbuf_get (&rsb), 0, y - 1, x + 1024, y); - r_str_ansi_filter (R, NULL, NULL, -1); - char *r = r_str_ansi_crop (r_strbuf_get (&rsb), x - 1, y - 1, x + 1024, y); - r_str_ansi_filter (r, NULL, NULL, -1); + rz_strbuf_init (&rsb); + char *cs = rz_cons_canvas_to_string (panels->can); + rz_strbuf_setf (&rsb, " %s", cs); + char *R = rz_str_ansi_crop (rz_strbuf_get (&rsb), 0, y - 1, x + 1024, y); + rz_str_ansi_filter (R, NULL, NULL, -1); + char *r = rz_str_ansi_crop (rz_strbuf_get (&rsb), x - 1, y - 1, x + 1024, y); + rz_str_ansi_filter (r, NULL, NULL, -1); char *pos = strstr (R, r); if (!pos) { pos = R; } #define TOkENs ":=*+-/()[,] " - const char *sp = r_str_rsep (R, pos, TOkENs); + const char *sp = rz_str_rsep (R, pos, TOkENs); if (sp) { sp++; } else { sp = pos; } - char *sp2 = (char *)r_str_sep (sp, TOkENs); + char *sp2 = (char *)rz_str_sep (sp, TOkENs); if (sp2) { *sp2 = 0; } @@ -6625,16 +6625,16 @@ char *get_word_from_canvas(RCore *core, RPanels *panels, int x, int y) { free (r); free (R); free (cs); - r_strbuf_fini (&rsb); + rz_strbuf_fini (&rsb); return res; } -char *get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x, int y) { - char *cs = r_cons_canvas_to_string (panels->can); - char *R = r_str_ansi_crop (cs, 0, y - 1, x + 1024, y); - r_str_ansi_filter (R, NULL, NULL, -1); - char *r = r_str_ansi_crop (cs, x - 1, y - 1, x + 1024, y); - r_str_ansi_filter (r, NULL, NULL, -1); +char *get_word_from_canvas_for_menu(RzCore *core, RPanels *panels, int x, int y) { + char *cs = rz_cons_canvas_to_string (panels->can); + char *R = rz_str_ansi_crop (cs, 0, y - 1, x + 1024, y); + rz_str_ansi_filter (R, NULL, NULL, -1); + char *r = rz_str_ansi_crop (cs, x - 1, y - 1, x + 1024, y); + rz_str_ansi_filter (r, NULL, NULL, -1); char *pos = strstr (R, r); char *tmp = pos; const char *padding = " "; @@ -6650,7 +6650,7 @@ char *get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x, int y) tmp++; i++; } - char *ret = r_str_newlen (pos += strlen (padding), i - strlen (padding)); + char *ret = rz_str_newlen (pos += strlen (padding), i - strlen (padding)); if (!ret) { ret = strdup (pos); } @@ -6660,7 +6660,7 @@ char *get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x, int y) return ret; } -void __panels_process(RCore *core, RPanels *panels) { +void __panels_process(RzCore *core, RPanels *panels) { if (!panels) { return; } @@ -6670,11 +6670,11 @@ void __panels_process(RCore *core, RPanels *panels) { prev = core->panels; core->panels = panels; panels->autoUpdate = true; - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); panels->can = __create_new_canvas (core, w, h); __set_refresh_all (core, false, true); - r_cons_switchbuf (false); + rz_cons_switchbuf (false); int originCursor = core->print->cur; core->print->cur = 0; @@ -6684,23 +6684,23 @@ void __panels_process(RCore *core, RPanels *panels) { bool originVmode = core->vmode; core->vmode = true; { - const char *layout = r_config_get (core->config, "scr.layout"); + const char *layout = rz_config_get (core->config, "scr.layout"); if (R_STR_ISNOTEMPTY (layout)) { - r_load_panels_layout (core, layout); + rz_load_panels_layout (core, layout); } } - bool o_interactive = r_cons_is_interactive (); - r_cons_set_interactive (true); - r_core_visual_showcursor (core, false); + bool o_interactive = rz_cons_is_interactive (); + rz_cons_set_interactive (true); + rz_core_visual_showcursor (core, false); - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); repeat: - r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel")); + rz_cons_enable_mouse (rz_config_get_i (core->config, "scr.wheel")); core->panels = panels; core->cons->event_resize = NULL; // avoid running old event with new data core->cons->event_data = core; - core->cons->event_resize = (RConsEvent) __do_panels_refreshOneShot; + core->cons->event_resize = (RzConsEvent) __do_panels_refreshOneShot; __panels_layout_refresh (core); RPanel *cur = __get_cur_panel (panels); if (panels->fun == PANEL_FUN_SNOW || panels->fun == PANEL_FUN_SAKURA) { @@ -6709,16 +6709,16 @@ repeat: __reset_snow (panels); goto repeat; } - okey = r_cons_readchar_timeout (300); + okey = rz_cons_readchar_timeout (300); if (okey == -1) { cur->view->refresh = true; goto repeat; } } else { - okey = r_cons_readchar (); + okey = rz_cons_readchar (); } - key = r_cons_arrow_to_hjkl (okey); + key = rz_cons_arrow_to_hjkl (okey); if (__handle_mouse (core, cur, &key)) { if (panels_root->root_state != DEFAULT) { goto exit; @@ -6726,7 +6726,7 @@ repeat: goto repeat; } - r_cons_switchbuf (true); + rz_cons_switchbuf (true); if (panels->mode == PANEL_MODE_MENU) { __handle_menu (core, key); @@ -6757,13 +6757,13 @@ repeat: if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY) && '0' < key && key <= '9') { ut8 ch = key; - r_core_visual_jump (core, ch); + rz_core_visual_jump (core, ch); __set_panel_addr (core, cur, core->offset); goto repeat; } const char *cmd; - RConsCanvas *can = panels->can; + RzConsCanvas *can = panels->can; if (__handle_console (core, cur, key)) { goto repeat; } @@ -6782,13 +6782,13 @@ repeat: break; case '.': if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { - ut64 addr = r_debug_reg_get (core->dbg, "PC"); + ut64 addr = rz_debug_reg_get (core->dbg, "PC"); if (addr && addr != UT64_MAX) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } else { - addr = r_num_get (core->num, "entry0"); + addr = rz_num_get (core->num, "entry0"); if (addr && addr != UT64_MAX) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } } __set_panel_addr (core, cur, core->offset); @@ -6798,16 +6798,16 @@ repeat: __toggle_help (core); break; case 'b': - r_core_visual_browse (core, NULL); + rz_core_visual_browse (core, NULL); break; case ';': __handleComment (core); break; case '$': if (core->print->cur_enabled) { - r_core_cmdf (core, "dr PC=$$+%d", core->print->cur); + rz_core_cmdf (core, "dr PC=$$+%d", core->print->cur); } else { - r_core_cmd0 (core, "dr PC=$$"); + rz_core_cmd0 (core, "dr PC=$$"); } break; case 's': @@ -6823,14 +6823,14 @@ repeat: } break; case ' ': - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "agv $$"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "agv $$"); } else { __call_visual_graph (core); } break; case ':': - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); __set_panel_addr (core, cur, core->offset); break; case 'c': @@ -6838,38 +6838,38 @@ repeat: break; case 'C': { - int color = r_config_get_i (core->config, "scr.color"); + int color = rz_config_get_i (core->config, "scr.color"); if (++color > 2) { color = 0; } - r_config_set_i (core->config, "scr.color", color); + rz_config_set_i (core->config, "scr.color", color); can->color = color; __set_refresh_all (core, true, false); } break; case 'r': // TODO: toggle shortcut hotkeys - if (r_config_get_i (core->config, "asm.hint.call")) { - r_core_cmd0 (core, "e!asm.hint.call"); - r_core_cmd0 (core, "e asm.hint.jmp=true"); - } else if (r_config_get_i (core->config, "asm.hint.jmp")) { - r_core_cmd0 (core, "e!asm.hint.jmp"); - r_core_cmd0 (core, "e asm.hint.emu=true"); - } else if (r_config_get_i (core->config, "asm.hint.emu")) { - r_core_cmd0 (core, "e!asm.hint.emu"); - r_core_cmd0 (core, "e asm.hint.lea=true"); - } else if (r_config_get_i (core->config, "asm.hint.lea")) { - r_core_cmd0 (core, "e!asm.hint.lea"); - r_core_cmd0 (core, "e asm.hint.call=true"); + if (rz_config_get_i (core->config, "asm.hint.call")) { + rz_core_cmd0 (core, "e!asm.hint.call"); + rz_core_cmd0 (core, "e asm.hint.jmp=true"); + } else if (rz_config_get_i (core->config, "asm.hint.jmp")) { + rz_core_cmd0 (core, "e!asm.hint.jmp"); + rz_core_cmd0 (core, "e asm.hint.emu=true"); + } else if (rz_config_get_i (core->config, "asm.hint.emu")) { + rz_core_cmd0 (core, "e!asm.hint.emu"); + rz_core_cmd0 (core, "e asm.hint.lea=true"); + } else if (rz_config_get_i (core->config, "asm.hint.lea")) { + rz_core_cmd0 (core, "e!asm.hint.lea"); + rz_core_cmd0 (core, "e asm.hint.call=true"); } else { - r_core_cmd0 (core, "e asm.hint.call=true"); + rz_core_cmd0 (core, "e asm.hint.call=true"); } break; case 'R': - if (r_config_get_i (core->config, "scr.randpal")) { - r_core_cmd0 (core, "ecr"); + if (rz_config_get_i (core->config, "scr.randpal")) { + rz_core_cmd0 (core, "ecr"); } else { - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); } __do_panels_refresh (core); break; @@ -6879,30 +6879,30 @@ repeat: case 'A': { const int ocur = core->print->cur_enabled; - r_core_visual_asm (core, core->offset); + rz_core_visual_asm (core, core->offset); core->print->cur_enabled = ocur; } break; case 'd': - r_core_visual_define (core, "", 0); + rz_core_visual_define (core, "", 0); break; case 'D': __replace_cmd (core, PANEL_TITLE_DISASSEMBLY, PANEL_CMD_DISASSEMBLY); break; case 'j': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { cur->model->directionCb (core, (int)DOWN); } break; case 'k': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { cur->model->directionCb (core, (int)UP); } break; case 'K': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { for (i = 0; i < __get_cur_panel (panels)->view->pos.h / 2 - 6; i++) { cur->model->directionCb (core, (int)UP); @@ -6910,7 +6910,7 @@ repeat: } break; case 'J': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { for (i = 0; i < __get_cur_panel (panels)->view->pos.h / 2 - 6; i++) { cur->model->directionCb (core, (int)DOWN); @@ -6918,7 +6918,7 @@ repeat: } break; case 'H': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { for (i = 0; i < __get_cur_panel (panels)->view->pos.w / 3; i++) { cur->model->directionCb (core, (int)LEFT); @@ -6926,7 +6926,7 @@ repeat: } break; case 'L': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { for (i = 0; i < __get_cur_panel (panels)->view->pos.w / 3; i++) { cur->model->directionCb (core, (int)RIGHT); @@ -6943,10 +6943,10 @@ repeat: __hudstuff (core); break; case '\\': - r_core_visual_hud (core); + rz_core_visual_hud (core); break; case '"': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); __create_almighty (core, cur, panels->almighty_db); if (__check_root_state (core, ROTATE)) { goto exit; @@ -6963,13 +6963,13 @@ repeat: break; case 'n': if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { - r_core_seek_next (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_next (core, rz_config_get (core->config, "scr.nkey")); __set_panel_addr (core, cur, core->offset); } break; case 'N': if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { - r_core_seek_previous (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_previous (core, rz_config_get (core->config, "scr.nkey")); __set_panel_addr (core, cur, core->offset); } break; @@ -6979,7 +6979,7 @@ repeat: case 'X': #if 0 // already accessible via xX - r_core_visual_refs (core, false, true); + rz_core_visual_refs (core, false, true); cur->model->addr = core->offset; set_refresh_all (panels, false); #endif @@ -7009,62 +7009,62 @@ repeat: __get_cur_panel (panels)->view->refresh = true; break; case 'g': - r_core_visual_showcursor (core, true); - r_core_visual_offset (core); - r_core_visual_showcursor (core, false); + rz_core_visual_showcursor (core, true); + rz_core_visual_offset (core); + rz_core_visual_showcursor (core, false); __set_panel_addr (core, cur, core->offset); break; case 'G': { - const char *hl = r_config_get (core->config, "scr.highlight"); + const char *hl = rz_config_get (core->config, "scr.highlight"); if (hl) { - ut64 addr = r_num_math (core->num, hl); + ut64 addr = rz_num_math (core->num, hl); __set_panel_addr (core, cur, addr); - // r_io_sundo_push (core->io, addr, false); // doesnt seems to work + // rz_io_sundo_push (core->io, addr, false); // doesnt seems to work } } break; case 'h': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { cur->model->directionCb (core, (int)LEFT); } break; case 'l': - r_cons_switchbuf (false); + rz_cons_switchbuf (false); if (cur->model->directionCb) { cur->model->directionCb (core, (int)RIGHT); } break; case 'V': - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "agv $$"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "agv $$"); } else { __call_visual_graph (core); } break; case ']': if (__check_panel_type (cur, PANEL_CMD_HEXDUMP)) { - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") + 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") + 1); } else { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); - r_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); } cur->view->refresh = true; break; case '[': if (__check_panel_type (cur, PANEL_CMD_HEXDUMP)) { - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") - 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") - 1); } else { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); if (cmtcol > 2) { - r_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); } } cur->view->refresh = true; break; case '/': - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); break; case 'z': if (panels->curnode > 0) { @@ -7119,12 +7119,12 @@ repeat: } case '*': if (__check_func (core)) { - r_cons_canvas_free (can); + rz_cons_canvas_free (can); panels->can = NULL; __replace_cmd (core, PANEL_TITLE_DECOMPILER, PANEL_CMD_DECOMPILER); - int h, w = r_cons_get_size (&h); + int h, w = rz_cons_get_size (&h); panels->can = __create_new_canvas (core, w, h); } break; @@ -7145,47 +7145,47 @@ repeat: __toggle_cache (core, __get_cur_panel (panels)); break; case R_CONS_KEY_F1: - cmd = r_config_get (core->config, "key.f1"); + cmd = rz_config_get (core->config, "key.f1"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F2: - cmd = r_config_get (core->config, "key.f2"); + cmd = rz_config_get (core->config, "key.f2"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { __panel_breakpoint (core); } break; case R_CONS_KEY_F3: - cmd = r_config_get (core->config, "key.f3"); + cmd = rz_config_get (core->config, "key.f3"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F4: - cmd = r_config_get (core->config, "key.f4"); + cmd = rz_config_get (core->config, "key.f4"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F5: - cmd = r_config_get (core->config, "key.f5"); + cmd = rz_config_get (core->config, "key.f5"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F6: - cmd = r_config_get (core->config, "key.f6"); + cmd = rz_config_get (core->config, "key.f6"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F7: - cmd = r_config_get (core->config, "key.f7"); + cmd = rz_config_get (core->config, "key.f7"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { __panel_single_step_in (core); if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { @@ -7194,9 +7194,9 @@ repeat: } break; case R_CONS_KEY_F8: - cmd = r_config_get (core->config, "key.f8"); + cmd = rz_config_get (core->config, "key.f8"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { __panel_single_step_over (core); if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { @@ -7205,9 +7205,9 @@ repeat: } break; case R_CONS_KEY_F9: - cmd = r_config_get (core->config, "key.f9"); + cmd = rz_config_get (core->config, "key.f9"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } else { if (__check_panel_type (cur, PANEL_CMD_DISASSEMBLY)) { __panel_continue (core); @@ -7216,21 +7216,21 @@ repeat: } break; case R_CONS_KEY_F10: - cmd = r_config_get (core->config, "key.f10"); + cmd = rz_config_get (core->config, "key.f10"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F11: - cmd = r_config_get (core->config, "key.f11"); + cmd = rz_config_get (core->config, "key.f11"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F12: - cmd = r_config_get (core->config, "key.f12"); + cmd = rz_config_get (core->config, "key.f12"); if (cmd && *cmd) { - (void)r_core_cmd0 (core, cmd); + (void)rz_core_cmd0 (core, cmd); } break; case 'Q': @@ -7242,15 +7242,15 @@ repeat: case -1: // EOF __set_root_state (core, DEL); if (core->panels_root->n_panels < 2) { - if (r_config_get_i (core->config, "scr.demo")) { + if (rz_config_get_i (core->config, "scr.demo")) { demo_end (core, can); } } goto exit; #if 0 case 27: // ESC - if (r_cons_readchar () == 91) { - if (r_cons_readchar () == 90) {} + if (rz_cons_readchar () == 91) { + if (rz_cons_readchar () == 90) {} } break; #endif @@ -7262,7 +7262,7 @@ repeat: goto repeat; exit: if (!originVmode) { - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); } core->cons->event_resize = NULL; core->cons->event_data = NULL; @@ -7271,5 +7271,5 @@ exit: core->print->col = 0; core->vmode = originVmode; core->panels = prev; - r_cons_set_interactive (o_interactive); + rz_cons_set_interactive (o_interactive); } diff --git a/libr/core/patch.c b/librz/core/patch.c similarity index 55% rename from libr/core/patch.c rename to librz/core/patch.c index d597acfa0b..bbddfda8e4 100644 --- a/libr/core/patch.c +++ b/librz/core/patch.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include +#include -R_API int r_core_patch_line(RCore *core, char *str) { +RZ_API int rz_core_patch_line(RzCore *core, char *str) { char *p, *q; p = strchr (str + 1, ' '); if (!p) { @@ -19,12 +19,12 @@ R_API int r_core_patch_line(RCore *core, char *str) { if (q) { *q = 0; } - r_core_cmdf (core, "s %s", str); - r_core_cmdf (core, "\"w %s\"", p+1); + rz_core_cmdf (core, "s %s", str); + rz_core_cmdf (core, "\"w %s\"", p+1); break; case ':': - r_core_cmdf (core, "s %s", str); - r_core_cmdf (core, "\"wa %s\"", p); + rz_core_cmdf (core, "s %s", str); + rz_core_cmdf (core, "\"wa %s\"", p); break; case 'v': q = strchr (p + 1,' '); @@ -36,27 +36,27 @@ R_API int r_core_patch_line(RCore *core, char *str) { } else { return 0; } - r_core_cmdf (core, "s %s", str); - r_core_cmdf (core, "wv%s %s", p + 1, q); + rz_core_cmdf (core, "s %s", str); + rz_core_cmdf (core, "wv%s %s", p + 1, q); break; default: - r_core_cmdf (core, "s %s", str); - r_core_cmdf (core, "wx %s", p); + rz_core_cmdf (core, "s %s", str); + rz_core_cmdf (core, "wx %s", p); break; } return 1; } -static int __core_patch_bracket(RCore *core, const char *str, ut64 *noff) { +static int __core_patch_bracket(RzCore *core, const char *str, ut64 *noff) { char tmp[128]; char *s, *p, *q, *off; - RBuffer *b = r_buf_new (); + RBuffer *b = rz_buf_new (); if (!b) { return 0; } p = off = strdup (str); if (!p) { - r_buf_free (b); + rz_buf_free (b); return 0; } for (;*p;) { @@ -73,40 +73,40 @@ static int __core_patch_bracket(RCore *core, const char *str, ut64 *noff) { char *end = strchr (q+2,'}'); if (end) { *q = *end = 0; - *noff = r_num_math (core->num, q+2); - r_buf_append_bytes (b, (const ut8*)str, strlen (str)); + *noff = rz_num_math (core->num, q+2); + rz_buf_append_bytes (b, (const ut8*)str, strlen (str)); snprintf (tmp, sizeof (tmp), "0x%08"PFMT64x, *noff); - r_buf_append_bytes (b, (const ut8*)tmp, strlen (tmp)); - r_buf_append_bytes (b, (const ut8*)end+1, strlen (end+1)); + rz_buf_append_bytes (b, (const ut8*)tmp, strlen (tmp)); + rz_buf_append_bytes (b, (const ut8*)end+1, strlen (end+1)); } } else { - r_buf_append_bytes (b, (const ut8*)str, strlen (str)); + rz_buf_append_bytes (b, (const ut8*)str, strlen (str)); } str = p; } - s = r_buf_to_string (b); - r_egg_load (core->egg, s, 0); + s = rz_buf_to_string (b); + rz_egg_load (core->egg, s, 0); free (s); - (void)r_egg_compile (core->egg); - (void)r_egg_assemble (core->egg); + (void)rz_egg_compile (core->egg); + (void)rz_egg_assemble (core->egg); - r_buf_free (b); - b = r_egg_get_bin (core->egg); + rz_buf_free (b); + b = rz_egg_get_bin (core->egg); if (strcmp (off, "+")) { - *noff = r_num_math (core->num, off); + *noff = rz_num_math (core->num, off); } ut64 tmpsz; - const ut8 *tmpbuf = r_buf_data (b, &tmpsz); - r_core_write_at (core, *noff, tmpbuf, tmpsz); - *noff += r_buf_size (b); + const ut8 *tmpbuf = rz_buf_data (b, &tmpsz); + rz_core_write_at (core, *noff, tmpbuf, tmpsz); + *noff += rz_buf_size (b); free (off); return 1; } -R_API int r_core_patch(RCore *core, const char *patch) { +RZ_API int rz_core_patch(RzCore *core, const char *patch) { char *p, *p0, *str; ut64 noff = 0LL; @@ -129,17 +129,17 @@ R_API int r_core_patch(RCore *core, const char *patch) { case '\0': break; case ':': - r_core_cmd0 (core, str+1); + rz_core_cmd0 (core, str+1); break; case '.': case '!': - r_core_cmd0 (core, str); + rz_core_cmd0 (core, str); break; case '{': (void)__core_patch_bracket (core, str, &noff); break; default: - r_core_patch_line (core, str); + rz_core_patch_line (core, str); break; } if (!*p) { diff --git a/librz/core/project.c b/librz/core/project.c new file mode 100644 index 0000000000..12b04c84c7 --- /dev/null +++ b/librz/core/project.c @@ -0,0 +1,939 @@ +/* radare - LGPL - Copyright 2010-2020 - pancake, maijin */ + +#include +#include +#include +#include +#define USE_R2 1 +#include + +static bool is_valid_project_name(const char *name) { + int i; + if (rz_str_endswith (name, ".zip")) { + return false; + } + for (i = 0; name[i]; i++) { + switch (name[i]) { + case '\\': // for w32 + case '.': + case '_': + case ':': + case '-': + continue; + } + if (name[i] >= 'a' && name[i] <= 'z') { + continue; + } + if (name[i] >= 'A' && name[i] <= 'Z') { + continue; + } + if (IS_DIGIT (name[i])) { + continue; + } + return false; + } + return true; +} + +static char *get_project_script_path(RzCore *core, const char *file) { + const char *magic = "# r2 rdb project file"; + char *data, *prjfile; + if (rz_file_is_abspath (file)) { + prjfile = strdup (file); + } else { + if (!is_valid_project_name (file)) { + return NULL; + } + prjfile = rz_file_abspath (rz_config_get (core->config, "dir.projects")); + prjfile = rz_str_append (prjfile, R_SYS_DIR); + prjfile = rz_str_append (prjfile, file); + if (!rz_file_exists (prjfile) || rz_file_is_directory (prjfile)) { + prjfile = rz_str_append (prjfile, R_SYS_DIR "rc"); + } + } + data = rz_file_slurp (prjfile, NULL); + if (data) { + if (strncmp (data, magic, strlen (magic))) { + R_FREE (prjfile); + } + } + free (data); + return prjfile; +} + +static int make_projects_directory(RzCore *core) { + char *prjdir = rz_file_abspath (rz_config_get (core->config, "dir.projects")); + int ret = rz_sys_mkdirp (prjdir); + if (!ret) { + eprintf ("Cannot mkdir dir.projects\n"); + } + free (prjdir); + return ret; +} + +RZ_API bool rz_core_is_project(RzCore *core, const char *name) { + bool ret = false; + if (name && *name && *name != '.') { + char *path = get_project_script_path (core, name); + if (!path) { + return false; + } + if (rz_str_endswith (path, R_SYS_DIR "rc") && rz_file_exists (path)) { + ret = true; + } else { + path = rz_str_append (path, ".d"); + if (rz_file_is_directory (path)) { + ret = true; + } + } + free (path); + } + return ret; +} + +RZ_API int rz_core_project_cat(RzCore *core, const char *name) { + char *path = get_project_script_path (core, name); + if (path) { + char *data = rz_file_slurp (path, NULL); + if (data) { + rz_cons_println (data); + free (data); + } + } + free (path); + return 0; +} + +RZ_API int rz_core_project_list(RzCore *core, int mode) { + PJ *pj = NULL; + RzListIter *iter; + RzList *list; + + char *foo, *path = rz_file_abspath (rz_config_get (core->config, "dir.projects")); + if (!path) { + return 0; + } + list = rz_sys_dir (path); + switch (mode) { + case 'j': + pj = pj_new (); + if (!pj) { + break; + } + pj_a (pj); + rz_list_foreach (list, iter, foo) { + // todo. escape string + if (rz_core_is_project (core, foo)) { + pj_s (pj, foo); + } + } + pj_end (pj); + rz_cons_printf ("%s\n", pj_string (pj)); + pj_free (pj); + break; + default: + rz_list_foreach (list, iter, foo) { + if (rz_core_is_project (core, foo)) { + rz_cons_println (foo); + } + } + break; + } + rz_list_free (list); + free (path); + return 0; +} + +static inline void remove_project_file(char * path) { + if (rz_file_exists (path)) { + rz_file_rm (path); + eprintf ("rm %s\n", path); + } +} + +static inline void remove_notes_file(char *prjDir) { + char *notes_txt = rz_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "notes.txt"); + if (rz_file_exists (notes_txt)) { + rz_file_rm (notes_txt); + eprintf ("rm %s\n", notes_txt); + } + free(notes_txt); +} + +static inline void remove_rop_directory(char *prjDir) { + char *rop_d = rz_str_newf ("%s%s%s", prjDir, R_SYS_DIR, "rop.d"); + + if (rz_file_is_directory (rop_d)) { + char *f; + RzListIter *iter; + RzList *files = rz_sys_dir (rop_d); + rz_list_foreach (files, iter, f) { + char *filepath = rz_str_append (strdup (rop_d), R_SYS_DIR); + filepath = rz_str_append (filepath, f); + if (!rz_file_is_directory (filepath)) { + eprintf ("rm %s\n", filepath); + rz_file_rm (filepath); + } + + free (filepath); + } + + rz_file_rm (rop_d); + eprintf ("rm %s\n", rop_d); + rz_list_free (files); + } + + free (rop_d); +} +RZ_API int rz_core_project_delete(RzCore *core, const char *prjfile) { + if (rz_sandbox_enable (0)) { + eprintf ("Cannot delete project in sandbox mode\n"); + return 0; + } + char *path = get_project_script_path (core, prjfile); + if (!path) { + eprintf ("Invalid project name '%s'\n", prjfile); + return false; + } + if (rz_core_is_project (core, prjfile)) { + char *prjDir = rz_file_dirname (path); + if (!prjDir) { + eprintf ("Cannot resolve directory\n"); + free (path); + return false; + } + remove_project_file (path); + remove_notes_file (prjDir); + remove_rop_directory (prjDir); + // remove directory only if it's empty + rz_file_rm (prjDir); + free (prjDir); + } + free (path); + return 0; +} + +static bool load_project_rop(RzCore *core, const char *prjfile) { + char *path, *db = NULL, *path_ns; + bool found = 0; + SdbListIter *it; + SdbNs *ns; + + if (!prjfile || !*prjfile) { + return false; + } + + Sdb *rop_db = sdb_ns (core->sdb, "rop", false); + Sdb *nop_db = sdb_ns (rop_db, "nop", false); + Sdb *mov_db = sdb_ns (rop_db, "mov", false); + Sdb *const_db = sdb_ns (rop_db, "const", false); + Sdb *arithm_db = sdb_ns (rop_db, "arithm", false); + Sdb *arithmct_db = sdb_ns (rop_db, "arithm_ct", false); + + char *rcPath = get_project_script_path (core, prjfile); + char *prjDir = rz_file_dirname (rcPath); + + if (rz_str_endswith (prjfile, R_SYS_DIR "rc")) { + // XXX + eprintf ("ENDS WITH\n"); + path = strdup (prjfile); + path[strlen (path) - 3] = 0; + } else if (rz_file_fexists ("%s" R_SYS_DIR "rc", prjDir, prjfile)) { + path = rz_str_newf ("%s" R_SYS_DIR, prjDir, prjfile); + } else { + if (*prjfile == R_SYS_DIR[0]) { + db = rz_str_newf ("%s.d", prjfile); + if (!db) { + free (prjDir); + free (rcPath); + return false; + } + path = strdup (db); + } else { + db = rz_str_newf ("%s" R_SYS_DIR "%s.d", prjDir, prjfile); + if (!db) { + free (prjDir); + free (rcPath); + return false; + } + path = rz_file_abspath (db); + } + } + if (!path) { + free (db); + free (prjDir); + free (rcPath); + return false; + } + if (rop_db) { + ls_foreach (core->sdb->ns, it, ns){ + if (ns->sdb == rop_db) { + ls_delete (core->sdb->ns, it); + found = true; + break; + } + } + } + if (!found) { + sdb_free (rop_db); + } + rop_db = sdb_new (path, "rop", 0); + if (!rop_db) { + free (db); + free (path); + free (prjDir); + free (rcPath); + return false; + } + sdb_ns_set (core->sdb, "rop", rop_db); + + path_ns = rz_str_newf ("%s" R_SYS_DIR "rop", prjDir); + if (!rz_file_exists (path_ns)) { + path_ns = rz_str_append (path_ns, ".sdb"); + } + nop_db = sdb_new (path_ns, "nop", 0); + sdb_ns_set (rop_db, "nop", nop_db); + + mov_db = sdb_new (path_ns, "mov", 0); + sdb_ns_set (rop_db, "mov", mov_db); + + const_db = sdb_new (path_ns, "const", 0); + sdb_ns_set (rop_db, "const", const_db); + + arithm_db = sdb_new (path_ns, "arithm", 0); + sdb_ns_set (rop_db, "arithm", arithm_db); + + arithmct_db = sdb_new (path_ns, "arithm_ct", 0); + sdb_ns_set (rop_db, "arithm_ct", arithmct_db); + + free (path); + free (path_ns); + free (db); + free (prjDir); + free (rcPath); + return true; +} + +RZ_API void rz_core_project_execute_cmds(RzCore *core, const char *prjfile) { + char *str = rz_core_project_notes_file (core, prjfile); + char *data = rz_file_slurp (str, NULL); + if (!data) { + free (str); + return; + } + Output out; + out.fout = NULL; + out.cout = rz_strbuf_new (NULL); + rz_strbuf_init (out.cout); + struct Proc proc; + spp_proc_set (&proc, "spp", 1); + spp_eval (data, &out); + free (data); + data = strdup (rz_strbuf_get (out.cout)); + char *bol = strtok (data, "\n"); + while (bol) { + if (bol[0] == ':') { + rz_core_cmd0 (core, bol + 1); + } + bol = strtok (NULL, "\n"); + } + free (data); + free (str); +} + +/*** vvv thready ***/ + +typedef struct { + RzCore *core; + char *prjName; + char *rcPath; +} ProjectState; + +static RzThreadFunctionRet project_load_background(RzThread *th) { + ProjectState *ps = th->user; + rz_core_project_load (ps->core, ps->prjName, ps->rcPath); + free (ps->prjName); + free (ps->rcPath); + free (ps); + return R_TH_STOP; +} + +RZ_API RzThread *rz_core_project_load_bg(RzCore *core, const char *prjName, const char *rcPath) { + ProjectState *ps = R_NEW (ProjectState); + ps->core = core; + ps->prjName = strdup (prjName); + ps->rcPath = strdup (rcPath); + RzThread *th = rz_th_new (project_load_background, ps, false); + if (th) { + rz_th_start (th, true); + char thname[16] = {0}; + size_t thlen = R_MIN (strlen(prjName), sizeof(thname) - 1); + strncpy (thname, prjName, thlen); + thname[15] = 0; + rz_th_setname (th, thname); + } + return th; +} + +/*** ^^^ thready ***/ + +static ut64 getProjectLaddr(RzCore *core, const char *prjfile) { + ut64 laddr = 0; + char *buf = rz_file_slurp (prjfile, NULL); + char *pos; + if (buf) { + if ((pos = strstr(buf, "\"e bin.laddr = "))) { + laddr = rz_num_math (NULL, pos + 15); + } + free (buf); + } + return laddr; +} + +RZ_API bool rz_core_project_open(RzCore *core, const char *prjfile, bool thready) { + bool askuser = true; + int ret, close_current_session = 1; + char *oldbin; + const char *newbin; + ut64 mapaddr = 0; + if (!prjfile || !*prjfile) { + return false; + } + if (thready) { + eprintf ("Loading projects in a thread has been deprecated. Use tasks\n"); + return false; + } + char *prj = get_project_script_path (core, prjfile); + if (!prj) { + eprintf ("Invalid project name '%s'\n", prjfile); + return false; + } + char *filepath = rz_core_project_info (core, prj); + // eprintf ("OPENING (%s) from %s\n", prj, rz_config_get (core->config, "file.path")); + /* if it is not an URI */ + if (!filepath) { + eprintf ("Cannot retrieve information for project '%s'\n", prj); + free (prj); + return false; + } + + if (!filepath[0]) { + goto cookiefactory; + } + if (!strstr (filepath, "://")) { + /* check if path exists */ + if (!rz_file_exists (filepath)) { + eprintf ("Cannot find file '%s'\n", filepath); + free (prj); + free (filepath); + return false; + } + } + cookiefactory: + ; + const char *file_path = rz_config_get (core->config, "file.path"); + if (!file_path || !*file_path) { + file_path = rz_config_get (core->config, "file.lastpath"); + } + oldbin = strdup (file_path); + if (!strcmp (prjfile, rz_config_get (core->config, "prj.name"))) { + // eprintf ("Reloading project\n"); + askuser = false; +#if 0 + free (prj); + free (filepath); + return false; +#endif + } + if (askuser) { + if (rz_cons_is_interactive ()) { + close_current_session = rz_cons_yesno ('y', "Close current session? (Y/n)"); + } + } + if (close_current_session) { + // delete + rz_core_file_close_fd (core, -1); + rz_io_close_all (core->io); + rz_anal_purge (core->anal); + rz_flag_unset_all (core->flags); + rz_bin_file_delete_all (core->bin); + // open new file + // TODO: handle read/read-write mode + if (filepath[0]) { + /* Old-style project without embedded on commands to open all files. */ + if (!rz_core_file_open (core, filepath, 0, UT64_MAX)) { + eprintf ("Cannot open file '%s'\n", filepath); + ret = false; + goto beach; + } + } + } + mapaddr = getProjectLaddr (core, prj); + if (mapaddr) { + rz_config_set_i (core->config, "bin.laddr", mapaddr); + } + if (filepath[0] && close_current_session && rz_config_get_i (core->config, "file.info")) { + mapaddr = rz_config_get_i (core->config, "file.offset"); + (void)rz_core_bin_load (core, filepath, mapaddr? mapaddr: UT64_MAX); + } + /* load sdb stuff in here */ + ret = rz_core_project_load (core, prjfile, prj); + if (filepath[0]) { + newbin = rz_config_get (core->config, "file.path"); + if (!newbin || !*newbin) { + newbin = rz_config_get (core->config, "file.lastpath"); + } + if (strcmp (oldbin, newbin)) { + eprintf ("WARNING: file.path changed: %s => %s\n", oldbin, newbin); + } + } +beach: + free (oldbin); + free (filepath); + free (prj); + return ret; +} + +RZ_API char *rz_core_project_info(RzCore *core, const char *prjfile) { + FILE *fd; + char buf[256], *file = NULL; + char *prj = get_project_script_path (core, prjfile); + if (!prj) { + eprintf ("Invalid project name '%s'\n", prjfile); + return NULL; + } + fd = rz_sandbox_fopen (prj, "r"); + if (fd) { + for (;;) { + if (!fgets (buf, sizeof (buf), fd)) { + break; + } + if (feof (fd)) { + break; + } + if (!strncmp (buf, "\"e file.path = ", 15)) { + buf[strlen (buf) - 2] = 0; + file = rz_str_new (buf + 15); + break; + } + if (!strncmp (buf, "\"e file.lastpath = ", 19)) { + buf[strlen (buf) - 2] = 0; + file = rz_str_new (buf + 19); + break; + } + // TODO: deprecate before 1.0 + if (!strncmp (buf, "e file.path = ", 14)) { + buf[strlen (buf) - 1] = 0; + file = rz_str_new (buf + 14); + break; + } + } + fclose (fd); + } else { + eprintf ("Cannot open project info (%s)\n", prj); + } +#if 0 + if (file) { + rz_cons_printf ("Project: %s\n", prj); + rz_cons_printf ("FilePath: %s\n", file); + } +#endif + free (prj); + return file; +} + +static int fdc; //this is a ugly, remove it, when we have $fd + +static bool store_files_and_maps (RzCore *core, RzIODesc *desc, ut32 id) { + RzList *maps = NULL; + RzListIter *iter; + RzIOMap *map; + if (desc) { + // reload bin info + rz_cons_printf ("\"obf %s\"\n", desc->uri); + rz_cons_printf ("\"ofs \\\"%s\\\" %s\"\n", desc->uri, rz_str_rwx_i (desc->perm)); + if ((maps = rz_io_map_get_for_fd (core->io, id))) { + rz_list_foreach (maps, iter, map) { + rz_cons_printf ("om %d 0x%"PFMT64x" 0x%"PFMT64x" 0x%"PFMT64x" %s%s%s\n", fdc, + map->itv.addr, map->itv.size, map->delta, rz_str_rwx_i (map->perm), + map->name ? " " : "", map->name ? map->name : ""); + } + rz_list_free (maps); + } + fdc++; + } + return true; +} + +static bool simple_project_save_script(RzCore *core, const char *file, int opts) { + char *filename, *hl, *ohl = NULL; + int fd, fdold; + + if (!file || * file == '\0') { + return false; + } + + filename = rz_str_word_get_first (file); + fd = rz_sandbox_open (file, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0644); + if (fd == -1) { + free (filename); + return false; + } + + hl = rz_cons_singleton ()->highlight; + if (hl) { + ohl = strdup (hl); + rz_cons_highlight (NULL); + } + + fdold = rz_cons_singleton ()->fdout; + rz_cons_singleton ()->fdout = fd; + rz_cons_singleton ()->context->is_interactive = false; // NOES must use api + + rz_str_write (fd, "# r2 rdb project file\n"); + + if (opts & R_CORE_PRJ_EVAL) { + rz_str_write (fd, "# eval\n"); + rz_config_list (core->config, NULL, true); + rz_cons_flush (); + } + + if (opts & R_CORE_PRJ_FCNS) { + rz_str_write (fd, "# functions\n"); + rz_str_write (fd, "fs functions\n"); + rz_core_cmd (core, "afl*", 0); + rz_cons_flush (); + } + + if (opts & R_CORE_PRJ_FLAGS) { + rz_str_write (fd, "# flags\n"); + rz_core_cmd (core, "f.**", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_META) { + rz_str_write (fd, "# meta\n"); + rz_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1); + rz_cons_flush (); + rz_core_cmd (core, "fV*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_XREFS) { + rz_str_write (fd, "# xrefs\n"); + rz_core_cmd (core, "ax*", 0); + rz_cons_flush (); + } + + + rz_cons_singleton ()->fdout = fdold; + rz_cons_singleton ()->context->is_interactive = true; + + if (ohl) { + rz_cons_highlight (ohl); + free (ohl); + } + + close (fd); + free (filename); + + return true; +} + +static bool project_save_script(RzCore *core, const char *file, int opts) { + char *filename, *hl, *ohl = NULL; + int fd, fdold; + + if (!file || *file == '\0') { + return false; + } + + filename = rz_str_word_get_first (file); + fd = rz_sandbox_open (file, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, 0644); + if (fd == -1) { + free (filename); + return false; + } + + hl = rz_cons_singleton ()->highlight; + if (hl) { + ohl = strdup (hl); + rz_cons_highlight (NULL); + } + fdold = rz_cons_singleton ()->fdout; + rz_cons_singleton ()->fdout = fd; + rz_cons_singleton ()->context->is_interactive = false; + rz_str_write (fd, "# r2 rdb project file\n"); + if (!core->bin->is_debugger && !rz_config_get_i (core->config, "asm.emu")) { + if (core->bin->file) { + char *fpath = rz_file_abspath (core->bin->file); + if (fpath) { + char *reopen = rz_str_newf ("\"o %s\"\n", fpath); + if (reopen) { + rz_str_write (fd, reopen); + free (reopen); + free (fpath); + } + } + } + + } + // Set file.path and file.lastpath to empty string to signal + // new behaviour to project load routine (see io maps below). + rz_config_set (core->config, "file.path", ""); + rz_config_set (core->config, "file.lastpath", ""); + if (opts & R_CORE_PRJ_EVAL) { + rz_str_write (fd, "# eval\n"); + rz_config_list (core->config, NULL, true); + rz_cons_flush (); + } + + if (opts & R_CORE_PRJ_FCNS) { + rz_str_write (fd, "# functions\n"); + rz_str_write (fd, "fs functions\n"); + rz_core_cmd (core, "afl*", 0); + rz_cons_flush (); + } + + if (opts & R_CORE_PRJ_FLAGS) { + rz_str_write (fd, "# flags\n"); + rz_flag_space_push (core->flags, NULL); + rz_flag_list (core->flags, true, NULL); + rz_flag_space_pop (core->flags); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_IO_MAPS && core->io && core->io->files) { + fdc = 3; + rz_id_storage_foreach (core->io->files, (RIDStorageForeachCb)store_files_and_maps, core); + rz_cons_flush (); + } + { + rz_core_cmd (core, "fz*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_META) { + rz_str_write (fd, "# meta\n"); + rz_meta_print_list_all (core->anal, R_META_TYPE_ANY, 1); + rz_cons_flush (); + rz_core_cmd (core, "fV*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_XREFS) { + rz_core_cmd (core, "ax*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_FLAGS) { + rz_core_cmd (core, "f.**", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_DBG_BREAK) { + rz_core_cmd (core, "db*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_ANAL_HINTS) { + rz_core_cmd (core, "ah*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_ANAL_TYPES) { + rz_str_write (fd, "# types\n"); + rz_core_cmd (core, "t*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_ANAL_MACROS) { + rz_str_write (fd, "# macros\n"); + rz_core_cmd (core, "(*", 0); + rz_str_write (fd, "# aliases\n"); + rz_core_cmd (core, "$*", 0); + rz_cons_flush (); + } + if (opts & R_CORE_PRJ_ANAL_SEEK) { + rz_cons_printf ("# seek\n" + "s 0x%08"PFMT64x "\n", core->offset); + rz_cons_flush (); + } + + rz_cons_singleton ()->fdout = fdold; + rz_cons_singleton ()->context->is_interactive = true; + + if (ohl) { + rz_cons_highlight (ohl); + free (ohl); + } + + close (fd); + free (filename); + + return true; +} + +// TODO: rename to rz_core_project_save_script +RZ_API bool rz_core_project_save_script(RzCore *core, const char *file, int opts) { + return project_save_script (core, file, opts); +} + +#define TRANSITION 1 + +RZ_API bool rz_core_project_save(RzCore *core, const char *prjName) { + bool scr_null = false; + bool ret = true; + char *scriptPath, *prjDir; + SdbListIter *it; + SdbNs *ns; + char *oldPrjName = NULL; + + if (!prjName || !*prjName) { + return false; + } + scriptPath = get_project_script_path (core, prjName); + if (!scriptPath) { + eprintf ("Invalid project name '%s'\n", prjName); + return false; + } + if (rz_str_endswith (scriptPath, R_SYS_DIR "rc")) { + /* new project format */ + prjDir = rz_file_dirname (scriptPath); + } else { + prjDir = rz_str_newf ("%s.d", scriptPath); + } + if (rz_file_exists (scriptPath)) { + if (rz_file_is_directory (scriptPath)) { + eprintf ("WTF. rc is a directory?\n"); + } + if (rz_str_endswith (prjDir, ".d")) { + eprintf ("Upgrading project...\n"); +#if TRANSITION + rz_file_rm (scriptPath); + rz_sys_mkdirp (prjDir); + eprintf ("Please remove: rm -rf %s %s.d\n", prjName, prjName); + char *rc = rz_str_newf ("%s" R_SYS_DIR "rc", prjDir); + if (!rc) { + free (prjDir); + free (scriptPath); + return false; + } + free (scriptPath); + scriptPath = rc; + free (prjDir); + prjDir = rz_file_dirname (scriptPath); +#endif + } + } + if (!prjDir) { + prjDir = strdup (prjName); + } + if (!rz_file_exists (prjDir)) { + rz_sys_mkdirp (prjDir); + } + if (rz_config_get_i (core->config, "scr.null")) { + rz_config_set_i (core->config, "scr.null", false); + scr_null = true; + } + make_projects_directory (core); + + Sdb *rop_db = sdb_ns (core->sdb, "rop", false); + if (rop_db) { + /* set filepath for all the rop sub-dbs */ + ls_foreach (rop_db->ns, it, ns) { + char *rop_path = rz_str_newf ("%s" R_SYS_DIR "rop.d" R_SYS_DIR "%s", prjDir, ns->name); + sdb_file (ns->sdb, rop_path); + sdb_sync (ns->sdb); + free (rop_path); + } + } + + const char *oldPrjNameC = rz_config_get (core->config, "prj.name"); + if (oldPrjNameC) { + oldPrjName = strdup (oldPrjNameC); + } + rz_config_set (core->config, "prj.name", prjName); + if (rz_config_get_i (core->config, "prj.simple")) { + if (!simple_project_save_script (core, scriptPath, R_CORE_PRJ_ALL)) { + eprintf ("Cannot open '%s' for writing\n", prjName); + ret = false; + } + } else { + if (!project_save_script (core, scriptPath, R_CORE_PRJ_ALL)) { + eprintf ("Cannot open '%s' for writing\n", prjName); + ret = false; + } + } + + if (rz_config_get_i (core->config, "prj.files")) { + eprintf ("TODO: prj.files: support copying more than one file into the project directory\n"); + char *binFile = rz_core_project_info (core, prjName); + const char *binFileName = rz_file_basename (binFile); + char *prjBinDir = rz_str_newf ("%s" R_SYS_DIR "bin", prjDir); + char *prjBinFile = rz_str_newf ("%s" R_SYS_DIR "%s", prjBinDir, binFileName); + rz_sys_mkdirp (prjBinDir); + if (!rz_file_copy (binFile, prjBinFile)) { + eprintf ("Warning: Cannot copy '%s' into '%s'\n", binFile, prjBinFile); + } + free (prjBinFile); + free (prjBinDir); + free (binFile); + } + if (rz_config_get_i (core->config, "prj.git")) { + char *cwd = rz_sys_getdir (); + char *gitDir = rz_str_newf ("%s" R_SYS_DIR ".git", prjDir); + if (rz_sys_chdir (prjDir)) { + if (!rz_file_is_directory (gitDir)) { + rz_sys_cmd ("git init"); + } + rz_sys_cmd ("git add * ; git commit -a"); + } else { + eprintf ("Cannot chdir %s\n", prjDir); + } + rz_sys_chdir (cwd); + free (gitDir); + free (cwd); + } + if (rz_config_get_i (core->config, "prj.zip")) { + char *cwd = rz_sys_getdir (); + const char *prjName = rz_file_basename (prjDir); + if (rz_sys_chdir (prjDir)) { + if (!strchr (prjName, '\'')) { + rz_sys_chdir (".."); + rz_sys_cmdf ("rm -f '%s.zip'; zip -r '%s'.zip '%s'", + prjName, prjName, prjName); + } else { + eprintf ("Command injection attempt?\n"); + } + } else { + eprintf ("Cannot chdir %s\n", prjDir); + } + rz_sys_chdir (cwd); + free (cwd); + } + // LEAK : not always in heap free (prjName); + free (prjDir); + if (scr_null) { + rz_config_set_i (core->config, "scr.null", true); + } + if (!ret && oldPrjName) { + // reset prj.name on fail + rz_config_set (core->config, "prj.name", oldPrjName); + } + free (scriptPath); + free (oldPrjName); + return ret; +} + +RZ_API char *rz_core_project_notes_file(RzCore *core, const char *prjName) { + char *notes_txt; + const char *prjdir = rz_config_get (core->config, "dir.projects"); + char *prjpath = rz_file_abspath (prjdir); + notes_txt = rz_str_newf ("%s"R_SYS_DIR "%s"R_SYS_DIR "notes.txt", prjpath, prjName); + free (prjpath); + return notes_txt; +} + +RZ_API bool rz_core_project_load(RzCore *core, const char *prjName, const char *rcpath) { + const bool cfg_fortunes = rz_config_get_i (core->config, "cfg.fortunes"); + const bool scr_interactive = rz_cons_is_interactive (); + const bool scr_prompt = rz_config_get_i (core->config, "scr.prompt"); + (void) load_project_rop (core, prjName); + bool ret = rz_core_cmd_file (core, rcpath); + rz_config_set_i (core->config, "cfg.fortunes", cfg_fortunes); + rz_config_set_i (core->config, "scr.interactive", scr_interactive); + rz_config_set_i (core->config, "scr.prompt", scr_prompt); + rz_config_bump (core->config, "asm.arch"); + return ret; +} diff --git a/libr/core/pseudo.c b/librz/core/pseudo.c similarity index 72% rename from libr/core/pseudo.c rename to librz/core/pseudo.c index 4deb101430..d316f8db9f 100644 --- a/libr/core/pseudo.c +++ b/librz/core/pseudo.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2015-2017 - pancake */ -#include +#include #define TYPE_NONE 0 #define TYPE_STR 1 #define TYPE_SYM 2 @@ -166,8 +166,8 @@ static void find_and_change (char* in, int len) { } } -R_API int r_core_pseudo_code(RCore *core, const char *input) { - const char *cmdPdc = r_config_get (core->config, "cmd.pdc"); +RZ_API int rz_core_pseudo_code(RzCore *core, const char *input) { + const char *cmdPdc = rz_config_get (core->config, "cmd.pdc"); if (cmdPdc && *cmdPdc && !strstr (cmdPdc, "pdc")) { if (strstr (cmdPdc, "!*") || strstr (cmdPdc, "#!")) { if (!strcmp (input, "*")) { @@ -178,47 +178,47 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { input = " -h"; } } - return r_core_cmdf (core, "%s%s", cmdPdc, input); + return rz_core_cmdf (core, "%s%s", cmdPdc, input); } Sdb *db; ut64 queuegoto = 0LL; const char *blocktype = "else"; - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); - RConfigHold *hc = r_config_hold_new (core->config); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RConfigHold *hc = rz_config_hold_new (core->config); if (!hc) { return false; } - r_config_hold_i (hc, "asm.pseudo", "asm.decode", "asm.lines", "asm.bytes", "asm.stackptr", NULL); - r_config_hold_i (hc, "asm.offset", "asm.flags", "asm.lines.fcn", "asm.comments", NULL); - r_config_hold_i (hc, "asm.functions", "asm.section", "asm.cmt.col", "asm.filter", NULL); - r_config_hold_i (hc, "scr.color", "emu.str", "asm.emu", "emu.write", NULL); - r_config_hold_i (hc, "io.cache", NULL); + rz_config_hold_i (hc, "asm.pseudo", "asm.decode", "asm.lines", "asm.bytes", "asm.stackptr", NULL); + rz_config_hold_i (hc, "asm.offset", "asm.flags", "asm.lines.fcn", "asm.comments", NULL); + rz_config_hold_i (hc, "asm.functions", "asm.section", "asm.cmt.col", "asm.filter", NULL); + rz_config_hold_i (hc, "scr.color", "emu.str", "asm.emu", "emu.write", NULL); + rz_config_hold_i (hc, "io.cache", NULL); if (!fcn) { eprintf ("Cannot find function in 0x%08"PFMT64x"\n", core->offset); - r_config_hold_free (hc); + rz_config_hold_free (hc); return false; } - r_config_set_i (core->config, "scr.color", 0); - r_config_set_i (core->config, "asm.stackptr", 0); - r_config_set_i (core->config, "asm.pseudo", 1); - r_config_set_i (core->config, "asm.decode", 0); - r_config_set_i (core->config, "asm.filter", 1); - r_config_set_i (core->config, "asm.lines", 0); - r_config_set_i (core->config, "asm.bytes", 0); - r_config_set_i (core->config, "asm.offset", 0); - r_config_set_i (core->config, "asm.flags", 0); - r_config_set_i (core->config, "asm.emu", 1); - r_config_set_i (core->config, "emu.str", 1); - r_config_set_i (core->config, "emu.write", 1); - r_config_set_i (core->config, "asm.lines.fcn", 0); - r_config_set_i (core->config, "asm.comments", 1); - r_config_set_i (core->config, "asm.functions", 0); - r_config_set_i (core->config, "asm.tabs", 0); - r_config_set_i (core->config, "asm.section", 0); - r_config_set_i (core->config, "asm.cmt.col", 30); - r_config_set_i (core->config, "io.cache", 1); - r_core_cmd0 (core, "aeim"); + rz_config_set_i (core->config, "scr.color", 0); + rz_config_set_i (core->config, "asm.stackptr", 0); + rz_config_set_i (core->config, "asm.pseudo", 1); + rz_config_set_i (core->config, "asm.decode", 0); + rz_config_set_i (core->config, "asm.filter", 1); + rz_config_set_i (core->config, "asm.lines", 0); + rz_config_set_i (core->config, "asm.bytes", 0); + rz_config_set_i (core->config, "asm.offset", 0); + rz_config_set_i (core->config, "asm.flags", 0); + rz_config_set_i (core->config, "asm.emu", 1); + rz_config_set_i (core->config, "emu.str", 1); + rz_config_set_i (core->config, "emu.write", 1); + rz_config_set_i (core->config, "asm.lines.fcn", 0); + rz_config_set_i (core->config, "asm.comments", 1); + rz_config_set_i (core->config, "asm.functions", 0); + rz_config_set_i (core->config, "asm.tabs", 0); + rz_config_set_i (core->config, "asm.section", 0); + rz_config_set_i (core->config, "asm.cmt.col", 30); + rz_config_set_i (core->config, "io.cache", 1); + rz_core_cmd0 (core, "aeim"); db = sdb_new0 (); // walk all basic blocks @@ -226,14 +226,14 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { // use it for indentation // asm.pseudo=true // asm.decode=true - RAnalBlock *bb = r_list_first (fcn->bbs); + RzAnalBlock *bb = rz_list_first (fcn->bbs); char indentstr[1024] = {0}; - int n_bb = r_list_length (fcn->bbs); - r_cons_printf ("function %s () {", fcn->name); + int n_bb = rz_list_length (fcn->bbs); + rz_cons_printf ("function %s () {", fcn->name); int indent = 1; int nindent = 1; - RList *visited = r_list_newf (NULL); - r_cons_printf ("\n // %d basic blocks\n", n_bb); + RzList *visited = rz_list_newf (NULL); + rz_cons_printf ("\n // %d basic blocks\n", n_bb); do { #define I_TAB 4 #define K_MARK(x) sdb_fmt("mark.%"PFMT64x,x) @@ -243,18 +243,18 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { if (!bb) { break; } - r_list_append (visited, bb); - r_cons_push (); - bool html = r_config_get_i (core->config, "scr.html"); - r_config_set_i (core->config, "scr.html", 0); - char *code = r_core_cmd_str (core, sdb_fmt ("pD %d @ 0x%08"PFMT64x"\n", bb->size, bb->addr)); - r_cons_pop (); - r_config_set_i (core->config, "scr.html", html); + rz_list_append (visited, bb); + rz_cons_push (); + bool html = rz_config_get_i (core->config, "scr.html"); + rz_config_set_i (core->config, "scr.html", 0); + char *code = rz_core_cmd_str (core, sdb_fmt ("pD %d @ 0x%08"PFMT64x"\n", bb->size, bb->addr)); + rz_cons_pop (); + rz_config_set_i (core->config, "scr.html", html); if (indent * I_TAB + 2 >= sizeof (indentstr)) { indent = (sizeof (indentstr) / I_TAB) - 4; } SET_INDENT (indent); - code = r_str_prefix_all (code, indentstr); + code = rz_str_prefix_all (code, indentstr); if (!code) { eprintf ("No code here\n"); break; @@ -266,13 +266,13 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { bool mustprint = !queuegoto || queuegoto != bb->addr; if (mustprint) { if (queuegoto) { - r_cons_printf ("\n%s goto loc_0x%llx", + rz_cons_printf ("\n%s goto loc_0x%llx", indentstr, queuegoto); queuegoto = 0LL; } - r_cons_printf ("\n%s loc_0x%llx:\n", indentstr, bb->addr); + rz_cons_printf ("\n%s loc_0x%llx:\n", indentstr, bb->addr); indentstr[(indent * I_TAB) - 2] = 0; - r_cons_printf ("\n%s", code); + rz_cons_printf ("\n%s", code); free (code); sdb_num_set (db, K_MARK (bb->addr), 1, 0); } @@ -287,13 +287,13 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { nindent = 1; for (i = indent; i != nindent; i--) { SET_INDENT (i); - r_cons_printf ("\n%s}", indentstr); + rz_cons_printf ("\n%s}", indentstr); } - r_cons_printf ("\n%sreturn;\n", indentstr); - RAnalBlock *nbb = r_anal_bb_from_offset (core->anal, bb->fail); - if (r_list_contains (visited, nbb)) { - nbb = r_anal_bb_from_offset (core->anal, bb->jump); - if (r_list_contains (visited, nbb)) { + rz_cons_printf ("\n%sreturn;\n", indentstr); + RzAnalBlock *nbb = rz_anal_bb_from_offset (core->anal, bb->fail); + if (rz_list_contains (visited, nbb)) { + nbb = rz_anal_bb_from_offset (core->anal, bb->jump); + if (rz_list_contains (visited, nbb)) { nbb = NULL; } } @@ -306,18 +306,18 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { } if (sdb_num_get (db, K_ELSE (bb->addr), 0)) { if (!strcmp (blocktype, "else")) { - r_cons_printf ("\n%s } %s {", indentstr, blocktype); + rz_cons_printf ("\n%s } %s {", indentstr, blocktype); } else { - r_cons_printf ("\n%s } %s (?);", indentstr, blocktype); + rz_cons_printf ("\n%s } %s (?);", indentstr, blocktype); } } else { - r_cons_printf ("\n%s}", indentstr); + rz_cons_printf ("\n%s}", indentstr); } if (addr != bb->addr) { queuegoto = addr; - // r_cons_printf ("\n%s goto loc_0x%llx", indentstr, addr); + // rz_cons_printf ("\n%s goto loc_0x%llx", indentstr, addr); } - bb = r_anal_bb_from_offset (core->anal, addr); + bb = rz_anal_bb_from_offset (core->anal, addr); if (!bb) { eprintf ("failed block\n"); break; @@ -328,7 +328,7 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { int i; for (i = indent; i != nindent; i--) { SET_INDENT (i); - r_cons_printf ("\n%s }", indentstr); + rz_cons_printf ("\n%s }", indentstr); } } indent = nindent; @@ -340,19 +340,19 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { ut64 jump = swap ? bb->jump : bb->fail; ut64 fail = swap ? bb->fail : bb->jump; // if its from another function chop it! - RAnalFunction *curfcn = r_anal_get_fcn_in (core->anal, jump, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *curfcn = rz_anal_get_fcn_in (core->anal, jump, R_ANAL_FCN_TYPE_NULL); if (curfcn != fcn) { // chop that branch - r_cons_printf ("\n // chop\n"); + rz_cons_printf ("\n // chop\n"); // break; } if (sdb_get (db, K_INDENT (jump), 0)) { // already tracekd if (!sdb_get (db, K_INDENT (fail), 0)) { - bb = r_anal_bb_from_offset (core->anal, fail); + bb = rz_anal_bb_from_offset (core->anal, fail); } } else { - bb = r_anal_bb_from_offset (core->anal, jump); + bb = rz_anal_bb_from_offset (core->anal, jump); if (!bb) { eprintf ("failed to retrieve block at 0x%"PFMT64x"\n", jump); break; @@ -364,15 +364,15 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { /* do nothing here */ eprintf ("BlockAlready 0x%"PFMT64x"\n", bb->addr); } else { - // r_cons_printf (" { RADICAL %llx\n", bb->addr); + // rz_cons_printf (" { RADICAL %llx\n", bb->addr); sdb_array_push_num (db, "indent", fail, 0); sdb_num_set (db, K_INDENT (fail), indent, 0); sdb_num_set (db, K_ELSE (fail), 1, 0); SET_INDENT (indent); - r_cons_printf ("\n%s {", indentstr); + rz_cons_printf ("\n%s {", indentstr); } } else { - r_cons_printf ("\n%s do", indentstr); + rz_cons_printf ("\n%s do", indentstr); sdb_array_push_num (db, "indent", jump, 0); sdb_num_set (db, K_INDENT (jump), indent, 0); sdb_num_set (db, K_ELSE (jump), 1, 0); @@ -381,37 +381,37 @@ R_API int r_core_pseudo_code(RCore *core, const char *input) { } else { blocktype = "else"; } - r_cons_printf ("\n%s {", indentstr); + rz_cons_printf ("\n%s {", indentstr); indent++; } } } else { ut64 addr = sdb_array_pop_num (db, "indent", NULL); if (addr == UT64_MAX) { - r_cons_printf ("\n(break)\n"); + rz_cons_printf ("\n(break)\n"); break; } - bb = r_anal_bb_from_offset (core->anal, addr); + bb = rz_anal_bb_from_offset (core->anal, addr); nindent = sdb_num_get (db, K_INDENT (addr), NULL); if (indent > nindent) { int i; for (i = indent; i != nindent; i--) { SET_INDENT (i); - r_cons_printf ("\n%s}", indentstr); + rz_cons_printf ("\n%s}", indentstr); } } if (nindent != indent) { - r_cons_printf ("\n%s} else {\n", indentstr); + rz_cons_printf ("\n%s} else {\n", indentstr); } indent = nindent; } } //n_bb --; } while (n_bb > 0); - r_list_free (visited); - r_cons_printf ("\n}\n"); - r_config_hold_restore (hc); - r_config_hold_free (hc); + rz_list_free (visited); + rz_cons_printf ("\n}\n"); + rz_config_hold_restore (hc); + rz_config_hold_free (hc); sdb_free (db); return true; } diff --git a/libr/core/rtr.c b/librz/core/rtr.c similarity index 67% rename from libr/core/rtr.c rename to librz/core/rtr.c index 421301d4cf..5bddf2c9b8 100644 --- a/libr/core/rtr.c +++ b/librz/core/rtr.c @@ -1,7 +1,7 @@ /* radare - Copyright 2009-2020 - pancake, nibble */ -#include "r_core.h" -#include "r_socket.h" +#include "rz_core.h" +#include "rz_socket.h" #include "gdb/include/libgdbr.h" #include "gdb/include/gdbserver/core.h" @@ -23,9 +23,9 @@ SECURITY IMPLICATIONS #define rtr_n core->rtr_n #define rtr_host core->rtr_host -static RSocket *s = NULL; -static RThread *httpthread = NULL; -static RThread *rapthread = NULL; +static RzSocket *s = NULL; +static RzThread *httpthread = NULL; +static RzThread *rapthread = NULL; static const char *listenport = NULL; typedef struct { @@ -35,36 +35,36 @@ typedef struct { } TextLog; typedef struct { - RCore *core; + RzCore *core; int launch; int browse; char *path; } HttpThread; typedef struct { - RCore *core; + RzCore *core; char* input; } RapThread; -R_API void r_core_wait(RCore *core) { - r_cons_singleton ()->context->breaked = true; - r_th_kill (httpthread, true); - r_th_kill (rapthread, true); - r_th_wait (httpthread); - r_th_wait (rapthread); +RZ_API void rz_core_wait(RzCore *core) { + rz_cons_singleton ()->context->breaked = true; + rz_th_kill (httpthread, true); + rz_th_kill (rapthread, true); + rz_th_wait (httpthread); + rz_th_wait (rapthread); } -static void http_logf(RCore *core, const char *fmt, ...) { - bool http_log_enabled = r_config_get_i (core->config, "http.log"); +static void http_logf(RzCore *core, const char *fmt, ...) { + bool http_log_enabled = rz_config_get_i (core->config, "http.log"); va_list ap; va_start (ap, fmt); if (http_log_enabled) { - const char *http_log_file = r_config_get (core->config, "http.logfile"); + const char *http_log_file = rz_config_get (core->config, "http.logfile"); if (http_log_file && *http_log_file) { char * msg = calloc (4096, 1); if (msg) { vsnprintf (msg, 4095, fmt, ap); - r_file_dump (http_log_file, (const ut8*)msg, -1, true); + rz_file_dump (http_log_file, (const ut8*)msg, -1, true); free (msg); } } else { @@ -76,11 +76,11 @@ static void http_logf(RCore *core, const char *fmt, ...) { static char *rtrcmd (TextLog T, const char *str) { char *res, *ptr2; - char *ptr = r_str_uri_encode (str); - char *uri = r_str_newf ("http://%s:%s/%s%s", T.host, T.port, T.file, ptr? ptr: str); + char *ptr = rz_str_uri_encode (str); + char *uri = rz_str_newf ("http://%s:%s/%s%s", T.host, T.port, T.file, ptr? ptr: str); int len; free (ptr); - ptr2 = r_socket_http_get (uri, NULL, &len); + ptr2 = rz_socket_http_get (uri, NULL, &len); free (uri); if (ptr2) { ptr2[len] = 0; @@ -93,29 +93,29 @@ static char *rtrcmd (TextLog T, const char *str) { return NULL; } -static void showcursor(RCore *core, int x) { +static void showcursor(RzCore *core, int x) { if (core && core->vmode) { - r_cons_show_cursor (x); - r_cons_enable_mouse (x? r_config_get_i (core->config, "scr.wheel"): false); + rz_cons_show_cursor (x); + rz_cons_enable_mouse (x? rz_config_get_i (core->config, "scr.wheel"): false); } else { - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); } - r_cons_flush (); + rz_cons_flush (); } // TODO: rename /name to /nick or /so? // clone of textlog_chat () using rtrcmd() -static void rtr_textlog_chat (RCore *core, TextLog T) { +static void rtr_textlog_chat (RzCore *core, TextLog T) { char prompt[64]; char buf[1024]; int lastmsg = 0; - const char *me = r_config_get (core->config, "cfg.user"); + const char *me = rz_config_get (core->config, "cfg.user"); char *ret, msg[1024]; eprintf ("Type '/help' for commands and ^D to quit:\n"); - char *oldprompt = strdup (r_line_singleton ()->prompt); + char *oldprompt = strdup (rz_line_singleton ()->prompt); snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me); - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); ret = rtrcmd (T, msg); for (;;) { if (lastmsg >= 0) { @@ -124,12 +124,12 @@ static void rtr_textlog_chat (RCore *core, TextLog T) { strcpy (msg, "T"); } ret = rtrcmd (T, msg); - r_cons_println (ret); + rz_cons_println (ret); free (ret); ret = rtrcmd (T, "Tl"); lastmsg = atoi (ret)-1; free (ret); - if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { + if (rz_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { goto beach; } if (!*buf) { @@ -142,54 +142,54 @@ static void rtr_textlog_chat (RCore *core, TextLog T) { eprintf ("/clear clear text log messages\n"); } else if (!strncmp (buf, "/nick ", 6)) { snprintf (msg, sizeof (msg) - 1, "* '%s' is now known as '%s'", me, buf+6); - r_cons_println (msg); - r_core_log_add (core, msg); - r_config_set (core->config, "cfg.user", buf+6); - me = r_config_get (core->config, "cfg.user"); + rz_cons_println (msg); + rz_core_log_add (core, msg); + rz_config_set (core->config, "cfg.user", buf+6); + me = rz_config_get (core->config, "cfg.user"); snprintf (prompt, sizeof (prompt) - 1, "[%s]> ", me); - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); } else if (!strcmp (buf, "/log")) { char *ret = rtrcmd (T, "T"); if (ret) { - r_cons_println (ret); + rz_cons_println (ret); free (ret); } } else if (!strcmp (buf, "/clear")) { - //r_core_log_del (core, 0); + //rz_core_log_del (core, 0); free (rtrcmd (T, "T-")); } else if (!strcmp (buf, "/quit")) { goto beach; } else if (*buf=='/') { eprintf ("Unknown command: %s\n", buf); } else { - char *cmd = r_str_newf ("T [%s] %s", me, buf); + char *cmd = rz_str_newf ("T [%s] %s", me, buf); free (rtrcmd (T, cmd)); free (cmd); } } beach: - r_line_set_prompt (oldprompt); + rz_line_set_prompt (oldprompt); free (oldprompt); } -R_API int r_core_rtr_http_stop(RCore *u) { - RCore *core = (RCore*)u; +RZ_API int rz_core_rtr_http_stop(RzCore *u) { + RzCore *core = (RzCore*)u; const int timeout = 1; // 1 second const char *port; - RSocket* sock; + RzSocket* sock; #if __WINDOWS__ - r_socket_http_server_set_breaked (&r_cons_singleton ()->context->breaked); + rz_socket_http_server_set_breaked (&rz_cons_singleton ()->context->breaked); #endif if (((size_t)u) > 0xff) { - port = listenport? listenport: r_config_get ( + port = listenport? listenport: rz_config_get ( core->config, "http.port"); - sock = r_socket_new (0); - (void)r_socket_connect (sock, "localhost", + sock = rz_socket_new (0); + (void)rz_socket_connect (sock, "localhost", port, R_SOCKET_PROTO_TCP, timeout); - r_socket_free (sock); + rz_socket_free (sock); } - r_socket_free (s); + rz_socket_free (s); s = NULL; return 0; } @@ -197,19 +197,19 @@ R_API int r_core_rtr_http_stop(RCore *u) { static char *rtr_dir_files(const char *path) { char *ptr = strdup ("\n"); const char *file; - RListIter *iter; + RzListIter *iter; // list files - RList *files = r_sys_dir (path); + RzList *files = rz_sys_dir (path); eprintf ("Listing directory %s\n", path); - r_list_foreach (files, iter, file) { + rz_list_foreach (files, iter, file) { if (file[0] == '.') { continue; } - ptr = r_str_appendf (ptr, "%s
\n", + ptr = rz_str_appendf (ptr, "%s
\n", path, file, file); } - r_list_free (files); - return r_str_append (ptr, "\n"); + rz_list_free (files); + return rz_str_append (ptr, "\n"); } #if __UNIX__ @@ -219,11 +219,11 @@ static void dietime(int sig) { } #endif -static void activateDieTime(RCore *core) { - int dt = r_config_get_i (core->config, "http.dietime"); +static void activateDieTime(RzCore *core) { + int dt = rz_config_get_i (core->config, "http.dietime"); if (dt > 0) { #if __UNIX__ - r_sys_signal (SIGALRM, dietime); + rz_sys_signal (SIGALRM, dietime); alarm (dt); #else eprintf ("http.dietime only works on *nix systems\n"); @@ -238,13 +238,13 @@ static int write_reg_val(char *buf, ut64 sz, ut64 reg, int regsize, bool bigendi if (!bigendian) { switch (regsize) { case 2: - reg = r_swap_ut16 (reg); + reg = rz_swap_ut16 (reg); break; case 4: - reg = r_swap_ut32 (reg); + reg = rz_swap_ut32 (reg); break; case 8: - reg = r_swap_ut64 (reg); + reg = rz_swap_ut64 (reg); break; default: eprintf ("%s: Unsupported reg size: %d\n", @@ -265,8 +265,8 @@ static int write_big_reg(char *buf, ut64 sz, const utX *val, int regsize, bool b val->v80.Low); } return snprintf (buf, sz, - "%016"PFMT64x"%04x", r_swap_ut64 (val->v80.Low), - r_swap_ut16 (val->v80.High)); + "%016"PFMT64x"%04x", rz_swap_ut64 (val->v80.Low), + rz_swap_ut16 (val->v80.High)); case 12: if (bigendian) { return snprintf (buf, sz, @@ -274,8 +274,8 @@ static int write_big_reg(char *buf, ut64 sz, const utX *val, int regsize, bool b val->v96.Low); } return snprintf (buf, sz, - "%016"PFMT64x"%08"PFMT32x, r_swap_ut64 (val->v96.Low), - r_swap_ut32 (val->v96.High)); + "%016"PFMT64x"%08"PFMT32x, rz_swap_ut64 (val->v96.Low), + rz_swap_ut32 (val->v96.High)); case 16: if (bigendian) { return snprintf (buf, sz, @@ -284,8 +284,8 @@ static int write_big_reg(char *buf, ut64 sz, const utX *val, int regsize, bool b } return snprintf (buf, sz, "%016"PFMT64x"%016"PFMT64x, - r_swap_ut64 (val->v128.Low), - r_swap_ut64 (val->v128.High)); + rz_swap_ut64 (val->v128.Low), + rz_swap_ut64 (val->v128.High)); default: eprintf ("%s: big registers (%d byte(s)) not yet supported\n", __func__, regsize); @@ -340,21 +340,21 @@ static int swap_big_regs(char *dest, ut64 sz, const char *src, int regsz) { } } -static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, +static int rz_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, char *out_buf, size_t max_len) { int ret; - RList *list; - RListIter *iter; + RzList *list; + RzListIter *iter; gdb_reg_t *gdb_reg; - RRegItem *r; + RzRegItem *r; utX val_big; ut64 m_off, reg_val; bool be; - RDebugPid *dbgpid; + RzDebugPid *dbgpid; if (!core_ptr || ! cmd) { return -1; } - RCore *core = (RCore*) core_ptr; + RzCore *core = (RzCore*) core_ptr; switch (cmd[0]) { case '?': // Stop reason if (!out_buf) { @@ -378,7 +378,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, case 'd': switch (cmd[1]) { case 'm': // dm - if (snprintf (out_buf, max_len - 1, "%"PFMT64x, r_debug_get_baddr (core->dbg, NULL)) < 0) { + if (snprintf (out_buf, max_len - 1, "%"PFMT64x, rz_debug_get_baddr (core->dbg, NULL)) < 0) { return -1; } return 0; @@ -400,7 +400,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, memset (out_buf, 0, max_len); out_buf[0] = 'm'; ret = 1; - r_list_foreach (list, iter, dbgpid) { + rz_list_foreach (list, iter, dbgpid) { // Max length of a hex pid = 8? if (ret >= max_len - 9) { break; @@ -416,13 +416,13 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, case 'r': // dptr -> return current tid as int return core->dbg->tid; default: - return r_core_cmd (core, cmd, 0); + return rz_core_cmd (core, cmd, 0); } } break; case 'r': // dr - r_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); - be = r_config_get_i (core->config, "cfg.bigendian"); + rz_debug_reg_sync (core->dbg, R_REG_TYPE_ALL, false); + be = rz_config_get_i (core->config, "cfg.bigendian"); if (isspace ((ut8)cmd[2])) { // dr reg const char *name, *val_ptr; char new_cmd[128] = { 0 }; @@ -434,7 +434,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, } else { strncpy (new_cmd, name, sizeof (new_cmd) - 1); } - if (!(r = r_reg_get (core->dbg->reg, new_cmd, -1))) { + if (!(r = rz_reg_get (core->dbg->reg, new_cmd, -1))) { return -1; } if (val_ptr) { // dr reg=val @@ -442,7 +442,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, off = val_ptr - cmd; if (be) { // We don't need to swap - r_core_cmd (core, cmd, 0); + rz_core_cmd (core, cmd, 0); } // Previous contents are overwritten, since len(name) < off strncpy (new_cmd, cmd, off); @@ -452,21 +452,21 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, reg_val, r->size / 8, be) < 0) { return -1; } - return r_core_cmd (core, new_cmd, 0); + return rz_core_cmd (core, new_cmd, 0); } // Big registers if (swap_big_regs (new_cmd + off, sizeof (new_cmd) - off - 1, val_ptr, r->size / 8) < 0) { return -1; } - return r_core_cmd (core, new_cmd, 0); + return rz_core_cmd (core, new_cmd, 0); } if (r->size <= 64) { - reg_val = r_reg_get_value (core->dbg->reg, r); + reg_val = rz_reg_get_value (core->dbg->reg, r); return write_reg_val (out_buf, max_len - 1, reg_val, r->size / 8, be); } - r_reg_get_value_big (core->dbg->reg, + rz_reg_get_value_big (core->dbg->reg, r, &val_big); return write_big_reg (out_buf, max_len - 1, &val_big, r->size / 8, be); @@ -481,15 +481,15 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, return -1; } if (gdb_reg->size <= 8) { - reg_val = r_reg_getv (core->dbg->reg, gdb_reg->name); + reg_val = rz_reg_getv (core->dbg->reg, gdb_reg->name); if (write_reg_val (out_buf + ret, gdb_reg->size * 2 + 1, reg_val, gdb_reg->size, be) < 0) { return -1; } } else { - r_reg_get_value_big (core->dbg->reg, - r_reg_get (core->dbg->reg, gdb_reg->name, -1), + rz_reg_get_value_big (core->dbg->reg, + rz_reg_get (core->dbg->reg, gdb_reg->name, -1), &val_big); if (write_big_reg (out_buf + ret, gdb_reg->size * 2 + 1, &val_big, gdb_reg->size, be) < 0) { @@ -502,7 +502,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, out_buf[ret] = '\0'; return ret; default: - return r_core_cmd (core, cmd, 0); + return rz_core_cmd (core, cmd, 0); } break; case 'i': @@ -510,7 +510,7 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, case 'f': { ut64 off, len, sz, namelen; - RIODesc *desc = core && core->file ? r_io_desc_get (core->io, core->file->fd) : NULL; + RzIODesc *desc = core && core->file ? rz_io_desc_get (core->io, core->file->fd) : NULL; if (sscanf (cmd + 2, "%"PFMT64x",%"PFMT64x, &off, &len) != 2) { strcpy (out_buf, "E00"); return 0; @@ -532,19 +532,19 @@ static int r_core_rtr_gdb_cb(libgdbr_t *g, void *core_ptr, const char *cmd, break; case 'm': sscanf (cmd + 1, "%"PFMT64x",%x", &m_off, &ret); - if (r_io_read_at (core->io, m_off, (ut8*) out_buf, ret)) { + if (rz_io_read_at (core->io, m_off, (ut8*) out_buf, ret)) { return ret; } return -1; default: - return r_core_cmd (core, cmd, 0); + return rz_core_cmd (core, cmd, 0); } return -1; } // path = " " -static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) { - RSocket *sock; +static int rz_core_rtr_gdb_run(RzCore *core, int launch, const char *path) { + RzSocket *sock; int p, ret; bool debug_msg = false; char port[10]; @@ -558,7 +558,7 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) { debug_msg = true; path++; } - if (!(path = r_str_trim_head_ro (path)) || !*path) { + if (!(path = rz_str_trim_head_ro (path)) || !*path) { eprintf ("gdbserver: Port not specified\n"); return -1; } @@ -571,55 +571,55 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) { eprintf ("gdbserver: File not specified\n"); return -1; } - if (!(file = (char *)r_str_trim_head_ro (file)) || !*file) { + if (!(file = (char *)rz_str_trim_head_ro (file)) || !*file) { eprintf ("gdbserver: File not specified\n"); return -1; } args = strchr (file, ' '); if (args) { *args++ = '\0'; - if (!(args = (char *)r_str_trim_head_ro (args))) { + if (!(args = (char *)rz_str_trim_head_ro (args))) { args = ""; } } else { args = ""; } - if (!r_core_file_open (core, file, R_PERM_R, 0)) { + if (!rz_core_file_open (core, file, R_PERM_R, 0)) { eprintf ("Cannot open file (%s)\n", file); return -1; } - r_core_file_reopen_debug (core, args); + rz_core_file_reopen_debug (core, args); - if (!(sock = r_socket_new (false))) { + if (!(sock = rz_socket_new (false))) { eprintf ("gdbserver: Could not open socket for listening\n"); return -1; } - if (!r_socket_listen (sock, port, NULL)) { - r_socket_free (sock); + if (!rz_socket_listen (sock, port, NULL)) { + rz_socket_free (sock); eprintf ("gdbserver: Cannot listen on port: %s\n", port); return -1; } if (!(g = R_NEW0 (libgdbr_t))) { - r_socket_free (sock); + rz_socket_free (sock); eprintf ("gdbserver: Cannot alloc libgdbr instance\n"); return -1; } gdbr_init (g, true); g->server_debug = debug_msg; - int arch = r_sys_arch_id (r_config_get (core->config, "asm.arch")); - int bits = r_config_get_i (core->config, "asm.bits"); + int arch = rz_sys_arch_id (rz_config_get (core->config, "asm.arch")); + int bits = rz_config_get_i (core->config, "asm.bits"); gdbr_set_architecture (g, arch, bits); core->gdbserver_up = 1; eprintf ("gdbserver started on port: %s, file: %s\n", port, file); for (;;) { - if (!(g->sock = r_socket_accept (sock))) { + if (!(g->sock = rz_socket_accept (sock))) { break; } g->connected = 1; - ret = gdbr_server_serve (g, r_core_rtr_gdb_cb, (void*) core); - r_socket_close (g->sock); + ret = gdbr_server_serve (g, rz_core_rtr_gdb_cb, (void*) core); + rz_socket_close (g->sock); g->connected = 0; if (ret < 0) { break; @@ -628,13 +628,13 @@ static int r_core_rtr_gdb_run(RCore *core, int launch, const char *path) { core->gdbserver_up = 0; gdbr_cleanup (g); free (g); - r_socket_free (sock); + rz_socket_free (sock); return 0; } -R_API int r_core_rtr_gdb(RCore *core, int launch, const char *path) { +RZ_API int rz_core_rtr_gdb(RzCore *core, int launch, const char *path) { int ret; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: connect disabled\n"); return -1; } @@ -643,11 +643,11 @@ R_API int r_core_rtr_gdb(RCore *core, int launch, const char *path) { eprintf ("gdbserver is already running\n"); return -1; } - ret = r_core_rtr_gdb_run (core, launch, path); + ret = rz_core_rtr_gdb_run (core, launch, path); return ret; } -R_API void r_core_rtr_pushout(RCore *core, const char *input) { +RZ_API void rz_core_rtr_pushout(RzCore *core, const char *input) { int fd = atoi (input); const char *cmd = NULL; char *str = NULL; @@ -670,7 +670,7 @@ R_API void r_core_rtr_pushout(RCore *core, const char *input) { return; } - if (!(str = r_core_cmd_str (core, cmd))) { + if (!(str = rz_core_cmd_str (core, cmd))) { eprintf ("Error: radare_cmd_str returned NULL\n"); return; } @@ -680,14 +680,14 @@ R_API void r_core_rtr_pushout(RCore *core, const char *input) { eprintf ("Error: Cannot use '=<' to a rap connection.\n"); break; case RTR_PROTOCOL_UNIX: - r_socket_write (rtr_host[rtr_n].fd, str, strlen (str)); + rz_socket_write (rtr_host[rtr_n].fd, str, strlen (str)); break; case RTR_PROTOCOL_HTTP: eprintf ("TODO\n"); break; case RTR_PROTOCOL_TCP: case RTR_PROTOCOL_UDP: - r_socket_write (rtr_host[rtr_n].fd, str, strlen (str)); + rz_socket_write (rtr_host[rtr_n].fd, str, strlen (str)); break; default: eprintf ("Unknown protocol\n"); @@ -696,7 +696,7 @@ R_API void r_core_rtr_pushout(RCore *core, const char *input) { free (str); } -R_API void r_core_rtr_list(RCore *core) { +RZ_API void rz_core_rtr_list(RzCore *core) { int i; for (i = 0; i < RTR_MAX_HOSTS; i++) { if (!rtr_host[i].fd) { @@ -710,23 +710,23 @@ R_API void r_core_rtr_list(RCore *core) { case RTR_PROTOCOL_RAP: proto = "rap"; break; case RTR_PROTOCOL_UNIX: proto = "unix"; break; } - r_cons_printf ("%d fd:%i %s://%s:%i/%s\n", + rz_cons_printf ("%d fd:%i %s://%s:%i/%s\n", i, rtr_host[i].fd->fd, proto, rtr_host[i].host, rtr_host[i].port, rtr_host[i].file); } } -R_API void r_core_rtr_add(RCore *core, const char *_input) { +RZ_API void rz_core_rtr_add(RzCore *core, const char *_input) { char *port, input[1024], *file = NULL, *ptr = NULL; int i, timeout, ret; - RSocket *fd; + RzSocket *fd; - timeout = r_config_get_i (core->config, "http.timeout"); + timeout = rz_config_get_i (core->config, "http.timeout"); strncpy (input, _input, sizeof (input) - 4); input[sizeof (input) - 4] = '\0'; int proto = RTR_PROTOCOL_RAP; - char *host = (char *)r_str_trim_head_ro (input); + char *host = (char *)rz_str_trim_head_ro (input); char *pikaboo = strstr (host, "://"); if (pikaboo) { struct { @@ -741,10 +741,10 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { {"unix", RTR_PROTOCOL_UNIX}, {NULL, 0} }; - char *s = r_str_ndup (input, pikaboo - input); + char *s = rz_str_ndup (input, pikaboo - input); //int nlen = pikaboo - input; for (i = 0; uris[i].name; i++) { - if (r_str_endswith (s, uris[i].name)) { + if (rz_str_endswith (s, uris[i].name)) { proto = uris[i].protocol; host = pikaboo + 3; break; @@ -759,7 +759,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { } else { *ptr++ = '\0'; port = ptr; - r_str_trim (port); + rz_str_trim (port); } } else { port = NULL; @@ -767,7 +767,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { file = strchr (ptr, '/'); if (file) { *file = 0; - file = (char *)r_str_trim_head_ro (file + 1); + file = (char *)rz_str_trim_head_ro (file + 1); } else { if (*host == ':' || strstr (host, "://:")) { // listen // it's fine to listen without serving a file @@ -778,12 +778,12 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { } } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: connect disabled\n"); return; } - fd = r_socket_new (false); + fd = rz_socket_new (false); if (!fd) { eprintf ("Error: Cannot create new socket\n"); return; @@ -792,8 +792,8 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { case RTR_PROTOCOL_HTTP: { int len; - char *uri = r_str_newf ("http://%s:%s/%s", host, port, file); - char *str = r_socket_http_get (uri, NULL, &len); + char *uri = rz_str_newf ("http://%s:%s/%s", host, port, file); + char *str = rz_socket_http_get (uri, NULL, &len); if (!str) { eprintf ("Cannot find peer\n"); return; @@ -804,40 +804,40 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { } break; case RTR_PROTOCOL_RAP: - if (!r_socket_connect_tcp (fd, host, port, timeout)) { //TODO: Use rap.ssl + if (!rz_socket_connect_tcp (fd, host, port, timeout)) { //TODO: Use rap.ssl eprintf ("Error: Cannot connect to '%s' (%s)\n", host, port); - r_socket_free (fd); + rz_socket_free (fd); return; } else { - int n = r_socket_rap_client_open (fd, file, 0); + int n = rz_socket_rap_client_open (fd, file, 0); eprintf ("opened as fd = %d\n", n); } break; case RTR_PROTOCOL_UNIX: - if (!r_socket_connect_unix (fd, host)) { + if (!rz_socket_connect_unix (fd, host)) { core->num->value = 1; eprintf ("Error: Cannot connect to 'unix://%s'\n", host); - r_socket_free (fd); + rz_socket_free (fd); return; } core->num->value = 0; eprintf ("Connected to: 'unix://%s'\n", host); break; case RTR_PROTOCOL_TCP: - if (!r_socket_connect_tcp (fd, host, port, timeout)) { //TODO: Use rap.ssl + if (!rz_socket_connect_tcp (fd, host, port, timeout)) { //TODO: Use rap.ssl core->num->value = 1; eprintf ("Error: Cannot connect to '%s' (%s)\n", host, port); - r_socket_free (fd); + rz_socket_free (fd); return; } core->num->value = 0; eprintf ("Connected to: %s at port %s\n", host, port); break; case RTR_PROTOCOL_UDP: - if (!r_socket_connect_udp (fd, host, port, timeout)) { //TODO: Use rap.ssl + if (!rz_socket_connect_udp (fd, host, port, timeout)) { //TODO: Use rap.ssl core->num->value = 1; eprintf ("Error: Cannot connect to '%s' (%s)\n", host, port); - r_socket_free (fd); + rz_socket_free (fd); return; } core->num->value = 0; @@ -851,7 +851,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { } rtr_host[i].proto = proto; strncpy (rtr_host[i].host, host, sizeof (rtr_host[i].host)-1); - rtr_host[i].port = r_num_get (core->num, port); + rtr_host[i].port = rz_num_get (core->num, port); if (!file) { file = ""; } @@ -861,56 +861,56 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { break; } core->num->value = ret; - // double free wtf is freed this here? r_socket_free(fd); - //r_core_rtr_list (core); + // double free wtf is freed this here? rz_socket_free(fd); + //rz_core_rtr_list (core); } -R_API void r_core_rtr_remove(RCore *core, const char *input) { +RZ_API void rz_core_rtr_remove(RzCore *core, const char *input) { int i; if (IS_DIGIT (input[0])) { - i = r_num_math (core->num, input); + i = rz_num_math (core->num, input); if (i >= 0 && i < RTR_MAX_HOSTS) { - r_socket_free (rtr_host[i].fd); + rz_socket_free (rtr_host[i].fd); rtr_host[i].fd = NULL; } } else { for (i = 0; i < RTR_MAX_HOSTS; i++) { if (rtr_host[i].fd) { - r_socket_free (rtr_host[i].fd); + rz_socket_free (rtr_host[i].fd); rtr_host[i].fd = NULL; } } - memset (rtr_host, '\0', RTR_MAX_HOSTS * sizeof (RCoreRtrHost)); + memset (rtr_host, '\0', RTR_MAX_HOSTS * sizeof (RzCoreRtrHost)); rtr_n = 0; } } -R_API void r_core_rtr_session(RCore *core, const char *input) { +RZ_API void rz_core_rtr_session(RzCore *core, const char *input) { __rtr_shell (core, atoi (input)); } -static bool r_core_rtr_rap_run(RCore *core, const char *input) { - char *file = r_str_newf ("rap://%s", input); +static bool rz_core_rtr_rap_run(RzCore *core, const char *input) { + char *file = rz_str_newf ("rap://%s", input); int flags = R_PERM_RW; - RIODesc *fd = r_io_open_nomap (core->io, file, flags, 0644); + RzIODesc *fd = rz_io_open_nomap (core->io, file, flags, 0644); if (fd) { - if (r_io_is_listener (core->io)) { - if (!r_core_serve (core, fd)) { - r_cons_singleton ()->context->breaked = true; + if (rz_io_is_listener (core->io)) { + if (!rz_core_serve (core, fd)) { + rz_cons_singleton ()->context->breaked = true; } - r_io_desc_close (fd); + rz_io_desc_close (fd); // avoid double free, we are not the owners of this fd so we can't destroy it - //r_io_desc_free (fd); + //rz_io_desc_free (fd); } } else { - r_cons_singleton ()->context->breaked = true; + rz_cons_singleton ()->context->breaked = true; } - return !r_cons_singleton ()->context->breaked; - // r_core_cmdf (core, "o rap://%s", input); + return !rz_cons_singleton ()->context->breaked; + // rz_core_cmdf (core, "o rap://%s", input); } -static RThreadFunctionRet r_core_rtr_rap_thread(RThread *th) { +static RzThreadFunctionRet rz_core_rtr_rap_thread(RzThread *th) { if (!th) { return false; } @@ -918,25 +918,25 @@ static RThreadFunctionRet r_core_rtr_rap_thread(RThread *th) { if (!rt || !rt->core) { return false; } - return r_core_rtr_rap_run (rt->core, rt->input) ? R_TH_REPEAT : R_TH_STOP; + return rz_core_rtr_rap_run (rt->core, rt->input) ? R_TH_REPEAT : R_TH_STOP; } -R_API void r_core_rtr_cmd(RCore *core, const char *input) { +RZ_API void rz_core_rtr_cmd(RzCore *core, const char *input) { unsigned int cmd_len = 0; int fd = atoi (input); if (!fd && *input != '0') { fd = -1; } - const char *cmd = strchr (r_str_trim_head_ro (input), ' '); + const char *cmd = strchr (rz_str_trim_head_ro (input), ' '); if (cmd) { cmd ++; cmd_len = strlen (cmd); } // "=:" if (*input == ':' && !strchr (input + 1, ':')) { - void *bed = r_cons_sleep_begin (); - r_core_rtr_rap_run (core, input); - r_cons_sleep_end (bed); + void *bed = rz_cons_sleep_begin (); + rz_core_rtr_rap_run (core, input); + rz_cons_sleep_end (bed); return; } @@ -951,11 +951,11 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) { RT->core = core; RT->input = strdup (input + 1); //RapThread rt = { core, strdup (input + 1) }; - rapthread = r_th_new (r_core_rtr_rap_thread, RT, false); - int cpuaff = (int)r_config_get_i (core->config, "cfg.cpuaffinity"); - r_th_setaffinity (rapthread, cpuaff); - r_th_setname (rapthread, "rapthread"); - r_th_start (rapthread, true); + rapthread = rz_th_new (rz_core_rtr_rap_thread, RT, false); + int cpuaff = (int)rz_config_get_i (core->config, "cfg.cpuaffinity"); + rz_th_setaffinity (rapthread, cpuaff); + rz_th_setname (rapthread, "rapthread"); + rz_th_start (rapthread, true); eprintf ("Background rap server started.\n"); } } @@ -980,49 +980,49 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) { } if (rtr_host[rtr_n].proto == RTR_PROTOCOL_TCP) { - RCoreRtrHost *rh = &rtr_host[rtr_n]; - RSocket *s = rh->fd; + RzCoreRtrHost *rh = &rtr_host[rtr_n]; + RzSocket *s = rh->fd; if (cmd_len < 1 || cmd_len > 16384) { return; } - r_socket_close (s); - if (!r_socket_connect (s, rh->host, sdb_fmt ("%d", rh->port), R_SOCKET_PROTO_TCP, 0)) { + rz_socket_close (s); + if (!rz_socket_connect (s, rh->host, sdb_fmt ("%d", rh->port), R_SOCKET_PROTO_TCP, 0)) { eprintf ("Error: Cannot connect to '%s' (%d)\n", rh->host, rh->port); - r_socket_free (s); + rz_socket_free (s); return; } - r_socket_write (s, (ut8*)cmd, cmd_len); - r_socket_write (s, "\n", 2); - int maxlen = 4096; // r_read_le32 (blen); + rz_socket_write (s, (ut8*)cmd, cmd_len); + rz_socket_write (s, "\n", 2); + int maxlen = 4096; // rz_read_le32 (blen); char *cmd_output = calloc (1, maxlen + 1); if (!cmd_output) { eprintf ("Error: Allocating cmd output\n"); return; } - (void)r_socket_read_block (s, (ut8*)cmd_output, maxlen); + (void)rz_socket_read_block (s, (ut8*)cmd_output, maxlen); //ensure the termination - r_socket_close (s); + rz_socket_close (s); cmd_output[maxlen] = 0; - r_cons_println (cmd_output); + rz_cons_println (cmd_output); free ((void *)cmd_output); return; } if (rtr_host[rtr_n].proto == RTR_PROTOCOL_HTTP) { - RCoreRtrHost *rh = &rtr_host[rtr_n]; + RzCoreRtrHost *rh = &rtr_host[rtr_n]; if (cmd_len < 1 || cmd_len > 16384) { return; } int len; - char *uri = r_str_newf ("http://%s:%d/cmd/%s", rh->host, rh->port, cmd); - char *str = r_socket_http_get (uri, NULL, &len); + char *uri = rz_str_newf ("http://%s:%d/cmd/%s", rh->host, rh->port, cmd); + char *str = rz_socket_http_get (uri, NULL, &len); if (!str) { eprintf ("Cannot find '%s'\n", uri); return; } core->num->value = 0; str[len] = 0; - r_cons_print (str); + rz_cons_print (str); free ((void *)str); free ((void *)uri); return; @@ -1030,15 +1030,15 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) { if (rtr_host[rtr_n].proto == RTR_PROTOCOL_RAP) { core->num->value = 0; // that's fine - cmd = r_str_trim_head_ro (cmd); - RSocket *fh = rtr_host[rtr_n].fd; + cmd = rz_str_trim_head_ro (cmd); + RzSocket *fh = rtr_host[rtr_n].fd; if (!strlen (cmd)) { // just check if we can connect - r_socket_close (fh); + rz_socket_close (fh); return; } - char *cmd_output = r_socket_rap_client_command (fh, cmd, &core->anal->coreb); - r_cons_println (cmd_output); + char *cmd_output = rz_socket_rap_client_command (fh, cmd, &core->anal->coreb); + rz_cons_println (cmd_output); free (cmd_output); return; } @@ -1046,35 +1046,35 @@ R_API void r_core_rtr_cmd(RCore *core, const char *input) { } // TODO: support len for binary data? -R_API char *r_core_rtr_cmds_query (RCore *core, const char *host, const char *port, const char *cmd) { - RSocket *s = r_socket_new (0); +RZ_API char *rz_core_rtr_cmds_query (RzCore *core, const char *host, const char *port, const char *cmd) { + RzSocket *s = rz_socket_new (0); const int timeout = 0; char *rbuf = NULL; int retries = 6; ut8 buf[1024]; - for (; retries > 0; r_sys_usleep (10 * 1000)) { - if (r_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, timeout)) { + for (; retries > 0; rz_sys_usleep (10 * 1000)) { + if (rz_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, timeout)) { break; } retries--; } if (retries > 0) { rbuf = strdup (""); - r_socket_write (s, (void*)cmd, strlen (cmd)); - //r_socket_write (s, "px\n", 3); + rz_socket_write (s, (void*)cmd, strlen (cmd)); + //rz_socket_write (s, "px\n", 3); for (;;) { - int ret = r_socket_read (s, buf, sizeof (buf)); + int ret = rz_socket_read (s, buf, sizeof (buf)); if (ret < 1) { break; } buf[ret] = 0; - rbuf = r_str_append (rbuf, (const char *)buf); + rbuf = rz_str_append (rbuf, (const char *)buf); } } else { eprintf ("Cannot connect\n"); } - r_socket_free (s); + rz_socket_free (s); return rbuf; } @@ -1087,7 +1087,7 @@ typedef struct rtr_cmds_context_t { } rtr_cmds_context; typedef struct rtr_cmds_client_context_t { - RCore *core; + RzCore *core; char buf[4096]; char *res; size_t len; @@ -1099,9 +1099,9 @@ static void rtr_cmds_client_close(uv_tcp_t *client, bool remove) { rtr_cmds_context *context = loop->data; if (remove) { size_t i; - for (i = 0; i < r_pvector_len (&context->clients); i++) { - if (r_pvector_at (&context->clients, i) == client) { - r_pvector_remove_at (&context->clients, i); + for (i = 0; i < rz_pvector_len (&context->clients); i++) { + if (rz_pvector_at (&context->clients, i) == client) { + rz_pvector_remove_at (&context->clients, i); break; } } @@ -1150,16 +1150,16 @@ static void rtr_cmds_read(uv_stream_t *client, ssize_t nread, const uv_buf_t *bu } *end = '\0'; - r_cons_sleep_end (context->bed); - client_context->res = r_core_cmd_str (client_context->core, (const char *)client_context->buf); - context->bed = r_cons_sleep_begin (); + rz_cons_sleep_end (context->bed); + client_context->res = rz_core_cmd_str (client_context->core, (const char *)client_context->buf); + context->bed = rz_cons_sleep_begin (); if (!client_context->res || !*client_context->res) { free (client_context->res); client_context->res = strdup ("\n"); } - if (!client_context->res || (!r_config_get_i (client_context->core->config, "scr.prompt") && + if (!client_context->res || (!rz_config_get_i (client_context->core->config, "scr.prompt") && !strcmp ((char *)buf, "q!")) || !strcmp ((char *)buf, ".--")) { rtr_cmds_client_close ((uv_tcp_t *) client, true); @@ -1205,7 +1205,7 @@ static void rtr_cmds_new_connection(uv_stream_t *server, int status) { uv_read_start ((uv_stream_t *)client, rtr_cmds_alloc_buffer, rtr_cmds_read); - r_pvector_push (&context->clients, client); + rz_pvector_push (&context->clients, client); } else { uv_close ((uv_handle_t *)client, NULL); } @@ -1219,7 +1219,7 @@ static void rtr_cmds_stop(uv_async_t *handle) { uv_close ((uv_handle_t *) &context->server, NULL); void **it; - r_pvector_foreach (&context->clients, it) { + rz_pvector_foreach (&context->clients, it) { uv_tcp_t *client = *it; rtr_cmds_client_close (client, false); } @@ -1229,9 +1229,9 @@ static void rtr_cmds_break(uv_async_t *async) { uv_async_send (async); } -R_API int r_core_rtr_cmds(RCore *core, const char *port) { +RZ_API int rz_core_rtr_cmds(RzCore *core, const char *port) { if (!port || port[0] == '?') { - r_cons_printf ("Usage: .:[tcp-port] run r2 commands for clients\n"); + rz_cons_printf ("Usage: .:[tcp-port] run r2 commands for clients\n"); return 0; } @@ -1242,15 +1242,15 @@ R_API int r_core_rtr_cmds(RCore *core, const char *port) { uv_loop_init (loop); rtr_cmds_context context; - r_pvector_init (&context.clients, NULL); + rz_pvector_init (&context.clients, NULL); loop->data = &context; context.server.data = core; uv_tcp_init (loop, &context.server); struct sockaddr_in addr; - bool local = (bool) r_config_get_i(core->config, "tcp.islocal"); - int porti = r_socket_port_by_name (port); + bool local = (bool) rz_config_get_i(core->config, "tcp.islocal"); + int porti = rz_socket_port_by_name (port); uv_ip4_addr (local ? "127.0.0.1" : "0.0.0.0", porti, &addr); uv_tcp_bind (&context.server, (const struct sockaddr *) &addr, 0); @@ -1263,53 +1263,53 @@ R_API int r_core_rtr_cmds(RCore *core, const char *port) { uv_async_t stop_async; uv_async_init (loop, &stop_async, rtr_cmds_stop); - r_cons_break_push ((RConsBreak) rtr_cmds_break, &stop_async); - context.bed = r_cons_sleep_begin (); + rz_cons_break_push ((RzConsBreak) rtr_cmds_break, &stop_async); + context.bed = rz_cons_sleep_begin (); uv_run (loop, UV_RUN_DEFAULT); - r_cons_sleep_end (context.bed); - r_cons_break_pop (); + rz_cons_sleep_end (context.bed); + rz_cons_break_pop (); beach: uv_loop_close (loop); free (loop); - r_pvector_clear (&context.clients); + rz_pvector_clear (&context.clients); return 0; } #else -R_API int r_core_rtr_cmds (RCore *core, const char *port) { +RZ_API int rz_core_rtr_cmds (RzCore *core, const char *port) { unsigned char buf[4097]; - RSocket *ch = NULL; + RzSocket *ch = NULL; int i, ret; char *str; if (!port || port[0] == '?') { - r_cons_printf ("Usage: .:[tcp-port] run r2 commands for clients\n"); + rz_cons_printf ("Usage: .:[tcp-port] run r2 commands for clients\n"); return false; } - RSocket *s = r_socket_new (0); - s->local = r_config_get_i (core->config, "tcp.islocal"); + RzSocket *s = rz_socket_new (0); + s->local = rz_config_get_i (core->config, "tcp.islocal"); - if (!r_socket_listen (s, port, NULL)) { + if (!rz_socket_listen (s, port, NULL)) { eprintf ("Error listening on port %s\n", port); - r_socket_free (s); + rz_socket_free (s); return false; } eprintf ("Listening for commands on port %s\n", port); listenport = port; - r_cons_break_push ((RConsBreak)r_core_rtr_http_stop, core); + rz_cons_break_push ((RzConsBreak)rz_core_rtr_http_stop, core); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } - void *bed = r_cons_sleep_begin (); - ch = r_socket_accept (s); + void *bed = rz_cons_sleep_begin (); + ch = rz_socket_accept (s); buf[0] = 0; - ret = r_socket_read (ch, buf, sizeof (buf) - 1); - r_cons_sleep_end (bed); + ret = rz_socket_read (ch, buf, sizeof (buf) - 1); + rz_cons_sleep_end (bed); if (ret > 0) { buf[ret] = 0; for (i = 0; buf[i]; i++) { @@ -1317,29 +1317,29 @@ R_API int r_core_rtr_cmds (RCore *core, const char *port) { buf[i] = buf[i + 1]? ';': '\0'; } } - if ((!r_config_get_i (core->config, "scr.prompt") && + if ((!rz_config_get_i (core->config, "scr.prompt") && !strcmp ((char *)buf, "q!")) || !strcmp ((char *)buf, ".--")) { - r_socket_close (ch); + rz_socket_close (ch); break; } - str = r_core_cmd_str (core, (const char *)buf); - bed = r_cons_sleep_begin (); + str = rz_core_cmd_str (core, (const char *)buf); + bed = rz_cons_sleep_begin (); if (str && *str) { - r_socket_write (ch, str, strlen (str)); + rz_socket_write (ch, str, strlen (str)); } else { - r_socket_write (ch, "\n", 1); + rz_socket_write (ch, "\n", 1); } - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); free (str); } - r_socket_close (ch); - r_socket_free (ch); + rz_socket_close (ch); + rz_socket_free (ch); ch = NULL; } - r_cons_break_pop (); - r_socket_free (s); - r_socket_free (ch); + rz_cons_break_pop (); + rz_socket_free (s); + rz_socket_free (ch); return 0; } diff --git a/libr/core/rtr_http.c b/librz/core/rtr_http.c similarity index 51% rename from libr/core/rtr_http.c rename to librz/core/rtr_http.c index 5c8b314e53..e08c72fed1 100644 --- a/libr/core/rtr_http.c +++ b/librz/core/rtr_http.c @@ -1,28 +1,28 @@ // included from rtr.c // return 1 on error -static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char *path) { +static int rz_core_rtr_http_run(RzCore *core, int launch, int browse, const char *path) { RConfig *newcfg = NULL, *origcfg = NULL; char headers[128] = R_EMPTY; - RSocketHTTPRequest *rs; + RzSocketHTTPRequest *rs; char buf[32]; int ret = 0; - RSocket *s; - RSocketHTTPOptions so; + RzSocket *s; + RzSocketHTTPOptions so; char *dir; int iport; - const char *host = r_config_get (core->config, "http.bind"); - const char *index = r_config_get (core->config, "http.index"); - const char *root = r_config_get (core->config, "http.root"); - const char *homeroot = r_config_get (core->config, "http.homeroot"); - const char *port = r_config_get (core->config, "http.port"); - const char *allow = r_config_get (core->config, "http.allow"); - const char *httpui = r_config_get (core->config, "http.ui"); - const char *httpauthfile = r_config_get (core->config, "http.authfile"); + const char *host = rz_config_get (core->config, "http.bind"); + const char *index = rz_config_get (core->config, "http.index"); + const char *root = rz_config_get (core->config, "http.root"); + const char *homeroot = rz_config_get (core->config, "http.homeroot"); + const char *port = rz_config_get (core->config, "http.port"); + const char *allow = rz_config_get (core->config, "http.allow"); + const char *httpui = rz_config_get (core->config, "http.ui"); + const char *httpauthfile = rz_config_get (core->config, "http.authfile"); char *pfile = NULL; - if (!r_file_is_directory (root)) { - if (!r_file_is_directory (homeroot)) { + if (!rz_file_is_directory (root)) { + if (!rz_file_is_directory (homeroot)) { eprintf ("Cannot find http.root or http.homeroot\n"); } } @@ -35,7 +35,7 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * } if (path && atoi (path)) { port = path; - r_config_set (core->config, "http.port", port); + rz_config_set (core->config, "http.port", port); path = NULL; } else { if (core->file && (!path || !*path)) { @@ -49,12 +49,12 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * } if (!strcmp (port, "0")) { - r_num_irand (); - iport = 1024 + r_num_rand (45256); + rz_num_irand (); + iport = 1024 + rz_num_rand (45256); snprintf (buf, sizeof (buf), "%d", iport); port = buf; } - s = r_socket_new (false); + s = rz_socket_new (false); { if (host && *host) { if (!strcmp (host, "::1")) { @@ -65,11 +65,11 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * s->local = true; } else if (!strcmp (host, "local")) { s->local = true; - r_config_set (core->config, "http.bind", "localhost"); + rz_config_set (core->config, "http.bind", "localhost"); } else if (host[0]=='0' || !strcmp (host, "public")) { // public host = "127.0.0.1"; - r_config_set (core->config, "http.bind", "0.0.0.0"); + rz_config_set (core->config, "http.bind", "0.0.0.0"); s->local = false; } else { s->local = true; @@ -79,57 +79,57 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * } memset (&so, 0, sizeof (so)); } - if (!r_socket_listen (s, port, NULL)) { - r_socket_free (s); + if (!rz_socket_listen (s, port, NULL)) { + rz_socket_free (s); eprintf ("Cannot listen on http.port\n"); return 1; } if (browse == 'H') { - const char *browser = r_config_get (core->config, "http.browser"); - r_sys_cmdf ("%s http://%s:%d/%s &", + const char *browser = rz_config_get (core->config, "http.browser"); + rz_sys_cmdf ("%s http://%s:%d/%s &", browser, host, atoi (port), path? path:""); } - so.httpauth = r_config_get_i (core->config, "http.auth"); + so.httpauth = rz_config_get_i (core->config, "http.auth"); if (so.httpauth) { if (!httpauthfile) { - r_socket_free (s); + rz_socket_free (s); eprintf ("No user list set for HTTP Authentication\n"); return 1; } - pfile = r_file_slurp (httpauthfile, NULL); + pfile = rz_file_slurp (httpauthfile, NULL); if (pfile) { - so.authtokens = r_str_split_list (pfile, "\n", 0); + so.authtokens = rz_str_split_list (pfile, "\n", 0); } else { - r_socket_free (s); + rz_socket_free (s); eprintf ("Empty list of HTTP users\n"); return 1; } - so.timeout = r_config_get_i (core->config, "http.timeout"); + so.timeout = rz_config_get_i (core->config, "http.timeout"); so.accept_timeout = 1; } origcfg = core->config; - newcfg = r_config_clone (core->config); + newcfg = rz_config_clone (core->config); core->config = newcfg; - r_config_set (core->config, "asm.cmt.right", "false"); + rz_config_set (core->config, "asm.cmt.right", "false"); #if 0 // WHY - r_config_set (core->config, "scr.html", "true"); + rz_config_set (core->config, "scr.html", "true"); #endif - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); - r_config_set (core->config, "asm.bytes", "false"); - r_config_set (core->config, "scr.interactive", "false"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "scr.interactive", "false"); bool restoreSandbox = false; - if (r_config_get_i (core->config, "http.sandbox")) { - //(void)r_config_get_i (core->config, "cfg.sandbox"); - r_config_set (core->config, "cfg.sandbox", "true"); + if (rz_config_get_i (core->config, "http.sandbox")) { + //(void)rz_config_get_i (core->config, "cfg.sandbox"); + rz_config_set (core->config, "cfg.sandbox", "true"); restoreSandbox = true; } eprintf ("Starting http server...\n"); @@ -143,8 +143,8 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * newblk = malloc (core->blocksize); if (!newblk) { - r_socket_free (s); - r_list_free (so.authtokens); + rz_socket_free (s); + rz_list_free (so.authtokens); free (pfile); return 1; } @@ -152,13 +152,13 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * core->block = newblk; // TODO: handle mutex lock/unlock here - r_cons_break_push ((RConsBreak)r_core_rtr_http_stop, core); - while (!r_cons_is_breaked ()) { + rz_cons_break_push ((RzConsBreak)rz_core_rtr_http_stop, core); + while (!rz_cons_is_breaked ()) { /* restore environment */ core->config = origcfg; - r_config_set (origcfg, "scr.html", r_config_get (origcfg, "scr.html")); - r_config_set_i (origcfg, "scr.color", r_config_get_i (origcfg, "scr.color")); - r_config_set (origcfg, "scr.interactive", r_config_get (origcfg, "scr.interactive")); + rz_config_set (origcfg, "scr.html", rz_config_get (origcfg, "scr.html")); + rz_config_set_i (origcfg, "scr.color", rz_config_get_i (origcfg, "scr.color")); + rz_config_set (origcfg, "scr.interactive", rz_config_get (origcfg, "scr.interactive")); core->http_up = 0; // DAT IS NOT TRUE AT ALL.. but its the way to enable visual newoff = core->offset; @@ -174,9 +174,9 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * /* this is blocking */ activateDieTime (core); - void *bed = r_cons_sleep_begin (); - rs = r_socket_http_accept (s, &so); - r_cons_sleep_end (bed); + void *bed = rz_cons_sleep_begin (); + rs = rz_socket_http_accept (s, &so); + rz_cons_sleep_end (bed); origoff = core->offset; origblk = core->block; @@ -188,29 +188,29 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * // backup and restore offset and blocksize core->http_up = 1; core->config = newcfg; - r_config_set (newcfg, "scr.html", r_config_get (newcfg, "scr.html")); - r_config_set_i (newcfg, "scr.color", r_config_get_i (newcfg, "scr.color")); - r_config_set (newcfg, "scr.interactive", r_config_get (newcfg, "scr.interactive")); + rz_config_set (newcfg, "scr.html", rz_config_get (newcfg, "scr.html")); + rz_config_set_i (newcfg, "scr.color", rz_config_get_i (newcfg, "scr.color")); + rz_config_set (newcfg, "scr.interactive", rz_config_get (newcfg, "scr.interactive")); if (!rs) { - bed = r_cons_sleep_begin (); - r_sys_usleep (100); - r_cons_sleep_end (bed); + bed = rz_cons_sleep_begin (); + rz_sys_usleep (100); + rz_cons_sleep_end (bed); continue; } if (allow && *allow) { bool accepted = false; const char *allows_host; - char *p, *peer = r_socket_to_string (rs->s); + char *p, *peer = rz_socket_to_string (rs->s); char *allows = strdup (allow); //eprintf ("Firewall (%s)\n", allows); - int i, count = r_str_split (allows, ','); + int i, count = rz_str_split (allows, ','); p = strchr (peer, ':'); if (p) { *p = 0; } for (i = 0; i < count; i++) { - allows_host = r_str_word_get0 (allows, i); + allows_host = rz_str_word_get0 (allows, i); //eprintf ("--- (%s) (%s)\n", host, peer); if (!strcmp (allows_host, peer)) { accepted = true; @@ -220,88 +220,88 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * free (peer); free (allows); if (!accepted) { - r_socket_http_close (rs); + rz_socket_http_close (rs); continue; } } if (!rs->method || !rs->path) { http_logf (core, "Invalid http headers received from client\n"); - r_socket_http_close (rs); + rz_socket_http_close (rs); continue; } dir = NULL; if (!rs->auth) { - r_socket_http_response (rs, 401, "", 0, NULL); + rz_socket_http_response (rs, 401, "", 0, NULL); } - if (r_config_get_i (core->config, "http.verbose")) { - char *peer = r_socket_to_string (rs->s); + if (rz_config_get_i (core->config, "http.verbose")) { + char *peer = rz_socket_to_string (rs->s); http_logf (core, "[HTTP] %s %s\n", peer, rs->path); free (peer); } - if (r_config_get_i (core->config, "http.dirlist")) { - if (r_file_is_directory (rs->path)) { + if (rz_config_get_i (core->config, "http.dirlist")) { + if (rz_file_is_directory (rs->path)) { dir = strdup (rs->path); } } - if (r_config_get_i (core->config, "http.cors")) { + if (rz_config_get_i (core->config, "http.cors")) { strcpy (headers, "Access-Control-Allow-Origin: *\n" "Access-Control-Allow-Headers: Origin, " "X-Requested-With, Content-Type, Accept\n"); } if (!strcmp (rs->method, "OPTIONS")) { - r_socket_http_response (rs, 200, "", 0, headers); + rz_socket_http_response (rs, 200, "", 0, headers); } else if (!strcmp (rs->method, "GET")) { if (!strncmp (rs->path, "/up/", 4)) { - if (r_config_get_i (core->config, "http.upget")) { - const char *uproot = r_config_get (core->config, "http.uproot"); + if (rz_config_get_i (core->config, "http.upget")) { + const char *uproot = rz_config_get (core->config, "http.uproot"); if (!rs->path[3] || (rs->path[3]=='/' && !rs->path[4])) { char *ptr = rtr_dir_files (uproot); - r_socket_http_response (rs, 200, ptr, 0, headers); + rz_socket_http_response (rs, 200, ptr, 0, headers); free (ptr); } else { - char *path = r_file_root (uproot, rs->path + 4); - if (r_file_exists (path)) { + char *path = rz_file_root (uproot, rs->path + 4); + if (rz_file_exists (path)) { size_t sz = 0; - char *f = r_file_slurp (path, &sz); + char *f = rz_file_slurp (path, &sz); if (f) { - r_socket_http_response (rs, 200, f, (int)sz, headers); + rz_socket_http_response (rs, 200, f, (int)sz, headers); free (f); } else { - r_socket_http_response (rs, 403, "Permission denied", 0, headers); + rz_socket_http_response (rs, 403, "Permission denied", 0, headers); http_logf (core, "http: Cannot open '%s'\n", path); } } else { if (dir) { char *resp = rtr_dir_files (dir); - r_socket_http_response (rs, 404, resp, 0, headers); + rz_socket_http_response (rs, 404, resp, 0, headers); free (resp); } else { http_logf (core, "File '%s' not found\n", path); - r_socket_http_response (rs, 404, "File not found\n", 0, headers); + rz_socket_http_response (rs, 404, "File not found\n", 0, headers); } } free (path); } } else { - r_socket_http_response (rs, 403, "", 0, NULL); + rz_socket_http_response (rs, 403, "", 0, NULL); } } else if (!strncmp (rs->path, "/cmd/", 5)) { - const bool colon = r_config_get_i (core->config, "http.colon"); + const bool colon = rz_config_get_i (core->config, "http.colon"); if (colon && rs->path[5] != ':') { - r_socket_http_response (rs, 403, "Permission denied", 0, headers); + rz_socket_http_response (rs, 403, "Permission denied", 0, headers); } else { char *cmd = rs->path + 5; - const char *httpcmd = r_config_get (core->config, "http.uri"); - const char *httpref = r_config_get (core->config, "http.referer"); + const char *httpcmd = rz_config_get (core->config, "http.uri"); + const char *httpref = rz_config_get (core->config, "http.referer"); const bool httpref_enabled = (httpref && *httpref); char *refstr = NULL; if (httpref_enabled) { if (strstr (httpref, "http")) { refstr = strdup (httpref); } else { - refstr = r_str_newf ("http://localhost:%d/", atoi (port)); + refstr = rz_str_newf ("http://localhost:%d/", atoi (port)); } } @@ -309,58 +309,58 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * cmd++; } if (httpref_enabled && (!rs->referer || (refstr && !strstr (rs->referer, refstr)))) { - r_socket_http_response (rs, 503, "", 0, headers); + rz_socket_http_response (rs, 503, "", 0, headers); } else { if (httpcmd && *httpcmd) { int len; // do remote http query and proxy response - char *res, *bar = r_str_newf ("%s/%s", httpcmd, cmd); - bed = r_cons_sleep_begin (); - res = r_socket_http_get (bar, NULL, &len); - r_cons_sleep_end (bed); + char *res, *bar = rz_str_newf ("%s/%s", httpcmd, cmd); + bed = rz_cons_sleep_begin (); + res = rz_socket_http_get (bar, NULL, &len); + rz_cons_sleep_end (bed); if (res) { res[len] = 0; - r_cons_println (res); + rz_cons_println (res); } free (bar); } else { char *out, *cmd = rs->path + 5; - r_str_uri_decode (cmd); - r_config_set (core->config, "scr.interactive", "false"); + rz_str_uri_decode (cmd); + rz_config_set (core->config, "scr.interactive", "false"); - if (!r_sandbox_enable (0) && + if (!rz_sandbox_enable (0) && (!strcmp (cmd, "=h*") || !strcmp (cmd, "=h--"))) { out = NULL; } else if (*cmd == ':') { /* commands in /cmd/: starting with : do not show any output */ - r_core_cmd0 (core, cmd + 1); + rz_core_cmd0 (core, cmd + 1); out = NULL; } else { - out = r_core_cmd_str_pipe (core, cmd); + out = rz_core_cmd_str_pipe (core, cmd); } if (out) { - char *res = r_str_uri_encode (out); - char *newheaders = r_str_newf ( + char *res = rz_str_uri_encode (out); + char *newheaders = rz_str_newf ( "Content-Type: text/plain\n%s", headers); - r_socket_http_response (rs, 200, out, 0, newheaders); + rz_socket_http_response (rs, 200, out, 0, newheaders); free (out); free (newheaders); free (res); } else { - r_socket_http_response (rs, 200, "", 0, headers); + rz_socket_http_response (rs, 200, "", 0, headers); } - if (!r_sandbox_enable (0)) { + if (!rz_sandbox_enable (0)) { if (!strcmp (cmd, "=h*")) { /* do stuff */ - r_socket_http_close (rs); + rz_socket_http_close (rs); free (dir); free (refstr); ret = -2; goto the_end; } else if (!strcmp (cmd, "=h--")) { - r_socket_http_close (rs); + rz_socket_http_close (rs); free (dir); free (refstr); ret = 0; @@ -372,8 +372,8 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * free (refstr); } } else { - const char *root = r_config_get (core->config, "http.root"); - const char *homeroot = r_config_get (core->config, "http.homeroot"); + const char *root = rz_config_get (core->config, "http.root"); + const char *homeroot = rz_config_get (core->config, "http.homeroot"); char *path; if (!strcmp (rs->path, "/")) { free (rs->path); @@ -381,16 +381,16 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * rs->path = strdup (index); path = strdup (index); } else { - rs->path = r_str_newf ("/%s", index); - path = r_file_root (root, rs->path); + rs->path = rz_str_newf ("/%s", index); + path = rz_file_root (root, rs->path); } } else if (homeroot && *homeroot) { - char *homepath = r_file_abspath (homeroot); - path = r_file_root (homepath, rs->path); + char *homepath = rz_file_abspath (homeroot); + path = rz_file_root (homepath, rs->path); free (homepath); - if (!r_file_exists (path) && !r_file_is_directory (path)) { + if (!rz_file_exists (path) && !rz_file_is_directory (path)) { free (path); - path = r_file_root (root, rs->path); + path = rz_file_root (root, rs->path); } } else { if (*index == '/') { @@ -400,22 +400,22 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * } // FD IS OK HERE if (rs->path [strlen (rs->path) - 1] == '/') { - path = (*index == '/')? strdup (index): r_str_append (path, index); + path = (*index == '/')? strdup (index): rz_str_append (path, index); } else { //snprintf (path, sizeof (path), "%s/%s", root, rs->path); - if (r_file_is_directory (path)) { - char *res = r_str_newf ("Location: %s/\n%s", rs->path, headers); - r_socket_http_response (rs, 302, NULL, 0, res); - r_socket_http_close (rs); + if (rz_file_is_directory (path)) { + char *res = rz_str_newf ("Location: %s/\n%s", rs->path, headers); + rz_socket_http_response (rs, 302, NULL, 0, res); + rz_socket_http_close (rs); free (path); free (res); R_FREE (dir); continue; } } - if (r_file_exists (path)) { + if (rz_file_exists (path)) { size_t sz = 0; - char *f = r_file_slurp (path, &sz); + char *f = rz_file_slurp (path, &sz); if (f) { const char *ct = NULL; if (strstr (path, ".js")) { @@ -427,23 +427,23 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * if (strstr (path, ".html")) { ct = "Content-Type: text/html\n"; } - char *hdr = r_str_newf ("%s%s", ct, headers); - r_socket_http_response (rs, 200, f, (int)sz, hdr); + char *hdr = rz_str_newf ("%s%s", ct, headers); + rz_socket_http_response (rs, 200, f, (int)sz, hdr); free (hdr); free (f); } else { - r_socket_http_response (rs, 403, "Permission denied", 0, headers); + rz_socket_http_response (rs, 403, "Permission denied", 0, headers); http_logf (core, "http: Cannot open '%s'\n", path); } } else { if (dir) { char *resp = rtr_dir_files (dir); http_logf (core, "Dirlisting %s\n", dir); - r_socket_http_response (rs, 404, resp, 0, headers); + rz_socket_http_response (rs, 404, resp, 0, headers); free (resp); } else { http_logf (core, "File '%s' not found\n", path); - r_socket_http_response (rs, 404, "File not found\n", 0, headers); + rz_socket_http_response (rs, 404, "File not found\n", 0, headers); } } free (path); @@ -452,67 +452,67 @@ static int r_core_rtr_http_run(RCore *core, int launch, int browse, const char * ut8 *ret; int retlen; char buf[128]; - if (r_config_get_i (core->config, "http.upload")) { - ret = r_socket_http_handle_upload (rs->data, rs->data_length, &retlen); + if (rz_config_get_i (core->config, "http.upload")) { + ret = rz_socket_http_handle_upload (rs->data, rs->data_length, &retlen); if (ret) { - ut64 size = r_config_get_i (core->config, "http.maxsize"); + ut64 size = rz_config_get_i (core->config, "http.maxsize"); if (size && retlen > size) { - r_socket_http_response (rs, 403, "403 File too big\n", 0, headers); + rz_socket_http_response (rs, 403, "403 File too big\n", 0, headers); } else { - char *filename = r_file_root ( - r_config_get (core->config, "http.uproot"), + char *filename = rz_file_root ( + rz_config_get (core->config, "http.uproot"), rs->path + 4); http_logf (core, "UPLOADED '%s'\n", filename); - r_file_dump (filename, ret, retlen, 0); + rz_file_dump (filename, ret, retlen, 0); free (filename); snprintf (buf, sizeof (buf), "

uploaded %d byte(s). Thanks

\n", retlen); - r_socket_http_response (rs, 200, buf, 0, headers); + rz_socket_http_response (rs, 200, buf, 0, headers); } free (ret); } } else { - r_socket_http_response (rs, 403, "403 Forbidden\n", 0, headers); + rz_socket_http_response (rs, 403, "403 Forbidden\n", 0, headers); } } else { - r_socket_http_response (rs, 404, "Invalid protocol", 0, headers); + rz_socket_http_response (rs, 404, "Invalid protocol", 0, headers); } - r_socket_http_close (rs); + rz_socket_http_close (rs); free (dir); } the_end: { - int timeout = r_config_get_i (core->config, "http.timeout"); - const char *host = r_config_get (core->config, "http.bind"); - const char *port = r_config_get (core->config, "http.port"); - const char *cors = r_config_get (core->config, "http.cors"); - const char *allow = r_config_get (core->config, "http.allow"); - const char *httpui = r_config_get (core->config, "http.ui"); + int timeout = rz_config_get_i (core->config, "http.timeout"); + const char *host = rz_config_get (core->config, "http.bind"); + const char *port = rz_config_get (core->config, "http.port"); + const char *cors = rz_config_get (core->config, "http.cors"); + const char *allow = rz_config_get (core->config, "http.allow"); + const char *httpui = rz_config_get (core->config, "http.ui"); core->config = origcfg; - r_config_set_i (core->config, "http.timeout", timeout); - r_config_set (core->config, "http.bind", host); - r_config_set (core->config, "http.port", port); - r_config_set (core->config, "http.cors", cors); - r_config_set (core->config, "http.allow", allow); - r_config_set (core->config, "http.ui", httpui); + rz_config_set_i (core->config, "http.timeout", timeout); + rz_config_set (core->config, "http.bind", host); + rz_config_set (core->config, "http.port", port); + rz_config_set (core->config, "http.cors", cors); + rz_config_set (core->config, "http.allow", allow); + rz_config_set (core->config, "http.ui", httpui); } - r_cons_break_pop (); + rz_cons_break_pop (); core->http_up = false; free (pfile); - r_socket_free (s); - r_config_free (newcfg); + rz_socket_free (s); + rz_config_free (newcfg); if (restoreSandbox) { - r_sandbox_disable (true); + rz_sandbox_disable (true); } /* refresh settings - run callbacks */ - r_config_set (origcfg, "scr.html", r_config_get (origcfg, "scr.html")); - r_config_set_i (origcfg, "scr.color", r_config_get_i (origcfg, "scr.color")); - r_config_set (origcfg, "scr.interactive", r_config_get (origcfg, "scr.interactive")); + rz_config_set (origcfg, "scr.html", rz_config_get (origcfg, "scr.html")); + rz_config_set_i (origcfg, "scr.color", rz_config_get_i (origcfg, "scr.color")); + rz_config_set (origcfg, "scr.interactive", rz_config_get (origcfg, "scr.interactive")); return ret; } #if 0 -static RThreadFunctionRet r_core_rtr_http_thread (RThread *th) { +static RzThreadFunctionRet rz_core_rtr_http_thread (RzThread *th) { if (!th) { return false; } @@ -521,12 +521,12 @@ static RThreadFunctionRet r_core_rtr_http_thread (RThread *th) { return false; } eprintf ("WARNING: Background webserver requires http.sandbox=false to run properly\n"); - int ret = r_core_rtr_http_run (ht->core, ht->launch, ht->browse, ht->path); + int ret = rz_core_rtr_http_run (ht->core, ht->launch, ht->browse, ht->path); R_FREE (ht->path); if (ret) { - int p = r_config_get_i (ht->core->config, "http.port"); - r_config_set_i (ht->core->config, "http.port", p + 1); - if (p >= r_config_get_i (ht->core->config, "http.maxport")) { + int p = rz_config_get_i (ht->core->config, "http.port"); + rz_config_set_i (ht->core->config, "http.port", p + 1); + if (p >= rz_config_get_i (ht->core->config, "http.maxport")) { return R_TH_STOP; } } @@ -534,16 +534,16 @@ static RThreadFunctionRet r_core_rtr_http_thread (RThread *th) { } #endif -R_API int r_core_rtr_http(RCore *core, int launch, int browse, const char *path) { +RZ_API int rz_core_rtr_http(RzCore *core, int launch, int browse, const char *path) { int ret; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: connect disabled\n"); return 1; } if (launch == '-') { if (httpthread) { eprintf ("Press ^C to stop the webserver\n"); - r_th_kill_free (httpthread); + rz_th_kill_free (httpthread); httpthread = NULL; } else { eprintf ("No webserver running\n"); @@ -558,7 +558,7 @@ R_API int r_core_rtr_http(RCore *core, int launch, int browse, const char *path) while (*path == '&') { path++; } - return r_core_cmdf (core, "& =h%s", path); + return rz_core_cmdf (core, "& =h%s", path); } #if 0 if (httpthread) { @@ -567,25 +567,25 @@ R_API int r_core_rtr_http(RCore *core, int launch, int browse, const char *path) eprintf ("TODO: Use different eval environ for scr. for the web\n"); eprintf ("TODO: Visual mode should be enabled on local\n"); } else { - const char *tpath = r_str_trim_head_ro (path + 1); + const char *tpath = rz_str_trim_head_ro (path + 1); //HttpThread ht = { core, launch, strdup (tpath) }; HttpThread *ht = calloc (sizeof (HttpThread), 1); ht->core = core; ht->launch = launch; ht->browse = browse; ht->path = strdup (tpath); - httpthread = r_th_new (r_core_rtr_http_thread, ht, false); + httpthread = rz_th_new (rz_core_rtr_http_thread, ht, false); if (httpthread) { - r_th_setname (httpthread, "httpthread"); + rz_th_setname (httpthread, "httpthread"); } - r_th_start (httpthread, true); + rz_th_start (httpthread, true); eprintf ("Background http server started.\n"); } return 0; } #endif do { - ret = r_core_rtr_http_run (core, launch, browse, path); + ret = rz_core_rtr_http_run (core, launch, browse, path); } while (ret == -2); return ret; } diff --git a/libr/core/rtr_shell.c b/librz/core/rtr_shell.c similarity index 70% rename from libr/core/rtr_shell.c rename to librz/core/rtr_shell.c index 761efe2bc9..0e6dfe2c82 100644 --- a/libr/core/rtr_shell.c +++ b/librz/core/rtr_shell.c @@ -1,20 +1,20 @@ -static bool rtr_visual(RCore *core, TextLog T, const char *cmd) { +static bool rtr_visual(RzCore *core, TextLog T, const char *cmd) { bool autorefresh = false; if (cmd) { - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { char *ret; - r_cons_clear00 (); + rz_cons_clear00 (); ret = rtrcmd (T, cmd); - r_cons_println (ret); + rz_cons_println (ret); free (ret); - r_cons_flush (); - if (r_cons_is_breaked ()) { + rz_cons_flush (); + if (rz_cons_is_breaked ()) { break; } - r_sys_sleep (1); + rz_sys_sleep (1); } - r_cons_break_pop (); + rz_cons_break_pop (); } else { const char *cmds[] = { "px", "pd", "pxa", "dr", "sr SP;pxa", NULL }; int cmdidx = 0; @@ -22,28 +22,28 @@ static bool rtr_visual(RCore *core, TextLog T, const char *cmd) { free (rtrcmd (T, "e scr.color=true")); free (rtrcmd (T, "e scr.html=false")); for (;;) { - r_cons_clear00 (); + rz_cons_clear00 (); ret = rtrcmd (T, cmds[cmdidx]); if (ret) { - r_cons_println (ret); + rz_cons_println (ret); free (ret); } - r_cons_flush (); + rz_cons_flush (); if (autorefresh) { - r_cons_printf ("(auto-refresh)\n"); - r_cons_flush (); - r_cons_break_push (NULL, NULL); - r_sys_sleep (1); - if (r_cons_is_breaked ()) { + rz_cons_printf ("(auto-refresh)\n"); + rz_cons_flush (); + rz_cons_break_push (NULL, NULL); + rz_sys_sleep (1); + if (rz_cons_is_breaked ()) { autorefresh = false; - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } else { - r_cons_break_pop (); + rz_cons_break_pop (); continue; } - r_cons_break_pop (); + rz_cons_break_pop (); } else { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } #if 0 TODO: @@ -52,8 +52,8 @@ TODO: #endif switch (ch) { case '?': - r_cons_clear00 (); - r_cons_printf ("Remote Visual keys:\n" + rz_cons_clear00 (); + rz_cons_printf ("Remote Visual keys:\n" " hjkl : move\n" " HJKL : move faster\n" " +-*/ : change block size\n" @@ -64,8 +64,8 @@ TODO: " q : quit this mode and go back to the shell\n" " sS : step / step over\n" " . : seek entry or pc\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case 'i': { @@ -76,20 +76,20 @@ TODO: #endif char buf[1024]; if (COLORFLAGS) { - r_line_set_prompt (Color_RESET":> "); + rz_line_set_prompt (Color_RESET":> "); } else { - r_line_set_prompt (":> "); + rz_line_set_prompt (":> "); } showcursor (core, true); - r_cons_fgets (buf + 3, sizeof (buf) - 3, 0, NULL); + rz_cons_fgets (buf + 3, sizeof (buf) - 3, 0, NULL); memcpy (buf, "wx ", 3); if (buf[3]) { char *res = rtrcmd (T, buf); if (res) { - r_cons_println (res); + rz_cons_println (res); free (res); } - r_cons_flush (); + rz_cons_flush (); } } break; @@ -109,25 +109,25 @@ TODO: do { char buf[1024]; #if __UNIX__ - r_line_set_prompt (Color_RESET":> "); + rz_line_set_prompt (Color_RESET":> "); #else - r_line_set_prompt (":> "); + rz_line_set_prompt (":> "); #endif showcursor (core, true); - r_cons_fgets (buf, sizeof (buf), 0, NULL); + rz_cons_fgets (buf, sizeof (buf), 0, NULL); if (*buf) { - r_line_hist_add (buf); + rz_line_hist_add (buf); char *res = rtrcmd (T, buf); if (res) { - r_cons_println (res); + rz_cons_println (res); free (res); } - r_cons_flush (); + rz_cons_flush (); ret = true; } else { ret = false; - //r_cons_any_key (); - r_cons_clear00 (); + //rz_cons_any_key (); + rz_cons_clear00 (); showcursor (core, false); } } while (ret); @@ -177,7 +177,7 @@ TODO: } // XXX: this needs to be moved to use the standard shell like in !=! and support visual+panels -static void __rtr_shell(RCore *core, int nth) { +static void __rtr_shell(RzCore *core, int nth) { char *proto = "http"; char *host = ""; char *port= ""; @@ -185,15 +185,15 @@ static void __rtr_shell(RCore *core, int nth) { char prompt[64], prompt2[64], *str, *ptr; int len; const char* res; - RSocket *s = NULL; + RzSocket *s = NULL; TextLog T = { host, port, file }; snprintf (prompt, sizeof (prompt), "[%s://%s:%s/%s]> ", proto, host, port, file); snprintf (prompt2, sizeof (prompt2), "[%s:%s]$ ", host, port); for (;;) { - r_line_set_prompt (prompt); - res = r_line_readline (); + rz_line_set_prompt (prompt); + res = rz_line_readline (); if (!res || !*res) { break; } @@ -202,14 +202,14 @@ static void __rtr_shell(RCore *core, int nth) { } if (!strcmp (res, "!sh")) { for (;;) { - r_line_set_prompt (prompt2); - res = r_line_readline (); + rz_line_set_prompt (prompt2); + res = rz_line_readline (); if (!res || !*res || !strcmp (res, "exit")) { break; } - ptr = r_str_uri_encode (res); - char *uri = r_str_newf ("http://%s:%s/%s!%s", host, port, file, res); - str = r_socket_http_get (uri, NULL, &len); + ptr = rz_str_uri_encode (res); + char *uri = rz_str_newf ("http://%s:%s/%s!%s", host, port, file, res); + str = rz_socket_http_get (uri, NULL, &len); if (str) { str[len] = 0; res = strstr (str, "\n\n"); @@ -219,7 +219,7 @@ static void __rtr_shell(RCore *core, int nth) { res = res? res + 2: str; const char *tail = (res[strlen (res) - 1] == '\n')? "": "\n"; printf ("%s%s", res, tail); - r_line_hist_add (str); + rz_line_hist_add (str); free (str); } free (ptr); @@ -234,12 +234,12 @@ static void __rtr_shell(RCore *core, int nth) { } else if (!strcmp (res, "TT")) { rtr_textlog_chat (core, T); } else { - char *cmdline = r_str_newf ("%d %s", nth, res); - r_core_rtr_cmd (core, cmdline); - r_cons_flush (); - r_line_hist_add (res); + char *cmdline = rz_str_newf ("%d %s", nth, res); + rz_core_rtr_cmd (core, cmdline); + rz_cons_flush (); + rz_line_hist_add (res); } } - r_socket_free (s); + rz_socket_free (s); } diff --git a/libr/core/r2-shell-parser-cmds.inc b/librz/core/rz-shell-parser-cmds.inc similarity index 100% rename from libr/core/r2-shell-parser-cmds.inc rename to librz/core/rz-shell-parser-cmds.inc diff --git a/libr/core/task.c b/librz/core/task.c similarity index 52% rename from libr/core/task.c rename to librz/core/task.c index 9853c1bcb6..ff73facd37 100644 --- a/libr/core/task.c +++ b/librz/core/task.c @@ -1,26 +1,26 @@ /* radare - LGPL - Copyright 2014-2019 - pancake, thestr4ng3r */ -#include +#include -R_API void r_core_task_scheduler_init (RCoreTaskScheduler *tasks, RCore *core) { +RZ_API void rz_core_task_scheduler_init (RzCoreTaskScheduler *tasks, RzCore *core) { tasks->task_id_next = 0; - tasks->tasks = r_list_newf ((RListFree)r_core_task_decref); - tasks->tasks_queue = r_list_new (); - tasks->oneshot_queue = r_list_newf (free); + tasks->tasks = rz_list_newf ((RzListFree)rz_core_task_decref); + tasks->tasks_queue = rz_list_new (); + tasks->oneshot_queue = rz_list_newf (free); tasks->oneshots_enqueued = 0; - tasks->lock = r_th_lock_new (true); + tasks->lock = rz_th_lock_new (true); tasks->tasks_running = 0; tasks->oneshot_running = false; - tasks->main_task = r_core_task_new (core, false, NULL, NULL, NULL); - r_list_append (tasks->tasks, tasks->main_task); + tasks->main_task = rz_core_task_new (core, false, NULL, NULL, NULL); + rz_list_append (tasks->tasks, tasks->main_task); tasks->current_task = NULL; } -R_API void r_core_task_scheduler_fini (RCoreTaskScheduler *tasks) { - r_list_free (tasks->tasks); - r_list_free (tasks->tasks_queue); - r_list_free (tasks->oneshot_queue); - r_th_lock_free (tasks->lock); +RZ_API void rz_core_task_scheduler_fini (RzCoreTaskScheduler *tasks) { + rz_list_free (tasks->tasks); + rz_list_free (tasks->tasks_queue); + rz_list_free (tasks->oneshot_queue); + rz_th_lock_free (tasks->lock); } #if HAVE_PTHREAD @@ -29,11 +29,11 @@ static void tasks_lock_block_signals(sigset_t *old_sigset) { sigset_t block_sigset; sigemptyset (&block_sigset); sigaddset (&block_sigset, SIGWINCH); - r_signal_sigmask (SIG_BLOCK, &block_sigset, old_sigset); + rz_signal_sigmask (SIG_BLOCK, &block_sigset, old_sigset); } static void tasks_lock_block_signals_reset(sigset_t *old_sigset) { - r_signal_sigmask (SIG_SETMASK, old_sigset, NULL); + rz_signal_sigmask (SIG_SETMASK, old_sigset, NULL); } #else #define TASK_SIGSET_T void * @@ -41,45 +41,45 @@ static void tasks_lock_block_signals(TASK_SIGSET_T *old_sigset) { (void)old_sigs static void tasks_lock_block_signals_reset(TASK_SIGSET_T *old_sigset) { (void)old_sigset; } #endif -static void tasks_lock_enter(RCoreTaskScheduler *scheduler, TASK_SIGSET_T *old_sigset) { +static void tasks_lock_enter(RzCoreTaskScheduler *scheduler, TASK_SIGSET_T *old_sigset) { tasks_lock_block_signals (old_sigset); - r_th_lock_enter (scheduler->lock); + rz_th_lock_enter (scheduler->lock); } -static void tasks_lock_leave(RCoreTaskScheduler *scheduler, TASK_SIGSET_T *old_sigset) { - r_th_lock_leave (scheduler->lock); +static void tasks_lock_leave(RzCoreTaskScheduler *scheduler, TASK_SIGSET_T *old_sigset) { + rz_th_lock_leave (scheduler->lock); tasks_lock_block_signals_reset (old_sigset); } typedef struct oneshot_t { - RCoreTaskOneShot func; + RzCoreTaskOneShot func; void *user; } OneShot; -R_API void r_core_task_print (RCore *core, RCoreTask *task, int mode) { +RZ_API void rz_core_task_print (RzCore *core, RzCoreTask *task, int mode) { switch (mode) { case 'j': { - r_cons_printf ("{\"id\":%d,\"state\":\"", task->id); + rz_cons_printf ("{\"id\":%d,\"state\":\"", task->id); switch (task->state) { case R_CORE_TASK_STATE_BEFORE_START: - r_cons_print ("before_start"); + rz_cons_print ("before_start"); break; case R_CORE_TASK_STATE_RUNNING: - r_cons_print ("running"); + rz_cons_print ("running"); break; case R_CORE_TASK_STATE_SLEEPING: - r_cons_print ("sleeping"); + rz_cons_print ("sleeping"); break; case R_CORE_TASK_STATE_DONE: - r_cons_print ("done"); + rz_cons_print ("done"); break; } - r_cons_printf ("\",\"transient\":%s,\"cmd\":", task->transient ? "true" : "false"); + rz_cons_printf ("\",\"transient\":%s,\"cmd\":", task->transient ? "true" : "false"); if (task->cmd) { - r_cons_printf ("\"%s\"}", task->cmd); + rz_cons_printf ("\"%s\"}", task->cmd); } else { - r_cons_printf ("null}"); + rz_cons_printf ("null}"); } } break; @@ -88,45 +88,45 @@ R_API void r_core_task_print (RCore *core, RCoreTask *task, int mode) { if (task == core->tasks.main_task) { info = "-- MAIN TASK --"; } - r_cons_printf ("%3d %3s %12s %s\n", + rz_cons_printf ("%3d %3s %12s %s\n", task->id, task->transient ? "(t)" : "", - r_core_task_status (task), + rz_core_task_status (task), info ? info : ""); } break; } } -R_API void r_core_task_list(RCore *core, int mode) { - RListIter *iter; - RCoreTask *task; +RZ_API void rz_core_task_list(RzCore *core, int mode) { + RzListIter *iter; + RzCoreTask *task; if (mode == 'j') { - r_cons_printf ("["); + rz_cons_printf ("["); } TASK_SIGSET_T old_sigset; tasks_lock_enter (&core->tasks, &old_sigset); - r_list_foreach (core->tasks.tasks, iter, task) { - r_core_task_print (core, task, mode); + rz_list_foreach (core->tasks.tasks, iter, task) { + rz_core_task_print (core, task, mode); if (mode == 'j' && iter->n) { - r_cons_printf (","); + rz_cons_printf (","); } } if (mode == 'j') { - r_cons_printf ("]\n"); + rz_cons_printf ("]\n"); } else { - r_cons_printf ("--\ntotal running: %d\n", core->tasks.tasks_running); + rz_cons_printf ("--\ntotal running: %d\n", core->tasks.tasks_running); } tasks_lock_leave (&core->tasks, &old_sigset); } -R_API int r_core_task_running_tasks_count(RCoreTaskScheduler *scheduler) { - RListIter *iter; - RCoreTask *task; +RZ_API int rz_core_task_running_tasks_count(RzCoreTaskScheduler *scheduler) { + RzListIter *iter; + RzCoreTask *task; int count = 0; TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - r_list_foreach (scheduler->tasks, iter, task) { + rz_list_foreach (scheduler->tasks, iter, task) { if (task != scheduler->main_task && task->state != R_CORE_TASK_STATE_DONE) { count++; } @@ -135,80 +135,80 @@ R_API int r_core_task_running_tasks_count(RCoreTaskScheduler *scheduler) { return count; } -static void task_join(RCoreTask *task) { - RThreadSemaphore *sem = task->running_sem; +static void task_join(RzCoreTask *task) { + RzThreadSemaphore *sem = task->running_sem; if (!sem) { return; } - r_th_sem_wait (sem); - r_th_sem_post (sem); + rz_th_sem_wait (sem); + rz_th_sem_post (sem); } -R_API void r_core_task_join(RCoreTaskScheduler *scheduler, RCoreTask *current, int id) { +RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id) { if (current && id == current->id) { return; } if (id >= 0) { - RCoreTask *task = r_core_task_get_incref (scheduler, id); + RzCoreTask *task = rz_core_task_get_incref (scheduler, id); if (!task) { return; } if (current) { - r_core_task_sleep_begin (current); + rz_core_task_sleep_begin (current); } task_join (task); if (current) { - r_core_task_sleep_end (current); + rz_core_task_sleep_end (current); } - r_core_task_decref (task); + rz_core_task_decref (task); } else { TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - RList *tasks = r_list_clone (scheduler->tasks); - RListIter *iter; - RCoreTask *task; - r_list_foreach (tasks, iter, task) { + RzList *tasks = rz_list_clone (scheduler->tasks); + RzListIter *iter; + RzCoreTask *task; + rz_list_foreach (tasks, iter, task) { if (current == task) { continue; } - r_core_task_incref (task); + rz_core_task_incref (task); } tasks_lock_leave (scheduler, &old_sigset); - r_list_foreach (tasks, iter, task) { + rz_list_foreach (tasks, iter, task) { if (current == task) { continue; } if (current) { - r_core_task_sleep_begin (current); + rz_core_task_sleep_begin (current); } task_join (task); if (current) { - r_core_task_sleep_end (current); + rz_core_task_sleep_end (current); } - r_core_task_decref (task); + rz_core_task_decref (task); } - r_list_free (tasks); + rz_list_free (tasks); } } -static void task_free (RCoreTask *task) { +static void task_free (RzCoreTask *task) { if (!task) { return; } free (task->cmd); free (task->res); - r_th_free (task->thread); - r_th_sem_free (task->running_sem); - r_th_cond_free (task->dispatch_cond); - r_th_lock_free (task->dispatch_lock); - r_cons_context_free (task->cons_context); + rz_th_free (task->thread); + rz_th_sem_free (task->running_sem); + rz_th_cond_free (task->dispatch_cond); + rz_th_lock_free (task->dispatch_lock); + rz_cons_context_free (task->cons_context); free (task); } -R_API RCoreTask *r_core_task_new(RCore *core, bool create_cons, const char *cmd, RCoreTaskCallback cb, void *user) { - RCoreTask *task = R_NEW0 (RCoreTask); +RZ_API RzCoreTask *rz_core_task_new(RzCore *core, bool create_cons, const char *cmd, RzCoreTaskCallback cb, void *user) { + RzCoreTask *task = R_NEW0 (RzCoreTask); if (!task) { goto hell; } @@ -219,14 +219,14 @@ R_API RCoreTask *r_core_task_new(RCore *core, bool create_cons, const char *cmd, task->res = NULL; task->running_sem = NULL; task->dispatched = false; - task->dispatch_cond = r_th_cond_new (); - task->dispatch_lock = r_th_lock_new (false); + task->dispatch_cond = rz_th_cond_new (); + task->dispatch_lock = rz_th_lock_new (false); if (!task->dispatch_cond || !task->dispatch_lock) { goto hell; } if (create_cons) { - task->cons_context = r_cons_context_new (r_cons_singleton ()->context); + task->cons_context = rz_cons_context_new (rz_cons_singleton ()->context); if (!task->cons_context) { goto hell; } @@ -248,7 +248,7 @@ hell: return NULL; } -R_API void r_core_task_incref (RCoreTask *task) { +RZ_API void rz_core_task_incref (RzCoreTask *task) { if (!task) { return; } @@ -258,12 +258,12 @@ R_API void r_core_task_incref (RCoreTask *task) { tasks_lock_leave (&task->core->tasks, &old_sigset); } -R_API void r_core_task_decref (RCoreTask *task) { +RZ_API void rz_core_task_decref (RzCoreTask *task) { if (!task) { return; } TASK_SIGSET_T old_sigset; - RCoreTaskScheduler *scheduler = &task->core->tasks; + RzCoreTaskScheduler *scheduler = &task->core->tasks; tasks_lock_enter (scheduler, &old_sigset); task->refcount--; if (task->refcount <= 0) { @@ -272,9 +272,9 @@ R_API void r_core_task_decref (RCoreTask *task) { tasks_lock_leave (scheduler, &old_sigset); } -R_API void r_core_task_schedule(RCoreTask *current, RTaskState next_state) { - RCore *core = current->core; - RCoreTaskScheduler *scheduler = &core->tasks; +RZ_API void rz_core_task_schedule(RzCoreTask *current, RTaskState next_state) { + RzCore *core = current->core; + RzCoreTaskScheduler *scheduler = &core->tasks; bool stop = next_state != R_CORE_TASK_STATE_RUNNING; if (scheduler->oneshot_running || (!stop && scheduler->tasks_running == 1 && scheduler->oneshots_enqueued == 0)) { @@ -295,7 +295,7 @@ R_API void r_core_task_schedule(RCoreTask *current, RTaskState next_state) { // oneshots always have priority. // if there are any queued, run them immediately. OneShot *oneshot; - while ((oneshot = r_list_pop_head (scheduler->oneshot_queue))) { + while ((oneshot = rz_list_pop_head (scheduler->oneshot_queue))) { scheduler->oneshots_enqueued--; scheduler->oneshot_running = true; oneshot->func (oneshot->user); @@ -303,43 +303,43 @@ R_API void r_core_task_schedule(RCoreTask *current, RTaskState next_state) { free (oneshot); } - RCoreTask *next = r_list_pop_head (scheduler->tasks_queue); + RzCoreTask *next = rz_list_pop_head (scheduler->tasks_queue); if (next && !stop) { - r_list_append (scheduler->tasks_queue, current); - r_th_lock_enter (current->dispatch_lock); + rz_list_append (scheduler->tasks_queue, current); + rz_th_lock_enter (current->dispatch_lock); } tasks_lock_leave (scheduler, &old_sigset); if (next) { - r_cons_context_reset (); - r_th_lock_enter (next->dispatch_lock); + rz_cons_context_reset (); + rz_th_lock_enter (next->dispatch_lock); next->dispatched = true; - r_th_lock_leave (next->dispatch_lock); - r_th_cond_signal (next->dispatch_cond); + rz_th_lock_leave (next->dispatch_lock); + rz_th_cond_signal (next->dispatch_cond); if (!stop) { while (!current->dispatched) { - r_th_cond_wait (current->dispatch_cond, current->dispatch_lock); + rz_th_cond_wait (current->dispatch_cond, current->dispatch_lock); } current->dispatched = false; - r_th_lock_leave (current->dispatch_lock); + rz_th_lock_leave (current->dispatch_lock); } } if (!stop) { scheduler->current_task = current; if (current->cons_context) { - r_cons_context_load (current->cons_context); + rz_cons_context_load (current->cons_context); } else { - r_cons_context_reset (); + rz_cons_context_reset (); } } } -static void task_wakeup(RCoreTask *current) { - RCore *core = current->core; - RCoreTaskScheduler *scheduler = &core->tasks; +static void task_wakeup(RzCoreTask *current) { + RzCore *core = current->core; + RzCoreTaskScheduler *scheduler = &core->tasks; TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); @@ -350,49 +350,49 @@ static void task_wakeup(RCoreTask *current) { // check if there are other tasks running bool single = scheduler->tasks_running == 1 || scheduler->tasks_running == 0; - r_th_lock_enter (current->dispatch_lock); + rz_th_lock_enter (current->dispatch_lock); // if we are not the only task, we must wait until another task signals us. if (!single) { - r_list_append (scheduler->tasks_queue, current); + rz_list_append (scheduler->tasks_queue, current); } tasks_lock_leave (scheduler, &old_sigset); if (!single) { while (!current->dispatched) { - r_th_cond_wait (current->dispatch_cond, current->dispatch_lock); + rz_th_cond_wait (current->dispatch_cond, current->dispatch_lock); } current->dispatched = false; } - r_th_lock_leave (current->dispatch_lock); + rz_th_lock_leave (current->dispatch_lock); scheduler->current_task = current; if (current->cons_context) { - r_cons_context_load (current->cons_context); + rz_cons_context_load (current->cons_context); } else { - r_cons_context_reset (); + rz_cons_context_reset (); } } -R_API void r_core_task_yield(RCoreTaskScheduler *scheduler) { - RCoreTask *task = r_core_task_self (scheduler); +RZ_API void rz_core_task_yield(RzCoreTaskScheduler *scheduler) { + RzCoreTask *task = rz_core_task_self (scheduler); if (!task) { return; } - r_core_task_schedule (task, R_CORE_TASK_STATE_RUNNING); + rz_core_task_schedule (task, R_CORE_TASK_STATE_RUNNING); } -static void task_end(RCoreTask *t) { - r_core_task_schedule (t, R_CORE_TASK_STATE_DONE); +static void task_end(RzCoreTask *t) { + rz_core_task_schedule (t, R_CORE_TASK_STATE_DONE); } -static RThreadFunctionRet task_run(RCoreTask *task) { - RCore *core = task->core; - RCoreTaskScheduler *scheduler = &task->core->tasks; +static RzThreadFunctionRet task_run(RzCoreTask *task) { + RzCore *core = task->core; + RzCoreTaskScheduler *scheduler = &task->core->tasks; task_wakeup (task); @@ -403,16 +403,16 @@ static RThreadFunctionRet task_run(RCoreTask *task) { char *res_str; if (task == scheduler->main_task) { - r_core_cmd (core, task->cmd, task->cmd_log); + rz_core_cmd (core, task->cmd, task->cmd_log); res_str = NULL; } else { - res_str = r_core_cmd_str (core, task->cmd); + res_str = rz_core_cmd_str (core, task->cmd); } free (task->res); task->res = res_str; - if (task != scheduler->main_task && r_cons_default_context_is_interactive ()) { + if (task != scheduler->main_task && rz_cons_default_context_is_interactive ()) { eprintf ("\nTask %d finished\n", task->id); } @@ -427,20 +427,20 @@ stillbirth: } if (task->running_sem) { - r_th_sem_post (task->running_sem); + rz_th_sem_post (task->running_sem); } if (task->cons_context && task->cons_context->break_stack) { - r_cons_context_break_pop (task->cons_context, false); + rz_cons_context_break_pop (task->cons_context, false); } int ret = R_TH_STOP; if (task->transient) { - RCoreTask *ltask; - RListIter *iter; - r_list_foreach (scheduler->tasks, iter, ltask) { + RzCoreTask *ltask; + RzListIter *iter; + rz_list_foreach (scheduler->tasks, iter, ltask) { if (ltask == task) { - r_list_delete (scheduler->tasks, iter); + rz_list_delete (scheduler->tasks, iter); ret = R_TH_FREED; break; } @@ -451,32 +451,32 @@ stillbirth: return ret; } -static RThreadFunctionRet task_run_thread(RThread *th) { - RCoreTask *task = (RCoreTask *)th->user; +static RzThreadFunctionRet task_run_thread(RzThread *th) { + RzCoreTask *task = (RzCoreTask *)th->user; return task_run (task); } -R_API void r_core_task_enqueue(RCoreTaskScheduler *scheduler, RCoreTask *task) { +RZ_API void rz_core_task_enqueue(RzCoreTaskScheduler *scheduler, RzCoreTask *task) { if (!scheduler || !task) { return; } TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); if (!task->running_sem) { - task->running_sem = r_th_sem_new (1); + task->running_sem = rz_th_sem_new (1); } if (task->running_sem) { - r_th_sem_wait (task->running_sem); + rz_th_sem_wait (task->running_sem); } if (task->cons_context) { - r_cons_context_break_push (task->cons_context, NULL, NULL, false); + rz_cons_context_break_push (task->cons_context, NULL, NULL, false); } - r_list_append (scheduler->tasks, task); - task->thread = r_th_new (task_run_thread, task, 0); + rz_list_append (scheduler->tasks, task); + task->thread = rz_th_new (task_run_thread, task, 0); tasks_lock_leave (scheduler, &old_sigset); } -R_API void r_core_task_enqueue_oneshot(RCoreTaskScheduler *scheduler, RCoreTaskOneShot func, void *user) { +RZ_API void rz_core_task_enqueue_oneshot(RzCoreTaskScheduler *scheduler, RzCoreTaskOneShot func, void *user) { if (!scheduler || !func) { return; } @@ -493,21 +493,21 @@ R_API void r_core_task_enqueue_oneshot(RCoreTaskScheduler *scheduler, RCoreTaskO if (oneshot) { oneshot->func = func; oneshot->user = user; - r_list_append (scheduler->oneshot_queue, oneshot); + rz_list_append (scheduler->oneshot_queue, oneshot); scheduler->oneshots_enqueued++; } } tasks_lock_leave (scheduler, &old_sigset); } -R_API int r_core_task_run_sync(RCoreTaskScheduler *scheduler, RCoreTask *task) { +RZ_API int rz_core_task_run_sync(RzCoreTaskScheduler *scheduler, RzCoreTask *task) { task->thread = NULL; return task_run (task); } /* begin running stuff synchronously on the main task */ -R_API void r_core_task_sync_begin(RCoreTaskScheduler *scheduler) { - RCoreTask *task = scheduler->main_task; +RZ_API void rz_core_task_sync_begin(RzCoreTaskScheduler *scheduler) { + RzCoreTask *task = scheduler->main_task; TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); task->thread = NULL; @@ -518,22 +518,22 @@ R_API void r_core_task_sync_begin(RCoreTaskScheduler *scheduler) { task_wakeup (task); } -/* end running stuff synchronously, initially started with r_core_task_sync_begin() */ -R_API void r_core_task_sync_end(RCoreTaskScheduler *scheduler) { +/* end running stuff synchronously, initially started with rz_core_task_sync_begin() */ +RZ_API void rz_core_task_sync_end(RzCoreTaskScheduler *scheduler) { task_end (scheduler->main_task); } /* To be called from within a task. - * Begin sleeping and schedule other tasks until r_core_task_sleep_end() is called. */ -R_API void r_core_task_sleep_begin(RCoreTask *task) { - r_core_task_schedule (task, R_CORE_TASK_STATE_SLEEPING); + * Begin sleeping and schedule other tasks until rz_core_task_sleep_end() is called. */ +RZ_API void rz_core_task_sleep_begin(RzCoreTask *task) { + rz_core_task_schedule (task, R_CORE_TASK_STATE_SLEEPING); } -R_API void r_core_task_sleep_end(RCoreTask *task) { +RZ_API void rz_core_task_sleep_end(RzCoreTask *task) { task_wakeup (task); } -R_API const char *r_core_task_status (RCoreTask *task) { +RZ_API const char *rz_core_task_status (RzCoreTask *task) { switch (task->state) { case R_CORE_TASK_STATE_RUNNING: return "running"; @@ -548,14 +548,14 @@ R_API const char *r_core_task_status (RCoreTask *task) { } } -R_API RCoreTask *r_core_task_self (RCoreTaskScheduler *scheduler) { +RZ_API RzCoreTask *rz_core_task_self (RzCoreTaskScheduler *scheduler) { return scheduler->current_task ? scheduler->current_task : scheduler->main_task; } -static RCoreTask *task_get (RCoreTaskScheduler *scheduler, int id) { - RCoreTask *task; - RListIter *iter; - r_list_foreach (scheduler->tasks, iter, task) { +static RzCoreTask *task_get (RzCoreTaskScheduler *scheduler, int id) { + RzCoreTask *task; + RzListIter *iter; + rz_list_foreach (scheduler->tasks, iter, task) { if (task->id == id) { return task; } @@ -563,57 +563,57 @@ static RCoreTask *task_get (RCoreTaskScheduler *scheduler, int id) { return NULL; } -R_API RCoreTask *r_core_task_get_incref(RCoreTaskScheduler *scheduler, int id) { +RZ_API RzCoreTask *rz_core_task_get_incref(RzCoreTaskScheduler *scheduler, int id) { TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - RCoreTask *task = task_get (scheduler, id); + RzCoreTask *task = task_get (scheduler, id); if (task) { - r_core_task_incref (task); + rz_core_task_incref (task); } tasks_lock_leave (scheduler, &old_sigset); return task; } -R_API void r_core_task_break(RCoreTaskScheduler *scheduler, int id) { +RZ_API void rz_core_task_break(RzCoreTaskScheduler *scheduler, int id) { TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - RCoreTask *task = task_get (scheduler, id); + RzCoreTask *task = task_get (scheduler, id); if (!task || task->state == R_CORE_TASK_STATE_DONE) { tasks_lock_leave (scheduler, &old_sigset); return; } if (task->cons_context) { - r_cons_context_break (task->cons_context); + rz_cons_context_break (task->cons_context); } tasks_lock_leave (scheduler, &old_sigset); } -R_API void r_core_task_break_all(RCoreTaskScheduler *scheduler) { +RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler) { TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - RCoreTask *task; - RListIter *iter; - r_list_foreach (scheduler->tasks, iter, task) { + RzCoreTask *task; + RzListIter *iter; + rz_list_foreach (scheduler->tasks, iter, task) { if (task->state != R_CORE_TASK_STATE_DONE) { - r_cons_context_break (task->cons_context); + rz_cons_context_break (task->cons_context); } } tasks_lock_leave (scheduler, &old_sigset); } -R_API int r_core_task_del (RCoreTaskScheduler *scheduler, int id) { - RCoreTask *task; - RListIter *iter; +RZ_API int rz_core_task_del (RzCoreTaskScheduler *scheduler, int id) { + RzCoreTask *task; + RzListIter *iter; bool ret = false; TASK_SIGSET_T old_sigset; tasks_lock_enter (scheduler, &old_sigset); - r_list_foreach (scheduler->tasks, iter, task) { + rz_list_foreach (scheduler->tasks, iter, task) { if (task->id == id) { if (task == scheduler->main_task) { break; } if (task->state == R_CORE_TASK_STATE_DONE) { - r_list_delete (scheduler->tasks, iter); + rz_list_delete (scheduler->tasks, iter); } else { task->transient = true; } @@ -625,12 +625,12 @@ R_API int r_core_task_del (RCoreTaskScheduler *scheduler, int id) { return ret; } -R_API void r_core_task_del_all_done (RCoreTaskScheduler *scheduler) { - RCoreTask *task; - RListIter *iter, *iter2; - r_list_foreach_safe (scheduler->tasks, iter, iter2, task) { +RZ_API void rz_core_task_del_all_done (RzCoreTaskScheduler *scheduler) { + RzCoreTask *task; + RzListIter *iter, *iter2; + rz_list_foreach_safe (scheduler->tasks, iter, iter2, task) { if (task != scheduler->main_task && task->state == R_CORE_TASK_STATE_DONE) { - r_list_delete (scheduler->tasks, iter); + rz_list_delete (scheduler->tasks, iter); } } } diff --git a/librz/core/vasm.c b/librz/core/vasm.c new file mode 100644 index 0000000000..f883a1f03d --- /dev/null +++ b/librz/core/vasm.c @@ -0,0 +1,97 @@ +/* radare - LGPL - Copyright 2009-2018 - pancake */ + +#include + +#define R_VISUAL_ASM_BUFSIZE 1024 + +typedef struct { + RzCore *core; + char blockbuf[R_VISUAL_ASM_BUFSIZE]; + char codebuf[R_VISUAL_ASM_BUFSIZE]; + int oplen; + ut8 buf[128]; + RzAsmCode *acode; + int blocklen; + ut64 off; +} RzCoreVisualAsm; + +static int readline_callback(void *_a, const char *str) { + RzCoreVisualAsm *a = _a; + RzCore *core = a->core; + rz_cons_clear00 (); + rz_cons_printf ("Write some %s-%d assembly...\n\n", + rz_config_get (a->core->config, "asm.arch"), + rz_config_get_i (a->core->config, "asm.bits")); + if (*str == '?') { + rz_cons_printf ("0> ?\n\n" + "Visual assembler help:\n\n" + " assemble input while typing using asm.arch, asm.bits and cfg.bigendian\n" + " press enter to quit (prompt if there are bytes to be written)\n" + " this assembler supports various directives like .hex ...\n"); + } else { + rz_asm_code_free (a->acode); + rz_asm_set_pc (a->core->rasm, a->off); + a->acode = rz_asm_massemble (a->core->rasm, str); + if (a->acode) { + char* hex = rz_asm_code_get_hex (a->acode); + rz_cons_printf ("[VA:%d]> %s\n", a->acode? a->acode->len: 0, str); + if (a->acode && a->acode->len) { + rz_cons_printf ("* %s\n\n", hex); + } else { + rz_cons_print ("\n\n"); + } + int xlen = R_MIN (strlen (hex), R_VISUAL_ASM_BUFSIZE - 2); + strcpy (a->codebuf, a->blockbuf); + memcpy (a->codebuf, hex, xlen); + if (xlen >= strlen (a->blockbuf)) { + a->codebuf[xlen] = '\0'; + } + free (hex); + } else { + rz_cons_printf ("[VA:0]> %s\n* ?\n\n", str); + } + { + int rows = 0; + int cols = rz_cons_get_size (&rows); + core->print->cur_enabled = 1; + core->print->ocur = 0; + core->print->cur = (a->acode && a->acode->len) ? a->acode->len - 1: 0; + char *cmd = rz_str_newf ("pd %d @x:%s @0x%"PFMT64x, rows - 11, a->codebuf, a->off); + char *res = rz_core_cmd_str (a->core, cmd); + char *msg = rz_str_ansi_crop (res, 0,0, cols - 2, rows - 5); + rz_cons_printf ("%s\n", msg); + free (msg); + free (res); + free (cmd); + } + } + rz_cons_flush (); + return 1; +} + +RZ_API void rz_core_visual_asm(RzCore *core, ut64 off) { + RzCoreVisualAsm cva = { + .core = core, + .off = off + }; + rz_io_read_at (core->io, off, cva.buf, sizeof (cva.buf)); + cva.blocklen = rz_hex_bin2str (cva.buf, sizeof (cva.buf), cva.blockbuf); + + rz_line_readline_cb (readline_callback, &cva); + + if (cva.acode && cva.acode->len > 0) { + if (rz_cons_yesno ('y', "Save changes? (Y/n)")) { + if (!rz_io_write_at (core->io, off, cva.acode->bytes, cva.acode->len)) { + eprintf ("ERROR: Cannot write in here, check map permissions or reopen the file with oo+\n"); + rz_cons_any_key (NULL); + } + // rz_core_cmdf (core, "wx %s @ 0x%"PFMT64x, cva.acode->buf_hex, off); + } +#if 0 + } else if (!cva.acode || cva.acode->len == 0) { + eprintf ("ERROR: Cannot assemble those instructions\n"); +// rz_cons_any_key (NULL); +#endif + } + rz_asm_code_free (cva.acode); +} diff --git a/libr/core/visual.c b/librz/core/visual.c similarity index 57% rename from libr/core/visual.c rename to librz/core/visual.c index 6b4167ca47..8343269964 100644 --- a/libr/core/visual.c +++ b/librz/core/visual.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #define NPF 5 #define PIDX (R_ABS (core->printidx % NPF)) -static void visual_refresh(RCore *core); +static void visual_refresh(RzCore *core); static int obs = 0; static int blocksize = 0; @@ -15,7 +15,7 @@ static int disMode = 0; static int hexMode = 0; static int printMode = 0; static bool snowMode = false; -static RList *snows = NULL; +static RzList *snows = NULL; static int color = 1; static int debug = 1; static int zoom = 0; @@ -70,64 +70,64 @@ static const char *print5Formats[PRINT_5_FORMATS] = { "pca", "pcA", "p8", "pcc", "pss", "pcp", "pcd", "pcj" }; -R_API void r_core_visual_applyHexMode(RCore *core, int hexMode) { +RZ_API void rz_core_visual_applyHexMode(RzCore *core, int hexMode) { currentFormat = R_ABS(hexMode) % PRINT_HEX_FORMATS; switch (currentFormat) { case 0: /* px */ case 3: /* prx */ case 6: /* pxw */ case 9: /* pxr */ - r_config_set (core->config, "hex.compact", "false"); - r_config_set (core->config, "hex.comments", "true"); + rz_config_set (core->config, "hex.compact", "false"); + rz_config_set (core->config, "hex.comments", "true"); break; case 1: /* pxa */ case 4: /* pxb */ case 7: /* pxq */ - r_config_set (core->config, "hex.compact", "true"); - r_config_set (core->config, "hex.comments", "true"); + rz_config_set (core->config, "hex.compact", "true"); + rz_config_set (core->config, "hex.comments", "true"); break; case 2: /* pxr */ case 5: /* pxh */ case 8: /* pxd */ - r_config_set (core->config, "hex.compact", "false"); - r_config_set (core->config, "hex.comments", "false"); + rz_config_set (core->config, "hex.compact", "false"); + rz_config_set (core->config, "hex.comments", "false"); break; } } -R_API void r_core_visual_toggle_decompiler_disasm(RCore *core, bool for_graph, bool reset) { +RZ_API void rz_core_visual_toggle_decompiler_disasm(RzCore *core, bool for_graph, bool reset) { static RConfigHold *hold = NULL; // should be a tab-specific var if (hold) { - r_config_hold_restore (hold); - r_config_hold_free (hold); + rz_config_hold_restore (hold); + rz_config_hold_free (hold); hold = NULL; return; } if (reset) { return; } - hold = r_config_hold_new (core->config); - r_config_hold_s (hold, "asm.hint.pos", "asm.cmt.col", "asm.offset", "asm.lines", + hold = rz_config_hold_new (core->config); + rz_config_hold_s (hold, "asm.hint.pos", "asm.cmt.col", "asm.offset", "asm.lines", "asm.indent", "asm.bytes", "asm.comments", "asm.dwarf", "asm.usercomments", "asm.instr", NULL); if (for_graph) { - r_config_set (core->config, "asm.hint.pos", "-2"); - r_config_set (core->config, "asm.lines", "false"); - r_config_set (core->config, "asm.indent", "false"); + rz_config_set (core->config, "asm.hint.pos", "-2"); + rz_config_set (core->config, "asm.lines", "false"); + rz_config_set (core->config, "asm.indent", "false"); } else { - r_config_set (core->config, "asm.hint.pos", "0"); - r_config_set (core->config, "asm.indent", "true"); - r_config_set (core->config, "asm.lines", "true"); + rz_config_set (core->config, "asm.hint.pos", "0"); + rz_config_set (core->config, "asm.indent", "true"); + rz_config_set (core->config, "asm.lines", "true"); } - r_config_set (core->config, "asm.cmt.col", "0"); - r_config_set (core->config, "asm.offset", "false"); - r_config_set (core->config, "asm.dwarf", "true"); - r_config_set (core->config, "asm.bytes", "false"); - r_config_set (core->config, "asm.comments", "false"); - r_config_set (core->config, "asm.usercomments", "true"); - r_config_set (core->config, "asm.instr", "false"); + rz_config_set (core->config, "asm.cmt.col", "0"); + rz_config_set (core->config, "asm.offset", "false"); + rz_config_set (core->config, "asm.dwarf", "true"); + rz_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.comments", "false"); + rz_config_set (core->config, "asm.usercomments", "true"); + rz_config_set (core->config, "asm.instr", "false"); } -static void setcursor(RCore *core, bool cur) { +static void setcursor(RzCore *core, bool cur) { int flags = core->print->flags; // wtf if (core->print->cur_enabled) { flags |= R_PRINT_FLAGS_CURSOR; @@ -138,47 +138,47 @@ static void setcursor(RCore *core, bool cur) { if (core->print->cur == -1) { core->print->cur = 0; } - r_print_set_flags (core->print, flags); + rz_print_set_flags (core->print, flags); core->print->col = core->print->cur_enabled? 1: 0; } -R_API void r_core_visual_applyDisMode(RCore *core, int disMode) { +RZ_API void rz_core_visual_applyDisMode(RzCore *core, int disMode) { currentFormat = R_ABS(disMode) % 5; switch (currentFormat) { case 0: - r_config_set (core->config, "asm.pseudo", "false"); - r_config_set (core->config, "asm.bytes", "true"); - r_config_set (core->config, "asm.esil", "false"); - r_config_set (core->config, "emu.str", "false"); - r_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "asm.pseudo", "false"); + rz_config_set (core->config, "asm.bytes", "true"); + rz_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "emu.str", "false"); + rz_config_set (core->config, "asm.emu", "false"); break; case 1: - r_config_set (core->config, "asm.pseudo", "false"); - r_config_set (core->config, "asm.bytes", "true"); - r_config_set (core->config, "asm.esil", "false"); - r_config_set (core->config, "asm.emu", "false"); - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "asm.pseudo", "false"); + rz_config_set (core->config, "asm.bytes", "true"); + rz_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "emu.str", "true"); break; case 2: - r_config_set (core->config, "asm.pseudo", "true"); - r_config_set (core->config, "asm.bytes", "true"); - r_config_set (core->config, "asm.esil", "true"); - r_config_set (core->config, "emu.str", "true"); - r_config_set (core->config, "asm.emu", "true"); + rz_config_set (core->config, "asm.pseudo", "true"); + rz_config_set (core->config, "asm.bytes", "true"); + rz_config_set (core->config, "asm.esil", "true"); + rz_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "asm.emu", "true"); break; case 3: - r_config_set (core->config, "asm.pseudo", "false"); - r_config_set (core->config, "asm.bytes", "false"); - r_config_set (core->config, "asm.esil", "false"); - r_config_set (core->config, "asm.emu", "false"); - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "asm.pseudo", "false"); + rz_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "emu.str", "true"); break; case 4: - r_config_set (core->config, "asm.pseudo", "true"); - r_config_set (core->config, "asm.bytes", "false"); - r_config_set (core->config, "asm.esil", "false"); - r_config_set (core->config, "asm.emu", "false"); - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "asm.pseudo", "true"); + rz_config_set (core->config, "asm.bytes", "false"); + rz_config_set (core->config, "asm.esil", "false"); + rz_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "emu.str", "true"); break; } } @@ -197,12 +197,12 @@ static void prevPrintCommand(void) { currentFormat = current0format; } -static const char *stackPrintCommand(RCore *core) { +static const char *stackPrintCommand(RzCore *core) { if (current0format == 0) { - if (r_config_get_i (core->config, "dbg.slow")) { + if (rz_config_get_i (core->config, "dbg.slow")) { return "pxr"; } - if (r_config_get_i (core->config, "stack.bytes")) { + if (rz_config_get_i (core->config, "stack.bytes")) { return "px"; } switch (core->rasm->bits) { @@ -214,43 +214,43 @@ static const char *stackPrintCommand(RCore *core) { return printHexFormats[current0format % PRINT_HEX_FORMATS]; } -static const char *__core_visual_print_command(RCore *core) { +static const char *__core_visual_print_command(RzCore *core) { if (core->visual.tabs) { - RCoreVisualTab *tab = r_list_get_n (core->visual.tabs, core->visual.tab); + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); if (tab && tab->name[0] == ':') { return tab->name + 1; } } - if (r_config_get_i (core->config, "scr.dumpcols")) { + if (rz_config_get_i (core->config, "scr.dumpcols")) { free (core->stkcmd); - core->stkcmd = r_str_newf (stackPrintCommand (core)); + core->stkcmd = rz_str_newf (stackPrintCommand (core)); return printfmtColumns[PIDX]; } return printfmtSingle[PIDX]; } -static bool __core_visual_gogo(RCore *core, int ch) { - RIOMap *map; +static bool __core_visual_gogo(RzCore *core, int ch) { + RzIOMap *map; int ret = -1; switch (ch) { case 'g': if (core->io->va) { - RIOMap *map = r_io_map_get (core->io, core->offset); - if (!map && !r_pvector_empty (&core->io->maps)) { - map = r_pvector_at (&core->io->maps, r_pvector_len (&core->io->maps) - 1); + RzIOMap *map = rz_io_map_get (core->io, core->offset); + if (!map && !rz_pvector_empty (&core->io->maps)) { + map = rz_pvector_at (&core->io->maps, rz_pvector_len (&core->io->maps) - 1); } if (map) { - r_core_seek (core, r_itv_begin (map->itv), true); + rz_core_seek (core, rz_itv_begin (map->itv), true); } } else { - r_core_seek (core, 0, true); + rz_core_seek (core, 0, true); } - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); return true; case 'G': - map = r_io_map_get (core->io, core->offset); - if (!map && !r_pvector_empty (&core->io->maps)) { - map = r_pvector_at (&core->io->maps, 0); + map = rz_io_map_get (core->io, core->offset); + if (!map && !rz_pvector_empty (&core->io->maps)) { + map = rz_pvector_at (&core->io->maps, 0); } if (map) { RPrint *p = core->print; @@ -259,11 +259,11 @@ static bool __core_visual_gogo(RCore *core, int ch) { break; } (void)p->consbind.get_size (&scr_rows); - ut64 scols = r_config_get_i (core->config, "hex.cols"); - ret = r_core_seek (core, r_itv_end (map->itv) - (scr_rows - 2) * scols, true); + ut64 scols = rz_config_get_i (core->config, "hex.cols"); + ret = rz_core_seek (core, rz_itv_end (map->itv) - (scr_rows - 2) * scols, true); } if (ret != -1) { - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } return true; } @@ -359,45 +359,45 @@ static ut64 splitPtr = UT64_MAX; #if USE_THREADS -static void printSnow(RCore *core) { +static void printSnow(RzCore *core) { if (!snows) { - snows = r_list_newf (free); + snows = rz_list_newf (free); } - int i, h, w = r_cons_get_size (&h); - int amount = r_num_rand (4); + int i, h, w = rz_cons_get_size (&h); + int amount = rz_num_rand (4); if (amount > 0) { for (i = 0; i < amount; i++) { Snow *snow = R_NEW (Snow); - snow->x = r_num_rand (w); + snow->x = rz_num_rand (w); snow->y = 0; - r_list_append (snows, snow); + rz_list_append (snows, snow); } } - RListIter *iter, *iter2; + RzListIter *iter, *iter2; Snow *snow; - r_list_foreach_safe (snows, iter, iter2, snow) { - int pos = (r_num_rand (3)) - 1; + rz_list_foreach_safe (snows, iter, iter2, snow) { + int pos = (rz_num_rand (3)) - 1; snow->x += pos; snow->y++; if (snow->x >= w) { - r_list_delete (snows, iter); + rz_list_delete (snows, iter); continue; } if (snow->y > h) { - r_list_delete (snows, iter); + rz_list_delete (snows, iter); continue; } - r_cons_gotoxy (snow->x, snow->y); - r_cons_printf ("*"); + rz_cons_gotoxy (snow->x, snow->y); + rz_cons_printf ("*"); } - // r_cons_gotoxy (10 , 10); - r_cons_flush (); + // rz_cons_gotoxy (10 , 10); + rz_cons_flush (); } #endif -static void rotateAsmBits(RCore *core) { - RAnalHint *hint = r_anal_hint_get (core->anal, core->offset); - int bits = hint? hint->bits : r_config_get_i (core->config, "asm.bits"); +static void rotateAsmBits(RzCore *core) { + RzAnalHint *hint = rz_anal_hint_get (core->anal, core->offset); + int bits = hint? hint->bits : rz_config_get_i (core->config, "asm.bits"); int retries = 4; while (retries > 0) { int nb = bits == 64 ? 8: @@ -405,55 +405,55 @@ static void rotateAsmBits(RCore *core) { bits == 16 ? 32: bits == 8 ? 16: bits; if ((core->rasm->cur->bits & nb) == nb) { - r_core_cmdf (core, "ahb %d", nb); + rz_core_cmdf (core, "ahb %d", nb); break; } bits = nb; retries--; } - r_anal_hint_free (hint); + rz_anal_hint_free (hint); } -static const char *rotateAsmemu(RCore *core) { - const bool isEmuStr = r_config_get_i (core->config, "emu.str"); - const bool isEmu = r_config_get_i (core->config, "asm.emu"); +static const char *rotateAsmemu(RzCore *core) { + const bool isEmuStr = rz_config_get_i (core->config, "emu.str"); + const bool isEmu = rz_config_get_i (core->config, "asm.emu"); if (isEmu) { if (isEmuStr) { - r_config_set (core->config, "emu.str", "false"); + rz_config_set (core->config, "emu.str", "false"); } else { - r_config_set (core->config, "asm.emu", "false"); + rz_config_set (core->config, "asm.emu", "false"); } } else { - r_config_set (core->config, "emu.str", "true"); + rz_config_set (core->config, "emu.str", "true"); } return "pd"; } -R_API void r_core_visual_showcursor(RCore *core, int x) { +RZ_API void rz_core_visual_showcursor(RzCore *core, int x) { if (core && core->vmode) { - r_cons_show_cursor (x); - r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel")); + rz_cons_show_cursor (x); + rz_cons_enable_mouse (rz_config_get_i (core->config, "scr.wheel")); } else { - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); } - r_cons_flush (); + rz_cons_flush (); } -static void printFormat(RCore *core, const int next) { +static void printFormat(RzCore *core, const int next) { switch (core->printidx) { case R_CORE_VISUAL_MODE_PX: // 0 // xc hexMode += next; - r_core_visual_applyHexMode (core, hexMode); + rz_core_visual_applyHexMode (core, hexMode); printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; break; case R_CORE_VISUAL_MODE_PD: // pd disMode += next; - r_core_visual_applyDisMode (core, disMode); + rz_core_visual_applyDisMode (core, disMode); printfmtSingle[1] = rotateAsmemu (core); break; case R_CORE_VISUAL_MODE_DB: // debugger disMode += next; - r_core_visual_applyDisMode (core, disMode); + rz_core_visual_applyDisMode (core, disMode); printfmtSingle[1] = rotateAsmemu (core); current3format += next; currentFormat = R_ABS (current3format) % PRINT_3_FORMATS; @@ -472,123 +472,123 @@ static void printFormat(RCore *core, const int next) { } } -static inline void nextPrintFormat(RCore *core) { +static inline void nextPrintFormat(RzCore *core) { printFormat (core, 1); } -static inline void prevPrintFormat(RCore *core) { +static inline void prevPrintFormat(RzCore *core) { printFormat (core, -1); } -R_API int r_core_visual_hud(RCore *core) { - const char *c = r_config_get (core->config, "hud.path"); - char *f = r_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"), - r_sys_prefix (NULL)); +RZ_API int rz_core_visual_hud(RzCore *core) { + const char *c = rz_config_get (core->config, "hud.path"); + char *f = rz_str_newf (R_JOIN_3_PATHS ("%s", R2_HUD, "main"), + rz_sys_prefix (NULL)); int use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - char *homehud = r_str_home (R2_HOME_HUD); + char *homehud = rz_str_home (R2_HOME_HUD); char *res = NULL; char *p = 0; - r_cons_singleton ()->context->color_mode = use_color; + rz_cons_singleton ()->context->color_mode = use_color; - r_core_visual_showcursor (core, true); - if (c && *c && r_file_exists (c)) { - res = r_cons_hud_file (c); + rz_core_visual_showcursor (core, true); + if (c && *c && rz_file_exists (c)) { + res = rz_cons_hud_file (c); } if (!res && homehud) { - res = r_cons_hud_file (homehud); + res = rz_cons_hud_file (homehud); } - if (!res && r_file_exists (f)) { - res = r_cons_hud_file (f); + if (!res && rz_file_exists (f)) { + res = rz_cons_hud_file (f); } if (!res) { - r_cons_message ("Cannot find hud file"); + rz_cons_message ("Cannot find hud file"); } - r_cons_clear (); + rz_cons_clear (); if (res) { p = strchr (res, ';'); - r_cons_println (res); - r_cons_flush (); + rz_cons_println (res); + rz_cons_flush (); if (p) { - r_core_cmd0 (core, p + 1); + rz_core_cmd0 (core, p + 1); } free (res); } - r_core_visual_showcursor (core, false); - r_cons_flush (); + rz_core_visual_showcursor (core, false); + rz_cons_flush (); free (homehud); free (f); return (int) (size_t) p; } -R_API void r_core_visual_jump(RCore *core, ut8 ch) { +RZ_API void rz_core_visual_jump(RzCore *core, ut8 ch) { char chbuf[2]; ut64 off; chbuf[0] = ch; chbuf[1] = '\0'; - off = r_core_get_asmqjmps (core, chbuf); + off = rz_core_get_asmqjmps (core, chbuf); if (off != UT64_MAX) { int delta = R_ABS ((st64) off - (st64) core->offset); - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); if (core->print->cur_enabled && delta < 100) { core->print->cur = delta; } else { - r_core_visual_seek_animation (core, off); + rz_core_visual_seek_animation (core, off); core->print->cur = 0; } - r_core_block_read (core); + rz_core_block_read (core); } } -R_API void r_core_visual_append_help(RStrBuf *p, const char *title, const char **help) { +RZ_API void rz_core_visual_append_help(RStrBuf *p, const char *title, const char **help) { int i, max_length = 0, padding = 0; - RConsContext *cons_ctx = r_cons_singleton ()->context; + RzConsContext *cons_ctx = rz_cons_singleton ()->context; const char *pal_args_color = cons_ctx->color_mode ? cons_ctx->pal.args : "", *pal_help_color = cons_ctx->color_mode ? cons_ctx->pal.help : "", *pal_reset = cons_ctx->color_mode ? cons_ctx->pal.reset : ""; for (i = 0; help[i]; i += 2) { max_length = R_MAX (max_length, strlen (help[i])); } - r_strbuf_appendf (p, "|%s:\n", title); + rz_strbuf_appendf (p, "|%s:\n", title); for (i = 0; help[i]; i += 2) { padding = max_length - (strlen (help[i])); - r_strbuf_appendf (p, "| %s%s%*s %s%s%s\n", + rz_strbuf_appendf (p, "| %s%s%*s %s%s%s\n", pal_args_color, help[i], padding, "", pal_help_color, help[i + 1], pal_reset); } } -static int visual_help(RCore *core) { +static int visual_help(RzCore *core) { int ret = 0; RStrBuf *p, *q; repeat: - p = r_strbuf_new (NULL); - q = r_strbuf_new (NULL); + p = rz_strbuf_new (NULL); + q = rz_strbuf_new (NULL); if (!p) { return 0; } - r_cons_clear00 (); - r_core_visual_append_help (q, "Visual Help", help_visual); - r_cons_printf ("%s", r_strbuf_get (q)); - r_cons_flush (); - switch (r_cons_readchar ()) { + rz_cons_clear00 (); + rz_core_visual_append_help (q, "Visual Help", help_visual); + rz_cons_printf ("%s", rz_strbuf_get (q)); + rz_cons_flush (); + switch (rz_cons_readchar ()) { case 'q': - r_strbuf_free (p); - r_strbuf_free (q); + rz_strbuf_free (p); + rz_strbuf_free (q); return ret; case '!': - r_core_visual_panels_root (core, core->panels_root); + rz_core_visual_panels_root (core, core->panels_root); break; case '?': - r_core_visual_append_help (p, "Visual mode help", help_msg_visual); - r_core_visual_append_help (p, "Function Keys: (See 'e key.'), defaults to", help_msg_visual_fn); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + rz_core_visual_append_help (p, "Visual mode help", help_msg_visual); + rz_core_visual_append_help (p, "Function Keys: (See 'e key.'), defaults to", help_msg_visual_fn); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'v': - r_strbuf_appendf (p, "Visual Views:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Views:\n\n"); + rz_strbuf_appendf (p, " \\ toggle horizonal split mode\n" " tt create a new tab (same as t+)\n" " t= give a name to the current tab\n" @@ -599,53 +599,53 @@ repeat: " C -> rotate scr.color=0,1,2,3\n" " R -> rotate color theme with ecr command which honors scr.randpal\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'p': - r_strbuf_appendf (p, "Visual Print Modes:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Print Modes:\n\n"); + rz_strbuf_appendf (p, " pP -> change to the next/previous print mode (hex, dis, ..)\n" " TAB -> rotate between all the configurations for the current print mode\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'e': - r_strbuf_appendf (p, "Visual Evals:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Evals:\n\n"); + rz_strbuf_appendf (p, " E toggle asm.leahints\n" " & rotate asm.bits=16,32,64\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'c': setcursor (core, !core->print->cur_enabled); - r_strbuf_free (p); + rz_strbuf_free (p); return ret; case 'i': - r_strbuf_appendf (p, "Visual Insertion Help:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Insertion Help:\n\n"); + rz_strbuf_appendf (p, " i -> insert bits, bytes or text depending on view\n" " a -> assemble instruction and write the bytes in the current offset\n" " A -> visual assembler\n" " + -> increment value of byte\n" " - -> decrement value of byte\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'd': - r_strbuf_appendf (p, "Visual Debugger Help:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Debugger Help:\n\n"); + rz_strbuf_appendf (p, " $ -> set the program counter (PC register)\n" " s -> step in\n" " S -> step over\n" " B -> toggle breakpoint\n" " :dc -> continue\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'm': - r_strbuf_appendf (p, "Visual Moving Around:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Moving Around:\n\n"); + rz_strbuf_appendf (p, " g type flag/offset/register name to seek\n" " hl seek to the next/previous byte\n" " jk seek to the next row (core.offset += hex.cols)\n" @@ -655,11 +655,11 @@ repeat: " c toggle cursor mode (use hjkl to move and HJKL to select a range)\n" " mK/'K mark/go to Key (any key)\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; case 'a': - r_strbuf_appendf (p, "Visual Analysis:\n\n"); - r_strbuf_appendf (p, + rz_strbuf_appendf (p, "Visual Analysis:\n\n"); + rz_strbuf_appendf (p, " df -> define function\n" " du -> undefine function\n" " dc -> define as code\n" @@ -668,11 +668,11 @@ repeat: " dd -> define current block or selected bytes as data\n" " V -> view graph (same as press the 'space' key)\n" ); - ret = r_cons_less_str (r_strbuf_get (p), "?"); + ret = rz_cons_less_str (rz_strbuf_get (p), "?"); break; } - r_strbuf_free (p); - r_strbuf_free (q); + rz_strbuf_free (p); + rz_strbuf_free (q); goto repeat; } @@ -681,10 +681,10 @@ static void prompt_read(const char *p, char *buf, int buflen) { return; } *buf = 0; - r_line_set_prompt (p); - r_core_visual_showcursor (NULL, true); - r_cons_fgets (buf, buflen, 0, NULL); - r_core_visual_showcursor (NULL, false); + rz_line_set_prompt (p); + rz_core_visual_showcursor (NULL, true); + rz_cons_fgets (buf, buflen, 0, NULL); + rz_core_visual_showcursor (NULL, false); } static void reset_print_cur(RPrint *p) { @@ -692,28 +692,28 @@ static void reset_print_cur(RPrint *p) { p->ocur = -1; } -static bool __holdMouseState(RCore *core) { - bool m = r_cons_singleton ()->mouse; - r_cons_enable_mouse (false); +static bool __holdMouseState(RzCore *core) { + bool m = rz_cons_singleton ()->mouse; + rz_cons_enable_mouse (false); return m; } -static void backup_current_addr(RCore *core, ut64 *addr, ut64 *bsze, ut64 *newaddr) { +static void backup_current_addr(RzCore *core, ut64 *addr, ut64 *bsze, ut64 *newaddr) { *addr = core->offset; *bsze = core->blocksize; if (core->print->cur_enabled) { if (core->print->ocur != -1) { int newsz = core->print->cur - core->print->ocur; *newaddr = core->offset + core->print->ocur; - r_core_block_size (core, newsz); + rz_core_block_size (core, newsz); } else { *newaddr = core->offset + core->print->cur; } - r_core_seek (core, *newaddr, true); + rz_core_seek (core, *newaddr, true); } } -static void restore_current_addr(RCore *core, ut64 addr, ut64 bsze, ut64 newaddr) { +static void restore_current_addr(RzCore *core, ut64 addr, ut64 bsze, ut64 newaddr) { bool restore_seek = true; if (core->offset != newaddr) { bool cursor_moved = false; @@ -736,227 +736,227 @@ static void restore_current_addr(RCore *core, ut64 addr, ut64 bsze, ut64 newaddr if (core->print->cur_enabled) { if (restore_seek) { - r_core_seek (core, addr, true); - r_core_block_size (core, bsze); + rz_core_seek (core, addr, true); + rz_core_block_size (core, bsze); } } } -R_API void r_core_visual_prompt_input(RCore *core) { +RZ_API void rz_core_visual_prompt_input(RzCore *core) { ut64 addr, bsze, newaddr = 0LL; int ret, h; - (void) r_cons_get_size (&h); + (void) rz_cons_get_size (&h); bool mouse_state = __holdMouseState(core); - r_cons_gotoxy (0, h); - r_cons_reset_colors (); - //r_cons_printf ("\nPress to return to Visual mode.\n"); - r_cons_show_cursor (true); + rz_cons_gotoxy (0, h); + rz_cons_reset_colors (); + //rz_cons_printf ("\nPress to return to Visual mode.\n"); + rz_cons_show_cursor (true); core->vmode = false; backup_current_addr (core, &addr, &bsze, &newaddr); do { - ret = r_core_visual_prompt (core); + ret = rz_core_visual_prompt (core); } while (ret); restore_current_addr (core, addr, bsze, newaddr); - r_cons_show_cursor (false); + rz_cons_show_cursor (false); core->vmode = true; - r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel")); - r_cons_show_cursor (true); + rz_cons_enable_mouse (mouse_state && rz_config_get_i (core->config, "scr.wheel")); + rz_cons_show_cursor (true); } -R_API int r_core_visual_prompt(RCore *core) { +RZ_API int rz_core_visual_prompt(RzCore *core) { char buf[1024]; int ret; if (PIDX != 2) { core->seltab = 0; } #if __UNIX__ - r_line_set_prompt (Color_RESET ":> "); + rz_line_set_prompt (Color_RESET ":> "); #else - r_line_set_prompt (":> "); + rz_line_set_prompt (":> "); #endif - r_core_visual_showcursor (core, true); - r_cons_fgets (buf, sizeof (buf), 0, NULL); + rz_core_visual_showcursor (core, true); + rz_cons_fgets (buf, sizeof (buf), 0, NULL); if (!strcmp (buf, "q")) { ret = false; } else if (*buf) { - r_line_hist_add (buf); - r_core_cmd (core, buf, 0); - r_cons_echo (NULL); - r_cons_flush (); + rz_line_hist_add (buf); + rz_core_cmd (core, buf, 0); + rz_cons_echo (NULL); + rz_cons_flush (); ret = true; - if (r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd (core, ".dr*", 0); + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd (core, ".dr*", 0); } } else { ret = false; - //r_cons_any_key (NULL); - r_cons_clear00 (); - r_core_visual_showcursor (core, false); + //rz_cons_any_key (NULL); + rz_cons_clear00 (); + rz_core_visual_showcursor (core, false); } return ret; } -static void visual_single_step_in(RCore *core) { - if (r_config_get_i (core->config, "cfg.debug")) { +static void visual_single_step_in(RzCore *core) { + if (rz_config_get_i (core->config, "cfg.debug")) { if (core->print->cur_enabled) { // dcu 0xaddr - r_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); core->print->cur_enabled = 0; } else { - r_core_cmd (core, "ds", 0); - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, "ds", 0); + rz_core_cmd (core, ".dr*", 0); } } else { - r_core_cmd (core, "aes", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aes", 0); + rz_core_cmd (core, ".ar*", 0); } } -static void __core_visual_step_over(RCore *core) { - bool io_cache = r_config_get_i (core->config, "io.cache"); - r_config_set_i (core->config, "io.cache", false); - if (r_config_get_i (core->config, "cfg.debug")) { +static void __core_visual_step_over(RzCore *core) { + bool io_cache = rz_config_get_i (core->config, "io.cache"); + rz_config_set_i (core->config, "io.cache", false); + if (rz_config_get_i (core->config, "cfg.debug")) { if (core->print->cur_enabled) { - r_core_cmd (core, "dcr", 0); + rz_core_cmd (core, "dcr", 0); core->print->cur_enabled = 0; } else { - r_core_cmd (core, "dso", 0); - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, "dso", 0); + rz_core_cmd (core, ".dr*", 0); } } else { - r_core_cmd (core, "aeso", 0); - r_core_cmd (core, ".ar*", 0); + rz_core_cmd (core, "aeso", 0); + rz_core_cmd (core, ".ar*", 0); } - r_config_set_i (core->config, "io.cache", io_cache); + rz_config_set_i (core->config, "io.cache", io_cache); } -static void visual_breakpoint(RCore *core) { - r_core_cmd (core, "dbs $$", 0); +static void visual_breakpoint(RzCore *core) { + rz_core_cmd (core, "dbs $$", 0); } -static void visual_continue(RCore *core) { - if (r_config_get_i (core->config, "cfg.debug")) { - r_core_cmd (core, "dc", 0); +static void visual_continue(RzCore *core) { + if (rz_config_get_i (core->config, "cfg.debug")) { + rz_core_cmd (core, "dc", 0); } else { - r_core_cmd (core, "aec;.ar*", 0); + rz_core_cmd (core, "aec;.ar*", 0); } } -static int visual_nkey(RCore *core, int ch) { +static int visual_nkey(RzCore *core, int ch) { const char *cmd; ut64 oseek = UT64_MAX; if (core->print->ocur == -1) { oseek = core->offset; - r_core_seek (core, core->offset + core->print->cur, false); + rz_core_seek (core, core->offset + core->print->cur, false); } switch (ch) { case R_CONS_KEY_F1: - cmd = r_config_get (core->config, "key.f1"); + cmd = rz_config_get (core->config, "key.f1"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { visual_help (core); } break; case R_CONS_KEY_F2: - cmd = r_config_get (core->config, "key.f2"); + cmd = rz_config_get (core->config, "key.f2"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { visual_breakpoint (core); } break; case R_CONS_KEY_F3: - cmd = r_config_get (core->config, "key.f3"); + cmd = rz_config_get (core->config, "key.f3"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F4: - cmd = r_config_get (core->config, "key.f4"); + cmd = rz_config_get (core->config, "key.f4"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { if (core->print->cur_enabled) { // dcu 0xaddr - r_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "dcu 0x%08"PFMT64x, core->offset + core->print->cur); core->print->cur_enabled = 0; } } break; case R_CONS_KEY_F5: - cmd = r_config_get (core->config, "key.f5"); + cmd = rz_config_get (core->config, "key.f5"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F6: - cmd = r_config_get (core->config, "key.f6"); + cmd = rz_config_get (core->config, "key.f6"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F7: - cmd = r_config_get (core->config, "key.f7"); + cmd = rz_config_get (core->config, "key.f7"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { visual_single_step_in (core); } break; case R_CONS_KEY_F8: - cmd = r_config_get (core->config, "key.f8"); + cmd = rz_config_get (core->config, "key.f8"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { __core_visual_step_over (core); } break; case R_CONS_KEY_F9: - cmd = r_config_get (core->config, "key.f9"); + cmd = rz_config_get (core->config, "key.f9"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } else { visual_continue (core); } break; case R_CONS_KEY_F10: - cmd = r_config_get (core->config, "key.f10"); + cmd = rz_config_get (core->config, "key.f10"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F11: - cmd = r_config_get (core->config, "key.f11"); + cmd = rz_config_get (core->config, "key.f11"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; case R_CONS_KEY_F12: - cmd = r_config_get (core->config, "key.f12"); + cmd = rz_config_get (core->config, "key.f12"); if (cmd && *cmd) { - ch = r_core_cmd0 (core, cmd); + ch = rz_core_cmd0 (core, cmd); } break; } if (oseek != UT64_MAX) { - r_core_seek (core, oseek, false); + rz_core_seek (core, oseek, false); } return ch; } -static void setdiff(RCore *core) { +static void setdiff(RzCore *core) { char from[64], to[64]; prompt_read ("diff from: ", from, sizeof (from)); - r_config_set (core->config, "diff.from", from); + rz_config_set (core->config, "diff.from", from); prompt_read ("diff to: ", to, sizeof (to)); - r_config_set (core->config, "diff.to", to); + rz_config_set (core->config, "diff.to", to); } -static void findPair(RCore *core) { +static void findPair(RzCore *core) { ut8 buf[256]; int i, len, d = core->print->cur + 1; int delta = 0; @@ -984,21 +984,21 @@ static void findPair(RCore *core) { } } } else { - q = r_mem_mem (core->block + d, core->blocksize - d, + q = rz_mem_mem (core->block + d, core->blocksize - d, (const ut8 *) buf, len); if (!q) { - q = r_mem_mem (core->block, R_MIN (core->blocksize, d), + q = rz_mem_mem (core->block, R_MIN (core->blocksize, d), (const ut8 *) buf, len); } } if (q) { core->print->cur = (int) (size_t) (q - core->block); core->print->ocur = -1; - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); } } -static void findNextWord(RCore *core) { +static void findNextWord(RzCore *core) { int i, d = core->print->cur_enabled? core->print->cur: 0; for (i = d + 1; i < core->blocksize; i++) { switch (core->block[i]) { @@ -1009,9 +1009,9 @@ static void findNextWord(RCore *core) { if (core->print->cur_enabled) { core->print->cur = i + 1; core->print->ocur = -1; - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); } else { - r_core_seek (core, core->offset + i + 1, true); + rz_core_seek (core, core->offset + i + 1, true); } return; } @@ -1030,7 +1030,7 @@ static int isSpace(char ch) { return 0; } -static void findPrevWord(RCore *core) { +static void findPrevWord(RzCore *core) { int i = core->print->cur_enabled? core->print->cur: 0; while (i > 1) { if (isSpace (core->block[i])) { @@ -1046,7 +1046,7 @@ static void findPrevWord(RCore *core) { if (core->print->cur_enabled) { core->print->cur = i + 1; core->print->ocur = -1; - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); } break; } @@ -1054,16 +1054,16 @@ static void findPrevWord(RCore *core) { } // TODO: integrate in '/' command with search.inblock ? -static void visual_search(RCore *core) { +static void visual_search(RzCore *core) { const ut8 *p; int len, d = core->print->cur; char str[128], buf[sizeof (str) * 2 + 1]; - r_line_set_prompt ("search byte/string in block: "); - r_cons_fgets (str, sizeof (str), 0, NULL); - len = r_hex_str2bin (str, (ut8 *) buf); + rz_line_set_prompt ("search byte/string in block: "); + rz_cons_fgets (str, sizeof (str), 0, NULL); + len = rz_hex_str2bin (str, (ut8 *) buf); if (*str == '"') { - r_str_ncpy (buf, str + 1, sizeof (buf)); + rz_str_ncpy (buf, str + 1, sizeof (buf)); len = strlen (buf); char *e = buf + len - 1; if (e > buf && *e == '"') { @@ -1071,10 +1071,10 @@ static void visual_search(RCore *core) { len--; } } else if (len < 1) { - r_str_ncpy (buf, str, sizeof (buf)); + rz_str_ncpy (buf, str, sizeof (buf)); len = strlen (buf); } - p = r_mem_mem (core->block + d, core->blocksize - d, + p = rz_mem_mem (core->block + d, core->blocksize - d, (const ut8 *) buf, len); if (p) { core->print->cur = (int) (size_t) (p - core->block); @@ -1083,55 +1083,55 @@ static void visual_search(RCore *core) { } else { core->print->ocur = -1; } - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); eprintf ("Found in offset 0x%08"PFMT64x" + %d\n", core->offset, core->print->cur); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } else { eprintf ("Cannot find bytes.\n"); - r_cons_any_key (NULL); - r_cons_clear00 (); + rz_cons_any_key (NULL); + rz_cons_clear00 (); } } -R_API void r_core_visual_show_char(RCore *core, char ch) { - if (r_config_get_i (core->config, "scr.feedback") < 2) { +RZ_API void rz_core_visual_show_char(RzCore *core, char ch) { + if (rz_config_get_i (core->config, "scr.feedback") < 2) { return; } if (!IS_PRINTABLE (ch)) { return; } - r_cons_gotoxy (1, 2); - r_cons_printf (".---.\n"); - r_cons_printf ("| %c |\n", ch); - r_cons_printf ("'---'\n"); - r_cons_flush (); - r_sys_sleep (1); + rz_cons_gotoxy (1, 2); + rz_cons_printf (".---.\n"); + rz_cons_printf ("| %c |\n", ch); + rz_cons_printf ("'---'\n"); + rz_cons_flush (); + rz_sys_sleep (1); } -R_API void r_core_visual_seek_animation(RCore *core, ut64 addr) { - r_core_seek (core, addr, true); - if (r_config_get_i (core->config, "scr.feedback") < 1) { +RZ_API void rz_core_visual_seek_animation(RzCore *core, ut64 addr) { + rz_core_seek (core, addr, true); + if (rz_config_get_i (core->config, "scr.feedback") < 1) { return; } if (core->offset == addr) { return; } - r_cons_gotoxy (1, 2); + rz_cons_gotoxy (1, 2); if (addr > core->offset) { - r_cons_printf (".----.\n"); - r_cons_printf ("| \\/ |\n"); - r_cons_printf ("'----'\n"); + rz_cons_printf (".----.\n"); + rz_cons_printf ("| \\/ |\n"); + rz_cons_printf ("'----'\n"); } else { - r_cons_printf (".----.\n"); - r_cons_printf ("| /\\ |\n"); - r_cons_printf ("'----'\n"); + rz_cons_printf (".----.\n"); + rz_cons_printf ("| /\\ |\n"); + rz_cons_printf ("'----'\n"); } - r_cons_flush (); - r_sys_usleep (90000); + rz_cons_flush (); + rz_sys_usleep (90000); } -static void setprintmode(RCore *core, int n) { - RAsmOp op; +static void setprintmode(RzCore *core, int n) { + RzAsmOp op; if (n > 0) { core->printidx = R_ABS ((core->printidx + 1) % NPF); @@ -1145,9 +1145,9 @@ static void setprintmode(RCore *core, int n) { switch (core->printidx) { case R_CORE_VISUAL_MODE_PD: case R_CORE_VISUAL_MODE_DB: - r_asm_op_init (&op); - r_asm_disassemble (core->rasm, &op, core->block, R_MIN (32, core->blocksize)); - r_asm_op_fini (&op); + rz_asm_op_init (&op); + rz_asm_disassemble (core->rasm, &op, core->block, R_MIN (32, core->blocksize)); + rz_asm_op_fini (&op); break; default: break; @@ -1155,14 +1155,14 @@ static void setprintmode(RCore *core, int n) { } #define OPDELTA 32 -static ut64 prevop_addr(RCore *core, ut64 addr) { +static ut64 prevop_addr(RzCore *core, ut64 addr) { ut8 buf[OPDELTA * 2]; ut64 target, base; - RAnalBlock *bb; - RAnalOp op; + RzAnalBlock *bb; + RzAnalOp op; int len, ret, i; - int minop = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); - int maxop = r_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); + int minop = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MIN_OP_SIZE); + int maxop = rz_anal_archinfo (core->anal, R_ANAL_ARCHINFO_MAX_OP_SIZE); if (minop == maxop) { if (minop == -1) { @@ -1175,29 +1175,29 @@ static ut64 prevop_addr(RCore *core, ut64 addr) { // TODO: look in the current basicblock, then in the current function // and search in all functions only as a last chance, to try to speed // up the process. - bb = r_anal_bb_from_offset (core->anal, addr - minop); + bb = rz_anal_bb_from_offset (core->anal, addr - minop); if (bb) { - ut64 res = r_anal_bb_opaddr_at (bb, addr - minop); + ut64 res = rz_anal_bb_opaddr_at (bb, addr - minop); if (res != UT64_MAX) { return res; } } // if we anal info didn't help then fallback to the dumb solution. - int midflags = r_config_get_i (core->config, "asm.flags.middle"); + int midflags = rz_config_get_i (core->config, "asm.flags.middle"); target = addr; base = target > OPDELTA ? target - OPDELTA : 0; - r_io_read_at (core->io, base, buf, sizeof (buf)); + rz_io_read_at (core->io, base, buf, sizeof (buf)); for (i = 0; i < sizeof (buf); i++) { - ret = r_anal_op (core->anal, &op, base + i, + ret = rz_anal_op (core->anal, &op, base + i, buf + i, sizeof (buf) - i, R_ANAL_OP_MASK_BASIC); if (ret) { len = op.size; if (len < 1) { len = 1; } - r_anal_op_fini (&op); // XXX + rz_anal_op_fini (&op); // XXX if (midflags >= R_MIDFLAGS_REALIGN) { - int skip_bytes = r_core_flag_in_middle (core, base + i, len, &midflags); + int skip_bytes = rz_core_flag_in_middle (core, base + i, len, &midflags); if (skip_bytes && base + i + skip_bytes < target) { i += skip_bytes - 1; continue; @@ -1217,13 +1217,13 @@ static ut64 prevop_addr(RCore *core, ut64 addr) { // Returns true if we can use analysis to find the previous operation address, // sets prev_addr to the value of the instruction numinstrs back. // If we can't use the anal, then set prev_addr to UT64_MAX and return false; -R_API bool r_core_prevop_addr(RCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr) { - RAnalBlock *bb; +RZ_API bool rz_core_prevop_addr(RzCore *core, ut64 start_addr, int numinstrs, ut64 *prev_addr) { + RzAnalBlock *bb; int i; // Check that we're in a bb, otherwise this prevop stuff won't work. - bb = r_anal_bb_from_offset (core->anal, start_addr); + bb = rz_anal_bb_from_offset (core->anal, start_addr); if (bb) { - if (r_anal_bb_opaddr_at (bb, start_addr) != UT64_MAX) { + if (rz_anal_bb_opaddr_at (bb, start_addr) != UT64_MAX) { // Do some anal looping. for (i = 0; i < numinstrs; i++) { *prev_addr = prevop_addr (core, start_addr); @@ -1237,9 +1237,9 @@ R_API bool r_core_prevop_addr(RCore *core, ut64 start_addr, int numinstrs, ut64 return false; } -// Like r_core_prevop_addr(), but also uses fallback from prevop_addr() if +// Like rz_core_prevop_addr(), but also uses fallback from prevop_addr() if // no anal info is available. -R_API ut64 r_core_prevop_addr_force(RCore *core, ut64 start_addr, int numinstrs) { +RZ_API ut64 rz_core_prevop_addr_force(RzCore *core, ut64 start_addr, int numinstrs) { int i; for (i = 0; i < numinstrs; i++) { start_addr = prevop_addr (core, start_addr); @@ -1247,20 +1247,20 @@ R_API ut64 r_core_prevop_addr_force(RCore *core, ut64 start_addr, int numinstrs) return start_addr; } -R_API int r_line_hist_offset_up(RLine *line) { - RCore *core = line->user; - RIOUndo *undo = &core->io->undo; +RZ_API int rz_line_hist_offset_up(RLine *line) { + RzCore *core = line->user; + RzIOUndo *undo = &core->io->undo; if (line->offset_hist_index <= -undo->undos) { return false; } line->offset_hist_index--; ut64 off = undo->seek[undo->idx + line->offset_hist_index].off; - RFlagItem *f = r_flag_get_at (core->flags, off, false); + RzFlagItem *f = rz_flag_get_at (core->flags, off, false); char *command; if (f && f->offset == off && f->offset > 0) { - command = r_str_newf ("%s", f->name); + command = rz_str_newf ("%s", f->name); } else { - command = r_str_newf ("0x%"PFMT64x, off); + command = rz_str_newf ("0x%"PFMT64x, off); } strncpy (line->buffer.data, command, R_LINE_BUFSIZE - 1); line->buffer.index = line->buffer.length = strlen (line->buffer.data); @@ -1268,9 +1268,9 @@ R_API int r_line_hist_offset_up(RLine *line) { return true; } -R_API int r_line_hist_offset_down(RLine *line) { - RCore *core = line->user; - RIOUndo *undo = &core->io->undo; +RZ_API int rz_line_hist_offset_down(RLine *line) { + RzCore *core = line->user; + RzIOUndo *undo = &core->io->undo; if (line->offset_hist_index >= undo->redos) { return false; } @@ -1281,12 +1281,12 @@ R_API int r_line_hist_offset_down(RLine *line) { return false; } ut64 off = undo->seek[undo->idx + line->offset_hist_index].off; - RFlagItem *f = r_flag_get_at (core->flags, off, false); + RzFlagItem *f = rz_flag_get_at (core->flags, off, false); char *command; if (f && f->offset == off && f->offset > 0) { - command = r_str_newf ("%s", f->name); + command = rz_str_newf ("%s", f->name); } else { - command = r_str_newf ("0x%"PFMT64x, off); + command = rz_str_newf ("0x%"PFMT64x, off); } strncpy (line->buffer.data, command, R_LINE_BUFSIZE - 1); line->buffer.index = line->buffer.length = strlen (line->buffer.data); @@ -1294,75 +1294,75 @@ R_API int r_line_hist_offset_down(RLine *line) { return true; } -R_API void r_core_visual_offset(RCore *core) { +RZ_API void rz_core_visual_offset(RzCore *core) { ut64 addr, bsze, newaddr = 0LL; char buf[256]; backup_current_addr (core, &addr, &bsze, &newaddr); core->cons->line->prompt_type = R_LINE_PROMPT_OFFSET; - r_line_set_hist_callback (core->cons->line, - &r_line_hist_offset_up, - &r_line_hist_offset_down); - r_line_set_prompt ("[offset]> "); + rz_line_set_hist_callback (core->cons->line, + &rz_line_hist_offset_up, + &rz_line_hist_offset_down); + rz_line_set_prompt ("[offset]> "); strcpy (buf, "s "); - if (r_cons_fgets (buf + 2, sizeof (buf) - 2, 0, NULL) > 0) { + if (rz_cons_fgets (buf + 2, sizeof (buf) - 2, 0, NULL) > 0) { if (!strcmp (buf + 2, "g") || !strcmp (buf + 2, "G")) { __core_visual_gogo (core, buf[2]); } else { if (buf[2] == '.') { buf[1] = '.'; } - r_core_cmd0 (core, buf); + rz_core_cmd0 (core, buf); restore_current_addr (core, addr, bsze, newaddr); } } - r_line_set_hist_callback (core->cons->line, &r_line_hist_cmd_up, &r_line_hist_cmd_down); + rz_line_set_hist_callback (core->cons->line, &rz_line_hist_cmd_up, &rz_line_hist_cmd_down); core->cons->line->prompt_type = R_LINE_PROMPT_DEFAULT; } -R_API int r_core_visual_prevopsz(RCore *core, ut64 addr) { +RZ_API int rz_core_visual_prevopsz(RzCore *core, ut64 addr) { ut64 prev_addr = prevop_addr (core, addr); return addr - prev_addr; } -static void addComment(RCore *core, ut64 addr) { +static void addComment(RzCore *core, ut64 addr) { char buf[1024]; - r_cons_printf ("Enter comment for reference:\n"); - r_core_visual_showcursor (core, true); - r_cons_flush (); - r_cons_set_raw (false); - r_line_set_prompt (":> "); - r_cons_enable_mouse (false); - if (r_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { + rz_cons_printf ("Enter comment for reference:\n"); + rz_core_visual_showcursor (core, true); + rz_cons_flush (); + rz_cons_set_raw (false); + rz_line_set_prompt (":> "); + rz_cons_enable_mouse (false); + if (rz_cons_fgets (buf, sizeof (buf), 0, NULL) < 0) { buf[0] = '\0'; } - r_core_cmdf (core, "\"CC %s\"@0x%08"PFMT64x, buf, addr); - r_core_visual_showcursor (core, false); - r_cons_set_raw (true); + rz_core_cmdf (core, "\"CC %s\"@0x%08"PFMT64x, buf, addr); + rz_core_visual_showcursor (core, false); + rz_cons_set_raw (true); } -static int follow_ref(RCore *core, RList *xrefs, int choice, int xref) { - RAnalRef *refi = r_list_get_n (xrefs, choice); +static int follow_ref(RzCore *core, RzList *xrefs, int choice, int xref) { + RzAnalRef *refi = rz_list_get_n (xrefs, choice); if (refi) { if (core->print->cur_enabled) { core->print->cur = 0; } ut64 addr = refi->addr; - r_io_sundo_push (core->io, core->offset, -1); - r_core_seek (core, addr, true); + rz_io_sundo_push (core->io, core->offset, -1); + rz_core_seek (core, addr, true); return 1; } return 0; } -R_API int r_core_visual_refs(RCore *core, bool xref, bool fcnInsteadOfAddr) { +RZ_API int rz_core_visual_refs(RzCore *core, bool xref, bool fcnInsteadOfAddr) { ut64 cur_ref_addr = UT64_MAX; int ret = 0; char ch; int count = 0; - RList *xrefs = NULL; - RAnalRef *refi; - RListIter *iter; + RzList *xrefs = NULL; + RzAnalRef *refi; + RzListIter *iter; int skip = 0; int idx = 0; char cstr[32]; @@ -1373,58 +1373,58 @@ R_API int r_core_visual_refs(RCore *core, bool xref, bool fcnInsteadOfAddr) { addr += core->print->cur; } repeat: - r_list_free (xrefs); + rz_list_free (xrefs); if (xrefsMode) { - RAnalFunction *fun = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fun = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fun) { if (xref) { // function xrefs - xrefs = r_anal_xrefs_get (core->anal, addr); - //XXX xrefs = r_anal_fcn_get_xrefs (core->anal, fun); + xrefs = rz_anal_xrefs_get (core->anal, addr); + //XXX xrefs = rz_anal_fcn_get_xrefs (core->anal, fun); // this function is buggy so we must get the xrefs of the addr } else { // functon refs - xrefs = r_anal_function_get_refs (fun); + xrefs = rz_anal_function_get_refs (fun); } } else { xrefs = NULL; } } else { if (xref) { // address xrefs - xrefs = r_anal_xrefs_get (core->anal, addr); + xrefs = rz_anal_xrefs_get (core->anal, addr); } else { // address refs - xrefs = r_anal_refs_get (core->anal, addr); + xrefs = rz_anal_refs_get (core->anal, addr); } } - r_cons_clear00 (); - r_cons_gotoxy (1, 1); + rz_cons_clear00 (); + rz_cons_gotoxy (1, 1); { char *address = (core->dbg->bits & R_SYS_BITS_64) - ? r_str_newf ("0x%016"PFMT64x, addr) - : r_str_newf ("0x%08"PFMT64x, addr); - r_cons_printf ("[%s%srefs]> %s # (TAB/jk/q/?) ", + ? rz_str_newf ("0x%016"PFMT64x, addr) + : rz_str_newf ("0x%08"PFMT64x, addr); + rz_cons_printf ("[%s%srefs]> %s # (TAB/jk/q/?) ", xrefsMode? "fcn.": "addr.", xref ? "x": "", address); free (address); } - if (!xrefs || r_list_empty (xrefs)) { - r_list_free (xrefs); + if (!xrefs || rz_list_empty (xrefs)) { + rz_list_free (xrefs); xrefs = NULL; - r_cons_printf ("\n\n(no %srefs)\n", xref ? "x": ""); + rz_cons_printf ("\n\n(no %srefs)\n", xref ? "x": ""); } else { - int h, w = r_cons_get_size (&h); - bool asm_bytes = r_config_get_i (core->config, "asm.bytes"); - r_config_set_i (core->config, "asm.bytes", false); - r_core_cmd0 (core, "fd"); + int h, w = rz_cons_get_size (&h); + bool asm_bytes = rz_config_get_i (core->config, "asm.bytes"); + rz_config_set_i (core->config, "asm.bytes", false); + rz_core_cmd0 (core, "fd"); int maxcount = 9; - int rows, cols = r_cons_get_size (&rows); + int rows, cols = rz_cons_get_size (&rows); count = 0; char *dis = NULL; rows -= 4; idx = 0; ut64 curat = UT64_MAX; - r_list_foreach (xrefs, iter, refi) { + rz_list_foreach (xrefs, iter, refi) { if (idx - skip > maxcount) { - r_cons_printf ("..."); + rz_cons_printf ("..."); break; } if (!iter->n && idx < skip) { @@ -1439,14 +1439,14 @@ repeat: if (idx == skip) { cur_ref_addr = refi->addr; } - RAnalFunction *fun = r_anal_get_fcn_in (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fun = rz_anal_get_fcn_in (core->anal, refi->addr, R_ANAL_FCN_TYPE_NULL); char *name; if (fun) { name = strdup (fun->name); } else { - RFlagItem *f = r_flag_get_at (core->flags, refi->addr, true); + RzFlagItem *f = rz_flag_get_at (core->flags, refi->addr, true); if (f) { - name = r_str_newf ("%s + %d", f->name, refi->addr - f->offset); + name = rz_str_newf ("%s + %d", f->name, refi->addr - f->offset); } else { name = strdup ("unk"); } @@ -1458,44 +1458,44 @@ repeat: } else { name[0] = 0; } - char *cmt = r_core_cmd_strf (core, "CC.@0x%08"PFMT64x, refi->addr); - r_str_trim (cmt); - r_cons_printf (" %d [%s] 0x%08"PFMT64x" 0x%08"PFMT64x " %s %sref (%s) ; %s\n", + char *cmt = rz_core_cmd_strf (core, "CC.@0x%08"PFMT64x, refi->addr); + rz_str_trim (cmt); + rz_cons_printf (" %d [%s] 0x%08"PFMT64x" 0x%08"PFMT64x " %s %sref (%s) ; %s\n", idx, cstr, refi->at, refi->addr, - r_anal_xrefs_type_tostring (refi->type), + rz_anal_xrefs_type_tostring (refi->type), xref ? "x":"", name, cmt); free (cmt); free (name); if (idx == skip) { free (dis); curat = refi->addr; - char *res = r_core_cmd_strf (core, "pd 4 @ 0x%08"PFMT64x"@e:asm.flags.limit=1", refi->at); + char *res = rz_core_cmd_strf (core, "pd 4 @ 0x%08"PFMT64x"@e:asm.flags.limit=1", refi->at); // TODO: show disasm with context. not seek addr - // dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr); + // dis = rz_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr); dis = NULL; - res = r_str_appendf (res, "; ---------------------------\n"); + res = rz_str_appendf (res, "; ---------------------------\n"); switch (printMode) { case 0: - dis = r_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr); + dis = rz_core_cmd_strf (core, "pd $r-4 @ 0x%08"PFMT64x, refi->addr); break; case 1: - dis = r_core_cmd_strf (core, "pd @ 0x%08"PFMT64x"-32", refi->addr); + dis = rz_core_cmd_strf (core, "pd @ 0x%08"PFMT64x"-32", refi->addr); break; case 2: - dis = r_core_cmd_strf (core, "px @ 0x%08"PFMT64x, refi->addr); + dis = rz_core_cmd_strf (core, "px @ 0x%08"PFMT64x, refi->addr); break; case 3: - dis = r_core_cmd_strf (core, "pds @ 0x%08"PFMT64x, refi->addr); + dis = rz_core_cmd_strf (core, "pds @ 0x%08"PFMT64x, refi->addr); break; } if (dis) { - res = r_str_append (res, dis); + res = rz_str_append (res, dis); free (dis); } dis = res; } if (++count >= rows) { - r_cons_printf ("..."); + rz_cons_printf ("..."); break; } } @@ -1503,44 +1503,44 @@ repeat: } if (dis) { if (count < rows) { - r_cons_newline (); + rz_cons_newline (); } int i = count; for (; i < 9; i++) { - r_cons_newline (); + rz_cons_newline (); } /* prepare highlight */ - char *cmd = strdup (r_config_get (core->config, "scr.highlight")); - char *ats = r_str_newf ("%"PFMT64x, curat); + char *cmd = strdup (rz_config_get (core->config, "scr.highlight")); + char *ats = rz_str_newf ("%"PFMT64x, curat); if (ats && !*cmd) { - (void) r_config_set (core->config, "scr.highlight", ats); + (void) rz_config_set (core->config, "scr.highlight", ats); } /* print disasm */ - char *d = r_str_ansi_crop (dis, 0, 0, cols, rows - 9); + char *d = rz_str_ansi_crop (dis, 0, 0, cols, rows - 9); if (d) { - r_cons_printf ("%s", d); + rz_cons_printf ("%s", d); free (d); } /* flush and restore highlight */ - r_cons_flush (); - r_config_set (core->config, "scr.highlight", cmd); + rz_cons_flush (); + rz_config_set (core->config, "scr.highlight", cmd); free (ats); free (cmd); free (dis); dis = NULL; } - r_config_set_i (core->config, "asm.bytes", asm_bytes); + rz_config_set_i (core->config, "asm.bytes", asm_bytes); } - r_cons_flush (); - r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel")); - ch = r_cons_readchar (); - ch = r_cons_arrow_to_hjkl (ch); + rz_cons_flush (); + rz_cons_enable_mouse (rz_config_get_i (core->config, "scr.wheel")); + ch = rz_cons_readchar (); + ch = rz_cons_arrow_to_hjkl (ch); if (ch == ':') { - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); goto repeat; } else if (ch == '?') { - r_cons_clear00 (); - r_cons_printf ("Usage: Visual Xrefs\n" + rz_cons_clear00 (); + rz_cons_printf ("Usage: Visual Xrefs\n" " jk - select next or previous item (use arrows)\n" " JK - step 10 rows\n" " pP - rotate between various print modes\n" @@ -1552,29 +1552,29 @@ repeat: " xX - switch to refs or xrefs\n" " q - quit this view\n" " \\n - seek to this xref"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); goto repeat; } else if (ch == 9) { // TAB xrefsMode = !xrefsMode; - r_core_visual_toggle_decompiler_disasm (core, false, true); + rz_core_visual_toggle_decompiler_disasm (core, false, true); goto repeat; } else if (ch == 'p') { - r_core_visual_toggle_decompiler_disasm (core, false, true); + rz_core_visual_toggle_decompiler_disasm (core, false, true); printMode++; if (printMode > lastPrintMode) { printMode = 0; } goto repeat; } else if (ch == 'P') { - r_core_visual_toggle_decompiler_disasm (core, false, true); + rz_core_visual_toggle_decompiler_disasm (core, false, true); printMode--; if (printMode < 0) { printMode = lastPrintMode; } goto repeat; } else if (ch == '/') { - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); goto repeat; } else if (ch == 'x' || ch == '<') { xref = true; @@ -1618,7 +1618,7 @@ repeat: } else if (ch != 'q' && ch != 'Q' && ch != 'h') { goto repeat; } - r_list_free (xrefs); + rz_list_free (xrefs); return ret; } @@ -1642,57 +1642,57 @@ void SetWindow(int Width, int Height) { #endif // unnecesarily public -char *getcommapath(RCore *core) { +char *getcommapath(RzCore *core) { char *cwd; - const char *dir = r_config_get (core->config, "dir.projects"); - const char *prj = r_config_get (core->config, "prj.name"); + const char *dir = rz_config_get (core->config, "dir.projects"); + const char *prj = rz_config_get (core->config, "prj.name"); if (dir && *dir && prj && *prj) { - char *abspath = r_file_abspath (dir); + char *abspath = rz_file_abspath (dir); /* use prjdir as base directory for comma-ent files */ - cwd = r_str_newf ("%s"R_SYS_DIR "%s.d", abspath, prj); + cwd = rz_str_newf ("%s"R_SYS_DIR "%s.d", abspath, prj); free (abspath); } else { /* use cwd as base directory for comma-ent files */ - cwd = r_sys_getdir (); + cwd = rz_sys_getdir (); } return cwd; } -static void visual_comma(RCore *core) { +static void visual_comma(RzCore *core) { bool mouse_state = __holdMouseState (core); ut64 addr = core->offset + (core->print->cur_enabled? core->print->cur: 0); char *comment, *cwd, *cmtfile; - const char *prev_cmt = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); + const char *prev_cmt = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, addr); comment = prev_cmt ? strdup (prev_cmt) : NULL; - cmtfile = r_str_between (comment, ",(", ")"); + cmtfile = rz_str_between (comment, ",(", ")"); cwd = getcommapath (core); if (!cmtfile) { char *fn; - fn = r_cons_input (" "); + fn = rz_cons_input (" "); if (fn && *fn) { cmtfile = strdup (fn); if (!comment || !*comment) { - comment = r_str_newf (",(%s)", fn); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment); + comment = rz_str_newf (",(%s)", fn); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, comment); } else { // append filename in current comment - char *nc = r_str_newf ("%s ,(%s)", comment, fn); - r_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); + char *nc = rz_str_newf ("%s ,(%s)", comment, fn); + rz_meta_set_string (core->anal, R_META_TYPE_COMMENT, addr, nc); free (nc); } } free (fn); } if (cmtfile) { - char *cwf = r_str_newf ("%s"R_SYS_DIR "%s", cwd, cmtfile); - char *odata = r_file_slurp (cwf, NULL); + char *cwf = rz_str_newf ("%s"R_SYS_DIR "%s", cwd, cmtfile); + char *odata = rz_file_slurp (cwf, NULL); if (!odata) { eprintf ("Could not open '%s'.\n", cwf); free (cwf); goto beach; } - char *data = r_core_editor (core, NULL, odata); - r_file_dump (cwf, (const ut8 *) data, -1, 0); + char *data = rz_core_editor (core, NULL, odata); + rz_file_dump (cwf, (const ut8 *) data, -1, 0); free (data); free (odata); free (cwf); @@ -1701,14 +1701,14 @@ static void visual_comma(RCore *core) { } beach: free (comment); - r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel")); + rz_cons_enable_mouse (mouse_state && rz_config_get_i (core->config, "scr.wheel")); } static bool isDisasmPrint(int mode) { return (mode == R_CORE_VISUAL_MODE_PD || mode == R_CORE_VISUAL_MODE_DB); } -static void cursor_ocur(RCore *core, bool use_ocur) { +static void cursor_ocur(RzCore *core, bool use_ocur) { RPrint *p = core->print; if (use_ocur && p->ocur == -1) { p->ocur = p->cur; @@ -1717,21 +1717,21 @@ static void cursor_ocur(RCore *core, bool use_ocur) { } } -static void nextOpcode(RCore *core) { - RAnalOp *aop = r_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC); +static void nextOpcode(RzCore *core) { + RzAnalOp *aop = rz_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC); RPrint *p = core->print; if (aop) { p->cur += aop->size; - r_anal_op_free (aop); + rz_anal_op_free (aop); } else { p->cur += 4; } } -static void prevOpcode(RCore *core) { +static void prevOpcode(RzCore *core) { RPrint *p = core->print; ut64 addr, oaddr = core->offset + core->print->cur; - if (r_core_prevop_addr (core, oaddr, 1, &addr)) { + if (rz_core_prevop_addr (core, oaddr, 1, &addr)) { const int delta = oaddr - addr; p->cur -= delta; } else { @@ -1739,11 +1739,11 @@ static void prevOpcode(RCore *core) { } } -static void cursor_nextrow(RCore *core, bool use_ocur) { +static void cursor_nextrow(RzCore *core, bool use_ocur) { RPrint *p = core->print; ut32 roff, next_roff; int row, sz, delta; - RAsmOp op; + RzAsmOp op; cursor_ocur (core, use_ocur); if (PIDX == 1) { // DISASM @@ -1751,12 +1751,12 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { return; } - if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) { - p->cur += r_config_get_i (core->config, "hex.cols"); + if (PIDX == 7 || !strcmp ("prc", rz_config_get (core->config, "cmd.visual"))) { + p->cur += rz_config_get_i (core->config, "hex.cols"); return; } if (splitView) { - int w = r_config_get_i (core->config, "hex.cols"); + int w = rz_config_get_i (core->config, "hex.cols"); if (w < 1) { w = 16; } @@ -1769,14 +1769,14 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { } if (PIDX == R_CORE_VISUAL_MODE_DB) { const int cols = core->dbg->regcols; - int w = r_config_get_i (core->config, "hex.cols"); + int w = rz_config_get_i (core->config, "hex.cols"); switch (core->seltab) { case 0: if (w < 1) { w = 16; } - r_config_set_i (core->config, "stack.delta", - r_config_get_i (core->config, "stack.delta") - w); + rz_config_set_i (core->config, "stack.delta", + rz_config_get_i (core->config, "stack.delta") - w); return; case 1: p->cur += cols > 0? cols: 3; @@ -1788,13 +1788,13 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { } if (p->row_offsets) { // FIXME: cache the current row - row = r_print_row_at_off (p, p->cur); - roff = r_print_rowoff (p, row); + row = rz_print_row_at_off (p, p->cur); + roff = rz_print_rowoff (p, row); if (roff == -1) { p->cur++; return; } - next_roff = r_print_rowoff (p, row + 1); + next_roff = rz_print_rowoff (p, row + 1); if (next_roff == UT32_MAX) { p->cur++; return; @@ -1804,7 +1804,7 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { return; } if (next_roff + 32 < core->blocksize) { - sz = r_asm_disassemble (core->rasm, &op, + sz = rz_asm_disassemble (core->rasm, &op, core->block + next_roff, 32); if (sz < 1) { sz = 1; @@ -1819,7 +1819,7 @@ static void cursor_nextrow(RCore *core, bool use_ocur) { } } -static void cursor_prevrow(RCore *core, bool use_ocur) { +static void cursor_prevrow(RzCore *core, bool use_ocur) { RPrint *p = core->print; ut32 roff, prev_roff; int row; @@ -1830,14 +1830,14 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { return; } - if (PIDX == 7 || !strcmp ("prc", r_config_get (core->config, "cmd.visual"))) { - int cols = r_config_get_i (core->config, "hex.cols"); + if (PIDX == 7 || !strcmp ("prc", rz_config_get (core->config, "cmd.visual"))) { + int cols = rz_config_get_i (core->config, "hex.cols"); p->cur -= R_MAX (cols, 0); return; } if (splitView) { - int w = r_config_get_i (core->config, "hex.cols"); + int w = rz_config_get_i (core->config, "hex.cols"); if (w < 1) { w = 16; } @@ -1852,12 +1852,12 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { switch (core->seltab) { case 0: { - int w = r_config_get_i (core->config, "hex.cols"); + int w = rz_config_get_i (core->config, "hex.cols"); if (w < 1) { w = 16; } - r_config_set_i (core->config, "stack.delta", - r_config_get_i (core->config, "stack.delta") + w); + rz_config_set_i (core->config, "stack.delta", + rz_config_get_i (core->config, "stack.delta") + w); } return; case 1: @@ -1875,13 +1875,13 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { int delta, prev_sz; // FIXME: cache the current row - row = r_print_row_at_off (p, p->cur); - roff = r_print_rowoff (p, row); + row = rz_print_row_at_off (p, p->cur); + roff = rz_print_rowoff (p, row); if (roff == UT32_MAX) { p->cur--; return; } - prev_roff = row > 0? r_print_rowoff (p, row - 1): UT32_MAX; + prev_roff = row > 0? rz_print_rowoff (p, row - 1): UT32_MAX; delta = p->cur - roff; if (prev_roff == UT32_MAX) { ut64 prev_addr = prevop_addr (core, core->offset + roff); @@ -1889,10 +1889,10 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { prev_roff = 0; prev_sz = 1; } else { - RAsmOp op; + RzAsmOp op; prev_roff = 0; - r_core_seek (core, prev_addr, true); - prev_sz = r_asm_disassemble (core->rasm, &op, + rz_core_seek (core, prev_addr, true); + prev_sz = rz_asm_disassemble (core->rasm, &op, core->block, 32); } } else { @@ -1912,7 +1912,7 @@ static void cursor_prevrow(RCore *core, bool use_ocur) { } } -static void cursor_left(RCore *core, bool use_ocur) { +static void cursor_left(RzCore *core, bool use_ocur) { if (PIDX == 2) { if (core->seltab == 1) { core->print->cur--; @@ -1923,7 +1923,7 @@ static void cursor_left(RCore *core, bool use_ocur) { core->print->cur--; } -static void cursor_right(RCore *core, bool use_ocur) { +static void cursor_right(RzCore *core, bool use_ocur) { if (PIDX == 2) { if (core->seltab == 1) { core->print->cur++; @@ -1934,7 +1934,7 @@ static void cursor_right(RCore *core, bool use_ocur) { core->print->cur++; } -static bool fix_cursor(RCore *core) { +static bool fix_cursor(RzCore *core) { RPrint *p = core->print; int offscreen = (core->cons->rows - 3) * p->cols; bool res = false; @@ -1950,16 +1950,16 @@ static bool fix_cursor(RCore *core) { if ((!cur_is_visible && !is_close) || (!cur_is_visible && p->cur == 0)) { // when the cursor is not visible and it's far from the // last visible byte, just seek there. - r_core_seek_delta (core, p->cur); + rz_core_seek_delta (core, p->cur); reset_print_cur (p); } else if ((!cur_is_visible && is_close) || !off_is_visible) { - RAsmOp op; - int sz = r_asm_disassemble (core->rasm, + RzAsmOp op; + int sz = rz_asm_disassemble (core->rasm, &op, core->block, 32); if (sz < 1) { sz = 1; } - r_core_seek_delta (core, sz); + rz_core_seek_delta (core, sz); p->cur = R_MAX (p->cur - sz, 0); if (p->ocur != -1) { p->ocur = R_MAX (p->ocur - sz, 0); @@ -1967,7 +1967,7 @@ static bool fix_cursor(RCore *core) { res |= off_is_visible; } } else if (core->print->cur >= offscreen) { - r_core_seek (core, core->offset + p->cols, true); + rz_core_seek (core, core->offset + p->cols, true); p->cur -= p->cols; if (p->ocur != -1) { p->ocur -= p->cols; @@ -1977,12 +1977,12 @@ static bool fix_cursor(RCore *core) { if (p->cur < 0) { int sz = p->cols; if (isDisasmPrint (core->printidx)) { - sz = r_core_visual_prevopsz (core, core->offset + p->cur); + sz = rz_core_visual_prevopsz (core, core->offset + p->cur); if (sz < 1) { sz = 1; } } - r_core_seek_delta (core, -sz); + rz_core_seek_delta (core, -sz); p->cur += sz; if (p->ocur != -1) { p->ocur += sz; @@ -1994,17 +1994,17 @@ static bool fix_cursor(RCore *core) { static bool __ime = false; static int __nib = -1; -static bool insert_mode_enabled(RCore *core) { +static bool insert_mode_enabled(RzCore *core) { if (!__ime) { return false; } - char ch = (ut8)r_cons_readchar (); + char ch = (ut8)rz_cons_readchar (); if ((ut8)ch == KEY_ALTQ) { - (void)r_cons_readchar (); + (void)rz_cons_readchar (); __ime = false; return true; } - char arrows = r_cons_arrow_to_hjkl (ch); + char arrows = rz_cons_arrow_to_hjkl (ch); switch (ch) { case 127: core->print->cur = R_MAX (0, core->print->cur - 1); @@ -2029,7 +2029,7 @@ static bool insert_mode_enabled(RCore *core) { if (core->print->col == 2) { /* ascii column */ if (IS_PRINTABLE (ch)) { - r_core_cmdf (core, "\"w %c\" @ $$+%d", ch, core->print->cur); + rz_core_cmdf (core, "\"w %c\" @ $$+%d", ch, core->print->cur); core->print->cur++; } return true; @@ -2054,19 +2054,19 @@ static bool insert_mode_enabled(RCore *core) { case 'e': case 'f': if (__nib != -1) { - r_core_cmdf (core, "wx %c%c @ $$+%d", __nib, ch, core->print->cur); + rz_core_cmdf (core, "wx %c%c @ $$+%d", __nib, ch, core->print->cur); core->print->cur++; __nib = -1; } else { - r_core_cmdf (core, "wx %c. @ $$+%d", ch, core->print->cur); + rz_core_cmdf (core, "wx %c. @ $$+%d", ch, core->print->cur); __nib = ch; } break; case 'r': - r_core_cmdf (core, "r-1 @ 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "r-1 @ 0x%08"PFMT64x, core->offset + core->print->cur); break; case 'R': - r_core_cmdf (core, "r+1 @ 0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "r+1 @ 0x%08"PFMT64x, core->offset + core->print->cur); break; case 'h': core->print->cur = R_MAX (0, core->print->cur - 1); @@ -2085,7 +2085,7 @@ static bool insert_mode_enabled(RCore *core) { __ime = false; break; case '?': - r_cons_less_str ("\nVisual Insert Mode:\n\n" + rz_cons_less_str ("\nVisual Insert Mode:\n\n" " tab - toggle between ascii and hex columns\n" " q (or alt-q) - quit insert mode\n" "\nHex column:\n" @@ -2102,7 +2102,7 @@ static bool insert_mode_enabled(RCore *core) { return true; } -R_API void r_core_visual_browse(RCore *core, const char *input) { +RZ_API void rz_core_visual_browse(RzCore *core, const char *input) { const char *browsemsg = \ "Browse stuff:\n" "-------------\n" @@ -2136,113 +2136,113 @@ R_API void r_core_visual_browse(RCore *core, const char *input) { " : run command\n" ; for (;;) { - r_cons_clear00 (); - r_cons_printf ("%s\n", browsemsg); - r_cons_flush (); + rz_cons_clear00 (); + rz_cons_printf ("%s\n", browsemsg); + rz_cons_flush (); char ch = 0; if (input && *input) { ch = *input; input++; } else { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { case '1': - r_core_visual_bit_editor (core); + rz_core_visual_bit_editor (core); break; case 'M': - if (!r_list_empty (core->fs->roots)) { - r_core_visual_mounts (core); + if (!rz_list_empty (core->fs->roots)) { + rz_core_visual_mounts (core); } break; case 'z': // "vbz" - if (r_core_visual_view_zigns (core)) { + if (rz_core_visual_view_zigns (core)) { return; } break; case 'g': // "vbg" - if (r_core_visual_view_graph (core)) { + if (rz_core_visual_view_graph (core)) { return; } break; case 'r': // "vbr" - r_core_visual_view_rop (core); + rz_core_visual_view_rop (core); break; case 'f': // "vbf" - r_core_visual_trackflags (core); + rz_core_visual_trackflags (core); break; case 'F': // "vbF" - r_core_visual_anal (core, NULL); - // r_core_cmd0 (core, "s $(afl~...)"); + rz_core_visual_anal (core, NULL); + // rz_core_cmd0 (core, "s $(afl~...)"); break; case 'd': // "vbd" - r_core_visual_debugtraces (core, NULL); + rz_core_visual_debugtraces (core, NULL); break; case 'v': // "vbv" - r_core_visual_anal (core, "v"); + rz_core_visual_anal (core, "v"); break; case 'e': // "vbe" - r_core_visual_config (core); + rz_core_visual_config (core); break; case 'E': // "vbe" - r_core_visual_esil (core); + rz_core_visual_esil (core); break; case 'c': // "vbc" - r_core_visual_classes (core); + rz_core_visual_classes (core); break; case 'a': // "vba" - r_core_visual_anal_classes (core); + rz_core_visual_anal_classes (core); break; case 'C': // "vbC" - r_core_visual_comments (core); - //r_core_cmd0 (core, "s $(CC~...)"); + rz_core_visual_comments (core); + //rz_core_cmd0 (core, "s $(CC~...)"); break; case 't': // "vbt" - r_core_visual_types (core); + rz_core_visual_types (core); break; case 'T': // "vbT" - r_core_cmd0 (core, "eco $(eco~...)"); + rz_core_cmd0 (core, "eco $(eco~...)"); break; case 'l': // previously VT - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox not enabled\n"); } else { - if (r_cons_is_interactive ()) { - r_core_cmd0 (core, "TT"); + if (rz_cons_is_interactive ()) { + rz_core_cmd0 (core, "TT"); } } break; case 'p': - r_core_cmd0 (core, "dpt=$(dpt~[1-])"); + rz_core_cmd0 (core, "dpt=$(dpt~[1-])"); break; case 'b': - r_core_cmd0 (core, "s $(afb~...)"); + rz_core_cmd0 (core, "s $(afb~...)"); break; case 'i': // XXX ii shows index first and iiq shows no offset :( - r_core_cmd0 (core, "s $(ii~...)"); + rz_core_cmd0 (core, "s $(ii~...)"); break; case 's': - r_core_cmd0 (core, "s $(isq~...)"); + rz_core_cmd0 (core, "s $(isq~...)"); break; case 'm': - r_core_cmd0 (core, "s $(dm~...)"); + rz_core_cmd0 (core, "s $(dm~...)"); break; case 'x': - r_core_visual_refs (core, true, true); + rz_core_visual_refs (core, true, true); break; case 'X': - r_core_visual_refs (core, false, true); + rz_core_visual_refs (core, false, true); break; case 'h': // seek history - r_core_cmdf (core, "s!~..."); + rz_core_cmdf (core, "s!~..."); break; case '_': - r_core_visual_hudstuff (core); + rz_core_visual_hudstuff (core); break; case ':': - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); break; case 127: // backspace case 'q': @@ -2253,7 +2253,7 @@ R_API void r_core_visual_browse(RCore *core, const char *input) { #include "visual_tabs.inc" -static bool isNumber(RCore *core, int ch) { +static bool isNumber(RzCore *core, int ch) { if (ch > '0' && ch <= '9') { return true; } @@ -2287,31 +2287,31 @@ static int numbuf_pull(void) { return distance; } -static bool canWrite(RCore *core, ut64 addr) { - if (r_config_get_i (core->config, "io.cache")) { +static bool canWrite(RzCore *core, ut64 addr) { + if (rz_config_get_i (core->config, "io.cache")) { return true; } - RIOMap *map = r_io_map_get (core->io, addr); + RzIOMap *map = rz_io_map_get (core->io, addr); return (map && (map->perm & R_PERM_W)); } -static bool toggle_bb(RCore *core, ut64 addr) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); +static bool toggle_bb(RzCore *core, ut64 addr) { + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (fcn) { - RAnalBlock *bb = r_anal_fcn_bbget_in (core->anal, fcn, addr); + RzAnalBlock *bb = rz_anal_fcn_bbget_in (core->anal, fcn, addr); if (bb) { bb->folded = !bb->folded; } else { - r_warn_if_reached (); + rz_warn_if_reached (); } return true; } return false; } -R_API int r_core_visual_cmd(RCore *core, const char *arg) { +RZ_API int rz_core_visual_cmd(RzCore *core, const char *arg) { ut8 och = arg[0]; - RAsmOp op; + RzAsmOp op; ut64 offset = core->offset; char buf[4096]; const char *key_s; @@ -2319,14 +2319,14 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { int wheelspeed; int ch = och; if ((ut8)ch == KEY_ALTQ) { - r_cons_readchar (); + rz_cons_readchar (); ch = 'q'; } - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_arrow_to_hjkl (ch); ch = visual_nkey (core, ch); if (ch < 2) { int x, y; - if (r_cons_get_click (&x, &y)) { + if (rz_cons_get_click (&x, &y)) { if (y == 1) { if (x < 15) { ch = '_'; @@ -2351,8 +2351,8 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { return 1; } } - if (r_cons_singleton ()->mouse_event) { - wheelspeed = r_config_get_i (core->config, "scr.wheel.speed"); + if (rz_cons_singleton ()->mouse_event) { + wheelspeed = rz_config_get_i (core->config, "scr.wheel.speed"); } else { wheelspeed = 1; } @@ -2369,10 +2369,10 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (isNumber (core, ch)) { // only in disasm and debug prints.. if (isDisasmPrint (core->printidx)) { - if (r_config_get_i (core->config, "asm.hints") && (r_config_get_i (core->config, "asm.hint.jmp") - || r_config_get_i (core->config, "asm.hint.lea") || r_config_get_i (core->config, "asm.hint.emu") - || r_config_get_i (core->config, "asm.hint.call"))) { - r_core_visual_jump (core, ch); + if (rz_config_get_i (core->config, "asm.hints") && (rz_config_get_i (core->config, "asm.hint.jmp") + || rz_config_get_i (core->config, "asm.hint.lea") || rz_config_get_i (core->config, "asm.hint.emu") + || rz_config_get_i (core->config, "asm.hint.call"))) { + rz_core_visual_jump (core, ch); } else { numbuf_append (ch); } @@ -2391,13 +2391,13 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { #endif case 0x0d: // "enter" "\\n" "newline" { - RAnalOp *op; - int wheel = r_config_get_i (core->config, "scr.wheel"); + RzAnalOp *op; + int wheel = rz_config_get_i (core->config, "scr.wheel"); if (wheel) { - r_cons_enable_mouse (true); + rz_cons_enable_mouse (true); } do { - op = r_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC); + op = rz_core_anal_op (core, core->offset + core->print->cur, R_ANAL_OP_MASK_BASIC); if (op) { if (op->type == R_ANAL_OP_TYPE_JMP || op->type == R_ANAL_OP_TYPE_CJMP || @@ -2406,20 +2406,20 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->print->cur_enabled) { int delta = R_ABS ((st64) op->jump - (st64) offset); if (op->jump < core->offset || op->jump >= core->print->screen_bounds) { - r_io_sundo_push (core->io, offset, r_print_get_cursor (core->print)); - r_core_visual_seek_animation (core, op->jump); + rz_io_sundo_push (core->io, offset, rz_print_get_cursor (core->print)); + rz_core_visual_seek_animation (core, op->jump); core->print->cur = 0; } else { - r_io_sundo_push (core->io, offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, offset, rz_print_get_cursor (core->print)); core->print->cur = delta; } } else { - r_io_sundo_push (core->io, offset, 0); - r_core_visual_seek_animation (core, op->jump); + rz_io_sundo_push (core->io, offset, 0); + rz_core_visual_seek_animation (core, op->jump); } } } - r_anal_op_free (op); + rz_anal_op_free (op); } while (--wheelspeed > 0); } break; @@ -2428,7 +2428,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case 'O': // tab TAB case 9: // tab TAB - r_core_visual_toggle_decompiler_disasm (core, false, true); + rz_core_visual_toggle_decompiler_disasm (core, false, true); if (splitView) { // this split view is kind of useless imho, we should kill it or merge it into tabs core->print->cur = 0; @@ -2448,8 +2448,8 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } } else { core->seltab = 0; - ut64 f = r_config_get_i (core->config, "diff.from"); - ut64 t = r_config_get_i (core->config, "diff.to"); + ut64 f = rz_config_get_i (core->config, "diff.from"); + ut64 t = rz_config_get_i (core->config, "diff.to"); if (f == t && f == 0) { core->print->col = core->print->col == 1? 2: 1; } @@ -2468,87 +2468,87 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { ut64 addr = core->offset; if (PIDX == 2) { if (core->seltab == 0) { - addr = r_debug_reg_get (core->dbg, "SP"); + addr = rz_debug_reg_get (core->dbg, "SP"); } } if (!canWrite (core, addr)) { - r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n"); - r_cons_any_key (NULL); + rz_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n"); + rz_cons_any_key (NULL); return true; } } - r_cons_printf ("Enter assembler opcodes separated with ';':\n"); - r_core_visual_showcursor (core, true); - r_cons_flush (); - r_cons_set_raw (false); + rz_cons_printf ("Enter assembler opcodes separated with ';':\n"); + rz_core_visual_showcursor (core, true); + rz_cons_flush (); + rz_cons_set_raw (false); strcpy (buf, "\"wa "); - r_line_set_prompt (":> "); - r_cons_enable_mouse (false); - if (r_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) { + rz_line_set_prompt (":> "); + rz_cons_enable_mouse (false); + if (rz_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) { buf[0] = '\0'; } strcat (buf, "\""); - int wheel = r_config_get_i (core->config, "scr.wheel"); + int wheel = rz_config_get_i (core->config, "scr.wheel"); if (wheel) { - r_cons_enable_mouse (true); + rz_cons_enable_mouse (true); } if (*buf) { if (core->print->cur_enabled) { int t = core->offset + core->print->cur; - r_core_seek (core, t, false); + rz_core_seek (core, t, false); } - r_core_cmd (core, buf, true); + rz_core_cmd (core, buf, true); if (core->print->cur_enabled) { int t = core->offset - core->print->cur; - r_core_seek (core, t, true); + rz_core_seek (core, t, true); } } - r_core_visual_showcursor (core, false); - r_cons_set_raw (true); + rz_core_visual_showcursor (core, false); + rz_cons_set_raw (true); } break; case '=': { // TODO: edit - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); const char *buf = NULL; #define I core->cons - const char *cmd = r_config_get (core->config, "cmd.vprompt"); - r_line_set_prompt ("cmd.vprompt> "); + const char *cmd = rz_config_get (core->config, "cmd.vprompt"); + rz_line_set_prompt ("cmd.vprompt> "); I->line->contents = strdup (cmd); - buf = r_line_readline (); + buf = rz_line_readline (); I->line->contents = NULL; - (void)r_config_set (core->config, "cmd.vprompt", buf); - r_core_visual_showcursor (core, false); + (void)rz_config_set (core->config, "cmd.vprompt", buf); + rz_core_visual_showcursor (core, false); } break; case '|': { // TODO: edit - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); const char *buf = NULL; #define I core->cons - const char *cmd = r_config_get (core->config, "cmd.cprompt"); - r_line_set_prompt ("cmd.cprompt> "); + const char *cmd = rz_config_get (core->config, "cmd.cprompt"); + rz_line_set_prompt ("cmd.cprompt> "); I->line->contents = strdup (cmd); - buf = r_line_readline (); + buf = rz_line_readline (); if (buf && !strcmp (buf, "|")) { R_FREE (I->line->contents); core->print->cur_enabled = true; core->print->cur = 0; - (void)r_config_set (core->config, "cmd.cprompt", "p=e $r-2"); + (void)rz_config_set (core->config, "cmd.cprompt", "p=e $r-2"); } else { R_FREE (I->line->contents); - (void)r_config_set (core->config, "cmd.cprompt", buf? buf: ""); + (void)rz_config_set (core->config, "cmd.cprompt", buf? buf: ""); } - r_core_visual_showcursor (core, false); + rz_core_visual_showcursor (core, false); } break; case '!': - r_core_visual_panels_root (core, core->panels_root); + rz_core_visual_panels_root (core, core->panels_root); break; case 'g': - r_core_visual_showcursor (core, true); - r_core_visual_offset (core); - r_core_visual_showcursor (core, false); + rz_core_visual_showcursor (core, true); + rz_core_visual_offset (core); + rz_core_visual_showcursor (core, false); break; case 'G': __core_visual_gogo (core, 'G'); @@ -2560,13 +2560,13 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { const int occ = core->print->cur; ut64 off = oce? core->offset + core->print->cur: core->offset; core->print->cur_enabled = 0; - r_cons_enable_mouse (false); - r_core_visual_asm (core, off); + rz_cons_enable_mouse (false); + rz_core_visual_asm (core, off); core->print->cur_enabled = oce; core->print->cur = occ; core->print->ocur = oco; - if (r_config_get_i (core->config, "scr.wheel")) { - r_cons_enable_mouse (true); + if (rz_config_get_i (core->config, "scr.wheel")) { + rz_cons_enable_mouse (true); } } break; @@ -2582,31 +2582,31 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case '$': if (core->print->cur_enabled) { - r_core_cmdf (core, "dr PC=$$+%d", core->print->cur); + rz_core_cmdf (core, "dr PC=$$+%d", core->print->cur); } else { - r_core_cmd0 (core, "dr PC=$$"); + rz_core_cmd0 (core, "dr PC=$$"); } break; case '@': if (core->print->cur_enabled) { char buf[128]; prompt_read ("cursor at:", buf, sizeof (buf)); - core->print->cur = (st64) r_num_math (core->num, buf); + core->print->cur = (st64) rz_num_math (core->num, buf); } break; case 'C': if (++color > 2) { color = 0; } - r_config_set_i (core->config, "scr.color", color); + rz_config_set_i (core->config, "scr.color", color); break; case 'd': { bool mouse_state = __holdMouseState (core); - r_core_visual_showcursor (core, true); + rz_core_visual_showcursor (core, true); int distance = numbuf_pull (); - r_core_visual_define (core, arg + 1, distance - 1); - r_core_visual_showcursor (core, false); - r_cons_enable_mouse (mouse_state && r_config_get_i(core->config, "scr.wheel")); + rz_core_visual_define (core, arg + 1, distance - 1); + rz_core_visual_showcursor (core, false); + rz_cons_enable_mouse (mouse_state && rz_config_get_i(core->config, "scr.wheel")); } break; case 'D': @@ -2617,11 +2617,11 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { bool mouse_state = __holdMouseState (core); int range, min, max; char name[256], *n; - r_line_set_prompt ("flag name: "); - r_core_visual_showcursor (core, true); - if (r_cons_fgets (name, sizeof (name), 0, NULL) >= 0 && *name) { + rz_line_set_prompt ("flag name: "); + rz_core_visual_showcursor (core, true); + if (rz_cons_fgets (name, sizeof (name), 0, NULL) >= 0 && *name) { n = name; - r_str_trim (n); + rz_str_trim (n); if (core->print->ocur != -1) { min = R_MIN (core->print->cur, core->print->ocur); max = R_MAX (core->print->cur, core->print->ocur); @@ -2630,45 +2630,45 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } range = max - min + 1; if (!strcmp (n, "-")) { - r_flag_unset_off (core->flags, core->offset + core->print->cur); + rz_flag_unset_off (core->flags, core->offset + core->print->cur); } else if (*n == '.') { if (n[1] == '-') { //unset - r_core_cmdf (core, "f.-%s@0x%"PFMT64x, n + 1, core->offset + min); + rz_core_cmdf (core, "f.-%s@0x%"PFMT64x, n + 1, core->offset + min); } else { - r_core_cmdf (core, "f.%s@0x%"PFMT64x, n + 1, core->offset + min); + rz_core_cmdf (core, "f.%s@0x%"PFMT64x, n + 1, core->offset + min); } } else if (*n == '-') { if (*n) { - r_flag_unset_name (core->flags, n + 1); + rz_flag_unset_name (core->flags, n + 1); } } else { if (range < 1) { range = 1; } if (*n) { - r_flag_set (core->flags, n, + rz_flag_set (core->flags, n, core->offset + min, range); } } } - r_cons_enable_mouse (mouse_state && r_config_get_i(core->config, "scr.wheel")); + rz_cons_enable_mouse (mouse_state && rz_config_get_i(core->config, "scr.wheel")); } - r_core_visual_showcursor (core, false); + rz_core_visual_showcursor (core, false); break; case ',': visual_comma (core); break; case 't': { - r_cons_gotoxy (0, 0); + rz_cons_gotoxy (0, 0); if (core->visual.tabs) { - r_cons_printf ("[tnp:=+-] "); + rz_cons_printf ("[tnp:=+-] "); } else { - r_cons_printf ("[t] "); + rz_cons_printf ("[t] "); } - r_cons_flush(); - int ch = r_cons_readchar (); + rz_cons_flush(); + int ch = rz_cons_readchar (); if (isdigit (ch)) { visual_nthtab (core, ch - '0' - 1); } @@ -2692,10 +2692,10 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case ':': { - RCoreVisualTab *tab = visual_newtab (core); + RzCoreVisualTab *tab = visual_newtab (core); if (tab) { tab->name[0] = ':'; - r_cons_fgets (tab->name + 1, sizeof (tab->name) - 1, 0, NULL); + rz_cons_fgets (tab->name + 1, sizeof (tab->name) - 1, 0, NULL); } } break; @@ -2711,10 +2711,10 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { visual_closetab (core); break; case 'n': - r_core_seek_next (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_next (core, rz_config_get (core->config, "scr.nkey")); break; case 'N': - r_core_seek_previous (core, r_config_get (core->config, "scr.nkey")); + rz_core_seek_previous (core, rz_config_get (core->config, "scr.nkey")); break; case 'i': case 'I': @@ -2724,7 +2724,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { ut64 addr = core->offset + delta; if (PIDX == 0) { if (strstr (printfmtSingle[0], "pxb")) { - r_core_visual_define (core, "1", 1); + rz_core_visual_define (core, "1", 1); return true; } if (core->print->ocur == -1) { @@ -2734,31 +2734,31 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } } else if (PIDX == 2) { if (core->seltab == 0) { - addr = r_debug_reg_get (core->dbg, "SP") + delta; + addr = rz_debug_reg_get (core->dbg, "SP") + delta; } else if (core->seltab == 1) { char buf[128]; prompt_read ("new-reg-value> ", buf, sizeof (buf)); if (*buf) { const char *creg = core->dbg->creg; if (creg) { - r_core_cmdf (core, "dr %s = %s\n", creg, buf); + rz_core_cmdf (core, "dr %s = %s\n", creg, buf); } } return true; } } if (!canWrite (core, addr)) { - r_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n"); - r_cons_any_key (NULL); + rz_cons_printf ("\nFile has been opened in read-only mode. Use -w flag, oo+ or e io.cache=true\n"); + rz_cons_any_key (NULL); return true; } - r_core_visual_showcursor (core, true); - r_cons_flush (); - r_cons_set_raw (0); + rz_core_visual_showcursor (core, true); + rz_cons_flush (); + rz_cons_set_raw (0); if (ch == 'I') { strcpy (buf, "wow "); - r_line_set_prompt ("insert hexpair block: "); - if (r_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) { + rz_line_set_prompt ("insert hexpair block: "); + if (rz_cons_fgets (buf + 4, sizeof (buf) - 4, 0, NULL) < 0) { buf[0] = '\0'; } char *p = strdup (buf); @@ -2768,19 +2768,19 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } snprintf (buf, sizeof (buf), "%s @ $$0!%i", p, core->blocksize - cur); - r_core_cmd (core, buf, 0); + rz_core_cmd (core, buf, 0); free (p); break; } if (core->print->col == 2) { strcpy (buf, "\"w "); - r_line_set_prompt ("insert string: "); - if (r_cons_fgets (buf + 3, sizeof (buf) - 3, 0, NULL) < 0) { + rz_line_set_prompt ("insert string: "); + if (rz_cons_fgets (buf + 3, sizeof (buf) - 3, 0, NULL) < 0) { buf[0] = '\0'; } strcat (buf, "\""); } else { - r_line_set_prompt ("insert hex: "); + rz_line_set_prompt ("insert hex: "); if (core->print->ocur != -1) { int bs = R_ABS (core->print->cur - core->print->ocur) + 1; core->blocksize = bs; @@ -2788,92 +2788,92 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } else { strcpy (buf, "wx "); } - if (r_cons_fgets (buf + strlen (buf), sizeof (buf) - strlen (buf), 0, NULL) < 0) { + if (rz_cons_fgets (buf + strlen (buf), sizeof (buf) - strlen (buf), 0, NULL) < 0) { buf[0] = '\0'; } } if (core->print->cur_enabled) { - r_core_seek (core, addr, false); + rz_core_seek (core, addr, false); } - r_core_cmd (core, buf, 1); + rz_core_cmd (core, buf, 1); if (core->print->cur_enabled) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } - r_cons_set_raw (1); - r_core_visual_showcursor (core, false); - r_core_seek (core, oaddr, true); + rz_cons_set_raw (1); + rz_core_visual_showcursor (core, false); + rz_core_seek (core, oaddr, true); } break; case 'R': - if (r_config_get_i (core->config, "scr.randpal")) { - r_core_cmd0 (core, "ecr"); + if (rz_config_get_i (core->config, "scr.randpal")) { + rz_core_cmd0 (core, "ecr"); } else { - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); } break; case 'e': - r_core_visual_config (core); + rz_core_visual_config (core); break; case '^': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - r_core_seek (core, fcn->addr, false); + rz_core_seek (core, fcn->addr, false); } else { __core_visual_gogo (core, 'g'); } } break; case 'E': - r_core_visual_colors (core); + rz_core_visual_colors (core); break; case 'x': - r_core_visual_refs (core, true, false); + rz_core_visual_refs (core, true, false); break; case 'X': - r_core_visual_refs (core, false, false); + rz_core_visual_refs (core, false, false); break; case 'r': // TODO: toggle shortcut hotkeys - if (r_config_get_i (core->config, "asm.hint.call")) { - r_core_cmd0 (core, "e!asm.hint.call"); - r_core_cmd0 (core, "e asm.hint.jmp=true"); - } else if (r_config_get_i (core->config, "asm.hint.jmp")) { - r_core_cmd0 (core, "e!asm.hint.jmp"); - r_core_cmd0 (core, "e asm.hint.emu=true"); - } else if (r_config_get_i (core->config, "asm.hint.emu")) { - r_core_cmd0 (core, "e!asm.hint.emu"); - r_core_cmd0 (core, "e asm.hint.lea=true"); - } else if (r_config_get_i (core->config, "asm.hint.lea")) { - r_core_cmd0 (core, "e!asm.hint.lea"); - r_core_cmd0 (core, "e asm.hint.call=true"); + if (rz_config_get_i (core->config, "asm.hint.call")) { + rz_core_cmd0 (core, "e!asm.hint.call"); + rz_core_cmd0 (core, "e asm.hint.jmp=true"); + } else if (rz_config_get_i (core->config, "asm.hint.jmp")) { + rz_core_cmd0 (core, "e!asm.hint.jmp"); + rz_core_cmd0 (core, "e asm.hint.emu=true"); + } else if (rz_config_get_i (core->config, "asm.hint.emu")) { + rz_core_cmd0 (core, "e!asm.hint.emu"); + rz_core_cmd0 (core, "e asm.hint.lea=true"); + } else if (rz_config_get_i (core->config, "asm.hint.lea")) { + rz_core_cmd0 (core, "e!asm.hint.lea"); + rz_core_cmd0 (core, "e asm.hint.call=true"); } else { - r_core_cmd0 (core, "e asm.hint.call=true"); + rz_core_cmd0 (core, "e asm.hint.call=true"); } visual_refresh (core); break; case ' ': case 'V': - if (r_config_get_i (core->config, "graph.web")) { - r_core_cmd0 (core, "agv $$"); + if (rz_config_get_i (core->config, "graph.web")) { + rz_core_cmd0 (core, "agv $$"); } else { - RAnalFunction *fun = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); - int ocolor = r_config_get_i (core->config, "scr.color"); + RzAnalFunction *fun = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + int ocolor = rz_config_get_i (core->config, "scr.color"); if (!fun) { - r_cons_message ("Not in a function. Type 'df' to define it here"); + rz_cons_message ("Not in a function. Type 'df' to define it here"); break; - } else if (r_list_empty (fun->bbs)) { - r_cons_message ("No basic blocks in this function. You may want to use 'afb+'."); + } else if (rz_list_empty (fun->bbs)) { + rz_cons_message ("No basic blocks in this function. You may want to use 'afb+'."); break; } reset_print_cur (core->print); eprintf ("\rRendering graph..."); - r_core_visual_graph (core, NULL, NULL, true); - r_config_set_i (core->config, "scr.color", ocolor); + rz_core_visual_graph (core, NULL, NULL, true); + rz_config_set_i (core->config, "scr.color", ocolor); } break; case 'v': - r_core_visual_anal (core, NULL); + rz_core_visual_anal (core, NULL); break; case 'h': case 'l': @@ -2893,7 +2893,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (ch == 'h') { distance = -distance; } - r_core_seek_delta (core, distance); + rz_core_seek_delta (core, distance); } } break; @@ -2915,7 +2915,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (ch == 'H') { distance = -distance; } - r_core_seek_delta (core, distance * 2); + rz_core_seek_delta (core, distance * 2); } } break; @@ -2926,24 +2926,24 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { cursor_nextrow (core, false); } } else { - if (r_config_get_i (core->config, "scr.wheel.nkey")) { + if (rz_config_get_i (core->config, "scr.wheel.nkey")) { int i, distance = numbuf_pull (); if (distance < 1) { distance = 1; } for (i = 0; i < distance; i++) { - r_core_cmd0 (core, "sn"); + rz_core_cmd0 (core, "sn"); } } else { int times = R_MAX (1, wheelspeed); // Check if we have a data annotation. ut64 amisize; - RAnalMetaItem *ami = r_meta_get_at (core->anal, core->offset, R_META_TYPE_DATA, &amisize); + RzAnalMetaItem *ami = rz_meta_get_at (core->anal, core->offset, R_META_TYPE_DATA, &amisize); if (!ami) { - ami = r_meta_get_at (core->anal, core->offset, R_META_TYPE_STRING, &amisize); + ami = rz_meta_get_at (core->anal, core->offset, R_META_TYPE_STRING, &amisize); } if (ami) { - r_core_seek_delta (core, amisize); + rz_core_seek_delta (core, amisize); } else { int distance = numbuf_pull (); if (distance > 1) { @@ -2951,12 +2951,12 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } while (times--) { if (isDisasmPrint (core->printidx)) { - r_core_visual_disasm_down (core, &op, &cols); + rz_core_visual_disasm_down (core, &op, &cols); } else if (!strcmp (__core_visual_print_command (core), "prc")) { - cols = r_config_get_i (core->config, "hex.cols"); + cols = rz_config_get_i (core->config, "hex.cols"); } - r_core_seek (core, core->offset + cols, true); + rz_core_seek (core, core->offset + cols, true); } } } @@ -2974,24 +2974,24 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (isDisasmPrint (core->printidx)) { if (core->print->screen_bounds == core->offset) { ut64 addr = core->print->screen_bounds; - addr += r_asm_disassemble (core->rasm, &op, core->block, 32); + addr += rz_asm_disassemble (core->rasm, &op, core->block, 32); } if (addr == core->offset || addr == UT64_MAX) { addr = core->offset + 48; } } else { int h; - int hexCols = r_config_get_i (core->config, "hex.cols"); + int hexCols = rz_config_get_i (core->config, "hex.cols"); if (hexCols < 1) { hexCols = 16; } - (void)r_cons_get_size (&h); + (void)rz_cons_get_size (&h); int delta = hexCols * (h / 4); addr = core->offset + delta; } - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } else { - r_core_seek (core, core->offset + obs, true); + rz_core_seek (core, core->offset + obs, true); } } break; @@ -3002,13 +3002,13 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { cursor_prevrow (core, false); } } else { - if (r_config_get_i (core->config, "scr.wheel.nkey")) { + if (rz_config_get_i (core->config, "scr.wheel.nkey")) { int i, distance = numbuf_pull (); if (distance < 1) { distance = 1; } for (i = 0; i < distance; i++) { - r_core_cmd0 (core, "sp"); + rz_core_cmd0 (core, "sp"); } } else { int times = wheelspeed; @@ -3021,11 +3021,11 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } while (times--) { if (isDisasmPrint (core->printidx)) { - r_core_visual_disasm_up (core, &cols); + rz_core_visual_disasm_up (core, &cols); } else if (!strcmp (__core_visual_print_command (core), "prc")) { - cols = r_config_get_i (core->config, "hex.cols"); + cols = rz_config_get_i (core->config, "hex.cols"); } - r_core_seek_delta (core, -cols); + rz_core_seek_delta (core, -cols); } } } @@ -3040,16 +3040,16 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->print->screen_bounds > 1 && core->print->screen_bounds > core->offset) { int delta = (core->print->screen_bounds - core->offset); if (core->offset >= delta) { - r_core_seek (core, core->offset - delta, true); + rz_core_seek (core, core->offset - delta, true); } else { - r_core_seek (core, 0, true); + rz_core_seek (core, 0, true); } } else { ut64 at = (core->offset > obs)? core->offset - obs: 0; if (core->offset > obs) { - r_core_seek (core, at, true); + rz_core_seek (core, at, true); } else { - r_core_seek (core, 0, true); + rz_core_seek (core, 0, true); } } } @@ -3059,17 +3059,17 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->print->cur_enabled && (core->printidx == R_CORE_VISUAL_MODE_PD || (core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab == 2))) { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); if (cmtcol > 2) { - r_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol - 2); } } // hex column if ((core->printidx != R_CORE_VISUAL_MODE_PD && core->printidx != R_CORE_VISUAL_MODE_DB) || (core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab != 2)) { - int scrcols = r_config_get_i (core->config, "hex.cols"); + int scrcols = rz_config_get_i (core->config, "hex.cols"); if (scrcols > 1) { - r_config_set_i (core->config, "hex.cols", scrcols - 1); + rz_config_set_i (core->config, "hex.cols", scrcols - 1); } } break; @@ -3078,43 +3078,43 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->print->cur_enabled && (core->printidx == R_CORE_VISUAL_MODE_PD || (core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab == 2))) { - int cmtcol = r_config_get_i (core->config, "asm.cmt.col"); - r_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); + int cmtcol = rz_config_get_i (core->config, "asm.cmt.col"); + rz_config_set_i (core->config, "asm.cmt.col", cmtcol + 2); } // hex column if ((core->printidx != R_CORE_VISUAL_MODE_PD && core->printidx != R_CORE_VISUAL_MODE_DB) || (core->printidx == R_CORE_VISUAL_MODE_DB && core->seltab != 2)) { - int scrcols = r_config_get_i (core->config, "hex.cols"); - r_config_set_i (core->config, "hex.cols", scrcols + 1); + int scrcols = rz_config_get_i (core->config, "hex.cols"); + rz_config_set_i (core->config, "hex.cols", scrcols + 1); } break; #if 0 case 'I': - r_core_cmd (core, "dsp", 0); - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, "dsp", 0); + rz_core_cmd (core, ".dr*", 0); break; #endif case 's': - key_s = r_config_get (core->config, "key.s"); + key_s = rz_config_get (core->config, "key.s"); if (key_s && *key_s) { - r_core_cmd0 (core, key_s); + rz_core_cmd0 (core, key_s); } else { visual_single_step_in (core); } break; case 'S': - key_s = r_config_get (core->config, "key.S"); + key_s = rz_config_get (core->config, "key.S"); if (key_s && *key_s) { - r_core_cmd0 (core, key_s); + rz_core_cmd0 (core, key_s); } else { __core_visual_step_over (core); } break; case '"': - r_config_toggle (core->config, "scr.dumpcols"); + rz_config_toggle (core->config, "scr.dumpcols"); break; case 'p': - r_core_visual_toggle_decompiler_disasm (core, false, true); + rz_core_visual_toggle_decompiler_disasm (core, false, true); if (core->printidx == R_CORE_VISUAL_MODE_DB && core->print->cur_enabled) { nextPrintCommand (); } else { @@ -3137,9 +3137,9 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (autoblocksize) { obs = core->blocksize; } else { - r_core_block_size (core, obs); + rz_core_block_size (core, obs); } - r_cons_clear (); + rz_cons_clear (); } break; case 'w': @@ -3147,61 +3147,61 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case 'W': findPrevWord (core); - //r_core_cmd0 (core, "=H"); + //rz_core_cmd0 (core, "=H"); break; case 'm': { - r_cons_gotoxy (0, 0); - r_cons_printf (R_CONS_CLEAR_LINE"Set shortcut key for 0x%"PFMT64x"\n", core->offset); - r_cons_flush (); - int ch = r_cons_readchar (); - r_core_visual_mark (core, ch); + rz_cons_gotoxy (0, 0); + rz_cons_printf (R_CONS_CLEAR_LINE"Set shortcut key for 0x%"PFMT64x"\n", core->offset); + rz_cons_flush (); + int ch = rz_cons_readchar (); + rz_core_visual_mark (core, ch); } break; case 'M': { - r_cons_gotoxy (0, 0); - if (r_core_visual_mark_dump (core)) { - r_cons_printf (R_CONS_CLEAR_LINE"Remove a shortcut key from the list\n"); - r_cons_flush (); - int ch = r_cons_readchar (); - r_core_visual_mark_del (core, ch); + rz_cons_gotoxy (0, 0); + if (rz_core_visual_mark_dump (core)) { + rz_cons_printf (R_CONS_CLEAR_LINE"Remove a shortcut key from the list\n"); + rz_cons_flush (); + int ch = rz_cons_readchar (); + rz_core_visual_mark_del (core, ch); } } break; case '\'': { - r_cons_gotoxy (0, 0); - if (r_core_visual_mark_dump (core)) { - r_cons_flush (); - int ch = r_cons_readchar (); - r_core_visual_mark_seek (core, ch); + rz_cons_gotoxy (0, 0); + if (rz_core_visual_mark_dump (core)) { + rz_cons_flush (); + int ch = rz_cons_readchar (); + rz_core_visual_mark_seek (core, ch); } } break; case 'y': if (core->print->ocur == -1) { - r_core_yank (core, core->offset + core->print->cur, 1); + rz_core_yank (core, core->offset + core->print->cur, 1); } else { - r_core_yank (core, core->offset + ((core->print->ocur < core->print->cur) ? + rz_core_yank (core, core->offset + ((core->print->ocur < core->print->cur) ? core->print->ocur: core->print->cur), R_ABS (core->print->cur - core->print->ocur) + 1); } break; case 'Y': if (!core->yank_buf) { - r_cons_strcat ("Cannot paste, clipboard is empty.\n"); - r_cons_flush (); - r_cons_any_key (NULL); - r_cons_clear00 (); + rz_cons_strcat ("Cannot paste, clipboard is empty.\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); + rz_cons_clear00 (); } else { - r_core_yank_paste (core, core->offset + core->print->cur, 0); + rz_core_yank_paste (core, core->offset + core->print->cur, 0); } break; case '0': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (fcn) { - r_core_seek (core, fcn->addr, true); + rz_core_seek (core, fcn->addr, true); } } break; @@ -3211,12 +3211,12 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->seltab) { const char *creg = core->dbg->creg; if (creg) { - r_core_cmdf (core, "dr %s = %s-1\n", creg, creg); + rz_core_cmdf (core, "dr %s = %s-1\n", creg, creg); } } else { - int w = r_config_get_i (core->config, "hex.cols"); - r_config_set_i (core->config, "stack.size", - r_config_get_i (core->config, "stack.size") - w); + int w = rz_config_get_i (core->config, "hex.cols"); + rz_config_set_i (core->config, "stack.size", + rz_config_get_i (core->config, "stack.size") - w); } } else { if (core->print->ocur == -1) { @@ -3227,11 +3227,11 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { : core->print->ocur, R_ABS (core->print->ocur - core->print->cur) + 1); } - r_core_cmd (core, buf, 0); + rz_core_cmd (core, buf, 0); } } else { if (!autoblocksize) { - r_core_block_size (core, core->blocksize - 1); + rz_core_block_size (core, core->blocksize - 1); } } break; @@ -3241,12 +3241,12 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (core->seltab) { const char *creg = core->dbg->creg; if (creg) { - r_core_cmdf (core, "dr %s = %s+1\n", creg, creg); + rz_core_cmdf (core, "dr %s = %s+1\n", creg, creg); } } else { - int w = r_config_get_i (core->config, "hex.cols"); - r_config_set_i (core->config, "stack.size", - r_config_get_i (core->config, "stack.size") + w); + int w = rz_config_get_i (core->config, "hex.cols"); + rz_config_set_i (core->config, "stack.size", + rz_config_get_i (core->config, "stack.size") + w); } } else { if (core->print->ocur == -1) { @@ -3257,11 +3257,11 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { : core->print->ocur, R_ABS (core->print->ocur - core->print->cur) + 1); } - r_core_cmd (core, buf, 0); + rz_core_cmd (core, buf, 0); } } else { if (!autoblocksize) { - r_core_block_size (core, core->blocksize + 1); + rz_core_block_size (core, core->blocksize + 1); } } break; @@ -3273,29 +3273,29 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { const char *creg = core->dbg->creg; if (creg) { int delta = core->rasm->bits / 8; - r_core_cmdf (core, "dr %s = %s-%d\n", creg, creg, delta); + rz_core_cmdf (core, "dr %s = %s-%d\n", creg, creg, delta); } } else { - int w = r_config_get_i (core->config, "hex.cols"); - r_config_set_i (core->config, "stack.size", - r_config_get_i (core->config, "stack.size") - w); + int w = rz_config_get_i (core->config, "hex.cols"); + rz_config_set_i (core->config, "stack.size", + rz_config_get_i (core->config, "stack.size") - w); } } else { visual_search (core); } } else { if (autoblocksize) { - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); } else { - r_core_block_size (core, core->blocksize - cols); + rz_core_block_size (core, core->blocksize - cols); } } - r_cons_enable_mouse (mouse_state && r_config_get_i (core->config, "scr.wheel")); + rz_cons_enable_mouse (mouse_state && rz_config_get_i (core->config, "scr.wheel")); } break; case '(': snowMode = !snowMode; if (!snowMode) { - r_list_free (snows); + rz_list_free (snows); snows = NULL; } break; @@ -3304,7 +3304,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case '#': if (core->printidx == 1) { - r_core_visual_toggle_decompiler_disasm (core, false, false); + rz_core_visual_toggle_decompiler_disasm (core, false, false); } else { // do nothing for now :?, px vs pxa? } @@ -3316,25 +3316,25 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { const char *creg = core->dbg->creg; if (creg) { int delta = core->rasm->bits / 8; - r_core_cmdf (core, "dr %s = %s+%d\n", creg, creg, delta); + rz_core_cmdf (core, "dr %s = %s+%d\n", creg, creg, delta); } } else { - int w = r_config_get_i (core->config, "hex.cols"); - r_config_set_i (core->config, "stack.size", - r_config_get_i (core->config, "stack.size") + w); + int w = rz_config_get_i (core->config, "hex.cols"); + rz_config_set_i (core->config, "stack.size", + rz_config_get_i (core->config, "stack.size") + w); } } else { - r_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + core->print->cur); + rz_core_cmdf (core, "dr PC=0x%08"PFMT64x, core->offset + core->print->cur); } } else if (!autoblocksize) { - r_core_block_size (core, core->blocksize + cols); + rz_core_block_size (core, core->blocksize + cols); } break; case '>': if (core->print->cur_enabled) { if (core->print->ocur == -1) { eprintf ("No range selected. Use HJKL.\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); break; } char buf[128]; @@ -3343,11 +3343,11 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { if (buf[0]) { ut64 from = core->offset + core->print->ocur; ut64 size = R_ABS (core->print->cur - core->print->ocur) + 1; - r_core_dump (core, buf, from, size, false); + rz_core_dump (core, buf, from, size, false); } } else { - r_core_seek (core, core->offset + core->blocksize, false); - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_core_seek (core, core->offset + core->blocksize, false); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } break; case '<': // "V<" @@ -3357,7 +3357,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { prompt_read ("load from file: ", buf, sizeof (buf)); if (buf[0]) { size_t sz; - char *data = r_file_slurp (buf, &sz); + char *data = rz_file_slurp (buf, &sz); if (data) { int cur; if (core->print->ocur != -1) { @@ -3368,75 +3368,75 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { ut64 from = core->offset + cur; ut64 size = R_ABS (core->print->cur - core->print->ocur) + 1; ut64 s = R_MIN (size, (ut64)sz); - r_io_write_at (core->io, from, (const ut8*)data, s); + rz_io_write_at (core->io, from, (const ut8*)data, s); } } } else { - r_core_seek (core, core->offset - core->blocksize, false); - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_core_seek (core, core->offset - core->blocksize, false); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); } break; case '.': // "V." - r_io_sundo_push (core->io, core->offset, r_print_get_cursor (core->print)); + rz_io_sundo_push (core->io, core->offset, rz_print_get_cursor (core->print)); if (core->print->cur_enabled) { - r_config_set_i (core->config, "stack.delta", 0); - r_core_seek (core, core->offset + core->print->cur, true); + rz_config_set_i (core->config, "stack.delta", 0); + rz_core_seek (core, core->offset + core->print->cur, true); core->print->cur = 0; } else { - ut64 addr = r_debug_reg_get (core->dbg, "PC"); + ut64 addr = rz_debug_reg_get (core->dbg, "PC"); if (addr && addr != UT64_MAX) { - r_core_seek (core, addr, true); - r_core_cmdf (core, "ar `arn PC`=0x%"PFMT64x, addr); + rz_core_seek (core, addr, true); + rz_core_cmdf (core, "ar `arn PC`=0x%"PFMT64x, addr); } else { - ut64 entry = r_num_get (core->num, "entry0"); + ut64 entry = rz_num_get (core->num, "entry0"); if (!entry || entry == UT64_MAX) { - RBinObject *o = r_bin_cur_object (core->bin); - RBinSection *s = o? r_bin_get_section_at (o, addr, core->io->va): NULL; + RBinObject *o = rz_bin_cur_object (core->bin); + RBinSection *s = o? rz_bin_get_section_at (o, addr, core->io->va): NULL; if (s) { entry = s->vaddr; } else { - RIOMap *map = r_pvector_pop (&core->io->maps); + RzIOMap *map = rz_pvector_pop (&core->io->maps); if (map) { entry = map->itv.addr; } else { - entry = r_config_get_i (core->config, "bin.baddr"); + entry = rz_config_get_i (core->config, "bin.baddr"); } - r_pvector_push_front (&core->io->maps, map); + rz_pvector_push_front (&core->io->maps, map); } } if (entry != UT64_MAX) { - r_core_seek (core, entry, true); + rz_core_seek (core, entry, true); } } } break; #if 0 - case 'n': r_core_seek_delta (core, core->blocksize); break; - case 'N': r_core_seek_delta (core, 0 - (int) core->blocksize); break; + case 'n': rz_core_seek_delta (core, core->blocksize); break; + case 'N': rz_core_seek_delta (core, 0 - (int) core->blocksize); break; #endif case ':': - r_core_visual_prompt_input (core); + rz_core_visual_prompt_input (core); break; case '_': - r_core_visual_hudstuff (core); + rz_core_visual_hudstuff (core); break; case ';': - r_cons_enable_mouse (false); - r_cons_gotoxy (0, 0); - r_cons_printf ("Enter a comment: ('-' to remove, '!' to use $EDITOR)\n"); - r_core_visual_showcursor (core, true); - r_cons_flush (); - r_cons_set_raw (false); - r_line_set_prompt ("comment: "); + rz_cons_enable_mouse (false); + rz_cons_gotoxy (0, 0); + rz_cons_printf ("Enter a comment: ('-' to remove, '!' to use $EDITOR)\n"); + rz_core_visual_showcursor (core, true); + rz_cons_flush (); + rz_cons_set_raw (false); + rz_line_set_prompt ("comment: "); strcpy (buf, "\"CC "); i = strlen (buf); - if (r_cons_fgets (buf + i, sizeof (buf) - i, 0, NULL) > 0) { + if (rz_cons_fgets (buf + i, sizeof (buf) - i, 0, NULL) > 0) { ut64 addr, orig; addr = orig = core->offset; if (core->print->cur_enabled) { addr += core->print->cur; - r_core_seek (core, addr, false); - r_core_cmdf (core, "s 0x%"PFMT64x, addr); + rz_core_seek (core, addr, false); + rz_core_cmdf (core, "s 0x%"PFMT64x, addr); } if (!strcmp (buf + i, "-")) { strcpy (buf, "CC-"); @@ -3470,28 +3470,28 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } free (duped); } - r_core_cmd (core, buf, 1); + rz_core_cmd (core, buf, 1); if (core->print->cur_enabled) { - r_core_seek (core, orig, true); + rz_core_seek (core, orig, true); } } - r_cons_set_raw (true); - r_core_visual_showcursor (core, false); + rz_cons_set_raw (true); + rz_core_visual_showcursor (core, false); break; case 'b': - r_core_visual_browse (core, arg + 1); + rz_core_visual_browse (core, arg + 1); break; case 'B': { ut64 addr = core->print->cur_enabled? core->offset + core->print->cur: core->offset; - r_core_cmdf (core, "dbs 0x%08"PFMT64x, addr); + rz_core_cmdf (core, "dbs 0x%08"PFMT64x, addr); } break; case 'u': { - RIOUndos *undo = r_io_sundo (core->io, core->offset); + RzIOUndos *undo = rz_io_sundo (core->io, core->offset); if (undo) { - r_core_visual_seek_animation (core, undo->off); + rz_core_visual_seek_animation (core, undo->off); core->print->cur = undo->cursor; } else { eprintf ("Cannot undo\n"); @@ -3500,27 +3500,27 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case 'U': { - RIOUndos *undo = r_io_sundo_redo (core->io); + RzIOUndos *undo = rz_io_sundo_redo (core->io); if (undo) { - r_core_visual_seek_animation (core, undo->off); + rz_core_visual_seek_animation (core, undo->off); reset_print_cur (core->print); } } break; case 'z': { - RAnalFunction *fcn; + RzAnalFunction *fcn; if (core->print->cur_enabled) { - fcn = r_anal_get_fcn_in (core->anal, + fcn = rz_anal_get_fcn_in (core->anal, core->offset + core->print->cur, R_ANAL_FCN_TYPE_NULL); } else { - fcn = r_anal_get_fcn_in (core->anal, + fcn = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); } if (fcn) { fcn->folded = !fcn->folded; } else { - r_config_toggle (core->config, "asm.cmt.fold"); + rz_config_toggle (core->config, "asm.cmt.fold"); } } break; @@ -3542,7 +3542,7 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { break; case '?': if (visual_help (core) == '?') { - r_core_visual_hud (core); + rz_core_visual_hud (core); } break; case 0x1b: @@ -3553,51 +3553,51 @@ R_API int r_core_visual_cmd(RCore *core, const char *arg) { } numbuf_i = 0; } - r_core_block_read (core); + rz_core_block_read (core); return true; } -R_API void r_core_visual_title(RCore *core, int color) { - bool showDelta = r_config_get_i (core->config, "scr.slow"); +RZ_API void rz_core_visual_title(RzCore *core, int color) { + bool showDelta = rz_config_get_i (core->config, "scr.slow"); static ut64 oldpc = 0; const char *BEGIN = core->cons->context->pal.prompt; const char *filename; char pos[512], bar[512], pcs[32]; if (!oldpc) { - oldpc = r_debug_reg_get (core->dbg, "PC"); + oldpc = rz_debug_reg_get (core->dbg, "PC"); } /* automatic block size */ - int pc, hexcols = r_config_get_i (core->config, "hex.cols"); + int pc, hexcols = rz_config_get_i (core->config, "hex.cols"); if (autoblocksize) { switch (core->printidx) { #if 0 case R_CORE_VISUAL_MODE_PXR: // prc case R_CORE_VISUAL_MODE_PRC: // prc - r_core_block_size (core, (int)(core->cons->rows * hexcols * 3.5)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols * 3.5)); break; case R_CORE_VISUAL_MODE_PXa: // pxa case R_CORE_VISUAL_MODE_PW: // XXX pw - r_core_block_size (core, (int)(core->cons->rows * hexcols)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols)); break; case R_CORE_VISUAL_MODE_PC: // XXX pc - r_core_block_size (core, (int)(core->cons->rows * hexcols * 4)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols * 4)); break; case R_CORE_VISUAL_MODE_PXA: // pxA - r_core_block_size (core, hexcols * core->cons->rows * 8); + rz_core_block_size (core, hexcols * core->cons->rows * 8); break; #endif case R_CORE_VISUAL_MODE_PX: // x if (currentFormat == 3 || currentFormat == 9 || currentFormat == 5) { // prx - r_core_block_size (core, (int)(core->cons->rows * hexcols * 4)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols * 4)); } else if ((R_ABS (hexMode) % 3) == 0) { // prx - r_core_block_size (core, (int)(core->cons->rows * hexcols)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols)); } else { - r_core_block_size (core, (int)(core->cons->rows * hexcols * 2)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols * 2)); } break; case R_CORE_VISUAL_MODE_OV: case R_CORE_VISUAL_MODE_CD: - r_core_block_size (core, (int)(core->cons->rows * hexcols * 2)); + rz_core_block_size (core, (int)(core->cons->rows * hexcols * 2)); break; case R_CORE_VISUAL_MODE_PD: // pd case R_CORE_VISUAL_MODE_DB: // pd+dbg @@ -3613,45 +3613,45 @@ R_API void r_core_visual_title(RCore *core, int color) { bsize = new_sz; } } - r_core_block_size (core, bsize); + rz_core_block_size (core, bsize); break; } } } - if (r_config_get_i (core->config, "scr.scrollbar") == 2) { - r_core_cmd (core, "fz:", 0); + if (rz_config_get_i (core->config, "scr.scrollbar") == 2) { + rz_core_cmd (core, "fz:", 0); } - if (r_config_get_i (core->config, "cfg.debug")) { - ut64 curpc = r_debug_reg_get (core->dbg, "PC"); + if (rz_config_get_i (core->config, "cfg.debug")) { + ut64 curpc = rz_debug_reg_get (core->dbg, "PC"); if (curpc && curpc != UT64_MAX && curpc != oldpc) { // check dbg.follow here - int follow = (int) (st64) r_config_get_i (core->config, "dbg.follow"); + int follow = (int) (st64) rz_config_get_i (core->config, "dbg.follow"); if (follow > 0) { if ((curpc < core->offset) || (curpc > (core->offset + follow))) { - r_core_seek (core, curpc, true); + rz_core_seek (core, curpc, true); } } else if (follow < 0) { - r_core_seek (core, curpc + follow, true); + rz_core_seek (core, curpc + follow, true); } oldpc = curpc; } } - RIOMap *map = r_io_map_get (core->io, core->offset); - RIODesc *desc = map - ? r_io_desc_get (core->io, map->fd) - : core->file? r_io_desc_get (core->io, core->file->fd): NULL; + RzIOMap *map = rz_io_map_get (core->io, core->offset); + RzIODesc *desc = map + ? rz_io_desc_get (core->io, map->fd) + : core->file? rz_io_desc_get (core->io, core->file->fd): NULL; filename = desc? desc->name: ""; { /* get flag with delta */ ut64 addr = core->offset + (core->print->cur_enabled? core->print->cur: 0); - /* TODO: we need a helper into r_flags to do that */ - RFlagItem *f = NULL; - if (r_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS)) { - f = r_flag_get_at (core->flags, addr, showDelta); - r_flag_space_pop (core->flags); + /* TODO: we need a helper into rz_flags to do that */ + RzFlagItem *f = NULL; + if (rz_flag_space_push (core->flags, R_FLAGS_FS_SYMBOLS)) { + f = rz_flag_get_at (core->flags, addr, showDelta); + rz_flag_space_pop (core->flags); } if (!f) { - f = r_flag_get_at (core->flags, addr, showDelta); + f = rz_flag_get_at (core->flags, addr, showDelta); } if (f) { if (f->offset == addr || !f->offset) { @@ -3661,7 +3661,7 @@ R_API void r_core_visual_title(RCore *core, int color) { f->name, (int) (addr - f->offset), addr); } } else { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, addr, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); if (fcn) { int delta = addr - fcn->addr; if (delta > 0) { @@ -3682,28 +3682,28 @@ R_API void r_core_visual_title(RCore *core, int color) { } if (color) { - r_cons_strcat (BEGIN); + rz_cons_strcat (BEGIN); } - const char *cmd_visual = r_config_get (core->config, "cmd.visual"); + const char *cmd_visual = rz_config_get (core->config, "cmd.visual"); if (cmd_visual && *cmd_visual) { - r_str_ncpy (bar, cmd_visual, sizeof (bar) - 1); + rz_str_ncpy (bar, cmd_visual, sizeof (bar) - 1); bar[10] = '.'; // chop cmdfmt bar[11] = '.'; // chop cmdfmt bar[12] = 0; // chop cmdfmt } else { const char *cmd = __core_visual_print_command (core); if (cmd) { - r_str_ncpy (bar, cmd, sizeof (bar) - 1); + rz_str_ncpy (bar, cmd, sizeof (bar) - 1); bar[10] = '.'; // chop cmdfmt bar[11] = '.'; // chop cmdfmt bar[12] = 0; // chop cmdfmt } } { - ut64 sz = r_io_size (core->io); + ut64 sz = rz_io_size (core->io); ut64 pa = core->offset; { - RIOMap *map = r_io_map_get (core->io, core->offset); + RzIOMap *map = rz_io_map_get (core->io, core->offset); if (map) { pa = map->delta; } @@ -3722,10 +3722,10 @@ R_API void r_core_visual_title(RCore *core, int color) { { char *title; char *address = (core->print->wide_offsets && core->dbg->bits & R_SYS_BITS_64) - ? r_str_newf ("0x%016"PFMT64x, core->offset) - : r_str_newf ("0x%08"PFMT64x, core->offset); + ? rz_str_newf ("0x%016"PFMT64x, core->offset) + : rz_str_newf ("0x%08"PFMT64x, core->offset); if (__ime) { - title = r_str_newf ("[%s + %d> * INSERT MODE *\n", + title = rz_str_newf ("[%s + %d> * INSERT MODE *\n", address, core->print->cur); } else { char pm[32] = "[XADVC]"; @@ -3739,19 +3739,19 @@ R_API void r_core_visual_title(RCore *core, int color) { } if (core->print->cur_enabled) { if (core->print->ocur == -1) { - title = r_str_newf ("[%s *0x%08"PFMT64x" %s%d ($$+0x%x)]> %s %s\n", + title = rz_str_newf ("[%s *0x%08"PFMT64x" %s%d ($$+0x%x)]> %s %s\n", address, core->offset + core->print->cur, pm, currentFormat, core->print->cur, bar, pos); } else { - title = r_str_newf ("[%s 0x%08"PFMT64x" %s%d [0x%x..0x%x] %d]> %s %s\n", + title = rz_str_newf ("[%s 0x%08"PFMT64x" %s%d [0x%x..0x%x] %d]> %s %s\n", address, core->offset + core->print->cur, pm, currentFormat, core->print->ocur, core->print->cur, R_ABS (core->print->cur - core->print->ocur) + 1, bar, pos); } } else { - title = r_str_newf ("[%s %s%d %s%d %s]> %s %s\n", + title = rz_str_newf ("[%s %s%d %s%d %s]> %s %s\n", address, pm, currentFormat, pcs, core->blocksize, filename, bar, pos); } } @@ -3760,64 +3760,64 @@ R_API void r_core_visual_title(RCore *core, int color) { const char *kolor = core->cons->context->pal.prompt; char *tabstring = __core_visual_tab_string (core, kolor); if (tabstring) { - title = r_str_append (title, tabstring); + title = rz_str_append (title, tabstring); free (tabstring); } #if 0 // TODO: add an option to show this tab mode instead? const int curTab = core->visual.tab; - r_cons_printf ("["); + rz_cons_printf ("["); int i; for (i = 0; i < tabsCount; i++) { if (i == curTab) { - r_cons_printf ("%d", curTab + 1); + rz_cons_printf ("%d", curTab + 1); } else { - r_cons_printf ("."); + rz_cons_printf ("."); } } - r_cons_printf ("]"); - r_cons_printf ("[tab:%d/%d]", core->visual.tab, tabsCount); + rz_cons_printf ("]"); + rz_cons_printf ("[tab:%d/%d]", core->visual.tab, tabsCount); #endif } - r_cons_print (title); + rz_cons_print (title); free (title); free (address); } if (color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } } -static int visual_responsive(RCore *core) { - int h, w = r_cons_get_size (&h); - if (r_config_get_i (core->config, "scr.responsive")) { +static int visual_responsive(RzCore *core) { + int h, w = rz_cons_get_size (&h); + if (rz_config_get_i (core->config, "scr.responsive")) { if (w < 110) { - r_config_set_i (core->config, "asm.cmt.right", 0); + rz_config_set_i (core->config, "asm.cmt.right", 0); } else { - r_config_set_i (core->config, "asm.cmt.right", 1); + rz_config_set_i (core->config, "asm.cmt.right", 1); } if (w < 68) { - r_config_set_i (core->config, "hex.cols", (int)(w / 5.2)); + rz_config_set_i (core->config, "hex.cols", (int)(w / 5.2)); } else { - r_config_set_i (core->config, "hex.cols", 16); + rz_config_set_i (core->config, "hex.cols", 16); } if (w < 25) { - r_config_set_i (core->config, "asm.offset", 0); + rz_config_set_i (core->config, "asm.offset", 0); } else { - r_config_set_i (core->config, "asm.offset", 1); + rz_config_set_i (core->config, "asm.offset", 1); } if (w > 80) { - r_config_set_i (core->config, "asm.lines.width", 14); - r_config_set_i (core->config, "asm.lines.width", w - (int)(w / 1.2)); - r_config_set_i (core->config, "asm.cmt.col", w - (int)(w / 2.5)); + rz_config_set_i (core->config, "asm.lines.width", 14); + rz_config_set_i (core->config, "asm.lines.width", w - (int)(w / 1.2)); + rz_config_set_i (core->config, "asm.cmt.col", w - (int)(w / 2.5)); } else { - r_config_set_i (core->config, "asm.lines.width", 7); + rz_config_set_i (core->config, "asm.lines.width", 7); } if (w < 70) { - r_config_set_i (core->config, "asm.lines.width", 1); - r_config_set_i (core->config, "asm.bytes", 0); + rz_config_set_i (core->config, "asm.lines.width", 1); + rz_config_set_i (core->config, "asm.bytes", 0); } else { - r_config_set_i (core->config, "asm.bytes", 1); + rz_config_set_i (core->config, "asm.bytes", 1); } } return w; @@ -3825,16 +3825,16 @@ static int visual_responsive(RCore *core) { // TODO: use colors // TODO: find better name -R_API void r_core_print_scrollbar(RCore *core) { - int i, h, w = r_cons_get_size (&h); +RZ_API void rz_core_print_scrollbar(RzCore *core) { + int i, h, w = rz_cons_get_size (&h); - int scrollbar = r_config_get_i (core->config, "scr.scrollbar"); + int scrollbar = rz_config_get_i (core->config, "scr.scrollbar"); if (scrollbar == 2) { - // already handled by r_core_cmd("zf:") in visual.c + // already handled by rz_core_cmd("zf:") in visual.c return; } if (scrollbar > 2) { - r_core_print_scrollbar_bottom (core); + rz_core_print_scrollbar_bottom (core); return; } @@ -3843,185 +3843,185 @@ R_API void r_core_print_scrollbar(RCore *core) { } ut64 from = 0; ut64 to = UT64_MAX; - if (r_config_get_i (core->config, "cfg.debug")) { - from = r_num_math (core->num, "$D"); - to = r_num_math (core->num, "$D+$DD"); - } else if (r_config_get_i (core->config, "io.va")) { - from = r_num_math (core->num, "$S"); - to = r_num_math (core->num, "$S+$SS"); + if (rz_config_get_i (core->config, "cfg.debug")) { + from = rz_num_math (core->num, "$D"); + to = rz_num_math (core->num, "$D+$DD"); + } else if (rz_config_get_i (core->config, "io.va")) { + from = rz_num_math (core->num, "$S"); + to = rz_num_math (core->num, "$S+$SS"); } else { - to = r_num_math (core->num, "$s"); + to = rz_num_math (core->num, "$s"); } - char *s = r_str_newf ("[0x%08"PFMT64x"]", from); - r_cons_gotoxy (w - strlen (s) + 1, 2); - r_cons_strcat (s); + char *s = rz_str_newf ("[0x%08"PFMT64x"]", from); + rz_cons_gotoxy (w - strlen (s) + 1, 2); + rz_cons_strcat (s); free (s); ut64 block = (to - from) / h; - RList *words = r_flag_zone_barlist (core->flags, from, block, h); + RzList *words = rz_flag_zone_barlist (core->flags, from, block, h); bool hadMatch = false; for (i = 0; i < h ; i++) { - const char *word = r_list_pop_head (words); + const char *word = rz_list_pop_head (words); if (word && *word) { - r_cons_gotoxy (w - strlen (word) - 1, i + 3); - r_cons_printf ("%s>", word); + rz_cons_gotoxy (w - strlen (word) - 1, i + 3); + rz_cons_printf ("%s>", word); } - r_cons_gotoxy (w, i + 3); + rz_cons_gotoxy (w, i + 3); if (hadMatch) { - r_cons_printf ("|"); + rz_cons_printf ("|"); } else { ut64 cur = from + (block * i); ut64 nex = from + (block * (i + 1)); if (R_BETWEEN (cur, core->offset, nex)) { - r_cons_printf (Color_INVERT"|"Color_RESET); + rz_cons_printf (Color_INVERT"|"Color_RESET); hadMatch = true; } else { - r_cons_printf ("|"); + rz_cons_printf ("|"); } } } - s = r_str_newf ("[0x%08"PFMT64x"]", to); + s = rz_str_newf ("[0x%08"PFMT64x"]", to); if (s) { - r_cons_gotoxy (w - strlen (s) + 1, h + 1); - r_cons_strcat (s); + rz_cons_gotoxy (w - strlen (s) + 1, h + 1); + rz_cons_strcat (s); free (s); } - r_list_free (words); - r_cons_flush (); + rz_list_free (words); + rz_cons_flush (); } -R_API void r_core_print_scrollbar_bottom(RCore *core) { - int i, h, w = r_cons_get_size (&h); +RZ_API void rz_core_print_scrollbar_bottom(RzCore *core) { + int i, h, w = rz_cons_get_size (&h); if (w < 10 || h < 4) { return; } ut64 from = 0; ut64 to = UT64_MAX; - if (r_config_get_i (core->config, "cfg.debug")) { - from = r_num_math (core->num, "$D"); - to = r_num_math (core->num, "$D+$DD"); - } else if (r_config_get_i (core->config, "io.va")) { - from = r_num_math (core->num, "$S"); - to = r_num_math (core->num, "$S+$SS"); + if (rz_config_get_i (core->config, "cfg.debug")) { + from = rz_num_math (core->num, "$D"); + to = rz_num_math (core->num, "$D+$DD"); + } else if (rz_config_get_i (core->config, "io.va")) { + from = rz_num_math (core->num, "$S"); + to = rz_num_math (core->num, "$S+$SS"); } else { - to = r_num_math (core->num, "$s"); + to = rz_num_math (core->num, "$s"); } - char *s = r_str_newf ("[0x%08"PFMT64x"]", from); + char *s = rz_str_newf ("[0x%08"PFMT64x"]", from); int slen = strlen (s) + 1; - r_cons_gotoxy (0, h + 1); - r_cons_strcat (s); + rz_cons_gotoxy (0, h + 1); + rz_cons_strcat (s); free (s); int linew = (w - (slen * 2)) + 1; ut64 block = (to - from) / linew; - RList *words = r_flag_zone_barlist (core->flags, from, block, h); + RzList *words = rz_flag_zone_barlist (core->flags, from, block, h); bool hadMatch = false; for (i = 0; i < linew + 1; i++) { - r_cons_gotoxy (i + slen, h + 1); + rz_cons_gotoxy (i + slen, h + 1); if (hadMatch) { - r_cons_strcat ("-"); + rz_cons_strcat ("-"); } else { ut64 cur = from + (block * i); ut64 nex = from + (block * (i + 2)); if (R_BETWEEN (cur, core->offset, nex)) { - r_cons_strcat (Color_INVERT"-"Color_RESET); + rz_cons_strcat (Color_INVERT"-"Color_RESET); hadMatch = true; } else { - r_cons_strcat ("-"); + rz_cons_strcat ("-"); } } } for (i = 0; i < linew; i++) { - const char *word = r_list_pop_head (words); + const char *word = rz_list_pop_head (words); if (word && *word) { ut64 cur = from + (block * i); ut64 nex = from + (block * (i + strlen (word) + 1)); - r_cons_gotoxy (i + slen - 1, h); + rz_cons_gotoxy (i + slen - 1, h); if (R_BETWEEN (cur, core->offset, nex)) { - r_cons_printf (Color_INVERT"{%s}"Color_RESET, word); + rz_cons_printf (Color_INVERT"{%s}"Color_RESET, word); } else { - r_cons_printf ("{%s}", word); + rz_cons_printf ("{%s}", word); } } } - s = r_str_newf ("[0x%08"PFMT64x"]", to); + s = rz_str_newf ("[0x%08"PFMT64x"]", to); if (s) { - r_cons_gotoxy (linew + slen + 1, h + 1); - r_cons_strcat (s); + rz_cons_gotoxy (linew + slen + 1, h + 1); + rz_cons_strcat (s); free (s); } - r_list_free (words); - r_cons_flush (); + rz_list_free (words); + rz_cons_flush (); } -static void visual_refresh(RCore *core) { +static void visual_refresh(RzCore *core) { static ut64 oseek = UT64_MAX; const char *vi, *vcmd, *cmd_str; if (!core) { return; } - r_print_set_cursor (core->print, core->print->cur_enabled, core->print->ocur, core->print->cur); + rz_print_set_cursor (core->print, core->print->cur_enabled, core->print->ocur, core->print->cur); core->cons->blankline = true; int w = visual_responsive (core); if (autoblocksize) { - r_cons_gotoxy (0, 0); + rz_cons_gotoxy (0, 0); } else { - r_cons_clear (); + rz_cons_clear (); } - r_cons_flush (); - r_cons_print_clear (); + rz_cons_flush (); + rz_cons_print_clear (); - int hex_cols = r_config_get_i (core->config, "hex.cols"); + int hex_cols = rz_config_get_i (core->config, "hex.cols"); int split_w = 12 + 4 + hex_cols + (hex_cols * 3); bool ce = core->print->cur_enabled; - vi = r_config_get (core->config, "cmd.cprompt"); + vi = rz_config_get (core->config, "cmd.cprompt"); bool vsplit = (vi && *vi); if (vsplit) { // XXX: slow core->cons->blankline = false; { - int hex_cols = r_config_get_i (core->config, "hex.cols"); + int hex_cols = rz_config_get_i (core->config, "hex.cols"); int split_w = 12 + 4 + hex_cols + (hex_cols * 3); if (split_w > w) { // do not show column contents } else { - r_cons_printf ("[cmd.cprompt=%s]\n", vi); + rz_cons_printf ("[cmd.cprompt=%s]\n", vi); if (oseek != UT64_MAX) { - r_core_seek (core, oseek, true); + rz_core_seek (core, oseek, true); } - r_core_cmd0 (core, vi); - r_cons_column (split_w); + rz_core_cmd0 (core, vi); + rz_cons_column (split_w); if (!strncmp (vi, "p=", 2) && core->print->cur_enabled) { oseek = core->offset; core->print->cur_enabled = false; - r_core_seek (core, core->num->value, true); + rz_core_seek (core, core->num->value, true); } else { oseek = UT64_MAX; } } } - r_cons_gotoxy (0, 0); + rz_cons_gotoxy (0, 0); } - vi = r_config_get (core->config, "cmd.vprompt"); + vi = rz_config_get (core->config, "cmd.vprompt"); if (vi && *vi) { - r_core_cmd0 (core, vi); + rz_core_cmd0 (core, vi); #if 0 - char *output = r_core_cmd_str (core, vi); - r_cons_strcat_at (output, 10, 5, 20, 20); + char *output = rz_core_cmd_str (core, vi); + rz_cons_strcat_at (output, 10, 5, 20, 20); free (output); #endif } - r_core_visual_title (core, color); - vcmd = r_config_get (core->config, "cmd.visual"); + rz_core_visual_title (core, color); + vcmd = rz_config_get (core->config, "cmd.visual"); if (vcmd && *vcmd) { // disable screen bounds when it's a user-defined command // because it can cause some issues @@ -4031,7 +4031,7 @@ static void visual_refresh(RCore *core) { if (splitView) { static char debugstr[512]; const char *pxw = NULL; - int h = r_num_get (core->num, "$r"); + int h = rz_num_get (core->num, "$r"); int size = (h * 16) / 2; switch (core->printidx) { case 1: @@ -4056,17 +4056,17 @@ static void visual_refresh(RCore *core) { } if (cmd_str && *cmd_str) { if (vsplit) { - char *cmd_result = r_core_cmd_str (core, cmd_str); - cmd_result = r_str_ansi_crop (cmd_result, 0, 0, split_w, -1); - r_cons_strcat (cmd_result); + char *cmd_result = rz_core_cmd_str (core, cmd_str); + cmd_result = rz_str_ansi_crop (cmd_result, 0, 0, split_w, -1); + rz_cons_strcat (cmd_result); } else { - r_core_cmd0 (core, cmd_str); + rz_core_cmd0 (core, cmd_str); } } core->print->cur_enabled = ce; #if 0 if (core->print->screen_bounds != 1LL) { - r_cons_printf ("[0x%08"PFMT64x "..0x%08"PFMT64x "]\n", + rz_cons_printf ("[0x%08"PFMT64x "..0x%08"PFMT64x "]\n", core->offset, core->print->screen_bounds); } #endif @@ -4074,13 +4074,13 @@ static void visual_refresh(RCore *core) { /* this is why there's flickering */ if (core->print->vflush) { - r_cons_visual_flush (); + rz_cons_visual_flush (); } else { - r_cons_reset (); + rz_cons_reset (); } if (core->scr_gadgets) { - r_core_cmd0 (core, "pg"); - r_cons_flush (); + rz_core_cmd0 (core, "pg"); + rz_cons_flush (); } core->cons->blankline = false; core->cons->blankline = true; @@ -4090,46 +4090,46 @@ static void visual_refresh(RCore *core) { if (snowMode) { printSnow (core); } - if (r_config_get_i (core->config, "scr.scrollbar")) { - r_core_print_scrollbar (core); + if (rz_config_get_i (core->config, "scr.scrollbar")) { + rz_core_print_scrollbar (core); } } -static void visual_refresh_oneshot(RCore *core) { - r_core_task_enqueue_oneshot (&core->tasks, (RCoreTaskOneShot) visual_refresh, core); +static void visual_refresh_oneshot(RzCore *core) { + rz_core_task_enqueue_oneshot (&core->tasks, (RzCoreTaskOneShot) visual_refresh, core); } -R_API void r_core_visual_disasm_up(RCore *core, int *cols) { - RAnalFunction *f = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); +RZ_API void rz_core_visual_disasm_up(RzCore *core, int *cols) { + RzAnalFunction *f = rz_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (f && f->folded) { *cols = core->offset - f->addr; // + f->size; if (*cols < 1) { *cols = 4; } } else { - *cols = r_core_visual_prevopsz (core, core->offset); + *cols = rz_core_visual_prevopsz (core, core->offset); } } -R_API void r_core_visual_disasm_down(RCore *core, RAsmOp *op, int *cols) { - int midflags = r_config_get_i (core->config, "asm.flags.middle"); - const bool midbb = r_config_get_i (core->config, "asm.bb.middle"); - RAnalFunction *f = NULL; - f = r_anal_get_fcn_in (core->anal, core->offset, 0); +RZ_API void rz_core_visual_disasm_down(RzCore *core, RzAsmOp *op, int *cols) { + int midflags = rz_config_get_i (core->config, "asm.flags.middle"); + const bool midbb = rz_config_get_i (core->config, "asm.bb.middle"); + RzAnalFunction *f = NULL; + f = rz_anal_get_fcn_in (core->anal, core->offset, 0); op->size = 1; if (f && f->folded) { - *cols = core->offset - r_anal_function_max_addr (f); + *cols = core->offset - rz_anal_function_max_addr (f); } else { - r_asm_set_pc (core->rasm, core->offset); - *cols = r_asm_disassemble (core->rasm, + rz_asm_set_pc (core->rasm, core->offset); + *cols = rz_asm_disassemble (core->rasm, op, core->block, 32); if (midflags || midbb) { int skip_bytes_flag = 0, skip_bytes_bb = 0; if (midflags >= R_MIDFLAGS_REALIGN) { - skip_bytes_flag = r_core_flag_in_middle (core, core->offset, *cols, &midflags); + skip_bytes_flag = rz_core_flag_in_middle (core, core->offset, *cols, &midflags); } if (midbb) { - skip_bytes_bb = r_core_bb_starts_in_middle (core, core->offset, *cols); + skip_bytes_bb = rz_core_bb_starts_in_middle (core, core->offset, *cols); } if (skip_bytes_flag) { *cols = skip_bytes_flag; @@ -4146,17 +4146,17 @@ R_API void r_core_visual_disasm_down(RCore *core, RAsmOp *op, int *cols) { #ifdef __WINDOWS__ -static bool is_mintty(RCons *cons) { +static bool is_mintty(RzCons *cons) { return cons->term_xterm; } static void flush_stdin(void) { - while (r_cons_readchar_timeout (1) != -1) ; + while (rz_cons_readchar_timeout (1) != -1) ; } #else -static bool is_mintty(RCons *cons) { +static bool is_mintty(RzCons *cons) { return false; } @@ -4166,7 +4166,7 @@ static void flush_stdin(void) { #endif -R_API int r_core_visual(RCore *core, const char *input) { +RZ_API int rz_core_visual(RzCore *core, const char *input) { const char *teefile; ut64 scrseek; int flags, ch; @@ -4177,25 +4177,25 @@ R_API int r_core_visual(RCore *core, const char *input) { splitPtr = UT64_MAX; - if (r_cons_get_size (&ch) < 1 || ch < 1) { + if (rz_cons_get_size (&ch) < 1 || ch < 1) { eprintf ("Cannot create Visual context. Use scr.fix_{columns|rows}\n"); return 0; } obs = core->blocksize; - //r_cons_set_cup (true); + //rz_cons_set_cup (true); core->vmode = false; /* honor vim */ if (!strncmp (input, "im", 2)) { - char *cmd = r_str_newf ("!v%s", input); - int ret = r_core_cmd0 (core, cmd); + char *cmd = rz_str_newf ("!v%s", input); + int ret = rz_core_cmd0 (core, cmd); free (cmd); return ret; } while (*input) { int len = *input == 'd'? 2: 1; - if (!r_core_visual_cmd (core, input)) { + if (!rz_core_visual_cmd (core, input)) { return 0; } input += len; @@ -4203,27 +4203,27 @@ R_API int r_core_visual(RCore *core, const char *input) { core->vmode = true; // disable tee in cons - teefile = r_cons_singleton ()->teefile; - r_cons_singleton ()->teefile = ""; + teefile = rz_cons_singleton ()->teefile; + rz_cons_singleton ()->teefile = ""; static char debugstr[512]; core->print->flags |= R_PRINT_FLAGS_ADDRMOD; do { dodo: - r_core_visual_tab_update (core); + rz_core_visual_tab_update (core); // update the cursor when it's not visible anymore skip = fix_cursor (core); - r_cons_show_cursor (false); - r_cons_set_raw (1); - const int ref = r_config_get_i (core->config, "dbg.slow"); + rz_cons_show_cursor (false); + rz_cons_set_raw (1); + const int ref = rz_config_get_i (core->config, "dbg.slow"); #if 1 // This is why multiple debug views dont work if (core->printidx == R_CORE_VISUAL_MODE_DB) { - const int pxa = r_config_get_i (core->config, "stack.anotated"); // stack.anotated - const char *reg = r_config_get (core->config, "stack.reg"); - const int size = r_config_get_i (core->config, "stack.size"); - const int delta = r_config_get_i (core->config, "stack.delta"); - const char *cmdvhex = r_config_get (core->config, "cmd.stack"); + const int pxa = rz_config_get_i (core->config, "stack.anotated"); // stack.anotated + const char *reg = rz_config_get (core->config, "stack.reg"); + const int size = rz_config_get_i (core->config, "stack.size"); + const int delta = rz_config_get_i (core->config, "stack.delta"); + const char *cmdvhex = rz_config_get (core->config, "cmd.stack"); if (cmdvhex && *cmdvhex) { snprintf (debugstr, sizeof (debugstr), @@ -4245,31 +4245,31 @@ dodo: printfmtSingle[2] = debugstr; } #endif - r_cons_show_cursor (false); - r_cons_enable_mouse (r_config_get_i (core->config, "scr.wheel")); + rz_cons_show_cursor (false); + rz_cons_enable_mouse (rz_config_get_i (core->config, "scr.wheel")); core->cons->event_resize = NULL; // avoid running old event with new data core->cons->event_data = core; - core->cons->event_resize = (RConsEvent) visual_refresh_oneshot; + core->cons->event_resize = (RzConsEvent) visual_refresh_oneshot; flags = core->print->flags; - color = r_config_get_i (core->config, "scr.color"); + color = rz_config_get_i (core->config, "scr.color"); if (color) { flags |= R_PRINT_FLAGS_COLOR; } - debug = r_config_get_i (core->config, "cfg.debug"); + debug = rz_config_get_i (core->config, "cfg.debug"); flags |= R_PRINT_FLAGS_ADDRMOD | R_PRINT_FLAGS_HEADER; - r_print_set_flags (core->print, flags); - scrseek = r_num_math (core->num, - r_config_get (core->config, "scr.seek")); + rz_print_set_flags (core->print, flags); + scrseek = rz_num_math (core->num, + rz_config_get (core->config, "scr.seek")); if (scrseek != 0LL) { - r_core_seek (core, scrseek, true); + rz_core_seek (core, scrseek, true); } if (debug) { - r_core_cmd (core, ".dr*", 0); + rz_core_cmd (core, ".dr*", 0); } #if 0 - cmdprompt = r_config_get (core->config, "cmd.vprompt"); + cmdprompt = rz_config_get (core->config, "cmd.vprompt"); if (cmdprompt && *cmdprompt) { - r_core_cmd (core, cmdprompt, 0); + rz_core_cmd (core, cmdprompt, 0); } #endif core->print->vflush = !skip; @@ -4279,13 +4279,13 @@ dodo: } if (!skip) { if (snowMode) { - ch = r_cons_readchar_timeout (300); + ch = rz_cons_readchar_timeout (300); if (ch == -1) { skip = 1; continue; } } else { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } if (I->vtmode == 2 && !is_mintty (core->cons)) { // Prevent runaway scrolling @@ -4294,9 +4294,9 @@ dodo: } else if (ch == 0x1b) { char chrs[2]; int chrs_read = 1; - chrs[0] = r_cons_readchar (); + chrs[0] = rz_cons_readchar (); if (chrs[0] == '[') { - chrs[1] = r_cons_readchar (); + chrs[1] = rz_cons_readchar (); chrs_read++; if (chrs[1] >= 'A' && chrs[1] <= 'D') { // arrow keys flush_stdin (); @@ -4304,47 +4304,47 @@ dodo: // Following seems to fix an issue where scrolling slows // down to a crawl for some terminals after some time // mashing the up and down arrow keys - r_cons_set_raw (false); - r_cons_set_raw (true); + rz_cons_set_raw (false); + rz_cons_set_raw (true); #endif } } - (void)r_cons_readpush (chrs, chrs_read); + (void)rz_cons_readpush (chrs, chrs_read); } } - if (r_cons_is_breaked()) { + if (rz_cons_is_breaked()) { break; } - r_core_visual_show_char (core, ch); + rz_core_visual_show_char (core, ch); if (ch == -1 || ch == 4) { break; // error or eof } arg[0] = ch; arg[1] = 0; } - } while (skip || (*arg && r_core_visual_cmd (core, arg))); + } while (skip || (*arg && rz_core_visual_cmd (core, arg))); - r_cons_enable_mouse (false); + rz_cons_enable_mouse (false); if (color) { - r_cons_strcat (Color_RESET); + rz_cons_strcat (Color_RESET); } - r_config_set_i (core->config, "scr.color", color); + rz_config_set_i (core->config, "scr.color", color); core->print->cur_enabled = false; if (autoblocksize) { - r_core_block_size (core, obs); + rz_core_block_size (core, obs); } - r_cons_singleton ()->teefile = teefile; - r_cons_set_cup (false); - r_cons_clear00 (); + rz_cons_singleton ()->teefile = teefile; + rz_cons_set_cup (false); + rz_cons_clear00 (); core->vmode = false; core->cons->event_resize = NULL; core->cons->event_data = NULL; - r_cons_show_cursor (true); + rz_cons_show_cursor (true); return 0; } -R_API RListInfo *r_listinfo_new(const char *name, RInterval pitv, RInterval vitv, int perm, const char *extra) { - RListInfo *info = R_NEW (RListInfo); +RZ_API RzListInfo *rz_listinfo_new(const char *name, RInterval pitv, RInterval vitv, int perm, const char *extra) { + RzListInfo *info = R_NEW (RzListInfo); if (info) { info->name = name ? strdup (name) : NULL; info->pitv = pitv; @@ -4355,7 +4355,7 @@ R_API RListInfo *r_listinfo_new(const char *name, RInterval pitv, RInterval vitv return info; } -R_API void r_listinfo_free (RListInfo *info) { +RZ_API void rz_listinfo_free (RzListInfo *info) { if (!info) { return; } diff --git a/librz/core/visual_tabs.inc b/librz/core/visual_tabs.inc new file mode 100644 index 0000000000..52c5aaeedf --- /dev/null +++ b/librz/core/visual_tabs.inc @@ -0,0 +1,222 @@ + +static void rz_core_visual_tab_free (RzCoreVisualTab *tab) { + free (tab); +} + +static int __core_visual_tab_count (RzCore *core) { + return core->visual.tabs? rz_list_length (core->visual.tabs): 0; +} + +static char *__core_visual_tab_string(RzCore *core, const char *kolor) { + int hex_cols = rz_config_get_i (core->config, "hex.cols"); + int scr_color = rz_config_get_i (core->config, "scr.color"); + if (hex_cols < 4) { + return strdup (""); + } + int i = 0; + char *str = NULL; + int tabs = rz_list_length (core->visual.tabs); + if (scr_color > 0) { + // TODO: use theme + if (tabs > 0) { + str = rz_str_appendf (str, "%s-+__", kolor); + } + for (i = 0; i < tabs;i++) { + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, i); + const char *name = (tab && *tab->name)? tab->name: NULL; + if (i == core->visual.tab) { + str = rz_str_appendf (str, Color_WHITE"_/ %s \\_%s", name? name: "t=", kolor); + } else { + str = rz_str_appendf (str, "_%s(%d)_", name?name: "", i+ 1); + } + } + } else { + if (tabs > 0) { + str = rz_str_append (str, "___"); + } + for (i = 0;i < tabs; i++) { + const char *name = NULL; + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, i); + if (tab && *tab->name) { + name = tab->name; + } + if (i==core->visual.tab) { + str = rz_str_appendf (str, "_/ %d:%s \\_", i + 1, name? name: "'="); + } else { + str = rz_str_appendf (str, "_(t%d%s%s)__", i + 1, name?":":"", name?name: ""); + } + } + } + if (str) { + int n = 79 - rz_str_ansi_len (str); + if (n > 0) { + str = rz_str_append (str, rz_str_pad ('_', n)); + } + str = rz_str_append (str, "\n"Color_RESET); + } + return str; +} + +static void visual_tabset(RzCore *core, RzCoreVisualTab *tab) { + rz_return_if_fail (core && tab); + + rz_core_seek (core, tab->offset, true); + core->printidx = tab->printidx; + core->print->cur_enabled = tab->cur_enabled; + core->print->cur = tab->cur; + core->print->ocur = tab->ocur; + disMode = tab->disMode; + hexMode = tab->hexMode; + printMode = tab->printMode; + current3format = tab->current3format; + current4format = tab->current4format; + current5format = tab->current5format; + rz_core_visual_applyDisMode (core, disMode); + rz_core_visual_applyHexMode (core, hexMode); + rz_config_set_i (core->config, "asm.offset", tab->asm_offset); + rz_config_set_i (core->config, "asm.instr", tab->asm_instr); + rz_config_set_i (core->config, "asm.bytes", tab->asm_bytes); + rz_config_set_i (core->config, "asm.indent", tab->asm_indent); + rz_config_set_i (core->config, "asm.cmt.col", tab->asm_cmt_col); + rz_config_set_i (core->config, "hex.cols", tab->cols); + rz_config_set_i (core->config, "scr.dumpcols", tab->dumpCols); + printfmtSingle[0] = printHexFormats[R_ABS(hexMode) % PRINT_HEX_FORMATS]; + printfmtSingle[2] = print3Formats[R_ABS(current3format) % PRINT_3_FORMATS]; + printfmtSingle[3] = print4Formats[R_ABS(current4format) % PRINT_4_FORMATS]; + printfmtSingle[4] = print5Formats[R_ABS(current5format) % PRINT_5_FORMATS]; +} + +static void visual_tabget(RzCore *core, RzCoreVisualTab *tab) { + rz_return_if_fail (core && tab); + + tab->offset = core->offset; + tab->printidx = core->printidx; + tab->asm_offset = rz_config_get_i (core->config, "asm.offset"); + tab->asm_instr = rz_config_get_i (core->config, "asm.instr"); + tab->asm_indent = rz_config_get_i (core->config, "asm.indent"); + tab->asm_bytes = rz_config_get_i (core->config, "asm.bytes"); + tab->asm_cmt_col = rz_config_get_i (core->config, "asm.cmt.col"); + tab->cur_enabled = core->print->cur_enabled; + tab->cur = core->print->cur; + tab->ocur = core->print->ocur; + tab->cols = rz_config_get_i (core->config, "hex.cols"); + tab->dumpCols = rz_config_get_i (core->config, "scr.dumpcols"); + tab->disMode = disMode; + tab->hexMode = hexMode; + tab->printMode = printMode; + tab->current3format = current3format; + tab->current4format = current4format; + tab->current5format = current5format; + // tab->cols = core->print->cols; +} + +static RzCoreVisualTab *rz_core_visual_tab_new(RzCore *core) { + RzCoreVisualTab *tab = R_NEW0 (RzCoreVisualTab); + if (tab) { + visual_tabget (core, tab); + } + return tab; +} + +static void rz_core_visual_tab_update(RzCore *core) { + if (!core->visual.tabs) { + return; + } + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + visual_tabget (core, tab); + } +} + +static RzCoreVisualTab *visual_newtab (RzCore *core) { + if (!core->visual.tabs) { + core->visual.tabs = rz_list_newf ((RzListFree)rz_core_visual_tab_free); + if (!core->visual.tabs) { + return NULL; + } + core->visual.tab = -1; + visual_newtab (core); + } + core->visual.tab++; + RzCoreVisualTab *tab = rz_core_visual_tab_new (core); + if (tab) { + rz_list_append (core->visual.tabs, tab); + visual_tabset (core, tab); + } + return tab; +} + +static void visual_nthtab (RzCore *core, int n) { + if (!core->visual.tabs || n < 0 || n >= rz_list_length (core->visual.tabs)) { + return; + } + core->visual.tab = n; + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + visual_tabset (core, tab); + } +} + +static void visual_tabname (RzCore *core) { + if (!core->visual.tabs) { + return; + } + char name[32]={0}; + prompt_read ("tab name: ", name, sizeof (name)); + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + strcpy (tab->name, name); + } +} + +static void visual_nexttab (RzCore *core) { + if (!core->visual.tabs) { + return; + } + if (core->visual.tab >= rz_list_length (core->visual.tabs) - 1) { + core->visual.tab = -1; + } + core->visual.tab++; + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + visual_tabset (core, tab); + } +} + +static void visual_prevtab (RzCore *core) { + if (!core->visual.tabs) { + return; + } + if (core->visual.tab < 1) { + core->visual.tab = rz_list_length (core->visual.tabs) - 1; + } else { + core->visual.tab--; + } + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + visual_tabset (core, tab); + } +} + +static void visual_closetab (RzCore *core) { + if (!core->visual.tabs) { + return; + } + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + rz_list_delete_data (core->visual.tabs, tab); + const int tabsCount = rz_list_length (core->visual.tabs); + if (tabsCount > 0) { + if (core->visual.tab > 0) { + core->visual.tab--; + } + RzCoreVisualTab *tab = rz_list_get_n (core->visual.tabs, core->visual.tab); + if (tab) { + visual_tabset(core, tab); + } + } else { + rz_list_free (core->visual.tabs); + core->visual.tabs = NULL; + } + } +} diff --git a/librz/core/vmarks.c b/librz/core/vmarks.c new file mode 100644 index 0000000000..b1ce0518bd --- /dev/null +++ b/librz/core/vmarks.c @@ -0,0 +1,58 @@ +/* radare - LGPL - Copyright 2009-2020 - pancake */ + +#include + + +RZ_API void rz_core_visual_mark_reset(RzCore *core) { + size_t i; + for (i = 0; i < UT8_MAX; i++) { + core->marks[i] = UT64_MAX; + } + core->marks_init = true; +} + +RZ_API bool rz_core_visual_mark_dump(RzCore *core) { + size_t i; + if (!core->marks_init) { + return false; + } + bool res = false; + for (i = 0; i < UT8_MAX; i++) { + if (core->marks[i] != UT64_MAX) { + if (i > ASCII_MAX) { + rz_cons_printf ("fV %d 0x%"PFMT64x"\n", i - ASCII_MAX - 1, core->marks[i]); + } else { + rz_cons_printf ("fV %c 0x%"PFMT64x"\n", i, core->marks[i]); + } + res = true; + } + } + return res; +} + +RZ_API void rz_core_visual_mark_set(RzCore *core, ut8 ch, ut64 addr) { + if (!core->marks_init) { + rz_core_visual_mark_reset (core); + } + core->marks[ch] = addr; +} + +RZ_API void rz_core_visual_mark_del(RzCore *core, ut8 ch) { + if (!core->marks_init) { + return; + } + core->marks[ch] = UT64_MAX; +} + +RZ_API void rz_core_visual_mark(RzCore *core, ut8 ch) { + if (IS_DIGIT (ch)) { + ch += ASCII_MAX + 1; + } + rz_core_visual_mark_set (core, ch, core->offset); +} + +RZ_API void rz_core_visual_mark_seek(RzCore *core, ut8 ch) { + if (core->marks_init && core->marks[ch] != UT64_MAX) { + rz_core_seek (core, core->marks[ch], true); + } +} diff --git a/libr/core/vmenus.c b/librz/core/vmenus.c similarity index 55% rename from libr/core/vmenus.c rename to librz/core/vmenus.c index 4886ff2b26..1b8eb7cf64 100644 --- a/libr/core/vmenus.c +++ b/librz/core/vmenus.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #include #define MAX_FORMAT 3 @@ -20,54 +20,54 @@ enum { }; typedef struct { - RCore *core; + RzCore *core; int t_idx; int t_ctr; const char *type; char *curname; char *curfmt; const char *optword; -} RCoreVisualTypes; +} RzCoreVisualTypes; -// TODO: move this helper into r_cons +// TODO: move this helper into rz_cons static char *prompt(const char *str, const char *txt) { char cmd[1024]; char *res = NULL; - char *oprompt = strdup (r_cons_singleton ()->line->prompt); - r_cons_show_cursor (true); + char *oprompt = strdup (rz_cons_singleton ()->line->prompt); + rz_cons_show_cursor (true); if (txt && *txt) { - free (r_cons_singleton ()->line->contents); - r_cons_singleton ()->line->contents = strdup (txt); + free (rz_cons_singleton ()->line->contents); + rz_cons_singleton ()->line->contents = strdup (txt); } else { - R_FREE (r_cons_singleton ()->line->contents); + R_FREE (rz_cons_singleton ()->line->contents); } *cmd = '\0'; - r_line_set_prompt (str); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (str); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { *cmd = '\0'; } //line[strlen(line)-1]='\0'; if (*cmd) { res = strdup (cmd); } - r_line_set_prompt (oprompt); + rz_line_set_prompt (oprompt); free (oprompt); - R_FREE (r_cons_singleton ()->line->contents); + R_FREE (rz_cons_singleton ()->line->contents); return res; } -static inline char *getformat (RCoreVisualTypes *vt, const char *k) { +static inline char *getformat (RzCoreVisualTypes *vt, const char *k) { return sdb_get (vt->core->anal->sdb_types, sdb_fmt ("type.%s", k), 0); } -static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype, ut64 addr) { +static char *colorize_asm_string(RzCore *core, const char *buf_asm, int optype, ut64 addr) { char *tmp, *spacer = NULL; char *source = (char*)buf_asm; bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; const char *color_num = core->cons->context->pal.num; const char *color_reg = core->cons->context->pal.reg; - RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction* fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); if (!use_color) { return strdup (source); @@ -75,11 +75,11 @@ static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype, u // workaround dummy colorizer in case of paired commands (tms320 & friends) spacer = strstr (source, "||"); if (spacer) { - char *s1 = r_str_ndup (source, spacer - source); + char *s1 = rz_str_ndup (source, spacer - source); char *s2 = strdup (spacer + 2); - char *scol1 = r_print_colorize_opcode (core->print, s1, color_reg, color_num, false, fcn ? fcn->addr : 0); - char *scol2 = r_print_colorize_opcode (core->print, s2, color_reg, color_num, false, fcn ? fcn->addr : 0); - char *source = r_str_newf ("%s||%s", r_str_get2 (scol1), r_str_get2 (scol2)); + char *scol1 = rz_print_colorize_opcode (core->print, s1, color_reg, color_num, false, fcn ? fcn->addr : 0); + char *scol2 = rz_print_colorize_opcode (core->print, s2, color_reg, color_num, false, fcn ? fcn->addr : 0); + char *source = rz_str_newf ("%s||%s", rz_str_get2 (scol1), rz_str_get2 (scol2)); free (scol1); free (scol2); free (s1); @@ -87,9 +87,9 @@ static char *colorize_asm_string(RCore *core, const char *buf_asm, int optype, u return source; } char *res = strdup (""); - res = r_str_append (res, r_print_color_op_type (core->print, optype)); - tmp = r_print_colorize_opcode (core->print, source, color_reg, color_num, false, fcn ? fcn->addr : 0); - res = r_str_append (res, tmp); + res = rz_str_append (res, rz_print_color_op_type (core->print, optype)); + tmp = rz_print_colorize_opcode (core->print, source, color_reg, color_num, false, fcn ? fcn->addr : 0); + res = rz_str_append (res, tmp); free (tmp); return res; } @@ -121,72 +121,72 @@ static int wordpos(const char *esil, int n) { return (size_t)(w - esil); } -static void showreg(RAnalEsil *esil, const char *rn, const char *desc) { +static void showreg(RzAnalEsil *esil, const char *rn, const char *desc) { ut64 nm = 0; int sz = 0; - r_cons_printf ("%s 0x%08"PFMT64x" (%d) ; %s\n", rn, nm, sz, desc); + rz_cons_printf ("%s 0x%08"PFMT64x" (%d) ; %s\n", rn, nm, sz, desc); } -R_API bool r_core_visual_esil(RCore *core) { +RZ_API bool rz_core_visual_esil(RzCore *core) { const int nbits = sizeof (ut64) * 8; int analopType; char *word = NULL; int x = 0; - RAsmOp asmop; - RAnalOp analop; + RzAsmOp asmop; + RzAnalOp analop; ut8 buf[sizeof (ut64)]; - unsigned int addrsize = r_config_get_i (core->config, "esil.addr.size"); + unsigned int addrsize = rz_config_get_i (core->config, "esil.addr.size"); if (core->blocksize < sizeof (ut64)) { return false; } memcpy (buf, core->block, sizeof (ut64)); - RAnalEsil *esil = r_anal_esil_new (20, 0, addrsize); + RzAnalEsil *esil = rz_anal_esil_new (20, 0, addrsize); esil->anal = core->anal; - r_anal_esil_set_pc (esil, core->offset); + rz_anal_esil_set_pc (esil, core->offset); for (;;) { - r_cons_clear00 (); + rz_cons_clear00 (); // bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - (void) r_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64)); + (void) rz_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64)); analop.type = -1; - (void)r_anal_op (core->anal, &analop, core->offset, buf, sizeof (ut64), R_ANAL_OP_MASK_ESIL); + (void)rz_anal_op (core->anal, &analop, core->offset, buf, sizeof (ut64), R_ANAL_OP_MASK_ESIL); analopType = analop.type & R_ANAL_OP_TYPE_MASK; - r_cons_printf ("r2's esil debugger:\n\n"); - r_cons_printf ("pos: %d\n", x); + rz_cons_printf ("r2's esil debugger:\n\n"); + rz_cons_printf ("pos: %d\n", x); { - char *op_hex = r_asm_op_get_hex (&asmop); - char *res = r_print_hexpair (core->print, op_hex, -1); - r_cons_printf ("hex: %s\n"Color_RESET, res); + char *op_hex = rz_asm_op_get_hex (&asmop); + char *res = rz_print_hexpair (core->print, op_hex, -1); + rz_cons_printf ("hex: %s\n"Color_RESET, res); free (res); free (op_hex); } { - char *op = colorize_asm_string (core, r_asm_op_get_asm (&asmop), analopType, core->offset); - r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op); + char *op = colorize_asm_string (core, rz_asm_op_get_asm (&asmop), analopType, core->offset); + rz_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op); free (op); } { - const char *expr = r_strbuf_get (&analop.esil); - r_cons_printf (Color_RESET"esil: %s\n"Color_RESET, expr); + const char *expr = rz_strbuf_get (&analop.esil); + rz_cons_printf (Color_RESET"esil: %s\n"Color_RESET, expr); int wp = wordpos (expr, x); - char *pas = strdup (r_str_pad (' ', wp ? wp + 1: 0)); + char *pas = strdup (rz_str_pad (' ', wp ? wp + 1: 0)); int wp2 = wordpos (expr, x + 1); free (word); - word = r_str_ndup (expr + (wp?(wp+1):0), (wp2 - wp) - (wp?1:0)); + word = rz_str_ndup (expr + (wp?(wp+1):0), (wp2 - wp) - (wp?1:0)); if (wp == wp2) { // x --; eprintf ("Done\n"); x = 0; - r_sys_sleep (1); + rz_sys_sleep (1); free (pas); continue; } - const char *pad = r_str_pad ('-', wp2 - ((wp > 0)? wp + 1: 0)); - r_cons_printf (Color_RESET" %s%s\n"Color_RESET, pas, pad); + const char *pad = rz_str_pad ('-', wp2 - ((wp > 0)? wp + 1: 0)); + rz_cons_printf (Color_RESET" %s%s\n"Color_RESET, pas, pad); free (pas); // free (pad); } - r_cons_printf ("esil regs:\n"); + rz_cons_printf ("esil regs:\n"); showreg (esil, "$$", "address"); showreg (esil, "$z", "zero"); showreg (esil, "$b", "borrow"); @@ -198,87 +198,87 @@ R_API bool r_core_visual_esil(RCore *core) { showreg (esil, "$d", "delay"); showreg (esil, "$j", "jump"); - r_cons_printf ("regs:\n"); - char *r = r_core_cmd_str (core, "dr="); + rz_cons_printf ("regs:\n"); + char *r = rz_core_cmd_str (core, "dr="); if (r) { - r_cons_printf ("%s", r); + rz_cons_printf ("%s", r); free (r); } - r_cons_printf ("esil stack:\n"); - r_anal_esil_dumpstack (esil); - r_anal_op_fini (&analop); - r_cons_newline (); - r_cons_visual_flush (); + rz_cons_printf ("esil stack:\n"); + rz_anal_esil_dumpstack (esil); + rz_anal_op_fini (&analop); + rz_cons_newline (); + rz_cons_visual_flush (); - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { break; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'Q': case 'q': goto beach; case 's': eprintf ("step ((%s))\n", word); - r_sys_usleep (500); + rz_sys_usleep (500); x = R_MIN (x + 1, nbits - 1); - r_anal_esil_runword (esil, word); + rz_anal_esil_runword (esil, word); break; case 'S': eprintf ("esil step over :D\n"); - r_sys_usleep (500); + rz_sys_usleep (500); break; case 'r': case 'h': x = 0; //R_MAX (x - 1, 0); break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "Vd1?: Visual Bit Editor Help:\n\n" " q - quit the bit editor\n" " h/r - reset / go back (reinitialize esil state)\n" " s - esil step in\n" " j/k - toggle bit value (same as space key)\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': // TODO: move this into a separate helper function { char cmd[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); *cmd = 0; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0] = '\0'; } - r_core_cmd_task_sync (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd_task_sync (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (cmd[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } - r_cons_clear (); + rz_cons_clear (); } break; } } beach: - r_anal_esil_free (esil); + rz_anal_esil_free (esil); free (word); return true; } -R_API bool r_core_visual_bit_editor(RCore *core) { +RZ_API bool rz_core_visual_bit_editor(RzCore *core) { const int nbits = sizeof (ut64) * 8; bool colorBits = false; int analopType; int i, j, x = 0; - RAsmOp asmop; - RAnalOp analop; + RzAsmOp asmop; + RzAnalOp analop; ut8 buf[sizeof (ut64)]; bool bitsInLine = false; @@ -291,108 +291,108 @@ R_API bool r_core_visual_bit_editor(RCore *core) { } memcpy (buf, core->block + cur, sizeof (ut64)); for (;;) { - r_cons_clear00 (); + rz_cons_clear00 (); bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - (void) r_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64)); + (void) rz_asm_disassemble (core->rasm, &asmop, buf, sizeof (ut64)); analop.type = -1; - (void)r_anal_op (core->anal, &analop, core->offset, buf, sizeof (ut64), R_ANAL_OP_MASK_ESIL); + (void)rz_anal_op (core->anal, &analop, core->offset, buf, sizeof (ut64), R_ANAL_OP_MASK_ESIL); analopType = analop.type & R_ANAL_OP_TYPE_MASK; - r_cons_printf ("r2's bit editor:\n\n"); - r_cons_printf ("offset: 0x%08"PFMT64x"\n"Color_RESET, core->offset + cur); + rz_cons_printf ("r2's bit editor:\n\n"); + rz_cons_printf ("offset: 0x%08"PFMT64x"\n"Color_RESET, core->offset + cur); { - char *op_hex = r_asm_op_get_hex (&asmop); - char *res = r_print_hexpair (core->print, op_hex, -1); - r_cons_printf ("hex: %s\n"Color_RESET, res); + char *op_hex = rz_asm_op_get_hex (&asmop); + char *res = rz_print_hexpair (core->print, op_hex, -1); + rz_cons_printf ("hex: %s\n"Color_RESET, res); free (res); free (op_hex); } - r_cons_printf ("len: %d\n", asmop.size); + rz_cons_printf ("len: %d\n", asmop.size); { ut32 word = (x % 32); - r_cons_printf ("shift: >> %d << %d\n", word, (asmop.size * 8) - word - 1); + rz_cons_printf ("shift: >> %d << %d\n", word, (asmop.size * 8) - word - 1); } { - char *op = colorize_asm_string (core, r_asm_op_get_asm (&asmop), analopType, core->offset); - r_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op); + char *op = colorize_asm_string (core, rz_asm_op_get_asm (&asmop), analopType, core->offset); + rz_cons_printf (Color_RESET"asm: %s\n"Color_RESET, op); free (op); } - r_cons_printf (Color_RESET"esl: %s\n"Color_RESET, r_strbuf_get (&analop.esil)); - r_anal_op_fini (&analop); - r_cons_printf ("chr:"); + rz_cons_printf (Color_RESET"esl: %s\n"Color_RESET, rz_strbuf_get (&analop.esil)); + rz_anal_op_fini (&analop); + rz_cons_printf ("chr:"); for (i = 0; i < 8; i++) { const ut8 *byte = buf + i; char ch = IS_PRINTABLE (*byte)? *byte: '?'; if (i == 4) { - r_cons_printf (" |"); + rz_cons_printf (" |"); } if (use_color) { - r_cons_printf (" %5s'%s%c"Color_RESET"'", " ", core->cons->context->pal.btext, ch); + rz_cons_printf (" %5s'%s%c"Color_RESET"'", " ", core->cons->context->pal.btext, ch); } else { - r_cons_printf (" %5s'%c'", " ", ch); + rz_cons_printf (" %5s'%c'", " ", ch); } } - r_cons_printf ("\ndec:"); + rz_cons_printf ("\ndec:"); for (i = 0; i < 8; i++) { const ut8 *byte = buf + i; if (i == 4) { - r_cons_printf (" |"); + rz_cons_printf (" |"); } - r_cons_printf (" %8d", *byte); + rz_cons_printf (" %8d", *byte); } - r_cons_printf ("\nhex:"); + rz_cons_printf ("\nhex:"); for (i = 0; i < 8; i++) { const ut8 *byte = buf + i; if (i == 4) { - r_cons_printf (" |"); + rz_cons_printf (" |"); } - r_cons_printf (" 0x%02x", *byte); + rz_cons_printf (" 0x%02x", *byte); } if (bitsInLine) { - r_cons_printf ("\nbit: "); + rz_cons_printf ("\nbit: "); for (i = 0; i < 8; i++) { ut8 *byte = buf + i; if (i == 4) { - r_cons_printf ("| "); + rz_cons_printf ("| "); } if (colorBits && i >= asmop.size) { - r_cons_print (Color_RESET); + rz_cons_print (Color_RESET); colorBits = false; } for (j = 0; j < 8; j++) { bool bit = R_BIT_CHK (byte, 7 - j); - r_cons_printf ("%d", bit? 1: 0); + rz_cons_printf ("%d", bit? 1: 0); } - r_cons_print (" "); + rz_cons_print (" "); } } else { int set; - const char *ws = r_config_get_i (core->config, "scr.utf8")? "·": " "; + const char *ws = rz_config_get_i (core->config, "scr.utf8")? "·": " "; for (set = 1; set >= 0 ; set--) { - r_cons_printf ("\nbit: "); + rz_cons_printf ("\nbit: "); for (i = 0; i < 8; i++) { ut8 *byte = buf + i; if (i == 4) { - r_cons_printf ("| "); + rz_cons_printf ("| "); } if (colorBits && i >= asmop.size) { - r_cons_print (Color_RESET); + rz_cons_print (Color_RESET); colorBits = false; } for (j = 0; j < 8; j++) { bool bit = R_BIT_CHK (byte, 7 - j); if (set && bit) { - r_cons_printf ("1"); + rz_cons_printf ("1"); } else if (!set && !bit) { - r_cons_printf ("0"); + rz_cons_printf ("0"); } else { - r_cons_printf (ws); + rz_cons_printf (ws); } } - r_cons_print (" "); + rz_cons_print (" "); } } } - r_cons_newline (); + rz_cons_newline (); char str_pos[128]; memset (str_pos, '-', nbits + 9); int pos = x; @@ -410,24 +410,24 @@ R_API bool r_core_visual_bit_editor(RCore *core) { str_pos[46] = ' '; str_pos[55] = ' '; str_pos[64] = ' '; - r_cons_printf ("pos: %s\n", str_pos); - r_cons_newline (); - r_cons_visual_flush (); + rz_cons_printf ("pos: %s\n", str_pos); + rz_cons_newline (); + rz_cons_visual_flush (); - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { break; } if (ch != 10) { - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char } switch (ch) { case 'Q': case 'q': { - char *op_hex = r_asm_op_get_hex (&asmop); - char *res = r_print_hexpair (core->print, op_hex, -1); - r_core_cmdf (core, "wx %02x%02x%02x%02x", buf[0], buf[1], buf[2], buf[3]); + char *op_hex = rz_asm_op_get_hex (&asmop); + char *res = rz_print_hexpair (core->print, op_hex, -1); + rz_core_cmdf (core, "wx %02x%02x%02x%02x", buf[0], buf[1], buf[2], buf[3]); free (res); free (op_hex); } @@ -470,19 +470,19 @@ R_API bool r_core_visual_bit_editor(RCore *core) { break; case 'i': { - r_line_set_prompt ("> "); - const char *line = r_line_readline (); - ut64 num = r_num_math (core->num, line); + rz_line_set_prompt ("> "); + const char *line = rz_line_readline (); + ut64 num = rz_num_math (core->num, line); if (num || (!num && *line == '0')) { buf[x/8] = num; } } break; case 'R': - if (r_config_get_i (core->config, "scr.randpal")) { - r_core_cmd0 (core, "ecr"); + if (rz_config_get_i (core->config, "scr.randpal")) { + rz_core_cmd0 (core, "ecr"); } else { - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); } break; case '+': @@ -501,8 +501,8 @@ R_API bool r_core_visual_bit_editor(RCore *core) { bitsInLine = !bitsInLine; break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "Vd1?: Visual Bit Editor Help:\n\n" " q - quit the bit editor\n" " R - randomize color palette\n" @@ -513,26 +513,26 @@ R_API bool r_core_visual_bit_editor(RCore *core) { " - rotate left/right byte value\n" " i - insert numeric value of byte\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': // TODO: move this into a separate helper function { char cmd[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); cmd[0]='\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0] = '\0'; } - r_core_cmd (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (cmd[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } - r_cons_clear (); + rz_cons_clear (); } break; } @@ -540,15 +540,15 @@ R_API bool r_core_visual_bit_editor(RCore *core) { return true; } -// belongs to r_core_visual_types +// belongs to rz_core_visual_types static bool sdbforcb (void *p, const char *k, const char *v) { const char *pre = " "; - RCoreVisualTypes *vt = (RCoreVisualTypes*)p; + RzCoreVisualTypes *vt = (RzCoreVisualTypes*)p; bool use_color = vt->core->print->flags & R_PRINT_FLAGS_COLOR; char *color_sel = vt->core->cons->context->pal.prompt; if (vt->optword) { if (!strcmp (vt->type, "struct")) { - char *s = r_str_newf ("struct.%s.", vt->optword); + char *s = rz_str_newf ("struct.%s.", vt->optword); /* enum */ if (!strncmp (s, k, strlen (s))) { if (vt->t_idx == vt->t_ctr) { @@ -559,17 +559,17 @@ static bool sdbforcb (void *p, const char *k, const char *v) { pre = ">"; } if (use_color && *pre == '>') { - r_cons_printf ("%s %s %s %s %10s\n", color_sel, + rz_cons_printf ("%s %s %s %s %10s\n", color_sel, Color_RESET, pre, k+strlen (s), v); } else { - r_cons_printf (" %s %s %10s\n", + rz_cons_printf (" %s %s %10s\n", pre, k + strlen (s), v); } vt->t_ctr ++; } free (s); } else { - char *s = r_str_newf ("%s.", vt->optword); + char *s = rz_str_newf ("%s.", vt->optword); /* enum */ if (!strncmp (s, k, strlen (s))) { if (!strstr (k, ".0x")) { @@ -581,10 +581,10 @@ static bool sdbforcb (void *p, const char *k, const char *v) { pre = ">"; } if (use_color && *pre=='>') { - r_cons_printf ("%s %s %s %s\n", color_sel, + rz_cons_printf ("%s %s %s %s\n", color_sel, Color_RESET, pre, k, v); } else { - r_cons_printf (" %s %s %s\n", + rz_cons_printf (" %s %s %s\n", pre, k, v); } vt->t_ctr ++; @@ -603,10 +603,10 @@ static bool sdbforcb (void *p, const char *k, const char *v) { pre = ">"; } if (use_color && *pre == '>') { - r_cons_printf ("%s %s pf %3s %s\n"Color_RESET, + rz_cons_printf ("%s %s pf %3s %s\n"Color_RESET, color_sel, pre, fmt, k); } else { - r_cons_printf (" %s pf %3s %s\n", + rz_cons_printf (" %s pf %3s %s\n", pre, fmt, k); } free (fmt); @@ -619,11 +619,11 @@ static bool sdbforcb (void *p, const char *k, const char *v) { pre = ">"; } if (use_color && *pre == '>') { - r_cons_printf ("%s %s %s\n"Color_RESET, color_sel, + rz_cons_printf ("%s %s %s\n"Color_RESET, color_sel, (vt->t_idx == vt->t_ctr)? ">":" ", k); } else { - r_cons_printf (" %s %s\n", + rz_cons_printf (" %s %s\n", (vt->t_idx == vt->t_ctr)? ">":" ", k); } @@ -633,8 +633,8 @@ static bool sdbforcb (void *p, const char *k, const char *v) { return true; } -R_API int r_core_visual_types(RCore *core) { - RCoreVisualTypes vt = {core, 0, 0}; +RZ_API int rz_core_visual_types(RzCore *core) { + RzCoreVisualTypes vt = {core, 0, 0}; int i, ch; int _option = 0; int option = 0; @@ -653,31 +653,31 @@ R_API int r_core_visual_types(RCore *core) { NULL }; bool use_color = core->print->flags & R_PRINT_FLAGS_COLOR; - if (r_flag_space_is_empty (core->flags)) { + if (rz_flag_space_is_empty (core->flags)) { menu = 1; } for (;;) { - r_cons_clear00 (); + rz_cons_clear00 (); for (i = 0; opts[i]; i++) { if (use_color) { if (h_opt == i) { - r_cons_printf ("%s[%s]%s ", core->cons->context->pal.call, + rz_cons_printf ("%s[%s]%s ", core->cons->context->pal.call, opts[i], Color_RESET); } else { - r_cons_printf ("%s%s%s ", core->cons->context->pal.other, + rz_cons_printf ("%s%s%s ", core->cons->context->pal.other, opts[i], Color_RESET); } } else { - r_cons_printf (h_opt == i ? "[%s] " : " %s ", opts[i]); + rz_cons_printf (h_opt == i ? "[%s] " : " %s ", opts[i]); } } - r_cons_newline (); + rz_cons_newline (); if (optword) { - r_cons_printf (">> %s\n", optword); + rz_cons_printf (">> %s\n", optword); } if (!strcmp (opts[h_opt], "cc")) { // XXX TODO: make this work (select with cursor, to delete, or add a new one with 'i', etc) - r_core_cmdf (core, "tfcl"); + rz_core_cmdf (core, "tfcl"); } else { vt.t_idx = option; vt.t_ctr = 0; @@ -686,12 +686,12 @@ R_API int r_core_visual_types(RCore *core) { sdb_foreach (core->anal->sdb_types, sdbforcb, &vt); } - r_cons_visual_flush (); - ch = r_cons_readchar (); + rz_cons_visual_flush (); + ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { return false; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'h': h_opt--; @@ -713,7 +713,7 @@ R_API int r_core_visual_types(RCore *core) { { char *file = prompt ("Filename: ", NULL); if (file) { - r_core_cmdf (core, "\"to %s\"", file); + rz_core_cmdf (core, "\"to %s\"", file); free (file); } } @@ -741,7 +741,7 @@ R_API int r_core_visual_types(RCore *core) { } break; case 'b': - r_core_cmdf (core, "tl %s", vt.curname); + rz_core_cmdf (core, "tl %s", vt.curname); break; case -1: // EOF case 'Q': @@ -757,7 +757,7 @@ R_API int r_core_visual_types(RCore *core) { option = _option; if (menu==0) { // if no flagspaces, just quit - if (r_flag_space_is_empty (core->flags)) { + if (rz_flag_space_is_empty (core->flags)) { return true; } } @@ -766,16 +766,16 @@ R_API int r_core_visual_types(RCore *core) { { txt = prompt ("add C type: ", NULL); if (txt) { - r_core_cmdf (core, "\"td %s\"", txt); + rz_core_cmdf (core, "\"td %s\"", txt); free (txt); } } break; case 'd': - r_core_cmdf (core, "t- %s", vt.curname); + rz_core_cmdf (core, "t- %s", vt.curname); break; case '-': - r_core_cmd0 (core, "to -"); + rz_core_cmd0 (core, "to -"); break; case ' ': case '\r': @@ -805,8 +805,8 @@ R_API int r_core_visual_types(RCore *core) { } break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "Vt?: Visual Types Help:\n\n" " q - quit menu\n" " j/k - down/up keys\n" @@ -818,122 +818,122 @@ R_API int r_core_visual_types(RCore *core) { " o - open .h include file\n" " - - Open cfg.editor to load types\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); cmd[0] = '\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0]='\0'; } - r_core_cmd (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (cmd[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } - r_cons_clear (); + rz_cons_clear (); continue; } } return true; } -R_API bool r_core_visual_hudclasses(RCore *core) { - RListIter *iter, *iter2; +RZ_API bool rz_core_visual_hudclasses(RzCore *core) { + RzListIter *iter, *iter2; RBinClass *c; RBinField *f; RBinSymbol *m; ut64 addr; char *res; - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { return false; } list->free = free; - RList *classes = r_bin_get_classes (core->bin); - r_list_foreach (classes, iter, c) { - r_list_foreach (c->fields, iter2, f) { - r_list_append (list, r_str_newf ("0x%08"PFMT64x" %s %s", + RzList *classes = rz_bin_get_classes (core->bin); + rz_list_foreach (classes, iter, c) { + rz_list_foreach (c->fields, iter2, f) { + rz_list_append (list, rz_str_newf ("0x%08"PFMT64x" %s %s", f->vaddr, c->name, f->name)); } - r_list_foreach (c->methods, iter2, m) { + rz_list_foreach (c->methods, iter2, m) { const char *name = m->dname? m->dname: m->name; - r_list_append (list, r_str_newf ("0x%08"PFMT64x" %s %s", + rz_list_append (list, rz_str_newf ("0x%08"PFMT64x" %s %s", m->vaddr, c->name, name)); } } - res = r_cons_hud (list, NULL); + res = rz_cons_hud (list, NULL); if (res) { char *p = strchr (res, ' '); if (p) { *p = 0; } - addr = r_num_get (NULL, res); - r_core_seek (core, addr, true); + addr = rz_num_get (NULL, res); + rz_core_seek (core, addr, true); free (res); } - r_list_free (list); + rz_list_free (list); return res != NULL; } -static bool hudstuff_append(RFlagItem *fi, void *user) { - RList *list = (RList *)user; - char *s = r_str_newf ("0x%08"PFMT64x" %s", fi->offset, fi->name); +static bool hudstuff_append(RzFlagItem *fi, void *user) { + RzList *list = (RzList *)user; + char *s = rz_str_newf ("0x%08"PFMT64x" %s", fi->offset, fi->name); if (s) { - r_list_append (list, s); + rz_list_append (list, s); } return true; } -R_API bool r_core_visual_hudstuff(RCore *core) { +RZ_API bool rz_core_visual_hudstuff(RzCore *core) { ut64 addr; char *res; - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { return false; } list->free = free; - r_flag_foreach (core->flags, hudstuff_append, list); + rz_flag_foreach (core->flags, hudstuff_append, list); RIntervalTreeIter it; - RAnalMetaItem *mi; - r_interval_tree_foreach (&core->anal->meta, it, mi) { + RzAnalMetaItem *mi; + rz_interval_tree_foreach (&core->anal->meta, it, mi) { if (mi->type == R_META_TYPE_COMMENT) { - char *s = r_str_newf ("0x%08"PFMT64x" %s", r_interval_tree_iter_get (&it)->start, mi->str); + char *s = rz_str_newf ("0x%08"PFMT64x" %s", rz_interval_tree_iter_get (&it)->start, mi->str); if (s) { - r_list_push (list, s); + rz_list_push (list, s); } } } - res = r_cons_hud (list, NULL); + res = rz_cons_hud (list, NULL); if (res) { char *p = strchr (res, ' '); if (p) { *p = 0; } - addr = r_num_get (NULL, res); - r_core_seek (core, addr, true); + addr = rz_num_get (NULL, res); + rz_core_seek (core, addr, true); free (res); } - r_list_free (list); + rz_list_free (list); return res != NULL; } -static bool r_core_visual_config_hud(RCore *core) { - RListIter *iter; +static bool rz_core_visual_config_hud(RzCore *core) { + RzListIter *iter; RConfigNode *bt; - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { return false; } list->free = free; - r_list_foreach (core->config->nodes, iter, bt) { - r_list_append (list, r_str_newf ("%s %s", bt->name, bt->value)); + rz_list_foreach (core->config->nodes, iter, bt) { + rz_list_append (list, rz_str_newf ("%s %s", bt->name, bt->value)); } - char *res = r_cons_hud (list, NULL); + char *res = rz_cons_hud (list, NULL); if (res) { const char *oldvalue = NULL; char cmd[512]; @@ -941,20 +941,20 @@ static bool r_core_visual_config_hud(RCore *core) { if (p) { *p = 0; } - oldvalue = r_config_get (core->config, res); - r_cons_show_cursor (true); - r_cons_set_raw (false); + oldvalue = rz_config_get (core->config, res); + rz_cons_show_cursor (true); + rz_cons_set_raw (false); cmd[0] = '\0'; eprintf ("Set new value for %s (old=%s)\n", res, oldvalue); - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0] = '\0'; } - r_config_set (core->config, res, cmd); - r_cons_set_raw (true); - r_cons_show_cursor (false); + rz_config_set (core->config, res, cmd); + rz_cons_set_raw (true); + rz_cons_show_cursor (false); } - r_list_free (list); + rz_list_free (list); return true; } @@ -963,9 +963,9 @@ static bool r_core_visual_config_hud(RCore *core) { // TODO: wrap index when out of boundaries // TODO: Add support to show class fields too // Segfaults - stack overflow, because of recursion -static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const char *grep, RList *list) { - bool show_color = r_config_get_i (core->config, "scr.color"); - RListIter *iter; +static void *show_class(RzCore *core, int mode, int *idx, RBinClass *_c, const char *grep, RzList *list) { + bool show_color = rz_config_get_i (core->config, "scr.color"); + RzListIter *iter; RBinClass *c, *cur = NULL; RBinSymbol *m, *mur = NULL; RBinField *f, *fur = NULL; @@ -975,10 +975,10 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch switch (mode) { case 'c': - r_cons_printf ("[hjkl_/Cfm]> classes:\n\n"); - r_list_foreach (list, iter, c) { + rz_cons_printf ("[hjkl_/Cfm]> classes:\n\n"); + rz_list_foreach (list, iter, c) { if (grep) { - if (!r_str_casestr (c->name, grep)) { + if (!rz_str_casestr (c->name, grep)) { i++; continue; } @@ -994,15 +994,15 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch if (show_color) { if (i == *idx) { const char *clr = Color_BLUE; - r_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" + rz_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" PFMT64x Color_YELLOW " %s\n" Color_RESET, i, clr, c->addr, c->name); } else { - r_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s\n", + rz_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s\n", i, core->cons->context->pal.offset, c->addr, c->name); } } else { - r_cons_printf ("%s %02d 0x%08"PFMT64x" %s\n", + rz_cons_printf ("%s %02d 0x%08"PFMT64x" %s\n", (i==*idx)?">>":"- ", i, c->addr, c->name); } if (i++ == *idx) { @@ -1015,17 +1015,17 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch if (!found) { return NULL; } - // r_cons_clear00 (); + // rz_cons_clear00 (); return NULL; // show_class (core, mode, idx, _c, "", list); } return cur; case 'f': // show fields - r_cons_printf ("[hjkl_/cFm]> fields of %s:\n\n", _c->name); - r_list_foreach (_c->fields, iter, f) { + rz_cons_printf ("[hjkl_/cFm]> fields of %s:\n\n", _c->name); + rz_list_foreach (_c->fields, iter, f) { const char *name = f->name; if (grep) { - if (!r_str_casestr (name, grep)) { + if (!rz_str_casestr (name, grep)) { i++; continue; } @@ -1041,21 +1041,21 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch char *mflags = strdup (""); - if (r_str_startswith (name, _c->name)) { + if (rz_str_startswith (name, _c->name)) { name += strlen (_c->name); } if (show_color) { if (i == *idx) { const char *clr = Color_BLUE; - r_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" + rz_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" PFMT64x Color_YELLOW " %s %s\n" Color_RESET, i, clr, f->vaddr, mflags, name); } else { - r_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s %s\n", + rz_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s %s\n", i, core->cons->context->pal.offset, f->vaddr, mflags, name); } } else { - r_cons_printf ("%s %02d 0x%08"PFMT64x" %s %s\n", + rz_cons_printf ("%s %02d 0x%08"PFMT64x" %s %s\n", (i==*idx)? ">>": "- ", i, f->vaddr, mflags, name); } @@ -1067,10 +1067,10 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch } if (!fur) { *idx = i - 1; - if (r_list_empty (_c->fields)) { + if (rz_list_empty (_c->fields)) { return NULL; } - // r_cons_clear00 (); + // rz_cons_clear00 (); return NULL; // show_class (core, mode, idx, _c, grep, list); } return fur; @@ -1081,12 +1081,12 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch eprintf ("No class selected.\n"); return mur; } - r_cons_printf ("[hjkl_/cfM]> methods of %s\n\n", _c->name); - r_list_foreach (_c->methods, iter, m) { + rz_cons_printf ("[hjkl_/cfM]> methods of %s\n\n", _c->name); + rz_list_foreach (_c->methods, iter, m) { const char *name = m->dname? m->dname: m->name; char *mflags; if (grep) { - if (!r_str_casestr (name, grep)) { + if (!rz_str_casestr (name, grep)) { i++; continue; } @@ -1100,23 +1100,23 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch } } - mflags = r_core_bin_method_flags_str (m->method_flags, 0); + mflags = rz_core_bin_method_flags_str (m->method_flags, 0); if (show_color) { - if (r_str_startswith (name, _c->name)) { + if (rz_str_startswith (name, _c->name)) { name += strlen (_c->name); } if (i == *idx) { const char *clr = Color_BLUE; - r_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" + rz_cons_printf (Color_GREEN ">>" Color_RESET " %02d %s0x%08" PFMT64x Color_YELLOW " %s %s\n" Color_RESET, i, clr, m->vaddr, mflags, name); } else { - r_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s %s\n", + rz_cons_printf ("- %02d %s0x%08"PFMT64x Color_RESET" %s %s\n", i, core->cons->context->pal.offset, m->vaddr, mflags, name); } } else { - r_cons_printf ("%s %02d 0x%08"PFMT64x" %s %s\n", + rz_cons_printf ("%s %02d 0x%08"PFMT64x" %s %s\n", (i==*idx)? ">>": "- ", i, m->vaddr, mflags, name); } @@ -1128,10 +1128,10 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch } if (!mur) { *idx = i - 1; - if (r_list_empty (_c->methods)) { + if (rz_list_empty (_c->methods)) { return NULL; } - // r_cons_clear00 (); + // rz_cons_clear00 (); return NULL; // show_class (core, mode, idx, _c, grep, list); } return mur; @@ -1139,7 +1139,7 @@ static void *show_class(RCore *core, int mode, int *idx, RBinClass *_c, const ch return NULL; } -R_API int r_core_visual_classes(RCore *core) { +RZ_API int rz_core_visual_classes(RzCore *core) { int ch, index = 0; char cmd[1024]; int mode = 'c'; @@ -1150,16 +1150,16 @@ R_API int r_core_visual_classes(RCore *core) { int oldcur = 0; char *grep = NULL; bool grepmode = false; - RList *list = r_bin_get_classes (core->bin); - if (r_list_empty (list)) { - r_cons_message ("No Classes"); + RzList *list = rz_bin_get_classes (core->bin); + if (rz_list_empty (list)) { + rz_cons_message ("No Classes"); return false; } for (;;) { int cols; - r_cons_clear00 (); + rz_cons_clear00 (); if (grepmode) { - r_cons_printf ("Grep: %s\n", grep? grep: ""); + rz_cons_printf ("Grep: %s\n", grep? grep: ""); } ptr = show_class (core, mode, &index, cur, grep, list); switch (mode) { @@ -1175,9 +1175,9 @@ R_API int r_core_visual_classes(RCore *core) { } /* update terminal size */ - (void) r_cons_get_size (&cols); - r_cons_visual_flush (); - ch = r_cons_readchar (); + (void) rz_cons_get_size (&cols); + rz_cons_visual_flush (); + ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { R_FREE (grep); return false; @@ -1203,20 +1203,20 @@ R_API int r_core_visual_classes(RCore *core) { break; default: grep = grep - ? r_str_appendf (grep, "%c", ch) - : r_str_newf ("%c", ch); + ? rz_str_appendf (grep, "%c", ch) + : rz_str_newf ("%c", ch); break; } continue; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'C': - r_config_toggle (core->config, "scr.color"); + rz_config_toggle (core->config, "scr.color"); break; case '_': - if (r_core_visual_hudclasses (core)) { + if (rz_core_visual_hudclasses (core)) { return true; } break; @@ -1237,7 +1237,7 @@ R_API int r_core_visual_classes(RCore *core) { index = 0; break; case 'G': - index = r_list_length (list) - 1; + index = rz_list_length (list) - 1; break; case 'i': { @@ -1250,8 +1250,8 @@ R_API int r_core_visual_classes(RCore *core) { break; case 'p': if (mode == 'm' && mur) { - r_core_seek (core, mur->vaddr, true); - r_core_cmd0 (core, "af;pdf~.."); + rz_core_seek (core, mur->vaddr, true); + rz_core_cmd0 (core, "af;pdf~.."); } break; case 'm': // methods @@ -1280,11 +1280,11 @@ R_API int r_core_visual_classes(RCore *core) { case '\r': case '\n': if (mur && mode == 'm') { - r_core_seek (core, mur->vaddr, true); + rz_core_seek (core, mur->vaddr, true); return true; } if (fur) { - r_core_seek (core, fur->vaddr, true); + rz_core_seek (core, fur->vaddr, true); return true; } if (cur) { @@ -1294,8 +1294,8 @@ R_API int r_core_visual_classes(RCore *core) { } break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "\nVF: Visual Classes help:\n\n" " q - quit menu\n" " j/k - down/up keys\n" @@ -1309,88 +1309,88 @@ R_API int r_core_visual_classes(RCore *core) { " l/' ' - accept current selection\n" " p - preview method disasm with less\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); cmd[0] = '\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0]='\0'; } //line[strlen(line)-1]='\0'; - r_core_cmd (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (cmd[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } //cons_gotoxy(0,0); - r_cons_clear (); + rz_cons_clear (); break; } } return true; } -static void anal_class_print(RAnal *anal, const char *class_name) { - RVector *bases = r_anal_class_base_get_all (anal, class_name); - RVector *vtables = r_anal_class_vtable_get_all (anal, class_name); - RVector *methods = r_anal_class_method_get_all (anal, class_name); +static void anal_class_print(RzAnal *anal, const char *class_name) { + RzVector *bases = rz_anal_class_base_get_all (anal, class_name); + RzVector *vtables = rz_anal_class_vtable_get_all (anal, class_name); + RzVector *methods = rz_anal_class_method_get_all (anal, class_name); - r_cons_print (class_name); + rz_cons_print (class_name); if (bases) { - RAnalBaseClass *base; + RzAnalBaseClass *base; bool first = true; - r_vector_foreach (bases, base) { + rz_vector_foreach (bases, base) { if (first) { - r_cons_print (": "); + rz_cons_print (": "); first = false; } else { - r_cons_print (", "); + rz_cons_print (", "); } - r_cons_print (base->class_name); + rz_cons_print (base->class_name); } - r_vector_free (bases); + rz_vector_free (bases); } - r_cons_print ("\n"); + rz_cons_print ("\n"); if (vtables) { - RAnalVTable *vtable; - r_vector_foreach (vtables, vtable) { - r_cons_printf (" %2s vtable 0x%"PFMT64x" @ +0x%"PFMT64x" size:+0x%"PFMT64x"\n", vtable->id, vtable->addr, vtable->offset, vtable->size); + RzAnalVTable *vtable; + rz_vector_foreach (vtables, vtable) { + rz_cons_printf (" %2s vtable 0x%"PFMT64x" @ +0x%"PFMT64x" size:+0x%"PFMT64x"\n", vtable->id, vtable->addr, vtable->offset, vtable->size); } - r_vector_free (vtables); + rz_vector_free (vtables); } - r_cons_print ("\n"); + rz_cons_print ("\n"); if (methods) { - RAnalMethod *meth; - r_vector_foreach (methods, meth) { - r_cons_printf (" %s @ 0x%"PFMT64x, meth->name, meth->addr); + RzAnalMethod *meth; + rz_vector_foreach (methods, meth) { + rz_cons_printf (" %s @ 0x%"PFMT64x, meth->name, meth->addr); if (meth->vtable_offset >= 0) { - r_cons_printf (" (vtable + 0x%"PFMT64x")\n", (ut64)meth->vtable_offset); + rz_cons_printf (" (vtable + 0x%"PFMT64x")\n", (ut64)meth->vtable_offset); } else { - r_cons_print ("\n"); + rz_cons_print ("\n"); } } - r_vector_free (methods); + rz_vector_free (methods); } } -static const char *show_anal_classes(RCore *core, char mode, int *idx, SdbList *list, const char *class_name) { - bool show_color = r_config_get_i (core->config, "scr.color"); +static const char *show_anal_classes(RzCore *core, char mode, int *idx, SdbList *list, const char *class_name) { + bool show_color = rz_config_get_i (core->config, "scr.color"); SdbListIter *iter; SdbKv *kv; int i = 0; int skip = *idx - 10; const char * cur_class = NULL; - r_cons_printf ("[hjkl_/Cfm]> anal classes:\n\n"); + rz_cons_printf ("[hjkl_/Cfm]> anal classes:\n\n"); if (mode == 'd' && class_name) { anal_class_print (core->anal, class_name); @@ -1416,10 +1416,10 @@ static const char *show_anal_classes(RCore *core, char mode, int *idx, SdbList * txt_clr = Color_YELLOW; cur_class = class_name; } - r_cons_printf ("%s" Color_RESET " %02d" + rz_cons_printf ("%s" Color_RESET " %02d" " %s%s\n" Color_RESET, pointer, i, txt_clr, class_name); } else { - r_cons_printf ("%s %02d %s\n", (i==*idx) ? ">>" : "- ", i, class_name); + rz_cons_printf ("%s %02d %s\n", (i==*idx) ? ">>" : "- ", i, class_name); } i++; @@ -1431,36 +1431,36 @@ static const char *show_anal_classes(RCore *core, char mode, int *idx, SdbList * // Should the classes be refreshed after command execution with : // in case new class information would be added? // Add grep? -R_API int r_core_visual_anal_classes(RCore *core) { +RZ_API int rz_core_visual_anal_classes(RzCore *core) { int ch, index = 0; char command[1024]; - SdbList *list = r_anal_class_get_all (core->anal, true); + SdbList *list = rz_anal_class_get_all (core->anal, true); int oldcur = 0; char mode = ' '; const char *class_name = ""; - if (r_list_empty (list)) { - r_cons_message ("No Classes"); + if (rz_list_empty (list)) { + rz_cons_message ("No Classes"); goto cleanup; } for (;;) { int cols; - r_cons_clear00 (); + rz_cons_clear00 (); class_name = show_anal_classes (core, mode, &index, list, class_name); /* update terminal size */ - (void) r_cons_get_size (&cols); - r_cons_visual_flush (); - ch = r_cons_readchar (); + (void) rz_cons_get_size (&cols); + rz_cons_visual_flush (); + ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { goto cleanup; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'C': - r_config_toggle (core->config, "scr.color"); + rz_config_toggle (core->config, "scr.color"); break; case 'J': index += 10; @@ -1509,8 +1509,8 @@ R_API int r_core_visual_anal_classes(RCore *core) { mode = 'd'; break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "\nVF: Visual Classes help:\n\n" " q - quit menu\n" " j/k - down/up keys\n" @@ -1518,26 +1518,26 @@ R_API int r_core_visual_anal_classes(RCore *core) { " g/G - go first/last item\n" " l/' ' - accept current selection\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); command[0] = '\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (command, sizeof (command), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (command, sizeof (command), 0, NULL) < 0) { command[0]='\0'; } //line[strlen(line)-1]='\0'; - r_core_cmd (core, command, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd (core, command, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (command[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } //cons_gotoxy(0,0); - r_cons_clear (); + rz_cons_clear (); break; } } @@ -1547,14 +1547,14 @@ cleanup: } static int flag_name_sort(const void *a, const void *b) { - const RFlagItem *fa = (const RFlagItem *)a; - const RFlagItem *fb = (const RFlagItem *)b; + const RzFlagItem *fa = (const RzFlagItem *)a; + const RzFlagItem *fb = (const RzFlagItem *)b; return strcmp (fa->name, fb->name); } static int flag_offset_sort(const void *a, const void *b) { - const RFlagItem *fa = (const RFlagItem *)a; - const RFlagItem *fb = (const RFlagItem *)b; + const RzFlagItem *fa = (const RzFlagItem *)a; + const RzFlagItem *fb = (const RzFlagItem *)b; if (fa->offset < fb->offset) { return -1; } @@ -1564,13 +1564,13 @@ static int flag_offset_sort(const void *a, const void *b) { return 0; } -static void sort_flags(RList *l, int sort) { +static void sort_flags(RzList *l, int sort) { switch (sort) { case SORT_NAME: - r_list_sort (l, flag_name_sort); + rz_list_sort (l, flag_name_sort); break; case SORT_OFFSET: - r_list_sort (l, flag_offset_sort); + rz_list_sort (l, flag_offset_sort); break; case SORT_NONE: default: @@ -1583,108 +1583,108 @@ static void sort_flags(RList *l, int sort) { static char *print_rop(void *_core, void *_item, bool selected) { char *line = _item; // TODO: trim if too long - return r_str_newf ("%c %s\n", selected?'>':' ', line); + return rz_str_newf ("%c %s\n", selected?'>':' ', line); } -R_API int r_core_visual_view_rop(RCore *core) { - RListIter *iter; +RZ_API int rz_core_visual_view_rop(RzCore *core) { + RzListIter *iter; const int rows = 7; int cur = 0; - r_line_set_prompt ("rop regexp: "); - const char *line = r_line_readline (); + rz_line_set_prompt ("rop regexp: "); + const char *line = rz_line_readline (); - int scr_h, scr_w = r_cons_get_size (&scr_h); + int scr_h, scr_w = rz_cons_get_size (&scr_h); if (!line || !*line) { return false; } - // maybe store in RCore, so we can save it in project and use it outside visual + // maybe store in RzCore, so we can save it in project and use it outside visual eprintf ("Searching ROP gadgets...\n"); - char *ropstr = r_core_cmd_strf (core, "\"/Rl %s\" @e:scr.color=0", line); - RList *rops = r_str_split_list (ropstr, "\n", 0); + char *ropstr = rz_core_cmd_strf (core, "\"/Rl %s\" @e:scr.color=0", line); + RzList *rops = rz_str_split_list (ropstr, "\n", 0); int delta = 0; bool show_color = core->print->flags & R_PRINT_FLAGS_COLOR; bool forceaddr = false; ut64 addr = UT64_MAX; char *cursearch = strdup (line); while (true) { - r_cons_clear00 (); - r_cons_printf ("[0x%08"PFMT64x"]-[visual-r2rop] %s (see pdp command)\n", + rz_cons_clear00 (); + rz_cons_printf ("[0x%08"PFMT64x"]-[visual-r2rop] %s (see pdp command)\n", (addr == UT64_MAX)? 0: addr + delta, cursearch); // compute chain - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); char *msg; - r_list_foreach (core->ropchain, iter, msg) { + rz_list_foreach (core->ropchain, iter, msg) { if (core->rasm->bits == 64) { - ut64 n = r_num_get (NULL, msg); - n = r_read_be64 (&n); - r_strbuf_appendf (sb, "%016"PFMT64x, n); + ut64 n = rz_num_get (NULL, msg); + n = rz_read_be64 (&n); + rz_strbuf_appendf (sb, "%016"PFMT64x, n); } else { - ut32 n = r_num_get (NULL, msg); - n = r_read_be32 (&n); - r_strbuf_appendf (sb, "%08x", n); + ut32 n = rz_num_get (NULL, msg); + n = rz_read_be32 (&n); + rz_strbuf_appendf (sb, "%08x", n); } } - char *chainstr = r_strbuf_drain (sb); + char *chainstr = rz_strbuf_drain (sb); - char *wlist = r_str_widget_list (core, rops, rows, cur, print_rop); - r_cons_printf ("%s", wlist); + char *wlist = rz_str_widget_list (core, rops, rows, cur, print_rop); + rz_cons_printf ("%s", wlist); free (wlist); - char *curline = r_str_dup (NULL, r_str_trim_head_ro (r_str_widget_list ( + char *curline = rz_str_dup (NULL, rz_str_trim_head_ro (rz_str_widget_list ( core, rops, rows, cur, print_rop))); if (curline) { char *sp = strchr (curline, ' '); if (sp) { *sp = 0; if (!forceaddr) { - addr = r_num_math (NULL, curline); + addr = rz_num_math (NULL, curline); } *sp = ' '; } if (addr != UT64_MAX) { - r_cons_printf ("Gadget:"); + rz_cons_printf ("Gadget:"); // get comment - char *output = r_core_cmd_strf (core, "piu 10 @ 0x%08"PFMT64x, addr + delta); + char *output = rz_core_cmd_strf (core, "piu 10 @ 0x%08"PFMT64x, addr + delta); if (output) { - r_cons_strcat_at (output, 0, 10, scr_w, 10); + rz_cons_strcat_at (output, 0, 10, scr_w, 10); free (output); } } } int count = 0; - r_cons_flush (); - r_cons_gotoxy (0, 20); - r_cons_printf ("ROPChain:\n %s\n", chainstr? chainstr: ""); - r_list_foreach (core->ropchain, iter, msg) { + rz_cons_flush (); + rz_cons_gotoxy (0, 20); + rz_cons_printf ("ROPChain:\n %s\n", chainstr? chainstr: ""); + rz_list_foreach (core->ropchain, iter, msg) { int extra = strlen (chainstr) / scr_w; - r_cons_gotoxy (0, extra + 22 + count); - r_cons_strcat (msg); - const char *cmt = r_meta_get_string (core->anal, R_META_TYPE_COMMENT, r_num_get (NULL, msg)); + rz_cons_gotoxy (0, extra + 22 + count); + rz_cons_strcat (msg); + const char *cmt = rz_meta_get_string (core->anal, R_META_TYPE_COMMENT, rz_num_get (NULL, msg)); if (cmt) { - r_cons_strcat (cmt); + rz_cons_strcat (cmt); } count ++; } - r_cons_flush (); - int ch = r_cons_readchar (); + rz_cons_flush (); + int ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { free (curline); free (cursearch); R_FREE (chainstr); return false; } -#define NEWTYPE(x,y) r_mem_dup (&(y), sizeof (x)); - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char +#define NEWTYPE(x,y) rz_mem_dup (&(y), sizeof (x)); + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 127: - free (r_list_pop (core->ropchain)); + free (rz_list_pop (core->ropchain)); break; case '?': - r_cons_clear00 (); - r_cons_printf ("[r2rop-visual] Help\n" + rz_cons_clear00 (); + rz_cons_printf ("[r2rop-visual] Help\n" " jk - select next/prev rop gadget\n" " JK - scroll next/prev page from list\n" " hl - increase/decrease delta offset in disasm\n" @@ -1700,41 +1700,41 @@ R_API int r_core_visual_view_rop(RCore *core) { " ? - show this help message\n" " q - quit this view\n" ); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': // TODO: move this into a separate helper function - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); while (true) { char cmd[1024]; cmd[0] = '\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0] = '\0'; } if (!*cmd || *cmd == 'q') { break; } ut64 oseek = core->offset; - r_core_seek (core, addr + delta, false); - r_core_cmd (core, cmd, 1); - r_core_seek (core, oseek, false); - r_cons_flush (); + rz_core_seek (core, addr + delta, false); + rz_core_cmd (core, cmd, 1); + rz_core_seek (core, oseek, false); + rz_cons_flush (); } - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); break; case 'y': - r_core_cmdf (core, "yfx %s", chainstr); + rz_core_cmdf (core, "yfx %s", chainstr); break; case 'o': { - r_line_set_prompt ("offset: "); - const char *line = r_line_readline (); + rz_line_set_prompt ("offset: "); + const char *line = rz_line_readline (); if (line && *line) { - ut64 off = r_num_math (core->num, line); - r_core_seek (core, off, true); + ut64 off = rz_num_math (core->num, line); + rz_core_seek (core, off, true); addr = off; forceaddr = true; delta = 0; @@ -1743,8 +1743,8 @@ R_API int r_core_visual_view_rop(RCore *core) { break; case 'r': { - r_line_set_prompt ("rop regexp: "); - const char *line = r_line_readline (); + rz_line_set_prompt ("rop regexp: "); + const char *line = rz_line_readline (); if (line && *line) { free (cursearch); delta = 0; @@ -1752,32 +1752,32 @@ R_API int r_core_visual_view_rop(RCore *core) { cur = 0; cursearch = strdup (line); free (ropstr); - ropstr = r_core_cmd_strf (core, "\"/Rl %s\" @e:scr.color=0", line); - r_list_free (rops); - rops = r_str_split_list (ropstr, "\n", 0); + ropstr = rz_core_cmd_strf (core, "\"/Rl %s\" @e:scr.color=0", line); + rz_list_free (rops); + rops = rz_str_split_list (ropstr, "\n", 0); } } break; case '/': - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); break; case 'i': { - r_line_set_prompt ("insert value: "); - const char *line = r_line_readline (); + rz_line_set_prompt ("insert value: "); + const char *line = rz_line_readline (); if (line && *line) { - ut64 n = r_num_math (core->num, line); - r_list_push (core->ropchain, r_str_newf ("0x%08"PFMT64x, n)); + ut64 n = rz_num_math (core->num, line); + rz_list_push (core->ropchain, rz_str_newf ("0x%08"PFMT64x, n)); } } break; case ';': { - r_line_set_prompt ("comment: "); - const char *line = r_line_readline (); + rz_line_set_prompt ("comment: "); + const char *line = rz_line_readline (); if (line && *line) { // XXX code injection bug here - r_core_cmdf (core, "CC %s @ 0x%08"PFMT64x, line, addr + delta); + rz_core_cmdf (core, "CC %s @ 0x%08"PFMT64x, line, addr + delta); } } break; @@ -1785,15 +1785,15 @@ R_API int r_core_visual_view_rop(RCore *core) { case '\n': case '\r': if (curline && *curline) { - char *line = r_core_cmd_strf (core, "piuq@0x%08"PFMT64x, addr + delta); - r_str_replace_char (line, '\n', ';'); + char *line = rz_core_cmd_strf (core, "piuq@0x%08"PFMT64x, addr + delta); + rz_str_replace_char (line, '\n', ';'); if (show_color) { // XXX parsing fails to read this ansi-offset - // const char *offsetColor = r_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache - // r_list_push (core->ropchain, r_str_newf ("%s0x%08"PFMT64x""Color_RESET" %s", offsetColor, addr + delta, line)); - r_list_push (core->ropchain, r_str_newf ("0x%08"PFMT64x" %s", addr + delta, line)); + // const char *offsetColor = rz_cons_singleton ()->context->pal.offset; // TODO etooslow. must cache + // rz_list_push (core->ropchain, rz_str_newf ("%s0x%08"PFMT64x""Color_RESET" %s", offsetColor, addr + delta, line)); + rz_list_push (core->ropchain, rz_str_newf ("0x%08"PFMT64x" %s", addr + delta, line)); } else { - r_list_push (core->ropchain, r_str_newf ("0x%08"PFMT64x" %s", addr + delta, line)); + rz_list_push (core->ropchain, rz_str_newf ("0x%08"PFMT64x" %s", addr + delta, line)); } free (line); } @@ -1849,7 +1849,7 @@ R_API int r_core_visual_view_rop(RCore *core) { return false; } -R_API int r_core_visual_trackflags(RCore *core) { +RZ_API int rz_core_visual_trackflags(RzCore *core) { const char *fs = NULL, *fs2 = NULL; int hit, i, j, ch; int _option = 0; @@ -1860,23 +1860,23 @@ R_API int r_core_visual_trackflags(RCore *core) { int menu = 0; int sort = SORT_NONE; - if (r_flag_space_is_empty (core->flags)) { + if (rz_flag_space_is_empty (core->flags)) { menu = 1; } for (;;) { - bool hasColor = r_config_get_i (core->config, "scr.color"); - r_cons_clear00 (); + bool hasColor = rz_config_get_i (core->config, "scr.color"); + rz_cons_clear00 (); if (menu) { - r_cons_printf ("Flags in flagspace '%s'. Press '?' for help.\n\n", - r_flag_space_cur_name (core->flags)); + rz_cons_printf ("Flags in flagspace '%s'. Press '?' for help.\n\n", + rz_flag_space_cur_name (core->flags)); hit = 0; i = j = 0; - RList *l = r_flag_all_list (core->flags, true); - RListIter *iter; - RFlagItem *fi; + RzList *l = rz_flag_all_list (core->flags, true); + RzListIter *iter; + RzFlagItem *fi; sort_flags (l, sort); - r_list_foreach (l, iter, fi) { + rz_list_foreach (l, iter, fi) { if (option == i) { fs2 = fi->name; hit = 1; @@ -1884,28 +1884,28 @@ R_API int r_core_visual_trackflags(RCore *core) { if ((i>=option-delta) && ((i':' ', i, fi->offset, fi->size, fi->name); if (cur && hasColor) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } j++; } i++; } - r_list_free (l); + rz_list_free (l); if (!hit && i > 0) { option = i - 1; continue; } if (fs2) { - int cols, rows = r_cons_get_size (&cols); + int cols, rows = rz_cons_get_size (&cols); //int rows = 20; rows -= 12; - r_cons_printf ("\n Selected: %s\n\n", fs2); + rz_cons_printf ("\n Selected: %s\n\n", fs2); // Honor MAX_FORMATS here switch (format) { case 0: snprintf (cmd, sizeof (cmd), "px %d @ %s!64", rows*16, fs2); core->printidx = 0; break; @@ -1915,25 +1915,25 @@ R_API int r_core_visual_trackflags(RCore *core) { default: format = 0; continue; } if (*cmd) { - r_core_cmd (core, cmd, 0); + rz_core_cmd (core, cmd, 0); } } else { - r_cons_printf ("(no flags)\n"); + rz_cons_printf ("(no flags)\n"); } } else { - r_cons_printf ("Flag spaces:\n\n"); + rz_cons_printf ("Flag spaces:\n\n"); hit = 0; RSpaceIter it; - const RSpace *s, *cur = r_flag_space_cur (core->flags); + const RSpace *s, *cur = rz_flag_space_cur (core->flags); int i = 0; - r_flag_space_foreach (core->flags, it, s) { + rz_flag_space_foreach (core->flags, it, s) { if (option == i) { fs = s->name; hit = 1; } if ((i >= option - delta) && ((i < option + delta) || ((option < delta) && (i < (delta << 1))))) { - r_cons_printf (" %c %c %s\n", + rz_cons_printf (" %c %c %s\n", (option == i)? '>': ' ', (s == cur)? '*': ' ', s->name); @@ -1944,7 +1944,7 @@ R_API int r_core_visual_trackflags(RCore *core) { fs = "*"; hit = 1; } - r_cons_printf (" %c %c %s\n", (option == i)? '>': ' ', + rz_cons_printf (" %c %c %s\n", (option == i)? '>': ' ', !cur? '*': ' ', "*"); i++; if (!hit && i > 0) { @@ -1952,18 +1952,18 @@ R_API int r_core_visual_trackflags(RCore *core) { continue; } } - r_cons_visual_flush (); - ch = r_cons_readchar (); + rz_cons_visual_flush (); + ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { return false; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'C': - r_config_toggle (core->config, "scr.color"); + rz_config_toggle (core->config, "scr.color"); break; case '_': - if (r_core_visual_hudstuff (core)) { + if (rz_core_visual_hudstuff (core)) { return true; } break; @@ -1991,9 +1991,9 @@ R_API int r_core_visual_trackflags(RCore *core) { menu--; option = _option; if (menu == 0) { - r_flag_space_set (core->flags, NULL); + rz_flag_space_set (core->flags, NULL); // if no flagspaces, just quit - if (r_flag_space_is_empty (core->flags)) { + if (rz_flag_space_is_empty (core->flags)) { return true; } } @@ -2001,89 +2001,89 @@ R_API int r_core_visual_trackflags(RCore *core) { case 'a': switch (menu) { case 0: // new flag space - r_cons_show_cursor (true); - r_line_set_prompt ("add flagspace: "); + rz_cons_show_cursor (true); + rz_line_set_prompt ("add flagspace: "); strcpy (cmd, "fs "); - if (r_cons_fgets (cmd + 3, sizeof (cmd) - 3, 0, NULL) > 0) { - r_core_cmd (core, cmd, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); + if (rz_cons_fgets (cmd + 3, sizeof (cmd) - 3, 0, NULL) > 0) { + rz_core_cmd (core, cmd, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } break; case 1: // new flag - r_cons_show_cursor (true); - r_line_set_prompt ("add flag: "); + rz_cons_show_cursor (true); + rz_line_set_prompt ("add flag: "); strcpy (cmd, "f "); - if (r_cons_fgets (cmd + 2, sizeof (cmd) - 2, 0, NULL) > 0) { - r_core_cmd (core, cmd, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); + if (rz_cons_fgets (cmd + 2, sizeof (cmd) - 2, 0, NULL) > 0) { + rz_core_cmd (core, cmd, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } break; } break; case 'd': - r_flag_unset_name (core->flags, fs2); + rz_flag_unset_name (core->flags, fs2); break; case 'e': /* TODO: prompt for addr, size, name */ eprintf ("TODO\n"); - r_sys_sleep (1); + rz_sys_sleep (1); break; case '*': - r_core_block_size (core, core->blocksize+16); + rz_core_block_size (core, core->blocksize+16); break; case '/': - r_core_block_size (core, core->blocksize-16); + rz_core_block_size (core, core->blocksize-16); break; case '+': if (menu == 1) { - r_core_cmdf (core, "f %s=%s+1", fs2, fs2); + rz_core_cmdf (core, "f %s=%s+1", fs2, fs2); } else { - r_core_block_size (core, core->blocksize + 1); + rz_core_block_size (core, core->blocksize + 1); } break; case '-': if (menu == 1) { - r_core_cmdf (core, "f %s=%s-1", fs2, fs2); + rz_core_cmdf (core, "f %s=%s-1", fs2, fs2); } else { - r_core_block_size (core, core->blocksize-1); + rz_core_block_size (core, core->blocksize-1); } break; case 'r': // "Vtr" if (menu == 1) { int len; - r_cons_show_cursor (true); - r_cons_set_raw (0); - // TODO: use r_flag_rename or wtf?..fr doesnt uses this.. + rz_cons_show_cursor (true); + rz_cons_set_raw (0); + // TODO: use rz_flag_rename or wtf?..fr doesnt uses this.. snprintf (cmd, sizeof (cmd), "fr %s ", fs2); len = strlen (cmd); eprintf ("Rename flag '%s' as:\n", fs2); - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd + len, sizeof (cmd) - len, 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd + len, sizeof (cmd) - len, 0, NULL) < 0) { cmd[0] = '\0'; } - r_core_cmd (core, cmd, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd (core, cmd, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } break; case 'R': if (menu == 1) { char line[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); eprintf ("Rename function '%s' as:\n", fs2); - r_line_set_prompt (":> "); - if (r_cons_fgets (line, sizeof (line), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (line, sizeof (line), 0, NULL) < 0) { cmd[0] = '\0'; } int res = snprintf (cmd, sizeof (cmd), "afr %s %s", line, fs2); if (res < sizeof (cmd)) { - r_core_cmd (core, cmd, 0); + rz_core_cmd (core, cmd, 0); } - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } break; case 'P': @@ -2099,17 +2099,17 @@ R_API int r_core_visual_trackflags(RCore *core) { case '\n': if (menu == 1) { sprintf (cmd, "s %s", fs2); - r_core_cmd (core, cmd, 0); + rz_core_cmd (core, cmd, 0); return true; } - r_flag_space_set (core->flags, fs); + rz_flag_space_set (core->flags, fs); menu = 1; _option = option; option = 0; break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "\nVF: Visual Flags help:\n\n" " q - quit menu\n" " j/k - line down/up keys\n" @@ -2125,33 +2125,33 @@ R_API int r_core_visual_trackflags(RCore *core) { " p/P - rotate print format\n" " _ - hud for flags and comments\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); *cmd = 0; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) <0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) <0) { *cmd = 0; } cmd[sizeof (cmd) - 1] = 0; - r_core_cmd_task_sync (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd_task_sync (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (*cmd) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } //cons_gotoxy(0,0); - r_cons_clear (); + rz_cons_clear (); continue; } } return true; } -R_API int r_core_visual_comments (RCore *core) { +RZ_API int rz_core_visual_comments (RzCore *core) { char *str; char cmd[512], *p = NULL; int ch, option = 0; @@ -2159,36 +2159,36 @@ R_API int r_core_visual_comments (RCore *core) { ut64 addr, from = 0, size = 0; for (;;) { - r_cons_clear00 (); - r_cons_strcat ("Comments:\n"); + rz_cons_clear00 (); + rz_cons_strcat ("Comments:\n"); RIntervalTreeIter it; - RAnalMetaItem *item; + RzAnalMetaItem *item; i = 0; - r_interval_tree_foreach (&core->anal->meta, it, item) { + rz_interval_tree_foreach (&core->anal->meta, it, item) { if (item->type != R_META_TYPE_COMMENT) { continue; } str = item->str; - addr = r_interval_tree_iter_get (&it)->start; + addr = rz_interval_tree_iter_get (&it)->start; if (option==i) { from = addr; size = 1; // XXX: remove this thing size for comments is useless d->size; free (p); p = strdup (str); - r_cons_printf (" > %s\n", str); + rz_cons_printf (" > %s\n", str); } else { - r_cons_printf (" %s\n", str); + rz_cons_printf (" %s\n", str); } i ++; } if (!i) { if (--option < 0) { - r_cons_any_key ("No comments"); + rz_cons_any_key ("No comments"); break; } continue; } - r_cons_newline (); + rz_cons_newline (); switch (format) { case 0: sprintf (cmd, "px @ 0x%"PFMT64x":64", from); core->printidx = 0; break; @@ -2197,11 +2197,11 @@ R_API int r_core_visual_comments (RCore *core) { default: format = 0; continue; } if (*cmd) { - r_core_cmd (core, cmd, 0); + rz_core_cmd (core, cmd, 0); } - r_cons_visual_flush (); - ch = r_cons_readchar (); - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + rz_cons_visual_flush (); + ch = rz_cons_readchar (); + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'a': //TODO @@ -2211,7 +2211,7 @@ R_API int r_core_visual_comments (RCore *core) { break; case 'd': if (p) { - r_meta_del (core->anal, R_META_TYPE_ANY, from, size); + rz_meta_del (core->anal, R_META_TYPE_ANY, from, size); } break; case 'P': @@ -2243,7 +2243,7 @@ R_API int r_core_visual_comments (RCore *core) { case ' ': case '\r': case '\n': - r_core_cmdf (core, "s 0x%"PFMT64x, from); + rz_core_cmdf (core, "s 0x%"PFMT64x, from); R_FREE (p); return true; case 'Q': @@ -2252,8 +2252,8 @@ R_API int r_core_visual_comments (RCore *core) { return true; case '?': case 'h': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "\nVT: Visual Comments/Anal help:\n\n" " q - quit menu\n" " j/k - down/up keys\n" @@ -2261,8 +2261,8 @@ R_API int r_core_visual_comments (RCore *core) { " l/' ' - accept current selection\n" " a/d/e - add/delete/edit comment/anal symbol\n" " p/P - rotate print format\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; } R_FREE (p); @@ -2270,52 +2270,52 @@ R_API int r_core_visual_comments (RCore *core) { return true; } -static void config_visual_hit_i(RCore *core, const char *name, int delta) { - struct r_config_node_t *node; - node = r_config_node_get (core->config, name); - if (node && r_config_node_is_int (node)) { - int hitDelta = r_config_get_i (core->config, name) + delta; - (void) r_config_set_i (core->config, name, hitDelta); +static void config_visual_hit_i(RzCore *core, const char *name, int delta) { + struct rz_config_node_t *node; + node = rz_config_node_get (core->config, name); + if (node && rz_config_node_is_int (node)) { + int hitDelta = rz_config_get_i (core->config, name) + delta; + (void) rz_config_set_i (core->config, name, hitDelta); } } /* Visually activate the config variable */ -static void config_visual_hit(RCore *core, const char *name, int editor) { +static void config_visual_hit(RzCore *core, const char *name, int editor) { char buf[1024]; RConfigNode *node; - if (!(node = r_config_node_get (core->config, name))) { + if (!(node = rz_config_node_get (core->config, name))) { return; } - if (r_config_node_is_bool (node)) { - r_config_set_i (core->config, name, node->i_value? 0:1); + if (rz_config_node_is_bool (node)) { + rz_config_set_i (core->config, name, node->i_value? 0:1); } else { // XXX: must use config_set () to run callbacks! if (editor) { - char * buf = r_core_editor (core, NULL, node->value); - node->value = r_str_dup (node->value, buf); + char * buf = rz_core_editor (core, NULL, node->value); + node->value = rz_str_dup (node->value, buf); free (buf); } else { // FGETS AND SO - r_cons_printf ("New value (old=%s): \n", node->value); - r_cons_show_cursor (true); - r_cons_flush (); - r_cons_set_raw (0); - r_line_set_prompt (":> "); - r_cons_fgets (buf, sizeof (buf), 0, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); - r_config_set (core->config, name, buf); - //node->value = r_str_dup (node->value, buf); + rz_cons_printf ("New value (old=%s): \n", node->value); + rz_cons_show_cursor (true); + rz_cons_flush (); + rz_cons_set_raw (0); + rz_line_set_prompt (":> "); + rz_cons_fgets (buf, sizeof (buf), 0, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + rz_config_set (core->config, name, buf); + //node->value = rz_str_dup (node->value, buf); } } } -R_API void r_core_visual_config(RCore *core) { +RZ_API void rz_core_visual_config(RzCore *core) { char *fs = NULL, *fs2 = NULL, *desc = NULL; int i, j, ch, hit, show; int option, _option = 0; - RListIter *iter; + RzListIter *iter; RConfigNode *bt; char old[1024]; int delta = 9; @@ -2324,23 +2324,23 @@ R_API void r_core_visual_config(RCore *core) { option = 0; for (;;) { - r_cons_clear00 (); - r_cons_get_size (&delta); + rz_cons_clear00 (); + rz_cons_get_size (&delta); delta /= 4; switch (menu) { case 0: // flag space - r_cons_printf ("[EvalSpace]\n\n"); + rz_cons_printf ("[EvalSpace]\n\n"); hit = j = i = 0; - r_list_foreach (core->config->nodes, iter, bt) { + rz_list_foreach (core->config->nodes, iter, bt) { if (option == i) { fs = bt->name; } if (!old[0]) { - r_str_ccpy (old, bt->name, '.'); + rz_str_ccpy (old, bt->name, '.'); show = 1; - } else if (r_str_ccmp (old, bt->name, '.')) { - r_str_ccpy (old, bt->name, '.'); + } else if (rz_str_ccmp (old, bt->name, '.')) { + rz_str_ccpy (old, bt->name, '.'); show = 1; } else { show = 0; @@ -2350,7 +2350,7 @@ R_API void r_core_visual_config(RCore *core) { hit = 1; } if ( (i >=option-delta) && ((i':' ', old); + rz_cons_printf (" %c %s\n", (option == i)?'>':' ', old); j++; } i++; @@ -2360,15 +2360,15 @@ R_API void r_core_visual_config(RCore *core) { option--; continue; } - r_cons_printf ("\n Sel:%s \n\n", fs); + rz_cons_printf ("\n Sel:%s \n\n", fs); break; case 1: // flag selection - r_cons_printf ("[EvalSpace < Variables: %s]\n\n", fs); + rz_cons_printf ("[EvalSpace < Variables: %s]\n\n", fs); hit = 0; j = i = 0; // TODO: cut -d '.' -f 1 | sort | uniq !!! - r_list_foreach (core->config->nodes, iter, bt) { - if (!r_str_ccmp (bt->name, fs, '.')) { + rz_list_foreach (core->config->nodes, iter, bt) { + if (!rz_str_ccmp (bt->name, fs, '.')) { if (option==i) { fs2 = bt->name; desc = bt->desc; @@ -2376,7 +2376,7 @@ R_API void r_core_visual_config(RCore *core) { } if ( (i>=option-delta) && ((i':' ', bt->name, bt->value); + rz_cons_printf (" %c %s = %s\n", (option==i)?'>':' ', bt->name, bt->value); j++; } i++; @@ -2388,20 +2388,20 @@ R_API void r_core_visual_config(RCore *core) { } if (fs2 != NULL) { // TODO: Break long lines. - r_cons_printf ("\n Selected: %s (%s)\n\n", + rz_cons_printf ("\n Selected: %s (%s)\n\n", fs2, desc); } } if (fs && !strncmp (fs, "asm.", 4)) { - r_core_cmd (core, "pd $r", 0); + rz_core_cmd (core, "pd $r", 0); } - r_cons_visual_flush (); - ch = r_cons_readchar (); + rz_cons_visual_flush (); + ch = rz_cons_readchar (); if (ch == 4 || ch == -1) { return; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'j': option++; break; @@ -2414,7 +2414,7 @@ R_API void r_core_visual_config(RCore *core) { option = _option; break; case '_': - r_core_visual_config_hud (core); + rz_core_visual_config_hud (core); break; case 'Q': case 'q': @@ -2425,8 +2425,8 @@ R_API void r_core_visual_config(RCore *core) { option = _option; break; case '$': - r_core_cmd0 (core, "?$"); - r_cons_any_key (NULL); + rz_core_cmd0 (core, "?$"); + rz_cons_any_key (NULL); break; case '*': case '+': @@ -2451,8 +2451,8 @@ R_API void r_core_visual_config(RCore *core) { } break; case '?': - r_cons_clear00 (); - r_cons_printf ("\nVe: Visual Eval help:\n\n" + rz_cons_clear00 (); + rz_cons_printf ("\nVe: Visual Eval help:\n\n" " q - quit menu\n" " j/k - down/up keys\n" " h/b - go back\n" @@ -2461,32 +2461,32 @@ R_API void r_core_visual_config(RCore *core) { " E - edit variable with 'cfg.editor' (vi?)\n" " +/- - increase/decrease numeric value (* and /, too)\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); { char *cmd = prompt (":> ", NULL); - r_core_cmd (core, cmd, 1); + rz_core_cmd (core, cmd, 1); free (cmd); } - r_cons_set_raw (1); - r_cons_show_cursor (false); - r_cons_any_key (NULL); - r_cons_clear00 (); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + rz_cons_any_key (NULL); + rz_cons_clear00 (); continue; } } } -R_API void r_core_visual_mounts(RCore *core) { - RList *list = NULL; - RFSRoot *fsroot = NULL; - RListIter *iter; - RFSFile *file; - RFSPartition *part; +RZ_API void rz_core_visual_mounts(RzCore *core) { + RzList *list = NULL; + RzFSRoot *fsroot = NULL; + RzListIter *iter; + RzFSFile *file; + RzFSPartition *part; int i, ch, option, mode, partition, dir, delta = 7; char *str, path[4096], buf[1024], *root = NULL; const char *n, *p; @@ -2494,101 +2494,101 @@ R_API void r_core_visual_mounts(RCore *core) { dir = partition = option = mode = 0; for (;;) { /* Clear */ - r_cons_clear00 (); + rz_cons_clear00 (); /* Show */ if (mode == 0) { if (list) { - r_list_free (list); + rz_list_free (list); list = NULL; } - r_cons_printf ("Press '/' to navigate the root filesystem.\nPartitions:\n\n"); - n = r_fs_partition_type_get (partition); - list = r_fs_partitions (core->fs, n, 0); + rz_cons_printf ("Press '/' to navigate the root filesystem.\nPartitions:\n\n"); + n = rz_fs_partition_type_get (partition); + list = rz_fs_partitions (core->fs, n, 0); i = 0; if (list) { - r_list_foreach (list, iter, part) { + rz_list_foreach (list, iter, part) { if ((option-delta <= i) && (i <= option+delta)) { if (option == i) { - r_cons_printf (" > "); + rz_cons_printf (" > "); } else { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n", + rz_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n", part->number, part->type, part->start, part->start+part->length); } i++; } - r_list_free (list); + rz_list_free (list); list = NULL; } else { - r_cons_printf ("Cannot read partition\n"); + rz_cons_printf ("Cannot read partition\n"); } } else if (mode == 1) { - r_cons_printf ("Types:\n\n"); + rz_cons_printf ("Types:\n\n"); for (i=0;;i++) { - n = r_fs_partition_type_get (i); + n = rz_fs_partition_type_get (i); if (!n) { break; } - r_cons_printf ("%s%s\n", (i==partition)?" > ":" ", n); + rz_cons_printf ("%s%s\n", (i==partition)?" > ":" ", n); } } else if (mode == 3) { i = 0; - r_cons_printf ("Mountpoints:\n\n"); - r_list_foreach (core->fs->roots, iter, fsroot) { + rz_cons_printf ("Mountpoints:\n\n"); + rz_list_foreach (core->fs->roots, iter, fsroot) { if (fsroot && (option-delta <= i) && (i <= option+delta)) { - r_cons_printf ("%s %s\n", (option == i)?" > ":" ", + rz_cons_printf ("%s %s\n", (option == i)?" > ":" ", fsroot->path); } i++; } } else { if (root) { - list = r_fs_dir (core->fs, path); + list = rz_fs_dir (core->fs, path); if (list) { - r_cons_printf ("%s:\n\n", path); + rz_cons_printf ("%s:\n\n", path); i = 0; - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { if ((dir-delta <= i) && (i <= dir+delta)) { - r_cons_printf ("%s%c %s\n", (dir == i)?" > ":" ", + rz_cons_printf ("%s%c %s\n", (dir == i)?" > ":" ", file->type, file->name); } i++; } - r_cons_printf ("\n"); - r_list_free (list); + rz_cons_printf ("\n"); + rz_list_free (list); list = NULL; } else { - r_cons_printf ("Cannot open '%s' directory\n", root); + rz_cons_printf ("Cannot open '%s' directory\n", root); } } else { - r_cons_printf ("Root undefined\n"); + rz_cons_printf ("Root undefined\n"); } } if (mode==2) { - r_str_trim_path (path); + rz_str_trim_path (path); str = path + strlen (path); strncat (path, "/", sizeof (path)-strlen (path)-1); - list = r_fs_dir (core->fs, path); - file = r_list_get_n (list, dir); + list = rz_fs_dir (core->fs, path); + file = rz_list_get_n (list, dir); if (file && file->type != 'd') { - r_core_cmdf (core, "px @ 0x%" PFMT64x "!64", file->off); + rz_core_cmdf (core, "px @ 0x%" PFMT64x "!64", file->off); } - r_list_free (list); + rz_list_free (list); list = NULL; *str='\0'; } - r_cons_flush (); + rz_cons_flush (); /* Ask for option */ - ch = r_cons_readchar (); + ch = rz_cons_readchar (); if (ch==-1||ch==4){ free (root); return; } - ch = r_cons_arrow_to_hjkl (ch); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { case '/': R_FREE (root); @@ -2600,66 +2600,66 @@ R_API void r_core_visual_mounts(RCore *core) { case '\r': case '\n': if (mode == 0) { - n = r_fs_partition_type_get (partition); - list = r_fs_partitions (core->fs, n, 0); + n = rz_fs_partition_type_get (partition); + list = rz_fs_partitions (core->fs, n, 0); if (!list) { - r_cons_printf ("Unknown partition\n"); - r_cons_any_key (NULL); - r_cons_flush (); + rz_cons_printf ("Unknown partition\n"); + rz_cons_any_key (NULL); + rz_cons_flush (); break; } - part = r_list_get_n (list, option); + part = rz_list_get_n (list, option); if (!part) { - r_cons_printf ("Unknown partition\n"); - r_cons_any_key (NULL); - r_cons_flush (); + rz_cons_printf ("Unknown partition\n"); + rz_cons_any_key (NULL); + rz_cons_flush (); break; } - p = r_fs_partition_type (n, part->type); + p = rz_fs_partition_type (n, part->type); if (p) { - if (r_fs_mount (core->fs, p, "/root", part->start)) { + if (rz_fs_mount (core->fs, p, "/root", part->start)) { free (root); root = strdup ("/root"); strncpy (path, root, sizeof (path)-1); mode = 2; } else { - r_cons_printf ("Cannot mount partition\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_printf ("Cannot mount partition\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); } } else { - r_cons_printf ("Unknown partition type\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_printf ("Unknown partition type\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); } - r_list_free (list); + rz_list_free (list); list = NULL; } else if (mode == 2){ - r_str_trim_path (path); + rz_str_trim_path (path); strncat (path, "/", sizeof (path)-strlen (path)-1); - list = r_fs_dir (core->fs, path); - file = r_list_get_n (list, dir); + list = rz_fs_dir (core->fs, path); + file = rz_list_get_n (list, dir); if (file) { if (file->type == 'd') { strncat (path, file->name, sizeof (path)-strlen (path)-1); - r_str_trim_path (path); + rz_str_trim_path (path); if (root && strncmp (root, path, strlen (root) - 1)) { strncpy (path, root, sizeof (path) - 1); } } else { - r_core_cmdf (core, "s 0x%"PFMT64x, file->off); - r_fs_umount (core->fs, root); + rz_core_cmdf (core, "s 0x%"PFMT64x, file->off); + rz_fs_umount (core->fs, root); free (root); return; } } else { - r_cons_printf ("Unknown file\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_printf ("Unknown file\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); } } else if (mode == 3) { - fsroot = r_list_get_n (core->fs->roots, option); + fsroot = rz_list_get_n (core->fs->roots, option); if (fsroot) { root = strdup (fsroot->path); strncpy (path, root, sizeof (path)-1); @@ -2685,22 +2685,22 @@ R_API void r_core_visual_mounts(RCore *core) { break; case 'j': if (mode == 0) { - n = r_fs_partition_type_get (partition); - list = r_fs_partitions (core->fs, n, 0); - if (option < r_list_length (list) - 1) { + n = rz_fs_partition_type_get (partition); + list = rz_fs_partitions (core->fs, n, 0); + if (option < rz_list_length (list) - 1) { option++; } } else if (mode == 1) { - if (partition < r_fs_partition_get_size () - 1) { + if (partition < rz_fs_partition_get_size () - 1) { partition++; } } else if (mode == 3) { - if (option < r_list_length (core->fs->roots) - 1) { + if (option < rz_list_length (core->fs->roots) - 1) { option++; } } else { - list = r_fs_dir (core->fs, path); - if (dir < r_list_length (list) - 1) { + list = rz_fs_dir (core->fs, path); + if (dir < rz_list_length (list) - 1) { dir++; } } @@ -2715,9 +2715,9 @@ R_API void r_core_visual_mounts(RCore *core) { } else if (strcmp (path, root)) { strcat (path, "/.."); - r_str_trim_path (path); + rz_str_trim_path (path); } else { - r_fs_umount (core->fs, root); + rz_fs_umount (core->fs, root); mode = 0; } } else if (mode == 1) { @@ -2729,7 +2729,7 @@ R_API void r_core_visual_mounts(RCore *core) { case 'Q': case 'q': if (mode == 2 && root) { - r_fs_umount (core->fs, root); + rz_fs_umount (core->fs, root); mode = 0; } else { return; @@ -2737,37 +2737,37 @@ R_API void r_core_visual_mounts(RCore *core) { break; case 'g': if (mode == 2) { - r_str_trim_path (path); + rz_str_trim_path (path); str = path + strlen (path); strncat (path, "/", sizeof (path)-strlen (path)-1); - list = r_fs_dir (core->fs, path); - file = r_list_get_n (list, dir); + list = rz_fs_dir (core->fs, path); + file = rz_list_get_n (list, dir); if (file && root) { strncat (path, file->name, sizeof (path)-strlen (path)-1); - r_str_trim_path (path); + rz_str_trim_path (path); if (strncmp (root, path, strlen (root) - 1)) { strncpy (path, root, sizeof (path) - 1); } - file = r_fs_open (core->fs, path, false); + file = rz_fs_open (core->fs, path, false); if (file) { - r_fs_read (core->fs, file, 0, file->size); - r_cons_show_cursor (true); - r_cons_set_raw (0); - r_line_set_prompt ("Dump path (ej: /tmp/file): "); - r_cons_fgets (buf, sizeof (buf), 0, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); - r_file_dump (buf, file->data, file->size, 0); - r_fs_close (core->fs, file); - r_cons_printf ("Done\n"); + rz_fs_read (core->fs, file, 0, file->size); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); + rz_line_set_prompt ("Dump path (ej: /tmp/file): "); + rz_cons_fgets (buf, sizeof (buf), 0, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + rz_file_dump (buf, file->data, file->size, 0); + rz_fs_close (core->fs, file); + rz_cons_printf ("Done\n"); } else { - r_cons_printf ("Cannot dump file\n"); + rz_cons_printf ("Cannot dump file\n"); } } else { - r_cons_printf ("Cannot dump file\n"); + rz_cons_printf ("Cannot dump file\n"); } - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); *str='\0'; } break; @@ -2776,107 +2776,107 @@ R_API void r_core_visual_mounts(RCore *core) { option = 0; break; case '?': - r_cons_clear00 (); - r_cons_printf ("\nVM: Visual Mount points help:\n\n"); - r_cons_printf (" q - go back or quit menu\n"); - r_cons_printf (" j/k - down/up keys\n"); - r_cons_printf (" h/l - forward/go keys\n"); - r_cons_printf (" t - choose partition type\n"); - r_cons_printf (" g - dump file\n"); - r_cons_printf (" m - show mountpoints\n"); - r_cons_printf (" : - enter command\n"); - r_cons_printf (" ? - show this help\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_clear00 (); + rz_cons_printf ("\nVM: Visual Mount points help:\n\n"); + rz_cons_printf (" q - go back or quit menu\n"); + rz_cons_printf (" j/k - down/up keys\n"); + rz_cons_printf (" h/l - forward/go keys\n"); + rz_cons_printf (" t - choose partition type\n"); + rz_cons_printf (" g - dump file\n"); + rz_cons_printf (" m - show mountpoints\n"); + rz_cons_printf (" : - enter command\n"); + rz_cons_printf (" ? - show this help\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case ':': - r_cons_show_cursor (true); - r_cons_set_raw (0); - r_line_set_prompt (":> "); - r_cons_fgets (buf, sizeof (buf), 0, 0); - r_cons_set_raw (1); - r_cons_show_cursor (false); - r_core_cmd (core, buf, 1); - r_cons_any_key (NULL); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); + rz_line_set_prompt (":> "); + rz_cons_fgets (buf, sizeof (buf), 0, 0); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + rz_core_cmd (core, buf, 1); + rz_cons_any_key (NULL); break; } } } // helper -static void function_rename(RCore *core, ut64 addr, const char *name) { - RListIter *iter; - RAnalFunction *fcn; +static void function_rename(RzCore *core, ut64 addr, const char *name) { + RzListIter *iter; + RzAnalFunction *fcn; - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { if (fcn->addr == addr) { - r_flag_unset_name (core->flags, fcn->name); + rz_flag_unset_name (core->flags, fcn->name); free (fcn->name); fcn->name = strdup (name); - r_flag_set (core->flags, name, addr, r_anal_function_size_from_entry (fcn)); + rz_flag_set (core->flags, name, addr, rz_anal_function_size_from_entry (fcn)); break; } } } -static void variable_rename (RCore *core, ut64 addr, int vindex, const char *name) { - RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); +static void variable_rename (RzCore *core, ut64 addr, int vindex, const char *name) { + RzAnalFunction* fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); ut64 a_tmp = core->offset; int i = 0; - RListIter *iter; - RList *list = r_anal_var_all_list (core->anal, fcn); - RAnalVar* var; + RzListIter *iter; + RzList *list = rz_anal_var_all_list (core->anal, fcn); + RzAnalVar* var; - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { if (i == vindex) { - r_core_seek (core, addr, false); - r_core_cmd_strf (core, "afvn %s %s", name, var->name); - r_core_seek (core, a_tmp, false); + rz_core_seek (core, addr, false); + rz_core_cmd_strf (core, "afvn %s %s", name, var->name); + rz_core_seek (core, a_tmp, false); break; } ++i; } - r_list_free (list); + rz_list_free (list); } -static void variable_set_type (RCore *core, ut64 addr, int vindex, const char *type) { - RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); - RList *list = r_anal_var_all_list (core->anal, fcn); - RListIter *iter; - RAnalVar* var; +static void variable_set_type (RzCore *core, ut64 addr, int vindex, const char *type) { + RzAnalFunction* fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + RzList *list = rz_anal_var_all_list (core->anal, fcn); + RzListIter *iter; + RzAnalVar* var; - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { if (vindex == 0) { - r_anal_var_set_type (var, type); + rz_anal_var_set_type (var, type); break; } vindex--; } - r_list_free (list); + rz_list_free (list); } // In visual mode, display function list -static ut64 var_functions_show(RCore *core, int idx, int show, int cols) { +static ut64 var_functions_show(RzCore *core, int idx, int show, int cols) { int wdelta = (idx > 5)? idx - 5: 0; char *var_functions; ut64 seek = core->offset; ut64 addr = core->offset; - RAnalFunction *fcn; + RzAnalFunction *fcn; int window, i = 0, print_full_func; - RListIter *iter; + RzListIter *iter; // Adjust the windows size automaticaly - (void)r_cons_get_size (&window); + (void)rz_cons_get_size (&window); window -= 8; // Size of printed things - bool color = r_config_get_i (core->config, "scr.color"); + bool color = rz_config_get_i (core->config, "scr.color"); const char *color_addr = core->cons->context->pal.offset; const char *color_fcn = core->cons->context->pal.fname; - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { print_full_func = true; if (i >= wdelta) { if (i > window + wdelta - 1) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); break; } if (idx == i) { @@ -2885,32 +2885,32 @@ static ut64 var_functions_show(RCore *core, int idx, int show, int cols) { if (show) { char *tmp; if (color) { - var_functions = r_str_newf ("%c%c %s0x%08"PFMT64x"" Color_RESET" %4d %s%s"Color_RESET"", + var_functions = rz_str_newf ("%c%c %s0x%08"PFMT64x"" Color_RESET" %4d %s%s"Color_RESET"", (seek == fcn->addr)?'>':' ', (idx==i)?'*':' ', - color_addr, fcn->addr, r_anal_function_realsize (fcn), + color_addr, fcn->addr, rz_anal_function_realsize (fcn), color_fcn, fcn->name); } else { - var_functions = r_str_newf ("%c%c 0x%08"PFMT64x" %4d %s", + var_functions = rz_str_newf ("%c%c 0x%08"PFMT64x" %4d %s", (seek == fcn->addr)?'>':' ', (idx==i)?'*':' ', - fcn->addr, r_anal_function_realsize (fcn), fcn->name); + fcn->addr, rz_anal_function_realsize (fcn), fcn->name); } if (var_functions) { - if (!r_cons_singleton ()->show_vals) { - int fun_len = r_str_ansi_len (var_functions); + if (!rz_cons_singleton ()->show_vals) { + int fun_len = rz_str_ansi_len (var_functions); int columns = fun_len > cols ? cols - 2 : cols; - tmp = r_str_ansi_crop (var_functions, 0, 0, columns, window); - if (r_str_ansi_len (tmp) < fun_len) { - r_cons_printf ("%s..%s\n", tmp, Color_RESET); + tmp = rz_str_ansi_crop (var_functions, 0, 0, columns, window); + if (rz_str_ansi_len (tmp) < fun_len) { + rz_cons_printf ("%s..%s\n", tmp, Color_RESET); print_full_func = false; } - r_free (tmp); + rz_free (tmp); } if (print_full_func) { - r_cons_println (var_functions); + rz_cons_println (var_functions); } - r_free (var_functions); + rz_free (var_functions); } } } @@ -2920,50 +2920,50 @@ static ut64 var_functions_show(RCore *core, int idx, int show, int cols) { } // In visual mode, display the variables. -static ut64 var_variables_show(RCore* core, int idx, int *vindex, int show, int cols) { +static ut64 var_variables_show(RzCore* core, int idx, int *vindex, int show, int cols) { int i = 0; const ut64 addr = var_functions_show (core, idx, 0, cols); - RAnalFunction* fcn = r_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); + RzAnalFunction* fcn = rz_anal_get_fcn_in (core->anal, addr, R_ANAL_FCN_TYPE_NULL); int window; int wdelta = (idx > 5) ? idx - 5 : 0; - RListIter *iter; - RList *list = r_anal_var_all_list (core->anal, fcn); - RAnalVar* var; + RzListIter *iter; + RzList *list = rz_anal_var_all_list (core->anal, fcn); + RzAnalVar* var; // Adjust the window size automatically. - (void)r_cons_get_size (&window); + (void)rz_cons_get_size (&window); window -= 8; // Size of printed things. // A new line so this looks reasonable. - r_cons_newline (); + rz_cons_newline (); - int llen = r_list_length (list); + int llen = rz_list_length (list); if (*vindex >= llen) { *vindex = llen - 1; } - r_list_foreach (list, iter, var) { + rz_list_foreach (list, iter, var) { if (i >= wdelta) { if (i > window + wdelta) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); break; } if (show) { switch (var->kind & 0xff) { case 'r': { - RRegItem *r = r_reg_index_get (core->anal->reg, var->delta); + RzRegItem *r = rz_reg_index_get (core->anal->reg, var->delta); if (!r) { eprintf ("Register not found"); break; } - r_cons_printf ("%sarg %s %s @ %s\n", + rz_cons_printf ("%sarg %s %s @ %s\n", i == *vindex ? "* ":" ", var->type, var->name, r->name); } break; case 'b': - r_cons_printf ("%s%s %s %s @ %s%s0x%x\n", + rz_cons_printf ("%s%s %s %s @ %s%s0x%x\n", i == *vindex ? "* ":" ", var->delta < 0? "var": "arg", var->type, var->name, @@ -2972,7 +2972,7 @@ static ut64 var_variables_show(RCore* core, int idx, int *vindex, int show, int var->delta); break; case 's': - r_cons_printf ("%s%s %s %s @ %s%s0x%x\n", + rz_cons_printf ("%s%s %s %s @ %s%s0x%x\n", i == *vindex ? "* ":" ", var->delta < 0? "var": "arg", var->type, var->name, @@ -2985,7 +2985,7 @@ static ut64 var_variables_show(RCore* core, int idx, int *vindex, int show, int } ++i; } - r_list_free (list); + rz_list_free (list); return addr; } @@ -3000,13 +3000,13 @@ static const char *printCmds[lastPrintMode] = { "pdf", "pd $r", "afi", "pdsf", "pdc", "pdr" }; -static void r_core_visual_anal_refresh_column (RCore *core, int colpos) { +static void rz_core_visual_anal_refresh_column (RzCore *core, int colpos) { const ut64 addr = (level != 0 && level != 1) ? core->offset : var_functions_show (core, option, 0, colpos); - // RAnalFunction* fcn = r_anal_get_fcn_in(core->anal, addr, R_ANAL_FCN_TYPE_NULL); - int h, w = r_cons_get_size (&h); - // int sz = (fcn)? R_MIN (r_anal_fcn_size (fcn), h * 15) : 16; // max instr is 15 bytes. + // RzAnalFunction* fcn = rz_anal_get_fcn_in(core->anal, addr, R_ANAL_FCN_TYPE_NULL); + int h, w = rz_cons_get_size (&h); + // int sz = (fcn)? R_MIN (rz_anal_fcn_size (fcn), h * 15) : 16; // max instr is 15 bytes. const char *cmd; if (printMode > 0 && printMode < lastPrintMode) { @@ -3014,15 +3014,15 @@ static void r_core_visual_anal_refresh_column (RCore *core, int colpos) { } else { cmd = printCmds[printMode = 0]; } - char *cmdf = r_str_newf ("%s @ 0x%"PFMT64x, cmd, addr + delta); + char *cmdf = rz_str_newf ("%s @ 0x%"PFMT64x, cmd, addr + delta); if (!cmdf) { return; } - char *output = r_core_cmd_str (core, cmdf); + char *output = rz_core_cmd_str (core, cmdf); if (output) { - // 'h - 2' because we have two new lines in r_cons_printf - char *out = r_str_ansi_crop (output, 0, 0, w - colpos, h - 2); - r_cons_printf ("\n%s\n", out); + // 'h - 2' because we have two new lines in rz_cons_printf + char *out = rz_str_ansi_crop (output, 0, 0, w - colpos, h - 2); + rz_cons_printf ("\n%s\n", out); free (out); R_FREE (output); } @@ -3066,29 +3066,29 @@ static const char *help_vv_actions_visual[] = { NULL }; -static void r_core_vmenu_append_help (RStrBuf *p, const char **help) { +static void rz_core_vmenu_append_help (RStrBuf *p, const char **help) { int i; - RConsContext *cons_ctx = r_cons_singleton ()->context; + RzConsContext *cons_ctx = rz_cons_singleton ()->context; const char *pal_args_color = cons_ctx->color_mode ? cons_ctx->pal.args : "", *pal_help_color = cons_ctx->color_mode ? cons_ctx->pal.help : "", *pal_reset = cons_ctx->color_mode ? cons_ctx->pal.reset : ""; for (i = 0; help[i]; i += 2) { - r_strbuf_appendf (p, "%s%s %s%s%s", + rz_strbuf_appendf (p, "%s%s %s%s%s", pal_args_color, help[i], pal_help_color, help[i + 1], pal_reset); } } -static ut64 r_core_visual_anal_refresh (RCore *core) { +static ut64 rz_core_visual_anal_refresh (RzCore *core) { if (!core) { return 0LL; } ut64 addr; RStrBuf *buf; char old[1024]; - bool color = r_config_get_i (core->config, "scr.color"); - int h, cols = r_cons_get_size (&h); + bool color = rz_config_get_i (core->config, "scr.color"); + int h, cols = rz_cons_get_size (&h); old[0] = '\0'; addr = core->offset; cols -= 50; @@ -3096,67 +3096,67 @@ static ut64 r_core_visual_anal_refresh (RCore *core) { cols = 60; } - r_cons_clear00 (); - r_core_visual_anal_refresh_column (core, cols); + rz_cons_clear00 (); + rz_core_visual_anal_refresh_column (core, cols); if (cols > 30) { - r_cons_column (cols); + rz_cons_column (cols); } switch (level) { // Show functions list help in visual mode case 0: - buf = r_strbuf_new (""); + buf = rz_strbuf_new (""); if (color) { - r_cons_strcat (core->cons->context->pal.prompt); + rz_cons_strcat (core->cons->context->pal.prompt); } if (selectPanel) { - r_cons_printf ("-- functions -----------------[ %s ]-->>", printCmds[printMode]); + rz_cons_printf ("-- functions -----------------[ %s ]-->>", printCmds[printMode]); } else { - r_cons_printf ("-[ functions ]----------------- %s ---", printCmds[printMode]); + rz_cons_printf ("-[ functions ]----------------- %s ---", printCmds[printMode]); } if (color) { - r_cons_strcat ("\n" Color_RESET); + rz_cons_strcat ("\n" Color_RESET); } - r_core_vmenu_append_help (buf, help_fun_visual); - r_cons_printf ("%s", r_strbuf_drain (buf)); + rz_core_vmenu_append_help (buf, help_fun_visual); + rz_cons_printf ("%s", rz_strbuf_drain (buf)); addr = var_functions_show (core, option, 1, cols); break; case 1: - buf = r_strbuf_new (""); + buf = rz_strbuf_new (""); if (color) { - r_cons_strcat (core->cons->context->pal.prompt); + rz_cons_strcat (core->cons->context->pal.prompt); } - r_cons_printf ("-[ variables ]----- 0x%08"PFMT64x"", addr); + rz_cons_printf ("-[ variables ]----- 0x%08"PFMT64x"", addr); if (color) { - r_cons_strcat ("\n" Color_RESET); + rz_cons_strcat ("\n" Color_RESET); } - r_core_vmenu_append_help (buf, help_var_visual); - char *drained = r_strbuf_drain (buf); - r_cons_printf ("%s", drained); + rz_core_vmenu_append_help (buf, help_var_visual); + char *drained = rz_strbuf_drain (buf); + rz_cons_printf ("%s", drained); addr = var_variables_show (core, option, &variable_option, 1, cols); free (drained); // var_index_show (core->anal, fcn, addr, option); break; case 2: - r_cons_printf ("Press 'q' to quit call refs\n"); + rz_cons_printf ("Press 'q' to quit call refs\n"); if (color) { - r_cons_strcat (core->cons->context->pal.prompt); + rz_cons_strcat (core->cons->context->pal.prompt); } - r_cons_printf ("-[ calls ]----------------------- 0x%08"PFMT64x" (TODO)\n", addr); + rz_cons_printf ("-[ calls ]----------------------- 0x%08"PFMT64x" (TODO)\n", addr); if (color) { - r_cons_strcat ("\n" Color_RESET); + rz_cons_strcat ("\n" Color_RESET); } // TODO: filter only the callrefs. but we cant grep here sprintf (old, "afi @ 0x%08"PFMT64x, addr); - char *output = r_core_cmd_str (core, old); + char *output = rz_core_cmd_str (core, old); if (output) { - // 'h - 2' because we have two new lines in r_cons_printf - if (!r_cons_singleton ()->show_vals) { - char *out = r_str_ansi_crop(output, 0, 0, cols, h - 2); - r_cons_printf ("\n%s\n", out); + // 'h - 2' because we have two new lines in rz_cons_printf + if (!rz_cons_singleton ()->show_vals) { + char *out = rz_str_ansi_crop(output, 0, 0, cols, h - 2); + rz_cons_printf ("\n%s\n", out); free (out); R_FREE (output); } else { - r_cons_printf ("\n%s\n", output); + rz_cons_printf ("\n%s\n", output); R_FREE (output); } } @@ -3165,48 +3165,48 @@ static ut64 r_core_visual_anal_refresh (RCore *core) { // assert break; } - r_cons_flush (); + rz_cons_flush (); return addr; } -static void r_core_visual_anal_refresh_oneshot (RCore *core) { - r_core_task_enqueue_oneshot (&core->tasks, (RCoreTaskOneShot) r_core_visual_anal_refresh, core); +static void rz_core_visual_anal_refresh_oneshot (RzCore *core) { + rz_core_task_enqueue_oneshot (&core->tasks, (RzCoreTaskOneShot) rz_core_visual_anal_refresh, core); } -static void r_core_visual_debugtraces_help(RCore *core) { - r_cons_clear00 (); - r_cons_printf ( +static void rz_core_visual_debugtraces_help(RzCore *core) { + rz_cons_clear00 (); + rz_cons_printf ( "vbd: Visual Browse Debugtraces:\n\n" " q - quit the bit editor\n" " Q - Quit (jump into the disasm view)\n" " j/k - Select next/previous trace\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); } -R_API void r_core_visual_debugtraces(RCore *core, const char *input) { +RZ_API void rz_core_visual_debugtraces(RzCore *core, const char *input) { int i, delta = 0; for (;;) { - char *trace_addr_str = r_core_cmd_strf (core, "dtdq %d", delta); - ut64 trace_addr = r_num_get (NULL, trace_addr_str); + char *trace_addr_str = rz_core_cmd_strf (core, "dtdq %d", delta); + ut64 trace_addr = rz_num_get (NULL, trace_addr_str); free (trace_addr_str); - r_cons_printf ("[0x%08"PFMT64x"]> %d dbg.trace\n", trace_addr, delta); + rz_cons_printf ("[0x%08"PFMT64x"]> %d dbg.trace\n", trace_addr, delta); for (i = 0; i < delta; i++) { - r_core_cmdf (core, ".dte %d", i); + rz_core_cmdf (core, ".dte %d", i); } - r_core_cmd0 (core, "x 64@r:SP"); - r_core_cmd0 (core, "dri"); + rz_core_cmd0 (core, "x 64@r:SP"); + rz_core_cmd0 (core, "dri"); // limit by rows here - //int rows = r_cons_get_size (NULL); - r_core_cmdf (core, "dtd %d", delta); - r_cons_visual_flush (); + //int rows = rz_cons_get_size (NULL); + rz_core_cmdf (core, "dtd %d", delta); + rz_cons_visual_flush (); char ch ; if (input && *input) { ch = *input; input++; } else { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } if (ch == 4 || ch == -1) { if (level == 0) { @@ -3215,25 +3215,25 @@ R_API void r_core_visual_debugtraces(RCore *core, const char *input) { level--; continue; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'Q': // tab { ut64 oseek = core->offset; core->vmode = false; - r_core_seek (core, trace_addr, true); - r_core_visual (core, ""); - r_core_seek (core, oseek, true); + rz_core_seek (core, trace_addr, true); + rz_core_visual (core, ""); + rz_core_seek (core, oseek, true); } break; case 'q': goto beach; break; case ']': - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") + 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") + 1); break; case '[': - r_config_set_i (core->config, "hex.cols", r_config_get_i (core->config, "hex.cols") - 1); + rz_config_set_i (core->config, "hex.cols", rz_config_get_i (core->config, "hex.cols") - 1); break; case 'J': delta += 10; @@ -3253,11 +3253,11 @@ R_API void r_core_visual_debugtraces(RCore *core, const char *input) { } break; case ':': - r_core_visual_prompt (core); - r_cons_any_key (NULL); + rz_core_visual_prompt (core); + rz_cons_any_key (NULL); break; case '?': - r_core_visual_debugtraces_help (core); + rz_core_visual_debugtraces_help (core); break; } } @@ -3267,23 +3267,23 @@ beach: static char *__prompt(const char *msg, void *p) { char res[128]; - r_cons_show_cursor (true); - r_cons_set_raw (false); - r_line_set_prompt (msg); + rz_cons_show_cursor (true); + rz_cons_set_raw (false); + rz_line_set_prompt (msg); res[0] =0; - if (!r_cons_fgets (res, sizeof (res), 0, NULL)) { + if (!rz_cons_fgets (res, sizeof (res), 0, NULL)) { res[0] = 0; } return strdup (res); } -static void addVar(RCore *core, int ch, const char *msg) { +static void addVar(RzCore *core, int ch, const char *msg) { char *src = __prompt (msg, NULL); char *name = __prompt ("Variable Name: ", NULL); char *type = __prompt ("Type of Variable (int32_t): ", NULL); - char *cmd = r_str_newf ("afv%c %s %s %s", ch, src, name, type); - r_str_trim (cmd); - r_core_cmd0 (core, cmd); + char *cmd = rz_str_newf ("afv%c %s %s %s", ch, src, name, type); + rz_str_trim (cmd); + rz_core_cmd0 (core, cmd); free(cmd); free (src); free (name); @@ -3291,30 +3291,30 @@ static void addVar(RCore *core, int ch, const char *msg) { } /* Like emenu but for real */ -R_API void r_core_visual_anal(RCore *core, const char *input) { +RZ_API void rz_core_visual_anal(RzCore *core, const char *input) { char old[218]; int nfcns, ch, _option = 0; - RConsEvent olde = core->cons->event_resize; + RzConsEvent olde = core->cons->event_resize; void *olde_user = core->cons->event_data; ut64 addr = core->offset; core->cons->event_resize = NULL; // avoid running old event with new data core->cons->event_data = core; - core->cons->event_resize = (RConsEvent) r_core_visual_anal_refresh_oneshot; + core->cons->event_resize = (RzConsEvent) rz_core_visual_anal_refresh_oneshot; level = 0; - int asmbytes = r_config_get_i (core->config, "asm.bytes"); - r_config_set_i (core->config, "asm.bytes", 0); + int asmbytes = rz_config_get_i (core->config, "asm.bytes"); + rz_config_set_i (core->config, "asm.bytes", 0); for (;;) { - nfcns = r_list_length (core->anal->fcns); - addr = r_core_visual_anal_refresh (core); + nfcns = rz_list_length (core->anal->fcns); + addr = rz_core_visual_anal_refresh (core); if (input && *input) { ch = *input; input++; } else { - ch = r_cons_readchar (); + ch = rz_cons_readchar (); } if (ch == 4 || ch == -1) { if (level == 0) { @@ -3323,23 +3323,23 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { level--; continue; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case '[': - r_cons_singleton ()->show_vals = true; + rz_cons_singleton ()->show_vals = true; break; case ']': - r_cons_singleton ()->show_vals = false; + rz_cons_singleton ()->show_vals = false; break; case '?': - r_cons_clear00 (); - RStrBuf *buf = r_strbuf_new (""); - r_cons_println ("|Usage: vv"); - r_core_visual_append_help (buf, "Actions supported", help_vv_actions_visual); - r_core_visual_append_help (buf, "Keys", help_vv_visual); - r_cons_printf ("%s", r_strbuf_drain (buf)); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_clear00 (); + RStrBuf *buf = rz_strbuf_new (""); + rz_cons_println ("|Usage: vv"); + rz_core_visual_append_help (buf, "Actions supported", help_vv_actions_visual); + rz_core_visual_append_help (buf, "Keys", help_vv_visual); + rz_cons_printf ("%s", rz_strbuf_drain (buf)); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case 9: selectPanel = !selectPanel; @@ -3351,23 +3351,23 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { case ':': { ut64 orig = core->offset; - r_core_seek (core, addr, false); - while (r_core_visual_prompt (core)); - r_core_seek (core, orig, false); + rz_core_seek (core, addr, false); + while (rz_core_visual_prompt (core)); + rz_core_seek (core, orig, false); } continue; case '/': - r_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); + rz_core_cmd0 (core, "?i highlight;e scr.highlight=`yp`"); break; case 'a': switch (level) { case 0: - r_core_cmd0 (core, "af-$$;af"); // reanalize + rz_core_cmd0 (core, "af-$$;af"); // reanalize break; case 1: { eprintf ("Select variable source ('r'egister, 's'tackptr or 'b'aseptr): "); - int type = r_cons_readchar (); + int type = rz_cons_readchar (); switch (type) { case 'r': addVar (core, type, "Source Register Name: "); @@ -3387,10 +3387,10 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { { switch (level) { case 1: - r_cons_show_cursor (true); - r_cons_set_raw (false); - r_line_set_prompt ("New name: "); - if (r_cons_fgets (old, sizeof (old), 0, NULL)) { + rz_cons_show_cursor (true); + rz_cons_set_raw (false); + rz_line_set_prompt ("New name: "); + if (rz_cons_fgets (old, sizeof (old), 0, NULL)) { if (*old) { //old[strlen (old)-1] = 0; variable_rename (core, addr, variable_option, old); @@ -3398,8 +3398,8 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { } break; default: - r_line_set_prompt ("New name: "); - if (r_cons_fgets (old, sizeof (old), 0, NULL)) { + rz_line_set_prompt ("New name: "); + if (rz_cons_fgets (old, sizeof (old), 0, NULL)) { if (*old) { //old[strlen (old)-1] = 0; function_rename (core, addr, old); @@ -3407,30 +3407,30 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { } break; } - r_cons_set_raw (true); - r_cons_show_cursor (false); + rz_cons_set_raw (true); + rz_cons_show_cursor (false); } break; case 't': if (level == 1) { - r_cons_show_cursor (true); - r_cons_set_raw (false); - r_line_set_prompt ("New type: "); - if (r_cons_fgets (old, sizeof (old), 0, NULL)) { + rz_cons_show_cursor (true); + rz_cons_set_raw (false); + rz_line_set_prompt ("New type: "); + if (rz_cons_fgets (old, sizeof (old), 0, NULL)) { if (*old) { //old[strlen (old)-1] = 0; variable_set_type (core, addr, variable_option, old); } } - r_cons_set_raw (true); - r_cons_show_cursor (false); + rz_cons_set_raw (true); + rz_cons_show_cursor (false); } break; case '.': delta = 0; break; case 'R': - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); break; case 'p': printMode ++; @@ -3443,23 +3443,23 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { } break; case 'd': - r_core_visual_define(core, "", 0); + rz_core_visual_define(core, "", 0); break; case '-': switch (level) { case 0: - r_core_cmdf (core, "af-0x%"PFMT64x, addr); + rz_core_cmdf (core, "af-0x%"PFMT64x, addr); break; } break; case 'x': - r_core_visual_refs (core, false, true); + rz_core_visual_refs (core, false, true); break; case 'X': - r_core_visual_refs (core, true, true); + rz_core_visual_refs (core, true, true); break; case 's': - r_core_cmdf (core, "afs!@0x%08"PFMT64x, addr); + rz_core_cmdf (core, "afs!@0x%08"PFMT64x, addr); break; case 'c': level = 2; @@ -3470,11 +3470,11 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { break; case '_': { - r_core_cmd0 (core, "s $(afl~...)"); + rz_core_cmd0 (core, "s $(afl~...)"); int n = 0; - RListIter *iter; - RAnalFunction *fcn; - r_list_foreach (core->anal->fcns, iter, fcn) { + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (core->anal->fcns, iter, fcn) { if (fcn->addr == core->offset) { option = n; break; @@ -3507,7 +3507,7 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { { static int sortMode = 0; const char *sortModes[4] = { "aflsa", "aflss", "aflsb", "aflsn" }; - r_core_cmd0 (core, sortModes[sortMode%4]); + rz_core_cmd0 (core, sortModes[sortMode%4]); sortMode++; } break; @@ -3534,7 +3534,7 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { delta += 40; } else { int rows = 0; - r_cons_get_size (&rows); + rz_cons_get_size (&rows); option += (rows - 5); if (option >= nfcns) { option = nfcns - 1; @@ -3547,7 +3547,7 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { delta -= 40; } else { int rows = 0; - r_cons_get_size (&rows); + rz_cons_get_size (&rows); option -= (rows - 5); if (option < 0) { option = 0; @@ -3555,28 +3555,28 @@ R_API void r_core_visual_anal(RCore *core, const char *input) { } break; case 'g': { - r_core_visual_showcursor (core, true); - r_core_visual_offset (core); // change the seek to selected offset - RListIter *iter; // change the current option to selected seek - RAnalFunction *fcn; + rz_core_visual_showcursor (core, true); + rz_core_visual_offset (core); // change the seek to selected offset + RzListIter *iter; // change the current option to selected seek + RzAnalFunction *fcn; int i = 0; - r_list_foreach (core->anal->fcns, iter, fcn) { + rz_list_foreach (core->anal->fcns, iter, fcn) { if (core->offset == fcn->addr){ option = i; } i++; } - r_core_visual_showcursor (core, false); + rz_core_visual_showcursor (core, false); } break; case 'G': - r_core_seek (core, addr, SEEK_SET); + rz_core_seek (core, addr, SEEK_SET); goto beach; case ' ': case '\r': case '\n': level = 0; - r_core_seek (core, addr, SEEK_SET); + rz_core_seek (core, addr, SEEK_SET); goto beach; break; case 'l': @@ -3602,7 +3602,7 @@ beach: core->cons->event_data = olde_user; core->cons->event_resize = olde; level = 0; - r_config_set_i (core->config, "asm.bytes", asmbytes); + rz_config_set_i (core->config, "asm.bytes", asmbytes); } struct seek_flag_offset_t { @@ -3611,7 +3611,7 @@ struct seek_flag_offset_t { bool is_next; }; -static bool seek_flag_offset(RFlagItem *fi, void *user) { +static bool seek_flag_offset(RzFlagItem *fi, void *user) { struct seek_flag_offset_t *u = (struct seek_flag_offset_t *)user; if (u->is_next) { if (fi->offset < *u->next && fi->offset > u->offset) { @@ -3625,72 +3625,72 @@ static bool seek_flag_offset(RFlagItem *fi, void *user) { return true; } -R_API void r_core_seek_next(RCore *core, const char *type) { - RListIter *iter; +RZ_API void rz_core_seek_next(RzCore *core, const char *type) { + RzListIter *iter; ut64 next = UT64_MAX; if (strstr (type, "opc")) { - RAnalOp aop; - if (r_anal_op (core->anal, &aop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { + RzAnalOp aop; + if (rz_anal_op (core->anal, &aop, core->offset, core->block, core->blocksize, R_ANAL_OP_MASK_BASIC)) { next = core->offset + aop.size; } else { eprintf ("Invalid opcode\n"); } } else if (strstr (type, "fun")) { - RAnalFunction *fcni; - r_list_foreach (core->anal->fcns, iter, fcni) { + RzAnalFunction *fcni; + rz_list_foreach (core->anal->fcns, iter, fcni) { if (fcni->addr < next && fcni->addr > core->offset) { next = fcni->addr; } } } else if (strstr (type, "hit")) { - const char *pfx = r_config_get (core->config, "search.prefix"); + const char *pfx = rz_config_get (core->config, "search.prefix"); struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = true }; - r_flag_foreach_prefix (core->flags, pfx, -1, seek_flag_offset, &u); + rz_flag_foreach_prefix (core->flags, pfx, -1, seek_flag_offset, &u); } else { // flags struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = true }; - r_flag_foreach (core->flags, seek_flag_offset, &u); + rz_flag_foreach (core->flags, seek_flag_offset, &u); } if (next != UT64_MAX) { - r_core_seek (core, next, true); + rz_core_seek (core, next, true); } } -R_API void r_core_seek_previous (RCore *core, const char *type) { - RListIter *iter; +RZ_API void rz_core_seek_previous (RzCore *core, const char *type) { + RzListIter *iter; ut64 next = 0; if (strstr (type, "opc")) { - eprintf ("TODO: r_core_seek_previous (opc)\n"); + eprintf ("TODO: rz_core_seek_previous (opc)\n"); } else if (strstr (type, "fun")) { - RAnalFunction *fcni; - r_list_foreach (core->anal->fcns, iter, fcni) { + RzAnalFunction *fcni; + rz_list_foreach (core->anal->fcns, iter, fcni) { if (fcni->addr > next && fcni->addr < core->offset) { next = fcni->addr; } } } else if (strstr (type, "hit")) { - const char *pfx = r_config_get (core->config, "search.prefix"); + const char *pfx = rz_config_get (core->config, "search.prefix"); struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = false }; - r_flag_foreach_prefix (core->flags, pfx, -1, seek_flag_offset, &u); + rz_flag_foreach_prefix (core->flags, pfx, -1, seek_flag_offset, &u); } else { // flags struct seek_flag_offset_t u = { .offset = core->offset, .next = &next, .is_next = false }; - r_flag_foreach (core->flags, seek_flag_offset, &u); + rz_flag_foreach (core->flags, seek_flag_offset, &u); } if (next != 0) { - r_core_seek (core, next, true); + rz_core_seek (core, next, true); } } //define the data at offset according to the type (byte, word...) n times -static void define_data_ntimes (RCore *core, ut64 off, int times, int type) { +static void define_data_ntimes (RzCore *core, ut64 off, int times, int type) { int i = 0; - r_meta_del (core->anal, R_META_TYPE_ANY, off, core->blocksize); + rz_meta_del (core->anal, R_META_TYPE_ANY, off, core->blocksize); if (times < 0) { times = 1; } for (i = 0; i < times; i++, off += type) { - r_meta_set (core->anal, R_META_TYPE_DATA, off, type, ""); + rz_meta_set (core->anal, R_META_TYPE_DATA, off, type, ""); } } @@ -3698,7 +3698,7 @@ static bool isDisasmPrint(int mode) { return (mode == 1 || mode == 2); } -static void handleHints(RCore *core) { +static void handleHints(RzCore *core) { //TODO extend for more anal hints int i = 0; char ch[64] = R_EMPTY; @@ -3706,20 +3706,20 @@ static void handleHints(RCore *core) { ," b [16,32,64] set bits hint" , NULL}; for (i = 0; lines[i]; i++) { - r_cons_fill_line (); - r_cons_printf ("\r%s\n", lines[i]); + rz_cons_fill_line (); + rz_cons_printf ("\r%s\n", lines[i]); } - r_cons_flush (); - r_line_set_prompt ("anal hint: "); - if (r_cons_fgets (ch, sizeof (ch), 0, NULL) > 0) { + rz_cons_flush (); + rz_line_set_prompt ("anal hint: "); + if (rz_cons_fgets (ch, sizeof (ch), 0, NULL) > 0) { switch (ch[0]) { case 'b': { char *arg = ch + 1; - r_str_trim (arg); + rz_str_trim (arg); int bits = atoi (arg); if (bits == 8 || bits == 16 || bits == 32 || bits == 64) { - r_anal_hint_set_bits (core->anal, core->offset, bits); + rz_anal_hint_set_bits (core->anal, core->offset, bits); } } break; @@ -3729,7 +3729,7 @@ static void handleHints(RCore *core) { } } -R_API void r_core_visual_define(RCore *core, const char *args, int distance) { +RZ_API void rz_core_visual_define(RzCore *core, const char *args, int distance) { int plen = core->blocksize; ut64 off = core->offset; int i, h = 0, n, ch, ntotal = 0; @@ -3748,13 +3748,13 @@ R_API void r_core_visual_define(RCore *core, const char *args, int distance) { off += cur; p += cur; } - (void) r_cons_get_size (&h); + (void) rz_cons_get_size (&h); h -= 19; if (h < 0) { h = 0; - r_cons_clear00 (); + rz_cons_clear00 (); } else { - r_cons_gotoxy (0, 3); + rz_cons_gotoxy (0, 3); } const char *lines[] = { "" ,"[Vd]- Define current block as:" @@ -3793,10 +3793,10 @@ R_API void r_core_visual_define(RCore *core, const char *args, int distance) { ," z zone flag" , NULL}; for (i = 0; lines[i]; i++) { - r_cons_fill_line (); - r_cons_printf ("\r%s\n", lines[i]); + rz_cons_fill_line (); + rz_cons_printf ("\r%s\n", lines[i]); } - r_cons_flush (); + rz_cons_flush (); int wordsize = 0; // get ESC+char, return 'hjkl' char repeat: @@ -3804,69 +3804,69 @@ repeat: ch = *args; args++; } else { - ch = r_cons_arrow_to_hjkl (r_cons_readchar ()); + ch = rz_cons_arrow_to_hjkl (rz_cons_readchar ()); } onemoretime: wordsize = 4; switch (ch) { case 'N': - r_core_cmdf (core, "afs! @ 0x%08"PFMT64x, off); + rz_core_cmdf (core, "afs! @ 0x%08"PFMT64x, off); break; case 'F': { char cmd[128]; - r_cons_show_cursor (true); - r_core_cmd0 (core, "pf?"); - r_cons_flush (); - r_line_set_prompt ("format: "); + rz_cons_show_cursor (true); + rz_core_cmd0 (core, "pf?"); + rz_cons_flush (); + rz_line_set_prompt ("format: "); strcpy (cmd, "Cf 0 "); - if (r_cons_fgets (cmd + 5, sizeof (cmd) - 5, 0, NULL) > 0) { - r_core_cmdf (core, "%s @ 0x%08"PFMT64x, cmd, off); - r_cons_set_raw (1); - r_cons_show_cursor (false); + if (rz_cons_fgets (cmd + 5, sizeof (cmd) - 5, 0, NULL) > 0) { + rz_core_cmdf (core, "%s @ 0x%08"PFMT64x, cmd, off); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } } break; case '1': - r_core_visual_bit_editor (core); + rz_core_visual_bit_editor (core); break; case 't': case 'o': { char str[128]; - r_cons_show_cursor (true); - r_line_set_prompt (ch=='t'?"type: ": "opstr: "); - if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ah%c %s @ 0x%"PFMT64x, ch, str, off); + rz_cons_show_cursor (true); + rz_line_set_prompt (ch=='t'?"type: ": "opstr: "); + if (rz_cons_fgets (str, sizeof (str), 0, NULL) > 0) { + rz_core_cmdf (core, "ah%c %s @ 0x%"PFMT64x, ch, str, off); } } break; case 'x': - r_core_cmd0 (core, "/r $$"); + rz_core_cmd0 (core, "/r $$"); break; case 'i': { char str[128]; - r_cons_show_cursor (true); - r_line_set_prompt ("immbase: "); - if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ahi %s @ 0x%"PFMT64x, str, off); + rz_cons_show_cursor (true); + rz_line_set_prompt ("immbase: "); + if (rz_cons_fgets (str, sizeof (str), 0, NULL) > 0) { + rz_core_cmdf (core, "ahi %s @ 0x%"PFMT64x, str, off); } } break; case 'I': { char str[128]; - r_cons_show_cursor (true); - r_line_set_prompt ("immbase: "); - if (r_cons_fgets (str, sizeof (str), 0, NULL) > 0) { - r_core_cmdf (core, "ahi1 %s @ 0x%"PFMT64x, str, off); + rz_cons_show_cursor (true); + rz_line_set_prompt ("immbase: "); + if (rz_cons_fgets (str, sizeof (str), 0, NULL) > 0) { + rz_core_cmdf (core, "ahi1 %s @ 0x%"PFMT64x, str, off); } } break; case 'a': - r_core_visual_asm (core, off); + rz_core_visual_asm (core, off); break; case 'b': if (plen != core->blocksize) { @@ -3900,159 +3900,159 @@ onemoretime: { char *man = NULL; /* check for manpage */ - RAnalOp *op = r_core_anal_op (core, off, R_ANAL_OP_MASK_BASIC); + RzAnalOp *op = rz_core_anal_op (core, off, R_ANAL_OP_MASK_BASIC); if (op) { if (op->jump != UT64_MAX) { - RFlagItem *item = r_flag_get_i (core->flags, op->jump); + RzFlagItem *item = rz_flag_get_i (core->flags, op->jump); if (item) { - const char *ptr = r_str_lchr (item->name, '.'); + const char *ptr = rz_str_lchr (item->name, '.'); if (ptr) { man = strdup (ptr + 1); } } } - r_anal_op_free (op); + rz_anal_op_free (op); } if (man) { char *p = strstr (man, "INODE"); if (p) { *p = 0; } - r_cons_clear (); - r_cons_flush (); - r_sys_cmdf ("man %s", man); + rz_cons_clear (); + rz_cons_flush (); + rz_sys_cmdf ("man %s", man); free (man); } - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } break; case 'n': { - RAnalOp op; + RzAnalOp op; char *q = NULL; ut64 tgt_addr = UT64_MAX; if (!isDisasmPrint (core->printidx)) { break; } // TODO: get the aligned instruction even if the cursor is in the middle of it. - r_anal_op (core->anal, &op, off, + rz_anal_op (core->anal, &op, off, core->block + off - core->offset, 32, R_ANAL_OP_MASK_BASIC); tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr; - RAnalVar *var = r_anal_get_used_function_var (core->anal, op.addr); + RzAnalVar *var = rz_anal_get_used_function_var (core->anal, op.addr); if (var) { -// q = r_str_newf ("?i Rename variable %s to;afvn %s `yp`", op.var->name, op.var->name); - char *newname = r_cons_input (sdb_fmt ("New variable name for '%s': ", var->name)); +// q = rz_str_newf ("?i Rename variable %s to;afvn %s `yp`", op.var->name, op.var->name); + char *newname = rz_cons_input (sdb_fmt ("New variable name for '%s': ", var->name)); if (newname && *newname) { - r_anal_var_rename (var, newname, true); + rz_anal_var_rename (var, newname, true); free (newname); } } else if (tgt_addr != UT64_MAX) { - RAnalFunction *fcn = r_anal_get_function_at (core->anal, tgt_addr); - RFlagItem *f = r_flag_get_i (core->flags, tgt_addr); + RzAnalFunction *fcn = rz_anal_get_function_at (core->anal, tgt_addr); + RzFlagItem *f = rz_flag_get_i (core->flags, tgt_addr); if (fcn) { - q = r_str_newf ("?i Rename function %s to;afn `yp` 0x%"PFMT64x, + q = rz_str_newf ("?i Rename function %s to;afn `yp` 0x%"PFMT64x, fcn->name, tgt_addr); } else if (f) { - q = r_str_newf ("?i Rename flag %s to;fr %s `yp`", + q = rz_str_newf ("?i Rename flag %s to;fr %s `yp`", f->name, f->name); } else { - q = r_str_newf ("?i Create flag at 0x%"PFMT64x" named;f `yp` @ 0x%"PFMT64x, + q = rz_str_newf ("?i Create flag at 0x%"PFMT64x" named;f `yp` @ 0x%"PFMT64x, tgt_addr, tgt_addr); } } if (q) { - r_core_cmd0 (core, q); + rz_core_cmd0 (core, q); free (q); } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); break; } case 'C': { - RFlagItem *item = r_flag_get_i (core->flags, off); + RzFlagItem *item = rz_flag_get_i (core->flags, off); if (item) { char cmd[128]; - r_cons_show_cursor (true); - r_cons_flush (); - r_line_set_prompt ("color: "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) > 0) { - r_flag_item_set_color (item, cmd); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_cons_show_cursor (true); + rz_cons_flush (); + rz_line_set_prompt ("color: "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) > 0) { + rz_flag_item_set_color (item, cmd); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } } else { eprintf ("Sorry. No flag here\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } } break; case '$': { - RFlagItem *item = r_flag_get_i (core->flags, off); + RzFlagItem *item = rz_flag_get_i (core->flags, off); if (item) { char cmd[128]; - r_cons_printf ("Current flag size is: %d\n", item->size); - r_cons_show_cursor (true); - r_cons_flush (); - r_line_set_prompt ("new size: "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) > 0) { - item->size = r_num_math (core->num, cmd); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_cons_printf ("Current flag size is: %d\n", item->size); + rz_cons_show_cursor (true); + rz_cons_flush (); + rz_line_set_prompt ("new size: "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) > 0) { + item->size = rz_num_math (core->num, cmd); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); } } else { eprintf ("Sorry. No flag here\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } } break; case 'e': // set function size { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, off, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, off, 0); if (!fcn) { - fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); } if (fcn) { - RAnalOp op; + RzAnalOp op; ut64 size; - if (r_anal_op (core->anal, &op, off, core->block+delta, + if (rz_anal_op (core->anal, &op, off, core->block+delta, core->blocksize-delta, R_ANAL_OP_MASK_BASIC)) { size = off - fcn->addr + op.size; - r_anal_function_resize (fcn, size); + rz_anal_function_resize (fcn, size); } } } break; case 'j': - r_core_cmdf (core, "afm $$+$F @0x%08"PFMT64x, off); + rz_core_cmdf (core, "afm $$+$F @0x%08"PFMT64x, off); break; case 'k': eprintf ("TODO: merge up\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); break; // very weak and incomplete case 'h': // "Vdh" handleHints (core); break; case 'r': // "Vdr" - r_core_cmdf (core, "?i new function name;afn `yp` @ 0x%08"PFMT64x, off); + rz_core_cmdf (core, "?i new function name;afn `yp` @ 0x%08"PFMT64x, off); break; case 'z': // "Vdz" - r_core_cmdf (core, "?i zone name;fz `yp` @ 0x%08"PFMT64x, off); + rz_core_cmdf (core, "?i zone name;fz `yp` @ 0x%08"PFMT64x, off); break; case 'R': // "VdR" eprintf ("Finding references to 0x%08"PFMT64x" ...\n", off); - r_core_cmdf (core, "./r 0x%08"PFMT64x" @ $S", off); + rz_core_cmdf (core, "./r 0x%08"PFMT64x" @ $S", off); break; case 'S': { int i, j; bool is_wide = false; do { - n = r_str_nlen_w ((const char *)p + ntotal, + n = rz_str_nlen_w ((const char *)p + ntotal, plen - ntotal) + 1; if (n < 2) { break; @@ -4077,16 +4077,16 @@ onemoretime: } name[4 + n] = '\0'; if (is_wide) { - r_meta_set (core->anal, R_META_TYPE_STRING, + rz_meta_set (core->anal, R_META_TYPE_STRING, off + ntotal, (n * 2) + ntotal, (const char *) name + 4); } else { - r_meta_set (core->anal, R_META_TYPE_STRING, + rz_meta_set (core->anal, R_META_TYPE_STRING, off + ntotal, n + ntotal, (const char *) name + 4); } - r_name_filter (name, n + 10); - r_flag_set (core->flags, name, off + ntotal, n); + rz_name_filter (name, n + 10); + rz_flag_set (core->flags, name, off + ntotal, n); free (name); if (is_wide) { ntotal += n * 2 - 1; @@ -4104,7 +4104,7 @@ onemoretime: if (core->print->ocur != -1) { n = plen; } else { - n = r_str_nlen_w ((const char*)p, plen) + 1; + n = rz_str_nlen_w ((const char*)p, plen) + 1; } name = malloc (n + 10); if (!name) { @@ -4130,51 +4130,51 @@ onemoretime: //handle wide strings //memcpy (name + 4, (const char *)p, n); if (is_wide) { - r_meta_set (core->anal, R_META_TYPE_STRING, off, + rz_meta_set (core->anal, R_META_TYPE_STRING, off, n * 2, (const char *) name + 4); } else { - r_meta_set (core->anal, R_META_TYPE_STRING, off, + rz_meta_set (core->anal, R_META_TYPE_STRING, off, n, (const char *) name + 4); } - r_name_filter (name, n + 10); - r_flag_set (core->flags, name, off, n); + rz_name_filter (name, n + 10); + rz_flag_set (core->flags, name, off, n); wordsize = n; free (name); } break; case 'd': // TODO: check - r_meta_del (core->anal, R_META_TYPE_ANY, off, plen); - r_meta_set (core->anal, R_META_TYPE_DATA, off, plen, ""); + rz_meta_del (core->anal, R_META_TYPE_ANY, off, plen); + rz_meta_set (core->anal, R_META_TYPE_DATA, off, plen, ""); break; case 'c': // TODO: check - r_meta_del (core->anal, R_META_TYPE_ANY, off, plen); - r_meta_set (core->anal, R_META_TYPE_CODE, off, plen, ""); + rz_meta_del (core->anal, R_META_TYPE_ANY, off, plen); + rz_meta_set (core->anal, R_META_TYPE_CODE, off, plen, ""); break; case 'u': - r_core_anal_undefine (core, off); + rz_core_anal_undefine (core, off); break; case 'f': { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, 0); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, core->offset, 0); if (fcn) { - r_anal_function_resize (fcn, core->offset - fcn->addr); + rz_anal_function_resize (fcn, core->offset - fcn->addr); } - r_cons_break_push (NULL, NULL); - r_core_cmdf (core, "af @ 0x%08" PFMT64x, off); // required for thumb autodetection - r_cons_break_pop (); + rz_cons_break_push (NULL, NULL); + rz_core_cmdf (core, "af @ 0x%08" PFMT64x, off); // required for thumb autodetection + rz_cons_break_pop (); } break; case 'v': { ut64 N; char *endptr = NULL; - char *end_off = r_cons_input ("Last hexadecimal digits of instruction: "); + char *end_off = rz_cons_input ("Last hexadecimal digits of instruction: "); if (end_off) { N = strtoull (end_off, &endptr, 16); } if (!end_off || end_off == endptr) { eprintf ("Invalid numeric input\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); free (end_off); break; } @@ -4198,32 +4198,32 @@ onemoretime: } ut64 try_off; - RAnalOp *op = NULL; - RAnalVar *var = NULL; + RzAnalOp *op = NULL; + RzAnalVar *var = NULL; for (try_off = start_off; try_off < start_off + incr*16; try_off += incr) { - r_anal_op_free (op); - op = r_core_anal_op (core, try_off, R_ANAL_OP_MASK_ALL); + rz_anal_op_free (op); + op = rz_core_anal_op (core, try_off, R_ANAL_OP_MASK_ALL); if (!op) { break; } - var = r_anal_get_used_function_var (core->anal, op->addr); + var = rz_anal_get_used_function_var (core->anal, op->addr); if (var) { break; } } if (var) { - char *newname = r_cons_input (sdb_fmt ("New variable name for '%s': ", var->name)); + char *newname = rz_cons_input (sdb_fmt ("New variable name for '%s': ", var->name)); if (newname && *newname) { - r_anal_var_rename (var, newname, true); + rz_anal_var_rename (var, newname, true); free (newname); } } else { eprintf ("Cannot find instruction with a variable\n"); - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } - r_anal_op_free (op); + rz_anal_op_free (op); break; } case 'Q': @@ -4245,24 +4245,24 @@ onemoretime: } } -R_API void r_core_visual_colors(RCore *core) { +RZ_API void rz_core_visual_colors(RzCore *core) { char *color = calloc (1, 64), cstr[32]; char preview_cmd[128] = "pd $r"; int ch, opt = 0, oopt = -1; - bool truecolor = r_cons_singleton ()->context->color_mode == COLOR_MODE_16M; + bool truecolor = rz_cons_singleton ()->context->color_mode == COLOR_MODE_16M; char *rgb_xxx_fmt = truecolor ? "rgb:%2.2x%2.2x%2.2x ":"rgb:%x%x%x "; const char *k; RColor rcolor; - r_cons_show_cursor (false); - rcolor = r_cons_pal_get_i (opt); + rz_cons_show_cursor (false); + rcolor = rz_cons_pal_get_i (opt); for (;;) { - r_cons_clear (); - r_cons_gotoxy (0, 0); - k = r_cons_pal_get_name (opt); + rz_cons_clear (); + rz_cons_gotoxy (0, 0); + k = rz_cons_pal_get_name (opt); if (!k) { opt = 0; - k = r_cons_pal_get_name (opt); + k = rz_cons_pal_get_name (opt); } if (!truecolor) { rcolor.r &= 0xf; @@ -4281,40 +4281,40 @@ R_API void r_core_visual_colors(RCore *core) { } sprintf (color, rgb_xxx_fmt, rcolor.r, rcolor.g, rcolor.b); if (rcolor.r2 || rcolor.g2 || rcolor.b2) { - color = r_str_appendf (color, rgb_xxx_fmt, rcolor.r2, rcolor.g2, rcolor.b2); + color = rz_str_appendf (color, rgb_xxx_fmt, rcolor.r2, rcolor.g2, rcolor.b2); rcolor.a = ALPHA_FGBG; } else { rcolor.a = ALPHA_FG; } - r_cons_rgb_str (cstr, sizeof (cstr), &rcolor); + rz_cons_rgb_str (cstr, sizeof (cstr), &rcolor); char *esc = strchr (cstr + 1, '\x1b'); - char *curtheme = r_core_get_theme (); + char *curtheme = rz_core_get_theme (); - r_cons_printf ("# Use '.' to randomize current color and ':' to randomize palette\n"); - r_cons_printf ("# Press '"Color_RED"rR"Color_GREEN"gG"Color_BLUE"bB"Color_RESET + rz_cons_printf ("# Use '.' to randomize current color and ':' to randomize palette\n"); + rz_cons_printf ("# Press '"Color_RED"rR"Color_GREEN"gG"Color_BLUE"bB"Color_RESET "' or '"Color_BGRED"eE"Color_BGGREEN"fF"Color_BGBLUE"vV"Color_RESET "' to change foreground/background color\n"); - r_cons_printf ("# Export colorscheme with command 'ec* > filename'\n"); - r_cons_printf ("# Preview command: '%s' - Press 'c' to change it\n", preview_cmd); - r_cons_printf ("# Selected colorscheme : %s - Use 'hl' or left/right arrow keys to change colorscheme\n", curtheme ? curtheme : "default"); - r_cons_printf ("# Selected element: %s - Use 'jk' or up/down arrow keys to change element\n", k); - r_cons_printf ("# ec %s %s # %d (\\x1b%.*s)", + rz_cons_printf ("# Export colorscheme with command 'ec* > filename'\n"); + rz_cons_printf ("# Preview command: '%s' - Press 'c' to change it\n", preview_cmd); + rz_cons_printf ("# Selected colorscheme : %s - Use 'hl' or left/right arrow keys to change colorscheme\n", curtheme ? curtheme : "default"); + rz_cons_printf ("# Selected element: %s - Use 'jk' or up/down arrow keys to change element\n", k); + rz_cons_printf ("# ec %s %s # %d (\\x1b%.*s)", k, color, atoi (cstr+7), esc ? esc - cstr - 1 : strlen (cstr + 1), cstr+1); if (esc) { - r_cons_printf (" (\\x1b%s)", esc + 1); + rz_cons_printf (" (\\x1b%s)", esc + 1); } - r_cons_newline (); + rz_cons_newline (); - r_core_cmdf (core, "ec %s %s", k, color); - char * res = r_core_cmd_str (core, preview_cmd); - int h, w = r_cons_get_size (&h); - char *body = r_str_ansi_crop (res, 0, 0, w, h - 8); + rz_core_cmdf (core, "ec %s %s", k, color); + char * res = rz_core_cmd_str (core, preview_cmd); + int h, w = rz_cons_get_size (&h); + char *body = rz_str_ansi_crop (res, 0, 0, w, h - 8); if (body) { - r_cons_printf ("\n%s", body); + rz_cons_printf ("\n%s", body); } - r_cons_flush (); - ch = r_cons_readchar (); - ch = r_cons_arrow_to_hjkl (ch); + rz_cons_flush (); + ch = rz_cons_readchar (); + ch = rz_cons_arrow_to_hjkl (ch); switch (ch) { #define CASE_RGB(x,X,y) \ case x:if ((y) > 0x00) { (y)--; } break;\ @@ -4337,35 +4337,35 @@ R_API void r_core_visual_colors(RCore *core) { opt++; break; case 'l': - r_core_cmd0 (core, "ecn"); + rz_core_cmd0 (core, "ecn"); oopt = -1; break; case 'h': - r_core_cmd0 (core, "ecp"); + rz_core_cmd0 (core, "ecp"); oopt = -1; break; case 'K': opt = 0; break; case 'J': - opt = r_cons_pal_len () - 1; + opt = rz_cons_pal_len () - 1; break; case ':': - r_cons_pal_random (); + rz_cons_pal_random (); break; case '.': - rcolor.r = r_num_rand (0xff); - rcolor.g = r_num_rand (0xff); - rcolor.b = r_num_rand (0xff); + rcolor.r = rz_num_rand (0xff); + rcolor.g = rz_num_rand (0xff); + rcolor.b = rz_num_rand (0xff); break; case 'c': - r_line_set_prompt ("Preview command> "); - r_cons_show_cursor (true); - r_cons_fgets (preview_cmd, sizeof (preview_cmd), 0, NULL); - r_cons_show_cursor (false); + rz_line_set_prompt ("Preview command> "); + rz_cons_show_cursor (true); + rz_cons_fgets (preview_cmd, sizeof (preview_cmd), 0, NULL); + rz_cons_show_cursor (false); } if (opt != oopt) { - rcolor = r_cons_pal_get_i (opt); + rcolor = rz_cons_pal_get_i (opt); oopt = opt; } free (body); diff --git a/librz/core/vmenus_graph.c b/librz/core/vmenus_graph.c new file mode 100644 index 0000000000..d18abb8c74 --- /dev/null +++ b/librz/core/vmenus_graph.c @@ -0,0 +1,425 @@ +/* radare - LGPL - Copyright 2019 - pancake */ + +#include +#define SORT_ADDRESS 0 +#define SORT_NAME 1 + +// find a better name and move to rz_util or rz_cons? +RZ_API char *rz_str_widget_list(void *user, RzList *list, int rows, int cur, PrintItemCallback cb) { + void *item; + RStrBuf *sb = rz_strbuf_new (""); + RzListIter *iter; + int count = 0; + int skip = 0; + if (cur > (rows / 2)) { + skip = cur - (rows / 2); + } + rz_list_foreach (list, iter, item) { + if (rows >= 0) { + if (skip > 0) { + skip--; + } else { + char *line = cb (user, item, cur == count); + if (line) { + rz_strbuf_appendf (sb, "%s", line); + free (line); + } + rows--; + if (rows == 0) { + break; + } + } + } + count++; + } + return rz_strbuf_drain (sb); +} + +typedef struct { + ut64 addr; + RzAnalFunction *fcn; + int cur; // current row selected + int cur_sort; // holds current sort + RzCore *core; + RzList *mainCol; + RzList *xrefsCol; + RzList *refsCol; +} RzCoreVisualViewGraph; + +typedef struct { + ut64 addr; + const char *name; + RzAnalFunction *fcn; +} RzCoreVisualViewGraphItem; + +static char *print_item(void *_core, void *_item, bool selected) { + RzCoreVisualViewGraphItem *item = _item; + if (item->name && *item->name) { + if (false && item->fcn && item->addr > item->fcn->addr) { + st64 delta = item->addr - item->fcn->addr; + return rz_str_newf ("%c %s+0x%"PFMT64x"\n", selected?'>':' ', item->name, delta); + } else { + return rz_str_newf ("%c %s\n", selected?'>':' ', item->name); + } + } + return rz_str_newf ("%c 0x%08"PFMT64x"\n", selected?'>':' ', item->addr); +} + +static RzList *__xrefs(RzCore *core, ut64 addr) { + RzList *r = rz_list_newf (free); + RzListIter *iter; + RzAnalRef *ref; + RzList *xrefs = rz_anal_xrefs_get (core->anal, addr); + rz_list_foreach (xrefs, iter, ref) { + if (ref->type != 'C') { + continue; + } + RzCoreVisualViewGraphItem *item = R_NEW0 (RzCoreVisualViewGraphItem); + RzFlagItem *f = rz_flag_get_at (core->flags, ref->addr, 0); + item->addr = ref->addr; + item->name = f? f->name: NULL; + RzAnalFunction *rf = rz_anal_get_fcn_in (core->anal, ref->addr, 0); + item->fcn = rf; + if (rf) { + item->name = rf->name; + } + rz_list_append (r, item); + } + return r; +} + +static RzList *__refs(RzCore *core, ut64 addr) { + RzList *r = rz_list_newf (free); + RzListIter *iter; + RzAnalRef *ref; + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, addr, 0); + if (!fcn) { + return r; + } + RzList *refs = rz_anal_function_get_refs (fcn); + rz_list_foreach (refs, iter, ref) { + if (ref->type != 'C') { + continue; + } + RzCoreVisualViewGraphItem *item = R_NEW0 (RzCoreVisualViewGraphItem); + RzFlagItem *f = rz_flag_get_at (core->flags, ref->addr, 0); + item->addr = ref->addr; + item->name = f? f->name: NULL; + RzAnalFunction *rf = rz_anal_get_fcn_in (core->anal, ref->addr, 0); + if (rf) { + item->name = rf->name; + item->fcn = rf; + } + rz_list_append (r, item); + } + return r; +} + +static RzList *__fcns(RzCore *core) { + RzList *r = rz_list_newf (free); + RzListIter *iter; + RzAnalFunction *fcn; + rz_list_foreach (core->anal->fcns, iter, fcn) { + RzCoreVisualViewGraphItem *item = R_NEW0 (RzCoreVisualViewGraphItem); + item->addr = fcn->addr; + item->name = fcn->name; + item->fcn = fcn; + rz_list_append (r, item); + } + return r; // core->anal->fcns; +} + +static void __seek_cursor(RzCoreVisualViewGraph *status) { + ut64 target = 0; + if (status->fcn) { + target = status->fcn->addr; + } else { + target = status->addr; + } + + RzListIter *iter; + RzCoreVisualViewGraphItem *item; + int cur = 0; + rz_list_foreach (status->mainCol, iter, item) { + if (target == item->addr) { + status->cur = cur; + } + cur++; + } + return; +} + +static int cmpaddr (const void *_a, const void *_b) { + const RzCoreVisualViewGraphItem *a = _a, *b = _b; + return a->addr - b->addr; +} + +static int cmpname (const void *_a, const void *_b) { + const RzCoreVisualViewGraphItem *a = _a, *b = _b; + if (!a || !b || !a->name || !b->name) { + return 0; + } + return (int)strcmp (a->name, b->name); +} + +static void __sort (RzCoreVisualViewGraph *status, RzList *list) { + rz_return_if_fail (status && list); + RzListComparator cmp = (status->cur_sort == SORT_ADDRESS)? cmpaddr: cmpname; + list->sorted = false; + rz_list_sort (list, cmp); +} + +static void __toggleSort (RzCoreVisualViewGraph *status) { + rz_return_if_fail (status); + status->cur_sort = (status->cur_sort == SORT_ADDRESS)? SORT_NAME: SORT_ADDRESS; + __sort (status, status->mainCol); + __sort (status, status->refsCol); + __sort (status, status->xrefsCol); + __seek_cursor (status); +} + +static void __reset_status(RzCoreVisualViewGraph *status) { + status->addr = status->core->offset; + status->fcn = rz_anal_get_function_at (status->core->anal, status->addr); + + status->mainCol = __fcns (status->core); + __sort (status, status->mainCol); + __seek_cursor (status); + + return; +} + +static void __sync_status_with_cursor(RzCoreVisualViewGraph *status) { + RzCoreVisualViewGraphItem *item = rz_list_get_n (status->mainCol, status->cur); + if (!item) { + rz_list_free (status->mainCol); + __reset_status (status); + return; + } + + status->addr = item->addr; + status->fcn = item->fcn; + + // Update xrefs and refs columns based on selected element in fcns column + if (status->fcn && status->fcn->addr) { + status->xrefsCol = __xrefs (status->core, status->fcn->addr); + status->refsCol = __refs (status->core, status->fcn->addr); + } else { + status->xrefsCol = __xrefs (status->core, status->addr); + status->refsCol = rz_list_newf (free); + } + __sort (status, status->xrefsCol); + __sort (status, status->refsCol); +} + +RZ_API int __core_visual_view_graph_update(RzCore *core, RzCoreVisualViewGraph *status) { + int h, w = rz_cons_get_size (&h); + const int colw = w / 4; + const int colh = h / 2; + const int colx = w / 3; + rz_cons_clear00 (); + + char *xrefsColstr = rz_str_widget_list (core, status->xrefsCol, colh, 0, print_item); + char *mainColstr = rz_str_widget_list (core, status->mainCol, colh, status->cur, print_item); + char *refsColstr = rz_str_widget_list (core, status->refsCol, colh, 0, print_item); + + /* if (rz_list_empty (status->xrefsCol) && rz_list_empty (status->refsCol)) { */ + /* // We've found ourselves in a bad state, reset the view */ + /* rz_list_free (status->mainCol); */ + /* __reset_status (status); */ + /* } */ + + char *title = rz_str_newf ("[r2-visual-browser] addr=0x%08"PFMT64x" faddr=0x%08"PFMT64x"", status->addr, status->fcn ? status->fcn->addr : 0); + if (title) { + rz_cons_strcat_at (title, 0, 0, w - 1, 2); + free (title); + } + rz_cons_strcat_at (xrefsColstr, 0, 2, colw, colh); + rz_cons_strcat_at (mainColstr, colx, 2, colw*2, colh); + rz_cons_strcat_at (refsColstr, colx * 2, 2, colw, colh); + + char *output = rz_core_cmd_strf (core, "pd %d @e:asm.flags=0@ 0x%08"PFMT64x"; pds 256 @ 0x%08"PFMT64x"\n", + 32, status->addr, status->addr); + int disy = colh + 2; + rz_cons_strcat_at (output, 10, disy, w, h - disy); + free (output); + rz_cons_flush(); + + free (xrefsColstr); + free (mainColstr); + free (refsColstr); + return 0; +} + +RZ_API int rz_core_visual_view_graph(RzCore *core) { + RzCoreVisualViewGraph status = {0}; + status.core = core; + status.cur_sort = SORT_NAME; + __reset_status (&status); + __sync_status_with_cursor (&status); + RzAnalFunction *fcn = rz_anal_get_fcn_in (core->anal, status.addr, 0); + if (fcn) { + status.addr = fcn->addr; + status.fcn = fcn; + } + while (true) { + __core_visual_view_graph_update (core, &status); + int ch = rz_cons_readchar (); + if (ch == -1 || ch == 4) { + return true; + } + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + switch (ch) { + case 'h': + if (!rz_list_empty (status.xrefsCol)) { + status.cur = 0; + rz_list_free (status.mainCol); + rz_list_free (status.refsCol); + status.mainCol = status.xrefsCol; + + __sync_status_with_cursor (&status); + } + break; + case 'l': + if (!rz_list_empty (status.refsCol)) { + status.cur = 0; + rz_list_free (status.mainCol); + rz_list_free (status.xrefsCol); + status.mainCol = status.refsCol; + + __sync_status_with_cursor (&status); + } + break; + case 'J': + { + status.cur += 10; + int length = rz_list_length (status.mainCol); + if (status.cur >= length) { + status.cur = length-1; + } + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __sync_status_with_cursor (&status); + } + break; + case 'K': + if (status.cur > 10) { + status.cur -= 10; + } else { + status.cur = 0; + } + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __sync_status_with_cursor (&status); + break; + case '.': + // reset view and seek status->cur to current function + rz_list_free (status.mainCol); + __reset_status (&status); + break; + case 9: + case ' ': + case '\r': + case '\n': + { + RzCoreVisualViewGraphItem *item = rz_list_get_n (status.mainCol, status.cur); + rz_core_seek (core, item->addr, true); + } + return true; + break; + case '_': + rz_core_visual_hudstuff (core); + rz_list_free (status.mainCol); + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __reset_status (&status); + __sync_status_with_cursor (&status); + break; + case 'r': + rz_list_free (status.mainCol); + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __reset_status (&status); + __sync_status_with_cursor (&status); + break; + case 'j': + { + status.cur++; + int length = rz_list_length (status.mainCol); + if (status.cur >= length) { + status.cur = length-1; + } + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __sync_status_with_cursor (&status); + } + break; + case 'k': + if (status.cur > 0) { + status.cur--; + } else { + status.cur = 0; + } + rz_list_free (status.xrefsCol); + rz_list_free (status.refsCol); + __sync_status_with_cursor (&status); + break; + case '?': + rz_cons_clear00 (); + rz_cons_printf ( + "vbg: Visual Browser (Code) Graph:\n\n" + " jkJK - scroll up/down\n" + " hl - move to the left/right panel\n" + " q - quit this visual mode\n" + " _ - enter the hud\n" + " . - go back to the initial function list view\n" + " : - enter command\n"); + rz_cons_flush (); + rz_cons_any_key (NULL); + break; + case '/': + { + char cmd[1024]; + rz_cons_show_cursor (true); + rz_cons_set_raw (0); + cmd[0]='\0'; + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + cmd[0] = '\0'; + } + rz_config_set (core->config, "scr.highlight", cmd); + //rz_core_cmd_task_sync (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + rz_cons_clear (); + } + break; + case 'q': + return false; + case ':': // TODO: move this into a separate helper function + { + char cmd[1024]; + rz_cons_show_cursor (true); + rz_cons_set_raw (0); + cmd[0]='\0'; + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + cmd[0] = '\0'; + } + rz_core_cmd0 (core, cmd); + //rz_core_cmd_task_sync (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); + if (cmd[0]) { + rz_cons_any_key (NULL); + } + rz_cons_clear (); + } + break; + case '!': { + __toggleSort (&status); + } break; + } + } + return false; +} diff --git a/libr/core/vmenus_zigns.c b/librz/core/vmenus_zigns.c similarity index 58% rename from libr/core/vmenus_zigns.c rename to librz/core/vmenus_zigns.c index 00fc0c78dd..1ed2cfeff5 100644 --- a/libr/core/vmenus_zigns.c +++ b/librz/core/vmenus_zigns.c @@ -1,23 +1,23 @@ /* radare - LGPL - Copyright 2019 - pancake */ -#include +#include typedef struct { ut64 addr; ut64 faddr; - RAnalFunction *fcn; + RzAnalFunction *fcn; int pos; // related to columns int cur; // current row selected - RList *columns; - RCore *core; + RzList *columns; + RzCore *core; bool canLeft; bool canRight; -} RCoreVisualViewZigns; +} RzCoreVisualViewZigns; static const char *cur_name = NULL; static char *print_item (void *_core, void *_item, bool selected) { - RSignItem *item = _item; + RzSignItem *item = _item; int i; int bytes_mask = 0; int bytes_size = item->bytes->size; @@ -32,50 +32,50 @@ static char *print_item (void *_core, void *_item, bool selected) { if (selected && item->name) { cur_name = strdup (item->name); } - return r_str_newf ("%c 0x%08"PFMT64x" bytes=%d/%d %20s\n", selected?'>':' ', + return rz_str_newf ("%c 0x%08"PFMT64x" bytes=%d/%d %20s\n", selected?'>':' ', item->addr, bytes_mask, bytes_size, item->name); } -static RList *__signs(RCoreVisualViewZigns *status, ut64 addr, bool update) { - RCore *core = status->core; - return r_sign_get_list (core->anal); +static RzList *__signs(RzCoreVisualViewZigns *status, ut64 addr, bool update) { + RzCore *core = status->core; + return rz_sign_get_list (core->anal); } -R_API int __core_visual_view_zigns_update(RCore *core, RCoreVisualViewZigns *status) { - int h, w = r_cons_get_size (&h); - r_cons_clear00 (); +RZ_API int __core_visual_view_zigns_update(RzCore *core, RzCoreVisualViewZigns *status) { + int h, w = rz_cons_get_size (&h); + rz_cons_clear00 (); int colh = h -2; int colw = w -1; - RList *col0 = __signs (status, status->addr, true); - char *col0str = r_str_widget_list (core, col0, colh, status->cur, print_item); + RzList *col0 = __signs (status, status->addr, true); + char *col0str = rz_str_widget_list (core, col0, colh, status->cur, print_item); - char *title = r_str_newf ("[r2-visual-signatures] 0x%08"PFMT64x" 0x%08"PFMT64x, status->addr, status->faddr); + char *title = rz_str_newf ("[r2-visual-signatures] 0x%08"PFMT64x" 0x%08"PFMT64x, status->addr, status->faddr); if (title) { - r_cons_strcat_at (title, 0, 0, w - 1, 2); + rz_cons_strcat_at (title, 0, 0, w - 1, 2); free (title); } - r_cons_strcat_at (col0str, 0, 2, colw, colh); - r_list_free (col0); - r_cons_flush(); + rz_cons_strcat_at (col0str, 0, 2, colw, colh); + rz_list_free (col0); + rz_cons_flush(); return 0; } -R_API int r_core_visual_view_zigns(RCore *core) { - RCoreVisualViewZigns status = {0}; +RZ_API int rz_core_visual_view_zigns(RzCore *core) { + RzCoreVisualViewZigns status = {0}; status.core = core; status.addr = core->offset; status.fcn = NULL; while (true) { __core_visual_view_zigns_update (core, &status); - int ch = r_cons_readchar (); + int ch = rz_cons_readchar (); if (ch == -1 || ch == 4) { return true; } - ch = r_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char + ch = rz_cons_arrow_to_hjkl (ch); // get ESC+char, return 'hjkl' char switch (ch) { case 'g': - r_core_cmd0 (core, "zg"); + rz_core_cmd0 (core, "zg"); break; case 'h': if (status.canLeft) { @@ -97,7 +97,7 @@ R_API int r_core_visual_view_zigns(RCore *core) { break; case 'd': if (cur_name && *cur_name) { - r_sign_delete (core->anal, cur_name); + rz_sign_delete (core->anal, cur_name); R_FREE (cur_name); } break; @@ -119,14 +119,14 @@ R_API int r_core_visual_view_zigns(RCore *core) { case '\r': case '\n': if (status.pos) { - r_core_seek (core, status.faddr, true); + rz_core_seek (core, status.faddr, true); } else { - r_core_seek (core, status.addr, true); + rz_core_seek (core, status.addr, true); } return true; break; case '_': - r_core_cmd0 (core, "z*~..."); + rz_core_cmd0 (core, "z*~..."); break; case 'j': status.cur++; @@ -139,8 +139,8 @@ R_API int r_core_visual_view_zigns(RCore *core) { } break; case '?': - r_cons_clear00 (); - r_cons_printf ( + rz_cons_clear00 (); + rz_cons_printf ( "vbz: Visual Zignatures:\n\n" " jkJK - scroll up/down\n" " d - delete current signature\n" @@ -148,8 +148,8 @@ R_API int r_core_visual_view_zigns(RCore *core) { " q - quit this visual mode\n" " _ - enter the hud\n" " : - enter command\n"); - r_cons_flush (); - r_cons_any_key (NULL); + rz_cons_flush (); + rz_cons_any_key (NULL); break; case 'q': R_FREE (cur_name); @@ -157,20 +157,20 @@ R_API int r_core_visual_view_zigns(RCore *core) { case ':': // TODO: move this into a separate helper function { char cmd[1024]; - r_cons_show_cursor (true); - r_cons_set_raw (0); + rz_cons_show_cursor (true); + rz_cons_set_raw (0); cmd[0]='\0'; - r_line_set_prompt (":> "); - if (r_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { + rz_line_set_prompt (":> "); + if (rz_cons_fgets (cmd, sizeof (cmd), 0, NULL) < 0) { cmd[0] = '\0'; } - r_core_cmd_task_sync (core, cmd, 1); - r_cons_set_raw (1); - r_cons_show_cursor (false); + rz_core_cmd_task_sync (core, cmd, 1); + rz_cons_set_raw (1); + rz_cons_show_cursor (false); if (cmd[0]) { - r_cons_any_key (NULL); + rz_cons_any_key (NULL); } - r_cons_clear (); + rz_cons_clear (); } break; } diff --git a/libr/core/windows_heap.c b/librz/core/windows_heap.c similarity index 90% rename from libr/core/windows_heap.c rename to librz/core/windows_heap.c index 0b61fc73c5..1b853a2b1b 100644 --- a/libr/core/windows_heap.c +++ b/librz/core/windows_heap.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2019 - GustavoLCR */ -#include +#include #include #include #include "..\..\debug\p\native\maps\windows_maps.h" @@ -60,7 +60,7 @@ static size_t RtlpLFHKeyOffset = 0; return;\ }\ if (!heapInfo->count) {\ - r_cons_print ("No heaps for this process\n");\ + rz_cons_print ("No heaps for this process\n");\ return;\ } @@ -76,7 +76,7 @@ static size_t RtlpLFHKeyOffset = 0; static bool __is_windows_ten(void) { int major = 0; - RSysInfo *info = r_sys_info (); + RSysInfo *info = rz_sys_info (); if (info && info->version) { char *dot = strchr (info->version, '.'); if (dot) { @@ -84,7 +84,7 @@ static bool __is_windows_ten(void) { major = atoi (info->version); } } - r_sys_info_free (info); + rz_sys_info_free (info); return major == 10; } @@ -117,7 +117,7 @@ static char *get_type(WPARAM flags) { } else if (flags & VS_BLOCK) { type = "/VS"; } - return r_str_newf ("%s %s%s", state, heaptype, type); + return rz_str_newf ("%s %s%s", state, heaptype, type); } static bool init_func(void) { @@ -152,7 +152,7 @@ static bool is_segment_heap(HANDLE h_proc, PVOID heapBase) { // These functions are basically Heap32First and Heap32Next but faster static bool GetFirstHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) { - r_return_val_if_fail (heapInfo && hb, false); + rz_return_val_if_fail (heapInfo && hb, false); PHeapBlockBasicInfo block; hb->index = 0; @@ -192,7 +192,7 @@ static bool GetFirstHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) { } static bool GetNextHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) { - r_return_val_if_fail (heapInfo && hb, false); + rz_return_val_if_fail (heapInfo && hb, false); PHeapBlockBasicInfo block; block = (PHeapBlockBasicInfo)heapInfo->Blocks; @@ -241,7 +241,7 @@ static bool GetNextHeapBlock(PDEBUG_HEAP_INFORMATION heapInfo, PHeapBlock hb) { } static void free_extra_info(PDEBUG_HEAP_INFORMATION heap) { - r_return_if_fail (heap); + rz_return_if_fail (heap); HeapBlock hb; if (GetFirstHeapBlock (heap, &hb)) { do { @@ -250,14 +250,14 @@ static void free_extra_info(PDEBUG_HEAP_INFORMATION heap) { } } -static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { - RList *modules = r_w32_dbg_modules (dbg); - RListIter *it; - RDebugMap *map; +static bool GetHeapGlobalsOffset(RzDebug *dbg, HANDLE h_proc) { + RzList *modules = rz_w32_dbg_modules (dbg); + RzListIter *it; + RzDebugMap *map; bool found = false; const char ntdll[] = "ntdll.dll"; static ut64 lastNdtllAddr = 0; - r_list_foreach (modules, it, map) { + rz_list_foreach (modules, it, map) { if (!strncmp(map->name, ntdll, sizeof (ntdll))) { found = true; break; @@ -265,7 +265,7 @@ static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { } if (!found) { eprintf ("ntdll.dll not loaded."); - r_list_free (modules); + rz_list_free (modules); return false; } bool doopen = lastNdtllAddr != map->addr; @@ -285,13 +285,13 @@ static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { } if (doopen) { - char *ntdllpath = r_lib_path ("ntdll"); + char *ntdllpath = rz_lib_path ("ntdll"); eprintf ("Opening %s\n", ntdllpath); dbg->corebind.cmdf (dbg->corebind.core, "o %s 0x%"PFMT64x"", ntdllpath, map->addr); lastNdtllAddr = map->addr; free (ntdllpath); } - r_list_free (modules); + rz_list_free (modules); if (!RtlpHpHeapGlobalsOffset || !RtlpLFHKeyOffset) { char *res = dbg->corebind.cmdstrf (dbg->corebind.core, "idpi~RtlpHpHeapGlobals"); @@ -302,7 +302,7 @@ static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { res = dbg->corebind.cmdstrf (dbg->corebind.core, "idpi~RtlpHpHeapGlobals"); } if (*res) { - RtlpHpHeapGlobalsOffset = r_num_math (NULL, res); + RtlpHpHeapGlobalsOffset = rz_num_math (NULL, res); } else { free (res); return false; @@ -310,7 +310,7 @@ static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { free (res); res = dbg->corebind.cmdstrf (dbg->corebind.core, "idpi~RtlpLFHKey"); if (*res) { - RtlpLFHKeyOffset = r_num_math (NULL, res); + RtlpLFHKeyOffset = rz_num_math (NULL, res); } free (res); } @@ -325,8 +325,8 @@ static bool GetHeapGlobalsOffset(RDebug *dbg, HANDLE h_proc) { return true; } -static bool GetLFHKey(RDebug *dbg, HANDLE h_proc, bool segment, WPARAM *lfhKey) { - r_return_val_if_fail (dbg, 0); +static bool GetLFHKey(RzDebug *dbg, HANDLE h_proc, bool segment, WPARAM *lfhKey) { + rz_return_val_if_fail (dbg, 0); WPARAM lfhKeyLocation; if (!GetHeapGlobalsOffset (dbg, h_proc)) { @@ -340,7 +340,7 @@ static bool GetLFHKey(RDebug *dbg, HANDLE h_proc, bool segment, WPARAM *lfhKey) lfhKeyLocation = RtlpLFHKeyOffset; // ntdll!RtlpLFHKey } if (!ReadProcessMemory (h_proc, (PVOID)lfhKeyLocation, lfhKey, sizeof (WPARAM), NULL)) { - r_sys_perror ("ReadProcessMemory"); + rz_sys_perror ("ReadProcessMemory"); eprintf ("LFH key not found.\n"); *lfhKey = 0; return false; @@ -348,8 +348,8 @@ static bool GetLFHKey(RDebug *dbg, HANDLE h_proc, bool segment, WPARAM *lfhKey) return true; } -static bool DecodeHeapEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry) { - r_return_val_if_fail (heap && entry, false); +static bool DecodeHeapEntry(RzDebug *dbg, PHEAP heap, PHEAP_ENTRY entry) { + rz_return_val_if_fail (heap && entry, false); if (dbg->bits == R_SYS_BITS_64) { entry = (PHEAP_ENTRY)((ut8 *)entry + dbg->bits); } @@ -362,8 +362,8 @@ static bool DecodeHeapEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry) { return !(((BYTE *)entry)[0] ^ ((BYTE *)entry)[1] ^ ((BYTE *)entry)[2] ^ ((BYTE *)entry)[3]); } -static bool DecodeLFHEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry, PHEAP_USERDATA_HEADER userBlocks, WPARAM key, WPARAM addr) { - r_return_val_if_fail (heap && entry, false); +static bool DecodeLFHEntry(RzDebug *dbg, PHEAP heap, PHEAP_ENTRY entry, PHEAP_USERDATA_HEADER userBlocks, WPARAM key, WPARAM addr) { + rz_return_val_if_fail (heap && entry, false); if (dbg->bits == R_SYS_BITS_64) { entry = (PHEAP_ENTRY)((ut8 *)entry + dbg->bits); } @@ -375,7 +375,7 @@ static bool DecodeLFHEntry(RDebug *dbg, PHEAP heap, PHEAP_ENTRY entry, PHEAP_USE } typedef struct _th_query_params { - RDebug *dbg; + RzDebug *dbg; DWORD mask; PDEBUG_BUFFER db; DWORD ret; @@ -394,15 +394,15 @@ static DWORD WINAPI __th_QueryDebugBuffer(void *param) { return 0; } -static RList *GetListOfHeaps(RDebug *dbg, HANDLE ph) { +static RzList *GetListOfHeaps(RzDebug *dbg, HANDLE ph) { PROCESS_BASIC_INFORMATION pib; if (w32_NtQueryInformationProcess (ph, ProcessBasicInformation, &pib, sizeof (pib), NULL)) { - r_sys_perror ("NtQueryInformationProcess"); + rz_sys_perror ("NtQueryInformationProcess"); return NULL; } PEB peb; ReadProcessMemory (ph, pib.PebBaseAddress, &peb, sizeof (PEB), NULL); - RList *heaps = r_list_new (); + RzList *heaps = rz_list_new (); PVOID heapAddress; PVOID *processHeaps; ULONG numberOfHeaps; @@ -415,7 +415,7 @@ static RList *GetListOfHeaps(RDebug *dbg, HANDLE ph) { } do { ReadProcessMemory (ph, processHeaps, &heapAddress, sizeof (PVOID), NULL); - r_list_push (heaps, heapAddress); + rz_list_push (heaps, heapAddress); processHeaps += 1; } while (--numberOfHeaps); return heaps; @@ -428,7 +428,7 @@ static RList *GetListOfHeaps(RDebug *dbg, HANDLE ph) { * Notes: * Some LFH allocations seem misaligned */ -static PDEBUG_BUFFER InitHeapInfo(RDebug *dbg, DWORD mask) { +static PDEBUG_BUFFER InitHeapInfo(RzDebug *dbg, DWORD mask) { // Check: // RtlpQueryProcessDebugInformationFromWow64 // RtlpQueryProcessDebugInformationRemote @@ -459,7 +459,7 @@ static PDEBUG_BUFFER InitHeapInfo(RDebug *dbg, DWORD mask) { } else if (params->ret) { RtlDestroyQueryDebugBuffer (db); db = NULL; - r_sys_perror ("RtlQueryProcessDebugInformation"); + rz_sys_perror ("RtlQueryProcessDebugInformation"); } CloseHandle (th); if (db) { @@ -484,7 +484,7 @@ static PDEBUG_BUFFER InitHeapInfo(RDebug *dbg, DWORD mask) { RtlDestroyQueryDebugBuffer (db); return NULL; } - RList *heaps = GetListOfHeaps (dbg, h_proc); + RzList *heaps = GetListOfHeaps (dbg, h_proc); CloseHandle (h_proc); heapInfo->count = heaps->length; void *tmp = realloc (heapInfo, sizeof (DEBUG_HEAP_INFORMATION) * heapInfo->count + sizeof (heapInfo)); @@ -495,9 +495,9 @@ static PDEBUG_BUFFER InitHeapInfo(RDebug *dbg, DWORD mask) { } heapInfo = tmp; int i = 0; - RListIter *it; + RzListIter *it; void *heapBase; - r_list_foreach (heaps, it, heapBase) { + rz_list_foreach (heaps, it, heapBase) { heapInfo->heaps[i].Base = heapBase; heapInfo->heaps[i].Granularity = sizeof (HEAP_ENTRY); heapInfo->heaps[i].Allocated = 0; @@ -505,7 +505,7 @@ static PDEBUG_BUFFER InitHeapInfo(RDebug *dbg, DWORD mask) { i++; } db->HeapInformation = heapInfo; - r_list_free (heaps); + rz_list_free (heaps); return db; } return NULL; @@ -573,8 +573,8 @@ static bool __lfh_segment_loop(HANDLE h_proc, PHeapBlockBasicInfo *blocks, SIZE_ return true; } -static bool GetSegmentHeapBlocks(RDebug *dbg, HANDLE h_proc, PVOID heapBase, PHeapBlockBasicInfo *blocks, WPARAM *count, SIZE_T *allocated) { - r_return_val_if_fail (h_proc && blocks && count && allocated, false); +static bool GetSegmentHeapBlocks(RzDebug *dbg, HANDLE h_proc, PVOID heapBase, PHeapBlockBasicInfo *blocks, WPARAM *count, SIZE_T *allocated) { + rz_return_val_if_fail (h_proc && blocks && count && allocated, false); WPARAM bytesRead; SEGMENT_HEAP segheapHeader; ReadProcessMemory (h_proc, heapBase, &segheapHeader, sizeof (SEGMENT_HEAP), &bytesRead); @@ -585,7 +585,7 @@ static bool GetSegmentHeapBlocks(RDebug *dbg, HANDLE h_proc, PVOID heapBase, PHe WPARAM lfhKey; WPARAM lfhKeyLocation = RtlpHpHeapGlobalsOffset + sizeof (WPARAM); if (!ReadProcessMemory (h_proc, (PVOID)lfhKeyLocation, &lfhKey, sizeof (WPARAM), &bytesRead)) { - r_sys_perror ("ReadProcessMemory"); + rz_sys_perror ("ReadProcessMemory"); eprintf ("LFH key not found.\n"); return false; } @@ -618,16 +618,16 @@ static bool GetSegmentHeapBlocks(RDebug *dbg, HANDLE h_proc, PVOID heapBase, PHe // Large Blocks if (segheapHeader.LargeAllocMetadata.Root) { PRTL_BALANCED_NODE node = malloc (sizeof (RTL_BALANCED_NODE)); - RStack *s = r_stack_new (segheapHeader.LargeReservedPages); + RStack *s = rz_stack_new (segheapHeader.LargeReservedPages); PRTL_BALANCED_NODE curr = segheapHeader.LargeAllocMetadata.Root; - do { // while (!r_stack_is_empty(s)); + do { // while (!rz_stack_is_empty(s)); GROW_PBLOCKS (); while (curr) { - r_stack_push (s, curr); + rz_stack_push (s, curr); ReadProcessMemory (h_proc, curr, node, sizeof (RTL_BALANCED_NODE), &bytesRead); curr = node->Left; }; - curr = (PRTL_BALANCED_NODE)r_stack_pop (s); + curr = (PRTL_BALANCED_NODE)rz_stack_pop (s); HEAP_LARGE_ALLOC_DATA entry; ReadProcessMemory (h_proc, curr, &entry, sizeof (HEAP_LARGE_ALLOC_DATA), &bytesRead); (*blocks)[*count].address = entry.VirtualAddess - entry.UnusedBytes; // This is a union @@ -642,8 +642,8 @@ static bool GetSegmentHeapBlocks(RDebug *dbg, HANDLE h_proc, PVOID heapBase, PHe (*blocks)[*count].extra = EXTRA_FLAG | (WPARAM)extra; curr = entry.TreeNode.Right; *count += 1; - } while (curr || !r_stack_is_empty (s)); - r_stack_free (s); + } while (curr || !rz_stack_is_empty (s)); + rz_stack_free (s); free (node); } @@ -712,7 +712,7 @@ static bool GetSegmentHeapBlocks(RDebug *dbg, HANDLE h_proc, PVOID heapBase, PHe return true; } -static PDEBUG_BUFFER GetHeapBlocks(DWORD pid, RDebug *dbg) { +static PDEBUG_BUFFER GetHeapBlocks(DWORD pid, RzDebug *dbg) { /* TODO: Break this behemoth @@ -799,7 +799,7 @@ static PDEBUG_BUFFER GetHeapBlocks(DWORD pid, RDebug *dbg) { if (heapHeader.FrontEndHeap && heapHeader.FrontEndHeapType == 0x2) { LFH_HEAP lfhHeader; if (!ReadProcessMemory (h_proc, heapHeader.FrontEndHeap, &lfhHeader, sizeof (LFH_HEAP), &bytesRead)) { - r_sys_perror ("ReadProcessMemory"); + rz_sys_perror ("ReadProcessMemory"); goto err; } @@ -947,7 +947,7 @@ err: return NULL; } -static PHeapBlock GetSingleSegmentBlock(RDebug *dbg, HANDLE h_proc, PSEGMENT_HEAP heapBase, WPARAM offset) { +static PHeapBlock GetSingleSegmentBlock(RzDebug *dbg, HANDLE h_proc, PSEGMENT_HEAP heapBase, WPARAM offset) { /* * TODO: * - Backend (Is this needed?) @@ -1052,7 +1052,7 @@ err: return NULL; } -static PHeapBlock GetSingleBlock(RDebug *dbg, ut64 offset) { +static PHeapBlock GetSingleBlock(RzDebug *dbg, ut64 offset) { PHeapBlock hb = R_NEW0 (HeapBlock); PDEBUG_BUFFER db = NULL; PHeapBlockExtraInfo extra = NULL; @@ -1063,7 +1063,7 @@ static PHeapBlock GetSingleBlock(RDebug *dbg, ut64 offset) { } HANDLE h_proc = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, dbg->pid); if (!h_proc) { - r_sys_perror ("GetSingleBlock/OpenProcess"); + rz_sys_perror ("GetSingleBlock/OpenProcess"); goto err; } db = InitHeapInfo (dbg, PDI_HEAPS); @@ -1134,7 +1134,7 @@ static PHeapBlock GetSingleBlock(RDebug *dbg, ut64 offset) { HEAP_USERDATA_HEADER UserBlocks; HEAP_SUBSEGMENT subsegment; if (!ReadProcessMemory (h_proc, (PVOID)userBlocksOffset, &UserBlocks, sizeof (HEAP_USERDATA_HEADER), NULL)) { - r_sys_perror ("GetSingleBlock/ReadProcessMemory"); + rz_sys_perror ("GetSingleBlock/ReadProcessMemory"); continue; } if (!ReadProcessMemory (h_proc, (PVOID)UserBlocks.SubSegment, &subsegment, sizeof (HEAP_SUBSEGMENT), NULL)) { @@ -1167,17 +1167,17 @@ err: } static RTable *__new_heapblock_tbl(void) { - RTable *tbl = r_table_new (); - r_table_add_column (tbl, r_table_type ("number"), "HeaderAddress", -1); - r_table_add_column (tbl, r_table_type ("number"), "UserAddress", -1); - r_table_add_column (tbl, r_table_type ("number"), "Size", -1); - r_table_add_column (tbl, r_table_type ("number"), "Granularity", -1); - r_table_add_column (tbl, r_table_type ("number"), "Unused", -1); - r_table_add_column (tbl, r_table_type ("String"), "Type", -1); + RTable *tbl = rz_table_new (); + rz_table_add_column (tbl, rz_table_type ("number"), "HeaderAddress", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "UserAddress", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Size", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Granularity", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Unused", -1); + rz_table_add_column (tbl, rz_table_type ("String"), "Type", -1); return tbl; } -static void w32_list_heaps(RCore *core, const char format) { +static void w32_list_heaps(RzCore *core, const char format) { ULONG pid = core->dbg->pid; PDEBUG_BUFFER db = InitHeapInfo (core->dbg, PDI_HEAPS | PDI_HEAP_BLOCKS); if (!db) { @@ -1192,11 +1192,11 @@ static void w32_list_heaps(RCore *core, const char format) { PHeapInformation heapInfo = db->HeapInformation; CHECK_INFO (heapInfo); int i; - RTable *tbl = r_table_new (); - r_table_add_column (tbl, r_table_type ("number"), "Address", -1); - r_table_add_column (tbl, r_table_type ("number"), "Blocks", -1); - r_table_add_column (tbl, r_table_type ("number"), "Allocated", -1); - r_table_add_column (tbl, r_table_type ("number"), "Commited", -1); + RTable *tbl = rz_table_new (); + rz_table_add_column (tbl, rz_table_type ("number"), "Address", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Blocks", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Allocated", -1); + rz_table_add_column (tbl, rz_table_type ("number"), "Commited", -1); PJ *pj = pj_new (); pj_a (pj); for (i = 0; i < heapInfo->count; i++) { @@ -1211,7 +1211,7 @@ static void w32_list_heaps(RCore *core, const char format) { pj_end (pj); break; default: - r_table_add_rowf (tbl, "xnnn", (ut64)heap.Base, (ut64)heap.BlockCount, (ut64)heap.Allocated, (ut64)heap.Committed); + rz_table_add_rowf (tbl, "xnnn", (ut64)heap.Base, (ut64)heap.BlockCount, (ut64)heap.Allocated, (ut64)heap.Committed); break; } if (!(db->InfoClassMask & PDI_HEAP_BLOCKS)) { @@ -1221,16 +1221,16 @@ static void w32_list_heaps(RCore *core, const char format) { } if (format == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } else { - r_cons_println (r_table_tostring (tbl)); + rz_cons_println (rz_table_tostring (tbl)); } - r_table_free (tbl); + rz_table_free (tbl); pj_free (pj); RtlDestroyQueryDebugBuffer (db); } -static void w32_list_heaps_blocks(RCore *core, const char format) { +static void w32_list_heaps_blocks(RzCore *core, const char format) { DWORD pid = core->dbg->pid; PDEBUG_BUFFER db; if (__is_windows_ten ()) { @@ -1254,7 +1254,7 @@ static void w32_list_heaps_blocks(RCore *core, const char format) { switch (format) { case 'f': if (heapInfo->heaps[i].BlockCount > 50000) { - go = r_cons_yesno ('n', "Are you sure you want to add %"PFMT64u" flags? (y/N)", heapInfo->heaps[i].BlockCount); + go = rz_cons_yesno ('n', "Are you sure you want to add %"PFMT64u" flags? (y/N)", heapInfo->heaps[i].BlockCount); } break; case 'j': @@ -1277,8 +1277,8 @@ static void w32_list_heaps_blocks(RCore *core, const char format) { switch (format) { case 'f': { - char *name = r_str_newf ("alloc.%"PFMT64x"", address); - r_flag_set (core->flags, name, address, block->dwSize); + char *name = rz_str_newf ("alloc.%"PFMT64x"", address); + rz_flag_set (core->flags, name, address, block->dwSize); free (name); break; } @@ -1292,7 +1292,7 @@ static void w32_list_heaps_blocks(RCore *core, const char format) { pj_end (pj); break; default: - r_table_add_rowf (tbl, "xxnnns", address, (ut64)block->dwAddress, block->dwSize, granularity, unusedBytes, type); + rz_table_add_rowf (tbl, "xxnnns", address, (ut64)block->dwAddress, block->dwSize, granularity, unusedBytes, type); break; } } while (GetNextHeapBlock (&heapInfo->heaps[i], block)); @@ -1309,11 +1309,11 @@ static void w32_list_heaps_blocks(RCore *core, const char format) { } if (format == 'j') { pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } else if (format != 'f') { - r_cons_println (r_table_tostring (tbl)); + rz_cons_println (rz_table_tostring (tbl)); } - r_table_free (tbl); + rz_table_free (tbl); pj_free (pj); RtlDestroyQueryDebugBuffer (db); } @@ -1333,11 +1333,11 @@ static const char *help_msg_block[] = { NULL }; -static void cmd_debug_map_heap_block_win(RCore *core, const char *input) { +static void cmd_debug_map_heap_block_win(RzCore *core, const char *input) { char *space = strchr (input, ' '); ut64 off = 0; if (space) { - off = r_num_math (core->num, space + 1); + off = rz_num_math (core->num, space + 1); PHeapBlock hb = GetSingleBlock (core->dbg, off); if (hb) { ut64 granularity = hb->extraInfo->granularity; @@ -1350,8 +1350,8 @@ static void cmd_debug_map_heap_block_win(RCore *core, const char *input) { ut64 headerAddr = off - granularity; switch (input[0]) { case ' ': - r_table_add_rowf (tbl, "xxnnns", headerAddr, off, (ut64)hb->dwSize, granularity, (ut64)hb->extraInfo->unusedBytes, type); - r_cons_println (r_table_tostring (tbl)); + rz_table_add_rowf (tbl, "xxnnns", headerAddr, off, (ut64)hb->dwSize, granularity, (ut64)hb->extraInfo->unusedBytes, type); + rz_cons_println (rz_table_tostring (tbl)); break; case 'j': pj_o (pj); @@ -1363,11 +1363,11 @@ static void cmd_debug_map_heap_block_win(RCore *core, const char *input) { pj_kN (pj, "unused", hb->extraInfo->unusedBytes); } pj_end (pj); - r_cons_println (pj_string (pj)); + rz_cons_println (pj_string (pj)); } free (hb->extraInfo); free (hb); - r_table_free (tbl); + rz_table_free (tbl); pj_free (pj); } return; @@ -1379,15 +1379,15 @@ static void cmd_debug_map_heap_block_win(RCore *core, const char *input) { w32_list_heaps_blocks (core, input[0]); break; default: - r_core_cmd_help (core, help_msg_block); + rz_core_cmd_help (core, help_msg_block); } } -static int cmd_debug_map_heap_win(RCore *core, const char *input) { +static int cmd_debug_map_heap_win(RzCore *core, const char *input) { init_func (); switch (input[0]) { case '?': // dmh? - r_core_cmd_help (core, help_msg); + rz_core_cmd_help (core, help_msg); break; case 'b': // dmhb cmd_debug_map_heap_block_win (core, input + 1); diff --git a/libr/core/yank.c b/librz/core/yank.c similarity index 57% rename from libr/core/yank.c rename to librz/core/yank.c index 7b59918837..ea59a337cd 100644 --- a/libr/core/yank.c +++ b/librz/core/yank.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2009-2019 - pancake & dso */ -#include "r_core.h" -#include "r_util.h" -#include "r_io.h" +#include "rz_core.h" +#include "rz_util.h" +#include "rz_io.h" /* * perform_mapped_file_yank will map in a file and yank from offset the number of len bytes from * filename. if the len is -1, the all the bytes are mapped into the yank buffer. */ -static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const char *filename); +static int perform_mapped_file_yank(RzCore *core, ut64 offset, ut64 len, const char *filename); static ut32 find_next_char(const char *input, char b); static ut32 consume_chars(const char *input, char b); @@ -34,23 +34,23 @@ static ut32 consume_chars(const char *input, char b) { return i; } -static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const char *filename) { +static int perform_mapped_file_yank(RzCore *core, ut64 offset, ut64 len, const char *filename) { // grab the current file descriptor, so we can reset core and io state // after our io op is done - RIODesc *yankdesc = NULL; + RzIODesc *yankdesc = NULL; ut64 fd = core->file? core->file->fd: -1, yank_file_sz = 0, loadaddr = 0, addr = offset; int res = false; if (filename && *filename) { - ut64 load_align = r_config_get_i (core->config, "file.loadalign"); - RIOMap *map = NULL; - yankdesc = r_io_open_nomap (core->io, filename, R_PERM_R, 0644); + ut64 load_align = rz_config_get_i (core->config, "file.loadalign"); + RzIOMap *map = NULL; + yankdesc = rz_io_open_nomap (core->io, filename, R_PERM_R, 0644); // map the file in for IO operations. if (yankdesc && load_align) { - yank_file_sz = r_io_size (core->io); - ut64 addr = r_io_map_next_available (core->io, 0, yank_file_sz, load_align); - map = r_io_map_new (core->io, yankdesc->fd, R_PERM_R, 0, addr, yank_file_sz); + yank_file_sz = rz_io_size (core->io); + ut64 addr = rz_io_map_next_available (core->io, 0, yank_file_sz, load_align); + map = rz_io_map_new (core->io, yankdesc->fd, R_PERM_R, 0, addr, yank_file_sz); loadaddr = map? map->itv.addr: -1; if (yankdesc && map && loadaddr != -1) { // ***NOTE*** this is important, we need to @@ -58,7 +58,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch addr += loadaddr; } else if (yankdesc) { eprintf ("Unable to map the opened file: %s", filename); - r_io_desc_close (yankdesc); + rz_io_desc_close (yankdesc); yankdesc = NULL; } else { eprintf ("Unable to open the file: %s", filename); @@ -74,15 +74,15 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch // this wont happen if the file failed to open or the file failed to // map into the IO layer if (yankdesc) { - ut64 res = r_io_seek (core->io, addr, R_IO_SEEK_SET); + ut64 res = rz_io_seek (core->io, addr, R_IO_SEEK_SET); ut64 actual_len = len <= yank_file_sz? len: 0; ut8 *buf = NULL; if (actual_len > 0 && res == addr) { buf = malloc (actual_len); - if (!r_io_read_at (core->io, addr, buf, actual_len)) { + if (!rz_io_read_at (core->io, addr, buf, actual_len)) { actual_len = 0; } - r_core_yank_set (core, R_CORE_FOREIGN_ADDR, buf, len); + rz_core_yank_set (core, R_CORE_FOREIGN_ADDR, buf, len); res = true; } else if (res != addr) { eprintf ( @@ -96,23 +96,23 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch PFMT64x ") > file_sz (0x%"PFMT64x ")\n", addr + len, yank_file_sz ); } - r_io_desc_close (yankdesc); + rz_io_desc_close (yankdesc); free (buf); } if (fd != -1) { - r_io_use_fd (core->io, fd); + rz_io_use_fd (core->io, fd); core->switch_file_view = 1; - r_core_block_read (core); + rz_core_block_read (core); } return res; } -R_API int r_core_yank_set(RCore *core, ut64 addr, const ut8 *buf, ut32 len) { +RZ_API int rz_core_yank_set(RzCore *core, ut64 addr, const ut8 *buf, ut32 len) { // free (core->yank_buf); if (buf && len) { // FIXME: direct access to base should be avoided (use _sparse // when you need buffer that starts at given addr) - r_buf_set_bytes (core->yank_buf, buf, len); + rz_buf_set_bytes (core->yank_buf, buf, len); core->yank_addr = addr; return true; } @@ -120,21 +120,21 @@ R_API int r_core_yank_set(RCore *core, ut64 addr, const ut8 *buf, ut32 len) { } // Call set and then null terminate the bytes. -R_API int r_core_yank_set_str(RCore *core, ut64 addr, const char *str, ut32 len) { +RZ_API int rz_core_yank_set_str(RzCore *core, ut64 addr, const char *str, ut32 len) { // free (core->yank_buf); - int res = r_core_yank_set (core, addr, (ut8 *)str, len); + int res = rz_core_yank_set (core, addr, (ut8 *)str, len); if (res == true) { ut8 zero = 0; - r_buf_write_at (core->yank_buf, len - 1, &zero, sizeof (zero)); + rz_buf_write_at (core->yank_buf, len - 1, &zero, sizeof (zero)); } return res; } -R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) { +RZ_API int rz_core_yank(struct rz_core_t *core, ut64 addr, int len) { ut64 curseek = core->offset; ut8 *buf = NULL; if (len < 0) { - eprintf ("r_core_yank: cannot yank negative bytes\n"); + eprintf ("rz_core_yank: cannot yank negative bytes\n"); return false; } if (len == 0) { @@ -145,27 +145,27 @@ R_API int r_core_yank(struct r_core_t *core, ut64 addr, int len) { return false; } if (addr != core->offset) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } - r_io_read_at (core->io, addr, buf, len); - r_core_yank_set (core, addr, buf, len); + rz_io_read_at (core->io, addr, buf, len); + rz_core_yank_set (core, addr, buf, len); if (curseek != addr) { - r_core_seek (core, curseek, true); + rz_core_seek (core, curseek, true); } free (buf); return true; } /* Copy a zero terminated string to the clipboard. Clamp to maxlen or blocksize. */ -R_API int r_core_yank_string(RCore *core, ut64 addr, int maxlen) { +RZ_API int rz_core_yank_string(RzCore *core, ut64 addr, int maxlen) { ut64 curseek = core->offset; ut8 *buf = NULL; if (maxlen < 0) { - eprintf ("r_core_yank_string: cannot yank negative bytes\n"); + eprintf ("rz_core_yank_string: cannot yank negative bytes\n"); return false; } if (addr != core->offset) { - r_core_seek (core, addr, true); + rz_core_seek (core, addr, true); } /* Ensure space and safe termination for largest possible string allowed */ buf = calloc (1, core->blocksize + 1); @@ -173,40 +173,40 @@ R_API int r_core_yank_string(RCore *core, ut64 addr, int maxlen) { return false; } buf[core->blocksize] = 0; - r_io_read_at (core->io, addr, buf, core->blocksize); + rz_io_read_at (core->io, addr, buf, core->blocksize); if (maxlen == 0) { // Don't use strnlen, see: http://sourceforge.net/p/mingw/bugs/1912/ - maxlen = r_str_nlen ((const char *) buf, core->blocksize); + maxlen = rz_str_nlen ((const char *) buf, core->blocksize); } else if (maxlen > core->blocksize) { maxlen = core->blocksize; } - r_core_yank_set (core, addr, buf, maxlen); + rz_core_yank_set (core, addr, buf, maxlen); if (curseek != addr) { - r_core_seek (core, curseek, true); + rz_core_seek (core, curseek, true); } free (buf); return true; } -R_API int r_core_yank_paste(RCore *core, ut64 addr, int len) { +RZ_API int rz_core_yank_paste(RzCore *core, ut64 addr, int len) { if (len < 0) { return false; } - if (len == 0 || len >= r_buf_size (core->yank_buf)) { - len = r_buf_size (core->yank_buf); + if (len == 0 || len >= rz_buf_size (core->yank_buf)) { + len = rz_buf_size (core->yank_buf); } ut8 *buf = R_NEWS (ut8, len); if (!buf) { return false; } - r_buf_read_at (core->yank_buf, 0, buf, len); - if (!r_core_write_at (core, addr, buf, len)) { + rz_buf_read_at (core->yank_buf, 0, buf, len); + if (!rz_core_write_at (core, addr, buf, len)) { return false; } return true; } -R_API int r_core_yank_to(RCore *core, const char *_arg) { +RZ_API int rz_core_yank_to(RzCore *core, const char *_arg) { ut64 len = 0; ut64 pos = -1; char *str, *arg; @@ -219,8 +219,8 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) { str = strchr (arg, ' '); if (str) { str[0] = '\0'; - len = r_num_math (core->num, arg); - pos = r_num_math (core->num, str + 1); + len = rz_num_math (core->num, arg); + pos = rz_num_math (core->num, str + 1); str[0] = ' '; } if (!str || pos == -1 || len == 0) { @@ -228,52 +228,52 @@ R_API int r_core_yank_to(RCore *core, const char *_arg) { free (arg); return res; } - if (r_core_yank (core, core->offset, len) == true) { - res = r_core_yank_paste (core, pos, len); + if (rz_core_yank (core, core->offset, len) == true) { + res = rz_core_yank_paste (core, pos, len); } free (arg); return res; } -R_API bool r_core_yank_dump(RCore *core, ut64 pos, int format) { +RZ_API bool rz_core_yank_dump(RzCore *core, ut64 pos, int format) { bool res = false; int i = 0; - int ybl = r_buf_size (core->yank_buf); + int ybl = rz_buf_size (core->yank_buf); if (ybl > 0) { if (pos < ybl) { switch (format) { case 'q': - for (i = pos; i < r_buf_size (core->yank_buf); i++) { - r_cons_printf ("%02x", r_buf_read8_at (core->yank_buf, i)); + for (i = pos; i < rz_buf_size (core->yank_buf); i++) { + rz_cons_printf ("%02x", rz_buf_read8_at (core->yank_buf, i)); } - r_cons_newline (); + rz_cons_newline (); break; case 'j': { - r_cons_printf ("{\"addr\":%"PFMT64u",\"bytes\":\"", core->yank_addr); - for (i = pos; i < r_buf_size (core->yank_buf); i++) { - r_cons_printf ("%02x", r_buf_read8_at (core->yank_buf, i)); + rz_cons_printf ("{\"addr\":%"PFMT64u",\"bytes\":\"", core->yank_addr); + for (i = pos; i < rz_buf_size (core->yank_buf); i++) { + rz_cons_printf ("%02x", rz_buf_read8_at (core->yank_buf, i)); } - r_cons_printf ("\"}\n"); + rz_cons_printf ("\"}\n"); } break; case '*': - //r_cons_printf ("yfx "); - r_cons_printf ("wx "); - for (i = pos; i < r_buf_size (core->yank_buf); i++) { - r_cons_printf ("%02x", r_buf_read8_at (core->yank_buf, i)); + //rz_cons_printf ("yfx "); + rz_cons_printf ("wx "); + for (i = pos; i < rz_buf_size (core->yank_buf); i++) { + rz_cons_printf ("%02x", rz_buf_read8_at (core->yank_buf, i)); } - //r_cons_printf (" @ 0x%08"PFMT64x, core->yank_addr); - r_cons_newline (); + //rz_cons_printf (" @ 0x%08"PFMT64x, core->yank_addr); + rz_cons_newline (); break; default: - r_cons_printf ("0x%08" PFMT64x " %d ", + rz_cons_printf ("0x%08" PFMT64x " %d ", core->yank_addr + pos, - r_buf_size (core->yank_buf) - pos); - for (i = pos; i < r_buf_size (core->yank_buf); i++) { - r_cons_printf ("%02x", r_buf_read8_at (core->yank_buf, i)); + rz_buf_size (core->yank_buf) - pos); + for (i = pos; i < rz_buf_size (core->yank_buf); i++) { + rz_cons_printf ("%02x", rz_buf_read8_at (core->yank_buf, i)); } - r_cons_newline (); + rz_cons_newline (); } res = true; } else { @@ -281,7 +281,7 @@ R_API bool r_core_yank_dump(RCore *core, ut64 pos, int format) { } } else { if (format == 'j') { - r_cons_printf ("{}\n"); + rz_cons_printf ("{}\n"); } else { eprintf ("No buffer yanked already\n"); } @@ -289,17 +289,17 @@ R_API bool r_core_yank_dump(RCore *core, ut64 pos, int format) { return res; } -R_API int r_core_yank_hexdump(RCore *core, ut64 pos) { +RZ_API int rz_core_yank_hexdump(RzCore *core, ut64 pos) { int res = false; - int ybl = r_buf_size (core->yank_buf); + int ybl = rz_buf_size (core->yank_buf); if (ybl > 0) { if (pos < ybl) { ut8 *buf = R_NEWS (ut8, ybl - pos); if (!buf) { return false; } - r_buf_read_at (core->yank_buf, pos, buf, ybl - pos); - r_print_hexdump (core->print, pos, + rz_buf_read_at (core->yank_buf, pos, buf, ybl - pos); + rz_print_hexdump (core->print, pos, buf, ybl - pos, 16, 1, 1); res = true; } else { @@ -311,8 +311,8 @@ R_API int r_core_yank_hexdump(RCore *core, ut64 pos) { return res; } -R_API int r_core_yank_cat(RCore *core, ut64 pos) { - int ybl = r_buf_size (core->yank_buf); +RZ_API int rz_core_yank_cat(RzCore *core, ut64 pos) { + int ybl = rz_buf_size (core->yank_buf); if (ybl > 0) { if (pos < ybl) { ut64 sz = ybl - pos; @@ -320,20 +320,20 @@ R_API int r_core_yank_cat(RCore *core, ut64 pos) { if (!buf) { return false; } - r_buf_read_at (core->yank_buf, pos, (ut8 *)buf, sz); - r_cons_memcat (buf, sz); - r_cons_newline (); + rz_buf_read_at (core->yank_buf, pos, (ut8 *)buf, sz); + rz_cons_memcat (buf, sz); + rz_cons_newline (); return true; } eprintf ("Position exceeds buffer length.\n"); } else { - r_cons_newline (); + rz_cons_newline (); } return false; } -R_API int r_core_yank_cat_string(RCore *core, ut64 pos) { - int ybl = r_buf_size (core->yank_buf); +RZ_API int rz_core_yank_cat_string(RzCore *core, ut64 pos) { + int ybl = rz_buf_size (core->yank_buf); if (ybl > 0) { if (pos < ybl) { ut64 sz = ybl - pos; @@ -341,20 +341,20 @@ R_API int r_core_yank_cat_string(RCore *core, ut64 pos) { if (!buf) { return false; } - r_buf_read_at (core->yank_buf, pos, (ut8 *)buf, sz); - int len = r_str_nlen (buf, sz); - r_cons_memcat (buf, len); - r_cons_newline (); + rz_buf_read_at (core->yank_buf, pos, (ut8 *)buf, sz); + int len = rz_str_nlen (buf, sz); + rz_cons_memcat (buf, len); + rz_cons_newline (); return true; } eprintf ("Position exceeds buffer length.\n"); } else { - r_cons_newline (); + rz_cons_newline (); } return false; } -R_API int r_core_yank_hud_file(RCore *core, const char *input) { +RZ_API int rz_core_yank_hud_file(RzCore *core, const char *input) { char *buf = NULL; bool res = false; ut32 len = 0; @@ -364,41 +364,41 @@ R_API int r_core_yank_hud_file(RCore *core, const char *input) { for (input++; *input == ' '; input++) { /* nothing */ } - buf = r_cons_hud_file (input); + buf = rz_cons_hud_file (input); len = buf? strlen ((const char *) buf) + 1: 0; - res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len); + res = rz_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len); free (buf); return res; } -R_API int r_core_yank_hud_path(RCore *core, const char *input, int dir) { +RZ_API int rz_core_yank_hud_path(RzCore *core, const char *input, int dir) { char *buf = NULL; ut32 len = 0; int res; for (input++; *input == ' '; input++) { /* nothing */ } - buf = r_cons_hud_path (input, dir); + buf = rz_cons_hud_path (input, dir); len = buf? strlen ((const char *) buf) + 1: 0; - res = r_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len); + res = rz_core_yank_set_str (core, R_CORE_FOREIGN_ADDR, buf, len); free (buf); return res; } -R_API bool r_core_yank_hexpair(RCore *core, const char *input) { +RZ_API bool rz_core_yank_hexpair(RzCore *core, const char *input) { if (!input || !*input) { return false; } char *out = strdup (input); - int len = r_hex_str2bin (input, (ut8 *)out); + int len = rz_hex_str2bin (input, (ut8 *)out); if (len > 0) { - r_core_yank_set (core, core->offset, (ut8 *)out, len); + rz_core_yank_set (core, core->offset, (ut8 *)out, len); } free (out); return true; } -R_API bool r_core_yank_file_ex(RCore *core, const char *input) { +RZ_API bool rz_core_yank_file_ex(RzCore *core, const char *input) { ut64 len = 0, adv = 0, addr = 0; bool res = false; @@ -407,7 +407,7 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) { } // get the number of bytes to yank adv = consume_chars (input, ' '); - len = r_num_math (core->num, input + adv); + len = rz_num_math (core->num, input + adv); if (len == 0) { eprintf ("ERROR: Number of bytes read must be > 0\n"); return res; @@ -421,7 +421,7 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) { adv++; // XXX - bug, will fail if address needs to be computed and has spaces - addr = r_num_math (core->num, input + adv); + addr = rz_num_math (core->num, input + adv); adv += find_next_char (input + adv, ' '); if (adv == 0) { @@ -435,7 +435,7 @@ R_API bool r_core_yank_file_ex(RCore *core, const char *input) { return perform_mapped_file_yank (core, addr, len, input + adv); } -R_API int r_core_yank_file_all(RCore *core, const char *input) { +RZ_API int rz_core_yank_file_all(RzCore *core, const char *input) { ut64 adv = 0; if (!input) { return false; diff --git a/libr/core/zdiff.c b/librz/core/zdiff.c similarity index 65% rename from libr/core/zdiff.c rename to librz/core/zdiff.c index bf1726a976..0de14f6746 100644 --- a/libr/core/zdiff.c +++ b/librz/core/zdiff.c @@ -2,9 +2,9 @@ #include #include -#include +#include -static bool matchBytes(RSignItem *a, RSignItem *b) { +static bool matchBytes(RzSignItem *a, RzSignItem *b) { if (a->bytes && b->bytes) { if (a->bytes->size == b->bytes->size) { return !memcmp (a->bytes->bytes, b->bytes->bytes, b->bytes->size); @@ -13,7 +13,7 @@ static bool matchBytes(RSignItem *a, RSignItem *b) { return false; } -static bool matchGraph(RSignItem *a, RSignItem *b) { +static bool matchGraph(RzSignItem *a, RzSignItem *b) { if (a->graph && b->graph) { if (a->graph->cc != b->graph->cc) { return false; @@ -35,7 +35,7 @@ static bool matchGraph(RSignItem *a, RSignItem *b) { return false; } -R_API int r_core_zdiff(RCore *c, RCore *c2) { +RZ_API int rz_core_zdiff(RzCore *c, RzCore *c2) { if (!c || !c2) { return false; } @@ -46,37 +46,37 @@ R_API int r_core_zdiff(RCore *c, RCore *c2) { eprintf ("Diff %d %d\n", (int)ls_length (a), (int)ls_length (b)); SdbListIter *iter; SdbKv *kv; - RList *la = r_list_new (); + RzList *la = rz_list_new (); ls_foreach (a, iter, kv) { - RSignItem *it = r_sign_item_new (); - if (r_sign_deserialize (c->anal, it, kv->base.key, kv->base.value)) { - r_list_append (la, it); + RzSignItem *it = rz_sign_item_new (); + if (rz_sign_deserialize (c->anal, it, kv->base.key, kv->base.value)) { + rz_list_append (la, it); } else { - r_sign_item_free (it); + rz_sign_item_free (it); } } - RList *lb = r_list_new (); + RzList *lb = rz_list_new (); ls_foreach (b, iter, kv) { - RSignItem *it = r_sign_item_new (); - if (r_sign_deserialize (c2->anal, it, kv->base.key, kv->base.value)) { - r_list_append (lb, it); + RzSignItem *it = rz_sign_item_new (); + if (rz_sign_deserialize (c2->anal, it, kv->base.key, kv->base.value)) { + rz_list_append (lb, it); } else { - r_sign_item_free (it); + rz_sign_item_free (it); } } ////////// - RListIter *itr; - RListIter *itr2; - RSignItem *si; - RSignItem *si2; + RzListIter *itr; + RzListIter *itr2; + RzSignItem *si; + RzSignItem *si2; // do the sign diff here - r_list_foreach (la, itr, si) { + rz_list_foreach (la, itr, si) { //eprintf ("-- %s\n", si->name); if (strstr (si->name, "imp.")) { continue; } - r_list_foreach (lb, itr2, si2) { + rz_list_foreach (lb, itr2, si2) { if (strstr (si2->name, "imp.")) { continue; } @@ -90,7 +90,7 @@ R_API int r_core_zdiff(RCore *c, RCore *c2) { } /* Diff functions */ - // r_anal_diff_fcn (cores[0]->anal, cores[0]->anal->fcns, cores[1]->anal->fcns); + // rz_anal_diff_fcn (cores[0]->anal, cores[0]->anal->fcns, cores[1]->anal->fcns); return true; } diff --git a/libr/crypto/Makefile b/librz/crypto/Makefile similarity index 90% rename from libr/crypto/Makefile rename to librz/crypto/Makefile index af7e939f3d..11156973b6 100644 --- a/libr/crypto/Makefile +++ b/librz/crypto/Makefile @@ -1,5 +1,5 @@ -NAME=r_crypto -R2DEPS=r_hash r_util +NAME=rz_crypto +R2DEPS=rz_hash rz_util CFLAGS+=-DR2_PLUGIN_INCORE include ../config.mk diff --git a/libr/crypto/crypto.c b/librz/crypto/crypto.c similarity index 63% rename from libr/crypto/crypto.c rename to librz/crypto/crypto.c index bb99d956ae..069d5084c7 100644 --- a/libr/crypto/crypto.c +++ b/librz/crypto/crypto.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include "r_crypto.h" +#include "rz_crypto.h" #include "config.h" -R_LIB_VERSION (r_crypto); +R_LIB_VERSION (rz_crypto); static const struct { const char *name; - RCryptoSelector bit; + RzCryptoSelector bit; } crypto_name_bytes[] = { { "all", UT64_MAX }, { "rc2", R_CRYPTO_RC2 }, @@ -28,7 +28,7 @@ static const struct { static const struct { const char *name; - RCryptoSelector bit; + RzCryptoSelector bit; } codec_name_bytes[] = { { "all", UT64_MAX }, { "base64", R_CODEC_B64 }, @@ -37,7 +37,7 @@ static const struct { { NULL, 0 } }; -R_API const char *r_crypto_name(const RCryptoSelector bit) { +RZ_API const char *rz_crypto_name(const RzCryptoSelector bit) { size_t i; for (i = 1; crypto_name_bytes[i].bit; i++) { if (bit & crypto_name_bytes[i].bit) { @@ -47,7 +47,7 @@ R_API const char *r_crypto_name(const RCryptoSelector bit) { return ""; } -R_API const char *r_crypto_codec_name(const RCryptoSelector bit) { +RZ_API const char *rz_crypto_codec_name(const RzCryptoSelector bit) { size_t i; for (i = 1; codec_name_bytes[i].bit; i++) { if (bit & codec_name_bytes[i].bit) { @@ -57,11 +57,11 @@ R_API const char *r_crypto_codec_name(const RCryptoSelector bit) { return ""; } -static RCryptoPlugin *crypto_static_plugins[] = { +static RzCryptoPlugin *crypto_static_plugins[] = { R_CRYPTO_STATIC_PLUGINS }; -R_API RCrypto *r_crypto_init(RCrypto *cry, int hard) { +RZ_API RzCrypto *rz_crypto_init(RzCrypto *cry, int hard) { int i; if (cry) { cry->iv = NULL; @@ -70,50 +70,50 @@ R_API RCrypto *r_crypto_init(RCrypto *cry, int hard) { cry->user = NULL; if (hard) { // first call initializes the output_* variables - r_crypto_get_output (cry, NULL); - cry->plugins = r_list_newf (NULL); + rz_crypto_get_output (cry, NULL); + cry->plugins = rz_list_newf (NULL); for (i = 0; crypto_static_plugins[i]; i++) { - RCryptoPlugin *p = R_NEW0 (RCryptoPlugin); + RzCryptoPlugin *p = R_NEW0 (RzCryptoPlugin); if (!p) { free (cry); return NULL; } - memcpy (p, crypto_static_plugins[i], sizeof (RCryptoPlugin)); - r_crypto_add (cry, p); + memcpy (p, crypto_static_plugins[i], sizeof (RzCryptoPlugin)); + rz_crypto_add (cry, p); } } } return cry; } -R_API int r_crypto_add(RCrypto *cry, RCryptoPlugin *h) { +RZ_API int rz_crypto_add(RzCrypto *cry, RzCryptoPlugin *h) { // add a check ? - r_list_append (cry->plugins, h); + rz_list_append (cry->plugins, h); return true; } -R_API int r_crypto_del(RCrypto *cry, RCryptoPlugin *h) { - r_list_delete_data (cry->plugins, h); +RZ_API int rz_crypto_del(RzCrypto *cry, RzCryptoPlugin *h) { + rz_list_delete_data (cry->plugins, h); return true; } -R_API struct r_crypto_t *r_crypto_new(void) { - RCrypto *cry = R_NEW0 (RCrypto); - return r_crypto_init (cry, true); +RZ_API struct rz_crypto_t *rz_crypto_new(void) { + RzCrypto *cry = R_NEW0 (RzCrypto); + return rz_crypto_init (cry, true); } -R_API struct r_crypto_t *r_crypto_as_new(struct r_crypto_t *cry) { - RCrypto *c = R_NEW0 (RCrypto); +RZ_API struct rz_crypto_t *rz_crypto_as_new(struct rz_crypto_t *cry) { + RzCrypto *c = R_NEW0 (RzCrypto); if (c) { - r_crypto_init (c, false); // soft init + rz_crypto_init (c, false); // soft init memcpy (&c->plugins, &cry->plugins, sizeof (cry->plugins)); } return c; } -R_API struct r_crypto_t *r_crypto_free(RCrypto *cry) { +RZ_API struct rz_crypto_t *rz_crypto_free(RzCrypto *cry) { // TODO: call the destructor function of the plugin to destroy the *user pointer if needed - r_list_free (cry->plugins); + rz_list_free (cry->plugins); free (cry->output); free (cry->key); free (cry->iv); @@ -121,10 +121,10 @@ R_API struct r_crypto_t *r_crypto_free(RCrypto *cry) { return NULL; } -R_API bool r_crypto_use(RCrypto *cry, const char *algo) { - RListIter *iter; - RCryptoPlugin *h; - r_list_foreach (cry->plugins, iter, h) { +RZ_API bool rz_crypto_use(RzCrypto *cry, const char *algo) { + RzListIter *iter; + RzCryptoPlugin *h; + rz_list_foreach (cry->plugins, iter, h) { if (h && h->use && h->use (algo)) { cry->h = h; cry->key_len = h->get_key_size (cry); @@ -135,7 +135,7 @@ R_API bool r_crypto_use(RCrypto *cry, const char *algo) { return false; } -R_API bool r_crypto_set_key(RCrypto *cry, const ut8* key, int keylen, int mode, int direction) { +RZ_API bool rz_crypto_set_key(RzCrypto *cry, const ut8* key, int keylen, int mode, int direction) { if (keylen < 0) { keylen = strlen ((const char *)key); } @@ -145,29 +145,29 @@ R_API bool r_crypto_set_key(RCrypto *cry, const ut8* key, int keylen, int mode, return cry->h->set_key (cry, key, keylen, mode, direction); } -R_API int r_crypto_get_key_size(RCrypto *cry) { +RZ_API int rz_crypto_get_key_size(RzCrypto *cry) { return (cry && cry->h && cry->h->get_key_size)? cry->h->get_key_size (cry): 0; } -R_API bool r_crypto_set_iv(RCrypto *cry, const ut8 *iv, int ivlen) { +RZ_API bool rz_crypto_set_iv(RzCrypto *cry, const ut8 *iv, int ivlen) { return (cry && cry->h && cry->h->set_iv)? cry->h->set_iv(cry, iv, ivlen): 0; } // return the number of bytes written in the output buffer -R_API int r_crypto_update(RCrypto *cry, const ut8 *buf, int len) { +RZ_API int rz_crypto_update(RzCrypto *cry, const ut8 *buf, int len) { return (cry && cry->h && cry->h->update)? cry->h->update (cry, buf, len): 0; } -R_API int r_crypto_final(RCrypto *cry, const ut8 *buf, int len) { +RZ_API int rz_crypto_final(RzCrypto *cry, const ut8 *buf, int len) { return (cry && cry->h && cry->h->final)? cry->h->final (cry, buf, len): 0; } -// TODO: internal api?? used from plugins? TODO: use r_buf here -R_API int r_crypto_append(RCrypto *cry, const ut8 *buf, int len) { +// TODO: internal api?? used from plugins? TODO: use rz_buf here +RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len) { if (!cry || !buf) { return -1; } @@ -180,7 +180,7 @@ R_API int r_crypto_append(RCrypto *cry, const ut8 *buf, int len) { return cry->output_len; } -R_API ut8 *r_crypto_get_output(RCrypto *cry, int *size) { +RZ_API ut8 *rz_crypto_get_output(RzCrypto *cry, int *size) { if (cry->output_size < 1) { return NULL; } diff --git a/libr/crypto/des.c b/librz/crypto/des.c similarity index 96% rename from libr/crypto/des.c rename to librz/crypto/des.c index f1e5f6b782..9be78b1d38 100644 --- a/libr/crypto/des.c +++ b/librz/crypto/des.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #define ROTL28(rs, sh) ((((rs) << (sh)) | ((rs) >> (28 - (sh)))) & 0x0FFFFFFF) // left 28 #define ROTL(rs, sh) (((rs) << (sh)) | ((rs) >> (32 - (sh)))) // left 32 @@ -94,7 +94,7 @@ static const ut32 sbox8[64] = { 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000, 0x10041000 }; -R_API void r_des_permute_key (ut32 *keylo, ut32 *keyhi) { +RZ_API void rz_des_permute_key (ut32 *keylo, ut32 *keyhi) { if (!keylo || !keyhi) { return; } @@ -121,7 +121,7 @@ R_API void r_des_permute_key (ut32 *keylo, ut32 *keyhi) { } // first permutation of the block -R_API void r_des_permute_block0 (ut32 *blocklo, ut32 *blockhi) { +RZ_API void rz_des_permute_block0 (ut32 *blocklo, ut32 *blockhi) { if (!blocklo || !blockhi) { return; } @@ -142,7 +142,7 @@ R_API void r_des_permute_block0 (ut32 *blocklo, ut32 *blockhi) { } // last permutation of the block -R_API void r_des_permute_block1 (ut32 *blocklo, ut32 *blockhi) { +RZ_API void rz_des_permute_block1 (ut32 *blocklo, ut32 *blockhi) { if (!blocklo || !blockhi) { return; } @@ -166,7 +166,7 @@ R_API void r_des_permute_block1 (ut32 *blocklo, ut32 *blockhi) { // keylo & keyhi are the derivated round keys // deskeylo & deskeyhi are the des derivated keys -R_API void r_des_round_key (int i, ut32 *keylo, ut32 *keyhi, ut32 *deskeylo, ut32 *deskeyhi) { +RZ_API void rz_des_round_key (int i, ut32 *keylo, ut32 *keyhi, ut32 *deskeylo, ut32 *deskeyhi) { if (!keylo || !keyhi || !deskeylo || !deskeyhi) { return; } @@ -206,7 +206,7 @@ R_API void r_des_round_key (int i, ut32 *keylo, ut32 *keyhi, ut32 *deskeylo, ut3 ((deshi << 2) & 0x00000004) | ((deshi >> 21) & 0x00000002); } -R_API void r_des_round (ut32 *buflo, ut32 *bufhi, ut32 *roundkeylo, ut32 *roundkeyhi) { +RZ_API void rz_des_round (ut32 *buflo, ut32 *bufhi, ut32 *roundkeylo, ut32 *roundkeyhi) { if (!buflo || !bufhi || !roundkeylo || !roundkeyhi) { return; } diff --git a/libr/crypto/meson.build b/librz/crypto/meson.build similarity index 74% rename from libr/crypto/meson.build rename to librz/crypto/meson.build index 409dd969e6..534750cf60 100644 --- a/libr/crypto/meson.build +++ b/librz/crypto/meson.build @@ -1,4 +1,4 @@ -r_crypto_sources = [ +rz_crypto_sources = [ 'des.c', 'crypto.c', 'p/crypto_aes.c', @@ -21,9 +21,9 @@ r_crypto_sources = [ 'p/crypto_xor.c', ] -r_crypto = library('r_crypto', r_crypto_sources, +rz_crypto = library('rz_crypto', rz_crypto_sources, include_directories: [platform_inc], - dependencies: [r_util_dep], + dependencies: [rz_util_dep], c_args: library_cflags, install: true, implicit_include_directories: false, @@ -31,17 +31,17 @@ r_crypto = library('r_crypto', r_crypto_sources, soversion: r2_libversion ) -r_crypto_dep = declare_dependency(link_with: r_crypto, +rz_crypto_dep = declare_dependency(link_with: rz_crypto, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_crypto, - subdirs: 'libr', +pkgconfig_mod.generate(rz_crypto, + subdirs: 'librz', version: r2_version, - name: 'r_crypto', - filebase: 'r_crypto', + name: 'rz_crypto', + filebase: 'rz_crypto', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/crypto/p/Makefile b/librz/crypto/p/Makefile similarity index 92% rename from libr/crypto/p/Makefile rename to librz/crypto/p/Makefile index f70ba0e99f..68364869cb 100644 --- a/libr/crypto/p/Makefile +++ b/librz/crypto/p/Makefile @@ -1,7 +1,7 @@ include ../../config.mk include ../../../mk/platform.mk -LINK+=-L../../util -lr_util +LINK+=-L../../util -lrz_util LDFLAGS+=${LINK} ifeq ($(WITHPIC),1) diff --git a/libr/crypto/p/aes.mk b/librz/crypto/p/aes.mk similarity index 79% rename from libr/crypto/p/aes.mk rename to librz/crypto/p/aes.mk index a5fee097e8..b32b58a46d 100644 --- a/libr/crypto/p/aes.mk +++ b/librz/crypto/p/aes.mk @@ -1,7 +1,7 @@ OBJ_AES=crypto_aes.o crypto_aes_algo.o -R2DEPS+=r_util -DEPFLAGS=-L../../util -lr_util -L.. -lr_crypto +R2DEPS+=rz_util +DEPFLAGS=-L../../util -lrz_util -L.. -lrz_crypto STATIC_OBJ+=${OBJ_AES} TARGET_AES=crypto_aes.${EXT_SO} diff --git a/libr/crypto/p/aes_cbc.mk b/librz/crypto/p/aes_cbc.mk similarity index 85% rename from libr/crypto/p/aes_cbc.mk rename to librz/crypto/p/aes_cbc.mk index 54abe46ec7..6fbad8bf1b 100644 --- a/libr/crypto/p/aes_cbc.mk +++ b/librz/crypto/p/aes_cbc.mk @@ -4,7 +4,7 @@ STATIC_OBJ+=${OBJ_AES_CBC} TARGET_AES_CBC=crypto_aes_cbc.${EXT_SO} ALL_TARGETS+=${TARGET_AES_CBC} -DEPFLAGS=-L.. -lr_crypto -I../../../include +DEPFLAGS=-L.. -lrz_crypto -I../../../include ${TARGET_AES_CBC}: ${OBJ_AES_CBC} ${CC} $(call libname,crypto_aes_cbc) $(DEPFLAGS) \ diff --git a/libr/crypto/p/base64.mk b/librz/crypto/p/base64.mk similarity index 100% rename from libr/crypto/p/base64.mk rename to librz/crypto/p/base64.mk diff --git a/libr/crypto/p/base91.mk b/librz/crypto/p/base91.mk similarity index 100% rename from libr/crypto/p/base91.mk rename to librz/crypto/p/base91.mk diff --git a/libr/crypto/p/blowfish.mk b/librz/crypto/p/blowfish.mk similarity index 100% rename from libr/crypto/p/blowfish.mk rename to librz/crypto/p/blowfish.mk diff --git a/libr/crypto/p/cps2.mk b/librz/crypto/p/cps2.mk similarity index 100% rename from libr/crypto/p/cps2.mk rename to librz/crypto/p/cps2.mk diff --git a/libr/crypto/p/crypto_aes.c b/librz/crypto/p/crypto_aes.c similarity index 78% rename from libr/crypto/p/crypto_aes.c rename to librz/crypto/p/crypto_aes.c index bb1bab7412..c85766a97e 100644 --- a/libr/crypto/p/crypto_aes.c +++ b/librz/crypto/p/crypto_aes.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2015-2017 - pancake */ -#include -#include +#include +#include #include "crypto_aes_algo.h" // TODO: avoid globals static struct aes_state st = {{0}}; -static bool aes_set_key (RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool aes_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { if (!(keylen == 128 / 8 || keylen == 192 / 8 || keylen == 256 / 8)) { return false; } @@ -19,7 +19,7 @@ static bool aes_set_key (RCrypto *cry, const ut8 *key, int keylen, int mode, int return true; } -static int aes_get_key_size (RCrypto *cry) { +static int aes_get_key_size (RzCrypto *cry) { return st.key_size; } @@ -29,7 +29,7 @@ static bool aes_use (const char *algo) { #define BLOCK_SIZE 16 -static bool update (RCrypto *cry, const ut8 *buf, int len) { +static bool update (RzCrypto *cry, const ut8 *buf, int len) { // Pad to the block size, do not append dummy block const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE; const int size = len + diff; @@ -67,17 +67,17 @@ static bool update (RCrypto *cry, const ut8 *buf, int len) { // printf("%128s\n", obuf); - r_crypto_append (cry, obuf, size); + rz_crypto_append (cry, obuf, size); free (obuf); free (ibuf); return true; } -static bool final (RCrypto *cry, const ut8 *buf, int len) { +static bool final (RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_aes = { +RzCryptoPlugin rz_crypto_plugin_aes = { .name = "aes-ecb", .set_key = aes_set_key, .get_key_size = aes_get_key_size, @@ -87,9 +87,9 @@ RCryptoPlugin r_crypto_plugin_aes = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_aes, + .data = &rz_crypto_plugin_aes, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_aes_algo.c b/librz/crypto/p/crypto_aes_algo.c similarity index 100% rename from libr/crypto/p/crypto_aes_algo.c rename to librz/crypto/p/crypto_aes_algo.c diff --git a/libr/crypto/p/crypto_aes_algo.h b/librz/crypto/p/crypto_aes_algo.h similarity index 99% rename from libr/crypto/p/crypto_aes_algo.h rename to librz/crypto/p/crypto_aes_algo.h index 9bbf57ea99..bfcd604951 100644 --- a/libr/crypto/p/crypto_aes_algo.h +++ b/librz/crypto/p/crypto_aes_algo.h @@ -1,8 +1,8 @@ #ifndef CRYPTO_AES_ALGO_H #define CRYPTO_AES_ALGO_H -#include -#include +#include +#include #include struct aes_state { diff --git a/libr/crypto/p/crypto_aes_cbc.c b/librz/crypto/p/crypto_aes_cbc.c similarity index 78% rename from libr/crypto/p/crypto_aes_cbc.c rename to librz/crypto/p/crypto_aes_cbc.c index e4b549ef1f..bdd72f48e1 100644 --- a/libr/crypto/p/crypto_aes_cbc.c +++ b/librz/crypto/p/crypto_aes_cbc.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016-2017 - rakholiyajenish.07 */ -#include -#include +#include +#include #include "crypto_aes_algo.h" #define BLOCK_SIZE 16 @@ -10,7 +10,7 @@ static struct aes_state st; static bool iv_set = 0; static ut8 iv[32]; -static bool aes_cbc_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool aes_cbc_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { if (!(keylen == 128 / 8 || keylen == 192 / 8 || keylen == 256 / 8)) { return false; } @@ -22,11 +22,11 @@ static bool aes_cbc_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, return true; } -static int aes_cbc_get_key_size(RCrypto *cry) { +static int aes_cbc_get_key_size(RzCrypto *cry) { return st.key_size; } -static bool aes_cbc_set_iv(RCrypto *cry, const ut8 *iv_src, int ivlen) { +static bool aes_cbc_set_iv(RzCrypto *cry, const ut8 *iv_src, int ivlen) { if (ivlen != BLOCK_SIZE) { return false; } @@ -39,7 +39,7 @@ static bool aes_cbc_use(const char *algo) { return algo && !strcmp (algo, "aes-cbc"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { if (!iv_set) { eprintf ("IV not set. Use -I [iv]\n"); return false; @@ -85,17 +85,17 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { } } - r_crypto_append (cry, obuf, size); + rz_crypto_append (cry, obuf, size); free (obuf); free (ibuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_aes_cbc = { +RzCryptoPlugin rz_crypto_plugin_aes_cbc = { .name = "aes-cbc", .set_key = aes_cbc_set_key, .get_key_size = aes_cbc_get_key_size, @@ -106,9 +106,9 @@ RCryptoPlugin r_crypto_plugin_aes_cbc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_aes_cbc, + .data = &rz_crypto_plugin_aes_cbc, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_base64.c b/librz/crypto/p/crypto_base64.c similarity index 59% rename from libr/crypto/p/crypto_base64.c rename to librz/crypto/p/crypto_base64.c index 0eaf81e619..bdefe2fcc7 100644 --- a/libr/crypto/p/crypto_base64.c +++ b/librz/crypto/p/crypto_base64.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2016-2017 - rakholiyajenish.07 */ -#include -#include -#include +#include +#include +#include -static bool base64_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool base64_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { cry->dir = direction; return true; } -static int base64_get_key_size(RCrypto *cry) { +static int base64_get_key_size(RzCrypto *cry) { return 0; } @@ -17,7 +17,7 @@ static bool base64_use(const char *algo) { return !strcmp (algo, "base64"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { int olen = 0; ut8 *obuf = NULL; if (cry->dir == 0) { @@ -26,7 +26,7 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { if (!obuf) { return false; } - r_base64_encode ((char *)obuf, (const ut8 *)buf, len); + rz_base64_encode ((char *)obuf, (const ut8 *)buf, len); } else if (cry->dir == 1) { olen = 4 + ((len / 4) * 3); if (len > 0) { @@ -36,20 +36,20 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { if (!obuf) { return false; } - olen = r_base64_decode (obuf, (const char *)buf, len); + olen = rz_base64_decode (obuf, (const char *)buf, len); } if (olen > 0) { - r_crypto_append (cry, obuf, olen); + rz_crypto_append (cry, obuf, olen); } free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_base64 = { +RzCryptoPlugin rz_crypto_plugin_base64 = { .name = "base64", .set_key = base64_set_key, .get_key_size = base64_get_key_size, @@ -59,9 +59,9 @@ RCryptoPlugin r_crypto_plugin_base64 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_base64, + .data = &rz_crypto_plugin_base64, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_base91.c b/librz/crypto/p/crypto_base91.c similarity index 54% rename from libr/crypto/p/crypto_base91.c rename to librz/crypto/p/crypto_base91.c index 3c7182e2a5..6125552a03 100644 --- a/libr/crypto/p/crypto_base91.c +++ b/librz/crypto/p/crypto_base91.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2016-2017 - rakholiyajenish.07 */ -#include -#include -#include +#include +#include +#include #define INSIZE 32768 -static bool base91_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool base91_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { cry->dir = direction; return true; } -static int base91_get_key_size(RCrypto *cry) { +static int base91_get_key_size(RzCrypto *cry) { return 0; } @@ -19,7 +19,7 @@ static bool base91_use(const char *algo) { return algo && !strcmp (algo, "base91"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { int olen = INSIZE; if (!cry || !buf || len < 1) { return false; @@ -29,20 +29,20 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { return false; } if (cry->dir == 0) { - olen = r_base91_encode ((char *)obuf, (const ut8 *)buf, len); + olen = rz_base91_encode ((char *)obuf, (const ut8 *)buf, len); } else if (cry->dir == 1) { - olen = r_base91_decode (obuf, (const char *)buf, len); + olen = rz_base91_decode (obuf, (const char *)buf, len); } - r_crypto_append (cry, obuf, olen); + rz_crypto_append (cry, obuf, olen); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_base91 = { +RzCryptoPlugin rz_crypto_plugin_base91 = { .name = "base91", .set_key = base91_set_key, .get_key_size = base91_get_key_size, @@ -52,9 +52,9 @@ RCryptoPlugin r_crypto_plugin_base91 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_base91, + .data = &rz_crypto_plugin_base91, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_blowfish.c b/librz/crypto/p/crypto_blowfish.c similarity index 97% rename from libr/crypto/p/crypto_blowfish.c rename to librz/crypto/p/crypto_blowfish.c index e1adaeb0c6..aeb481dd68 100644 --- a/libr/crypto/p/crypto_blowfish.c +++ b/librz/crypto/p/crypto_blowfish.c @@ -3,8 +3,8 @@ * https://www.schneier.com/cryptography/archives/1994/09/description_of_a_new.html * */ -#include -#include +#include +#include #include #define BLOCK_SIZE 8 @@ -290,12 +290,12 @@ static bool blowfish_init(struct blowfish_state *const state, const ut8 *key, in static struct blowfish_state st = {{0}}; -static bool blowfish_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool blowfish_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { cry->dir = direction; return blowfish_init (&st, key, keylen); } -static int blowfish_get_key_size(RCrypto *cry) { +static int blowfish_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -303,7 +303,7 @@ static bool blowfish_use(const char *algo) { return !strcmp (algo, "blowfish"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { if (!cry || !buf) { return false; } @@ -316,16 +316,16 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { } else if (cry->dir == 1) { blowfish_decrypt (&st, buf, obuf, len); } - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_blowfish = { +RzCryptoPlugin rz_crypto_plugin_blowfish = { .name = "blowfish", .license = "LGPL3", .set_key = blowfish_set_key, @@ -336,9 +336,9 @@ RCryptoPlugin r_crypto_plugin_blowfish = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_blowfish, + .data = &rz_crypto_plugin_blowfish, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_cps2.c b/librz/crypto/p/crypto_cps2.c similarity index 96% rename from libr/crypto/p/crypto_cps2.c rename to librz/crypto/p/crypto_cps2.c index 7f0e4cfd7c..8ebefdf14f 100644 --- a/libr/crypto/p/crypto_cps2.c +++ b/librz/crypto/p/crypto_cps2.c @@ -9,8 +9,8 @@ ((BIT(val,B7) << 7) | (BIT(val,B6) << 6) | (BIT(val,B5) << 5) | (BIT(val,B4) << 4) | \ (BIT(val,B3) << 3) | (BIT(val,B2) << 2) | (BIT(val,B1) << 1) | (BIT(val,B0) << 0)) -#include -#include +#include +#include // license:BSD-3-Clause // copyright-holders:Paul Leaman, Andreas Naive, Nicola Salmoria,Charles MacDonald @@ -188,7 +188,7 @@ static const struct sbox fn1_r1_boxes[4] = { }, }; -static const struct sbox fn1_r2_boxes[4] = { +static const struct sbox fn1_rz_boxes[4] = { { // subkey bits 24-29 { 3,3,2,0,3,0,3,1,0,3,0,1,0,2,1,3,1,3,0,3,3,1,3,3,3,2,3,2,2,3,1,2, @@ -330,7 +330,7 @@ static const struct sbox fn2_r1_boxes[4] = { }, }; -static const struct sbox fn2_r2_boxes[4] = { +static const struct sbox fn2_rz_boxes[4] = { { // subkey bits 24-29 { 3,1,3,0,3,0,3,1,3,0,0,1,1,3,0,3,1,1,0,1,2,3,2,3,3,1,2,2,2,0,2,3, @@ -608,11 +608,11 @@ static void cps2_crypt(int dir, const ut16 *rom, ut16 *dec, int length, const ut struct optimised_sbox sboxes2[4*4]; optimise_sboxes(&sboxes1[0*4], fn1_r1_boxes); - optimise_sboxes(&sboxes1[1*4], fn1_r2_boxes); + optimise_sboxes(&sboxes1[1*4], fn1_rz_boxes); optimise_sboxes(&sboxes1[2*4], fn1_r3_boxes); optimise_sboxes(&sboxes1[3*4], fn1_r4_boxes); optimise_sboxes(&sboxes2[0*4], fn2_r1_boxes); - optimise_sboxes(&sboxes2[1*4], fn2_r2_boxes); + optimise_sboxes(&sboxes2[1*4], fn2_rz_boxes); optimise_sboxes(&sboxes2[2*4], fn2_r3_boxes); optimise_sboxes(&sboxes2[3*4], fn2_r4_boxes); @@ -671,10 +671,10 @@ static void cps2_crypt(int dir, const ut16 *rom, ut16 *dec, int length, const ut dec[a] = feistel (rom[a], fn2_groupA, fn2_groupB, &sboxes2[0*4], &sboxes2[1*4], &sboxes2[2*4], &sboxes2[3*4], key2[0], key2[1], key2[2], key2[3]); - dec[a] = r_read_be16 (&dec[a]); + dec[a] = rz_read_be16 (&dec[a]); } else { /* encrypt */ - dec[a] = r_read_be16 (&rom[a]); + dec[a] = rz_read_be16 (&rom[a]); dec[a] = feistel (dec[a], fn2_groupA, fn2_groupB, &sboxes2[3*4], &sboxes2[2*4], &sboxes2[1*4], &sboxes2[0*4], key2[3], key2[2], key2[1], key2[0]); @@ -682,7 +682,7 @@ static void cps2_crypt(int dir, const ut16 *rom, ut16 *dec, int length, const ut } // copy the unencrypted part while (a < length/2) { - dec[a] = r_read_be16 (&rom[a]); + dec[a] = rz_read_be16 (&rom[a]); a += 0x10000; } } @@ -715,19 +715,19 @@ main(cps_state,cps2crypt) { static ut32 cps2key[2] = {0}; -static bool set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { cry->dir = direction; if (keylen == 8) { /* fix key endianness */ const ut32 *key32 = (const ut32*)key; - cps2key[0] = r_read_be32 (key32); - cps2key[1] = r_read_be32 (key32 + 1); + cps2key[0] = rz_read_be32 (key32); + cps2key[1] = rz_read_be32 (key32 + 1); return true; } return false; } -static int get_key_size(RCrypto *cry) { +static int get_key_size(RzCrypto *cry) { /* 64bit key */ return 8; } @@ -736,16 +736,16 @@ static bool cps2_use(const char *algo) { return !strcmp (algo, "cps2"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { ut8 *output = calloc (1, len); /* TODO : control decryption errors */ cps2_crypt (cry->dir, (const ut16 *)buf, (ut16*)output, len, cps2key, UPPER_LIMIT); - r_crypto_append (cry, output, len); + rz_crypto_append (cry, output, len); free (output); return true; } -RCryptoPlugin r_crypto_plugin_cps2 = { +RzCryptoPlugin rz_crypto_plugin_cps2 = { .name = "cps2", .set_key = set_key, .get_key_size = get_key_size, @@ -754,9 +754,9 @@ RCryptoPlugin r_crypto_plugin_cps2 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rol, + .data = &rz_crypto_plugin_rol, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_des.c b/librz/crypto/p/crypto_des.c similarity index 75% rename from libr/crypto/p/crypto_des.c rename to librz/crypto/p/crypto_des.c index d58f235265..56502dfd1d 100644 --- a/libr/crypto/p/crypto_des.c +++ b/librz/crypto/p/crypto_des.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2017 - deroad */ -#include -#include -#include +#include +#include +#include struct des_state { ut32 keylo[16]; // round key low @@ -41,13 +41,13 @@ static int des_encrypt (struct des_state *st, const ut8 *input, ut8 *output) { st->bufhi = be32 (input + 4); //first permutation - r_des_permute_block0 (&st->buflo, &st->bufhi); + rz_des_permute_block0 (&st->buflo, &st->bufhi); for (st->i = 0; st->i < 16; st->i++) { - r_des_round (&st->buflo, &st->bufhi, &st->keylo[st->i], &st->keyhi[st->i]); + rz_des_round (&st->buflo, &st->bufhi, &st->keylo[st->i], &st->keyhi[st->i]); } //last permutation - r_des_permute_block1 (&st->bufhi, &st->buflo); + rz_des_permute_block1 (&st->bufhi, &st->buflo); //result wbe32 (output + 0, st->bufhi); @@ -63,21 +63,21 @@ static int des_decrypt (struct des_state *st, const ut8 *input, ut8 *output) { st->buflo = be32 (input + 0); st->bufhi = be32 (input + 4); //first permutation - r_des_permute_block0 (&st->buflo, &st->bufhi); + rz_des_permute_block0 (&st->buflo, &st->bufhi); for (st->i = 0; st->i < 16; st->i++) { - r_des_round (&st->buflo, &st->bufhi, &st->keylo[15 - st->i], &st->keyhi[15 - st->i]); + rz_des_round (&st->buflo, &st->bufhi, &st->keylo[15 - st->i], &st->keyhi[15 - st->i]); } //last permutation - r_des_permute_block1 (&st->bufhi, &st->buflo); + rz_des_permute_block1 (&st->bufhi, &st->buflo); //result wbe32 (output + 0, st->bufhi); wbe32 (output + 4, st->buflo); return true; } -static bool des_set_key (RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool des_set_key (RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { ut32 keylo, keyhi, i; if (keylen != DES_KEY_SIZE) { return false; @@ -90,17 +90,17 @@ static bool des_set_key (RCrypto *cry, const ut8 *key, int keylen, int mode, int st.rounds = 16; cry->dir = direction; // = direction == 0; // key permutation to derive round keys - r_des_permute_key (&keylo, &keyhi); + rz_des_permute_key (&keylo, &keyhi); for (i = 0; i < 16; i++) { // filling round keys space - r_des_round_key (i, &st.keylo[i], &st.keyhi[i], &keylo, &keyhi); + rz_des_round_key (i, &st.keylo[i], &st.keyhi[i], &keylo, &keyhi); } return true; } -static int des_get_key_size (RCrypto *cry) { +static int des_get_key_size (RzCrypto *cry) { return st.key_size; } @@ -108,7 +108,7 @@ static bool des_use (const char *algo) { return algo && !strcmp (algo, "des-ecb"); } -static bool update (RCrypto *cry, const ut8 *buf, int len) { +static bool update (RzCrypto *cry, const ut8 *buf, int len) { if (len <= 0) { return false; } @@ -150,17 +150,17 @@ static bool update (RCrypto *cry, const ut8 *buf, int len) { } } - r_crypto_append (cry, obuf, size); + rz_crypto_append (cry, obuf, size); free (obuf); free (ibuf); return 0; } -static bool final (RCrypto *cry, const ut8 *buf, int len) { +static bool final (RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_des = { +RzCryptoPlugin rz_crypto_plugin_des = { .name = "des-ecb", .set_key = des_set_key, .get_key_size = des_get_key_size, @@ -170,9 +170,9 @@ RCryptoPlugin r_crypto_plugin_des = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_des, + .data = &rz_crypto_plugin_des, .version = R2_VERSION }; #endif diff --git a/librz/crypto/p/crypto_punycode.c b/librz/crypto/p/crypto_punycode.c new file mode 100644 index 0000000000..209a04c8f3 --- /dev/null +++ b/librz/crypto/p/crypto_punycode.c @@ -0,0 +1,54 @@ +/* radare - LGPL - Copyright 2009-2016 - pancake */ + +#include +#include +#include + +static int flag = 0; + +static bool punycode_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { + flag = direction; + return true; +} + +static int punycode_get_key_size(RzCrypto *cry) { + return 0; +} + +static bool punycode_use(const char *algo) { + return !strcmp (algo, "punycode"); +} + +static bool update(RzCrypto *cry, const ut8 *buf, int len) { + char *obuf; + int olen; + if (flag) { + obuf = rz_punycode_decode ((const char *)buf, len, &olen); + } else { + obuf = rz_punycode_encode (buf, len, &olen); + } + rz_crypto_append (cry, (ut8*)obuf, olen); + free (obuf); + return true; +} + +static bool final(RzCrypto *cry, const ut8* buf, int len) { + return update (cry, buf, len); +} + +RzCryptoPlugin rz_crypto_plugin_punycode = { + .name = "punycode", + .set_key = punycode_set_key, + .get_key_size = punycode_get_key_size, + .use = punycode_use, + .update = update, + .final = final +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_CRYPTO, + .data = &rz_crypto_plugin_punycode, + .version = R2_VERSION +}; +#endif diff --git a/libr/crypto/p/crypto_rc2.c b/librz/crypto/p/crypto_rc2.c similarity index 94% rename from libr/crypto/p/crypto_rc2.c rename to librz/crypto/p/crypto_rc2.c index 45d3f7490f..698713b695 100644 --- a/libr/crypto/p/crypto_rc2.c +++ b/librz/crypto/p/crypto_rc2.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #define BITS 1024 #define RC2_KEY_SIZE 64 // bytes @@ -199,13 +199,13 @@ static void rc2_crypt(struct rc2_state *state, const ut8 *inbuf, ut8 *outbuf, in static struct rc2_state state; static int flag = 0; -static bool rc2_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool rc2_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { flag = direction; state.key_size = 1024; return rc2_expandKey(&state, key, keylen); } -static int rc2_get_key_size(RCrypto *cry) { +static int rc2_get_key_size(RzCrypto *cry) { return state.key_size; } @@ -213,7 +213,7 @@ static bool rc2_use(const char *algo) { return !strcmp (algo, "rc2"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { ut8 *obuf = calloc (1, len); if (!obuf) { return false; @@ -223,16 +223,16 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { } else if (flag == 1) { rc2_dcrypt (&state, buf, obuf, len); } - r_crypto_append(cry, obuf, len); + rz_crypto_append(cry, obuf, len); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_rc2 = { +RzCryptoPlugin rz_crypto_plugin_rc2 = { .name = "rc2", .set_key = rc2_set_key, .get_key_size = rc2_get_key_size, @@ -242,9 +242,9 @@ RCryptoPlugin r_crypto_plugin_rc2 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rc2, + .data = &rz_crypto_plugin_rc2, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_rc4.c b/librz/crypto/p/crypto_rc4.c similarity index 84% rename from libr/crypto/p/crypto_rc4.c rename to librz/crypto/p/crypto_rc4.c index 725e3ae855..78a272db53 100644 --- a/libr/crypto/p/crypto_rc4.c +++ b/librz/crypto/p/crypto_rc4.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016 - pancake */ -#include -#include +#include +#include struct rc4_state { @@ -74,11 +74,11 @@ static void rc4_crypt(struct rc4_state *const state, const ut8 *inbuf, ut8 *outb static struct rc4_state st; -static bool rc4_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool rc4_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { return rc4_init (&st, key, keylen); } -static int rc4_get_key_size(RCrypto *cry) { +static int rc4_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -86,22 +86,22 @@ static bool rc4_use(const char *algo) { return !strcmp (algo, "rc4"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { ut8 *obuf = calloc (1, len); if (!obuf) { return false; } rc4_crypt (&st, buf, obuf, len); - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return false; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_rc4 = { +RzCryptoPlugin rz_crypto_plugin_rc4 = { .name = "rc4", .set_key = rc4_set_key, .get_key_size = rc4_get_key_size, @@ -111,9 +111,9 @@ RCryptoPlugin r_crypto_plugin_rc4 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rc4, + .data = &rz_crypto_plugin_rc4, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_rc6.c b/librz/crypto/p/crypto_rc6.c similarity index 90% rename from libr/crypto/p/crypto_rc6.c rename to librz/crypto/p/crypto_rc6.c index ed12b56d3d..5196b9e230 100644 --- a/libr/crypto/p/crypto_rc6.c +++ b/librz/crypto/p/crypto_rc6.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2016 - pancake */ //Implemented AES version of RC6. keylen = 16, 23, or 32 bytes; w = 32; and r = 20. -#include -#include +#include +#include #define Pw 0xb7e15163 #define Qw 0x9e3779b9 @@ -156,11 +156,11 @@ static void rc6_decrypt(struct rc6_state *const state, const ut8 *inbuf, ut8 *ou static struct rc6_state st; -static bool rc6_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool rc6_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { return rc6_init (&st, key, keylen, direction); } -static int rc6_get_key_size(RCrypto *cry) { +static int rc6_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -168,7 +168,7 @@ static bool rc6_use(const char *algo) { return !strcmp (algo, "rc6"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { if (len % BLOCK_SIZE != 0) { //let user handle with with pad. eprintf ("Input should be multiple of 128bit.\n"); return false; @@ -192,16 +192,16 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { } } - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_rc6 = { +RzCryptoPlugin rz_crypto_plugin_rc6 = { .name = "rc6", .set_key = rc6_set_key, .get_key_size = rc6_get_key_size, @@ -211,9 +211,9 @@ RCryptoPlugin r_crypto_plugin_rc6 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rc6, + .data = &rz_crypto_plugin_rc6, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_rol.c b/librz/crypto/p/crypto_rol.c similarity index 77% rename from libr/crypto/p/crypto_rol.c rename to librz/crypto/p/crypto_rol.c index e1af520538..e6a3cdddcb 100644 --- a/libr/crypto/p/crypto_rol.c +++ b/librz/crypto/p/crypto_rol.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016 - pancake */ -#include -#include +#include +#include #define NAME "rol" @@ -36,12 +36,12 @@ static void rol_crypt(struct rol_state *const state, const ut8 *inbuf, ut8 *outb static struct rol_state st; static int flag = 0; -static bool rol_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool rol_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { flag = direction; return rol_init (&st, key, keylen); } -static int rol_get_key_size(RCrypto *cry) { +static int rol_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -49,7 +49,7 @@ static bool rol_use(const char *algo) { return !strcmp (algo, NAME); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { if (flag) { eprintf ("Use ROR\n"); return false; @@ -59,12 +59,12 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { return false; } rol_crypt (&st, buf, obuf, len); - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -RCryptoPlugin r_crypto_plugin_rol = { +RzCryptoPlugin rz_crypto_plugin_rol = { .name = NAME, .set_key = rol_set_key, .get_key_size = rol_get_key_size, @@ -74,9 +74,9 @@ RCryptoPlugin r_crypto_plugin_rol = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rol, + .data = &rz_crypto_plugin_rol, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_ror.c b/librz/crypto/p/crypto_ror.c similarity index 76% rename from libr/crypto/p/crypto_ror.c rename to librz/crypto/p/crypto_ror.c index ec34b8a184..1dd4d7527e 100644 --- a/libr/crypto/p/crypto_ror.c +++ b/librz/crypto/p/crypto_ror.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #define NAME "ror" @@ -34,12 +34,12 @@ static void ror_crypt(struct ror_state *const state, const ut8 *inbuf, ut8 *outb static struct ror_state st; static int flag = 0; -static bool ror_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool ror_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { flag = direction; return ror_init (&st, key, keylen); } -static int ror_get_key_size(RCrypto *cry) { +static int ror_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -47,7 +47,7 @@ static bool ror_use(const char *algo) { return !strcmp (algo, NAME); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { if (flag) { eprintf ("USE ROL\n"); return false; @@ -57,12 +57,12 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { return false; } ror_crypt (&st, buf, obuf, len); - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -RCryptoPlugin r_crypto_plugin_ror = { +RzCryptoPlugin rz_crypto_plugin_ror = { .name = NAME, .set_key = ror_set_key, .get_key_size = ror_get_key_size, @@ -72,9 +72,9 @@ RCryptoPlugin r_crypto_plugin_ror = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_ror, + .data = &rz_crypto_plugin_ror, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_rot.c b/librz/crypto/p/crypto_rot.c similarity index 81% rename from libr/crypto/p/crypto_rot.c rename to librz/crypto/p/crypto_rot.c index dc65cf2336..89bea46913 100644 --- a/libr/crypto/p/crypto_rot.c +++ b/librz/crypto/p/crypto_rot.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include -#include +#include +#include int mod(int a, int b) { if (b < 0) { @@ -55,12 +55,12 @@ static void rot_decrypt(ut8 key, const ut8 *inbuf, ut8 *outbuf, int buflen) { static ut8 rot_key; static int flag = 0; -static bool rot_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool rot_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { flag = direction; return rot_init (&rot_key, key, keylen); } -static int rot_get_key_size(RCrypto *cry) { +static int rot_get_key_size(RzCrypto *cry) { //Returning number of bytes occupied by ut8 return 1; } @@ -69,7 +69,7 @@ static bool rot_use(const char *algo) { return !strcmp (algo, "rot"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { ut8 *obuf = calloc (1, len); if (!obuf) { return false; @@ -79,16 +79,16 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { } else if (flag == 1) { rot_decrypt (rot_key, buf, obuf, len); } - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_rot = { +RzCryptoPlugin rz_crypto_plugin_rot = { .name = "rot", .set_key = rot_set_key, .get_key_size = rot_get_key_size, @@ -98,9 +98,9 @@ RCryptoPlugin r_crypto_plugin_rot = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_rot, + .data = &rz_crypto_plugin_rot, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_serpent.c b/librz/crypto/p/crypto_serpent.c similarity index 79% rename from libr/crypto/p/crypto_serpent.c rename to librz/crypto/p/crypto_serpent.c index 694dba0913..57dd7a8fc9 100644 --- a/libr/crypto/p/crypto_serpent.c +++ b/librz/crypto/p/crypto_serpent.c @@ -1,10 +1,10 @@ -#include -#include +#include +#include #include "crypto_serpent_algo.h" static struct serpent_state st = {{0}}; -static bool serpent_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool serpent_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { eprintf ("key_size: %d\n", keylen); if ((keylen != 128 / 8) && (keylen != 192 / 8) && (keylen != 256 / 8)) { return false; @@ -16,7 +16,7 @@ static bool serpent_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, return true; } -static int serpent_get_key_size(RCrypto *cry) { +static int serpent_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -26,7 +26,7 @@ static bool serpent_use(const char *algo) { #define BLOCK_SIZE 16 -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { // Pad to the block size, do not append dummy block const int diff = (BLOCK_SIZE - (len % BLOCK_SIZE)) % BLOCK_SIZE; const int size = len + diff; @@ -51,7 +51,7 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { // Construct ut32 blocks from byte stream for (j = 0; j < size/4; j++) { - ibuf[j] = r_read_le32(&buf[4*j]); + ibuf[j] = rz_read_le32(&buf[4*j]); } // Zero padding. @@ -80,18 +80,18 @@ static bool update(RCrypto *cry, const ut8 *buf, int len) { obuf[k+3] = (tmp[j] >> 24) & 0xff; } - r_crypto_append (cry, obuf, size); + rz_crypto_append (cry, obuf, size); free (obuf); free (ibuf); free (tmp); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_serpent = { +RzCryptoPlugin rz_crypto_plugin_serpent = { .name = "serpent-ecb", .set_key = serpent_set_key, .get_key_size = serpent_get_key_size, @@ -101,9 +101,9 @@ RCryptoPlugin r_crypto_plugin_serpent = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_serpent, + .data = &rz_crypto_plugin_serpent, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/crypto_serpent_algo.c b/librz/crypto/p/crypto_serpent_algo.c similarity index 100% rename from libr/crypto/p/crypto_serpent_algo.c rename to librz/crypto/p/crypto_serpent_algo.c diff --git a/libr/crypto/p/crypto_serpent_algo.h b/librz/crypto/p/crypto_serpent_algo.h similarity index 98% rename from libr/crypto/p/crypto_serpent_algo.h rename to librz/crypto/p/crypto_serpent_algo.h index e44f1b2799..9a3a740de1 100644 --- a/libr/crypto/p/crypto_serpent_algo.h +++ b/librz/crypto/p/crypto_serpent_algo.h @@ -1,7 +1,7 @@ #ifndef CRYPTO_SERPENT_ALGO_H #define CRYPTO_SERPENT_ALGO_H -#include +#include #define DW_BY_BLOCK 4 #define DW_BY_USERKEY 8 #define NB_ROUNDS 32 diff --git a/libr/crypto/p/crypto_xor.c b/librz/crypto/p/crypto_xor.c similarity index 73% rename from libr/crypto/p/crypto_xor.c rename to librz/crypto/p/crypto_xor.c index e47d22cf38..29c680403b 100644 --- a/libr/crypto/p/crypto_xor.c +++ b/librz/crypto/p/crypto_xor.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include -#include +#include +#include #define MAX_xor_KEY_SIZE 32768 @@ -32,11 +32,11 @@ static void xor_crypt(struct xor_state *const state, const ut8 *inbuf, ut8 *outb outbuf[i] = inbuf[i] ^ state->key[(i%state->key_size)]; } } -static bool xor_set_key(RCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { +static bool xor_set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { return xor_init (&st, key, keylen); } -static int xor_get_key_size(RCrypto *cry) { +static int xor_get_key_size(RzCrypto *cry) { return st.key_size; } @@ -44,22 +44,22 @@ static bool xor_use(const char *algo) { return !strcmp (algo, "xor"); } -static bool update(RCrypto *cry, const ut8 *buf, int len) { +static bool update(RzCrypto *cry, const ut8 *buf, int len) { ut8 *obuf = calloc (1, len); if (!obuf) { return false; } xor_crypt (&st, buf, obuf, len); - r_crypto_append (cry, obuf, len); + rz_crypto_append (cry, obuf, len); free (obuf); return true; } -static bool final(RCrypto *cry, const ut8 *buf, int len) { +static bool final(RzCrypto *cry, const ut8 *buf, int len) { return update (cry, buf, len); } -RCryptoPlugin r_crypto_plugin_xor = { +RzCryptoPlugin rz_crypto_plugin_xor = { .name = "xor", .set_key = xor_set_key, .get_key_size = xor_get_key_size, @@ -69,9 +69,9 @@ RCryptoPlugin r_crypto_plugin_xor = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_CRYPTO, - .data = &r_crypto_plugin_xor, + .data = &rz_crypto_plugin_xor, .version = R2_VERSION }; #endif diff --git a/libr/crypto/p/des.mk b/librz/crypto/p/des.mk similarity index 100% rename from libr/crypto/p/des.mk rename to librz/crypto/p/des.mk diff --git a/libr/crypto/p/punycode.mk b/librz/crypto/p/punycode.mk similarity index 100% rename from libr/crypto/p/punycode.mk rename to librz/crypto/p/punycode.mk diff --git a/libr/crypto/p/rc2.mk b/librz/crypto/p/rc2.mk similarity index 100% rename from libr/crypto/p/rc2.mk rename to librz/crypto/p/rc2.mk diff --git a/libr/crypto/p/rc4.mk b/librz/crypto/p/rc4.mk similarity index 100% rename from libr/crypto/p/rc4.mk rename to librz/crypto/p/rc4.mk diff --git a/libr/crypto/p/rc6.mk b/librz/crypto/p/rc6.mk similarity index 100% rename from libr/crypto/p/rc6.mk rename to librz/crypto/p/rc6.mk diff --git a/libr/crypto/p/rol.mk b/librz/crypto/p/rol.mk similarity index 100% rename from libr/crypto/p/rol.mk rename to librz/crypto/p/rol.mk diff --git a/libr/crypto/p/ror.mk b/librz/crypto/p/ror.mk similarity index 100% rename from libr/crypto/p/ror.mk rename to librz/crypto/p/ror.mk diff --git a/libr/crypto/p/rot.mk b/librz/crypto/p/rot.mk similarity index 100% rename from libr/crypto/p/rot.mk rename to librz/crypto/p/rot.mk diff --git a/libr/crypto/p/serpent.mk b/librz/crypto/p/serpent.mk similarity index 82% rename from libr/crypto/p/serpent.mk rename to librz/crypto/p/serpent.mk index f7acd1a844..816fb1d361 100644 --- a/libr/crypto/p/serpent.mk +++ b/librz/crypto/p/serpent.mk @@ -1,7 +1,7 @@ OBJ_SERPENT=crypto_serpent.o crypto_serpent_algo.o -R2DEPS+=r_util -DEPFLAGS=-L../../util -lr_util -L.. -lr_crypto +R2DEPS+=rz_util +DEPFLAGS=-L../../util -lrz_util -L.. -lrz_crypto STATIC_OBJ+=${OBJ_SERPENT} TARGET_SERPENT=crypto_serpent.${EXT_SO} diff --git a/libr/crypto/p/xor.mk b/librz/crypto/p/xor.mk similarity index 100% rename from libr/crypto/p/xor.mk rename to librz/crypto/p/xor.mk diff --git a/libr/debug/Makefile b/librz/debug/Makefile similarity index 89% rename from libr/debug/Makefile rename to librz/debug/Makefile index 268160ffc1..d019bcf5a6 100644 --- a/libr/debug/Makefile +++ b/librz/debug/Makefile @@ -1,8 +1,8 @@ include ../config.mk -NAME=r_debug -R2DEPS=r_reg r_anal r_bp r_io r_parse r_cons r_syscall r_hash r_flag r_util r_egg r_crypto -R2DEPS+=r_socket +NAME=rz_debug +R2DEPS=rz_reg rz_anal rz_bp rz_io rz_parse rz_cons rz_syscall rz_hash rz_flag rz_util rz_egg rz_crypto +R2DEPS+=rz_socket CFLAGS+=-DR2_PLUGIN_INCORE ifeq ($(OSTYPE),bsd) diff --git a/libr/debug/arg.c b/librz/debug/arg.c similarity index 78% rename from libr/debug/arg.c rename to librz/debug/arg.c index 61d8623ecb..c3e1040848 100644 --- a/libr/debug/arg.c +++ b/librz/debug/arg.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2010-2015 pancake */ -#include +#include -R_API ut64 r_debug_arg_get (RDebug *dbg, int cctype, int num) { +RZ_API ut64 rz_debug_arg_get (RzDebug *dbg, int cctype, int num) { ut32 n32; ut64 n64, sp; char reg[32]; @@ -11,10 +11,10 @@ R_API ut64 r_debug_arg_get (RDebug *dbg, int cctype, int num) { case R_ANAL_CC_TYPE_SYSV: case R_ANAL_CC_TYPE_FASTCALL: snprintf (reg, sizeof (reg)-1, "A%d", num); - return r_debug_reg_get (dbg, reg); + return rz_debug_reg_get (dbg, reg); case R_ANAL_CC_TYPE_STDCALL: case R_ANAL_CC_TYPE_PASCAL: - sp = r_debug_reg_get (dbg, "SP"); + sp = rz_debug_reg_get (dbg, "SP"); if (dbg->bits == 64) { sp += 8; // skip return address, assume we are inside the call sp += 8 * num; @@ -30,17 +30,17 @@ R_API ut64 r_debug_arg_get (RDebug *dbg, int cctype, int num) { } } snprintf (reg, sizeof (reg)-1, "A%d", num); - return r_debug_reg_get (dbg, reg); + return rz_debug_reg_get (dbg, reg); } -R_API bool r_debug_arg_set (RDebug *dbg, int cctype, int num, ut64 val) { +RZ_API bool rz_debug_arg_set (RzDebug *dbg, int cctype, int num, ut64 val) { // TODO replace the hardcoded implementation with the sdb char reg[32]; switch (cctype) { case R_ANAL_CC_TYPE_SYSV: case R_ANAL_CC_TYPE_FASTCALL: snprintf (reg, 30, "A%d", num); - return r_debug_reg_set (dbg, reg, val); + return rz_debug_reg_set (dbg, reg, val); case R_ANAL_CC_TYPE_STDCALL: case R_ANAL_CC_TYPE_PASCAL: /* TODO: get from stack */ diff --git a/libr/debug/ddesc.c b/librz/debug/ddesc.c similarity index 63% rename from libr/debug/ddesc.c rename to librz/debug/ddesc.c index 7f96fde97a..ccc87f9b96 100644 --- a/libr/debug/ddesc.c +++ b/librz/debug/ddesc.c @@ -2,10 +2,10 @@ // XXX: All this stuff must be linked to the code injection api -#include +#include -R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int off) { - RDebugDesc *desc = R_NEW (RDebugDesc); +RZ_API RzDebugDesc *rz_debug_desc_new (int fd, char* path, int perm, int type, int off) { + RzDebugDesc *desc = R_NEW (RzDebugDesc); if (desc) { desc->fd = fd; desc->path = strdup (path); @@ -16,7 +16,7 @@ R_API RDebugDesc *r_debug_desc_new (int fd, char* path, int perm, int type, int return desc; } -R_API void r_debug_desc_free (RDebugDesc *p) { +RZ_API void rz_debug_desc_free (RzDebugDesc *p) { if (p) { if (p->path) { free (p->path); @@ -25,53 +25,53 @@ R_API void r_debug_desc_free (RDebugDesc *p) { } } -R_API int r_debug_desc_open(RDebug *dbg, const char *path) { +RZ_API int rz_debug_desc_open(RzDebug *dbg, const char *path) { if (dbg && dbg->h && dbg->h->desc.open) { return dbg->h->desc.open (path); } return false; } -R_API int r_debug_desc_close(RDebug *dbg, int fd) { +RZ_API int rz_debug_desc_close(RzDebug *dbg, int fd) { if (dbg && dbg->h && dbg->h->desc.close) { return dbg->h->desc.close (fd); } return false; } -R_API int r_debug_desc_dup(RDebug *dbg, int fd, int newfd) { +RZ_API int rz_debug_desc_dup(RzDebug *dbg, int fd, int newfd) { if (dbg && dbg->h && dbg->h->desc.dup) { return dbg->h->desc.dup (fd, newfd); } return false; } -R_API int r_debug_desc_read(RDebug *dbg, int fd, ut64 addr, int len) { +RZ_API int rz_debug_desc_read(RzDebug *dbg, int fd, ut64 addr, int len) { if (dbg && dbg->h && dbg->h->desc.read) { return dbg->h->desc.read (fd, addr, len); } return false; } -R_API int r_debug_desc_seek(RDebug *dbg, int fd, ut64 addr) { +RZ_API int rz_debug_desc_seek(RzDebug *dbg, int fd, ut64 addr) { if (dbg && dbg->h && dbg->h->desc.seek) { return dbg->h->desc.seek (fd, addr); } return false; } -R_API int r_debug_desc_write(RDebug *dbg, int fd, ut64 addr, int len) { +RZ_API int rz_debug_desc_write(RzDebug *dbg, int fd, ut64 addr, int len) { if (dbg && dbg->h && dbg->h->desc.write) { return dbg->h->desc.write (fd, addr, len); } return false; } -R_API int r_debug_desc_list(RDebug *dbg, int rad) { +RZ_API int rz_debug_desc_list(RzDebug *dbg, int rad) { int count = 0; - RList *list; - RListIter *iter; - RDebugDesc *p; + RzList *list; + RzListIter *iter; + RzDebugDesc *p; if (rad) { if (dbg && dbg->cb_printf) { @@ -80,13 +80,13 @@ R_API int r_debug_desc_list(RDebug *dbg, int rad) { } else { if (dbg && dbg->h && dbg->h->desc.list) { list = dbg->h->desc.list (dbg->pid); - r_list_foreach (list, iter, p) { + rz_list_foreach (list, iter, p) { dbg->cb_printf ("%i 0x%"PFMT64x" %c%c%c %s\n", p->fd, p->off, (p->perm & R_PERM_R)?'r':'-', (p->perm & R_PERM_W)?'w':'-', p->type, p->path); } - r_list_purge (list); + rz_list_purge (list); free (list); } } diff --git a/libr/debug/debug.c b/librz/debug/debug.c similarity index 67% rename from libr/debug/debug.c rename to librz/debug/debug.c index c2a33421ff..af62a74b30 100644 --- a/libr/debug/debug.c +++ b/librz/debug/debug.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2009-2018 - pancake, jduck, TheLemonMan, saucec0de */ -#include -#include -#include +#include +#include +#include #include -R_LIB_VERSION(r_debug); +R_LIB_VERSION(rz_debug); -// Size of the lookahead buffers used in r_debug functions +// Size of the lookahead buffers used in rz_debug functions #define DBG_BUF_SIZE 512 -R_API RDebugInfo *r_debug_info(RDebug *dbg, const char *arg) { +RZ_API RzDebugInfo *rz_debug_info(RzDebug *dbg, const char *arg) { if (!dbg || !dbg->h || !dbg->h->info) { return NULL; } @@ -20,7 +20,7 @@ R_API RDebugInfo *r_debug_info(RDebug *dbg, const char *arg) { return dbg->h->info (dbg, arg); } -R_API void r_debug_info_free(RDebugInfo *rdi) { +RZ_API void rz_debug_info_free(RzDebugInfo *rdi) { if (rdi) { free (rdi->cwd); free (rdi->exe); @@ -31,18 +31,18 @@ R_API void r_debug_info_free(RDebugInfo *rdi) { } } -R_API void r_debug_bp_update(RDebug *dbg) { +RZ_API void rz_debug_bp_update(RzDebug *dbg) { /* update all bp->addr if they are named bps */ RBreakpointItem *bp; - RListIter *iter; - r_list_foreach (dbg->bp->bps, iter, bp) { + RzListIter *iter; + rz_list_foreach (dbg->bp->bps, iter, bp) { if (bp->expr) { bp->addr = dbg->corebind.numGet (dbg->corebind.core, bp->expr); } } } -static int r_debug_drx_at(RDebug *dbg, ut64 addr) { +static int rz_debug_drx_at(RzDebug *dbg, ut64 addr) { if (dbg && dbg->h && dbg->h->drx) { return dbg->h->drx (dbg, 0, addr, 0, 0, 0, DRX_API_GET_BP); } @@ -55,10 +55,10 @@ static int r_debug_drx_at(RDebug *dbg, ut64 addr) { * 2. on resume, single step once and then replace the breakpoint. * * Thus, we have two functions to handle these situations. - * r_debug_bp_hit handles stage 1. - * r_debug_recoil handles stage 2. + * rz_debug_bp_hit handles stage 1. + * rz_debug_recoil handles stage 2. */ -static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem **pb) { +static int rz_debug_bp_hit(RzDebug *dbg, RzRegItem *pc_ri, ut64 pc, RBreakpointItem **pb) { RBreakpointItem *b; if (!pb) { @@ -70,7 +70,7 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem /* if we are tracing, update the tracing data */ if (dbg->trace->enabled) { - r_debug_trace_pc (dbg, pc); + rz_debug_trace_pc (dbg, pc); } /* remove all sw breakpoints for now. we'll set them back in stage 2 @@ -78,12 +78,12 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem * this is necessary because while stopped we don't want any breakpoints in * the code messing up our analysis. */ - r_debug_bp_update (dbg); - if (!r_bp_restore (dbg->bp, false)) { // unset sw breakpoints + rz_debug_bp_update (dbg); + if (!rz_bp_restore (dbg->bp, false)) { // unset sw breakpoints return false; } - /* if we are recoiling, tell r_debug_step that we ignored a breakpoint + /* if we are recoiling, tell rz_debug_step that we ignored a breakpoint * event */ if (!dbg->swstep && dbg->recoil_mode != R_DBG_RECOIL_NONE) { dbg->reason.bp_addr = 0; @@ -93,7 +93,7 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem /* The MIPS ptrace has a different behaviour */ # if __mips__ /* see if we really have a breakpoint here... */ - b = r_bp_get_at (dbg->bp, pc); + b = rz_bp_get_at (dbg->bp, pc); if (!b) { /* we don't. nothing left to do */ return true; } @@ -101,13 +101,13 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem int pc_off = dbg->bpsize; /* see if we really have a breakpoint here... */ if (!dbg->pc_at_bp_set) { - b = r_bp_get_at (dbg->bp, pc - dbg->bpsize); + b = rz_bp_get_at (dbg->bp, pc - dbg->bpsize); if (!b) { /* we don't. nothing left to do */ /* Some targets set pc to breakpoint */ - b = r_bp_get_at (dbg->bp, pc); + b = rz_bp_get_at (dbg->bp, pc); if (!b) { /* handle the case of hw breakpoints - notify the user */ - int drx_reg_idx = r_debug_drx_at (dbg, pc); + int drx_reg_idx = rz_debug_drx_at (dbg, pc); if (drx_reg_idx != -1) { eprintf ("hit hardware breakpoint %d at: %" PFMT64x "\n", drx_reg_idx, pc); @@ -131,19 +131,19 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem if (dbg->pc_at_bp) { pc_off = 0; - b = r_bp_get_at (dbg->bp, pc); + b = rz_bp_get_at (dbg->bp, pc); } else { - b = r_bp_get_at (dbg->bp, pc - dbg->bpsize); + b = rz_bp_get_at (dbg->bp, pc - dbg->bpsize); } if (!b) { return true; } - b = r_bp_get_at (dbg->bp, pc - dbg->bpsize); + b = rz_bp_get_at (dbg->bp, pc - dbg->bpsize); if (!b) { /* we don't. nothing left to do */ /* Some targets set pc to breakpoint */ - b = r_bp_get_at (dbg->bp, pc); + b = rz_bp_get_at (dbg->bp, pc); if (!b) { return true; } @@ -153,11 +153,11 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem /* set the pc value back */ if (pc_off) { pc -= pc_off; - if (!r_reg_set_value (dbg->reg, pc_ri, pc)) { + if (!rz_reg_set_value (dbg->reg, pc_ri, pc)) { eprintf ("failed to set PC!\n"); return false; } - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, true)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, true)) { eprintf ("cannot set registers!\n"); return false; } @@ -191,10 +191,10 @@ static int r_debug_bp_hit(RDebug *dbg, RRegItem *pc_ri, ut64 pc, RBreakpointItem } /* enable all software breakpoints */ -static int r_debug_bps_enable(RDebug *dbg) { +static int rz_debug_bps_enable(RzDebug *dbg) { /* restore all sw breakpoints. we are about to step/continue so these need * to be in place. */ - if (!r_bp_restore (dbg->bp, true)) { + if (!rz_bp_restore (dbg->bp, true)) { return false; } /* done recoiling... */ @@ -205,7 +205,7 @@ static int r_debug_bps_enable(RDebug *dbg) { /* * replace breakpoints before we continue execution * - * this is called from r_debug_step_hard or r_debug_continue_kill + * this is called from rz_debug_step_hard or rz_debug_continue_kill * * this is a trick process because of breakpoints/tracepoints. * @@ -214,10 +214,10 @@ static int r_debug_bps_enable(RDebug *dbg) { * * if the user wants to step, the single step here does the job. */ -static int r_debug_recoil(RDebug *dbg, RDebugRecoilMode rc_mode) { +static int rz_debug_recoil(RzDebug *dbg, RzDebugRecoilMode rc_mode) { /* if bp_addr is not set, we must not have actually hit a breakpoint */ if (!dbg->reason.bp_addr) { - return r_debug_bps_enable (dbg); + return rz_debug_bps_enable (dbg); } /* don't do anything if we already are recoiling */ @@ -228,7 +228,7 @@ static int r_debug_recoil(RDebug *dbg, RDebugRecoilMode rc_mode) { * so we just restore all except what we originally hit and reset. */ if (dbg->swstep) { - if (!r_bp_restore_except (dbg->bp, true, dbg->reason.bp_addr)) { + if (!rz_bp_restore_except (dbg->bp, true, dbg->reason.bp_addr)) { return false; } return true; @@ -242,12 +242,12 @@ static int r_debug_recoil(RDebug *dbg, RDebugRecoilMode rc_mode) { dbg->recoil_mode = rc_mode; /* step over the place with the breakpoint and let the caller resume */ - if (r_debug_step (dbg, 1) != 1) { + if (rz_debug_step (dbg, 1) != 1) { return false; } /* when stepping away from a breakpoint during recoil in stepping mode, - * the r_debug_bp_hit function tells us that it was called + * the rz_debug_bp_hit function tells us that it was called * innapropriately by setting bp_addr back to zero. however, recoil_mode * is still set. we use this condition to know not to proceed but * pretend as if we had. @@ -257,41 +257,41 @@ static int r_debug_recoil(RDebug *dbg, RDebugRecoilMode rc_mode) { } dbg->reason.bp_addr = 0; - return r_debug_bps_enable (dbg); + return rz_debug_bps_enable (dbg); } /* add a breakpoint with some typical values */ -R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch, int rw, char *module, st64 m_delta) { - int bpsz = r_bp_size(dbg->bp); +RZ_API RBreakpointItem *rz_debug_bp_add(RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, char *module, st64 m_delta) { + int bpsz = rz_bp_size(dbg->bp); RBreakpointItem *bpi; const char *module_name = module; - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; if (!addr && module) { bool detect_module, valid = false; int perm; if (m_delta) { detect_module = false; - RList *list = r_debug_modules_list (dbg); - r_list_foreach (list, iter, map) { + RzList *list = rz_debug_modules_list (dbg); + rz_list_foreach (list, iter, map) { if (strstr (map->file, module)) { addr = map->addr + m_delta; module_name = map->file; break; } } - r_list_free (list); + rz_list_free (list); } else { //module holds the address - addr = (ut64)r_num_math (dbg->num, module); + addr = (ut64)rz_num_math (dbg->num, module); if (!addr) { return NULL; } detect_module = true; } - r_debug_map_sync (dbg); - r_list_foreach (dbg->maps, iter, map) { + rz_debug_map_sync (dbg); + rz_list_foreach (dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { valid = true; if (detect_module) { @@ -312,8 +312,8 @@ R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch } if (!module) { //express db breakpoints as dbm due to ASLR when saving into project - r_debug_map_sync (dbg); - r_list_foreach (dbg->maps, iter, map) { + rz_debug_map_sync (dbg); + rz_list_foreach (dbg->maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { module_name = map->file; m_delta = addr - map->addr; @@ -323,30 +323,30 @@ R_API RBreakpointItem *r_debug_bp_add(RDebug *dbg, ut64 addr, int hw, bool watch } if (watch) { hw = 1; //XXX - bpi = r_bp_watch_add (dbg->bp, addr, bpsz, hw, rw); + bpi = rz_bp_watch_add (dbg->bp, addr, bpsz, hw, rw); } else { bpi = hw - ? r_bp_add_hw (dbg->bp, addr, bpsz, R_BP_PROT_EXEC) - : r_bp_add_sw (dbg->bp, addr, bpsz, R_BP_PROT_EXEC); + ? rz_bp_add_hw (dbg->bp, addr, bpsz, R_BP_PROT_EXEC) + : rz_bp_add_sw (dbg->bp, addr, bpsz, R_BP_PROT_EXEC); } if (bpi) { if (module_name) { bpi->module_name = strdup (module_name); - bpi->name = r_str_newf ("%s+0x%" PFMT64x, module_name, m_delta); + bpi->name = rz_str_newf ("%s+0x%" PFMT64x, module_name, m_delta); } bpi->module_delta = m_delta; } return bpi; } -static const char *r_debug_str_callback(RNum *userptr, ut64 off, int *ok) { - // RDebug *dbg = (RDebug *)userptr; +static const char *rz_debug_str_callback(RNum *userptr, ut64 off, int *ok) { + // RzDebug *dbg = (RzDebug *)userptr; eprintf ("STR CALLBACK WTF WTF WTF\n"); return NULL; } -R_API RDebug *r_debug_new(int hard) { - RDebug *dbg = R_NEW0 (RDebug); +RZ_API RzDebug *rz_debug_new(int hard) { + RzDebug *dbg = R_NEW0 (RzDebug); if (!dbg) { return NULL; } @@ -358,8 +358,8 @@ R_API RDebug *r_debug_new(int hard) { dbg->main_pid = -1; dbg->n_threads = 0; dbg->trace_clone = 0; - dbg->egg = r_egg_new (); - r_egg_setup (dbg->egg, R_SYS_ARCH, R_SYS_BITS, R_SYS_ENDIAN, R_SYS_OS); + dbg->egg = rz_egg_new (); + rz_egg_setup (dbg->egg, R_SYS_ARCH, R_SYS_BITS, R_SYS_ENDIAN, R_SYS_OS); dbg->trace_aftersyscall = true; dbg->follow_child = false; R_FREE (dbg->btalgo); @@ -368,67 +368,67 @@ R_API RDebug *r_debug_new(int hard) { dbg->pid = -1; dbg->bpsize = 1; dbg->tid = -1; - dbg->tree = r_tree_new (); + dbg->tree = rz_tree_new (); dbg->tracenodes = sdb_new0 (); dbg->swstep = 0; dbg->stop_all_threads = false; - dbg->trace = r_debug_trace_new (); + dbg->trace = rz_debug_trace_new (); dbg->cb_printf = (void *)printf; - dbg->reg = r_reg_new (); - dbg->num = r_num_new (r_debug_num_callback, r_debug_str_callback, dbg); + dbg->reg = rz_reg_new (); + dbg->num = rz_num_new (rz_debug_num_callback, rz_debug_str_callback, dbg); dbg->h = NULL; dbg->threads = NULL; dbg->hitinfo = 1; /* TODO: needs a redesign? */ - dbg->maps = r_debug_map_list_new (); - dbg->maps_user = r_debug_map_list_new (); + dbg->maps = rz_debug_map_list_new (); + dbg->maps_user = rz_debug_map_list_new (); dbg->q_regs = NULL; dbg->call_frames = NULL; dbg->main_arena_resolved = false; dbg->glibc_version = 231; /* default version ubuntu 20 */ - r_debug_signal_init (dbg); + rz_debug_signal_init (dbg); if (hard) { - dbg->bp = r_bp_new (); - r_debug_plugin_init (dbg); + dbg->bp = rz_bp_new (); + rz_debug_plugin_init (dbg); dbg->bp->iob.init = false; dbg->bp->baddr = 0; } return dbg; } -static int free_tracenodes_entry(RDebug *dbg, const char *k, const char *v) { - ut64 v_num = r_num_get (NULL, v); +static int free_tracenodes_entry(RzDebug *dbg, const char *k, const char *v) { + ut64 v_num = rz_num_get (NULL, v); free((void *)(size_t)v_num); return true; } -R_API void r_debug_tracenodes_reset(RDebug *dbg) { +RZ_API void rz_debug_tracenodes_reset(RzDebug *dbg) { sdb_foreach (dbg->tracenodes, (SdbForeachCallback)free_tracenodes_entry, dbg); sdb_reset (dbg->tracenodes); } -R_API RDebug *r_debug_free(RDebug *dbg) { +RZ_API RzDebug *rz_debug_free(RzDebug *dbg) { if (dbg) { // TODO: free it correctly.. we must ensure this is an instance and not a reference.. - r_bp_free (dbg->bp); - //r_reg_free(&dbg->reg); + rz_bp_free (dbg->bp); + //rz_reg_free(&dbg->reg); free (dbg->snap_path); - r_list_free (dbg->maps); - r_list_free (dbg->maps_user); - r_list_free (dbg->threads); - r_num_free (dbg->num); + rz_list_free (dbg->maps); + rz_list_free (dbg->maps_user); + rz_list_free (dbg->threads); + rz_num_free (dbg->num); sdb_free (dbg->sgnls); - r_tree_free (dbg->tree); + rz_tree_free (dbg->tree); sdb_foreach (dbg->tracenodes, (SdbForeachCallback)free_tracenodes_entry, dbg); sdb_free (dbg->tracenodes); - r_list_free (dbg->plugins); - r_list_free (dbg->call_frames); + rz_list_free (dbg->plugins); + rz_list_free (dbg->call_frames); free (dbg->btalgo); - r_debug_trace_free (dbg->trace); - r_debug_session_free (dbg->session); - r_anal_op_free (dbg->cur_op); + rz_debug_trace_free (dbg->trace); + rz_debug_session_free (dbg->session); + rz_anal_op_free (dbg->cur_op); dbg->trace = NULL; - r_egg_free (dbg->egg); + rz_egg_free (dbg->egg); free (dbg->arch); free (dbg->glob_libs); free (dbg->glob_unlibs); @@ -437,28 +437,28 @@ R_API RDebug *r_debug_free(RDebug *dbg) { return NULL; } -R_API int r_debug_attach(RDebug *dbg, int pid) { +RZ_API int rz_debug_attach(RzDebug *dbg, int pid) { int ret = false; if (dbg && dbg->h && dbg->h->attach) { ret = dbg->h->attach (dbg, pid); if (ret != -1) { - r_debug_select (dbg, pid, ret); //dbg->pid, dbg->tid); + rz_debug_select (dbg, pid, ret); //dbg->pid, dbg->tid); } } return ret; } /* stop execution of child process */ -R_API int r_debug_stop(RDebug *dbg) { +RZ_API int rz_debug_stop(RzDebug *dbg) { if (dbg && dbg->h && dbg->h->stop) { return dbg->h->stop (dbg); } return false; } -R_API bool r_debug_set_arch(RDebug *dbg, const char *arch, int bits) { +RZ_API bool rz_debug_set_arch(RzDebug *dbg, const char *arch, int bits) { if (arch && dbg && dbg->h) { - bool rc = r_sys_arch_match (dbg->h->arch, arch); + bool rc = rz_sys_arch_match (dbg->h->arch, arch); if (rc) { switch (bits) { case 27: @@ -497,28 +497,28 @@ R_API bool r_debug_set_arch(RDebug *dbg, const char *arch, int bits) { /* * Save 4096 bytes from %esp * TODO: Add support for reverse stack architectures - * Also known as r_debug_inject() + * Also known as rz_debug_inject() */ -R_API ut64 r_debug_execute(RDebug *dbg, const ut8 *buf, int len, int restore) { +RZ_API ut64 rz_debug_execute(RzDebug *dbg, const ut8 *buf, int len, int restore) { int orig_sz; ut8 stackbackup[4096]; ut8 *backup, *orig = NULL; - RRegItem *ri, *risp, *ripc; + RzRegItem *ri, *risp, *ripc; ut64 rsp, rpc, ra0 = 0LL; - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return false; } - ripc = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); - risp = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_SP], R_REG_TYPE_GPR); + ripc = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); + risp = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_SP], R_REG_TYPE_GPR); if (ripc) { - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - orig = r_reg_get_bytes (dbg->reg, R_REG_TYPE_ALL, &orig_sz); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + orig = rz_reg_get_bytes (dbg->reg, R_REG_TYPE_ALL, &orig_sz); if (!orig) { eprintf ("Cannot get register arena bytes\n"); return 0LL; } - rpc = r_reg_get_value (dbg->reg, ripc); - rsp = r_reg_get_value (dbg->reg, risp); + rpc = rz_reg_get_value (dbg->reg, ripc); + rsp = rz_reg_get_value (dbg->reg, risp); backup = malloc (len); if (!backup) { @@ -528,51 +528,51 @@ R_API ut64 r_debug_execute(RDebug *dbg, const ut8 *buf, int len, int restore) { dbg->iob.read_at (dbg->iob.io, rpc, backup, len); dbg->iob.read_at (dbg->iob.io, rsp, stackbackup, len); - r_bp_add_sw (dbg->bp, rpc+len, dbg->bpsize, R_BP_PROT_EXEC); + rz_bp_add_sw (dbg->bp, rpc+len, dbg->bpsize, R_BP_PROT_EXEC); /* execute code here */ dbg->iob.write_at (dbg->iob.io, rpc, buf, len); - //r_bp_add_sw (dbg->bp, rpc+len, 4, R_BP_PROT_EXEC); - r_debug_continue (dbg); - //r_bp_del (dbg->bp, rpc+len); + //rz_bp_add_sw (dbg->bp, rpc+len, 4, R_BP_PROT_EXEC); + rz_debug_continue (dbg); + //rz_bp_del (dbg->bp, rpc+len); /* TODO: check if stopped in breakpoint or not */ - r_bp_del (dbg->bp, rpc+len); + rz_bp_del (dbg->bp, rpc+len); dbg->iob.write_at (dbg->iob.io, rpc, backup, len); if (restore) { dbg->iob.write_at (dbg->iob.io, rsp, stackbackup, len); } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - ri = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_A0], R_REG_TYPE_GPR); - ra0 = r_reg_get_value (dbg->reg, ri); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + ri = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_A0], R_REG_TYPE_GPR); + ra0 = rz_reg_get_value (dbg->reg, ri); if (restore) { - r_reg_read_regs (dbg->reg, orig, orig_sz); + rz_reg_read_regs (dbg->reg, orig, orig_sz); } else { - r_reg_set_value (dbg->reg, ripc, rpc); + rz_reg_set_value (dbg->reg, ripc, rpc); } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, true); free (backup); free (orig); eprintf ("ra0=0x%08"PFMT64x"\n", ra0); } else { - eprintf ("r_debug_execute: Cannot get program counter\n"); + eprintf ("rz_debug_execute: Cannot get program counter\n"); } return (ra0); } -R_API int r_debug_startv(struct r_debug_t *dbg, int argc, char **argv) { - /* TODO : r_debug_startv unimplemented */ +RZ_API int rz_debug_startv(struct rz_debug_t *dbg, int argc, char **argv) { + /* TODO : rz_debug_startv unimplemented */ return false; } -R_API int r_debug_start(RDebug *dbg, const char *cmd) { - /* TODO: this argc/argv parser is done in r_io */ +RZ_API int rz_debug_start(RzDebug *dbg, const char *cmd) { + /* TODO: this argc/argv parser is done in rz_io */ // TODO: parse cmd and generate argc and argv return false; } -R_API int r_debug_detach(RDebug *dbg, int pid) { +RZ_API int rz_debug_detach(RzDebug *dbg, int pid) { int ret = 0; if (dbg->h && dbg->h->detach) { ret = dbg->h->detach (dbg, pid); @@ -584,7 +584,7 @@ R_API int r_debug_detach(RDebug *dbg, int pid) { return ret; } -R_API bool r_debug_select(RDebug *dbg, int pid, int tid) { +RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid) { ut64 pc = 0; int prev_pid = dbg->pid; int prev_tid = dbg->tid; @@ -620,23 +620,23 @@ R_API bool r_debug_select(RDebug *dbg, int pid, int tid) { dbg->tid = tid; } - r_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); + rz_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); // Synchronize with the current thread's data if (dbg->corebind.core) { - RCore *core = (RCore *)dbg->corebind.core; + RzCore *core = (RzCore *)dbg->corebind.core; - r_reg_arena_swap (core->dbg->reg, true); - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); + rz_reg_arena_swap (core->dbg->reg, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); - pc = r_debug_reg_get (dbg, "PC"); + pc = rz_debug_reg_get (dbg, "PC"); core->offset = pc; } return true; } -R_API const char *r_debug_reason_to_string(int type) { +RZ_API const char *rz_debug_reason_to_string(int type) { switch (type) { case R_DEBUG_REASON_DEAD: return "dead"; case R_DEBUG_REASON_ABORT: return "abort"; @@ -667,7 +667,7 @@ R_API const char *r_debug_reason_to_string(int type) { return "unhandled"; } -R_API RDebugReasonType r_debug_stop_reason(RDebug *dbg) { +RZ_API RzDebugReasonType rz_debug_stop_reason(RzDebug *dbg) { // TODO: return reason to stop debugging // - new process // - trap instruction @@ -682,8 +682,8 @@ R_API RDebugReasonType r_debug_stop_reason(RDebug *dbg) { * * Returns R_DEBUG_REASON_* */ -R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { - RDebugReasonType reason = R_DEBUG_REASON_ERROR; +RZ_API RzDebugReasonType rz_debug_wait(RzDebug *dbg, RBreakpointItem **bp) { + RzDebugReasonType reason = R_DEBUG_REASON_ERROR; if (!dbg) { return reason; } @@ -693,7 +693,7 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { } /* default to unknown */ dbg->reason.type = R_DEBUG_REASON_UNKNOWN; - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return R_DEBUG_REASON_DEAD; } @@ -705,9 +705,9 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { REventDebugProcessFinished event = { .pid = dbg->pid }; - r_event_send (dbg->ev, R_EVENT_DEBUG_PROCESS_FINISHED, &event); + rz_event_send (dbg->ev, R_EVENT_DEBUG_PROCESS_FINISHED, &event); // XXX(jjd): TODO: handle fallback or something else - //r_debug_select (dbg, -1, -1); + //rz_debug_select (dbg, -1, -1); return R_DEBUG_REASON_DEAD; } @@ -716,7 +716,7 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { // when writing to the same process memory to set/unset breakpoints // and is problematic in Linux. if (dbg->continue_all_threads) { - r_debug_stop (dbg); + rz_debug_stop (dbg); } #endif @@ -726,7 +726,7 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { } /* read general purpose registers */ - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { return R_DEBUG_REASON_ERROR; } @@ -735,21 +735,21 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { if (reason == R_DEBUG_REASON_BREAKPOINT || reason == R_DEBUG_REASON_STEP || (libs_bp && ((reason == R_DEBUG_REASON_NEW_LIB) || (reason == R_DEBUG_REASON_EXIT_LIB)))) { - RRegItem *pc_ri; + RzRegItem *pc_ri; RBreakpointItem *b = NULL; ut64 pc; /* get the program coounter */ - pc_ri = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], -1); + pc_ri = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], -1); if (!pc_ri) { /* couldn't find PC?! */ eprintf ("Couldn't find PC!\n"); return R_DEBUG_REASON_ERROR; } /* get the value */ - pc = r_reg_get_value (dbg->reg, pc_ri); + pc = rz_reg_get_value (dbg->reg, pc_ri); - if (!r_debug_bp_hit (dbg, pc_ri, pc, &b)) { + if (!rz_debug_bp_hit (dbg, pc_ri, pc, &b)) { return R_DEBUG_REASON_ERROR; } @@ -773,10 +773,10 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { dbg->reason.type = reason; if (reason == R_DEBUG_REASON_SIGNAL && dbg->reason.signum != -1) { /* handle signal on continuations here */ - int what = r_debug_signal_what (dbg, dbg->reason.signum); - const char *name = r_signal_to_string (dbg->reason.signum); + int what = rz_debug_signal_what (dbg, dbg->reason.signum); + const char *name = rz_signal_to_string (dbg->reason.signum); if (name && strcmp ("SIGTRAP", name)) { - r_cons_printf ("[+] signal %d aka %s received %d\n", + rz_cons_printf ("[+] signal %d aka %s received %d\n", dbg->reason.signum, name, what); } } @@ -784,11 +784,11 @@ R_API RDebugReasonType r_debug_wait(RDebug *dbg, RBreakpointItem **bp) { return reason; } -R_API int r_debug_step_soft(RDebug *dbg) { +RZ_API int rz_debug_step_soft(RzDebug *dbg) { ut8 buf[32]; ut64 pc, sp, r; ut64 next[2]; - RAnalOp op; + RzAnalOp op; int br, i, ret; union { ut64 r64; @@ -803,12 +803,12 @@ R_API int r_debug_step_soft(RDebug *dbg) { dbg->recoil_mode = R_DBG_RECOIL_STEP; } - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return false; } - pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); - sp = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_SP]); + pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + sp = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_SP]); if (!dbg->iob.read_at) { return false; @@ -816,7 +816,7 @@ R_API int r_debug_step_soft(RDebug *dbg) { if (!dbg->iob.read_at (dbg->iob.io, pc, buf, sizeof (buf))) { return false; } - if (!r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC)) { + if (!rz_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC)) { return false; } if (op.type == R_ANAL_OP_TYPE_ILL) { @@ -841,13 +841,13 @@ R_API int r_debug_step_soft(RDebug *dbg) { break; case R_ANAL_OP_TYPE_RJMP: case R_ANAL_OP_TYPE_RCALL: - r = r_debug_reg_get (dbg,op.reg); + r = rz_debug_reg_get (dbg,op.reg); next[0] = r; br = 1; break; case R_ANAL_OP_TYPE_IRCALL: case R_ANAL_OP_TYPE_IRJMP: - r = r_debug_reg_get (dbg,op.reg); + r = rz_debug_reg_get (dbg,op.reg); if (!dbg->iob.read_at (dbg->iob.io, r, (ut8*)&memval, 8)) { next[0] = op.addr + op.size; } else { @@ -858,7 +858,7 @@ R_API int r_debug_step_soft(RDebug *dbg) { case R_ANAL_OP_TYPE_UCALL: case R_ANAL_OP_TYPE_MJMP: if (op.ireg) { - r = r_debug_reg_get (dbg,op.ireg); + r = rz_debug_reg_get (dbg,op.ireg); } else { r = 0; } @@ -877,33 +877,33 @@ R_API int r_debug_step_soft(RDebug *dbg) { } for (i = 0; i < br; i++) { - RBreakpointItem *bpi = r_bp_add_sw (dbg->bp, next[i], dbg->bpsize, R_BP_PROT_EXEC); + RBreakpointItem *bpi = rz_bp_add_sw (dbg->bp, next[i], dbg->bpsize, R_BP_PROT_EXEC); if (bpi) { bpi->swstep = true; } } - ret = r_debug_continue (dbg); + ret = rz_debug_continue (dbg); for (i = 0; i < br; i++) { - r_bp_del (dbg->bp, next[i]); + rz_bp_del (dbg->bp, next[i]); } return ret; } -R_API int r_debug_step_hard(RDebug *dbg, RBreakpointItem **pb) { - RDebugReasonType reason; +RZ_API int rz_debug_step_hard(RzDebug *dbg, RBreakpointItem **pb) { + RzDebugReasonType reason; dbg->reason.type = R_DEBUG_REASON_STEP; - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return false; } /* only handle recoils when not already in recoil mode. */ if (dbg->recoil_mode == R_DBG_RECOIL_NONE) { /* handle the stage-2 of breakpoints */ - if (!r_debug_recoil (dbg, R_DBG_RECOIL_STEP)) { + if (!rz_debug_recoil (dbg, R_DBG_RECOIL_STEP)) { return false; } @@ -924,19 +924,19 @@ R_API int r_debug_step_hard(RDebug *dbg, RBreakpointItem **pb) { bool prev_continue = dbg->continue_all_threads; dbg->continue_all_threads = false; #endif - reason = r_debug_wait (dbg, pb); + reason = rz_debug_wait (dbg, pb); #if __linux__ dbg->continue_all_threads = prev_continue; #endif - if (reason == R_DEBUG_REASON_DEAD || r_debug_is_dead (dbg)) { + if (reason == R_DEBUG_REASON_DEAD || rz_debug_is_dead (dbg)) { return false; } // Unset breakpoints before leaving if (reason != R_DEBUG_REASON_BREAKPOINT && reason != R_DEBUG_REASON_COND && reason != R_DEBUG_REASON_TRACEPOINT) { - r_bp_restore (dbg->bp, false); + rz_bp_restore (dbg->bp, false); } /* TODO: handle better */ if (reason == R_DEBUG_REASON_ERROR) { @@ -945,7 +945,7 @@ R_API int r_debug_step_hard(RDebug *dbg, RBreakpointItem **pb) { return true; } -R_API int r_debug_step(RDebug *dbg, int steps) { +RZ_API int rz_debug_step(RzDebug *dbg, int steps) { RBreakpointItem *bp = NULL; int ret, steps_taken = 0; @@ -958,7 +958,7 @@ R_API int r_debug_step(RDebug *dbg, int steps) { return steps_taken; } - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return steps_taken; } @@ -966,7 +966,7 @@ R_API int r_debug_step(RDebug *dbg, int steps) { if (dbg->session) { if (dbg->session->cnum != dbg->session->maxcnum) { - steps_taken = r_debug_step_cnum (dbg, steps); + steps_taken = rz_debug_step_cnum (dbg, steps); } } @@ -975,15 +975,15 @@ R_API int r_debug_step(RDebug *dbg, int steps) { dbg->session->cnum++; dbg->session->maxcnum++; dbg->session->bp = 0; - if (!r_debug_trace_ins_before (dbg)) { + if (!rz_debug_trace_ins_before (dbg)) { eprintf ("trace_ins_before: failed"); } } if (dbg->swstep) { - ret = r_debug_step_soft (dbg); + ret = rz_debug_step_soft (dbg); } else { - ret = r_debug_step_hard (dbg, &bp); + ret = rz_debug_step_hard (dbg, &bp); } if (!ret) { eprintf ("Stepping failed!\n"); @@ -991,7 +991,7 @@ R_API int r_debug_step(RDebug *dbg, int steps) { } if (dbg->session && dbg->recoil_mode == R_DBG_RECOIL_NONE) { - if (!r_debug_trace_ins_after (dbg)) { + if (!rz_debug_trace_ins_after (dbg)) { eprintf ("trace_ins_after: failed"); } dbg->session->reasontype = dbg->reason.type; @@ -1016,13 +1016,13 @@ static bool isStepOverable(ut64 opType) { return false; } -R_API int r_debug_step_over(RDebug *dbg, int steps) { - RAnalOp op; +RZ_API int rz_debug_step_over(RzDebug *dbg, int steps) { + RzAnalOp op; ut64 buf_pc, pc, ins_size; ut8 buf[DBG_BUF_SIZE]; int steps_taken = 0; - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return steps_taken; } @@ -1035,13 +1035,13 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) { if (dbg->session && dbg->recoil_mode == R_DBG_RECOIL_NONE) { dbg->session->cnum++; dbg->session->maxcnum++; - r_debug_trace_ins_before (dbg); + rz_debug_trace_ins_before (dbg); } if (!dbg->h->step_over (dbg)) { return steps_taken; } if (dbg->session && dbg->recoil_mode == R_DBG_RECOIL_NONE) { - r_debug_trace_ins_after (dbg); + rz_debug_trace_ins_after (dbg); } } return steps_taken; @@ -1052,18 +1052,18 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) { } // Initial refill - buf_pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + buf_pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); dbg->iob.read_at (dbg->iob.io, buf_pc, buf, sizeof (buf)); for (; steps_taken < steps; steps_taken++) { - pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); // Try to keep the buffer full if (pc - buf_pc > sizeof (buf)) { buf_pc = pc; dbg->iob.read_at (dbg->iob.io, buf_pc, buf, sizeof (buf)); } // Analyze the opcode - if (!r_anal_op (dbg->anal, &op, pc, buf + (pc - buf_pc), sizeof (buf) - (pc - buf_pc), R_ANAL_OP_MASK_BASIC)) { + if (!rz_anal_op (dbg->anal, &op, pc, buf + (pc - buf_pc), sizeof (buf) - (pc - buf_pc), R_ANAL_OP_MASK_BASIC)) { eprintf ("debug-step-over: Decode error at %"PFMT64x"\n", pc); return steps_taken; } @@ -1075,57 +1075,57 @@ R_API int r_debug_step_over(RDebug *dbg, int steps) { } // Skip over all the subroutine calls if (isStepOverable (op.type)) { - if (!r_debug_continue_until (dbg, ins_size)) { + if (!rz_debug_continue_until (dbg, ins_size)) { eprintf ("Could not step over call @ 0x%"PFMT64x"\n", pc); return steps_taken; } } else if ((op.prefix & (R_ANAL_OP_PREFIX_REP | R_ANAL_OP_PREFIX_REPNE | R_ANAL_OP_PREFIX_LOCK))) { //eprintf ("REP: skip to next instruction...\n"); - if (!r_debug_continue_until (dbg, ins_size)) { + if (!rz_debug_continue_until (dbg, ins_size)) { eprintf ("step over failed over rep\n"); return steps_taken; } } else { - r_debug_step (dbg, 1); + rz_debug_step (dbg, 1); } } return steps_taken; } -R_API bool r_debug_goto_cnum(RDebug *dbg, ut32 cnum) { +RZ_API bool rz_debug_goto_cnum(RzDebug *dbg, ut32 cnum) { if (cnum > dbg->session->maxcnum) { eprintf ("Error: out of cnum range\n"); return false; } dbg->session->cnum = cnum; - r_debug_session_restore_reg_mem (dbg, cnum); + rz_debug_session_restore_reg_mem (dbg, cnum); return true; } -R_API int r_debug_step_back(RDebug *dbg, int steps) { +RZ_API int rz_debug_step_back(RzDebug *dbg, int steps) { if (steps > dbg->session->cnum) { steps = dbg->session->cnum; } - if (!r_debug_goto_cnum (dbg, dbg->session->cnum - steps)) { + if (!rz_debug_goto_cnum (dbg, dbg->session->cnum - steps)) { return -1; } return steps; } -R_API int r_debug_step_cnum(RDebug *dbg, int steps) { +RZ_API int rz_debug_step_cnum(RzDebug *dbg, int steps) { if (steps > dbg->session->maxcnum - dbg->session->cnum) { steps = dbg->session->maxcnum - dbg->session->cnum; } - r_debug_goto_cnum (dbg, dbg->session->cnum + steps); + rz_debug_goto_cnum (dbg, dbg->session->cnum + steps); return steps; } -R_API int r_debug_continue_kill(RDebug *dbg, int sig) { - RDebugReasonType reason = R_DEBUG_REASON_NONE; +RZ_API int rz_debug_continue_kill(RzDebug *dbg, int sig) { + RzDebugReasonType reason = R_DEBUG_REASON_NONE; int ret = 0; RBreakpointItem *bp = NULL; @@ -1137,32 +1137,32 @@ R_API int r_debug_continue_kill(RDebug *dbg, int sig) { // Go to the end or the next breakpoint in the changes if (dbg->session && dbg->session->cnum != dbg->session->maxcnum) { bool has_bp = false; - RRegItem *ripc = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); - RVector *vreg = ht_up_find (dbg->session->registers, ripc->offset | (ripc->arena << 16), NULL); - RDebugChangeReg *reg; - r_vector_foreach_prev (vreg, reg) { + RzRegItem *ripc = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); + RzVector *vreg = ht_up_find (dbg->session->registers, ripc->offset | (ripc->arena << 16), NULL); + RzDebugChangeReg *reg; + rz_vector_foreach_prev (vreg, reg) { if (reg->cnum <= dbg->session->cnum) { continue; } - has_bp = r_bp_get_in (dbg->bp, reg->data, R_BP_PROT_EXEC) != NULL; + has_bp = rz_bp_get_in (dbg->bp, reg->data, R_BP_PROT_EXEC) != NULL; if (has_bp) { eprintf ("hit breakpoint at: 0x%" PFMT64x " cnum: %d\n", reg->data, reg->cnum); - r_debug_goto_cnum (dbg, reg->cnum); + rz_debug_goto_cnum (dbg, reg->cnum); return dbg->tid; } } - r_debug_goto_cnum (dbg, dbg->session->maxcnum); + rz_debug_goto_cnum (dbg, dbg->session->maxcnum); return dbg->tid; } repeat: - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return 0; } if (dbg->session && dbg->trace_continue) { - while (!r_cons_is_breaked ()) { - if (r_debug_step (dbg, 1) != 1) { + while (!rz_cons_is_breaked ()) { + if (rz_debug_step (dbg, 1) != 1) { break; } if (dbg->session->reasontype != R_DEBUG_REASON_STEP) { @@ -1173,19 +1173,19 @@ repeat: bp = dbg->session->bp; } else if (dbg->h && dbg->h->cont) { /* handle the stage-2 of breakpoints */ - if (!r_debug_recoil (dbg, R_DBG_RECOIL_CONTINUE)) { + if (!rz_debug_recoil (dbg, R_DBG_RECOIL_CONTINUE)) { return 0; } /* tell the inferior to go! */ ret = dbg->h->cont (dbg, dbg->pid, dbg->tid, sig); //XXX(jjd): why? //dbg->reason.signum = 0; - reason = r_debug_wait (dbg, &bp); + reason = rz_debug_wait (dbg, &bp); } else { return 0; } if (dbg->corebind.core) { - RCore *core = (RCore *)dbg->corebind.core; + RzCore *core = (RzCore *)dbg->corebind.core; RNum *num = core->num; if (reason == R_DEBUG_REASON_COND) { if (bp && bp->cond && dbg->corebind.cmd) { @@ -1197,7 +1197,7 @@ repeat: } } if (reason == R_DEBUG_REASON_BREAKPOINT && - ((bp && !bp->enabled) || (!bp && !r_cons_is_breaked () && dbg->corebind.core && + ((bp && !bp->enabled) || (!bp && !rz_cons_is_breaked () && dbg->corebind.core && dbg->corebind.cfggeti (dbg->corebind.core, "dbg.bpsysign")))) { goto repeat; } @@ -1207,9 +1207,9 @@ repeat: #if DEBUGGER /// if the plugin is not compiled link fails, so better do runtime linking /// until this code gets fixed - static bool (*linux_attach_new_process) (RDebug *dbg, int pid) = NULL; + static bool (*linux_attach_new_process) (RzDebug *dbg, int pid) = NULL; if (!linux_attach_new_process) { - linux_attach_new_process = r_lib_dl_sym (NULL, "linux_attach_new_process"); + linux_attach_new_process = rz_lib_dl_sym (NULL, "linux_attach_new_process"); } if (linux_attach_new_process) { linux_attach_new_process (dbg, dbg->forked_pid); @@ -1245,35 +1245,35 @@ repeat: #if __WINDOWS__ dbg->pid = -1; #elif __linux__ - r_debug_bp_update (dbg); - r_bp_restore (dbg->bp, false); // (vdf) there has got to be a better way + rz_debug_bp_update (dbg); + rz_bp_restore (dbg->bp, false); // (vdf) there has got to be a better way #endif } /* if continuing killed the inferior, we won't be able to get * the registers.. */ - if (reason == R_DEBUG_REASON_DEAD || r_debug_is_dead (dbg)) { + if (reason == R_DEBUG_REASON_DEAD || rz_debug_is_dead (dbg)) { return 0; } /* if we hit a tracing breakpoint, we need to continue in * whatever mode the user desired. */ if (reason == R_DEBUG_REASON_TRACEPOINT) { - r_debug_step (dbg, 1); + rz_debug_step (dbg, 1); goto repeat; } /* choose the thread that was returned from the continue function */ // XXX(jjd): there must be a cleaner way to do this... if (ret != dbg->tid) { - r_debug_select (dbg, dbg->pid, ret); + rz_debug_select (dbg, dbg->pid, ret); } sig = 0; // clear continuation after signal if needed /* handle general signals here based on the return from the wait * function */ if (dbg->reason.signum != -1) { - int what = r_debug_signal_what (dbg, dbg->reason.signum); + int what = rz_debug_signal_what (dbg, dbg->reason.signum); if (what & R_DBG_SIGNAL_CONT) { sig = dbg->reason.signum; eprintf ("Continue into the signal %d handler\n", sig); @@ -1281,63 +1281,63 @@ repeat: } else if (what & R_DBG_SIGNAL_SKIP) { // skip signal. requires skipping one instruction ut8 buf[64]; - RAnalOp op = {0}; - ut64 pc = r_debug_reg_get (dbg, "PC"); + RzAnalOp op = {0}; + ut64 pc = rz_debug_reg_get (dbg, "PC"); dbg->iob.read_at (dbg->iob.io, pc, buf, sizeof (buf)); - r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); + rz_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_BASIC); if (op.size > 0) { - const char *signame = r_signal_to_string (dbg->reason.signum); - r_debug_reg_set (dbg, "PC", pc+op.size); + const char *signame = rz_signal_to_string (dbg->reason.signum); + rz_debug_reg_set (dbg, "PC", pc+op.size); eprintf ("Skip signal %d handler %s\n", dbg->reason.signum, signame); goto repeat; } else { - ut64 pc = r_debug_reg_get (dbg, "PC"); + ut64 pc = rz_debug_reg_get (dbg, "PC"); eprintf ("Stalled with an exception at 0x%08"PFMT64x"\n", pc); } } } #if __WINDOWS__ - r_cons_break_pop (); + rz_cons_break_pop (); #endif // Unset breakpoints before leaving if (reason != R_DEBUG_REASON_BREAKPOINT) { - r_bp_restore (dbg->bp, false); + rz_bp_restore (dbg->bp, false); } // Add a checkpoint at stops if (dbg->session && !dbg->trace_continue) { dbg->session->cnum++; dbg->session->maxcnum++; - r_debug_add_checkpoint (dbg); + rz_debug_add_checkpoint (dbg); } return ret; } -R_API int r_debug_continue(RDebug *dbg) { - return r_debug_continue_kill (dbg, 0); //dbg->reason.signum); +RZ_API int rz_debug_continue(RzDebug *dbg) { + return rz_debug_continue_kill (dbg, 0); //dbg->reason.signum); } #if __WINDOWS__ -R_API int r_debug_continue_pass_exception(RDebug *dbg) { - return r_debug_continue_kill (dbg, DBG_EXCEPTION_NOT_HANDLED); +RZ_API int rz_debug_continue_pass_exception(RzDebug *dbg) { + return rz_debug_continue_kill (dbg, DBG_EXCEPTION_NOT_HANDLED); } #endif -R_API int r_debug_continue_until_nontraced(RDebug *dbg) { +RZ_API int rz_debug_continue_until_nontraced(RzDebug *dbg) { eprintf ("TODO\n"); return false; } -R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) { +RZ_API int rz_debug_continue_until_optype(RzDebug *dbg, int type, int over) { int ret, n = 0; ut64 pc, buf_pc = 0; - RAnalOp op; + RzAnalOp op; ut8 buf[DBG_BUF_SIZE]; - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return false; } @@ -1346,27 +1346,27 @@ R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) { return false; } - r_debug_step (dbg, 1); - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + rz_debug_step (dbg, 1); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); // Initial refill - buf_pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + buf_pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); dbg->iob.read_at (dbg->iob.io, buf_pc, buf, sizeof (buf)); // step first, we don't want to check current optype for (;;) { - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { break; } - pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); // Try to keep the buffer full if (pc - buf_pc > sizeof (buf)) { buf_pc = pc; dbg->iob.read_at (dbg->iob.io, buf_pc, buf, sizeof (buf)); } // Analyze the opcode - if (!r_anal_op (dbg->anal, &op, pc, buf + (pc - buf_pc), sizeof (buf) - (pc - buf_pc), R_ANAL_OP_MASK_BASIC)) { + if (!rz_anal_op (dbg->anal, &op, pc, buf + (pc - buf_pc), sizeof (buf) - (pc - buf_pc), R_ANAL_OP_MASK_BASIC)) { eprintf ("Decode error at %"PFMT64x"\n", pc); return false; } @@ -1375,11 +1375,11 @@ R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) { } // Step over and repeat ret = over - ? r_debug_step_over (dbg, 1) - : r_debug_step (dbg, 1); + ? rz_debug_step_over (dbg, 1) + : rz_debug_step (dbg, 1); if (!ret) { - eprintf ("r_debug_step: failed\n"); + eprintf ("rz_debug_step: failed\n"); break; } n++; @@ -1388,62 +1388,62 @@ R_API int r_debug_continue_until_optype(RDebug *dbg, int type, int over) { return n; } -static int r_debug_continue_until_internal(RDebug *dbg, ut64 addr, bool block) { - if (r_debug_is_dead (dbg)) { +static int rz_debug_continue_until_internal(RzDebug *dbg, ut64 addr, bool block) { + if (rz_debug_is_dead (dbg)) { return false; } // Check if there was another breakpoint set at addr - bool has_bp = r_bp_get_in (dbg->bp, addr, R_BP_PROT_EXEC) != NULL; + bool has_bp = rz_bp_get_in (dbg->bp, addr, R_BP_PROT_EXEC) != NULL; if (!has_bp) { - r_bp_add_sw (dbg->bp, addr, dbg->bpsize, R_BP_PROT_EXEC); + rz_bp_add_sw (dbg->bp, addr, dbg->bpsize, R_BP_PROT_EXEC); } // Continue until the bp is reached dbg->reason.type = 0; for (;;) { - if (r_debug_is_dead (dbg) || dbg->reason.type) { + if (rz_debug_is_dead (dbg) || dbg->reason.type) { break; } - ut64 pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + ut64 pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); if (pc == addr) { break; } - if (block && r_bp_get_at (dbg->bp, pc)) { + if (block && rz_bp_get_at (dbg->bp, pc)) { break; } - r_debug_continue (dbg); + rz_debug_continue (dbg); } // Clean up if needed if (!has_bp) { - r_bp_del (dbg->bp, addr); + rz_bp_del (dbg->bp, addr); } return true; } -R_API int r_debug_continue_until(RDebug *dbg, ut64 addr) { - return r_debug_continue_until_internal (dbg, addr, true); +RZ_API int rz_debug_continue_until(RzDebug *dbg, ut64 addr) { + return rz_debug_continue_until_internal (dbg, addr, true); } -R_API int r_debug_continue_until_nonblock(RDebug *dbg, ut64 addr) { - return r_debug_continue_until_internal (dbg, addr, false); +RZ_API int rz_debug_continue_until_nonblock(RzDebug *dbg, ut64 addr) { + return rz_debug_continue_until_internal (dbg, addr, false); } -R_API bool r_debug_continue_back(RDebug *dbg) { +RZ_API bool rz_debug_continue_back(RzDebug *dbg) { int cnum; bool has_bp = false; - RRegItem *ripc = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); - RVector *vreg = ht_up_find (dbg->session->registers, ripc->offset | (ripc->arena << 16), NULL); + RzRegItem *ripc = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); + RzVector *vreg = ht_up_find (dbg->session->registers, ripc->offset | (ripc->arena << 16), NULL); if (!vreg) { eprintf ("Error: cannot find PC change vector"); return false; } - RDebugChangeReg *reg; - r_vector_foreach_prev (vreg, reg) { + RzDebugChangeReg *reg; + rz_vector_foreach_prev (vreg, reg) { if (reg->cnum >= dbg->session->cnum) { continue; } - has_bp = r_bp_get_in (dbg->bp, reg->data, R_BP_PROT_EXEC) != NULL; + has_bp = rz_bp_get_in (dbg->bp, reg->data, R_BP_PROT_EXEC) != NULL; if (has_bp) { cnum = reg->cnum; eprintf ("hit breakpoint at: 0x%" PFMT64x " cnum: %d\n", reg->data, reg->cnum); @@ -1452,23 +1452,23 @@ R_API bool r_debug_continue_back(RDebug *dbg) { } if (has_bp) { - r_debug_goto_cnum (dbg, cnum); + rz_debug_goto_cnum (dbg, cnum); } else { if (dbg->session->maxcnum > 0) { - r_debug_goto_cnum (dbg, 0); + rz_debug_goto_cnum (dbg, 0); } } return true; } -static int show_syscall(RDebug *dbg, const char *sysreg) { +static int show_syscall(RzDebug *dbg, const char *sysreg) { const char *sysname; char regname[32]; int reg, i, args; - RSyscallItem *si; - reg = (int)r_debug_reg_get (dbg, sysreg); - si = r_syscall_get (dbg->anal->syscall, reg, -1); + RzSyscallItem *si; + reg = (int)rz_debug_reg_get (dbg, sysreg); + si = rz_syscall_get (dbg->anal->syscall, reg, -1); if (si) { sysname = si->name? si->name: "unknown"; args = si->args; @@ -1477,11 +1477,11 @@ static int show_syscall(RDebug *dbg, const char *sysreg) { args = 3; } eprintf ("--> %s 0x%08"PFMT64x" syscall %d %s (", sysreg, - r_debug_reg_get (dbg, "PC"), reg, sysname); + rz_debug_reg_get (dbg, "PC"), reg, sysname); for (i=0; i-0xffff)) { eprintf ("%"PFMT64d"%s", val, (i+1==args)?"":" "); } else { @@ -1489,34 +1489,34 @@ static int show_syscall(RDebug *dbg, const char *sysreg) { } } eprintf (")\n"); - r_syscall_item_free (si); + rz_syscall_item_free (si); return reg; } -R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) { +RZ_API int rz_debug_continue_syscalls(RzDebug *dbg, int *sc, int n_sc) { int i, err, reg, ret = false; - if (!dbg || !dbg->h || r_debug_is_dead (dbg)) { + if (!dbg || !dbg->h || rz_debug_is_dead (dbg)) { return false; } if (!dbg->h->contsc) { /* user-level syscall tracing */ - r_debug_continue_until_optype (dbg, R_ANAL_OP_TYPE_SWI, 0); + rz_debug_continue_until_optype (dbg, R_ANAL_OP_TYPE_SWI, 0); return show_syscall (dbg, "A0"); } - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { eprintf ("--> cannot read registers\n"); return -1; } - reg = (int)r_debug_reg_get_err (dbg, "SN", &err, NULL); + reg = (int)rz_debug_reg_get_err (dbg, "SN", &err, NULL); if (err) { eprintf ("Cannot find 'sn' register for current arch-os.\n"); return -1; } for (;;) { - RDebugReasonType reason; + RzDebugReasonType reason; - if (r_cons_singleton ()->context->breaked) { + if (rz_cons_singleton ()->context->breaked) { break; } #if __linux__ @@ -1524,12 +1524,12 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) { /* XXX(jjd): actually one stop is before the syscall, the other is * after. this allows you to inspect the arguments before and the * return value after... */ - r_debug_step (dbg, 1); + rz_debug_step (dbg, 1); #endif dbg->h->contsc (dbg, dbg->pid, 0); // TODO handle return value // wait until continuation - reason = r_debug_wait (dbg, NULL); - if (reason == R_DEBUG_REASON_DEAD || r_debug_is_dead (dbg)) { + reason = rz_debug_wait (dbg, NULL); + if (reason == R_DEBUG_REASON_DEAD || rz_debug_is_dead (dbg)) { break; } #if 0 @@ -1538,7 +1538,7 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) { break; } #endif - if (!r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { + if (!rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false)) { eprintf ("--> cannot sync regs, process is probably dead\n"); return -1; } @@ -1559,28 +1559,28 @@ R_API int r_debug_continue_syscalls(RDebug *dbg, int *sc, int n_sc) { return reg; } } - // TODO: must use r_core_cmd(as)..import code from rcore + // TODO: must use rz_core_cmd(as)..import code from rcore } return ret; } -R_API int r_debug_continue_syscall(RDebug *dbg, int sc) { - return r_debug_continue_syscalls (dbg, &sc, 1); +RZ_API int rz_debug_continue_syscall(RzDebug *dbg, int sc) { + return rz_debug_continue_syscalls (dbg, &sc, 1); } // TODO: remove from here? this is code injection! -R_API int r_debug_syscall(RDebug *dbg, int num) { +RZ_API int rz_debug_syscall(RzDebug *dbg, int num) { bool ret = true; if (dbg->h->contsc) { ret = dbg->h->contsc (dbg, dbg->pid, num); } eprintf ("TODO: show syscall information\n"); - /* r2rc task? ala inject? */ + /* rz_testc task? ala inject? */ return (int)ret; } -R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig) { - if (r_debug_is_dead (dbg)) { +RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig) { + if (rz_debug_is_dead (dbg)) { return false; } if (dbg->h && dbg->h->kill) { @@ -1593,7 +1593,7 @@ R_API int r_debug_kill(RDebug *dbg, int pid, int tid, int sig) { return false; } -R_API RList *r_debug_frames(RDebug *dbg, ut64 at) { +RZ_API RzList *rz_debug_frames(RzDebug *dbg, ut64 at) { if (dbg && dbg->h && dbg->h->frames) { return dbg->h->frames (dbg, at); } @@ -1601,19 +1601,19 @@ R_API RList *r_debug_frames(RDebug *dbg, ut64 at) { } /* TODO: Implement fork and clone */ -R_API int r_debug_child_fork(RDebug *dbg) { +RZ_API int rz_debug_child_fork(RzDebug *dbg) { //if (dbg && dbg->h && dbg->h->frames) //return dbg->h->frames (dbg); return 0; } -R_API int r_debug_child_clone(RDebug *dbg) { +RZ_API int rz_debug_child_clone(RzDebug *dbg) { //if (dbg && dbg->h && dbg->h->frames) //return dbg->h->frames (dbg); return 0; } -R_API bool r_debug_is_dead(RDebug *dbg) { +RZ_API bool rz_debug_is_dead(RzDebug *dbg) { if (!dbg->h) { return false; } @@ -1636,34 +1636,34 @@ R_API bool r_debug_is_dead(RDebug *dbg) { return is_dead; } -R_API int r_debug_map_protect(RDebug *dbg, ut64 addr, int size, int perms) { +RZ_API int rz_debug_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { if (dbg && dbg->h && dbg->h->map_protect) { return dbg->h->map_protect (dbg, addr, size, perms); } return false; } -R_API void r_debug_drx_list(RDebug *dbg) { +RZ_API void rz_debug_drx_list(RzDebug *dbg) { if (dbg && dbg->h && dbg->h->drx) { dbg->h->drx (dbg, 0, 0, 0, 0, 0, DRX_API_LIST); } } -R_API int r_debug_drx_set(RDebug *dbg, int idx, ut64 addr, int len, int rwx, int g) { +RZ_API int rz_debug_drx_set(RzDebug *dbg, int idx, ut64 addr, int len, int rwx, int g) { if (dbg && dbg->h && dbg->h->drx) { return dbg->h->drx (dbg, idx, addr, len, rwx, g, DRX_API_SET_BP); } return false; } -R_API int r_debug_drx_unset(RDebug *dbg, int idx) { +RZ_API int rz_debug_drx_unset(RzDebug *dbg, int idx) { if (dbg && dbg->h && dbg->h->drx) { return dbg->h->drx (dbg, idx, 0, -1, 0, 0, DRX_API_REMOVE_BP); } return false; } -R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) { +RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file) { if (!dbg || !dbg->iob.io || !dbg->iob.io->desc) { return 0LL; } @@ -1671,36 +1671,36 @@ R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) { // Tell gdb that we want baddr, not full mem map dbg->iob.system (dbg->iob.io, "baddr"); } - int pid = r_io_desc_get_pid (dbg->iob.io->desc); - int tid = r_io_desc_get_tid (dbg->iob.io->desc); + int pid = rz_io_desc_get_pid (dbg->iob.io->desc); + int tid = rz_io_desc_get_tid (dbg->iob.io->desc); if (pid < 0 || tid < 0) { return 0LL; } - if (r_debug_attach (dbg, pid) == -1) { + if (rz_debug_attach (dbg, pid) == -1) { return 0LL; } #if __WINDOWS__ ut64 base; - bool ret = r_io_desc_get_base (dbg->iob.io->desc, &base); + bool ret = rz_io_desc_get_base (dbg->iob.io->desc, &base); if (ret) { return base; } #endif - RListIter *iter; - RDebugMap *map; - r_debug_select (dbg, pid, tid); - r_debug_map_sync (dbg); - char *abspath = r_sys_pid_to_path (pid); + RzListIter *iter; + RzDebugMap *map; + rz_debug_select (dbg, pid, tid); + rz_debug_map_sync (dbg); + char *abspath = rz_sys_pid_to_path (pid); #if !__WINDOWS__ if (!abspath) { - abspath = r_file_abspath (file); + abspath = rz_file_abspath (file); } #endif if (!abspath) { abspath = strdup (file); } if (abspath) { - r_list_foreach (dbg->maps, iter, map) { + rz_list_foreach (dbg->maps, iter, map) { if (!strcmp (abspath, map->name)) { free (abspath); return map->addr; @@ -1710,7 +1710,7 @@ R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) { } // fallback resolution (osx/w32?) // we assume maps to be loaded in order, so lower addresses come first - r_list_foreach (dbg->maps, iter, map) { + rz_list_foreach (dbg->maps, iter, map) { if (map->perm == 5) { // r-x return map->addr; } @@ -1718,15 +1718,15 @@ R_API ut64 r_debug_get_baddr(RDebug *dbg, const char *file) { return 0LL; } -R_API void r_debug_bp_rebase(RDebug *dbg, ut64 old_base, ut64 new_base) { +RZ_API void rz_debug_bp_rebase(RzDebug *dbg, ut64 old_base, ut64 new_base) { RBreakpointItem *bp; - RListIter *iter; + RzListIter *iter; ut64 diff = new_base - old_base; // update bp->baddr dbg->bp->baddr = new_base; // update bp's address - r_list_foreach (dbg->bp->bps, iter, bp) { + rz_list_foreach (dbg->bp->bps, iter, bp) { bp->addr += diff; bp->delta = bp->addr - dbg->bp->baddr; } diff --git a/libr/debug/desil.c b/librz/debug/desil.c similarity index 60% rename from libr/debug/desil.c rename to librz/debug/desil.c index ada5643de2..885f494d24 100644 --- a/libr/debug/desil.c +++ b/librz/debug/desil.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2015 - pancake */ -#include +#include #if 0 /* debugesil performs step into + esil conditionals */ @@ -26,15 +26,15 @@ typedef struct { } EsilBreak; // TODO: Kill those globals -RDebug *dbg = NULL; +RzDebug *dbg = NULL; static int has_match = 0; static int prestep = 1; // TODO: make it configurable static ut64 opc = 0; -RList *esil_watchpoints = NULL; +RzList *esil_watchpoints = NULL; #define EWPS esil_watchpoints #define ESIL dbg->anal->esil -static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) { +static int exprmatch (RzDebug *dbg, ut64 addr, const char *expr) { char *e = strdup (expr); if (!e) { return 0; @@ -45,8 +45,8 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) { if (p) { *p = 0; p += 2; - a = r_num_math (dbg->num, e); - b = r_num_math (dbg->num, p); + a = rz_num_math (dbg->num, e); + b = rz_num_math (dbg->num, p); if (a= a && addr <= b) { ret = 1; @@ -57,7 +57,7 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) { } } } else { - a = r_num_math (dbg->num, e); + a = rz_num_math (dbg->num, e); if (addr == a) { ret = 1; } @@ -67,13 +67,13 @@ static int exprmatch (RDebug *dbg, ut64 addr, const char *expr) { return ret; } -static int esilbreak_check_pc (RDebug *dbg, ut64 pc) { +static int esilbreak_check_pc (RzDebug *dbg, ut64 pc) { EsilBreak *ew; - RListIter *iter; + RzListIter *iter; if (!pc) { - pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); } - r_list_foreach (EWPS, iter, ew) { + rz_list_foreach (EWPS, iter, ew) { if (ew->rwx & R_PERM_X) { if (exprmatch (dbg, pc, ew->expr)) { return 1; @@ -83,11 +83,11 @@ static int esilbreak_check_pc (RDebug *dbg, ut64 pc) { return 0; } -static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { +static int esilbreak_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len) { EsilBreak *ew; - RListIter *iter; + RzListIter *iter; eprintf (Color_GREEN"MEM READ 0x%"PFMT64x"\n"Color_RESET, addr); - r_list_foreach (EWPS, iter, ew) { + rz_list_foreach (EWPS, iter, ew) { if (ew->rwx & R_PERM_R && ew->dev == 'm') { if (exprmatch (dbg, addr, ew->expr)) { has_match = 1; @@ -98,11 +98,11 @@ static int esilbreak_mem_read(RAnalEsil *esil, ut64 addr, ut8 *buf, int len) { return 0; // fallback } -static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { +static int esilbreak_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len) { EsilBreak *ew; - RListIter *iter; + RzListIter *iter; eprintf (Color_RED"MEM WRTE 0x%"PFMT64x"\n"Color_RESET, addr); - r_list_foreach (EWPS, iter, ew) { + rz_list_foreach (EWPS, iter, ew) { if (ew->rwx & R_PERM_W && ew->dev == 'm') { if (exprmatch (dbg, addr, ew->expr)) { has_match = 1; @@ -113,15 +113,15 @@ static int esilbreak_mem_write(RAnalEsil *esil, ut64 addr, const ut8 *buf, int l return 1; // fallback } -static int esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, int *size) { +static int esilbreak_reg_read(RzAnalEsil *esil, const char *regname, ut64 *num, int *size) { EsilBreak *ew; - RListIter *iter; + RzListIter *iter; if (regname[0]>='0' && regname[0]<='9') { //eprintf (Color_CYAN"IMM READ %s\n"Color_RESET, regname); return 0; } eprintf (Color_YELLOW"REG READ %s\n"Color_RESET, regname); - r_list_foreach (EWPS, iter, ew) { + rz_list_foreach (EWPS, iter, ew) { if (ew->rwx & R_PERM_R && ew->dev == 'r') { // XXX: support array of regs in expr if (!strcmp (regname, ew->expr)) { @@ -133,7 +133,7 @@ static int esilbreak_reg_read(RAnalEsil *esil, const char *regname, ut64 *num, i return 0; // fallback } -static int exprtoken(RDebug *dbg, char *s, const char *sep, char **o) { +static int exprtoken(RzDebug *dbg, char *s, const char *sep, char **o) { char *p = strstr (s, sep); if (p) { *p = 0; @@ -145,7 +145,7 @@ static int exprtoken(RDebug *dbg, char *s, const char *sep, char **o) { return 0; } -static int exprmatchreg (RDebug *dbg, const char *regname, const char *expr) { +static int exprmatchreg (RzDebug *dbg, const char *regname, const char *expr) { int ret = 0; char *p; char *s = strdup (expr); @@ -155,27 +155,27 @@ static int exprmatchreg (RDebug *dbg, const char *regname, const char *expr) { if (!strcmp (regname, s)) { ret = 1; } else { -#define CURVAL 0){}r_str_trim (s);if (!strcmp(regname,s) && regval - ut64 regval = r_debug_reg_get_err (dbg, regname, NULL, NULL); +#define CURVAL 0){}rz_str_trim (s);if (!strcmp(regname,s) && regval + ut64 regval = rz_debug_reg_get_err (dbg, regname, NULL, NULL); if (exprtoken (dbg, s, ">=", &p)) { - if (CURVAL >= r_num_math (dbg->num, p)) + if (CURVAL >= rz_num_math (dbg->num, p)) ret = 1; } else if (exprtoken (dbg, s, "<=", &p)) { - if (CURVAL <= r_num_math (dbg->num, p)) + if (CURVAL <= rz_num_math (dbg->num, p)) ret = 1; } else if (exprtoken (dbg, s, "==", &p)) { - if (CURVAL <= r_num_math (dbg->num, p)) + if (CURVAL <= rz_num_math (dbg->num, p)) ret = 1; } else if (exprtoken (dbg, s, "<", &p)) { - if (CURVAL < r_num_math (dbg->num, p)) + if (CURVAL < rz_num_math (dbg->num, p)) ret = 1; } else if (exprtoken (dbg, s, ">", &p)) { - if (CURVAL > r_num_math (dbg->num, p)) + if (CURVAL > rz_num_math (dbg->num, p)) ret = 1; } else if (exprtoken (dbg, s, " ", &p)) { - r_str_trim (s); + rz_str_trim (s); if (!strcmp (regname, s)) { - ut64 num = r_num_math (dbg->num, p); + ut64 num = rz_num_math (dbg->num, p); ret = exprmatch (dbg, num, s); } } else { @@ -188,16 +188,16 @@ static int exprmatchreg (RDebug *dbg, const char *regname, const char *expr) { return ret; } -static int esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num) { +static int esilbreak_reg_write(RzAnalEsil *esil, const char *regname, ut64 *num) { EsilBreak *ew; - RListIter *iter; + RzListIter *iter; if (regname[0] >= '0' && regname[0] <= '9') { // wtf this should never happen //eprintf (Color_BLUE"IMM WRTE %s\n"Color_RESET, regname); return 0; } eprintf (Color_MAGENTA"REG WRTE %s 0x%"PFMT64x"\n"Color_RESET, regname, *num); - r_list_foreach (EWPS, iter, ew) { + rz_list_foreach (EWPS, iter, ew) { if ((ew->rwx & R_PERM_W) && (ew->dev == 'r')) { // XXX: support array of regs in expr if (exprmatchreg (dbg, regname, ew->expr)) { @@ -209,25 +209,25 @@ static int esilbreak_reg_write(RAnalEsil *esil, const char *regname, ut64 *num) return 1; // fallback } -R_API void r_debug_esil_prestep (RDebug *d, int p) { +RZ_API void rz_debug_esil_prestep (RzDebug *d, int p) { prestep = p; } -R_API int r_debug_esil_stepi (RDebug *d) { - RAnalOp op; +RZ_API int rz_debug_esil_stepi (RzDebug *d) { + RzAnalOp op; ut8 obuf[64]; int ret = 1; dbg = d; if (!ESIL) { - ESIL = r_anal_esil_new (32, true, 64); + ESIL = rz_anal_esil_new (32, true, 64); // TODO setup something? if (!ESIL) { return 0; } } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - opc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + opc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); dbg->iob.read_at (dbg->iob.io, opc, obuf, sizeof (obuf)); //dbg->iob.read_at (dbg->iob.io, npc, buf, sizeof (buf)); @@ -241,46 +241,46 @@ R_API int r_debug_esil_stepi (RDebug *d) { if (prestep) { // required when a exxpression is like <= == .. // otherwise it will stop at the next instruction - if (r_debug_step (dbg, 1)<1) { + if (rz_debug_step (dbg, 1)<1) { eprintf ("Step failed\n"); return 0; } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - // npc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + // npc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); } - if (r_anal_op (dbg->anal, &op, opc, obuf, sizeof (obuf), R_ANAL_OP_MASK_ESIL)) { + if (rz_anal_op (dbg->anal, &op, opc, obuf, sizeof (obuf), R_ANAL_OP_MASK_ESIL)) { if (esilbreak_check_pc (dbg, opc)) { eprintf ("STOP AT 0x%08"PFMT64x"\n", opc); ret = 0; } else { - r_anal_esil_set_pc (ESIL, opc); + rz_anal_esil_set_pc (ESIL, opc); eprintf ("0x%08"PFMT64x" %s\n", opc, R_STRBUF_SAFEGET (&op.esil)); - (void)r_anal_esil_parse (ESIL, R_STRBUF_SAFEGET (&op.esil)); - //r_anal_esil_dumpstack (ESIL); - r_anal_esil_stack_free (ESIL); + (void)rz_anal_esil_parse (ESIL, R_STRBUF_SAFEGET (&op.esil)); + //rz_anal_esil_dumpstack (ESIL); + rz_anal_esil_stack_free (ESIL); ret = 1; } } if (!prestep) { if (ret && !has_match) { - if (r_debug_step (dbg, 1)<1) { + if (rz_debug_step (dbg, 1)<1) { eprintf ("Step failed\n"); return 0; } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - // npc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + // npc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); } } return ret; } -R_API ut64 r_debug_esil_step(RDebug *dbg, ut32 count) { +RZ_API ut64 rz_debug_esil_step(RzDebug *dbg, ut32 count) { count++; has_match = 0; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } if (has_match) { @@ -294,13 +294,13 @@ R_API ut64 r_debug_esil_step(RDebug *dbg, ut32 count) { break; } } - } while (r_debug_esil_stepi (dbg)); - r_cons_break_pop (); + } while (rz_debug_esil_stepi (dbg)); + rz_cons_break_pop (); return opc; } -R_API ut64 r_debug_esil_continue (RDebug *dbg) { - return r_debug_esil_step (dbg, UT32_MAX); +RZ_API ut64 rz_debug_esil_continue (RzDebug *dbg) { + return rz_debug_esil_step (dbg, UT32_MAX); } static void ewps_free(EsilBreak *ew) { @@ -308,17 +308,17 @@ static void ewps_free(EsilBreak *ew) { free (ew); } -R_API int r_debug_esil_watch_empty(RDebug *dbg) { - return r_list_empty (EWPS); +RZ_API int rz_debug_esil_watch_empty(RzDebug *dbg) { + return rz_list_empty (EWPS); } -R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr) { +RZ_API void rz_debug_esil_watch(RzDebug *dbg, int rwx, int dev, const char *expr) { if (!EWPS) { - EWPS = r_list_new (); + EWPS = rz_list_new (); if (!EWPS) { return; } - EWPS->free = (RListFree)ewps_free; + EWPS->free = (RzListFree)ewps_free; } EsilBreak *ew = R_NEW0 (EsilBreak); if (!ew) { @@ -328,18 +328,18 @@ R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr) { ew->rwx = rwx; ew->dev = dev; ew->expr = strdup (expr); - r_list_append (EWPS, ew); + rz_list_append (EWPS, ew); } -R_API void r_debug_esil_watch_reset(RDebug *dbg) { - r_list_free (EWPS); +RZ_API void rz_debug_esil_watch_reset(RzDebug *dbg) { + rz_list_free (EWPS); EWPS = NULL; } -R_API void r_debug_esil_watch_list(RDebug *dbg) { +RZ_API void rz_debug_esil_watch_list(RzDebug *dbg) { EsilBreak *ew; - RListIter *iter; - r_list_foreach (EWPS, iter, ew) { - dbg->cb_printf ("de %s %c %s\n", r_str_rwx_i (ew->rwx), ew->dev, ew->expr); + RzListIter *iter; + rz_list_foreach (EWPS, iter, ew) { + dbg->cb_printf ("de %s %c %s\n", rz_str_rwx_i (ew->rwx), ew->dev, ew->expr); } } diff --git a/libr/debug/dmap.c b/librz/debug/dmap.c similarity index 71% rename from libr/debug/dmap.c rename to librz/debug/dmap.c index 044ccae75b..815e74b8fd 100644 --- a/libr/debug/dmap.c +++ b/librz/debug/dmap.c @@ -1,47 +1,47 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include -#include +#include +#include /* Print out the JSON body for memory maps in the passed map region */ -static void print_debug_map_json(RDebug *dbg, RDebugMap *map, bool prefix_comma) { +static void print_debug_map_json(RzDebug *dbg, RzDebugMap *map, bool prefix_comma) { dbg->cb_printf ("%s{", prefix_comma ? ",": ""); if (map->name && *map->name) { - char *escaped_name = r_str_escape (map->name); + char *escaped_name = rz_str_escape (map->name); dbg->cb_printf ("\"name\":\"%s\",", escaped_name); free (escaped_name); } if (map->file && *map->file) { - char *escaped_path = r_str_escape (map->file); + char *escaped_path = rz_str_escape (map->file); dbg->cb_printf ("\"file\":\"%s\",", escaped_path); free (escaped_path); } dbg->cb_printf ("\"addr\":%" PFMT64u ",", map->addr); dbg->cb_printf ("\"addr_end\":%" PFMT64u ",", map->addr_end); dbg->cb_printf ("\"type\":\"%c\",", map->user?'u':'s'); - dbg->cb_printf ("\"perm\":\"%s\"", r_str_rwx_i (map->perm)); + dbg->cb_printf ("\"perm\":\"%s\"", rz_str_rwx_i (map->perm)); dbg->cb_printf ("}"); } /* Write the memory map header describing the line columns */ -static void print_debug_map_line_header(RDebug *dbg, const char *input) { +static void print_debug_map_line_header(RzDebug *dbg, const char *input) { // TODO: Write header to console based on which command is being ran } /* Write a single memory map line to the console */ -static void print_debug_map_line(RDebug *dbg, RDebugMap *map, ut64 addr, const char *input) { +static void print_debug_map_line(RzDebug *dbg, RzDebugMap *map, ut64 addr, const char *input) { char humansz[8]; if (input[0] == 'q') { // "dmq" char *name = (map->name && *map->name) - ? r_str_newf ("%s.%s", map->name, r_str_rwx_i (map->perm)) - : r_str_newf ("%08" PFMT64x ".%s", map->addr, r_str_rwx_i (map->perm)); - r_name_filter (name, 0); - r_num_units (humansz, sizeof (humansz), map->addr_end - map->addr); + ? rz_str_newf ("%s.%s", map->name, rz_str_rwx_i (map->perm)) + : rz_str_newf ("%08" PFMT64x ".%s", map->addr, rz_str_rwx_i (map->perm)); + rz_name_filter (name, 0); + rz_num_units (humansz, sizeof (humansz), map->addr_end - map->addr); dbg->cb_printf ("0x%016" PFMT64x " - 0x%016" PFMT64x " %6s %5s %s\n", map->addr, map->addr_end, humansz, - r_str_rwx_i (map->perm), + rz_str_rwx_i (map->perm), name ); free (name); @@ -56,14 +56,14 @@ static void print_debug_map_line(RDebug *dbg, RDebugMap *map, ut64 addr, const c flagname = ""; } else if (map->name) { char *filtered_name = strdup (map->name); - r_name_filter (filtered_name, 0); + rz_name_filter (filtered_name, 0); if (!strncmp (flagname, "map.", 4) && \ !strcmp (flagname + 4, filtered_name)) { flagname = ""; } free (filtered_name); } - r_num_units (humansz, sizeof (humansz), map->size); + rz_num_units (humansz, sizeof (humansz), map->size); dbg->cb_printf (fmtstr, map->addr, map->addr_end, @@ -71,7 +71,7 @@ static void print_debug_map_line(RDebug *dbg, RDebugMap *map, ut64 addr, const c type, humansz, map->user ? 'u' : 's', - r_str_rwx_i (map->perm), + rz_str_rwx_i (map->perm), map->name ? map->name : "?", map->file ? map->file : "?", *flagname ? " ; " : "", @@ -80,11 +80,11 @@ static void print_debug_map_line(RDebug *dbg, RDebugMap *map, ut64 addr, const c } } -R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input) { +RZ_API void rz_debug_map_list(RzDebug *dbg, ut64 addr, const char *input) { int i; bool notfirst = false; - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; if (!dbg) { return; } @@ -101,8 +101,8 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input) { } for (i = 0; i < 2; i++) { // Iterate over dbg::maps and dbg::maps_user - RList *maps = (i == 0) ? dbg->maps : dbg->maps_user; - r_list_foreach (maps, iter, map) { + RzList *maps = (i == 0) ? dbg->maps : dbg->maps_user; + rz_list_foreach (maps, iter, map) { switch (input[0]) { case 'j': // "dmj" print_debug_map_json (dbg, map, notfirst); @@ -111,9 +111,9 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input) { case '*': // "dm*" { char *name = (map->name && *map->name) - ? r_str_newf ("%s.%s", map->name, r_str_rwx_i (map->perm)) - : r_str_newf ("%08" PFMT64x ".%s", map->addr, r_str_rwx_i (map->perm)); - r_name_filter (name, 0); + ? rz_str_newf ("%s.%s", map->name, rz_str_rwx_i (map->perm)) + : rz_str_newf ("%08" PFMT64x ".%s", map->addr, rz_str_rwx_i (map->perm)); + rz_name_filter (name, 0); dbg->cb_printf ("f map.%s 0x%08" PFMT64x " 0x%08" PFMT64x "\n", name, map->addr_end - map->addr + 1, map->addr); free (name); @@ -146,14 +146,14 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, const char *input) { } static int cmp(const void *a, const void *b) { - RDebugMap *ma = (RDebugMap*) a; - RDebugMap *mb = (RDebugMap*) b; + RzDebugMap *ma = (RzDebugMap*) a; + RzDebugMap *mb = (RzDebugMap*) b; return ma->addr - mb->addr; } /** - * \brief Find the min and max addresses in an RList of maps. - * \param maps RList of maps that will be searched through + * \brief Find the min and max addresses in an RzList of maps. + * \param maps RzList of maps that will be searched through * \param min Pointer to a ut64 that the min will be stored in * \param max Pointer to a ut64 that the max will be stored in * \param skip How many maps to skip at the start of iteration @@ -163,12 +163,12 @@ static int cmp(const void *a, const void *b) { * Used to determine the min & max addresses of maps and * scale the ascii bar to the width of the terminal */ -static int findMinMax(RList *maps, ut64 *min, ut64 *max, int skip, int width) { - RDebugMap *map; - RListIter *iter; +static int findMinMax(RzList *maps, ut64 *min, ut64 *max, int skip, int width) { + RzDebugMap *map; + RzListIter *iter; *min = UT64_MAX; *max = 0; - r_list_foreach (maps, iter, map) { + rz_list_foreach (maps, iter, map) { if (skip > 0) { skip--; continue; @@ -183,17 +183,17 @@ static int findMinMax(RList *maps, ut64 *min, ut64 *max, int skip, int width) { return (*max - *min) / width; } -static void print_debug_maps_ascii_art(RDebug *dbg, RList *maps, ut64 addr, int colors) { +static void print_debug_maps_ascii_art(RzDebug *dbg, RzList *maps, ut64 addr, int colors) { ut64 mul; // The amount of address space a single console column will represent in bar graph ut64 min = -1, max = 0; - int width = r_cons_get_size (NULL) - 90; - RListIter *iter; - RDebugMap *map; - RConsPrintablePalette *pal = &r_cons_singleton ()->context->pal; + int width = rz_cons_get_size (NULL) - 90; + RzListIter *iter; + RzDebugMap *map; + RzConsPrintablePalette *pal = &rz_cons_singleton ()->context->pal; if (width < 1) { width = 30; } - r_list_sort (maps, cmp); + rz_list_sort (maps, cmp); mul = findMinMax (maps, &min, &max, 0, width); ut64 last = min; if (min != -1 && mul != 0) { @@ -202,8 +202,8 @@ static void print_debug_maps_ascii_art(RDebug *dbg, RList *maps, ut64 addr, int const char *fmtstr; char humansz[8]; // Holds the human formatted size string [124K] int skip = 0; // Number of maps to skip when re-calculating the minmax - r_list_foreach (maps, iter, map) { - r_num_units (humansz, sizeof (humansz), map->size); // Convert map size to human readable string + rz_list_foreach (maps, iter, map) { + rz_num_units (humansz, sizeof (humansz), map->size); // Convert map size to human readable string if (colors) { color_suffix = Color_RESET; if ((map->perm & 2) && (map->perm & 1)) { // Writable & Executable @@ -245,23 +245,23 @@ static void print_debug_maps_ascii_art(RDebug *dbg, RList *maps, ut64 addr, int "| %s0x%016" PFMT64x "%s %s %s\n" : "| %s0x%08" PFMT64x "%s %s %s\n"; dbg->cb_printf (fmtstr, color_prefix, map->addr_end, color_suffix, - r_str_rwx_i (map->perm), map->name); + rz_str_rwx_i (map->perm), map->name); last = map->addr; } } } -R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, const char *input, int colors) { +RZ_API void rz_debug_map_list_visual(RzDebug *dbg, ut64 addr, const char *input, int colors) { if (dbg) { int i; for (i = 0; i < 2; i++) { // Iterate over dbg::maps and dbg::maps_user - RList *maps = (i == 0) ? dbg->maps : dbg->maps_user; + RzList *maps = (i == 0) ? dbg->maps : dbg->maps_user; if (maps) { - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; if (input[1] == '.') { // "dm=." Only show map overlapping current offset dbg->cb_printf ("TODO:\n"); - r_list_foreach (maps, iter, map) { + rz_list_foreach (maps, iter, map) { if (addr >= map->addr && addr < map->addr_end) { // print_debug_map_ascii_art (dbg, map); } @@ -274,15 +274,15 @@ R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, const char *input, in } } -R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user) { - RDebugMap *map; +RZ_API RzDebugMap *rz_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user) { + RzDebugMap *map; /* range could be 0k on OpenBSD, it's a honeypot */ if (!name || addr > addr_end) { - eprintf ("r_debug_map_new: error (\ + eprintf ("rz_debug_map_new: error (\ %" PFMT64x ">%" PFMT64x ")\n", addr, addr_end); return NULL; } - map = R_NEW0 (RDebugMap); + map = R_NEW0 (RzDebugMap); if (!map) { return NULL; } @@ -295,17 +295,17 @@ R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, return map; } -R_API RList *r_debug_modules_list(RDebug *dbg) { +RZ_API RzList *rz_debug_modules_list(RzDebug *dbg) { return (dbg && dbg->h && dbg->h->modules_get)? dbg->h->modules_get (dbg): NULL; } -R_API bool r_debug_map_sync(RDebug *dbg) { +RZ_API bool rz_debug_map_sync(RzDebug *dbg) { bool ret = false; if (dbg && dbg->h && dbg->h->map_get) { - RList *newmaps = dbg->h->map_get (dbg); + RzList *newmaps = dbg->h->map_get (dbg); if (newmaps) { - r_list_free (dbg->maps); + rz_list_free (dbg->maps); dbg->maps = newmaps; ret = true; } @@ -313,15 +313,15 @@ R_API bool r_debug_map_sync(RDebug *dbg) { return ret; } -R_API RDebugMap* r_debug_map_alloc(RDebug *dbg, ut64 addr, int size, bool thp) { - RDebugMap *map = NULL; +RZ_API RzDebugMap* rz_debug_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp) { + RzDebugMap *map = NULL; if (dbg && dbg->h && dbg->h->map_alloc) { map = dbg->h->map_alloc (dbg, addr, size, thp); } return map; } -R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map) { +RZ_API int rz_debug_map_dealloc(RzDebug *dbg, RzDebugMap *map) { bool ret = false; ut64 addr = map->addr; if (dbg && dbg->h && dbg->h->map_dealloc) { @@ -332,10 +332,10 @@ R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map) { return (int)ret; } -R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr) { - RDebugMap *map, *ret = NULL; - RListIter *iter; - r_list_foreach (dbg->maps, iter, map) { +RZ_API RzDebugMap *rz_debug_map_get(RzDebug *dbg, ut64 addr) { + RzDebugMap *map, *ret = NULL; + RzListIter *iter; + rz_list_foreach (dbg->maps, iter, map) { if (addr >= map->addr && addr <= map->addr_end) { ret = map; break; @@ -344,17 +344,17 @@ R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr) { return ret; } -R_API void r_debug_map_free(RDebugMap *map) { +RZ_API void rz_debug_map_free(RzDebugMap *map) { free (map->name); free (map->file); free (map); } -R_API RList *r_debug_map_list_new(void) { - RList *list = r_list_new (); +RZ_API RzList *rz_debug_map_list_new(void) { + RzList *list = rz_list_new (); if (!list) { return NULL; } - list->free = (RListFree)r_debug_map_free; + list->free = (RzListFree)rz_debug_map_free; return list; } diff --git a/libr/debug/dreg.c b/librz/debug/dreg.c similarity index 78% rename from libr/debug/dreg.c rename to librz/debug/dreg.c index 31777ad245..ff08f3685d 100644 --- a/libr/debug/dreg.c +++ b/librz/debug/dreg.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include // just to get the RPrint instance -#include -#include -#include +#include // just to get the RPrint instance +#include +#include +#include -R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) { +RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write) { int i, n, size; if (!dbg || !dbg->reg || !dbg->h) { return false; } // There's no point in syncing a dead target - if (r_debug_is_dead (dbg)) { + if (rz_debug_is_dead (dbg)) { return false; } // Check if the functions needed are available @@ -44,10 +44,10 @@ R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) { } do { if (write) { - ut8 *buf = r_reg_get_bytes (dbg->reg, i, &size); + ut8 *buf = rz_reg_get_bytes (dbg->reg, i, &size); if (!buf || !dbg->h->reg_write (dbg, i, buf, size)) { if (i == R_REG_TYPE_GPR) { - eprintf ("r_debug_reg: error writing " + eprintf ("rz_debug_reg: error writing " "registers %d to %d\n", i, dbg->tid); } if (type != R_REG_TYPE_ALL || i == R_REG_TYPE_GPR) { @@ -69,7 +69,7 @@ R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) { size = dbg->h->reg_read (dbg, i, buf, bufsize); // we need to check against zero because reg_read can return false if (size > 0) { - r_reg_set_bytes (dbg->reg, i, buf, size); //R_MIN (size, bufsize)); + rz_reg_set_bytes (dbg->reg, i, buf, size); //R_MIN (size, bufsize)); // free (buf); // return true; } @@ -84,14 +84,14 @@ R_API int r_debug_reg_sync(RDebug *dbg, int type, int write) { return true; } -R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char *use_color) { +RZ_API bool rz_debug_reg_list(RzDebug *dbg, int type, int size, int rad, const char *use_color) { int delta, cols, n = 0; const char *fmt, *fmt2, *kwhites; RPrint *pr = NULL; int colwidth = 20; - RListIter *iter; - RRegItem *item; - RList *head; + RzListIter *iter; + RzRegItem *item; + RzList *head; ut64 diff; char strvalue[256]; bool isJson = (rad == 'j' || rad == 'J'); @@ -99,7 +99,7 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char return false; } if (dbg->corebind.core) { - pr = ((RCore*)dbg->corebind.core)->print; + pr = ((RzCore*)dbg->corebind.core)->print; } if (size != 0 && !(dbg->reg->bits & size)) { // TODO: verify if 32bit exists, otherwise use 64 or 8? @@ -138,11 +138,11 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char int itmidx = -1; dbg->creg = NULL; - head = r_reg_get_list (dbg->reg, type); + head = rz_reg_get_list (dbg->reg, type); if (!head) { return false; } - r_list_foreach (head, iter, item) { + rz_list_foreach (head, iter, item) { ut64 value; utX valueBig; if (type != -1) { @@ -155,12 +155,12 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char } // Is this register being asked? if (dbg->q_regs) { - if (!r_list_empty (dbg->q_regs)) { - RListIter *iterreg; - RList *q_reg = dbg->q_regs; + if (!rz_list_empty (dbg->q_regs)) { + RzListIter *iterreg; + RzList *q_reg = dbg->q_regs; char *q_name; bool found = false; - r_list_foreach (q_reg, iterreg, q_name) { + rz_list_foreach (q_reg, iterreg, q_name) { if (!strcmp (item->name, q_name)) { found = true; break; @@ -169,7 +169,7 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char if (!found) { continue; } - r_list_delete (q_reg, iterreg); + rz_list_delete (q_reg, iterreg); } else { // List is empty, all requested regs were taken, no need to go further goto beach; @@ -177,10 +177,10 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char } int regSize = item->size; if (regSize < 80) { - value = r_reg_get_value (dbg->reg, item); - r_reg_arena_swap (dbg->reg, false); - diff = r_reg_get_value (dbg->reg, item); - r_reg_arena_swap (dbg->reg, false); + value = rz_reg_get_value (dbg->reg, item); + rz_reg_arena_swap (dbg->reg, false); + diff = rz_reg_get_value (dbg->reg, item); + rz_reg_arena_swap (dbg->reg, false); delta = value - diff; if (isJson) { pj_kn (pj, item->name, value); @@ -192,7 +192,7 @@ R_API bool r_debug_reg_list(RDebug *dbg, int type, int size, int rad, const char } } } else { - value = r_reg_get_value_big (dbg->reg, item, &valueBig); + value = rz_reg_get_value_big (dbg->reg, item, &valueBig); switch (regSize) { case 80: snprintf (strvalue, sizeof (strvalue), "0x%04x%016"PFMT64x"", valueBig.v80.High, valueBig.v80.Low); @@ -299,32 +299,32 @@ beach: return n != 0; } -R_API int r_debug_reg_set(struct r_debug_t *dbg, const char *name, ut64 num) { - RRegItem *ri; - int role = r_reg_get_name_idx (name); +RZ_API int rz_debug_reg_set(struct rz_debug_t *dbg, const char *name, ut64 num) { + RzRegItem *ri; + int role = rz_reg_get_name_idx (name); if (!dbg || !dbg->reg) { return false; } if (role != -1) { - name = r_reg_get_name (dbg->reg, role); + name = rz_reg_get_name (dbg->reg, role); } - ri = r_reg_get (dbg->reg, name, R_REG_TYPE_ALL); + ri = rz_reg_get (dbg->reg, name, R_REG_TYPE_ALL); if (ri) { - r_reg_set_value (dbg->reg, ri, num); - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, true); + rz_reg_set_value (dbg->reg, ri, num); + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, true); } return (ri != NULL); } -R_API ut64 r_debug_reg_get(RDebug *dbg, const char *name) { +RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name) { // ignores errors - return r_debug_reg_get_err (dbg, name, NULL, NULL); + return rz_debug_reg_get_err (dbg, name, NULL, NULL); } -R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *value) { - RRegItem *ri = NULL; +RZ_API ut64 rz_debug_reg_get_err(RzDebug *dbg, const char *name, int *err, utX *value) { + RzRegItem *ri = NULL; ut64 ret = 0LL; - int role = r_reg_get_name_idx (name); + int role = rz_reg_get_name_idx (name); const char *pname = name; if (err) { *err = 0; @@ -336,7 +336,7 @@ R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *val return UT64_MAX; } if (role != -1) { - name = r_reg_get_name (dbg->reg, role); + name = rz_reg_get_name (dbg->reg, role); if (!name || *name == '\0') { eprintf ("No debug register profile defined for '%s'.\n", pname); if (err) { @@ -345,16 +345,16 @@ R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *val return UT64_MAX; } } - ri = r_reg_get (dbg->reg, name, R_REG_TYPE_ALL); + ri = rz_reg_get (dbg->reg, name, R_REG_TYPE_ALL); if (ri) { - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); if (value && ri->size > 64) { if (err) { *err = ri->size; } - ret = r_reg_get_value_big (dbg->reg, ri, value); + ret = rz_reg_get_value_big (dbg->reg, ri, value); } else { - ret = r_reg_get_value (dbg->reg, ri); + ret = rz_reg_get_value (dbg->reg, ri); } } else { if (err) { @@ -365,8 +365,8 @@ R_API ut64 r_debug_reg_get_err(RDebug *dbg, const char *name, int *err, utX *val } // XXX: dup for get_Err! -R_API ut64 r_debug_num_callback(RNum *userptr, const char *str, int *ok) { - RDebug *dbg = (RDebug *)userptr; +RZ_API ut64 rz_debug_num_callback(RNum *userptr, const char *str, int *ok) { + RzDebug *dbg = (RzDebug *)userptr; // resolve using regnu - return r_debug_reg_get_err (dbg, str, ok, NULL); + return rz_debug_reg_get_err (dbg, str, ok, NULL); } diff --git a/libr/debug/dsession.c b/librz/debug/dsession.c similarity index 59% rename from libr/debug/dsession.c rename to librz/debug/dsession.c index 1c4721a20c..0cb84736cb 100644 --- a/libr/debug/dsession.c +++ b/librz/debug/dsession.c @@ -1,152 +1,152 @@ /* radare - LGPL - Copyright 2017 - rkx1209 */ -#include -#include +#include +#include -#define CMP_CNUM_REG(x, y) ((x) >= ((RDebugChangeReg *)y)->cnum ? 1 : -1) -#define CMP_CNUM_MEM(x, y) ((x) >= ((RDebugChangeMem *)y)->cnum ? 1 : -1) -#define CMP_CNUM_CHKPT(x, y) ((x) >= ((RDebugCheckpoint *)y)->cnum ? 1 : -1) +#define CMP_CNUM_REG(x, y) ((x) >= ((RzDebugChangeReg *)y)->cnum ? 1 : -1) +#define CMP_CNUM_MEM(x, y) ((x) >= ((RzDebugChangeMem *)y)->cnum ? 1 : -1) +#define CMP_CNUM_CHKPT(x, y) ((x) >= ((RzDebugCheckpoint *)y)->cnum ? 1 : -1) -R_API void r_debug_session_free(RDebugSession *session) { +RZ_API void rz_debug_session_free(RzDebugSession *session) { if (session) { - r_vector_free (session->checkpoints); + rz_vector_free (session->checkpoints); ht_up_free (session->registers); ht_up_free (session->memory); R_FREE (session); } } -static void r_debug_checkpoint_fini(void *element, void *user) { - RDebugCheckpoint *checkpoint = element; +static void rz_debug_checkpoint_fini(void *element, void *user) { + RzDebugCheckpoint *checkpoint = element; size_t i; for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_reg_arena_free (checkpoint->arena[i]); + rz_reg_arena_free (checkpoint->arena[i]); } - r_list_free (checkpoint->snaps); + rz_list_free (checkpoint->snaps); } static void htup_vector_free(HtUPKv *kv) { - r_vector_free (kv->value); + rz_vector_free (kv->value); } -R_API RDebugSession *r_debug_session_new(void) { - RDebugSession *session = R_NEW0 (RDebugSession); +RZ_API RzDebugSession *rz_debug_session_new(void) { + RzDebugSession *session = R_NEW0 (RzDebugSession); if (!session) { return NULL; } - session->checkpoints = r_vector_new (sizeof (RDebugCheckpoint), r_debug_checkpoint_fini, NULL); + session->checkpoints = rz_vector_new (sizeof (RzDebugCheckpoint), rz_debug_checkpoint_fini, NULL); if (!session->checkpoints) { - r_debug_session_free (session); + rz_debug_session_free (session); return NULL; } session->registers = ht_up_new (NULL, htup_vector_free, NULL); if (!session->registers) { - r_debug_session_free (session); + rz_debug_session_free (session); return NULL; } session->memory = ht_up_new (NULL, htup_vector_free, NULL); if (!session->memory) { - r_debug_session_free (session); + rz_debug_session_free (session); return NULL; } return session; } -R_API bool r_debug_add_checkpoint(RDebug *dbg) { - r_return_val_if_fail (dbg->session, false); +RZ_API bool rz_debug_add_checkpoint(RzDebug *dbg) { + rz_return_val_if_fail (dbg->session, false); size_t i; - RDebugCheckpoint checkpoint = { 0 }; + RzDebugCheckpoint checkpoint = { 0 }; // Save current registers arena iter - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, 0); + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, 0); for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = dbg->reg->regset[i].arena; - RRegArena *b = r_reg_arena_new (a->size); + RzRegArena *a = dbg->reg->regset[i].arena; + RzRegArena *b = rz_reg_arena_new (a->size); memcpy (b->bytes, a->bytes, b->size); checkpoint.arena[i] = b; } // Save current memory maps - checkpoint.snaps = r_list_newf ((RListFree)r_debug_snap_free); + checkpoint.snaps = rz_list_newf ((RzListFree)rz_debug_snap_free); if (!checkpoint.snaps) { return false; } - RListIter *iter; - RDebugMap *map; - r_debug_map_sync (dbg); - r_list_foreach (dbg->maps, iter, map) { + RzListIter *iter; + RzDebugMap *map; + rz_debug_map_sync (dbg); + rz_list_foreach (dbg->maps, iter, map) { if ((map->perm & R_PERM_RW) == R_PERM_RW) { - RDebugSnap *snap = r_debug_snap_map (dbg, map); + RzDebugSnap *snap = rz_debug_snap_map (dbg, map); if (snap) { - r_list_append (checkpoint.snaps, snap); + rz_list_append (checkpoint.snaps, snap); } } } checkpoint.cnum = dbg->session->cnum; - r_vector_push (dbg->session->checkpoints, &checkpoint); + rz_vector_push (dbg->session->checkpoints, &checkpoint); // Add PC register change so we can check for breakpoints when continue [back] - RRegItem *ripc = r_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); - ut64 data = r_reg_get_value (dbg->reg, ripc); - r_debug_session_add_reg_change (dbg->session, ripc->arena, ripc->offset, data); + RzRegItem *ripc = rz_reg_get (dbg->reg, dbg->reg->name[R_REG_NAME_PC], R_REG_TYPE_GPR); + ut64 data = rz_reg_get_value (dbg->reg, ripc); + rz_debug_session_add_reg_change (dbg->session, ripc->arena, ripc->offset, data); return true; } -static void _set_initial_registers(RDebug *dbg) { +static void _set_initial_registers(RzDebug *dbg) { size_t i; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = dbg->session->cur_chkpt->arena[i]; - RRegArena *b = dbg->reg->regset[i].arena; + RzRegArena *a = dbg->session->cur_chkpt->arena[i]; + RzRegArena *b = dbg->reg->regset[i].arena; if (a && b && a->bytes && b->bytes) { memcpy (b->bytes, a->bytes, a->size); } } } -static void _set_register(RDebug *dbg, RRegItem *ri, ut32 cnum) { - RVector *vreg = ht_up_find (dbg->session->registers, ri->offset | (ri->arena << 16), NULL); +static void _set_register(RzDebug *dbg, RzRegItem *ri, ut32 cnum) { + RzVector *vreg = ht_up_find (dbg->session->registers, ri->offset | (ri->arena << 16), NULL); if (!vreg) { return; } size_t index; - r_vector_upper_bound (vreg, cnum, index, CMP_CNUM_REG); + rz_vector_upper_bound (vreg, cnum, index, CMP_CNUM_REG); if (index > 0 && index <= vreg->len) { - RDebugChangeReg *reg = r_vector_index_ptr (vreg, index - 1); + RzDebugChangeReg *reg = rz_vector_index_ptr (vreg, index - 1); if (reg->cnum > dbg->session->cur_chkpt->cnum) { - r_reg_set_value (dbg->reg, ri, reg->data); + rz_reg_set_value (dbg->reg, ri, reg->data); } } } -R_API void _restore_registers(RDebug *dbg, ut32 cnum) { - RListIter *iter; - RRegItem *ri; +RZ_API void _restore_registers(RzDebug *dbg, ut32 cnum) { + RzListIter *iter; + RzRegItem *ri; _set_initial_registers (dbg); - r_list_foreach (dbg->reg->allregs, iter, ri) { + rz_list_foreach (dbg->reg->allregs, iter, ri) { _set_register (dbg, ri, cnum); } } -static void _set_initial_memory(RDebug *dbg) { - RListIter *iter; - RDebugSnap *snap; - r_list_foreach (dbg->session->cur_chkpt->snaps, iter, snap) { +static void _set_initial_memory(RzDebug *dbg) { + RzListIter *iter; + RzDebugSnap *snap; + rz_list_foreach (dbg->session->cur_chkpt->snaps, iter, snap) { dbg->iob.write_at (dbg->iob.io, snap->addr, snap->data, snap->size); } } static bool _restore_memory_cb(void *user, const ut64 key, const void *value) { size_t index; - RDebug *dbg = user; - RVector *vmem = (RVector *)value; + RzDebug *dbg = user; + RzVector *vmem = (RzVector *)value; - r_vector_upper_bound (vmem, dbg->session->cnum, index, CMP_CNUM_MEM); + rz_vector_upper_bound (vmem, dbg->session->cnum, index, CMP_CNUM_MEM); if (index > 0 && index <= vmem->len) { - RDebugChangeMem *mem = r_vector_index_ptr (vmem, index - 1); + RzDebugChangeMem *mem = rz_vector_index_ptr (vmem, index - 1); if (mem->cnum > dbg->session->cur_chkpt->cnum) { dbg->iob.write_at (dbg->iob.io, key, &mem->data, 1); } @@ -154,108 +154,108 @@ static bool _restore_memory_cb(void *user, const ut64 key, const void *value) { return true; } -static void _restore_memory(RDebug *dbg, ut32 cnum) { +static void _restore_memory(RzDebug *dbg, ut32 cnum) { _set_initial_memory (dbg); ht_up_foreach (dbg->session->memory, _restore_memory_cb, dbg); } -static RDebugCheckpoint *_get_checkpoint_before(RDebugSession *session, ut32 cnum) { - RDebugCheckpoint *checkpoint = NULL; +static RzDebugCheckpoint *_get_checkpoint_before(RzDebugSession *session, ut32 cnum) { + RzDebugCheckpoint *checkpoint = NULL; size_t index; - r_vector_upper_bound (session->checkpoints, cnum, index, CMP_CNUM_CHKPT); + rz_vector_upper_bound (session->checkpoints, cnum, index, CMP_CNUM_CHKPT); if (index > 0 && index <= session->checkpoints->len) { - checkpoint = r_vector_index_ptr (session->checkpoints, index - 1); + checkpoint = rz_vector_index_ptr (session->checkpoints, index - 1); } return checkpoint; } -R_API void r_debug_session_restore_reg_mem(RDebug *dbg, ut32 cnum) { +RZ_API void rz_debug_session_restore_reg_mem(RzDebug *dbg, ut32 cnum) { // Set checkpoint for initial registers and memory dbg->session->cur_chkpt = _get_checkpoint_before (dbg->session, cnum); // Restore registers _restore_registers (dbg, cnum); - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, true); // Restore memory _restore_memory (dbg, cnum); } -R_API void r_debug_session_list_memory(RDebug *dbg) { - RListIter *iter; - RDebugMap *map; - r_debug_map_sync (dbg); - r_list_foreach (dbg->maps, iter, map) { +RZ_API void rz_debug_session_list_memory(RzDebug *dbg) { + RzListIter *iter; + RzDebugMap *map; + rz_debug_map_sync (dbg); + rz_list_foreach (dbg->maps, iter, map) { if ((map->perm & R_PERM_RW) == R_PERM_RW) { - RDebugSnap *snap = r_debug_snap_map (dbg, map); + RzDebugSnap *snap = rz_debug_snap_map (dbg, map); if (!snap) { return; } - ut8 *hash = r_debug_snap_get_hash (snap); + ut8 *hash = rz_debug_snap_get_hash (snap); if (!hash) { - r_debug_snap_free (snap); + rz_debug_snap_free (snap); return; } - char *hexstr = r_hex_bin2strdup (hash, R_HASH_SIZE_SHA256); + char *hexstr = rz_hex_bin2strdup (hash, R_HASH_SIZE_SHA256); if (!hexstr) { free (hash); - r_debug_snap_free (snap); + rz_debug_snap_free (snap); return; } dbg->cb_printf ("%s: %s\n", snap->name, hexstr); free (hexstr); free (hash); - r_debug_snap_free (snap); + rz_debug_snap_free (snap); } } } -R_API bool r_debug_session_add_reg_change(RDebugSession *session, int arena, ut64 offset, ut64 data) { - RVector *vreg = ht_up_find (session->registers, offset | (arena << 16), NULL); +RZ_API bool rz_debug_session_add_reg_change(RzDebugSession *session, int arena, ut64 offset, ut64 data) { + RzVector *vreg = ht_up_find (session->registers, offset | (arena << 16), NULL); if (!vreg) { - vreg = r_vector_new (sizeof (RDebugChangeReg), NULL, NULL); + vreg = rz_vector_new (sizeof (RzDebugChangeReg), NULL, NULL); if (!vreg) { eprintf ("Error: creating a register vector.\n"); return false; } ht_up_insert (session->registers, offset | (arena << 16), vreg); } - RDebugChangeReg reg = { session->cnum, data }; - r_vector_push (vreg, ®); + RzDebugChangeReg reg = { session->cnum, data }; + rz_vector_push (vreg, ®); return true; } -R_API bool r_debug_session_add_mem_change(RDebugSession *session, ut64 addr, ut8 data) { - RVector *vmem = ht_up_find (session->memory, addr, NULL); +RZ_API bool rz_debug_session_add_mem_change(RzDebugSession *session, ut64 addr, ut8 data) { + RzVector *vmem = ht_up_find (session->memory, addr, NULL); if (!vmem) { - vmem = r_vector_new (sizeof (RDebugChangeMem), NULL, NULL); + vmem = rz_vector_new (sizeof (RzDebugChangeMem), NULL, NULL); if (!vmem) { eprintf ("Error: creating a memory vector.\n"); return false; } ht_up_insert (session->memory, addr, vmem); } - RDebugChangeMem mem = { session->cnum, data }; - r_vector_push (vmem, &mem); + RzDebugChangeMem mem = { session->cnum, data }; + rz_vector_push (vmem, &mem); return true; } /* Save and Load Session */ -// 0x=[] +// 0x=[] static bool serialize_register_cb(void *db, const ut64 k, const void *v) { - RDebugChangeReg *reg; - RVector *vreg = (RVector *)v; + RzDebugChangeReg *reg; + RzVector *vreg = (RzVector *)v; PJ *j = pj_new (); if (!j) { return false; } pj_a (j); - r_vector_foreach (vreg, reg) { + rz_vector_foreach (vreg, reg) { pj_o (j); pj_kN (j, "cnum", reg->cnum); pj_kn (j, "data", reg->data); @@ -272,17 +272,17 @@ static void serialize_registers(Sdb *db, HtUP *registers) { ht_up_foreach (registers, serialize_register_cb, db); } -// 0x={"size":, "a":[]}}, +// 0x={"size":, "a":[]}}, static bool serialize_memory_cb(void *db, const ut64 k, const void *v) { - RDebugChangeMem *mem; - RVector *vmem = (RVector *)v; + RzDebugChangeMem *mem; + RzVector *vmem = (RzVector *)v; PJ *j = pj_new (); if (!j) { return false; } pj_a (j); - r_vector_foreach (vmem, mem) { + rz_vector_foreach (vmem, mem) { pj_o (j); pj_kN (j, "cnum", mem->cnum); pj_kn (j, "data", mem->data); @@ -299,16 +299,16 @@ static void serialize_memory(Sdb *db, HtUP *memory) { ht_up_foreach (memory, serialize_memory_cb, db); } -static void serialize_checkpoints(Sdb *db, RVector *checkpoints) { +static void serialize_checkpoints(Sdb *db, RzVector *checkpoints) { size_t i; - RDebugCheckpoint *chkpt; - RDebugSnap *snap; - RListIter *iter; + RzDebugCheckpoint *chkpt; + RzDebugSnap *snap; + RzListIter *iter; - r_vector_foreach (checkpoints, chkpt) { + rz_vector_foreach (checkpoints, chkpt) { // 0x={ - // registers:{"":, ...}, - // snaps:{"size":, "a":[]} + // registers:{"":, ...}, + // snaps:{"size":, "a":[]} // } PJ *j = pj_new (); if (!j) { @@ -316,11 +316,11 @@ static void serialize_checkpoints(Sdb *db, RVector *checkpoints) { } pj_o (j); - // Serialize RRegArena to "registers" + // Serialize RzRegArena to "registers" // {"size":, "bytes":""} pj_ka (j, "registers"); for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *arena = chkpt->arena[i]; + RzRegArena *arena = chkpt->arena[i]; if (arena->bytes) { pj_o (j); pj_kn (j, "arena", i); @@ -333,11 +333,11 @@ static void serialize_checkpoints(Sdb *db, RVector *checkpoints) { } pj_end (j); - // Serialize RDebugSnap to "snaps" + // Serialize RzDebugSnap to "snaps" // {"name":, "addr":, "addr_end":, "size":, // "data":"", "perm":, "user":, "shared":} pj_ka (j, "snaps"); - r_list_foreach (chkpt->snaps, iter, snap) { + rz_list_foreach (chkpt->snaps, iter, snap) { pj_o (j); pj_ks (j, "name", snap->name); pj_kn (j, "addr", snap->addr); @@ -370,34 +370,34 @@ static void serialize_checkpoints(Sdb *db, RVector *checkpoints) { * maxcnum= * * /registers - * 0x={"size":, "a":[]} + * 0x={"size":, "a":[]} * * /memory - * 0x={"size":, "a":[]} + * 0x={"size":, "a":[]} * * /checkpoints * 0x={ - * registers:{"":, ...}, - * snaps:{"size":, "a":[]} + * registers:{"":, ...}, + * snaps:{"size":, "a":[]} * } * - * RDebugChangeReg JSON: + * RzDebugChangeReg JSON: * {"cnum":, "data":} * - * RDebugChangeMem JSON: + * RzDebugChangeMem JSON: * {"cnum":, "data":} * - * RRegArena JSON: + * RzRegArena JSON: * {"size":, "bytes":""} * - * RDebugSnap JSON: + * RzDebugSnap JSON: * {"name":, "addr":, "addr_end":, "size":, * "data":"", "perm":, "user":, "shared":} * * Notes: * - This mostly follows r2db-style serialization and uses sdb_json as the parser. */ -R_API void r_debug_session_serialize(RDebugSession *session, Sdb *db) { +RZ_API void rz_debug_session_serialize(RzDebugSession *session, Sdb *db) { sdb_num_set (db, "maxcnum", session->maxcnum, 0); serialize_registers (sdb_ns (db, "registers", true), session->registers); serialize_memory (sdb_ns (db, "memory", true), session->memory); @@ -406,12 +406,12 @@ R_API void r_debug_session_serialize(RDebugSession *session, Sdb *db) { static bool session_sdb_save(Sdb *db, const char *path) { char *filename; - if (!r_file_is_directory (path)) { + if (!rz_file_is_directory (path)) { eprintf ("Error: %s is not a directory\n", path); return false; } - filename = r_str_newf ("%s%ssession.sdb", path, R_SYS_DIR); + filename = rz_str_newf ("%s%ssession.sdb", path, R_SYS_DIR); sdb_file (db, filename); if (!sdb_sync (db)) { eprintf ("Failed to sync session to %s\n", filename); @@ -425,7 +425,7 @@ static bool session_sdb_save(Sdb *db, const char *path) { SdbListIter *it; SdbNs *ns; ls_foreach (db->ns, it, ns) { - char *filename = r_str_newf ("%s%s%s.sdb", path, R_SYS_DIR, ns->name); + char *filename = rz_str_newf ("%s%s%s.sdb", path, R_SYS_DIR, ns->name); sdb_file (ns->sdb, filename); if (!sdb_sync (ns->sdb)) { eprintf ("Failed to sync %s to %s\n", ns->name, filename); @@ -440,12 +440,12 @@ static bool session_sdb_save(Sdb *db, const char *path) { return true; } -R_API bool r_debug_session_save(RDebugSession *session, const char *path) { +RZ_API bool rz_debug_session_save(RzDebugSession *session, const char *path) { Sdb *db = sdb_new0 (); if (!db) { return false; } - r_debug_session_serialize (session, db); + rz_debug_session_serialize (session, db); if (!session_sdb_save (db, path)) { sdb_free (db); @@ -466,7 +466,7 @@ static bool deserialize_memory_cb(void *user, const char *addr, const char *v) { if (!json_str) { return true; } - RJson *reg_json = r_json_parse (json_str); + RJson *reg_json = rz_json_parse (json_str); if (!reg_json || reg_json->type != R_JSON_ARRAY) { free (json_str); return true; @@ -474,28 +474,28 @@ static bool deserialize_memory_cb(void *user, const char *addr, const char *v) { HtUP *memory = user; // Insert a new vector into `memory` HtUP at `addr` - RVector *vmem = r_vector_new (sizeof (RDebugChangeMem), NULL, NULL); + RzVector *vmem = rz_vector_new (sizeof (RzDebugChangeMem), NULL, NULL); if (!vmem) { - eprintf ("Error: failed to allocate RVector vmem.\n"); + eprintf ("Error: failed to allocate RzVector vmem.\n"); return false; } ht_up_insert (memory, sdb_atoi (addr), vmem); - // Extract 's into the new vector + // Extract 's into the new vector for (child = reg_json->children.first; child; child = child->next) { if (child->type != R_JSON_OBJECT) { continue; } - const RJson *baby = r_json_get (child, "cnum"); + const RJson *baby = rz_json_get (child, "cnum"); CHECK_TYPE (baby, R_JSON_INTEGER); int cnum = baby->num.s_value; - baby = r_json_get (child, "data"); + baby = rz_json_get (child, "data"); CHECK_TYPE (baby, R_JSON_INTEGER); ut64 data = baby->num.u_value; - RDebugChangeMem mem = { cnum, data }; - r_vector_push (vmem, &mem); + RzDebugChangeMem mem = { cnum, data }; + rz_vector_push (vmem, &mem); } return true; @@ -511,7 +511,7 @@ static bool deserialize_registers_cb(void *user, const char *addr, const char *v if (!json_str) { return true; } - RJson *reg_json = r_json_parse (json_str); + RJson *reg_json = rz_json_parse (json_str); if (!reg_json || reg_json->type != R_JSON_ARRAY) { free (json_str); return true; @@ -519,33 +519,33 @@ static bool deserialize_registers_cb(void *user, const char *addr, const char *v // Insert a new vector into `registers` HtUP at `addr` HtUP *registers = user; - RVector *vreg = r_vector_new (sizeof (RDebugChangeReg), NULL, NULL); + RzVector *vreg = rz_vector_new (sizeof (RzDebugChangeReg), NULL, NULL); if (!vreg) { - eprintf ("Error: failed to allocate RVector vreg.\n"); - r_json_free (reg_json); + eprintf ("Error: failed to allocate RzVector vreg.\n"); + rz_json_free (reg_json); free (json_str); return true; } ht_up_insert (registers, sdb_atoi (addr), vreg); - // Extract 's into the new vector + // Extract 's into the new vector for (child = reg_json->children.first; child; child = child->next) { if (child->type != R_JSON_OBJECT) { continue; } - const RJson *baby = r_json_get (child, "cnum"); + const RJson *baby = rz_json_get (child, "cnum"); CHECK_TYPE (baby, R_JSON_INTEGER); int cnum = baby->num.s_value; - baby = r_json_get (child, "data"); + baby = rz_json_get (child, "data"); CHECK_TYPE (baby, R_JSON_INTEGER); ut64 data = baby->num.u_value; - RDebugChangeReg reg = { cnum, data }; - r_vector_push (vreg, ®); + RzDebugChangeReg reg = { cnum, data }; + rz_vector_push (vreg, ®); } - r_json_free (reg_json); + rz_json_free (reg_json); free (json_str); return true; } @@ -563,40 +563,40 @@ static bool deserialize_checkpoints_cb(void *user, const char *cnum, const char if (!json_str) { return true; } - RJson *chkpt_json = r_json_parse (json_str); + RJson *chkpt_json = rz_json_parse (json_str); if (!chkpt_json || chkpt_json->type != R_JSON_OBJECT) { free (json_str); return true; } - RVector *checkpoints = user; - RDebugCheckpoint checkpoint = { 0 }; + RzVector *checkpoints = user; + RzDebugCheckpoint checkpoint = { 0 }; checkpoint.cnum = (int)sdb_atoi (cnum); - // Extract RRegArena's from "registers" - const RJson *regs_json = r_json_get (chkpt_json, "registers"); + // Extract RzRegArena's from "registers" + const RJson *regs_json = rz_json_get (chkpt_json, "registers"); if (!regs_json || regs_json->type != R_JSON_ARRAY) { return true; } for (child = regs_json->children.first; child; child = child->next) { const RJson *baby; - baby = r_json_get (child, "arena"); + baby = rz_json_get (child, "arena"); CHECK_TYPE (baby, R_JSON_INTEGER); int arena = baby->num.s_value; if (arena < R_REG_TYPE_GPR || arena > R_REG_TYPE_SEG) { continue; } - baby = r_json_get (child, "size"); + baby = rz_json_get (child, "size"); CHECK_TYPE (baby, R_JSON_INTEGER); int size = baby->num.s_value; if (size < 0) { continue; } - baby = r_json_get (child, "bytes"); + baby = rz_json_get (child, "bytes"); CHECK_TYPE (baby, R_JSON_STRING); ut8 *bytes = sdb_decode (baby->str_value, NULL); - RRegArena *a = r_reg_arena_new (size); + RzRegArena *a = rz_reg_arena_new (size); if (!a) { free (bytes); continue; @@ -606,33 +606,33 @@ static bool deserialize_checkpoints_cb(void *user, const char *cnum, const char free (bytes); } - // Extract RDebugSnap's from "snaps" - checkpoint.snaps = r_list_newf ((RListFree)r_debug_snap_free); - const RJson *snaps_json = r_json_get (chkpt_json, "snaps"); + // Extract RzDebugSnap's from "snaps" + checkpoint.snaps = rz_list_newf ((RzListFree)rz_debug_snap_free); + const RJson *snaps_json = rz_json_get (chkpt_json, "snaps"); if (!snaps_json || snaps_json->type != R_JSON_ARRAY) { goto end; } for (child = snaps_json->children.first; child; child = child->next) { - const RJson *namej = r_json_get (child, "name"); + const RJson *namej = rz_json_get (child, "name"); CHECK_TYPE (namej, R_JSON_STRING); - const RJson *dataj = r_json_get (child, "data"); + const RJson *dataj = rz_json_get (child, "data"); CHECK_TYPE (dataj, R_JSON_STRING); - const RJson *sizej = r_json_get (child, "size"); + const RJson *sizej = rz_json_get (child, "size"); CHECK_TYPE (sizej, R_JSON_INTEGER); - const RJson *addrj = r_json_get (child, "addr"); + const RJson *addrj = rz_json_get (child, "addr"); CHECK_TYPE (addrj, R_JSON_INTEGER); - const RJson *addr_endj = r_json_get (child, "addr_end"); + const RJson *addr_endj = rz_json_get (child, "addr_end"); CHECK_TYPE (addr_endj, R_JSON_INTEGER); - const RJson *permj = r_json_get (child, "perm"); + const RJson *permj = rz_json_get (child, "perm"); CHECK_TYPE (permj, R_JSON_INTEGER); - const RJson *userj = r_json_get (child, "user"); + const RJson *userj = rz_json_get (child, "user"); CHECK_TYPE (userj, R_JSON_INTEGER); - const RJson *sharedj = r_json_get (child, "shared"); + const RJson *sharedj = rz_json_get (child, "shared"); CHECK_TYPE (sharedj, R_JSON_BOOLEAN); - RDebugSnap *snap = R_NEW0 (RDebugSnap); + RzDebugSnap *snap = R_NEW0 (RzDebugSnap); if (!snap) { - eprintf ("Error: failed to allocate RDebugSnap snap"); + eprintf ("Error: failed to allocate RzDebugSnap snap"); continue; } snap->name = strdup (namej->str_value); @@ -644,14 +644,14 @@ static bool deserialize_checkpoints_cb(void *user, const char *cnum, const char snap->user = userj->num.s_value; snap->shared = sharedj->num.u_value; - r_list_append (checkpoint.snaps, snap); + rz_list_append (checkpoint.snaps, snap); } end: - r_vector_push (checkpoints, &checkpoint); + rz_vector_push (checkpoints, &checkpoint); return true; } -static void deserialize_checkpoints(Sdb *db, RVector *checkpoints) { +static void deserialize_checkpoints(Sdb *db, RzVector *checkpoints) { sdb_foreach (db, deserialize_checkpoints_cb, checkpoints); } @@ -676,7 +676,7 @@ static Sdb *session_sdb_load(const char *path) { } #define SDB_LOAD(fn, ns) do { \ - filename = r_str_newf ("%s%s" fn ".sdb", path, R_SYS_DIR); \ + filename = rz_str_newf ("%s%s" fn ".sdb", path, R_SYS_DIR); \ if (!session_sdb_load_ns (db, ns, filename)) { \ free (filename); \ goto error; \ @@ -694,7 +694,7 @@ error: return NULL; } -R_API void r_debug_session_deserialize(RDebugSession *session, Sdb *db) { +RZ_API void rz_debug_session_deserialize(RzDebugSession *session, Sdb *db) { Sdb *subdb; session->maxcnum = sdb_num_get (db, "maxcnum", 0); @@ -713,14 +713,14 @@ R_API void r_debug_session_deserialize(RDebugSession *session, Sdb *db) { DESERIALIZE ("checkpoints", deserialize_checkpoints (subdb, session->checkpoints)); } -R_API bool r_debug_session_load(RDebug *dbg, const char *path) { +RZ_API bool rz_debug_session_load(RzDebug *dbg, const char *path) { Sdb *db = session_sdb_load (path); if (!db) { return false; } - r_debug_session_deserialize (dbg->session, db); + rz_debug_session_deserialize (dbg->session, db); // Restore debugger to the beginning of the session - r_debug_session_restore_reg_mem (dbg, 0); + rz_debug_session_restore_reg_mem (dbg, 0); sdb_free (db); return true; } diff --git a/libr/debug/dsignal.c b/librz/debug/dsignal.c similarity index 70% rename from libr/debug/dsignal.c rename to librz/debug/dsignal.c index a15ea3d4b1..fd27ecf29d 100644 --- a/libr/debug/dsignal.c +++ b/librz/debug/dsignal.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2014-2020 - pancake */ -#include +#include #define DB dbg->sgnls @@ -50,7 +50,7 @@ static struct { { NULL } }; -R_API void r_debug_signal_init(RDebug *dbg) { +RZ_API void rz_debug_signal_init(RzDebug *dbg) { int i; // XXX DB = sdb_new (NULL, "signals", 0); @@ -62,23 +62,23 @@ R_API void r_debug_signal_init(RDebug *dbg) { static bool siglistcb (void *p, const char *k, const char *v) { static char key[32] = "cfg."; - RDebug *dbg = (RDebug *)p; + RzDebug *dbg = (RzDebug *)p; int opt, mode = dbg->_mode; if (atoi (k) > 0) { strncpy (key + 4, k, 20); opt = sdb_num_get (DB, key, 0); if (opt) { - r_cons_printf ("%s %s", k, v); + rz_cons_printf ("%s %s", k, v); if (opt & R_DBG_SIGNAL_CONT) { - r_cons_strcat (" cont"); + rz_cons_strcat (" cont"); } if (opt & R_DBG_SIGNAL_SKIP) { - r_cons_strcat (" skip"); + rz_cons_strcat (" skip"); } - r_cons_newline (); + rz_cons_newline (); } else { if (mode == 0) { - r_cons_printf ("%s %s\n", k, v); + rz_cons_printf ("%s %s\n", k, v); } } } @@ -87,7 +87,7 @@ static bool siglistcb (void *p, const char *k, const char *v) { static bool siglistjsoncb (void *p, const char *k, const char *v) { static char key[32] = "cfg."; - RDebug *dbg = (RDebug *)p; + RzDebug *dbg = (RzDebug *)p; int opt; if (atoi (k)>0) { strncpy (key + 4, k, 20); @@ -95,22 +95,22 @@ static bool siglistjsoncb (void *p, const char *k, const char *v) { if (dbg->_mode == 2) { dbg->_mode = 0; } else { - r_cons_strcat (","); + rz_cons_strcat (","); } - r_cons_printf ("{\"signum\":\"%s\",\"name\":\"%s\",\"option\":", k, v); + rz_cons_printf ("{\"signum\":\"%s\",\"name\":\"%s\",\"option\":", k, v); if (opt & R_DBG_SIGNAL_CONT) { - r_cons_strcat ("\"cont\""); + rz_cons_strcat ("\"cont\""); } else if (opt & R_DBG_SIGNAL_SKIP) { - r_cons_strcat ("\"skip\""); + rz_cons_strcat ("\"skip\""); } else { - r_cons_strcat ("null"); + rz_cons_strcat ("null"); } - r_cons_strcat ("}"); + rz_cons_strcat ("}"); } return true; } -R_API void r_debug_signal_list(RDebug *dbg, int mode) { +RZ_API void rz_debug_signal_list(RzDebug *dbg, int mode) { dbg->_mode = mode; switch (mode) { case 0: @@ -118,50 +118,50 @@ R_API void r_debug_signal_list(RDebug *dbg, int mode) { sdb_foreach (DB, siglistcb, dbg); break; case 2: - r_cons_strcat ("["); + rz_cons_strcat ("["); sdb_foreach (DB, siglistjsoncb, dbg); - r_cons_strcat ("]"); - r_cons_newline(); + rz_cons_strcat ("]"); + rz_cons_newline(); break; } dbg->_mode = 0; } -R_API int r_debug_signal_send(RDebug *dbg, int num) { - return r_sandbox_kill (dbg->pid, num); +RZ_API int rz_debug_signal_send(RzDebug *dbg, int num) { + return rz_sandbox_kill (dbg->pid, num); } -R_API void r_debug_signal_setup(RDebug *dbg, int num, int opt) { +RZ_API void rz_debug_signal_setup(RzDebug *dbg, int num, int opt) { sdb_queryf (DB, "cfg.%d=%d", num, opt); } -R_API int r_debug_signal_what(RDebug *dbg, int num) { +RZ_API int rz_debug_signal_what(RzDebug *dbg, int num) { char k[32]; snprintf (k, sizeof (k), "cfg.%d", num); return sdb_num_get (DB, k, 0); } -R_API int r_debug_signal_set(RDebug *dbg, int num, ut64 addr) { +RZ_API int rz_debug_signal_set(RzDebug *dbg, int num, ut64 addr) { // TODO - // r_debug_syscall (dbg, "signal", "addr"); + // rz_debug_syscall (dbg, "signal", "addr"); return 0; } /* TODO rename to _kill_ -> _signal_ */ -R_API RList *r_debug_kill_list(RDebug *dbg) { +RZ_API RzList *rz_debug_kill_list(RzDebug *dbg) { if (dbg->h->kill_list) { return dbg->h->kill_list (dbg); } return NULL; } -R_API int r_debug_kill_setup(RDebug *dbg, int sig, int action) { +RZ_API int rz_debug_kill_setup(RzDebug *dbg, int sig, int action) { eprintf ("TODO: set signal handlers of child\n"); // TODO: must inject code to call signal() #if 0 if (dbg->h->kill_setup) return dbg->h->kill_setup (dbg, sig, action); #endif - // TODO: implement r_debug_kill_setup + // TODO: implement rz_debug_kill_setup return false; } diff --git a/libr/debug/meson.build b/librz/debug/meson.build similarity index 60% rename from libr/debug/meson.build rename to librz/debug/meson.build index 26d7cbe24b..b6e6f443d6 100644 --- a/libr/debug/meson.build +++ b/librz/debug/meson.build @@ -1,4 +1,4 @@ -r_debug_sources = [ +rz_debug_sources = [ 'arg.c', 'ddesc.c', 'debug.c', @@ -32,51 +32,51 @@ r_debug_sources = [ #'p/native/maps/darwin.c', ] -r_debug_deps = [ - r_util_dep, - r_hash_dep, - r_reg_dep, - r_syscall_dep, - r_anal_dep, - r_flag_dep, - r_io_dep, - r_bp_dep, - r_search_dep, - r_cons_dep, - r_lang_dep, - r_egg_dep, +rz_debug_deps = [ + rz_util_dep, + rz_hash_dep, + rz_reg_dep, + rz_syscall_dep, + rz_anal_dep, + rz_flag_dep, + rz_io_dep, + rz_bp_dep, + rz_search_dep, + rz_cons_dep, + rz_lang_dep, + rz_egg_dep, winkd_dep, qnx_dep, gdb_dep, bochs_dep, - r_socket_dep + rz_socket_dep ] if host_machine.system() == 'linux' or host_machine.system() == 'android' - r_debug_sources += ['p/native/linux/linux_debug.c'] + rz_debug_sources += ['p/native/linux/linux_debug.c'] endif if host_machine.system() == 'linux' - r_debug_sources += ['p/native/linux/linux_coredump.c'] + rz_debug_sources += ['p/native/linux/linux_coredump.c'] endif if host_machine.system() == 'windows' - r_debug_sources += [ + rz_debug_sources += [ 'p/debug_windbg.c', 'p/native/maps/windows_maps.c', 'p/native/windows/windows_debug.c', 'p/native/windows/windows_message.c', ] - r_debug_deps += w32dbg_wrap_dep + rz_debug_deps += w32dbg_wrap_dep endif if host_machine.system() != 'windows' - r_debug_sources += [ + rz_debug_sources += [ 'p/native/procfs.c' ] endif if host_machine.system() == 'darwin' - r_debug_sources += [ + rz_debug_sources += [ 'p/native/xnu/xnu_debug.c', #'p/native/xnu/trap_arm.c', #'p/native/xnu/trap_x86.c', @@ -86,52 +86,52 @@ if host_machine.system() == 'darwin' endif if ['netbsd', 'openbsd', 'freebsd', 'dragonfly'].contains(host_machine.system()) - r_debug_deps += cc.find_library('kvm', required: true) - r_debug_sources += [ + rz_debug_deps += cc.find_library('kvm', required: true) + rz_debug_sources += [ 'p/native/bsd/bsd_debug.c', ] endif -r_debug_inc = [ +rz_debug_inc = [ platform_inc, include_directories( '../bin/format/elf' ) ] -r_debug = library('r_debug', r_debug_sources, - include_directories: r_debug_inc, +rz_debug = library('rz_debug', rz_debug_sources, + include_directories: rz_debug_inc, c_args: library_cflags, - dependencies: r_debug_deps, + dependencies: rz_debug_deps, install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_debug_dep = declare_dependency(link_with: r_debug, - include_directories: r_debug_inc) +rz_debug_dep = declare_dependency(link_with: rz_debug, + include_directories: rz_debug_inc) -pkgconfig_mod.generate(r_debug, - subdirs: 'libr', +pkgconfig_mod.generate(rz_debug, + subdirs: 'librz', version: r2_version, - name: 'r_debug', - filebase: 'r_debug', + name: 'rz_debug', + filebase: 'rz_debug', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_hash', - 'r_reg', - 'r_syscall', - 'r_anal', - 'r_flag', - 'r_io', - 'r_bp', - 'r_search', - 'r_cons', - 'r_lang', - 'r_egg', - 'r_socket' + 'rz_util', + 'rz_hash', + 'rz_reg', + 'rz_syscall', + 'rz_anal', + 'rz_flag', + 'rz_io', + 'rz_bp', + 'rz_search', + 'rz_cons', + 'rz_lang', + 'rz_egg', + 'rz_socket' ], description: 'radare foundation libraries' ) diff --git a/libr/debug/p/Makefile b/librz/debug/p/Makefile similarity index 100% rename from libr/debug/p/Makefile rename to librz/debug/p/Makefile diff --git a/libr/debug/p/bf.mk b/librz/debug/p/bf.mk similarity index 100% rename from libr/debug/p/bf.mk rename to librz/debug/p/bf.mk diff --git a/libr/debug/p/bfvm.c b/librz/debug/p/bfvm.c similarity index 85% rename from libr/debug/p/bfvm.c rename to librz/debug/p/bfvm.c index 3f0ea2ac85..6611e3a0a0 100644 --- a/libr/debug/p/bfvm.c +++ b/librz/debug/p/bfvm.c @@ -14,7 +14,7 @@ static ut8 bfvm_op(BfvmCPU *c) { return buf[0]; } -R_API int bfvm_in_trap(BfvmCPU *c) { +RZ_API int bfvm_in_trap(BfvmCPU *c) { switch (bfvm_op (c)) { case 0x00: case 0xcc: @@ -24,7 +24,7 @@ R_API int bfvm_in_trap(BfvmCPU *c) { return 0; } -R_API void bfvm_reset(BfvmCPU *c) { +RZ_API void bfvm_reset(BfvmCPU *c) { memset (c->mem, '\0', c->size); memset (c->input_buf, '\0', c->input_size); memset (c->screen_buf, '\0', c->screen_size); @@ -38,7 +38,7 @@ R_API void bfvm_reset(BfvmCPU *c) { c->esp = c->base; } -R_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) { +RZ_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) { memset (c, '\0', sizeof (BfvmCPU)); /* data */ @@ -66,14 +66,14 @@ R_API int bfvm_init(BfvmCPU *c, ut32 size, int circular) { return 1; } -R_API BfvmCPU *bfvm_new(RIOBind *iob) { +RZ_API BfvmCPU *bfvm_new(RzIOBind *iob) { BfvmCPU *c = R_NEW0 (BfvmCPU); bfvm_init (c, 4096, 1); memcpy (&c->iob, iob, sizeof (c->iob)); return c; } -R_API BfvmCPU *bfvm_free(BfvmCPU *c) { +RZ_API BfvmCPU *bfvm_free(BfvmCPU *c) { free (c->mem); c->mem = 0; free (c->screen_buf); @@ -82,7 +82,7 @@ R_API BfvmCPU *bfvm_free(BfvmCPU *c) { return NULL; } -R_API ut8 *bfvm_get_ptr_at(BfvmCPU *c, ut64 at) { +RZ_API ut8 *bfvm_get_ptr_at(BfvmCPU *c, ut64 at) { if (at >= c->base) { at -= c->base; } else if (at >= c->size) { @@ -91,47 +91,47 @@ R_API ut8 *bfvm_get_ptr_at(BfvmCPU *c, ut64 at) { return c->mem + at; } -R_API ut8 *bfvm_get_ptr(BfvmCPU *c) { +RZ_API ut8 *bfvm_get_ptr(BfvmCPU *c) { //return bfvm_cpu.mem; return bfvm_get_ptr_at (c, c->ptr); } -R_API ut8 bfvm_get(BfvmCPU *c) { +RZ_API ut8 bfvm_get(BfvmCPU *c) { ut8 *ptr = bfvm_get_ptr (c); return ptr? *ptr: 0; } -R_API void bfvm_inc(BfvmCPU *c) { +RZ_API void bfvm_inc(BfvmCPU *c) { ut8 *mem = bfvm_get_ptr (c); if (mem != NULL) { mem[0]++; } } -R_API void bfvm_dec(BfvmCPU *c) { +RZ_API void bfvm_dec(BfvmCPU *c) { ut8 *mem = bfvm_get_ptr (c); if (mem != NULL) { mem[0]--; } } -R_API int bfvm_reg_set(BfvmCPU *c, const char *str) { +RZ_API int bfvm_reg_set(BfvmCPU *c, const char *str) { char *ptr = strchr (str, ' '); if (!ptr) { return 0; } if (strstr (str, "eip")) { - c->eip = r_num_math (NULL, ptr+1); + c->eip = rz_num_math (NULL, ptr+1); } else if (strstr (str, "esp")) { - c->esp = r_num_math (NULL, ptr+1); + c->esp = rz_num_math (NULL, ptr+1); } else if (strstr (str, "ptr")) { - c->ptr = r_num_math (NULL, ptr + 1); + c->ptr = rz_num_math (NULL, ptr + 1); } return 1; } /* screen and input */ -R_API void bfvm_peek(BfvmCPU *c) { +RZ_API void bfvm_peek(BfvmCPU *c) { int idx = c->input_idx; ut8 *ptr = bfvm_get_ptr (c); @@ -145,13 +145,13 @@ R_API void bfvm_peek(BfvmCPU *c) { } } -R_API void bfvm_poke(BfvmCPU *c) { +RZ_API void bfvm_poke(BfvmCPU *c) { int idx = c->screen_idx; c->screen_buf[idx] = bfvm_get (c); c->screen_idx = idx+1; } -R_API int bfvm_trace_op(BfvmCPU *c, ut8 op) { +RZ_API int bfvm_trace_op(BfvmCPU *c, ut8 op) { ut8 g; switch (op) { case '\0': @@ -178,7 +178,7 @@ R_API int bfvm_trace_op(BfvmCPU *c, ut8 op) { #define T if (c->trace) /* debug */ -R_API int bfvm_step(BfvmCPU *c, int over) { +RZ_API int bfvm_step(BfvmCPU *c, int over) { ut8 op2, op = bfvm_op (c); do { @@ -231,7 +231,7 @@ R_API int bfvm_step(BfvmCPU *c, int over) { return 0; } -R_API int bfvm_contsc(BfvmCPU *c) { +RZ_API int bfvm_contsc(BfvmCPU *c) { c->breaked = 0; while (!c->breaked) { bfvm_step (c, 0); @@ -253,7 +253,7 @@ R_API int bfvm_contsc(BfvmCPU *c) { return 0; } -R_API int bfvm_cont(BfvmCPU *c, ut64 until) { +RZ_API int bfvm_cont(BfvmCPU *c, ut64 until) { c->breaked = 0; while (!c->breaked && c->eip != until) { bfvm_step (c, 0); @@ -265,14 +265,14 @@ R_API int bfvm_cont(BfvmCPU *c, ut64 until) { return 0; } -R_API int bfvm_trace(BfvmCPU *c, ut64 until) { +RZ_API int bfvm_trace(BfvmCPU *c, ut64 until) { c->trace=1; bfvm_cont (c, until); c->trace=0; return 0; } -R_API void bfvm_show_regs(BfvmCPU *c, int rad) { +RZ_API void bfvm_show_regs(BfvmCPU *c, int rad) { if (rad) { eprintf ("fs regs\n"); eprintf ("f eip @ 0x%08"PFMT64x"\n", (ut64)c->eip); @@ -288,7 +288,7 @@ R_API void bfvm_show_regs(BfvmCPU *c, int rad) { } } -R_API void bfvm_maps(BfvmCPU *c, int rad) { +RZ_API void bfvm_maps(BfvmCPU *c, int rad) { if (rad) { eprintf ("fs sections\n"); eprintf ("e cmd.vprompt=px@screen\n"); diff --git a/libr/debug/p/bfvm.h b/librz/debug/p/bfvm.h similarity index 76% rename from libr/debug/p/bfvm.h rename to librz/debug/p/bfvm.h index 285fc60125..28a57f47e1 100644 --- a/libr/debug/p/bfvm.h +++ b/librz/debug/p/bfvm.h @@ -1,8 +1,8 @@ #ifndef _R_BFVM_INCLUDE_ #define _R_BFVM_INCLUDE_ -#include -#include +#include +#include #define BFVM_SCREEN_ADDR 0x50000 #define BFVM_SCREEN_SIZE 4096 @@ -31,13 +31,13 @@ typedef struct bfvm_cpu_t { int input_size; ut8 *input_buf; int circular; /* circular memory */ - RIOBind iob; + RzIOBind iob; } BfvmCPU; -#ifdef R_API -R_API BfvmCPU *bfvm_new(RIOBind *iob); -R_API BfvmCPU *bfvm_free(BfvmCPU *c); -R_API int bfvm_step(BfvmCPU *c, int over); +#ifdef RZ_API +RZ_API BfvmCPU *bfvm_new(RzIOBind *iob); +RZ_API BfvmCPU *bfvm_free(BfvmCPU *c); +RZ_API int bfvm_step(BfvmCPU *c, int over); #endif #endif diff --git a/libr/debug/p/bochs.mk b/librz/debug/p/bochs.mk similarity index 63% rename from libr/debug/p/bochs.mk rename to librz/debug/p/bochs.mk index ad55dd89de..d31cd8a63d 100644 --- a/libr/debug/p/bochs.mk +++ b/librz/debug/p/bochs.mk @@ -1,5 +1,5 @@ #include ../../config.mk -#BINDEPS=r_reg r_bp r_util r_io r_anal +#BINDEPS=rz_reg rz_bp rz_util rz_io rz_anal CFLAGS+=-I$(SHLR)/bochs/include/ LIB_PATH=$(SHRL)/bochs/ @@ -14,13 +14,13 @@ endif -include ../../global.mk -include ../../../global.mk -include $(STOP)/bochs/deps.mk -LDFLAGS+=-L$(LTOP)/util -lr_util -LDFLAGS+=-L$(LTOP)/cons -lr_cons -LDFLAGS+=-L$(LTOP)/parse -lr_parse -LDFLAGS+=-L$(LTOP)/anal -lr_anal -LDFLAGS+=-L$(LTOP)/reg -lr_reg -LDFLAGS+=-L$(LTOP)/bp -lr_bp -LDFLAGS+=-L$(LTOP)/io -lr_io +LDFLAGS+=-L$(LTOP)/util -lrz_util +LDFLAGS+=-L$(LTOP)/cons -lrz_cons +LDFLAGS+=-L$(LTOP)/parse -lrz_parse +LDFLAGS+=-L$(LTOP)/anal -lrz_anal +LDFLAGS+=-L$(LTOP)/reg -lrz_reg +LDFLAGS+=-L$(LTOP)/bp -lrz_bp +LDFLAGS+=-L$(LTOP)/io -lrz_io OBJ_BOCHS=debug_bochs.o diff --git a/libr/debug/p/debug_bf.c b/librz/debug/p/debug_bf.c similarity index 54% rename from libr/debug/p/debug_bf.c rename to librz/debug/p/debug_bf.c index 17c2a213ec..ae62e59beb 100644 --- a/libr/debug/p/debug_bf.c +++ b/librz/debug/p/debug_bf.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include -#include -#undef R_API -#define R_API static inline +#include +#include +#undef RZ_API +#define RZ_API static inline #include "bfvm.c" typedef struct { @@ -11,7 +11,7 @@ typedef struct { ut8 *buf; ut32 size; BfvmCPU *bfvm; -} RIOBdescbg; +} RzIOBdescbg; struct bfvm_regs { ut32 pc; @@ -27,8 +27,8 @@ struct bfvm_regs { static struct bfvm_regs r; -static bool is_io_bf(RDebug *dbg) { - RIODesc *d = dbg->iob.io->desc; +static bool is_io_bf(RzDebug *dbg) { + RzIODesc *d = dbg->iob.io->desc; if (d && d->plugin && d->plugin->name) { if (!strcmp ("bfdbg", d->plugin->name)) { return true; @@ -38,8 +38,8 @@ static bool is_io_bf(RDebug *dbg) { return false; } -static int r_debug_bf_step_over(RDebug *dbg) { - RIOBdescbg *o = dbg->iob.io->desc->data; +static int rz_debug_bf_step_over(RzDebug *dbg) { + RzIOBdescbg *o = dbg->iob.io->desc->data; int op, oop = 0; for (;;) { op = bfvm_op (o->bfvm); @@ -55,21 +55,21 @@ static int r_debug_bf_step_over(RDebug *dbg) { return true; } -static int r_debug_bf_step(RDebug *dbg) { - RIOBdescbg *o = dbg->iob.io->desc->data; +static int rz_debug_bf_step(RzDebug *dbg) { + RzIOBdescbg *o = dbg->iob.io->desc->data; bfvm_step (o->bfvm, 0); return true; } -static int r_debug_bf_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { - r_return_val_if_fail (dbg && buf && size > 0, -1); +static int rz_debug_bf_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + rz_return_val_if_fail (dbg && buf && size > 0, -1); if (!is_io_bf (dbg)) { return 0; } if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data)) { return 0; } - RIOBdescbg *o = dbg->iob.io->desc->data; + RzIOBdescbg *o = dbg->iob.io->desc->data; r.pc = o->bfvm->eip; r.ptr = o->bfvm->ptr; r.sp = o->bfvm->esp; @@ -80,11 +80,11 @@ static int r_debug_bf_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { r.mem = o->bfvm->base; r.memi = o->bfvm->ptr; memcpy (buf, &r, sizeof (r)); - //r_io_system (dbg->iob.io, "dr"); + //rz_io_system (dbg->iob.io, "dr"); return sizeof (r); } -static int r_debug_bf_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int rz_debug_bf_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { if (!dbg) { return false; } @@ -94,7 +94,7 @@ static int r_debug_bf_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) if (!(dbg->iob.io) || !(dbg->iob.io->desc) || !(dbg->iob.io->desc->data)) { return 0; } - RIOBdescbg *o = dbg->iob.io->desc->data; + RzIOBdescbg *o = dbg->iob.io->desc->data; memcpy (&r, buf, sizeof (r)); o->bfvm->eip = r.pc; o->bfvm->ptr = r.ptr; // dup @@ -108,36 +108,36 @@ static int r_debug_bf_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) return true; } -static int r_debug_bf_continue(RDebug *dbg, int pid, int tid, int sig) { - RIOBdescbg *o = dbg->iob.io->desc->data; +static int rz_debug_bf_continue(RzDebug *dbg, int pid, int tid, int sig) { + RzIOBdescbg *o = dbg->iob.io->desc->data; bfvm_cont (o->bfvm, UT64_MAX); return true; } -static int r_debug_bf_continue_syscall(RDebug *dbg, int pid, int num) { - RIOBdescbg *o = dbg->iob.io->desc->data; +static int rz_debug_bf_continue_syscall(RzDebug *dbg, int pid, int num) { + RzIOBdescbg *o = dbg->iob.io->desc->data; bfvm_contsc (o->bfvm); return true; } -static int r_debug_bf_wait(RDebug *dbg, int pid) { +static int rz_debug_bf_wait(RzDebug *dbg, int pid) { /* do nothing */ return true; } -static int r_debug_bf_attach(RDebug *dbg, int pid) { +static int rz_debug_bf_attach(RzDebug *dbg, int pid) { if (!is_io_bf (dbg)) { return false; } return true; } -static int r_debug_bf_detach(RDebug *dbg, int pid) { +static int rz_debug_bf_detach(RzDebug *dbg, int pid) { // reset vm? return true; } -static char *r_debug_bf_reg_profile(RDebug *dbg) { +static char *rz_debug_bf_reg_profile(RzDebug *dbg) { return strdup ( "=PC pc\n" "=SP esp\n" @@ -154,78 +154,78 @@ static char *r_debug_bf_reg_profile(RDebug *dbg) { ); } -static int r_debug_bf_breakpoint (struct r_bp_t *bp, RBreakpointItem *b, bool set) { - //r_io_system (dbg->iob.io, "db"); +static int rz_debug_bf_breakpoint (struct rz_bp_t *bp, RBreakpointItem *b, bool set) { + //rz_io_system (dbg->iob.io, "db"); return false; } -static bool r_debug_bf_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool rz_debug_bf_kill(RzDebug *dbg, int pid, int tid, int sig) { if (!is_io_bf (dbg)) { return false; } - RIOBdescbg *o = dbg->iob.io->desc->data; + RzIOBdescbg *o = dbg->iob.io->desc->data; if (o) { bfvm_reset (o->bfvm); } return true; } -static RList *r_debug_native_map_get(RDebug *dbg) { +static RzList *rz_debug_native_map_get(RzDebug *dbg) { if (!is_io_bf (dbg)) { return false; } - RIOBdescbg *o = dbg->iob.io->desc->data; + RzIOBdescbg *o = dbg->iob.io->desc->data; BfvmCPU *c = o->bfvm; - RList *list = r_list_newf ((RListFree)r_debug_map_free); + RzList *list = rz_list_newf ((RzListFree)rz_debug_map_free); if (!list) { return NULL; } - r_list_append (list, r_debug_map_new ( + rz_list_append (list, rz_debug_map_new ( "code", 0, 4096, 6, 0)); - r_list_append (list, r_debug_map_new ( + rz_list_append (list, rz_debug_map_new ( "memory", c->base, c->base+c->size, 6, 0)); - r_list_append (list, r_debug_map_new ( + rz_list_append (list, rz_debug_map_new ( "screen", c->screen, c->screen+c->screen_size, 6, 0)); - r_list_append (list, r_debug_map_new ( + rz_list_append (list, rz_debug_map_new ( "input", c->input, c->input+c->input_size, 6, 0)); return list; } -static int r_debug_bf_stop(RDebug *dbg) { +static int rz_debug_bf_stop(RzDebug *dbg) { if (!is_io_bf (dbg)) { return false; } - RIOBdescbg *o = dbg->iob.io->desc->data; + RzIOBdescbg *o = dbg->iob.io->desc->data; BfvmCPU *c = o->bfvm; c->breaked = true; return true; } -RDebugPlugin r_debug_plugin_bf = { +RzDebugPlugin rz_debug_plugin_bf = { .name = "bf", .arch = "bf", .license = "LGPL3", .bits = R_SYS_BITS_32 | R_SYS_BITS_64, - .step = r_debug_bf_step, - .step_over = r_debug_bf_step_over, - .cont = r_debug_bf_continue, - .contsc = r_debug_bf_continue_syscall, - .attach = &r_debug_bf_attach, - .detach = &r_debug_bf_detach, - .wait = &r_debug_bf_wait, - .stop = r_debug_bf_stop, - .kill = r_debug_bf_kill, - .breakpoint = &r_debug_bf_breakpoint, - .reg_read = &r_debug_bf_reg_read, - .reg_write = &r_debug_bf_reg_write, - .reg_profile = r_debug_bf_reg_profile, - .map_get = r_debug_native_map_get, + .step = rz_debug_bf_step, + .step_over = rz_debug_bf_step_over, + .cont = rz_debug_bf_continue, + .contsc = rz_debug_bf_continue_syscall, + .attach = &rz_debug_bf_attach, + .detach = &rz_debug_bf_detach, + .wait = &rz_debug_bf_wait, + .stop = rz_debug_bf_stop, + .kill = rz_debug_bf_kill, + .breakpoint = &rz_debug_bf_breakpoint, + .reg_read = &rz_debug_bf_reg_read, + .reg_write = &rz_debug_bf_reg_write, + .reg_profile = rz_debug_bf_reg_profile, + .map_get = rz_debug_native_map_get, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_bf, + .data = &rz_debug_plugin_bf, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_bochs.c b/librz/debug/p/debug_bochs.c similarity index 86% rename from libr/debug/p/debug_bochs.c rename to librz/debug/p/debug_bochs.c index 40db73632d..462f12f168 100644 --- a/libr/debug/p/debug_bochs.c +++ b/librz/debug/p/debug_bochs.c @@ -1,7 +1,7 @@ /* debugbochs - LGPL - Copyright 2016 - SkUaTeR */ -#include -#include +#include +#include #include static bool bCapturaRegs = true; @@ -13,12 +13,12 @@ static ut64 ripStop = 0LL; typedef struct { libbochs_t desc; -} RIOBochs; +} RzIOBochs; static libbochs_t *desc = NULL; -static bool isBochs(RDebug *dbg) { - RIODesc *d = dbg->iob.io->desc; +static bool isBochs(RzDebug *dbg) { + RzIODesc *d = dbg->iob.io->desc; if (d && d->plugin && d->plugin->name) { if (!strcmp ("bochs", d->plugin->name)) { return true; @@ -28,7 +28,7 @@ static bool isBochs(RDebug *dbg) { return false; } -static int r_debug_bochs_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { +static int rz_debug_bochs_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { char cmd[64]; char num[4]; char addr[19]; @@ -64,8 +64,8 @@ static int r_debug_bochs_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool s num[3] = 0; strncpy(addr, &desc->data[i + 28], 18); addr[18] = 0; - n = r_num_get (NULL,num); - a = r_num_get (NULL,addr); + n = rz_num_get (NULL,num); + a = rz_num_get (NULL,addr); //eprintf("parseado %x %016"PFMT64x"\n",n,a); if (a == b->addr) { break; @@ -84,7 +84,7 @@ static int r_debug_bochs_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool s return true; } -static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int rz_debug_bochs_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { char strReg[19]; char regname[4]; char strBase[19]; @@ -114,7 +114,7 @@ static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { strReg[1]='x'; strReg[18] = 0; i += 22; - val = r_num_get (NULL, strReg); + val = rz_num_get (NULL, strReg); // eprintf("parseado %s = %s valx64 = %016"PFMT64x"\n", regname, strReg,val); memcpy (&buf[pos], &val, 8); // guardamos la posicion del rip y su valor para ajustarlo al obtener el CS @@ -170,7 +170,7 @@ static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { if ((x = strstr (desc->data,s[n]))) { strncpy (&strReg[0], x+3, 7); strReg[6] = 0; - val = r_num_get (NULL, strReg); + val = rz_num_get (NULL, strReg); strncpy (regname, s[n], 2); regname[2] = 0; if ((x = strstr (x, "base="))) { @@ -209,29 +209,29 @@ static int r_debug_bochs_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return size; } -static int r_debug_bochs_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int rz_debug_bochs_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { //eprintf("bochs_reg_write\n"); return -1; } -void map_free(RDebugMap *map) { +void map_free(RzDebugMap *map) { free (map->name); free (map); } -static RList *r_debug_bochs_map_get(RDebug* dbg) { //TODO +static RzList *rz_debug_bochs_map_get(RzDebug* dbg) { //TODO if (!isBochs (dbg)) { return NULL; } //eprintf("bochs_map_getdebug:\n"); - RDebugMap *mr; - RList *list = r_list_newf ((RListFree)map_free); + RzDebugMap *mr; + RzList *list = rz_list_newf ((RzListFree)map_free); if (!list) { return NULL; } - mr = R_NEW0 (RDebugMap); + mr = R_NEW0 (RzDebugMap); if (!mr) { - r_list_free (list); + rz_list_free (list); return NULL; } mr->name = strdup ("fake"); @@ -240,11 +240,11 @@ static RList *r_debug_bochs_map_get(RDebug* dbg) { //TODO mr->size = UT32_MAX; mr->perm = 0; mr->user = 0; - r_list_append (list, mr); + rz_list_append (list, mr); return list; } -static int r_debug_bochs_step(RDebug *dbg) { +static int rz_debug_bochs_step(RzDebug *dbg) { if (!isBochs (dbg)) { return false; } @@ -255,7 +255,7 @@ static int r_debug_bochs_step(RDebug *dbg) { return true; } -static int r_debug_bochs_continue(RDebug *dbg, int pid, int tid, int sig) { +static int rz_debug_bochs_continue(RzDebug *dbg, int pid, int tid, int sig) { //eprintf ("bochs_continue:\n"); bochs_send_cmd (desc, "c", false); bCapturaRegs = true; @@ -269,7 +269,7 @@ static void bochs_debug_break(void *u) { bBreak = true; } -static int r_debug_bochs_wait(RDebug *dbg, int pid) { +static int rz_debug_bochs_wait(RzDebug *dbg, int pid) { if (!isBochs (dbg)) { return false; } @@ -283,7 +283,7 @@ static int r_debug_bochs_wait(RDebug *dbg, int pid) { if (bStep) { bStep = false; } else { - r_cons_break_push (bochs_debug_break, dbg); + rz_cons_break_push (bochs_debug_break, dbg); i = 500; do { bochs_wait (desc); @@ -304,7 +304,7 @@ static int r_debug_bochs_wait(RDebug *dbg, int pid) { break; } } while(1); - r_cons_break_pop (); + rz_cons_break_pop (); } //eprintf ("bochs_wait: loop done\n"); // Next at t=394241428 @@ -317,7 +317,7 @@ static int r_debug_bochs_wait(RDebug *dbg, int pid) { strncpy (strIP, ini+1, len); strIP[len] = 0; //eprintf(" parada EIP = %s\n",strIP); - ripStop = r_num_get (NULL, strIP); + ripStop = rz_num_get (NULL, strIP); } } } @@ -326,22 +326,22 @@ static int r_debug_bochs_wait(RDebug *dbg, int pid) { return true; } -static int r_debug_bochs_stop(RDebug *dbg) { +static int rz_debug_bochs_stop(RzDebug *dbg) { //eprintf("bochs_stop:\n"); - //RIOBdescbg *o = dbg->iob.io->desc->data; + //RzIOBdescbg *o = dbg->iob.io->desc->data; //BfvmCPU *c = o->bfvm; //c->breaked = true; return true; } -static int r_debug_bochs_attach(RDebug *dbg, int pid) { - RIODesc *d = dbg->iob.io->desc; +static int rz_debug_bochs_attach(RzDebug *dbg, int pid) { + RzIODesc *d = dbg->iob.io->desc; //eprintf ("bochs_attach:\n"); dbg->swstep = false; if (d && d->plugin && d->plugin->name && d->data) { if (!strcmp ("bochs", d->plugin->name)) { - RIOBochs *g = d->data; - //int arch = r_sys_arch_id (dbg->arch); + RzIOBochs *g = d->data; + //int arch = rz_sys_arch_id (dbg->arch); // int bits = dbg->anal->bits; if (( desc = &g->desc )) { eprintf("bochs attach: ok\n"); @@ -355,13 +355,13 @@ static int r_debug_bochs_attach(RDebug *dbg, int pid) { return true; } -static int r_debug_bochs_detach(RDebug *dbg, int pid) { +static int rz_debug_bochs_detach(RzDebug *dbg, int pid) { //eprintf ("bochs_detach:\n"); free (saveRegs); return true; } -static const char *r_debug_bochs_reg_profile(RDebug *dbg) { +static const char *rz_debug_bochs_reg_profile(RzDebug *dbg) { int bits = dbg->anal->bits; if (bits == 16 || bits == 32 || bits == 64) { @@ -543,29 +543,29 @@ static const char *r_debug_bochs_reg_profile(RDebug *dbg) { return NULL; } -RDebugPlugin r_debug_plugin_bochs = { +RzDebugPlugin rz_debug_plugin_bochs = { .name = "bochs", .license = "LGPL3", .arch = "x86", .bits = R_SYS_BITS_16 | R_SYS_BITS_32 | R_SYS_BITS_64, - .step = r_debug_bochs_step, - .cont = r_debug_bochs_continue, - .attach = &r_debug_bochs_attach, - .detach = &r_debug_bochs_detach, + .step = rz_debug_bochs_step, + .cont = rz_debug_bochs_continue, + .attach = &rz_debug_bochs_attach, + .detach = &rz_debug_bochs_detach, .canstep = 1, - .stop = &r_debug_bochs_stop, - .wait = &r_debug_bochs_wait, - .map_get = r_debug_bochs_map_get, - .breakpoint = r_debug_bochs_breakpoint, - .reg_read = &r_debug_bochs_reg_read, - .reg_write = &r_debug_bochs_reg_write, - .reg_profile = (void *)r_debug_bochs_reg_profile, + .stop = &rz_debug_bochs_stop, + .wait = &rz_debug_bochs_wait, + .map_get = rz_debug_bochs_map_get, + .breakpoint = rz_debug_bochs_breakpoint, + .reg_read = &rz_debug_bochs_reg_read, + .reg_write = &rz_debug_bochs_reg_write, + .reg_profile = (void *)rz_debug_bochs_reg_profile, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_bochs, + .data = &rz_debug_plugin_bochs, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_esil.c b/librz/debug/p/debug_esil.c similarity index 65% rename from libr/debug/p/debug_esil.c rename to librz/debug/p/debug_esil.c index b4a6d366bd..be32896300 100644 --- a/libr/debug/p/debug_esil.c +++ b/librz/debug/p/debug_esil.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2013-2017 pancake */ // r2 -Desil ls -#include -#include +#include +#include #if 0 -static int is_io_esil(RDebug *dbg) { - RIODesc *d = dbg->iob.io->desc; +static int is_io_esil(RzDebug *dbg) { + RzIODesc *d = dbg->iob.io->desc; if (d && d->plugin && d->plugin->name) if (!strcmp ("esil", d->plugin->name)) return true; @@ -14,60 +14,60 @@ static int is_io_esil(RDebug *dbg) { } #endif -static int __esil_step_over(RDebug *dbg) { +static int __esil_step_over(RzDebug *dbg) { eprintf ("TODO: ESIL STEP OVER\n"); return true; } -static int __esil_step(RDebug *dbg) { +static int __esil_step(RzDebug *dbg) { int oplen; ut8 buf[64]; ut64 pc = 0LL; // getreg("pc") - RAnalOp op = {0}; + RzAnalOp op = {0}; - r_debug_reg_sync(dbg, R_REG_TYPE_GPR, false); - pc = r_debug_reg_get (dbg, "PC"); + rz_debug_reg_sync(dbg, R_REG_TYPE_GPR, false); + pc = rz_debug_reg_get (dbg, "PC"); eprintf ("PC = 0x%" PFMT64x "\n", pc); /// XXX. hack to trick vaddr issue //pc = 0x100001478; //memset (buf, 0, sizeof (buf)); dbg->iob.read_at (dbg->iob.io, pc, buf, 64); eprintf ("READ 0x%08"PFMT64x" %02x %02x %02x\n", pc, buf[0], buf[1], buf[2]); - oplen = r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_ESIL); + oplen = rz_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_ESIL); if (oplen > 0) { if (*R_STRBUF_SAFEGET (&op.esil)) { eprintf ("ESIL: %s\n", R_STRBUF_SAFEGET (&op.esil)); - r_anal_esil_parse (dbg->anal->esil, R_STRBUF_SAFEGET (&op.esil)); + rz_anal_esil_parse (dbg->anal->esil, R_STRBUF_SAFEGET (&op.esil)); } } - r_anal_op_fini (&op); + rz_anal_op_fini (&op); eprintf ("TODO: ESIL STEP\n"); return true; } -static int __esil_init(RDebug *dbg) { +static int __esil_init(RzDebug *dbg) { dbg->tid = dbg->pid = 1; // aeim // aei return true; } -static int __esil_continue(RDebug *dbg, int pid, int tid, int sig) { +static int __esil_continue(RzDebug *dbg, int pid, int tid, int sig) { eprintf ("TODO continue\n"); return true; } -static int __esil_continue_syscall(RDebug *dbg, int pid, int num) { +static int __esil_continue_syscall(RzDebug *dbg, int pid, int num) { eprintf ("TODO: esil continue until syscall\n"); return true; } -static int __esil_wait(RDebug *dbg, int pid) { +static int __esil_wait(RzDebug *dbg, int pid) { /* do nothing */ return true; } -static int __esil_attach(RDebug *dbg, int pid) { +static int __esil_attach(RzDebug *dbg, int pid) { eprintf ("OK attach\n"); return true; #if 0 @@ -75,7 +75,7 @@ static int __esil_attach(RDebug *dbg, int pid) { return false; #endif #if 0 - RIOBdescbg *o; + RzIOBdescbg *o; o = dbg->iob.io->desc->data; eprintf ("base = %llx\n", o->bfvm->base); eprintf ("screen = %llx\n", o->bfvm->screen); @@ -84,12 +84,12 @@ eprintf ("input = %llx\n", o->bfvm->input); return true; } -static int __esil_detach(RDebug *dbg, int pid) { +static int __esil_detach(RzDebug *dbg, int pid) { // reset vm? return true; } -static char *__esil_reg_profile(RDebug *dbg) { +static char *__esil_reg_profile(RzDebug *dbg) { if (!strcmp (dbg->arch, "bf")) { return strdup ( "=PC pc\n" @@ -107,34 +107,34 @@ static char *__esil_reg_profile(RDebug *dbg) { "gpr memi .32 32 0\n" ); } - return r_anal_get_reg_profile (dbg->anal); + return rz_anal_get_reg_profile (dbg->anal); } static int __esil_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { - //r_io_system (dbg->iob.io, "db"); + //rz_io_system (dbg->iob.io, "db"); return false; } -static bool __esil_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool __esil_kill(RzDebug *dbg, int pid, int tid, int sig) { // TODO: ESIL reset return true; } -static int __esil_stop(RDebug *dbg) { +static int __esil_stop(RzDebug *dbg) { eprintf ("ESIL: stop\n"); return true; } -static int __reg_read (RDebug *dbg, int type, ut8 *buf, int size) { +static int __reg_read (RzDebug *dbg, int type, ut8 *buf, int size) { int sz; /* do nothing */ - ut8 *bytes = r_reg_get_bytes (dbg->reg, type, &sz); + ut8 *bytes = rz_reg_get_bytes (dbg->reg, type, &sz); memcpy (buf, bytes, R_MIN (size, sz)); free (bytes); return size; } -RDebugPlugin r_debug_plugin_esil = { +RzDebugPlugin rz_debug_plugin_esil = { .name = "esil", .license = "LGPL3", .arch = "any", // TODO: exception! @@ -155,9 +155,9 @@ RDebugPlugin r_debug_plugin_esil = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_esil, + .data = &rz_debug_plugin_esil, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_gdb.c b/librz/debug/p/debug_gdb.c similarity index 72% rename from libr/debug/p/debug_gdb.c rename to librz/debug/p/debug_gdb.c index 5b618b5d16..d45da8723f 100644 --- a/libr/debug/p/debug_gdb.c +++ b/librz/debug/p/debug_gdb.c @@ -1,34 +1,34 @@ /* radare - LGPL - Copyright 2009-2018 - pancake, defragger */ -#include -#include -#include +#include +#include +#include #include #include typedef struct { libgdbr_t desc; -} RIOGdb; +} RzIOGdb; #define UNKNOWN (-1) #define UNSUPPORTED 0 #define SUPPORTED 1 -static RIOGdb ** origriogdb = NULL; +static RzIOGdb ** origriogdb = NULL; static libgdbr_t *desc = NULL; static ut8* reg_buf = NULL; static int buf_size = 0; static int support_sw_bp = UNKNOWN; static int support_hw_bp = UNKNOWN; -static int r_debug_gdb_attach(RDebug *dbg, int pid); -static void check_connection (RDebug *dbg) { +static int rz_debug_gdb_attach(RzDebug *dbg, int pid); +static void check_connection (RzDebug *dbg) { if (!desc) { - r_debug_gdb_attach (dbg, -1); + rz_debug_gdb_attach (dbg, -1); } } -static int r_debug_gdb_step(RDebug *dbg) { +static int rz_debug_gdb_step(RzDebug *dbg) { check_connection (dbg); if (!desc) { return R_DEBUG_REASON_UNKNOWN; @@ -37,23 +37,23 @@ static int r_debug_gdb_step(RDebug *dbg) { return true; } -static RList* r_debug_gdb_threads(RDebug *dbg, int pid) { - RList *list; +static RzList* rz_debug_gdb_threads(RzDebug *dbg, int pid) { + RzList *list; if ((list = gdbr_threads_list (desc, pid))) { - list->free = (RListFree) &r_debug_pid_free; + list->free = (RzListFree) &rz_debug_pid_free; } return list; } -static RList* r_debug_gdb_pids(RDebug *dbg, int pid) { - RList *list; +static RzList* rz_debug_gdb_pids(RzDebug *dbg, int pid) { + RzList *list; if ((list = gdbr_pids_list (desc, pid))) { - list->free = (RListFree) &r_debug_pid_free; + list->free = (RzListFree) &rz_debug_pid_free; } return list; } -static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int rz_debug_gdb_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { int copy_size; int buflen = 0; check_connection (dbg); @@ -65,9 +65,9 @@ static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return -1; } // read the len of the current area - free (r_reg_get_bytes (dbg->reg, type, &buflen)); + free (rz_reg_get_bytes (dbg->reg, type, &buflen)); if (size < desc->data_len) { - eprintf ("r_debug_gdb_reg_read: small buffer %d vs %d\n", + eprintf ("rz_debug_gdb_reg_read: small buffer %d vs %d\n", (int)size, (int)desc->data_len); // return -1; } @@ -106,25 +106,25 @@ static int r_debug_gdb_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return desc->data_len; } -static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO +static RzList *rz_debug_gdb_map_get(RzDebug* dbg) { //TODO check_connection (dbg); if (!desc || desc->pid <= 0) { return NULL; } - RList *retlist = NULL; + RzList *retlist = NULL; if (desc->get_baddr) { desc->get_baddr = false; ut64 baddr; if ((baddr = gdbr_get_baddr (desc)) != UINT64_MAX) { - if (!(retlist = r_list_new ())) { + if (!(retlist = rz_list_new ())) { return NULL; } - RDebugMap *map; - if (!(map = r_debug_map_new ("", baddr, baddr, R_PERM_RX, 0))) { - r_list_free (retlist); + RzDebugMap *map; + if (!(map = rz_debug_map_new ("", baddr, baddr, R_PERM_RX, 0))) { + rz_list_free (retlist); return NULL; } - r_list_append (retlist, map); + rz_list_append (retlist, map); return retlist; } } @@ -165,7 +165,7 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO char *ptr, *pos_1; size_t line_len; char name[1024], region1[100], region2[100], perms[5]; - RDebugMap *map = NULL; + RzDebugMap *map = NULL; region1[0] = region2[0] = '0'; region1[1] = region2[1] = 'x'; if (!(ptr = strtok ((char*) buf, "\n"))) { @@ -173,7 +173,7 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO free (buf); return NULL; } - if (!(retlist = r_list_new ())) { + if (!(retlist = rz_list_new ())) { gdbr_close_file (desc); free (buf); return NULL; @@ -197,7 +197,7 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO __func__, path, buf); gdbr_close_file (desc); free (buf); - r_list_free (retlist); + rz_list_free (retlist); return NULL; } if (!(pos_1 = strchr (®ion1[2], '-'))) { @@ -218,21 +218,21 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO case 's': map_is_shared = true; break; } } - map_start = r_num_get (NULL, region1); - map_end = r_num_get (NULL, region2); + map_start = rz_num_get (NULL, region1); + map_end = rz_num_get (NULL, region2); if (map_start == map_end || map_end == 0) { eprintf ("%s: ignoring invalid map size: %s - %s\n", __func__, region1, region2); ptr = strtok (NULL, "\n"); continue; } - if (!(map = r_debug_map_new (name, map_start, map_end, perm, 0))) { + if (!(map = rz_debug_map_new (name, map_start, map_end, perm, 0))) { break; } map->offset = offset; map->shared = map_is_shared; map->file = strdup (name); - r_list_append (retlist, map); + rz_list_append (retlist, map); ptr = strtok (NULL, "\n"); } gdbr_close_file (desc); @@ -240,20 +240,20 @@ static RList *r_debug_gdb_map_get(RDebug* dbg) { //TODO return retlist; } -static RList* r_debug_gdb_modules_get(RDebug *dbg) { +static RzList* rz_debug_gdb_modules_get(RzDebug *dbg) { char *lastname = NULL; - RDebugMap *map; - RListIter *iter, *iter2; - RList *list, *last; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; bool must_delete; - if (!(list = r_debug_gdb_map_get (dbg))) { + if (!(list = rz_debug_gdb_map_get (dbg))) { return NULL; } - if (!(last = r_list_newf ((RListFree)r_debug_map_free))) { - r_list_free (list); + if (!(last = rz_list_newf ((RzListFree)rz_debug_map_free))) { + rz_list_free (list); return NULL; } - r_list_foreach_safe (list, iter, iter2, map) { + rz_list_foreach_safe (list, iter, iter2, map) { const char *file = map->file; if (!map->file) { file = map->file = strdup (map->name); @@ -265,20 +265,20 @@ static RList* r_debug_gdb_modules_get(RDebug *dbg) { } } if (must_delete) { - r_list_delete (list, iter); + rz_list_delete (list, iter); } else { - r_list_append (last, map); + rz_list_append (last, map); free (lastname); lastname = strdup (file); } } list->free = NULL; free (lastname); - r_list_free (list); + rz_list_free (list); return last; } -static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int rz_debug_gdb_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { check_connection (dbg); if (!desc) { return R_DEBUG_REASON_UNKNOWN; @@ -289,14 +289,14 @@ static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size } int buflen = 0; int bits = dbg->anal->bits; - const char *pcname = r_reg_get_name (dbg->anal->reg, R_REG_NAME_PC); - RRegItem *reg = r_reg_get (dbg->anal->reg, pcname, 0); + const char *pcname = rz_reg_get_name (dbg->anal->reg, R_REG_NAME_PC); + RzRegItem *reg = rz_reg_get (dbg->anal->reg, pcname, 0); if (reg) { if (dbg->anal->bits != reg->size) { bits = reg->size; } } - free (r_reg_get_bytes (dbg->reg, type, &buflen)); + free (rz_reg_get_bytes (dbg->reg, type, &buflen)); // some implementations of the gdb protocol are acting weird. // so winedbg is not able to write registers through the packet // and also it does not return the whole gdb register profile after @@ -312,12 +312,12 @@ static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size memset (new_buf + buf_size, 0, buflen - buf_size); } - RRegItem* current = NULL; + RzRegItem* current = NULL; // We default to little endian if there's no way to get the configuration, // since this was the behaviour prior to the change. - RRegArena *arena = dbg->reg->regset[type].arena; + RzRegArena *arena = dbg->reg->regset[type].arena; for (;;) { - current = r_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits); + current = rz_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits); if (!current) { break; } @@ -326,7 +326,7 @@ static int r_debug_gdb_reg_write(RDebug *dbg, int type, const ut8 *buf, int size return true; } -static int r_debug_gdb_continue(RDebug *dbg, int pid, int tid, int sig) { +static int rz_debug_gdb_continue(RzDebug *dbg, int pid, int tid, int sig) { check_connection (dbg); if (!desc) { return R_DEBUG_REASON_UNKNOWN; @@ -341,7 +341,7 @@ static int r_debug_gdb_continue(RDebug *dbg, int pid, int tid, int sig) { return desc->tid; } -static RDebugReasonType r_debug_gdb_wait(RDebug *dbg, int pid) { +static RzDebugReasonType rz_debug_gdb_wait(RzDebug *dbg, int pid) { check_connection (dbg); if (!desc) { return R_DEBUG_REASON_UNKNOWN; @@ -366,19 +366,19 @@ static RDebugReasonType r_debug_gdb_wait(RDebug *dbg, int pid) { return desc->stop_reason.reason; } -static int r_debug_gdb_attach(RDebug *dbg, int pid) { - RIODesc *d = dbg->iob.io->desc; +static int rz_debug_gdb_attach(RzDebug *dbg, int pid) { + RzIODesc *d = dbg->iob.io->desc; // TODO: the core must update the dbg.swstep config var when this var is changed dbg->swstep = false; //eprintf ("XWJSTEP TOFALSE\n"); if (d && d->plugin && d->plugin->name && d->data) { if (!strcmp ("gdb", d->plugin->name)) { - RIOGdb *g = d->data; - origriogdb = (RIOGdb **)&d->data; //TODO bit of a hack, please improve + RzIOGdb *g = d->data; + origriogdb = (RzIOGdb **)&d->data; //TODO bit of a hack, please improve support_sw_bp = UNKNOWN; support_hw_bp = UNKNOWN; desc = &g->desc; - int arch = r_sys_arch_id (dbg->arch); + int arch = rz_sys_arch_id (dbg->arch); int bits = dbg->anal->bits; gdbr_set_architecture (desc, arch, bits); } else { @@ -388,7 +388,7 @@ static int r_debug_gdb_attach(RDebug *dbg, int pid) { return true; } -static int r_debug_gdb_detach(RDebug *dbg, int pid) { +static int rz_debug_gdb_detach(RzDebug *dbg, int pid) { int ret = 0; if (pid <= 0 || !desc->stub_features.multiprocess) { @@ -402,11 +402,11 @@ static int r_debug_gdb_detach(RDebug *dbg, int pid) { return ret; } -static const char *r_debug_gdb_reg_profile(RDebug *dbg) { +static const char *rz_debug_gdb_reg_profile(RzDebug *dbg) { check_connection (dbg); - int arch = r_sys_arch_id (dbg->arch); + int arch = rz_sys_arch_id (dbg->arch); int bits = dbg->anal->bits; - // XXX This happens when radare2 set dbg.backend before opening io_gdb + // XXX This happens when rizin set dbg.backend before opening io_gdb if (!desc) { return gdbr_get_reg_profile (arch, bits); } @@ -419,14 +419,14 @@ static const char *r_debug_gdb_reg_profile(RDebug *dbg) { return NULL; } -static int r_debug_gdb_set_reg_profile(const char *str) { +static int rz_debug_gdb_set_reg_profile(const char *str) { if (desc && str) { return gdbr_set_reg_profile (desc, str); } return false; } -static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { +static int rz_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { int ret = 0, bpsize; if (!b) { return false; @@ -473,7 +473,7 @@ static int r_debug_gdb_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set return !ret; } -static bool r_debug_gdb_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool rz_debug_gdb_kill(RzDebug *dbg, int pid, int tid, int sig) { // TODO kill based on pid and signal if (sig != 0) { if (gdbr_kill (desc) < 0) { @@ -483,7 +483,7 @@ static bool r_debug_gdb_kill(RDebug *dbg, int pid, int tid, int sig) { return true; } -static int r_debug_gdb_select(RDebug *dbg, int pid, int tid) { +static int rz_debug_gdb_select(RzDebug *dbg, int pid, int tid) { if (!desc || !*origriogdb) { desc = NULL; //TODO hacky fix, please improve. I would suggest using a **desc instead of a *desc, so it is automatically updated return false; @@ -492,23 +492,23 @@ static int r_debug_gdb_select(RDebug *dbg, int pid, int tid) { return gdbr_select (desc, pid, tid) >= 0; } -static RDebugInfo* r_debug_gdb_info(RDebug *dbg, const char *arg) { - RDebugInfo *rdi; - if (!(rdi = R_NEW0 (RDebugInfo))) { +static RzDebugInfo* rz_debug_gdb_info(RzDebug *dbg, const char *arg) { + RzDebugInfo *rdi; + if (!(rdi = R_NEW0 (RzDebugInfo))) { return NULL; } - RList *th_list; + RzList *th_list; bool list_alloc = false; if (dbg->threads) { th_list = dbg->threads; } else { - th_list = r_debug_gdb_threads (dbg, dbg->pid); + th_list = rz_debug_gdb_threads (dbg, dbg->pid); list_alloc = true; } - RDebugPid *th; - RListIter *it; + RzDebugPid *th; + RzListIter *it; bool found = false; - r_list_foreach (th_list, it, th) { + rz_list_foreach (th_list, it, th) { if (th->pid == dbg->pid) { found = true; break; @@ -525,50 +525,50 @@ static RDebugInfo* r_debug_gdb_info(RDebug *dbg, const char *arg) { rdi->signum = desc->stop_reason.signum; } if (list_alloc) { - r_list_free (th_list); + rz_list_free (th_list); } return rdi; } #include "native/bt.c" -static RList* r_debug_gdb_frames(RDebug *dbg, ut64 at) { - return r_debug_native_frames (dbg, at); +static RzList* rz_debug_gdb_frames(RzDebug *dbg, ut64 at) { + return rz_debug_native_frames (dbg, at); } -RDebugPlugin r_debug_plugin_gdb = { +RzDebugPlugin rz_debug_plugin_gdb = { .name = "gdb", /* TODO: Add support for more architectures here */ .license = "LGPL3", .arch = "x86,arm,sh,mips,avr,lm32,v850,ba2", .bits = R_SYS_BITS_16 | R_SYS_BITS_32 | R_SYS_BITS_64, - .step = r_debug_gdb_step, - .cont = r_debug_gdb_continue, - .attach = &r_debug_gdb_attach, - .detach = &r_debug_gdb_detach, - .threads = &r_debug_gdb_threads, - .pids = &r_debug_gdb_pids, + .step = rz_debug_gdb_step, + .cont = rz_debug_gdb_continue, + .attach = &rz_debug_gdb_attach, + .detach = &rz_debug_gdb_detach, + .threads = &rz_debug_gdb_threads, + .pids = &rz_debug_gdb_pids, .canstep = 1, - .wait = &r_debug_gdb_wait, - .map_get = r_debug_gdb_map_get, - .modules_get = r_debug_gdb_modules_get, - .breakpoint = &r_debug_gdb_breakpoint, - .reg_read = &r_debug_gdb_reg_read, - .reg_write = &r_debug_gdb_reg_write, - .reg_profile = (void *)r_debug_gdb_reg_profile, - .set_reg_profile = &r_debug_gdb_set_reg_profile, - .kill = &r_debug_gdb_kill, - .info = &r_debug_gdb_info, - .select = &r_debug_gdb_select, - .frames = &r_debug_gdb_frames, - //.bp_write = &r_debug_gdb_bp_write, - //.bp_read = &r_debug_gdb_bp_read, + .wait = &rz_debug_gdb_wait, + .map_get = rz_debug_gdb_map_get, + .modules_get = rz_debug_gdb_modules_get, + .breakpoint = &rz_debug_gdb_breakpoint, + .reg_read = &rz_debug_gdb_reg_read, + .reg_write = &rz_debug_gdb_reg_write, + .reg_profile = (void *)rz_debug_gdb_reg_profile, + .set_reg_profile = &rz_debug_gdb_set_reg_profile, + .kill = &rz_debug_gdb_kill, + .info = &rz_debug_gdb_info, + .select = &rz_debug_gdb_select, + .frames = &rz_debug_gdb_frames, + //.bp_write = &rz_debug_gdb_bp_write, + //.bp_read = &rz_debug_gdb_bp_read, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_gdb, + .data = &rz_debug_plugin_gdb, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_io.c b/librz/debug/p/debug_io.c similarity index 69% rename from libr/debug/p/debug_io.c rename to librz/debug/p/debug_io.c index 7bdc5ccb14..a928c393b5 100644 --- a/libr/debug/p/debug_io.c +++ b/librz/debug/p/debug_io.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2016-2018 pancake */ -#include -#include -#include +#include +#include +#include -static int __io_step(RDebug *dbg) { +static int __io_step(RzDebug *dbg) { free (dbg->iob.system (dbg->iob.io, "ds")); return true; } -static int __io_step_over(RDebug *dbg) { +static int __io_step_over(RzDebug *dbg) { free (dbg->iob.system (dbg->iob.io, "dso")); return true; } -static RList *__io_maps(RDebug *dbg) { - RList *list = r_list_new (); +static RzList *__io_maps(RzDebug *dbg) { + RzList *list = rz_list_new (); char *str = dbg->iob.system (dbg->iob.io, "dm"); if (!str) { - r_list_free (list); + rz_list_free (list); return NULL; } char *ostr = str; @@ -51,8 +51,8 @@ static RList *__io_maps(RDebug *dbg) { sscanf (str, "0x%"PFMT64x" - 0x%"PFMT64x" %s %s", &map_start, &map_end, perm, name); if (map_end != 0LL) { - RDebugMap *map = r_debug_map_new (name, map_start, map_end, r_str_rwx (perm), 0); - r_list_append (list, map); + RzDebugMap *map = rz_debug_map_new (name, map_start, map_end, rz_str_rwx (perm), 0); + rz_list_append (list, map); } str = nl + 1; } else { @@ -60,54 +60,54 @@ static RList *__io_maps(RDebug *dbg) { } } free (ostr); - r_cons_reset(); + rz_cons_reset(); return list; } -static int __io_wait(RDebug *dbg, int pid) { +static int __io_wait(RzDebug *dbg, int pid) { /* do nothing */ return true; } -static int __io_attach(RDebug *dbg, int pid) { +static int __io_attach(RzDebug *dbg, int pid) { return true; } // "drp" register profile -static char *__io_reg_profile(RDebug *dbg) { - r_cons_push (); +static char *__io_reg_profile(RzDebug *dbg) { + rz_cons_push (); char *drp = dbg->iob.system (dbg->iob.io, "drp"); if (drp) { return drp; } - const char *buf = r_cons_get_buffer (); + const char *buf = rz_cons_get_buffer (); if (buf && *buf) { char *ret = strdup (buf); - r_cons_pop (); + rz_cons_pop (); return ret; } - return r_anal_get_reg_profile (dbg->anal); + return rz_anal_get_reg_profile (dbg->anal); } // "dr8" read register state -static int __reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int __reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { char *dr8 = dbg->iob.system (dbg->iob.io, "dr8"); if (!dr8) { - const char *fb = r_cons_get_buffer (); + const char *fb = rz_cons_get_buffer (); if (!fb || !*fb) { eprintf ("debug.io: Failed to get dr8 from io\n"); return -1; } dr8 = strdup (fb); - r_cons_reset (); + rz_cons_reset (); } ut8 *bregs = calloc (1, strlen (dr8)); if (!bregs) { free (dr8); return -1; } - r_str_trim ((char *)bregs); - int sz = r_hex_str2bin (dr8, bregs); + rz_str_trim ((char *)bregs); + int sz = rz_hex_str2bin (dr8, bregs); if (sz > 0) { memcpy (buf, bregs, R_MIN (size, sz)); free (bregs); @@ -122,21 +122,21 @@ static int __reg_read(RDebug *dbg, int type, ut8 *buf, int size) { } // "dc" continue execution -static int __io_continue(RDebug *dbg, int pid, int tid, int sig) { +static int __io_continue(RzDebug *dbg, int pid, int tid, int sig) { dbg->iob.system (dbg->iob.io, "dc"); - r_cons_flush (); + rz_cons_flush (); return true; } // "dk" send kill signal -static bool __io_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool __io_kill(RzDebug *dbg, int pid, int tid, int sig) { const char *cmd = sdb_fmt ("dk %d", sig); dbg->iob.system (dbg->iob.io, cmd); - r_cons_flush (); + rz_cons_flush (); return true; } -RDebugPlugin r_debug_plugin_io = { +RzDebugPlugin rz_debug_plugin_io = { .name = "io", .license = "MIT", .arch = "any", // TODO: exception! @@ -161,9 +161,9 @@ RDebugPlugin r_debug_plugin_io = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_io, + .data = &rz_debug_plugin_io, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_native.c b/librz/debug/p/debug_native.c similarity index 71% rename from libr/debug/p/debug_native.c rename to librz/debug/p/debug_native.c index 0226e240e2..ab942c3343 100644 --- a/libr/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #if DEBUGGER #include "native/drx.c" // x86 specific -#include "r_cons.h" +#include "rz_cons.h" -static int r_debug_native_continue (RDebug *dbg, int pid, int tid, int sig); -static int r_debug_native_reg_read (RDebug *dbg, int type, ut8 *buf, int size); -static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int size); +static int rz_debug_native_continue (RzDebug *dbg, int pid, int tid, int sig); +static int rz_debug_native_reg_read (RzDebug *dbg, int type, ut8 *buf, int size); +static int rz_debug_native_reg_write (RzDebug *dbg, int type, const ut8* buf, int size); #include "native/bt.c" @@ -35,8 +35,8 @@ static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int //#include #include "native/windows/windows_debug.h" // TODO: Move these onto windows.h? -R_API RList *r_w32_dbg_modules(RDebug *); //ugly! -R_API RList *r_w32_dbg_maps(RDebug *); +RZ_API RzList *rz_w32_dbg_modules(RzDebug *); //ugly! +RZ_API RzList *rz_w32_dbg_maps(RzDebug *); #define R_DEBUG_REG_T CONTEXT #ifdef NTSTATUS #undef NTSTATUS @@ -92,7 +92,7 @@ R_API RList *r_w32_dbg_maps(RDebug *); #if DEBUGGER #if !__WINDOWS__ && !(__linux__ && !defined(WAIT_ON_ALL_CHILDREN)) -static int r_debug_handle_signals(RDebug *dbg) { +static int rz_debug_handle_signals(RzDebug *dbg) { #if __KFBSD__ return bsd_handle_signals (dbg); #else @@ -104,7 +104,7 @@ static int r_debug_handle_signals(RDebug *dbg) { //this is temporal #if __APPLE__ || __linux__ -static char *r_debug_native_reg_profile (RDebug *dbg) { +static char *rz_debug_native_reg_profile (RzDebug *dbg) { #if __APPLE__ return xnu_reg_profile (dbg); #elif __linux__ @@ -116,7 +116,7 @@ static char *r_debug_native_reg_profile (RDebug *dbg) { #include "native/reg.c" // x86 specific #endif -static int r_debug_native_step (RDebug *dbg) { +static int rz_debug_native_step (RzDebug *dbg) { #if __APPLE__ return xnu_step (dbg); #elif __WINDOWS__ @@ -134,7 +134,7 @@ static int r_debug_native_step (RDebug *dbg) { } // return thread id -static int r_debug_native_attach (RDebug *dbg, int pid) { +static int rz_debug_native_attach (RzDebug *dbg, int pid) { #if 0 if (!dbg || pid == dbg->pid) return dbg->tid; @@ -160,7 +160,7 @@ static int r_debug_native_attach (RDebug *dbg, int pid) { #endif } -static int r_debug_native_detach (RDebug *dbg, int pid) { +static int rz_debug_native_detach (RzDebug *dbg, int pid) { #if __APPLE__ return xnu_detach (dbg, pid); #elif __WINDOWS__ @@ -168,11 +168,11 @@ static int r_debug_native_detach (RDebug *dbg, int pid) { #elif __BSD__ return ptrace (PT_DETACH, pid, NULL, 0); #else - return r_debug_ptrace (dbg, PTRACE_DETACH, pid, NULL, (r_ptrace_data_t)(size_t)0); + return rz_debug_ptrace (dbg, PTRACE_DETACH, pid, NULL, (rz_ptrace_data_t)(size_t)0); #endif } -static int r_debug_native_select(RDebug *dbg, int pid, int tid) { +static int rz_debug_native_select(RzDebug *dbg, int pid, int tid) { #if __WINDOWS__ return w32_select (dbg, pid, tid); #elif __linux__ @@ -182,13 +182,13 @@ static int r_debug_native_select(RDebug *dbg, int pid, int tid) { #endif } -static int r_debug_native_continue_syscall (RDebug *dbg, int pid, int num) { +static int rz_debug_native_continue_syscall (RzDebug *dbg, int pid, int num) { // XXX: num is ignored #if __linux__ linux_set_options (dbg, pid); - return r_debug_ptrace (dbg, PTRACE_SYSCALL, pid, 0, 0); + return rz_debug_ptrace (dbg, PTRACE_SYSCALL, pid, 0, 0); #elif __BSD__ - ut64 pc = r_debug_reg_get (dbg, "PC"); + ut64 pc = rz_debug_reg_get (dbg, "PC"); errno = 0; return ptrace (PTRACE_SYSCALL, pid, (void*)(size_t)pc, 0) == 0; #else @@ -199,13 +199,13 @@ static int r_debug_native_continue_syscall (RDebug *dbg, int pid, int num) { #if !__WINDOWS__ && !__APPLE__ && !__BSD__ /* Callback to trigger SIGINT signal */ -static void interrupt_process(RDebug *dbg) { - r_debug_kill (dbg, dbg->pid, dbg->tid, SIGINT); - r_cons_break_pop (); +static void interrupt_process(RzDebug *dbg) { + rz_debug_kill (dbg, dbg->pid, dbg->tid, SIGINT); + rz_cons_break_pop (); } #endif -static int r_debug_native_stop(RDebug *dbg) { +static int rz_debug_native_stop(RzDebug *dbg) { #if __linux__ // Stop all running threads except the thread reported by waitpid return linux_stop_threads (dbg, dbg->reason.tid); @@ -216,7 +216,7 @@ static int r_debug_native_stop(RDebug *dbg) { /* TODO: specify thread? */ /* TODO: must return true/false */ -static int r_debug_native_continue(RDebug *dbg, int pid, int tid, int sig) { +static int rz_debug_native_continue(RzDebug *dbg, int pid, int tid, int sig) { #if __APPLE__ bool ret = xnu_continue (dbg, pid, tid, sig); if (!ret) { @@ -227,7 +227,7 @@ static int r_debug_native_continue(RDebug *dbg, int pid, int tid, int sig) { return w32_continue (dbg, pid, tid, sig); #elif __BSD__ void *data = (void*)(size_t)((sig != -1) ? sig : dbg->reason.signum); - ut64 pc = r_debug_reg_get (dbg, "PC"); + ut64 pc = rz_debug_reg_get (dbg, "PC"); return ptrace (PTRACE_CONT, pid, (void*)(size_t)pc, (int)(size_t)data) == 0; #else int contsig = dbg->reason.signum; @@ -238,22 +238,22 @@ static int r_debug_native_continue(RDebug *dbg, int pid, int tid, int sig) { } /* SIGINT handler for attached processes: dbg.consbreak (disabled by default) */ if (dbg->consbreak) { - r_cons_break_push ((RConsBreak)interrupt_process, dbg); + rz_cons_break_push ((RzConsBreak)interrupt_process, dbg); } if (dbg->continue_all_threads && dbg->n_threads && dbg->threads) { - RDebugPid *th; - RListIter *it; - r_list_foreach (dbg->threads, it, th) { - ret = r_debug_ptrace (dbg, PTRACE_CONT, th->pid, 0, 0); + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { + ret = rz_debug_ptrace (dbg, PTRACE_CONT, th->pid, 0, 0); if (ret) { eprintf ("Error: (%d) is running or dead.\n", th->pid); } } } else { - ret = r_debug_ptrace (dbg, PTRACE_CONT, tid, NULL, (r_ptrace_data_t)(size_t)contsig); + ret = rz_debug_ptrace (dbg, PTRACE_CONT, tid, NULL, (rz_ptrace_data_t)(size_t)contsig); if (ret) { - r_sys_perror ("PTRACE_CONT"); + rz_sys_perror ("PTRACE_CONT"); } } //return ret >= 0 ? tid : false; @@ -261,7 +261,7 @@ static int r_debug_native_continue(RDebug *dbg, int pid, int tid, int sig) { #endif } -static RDebugInfo* r_debug_native_info (RDebug *dbg, const char *arg) { +static RzDebugInfo* rz_debug_native_info (RzDebug *dbg, const char *arg) { #if __APPLE__ return xnu_info (dbg, arg); #elif __WINDOWS__ @@ -276,7 +276,7 @@ static RDebugInfo* r_debug_native_info (RDebug *dbg, const char *arg) { } #if __WINDOWS__ -static bool tracelib(RDebug *dbg, const char *mode, PLIB_ITEM item) { +static bool tracelib(RzDebug *dbg, const char *mode, PLIB_ITEM item) { const char *needle = NULL; int tmp = 0; if (mode) { @@ -285,11 +285,11 @@ static bool tracelib(RDebug *dbg, const char *mode, PLIB_ITEM item) { case 'u': needle = dbg->glob_unlibs; break; } } - r_cons_printf ("(%d) %sing library at 0x%p (%s) %s\n", item->pid, mode, + rz_cons_printf ("(%d) %sing library at 0x%p (%s) %s\n", item->pid, mode, item->BaseOfDll, item->Path, item->Name); - r_cons_flush (); + rz_cons_flush (); if (needle && strlen (needle)) { - tmp = r_str_glob (item->Name, needle); + tmp = rz_str_glob (item->Name, needle); } return !mode || !needle || tmp ; } @@ -301,8 +301,8 @@ static bool tracelib(RDebug *dbg, const char *mode, PLIB_ITEM item) { * Returns R_DEBUG_REASON_* */ #if __WINDOWS__ -static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { - RDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; // Store the original TID to attempt to switch back after handling events that // require switching to the event's thread that shouldn't bother the user int orig_tid = dbg->tid; @@ -310,20 +310,20 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { W32DbgWInst *wrap = dbg->user; if (pid == -1) { - eprintf ("ERROR: r_debug_native_wait called with pid -1\n"); + eprintf ("ERROR: rz_debug_native_wait called with pid -1\n"); return R_DEBUG_REASON_ERROR; } reason = w32_dbg_wait (dbg, pid); if (reason == R_DEBUG_REASON_NEW_LIB) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->lib) { if (tracelib (dbg, "load", r->lib)) { reason = R_DEBUG_REASON_TRAP; } /* Check if autoload PDB is set, and load PDB information if yes */ - RCore *core = dbg->corebind.core; + RzCore *core = dbg->corebind.core; bool autoload_pdb = dbg->corebind.cfggeti (core, "pdb.autoload"); if (autoload_pdb) { PLIB_ITEM lib = r->lib; @@ -333,8 +333,8 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { free (o_res); if (fd) { char *pdb_file = dbg->corebind.cmdstr (core, "i~dbg_file"); - if (pdb_file && (r_str_trim (pdb_file), *pdb_file)) { - if (!r_file_exists (pdb_file + 9)) { + if (pdb_file && (rz_str_trim (pdb_file), *pdb_file)) { + if (!rz_file_exists (pdb_file + 9)) { dbg->corebind.cmdf (core, "idpd"); } dbg->corebind.cmdf (core, "idp"); @@ -342,64 +342,64 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { dbg->corebind.cmdf (core, "o-%d", fd); } } - r_debug_info_free (r); + rz_debug_info_free (r); } else { - r_cons_printf ("Loading unknown library.\n"); - r_cons_flush (); + rz_cons_printf ("Loading unknown library.\n"); + rz_cons_flush (); } restore_thread = true; } else if (reason == R_DEBUG_REASON_EXIT_LIB) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->lib) { if (tracelib (dbg, "unload", r->lib)) { reason = R_DEBUG_REASON_TRAP; } - r_debug_info_free (r); + rz_debug_info_free (r); } else { - r_cons_printf ("Unloading unknown library.\n"); - r_cons_flush (); + rz_cons_printf ("Unloading unknown library.\n"); + rz_cons_flush (); } restore_thread = true; } else if (reason == R_DEBUG_REASON_NEW_TID) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->thread) { PTHREAD_ITEM item = r->thread; - r_cons_printf ("(%d) Created thread %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); - r_cons_flush (); + rz_cons_printf ("(%d) Created thread %d (start @ %p) (teb @ %p)\n", item->pid, item->tid, item->lpStartAddress, item->lpThreadLocalBase); + rz_cons_flush (); - r_debug_info_free (r); + rz_debug_info_free (r); } restore_thread = true; } else if (reason == R_DEBUG_REASON_EXIT_TID) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->thread) { PTHREAD_ITEM item = r->thread; - r_cons_printf ("(%d) Finished thread %d Exit code %d\n", (ut32)item->pid, (ut32)item->tid, (ut32)item->dwExitCode); - r_cons_flush (); + rz_cons_printf ("(%d) Finished thread %d Exit code %d\n", (ut32)item->pid, (ut32)item->tid, (ut32)item->dwExitCode); + rz_cons_flush (); - r_debug_info_free (r); + rz_debug_info_free (r); } if (dbg->tid != orig_tid) { restore_thread = true; } } else if (reason == R_DEBUG_REASON_DEAD) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->thread) { PTHREAD_ITEM item = r->thread; - r_cons_printf ("(%d) Finished process with exit code %d\n", dbg->main_pid, item->dwExitCode); - r_cons_flush (); - r_debug_info_free (r); + rz_cons_printf ("(%d) Finished process with exit code %d\n", dbg->main_pid, item->dwExitCode); + rz_cons_flush (); + rz_debug_info_free (r); } dbg->pid = -1; dbg->tid = -1; } else if (reason == R_DEBUG_REASON_USERSUSP && dbg->tid != orig_tid) { - RDebugInfo *r = r_debug_native_info (dbg, ""); + RzDebugInfo *r = rz_debug_native_info (dbg, ""); if (r && r->thread) { PTHREAD_ITEM item = r->thread; - r_cons_printf ("(%d) Created DebugBreak thread %d (start @ %p)\n", item->pid, item->tid, item->lpStartAddress); - r_cons_flush (); + rz_cons_printf ("(%d) Created DebugBreak thread %d (start @ %p)\n", item->pid, item->tid, item->lpStartAddress); + rz_cons_flush (); - r_debug_info_free (r); + rz_debug_info_free (r); } // DebugProcessBreak creates a new thread that will trigger a breakpoint. We record the // tid here to ignore it once the breakpoint is hit. @@ -418,7 +418,7 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { dbg->pid = -1; reason = R_DEBUG_REASON_DEAD; } else { - r_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); + rz_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); if (dbg->tid != orig_tid) { reason = R_DEBUG_REASON_UNKNOWN; } @@ -431,11 +431,11 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { } // FIXME: Should WAIT_ON_ALL_CHILDREN be a compilation flag instead of runtime debug config? #elif __linux__ && !defined(WAIT_ON_ALL_CHILDREN) // __WINDOWS__ -static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { - RDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; if (pid == -1) { - eprintf ("ERROR: r_debug_native_wait called with pid -1\n"); + eprintf ("ERROR: rz_debug_native_wait called with pid -1\n"); return R_DEBUG_REASON_ERROR; } @@ -444,20 +444,20 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { return reason; } #else // if __WINDOWS__ & elif __linux__ && !defined (WAIT_ON_ALL_CHILDREN) -static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { - RDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; +static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; if (pid == -1) { - eprintf ("ERROR: r_debug_native_wait called with pid -1\n"); + eprintf ("ERROR: rz_debug_native_wait called with pid -1\n"); return R_DEBUG_REASON_ERROR; } #if __APPLE__ - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { reason = xnu_wait (dbg, pid); if (reason == R_DEBUG_REASON_MACH_RCV_INTERRUPTED) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { // Perhaps check the inferior is still alive, // otherwise xnu_stop will fail. reason = xnu_stop (dbg, pid) @@ -470,7 +470,7 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { } break; } while (true); - r_cons_break_pop (); + rz_cons_break_pop (); #else int status = -1; // XXX: this is blocking, ^C will be ignored @@ -483,17 +483,17 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { } #endif // WAIT_ON_ALL_CHILDREN if (ret == -1) { - r_sys_perror ("waitpid"); + rz_sys_perror ("waitpid"); return R_DEBUG_REASON_ERROR; } - //eprintf ("r_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); + //eprintf ("rz_debug_native_wait: status=%d (0x%x) (return=%d)\n", status, status, ret); #ifdef WAIT_ON_ALL_CHILDREN if (ret != pid) { reason = R_DEBUG_REASON_NEW_PID; eprintf ("switching to pid %d\n", ret); - r_debug_select (dbg, ret, ret); + rz_debug_select (dbg, ret, ret); } #endif // WAIT_ON_ALL_CHILDREN // TODO: switch status and handle reasons here @@ -533,7 +533,7 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { #if __OpenBSD__ || __NetBSD__ reason = R_DEBUG_REASON_BREAKPOINT; #else - if (!r_debug_handle_signals (dbg)) { + if (!rz_debug_handle_signals (dbg)) { return R_DEBUG_REASON_ERROR; } reason = dbg->reason.type; @@ -576,29 +576,29 @@ static RDebugReasonType r_debug_native_wait(RDebug *dbg, int pid) { #undef MAXPID #define MAXPID 99999 -static RList *r_debug_native_tids (RDebug *dbg, int pid) { +static RzList *rz_debug_native_tids (RzDebug *dbg, int pid) { printf ("TODO: Threads: \n"); // T return NULL; } -static RList *r_debug_native_pids(RDebug *dbg, int pid) { - RList *list = r_list_new (); +static RzList *rz_debug_native_pids(RzDebug *dbg, int pid) { + RzList *list = rz_list_new (); if (!list) { return NULL; } #if __APPLE__ if (pid) { - RDebugPid *p = xnu_get_pid (pid); + RzDebugPid *p = xnu_get_pid (pid); if (p) { - r_list_append (list, p); + rz_list_append (list, p); } } else { int i; for (i = 1; i < MAXPID; i++) { - RDebugPid *p = xnu_get_pid (i); + RzDebugPid *p = xnu_get_pid (i); if (p) { - r_list_append (list, p); + rz_list_append (list, p); } } } @@ -612,8 +612,8 @@ static RList *r_debug_native_pids(RDebug *dbg, int pid) { return list; } -static RList *r_debug_native_threads (RDebug *dbg, int pid) { - RList *list = r_list_new (); +static RzList *rz_debug_native_threads (RzDebug *dbg, int pid) { + RzList *list = rz_list_new (); if (!list) { eprintf ("No list?\n"); return NULL; @@ -632,7 +632,7 @@ static RList *r_debug_native_threads (RDebug *dbg, int pid) { #if __sun || __NetBSD__ || __KFBSD__ || __OpenBSD__ || __DragonFly__ //Function to read register from Linux, BSD, Android systems -static int bsd_reg_read (RDebug *dbg, int type, ut8* buf, int size) { +static int bsd_reg_read (RzDebug *dbg, int type, ut8* buf, int size) { int showfpu = false; int pid = dbg->pid; int ret; @@ -693,7 +693,7 @@ static int bsd_reg_read (RDebug *dbg, int type, ut8* buf, int size) { // TODO: what about float and hardware regs here ??? // TODO: add flag for type -static int r_debug_native_reg_read (RDebug *dbg, int type, ut8 *buf, int size) { +static int rz_debug_native_reg_read (RzDebug *dbg, int type, ut8 *buf, int size) { if (size < 1) { return false; } @@ -711,7 +711,7 @@ static int r_debug_native_reg_read (RDebug *dbg, int type, ut8 *buf, int size) { #endif } -static int r_debug_native_reg_write (RDebug *dbg, int type, const ut8* buf, int size) { +static int rz_debug_native_reg_write (RzDebug *dbg, int type, const ut8* buf, int size) { // XXX use switch or so if (type == R_REG_TYPE_DRX) { #if __i386__ || __x86_64__ @@ -774,7 +774,7 @@ static int io_perms_to_prot (int io_perms) { } -static int linux_map_thp (RDebug *dbg, ut64 addr, int size) { +static int linux_map_thp (RzDebug *dbg, ut64 addr, int size) { #if !defined(__ANDROID__) && defined(MADV_HUGEPAGE) RBuffer *buf = NULL; char code[1024]; @@ -795,36 +795,36 @@ static int linux_map_thp (RDebug *dbg, ut64 addr, int size) { // In always mode, is more into mmap syscall level // even though the address might not have the 'hg' // vmflags - if (r_sys_thp_mode() != 1) { + if (rz_sys_thp_mode() != 1) { eprintf ("transparent huge page mode is not in madvise mode\n"); return false; } - int num = r_syscall_get_num (dbg->anal->syscall, "madvise"); + int num = rz_syscall_get_num (dbg->anal->syscall, "madvise"); snprintf (code, sizeof (code), "sc_madvise@syscall(%d);\n" "main@naked(0) { .rarg0 = sc_madvise(0x%08" PFMT64x ",%d, %d);break;\n" "}\n", num, addr, size, MADV_HUGEPAGE); - r_egg_reset (dbg->egg); - r_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - r_egg_load (dbg->egg, code, 0); - if (!r_egg_compile (dbg->egg)) { + rz_egg_reset (dbg->egg); + rz_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load (dbg->egg, code, 0); + if (!rz_egg_compile (dbg->egg)) { eprintf ("Cannot compile.\n"); goto err_linux_map_thp; } - if (!r_egg_assemble_asm (dbg->egg, asm_list)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble_asm (dbg->egg, asm_list)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); goto err_linux_map_thp; } - buf = r_egg_get_bin (dbg->egg); + buf = rz_egg_get_bin (dbg->egg); if (buf) { - r_reg_arena_push (dbg->reg); + rz_reg_arena_push (dbg->reg); ut64 tmpsz; - const ut8 *tmp = r_buf_data (buf, &tmpsz); - ret = r_debug_execute (dbg, tmp, tmpsz, 1) == 0; - r_reg_arena_pop (dbg->reg); + const ut8 *tmp = rz_buf_data (buf, &tmpsz); + ret = rz_debug_execute (dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop (dbg->reg); } err_linux_map_thp: return ret; @@ -833,9 +833,9 @@ err_linux_map_thp: #endif } -static RDebugMap* linux_map_alloc (RDebug *dbg, ut64 addr, int size, bool thp) { +static RzDebugMap* linux_map_alloc (RzDebug *dbg, ut64 addr, int size, bool thp) { RBuffer *buf = NULL; - RDebugMap* map = NULL; + RzDebugMap* map = NULL; char code[1024], *sc_name; int num; /* force to usage of x86.as, not yet working x86.nz */ @@ -852,7 +852,7 @@ static RDebugMap* linux_map_alloc (RDebug *dbg, ut64 addr, int size, bool thp) { } else { sc_name = "mmap"; } - num = r_syscall_get_num (dbg->anal->syscall, sc_name); + num = rz_syscall_get_num (dbg->anal->syscall, sc_name); #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS 0x20 #endif @@ -861,26 +861,26 @@ static RDebugMap* linux_map_alloc (RDebug *dbg, ut64 addr, int size, bool thp) { "main@naked(0) { .rarg0 = sc_mmap(0x%08"PFMT64x",%d,%d,%d,%d,%d);break;\n" "}\n", num, addr, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - r_egg_reset (dbg->egg); - r_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - r_egg_load (dbg->egg, code, 0); - if (!r_egg_compile (dbg->egg)) { + rz_egg_reset (dbg->egg); + rz_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load (dbg->egg, code, 0); + if (!rz_egg_compile (dbg->egg)) { eprintf ("Cannot compile.\n"); goto err_linux_map_alloc; } - if (!r_egg_assemble_asm (dbg->egg, asm_list)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble_asm (dbg->egg, asm_list)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); goto err_linux_map_alloc; } - buf = r_egg_get_bin (dbg->egg); + buf = rz_egg_get_bin (dbg->egg); if (buf) { ut64 map_addr; - r_reg_arena_push (dbg->reg); + rz_reg_arena_push (dbg->reg); ut64 tmpsz; - const ut8 *tmp = r_buf_data (buf, &tmpsz); - map_addr = r_debug_execute (dbg, tmp, tmpsz, 1); - r_reg_arena_pop (dbg->reg); + const ut8 *tmp = rz_buf_data (buf, &tmpsz); + map_addr = rz_debug_execute (dbg, tmp, tmpsz, 1); + rz_reg_arena_pop (dbg->reg); if (map_addr != (ut64)-1) { if (thp) { if (!linux_map_thp (dbg, map_addr, size)) { @@ -888,15 +888,15 @@ static RDebugMap* linux_map_alloc (RDebug *dbg, ut64 addr, int size, bool thp) { eprintf ("map promotion to huge page failed\n"); } } - r_debug_map_sync (dbg); - map = r_debug_map_get (dbg, map_addr); + rz_debug_map_sync (dbg); + map = rz_debug_map_get (dbg, map_addr); } } err_linux_map_alloc: return map; } -static int linux_map_dealloc(RDebug *dbg, ut64 addr, int size) { +static int linux_map_dealloc(RzDebug *dbg, ut64 addr, int size) { RBuffer *buf = NULL; char code[1024]; int ret = 0; @@ -905,38 +905,38 @@ static int linux_map_dealloc(RDebug *dbg, ut64 addr, int size) { "x64", "x86.as", NULL }; - int num = r_syscall_get_num (dbg->anal->syscall, "munmap"); + int num = rz_syscall_get_num (dbg->anal->syscall, "munmap"); snprintf (code, sizeof (code), "sc_munmap@syscall(%d);\n" "main@naked(0) { .rarg0 = sc_munmap(0x%08" PFMT64x ",%d);break;\n" "}\n", num, addr, size); - r_egg_reset (dbg->egg); - r_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - r_egg_load (dbg->egg, code, 0); - if (!r_egg_compile (dbg->egg)) { + rz_egg_reset (dbg->egg); + rz_egg_setup (dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load (dbg->egg, code, 0); + if (!rz_egg_compile (dbg->egg)) { eprintf ("Cannot compile.\n"); goto err_linux_map_dealloc; } - if (!r_egg_assemble_asm (dbg->egg, asm_list)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble_asm (dbg->egg, asm_list)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); goto err_linux_map_dealloc; } - buf = r_egg_get_bin (dbg->egg); + buf = rz_egg_get_bin (dbg->egg); if (buf) { - r_reg_arena_push (dbg->reg); + rz_reg_arena_push (dbg->reg); ut64 tmpsz; - const ut8 *tmp = r_buf_data (buf, &tmpsz); - ret = r_debug_execute (dbg, tmp, tmpsz, 1) == 0; - r_reg_arena_pop (dbg->reg); + const ut8 *tmp = rz_buf_data (buf, &tmpsz); + ret = rz_debug_execute (dbg, tmp, tmpsz, 1) == 0; + rz_reg_arena_pop (dbg->reg); } err_linux_map_dealloc: return ret; } #endif -static RDebugMap* r_debug_native_map_alloc (RDebug *dbg, ut64 addr, int size, bool thp) { +static RzDebugMap* rz_debug_native_map_alloc (RzDebug *dbg, ut64 addr, int size, bool thp) { #if __APPLE__ (void)thp; return xnu_map_alloc (dbg, addr, size); @@ -951,7 +951,7 @@ static RDebugMap* r_debug_native_map_alloc (RDebug *dbg, ut64 addr, int size, bo #endif } -static int r_debug_native_map_dealloc (RDebug *dbg, ut64 addr, int size) { +static int rz_debug_native_map_dealloc (RzDebug *dbg, ut64 addr, int size) { #if __APPLE__ return xnu_map_dealloc (dbg, addr, size); #elif __WINDOWS__ @@ -965,7 +965,7 @@ static int r_debug_native_map_dealloc (RDebug *dbg, ut64 addr, int size) { } #if !__WINDOWS__ && !__APPLE__ -static void _map_free(RDebugMap *map) { +static void _map_free(RzDebugMap *map) { if (!map) { return; } @@ -975,8 +975,8 @@ static void _map_free(RDebugMap *map) { } #endif -static RList *r_debug_native_map_get (RDebug *dbg) { - RList *list = NULL; +static RzList *rz_debug_native_map_get (RzDebug *dbg) { + RzList *list = NULL; #if __KFBSD__ int ign; char unkstr[128]; @@ -984,7 +984,7 @@ static RList *r_debug_native_map_get (RDebug *dbg) { #if __APPLE__ list = xnu_dbg_maps (dbg, 0); #elif __WINDOWS__ - list = r_w32_dbg_maps (dbg); + list = rz_w32_dbg_maps (dbg); #else #if __sun char path[1024]; @@ -992,14 +992,14 @@ static RList *r_debug_native_map_get (RDebug *dbg) { snprintf (path, sizeof(path) - 1, "pmap %d >&2", ps.tid); system (path); #else - RDebugMap *map; + RzDebugMap *map; int i, perm, unk = 0; char *pos_c; char path[1024], line[1024], name[1024]; char region[100], region2[100], perms[5]; FILE *fd; if (dbg->pid == -1) { - //eprintf ("r_debug_native_map_get: No selected pid (-1)\n"); + //eprintf ("rz_debug_native_map_get: No selected pid (-1)\n"); return NULL; } /* prepend 0x prefix */ @@ -1020,18 +1020,18 @@ static RList *r_debug_native_map_get (RDebug *dbg) { #else snprintf (path, sizeof (path), "/proc/%d/maps", dbg->pid); #endif - fd = r_sandbox_fopen (path, "r"); + fd = rz_sandbox_fopen (path, "r"); if (!fd) { perror (sdb_fmt ("Cannot open '%s'", path)); return NULL; } - list = r_list_new (); + list = rz_list_new (); if (!list) { fclose (fd); return NULL; } - list->free = (RListFree)_map_free; + list->free = (RzListFree)_map_free; while (!feof (fd)) { size_t line_len; bool map_is_shared = false; @@ -1056,7 +1056,7 @@ static RList *r_debug_native_map_get (RDebug *dbg) { ®ion[2], ®ion2[2], &ign, &ign, unkstr, perms, &ign, &ign) != 8) { eprintf ("%s: Unable to parse \"%s\"\n", __func__, path); - r_list_free (list); + rz_list_free (list); return NULL; } @@ -1076,7 +1076,7 @@ static RList *r_debug_native_map_get (RDebug *dbg) { } else if (i != 4) { eprintf ("%s: Unable to parse \"%s\"\n", __func__, path); eprintf ("%s: problematic line: %s\n", __func__, line); - r_list_free (list); + rz_list_free (list); return NULL; } @@ -1101,13 +1101,13 @@ static RList *r_debug_native_map_get (RDebug *dbg) { } } - map_start = r_num_get (NULL, region); - map_end = r_num_get (NULL, region2); + map_start = rz_num_get (NULL, region); + map_end = rz_num_get (NULL, region2); if (map_start == map_end || map_end == 0) { eprintf ("%s: ignoring invalid map size: %s - %s\n", __func__, region, region2); continue; } - map = r_debug_map_new (name, map_start, map_end, perm, 0); + map = rz_debug_map_new (name, map_start, map_end, perm, 0); if (!map) { break; } @@ -1116,7 +1116,7 @@ static RList *r_debug_native_map_get (RDebug *dbg) { map->shared = map_is_shared; #endif map->file = strdup (name); - r_list_append (list, map); + rz_list_append (list, map); } fclose (fd); #endif // __sun @@ -1124,31 +1124,31 @@ static RList *r_debug_native_map_get (RDebug *dbg) { return list; } -static RList *r_debug_native_modules_get (RDebug *dbg) { +static RzList *rz_debug_native_modules_get (RzDebug *dbg) { char *lastname = NULL; - RDebugMap *map; - RListIter *iter, *iter2; - RList *list, *last; + RzDebugMap *map; + RzListIter *iter, *iter2; + RzList *list, *last; bool must_delete; #if __APPLE__ list = xnu_dbg_maps (dbg, 1); - if (list && !r_list_empty (list)) { + if (list && !rz_list_empty (list)) { return list; } #elif __WINDOWS__ - list = r_w32_dbg_modules (dbg); - if (list && !r_list_empty (list)) { + list = rz_w32_dbg_modules (dbg); + if (list && !rz_list_empty (list)) { return list; } #endif - if (!(list = r_debug_native_map_get (dbg))) { + if (!(list = rz_debug_native_map_get (dbg))) { return NULL; } - if (!(last = r_list_newf ((RListFree)r_debug_map_free))) { - r_list_free (list); + if (!(last = rz_list_newf ((RzListFree)rz_debug_map_free))) { + rz_list_free (list); return NULL; } - r_list_foreach_safe (list, iter, iter2, map) { + rz_list_foreach_safe (list, iter, iter2, map) { const char *file = map->file; if (!map->file) { file = map->file = strdup (map->name); @@ -1160,20 +1160,20 @@ static RList *r_debug_native_modules_get (RDebug *dbg) { } } if (must_delete) { - r_list_delete (list, iter); + rz_list_delete (list, iter); } else { - r_list_append (last, map); + rz_list_append (last, map); free (lastname); lastname = strdup (file); } } list->free = NULL; free (lastname); - r_list_free (list); + rz_list_free (list); return last; } -static bool r_debug_native_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool rz_debug_native_kill(RzDebug *dbg, int pid, int tid, int sig) { bool ret = false; if (pid == 0) { pid = dbg->pid; @@ -1191,10 +1191,10 @@ static bool r_debug_native_kill(RDebug *dbg, int pid, int tid, int sig) { } else { #endif if (sig == SIGKILL && dbg->threads) { - r_list_free (dbg->threads); + rz_list_free (dbg->threads); dbg->threads = NULL; } - if ((r_sandbox_kill (pid, sig) != -1)) { + if ((rz_sandbox_kill (pid, sig) != -1)) { ret = true; } if (errno == 1) { @@ -1207,9 +1207,9 @@ static bool r_debug_native_kill(RDebug *dbg, int pid, int tid, int sig) { return ret; } -struct r_debug_desc_plugin_t r_debug_desc_plugin_native; -static int r_debug_native_init (RDebug *dbg) { - dbg->h->desc = r_debug_desc_plugin_native; +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native; +static int rz_debug_native_init (RzDebug *dbg) { + dbg->h->desc = rz_debug_desc_plugin_native; #if __WINDOWS__ return w32_init (dbg); #else @@ -1217,7 +1217,7 @@ static int r_debug_native_init (RDebug *dbg) { #endif } -static void sync_drx_regs (RDebug *dbg, drxt *regs, size_t num_regs) { +static void sync_drx_regs (RzDebug *dbg, drxt *regs, size_t num_regs) { #if __i386__ || __x86_64__ /* sanity check, we rely on this assumption */ if (num_regs != NUM_DRX_REGISTERS) { @@ -1227,23 +1227,23 @@ static void sync_drx_regs (RDebug *dbg, drxt *regs, size_t num_regs) { // sync drx regs #define R dbg->reg - regs[0] = r_reg_getv (R, "dr0"); - regs[1] = r_reg_getv (R, "dr1"); - regs[2] = r_reg_getv (R, "dr2"); - regs[3] = r_reg_getv (R, "dr3"); + regs[0] = rz_reg_getv (R, "dr0"); + regs[1] = rz_reg_getv (R, "dr1"); + regs[2] = rz_reg_getv (R, "dr2"); + regs[3] = rz_reg_getv (R, "dr3"); /* RESERVED - regs[4] = r_reg_getv (R, "dr4"); - regs[5] = r_reg_getv (R, "dr5"); + regs[4] = rz_reg_getv (R, "dr4"); + regs[5] = rz_reg_getv (R, "dr5"); */ - regs[6] = r_reg_getv (R, "dr6"); - regs[7] = r_reg_getv (R, "dr7"); + regs[6] = rz_reg_getv (R, "dr6"); + regs[7] = rz_reg_getv (R, "dr7"); #else eprintf ("drx sync_drx_regs: Unsupported platform\n"); #endif } -static void set_drx_regs (RDebug *dbg, drxt *regs, size_t num_regs) { +static void set_drx_regs (RzDebug *dbg, drxt *regs, size_t num_regs) { #if __i386__ || __x86_64__ /* sanity check, we rely on this assumption */ if (num_regs != NUM_DRX_REGISTERS){ @@ -1252,18 +1252,18 @@ static void set_drx_regs (RDebug *dbg, drxt *regs, size_t num_regs) { } #define R dbg->reg - r_reg_setv (R, "dr0", regs[0]); - r_reg_setv (R, "dr1", regs[1]); - r_reg_setv (R, "dr2", regs[2]); - r_reg_setv (R, "dr3", regs[3]); - r_reg_setv (R, "dr6", regs[6]); - r_reg_setv (R, "dr7", regs[7]); + rz_reg_setv (R, "dr0", regs[0]); + rz_reg_setv (R, "dr1", regs[1]); + rz_reg_setv (R, "dr2", regs[2]); + rz_reg_setv (R, "dr3", regs[3]); + rz_reg_setv (R, "dr6", regs[6]); + rz_reg_setv (R, "dr7", regs[7]); #else eprintf ("drx set_drx_regs: Unsupported platform\n"); #endif } -static int r_debug_native_drx (RDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { +static int rz_debug_native_drx (RzDebug *dbg, int n, ut64 addr, int sz, int rwx, int g, int api_type) { #if __i386__ || __x86_64__ int retval = false; drxt regs[NUM_DRX_REGISTERS] = {0}; @@ -1291,7 +1291,7 @@ static int r_debug_native_drx (RDebug *dbg, int n, ut64 addr, int sz, int rwx, i break; default: /* this should not happen, someone misused the API */ - eprintf ("drx: Unsupported api type in r_debug_native_drx\n"); + eprintf ("drx: Unsupported api type in rz_debug_native_drx\n"); retval = false; } @@ -1333,11 +1333,11 @@ static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) return ptrace (PTRACE_SETHBPREGS, pid, -2, &control) != -1; } -static bool arm32_hwbp_add (RDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { +static bool arm32_hwbp_add (RzDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { return ll_arm32_hwbp_set (dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); } -static bool arm32_hwbp_del (RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { +static bool arm32_hwbp_del (RzDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { return false; // TODO: hwbp.del not yetimplemented } #else @@ -1345,11 +1345,11 @@ static bool ll_arm32_hwbp_set(pid_t pid, ut64 addr, int size, int wp, int type) return false; } -static bool arm32_hwbp_add (RDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { +static bool arm32_hwbp_add (RzDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { return false; } -static bool arm32_hwbp_del (RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { +static bool arm32_hwbp_del (RzDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { return false; } #endif // PTRACE_GETHWBPREGS @@ -1379,7 +1379,7 @@ static bool ll_arm64_hwbp_set(pid_t pid, ut64 _addr, int size, int wp, ut32 type dreg_state.dbg_regs[0].addr = (uintptr_t)(addr - offset); dreg_state.dbg_regs[0].ctrl = control; iov.iov_base = &dreg_state; - iov.iov_len = r_offsetof (struct user_hwdebug_state, dbg_regs) + + iov.iov_len = rz_offsetof (struct user_hwdebug_state, dbg_regs) + sizeof (dreg_state.dbg_regs[0]); if (ptrace (PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { return true; @@ -1401,7 +1401,7 @@ static bool ll_arm64_hwbp_del(pid_t pid, ut64 _addr, int size, int wp, ut32 type struct iovec iov = {0}; iov.iov_base = &dreg_state; // only delete 1 bp for now - iov.iov_len = r_offsetof (struct user_hwdebug_state, dbg_regs) + + iov.iov_len = rz_offsetof (struct user_hwdebug_state, dbg_regs) + sizeof (dreg_state.dbg_regs[0]); if (ptrace (PTRACE_SETREGSET, pid, NT_ARM_HW_WATCH, &iov) == 0) { return true; @@ -1415,11 +1415,11 @@ static bool ll_arm64_hwbp_del(pid_t pid, ut64 _addr, int size, int wp, ut32 type return false; } -static bool arm64_hwbp_add (RDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { +static bool arm64_hwbp_add (RzDebug *dbg, RBreakpoint* bp, RBreakpointItem *b) { return ll_arm64_hwbp_set (dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); } -static bool arm64_hwbp_del (RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { +static bool arm64_hwbp_del (RzDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { return ll_arm64_hwbp_del (dbg->pid, b->addr, b->size, 0, 1 | 2 | 4); } @@ -1432,8 +1432,8 @@ static bool arm64_hwbp_del (RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { * we only handle the case for hardware breakpoints here. otherwise, * we let the caller handle the work. */ -static int r_debug_native_bp(RBreakpoint *bp, RBreakpointItem *b, bool set) { - RDebug *dbg = bp->user; +static int rz_debug_native_bp(RBreakpoint *bp, RBreakpointItem *b, bool set) { + RzDebug *dbg = bp->user; if (b && b->hw) { #if __i386__ || __x86_64__ return set @@ -1462,13 +1462,13 @@ static int getMaxFiles(void) { return limit.rlim_cur; } -static RList *xnu_desc_list (int pid) { +static RzList *xnu_desc_list (int pid) { #if TARGET_OS_IPHONE || __POWERPC__ return NULL; #else -#define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) - RDebugDesc *desc; - RList *ret = r_list_new (); +#define xwrz_testwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) + RzDebugDesc *desc; + RzList *ret = rz_list_new (); struct vnode_fdinfowithpath vi; int i, nb, type = 0; int maxfd = getMaxFiles(); @@ -1484,18 +1484,18 @@ static RList *xnu_desc_list (int pid) { } //printf ("FD %d RWX %x ", i, vi.pfi.fi_openflags); //printf ("PATH %s\n", vi.pvip.vip_path); - desc = r_debug_desc_new (i, + desc = rz_debug_desc_new (i, vi.pvip.vip_path, - xwr2rwx(vi.pfi.fi_openflags), + xwrz_testwx(vi.pfi.fi_openflags), type, 0); - r_list_append (ret, desc); + rz_list_append (ret, desc); } return ret; #endif } #endif -static RList *r_debug_desc_native_list (int pid) { +static RzList *rz_debug_desc_native_list (int pid) { #if __APPLE__ return xnu_desc_list (pid); #elif __WINDOWS__ @@ -1510,7 +1510,7 @@ static RList *r_debug_desc_native_list (int pid) { #endif } -static int r_debug_native_map_protect (RDebug *dbg, ut64 addr, int size, int perms) { +static int rz_debug_native_map_protect (RzDebug *dbg, ut64 addr, int size, int perms) { #if __WINDOWS__ return w32_map_protect (dbg, addr, size, perms); #elif __APPLE__ @@ -1520,31 +1520,31 @@ static int r_debug_native_map_protect (RDebug *dbg, ut64 addr, int size, int per char code[1024]; int num; - num = r_syscall_get_num (dbg->anal->syscall, "mprotect"); + num = rz_syscall_get_num (dbg->anal->syscall, "mprotect"); snprintf (code, sizeof (code), "sc@syscall(%d);\n" "main@global(0) { sc(%p,%d,%d);\n" ":int3\n" "}\n", num, (void*)addr, size, io_perms_to_prot (perms)); - r_egg_reset (dbg->egg); - r_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); - r_egg_load (dbg->egg, code, 0); - if (!r_egg_compile (dbg->egg)) { + rz_egg_reset (dbg->egg); + rz_egg_setup(dbg->egg, dbg->arch, 8 * dbg->bits, 0, 0); + rz_egg_load (dbg->egg, code, 0); + if (!rz_egg_compile (dbg->egg)) { eprintf ("Cannot compile.\n"); return false; } - if (!r_egg_assemble (dbg->egg)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble (dbg->egg)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); return false; } - buf = r_egg_get_bin (dbg->egg); + buf = rz_egg_get_bin (dbg->egg); if (buf) { - r_reg_arena_push (dbg->reg); + rz_reg_arena_push (dbg->reg); ut64 tmpsz; - const ut8 *tmp = r_buf_data (buf, &tmpsz); - r_debug_execute (dbg, tmp, tmpsz, 1); - r_reg_arena_pop (dbg->reg); + const ut8 *tmp = rz_buf_data (buf, &tmpsz); + rz_debug_execute (dbg, tmp, tmpsz, 1); + rz_reg_arena_pop (dbg->reg); return true; } @@ -1555,25 +1555,25 @@ static int r_debug_native_map_protect (RDebug *dbg, ut64 addr, int size, int per #endif } -static int r_debug_desc_native_open (const char *path) { +static int rz_debug_desc_native_open (const char *path) { return 0; } #if 0 -static int r_debug_setup_ownership (int fd, RDebug *dbg) { - RDebugInfo *info = r_debug_info (dbg, NULL); +static int rz_debug_setup_ownership (int fd, RzDebug *dbg) { + RzDebugInfo *info = rz_debug_info (dbg, NULL); if (!info) { eprintf ("Error while getting debug info.\n"); return -1; } fchown (fd, info->uid, info->gid); - r_debug_info_free (info); + rz_debug_info_free (info); return 0; } #endif -static bool r_debug_gcore (RDebug *dbg, RBuffer *dest) { +static bool rz_debug_gcore (RzDebug *dbg, RBuffer *dest) { #if __APPLE__ return xnu_generate_corefile (dbg, dest); #elif __linux__ && (__x86_64__ || __i386__ || __arm__ || __arm64__) @@ -1587,12 +1587,12 @@ static bool r_debug_gcore (RDebug *dbg, RBuffer *dest) { #endif } -struct r_debug_desc_plugin_t r_debug_desc_plugin_native = { - .open = r_debug_desc_native_open, - .list = r_debug_desc_native_list, +struct rz_debug_desc_plugin_t rz_debug_desc_plugin_native = { + .open = rz_debug_desc_native_open, + .list = rz_debug_desc_native_list, }; -RDebugPlugin r_debug_plugin_native = { +RzDebugPlugin rz_debug_plugin_native = { .name = "native", .license = "LGPL3", #if __i386__ @@ -1633,48 +1633,48 @@ RDebugPlugin r_debug_plugin_native = { #warning Unsupported architecture #endif #endif - .init = &r_debug_native_init, - .step = &r_debug_native_step, - .cont = &r_debug_native_continue, - .stop = &r_debug_native_stop, - .contsc = &r_debug_native_continue_syscall, - .attach = &r_debug_native_attach, - .detach = &r_debug_native_detach, + .init = &rz_debug_native_init, + .step = &rz_debug_native_step, + .cont = &rz_debug_native_continue, + .stop = &rz_debug_native_stop, + .contsc = &rz_debug_native_continue_syscall, + .attach = &rz_debug_native_attach, + .detach = &rz_debug_native_detach, // TODO: add native select for other platforms? #if __WINDOWS__ || __linux__ - .select = &r_debug_native_select, + .select = &rz_debug_native_select, #endif - .pids = &r_debug_native_pids, - .tids = &r_debug_native_tids, - .threads = &r_debug_native_threads, - .wait = &r_debug_native_wait, - .kill = &r_debug_native_kill, - .frames = &r_debug_native_frames, // rename to backtrace ? - .reg_profile = r_debug_native_reg_profile, - .reg_read = r_debug_native_reg_read, - .info = r_debug_native_info, - .reg_write = (void *)&r_debug_native_reg_write, - .map_alloc = r_debug_native_map_alloc, - .map_dealloc = r_debug_native_map_dealloc, - .map_get = r_debug_native_map_get, - .modules_get = r_debug_native_modules_get, - .map_protect = r_debug_native_map_protect, - .breakpoint = r_debug_native_bp, - .drx = r_debug_native_drx, - .gcore = r_debug_gcore, + .pids = &rz_debug_native_pids, + .tids = &rz_debug_native_tids, + .threads = &rz_debug_native_threads, + .wait = &rz_debug_native_wait, + .kill = &rz_debug_native_kill, + .frames = &rz_debug_native_frames, // rename to backtrace ? + .reg_profile = rz_debug_native_reg_profile, + .reg_read = rz_debug_native_reg_read, + .info = rz_debug_native_info, + .reg_write = (void *)&rz_debug_native_reg_write, + .map_alloc = rz_debug_native_map_alloc, + .map_dealloc = rz_debug_native_map_dealloc, + .map_get = rz_debug_native_map_get, + .modules_get = rz_debug_native_modules_get, + .map_protect = rz_debug_native_map_protect, + .breakpoint = rz_debug_native_bp, + .drx = rz_debug_native_drx, + .gcore = rz_debug_gcore, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_native, + .data = &rz_debug_plugin_native, .version = R2_VERSION }; #endif // R2_PLUGIN_INCORE //#endif #else // DEBUGGER -RDebugPlugin r_debug_plugin_native = { +RzDebugPlugin rz_debug_plugin_native = { NULL // .name = "native", }; diff --git a/libr/debug/p/debug_null.c b/librz/debug/p/debug_null.c similarity index 60% rename from libr/debug/p/debug_null.c rename to librz/debug/p/debug_null.c index 03b03d1dc6..17770a0d25 100644 --- a/libr/debug/p/debug_null.c +++ b/librz/debug/p/debug_null.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2016-2017 pancake */ -#include -#include +#include +#include -RDebugPlugin r_debug_plugin_null = { +RzDebugPlugin rz_debug_plugin_null = { .name = "null", .license = "MIT", .arch = "any", @@ -11,9 +11,9 @@ RDebugPlugin r_debug_plugin_null = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_null, + .data = &rz_debug_plugin_null, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_qnx.c b/librz/debug/p/debug_qnx.c similarity index 72% rename from libr/debug/p/debug_qnx.c rename to librz/debug/p/debug_qnx.c index e936616816..b69af88bdc 100644 --- a/libr/debug/p/debug_qnx.c +++ b/librz/debug/p/debug_qnx.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2009-2016 - pancake, defragger, madprogrammer */ -#include -#include +#include +#include #include /* HACK_FOR_PLUGIN_LINKAGE */ -R_API RDebugPid *__r_debug_pid_new(const char *path, int pid, char status, ut64 pc) { - RDebugPid *p = R_NEW0 (RDebugPid); +RZ_API RzDebugPid *__r_debug_pid_new(const char *path, int pid, char status, ut64 pc) { + RzDebugPid *p = R_NEW0 (RzDebugPid); if (!p) { return NULL; } @@ -17,7 +17,7 @@ R_API RDebugPid *__r_debug_pid_new(const char *path, int pid, char status, ut64 p->pc = pc; return p; } -R_API void *__r_debug_pid_free(RDebugPid *pid) { +RZ_API void *__r_debug_pid_free(RzDebugPid *pid) { free (pid->path); free (pid); return NULL; @@ -26,37 +26,37 @@ R_API void *__r_debug_pid_free(RDebugPid *pid) { typedef struct { libqnxr_t desc; -} RIOQnx; +} RzIOQnx; static libqnxr_t *desc = NULL; static ut8 *reg_buf = NULL; static int buf_size = 0; static void pidlist_cb (void *ctx, pid_t pid, char *name) { - RList *list = ctx; - r_list_append (list, __r_debug_pid_new (name, pid, 's', 0)); + RzList *list = ctx; + rz_list_append (list, __r_debug_pid_new (name, pid, 's', 0)); } -static int r_debug_qnx_select (RDebug *dbg, int pid, int tid) { +static int rz_debug_qnx_select (RzDebug *dbg, int pid, int tid) { return qnxr_select (desc, pid, tid); } -static RList *r_debug_qnx_tids (RDebug *dbg, int pid) { +static RzList *rz_debug_qnx_tids (RzDebug *dbg, int pid) { eprintf ("%s: TODO: Threads\n", __func__); return NULL; } -static RList *r_debug_qnx_pids (RDebug *dbg, int pid) { - RList *list = r_list_new (); +static RzList *rz_debug_qnx_pids (RzDebug *dbg, int pid) { + RzList *list = rz_list_new (); if (!list) { return NULL; } - list->free = (RListFree)&__r_debug_pid_free; + list->free = (RzListFree)&__r_debug_pid_free; /* TODO */ if (pid) { - r_list_append (list, __r_debug_pid_new ("(current)", pid, 's', 0)); + rz_list_append (list, __r_debug_pid_new ("(current)", pid, 's', 0)); } else { qnxr_pidlist (desc, list, &pidlist_cb); } @@ -64,7 +64,7 @@ static RList *r_debug_qnx_pids (RDebug *dbg, int pid) { return list; } -static int r_debug_qnx_reg_read (RDebug *dbg, int type, ut8 *buf, int size) { +static int rz_debug_qnx_reg_read (RzDebug *dbg, int type, ut8 *buf, int size) { int copy_size; int buflen = 0; if (!desc) { @@ -75,9 +75,9 @@ static int r_debug_qnx_reg_read (RDebug *dbg, int type, ut8 *buf, int size) { return -1; } // read the len of the current area - free (r_reg_get_bytes (dbg->reg, type, &buflen)); + free (rz_reg_get_bytes (dbg->reg, type, &buflen)); if (size < len) { - eprintf ("r_debug_qnx_reg_read: small buffer %d vs %d\n", + eprintf ("rz_debug_qnx_reg_read: small buffer %d vs %d\n", (int)size, (int)len); } copy_size = R_MIN (len, size); @@ -107,15 +107,15 @@ static int r_debug_qnx_reg_read (RDebug *dbg, int type, ut8 *buf, int size) { return len; } -static RList *r_debug_qnx_map_get (RDebug *dbg) { +static RzList *rz_debug_qnx_map_get (RzDebug *dbg) { return NULL; } -static int r_debug_qnx_reg_write (RDebug *dbg, int type, const ut8 *buf, int size) { +static int rz_debug_qnx_reg_write (RzDebug *dbg, int type, const ut8 *buf, int size) { int buflen = 0; int bits = dbg->anal->bits; - const char *pcname = r_reg_get_name (dbg->anal->reg, R_REG_NAME_PC); - RRegItem *reg = r_reg_get (dbg->anal->reg, pcname, 0); + const char *pcname = rz_reg_get_name (dbg->anal->reg, R_REG_NAME_PC); + RzRegItem *reg = rz_reg_get (dbg->anal->reg, pcname, 0); if (!reg_buf) { // we cannot write registers before we once read them return -1; @@ -125,7 +125,7 @@ static int r_debug_qnx_reg_write (RDebug *dbg, int type, const ut8 *buf, int siz bits = reg->size; } } - free (r_reg_get_bytes (dbg->reg, type, &buflen)); + free (rz_reg_get_bytes (dbg->reg, type, &buflen)); // some implementations of the gdb protocol are acting weird. // so winedbg is not able to write registers through the packet // and also it does not return the whole gdb register profile after @@ -141,30 +141,30 @@ static int r_debug_qnx_reg_write (RDebug *dbg, int type, const ut8 *buf, int siz memset (new_buf + buf_size, 0, buflen - buf_size); } - RRegItem *current = NULL; + RzRegItem *current = NULL; for (;;) { - current = r_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits); + current = rz_reg_next_diff (dbg->reg, type, reg_buf, buflen, current, bits); if (!current) { break; } - ut64 val = r_reg_get_value (dbg->reg, current); + ut64 val = rz_reg_get_value (dbg->reg, current); int bytes = bits / 8; qnxr_write_reg (desc, current->name, (char *)&val, bytes); } return true; } -static int r_debug_qnx_continue (RDebug *dbg, int pid, int tid, int sig) { +static int rz_debug_qnx_continue (RzDebug *dbg, int pid, int tid, int sig) { qnxr_continue (desc, -1); return true; } -static int r_debug_qnx_step (RDebug *dbg) { +static int rz_debug_qnx_step (RzDebug *dbg) { qnxr_step (desc, -1); return true; } -static int r_debug_qnx_wait (RDebug *dbg, int pid) { +static int rz_debug_qnx_wait (RzDebug *dbg, int pid) { ptid_t ptid = qnxr_wait (desc, pid); if (!ptid_equal (ptid, null_ptid)) { dbg->reason.signum = desc->signal; @@ -173,19 +173,19 @@ static int r_debug_qnx_wait (RDebug *dbg, int pid) { return 0; } -static int r_debug_qnx_stop (RDebug *dbg) { +static int rz_debug_qnx_stop (RzDebug *dbg) { qnxr_stop (desc); return true; } -static int r_debug_qnx_attach (RDebug *dbg, int pid) { - RIODesc *d = dbg->iob.io->desc; +static int rz_debug_qnx_attach (RzDebug *dbg, int pid) { + RzIODesc *d = dbg->iob.io->desc; dbg->swstep = false; if (d && d->plugin && d->plugin->name && d->data) { if (!strcmp ("qnx", d->plugin->name)) { - RIOQnx *g = d->data; - int arch = r_sys_arch_id (dbg->arch); + RzIOQnx *g = d->data; + int arch = rz_sys_arch_id (dbg->arch); int bits = dbg->anal->bits; if ((desc = &g->desc)) { switch (arch) { @@ -220,14 +220,14 @@ static int r_debug_qnx_attach (RDebug *dbg, int pid) { return true; } -static int r_debug_qnx_detach (RDebug *dbg, int pid) { +static int rz_debug_qnx_detach (RzDebug *dbg, int pid) { qnxr_disconnect (desc); free (reg_buf); return true; } -static const char *r_debug_qnx_reg_profile (RDebug *dbg) { - int arch = r_sys_arch_id (dbg->arch); +static const char *rz_debug_qnx_reg_profile (RzDebug *dbg) { + int arch = rz_sys_arch_id (dbg->arch); int bits = dbg->anal->bits; switch (arch) { case R_SYS_ARCH_X86: @@ -326,7 +326,7 @@ static const char *r_debug_qnx_reg_profile (RDebug *dbg) { return NULL; } -static int r_debug_qnx_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { +static int rz_debug_qnx_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { if (!b) { return false; } @@ -340,31 +340,31 @@ static int r_debug_qnx_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set return !ret; } -RDebugPlugin r_debug_plugin_qnx = { +RzDebugPlugin rz_debug_plugin_qnx = { .name = "qnx", .license = "LGPL3", .arch = "x86,arm", .bits = R_SYS_BITS_32, - .step = r_debug_qnx_step, - .cont = r_debug_qnx_continue, - .attach = &r_debug_qnx_attach, - .detach = &r_debug_qnx_detach, - .pids = &r_debug_qnx_pids, - .tids = &r_debug_qnx_tids, - .select = &r_debug_qnx_select, - .stop = &r_debug_qnx_stop, + .step = rz_debug_qnx_step, + .cont = rz_debug_qnx_continue, + .attach = &rz_debug_qnx_attach, + .detach = &rz_debug_qnx_detach, + .pids = &rz_debug_qnx_pids, + .tids = &rz_debug_qnx_tids, + .select = &rz_debug_qnx_select, + .stop = &rz_debug_qnx_stop, .canstep = 1, - .wait = &r_debug_qnx_wait, - .map_get = r_debug_qnx_map_get, - .breakpoint = r_debug_qnx_breakpoint, - .reg_read = &r_debug_qnx_reg_read, - .reg_write = &r_debug_qnx_reg_write, - .reg_profile = (void *)r_debug_qnx_reg_profile, + .wait = &rz_debug_qnx_wait, + .map_get = rz_debug_qnx_map_get, + .breakpoint = rz_debug_qnx_breakpoint, + .reg_read = &rz_debug_qnx_reg_read, + .reg_write = &rz_debug_qnx_reg_write, + .reg_profile = (void *)rz_debug_qnx_reg_profile, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_qnx, + .data = &rz_debug_plugin_qnx, .version = R2_VERSION}; #endif diff --git a/libr/debug/p/debug_rap.c b/librz/debug/p/debug_rap.c similarity index 54% rename from libr/debug/p/debug_rap.c rename to librz/debug/p/debug_rap.c index efa8fd1da4..aa5bebcd4b 100644 --- a/libr/debug/p/debug_rap.c +++ b/librz/debug/p/debug_rap.c @@ -1,36 +1,36 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include -#include -#include +#include +#include +#include -static int __rap_step(RDebug *dbg) { - r_io_system (dbg->iob.io, "ds"); +static int __rap_step(RzDebug *dbg) { + rz_io_system (dbg->iob.io, "ds"); return true; } -static int __rap_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { - r_io_system (dbg->iob.io, "dr"); +static int __rap_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { + rz_io_system (dbg->iob.io, "dr"); return 0; } -static int __rap_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int __rap_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { return false; // XXX Error check } -static int __rap_continue(RDebug *dbg, int pid, int tid, int sig) { - r_io_system (dbg->iob.io, "dc"); +static int __rap_continue(RzDebug *dbg, int pid, int tid, int sig) { + rz_io_system (dbg->iob.io, "dc"); return true; } -static int __rap_wait(RDebug *dbg, int pid) { +static int __rap_wait(RzDebug *dbg, int pid) { /* do nothing */ return true; } -static int __rap_attach(RDebug *dbg, int pid) { +static int __rap_attach(RzDebug *dbg, int pid) { // XXX TODO PID must be a socket here !!1 - RIODesc *d = dbg->iob.io->desc; + RzIODesc *d = dbg->iob.io->desc; if (d && d->plugin && d->plugin->name) { if (!strcmp ("rap", d->plugin->name)) { eprintf ("SUCCESS: rap attach with inferior rap rio worked\n"); @@ -41,31 +41,31 @@ static int __rap_attach(RDebug *dbg, int pid) { return true; } -static int __rap_detach(RDebug *dbg, int pid) { +static int __rap_detach(RzDebug *dbg, int pid) { // XXX TODO PID must be a socket here !!1 // close (pid); //XXX Maybe we should continue here? return true; } -static char *__rap_reg_profile(RDebug *dbg) { - char *out, *tf = r_file_temp ("rap.XXXXXX"); - int fd = r_cons_pipe_open (tf, 1, 0); - r_io_system (dbg->iob.io, "drp"); - r_cons_flush (); - r_cons_pipe_close (fd); - out = r_file_slurp (tf, NULL); - r_file_rm (tf); +static char *__rap_reg_profile(RzDebug *dbg) { + char *out, *tf = rz_file_temp ("rap.XXXXXX"); + int fd = rz_cons_pipe_open (tf, 1, 0); + rz_io_system (dbg->iob.io, "drp"); + rz_cons_flush (); + rz_cons_pipe_close (fd); + out = rz_file_slurp (tf, NULL); + rz_file_rm (tf); free (tf); return out; } static int __rap_breakpoint (RBreakpoint *bp, RBreakpointItem *b, bool set) { - //r_io_system (dbg->iob.io, "db"); + //rz_io_system (dbg->iob.io, "db"); return false; } -RDebugPlugin r_debug_plugin_rap = { +RzDebugPlugin rz_debug_plugin_rap = { .name = "rap", .license = "LGPL3", .arch = "any", @@ -84,9 +84,9 @@ RDebugPlugin r_debug_plugin_rap = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_rap, + .data = &rz_debug_plugin_rap, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/debug_windbg.c b/librz/debug/p/debug_windbg.c similarity index 80% rename from libr/debug/p/debug_windbg.c rename to librz/debug/p/debug_windbg.c index e7e19e2649..3a698f561f 100644 --- a/libr/debug/p/debug_windbg.c +++ b/librz/debug/p/debug_windbg.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2020 - GustavoLCR */ -#include +#include #include #ifndef CONTEXT_ARM @@ -51,7 +51,7 @@ static bool __is_target_kernel(DbgEngContext *idbg) { return false; } -static int windbg_init(RDebug *dbg) { +static int windbg_init(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; if (!idbg || !idbg->initialized) { return 0; @@ -59,16 +59,16 @@ static int windbg_init(RDebug *dbg) { return 1; } -static int windbg_step(RDebug *dbg) { +static int windbg_step(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); idbg->lastExecutionStatus = DEBUG_STATUS_STEP_INTO; return SUCCEEDED (ITHISCALL (dbgCtrl, SetExecutionStatus, DEBUG_STATUS_STEP_INTO)); } -static int windbg_step_over(RDebug *dbg) { +static int windbg_step_over(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); idbg->lastExecutionStatus = DEBUG_STATUS_STEP_OVER; if (SUCCEEDED (ITHISCALL (dbgCtrl, SetExecutionStatus, DEBUG_STATUS_STEP_OVER))) { return windbg_wait (dbg, dbg->pid) != R_DEBUG_REASON_ERROR; @@ -76,9 +76,9 @@ static int windbg_step_over(RDebug *dbg) { return 0; } -static int windbg_select(RDebug *dbg, int pid, int tid) { +static int windbg_select(RzDebug *dbg, int pid, int tid) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); ULONG Id = tid, Class, Qualifier; if (!__is_target_kernel (idbg)) { ITHISCALL (dbgSysObj, GetThreadIdBySystemId, tid, &Id); @@ -89,16 +89,16 @@ static int windbg_select(RDebug *dbg, int pid, int tid) { return 0; } -static int windbg_continue(RDebug *dbg, int pid, int tid, int sig) { +static int windbg_continue(RzDebug *dbg, int pid, int tid, int sig) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); idbg->lastExecutionStatus = DEBUG_STATUS_GO; ITHISCALL (dbgCtrl, SetExecutionStatus, DEBUG_STATUS_GO); return tid; } // nicked from windows_debug.c -static RDebugReasonType exception_to_reason(DWORD ExceptionCode) { +static RzDebugReasonType exception_to_reason(DWORD ExceptionCode) { switch (ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: case EXCEPTION_GUARD_PAGE: @@ -124,16 +124,16 @@ static RDebugReasonType exception_to_reason(DWORD ExceptionCode) { } } -static int windbg_stop(RDebug *dbg) { +static int windbg_stop(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); return SUCCEEDED (ITHISCALL (dbgCtrl, SetInterrupt, DEBUG_INTERRUPT_ACTIVE)); } static bool do_break = false; static void __break(void *user) { - RDebug *dbg = (RDebug *)user; + RzDebug *dbg = (RzDebug *)user; DbgEngContext *idbg = dbg->user; if (__is_target_kernel (idbg)) { windbg_stop (dbg); @@ -141,22 +141,22 @@ static void __break(void *user) { do_break = true; } -static int windbg_wait(RDebug *dbg, int pid) { +static int windbg_wait(RzDebug *dbg, int pid) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); ULONG Type, ProcessId, ThreadId; - r_cons_break_push (__break, dbg); + rz_cons_break_push (__break, dbg); const ULONG timeout = __is_target_kernel (idbg) ? INFINITE : TIMEOUT; HRESULT hr; while ((hr = ITHISCALL (dbgCtrl, WaitForEvent, DEBUG_WAIT_DEFAULT, timeout)) == S_FALSE) { if (do_break) { ITHISCALL (dbgCtrl, SetExecutionStatus, DEBUG_STATUS_BREAK); do_break = false; - r_cons_break_pop (); + rz_cons_break_pop (); return R_DEBUG_REASON_USERSUSP; } } - r_cons_break_pop (); + rz_cons_break_pop (); if (FAILED (hr)) { return R_DEBUG_REASON_DEAD; } @@ -188,7 +188,7 @@ static int windbg_wait(RDebug *dbg, int pid) { dbg->reason.type = exception_to_reason (exr.ExceptionCode); dbg->reason.tid = dbg->tid; dbg->reason.addr = exr.ExceptionAddress; - dbg->reason.timestamp = r_time_now (); + dbg->reason.timestamp = rz_time_now (); ret = dbg->reason.type; break; } @@ -208,10 +208,10 @@ static int windbg_wait(RDebug *dbg, int pid) { static int windbg_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool set) { static int bp_idx = 0; - RDebug *dbg = bp->user; - r_return_val_if_fail (dbg, 0); + RzDebug *dbg = bp->user; + rz_return_val_if_fail (dbg, 0); DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); ULONG type = b->hw ? DEBUG_BREAKPOINT_DATA : DEBUG_BREAKPOINT_CODE; PDEBUG_BREAKPOINT bkpt; if (FAILED (ITHISCALL (dbgCtrl, GetBreakpointById, b->internal, &bkpt))) { @@ -250,7 +250,7 @@ static int windbg_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool set) { return 1; } -static char *windbg_reg_profile(RDebug *dbg) { +static char *windbg_reg_profile(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; ULONG type; if (!idbg || !idbg->initialized || FAILED (ITHISCALL (dbgCtrl, GetActualProcessorType, &type))) { @@ -273,9 +273,9 @@ static char *windbg_reg_profile(RDebug *dbg) { return NULL; } -static int windbg_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int windbg_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); if (!idbg || !idbg->initialized || FAILED (ITHISCALL (dbgCtrl, GetActualProcessorType, &type))) { return 0; } @@ -297,18 +297,18 @@ static int windbg_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { } return 0; } -static int windbg_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int windbg_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); if (SUCCEEDED (ITHISCALL (dbgAdvanced, SetThreadContext, (PVOID)buf, size))) { return size; } return 0; } -static RList *windbg_frames(RDebug *dbg, ut64 at) { +static RzList *windbg_frames(RzDebug *dbg, ut64 at) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); const size_t frame_cnt = 128; PDEBUG_STACK_FRAME dbgframes = R_NEWS (DEBUG_STACK_FRAME, frame_cnt); if (!dbgframes) { @@ -319,10 +319,10 @@ static RList *windbg_frames(RDebug *dbg, ut64 at) { free (dbgframes); return NULL; } - RList *frames = r_list_newf (free); + RzList *frames = rz_list_newf (free); size_t i; for (i = 0; i < frames_filled; i++) { - RDebugFrame *f = R_NEW0 (RDebugFrame); + RzDebugFrame *f = R_NEW0 (RzDebugFrame); if (!f) { break; } @@ -330,14 +330,14 @@ static RList *windbg_frames(RDebug *dbg, ut64 at) { f->bp = dbgframes[i].FrameOffset; f->addr = dbgframes[i].ReturnOffset; f->size = f->bp - f->sp; - r_list_append (frames, f); + rz_list_append (frames, f); } return frames; } -static RList *windbg_modules_get(RDebug *dbg) { +static RzList *windbg_modules_get(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); ULONG mod_cnt, mod_un_cnt; if (FAILED (ITHISCALL (dbgSymbols, GetNumberModules, &mod_cnt, &mod_un_cnt))) { return NULL; @@ -352,7 +352,7 @@ static RList *windbg_modules_get(RDebug *dbg) { if (FAILED (ITHISCALL (dbgSymbols, GetModuleParameters, mod_cnt, 0, 0, params))) { return NULL; } - RList *modules_list = r_list_newf ((RListFree)r_debug_map_free); + RzList *modules_list = rz_list_newf ((RzListFree)rz_debug_map_free); if (!modules_list) { return NULL; } @@ -375,10 +375,10 @@ static RList *windbg_modules_get(RDebug *dbg) { free (image_name); break; } - RDebugMap *mod = r_debug_map_new (mod_name, params[i].Base, params[i].Base + params[i].Size, 0, params[i].Size); + RzDebugMap *mod = rz_debug_map_new (mod_name, params[i].Base, params[i].Base + params[i].Size, 0, params[i].Size); if (mod) { mod->file = strdup (image_name); - r_list_append (modules_list, mod); + rz_list_append (modules_list, mod); } free (mod_name); free (image_name); @@ -386,21 +386,21 @@ static RList *windbg_modules_get(RDebug *dbg) { return modules_list; } -static RList *windbg_map_get(RDebug *dbg) { +static RzList *windbg_map_get(RzDebug *dbg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, NULL); + rz_return_val_if_fail (idbg && idbg->initialized, NULL); int perm; ULONG64 to = 0ULL; MEMORY_BASIC_INFORMATION64 mbi; - RList *mod_list = windbg_modules_get (dbg); - RList *map_list = r_list_newf ((RListFree)r_debug_map_free); - const int mod_cnt = mod_list ? r_list_length (mod_list) : 0; + RzList *mod_list = windbg_modules_get (dbg); + RzList *map_list = rz_list_newf ((RzListFree)rz_debug_map_free); + const int mod_cnt = mod_list ? rz_list_length (mod_list) : 0; PIMAGE_NT_HEADERS64 h = R_NEWS (IMAGE_NT_HEADERS64, mod_cnt); PIMAGE_SECTION_HEADER *s = R_NEWS0 (PIMAGE_SECTION_HEADER, mod_cnt); - RListIter *it; - RDebugMap *mod = NULL; + RzListIter *it; + RzDebugMap *mod = NULL; size_t i = 0; - r_list_foreach (mod_list, it, mod) { + rz_list_foreach (mod_list, it, mod) { if (FAILED (ITHISCALL (dbgData, ReadImageNtHeaders, mod->addr, h + i))) { memset (h + i, 0, sizeof (IMAGE_NT_HEADERS64)); } else { @@ -434,7 +434,7 @@ static RList *windbg_map_get(RDebug *dbg) { char *name = ""; if (mbi.Type == MEM_IMAGE) { i = 0; - r_list_foreach (mod_list, it, mod) { + rz_list_foreach (mod_list, it, mod) { if (mbi.BaseAddress >= mod->addr && mbi.BaseAddress < mod->addr + mod->size) { break; } @@ -455,22 +455,22 @@ static RList *windbg_map_get(RDebug *dbg) { } } } - RDebugMap *map = r_debug_map_new (name, mbi.BaseAddress, to, perm, 0); - r_list_append (map_list, map); + RzDebugMap *map = rz_debug_map_new (name, mbi.BaseAddress, to, perm, 0); + rz_list_append (map_list, map); } for (i = 0; i < mod_cnt; i++) { free (s[i]); } free (s); free (h); - r_list_free (mod_list); + rz_list_free (mod_list); return map_list; } -static int windbg_attach(RDebug *dbg, int pid) { +static int windbg_attach(RzDebug *dbg, int pid) { ULONG Id = 0; DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, -1); + rz_return_val_if_fail (idbg && idbg->initialized, -1); if (SUCCEEDED (ITHISCALL (dbgSysObj, GetCurrentProcessSystemId, &Id))) { if (Id == pid && SUCCEEDED (ITHISCALL (dbgSysObj, GetCurrentThreadSystemId, &Id))) { return Id; @@ -482,15 +482,15 @@ static int windbg_attach(RDebug *dbg, int pid) { return -1; } -static int windbg_detach(RDebug *dbg, int pid) { +static int windbg_detach(RzDebug *dbg, int pid) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, 0); + rz_return_val_if_fail (idbg && idbg->initialized, 0); return SUCCEEDED (ITHISCALL (dbgClient, DetachProcesses)); } -static bool windbg_kill(RDebug *dbg, int pid, int tid, int sig) { +static bool windbg_kill(RzDebug *dbg, int pid, int tid, int sig) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, false); + rz_return_val_if_fail (idbg && idbg->initialized, false); if (!sig) { ULONG exit_code, class, qualifier; if (SUCCEEDED (ITHISCALL (dbgCtrl, GetDebuggeeType, &class, &qualifier))) { @@ -510,9 +510,9 @@ static bool windbg_kill(RDebug *dbg, int pid, int tid, int sig) { return SUCCEEDED (hr); } -static RList *windbg_threads(RDebug *dbg, int pid) { +static RzList *windbg_threads(RzDebug *dbg, int pid) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, NULL); + rz_return_val_if_fail (idbg && idbg->initialized, NULL); ULONG thread_cnt = 0; ITHISCALL (dbgSysObj, GetNumberThreads, &thread_cnt); if (!thread_cnt) { @@ -520,7 +520,7 @@ static RList *windbg_threads(RDebug *dbg, int pid) { } PULONG threads_ids = R_NEWS (ULONG, thread_cnt); PULONG threads_sysids = R_NEWS (ULONG, thread_cnt); - RList *list = r_list_newf ((RListFree)r_debug_pid_free); + RzList *list = rz_list_newf ((RzListFree)rz_debug_pid_free); if (!list || !threads_ids || !threads_sysids) { free (list); free (threads_ids); @@ -533,7 +533,7 @@ static RList *windbg_threads(RDebug *dbg, int pid) { ULONG64 pc; ITHISCALL (dbgSysObj, SetCurrentThreadId, threads_ids[i]); ITHISCALL (dbgReg, GetInstructionOffset, &pc); - r_list_append (list, r_debug_pid_new (NULL, threads_sysids[i], 0, 's', pc)); + rz_list_append (list, rz_debug_pid_new (NULL, threads_sysids[i], 0, 's', pc)); } windbg_select (dbg, dbg->pid, dbg->tid); free (threads_ids); @@ -541,13 +541,13 @@ static RList *windbg_threads(RDebug *dbg, int pid) { return list; } -static RDebugInfo *windbg_info(RDebug *dbg, const char *arg) { +static RzDebugInfo *windbg_info(RzDebug *dbg, const char *arg) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, NULL); + rz_return_val_if_fail (idbg && idbg->initialized, NULL); char exeinfo[MAX_PATH]; char cmdline[MAX_PATH]; if (SUCCEEDED (ITHISCALL (dbgClient, GetRunningProcessDescription, idbg->server, dbg->pid, DEBUG_PROC_DESC_NO_SERVICES | DEBUG_PROC_DESC_NO_MTS_PACKAGES, exeinfo, MAX_PATH, NULL, cmdline, MAX_PATH, NULL))) { - RDebugInfo *info = R_NEW0 (RDebugInfo); + RzDebugInfo *info = R_NEW0 (RzDebugInfo); if (!info) { return NULL; } @@ -559,28 +559,28 @@ static RDebugInfo *windbg_info(RDebug *dbg, const char *arg) { return NULL; } -static bool windbg_gcore(RDebug *dbg, RBuffer *dest) { +static bool windbg_gcore(RzDebug *dbg, RBuffer *dest) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, false); - char *path = r_sys_getenv (R_SYS_TMP); + rz_return_val_if_fail (idbg && idbg->initialized, false); + char *path = rz_sys_getenv (R_SYS_TMP); if (R_STR_ISEMPTY (path)) { free (path); - path = r_sys_getdir (); + path = rz_sys_getdir (); if (R_STR_ISEMPTY (path)) { free (path); return false; } } - path = r_str_appendf (path, "\\core.%d", dbg->pid); + path = rz_str_appendf (path, "\\core.%d", dbg->pid); ITHISCALL (dbgClient, WriteDumpFile, path, DEBUG_DUMP_DEFAULT); free (path); return true; } -RList *windbg_pids(RDebug *dbg, int pid) { +RzList *windbg_pids(RzDebug *dbg, int pid) { DbgEngContext *idbg = dbg->user; - r_return_val_if_fail (idbg && idbg->initialized, NULL); - RList *list = r_list_newf ((RListFree)r_debug_pid_free); + rz_return_val_if_fail (idbg && idbg->initialized, NULL); + RzList *list = rz_list_newf ((RzListFree)rz_debug_pid_free); ULONG ids[1000]; ULONG ids_cnt; if (SUCCEEDED (ITHISCALL (dbgClient, GetRunningProcessSystemIds, @@ -591,15 +591,15 @@ RList *windbg_pids(RDebug *dbg, int pid) { if (SUCCEEDED (ITHISCALL (dbgClient, GetRunningProcessDescription, idbg->server, ids[i], DEBUG_PROC_DESC_DEFAULT, path, sizeof (path), NULL, NULL, 0, NULL))) { - RDebugPid *pid = r_debug_pid_new (path, ids[i], 0, 'r', 0); - r_list_append (list, pid); + RzDebugPid *pid = rz_debug_pid_new (path, ids[i], 0, 'r', 0); + rz_list_append (list, pid); } } } return list; } -RDebugPlugin r_debug_plugin_windbg = { +RzDebugPlugin rz_debug_plugin_windbg = { .name = "windbg", .license = "LGPL3", .bits = R_SYS_BITS_64, @@ -629,9 +629,9 @@ RDebugPlugin r_debug_plugin_windbg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_windbg, + .data = &rz_debug_plugin_windbg, .version = R2_VERSION }; #endif // R2_PLUGIN_INCORE diff --git a/libr/debug/p/debug_winkd.c b/librz/debug/p/debug_winkd.c similarity index 61% rename from libr/debug/p/debug_winkd.c rename to librz/debug/p/debug_winkd.c index 7b3882012d..b84a29d1b9 100644 --- a/libr/debug/p/debug_winkd.c +++ b/librz/debug/p/debug_winkd.c @@ -13,33 +13,33 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library. -#include -#include +#include +#include #include #include static WindCtx *wctx = NULL; -static int r_debug_winkd_step(RDebug *dbg) { +static int rz_debug_winkd_step(RzDebug *dbg) { return true; } -static int r_debug_winkd_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int rz_debug_winkd_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { int ret = winkd_read_reg(wctx, buf, size); if (!ret || size != ret) { return -1; } - r_reg_read_regs (dbg->reg, buf, ret); + rz_reg_read_regs (dbg->reg, buf, ret); // Report as if no register has been written as we've already updated the arena here return 0; } -static int r_debug_winkd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +static int rz_debug_winkd_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { if (!dbg->reg) { return false; } int arena_size; - ut8 *arena = r_reg_get_bytes (dbg->reg, R_REG_TYPE_ALL, &arena_size); + ut8 *arena = rz_reg_get_bytes (dbg->reg, R_REG_TYPE_ALL, &arena_size); if (!arena) { eprintf ("Could not retrieve the register arena!\n"); return false; @@ -49,19 +49,19 @@ static int r_debug_winkd_reg_write(RDebug *dbg, int type, const ut8 *buf, int si return ret; } -static int r_debug_winkd_continue(RDebug *dbg, int pid, int tid, int sig) { +static int rz_debug_winkd_continue(RzDebug *dbg, int pid, int tid, int sig) { return winkd_continue(wctx); } -static RDebugReasonType r_debug_winkd_wait(RDebug *dbg, int pid) { - RDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; +static RzDebugReasonType rz_debug_winkd_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; kd_packet_t *pkt = NULL; kd_stc_64 *stc; winkd_lock_enter (wctx); for (;;) { - void *bed = r_cons_sleep_begin (); + void *bed = rz_cons_sleep_begin (); int ret = winkd_wait_packet (wctx, KD_PACKET_TYPE_STATE_CHANGE64, &pkt); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (ret != KD_E_OK || !pkt) { reason = R_DEBUG_REASON_ERROR; break; @@ -87,8 +87,8 @@ static RDebugReasonType r_debug_winkd_wait(RDebug *dbg, int pid) { return reason; } -static int r_debug_winkd_attach(RDebug *dbg, int pid) { - RIODesc *desc = dbg->iob.io->desc; +static int rz_debug_winkd_attach(RzDebug *dbg, int pid) { + RzIODesc *desc = dbg->iob.io->desc; if (!desc || !desc->plugin || !desc->plugin->name || !desc->data) { return false; @@ -112,24 +112,24 @@ static int r_debug_winkd_attach(RDebug *dbg, int pid) { return false; } dbg->bits = winkd_get_bits (wctx); - // Make r_debug_is_dead happy + // Make rz_debug_is_dead happy dbg->pid = 0; return true; } -static int r_debug_winkd_detach(RDebug *dbg, int pid) { +static int rz_debug_winkd_detach(RzDebug *dbg, int pid) { eprintf ("Detaching...\n"); return true; } -static char *r_debug_winkd_reg_profile(RDebug *dbg) { +static char *rz_debug_winkd_reg_profile(RzDebug *dbg) { if (!dbg) { return NULL; } if (dbg->arch && strcmp (dbg->arch, "x86")) { return NULL; } - r_debug_winkd_attach (dbg, 0); + rz_debug_winkd_attach (dbg, 0); if (dbg->bits == R_SYS_BITS_32) { #include "native/reg/windows-x86.h" } else if (dbg->bits == R_SYS_BITS_64) { @@ -138,7 +138,7 @@ static char *r_debug_winkd_reg_profile(RDebug *dbg) { return NULL; } -static int r_debug_winkd_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool set) { +static int rz_debug_winkd_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool set) { int *tag; if (!b) { return false; @@ -154,40 +154,40 @@ static int r_debug_winkd_breakpoint(RBreakpoint *bp, RBreakpointItem *b, bool se return winkd_bkpt (wctx, b->addr, set, b->hw, tag); } -static int r_debug_winkd_init(RDebug *dbg) { +static int rz_debug_winkd_init(RzDebug *dbg) { return true; } -static RList *r_debug_winkd_pids(RDebug *dbg, int pid) { - RListIter *it; +static RzList *rz_debug_winkd_pids(RzDebug *dbg, int pid) { + RzListIter *it; WindProc *p; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RList *pids = winkd_list_process(wctx); + RzList *pids = winkd_list_process(wctx); if (!pids) { return ret; } - r_list_foreach (pids, it, p) { - RDebugPid *newpid = R_NEW0 (RDebugPid); + rz_list_foreach (pids, it, p) { + RzDebugPid *newpid = R_NEW0 (RzDebugPid); if (!newpid) { - r_list_free (ret); + rz_list_free (ret); return NULL; } newpid->path = strdup (p->name); newpid->pid = p->uniqueid; newpid->status = 's'; newpid->runnable = true; - r_list_append (ret, newpid); + rz_list_append (ret, newpid); } - // r_list_free (pids); + // rz_list_free (pids); return ret; } -static int r_debug_winkd_select(RDebug *dbg, int pid, int tid) { +static int rz_debug_winkd_select(RzDebug *dbg, int pid, int tid) { ut32 old = winkd_get_target (wctx); int ret = winkd_set_target (wctx, pid); if (!ret) { @@ -202,94 +202,94 @@ static int r_debug_winkd_select(RDebug *dbg, int pid, int tid) { return true; } -static RList *r_debug_winkd_threads(RDebug *dbg, int pid) { - RListIter *it; +static RzList *rz_debug_winkd_threads(RzDebug *dbg, int pid) { + RzListIter *it; WindThread *t; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RList *threads = winkd_list_threads (wctx); + RzList *threads = winkd_list_threads (wctx); if (!threads) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - r_list_foreach (threads, it, t) { - RDebugPid *newpid = R_NEW0 (RDebugPid); + rz_list_foreach (threads, it, t) { + RzDebugPid *newpid = R_NEW0 (RzDebugPid); if (!newpid) { - r_list_free (ret); + rz_list_free (ret); return NULL; } newpid->pid = t->uniqueid; newpid->status = t->status; newpid->runnable = t->runnable; - r_list_append (ret, newpid); + rz_list_append (ret, newpid); } return ret; } -static RList *r_debug_winkd_modules(RDebug *dbg) { - RListIter *it; +static RzList *rz_debug_winkd_modules(RzDebug *dbg) { + RzListIter *it; WindModule *m; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - RList *modules = winkd_list_modules (wctx); + RzList *modules = winkd_list_modules (wctx); if (!modules) { - r_list_free (ret); + rz_list_free (ret); return NULL; } - r_list_foreach (modules, it, m) { - RDebugMap *mod = R_NEW0 (RDebugMap); + rz_list_foreach (modules, it, m) { + RzDebugMap *mod = R_NEW0 (RzDebugMap); if (!mod) { - r_list_free (modules); - r_list_free (ret); + rz_list_free (modules); + rz_list_free (ret); return NULL; } mod->file = m->name; mod->size = m->size; mod->addr = m->addr; mod->addr_end = m->addr + m->size; - r_list_append (ret, mod); + rz_list_append (ret, mod); } - r_list_free (modules); + rz_list_free (modules); return ret; } -RDebugPlugin r_debug_plugin_winkd = { +RzDebugPlugin rz_debug_plugin_winkd = { .name = "winkd", .license = "LGPL3", .arch = "x86", .bits = R_SYS_BITS_32 | R_SYS_BITS_64, - .init = &r_debug_winkd_init, - .step = &r_debug_winkd_step, - .cont = &r_debug_winkd_continue, - .attach = &r_debug_winkd_attach, - .detach = &r_debug_winkd_detach, - .pids = &r_debug_winkd_pids, - .wait = &r_debug_winkd_wait, - .select = &r_debug_winkd_select, - .breakpoint = r_debug_winkd_breakpoint, - .reg_read = &r_debug_winkd_reg_read, - .reg_write = &r_debug_winkd_reg_write, - .reg_profile = &r_debug_winkd_reg_profile, - .threads = &r_debug_winkd_threads, - .modules_get = &r_debug_winkd_modules + .init = &rz_debug_winkd_init, + .step = &rz_debug_winkd_step, + .cont = &rz_debug_winkd_continue, + .attach = &rz_debug_winkd_attach, + .detach = &rz_debug_winkd_detach, + .pids = &rz_debug_winkd_pids, + .wait = &rz_debug_winkd_wait, + .select = &rz_debug_winkd_select, + .breakpoint = rz_debug_winkd_breakpoint, + .reg_read = &rz_debug_winkd_reg_read, + .reg_write = &rz_debug_winkd_reg_write, + .reg_profile = &rz_debug_winkd_reg_profile, + .threads = &rz_debug_winkd_threads, + .modules_get = &rz_debug_winkd_modules }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_DBG, - .data = &r_debug_plugin_winkd, + .data = &rz_debug_plugin_winkd, .version = R2_VERSION }; #endif diff --git a/libr/debug/p/esil.mk b/librz/debug/p/esil.mk similarity index 100% rename from libr/debug/p/esil.mk rename to librz/debug/p/esil.mk diff --git a/libr/debug/p/gdb.mk b/librz/debug/p/gdb.mk similarity index 61% rename from libr/debug/p/gdb.mk rename to librz/debug/p/gdb.mk index ea35350d69..96b804db65 100644 --- a/libr/debug/p/gdb.mk +++ b/librz/debug/p/gdb.mk @@ -13,14 +13,14 @@ endif -include $(STOP)/gdb/deps.mk LDFLAGS+=$(LINK) -LDFLAGS+=-L$(LTOP)/util -lr_util -LDFLAGS+=-L$(LTOP)/cons -lr_cons -LDFLAGS+=-L$(LTOP)/parse -lr_parse -LDFLAGS+=-L$(LTOP)/socket -lr_socket -LDFLAGS+=-L$(LTOP)/anal -lr_anal -LDFLAGS+=-L$(LTOP)/reg -lr_reg -LDFLAGS+=-L$(LTOP)/bp -lr_bp -LDFLAGS+=-L$(LTOP)/io -lr_io +LDFLAGS+=-L$(LTOP)/util -lrz_util +LDFLAGS+=-L$(LTOP)/cons -lrz_cons +LDFLAGS+=-L$(LTOP)/parse -lrz_parse +LDFLAGS+=-L$(LTOP)/socket -lrz_socket +LDFLAGS+=-L$(LTOP)/anal -lrz_anal +LDFLAGS+=-L$(LTOP)/reg -lrz_reg +LDFLAGS+=-L$(LTOP)/bp -lrz_bp +LDFLAGS+=-L$(LTOP)/io -lrz_io OBJ_GDB=debug_gdb.o @@ -31,4 +31,4 @@ ALL_TARGETS+=${TARGET_GDB} ${TARGET_GDB}: ${OBJ_GDB} ${CC} $(call libname,debug_gdb) ${OBJ_GDB} ${CFLAGS} ${LDFLAGS} \ - -L.. -lr_debug + -L.. -lrz_debug diff --git a/libr/debug/p/io.mk b/librz/debug/p/io.mk similarity index 100% rename from libr/debug/p/io.mk rename to librz/debug/p/io.mk diff --git a/libr/debug/p/native.mk b/librz/debug/p/native.mk similarity index 58% rename from libr/debug/p/native.mk rename to librz/debug/p/native.mk index 1e911c6e5e..dc6ab00508 100644 --- a/libr/debug/p/native.mk +++ b/librz/debug/p/native.mk @@ -23,12 +23,12 @@ endif ${TARGET_PTRACE}: ${OBJ_PTRACE} ${CC} $(call libname,debug_native) ${CFLAGS} \ - ${LDFLAGS_LINKPATH}.. -L.. -lr_debug \ - ${LDFLAGS_LINKPATH}../../io -L../../io -lr_io \ - ${LDFLAGS_LINKPATH}../../bp -L../../bp -lr_bp \ - ${LDFLAGS_LINKPATH}../../anal -L../../anal -lr_anal \ - ${LDFLAGS_LINKPATH}../../reg -L../../reg -lr_reg \ - ${LDFLAGS_LINKPATH}../../util -L../../util -lr_util \ - ${LDFLAGS_LINKPATH}../../syscall -L../../util -lr_syscall \ - ${LDFLAGS_LINKPATH}../../cons -L../../cons -lr_cons \ + ${LDFLAGS_LINKPATH}.. -L.. -lrz_debug \ + ${LDFLAGS_LINKPATH}../../io -L../../io -lrz_io \ + ${LDFLAGS_LINKPATH}../../bp -L../../bp -lrz_bp \ + ${LDFLAGS_LINKPATH}../../anal -L../../anal -lrz_anal \ + ${LDFLAGS_LINKPATH}../../reg -L../../reg -lrz_reg \ + ${LDFLAGS_LINKPATH}../../util -L../../util -lrz_util \ + ${LDFLAGS_LINKPATH}../../syscall -L../../util -lrz_syscall \ + ${LDFLAGS_LINKPATH}../../cons -L../../cons -lrz_cons \ ${OBJ_PTRACE} diff --git a/libr/debug/p/native/arm.c b/librz/debug/p/native/arm.c similarity index 100% rename from libr/debug/p/native/arm.c rename to librz/debug/p/native/arm.c diff --git a/libr/debug/p/native/bsd/bsd_debug.c b/librz/debug/p/native/bsd/bsd_debug.c similarity index 87% rename from libr/debug/p/native/bsd/bsd_debug.c rename to librz/debug/p/native/bsd/bsd_debug.c index 047734a18f..7c0f4ad8f3 100644 --- a/libr/debug/p/native/bsd/bsd_debug.c +++ b/librz/debug/p/native/bsd/bsd_debug.c @@ -60,7 +60,7 @@ static void addr_to_string (struct sockaddr_storage *ss, char *buffer, int bufle } #endif -int bsd_handle_signals(RDebug *dbg) { +int bsd_handle_signals(RzDebug *dbg) { #if __KFBSD__ // Trying to figure out a bit by the signal struct ptrace_lwpinfo linfo = {0}; @@ -71,7 +71,7 @@ int bsd_handle_signals(RDebug *dbg) { dbg->reason.type = R_DEBUG_REASON_DEAD; return 0; } - r_sys_perror ("ptrace PTRACE_LWPINFO"); + rz_sys_perror ("ptrace PTRACE_LWPINFO"); return -1; } @@ -100,7 +100,7 @@ int bsd_handle_signals(RDebug *dbg) { #endif } -int bsd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +int bsd_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { int r = -1; switch (type) { case R_REG_TYPE_GPR: @@ -120,10 +120,10 @@ int bsd_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { return (r == 0 ? true : false); } -RDebugInfo *bsd_info(RDebug *dbg, const char *arg) { +RzDebugInfo *bsd_info(RzDebug *dbg, const char *arg) { #if __KFBSD__ struct kinfo_proc *kp; - RDebugInfo *rdi = R_NEW0 (RDebugInfo); + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) { return NULL; } @@ -166,7 +166,7 @@ RDebugInfo *bsd_info(RDebug *dbg, const char *arg) { struct kinfo_proc *kp; char err[_POSIX2_LINE_MAX]; int rc; - RDebugInfo *rdi = R_NEW0 (RDebugInfo); + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) { return NULL; } @@ -206,7 +206,7 @@ RDebugInfo *bsd_info(RDebug *dbg, const char *arg) { struct kinfo_proc2 *kp; char err[_POSIX2_LINE_MAX]; int np; - RDebugInfo *rdi = R_NEW0 (RDebugInfo); + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) { return NULL; } @@ -253,7 +253,7 @@ RDebugInfo *bsd_info(RDebug *dbg, const char *arg) { #endif } -RList *bsd_pid_list(RDebug *dbg, RList *list) { +RzList *bsd_pid_list(RzDebug *dbg, RzList *list) { #if __KFBSD__ #ifdef __NetBSD__ # define KVM_OPEN_FLAG KVM_NO_FILES @@ -304,15 +304,15 @@ RList *bsd_pid_list(RDebug *dbg, RList *list) { if (pid) { kp = KVM_GETPROCS (kd, KERN_PROC_PID, pid, &cnt); if (cnt == 1) { - RDebugPid *p = r_debug_pid_new (KP_COMM (kp), pid, KP_UID (kp), 's', 0); - if (p) r_list_append (list, p); + RzDebugPid *p = rz_debug_pid_new (KP_COMM (kp), pid, KP_UID (kp), 's', 0); + if (p) rz_list_append (list, p); /* we got our process, now fetch the parent process */ kp = KVM_GETPROCS (kd, KERN_PROC_PID, KP_PPID(kp), &cnt); if (cnt == 1) { - RDebugPid *p = r_debug_pid_new (KP_COMM (kp), KP_PID (kp), KP_UID (kp), 's', 0); + RzDebugPid *p = rz_debug_pid_new (KP_COMM (kp), KP_PID (kp), KP_UID (kp), 's', 0); if (p) { p->ppid = KP_PPID (kp); - r_list_append (list, p); + rz_list_append (list, p); } } } @@ -320,10 +320,10 @@ RList *bsd_pid_list(RDebug *dbg, RList *list) { kp = KVM_GETPROCS (kd, KERN_PROC_UID, geteuid(), &cnt); int i; for (i = 0; i < cnt; i++) { - RDebugPid *p = r_debug_pid_new (KP_COMM (kp + i), KP_PID (kp + i), KP_UID (kp), 's', 0); + RzDebugPid *p = rz_debug_pid_new (KP_COMM (kp + i), KP_PID (kp + i), KP_UID (kp), 's', 0); if (p) { p->ppid = KP_PPID (kp); - r_list_append (list, p); + rz_list_append (list, p); } } } @@ -332,14 +332,14 @@ RList *bsd_pid_list(RDebug *dbg, RList *list) { return list; } -RList *bsd_native_sysctl_map(RDebug *dbg) { +RzList *bsd_native_sysctl_map(RzDebug *dbg) { #if __KFBSD__ int mib[4]; size_t len; char *buf, *bp, *eb; struct kinfo_vmentry *kve; - RList *list = NULL; - RDebugMap *map; + RzList *list = NULL; + RzDebugMap *map; len = 0; mib[0] = CTL_KERN; @@ -359,17 +359,17 @@ RList *bsd_native_sysctl_map(RDebug *dbg) { } bp = buf; eb = buf + len; - list = r_debug_map_list_new(); + list = rz_debug_map_list_new(); if (!list) { free (buf); return NULL; } while (bp < eb) { kve = (struct kinfo_vmentry *)(uintptr_t)bp; - map = r_debug_map_new (kve->kve_path, kve->kve_start, + map = rz_debug_map_new (kve->kve_path, kve->kve_start, kve->kve_end, kve->kve_protection, 0); if (!map) break; - r_list_append (list, map); + rz_list_append (list, map); bp += kve->kve_structsize; } free (buf); @@ -379,8 +379,8 @@ RList *bsd_native_sysctl_map(RDebug *dbg) { size_t len; struct kinfo_vmentry entry; u_long old_end = 0; - RList *list = NULL; - RDebugMap *map; + RzList *list = NULL; + RzDebugMap *map; len = sizeof(entry); mib[0] = CTL_KERN; @@ -393,7 +393,7 @@ RList *bsd_native_sysctl_map(RDebug *dbg) { return NULL; } - list = r_debug_map_list_new(); + list = rz_debug_map_list_new(); if (!list) return NULL; while (sysctl (mib, 3, &entry, &len, NULL, 0) != -1) { @@ -404,10 +404,10 @@ RList *bsd_native_sysctl_map(RDebug *dbg) { /* path to vm obj is not included in kinfo_vmentry. * see usr.sbin/procmap for namei-cache lookup. */ - map = r_debug_map_new ("", entry.kve_start, entry.kve_end, + map = rz_debug_map_new ("", entry.kve_start, entry.kve_end, entry.kve_protection, 0); if (!map) break; - r_list_append (list, map); + rz_list_append (list, map); entry.kve_start = entry.kve_start + 1; old_end = entry.kve_end; @@ -419,13 +419,13 @@ RList *bsd_native_sysctl_map(RDebug *dbg) { #endif } -RList *bsd_desc_list(int pid) { +RzList *bsd_desc_list(int pid) { #if __KFBSD__ - RList *ret = NULL; + RzList *ret = NULL; int perm, type, mib[4]; size_t len; char *buf, *bp, *eb, *str, path[1024]; - RDebugDesc *desc; + RzDebugDesc *desc; struct kinfo_file *kve; len = 0; @@ -446,12 +446,12 @@ RList *bsd_desc_list(int pid) { } bp = buf; eb = buf + len; - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { free (buf); return NULL; } - ret->free = (RListFree) r_debug_desc_free; + ret->free = (RzListFree) rz_debug_desc_free; while (bp < eb) { kve = (struct kinfo_file *)(uintptr_t)bp; bp += kve->kf_structsize; @@ -506,11 +506,11 @@ RList *bsd_desc_list(int pid) { } perm = (kve->kf_flags & KF_FLAG_READ)? R_PERM_R: 0; perm |= (kve->kf_flags & KF_FLAG_WRITE)? R_PERM_W: 0; - desc = r_debug_desc_new (kve->kf_fd, str, perm, type, kve->kf_offset); + desc = rz_debug_desc_new (kve->kf_fd, str, perm, type, kve->kf_offset); if (!desc) { break; } - r_list_append (ret, desc); + rz_list_append (ret, desc); } free (buf); @@ -521,7 +521,7 @@ RList *bsd_desc_list(int pid) { } #if __KFBSD__ -static int get_r2_status(int stat) { +static int get_rz_status(int stat) { switch (stat) { case SRUN: case SIDL: @@ -540,7 +540,7 @@ static int get_r2_status(int stat) { } #endif -RList *bsd_thread_list(RDebug *dbg, int pid, RList *list) { +RzList *bsd_thread_list(RzDebug *dbg, int pid, RzList *list) { #if __KFBSD__ int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD, pid }; struct kinfo_proc *kp; @@ -549,7 +549,7 @@ RList *bsd_thread_list(RDebug *dbg, int pid, RList *list) { int i = 0; if (sysctl (mib, 4, NULL, &len, NULL, 0) == -1) { - r_list_free (list); + rz_list_free (list); return NULL; } @@ -557,26 +557,26 @@ RList *bsd_thread_list(RDebug *dbg, int pid, RList *list) { kp = malloc(len); if (sysctl (mib, 4, kp, &len, NULL, 0) == -1) { free (kp); - r_list_free (list); + rz_list_free (list); return NULL; } max = len / sizeof(*kp); for (i = 0; i < max; i ++) { - RDebugPid *pid_info; + RzDebugPid *pid_info; int pid_stat; - pid_stat = get_r2_status (kp[i].ki_stat); - pid_info = r_debug_pid_new (kp[i].ki_comm, kp[i].ki_tid, + pid_stat = get_rz_status (kp[i].ki_stat); + pid_info = rz_debug_pid_new (kp[i].ki_comm, kp[i].ki_tid, kp[i].ki_uid, pid_stat, (ut64)kp[i].ki_wchan); - r_list_append (list, pid_info); + rz_list_append (list, pid_info); } free (kp); return list; #else eprintf ("bsd_thread_list unsupported on this platform\n"); - r_list_free (list); + rz_list_free (list); return NULL; #endif } diff --git a/librz/debug/p/native/bsd/bsd_debug.h b/librz/debug/p/native/bsd/bsd_debug.h new file mode 100644 index 0000000000..21a440ddad --- /dev/null +++ b/librz/debug/p/native/bsd/bsd_debug.h @@ -0,0 +1,16 @@ +/* radare - LGPL - Copyright 2009-2019 - pancake */ + +#ifndef _BSD_DEBUG_H +#define _BSD_DEBUG_H +#include +#include +#define R_DEBUG_REG_T struct reg + +int bsd_handle_signals(RzDebug *dbg); +int bsd_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size); +RzDebugInfo *bsd_info(RzDebug *dbg, const char *arg); +RzList *bsd_pid_list(RzDebug *dbg, RzList *list); +RzList *bsd_native_sysctl_map(RzDebug *dbg); +RzList *bsd_desc_list(int pid); +RzList *bsd_thread_list(RzDebug *dbg, int pid, RzList *list); +#endif diff --git a/libr/debug/p/native/bt.c b/librz/debug/p/native/bt.c similarity index 64% rename from libr/debug/p/native/bt.c rename to librz/debug/p/native/bt.c index db2f40257c..b71c67059f 100644 --- a/libr/debug/p/native/bt.c +++ b/librz/debug/p/native/bt.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include +#include #include "bt/generic-x86.c" #include "bt/generic-x64.c" #include "bt/fuzzy-all.c" -typedef RList* (*RDebugFrameCallback)(RDebug *dbg, ut64 at); +typedef RzList* (*RzDebugFrameCallback)(RzDebug *dbg, ut64 at); -static void prepend_current_pc (RDebug *dbg, RList *list) { - RDebugFrame *frame; +static void prepend_current_pc (RzDebug *dbg, RzList *list) { + RzDebugFrame *frame; const char *pcname; if (list) { - pcname = r_reg_get_name (dbg->reg, R_REG_NAME_PC); + pcname = rz_reg_get_name (dbg->reg, R_REG_NAME_PC); if (pcname) { - ut64 addr = r_reg_getv (dbg->reg, pcname); - frame = R_NEW0 (RDebugFrame); + ut64 addr = rz_reg_getv (dbg->reg, pcname); + frame = R_NEW0 (RzDebugFrame); frame->addr = addr; frame->size = 0; - r_list_prepend (list, frame); + rz_list_prepend (list, frame); } } } @@ -26,8 +26,8 @@ static void prepend_current_pc (RDebug *dbg, RList *list) { #if HAVE_PTRACE struct frames_proxy_args { - RDebugFrameCallback cb; - RDebug *dbg; + RzDebugFrameCallback cb; + RzDebug *dbg; ut64 at; }; @@ -40,8 +40,8 @@ static void *backtrace_proxy(void *user) { } #endif -static RList *r_debug_native_frames(RDebug *dbg, ut64 at) { - RDebugFrameCallback cb = NULL; +static RzList *rz_debug_native_frames(RzDebug *dbg, ut64 at) { + RzDebugFrameCallback cb = NULL; if (dbg->btalgo) { if (!strcmp (dbg->btalgo, "fuzzy")) { cb = backtrace_fuzzy; @@ -61,13 +61,13 @@ static RList *r_debug_native_frames(RDebug *dbg, ut64 at) { } } - RList *list; + RzList *list; if (dbg->btalgo && !strcmp (dbg->btalgo, "trace")) { - list = r_list_clone (dbg->call_frames); + list = rz_list_clone (dbg->call_frames); } else { #if HAVE_PTRACE struct frames_proxy_args args = { cb, dbg, at }; - list = r_debug_ptrace_func (dbg, backtrace_proxy, &args); + list = rz_debug_ptrace_func (dbg, backtrace_proxy, &args); #else list = cb (dbg, at); #endif diff --git a/libr/debug/p/native/bt/fuzzy-all.c b/librz/debug/p/native/bt/fuzzy-all.c similarity index 77% rename from libr/debug/p/native/bt/fuzzy-all.c rename to librz/debug/p/native/bt/fuzzy-all.c index a9241d0322..66d9ea292a 100644 --- a/libr/debug/p/native/bt/fuzzy-all.c +++ b/librz/debug/p/native/bt/fuzzy-all.c @@ -1,6 +1,6 @@ /* implementation */ -static int iscallret(RDebug *dbg, ut64 addr) { +static int iscallret(RzDebug *dbg, ut64 addr) { ut8 buf[32]; if (addr == 0LL || addr == UT64_MAX) return 0; @@ -20,14 +20,14 @@ static int iscallret(RDebug *dbg, ut64 addr) { } // IMMAMISSINGANYOP } else { - RAnalOp op; + RzAnalOp op; (void) dbg->iob.read_at (dbg->iob.io, addr-8, buf, 8); - (void) r_anal_op (dbg->anal, &op, addr-8, buf, 8, R_ANAL_OP_MASK_BASIC); + (void) rz_anal_op (dbg->anal, &op, addr-8, buf, 8, R_ANAL_OP_MASK_BASIC); if (op.type == R_ANAL_OP_TYPE_CALL || op.type == R_ANAL_OP_TYPE_UCALL) { return 1; } /* delay slot */ - (void) r_anal_op (dbg->anal, &op, addr-4, buf, 4, R_ANAL_OP_MASK_BASIC); + (void) rz_anal_op (dbg->anal, &op, addr-4, buf, 4, R_ANAL_OP_MASK_BASIC); if (op.type == R_ANAL_OP_TYPE_CALL || op.type == R_ANAL_OP_TYPE_UCALL) { return 1; } @@ -35,41 +35,41 @@ static int iscallret(RDebug *dbg, ut64 addr) { return 0; } -static RList *backtrace_fuzzy(RDebug *dbg, ut64 at) { +static RzList *backtrace_fuzzy(RzDebug *dbg, ut64 at) { ut8 *stack, *ptr; int wordsize = dbg->bits; // XXX, dbg->bits is wordsize not bits ut64 sp; - RIOBind *bio = &dbg->iob; + RzIOBind *bio = &dbg->iob; int i, stacksize; ut64 *p64, addr = 0LL; ut32 *p32; ut16 *p16; ut64 cursp, oldsp; - RList *list; + RzList *list; stacksize = 1024*512; // 512KB .. should get the size from the regions if possible stack = malloc (stacksize); if (at == UT64_MAX) { - RRegItem *ri; - RReg *reg = dbg->reg; - const char *spname = r_reg_get_name (reg, R_REG_NAME_SP); + RzRegItem *ri; + RzReg *reg = dbg->reg; + const char *spname = rz_reg_get_name (reg, R_REG_NAME_SP); if (!spname) { eprintf ("Cannot find stack pointer register\n"); free (stack); return NULL; } - ri = r_reg_get (reg, spname, R_REG_TYPE_GPR); + ri = rz_reg_get (reg, spname, R_REG_TYPE_GPR); if (!ri) { eprintf ("Cannot find stack pointer register\n"); free (stack); return NULL; } - sp = r_reg_get_value (reg, ri); + sp = rz_reg_get_value (reg, ri); } else { sp = at; } - list = r_list_new (); + list = rz_list_new (); list->free = free; cursp = oldsp = sp; (void)bio->read_at (bio->io, sp, stack, stacksize); @@ -84,17 +84,17 @@ static RList *backtrace_fuzzy(RDebug *dbg, ut64 at) { case 2: addr = *p16; break; default: eprintf ("Invalid word size with asm.bits\n"); - r_list_free (list); + rz_list_free (list); return NULL; } if (iscallret (dbg, addr)) { - RDebugFrame *frame = R_NEW0 (RDebugFrame); + RzDebugFrame *frame = R_NEW0 (RzDebugFrame); frame->addr = addr; frame->size = cursp - oldsp; frame->sp = cursp; frame->bp = oldsp; //addr + (i * wordsize); // -4 || -8 // eprintf ("--------------> 0x%llx (%d)\n", addr, frame->size); - r_list_append (list, frame); + rz_list_append (list, frame); oldsp = cursp; } ptr += wordsize; diff --git a/libr/debug/p/native/bt/generic-x64.c b/librz/debug/p/native/bt/generic-x64.c similarity index 58% rename from libr/debug/p/native/bt/generic-x64.c rename to librz/debug/p/native/bt/generic-x64.c index 3e04e0ee69..7e2af27a68 100644 --- a/libr/debug/p/native/bt/generic-x64.c +++ b/librz/debug/p/native/bt/generic-x64.c @@ -1,23 +1,23 @@ -static RList *backtrace_x86_64(RDebug *dbg, ut64 at) { +static RzList *backtrace_x86_64(RzDebug *dbg, ut64 at) { int i; ut8 buf[8]; - RDebugFrame *frame; + RzDebugFrame *frame; ut64 ptr, ebp2; ut64 _rip, _rsp, _rbp = 0; - RList *list; - RReg *reg = dbg->reg; - RIOBind *bio = &dbg->iob; + RzList *list; + RzReg *reg = dbg->reg; + RzIOBind *bio = &dbg->iob; - _rip = r_reg_get_value (reg, r_reg_get (reg, "rip", R_REG_TYPE_GPR)); + _rip = rz_reg_get_value (reg, rz_reg_get (reg, "rip", R_REG_TYPE_GPR)); if (at == UT64_MAX) { - _rsp = r_reg_get_value (reg, r_reg_get (reg, "rsp", R_REG_TYPE_GPR)); - _rbp = r_reg_get_value (reg, r_reg_get (reg, "rbp", R_REG_TYPE_GPR)); + _rsp = rz_reg_get_value (reg, rz_reg_get (reg, "rsp", R_REG_TYPE_GPR)); + _rbp = rz_reg_get_value (reg, rz_reg_get (reg, "rbp", R_REG_TYPE_GPR)); } else { _rsp = _rbp = at; } - list = r_list_new (); + list = rz_list_new (); list->free = free; bio->read_at (bio->io, _rip, (ut8*)&buf, 8); /* %rbp=old rbp, %rbp+4 points to ret */ @@ -25,14 +25,14 @@ static RList *backtrace_x86_64(RDebug *dbg, ut64 at) { if (!memcmp (buf, "\x55\x89\xe5", 3) || !memcmp (buf, "\x89\xe5\x57", 3)) { if (!bio->read_at (bio->io, _rsp, (ut8*)&ptr, 8)) { eprintf ("read error at 0x%08"PFMT64x"\n", _rsp); - r_list_purge (list); + rz_list_purge (list); free (list); return false; } - frame = R_NEW0 (RDebugFrame); + frame = R_NEW0 (RzDebugFrame); frame->addr = ptr; frame->size = 0; // TODO ? - r_list_append (list, frame); + rz_list_append (list, frame); _rbp = ptr; } @@ -44,47 +44,47 @@ static RList *backtrace_x86_64(RDebug *dbg, ut64 at) { bio->read_at (bio->io, _rbp+8, (ut8*)&ptr, 8); if (!ptr || !_rbp) break; - frame = R_NEW0 (RDebugFrame); + frame = R_NEW0 (RzDebugFrame); frame->addr = ptr; frame->size = 0; // TODO ? - r_list_append (list, frame); + rz_list_append (list, frame); _rbp = ebp2; } return list; } // XXX: Do this work correctly? -static RList *backtrace_x86_64_anal(RDebug *dbg, ut64 at) { +static RzList *backtrace_x86_64_anal(RzDebug *dbg, ut64 at) { int i; ut8 buf[8]; - RDebugFrame *frame; + RzDebugFrame *frame; ut64 ptr, ebp2 = UT64_MAX; ut64 _rip, _rbp; - RList *list; - RReg *reg = dbg->reg; - RIOBind *bio = &dbg->iob; - RAnalFunction *fcn; + RzList *list; + RzReg *reg = dbg->reg; + RzIOBind *bio = &dbg->iob; + RzAnalFunction *fcn; - _rip = r_reg_get_value (reg, r_reg_get (reg, "rip", R_REG_TYPE_GPR)); + _rip = rz_reg_get_value (reg, rz_reg_get (reg, "rip", R_REG_TYPE_GPR)); if (at == UT64_MAX) { - //_rsp = r_reg_get_value (reg, r_reg_get (reg, "rsp", R_REG_TYPE_GPR)); - _rbp = r_reg_get_value (reg, r_reg_get (reg, "rbp", R_REG_TYPE_GPR)); + //_rsp = rz_reg_get_value (reg, rz_reg_get (reg, "rsp", R_REG_TYPE_GPR)); + _rbp = rz_reg_get_value (reg, rz_reg_get (reg, "rbp", R_REG_TYPE_GPR)); } else { _rbp = at; } - list = r_list_new (); + list = rz_list_new (); list->free = free; bio->read_at (bio->io, _rip, (ut8*)&buf, 8); // TODO : frame->size by using esil to emulate first instructions - fcn = r_anal_get_fcn_in (dbg->anal, _rip, R_ANAL_FCN_TYPE_NULL); + fcn = rz_anal_get_fcn_in (dbg->anal, _rip, R_ANAL_FCN_TYPE_NULL); if (fcn) { - frame = R_NEW0 (RDebugFrame); + frame = R_NEW0 (RzDebugFrame); frame->addr = _rip; frame->size = 0; frame->sp = _rbp; frame->bp = _rbp + 8; // XXX - r_list_append (list, frame); + rz_list_append (list, frame); } for (i=1; ibtdepth; i++) { @@ -95,14 +95,14 @@ static RList *backtrace_x86_64_anal(RDebug *dbg, ut64 at) { bio->read_at (bio->io, _rbp+8, (ut8*)&ptr, 8); if (!ptr || !_rbp) break; - //fcn = r_anal_get_fcn_in (dbg->anal, ptr, R_ANAL_FCN_TYPE_NULL); - frame = R_NEW0 (RDebugFrame); + //fcn = rz_anal_get_fcn_in (dbg->anal, ptr, R_ANAL_FCN_TYPE_NULL); + frame = R_NEW0 (RzDebugFrame); frame->addr = ptr; frame->size = 0; frame->sp = _rbp; frame->bp = _rbp + 8; //frame->name = (fcn && fcn->name) ? strdup (fcn->name) : NULL; - r_list_append (list, frame); + rz_list_append (list, frame); _rbp = ebp2; } diff --git a/libr/debug/p/native/bt/generic-x86.c b/librz/debug/p/native/bt/generic-x86.c similarity index 53% rename from libr/debug/p/native/bt/generic-x86.c rename to librz/debug/p/native/bt/generic-x86.c index 76b7348c18..ab9a60404a 100644 --- a/libr/debug/p/native/bt/generic-x86.c +++ b/librz/debug/p/native/bt/generic-x86.c @@ -1,22 +1,22 @@ /* definition */ -//static RList *backtrace_frames_x86_32(RDebug *dbg, ut64 at); -//static RList *backtrace_frames_x86_32_anal(RDebug *dbg, ut64 at); +//static RzList *backtrace_frames_x86_32(RzDebug *dbg, ut64 at); +//static RzList *backtrace_frames_x86_32_anal(RzDebug *dbg, ut64 at); /* implementation */ -#include +#include -static RList *backtrace_x86_32(RDebug *dbg, ut64 at) { - RRegItem *ri; - RReg *reg = dbg->reg; +static RzList *backtrace_x86_32(RzDebug *dbg, ut64 at) { + RzRegItem *ri; + RzReg *reg = dbg->reg; ut32 i, _esp, esp, ebp2; - RList *list = r_list_new (); - RIOBind *bio = &dbg->iob; + RzList *list = rz_list_new (); + RzIOBind *bio = &dbg->iob; ut8 buf[4]; list->free = free; - ri = (at==UT64_MAX)? r_reg_get (reg, "ebp", R_REG_TYPE_GPR): NULL; - _esp = (ut32) ((ri)? r_reg_get_value (reg, ri): at); + ri = (at==UT64_MAX)? rz_reg_get (reg, "ebp", R_REG_TYPE_GPR): NULL; + _esp = (ut32) ((ri)? rz_reg_get_value (reg, ri): at); // TODO: implement [stack] map uptrace method too esp = _esp; for (i=0; ibtdepth; i++) { @@ -28,10 +28,10 @@ static RList *backtrace_x86_32(RDebug *dbg, ut64 at) { // TODO: arch_is_call() here and this fun will be portable if (buf[(ebp2-5)%4] == 0xe8) { - RDebugFrame *frame = R_NEW0 (RDebugFrame); + RzDebugFrame *frame = R_NEW0 (RzDebugFrame); frame->addr = ebp2; frame->size = esp - _esp; - r_list_append (list, frame); + rz_list_append (list, frame); } esp += 4; } @@ -39,32 +39,32 @@ static RList *backtrace_x86_32(RDebug *dbg, ut64 at) { } /* TODO: Can I use this as in a coroutine? */ -static RList *backtrace_x86_32_anal(RDebug *dbg, ut64 at) { - RRegItem *ri; - RReg *reg = dbg->reg; +static RzList *backtrace_x86_32_anal(RzDebug *dbg, ut64 at) { + RzRegItem *ri; + RzReg *reg = dbg->reg; ut32 i, _esp, esp, eip, ebp2; - RList *list; - RIOBind *bio = &dbg->iob; - RAnalFunction *fcn; - RDebugFrame *frame; + RzList *list; + RzIOBind *bio = &dbg->iob; + RzAnalFunction *fcn; + RzDebugFrame *frame; ut8 buf[4]; // TODO : frame->size by using esil to emulate first instructions - list = r_list_new (); + list = rz_list_new (); list->free = free; - ri = (at==UT64_MAX)? r_reg_get (reg, "ebp", R_REG_TYPE_GPR): NULL; - _esp = (ut32) ((ri)? r_reg_get_value (reg, ri): at); + ri = (at==UT64_MAX)? rz_reg_get (reg, "ebp", R_REG_TYPE_GPR): NULL; + _esp = (ut32) ((ri)? rz_reg_get_value (reg, ri): at); // TODO: implement [stack] map uptrace method too esp = _esp; - eip = r_reg_get_value (reg, r_reg_get (reg, "eip", R_REG_TYPE_GPR)); - fcn = r_anal_get_fcn_in (dbg->anal, eip, R_ANAL_FCN_TYPE_NULL); + eip = rz_reg_get_value (reg, rz_reg_get (reg, "eip", R_REG_TYPE_GPR)); + fcn = rz_anal_get_fcn_in (dbg->anal, eip, R_ANAL_FCN_TYPE_NULL); if (fcn != NULL) { - frame = R_NEW0 (RDebugFrame); + frame = R_NEW0 (RzDebugFrame); frame->addr = eip; frame->size = 0; - r_list_append (list, frame); + rz_list_append (list, frame); } for (i=1; ibtdepth; i++) { @@ -76,12 +76,12 @@ static RList *backtrace_x86_32_anal(RDebug *dbg, ut64 at) { // TODO: arch_is_call() here and this fun will be portable if (buf[(ebp2-5)%4]==0xe8) { - frame = R_NEW0 (RDebugFrame); + frame = R_NEW0 (RzDebugFrame); frame->addr = ebp2; frame->size = esp - _esp; frame->sp = _esp; frame->bp = _esp + frame->size; - r_list_append (list, frame); + rz_list_append (list, frame); } esp += 4; } diff --git a/libr/debug/p/native/darwin.c b/librz/debug/p/native/darwin.c similarity index 100% rename from libr/debug/p/native/darwin.c rename to librz/debug/p/native/darwin.c diff --git a/libr/debug/p/native/drx.c b/librz/debug/p/native/drx.c similarity index 92% rename from libr/debug/p/native/drx.c rename to librz/debug/p/native/drx.c index 741fb20b3f..94dabb25db 100644 --- a/libr/debug/p/native/drx.c +++ b/librz/debug/p/native/drx.c @@ -1,4 +1,4 @@ -#include +#include /* -------------------- drx.h ------------------- */ #define DRXN 8 @@ -204,22 +204,22 @@ void drx_enable(drxt *r, int n, int enabled) { } } -bool drx_add(RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { +bool drx_add(RzDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { if (bp->nhwbps < 4) { - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); - r_debug_drx_set (dbg, bp->nhwbps, b->addr, b->size, b->perm, 0); - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_set (dbg, bp->nhwbps, b->addr, b->size, b->perm, 0); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); bp->nhwbps++; return true; } return false; } -bool drx_del(RDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { +bool drx_del(RzDebug *dbg, RBreakpoint *bp, RBreakpointItem *b) { if (bp->nhwbps > 0) { - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); - r_debug_drx_unset (dbg, bp->nhwbps - 1); - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); + rz_debug_drx_unset (dbg, bp->nhwbps - 1); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); bp->nhwbps--; } return true; diff --git a/libr/debug/p/native/linux/linux_coredump.c b/librz/debug/p/native/linux/linux_coredump.c similarity index 91% rename from libr/debug/p/native/linux/linux_coredump.c rename to librz/debug/p/native/linux/linux_coredump.c index ea12215b8b..ada2acfd1c 100644 --- a/libr/debug/p/native/linux/linux_coredump.c +++ b/librz/debug/p/native/linux/linux_coredump.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2016 - Oscar Salvador */ -#include +#include #if DEBUGGER @@ -51,7 +51,7 @@ static bool is_a_kernel_mapping(const char *name) { static char *prpsinfo_get_psargs(char *buffer, int len) { char paux[ELF_PRARGSZ]; int i, bytes_left; - char *p = r_mem_dup (buffer, len); + char *p = rz_mem_dup (buffer, len); if (!p) { return NULL; } @@ -73,7 +73,7 @@ static char *prpsinfo_get_psargs(char *buffer, int len) { return p; } -static prpsinfo_t *linux_get_prpsinfo(RDebug *dbg, proc_per_process_t *proc_data) { +static prpsinfo_t *linux_get_prpsinfo(RzDebug *dbg, proc_per_process_t *proc_data) { const char *prog_states = "RSDTZW"; /* fs/binfmt_elf.c from kernel */ const char *basename = NULL; char *buffer, *pfname = NULL, *ppsargs = NULL, *file = NULL; @@ -90,7 +90,7 @@ static prpsinfo_t *linux_get_prpsinfo(RDebug *dbg, proc_per_process_t *proc_data p->pr_pid = mypid = dbg->pid; /* Start filling pr_fname and pr_psargs */ file = sdb_fmt ("/proc/%d/cmdline", mypid); - buffer = r_file_slurp (file, &len); + buffer = rz_file_slurp (file, &len); if (!buffer) { eprintf ("buffer NULL\n"); goto error; @@ -100,7 +100,7 @@ static prpsinfo_t *linux_get_prpsinfo(RDebug *dbg, proc_per_process_t *proc_data if (!pfname) { goto error; } - basename = r_file_basename (pfname); + basename = rz_file_basename (pfname); strncpy (p->pr_fname, basename, sizeof (p->pr_fname)); p->pr_fname[sizeof (p->pr_fname) - 1] = 0; ppsargs = prpsinfo_get_psargs (buffer, (int)len); @@ -137,7 +137,7 @@ static proc_per_thread_t *get_proc_thread_content(int pid, int tid) { size_t size; const char * file = sdb_fmt ("/proc/%d/task/%d/stat", pid, tid); - char *buff = r_file_slurp (file, &size); + char *buff = rz_file_slurp (file, &size); if (!buff) { return NULL; } @@ -163,7 +163,7 @@ static proc_per_thread_t *get_proc_thread_content(int pid, int tid) { /* /proc/[pid]/status for uid, gid, sigpend and sighold */ file = sdb_fmt ("/proc/%d/task/%d/status", pid, tid); - buff = r_file_slurp (file, &size); + buff = rz_file_slurp (file, &size); if (!buff) { free (t); return NULL; @@ -198,7 +198,7 @@ static proc_per_thread_t *get_proc_thread_content(int pid, int tid) { return t; } -static prstatus_t *linux_get_prstatus(RDebug *dbg, int pid, int tid, proc_content_t *proc_data, short int signr) { +static prstatus_t *linux_get_prstatus(RzDebug *dbg, int pid, int tid, proc_content_t *proc_data, short int signr) { elf_gregset_t regs; prstatus_t *p; @@ -226,7 +226,7 @@ static prstatus_t *linux_get_prstatus(RDebug *dbg, int pid, int tid, proc_conten p->pr_cstime.tv_sec = proc_data->per_thread->cstime / 1000; p->pr_cstime.tv_usec = (proc_data->per_thread->cstime % 1000) / 1000; - if (r_debug_ptrace (dbg, PTRACE_GETREGS, tid, NULL, ®s) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETREGS, tid, NULL, ®s) < 0) { perror ("PTRACE_GETREGS"); R_FREE (proc_data->per_thread); free (p); @@ -237,10 +237,10 @@ static prstatus_t *linux_get_prstatus(RDebug *dbg, int pid, int tid, proc_conten return p; } -static elf_fpregset_t *linux_get_fp_regset(RDebug *dbg, int pid) { +static elf_fpregset_t *linux_get_fp_regset(RzDebug *dbg, int pid) { elf_fpregset_t *p = R_NEW0 (elf_fpregset_t); if (p) { - if (r_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, p) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, p) < 0) { perror ("PTRACE_GETFPREGS"); free (p); return NULL; @@ -250,12 +250,12 @@ static elf_fpregset_t *linux_get_fp_regset(RDebug *dbg, int pid) { return NULL; } -static siginfo_t *linux_get_siginfo(RDebug *dbg, int pid) { +static siginfo_t *linux_get_siginfo(RzDebug *dbg, int pid) { siginfo_t *siginfo = R_NEW0 (siginfo_t); if (!siginfo) { return NULL; } - int ret = r_debug_ptrace (dbg, PTRACE_GETSIGINFO, pid, 0, (r_ptrace_data_t)(size_t)siginfo); + int ret = rz_debug_ptrace (dbg, PTRACE_GETSIGINFO, pid, 0, (rz_ptrace_data_t)(size_t)siginfo); if (ret == -1 || !siginfo->si_signo) { perror ("PTRACE_GETSIGINFO"); free (siginfo); @@ -301,7 +301,7 @@ static char *isAnonymousKeyword(const char *pp) { static bool has_map_anonymous_content(char *buff_smaps, unsigned long start_addr, unsigned long end_addr) { char *p, *pp, *extern_tok, *keyw = NULL; - char *identity = r_str_newf (fmt_addr, start_addr, end_addr); + char *identity = rz_str_newf (fmt_addr, start_addr, end_addr); char *str = strdup (buff_smaps); bool is_anonymous; @@ -326,7 +326,7 @@ static bool has_map_anonymous_content(char *buff_smaps, unsigned long start_addr static bool dump_this_map(char *buff_smaps, linux_map_entry_t *entry, ut8 filter_flags) { char *p, *pp, *ppp, *extern_tok, *flags_str = NULL; - char *identity = r_str_newf (fmt_addr, entry->start_addr, entry->end_addr); + char *identity = rz_str_newf (fmt_addr, entry->start_addr, entry->end_addr); bool found = false; char *aux = NULL; ut8 vmflags = 0, perms = entry->perms; @@ -477,33 +477,33 @@ static void clean_maps(linux_map_entry_t *h) { } } -static linux_map_entry_t *linux_get_mapped_files(RDebug *dbg, ut8 filter_flags) { +static linux_map_entry_t *linux_get_mapped_files(RzDebug *dbg, ut8 filter_flags) { linux_map_entry_t *me_head = NULL, *me_tail = NULL; - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; bool is_anonymous = false, is_deleted = false, ret = 0; char *file = NULL, *buff_maps= NULL, *buff_smaps = NULL; size_t size_file = 0; - file = r_str_newf ("/proc/%d/smaps", dbg->pid); - buff_smaps = r_file_slurp (file, &size_file); + file = rz_str_newf ("/proc/%d/smaps", dbg->pid); + buff_smaps = rz_file_slurp (file, &size_file); if (!buff_smaps) { goto error; } R_FREE (file); - file = r_str_newf ("/proc/%d/maps", dbg->pid); - buff_maps = r_file_slurp (file, &size_file); + file = rz_str_newf ("/proc/%d/maps", dbg->pid); + buff_maps = rz_file_slurp (file, &size_file); if (!buff_maps) { goto error; } R_FREE (file); - ret = r_debug_map_sync (dbg); + ret = rz_debug_map_sync (dbg); if (!ret) { goto error; } - r_list_foreach (dbg->maps, iter, map) { + rz_list_foreach (dbg->maps, iter, map) { linux_map_entry_t *pmentry = R_NEW0 (linux_map_entry_t); if (!pmentry) { goto error; @@ -560,14 +560,14 @@ error: return NULL; } -static auxv_buff_t *linux_get_auxv(RDebug *dbg) { +static auxv_buff_t *linux_get_auxv(RzDebug *dbg) { char *buff = NULL; auxv_buff_t *auxv = NULL; int auxv_entries; size_t size; const char *file = sdb_fmt ("/proc/%d/auxv", dbg->pid); - buff = r_file_slurp (file, &size); + buff = rz_file_slurp (file, &size); if (!buff) { return NULL; } @@ -580,7 +580,7 @@ static auxv_buff_t *linux_get_auxv(RDebug *dbg) { return NULL; } auxv->size = size; - auxv->data = r_mem_dup (buff, (int)size); + auxv->data = rz_mem_dup (buff, (int)size); if (!auxv->data) { free (buff); free (auxv); @@ -659,7 +659,7 @@ static int get_info_mappings(linux_map_entry_t *me_head, size_t *maps_size) { } static bool dump_elf_header(RBuffer *dest, elf_hdr_t *hdr) { - return r_buf_append_bytes (dest, (const ut8*)hdr, hdr->e_ehsize); + return rz_buf_append_bytes (dest, (const ut8*)hdr, hdr->e_ehsize); } static void *get_ntfile_data(linux_map_entry_t *head) { @@ -716,7 +716,7 @@ static bool dump_elf_pheaders(RBuffer *dest, linux_map_entry_t *maps, elf_offset phdr.p_memsz = 0x0; phdr.p_align = 0x1; - if (!r_buf_append_bytes (dest, (const ut8 *)&phdr, sizeof (elf_phdr_t))) { + if (!rz_buf_append_bytes (dest, (const ut8 *)&phdr, sizeof (elf_phdr_t))) { return false; } @@ -736,7 +736,7 @@ static bool dump_elf_pheaders(RBuffer *dest, linux_map_entry_t *maps, elf_offset phdr.p_offset = offset_to_next; phdr.p_align = 0x1; offset_to_next += phdr.p_filesz == 0 ? 0 : phdr.p_filesz; - ret = r_buf_append_bytes (dest, (const ut8*)&phdr, sizeof (elf_phdr_t)); + ret = rz_buf_append_bytes (dest, (const ut8*)&phdr, sizeof (elf_phdr_t)); if (!ret) { return false; } @@ -748,10 +748,10 @@ static bool dump_elf_pheaders(RBuffer *dest, linux_map_entry_t *maps, elf_offset } static bool dump_elf_note(RBuffer *dest, void *note_data, size_t note_section_size) { - return r_buf_append_bytes (dest, (const ut8*)note_data, note_section_size); + return rz_buf_append_bytes (dest, (const ut8*)note_data, note_section_size); } -static bool dump_elf_map_content(RDebug *dbg, RBuffer *dest, linux_map_entry_t *head, pid_t pid) { +static bool dump_elf_map_content(RzDebug *dbg, RBuffer *dest, linux_map_entry_t *head, pid_t pid) { linux_map_entry_t *p; ut8 *map_content; size_t size; @@ -772,9 +772,9 @@ static bool dump_elf_map_content(RDebug *dbg, RBuffer *dest, linux_map_entry_t * if (!ret) { eprintf ("Problems reading %"PFMTSZd" bytes at %"PFMT64x"\n", size, (ut64)p->start_addr); } else { - ret = r_buf_append_bytes (dest, (const ut8*)map_content, size); + ret = rz_buf_append_bytes (dest, (const ut8*)map_content, size); if (!ret) { - eprintf ("r_buf_append_bytes - failed\n"); + eprintf ("rz_buf_append_bytes - failed\n"); } } free (map_content); @@ -783,7 +783,7 @@ static bool dump_elf_map_content(RDebug *dbg, RBuffer *dest, linux_map_entry_t * return true; } -static proc_per_process_t *get_proc_process_content (RDebug *dbg) { +static proc_per_process_t *get_proc_process_content (RzDebug *dbg) { proc_per_process_t *p; char *temp_p_uid, *temp_p_gid, *p_uid, *p_gid; ut16 filter_flags, default_filter_flags = 0x33; @@ -791,7 +791,7 @@ static proc_per_process_t *get_proc_process_content (RDebug *dbg) { const char *file = sdb_fmt ("/proc/%d/stat", dbg->pid); size_t size; - buff = r_file_slurp (file, &size); + buff = rz_file_slurp (file, &size); if (!buff) { return NULL; } @@ -823,7 +823,7 @@ static proc_per_process_t *get_proc_process_content (RDebug *dbg) { return NULL; } file = sdb_fmt ("/proc/%d/status", dbg->pid); - buff = r_file_slurp (file, &size); + buff = rz_file_slurp (file, &size); if (!buff) { free (p); return NULL; @@ -863,7 +863,7 @@ static proc_per_process_t *get_proc_process_content (RDebug *dbg) { free (buff); /* Check the coredump_filter value if we have*/ file = sdb_fmt ("/proc/%d/coredump_filter", dbg->pid); - buff = r_file_slurp (file, &size); + buff = rz_file_slurp (file, &size); if (buff) { sscanf (buff, "%hx", &filter_flags); p->coredump_filter = filter_flags; @@ -903,18 +903,18 @@ static elf_shdr_t *get_extra_sectionhdr(elf_hdr_t *elf_hdr, st64 offset, int n_s } static bool dump_elf_sheader_pxnum(RBuffer *dest, elf_shdr_t *shdr) { - return r_buf_append_bytes (dest, (const ut8 *)shdr, sizeof (*shdr)); + return rz_buf_append_bytes (dest, (const ut8 *)shdr, sizeof (*shdr)); } #if __i386__ -static elf_fpxregset_t *linux_get_fpx_regset (RDebug *dbg, int tid) { +static elf_fpxregset_t *linux_get_fpx_regset (RzDebug *dbg, int tid) { #ifdef PTRACE_GETREGSET struct iovec transfer; elf_fpxregset_t *fpxregset = R_NEW0 (elf_fpxregset_t); if (fpxregset) { transfer.iov_base = fpxregset; transfer.iov_len = sizeof (elf_fpxregset_t); - if (r_debug_ptrace (dbg, PTRACE_GETREGSET, tid, (void *)NT_PRXFPREG, &transfer) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETREGSET, tid, (void *)NT_PRXFPREG, &transfer) < 0) { perror ("linux_get_fpx_regset"); R_FREE (fpxregset); } @@ -927,7 +927,7 @@ static elf_fpxregset_t *linux_get_fpx_regset (RDebug *dbg, int tid) { #endif #if __i386__ || __x86_64__ -void *linux_get_xsave_data (RDebug *dbg, int tid, ut32 size) { +void *linux_get_xsave_data (RzDebug *dbg, int tid, ut32 size) { #ifdef PTRACE_GETREGSET struct iovec transfer; char *xsave_data = calloc (size, 1); @@ -936,7 +936,7 @@ void *linux_get_xsave_data (RDebug *dbg, int tid, ut32 size) { } transfer.iov_base = xsave_data; transfer.iov_len = size; - if (r_debug_ptrace (dbg, PTRACE_GETREGSET, tid, (void *)NT_X86_XSTATE, &transfer) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETREGSET, tid, (void *)NT_X86_XSTATE, &transfer) < 0) { perror ("linux_get_xsave_data"); free (xsave_data); return NULL; @@ -949,14 +949,14 @@ void *linux_get_xsave_data (RDebug *dbg, int tid, ut32 size) { #endif #if __arm__ || __arm64__ -void *linux_get_arm_vfp_data (RDebug *dbg, int tid) { +void *linux_get_arm_vfp_data (RzDebug *dbg, int tid) { #ifdef PTRACE_GETVFPREGS char *vfp_data = calloc (ARM_VFPREGS_SIZE + 1, 1); if (!vfp_data) { return NULL; } - if (r_debug_ptrace (dbg, PTRACE_GETVFPREGS, tid, 0, vfp_data) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETVFPREGS, tid, 0, vfp_data) < 0) { perror ("linux_get_arm_vfp_data"); free (vfp_data); return NULL; @@ -1032,10 +1032,10 @@ void write_note_hdr (note_type_t type, ut8 **note_data) { *note_data += size_note_hdr; } -static int *get_unique_thread_id (RDebug *dbg, int n_threads) { - RListIter *it; - RList *list; - RDebugPid *th; +static int *get_unique_thread_id (RzDebug *dbg, int n_threads) { + RzListIter *it; + RzList *list; + RzDebugPid *th; int *thread_id = NULL; int i = 0; bool found = false; @@ -1049,7 +1049,7 @@ static int *get_unique_thread_id (RDebug *dbg, int n_threads) { if (!thread_id) { return NULL; /* free list */ } - r_list_foreach (list, it, th) { + rz_list_foreach (list, it, th) { if (th->pid) { int j; for (j = 0; j < i && !found ; j++) { @@ -1063,7 +1063,7 @@ static int *get_unique_thread_id (RDebug *dbg, int n_threads) { thread_id[i] = th->pid; /* The main thread is already being traced */ if (th->pid != dbg->pid) { - if (r_debug_ptrace (dbg, PTRACE_ATTACH, thread_id[i], 0, 0) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_ATTACH, thread_id[i], 0, 0) < 0) { perror ("Could not attach to thread"); } } @@ -1077,18 +1077,18 @@ static int *get_unique_thread_id (RDebug *dbg, int n_threads) { return thread_id; } -void detach_threads (RDebug *dbg, int *thread_id, int n_threads) { +void detach_threads (RzDebug *dbg, int *thread_id, int n_threads) { int i; for(i = 0; i < n_threads ; i++) { if (dbg->pid != thread_id[i]) { - if (r_debug_ptrace (dbg, PTRACE_DETACH, thread_id[i], 0, 0) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_DETACH, thread_id[i], 0, 0) < 0) { perror ("PTRACE_DETACH"); } } } } -static ut8 *build_note_section(RDebug *dbg, elf_proc_note_t *elf_proc_note, proc_content_t *proc_data, size_t *section_size) { +static ut8 *build_note_section(RzDebug *dbg, elf_proc_note_t *elf_proc_note, proc_content_t *proc_data, size_t *section_size) { ut8 *note_data, *pnote_data; char *maps_data; int i, n_notes = 0, *thread_id; @@ -1336,7 +1336,7 @@ fail: } #if __i386__ || __x86_64__ -static int get_xsave_size(RDebug *dbg, int pid) { +static int get_xsave_size(RzDebug *dbg, int pid) { #ifdef PTRACE_GETREGSET struct iovec local; unsigned long xstate_hdr[XSTATE_HDR_SIZE/sizeof(unsigned long)]; @@ -1346,7 +1346,7 @@ static int get_xsave_size(RDebug *dbg, int pid) { We could also check this by cpuid instruction https://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits*/ local.iov_base = xstate_hdr; local.iov_len = sizeof (xstate_hdr); - if (r_debug_ptrace (dbg, PTRACE_GETREGSET, pid, (void *)NT_X86_XSTATE, &local) < 0) { + if (rz_debug_ptrace (dbg, PTRACE_GETREGSET, pid, (void *)NT_X86_XSTATE, &local) < 0) { perror ("NT_X86_XSTATE"); return 0; } @@ -1390,7 +1390,7 @@ static int get_arm_vfpregs_size(void) { } #endif -static void init_note_info_structure(RDebug *dbg, int pid, size_t auxv_size) { +static void init_note_info_structure(RzDebug *dbg, int pid, size_t auxv_size) { note_type_t type; int len_name_core = round_up (strlen ("CORE") + 1); int len_name_linux = round_up (strlen ("LINUX") + 1); @@ -1456,7 +1456,7 @@ static void init_note_info_structure(RDebug *dbg, int pid, size_t auxv_size) { #endif } -bool linux_generate_corefile (RDebug *dbg, RBuffer *dest) { +bool linux_generate_corefile (RzDebug *dbg, RBuffer *dest) { proc_content_t *proc_data = NULL; elf_proc_note_t *elf_proc_note = NULL; elf_shdr_t *shdr_pxnum = NULL; diff --git a/libr/debug/p/native/linux/linux_coredump.h b/librz/debug/p/native/linux/linux_coredump.h similarity index 97% rename from libr/debug/p/native/linux/linux_coredump.h rename to librz/debug/p/native/linux/linux_coredump.h index cb54a6d529..0a391ab7b2 100644 --- a/libr/debug/p/native/linux/linux_coredump.h +++ b/librz/debug/p/native/linux/linux_coredump.h @@ -211,7 +211,7 @@ extern ssize_t process_vm_readv(pid_t pid, const struct iovec *local_iov, unsigned long liovcnt, const struct iovec *remote_iov, unsigned long riovcnt, unsigned long flags); -bool linux_generate_corefile (RDebug *dbg, RBuffer *dest); -int linux_reg_read (RDebug *dbg, int type, ut8 *buf, int size); +bool linux_generate_corefile (RzDebug *dbg, RBuffer *dest); +int linux_reg_read (RzDebug *dbg, int type, ut8 *buf, int size); #endif diff --git a/libr/debug/p/native/linux/linux_debug.c b/librz/debug/p/native/linux/linux_debug.c similarity index 71% rename from libr/debug/p/native/linux/linux_debug.c rename to librz/debug/p/native/linux/linux_debug.c index 39c6b83d67..f295261229 100644 --- a/libr/debug/p/native/linux/linux_debug.c +++ b/librz/debug/p/native/linux/linux_debug.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include #if DEBUGGER -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -26,7 +26,7 @@ #define HAVE_YMM 0 #endif -char *linux_reg_profile (RDebug *dbg) { +char *linux_reg_profile (RzDebug *dbg) { #if __arm__ # include "reg/linux-arm.h" #elif __riscv @@ -63,27 +63,27 @@ char *linux_reg_profile (RDebug *dbg) { #endif } -static void linux_detach_all(RDebug *dbg); +static void linux_detach_all(RzDebug *dbg); static char *read_link(int pid, const char *file); -static bool linux_attach_single_pid(RDebug *dbg, int ptid); -static void linux_remove_thread(RDebug *dbg, int pid); -static void linux_add_new_thread(RDebug *dbg, int tid); -static bool linux_stop_thread(RDebug *dbg, int tid); +static bool linux_attach_single_pid(RzDebug *dbg, int ptid); +static void linux_remove_thread(RzDebug *dbg, int pid); +static void linux_add_new_thread(RzDebug *dbg, int tid); +static bool linux_stop_thread(RzDebug *dbg, int tid); static bool linux_kill_thread(int tid, int signo); -static void linux_dbg_wait_break_main(RDebug *dbg); -static void linux_dbg_wait_break(RDebug *dbg); -static RDebugReasonType linux_handle_new_task(RDebug *dbg, int tid); +static void linux_dbg_wait_break_main(RzDebug *dbg); +static void linux_dbg_wait_break(RzDebug *dbg); +static RzDebugReasonType linux_handle_new_task(RzDebug *dbg, int tid); -int linux_handle_signals(RDebug *dbg, int tid) { +int linux_handle_signals(RzDebug *dbg, int tid) { siginfo_t siginfo = { 0 }; - int ret = r_debug_ptrace (dbg, PTRACE_GETSIGINFO, tid, 0, (r_ptrace_data_t)(size_t)&siginfo); + int ret = rz_debug_ptrace (dbg, PTRACE_GETSIGINFO, tid, 0, (rz_ptrace_data_t)(size_t)&siginfo); if (ret == -1) { /* ESRCH means the process already went away :-/ */ if (errno == ESRCH) { dbg->reason.type = R_DEBUG_REASON_DEAD; return true; } - r_sys_perror ("ptrace GETSIGINFO"); + rz_sys_perror ("ptrace GETSIGINFO"); return false; } @@ -100,22 +100,22 @@ int linux_handle_signals(RDebug *dbg, int tid) { case SIGTRAP: { if (dbg->glob_libs || dbg->glob_unlibs) { - ut64 pc_addr = r_debug_reg_get (dbg, "PC"); - RBreakpointItem *b = r_bp_get_at (dbg->bp, pc_addr - dbg->bpsize); + ut64 pc_addr = rz_debug_reg_get (dbg, "PC"); + RBreakpointItem *b = rz_bp_get_at (dbg->bp, pc_addr - dbg->bpsize); if (b && b->internal) { char *p = strstr (b->data, "dbg."); if (p) { - if (r_str_startswith (p, "dbg.libs")) { + if (rz_str_startswith (p, "dbg.libs")) { const char *name; if (strstr (b->data, "sym.imp.dlopen")) { - name = r_reg_get_name (dbg->reg, R_REG_NAME_A0); + name = rz_reg_get_name (dbg->reg, R_REG_NAME_A0); } else { - name = r_reg_get_name (dbg->reg, R_REG_NAME_A1); + name = rz_reg_get_name (dbg->reg, R_REG_NAME_A1); } - b->data = r_str_appendf (b->data, ";ps@r:%s", name); + b->data = rz_str_appendf (b->data, ";ps@r:%s", name); dbg->reason.type = R_DEBUG_REASON_NEW_LIB; break; - } else if (r_str_startswith (p, "dbg.unlibs")) { + } else if (rz_str_startswith (p, "dbg.unlibs")) { dbg->reason.type = R_DEBUG_REASON_EXIT_LIB; break; } @@ -130,7 +130,7 @@ int linux_handle_signals(RDebug *dbg, int tid) { dbg->reason.bp_addr = (ut64)(size_t)siginfo.si_addr; dbg->reason.type = R_DEBUG_REASON_BREAKPOINT; // Switch to the thread that hit the breakpoint - r_debug_select (dbg, dbg->pid, tid); + rz_debug_select (dbg, dbg->pid, tid); dbg->tid = tid; } } @@ -151,7 +151,7 @@ int linux_handle_signals(RDebug *dbg, int tid) { break; } if (dbg->reason.signum != SIGTRAP && - (dbg->reason.signum != SIGINT || !r_cons_is_breaked ())) { + (dbg->reason.signum != SIGINT || !rz_cons_is_breaked ())) { eprintf ("[+] SIGNAL %d errno=%d addr=0x%08"PFMT64x " code=%d si_pid=%d ret=%d\n", siginfo.si_signo, siginfo.si_errno, @@ -169,8 +169,8 @@ int linux_handle_signals(RDebug *dbg, int tid) { // Used to remove breakpoints before detaching from a fork, without it the child // will die upon hitting a breakpoint while not being traced -static void linux_remove_fork_bps(RDebug *dbg) { - RListIter *iter; +static void linux_remove_fork_bps(RzDebug *dbg) { + RzListIter *iter; RBreakpointItem *b; int prev_pid = dbg->pid; int prev_tid = dbg->tid; @@ -178,26 +178,26 @@ static void linux_remove_fork_bps(RDebug *dbg) { // Set dbg tid to the new child temporarily dbg->pid = dbg->forked_pid; dbg->tid = dbg->forked_pid; - r_debug_select (dbg, dbg->forked_pid, dbg->forked_pid); + rz_debug_select (dbg, dbg->forked_pid, dbg->forked_pid); // Unset all hw breakpoints in the child process - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); - r_list_foreach (dbg->bp->bps, iter, b) { - r_debug_drx_unset (dbg, r_bp_get_index_at (dbg->bp, b->addr)); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, false); + rz_list_foreach (dbg->bp->bps, iter, b) { + rz_debug_drx_unset (dbg, rz_bp_get_index_at (dbg->bp, b->addr)); } - r_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); + rz_debug_reg_sync (dbg, R_REG_TYPE_DRX, true); // Unset software breakpoints in the child process - r_debug_bp_update (dbg); - r_bp_restore (dbg->bp, false); + rz_debug_bp_update (dbg); + rz_bp_restore (dbg->bp, false); // Return to the parent dbg->pid = prev_pid; dbg->tid = prev_tid; - r_debug_select (dbg, dbg->pid, dbg->pid); + rz_debug_select (dbg, dbg->pid, dbg->pid); // Restore sw breakpoints in the parent - r_bp_restore (dbg->bp, true); + rz_bp_restore (dbg->bp, true); } #ifdef PT_GETEVENTMSG @@ -205,13 +205,13 @@ static void linux_remove_fork_bps(RDebug *dbg) { * @brief Handle PTRACE_EVENT_* when receiving SIGTRAP * * @param dowait Do waitpid to consume any signal in the newly created task - * @return RDebugReasonType, + * @return RzDebugReasonType, * - R_DEBUG_REASON_UNKNOWN if the ptrace_event cannot be handled, * - R_DEBUG_REASON_ERROR if a ptrace command failed. * * NOTE: This API was added in Linux 2.5.46 */ -RDebugReasonType linux_ptrace_event (RDebug *dbg, int ptid, int status, bool dowait) { +RzDebugReasonType linux_ptrace_event (RzDebug *dbg, int ptid, int status, bool dowait) { ut32 pt_evt; #if __powerpc64__ || __arm64__ || __aarch64__ || __x86_64__ ut64 data; @@ -230,8 +230,8 @@ RDebugReasonType linux_ptrace_event (RDebug *dbg, int ptid, int status, bool dow break; case PTRACE_EVENT_CLONE: // Get the tid of the new thread - if (r_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (r_ptrace_data_t)(size_t)&data) == -1) { - r_sys_perror ("ptrace GETEVENTMSG"); + if (rz_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (rz_ptrace_data_t)(size_t)&data) == -1) { + rz_sys_perror ("ptrace GETEVENTMSG"); return R_DEBUG_REASON_ERROR; } if (dowait) { @@ -244,15 +244,15 @@ RDebugReasonType linux_ptrace_event (RDebug *dbg, int ptid, int status, bool dow linux_add_new_thread (dbg, (int)data); if (dbg->trace_clone) { - r_debug_select (dbg, dbg->pid, (int)data); + rz_debug_select (dbg, dbg->pid, (int)data); } eprintf ("(%d) Created thread %d\n", ptid, (int)data); return R_DEBUG_REASON_NEW_TID; case PTRACE_EVENT_VFORK: case PTRACE_EVENT_FORK: // Get the pid of the new process - if (r_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (r_ptrace_data_t)(size_t)&data) == -1) { - r_sys_perror ("ptrace GETEVENTMSG"); + if (rz_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (rz_ptrace_data_t)(size_t)&data) == -1) { + rz_sys_perror ("ptrace GETEVENTMSG"); return R_DEBUG_REASON_ERROR; } dbg->forked_pid = data; @@ -268,15 +268,15 @@ RDebugReasonType linux_ptrace_event (RDebug *dbg, int ptid, int status, bool dow // We need to do this even if the new process will be detached since the // breakpoints are inherited from the parent linux_remove_fork_bps (dbg); - if (r_debug_ptrace (dbg, PTRACE_DETACH, dbg->forked_pid, NULL, (r_ptrace_data_t)(size_t)NULL) == -1) { + if (rz_debug_ptrace (dbg, PTRACE_DETACH, dbg->forked_pid, NULL, (rz_ptrace_data_t)(size_t)NULL) == -1) { perror ("PTRACE_DETACH"); } } return R_DEBUG_REASON_NEW_PID; case PTRACE_EVENT_EXIT: // Get the exit status of the exiting task - if (r_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (r_ptrace_data_t)(size_t)&data) == -1) { - r_sys_perror ("ptrace GETEVENTMSG"); + if (rz_debug_ptrace (dbg, PTRACE_GETEVENTMSG, ptid, 0, (rz_ptrace_data_t)(size_t)&data) == -1) { + rz_sys_perror ("ptrace GETEVENTMSG"); return R_DEBUG_REASON_ERROR; } //TODO: Check other processes exit if dbg->trace_forks is on @@ -300,21 +300,21 @@ RDebugReasonType linux_ptrace_event (RDebug *dbg, int ptid, int status, bool dow * handle the pending SIGTRAP with PTRACE_EVENT_* * * @param tid, TID of the new task - * @return RDebugReasonType, Debug reason + * @return RzDebugReasonType, Debug reason */ -static RDebugReasonType linux_handle_new_task(RDebug *dbg, int tid) { +static RzDebugReasonType linux_handle_new_task(RzDebug *dbg, int tid) { int ret, status; if (dbg->threads) { - RDebugPid *th; - RListIter *it; + RzDebugPid *th; + RzListIter *it; // Search for SIGTRAP with PTRACE_EVENT_* in other threads. - r_list_foreach (dbg->threads, it, th) { + rz_list_foreach (dbg->threads, it, th) { if (th->pid == tid) { continue; } // Retrieve the signal without consuming it with PTRACE_GETSIGINFO siginfo_t siginfo = { 0 }; - ret = r_debug_ptrace (dbg, PTRACE_GETSIGINFO, th->pid, 0, (r_ptrace_data_t)(size_t)&siginfo); + ret = rz_debug_ptrace (dbg, PTRACE_GETSIGINFO, th->pid, 0, (rz_ptrace_data_t)(size_t)&siginfo); // Skip if PTRACE_GETSIGINFO fails when the thread is running. if (ret == -1) { continue; @@ -341,10 +341,10 @@ static RDebugReasonType linux_handle_new_task(RDebug *dbg, int tid) { return R_DEBUG_REASON_UNKNOWN; } -int linux_step(RDebug *dbg) { +int linux_step(RzDebug *dbg) { int ret = false; int pid = dbg->tid; - ret = r_debug_ptrace (dbg, PTRACE_SINGLESTEP, pid, 0, 0); + ret = rz_debug_ptrace (dbg, PTRACE_SINGLESTEP, pid, 0, 0); //XXX(jjd): why?? //linux_handle_signals (dbg); if (ret == -1) { perror ("native-singlestep"); @@ -355,7 +355,7 @@ int linux_step(RDebug *dbg) { return ret; } -bool linux_set_options(RDebug *dbg, int pid) { +bool linux_set_options(RzDebug *dbg, int pid) { int traceflags = 0; traceflags |= PTRACE_O_TRACEFORK; traceflags |= PTRACE_O_TRACEVFORK; @@ -374,22 +374,22 @@ bool linux_set_options(RDebug *dbg, int pid) { // PTRACE_SETOPTIONS can fail because of the asynchronous nature of ptrace // If the target is traced, the loop will always end with success - while (r_debug_ptrace (dbg, PTRACE_SETOPTIONS, pid, 0, (r_ptrace_data_t)(size_t)traceflags) == -1) { - void *bed = r_cons_sleep_begin (); + while (rz_debug_ptrace (dbg, PTRACE_SETOPTIONS, pid, 0, (rz_ptrace_data_t)(size_t)traceflags) == -1) { + void *bed = rz_cons_sleep_begin (); usleep (1000); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); } return true; } -static void linux_detach_all(RDebug *dbg) { - RList *th_list = dbg->threads; +static void linux_detach_all(RzDebug *dbg) { + RzList *th_list = dbg->threads; if (th_list) { - RDebugPid *th; - RListIter *it; - r_list_foreach (th_list, it, th) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (th_list, it, th) { if (th->pid != dbg->main_pid) { - if (r_debug_ptrace (dbg, PTRACE_DETACH, th->pid, NULL, (r_ptrace_data_t)(size_t)NULL) == -1) { + if (rz_debug_ptrace (dbg, PTRACE_DETACH, th->pid, NULL, (rz_ptrace_data_t)(size_t)NULL) == -1) { perror ("PTRACE_DETACH"); } } @@ -397,18 +397,18 @@ static void linux_detach_all(RDebug *dbg) { } // Detaching from main proc - if (r_debug_ptrace (dbg, PTRACE_DETACH, dbg->main_pid, NULL, (r_ptrace_data_t)(size_t)NULL) == -1) { + if (rz_debug_ptrace (dbg, PTRACE_DETACH, dbg->main_pid, NULL, (rz_ptrace_data_t)(size_t)NULL) == -1) { perror ("PTRACE_DETACH"); } } -static void linux_remove_thread(RDebug *dbg, int tid) { +static void linux_remove_thread(RzDebug *dbg, int tid) { if (dbg->threads) { - RDebugPid *th; - RListIter *it; - r_list_foreach (dbg->threads, it, th) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { if (th->pid == tid) { - r_list_delete (dbg->threads, it); + rz_list_delete (dbg->threads, it); dbg->n_threads--; break; } @@ -416,17 +416,17 @@ static void linux_remove_thread(RDebug *dbg, int tid) { } } -bool linux_select(RDebug *dbg, int pid, int tid) { +bool linux_select(RzDebug *dbg, int pid, int tid) { if (dbg->pid != -1 && dbg->pid != pid) { return linux_attach_new_process (dbg, pid); } return linux_attach (dbg, tid); } -bool linux_attach_new_process(RDebug *dbg, int pid) { +bool linux_attach_new_process(RzDebug *dbg, int pid) { linux_detach_all (dbg); if (dbg->threads) { - r_list_free (dbg->threads); + rz_list_free (dbg->threads); dbg->threads = NULL; } @@ -437,21 +437,21 @@ bool linux_attach_new_process(RDebug *dbg, int pid) { // Call select to syncrhonize the thread's data. dbg->pid = pid; dbg->tid = pid; - r_debug_select (dbg, pid, pid); + rz_debug_select (dbg, pid, pid); return true; } -static void linux_dbg_wait_break_main(RDebug *dbg) { +static void linux_dbg_wait_break_main(RzDebug *dbg) { // Get the debugger and debuggee process group ID pid_t dpgid = getpgid (0); if (dpgid == -1) { - r_sys_perror ("getpgid"); + rz_sys_perror ("getpgid"); return; } pid_t tpgid = getpgid (dbg->pid); if (tpgid == -1) { - r_sys_perror ("getpgid"); + rz_sys_perror ("getpgid"); return; } @@ -468,14 +468,14 @@ static void linux_dbg_wait_break_main(RDebug *dbg) { } } -static void linux_dbg_wait_break(RDebug *dbg) { +static void linux_dbg_wait_break(RzDebug *dbg) { if (!linux_kill_thread (dbg->pid, SIGINT)) { eprintf ("Could not interrupt pid (%d)\n", dbg->pid); } } -RDebugReasonType linux_dbg_wait(RDebug *dbg, int pid) { - RDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; +RzDebugReasonType linux_dbg_wait(RzDebug *dbg, int pid) { + RzDebugReasonType reason = R_DEBUG_REASON_UNKNOWN; int tid; int status, flags = __WALL; int ret = -1; @@ -488,19 +488,19 @@ RDebugReasonType linux_dbg_wait(RDebug *dbg, int pid) { // In the main context, SIGINT is propagated to the debuggee if it is // in the same process group. Otherwise, the task is running in // background and SIGINT will not be propagated to the debuggee. - if (r_cons_context_is_main ()) { - r_cons_break_push ((RConsBreak)linux_dbg_wait_break_main, dbg); + if (rz_cons_context_is_main ()) { + rz_cons_break_push ((RzConsBreak)linux_dbg_wait_break_main, dbg); } else { - r_cons_break_push ((RConsBreak)linux_dbg_wait_break, dbg); + rz_cons_break_push ((RzConsBreak)linux_dbg_wait_break, dbg); } - void *bed = r_cons_sleep_begin (); + void *bed = rz_cons_sleep_begin (); if (dbg->continue_all_threads) { ret = waitpid (-1, &status, flags); } else { ret = waitpid (pid, &status, flags); } - r_cons_sleep_end (bed); - r_cons_break_pop (); + rz_cons_sleep_end (bed); + rz_cons_break_pop (); if (ret < 0) { // Continue when interrupted by user; @@ -523,7 +523,7 @@ RDebugReasonType linux_dbg_wait(RDebug *dbg, int pid) { if (WIFEXITED (status)) { if (tid == dbg->main_pid) { - r_list_free (dbg->threads); + rz_list_free (dbg->threads); dbg->threads = NULL; reason = R_DEBUG_REASON_DEAD; eprintf ("(%d) Process terminated with status %d\n", tid, WEXITSTATUS (status)); @@ -539,7 +539,7 @@ RDebugReasonType linux_dbg_wait(RDebug *dbg, int pid) { } else if (WIFSTOPPED (status)) { // If tid is not in the thread list and stopped by SIGSTOP, // handle it as a new task. - if (!r_list_find (dbg->threads, &tid, &match_pid) && + if (!rz_list_find (dbg->threads, &tid, &match_pid) && WSTOPSIG (status) == SIGSTOP) { reason = linux_handle_new_task (dbg, tid); if (reason != R_DEBUG_REASON_UNKNOWN) { @@ -582,22 +582,22 @@ RDebugReasonType linux_dbg_wait(RDebug *dbg, int pid) { int match_pid(const void *pid_o, const void *th_o) { int pid = *(int *)pid_o; - RDebugPid *th = (RDebugPid *)th_o; + RzDebugPid *th = (RzDebugPid *)th_o; return (pid == th->pid)? 0 : 1; } -static void linux_add_new_thread(RDebug *dbg, int tid) { +static void linux_add_new_thread(RzDebug *dbg, int tid) { int uid = getuid(); // XXX char info[1024] = {0}; - RDebugPid *tid_info; + RzDebugPid *tid_info; if (!procfs_pid_slurp (tid, "status", info, sizeof (info))) { tid_info = fill_pid_info (info, NULL, tid); } else { - tid_info = r_debug_pid_new ("new_path", tid, uid, 's', 0); + tid_info = rz_debug_pid_new ("new_path", tid, uid, 's', 0); } linux_set_options (dbg, tid); - r_list_append (dbg->threads, tid_info); + rz_list_append (dbg->threads, tid_info); dbg->n_threads++; } @@ -612,13 +612,13 @@ static bool linux_kill_thread(int tid, int signo) { return true; } -static bool linux_stop_thread(RDebug *dbg, int tid) { +static bool linux_stop_thread(RzDebug *dbg, int tid) { int status, ret; siginfo_t siginfo = { 0 }; // Return if the thread is already stopped - ret = r_debug_ptrace (dbg, PTRACE_GETSIGINFO, tid, 0, - (r_ptrace_data_t) (intptr_t)&siginfo); + ret = rz_debug_ptrace (dbg, PTRACE_GETSIGINFO, tid, 0, + (rz_ptrace_data_t) (intptr_t)&siginfo); if (ret == 0) { return true; } @@ -632,12 +632,12 @@ static bool linux_stop_thread(RDebug *dbg, int tid) { return false; } -bool linux_stop_threads(RDebug *dbg, int except) { +bool linux_stop_threads(RzDebug *dbg, int except) { bool ret = true; if (dbg->threads) { - RDebugPid *th; - RListIter *it; - r_list_foreach (dbg->threads, it, th) { + RzDebugPid *th; + RzListIter *it; + rz_list_foreach (dbg->threads, it, th) { if (th->pid && th->pid != except) { if (!linux_stop_thread (dbg, th->pid)) { ret = false; @@ -648,7 +648,7 @@ bool linux_stop_threads(RDebug *dbg, int except) { return ret; } -static bool linux_attach_single_pid(RDebug *dbg, int ptid) { +static bool linux_attach_single_pid(RzDebug *dbg, int ptid) { siginfo_t sig = { 0 }; if (ptid < 0) { @@ -659,9 +659,9 @@ static bool linux_attach_single_pid(RDebug *dbg, int ptid) { // Attaching to a process that has already been started with PTRACE_TRACEME. // sets errno to "Operation not permitted" which may be misleading. // GETSIGINFO can be called multiple times and would fail without attachment. - if (r_debug_ptrace (dbg, PTRACE_GETSIGINFO, ptid, NULL, - (r_ptrace_data_t)&sig) == -1) { - if (r_debug_ptrace (dbg, PTRACE_ATTACH, ptid, NULL, NULL) == -1) { + if (rz_debug_ptrace (dbg, PTRACE_GETSIGINFO, ptid, NULL, + (rz_ptrace_data_t)&sig) == -1) { + if (rz_debug_ptrace (dbg, PTRACE_ATTACH, ptid, NULL, NULL) == -1) { perror ("ptrace (PT_ATTACH)"); return false; } @@ -681,8 +681,8 @@ static bool linux_attach_single_pid(RDebug *dbg, int ptid) { return true; } -static RList *get_pid_thread_list(RDebug *dbg, int main_pid) { - RList *list = r_list_new (); +static RzList *get_pid_thread_list(RzDebug *dbg, int main_pid) { + RzList *list = rz_list_new (); if (list) { list = linux_thread_list (dbg, main_pid, list); dbg->main_pid = main_pid; @@ -690,14 +690,14 @@ static RList *get_pid_thread_list(RDebug *dbg, int main_pid) { return list; } -int linux_attach(RDebug *dbg, int pid) { +int linux_attach(RzDebug *dbg, int pid) { // First time we run: We try to attach to all "possible" threads and to the main pid if (!dbg->threads) { dbg->threads = get_pid_thread_list (dbg, pid); } else { // This means we did a first run, so we probably attached to all possible threads already. // So check if the requested thread is being traced already. If not, attach it - if (!r_list_find (dbg->threads, &pid, &match_pid)) { + if (!rz_list_find (dbg->threads, &pid, &match_pid)) { linux_attach_single_pid (dbg, pid); } } @@ -717,28 +717,28 @@ static char *read_link(int pid, const char *file) { return NULL; } -RDebugInfo *linux_info(RDebug *dbg, const char *arg) { +RzDebugInfo *linux_info(RzDebug *dbg, const char *arg) { char proc_buff[1024]; - RDebugInfo *rdi = R_NEW0 (RDebugInfo); + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) { return NULL; } - RList *th_list; + RzList *th_list; bool list_alloc = false; if (dbg->threads) { th_list = dbg->threads; } else { - th_list = r_list_new (); + th_list = rz_list_new (); list_alloc = true; if (th_list) { th_list = linux_thread_list (dbg, dbg->pid, th_list); } } - RDebugPid *th; - RListIter *it; + RzDebugPid *th; + RzListIter *it; bool found = false; - r_list_foreach (th_list, it, th) { + rz_list_foreach (th_list, it, th) { if (th->pid == dbg->pid) { found = true; break; @@ -751,18 +751,18 @@ RDebugInfo *linux_info(RDebug *dbg, const char *arg) { rdi->cwd = read_link (rdi->pid, "cwd"); rdi->exe = read_link (rdi->pid, "exe"); snprintf (proc_buff, sizeof (proc_buff), "/proc/%d/cmdline", rdi->pid); - rdi->cmdline = r_file_slurp (proc_buff, NULL); + rdi->cmdline = rz_file_slurp (proc_buff, NULL); snprintf (proc_buff, sizeof (proc_buff), "/proc/%d/stack", rdi->pid); - rdi->kernel_stack = r_file_slurp (proc_buff, NULL); + rdi->kernel_stack = rz_file_slurp (proc_buff, NULL); rdi->status = found ? th->status : R_DBG_PROC_STOP; if (list_alloc) { - r_list_free (th_list); + rz_list_free (th_list); } return rdi; } -RDebugPid *fill_pid_info(const char *info, const char *path, int tid) { - RDebugPid *pid_info = R_NEW0 (RDebugPid); +RzDebugPid *fill_pid_info(const char *info, const char *path, int tid) { + RzDebugPid *pid_info = R_NEW0 (RzDebugPid); if (!pid_info) { return NULL; } @@ -810,17 +810,17 @@ RDebugPid *fill_pid_info(const char *info, const char *path, int tid) { return pid_info; } -RList *linux_pid_list(int pid, RList *list) { - list->free = (RListFree)&r_debug_pid_free; +RzList *linux_pid_list(int pid, RzList *list) { + list->free = (RzListFree)&rz_debug_pid_free; DIR *dh = NULL; struct dirent *de = NULL; char path[PATH_MAX], info[PATH_MAX]; int i = -1; - RDebugPid *pid_info = NULL; + RzDebugPid *pid_info = NULL; dh = opendir ("/proc"); if (!dh) { - r_sys_perror ("opendir /proc"); - r_list_free (list); + rz_sys_perror ("opendir /proc"); + rz_list_free (list); return NULL; } while ((de = readdir (dh))) { @@ -836,33 +836,33 @@ RList *linux_pid_list(int pid, RList *list) { // Get information about pid (status, pc, etc.) pid_info = fill_pid_info (info, path, i); } else { - pid_info = r_debug_pid_new (path, i, 0, R_DBG_PROC_STOP, 0); + pid_info = rz_debug_pid_new (path, i, 0, R_DBG_PROC_STOP, 0); } // Unless pid 0 is requested, only add the requested pid and it's child processes if (0 == pid || i == pid || pid_info->ppid == pid) { - r_list_append (list, pid_info); + rz_list_append (list, pid_info); } } closedir (dh); return list; } -RList *linux_thread_list(RDebug *dbg, int pid, RList *list) { +RzList *linux_thread_list(RzDebug *dbg, int pid, RzList *list) { int i = 0, thid = 0; char *ptr, buf[PATH_MAX]; - RDebugPid *pid_info = NULL; + RzDebugPid *pid_info = NULL; ut64 pc = 0; int prev_tid = dbg->tid; if (!pid) { - r_list_free (list); + rz_list_free (list); return NULL; } - list->free = (RListFree)&r_debug_pid_free; + list->free = (RzListFree)&rz_debug_pid_free; /* if this process has a task directory, use that */ snprintf (buf, sizeof (buf), "/proc/%d/task", pid); - if (r_file_is_directory (buf)) { + if (rz_file_is_directory (buf)) { struct dirent *de; DIR *dh = opendir (buf); // Update the process' memory maps to set correct paths @@ -895,24 +895,24 @@ RList *linux_thread_list(RDebug *dbg, int pid, RList *list) { dbg->tid = tid; } - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); - pc = r_debug_reg_get (dbg, "PC"); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + pc = rz_debug_reg_get (dbg, "PC"); if (!procfs_pid_slurp (tid, "status", info, sizeof (info))) { // Get information about pid (status, pc, etc.) pid_info = fill_pid_info (info, NULL, tid); pid_info->pc = pc; } else { - pid_info = r_debug_pid_new (NULL, tid, uid, 's', pc); + pid_info = rz_debug_pid_new (NULL, tid, uid, 's', pc); } - r_list_append (list, pid_info); + rz_list_append (list, pid_info); dbg->n_threads++; } closedir (dh); // Return to the original thread linux_attach_single_pid (dbg, prev_tid); dbg->tid = prev_tid; - r_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); + rz_debug_reg_sync (dbg, R_REG_TYPE_GPR, false); } else { /* Some linux configurations might hide threads from /proc, use this workaround instead */ #undef MAXPID @@ -941,7 +941,7 @@ RList *linux_thread_list(RDebug *dbg, int pid, RList *list) { /* fall back to auto-id */ snprintf (buf, sizeof(buf), "thread_%d", thid++); } - r_list_append (list, r_debug_pid_new (buf, i, uid, 's', 0)); + rz_list_append (list, rz_debug_pid_new (buf, i, uid, 's', 0)); } } } @@ -949,23 +949,23 @@ RList *linux_thread_list(RDebug *dbg, int pid, RList *list) { } #define PRINT_FPU(fpregs) \ - r_cons_printf ("cwd = 0x%04x ; control ", (fpregs).cwd);\ - r_cons_printf ("swd = 0x%04x ; status\n", (fpregs).swd);\ - r_cons_printf ("ftw = 0x%04x ", (fpregs).ftw);\ - r_cons_printf ("fop = 0x%04x\n", (fpregs).fop);\ - r_cons_printf ("rip = 0x%016"PFMT64x" ", (ut64)(fpregs).rip);\ - r_cons_printf ("rdp = 0x%016"PFMT64x"\n", (ut64)(fpregs).rdp);\ - r_cons_printf ("mxcsr = 0x%08x ", (fpregs).mxcsr);\ - r_cons_printf ("mxcr_mask = 0x%08x\n", (fpregs).mxcr_mask)\ + rz_cons_printf ("cwd = 0x%04x ; control ", (fpregs).cwd);\ + rz_cons_printf ("swd = 0x%04x ; status\n", (fpregs).swd);\ + rz_cons_printf ("ftw = 0x%04x ", (fpregs).ftw);\ + rz_cons_printf ("fop = 0x%04x\n", (fpregs).fop);\ + rz_cons_printf ("rip = 0x%016"PFMT64x" ", (ut64)(fpregs).rip);\ + rz_cons_printf ("rdp = 0x%016"PFMT64x"\n", (ut64)(fpregs).rdp);\ + rz_cons_printf ("mxcsr = 0x%08x ", (fpregs).mxcsr);\ + rz_cons_printf ("mxcr_mask = 0x%08x\n", (fpregs).mxcr_mask)\ #define PRINT_FPU_NOXMM(fpregs) \ - r_cons_printf ("cwd = 0x%04lx ; control ", (fpregs).cwd);\ - r_cons_printf ("swd = 0x%04lx ; status\n", (fpregs).swd);\ - r_cons_printf ("twd = 0x%04lx ", (fpregs).twd);\ - r_cons_printf ("fip = 0x%04lx \n", (fpregs).fip);\ - r_cons_printf ("fcs = 0x%04lx ", (fpregs).fcs);\ - r_cons_printf ("foo = 0x%04lx \n", (fpregs).foo);\ - r_cons_printf ("fos = 0x%04lx ", (fpregs).fos) + rz_cons_printf ("cwd = 0x%04lx ; control ", (fpregs).cwd);\ + rz_cons_printf ("swd = 0x%04lx ; status\n", (fpregs).swd);\ + rz_cons_printf ("twd = 0x%04lx ", (fpregs).twd);\ + rz_cons_printf ("fip = 0x%04lx \n", (fpregs).fip);\ + rz_cons_printf ("fcs = 0x%04lx ", (fpregs).fcs);\ + rz_cons_printf ("foo = 0x%04lx \n", (fpregs).foo);\ + rz_cons_printf ("fos = 0x%04lx ", (fpregs).fos) static void print_fpu(void *f){ #if __x86_64__ @@ -979,34 +979,34 @@ static void print_fpu(void *f){ float *f = (float *)&fpregs.st_space; c = c + (i * 4); f = f + (i * 4); - r_cons_printf ("st%d =%0.3lg (0x%016"PFMT64x") | %0.3f (%08x) | "\ + rz_cons_printf ("st%d =%0.3lg (0x%016"PFMT64x") | %0.3f (%08x) | "\ "%0.3f (%08x) \n", i, (double)*((double*)&fpregs.st_space[i*4]), *b, (float) f[0], c[0], (float) f[1], c[1]); } #else - r_cons_printf ("---- x86-64 ----\n"); + rz_cons_printf ("---- x86-64 ----\n"); PRINT_FPU (fpregs); - r_cons_printf ("size = 0x%08x\n", (ut32)sizeof (fpregs)); + rz_cons_printf ("size = 0x%08x\n", (ut32)sizeof (fpregs)); for (i = 0; i < 16; i++) { ut32 *a = (ut32 *)&fpregs.xmm_space; a = a + (i * 4); - r_cons_printf ("xmm%d = %08x %08x %08x %08x ", i, (int)a[0], (int)a[1], + rz_cons_printf ("xmm%d = %08x %08x %08x %08x ", i, (int)a[0], (int)a[1], (int)a[2], (int)a[3] ); if (i < 8) { ut64 *st_u64 = (ut64*)&fpregs.st_space[i * 4]; ut8 *st_u8 = (ut8 *)&fpregs.st_space[i * 4]; long double *st_ld = (long double *)&fpregs.st_space[i * 4]; - r_cons_printf ("mm%d = 0x%016" PFMT64x " | st%d = ", i, *st_u64, i); + rz_cons_printf ("mm%d = 0x%016" PFMT64x " | st%d = ", i, *st_u64, i); // print as hex TBYTE - always little endian for (j = 9; j >= 0; j--) { - r_cons_printf ("%02x", st_u8[j]); + rz_cons_printf ("%02x", st_u8[j]); } // Using %Lf and %Le even though we do not show the extra precision to avoid another cast // %f with (double)*st_ld would also work - r_cons_printf (" %Le %Lf\n", *st_ld, *st_ld); + rz_cons_printf (" %Le %Lf\n", *st_ld, *st_ld); } else { - r_cons_printf ("\n"); + rz_cons_printf ("\n"); } } #endif // __ANDROID__ @@ -1014,16 +1014,16 @@ static void print_fpu(void *f){ int i,j; #if __ANDROID__ struct user_fpxregs_struct fpxregs = *(struct user_fpxregs_struct*)f; - r_cons_printf ("---- x86-32 ----\n"); - r_cons_printf ("cwd = 0x%04x ; control ", fpxregs.cwd); - r_cons_printf ("swd = 0x%04x ; status\n", fpxregs.swd); - r_cons_printf ("twd = 0x%04x ", fpxregs.twd); - r_cons_printf ("fop = 0x%04x\n", fpxregs.fop); - r_cons_printf ("fip = 0x%08x\n", (ut32)fpxregs.fip); - r_cons_printf ("fcs = 0x%08x\n", (ut32)fpxregs.fcs); - r_cons_printf ("foo = 0x%08x\n", (ut32)fpxregs.foo); - r_cons_printf ("fos = 0x%08x\n", (ut32)fpxregs.fos); - r_cons_printf ("mxcsr = 0x%08x\n", (ut32)fpxregs.mxcsr); + rz_cons_printf ("---- x86-32 ----\n"); + rz_cons_printf ("cwd = 0x%04x ; control ", fpxregs.cwd); + rz_cons_printf ("swd = 0x%04x ; status\n", fpxregs.swd); + rz_cons_printf ("twd = 0x%04x ", fpxregs.twd); + rz_cons_printf ("fop = 0x%04x\n", fpxregs.fop); + rz_cons_printf ("fip = 0x%08x\n", (ut32)fpxregs.fip); + rz_cons_printf ("fcs = 0x%08x\n", (ut32)fpxregs.fcs); + rz_cons_printf ("foo = 0x%08x\n", (ut32)fpxregs.foo); + rz_cons_printf ("fos = 0x%08x\n", (ut32)fpxregs.fos); + rz_cons_printf ("mxcsr = 0x%08x\n", (ut32)fpxregs.mxcsr); for(i = 0; i < 8; i++) { ut32 *a = (ut32*)(&fpxregs.xmm_space); ut64 *b = (ut64 *)(&fpxregs.st_space[i * 4]); @@ -1032,16 +1032,16 @@ static void print_fpu(void *f){ a = a + (i * 4); c = c + (i * 4); f = f + (i * 4); - r_cons_printf ("xmm%d = %08x %08x %08x %08x ", i, (int)a[0], + rz_cons_printf ("xmm%d = %08x %08x %08x %08x ", i, (int)a[0], (int)a[1], (int)a[2], (int)a[3] ); - r_cons_printf ("st%d = %0.3lg (0x%016"PFMT64x") | %0.3f (0x%08x) | "\ + rz_cons_printf ("st%d = %0.3lg (0x%016"PFMT64x") | %0.3f (0x%08x) | "\ "%0.3f (0x%08x)\n", i, (double)*((double*)(&fpxregs.st_space[i*4])), b[0], f[0], c[0], f[1], c[1]); } #else struct user_fpregs_struct fpregs = *(struct user_fpregs_struct *)f; - r_cons_printf ("---- x86-32-noxmm ----\n"); + rz_cons_printf ("---- x86-32-noxmm ----\n"); PRINT_FPU_NOXMM (fpregs); for(i = 0; i < 8; i++) { ut64 *b = (ut64 *)(&fpregs.st_space[i*4]); @@ -1050,7 +1050,7 @@ static void print_fpu(void *f){ float *f = (float *)&fpregs.st_space; c = c + (i * 4); f = f + (i * 4); - r_cons_printf ("st%d = %0.3lg (0x%016"PFMT64x") | %0.3f (0x%08x) | "\ + rz_cons_printf ("st%d = %0.3lg (0x%016"PFMT64x") | %0.3f (0x%08x) | "\ "%0.3f (0x%08x)\n", i, d[0], b[0], f[0], c[0], f[1], c[1]); } #endif @@ -1059,7 +1059,7 @@ static void print_fpu(void *f){ #endif } -int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { bool showfpu = false; int pid = dbg->tid; int ret = 0; @@ -1080,8 +1080,8 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { if (i == 4 || i == 5) { continue; } - long ret = r_debug_ptrace (dbg, PTRACE_PEEKUSER, pid, - (void *)r_offsetof (struct user, u_debugreg[i]), 0); + long ret = rz_debug_ptrace (dbg, PTRACE_PEEKUSER, pid, + (void *)rz_offsetof (struct user, u_debugreg[i]), 0); if ((i+1) * sizeof (ret) > size) { eprintf ("linux_reg_get: Buffer too small %d\n", size); break; @@ -1107,9 +1107,9 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { struct user_fpregs_struct fpregs; if (type == R_REG_TYPE_FPU) { #if __x86_64__ - ret = r_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); + ret = rz_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); if (ret != 0) { - r_sys_perror ("PTRACE_GETFPREGS"); + rz_sys_perror ("PTRACE_GETFPREGS"); return false; } if (showfpu) { @@ -1121,7 +1121,7 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { #elif __i386__ #if !__ANDROID__ struct user_fpxregs_struct fpxregs; - ret = r_debug_ptrace (dbg, PTRACE_GETFPXREGS, pid, NULL, &fpxregs); + ret = rz_debug_ptrace (dbg, PTRACE_GETFPXREGS, pid, NULL, &fpxregs); if (ret == 0) { if (showfpu) { print_fpu ((void *)&fpxregs); @@ -1130,12 +1130,12 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { memcpy (buf, &fpxregs, size); return size; } else { - ret = r_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); + ret = rz_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); if (showfpu) { print_fpu ((void *)&fpregs); } if (ret != 0) { - r_sys_perror ("PTRACE_GETFPREGS"); + rz_sys_perror ("PTRACE_GETFPREGS"); return false; } size = R_MIN (sizeof (fpregs), size); @@ -1143,12 +1143,12 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return size; } #else - ret = r_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); + ret = rz_debug_ptrace (dbg, PTRACE_GETFPREGS, pid, NULL, &fpregs); if (showfpu) { print_fpu ((void *)&fpregs); } if (ret != 0) { - r_sys_perror ("PTRACE_GETFPREGS"); + rz_sys_perror ("PTRACE_GETFPREGS"); return false; } size = R_MIN (sizeof (fpregs), size); @@ -1174,17 +1174,17 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { .iov_base = ®s, .iov_len = sizeof (regs) }; - ret = r_debug_ptrace (dbg, PTRACE_GETREGSET, pid, 1, &io); + ret = rz_debug_ptrace (dbg, PTRACE_GETREGSET, pid, 1, &io); // ret = ptrace (PTRACE_GETREGSET, pid, (void*)(size_t)(NT_PRSTATUS), NULL); // &io); if (ret != 0) { - r_sys_perror("PTRACE_GETREGSET"); + rz_sys_perror("PTRACE_GETREGSET"); return false; } #elif __BSD__ && (__POWERPC__ || __sparc__) - ret = r_debug_ptrace (dbg, PTRACE_GETREGS, pid, ®s, NULL); + ret = rz_debug_ptrace (dbg, PTRACE_GETREGS, pid, ®s, NULL); #else /* linux -{arm/mips/riscv/x86/x86_64} */ - ret = r_debug_ptrace (dbg, PTRACE_GETREGS, pid, NULL, ®s); + ret = rz_debug_ptrace (dbg, PTRACE_GETREGS, pid, NULL, ®s); #endif /* * if perror here says 'no such process' and the @@ -1193,7 +1193,7 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { * more ptrace queries. */ if (ret != 0) { - r_sys_perror ("PTRACE_GETREGS"); + rz_sys_perror ("PTRACE_GETREGS"); return false; } size = R_MIN (sizeof (regs), size); @@ -1209,9 +1209,9 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { struct iovec iov; iov.iov_base = &xstate; iov.iov_len = sizeof(struct _xstate); - ret = r_debug_ptrace (dbg, PTRACE_GETREGSET, pid, (void*)NT_X86_XSTATE, &iov); + ret = rz_debug_ptrace (dbg, PTRACE_GETREGSET, pid, (void*)NT_X86_XSTATE, &iov); if (ret != 0) { - r_sys_perror ("PTRACE_GETREGSET"); + rz_sys_perror ("PTRACE_GETREGSET"); return false; } // stitch together xstate.fpstate._xmm and xstate.ymmh assuming LE @@ -1235,7 +1235,7 @@ int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return false; } -int linux_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +int linux_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { int pid = dbg->tid; if (type == R_REG_TYPE_DRX) { @@ -1246,10 +1246,10 @@ int linux_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { if (i == 4 || i == 5) { continue; } - if (r_debug_ptrace (dbg, PTRACE_POKEUSER, pid, - (void *)r_offsetof (struct user, u_debugreg[i]), (r_ptrace_data_t)val[i])) { + if (rz_debug_ptrace (dbg, PTRACE_POKEUSER, pid, + (void *)rz_offsetof (struct user, u_debugreg[i]), (rz_ptrace_data_t)val[i])) { eprintf ("ptrace error for dr %d\n", i); - r_sys_perror ("ptrace POKEUSER"); + rz_sys_perror ("ptrace POKEUSER"); } } return sizeof (R_DEBUG_REG_T); @@ -1263,11 +1263,11 @@ int linux_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { .iov_base = (void*)buf, .iov_len = sizeof (R_DEBUG_REG_T) }; - int ret = r_debug_ptrace (dbg, PTRACE_SETREGSET, pid, (void*)(size_t)NT_PRSTATUS, (r_ptrace_data_t)(size_t)&io); + int ret = rz_debug_ptrace (dbg, PTRACE_SETREGSET, pid, (void*)(size_t)NT_PRSTATUS, (rz_ptrace_data_t)(size_t)&io); #elif __POWERPC__ || __sparc__ - int ret = r_debug_ptrace (dbg, PTRACE_SETREGS, pid, buf, NULL); + int ret = rz_debug_ptrace (dbg, PTRACE_SETREGS, pid, buf, NULL); #else - int ret = r_debug_ptrace (dbg, PTRACE_SETREGS, pid, 0, (void*)buf); + int ret = rz_debug_ptrace (dbg, PTRACE_SETREGS, pid, 0, (void*)buf); #endif #if DEAD_CODE if (size > sizeof (R_DEBUG_REG_T)) { @@ -1275,25 +1275,25 @@ int linux_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { } #endif if (ret == -1) { - r_sys_perror ("reg_write"); + rz_sys_perror ("reg_write"); return false; } return true; } if (type == R_REG_TYPE_FPU) { #if __i386__ || __x86_64__ - int ret = r_debug_ptrace (dbg, PTRACE_SETFPREGS, pid, 0, (void*)buf); + int ret = rz_debug_ptrace (dbg, PTRACE_SETFPREGS, pid, 0, (void*)buf); return (ret != 0) ? false : true; #endif } return false; } -RList *linux_desc_list (int pid) { - RList *ret = NULL; +RzList *linux_desc_list (int pid) { + RzList *ret = NULL; char path[512], file[512], buf[512]; struct dirent *de; - RDebugDesc *desc; + RzDebugDesc *desc; int type, perm; int len, len2; struct stat st; @@ -1301,15 +1301,15 @@ RList *linux_desc_list (int pid) { snprintf (path, sizeof (path), "/proc/%i/fd/", pid); if (!(dd = opendir (path))) { - r_sys_perror ("opendir /proc/x/fd"); + rz_sys_perror ("opendir /proc/x/fd"); return NULL; } - ret = r_list_new (); + ret = rz_list_new (); if (!ret) { closedir (dd); return NULL; } - ret->free = (RListFree)r_debug_desc_free; + ret->free = (RzListFree)rz_debug_desc_free; while ((de = (struct dirent *)readdir(dd))) { if (de->d_name[0] == '.') { continue; @@ -1317,7 +1317,7 @@ RList *linux_desc_list (int pid) { len = strlen (path); len2 = strlen (de->d_name); if (len + len2 + 1 >= sizeof(file)) { - r_list_free (ret); + rz_list_free (ret); closedir (dd); eprintf ("Filename is too long"); return NULL; @@ -1346,11 +1346,11 @@ RList *linux_desc_list (int pid) { } } //TODO: Offset - desc = r_debug_desc_new (atoi (de->d_name), buf, perm, type, 0); + desc = rz_debug_desc_new (atoi (de->d_name), buf, perm, type, 0); if (!desc) { break; } - r_list_append (ret, desc); + rz_list_append (ret, desc); } closedir (dd); return ret; diff --git a/libr/debug/p/native/linux/linux_debug.h b/librz/debug/p/native/linux/linux_debug.h similarity index 79% rename from libr/debug/p/native/linux/linux_debug.h rename to librz/debug/p/native/linux/linux_debug.h index 74403c66a1..ca51653f47 100644 --- a/libr/debug/p/native/linux/linux_debug.h +++ b/librz/debug/p/native/linux/linux_debug.h @@ -118,23 +118,23 @@ typedef ut64 mips64_regs_t [274]; #endif //API -bool linux_set_options(RDebug *dbg, int pid); -int linux_step(RDebug *dbg); -RDebugReasonType linux_ptrace_event(RDebug *dbg, int pid, int status, bool dowait); -int linux_attach(RDebug *dbg, int pid); -bool linux_attach_new_process(RDebug *dbg, int pid); -RDebugInfo *linux_info(RDebug *dbg, const char *arg); -RList *linux_pid_list(int pid, RList *list); -RList *linux_thread_list(RDebug *dbg, int pid, RList *list); -bool linux_select(RDebug *dbg, int pid, int tid); -RDebugPid *fill_pid_info(const char *info, const char *path, int tid); -int linux_reg_read(RDebug *dbg, int type, ut8 *buf, int size); -int linux_reg_write(RDebug *dbg, int type, const ut8 *buf, int size); -RList *linux_desc_list(int pid); -bool linux_stop_threads(RDebug *dbg, int except); -int linux_handle_signals(RDebug *dbg, int tid); -int linux_dbg_wait(RDebug *dbg, int pid); -char *linux_reg_profile(RDebug *dbg); +bool linux_set_options(RzDebug *dbg, int pid); +int linux_step(RzDebug *dbg); +RzDebugReasonType linux_ptrace_event(RzDebug *dbg, int pid, int status, bool dowait); +int linux_attach(RzDebug *dbg, int pid); +bool linux_attach_new_process(RzDebug *dbg, int pid); +RzDebugInfo *linux_info(RzDebug *dbg, const char *arg); +RzList *linux_pid_list(int pid, RzList *list); +RzList *linux_thread_list(RzDebug *dbg, int pid, RzList *list); +bool linux_select(RzDebug *dbg, int pid, int tid); +RzDebugPid *fill_pid_info(const char *info, const char *path, int tid); +int linux_reg_read(RzDebug *dbg, int type, ut8 *buf, int size); +int linux_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size); +RzList *linux_desc_list(int pid); +bool linux_stop_threads(RzDebug *dbg, int except); +int linux_handle_signals(RzDebug *dbg, int tid); +int linux_dbg_wait(RzDebug *dbg, int pid); +char *linux_reg_profile(RzDebug *dbg); int match_pid(const void *pid_o, const void *th_o); #endif diff --git a/libr/debug/p/native/linux/linux_ptrace.h b/librz/debug/p/native/linux/linux_ptrace.h similarity index 100% rename from libr/debug/p/native/linux/linux_ptrace.h rename to librz/debug/p/native/linux/linux_ptrace.h diff --git a/libr/debug/p/native/linux/reg/linux-arm.h b/librz/debug/p/native/linux/reg/linux-arm.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-arm.h rename to librz/debug/p/native/linux/reg/linux-arm.h diff --git a/libr/debug/p/native/linux/reg/linux-arm64.h b/librz/debug/p/native/linux/reg/linux-arm64.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-arm64.h rename to librz/debug/p/native/linux/reg/linux-arm64.h diff --git a/libr/debug/p/native/linux/reg/linux-mips.h b/librz/debug/p/native/linux/reg/linux-mips.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-mips.h rename to librz/debug/p/native/linux/reg/linux-mips.h diff --git a/libr/debug/p/native/linux/reg/linux-mips64.h b/librz/debug/p/native/linux/reg/linux-mips64.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-mips64.h rename to librz/debug/p/native/linux/reg/linux-mips64.h diff --git a/libr/debug/p/native/linux/reg/linux-ppc.h b/librz/debug/p/native/linux/reg/linux-ppc.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-ppc.h rename to librz/debug/p/native/linux/reg/linux-ppc.h diff --git a/libr/debug/p/native/linux/reg/linux-ppc64.h b/librz/debug/p/native/linux/reg/linux-ppc64.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-ppc64.h rename to librz/debug/p/native/linux/reg/linux-ppc64.h diff --git a/libr/debug/p/native/linux/reg/linux-riscv64.h b/librz/debug/p/native/linux/reg/linux-riscv64.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-riscv64.h rename to librz/debug/p/native/linux/reg/linux-riscv64.h diff --git a/libr/debug/p/native/linux/reg/linux-s390x.h b/librz/debug/p/native/linux/reg/linux-s390x.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-s390x.h rename to librz/debug/p/native/linux/reg/linux-s390x.h diff --git a/libr/debug/p/native/linux/reg/linux-x64-32.h b/librz/debug/p/native/linux/reg/linux-x64-32.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-x64-32.h rename to librz/debug/p/native/linux/reg/linux-x64-32.h diff --git a/libr/debug/p/native/linux/reg/linux-x64.h b/librz/debug/p/native/linux/reg/linux-x64.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-x64.h rename to librz/debug/p/native/linux/reg/linux-x64.h diff --git a/libr/debug/p/native/linux/reg/linux-x86.h b/librz/debug/p/native/linux/reg/linux-x86.h similarity index 100% rename from libr/debug/p/native/linux/reg/linux-x86.h rename to librz/debug/p/native/linux/reg/linux-x86.h diff --git a/libr/debug/p/native/maps/darwin.c b/librz/debug/p/native/maps/darwin.c similarity index 89% rename from libr/debug/p/native/maps/darwin.c rename to librz/debug/p/native/maps/darwin.c index 15ee9541b4..2c512fe151 100644 --- a/libr/debug/p/native/maps/darwin.c +++ b/librz/debug/p/native/maps/darwin.c @@ -70,7 +70,7 @@ vm_address_t get_kernel_base(task_t ___task) { extern int proc_regionfilename(int pid, uint64_t address, void * buffer, uint32_t buffersize); -static RList *ios_dbg_maps(RDebug *dbg) { +static RzList *ios_dbg_maps(RzDebug *dbg) { bool contiguous = false; ut32 oldprot = UT32_MAX; char buf[1024]; @@ -79,8 +79,8 @@ static RList *ios_dbg_maps(RDebug *dbg) { mach_vm_size_t osize = (mach_vm_size_t) 0; natural_t depth = 0; task_t task = pid_to_task (dbg->tid); - RDebugMap *mr = NULL; - RList *list = NULL; + RzDebugMap *mr = NULL; + RzList *list = NULL; int i = 0; #if __arm64__ || __aarch64__ size = osize = 16384; // according to frida @@ -110,8 +110,8 @@ static RList *ios_dbg_maps(RDebug *dbg) { break; } if (!list) { - list = r_list_new (); - //list->free = (RListFree*)r_debug_map_free; + list = rz_list_new (); + //list->free = (RzListFree*)rz_debug_map_free; } if (mr) { if (address == mr->addr + mr->size) { @@ -138,10 +138,10 @@ static RList *ios_dbg_maps(RDebug *dbg) { int ret = 0; #endif module_name[ret] = 0; - #define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) + #define xwrz_testwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) // XXX: if its shared, it cannot be read? snprintf (buf, sizeof (buf), "%s %02x %s%s%s%s%s %s depth=%d", - r_str_rwx_i (xwr2rwx (info.max_protection)), i, + rz_str_rwx_i (xwrz_testwx (info.max_protection)), i, unparse_inheritance (info.inheritance), info.user_tag? " user": "", info.is_submap? " sub": "", @@ -151,15 +151,15 @@ static RList *ios_dbg_maps(RDebug *dbg) { //info.shared ? "shar" : "priv", //info.reserved ? "reserved" : "not-reserved", //""); //module_name); - mr = r_debug_map_new (buf, address, address+size, - xwr2rwx (info.protection), 0); + mr = rz_debug_map_new (buf, address, address+size, + xwrz_testwx (info.protection), 0); if (!mr) { - eprintf ("Cannot create r_debug_map_new\n"); + eprintf ("Cannot create rz_debug_map_new\n"); break; } mr->file = strdup (module_name); i++; - r_list_append (list, mr); + rz_list_append (list, mr); } if (size<1) size = osize; // fuck address += size; @@ -170,8 +170,8 @@ static RList *ios_dbg_maps(RDebug *dbg) { #if 0 // TODO: this loop MUST be cleaned up -static RList *osx_dbg_maps (RDebug *dbg) { - RDebugMap *mr; +static RzList *osx_dbg_maps (RzDebug *dbg) { + RzDebugMap *mr; char buf[1024]; int i, print; kern_return_t kret; @@ -184,7 +184,7 @@ static RList *osx_dbg_maps (RDebug *dbg) { int num_printed = 0; size_t address = 0; task_t task = pid_to_task (dbg->pid); - RList *list = r_list_new (); + RzList *list = rz_list_new (); // XXX: wrong for 64bits /* count = VM_REGION_BASIC_INFO_COUNT_64; @@ -246,24 +246,24 @@ static RList *osx_dbg_maps (RDebug *dbg) { int ret = proc_regionfilename (dbg->pid, address, module_name, sizeof (module_name)); module_name[ret] = 0; - #define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) + #define xwrz_testwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) if (print && size>0 && prev_info.inheritance != VM_INHERIT_SHARE) { snprintf (buf, sizeof (buf), "%s %02x %s/%s/%s %s", - r_str_rwx_i (xwr2rwx (prev_info.max_protection)), i, + rz_str_rwx_i (xwrz_testwx (prev_info.max_protection)), i, unparse_inheritance (prev_info.inheritance), prev_info.shared ? "shar" : "priv", prev_info.reserved ? "reserved" : "not-reserved", module_name); // TODO: MAPS can have min and max protection rules // :: prev_info.max_protection - mr = r_debug_map_new (buf, prev_address, prev_address+prev_size, - xwr2rwx (prev_info.protection), 0); + mr = rz_debug_map_new (buf, prev_address, prev_address+prev_size, + xwrz_testwx (prev_info.protection), 0); if (!mr) { - eprintf ("Cannot create r_debug_map_new\n"); + eprintf ("Cannot create rz_debug_map_new\n"); break; } mr->file = strdup (module_name); - r_list_append (list, mr); + rz_list_append (list, mr); } } #if 0 @@ -311,7 +311,7 @@ static RList *osx_dbg_maps (RDebug *dbg) { } #endif -static RList *darwin_dbg_maps(RDebug *dbg) { +static RzList *darwin_dbg_maps(RzDebug *dbg) { //return osx_dbg_maps (dbg); return ios_dbg_maps (dbg); #if 0 diff --git a/libr/debug/p/native/maps/windows_maps.c b/librz/debug/p/native/maps/windows_maps.c similarity index 78% rename from libr/debug/p/native/maps/windows_maps.c rename to librz/debug/p/native/maps/windows_maps.c index 7c5c289840..8ab431d46f 100644 --- a/libr/debug/p/native/maps/windows_maps.c +++ b/librz/debug/p/native/maps/windows_maps.c @@ -2,7 +2,7 @@ #include "../windows/windows_debug.h" typedef struct { - RDebugMap *map; + RzDebugMap *map; IMAGE_SECTION_HEADER *sect_hdr; int sect_count; } RWinModInfo; @@ -25,7 +25,7 @@ static char *get_map_type(MEMORY_BASIC_INFORMATION *mbi) { return type; } -static RDebugMap *add_map(RList *list, const char *name, ut64 addr, ut64 len, MEMORY_BASIC_INFORMATION *mbi) { +static RzDebugMap *add_map(RzList *list, const char *name, ut64 addr, ut64 len, MEMORY_BASIC_INFORMATION *mbi) { int perm; char *map_type = get_map_type (mbi); @@ -54,52 +54,52 @@ static RDebugMap *add_map(RList *list, const char *name, ut64 addr, ut64 len, ME default: perm = 0; } - char *map_name = r_str_newf ("%-8s %s", map_type, name); + char *map_name = rz_str_newf ("%-8s %s", map_type, name); if (!map_name) { return NULL; } - RDebugMap *mr = r_debug_map_new (map_name, addr, addr + len, perm, mbi->Type == MEM_PRIVATE); + RzDebugMap *mr = rz_debug_map_new (map_name, addr, addr + len, perm, mbi->Type == MEM_PRIVATE); free (map_name); if (mr) { - r_list_append (list, mr); + rz_list_append (list, mr); } return mr; } -static inline RDebugMap *add_map_reg(RList *list, const char *name, MEMORY_BASIC_INFORMATION *mbi) { +static inline RzDebugMap *add_map_reg(RzList *list, const char *name, MEMORY_BASIC_INFORMATION *mbi) { return add_map (list, name, (ut64)(size_t)mbi->BaseAddress, (ut64)mbi->RegionSize, mbi); } -R_API RList *r_w32_dbg_modules(RDebug *dbg) { +RZ_API RzList *rz_w32_dbg_modules(RzDebug *dbg) { if (dbg->pid == -1) { return NULL; } MODULEENTRY32 me; - RList *list = r_list_newf ((RListFree)r_debug_map_free); + RzList *list = rz_list_newf ((RzListFree)rz_debug_map_free); DWORD flags = TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32; HANDLE h_mod_snap = w32_CreateToolhelp32Snapshot (flags, dbg->pid); if (h_mod_snap == INVALID_HANDLE_VALUE) { // Suppress if process is still initializing - if (GetLastError () != ERROR_PARTIAL_COPY || r_list_length (dbg->threads) > 1) { - r_sys_perror ("r_w32_dbg_modules/CreateToolhelp32Snapshot"); + if (GetLastError () != ERROR_PARTIAL_COPY || rz_list_length (dbg->threads) > 1) { + rz_sys_perror ("rz_w32_dbg_modules/CreateToolhelp32Snapshot"); } goto err_w32_dbg_modules; } me.dwSize = sizeof (MODULEENTRY32); if (!Module32First (h_mod_snap, &me)) { - r_sys_perror ("r_w32_dbg_modules/Module32First"); + rz_sys_perror ("rz_w32_dbg_modules/Module32First"); goto err_w32_dbg_modules; } do { ut64 baddr = (ut64)(size_t)me.modBaseAddr; - char *mod_name = r_sys_conv_win_to_utf8 (me.szModule); - RDebugMap *dbgmap = r_debug_map_new (mod_name, baddr, baddr + me.modBaseSize, 0, 0); + char *mod_name = rz_sys_conv_win_to_utf8 (me.szModule); + RzDebugMap *dbgmap = rz_debug_map_new (mod_name, baddr, baddr + me.modBaseSize, 0, 0); free (mod_name); if (dbgmap) { - dbgmap->file = r_sys_conv_win_to_utf8 (me.szExePath); + dbgmap->file = rz_sys_conv_win_to_utf8 (me.szExePath); if (dbgmap->file) { - r_list_append (list, dbgmap); + rz_list_append (list, dbgmap); } } } while (Module32Next (h_mod_snap, &me)); @@ -124,7 +124,7 @@ static bool is_pe_hdr(unsigned char *pe_hdr) { return false; } -static int set_mod_inf(HANDLE h_proc, RDebugMap *map, RWinModInfo *mod) { +static int set_mod_inf(HANDLE h_proc, RzDebugMap *map, RWinModInfo *mod) { IMAGE_DOS_HEADER *dos_hdr; IMAGE_NT_HEADERS *nt_hdrs; IMAGE_NT_HEADERS32 *nt_hdrs32; @@ -164,16 +164,16 @@ static int set_mod_inf(HANDLE h_proc, RDebugMap *map, RWinModInfo *mod) { return mod_inf_fill; } -static void proc_mem_img(HANDLE h_proc, RList *map_list, RList *mod_list, RWinModInfo *mod, SYSTEM_INFO *si, MEMORY_BASIC_INFORMATION *mbi) { +static void proc_mem_img(HANDLE h_proc, RzList *map_list, RzList *mod_list, RWinModInfo *mod, SYSTEM_INFO *si, MEMORY_BASIC_INFORMATION *mbi) { ut64 addr = (ut64)(size_t)mbi->BaseAddress; ut64 len = (ut64)mbi->RegionSize; if (!mod->map || addr < mod->map->addr || (addr + len) > mod->map->addr_end) { - RListIter *iter; - RDebugMap *map; + RzListIter *iter; + RzDebugMap *map; free (mod->sect_hdr); memset (mod, 0, sizeof (RWinModInfo)); - r_list_foreach (mod_list, iter, map) { + rz_list_foreach (mod_list, iter, map) { if (addr >= map->addr && addr <= map->addr_end) { mod->map = map; set_mod_inf (h_proc, map, mod); @@ -201,9 +201,9 @@ static void proc_mem_img(HANDLE h_proc, RList *map_list, RList *mod_list, RWinMo sect_found = 2; } if (sect_found) { - char *map_name = r_str_newf ("%s | %.8s", mod->map->name, sect_hdr->Name); + char *map_name = rz_str_newf ("%s | %.8s", mod->map->name, sect_hdr->Name); if (!map_name) { - perror ("r_str_newf"); + perror ("rz_str_newf"); return; } if (sect_found == 1) { @@ -227,12 +227,12 @@ static void proc_mem_img(HANDLE h_proc, RList *map_list, RList *mod_list, RWinMo } } -static void proc_mem_map(HANDLE h_proc, RList *map_list, MEMORY_BASIC_INFORMATION *mbi) { +static void proc_mem_map(HANDLE h_proc, RzList *map_list, MEMORY_BASIC_INFORMATION *mbi) { TCHAR f_name[MAX_PATH + 1]; DWORD len = GetMappedFileName (h_proc, mbi->BaseAddress, f_name, MAX_PATH); if (len > 0) { - char *f_name_ = r_sys_conv_win_to_utf8 (f_name); + char *f_name_ = rz_sys_conv_win_to_utf8 (f_name); add_map_reg (map_list, f_name_, mbi); free (f_name_); } else { @@ -240,7 +240,7 @@ static void proc_mem_map(HANDLE h_proc, RList *map_list, MEMORY_BASIC_INFORMATIO } } -R_API RList *r_w32_dbg_maps(RDebug *dbg) { +RZ_API RzList *rz_w32_dbg_maps(RzDebug *dbg) { if (dbg->pid == -1) { return NULL; } @@ -248,13 +248,13 @@ R_API RList *r_w32_dbg_maps(RDebug *dbg) { LPVOID cur_addr; MEMORY_BASIC_INFORMATION mbi; RWinModInfo mod_inf = {0}; - RList *map_list = r_list_newf ((RListFree)r_debug_map_free), *mod_list = NULL; + RzList *map_list = rz_list_newf ((RzListFree)rz_debug_map_free), *mod_list = NULL; W32DbgWInst *wrap = dbg->user; GetSystemInfo (&si); cur_addr = si.lpMinimumApplicationAddress; /* get process modules list */ - mod_list = r_w32_dbg_modules (dbg); + mod_list = rz_w32_dbg_modules (dbg); /* process memory map */ while (cur_addr < si.lpMaximumApplicationAddress && VirtualQueryEx (wrap->pi.hProcess, cur_addr, &mbi, sizeof (mbi)) != 0) { @@ -273,6 +273,6 @@ R_API RList *r_w32_dbg_maps(RDebug *dbg) { cur_addr = (LPVOID)(size_t)((ut64)(size_t)mbi.BaseAddress + mbi.RegionSize); } free (mod_inf.sect_hdr); - r_list_free (mod_list); + rz_list_free (mod_list); return map_list; } diff --git a/librz/debug/p/native/maps/windows_maps.h b/librz/debug/p/native/maps/windows_maps.h new file mode 100644 index 0000000000..2e2c355d0c --- /dev/null +++ b/librz/debug/p/native/maps/windows_maps.h @@ -0,0 +1,8 @@ +#ifndef WINDOWS_MAPS_H +#define WINDOWS_MAPS_H +#include + +RZ_API RzList *rz_w32_dbg_modules(RzDebug *dbg); +RZ_API RzList *rz_w32_dbg_maps(RzDebug *dbg); + +#endif \ No newline at end of file diff --git a/libr/debug/p/native/procfs.c b/librz/debug/p/native/procfs.c similarity index 70% rename from libr/debug/p/native/procfs.c rename to librz/debug/p/native/procfs.c index 663e1cba80..1ebdd2dc75 100644 --- a/libr/debug/p/native/procfs.c +++ b/librz/debug/p/native/procfs.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2009-2016 - pancake */ -#include -#include +#include +#include int procfs_pid_slurp(int pid, char *prop, char *out, size_t len) { int fd, ret = -1; ssize_t nr; - char *filename = r_str_newf ("/proc/%d/%s", pid, prop); + char *filename = rz_str_newf ("/proc/%d/%s", pid, prop); if (!filename) { return -1; } - fd = r_sandbox_open (filename, O_RDONLY, 0); + fd = rz_sandbox_open (filename, O_RDONLY, 0); if (fd == -1) { free (filename); return -1; @@ -22,7 +22,7 @@ int procfs_pid_slurp(int pid, char *prop, char *out, size_t len) { out[nr - 1] = '\0'; /* terminate at newline */ ret = 0; } else if (nr < 0) { - r_sys_perror ("read"); + rz_sys_perror ("read"); } close (fd); free (filename); diff --git a/libr/debug/p/native/procfs.h b/librz/debug/p/native/procfs.h similarity index 100% rename from libr/debug/p/native/procfs.h rename to librz/debug/p/native/procfs.h diff --git a/libr/debug/p/native/reg.c b/librz/debug/p/native/reg.c similarity index 95% rename from libr/debug/p/native/reg.c rename to librz/debug/p/native/reg.c index 2a1f2e0788..13af278865 100644 --- a/libr/debug/p/native/reg.c +++ b/librz/debug/p/native/reg.c @@ -1,7 +1,7 @@ // included from p/debug_native.c // split for better reading/cleaning up -static char *r_debug_native_reg_profile(RDebug *dbg) { +static char *rz_debug_native_reg_profile(RzDebug *dbg) { #if __WINDOWS__ /*_______ | | | diff --git a/libr/debug/p/native/reg/kfbsd-arm64.h b/librz/debug/p/native/reg/kfbsd-arm64.h similarity index 100% rename from libr/debug/p/native/reg/kfbsd-arm64.h rename to librz/debug/p/native/reg/kfbsd-arm64.h diff --git a/libr/debug/p/native/reg/kfbsd-x64.h b/librz/debug/p/native/reg/kfbsd-x64.h similarity index 100% rename from libr/debug/p/native/reg/kfbsd-x64.h rename to librz/debug/p/native/reg/kfbsd-x64.h diff --git a/libr/debug/p/native/reg/kfbsd-x86.h b/librz/debug/p/native/reg/kfbsd-x86.h similarity index 100% rename from libr/debug/p/native/reg/kfbsd-x86.h rename to librz/debug/p/native/reg/kfbsd-x86.h diff --git a/libr/debug/p/native/reg/netbsd-x64.h b/librz/debug/p/native/reg/netbsd-x64.h similarity index 100% rename from libr/debug/p/native/reg/netbsd-x64.h rename to librz/debug/p/native/reg/netbsd-x64.h diff --git a/libr/debug/p/native/reg/netbsd-x86.h b/librz/debug/p/native/reg/netbsd-x86.h similarity index 100% rename from libr/debug/p/native/reg/netbsd-x86.h rename to librz/debug/p/native/reg/netbsd-x86.h diff --git a/libr/debug/p/native/reg/windows-arm.h b/librz/debug/p/native/reg/windows-arm.h similarity index 100% rename from libr/debug/p/native/reg/windows-arm.h rename to librz/debug/p/native/reg/windows-arm.h diff --git a/libr/debug/p/native/reg/windows-arm64.h b/librz/debug/p/native/reg/windows-arm64.h similarity index 100% rename from libr/debug/p/native/reg/windows-arm64.h rename to librz/debug/p/native/reg/windows-arm64.h diff --git a/libr/debug/p/native/reg/windows-x64.h b/librz/debug/p/native/reg/windows-x64.h similarity index 100% rename from libr/debug/p/native/reg/windows-x64.h rename to librz/debug/p/native/reg/windows-x64.h diff --git a/libr/debug/p/native/reg/windows-x86.h b/librz/debug/p/native/reg/windows-x86.h similarity index 100% rename from libr/debug/p/native/reg/windows-x86.h rename to librz/debug/p/native/reg/windows-x86.h diff --git a/libr/debug/p/native/w32.c b/librz/debug/p/native/w32.c similarity index 87% rename from libr/debug/p/native/w32.c rename to librz/debug/p/native/w32.c index 47da39b51b..7059197b76 100644 --- a/libr/debug/p/native/w32.c +++ b/librz/debug/p/native/w32.c @@ -162,7 +162,7 @@ int w32_first_thread(int pid) { if (te32.th32OwnerProcessID == pid) { thid = w32_OpenThread (THREAD_ALL_ACCESS, 0, te32.th32ThreadID); if (!thid) { - r_sys_perror ("w32_first_thread/OpenThread"); + rz_sys_perror ("w32_first_thread/OpenThread"); goto err_load_th; } CloseHandle (th); @@ -287,7 +287,7 @@ err_get_file_name_from_handle: CloseHandle (handle_file_map); } if (filename) { - char *filename_ = r_sys_conv_win_to_utf8(filename); + char *filename_ = rz_sys_conv_win_to_utf8(filename); free (filename); return filename_; @@ -297,15 +297,15 @@ err_get_file_name_from_handle: LPVOID lstLib = 0; PLIB_ITEM lstLibPtr = 0; /* -static char * r_debug_get_dll(void) { +static char * rz_debug_get_dll(void) { return lstLibPtr->Path; } */ -static PLIB_ITEM r_debug_get_lib_item(void) { +static PLIB_ITEM rz_debug_get_lib_item(void) { return lstLibPtr; } #define PLIB_MAX 512 -static void r_debug_lstLibAdd(DWORD pid,LPVOID lpBaseOfDll, HANDLE hFile,char * dllname) { +static void rz_debug_lstLibAdd(DWORD pid,LPVOID lpBaseOfDll, HANDLE hFile,char * dllname) { int x; if (lstLib == 0) lstLib = VirtualAlloc (0, PLIB_MAX * sizeof (LIB_ITEM), MEM_COMMIT, PAGE_READWRITE); @@ -326,9 +326,9 @@ static void r_debug_lstLibAdd(DWORD pid,LPVOID lpBaseOfDll, HANDLE hFile,char * } lstLibPtr++; } - eprintf("r_debug_lstLibAdd: Cannot find slot\n"); + eprintf("rz_debug_lstLibAdd: Cannot find slot\n"); } -static void * r_debug_findlib (void * BaseOfDll) { +static void * rz_debug_findlib (void * BaseOfDll) { PLIB_ITEM libPtr = NULL; if (lstLib) { libPtr = (PLIB_ITEM)lstLib; @@ -344,11 +344,11 @@ static void * r_debug_findlib (void * BaseOfDll) { LPVOID lstThread = 0; PTHREAD_ITEM lstThreadPtr = 0; -static PTHREAD_ITEM r_debug_get_thread_item (void) { +static PTHREAD_ITEM rz_debug_get_thread_item (void) { return lstThreadPtr; } #define PTHREAD_MAX 1024 -static void r_debug_lstThreadAdd (DWORD pid, DWORD tid, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress, BOOL bFinished) { +static void rz_debug_lstThreadAdd (DWORD pid, DWORD tid, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress, BOOL bFinished) { int x; PVOID startAddress = 0; if (lstThread == 0) @@ -369,10 +369,10 @@ static void r_debug_lstThreadAdd (DWORD pid, DWORD tid, HANDLE hThread, LPVOID } lstThreadPtr++; } - eprintf ("r_debug_lstThreadAdd: Cannot find slot\n"); + eprintf ("rz_debug_lstThreadAdd: Cannot find slot\n"); } -static void * r_debug_findthread (int pid, int tid) { +static void * rz_debug_findthread (int pid, int tid) { PTHREAD_ITEM threadPtr = NULL; if (lstThread) { threadPtr = (PTHREAD_ITEM)lstThread; @@ -388,7 +388,7 @@ static void * r_debug_findthread (int pid, int tid) { return NULL; } -int w32_dbg_wait(RDebug *dbg, int pid) { +int w32_dbg_wait(RzDebug *dbg, int pid) { DEBUG_EVENT de; int tid, next_event = 0; unsigned int code; @@ -403,7 +403,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) { } memset (&de, 0, sizeof (DEBUG_EVENT)); if (WaitForDebugEvent (&de, INFINITE) == 0) { - r_sys_perror ("w32_dbg_wait/WaitForDebugEvent"); + rz_sys_perror ("w32_dbg_wait/WaitForDebugEvent"); return -1; } code = de.dwDebugEventCode; @@ -417,16 +417,16 @@ int w32_dbg_wait(RDebug *dbg, int pid) { eprintf ("(%d) created process (%d:%p)\n", pid, w32_h2t (de.u.CreateProcessInfo.hProcess), de.u.CreateProcessInfo.lpStartAddress); - r_debug_native_continue (dbg, pid, tid, -1); + rz_debug_native_continue (dbg, pid, tid, -1); next_event = 1; ret = R_DEBUG_REASON_NEW_PID; break; case EXIT_PROCESS_DEBUG_EVENT: //eprintf ("(%d) Process %d exited with exit code %d\n", (int)de.dwProcessId, (int)de.dwProcessId, // (int)de.u.ExitProcess.dwExitCode); - r_cons_printf ("(%d) Process %d exited with exit code %d\n", (int)de.dwProcessId, (int)de.dwProcessId, + rz_cons_printf ("(%d) Process %d exited with exit code %d\n", (int)de.dwProcessId, (int)de.dwProcessId, (int)de.u.ExitProcess.dwExitCode); - r_cons_flush (); + rz_cons_flush (); //debug_load(); next_event = 0; exited_already = pid; @@ -434,28 +434,28 @@ int w32_dbg_wait(RDebug *dbg, int pid) { break; case CREATE_THREAD_DEBUG_EVENT: //eprintf ("(%d) Created thread %d (start @ %p)\n", pid, tid, de.u.CreateThread.lpStartAddress); - r_debug_lstThreadAdd (pid, tid, de.u.CreateThread.hThread, de.u.CreateThread.lpThreadLocalBase, de.u.CreateThread.lpStartAddress, FALSE); - //r_debug_native_continue (dbg, pid, tid, -1); + rz_debug_lstThreadAdd (pid, tid, de.u.CreateThread.hThread, de.u.CreateThread.lpThreadLocalBase, de.u.CreateThread.lpStartAddress, FALSE); + //rz_debug_native_continue (dbg, pid, tid, -1); ret = R_DEBUG_REASON_NEW_TID; next_event = 0; break; case EXIT_THREAD_DEBUG_EVENT: //eprintf ("(%d) Finished thread %d\n", pid, tid); - lstThreadPtr = (PTHREAD_ITEM)r_debug_findthread (pid, tid); + lstThreadPtr = (PTHREAD_ITEM)rz_debug_findthread (pid, tid); if (lstThreadPtr) { lstThreadPtr->bFinished = TRUE; lstThreadPtr->dwExitCode = de.u.ExitThread.dwExitCode; } else { - r_debug_lstThreadAdd (pid, tid, de.u.CreateThread.hThread, de.u.CreateThread.lpThreadLocalBase, de.u.CreateThread.lpStartAddress, TRUE); + rz_debug_lstThreadAdd (pid, tid, de.u.CreateThread.hThread, de.u.CreateThread.lpThreadLocalBase, de.u.CreateThread.lpStartAddress, TRUE); } - //r_debug_native_continue (dbg, pid, tid, -1); + //rz_debug_native_continue (dbg, pid, tid, -1); next_event = 0; ret = R_DEBUG_REASON_EXIT_TID; break; case LOAD_DLL_DEBUG_EVENT: dllname = get_file_name_from_handle (de.u.LoadDll.hFile); //eprintf ("(%d) Loading library at %p (%s)\n",pid, de.u.LoadDll.lpBaseOfDll, dllname ? dllname : "no name"); - r_debug_lstLibAdd (pid,de.u.LoadDll.lpBaseOfDll, de.u.LoadDll.hFile, dllname); + rz_debug_lstLibAdd (pid,de.u.LoadDll.lpBaseOfDll, de.u.LoadDll.hFile, dllname); if (dllname) { free (dllname); } @@ -464,11 +464,11 @@ int w32_dbg_wait(RDebug *dbg, int pid) { break; case UNLOAD_DLL_DEBUG_EVENT: //eprintf ("(%d) Unloading library at %p\n", pid, de.u.UnloadDll.lpBaseOfDll); - lstLibPtr = (PLIB_ITEM)r_debug_findlib (de.u.UnloadDll.lpBaseOfDll); + lstLibPtr = (PLIB_ITEM)rz_debug_findlib (de.u.UnloadDll.lpBaseOfDll); if (lstLibPtr != NULL) { lstLibPtr->hFile = (HANDLE)-1; } else { - r_debug_lstLibAdd (pid, de.u.UnloadDll.lpBaseOfDll, (HANDLE)-1, "not cached"); + rz_debug_lstLibAdd (pid, de.u.UnloadDll.lpBaseOfDll, (HANDLE)-1, "not cached"); if (dllname) free (dllname); } @@ -477,17 +477,17 @@ int w32_dbg_wait(RDebug *dbg, int pid) { break; case OUTPUT_DEBUG_STRING_EVENT: //eprintf ("(%d) Debug string\n", pid); - r_cons_printf ("(%d) Debug string\n", pid); - r_cons_flush (); + rz_cons_printf ("(%d) Debug string\n", pid); + rz_cons_flush (); - r_debug_native_continue (dbg, pid, tid, -1); + rz_debug_native_continue (dbg, pid, tid, -1); next_event = 1; break; case RIP_EVENT: //eprintf ("(%d) RIP event\n", pid); - r_cons_printf ("(%d) RIP event\n", pid); - r_cons_flush (); - r_debug_native_continue (dbg, pid, tid, -1); + rz_cons_printf ("(%d) RIP event\n", pid); + rz_cons_flush (); + rz_debug_native_continue (dbg, pid, tid, -1); next_event = 1; // XXX unknown ret = R_DEBUG_REASON_TRAP; break; @@ -514,7 +514,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) { } else { next_event = 1; - r_debug_native_continue (dbg, pid, tid, -1); + rz_debug_native_continue (dbg, pid, tid, -1); } } @@ -544,12 +544,12 @@ bool is_pe_hdr(unsigned char *pe_hdr) { static HANDLE w32_open_thread(int pid, int tid) { HANDLE thread = w32_OpenThread (THREAD_ALL_ACCESS, 0, tid); if (thread == INVALID_HANDLE_VALUE) { - r_sys_perror ("w32_open_thread/OpenThread"); + rz_sys_perror ("w32_open_thread/OpenThread"); } return thread; } -RList *w32_thread_list(int pid, RList *list) { +RzList *w32_thread_list(int pid, RzList *list) { HANDLE th; HANDLE thid; THREADENTRY32 te32; @@ -581,10 +581,10 @@ RList *w32_thread_list(int pid, RList *list) { #endif thid = w32_OpenThread (THREAD_ALL_ACCESS, 0, te32.th32ThreadID); if (!thid) { - r_sys_perror ("w32_thread_list/OpenThread"); + rz_sys_perror ("w32_thread_list/OpenThread"); goto err_load_th; } - r_list_append (list, r_debug_pid_new ("???", te32.th32ThreadID, 0, 's', 0)); + rz_list_append (list, rz_debug_pid_new ("???", te32.th32ThreadID, 0, 's', 0)); } } while (Thread32Next (th, &te32)); err_load_th: @@ -593,10 +593,10 @@ err_load_th: return list; } -static RDebugPid *build_debug_pid(PROCESSENTRY32 *pe) { +static RzDebugPid *build_debug_pid(PROCESSENTRY32 *pe) { TCHAR image_name[MAX_PATH + 1]; DWORD length = MAX_PATH; - RDebugPid *ret; + RzDebugPid *ret; char *name; HANDLE process = w32_OpenProcess (0x1000, //PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pe->th32ProcessID); @@ -609,16 +609,16 @@ static RDebugPid *build_debug_pid(PROCESSENTRY32 *pe) { CloseHandle(process); } if (*image_name) { - name = r_sys_conv_win_to_utf8 (image_name); + name = rz_sys_conv_win_to_utf8 (image_name); } else { - name = r_sys_conv_win_to_utf8 (pe->szExeFile); + name = rz_sys_conv_win_to_utf8 (pe->szExeFile); } - ret = r_debug_pid_new (name, pe->th32ProcessID, 0, 's', 0); + ret = rz_debug_pid_new (name, pe->th32ProcessID, 0, 's', 0); free (name); return ret; } -RList *w32_pids(int pid, RList *list) { +RzList *w32_pids(int pid, RzList *list) { HANDLE process_snapshot; PROCESSENTRY32 pe; pe.dwSize = sizeof (PROCESSENTRY32); @@ -626,11 +626,11 @@ RList *w32_pids(int pid, RList *list) { process_snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, pid); if (process_snapshot == INVALID_HANDLE_VALUE) { - r_sys_perror ("w32_pids/CreateToolhelp32Snapshot"); + rz_sys_perror ("w32_pids/CreateToolhelp32Snapshot"); return list; } if (!Process32First (process_snapshot, &pe)) { - r_sys_perror ("w32_pids/Process32First"); + rz_sys_perror ("w32_pids/Process32First"); CloseHandle (process_snapshot); return list; } @@ -639,9 +639,9 @@ RList *w32_pids(int pid, RList *list) { pe.th32ProcessID == pid || pe.th32ParentProcessID == pid) { - RDebugPid *debug_pid = build_debug_pid (&pe); + RzDebugPid *debug_pid = build_debug_pid (&pe); if (debug_pid) { - r_list_append (list, debug_pid); + rz_list_append (list, debug_pid); } } } while (Process32Next (process_snapshot, &pe)); @@ -650,11 +650,11 @@ RList *w32_pids(int pid, RList *list) { return list; } -bool w32_terminate_process(RDebug *dbg, int pid) { +bool w32_terminate_process(RzDebug *dbg, int pid) { HANDLE h_proc = w32_OpenProcess(PROCESS_TERMINATE | SYNCHRONIZE , FALSE, pid); bool ret = false; if (!h_proc) { - r_sys_perror ("w32_terminate_process/OpenProcess"); + rz_sys_perror ("w32_terminate_process/OpenProcess"); goto err_w32_terminate_process; } /* stop debugging if we are still attached */ @@ -662,14 +662,14 @@ bool w32_terminate_process(RDebug *dbg, int pid) { w32_DebugActiveProcessStop (pid); //DebugActiveProcessStop (pid); } if (TerminateProcess (h_proc, 1) == 0) { - r_sys_perror ("e32_terminate_process/TerminateProcess"); + rz_sys_perror ("e32_terminate_process/TerminateProcess"); goto err_w32_terminate_process; } /* wait up to one second to give the process some time to exit */ DWORD ret_wait = WaitForSingleObject (h_proc, 1000); if (ret_wait == WAIT_FAILED) { - r_sys_perror ("w32_terminate_process/WaitForSingleObject"); + rz_sys_perror ("w32_terminate_process/WaitForSingleObject"); goto err_w32_terminate_process; } if (ret_wait == WAIT_TIMEOUT) { @@ -685,14 +685,14 @@ err_w32_terminate_process: } void w32_break_process(void *d) { - RDebug *dbg = (RDebug *)d; + RzDebug *dbg = (RzDebug *)d; HANDLE h_proc = w32_OpenProcess (PROCESS_ALL_ACCESS, FALSE, dbg->pid); if (!h_proc) { - r_sys_perror ("w32_break_process/w32_OpenProcess"); + rz_sys_perror ("w32_break_process/w32_OpenProcess"); goto err_w32_break_process; } if (!w32_DebugBreakProcess (h_proc)) { - r_sys_perror ("w32_break_process/w32_DebugBreakProcess"); + rz_sys_perror ("w32_break_process/w32_DebugBreakProcess"); goto err_w32_break_process; } err_w32_break_process: @@ -849,7 +849,7 @@ static void printwincontext(HANDLE hThread, CONTEXT * ctx) { } } -static int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +static int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { #ifdef _MSC_VER CONTEXT ctx; #else @@ -877,7 +877,7 @@ static int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { // size = 0; //} } else { - r_sys_perror ("w32_reg_read/GetThreadContext"); + rz_sys_perror ("w32_reg_read/GetThreadContext"); size = 0; } if (showfpu) { @@ -887,7 +887,7 @@ static int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return size; } -static int w32_reg_write(RDebug *dbg, int type, const ut8* buf, int size) { +static int w32_reg_write(RzDebug *dbg, int type, const ut8* buf, int size) { BOOL ret = false; HANDLE thread; #if _MSC_VER @@ -910,7 +910,7 @@ static int w32_reg_write(RDebug *dbg, int type, const ut8* buf, int size) { return ret; } -static void w32_info_user(RDebug *dbg, RDebugInfo *rdi) { +static void w32_info_user(RzDebug *dbg, RzDebugInfo *rdi) { HANDLE h_tok = NULL; DWORD tok_len = 0; PTOKEN_USER tok_usr = NULL; @@ -921,15 +921,15 @@ static void w32_info_user(RDebug *dbg, RDebugInfo *rdi) { HANDLE h_proc = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, dbg->pid); if (!h_proc) { - r_sys_perror ("w32_info_user/OpenProcess"); + rz_sys_perror ("w32_info_user/OpenProcess"); goto err_w32_info_user; } if (!OpenProcessToken (h_proc, TOKEN_QUERY, &h_tok)) { - r_sys_perror ("w32_info_user/OpenProcessToken"); + rz_sys_perror ("w32_info_user/OpenProcessToken"); goto err_w32_info_user; } if (!GetTokenInformation (h_tok, TokenUser, (LPVOID)&tok_usr, 0, &tok_len) && GetLastError () != ERROR_INSUFFICIENT_BUFFER) { - r_sys_perror ("w32_info_user/GetTokenInformation"); + rz_sys_perror ("w32_info_user/GetTokenInformation"); goto err_w32_info_user; } tok_usr = (PTOKEN_USER)malloc (tok_len); @@ -938,7 +938,7 @@ static void w32_info_user(RDebug *dbg, RDebugInfo *rdi) { goto err_w32_info_user; } if (!GetTokenInformation (h_tok, TokenUser, (LPVOID)tok_usr, tok_len, &tok_len)) { - r_sys_perror ("w32_info_user/GetTokenInformation"); + rz_sys_perror ("w32_info_user/GetTokenInformation"); goto err_w32_info_user; } usr = (LPTSTR)malloc (usr_len); @@ -954,13 +954,13 @@ static void w32_info_user(RDebug *dbg, RDebugInfo *rdi) { } *usr_dom = '\0'; if (!LookupAccountSid (NULL, tok_usr->User.Sid, usr, &usr_len, usr_dom, &usr_dom_len, &snu)) { - r_sys_perror ("w32_info_user/LookupAccountSid"); + rz_sys_perror ("w32_info_user/LookupAccountSid"); goto err_w32_info_user; } if (*usr_dom) { - rdi->usr = r_str_newf (W32_TCHAR_FSTR"\\"W32_TCHAR_FSTR, usr_dom, usr); + rdi->usr = rz_str_newf (W32_TCHAR_FSTR"\\"W32_TCHAR_FSTR, usr_dom, usr); } else { - rdi->usr = r_sys_conv_win_to_utf8 (usr); + rdi->usr = rz_sys_conv_win_to_utf8 (usr); } err_w32_info_user: if (h_proc) { @@ -974,7 +974,7 @@ err_w32_info_user: free (tok_usr); } -static void w32_info_exe(RDebug *dbg, RDebugInfo *rdi) { +static void w32_info_exe(RzDebug *dbg, RzDebugInfo *rdi) { LPTSTR path = NULL; HANDLE h_proc; DWORD len; @@ -984,7 +984,7 @@ static void w32_info_exe(RDebug *dbg, RDebugInfo *rdi) { } h_proc = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, dbg->pid); if (!h_proc) { - r_sys_perror ("w32_info_exe/OpenProcess"); + rz_sys_perror ("w32_info_exe/OpenProcess"); goto err_w32_info_exe; } path = (LPTSTR)malloc (MAX_PATH + 1); @@ -995,9 +995,9 @@ static void w32_info_exe(RDebug *dbg, RDebugInfo *rdi) { len = MAX_PATH; if (w32_QueryFullProcessImageName (h_proc, 0, path, &len)) { path[len] = '\0'; - rdi->exe = r_sys_conv_win_to_utf8 (path); + rdi->exe = rz_sys_conv_win_to_utf8 (path); } else { - r_sys_perror ("w32_info_exe/QueryFullProcessImageName"); + rz_sys_perror ("w32_info_exe/QueryFullProcessImageName"); } err_w32_info_exe: if (h_proc) { @@ -1006,13 +1006,13 @@ err_w32_info_exe: free (path); } -RDebugInfo *w32_info(RDebug *dbg, const char *arg) { - RDebugInfo *rdi = R_NEW0 (RDebugInfo); +RzDebugInfo *w32_info(RzDebug *dbg, const char *arg) { + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); rdi->status = R_DBG_PROC_SLEEP; // TODO: Fix this rdi->pid = dbg->pid; rdi->tid = dbg->tid; - rdi->lib = (void *) r_debug_get_lib_item(); - rdi->thread = (void *)r_debug_get_thread_item (); + rdi->lib = (void *) rz_debug_get_lib_item(); + rdi->thread = (void *)rz_debug_get_thread_item (); rdi->uid = -1; rdi->gid = -1; rdi->cwd = NULL; diff --git a/libr/debug/p/native/w32.h b/librz/debug/p/native/w32.h similarity index 94% rename from libr/debug/p/native/w32.h rename to librz/debug/p/native/w32.h index 885f41e6aa..dab2ab1c00 100644 --- a/libr/debug/p/native/w32.h +++ b/librz/debug/p/native/w32.h @@ -137,12 +137,12 @@ HANDLE (WINAPI *w32_CreateToolhelp32Snapshot)(DWORD, DWORD); #define CONTEXT_ALL 1048607 #endif void w32_break_process(void *d); -bool w32_terminate_process(RDebug *dbg, int pid); +bool w32_terminate_process(RzDebug *dbg, int pid); int w32_first_thread(int pid); -int w32_dbg_wait(RDebug *dbg, int pid); -RDebugInfo *w32_info(RDebug *dbg, const char *arg); -RList *w32_pids(int pid, RList *list); -RList *w32_thread_list(int pid, RList *list); +int w32_dbg_wait(RzDebug *dbg, int pid); +RzDebugInfo *w32_info(RzDebug *dbg, const char *arg); +RzList *w32_pids(int pid, RzList *list); +RzList *w32_thread_list(int pid, RzList *list); bool is_pe_hdr(unsigned char *pe_hdr); #include "maps/windows_maps.h" #endif \ No newline at end of file diff --git a/libr/debug/p/native/windows/windows_debug.c b/librz/debug/p/native/windows/windows_debug.c similarity index 87% rename from libr/debug/p/native/windows/windows_debug.c rename to librz/debug/p/native/windows/windows_debug.c index d56b0c679e..8f6cd30520 100644 --- a/libr/debug/p/native/windows/windows_debug.c +++ b/librz/debug/p/native/windows/windows_debug.c @@ -7,7 +7,7 @@ #undef WIN32_NO_STATUS const DWORD wait_time = 1000; -static RList *lib_list = NULL; +static RzList *lib_list = NULL; static PLIB_ITEM last_lib = NULL; #define w32_PROCESS_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF) @@ -33,7 +33,7 @@ bool setup_debug_privileges(bool b) { return ret; } -int w32_init(RDebug *dbg) { +int w32_init(RzDebug *dbg) { W32DbgWInst *wrap = dbg->user; if (!wrap) { if (dbg->iob.io->w32dbg_wrap) { @@ -146,18 +146,18 @@ static int __w32_findthread_cmp(int *tid, PTHREAD_ITEM th) { return (int)!(*tid == th->tid); } -static inline PTHREAD_ITEM __find_thread(RDebug *dbg, int tid) { +static inline PTHREAD_ITEM __find_thread(RzDebug *dbg, int tid) { if (!dbg->threads) { return NULL; } - RListIter *it = r_list_find (dbg->threads, &tid, (RListComparator)__w32_findthread_cmp); + RzListIter *it = rz_list_find (dbg->threads, &tid, (RzListComparator)__w32_findthread_cmp); return it ? it->data : NULL; } -static PTHREAD_ITEM __r_debug_thread_add(RDebug *dbg, DWORD pid, DWORD tid, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress, BOOL bFinished) { - r_return_val_if_fail (dbg, NULL); +static PTHREAD_ITEM __r_debug_thread_add(RzDebug *dbg, DWORD pid, DWORD tid, HANDLE hThread, LPVOID lpThreadLocalBase, LPVOID lpStartAddress, BOOL bFinished) { + rz_return_val_if_fail (dbg, NULL); if (!dbg->threads) { - dbg->threads = r_list_newf (free); + dbg->threads = rz_list_newf (free); } if (!lpStartAddress) { w32_NtQueryInformationThread (hThread, 9, &lpStartAddress, sizeof (LPVOID), NULL); @@ -182,7 +182,7 @@ static PTHREAD_ITEM __r_debug_thread_add(RDebug *dbg, DWORD pid, DWORD tid, HAND return NULL; } *pthread = th; - r_list_append (dbg->threads, pthread); + rz_list_append (dbg->threads, pthread); return pthread; } @@ -190,11 +190,11 @@ static int __suspend_thread(HANDLE th, int bits) { int ret; //if (bits == R_SYS_BITS_32) { if ((ret = SuspendThread (th)) == -1) { - r_sys_perror ("__suspend_thread/SuspendThread"); + rz_sys_perror ("__suspend_thread/SuspendThread"); } /*} else { if ((ret = Wow64SuspendThread (th)) == -1) { - r_sys_perror ("__suspend_thread/Wow64SuspendThread"); + rz_sys_perror ("__suspend_thread/Wow64SuspendThread"); } }*/ return ret; @@ -204,11 +204,11 @@ static int __resume_thread(HANDLE th, int bits) { int ret; //if (bits == R_SYS_BITS_32) { if ((ret = ResumeThread (th)) == -1) { - r_sys_perror ("__resume_thread/ResumeThread"); + rz_sys_perror ("__resume_thread/ResumeThread"); } /*} else { if ((ret = ResumeThread (th)) == -1) { - r_sys_perror ("__resume_thread/Wow64ResumeThread"); + rz_sys_perror ("__resume_thread/Wow64ResumeThread"); } }*/ return ret; @@ -221,7 +221,7 @@ static inline void __continue_thread(HANDLE th, int bits) { } while (ret > 0); } -static bool __is_thread_alive(RDebug *dbg, int tid) { +static bool __is_thread_alive(RzDebug *dbg, int tid) { PTHREAD_ITEM th = __find_thread (dbg, tid); if (!th) { return false; @@ -253,7 +253,7 @@ static int __set_thread_context(HANDLE th, const ut8 *buf, int size, int bits) { size = R_MIN (size, sizeof (ctx)); memcpy (&ctx, buf, size); if(!(ret = SetThreadContext (th, &ctx))) { - r_sys_perror ("__set_thread_context/SetThreadContext"); + rz_sys_perror ("__set_thread_context/SetThreadContext"); } return ret; } @@ -271,7 +271,7 @@ static int __get_thread_context(HANDLE th, ut8 *buf, int size, int bits) { ret = size; } else { if (__is_proc_alive (th)) { - r_sys_perror ("__get_thread_context/GetThreadContext"); + rz_sys_perror ("__get_thread_context/GetThreadContext"); } } return ret; @@ -419,7 +419,7 @@ static void __printwincontext(HANDLE th, CONTEXT *ctx) { } } -int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { bool showfpu = false; if (type < -1) { showfpu = true; // hack for debugging @@ -436,7 +436,7 @@ int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { } th = w32_OpenThread (flags, FALSE, dbg->tid); if (!th && alive) { - r_sys_perror ("w32_reg_read/OpenThread"); + rz_sys_perror ("w32_reg_read/OpenThread"); } if (!th) { return 0; @@ -461,7 +461,7 @@ int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return size; } -static void __transfer_drx(RDebug *dbg, const ut8 *buf) { +static void __transfer_drx(RzDebug *dbg, const ut8 *buf) { CONTEXT cur_ctx; if (w32_reg_read (dbg, R_REG_TYPE_ALL, (ut8 *)&cur_ctx, sizeof (CONTEXT))) { CONTEXT *new_ctx = (CONTEXT *)buf; @@ -471,14 +471,14 @@ static void __transfer_drx(RDebug *dbg, const ut8 *buf) { } } -int w32_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +int w32_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { DWORD flags = THREAD_SUSPEND_RESUME | THREAD_SET_CONTEXT; if (dbg->bits == R_SYS_BITS_64) { flags |= THREAD_QUERY_INFORMATION; } HANDLE th = w32_OpenThread (flags, FALSE, dbg->tid); if (!th) { - r_sys_perror ("w32_reg_write/OpenThread"); + rz_sys_perror ("w32_reg_write/OpenThread"); return false; } bool alive = __is_thread_alive (dbg, dbg->tid); @@ -499,7 +499,7 @@ int w32_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { return ret; } -int w32_attach(RDebug *dbg, int pid) { +int w32_attach(RzDebug *dbg, int pid) { W32DbgWInst *wrap = dbg->user; if (wrap->pi.hProcess) { return wrap->pi.dwThreadId; @@ -514,7 +514,7 @@ int w32_attach(RDebug *dbg, int pid) { w32dbg_wrap_wait_ret (wrap); if (!wrap->params.ret) { w32dbgw_err (wrap); - r_sys_perror ("DebugActiveProcess"); + rz_sys_perror ("DebugActiveProcess"); CloseHandle (ph); return -1; } @@ -522,7 +522,7 @@ int w32_attach(RDebug *dbg, int pid) { return wrap->pi.dwThreadId; } -int w32_detach(RDebug *dbg, int pid) { +int w32_detach(RzDebug *dbg, int pid) { if (pid == -1 || dbg->pid != pid) { return false; } @@ -603,7 +603,7 @@ err_get_file_name_from_handle: CloseHandle (handle_file_map); } if (filename) { - char *ret = r_sys_conv_win_to_utf8 (filename); + char *ret = rz_sys_conv_win_to_utf8 (filename); free (filename); return ret; } @@ -616,7 +616,7 @@ static char *__resolve_path(HANDLE ph, HANDLE mh) { TCHAR filename[MAX_PATH]; DWORD length = GetModuleFileNameEx (ph, mh, filename, maxlength); if (length > 0) { - return r_sys_conv_win_to_utf8 (filename); + return rz_sys_conv_win_to_utf8 (filename); } char *name = __get_file_name_from_handle (mh); if (name) { @@ -644,7 +644,7 @@ static char *__resolve_path(HANDLE ph, HANDLE mh) { if (!_tcsncmp (filename, device, length)) { TCHAR path[MAX_PATH]; _sntprintf (path, maxlength, TEXT ("%s%s"), drv, tmp); - ret = r_sys_conv_win_to_utf8 (path); + ret = rz_sys_conv_win_to_utf8 (path); break; } } @@ -668,21 +668,21 @@ static int findlibcmp(void *BaseOfDll, void *lib) { } static void *findlib(void *BaseOfDll) { - RListIter *it = r_list_find (lib_list, BaseOfDll, (RListComparator)findlibcmp); + RzListIter *it = rz_list_find (lib_list, BaseOfDll, (RzListComparator)findlibcmp); return it ? it->data : NULL; } static PLIB_ITEM lib_list_add(DWORD pid, LPVOID lpBaseOfDll, HANDLE hFile, char *dllname) { if (lib_list == NULL) { - lib_list = r_list_newf ((RListFree)libfree); + lib_list = rz_list_newf ((RzListFree)libfree); if (!lib_list) { R_LOG_ERROR ("Failed to allocate memory"); return NULL; } } - RListIter *it; + RzListIter *it; PLIB_ITEM lib; - r_list_foreach (lib_list, it, lib) { + rz_list_foreach (lib_list, it, lib) { if (lib->hFile == hFile && lib->BaseOfDll == lpBaseOfDll) { return lib; } @@ -696,15 +696,15 @@ static PLIB_ITEM lib_list_add(DWORD pid, LPVOID lpBaseOfDll, HANDLE hFile, char lib->hFile = hFile; lib->BaseOfDll = lpBaseOfDll; lib->Path = strdup (dllname); - lib->Name = strdup (r_file_basename (dllname)); + lib->Name = strdup (rz_file_basename (dllname)); - (void)r_list_append (lib_list, lib); + (void)rz_list_append (lib_list, lib); return lib; } static bool breaked = false; -int w32_attach_new_process(RDebug* dbg, int pid) { +int w32_attach_new_process(RzDebug* dbg, int pid) { int tid = -1; if (!w32_detach (dbg, dbg->pid)) { @@ -720,12 +720,12 @@ int w32_attach_new_process(RDebug* dbg, int pid) { dbg->tid = tid; dbg->pid = pid; // Call select to sync the new pid's data - r_debug_select (dbg, pid, tid); + rz_debug_select (dbg, pid, tid); return dbg->tid; } -int w32_select(RDebug *dbg, int pid, int tid) { - RListIter *it; +int w32_select(RzDebug *dbg, int pid, int tid) { + RzListIter *it; W32DbgWInst *wrap = dbg->user; // Re-attach to a different pid @@ -738,7 +738,7 @@ int w32_select(RDebug *dbg, int pid, int tid) { } if (!dbg->threads) { - dbg->threads = r_list_newf (free); + dbg->threads = rz_list_newf (free); } PTHREAD_ITEM th = __find_thread (dbg, tid); @@ -753,7 +753,7 @@ int w32_select(RDebug *dbg, int pid, int tid) { selected = tid; } else if (tid) { // If thread is dead, search for another one - r_list_foreach (dbg->threads, it, th) { + rz_list_foreach (dbg->threads, it, th) { if (!__is_thread_alive (dbg, th->tid)) { continue; } @@ -765,7 +765,7 @@ int w32_select(RDebug *dbg, int pid, int tid) { if (dbg->corebind.cfggeti (dbg->corebind.core, "dbg.threads")) { // Suspend all other threads - r_list_foreach (dbg->threads, it, th) { + rz_list_foreach (dbg->threads, it, th) { if (!th->bFinished && !th->bSuspended && th->tid != selected) { __suspend_thread (th->hThread, dbg->bits); th->bSuspended = true; @@ -776,16 +776,16 @@ int w32_select(RDebug *dbg, int pid, int tid) { return selected; } -int w32_kill(RDebug *dbg, int pid, int tid, int sig) { +int w32_kill(RzDebug *dbg, int pid, int tid, int sig) { W32DbgWInst *wrap = dbg->user; if (sig == 0) { - if (r_list_empty (dbg->threads) || (dbg->reason.tid == pid && dbg->reason.signum == EXIT_PROCESS_DEBUG_EVENT)) { + if (rz_list_empty (dbg->threads) || (dbg->reason.tid == pid && dbg->reason.signum == EXIT_PROCESS_DEBUG_EVENT)) { if (dbg->threads) { - r_list_purge (dbg->threads); + rz_list_purge (dbg->threads); } if (lib_list) { - r_list_purge (lib_list); + rz_list_purge (lib_list); } return false; } @@ -803,13 +803,13 @@ int w32_kill(RDebug *dbg, int pid, int tid, int sig) { } void w32_break_process(void *user) { - RDebug *dbg = (RDebug *)user; + RzDebug *dbg = (RzDebug *)user; W32DbgWInst *wrap = dbg->user; if (dbg->corebind.cfggeti (dbg->corebind.core, "dbg.threads")) { w32_select (dbg, wrap->pi.dwProcessId, -1); // Suspend all threads } else { if (!w32_DebugBreakProcess (wrap->pi.hProcess)) { - r_sys_perror ("w32_break_process/DebugBreakProcess"); + rz_sys_perror ("w32_break_process/DebugBreakProcess"); eprintf("Could not interrupt program, attempt to press Ctrl-C in the program's console.\n"); } } @@ -817,7 +817,7 @@ void w32_break_process(void *user) { breaked = true; } -static RDebugReasonType exception_to_reason (DWORD ExceptionCode) { +static RzDebugReasonType exception_to_reason (DWORD ExceptionCode) { switch (ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: case EXCEPTION_GUARD_PAGE: @@ -919,7 +919,7 @@ static char *__r_debug_get_dll(void) { } #endif -int w32_dbg_wait(RDebug *dbg, int pid) { +int w32_dbg_wait(RzDebug *dbg, int pid) { W32DbgWInst *wrap = dbg->user; DEBUG_EVENT de; int tid, next_event = 0; @@ -927,7 +927,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) { int ret = R_DEBUG_REASON_UNKNOWN; static int exited_already = 0; - r_cons_break_push (w32_break_process, dbg); + rz_cons_break_push (w32_break_process, dbg); /* handle debug events */ do { @@ -940,12 +940,12 @@ int w32_dbg_wait(RDebug *dbg, int pid) { wrap->params.type = W32_WAIT; wrap->params.wait.de = &de; wrap->params.wait.wait_time = wait_time; - void *bed = r_cons_sleep_begin (); + void *bed = rz_cons_sleep_begin (); w32dbg_wrap_wait_ret (wrap); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (!w32dbgw_ret (wrap)) { if (w32dbgw_err (wrap) != ERROR_SEM_TIMEOUT) { - r_sys_perror ("w32_dbg_wait/WaitForDebugEvent"); + rz_sys_perror ("w32_dbg_wait/WaitForDebugEvent"); ret = -1; goto end; } @@ -1036,8 +1036,8 @@ int w32_dbg_wait(RDebug *dbg, int pid) { char *str = calloc (de.u.DebugString.nDebugStringLength, sizeof (TCHAR)); ReadProcessMemory (wrap->pi.hProcess, de.u.DebugString.lpDebugStringData, str, de.u.DebugString.nDebugStringLength, NULL); char *tmp = de.u.DebugString.fUnicode - ? r_utf16_to_utf8 ((wchar_t *)str) - : r_acp_to_utf8 (str); + ? rz_utf16_to_utf8 ((wchar_t *)str) + : rz_acp_to_utf8 (str); if (tmp) { free (str); str = tmp; @@ -1082,7 +1082,7 @@ int w32_dbg_wait(RDebug *dbg, int pid) { dbg->reason.type = exception_to_reason (de.u.Exception.ExceptionRecord.ExceptionCode); dbg->reason.tid = de.dwThreadId; dbg->reason.addr = (size_t)de.u.Exception.ExceptionRecord.ExceptionAddress; - dbg->reason.timestamp = r_time_now (); + dbg->reason.timestamp = rz_time_now (); ret = dbg->reason.type; } else { w32_continue (dbg, pid, tid, DBG_EXCEPTION_NOT_HANDLED); @@ -1112,14 +1112,14 @@ int w32_dbg_wait(RDebug *dbg, int pid) { end: if (ret == R_DEBUG_REASON_DEAD) { w32_detach (dbg, dbg->pid); - r_list_purge (dbg->threads); - r_list_purge (lib_list); + rz_list_purge (dbg->threads); + rz_list_purge (lib_list); } - r_cons_break_pop (); + rz_cons_break_pop (); return ret; } -int w32_step(RDebug *dbg) { +int w32_step(RzDebug *dbg) { /* set TRAP flag */ CONTEXT ctx; if (!w32_reg_read (dbg, R_REG_TYPE_GPR, (ut8 *)&ctx, sizeof (ctx))) { @@ -1130,13 +1130,13 @@ int w32_step(RDebug *dbg) { return false; } return w32_continue (dbg, dbg->pid, dbg->tid, dbg->reason.signum); - // (void)r_debug_handle_signals (dbg); + // (void)rz_debug_handle_signals (dbg); } -int w32_continue(RDebug *dbg, int pid, int tid, int sig) { +int w32_continue(RzDebug *dbg, int pid, int tid, int sig) { if (tid != dbg->tid) { dbg->tid = w32_select (dbg, pid, tid); - r_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); + rz_io_system (dbg->iob.io, sdb_fmt ("pid %d", dbg->tid)); } // Don't continue with a thread that wasn't requested if (dbg->tid != tid) { @@ -1165,28 +1165,28 @@ int w32_continue(RDebug *dbg, int pid, int tid, int sig) { w32dbg_wrap_wait_ret (wrap); if (!w32dbgw_ret (wrap)) { w32dbgw_err (wrap); - r_sys_perror ("w32_continue/ContinueDebugEvent"); + rz_sys_perror ("w32_continue/ContinueDebugEvent"); return -1; } return tid; } -RDebugMap *w32_map_alloc(RDebug *dbg, ut64 addr, int size) { +RzDebugMap *w32_map_alloc(RzDebug *dbg, ut64 addr, int size) { W32DbgWInst *wrap = dbg->user; LPVOID base = VirtualAllocEx (wrap->pi.hProcess, (LPVOID)addr, (SIZE_T)size, MEM_COMMIT, PAGE_READWRITE); if (!base) { - r_sys_perror ("w32_map_alloc/VirtualAllocEx"); + rz_sys_perror ("w32_map_alloc/VirtualAllocEx"); return NULL; } - r_debug_map_sync (dbg); - return r_debug_map_get (dbg, (ut64)base); + rz_debug_map_sync (dbg); + return rz_debug_map_get (dbg, (ut64)base); } -int w32_map_dealloc(RDebug *dbg, ut64 addr, int size) { +int w32_map_dealloc(RzDebug *dbg, ut64 addr, int size) { W32DbgWInst *wrap = dbg->user; if (!VirtualFreeEx (wrap->pi.hProcess, (LPVOID)addr, 0, MEM_RELEASE)) { - r_sys_perror ("w32_map_dealloc/VirtualFreeEx"); + rz_sys_perror ("w32_map_dealloc/VirtualFreeEx"); return false; } return true; @@ -1215,18 +1215,18 @@ static int __io_perms_to_prot(int io_perms) { return prot_perms; } -int w32_map_protect(RDebug *dbg, ut64 addr, int size, int perms) { +int w32_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { DWORD old; W32DbgWInst *wrap = dbg->user; return VirtualProtectEx (wrap->pi.hProcess, (LPVOID)(size_t)addr, size, __io_perms_to_prot (perms), &old); } -RList *w32_thread_list(RDebug *dbg, int pid, RList *list) { +RzList *w32_thread_list(RzDebug *dbg, int pid, RzList *list) { // pid is not respected for TH32CS_SNAPTHREAD flag HANDLE th = w32_CreateToolhelp32Snapshot (TH32CS_SNAPTHREAD, 0); if (th == INVALID_HANDLE_VALUE) { - r_sys_perror ("w32_thread_list/CreateToolhelp32Snapshot"); + rz_sys_perror ("w32_thread_list/CreateToolhelp32Snapshot"); return list; } THREADENTRY32 te; @@ -1273,19 +1273,19 @@ RList *w32_thread_list(RDebug *dbg, int pid, RList *list) { } } } - r_list_append (list, r_debug_pid_new (path, te.th32ThreadID, uid, status, pc)); + rz_list_append (list, rz_debug_pid_new (path, te.th32ThreadID, uid, status, pc)); } } while (Thread32Next (th, &te)); dbg->tid = saved_tid; free (path); } else { - r_sys_perror ("w32_thread_list/Thread32First"); + rz_sys_perror ("w32_thread_list/Thread32First"); } CloseHandle (th); return list; } -static void __w32_info_user(RDebug *dbg, RDebugInfo *rdi) { +static void __w32_info_user(RzDebug *dbg, RzDebugInfo *rdi) { HANDLE h_tok = NULL; DWORD tok_len = 0; PTOKEN_USER tok_usr = NULL; @@ -1300,11 +1300,11 @@ static void __w32_info_user(RDebug *dbg, RDebugInfo *rdi) { } if (!OpenProcessToken (wrap->pi.hProcess, TOKEN_QUERY, &h_tok)) { - r_sys_perror ("__w32_info_user/OpenProcessToken"); + rz_sys_perror ("__w32_info_user/OpenProcessToken"); goto err___w32_info_user; } if (!GetTokenInformation (h_tok, TokenUser, (LPVOID)&tok_usr, 0, &tok_len) && GetLastError () != ERROR_INSUFFICIENT_BUFFER) { - r_sys_perror ("__w32_info_user/GetTokenInformation"); + rz_sys_perror ("__w32_info_user/GetTokenInformation"); goto err___w32_info_user; } tok_usr = (PTOKEN_USER)malloc (tok_len); @@ -1313,7 +1313,7 @@ static void __w32_info_user(RDebug *dbg, RDebugInfo *rdi) { goto err___w32_info_user; } if (!GetTokenInformation (h_tok, TokenUser, (LPVOID)tok_usr, tok_len, &tok_len)) { - r_sys_perror ("__w32_info_user/GetTokenInformation"); + rz_sys_perror ("__w32_info_user/GetTokenInformation"); goto err___w32_info_user; } usr = (LPTSTR)malloc (usr_len * sizeof (TCHAR)); @@ -1329,13 +1329,13 @@ static void __w32_info_user(RDebug *dbg, RDebugInfo *rdi) { } *usr_dom = '\0'; if (!LookupAccountSid (NULL, tok_usr->User.Sid, usr, &usr_len, usr_dom, &usr_dom_len, &snu)) { - r_sys_perror ("__w32_info_user/LookupAccountSid"); + rz_sys_perror ("__w32_info_user/LookupAccountSid"); goto err___w32_info_user; } if (*usr_dom) { - rdi->usr = r_str_newf (W32_TCHAR_FSTR"\\"W32_TCHAR_FSTR, usr_dom, usr); + rdi->usr = rz_str_newf (W32_TCHAR_FSTR"\\"W32_TCHAR_FSTR, usr_dom, usr); } else { - rdi->usr = r_sys_conv_win_to_utf8 (usr); + rdi->usr = rz_sys_conv_win_to_utf8 (usr); } err___w32_info_user: if (h_tok) { @@ -1346,13 +1346,13 @@ err___w32_info_user: free (tok_usr); } -static void __w32_info_exe(RDebug *dbg, RDebugInfo *rdi) { +static void __w32_info_exe(RzDebug *dbg, RzDebugInfo *rdi) { W32DbgWInst *wrap = dbg->user; rdi->exe = __resolve_path (wrap->pi.hProcess, NULL); } -RDebugInfo *w32_info(RDebug *dbg, const char *arg) { - RDebugInfo *rdi = R_NEW0 (RDebugInfo); +RzDebugInfo *w32_info(RzDebug *dbg, const char *arg) { + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) { return NULL; } @@ -1372,7 +1372,7 @@ RDebugInfo *w32_info(RDebug *dbg, const char *arg) { return rdi; } -static RDebugPid *__build_debug_pid(int pid, int ppid, HANDLE ph, const TCHAR* name) { +static RzDebugPid *__build_debug_pid(int pid, int ppid, HANDLE ph, const TCHAR* name) { char *path = NULL; int uid = -1; if (!ph) { @@ -1395,19 +1395,19 @@ static RDebugPid *__build_debug_pid(int pid, int ppid, HANDLE ph, const TCHAR* n } } if (!path) { - path = r_sys_conv_win_to_utf8 (name); + path = rz_sys_conv_win_to_utf8 (name); } // it is possible to get pc for a non debugged process but the operation is expensive and might be risky - RDebugPid *ret = r_debug_pid_new (path, pid, uid, 's', 0); + RzDebugPid *ret = rz_debug_pid_new (path, pid, uid, 's', 0); ret->ppid = ppid; free (path); return ret; } -RList *w32_pid_list(RDebug *dbg, int pid, RList *list) { +RzList *w32_pid_list(RzDebug *dbg, int pid, RzList *list) { HANDLE sh = w32_CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, pid); if (sh == INVALID_HANDLE_VALUE) { - r_sys_perror ("w32_pid_list/CreateToolhelp32Snapshot"); + rz_sys_perror ("w32_pid_list/CreateToolhelp32Snapshot"); return list; } PROCESSENTRY32 pe; @@ -1418,10 +1418,10 @@ RList *w32_pid_list(RDebug *dbg, int pid, RList *list) { do { if (all || pe.th32ProcessID == pid || pe.th32ParentProcessID == pid) { // Returns NULL if process is inaccessible unless if its a child process of debugged process - RDebugPid *dbg_pid = __build_debug_pid (pe.th32ProcessID, pe.th32ParentProcessID, + RzDebugPid *dbg_pid = __build_debug_pid (pe.th32ProcessID, pe.th32ParentProcessID, dbg->pid == pe.th32ProcessID ? wrap->pi.hProcess : NULL, pe.szExeFile); if (dbg_pid) { - r_list_append (list, dbg_pid); + rz_list_append (list, dbg_pid); } #if 0 else { @@ -1431,27 +1431,27 @@ RList *w32_pid_list(RDebug *dbg, int pid, RList *list) { } } while (Process32Next (sh, &pe)); } else { - r_sys_perror ("w32_pid_list/Process32First"); + rz_sys_perror ("w32_pid_list/Process32First"); } CloseHandle (sh); return list; } -RList *w32_desc_list(int pid) { - RDebugDesc *desc; +RzList *w32_desc_list(int pid) { + RzDebugDesc *desc; int i; HANDLE ph; PSYSTEM_HANDLE_INFORMATION handleInfo; NTSTATUS status; ULONG handleInfoSize = 0x10000; POBJECT_TYPE_INFORMATION objectTypeInfo = malloc (0x1000); - RList *ret = r_list_newf ((RListFree)r_debug_desc_free); + RzList *ret = rz_list_newf ((RzListFree)rz_debug_desc_free); if (!ret) { return NULL; } if (!(ph = w32_OpenProcess (PROCESS_DUP_HANDLE, FALSE, pid))) { - r_sys_perror ("win_desc_list/OpenProcess"); - r_list_free (ret); + rz_sys_perror ("win_desc_list/OpenProcess"); + rz_list_free (ret); return NULL; } handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc (handleInfoSize); @@ -1464,9 +1464,9 @@ RList *w32_desc_list(int pid) { } } if (status) { - r_sys_perror ("win_desc_list/NtQuerySystemInformation"); + rz_sys_perror ("win_desc_list/NtQuerySystemInformation"); CloseHandle (ph); - r_list_free (ret); + rz_list_free (ret); return NULL; } for (i = 0; i < handleInfo->HandleCount; i++) { @@ -1516,22 +1516,22 @@ RList *w32_desc_list(int pid) { } objectName = *(PUNICODE_STRING)objectNameInfo; if (objectName.Length) { - char *name = r_utf16_to_utf8_l (objectName.Buffer, objectName.Length / 2); - desc = r_debug_desc_new (handle.Handle, name, perms, '?', 0); + char *name = rz_utf16_to_utf8_l (objectName.Buffer, objectName.Length / 2); + desc = rz_debug_desc_new (handle.Handle, name, perms, '?', 0); if (!desc) { free (name); break; } - r_list_append (ret, desc); + rz_list_append (ret, desc); free (name); } else { - char *name = r_utf16_to_utf8_l (objectTypeInfo->Name.Buffer, objectTypeInfo->Name.Length / 2); - desc = r_debug_desc_new (handle.Handle, name, perms, '?', 0); + char *name = rz_utf16_to_utf8_l (objectTypeInfo->Name.Buffer, objectTypeInfo->Name.Length / 2); + desc = rz_debug_desc_new (handle.Handle, name, perms, '?', 0); if (!desc) { free (name); break; } - r_list_append (ret, desc); + rz_list_append (ret, desc); free (name); } free (objectNameInfo); diff --git a/libr/debug/p/native/windows/windows_debug.h b/librz/debug/p/native/windows/windows_debug.h similarity index 80% rename from libr/debug/p/native/windows/windows_debug.h rename to librz/debug/p/native/windows/windows_debug.h index c9c17b3a8c..9eb1a020e3 100644 --- a/libr/debug/p/native/windows/windows_debug.h +++ b/librz/debug/p/native/windows/windows_debug.h @@ -7,8 +7,8 @@ |___|___| */ -#include -#include +#include +#include #include #include @@ -142,29 +142,29 @@ DWORD (WINAPI *w32_GetModuleFileNameEx)(HANDLE, HMODULE, LPTSTR, DWORD); HANDLE (WINAPI *w32_CreateToolhelp32Snapshot)(DWORD, DWORD); // APIs -int w32_init(RDebug *dbg); +int w32_init(RzDebug *dbg); -int w32_reg_read(RDebug *dbg, int type, ut8 *buf, int size); -int w32_reg_write(RDebug *dbg, int type, const ut8 *buf, int size); +int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size); +int w32_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size); -int w32_attach(RDebug *dbg, int pid); -int w32_detach(RDebug *dbg, int pid); -int w32_attach_new_process(RDebug* dbg, int pid); -int w32_select(RDebug *dbg, int pid, int tid); -int w32_kill(RDebug *dbg, int pid, int tid, int sig); +int w32_attach(RzDebug *dbg, int pid); +int w32_detach(RzDebug *dbg, int pid); +int w32_attach_new_process(RzDebug* dbg, int pid); +int w32_select(RzDebug *dbg, int pid, int tid); +int w32_kill(RzDebug *dbg, int pid, int tid, int sig); void w32_break_process(void *user); -int w32_dbg_wait(RDebug *dbg, int pid); +int w32_dbg_wait(RzDebug *dbg, int pid); -int w32_step(RDebug *dbg); -int w32_continue(RDebug *dbg, int pid, int tid, int sig); -RDebugMap *w32_map_alloc(RDebug *dbg, ut64 addr, int size); -int w32_map_dealloc(RDebug *dbg, ut64 addr, int size); -int w32_map_protect(RDebug *dbg, ut64 addr, int size, int perms); +int w32_step(RzDebug *dbg); +int w32_continue(RzDebug *dbg, int pid, int tid, int sig); +RzDebugMap *w32_map_alloc(RzDebug *dbg, ut64 addr, int size); +int w32_map_dealloc(RzDebug *dbg, ut64 addr, int size); +int w32_map_protect(RzDebug *dbg, ut64 addr, int size, int perms); -RList *w32_thread_list(RDebug *dbg, int pid, RList *list); -RDebugInfo *w32_info(RDebug *dbg, const char *arg); +RzList *w32_thread_list(RzDebug *dbg, int pid, RzList *list); +RzDebugInfo *w32_info(RzDebug *dbg, const char *arg); -RList *w32_pid_list(RDebug *dbg, int pid, RList *list); +RzList *w32_pid_list(RzDebug *dbg, int pid, RzList *list); -RList *w32_desc_list(int pid); +RzList *w32_desc_list(int pid); #endif \ No newline at end of file diff --git a/libr/debug/p/native/windows/windows_message.c b/librz/debug/p/native/windows/windows_message.c similarity index 81% rename from libr/debug/p/native/windows/windows_message.c rename to librz/debug/p/native/windows/windows_message.c index 0fb263a233..125b7d0714 100644 --- a/libr/debug/p/native/windows/windows_message.c +++ b/librz/debug/p/native/windows/windows_message.c @@ -1,5 +1,5 @@ -/* radare2 - LGPL - Copyright 2019 - GustavoLCR */ -#include +/* rizin - LGPL - Copyright 2019 - GustavoLCR */ +#include #include "windows_message.h" static char *msg_types_arr[] = { @@ -253,7 +253,7 @@ void __free_window (void *ptr) { } static window *__window_from_handle(HANDLE hwnd) { - r_return_val_if_fail (hwnd, NULL); + rz_return_val_if_fail (hwnd, NULL); window *win = R_NEW0 (window); if (!win) { return NULL; @@ -268,7 +268,7 @@ static window *__window_from_handle(HANDLE hwnd) { return NULL; } GetClassNameW (hwnd, tmp, MAX_CLASS_NAME); - win->name = r_utf16_to_utf8 (tmp); + win->name = rz_utf16_to_utf8 (tmp); free (tmp); if (!win->name) { win->name = strdup (""); @@ -277,36 +277,36 @@ static window *__window_from_handle(HANDLE hwnd) { } static RTable *__create_window_table(void) { - RTable *tbl = r_table_new (); + RTable *tbl = rz_table_new (); if (!tbl) { return NULL; } - r_table_add_column (tbl, r_table_type ("number"), "Handle", ST32_MAX); - r_table_add_column (tbl, r_table_type ("number"), "PID", ST32_MAX); - r_table_add_column (tbl, r_table_type ("number"), "TID", ST32_MAX); - r_table_add_column (tbl, r_table_type ("string"), "Class Name", ST32_MAX); + rz_table_add_column (tbl, rz_table_type ("number"), "Handle", ST32_MAX); + rz_table_add_column (tbl, rz_table_type ("number"), "PID", ST32_MAX); + rz_table_add_column (tbl, rz_table_type ("number"), "TID", ST32_MAX); + rz_table_add_column (tbl, rz_table_type ("string"), "Class Name", ST32_MAX); return tbl; } static void __add_window_to_table(RTable *tbl, window *win) { - r_return_if_fail (tbl && win); - char *handle = r_str_newf ("0x%08"PFMT64x"", win->h); - char *pid = r_str_newf ("%lu", win->pid); - char *tid = r_str_newf ("%lu", win->tid); - r_table_add_row (tbl, handle, pid, tid, win->name, NULL); + rz_return_if_fail (tbl && win); + char *handle = rz_str_newf ("0x%08"PFMT64x"", win->h); + char *pid = rz_str_newf ("%lu", win->pid); + char *tid = rz_str_newf ("%lu", win->tid); + rz_table_add_row (tbl, handle, pid, tid, win->name, NULL); free (handle); free (tid); free (pid); } -R_API void r_w32_identify_window(void) { - while (!r_cons_yesno ('y', "Move cursor to the window to be identified. Ready?")); +RZ_API void rz_w32_identify_window(void) { + while (!rz_cons_yesno ('y', "Move cursor to the window to be identified. Ready?")); POINT p; GetCursorPos (&p); HANDLE hwnd = WindowFromPoint (p); window *win = NULL; if (hwnd) { - if (r_cons_yesno ('y', "Try to get the child?")) { + if (rz_cons_yesno ('y', "Try to get the child?")) { HANDLE child = ChildWindowFromPoint (hwnd, p); hwnd = child ? child : hwnd; } @@ -324,27 +324,27 @@ R_API void r_w32_identify_window(void) { return; } __add_window_to_table (tbl, win); - char *tbl_str = r_table_tofancystring (tbl); - r_cons_print (tbl_str); + char *tbl_str = rz_table_tofancystring (tbl); + rz_cons_print (tbl_str); free (tbl_str); - r_table_free (tbl); + rz_table_free (tbl); } static BOOL CALLBACK __enum_childs( _In_ HWND hwnd, _In_ LPARAM lParam ) { - RList *windows = (RList *)lParam; + RzList *windows = (RzList *)lParam; window *win = __window_from_handle (hwnd); if (!win) { return false; } - r_list_push (windows, win); + rz_list_push (windows, win); return true; } -static RList *__get_windows(RDebug *dbg) { - RList *windows = r_list_newf ((RListFree)__free_window); +static RzList *__get_windows(RzDebug *dbg) { + RzList *windows = rz_list_newf ((RzListFree)__free_window); HWND hCurWnd = NULL; do { hCurWnd = FindWindowEx (NULL, hCurWnd, NULL, NULL); @@ -354,21 +354,21 @@ static RList *__get_windows(RDebug *dbg) { EnumChildWindows (hCurWnd, __enum_childs, (LPARAM)windows); window *win = __window_from_handle (hCurWnd); if (!win) { - r_list_free (windows); + rz_list_free (windows); return NULL; } - r_list_push (windows, win); + rz_list_push (windows, win); } } while (hCurWnd != NULL); return windows; } -static ut64 __get_dispatchmessage_offset(RDebug *dbg) { - RList *modlist = r_debug_modules_list (dbg); - RListIter *it; - RDebugMap *mod; +static ut64 __get_dispatchmessage_offset(RzDebug *dbg) { + RzList *modlist = rz_debug_modules_list (dbg); + RzListIter *it; + RzDebugMap *mod; bool found = false; - r_list_foreach (modlist, it, mod) { + rz_list_foreach (modlist, it, mod) { if (!strnicmp (mod->name, "user32.dll", sizeof ("user32.dll"))) { found = true; break; @@ -386,8 +386,8 @@ static ut64 __get_dispatchmessage_offset(RDebug *dbg) { ut64 offset = 0; do { char *sym = strrchr (line, ' '); - if (sym && r_str_startswith (sym + 1, "sym.imp")) { - offset = r_num_math (NULL, line); + if (sym && rz_str_startswith (sym + 1, "sym.imp")) { + offset = rz_num_math (NULL, line); dbg->iob.read_at (dbg->iob.io, offset, (ut8 *)&offset, sizeof (offset)); break; } @@ -413,30 +413,30 @@ static DWORD __get_msg_type(char *name) { ut32 found; const char *type_str = sdb_const_get (msg_types, name, &found); if (found) { - int type = r_num_math (NULL, type_str); + int type = rz_num_math (NULL, type_str); return type; } return 0; } -static void __print_windows(RDebug *dbg, RList *windows) { +static void __print_windows(RzDebug *dbg, RzList *windows) { RTable *tbl = __create_window_table (); if (!tbl) { return; } - RListIter *it; + RzListIter *it; window *win; - r_list_foreach (windows, it, win) { + rz_list_foreach (windows, it, win) { __add_window_to_table (tbl, win); } - char *t = r_table_tofancystring (tbl); + char *t = rz_table_tofancystring (tbl); dbg->cb_printf (t); free (t); - r_table_free (tbl); + rz_table_free (tbl); } -R_API void r_w32_print_windows(RDebug *dbg) { - RList *windows = __get_windows (dbg); +RZ_API void rz_w32_print_windows(RzDebug *dbg) { + RzList *windows = __get_windows (dbg); if (windows) { if (!windows->length) { dbg->cb_printf ("No windows for this process.\n"); @@ -444,13 +444,13 @@ R_API void r_w32_print_windows(RDebug *dbg) { } __print_windows (dbg, windows); } - r_list_free (windows); + rz_list_free (windows); } -R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input) { - r_return_val_if_fail (dbg && input, false); +RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *input) { + rz_return_val_if_fail (dbg && input, false); char *name = strdup (input); - r_str_trim (name); + rz_str_trim (name); char *window_id = strchr (name, ' '); if (window_id) { *window_id = 0; @@ -463,14 +463,14 @@ R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input) { } ut64 offset = 0; if (window_id) { - RList *windows = __get_windows (dbg); + RzList *windows = __get_windows (dbg); if (windows && !windows->length) { dbg->cb_printf ("No windows for this process.\n"); } - ut64 win_h = r_num_math (NULL, window_id); - RListIter *it; + ut64 win_h = rz_num_math (NULL, window_id); + RzListIter *it; window *win; - r_list_foreach (windows, it, win) { + rz_list_foreach (windows, it, win) { if ((ut64)win->h == win_h || !strnicmp (win->name, window_id, strlen (window_id))) { offset = win->proc; break; @@ -480,7 +480,7 @@ R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input) { dbg->cb_printf ("Window not found, try these:\n"); __print_windows (dbg, windows); } - r_list_free (windows); + rz_list_free (windows); } else { offset = __get_dispatchmessage_offset (dbg); } @@ -488,10 +488,10 @@ R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input) { free (name); return false; } - r_debug_bp_add (dbg, offset, 0, 0, 0, NULL, 0); + rz_debug_bp_add (dbg, offset, 0, 0, 0, NULL, 0); char *cond; if (window_id) { - cond = r_str_newf ("?= `ae %d,edx,-`", type); + cond = rz_str_newf ("?= `ae %d,edx,-`", type); } else { char *reg; if (dbg->bits == R_SYS_BITS_64) { @@ -499,7 +499,7 @@ R_API bool r_w32_add_winmsg_breakpoint(RDebug *dbg, const char *input) { } else { reg = "ecx"; } - cond = r_str_newf ("?= `ae %d,%s,%d,+,[4],-`", type, reg, dbg->bits); + cond = rz_str_newf ("?= `ae %d,%s,%d,+,[4],-`", type, reg, dbg->bits); } dbg->corebind.cmdf (dbg->corebind.core, "\"dbC 0x%"PFMT64x" %s\"", offset, cond); free (name); diff --git a/librz/debug/p/native/windows/windows_message.h b/librz/debug/p/native/windows/windows_message.h new file mode 100644 index 0000000000..fdfff297b8 --- /dev/null +++ b/librz/debug/p/native/windows/windows_message.h @@ -0,0 +1,13 @@ +#include + +typedef struct _window { + DWORD pid; + DWORD tid; + HANDLE h; + char *name; + ut64 proc; +} window; + +RZ_API bool rz_w32_add_winmsg_breakpoint(RzDebug *dbg, const char *input); +RZ_API void rz_w32_identify_window(void); +RZ_API void rz_w32_print_windows(RzDebug *dbg); diff --git a/libr/debug/p/native/xnu/reg/darwin-arm.h b/librz/debug/p/native/xnu/reg/darwin-arm.h similarity index 100% rename from libr/debug/p/native/xnu/reg/darwin-arm.h rename to librz/debug/p/native/xnu/reg/darwin-arm.h diff --git a/libr/debug/p/native/xnu/reg/darwin-arm64.h b/librz/debug/p/native/xnu/reg/darwin-arm64.h similarity index 100% rename from libr/debug/p/native/xnu/reg/darwin-arm64.h rename to librz/debug/p/native/xnu/reg/darwin-arm64.h diff --git a/libr/debug/p/native/xnu/reg/darwin-ppc.h b/librz/debug/p/native/xnu/reg/darwin-ppc.h similarity index 100% rename from libr/debug/p/native/xnu/reg/darwin-ppc.h rename to librz/debug/p/native/xnu/reg/darwin-ppc.h diff --git a/libr/debug/p/native/xnu/reg/darwin-x64.h b/librz/debug/p/native/xnu/reg/darwin-x64.h similarity index 100% rename from libr/debug/p/native/xnu/reg/darwin-x64.h rename to librz/debug/p/native/xnu/reg/darwin-x64.h diff --git a/libr/debug/p/native/xnu/reg/darwin-x86.h b/librz/debug/p/native/xnu/reg/darwin-x86.h similarity index 100% rename from libr/debug/p/native/xnu/reg/darwin-x86.h rename to librz/debug/p/native/xnu/reg/darwin-x86.h diff --git a/libr/debug/p/native/xnu/trap_arm.c b/librz/debug/p/native/xnu/trap_arm.c similarity index 92% rename from libr/debug/p/native/xnu/trap_arm.c rename to librz/debug/p/native/xnu/trap_arm.c index c7a8e00bc9..2d09b2cf13 100644 --- a/libr/debug/p/native/xnu/trap_arm.c +++ b/librz/debug/p/native/xnu/trap_arm.c @@ -4,7 +4,7 @@ static int isThumb32(ut16 op) { return (((op & 0xE000) == 0xE000) && (op & 0x1800)); } -static bool ios_hwstep_enable64(RDebug *dbg, bool enable) { +static bool ios_hwstep_enable64(RzDebug *dbg, bool enable) { ARMDebugState64 ds; thread_t th = getcurthread (dbg, NULL); @@ -30,7 +30,7 @@ static bool ios_hwstep_enable64(RDebug *dbg, bool enable) { return true; } -static bool ios_hwstep_enable32(RDebug *dbg, bool enable) { +static bool ios_hwstep_enable32(RzDebug *dbg, bool enable) { mach_msg_type_number_t count; arm_unified_thread_state_t state = {{0}}; _STRUCT_ARM_DEBUG_STATE ds; @@ -52,7 +52,7 @@ static bool ios_hwstep_enable32(RDebug *dbg, bool enable) { //eprintf ("PC = 0x%08x\n", state.ts_32.__pc); if (enable) { int i; - RIOBind *bio = &dbg->iob; + RzIOBind *bio = &dbg->iob; ut32 pc = state.ts_32.__pc; ut32 cpsr = state.ts_32.__cpsr; for (i = 0; i < 16 ; i++) { @@ -86,7 +86,7 @@ static bool ios_hwstep_enable32(RDebug *dbg, bool enable) { return true; } -bool xnu_native_hwstep_enable(RDebug *dbg, bool enable) { +bool xnu_native_hwstep_enable(RzDebug *dbg, bool enable) { if (dbg->bits == R_SYS_BITS_64 || dbg->bits == 64) { return ios_hwstep_enable64 (dbg, enable); } diff --git a/libr/debug/p/native/xnu/trap_x86.c b/librz/debug/p/native/xnu/trap_x86.c similarity index 82% rename from libr/debug/p/native/xnu/trap_x86.c rename to librz/debug/p/native/xnu/trap_x86.c index b10414b3c2..98999b5f19 100644 --- a/libr/debug/p/native/xnu/trap_x86.c +++ b/librz/debug/p/native/xnu/trap_x86.c @@ -1,8 +1,8 @@ #if __i386__ || __x86_64__ -static bool xnu_thread_get_gpr(RDebug *dbg, xnu_thread_t *thread); -static xnu_thread_t* get_xnu_thread(RDebug *dbg, int tid); +static bool xnu_thread_get_gpr(RzDebug *dbg, xnu_thread_t *thread); +static xnu_thread_t* get_xnu_thread(RzDebug *dbg, int tid); -static bool xnu_x86_hwstep_enable64(RDebug *dbg, bool enable) { +static bool xnu_x86_hwstep_enable64(RzDebug *dbg, bool enable) { R_REG_T *state; int ret; xnu_thread_t *th = get_xnu_thread (dbg, dbg->tid); @@ -29,7 +29,7 @@ static bool xnu_x86_hwstep_enable64(RDebug *dbg, bool enable) { return true; } -static bool xnu_x86_hwstep_enable32(RDebug *dbg, bool enable) { +static bool xnu_x86_hwstep_enable32(RzDebug *dbg, bool enable) { R_REG_T *state; xnu_thread_t *th = get_xnu_thread (dbg, dbg->tid); int ret = xnu_thread_get_gpr (dbg, th); @@ -52,7 +52,7 @@ static bool xnu_x86_hwstep_enable32(RDebug *dbg, bool enable) { return true; } -bool xnu_native_hwstep_enable(RDebug *dbg, bool enable) { +bool xnu_native_hwstep_enable(RzDebug *dbg, bool enable) { if (dbg->bits == R_SYS_BITS_64) return xnu_x86_hwstep_enable64 (dbg, enable); return xnu_x86_hwstep_enable32 (dbg, enable); diff --git a/libr/debug/p/native/xnu/xnu_debug.c b/librz/debug/p/native/xnu/xnu_debug.c similarity index 86% rename from libr/debug/p/native/xnu/xnu_debug.c rename to librz/debug/p/native/xnu/xnu_debug.c index 18a3124c2b..2a2dd0702d 100644 --- a/libr/debug/p/native/xnu/xnu_debug.c +++ b/librz/debug/p/native/xnu/xnu_debug.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2015-2019 - pancake, alvaro_fe */ +/* rizin - LGPL - Copyright 2015-2019 - pancake, alvaro_fe */ -#include +#include #if DEBUGGER #if XNU_USE_PTRACE @@ -10,11 +10,11 @@ #endif // ------------------------------------ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -65,7 +65,7 @@ typedef struct { } DyldImageInfo64; /* XXX: right now it just returns the first thread, not the one selected in dbg->tid */ -static thread_t getcurthread (RDebug *dbg) { +static thread_t getcurthread (RzDebug *dbg) { thread_t th; thread_array_t threads = NULL; unsigned int n_threads = 0; @@ -85,7 +85,7 @@ static thread_t getcurthread (RDebug *dbg) { return th; } -static xnu_thread_t* get_xnu_thread(RDebug *dbg, int tid) { +static xnu_thread_t* get_xnu_thread(RzDebug *dbg, int tid) { if (!dbg || tid < 0) { return NULL; } @@ -94,12 +94,12 @@ static xnu_thread_t* get_xnu_thread(RDebug *dbg, int tid) { return NULL; } //TODO get the current thread - RListIter *it = r_list_find (dbg->threads, (const void *)(size_t)&tid, - (RListComparator)&thread_find); + RzListIter *it = rz_list_find (dbg->threads, (const void *)(size_t)&tid, + (RzListComparator)&thread_find); if (!it) { tid = getcurthread (dbg); - it = r_list_find (dbg->threads, (const void *)(size_t)&tid, - (RListComparator)&thread_find); + it = rz_list_find (dbg->threads, (const void *)(size_t)&tid, + (RzListComparator)&thread_find); if (!it) { eprintf ("Thread not found get_xnu_thread\n"); return NULL; @@ -159,7 +159,7 @@ static task_t task_for_pid_ios9pangu(int pid) { return task; } -int xnu_wait(RDebug *dbg, int pid) { +int xnu_wait(RzDebug *dbg, int pid) { #if XNU_USE_PTRACE return R_DEBUG_REASON_UNKNOWN; #else @@ -167,9 +167,9 @@ int xnu_wait(RDebug *dbg, int pid) { #endif } -bool xnu_step(RDebug *dbg) { +bool xnu_step(RzDebug *dbg) { #if XNU_USE_PTRACE - int ret = r_debug_ptrace (dbg, PT_STEP, dbg->pid, (caddr_t)1, 0) == 0; //SIGINT + int ret = rz_debug_ptrace (dbg, PT_STEP, dbg->pid, (caddr_t)1, 0) == 0; //SIGINT if (!ret) { perror ("ptrace-step"); eprintf ("mach-error: %d, %s\n", ret, MACH_ERROR_STRING (ret)); @@ -197,12 +197,12 @@ bool xnu_step(RDebug *dbg) { #endif } -int xnu_attach(RDebug *dbg, int pid) { +int xnu_attach(RzDebug *dbg, int pid) { #if XNU_USE_PTRACE #if PT_ATTACHEXC - if (r_debug_ptrace (dbg, PT_ATTACHEXC, pid, 0, 0) == -1) { + if (rz_debug_ptrace (dbg, PT_ATTACHEXC, pid, 0, 0) == -1) { #else - if (r_debug_ptrace (dbg, PT_ATTACH, pid, 0, 0) == -1) { + if (rz_debug_ptrace (dbg, PT_ATTACH, pid, 0, 0) == -1) { #endif perror ("ptrace (PT_ATTACH)"); return -1; @@ -219,9 +219,9 @@ int xnu_attach(RDebug *dbg, int pid) { #endif } -int xnu_detach(RDebug *dbg, int pid) { +int xnu_detach(RzDebug *dbg, int pid) { #if XNU_USE_PTRACE - return r_debug_ptrace (dbg, PT_DETACH, pid, NULL, 0); + return rz_debug_ptrace (dbg, PT_DETACH, pid, NULL, 0); #else kern_return_t kr; //do the cleanup necessary @@ -234,7 +234,7 @@ int xnu_detach(RDebug *dbg, int pid) { } //we mark the task as not longer available since we deallocated the ref task_dbg = 0; - r_list_free (dbg->threads); + rz_list_free (dbg->threads); dbg->threads = NULL; return true; #endif @@ -252,7 +252,7 @@ static int task_suspend_count(task_t task) { return info.suspend_count; } -int xnu_stop(RDebug *dbg, int pid) { +int xnu_stop(RzDebug *dbg, int pid) { #if XNU_USE_PTRACE eprintf ("xnu_stop: not implemented\n"); return false; @@ -290,11 +290,11 @@ int xnu_stop(RDebug *dbg, int pid) { #endif } -int xnu_continue(RDebug *dbg, int pid, int tid, int sig) { +int xnu_continue(RzDebug *dbg, int pid, int tid, int sig) { #if XNU_USE_PTRACE void *data = (void*)(size_t)((sig != -1) ? sig : dbg->reason.signum); task_resume (pid_to_task (pid)); - return r_debug_ptrace (dbg, PT_CONTINUE, pid, (void*)(size_t)1, + return rz_debug_ptrace (dbg, PT_CONTINUE, pid, (void*)(size_t)1, (int)(size_t)data) == 0; #else task_t task = pid_to_task (pid); @@ -322,7 +322,7 @@ int xnu_continue(RDebug *dbg, int pid, int tid, int sig) { #endif } -char *xnu_reg_profile(RDebug *dbg) { +char *xnu_reg_profile(RzDebug *dbg) { #if __i386__ || __x86_64__ if (dbg->bits & R_SYS_BITS_32) { # include "reg/darwin-x86.h" @@ -345,11 +345,11 @@ char *xnu_reg_profile(RDebug *dbg) { #endif } -//r_debug_select +//rz_debug_select //using getcurthread has some drawbacks. You lose the ability to select //the thread you want to write or read from. but how that feature //is not implemented yet i don't care so much -int xnu_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { +int xnu_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size) { bool ret; xnu_thread_t *th = get_xnu_thread (dbg, getcurthread (dbg)); if (!th) { @@ -385,7 +385,7 @@ int xnu_reg_write(RDebug *dbg, int type, const ut8 *buf, int size) { return ret; } -int xnu_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { +int xnu_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { xnu_thread_t *th = get_xnu_thread (dbg, getcurthread (dbg)); if (!th) { return 0; @@ -416,7 +416,7 @@ int xnu_reg_read(RDebug *dbg, int type, ut8 *buf, int size) { return 0; } -RDebugMap *xnu_map_alloc(RDebug *dbg, ut64 addr, int size) { +RzDebugMap *xnu_map_alloc(RzDebug *dbg, ut64 addr, int size) { kern_return_t ret; ut8 *base = (ut8 *)addr; xnu_thread_t *th = get_xnu_thread (dbg, dbg->tid); @@ -434,11 +434,11 @@ RDebugMap *xnu_map_alloc(RDebug *dbg, ut64 addr, int size) { eprintf ("vm_allocate failed\n"); return NULL; } - r_debug_map_sync (dbg); // update process memory maps - return r_debug_map_get (dbg, (ut64)base); + rz_debug_map_sync (dbg); // update process memory maps + return rz_debug_map_get (dbg, (ut64)base); } -int xnu_map_dealloc (RDebug *dbg, ut64 addr, int size) { +int xnu_map_dealloc (RzDebug *dbg, ut64 addr, int size) { xnu_thread_t *th = get_xnu_thread (dbg, dbg->tid); if (!th) { return false; @@ -467,10 +467,10 @@ static int xnu_get_kinfo_proc (int pid, struct kinfo_proc *kp) { return 0; } -RDebugInfo *xnu_info (RDebug *dbg, const char *arg) { +RzDebugInfo *xnu_info (RzDebug *dbg, const char *arg) { struct kinfo_proc kp; // XXX This need to be freed? int kinfo_proc_error = 0; - RDebugInfo *rdi = R_NEW0 (RDebugInfo); + RzDebugInfo *rdi = R_NEW0 (RzDebugInfo); if (!rdi) return NULL; kinfo_proc_error = xnu_get_kinfo_proc(dbg->pid, &kp); @@ -508,7 +508,7 @@ RDebugInfo *xnu_info (RDebug *dbg, const char *arg) { } /* -static void xnu_free_threads_ports (RDebugPid *p) { +static void xnu_free_threads_ports (RzDebugPid *p) { kern_return_t kr; if (!p) return; free (p->path); @@ -522,7 +522,7 @@ static void xnu_free_threads_ports (RDebugPid *p) { } */ -RList *xnu_thread_list (RDebug *dbg, int pid, RList *list) { +RzList *xnu_thread_list (RzDebug *dbg, int pid, RzList *list) { #if __arm__ || __arm64__ || __aarch_64__ #define CPU_PC (dbg->bits == R_SYS_BITS_64) ? \ state.ts_64.__pc : state.ts_32.__pc @@ -532,19 +532,19 @@ RList *xnu_thread_list (RDebug *dbg, int pid, RList *list) { #define CPU_PC (dbg->bits == R_SYS_BITS_64) ? \ state.uts.ts64.__rip : state.uts.ts32.__eip #endif - RListIter *iter; + RzListIter *iter; xnu_thread_t *thread; R_REG_T state; xnu_update_thread_list (dbg); - list->free = (RListFree)&r_debug_pid_free; - r_list_foreach (dbg->threads, iter, thread) { + list->free = (RzListFree)&rz_debug_pid_free; + rz_list_foreach (dbg->threads, iter, thread) { if (!xnu_thread_get_gpr (dbg, thread)) { eprintf ("Failed to get gpr registers xnu_thread_list\n"); continue; } thread->state_size = sizeof (thread->gpr); memcpy (&state, &thread->gpr, sizeof (R_REG_T)); - r_list_append (list, r_debug_pid_new (thread->name, + rz_list_append (list, rz_debug_pid_new (thread->name, thread->port, getuid (), 's', CPU_PC)); } return list; @@ -558,11 +558,11 @@ static vm_prot_t unix_prot_to_darwin(int prot) { } #endif -int xnu_map_protect (RDebug *dbg, ut64 addr, int size, int perms) { +int xnu_map_protect (RzDebug *dbg, ut64 addr, int size, int perms) { int ret; task_t task = pid_to_task (dbg->tid); -#define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) - int xnu_perms = xwr2rwx (perms); +#define xwrz_testwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) + int xnu_perms = xwrz_testwx (perms); ret = mach_vm_protect (task, (vm_address_t)addr, (vm_size_t)size, (boolean_t)0, xnu_perms); //VM_PROT_COPY | perms); if (ret != KERN_SUCCESS) { perror ("vm_protect"); @@ -605,7 +605,7 @@ task_t pid_to_task (int pid) { } eprintf ("You probably need to run as root or sign " "the binary.\n Read doc/ios.md || doc/macos.md\n" - " make -C binr/radare2 ios-sign || macos-sign\n"); + " make -C binrz/rizin ios-sign || macos-sign\n"); return 0; } } @@ -648,7 +648,7 @@ int xnu_get_vmmap_entries_for_pid (pid_t pid) { return n; } -#define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) +#define xwrz_testwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2) #define COMMAND_SIZE(segment_count,segment_command_sz,\ thread_count,tstate_size)\ segment_count * segment_command_sz + thread_count * \ @@ -721,8 +721,8 @@ static void xnu_build_corefile_header (vm_offset_t header, #endif } -static int xnu_dealloc_threads (RList *threads) { - RListIter *iter, *iter2; +static int xnu_dealloc_threads (RzList *threads) { + RzListIter *iter, *iter2; xnu_thread_t *thread; mach_msg_type_number_t thread_count; thread_array_t thread_list; @@ -732,7 +732,7 @@ static int xnu_dealloc_threads (RList *threads) { if (kr != KERN_SUCCESS) { perror ("task_threads"); } else { - r_list_foreach_safe (threads, iter, iter2, thread) { + rz_list_foreach_safe (threads, iter, iter2, thread) { mach_port_deallocate (mach_task_self (), thread->port); } vm_deallocate (mach_task_self (), (vm_address_t)thread_list, @@ -746,10 +746,10 @@ static int xnu_dealloc_threads (RList *threads) { /* XXX which follow the header. */ /* XXX Maybe this function needs refactoring, but I haven't come up with */ /* XXX a better way to do it yet. */ -static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RList *mem_maps, int start_offset, +static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RzList *mem_maps, int start_offset, vm_offset_t header, int header_end, int segment_command_sz, int *hoffset_out) { - RListIter *iter, *iter2; - RDebugMap *curr_map; + RzListIter *iter, *iter2; + RzDebugMap *curr_map; int foffset = 0; //start_offset; int hoffset = header_end; kern_return_t kr = KERN_SUCCESS; @@ -762,7 +762,7 @@ static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RList *mem_maps, int s #elif __i386__ || __ppc__ || __POWERPC__ struct segment_command *sc; #endif - r_list_foreach_safe (mem_maps, iter, iter2, curr_map) { + rz_list_foreach_safe (mem_maps, iter, iter2, curr_map) { eprintf ("Writing section from 0x%"PFMT64x" to 0x%"PFMT64x" (%"PFMT64d")\n", curr_map->addr, curr_map->addr_end, curr_map->size); @@ -774,8 +774,8 @@ static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RList *mem_maps, int s sc64->segname[0] = 0; // XXX curr_map->name OR curr_map->file ??? sc64->vmaddr = curr_map->addr; sc64->vmsize = curr_map->size; - sc64->maxprot = xwr2rwx (curr_map->user); - sc64->initprot = xwr2rwx (curr_map->perm); + sc64->maxprot = xwrz_testwx (curr_map->user); + sc64->initprot = xwrz_testwx (curr_map->perm); sc64->nsects = 0; #elif __i386__ || __ppc__ sc = (struct segment_command*)(header + hoffset); @@ -786,8 +786,8 @@ static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RList *mem_maps, int s sc->vmsize = CAST_DOWN (vm_size_t, curr_map->size); sc->fileoff = CAST_DOWN (ut32, foffset); sc->filesize = CAST_DOWN (ut32, curr_map->size); - sc->maxprot = xwr2rwx (curr_map->user); - sc->initprot = xwr2rwx (curr_map->perm); + sc->maxprot = xwrz_testwx (curr_map->user); + sc->initprot = xwrz_testwx (curr_map->perm); sc->nsects = 0; #endif if ((curr_map->perm & VM_PROT_READ) == 0) { @@ -823,10 +823,10 @@ static int xnu_write_mem_maps_to_buffer (RBuffer *buffer, RList *mem_maps, int s goto cleanup; } #if __ppc64__ || __x86_64__ || __aarch64__ || __arm64__ - rc = r_buf_append_bytes (buffer, (const ut8*)local_address, xfer_size); + rc = rz_buf_append_bytes (buffer, (const ut8*)local_address, xfer_size); // #elif __i386__ || __ppc__ || __arm__ #else - rc = r_buf_append_bytes (buffer, (void *)CAST_DOWN (ut32, local_address), + rc = rz_buf_append_bytes (buffer, (void *)CAST_DOWN (ut32, local_address), CAST_DOWN (ut32, xfer_size)); #endif if (!rc) { @@ -905,7 +905,7 @@ static uid_t uidFromPid(pid_t pid) { return uid; } -bool xnu_generate_corefile (RDebug *dbg, RBuffer *dest) { +bool xnu_generate_corefile (RzDebug *dbg, RBuffer *dest) { int error = 0, i; int tstate_size; int segment_count; @@ -919,18 +919,18 @@ bool xnu_generate_corefile (RDebug *dbg, RBuffer *dest) { RBuffer *mem_maps_buffer; vm_offset_t header; ut8 *padding = NULL; - RListIter *iter, *iter2; - RList *threads_list; + RzListIter *iter, *iter2; + RzList *threads_list; xnu_thread_t *thread; task_t task = pid_to_task (dbg->pid); coredump_thread_state_flavor_t flavors[MAX_TSTATE_FLAVORS]; tir_t tir; - mem_maps_buffer = r_buf_new (); + mem_maps_buffer = rz_buf_new (); get_mach_header_sizes (&mach_header_sz, &segment_command_sz); (void)task_suspend(task); - threads_list = xnu_thread_list (dbg, dbg->pid, r_list_new ()); + threads_list = xnu_thread_list (dbg, dbg->pid, rz_list_new ()); xnu_dealloc_threads (threads_list); segment_count = xnu_get_vmmap_entries_for_pid (dbg->pid); @@ -944,11 +944,11 @@ bool xnu_generate_corefile (RDebug *dbg, RBuffer *dest) { } command_size = COMMAND_SIZE (segment_count,segment_command_sz, - r_list_length (threads_list), tstate_size); + rz_list_length (threads_list), tstate_size); header_size = command_size + mach_header_sz; // XXX: Add here the round_page() ? header = (vm_offset_t)calloc (1, header_size); xnu_build_corefile_header (header, segment_count, - r_list_length (threads_list), command_size, dbg->pid); + rz_list_length (threads_list), command_size, dbg->pid); if (!dbg->maps) { perror ("There are not loaded maps"); @@ -965,27 +965,27 @@ bool xnu_generate_corefile (RDebug *dbg, RBuffer *dest) { tir.flavors = flavors; tir.tstate_size = tstate_size; - r_list_foreach_safe (threads_list, iter, iter2, thread) { + rz_list_foreach_safe (threads_list, iter, iter2, thread) { xnu_collect_thread_state (thread->port, &tir); } xnu_dealloc_threads (threads_list); - r_buf_append_bytes (dest, (const ut8*)header, header_size); + rz_buf_append_bytes (dest, (const ut8*)header, header_size); padding_sz = round_page (header_size) - header_size; padding = (ut8*)calloc (1, padding_sz); - r_buf_append_bytes (dest, (const ut8*)padding, padding_sz); - r_buf_append_buf (dest, mem_maps_buffer); + rz_buf_append_bytes (dest, (const ut8*)padding, padding_sz); + rz_buf_append_buf (dest, mem_maps_buffer); cleanup: //if (corefile_fd > 0) close (corefile_fd); - r_buf_free (mem_maps_buffer); + rz_buf_free (mem_maps_buffer); free ((void *)header); free ((void *)padding); - r_list_free (threads_list); + rz_list_free (threads_list); return !error; } -RDebugPid *xnu_get_pid (int pid) { +RzDebugPid *xnu_get_pid (int pid) { int psnamelen, foo, nargs, mib[3], uid; size_t size, argmax = 4096; char *curr_arg, *start_args, *iter_args, *end_args; @@ -1087,7 +1087,7 @@ RDebugPid *xnu_get_pid (int pid) { return NULL; } #endif - return r_debug_pid_new (psname, pid, uid, 's', 0); // XXX 's' ??, 0?? must set correct values + return rz_debug_pid_new (psname, pid, uid, 's', 0); // XXX 's' ??, 0?? must set correct values } kern_return_t mach_vm_region_recurse ( @@ -1164,11 +1164,11 @@ vm_address_t get_kernel_base(task_t ___task) { } // TODO: Implement mach0 size.. maybe copypasta from rbin? -static int mach0_size (RDebug *dbg, ut64 addr) { +static int mach0_size (RzDebug *dbg, ut64 addr) { return 4096; } -static void xnu_map_free(RDebugMap *map) { +static void xnu_map_free(RzDebugMap *map) { if (map) { free (map->name); free (map->file); @@ -1176,7 +1176,7 @@ static void xnu_map_free(RDebugMap *map) { } } -static RList *xnu_dbg_modules(RDebug *dbg) { +static RzList *xnu_dbg_modules(RzDebug *dbg) { #if __POWERPC__ #warning TODO: xnu_dbg_modules not supported return NULL; @@ -1192,15 +1192,15 @@ static RList *xnu_dbg_modules(RDebug *dbg) { count = TASK_DYLD_INFO_COUNT; task_t task = pid_to_task (dbg->tid); ut64 addr, file_path_address; - RDebugMap *mr = NULL; - RList *list = NULL; + RzDebugMap *mr = NULL; + RzList *list = NULL; if (!task) { return NULL; } kr = task_info (task, TASK_DYLD_INFO, (task_info_t) &info, &count); if (kr != KERN_SUCCESS) { - r_list_free (list); + rz_list_free (list); return NULL; } @@ -1233,7 +1233,7 @@ static RList *xnu_dbg_modules(RDebug *dbg) { dbg->iob.read_at (dbg->iob.io, info_array_address, info_array, info_array_size); - list = r_list_newf ((RListFree)xnu_map_free); + list = rz_list_newf ((RzListFree)xnu_map_free); if (!list) { free (info_array); return NULL; @@ -1255,24 +1255,24 @@ static RList *xnu_dbg_modules(RDebug *dbg) { (ut8*)file_path, MAXPATHLEN - 1); //eprintf ("--> %d 0x%08"PFMT64x" %s\n", i, addr, file_path); size = mach0_size (dbg, addr); - mr = r_debug_map_new (file_path, addr, addr + size, 7, 7); + mr = rz_debug_map_new (file_path, addr, addr + size, 7, 7); if (!mr) { - eprintf ("Cannot create r_debug_map_new\n"); + eprintf ("Cannot create rz_debug_map_new\n"); break; } mr->file = strdup (file_path); mr->shared = true; - r_list_append (list, mr); + rz_list_append (list, mr); } free (info_array); return list; #endif } -static RDebugMap *moduleAt(RList *list, ut64 addr) { - RListIter *iter; - RDebugMap *map; - r_list_foreach (list, iter, map) { +static RzDebugMap *moduleAt(RzList *list, ut64 addr) { + RzListIter *iter; + RzDebugMap *map; + rz_list_foreach (list, iter, map) { if (R_BETWEEN (map->addr, addr, map->addr_end)) { return map; } @@ -1281,8 +1281,8 @@ static RDebugMap *moduleAt(RList *list, ut64 addr) { } static int cmp (const void *_a, const void *_b) { - const RDebugMap *a = _a; - const RDebugMap *b = _b; + const RzDebugMap *a = _a; + const RzDebugMap *b = _b; if (a->addr > b->addr) { return 1; } @@ -1292,9 +1292,9 @@ static int cmp (const void *_a, const void *_b) { return 0; } -static RDebugMap *r_debug_map_clone (RDebugMap *m) { - RDebugMap *map = R_NEWCOPY (RDebugMap, m); - // memcpy (map, m, sizeof (RDebugMap)); +static RzDebugMap *rz_debug_map_clone (RzDebugMap *m) { + RzDebugMap *map = R_NEWCOPY (RzDebugMap, m); + // memcpy (map, m, sizeof (RzDebugMap)); if (m->name) { map->name = strdup (m->name); } @@ -1304,7 +1304,7 @@ static RDebugMap *r_debug_map_clone (RDebugMap *m) { return map; } -RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { +RzList *xnu_dbg_maps(RzDebug *dbg, int only_modules) { //bool contiguous = false; //ut32 oldprot = UT32_MAX; //ut32 oldmaxprot = UT32_MAX; @@ -1316,13 +1316,13 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { natural_t depth = 0; int tid = dbg->pid; task_t task = pid_to_task (tid); - RDebugMap *mr = NULL; + RzDebugMap *mr = NULL; int i = 0; if (!task) { return NULL; } - RList *modules = xnu_dbg_modules (dbg); + RzList *modules = xnu_dbg_modules (dbg); if (only_modules) { return modules; } @@ -1338,11 +1338,11 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { return NULL; } #endif - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { return NULL; } - list->free = (RListFree)xnu_map_free; + list->free = (RzListFree)xnu_map_free; for (;;) { struct vm_region_submap_info_64 info = {0}; mach_msg_type_number_t info_count = VM_REGION_SUBMAP_INFO_COUNT_64; @@ -1373,7 +1373,7 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { } if (info.max_protection != info.protection) { - strcpy (maxperm, r_str_rwx_i (xwr2rwx ( + strcpy (maxperm, rz_str_rwx_i (xwrz_testwx ( info.max_protection))); } else { maxperm[0] = 0; @@ -1385,11 +1385,11 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { info.is_submap? "_sub": "", "", info.is_submap ? "_submap": "", module_name, maxperm, depthstr); - if (!(mr = r_debug_map_new (buf, address, address + size, xwr2rwx (info.protection), xwr2rwx (info.max_protection)))) { - eprintf ("Cannot create r_debug_map_new\n"); + if (!(mr = rz_debug_map_new (buf, address, address + size, xwrz_testwx (info.protection), xwrz_testwx (info.max_protection)))) { + eprintf ("Cannot create rz_debug_map_new\n"); break; } - RDebugMap *rdm = moduleAt (modules, address); + RzDebugMap *rdm = moduleAt (modules, address); if (rdm) { mr->file = strdup (rdm->name); } else { @@ -1400,7 +1400,7 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { if (mr->file) { if (!strcmp (mr->file, mr->file)) { mr->name[0] = 0; - const char *slash = r_str_lchr (mr->file, '/'); + const char *slash = rz_str_lchr (mr->file, '/'); if (slash) { strcpy (mr->name, slash + 1); } @@ -1408,7 +1408,7 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { } i++; mr->shared = false; - r_list_append (list, mr); + rz_list_append (list, mr); } if (size < 1) { eprintf ("size error\n"); @@ -1417,23 +1417,23 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) { address += size; size = 0; } - RListIter *iter; - RDebugMap *m; - r_list_foreach (modules, iter, m) { - RDebugMap *m2 = r_debug_map_clone (m); + RzListIter *iter; + RzDebugMap *m; + rz_list_foreach (modules, iter, m) { + RzDebugMap *m2 = rz_debug_map_clone (m); if (m2->name && m2->file) { if (!strcmp (m2->name, m2->file)) { m2->name[0] = 0; - const char *slash = r_str_lchr (m2->file, '/'); + const char *slash = rz_str_lchr (m2->file, '/'); if (slash) { strcpy (m2->name, slash + 1); } } } - r_list_append (list, m2); + rz_list_append (list, m2); } - r_list_sort (list, cmp); - r_list_free (modules); + rz_list_sort (list, cmp); + rz_list_free (modules); return list; } diff --git a/libr/debug/p/native/xnu/xnu_debug.h b/librz/debug/p/native/xnu/xnu_debug.h similarity index 88% rename from libr/debug/p/native/xnu/xnu_debug.h rename to librz/debug/p/native/xnu/xnu_debug.h index f8731110d5..f80fef90a1 100644 --- a/libr/debug/p/native/xnu/xnu_debug.h +++ b/librz/debug/p/native/xnu/xnu_debug.h @@ -9,7 +9,7 @@ #define _XNU_DEBUG_H #define MACH_ERROR_STRING(ret) \ - (mach_error_string (ret) ? r_str_get (mach_error_string (ret)) : "(unknown)") + (mach_error_string (ret) ? rz_str_get (mach_error_string (ret)) : "(unknown)") #if TARGET_OS_IPHONE // no ptrace @@ -263,23 +263,23 @@ typedef struct { task_t pid_to_task (int pid); int xnu_get_vmmap_entries_for_pid (pid_t pid); char *xnu_corefile_default_location(void); -bool xnu_generate_corefile(RDebug *dbg, RBuffer *dest); -int xnu_reg_read (RDebug *dbg, int type, ut8 *buf, int size); -int xnu_reg_write (RDebug *dgb, int type, const ut8 *buf, int size); -char *xnu_reg_profile (RDebug *dbg); -int xnu_attach (RDebug *dbg, int pid); -bool xnu_step (RDebug *dbg); -int xnu_detach (RDebug *dbg, int pid); -int xnu_stop (RDebug *dbg, int pid); -int xnu_continue (RDebug *dbg, int pid, int tid, int sig); -RDebugMap *xnu_map_alloc (RDebug *dbg, ut64 addr, int size); -int xnu_map_dealloc (RDebug *dbg, ut64 addr, int size); -int xnu_map_protect (RDebug *dbg, ut64 addr, int size, int perms); +bool xnu_generate_corefile(RzDebug *dbg, RBuffer *dest); +int xnu_reg_read (RzDebug *dbg, int type, ut8 *buf, int size); +int xnu_reg_write (RzDebug *dgb, int type, const ut8 *buf, int size); +char *xnu_reg_profile (RzDebug *dbg); +int xnu_attach (RzDebug *dbg, int pid); +bool xnu_step (RzDebug *dbg); +int xnu_detach (RzDebug *dbg, int pid); +int xnu_stop (RzDebug *dbg, int pid); +int xnu_continue (RzDebug *dbg, int pid, int tid, int sig); +RzDebugMap *xnu_map_alloc (RzDebug *dbg, ut64 addr, int size); +int xnu_map_dealloc (RzDebug *dbg, ut64 addr, int size); +int xnu_map_protect (RzDebug *dbg, ut64 addr, int size, int perms); int xnu_init (void); -int xnu_wait (RDebug *dbg, int pid); -RDebugPid *xnu_get_pid (int pid); -RList *xnu_dbg_maps (RDebug *dbg, int only_modules); -RList *xnu_thread_list (RDebug *dbg, int pid, RList *list); -RDebugInfo *xnu_info (RDebug *dbg, const char *arg); +int xnu_wait (RzDebug *dbg, int pid); +RzDebugPid *xnu_get_pid (int pid); +RzList *xnu_dbg_maps (RzDebug *dbg, int only_modules); +RzList *xnu_thread_list (RzDebug *dbg, int pid, RzList *list); +RzDebugInfo *xnu_info (RzDebug *dbg, const char *arg); #endif diff --git a/libr/debug/p/native/xnu/xnu_excthreads.c b/librz/debug/p/native/xnu/xnu_excthreads.c similarity index 94% rename from libr/debug/p/native/xnu/xnu_excthreads.c rename to librz/debug/p/native/xnu/xnu_excthreads.c index 1226924166..62f34a9927 100644 --- a/libr/debug/p/native/xnu/xnu_excthreads.c +++ b/librz/debug/p/native/xnu/xnu_excthreads.c @@ -13,7 +13,7 @@ ENABLE is a boolean, indicating whether to set (1) the Trap Flag or clear it (0). */ -static bool modify_trace_bit(RDebug *dbg, xnu_thread_t *th, int enable) { +static bool modify_trace_bit(RzDebug *dbg, xnu_thread_t *th, int enable) { R_REG_T *state; int ret; ret = xnu_thread_get_gpr (dbg, th); @@ -42,11 +42,11 @@ static bool modify_trace_bit(RDebug *dbg, xnu_thread_t *th, int enable) { #elif __POWERPC__ //ppc processor //XXX poor support at this stage i don't care so much. Once intel and arm done it could be done //TODO add better support for ppc -static bool modify_trace_bit(RDebug *dbg, void *th, int enable) { +static bool modify_trace_bit(RzDebug *dbg, void *th, int enable) { return false; } #if 0 -static bool modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) { +static bool modify_trace_bit(RzDebug *dbg, xnu_thread *th, int enable) { return false; R_REG_T state; unsigned int state_count = R_REG_STATE_SZ; @@ -111,7 +111,7 @@ static bool is_thumb_32(ut16 op) { } #endif -static int modify_trace_bit(RDebug *dbg, xnu_thread_t *th, int enable) { +static int modify_trace_bit(RzDebug *dbg, xnu_thread_t *th, int enable) { int i = 0; int ret = xnu_thread_get_drx (dbg, th); if (!ret) { @@ -146,7 +146,7 @@ static int modify_trace_bit(RDebug *dbg, xnu_thread_t *th, int enable) { regs = (R_REG_T*)&th->gpr; if (enable) { static ut64 chained_address = 0; - RIOBind *bio = &dbg->iob; + RzIOBind *bio = &dbg->iob; //set a breakpoint that will stop when the PC doesn't //match the current one //set the current PC as the breakpoint address @@ -210,14 +210,14 @@ static int modify_trace_bit(RDebug *dbg, xnu_thread_t *th, int enable) { #elif __POWERPC__ // no need to do this here -static int modify_trace_bit(RDebug *dbg, xnu_thread *th, int enable) { +static int modify_trace_bit(RzDebug *dbg, xnu_thread *th, int enable) { return true; } #else #error "unknown architecture" #endif -// TODO: Tuck this into RDebug; `void *user` seems like a good candidate. +// TODO: Tuck this into RzDebug; `void *user` seems like a good candidate. static xnu_exception_info ex = { { 0 } }; static bool xnu_restore_exception_ports (int pid) { @@ -255,7 +255,7 @@ static void encode_reply(mig_reply_error_t *reply, mach_msg_header_t *hdr, int c reply->RetCode = code; } -static bool validate_mach_message (RDebug *dbg, exc_msg *msg) { +static bool validate_mach_message (RzDebug *dbg, exc_msg *msg) { kern_return_t kr; #if __POWERPC__ return false; @@ -309,7 +309,7 @@ static bool validate_mach_message (RDebug *dbg, exc_msg *msg) { #endif } -static bool handle_dead_notify (RDebug *dbg, exc_msg *msg) { +static bool handle_dead_notify (RzDebug *dbg, exc_msg *msg) { if (msg->hdr.msgh_id == 0x48) { dbg->pid = -1; return true; @@ -317,7 +317,7 @@ static bool handle_dead_notify (RDebug *dbg, exc_msg *msg) { return false; } -static int handle_exception_message (RDebug *dbg, exc_msg *msg, int *ret_code) { +static int handle_exception_message (RzDebug *dbg, exc_msg *msg, int *ret_code) { int ret = R_DEBUG_REASON_UNKNOWN; kern_return_t kr; *ret_code = KERN_SUCCESS; @@ -372,7 +372,7 @@ static int handle_exception_message (RDebug *dbg, exc_msg *msg, int *ret_code) { } //TODO improve this code -static int __xnu_wait (RDebug *dbg, int pid) { +static int __xnu_wait (RzDebug *dbg, int pid) { // here comes the important thing kern_return_t kr; int ret_code, reason = R_DEBUG_REASON_UNKNOWN; @@ -433,11 +433,11 @@ static int __xnu_wait (RDebug *dbg, int pid) { } break; // to avoid infinite loops } - dbg->stopaddr = r_debug_reg_get (dbg, "PC"); + dbg->stopaddr = rz_debug_reg_get (dbg, "PC"); return reason; } -bool xnu_create_exception_thread(RDebug *dbg) { +bool xnu_create_exception_thread(RzDebug *dbg) { #if __POWERPC__ return false; #else @@ -452,7 +452,7 @@ bool xnu_create_exception_thread(RDebug *dbg) { " xnu_start_exception_thread\n"); return false; } - r_debug_ptrace (dbg, PT_ATTACHEXC, dbg->pid, 0, 0); + rz_debug_ptrace (dbg, PT_ATTACHEXC, dbg->pid, 0, 0); if (!MACH_PORT_VALID (task_self)) { eprintf ("error to get the task for the current process" " xnu_start_exception_thread\n"); diff --git a/libr/debug/p/native/xnu/xnu_threads.c b/librz/debug/p/native/xnu/xnu_threads.c similarity index 89% rename from libr/debug/p/native/xnu/xnu_threads.c rename to librz/debug/p/native/xnu/xnu_threads.c index c506dc3d88..a138eecf4d 100644 --- a/libr/debug/p/native/xnu/xnu_threads.c +++ b/librz/debug/p/native/xnu/xnu_threads.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include #if DEBUGGER // TODO much work remains to be done @@ -23,8 +23,8 @@ static void xnu_thread_free (xnu_thread_t *thread) { } // XXX this should work as long as in arm trace bit relies on this -static bool xnu_thread_get_drx (RDebug *dbg, xnu_thread_t *thread) { - r_return_val_if_fail (dbg && thread, false); +static bool xnu_thread_get_drx (RzDebug *dbg, xnu_thread_t *thread) { + rz_return_val_if_fail (dbg && thread, false); kern_return_t rc; #if __x86_64__ || __i386__ thread->flavor = x86_DEBUG_STATE; @@ -67,8 +67,8 @@ static bool xnu_thread_get_drx (RDebug *dbg, xnu_thread_t *thread) { return true; } -static bool xnu_thread_set_drx (RDebug *dbg, xnu_thread_t *thread) { - r_return_val_if_fail (dbg && thread, false); +static bool xnu_thread_set_drx (RzDebug *dbg, xnu_thread_t *thread) { + rz_return_val_if_fail (dbg && thread, false); kern_return_t rc; #if __i386__ || __x86_64__ x86_debug_state_t *regs = &thread->drx; @@ -127,8 +127,8 @@ static bool xnu_thread_set_drx (RDebug *dbg, xnu_thread_t *thread) { return true; } -static bool xnu_thread_set_gpr (RDebug *dbg, xnu_thread_t *thread) { - r_return_val_if_fail (dbg && thread, false); +static bool xnu_thread_set_gpr (RzDebug *dbg, xnu_thread_t *thread) { + rz_return_val_if_fail (dbg && thread, false); kern_return_t rc; R_REG_T *regs = (R_REG_T *)&thread->gpr; if (!regs) { @@ -181,8 +181,8 @@ static bool xnu_thread_set_gpr (RDebug *dbg, xnu_thread_t *thread) { return true; } -static bool xnu_thread_get_gpr (RDebug *dbg, xnu_thread_t *thread) { - r_return_val_if_fail (dbg && thread, false); +static bool xnu_thread_get_gpr (RzDebug *dbg, xnu_thread_t *thread) { + rz_return_val_if_fail (dbg && thread, false); R_REG_T *regs = &thread->gpr; if (!regs) { return false; @@ -225,7 +225,7 @@ static bool xnu_thread_get_gpr (RDebug *dbg, xnu_thread_t *thread) { return true; } -static bool xnu_fill_info_thread (RDebug *dbg, xnu_thread_t *thread) { +static bool xnu_fill_info_thread (RzDebug *dbg, xnu_thread_t *thread) { #if __POWERPC__ thread->name = strdup ("unknown"); return false; @@ -264,7 +264,7 @@ static bool xnu_fill_info_thread (RDebug *dbg, xnu_thread_t *thread) { return true; } -static xnu_thread_t *xnu_get_thread_with_info (RDebug *dbg, thread_t port) { +static xnu_thread_t *xnu_get_thread_with_info (RzDebug *dbg, thread_t port) { xnu_thread_t *thread = R_NEW0 (xnu_thread_t); if (!thread) { return NULL; @@ -277,7 +277,7 @@ static xnu_thread_t *xnu_get_thread_with_info (RDebug *dbg, thread_t port) { return thread; } -static int xnu_update_thread_info (RDebug *dbg, xnu_thread_t *thread) { +static int xnu_update_thread_info (RzDebug *dbg, xnu_thread_t *thread) { if (!xnu_fill_info_thread (dbg, thread)) { free (thread->name); thread->name = strdup ("unknown"); @@ -289,7 +289,7 @@ static int thread_find (thread_t *port, xnu_thread_t *a) { return (a && port && (a->port == *port))? 0: 1; } -static int xnu_update_thread_list (RDebug *dbg) { +static int xnu_update_thread_list (RzDebug *dbg) { thread_array_t thread_list = NULL; unsigned int thread_count = 0; xnu_thread_t *thread; @@ -298,7 +298,7 @@ static int xnu_update_thread_list (RDebug *dbg) { int i; if (!dbg->threads) { - dbg->threads = r_list_newf ((RListFree)&xnu_thread_free); + dbg->threads = rz_list_newf ((RzListFree)&xnu_thread_free); if (!dbg->threads) { return false; } @@ -316,7 +316,7 @@ static int xnu_update_thread_list (RDebug *dbg) { eprintf ("Failed to get list of task's threads\n"); return false; } - if (r_list_empty (dbg->threads)) { + if (rz_list_empty (dbg->threads)) { // it's the first time write all threads inside the list for (i = 0; i < thread_count; i++) { thread = xnu_get_thread_with_info (dbg, thread_list[i]); @@ -324,16 +324,16 @@ static int xnu_update_thread_list (RDebug *dbg) { eprintf ("Failed to fill_thread\n"); continue; } - if (!r_list_append (dbg->threads, thread)) { + if (!rz_list_append (dbg->threads, thread)) { eprintf ("Failed to add thread to list\n"); xnu_thread_free (thread); } } } else { - RListIter *iter, *iter2; + RzListIter *iter, *iter2; // first pass to get rid of those threads that are not longer // alive - r_list_foreach_safe (dbg->threads, iter, iter2, thread) { + rz_list_foreach_safe (dbg->threads, iter, iter2, thread) { bool flag = true; // this flag will denote when delete // a thread for (i = 0; i < thread_count; i++) { @@ -345,7 +345,7 @@ static int xnu_update_thread_list (RDebug *dbg) { if (flag) { // it is not longer alive so remove from the // list - r_list_delete (dbg->threads, iter); + rz_list_delete (dbg->threads, iter); } else { // otherwise update the info xnu_update_thread_info (dbg, thread); @@ -354,8 +354,8 @@ static int xnu_update_thread_list (RDebug *dbg) { // ok now we have to insert those threads that we don't have for (i = 0; i < thread_count; i++) { xnu_thread_t *t; - iter = r_list_find (dbg->threads, &thread_list[i], - (RListComparator)&thread_find); + iter = rz_list_find (dbg->threads, &thread_list[i], + (RzListComparator)&thread_find); // it means is already in our list if (iter) { // free the ownership over the thread @@ -368,7 +368,7 @@ static int xnu_update_thread_list (RDebug *dbg) { } // otherwise insert it t = xnu_get_thread_with_info (dbg, thread_list[i]); - r_list_append (dbg->threads, t); + rz_list_append (dbg->threads, t); } } // once that is over we need to free the buffer diff --git a/libr/debug/p/native/xnu/xnu_threads.h b/librz/debug/p/native/xnu/xnu_threads.h similarity index 100% rename from libr/debug/p/native/xnu/xnu_threads.h rename to librz/debug/p/native/xnu/xnu_threads.h diff --git a/libr/debug/p/null.mk b/librz/debug/p/null.mk similarity index 100% rename from libr/debug/p/null.mk rename to librz/debug/p/null.mk diff --git a/libr/debug/p/qnx.mk b/librz/debug/p/qnx.mk similarity index 62% rename from libr/debug/p/qnx.mk rename to librz/debug/p/qnx.mk index 125bb392d6..590325cd9d 100644 --- a/libr/debug/p/qnx.mk +++ b/librz/debug/p/qnx.mk @@ -1,5 +1,5 @@ #include ../../config.mk -#BINDEPS=r_reg r_bp r_util r_io r_anal +#BINDEPS=rz_reg rz_bp rz_util rz_io rz_anal CFLAGS+=-I$(SHLR)/qnx/include/ LIB_PATH=$(SHRL)/qnx/ @@ -16,13 +16,13 @@ endif -include $(STOP)/qnx/deps.mk -LDFLAGS+=-L$(LTOP)/util -lr_util -LDFLAGS+=-L$(LTOP)/cons -lr_cons -LDFLAGS+=-L$(LTOP)/parse -lr_parse -LDFLAGS+=-L$(LTOP)/anal -lr_anal -LDFLAGS+=-L$(LTOP)/reg -lr_reg -LDFLAGS+=-L$(LTOP)/bp -lr_bp -LDFLAGS+=-L$(LTOP)/io -lr_io +LDFLAGS+=-L$(LTOP)/util -lrz_util +LDFLAGS+=-L$(LTOP)/cons -lrz_cons +LDFLAGS+=-L$(LTOP)/parse -lrz_parse +LDFLAGS+=-L$(LTOP)/anal -lrz_anal +LDFLAGS+=-L$(LTOP)/reg -lrz_reg +LDFLAGS+=-L$(LTOP)/bp -lrz_bp +LDFLAGS+=-L$(LTOP)/io -lrz_io OBJ_QNX=debug_qnx.o diff --git a/libr/debug/p/rap.mk b/librz/debug/p/rap.mk similarity index 100% rename from libr/debug/p/rap.mk rename to librz/debug/p/rap.mk diff --git a/libr/debug/p/winkd.mk b/librz/debug/p/winkd.mk similarity index 60% rename from libr/debug/p/winkd.mk rename to librz/debug/p/winkd.mk index 4740e179ae..a10aeee8bd 100644 --- a/libr/debug/p/winkd.mk +++ b/librz/debug/p/winkd.mk @@ -3,13 +3,13 @@ LIB_PATH=$(SHLR)/winkd/ -include ../../global.mk -include ../../../global.mk -LDFLAGS+=-L$(LTOP)/util -lr_util -LDFLAGS+=-L$(LTOP)/cons -lr_cons -LDFLAGS+=-L$(LTOP)/parse -lr_parse -LDFLAGS+=-L$(LTOP)/anal -lr_anal -LDFLAGS+=-L$(LTOP)/reg -lr_reg -LDFLAGS+=-L$(LTOP)/bp -lr_bp -LDFLAGS+=-L$(LTOP)/io -lr_io +LDFLAGS+=-L$(LTOP)/util -lrz_util +LDFLAGS+=-L$(LTOP)/cons -lrz_cons +LDFLAGS+=-L$(LTOP)/parse -lrz_parse +LDFLAGS+=-L$(LTOP)/anal -lrz_anal +LDFLAGS+=-L$(LTOP)/reg -lrz_reg +LDFLAGS+=-L$(LTOP)/bp -lrz_bp +LDFLAGS+=-L$(LTOP)/io -lrz_io include $(STOP)/winkd/deps.mk diff --git a/libr/debug/pid.c b/librz/debug/pid.c similarity index 58% rename from libr/debug/pid.c rename to librz/debug/pid.c index fff6582adc..feedb47213 100644 --- a/libr/debug/pid.c +++ b/librz/debug/pid.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include +#include -R_API RDebugPid *r_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc) { - RDebugPid *p = R_NEW0 (RDebugPid); +RZ_API RzDebugPid *rz_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc) { + RzDebugPid *p = R_NEW0 (RzDebugPid); if (!p) { return NULL; } @@ -16,13 +16,13 @@ R_API RDebugPid *r_debug_pid_new(const char *path, int pid, int uid, char status return p; } -R_API RDebugPid *r_debug_pid_free(RDebugPid *pid) { +RZ_API RzDebugPid *rz_debug_pid_free(RzDebugPid *pid) { free (pid->path); free (pid); return NULL; } -R_API RList *r_debug_pids(RDebug *dbg, int pid) { +RZ_API RzList *rz_debug_pids(RzDebug *dbg, int pid) { if (dbg && dbg->h && dbg->h->pids) { return dbg->h->pids (dbg, pid); } @@ -30,10 +30,10 @@ R_API RList *r_debug_pids(RDebug *dbg, int pid) { } // TODO: deprecate list/iterate functions from core apis? keep them for easiness? -R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) { - RList *list; - RListIter *iter; - RDebugPid *p; +RZ_API int rz_debug_pid_list(RzDebug *dbg, int pid, char fmt) { + RzList *list; + RzListIter *iter; + RzDebugPid *p; if (dbg && dbg->h && dbg->h->pids) { list = dbg->h->pids (dbg, R_MAX (0, pid)); if (!list) { @@ -41,7 +41,7 @@ R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) { } PJ *j = pj_new (); pj_a (j); - r_list_foreach (list, iter, p) { + rz_list_foreach (list, iter, p) { switch (fmt) { case 'j': pj_o (j); @@ -65,17 +65,17 @@ R_API int r_debug_pid_list(RDebug *dbg, int pid, char fmt) { dbg->cb_printf (pj_string (j)); } pj_free (j); - r_list_free (list); + rz_list_free (list); } return false; } -R_API int r_debug_thread_list(RDebug *dbg, int pid, char fmt) { - RList *list; - RListIter *iter; - RDebugPid *p; - RAnalFunction *fcn = NULL; - RDebugMap *map = NULL; +RZ_API int rz_debug_thread_list(RzDebug *dbg, int pid, char fmt) { + RzList *list; + RzListIter *iter; + RzDebugPid *p; + RzAnalFunction *fcn = NULL; + RzDebugMap *map = NULL; RStrBuf *path = NULL; if (pid == -1) { return false; @@ -87,19 +87,19 @@ R_API int r_debug_thread_list(RDebug *dbg, int pid, char fmt) { } PJ *j = pj_new (); pj_a (j); - r_list_foreach (list, iter, p) { - path = r_strbuf_new (""); + rz_list_foreach (list, iter, p) { + path = rz_strbuf_new (""); if (p->pc != 0) { - map = r_debug_map_get (dbg, p->pc); + map = rz_debug_map_get (dbg, p->pc); if (map && map->name && map->name[0]) { - r_strbuf_appendf (path, "%s ", map->name); + rz_strbuf_appendf (path, "%s ", map->name); } - r_strbuf_appendf (path, "(0x%" PFMT64x ")", p->pc); + rz_strbuf_appendf (path, "(0x%" PFMT64x ")", p->pc); - fcn = r_anal_get_fcn_in (dbg->anal, p->pc, 0); + fcn = rz_anal_get_fcn_in (dbg->anal, p->pc, 0); if (fcn) { - r_strbuf_appendf (path, " in %s+0x%" PFMT64x, fcn->name, (p->pc - fcn->addr)); + rz_strbuf_appendf (path, " in %s+0x%" PFMT64x, fcn->name, (p->pc - fcn->addr)); } } switch (fmt) { @@ -108,57 +108,57 @@ R_API int r_debug_thread_list(RDebug *dbg, int pid, char fmt) { pj_kb (j, "current", dbg->tid == p->pid); pj_ki (j, "pid", p->pid); pj_ks (j, "status", &p->status); - pj_ks (j, "path", r_strbuf_get (path)); + pj_ks (j, "path", rz_strbuf_get (path)); pj_end (j); break; default: dbg->cb_printf (" %c %d %c %s\n", dbg->tid == p->pid? '*': '-', - p->pid, p->status, r_strbuf_get (path)); + p->pid, p->status, rz_strbuf_get (path)); break; } - r_strbuf_free (path); + rz_strbuf_free (path); } pj_end (j); if (fmt == 'j') { dbg->cb_printf (pj_string (j)); } pj_free (j); - r_list_free (list); + rz_list_free (list); } return false; } /* processes */ -R_API int r_debug_pid_parent(RDebugPid *pid) { +RZ_API int rz_debug_pid_parent(RzDebugPid *pid) { // fork in child return 0; } #if 0 -R_API int r_debug_pid_del(struct r_debug_t *dbg) { +RZ_API int rz_debug_pid_del(struct rz_debug_t *dbg) { // kill da child return true; } /* threads */ -R_API int r_debug_pid_add_thread(struct r_debug_t *dbg) { +RZ_API int rz_debug_pid_add_thread(struct rz_debug_t *dbg) { // create a thread in process return true; } -R_API int r_debug_pid_del_thread(struct r_debug_t *dbg) { +RZ_API int rz_debug_pid_del_thread(struct rz_debug_t *dbg) { // kill a thread in process return true; } #endif /* status */ -R_API int r_debug_pid_set_state(struct r_debug_t *dbg, int status) { +RZ_API int rz_debug_pid_set_state(struct rz_debug_t *dbg, int status) { return true; } /* status */ -R_API struct r_debug_pid_t *r_debug_pid_get_status(struct r_debug_t *dbg, int pid) { +RZ_API struct rz_debug_pid_t *rz_debug_pid_get_status(struct rz_debug_t *dbg, int pid) { return NULL; } diff --git a/libr/debug/plugin.c b/librz/debug/plugin.c similarity index 59% rename from libr/debug/plugin.c rename to librz/debug/plugin.c index b824d833ee..b55a3da5c2 100644 --- a/libr/debug/plugin.c +++ b/librz/debug/plugin.c @@ -1,29 +1,29 @@ /* radare - LGPL - Copyright 2009-2017 pancake */ -#include +#include #include -static RDebugPlugin *debug_static_plugins[] = { +static RzDebugPlugin *debug_static_plugins[] = { R_DEBUG_STATIC_PLUGINS }; -R_API void r_debug_plugin_init(RDebug *dbg) { +RZ_API void rz_debug_plugin_init(RzDebug *dbg) { int i; - dbg->plugins = r_list_newf (free); + dbg->plugins = rz_list_newf (free); for (i = 0; debug_static_plugins[i]; i++) { - r_debug_plugin_add (dbg, debug_static_plugins[i]); + rz_debug_plugin_add (dbg, debug_static_plugins[i]); } } -R_API bool r_debug_use(RDebug *dbg, const char *str) { +RZ_API bool rz_debug_use(RzDebug *dbg, const char *str) { if (dbg && str) { - RDebugPlugin *h; - RListIter *iter; - r_list_foreach (dbg->plugins, iter, h) { + RzDebugPlugin *h; + RzListIter *iter; + rz_list_foreach (dbg->plugins, iter, h) { if (h->name && !strcmp (str, h->name)) { dbg->h = h; if (dbg->anal && dbg->anal->cur) { - r_debug_set_arch (dbg, dbg->anal->cur->arch, dbg->bits); + rz_debug_set_arch (dbg, dbg->anal->cur->arch, dbg->bits); } dbg->bp->breakpoint = dbg->h->breakpoint; dbg->bp->user = dbg; @@ -33,15 +33,15 @@ R_API bool r_debug_use(RDebug *dbg, const char *str) { if (dbg && dbg->h && dbg->h->reg_profile) { char *p = dbg->h->reg_profile (dbg); if (p) { - r_reg_set_profile_string (dbg->reg, p); + rz_reg_set_profile_string (dbg->reg, p); if (dbg->anal && dbg->reg != dbg->anal->reg) { - r_reg_free (dbg->anal->reg); + rz_reg_free (dbg->anal->reg); dbg->anal->reg = dbg->reg; } if (dbg->h->init) { dbg->h->init (dbg); } - r_reg_set_profile_string (dbg->reg, p); + rz_reg_set_profile_string (dbg->reg, p); free (p); } else { eprintf ("Cannot retrieve reg profile from debug plugin (%s)\n", dbg->h->name); @@ -50,17 +50,17 @@ R_API bool r_debug_use(RDebug *dbg, const char *str) { return (dbg && dbg->h); } -R_API int r_debug_plugin_list(RDebug *dbg, int mode) { +RZ_API int rz_debug_plugin_list(RzDebug *dbg, int mode) { char spaces[16]; int count = 0; memset (spaces, ' ', 15); spaces[15] = 0; - RDebugPlugin *h; - RListIter *iter; + RzDebugPlugin *h; + RzListIter *iter; if (mode == 'j') { dbg->cb_printf ("["); } - r_list_foreach (dbg->plugins, iter, h) { + rz_list_foreach (dbg->plugins, iter, h) { int sp = 8-strlen (h->name); spaces[sp] = 0; if (mode == 'q') { @@ -84,20 +84,20 @@ R_API int r_debug_plugin_list(RDebug *dbg, int mode) { return false; } -R_API bool r_debug_plugin_add(RDebug *dbg, RDebugPlugin *foo) { +RZ_API bool rz_debug_plugin_add(RzDebug *dbg, RzDebugPlugin *foo) { if (!dbg || !foo || !foo->name) { return false; } - RDebugPlugin *dp = R_NEW (RDebugPlugin); - memcpy (dp, foo, sizeof (RDebugPlugin)); - r_list_append (dbg->plugins, dp); + RzDebugPlugin *dp = R_NEW (RzDebugPlugin); + memcpy (dp, foo, sizeof (RzDebugPlugin)); + rz_list_append (dbg->plugins, dp); return true; } -R_API bool r_debug_plugin_set_reg_profile(RDebug *dbg, const char *profile) { - char *str = r_file_slurp (profile, NULL); +RZ_API bool rz_debug_plugin_set_reg_profile(RzDebug *dbg, const char *profile) { + char *str = rz_file_slurp (profile, NULL); if (!str) { - eprintf ("r_debug_plugin_set_reg_profile: Cannot find '%s'\n", profile); + eprintf ("rz_debug_plugin_set_reg_profile: Cannot find '%s'\n", profile); return false; } if (dbg && dbg->h && dbg->h->set_reg_profile) { diff --git a/libr/debug/snap.c b/librz/debug/snap.c similarity index 51% rename from libr/debug/snap.c rename to librz/debug/snap.c index 0e1021df0b..9ba1c1f83b 100644 --- a/libr/debug/snap.c +++ b/librz/debug/snap.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2015-2020 - pancake, rkx1209 */ -#include -#include +#include +#include -R_API void r_debug_snap_free(RDebugSnap *snap) { +RZ_API void rz_debug_snap_free(RzDebugSnap *snap) { if (snap) { free (snap->name); free (snap->data); @@ -11,14 +11,14 @@ R_API void r_debug_snap_free(RDebugSnap *snap) { } } -R_API RDebugSnap *r_debug_snap_map(RDebug *dbg, RDebugMap *map) { - r_return_val_if_fail (dbg && map, NULL); +RZ_API RzDebugSnap *rz_debug_snap_map(RzDebug *dbg, RzDebugMap *map) { + rz_return_val_if_fail (dbg && map, NULL); if (map->size < 1) { eprintf ("Invalid map size\n"); return NULL; } - RDebugSnap *snap = R_NEW0 (RDebugSnap); + RzDebugSnap *snap = R_NEW0 (RzDebugSnap); if (!snap) { return NULL; } @@ -33,7 +33,7 @@ R_API RDebugSnap *r_debug_snap_map(RDebug *dbg, RDebugMap *map) { snap->data = malloc (map->size); if (!snap->data) { - r_debug_snap_free (snap); + rz_debug_snap_free (snap); return NULL; } eprintf ("Reading %d byte(s) from 0x%08"PFMT64x "...\n", snap->size, snap->addr); @@ -42,57 +42,57 @@ R_API RDebugSnap *r_debug_snap_map(RDebug *dbg, RDebugMap *map) { return snap; } -R_API bool r_debug_snap_contains(RDebugSnap *snap, ut64 addr) { +RZ_API bool rz_debug_snap_contains(RzDebugSnap *snap, ut64 addr) { return (snap->addr <= addr && addr >= snap->addr_end); } -R_API ut8 *r_debug_snap_get_hash(RDebugSnap *snap) { - ut64 algobit = r_hash_name_to_bits ("sha256"); - RHash *ctx = r_hash_new (true, algobit); +RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap) { + ut64 algobit = rz_hash_name_to_bits ("sha256"); + RzHash *ctx = rz_hash_new (true, algobit); if (!ctx) { return NULL; } - r_hash_do_begin (ctx, algobit); - r_hash_calculate (ctx, algobit, snap->data, snap->size); - r_hash_do_end (ctx, algobit); + rz_hash_do_begin (ctx, algobit); + rz_hash_calculate (ctx, algobit, snap->data, snap->size); + rz_hash_do_end (ctx, algobit); ut8 *ret = malloc (R_HASH_SIZE_SHA256); if (!ret) { - r_hash_free (ctx); + rz_hash_free (ctx); return NULL; } memcpy (ret, ctx->digest, R_HASH_SIZE_SHA256); - r_hash_free (ctx); + rz_hash_free (ctx); return ret; } -R_API bool r_debug_snap_is_equal(RDebugSnap *a, RDebugSnap *b) { +RZ_API bool rz_debug_snap_is_equal(RzDebugSnap *a, RzDebugSnap *b) { bool ret = false; - ut64 algobit = r_hash_name_to_bits ("sha256"); - RHash *ctx = r_hash_new (true, algobit); + ut64 algobit = rz_hash_name_to_bits ("sha256"); + RzHash *ctx = rz_hash_new (true, algobit); if (!ctx) { return ret; } - r_hash_do_begin (ctx, algobit); - r_hash_calculate (ctx, algobit, a->data, a->size); - r_hash_do_end (ctx, algobit); + rz_hash_do_begin (ctx, algobit); + rz_hash_calculate (ctx, algobit, a->data, a->size); + rz_hash_do_end (ctx, algobit); ut8 *temp = malloc (R_HASH_SIZE_SHA256); if (!temp) { - r_hash_free (ctx); + rz_hash_free (ctx); return ret; } memcpy (temp, ctx->digest, R_HASH_SIZE_SHA256); - r_hash_do_begin (ctx, algobit); - r_hash_calculate (ctx, algobit, b->data, b->size); - r_hash_do_end (ctx, algobit); + rz_hash_do_begin (ctx, algobit); + rz_hash_calculate (ctx, algobit, b->data, b->size); + rz_hash_do_end (ctx, algobit); ret = memcmp (temp, ctx->digest, R_HASH_SIZE_SHA256) == 0; free (temp); - r_hash_free (ctx); + rz_hash_free (ctx); return ret; } diff --git a/libr/debug/trace.c b/librz/debug/trace.c similarity index 56% rename from libr/debug/trace.c rename to librz/debug/trace.c index e570af0f65..5c1dc125c3 100644 --- a/libr/debug/trace.c +++ b/librz/debug/trace.c @@ -1,36 +1,36 @@ /* radare - LGPL - Copyright 2008-2020 - pancake */ -#include +#include // DO IT WITH SDB -R_API RDebugTrace *r_debug_trace_new (void) { - RDebugTrace *t = R_NEW0 (RDebugTrace); +RZ_API RzDebugTrace *rz_debug_trace_new (void) { + RzDebugTrace *t = R_NEW0 (RzDebugTrace); if (!t) { return NULL; } t->tag = 1; // UT32_MAX; t->addresses = NULL; t->enabled = false; - t->traces = r_list_new (); + t->traces = rz_list_new (); if (!t->traces) { - r_debug_trace_free (t); + rz_debug_trace_free (t); return NULL; } t->traces->free = free; t->ht = ht_pp_new0 (); if (!t->ht) { - r_debug_trace_free (t); + rz_debug_trace_free (t); return NULL; } return t; } -R_API void r_debug_trace_free (RDebugTrace *trace) { +RZ_API void rz_debug_trace_free (RzDebugTrace *trace) { if (!trace) { return; } - r_list_purge (trace->traces); + rz_list_purge (trace->traces); free (trace->traces); ht_pp_free (trace->ht); R_FREE (trace); @@ -38,46 +38,46 @@ R_API void r_debug_trace_free (RDebugTrace *trace) { // TODO: added overlap/mask support here... wtf? // TODO: think about tagged traces -R_API int r_debug_trace_tag (RDebug *dbg, int tag) { +RZ_API int rz_debug_trace_tag (RzDebug *dbg, int tag) { //if (tag>0 && tag<31) core->dbg->trace->tag = 1<<(sz-1); return (dbg->trace->tag = (tag>0)? tag: UT32_MAX); } -R_API bool r_debug_trace_ins_before(RDebug *dbg) { - RListIter *it, *it_tmp; - RAnalValue *val; +RZ_API bool rz_debug_trace_ins_before(RzDebug *dbg) { + RzListIter *it, *it_tmp; + RzAnalValue *val; ut8 buf_pc[32]; // Analyze current instruction - ut64 pc = r_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); + ut64 pc = rz_debug_reg_get (dbg, dbg->reg->name[R_REG_NAME_PC]); if (!dbg->iob.read_at) { return false; } if (!dbg->iob.read_at (dbg->iob.io, pc, buf_pc, sizeof (buf_pc))) { return false; } - dbg->cur_op = R_NEW0 (RAnalOp); + dbg->cur_op = R_NEW0 (RzAnalOp); if (!dbg->cur_op) { return false; } - if (!r_anal_op (dbg->anal, dbg->cur_op, pc, buf_pc, sizeof (buf_pc), R_ANAL_OP_MASK_VAL)) { - r_anal_op_free (dbg->cur_op); + if (!rz_anal_op (dbg->anal, dbg->cur_op, pc, buf_pc, sizeof (buf_pc), R_ANAL_OP_MASK_VAL)) { + rz_anal_op_free (dbg->cur_op); dbg->cur_op = NULL; return false; } // resolve mem write address - r_list_foreach_safe (dbg->cur_op->access, it, it_tmp, val) { + rz_list_foreach_safe (dbg->cur_op->access, it, it_tmp, val) { switch (val->type) { case R_ANAL_VAL_REG: if (!(val->access & R_ANAL_ACC_W)) { - r_list_delete (dbg->cur_op->access, it); + rz_list_delete (dbg->cur_op->access, it); } break; case R_ANAL_VAL_MEM: if (val->memref > 32) { eprintf ("Error: adding changes to %d bytes in memory.\n", val->memref); - r_list_delete (dbg->cur_op->access, it); + rz_list_delete (dbg->cur_op->access, it); break; } @@ -86,19 +86,19 @@ R_API bool r_debug_trace_ins_before(RDebug *dbg) { ut64 addr = 0; addr += val->delta; if (val->seg) { - addr += r_reg_get_value (dbg->reg, val->seg); + addr += rz_reg_get_value (dbg->reg, val->seg); } if (val->reg) { - addr += r_reg_get_value (dbg->reg, val->reg); + addr += rz_reg_get_value (dbg->reg, val->reg); } if (val->regdelta) { int mul = val->mul ? val->mul : 1; - addr += mul * r_reg_get_value (dbg->reg, val->regdelta); + addr += mul * rz_reg_get_value (dbg->reg, val->regdelta); } // resolve address into base for ins_after val->base = addr; } else { - r_list_delete (dbg->cur_op->access, it); + rz_list_delete (dbg->cur_op->access, it); } default: break; @@ -107,13 +107,13 @@ R_API bool r_debug_trace_ins_before(RDebug *dbg) { return true; } -R_API bool r_debug_trace_ins_after(RDebug *dbg) { - RListIter *it; - RAnalValue *val; +RZ_API bool rz_debug_trace_ins_after(RzDebug *dbg) { + RzListIter *it; + RzAnalValue *val; // Add reg/mem write change - r_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); - r_list_foreach (dbg->cur_op->access, it, val) { + rz_debug_reg_sync (dbg, R_REG_TYPE_ALL, false); + rz_list_foreach (dbg->cur_op->access, it, val) { if (!(val->access & R_ANAL_ACC_W)) { continue; } @@ -121,10 +121,10 @@ R_API bool r_debug_trace_ins_after(RDebug *dbg) { switch (val->type) { case R_ANAL_VAL_REG: { - ut64 data = r_reg_get_value (dbg->reg, val->reg); + ut64 data = rz_reg_get_value (dbg->reg, val->reg); // add reg write - r_debug_session_add_reg_change (dbg->session, val->reg->arena, val->reg->offset, data); + rz_debug_session_add_reg_change (dbg->session, val->reg->arena, val->reg->offset, data); break; } case R_ANAL_VAL_MEM: @@ -138,7 +138,7 @@ R_API bool r_debug_trace_ins_after(RDebug *dbg) { // add mem write size_t i; for (i = 0; i < val->memref; i++) { - r_debug_session_add_mem_change (dbg->session, val->base + i, buf[i]); + rz_debug_session_add_mem_change (dbg->session, val->base + i, buf[i]); } break; } @@ -146,7 +146,7 @@ R_API bool r_debug_trace_ins_after(RDebug *dbg) { break; } } - r_anal_op_free (dbg->cur_op); + rz_anal_op_free (dbg->cur_op); dbg->cur_op = NULL; return true; } @@ -154,28 +154,28 @@ R_API bool r_debug_trace_ins_after(RDebug *dbg) { /* * something happened at the given pc that we need to trace */ -R_API int r_debug_trace_pc(RDebug *dbg, ut64 pc) { +RZ_API int rz_debug_trace_pc(RzDebug *dbg, ut64 pc) { ut8 buf[32]; - RAnalOp op = {0}; + RzAnalOp op = {0}; if (!dbg->iob.is_valid_offset (dbg->iob.io, pc, 0)) { eprintf ("trace_pc: cannot read memory at 0x%"PFMT64x"\n", pc); return false; } (void)dbg->iob.read_at (dbg->iob.io, pc, buf, sizeof (buf)); - if (r_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_ESIL) < 1) { + if (rz_anal_op (dbg->anal, &op, pc, buf, sizeof (buf), R_ANAL_OP_MASK_ESIL) < 1) { eprintf ("trace_pc: cannot get opcode size at 0x%"PFMT64x"\n", pc); return false; } - r_debug_trace_op (dbg, &op); - r_anal_op_fini (&op); + rz_debug_trace_op (dbg, &op); + rz_anal_op_fini (&op); return true; } -R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) { +RZ_API void rz_debug_trace_op(RzDebug *dbg, RzAnalOp *op) { static ut64 oldpc = UT64_MAX; // Must trace the previously traced instruction if (dbg->trace->enabled) { if (dbg->anal->esil) { - r_anal_esil_trace_op (dbg->anal->esil, op); + rz_anal_esil_trace_op (dbg->anal->esil, op); } else { if (dbg->verbose) { eprintf ("Run aeim to get dbg->anal->esil initialized\n"); @@ -183,55 +183,55 @@ R_API void r_debug_trace_op(RDebug *dbg, RAnalOp *op) { } } if (oldpc != UT64_MAX) { - r_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do + rz_debug_trace_add (dbg, oldpc, op->size); //XXX review what this line really do } oldpc = op->addr; } -R_API void r_debug_trace_at(RDebug *dbg, const char *str) { +RZ_API void rz_debug_trace_at(RzDebug *dbg, const char *str) { // TODO: parse offsets and so use ut64 instead of strstr() free (dbg->trace->addresses); dbg->trace->addresses = (str&&*str)? strdup (str): NULL; } -R_API RDebugTracepoint *r_debug_trace_get (RDebug *dbg, ut64 addr) { +RZ_API RzDebugTracepoint *rz_debug_trace_get (RzDebug *dbg, ut64 addr) { int tag = dbg->trace->tag; return ht_pp_find (dbg->trace->ht, sdb_fmt ("trace.%d.%"PFMT64x, tag, addr), NULL); } static int cmpaddr (const void *_a, const void *_b) { - const RListInfo *a = _a, *b = _b; - return (r_itv_begin (a->pitv) > r_itv_begin (b->pitv))? 1: - (r_itv_begin (a->pitv) < r_itv_begin (b->pitv))? -1: 0; + const RzListInfo *a = _a, *b = _b; + return (rz_itv_begin (a->pitv) > rz_itv_begin (b->pitv))? 1: + (rz_itv_begin (a->pitv) < rz_itv_begin (b->pitv))? -1: 0; } -R_API void r_debug_trace_list (RDebug *dbg, int mode, ut64 offset) { +RZ_API void rz_debug_trace_list (RzDebug *dbg, int mode, ut64 offset) { int tag = dbg->trace->tag; - RListIter *iter; + RzListIter *iter; bool flag = false; - RList *info_list = r_list_new (); + RzList *info_list = rz_list_new (); if (!info_list && mode == '=') { return; } - RDebugTracepoint *trace; - r_list_foreach (dbg->trace->traces, iter, trace) { + RzDebugTracepoint *trace; + rz_list_foreach (dbg->trace->traces, iter, trace) { if (!trace->tag || (tag & trace->tag)) { switch (mode) { case 'q': dbg->cb_printf ("0x%"PFMT64x"\n", trace->addr); break; case '=': { - RListInfo *info = R_NEW0 (RListInfo); + RzListInfo *info = R_NEW0 (RzListInfo); if (!info) { return; } info->pitv = (RInterval) {trace->addr, trace->size}; info->vitv = info->pitv; info->perm = -1; - info->name = r_str_newf ("%d", trace->times); - info->extra = r_str_newf ("%d", trace->count); - r_list_append (info_list, info); + info->name = rz_str_newf ("%d", trace->times); + info->extra = rz_str_newf ("%d", trace->count); + rz_list_append (info_list, info); flag = true; } break; case 1: @@ -246,20 +246,20 @@ R_API void r_debug_trace_list (RDebug *dbg, int mode, ut64 offset) { } } if (flag) { - r_list_sort (info_list, cmpaddr); - RTable *table = r_table_new (); - table->cons = r_cons_singleton(); - RIO *io = dbg->iob.io; - r_table_visual_list (table, info_list, offset, 1, - r_cons_get_size (NULL), io->va); - io->cb_printf ("\n%s\n", r_table_tostring (table)); - r_table_free (table); - r_list_free (info_list); + rz_list_sort (info_list, cmpaddr); + RTable *table = rz_table_new (); + table->cons = rz_cons_singleton(); + RzIO *io = dbg->iob.io; + rz_table_visual_list (table, info_list, offset, 1, + rz_cons_get_size (NULL), io->va); + io->cb_printf ("\n%s\n", rz_table_tostring (table)); + rz_table_free (table); + rz_list_free (info_list); } } // XXX: find better name, make it public? -static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) { +static int rz_debug_trace_is_traceable(RzDebug *dbg, ut64 addr) { if (dbg->trace->addresses) { char addr_str[32]; snprintf (addr_str, sizeof (addr_str), "0x%08"PFMT64x, addr); @@ -270,34 +270,34 @@ static int r_debug_trace_is_traceable(RDebug *dbg, ut64 addr) { return true; } -R_API RDebugTracepoint *r_debug_trace_add (RDebug *dbg, ut64 addr, int size) { - RDebugTracepoint *tp; +RZ_API RzDebugTracepoint *rz_debug_trace_add (RzDebug *dbg, ut64 addr, int size) { + RzDebugTracepoint *tp; int tag = dbg->trace->tag; - if (!r_debug_trace_is_traceable (dbg, addr)) { + if (!rz_debug_trace_is_traceable (dbg, addr)) { return NULL; } - r_anal_trace_bb (dbg->anal, addr); - tp = R_NEW0 (RDebugTracepoint); + rz_anal_trace_bb (dbg->anal, addr); + tp = R_NEW0 (RzDebugTracepoint); if (!tp) { return NULL; } - tp->stamp = r_time_now (); + tp->stamp = rz_time_now (); tp->addr = addr; tp->tags = tag; tp->size = size; tp->count = ++dbg->trace->count; tp->times = 1; - r_list_append (dbg->trace->traces, tp); + rz_list_append (dbg->trace->traces, tp); ht_pp_update (dbg->trace->ht, sdb_fmt ("trace.%d.%"PFMT64x, tag, addr), tp); return tp; } -R_API void r_debug_trace_reset (RDebug *dbg) { - RDebugTrace *t = dbg->trace; - r_list_purge (t->traces); +RZ_API void rz_debug_trace_reset (RzDebug *dbg) { + RzDebugTrace *t = dbg->trace; + rz_list_purge (t->traces); ht_pp_free (t->ht); t->ht = ht_pp_new0 (); - t->traces = r_list_new (); + t->traces = rz_list_new (); t->traces->free = free; } diff --git a/libr/depgraph.pl b/librz/depgraph.pl similarity index 100% rename from libr/depgraph.pl rename to librz/depgraph.pl diff --git a/librz/do-ar-sh b/librz/do-ar-sh new file mode 100644 index 0000000000..762eab56cf --- /dev/null +++ b/librz/do-ar-sh @@ -0,0 +1,56 @@ +#!/bin/sh + +LIBS="librz/cons/librz_cons.a librz/util/librz_util.a librz/bin/librz_bin.a librz/anal/librz_anal.a librz/bp/librz_bp.a librz/hash/librz_hash.a librz/debug/librz_debug.a shlr/sdb/src/libsdb.a librz/core/librz_core.a librz/main/librz_main.a librz/fs/librz_fs.a librz/syscall/librz_syscall.a shlr/java/librz_java.a shlr/zip/librz.a librz/socket/librz_socket.a librz/anal/librz_anal.a librz/flag/librz_flag.a librz/search/librz_search.a librz/reg/librz_reg.a librz/config/librz_config.a librz/io/librz_io.a librz/parse/librz_parse.a librz/bp/librz_bp.a librz/asm/librz_asm.a librz/bp/librz_bp.a librz/egg/librz_egg.a librz/anal/librz_anal.a librz/magic/librz_magic.a librz/lang/librz_lang.a librz/fs/librz_fs.a shlr/grub/libgrubfs.a shlr/capstone/libcapstone.a shlr/gdb/lib/libgdbr.a shlr/tree-sitter/libtree-sitter.a shlr/rizin-shell-parser/libshell-parser.a" +cd .. + +LIB=librz.a +TMP=.ar.tmp + +IOSVER=1 +if [ -n "${IOSVER}" ]; then + RANLIB="xcrun --sdk iphoneos ranlib" + AR="xcrun --sdk iphoneos ar" +else + RANLIB=ranlib + AR=ar +fi + +rm -rf ${TMP} +mkdir -p ${TMP} +for a in ${LIBS} ; do + ${RANLIB} $a + file "$a" | grep -q universal + if [ $? = 0 ]; then + ARCHS=`lipo -info $a | cut -d : -f 3-` + else + ARCHS="" + fi + if [ -n "${ARCHS}" ]; then + for b in ${ARCHS} ; do + mkdir -p "$TMP/$a/$b" + ORIG="$PWD/$a.$b" + lipo -thin $b -output $a.$b $a + echo "cd $TMP/$a/$b : ${AR} -x $ORIG" + ( cd $TMP/$a/$b ; ${AR} -x $ORIG ) + rm -f $a.$b + done + else + mkdir -p "${TMP}/${a}" + ORIG="$PWD/$a" + ( cd $TMP/$a ; ${AR} -x $ORIG ) + echo $a + fi +done + +cd ${TMP} +OBJS=`find * -iname *.o` +if [ -z "${OBJS}" ]; then + echo + echo "Cannot find any object" + echo + exit 1 +else + rm -f "${LIB}" + ${AR} -qv "${LIB}" ${OBJS} + ${RANLIB} "${LIB}" +fi diff --git a/libr/egg/Makefile b/librz/egg/Makefile similarity index 78% rename from libr/egg/Makefile rename to librz/egg/Makefile index 67d288ebf5..e58126ec39 100644 --- a/libr/egg/Makefile +++ b/librz/egg/Makefile @@ -1,8 +1,8 @@ include ../config.mk -NAME=r_egg -R2DEPS=r_asm r_syscall r_util r_parse r_reg r_lang -R2DEPS+=r_flag r_cons +NAME=rz_egg +R2DEPS=rz_asm rz_syscall rz_util rz_parse rz_reg rz_lang +R2DEPS+=rz_flag rz_cons OBJS=egg.o egg_lang.o OBJS+=emit_x86.o diff --git a/libr/egg/README b/librz/egg/README similarity index 97% rename from libr/egg/README rename to librz/egg/README index d8fcb37e3d..6354ad4762 100644 --- a/libr/egg/README +++ b/librz/egg/README @@ -46,7 +46,7 @@ spp (merge into) TODO: this is not yet implemented - INCDIR@alias("/usr/include/ragg2"); + INCDIR@alias("/usr/include/rz_gg"); sys-osx.r@include(INCDIR); Hashbang @@ -54,7 +54,7 @@ Hashbang eggs can use a hashbang to make them executable. $ head -n1 hello.r - #!/usr/bin/ragg2 -X + #!/usr/bin/rz_gg -X $ ./hello.r Hello World! @@ -64,7 +64,7 @@ The execution of the code is done as in a flow. The first function to be defined will be the first one to be executed. If you want to run main() just do like this: - #!/usr/bin/ragg2 -X + #!/usr/bin/rz_gg -X main(); ... main@global(128,64) { @@ -140,7 +140,7 @@ Tracing Sometimes r_egg programs will break or just not work as expected. Use the 'trace' architecture to get a arch-backend call trace: - $ ragg2 -a trace -s yourprogram.r + $ rz_gg -a trace -s yourprogram.r Pointers -------- @@ -164,7 +164,7 @@ calling a function or when typing a variable name without assignment. add (3,4); } - $ ragg2 -F -o test test.r + $ rz_gg -F -o test test.r $ ./test $ echo $? 7 diff --git a/librz/egg/egg.c b/librz/egg/egg.c new file mode 100644 index 0000000000..f8de1729d7 --- /dev/null +++ b/librz/egg/egg.c @@ -0,0 +1,565 @@ +/* radare - LGPL - Copyright 2011-2018 - pancake */ + +#include +#include + +R_LIB_VERSION (rz_egg); + +// TODO: must be plugins +extern RzEggEmit emit_x86; +extern RzEggEmit emit_x64; +extern RzEggEmit emit_arm; +extern RzEggEmit emit_trace; + +static RzEggPlugin *egg_static_plugins[] = + { R_EGG_STATIC_PLUGINS }; + +struct egg_patch_t { + RBuffer *b; + int off; +}; + +void egg_patch_free (void *p) { + struct egg_patch_t *ep = (struct egg_patch_t *)p; + rz_buf_free (ep->b); + free (ep); +} + +RZ_API RzEgg *rz_egg_new(void) { + int i; + RzEgg *egg = R_NEW0 (RzEgg); + if (!egg) { + return NULL; + } + egg->src = rz_buf_new (); + if (!egg->src) { + goto beach; + } + egg->buf = rz_buf_new (); + if (!egg->buf) { + goto beach; + } + egg->bin = rz_buf_new (); + if (!egg->bin) { + goto beach; + } + egg->remit = &emit_x86; + egg->syscall = rz_syscall_new (); + if (!egg->syscall) { + goto beach; + } + egg->rasm = rz_asm_new (); + if (!egg->rasm) { + goto beach; + } + egg->bits = 0; + egg->endian = 0; + egg->db = sdb_new (NULL, NULL, 0); + if (!egg->db) { + goto beach; + } + egg->patches = rz_list_newf (egg_patch_free); + if (!egg->patches) { + goto beach; + } + egg->plugins = rz_list_new (); + for (i=0; egg_static_plugins[i]; i++) { + rz_egg_add (egg, egg_static_plugins[i]); + } + return egg; + +beach: + rz_egg_free (egg); + return NULL; +} + +RZ_API int rz_egg_add(RzEgg *a, RzEggPlugin *foo) { + RzListIter *iter; + RzAsmPlugin *h; + // TODO: cache foo->name length and use memcmp instead of strcmp + if (!foo->name) { + return false; + } + rz_list_foreach (a->plugins, iter, h) { + if (!strcmp (h->name, foo->name)) { + return false; + } + } + rz_list_append (a->plugins, foo); + return true; +} + +RZ_API char *rz_egg_to_string(RzEgg *egg) { + return rz_buf_to_string (egg->buf); +} + +RZ_API void rz_egg_free(RzEgg *egg) { + if (egg) { + rz_buf_free (egg->src); + rz_buf_free (egg->buf); + rz_buf_free (egg->bin); + rz_list_free (egg->list); + rz_asm_free (egg->rasm); + rz_syscall_free (egg->syscall); + sdb_free (egg->db); + rz_list_free (egg->plugins); + rz_list_free (egg->patches); + rz_egg_lang_free (egg); + free (egg); + } +} + +RZ_API void rz_egg_reset(RzEgg *egg) { + rz_egg_lang_include_init (egg); + // TODO: use rz_list_purge instead of free/new here + rz_buf_free (egg->src); + rz_buf_free (egg->buf); + rz_buf_free (egg->bin); + egg->src = rz_buf_new (); + egg->buf = rz_buf_new (); + egg->bin = rz_buf_new (); + rz_list_purge (egg->patches); +} + +RZ_API int rz_egg_setup(RzEgg *egg, const char *arch, int bits, int endian, const char *os) { + const char *asmcpu = NULL; // TODO + egg->remit = NULL; + + egg->os = os? rz_str_hash (os): R_EGG_OS_DEFAULT; + //eprintf ("%s -> %x (linux=%x) (darwin=%x)\n", os, egg->os, R_EGG_OS_LINUX, R_EGG_OS_DARWIN); + // TODO: setup egg->arch for all archs + if (!strcmp (arch, "x86")) { + egg->arch = R_SYS_ARCH_X86; + switch (bits) { + case 32: + rz_syscall_setup (egg->syscall, arch, bits, asmcpu, os); + egg->remit = &emit_x86; + egg->bits = bits; + break; + case 64: + rz_syscall_setup (egg->syscall, arch, bits, asmcpu, os); + egg->remit = &emit_x64; + egg->bits = bits; + break; + } + } else if (!strcmp (arch, "arm")) { + egg->arch = R_SYS_ARCH_ARM; + switch (bits) { + case 16: + case 32: + rz_syscall_setup (egg->syscall, arch, bits, asmcpu, os); + egg->remit = &emit_arm; + egg->bits = bits; + egg->endian = endian; + break; + } + } else if (!strcmp (arch, "trace")) { + //rz_syscall_setup (egg->syscall, arch, os, bits); + egg->remit = &emit_trace; + egg->bits = bits; + egg->endian = endian; + } + return 0; +} + +RZ_API int rz_egg_include(RzEgg *egg, const char *file, int format) { + size_t sz; + const ut8 *foo = (const ut8 *)rz_file_slurp (file, &sz); + if (!foo) { + return 0; + } + // XXX: format breaks compiler layers + switch (format) { + case 'r': // raw + rz_egg_raw (egg, foo, (int)sz); + break; + case 'a': // assembly + rz_buf_append_bytes (egg->buf, foo, (ut64)sz); + break; + default: + rz_buf_append_bytes (egg->src, foo, (ut64)sz); + } + free ((void *)foo); + return 1; +} + +RZ_API void rz_egg_load(RzEgg *egg, const char *code, int format) { + switch (format) { + case 'a': // assembly + rz_buf_append_bytes (egg->buf, (const ut8 *)code, strlen (code)); + break; + default: + rz_buf_append_bytes (egg->src, (const ut8 *)code, strlen (code)); + break; + } +} + +RZ_API void rz_egg_syscall(RzEgg *egg, const char *arg, ...) { + RzSyscallItem *item = rz_syscall_get (egg->syscall, + rz_syscall_get_num (egg->syscall, arg), -1); + if (!strcmp (arg, "close")) { + //egg->remit->syscall_args (); + } + if (!item) { + return; + } + egg->remit->syscall (egg, item->num); +} + +RZ_API void rz_egg_alloc(RzEgg *egg, int n) { + // add esp, n +} + +RZ_API void rz_egg_label(RzEgg *egg, const char *name) { + rz_egg_printf (egg, "%s:\n", name); +} + +RZ_API void rz_egg_math(RzEgg *egg) { //, char eq, const char *vs, char type, const char *sr + // TODO + //e->mathop (egg, op, type, eq, p); +} + +RZ_API int rz_egg_raw(RzEgg *egg, const ut8 *b, int len) { + int outlen = len * 2; // two hexadecimal digits per byte + char *out = malloc (outlen + 1); + if (!out) { + return false; + } + (void)rz_hex_bin2str (b, len, out); + rz_buf_append_bytes (egg->buf, (const ut8 *)".hex ", 5); + rz_buf_append_bytes (egg->buf, (const ut8 *)out, outlen); + rz_buf_append_bytes (egg->buf, (const ut8 *)"\n", 1); + free (out); + return true; +} + +static int rz_egg_raw_prepend(RzEgg *egg, const ut8 *b, int len) { + int outlen = len * 2; // two hexadecimal digits per byte + char *out = malloc (outlen + 1); + if (!out) { + return false; + } + rz_hex_bin2str (b, len, out); + rz_buf_prepend_bytes (egg->buf, (const ut8 *)"\n", 1); + rz_buf_prepend_bytes (egg->buf, (const ut8 *)out, outlen); + rz_buf_prepend_bytes (egg->buf, (const ut8 *)".hex ", 5); + free (out); + return true; +} + +static int rz_egg_prepend_bytes(RzEgg *egg, const ut8 *b, int len) { + if (!rz_egg_raw_prepend (egg, b, len)) { + return false; + } + if (!rz_buf_prepend_bytes (egg->bin, b, len)) { + return false; + } + return true; +} + +static int rz_egg_append_bytes(RzEgg *egg, const ut8 *b, int len) { + if (!rz_egg_raw (egg, b, len)) { + return false; + } + + if (!rz_buf_append_bytes (egg->bin, b, len)) { + return false; + } + + return true; +} + +// rz_egg_block (egg, FRAME | IF | ELSE | ENDIF | FOR | WHILE, sz) +RZ_API void rz_egg_if(RzEgg *egg, const char *reg, char cmp, int v) { + // egg->depth++; +} + +RZ_API void rz_egg_printf(RzEgg *egg, const char *fmt, ...) { + va_list ap; + int len; + char buf[1024]; + va_start (ap, fmt); + len = vsnprintf (buf, sizeof (buf), fmt, ap); + rz_buf_append_bytes (egg->buf, (const ut8 *)buf, len); + va_end (ap); +} + +RZ_API bool rz_egg_assemble_asm(RzEgg *egg, char **asm_list) { + RzAsmCode *asmcode = NULL; + char *code = NULL; + char *asm_name = NULL; + + if (asm_list) { + char **asm_; + + for (asm_ = asm_list; *asm_; asm_ += 2) { + if (!strcmp (egg->remit->arch, asm_[0])) { + asm_name = asm_[1]; + break; + } + } + } + if (!asm_name) { + if (egg->remit == &emit_x86 || egg->remit == &emit_x64) { + asm_name = "x86.nz"; + } else if (egg->remit == &emit_arm) { + asm_name = "arm"; + } + } + if (asm_name) { + rz_asm_use (egg->rasm, asm_name); + rz_asm_set_bits (egg->rasm, egg->bits); + rz_asm_set_big_endian (egg->rasm, egg->endian); + rz_asm_set_syntax (egg->rasm, R_ASM_SYNTAX_INTEL); + code = rz_buf_to_string (egg->buf); + asmcode = rz_asm_massemble (egg->rasm, code); + if (asmcode) { + if (asmcode->len > 0) { + rz_buf_append_bytes (egg->bin, asmcode->bytes, asmcode->len); + } + // LEAK rz_asm_code_free (asmcode); + } else { + eprintf ("fail assembling\n"); + } + } + free (code); + bool ret = (asmcode != NULL); + rz_asm_code_free (asmcode); + return ret; +} + +RZ_API bool rz_egg_assemble(RzEgg *egg) { + return rz_egg_assemble_asm (egg, NULL); +} + +RZ_API int rz_egg_compile(RzEgg *egg) { + rz_buf_seek (egg->src, 0, R_BUF_SET); + char b; + int r = rz_buf_read (egg->src, (ut8 *)&b, sizeof (b)); + if (r != sizeof (b) || !egg->remit) { + return true; + } + // only emit begin if code is found + rz_egg_lang_init (egg); + for (; b; ) { + rz_egg_lang_parsechar (egg, b); + if (egg->lang.elem_n >= sizeof (egg->lang.elem)) { + eprintf ("ERROR: elem too large.\n"); + break; + } + int r = rz_buf_read (egg->src, (ut8 *)&b, sizeof (b)); + if (r != sizeof (b)) { + break; + } + // XXX: some parse fail errors are false positives :( + } + if (egg->context>0) { + eprintf ("ERROR: expected '}' at the end of the file. %d left\n", egg->context); + return false; + } + // TODO: handle errors here + return true; +} + +RZ_API RBuffer *rz_egg_get_bin(RzEgg *egg) { + // TODO increment reference + return egg->bin; +} + +//RZ_API int rz_egg_dump (RzEgg *egg, const char *file) { } + +RZ_API char *rz_egg_get_source(RzEgg *egg) { + return rz_buf_to_string (egg->src); +} + +RZ_API char *rz_egg_get_assembly(RzEgg *egg) { + return rz_buf_to_string (egg->buf); +} + +RZ_API void rz_egg_append(RzEgg *egg, const char *src) { + rz_buf_append_bytes (egg->src, (const ut8*)src, strlen (src)); +} + +/* JIT : TODO: accept arguments here */ +RZ_API int rz_egg_run(RzEgg *egg) { + ut64 tmpsz; + const ut8 *tmp = rz_buf_data (egg->bin, &tmpsz); + bool res = rz_sys_run (tmp, tmpsz); + return res; +} + +RZ_API int rz_egg_run_rop(RzEgg *egg) { + ut64 sz; + const ut8 *tmp = rz_buf_data (egg->bin, &sz); + return rz_sys_run_rop (tmp, sz); +} + +#define R_EGG_FILL_TYPE_TRAP +#define R_EGG_FILL_TYPE_NOP +#define R_EGG_FILL_TYPE_CHAR +#define R_EGG_FILL_TYPE_SEQ +#define R_EGG_FILL_TYPE_SEQ + +static inline char *eon(char *n) { + while (*n && (*n >= '0' && *n <= '9')) { + n++; + } + return n; +} + +/* padding looks like: + ([snatSNAT][0-9]+)* +*/ +RZ_API int rz_egg_padding(RzEgg *egg, const char *pad) { + int number; + ut8 *buf, padding_byte; + char *p, *o = strdup (pad); + + for (p = o; *p;) { // parse pad string + const char f = *p++; + number = strtol (p, NULL, 10); + + if (number < 1) { + eprintf ("Invalid padding length at %d\n", number); + free (o); + return false; + } + p = eon(p); + + switch (f) { + case 's': case 'S': padding_byte = 0; break; + case 'n': case 'N': padding_byte = 0x90; break; + case 'a': + case 'A': padding_byte = 'A'; break; + case 't': + case 'T': padding_byte = 0xcc; break; + default: + eprintf ("Invalid padding format (%c)\n", *p); + eprintf ("Valid ones are:\n"); + eprintf (" s S : NULL byte"); + eprintf (" n N : nop"); + eprintf (" a A : 0x41"); + eprintf (" t T : trap (0xcc)"); + free (o); + return false; + } + + buf = malloc (number); + if (!buf) { + free (o); + return false; + } + + memset (buf, padding_byte, number); + if (f >= 'a' && f <= 'z') { + rz_egg_prepend_bytes(egg, buf, number); + } else { + rz_egg_append_bytes(egg, buf, number); + } + free (buf); + } + free (o); + return true; +} + +RZ_API void rz_egg_fill(RzEgg *egg, int pos, int type, int argc, int length) { + // TODO +} + +RZ_API void rz_egg_option_set(RzEgg *egg, const char *key, const char *val) { + sdb_set (egg->db, key, val, 0); +} + +RZ_API char *rz_egg_option_get(RzEgg *egg, const char *key) { + return sdb_get (egg->db, key, NULL); +} + +RZ_API int rz_egg_shellcode(RzEgg *egg, const char *name) { + RzEggPlugin *p; + RzListIter *iter; + RBuffer *b; + rz_list_foreach (egg->plugins, iter, p) { + if (p->type == R_EGG_PLUGIN_SHELLCODE && !strcmp (name, p->name)) { + b = p->build (egg); + if (!b) { + eprintf ("%s Shellcode has failed\n", p->name); + return false; + } + ut64 tmpsz; + const ut8 *tmp = rz_buf_data (b, &tmpsz); + rz_egg_raw (egg, tmp, tmpsz); + return true; + } + } + return false; +} + +RZ_API int rz_egg_encode(RzEgg *egg, const char *name) { + RzEggPlugin *p; + RzListIter *iter; + RBuffer *b; + rz_list_foreach (egg->plugins, iter, p) { + if (p->type == R_EGG_PLUGIN_ENCODER && !strcmp (name, p->name)) { + b = p->build (egg); + if (!b) { + return false; + } + rz_buf_free (egg->bin); + egg->bin = b; + return true; + } + } + return false; +} + +RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len) { + struct egg_patch_t *ep = R_NEW (struct egg_patch_t); + if (!ep) { + return false; + } + ep->b = rz_buf_new_with_bytes (buf, len); + if (!ep->b) { + egg_patch_free (ep); + return false; + } + ep->off = off; + rz_list_append (egg->patches, ep); + return true; +} + +RZ_API void rz_egg_finalize(RzEgg *egg) { + struct egg_patch_t *ep; + RzListIter *iter; + if (!egg->bin) { + rz_buf_free (egg->bin); + egg->bin = rz_buf_new (); + } + rz_list_foreach (egg->patches, iter, ep) { + if (ep->off < 0) { + ut64 sz; + const ut8 *buf = rz_buf_data (ep->b, &sz); + rz_egg_append_bytes (egg, buf, sz); + } else if (ep->off < rz_buf_size (egg->bin)) { + ut64 sz; + const ut8 *buf = rz_buf_data (ep->b, &sz); + int r = rz_buf_write_at (egg->bin, ep->off, buf, sz); + if (r < sz) { + eprintf ("Error during patch\n"); + return; + } + } else { + eprintf ("Cannot patch outside\n"); + return; + } + } +} + +RZ_API void rz_egg_pattern(RzEgg *egg, int size) { + char *ret = rz_debruijn_pattern ((int)size, 0, NULL); + if (ret) { + rz_egg_prepend_bytes (egg, (const ut8*)ret, strlen(ret)); + free (ret); + } else { + eprintf ("Invalid debruijn pattern length.\n"); + } +} diff --git a/libr/egg/egg_Cfile.c b/librz/egg/egg_Cfile.c similarity index 66% rename from libr/egg/egg_Cfile.c rename to librz/egg/egg_Cfile.c index 96e5aad3b1..71656e755e 100644 --- a/libr/egg/egg_Cfile.c +++ b/librz/egg/egg_Cfile.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2011-2018 - pancake */ -#include +#include // compilation environment struct cEnv_t { @@ -16,17 +16,17 @@ struct cEnv_t { const char *TEXT; }; -static char* r_egg_Cfile_getCompiler(void) { +static char* rz_egg_Cfile_getCompiler(void) { size_t i; const char *compilers[] = {"llvm-gcc", "clang", "gcc"}; - char *output = r_sys_getenv ("CC"); + char *output = rz_sys_getenv ("CC"); if (output) { return output; } for (i = 0; i < 3; i++) { - output = r_file_path (compilers[i]); + output = rz_file_path (compilers[i]); if (strcmp (output, compilers[i])) { free (output); return strdup (compilers[i]); @@ -38,13 +38,13 @@ static char* r_egg_Cfile_getCompiler(void) { return NULL; } -static inline bool r_egg_Cfile_armOrMips(const char *arch) { +static inline bool rz_egg_Cfile_armOrMips(const char *arch) { return (!strcmp (arch, "arm") || !strcmp (arch, "arm64") || !strcmp (arch, "aarch64") || !strcmp (arch, "thumb") || !strcmp (arch, "arm32") || !strcmp (arch, "mips") || !strcmp (arch, "mips32") || !strcmp (arch, "mips64")); } -static void r_egg_Cfile_free_cEnv(struct cEnv_t *cEnv) { +static void rz_egg_Cfile_free_cEnv(struct cEnv_t *cEnv) { if (cEnv) { free (cEnv->SFLIBPATH); free (cEnv->CC); @@ -56,7 +56,7 @@ static void r_egg_Cfile_free_cEnv(struct cEnv_t *cEnv) { free (cEnv); } -static inline bool r_egg_Cfile_check_cEnv(struct cEnv_t *cEnv) { +static inline bool rz_egg_Cfile_check_cEnv(struct cEnv_t *cEnv) { return (!cEnv->SFLIBPATH || !cEnv->CC || !cEnv->CFLAGS || !cEnv->LDFLAGS || !cEnv->SHDR || !cEnv->TRIPLET); } @@ -66,7 +66,7 @@ static inline bool isXNU(const char *os) { || !strcmp (os, "tvos") || !strcmp (os, "watchos") || !strcmp (os, "ios")); } -static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int bits) { +static struct cEnv_t* rz_egg_Cfile_set_cEnv(const char *arch, const char *os, int bits) { struct cEnv_t *cEnv = calloc (1, sizeof (struct cEnv_t)); bool use_clang; char *buffer = NULL; @@ -76,13 +76,13 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int return NULL; } - if (!(cEnv->CC = r_egg_Cfile_getCompiler())) { + if (!(cEnv->CC = rz_egg_Cfile_getCompiler())) { goto fail; } - cEnv->SFLIBPATH = r_sys_getenv ("SFLIBPATH"); + cEnv->SFLIBPATH = rz_sys_getenv ("SFLIBPATH"); if (!cEnv->SFLIBPATH) { - output = r_sys_cmd_strf ("r2 -hh | grep INCDIR | awk '{print $2}'"); + output = rz_sys_cmd_strf ("r2 -hh | grep INCDIR | awk '{print $2}'"); if (!output || (output[0] == '\0')) { eprintf ("Cannot find SFLIBPATH env var.\n" "Please define it, or fix r2 installation.\n"); @@ -90,12 +90,12 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int } output[strlen (output) - 1] = '\0'; // strip the ending '\n' - if (!(cEnv->SFLIBPATH = r_str_newf ("%s/sflib", output))) { + if (!(cEnv->SFLIBPATH = rz_str_newf ("%s/sflib", output))) { goto fail; } } - cEnv->JMP = r_egg_Cfile_armOrMips (arch) ? "b" : "jmp"; + cEnv->JMP = rz_egg_Cfile_armOrMips (arch) ? "b" : "jmp"; // TODO: Missing -Os .. caused some rip-relative LEA to be MOVQ on PIE in CLANG.. so sad if (isXNU (os)) { @@ -113,11 +113,11 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int cEnv->CFLAGS = strdup ("-shared -c -fPIC -pie -fPIE"); cEnv->LDFLAGS = strdup ("-shared -c -fPIC -pie -fPIE"); } - cEnv->SHDR = r_str_newf ("\n.text\n%s _main\n", cEnv->JMP); + cEnv->SHDR = rz_str_newf ("\n.text\n%s _main\n", cEnv->JMP); } else { cEnv->OBJCOPY = "objcopy"; cEnv->FMT = "elf"; - cEnv->SHDR = r_str_newf ("\n.section .text\n.globl main\n" + cEnv->SHDR = rz_str_newf ("\n.section .text\n.globl main\n" "// .type main, @function\n%s main\n", cEnv->JMP); if (!strcmp (arch, "x86")) { if (bits == 32) { @@ -133,7 +133,7 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int } } - cEnv->TRIPLET = r_str_newf ("%s-%s-%d", os, arch, bits); + cEnv->TRIPLET = rz_str_newf ("%s-%s-%d", os, arch, bits); if (!strcmp (os, "windows")) { cEnv->TEXT = ".text"; @@ -158,7 +158,7 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int cEnv->TEXT = "0.__TEXT.__text"; } - buffer = r_str_newf ("%s -fno-stack-protector -nostdinc -include '%s'/'%s'/sflib.h", + buffer = rz_str_newf ("%s -fno-stack-protector -nostdinc -include '%s'/'%s'/sflib.h", cEnv->CFLAGS, cEnv->SFLIBPATH, cEnv->TRIPLET); if (!buffer) { goto fail; @@ -168,7 +168,7 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int if (use_clang) { free (buffer); - buffer = r_str_newf ("%s -fomit-frame-pointer" + buffer = rz_str_newf ("%s -fomit-frame-pointer" " -fno-zero-initialized-in-bss", cEnv->CFLAGS); if (!buffer) { goto fail; @@ -177,7 +177,7 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int cEnv->CFLAGS = strdup (buffer); } else { free (buffer); - buffer = r_str_newf ("%s -z execstack -fomit-frame-pointer" + buffer = rz_str_newf ("%s -z execstack -fomit-frame-pointer" " -finline-functions -fno-zero-initialized-in-bss", cEnv->CFLAGS); if (!buffer) { goto fail; @@ -186,14 +186,14 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int cEnv->CFLAGS = strdup (buffer); } free (buffer); - buffer = r_str_newf ("%s -nostdlib", cEnv->LDFLAGS); + buffer = rz_str_newf ("%s -nostdlib", cEnv->LDFLAGS); if (!buffer) { goto fail; } free (cEnv->LDFLAGS); cEnv->LDFLAGS = strdup (buffer); - if (r_egg_Cfile_check_cEnv (cEnv)) { + if (rz_egg_Cfile_check_cEnv (cEnv)) { eprintf ("Error with cEnv allocation!\n"); goto fail; } @@ -205,31 +205,31 @@ static struct cEnv_t* r_egg_Cfile_set_cEnv(const char *arch, const char *os, int fail: free (buffer); free (output); - r_egg_Cfile_free_cEnv (cEnv); + rz_egg_Cfile_free_cEnv (cEnv); return NULL; } -static bool r_egg_Cfile_parseCompiled(const char *file) { - char *fileExt = r_str_newf ("%s.tmp", file); - char *buffer = r_file_slurp (fileExt, NULL); +static bool rz_egg_Cfile_parseCompiled(const char *file) { + char *fileExt = rz_str_newf ("%s.tmp", file); + char *buffer = rz_file_slurp (fileExt, NULL); if (!buffer) { eprintf ("Could not open '%s'.\n", fileExt); goto fail; } - buffer = r_str_replace (buffer, "rdata", "text", false); - buffer = r_str_replace (buffer, "rodata", "text", false); - buffer = r_str_replace (buffer, "get_pc_thunk.bx", "__getesp__", true); + buffer = rz_str_replace (buffer, "rdata", "text", false); + buffer = rz_str_replace (buffer, "rodata", "text", false); + buffer = rz_str_replace (buffer, "get_pc_thunk.bx", "__getesp__", true); const char *words[] = {".cstring", "size", "___main", "section", "__alloca", "zero", "cfi"}; size_t i; for (i = 0; i < 7; i++) { - r_str_stripLine (buffer, words[i]); + rz_str_stripLine (buffer, words[i]); } free (fileExt); - fileExt = r_str_newf ("%s.s", file); - if (!r_file_dump (fileExt, (const ut8*) buffer, strlen (buffer), true)) { + fileExt = rz_str_newf ("%s.s", file); + if (!rz_file_dump (fileExt, (const ut8*) buffer, strlen (buffer), true)) { eprintf ("Error while opening %s.s\n", file); goto fail; } @@ -244,49 +244,49 @@ fail: return false; } -R_API char* r_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits) { +RZ_API char* rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits) { char *output = NULL; char *fileExt = NULL; // "file" with extension (.s, .text, ...) - struct cEnv_t *cEnv = r_egg_Cfile_set_cEnv (arch, os, bits); + struct cEnv_t *cEnv = rz_egg_Cfile_set_cEnv (arch, os, bits); if (!cEnv) { goto fail; } - r_str_sanitize (cEnv->CC); + rz_str_sanitize (cEnv->CC); // Compile - char *cmd = r_str_newf ("'%s' %s -o '%s.tmp' -S '%s'\n", cEnv->CC, cEnv->CFLAGS, file, file); + char *cmd = rz_str_newf ("'%s' %s -o '%s.tmp' -S '%s'\n", cEnv->CC, cEnv->CFLAGS, file, file); eprintf ("%s\n", cmd); - int rc = r_sys_cmd (cmd); + int rc = rz_sys_cmd (cmd); free (cmd); if (rc != 0) { goto fail; } - if (!(fileExt = r_str_newf ("%s.s", file))) { + if (!(fileExt = rz_str_newf ("%s.s", file))) { goto fail; } - if (!r_file_dump (fileExt, (const ut8*) cEnv->SHDR, strlen (cEnv->SHDR), false)) { + if (!rz_file_dump (fileExt, (const ut8*) cEnv->SHDR, strlen (cEnv->SHDR), false)) { eprintf ("Error while opening %s.s\n", file); goto fail; } - if (!r_egg_Cfile_parseCompiled (file)) { + if (!rz_egg_Cfile_parseCompiled (file)) { goto fail; } // Assemble - cmd = r_str_newf ("'%s' %s -o '%s.o' '%s.s'", cEnv->CC, cEnv->LDFLAGS, file, file); + cmd = rz_str_newf ("'%s' %s -o '%s.o' '%s.s'", cEnv->CC, cEnv->LDFLAGS, file, file); eprintf ("%s\n", cmd); - rc = r_sys_cmd (cmd); + rc = rz_sys_cmd (cmd); free (cmd); if (rc != 0) { goto fail; } // Link - printf ("rabin2 -o '%s.text' -O d/S/'%s' '%s.o'\n", file, cEnv->TEXT, file); - output = r_sys_cmd_strf ("rabin2 -o '%s.text' -O d/S/'%s' '%s'.o", + printf ("rz_bin -o '%s.text' -O d/S/'%s' '%s.o'\n", file, cEnv->TEXT, file); + output = rz_sys_cmd_strf ("rz_bin -o '%s.text' -O d/S/'%s' '%s'.o", file, cEnv->TEXT, file); if (!output) { eprintf ("Linkage failed!\n"); @@ -294,23 +294,23 @@ R_API char* r_egg_Cfile_parser(const char *file, const char *arch, const char *o } free (fileExt); - if (!(fileExt = r_str_newf ("%s.o", file))) { + if (!(fileExt = rz_str_newf ("%s.o", file))) { goto fail; } - if (!r_file_exists (fileExt)) { + if (!rz_file_exists (fileExt)) { eprintf ("Cannot find %s.o\n", file); goto fail; } free (fileExt); - if (!(fileExt = r_str_newf ("%s.text", file))) { + if (!(fileExt = rz_str_newf ("%s.text", file))) { goto fail; } - if (r_file_size (fileExt) == 0) { - eprintf ("FALLBACK: Using objcopy instead of rabin2"); + if (rz_file_size (fileExt) == 0) { + eprintf ("FALLBACK: Using objcopy instead of rz_bin"); free (output); - output = r_sys_cmd_strf ("'%s' -j .text -O binary '%s.o' '%s.text'", + output = rz_sys_cmd_strf ("'%s' -j .text -O binary '%s.o' '%s.text'", cEnv->OBJCOPY, file, file); if (!output) { eprintf ("objcopy failed!\n"); @@ -322,24 +322,24 @@ R_API char* r_egg_Cfile_parser(const char *file, const char *arch, const char *o const char *extArray[] = {"bin", "tmp", "s", "o"}; for (i = 0; i < 4; i++) { free (fileExt); - if (!(fileExt = r_str_newf ("%s.%s", file, extArray[i]))) { + if (!(fileExt = rz_str_newf ("%s.%s", file, extArray[i]))) { goto fail; } - r_file_rm (fileExt); + rz_file_rm (fileExt); } free (fileExt); - if ((fileExt = r_str_newf ("%s.text", file)) == NULL) { + if ((fileExt = rz_str_newf ("%s.text", file)) == NULL) { goto fail; } free (output); - r_egg_Cfile_free_cEnv (cEnv); + rz_egg_Cfile_free_cEnv (cEnv); return fileExt; fail: free (fileExt); free (output); - r_egg_Cfile_free_cEnv (cEnv); + rz_egg_Cfile_free_cEnv (cEnv); return NULL; } diff --git a/libr/egg/egg_lang.c b/librz/egg/egg_lang.c similarity index 88% rename from libr/egg/egg_lang.c rename to librz/egg/egg_lang.c index 5ef2ac1e34..d2a095e063 100644 --- a/libr/egg/egg_lang.c +++ b/librz/egg/egg_lang.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2010-2018 - pancake */ -#include +#include #define CTX egg->context @@ -55,8 +55,8 @@ static char *trim(char *s) { return s; } -static void rcc_pushstr(REgg *egg, char *str, int filter); -static void rcc_context(REgg *egg, int delta); +static void rcc_pushstr(RzEgg *egg, char *str, int filter); +static void rcc_context(RzEgg *egg, int delta); enum { NORMAL = 0, @@ -72,12 +72,12 @@ enum { }; static char *find_include(const char *prefix, const char *file) { - char *pfx = NULL, *ret = NULL, *env = r_sys_getenv (R_EGG_INCDIR_ENV); + char *pfx = NULL, *ret = NULL, *env = rz_sys_getenv (R_EGG_INCDIR_ENV); if (!prefix) { prefix = ""; } if (*prefix == '$') { - char *out = r_sys_getenv (prefix + 1); + char *out = rz_sys_getenv (prefix + 1); pfx = out? out: strdup (""); } else { pfx = strdup (prefix); @@ -96,11 +96,11 @@ static char *find_include(const char *prefix, const char *file) { *ptr = 0; } free (ret); - ret = r_str_appendf (NULL, "%s/%s", pfx, file); + ret = rz_str_appendf (NULL, "%s/%s", pfx, file); { - char *filepath = r_str_appendf (NULL, "%s/%s/%s", str, pfx, file); + char *filepath = rz_str_appendf (NULL, "%s/%s/%s", str, pfx, file); // eprintf ("try (%s)\n", filepath); - if (r_file_exists (filepath)) { + if (rz_file_exists (filepath)) { free (env); free (pfx); free (ret); @@ -116,13 +116,13 @@ static char *find_include(const char *prefix, const char *file) { } free (env); } else { - ret = r_str_appendf (NULL, "%s/%s", pfx, file); + ret = rz_str_appendf (NULL, "%s/%s", pfx, file); } free (pfx); return ret; } -R_API void r_egg_lang_init(REgg *egg) { +RZ_API void rz_egg_lang_init(RzEgg *egg) { egg->lang.varsize = 'l'; /* do call or inline it ? */ // BOOL egg->lang.docall = 1; @@ -132,7 +132,7 @@ R_API void r_egg_lang_init(REgg *egg) { egg->lang.mode = NORMAL; } -R_API void r_egg_lang_free(REgg *egg) { +RZ_API void rz_egg_lang_free(RzEgg *egg) { int i, len; for (i = 0; i < egg->lang.nsyscalls; i++) { @@ -145,35 +145,35 @@ R_API void r_egg_lang_free(REgg *egg) { } } -R_API void r_egg_lang_include_path(REgg *egg, const char *path) { +RZ_API void rz_egg_lang_include_path(RzEgg *egg, const char *path) { char *tmp_ptr = NULL; - char *env = r_sys_getenv (R_EGG_INCDIR_ENV); + char *env = rz_sys_getenv (R_EGG_INCDIR_ENV); if (!env || !*env) { - r_egg_lang_include_init (egg); + rz_egg_lang_include_init (egg); free (env); - env = r_sys_getenv (R_EGG_INCDIR_ENV); + env = rz_sys_getenv (R_EGG_INCDIR_ENV); tmp_ptr = env; } - env = r_str_appendf (NULL, "%s:%s", path, env); + env = rz_str_appendf (NULL, "%s:%s", path, env); free (tmp_ptr); - r_sys_setenv (R_EGG_INCDIR_ENV, env); + rz_sys_setenv (R_EGG_INCDIR_ENV, env); free (env); } -R_API void r_egg_lang_include_init(REgg *egg) { - char *s = r_str_newf (".:%s/%s", r_sys_prefix (NULL), R_EGG_INCDIR_PATH); - r_sys_setenv (R_EGG_INCDIR_ENV, s); +RZ_API void rz_egg_lang_include_init(RzEgg *egg) { + char *s = rz_str_newf (".:%s/%s", rz_sys_prefix (NULL), R_EGG_INCDIR_PATH); + rz_sys_setenv (R_EGG_INCDIR_ENV, s); free (s); } -static void rcc_set_callname(REgg *egg, const char *s) { +static void rcc_set_callname(RzEgg *egg, const char *s) { R_FREE (egg->lang.callname); egg->lang.nargs = 0; egg->lang.callname = trim (strdup (skipspaces (s))); egg->lang.pushargs = !((!strcmp (s, "goto")) || (!strcmp (s, "break"))); } -static void rcc_reset_callname(REgg *egg) { +static void rcc_reset_callname(RzEgg *egg) { R_FREE (egg->lang.callname); egg->lang.nargs = 0; } @@ -206,7 +206,7 @@ static char *get_frame_label(int type) { return label; } -static char *get_end_frame_label(REgg *egg) { +static char *get_end_frame_label(RzEgg *egg) { static char label[128]; snprintf (label, sizeof (label) - 1, FRAME_END_FMT, egg->lang.nfunctions, egg->lang.nbrackets, context - 1); @@ -216,7 +216,7 @@ static char *get_end_frame_label(REgg *egg) { } #endif -static const char *find_alias(REgg *egg, const char *str) { +static const char *find_alias(RzEgg *egg, const char *str) { // do not forget to free return strings to avoid memory leak char *p = (char *) str; int i; @@ -237,7 +237,7 @@ static const char *find_alias(REgg *egg, const char *str) { // only strings or alias could return valuable data } -static void rcc_internal_mathop(REgg *egg, const char *ptr, char *ep, char op) { +static void rcc_internal_mathop(RzEgg *egg, const char *ptr, char *ep, char op) { char *p, *q, *oldp; // avoid mem leak char type = ' '; char buf[64]; // may cause stack overflow @@ -245,12 +245,12 @@ static void rcc_internal_mathop(REgg *egg, const char *ptr, char *ep, char op) { if (get_op (&q)) { *q = '\x00'; } - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; while (*p && is_space (*p)) { p++; } if (is_var (p)) { - p = r_egg_mkvar (egg, buf, p, 0); + p = rz_egg_mkvar (egg, buf, p, 0); if (egg->lang.varxs == '*') { e->load (egg, p, egg->lang.varsize); R_FREE (oldp); @@ -281,8 +281,8 @@ static void rcc_internal_mathop(REgg *egg, const char *ptr, char *ep, char op) { * level 3: * / * level 4: ^ $ | */ -static void rcc_mathop(REgg *egg, char **pos, int level) { - REggEmit *e = egg->remit; +static void rcc_mathop(RzEgg *egg, char **pos, int level) { + RzEggEmit *e = egg->remit; int op_ret = level; char op, *next_pos; @@ -323,9 +323,9 @@ static void rcc_mathop(REgg *egg, char **pos, int level) { */ } -static void rcc_pusharg(REgg *egg, char *str) { - REggEmit *e = egg->remit; - char buf[64], *p = r_egg_mkvar (egg, buf, str, 0); +static void rcc_pusharg(RzEgg *egg, char *str) { + RzEggEmit *e = egg->remit; + char buf[64], *p = rz_egg_mkvar (egg, buf, str, 0); if (!p) { return; } @@ -339,11 +339,11 @@ static void rcc_pusharg(REgg *egg, char *str) { free (p); } -static void rcc_element(REgg *egg, char *str) { +static void rcc_element(RzEgg *egg, char *str) { if (!egg || !str) { return; } - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; char *ptr, *p = str + strlen (str); int inside = 0; int num, num2; @@ -479,10 +479,10 @@ static void rcc_element(REgg *egg, char *str) { } } -static void rcc_pushstr(REgg *egg, char *str, int filter) { +static void rcc_pushstr(RzEgg *egg, char *str, int filter) { int dotrim; int i, j, len, ch; - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; e->comment (egg, "encode %s string (%s) (%s)", filter? "filtered": "unfiltered", str, egg->lang.callname); @@ -506,7 +506,7 @@ static void rcc_pushstr(REgg *egg, char *str, int filter) { dotrim = 1; break; case 'x': - ch = r_hex_pair2bin (str + i + 2); + ch = rz_hex_pair2bin (str + i + 2); if (ch == -1) { eprintf ("%s:%d Error string format\n", egg->lang.file, egg->lang.line); @@ -532,7 +532,7 @@ static void rcc_pushstr(REgg *egg, char *str, int filter) { R_FREE (egg->lang.dstvar); } -R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta) { +RZ_API char *rz_egg_mkvar(RzEgg *egg, char *out, const char *_str, int delta) { int i, len, qi; char *oldstr = NULL, *str = NULL, foo[32], *q, *ret = NULL; @@ -557,20 +557,20 @@ R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta) { egg->lang.varxs = 0; } if (str[0] == '.') { - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; if (!strncmp (str + 1, "ret", 3)) { strcpy (out, e->retvar); } else if (!strncmp (str + 1, "fix", 3)) { - int idx = (int)r_num_math (NULL, str + 4) + delta + e->size; + int idx = (int)rz_num_math (NULL, str + 4) + delta + e->size; e->get_var (egg, 0, out, idx - egg->lang.stackfixed); // sprintf(out, "%d(%%"R_BP")", -(atoi(str+4)+delta+R_SZ-egg->lang.stackfixed)); } else if (!strncmp (str + 1, "var", 3)) { - int idx = (int)r_num_math (NULL, str + 4) + delta + e->size; + int idx = (int)rz_num_math (NULL, str + 4) + delta + e->size; e->get_var (egg, 0, out, idx); // sprintf(out, "%d(%%"R_BP")", -(atoi(str+4)+delta+R_SZ)); } else if (!strncmp (str + 1, "rarg", 4)) { if (e->get_ar) { - int idx = (int)r_num_math (NULL, str + 5); + int idx = (int)rz_num_math (NULL, str + 5); e->get_ar (egg, out, idx); } } else if (!strncmp (str + 1, "arg", 3)) { @@ -578,7 +578,7 @@ R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta) { if (egg->lang.stackframe == 0) { e->get_var (egg, 1, out, 4); // idx-4); } else { - int idx = (int)r_num_math (NULL, str + 4) + delta + e->size; + int idx = (int)rz_num_math (NULL, str + 4) + delta + e->size; e->get_var (egg, 2, out, idx + 4); } } else { @@ -622,15 +622,15 @@ R_API char *r_egg_mkvar(REgg *egg, char *out, const char *_str, int delta) { free (egg->lang.dstvar); egg->lang.dstvar = strdup (skipspaces (foo)); rcc_pushstr (egg, str, mustfilter); - ret = r_egg_mkvar (egg, out, foo, 0); + ret = rz_egg_mkvar (egg, out, foo, 0); free (oldstr); } return ret; } -static void rcc_fun(REgg *egg, const char *str) { +static void rcc_fun(RzEgg *egg, const char *str) { char *ptr, *ptr2; - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; str = skipspaces (str); if (CTX) { ptr = strchr (str, '='); @@ -700,7 +700,7 @@ static void rcc_fun(REgg *egg, const char *str) { egg->lang.dstval = malloc (4096); egg->lang.ndstval = 0; */ - r_egg_printf (egg, "%s:\n", str); + rz_egg_printf (egg, "%s:\n", str); } else if (strstr (ptr, "inline")) { egg->lang.mode = INLINE; free (egg->lang.dstvar); @@ -710,16 +710,16 @@ static void rcc_fun(REgg *egg, const char *str) { } else { // naked label if (*ptr) { - r_egg_printf (egg, "\n.%s %s\n", ptr, str); + rz_egg_printf (egg, "\n.%s %s\n", ptr, str); } - r_egg_printf (egg, "%s:\n", str); + rz_egg_printf (egg, "%s:\n", str); } } else { // e->jmp (egg, egg->lang.ctxpush[context], 0); if (CTX > 0) { // WTF? eprintf ("LABEL %d\n", CTX); - r_egg_printf (egg, "\n%s:\n", str); + rz_egg_printf (egg, "\n%s:\n", str); } else { if (!strcmp (str, "goto")) { egg->lang.mode = GOTO; @@ -743,7 +743,7 @@ static void shownested(void) { } #endif -static void set_nested(REgg *egg, const char *s) { +static void set_nested(RzEgg *egg, const char *s) { int i = 0; if (CTX < 1) { return; @@ -759,8 +759,8 @@ static void set_nested(REgg *egg, const char *s) { } } -static void rcc_context(REgg *egg, int delta) { - REggEmit *emit = egg->remit; +static void rcc_context(RzEgg *egg, int delta) { + RzEggEmit *emit = egg->remit; char str[64]; if (CTX > 31 || CTX < 0) { @@ -865,7 +865,7 @@ static void rcc_context(REgg *egg, int delta) { } } -static int parsedatachar(REgg *egg, char c) { +static int parsedatachar(RzEgg *egg, char c) { char *str; int i, j; @@ -900,21 +900,21 @@ static int parsedatachar(REgg *egg, char c) { egg->lang.dstval[egg->lang.ndstval] = '\0'; egg->remit->comment (egg, "data (%s)(%s)size=(%d)\n", egg->lang.dstvar, egg->lang.dstval, egg->lang.stackframe); - r_egg_printf (egg, ".data\n"); + rz_egg_printf (egg, ".data\n"); for (str = egg->lang.dstval; is_space (*str); str++) { ; } j = (egg->lang.stackframe)? egg->lang.stackframe: 1; /* emit label */ - r_egg_printf (egg, "%s:\n", egg->lang.dstvar); + rz_egg_printf (egg, "%s:\n", egg->lang.dstvar); for (i = 1; i <= j; i++) { if (*str == '"') { - r_egg_printf (egg, ".ascii %s%s\n", egg->lang.dstval, (i == j)? "\"\\x00\"": ""); + rz_egg_printf (egg, ".ascii %s%s\n", egg->lang.dstval, (i == j)? "\"\\x00\"": ""); } else { - r_egg_printf (egg, ".long %s\n", egg->lang.dstval); + rz_egg_printf (egg, ".long %s\n", egg->lang.dstval); } } - r_egg_printf (egg, ".text\n"); + rz_egg_printf (egg, ".text\n"); R_FREE (egg->lang.dstvar); R_FREE (egg->lang.dstval); egg->lang.ndstval = 0; @@ -929,7 +929,7 @@ static int parsedatachar(REgg *egg, char c) { return 0; } -static int parseinlinechar(REgg *egg, char c) { +static int parseinlinechar(RzEgg *egg, char c) { /* skip until '{' */ if (c == '{') { /* XXX: repeated code!! */ rcc_context (egg, 1); @@ -973,15 +973,15 @@ static int parseinlinechar(REgg *egg, char c) { } /* TODO: split this function into several ones..quite long fun */ -static void rcc_next(REgg *egg) { +static void rcc_next(RzEgg *egg) { const char *ocn; - REggEmit *e = egg->remit; + RzEggEmit *e = egg->remit; char *str = NULL, *p, *ptr, buf[64]; int i; if (egg->lang.setenviron) { egg->lang.elem[egg->lang.elem_n - 1] = 0; - r_sys_setenv (egg->lang.setenviron, egg->lang.elem); + rz_sys_setenv (egg->lang.setenviron, egg->lang.elem); R_FREE (egg->lang.setenviron); return; } @@ -996,14 +996,14 @@ static void rcc_next(REgg *egg) { R_FREE (egg->lang.includefile); R_FREE (egg->lang.includedir); rcc_reset_callname (egg); - p = q = r_file_slurp (path, NULL); + p = q = rz_file_slurp (path, NULL); if (p) { int oline = ++(egg->lang.line); egg->lang.elem[0] = 0; // TODO: this must be a separate function egg->lang.elem_n = 0; egg->lang.line = 0; for (; *p; p++) { - r_egg_lang_parsechar (egg, *p); + rz_egg_lang_parsechar (egg, *p); } free (q); egg->lang.line = oline; @@ -1038,7 +1038,7 @@ static void rcc_next(REgg *egg) { if (!ocn) { return; } - str = r_egg_mkvar (egg, buf, ocn, 0); + str = rz_egg_mkvar (egg, buf, ocn, 0); if (!str) { eprintf ("Cannot mkvar\n"); return; @@ -1080,16 +1080,16 @@ static void rcc_next(REgg *egg) { e->syscall_args (egg, egg->lang.nargs); egg->lang.docall = 0; e->comment (egg, "syscall"); - r_egg_lang_parsechar (egg, '\n'); /* FIX parsing issue */ + rz_egg_lang_parsechar (egg, '\n'); /* FIX parsing issue */ if (p) { for (; *p; p++) { - r_egg_lang_parsechar (egg, *p); + rz_egg_lang_parsechar (egg, *p); } } else { char *q, *s = e->syscall (egg, egg->lang.nargs); if (s) { for (q = s; *q; q++) { - r_egg_lang_parsechar (egg, *q); + rz_egg_lang_parsechar (egg, *q); } free (s); } else { @@ -1106,9 +1106,9 @@ static void rcc_next(REgg *egg) { p = egg->lang.inlines[i].body; egg->lang.docall = 0; e->comment (egg, "inline"); - r_egg_lang_parsechar (egg, '\n'); /* FIX parsing issue */ + rz_egg_lang_parsechar (egg, '\n'); /* FIX parsing issue */ for (; *p; p++) { - r_egg_lang_parsechar (egg, *p); + rz_egg_lang_parsechar (egg, *p); } egg->lang.docall = 0; break; @@ -1131,7 +1131,7 @@ static void rcc_next(REgg *egg) { // XXX: Probably buggy and wrong *buf = 0; free (str); - str = r_egg_mkvar (egg, buf, ocn, 0); + str = rz_egg_mkvar (egg, buf, ocn, 0); if (*buf) e->get_result (egg, buf); // Why should get_result into ocn? //else { eprintf("external symbol %s\n", ocn); } @@ -1143,7 +1143,7 @@ static void rcc_next(REgg *egg) { //if (egg->lang.mode != NAKED) { *buf = 0; free (str); - str = r_egg_mkvar (egg, buf, egg->lang.dstvar, 0); + str = rz_egg_mkvar (egg, buf, egg->lang.dstvar, 0); if (*buf == 0) { eprintf ("Cannot resolve variable '%s'\n", egg->lang.dstvar); } else { @@ -1172,9 +1172,9 @@ static void rcc_next(REgg *egg) { R_FREE (egg->lang.mathline); tmp = NULL; // following code block is too ugly, oh noes - p = r_egg_mkvar (egg, buf, ptr, 0); + p = rz_egg_mkvar (egg, buf, ptr, 0); if (is_var (p)) { - char *q = r_egg_mkvar (egg, buf, p, 0); + char *q = rz_egg_mkvar (egg, buf, p, 0); if (q) { free (p); p = q; @@ -1193,10 +1193,10 @@ static void rcc_next(REgg *egg) { char str2[64], *p, ch = *(eq-1); *eq = '\0'; eq = (char*) skipspaces (eq+1); - p = r_egg_mkvar (egg, str2, ptr, 0); + p = rz_egg_mkvar (egg, str2, ptr, 0); vs = egg->lang.varsize; if (is_var (eq)) { - eq = r_egg_mkvar (egg, buf, eq, 0); + eq = rz_egg_mkvar (egg, buf, eq, 0); if (egg->lang.varxs=='*') e->load (egg, eq, egg->lang.varsize); else @@ -1230,8 +1230,8 @@ static void rcc_next(REgg *egg) { free (str); } -R_API int r_egg_lang_parsechar(REgg *egg, char c) { - REggEmit *e = egg->remit; +RZ_API int rz_egg_lang_parsechar(RzEgg *egg, char c) { + RzEggEmit *e = egg->remit; char *ptr, str[64], *tmp_ptr = NULL; int i, j; if (c == '\n') { @@ -1259,8 +1259,8 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) { if (c == '`') { egg->lang.elem[egg->lang.elem_n] = 0; egg->lang.elem_n = 0; - tmp_ptr = r_egg_mkvar (egg, str, egg->lang.elem, 0); - r_egg_printf (egg, "%s", tmp_ptr); + tmp_ptr = rz_egg_mkvar (egg, str, egg->lang.elem, 0); + rz_egg_printf (egg, "%s", tmp_ptr); free (tmp_ptr); egg->lang.quotelinevar = 0; } else { @@ -1271,13 +1271,13 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) { egg->lang.elem_n = 0; egg->lang.quotelinevar = 1; } else { - r_egg_printf (egg, "%c", c); + rz_egg_printf (egg, "%c", c); } } egg->lang.oc = c; return 0; } else { - r_egg_printf (egg, "\n"); + rz_egg_printf (egg, "\n"); egg->lang.quoteline = 0; } } @@ -1329,17 +1329,17 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) { CTX = 0; break; } - // r_egg_printf (egg, " %s:\n", get_frame_label (0)); + // rz_egg_printf (egg, " %s:\n", get_frame_label (0)); if (egg->lang.nested_callname[CTX] && strstr (egg->lang.nested_callname[CTX], "if") && strstr (egg->lang.elem, "else")) { *egg->lang.elem = '\x00'; egg->lang.elem_n = 0; R_FREE (egg->lang.ifelse_table[CTX][egg->lang.nestedi[CTX] - 1]) egg->lang.ifelse_table[CTX][egg->lang.nestedi[CTX] - 1] = - r_str_newf (" __end_%d_%d_%d", + rz_str_newf (" __end_%d_%d_%d", egg->lang.nfunctions, CTX, egg->lang.nestedi[CTX]); } - r_egg_printf (egg, " __begin_%d_%d_%d:\n", + rz_egg_printf (egg, " __begin_%d_%d_%d:\n", egg->lang.nfunctions, CTX, egg->lang.nestedi[CTX]); // %s:\n", get_frame_label (0)); } rcc_context (egg, 1); @@ -1348,24 +1348,24 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) { egg->lang.endframe = egg->lang.nested[CTX]; if (egg->lang.endframe) { // XXX: use egg->lang.endframe[context] - r_egg_printf (egg, "%s", egg->lang.endframe); + rz_egg_printf (egg, "%s", egg->lang.endframe); R_FREE (egg->lang.nested[CTX]); // R_FREE (egg->lang.endframe); } if (CTX > 1) { if (egg->lang.nested_callname[CTX - 1] && strstr (egg->lang.nested_callname[CTX - 1], "if")) { - tmp_ptr = r_str_newf ("__ifelse_%d_%d", CTX - 1, egg->lang.nestedi[CTX - 1] - 1); + tmp_ptr = rz_str_newf ("__ifelse_%d_%d", CTX - 1, egg->lang.nestedi[CTX - 1] - 1); e->jmp (egg, tmp_ptr, 0); R_FREE (tmp_ptr); // mem leak egg->lang.ifelse_table[CTX - 1][egg->lang.nestedi[CTX - 1] - 1] = - r_str_newf ("__end_%d_%d_%d", + rz_str_newf ("__end_%d_%d_%d", egg->lang.nfunctions, CTX - 1, egg->lang.nestedi[CTX - 1] - 1); } // if (nestede[CTX]) { - // r_egg_printf (egg, "%s:\n", nestede[CTX]); + // rz_egg_printf (egg, "%s:\n", nestede[CTX]); ////nestede[CTX] = NULL; // } else { - r_egg_printf (egg, " __end_%d_%d_%d:\n", + rz_egg_printf (egg, " __end_%d_%d_%d:\n", egg->lang.nfunctions, CTX - 1, egg->lang.nestedi[CTX - 1] - 1); // get_end_frame_label (egg)); // } @@ -1375,20 +1375,20 @@ R_API int r_egg_lang_parsechar(REgg *egg, char c) { } rcc_context (egg, -1); if (CTX == 0) { - r_egg_printf (egg, "\n"); + rz_egg_printf (egg, "\n"); // snprintf(str, 64, "__end_%d", egg->lang.nfunctions); // e->jmp(egg, str, 0); // edit this unnessary jmp to bypass tests for (i = 0; i < 32; i++) { for (j = 0; j < egg->lang.nestedi[i] && j < 32; j++) { if (egg->lang.ifelse_table[i][j]) { - r_egg_printf (egg, " __ifelse_%d_%d:\n", i, j); + rz_egg_printf (egg, " __ifelse_%d_%d:\n", i, j); e->jmp (egg, egg->lang.ifelse_table[i][j], 0); R_FREE (egg->lang.ifelse_table[i][j]); } } } - // r_egg_printf(egg, " __end_%d:\n\n", egg->lang.nfunctions); + // rz_egg_printf(egg, " __end_%d:\n\n", egg->lang.nfunctions); // edit this unnessary jmp to bypass tests egg->lang.nbrackets = 0; egg->lang.nfunctions++; diff --git a/libr/egg/emit_arm.c b/librz/egg/emit_arm.c similarity index 50% rename from libr/egg/emit_arm.c rename to librz/egg/emit_arm.c index c11f3441da..48d7823a7a 100644 --- a/libr/egg/emit_arm.c +++ b/librz/egg/emit_arm.c @@ -1,6 +1,6 @@ /* pancake // nopcode.org 2010-2011 -- arm emiter */ -#include +#include #define attsyntax 0 #define EMIT_NAME emit_arm @@ -18,11 +18,11 @@ static char *regs[] = R_GP; static int lastarg = 0; static char lastargs[16][32]; -static void emit_init(REgg *egg) { +static void emit_init(RzEgg *egg) { /* TODO */ } -static char *emit_syscall(REgg *egg, int num) { +static char *emit_syscall(RzEgg *egg, int num) { int svc = 0; switch (egg->os) { case R_EGG_OS_DARWIN: @@ -38,51 +38,51 @@ static char *emit_syscall(REgg *egg, int num) { svc = 0; break; } - return r_str_newf (": mov "R_AX ", `.arg`\n: svc 0x%x\n", svc); + return rz_str_newf (": mov "R_AX ", `.arg`\n: svc 0x%x\n", svc); } -static void emit_frame(REgg *egg, int sz) { - r_egg_printf (egg, " push {fp,lr}\n"); +static void emit_frame(RzEgg *egg, int sz) { + rz_egg_printf (egg, " push {fp,lr}\n"); if (sz > 0) { - r_egg_printf (egg, + rz_egg_printf (egg, // " mov "R_BP", "R_SP"\n" " add fp, sp, $4\n" // size of arguments " sub sp, %d\n", sz); // size of stackframe 8, 16, .. } } -static void emit_frame_end(REgg *egg, int sz, int ctx) { +static void emit_frame_end(RzEgg *egg, int sz, int ctx) { if (sz > 0) { - r_egg_printf (egg, " add sp, fp, %d\n", sz); + rz_egg_printf (egg, " add sp, fp, %d\n", sz); } if (ctx > 0) { - r_egg_printf (egg, " pop {fp,pc}\n"); + rz_egg_printf (egg, " pop {fp,pc}\n"); } } -static void emit_comment(REgg *egg, const char *fmt, ...) { +static void emit_comment(RzEgg *egg, const char *fmt, ...) { va_list ap; char buf[1024]; va_start (ap, fmt); vsnprintf (buf, sizeof (buf), fmt, ap); - r_egg_printf (egg, "# %s\n", buf); + rz_egg_printf (egg, "# %s\n", buf); va_end (ap); } -static void emit_equ(REgg *egg, const char *key, const char *value) { - r_egg_printf (egg, ".equ %s, %s\n", key, value); +static void emit_equ(RzEgg *egg, const char *key, const char *value) { + rz_egg_printf (egg, ".equ %s, %s\n", key, value); } -static void emit_syscall_args(REgg *egg, int nargs) { +static void emit_syscall_args(RzEgg *egg, int nargs) { int j, k; for (j = 0; j < nargs; j++) { k = j * R_SZ; - r_egg_printf (egg, " ldr %s, [sp, %d]\n", + rz_egg_printf (egg, " ldr %s, [sp, %d]\n", regs[j + 1], k? k + 4: k + 8); } } -static void emit_set_string(REgg *egg, const char *dstvar, const char *str, int j) { +static void emit_set_string(RzEgg *egg, const char *dstvar, const char *str, int j) { int rest, off = 0; off = strlen (str) + 1; rest = (off % 4); @@ -90,50 +90,50 @@ static void emit_set_string(REgg *egg, const char *dstvar, const char *str, int rest = 4 - rest; } off += rest - 4; - r_egg_printf (egg, " add pc, %d\n", (off)); - // XXX: does not handle \n and so on.. must use r_util - // use r_str_escape to handle \n + rz_egg_printf (egg, " add pc, %d\n", (off)); + // XXX: does not handle \n and so on.. must use rz_util + // use rz_str_escape to handle \n // do not forget mem leak - r_egg_printf (egg, ".string \"%s\"\n", str = r_str_escape (str)); + rz_egg_printf (egg, ".string \"%s\"\n", str = rz_str_escape (str)); free ((char *) str); if (rest) { - r_egg_printf (egg, ".fill %d, 1, 0\n", (rest)); + rz_egg_printf (egg, ".fill %d, 1, 0\n", (rest)); } - r_egg_printf (egg, " sub r0, pc, %d\n", off + 12); + rz_egg_printf (egg, " sub r0, pc, %d\n", off + 12); { - char str[32], *p = r_egg_mkvar (egg, str, dstvar, 0); - // r_egg_printf (egg, "DSTVAR=%s --> %s\n", dstvar, p); - r_egg_printf (egg, " str r0, [%s]\n", p); + char str[32], *p = rz_egg_mkvar (egg, str, dstvar, 0); + // rz_egg_printf (egg, "DSTVAR=%s --> %s\n", dstvar, p); + rz_egg_printf (egg, " str r0, [%s]\n", p); free (p); } } -static void emit_jmp(REgg *egg, const char *str, int atr) { +static void emit_jmp(RzEgg *egg, const char *str, int atr) { if (atr) { - r_egg_printf (egg, " ldr r0, %s", str); - r_egg_printf (egg, " bx r0\n"); + rz_egg_printf (egg, " ldr r0, %s", str); + rz_egg_printf (egg, " bx r0\n"); } else { - r_egg_printf (egg, " b %s\n", str); + rz_egg_printf (egg, " b %s\n", str); } } -static void emit_call(REgg *egg, const char *str, int atr) { +static void emit_call(RzEgg *egg, const char *str, int atr) { int i; - // r_egg_printf (egg, " ARGS=%d CALL(%s,%d)\n", lastarg, str, atr); + // rz_egg_printf (egg, " ARGS=%d CALL(%s,%d)\n", lastarg, str, atr); for (i = 0; i < lastarg; i++) { - r_egg_printf (egg, " ldr r%d, [%s]\n", lastarg - 1 - i, lastargs[i]); + rz_egg_printf (egg, " ldr r%d, [%s]\n", lastarg - 1 - i, lastargs[i]); lastargs[i][0] = 0; } if (atr) { - r_egg_printf (egg, " ldr r0, %s", str); - r_egg_printf (egg, " blx r0\n"); + rz_egg_printf (egg, " ldr r0, %s", str); + rz_egg_printf (egg, " blx r0\n"); } else { - r_egg_printf (egg, " bl %s\n", str); + rz_egg_printf (egg, " bl %s\n", str); } } -static void emit_arg(REgg *egg, int xs, int num, const char *str) { +static void emit_arg(RzEgg *egg, int xs, int num, const char *str) { int d = atoi (str); if (!attsyntax && (*str == '$')) { str++; @@ -142,53 +142,53 @@ static void emit_arg(REgg *egg, int xs, int num, const char *str) { switch (xs) { case 0: if (strchr (str, ',')) { - // r_egg_printf (egg, ". str r0, [%s]\n", str); + // rz_egg_printf (egg, ". str r0, [%s]\n", str); strncpy (lastargs[num - 1], str, sizeof(lastargs[0]) - 1); } else { if (!atoi (str)) { eprintf ("WARNING: probably a bug?\n"); } - r_egg_printf (egg, " mov r0, %s\n", str); + rz_egg_printf (egg, " mov r0, %s\n", str); snprintf (lastargs[num - 1], sizeof (lastargs[0]), "sp, %d", 8 + (num * 4)); - r_egg_printf (egg, " str r0, [%s]\n", lastargs[num - 1]); + rz_egg_printf (egg, " str r0, [%s]\n", lastargs[num - 1]); } break; case '*': - r_egg_printf (egg, " push {%s}\n", str); + rz_egg_printf (egg, " push {%s}\n", str); break; case '&': if (d) { - r_egg_printf (egg, " add "R_BP ", %d\n", d); + rz_egg_printf (egg, " add "R_BP ", %d\n", d); } - r_egg_printf (egg, " push {"R_BP "}\n"); + rz_egg_printf (egg, " push {"R_BP "}\n"); if (d) { - r_egg_printf (egg, " sub "R_BP ", %d\n", d); + rz_egg_printf (egg, " sub "R_BP ", %d\n", d); } break; } } -static void emit_get_result(REgg *egg, const char *ocn) { - r_egg_printf (egg, " mov %s, r0\n", ocn); +static void emit_get_result(RzEgg *egg, const char *ocn) { + rz_egg_printf (egg, " mov %s, r0\n", ocn); } -static void emit_restore_stack(REgg *egg, int size) { +static void emit_restore_stack(RzEgg *egg, int size) { // XXX: must die.. or add emit_store_stack. not needed by ARM - // r_egg_printf (egg, " add sp, %d\n", size); + // rz_egg_printf (egg, " add sp, %d\n", size); } -static void emit_get_while_end(REgg *egg, char *str, const char *ctxpush, const char *label) { +static void emit_get_while_end(RzEgg *egg, char *str, const char *ctxpush, const char *label) { sprintf (str, " push {%s}\n b %s\n", ctxpush, label); } -static void emit_while_end(REgg *egg, const char *labelback) { - r_egg_printf (egg, +static void emit_while_end(RzEgg *egg, const char *labelback) { + rz_egg_printf (egg, " pop "R_AX "\n" " cmp "R_AX ", "R_AX "\n" // XXX MUST SUPPORT != 0 COMPARE HERE " beq %s\n", labelback); } -static void emit_get_var(REgg *egg, int type, char *out, int idx) { +static void emit_get_var(RzEgg *egg, int type, char *out, int idx) { switch (type) { case 0: sprintf (out, "sp, %d", idx - 1); break;/* variable */ case 1: sprintf (out, "r%d", idx); break; /* registers */ @@ -196,15 +196,15 @@ static void emit_get_var(REgg *egg, int type, char *out, int idx) { } } -static void emit_trap(REgg *egg) { - r_egg_printf (egg, " udf 16\n"); +static void emit_trap(RzEgg *egg) { + rz_egg_printf (egg, " udf 16\n"); } -static void emit_load_ptr(REgg *egg, const char *dst) { - r_egg_printf (egg, " ldr r0, [fp, %d]\n", atoi (dst)); +static void emit_load_ptr(RzEgg *egg, const char *dst) { + rz_egg_printf (egg, " ldr r0, [fp, %d]\n", atoi (dst)); } -static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { +static void emit_branch(RzEgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { char *p, str[64]; char *arg = NULL; char *op = "beq"; @@ -231,32 +231,32 @@ static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, c if (*arg == '=') { arg++; /* for <=, >=, ... */ } - p = r_egg_mkvar (egg, str, arg, 0); - r_egg_printf (egg, " pop "R_AX "\n"); /* TODO: add support for more than one arg get arg0 */ - r_egg_printf (egg, " cmp %s, "R_AX "\n", p); + p = rz_egg_mkvar (egg, str, arg, 0); + rz_egg_printf (egg, " pop "R_AX "\n"); /* TODO: add support for more than one arg get arg0 */ + rz_egg_printf (egg, " cmp %s, "R_AX "\n", p); // if (context>0) - r_egg_printf (egg, " %s %s\n", op, dst); + rz_egg_printf (egg, " %s %s\n", op, dst); free (p); } -static void emit_load(REgg *egg, const char *dst, int sz) { +static void emit_load(RzEgg *egg, const char *dst, int sz) { switch (sz) { case 'l': - r_egg_printf (egg, " mov "R_AX ", %s\n", dst); - r_egg_printf (egg, " mov "R_AX ", ["R_AX "]\n"); + rz_egg_printf (egg, " mov "R_AX ", %s\n", dst); + rz_egg_printf (egg, " mov "R_AX ", ["R_AX "]\n"); break; case 'b': - r_egg_printf (egg, " mov "R_AX ", %s\n", dst); - r_egg_printf (egg, " movz "R_AX ", ["R_AX "]\n"); + rz_egg_printf (egg, " mov "R_AX ", %s\n", dst); + rz_egg_printf (egg, " movz "R_AX ", ["R_AX "]\n"); break; default: // TODO: unhandled?!? - r_egg_printf (egg, " mov "R_AX ", %s\n", dst); - r_egg_printf (egg, " mov "R_AX ", ["R_AX "]\n"); + rz_egg_printf (egg, " mov "R_AX ", %s\n", dst); + rz_egg_printf (egg, " mov "R_AX ", ["R_AX "]\n"); } } -static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, const char *p) { +static void emit_mathop(RzEgg *egg, int ch, int vs, int type, const char *eq, const char *p) { char *op; switch (ch) { case '^': op = "eor"; break; @@ -281,17 +281,17 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con eprintf (" %s %s, [%s]\n", op, p, eq); #endif if (type == '*') { - r_egg_printf (egg, " %s %s, [%s]\n", op, p, eq); + rz_egg_printf (egg, " %s %s, [%s]\n", op, p, eq); } else { - r_egg_printf (egg, " %s %s, %s\n", op, p, eq); + rz_egg_printf (egg, " %s %s, %s\n", op, p, eq); } } -static const char *emit_regs(REgg *egg, int idx) { +static const char *emit_regs(RzEgg *egg, int idx) { return regs[idx % R_NGP]; } -REggEmit EMIT_NAME = { +RzEggEmit EMIT_NAME = { .arch = R_ARCH, .size = R_SZ, .jmp = emit_jmp, diff --git a/libr/egg/emit_trace.c b/librz/egg/emit_trace.c similarity index 50% rename from libr/egg/emit_trace.c rename to librz/egg/emit_trace.c index 802aea4522..18a46815f3 100644 --- a/libr/egg/emit_trace.c +++ b/librz/egg/emit_trace.c @@ -1,6 +1,6 @@ /* pancake // nopcode.org 2011 -- trace emiter */ -#include +#include #define attsyntax 0 #define EMIT_NAME emit_trace @@ -16,102 +16,102 @@ // no attsyntax for arm static char *regs[] = R_GP; -static void emit_init (REgg *egg) { +static void emit_init (RzEgg *egg) { /* TODO */ } -static char *emit_syscall (REgg *egg, int num) { +static char *emit_syscall (RzEgg *egg, int num) { char buf[32]; snprintf (buf, sizeof (buf), "syscall (%d)\n", num); return strdup (buf); } -static void emit_frame (REgg *egg, int sz) { - r_egg_printf (egg, "frame (%d)\n", sz); +static void emit_frame (RzEgg *egg, int sz) { + rz_egg_printf (egg, "frame (%d)\n", sz); } -static void emit_frame_end (REgg *egg, int sz, int ctx) { - r_egg_printf (egg, "frame_end (%d, %d)\n", sz, ctx); +static void emit_frame_end (RzEgg *egg, int sz, int ctx) { + rz_egg_printf (egg, "frame_end (%d, %d)\n", sz, ctx); } -static void emit_comment(REgg *egg, const char *fmt, ...) { +static void emit_comment(RzEgg *egg, const char *fmt, ...) { va_list ap; char buf[1024]; va_start (ap, fmt); vsnprintf (buf, sizeof (buf), fmt, ap); - r_egg_printf (egg, "# %s\n", buf); + rz_egg_printf (egg, "# %s\n", buf); va_end (ap); } -static void emit_equ (REgg *egg, const char *key, const char *value) { - r_egg_printf (egg, "equ (%s, %s)\n", key, value); +static void emit_equ (RzEgg *egg, const char *key, const char *value) { + rz_egg_printf (egg, "equ (%s, %s)\n", key, value); } -static void emit_syscall_args(REgg *egg, int nargs) { - r_egg_printf (egg, "syscall_args (%d)\n", nargs); +static void emit_syscall_args(RzEgg *egg, int nargs) { + rz_egg_printf (egg, "syscall_args (%d)\n", nargs); } -static void emit_set_string(REgg *egg, const char *dstvar, const char *str, int j) { +static void emit_set_string(RzEgg *egg, const char *dstvar, const char *str, int j) { // what is j? - r_egg_printf (egg, "set (\"%s\", \"%s\", %d)\n", dstvar, str, j); + rz_egg_printf (egg, "set (\"%s\", \"%s\", %d)\n", dstvar, str, j); } -static void emit_call(REgg *egg, const char *str, int atr) { +static void emit_call(RzEgg *egg, const char *str, int atr) { if (atr) { - r_egg_printf (egg, "call ([%s])\n", str); + rz_egg_printf (egg, "call ([%s])\n", str); } else { - r_egg_printf (egg, "call (%s)\n", str); + rz_egg_printf (egg, "call (%s)\n", str); } } -static void emit_jmp(REgg *egg, const char *str, int atr) { +static void emit_jmp(RzEgg *egg, const char *str, int atr) { if (atr) { - r_egg_printf (egg, "goto ([%s])\n", str); + rz_egg_printf (egg, "goto ([%s])\n", str); } else { - r_egg_printf (egg, "goto (%s)\n", str); + rz_egg_printf (egg, "goto (%s)\n", str); } } -static void emit_arg (REgg *egg, int xs, int num, const char *str) { +static void emit_arg (RzEgg *egg, int xs, int num, const char *str) { // TODO: enhance output here - r_egg_printf (egg, "arg.%d.%d=%s\n", xs, num, str); + rz_egg_printf (egg, "arg.%d.%d=%s\n", xs, num, str); } -static void emit_get_result(REgg *egg, const char *ocn) { - r_egg_printf (egg, "get_result (%s)\n", ocn); +static void emit_get_result(RzEgg *egg, const char *ocn) { + rz_egg_printf (egg, "get_result (%s)\n", ocn); } -static void emit_restore_stack (REgg *egg, int size) { - r_egg_printf (egg, "restore_stack (%d)\n", size); +static void emit_restore_stack (RzEgg *egg, int size) { + rz_egg_printf (egg, "restore_stack (%d)\n", size); // XXX: must die.. or add emit_store_stack. not needed by ARM - // r_egg_printf (egg, " add sp, %d\n", size); + // rz_egg_printf (egg, " add sp, %d\n", size); } -static void emit_get_while_end (REgg *egg, char *str, const char *ctxpush, const char *label) { - r_egg_printf (egg, "get_while_end (%s, %s, %s)\n", str, ctxpush, label); +static void emit_get_while_end (RzEgg *egg, char *str, const char *ctxpush, const char *label) { + rz_egg_printf (egg, "get_while_end (%s, %s, %s)\n", str, ctxpush, label); } -static void emit_while_end (REgg *egg, const char *labelback) { - r_egg_printf (egg, "while_end (%s)\n", labelback); +static void emit_while_end (RzEgg *egg, const char *labelback) { + rz_egg_printf (egg, "while_end (%s)\n", labelback); } -static void emit_get_var (REgg *egg, int type, char *out, int idx) { +static void emit_get_var (RzEgg *egg, int type, char *out, int idx) { switch (type) { case 0: sprintf (out, "fp,$%d", -idx); break; /* variable */ case 1: sprintf (out, "sp,$%d", idx); break; /* argument */ // XXX: MUST BE r0, r1, r2, .. } } -static void emit_trap (REgg *egg) { - r_egg_printf (egg, "trap\n"); +static void emit_trap (RzEgg *egg) { + rz_egg_printf (egg, "trap\n"); } // TODO atoi here? -static void emit_load_ptr(REgg *egg, const char *dst) { - r_egg_printf (egg, "loadptr (%s)\n", dst); +static void emit_load_ptr(RzEgg *egg, const char *dst) { + rz_egg_printf (egg, "loadptr (%s)\n", dst); } -static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { +static void emit_branch(RzEgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { // This function signature is crap char *p, str[64]; char *arg = NULL; @@ -140,17 +140,17 @@ static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, c if (*arg == '=') { arg++; /* for <=, >=, ... */ } - p = r_egg_mkvar (egg, str, arg, 0); - r_egg_printf (egg, "%s (%s) => (%s)\n", op, p, dst); + p = rz_egg_mkvar (egg, str, arg, 0); + rz_egg_printf (egg, "%s (%s) => (%s)\n", op, p, dst); free (p); } // XXX: sz must be char -static void emit_load(REgg *egg, const char *dst, int sz) { - r_egg_printf (egg, "load (\"%s\", %c)\n", dst, sz); +static void emit_load(RzEgg *egg, const char *dst, int sz) { + rz_egg_printf (egg, "load (\"%s\", %c)\n", dst, sz); } -static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, const char *p) { +static void emit_mathop(RzEgg *egg, int ch, int vs, int type, const char *eq, const char *p) { char *op; switch (ch) { case '^': op = "eor"; break; @@ -175,17 +175,17 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con eprintf (" %s %s, [%s]\n", op, p, eq); #endif if (type == '*') { - r_egg_printf (egg, "%s (%s, [%s])\n", op, p, eq); + rz_egg_printf (egg, "%s (%s, [%s])\n", op, p, eq); } else { - r_egg_printf (egg, "%s (%s, %s)\n", op, p, eq); + rz_egg_printf (egg, "%s (%s, %s)\n", op, p, eq); } } -static const char* emit_regs(REgg *egg, int idx) { +static const char* emit_regs(RzEgg *egg, int idx) { return regs[idx%R_NGP]; } -REggEmit EMIT_NAME = { +RzEggEmit EMIT_NAME = { .retvar = "a0", .arch = R_ARCH, .size = R_SZ, diff --git a/librz/egg/emit_x64.c b/librz/egg/emit_x64.c new file mode 100644 index 0000000000..818b6c841d --- /dev/null +++ b/librz/egg/emit_x64.c @@ -0,0 +1,4 @@ +/* pancake // nopcode.org 2010-2011 -- emit module for rizin/rz_egg */ + +#define ARCH_X86_64 1 +#include "emit_x86.c" diff --git a/libr/egg/emit_x86.c b/librz/egg/emit_x86.c similarity index 53% rename from libr/egg/emit_x86.c rename to librz/egg/emit_x86.c index 4dc3e6dc05..1e5385bdd1 100644 --- a/libr/egg/emit_x86.c +++ b/librz/egg/emit_x86.c @@ -1,7 +1,7 @@ /* pancake // nopcode.org 2010-2013 -- emit module for rcc */ -#include -#include +#include +#include /* hardcoded */ #define attsyntax 0 @@ -32,16 +32,16 @@ static char *regs[] = { "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp" }; # define R_NGP (sizeof (regs)/sizeof (char *)) -static void emit_init (REgg *egg) { +static void emit_init (RzEgg *egg) { // TODO: add 'andb rsp, 0xf0' if (attsyntax) { - r_egg_printf (egg, "mov %%" R_SP ", %%" R_BP "\n"); + rz_egg_printf (egg, "mov %%" R_SP ", %%" R_BP "\n"); } else { - r_egg_printf (egg, "mov " R_BP ", " R_SP "\n"); + rz_egg_printf (egg, "mov " R_BP ", " R_SP "\n"); } } -static char *emit_syscall (REgg *egg, int nargs) { +static char *emit_syscall (RzEgg *egg, int nargs) { char p[512]; if (attsyntax) { return strdup (": mov $`.arg`, %" R_AX "\n: " SYSCALL_ATT "\n"); @@ -72,17 +72,17 @@ static char *emit_syscall (REgg *egg, int nargs) { return strdup (p); } -static void emit_frame (REgg *egg, int sz) { +static void emit_frame (RzEgg *egg, int sz) { if (sz < 1) { return; } if (attsyntax) { - r_egg_printf (egg, + rz_egg_printf (egg, " push %%"R_BP"\n" " mov %%"R_SP", %%"R_BP"\n" " sub $%d, %%"R_SP"\n", sz); } else { - r_egg_printf (egg, + rz_egg_printf (egg, " push " R_BP "\n" " mov " R_BP ", " R_SP "\n" " sub " R_SP ", %d\n", @@ -90,36 +90,36 @@ static void emit_frame (REgg *egg, int sz) { } } -static void emit_frame_end (REgg *egg, int sz, int ctx) { +static void emit_frame_end (RzEgg *egg, int sz, int ctx) { if (sz>0) { if (attsyntax) { - r_egg_printf (egg, " add $%d, %%"R_SP"\n", sz); - r_egg_printf (egg, " pop %%"R_BP"\n"); + rz_egg_printf (egg, " add $%d, %%"R_SP"\n", sz); + rz_egg_printf (egg, " pop %%"R_BP"\n"); } else { - r_egg_printf (egg, " add "R_SP", %d\n", sz); - r_egg_printf (egg, " pop "R_BP"\n"); + rz_egg_printf (egg, " add "R_SP", %d\n", sz); + rz_egg_printf (egg, " pop "R_BP"\n"); } } if (ctx > 0) { - r_egg_printf (egg, " ret\n"); + rz_egg_printf (egg, " ret\n"); } } -static void emit_comment(REgg *egg, const char *fmt, ...) { +static void emit_comment(RzEgg *egg, const char *fmt, ...) { va_list ap; char buf[1024]; va_start (ap, fmt); vsnprintf (buf, sizeof (buf), fmt, ap); if (attsyntax) { - r_egg_printf (egg, " /* %s */\n", buf); + rz_egg_printf (egg, " /* %s */\n", buf); } else { - r_egg_printf (egg, "# %s\n", buf); + rz_egg_printf (egg, "# %s\n", buf); } va_end (ap); } -static void emit_equ (REgg *egg, const char *key, const char *value) { - r_egg_printf (egg, ".equ %s,%s\n", key, value); +static void emit_equ (RzEgg *egg, const char *key, const char *value) { + rz_egg_printf (egg, ".equ %s,%s\n", key, value); } static const char *getreg(int i) { @@ -129,7 +129,7 @@ static const char *getreg(int i) { return regs[i]; } -static void emit_syscall_args(REgg *egg, int nargs) { +static void emit_syscall_args(RzEgg *egg, int nargs) { int j, k; for (j = 0; j < nargs; j++) { k = j * R_SZ; @@ -139,20 +139,20 @@ static void emit_syscall_args(REgg *egg, int nargs) { break; } if (attsyntax) { - r_egg_printf (egg, " mov %d(%%"R_SP"), %%%s\n", k, reg); + rz_egg_printf (egg, " mov %d(%%"R_SP"), %%%s\n", k, reg); } else { if (k > 0) { - r_egg_printf (egg, " mov %s, ["R_SP"+%d]\n", reg, k); + rz_egg_printf (egg, " mov %s, ["R_SP"+%d]\n", reg, k); } else if (k < 0) { - r_egg_printf (egg, " mov %s, ["R_SP"%d]\n", reg, k); + rz_egg_printf (egg, " mov %s, ["R_SP"%d]\n", reg, k); } else { - r_egg_printf (egg, " mov %s, ["R_SP"]\n", reg); + rz_egg_printf (egg, " mov %s, ["R_SP"]\n", reg); } } } } -static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) { +static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) { char *p, str2[64]; int i, oj = j; @@ -171,11 +171,11 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) { for (i=4; i<=oj; i+=4) { /* XXX endian issues (non-portable asm) */ ut32 *n = (ut32 *)(s+i-4); - p = r_egg_mkvar (egg, str2, dstvar, i+BPOFF); + p = rz_egg_mkvar (egg, str2, dstvar, i+BPOFF); if (attsyntax) { - r_egg_printf (egg, " movl $0x%x, %s\n", M32 (*n), p); + rz_egg_printf (egg, " movl $0x%x, %s\n", M32 (*n), p); } else { - r_egg_printf (egg, " mov dword %s, 0x%x\n", p, M32 (*n)); + rz_egg_printf (egg, " mov dword %s, 0x%x\n", p, M32 (*n)); } free (p); j -= 4; @@ -183,28 +183,28 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) { #undef M32 /* zero */ - p = r_egg_mkvar (egg, str2, dstvar, i+BPOFF); + p = rz_egg_mkvar (egg, str2, dstvar, i+BPOFF); if (attsyntax) { - r_egg_printf (egg, " movl $0, %s\n", p); + rz_egg_printf (egg, " movl $0, %s\n", p); } else { - r_egg_printf (egg, " mov dword %s, 0\n", p); + rz_egg_printf (egg, " mov dword %s, 0\n", p); } free (p); /* store pointer */ - p = r_egg_mkvar (egg, str2, dstvar, j+4+BPOFF); + p = rz_egg_mkvar (egg, str2, dstvar, j+4+BPOFF); if (attsyntax) { - r_egg_printf (egg, " lea %s, %%" R_AX "\n", p); + rz_egg_printf (egg, " lea %s, %%" R_AX "\n", p); } else { - r_egg_printf (egg, " lea " R_AX ", %s\n", p); + rz_egg_printf (egg, " lea " R_AX ", %s\n", p); } free (p); - p = r_egg_mkvar (egg, str2, dstvar, 0); + p = rz_egg_mkvar (egg, str2, dstvar, 0); if (attsyntax) { - r_egg_printf (egg, " mov %%" R_AX ", %s\n", p); + rz_egg_printf (egg, " mov %%" R_AX ", %s\n", p); } else { - r_egg_printf (egg, " mov %s, " R_AX "\n", p); + rz_egg_printf (egg, " mov %s, " R_AX "\n", p); } free (p); @@ -215,50 +215,50 @@ static void emit_string(REgg *egg, const char *dstvar, const char *str, int j) { for (i=0; i 0) { @@ -380,11 +380,11 @@ static void emit_get_var (REgg *egg, int type, char *out, int idx) { } } -static void emit_trap (REgg *egg) { - r_egg_printf (egg, " int3\n"); +static void emit_trap (RzEgg *egg) { + rz_egg_printf (egg, " int3\n"); } -static void emit_load_ptr(REgg *egg, const char *dst) { +static void emit_load_ptr(RzEgg *egg, const char *dst) { int d = atoi (dst); if (d == 0) { // hack to handle stackvarptrz char *p = strchr (dst, '+'); @@ -394,17 +394,17 @@ static void emit_load_ptr(REgg *egg, const char *dst) { } //eprintf ("emit_load_ptr: HACK\n"); // XXX: 32/64bit care - //r_egg_printf (egg, "# DELTA IS (%s)\n", dst); + //rz_egg_printf (egg, "# DELTA IS (%s)\n", dst); if (attsyntax) { - r_egg_printf (egg, " leal %d(%%"R_BP"), %%"R_AX"\n", d); + rz_egg_printf (egg, " leal %d(%%"R_BP"), %%"R_AX"\n", d); } else { - r_egg_printf (egg, " lea "R_AX", ["R_BP"+%d]\n", d); + rz_egg_printf (egg, " lea "R_AX", ["R_BP"+%d]\n", d); } - //r_egg_printf (egg, " movl %%"R_BP", %%"R_AX"\n"); - //r_egg_printf (egg, " addl $%d, %%"R_AX"\n", d); + //rz_egg_printf (egg, " movl %%"R_BP", %%"R_AX"\n"); + //rz_egg_printf (egg, " addl $%d, %%"R_AX"\n", d); } -static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { +static void emit_branch(RzEgg *egg, char *b, char *g, char *e, char *n, int sz, const char *dst) { char *p, str[64]; char *arg = NULL; char *op = "jz"; @@ -445,54 +445,54 @@ static void emit_branch(REgg *egg, char *b, char *g, char *e, char *n, int sz, c if (*arg == '=') { arg++; /* for <=, >=, ... */ } - p = r_egg_mkvar (egg, str, arg, 0); + p = rz_egg_mkvar (egg, str, arg, 0); if (attsyntax) { - r_egg_printf (egg, " pop %%"R_AX"\n"); /* TODO: add support for more than one arg get arg0 */ - r_egg_printf (egg, " cmp%c %s, %%"R_AX"\n", sz, p); + rz_egg_printf (egg, " pop %%"R_AX"\n"); /* TODO: add support for more than one arg get arg0 */ + rz_egg_printf (egg, " cmp%c %s, %%"R_AX"\n", sz, p); } else { - r_egg_printf (egg, " pop "R_AX"\n"); /* TODO: add support for more than one arg get arg0 */ - r_egg_printf (egg, " cmp "R_AX", %s\n", p); + rz_egg_printf (egg, " pop "R_AX"\n"); /* TODO: add support for more than one arg get arg0 */ + rz_egg_printf (egg, " cmp "R_AX", %s\n", p); } // if (context>0) free (p); - r_egg_printf (egg, " %s %s\n", op, dst); + rz_egg_printf (egg, " %s %s\n", op, dst); } -static void emit_load(REgg *egg, const char *dst, int sz) { +static void emit_load(RzEgg *egg, const char *dst, int sz) { if (attsyntax) { switch (sz) { case 'l': - r_egg_printf (egg, " movl %s, %%"R_AX"\n", dst); - r_egg_printf (egg, " movl (%%"R_AX"), %%"R_AX"\n"); + rz_egg_printf (egg, " movl %s, %%"R_AX"\n", dst); + rz_egg_printf (egg, " movl (%%"R_AX"), %%"R_AX"\n"); break; case 'b': - r_egg_printf (egg, " movl %s, %%"R_AX"\n", dst); - r_egg_printf (egg, " movzb (%%"R_AX"), %%"R_AX"\n"); + rz_egg_printf (egg, " movl %s, %%"R_AX"\n", dst); + rz_egg_printf (egg, " movzb (%%"R_AX"), %%"R_AX"\n"); break; default: // TODO: unhandled?!? - r_egg_printf (egg, " mov%c %s, %%"R_AX"\n", sz, dst); - r_egg_printf (egg, " mov%c (%%"R_AX"), %%"R_AX"\n", sz); + rz_egg_printf (egg, " mov%c %s, %%"R_AX"\n", sz, dst); + rz_egg_printf (egg, " mov%c (%%"R_AX"), %%"R_AX"\n", sz); } } else { switch (sz) { case 'l': - r_egg_printf (egg, " mov "R_AX", %s\n", dst); - r_egg_printf (egg, " mov "R_AX", ["R_AX"]\n"); + rz_egg_printf (egg, " mov "R_AX", %s\n", dst); + rz_egg_printf (egg, " mov "R_AX", ["R_AX"]\n"); break; case 'b': - r_egg_printf (egg, " mov "R_AX", %s\n", dst); - r_egg_printf (egg, " movz "R_AX", ["R_AX"]\n"); + rz_egg_printf (egg, " mov "R_AX", %s\n", dst); + rz_egg_printf (egg, " movz "R_AX", ["R_AX"]\n"); break; default: // TODO: unhandled?!? - r_egg_printf (egg, " mov "R_AX", %s\n", dst); - r_egg_printf (egg, " mov "R_AX", ["R_AX"]\n"); + rz_egg_printf (egg, " mov "R_AX", %s\n", dst); + rz_egg_printf (egg, " mov "R_AX", ["R_AX"]\n"); } } } -static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, const char *p) { +static void emit_mathop(RzEgg *egg, int ch, int vs, int type, const char *eq, const char *p) { char *op; switch(ch) { case '^': op = "xor"; break; @@ -511,7 +511,7 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con if (!p) { p = "%" R_AX; } - r_egg_printf (egg, " %s%c %c%s, %s\n", op, vs, type, eq, p); + rz_egg_printf (egg, " %s%c %c%s, %s\n", op, vs, type, eq, p); } else { if (!eq) { eq = R_AX; @@ -526,18 +526,18 @@ static void emit_mathop(REgg *egg, int ch, int vs, int type, const char *eq, con eprintf (" %s %s, [%s]\n", op, p, eq); #endif if (type == '*') { - r_egg_printf (egg, " %s %s, [%s]\n", op, p, eq); + rz_egg_printf (egg, " %s %s, [%s]\n", op, p, eq); } else { - r_egg_printf (egg, " %s %s, %s\n", op, p, eq); + rz_egg_printf (egg, " %s %s, %s\n", op, p, eq); } } } -static const char* emit_regs(REgg *egg, int idx) { +static const char* emit_regs(RzEgg *egg, int idx) { return regs[idx%R_NGP]; } -static void emit_get_ar (REgg *egg, char *out, int idx) { +static void emit_get_ar (RzEgg *egg, char *out, int idx) { const char *reg = emit_regs (egg, R_REG_AR_OFF + idx); if (reg) { @@ -545,7 +545,7 @@ static void emit_get_ar (REgg *egg, char *out, int idx) { } } -REggEmit EMIT_NAME = { +RzEggEmit EMIT_NAME = { .retvar = R_AX, .arch = R_ARCH, .size = R_SZ, diff --git a/libr/egg/meson.build b/librz/egg/meson.build similarity index 67% rename from libr/egg/meson.build rename to librz/egg/meson.build index 81222c88e1..acd4be777d 100644 --- a/libr/egg/meson.build +++ b/librz/egg/meson.build @@ -1,4 +1,4 @@ -r_egg_sources = [ +rz_egg_sources = [ 'egg.c', 'egg_Cfile.c', 'egg_lang.c', @@ -14,13 +14,13 @@ r_egg_sources = [ 'p/egg_xor.c' ] -r_egg = library('r_egg', r_egg_sources, +rz_egg = library('rz_egg', rz_egg_sources, include_directories: [platform_inc], c_args: library_cflags, dependencies: [ - r_util_dep, - r_asm_dep, - r_syscall_dep, + rz_util_dep, + rz_asm_dep, + rz_syscall_dep, mpc_dep ], install: true, @@ -29,19 +29,19 @@ r_egg = library('r_egg', r_egg_sources, soversion: r2_libversion ) -r_egg_dep = declare_dependency(link_with: r_egg, +rz_egg_dep = declare_dependency(link_with: rz_egg, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_egg, - subdirs: 'libr', +pkgconfig_mod.generate(rz_egg, + subdirs: 'librz', version: r2_version, - name: 'r_egg', - filebase: 'r_egg', + name: 'rz_egg', + filebase: 'rz_egg', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_asm', - 'r_syscall' + 'rz_util', + 'rz_asm', + 'rz_syscall' ], description: 'radare foundation libraries' ) diff --git a/libr/egg/p/egg_bind.c b/librz/egg/p/egg_bind.c similarity index 95% rename from libr/egg/p/egg_bind.c rename to librz/egg/p/egg_bind.c index 2e85dec39c..18200ba695 100644 --- a/libr/egg/p/egg_bind.c +++ b/librz/egg/p/egg_bind.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2013 - pancake */ -#include +#include static unsigned char x86_osx_bind4444[] = @@ -141,12 +141,12 @@ static unsigned char x86_w32_tcp4444[] = "\x7e\xe5\x98\xec\xac\x45\x1b\x13"; -static RBuffer *build (REgg *egg) { - RBuffer *buf = r_buf_new (); +static RBuffer *build (RzEgg *egg) { + RBuffer *buf = rz_buf_new (); const ut8 *sc = NULL; int cd = 0; - char *port = r_egg_option_get (egg, "port"); - //TODO: char *udp = r_egg_option_get (egg, "udp"); + char *port = rz_egg_option_get (egg, "port"); + //TODO: char *udp = rz_egg_option_get (egg, "udp"); switch (egg->os) { case R_EGG_OS_OSX: case R_EGG_OS_DARWIN: @@ -185,9 +185,9 @@ static RBuffer *build (REgg *egg) { break; } if (sc) { - r_buf_set_bytes (buf, sc, strlen ((const char *)sc)); + rz_buf_set_bytes (buf, sc, strlen ((const char *)sc)); if (shell && *shell) { - if (cd) r_buf_write_at (buf, cd, (const ut8*)shell, strlen (shell)+1); + if (cd) rz_buf_write_at (buf, cd, (const ut8*)shell, strlen (shell)+1); else eprintf ("Cannot set shell\n"); } } @@ -197,7 +197,7 @@ static RBuffer *build (REgg *egg) { } //TODO: rename plugin to run -REggPlugin r_egg_plugin_bind = { +RzEggPlugin rz_egg_plugin_bind = { .name = "bind", .type = R_EGG_PLUGIN_SHELLCODE, .desc = "listen port=4444", @@ -205,9 +205,9 @@ REggPlugin r_egg_plugin_bind = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_EGG, - .data = &r_egg_plugin_bind, + .data = &rz_egg_plugin_bind, .version = R2_VERSION }; #endif diff --git a/libr/egg/p/egg_cb.c b/librz/egg/p/egg_cb.c similarity index 100% rename from libr/egg/p/egg_cb.c rename to librz/egg/p/egg_cb.c diff --git a/libr/egg/p/egg_exec.c b/librz/egg/p/egg_exec.c similarity index 86% rename from libr/egg/p/egg_exec.c rename to librz/egg/p/egg_exec.c index e99b7e392e..1e71c94ba2 100644 --- a/libr/egg/p/egg_exec.c +++ b/librz/egg/p/egg_exec.c @@ -1,5 +1,5 @@ /* radare - LGPL - Copyright 2011 pancake<@nopcode.org> */ -#include +#include #if 0 linux setresuid(0,0)+execv(/bin/sh) @@ -55,12 +55,12 @@ static ut8 thumb_linux_binsh[] = "\x01\x30\x8f\xe2\x13\xff\x2f\xe1\x78\x46\x0c\x30\xc0\x46\x01\x90" "\x49\x1a\x92\x1a\x0b\x27\x01\xdf\x2f\x62\x69\x6e\x2f\x73\x68"; // "/bin/sh"; -static RBuffer *build (REgg *egg) { - RBuffer *buf = r_buf_new (); +static RBuffer *build (RzEgg *egg) { + RBuffer *buf = rz_buf_new (); const ut8 *sc = NULL; int cd = 0; - char *shell = r_egg_option_get (egg, "cmd"); - char *suid = r_egg_option_get (egg, "suid"); + char *shell = rz_egg_option_get (egg, "cmd"); + char *suid = rz_egg_option_get (egg, "suid"); // TODO: last char must not be \x00 .. or what? :D if (suid && *suid=='f') { // false free (suid); @@ -110,11 +110,11 @@ static RBuffer *build (REgg *egg) { if (!shell) { break; } - r_str_ncpy (shell, (char *)&b, sizeof (st64)); + rz_str_ncpy (shell, (char *)&b, sizeof (st64)); shell[sizeof (st64)] = 0; cd = 4; - r_buf_set_bytes (buf, sc, strlen ((const char *)sc)); - r_buf_write_at (buf, cd, (const ut8 *)shell, sizeof (st64)); + rz_buf_set_bytes (buf, sc, strlen ((const char *)sc)); + rz_buf_write_at (buf, cd, (const ut8 *)shell, sizeof (st64)); sc = 0; } break; @@ -142,10 +142,10 @@ static RBuffer *build (REgg *egg) { } if (sc) { - r_buf_set_bytes (buf, sc, strlen ((const char *)sc)); + rz_buf_set_bytes (buf, sc, strlen ((const char *)sc)); if (shell && *shell) { if (cd) { - r_buf_write_at (buf, cd, (const ut8 *)shell, strlen (shell) + 1); + rz_buf_write_at (buf, cd, (const ut8 *)shell, strlen (shell) + 1); } else { eprintf ("Cannot set shell\n"); } @@ -157,7 +157,7 @@ static RBuffer *build (REgg *egg) { } //TODO: rename plugin to run -REggPlugin r_egg_plugin_exec = { +RzEggPlugin rz_egg_plugin_exec = { .name = "exec", .type = R_EGG_PLUGIN_SHELLCODE, .desc = "execute cmd=/bin/sh suid=false", @@ -165,9 +165,9 @@ REggPlugin r_egg_plugin_exec = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_EGG, - .data = &r_egg_plugin_exec, + .data = &rz_egg_plugin_exec, .version = R2_VERSION }; #endif diff --git a/libr/egg/p/egg_reverse.c b/librz/egg/p/egg_reverse.c similarity index 83% rename from libr/egg/p/egg_reverse.c rename to librz/egg/p/egg_reverse.c index 039abe57dc..8dfc195b22 100644 --- a/libr/egg/p/egg_reverse.c +++ b/librz/egg/p/egg_reverse.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2013 - pancake */ -#include +#include unsigned long armle_osx_reverse[]= { @@ -26,12 +26,12 @@ unsigned char x86_freebsd_reverse[] = "\x43\x7f\x00\x00\x01\x2f\x62\x69\x6e\x2f\x73\x68"; -static RBuffer *build (REgg *egg) { - RBuffer *buf = r_buf_new (); +static RBuffer *build (RzEgg *egg) { + RBuffer *buf = rz_buf_new (); const ut8 *sc = NULL; int cd = 0; - char *port = r_egg_option_get (egg, "port"); - //TODO: char *udp = r_egg_option_get (egg, "udp"); + char *port = rz_egg_option_get (egg, "port"); + //TODO: char *udp = rz_egg_option_get (egg, "udp"); switch (egg->os) { case R_EGG_OS_OSX: case R_EGG_OS_DARWIN: @@ -57,9 +57,9 @@ static RBuffer *build (REgg *egg) { break; } if (sc) { - r_buf_set_bytes (buf, sc, strlen ((const char *)sc)); + rz_buf_set_bytes (buf, sc, strlen ((const char *)sc)); if (shell && *shell) { - if (cd) r_buf_write_at (buf, cd, (const ut8*)shell, strlen (shell)+1); + if (cd) rz_buf_write_at (buf, cd, (const ut8*)shell, strlen (shell)+1); else eprintf ("Cannot set shell\n"); } } @@ -69,7 +69,7 @@ static RBuffer *build (REgg *egg) { } //TODO: rename plugin to run -REggPlugin r_egg_plugin_bind = { +RzEggPlugin rz_egg_plugin_bind = { .name = "bind", .type = R_EGG_PLUGIN_SHELLCODE, .desc = "listen port=4444", @@ -77,9 +77,9 @@ REggPlugin r_egg_plugin_bind = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_EGG, - .data = &r_egg_plugin_bind, + .data = &rz_egg_plugin_bind, .version = R2_VERSION }; #endif diff --git a/libr/egg/p/egg_shya.c b/librz/egg/p/egg_shya.c similarity index 68% rename from libr/egg/p/egg_shya.c rename to librz/egg/p/egg_shya.c index 23da6f2a43..03daf0977e 100644 --- a/libr/egg/p/egg_shya.c +++ b/librz/egg/p/egg_shya.c @@ -11,17 +11,17 @@ - virtual machine */ -static RBuffer *build (REgg *egg) { - RBuffer *buf = r_buf_new (); - char *key = r_egg_option_get (egg, "key"); - char *seed = r_egg_option_get (egg, "seed"); +static RBuffer *build (RzEgg *egg) { + RBuffer *buf = rz_buf_new (); + char *key = rz_egg_option_get (egg, "key"); + char *seed = rz_egg_option_get (egg, "seed"); eprintf ("TODO: shoorisu yagana shellcode encoder\n"); free (key); free (seed); return buf; } -REggPlugin r_egg_plugin_shya = { +RzEggPlugin rz_egg_plugin_shya = { .name = "shya", .type = R_EGG_PLUGIN_ENCODER, .desc = "shoorisu yagana", @@ -30,9 +30,9 @@ REggPlugin r_egg_plugin_shya = { #if 0 #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_EGG, - .data = &r_egg_plugin_shya, + .data = &rz_egg_plugin_shya, .version = R2_VERSION }; #endif diff --git a/libr/egg/p/egg_xor.c b/librz/egg/p/egg_xor.c similarity index 69% rename from libr/egg/p/egg_xor.c rename to librz/egg/p/egg_xor.c index abdbc9b596..fd868c0dd7 100644 --- a/libr/egg/p/egg_xor.c +++ b/librz/egg/p/egg_xor.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2011-2016 - pancake */ /* based on @santitox patch */ -#include +#include #define DEFAULT_XOR_KEY "0xFF" -static RBuffer *build (REgg *egg) { +static RBuffer *build (RzEgg *egg) { RBuffer *buf, *sc; ut8 aux[32], nkey; const char *default_key = DEFAULT_XOR_KEY; - char *key = r_egg_option_get (egg, "key"); + char *key = rz_egg_option_get (egg, "key"); int i; if (!key || !*key) { @@ -17,7 +17,7 @@ static RBuffer *build (REgg *egg) { key = strdup (default_key); eprintf ("XOR key not provided. Using (%s) as the key\n", key); } - nkey = r_num_math (NULL, key); + nkey = rz_num_math (NULL, key); if (nkey == 0) { eprintf ("Invalid key (%s)\n", key); free (key); @@ -27,32 +27,32 @@ static RBuffer *build (REgg *egg) { nkey &= 0xff; eprintf ("xor key wrapped to (%d)\n", nkey); } - if (r_buf_size (egg->bin) > 240) { // XXX + if (rz_buf_size (egg->bin) > 240) { // XXX eprintf ("shellcode is too long :(\n"); free (key); return NULL; } sc = egg->bin; // hack - if (!r_buf_size (sc)) { + if (!rz_buf_size (sc)) { eprintf ("No shellcode found!\n"); free (key); return NULL; } - for (i = 0; i %02x\n", sc->buf[i], sc->buf[i] ^nkey); - if ((r_buf_read8_at (sc, i) ^ nkey)==0) { + if ((rz_buf_read8_at (sc, i) ^ nkey)==0) { eprintf ("This xor key generates null bytes. Try again.\n"); free (key); return NULL; } } - buf = r_buf_new (); - sc = r_buf_new (); + buf = rz_buf_new (); + sc = rz_buf_new (); // TODO: alphanumeric? :D // This is the x86-32/64 xor encoder - r_buf_append_buf (sc, egg->bin); + rz_buf_append_buf (sc, egg->bin); if (egg->arch == R_SYS_ARCH_X86) { #define STUBLEN 18 ut8 stub[STUBLEN] = @@ -66,29 +66,29 @@ static RBuffer *build (REgg *egg) { "\xe2\xf9"; // loop loop0 // ecx = length aux[0] = 0x6a; // push length - aux[1] = r_buf_size (sc); + aux[1] = rz_buf_size (sc); aux[2] = 0x59; // pop ecx // ebx = key aux[3] = 0x6a; // push key aux[4] = nkey; aux[5] = 0x5b; // pop ebx - r_buf_set_bytes (buf, aux, 6); + rz_buf_set_bytes (buf, aux, 6); - r_buf_append_bytes (buf, stub, STUBLEN); + rz_buf_append_bytes (buf, stub, STUBLEN); - for (i = 0; i -#include -#include +#include +#include +#include #include -R_LIB_VERSION(r_flag); +R_LIB_VERSION(rz_flag); -#define IS_FI_NOTIN_SPACE(f, i) (r_flag_space_cur (f) && (i)->space != r_flag_space_cur (f)) +#define IS_FI_NOTIN_SPACE(f, i) (rz_flag_space_cur (f) && (i)->space != rz_flag_space_cur (f)) #define IS_FI_IN_SPACE(fi, sp) (!(sp) || (fi)->space == (sp)) #define STRDUP_OR_NULL(s) (!R_STR_ISEMPTY (s)? strdup (s): NULL) static const char *str_callback(RNum *user, ut64 off, int *ok) { - RFlag *f = (RFlag*)user; + RzFlag *f = (RzFlag*)user; if (ok) { *ok = 0; } if (f) { - const RList *list = r_flag_get_list (f, off); - RFlagItem *item = r_list_get_top (list); + const RzList *list = rz_flag_get_list (f, off); + RzFlagItem *item = rz_list_get_top (list); if (item) { if (ok) { *ok = true; @@ -30,13 +30,13 @@ static const char *str_callback(RNum *user, ut64 off, int *ok) { } static void flag_skiplist_free(void *data) { - RFlagsAtOffset *item = (RFlagsAtOffset *)data; - r_list_free (item->flags); + RzFlagsAtOffset *item = (RzFlagsAtOffset *)data; + rz_list_free (item->flags); free (data); } static int flag_skiplist_cmp(const void *va, const void *vb) { - const RFlagsAtOffset *a = (RFlagsAtOffset *)va, *b = (RFlagsAtOffset *)vb; + const RzFlagsAtOffset *a = (RzFlagsAtOffset *)va, *b = (RzFlagsAtOffset *)vb; if (a->off == b->off) { return 0; } @@ -44,11 +44,11 @@ static int flag_skiplist_cmp(const void *va, const void *vb) { } static ut64 num_callback(RNum *user, const char *name, int *ok) { - RFlag *f = (RFlag *)user; + RzFlag *f = (RzFlag *)user; if (ok) { *ok = 0; } - RFlagItem *item = ht_pp_find (f->ht_name, name, NULL); + RzFlagItem *item = ht_pp_find (f->ht_name, name, NULL); if (item) { // NOTE: to avoid warning infinite loop here we avoid recursivity if (item->alias) { @@ -62,13 +62,13 @@ static ut64 num_callback(RNum *user, const char *name, int *ok) { return 0LL; } -static void free_item_realname(RFlagItem *item) { +static void free_item_realname(RzFlagItem *item) { if (item->name != item->realname) { free (item->realname); } } -static void free_item_name(RFlagItem *item) { +static void free_item_name(RzFlagItem *item) { if (item->name != item->realname) { free (item->name); } @@ -78,45 +78,45 @@ static void free_item_name(RFlagItem *item) { dir == -1 -> result <= off dir == 0 -> result == off dir == 1 -> result >= off*/ -static RFlagsAtOffset *r_flag_get_nearest_list(RFlag *f, ut64 off, int dir) { - RFlagsAtOffset key = { .off = off }; - RFlagsAtOffset *flags = (dir >= 0) - ? r_skiplist_get_geq (f->by_off, &key) - : r_skiplist_get_leq (f->by_off, &key); +static RzFlagsAtOffset *rz_flag_get_nearest_list(RzFlag *f, ut64 off, int dir) { + RzFlagsAtOffset key = { .off = off }; + RzFlagsAtOffset *flags = (dir >= 0) + ? rz_skiplist_get_geq (f->by_off, &key) + : rz_skiplist_get_leq (f->by_off, &key); return (dir == 0 && flags && flags->off != off)? NULL: flags; } -static void remove_offsetmap(RFlag *f, RFlagItem *item) { - r_return_if_fail (f && item); - RFlagsAtOffset *flags = r_flag_get_nearest_list (f, item->offset, 0); +static void remove_offsetmap(RzFlag *f, RzFlagItem *item) { + rz_return_if_fail (f && item); + RzFlagsAtOffset *flags = rz_flag_get_nearest_list (f, item->offset, 0); if (flags) { - r_list_delete_data (flags->flags, item); - if (r_list_empty (flags->flags)) { - r_skiplist_delete (f->by_off, flags); + rz_list_delete_data (flags->flags, item); + if (rz_list_empty (flags->flags)) { + rz_skiplist_delete (f->by_off, flags); } } } -static RFlagsAtOffset *flags_at_offset(RFlag *f, ut64 off) { - RFlagsAtOffset *res = r_flag_get_nearest_list (f, off, 0); +static RzFlagsAtOffset *flags_at_offset(RzFlag *f, ut64 off) { + RzFlagsAtOffset *res = rz_flag_get_nearest_list (f, off, 0); if (res) { return res; } // there is no existing flagsAtOffset, we create one now - res = R_NEW (RFlagsAtOffset); + res = R_NEW (RzFlagsAtOffset); if (!res) { return NULL; } - res->flags = r_list_new (); + res->flags = rz_list_new (); if (!res->flags) { free (res); return NULL; } res->off = off; - r_skiplist_insert (f->by_off, res); + rz_skiplist_insert (f->by_off, res); return res; } @@ -126,38 +126,38 @@ static char *filter_item_name(const char *name) { return NULL; } - r_str_trim (res); - r_name_filter (res, 0); + rz_str_trim (res); + rz_name_filter (res, 0); return res; } -static void set_name(RFlagItem *item, char *name) { +static void set_name(RzFlagItem *item, char *name) { free_item_name (item); item->name = name; free_item_realname (item); item->realname = item->name; } -static bool update_flag_item_offset(RFlag *f, RFlagItem *item, ut64 newoff, bool is_new, bool force) { +static bool update_flag_item_offset(RzFlag *f, RzFlagItem *item, ut64 newoff, bool is_new, bool force) { if (item->offset != newoff || force) { if (!is_new) { remove_offsetmap (f, item); } item->offset = newoff; - RFlagsAtOffset *flagsAtOffset = flags_at_offset (f, newoff); + RzFlagsAtOffset *flagsAtOffset = flags_at_offset (f, newoff); if (!flagsAtOffset) { return false; } - r_list_append (flagsAtOffset->flags, item); + rz_list_append (flagsAtOffset->flags, item); return true; } return false; } -static bool update_flag_item_name(RFlag *f, RFlagItem *item, const char *newname, bool force) { +static bool update_flag_item_name(RzFlag *f, RzFlagItem *item, const char *newname, bool force) { if (!f || !item || !newname) { return false; } @@ -181,48 +181,48 @@ static bool update_flag_item_name(RFlag *f, RFlagItem *item, const char *newname static void ht_free_flag(HtPPKv *kv) { free (kv->key); - r_flag_item_free (kv->value); + rz_flag_item_free (kv->value); } -static bool count_flags(RFlagItem *fi, void *user) { +static bool count_flags(RzFlagItem *fi, void *user) { int *count = (int *)user; (*count)++; return true; } -static bool unset_flags_space(RFlagItem *fi, void *user) { +static bool unset_flags_space(RzFlagItem *fi, void *user) { fi->space = NULL; return true; } static void count_flags_in_space(REvent *ev, int type, void *user, void *data) { RSpaces *sp = (RSpaces *)ev->user; - RFlag *f = container_of (sp, RFlag, spaces); + RzFlag *f = container_of (sp, RzFlag, spaces); RSpaceEvent *spe = (RSpaceEvent *)data; - r_flag_foreach_space (f, spe->data.count.space, count_flags, &spe->res); + rz_flag_foreach_space (f, spe->data.count.space, count_flags, &spe->res); } static void unset_flagspace(REvent *ev, int type, void *user, void *data) { RSpaces *sp = (RSpaces *)ev->user; - RFlag *f = container_of (sp, RFlag, spaces); + RzFlag *f = container_of (sp, RzFlag, spaces); const RSpaceEvent *spe = (const RSpaceEvent *)data; - r_flag_foreach_space (f, spe->data.unset.space, unset_flags_space, NULL); + rz_flag_foreach_space (f, spe->data.unset.space, unset_flags_space, NULL); } -static void new_spaces(RFlag *f) { - r_spaces_init (&f->spaces, "fs"); - r_event_hook (f->spaces.event, R_SPACE_EVENT_COUNT, count_flags_in_space, NULL); - r_event_hook (f->spaces.event, R_SPACE_EVENT_UNSET, unset_flagspace, NULL); +static void new_spaces(RzFlag *f) { + rz_spaces_init (&f->spaces, "fs"); + rz_event_hook (f->spaces.event, R_SPACE_EVENT_COUNT, count_flags_in_space, NULL); + rz_event_hook (f->spaces.event, R_SPACE_EVENT_UNSET, unset_flagspace, NULL); } -R_API RFlag *r_flag_new(void) { - RFlag *f = R_NEW0 (RFlag); +RZ_API RzFlag *rz_flag_new(void) { + RzFlag *f = R_NEW0 (RzFlag); if (!f) { return NULL; } - f->num = r_num_new (&num_callback, &str_callback, f); + f->num = rz_num_new (&num_callback, &str_callback, f); if (!f->num) { - r_flag_free (f); + rz_flag_free (f); return NULL; } f->base = 0; @@ -234,20 +234,20 @@ R_API RFlag *r_flag_new(void) { #endif f->tags = sdb_new0 (); f->ht_name = ht_pp_new (NULL, ht_free_flag, NULL); - f->by_off = r_skiplist_new (flag_skiplist_free, flag_skiplist_cmp); + f->by_off = rz_skiplist_new (flag_skiplist_free, flag_skiplist_cmp); #if R_FLAG_ZONE_USE_SDB sdb_free (f->zones); #else - r_list_free (f->zones); + rz_list_free (f->zones); #endif new_spaces(f); return f; } -R_API RFlagItem *r_flag_item_clone(RFlagItem *item) { - r_return_val_if_fail (item, NULL); +RZ_API RzFlagItem *rz_flag_item_clone(RzFlagItem *item) { + rz_return_val_if_fail (item, NULL); - RFlagItem *n = R_NEW0 (RFlagItem); + RzFlagItem *n = R_NEW0 (RzFlagItem); if (!n) { return NULL; } @@ -262,7 +262,7 @@ R_API RFlagItem *r_flag_item_clone(RFlagItem *item) { return n; } -R_API void r_flag_item_free(RFlagItem *item) { +RZ_API void rz_flag_item_free(RzFlagItem *item) { if (!item) { return; } @@ -275,26 +275,26 @@ R_API void r_flag_item_free(RFlagItem *item) { free (item); } -R_API RFlag *r_flag_free(RFlag *f) { - r_return_val_if_fail (f, NULL); - r_skiplist_free (f->by_off); +RZ_API RzFlag *rz_flag_free(RzFlag *f) { + rz_return_val_if_fail (f, NULL); + rz_skiplist_free (f->by_off); ht_pp_free (f->ht_name); sdb_free (f->tags); - r_spaces_fini (&f->spaces); - r_num_free (f->num); - r_list_free (f->zones); + rz_spaces_fini (&f->spaces); + rz_num_free (f->num); + rz_list_free (f->zones); free (f); return NULL; } -static bool print_flag_name(RFlagItem *fi, void *user) { - RFlag *flag = (RFlag *)user; +static bool print_flag_name(RzFlagItem *fi, void *user) { + RzFlag *flag = (RzFlag *)user; flag->cb_printf ("%s\n", fi->name); return true; } struct print_flag_t { - RFlag *f; + RzFlag *f; PJ *pj; bool in_range; ut64 range_from; @@ -304,7 +304,7 @@ struct print_flag_t { const char *pfx; }; -static bool print_flag_json(RFlagItem *flag, void *user) { +static bool print_flag_json(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { return true; @@ -327,7 +327,7 @@ static bool print_flag_json(RFlagItem *flag, void *user) { return true; } -static bool print_flag_rad(RFlagItem *flag, void *user) { +static bool print_flag_rad(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; char *comment_b64 = NULL, *tmp = NULL; if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { @@ -338,10 +338,10 @@ static bool print_flag_rad(RFlagItem *flag, void *user) { u->f->cb_printf ("fs %s\n", u->fs? u->fs->name: "*"); } if (flag->comment && *flag->comment) { - comment_b64 = r_base64_encode_dyn (flag->comment, -1); + comment_b64 = rz_base64_encode_dyn (flag->comment, -1); // prefix the armored string with "base64:" if (comment_b64) { - tmp = r_str_newf ("base64:%s", comment_b64); + tmp = rz_str_newf ("base64:%s", comment_b64); free (comment_b64); comment_b64 = tmp; } @@ -363,7 +363,7 @@ static bool print_flag_rad(RFlagItem *flag, void *user) { return true; } -static bool print_flag_orig_name(RFlagItem *flag, void *user) { +static bool print_flag_orig_name(RzFlagItem *flag, void *user) { struct print_flag_t *u = (struct print_flag_t *)user; if (u->in_range && (flag->offset < u->range_from || flag->offset >= u->range_to)) { return true; @@ -378,9 +378,9 @@ static bool print_flag_orig_name(RFlagItem *flag, void *user) { return true; } -/* print with r_cons the flag items in the flag f, given as a parameter */ -R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { - r_return_if_fail (f); +/* print with rz_cons the flag items in the flag f, given as a parameter */ +RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx) { + rz_return_if_fail (f); bool in_range = false; ut64 range_from = UT64_MAX; ut64 range_to = UT64_MAX; @@ -389,11 +389,11 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { sp = strchr (arg, ' '); if (sp) { *sp++ = 0; - range_from = r_num_math (f->num, arg); - range_to = r_num_math (f->num, sp); + range_from = rz_num_math (f->num, arg); + range_to = rz_num_math (f->num, sp); } else { const int bsize = 4096; - range_from = r_num_math (f->num, arg); + range_from = rz_num_math (f->num, arg); range_to = range_from + bsize; } in_range = true; @@ -408,7 +408,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { switch (rad) { case 'q': - r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_name, f); + rz_flag_foreach_space (f, rz_flag_space_cur (f), print_flag_name, f); break; case 'j': { PJ *pj = pj_new (); @@ -421,7 +421,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { .real = false }; pj_a (pj); - r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_json, &u); + rz_flag_foreach_space (f, rz_flag_space_cur (f), print_flag_json, &u); pj_end (pj); f->cb_printf ("%s\n", pj_string (pj)); pj_free (pj); @@ -437,7 +437,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { .fs = NULL, .pfx = pfx }; - r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_rad, &u); + rz_flag_foreach_space (f, rz_flag_space_cur (f), print_flag_rad, &u); break; } default: @@ -450,7 +450,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { .range_to = range_to, .real = (rad == 'n') }; - r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_orig_name, &u); + rz_flag_foreach_space (f, rz_flag_space_cur (f), print_flag_orig_name, &u); } else { PJ *pj = pj_new (); struct print_flag_t u = { @@ -462,7 +462,7 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { .real = true }; pj_a (pj); - r_flag_foreach_space (f, r_flag_space_cur (f), print_flag_json, &u); + rz_flag_foreach_space (f, rz_flag_space_cur (f), print_flag_json, &u); pj_end (pj); f->cb_printf ("%s\n", pj_string (pj)); pj_free (pj); @@ -472,23 +472,23 @@ R_API void r_flag_list(RFlag *f, int rad, const char *pfx) { } } -static RFlagItem *evalFlag(RFlag *f, RFlagItem *item) { - r_return_val_if_fail (f && item, NULL); +static RzFlagItem *evalFlag(RzFlag *f, RzFlagItem *item) { + rz_return_val_if_fail (f && item, NULL); if (item->alias) { - item->offset = r_num_math (f->num, item->alias); + item->offset = rz_num_math (f->num, item->alias); } return item; } /* return true if flag.* exist at offset. Otherwise, false is returned. * For example (f, "sym", 3, 0x1000)*/ -R_API bool r_flag_exist_at(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off) { - r_return_val_if_fail (f && flag_prefix, NULL); - RListIter *iter = NULL; - RFlagItem *item = NULL; - const RList *list = r_flag_get_list (f, off); +RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off) { + rz_return_val_if_fail (f && flag_prefix, NULL); + RzListIter *iter = NULL; + RzFlagItem *item = NULL; + const RzList *list = rz_flag_get_list (f, off); if (list) { - r_list_foreach (list, iter, item) { + rz_list_foreach (list, iter, item) { if (item->name && !strncmp (item->name, flag_prefix, fp_size)) { return true; } @@ -497,43 +497,43 @@ R_API bool r_flag_exist_at(RFlag *f, const char *flag_prefix, ut16 fp_size, ut64 return false; } -/* return the flag item with name "name" in the RFlag "f", if it exists. +/* return the flag item with name "name" in the RzFlag "f", if it exists. * Otherwise, NULL is returned. */ -R_API RFlagItem *r_flag_get(RFlag *f, const char *name) { - r_return_val_if_fail (f, NULL); - RFlagItem *r = ht_pp_find (f->ht_name, name, NULL); +RZ_API RzFlagItem *rz_flag_get(RzFlag *f, const char *name) { + rz_return_val_if_fail (f, NULL); + RzFlagItem *r = ht_pp_find (f->ht_name, name, NULL); return r? evalFlag (f, r): NULL; } /* return the first flag item that can be found at offset "off", or NULL otherwise */ -R_API RFlagItem *r_flag_get_i(RFlag *f, ut64 off) { - r_return_val_if_fail (f, NULL); - const RList *list = r_flag_get_list (f, off); - return list? evalFlag (f, r_list_get_top (list)): NULL; +RZ_API RzFlagItem *rz_flag_get_i(RzFlag *f, ut64 off) { + rz_return_val_if_fail (f, NULL); + const RzList *list = rz_flag_get_list (f, off); + return list? evalFlag (f, rz_list_get_top (list)): NULL; } /* return the first flag that matches an offset ordered by the order of * operands to the function. * Pass in the name of each space, in order, followed by a NULL */ -R_API RFlagItem *r_flag_get_by_spaces(RFlag *f, ut64 off, ...) { - r_return_val_if_fail (f, NULL); +RZ_API RzFlagItem *rz_flag_get_by_spaces(RzFlag *f, ut64 off, ...) { + rz_return_val_if_fail (f, NULL); - const RList *list = r_flag_get_list (f, off); - RFlagItem *ret = NULL; + const RzList *list = rz_flag_get_list (f, off); + RzFlagItem *ret = NULL; const char *spacename; RSpace **spaces; - RListIter *iter; - RFlagItem *flg; + RzListIter *iter; + RzFlagItem *flg; va_list ap, aq; size_t n_spaces = 0, i; va_start (ap, off); // some quick checks for common cases - if (r_list_empty (list)) { + if (rz_list_empty (list)) { goto beach; } - if (r_list_length (list) == 1) { - ret = r_list_get_top (list); + if (rz_list_length (list) == 1) { + ret = rz_list_get_top (list); goto beach; } @@ -551,7 +551,7 @@ R_API RFlagItem *r_flag_get_by_spaces(RFlag *f, ut64 off, ...) { spaces = R_NEWS (RSpace *, n_spaces); spacename = va_arg (ap, const char *); while (spacename) { - RSpace *space = r_flag_space_get (f, spacename); + RSpace *space = rz_flag_space_get (f, spacename); if (space) { spaces[i++] = space; } @@ -560,7 +560,7 @@ R_API RFlagItem *r_flag_get_by_spaces(RFlag *f, ut64 off, ...) { n_spaces = i; ut64 min_space_i = n_spaces + 1; - r_list_foreach (list, iter, flg) { + rz_list_foreach (list, iter, flg) { // get the "priority" of the flag flagspace and // check if better than what we found so far for (i = 0; i < n_spaces; i++) { @@ -597,18 +597,18 @@ static bool isFunctionFlag(const char *n) { /* returns the last flag item defined before or at the given offset. * NULL is returned if such a item is not found. */ -R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest) { - r_return_val_if_fail (f, NULL); +RZ_API RzFlagItem *rz_flag_get_at(RzFlag *f, ut64 off, bool closest) { + rz_return_val_if_fail (f, NULL); - RFlagItem *nice = NULL; - RListIter *iter; - const RFlagsAtOffset *flags_at = r_flag_get_nearest_list (f, off, -1); + RzFlagItem *nice = NULL; + RzListIter *iter; + const RzFlagsAtOffset *flags_at = rz_flag_get_nearest_list (f, off, -1); if (!flags_at) { return NULL; } if (flags_at->off == off) { - RFlagItem *item; - r_list_foreach (flags_at->flags, iter, item) { + RzFlagItem *item; + rz_list_foreach (flags_at->flags, iter, item) { if (IS_FI_NOTIN_SPACE (f, item)) { continue; } @@ -629,8 +629,8 @@ R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest) { return NULL; } while (!nice && flags_at) { - RFlagItem *item; - r_list_foreach (flags_at->flags, iter, item) { + RzFlagItem *item; + rz_list_foreach (flags_at->flags, iter, item) { if (IS_FI_NOTIN_SPACE (f, item)) { continue; } @@ -642,7 +642,7 @@ R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest) { break; } if (!nice && flags_at->off) { - flags_at = r_flag_get_nearest_list (f, flags_at->off - 1, -1); + flags_at = rz_flag_get_nearest_list (f, flags_at->off - 1, -1); } else { flags_at = NULL; } @@ -650,36 +650,36 @@ R_API RFlagItem *r_flag_get_at(RFlag *f, ut64 off, bool closest) { return nice? evalFlag (f, nice): NULL; } -static bool append_to_list(RFlagItem *fi, void *user) { - RList *ret = (RList *)user; - r_list_append (ret, fi); +static bool append_to_list(RzFlagItem *fi, void *user) { + RzList *ret = (RzList *)user; + rz_list_append (ret, fi); return true; } -R_API RList *r_flag_all_list(RFlag *f, bool by_space) { - RList *ret = r_list_new (); +RZ_API RzList *rz_flag_all_list(RzFlag *f, bool by_space) { + RzList *ret = rz_list_new (); if (!ret) { return NULL; } - RSpace *cur = by_space? r_flag_space_cur (f): NULL; - r_flag_foreach_space (f, cur, append_to_list, ret); + RSpace *cur = by_space? rz_flag_space_cur (f): NULL; + rz_flag_foreach_space (f, cur, append_to_list, ret); return ret; } /* return the list of flag items that are associated with a given offset */ -R_API const RList* /**/ r_flag_get_list(RFlag *f, ut64 off) { - const RFlagsAtOffset *item = r_flag_get_nearest_list (f, off, 0); +RZ_API const RzList* /**/ rz_flag_get_list(RzFlag *f, ut64 off) { + const RzFlagsAtOffset *item = rz_flag_get_nearest_list (f, off, 0); return item ? item->flags : NULL; } -R_API char *r_flag_get_liststr(RFlag *f, ut64 off) { - RFlagItem *fi; - RListIter *iter; - const RList *list = r_flag_get_list (f, off); +RZ_API char *rz_flag_get_liststr(RzFlag *f, ut64 off) { + RzFlagItem *fi; + RzListIter *iter; + const RzList *list = rz_flag_get_list (f, off); char *p = NULL; - r_list_foreach (list, iter, fi) { - p = r_str_appendf (p, "%s%s", + rz_list_foreach (list, iter, fi) { + p = rz_str_appendf (p, "%s%s", fi->realname, iter->n? ",": ":"); } return p; @@ -687,10 +687,10 @@ R_API char *r_flag_get_liststr(RFlag *f, ut64 off) { // Set a new flag named `name` at offset `off`. If there's already a flag with // the same name, slightly change the name by appending ".%d" as suffix -R_API RFlagItem *r_flag_set_next(RFlag *f, const char *name, ut64 off, ut32 size) { - r_return_val_if_fail (f && name, NULL); - if (!r_flag_get (f, name)) { - return r_flag_set (f, name, off, size); +RZ_API RzFlagItem *rz_flag_set_next(RzFlag *f, const char *name, ut64 off, ut32 size) { + rz_return_val_if_fail (f && name, NULL); + if (!rz_flag_get (f, name)) { + return rz_flag_set (f, name, off, size); } int i, newNameSize = strlen (name); char *newName = malloc (newNameSize + 16); @@ -700,8 +700,8 @@ R_API RFlagItem *r_flag_set_next(RFlag *f, const char *name, ut64 off, ut32 size strcpy (newName, name); for (i = 0; ; i++) { snprintf (newName + newNameSize, 15, ".%d", i); - if (!r_flag_get (f, newName)) { - RFlagItem *fi = r_flag_set (f, newName, off, size); + if (!rz_flag_get (f, newName)) { + RzFlagItem *fi = rz_flag_set (f, newName, off, size); if (fi) { free (newName); return fi; @@ -714,8 +714,8 @@ R_API RFlagItem *r_flag_set_next(RFlag *f, const char *name, ut64 off, ut32 size /* create or modify an existing flag item with the given name and parameters. * The realname of the item will be the same as the name. * NULL is returned in case of any errors during the process. */ -R_API RFlagItem *r_flag_set(RFlag *f, const char *name, ut64 off, ut32 size) { - r_return_val_if_fail (f && name && *name, NULL); +RZ_API RzFlagItem *rz_flag_set(RzFlag *f, const char *name, ut64 off, ut32 size) { + rz_return_val_if_fail (f && name && *name, NULL); bool is_new = false; char *itemname = filter_item_name (name); @@ -723,7 +723,7 @@ R_API RFlagItem *r_flag_set(RFlag *f, const char *name, ut64 off, ut32 size) { return NULL; } - RFlagItem *item = r_flag_get (f, itemname); + RzFlagItem *item = rz_flag_get (f, itemname); free (itemname); if (item && item->offset == off) { item->size = size; @@ -731,48 +731,48 @@ R_API RFlagItem *r_flag_set(RFlag *f, const char *name, ut64 off, ut32 size) { } if (!item) { - item = R_NEW0 (RFlagItem); + item = R_NEW0 (RzFlagItem); if (!item) { goto err; } is_new = true; } - item->space = r_flag_space_cur (f); + item->space = rz_flag_space_cur (f); item->size = size; update_flag_item_offset (f, item, off + f->base, is_new, true); update_flag_item_name (f, item, name, true); return item; err: - r_flag_item_free (item); + rz_flag_item_free (item); return NULL; } /* add/replace/remove the alias of a flag item */ -R_API void r_flag_item_set_alias(RFlagItem *item, const char *alias) { - r_return_if_fail (item); +RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias) { + rz_return_if_fail (item); free (item->alias); item->alias = R_STR_ISEMPTY (alias)? NULL: strdup (alias); } /* add/replace/remove the comment of a flag item */ -R_API void r_flag_item_set_comment(RFlagItem *item, const char *comment) { - r_return_if_fail (item); +RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment) { + rz_return_if_fail (item); free (item->comment); item->comment = R_STR_ISEMPTY (comment)? NULL: strdup (comment); } /* add/replace/remove the realname of a flag item */ -R_API void r_flag_item_set_realname(RFlagItem *item, const char *realname) { - r_return_if_fail (item); +RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname) { + rz_return_if_fail (item); free_item_realname (item); item->realname = R_STR_ISEMPTY (realname)? NULL: strdup (realname); } /* add/replace/remove the color of a flag item */ -R_API const char *r_flag_item_set_color(RFlagItem *item, const char *color) { - r_return_val_if_fail (item, NULL); +RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color) { + rz_return_val_if_fail (item, NULL); free (item->color); item->color = (color && *color) ? strdup (color) : NULL; return item->color; @@ -780,8 +780,8 @@ R_API const char *r_flag_item_set_color(RFlagItem *item, const char *color) { /* change the name of a flag item, if the new name is available. * true is returned if everything works well, false otherwise */ -R_API int r_flag_rename(RFlag *f, RFlagItem *item, const char *name) { - r_return_val_if_fail (f && item && name && *name, false); +RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name) { + rz_return_val_if_fail (f && item && name && *name, false); return update_flag_item_name (f, item, name, false); } @@ -789,8 +789,8 @@ R_API int r_flag_rename(RFlag *f, RFlagItem *item, const char *name) { * returns true if the item is successfully unset, false otherwise. * * NOTE: the item is freed. */ -R_API bool r_flag_unset(RFlag *f, RFlagItem *item) { - r_return_val_if_fail (f && item, false); +RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item) { + rz_return_val_if_fail (f && item, false); remove_offsetmap (f, item); ht_pp_delete (f->ht_name, item->name); return true; @@ -798,26 +798,26 @@ R_API bool r_flag_unset(RFlag *f, RFlagItem *item) { /* unset the first flag item found at offset off. * return true if such a flag is found and unset, false otherwise. */ -R_API bool r_flag_unset_off(RFlag *f, ut64 off) { - r_return_val_if_fail (f, false); - RFlagItem *item = r_flag_get_i (f, off); - if (item && r_flag_unset (f, item)) { +RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 off) { + rz_return_val_if_fail (f, false); + RzFlagItem *item = rz_flag_get_i (f, off); + if (item && rz_flag_unset (f, item)) { return true; } return false; } struct unset_foreach_t { - RFlag *f; + RzFlag *f; int n; }; -static bool unset_foreach(RFlagItem *fi, void *user) { +static bool unset_foreach(RzFlagItem *fi, void *user) { struct unset_foreach_t *u = (struct unset_foreach_t *)user; if (IS_FI_NOTIN_SPACE (u->f, fi)) { return true; } - r_flag_unset (u->f, fi); + rz_flag_unset (u->f, fi); u->n++; return true; } @@ -825,34 +825,34 @@ static bool unset_foreach(RFlagItem *fi, void *user) { /* unset all the flag items that satisfy the given glob. * return the number of unset items. -1 on error */ // XXX This is O(n^n) because unset_globa iterates all flags and unset too. -R_API int r_flag_unset_glob(RFlag *f, const char *glob) { - r_return_val_if_fail (f, -1); +RZ_API int rz_flag_unset_glob(RzFlag *f, const char *glob) { + rz_return_val_if_fail (f, -1); struct unset_foreach_t u = { .f = f, .n = 0 }; - r_flag_foreach_glob (f, glob, unset_foreach, &u); + rz_flag_foreach_glob (f, glob, unset_foreach, &u); return u.n; } /* unset the flag item with the given name. * returns true if the item is found and unset, false otherwise. */ -R_API bool r_flag_unset_name(RFlag *f, const char *name) { - r_return_val_if_fail (f, false); - RFlagItem *item = ht_pp_find (f->ht_name, name, NULL); - return item && r_flag_unset (f, item); +RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name) { + rz_return_val_if_fail (f, false); + RzFlagItem *item = ht_pp_find (f->ht_name, name, NULL); + return item && rz_flag_unset (f, item); } -/* unset all flag items in the RFlag f */ -R_API void r_flag_unset_all(RFlag *f) { - r_return_if_fail (f); +/* unset all flag items in the RzFlag f */ +RZ_API void rz_flag_unset_all(RzFlag *f) { + rz_return_if_fail (f); ht_pp_free (f->ht_name); f->ht_name = ht_pp_new (NULL, ht_free_flag, NULL); - r_skiplist_purge (f->by_off); - r_spaces_fini (&f->spaces); + rz_skiplist_purge (f->by_off); + rz_spaces_fini (&f->spaces); new_spaces (f); } struct flag_relocate_t { - RFlag *f; + RzFlag *f; ut64 off; ut64 off_mask; ut64 neg_mask; @@ -860,7 +860,7 @@ struct flag_relocate_t { int n; }; -static bool flag_relocate_foreach(RFlagItem *fi, void *user) { +static bool flag_relocate_foreach(RzFlagItem *fi, void *user) { struct flag_relocate_t *u = (struct flag_relocate_t *)user; ut64 fn = fi->offset & u->neg_mask; ut64 on = u->off & u->neg_mask; @@ -873,8 +873,8 @@ static bool flag_relocate_foreach(RFlagItem *fi, void *user) { return true; } -R_API int r_flag_relocate(RFlag *f, ut64 off, ut64 off_mask, ut64 to) { - r_return_val_if_fail (f, -1); +RZ_API int rz_flag_relocate(RzFlag *f, ut64 off, ut64 off_mask, ut64 to) { + rz_return_val_if_fail (f, -1); struct flag_relocate_t u = { .f = f, .off = off, @@ -884,58 +884,58 @@ R_API int r_flag_relocate(RFlag *f, ut64 off, ut64 off_mask, ut64 to) { .n = 0 }; - r_flag_foreach (f, flag_relocate_foreach, &u); + rz_flag_foreach (f, flag_relocate_foreach, &u); return u.n; } -R_API bool r_flag_move(RFlag *f, ut64 at, ut64 to) { - r_return_val_if_fail (f, false); - RFlagItem *item = r_flag_get_i (f, at); +RZ_API bool rz_flag_move(RzFlag *f, ut64 at, ut64 to) { + rz_return_val_if_fail (f, false); + RzFlagItem *item = rz_flag_get_i (f, at); if (item) { - r_flag_set (f, item->name, to, item->size); + rz_flag_set (f, item->name, to, item->size); return true; } return false; } // BIND -R_API void r_flag_bind(RFlag *f, RFlagBind *fb) { - r_return_if_fail (f && fb); +RZ_API void rz_flag_bind(RzFlag *f, RzFlagBind *fb) { + rz_return_if_fail (f && fb); fb->f = f; - fb->exist_at = r_flag_exist_at; - fb->get = r_flag_get; - fb->get_at = r_flag_get_at; - fb->get_list = r_flag_get_list; - fb->set = r_flag_set; - fb->unset = r_flag_unset; - fb->unset_name = r_flag_unset_name; - fb->unset_off = r_flag_unset_off; - fb->set_fs = r_flag_space_set; - fb->push_fs = r_flag_space_push; - fb->pop_fs = r_flag_space_pop; + fb->exist_at = rz_flag_exist_at; + fb->get = rz_flag_get; + fb->get_at = rz_flag_get_at; + fb->get_list = rz_flag_get_list; + fb->set = rz_flag_set; + fb->unset = rz_flag_unset; + fb->unset_name = rz_flag_unset_name; + fb->unset_off = rz_flag_unset_off; + fb->set_fs = rz_flag_space_set; + fb->push_fs = rz_flag_space_push; + fb->pop_fs = rz_flag_space_pop; } -static bool flag_count_foreach(RFlagItem *fi, void *user) { +static bool flag_count_foreach(RzFlagItem *fi, void *user) { int *count = (int *)user; (*count)++; return true; } -R_API int r_flag_count(RFlag *f, const char *glob) { +RZ_API int rz_flag_count(RzFlag *f, const char *glob) { int count = 0; - r_return_val_if_fail (f, -1); - r_flag_foreach_glob (f, glob, flag_count_foreach, &count); + rz_return_val_if_fail (f, -1); + rz_flag_foreach_glob (f, glob, flag_count_foreach, &count); return count; } #define FOREACH_BODY(condition) \ - RSkipListNode *it, *tmp; \ - RFlagsAtOffset *flags_at; \ - RListIter *it2, *tmp2; \ - RFlagItem *fi; \ - r_skiplist_foreach_safe (f->by_off, it, tmp, flags_at) { \ + RzSkipListNode *it, *tmp; \ + RzFlagsAtOffset *flags_at; \ + RzListIter *it2, *tmp2; \ + RzFlagItem *fi; \ + rz_skiplist_foreach_safe (f->by_off, it, tmp, flags_at) { \ if (flags_at) { \ - r_list_foreach_safe (flags_at->flags, it2, tmp2, fi) { \ + rz_list_foreach_safe (flags_at->flags, it2, tmp2, fi) { \ if (condition) { \ if (!cb (fi, user)) { \ return; \ @@ -945,27 +945,27 @@ R_API int r_flag_count(RFlag *f, const char *glob) { } \ } -R_API void r_flag_foreach(RFlag *f, RFlagItemCb cb, void *user) { +RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user) { FOREACH_BODY (true); } -R_API void r_flag_foreach_prefix(RFlag *f, const char *pfx, int pfx_len, RFlagItemCb cb, void *user) { +RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user) { pfx_len = pfx_len < 0? strlen (pfx): pfx_len; FOREACH_BODY (!strncmp (fi->name, pfx, pfx_len)); } -R_API void r_flag_foreach_range(RFlag *f, ut64 from, ut64 to, RFlagItemCb cb, void *user) { +RZ_API void rz_flag_foreach_range(RzFlag *f, ut64 from, ut64 to, RzFlagItemCb cb, void *user) { FOREACH_BODY (fi->offset >= from && fi->offset < to); } -R_API void r_flag_foreach_glob(RFlag *f, const char *glob, RFlagItemCb cb, void *user) { - FOREACH_BODY (!glob || r_str_glob (fi->name, glob)); +RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user) { + FOREACH_BODY (!glob || rz_str_glob (fi->name, glob)); } -R_API void r_flag_foreach_space_glob(RFlag *f, const char *glob, const RSpace *space, RFlagItemCb cb, void *user) { - FOREACH_BODY (IS_FI_IN_SPACE (fi, space) && (!glob || r_str_glob (fi->name, glob))); +RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RSpace *space, RzFlagItemCb cb, void *user) { + FOREACH_BODY (IS_FI_IN_SPACE (fi, space) && (!glob || rz_str_glob (fi->name, glob))); } -R_API void r_flag_foreach_space(RFlag *f, const RSpace *space, RFlagItemCb cb, void *user) { +RZ_API void rz_flag_foreach_space(RzFlag *f, const RSpace *space, RzFlagItemCb cb, void *user) { FOREACH_BODY (IS_FI_IN_SPACE (fi, space)); } diff --git a/libr/flag/meson.build b/librz/flag/meson.build similarity index 64% rename from libr/flag/meson.build rename to librz/flag/meson.build index ab1eb8ce0f..87fcb96d7f 100644 --- a/libr/flag/meson.build +++ b/librz/flag/meson.build @@ -1,14 +1,14 @@ -r_flag_sources = [ +rz_flag_sources = [ 'flag.c', 'tags.c', 'zones.c' ] -r_flag = library('r_flag', r_flag_sources, +rz_flag = library('rz_flag', rz_flag_sources, include_directories: [platform_inc], c_args: library_cflags, dependencies: [ - r_util_dep + rz_util_dep ], install: true, implicit_include_directories: false, @@ -16,17 +16,17 @@ r_flag = library('r_flag', r_flag_sources, soversion: r2_libversion ) -r_flag_dep = declare_dependency(link_with: r_flag, +rz_flag_dep = declare_dependency(link_with: rz_flag, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_flag, - subdirs: 'libr', +pkgconfig_mod.generate(rz_flag, + subdirs: 'librz', version: r2_version, - name: 'r_flag', - filebase: 'r_flag', + name: 'rz_flag', + filebase: 'rz_flag', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/librz/flag/tags.c b/librz/flag/tags.c new file mode 100644 index 0000000000..b11e912068 --- /dev/null +++ b/librz/flag/tags.c @@ -0,0 +1,71 @@ +/* radare - LGPL - Copyright 2018 - pancake */ + +#include + +RZ_API RzList *rz_flag_tags_set(RzFlag *f, const char *name, const char *words) { + rz_return_val_if_fail (f && name && words, NULL); + const char *k = sdb_fmt ("tag.%s", name); + sdb_set (f->tags, k, words, -1); + return NULL; +} + +RZ_API RzList *rz_flag_tags_list(RzFlag *f, const char *name) { + rz_return_val_if_fail (f, NULL); + if (name) { + const char *k = sdb_fmt ("tag.%s", name); + char *words = sdb_get (f->tags, k, NULL); + return rz_str_split_list (words, " ", 0); + } + RzList *res = rz_list_newf (free); + SdbList *o = sdb_foreach_list (f->tags, false); + SdbListIter *iter; + SdbKv *kv; + ls_foreach (o, iter, kv) { + const char *tag = sdbkv_key (kv); + if (strlen (tag) < 5) { + continue; + } + rz_list_append (res, (void *)strdup (tag + 4)); + } + ls_free (o); + return res; +} + +RZ_API void rz_flag_tags_reset(RzFlag *f, const char *name) { + // TODO: use name + rz_return_if_fail (f); + sdb_reset (f->tags); +} + +struct iter_glob_flag_t { + RzList *res; + RzList *words; +}; + +static bool iter_glob_flag(RzFlagItem *fi, void *user) { + struct iter_glob_flag_t *u = (struct iter_glob_flag_t *)user; + RzListIter *iter; + const char *word; + + rz_list_foreach (u->words, iter, word) { + if (rz_str_glob (fi->name, word)) { + rz_list_append (u->res, fi); + } + } + return true; +} + +RZ_API RzList *rz_flag_tags_get(RzFlag *f, const char *name) { + rz_return_val_if_fail (f && name, NULL); + const char *k = sdb_fmt ("tag.%s", name); + RzList *res = rz_list_newf (NULL); + char *words = sdb_get (f->tags, k, NULL); + if (words) { + RzList *list = rz_str_split_list (words, " ", 0); + struct iter_glob_flag_t u = { .res = res, .words = list }; + rz_flag_foreach (f, iter_glob_flag, &u); + rz_list_free (list); + free (words); + } + return res; +} diff --git a/libr/flag/zones.c b/librz/flag/zones.c similarity index 65% rename from libr/flag/zones.c rename to librz/flag/zones.c index 225bdd3042..9897266693 100644 --- a/libr/flag/zones.c +++ b/librz/flag/zones.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2016-2020 - pancake */ -#include -#include +#include +#include #define DB f->zones #if !R_FLAG_ZONE_USE_SDB -static RFlagZoneItem *r_flag_zone_get (RFlag *f, const char *name) { - RListIter *iter; - RFlagZoneItem *zi; - r_list_foreach (DB, iter, zi) { +static RzFlagZoneItem *rz_flag_zone_get (RzFlag *f, const char *name) { + RzListIter *iter; + RzFlagZoneItem *zi; + rz_list_foreach (DB, iter, zi) { if (!strcmp (name, zi->name)) { return zi; } @@ -19,10 +19,10 @@ static RFlagZoneItem *r_flag_zone_get (RFlag *f, const char *name) { } #endif -static RFlagZoneItem *r_flag_zone_get_inrange (RFlag *f, ut64 from, ut64 to) { - RListIter *iter; - RFlagZoneItem *zi; - r_list_foreach (DB, iter, zi) { +static RzFlagZoneItem *rz_flag_zone_get_inrange (RzFlag *f, ut64 from, ut64 to) { + RzListIter *iter; + RzFlagZoneItem *zi; + rz_list_foreach (DB, iter, zi) { if (R_BETWEEN (from, zi->from, to)) { return zi; } @@ -30,10 +30,10 @@ static RFlagZoneItem *r_flag_zone_get_inrange (RFlag *f, ut64 from, ut64 to) { return NULL; } -R_API bool r_flag_zone_add(RFlag *f, const char *name, ut64 addr) { - r_return_val_if_fail (f && name && *name, false); +RZ_API bool rz_flag_zone_add(RzFlag *f, const char *name, ut64 addr) { + rz_return_val_if_fail (f && name && *name, false); #if R_FLAG_ZONE_USE_SDB - RFlagZoneItem zi = { 0, 0, (const char *)name }; + RzFlagZoneItem zi = { 0, 0, (const char *)name }; if (!DB) { return false; } @@ -53,7 +53,7 @@ R_API bool r_flag_zone_add(RFlag *f, const char *name, ut64 addr) { sdb_set (DB, name, sdb_fmt ("%"PFMT64d",%"PFMT64d, addr, addr), 0); } #else - RFlagZoneItem *zi = r_flag_zone_get (f, name); + RzFlagZoneItem *zi = rz_flag_zone_get (f, name); if (zi) { if (addr < zi->from) { zi->from = addr; @@ -63,36 +63,36 @@ R_API bool r_flag_zone_add(RFlag *f, const char *name, ut64 addr) { } } else { if (!DB) { - r_flag_zone_reset (f); + rz_flag_zone_reset (f); } - zi = R_NEW0 (RFlagZoneItem); + zi = R_NEW0 (RzFlagZoneItem); zi->name = strdup (name); zi->from = zi->to = addr; - r_list_append (DB, zi); + rz_list_append (DB, zi); } #endif return true; } -R_API bool r_flag_zone_reset(RFlag *f) { +RZ_API bool rz_flag_zone_reset(RzFlag *f) { #if R_FLAG_ZONE_USE_SDB return sdb_reset (DB); #else - r_list_free (f->zones); - f->zones = r_list_newf (r_flag_zone_item_free); + rz_list_free (f->zones); + f->zones = rz_list_newf (rz_flag_zone_item_free); return true; #endif } -R_API bool r_flag_zone_del(RFlag *f, const char *name) { +RZ_API bool rz_flag_zone_del(RzFlag *f, const char *name) { #if R_FLAG_ZONE_USE_SDB return sdb_unset (DB, name, 0); #else - RListIter *iter; - RFlagZoneItem *zi; - r_list_foreach (DB, iter, zi) { + RzListIter *iter; + RzFlagZoneItem *zi; + rz_list_foreach (DB, iter, zi) { if (!strcmp (name, zi->name)) { - r_list_delete (DB, iter); + rz_list_delete (DB, iter); return true; } } @@ -102,17 +102,17 @@ R_API bool r_flag_zone_del(RFlag *f, const char *name) { #if R_FLAG_ZONE_USE_SDB -typedef struct r_flag_zone_context_t { - RFlag *f; +typedef struct rz_flag_zone_context_t { + RzFlag *f; ut64 addr; ut64 l, h; // lower, higher closest offsets const char **prev; const char **next; -} RFlagZoneContext; +} RzFlagZoneContext; static bool cb(void *user, const char *name, const char *from_to) { - RFlagZoneContext *zc = (RFlagZoneContext*)user; - RFlagZoneItem zi = { 0, 0, name }; + RzFlagZoneContext *zc = (RzFlagZoneContext*)user; + RzFlagZoneItem zi = { 0, 0, name }; sdb_fmt_tobin (from_to, "qq", &zi); if (zi.from > zc->addr) { if (zc->h == UT64_MAX) { @@ -161,38 +161,38 @@ static bool cb(void *user, const char *name, const char *from_to) { return true; } -R_API bool r_flag_zone_around(RFlag *f, ut64 addr, const char **prev, const char **next) { - RFlagZoneContext ctx = { f, addr, 0, UT64_MAX, prev, next }; +RZ_API bool rz_flag_zone_around(RzFlag *f, ut64 addr, const char **prev, const char **next) { + RzFlagZoneContext ctx = { f, addr, 0, UT64_MAX, prev, next }; *prev = *next = NULL; sdb_foreach (DB, cb, &ctx); return true; } static bool cb_list(void *user, const char *name, const char *from_to) { - eprintf ("%s%s %s\n", name, r_str_pad (' ', 10 - strlen (name)), from_to); + eprintf ("%s%s %s\n", name, rz_str_pad (' ', 10 - strlen (name)), from_to); return true; } -R_API bool r_flag_zone_list(RFlag *f, int mode) { +RZ_API bool rz_flag_zone_list(RzFlag *f, int mode) { sdb_foreach (DB, cb_list, NULL); return true; } #else -R_API void r_flag_zone_item_free(void *a) { - RFlagZoneItem *zi = a; +RZ_API void rz_flag_zone_item_free(void *a) { + RzFlagZoneItem *zi = a; free (zi->name); free (zi); } -R_API bool r_flag_zone_around(RFlag *f, ut64 addr, const char **prev, const char **next) { - RListIter *iter; - RFlagZoneItem *zi; +RZ_API bool rz_flag_zone_around(RzFlag *f, ut64 addr, const char **prev, const char **next) { + RzListIter *iter; + RzFlagZoneItem *zi; *prev = *next = NULL; ut64 h = UT64_MAX, l = 0LL; - r_list_foreach (DB, iter, zi) { + rz_list_foreach (DB, iter, zi) { if (zi->from > addr) { if (h == UT64_MAX) { h = zi->from; @@ -241,25 +241,25 @@ R_API bool r_flag_zone_around(RFlag *f, ut64 addr, const char **prev, const char return true; } -R_API RList *r_flag_zone_barlist(RFlag *f, ut64 from, ut64 bsize, int rows) { - RList *list = r_list_newf (NULL); +RZ_API RzList *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows) { + RzList *list = rz_list_newf (NULL); int i; for (i = 0; i < rows; i++) { - RFlagZoneItem *zi = r_flag_zone_get_inrange (f, from, from + bsize); + RzFlagZoneItem *zi = rz_flag_zone_get_inrange (f, from, from + bsize); if (zi) { - r_list_append (list, zi->name); + rz_list_append (list, zi->name); } else { - r_list_append (list, ""); + rz_list_append (list, ""); } from += bsize; } return list; } -R_API bool r_flag_zone_list(RFlag *f, int mode) { - RListIter *iter; - RFlagZoneItem *zi; - r_list_foreach (DB, iter, zi) { +RZ_API bool rz_flag_zone_list(RzFlag *f, int mode) { + RzListIter *iter; + RzFlagZoneItem *zi; + rz_list_foreach (DB, iter, zi) { if (mode == '*') { f->cb_printf ("fz %s @ 0x08%"PFMT64x"\n", zi->name, zi->from); f->cb_printf ("f %s %d 0x08%"PFMT64x"\n", zi->name, @@ -275,11 +275,11 @@ R_API bool r_flag_zone_list(RFlag *f, int mode) { // #define __MAIN__ 1 #if __MAIN__ -#define FZ(x) r_flag_zone_##x +#define FZ(x) rz_flag_zone_##x int main() { const char *a, *b; - RFlagZone *fz = r_flag_zone_new (); + RzFlagZone *fz = rz_flag_zone_new (); FZ(add)(fz, "main", 0x80000); FZ(add)(fz, "network", 0x85000); @@ -298,7 +298,7 @@ int main() { FZ(list)(fz); - r_flag_zone_free (fz); + rz_flag_zone_free (fz); return 0; } #endif diff --git a/libr/fs/Makefile b/librz/fs/Makefile similarity index 81% rename from libr/fs/Makefile rename to librz/fs/Makefile index 76677fbbed..a790b06dae 100644 --- a/libr/fs/Makefile +++ b/librz/fs/Makefile @@ -1,5 +1,5 @@ -NAME=r_fs -R2DEPS=r_util r_io r_socket +NAME=rz_fs +R2DEPS=rz_util rz_io rz_socket CFLAGS+=-DR2_PLUGIN_INCORE -Iarch/include -Iarch SHLR=../../shlr/ @@ -24,10 +24,10 @@ OBJS=${STATIC_OBJS} fs.o fs_file.o shell.o pre: cd d && ${MAKE} -# @if [ ! -e libr_fs.${EXT_SO} ]; then if [ ! -e libr_fs.${EXT_AR} ]; then rm -f ${STATIC_OBJS} ; fi ; fi +# @if [ ! -e librz_fs.${EXT_SO} ]; then if [ ! -e librz_fs.${EXT_AR} ]; then rm -f ${STATIC_OBJS} ; fi ; fi re: - rm -f fs.o libr_fs.so + rm -f fs.o librz_fs.so ${MAKE} rm -f t/fastcall.o sudo ${MAKE} install diff --git a/libr/fs/d/Makefile b/librz/fs/d/Makefile similarity index 100% rename from libr/fs/d/Makefile rename to librz/fs/d/Makefile diff --git a/libr/fs/d/dospart b/librz/fs/d/dospart similarity index 100% rename from libr/fs/d/dospart rename to librz/fs/d/dospart diff --git a/libr/fs/fs.c b/librz/fs/fs.c similarity index 61% rename from libr/fs/fs.c rename to librz/fs/fs.c index f47be6c489..7668fe39e0 100644 --- a/libr/fs/fs.c +++ b/librz/fs/fs.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2011-2019 - pancake */ +/* rizin - LGPL - Copyright 2011-2019 - pancake */ -#include +#include #include "config.h" #include "types.h" #include @@ -12,51 +12,51 @@ # endif #endif -R_LIB_VERSION (r_fs); +R_LIB_VERSION (rz_fs); -static RFSPlugin* fs_static_plugins[] = { +static RzFSPlugin* fs_static_plugins[] = { R_FS_STATIC_PLUGINS }; -R_API RFS* r_fs_new(void) { +RZ_API RzFS* rz_fs_new(void) { int i; - RFSPlugin* static_plugin; - RFS* fs = R_NEW0 (RFS); + RzFSPlugin* static_plugin; + RzFS* fs = R_NEW0 (RzFS); if (fs) { fs->view = R_FS_VIEW_NORMAL; - fs->roots = r_list_new (); + fs->roots = rz_list_new (); if (!fs->roots) { - r_fs_free (fs); + rz_fs_free (fs); return NULL; } - fs->roots->free = (RListFree) r_fs_root_free; - fs->plugins = r_list_new (); + fs->roots->free = (RzListFree) rz_fs_root_free; + fs->plugins = rz_list_new (); if (!fs->plugins) { - r_fs_free (fs); + rz_fs_free (fs); return NULL; } fs->plugins->free = free; - // XXX fs->roots->free = r_fs_plugin_free; + // XXX fs->roots->free = rz_fs_plugin_free; for (i = 0; fs_static_plugins[i]; i++) { - static_plugin = R_NEW (RFSPlugin); + static_plugin = R_NEW (RzFSPlugin); if (!static_plugin) { continue; } - memcpy (static_plugin, fs_static_plugins[i], sizeof (RFSPlugin)); - r_fs_add (fs, static_plugin); + memcpy (static_plugin, fs_static_plugins[i], sizeof (RzFSPlugin)); + rz_fs_add (fs, static_plugin); free (static_plugin); } } return fs; } -R_API RFSPlugin* r_fs_plugin_get(RFS* fs, const char* name) { - RListIter* iter; - RFSPlugin* p; +RZ_API RzFSPlugin* rz_fs_plugin_get(RzFS* fs, const char* name) { + RzListIter* iter; + RzFSPlugin* p; if (!fs || !name) { return NULL; } - r_list_foreach (fs->plugins, iter, p) { + rz_list_foreach (fs->plugins, iter, p) { if (!strcmp (p->name, name)) { return p; } @@ -64,55 +64,55 @@ R_API RFSPlugin* r_fs_plugin_get(RFS* fs, const char* name) { return NULL; } -R_API void r_fs_free(RFS* fs) { +RZ_API void rz_fs_free(RzFS* fs) { if (!fs) { return; } - //r_io_free (fs->iob.io); + //rz_io_free (fs->iob.io); //root makes use of plugin so revert to avoid UaF - r_list_free (fs->roots); - r_list_free (fs->plugins); + rz_list_free (fs->roots); + rz_list_free (fs->plugins); free (fs); } /* plugins */ -R_API void r_fs_add(RFS* fs, RFSPlugin* p) { +RZ_API void rz_fs_add(RzFS* fs, RzFSPlugin* p) { // TODO: find coliding plugin name if (p && p->init) { p->init (); } - RFSPlugin* sp = R_NEW0 (RFSPlugin); + RzFSPlugin* sp = R_NEW0 (RzFSPlugin); if (sp) { if (p) { - memcpy (sp, p, sizeof (RFSPlugin)); + memcpy (sp, p, sizeof (RzFSPlugin)); } - r_list_append (fs->plugins, sp); + rz_list_append (fs->plugins, sp); } } -R_API void r_fs_del(RFS* fs, RFSPlugin* p) { - // TODO: implement r_fs_del +RZ_API void rz_fs_del(RzFS* fs, RzFSPlugin* p) { + // TODO: implement rz_fs_del } /* mountpoint */ -R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 delta) { - RFSPlugin* p; - RFSRoot* root; - RListIter* iter; +RZ_API RzFSRoot* rz_fs_mount(RzFS* fs, const char* fstype, const char* path, ut64 delta) { + RzFSPlugin* p; + RzFSRoot* root; + RzListIter* iter; char* str; int len, lenstr; char *heapFsType = NULL; if (path[0] != '/') { - eprintf ("r_fs_mount: invalid mountpoint %s\n", path); + eprintf ("rz_fs_mount: invalid mountpoint %s\n", path); return NULL; } if (!fstype || !*fstype) { - heapFsType = r_fs_name (fs, delta); + heapFsType = rz_fs_name (fs, delta); fstype = (const char *)heapFsType; } - if (!(p = r_fs_plugin_get (fs, fstype))) { - // eprintf ("r_fs_mount: Invalid filesystem type\n"); + if (!(p = rz_fs_plugin_get (fs, fstype))) { + // eprintf ("rz_fs_mount: Invalid filesystem type\n"); free (heapFsType); return NULL; } @@ -121,14 +121,14 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de free (heapFsType); return NULL; } - r_str_trim_path (str); + rz_str_trim_path (str); if (*str && strchr (str + 1, '/')) { - eprintf ("r_fs_mount: mountpoint must have no subdirectories\n"); + eprintf ("rz_fs_mount: mountpoint must have no subdirectories\n"); free (heapFsType); return NULL; } /* Check if path exists */ - r_list_foreach (fs->roots, iter, root) { + rz_list_foreach (fs->roots, iter, root) { len = strlen (root->path); lenstr = strlen (str); if (!strncmp (str, root->path, len)) { @@ -138,91 +138,91 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de if (len > lenstr && root->path[lenstr] == '/') { continue; } - eprintf ("r_fs_mount: Invalid mount point\n"); + eprintf ("rz_fs_mount: Invalid mount point\n"); free (str); free (heapFsType); return NULL; } } - RFSFile* file = r_fs_open (fs, str, false); + RzFSFile* file = rz_fs_open (fs, str, false); if (file) { - r_fs_close (fs, file); - eprintf ("r_fs_mount: Invalid mount point\n"); + rz_fs_close (fs, file); + eprintf ("rz_fs_mount: Invalid mount point\n"); free (heapFsType); free (str); return NULL; } - RList *list = r_fs_dir (fs, str); - if (!r_list_empty (list)) { + RzList *list = rz_fs_dir (fs, str); + if (!rz_list_empty (list)) { //XXX: list need free ?? - eprintf ("r_fs_mount: Invalid mount point\n"); + eprintf ("rz_fs_mount: Invalid mount point\n"); free (str); free (heapFsType); return NULL; } // TODO: we should just construct the root with the rfs instance - root = r_fs_root_new (str, delta); + root = rz_fs_root_new (str, delta); root->p = p; root->iob = fs->iob; root->cob = fs->cob; if (!p->mount (root)) { free (str); free (heapFsType); - r_fs_root_free (root); + rz_fs_root_free (root); return NULL; } - r_list_append (fs->roots, root); + rz_list_append (fs->roots, root); eprintf ("Mounted %s on %s at 0x%" PFMT64x "\n", fstype, str, delta); free (str); free (heapFsType); return root; } -static inline bool r_fs_match(const char* root, const char* path, int len) { +static inline bool rz_fs_match(const char* root, const char* path, int len) { return (!strncmp (path, root, len)); } -R_API bool r_fs_umount(RFS* fs, const char* path) { +RZ_API bool rz_fs_umount(RzFS* fs, const char* path) { int len; - RFSRoot* root; - RListIter* iter, * riter = NULL; + RzFSRoot* root; + RzListIter* iter, * riter = NULL; if (!path) { return false; } - r_list_foreach (fs->roots, iter, root) { + rz_list_foreach (fs->roots, iter, root) { len = strlen (root->path); - if (r_fs_match (path, root->path, len)) { + if (rz_fs_match (path, root->path, len)) { riter = iter; } } if (riter) { - r_list_delete (fs->roots, riter); + rz_list_delete (fs->roots, riter); return true; } return false; } -R_API RList* r_fs_root(RFS* fs, const char* p) { - RList* roots; - RFSRoot* root; - RListIter* iter; +RZ_API RzList* rz_fs_root(RzFS* fs, const char* p) { + RzList* roots; + RzFSRoot* root; + RzListIter* iter; int len, olen; char* path = strdup (p); if (!path) { return NULL; } - roots = r_list_new (); - r_str_trim_path (path); - r_list_foreach (fs->roots, iter, root) { + roots = rz_list_new (); + rz_str_trim_path (path); + rz_list_foreach (fs->roots, iter, root) { len = strlen (root->path); - if (r_fs_match (path, root->path, len)) { + if (rz_fs_match (path, root->path, len)) { olen = strlen (path); if (len == 1 || olen == len) { - r_list_append (roots, root); + rz_list_append (roots, root); } else if (olen > len && path[len] == '/') { - r_list_append (roots, root); + rz_list_append (roots, root); } } } @@ -231,18 +231,18 @@ R_API RList* r_fs_root(RFS* fs, const char* p) { } /* filez */ -R_API RFSFile* r_fs_open(RFS* fs, const char* p, bool create) { - RFSRoot* root; - RListIter* iter; - RFSFile* f = NULL; +RZ_API RzFSFile* rz_fs_open(RzFS* fs, const char* p, bool create) { + RzFSRoot* root; + RzListIter* iter; + RzFSFile* f = NULL; const char* dir; - char* path = r_str_trim_dup (p); - RList *roots = r_fs_root (fs, path); - if (!r_list_empty (roots)) { - r_list_foreach (roots, iter, root) { + char* path = rz_str_trim_dup (p); + RzList *roots = rz_fs_root (fs, path); + if (!rz_list_empty (roots)) { + rz_list_foreach (roots, iter, root) { if (create) { if (root && root->p && root->p->write) { - f = r_fs_file_new (root, path + strlen (root->path)); + f = rz_fs_file_new (root, path + strlen (root->path)); break; } continue; @@ -266,7 +266,7 @@ R_API RFSFile* r_fs_open(RFS* fs, const char* p, bool create) { } // NOTE: close doesnt free -R_API void r_fs_close(RFS* fs, RFSFile* file) { +RZ_API void rz_fs_close(RzFS* fs, RzFSFile* file) { if (fs && file) { R_FREE (file->data); if (file->p && file->p->close) { @@ -275,7 +275,7 @@ R_API void r_fs_close(RFS* fs, RFSFile* file) { } } -R_API int r_fs_write(RFS* fs, RFSFile* file, ut64 addr, const ut8 *data, int len) { +RZ_API int rz_fs_write(RzFS* fs, RzFSFile* file, ut64 addr, const ut8 *data, int len) { if (len < 1) { return false; } @@ -285,14 +285,14 @@ R_API int r_fs_write(RFS* fs, RFSFile* file, ut64 addr, const ut8 *data, int len file->p->write (file, addr, data, len); return true; } - eprintf ("r_fs_write: file->p->write is null\n"); + eprintf ("rz_fs_write: file->p->write is null\n"); } return false; } -R_API int r_fs_read(RFS* fs, RFSFile* file, ut64 addr, int len) { +RZ_API int rz_fs_read(RzFS* fs, RzFSFile* file, ut64 addr, int len) { if (len < 1) { - eprintf ("r_fs_read: too short read\n"); + eprintf ("rz_fs_read: too short read\n"); return false; } if (fs && file) { @@ -304,21 +304,21 @@ R_API int r_fs_read(RFS* fs, RFSFile* file, ut64 addr, int len) { file->p->read (file, addr, len); return true; } else { - eprintf ("r_fs_read: file->p->read is null\n"); + eprintf ("rz_fs_read: file->p->read is null\n"); } } return false; } -R_API RList* r_fs_dir(RFS* fs, const char* p) { - RList *ret = NULL; - RFSRoot* root; - RListIter* iter; +RZ_API RzList* rz_fs_dir(RzFS* fs, const char* p) { + RzList *ret = NULL; + RzFSRoot* root; + RzListIter* iter; const char* dir; char* path = strdup (p); - r_str_trim_path (path); - RList *roots = r_fs_root (fs, path); - r_list_foreach (roots, iter, root) { + rz_str_trim_path (path); + RzList *roots = rz_fs_root (fs, path); + rz_list_foreach (roots, iter, root) { if (root) { if (strlen (root->path) == 1) { dir = path; @@ -339,23 +339,23 @@ R_API RList* r_fs_dir(RFS* fs, const char* p) { return ret; } -R_API int r_fs_dir_dump(RFS* fs, const char* path, const char* name) { - RList* list; - RListIter* iter; - RFSFile* file, * item; +RZ_API int rz_fs_dir_dump(RzFS* fs, const char* path, const char* name) { + RzList* list; + RzListIter* iter; + RzFSFile* file, * item; char* str, * npath; - list = r_fs_dir (fs, path); + list = rz_fs_dir (fs, path); if (!list) { return false; } - if (!r_sys_mkdir (name)) { - if (r_sys_mkdir_failed ()) { + if (!rz_sys_mkdir (name)) { + if (rz_sys_mkdir_failed ()) { eprintf ("Cannot create \"%s\"\n", name); return false; } } - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { if (!strcmp (file->name, ".") || !strcmp (file->name, "..")) { continue; } @@ -377,22 +377,22 @@ R_API int r_fs_dir_dump(RFS* fs, const char* path, const char* name) { switch (file->type) { // DON'T FOLLOW MOUNTPOINTS case R_FS_FILE_TYPE_DIRECTORY: - if (!r_fs_dir_dump (fs, npath, str)) { + if (!rz_fs_dir_dump (fs, npath, str)) { free (npath); free (str); return false; } break; case R_FS_FILE_TYPE_REGULAR: - item = r_fs_open (fs, npath, false); + item = rz_fs_open (fs, npath, false); if (item) { - r_fs_read (fs, item, 0, item->size); - if (!r_file_dump (str, item->data, item->size, 0)) { + rz_fs_read (fs, item, 0, item->size); + if (!rz_file_dump (str, item->data, item->size, 0)) { free (npath); free (str); return false; } - r_fs_close (fs, item); + rz_fs_close (fs, item); } break; } @@ -402,14 +402,14 @@ R_API int r_fs_dir_dump(RFS* fs, const char* path, const char* name) { return true; } -static void r_fs_find_off_aux(RFS* fs, const char* name, ut64 offset, RList* list) { - RList* dirs; - RListIter* iter; - RFSFile* item, * file; +static void rz_fs_find_off_aux(RzFS* fs, const char* name, ut64 offset, RzList* list) { + RzList* dirs; + RzListIter* iter; + RzFSFile* item, * file; char* found = NULL; - dirs = r_fs_dir (fs, name); - r_list_foreach (dirs, iter, item) { + dirs = rz_fs_dir (fs, name); + rz_list_foreach (dirs, iter, item) { if (!strcmp (item->name, ".") || !strcmp (item->name, "..")) { continue; } @@ -423,40 +423,40 @@ static void r_fs_find_off_aux(RFS* fs, const char* name, ut64 offset, RList* lis strcat (found, item->name); if (item->type == R_FS_FILE_TYPE_DIRECTORY) { - r_fs_find_off_aux (fs, found, offset, list); + rz_fs_find_off_aux (fs, found, offset, list); } else { - file = r_fs_open (fs, found, false); + file = rz_fs_open (fs, found, false); if (file) { - r_fs_read (fs, file, 0, file->size); + rz_fs_read (fs, file, 0, file->size); if (file->off == offset) { - r_list_append (list, found); + rz_list_append (list, found); } - r_fs_close (fs, file); + rz_fs_close (fs, file); } } free (found); } } -R_API RList* r_fs_find_off(RFS* fs, const char* name, ut64 off) { - RList* list = r_list_new (); +RZ_API RzList* rz_fs_find_off(RzFS* fs, const char* name, ut64 off) { + RzList* list = rz_list_new (); if (!list) { return NULL; } list->free = free; - r_fs_find_off_aux (fs, name, off, list); + rz_fs_find_off_aux (fs, name, off, list); return list; } -static void r_fs_find_name_aux(RFS* fs, const char* name, const char* glob, RList* list) { - RList* dirs; - RListIter* iter; - RFSFile* item; +static void rz_fs_find_name_aux(RzFS* fs, const char* name, const char* glob, RzList* list) { + RzList* dirs; + RzListIter* iter; + RzFSFile* item; char* found; - dirs = r_fs_dir (fs, name); - r_list_foreach (dirs, iter, item) { - if (r_str_glob (item->name, glob)) { + dirs = rz_fs_dir (fs, name); + rz_list_foreach (dirs, iter, item) { + if (rz_str_glob (item->name, glob)) { found = (char*) malloc (strlen (name) + strlen (item->name) + 2); if (!found) { break; @@ -464,7 +464,7 @@ static void r_fs_find_name_aux(RFS* fs, const char* name, const char* glob, RLis strcpy (found, name); strcat (found, "/"); strcat (found, item->name); - r_list_append (list, found); + rz_list_append (list, found); } if (!strcmp (item->name, ".") || !strcmp (item->name, "..")) { continue; @@ -477,26 +477,26 @@ static void r_fs_find_name_aux(RFS* fs, const char* name, const char* glob, RLis strcpy (found, name); strcat (found, "/"); strcat (found, item->name); - r_fs_find_name_aux (fs, found, glob, list); + rz_fs_find_name_aux (fs, found, glob, list); free (found); } } } -R_API RList* r_fs_find_name(RFS* fs, const char* name, const char* glob) { - RList* list = r_list_newf (free); +RZ_API RzList* rz_fs_find_name(RzFS* fs, const char* name, const char* glob) { + RzList* list = rz_list_newf (free); if (list) { - r_fs_find_name_aux (fs, name, glob, list); + rz_fs_find_name_aux (fs, name, glob, list); } return list; } -R_API RFSFile* r_fs_slurp(RFS* fs, const char* path) { - RFSFile* file = NULL; - RFSRoot* root; - RList* roots = r_fs_root (fs, path); - RListIter* iter; - r_list_foreach (roots, iter, root) { +RZ_API RzFSFile* rz_fs_slurp(RzFS* fs, const char* path) { + RzFSFile* file = NULL; + RzFSRoot* root; + RzList* roots = rz_fs_root (fs, path); + RzListIter* iter; + rz_list_foreach (roots, iter, root) { if (!root || !root->p) { continue; } @@ -505,14 +505,14 @@ R_API RFSFile* r_fs_slurp(RFS* fs, const char* path) { if (file) { root->p->read (file, 0, file->size); //file->data }else { - eprintf ("r_fs_slurp: cannot open file\n"); + eprintf ("rz_fs_slurp: cannot open file\n"); } } else { if (root->p->slurp) { free (roots); return root->p->slurp (root, path); } - eprintf ("r_fs_slurp: null root->p->slurp\n"); + eprintf ("rz_fs_slurp: null root->p->slurp\n"); } } free (roots); @@ -525,26 +525,26 @@ R_API RFSFile* r_fs_slurp(RFS* fs, const char* path) { #if USE_GRUB static int grub_parhook(void* disk, void* ptr, void* closure) { struct grub_partition* par = ptr; - RList* list = (RList*) closure; - RFSPartition* p = r_fs_partition_new ( - r_list_length (list), + RzList* list = (RzList*) closure; + RzFSPartition* p = rz_fs_partition_new ( + rz_list_length (list), par->start * 512, 512 * par->len); p->type = par->msdostype; - r_list_append (list, p); + rz_list_append (list, p); return 0; } #endif static int fs_parhook(void* disk, void* ptr, void* closure) { - RFSPartition* par = ptr; - RList* list = (RList*) closure; - r_list_append (list, par); + RzFSPartition* par = ptr; + RzList* list = (RzList*) closure; + rz_list_append (list, par); return 0; } #include "p/part_dos.c" -static RFSPartitionType partitions[] = { +static RzFSPartitionType partitions[] = { /* LGPL code */ {"dos", &fs_part_dos, fs_parhook}, #if USE_GRUB @@ -567,18 +567,18 @@ static RFSPartitionType partitions[] = { { NULL } }; -R_API const char* r_fs_partition_type_get(int n) { +RZ_API const char* rz_fs_partition_type_get(int n) { if (n < 0 || n >= R_FS_PARTITIONS_LENGTH) { return NULL; } return partitions[n].name; } -R_API int r_fs_partition_get_size(void) { +RZ_API int rz_fs_partition_get_size(void) { return R_FS_PARTITIONS_LENGTH; } -R_API RList* r_fs_partitions(RFS* fs, const char* ptype, ut64 delta) { +RZ_API RzList* rz_fs_partitions(RzFS* fs, const char* ptype, ut64 delta) { int i, cur = -1; for (i = 0; partitions[i].name; i++) { if (!strcmp (ptype, partitions[i].name)) { @@ -587,7 +587,7 @@ R_API RList* r_fs_partitions(RFS* fs, const char* ptype, ut64 delta) { } } if (cur != -1) { - RList* list = r_list_newf ((RListFree) r_fs_partition_free); + RzList* list = rz_list_newf ((RzListFree) rz_fs_partition_free); #if USE_GRUB void* disk = NULL; if (partitions[i].iterate == grub_parhook) { @@ -603,7 +603,7 @@ R_API RList* r_fs_partitions(RFS* fs, const char* ptype, ut64 delta) { #else { #endif - RFSPartitionIterator iterate = partitions[i].ptr; + RzFSPartitionIterator iterate = partitions[i].ptr; iterate (fs, partitions[i].iterate, list); //grub_parhook, list); } return list; @@ -619,12 +619,12 @@ R_API RList* r_fs_partitions(RFS* fs, const char* ptype, ut64 delta) { return NULL; } -R_API int r_fs_partition_type_str(const char* type) { +RZ_API int rz_fs_partition_type_str(const char* type) { // TODO: implement return 0; } -R_API const char* r_fs_partition_type(const char* part, int type) { +RZ_API const char* rz_fs_partition_type(const char* part, int type) { // XXX: part is ignored O_o switch (type) { case GRUB_PC_PARTITION_TYPE_FAT12: @@ -666,12 +666,12 @@ R_API const char* r_fs_partition_type(const char* part, int type) { } } -R_API char* r_fs_name(RFS* fs, ut64 offset) { +RZ_API char* rz_fs_name(RzFS* fs, ut64 offset) { ut8 buf[1024]; int i, j, len, ret = false; for (i = 0; fstypes[i].name; i++) { - RFSType* f = &fstypes[i]; + RzFSType* f = &fstypes[i]; len = R_MIN (f->buflen, sizeof (buf) - 1); fs->iob.read_at (fs->iob.io, offset + f->bufoff, buf, len); if (f->buflen > 0 && !memcmp (buf, f->buf, f->buflen)) { @@ -693,20 +693,20 @@ R_API char* r_fs_name(RFS* fs, ut64 offset) { return NULL; } -R_API void r_fs_view(RFS* fs, int view) { +RZ_API void rz_fs_view(RzFS* fs, int view) { fs->view = view; } -R_API bool r_fs_check(RFS *fs, const char *p) { - RFSRoot *root; - RListIter *iter; +RZ_API bool rz_fs_check(RzFS *fs, const char *p) { + RzFSRoot *root; + RzListIter *iter; char* path = strdup (p); if (!path) { return false; } - r_str_trim_path (path); - r_list_foreach (fs->roots, iter, root) { - if (r_fs_match (path, root->path, strlen (root->path))) { + rz_str_trim_path (path); + rz_list_foreach (fs->roots, iter, root) { + if (rz_fs_match (path, root->path, strlen (root->path))) { free (path); return true; } diff --git a/libr/fs/fs_file.c b/librz/fs/fs_file.c similarity index 58% rename from libr/fs/fs_file.c rename to librz/fs/fs_file.c index fb046ec807..e22046dbce 100644 --- a/libr/fs/fs_file.c +++ b/librz/fs/fs_file.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include +#include -R_API RFSFile* r_fs_file_new(RFSRoot* root, const char* path) { - RFSFile* file = R_NEW0 (RFSFile); +RZ_API RzFSFile* rz_fs_file_new(RzFSRoot* root, const char* path) { + RzFSFile* file = R_NEW0 (RzFSFile); if (!file) { return NULL; } @@ -12,7 +12,7 @@ R_API RFSFile* r_fs_file_new(RFSRoot* root, const char* path) { file->p = file->root->p; // XXX dupe } file->path = strdup (path); - char *last = (char *)r_str_rchr (file->path, NULL, '/'); + char *last = (char *)rz_str_rchr (file->path, NULL, '/'); if (last) { *last++ = 0; file->name = strdup (last); @@ -22,7 +22,7 @@ R_API RFSFile* r_fs_file_new(RFSRoot* root, const char* path) { return file; } -R_API void r_fs_file_free(RFSFile* file) { +RZ_API void rz_fs_file_free(RzFSFile* file) { if (file) { free (file->path); free (file->name); @@ -31,20 +31,20 @@ R_API void r_fs_file_free(RFSFile* file) { } } -R_API char* r_fs_file_copy_abs_path(RFSFile* file) { +RZ_API char* rz_fs_file_copy_abs_path(RzFSFile* file) { if (!file) { return NULL; } if (!strcmp (file->path, file->name)) { return strdup (file->path); } - return r_str_newf ("%s/%s", file->path, file->name); + return rz_str_newf ("%s/%s", file->path, file->name); } -// TODO: Use RFSRoot and pass it in the stack instead of heap? problematic with bindings -R_API RFSRoot* r_fs_root_new(const char* path, ut64 delta) { +// TODO: Use RzFSRoot and pass it in the stack instead of heap? problematic with bindings +RZ_API RzFSRoot* rz_fs_root_new(const char* path, ut64 delta) { char* p; - RFSRoot* root = R_NEW0 (RFSRoot); + RzFSRoot* root = R_NEW0 (RzFSRoot); if (!root) { return NULL; } @@ -61,7 +61,7 @@ R_API RFSRoot* r_fs_root_new(const char* path, ut64 delta) { return root; } -R_API void r_fs_root_free(RFSRoot* root) { +RZ_API void rz_fs_root_free(RzFSRoot* root) { if (root) { if (root->p && root->p->umount) { root->p->umount (root); @@ -71,8 +71,8 @@ R_API void r_fs_root_free(RFSRoot* root) { } } -R_API RFSPartition* r_fs_partition_new(int num, ut64 start, ut64 length) { - RFSPartition* p = R_NEW0 (RFSPartition); +RZ_API RzFSPartition* rz_fs_partition_new(int num, ut64 start, ut64 length) { + RzFSPartition* p = R_NEW0 (RzFSPartition); if (!p) { return NULL; } @@ -83,6 +83,6 @@ R_API RFSPartition* r_fs_partition_new(int num, ut64 start, ut64 length) { return p; } -R_API void r_fs_partition_free(RFSPartition* p) { +RZ_API void rz_fs_partition_free(RzFSPartition* p) { free (p); } diff --git a/libr/fs/meson.build b/librz/fs/meson.build similarity index 77% rename from libr/fs/meson.build rename to librz/fs/meson.build index 943402c563..a613aa7f9d 100644 --- a/libr/fs/meson.build +++ b/librz/fs/meson.build @@ -1,4 +1,4 @@ -r_fs_sources = [ +rz_fs_sources = [ 'fs_file.c', 'fs.c', 'shell.c', @@ -15,7 +15,7 @@ r_fs_sources = [ 'p/fs_minix.c', 'p/fs_ntfs.c', 'p/fs_posix.c', - 'p/fs_r2.c', + 'p/fs_rz.c', 'p/fs_reiserfs.c', 'p/fs_sfs.c', 'p/fs_tar.c', @@ -26,11 +26,11 @@ r_fs_sources = [ #'p/part_dos.c' ] -r_fs = library('r_fs', r_fs_sources, +rz_fs = library('rz_fs', rz_fs_sources, include_directories: platform_inc, c_args: library_cflags, dependencies: [ - r_util_dep, + rz_util_dep, grub_dep ], install: true, @@ -39,17 +39,17 @@ r_fs = library('r_fs', r_fs_sources, soversion: r2_libversion ) -r_fs_dep = declare_dependency(link_with: r_fs, +rz_fs_dep = declare_dependency(link_with: rz_fs, include_directories: platform_inc) -pkgconfig_mod.generate(r_fs, - subdirs: 'libr', +pkgconfig_mod.generate(rz_fs, + subdirs: 'librz', version: r2_version, - name: 'r_fs', - filebase: 'r_fs', + name: 'rz_fs', + filebase: 'rz_fs', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/fs/p/Makefile b/librz/fs/p/Makefile similarity index 100% rename from libr/fs/p/Makefile rename to librz/fs/p/Makefile diff --git a/libr/fs/p/cpio.mk b/librz/fs/p/cpio.mk similarity index 100% rename from libr/fs/p/cpio.mk rename to librz/fs/p/cpio.mk diff --git a/libr/fs/p/ext2.mk b/librz/fs/p/ext2.mk similarity index 100% rename from libr/fs/p/ext2.mk rename to librz/fs/p/ext2.mk diff --git a/libr/fs/p/fat.mk b/librz/fs/p/fat.mk similarity index 100% rename from libr/fs/p/fat.mk rename to librz/fs/p/fat.mk diff --git a/libr/fs/p/fb.mk b/librz/fs/p/fb.mk similarity index 100% rename from libr/fs/p/fb.mk rename to librz/fs/p/fb.mk diff --git a/libr/fs/p/fs_cpio.c b/librz/fs/p/fs_cpio.c similarity index 100% rename from libr/fs/p/fs_cpio.c rename to librz/fs/p/fs_cpio.c diff --git a/libr/fs/p/fs_ext2.c b/librz/fs/p/fs_ext2.c similarity index 100% rename from libr/fs/p/fs_ext2.c rename to librz/fs/p/fs_ext2.c diff --git a/libr/fs/p/fs_fat.c b/librz/fs/p/fs_fat.c similarity index 100% rename from libr/fs/p/fs_fat.c rename to librz/fs/p/fs_fat.c diff --git a/libr/fs/p/fs_fb.c b/librz/fs/p/fs_fb.c similarity index 100% rename from libr/fs/p/fs_fb.c rename to librz/fs/p/fs_fb.c diff --git a/libr/fs/p/fs_grub_base.c b/librz/fs/p/fs_grub_base.c similarity index 74% rename from libr/fs/p/fs_grub_base.c rename to librz/fs/p/fs_grub_base.c index a156d7602b..d7e4350cc6 100644 --- a/libr/fs/p/fs_grub_base.c +++ b/librz/fs/p/fs_grub_base.c @@ -1,18 +1,18 @@ /* radare - LGPL - Copyright 2011-2020 - pancake */ -#include +#include #include "grubfs.h" #if WITH_GPL -static RFSFile* FSP(_open)(RFSRoot *root, const char *path, bool create) { - RFSFile *file = r_fs_file_new (root, path); +static RzFSFile* FSP(_open)(RzFSRoot *root, const char *path, bool create) { + RzFSFile *file = rz_fs_file_new (root, path); GrubFS *gfs = grubfs_new (&FSIPTR, &root->iob); file->ptr = gfs; file->p = root->p; grubfs_bind_io (NULL, file->root->delta); if (gfs->file->fs->open (gfs->file, path)) { - r_fs_file_free (file); + rz_fs_file_free (file); grubfs_free (gfs); file = NULL; } else { @@ -22,7 +22,7 @@ static RFSFile* FSP(_open)(RFSRoot *root, const char *path, bool create) { return file; } -static bool FSP(_read)(RFSFile *file, ut64 addr, int len) { +static bool FSP(_read)(RzFSFile *file, ut64 addr, int len) { GrubFS *gfs = file->ptr; grubfs_bind_io (NULL, file->root->delta); gfs->file->fs->read (gfs->file, (char*)file->data, len); @@ -30,33 +30,33 @@ static bool FSP(_read)(RFSFile *file, ut64 addr, int len) { return false; } -static void FSP(_close)(RFSFile *file) { +static void FSP(_close)(RzFSFile *file) { GrubFS *gfs = file->ptr; gfs->file->fs->close (gfs->file); } -static RList *list = NULL; +static RzList *list = NULL; static int dirhook (const char *filename, const struct grub_dirhook_info *info, void *closure) { - RFSFile *fsf = r_fs_file_new (NULL, filename); + RzFSFile *fsf = rz_fs_file_new (NULL, filename); fsf->type = info->dir? 'd':'f'; fsf->time = info->mtime; - r_list_append (list, fsf); + rz_list_append (list, fsf); //info->mtimeset //info->case_insensitive //printf ("DIRFILE: %c (%d) %s\n", info->dir?'d':'f', info->mtime, filename); return 0; } -static RList *FSP(_dir)(RFSRoot *root, const char *path, int view) { +static RzList *FSP(_dir)(RzFSRoot *root, const char *path, int view) { GrubFS *gfs; if (!root) return NULL; gfs = root->ptr; - list = r_list_new (); -// eprintf ("r_fs_???_dir: %s\n", path); + list = rz_list_new (); +// eprintf ("rz_fs_???_dir: %s\n", path); //gfs->file->device->data = &root->iob; grubfs_bind_io (&root->iob, root->delta); gfs->file->fs->dir (gfs->file->device, path, dirhook, 0); @@ -66,7 +66,7 @@ static RList *FSP(_dir)(RFSRoot *root, const char *path, int view) { static int do_nothing (const char *a, const struct grub_dirhook_info *b, void *c) { return 0; } -static int FSP(_mount)(RFSRoot *root) { +static int FSP(_mount)(RzFSRoot *root) { int ret; GrubFS *gfs = grubfs_new (&FSIPTR, &root->iob); root->ptr = gfs; @@ -78,12 +78,12 @@ static int FSP(_mount)(RFSRoot *root) { return ret; } -static void FSP(_umount)(RFSRoot *root) { +static void FSP(_umount)(RzFSRoot *root) { grubfs_free (root->ptr); root->ptr = NULL; } -RFSPlugin FSS(r_fs_plugin) = { +RzFSPlugin FSS(rz_fs_plugin) = { .name = FSNAME, .desc = FSDESC, .license = "GPL2", @@ -95,7 +95,7 @@ RFSPlugin FSS(r_fs_plugin) = { .umount = FSP(_umount), }; #else -RFSPlugin FSS(r_fs_plugin) = { +RzFSPlugin FSS(rz_fs_plugin) = { .name = FSNAME, .desc = FSDESC, }; diff --git a/libr/fs/p/fs_hfs.c b/librz/fs/p/fs_hfs.c similarity index 100% rename from libr/fs/p/fs_hfs.c rename to librz/fs/p/fs_hfs.c diff --git a/libr/fs/p/fs_hfsplus.c b/librz/fs/p/fs_hfsplus.c similarity index 100% rename from libr/fs/p/fs_hfsplus.c rename to librz/fs/p/fs_hfsplus.c diff --git a/libr/fs/p/fs_io.c b/librz/fs/p/fs_io.c similarity index 63% rename from libr/fs/p/fs_io.c rename to librz/fs/p/fs_io.c index 6e1bd7eabc..3d93f8ee18 100644 --- a/libr/fs/p/fs_io.c +++ b/librz/fs/p/fs_io.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2017-2019 - pancake */ -#include -#include +#include +#include #include -static RFSFile *fs_io_open(RFSRoot *root, const char *path, bool create) { - char *cmd = r_str_newf ("m %s", path); +static RzFSFile *fs_io_open(RzFSRoot *root, const char *path, bool create) { + char *cmd = rz_str_newf ("m %s", path); char *res = root->iob.system (root->iob.io, cmd); R_FREE (cmd); if (res) { @@ -17,7 +17,7 @@ static RFSFile *fs_io_open(RFSRoot *root, const char *path, bool create) { if (size == 0) { return NULL; } - RFSFile *file = r_fs_file_new (root, path); + RzFSFile *file = rz_fs_file_new (root, path); if (!file) { return NULL; } @@ -29,13 +29,13 @@ static RFSFile *fs_io_open(RFSRoot *root, const char *path, bool create) { return NULL; } -static bool fs_io_read(RFSFile *file, ut64 addr, int len) { - RFSRoot *root = file->root; - char *abs_path = r_fs_file_copy_abs_path (file); +static bool fs_io_read(RzFSFile *file, ut64 addr, int len) { + RzFSRoot *root = file->root; + char *abs_path = rz_fs_file_copy_abs_path (file); if (!abs_path) { return false; } - char *cmd = r_str_newf ("mg %s", abs_path); + char *cmd = rz_str_newf ("mg %s", abs_path); R_FREE (abs_path); if (!cmd) { return false; @@ -54,7 +54,7 @@ static bool fs_io_read(RFSFile *file, ut64 addr, int len) { R_FREE (res); return false; } - int ret = r_hex_str2bin (res, file->data); + int ret = rz_hex_str2bin (res, file->data); if (ret != len) { eprintf ("Inconsistent read\n"); R_FREE (file->data); @@ -64,31 +64,31 @@ static bool fs_io_read(RFSFile *file, ut64 addr, int len) { return false; } -static void fs_io_close(RFSFile *file) { +static void fs_io_close(RzFSFile *file) { // fclose (file->ptr); } -static void append_file(RList *list, const char *name, int type, int time, ut64 size) { - RFSFile *fsf = r_fs_file_new (NULL, name); +static void append_file(RzList *list, const char *name, int type, int time, ut64 size) { + RzFSFile *fsf = rz_fs_file_new (NULL, name); if (!fsf) { return; } fsf->type = type; fsf->time = time; fsf->size = size; - r_list_append (list, fsf); + rz_list_append (list, fsf); } -static RList *fs_io_dir(RFSRoot *root, const char *path, int view /*ignored*/) { - RList *list = r_list_new (); +static RzList *fs_io_dir(RzFSRoot *root, const char *path, int view /*ignored*/) { + RzList *list = rz_list_new (); if (!list) { return NULL; } - char *cmd = r_str_newf ("md %s", path); + char *cmd = rz_str_newf ("md %s", path); char *res = root->iob.system (root->iob.io, cmd); if (res) { size_t i, count = 0; - size_t *lines = r_str_split_lines (res, &count); + size_t *lines = rz_str_split_lines (res, &count); if (lines) { for (i = 0; i < count; i++) { const char *line = res + lines[i]; @@ -110,18 +110,18 @@ static RList *fs_io_dir(RFSRoot *root, const char *path, int view /*ignored*/) { return list; } -static int fs_io_mount(RFSRoot *root) { +static int fs_io_mount(RzFSRoot *root) { root->ptr = NULL; return true; } -static void fs_io_umount(RFSRoot *root) { +static void fs_io_umount(RzFSRoot *root) { root->ptr = NULL; } -RFSPlugin r_fs_plugin_io = { +RzFSPlugin rz_fs_plugin_io = { .name = "io", - .desc = "r_io based filesystem", + .desc = "rz_io based filesystem", .license = "MIT", .open = fs_io_open, .read = fs_io_read, @@ -132,9 +132,9 @@ RFSPlugin r_fs_plugin_io = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_FS, - .data = &r_fs_plugin_io, + .data = &rz_fs_plugin_io, .version = R2_VERSION }; #endif diff --git a/libr/fs/p/fs_iso9660.c b/librz/fs/p/fs_iso9660.c similarity index 100% rename from libr/fs/p/fs_iso9660.c rename to librz/fs/p/fs_iso9660.c diff --git a/libr/fs/p/fs_jfs.c b/librz/fs/p/fs_jfs.c similarity index 100% rename from libr/fs/p/fs_jfs.c rename to librz/fs/p/fs_jfs.c diff --git a/libr/fs/p/fs_minix.c b/librz/fs/p/fs_minix.c similarity index 100% rename from libr/fs/p/fs_minix.c rename to librz/fs/p/fs_minix.c diff --git a/libr/fs/p/fs_ntfs.c b/librz/fs/p/fs_ntfs.c similarity index 100% rename from libr/fs/p/fs_ntfs.c rename to librz/fs/p/fs_ntfs.c diff --git a/libr/fs/p/fs_posix.c b/librz/fs/p/fs_posix.c similarity index 66% rename from libr/fs/p/fs_posix.c rename to librz/fs/p/fs_posix.c index d074276660..273dcbfcb9 100644 --- a/libr/fs/p/fs_posix.c +++ b/librz/fs/p/fs_posix.c @@ -1,45 +1,45 @@ /* radare - LGPL - Copyright 2011-2017 - pancake */ -#include -#include +#include +#include #include #ifdef _MSC_VER #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define MAXPATHLEN 255 #endif -static RFSFile* fs_posix_open(RFSRoot *root, const char *path, bool create) { +static RzFSFile* fs_posix_open(RzFSRoot *root, const char *path, bool create) { FILE *fd; - RFSFile *file = r_fs_file_new (root, path); + RzFSFile *file = rz_fs_file_new (root, path); if (!file) { return NULL; } file->ptr = NULL; file->p = root->p; - fd = r_sandbox_fopen (path, create? "wb": "rb"); + fd = rz_sandbox_fopen (path, create? "wb": "rb"); if (fd) { fseek (fd, 0, SEEK_END); file->size = ftell (fd); fclose (fd); } else { - r_fs_file_free (file); + rz_fs_file_free (file); file = NULL; } return file; } -static bool fs_posix_read(RFSFile *file, ut64 addr, int len) { +static bool fs_posix_read(RzFSFile *file, ut64 addr, int len) { free (file->data); - file->data = (void*)r_file_slurp_range (file->name, 0, len, NULL); + file->data = (void*)rz_file_slurp_range (file->name, 0, len, NULL); return false; } -static void fs_posix_close(RFSFile *file) { +static void fs_posix_close(RzFSFile *file) { //fclose (file->ptr); } -static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/) { - RList *list; +static RzList *fs_posix_dir(RzFSRoot *root, const char *path, int view /*ignored*/) { + RzList *list; char fullpath[4096]; struct stat st; #if __WINDOWS__ @@ -52,12 +52,12 @@ static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/ struct dirent *de; DIR *dir; #endif - list = r_list_new (); + list = rz_list_new (); if (!list) { return NULL; } #if __WINDOWS__ - wcpath = r_utf8_to_utf16 (path); + wcpath = rz_utf8_to_utf16 (path); if (!wcpath) { return NULL; } @@ -68,10 +68,10 @@ static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/ return NULL; } do { - if ((wctocbuff = r_utf16_to_utf8 (entry.cFileName))) { - RFSFile *fsf = r_fs_file_new (NULL, wctocbuff); + if ((wctocbuff = rz_utf16_to_utf8 (entry.cFileName))) { + RzFSFile *fsf = rz_fs_file_new (NULL, wctocbuff); if (!fsf) { - r_list_free (list); + rz_list_free (list); FindClose (fh); return NULL; } @@ -84,7 +84,7 @@ static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/ fsf->type = 'f'; fsf->time = 0; } - r_list_append (list, fsf); + rz_list_append (list, fsf); free (wctocbuff); } @@ -93,13 +93,13 @@ static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/ #else dir = opendir (path); if (!dir) { - r_list_free (list); + rz_list_free (list); return NULL; } while ((de = readdir (dir))) { - RFSFile *fsf = r_fs_file_new (NULL, de->d_name); + RzFSFile *fsf = rz_fs_file_new (NULL, de->d_name); if (!fsf) { - r_list_free (list); + rz_list_free (list); closedir (dir); return NULL; } @@ -112,23 +112,23 @@ static RList *fs_posix_dir(RFSRoot *root, const char *path, int view /*ignored*/ fsf->type = 'f'; fsf->time = 0; } - r_list_append (list, fsf); + rz_list_append (list, fsf); } closedir (dir); #endif return list; } -static int fs_posix_mount(RFSRoot *root) { +static int fs_posix_mount(RzFSRoot *root) { root->ptr = NULL; // XXX: TODO return true; } -static void fs_posix_umount(RFSRoot *root) { +static void fs_posix_umount(RzFSRoot *root) { root->ptr = NULL; } -RFSPlugin r_fs_plugin_posix = { +RzFSPlugin rz_fs_plugin_posix = { .name = "posix", .desc = "POSIX filesystem", .license = "MIT", @@ -141,9 +141,9 @@ RFSPlugin r_fs_plugin_posix = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_FS, - .data = &r_fs_plugin_posix, + .data = &rz_fs_plugin_posix, .version = R2_VERSION }; #endif diff --git a/libr/fs/p/fs_reiserfs.c b/librz/fs/p/fs_reiserfs.c similarity index 85% rename from libr/fs/p/fs_reiserfs.c rename to librz/fs/p/fs_reiserfs.c index 872fa90a98..d42c02da7e 100644 --- a/libr/fs/p/fs_reiserfs.c +++ b/librz/fs/p/fs_reiserfs.c @@ -3,7 +3,7 @@ #define FSP(x) reiserfs_##x #define FSS(x) x##_reiserfs #define FSNAME "reiserfs" -#define FSDESC "REISERFS filesystem" +#define FSDESC "REISERzFS filesystem" #define FSPRFX reiserfs #define FSIPTR grub_reiserfs_fs diff --git a/libr/fs/p/fs_r2.c b/librz/fs/p/fs_rz.c similarity index 59% rename from libr/fs/p/fs_r2.c rename to librz/fs/p/fs_rz.c index 9defdaec3e..9c9f627668 100644 --- a/libr/fs/p/fs_r2.c +++ b/librz/fs/p/fs_rz.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2017-2019 - pancake */ -#include -#include +#include +#include #include -typedef RList *(*DirHandler)(RFSRoot *root, const char *path); -typedef RFSFile *(*CatHandler)(RFSRoot *root, RFSFile *file, const char *path); -typedef bool (*WriteHandler)(RFSFile *file, ut64 addr, const ut8 *data, int len); +typedef RzList *(*DirHandler)(RzFSRoot *root, const char *path); +typedef RzFSFile *(*CatHandler)(RzFSRoot *root, RzFSFile *file, const char *path); +typedef bool (*WriteHandler)(RzFSFile *file, ut64 addr, const ut8 *data, int len); typedef struct { const char *path; @@ -16,17 +16,17 @@ typedef struct { WriteHandler write; } Routes; -static RFSFile *__flags_cat(RFSRoot *root, RFSFile *file, const char *path); -static RFSFile *__cfg_cat(RFSRoot *root, RFSFile *file, const char *path); -static RFSFile *__seek_cat(RFSRoot *root, RFSFile *file, const char *path); -static RFSFile *__bsize_cat(RFSRoot *root, RFSFile *file, const char *path); -static bool __cfg_write(RFSFile *file, ut64 addr, const ut8 *data, int len); -static bool __seek_write(RFSFile *file, ut64 addr, const ut8 *data, int len); -static bool __bsize_write(RFSFile *file, ut64 addr, const ut8 *data, int len); -static RFSFile *__version(RFSRoot *root, RFSFile *file, const char *path); -static RList *__root(RFSRoot *root, const char *path); -static RList *__cfg(RFSRoot *root, const char *path); -static RList *__flags(RFSRoot *root, const char *path); +static RzFSFile *__flags_cat(RzFSRoot *root, RzFSFile *file, const char *path); +static RzFSFile *__cfg_cat(RzFSRoot *root, RzFSFile *file, const char *path); +static RzFSFile *__seek_cat(RzFSRoot *root, RzFSFile *file, const char *path); +static RzFSFile *__bsize_cat(RzFSRoot *root, RzFSFile *file, const char *path); +static bool __cfg_write(RzFSFile *file, ut64 addr, const ut8 *data, int len); +static bool __seek_write(RzFSFile *file, ut64 addr, const ut8 *data, int len); +static bool __bsize_write(RzFSFile *file, ut64 addr, const ut8 *data, int len); +static RzFSFile *__version(RzFSRoot *root, RzFSFile *file, const char *path); +static RzList *__root(RzFSRoot *root, const char *path); +static RzList *__cfg(RzFSRoot *root, const char *path); +static RzList *__flags(RzFSRoot *root, const char *path); static Routes routes[] = { {"/cfg", &__cfg, &__cfg_cat, &__cfg_write }, @@ -38,30 +38,30 @@ static Routes routes[] = { {NULL, NULL} }; -static void append_file(RList *list, const char *name, int type, int time, ut64 size) { +static void append_file(RzList *list, const char *name, int type, int time, ut64 size) { if (!list || !name || !*name) { return; } - RFSFile *fsf = r_fs_file_new (NULL, name); + RzFSFile *fsf = rz_fs_file_new (NULL, name); if (!fsf) { return; } fsf->type = type; fsf->time = time; fsf->size = size; - r_list_append (list, fsf); + rz_list_append (list, fsf); } -static RList *fscmd(RFSRoot *root, const char *cmd, int type) { +static RzList *fscmd(RzFSRoot *root, const char *cmd, int type) { char *res = root->cob.cmdstr (root->cob.core, cmd); if (res) { - RList *list = r_list_newf (free); + RzList *list = rz_list_newf (free); if (!list) { free (res); return NULL; } size_t i, count = 0; - size_t *lines = r_str_split_lines (res, &count); + size_t *lines = rz_str_split_lines (res, &count); if (lines) { for (i = 0; i < count; i++) { append_file (list, res + lines[i], type, 0, 0); @@ -74,7 +74,7 @@ static RList *fscmd(RFSRoot *root, const char *cmd, int type) { return NULL; } -static RFSFile* fs_r2_open(RFSRoot *root, const char *path, bool create) { +static RzFSFile* fs_rz_open(RzFSRoot *root, const char *path, bool create) { int i; for (i = 0; routes[i].path; i++) { const char *cwd = routes[i].path; @@ -85,7 +85,7 @@ static RFSFile* fs_r2_open(RFSRoot *root, const char *path, bool create) { return NULL; } -static bool fs_r2_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { +static bool fs_rz_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) { int i; const char *path = file->path; const char *name = file->name; @@ -102,7 +102,7 @@ static bool fs_r2_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { return false; } -static bool fs_r2_read(RFSFile *file, ut64 addr, int len) { +static bool fs_rz_read(RzFSFile *file, ut64 addr, int len) { int i; const char *path = file->name; for (i = 0; routes[i].path; i++) { @@ -113,16 +113,16 @@ static bool fs_r2_read(RFSFile *file, ut64 addr, int len) { return false; } -static void fs_r2_close(RFSFile *file) { +static void fs_rz_close(RzFSFile *file) { // eprintf ("TODO: fs.r2.close\n"); //fclose (file->ptr); } -static RFSFile *__version(RFSRoot *root, RFSFile *file, const char *path) { +static RzFSFile *__version(RzFSRoot *root, RzFSFile *file, const char *path) { char *res = root->cob.cmdstrf (root->cob.core, "?V"); /// root->iob.io->cb_printf ("%s\n", res); if (!file) { - file = r_fs_file_new (root, path); + file = rz_fs_file_new (root, path); } file->ptr = NULL; free (file->data); @@ -132,9 +132,9 @@ static RFSFile *__version(RFSRoot *root, RFSFile *file, const char *path) { return file; } -static RFSFile *__flags_cat(RFSRoot *root, RFSFile *file, const char *path) { - r_return_val_if_fail (root && path, NULL); - const char *last = r_str_rchr (path, NULL, '/'); +static RzFSFile *__flags_cat(RzFSRoot *root, RzFSFile *file, const char *path) { + rz_return_val_if_fail (root && path, NULL); + const char *last = rz_str_rchr (path, NULL, '/'); if (last) { last++; } else { @@ -147,7 +147,7 @@ static RFSFile *__flags_cat(RFSRoot *root, RFSFile *file, const char *path) { file->p = root->p; file->size = strlen (res); } else { - file = r_fs_file_new (root, path); + file = rz_fs_file_new (root, path); file->ptr = NULL; file->data = (ut8*)res; file->p = root->p; @@ -156,17 +156,17 @@ static RFSFile *__flags_cat(RFSRoot *root, RFSFile *file, const char *path) { return file; } -static bool __bsize_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { +static bool __bsize_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) { void *core = file->root->cob.core; char *res = file->root->cob.cmdstrf (core, "b %s", data); free (res); return true; } -static RFSFile *__bsize_cat(RFSRoot *root, RFSFile *file, const char *path) { +static RzFSFile *__bsize_cat(RzFSRoot *root, RzFSFile *file, const char *path) { char *res = root->cob.cmdstrf (root->cob.core, "b"); if (!file) { - file = r_fs_file_new (root, path); + file = rz_fs_file_new (root, path); } file->ptr = NULL; file->data = (ut8*)res; @@ -175,17 +175,17 @@ static RFSFile *__bsize_cat(RFSRoot *root, RFSFile *file, const char *path) { return file; } -static bool __seek_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { +static bool __seek_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) { void *core = file->root->cob.core; char *res = file->root->cob.cmdstrf (core, "s %s", data); free (res); return true; } -static RFSFile *__seek_cat(RFSRoot *root, RFSFile *file, const char *path) { +static RzFSFile *__seek_cat(RzFSRoot *root, RzFSFile *file, const char *path) { char *res = root->cob.cmdstrf (root->cob.core, "s"); if (!file) { - file = r_fs_file_new (root, path); + file = rz_fs_file_new (root, path); } file->ptr = NULL; file->data = (ut8*)res; @@ -194,7 +194,7 @@ static RFSFile *__seek_cat(RFSRoot *root, RFSFile *file, const char *path) { return file; } -static bool __cfg_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { +static bool __cfg_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) { const char *a = file->name; void *core = file->root->cob.core; char *prefix = strdup (file->path + strlen ("/cfg/")); @@ -204,17 +204,17 @@ static bool __cfg_write(RFSFile *file, ut64 addr, const ut8 *data, int len) { return true; } -static RFSFile *__cfg_cat(RFSRoot *root, RFSFile *file, const char *path) { +static RzFSFile *__cfg_cat(RzFSRoot *root, RzFSFile *file, const char *path) { if (strlen (path) < 6) { return NULL; } char *a = strdup (path + 5); - r_str_replace_char (a, '/', '.'); + rz_str_replace_char (a, '/', '.'); char *res = root->cob.cmdstrf (root->cob.core, "e %s", a); // root->iob.io->cb_printf ("%s\n", res); // eprintf ("%s", res); if (!file) { - file = r_fs_file_new (root, path); + file = rz_fs_file_new (root, path); } file->ptr = NULL; file->data = (ut8*)res; @@ -223,37 +223,37 @@ static RFSFile *__cfg_cat(RFSRoot *root, RFSFile *file, const char *path) { return file; } -static RList *__flags(RFSRoot *root, const char *path) { +static RzList *__flags(RzFSRoot *root, const char *path) { const char *prefix = NULL; if (!strncmp (path, "/flags/", 7)) { prefix = path + 7; } char *cmd = prefix - ? r_str_newf ("fq@F:%s", prefix) + ? rz_str_newf ("fq@F:%s", prefix) : strdup ("fsq"); - RList *res = fscmd (root, cmd, prefix? 'f': 'd'); + RzList *res = fscmd (root, cmd, prefix? 'f': 'd'); free (cmd); return res; } -static RList *__cfg(RFSRoot *root, const char *path) { +static RzList *__cfg(RzFSRoot *root, const char *path) { const char *prefix = NULL; if (!strncmp (path, "/cfg/", 5)) { prefix = path + 5; } char *cmd = prefix - ? r_str_newf ("es %s", prefix) + ? rz_str_newf ("es %s", prefix) : strdup ("es"); char *res = root->cob.cmdstr (root->cob.core, cmd); free (cmd); if (res) { - RList *list = r_list_new (); + RzList *list = rz_list_new (); if (!list) { free (res); return NULL; } size_t i, count = 0; - size_t *lines = r_str_split_lines (res, &count); + size_t *lines = rz_str_split_lines (res, &count); if (lines) { for (i = 0; i < count; i++) { char *line = res + lines[i]; @@ -267,8 +267,8 @@ static RList *__cfg(RFSRoot *root, const char *path) { return NULL; } -static RList *__root(RFSRoot *root, const char *path) { - RList *list = r_list_newf (NULL); +static RzList *__root(RzFSRoot *root, const char *path) { + RzList *list = rz_list_newf (NULL); if (!list) { return NULL; } @@ -280,7 +280,7 @@ static RList *__root(RFSRoot *root, const char *path) { return list; } -static RList *fs_r2_dir(RFSRoot *root, const char *path, int view /*ignored*/) { +static RzList *fs_rz_dir(RzFSRoot *root, const char *path, int view /*ignored*/) { int i; for (i = 0; routes[i].path; i++) { if (routes[i].dir && !strncmp (path, routes[i].path, strlen (routes[i].path))) { @@ -290,32 +290,32 @@ static RList *fs_r2_dir(RFSRoot *root, const char *path, int view /*ignored*/) { return NULL; } -static int fs_r2_mount(RFSRoot *root) { +static int fs_rz_mount(RzFSRoot *root) { root->ptr = NULL; return true; } -static void fs_r2_umount(RFSRoot *root) { +static void fs_rz_umount(RzFSRoot *root) { root->ptr = NULL; } -RFSPlugin r_fs_plugin_r2 = { +RzFSPlugin rz_fs_plugin_rz = { .name = "r2", .desc = "r2-based filesystem", .license = "MIT", - .open = fs_r2_open, // open == read - .read = fs_r2_read, // read == open - .write = fs_r2_write, - .close = fs_r2_close, - .dir = &fs_r2_dir, - .mount = fs_r2_mount, - .umount = fs_r2_umount, + .open = fs_rz_open, // open == read + .read = fs_rz_read, // read == open + .write = fs_rz_write, + .close = fs_rz_close, + .dir = &fs_rz_dir, + .mount = fs_rz_mount, + .umount = fs_rz_umount, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_FS, - .data = &r_fs_plugin_r2, + .data = &rz_fs_plugin_rz, .versr2n = R2_VERSION }; #endif diff --git a/libr/fs/p/fs_sfs.c b/librz/fs/p/fs_sfs.c similarity index 100% rename from libr/fs/p/fs_sfs.c rename to librz/fs/p/fs_sfs.c diff --git a/libr/fs/p/fs_tar.c b/librz/fs/p/fs_tar.c similarity index 100% rename from libr/fs/p/fs_tar.c rename to librz/fs/p/fs_tar.c diff --git a/libr/fs/p/fs_udf.c b/librz/fs/p/fs_udf.c similarity index 100% rename from libr/fs/p/fs_udf.c rename to librz/fs/p/fs_udf.c diff --git a/libr/fs/p/fs_ufs.c b/librz/fs/p/fs_ufs.c similarity index 100% rename from libr/fs/p/fs_ufs.c rename to librz/fs/p/fs_ufs.c diff --git a/libr/fs/p/fs_ufs2.c b/librz/fs/p/fs_ufs2.c similarity index 100% rename from libr/fs/p/fs_ufs2.c rename to librz/fs/p/fs_ufs2.c diff --git a/libr/fs/p/fs_xfs.c b/librz/fs/p/fs_xfs.c similarity index 100% rename from libr/fs/p/fs_xfs.c rename to librz/fs/p/fs_xfs.c diff --git a/libr/fs/p/hfs.mk b/librz/fs/p/hfs.mk similarity index 100% rename from libr/fs/p/hfs.mk rename to librz/fs/p/hfs.mk diff --git a/libr/fs/p/hfsplus.mk b/librz/fs/p/hfsplus.mk similarity index 100% rename from libr/fs/p/hfsplus.mk rename to librz/fs/p/hfsplus.mk diff --git a/libr/fs/p/io.mk b/librz/fs/p/io.mk similarity index 100% rename from libr/fs/p/io.mk rename to librz/fs/p/io.mk diff --git a/libr/fs/p/iso9660.mk b/librz/fs/p/iso9660.mk similarity index 100% rename from libr/fs/p/iso9660.mk rename to librz/fs/p/iso9660.mk diff --git a/libr/fs/p/jfs.mk b/librz/fs/p/jfs.mk similarity index 100% rename from libr/fs/p/jfs.mk rename to librz/fs/p/jfs.mk diff --git a/libr/fs/p/makeplugin.sh b/librz/fs/p/makeplugin.sh similarity index 100% rename from libr/fs/p/makeplugin.sh rename to librz/fs/p/makeplugin.sh diff --git a/libr/fs/p/minix.mk b/librz/fs/p/minix.mk similarity index 100% rename from libr/fs/p/minix.mk rename to librz/fs/p/minix.mk diff --git a/libr/fs/p/ntfs.mk b/librz/fs/p/ntfs.mk similarity index 100% rename from libr/fs/p/ntfs.mk rename to librz/fs/p/ntfs.mk diff --git a/libr/fs/p/part_dos.c b/librz/fs/p/part_dos.c similarity index 78% rename from libr/fs/p/part_dos.c rename to librz/fs/p/part_dos.c index 2c98c2b456..ced16276a2 100644 --- a/libr/fs/p/part_dos.c +++ b/librz/fs/p/part_dos.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2015-2017 - pancake */ +/* rizin - LGPL - Copyright 2015-2017 - pancake */ /* XXX: maybe this should be implemented in RBin */ /* we need to extract the code section and get offset flags */ -#include -#include +#include +#include R_PACKED ( typedef struct { ut8 flag; // 0x80 if active @@ -28,16 +28,16 @@ typedef struct { static int fs_part_dos(void *disk, void *ptr, void *closure) { int i; MBR mbr; - RFS *fs = (RFS*)disk; - RFSPartition *par = NULL; - RFSPartitionIterator iterate = (RFSPartitionIterator)ptr; - RList *list = (RList*)closure; + RzFS *fs = (RzFS*)disk; + RzFSPartition *par = NULL; + RzFSPartitionIterator iterate = (RzFSPartitionIterator)ptr; + RzList *list = (RzList*)closure; memset (&mbr, 0, sizeof (mbr)); fs->iob.read_at (fs->iob.io, 0, (ut8*)&mbr, sizeof (mbr)); if (mbr.aa55 != 0xaa55) { eprintf ("Invalid DOS signature at 0x%x\n", - (int)r_offsetof (MBR, aa55)); + (int)rz_offsetof (MBR, aa55)); return 0; } for (i=0; i<4; i++) { @@ -51,7 +51,7 @@ static int fs_part_dos(void *disk, void *ptr, void *closure) { aend = 0; //e->start; aend += e->length; aend *= 512; - par = r_fs_partition_new (i, addr, aend); + par = rz_fs_partition_new (i, addr, aend); par->index = 0; par->type = e->type; iterate (disk, par, list); diff --git a/libr/fs/p/posix.mk b/librz/fs/p/posix.mk similarity index 100% rename from libr/fs/p/posix.mk rename to librz/fs/p/posix.mk diff --git a/librz/fs/p/reiserfs.mk b/librz/fs/p/reiserfs.mk new file mode 100644 index 0000000000..8755463eec --- /dev/null +++ b/librz/fs/p/reiserfs.mk @@ -0,0 +1,12 @@ +OBJ_REISERzFS=fs_reiserfs.o +EXTRA=$(GRUB) +CFLAGS+=-Igrub/include + +STATIC_OBJ+=${OBJ_REISERzFS} +#STATIC_OBJ+=${EXTRA} +TARGET_REISERzFS=fs_reiserfs.${EXT_SO} + +ALL_TARGETS+=${TARGET_REISERzFS} + +${TARGET_REISERzFS}: ${OBJ_REISERzFS} + ${CC} $(call libname,fs_reiserfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_REISERzFS} ${OBJ_REISERzFS} ${EXTRA} diff --git a/librz/fs/p/rz.mk b/librz/fs/p/rz.mk new file mode 100644 index 0000000000..c1e02de9bd --- /dev/null +++ b/librz/fs/p/rz.mk @@ -0,0 +1,9 @@ +OBJ_R2=fs_rz.o + +STATIC_OBJ+=${OBJ_R2} +TARGET_R2=fs_rz.${EXT_SO} + +ALL_TARGETS+=${TARGET_R2} + +${TARGET_R2}: ${OBJ_R2} + ${CC} $(call libname,fs_rz) ${LDFLAGS} ${CFLAGS} -o ${TARGET_R2} ${OBJ_R2} ${EXTRA} diff --git a/libr/fs/p/sfs.mk b/librz/fs/p/sfs.mk similarity index 100% rename from libr/fs/p/sfs.mk rename to librz/fs/p/sfs.mk diff --git a/libr/fs/p/tar.mk b/librz/fs/p/tar.mk similarity index 100% rename from libr/fs/p/tar.mk rename to librz/fs/p/tar.mk diff --git a/libr/fs/p/udf.mk b/librz/fs/p/udf.mk similarity index 100% rename from libr/fs/p/udf.mk rename to librz/fs/p/udf.mk diff --git a/libr/fs/p/ufs.mk b/librz/fs/p/ufs.mk similarity index 100% rename from libr/fs/p/ufs.mk rename to librz/fs/p/ufs.mk diff --git a/libr/fs/p/ufs2.mk b/librz/fs/p/ufs2.mk similarity index 100% rename from libr/fs/p/ufs2.mk rename to librz/fs/p/ufs2.mk diff --git a/libr/fs/p/xfs.mk b/librz/fs/p/xfs.mk similarity index 100% rename from libr/fs/p/xfs.mk rename to librz/fs/p/xfs.mk diff --git a/libr/fs/shell.c b/librz/fs/shell.c similarity index 72% rename from libr/fs/shell.c rename to librz/fs/shell.c index 6266a26fcb..98f403680b 100644 --- a/libr/fs/shell.c +++ b/librz/fs/shell.c @@ -1,56 +1,56 @@ -/* radare2 - LGPL - Copyright 2018-2020 - pancake */ +/* rizin - LGPL - Copyright 2018-2020 - pancake */ -#include +#include #define PROMPT_PATH_BUFSIZE 1024 -static bool handlePipes(RFS *fs, char *msg, const ut8 *data, const char *cwd) { +static bool handlePipes(RzFS *fs, char *msg, const ut8 *data, const char *cwd) { char *red = strchr (msg, '>'); if (!red) { return false; } *red++ = 0; - r_str_trim (msg); - red = r_str_trim_dup (red); + rz_str_trim (msg); + red = rz_str_trim_dup (red); if (*red != '/') { - char *blu = r_str_newf ("%s/%s", cwd, red); + char *blu = rz_str_newf ("%s/%s", cwd, red); free (red); red = blu; } - RFSFile *f = r_fs_open (fs, red, true); + RzFSFile *f = rz_fs_open (fs, red, true); if (!f) { eprintf ("Cannot open %s for writing\n", red); free (red); return true; } - r_fs_write (fs, f, 0, data ? data : (ut8*)msg, strlen (data ? (char*)data : msg)); + rz_fs_write (fs, f, 0, data ? data : (ut8*)msg, strlen (data ? (char*)data : msg)); free (red); - r_fs_close (fs, f); - r_fs_file_free (f); + rz_fs_close (fs, f); + rz_fs_file_free (f); return true; } -R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { +RZ_API int rz_fs_shell_prompt(RzFSShell* shell, RzFS* fs, const char* root) { char buf[PROMPT_PATH_BUFSIZE]; char path[PROMPT_PATH_BUFSIZE]; char prompt[PROMPT_PATH_BUFSIZE]; char str[2048]; char* input; const char* ptr; - RList* list = NULL; - RListIter* iter; - RFSFile* file = NULL; + RzList* list = NULL; + RzListIter* iter; + RzFSFile* file = NULL; if (root && *root) { strncpy (buf, root, sizeof (buf) - 1); - r_str_trim_path (buf); - list = r_fs_root (fs, buf); - if (r_list_empty (list)) { + rz_str_trim_path (buf); + list = rz_fs_root (fs, buf); + if (rz_list_empty (list)) { printf ("Unknown root\n"); - r_list_free (list); + rz_list_free (list); return false; } - r_str_ncpy (path, buf, sizeof (path) - 1); + rz_str_ncpy (path, buf, sizeof (path) - 1); } else { strcpy (path, "/"); } @@ -72,18 +72,18 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { if (feof (stdin)) { break; } - r_str_trim_tail (buf); + rz_str_trim_tail (buf); ptr = buf; } if (!ptr) { break; } - r_str_trim ((char *)ptr); // XXX abadidea + rz_str_trim ((char *)ptr); // XXX abadidea if (shell->hist_add) { shell->hist_add (ptr); } if (ptr != buf) { - r_str_ncpy (buf, ptr, sizeof (buf) - 1); + rz_str_ncpy (buf, ptr, sizeof (buf) - 1); } } else { printf ("%s", prompt); @@ -93,7 +93,7 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { if (feof (stdin)) { break; } - r_str_trim_tail (buf); + rz_str_trim_tail (buf); } char *wave = strchr (buf, '~'); if (wave) { @@ -101,7 +101,7 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { } if (!strcmp (buf, "q") || !strcmp (buf, "exit")) { - r_list_free (list); + rz_list_free (list); return true; } if (buf[0] == '#') { @@ -112,41 +112,41 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { printf ("%s\n", msg); free (msg); } else if (buf[0] == '!') { - r_sandbox_system (buf + 1, 1); + rz_sandbox_system (buf + 1, 1); } else if (!strncmp (buf, "echo", 4)) { - char *msg = r_str_trim_dup (buf + 4); + char *msg = rz_str_trim_dup (buf + 4); if (!handlePipes (fs, msg, NULL, path)) { cb_printf ("%s\n", msg); } free (msg); } else if (!strncmp (buf, "ls", 2)) { char *ptr = str; - r_list_free (list); + rz_list_free (list); if (buf[2] == ' ') { if (buf[3] != '/') { strncpy (str, path, sizeof (str) - 1); strcat (str, "/"); strncat (str, buf + 3, sizeof (buf) - 1); - list = r_fs_dir (fs, str); + list = rz_fs_dir (fs, str); } else { - list = r_fs_dir (fs, buf + 3); + list = rz_fs_dir (fs, buf + 3); ptr = buf + 3; } } else { ptr = path; - list = r_fs_dir (fs, path); + list = rz_fs_dir (fs, path); } if (list) { - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { cb_printf ("%c %s\n", file->type, file->name); } } // mountpoints if any - RFSRoot *r; + RzFSRoot *r; char *me = strdup (ptr); - r_list_foreach (fs->roots, iter, r) { + rz_list_foreach (fs->roots, iter, r) { char *base = strdup (r->path); - char *ls = (char *)r_str_lchr (base, '/'); + char *ls = (char *)rz_str_lchr (base, '/'); if (ls) { ls++; *ls = 0; @@ -162,13 +162,13 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { eprintf ("%s\n", path); } else if (!memcmp (buf, "cd ", 3)) { char opath[PROMPT_PATH_BUFSIZE]; - r_str_ncpy (opath, path, sizeof (opath)); + rz_str_ncpy (opath, path, sizeof (opath)); input = buf + 3; while (*input == ' ') { input++; } if (!strcmp (input, "..")) { - char* p = (char*) r_str_lchr (path, '/'); + char* p = (char*) rz_str_lchr (path, '/'); if (p) { p[(p == path)? 1: 0] = 0; } @@ -186,15 +186,15 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { } path[sizeof (path) - 1] = 0; } - r_str_trim_path (path); - r_list_free (list); - list = r_fs_dir (fs, path); - if (r_list_empty (list)) { - RFSRoot *r; - RListIter *iter; - r_list_foreach (fs->roots, iter, r) { + rz_str_trim_path (path); + rz_list_free (list); + list = rz_fs_dir (fs, path); + if (rz_list_empty (list)) { + RzFSRoot *r; + RzListIter *iter; + rz_list_foreach (fs->roots, iter, r) { if (!strcmp (path, r->path)) { - r_list_append (list, r->path); + rz_list_append (list, r->path); } } } @@ -218,25 +218,25 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { if (p) { *p = 0; } - file = r_fs_open (fs, str, false); + file = rz_fs_open (fs, str, false); if (file) { if (p) { *p = '>'; } - r_fs_read (fs, file, 0, file->size); + rz_fs_read (fs, file, 0, file->size); if (!handlePipes (fs, str, file->data, path)) { - char *s = r_str_ndup ((const char *)file->data, file->size); + char *s = rz_str_ndup ((const char *)file->data, file->size); cb_printf ("%s\n", s); free (s); } cb_printf ("\n"); - r_fs_close (fs, file); + rz_fs_close (fs, file); } else { eprintf ("Cannot open file\n"); } } else if (!memcmp (buf, "mount", 5)) { - RFSRoot* r; - r_list_foreach (fs->roots, iter, r) { + RzFSRoot* r; + rz_list_foreach (fs->roots, iter, r) { cb_printf ("%s %s\n", r->path, r->p->name); } } else if (!memcmp (buf, "get ", 4)) { @@ -268,15 +268,15 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { } strcat (s, "/"); strcat (s, input); - file = r_fs_open (fs, s, false); + file = rz_fs_open (fs, s, false); if (file) { - r_fs_read (fs, file, 0, file->size); - r_file_dump (input, file->data, file->size, 0); - r_fs_close (fs, file); + rz_fs_read (fs, file, 0, file->size); + rz_file_dump (input, file->data, file->size, 0); + rz_fs_close (fs, file); } else { input -= 2; //OMFG!!!! O_O memcpy (input, "./", 2); - if (!r_fs_dir_dump (fs, s, input)) { + if (!rz_fs_dir_dump (fs, s, input)) { eprintf ("Cannot open file\n"); } } @@ -306,7 +306,7 @@ R_API int r_fs_shell_prompt(RFSShell* shell, RFS* fs, const char* root) { beach: clearerr (stdin); printf ("\n"); - r_list_free (list); + rz_list_free (list); return true; } diff --git a/libr/fs/test.rsc b/librz/fs/test.rsc similarity index 100% rename from libr/fs/test.rsc rename to librz/fs/test.rsc diff --git a/libr/fs/types.h b/librz/fs/types.h similarity index 86% rename from libr/fs/types.h rename to librz/fs/types.h index 7fb71ae3e1..eb3b81ce33 100644 --- a/libr/fs/types.h +++ b/librz/fs/types.h @@ -1,7 +1,7 @@ #ifndef FS_TYPES_H #define FS_TYPES_H -typedef struct r_fs_type_t { +typedef struct rz_fs_type_t { const char *name; int bufoff; const char *buf; @@ -9,9 +9,9 @@ typedef struct r_fs_type_t { int byteoff; ut8 byte; int bytelen; -} RFSType; +} RzFSType; -static RFSType fstypes[] = { +static RzFSType fstypes[] = { { "hfs", 0x400, "BD", 2, 0, 0, 0x400 }, { "hfsplus", 0x400, "H+", 2, 0, 0, 0x400 }, { "fat", 0x36, "FAT12", 5, 0, 0, 0 }, diff --git a/libr/hash/Makefile b/librz/hash/Makefile similarity index 94% rename from libr/hash/Makefile rename to librz/hash/Makefile index e5274766a8..59702e25ae 100644 --- a/libr/hash/Makefile +++ b/librz/hash/Makefile @@ -1,6 +1,6 @@ include ../config.mk -NAME=r_hash +NAME=rz_hash PCLIBS=@LIBXXHASH@ # HACK ifneq ($(OSTYPE),darwin) @@ -10,7 +10,7 @@ LINK=-lm endif endif -R2DEPS=r_util +R2DEPS=rz_util OBJS=state.o hash.o hamdist.o crca.o fletcher.o OBJS+=entropy.o hcalc.o adler32.o luhn.o diff --git a/libr/hash/adler32.c b/librz/hash/adler32.c similarity index 76% rename from libr/hash/adler32.c rename to librz/hash/adler32.c index 32f84ec5a6..102c24728c 100644 --- a/libr/hash/adler32.c +++ b/librz/hash/adler32.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2013-2016 pancake */ -#include +#include -R_API ut32 r_hash_adler32(const ut8 *data, int len) { +RZ_API ut32 rz_hash_adler32(const ut8 *data, int len) { static const int MOD_ADLER = 65521; ut32 a = 1, b = 0; int index; diff --git a/libr/hash/crca.c b/librz/hash/crca.c similarity index 98% rename from libr/hash/crca.c rename to librz/hash/crca.c index 5311f701fa..3a72f58d5c 100644 --- a/libr/hash/crca.c +++ b/librz/hash/crca.c @@ -2,7 +2,7 @@ //license: the very same than radare, blah, blah //some definitions and test cases borrowed from http://www.nightmare.com/~ryb/code/CrcMoose.py (Ray Burr) -#include +#include void crc_init (R_CRC_CTX *ctx, utcrc crc, ut32 size, int reflect, utcrc poly, utcrc xout) { ctx->crc = crc; @@ -55,7 +55,7 @@ static void crc_final (R_CRC_CTX *ctx, utcrc *r) { #define CRC_PRESET(crc, size, reflect, poly, xout) \ { UTCRC_C(crc), (size), (reflect), UTCRC_C(poly), UTCRC_C(xout) } -/* NOTE: Run `rahash2 -a -s 123456789` to test CRC. */ +/* NOTE: Run `rz_hash -a -s 123456789` to test CRC. */ R_CRC_CTX crc_presets[] = { CRC_PRESET (0x00 , 8, 0, 0x07 , 0x00 ), //CRC-8-SMBUS, test vector for "1234567892: f4 #if R_HAVE_CRC8_EXTRA @@ -137,7 +137,7 @@ void crc_init_preset (R_CRC_CTX *ctx, enum CRC_PRESETS preset) { ctx->xout = crc_presets[preset].xout; } -utcrc r_hash_crc_preset (const ut8 *data, ut32 size, enum CRC_PRESETS preset) { +utcrc rz_hash_crc_preset (const ut8 *data, ut32 size, enum CRC_PRESETS preset) { if (!data || !size || preset >= CRC_PRESET_SIZE) { return 0; } diff --git a/libr/hash/entropy.c b/librz/hash/entropy.c similarity index 71% rename from libr/hash/entropy.c rename to librz/hash/entropy.c index afaed5ff12..654b5ff672 100644 --- a/libr/hash/entropy.c +++ b/librz/hash/entropy.c @@ -7,9 +7,9 @@ #include #include -#include "r_types.h" +#include "rz_types.h" -R_API double r_hash_entropy(const ut8 *data, ut64 size) { +RZ_API double rz_hash_entropy(const ut8 *data, ut64 size) { if (!data || !size) { return 0; } @@ -26,7 +26,7 @@ R_API double r_hash_entropy(const ut8 *data, ut64 size) { } return h; } -R_API double r_hash_entropy_fraction(const ut8 *data, ut64 size) { - return size ? r_hash_entropy (data, size) / \ +RZ_API double rz_hash_entropy_fraction(const ut8 *data, ut64 size) { + return size ? rz_hash_entropy (data, size) / \ log2 ((double) R_MIN (size, 256)) : 0; } diff --git a/libr/hash/fletcher.c b/librz/hash/fletcher.c similarity index 77% rename from libr/hash/fletcher.c rename to librz/hash/fletcher.c index 4dcdff7ff5..077c58c8d8 100644 --- a/libr/hash/fletcher.c +++ b/librz/hash/fletcher.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2019 pancake */ +/* rizin - LGPL - Copyright 2019 pancake */ -#include +#include -R_API ut16 r_hash_fletcher8(const ut8 *d, size_t length) { +RZ_API ut16 rz_hash_fletcher8(const ut8 *d, size_t length) { size_t i; ut16 a = 0; ut16 b = 0; @@ -15,7 +15,7 @@ R_API ut16 r_hash_fletcher8(const ut8 *d, size_t length) { return (a & 0xff); } -R_API ut16 r_hash_fletcher16(const ut8 *data, size_t len) { +RZ_API ut16 rz_hash_fletcher16(const ut8 *data, size_t len) { ut32 c0, c1; size_t i; @@ -36,7 +36,7 @@ R_API ut16 r_hash_fletcher16(const ut8 *data, size_t len) { return (c1 << 8 | c0); } -R_API ut32 r_hash_fletcher32(const ut8 *data, size_t len) { +RZ_API ut32 rz_hash_fletcher32(const ut8 *data, size_t len) { ut32 c0, c1; size_t i; ut8 word[sizeof (ut16)]; @@ -45,7 +45,7 @@ R_API ut32 r_hash_fletcher32(const ut8 *data, size_t len) { size_t left = 360 - i; memset (word, 0, sizeof (word)); memcpy (word, data, R_MIN (sizeof (word), left)); - c0 += r_read_le16 (word); + c0 += rz_read_le16 (word); c1 += c0; data += 2; } @@ -56,7 +56,7 @@ R_API ut32 r_hash_fletcher32(const ut8 *data, size_t len) { size_t left = len - i; memset (word, 0, sizeof (word)); memcpy (word, data, R_MIN (sizeof (word), left)); - c0 += r_read_le16 (word); + c0 += rz_read_le16 (word); c1 += c0; data += 2; } @@ -65,7 +65,7 @@ R_API ut32 r_hash_fletcher32(const ut8 *data, size_t len) { return (c1 << 16 | c0); } -R_API ut64 r_hash_fletcher64(const ut8 *addr, size_t len) { +RZ_API ut64 rz_hash_fletcher64(const ut8 *addr, size_t len) { const ut8 *p32 = addr; const ut8 *p32end = addr + len; ut32 lo32 = 0; @@ -76,7 +76,7 @@ R_API ut64 r_hash_fletcher64(const ut8 *addr, size_t len) { size_t left = p32end - p32; memset (word, 0, sizeof (word)); memcpy (word, p32, R_MIN (sizeof (word), left)); - ut32 w = r_read_le32 (word); + ut32 w = rz_read_le32 (word); lo32 += w; p32 += sizeof (ut32); hi32 += lo32; diff --git a/libr/hash/hamdist.c b/librz/hash/hamdist.c similarity index 90% rename from libr/hash/hamdist.c rename to librz/hash/hamdist.c index 4556c918b5..b6252a4a91 100644 --- a/libr/hash/hamdist.c +++ b/librz/hash/hamdist.c @@ -12,7 +12,7 @@ errors that transformed one string into the other. #endif -#include "r_types.h" +#include "rz_types.h" static int hamdist(int x, int y) { int dist = 0, val = x ^ y; @@ -23,7 +23,7 @@ static int hamdist(int x, int y) { return dist; } -R_API ut8 r_hash_hamdist(const ut8 *buf, int len) { +RZ_API ut8 rz_hash_hamdist(const ut8 *buf, int len) { int i, x, y; x = y = i = 0; for (i = 0; i < len; i++) { diff --git a/libr/hash/hash.c b/librz/hash/hash.c similarity index 88% rename from libr/hash/hash.c rename to librz/hash/hash.c index 0ba2eeee03..bae6f4e271 100644 --- a/libr/hash/hash.c +++ b/librz/hash/hash.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2007-2019 pancake */ +/* rizin - LGPL - Copyright 2007-2019 pancake */ -#include -#include "r_util.h" +#include +#include "rz_util.h" #if USE_LIB_XXHASH #include #else #include "xxhash.h" #endif -R_LIB_VERSION (r_hash); +R_LIB_VERSION (rz_hash); static const struct { const char *name; @@ -115,7 +115,7 @@ static const struct { }; /* returns 0-100 */ -R_API int r_hash_pcprint(const ut8 *buffer, ut64 len) { +RZ_API int rz_hash_pcprint(const ut8 *buffer, ut64 len) { const ut8 *end = buffer + len; int n; if (len < 1) { @@ -129,7 +129,7 @@ R_API int r_hash_pcprint(const ut8 *buffer, ut64 len) { return ((100 * n) / len); } -R_API int r_hash_parity(const ut8 *buf, ut64 len) { +RZ_API int rz_hash_parity(const ut8 *buf, ut64 len) { const ut8 *end = buf + len; ut32 ones = 0; for (; buf < end; buf++) { @@ -142,7 +142,7 @@ R_API int r_hash_parity(const ut8 *buf, ut64 len) { /* These functions comes from 0xFFFF */ /* fmi: nopcode.org/0xFFFF */ -R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len) { +RZ_API ut16 rz_hash_xorpair(const ut8 *a, ut64 len) { ut16 result = 0, *b = (ut16 *)a; for (len >>= 1; len--; b++) { result ^= *b; @@ -150,7 +150,7 @@ R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len) { return result; } -R_API ut8 r_hash_xor(const ut8 *b, ut64 len) { +RZ_API ut8 rz_hash_xor(const ut8 *b, ut64 len) { ut8 res = 0; for (; len--; b++) { res ^= *b; @@ -158,7 +158,7 @@ R_API ut8 r_hash_xor(const ut8 *b, ut64 len) { return res; } -R_API ut8 r_hash_mod255(const ut8 *b, ut64 len) { +RZ_API ut8 rz_hash_mod255(const ut8 *b, ut64 len) { int i, c = 0; /* from gdb */ for (i = 0; i < len; i++) { @@ -167,11 +167,11 @@ R_API ut8 r_hash_mod255(const ut8 *b, ut64 len) { return c % 255; } -R_API ut32 r_hash_xxhash(const ut8 *buf, ut64 len) { +RZ_API ut32 rz_hash_xxhash(const ut8 *buf, ut64 len) { return XXH32 (buf, (size_t)len, 0); } -R_API ut8 r_hash_deviation(const ut8 *b, ut64 len) { +RZ_API ut8 rz_hash_deviation(const ut8 *b, ut64 len) { int i, c; for (c = i = 0, len--; i < len; i++) { c += R_ABS (b[i + 1] - b[i]); @@ -179,7 +179,7 @@ R_API ut8 r_hash_deviation(const ut8 *b, ut64 len) { return c; } -R_API const char *r_hash_name(ut64 bit) { +RZ_API const char *rz_hash_name(ut64 bit) { int i; for (i = 1; hash_name_bytes[i].bit; i++) { if (bit & hash_name_bytes[i].bit) { @@ -189,7 +189,7 @@ R_API const char *r_hash_name(ut64 bit) { return ""; } -R_API int r_hash_size(ut64 algo) { +RZ_API int rz_hash_size(ut64 algo) { #define ALGOBIT(x)\ if (algo & R_HASH_##x) {\ return R_HASH_SIZE_##x;\ @@ -290,7 +290,7 @@ R_API int r_hash_size(ut64 algo) { } /* Converts a comma separated list of names to the respective bit combination */ -R_API ut64 r_hash_name_to_bits(const char *name) { +RZ_API ut64 rz_hash_name_to_bits(const char *name) { char tmp[128]; int i; const char *ptr = name; @@ -325,9 +325,9 @@ R_API ut64 r_hash_name_to_bits(const char *name) { return ret; } -R_API void r_hash_do_spice(RHash *ctx, ut64 algo, int loops, RHashSeed *seed) { +RZ_API void rz_hash_do_spice(RzHash *ctx, ut64 algo, int loops, RzHashSeed *seed) { ut8 buf[1024]; - int i, len, hlen = r_hash_size (algo); + int i, len, hlen = rz_hash_size (algo); for (i = 0; i < loops; i++) { if (seed) { if (seed->prefix) { @@ -342,24 +342,24 @@ R_API void r_hash_do_spice(RHash *ctx, ut64 algo, int loops, RHashSeed *seed) { memcpy (buf, ctx->digest, hlen); len = hlen; } - (void)r_hash_calculate (ctx, algo, buf, len); + (void)rz_hash_calculate (ctx, algo, buf, len); } } -R_API char *r_hash_to_string(RHash *ctx, const char *name, const ut8 *data, int len) { - ut64 algo = r_hash_name_to_bits (name); +RZ_API char *rz_hash_to_string(RzHash *ctx, const char *name, const ut8 *data, int len) { + ut64 algo = rz_hash_name_to_bits (name); char *digest_hex = NULL; - RHash *myctx = NULL; + RzHash *myctx = NULL; int i, digest_size; if (!algo || !data) { return NULL; } if (!ctx) { - myctx = ctx = r_hash_new (true, algo); + myctx = ctx = rz_hash_new (true, algo); } - r_hash_do_begin (ctx, algo); - digest_size = r_hash_calculate (ctx, algo, data, len); - r_hash_do_end (ctx, algo); + rz_hash_do_begin (ctx, algo); + digest_size = rz_hash_calculate (ctx, algo, data, len); + rz_hash_do_end (ctx, algo); if (digest_size == 0) { digest_hex = calloc (16, 1); snprintf (digest_hex, 15, "%02.8f", ctx->entropy); @@ -376,6 +376,6 @@ R_API char *r_hash_to_string(RHash *ctx, const char *name, const ut8 *data, int } } } - r_hash_free (myctx); + rz_hash_free (myctx); return digest_hex; } diff --git a/libr/hash/hash.h b/librz/hash/hash.h similarity index 93% rename from libr/hash/hash.h rename to librz/hash/hash.h index 8200e47f62..792ecb91c2 100644 --- a/libr/hash/hash.h +++ b/librz/hash/hash.h @@ -12,5 +12,5 @@ ut16 crc16(ut16 crc, const ut8 *buffer, ut64 len); void mdfour(ut8 *out, const ut8 *in, ut64 n); ut32 crc32(ut8 *buf, ut64 len); -ut64 r_hash_name_to_bits(const char *name); +ut64 rz_hash_name_to_bits(const char *name); //extern ut16 const crc16_table[256]; diff --git a/libr/hash/hcalc.c b/librz/hash/hcalc.c similarity index 68% rename from libr/hash/hcalc.c rename to librz/hash/hcalc.c index 9bfa8ac647..4a4c59e124 100644 --- a/libr/hash/hcalc.c +++ b/librz/hash/hcalc.c @@ -1,112 +1,112 @@ -/* radare2 - LGPL - Copyright 2009-2019 pancake */ +/* rizin - LGPL - Copyright 2009-2019 pancake */ -#include +#include #define HANDLE_CRC_PRESET(rbits, aname) \ do { \ if (algobit & R_HASH_##aname) { \ - ut##rbits res = r_hash_crc_preset (buf, len, CRC_PRESET_##aname); \ - r_write_be##rbits (ctx->digest, res); \ + ut##rbits res = rz_hash_crc_preset (buf, len, CRC_PRESET_##aname); \ + rz_write_be##rbits (ctx->digest, res); \ return R_HASH_SIZE_##aname; \ } \ } while(0) /* TODO: do it more beautiful with structs and not spaguetis */ -R_API int r_hash_calculate(RHash *ctx, ut64 algobit, const ut8 *buf, int len) { +RZ_API int rz_hash_calculate(RzHash *ctx, ut64 algobit, const ut8 *buf, int len) { if (len < 0) { return 0; } if (algobit & R_HASH_MD4) { - r_hash_do_md4 (ctx, buf, len); + rz_hash_do_md4 (ctx, buf, len); return R_HASH_SIZE_MD4; } if (algobit & R_HASH_MD5) { - r_hash_do_md5 (ctx, buf, len); + rz_hash_do_md5 (ctx, buf, len); return R_HASH_SIZE_MD5; } if (algobit & R_HASH_SHA1) { - r_hash_do_sha1 (ctx, buf, len); + rz_hash_do_sha1 (ctx, buf, len); return R_HASH_SIZE_SHA1; } if (algobit & R_HASH_SHA256) { - r_hash_do_sha256 (ctx, buf, len); + rz_hash_do_sha256 (ctx, buf, len); return R_HASH_SIZE_SHA256; } if (algobit & R_HASH_SHA384) { - r_hash_do_sha384 (ctx, buf, len); + rz_hash_do_sha384 (ctx, buf, len); return R_HASH_SIZE_SHA384; } if (algobit & R_HASH_SHA512) { - r_hash_do_sha512 (ctx, buf, len); + rz_hash_do_sha512 (ctx, buf, len); return R_HASH_SIZE_SHA512; } if (algobit & R_HASH_XXHASH) { - ut32 res = r_hash_xxhash (buf, len); + ut32 res = rz_hash_xxhash (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_XXHASH); return R_HASH_SIZE_XXHASH; } if (algobit & R_HASH_FLETCHER8) { - ut8 res = r_hash_fletcher8 (buf, len); + ut8 res = rz_hash_fletcher8 (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_FLETCHER8); return R_HASH_SIZE_FLETCHER8; } if (algobit & R_HASH_FLETCHER16) { - ut16 res = r_hash_fletcher16 (buf, len); + ut16 res = rz_hash_fletcher16 (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_FLETCHER16); return R_HASH_SIZE_FLETCHER16; } if (algobit & R_HASH_FLETCHER32) { - ut32 res = r_hash_fletcher32 (buf, len); + ut32 res = rz_hash_fletcher32 (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_FLETCHER32); return R_HASH_SIZE_FLETCHER32; } if (algobit & R_HASH_FLETCHER64) { - ut64 res = r_hash_fletcher64 (buf, len); + ut64 res = rz_hash_fletcher64 (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_FLETCHER64); return R_HASH_SIZE_FLETCHER64; } if (algobit & R_HASH_ADLER32) { - ut32 res = r_hash_adler32 (buf, len); + ut32 res = rz_hash_adler32 (buf, len); memcpy (ctx->digest, &res, R_HASH_SIZE_ADLER32); return R_HASH_SIZE_ADLER32; } if (algobit & R_HASH_HAMDIST) { - *ctx->digest = r_hash_hamdist (buf, len); + *ctx->digest = rz_hash_hamdist (buf, len); return R_HASH_SIZE_HAMDIST; } if (algobit & R_HASH_PCPRINT) { - *ctx->digest = r_hash_pcprint (buf, len); + *ctx->digest = rz_hash_pcprint (buf, len); return R_HASH_SIZE_PCPRINT; } if (algobit & R_HASH_PARITY) { - *ctx->digest = r_hash_parity (buf, len); + *ctx->digest = rz_hash_parity (buf, len); return R_HASH_SIZE_PARITY; } if (algobit & R_HASH_ENTROPY) { - r_mem_memzero (ctx->digest, sizeof (ctx->entropy)); - ctx->entropy = r_hash_entropy (buf, len); + rz_mem_memzero (ctx->digest, sizeof (ctx->entropy)); + ctx->entropy = rz_hash_entropy (buf, len); return R_HASH_SIZE_ENTROPY; } if (algobit & R_HASH_XOR) { - *ctx->digest = r_hash_xor (buf, len); + *ctx->digest = rz_hash_xor (buf, len); return R_HASH_SIZE_XOR; } if (algobit & R_HASH_XORPAIR) { - ut16 res = r_hash_xorpair (buf, len); + ut16 res = rz_hash_xorpair (buf, len); memcpy (ctx->digest, &res, 2); return R_HASH_SIZE_XORPAIR; } if (algobit & R_HASH_MOD255) { - *ctx->digest = r_hash_mod255 (buf, len); + *ctx->digest = rz_hash_mod255 (buf, len); return R_HASH_SIZE_MOD255; } if (algobit & R_HASH_LUHN) { - *ctx->digest = r_hash_luhn (buf, len); + *ctx->digest = rz_hash_luhn (buf, len); return R_HASH_SIZE_LUHN; } if (algobit & R_HASH_CRC8_SMBUS) { - ut8 res = r_hash_crc_preset (buf, len, CRC_PRESET_8_SMBUS); + ut8 res = rz_hash_crc_preset (buf, len, CRC_PRESET_8_SMBUS); memcpy (ctx->digest, &res, R_HASH_SIZE_CRC8_SMBUS); return R_HASH_SIZE_CRC8_SMBUS; } @@ -125,30 +125,30 @@ R_API int r_hash_calculate(RHash *ctx, ut64 algobit, const ut8 *buf, int len) { #if R_HAVE_CRC15_EXTRA if (algobit & R_HASH_CRC15_CAN) { - ut16 res = r_hash_crc_preset (buf, len, CRC_PRESET_15_CAN); - r_write_be16 (ctx->digest, res); + ut16 res = rz_hash_crc_preset (buf, len, CRC_PRESET_15_CAN); + rz_write_be16 (ctx->digest, res); return R_HASH_SIZE_CRC15_CAN; } #endif /* #if R_HAVE_CRC15_EXTRA */ if (algobit & R_HASH_CRC16) { - ut16 res = r_hash_crc_preset (buf, len, CRC_PRESET_16); - r_write_be16 (ctx->digest, res); + ut16 res = rz_hash_crc_preset (buf, len, CRC_PRESET_16); + rz_write_be16 (ctx->digest, res); return R_HASH_SIZE_CRC16; } if (algobit & R_HASH_CRC16_HDLC) { - ut16 res = r_hash_crc_preset (buf, len, CRC_PRESET_16_HDLC); - r_write_be16 (ctx->digest, res); + ut16 res = rz_hash_crc_preset (buf, len, CRC_PRESET_16_HDLC); + rz_write_be16 (ctx->digest, res); return R_HASH_SIZE_CRC16_HDLC; } if (algobit & R_HASH_CRC16_USB) { - ut16 res = r_hash_crc_preset (buf, len, CRC_PRESET_16_USB); - r_write_be16 (ctx->digest, res); + ut16 res = rz_hash_crc_preset (buf, len, CRC_PRESET_16_USB); + rz_write_be16 (ctx->digest, res); return R_HASH_SIZE_CRC16_USB; } if (algobit & R_HASH_CRC16_CITT) { - ut16 res = r_hash_crc_preset (buf, len, CRC_PRESET_16_CITT); - r_write_be16 (ctx->digest, res); + ut16 res = rz_hash_crc_preset (buf, len, CRC_PRESET_16_CITT); + rz_write_be16 (ctx->digest, res); return R_HASH_SIZE_CRC16_CITT; } #if R_HAVE_CRC16_EXTRA @@ -176,25 +176,25 @@ R_API int r_hash_calculate(RHash *ctx, ut64 algobit, const ut8 *buf, int len) { #if R_HAVE_CRC24 if (algobit & R_HASH_CRC24) { - ut32 res = r_hash_crc_preset (buf, len, CRC_PRESET_24); - r_write_be24 (ctx->digest, res); + ut32 res = rz_hash_crc_preset (buf, len, CRC_PRESET_24); + rz_write_be24 (ctx->digest, res); return R_HASH_SIZE_CRC24; } #endif /* #if R_HAVE_CRC24 */ if (algobit & R_HASH_CRC32) { - ut32 res = r_hash_crc_preset (buf, len, CRC_PRESET_32); - r_write_be32 (ctx->digest, res); + ut32 res = rz_hash_crc_preset (buf, len, CRC_PRESET_32); + rz_write_be32 (ctx->digest, res); return R_HASH_SIZE_CRC32; } if (algobit & R_HASH_CRC32C) { - ut32 res = r_hash_crc_preset (buf, len, CRC_PRESET_32C); - r_write_be32 (ctx->digest, res); + ut32 res = rz_hash_crc_preset (buf, len, CRC_PRESET_32C); + rz_write_be32 (ctx->digest, res); return R_HASH_SIZE_CRC32C; } if (algobit & R_HASH_CRC32_ECMA_267) { - ut32 res = r_hash_crc_preset (buf, len, CRC_PRESET_32_ECMA_267); - r_write_be32 (ctx->digest, res); + ut32 res = rz_hash_crc_preset (buf, len, CRC_PRESET_32_ECMA_267); + rz_write_be32 (ctx->digest, res); return R_HASH_SIZE_CRC32_ECMA_267; } #if R_HAVE_CRC32_EXTRA diff --git a/libr/hash/luhn.c b/librz/hash/luhn.c similarity index 70% rename from libr/hash/luhn.c rename to librz/hash/luhn.c index 41c433cf0a..efe74f4c15 100644 --- a/libr/hash/luhn.c +++ b/librz/hash/luhn.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - 2016-2018 - Copyright (C) moritz */ +/* rizin - LGPL - 2016-2018 - Copyright (C) moritz */ -#include +#include -R_API ut64 r_hash_luhn(const ut8 *buf, ut64 len) { +RZ_API ut64 rz_hash_luhn(const ut8 *buf, ut64 len) { int curDigit, parity = (len - 1) % 2; ut64 i, sum = 0; char curChar[2] = {0, 0}; diff --git a/libr/hash/md4.c b/librz/hash/md4.c similarity index 99% rename from libr/hash/md4.c rename to librz/hash/md4.c index 5c2067c05f..2c2a07ca69 100644 --- a/libr/hash/md4.c +++ b/librz/hash/md4.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ -#include +#include #if WITH_GPL diff --git a/libr/hash/md4.h b/librz/hash/md4.h similarity index 100% rename from libr/hash/md4.h rename to librz/hash/md4.h diff --git a/libr/hash/md5.c b/librz/hash/md5.c similarity index 98% rename from libr/hash/md5.c rename to librz/hash/md5.c index 9887fda508..62357ae712 100644 --- a/libr/hash/md5.c +++ b/librz/hash/md5.c @@ -22,7 +22,7 @@ * documentation and/or software. */ -#include +#include /* F, G, H and I are basic MD5 functions. */ #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) @@ -161,7 +161,7 @@ static void MD5Transform(ut32 state[4], const ut8 block[64]) { state[3] += d; /* Zeroize sensitive information. check if compiler optimizes out this */ - r_mem_memzero ((void*)x, sizeof (x)); + rz_mem_memzero ((void*)x, sizeof (x)); } static const ut8 PADDING[64] = { @@ -230,5 +230,5 @@ void MD5_Final(ut8 digest[16], R_MD5_CTX *context) { Encode (digest, context->state, 16); /* Zeroize sensitive information. */ - r_mem_memzero ((void*)context, sizeof (*context)); + rz_mem_memzero ((void*)context, sizeof (*context)); } diff --git a/libr/hash/md5.h b/librz/hash/md5.h similarity index 100% rename from libr/hash/md5.h rename to librz/hash/md5.h diff --git a/libr/hash/meson.build b/librz/hash/meson.build similarity index 64% rename from libr/hash/meson.build rename to librz/hash/meson.build index 5c7448a954..f3ca9f7cbd 100644 --- a/libr/hash/meson.build +++ b/librz/hash/meson.build @@ -1,4 +1,4 @@ -r_hash_sources = [ +rz_hash_sources = [ 'adler32.c', 'hcalc.c', 'crca.c', @@ -10,21 +10,21 @@ r_hash_sources = [ 'state.c' ] -dependencies = [mth, r_util_dep] +dependencies = [mth, rz_util_dep] if use_sys_xxhash dependencies += [sys_xxhash] else - r_hash_sources += ['xxhash.c'] + rz_hash_sources += ['xxhash.c'] endif if use_sys_openssl dependencies += [sys_openssl] else - r_hash_sources += ['md4.c', 'md5.c', 'sha1.c', 'sha2.c'] + rz_hash_sources += ['md4.c', 'md5.c', 'sha1.c', 'sha2.c'] endif -r_hash = library('r_hash', r_hash_sources, +rz_hash = library('rz_hash', rz_hash_sources, include_directories: [platform_inc], c_args: library_cflags, dependencies: dependencies, @@ -34,17 +34,17 @@ r_hash = library('r_hash', r_hash_sources, soversion: r2_libversion ) -r_hash_dep = declare_dependency(link_with: r_hash, +rz_hash_dep = declare_dependency(link_with: rz_hash, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_hash, - subdirs: 'libr', +pkgconfig_mod.generate(rz_hash, + subdirs: 'librz', version: r2_version, - name: 'r_hash', - filebase: 'r_hash', + name: 'rz_hash', + filebase: 'rz_hash', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/hash/sha1.c b/librz/hash/sha1.c similarity index 99% rename from libr/hash/sha1.c rename to librz/hash/sha1.c index 20a3695b7b..9ba6fb579f 100644 --- a/libr/hash/sha1.c +++ b/librz/hash/sha1.c @@ -33,7 +33,7 @@ * GPL. */ -#include "r_hash.h" +#include "rz_hash.h" #include "sha1.h" #define SHA_ROT(X, n) (((X) << (n)) | ((X) >> (32 - (n)))) diff --git a/libr/hash/sha1.h b/librz/hash/sha1.h similarity index 100% rename from libr/hash/sha1.h rename to librz/hash/sha1.h diff --git a/libr/hash/sha2.c b/librz/hash/sha2.c similarity index 98% rename from libr/hash/sha2.c rename to librz/hash/sha2.c index 0ebc7e290c..0a69828e15 100644 --- a/libr/hash/sha2.c +++ b/librz/hash/sha2.c @@ -33,7 +33,7 @@ */ #include /* memcpy()/memset() or bcopy()/bzero() */ -#include "r_hash.h" +#include "rz_hash.h" #include "sha2.h" #define WEAK_ALIASING 0 @@ -286,7 +286,7 @@ void SHA256_Init(R_SHA256_CTX *context) { return; } memcpy (context->state, sha256_initial_hash_value, SHA256_DIGEST_LENGTH); - r_mem_memzero (context->buffer, SHA256_BLOCK_LENGTH); + rz_mem_memzero (context->buffer, SHA256_BLOCK_LENGTH); context->bitcount = 0; } @@ -578,7 +578,7 @@ void SHA256_Final(ut8 *digest, R_SHA256_CTX *context) { } /* Clean up state data: */ - r_mem_memzero (context, sizeof(*context)); + rz_mem_memzero (context, sizeof(*context)); usedspace = 0; } @@ -599,9 +599,9 @@ char *SHA256_End(R_SHA256_CTX *context, char buffer[]) { } *buffer = (char) 0; } else { - r_mem_memzero (context, sizeof(*context)); + rz_mem_memzero (context, sizeof(*context)); } - r_mem_memzero (digest, SHA256_DIGEST_LENGTH); + rz_mem_memzero (digest, SHA256_DIGEST_LENGTH); return buffer; } @@ -620,7 +620,7 @@ void SHA512_Init(R_SHA512_CTX *context) { return; } memcpy (context->state, sha512_initial_hash_value, SHA512_DIGEST_LENGTH); - r_mem_memzero (context->buffer, SHA512_BLOCK_LENGTH); + rz_mem_memzero (context->buffer, SHA512_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } @@ -921,7 +921,7 @@ void SHA512_Final(ut8 digest[], R_SHA512_CTX *context) { } /* Zero out state data */ - r_mem_memzero (context, sizeof(*context)); + rz_mem_memzero (context, sizeof(*context)); } char *SHA512_End(R_SHA512_CTX *context, char buffer[]) { @@ -943,9 +943,9 @@ char *SHA512_End(R_SHA512_CTX *context, char buffer[]) { } *buffer = (char) 0; } else { - r_mem_memzero (context, sizeof(*context)); + rz_mem_memzero (context, sizeof(*context)); } - r_mem_memzero (digest, SHA512_DIGEST_LENGTH); + rz_mem_memzero (digest, SHA512_DIGEST_LENGTH); return buffer; } diff --git a/libr/hash/sha2.h b/librz/hash/sha2.h similarity index 100% rename from libr/hash/sha2.h rename to librz/hash/sha2.h diff --git a/libr/hash/state.c b/librz/hash/state.c similarity index 79% rename from libr/hash/state.c rename to librz/hash/state.c index 4b29a19624..b510514a91 100644 --- a/libr/hash/state.c +++ b/librz/hash/state.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2017 pancake */ -#include +#include #if HAVE_LIB_SSL #include @@ -15,17 +15,17 @@ #define CHKFLAG(x) if (!flags || flags & (x)) -R_API RHash *r_hash_new(bool rst, ut64 flags) { - RHash *ctx = R_NEW0 (RHash); +RZ_API RzHash *rz_hash_new(bool rst, ut64 flags) { + RzHash *ctx = R_NEW0 (RzHash); if (ctx) { - r_hash_do_begin (ctx, flags); + rz_hash_do_begin (ctx, flags); ctx->rst = rst; } return ctx; } -R_API void r_hash_do_begin(RHash *ctx, ut64 flags) { - CHKFLAG (R_HASH_MD5) r_hash_do_md5 (ctx, NULL, -1); +RZ_API void rz_hash_do_begin(RzHash *ctx, ut64 flags) { + CHKFLAG (R_HASH_MD5) rz_hash_do_md5 (ctx, NULL, -1); CHKFLAG (R_HASH_SHA1) SHA1_Init (&ctx->sha1); CHKFLAG (R_HASH_SHA256) SHA256_Init (&ctx->sha256); CHKFLAG (R_HASH_SHA384) SHA384_Init (&ctx->sha384); @@ -33,8 +33,8 @@ R_API void r_hash_do_begin(RHash *ctx, ut64 flags) { ctx->rst = false; } -R_API void r_hash_do_end(RHash *ctx, ut64 flags) { - CHKFLAG (R_HASH_MD5) r_hash_do_md5 (ctx, NULL, -2); +RZ_API void rz_hash_do_end(RzHash *ctx, ut64 flags) { + CHKFLAG (R_HASH_MD5) rz_hash_do_md5 (ctx, NULL, -2); CHKFLAG (R_HASH_SHA1) SHA1_Final (ctx->digest, &ctx->sha1); CHKFLAG (R_HASH_SHA256) SHA256_Final (ctx->digest, &ctx->sha256); CHKFLAG (R_HASH_SHA384) SHA384_Final (ctx->digest, &ctx->sha384); @@ -42,11 +42,11 @@ R_API void r_hash_do_end(RHash *ctx, ut64 flags) { ctx->rst = true; } -R_API void r_hash_free(RHash *ctx) { +RZ_API void rz_hash_free(RzHash *ctx) { free (ctx); } -R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_sha1(RzHash *ctx, const ut8 *input, int len) { if (len < 0) { return NULL; } @@ -60,7 +60,7 @@ R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, int len) { return ctx->digest; } -R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_sha256(RzHash *ctx, const ut8 *input, int len) { if (len < 0) { return NULL; } @@ -74,7 +74,7 @@ R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, int len) { return ctx->digest; } -R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_sha384(RzHash *ctx, const ut8 *input, int len) { if (len < 0) { return NULL; } @@ -88,7 +88,7 @@ R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len) { return ctx->digest; } -R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_sha512(RzHash *ctx, const ut8 *input, int len) { if (len < 0) { return NULL; } @@ -102,7 +102,7 @@ R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, int len) { return ctx->digest; } -R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_md5(RzHash *ctx, const ut8 *input, int len) { if (len < 0) { if (len == -1) { MD5_Init (&ctx->md5); @@ -125,7 +125,7 @@ R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, int len) { return ctx->digest; } -R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, int len) { +RZ_API ut8 *rz_hash_do_md4(RzHash *ctx, const ut8 *input, int len) { if (len >= 0) { MD4 (input, len, ctx->digest); return ctx->digest; @@ -133,7 +133,7 @@ R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, int len) { return NULL; } -R_API ut8 *r_hash_do_hmac_sha256(RHash *ctx, const ut8 *input, int len, const ut8 *key, int klen) { +RZ_API ut8 *rz_hash_do_hmac_sha256(RzHash *ctx, const ut8 *input, int len, const ut8 *key, int klen) { if (len < 0 || klen < 0) { return NULL; } diff --git a/libr/hash/xxhash.c b/librz/hash/xxhash.c similarity index 90% rename from libr/hash/xxhash.c rename to librz/hash/xxhash.c index 5bc4c7814b..e1723a2540 100644 --- a/libr/hash/xxhash.c +++ b/librz/hash/xxhash.c @@ -36,7 +36,7 @@ #include #include -#include +#include #include "xxhash.h" #define XXH_rotl32(x, r) (((x) << (r)) | ((x) >> (32 - (r)))) @@ -60,19 +60,19 @@ ut32 XXH32(const void *input, size_t len, ut32 seed) { ut32 v4 = seed - PRIME32_1; do { - v1 += r_read_le32 (p) * PRIME32_2; + v1 += rz_read_le32 (p) * PRIME32_2; v1 = XXH_rotl32 (v1, 13); v1 *= PRIME32_1; p += 4; - v2 += r_read_le32 (p) * PRIME32_2; + v2 += rz_read_le32 (p) * PRIME32_2; v2 = XXH_rotl32 (v2, 13); v2 *= PRIME32_1; p += 4; - v3 += r_read_le32 (p) * PRIME32_2; + v3 += rz_read_le32 (p) * PRIME32_2; v3 = XXH_rotl32 (v3, 13); v3 *= PRIME32_1; p += 4; - v4 += r_read_le32 (p) * PRIME32_2; + v4 += rz_read_le32 (p) * PRIME32_2; v4 = XXH_rotl32 (v4, 13); v4 *= PRIME32_1; p += 4; @@ -87,7 +87,7 @@ ut32 XXH32(const void *input, size_t len, ut32 seed) { h32 += (ut32) len; while (p <= bEnd - 4) { - h32 += r_read_le32 (p) * PRIME32_3; + h32 += rz_read_le32 (p) * PRIME32_3; h32 = XXH_rotl32 (h32, 17) * PRIME32_4; p += 4; } @@ -152,19 +152,19 @@ int XXH32_feed (void *state_in, const void *input, int len) { memcpy (state->memory + state->memsize, input, 16 - state->memsize); { const ut32 *p32 = (const ut32 *) state->memory; - state->v1 += r_read_le32 (p32) * PRIME32_2; + state->v1 += rz_read_le32 (p32) * PRIME32_2; state->v1 = XXH_rotl32 (state->v1, 13); state->v1 *= PRIME32_1; p32++; - state->v2 += r_read_le32 (p32) * PRIME32_2; + state->v2 += rz_read_le32 (p32) * PRIME32_2; state->v2 = XXH_rotl32 (state->v2, 13); state->v2 *= PRIME32_1; p32++; - state->v3 += r_read_le32 (p32) * PRIME32_2; + state->v3 += rz_read_le32 (p32) * PRIME32_2; state->v3 = XXH_rotl32 (state->v3, 13); state->v3 *= PRIME32_1; p32++; - state->v4 += r_read_le32 (p32) * PRIME32_2; + state->v4 += rz_read_le32 (p32) * PRIME32_2; state->v4 = XXH_rotl32 (state->v4, 13); state->v4 *= PRIME32_1; p32++; @@ -181,19 +181,19 @@ int XXH32_feed (void *state_in, const void *input, int len) { ut32 v4 = state->v4; while (p <= limit) { - v1 += r_read_le32 (p) * PRIME32_2; + v1 += rz_read_le32 (p) * PRIME32_2; v1 = XXH_rotl32 (v1, 13); v1 *= PRIME32_1; p += 4; - v2 += r_read_le32 (p) * PRIME32_2; + v2 += rz_read_le32 (p) * PRIME32_2; v2 = XXH_rotl32 (v2, 13); v2 *= PRIME32_1; p += 4; - v3 += r_read_le32 (p) * PRIME32_2; + v3 += rz_read_le32 (p) * PRIME32_2; v3 = XXH_rotl32 (v3, 13); v3 *= PRIME32_1; p += 4; - v4 += r_read_le32 (p) * PRIME32_2; + v4 += rz_read_le32 (p) * PRIME32_2; v4 = XXH_rotl32 (v4, 13); v4 *= PRIME32_1; p += 4; @@ -227,7 +227,7 @@ ut32 XXH32_getIntermediateResult (void *state_in) { h32 += (ut32) state->total_len; while (p <= bEnd - 4) { - h32 += r_read_le32 (p) * PRIME32_3; + h32 += rz_read_le32 (p) * PRIME32_3; h32 = XXH_rotl32 (h32, 17) * PRIME32_4; p += 4; } diff --git a/libr/hash/xxhash.h b/librz/hash/xxhash.h similarity index 100% rename from libr/hash/xxhash.h rename to librz/hash/xxhash.h diff --git a/librz/include/rz_agraph.h b/librz/include/rz_agraph.h new file mode 100644 index 0000000000..1d328270d4 --- /dev/null +++ b/librz/include/rz_agraph.h @@ -0,0 +1,116 @@ +#ifndef R2_AGRAPH_H +#define R2_AGRAPH_H + +#include +#include +#include + +typedef struct rz_ascii_node_t { + RGraphNode *gnode; + char *title; + char *body; + + int x; + int y; + int w; + int h; + + int layer; + int layer_height; + int layer_width; + int pos_in_layer; + int is_dummy; + int is_reversed; + int klass; + int difftype; + bool is_mini; +} RzANode; + +typedef struct rz_core_graph_hits_t { + char *old_word ; + RzVector word_list; + int word_nth; +} RzAGraphHits; + + +#define R_AGRAPH_MODE_NORMAL 0 +#define R_AGRAPH_MODE_OFFSET 1 +#define R_AGRAPH_MODE_MINI 2 +#define R_AGRAPH_MODE_TINY 3 +#define R_AGRAPH_MODE_SUMMARY 4 +#define R_AGRAPH_MODE_COMMENTS 5 +#define R_AGRAPH_MODE_MAX 6 + +typedef void (*RzANodeCallback)(RzANode *n, void *user); +typedef void (*RAEdgeCallback)(RzANode *from, RzANode *to, void *user); + +typedef struct rz_ascii_graph_t { + RzConsCanvas *can; + RGraph *graph; + const RGraphNode *curnode; + char *title; + Sdb *db; + Sdb *nodes; // Sdb with title(key)=RzANode*(value) + + int layout; + int is_instep; + bool is_tiny; + bool is_dis; + int edgemode; + int mode; + bool is_callgraph; + bool is_interactive; + int zoom; + int movspeed; + bool hints; + + RzANode *update_seek_on; + bool need_reload_nodes; + bool need_set_layout; + int need_update_dim; + int force_update_seek; + + /* events */ + RzANodeCallback on_curnode_change; + void *on_curnode_change_data; + bool dummy; // enable the dummy nodes for better layouting + bool show_node_titles; + bool show_node_body; + bool show_node_bubble; + + int x, y; + int w, h; + + /* layout algorithm info */ + RzList *back_edges; + RzList *long_edges; + struct layer_t *layers; + int n_layers; + RzList *dists; /* RzList */ + RzList *edges; /* RzList */ + RzAGraphHits ghits; +} RzAGraph; + +#ifdef RZ_API +RZ_API RzAGraph *rz_agraph_new(RzConsCanvas *can); +RZ_API void rz_agraph_free(RzAGraph *g); +RZ_API void rz_agraph_reset(RzAGraph *g); +RZ_API void rz_agraph_set_title(RzAGraph *g, const char *title); +RZ_API RzANode *rz_agraph_get_first_node(const RzAGraph *g); +RZ_API RzANode *rz_agraph_get_node(const RzAGraph *g, const char *title); +RZ_API RzANode *rz_agraph_add_node(const RzAGraph *g, const char *title, const char *body); +RZ_API RzANode *rz_agraph_add_node_with_color(const RzAGraph *g, const char *title, const char *body, int color); +RZ_API bool rz_agraph_del_node(const RzAGraph *g, const char *title); +RZ_API void rz_agraph_add_edge(const RzAGraph *g, RzANode *a, RzANode *b); +RZ_API void rz_agraph_add_edge_at(const RzAGraph *g, RzANode *a, RzANode *b, int nth); +RZ_API void rz_agraph_del_edge(const RzAGraph *g, RzANode *a, RzANode *b); +RZ_API void rz_agraph_print(RzAGraph *g); +RZ_API void rz_agraph_print_json(RzAGraph *g, PJ *pj); +RZ_API Sdb *rz_agraph_get_sdb(RzAGraph *g); +RZ_API void rz_agraph_foreach(RzAGraph *g, RzANodeCallback cb, void *user); +RZ_API void rz_agraph_foreach_edge(RzAGraph *g, RAEdgeCallback cb, void *user); +RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *node); +RZ_API RzAGraph *create_agraph_from_graph(const RGraph/**/ *graph); +#endif + +#endif diff --git a/librz/include/rz_anal.h b/librz/include/rz_anal.h new file mode 100644 index 0000000000..9430703141 --- /dev/null +++ b/librz/include/rz_anal.h @@ -0,0 +1,2191 @@ +/* rizin - LGPL - Copyright 2009-2020 - nibble, pancake, xvilka */ + +#ifndef R2_ANAL_H +#define R2_ANAL_H + +/* use old refs and function storage */ +// still required by core in lot of places +#define USE_VARSUBS 0 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define esilprintf(op, fmt, ...) rz_strbuf_setf (&op->esil, fmt, ##__VA_ARGS__) + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_anal); + +/* dwarf processing context */ +typedef struct rz_anal_dwarf_context { + const RBinDwarfDebugInfo *info; + HtUP/**/ *loc; + // const RBinDwarfCfa *cfa; TODO +} RzAnalDwarfContext; + +// TODO: save memory2 : fingerprints must be pointers to a buffer +// containing a dupped file in memory + +/* save memory: + bb_has_ops=1 -> 600M + bb_has_ops=0 -> 350MB + */ + +typedef struct { + struct rz_anal_t *anal; + int type; + int rad; + SdbForeachCallback cb; + void *user; + int count; + struct rz_anal_function_t *fcn; + PJ *pj; +} RzAnalMetaUserItem; + +typedef struct rz_anal_range_t { + ut64 from; + ut64 to; + int bits; + ut64 rb_max_addr; + RBNode rb; +} RzAnalRange; + +#define R_ANAL_GET_OFFSET(x,y,z) \ + (x && x->binb.bin && x->binb.get_offset)? \ + x->binb.get_offset (x->binb.bin, y, z): -1 +enum { + R_ANAL_DATA_TYPE_NULL = 0, + R_ANAL_DATA_TYPE_UNKNOWN = 1, + R_ANAL_DATA_TYPE_STRING = 2, + R_ANAL_DATA_TYPE_WIDE_STRING = 3, + R_ANAL_DATA_TYPE_POINTER = 4, + R_ANAL_DATA_TYPE_NUMBER = 5, + R_ANAL_DATA_TYPE_INVALID = 6, + R_ANAL_DATA_TYPE_HEADER = 7, + R_ANAL_DATA_TYPE_SEQUENCE = 8, + R_ANAL_DATA_TYPE_PATTERN = 9, +}; + +// used from core/anal.c +#define R_ANAL_ADDR_TYPE_EXEC 1 +#define R_ANAL_ADDR_TYPE_READ 1 << 1 +#define R_ANAL_ADDR_TYPE_WRITE 1 << 2 +#define R_ANAL_ADDR_TYPE_FLAG 1 << 3 +#define R_ANAL_ADDR_TYPE_FUNC 1 << 4 +#define R_ANAL_ADDR_TYPE_HEAP 1 << 5 +#define R_ANAL_ADDR_TYPE_STACK 1 << 6 +#define R_ANAL_ADDR_TYPE_REG 1 << 7 +#define R_ANAL_ADDR_TYPE_PROGRAM 1 << 8 +#define R_ANAL_ADDR_TYPE_LIBRARY 1 << 9 +#define R_ANAL_ADDR_TYPE_ASCII 1 << 10 +#define R_ANAL_ADDR_TYPE_SEQUENCE 1 << 11 + +#define R_ANAL_ARCHINFO_MIN_OP_SIZE 0 +#define R_ANAL_ARCHINFO_MAX_OP_SIZE 1 +#define R_ANAL_ARCHINFO_ALIGN 2 +#define R_ANAL_ARCHINFO_DATA_ALIGN 4 + +/* copypaste from rz_asm.h */ + +#define R_ANAL_GET_OFFSET(x,y,z) \ + (x && x->binb.bin && x->binb.get_offset)? \ + x->binb.get_offset (x->binb.bin, y, z): -1 + +#define R_ANAL_GET_NAME(x,y,z) \ + (x && x->binb.bin && x->binb.get_name)? \ + x->binb.get_name (x->binb.bin, y, z): NULL + +/* type = (R_ANAL_VAR_TYPE_BYTE & R_ANAL_VAR_TYPE_SIZE_MASK) | + * ( RANAL_VAR_TYPE_SIGNED & RANAL_VAR_TYPE_SIGN_MASK) | + * ( RANAL_VAR_TYPE_CONST & RANAL_VAR_TYPE_MODIFIER_MASK) + */ +typedef struct rz_anal_type_var_t { + char *name; + int index; + int scope; + ut16 type; // contain (type || signedness || modifier) + ut8 size; + union { + ut8 v8; + ut16 v16; + ut32 v32; + ut64 v64; + } value; +} RzAnalTypeVar; + +typedef struct rz_anal_type_ptr_t { + char *name; + ut16 type; // contain (type || signedness || modifier) + ut8 size; + union { + ut8 v8; + ut16 v16; + ut32 v32; + ut64 v64; + } value; +} RzAnalTypePtr; + +typedef struct rz_anal_type_array_t { + char *name; + ut16 type; // contain (type || signedness || modifier) + ut8 size; + ut64 count; + union { + ut8 *v8; + ut16 *v16; + ut32 *v32; + ut64 *v64; + } value; +} RzAnalTypeArray; + +typedef struct rz_anal_type_struct_t RzAnalTypeStruct; +typedef struct rz_anal_type_t RzAnalType; + +struct rz_anal_type_struct_t { + char *name; + ut8 type; + ut32 size; + void *parent; + RzAnalType *items; +}; + +typedef struct rz_anal_type_union_t { + char *name; + ut8 type; + ut32 size; + void *parent; + RzAnalType *items; +} RzAnalTypeUnion; + +typedef struct rz_anal_type_alloca_t { + long address; + long size; + void *parent; + RzAnalType *items; +} RzAnalTypeAlloca; + +enum { + R_ANAL_FQUALIFIER_NONE = 0, + R_ANAL_FQUALIFIER_STATIC = 1, + R_ANAL_FQUALIFIER_VOLATILE = 2, + R_ANAL_FQUALIFIER_INLINE = 3, + R_ANAL_FQUALIFIER_NAKED = 4, + R_ANAL_FQUALIFIER_VIRTUAL = 5, +}; + +/*--------------------Function Conventions-----------*/ +//XXX don't use them in the future +#define R_ANAL_CC_TYPE_STDCALL 0 +#define R_ANAL_CC_TYPE_PASCAL 1 +#define R_ANAL_CC_TYPE_FASTCALL 'A' // syscall +#define R_ANAL_CC_TYPE_SYSV 8 +#define R_ANAL_CC_MAXARG 16 + +enum { + R_ANAL_FCN_TYPE_NULL = 0, + R_ANAL_FCN_TYPE_FCN = 1 << 0, + R_ANAL_FCN_TYPE_LOC = 1 << 1, + R_ANAL_FCN_TYPE_SYM = 1 << 2, + R_ANAL_FCN_TYPE_IMP = 1 << 3, + R_ANAL_FCN_TYPE_INT = 1 << 4, /* privileged function - ends with iret/reti/.. */ + R_ANAL_FCN_TYPE_ROOT = 1 << 5, /* matching flag */ + R_ANAL_FCN_TYPE_ANY = -1 /* all the bits set */ +}; + +#define RzAnalBlock struct rz_anal_bb_t + +enum { + R_ANAL_DIFF_TYPE_NULL = 0, + R_ANAL_DIFF_TYPE_MATCH = 'm', + R_ANAL_DIFF_TYPE_UNMATCH = 'u' +}; + +typedef struct rz_anal_enum_case_t { + char *name; + int val; +} RzAnalEnumCase; + +typedef struct rz_anal_struct_member_t { + char *name; + char *type; + size_t offset; // in bytes + size_t size; // in bits? +} RzAnalStructMember; + +typedef struct rz_anal_union_member_t { + char *name; + char *type; + size_t offset; // in bytes + size_t size; // in bits? +} RzAnalUnionMember; + +typedef enum { + R_ANAL_BASE_TYPE_KIND_STRUCT, + R_ANAL_BASE_TYPE_KIND_UNION, + R_ANAL_BASE_TYPE_KIND_ENUM, + R_ANAL_BASE_TYPE_KIND_TYPEDEF, // probably temporary addition, dev purposes + R_ANAL_BASE_TYPE_KIND_ATOMIC, // For real atomic base types +} RzAnalBaseTypeKind; + +typedef struct rz_anal_base_type_struct_t { + RzVector/**/ members; +} RzAnalBaseTypeStruct; + +typedef struct rz_anal_base_type_union_t { + RzVector/**/ members; +} RzAnalBaseTypeUnion; + +typedef struct rz_anal_base_type_enum_t { + RzVector/* bits 0) (set-bits bits)) + int type; + const char *cc; // calling convention, should come from RzAnal.constpool + ut64 addr; + HtUP/**/ *labels; + HtPP/**/ *label_addrs; + RPVector vars; + HtUP/*>*/ *inst_vars; // offset of instructions => the variables they access + ut64 reg_save_area; // size of stack area pre-reserved for saving registers + st64 bp_off; // offset of bp inside owned stack frame + st64 stack; // stack frame size + int maxstack; + int ninstr; + bool folded; + bool is_pure; + bool is_variadic; + bool has_changed; // true if function may have changed since last anaysis TODO: set this attribute where necessary + bool bp_frame; + bool is_noreturn; // true if function does not return + ut8 *fingerprint; // TODO: make is fuzzy and smarter + size_t fingerprint_size; + RzAnalDiff *diff; + RzList *bbs; // TODO: should be RPVector + RzAnalFcnMeta meta; + RzList *imports; // maybe bound to class? + struct rz_anal_t *anal; // this function is associated with this instance +} RzAnalFunction; + +typedef struct rz_anal_func_arg_t { + const char *name; + const char *fmt; + const char *cc_source; + char *orig_c_type; + char *c_type; + ut64 size; + ut64 src; //Function-call argument value or pointer to it +} RzAnalFuncArg; + +struct rz_anal_type_t { + char *name; + ut32 type; + ut32 size; + RzList *content; +}; + +typedef enum { + R_META_TYPE_ANY = -1, + R_META_TYPE_DATA = 'd', + R_META_TYPE_CODE = 'c', + R_META_TYPE_STRING = 's', + R_META_TYPE_FORMAT = 'f', + R_META_TYPE_MAGIC = 'm', + R_META_TYPE_HIDE = 'h', + R_META_TYPE_COMMENT = 'C', + R_META_TYPE_RUN = 'r', + R_META_TYPE_HIGHLIGHT = 'H', + R_META_TYPE_VARTYPE = 't', +} RzAnalMetaType; + +/* meta */ +typedef struct rz_anal_meta_item_t { + RzAnalMetaType type; + int subtype; + char *str; + const RSpace *space; +} RzAnalMetaItem; + +// anal +typedef enum { + R_ANAL_OP_FAMILY_UNKNOWN = -1, + R_ANAL_OP_FAMILY_CPU = 0, /* normal cpu instruction */ + R_ANAL_OP_FAMILY_FPU, /* fpu (floating point) */ + R_ANAL_OP_FAMILY_MMX, /* multimedia instruction (packed data) */ + R_ANAL_OP_FAMILY_SSE, /* extended multimedia instruction (packed data) */ + R_ANAL_OP_FAMILY_PRIV, /* privileged instruction */ + R_ANAL_OP_FAMILY_CRYPTO, /* cryptographic instructions */ + R_ANAL_OP_FAMILY_THREAD, /* thread/lock/sync instructions */ + R_ANAL_OP_FAMILY_VIRT, /* virtualization instructions */ + R_ANAL_OP_FAMILY_SECURITY, /* security instructions */ + R_ANAL_OP_FAMILY_IO, /* IO instructions (i.e. IN/OUT) */ + R_ANAL_OP_FAMILY_LAST +} RzAnalOpFamily; + +#if 0 +On x86 according to Wikipedia + + Prefix group 1 + 0xF0: LOCK prefix + 0xF2: REPNE/REPNZ prefix + 0xF3: REP or REPE/REPZ prefix + Prefix group 2 + 0x2E: CS segment override + 0x36: SS segment override + 0x3E: DS segment override + 0x26: ES segment override + 0x64: FS segment override + 0x65: GS segment override + 0x2E: Branch not taken (hinting) + 0x3E: Branch taken + Prefix group 3 + 0x66: Operand-size override prefix + Prefix group 4 + 0x67: Address-size override prefix +#endif + typedef enum { + R_ANAL_OP_PREFIX_COND = 1, + R_ANAL_OP_PREFIX_REP = 1<<1, + R_ANAL_OP_PREFIX_REPNE = 1<<2, + R_ANAL_OP_PREFIX_LOCK = 1<<3, + R_ANAL_OP_PREFIX_LIKELY = 1<<4, + R_ANAL_OP_PREFIX_UNLIKELY = 1<<5 + /* TODO: add segment override typemods? */ + } RzAnalOpPrefix; + +// XXX: this definition is plain wrong. use enum or empower bits +#define R_ANAL_OP_TYPE_MASK 0x8000ffff +#define R_ANAL_OP_HINT_MASK 0xf0000000 +typedef enum { + R_ANAL_OP_TYPE_COND = 0x80000000, // TODO must be moved to prefix? + //TODO: MOVE TO PREFIX .. it is used by anal_java.. must be updated + R_ANAL_OP_TYPE_REP = 0x40000000, /* repeats next instruction N times */ + R_ANAL_OP_TYPE_MEM = 0x20000000, // TODO must be moved to prefix? + R_ANAL_OP_TYPE_REG = 0x10000000, // operand is a register + R_ANAL_OP_TYPE_IND = 0x08000000, // operand is indirect + R_ANAL_OP_TYPE_NULL = 0, + R_ANAL_OP_TYPE_JMP = 1, /* mandatory jump */ + R_ANAL_OP_TYPE_UJMP = 2, /* unknown jump (register or so) */ + R_ANAL_OP_TYPE_RJMP = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UJMP, + R_ANAL_OP_TYPE_IJMP = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_UJMP, + R_ANAL_OP_TYPE_IRJMP = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UJMP, + R_ANAL_OP_TYPE_CJMP = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_JMP, /* conditional jump */ + R_ANAL_OP_TYPE_RCJMP = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_CJMP, /* conditional jump register */ + R_ANAL_OP_TYPE_MJMP = R_ANAL_OP_TYPE_MEM | R_ANAL_OP_TYPE_JMP, /* memory jump */ + R_ANAL_OP_TYPE_MCJMP = R_ANAL_OP_TYPE_MEM | R_ANAL_OP_TYPE_CJMP, /* memory conditional jump */ + R_ANAL_OP_TYPE_UCJMP = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_UJMP, /* conditional unknown jump */ + R_ANAL_OP_TYPE_CALL = 3, /* call to subroutine (branch+link) */ + R_ANAL_OP_TYPE_UCALL = 4, /* unknown call (register or so) */ + R_ANAL_OP_TYPE_RCALL = R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UCALL, + R_ANAL_OP_TYPE_ICALL = R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_UCALL, + R_ANAL_OP_TYPE_IRCALL= R_ANAL_OP_TYPE_IND | R_ANAL_OP_TYPE_REG | R_ANAL_OP_TYPE_UCALL, + R_ANAL_OP_TYPE_CCALL = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_CALL, /* conditional call to subroutine */ + R_ANAL_OP_TYPE_UCCALL= R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_UCALL, /* conditional unknown call */ + R_ANAL_OP_TYPE_RET = 5, /* returns from subroutine */ + R_ANAL_OP_TYPE_CRET = R_ANAL_OP_TYPE_COND | R_ANAL_OP_TYPE_RET, /* conditional return from subroutine */ + R_ANAL_OP_TYPE_ILL = 6, /* illegal instruction // trap */ + R_ANAL_OP_TYPE_UNK = 7, /* unknown opcode type */ + R_ANAL_OP_TYPE_NOP = 8, /* does nothing */ + R_ANAL_OP_TYPE_MOV = 9, /* register move */ + R_ANAL_OP_TYPE_CMOV = 9 | R_ANAL_OP_TYPE_COND, /* conditional move */ + R_ANAL_OP_TYPE_TRAP = 10, /* it's a trap! */ + R_ANAL_OP_TYPE_SWI = 11, /* syscall, software interrupt */ + R_ANAL_OP_TYPE_CSWI = 11 | R_ANAL_OP_TYPE_COND, /* syscall, software interrupt */ + R_ANAL_OP_TYPE_UPUSH = 12, /* unknown push of data into stack */ + R_ANAL_OP_TYPE_RPUSH = R_ANAL_OP_TYPE_UPUSH | R_ANAL_OP_TYPE_REG, /* push register */ + R_ANAL_OP_TYPE_PUSH = 13, /* push value into stack */ + R_ANAL_OP_TYPE_POP = 14, /* pop value from stack to register */ + R_ANAL_OP_TYPE_CMP = 15, /* compare something */ + R_ANAL_OP_TYPE_ACMP = 16, /* compare via and */ + R_ANAL_OP_TYPE_ADD = 17, + R_ANAL_OP_TYPE_SUB = 18, + R_ANAL_OP_TYPE_IO = 19, + R_ANAL_OP_TYPE_MUL = 20, + R_ANAL_OP_TYPE_DIV = 21, + R_ANAL_OP_TYPE_SHR = 22, + R_ANAL_OP_TYPE_SHL = 23, + R_ANAL_OP_TYPE_SAL = 24, + R_ANAL_OP_TYPE_SAR = 25, + R_ANAL_OP_TYPE_OR = 26, + R_ANAL_OP_TYPE_AND = 27, + R_ANAL_OP_TYPE_XOR = 28, + R_ANAL_OP_TYPE_NOR = 29, + R_ANAL_OP_TYPE_NOT = 30, + R_ANAL_OP_TYPE_STORE = 31, /* store from register to memory */ + R_ANAL_OP_TYPE_LOAD = 32, /* load from memory to register */ + R_ANAL_OP_TYPE_LEA = 33, /* TODO add ulea */ + R_ANAL_OP_TYPE_LEAVE = 34, + R_ANAL_OP_TYPE_ROR = 35, + R_ANAL_OP_TYPE_ROL = 36, + R_ANAL_OP_TYPE_XCHG = 37, + R_ANAL_OP_TYPE_MOD = 38, + R_ANAL_OP_TYPE_SWITCH = 39, + R_ANAL_OP_TYPE_CASE = 40, + R_ANAL_OP_TYPE_LENGTH = 41, + R_ANAL_OP_TYPE_CAST = 42, + R_ANAL_OP_TYPE_NEW = 43, + R_ANAL_OP_TYPE_ABS = 44, + R_ANAL_OP_TYPE_CPL = 45, /* complement */ + R_ANAL_OP_TYPE_CRYPTO = 46, + R_ANAL_OP_TYPE_SYNC = 47, + //R_ANAL_OP_TYPE_DEBUG = 43, // monitor/trace/breakpoint +#if 0 + R_ANAL_OP_TYPE_PRIV = 40, /* privileged instruction */ + R_ANAL_OP_TYPE_FPU = 41, /* floating point stuff */ +#endif +} _RzAnalOpType; + +typedef enum { + R_ANAL_OP_MASK_BASIC = 0, // Just fills basic op info , it's fast + R_ANAL_OP_MASK_ESIL = 1, // It fills RzAnalop->esil info + R_ANAL_OP_MASK_VAL = 2, // It fills RzAnalop->dst/src info + R_ANAL_OP_MASK_HINT = 4, // It calls rz_anal_op_hint to override anal options + R_ANAL_OP_MASK_OPEX = 8, // It fills RzAnalop->opex info + R_ANAL_OP_MASK_DISASM = 16, // It fills RzAnalop->mnemonic // should be RzAnalOp->disasm // only from rz_core_anal_op() + R_ANAL_OP_MASK_ALL = 1 | 2 | 4 | 8 | 16 +} RzAnalOpMask; + +/* TODO: what to do with signed/unsigned conditionals? */ +typedef enum { + R_ANAL_COND_AL = 0, // Always executed (no condition) + R_ANAL_COND_EQ, // Equal + R_ANAL_COND_NE, // Not equal + R_ANAL_COND_GE, // Greater or equal + R_ANAL_COND_GT, // Greater than + R_ANAL_COND_LE, // Less or equal + R_ANAL_COND_LT, // Less than + R_ANAL_COND_NV, // Never executed must be a nop? :D + R_ANAL_COND_HS, // Carry set >, ==, or unordered + R_ANAL_COND_LO, // Carry clear Less than + R_ANAL_COND_MI, // Minus, negative Less than + R_ANAL_COND_PL, // Plus, positive or zero >, ==, or unordered + R_ANAL_COND_VS, // Overflow Unordered + R_ANAL_COND_VC, // No overflow Not unordered + R_ANAL_COND_HI, // Unsigned higher Greater than, or unordered + R_ANAL_COND_LS // Unsigned lower or same Less than or equal +} _RzAnalCond; + +typedef enum { + R_ANAL_VAR_SCOPE_LOCAL = 0x01 +} _RzAnalVarScope; + +typedef enum { + R_ANAL_STACK_NULL = 0, + R_ANAL_STACK_NOP, + R_ANAL_STACK_INC, + R_ANAL_STACK_GET, + R_ANAL_STACK_SET, + R_ANAL_STACK_RESET, + R_ANAL_STACK_ALIGN, +} RzAnalStackOp; + +enum { + R_ANAL_REFLINE_TYPE_UTF8 = 1, + R_ANAL_REFLINE_TYPE_WIDE = 2, /* reflines have a space between them */ + R_ANAL_REFLINE_TYPE_MIDDLE_BEFORE = 4, /* do not consider starts/ends of + * reflines (used for comment lines before disasm) */ + R_ANAL_REFLINE_TYPE_MIDDLE_AFTER = 8 /* as above but for lines after disasm */ +}; + +enum { + R_ANAL_RET_NOP = 0, + R_ANAL_RET_ERROR = -1, + R_ANAL_RET_DUP = -2, + R_ANAL_RET_NEW = -3, + R_ANAL_RET_END = -4 +}; + +typedef struct rz_anal_case_obj_t { + ut64 addr; + ut64 jump; + ut64 value; +} RzAnalCaseOp; + +typedef struct rz_anal_switch_obj_t { + ut64 addr; + ut64 min_val; + ut64 def_val; + ut64 max_val; + RzList/**/ *cases; +} RzAnalSwitchOp; + +struct rz_anal_t; +struct rz_anal_bb_t; +typedef struct rz_anal_callbacks_t { + int (*on_fcn_new) (struct rz_anal_t *, void *user, RzAnalFunction *fcn); + int (*on_fcn_delete) (struct rz_anal_t *, void *user, RzAnalFunction *fcn); + int (*on_fcn_rename) (struct rz_anal_t *, void *user, RzAnalFunction *fcn, const char *oldname); + int (*on_fcn_bb_new) (struct rz_anal_t *, void *user, RzAnalFunction *fcn, struct rz_anal_bb_t *bb); +} RzAnalCallbacks; + +#define R_ANAL_ESIL_GOTO_LIMIT 4096 + +typedef struct rz_anal_options_t { + int depth; + int graph_depth; + bool vars; //analyze local var and arguments + bool varname_stack; // name vars based on their offset in the stack + int cjmpref; + int jmpref; + int jmpabove; + bool ijmp; + bool jmpmid; // continue analysis after jmp into middle of insn + bool loads; + bool ignbithints; + int followdatarefs; + int searchstringrefs; + int followbrokenfcnsrefs; + int bb_max_size; + bool trycatch; + bool norevisit; + int afterjmp; // continue analysis after jmp eax or forward jmp // option + int recont; // continue on recurse analysis mode + int noncode; + int nopskip; // skip nops at the beginning of functions + int hpskip; // skip `mov reg,reg` and `lea reg,[reg]` + int jmptbl; // analyze jump tables + int nonull; + bool pushret; // analyze push+ret as jmp + bool armthumb; // + bool endsize; // chop function size which is known to be buggy but goodie too + bool delay; + int tailcall; + bool retpoline; +} RzAnalOptions; + +typedef enum { + R_ANAL_CPP_ABI_ITANIUM = 0, + R_ANAL_CPP_ABI_MSVC +} RzAnalCPPABI; + +typedef struct rz_anal_hint_cb_t { + //add more cbs as needed + void (*on_bits) (struct rz_anal_t *a, ut64 addr, int bits, bool set); +} RHintCb; + +typedef struct rz_anal_t { + char *cpu; // anal.cpu + char *os; // asm.os + int bits; // asm.bits + int lineswidth; // asm.lines.width + int big_endian; // cfg.bigendian + int sleep; // anal.sleep, sleep some usecs before analyzing more (avoid 100% cpu usages) + RzAnalCPPABI cpp_abi; // anal.cpp.abi + void *user; + ut64 gp; // anal.gp, global pointer. used for mips. but can be used by other arches too in the future + RBTree bb_tree; // all basic blocks by address. They can overlap each other, but must never start at the same address. + RzList *fcns; + HtUP *ht_addr_fun; // address => function + HtPP *ht_name_fun; // name => function + RzReg *reg; + ut8 *last_disasm_reg; + RzSyscall *syscall; + int diff_ops; + double diff_thbb; + double diff_thfcn; + RzIOBind iob; + RzFlagBind flb; + RzFlagSet flg_class_set; + RzFlagGet flg_class_get; + RzFlagSet flg_fcn_set; + RBinBind binb; // Set only from core when an analysis plugin is called. + RzCoreBind coreb; + int maxreflines; // asm.lines.maxref + int esil_goto_limit; // esil.gotolimit + int pcalign; // asm.pcalign + struct rz_anal_esil_t *esil; + struct rz_anal_plugin_t *cur; + RzAnalRange *limit; // anal.from, anal.to + RzList *plugins; + Sdb *sdb_types; + Sdb *sdb_fmts; + Sdb *sdb_zigns; + HtUP *dict_refs; + HtUP *dict_xrefs; + bool recursive_noreturn; // anal.rnr + RSpaces zign_spaces; + char *zign_path; // dir.zigns + PrintfCallback cb_printf; + //moved from RzAnalFcn + Sdb *sdb; // root + Sdb *sdb_pins; + HtUP/*>*/ *addr_hints; // all hints that correspond to a single address + RBTree/**/ arch_hints; + RBTree/**/ bits_hints; + RHintCb hint_cbs; + RIntervalTree meta; + RSpaces meta_spaces; + Sdb *sdb_cc; // calling conventions + Sdb *sdb_classes; + Sdb *sdb_classes_attrs; + RzAnalCallbacks cb; + RzAnalOptions opt; + RzList *reflines; + //RzList *noreturn; + RzListComparator columnSort; + int stackptr; + bool (*log)(struct rz_anal_t *anal, const char *msg); + bool (*read_at)(struct rz_anal_t *anal, ut64 addr, ut8 *buf, int len); + bool verbose; + int seggrn; + RzFlagGetAtAddr flag_get; + REvent *ev; + RzList/**/ *imports; // global imports + SetU *visited; + RStrConstPool constpool; + RzList *leaddrs; +} RzAnal; + +typedef enum rz_anal_addr_hint_type_t { + R_ANAL_ADDR_HINT_TYPE_IMMBASE, + R_ANAL_ADDR_HINT_TYPE_JUMP, + R_ANAL_ADDR_HINT_TYPE_FAIL, + R_ANAL_ADDR_HINT_TYPE_STACKFRAME, + R_ANAL_ADDR_HINT_TYPE_PTR, + R_ANAL_ADDR_HINT_TYPE_NWORD, + R_ANAL_ADDR_HINT_TYPE_RET, + R_ANAL_ADDR_HINT_TYPE_NEW_BITS, + R_ANAL_ADDR_HINT_TYPE_SIZE, + R_ANAL_ADDR_HINT_TYPE_SYNTAX, + R_ANAL_ADDR_HINT_TYPE_OPTYPE, + R_ANAL_ADDR_HINT_TYPE_OPCODE, + R_ANAL_ADDR_HINT_TYPE_TYPE_OFFSET, + R_ANAL_ADDR_HINT_TYPE_ESIL, + R_ANAL_ADDR_HINT_TYPE_HIGH, + R_ANAL_ADDR_HINT_TYPE_VAL +} RzAnalAddrHintType; + +typedef struct rz_anal_addr_hint_record_t { + RzAnalAddrHintType type; + union { + char *type_offset; + int nword; + ut64 jump; + ut64 fail; + int newbits; + int immbase; + ut64 ptr; + ut64 retval; + char *syntax; + char *opcode; + char *esil; + int optype; + ut64 size; + ut64 stackframe; + ut64 val; + }; +} RzAnalAddrHintRecord; + +typedef struct rz_anal_hint_t { + ut64 addr; + ut64 ptr; + ut64 val; // used to hint jmp rax + ut64 jump; + ut64 fail; + ut64 ret; // hint for function ret values + char *arch; + char *opcode; + char *syntax; + char *esil; + char *offset; + ut32 type; + ut64 size; + int bits; + int new_bits; // change asm.bits after evaluating this instruction + int immbase; + bool high; // highlight hint + int nword; + ut64 stackframe; +} RzAnalHint; + +typedef RzAnalFunction *(* RzAnalGetFcnIn)(RzAnal *anal, ut64 addr, int type); +typedef RzAnalHint *(* RzAnalGetHint)(RzAnal *anal, ut64 addr); + +typedef struct rz_anal_bind_t { + RzAnal *anal; + RzAnalGetFcnIn get_fcn_in; + RzAnalGetHint get_hint; +} RzAnalBind; + +typedef const char *(*RzAnalLabelAt) (RzAnalFunction *fcn, ut64); + +typedef enum { + R_ANAL_VAR_KIND_REG = 'r', + R_ANAL_VAR_KIND_BPV = 'b', + R_ANAL_VAR_KIND_SPV = 's' +} RzAnalVarKind; + +#define VARPREFIX "var" +#define ARGPREFIX "arg" + +typedef enum { + R_ANAL_VAR_ACCESS_TYPE_READ = (1 << 0), + R_ANAL_VAR_ACCESS_TYPE_WRITE = (1 << 1) +} RzAnalVarAccessType; + +typedef struct rz_anal_var_access_t { + const char *reg; // register used for access + st64 offset; // relative to the function's entrypoint + st64 stackptr; // delta added to register to get the var, e.g. [rbp - 0x10] + ut8 type; // RzAnalVarAccessType bits +} RzAnalVarAccess; + +typedef struct rz_anal_var_constraint_t { + _RzAnalCond cond; + ut64 val; +} RzAnalVarConstraint; + +// generic for args and locals +typedef struct rz_anal_var_t { + RzAnalFunction *fcn; + char *name; // name of the variable + char *type; // cparse type of the variable + RzAnalVarKind kind; + bool isarg; + int delta; /* delta offset inside stack frame */ + char *regname; // name of the register + RzVector/**/ accesses; // ordered by offset, touch this only through API or expect uaf + char *comment; + RzVector/**/ constraints; + + // below members are just for caching, TODO: remove them and do it better + int argnum; +} RzAnalVar; + +// Refers to a variable or a struct field inside a variable, only for varsub +R_DEPRECATE typedef struct rz_anal_var_field_t { + char *name; + st64 delta; + bool field; +} RzAnalVarField; + +typedef enum { + R_ANAL_ACC_UNKNOWN = 0, + R_ANAL_ACC_R = (1 << 0), + R_ANAL_ACC_W = (1 << 1), +} RzAnalValueAccess; + +typedef enum { + R_ANAL_VAL_REG, + R_ANAL_VAL_MEM, + R_ANAL_VAL_IMM, +} RzAnalValueType; + +// base+reg+regdelta*mul+delta +typedef struct rz_anal_value_t { + RzAnalValueType type; + RzAnalValueAccess access; + int absolute; // if true, unsigned cast is used + int memref; // is memory reference? which size? 1, 2 ,4, 8 + ut64 base ; // numeric address + st64 delta; // numeric delta + st64 imm; // immediate value + int mul; // multiplier (reg*4+base) + RzRegItem *seg; // segment selector register + RzRegItem *reg; // register / register base used (-1 if no reg) + RzRegItem *regdelta; // register index used (-1 if no reg) +} RzAnalValue; + +typedef enum { + R_ANAL_OP_DIR_READ = 1, + R_ANAL_OP_DIR_WRITE = 2, + R_ANAL_OP_DIR_EXEC = 4, + R_ANAL_OP_DIR_REF = 8, +} RzAnalOpDirection; + +typedef enum rz_anal_data_type_t { + R_ANAL_DATATYPE_NULL = 0, + R_ANAL_DATATYPE_ARRAY, + R_ANAL_DATATYPE_OBJECT, // instance + R_ANAL_DATATYPE_STRING, + R_ANAL_DATATYPE_CLASS, + R_ANAL_DATATYPE_BOOLEAN, + R_ANAL_DATATYPE_INT16, + R_ANAL_DATATYPE_INT32, + R_ANAL_DATATYPE_INT64, + R_ANAL_DATATYPE_FLOAT, +} RzAnalDataType; + +typedef struct rz_anal_op_t { + char *mnemonic; /* mnemonic.. it actually contains the args too, we should replace rasm with this */ + ut64 addr; /* address */ + ut32 type; /* type of opcode */ + RzAnalOpPrefix prefix; /* type of opcode prefix (rep,lock,..) */ + ut32 type2; /* used by java */ + RzAnalStackOp stackop; /* operation on stack? */ + _RzAnalCond cond; /* condition type */ + int size; /* size in bytes of opcode */ + int nopcode; /* number of bytes representing the opcode (not the arguments) TODO: find better name */ + int cycles; /* cpu-cycles taken by instruction */ + int failcycles; /* conditional cpu-cycles */ + RzAnalOpFamily family; /* family of opcode */ + int id; /* instruction id */ + bool eob; /* end of block (boolean) */ + bool sign; /* operates on signed values, false by default */ + /* Run N instructions before executing the current one */ + int delay; /* delay N slots (mips, ..)*/ + ut64 jump; /* true jmp */ + ut64 fail; /* false jmp */ + RzAnalOpDirection direction; + st64 ptr; /* reference to memory */ /* XXX signed? */ + ut64 val; /* reference to value */ /* XXX signed? */ + int ptrsize; /* f.ex: zero extends for 8, 16 or 32 bits only */ + st64 stackptr; /* stack pointer */ + int refptr; /* if (0) ptr = "reference" else ptr = "load memory of refptr bytes" */ + RzAnalValue *src[3]; + RzAnalValue *dst; + RzList *access; /* RzAnalValue access information */ + RStrBuf esil; + RStrBuf opex; + const char *reg; /* destination register */ + const char *ireg; /* register used for indirect memory computation*/ + int scale; + ut64 disp; + RzAnalSwitchOp *switch_op; + RzAnalHint hint; + RzAnalDataType datatype; +} RzAnalOp; + +#define R_ANAL_COND_SINGLE(x) (!x->arg[1] || x->arg[0]==x->arg[1]) + +typedef struct rz_anal_cond_t { + int type; // filled by CJMP opcode + RzAnalValue *arg[2]; // filled by CMP opcode +} RzAnalCond; + +typedef struct rz_anal_bb_t { + RBNode _rb; // private, node in the RBTree + ut64 _max_end; // private, augmented value for RBTree + + ut64 addr; + ut64 size; + ut64 jump; + ut64 fail; + bool traced; + bool folded; + ut32 colorize; + ut8 *fingerprint; + RzAnalDiff *diff; + RzAnalCond *cond; + RzAnalSwitchOp *switch_op; + ut16 *op_pos; // offsets of instructions in this block, count is ninstr - 1 (first is always 0) + ut8 *op_bytes; + ut8 *parent_reg_arena; + int op_pos_size; // size of the op_pos array + int ninstr; + int stackptr; + int parent_stackptr; + ut64 cmpval; + const char *cmpreg; + + RzList *fcns; + RzAnal *anal; + int ref; +#undef RzAnalBlock +} RzAnalBlock; + +typedef enum { + R_ANAL_REF_TYPE_NULL = 0, + R_ANAL_REF_TYPE_CODE = 'c', // code ref + R_ANAL_REF_TYPE_CALL = 'C', // code ref (call) + R_ANAL_REF_TYPE_DATA = 'd', // mem ref + R_ANAL_REF_TYPE_STRING='s' // string ref +} RzAnalRefType; + +typedef struct rz_anal_ref_t { + ut64 addr; + ut64 at; + RzAnalRefType type; +} RzAnalRef; +RZ_API const char *rz_anal_ref_type_tostring(RzAnalRefType t); + +/* represents a reference line from one address (from) to another (to) */ +typedef struct rz_anal_refline_t { + ut64 from; + ut64 to; + int index; + int level; + int type; + int direction; +} RzAnalRefline; + +typedef struct rz_anal_cycle_frame_t { + ut64 naddr; //next addr + RzList *hooks; + struct rz_anal_cycle_frame_t *prev; +} RzAnalCycleFrame; + +typedef struct rz_anal_cycle_hook_t { //rename ? + ut64 addr; + int cycles; +} RzAnalCycleHook; + +typedef struct rz_anal_esil_word_t { + int type; + const char *str; +} RzAnalEsilWord; + +// only flags that affect control flow +enum { + R_ANAL_ESIL_FLAG_ZERO = 1, + R_ANAL_ESIL_FLAG_CARRY = 2, + R_ANAL_ESIL_FLAG_OVERFLOW = 4, + R_ANAL_ESIL_FLAG_PARITY = 8, + R_ANAL_ESIL_FLAG_SIGN = 16, + // ... +}; + +enum { + R_ANAL_TRAP_NONE = 0, + R_ANAL_TRAP_UNHANDLED = 1, + R_ANAL_TRAP_BREAKPOINT = 2, + R_ANAL_TRAP_DIVBYZERO = 3, + R_ANAL_TRAP_WRITE_ERR = 4, + R_ANAL_TRAP_READ_ERR = 5, + R_ANAL_TRAP_EXEC_ERR = 6, + R_ANAL_TRAP_INVALID = 7, + R_ANAL_TRAP_UNALIGNED = 8, + R_ANAL_TRAP_TODO = 9, + R_ANAL_TRAP_HALT = 10, +}; + +enum { + R_ANAL_ESIL_PARM_INVALID = 0, + R_ANAL_ESIL_PARM_REG, + R_ANAL_ESIL_PARM_NUM, +}; + +/* Constructs to convert from ESIL to REIL */ +#define FOREACHOP(GENERATE) \ +/* No Operation */ GENERATE(NOP) \ +/* Unknown/Undefined */ GENERATE(UNK) \ +/* Conditional Jump */ GENERATE(JCC) \ +/* Store Value to register */ GENERATE(STR) \ +/* Store value to memory */ GENERATE(STM) \ +/* Load value from memory */ GENERATE(LDM) \ +/* Addition */ GENERATE(ADD) \ +/* Subtraction */ GENERATE(SUB) \ +/* Negation */ GENERATE(NEG) \ +/* Multiplication */ GENERATE(MUL) \ +/* Division */ GENERATE(DIV) \ +/* Modulo */ GENERATE(MOD) \ +/* Signed Multiplication */ GENERATE(SMUL) \ +/* Sugned Division */ GENERATE(SDIV) \ +/* Signed Modulus */ GENERATE(SMOD) \ +/* Shift Left */ GENERATE(SHL) \ +/* Shift Right */ GENERATE(SHR) \ +/* Binary and */ GENERATE(AND) \ +/* Binary or */ GENERATE(OR) \ +/* Binary xor */ GENERATE(XOR) \ +/* Binary not */ GENERATE(NOT) \ +/* Equation */ GENERATE(EQ) \ +/* Less Than */ GENERATE(LT) + +#define MAKE_ENUM(OP) REIL_##OP, +#define REIL_OP_STRING(STRING) #STRING, + +typedef enum { + FOREACHOP(MAKE_ENUM) +} RzAnalReilOpcode; + +typedef enum { + ARG_REG, // CPU Register + ARG_TEMP, // Temporary register used by REIL + ARG_CONST, // Constant value + ARG_ESIL_INTERNAL, // Used to resolve ESIL internal flags + ARG_NONE // Operand not used by the instruction +} RzAnalReilArgType; + +// Arguments to a REIL instruction. +typedef struct rz_anal_reil_arg { + RzAnalReilArgType type; // Type of the argument + ut8 size; // Size of the argument in bytes + char name[32]; // Name of the argument +} RzAnalReilArg; + +typedef struct rz_anal_ref_char { + char *str; + char *cols; +} RzAnalRefStr; + +// Instruction arg1, arg2, arg3 +typedef struct rz_anal_reil_inst { + RzAnalReilOpcode opcode; + RzAnalReilArg *arg[3]; +} RzAnalReilInst; + +typedef struct rz_anal_reil { + char old[32]; // Used to compute flags. + char cur[32]; + ut8 lastsz; + ut64 reilNextTemp; // Used to store the index of the next REIL temp register to be used. + ut64 addr; // Used for instruction sequencing. Check esil2reil.c for details. + ut8 seq_num; // Incremented and used when noInc is set to 1. + int skip; + int cmd_count; + char if_buf[64]; + char pc[8]; +} RzAnalReil; + +// must be a char +#define ESIL_INTERNAL_PREFIX '$' +#define ESIL_STACK_NAME "esil.ram" +#define ESIL struct rz_anal_esil_t + +typedef struct rz_anal_esil_source_t { + ut32 id; + ut32 claimed; + void *content; +} RzAnalEsilSource; + +RZ_API void rz_anal_esil_sources_init(ESIL *esil); +RZ_API ut32 rz_anal_esil_load_source(ESIL *esil, const char *path); +RZ_API void *rz_anal_esil_get_source(ESIL *esil, ut32 src_id); +RZ_API bool rz_anal_esil_claim_source(ESIL *esil, ut32 src_id); +RZ_API void rz_anal_esil_release_source(ESIL *esil, ut32 src_id); +RZ_API void rz_anal_esil_sources_fini(ESIL *esil); + +typedef bool (*RzAnalEsilInterruptCB)(ESIL *esil, ut32 interrupt, void *user); + +typedef struct rz_anal_esil_interrupt_handler_t { + const ut32 num; + const char* name; + void *(*init)(ESIL *esil); + RzAnalEsilInterruptCB cb; + void (*fini)(void *user); +} RzAnalEsilInterruptHandler; + +typedef struct rz_anal_esil_interrupt_t { + RzAnalEsilInterruptHandler *handler; + void *user; + ut32 src_id; +} RzAnalEsilInterrupt; + +typedef struct rz_anal_esil_change_reg_t { + int idx; + ut64 data; +} RzAnalEsilRegChange; + +typedef struct rz_anal_esil_change_mem_t { + int idx; + ut8 data; +} RzAnalEsilMemChange; + +typedef struct rz_anal_esil_trace_t { + int idx; + int end_idx; + HtUP *registers; + HtUP *memory; + RzRegArena *arena[R_REG_TYPE_LAST]; + ut64 stack_addr; + ut64 stack_size; + ut8 *stack_data; + //TODO remove `db` and reuse info above + Sdb *db; +} RzAnalEsilTrace; + +typedef int (*RzAnalEsilHookRegWriteCB)(ESIL *esil, const char *name, ut64 *val); + +typedef struct rz_anal_esil_callbacks_t { + void *user; + /* callbacks */ + int (*hook_flag_read)(ESIL *esil, const char *flag, ut64 *num); + int (*hook_command)(ESIL *esil, const char *op); + int (*hook_mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len); + int (*mem_read)(ESIL *esil, ut64 addr, ut8 *buf, int len); + int (*hook_mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len); + int (*mem_write)(ESIL *esil, ut64 addr, const ut8 *buf, int len); + int (*hook_reg_read)(ESIL *esil, const char *name, ut64 *res, int *size); + int (*reg_read)(ESIL *esil, const char *name, ut64 *res, int *size); + RzAnalEsilHookRegWriteCB hook_reg_write; + int (*reg_write)(ESIL *esil, const char *name, ut64 val); +} RzAnalEsilCallbacks; + +typedef struct rz_anal_esil_t { + RzAnal *anal; + char **stack; + ut64 addrmask; + int stacksize; + int stackptr; + ut32 skip; + int nowrite; + int iotrap; + int exectrap; + int repeat; + int parse_stop; + int parse_goto; + int parse_goto_count; + int verbose; + ut64 flags; + ut64 address; + ut64 stack_addr; + ut32 stack_size; + int delay; // mapped to $ds in ESIL + ut64 jump_target; // mapped to $jt in ESIL + int jump_target_set; // mapped to $js in ESIL + int trap; + ut32 trap_code; // extend into a struct to store more exception info? + // parity flag? done with cur + ut64 old; //used for carry-flagging and borrow-flagging + ut64 cur; //used for carry-flagging and borrow-flagging + ut8 lastsz; //in bits //used for signature-flag + /* native ops and custom ops */ + HtPP *ops; + char *current_opstr; + RIDStorage *sources; + SdbMini *interrupts; + //this is a disgusting workaround, because we have no ht-like storage without magic keys, that you cannot use, with int-keys + RzAnalEsilInterrupt *intr0; + /* deep esil parsing fills this */ + Sdb *stats; + RzAnalEsilTrace *trace; + RzAnalEsilCallbacks cb; + RzAnalReil *Reil; + // this is so cursed, can we please remove external commands from esil internals. + // Function pointers are fine, but not commands + char *cmd_step; // r2 (external) command to run before a step is performed + char *cmd_step_out; // r2 (external) command to run after a step is performed + char *cmd_intr; // r2 (external) command to run when an interrupt occurs + char *cmd_trap; // r2 (external) command to run when a trap occurs + char *cmd_mdev; // r2 (external) command to run when an memory mapped device address is used + char *cmd_todo; // r2 (external) command to run when esil expr contains TODO + char *cmd_ioer; // r2 (external) command to run when esil fails to IO + char *mdev_range; // string containing the rz_str_range to match for read/write accesses + bool (*cmd)(ESIL *esil, const char *name, ut64 a0, ut64 a1); + void *user; + int stack_fd; // ahem, let's not do this +} RzAnalEsil; + +#undef ESIL + + +enum { + R_ANAL_ESIL_OP_TYPE_UNKNOWN = 0x1, + R_ANAL_ESIL_OP_TYPE_CONTROL_FLOW, + R_ANAL_ESIL_OP_TYPE_MEM_READ = 0x4, + R_ANAL_ESIL_OP_TYPE_MEM_WRITE = 0x8, + R_ANAL_ESIL_OP_TYPE_REG_WRITE = 0x10, + R_ANAL_ESIL_OP_TYPE_MATH = 0x20, + R_ANAL_ESIL_OP_TYPE_CUSTOM = 0x40 +}; + + +typedef bool (*RzAnalEsilOpCb)(RzAnalEsil *esil); + +typedef struct rz_anal_esil_operation_t { + RzAnalEsilOpCb code; + ut32 push; // amount of operands pushed + ut32 pop; // amount of operands popped + ut32 type; +} RzAnalEsilOp; + + +// this is 80-bit offsets so we can address every piece of esil in an instruction +typedef struct rz_anal_esil_expr_offset_t { + ut64 off; + ut16 idx; +} RzAnalEsilEOffset; + +typedef enum { + R_ANAL_ESIL_BLOCK_ENTER_NORMAL = 0, + R_ANAL_ESIL_BLOCK_ENTER_TRUE, + R_ANAL_ESIL_BLOCK_ENTER_FALSE, + R_ANAL_ESIL_BLOCK_ENTER_GLUE, +} RzAnalEsilBlockEnterType; + +typedef struct rz_anal_esil_basic_block_t { + RzAnalEsilEOffset first; + RzAnalEsilEOffset last; + char *expr; //synthesized esil-expression for this block + RzAnalEsilBlockEnterType enter; //maybe more type is needed here +} RzAnalEsilBB; + +typedef struct rz_anal_esil_cfg_t { + RGraphNode *start; + RGraphNode *end; + RGraph *g; +} RzAnalEsilCFG; + +typedef enum { + R_ANAL_ESIL_DFG_BLOCK_CONST = 1, + R_ANAL_ESIL_DFG_BLOCK_VAR = 2, + R_ANAL_ESIL_DFG_BLOCK_PTR = 4, + R_ANAL_ESIL_DFG_BLOCK_RESULT = 8, + R_ANAL_ESIL_DFG_BLOCK_GENERATIVE = 16, +} RzAnalEsilDFGBlockType; + +typedef struct rz_anal_esil_dfg_t { + ut32 idx; + Sdb *regs; //resolves regnames to intervals + RContRBTree *reg_vars; //vars represented in regs + RQueue *todo; //todo-queue allocated in this struct for perf + void *insert; //needed for setting regs in dfg + RGraph *flow; + RGraphNode *cur; + RGraphNode *old; + bool malloc_failed; +} RzAnalEsilDFG; + +typedef struct rz_anal_esil_dfg_node_t { + // add more info here + ut32 idx; + RStrBuf *content; + RzAnalEsilDFGBlockType type; +} RzAnalEsilDFGNode; + +typedef int (*RzAnalCmdExt)(/* Rcore */RzAnal *anal, const char* input); + +// TODO: rm data + len +typedef int (*RzAnalOpCallback)(RzAnal *a, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask); + +typedef bool (*RzAnalRegProfCallback)(RzAnal *a); +typedef char*(*RzAnalRegProfGetCallback)(RzAnal *a); +typedef int (*RzAnalFPBBCallback)(RzAnal *a, RzAnalBlock *bb); +typedef int (*RzAnalFPFcnCallback)(RzAnal *a, RzAnalFunction *fcn); +typedef int (*RzAnalDiffBBCallback)(RzAnal *anal, RzAnalFunction *fcn, RzAnalFunction *fcn2); +typedef int (*RzAnalDiffFcnCallback)(RzAnal *anal, RzList *fcns, RzList *fcns2); +typedef int (*RzAnalDiffEvalCallback)(RzAnal *anal); + +typedef int (*RzAnalEsilCB)(RzAnalEsil *esil); +typedef int (*RzAnalEsilLoopCB)(RzAnalEsil *esil, RzAnalOp *op); +typedef int (*RzAnalEsilTrapCB)(RzAnalEsil *esil, int trap_type, int trap_code); + +typedef struct rz_anal_plugin_t { + char *name; + char *desc; + char *license; + char *arch; + char *author; + char *version; + int bits; + int esil; // can do esil or not + int fileformat_type; + int (*init)(void *user); + int (*fini)(void *user); + //int (*reset_counter) (RzAnal *anal, ut64 start_addr); + int (*archinfo)(RzAnal *anal, int query); + ut8* (*anal_mask)(RzAnal *anal, int size, const ut8 *data, ut64 at); + RzList* (*preludes)(RzAnal *anal); + + // legacy rz_anal_functions + RzAnalOpCallback op; + + // command extension to directly call any analysis functions + RzAnalCmdExt cmd_ext; + + RzAnalRegProfCallback set_reg_profile; + RzAnalRegProfGetCallback get_reg_profile; + RzAnalFPBBCallback fingerprint_bb; + RzAnalFPFcnCallback fingerprint_fcn; + RzAnalDiffBBCallback diff_bb; + RzAnalDiffFcnCallback diff_fcn; + RzAnalDiffEvalCallback diff_eval; + + RzAnalEsilCB esil_init; // initialize esil-related stuff + RzAnalEsilLoopCB esil_post_loop; //cycle-counting, firing interrupts, ... + RzAnalEsilTrapCB esil_trap; // traps / exceptions + RzAnalEsilCB esil_fini; // deinitialize +} RzAnalPlugin; + +/*----------------------------------------------------------------------------------------------*/ +int * (rz_anal_compare) (RzAnalFunction , RzAnalFunction ); +/*----------------------------------------------------------------------------------------------*/ + +#ifdef RZ_API +/* --------- */ /* REFACTOR */ /* ---------- */ +RZ_API RzListRange* rz_listrange_new (void); +RZ_API void rz_listrange_free(RzListRange *s); +RZ_API void rz_listrange_add(RzListRange *s, RzAnalFunction *f); +RZ_API void rz_listrange_del(RzListRange *s, RzAnalFunction *f); +RZ_API void rz_listrange_resize(RzListRange *s, RzAnalFunction *f, int newsize); +RZ_API RzAnalFunction *rz_listrange_find_in_range(RzListRange* s, ut64 addr); +RZ_API RzAnalFunction *rz_listrange_find_root(RzListRange* s, ut64 addr); +/* --------- */ /* REFACTOR */ /* ---------- */ +/* type.c */ +RZ_API RzAnalType *rz_anal_type_new(void); +RZ_API void rz_anal_type_add(RzAnal *l, RzAnalType *t); +RZ_API RzAnalType *rz_anal_type_find(RzAnal *a, const char* name); +RZ_API void rz_anal_type_list(RzAnal *a, short category, short enabled); +RZ_API const char *rz_anal_datatype_to_string(RzAnalDataType t); +RZ_API RzAnalType *rz_anal_str_to_type(RzAnal *a, const char* s); +RZ_API bool rz_anal_op_nonlinear(int t); +RZ_API bool rz_anal_op_ismemref(int t); +RZ_API const char *rz_anal_optype_to_string(int t); +RZ_API int rz_anal_optype_from_string(const char *type); +RZ_API const char *rz_anal_op_family_to_string (int n); +RZ_API int rz_anal_op_family_from_string(const char *f); +RZ_API int rz_anal_op_hint(RzAnalOp *op, RzAnalHint *hint); +RZ_API RzAnalType *rz_anal_type_free(RzAnalType *t); +RZ_API RzAnalType *rz_anal_type_loadfile(RzAnal *a, const char *path); + +/* block.c */ +typedef bool (*RzAnalBlockCb)(RzAnalBlock *block, void *user); +typedef bool (*RzAnalAddrCb)(ut64 addr, void *user); + +// lifetime +RZ_API void rz_anal_block_ref(RzAnalBlock *bb); +RZ_API void rz_anal_block_unref(RzAnalBlock *bb); + +// Create one block covering the given range. +// This will fail if the range overlaps any existing blocks. +RZ_API RzAnalBlock *rz_anal_create_block(RzAnal *anal, ut64 addr, ut64 size); + +static inline bool rz_anal_block_contains(RzAnalBlock *bb, ut64 addr) { + return addr >= bb->addr && addr < bb->addr + bb->size; +} + +// Split the block at the given address into two blocks. +// bb will stay the first block, the second block will be returned (or NULL on failure) +// The returned block will always be refd, i.e. it is necessary to always call rz_anal_block_unref() on the return value! +RZ_API RzAnalBlock *rz_anal_block_split(RzAnalBlock *bb, ut64 addr); + +static inline bool rz_anal_block_is_contiguous(RzAnalBlock *a, RzAnalBlock *b) { + return (a->addr + a->size) == b->addr; +} + +// Merge block b into a. +// b will be FREED (not just unrefd) and is NOT VALID anymore if this function is successful! +// This only works if b follows directly after a and their function lists are identical. +// returns true iff the blocks could be merged +RZ_API bool rz_anal_block_merge(RzAnalBlock *a, RzAnalBlock *b); + +// Manually delete a block and remove it from all its functions +// If there are more references to it than from its functions only, it will not be removed immediately! +RZ_API void rz_anal_delete_block(RzAnalBlock *bb); + +RZ_API void rz_anal_block_set_size(RzAnalBlock *block, ut64 size); + +// Set the address and size of the block. +// This can fail (and return false) if there is already another block at the new address +RZ_API bool rz_anal_block_relocate(RzAnalBlock *block, ut64 addr, ut64 size); + +RZ_API RzAnalBlock *rz_anal_get_block_at(RzAnal *anal, ut64 addr); +RZ_API bool rz_anal_blocks_foreach_in(RzAnal *anal, ut64 addr, RzAnalBlockCb cb, void *user); +RZ_API RzList *rz_anal_get_blocks_in(RzAnal *anal, ut64 addr); // values from rz_anal_blocks_foreach_in as a list +RZ_API void rz_anal_blocks_foreach_intersect(RzAnal *anal, ut64 addr, ut64 size, RzAnalBlockCb cb, void *user); +RZ_API RzList *rz_anal_get_blocks_intersect(RzAnal *anal, ut64 addr, ut64 size); // values from rz_anal_blocks_foreach_intersect as a list + +// Call cb on every direct successor address of block +// returns false if the loop was breaked by cb +RZ_API bool rz_anal_block_successor_addrs_foreach(RzAnalBlock *block, RzAnalAddrCb cb, void *user); + +// Call cb on block and every (recursive) successor of it +// returns false if the loop was breaked by cb +RZ_API bool rz_anal_block_recurse(RzAnalBlock *block, RzAnalBlockCb cb, void *user); + +// Call cb on block and every (recursive) successor of it +// If cb returns false, recursion stops only for that block +// returns false if the loop was breaked by cb +RZ_API bool rz_anal_block_recurse_followthrough(RzAnalBlock *block, RzAnalBlockCb cb, void *user); + +// Call cb on block and every (recursive) successor of it +// Call on_exit on block that doesn't have non-visited successors +// returns false if the loop was breaked by cb +RZ_API bool rz_anal_block_recurse_depth_first(RzAnalBlock *block, RzAnalBlockCb cb, R_NULLABLE RzAnalBlockCb on_exit, void *user); + +// same as rz_anal_block_recurse, but returns the blocks as a list +RZ_API RzList *rz_anal_block_recurse_list(RzAnalBlock *block); + +// return one shortest path from block to dst or NULL if none exists. +RZ_API R_NULLABLE RzList/**/ *rz_anal_block_shortest_path(RzAnalBlock *block, ut64 dst); + +// Add a case to the block's switch_op. +// If block->switch_op is NULL, it will be created with the given switch_addr. +RZ_API void rz_anal_block_add_switch_case(RzAnalBlock *block, ut64 switch_addr, ut64 case_value, ut64 case_addr); + +// Chop off the block at the specified address and remove all destinations. +// Blocks that have become unreachable after this operation will be automatically removed from all functions of block. +// addr must be the address directly AFTER the noreturn call! +// After the chopping, an rz_anal_block_automerge() is performed on the touched blocks. +// IMPORTANT: The automerge might also FREE block! This function returns block iff it is still valid afterwards. +// If this function returns NULL, the pointer to block MUST not be touched anymore! +RZ_API RzAnalBlock *rz_anal_block_chop_noreturn(RzAnalBlock *block, ut64 addr); + +// Merge every block in blocks with their contiguous predecessor, if possible. +// IMPORTANT: Merged blocks will be FREED! The blocks list will be updated to contain only the survived blocks. +RZ_API void rz_anal_block_automerge(RzList *blocks); + +// return true iff an instruction in the given basic block starts at the given address +RZ_API bool rz_anal_block_op_starts_at(RzAnalBlock *block, ut64 addr); + +// --------------------------------------- + +/* function.c */ + +RZ_API RzAnalFunction *rz_anal_function_new(RzAnal *anal); +RZ_API void rz_anal_function_free(void *fcn); + +// Add a function created with rz_anal_function_new() to anal +RZ_API bool rz_anal_add_function(RzAnal *anal, RzAnalFunction *fcn); + +// Create a new function and add it to anal (rz_anal_function_new() + set members + rz_anal_add_function()) +RZ_API RzAnalFunction *rz_anal_create_function(RzAnal *anal, const char *name, ut64 addr, int type, RzAnalDiff *diff); + +// returns all functions that have a basic block containing the given address +RZ_API RzList *rz_anal_get_functions_in(RzAnal *anal, ut64 addr); + +// returns the function that has its entrypoint at addr or NULL +RZ_API RzAnalFunction *rz_anal_get_function_at(RzAnal *anal, ut64 addr); + +RZ_API bool rz_anal_function_delete(RzAnalFunction *fcn); + +// rhange the entrypoint of fcn +// This can fail (and return false) if there is already another function at the new address +RZ_API bool rz_anal_function_relocate(RzAnalFunction *fcn, ut64 addr); + +// rename the given function +// This can fail (and return false) if there is another function with the name given +RZ_API bool rz_anal_function_rename(RzAnalFunction *fcn, const char *name); + +RZ_API void rz_anal_function_add_block(RzAnalFunction *fcn, RzAnalBlock *bb); +RZ_API void rz_anal_function_remove_block(RzAnalFunction *fcn, RzAnalBlock *bb); + + +// size of the entire range that the function spans, including holes. +// this is exactly rz_anal_function_max_addr() - rz_anal_function_min_addr() +RZ_API ut64 rz_anal_function_linear_size(RzAnalFunction *fcn); + +// lowest address covered by the function +RZ_API ut64 rz_anal_function_min_addr(RzAnalFunction *fcn); + +// first address directly after the function +RZ_API ut64 rz_anal_function_max_addr(RzAnalFunction *fcn); + +// size from the function entrypoint (fcn->addr) to the end of the function (rz_anal_function_max_addr) +RZ_API ut64 rz_anal_function_size_from_entry(RzAnalFunction *fcn); + +// the "real" size of the function, that is the sum of the size of the +// basicblocks this function is composed of +RZ_API ut64 rz_anal_function_realsize(const RzAnalFunction *fcn); + +// returns whether the function contains a basic block that contains addr +// This is completely independent of fcn->addr, which is only the entrypoint! +RZ_API bool rz_anal_function_contains(RzAnalFunction *fcn, ut64 addr); + +/* anal.c */ +RZ_API RzAnal *rz_anal_new(void); +RZ_API void rz_anal_purge(RzAnal *anal); +RZ_API RzAnal *rz_anal_free(RzAnal *r); +RZ_API void rz_anal_set_user_ptr(RzAnal *anal, void *user); +RZ_API void rz_anal_plugin_free (RzAnalPlugin *p); +RZ_API int rz_anal_add(RzAnal *anal, RzAnalPlugin *foo); +RZ_API int rz_anal_archinfo(RzAnal *anal, int query); +RZ_API bool rz_anal_use(RzAnal *anal, const char *name); +RZ_API bool rz_anal_set_reg_profile(RzAnal *anal); +RZ_API char *rz_anal_get_reg_profile(RzAnal *anal); +RZ_API ut64 rz_anal_get_bbaddr(RzAnal *anal, ut64 addr); +RZ_API bool rz_anal_set_bits(RzAnal *anal, int bits); +RZ_API bool rz_anal_set_os(RzAnal *anal, const char *os); +RZ_API void rz_anal_set_cpu(RzAnal *anal, const char *cpu); +RZ_API int rz_anal_set_big_endian(RzAnal *anal, int boolean); +RZ_API ut8 *rz_anal_mask(RzAnal *anal, int size, const ut8 *data, ut64 at); +RZ_API void rz_anal_trace_bb(RzAnal *anal, ut64 addr); +RZ_API const char *rz_anal_fcntype_tostring(int type); +RZ_API int rz_anal_fcn_bb (RzAnal *anal, RzAnalFunction *fcn, ut64 addr, int depth); +RZ_API void rz_anal_bind(RzAnal *b, RzAnalBind *bnd); +RZ_API bool rz_anal_set_triplet(RzAnal *anal, const char *os, const char *arch, int bits); +RZ_API void rz_anal_add_import(RzAnal *anal, const char *imp); +RZ_API void rz_anal_remove_import(RzAnal *anal, const char *imp); +RZ_API void rz_anal_purge_imports(RzAnal *anal); + +/* bb.c */ +RZ_API RzAnalBlock *rz_anal_bb_from_offset(RzAnal *anal, ut64 off); +RZ_API bool rz_anal_bb_set_offset(RzAnalBlock *bb, int i, ut16 v); +RZ_API ut16 rz_anal_bb_offset_inst(RzAnalBlock *bb, int i); +RZ_API ut64 rz_anal_bb_opaddr_i(RzAnalBlock *bb, int i); +RZ_API ut64 rz_anal_bb_opaddr_at(RzAnalBlock *bb, ut64 addr); +RZ_API ut64 rz_anal_bb_size_i(RzAnalBlock *bb, int i); + +/* op.c */ +RZ_API const char *rz_anal_stackop_tostring(int s); +RZ_API RzAnalOp *rz_anal_op_new(void); +RZ_API void rz_anal_op_free(void *op); +RZ_API void rz_anal_op_init(RzAnalOp *op); +RZ_API bool rz_anal_op_fini(RzAnalOp *op); +RZ_API int rz_anal_op_reg_delta(RzAnal *anal, ut64 addr, const char *name); +RZ_API bool rz_anal_op_is_eob(RzAnalOp *op); +RZ_API RzList *rz_anal_op_list_new(void); +RZ_API int rz_anal_op(RzAnal *anal, RzAnalOp *op, ut64 addr, const ut8 *data, int len, RzAnalOpMask mask); +RZ_API RzAnalOp *rz_anal_op_hexstr(RzAnal *anal, ut64 addr, const char *hexstr); +RZ_API char *rz_anal_op_to_string(RzAnal *anal, RzAnalOp *op); + +RZ_API RzAnalEsil *rz_anal_esil_new(int stacksize, int iotrap, unsigned int addrsize); +RZ_API bool rz_anal_esil_set_pc(RzAnalEsil *esil, ut64 addr); +RZ_API bool rz_anal_esil_setup(RzAnalEsil *esil, RzAnal *anal, int romem, int stats, int nonull); +RZ_API void rz_anal_esil_free(RzAnalEsil *esil); +RZ_API bool rz_anal_esil_runword(RzAnalEsil *esil, const char *word); +RZ_API bool rz_anal_esil_parse(RzAnalEsil *esil, const char *str); +RZ_API bool rz_anal_esil_dumpstack(RzAnalEsil *esil); +RZ_API int rz_anal_esil_mem_read(RzAnalEsil *esil, ut64 addr, ut8 *buf, int len); +RZ_API int rz_anal_esil_mem_write(RzAnalEsil *esil, ut64 addr, const ut8 *buf, int len); +RZ_API int rz_anal_esil_reg_read(RzAnalEsil *esil, const char *regname, ut64 *num, int *size); +RZ_API int rz_anal_esil_reg_write(RzAnalEsil *esil, const char *dst, ut64 num); +RZ_API bool rz_anal_esil_pushnum(RzAnalEsil *esil, ut64 num); +RZ_API bool rz_anal_esil_push(RzAnalEsil *esil, const char *str); +RZ_API char *rz_anal_esil_pop(RzAnalEsil *esil); +RZ_API bool rz_anal_esil_set_op(RzAnalEsil *esil, const char *op, RzAnalEsilOpCb code, ut32 push, ut32 pop, ut32 type); +RZ_API void rz_anal_esil_stack_free(RzAnalEsil *esil); +RZ_API int rz_anal_esil_get_parm_type(RzAnalEsil *esil, const char *str); +RZ_API int rz_anal_esil_get_parm(RzAnalEsil *esil, const char *str, ut64 *num); +RZ_API int rz_anal_esil_condition(RzAnalEsil *esil, const char *str); + +// esil_interrupt.c +RZ_API void rz_anal_esil_interrupts_init(RzAnalEsil *esil); +RZ_API RzAnalEsilInterrupt *rz_anal_esil_interrupt_new(RzAnalEsil *esil, ut32 src_id, RzAnalEsilInterruptHandler *ih); +RZ_API void rz_anal_esil_interrupt_free(RzAnalEsil *esil, RzAnalEsilInterrupt *intr); +RZ_API bool rz_anal_esil_set_interrupt(RzAnalEsil *esil, RzAnalEsilInterrupt *intr); +RZ_API int rz_anal_esil_fire_interrupt(RzAnalEsil *esil, ut32 intr_num); +RZ_API bool rz_anal_esil_load_interrupts(RzAnalEsil *esil, RzAnalEsilInterruptHandler **handlers, ut32 src_id); +RZ_API bool rz_anal_esil_load_interrupts_from_lib(RzAnalEsil *esil, const char *path); +RZ_API void rz_anal_esil_interrupts_fini(RzAnalEsil *esil); + +RZ_API void rz_anal_esil_mem_ro(RzAnalEsil *esil, int mem_readonly); +RZ_API void rz_anal_esil_stats(RzAnalEsil *esil, int enable); + +/* trace */ +RZ_API RzAnalEsilTrace *rz_anal_esil_trace_new(RzAnalEsil *esil); +RZ_API void rz_anal_esil_trace_free(RzAnalEsilTrace *trace); +RZ_API void rz_anal_esil_trace_op(RzAnalEsil *esil, RzAnalOp *op); +RZ_API void rz_anal_esil_trace_list(RzAnalEsil *esil); +RZ_API void rz_anal_esil_trace_show(RzAnalEsil *esil, int idx); +RZ_API void rz_anal_esil_trace_restore(RzAnalEsil *esil, int idx); + +/* pin */ +RZ_API void rz_anal_pin_init(RzAnal *a); +RZ_API void rz_anal_pin_fini(RzAnal *a); +RZ_API void rz_anal_pin(RzAnal *a, ut64 addr, const char *name); +RZ_API void rz_anal_pin_unset(RzAnal *a, ut64 addr); +RZ_API const char *rz_anal_pin_call(RzAnal *a, ut64 addr); +RZ_API void rz_anal_pin_list(RzAnal *a); + +/* fcn.c */ +RZ_API ut32 rz_anal_function_cost(RzAnalFunction *fcn); +RZ_API int rz_anal_function_count_edges(const RzAnalFunction *fcn, R_NULLABLE int *ebbs); + +// Use rz_anal_get_functions_in¿() instead +R_DEPRECATE RZ_API RzAnalFunction *rz_anal_get_fcn_in(RzAnal *anal, ut64 addr, int type); +R_DEPRECATE RZ_API RzAnalFunction *rz_anal_get_fcn_in_bounds(RzAnal *anal, ut64 addr, int type); + +RZ_API RzAnalFunction *rz_anal_get_function_byname(RzAnal *anal, const char *name); + +RZ_API int rz_anal_fcn(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, ut64 len, int reftype); +RZ_API int rz_anal_fcn_del(RzAnal *anal, ut64 addr); +RZ_API int rz_anal_fcn_del_locs(RzAnal *anal, ut64 addr); +RZ_API bool rz_anal_fcn_add_bb(RzAnal *anal, RzAnalFunction *fcn, + ut64 addr, ut64 size, + ut64 jump, ut64 fail, R_BORROW RzAnalDiff *diff); +RZ_API bool rz_anal_check_fcn(RzAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 low, ut64 high); +RZ_API void rz_anal_fcn_invalidate_read_ahead_cache(void); + +RZ_API void rz_anal_function_check_bp_use(RzAnalFunction *fcn); + + +#define R_ANAL_FCN_VARKIND_LOCAL 'v' + + +RZ_API int rz_anal_fcn_var_del_byindex (RzAnal *a, ut64 fna, const char kind, int scope, ut32 idx); +/* args */ +RZ_API int rz_anal_var_count(RzAnal *a, RzAnalFunction *fcn, int kind, int type); + +/* vars // globals. not here */ +RZ_API bool rz_anal_var_display(RzAnal *anal, RzAnalVar *var); + +RZ_API int rz_anal_function_complexity(RzAnalFunction *fcn); +RZ_API int rz_anal_function_loops(RzAnalFunction *fcn); +RZ_API void rz_anal_trim_jmprefs(RzAnal *anal, RzAnalFunction *fcn); +RZ_API void rz_anal_del_jmprefs(RzAnal *anal, RzAnalFunction *fcn); +RZ_API char *rz_anal_function_get_json(RzAnalFunction *function); +RZ_API RzAnalFunction *rz_anal_fcn_next(RzAnal *anal, ut64 addr); +RZ_API char *rz_anal_function_get_signature(RzAnalFunction *function); +RZ_API int rz_anal_str_to_fcn(RzAnal *a, RzAnalFunction *f, const char *_str); +RZ_API int rz_anal_fcn_count (RzAnal *a, ut64 from, ut64 to); +RZ_API RzAnalBlock *rz_anal_fcn_bbget_in(const RzAnal *anal, RzAnalFunction *fcn, ut64 addr); +RZ_API RzAnalBlock *rz_anal_fcn_bbget_at(RzAnal *anal, RzAnalFunction *fcn, ut64 addr); +RZ_API bool rz_anal_fcn_bbadd(RzAnalFunction *fcn, RzAnalBlock *bb); +RZ_API int rz_anal_function_resize(RzAnalFunction *fcn, int newsize); +RZ_API bool rz_anal_function_purity(RzAnalFunction *fcn); + +typedef bool (* RzAnalRefCmp)(RzAnalRef *ref, void *data); +RZ_API RzList *rz_anal_ref_list_new(void); +RZ_API ut64 rz_anal_xrefs_count(RzAnal *anal); +RZ_API const char *rz_anal_xrefs_type_tostring(RzAnalRefType type); +RZ_API RzAnalRefType rz_anal_xrefs_type(char ch); +RZ_API RzList *rz_anal_xrefs_get(RzAnal *anal, ut64 to); +RZ_API RzList *rz_anal_refs_get(RzAnal *anal, ut64 to); +RZ_API RzList *rz_anal_xrefs_get_from(RzAnal *anal, ut64 from); +RZ_API void rz_anal_xrefs_list(RzAnal *anal, int rad); +RZ_API RzList *rz_anal_function_get_refs(RzAnalFunction *fcn); +RZ_API RzList *rz_anal_function_get_xrefs(RzAnalFunction *fcn); +RZ_API int rz_anal_xrefs_from(RzAnal *anal, RzList *list, const char *kind, const RzAnalRefType type, ut64 addr); +RZ_API int rz_anal_xrefs_set(RzAnal *anal, ut64 from, ut64 to, const RzAnalRefType type); +RZ_API int rz_anal_xrefs_deln(RzAnal *anal, ut64 from, ut64 to, const RzAnalRefType type); +RZ_API int rz_anal_xref_del(RzAnal *anal, ut64 at, ut64 addr); + +RZ_API RzList *rz_anal_get_fcns(RzAnal *anal); + +/* type.c */ +RZ_API void rz_anal_remove_parsed_type(RzAnal *anal, const char *name); +RZ_API void rz_anal_save_parsed_type(RzAnal *anal, const char *parsed); + +/* var.c */ +RZ_API R_OWN char *rz_anal_function_autoname_var(RzAnalFunction *fcn, char kind, const char *pfx, int ptr); +RZ_API R_BORROW RzAnalVar *rz_anal_function_set_var(RzAnalFunction *fcn, int delta, char kind, R_NULLABLE const char *type, int size, bool isarg, R_NONNULL const char *name); +RZ_API R_BORROW RzAnalVar *rz_anal_function_get_var(RzAnalFunction *fcn, char kind, int delta); +RZ_API R_BORROW RzAnalVar *rz_anal_function_get_var_byname(RzAnalFunction *fcn, const char *name); +RZ_API void rz_anal_function_delete_vars_by_kind(RzAnalFunction *fcn, RzAnalVarKind kind); +RZ_API void rz_anal_function_delete_all_vars(RzAnalFunction *fcn); +RZ_API void rz_anal_function_delete_var(RzAnalFunction *fcn, RzAnalVar *var); +RZ_API bool rz_anal_function_rebase_vars(RzAnal *a, RzAnalFunction *fcn); +RZ_API st64 rz_anal_function_get_var_stackptr_at(RzAnalFunction *fcn, st64 delta, ut64 addr); +RZ_API const char *rz_anal_function_get_var_reg_at(RzAnalFunction *fcn, st64 delta, ut64 addr); +RZ_API R_BORROW RPVector *rz_anal_function_get_vars_used_at(RzAnalFunction *fcn, ut64 op_addr); + +// There could be multiple vars used in multiple functions. Use rz_anal_get_functions_in()+rz_anal_function_get_vars_used_at() instead. +RZ_API R_DEPRECATE RzAnalVar *rz_anal_get_used_function_var(RzAnal *anal, ut64 addr); + +RZ_API bool rz_anal_var_rename(RzAnalVar *var, const char *new_name, bool verbose); +RZ_API void rz_anal_var_set_type(RzAnalVar *var, const char *type); +RZ_API void rz_anal_var_delete(RzAnalVar *var); +RZ_API ut64 rz_anal_var_addr(RzAnalVar *var); +RZ_API void rz_anal_var_set_access(RzAnalVar *var, const char *reg, ut64 access_addr, int access_type, st64 stackptr); +RZ_API void rz_anal_var_remove_access_at(RzAnalVar *var, ut64 address); +RZ_API void rz_anal_var_clear_accesses(RzAnalVar *var); +RZ_API void rz_anal_var_add_constraint(RzAnalVar *var, R_BORROW RzAnalVarConstraint *constraint); +RZ_API char *rz_anal_var_get_constraints_readable(RzAnalVar *var); + +// Get the access to var at exactly addr if there is one +RZ_API RzAnalVarAccess *rz_anal_var_get_access_at(RzAnalVar *var, ut64 addr); + +RZ_API int rz_anal_var_get_argnum(RzAnalVar *var); + +RZ_API void rz_anal_extract_vars(RzAnal *anal, RzAnalFunction *fcn, RzAnalOp *op); +RZ_API void rz_anal_extract_rarg(RzAnal *anal, RzAnalOp *op, RzAnalFunction *fcn, int *reg_set, int *count); + +// Get the variable that var is written to at one of its accesses +// Useful for cases where a register-based argument is written away into a stack variable, +// so if var is the reg arg then this will return the stack var. +RZ_API RzAnalVar *rz_anal_var_get_dst_var(RzAnalVar *var); + +typedef struct rz_anal_fcn_vars_cache { + RzList *bvars; + RzList *rvars; + RzList *svars; +} RzAnalFcnVarsCache; +RZ_API void rz_anal_fcn_vars_cache_init(RzAnal *anal, RzAnalFcnVarsCache *cache, RzAnalFunction *fcn); +RZ_API void rz_anal_fcn_vars_cache_fini(RzAnalFcnVarsCache *cache); + +RZ_API char *rz_anal_fcn_format_sig(R_NONNULL RzAnal *anal, R_NONNULL RzAnalFunction *fcn, R_NULLABLE char *fcn_name, + R_NULLABLE RzAnalFcnVarsCache *reuse_cache, R_NULLABLE const char *fcn_name_pre, R_NULLABLE const char *fcn_name_post); + + +/* project */ +RZ_API bool rz_anal_xrefs_init (RzAnal *anal); + +#define R_ANAL_THRESHOLDFCN 0.7F +#define R_ANAL_THRESHOLDBB 0.7F + +/* diff.c */ +RZ_API RzAnalDiff *rz_anal_diff_new(void); +RZ_API void rz_anal_diff_setup(RzAnal *anal, int doops, double thbb, double thfcn); +RZ_API void rz_anal_diff_setup_i(RzAnal *anal, int doops, int thbb, int thfcn); +RZ_API void* rz_anal_diff_free(RzAnalDiff *diff); +RZ_API int rz_anal_diff_fingerprint_bb(RzAnal *anal, RzAnalBlock *bb); +RZ_API size_t rz_anal_diff_fingerprint_fcn(RzAnal *anal, RzAnalFunction *fcn); +RZ_API bool rz_anal_diff_bb(RzAnal *anal, RzAnalFunction *fcn, RzAnalFunction *fcn2); +RZ_API int rz_anal_diff_fcn(RzAnal *anal, RzList *fcns, RzList *fcns2); +RZ_API int rz_anal_diff_eval(RzAnal *anal); + +/* value.c */ +RZ_API RzAnalValue *rz_anal_value_new(void); +RZ_API RzAnalValue *rz_anal_value_copy (RzAnalValue *ov); +RZ_API RzAnalValue *rz_anal_value_new_from_string(const char *str); +RZ_API st64 rz_anal_value_eval(RzAnalValue *value); +RZ_API char *rz_anal_value_to_string (RzAnalValue *value); +RZ_API ut64 rz_anal_value_to_ut64(RzAnal *anal, RzAnalValue *val); +RZ_API int rz_anal_value_set_ut64(RzAnal *anal, RzAnalValue *val, ut64 num); +RZ_API void rz_anal_value_free(RzAnalValue *value); + +RZ_API RzAnalCond *rz_anal_cond_new(void); +RZ_API RzAnalCond *rz_anal_cond_new_from_op(RzAnalOp *op); +RZ_API void rz_anal_cond_fini(RzAnalCond *c); +RZ_API void rz_anal_cond_free(RzAnalCond *c); +RZ_API char *rz_anal_cond_to_string(RzAnalCond *cond); +RZ_API int rz_anal_cond_eval(RzAnal *anal, RzAnalCond *cond); +RZ_API RzAnalCond *rz_anal_cond_new_from_string(const char *str); +RZ_API const char *rz_anal_cond_tostring(int cc); + +/* jmptbl */ +RZ_API bool rz_anal_jmptbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, ut64 jmpaddr, ut64 table, ut64 tablesize, ut64 default_addr); + +// TODO: should be renamed +RZ_API bool try_get_delta_jmptbl_info(RzAnal *anal, RzAnalFunction *fcn, ut64 jmp_addr, ut64 lea_addr, ut64 *table_size, ut64 *default_case); +RZ_API bool try_walkthrough_jmptbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0); +RZ_API bool try_walkthrough_casetbl(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 casetbl_loc, ut64 jmptbl_off, ut64 sz, ut64 jmptbl_size, ut64 default_case, bool ret0); +RZ_API bool try_get_jmptbl_info(RzAnal *anal, RzAnalFunction *fcn, ut64 addr, RzAnalBlock *my_bb, ut64 *table_size, ut64 *default_case); +RZ_API int walkthrough_arm_jmptbl_style(RzAnal *anal, RzAnalFunction *fcn, RzAnalBlock *block, int depth, ut64 ip, ut64 jmptbl_loc, ut64 sz, ut64 jmptbl_size, ut64 default_case, int ret0); + +/* reflines.c */ +RZ_API RzList* /**/ rz_anal_reflines_get(RzAnal *anal, + ut64 addr, const ut8 *buf, ut64 len, int nlines, int linesout, int linescall); +RZ_API int rz_anal_reflines_middle(RzAnal *anal, RzList *list, ut64 addr, int len); +RZ_API RzAnalRefStr *rz_anal_reflines_str(void *core, ut64 addr, int opts); +RZ_API void rz_anal_reflines_str_free(RzAnalRefStr *refstr); +/* TODO move to rz_core */ +RZ_API void rz_anal_var_list_show(RzAnal *anal, RzAnalFunction *fcn, int kind, int mode, PJ* pj); +RZ_API RzList *rz_anal_var_list(RzAnal *anal, RzAnalFunction *fcn, int kind); +RZ_API R_DEPRECATE RzList/**/ *rz_anal_var_all_list(RzAnal *anal, RzAnalFunction *fcn); +RZ_API R_DEPRECATE RzList/**/ *rz_anal_function_get_var_fields(RzAnalFunction *fcn, int kind); + +// calling conventions API +RZ_API bool rz_anal_cc_exist(RzAnal *anal, const char *convention); +RZ_API void rz_anal_cc_del(RzAnal *anal, const char *name); +RZ_API bool rz_anal_cc_set(RzAnal *anal, const char *expr); +RZ_API char *rz_anal_cc_get(RzAnal *anal, const char *name); +RZ_API const char *rz_anal_cc_arg(RzAnal *anal, const char *convention, int n); +RZ_API const char *rz_anal_cc_self(RzAnal *anal, const char *convention); +RZ_API void rz_anal_cc_set_self(RzAnal *anal, const char *convention, const char *self); +RZ_API const char *rz_anal_cc_error(RzAnal *anal, const char *convention); +RZ_API void rz_anal_cc_set_error(RzAnal *anal, const char *convention, const char *error); +RZ_API int rz_anal_cc_max_arg(RzAnal *anal, const char *cc); +RZ_API const char *rz_anal_cc_ret(RzAnal *anal, const char *convention); +RZ_API const char *rz_anal_cc_default(RzAnal *anal); +RZ_API const char *rz_anal_cc_func(RzAnal *anal, const char *func_name); +RZ_API bool rz_anal_noreturn_at(RzAnal *anal, ut64 addr); + +typedef struct rz_anal_data_t { + ut64 addr; + int type; + ut64 ptr; + char *str; + int len; + ut8 *buf; + ut8 sbuf[8]; +} RzAnalData; + +RZ_API RzAnalData *rz_anal_data (RzAnal *anal, ut64 addr, const ut8 *buf, int size, int wordsize); +RZ_API const char *rz_anal_data_kind (RzAnal *anal, ut64 addr, const ut8 *buf, int len); +RZ_API RzAnalData *rz_anal_data_new_string (ut64 addr, const char *p, int size, int wide); +RZ_API RzAnalData *rz_anal_data_new (ut64 addr, int type, ut64 n, const ut8 *buf, int len); +RZ_API void rz_anal_data_free (RzAnalData *d); +#include +RZ_API char *rz_anal_data_to_string(RzAnalData *d, RzConsPrintablePalette *pal); + +/* meta + * + * Meta uses Condret's Klemmbaustein Priciple, i.e. intervals are defined inclusive/inclusive. + * A meta item from 0x42 to 0x42 has a size of 1. Items with size 0 do not exist. + * Meta items are allowed to overlap and the internal data structure allows for multiple meta items + * starting at the same address. + * Meta items are saved in an RIntervalTree. To access the interval of an item, use the members of RIntervalNode. + */ + +static inline ut64 rz_meta_item_size(ut64 start, ut64 end) { + // meta items use inclusive/inclusive intervals + return end - start + 1; +} + +static inline ut64 rz_meta_node_size(RIntervalNode *node) { + return rz_meta_item_size (node->start, node->end); +} + +// Set a meta item at addr with the given contents in the current space. +// If there already exists an item with this type and space at addr (regardless of its size) it will be overwritten. +RZ_API bool rz_meta_set(RzAnal *a, RzAnalMetaType type, ut64 addr, ut64 size, const char *str); + +// Same as rz_meta_set() but also sets the subtype. +RZ_API bool rz_meta_set_with_subtype(RzAnal *m, RzAnalMetaType type, int subtype, ut64 addr, ut64 size, const char *str); + +// Delete all meta items in the current space that intersect with the given interval. +// If size == UT64_MAX, everything in the current space will be deleted. +RZ_API void rz_meta_del(RzAnal *a, RzAnalMetaType type, ut64 addr, ut64 size); + +// Same as rz_meta_set() with a size of 1. +RZ_API bool rz_meta_set_string(RzAnal *a, RzAnalMetaType type, ut64 addr, const char *s); + +// Convenience function to get the str content of the item at addr with given type in the current space. +RZ_API const char *rz_meta_get_string(RzAnal *a, RzAnalMetaType type, ut64 addr); + +// Convenience function to add an R_META_TYPE_DATA item at the given addr in the current space. +RZ_API void rz_meta_set_data_at(RzAnal *a, ut64 addr, ut64 wordsz); + +// Returns the item with given type that starts at addr in the current space or NULL. The size of this item optionally returned through size. +RZ_API RzAnalMetaItem *rz_meta_get_at(RzAnal *a, ut64 addr, RzAnalMetaType type, R_OUT R_NULLABLE ut64 *size); + +// Returns the node for one meta item with the given type that contains addr in the current space or NULL. +// To get all the nodes, use rz_meta_get_all_in(). +RZ_API RIntervalNode *rz_meta_get_in(RzAnal *a, ut64 addr, RzAnalMetaType type); + +// Returns all nodes for items starting at the given address in the current space. +RZ_API RPVector/* *>*/ *rz_meta_get_all_at(RzAnal *a, ut64 at); + +// Returns all nodes for items with the given type containing the given address in the current space. +RZ_API RPVector/* *>*/ *rz_meta_get_all_in(RzAnal *a, ut64 at, RzAnalMetaType type); + +// Returns all nodes for items with the given type intersecting the given interval in the current space. +RZ_API RPVector/* *>*/ *rz_meta_get_all_intersect(RzAnal *a, ut64 start, ut64 size, RzAnalMetaType type); + +// Delete all meta items in the given space +RZ_API void rz_meta_space_unset_for(RzAnal *a, const RSpace *space); + +// Returns the number of meta items in the given space +RZ_API int rz_meta_space_count_for(RzAnal *a, const RSpace *space); + +// Shift all meta items by the given delta, for rebasing between different memory layouts. +RZ_API void rz_meta_rebase(RzAnal *anal, ut64 diff); + +// Calculate the total size covered by meta items of the given type. +RZ_API ut64 rz_meta_get_size(RzAnal *a, RzAnalMetaType type); + +RZ_API const char *rz_meta_type_to_string(int type); +RZ_API void rz_meta_print(RzAnal *a, RzAnalMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full); +RZ_API void rz_meta_print_list_all(RzAnal *a, int type, int rad); +RZ_API void rz_meta_print_list_at(RzAnal *a, ut64 addr, int rad); +RZ_API void rz_meta_print_list_in_function(RzAnal *a, int type, int rad, ut64 addr); + +/* hints */ + +RZ_API void rz_anal_hint_del(RzAnal *anal, ut64 addr, ut64 size); // delete all hints that are contained within the given range, if size > 1, this operation is quite heavy! +RZ_API void rz_anal_hint_clear (RzAnal *a); +RZ_API void rz_anal_hint_free (RzAnalHint *h); +RZ_API void rz_anal_hint_set_syntax (RzAnal *a, ut64 addr, const char *syn); +RZ_API void rz_anal_hint_set_type(RzAnal *a, ut64 addr, int type); +RZ_API void rz_anal_hint_set_jump(RzAnal *a, ut64 addr, ut64 jump); +RZ_API void rz_anal_hint_set_fail(RzAnal *a, ut64 addr, ut64 fail); +RZ_API void rz_anal_hint_set_newbits(RzAnal *a, ut64 addr, int bits); +RZ_API void rz_anal_hint_set_nword(RzAnal *a, ut64 addr, int nword); +RZ_API void rz_anal_hint_set_offset(RzAnal *a, ut64 addr, const char *typeoff); +RZ_API void rz_anal_hint_set_immbase(RzAnal *a, ut64 addr, int base); +RZ_API void rz_anal_hint_set_size(RzAnal *a, ut64 addr, ut64 size); +RZ_API void rz_anal_hint_set_opcode(RzAnal *a, ut64 addr, const char *str); +RZ_API void rz_anal_hint_set_esil(RzAnal *a, ut64 addr, const char *str); +RZ_API void rz_anal_hint_set_pointer(RzAnal *a, ut64 addr, ut64 ptr); +RZ_API void rz_anal_hint_set_ret(RzAnal *a, ut64 addr, ut64 val); +RZ_API void rz_anal_hint_set_high(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_set_stackframe(RzAnal *a, ut64 addr, ut64 size); +RZ_API void rz_anal_hint_set_val(RzAnal *a, ut64 addr, ut64 v); +RZ_API void rz_anal_hint_set_arch(RzAnal *a, ut64 addr, R_NULLABLE const char *arch); // arch == NULL => use global default +RZ_API void rz_anal_hint_set_bits(RzAnal *a, ut64 addr, int bits); // bits == NULL => use global default +RZ_API void rz_anal_hint_unset_val (RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_high(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_immbase(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_nword(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_size(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_type(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_esil(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_opcode(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_syntax(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_pointer(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_ret(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_offset(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_jump(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_fail(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_newbits(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_stackframe(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_arch(RzAnal *a, ut64 addr); +RZ_API void rz_anal_hint_unset_bits(RzAnal *a, ut64 addr); +RZ_API R_NULLABLE const RzVector/**/ *rz_anal_addr_hints_at(RzAnal *anal, ut64 addr); +typedef bool (*RzAnalAddrHintRecordsCb)(ut64 addr, const RzVector/**/ *records, void *user); +RZ_API void rz_anal_addr_hints_foreach(RzAnal *anal, RzAnalAddrHintRecordsCb cb, void *user); +typedef bool (*RzAnalArchHintCb)(ut64 addr, R_NULLABLE const char *arch, void *user); +RZ_API void rz_anal_arch_hints_foreach(RzAnal *anal, RzAnalArchHintCb cb, void *user); +typedef bool (*RzAnalBitsHintCb)(ut64 addr, int bits, void *user); +RZ_API void rz_anal_bits_hints_foreach(RzAnal *anal, RzAnalBitsHintCb cb, void *user); + +// get the hint-specified arch value to be considered at addr +// hint_addr will optionally be set to the address where the hint that specifies this arch is placed or UT64_MAX +// if there is no hint affecting addr. +RZ_API R_NULLABLE R_BORROW const char *rz_anal_hint_arch_at(RzAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr); + +// get the hint-specified bits value to be considered at addr +// hint_addr will optionally be set to the address where the hint that specifies this arch is placed or UT64_MAX +// if there is no hint affecting addr. +RZ_API int rz_anal_hint_bits_at(RzAnal *anal, ut64 addr, R_NULLABLE ut64 *hint_addr); + +RZ_API RzAnalHint *rz_anal_hint_get(RzAnal *anal, ut64 addr); // accumulate all available hints affecting the given address + +/* switch.c APIs */ +RZ_API RzAnalSwitchOp *rz_anal_switch_op_new(ut64 addr, ut64 min_val, ut64 max_val, ut64 def_val); +RZ_API void rz_anal_switch_op_free(RzAnalSwitchOp * swop); +RZ_API RzAnalCaseOp* rz_anal_switch_op_add_case(RzAnalSwitchOp * swop, ut64 addr, ut64 value, ut64 jump); + +/* cycles.c */ +RZ_API RzAnalCycleFrame* rz_anal_cycle_frame_new (void); +RZ_API void rz_anal_cycle_frame_free (RzAnalCycleFrame *cf); + +/* labels */ +RZ_API ut64 rz_anal_function_get_label(RzAnalFunction *fcn, const char *name); +RZ_API const char *rz_anal_function_get_label_at(RzAnalFunction *fcn, ut64 addr); +RZ_API bool rz_anal_function_set_label(RzAnalFunction *fcn, const char *name, ut64 addr); +RZ_API bool rz_anal_function_delete_label(RzAnalFunction *fcn, const char *name); +RZ_API bool rz_anal_function_delete_label_at(RzAnalFunction *fcn, ut64 addr); + +/* limits */ +RZ_API void rz_anal_set_limits(RzAnal *anal, ut64 from, ut64 to); +RZ_API void rz_anal_unset_limits(RzAnal *anal); + +/* ESIL to REIL */ +RZ_API int rz_anal_esil_to_reil_setup (RzAnalEsil *esil, RzAnal *anal, int romem, int stats); + +/* no-return stuff */ +RZ_API void rz_anal_noreturn_list(RzAnal *anal, int mode); +RZ_API bool rz_anal_noreturn_add(RzAnal *anal, const char *name, ut64 addr); +RZ_API bool rz_anal_noreturn_drop(RzAnal *anal, const char *expr); +RZ_API bool rz_anal_noreturn_at_addr(RzAnal *anal, ut64 addr); + +/* zign spaces */ +RZ_API int rz_sign_space_count_for(RzAnal *a, const RSpace *space); +RZ_API void rz_sign_space_unset_for(RzAnal *a, const RSpace *space); +RZ_API void rz_sign_space_rename_for(RzAnal *a, const RSpace *space, const char *oname, const char *nname); + +/* vtables */ +typedef struct { + RzAnal *anal; + RzAnalCPPABI abi; + ut8 word_size; + bool (*read_addr) (RzAnal *anal, ut64 addr, ut64 *buf); +} RVTableContext; + +typedef struct vtable_info_t { + ut64 saddr; //starting address + RzVector methods; +} RVTableInfo; + +typedef struct vtable_method_info_t { + ut64 addr; // addr of the function + ut64 vtable_offset; // offset inside the vtable +} RVTableMethodInfo; + +RZ_API void rz_anal_vtable_info_free(RVTableInfo *vtable); +RZ_API ut64 rz_anal_vtable_info_get_size(RVTableContext *context, RVTableInfo *vtable); +RZ_API bool rz_anal_vtable_begin(RzAnal *anal, RVTableContext *context); +RZ_API RVTableInfo *rz_anal_vtable_parse_at(RVTableContext *context, ut64 addr); +RZ_API RzList *rz_anal_vtable_search(RVTableContext *context); +RZ_API void rz_anal_list_vtables(RzAnal *anal, int rad); + +/* rtti */ +RZ_API char *rz_anal_rtti_msvc_demangle_class_name(RVTableContext *context, const char *name); +RZ_API void rz_anal_rtti_msvc_print_complete_object_locator(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_msvc_print_type_descriptor(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_msvc_print_class_hierarchy_descriptor(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_msvc_print_base_class_descriptor(RVTableContext *context, ut64 addr, int mode); +RZ_API bool rz_anal_rtti_msvc_print_at_vtable(RVTableContext *context, ut64 addr, int mode, bool strict); +RZ_API void rz_anal_rtti_msvc_recover_all(RVTableContext *vt_context, RzList *vtables); + +RZ_API char *rz_anal_rtti_itanium_demangle_class_name(RVTableContext *context, const char *name); +RZ_API void rz_anal_rtti_itanium_print_class_type_info(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_itanium_print_si_class_type_info(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_itanium_print_vmi_class_type_info(RVTableContext *context, ut64 addr, int mode); +RZ_API bool rz_anal_rtti_itanium_print_at_vtable(RVTableContext *context, ut64 addr, int mode); +RZ_API void rz_anal_rtti_itanium_recover_all(RVTableContext *vt_context, RzList *vtables); + +RZ_API char *rz_anal_rtti_demangle_class_name(RzAnal *anal, const char *name); +RZ_API void rz_anal_rtti_print_at_vtable(RzAnal *anal, ut64 addr, int mode); +RZ_API void rz_anal_rtti_print_all(RzAnal *anal, int mode); +RZ_API void rz_anal_rtti_recover_all(RzAnal *anal); + +RZ_API void rz_anal_colorize_bb(RzAnal *anal, ut64 addr, ut32 color); + +RZ_API RzList *rz_anal_preludes(RzAnal *anal); +RZ_API bool rz_anal_is_prelude(RzAnal *anal, const ut8 *data, int len); + +/* classes */ +typedef struct rz_anal_method_t { + char *name; + ut64 addr; + st64 vtable_offset; // >= 0 if method is virtual, else -1 +} RzAnalMethod; + +typedef struct rz_anal_base_class_t { + char *id; // id to identify the class attr + ut64 offset; // offset of the base class inside the derived class + char *class_name; +} RzAnalBaseClass; + +typedef struct rz_anal_vtable_t { + char *id; // id to identify the class attr + ut64 offset; // offset inside the class + ut64 addr; // where the content of the vtable is + ut64 size; // size (in bytes) of the vtable +} RzAnalVTable; + +typedef enum { + R_ANAL_CLASS_ERR_SUCCESS = 0, + R_ANAL_CLASS_ERR_CLASH, + R_ANAL_CLASS_ERR_NONEXISTENT_ATTR, + R_ANAL_CLASS_ERR_NONEXISTENT_CLASS, + R_ANAL_CLASS_ERR_OTHER +} RzAnalClassErr; + +RZ_API void rz_anal_class_create(RzAnal *anal, const char *name); +RZ_API void rz_anal_class_delete(RzAnal *anal, const char *name); +RZ_API bool rz_anal_class_exists(RzAnal *anal, const char *name); +RZ_API SdbList *rz_anal_class_get_all(RzAnal *anal, bool sorted); +RZ_API void rz_anal_class_foreach(RzAnal *anal, SdbForeachCallback cb, void *user); +RZ_API RzAnalClassErr rz_anal_class_rename(RzAnal *anal, const char *old_name, const char *new_name); + +RZ_API void rz_anal_class_method_fini(RzAnalMethod *meth); +RZ_API RzAnalClassErr rz_anal_class_method_get(RzAnal *anal, const char *class_name, const char *meth_name, RzAnalMethod *meth); +RZ_API RzVector/**/ *rz_anal_class_method_get_all(RzAnal *anal, const char *class_name); +RZ_API RzAnalClassErr rz_anal_class_method_set(RzAnal *anal, const char *class_name, RzAnalMethod *meth); +RZ_API RzAnalClassErr rz_anal_class_method_rename(RzAnal *anal, const char *class_name, const char *old_meth_name, const char *new_meth_name); +RZ_API RzAnalClassErr rz_anal_class_method_delete(RzAnal *anal, const char *class_name, const char *meth_name); + +RZ_API void rz_anal_class_base_fini(RzAnalBaseClass *base); +RZ_API RzAnalClassErr rz_anal_class_base_get(RzAnal *anal, const char *class_name, const char *base_id, RzAnalBaseClass *base); +RZ_API RzVector/**/ *rz_anal_class_base_get_all(RzAnal *anal, const char *class_name); +RZ_API RzAnalClassErr rz_anal_class_base_set(RzAnal *anal, const char *class_name, RzAnalBaseClass *base); +RZ_API RzAnalClassErr rz_anal_class_base_delete(RzAnal *anal, const char *class_name, const char *base_id); + +RZ_API void rz_anal_class_vtable_fini(RzAnalVTable *vtable); +RZ_API RzAnalClassErr rz_anal_class_vtable_get(RzAnal *anal, const char *class_name, const char *vtable_id, RzAnalVTable *vtable); +RZ_API RzVector/**/ *rz_anal_class_vtable_get_all(RzAnal *anal, const char *class_name); +RZ_API RzAnalClassErr rz_anal_class_vtable_set(RzAnal *anal, const char *class_name, RzAnalVTable *vtable); +RZ_API RzAnalClassErr rz_anal_class_vtable_delete(RzAnal *anal, const char *class_name, const char *vtable_id); + +RZ_API void rz_anal_class_print(RzAnal *anal, const char *class_name, bool detailed); +RZ_API void rz_anal_class_json(RzAnal *anal, PJ *j, const char *class_name); +RZ_API void rz_anal_class_list(RzAnal *anal, int mode); +RZ_API void rz_anal_class_list_bases(RzAnal *anal, const char *class_name); +RZ_API void rz_anal_class_list_vtables(RzAnal *anal, const char *class_name); +RZ_API void rz_anal_class_list_vtable_offset_functions(RzAnal *anal, const char *class_name, ut64 offset); +RZ_API RGraph/**/ *rz_anal_class_get_inheritance_graph(RzAnal *anal); + +RZ_API RzAnalEsilCFG *rz_anal_esil_cfg_expr(RzAnalEsilCFG *cfg, RzAnal *anal, const ut64 off, char *expr); +RZ_API RzAnalEsilCFG *rz_anal_esil_cfg_op(RzAnalEsilCFG *cfg, RzAnal *anal, RzAnalOp *op); +RZ_API void rz_anal_esil_cfg_merge_blocks(RzAnalEsilCFG *cfg); +RZ_API void rz_anal_esil_cfg_free(RzAnalEsilCFG *cfg); + +RZ_API RzAnalEsilDFGNode *rz_anal_esil_dfg_node_new (RzAnalEsilDFG *edf, const char *c); +RZ_API RzAnalEsilDFG *rz_anal_esil_dfg_new(RzReg *regs); +RZ_API void rz_anal_esil_dfg_free(RzAnalEsilDFG *dfg); +RZ_API RzAnalEsilDFG *rz_anal_esil_dfg_expr(RzAnal *anal, RzAnalEsilDFG *dfg, const char *expr); +RZ_API RStrBuf *rz_anal_esil_dfg_filter(RzAnalEsilDFG *dfg, const char *reg); +RZ_API RStrBuf *rz_anal_esil_dfg_filter_expr(RzAnal *anal, const char *expr, const char *reg); +RZ_API RzList *rz_anal_types_from_fcn(RzAnal *anal, RzAnalFunction *fcn); + +RZ_API RzAnalBaseType *rz_anal_get_base_type(RzAnal *anal, const char *name); +RZ_API void rz_parse_pdb_types(const RzAnal *anal, const RPdb *pdb); +RZ_API void rz_anal_save_base_type(const RzAnal *anal, const RzAnalBaseType *type); +RZ_API void rz_anal_base_type_free(RzAnalBaseType *type); +RZ_API RzAnalBaseType *rz_anal_base_type_new(RzAnalBaseTypeKind kind); +RZ_API void rz_anal_dwarf_process_info(const RzAnal *anal, RzAnalDwarfContext *ctx); +RZ_API void rz_anal_dwarf_integrate_functions(RzAnal *anal, RzFlag *flags, Sdb *dwarf_sdb); +/* plugin pointers */ +extern RzAnalPlugin rz_anal_plugin_null; +extern RzAnalPlugin rz_anal_plugin_6502; +extern RzAnalPlugin rz_anal_plugin_6502_cs; +extern RzAnalPlugin rz_anal_plugin_8051; +extern RzAnalPlugin rz_anal_plugin_amd29k; +extern RzAnalPlugin rz_anal_plugin_arc; +extern RzAnalPlugin rz_anal_plugin_arm_cs; +extern RzAnalPlugin rz_anal_plugin_arm_gnu; +extern RzAnalPlugin rz_anal_plugin_avr; +extern RzAnalPlugin rz_anal_plugin_bf; +extern RzAnalPlugin rz_anal_plugin_chip8; +extern RzAnalPlugin rz_anal_plugin_cr16; +extern RzAnalPlugin rz_anal_plugin_cris; +extern RzAnalPlugin rz_anal_plugin_dalvik; +extern RzAnalPlugin rz_anal_plugin_ebc; +extern RzAnalPlugin rz_anal_plugin_gb; +extern RzAnalPlugin rz_anal_plugin_h8300; +extern RzAnalPlugin rz_anal_plugin_hexagon; +extern RzAnalPlugin rz_anal_plugin_i4004; +extern RzAnalPlugin rz_anal_plugin_i8080; +extern RzAnalPlugin rz_anal_plugin_java; +extern RzAnalPlugin rz_anal_plugin_m68k_cs; +extern RzAnalPlugin rz_anal_plugin_m680x_cs; +extern RzAnalPlugin rz_anal_plugin_malbolge; +extern RzAnalPlugin rz_anal_plugin_mcore; +extern RzAnalPlugin rz_anal_plugin_mips_cs; +extern RzAnalPlugin rz_anal_plugin_mips_gnu; +extern RzAnalPlugin rz_anal_plugin_msp430; +extern RzAnalPlugin rz_anal_plugin_nios2; +extern RzAnalPlugin rz_anal_plugin_or1k; +extern RzAnalPlugin rz_anal_plugin_pic; +extern RzAnalPlugin rz_anal_plugin_ppc_cs; +extern RzAnalPlugin rz_anal_plugin_ppc_gnu; +extern RzAnalPlugin rz_anal_plugin_propeller; +extern RzAnalPlugin rz_anal_plugin_riscv; +extern RzAnalPlugin rz_anal_plugin_riscv_cs; +extern RzAnalPlugin rz_anal_plugin_rsp; +extern RzAnalPlugin rz_anal_plugin_sh; +extern RzAnalPlugin rz_anal_plugin_snes; +extern RzAnalPlugin rz_anal_plugin_sparc_cs; +extern RzAnalPlugin rz_anal_plugin_sparc_gnu; +extern RzAnalPlugin rz_anal_plugin_sysz; +extern RzAnalPlugin rz_anal_plugin_tms320; +extern RzAnalPlugin rz_anal_plugin_tms320c64x; +extern RzAnalPlugin rz_anal_plugin_tricore; +extern RzAnalPlugin rz_anal_plugin_v810; +extern RzAnalPlugin rz_anal_plugin_v850; +extern RzAnalPlugin rz_anal_plugin_vax; +extern RzAnalPlugin rz_anal_plugin_wasm; +extern RzAnalPlugin rz_anal_plugin_ws; +extern RzAnalPlugin rz_anal_plugin_x86; +extern RzAnalPlugin rz_anal_plugin_x86_cs; +extern RzAnalPlugin rz_anal_plugin_x86_im; +extern RzAnalPlugin rz_anal_plugin_x86_simple; +extern RzAnalPlugin rz_anal_plugin_x86_udis; +extern RzAnalPlugin rz_anal_plugin_xap; +extern RzAnalPlugin rz_anal_plugin_xcore_cs; +extern RzAnalPlugin rz_anal_plugin_xtensa; +extern RzAnalPlugin rz_anal_plugin_z80; +extern RzAnalPlugin rz_anal_plugin_pyc; +#ifdef __cplusplus +} +#endif + +#endif +#endif diff --git a/librz/include/rz_asm.h b/librz/include/rz_asm.h new file mode 100644 index 0000000000..ceb665f229 --- /dev/null +++ b/librz/include/rz_asm.h @@ -0,0 +1,278 @@ +/* radare - LGPL - Copyright 2009-2020 - nibble, pancake */ + +#ifndef R2_ASM_H +#define R2_ASM_H + +#include +#include // only for binding, no hard dep required +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_asm); + +/* backward compatibility */ +#define R_ASM_ARCH_NONE R_SYS_ARCH_NONE +#define R_ASM_ARCH_X86 R_SYS_ARCH_X86 +#define R_ASM_ARCH_ARM R_SYS_ARCH_ARM +#define R_ASM_ARCH_PPC R_SYS_ARCH_PPC +#define R_ASM_ARCH_M68K R_SYS_ARCH_M68K +#define R_ASM_ARCH_JAVA R_SYS_ARCH_JAVA +#define R_ASM_ARCH_LM32 R_SYS_ARCH_LM32 +#define R_ASM_ARCH_MIPS R_SYS_ARCH_MIPS +#define R_ASM_ARCH_SPARC R_SYS_ARCH_SPARC +#define R_ASM_ARCH_XAP R_SYS_ARCH_XAP +#define R_ASM_ARCH_MSIL R_SYS_ARCH_MSIL +#define R_ASM_ARCH_OBJD R_SYS_ARCH_OBJD +#define R_ASM_ARCH_BF R_SYS_ARCH_BF +#define R_ASM_ARCH_SH R_SYS_ARCH_SH +#define R_ASM_ARCH_Z80 R_SYS_ARCH_Z80 +#define R_ASM_ARCH_I8080 R_SYS_ARCH_I8080 +#define R_ASM_ARCH_ARC R_SYS_ARCH_ARC +#define R_ASM_ARCH_HPPA R_SYS_ARCH_HPPA + +#define R_ASM_GET_OFFSET(x,y,z) \ + (x && x->binb.bin && x->binb.get_offset)? \ + x->binb.get_offset (x->binb.bin, y, z): -1 + +#define R_ASM_GET_NAME(x,y,z) \ + (x && x->binb.bin && x->binb.get_name)? \ + x->binb.get_name (x->binb.bin, y, z, x->pseudo): NULL + +enum { + R_ASM_SYNTAX_NONE = 0, + R_ASM_SYNTAX_INTEL, + R_ASM_SYNTAX_ATT, + R_ASM_SYNTAX_MASM, + R_ASM_SYNTAX_REGNUM, // alias for capstone's NOREGNAME + R_ASM_SYNTAX_JZ, // hack to use jz instead of je on x86 +}; + +enum { + R_ASM_MOD_RAWVALUE = 'r', + R_ASM_MOD_VALUE = 'v', + R_ASM_MOD_DSTREG = 'd', + R_ASM_MOD_SRCREG0 = '0', + R_ASM_MOD_SRCREG1 = '1', + R_ASM_MOD_SRCREG2 = '2' +}; + +typedef struct rz_asm_op_t { + int size; // instruction size (must be deprecated. just use buf.len + int bitsize; // instruction size in bits (or 0 if fits in 8bit bytes) // wtf why dupe this field? :D + int payload; // size of payload (opsize = (size-payload)) + // But this is pretty slow..so maybe we should add some accessors + RStrBuf buf; + RStrBuf buf_asm; + RBuffer *buf_inc; // must die +} RzAsmOp; + +typedef struct rz_asm_code_t { +#if 1 + int len; + ut8 *bytes; + char *assembly; +#else + RzAsmOp op; // we have those fields already inside RzAsmOp +#endif + RzList *equs; // TODO: must be a hash + ut64 code_offset; + ut64 data_offset; + int code_align; +} RzAsmCode; + +// TODO: Must use Hashtable instead of this hack +typedef struct { + char *key; + char *value; +} RzAsmEqu; + +#define _RzAsmPlugin struct rz_asm_plugin_t +typedef struct rz_asm_t { + char *cpu; + int bits; + int big_endian; + int syntax; + ut64 pc; + void *user; + _RzAsmPlugin *cur; + _RzAsmPlugin *acur; + RzList *plugins; + RBinBind binb; + RzParse *ifilter; + RzParse *ofilter; + Sdb *pair; + RzSyscall *syscall; + RNum *num; + char *features; + int invhex; // invalid instructions displayed in hex + int pcalign; + int dataalign; + int bitshift; + bool immdisp; // Display immediates with # symbol (for arm stuff). + HtPP *flags; + int seggrn; + bool pseudo; +} RzAsm; + +typedef bool (*RzAsmModifyCallback)(RzAsm *a, ut8 *buf, int field, ut64 val); + +typedef struct rz_asm_plugin_t { + const char *name; + const char *arch; + const char *author; + const char *version; + const char *cpus; + const char *desc; + const char *license; + void *user; // user data pointer + int bits; + int endian; + bool (*init)(void *user); + bool (*fini)(void *user); + int (*disassemble)(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len); + int (*assemble)(RzAsm *a, RzAsmOp *op, const char *buf); + RzAsmModifyCallback modify; + char *(*mnemonics)(RzAsm *a, int id, bool json); + const char *features; +} RzAsmPlugin; + +#ifdef RZ_API +/* asm.c */ +RZ_API RzAsm *rz_asm_new(void); +RZ_API void rz_asm_free(RzAsm *a); +RZ_API bool rz_asm_modify(RzAsm *a, ut8 *buf, int field, ut64 val); +RZ_API char *rz_asm_mnemonics(RzAsm *a, int id, bool json); +RZ_API int rz_asm_mnemonics_byname(RzAsm *a, const char *name); +RZ_API void rz_asm_set_user_ptr(RzAsm *a, void *user); +RZ_API bool rz_asm_add(RzAsm *a, RzAsmPlugin *foo); +RZ_API bool rz_asm_setup(RzAsm *a, const char *arch, int bits, int big_endian); +RZ_API bool rz_asm_is_valid(RzAsm *a, const char *name); +RZ_API bool rz_asm_use(RzAsm *a, const char *name); +RZ_API bool rz_asm_use_assembler(RzAsm *a, const char *name); +RZ_API bool rz_asm_set_arch(RzAsm *a, const char *name, int bits); +RZ_API int rz_asm_set_bits(RzAsm *a, int bits); +RZ_API void rz_asm_set_cpu(RzAsm *a, const char *cpu); +RZ_API bool rz_asm_set_big_endian(RzAsm *a, bool big_endian); +RZ_API bool rz_asm_set_syntax(RzAsm *a, int syntax); +RZ_API int rz_asm_syntax_from_string(const char *name); +RZ_API int rz_asm_set_pc(RzAsm *a, ut64 pc); +RZ_API int rz_asm_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len); +RZ_API int rz_asm_assemble(RzAsm *a, RzAsmOp *op, const char *buf); +RZ_API RzAsmCode* rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len); +RZ_API RzAsmCode* rz_asm_mdisassemble_hexstr(RzAsm *a, RzParse *p, const char *hexstr); +RZ_API RzAsmCode* rz_asm_massemble(RzAsm *a, const char *buf); +RZ_API RzAsmCode* rz_asm_rasm_assemble(RzAsm *a, const char *buf, bool use_spp); +RZ_API char *rz_asm_to_string(RzAsm *a, ut64 addr, const ut8 *b, int l); +/* to ease the use of the native bindings (not used in r2) */ +RZ_API ut8 *rz_asm_from_string(RzAsm *a, ut64 addr, const char *b, int *l); +RZ_API int rz_asm_filter_input(RzAsm *a, const char *f); +RZ_API int rz_asm_filter_output(RzAsm *a, const char *f); +RZ_API char *rz_asm_describe(RzAsm *a, const char* str); +RZ_API RzList* rz_asm_get_plugins(RzAsm *a); +RZ_API void rz_asm_list_directives(void); + +/* code.c */ +RZ_API RzAsmCode *rz_asm_code_new(void); +RZ_API void* rz_asm_code_free(RzAsmCode *acode); +RZ_API void rz_asm_equ_item_free(RzAsmEqu *equ); +RZ_API bool rz_asm_code_set_equ(RzAsmCode *code, const char *key, const char *value); +RZ_API char *rz_asm_code_equ_replace(RzAsmCode *code, char *str); +RZ_API char* rz_asm_code_get_hex(RzAsmCode *acode); + +/* op.c */ +RZ_API RzAsmOp *rz_asm_op_new(void); +RZ_API void rz_asm_op_init(RzAsmOp *op); +RZ_API void rz_asm_op_free(RzAsmOp *op); +RZ_API void rz_asm_op_fini(RzAsmOp *op); +RZ_API char *rz_asm_op_get_hex(RzAsmOp *op); +RZ_API char *rz_asm_op_get_asm(RzAsmOp *op); +RZ_API int rz_asm_op_get_size(RzAsmOp *op); +RZ_API void rz_asm_op_set_asm(RzAsmOp *op, const char *str); +RZ_API int rz_asm_op_set_hex(RzAsmOp *op, const char *str); +RZ_API int rz_asm_op_set_hexbuf(RzAsmOp *op, const ut8 *buf, int len); +RZ_API void rz_asm_op_set_buf(RzAsmOp *op, const ut8 *str, int len); +RZ_API ut8 *rz_asm_op_get_buf(RzAsmOp *op); + +/* plugin pointers */ +extern RzAsmPlugin rz_asm_plugin_6502; +extern RzAsmPlugin rz_asm_plugin_6502_cs; +extern RzAsmPlugin rz_asm_plugin_8051; +extern RzAsmPlugin rz_asm_plugin_amd29k; +extern RzAsmPlugin rz_asm_plugin_arc; +extern RzAsmPlugin rz_asm_plugin_arm_as; +extern RzAsmPlugin rz_asm_plugin_arm_cs; +extern RzAsmPlugin rz_asm_plugin_arm_gnu; +extern RzAsmPlugin rz_asm_plugin_arm_winedbg; +extern RzAsmPlugin rz_asm_plugin_avr; +extern RzAsmPlugin rz_asm_plugin_bf; +extern RzAsmPlugin rz_asm_plugin_null; +extern RzAsmPlugin rz_asm_plugin_chip8; +extern RzAsmPlugin rz_asm_plugin_cr16; +extern RzAsmPlugin rz_asm_plugin_cris_gnu; +extern RzAsmPlugin rz_asm_plugin_dalvik; +extern RzAsmPlugin rz_asm_plugin_dcpu16; +extern RzAsmPlugin rz_asm_plugin_ebc; +extern RzAsmPlugin rz_asm_plugin_gb; +extern RzAsmPlugin rz_asm_plugin_h8300; +extern RzAsmPlugin rz_asm_plugin_hexagon; +extern RzAsmPlugin rz_asm_plugin_hexagon_gnu; +extern RzAsmPlugin rz_asm_plugin_hppa_gnu; +extern RzAsmPlugin rz_asm_plugin_i4004; +extern RzAsmPlugin rz_asm_plugin_i8080; +extern RzAsmPlugin rz_asm_plugin_java; +extern RzAsmPlugin rz_asm_plugin_lanai_gnu; +extern RzAsmPlugin rz_asm_plugin_lh5801; +extern RzAsmPlugin rz_asm_plugin_lm32; +extern RzAsmPlugin rz_asm_plugin_m68k_cs; +extern RzAsmPlugin rz_asm_plugin_m680x_cs; +extern RzAsmPlugin rz_asm_plugin_malbolge; +extern RzAsmPlugin rz_asm_plugin_mcore; +extern RzAsmPlugin rz_asm_plugin_mcs96; +extern RzAsmPlugin rz_asm_plugin_mips_cs; +extern RzAsmPlugin rz_asm_plugin_mips_gnu; +extern RzAsmPlugin rz_asm_plugin_msp430; +extern RzAsmPlugin rz_asm_plugin_nios2; +extern RzAsmPlugin rz_asm_plugin_or1k; +extern RzAsmPlugin rz_asm_plugin_pic; +extern RzAsmPlugin rz_asm_plugin_ppc_cs; +extern RzAsmPlugin rz_asm_plugin_ppc_gnu; +extern RzAsmPlugin rz_asm_plugin_propeller; +extern RzAsmPlugin rz_asm_plugin_riscv; +extern RzAsmPlugin rz_asm_plugin_riscv_cs; +extern RzAsmPlugin rz_asm_plugin_rsp; +extern RzAsmPlugin rz_asm_plugin_sh; +extern RzAsmPlugin rz_asm_plugin_snes; +extern RzAsmPlugin rz_asm_plugin_sparc_cs; +extern RzAsmPlugin rz_asm_plugin_sparc_gnu; +extern RzAsmPlugin rz_asm_plugin_spc700; +extern RzAsmPlugin rz_asm_plugin_sysz; +extern RzAsmPlugin rz_asm_plugin_tms320; +extern RzAsmPlugin rz_asm_plugin_tms320c64x; +extern RzAsmPlugin rz_asm_plugin_tricore; +extern RzAsmPlugin rz_asm_plugin_v810; +extern RzAsmPlugin rz_asm_plugin_v850; +extern RzAsmPlugin rz_asm_plugin_vax; +extern RzAsmPlugin rz_asm_plugin_wasm; +extern RzAsmPlugin rz_asm_plugin_ws; +extern RzAsmPlugin rz_asm_plugin_x86_as; +extern RzAsmPlugin rz_asm_plugin_x86_cs; +extern RzAsmPlugin rz_asm_plugin_x86_nasm; +extern RzAsmPlugin rz_asm_plugin_x86_nz; +extern RzAsmPlugin rz_asm_plugin_xap; +extern RzAsmPlugin rz_asm_plugin_xcore_cs; +extern RzAsmPlugin rz_asm_plugin_xtensa; +extern RzAsmPlugin rz_asm_plugin_z80; +extern RzAsmPlugin rz_asm_plugin_pyc; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_bin.h b/librz/include/rz_bin.h new file mode 100644 index 0000000000..080bcf51e7 --- /dev/null +++ b/librz/include/rz_bin.h @@ -0,0 +1,889 @@ +#ifndef R2_BIN_H +#define R2_BIN_H + +#include +#include +#include +#include +#include + +typedef struct rz_bin_t RBin; + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER (rz_bin); + +#define R_BIN_DBG_STRIPPED 0x01 +#define R_BIN_DBG_STATIC 0x02 +#define R_BIN_DBG_LINENUMS 0x04 +#define R_BIN_DBG_SYMS 0x08 +#define R_BIN_DBG_RELOCS 0x10 + +#define R_BIN_ENTRY_TYPE_PROGRAM 0 +#define R_BIN_ENTRY_TYPE_MAIN 1 +#define R_BIN_ENTRY_TYPE_INIT 2 +#define R_BIN_ENTRY_TYPE_FINI 3 +#define R_BIN_ENTRY_TYPE_TLS 4 +#define R_BIN_ENTRY_TYPE_PREINIT 5 + +#define R_BIN_SIZEOF_STRINGS 512 +#define R_BIN_MAX_ARCH 1024 + +#define R_BIN_REQ_ALL UT64_MAX +#define R_BIN_REQ_UNK 0x000000 +#define R_BIN_REQ_ENTRIES 0x000001 +#define R_BIN_REQ_IMPORTS 0x000002 +#define R_BIN_REQ_SYMBOLS 0x000004 +#define R_BIN_REQ_SECTIONS 0x000008 +#define R_BIN_REQ_INFO 0x000010 +#define R_BIN_REQ_OPERATION 0x000020 +#define R_BIN_REQ_HELP 0x000040 +#define R_BIN_REQ_STRINGS 0x000080 +#define R_BIN_REQ_FIELDS 0x000100 +#define R_BIN_REQ_LIBS 0x000200 +#define R_BIN_REQ_SRCLINE 0x000400 +#define R_BIN_REQ_MAIN 0x000800 +#define R_BIN_REQ_EXTRACT 0x001000 +#define R_BIN_REQ_RELOCS 0x002000 +#define R_BIN_REQ_LISTARCHS 0x004000 +#define R_BIN_REQ_CREATE 0x008000 +#define R_BIN_REQ_CLASSES 0x010000 +#define R_BIN_REQ_DWARF 0x020000 +#define R_BIN_REQ_SIZE 0x040000 +#define R_BIN_REQ_PDB 0x080000 +#define R_BIN_REQ_PDB_DWNLD 0x100000 +#define R_BIN_REQ_DLOPEN 0x200000 +#define R_BIN_REQ_EXPORTS 0x400000 +#define R_BIN_REQ_VERSIONINFO 0x800000 +#define R_BIN_REQ_PACKAGE 0x1000000 +#define R_BIN_REQ_HEADER 0x2000000 +#define R_BIN_REQ_LISTPLUGINS 0x4000000 +#define R_BIN_REQ_RESOURCES 0x8000000 +#define R_BIN_REQ_INITFINI 0x10000000 +#define R_BIN_REQ_SEGMENTS 0x20000000 +#define R_BIN_REQ_HASHES 0x40000000 +#define R_BIN_REQ_SIGNATURE 0x80000000 +#define R_BIN_REQ_TRYCATCH 0x100000000 +#define R_BIN_REQ_SECTIONS_MAPPING 0x200000000 + +/* RBinSymbol->method_flags : */ +#define R_BIN_METH_CLASS 0x0000000000000001L +#define R_BIN_METH_STATIC 0x0000000000000002L +#define R_BIN_METH_PUBLIC 0x0000000000000004L +#define R_BIN_METH_PRIVATE 0x0000000000000008L +#define R_BIN_METH_PROTECTED 0x0000000000000010L +#define R_BIN_METH_INTERNAL 0x0000000000000020L +#define R_BIN_METH_OPEN 0x0000000000000040L +#define R_BIN_METH_FILEPRIVATE 0x0000000000000080L +#define R_BIN_METH_FINAL 0x0000000000000100L +#define R_BIN_METH_VIRTUAL 0x0000000000000200L +#define R_BIN_METH_CONST 0x0000000000000400L +#define R_BIN_METH_MUTATING 0x0000000000000800L +#define R_BIN_METH_ABSTRACT 0x0000000000001000L +#define R_BIN_METH_SYNCHRONIZED 0x0000000000002000L +#define R_BIN_METH_NATIVE 0x0000000000004000L +#define R_BIN_METH_BRIDGE 0x0000000000008000L +#define R_BIN_METH_VARARGS 0x0000000000010000L +#define R_BIN_METH_SYNTHETIC 0x0000000000020000L +#define R_BIN_METH_STRICT 0x0000000000040000L +#define R_BIN_METH_MIRANDA 0x0000000000080000L +#define R_BIN_METH_CONSTRUCTOR 0x0000000000100000L +#define R_BIN_METH_DECLARED_SYNCHRONIZED 0x0000000000200000L + +#define R_BIN_BIND_LOCAL_STR "LOCAL" +#define R_BIN_BIND_GLOBAL_STR "GLOBAL" +#define R_BIN_BIND_WEAK_STR "WEAK" +#define R_BIN_BIND_NUM_STR "NUM" +#define R_BIN_BIND_LOOS_STR "LOOS" +#define R_BIN_BIND_HIOS_STR "HIOS" +#define R_BIN_BIND_LOPROC_STR "LOPROC" +#define R_BIN_BIND_HIPROC_STR "HIPROC" +#define R_BIN_BIND_UNKNOWN_STR "UNKNOWN" + +#define R_BIN_TYPE_NOTYPE_STR "NOTYPE" +#define R_BIN_TYPE_OBJECT_STR "OBJ" +#define R_BIN_TYPE_FUNC_STR "FUNC" +#define R_BIN_TYPE_METH_STR "METH" +#define R_BIN_TYPE_STATIC_STR "STATIC" +#define R_BIN_TYPE_SECTION_STR "SECT" +#define R_BIN_TYPE_FILE_STR "FILE" +#define R_BIN_TYPE_COMMON_STR "COMMON" +#define R_BIN_TYPE_TLS_STR "TLS" +#define R_BIN_TYPE_NUM_STR "NUM" +#define R_BIN_TYPE_LOOS_STR "LOOS" +#define R_BIN_TYPE_HIOS_STR "HIOS" +#define R_BIN_TYPE_LOPROC_STR "LOPROC" +#define R_BIN_TYPE_HIPROC_STR "HIPROC" +#define R_BIN_TYPE_SPECIAL_SYM_STR "SPCL" +#define R_BIN_TYPE_UNKNOWN_STR "UNK" + +enum { + R_BIN_SYM_ENTRY, + R_BIN_SYM_INIT, + R_BIN_SYM_MAIN, + R_BIN_SYM_FINI, + R_BIN_SYM_LAST +}; + +// name mangling types +// TODO: Rename to R_BIN_LANG_ +enum { + R_BIN_NM_NONE = 0, + R_BIN_NM_JAVA = 1, + R_BIN_NM_C = 1<<1, + R_BIN_NM_GO = 1<<2, + R_BIN_NM_CXX = 1<<3, + R_BIN_NM_OBJC = 1<<4, + R_BIN_NM_SWIFT = 1<<5, + R_BIN_NM_DLANG = 1<<6, + R_BIN_NM_MSVC = 1<<7, + R_BIN_NM_RUST = 1<<8, + R_BIN_NM_KOTLIN = 1<<9, + R_BIN_NM_BLOCKS = 1<<31, + R_BIN_NM_ANY = -1, +}; + +enum { + R_STRING_TYPE_DETECT = '?', + R_STRING_TYPE_ASCII = 'a', + R_STRING_TYPE_UTF8 = 'u', + R_STRING_TYPE_WIDE = 'w', // utf16 / widechar string + R_STRING_TYPE_WIDE32 = 'W', // utf32 + R_STRING_TYPE_BASE64 = 'b', +}; + +enum { + R_BIN_CLASS_PRIVATE, + R_BIN_CLASS_PUBLIC, + R_BIN_CLASS_FRIENDLY, + R_BIN_CLASS_PROTECTED, +}; + +enum { + R_BIN_RELOC_8 = 8, + R_BIN_RELOC_16 = 16, + R_BIN_RELOC_32 = 32, + R_BIN_RELOC_64 = 64 +}; + +enum { + R_BIN_TYPE_DEFAULT = 0, + R_BIN_TYPE_CORE = 1 +}; + +typedef struct rz_bin_addr_t { + ut64 vaddr; + ut64 paddr; + ut64 hvaddr; + ut64 hpaddr; + int type; + int bits; +} RBinAddr; + +typedef struct rz_bin_hash_t { + const char *type; + ut64 addr; + int len; + ut64 from; + ut64 to; + ut8 buf[32]; + const char *cmd; +} RBinHash; + +typedef struct rz_bin_file_hash_t { + const char *type; + const char *hex; +} RBinFileHash; + +typedef struct rz_bin_info_t { + char *file; + char *type; + char *bclass; + char *rclass; + char *arch; + char *cpu; + char *machine; + char *head_flag; + char *features; + char *os; + char *subsystem; + char *rpath; + char *guid; + char *debug_file_name; + const char *lang; + char *default_cc; + RzList/**/ *file_hashes; + int bits; + int has_va; + int has_pi; // pic/pie + int has_canary; + int has_retguard; + int has_sanitizers; + int has_crypto; + int has_nx; + int big_endian; + bool has_lit; + char *actual_checksum; + char *claimed_checksum; + int pe_overlay; + bool signature; + ut64 dbg_info; + RBinHash sum[3]; + ut64 baddr; + char *intrp; + char *compiler; +} RBinInfo; + +typedef struct rz_bin_object_t { + ut64 baddr; + st64 baddr_shift; + ut64 loadaddr; + ut64 boffset; + ut64 size; + ut64 obj_size; + RzList/**/ *sections; + RzList/**/ *imports; + RzList/**/ *symbols; + RzList/**/ *entries; + RzList/**/ *fields; + RzList/**/ *libs; + RBNode/**/ *relocs; + RzList/**/ *strings; + RzList/**/ *classes; + HtPP *classes_ht; + HtPP *methods_ht; + RzList/**/ *lines; + HtUP *strings_db; + RzList/**/ *mem; //RBinMem maybe? + RzList/*plugin +typedef struct rz_bin_file_t { + char *file; + int fd; + int size; + int rawstr; + int strmode; + ut32 id; + RBuffer *buf; + ut64 offset; + RBinObject *o; + void *xtr_obj; + ut64 loadaddr; + /* values used when searching the strings */ + int minstrlen; + int maxstrlen; + int narch; + struct rz_bin_xtr_plugin_t *curxtr; + // struct rz_bin_plugin_t *curplugin; // use o->plugin + RzList *xtr_data; + Sdb *sdb; + Sdb *sdb_info; + Sdb *sdb_addrinfo; + struct rz_bin_t *rbin; +} RBinFile; + +typedef struct rz_bin_file_options_t { + int rawstr; + ut64 baddr; // base address + ut64 laddr; // load address + ut64 paddr; // offset + const char *plugname; // force a plugin? why do i need this? + // const char *xtrname; +} RBinFileOptions; + +struct rz_bin_t { + const char *file; + RBinFile *cur; // TODO: deprecate + int narch; + void *user; + /* preconfigured values */ + int debase64; + int minstrlen; + int maxstrlen; + ut64 maxstrbuf; + int rawstr; + Sdb *sdb; + RIDStorage *ids; + RzList/**/ *plugins; + RzList/**/ *binxtrs; + RzList/**/ *binldrs; + RzList/**/ *binfiles; + PrintfCallback cb_printf; + int loadany; + RzIOBind iob; + RzConsBind consb; + char *force; + int is_debugger; + bool want_dbginfo; + int filter; // symbol filtering + char strfilter; // string filtering + char *strpurge; // purge false positive strings + char *srcdir; // dir.source + char *prefix; // bin.prefix + char *strenc; + ut64 filter_rules; + bool demanglercmd; + bool verbose; + bool use_xtr; // use extract plugins when loading a file? + bool use_ldr; // use loader plugins when loading a file? + RStrConstPool constpool; + bool is_reloc_patched; // used to indicate whether relocations were patched or not +}; + +typedef struct rz_bin_xtr_metadata_t { + char *arch; + int bits; + char *libname; + char *machine; + char *type; + const char *xtr_type; +} RBinXtrMetadata; + +typedef int (*FREE_XTR)(void *xtr_obj); +typedef struct rz_bin_xtr_extract_t { + char *file; + RBuffer *buf; + ut64 size; + ut64 offset; + ut64 baddr; + ut64 laddr; + int file_count; + int loaded; + RBinXtrMetadata *metadata; +} RBinXtrData; + +RZ_API RBinXtrData *rz_bin_xtrdata_new(RBuffer *buf, ut64 offset, ut64 size, ut32 file_count, RBinXtrMetadata *metadata); +RZ_API void rz_bin_xtrdata_free(void /*RBinXtrData*/ *data); + +typedef struct rz_bin_xtr_plugin_t { + char *name; + char *desc; + char *license; + int (*init)(void *user); + int (*fini)(void *user); + bool (*check_buffer)(RBuffer *b); + + RBinXtrData *(*extract_from_bytes)(RBin *bin, const ut8 *buf, ut64 size, int idx); + RBinXtrData *(*extract_from_buffer)(RBin *bin, RBuffer *buf, int idx); + RzList *(*extractall_from_bytes)(RBin *bin, const ut8 *buf, ut64 size); + RzList *(*extractall_from_buffer)(RBin *bin, RBuffer *buf); + RBinXtrData *(*extract)(RBin *bin, int idx); + RzList *(*extractall)(RBin *bin); + + bool (*load)(RBin *bin); + int (*size)(RBin *bin); + void (*destroy)(RBin *bin); + void (*free_xtr)(void *xtr_obj); +} RBinXtrPlugin; + +typedef struct rz_bin_ldr_plugin_t { + char *name; + char *desc; + char *license; + int (*init)(void *user); + int (*fini)(void *user); + bool (*load)(RBin *bin); +} RBinLdrPlugin; + +typedef struct rz_bin_arch_options_t { + const char *arch; + int bits; +} RBinArchOptions; + +typedef struct rz_bin_trycatch_t { + ut64 source; + ut64 from; + ut64 to; + ut64 handler; + ut64 filter; + // TODO: add type/name of exception +} RBinTrycatch; + +RZ_API RBinTrycatch *rz_bin_trycatch_new(ut64 source, ut64 from, ut64 to, ut64 handler, ut64 filter); +RZ_API void rz_bin_trycatch_free(RBinTrycatch *tc); + +typedef struct rz_bin_plugin_t { + char *name; + char *desc; + char *author; + char *version; + char *license; + int (*init)(void *user); + int (*fini)(void *user); + Sdb * (*get_sdb)(RBinFile *obj); + bool (*load_buffer)(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb); + ut64 (*size)(RBinFile *bin); // return ut64 maybe? meh + void (*destroy)(RBinFile *bf); + bool (*check_bytes)(const ut8 *buf, ut64 length); + bool (*check_buffer)(RBuffer *buf); + ut64 (*baddr)(RBinFile *bf); + ut64 (*boffset)(RBinFile *bf); + RBinAddr* (*binsym)(RBinFile *bf, int num); + RzList/**/* (*entries)(RBinFile *bf); + RzList/**/* (*sections)(RBinFile *bf); + R_BORROW RzList/**/* (*lines)(RBinFile *bf); + RzList/**/* (*symbols)(RBinFile *bf); + RzList/**/* (*imports)(RBinFile *bf); + RzList/**/* (*strings)(RBinFile *bf); + RBinInfo/**/* (*info)(RBinFile *bf); + RzList/**/* (*fields)(RBinFile *bf); + RzList/**/* (*libs)(RBinFile *bf); + RzList/**/* (*relocs)(RBinFile *bf); + RzList/**/* (*trycatch)(RBinFile *bf); + RzList/**/* (*classes)(RBinFile *bf); + RzList/**/* (*mem)(RBinFile *bf); + RzList/**/* (*patch_relocs)(RBin *bin); + RzList/**/* (*maps)(RBinFile *bf); + RzList/**/* (*hashes)(RBinFile *bf); + void (*header)(RBinFile *bf); + char* (*signature)(RBinFile *bf, bool json); + int (*demangle_type)(const char *str); + struct rz_bin_dbginfo_t *dbginfo; + struct rz_bin_write_t *write; + int (*get_offset)(RBinFile *bf, int type, int idx); + char* (*get_name)(RBinFile *bf, int type, int idx, bool simplified); + ut64 (*get_vaddr)(RBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr); + RBuffer* (*create)(RBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt); + char* (*demangle)(const char *str); + char* (*regstate)(RBinFile *bf); + int (*file_type)(RBinFile *bf); + /* default value if not specified by user */ + int minstrlen; + char strfilter; + void *user; +} RBinPlugin; + +typedef void (*RBinSymbollCallback)(RBinObject *obj, void *symbol); + +typedef struct rz_bin_section_t { + char *name; + ut64 size; + ut64 vsize; + ut64 vaddr; + ut64 paddr; + ut32 perm; + // per section platform info + const char *arch; + char *format; + int bits; + bool has_strings; + bool add; // indicates when you want to add the section to io `S` command + bool is_data; + bool is_segment; +} RBinSection; + +typedef struct rz_bin_class_t { + char *name; + // TODO: char *module; + char *super; + char *visibility_str; // XXX only used by java + int index; + ut64 addr; + RzList *methods; // + RzList *fields; // + // RzList *interfaces; // + int visibility; +} RBinClass; + +#define RBinSectionName rz_offsetof(RBinSection, name) +#define RBinSectionOffset rz_offsetof(RBinSection, offset) + +#define REBASE_PADDR(o, l, type_t)\ + do { \ + RzListIter *_it;\ + type_t *_el;\ + rz_list_foreach ((l), _it, _el) { \ + _el->paddr += (o)->loadaddr;\ + }\ + } while (0) + + +typedef struct rz_bin_symbol_t { + /* heap-allocated */ + char *name; + char *dname; + char *libname; + char *classname; + /* const-unique-strings */ + const char *forwarder; + const char *bind; + const char *type; + const char *rtype; + bool is_imported; + /* only used by java */ + const char *visibility_str; + // ---------------- + //char descriptor[R_BIN_SIZEOF_STRINGS+1]; + ut64 vaddr; + ut64 paddr; + ut32 size; + ut32 ordinal; + ut32 visibility; + int bits; + /* see R_BIN_METH_* constants */ + ut64 method_flags; + int dup_count; +} RBinSymbol; + +typedef struct rz_bin_import_t { + char *name; + char *libname; + const char *bind; + const char *type; + char *classname; + char *descriptor; + ut32 ordinal; + ut32 visibility; +} RBinImport; + +typedef struct rz_bin_reloc_t { + ut8 type; + ut8 additive; + RBinSymbol *symbol; + RBinImport *import; + st64 addend; + ut64 vaddr; + ut64 paddr; + ut32 visibility; + /* is_ifunc: indirect function, `addend` points to a resolver function + * that returns the actual relocation value, e.g. chooses + * an optimized version depending on the CPU. + * cf. https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html + */ + bool is_ifunc; + RBNode vrb; +} RBinReloc; + +typedef struct rz_bin_string_t { + // TODO: rename string->name (avoid colisions) + char *string; + ut64 vaddr; + ut64 paddr; + ut32 ordinal; + ut32 size; // size of buffer containing the string in bytes + ut32 length; // length of string in chars + char type; // Ascii Wide cp850 utf8 base64 ... +} RBinString; + +typedef struct rz_bin_field_t { + ut64 vaddr; + ut64 paddr; + int size; + int offset; + ut32 visibility; + char *name; + char *type; + char *comment; + char *format; + bool format_named; // whether format is the name of a format or a raw pf format string + ut64 flags; +} RBinField; + +RZ_API RBinField *rz_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char *name, const char *comment, const char *format, bool format_named); +RZ_API void rz_bin_field_free(void *); + +typedef struct rz_bin_mem_t { + char *name; + ut64 addr; + int size; + int perms; + RzList *mirrors; //for mirror access; stuff here should only create new maps not new fds +} RBinMem; + +typedef struct rz_bin_map_t { + ut64 addr; + ut64 offset; + int size; + int perms; + char *file; +} RBinMap; + +typedef struct rz_bin_dbginfo_t { + bool (*get_line)(RBinFile *arch, ut64 addr, char *file, int len, int *line); +} RBinDbgInfo; + +typedef struct rz_bin_write_t { + ut64 (*scn_resize)(RBinFile *bf, const char *name, ut64 size); + bool (*scn_perms)(RBinFile *bf, const char *name, int perms); + int (*rpath_del)(RBinFile *bf); + bool (*entry)(RBinFile *bf, ut64 addr); + bool (*addlib)(RBinFile *bf, const char *lib); +} RBinWrite; + +// TODO: deprecate rz_bin_is_big_endian +// TODO: has_dbg_syms... maybe flags? + +typedef int (*RBinGetOffset)(RBin *bin, int type, int idx); +typedef const char *(*RBinGetName)(RBin *bin, int type, int idx, bool sd); +typedef RzList *(*RBinGetSections)(RBin *bin); +typedef RBinSection *(*RBinGetSectionAt)(RBin *bin, ut64 addr); +typedef char *(*RBinDemangle)(RBinFile *bf, const char *def, const char *str, ut64 vaddr, bool libs); + +typedef struct rz_bin_bind_t { + RBin *bin; + RBinGetOffset get_offset; + RBinGetName get_name; + RBinGetSections get_sections; + RBinGetSectionAt get_vsect_at; + RBinDemangle demangle; + ut32 visibility; +} RBinBind; + +R_IPI RBinSection *rz_bin_section_new(const char *name); +R_IPI void rz_bin_section_free(RBinSection *bs); +RZ_API void rz_bin_info_free(RBinInfo *rb); +RZ_API void rz_bin_import_free(void *_imp); +RZ_API void rz_bin_symbol_free(void *_sym); +RZ_API RBinSymbol *rz_bin_symbol_new(const char *name, ut64 paddr, ut64 vaddr); +RZ_API void rz_bin_string_free(void *_str); + +#ifdef RZ_API + +typedef struct rz_bin_options_t { + const char *pluginname; + ut64 baseaddr; // where the linker maps the binary in memory + ut64 loadaddr; // starting physical address to read from the target file + ut64 sz; + int xtr_idx; // load Nth binary + int rawstr; + int fd; + const char *filename; +} RBinOptions; + +RZ_API RBinImport *rz_bin_import_clone(RBinImport *o); +RZ_API const char *rz_bin_symbol_name(RBinSymbol *s); +typedef void (*RBinSymbolCallback)(RBinObject *obj, RBinSymbol *symbol); + +// options functions +RZ_API void rz_bin_options_init(RBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, int rawstr); +RZ_API void rz_bin_arch_options_init(RBinArchOptions *opt, const char *arch, int bits); + +// open/close/reload functions +RZ_API RBin *rz_bin_new(void); +RZ_API void rz_bin_free(RBin *bin); +RZ_API bool rz_bin_open(RBin *bin, const char *file, RBinOptions *opt); +RZ_API bool rz_bin_open_io(RBin *bin, RBinOptions *opt); +RZ_API bool rz_bin_open_buf(RBin *bin, RBuffer *buf, RBinOptions *opt); +RZ_API bool rz_bin_reload(RBin *bin, ut32 bf_id, ut64 baseaddr); + +// plugins/bind functions +RZ_API void rz_bin_bind(RBin *b, RBinBind *bnd); +RZ_API bool rz_bin_add(RBin *bin, RBinPlugin *foo); +RZ_API bool rz_bin_xtr_add(RBin *bin, RBinXtrPlugin *foo); +RZ_API bool rz_bin_ldr_add(RBin *bin, RBinLdrPlugin *foo); +RZ_API void rz_bin_list(RBin *bin, int format); +RZ_API bool rz_bin_list_plugin(RBin *bin, const char *name, int json); +RZ_API RBinPlugin *rz_bin_get_binplugin_by_bytes(RBin *bin, const ut8 *bytes, ut64 sz); +RZ_API RBinPlugin *rz_bin_get_binplugin_by_buffer(RBin *bin, RBuffer *buf); +RZ_API void rz_bin_force_plugin(RBin *bin, const char *pname); + +// get/set various bin information +RZ_API ut64 rz_bin_get_baddr(RBin *bin); +RZ_API ut64 rz_bin_file_get_baddr(RBinFile *bf); +RZ_API void rz_bin_set_user_ptr(RBin *bin, void *user); +RZ_API RBinInfo *rz_bin_get_info(RBin *bin); +RZ_API void rz_bin_set_baddr(RBin *bin, ut64 baddr); +RZ_API ut64 rz_bin_get_laddr(RBin *bin); +RZ_API ut64 rz_bin_get_size(RBin *bin); +RZ_API RBinAddr *rz_bin_get_sym(RBin *bin, int sym); +RZ_API RzList *rz_bin_raw_strings(RBinFile *a, int min); +RZ_API RzList *rz_bin_dump_strings(RBinFile *a, int min, int raw); + +// use RBinFile instead +RZ_API RzList *rz_bin_get_entries(RBin *bin); +RZ_API RzList *rz_bin_get_fields(RBin *bin); +RZ_API RzList *rz_bin_get_imports(RBin *bin); +RZ_API RzList *rz_bin_get_libs(RBin *bin); +RZ_API RBNode *rz_bin_patch_relocs(RBin *bin); +RZ_API RzList *rz_bin_patch_relocs_list(RBin *bin); +RZ_API RBNode *rz_bin_get_relocs(RBin *bin); +RZ_API RzList *rz_bin_get_relocs_list(RBin *bin); +RZ_API RzList *rz_bin_get_sections(RBin *bin); +RZ_API RzList *rz_bin_get_classes(RBin *bin); +RZ_API RzList *rz_bin_get_strings(RBin *bin); +RZ_API RzList *rz_bin_file_get_trycatch(RBinFile *bf); +RZ_API RzList *rz_bin_get_symbols(RBin *bin); +RZ_API RzList *rz_bin_reset_strings(RBin *bin); +RZ_API int rz_bin_is_string(RBin *bin, ut64 va); +RZ_API int rz_bin_is_big_endian(RBin *bin); +RZ_API int rz_bin_is_static(RBin *bin); +RZ_API ut64 rz_bin_get_vaddr(RBin *bin, ut64 paddr, ut64 vaddr); +RZ_API ut64 rz_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr); +RZ_API ut64 rz_bin_a2b(RBin *bin, ut64 addr); + +RZ_API int rz_bin_load_languages(RBinFile *binfile); +RZ_API RBinFile *rz_bin_cur(RBin *bin); +RZ_API RBinObject *rz_bin_cur_object(RBin *bin); + +// select/list binfiles functions +RZ_API bool rz_bin_select(RBin *bin, const char *arch, int bits, const char *name); +RZ_API bool rz_bin_select_bfid(RBin *bin, ut32 bf_id); +RZ_API bool rz_bin_use_arch(RBin *bin, const char *arch, int bits, const char *name); +RZ_API void rz_bin_list_archs(RBin *bin, int mode); +RZ_API RBuffer *rz_bin_create(RBin *bin, const char *plugin_name, const ut8 *code, int codelen, const ut8 *data, int datalen, RBinArchOptions *opt); +RZ_API RBuffer *rz_bin_package(RBin *bin, const char *type, const char *file, RzList *files); + +RZ_API const char *rz_bin_string_type(int type); +RZ_API const char *rz_bin_entry_type_string(int etype); + +RZ_API bool rz_bin_file_object_new_from_xtr_data(RBin *bin, RBinFile *bf, ut64 baseaddr, ut64 loadaddr, RBinXtrData *data); + + +// RBinFile lifecycle +// R_IPI RBinFile *rz_bin_file_new(RBin *bin, const char *file, ut64 file_sz, int rawstr, int fd, const char *xtrname, Sdb *sdb, bool steal_ptr); +RZ_API bool rz_bin_file_close(RBin *bin, int bd); +RZ_API void rz_bin_file_free(void /*RBinFile*/ *bf_); +// RBinFile.get +RZ_API RBinFile *rz_bin_file_at(RBin *bin, ut64 addr); +RZ_API RBinFile *rz_bin_file_find_by_object_id(RBin *bin, ut32 binobj_id); +RZ_API RzList *rz_bin_file_get_symbols(RBinFile *bf); +// +RZ_API ut64 rz_bin_file_get_vaddr(RBinFile *bf, ut64 paddr, ut64 vaddr); +// RBinFile.add +RZ_API RBinClass *rz_bin_file_add_class(RBinFile *binfile, const char *name, const char *super, int view); +RZ_API RBinSymbol *rz_bin_file_add_method(RBinFile *bf, const char *classname, const char *name, int nargs); +RZ_API RBinField *rz_bin_file_add_field(RBinFile *binfile, const char *classname, const char *name); +// RBinFile.find +RZ_API RBinFile *rz_bin_file_find_by_arch_bits(RBin *bin, const char *arch, int bits); +RZ_API RBinFile *rz_bin_file_find_by_id(RBin *bin, ut32 bin_id); +RZ_API RBinFile *rz_bin_file_find_by_fd(RBin *bin, ut32 bin_fd); +RZ_API RBinFile *rz_bin_file_find_by_name(RBin *bin, const char *name); + +RZ_API bool rz_bin_file_set_cur_binfile(RBin *bin, RBinFile *bf); +RZ_API bool rz_bin_file_set_cur_by_name(RBin *bin, const char *name); +RZ_API bool rz_bin_file_deref(RBin *bin, RBinFile *a); +RZ_API bool rz_bin_file_set_cur_by_fd(RBin *bin, ut32 bin_fd); +RZ_API bool rz_bin_file_set_cur_by_id(RBin *bin, ut32 bin_id); +RZ_API bool rz_bin_file_set_cur_by_name(RBin *bin, const char *name); +RZ_API ut64 rz_bin_file_delete_all(RBin *bin); +RZ_API bool rz_bin_file_delete(RBin *bin, ut32 bin_id); +RZ_API RzList *rz_bin_file_compute_hashes(RBin *bin, ut64 limit); +RZ_API RzList *rz_bin_file_set_hashes(RBin *bin, RzList *new_hashes); +RZ_API RBinPlugin *rz_bin_file_cur_plugin(RBinFile *binfile); +RZ_API void rz_bin_file_hash_free(RBinFileHash *fhash); + +// binobject functions +RZ_API int rz_bin_object_set_items(RBinFile *binfile, RBinObject *o); +RZ_API bool rz_bin_object_delete(RBin *bin, ut32 binfile_id); +RZ_API void rz_bin_mem_free(void *data); + +// demangle functions +RZ_API char *rz_bin_demangle(RBinFile *binfile, const char *lang, const char *str, ut64 vaddr, bool libs); +RZ_API char *rz_bin_demangle_java(const char *str); +RZ_API char *rz_bin_demangle_cxx(RBinFile *binfile, const char *str, ut64 vaddr); +RZ_API char *rz_bin_demangle_msvc(const char *str); +RZ_API char *rz_bin_demangle_swift(const char *s, bool syscmd); +RZ_API char *rz_bin_demangle_objc(RBinFile *binfile, const char *sym); +RZ_API char *rz_bin_demangle_rust(RBinFile *binfile, const char *str, ut64 vaddr); +RZ_API int rz_bin_demangle_type(const char *str); +RZ_API void rz_bin_demangle_list(RBin *bin); +RZ_API char *rz_bin_demangle_plugin(RBin *bin, const char *name, const char *str); +RZ_API const char *rz_bin_get_meth_flag_string(ut64 flag, bool compact); + +RZ_API RBinSection *rz_bin_get_section_at(RBinObject *o, ut64 off, int va); + +/* dbginfo.c */ +RZ_API bool rz_bin_addr2line(RBin *bin, ut64 addr, char *file, int len, int *line); +RZ_API char *rz_bin_addr2text(RBin *bin, ut64 addr, int origin); +RZ_API char *rz_bin_addr2fileline(RBin *bin, ut64 addr); +/* bin_write.c */ +RZ_API bool rz_bin_wr_addlib(RBin *bin, const char *lib); +RZ_API ut64 rz_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size); +RZ_API bool rz_bin_wr_scn_perms(RBin *bin, const char *name, int perms); +RZ_API bool rz_bin_wr_rpath_del(RBin *bin); +RZ_API bool rz_bin_wr_entry(RBin *bin, ut64 addr); +RZ_API bool rz_bin_wr_output(RBin *bin, const char *filename); + +RZ_API RzList *rz_bin_get_mem(RBin *bin); + +/* filter.c */ +RZ_API void rz_bin_load_filter(RBin *bin, ut64 rules); +RZ_API void rz_bin_filter_symbols(RBinFile *bf, RzList *list); +RZ_API void rz_bin_filter_sections(RBinFile *bf, RzList *list); +RZ_API char *rz_bin_filter_name(RBinFile *bf, Sdb *db, ut64 addr, char *name); +RZ_API void rz_bin_filter_sym(RBinFile *bf, HtPP *ht, ut64 vaddr, RBinSymbol *sym); +RZ_API bool rz_bin_strpurge(RBin *bin, const char *str, ut64 addr); +RZ_API bool rz_bin_string_filter(RBin *bin, const char *str, ut64 addr); + +/* plugin pointers */ +extern RBinPlugin rz_bin_plugin_any; +extern RBinPlugin rz_bin_plugin_fs; +extern RBinPlugin rz_bin_plugin_cgc; +extern RBinPlugin rz_bin_plugin_elf; +extern RBinPlugin rz_bin_plugin_elf64; +extern RBinPlugin rz_bin_plugin_p9; +extern RBinPlugin rz_bin_plugin_ne; +extern RBinPlugin rz_bin_plugin_le; +extern RBinPlugin rz_bin_plugin_pe; +extern RBinPlugin rz_bin_plugin_mz; +extern RBinPlugin rz_bin_plugin_pe64; +extern RBinPlugin rz_bin_plugin_pebble; +extern RBinPlugin rz_bin_plugin_bios; +extern RBinPlugin rz_bin_plugin_bf; +extern RBinPlugin rz_bin_plugin_te; +extern RBinPlugin rz_bin_plugin_symbols; +extern RBinPlugin rz_bin_plugin_mach0; +extern RBinPlugin rz_bin_plugin_mach064; +extern RBinPlugin rz_bin_plugin_mdmp; +extern RBinPlugin rz_bin_plugin_java; +extern RBinPlugin rz_bin_plugin_dex; +extern RBinPlugin rz_bin_plugin_coff; +extern RBinPlugin rz_bin_plugin_ningb; +extern RBinPlugin rz_bin_plugin_ningba; +extern RBinPlugin rz_bin_plugin_ninds; +extern RBinPlugin rz_bin_plugin_nin3ds; +extern RBinPlugin rz_bin_plugin_xbe; +extern RBinPlugin rz_bin_plugin_bflt; +extern RBinXtrPlugin rz_bin_xtr_plugin_xtr_fatmach0; +extern RBinXtrPlugin rz_bin_xtr_plugin_xtr_dyldcache; +extern RBinXtrPlugin rz_bin_xtr_plugin_xtr_pemixed; +extern RBinXtrPlugin rz_bin_xtr_plugin_xtr_sep64; +extern RBinLdrPlugin rz_bin_ldr_plugin_ldr_linux; +extern RBinPlugin rz_bin_plugin_zimg; +extern RBinPlugin rz_bin_plugin_omf; +extern RBinPlugin rz_bin_plugin_art; +extern RBinPlugin rz_bin_plugin_bootimg; +extern RBinPlugin rz_bin_plugin_dol; +extern RBinPlugin rz_bin_plugin_nes; +extern RBinPlugin rz_bin_plugin_qnx; +extern RBinPlugin rz_bin_plugin_mbn; +extern RBinPlugin rz_bin_plugin_smd; +extern RBinPlugin rz_bin_plugin_sms; +extern RBinPlugin rz_bin_plugin_psxexe; +extern RBinPlugin rz_bin_plugin_spc700; +extern RBinPlugin rz_bin_plugin_vsf; +extern RBinPlugin rz_bin_plugin_dyldcache; +extern RBinPlugin rz_bin_plugin_xnu_kernelcache; +extern RBinPlugin rz_bin_plugin_avr; +extern RBinPlugin rz_bin_plugin_menuet; +extern RBinPlugin rz_bin_plugin_wasm; +extern RBinPlugin rz_bin_plugin_nro; +extern RBinPlugin rz_bin_plugin_nso; +extern RBinPlugin rz_bin_plugin_sfc; +extern RBinPlugin rz_bin_plugin_z64; +extern RBinPlugin rz_bin_plugin_prg; +extern RBinPlugin rz_bin_plugin_dmp64; +extern RBinPlugin rz_bin_plugin_pyc; + +#ifdef __cplusplus +} +#endif + +#endif +#endif diff --git a/libr/include/r_bin_dwarf.h b/librz/include/rz_bin_dwarf.h similarity index 97% rename from libr/include/r_bin_dwarf.h rename to librz/include/rz_bin_dwarf.h index 3bbed97116..70db223a07 100644 --- a/libr/include/r_bin_dwarf.h +++ b/librz/include/rz_bin_dwarf.h @@ -834,28 +834,28 @@ typedef struct { size_t file_names_count; } RBinDwarfLineHeader; -typedef struct r_bin_dwarf_loc_entry_t { +typedef struct rz_bin_dwarf_loc_entry_t { ut64 start; ut64 end; RBinDwarfBlock *expression; } RBinDwarfLocRange; -typedef struct r_bin_dwarf_loc_list_t { - RList/**/ *list; +typedef struct rz_bin_dwarf_loc_list_t { + RzList/**/ *list; ut64 offset; } RBinDwarfLocList; -#define r_bin_dwarf_line_new(o,a,f,l) o->address=a, o->file = strdup (f?f:""), o->line = l, o->column =0,o +#define rz_bin_dwarf_line_new(o,a,f,l) o->address=a, o->file = strdup (f?f:""), o->line = l, o->column =0,o -R_API RList *r_bin_dwarf_parse_aranges(RBin *a, int mode); -R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode); -R_API RBinDwarfDebugAbbrev *r_bin_dwarf_parse_abbrev(RBin *a, int mode); -R_API RBinDwarfDebugInfo *r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *a, int mode); -R_API HtUP/**/ *r_bin_dwarf_parse_loc(RBin *bin, int addr_size); -R_API void r_bin_dwarf_print_loc(HtUP /**/ *loc_table, int addr_size, PrintfCallback print); -R_API void r_bin_dwarf_free_loc(HtUP /**/ *loc_table); -R_API void r_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf); -R_API void r_bin_dwarf_free_debug_abbrev(RBinDwarfDebugAbbrev *da); +RZ_API RzList *rz_bin_dwarf_parse_aranges(RBin *a, int mode); +RZ_API RzList *rz_bin_dwarf_parse_line(RBin *a, int mode); +RZ_API RBinDwarfDebugAbbrev *rz_bin_dwarf_parse_abbrev(RBin *a, int mode); +RZ_API RBinDwarfDebugInfo *rz_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *a, int mode); +RZ_API HtUP/**/ *rz_bin_dwarf_parse_loc(RBin *bin, int addr_size); +RZ_API void rz_bin_dwarf_print_loc(HtUP /**/ *loc_table, int addr_size, PrintfCallback print); +RZ_API void rz_bin_dwarf_free_loc(HtUP /**/ *loc_table); +RZ_API void rz_bin_dwarf_free_debug_info(RBinDwarfDebugInfo *inf); +RZ_API void rz_bin_dwarf_free_debug_abbrev(RBinDwarfDebugAbbrev *da); #ifdef __cplusplus } diff --git a/librz/include/rz_bind.h b/librz/include/rz_bind.h new file mode 100644 index 0000000000..e44df76981 --- /dev/null +++ b/librz/include/rz_bind.h @@ -0,0 +1,46 @@ +/* rizin - LGPL - Copyright 2015-2020 - pancake */ + +#ifndef R2_BIND_H +#define R2_BIND_H + +// TODO: move riobind here too? +// TODO: move rprint here too + +typedef int (*RzCoreCmd)(void *core, const char *cmd); +typedef int (*RzCoreCmdF)(void *user, const char *fmt, ...); +typedef int (*RzCoreDebugBpHit)(void *core, void *bp); +typedef void (*RzCoreDebugSyscallHit)(void *core); +typedef char* (*RzCoreCmdStr)(void *core, const char *cmd); +typedef char* (*RzCoreCmdStrF)(void *core, const char *cmd, ...); +typedef void (*RzCorePuts)(const char *cmd); +typedef void (*RzCoreSetArchBits)(void *core, const char *arch, int bits); +typedef bool (*RzCoreIsMapped)(void *core, ut64 addr, int perm); +typedef bool (*RzCoreDebugMapsSync)(void *core); +typedef const char *(*RzCoreGetName)(void *core, ut64 off); +typedef char *(*RzCoreGetNameDelta)(void *core, ut64 off); +typedef void (*RzCoreSeekArchBits)(void *core, ut64 addr); +typedef int (*RzCoreConfigGetI)(void *core, const char *key); +typedef const char *(*RzCoreConfigGet)(void *core, const char *key); +typedef ut64 (*RzCoreNumGet)(void *core, const char *str); + +typedef struct rz_core_bind_t { + void *core; + RzCoreCmd cmd; + RzCoreCmdF cmdf; + RzCoreCmdStr cmdstr; + RzCoreCmdStrF cmdstrf; + RzCorePuts puts; + RzCoreDebugBpHit bphit; + RzCoreDebugSyscallHit syshit; + RzCoreSetArchBits setab; + RzCoreGetName getName; + RzCoreGetNameDelta getNameDelta; + RzCoreSeekArchBits archbits; + RzCoreConfigGetI cfggeti; + RzCoreConfigGet cfgGet; + RzCoreNumGet numGet; + RzCoreIsMapped isMapped; + RzCoreDebugMapsSync syncDebugMaps; +} RzCoreBind; + +#endif diff --git a/librz/include/rz_binheap.h b/librz/include/rz_binheap.h new file mode 100644 index 0000000000..b583d018c9 --- /dev/null +++ b/librz/include/rz_binheap.h @@ -0,0 +1,27 @@ +#ifndef R2_BINHEAP_H +#define R2_BINHEAP_H + +#include "rz_vector.h" +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_binheap_t { + RPVector a; + RPVectorComparator cmp; +} RBinHeap; + +RZ_API void rz_binheap_clear(RBinHeap *h); +#define rz_binheap_empty(h) (rz_pvector_empty (&(h)->a)) +RZ_API void rz_binheap_init(RBinHeap *h, RPVectorComparator cmp); +RZ_API RBinHeap *rz_binheap_new(RPVectorComparator cmp); +RZ_API void rz_binheap_free(RBinHeap *h); +RZ_API bool rz_binheap_push(RBinHeap *h, void *x); +RZ_API void *rz_binheap_pop(RBinHeap *h); +#define rz_binheap_top(h) (rz_pvector_at(&((h)->a), 0)) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_bp.h b/librz/include/rz_bp.h new file mode 100644 index 0000000000..37b593edde --- /dev/null +++ b/librz/include/rz_bp.h @@ -0,0 +1,182 @@ +#ifndef R2_BP_H +#define R2_BP_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_bp); + +#define R_BP_MAXPIDS 10 +#define R_BP_CONT_NORMAL 0 +#define R_BP_CONT_NORMAL 0 + +typedef struct rz_bp_arch_t { + int bits; + int length; + int endian; + const ut8 *bytes; +} RBreakpointArch; + +enum { + R_BP_TYPE_SW, + R_BP_TYPE_HW, + R_BP_TYPE_COND, + R_BP_TYPE_FAULT, + R_BP_TYPE_DELETE, +}; + +typedef struct rz_bp_plugin_t { + char *name; + char *arch; + int type; // R_BP_TYPE_SW + int nbps; + RBreakpointArch *bps; +} RBreakpointPlugin; + +typedef struct rz_bp_item_t { + char *name; + char *module_name; /*module where you get the base address*/ + st64 module_delta; /*delta to apply to module */ + ut64 addr; + ut64 delta; + int size; /* size of breakpoint area */ + int recoil; /* recoil */ + bool swstep; /* is this breakpoint from a swstep? */ + int perm; + int hw; + int trace; + int internal; /* used for internal purposes */ + int enabled; + int togglehits; /* counter that toggles breakpoint on reaching 0 */ + int hits; + ut8 *obytes; /* original bytes */ + ut8 *bbytes; /* breakpoint bytes */ + int pids[R_BP_MAXPIDS]; + char *data; + char *cond; /* used for conditional breakpoints */ + char *expr; /* to be used for named breakpoints (see rz_debug_bp_update) */ +} RBreakpointItem; + +struct rz_bp_t; +typedef int (*RBreakpointCallback)(struct rz_bp_t *bp, RBreakpointItem *b, bool set); + +typedef struct rz_bp_t { + void *user; + int stepcont; + int endian; + int bits; + bool bpinmaps; /* Only enable breakpoints inside a valid map */ + RzCoreBind corebind; + RzIOBind iob; // compile time dependency + RBreakpointPlugin *cur; + RzList *traces; // XXX + RzList *plugins; + PrintfCallback cb_printf; + RBreakpointCallback breakpoint; + /* storage of breakpoints */ + int nbps; + int nhwbps; + RzList *bps; // list of breakpoints + RBreakpointItem **bps_idx; + int bps_idx_count; + st64 delta; + ut64 baddr; +} RBreakpoint; + +// DEPRECATED: USE R_PERM +enum { + R_BP_PROT_EXEC = 1, + R_BP_PROT_WRITE = 2, + R_BP_PROT_READ = 4, + R_BP_PROT_ACCESS = 8, +}; + +typedef struct rz_bp_trace_t { + ut64 addr; + ut64 addr_end; + ut8 *traps; + ut8 *buffer; + ut8 *bits; + int length; + int bitlen; +} RBreakpointTrace; + +#ifdef RZ_API +RZ_API RBreakpoint *rz_bp_new(void); +RZ_API RBreakpoint *rz_bp_free(RBreakpoint *bp); + +RZ_API int rz_bp_del(RBreakpoint *bp, ut64 addr); +RZ_API int rz_bp_del_all(RBreakpoint *bp); + +RZ_API int rz_bp_plugin_add(RBreakpoint *bp, RBreakpointPlugin *foo); +RZ_API int rz_bp_use(RBreakpoint *bp, const char *name, int bits); +RZ_API int rz_bp_plugin_del(RBreakpoint *bp, const char *name); +RZ_API void rz_bp_plugin_list(RBreakpoint *bp); + +RZ_API int rz_bp_in(RBreakpoint *bp, ut64 addr, int perm); +// deprecate? +RZ_API int rz_bp_list(RBreakpoint *bp, int rad); +RZ_API int rz_bp_size(RBreakpoint *bp); + +/* bp item attribs setters */ +RZ_API int rz_bp_get_bytes(RBreakpoint *bp, ut8 *buf, int len, int endian, int idx); +RZ_API int rz_bp_set_trace(RBreakpoint *bp, ut64 addr, int set); +RZ_API int rz_bp_set_trace_all(RBreakpoint *bp, int set); +RZ_API RBreakpointItem *rz_bp_enable(RBreakpoint *bp, ut64 addr, int set, int count); +RZ_API int rz_bp_enable_all(RBreakpoint *bp, int set); + +/* index api */ +RZ_API int rz_bp_del_index(RBreakpoint *bp, int idx); +RZ_API RBreakpointItem *rz_bp_get_index(RBreakpoint *bp, int idx); +RZ_API int rz_bp_get_index_at (RBreakpoint *bp, ut64 addr); +RZ_API RBreakpointItem *rz_bp_item_new (RBreakpoint *bp); + +RZ_API RBreakpointItem *rz_bp_get_at (RBreakpoint *bp, ut64 addr); +RZ_API RBreakpointItem *rz_bp_get_in (RBreakpoint *bp, ut64 addr, int perm); + +RZ_API bool rz_bp_is_valid(RBreakpoint *bp, RBreakpointItem *b); + +RZ_API int rz_bp_add_cond(RBreakpoint *bp, const char *cond); +RZ_API int rz_bp_del_cond(RBreakpoint *bp, int idx); +RZ_API int rz_bp_add_fault(RBreakpoint *bp, ut64 addr, int size, int perm); + +RZ_API RBreakpointItem *rz_bp_add_sw(RBreakpoint *bp, ut64 addr, int size, int perm); +RZ_API RBreakpointItem *rz_bp_add_hw(RBreakpoint *bp, ut64 addr, int size, int perm); +RZ_API void rz_bp_restore_one(RBreakpoint *bp, RBreakpointItem *b, bool set); +RZ_API int rz_bp_restore(RBreakpoint *bp, bool set); +RZ_API bool rz_bp_restore_except(RBreakpoint *bp, bool set, ut64 addr); + +/* traptrace */ +RZ_API void rz_bp_traptrace_free(void *ptr); +RZ_API void rz_bp_traptrace_enable(RBreakpoint *bp, int enable); +RZ_API void rz_bp_traptrace_reset(RBreakpoint *bp, int hard); +RZ_API ut64 rz_bp_traptrace_next(RBreakpoint *bp, ut64 addr); +RZ_API int rz_bp_traptrace_add(RBreakpoint *bp, ut64 from, ut64 to); +RZ_API int rz_bp_traptrace_free_at(RBreakpoint *bp, ut64 from); +RZ_API void rz_bp_traptrace_list(RBreakpoint *bp); +RZ_API int rz_bp_traptrace_at(RBreakpoint *bp, ut64 from, int len); +RZ_API RzList *rz_bp_traptrace_new(void); +RZ_API void rz_bp_traptrace_enable(RBreakpoint *bp, int enable); + +/* watchpoint */ +RZ_API RBreakpointItem *rz_bp_watch_add(RBreakpoint *bp, ut64 addr, int size, int hw, int rw); + +/* plugin pointers */ +extern RBreakpointPlugin rz_bp_plugin_x86; +extern RBreakpointPlugin rz_bp_plugin_arm; +extern RBreakpointPlugin rz_bp_plugin_mips; +extern RBreakpointPlugin rz_bp_plugin_ppc; +extern RBreakpointPlugin rz_bp_plugin_sh; +extern RBreakpointPlugin rz_bp_plugin_bf; +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_cmd.h b/librz/include/rz_cmd.h new file mode 100644 index 0000000000..a51b8d0208 --- /dev/null +++ b/librz/include/rz_cmd.h @@ -0,0 +1,314 @@ +#ifndef R2_CMD_H +#define R2_CMD_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_core_t RzCore; + +//R_LIB_VERSION_HEADER (rz_cmd); + +#define MACRO_LIMIT 1024 +#define MACRO_LABELS 20 +#define R_CMD_MAXLEN 4096 + +typedef enum rz_cmd_status_t { + R_CMD_STATUS_OK = 0, // command handler exited in the right way + R_CMD_STATUS_WRONG_ARGS, // command handler could not handle the arguments passed to it + R_CMD_STATUS_ERROR, // command handler had issues while running (e.g. allocation error, etc.) + R_CMD_STATUS_INVALID, // command could not be executed (e.g. shell level error, not existing command, bad expression, etc.) + R_CMD_STATUS_EXIT, // command handler asks to exit the prompt loop +} RzCmdStatus; + +typedef int (*RzCmdCb) (void *user, const char *input); +typedef RzCmdStatus (*RzCmdArgvCb) (RzCore *core, int argc, const char **argv); +typedef int (*RzCmdNullCb) (void *user); + +typedef struct rz_cmd_parsed_args_t { + int argc; + char **argv; + bool has_space_after_cmd; +} RzCmdParsedArgs; + +typedef struct rz_cmd_macro_label_t { + char name[80]; + char *ptr; +} RzCmdMacroLabel; + +typedef struct rz_cmd_macro_item_t { + char *name; + char *args; + char *code; + int codelen; + int nargs; +} RzCmdMacroItem; + +typedef struct rz_cmd_macro_t { + int counter; + ut64 *brk_value; + ut64 _brk_value; + int brk; +// int (*cmd)(void *user, const char *cmd); + RzCoreCmd cmd; + PrintfCallback cb_printf; + void *user; + RNum *num; + int labels_n; + RzCmdMacroLabel labels[MACRO_LABELS]; + RzList *macros; +} RzCmdMacro; + +typedef struct rz_cmd_item_t { + char cmd[64]; + RzCmdCb callback; +} RzCmdItem; + +typedef struct rz_cmd_alias_t { + int count; + char **keys; + char **values; + int *remote; +} RzCmdAlias; + +typedef struct rz_cmd_desc_example_t { + const char *example; + const char *comment; +} RzCmdDescExample; + +/** + * Define how the command looks like in the help. + */ +typedef struct rz_cmd_desc_help_t { + /** + * Short-sentence explaining what the command does. + * This is shown, for example, when the list of sub-commands is printed + * and each sub-command has a very short description on the right, + * explaining what it does. + */ + const char *summary; + /** + * Long description of what the command does. It can be as long as you + * want and it should explain well how the command behaves. + * This is shown, for example, when `??` is appended on command or `?` + * is appended and the command has no children to show. In that case, + * the short summary is extended with this longer description. + * + * Optional. + */ + const char *description; + /** + * String used to identify the arguments. This usually comes together + * with the summary. + * TODO: explain how to differentiate between required and optional arguments + */ + const char *args_str; + /** + * String that overrides the name+args_str usually used to describe the + * command. + * + * Optional. + */ + const char *usage; + /** + * String to use as sub-commands suggestions instead of the + * auto-generated one (e.g. [abcd] or [?] that you can see near command + * names when doing `w?`). If not provided, the options will be + * auto-generated. + * + * Optional. + */ + const char *options; + /** + * List of examples used to better explain how to use the command. This + * is shown together with the long description. + * + * Optional. + */ + const RzCmdDescExample *examples; +} RzCmdDescHelp; + +typedef enum { + // for old handlers that parse their own input and accept a single string + R_CMD_DESC_TYPE_OLDINPUT = 0, + // for handlers that accept argc/argv + R_CMD_DESC_TYPE_ARGV, + // for cmd descriptors that are just used to group together related + // sub-commands. Do not use this if the command can be used by itself or + // if it's necessary to show its help, because this descriptor is not + // stored in the hashtable and cannot be retrieved except by listing the + // children of its parent. + R_CMD_DESC_TYPE_INNER, + // for cmd descriptors that are parent of other sub-commands but that + // may also have a sub-command with the same name. For example, `wc` is + // both the parent of `wci`, `wc*`, etc. but there is also `wc` as a + // sub-command. + R_CMD_DESC_TYPE_GROUP, +} RzCmdDescType; + +typedef struct rz_cmd_desc_t { + RzCmdDescType type; + char *name; + struct rz_cmd_desc_t *parent; + int n_children; + RPVector children; + const RzCmdDescHelp *help; + + union { + struct { + RzCmdCb cb; + } oldinput_data; + struct { + RzCmdArgvCb cb; + } argv_data; + struct { + struct rz_cmd_desc_t *exec_cd; + } group_data; + } d; +} RzCmdDesc; + +typedef struct rz_cmd_t { + void *data; + RzCmdNullCb nullcallback; + RzCmdItem *cmds[UT8_MAX]; + RzCmdMacro macro; + RzList *lcmds; + RzList *plist; + RzCmdAlias aliases; + void *language; // used to store TSLanguage * + HtUP *ts_symbols_ht; + RzCmdDesc *root_cmd_desc; + HtPP *ht_cmds; +} RzCmd; + +// TODO: remove this once transitioned to RzCmdDesc +typedef struct rz_cmd_descriptor_t { + const char *cmd; + const char **help_msg; + const char **help_detail; + const char **help_detail2; + struct rz_cmd_descriptor_t *sub[127]; +} RzCmdDescriptor; + +// TODO: move into rz_core.h +typedef struct rz_core_plugin_t { + const char *name; + const char *desc; + const char *license; + const char *author; + const char *version; + RzCmdCb call; // returns true if command was handled, false otherwise. + RzCmdCb init; + RzCmdCb fini; +} RzCorePlugin; + +#define DEFINE_CMD_ARGV_DESC_DETAIL(core, name, c_name, parent, handler, help) \ + RzCmdDesc *c_name##_cd = rz_cmd_desc_argv_new (core->rcmd, parent, #name, handler, help); \ + rz_warn_if_fail (c_name##_cd) +#define DEFINE_CMD_ARGV_DESC_SPECIAL(core, name, c_name, parent) \ + DEFINE_CMD_ARGV_DESC_DETAIL (core, name, c_name, parent, c_name##_handler, &c_name##_help) +#define DEFINE_CMD_ARGV_DESC_INNER(core, name, c_name, parent) \ + RzCmdDesc *c_name##_cd = rz_cmd_desc_inner_new (core->rcmd, parent, #name, &c_name##_help); \ + rz_warn_if_fail (c_name##_cd) +#define DEFINE_CMD_ARGV_GROUP_WITH_CHILD(core, name, parent) \ + RzCmdDesc *name##_cd = rz_cmd_desc_group_new (core->rcmd, parent, #name, name##_handler, &name##_help, &name##_group_help); \ + rz_warn_if_fail (name##_cd) +#define DEFINE_CMD_ARGV_DESC(core, name, parent) \ + DEFINE_CMD_ARGV_DESC_SPECIAL (core, name, name, parent) +#define DEFINE_CMD_OLDINPUT_DESC(core, name, parent) \ + RzCmdDesc *name##_cd = rz_cmd_desc_oldinput_new (core->rcmd, parent, #name, name##_handler_old, &name##_help); \ + rz_warn_if_fail (name##_cd) + +#ifdef RZ_API +RZ_API int rz_core_plugin_init(RzCmd *cmd); +RZ_API int rz_core_plugin_add(RzCmd *cmd, RzCorePlugin *plugin); +RZ_API int rz_core_plugin_check(RzCmd *cmd, const char *a0); +RZ_API int rz_core_plugin_fini(RzCmd *cmd); + +RZ_API RzCmd *rz_cmd_new(void); +RZ_API RzCmd *rz_cmd_free(RzCmd *cmd); +RZ_API int rz_cmd_set_data(RzCmd *cmd, void *data); +RZ_API int rz_cmd_add(RzCmd *cmd, const char *command, RzCmdCb callback); +RZ_API int rz_core_del(RzCmd *cmd, const char *command); +RZ_API int rz_cmd_call(RzCmd *cmd, const char *command); +RZ_API RzCmdStatus rz_cmd_call_parsed_args(RzCmd *cmd, RzCmdParsedArgs *args); +RZ_API RzCmdDesc *rz_cmd_get_root(RzCmd *cmd); +RZ_API RzCmdDesc *rz_cmd_get_desc(RzCmd *cmd, const char *cmd_identifier); +RZ_API char *rz_cmd_get_help(RzCmd *cmd, RzCmdParsedArgs *args, bool use_color); + +static inline RzCmdStatus rz_cmd_int2status(int v) { + if (v == -2) { + return R_CMD_STATUS_EXIT; + } else if (v < 0) { + return R_CMD_STATUS_ERROR; + } else { + return R_CMD_STATUS_OK; + } +} + +static inline int rz_cmd_status2int(RzCmdStatus s) { + switch (s) { + case R_CMD_STATUS_OK: + return 0; + case R_CMD_STATUS_ERROR: + case R_CMD_STATUS_WRONG_ARGS: + case R_CMD_STATUS_INVALID: + return -1; + case R_CMD_STATUS_EXIT: + default: + return -2; + } +} + +/* RzCmdDescriptor */ +RZ_API RzCmdDesc *rz_cmd_desc_argv_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help); +RZ_API RzCmdDesc *rz_cmd_desc_inner_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, const RzCmdDescHelp *help); +RZ_API RzCmdDesc *rz_cmd_desc_group_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdArgvCb cb, const RzCmdDescHelp *help, const RzCmdDescHelp *group_help); +RZ_API RzCmdDesc *rz_cmd_desc_oldinput_new(RzCmd *cmd, RzCmdDesc *parent, const char *name, RzCmdCb cb, const RzCmdDescHelp *help); +RZ_API RzCmdDesc *rz_cmd_desc_parent(RzCmdDesc *cd); +RZ_API bool rz_cmd_desc_has_handler(RzCmdDesc *cd); +RZ_API bool rz_cmd_desc_remove(RzCmd *cmd, RzCmdDesc *cd); + +#define rz_cmd_desc_children_foreach(root, it_cd) rz_pvector_foreach (&root->children, it_cd) + +/* RzCmdParsedArgs */ +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_new(const char *cmd, int n_args, char **args); +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_newcmd(const char *cmd); +RZ_API RzCmdParsedArgs *rz_cmd_parsed_args_newargs(int n_args, char **args); +RZ_API void rz_cmd_parsed_args_free(RzCmdParsedArgs *args); +RZ_API bool rz_cmd_parsed_args_setargs(RzCmdParsedArgs *arg, int n_args, char **args); +RZ_API bool rz_cmd_parsed_args_setcmd(RzCmdParsedArgs *arg, const char *cmd); +RZ_API char *rz_cmd_parsed_args_argstr(RzCmdParsedArgs *arg); +RZ_API char *rz_cmd_parsed_args_execstr(RzCmdParsedArgs *arg); +RZ_API const char *rz_cmd_parsed_args_cmd(RzCmdParsedArgs *arg); + +#define rz_cmd_parsed_args_foreach_arg(args, i, arg) for ((i) = 1; (i) < (args->argc) && ((arg) = (args)->argv[i]); (i)++) + +/* rz_cmd_macro */ +RZ_API RzCmdMacroItem *rz_cmd_macro_item_new(void); +RZ_API void rz_cmd_macro_item_free(RzCmdMacroItem *item); +RZ_API void rz_cmd_macro_init(RzCmdMacro *mac); +RZ_API int rz_cmd_macro_add(RzCmdMacro *mac, const char *name); +RZ_API int rz_cmd_macro_rm(RzCmdMacro *mac, const char *_name); +RZ_API void rz_cmd_macro_list(RzCmdMacro *mac); +RZ_API void rz_cmd_macro_meta(RzCmdMacro *mac); +RZ_API int rz_cmd_macro_call(RzCmdMacro *mac, const char *name); +RZ_API int rz_cmd_macro_break(RzCmdMacro *mac, const char *value); + +RZ_API bool rz_cmd_alias_del(RzCmd *cmd, const char *k); +RZ_API char **rz_cmd_alias_keys(RzCmd *cmd, int *sz); +RZ_API int rz_cmd_alias_set(RzCmd *cmd, const char *k, const char *v, int remote); +RZ_API char *rz_cmd_alias_get(RzCmd *cmd, const char *k, int remote); +RZ_API void rz_cmd_alias_free(RzCmd *cmd); +RZ_API void rz_cmd_macro_fini(RzCmdMacro *mac); + +#ifdef __cplusplus +} +#endif + +#endif +#endif diff --git a/librz/include/rz_config.h b/librz/include/rz_config.h new file mode 100644 index 0000000000..5e3ca13275 --- /dev/null +++ b/librz/include/rz_config.h @@ -0,0 +1,122 @@ +#ifndef R2_CONFIG_H +#define R2_CONFIG_H + +#include "rz_types.h" +#include "rz_util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_config); + +#define CN_BOOL 0x000001 +#define CN_INT 0x000002 +// NOTE: removed because this is redundant and it does not add any value +// compared to CN_INT. Use that instead for consistency +// #define CN_OFFT 0x000004 +#define CN_STR 0x000008 +#define CN_RO 0x000010 +#define CN_RW 0x000020 + +typedef bool (*RConfigCallback)(void *user, void *data); + +typedef struct rz_config_node_t { + char *name; + int flags; + char *value; + ut64 i_value; + ut64 *cb_ptr_q; + int *cb_ptr_i; + char **cb_ptr_s; + RConfigCallback getter; + RConfigCallback setter; + char *desc; + RzList *options; +} RConfigNode; + +RZ_API const char *rz_config_node_type(RConfigNode *node); + +typedef struct rz_config_t { + int lock; + void *user; + RNum *num; + PrintfCallback cb_printf; + RzList *nodes; + HtPP *ht; +} RConfig; + +typedef struct rz_config_hold_num_t { + char *key; + ut64 value; +} RConfigHoldNum; + +typedef struct rz_config_hold_char_t { + char *key; + char *value; +} RConfigHoldChar; + +typedef struct rz_config_hold_t { + RConfig *cfg; + RzList *list_num; //list of RConfigHoldNum to hold numeric values + RzList *list_char; //list of RConfigHoldChar to hold char values +} RConfigHold; + +#ifdef RZ_API +RZ_API RConfigHold* rz_config_hold_new(RConfig *cfg); +RZ_API void rz_config_hold_free(RConfigHold *h); + +RZ_API bool rz_config_hold_i(RConfigHold *h, ...); +RZ_API bool rz_config_hold_s(RConfigHold *h, ...); + +RZ_API void rz_config_hold_restore(RConfigHold *h); + +RZ_API RConfig *rz_config_new(void *user); +RZ_API RConfig *rz_config_clone (RConfig *cfg); +RZ_API void rz_config_free(RConfig *cfg); +RZ_API void rz_config_lock(RConfig *cfg, int l); +RZ_API bool rz_config_eval(RConfig *cfg, const char *str, bool many); +RZ_API void rz_config_bump(RConfig *cfg, const char *key); +RZ_API RConfigNode *rz_config_set_i(RConfig *cfg, const char *name, const ut64 i); +RZ_API RConfigNode *rz_config_set_cb(RConfig *cfg, const char *name, const char *value, bool (*callback)(void *user, void *data)); +RZ_API RConfigNode *rz_config_set_i_cb(RConfig *cfg, const char *name, int ivalue, bool (*callback)(void *user, void *data)); +RZ_API RConfigNode *rz_config_set(RConfig *cfg, const char *name, const char *value); +RZ_API bool rz_config_rm(RConfig *cfg, const char *name); +RZ_API ut64 rz_config_get_i(RConfig *cfg, const char *name); +RZ_API const char *rz_config_get(RConfig *cfg, const char *name); +RZ_API const char *rz_config_desc(RConfig *cfg, const char *name, const char *desc); +RZ_API const char *rz_config_node_desc(RConfigNode *node, const char *desc); +RZ_API void rz_config_list(RConfig *cfg, const char *str, int rad); +RZ_API RConfigNode *rz_config_node_get(RConfig *cfg, const char *name); +RZ_API RConfigNode *rz_config_node_new(const char *name, const char *value); +RZ_API void rz_config_node_free(void *n); +RZ_API void rz_config_node_value_format_i(char *buf, size_t buf_size, const ut64 i, R_NULLABLE RConfigNode *node); +RZ_API bool rz_config_toggle(RConfig *cfg, const char *name); +RZ_API bool rz_config_readonly (RConfig *cfg, const char *key); + +RZ_API void rz_config_set_sort_column (char *column); +RZ_API bool rz_config_set_setter (RConfig *cfg, const char *key, RConfigCallback cb); +RZ_API bool rz_config_set_getter (RConfig *cfg, const char *key, RConfigCallback cb); + +RZ_API void rz_config_serialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db); +RZ_API bool rz_config_unserialize(R_NONNULL RConfig *config, R_NONNULL Sdb *db, R_NULLABLE char **err); + +static inline bool rz_config_node_is_bool(RConfigNode *node) { + return node->flags & CN_BOOL; +} +static inline bool rz_config_node_is_int(RConfigNode *node) { + return node->flags & CN_INT; +} +static inline bool rz_config_node_is_ro(RConfigNode *node) { + return node->flags & CN_RO; +} +static inline bool rz_config_node_is_str(RConfigNode *node) { + return node->flags & CN_STR; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_cons.h b/librz/include/rz_cons.h similarity index 63% rename from libr/include/r_cons.h rename to librz/include/rz_cons.h index aecb0ceba0..be0bdc3c98 100644 --- a/libr/include/r_cons.h +++ b/librz/include/rz_cons.h @@ -5,21 +5,21 @@ extern "C" { #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -60,26 +60,26 @@ extern "C" { #define R_CONS_GREP_WORD_SIZE 64 #define R_CONS_GREP_TOKENS 64 -R_LIB_VERSION_HEADER(r_cons); +R_LIB_VERSION_HEADER(rz_cons); #define R_CONS_CMD_DEPTH 100 -typedef int (*RConsGetSize)(int *rows); -typedef int (*RConsGetCursor)(int *rows); -typedef bool (*RConsIsBreaked)(void); -typedef void (*RConsFlush)(void); -typedef void (*RConsGrepCallback)(const char *grep); +typedef int (*RzConsGetSize)(int *rows); +typedef int (*RzConsGetCursor)(int *rows); +typedef bool (*RzConsIsBreaked)(void); +typedef void (*RzConsFlush)(void); +typedef void (*RzConsGrepCallback)(const char *grep); -typedef struct r_cons_bind_t { - RConsGetSize get_size; - RConsGetCursor get_cursor; +typedef struct rz_cons_bind_t { + RzConsGetSize get_size; + RzConsGetCursor get_cursor; PrintfCallback cb_printf; - RConsIsBreaked is_breaked; - RConsFlush cb_flush; - RConsGrepCallback cb_grep; -} RConsBind; + RzConsIsBreaked is_breaked; + RzConsFlush cb_flush; + RzConsGrepCallback cb_grep; +} RzConsBind; -typedef struct r_cons_grep_t { +typedef struct rz_cons_grep_t { char strings[R_CONS_GREP_WORDS][R_CONS_GREP_WORD_SIZE]; int nstrings; char *str; @@ -106,11 +106,11 @@ typedef struct r_cons_grep_t { int begin; int end; int icase; -} RConsGrep; +} RzConsGrep; #if 0 -// TODO Might be better than using r_cons_pal_get_i -// And have smaller RConsPrintablePalette and RConsPalette +// TODO Might be better than using rz_cons_pal_get_i +// And have smaller RzConsPrintablePalette and RzConsPalette enum { R_CONS_PAL_0x00 = 0, R_CONS_PAL_0x7f, @@ -195,7 +195,7 @@ typedef struct rcolor_t { st8 id16; // Mapping to 16-color table } RColor; -typedef struct r_cons_palette_t { +typedef struct rz_cons_palette_t { RColor b0x00; RColor b0x7f; RColor b0xff; @@ -268,9 +268,9 @@ typedef struct r_cons_palette_t { RColor graph_diff_unmatch; RColor graph_diff_unknown; RColor graph_diff_new; -} RConsPalette; +} RzConsPalette; -typedef struct r_cons_printable_palette_t { +typedef struct rz_cons_printable_palette_t { char *b0x00; char *b0x7f; char *b0xff; @@ -346,13 +346,13 @@ typedef struct r_cons_printable_palette_t { char *graph_current; char **rainbow; // rainbow int rainbow_sz; // size of rainbow -} RConsPrintablePalette; +} RzConsPrintablePalette; -typedef void (*RConsEvent)(void *); +typedef void (*RzConsEvent)(void *); #define CONS_MAX_ATTR_SZ 16 -typedef struct r_cons_canvas_t { +typedef struct rz_cons_canvas_t { int w; int h; int x; @@ -367,7 +367,7 @@ typedef struct r_cons_canvas_t { int sy; // scrolly int color; int linemode; // 0 = diagonal , 1 = square -} RConsCanvas; +} RzConsCanvas; #define RUNECODE_MIN 0xc8 // 200 #define RUNECODE_LINE_VERT 0xc8 @@ -433,18 +433,18 @@ typedef struct r_cons_canvas_t { // Variation Selectors #define UTF8_VS16 "\xef\xb8\x8f" -typedef char *(*RConsEditorCallback)(void *core, const char *file, const char *str); -typedef int (*RConsClickCallback)(void *core, int x, int y); -typedef void (*RConsBreakCallback)(void *core); -typedef void *(*RConsSleepBeginCallback)(void *core); -typedef void (*RConsSleepEndCallback)(void *core, void *user); -typedef void (*RConsQueueTaskOneshot)(void *core, void *task, void *user); -typedef void (*RConsFunctionKey)(void *core, int fkey); +typedef char *(*RzConsEditorCallback)(void *core, const char *file, const char *str); +typedef int (*RzConsClickCallback)(void *core, int x, int y); +typedef void (*RzConsBreakCallback)(void *core); +typedef void *(*RzConsSleepBeginCallback)(void *core); +typedef void (*RzConsSleepEndCallback)(void *core, void *user); +typedef void (*RzConsQueueTaskOneshot)(void *core, void *task, void *user); +typedef void (*RzConsFunctionKey)(void *core, int fkey); -typedef enum { COLOR_MODE_DISABLED = 0, COLOR_MODE_16, COLOR_MODE_256, COLOR_MODE_16M } RConsColorMode; +typedef enum { COLOR_MODE_DISABLED = 0, COLOR_MODE_16, COLOR_MODE_256, COLOR_MODE_16M } RzConsColorMode; -typedef struct r_cons_context_t { - RConsGrep grep; +typedef struct rz_cons_context_t { + RzConsGrep grep; RStack *cons_stack; char *buffer; size_t buffer_len; @@ -452,12 +452,12 @@ typedef struct r_cons_context_t { bool breaked; RStack *break_stack; - RConsEvent event_interrupt; + RzConsEvent event_interrupt; void *event_interrupt_data; int cmd_depth; // Used for per-task logging redirection - RLogCallback log_callback; // TODO: RList of callbacks + RLogCallback log_callback; // TODO: RzList of callbacks char *lastOutput; int lastLength; @@ -467,14 +467,14 @@ typedef struct r_cons_context_t { bool pageable; int color_mode; - RConsPalette cpal; - RConsPrintablePalette pal; -} RConsContext; + RzConsPalette cpal; + RzConsPrintablePalette pal; +} RzConsContext; #define HUD_BUF_SIZE 512 -typedef struct r_cons_t { - RConsContext *context; +typedef struct rz_cons_t { + RzConsContext *context; char *lastline; bool is_html; bool was_html; @@ -494,19 +494,19 @@ typedef struct r_cons_t { int fdout; // only used in pipe.c :?? remove? const char *teefile; int (*user_fgets)(char *buf, int len); - RConsEvent event_resize; + RzConsEvent event_resize; void *event_data; int mouse_event; - RConsEditorCallback cb_editor; - RConsBreakCallback cb_break; - RConsSleepBeginCallback cb_sleep_begin; - RConsSleepEndCallback cb_sleep_end; - RConsClickCallback cb_click; - RConsQueueTaskOneshot cb_task_oneshot; - RConsFunctionKey cb_fkey; + RzConsEditorCallback cb_editor; + RzConsBreakCallback cb_break; + RzConsSleepBeginCallback cb_sleep_begin; + RzConsSleepEndCallback cb_sleep_end; + RzConsClickCallback cb_click; + RzConsQueueTaskOneshot cb_task_oneshot; + RzConsFunctionKey cb_fkey; - void *user; // Used by + void *user; // Used by #if __UNIX__ struct termios term_raw, term_buf; #elif __WINDOWS__ @@ -523,7 +523,7 @@ typedef struct r_cons_t { int null; // if set, does not show anything int mouse; int is_wine; - struct r_line_t *line; + struct rz_line_t *line; const char **vline; int refcnt; R_DEPRECATE bool newline; @@ -536,7 +536,7 @@ typedef struct r_cons_t { int pagesize; char *break_word; int break_word_len; - ut64 timeout; // must come from r_time_now_mono() + ut64 timeout; // must come from rz_time_now_mono() bool grep_color; bool grep_highlight; bool use_tts; @@ -547,18 +547,18 @@ typedef struct r_cons_t { int click_y; bool show_vals; // show which section in Vv // TODO: move into instance? + avoid unnecessary copies -} RCons; +} RzCons; -// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RCons */ +// XXX THIS MUST BE A SINGLETON AND WRAPPED INTO RzCons */ /* XXX : global variables? or a struct with a singleton? */ //extern FILE *stdin_fd; -//extern FILE *r_cons_stdin_fd; -//extern int r_cons_stdout_fd; -//extern int r_cons_stdout_file; -//extern char *r_cons_filterline; -//extern char *r_cons_teefile; +//extern FILE *rz_cons_stdin_fd; +//extern int rz_cons_stdout_fd; +//extern int rz_cons_stdout_file; +//extern char *rz_cons_filterline; +//extern char *rz_cons_teefile; // not needed anymoar -//extern int (*r_cons_user_fgets)(char *buf, int len); +//extern int (*rz_cons_user_fgets)(char *buf, int len); #define R_CONS_KEY_F1 0xf1 #define R_CONS_KEY_F2 0xf2 @@ -764,7 +764,7 @@ typedef enum { #define DOT_STYLE_CONDITIONAL 1 #define DOT_STYLE_BACKEDGE 2 -typedef struct r_cons_canvas_line_style_t { +typedef struct rz_cons_canvas_line_style_t { int color; int symbol; int dot_style; @@ -797,204 +797,204 @@ typedef struct r_cons_canvas_line_style_t { #endif -#ifdef R_API -R_API void r_cons_image(const ut8 *buf, int bufsz, int width, int mode); -R_API RConsCanvas* r_cons_canvas_new(int w, int h); -R_API void r_cons_canvas_free(RConsCanvas *c); -R_API void r_cons_canvas_clear(RConsCanvas *c); -R_API void r_cons_canvas_print(RConsCanvas *c); -R_API void r_cons_canvas_print_region(RConsCanvas *c); -R_API char *r_cons_canvas_to_string(RConsCanvas *c); -R_API void r_cons_canvas_attr(RConsCanvas *c,const char * attr); -R_API void r_cons_canvas_write(RConsCanvas *c, const char *_s); -R_API bool r_cons_canvas_gotoxy(RConsCanvas *c, int x, int y); -R_API void r_cons_canvas_goto_write(RConsCanvas *c,int x,int y, const char * s); -R_API void r_cons_canvas_box(RConsCanvas *c, int x, int y, int w, int h, const char *color); -R_API void r_cons_canvas_circle(RConsCanvas *c, int x, int y, int w, int h, const char *color); -R_API void r_cons_canvas_line(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); -R_API void r_cons_canvas_line_diagonal(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); -R_API void r_cons_canvas_line_square(RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); -R_API int r_cons_canvas_resize(RConsCanvas *c, int w, int h); -R_API void r_cons_canvas_fill(RConsCanvas *c, int x, int y, int w, int h, char ch); -R_API void r_cons_canvas_line_square_defined (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int bendpoint, int isvert); -R_API void r_cons_canvas_line_back_edge (RConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int ybendpoint1, int xbendpoint, int ybendpoint2, int isvert); -R_API RCons *r_cons_new(void); -R_API RCons *r_cons_singleton(void); -R_API RCons *r_cons_free(void); -R_API char *r_cons_lastline(int *size); -R_API char *r_cons_lastline_utf8_ansi_len(int *len); -R_API void r_cons_set_click(int x, int y); -R_API bool r_cons_get_click(int *x, int *y); +#ifdef RZ_API +RZ_API void rz_cons_image(const ut8 *buf, int bufsz, int width, int mode); +RZ_API RzConsCanvas* rz_cons_canvas_new(int w, int h); +RZ_API void rz_cons_canvas_free(RzConsCanvas *c); +RZ_API void rz_cons_canvas_clear(RzConsCanvas *c); +RZ_API void rz_cons_canvas_print(RzConsCanvas *c); +RZ_API void rz_cons_canvas_print_region(RzConsCanvas *c); +RZ_API char *rz_cons_canvas_to_string(RzConsCanvas *c); +RZ_API void rz_cons_canvas_attr(RzConsCanvas *c,const char * attr); +RZ_API void rz_cons_canvas_write(RzConsCanvas *c, const char *_s); +RZ_API bool rz_cons_canvas_gotoxy(RzConsCanvas *c, int x, int y); +RZ_API void rz_cons_canvas_goto_write(RzConsCanvas *c,int x,int y, const char * s); +RZ_API void rz_cons_canvas_box(RzConsCanvas *c, int x, int y, int w, int h, const char *color); +RZ_API void rz_cons_canvas_circle(RzConsCanvas *c, int x, int y, int w, int h, const char *color); +RZ_API void rz_cons_canvas_line(RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); +RZ_API void rz_cons_canvas_line_diagonal(RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); +RZ_API void rz_cons_canvas_line_square(RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style); +RZ_API int rz_cons_canvas_resize(RzConsCanvas *c, int w, int h); +RZ_API void rz_cons_canvas_fill(RzConsCanvas *c, int x, int y, int w, int h, char ch); +RZ_API void rz_cons_canvas_line_square_defined (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int bendpoint, int isvert); +RZ_API void rz_cons_canvas_line_back_edge (RzConsCanvas *c, int x, int y, int x2, int y2, RCanvasLineStyle *style, int ybendpoint1, int xbendpoint, int ybendpoint2, int isvert); +RZ_API RzCons *rz_cons_new(void); +RZ_API RzCons *rz_cons_singleton(void); +RZ_API RzCons *rz_cons_free(void); +RZ_API char *rz_cons_lastline(int *size); +RZ_API char *rz_cons_lastline_utf8_ansi_len(int *len); +RZ_API void rz_cons_set_click(int x, int y); +RZ_API bool rz_cons_get_click(int *x, int *y); -typedef void (*RConsBreak)(void *); -R_API bool r_cons_is_breaked(void); -R_API bool r_cons_is_interactive(void); -R_API bool r_cons_default_context_is_interactive(void); -R_API void *r_cons_sleep_begin(void); -R_API void r_cons_sleep_end(void *user); +typedef void (*RzConsBreak)(void *); +RZ_API bool rz_cons_is_breaked(void); +RZ_API bool rz_cons_is_interactive(void); +RZ_API bool rz_cons_default_context_is_interactive(void); +RZ_API void *rz_cons_sleep_begin(void); +RZ_API void rz_cons_sleep_end(void *user); /* ^C */ -R_API void r_cons_break_push(RConsBreak cb, void *user); -R_API void r_cons_break_pop(void); -R_API void r_cons_break_clear(void); -R_API void r_cons_breakword(const char *s); -R_API void r_cons_break_end(void); -R_API void r_cons_break_timeout(int timeout); +RZ_API void rz_cons_break_push(RzConsBreak cb, void *user); +RZ_API void rz_cons_break_pop(void); +RZ_API void rz_cons_break_clear(void); +RZ_API void rz_cons_breakword(const char *s); +RZ_API void rz_cons_break_end(void); +RZ_API void rz_cons_break_timeout(int timeout); /* pipe */ -R_API int r_cons_pipe_open(const char *file, int fdn, int append); -R_API void r_cons_pipe_close(int fd); +RZ_API int rz_cons_pipe_open(const char *file, int fdn, int append); +RZ_API void rz_cons_pipe_close(int fd); #if __WINDOWS__ -R_API int r_cons_is_vtcompat(void); -R_API void r_cons_w32_clear(void); -R_API void r_cons_w32_gotoxy(int fd, int x, int y); -R_API int r_cons_w32_print(const char *ptr, int len, bool vmode); -R_API int r_cons_win_printf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API int r_cons_win_eprintf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3); -R_API int r_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap); +RZ_API int rz_cons_is_vtcompat(void); +RZ_API void rz_cons_w32_clear(void); +RZ_API void rz_cons_w32_gotoxy(int fd, int x, int y); +RZ_API int rz_cons_w32_print(const char *ptr, int len, bool vmode); +RZ_API int rz_cons_win_printf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API int rz_cons_win_eprintf(bool vmode, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API int rz_cons_win_vhprintf(DWORD hdl, bool vmode, const char *fmt, va_list ap); #endif -R_API void r_cons_push(void); -R_API void r_cons_pop(void); -R_API RConsContext *r_cons_context_new(R_NULLABLE RConsContext *parent); -R_API void r_cons_context_free(RConsContext *context); -R_API void r_cons_context_load(RConsContext *context); -R_API void r_cons_context_reset(void); -R_API bool r_cons_context_is_main(void); -R_API void r_cons_context_break(RConsContext *context); -R_API void r_cons_context_break_push(RConsContext *context, RConsBreak cb, void *user, bool sig); -R_API void r_cons_context_break_pop(RConsContext *context, bool sig); +RZ_API void rz_cons_push(void); +RZ_API void rz_cons_pop(void); +RZ_API RzConsContext *rz_cons_context_new(R_NULLABLE RzConsContext *parent); +RZ_API void rz_cons_context_free(RzConsContext *context); +RZ_API void rz_cons_context_load(RzConsContext *context); +RZ_API void rz_cons_context_reset(void); +RZ_API bool rz_cons_context_is_main(void); +RZ_API void rz_cons_context_break(RzConsContext *context); +RZ_API void rz_cons_context_break_push(RzConsContext *context, RzConsBreak cb, void *user, bool sig); +RZ_API void rz_cons_context_break_pop(RzConsContext *context, bool sig); /* control */ -R_API char *r_cons_editor(const char *file, const char *str); -R_API void r_cons_reset(void); -R_API void r_cons_reset_colors(void); -R_API void r_cons_print_clear(void); -R_API void r_cons_echo(const char *msg); -R_API void r_cons_zero(void); -R_API void r_cons_highlight(const char *word); -R_API void r_cons_clear(void); -R_API void r_cons_clear_buffer(void); -R_API void r_cons_clear00(void); -R_API void r_cons_clear_line(int err); -R_API void r_cons_fill_line(void); -R_API void r_cons_stdout_open(const char *file, int append); -R_API int r_cons_stdout_set_fd(int fd); -R_API void r_cons_gotoxy(int x, int y); -R_API int r_cons_get_cur_line(void); -R_API void r_cons_show_cursor(int cursor); -R_API char *r_cons_swap_ground(const char *col); -R_API bool r_cons_drop(int n); -R_API void r_cons_chop(void); -R_API void r_cons_set_raw(bool b); -R_API void r_cons_set_interactive(bool b); -R_API void r_cons_set_last_interactive(void); -R_API void r_cons_set_utf8(bool b); -R_API void r_cons_grep(const char *grep); +RZ_API char *rz_cons_editor(const char *file, const char *str); +RZ_API void rz_cons_reset(void); +RZ_API void rz_cons_reset_colors(void); +RZ_API void rz_cons_print_clear(void); +RZ_API void rz_cons_echo(const char *msg); +RZ_API void rz_cons_zero(void); +RZ_API void rz_cons_highlight(const char *word); +RZ_API void rz_cons_clear(void); +RZ_API void rz_cons_clear_buffer(void); +RZ_API void rz_cons_clear00(void); +RZ_API void rz_cons_clear_line(int err); +RZ_API void rz_cons_fill_line(void); +RZ_API void rz_cons_stdout_open(const char *file, int append); +RZ_API int rz_cons_stdout_set_fd(int fd); +RZ_API void rz_cons_gotoxy(int x, int y); +RZ_API int rz_cons_get_cur_line(void); +RZ_API void rz_cons_show_cursor(int cursor); +RZ_API char *rz_cons_swap_ground(const char *col); +RZ_API bool rz_cons_drop(int n); +RZ_API void rz_cons_chop(void); +RZ_API void rz_cons_set_raw(bool b); +RZ_API void rz_cons_set_interactive(bool b); +RZ_API void rz_cons_set_last_interactive(void); +RZ_API void rz_cons_set_utf8(bool b); +RZ_API void rz_cons_grep(const char *grep); /* output */ -R_API int r_cons_printf(const char *format, ...); -R_API void r_cons_printf_list(const char *format, va_list ap); -R_API void r_cons_strcat(const char *str); -R_API void r_cons_strcat_at(const char *str, int x, char y, int w, int h); -#define r_cons_print(x) r_cons_strcat (x) -R_API void r_cons_println(const char* str); +RZ_API int rz_cons_printf(const char *format, ...); +RZ_API void rz_cons_printf_list(const char *format, va_list ap); +RZ_API void rz_cons_strcat(const char *str); +RZ_API void rz_cons_strcat_at(const char *str, int x, char y, int w, int h); +#define rz_cons_print(x) rz_cons_strcat (x) +RZ_API void rz_cons_println(const char* str); -R_API void r_cons_strcat_justify(const char *str, int j, char c); -R_API int r_cons_memcat(const char *str, int len); -R_API void r_cons_newline(void); -R_API void r_cons_filter(void); -R_API void r_cons_flush(void); -R_API void r_cons_print_fps (int col); -R_API void r_cons_last(void); -R_API int r_cons_less_str(const char *str, const char *exitkeys); -R_API void r_cons_less(void); -R_API void r_cons_2048(bool color); -R_API void r_cons_memset(char ch, int len); -R_API void r_cons_visual_flush(void); -R_API void r_cons_visual_write(char *buffer); -R_API bool r_cons_is_utf8(void); -R_API void r_cons_cmd_help(const char * help[], bool use_color); -R_API void r_cons_log_stub(const char *output, const char *funcname, const char *filename, +RZ_API void rz_cons_strcat_justify(const char *str, int j, char c); +RZ_API int rz_cons_memcat(const char *str, int len); +RZ_API void rz_cons_newline(void); +RZ_API void rz_cons_filter(void); +RZ_API void rz_cons_flush(void); +RZ_API void rz_cons_print_fps (int col); +RZ_API void rz_cons_last(void); +RZ_API int rz_cons_less_str(const char *str, const char *exitkeys); +RZ_API void rz_cons_less(void); +RZ_API void rz_cons_2048(bool color); +RZ_API void rz_cons_memset(char ch, int len); +RZ_API void rz_cons_visual_flush(void); +RZ_API void rz_cons_visual_write(char *buffer); +RZ_API bool rz_cons_is_utf8(void); +RZ_API void rz_cons_cmd_help(const char * help[], bool use_color); +RZ_API void rz_cons_log_stub(const char *output, const char *funcname, const char *filename, unsigned int lineno, unsigned int level, const char *tag, const char *fmtstr, ...) R_PRINTF_CHECK(7, 8); /* input */ -R_API int r_cons_controlz(int ch); -R_API int r_cons_readchar(void); -R_API bool r_cons_readpush(const char *str, int len); -R_API void r_cons_readflush(void); -R_API void r_cons_switchbuf(bool active); -R_API int r_cons_readchar_timeout(ut32 usec); -R_API int r_cons_any_key(const char *msg); -R_API int r_cons_eof(void); +RZ_API int rz_cons_controlz(int ch); +RZ_API int rz_cons_readchar(void); +RZ_API bool rz_cons_readpush(const char *str, int len); +RZ_API void rz_cons_readflush(void); +RZ_API void rz_cons_switchbuf(bool active); +RZ_API int rz_cons_readchar_timeout(ut32 usec); +RZ_API int rz_cons_any_key(const char *msg); +RZ_API int rz_cons_eof(void); -R_API int r_cons_palette_init(const unsigned char *pal); -R_API int r_cons_pal_set(const char *key, const char *val); -R_API void r_cons_pal_update_event(void); -R_API void r_cons_pal_free(RConsContext *ctx); -R_API void r_cons_pal_init(RConsContext *ctx); -R_API void r_cons_pal_copy(RConsContext *dst, RConsContext *src); -R_API char *r_cons_pal_parse(const char *str, RColor *outcol); -R_API void r_cons_pal_random(void); -R_API RColor r_cons_pal_get(const char *key); -R_API RColor r_cons_pal_get_i(int index); -R_API const char *r_cons_pal_get_name(int index); -R_API int r_cons_pal_len(void); -R_API int r_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a); -R_API char *r_cons_rgb_tostring(ut8 r, ut8 g, ut8 b); -R_API void r_cons_pal_list(int rad, const char *arg); -R_API void r_cons_pal_show(void); -R_API int r_cons_get_size(int *rows); -R_API bool r_cons_isatty(void); -R_API int r_cons_get_cursor(int *rows); -R_API int r_cons_arrow_to_hjkl(int ch); -R_API char *r_cons_html_filter(const char *ptr, int *newlen); -R_API char *r_cons_rainbow_get(int idx, int last, bool bg); -R_API void r_cons_rainbow_free(RConsContext *ctx); -R_API void r_cons_rainbow_new(RConsContext *ctx, int sz); +RZ_API int rz_cons_palette_init(const unsigned char *pal); +RZ_API int rz_cons_pal_set(const char *key, const char *val); +RZ_API void rz_cons_pal_update_event(void); +RZ_API void rz_cons_pal_free(RzConsContext *ctx); +RZ_API void rz_cons_pal_init(RzConsContext *ctx); +RZ_API void rz_cons_pal_copy(RzConsContext *dst, RzConsContext *src); +RZ_API char *rz_cons_pal_parse(const char *str, RColor *outcol); +RZ_API void rz_cons_pal_random(void); +RZ_API RColor rz_cons_pal_get(const char *key); +RZ_API RColor rz_cons_pal_get_i(int index); +RZ_API const char *rz_cons_pal_get_name(int index); +RZ_API int rz_cons_pal_len(void); +RZ_API int rz_cons_rgb_parse(const char *p, ut8 *r, ut8 *g, ut8 *b, ut8 *a); +RZ_API char *rz_cons_rgb_tostring(ut8 r, ut8 g, ut8 b); +RZ_API void rz_cons_pal_list(int rad, const char *arg); +RZ_API void rz_cons_pal_show(void); +RZ_API int rz_cons_get_size(int *rows); +RZ_API bool rz_cons_isatty(void); +RZ_API int rz_cons_get_cursor(int *rows); +RZ_API int rz_cons_arrow_to_hjkl(int ch); +RZ_API char *rz_cons_html_filter(const char *ptr, int *newlen); +RZ_API char *rz_cons_rainbow_get(int idx, int last, bool bg); +RZ_API void rz_cons_rainbow_free(RzConsContext *ctx); +RZ_API void rz_cons_rainbow_new(RzConsContext *ctx, int sz); -R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv); -R_API char *r_cons_hud(RList *list, const char *prompt); -R_API char *r_cons_hud_path(const char *path, int dir); -R_API char *r_cons_hud_string(const char *s); -R_API char *r_cons_hud_file(const char *f); +RZ_API int rz_cons_fgets(char *buf, int len, int argc, const char **argv); +RZ_API char *rz_cons_hud(RzList *list, const char *prompt); +RZ_API char *rz_cons_hud_path(const char *path, int dir); +RZ_API char *rz_cons_hud_string(const char *s); +RZ_API char *rz_cons_hud_file(const char *f); -R_API const char *r_cons_get_buffer(void); -R_API int r_cons_get_buffer_len(void); -R_API void r_cons_grep_help(void); -R_API void r_cons_grep_parsecmd(char *cmd, const char *quotestr); -R_API char * r_cons_grep_strip(char *cmd, const char *quotestr); -R_API void r_cons_grep_process(char * grep); -R_API int r_cons_grep_line(char *buf, int len); // must be static -R_API void r_cons_grepbuf(void); +RZ_API const char *rz_cons_get_buffer(void); +RZ_API int rz_cons_get_buffer_len(void); +RZ_API void rz_cons_grep_help(void); +RZ_API void rz_cons_grep_parsecmd(char *cmd, const char *quotestr); +RZ_API char * rz_cons_grep_strip(char *cmd, const char *quotestr); +RZ_API void rz_cons_grep_process(char * grep); +RZ_API int rz_cons_grep_line(char *buf, int len); // must be static +RZ_API void rz_cons_grepbuf(void); -R_API void r_cons_rgb(ut8 r, ut8 g, ut8 b, ut8 a); -R_API void r_cons_rgb_fgbg(ut8 r, ut8 g, ut8 b, ut8 R, ut8 G, ut8 B); -R_API void r_cons_rgb_init(void); -R_API char *r_cons_rgb_str_mode(RConsColorMode mode, char *outstr, size_t sz, RColor *rcolor); -R_API char *r_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor); -R_API char *r_cons_rgb_str_off(char *outstr, size_t sz, ut64 off); -R_API void r_cons_color(int fg, int r, int g, int b); +RZ_API void rz_cons_rgb(ut8 r, ut8 g, ut8 b, ut8 a); +RZ_API void rz_cons_rgb_fgbg(ut8 r, ut8 g, ut8 b, ut8 R, ut8 G, ut8 B); +RZ_API void rz_cons_rgb_init(void); +RZ_API char *rz_cons_rgb_str_mode(RzConsColorMode mode, char *outstr, size_t sz, RColor *rcolor); +RZ_API char *rz_cons_rgb_str(char *outstr, size_t sz, RColor *rcolor); +RZ_API char *rz_cons_rgb_str_off(char *outstr, size_t sz, ut64 off); +RZ_API void rz_cons_color(int fg, int r, int g, int b); -R_API RColor r_cons_color_random(ut8 alpha); -R_API void r_cons_invert(int set, int color); -R_API bool r_cons_yesno(int def, const char *fmt, ...); -R_API char *r_cons_input(const char *msg); -R_API char *r_cons_password(const char *msg); -R_API bool r_cons_set_cup(bool enable); -R_API void r_cons_column(int c); -R_API int r_cons_get_column(void); -R_API char *r_cons_message(const char *msg); -R_API void r_cons_set_title(const char *str); -R_API bool r_cons_enable_mouse(const bool enable); -R_API void r_cons_enable_highlight(const bool enable); -R_API void r_cons_bind(RConsBind *bind); -R_API const char* r_cons_get_rune(const ut8 ch); +RZ_API RColor rz_cons_color_random(ut8 alpha); +RZ_API void rz_cons_invert(int set, int color); +RZ_API bool rz_cons_yesno(int def, const char *fmt, ...); +RZ_API char *rz_cons_input(const char *msg); +RZ_API char *rz_cons_password(const char *msg); +RZ_API bool rz_cons_set_cup(bool enable); +RZ_API void rz_cons_column(int c); +RZ_API int rz_cons_get_column(void); +RZ_API char *rz_cons_message(const char *msg); +RZ_API void rz_cons_set_title(const char *str); +RZ_API bool rz_cons_enable_mouse(const bool enable); +RZ_API void rz_cons_enable_highlight(const bool enable); +RZ_API void rz_cons_bind(RzConsBind *bind); +RZ_API const char* rz_cons_get_rune(const ut8 ch); #endif -/* r_line */ +/* rz_line */ #define R_LINE_BUFSIZE 4096 #define R_LINE_HISTSIZE 256 @@ -1005,7 +1005,7 @@ R_API const char* r_cons_get_rune(const ut8 ch); #define R_SELWIDGET_DIR_UP 0 #define R_SELWIDGET_DIR_DOWN 1 -typedef struct r_selection_widget_t { +typedef struct rz_selection_widget_t { const char **options; int options_len; int selection; @@ -1015,7 +1015,7 @@ typedef struct r_selection_widget_t { bool direction; } RSelWidget; -typedef struct r_line_hist_t { +typedef struct rz_line_hist_t { char **data; int size; int index; @@ -1023,27 +1023,27 @@ typedef struct r_line_hist_t { int autosave; } RLineHistory; -typedef struct r_line_buffer_t { +typedef struct rz_line_buffer_t { char data[R_LINE_BUFSIZE]; int index; int length; } RLineBuffer; -typedef struct r_hud_t { +typedef struct rz_hud_t { int current_entry_n; int top_entry_n; char activate; int vi; } RLineHud; -typedef struct r_line_t RLine; // forward declaration -typedef struct r_line_comp_t RLineCompletion; +typedef struct rz_line_t RLine; // forward declaration +typedef struct rz_line_comp_t RLineCompletion; typedef enum { R_LINE_PROMPT_DEFAULT, R_LINE_PROMPT_OFFSET, R_LINE_PROMPT_FILE } RLinePromptType; typedef int (*RLineCompletionCb)(RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type, void *user); -struct r_line_comp_t { +struct rz_line_comp_t { bool opt; size_t args_limit; bool quit; @@ -1056,7 +1056,7 @@ typedef char* (*RLineEditorCb)(void *core, const char *str); typedef int (*RLineHistoryUpCb)(RLine* line); typedef int (*RLineHistoryDownCb)(RLine* line); -struct r_line_t { +struct rz_line_t { RLineCompletion completion; RLineBuffer buffer; RLineHistory history; @@ -1066,12 +1066,12 @@ struct r_line_t { RLineHistoryDownCb cb_history_down; RLineEditorCb cb_editor; // RLineFunctionKeyCb cb_fkey; - RConsFunctionKey cb_fkey; + RzConsFunctionKey cb_fkey; /* state , TODO: use more bool */ int echo; int has_echo; char *prompt; - RList/**/ *kill_ring; + RzList/**/ *kill_ring; int kill_ring_ptr; char *clipboard; int disable; @@ -1087,58 +1087,58 @@ struct r_line_t { int offset_hist_index; int file_hist_index; RLineHud *hud; - RList *sdbshell_hist; - RListIter *sdbshell_hist_iter; + RzList *sdbshell_hist; + RzListIter *sdbshell_hist_iter; int vtmode; }; /* RLine */ -#ifdef R_API +#ifdef RZ_API -R_API RLine *r_line_new(void); -R_API RLine *r_line_singleton(void); -R_API void r_line_free(void); -R_API char *r_line_get_prompt(void); -R_API void r_line_set_prompt(const char *prompt); -R_API int r_line_dietline_init(void); -R_API void r_line_clipboard_push (const char *str); -R_API void r_line_hist_free(void); +RZ_API RLine *rz_line_new(void); +RZ_API RLine *rz_line_singleton(void); +RZ_API void rz_line_free(void); +RZ_API char *rz_line_get_prompt(void); +RZ_API void rz_line_set_prompt(const char *prompt); +RZ_API int rz_line_dietline_init(void); +RZ_API void rz_line_clipboard_push (const char *str); +RZ_API void rz_line_hist_free(void); typedef int (RLineReadCallback)(void *user, const char *line); -R_API const char *r_line_readline(void); -R_API const char *r_line_readline_cb(RLineReadCallback cb, void *user); +RZ_API const char *rz_line_readline(void); +RZ_API const char *rz_line_readline_cb(RLineReadCallback cb, void *user); -R_API int r_line_hist_load(const char *file); -R_API int r_line_hist_add(const char *line); -R_API int r_line_hist_save(const char *file); -R_API int r_line_hist_label(const char *label, void (*cb)(const char*)); -R_API void r_line_label_show(void); -R_API int r_line_hist_list(void); -R_API const char *r_line_hist_get(int n); +RZ_API int rz_line_hist_load(const char *file); +RZ_API int rz_line_hist_add(const char *line); +RZ_API int rz_line_hist_save(const char *file); +RZ_API int rz_line_hist_label(const char *label, void (*cb)(const char*)); +RZ_API void rz_line_label_show(void); +RZ_API int rz_line_hist_list(void); +RZ_API const char *rz_line_hist_get(int n); -R_API int r_line_set_hist_callback(RLine *line, RLineHistoryUpCb cb_up, RLineHistoryDownCb cb_down); -R_API int r_line_hist_cmd_up(RLine *line); -R_API int r_line_hist_cmd_down(RLine *line); +RZ_API int rz_line_set_hist_callback(RLine *line, RLineHistoryUpCb cb_up, RLineHistoryDownCb cb_down); +RZ_API int rz_line_hist_cmd_up(RLine *line); +RZ_API int rz_line_hist_cmd_down(RLine *line); -R_API void r_line_completion_init(RLineCompletion *completion, size_t args_limit); -R_API void r_line_completion_fini(RLineCompletion *completion); -R_API void r_line_completion_push(RLineCompletion *completion, const char *str); -R_API void r_line_completion_set(RLineCompletion *completion, int argc, const char **argv); -R_API void r_line_completion_clear(RLineCompletion *completion); +RZ_API void rz_line_completion_init(RLineCompletion *completion, size_t args_limit); +RZ_API void rz_line_completion_fini(RLineCompletion *completion); +RZ_API void rz_line_completion_push(RLineCompletion *completion, const char *str); +RZ_API void rz_line_completion_set(RLineCompletion *completion, int argc, const char **argv); +RZ_API void rz_line_completion_clear(RLineCompletion *completion); #define R_CONS_INVERT(x,y) (y? (x?Color_INVERT: Color_INVERT_RESET): (x?"[":"]")) #endif typedef int (*RPanelsMenuCallback)(void *user); -typedef struct r_panels_menu_item { +typedef struct rz_panels_menu_item { int n_sub, selectedIndex; char *name; - struct r_panels_menu_item **sub; + struct rz_panels_menu_item **sub; RPanelsMenuCallback cb; RPanel *p; } RPanelsMenuItem; -typedef struct r_panels_menu_t { +typedef struct rz_panels_menu_t { RPanelsMenuItem *root; RPanelsMenuItem **history; int depth; @@ -1177,8 +1177,8 @@ typedef struct { int offset; } RModal; -typedef struct r_panels_t { - RConsCanvas *can; +typedef struct rz_panels_t { + RzConsCanvas *can; RPanel **panel; int n_panels; int columnWidth; @@ -1197,7 +1197,7 @@ typedef struct r_panels_t { RPanelsFun fun; RPanelsMode prevMode; RPanelsLayout layout; - RList *snows; + RzList *snows; char *name; } RPanels; @@ -1208,7 +1208,7 @@ typedef enum { QUIT, } RPanelsRootState; -typedef struct r_panels_root_t { +typedef struct rz_panels_root_t { int n_panels; int cur_panels; Sdb *pdc_caches; diff --git a/librz/include/rz_core.h b/librz/include/rz_core.h new file mode 100644 index 0000000000..debeb4c747 --- /dev/null +++ b/librz/include/rz_core.h @@ -0,0 +1,971 @@ +/* radare - LGPL - Copyright 2009-2020 - pancake */ + +#ifndef R2_CORE_H +#define R2_CORE_H + +#include +#include "rz_socket.h" +#include "rz_types.h" +#include "rz_magic.h" +#include "rz_agraph.h" +#include "rz_io.h" +#include "rz_fs.h" +#include "rz_lib.h" +#include "rz_diff.h" +#include "rz_egg.h" +#include "rz_lang.h" +#include "rz_asm.h" +#include "rz_parse.h" +#include "rz_anal.h" +#include "rz_cmd.h" +#include "rz_cons.h" +#include "rz_search.h" +#include "rz_sign.h" +#include "rz_debug.h" +#include "rz_flag.h" +#include "rz_config.h" +#include "rz_bin.h" +#include "rz_hash.h" +#include "rz_util.h" +#include "rz_util/rz_print.h" +#include "rz_crypto.h" +#include "rz_bind.h" +#include "rz_util/rz_annotated_code.h" + +#ifdef __cplusplus +extern "C" { +#endif +R_LIB_VERSION_HEADER(rz_core); + +#define R_CORE_CMD_OK 0 +#define R_CORE_CMD_INVALID -1 +#define R_CORE_CMD_EXIT -2 + +#define R_CORE_BLOCKSIZE 0x100 +#define R_CORE_BLOCKSIZE_MAX 0x3200000 /* 32MB */ + +#define R_CORE_ANAL_GRAPHLINES 1 +#define R_CORE_ANAL_GRAPHBODY 2 +#define R_CORE_ANAL_GRAPHDIFF 4 +#define R_CORE_ANAL_JSON 8 +#define R_CORE_ANAL_KEYVALUE 16 +#define R_CORE_ANAL_JSON_FORMAT_DISASM 32 +#define R_CORE_ANAL_STAR 64 + +#define R_FLAGS_FS_CLASSES "classes" +#define R_FLAGS_FS_FUNCTIONS "functions" +#define R_FLAGS_FS_IMPORTS "imports" +#define R_FLAGS_FS_RELOCS "relocs" +#define R_FLAGS_FS_RESOURCES "resources" +#define R_FLAGS_FS_SECTIONS "sections" +#define R_FLAGS_FS_SEGMENTS "segments" +#define R_FLAGS_FS_SIGNS "sign" +#define R_FLAGS_FS_STRINGS "strings" +#define R_FLAGS_FS_SYMBOLS "symbols" +#define R_FLAGS_FS_SYMBOLS_SECTIONS "symbols.sections" +#define R_FLAGS_FS_SYSCALLS "syscalls" + +#define R_GRAPH_FORMAT_NO 0 +#define R_GRAPH_FORMAT_GMLFCN 1 +#define R_GRAPH_FORMAT_JSON 2 +#define R_GRAPH_FORMAT_GML 3 +#define R_GRAPH_FORMAT_DOT 4 +#define R_GRAPH_FORMAT_CMD 5 + +/// +#define R_CONS_COLOR_DEF(x, def) ((core->cons && core->cons->context->pal.x)? core->cons->context->pal.x: def) +#define R_CONS_COLOR(x) R_CONS_COLOR_DEF (x, "") + +/* rtr */ +#define RTR_PROTOCOL_RAP 0 +#define RTR_PROTOCOL_TCP 1 +#define RTR_PROTOCOL_UDP 2 +#define RTR_PROTOCOL_HTTP 3 +#define RTR_PROTOCOL_UNIX 4 + +#define RTR_MAX_HOSTS 255 + +/* visual mode */ +typedef enum { + R_CORE_VISUAL_MODE_PX = 0, + R_CORE_VISUAL_MODE_PD = 1, + R_CORE_VISUAL_MODE_DB = 2, + R_CORE_VISUAL_MODE_OV = 3, + R_CORE_VISUAL_MODE_CD = 4 +} RzCoreVisualMode; + +/* +#define R_CORE_VISUAL_MODE_PC 4 +#define R_CORE_VISUAL_MODE_PXA 5 +#define R_CORE_VISUAL_MODE_PSS 6 +#define R_CORE_VISUAL_MODE_PRC 7 +#define R_CORE_VISUAL_MODE_PXa 8 +#define R_CORE_VISUAL_MODE_PXR 9 +*/ + +typedef struct rz_core_rtr_host_t { + int proto; + char host[512]; + int port; + char file[1024]; + RzSocket *fd; +} RzCoreRtrHost; + +typedef struct rz_core_undo_t { + char *action; + char *revert; + ut64 tstamp; + ut64 offset; +} RzCoreUndo; + +typedef enum { + AUTOCOMPLETE_DEFAULT, + AUTOCOMPLETE_MS +} RAutocompleteType; + +typedef struct { + ut64 addr; + const char *glob; + ut64 minstamp; +} RzCoreUndoCondition; + +typedef struct rz_core_log_t { + int first; + int last; + RStrpool *sp; +} RzCoreLog; + +typedef struct rz_core_file_t { + int dbg; + int fd; + RBinBind binb; + const struct rz_core_t *core; + ut8 alive; +} RzCoreFile; + + +typedef struct rz_core_times_t { + ut64 loadlibs_init_time; + ut64 loadlibs_time; + ut64 file_open_time; +} RzCoreTimes; + +#define R_CORE_ASMQJMPS_NUM 10 +#define R_CORE_ASMQJMPS_LETTERS 26 +#define R_CORE_ASMQJMPS_MAX_LETTERS (26 * 26 * 26 * 26 * 26) +#define R_CORE_ASMQJMPS_LEN_LETTERS 5 + +typedef enum rz_core_autocomplete_types_t { + R_CORE_AUTOCMPLT_DFLT = 0, + R_CORE_AUTOCMPLT_FLAG, + R_CORE_AUTOCMPLT_FLSP, + R_CORE_AUTOCMPLT_SEEK, + R_CORE_AUTOCMPLT_FCN, + R_CORE_AUTOCMPLT_ZIGN, + R_CORE_AUTOCMPLT_EVAL, + R_CORE_AUTOCMPLT_PRJT, + R_CORE_AUTOCMPLT_MINS, + R_CORE_AUTOCMPLT_BRKP, + R_CORE_AUTOCMPLT_MACR, + R_CORE_AUTOCMPLT_FILE, + R_CORE_AUTOCMPLT_THME, + R_CORE_AUTOCMPLT_OPTN, + R_CORE_AUTOCMPLT_MS, + R_CORE_AUTOCMPLT_SDB, +// --- left as last always + R_CORE_AUTOCMPLT_END, +} RzCoreAutocompleteType; + +typedef struct rz_core_autocomplete_t { + const char* cmd; + int length; + int n_subcmds; + bool locked; + int type; + struct rz_core_autocomplete_t** subcmds; +} RzCoreAutocomplete; + +typedef struct rz_core_visual_tab_t { + int printidx; + ut64 offset; + bool cur_enabled; + int cur; + int ocur; + int cols; + int disMode; + int hexMode; + int asm_offset; + int asm_instr; + int asm_indent; + int asm_bytes; + int asm_cmt_col; + int printMode; + int current3format; + int current4format; + int current5format; + int dumpCols; + char name[32]; // XXX leak because no rz_core_visual_tab_free + // TODO: cursor and such +} RzCoreVisualTab; +// #define RzCoreVisualTab Tab + +typedef struct rz_core_visual_t { + RzList *tabs; + int tab; +} RzCoreVisual; +// #define RzCoreVisual Visual + +typedef struct { + int x; + int y; + int w; + int h; + char *cmd; +} RzCoreGadget; + +RZ_API void rz_core_gadget_free (RzCoreGadget *g); + +typedef struct rz_core_tasks_t { + int task_id_next; + RzList *tasks; + RzList *tasks_queue; + RzList *oneshot_queue; + int oneshots_enqueued; + struct rz_core_task_t *current_task; + struct rz_core_task_t *main_task; + RzThreadLock *lock; + int tasks_running; + bool oneshot_running; +} RzCoreTaskScheduler; + +struct rz_core_t { + RBin *bin; + RConfig *config; + ut64 offset; // current seek + ut64 prompt_offset; // temporarily set to offset to have $$ in expressions always stay the same during temp seeks + ut32 blocksize; + ut32 blocksize_max; + ut8 *block; + RBuffer *yank_buf; + ut64 yank_addr; + bool tmpseek; + bool vmode; + int interrupted; // XXX IS THIS DUPPED SOMEWHERE? + /* files */ + RzCons *cons; + RzIO *io; + RzCoreFile *file; + RzList *files; + RNum *num; + ut64 rc; // command's return code .. related to num->value; + RzLib *lib; + RzCmd *rcmd; + RzCmdDescriptor root_cmd_descriptor; + RzList/**/ *cmd_descriptors; + RzAnal *anal; + RzAsm *rasm; + /* ^^ */ + RzCoreTimes *times; + RzParse *parser; + RPrint *print; + RzLang *lang; + RzDebug *dbg; + RzFlag *flags; + RzSearch *search; + RzFS *fs; + RzFSShell *rfs; + RzEgg *egg; + RzCoreLog *log; + RzAGraph *graph; + RPanelsRoot *panels_root; + RPanels* panels; + char *cmdqueue; + char *lastcmd; + char *cmdlog; + bool cfglog; // cfg.corelog + int cmdrepeat; // cmd.repeat + const char *cmdtimes; // cmd.times + R_DEPRECATE bool cmd_in_backticks; // whether currently executing a cmd out of backticks + int rtr_n; + RzCoreRtrHost rtr_host[RTR_MAX_HOSTS]; + ut64 *asmqjmps; + int asmqjmps_count; + int asmqjmps_size; + bool is_asmqjmps_letter; + bool keep_asmqjmps; + RzCoreVisual visual; + // visual // TODO: move them into RzCoreVisual + int http_up; + int gdbserver_up; + RzCoreVisualMode printidx; + char *stkcmd; + bool in_search; + RzList *watchers; + RzList *scriptstack; + RzCoreTaskScheduler tasks; + int max_cmd_depth; + ut8 switch_file_view; + Sdb *sdb; + int incomment; + int curtab; // current tab + int seltab; // selected tab + char *cmdremote; + char *lastsearch; + char *cmdfilter; + bool break_loop; + RzList *undos; + bool binat; + bool fixedbits; // will be true when using @b: + bool fixedarch; // will be true when using @a: + bool fixedblock; + char *table_query; + int sync_index; // used for http.sync and T= + struct rz_core_t *c2; + RzCoreAutocomplete *autocomplete; + int autocomplete_type; + int maxtab; + REvent *ev; + RzList *gadgets; + bool scr_gadgets; + bool log_events; // core.c:cb_event_handler : log actions from events if cfg.log.events is set + RzList *ropchain; + bool use_tree_sitter_rzcmd; + + bool marks_init; + ut64 marks[UT8_MAX + 1]; + + RzMainCallback rz_main_rizin; + // int (*rz_main_rizin)(int argc, char **argv); + int (*rz_main_rz_find)(int argc, const char **argv); + int (*rz_main_rz_diff)(int argc, const char **argv); + int (*rz_main_rz_bin)(int argc, const char **argv); + int (*rz_main_rz_run)(int argc, const char **argv); + int (*rz_main_rz_gg)(int argc, const char **argv); + int (*rz_main_rz_asm)(int argc, const char **argv); + int (*rz_main_rz_ax)(int argc, const char **argv); +}; + +// maybe move into RzAnal +typedef struct rz_core_item_t { + const char *type; + ut64 addr; + ut64 next; + ut64 prev; + int size; + int perm; + char *data; + char *comment; + char *sectname; + char *fcnname; +} RzCoreItem; + + +RZ_API RzCoreItem *rz_core_item_at (RzCore *core, ut64 addr); +RZ_API void rz_core_item_free (RzCoreItem *ci); + +RZ_API int rz_core_bind(RzCore *core, RzCoreBind *bnd); + +typedef struct rz_core_cmpwatch_t { + ut64 addr; + int size; + char cmd[32]; + ut8 *odata; + ut8 *ndata; +} RzCoreCmpWatcher; + +typedef int (*RzCoreSearchCallback)(RzCore *core, ut64 from, ut8 *buf, int len); + +#ifdef RZ_API +//#define rz_core_ncast(x) (RzCore*)(size_t)(x) +RZ_API RzList *rz_core_list_themes(RzCore *core); +RZ_API char *rz_core_get_theme(void); +RZ_API const char *rz_core_get_section_name(RzCore *core, ut64 addr); +RZ_API RzCons *rz_core_get_cons(RzCore *core); +RZ_API RBin *rz_core_get_bin(RzCore *core); +RZ_API RConfig *rz_core_get_config (RzCore *core); +RZ_API bool rz_core_init(RzCore *core); +RZ_API void rz_core_bind_cons(RzCore *core); // to restore pointers in cons +RZ_API RzCore *rz_core_new(void); +RZ_API void rz_core_free(RzCore *core); +RZ_API void rz_core_fini(RzCore *c); +RZ_API void rz_core_wait(RzCore *core); +RZ_API RzCore *rz_core_ncast(ut64 p); +RZ_API RzCore *rz_core_cast(void *p); +RZ_API bool rz_core_bin_load_structs(RzCore *core, const char *file); +RZ_API int rz_core_config_init(RzCore *core); +RZ_API void rz_core_config_update(RzCore *core); +RZ_API void rz_core_parse_rizinrc(RzCore *r); +RZ_API int rz_core_prompt(RzCore *core, int sync); +RZ_API int rz_core_prompt_exec(RzCore *core); +RZ_API int rz_core_lines_initcache (RzCore *core, ut64 start_addr, ut64 end_addr); +RZ_API int rz_core_lines_currline (RzCore *core); +RZ_API void rz_core_prompt_loop(RzCore *core); +RZ_API ut64 rz_core_pava(RzCore *core, ut64 addr); +RZ_API int rz_core_cmd(RzCore *core, const char *cmd, int log); +RZ_API int rz_core_cmd_task_sync(RzCore *core, const char *cmd, bool log); +RZ_API char *rz_core_editor(const RzCore *core, const char *file, const char *str); +RZ_API int rz_core_fgets(char *buf, int len); +RZ_API RzFlagItem *rz_core_flag_get_by_spaces(RzFlag *f, ut64 off); +RZ_API int rz_core_cmdf(RzCore *core, const char *fmt, ...); +RZ_API int rz_core_flush(RzCore *core, const char *cmd); +RZ_API int rz_core_cmd0(RzCore *core, const char *cmd); +RZ_API void rz_core_cmd_init(RzCore *core); +RZ_API int rz_core_cmd_pipe(RzCore *core, char *radare_cmd, char *shell_cmd); +RZ_API char *rz_core_cmd_str(RzCore *core, const char *cmd); +RZ_API char *rz_core_cmd_strf(RzCore *core, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API char *rz_core_cmd_str_pipe(RzCore *core, const char *cmd); +RZ_API int rz_core_cmd_file(RzCore *core, const char *file); +RZ_API int rz_core_cmd_lines(RzCore *core, const char *lines); +RZ_API int rz_core_cmd_command(RzCore *core, const char *command); +RZ_API bool rz_core_run_script (RzCore *core, const char *file); +RZ_API bool rz_core_seek(RzCore *core, ut64 addr, bool rb); +RZ_API bool rz_core_visual_bit_editor(RzCore *core); +RZ_API int rz_core_seek_base (RzCore *core, const char *hex); +RZ_API void rz_core_seek_previous (RzCore *core, const char *type); +RZ_API void rz_core_seek_next (RzCore *core, const char *type); +RZ_API int rz_core_seek_align(RzCore *core, ut64 align, int count); +RZ_API void rz_core_arch_bits_at(RzCore *core, ut64 addr, R_OUT R_NULLABLE int *bits, R_OUT R_BORROW R_NULLABLE const char **arch); +RZ_API void rz_core_seek_arch_bits(RzCore *core, ut64 addr); +RZ_API int rz_core_block_read(RzCore *core); +RZ_API int rz_core_block_size(RzCore *core, int bsize); +RZ_API int rz_core_seek_size(RzCore *core, ut64 addr, int bsize); +RZ_API int rz_core_is_valid_offset (RzCore *core, ut64 offset); +RZ_API int rz_core_shift_block(RzCore *core, ut64 addr, ut64 b_size, st64 dist); +RZ_API void rz_core_autocomplete(R_NULLABLE RzCore *core, RLineCompletion *completion, RLineBuffer *buf, RLinePromptType prompt_type); +RZ_API void rz_core_print_scrollbar(RzCore *core); +RZ_API void rz_core_print_scrollbar_bottom(RzCore *core); +RZ_API void rz_core_visual_prompt_input (RzCore *core); +RZ_API void rz_core_visual_toggle_decompiler_disasm(RzCore *core, bool for_graph, bool reset); +RZ_API void rz_core_visual_applyDisMode(RzCore *core, int disMode); +RZ_API void rz_core_visual_applyHexMode(RzCore *core, int hexMode); +RZ_API int rz_core_visual_refs(RzCore *core, bool xref, bool fcnInsteadOfAddr); +RZ_API void rz_core_visual_append_help(RStrBuf *p, const char *title, const char **help); +RZ_API bool rz_core_prevop_addr(RzCore* core, ut64 start_addr, int numinstrs, ut64* prev_addr); +RZ_API ut64 rz_core_prevop_addr_force(RzCore *core, ut64 start_addr, int numinstrs); +RZ_API bool rz_core_visual_hudstuff(RzCore *core); +RZ_API int rz_core_visual_classes(RzCore *core); +RZ_API int rz_core_visual_anal_classes(RzCore *core); +RZ_API int rz_core_visual_types(RzCore *core); +RZ_API int rz_core_visual(RzCore *core, const char *input); +RZ_API int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalFunction *_fcn, int is_interactive); +RZ_API bool rz_core_visual_panels_root(RzCore *core, RPanelsRoot *panels_root); +RZ_API void rz_core_visual_browse(RzCore *core, const char *arg); +RZ_API int rz_core_visual_cmd(RzCore *core, const char *arg); +RZ_API void rz_core_visual_seek_animation (RzCore *core, ut64 addr); +RZ_API void rz_core_visual_asm(RzCore *core, ut64 addr); +RZ_API void rz_core_visual_colors(RzCore *core); +RZ_API int rz_core_visual_xrefs_x(RzCore *core); +RZ_API int rz_core_visual_xrefs_X(RzCore *core); +RZ_API void rz_core_visual_showcursor(RzCore *core, int x); +RZ_API void rz_core_visual_offset(RzCore *core); +RZ_API int rz_core_visual_hud(RzCore *core); +RZ_API void rz_core_visual_jump(RzCore *core, ut8 ch); +RZ_API void rz_core_visual_disasm_up(RzCore *core, int *cols); +RZ_API void rz_core_visual_disasm_down(RzCore *core, RzAsmOp *op, int *cols); +RZ_API RBinReloc *rz_core_getreloc(RzCore *core, ut64 addr, int size); +RZ_API ut64 rz_core_get_asmqjmps(RzCore *core, const char *str); +RZ_API void rz_core_set_asmqjmps(RzCore *core, char *str, size_t len, int i); +RZ_API char* rz_core_add_asmqjmp(RzCore *core, ut64 addr); + +RZ_API void rz_core_anal_type_init(RzCore *core); +RZ_API void rz_core_link_stroff(RzCore *core, RzAnalFunction *fcn); +RZ_API void rz_core_anal_inflags (RzCore *core, const char *glob); +RZ_API bool cmd_anal_objc (RzCore *core, const char *input, bool auto_anal); +RZ_API void rz_core_anal_cc_init(RzCore *core); +RZ_API void rz_core_anal_paths(RzCore *core, ut64 from, ut64 to, bool followCalls, int followDepth, bool is_json); +RZ_API void rz_core_anal_esil_graph(RzCore *core, const char *expr); + +RZ_API void rz_core_list_io(RzCore *core); +RZ_API RzListInfo *rz_listinfo_new (const char *name, RInterval pitv, RInterval vitv, int perm, const char *extra); +RZ_API void rz_listinfo_free (RzListInfo *info); +/* visual marks */ +RZ_API void rz_core_visual_mark_seek(RzCore *core, ut8 ch); +RZ_API void rz_core_visual_mark(RzCore *core, ut8 ch); +RZ_API void rz_core_visual_mark_set(RzCore *core, ut8 ch, ut64 addr); +RZ_API void rz_core_visual_mark_del(RzCore *core, ut8 ch); +RZ_API bool rz_core_visual_mark_dump(RzCore *core); +RZ_API void rz_core_visual_mark_reset(RzCore *core); + +RZ_API int rz_core_search_cb(RzCore *core, ut64 from, ut64 to, RzCoreSearchCallback cb); +RZ_API bool rz_core_serve(RzCore *core, RzIODesc *fd); +RZ_API int rz_core_file_reopen(RzCore *core, const char *args, int perm, int binload); +RZ_API void rz_core_file_reopen_debug(RzCore *core, const char *args); +RZ_API void rz_core_file_reopen_remote_debug(RzCore *core, char *uri, ut64 addr); +RZ_API RzCoreFile * rz_core_file_find_by_fd(RzCore* core, ut64 fd); +RZ_API RzCoreFile * rz_core_file_find_by_name (RzCore * core, const char * name); +RZ_API RzCoreFile * rz_core_file_cur (RzCore *r); +RZ_API int rz_core_file_set_by_fd(RzCore *core, ut64 fd); +RZ_API int rz_core_file_set_by_name(RzCore *core, const char * name); +RZ_API int rz_core_file_set_by_file (RzCore * core, RzCoreFile *cf); +RZ_API int rz_core_setup_debugger (RzCore *r, const char *debugbackend, bool attach); + +RZ_API void rz_core_file_free(RzCoreFile *cf); +RZ_API RzCoreFile *rz_core_file_open(RzCore *core, const char *file, int flags, ut64 loadaddr); +RZ_API RzCoreFile *rz_core_file_open_many(RzCore *r, const char *file, int flags, ut64 loadaddr); +RZ_API RzCoreFile *rz_core_file_get_by_fd(RzCore *core, int fd); +RZ_API int rz_core_file_close(RzCore *core, RzCoreFile *fh); +RZ_API bool rz_core_file_close_fd(RzCore *core, int fd); +RZ_API bool rz_core_file_close_all_but(RzCore *core); +RZ_API int rz_core_file_list(RzCore *core, int mode); +RZ_API int rz_core_file_binlist(RzCore *core); +RZ_API bool rz_core_file_bin_raise(RzCore *core, ut32 num); +RZ_API int rz_core_seek_delta(RzCore *core, st64 addr); +RZ_API bool rz_core_extend_at(RzCore *core, ut64 addr, int size); +RZ_API bool rz_core_write_at(RzCore *core, ut64 addr, const ut8 *buf, int size); +RZ_API int rz_core_write_op(RzCore *core, const char *arg, char op); +RZ_API ut8* rz_core_transform_op(RzCore *core, const char *arg, char op); +RZ_API int rz_core_set_file_by_fd (RzCore * core, ut64 bin_fd); +RZ_API int rz_core_set_file_by_name (RBin * bin, const char * name); +RZ_API ut32 rz_core_file_cur_fd (RzCore *core); + +RZ_API void rz_core_debug_rr (RzCore *core, RzReg *reg, int mode); + +/* fortune */ +RZ_API void rz_core_fortune_list_types(void); +RZ_API void rz_core_fortune_list(RzCore *core); +RZ_API void rz_core_fortune_print_random(RzCore *core); + +/* project */ +RZ_API bool rz_core_project_load(RzCore *core, const char *prjfile, const char *rcfile); +RZ_API RzThread *rz_core_project_load_bg(RzCore *core, const char *prjfile, const char *rcfile); +RZ_API void rz_core_project_execute_cmds(RzCore *core, const char *prjfile); + +#define R_CORE_FOREIGN_ADDR -1 +RZ_API int rz_core_yank(RzCore *core, ut64 addr, int len); +RZ_API int rz_core_yank_string(RzCore *core, ut64 addr, int maxlen); +RZ_API bool rz_core_yank_hexpair(RzCore *core, const char *input); +RZ_API int rz_core_yank_paste(RzCore *core, ut64 addr, int len); +RZ_API int rz_core_yank_set (RzCore *core, ut64 addr, const ut8 *buf, ut32 len); // set yank buffer bytes +RZ_API int rz_core_yank_set_str (RzCore *core, ut64 addr, const char *buf, ut32 len); // Null terminate the bytes +RZ_API int rz_core_yank_to(RzCore *core, const char *arg); +RZ_API bool rz_core_yank_dump (RzCore *core, ut64 pos, int format); +RZ_API int rz_core_yank_hexdump (RzCore *core, ut64 pos); +RZ_API int rz_core_yank_cat (RzCore *core, ut64 pos); +RZ_API int rz_core_yank_cat_string (RzCore *core, ut64 pos); +RZ_API int rz_core_yank_hud_file (RzCore *core, const char *input); +RZ_API int rz_core_yank_hud_path (RzCore *core, const char *input, int dir); +RZ_API bool rz_core_yank_file_ex (RzCore *core, const char *input); +RZ_API int rz_core_yank_file_all (RzCore *core, const char *input); + +#define R_CORE_LOADLIBS_ENV 1 +#define R_CORE_LOADLIBS_HOME 2 +#define R_CORE_LOADLIBS_SYSTEM 4 +#define R_CORE_LOADLIBS_CONFIG 8 +#define R_CORE_LOADLIBS_ALL UT32_MAX + +RZ_API void rz_core_loadlibs_init(RzCore *core); +RZ_API int rz_core_loadlibs(RzCore *core, int where, const char *path); +RZ_API int rz_core_cmd_buffer(RzCore *core, const char *buf); +RZ_API int rz_core_cmdf(RzCore *core, const char *fmt, ...); +RZ_API int rz_core_cmd0(RzCore *core, const char *cmd); +RZ_API char *rz_core_cmd_str(RzCore *core, const char *cmd); +RZ_API int rz_core_cmd_foreach(RzCore *core, const char *cmd, char *each); +RZ_API int rz_core_cmd_foreach3(RzCore *core, const char *cmd, char *each); +RZ_API char *rz_core_op_str(RzCore *core, ut64 addr); +RZ_API RzAnalOp *rz_core_op_anal(RzCore *core, ut64 addr, RzAnalOpMask mask); +RZ_API char *rz_core_disassemble_instr(RzCore *core, ut64 addr, int l); +RZ_API char *rz_core_disassemble_bytes(RzCore *core, ut64 addr, int b); + +/* carg.c */ +RZ_API RzList *rz_core_get_func_args(RzCore *core, const char *func_name); +RZ_API void rz_core_print_func_args(RzCore *core); +RZ_API char *resolve_fcn_name(RzAnal *anal, const char * func_name); +RZ_API int rz_core_get_stacksz(RzCore *core, ut64 from, ut64 to); + +/* anal.c */ +RZ_API RzAnalOp* rz_core_anal_op(RzCore *core, ut64 addr, int mask); +RZ_API void rz_core_anal_esil(RzCore *core, const char *str, const char *addr); +RZ_API void rz_core_anal_fcn_merge (RzCore *core, ut64 addr, ut64 addr2); +RZ_API const char *rz_core_anal_optype_colorfor(RzCore *core, ut64 addr, bool verbose); +RZ_API ut64 rz_core_anal_address (RzCore *core, ut64 addr); +RZ_API void rz_core_anal_undefine (RzCore *core, ut64 off); +RZ_API void rz_core_anal_hint_print (RzAnal* a, ut64 addr, int mode); +RZ_API void rz_core_anal_hint_list (RzAnal *a, int mode); +RZ_API int rz_core_anal_search(RzCore *core, ut64 from, ut64 to, ut64 ref, int mode); +RZ_API int rz_core_anal_search_xrefs(RzCore *core, ut64 from, ut64 to, int rad); +RZ_API int rz_core_anal_data (RzCore *core, ut64 addr, int count, int depth, int wordsize); +RZ_API void rz_core_anal_datarefs(RzCore *core, ut64 addr); +RZ_API void rz_core_anal_coderefs(RzCore *core, ut64 addr); +RZ_API void rz_core_anal_codexrefs(RzCore *core, ut64 addr); +RZ_API void rz_core_anal_importxrefs(RzCore *core); +RZ_API void rz_core_anal_callgraph(RzCore *core, ut64 addr, int fmt); +RZ_API int rz_core_anal_refs(RzCore *core, const char *input); +RZ_API void rz_core_agraph_print(RzCore *core, int use_utf, const char *input); +RZ_API bool rz_core_esil_cmd(RzAnalEsil *esil, const char *cmd, ut64 a1, ut64 a2); +RZ_API int rz_core_esil_step(RzCore *core, ut64 until_addr, const char *until_expr, ut64 *prev_addr, bool stepOver); +RZ_API int rz_core_esil_step_back(RzCore *core); +RZ_API ut64 rz_core_anal_get_bbaddr(RzCore *core, ut64 addr); +RZ_API bool rz_core_anal_bb_seek(RzCore *core, ut64 addr); +RZ_API int rz_core_anal_fcn(RzCore *core, ut64 at, ut64 from, int reftype, int depth); +RZ_API char *rz_core_anal_fcn_autoname(RzCore *core, ut64 addr, int dump, int mode); +RZ_API void rz_core_anal_autoname_all_fcns(RzCore *core); +RZ_API void rz_core_anal_autoname_all_golang_fcns(RzCore *core); +RZ_API int rz_core_anal_fcn_list(RzCore *core, const char *input, const char *rad); +RZ_API char *rz_core_anal_fcn_name(RzCore *core, RzAnalFunction *fcn); +RZ_API ut64 rz_core_anal_fcn_list_size(RzCore *core); +RZ_API void rz_core_anal_fcn_labels(RzCore *core, RzAnalFunction *fcn, int rad); +RZ_API int rz_core_anal_fcn_clean(RzCore *core, ut64 addr); +RZ_API int rz_core_print_bb_custom(RzCore *core, RzAnalFunction *fcn); +RZ_API int rz_core_print_bb_gml(RzCore *core, RzAnalFunction *fcn); +RZ_API int rz_core_anal_graph(RzCore *core, ut64 addr, int opts); +RZ_API int rz_core_anal_graph_fcn(RzCore *core, char *input, int opts); +RZ_API RzList* rz_core_anal_graph_to(RzCore *core, ut64 addr, int n); +RZ_API int rz_core_anal_ref_list(RzCore *core, int rad); +RZ_API int rz_core_anal_all(RzCore *core); +RZ_API RzList* rz_core_anal_cycles (RzCore *core, int ccl); +RZ_API RzList *rz_core_anal_fcn_get_calls (RzCore *core, RzAnalFunction *fcn); // get all calls from a function + +/*tp.c*/ +RZ_API void rz_core_anal_type_match(RzCore *core, RzAnalFunction *fcn); + +/* asm.c */ +#define R_MIDFLAGS_SHOW 1 +#define R_MIDFLAGS_REALIGN 2 +#define R_MIDFLAGS_SYMALIGN 3 + +typedef struct rz_core_asm_hit { + char *code; + int len; + ut64 addr; + ut8 valid; +} RzCoreAsmHit; + +RZ_API RBuffer *rz_core_syscall (RzCore *core, const char *name, const char *args); +RZ_API RBuffer *rz_core_syscallf (RzCore *core, const char *name, const char *fmt, ...) R_PRINTF_CHECK(3, 4); +RZ_API RzCoreAsmHit *rz_core_asm_hit_new(void); +RZ_API RzList *rz_core_asm_hit_list_new(void); +RZ_API void rz_core_asm_hit_free(void *_hit); +RZ_API void rz_core_set_asm_configs(RzCore *core, char *arch, ut32 bits, int segoff); +RZ_API char* rz_core_asm_search(RzCore *core, const char *input); +RZ_API RzList *rz_core_asm_strsearch(RzCore *core, const char *input, ut64 from, ut64 to, int maxhits, int regexp, int everyByte, int mode); +RZ_API RzList *rz_core_asm_bwdisassemble (RzCore *core, ut64 addr, int n, int len); +RZ_API RzList *rz_core_asm_back_disassemble_instr (RzCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding); +RZ_API RzList *rz_core_asm_back_disassemble_byte (RzCore *core, ut64 addr, int len, ut32 hit_count, ut32 extra_padding); +RZ_API ut32 rz_core_asm_bwdis_len (RzCore* core, int* len, ut64* start_addr, ut32 l); +RZ_API int rz_core_print_disasm(RPrint *p, RzCore *core, ut64 addr, ut8 *buf, int len, int lines, int invbreak, int nbytes, bool json, PJ *pj, RzAnalFunction *pdf); +RZ_API int rz_core_print_disasm_json(RzCore *core, ut64 addr, ut8 *buf, int len, int lines, PJ *pj); +RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address, ut8 *buf, int nb_bytes, int nb_opcodes); +RZ_API int rz_core_print_disasm_instructions(RzCore *core, int nb_bytes, int nb_opcodes); +RZ_API int rz_core_print_disasm_all(RzCore *core, ut64 addr, int l, int len, int mode); +RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut32 nb_opcodes, ut32 nb_bytes, int fmt); +RZ_API int rz_core_disasm_pdi(RzCore *core, int nb_opcodes, int nb_bytes, int fmt); +RZ_API int rz_core_disasm_pde(RzCore *core, int nb_opcodes, int mode); +RZ_API int rz_core_print_fcn_disasm(RPrint *p, RzCore *core, ut64 addr, int l, int invbreak, int cbytes); +RZ_API int rz_core_get_prc_cols(RzCore *core); +RZ_API int rz_core_flag_in_middle(RzCore *core, ut64 at, int oplen, int *midflags); +RZ_API int rz_core_bb_starts_in_middle(RzCore *core, ut64 at, int oplen); + +RZ_API bool rz_core_bin_raise (RzCore *core, ut32 bfid); + +RZ_API int rz_core_bin_set_env (RzCore *r, RBinFile *binfile); +RZ_API int rz_core_bin_set_by_fd (RzCore *core, ut64 bin_fd); +RZ_API int rz_core_bin_set_by_name (RzCore *core, const char *name); +RZ_API int rz_core_bin_reload(RzCore *core, const char *file, ut64 baseaddr); +RZ_API bool rz_core_bin_load(RzCore *core, const char *file, ut64 baseaddr); +RZ_API int rz_core_bin_rebase(RzCore *core, ut64 baddr); +RZ_API void rz_core_bin_export_info(RzCore *core, int mode); +RZ_API int rz_core_bin_list(RzCore *core, int mode); +RZ_API bool rz_core_bin_delete (RzCore *core, ut32 binfile_idx); +RZ_API ut64 rz_core_bin_impaddr(RBin *bin, int va, const char *name); + +// XXX - this is kinda hacky, maybe there should be a way to +// refresh the bin environment without specific calls? +RZ_API int rz_core_pseudo_code (RzCore *core, const char *input); + +/* gdiff.c */ +RZ_API int rz_core_zdiff(RzCore *c, RzCore *c2); +RZ_API int rz_core_gdiff(RzCore *core1, RzCore *core2); +RZ_API int rz_core_gdiff_fcn(RzCore *c, ut64 addr, ut64 addr2); + +RZ_API bool rz_core_project_open(RzCore *core, const char *file, bool thready); +RZ_API int rz_core_project_cat(RzCore *core, const char *name); +RZ_API int rz_core_project_delete(RzCore *core, const char *prjfile); +RZ_API int rz_core_project_list(RzCore *core, int mode); +RZ_API bool rz_core_project_save_script(RzCore *core, const char *file, int opts); +RZ_API bool rz_core_project_save(RzCore *core, const char *file); +RZ_API char *rz_core_project_info(RzCore *core, const char *file); +RZ_API char *rz_core_project_notes_file (RzCore *core, const char *file); + +RZ_API char *rz_core_sysenv_begin(RzCore *core, const char *cmd); +RZ_API void rz_core_sysenv_end(RzCore *core, const char *cmd); + +RZ_API void rz_core_recover_vars(RzCore *core, RzAnalFunction *fcn, bool argonly); +// XXX dupe from rz_bin.h +/* bin.c */ +#define R_CORE_BIN_ACC_STRINGS 0x001 +#define R_CORE_BIN_ACC_INFO 0x002 +#define R_CORE_BIN_ACC_MAIN 0x004 +#define R_CORE_BIN_ACC_ENTRIES 0x008 +#define R_CORE_BIN_ACC_RELOCS 0x010 +#define R_CORE_BIN_ACC_IMPORTS 0x020 +#define R_CORE_BIN_ACC_SYMBOLS 0x040 +#define R_CORE_BIN_ACC_SECTIONS 0x080 +#define R_CORE_BIN_ACC_FIELDS 0x100 +#define R_CORE_BIN_ACC_LIBS 0x200 +#define R_CORE_BIN_ACC_CLASSES 0x400 +#define R_CORE_BIN_ACC_DWARF 0x800 +#define R_CORE_BIN_ACC_SIZE 0x1000 +#define R_CORE_BIN_ACC_PDB 0x2000 +#define R_CORE_BIN_ACC_MEM 0x4000 +#define R_CORE_BIN_ACC_EXPORTS 0x8000 +#define R_CORE_BIN_ACC_VERSIONINFO 0x10000 +#define R_CORE_BIN_ACC_SIGNATURE 0x20000 +#define R_CORE_BIN_ACC_RAW_STRINGS 0x40000 +#define R_CORE_BIN_ACC_HEADER 0x80000 +#define R_CORE_BIN_ACC_RESOURCES 0x100000 +#define R_CORE_BIN_ACC_INITFINI 0x200000 +#define R_CORE_BIN_ACC_SEGMENTS 0x400000 +#define R_CORE_BIN_ACC_SOURCE 0x800000 +#define R_CORE_BIN_ACC_HASHES 0x10000000 +#define R_CORE_BIN_ACC_TRYCATCH 0x20000000 +#define R_CORE_BIN_ACC_SECTIONS_MAPPING 0x40000000 +#define R_CORE_BIN_ACC_ALL 0x504FFF + +#define R_CORE_PRJ_FLAGS 0x0001 +#define R_CORE_PRJ_EVAL 0x0002 +#define R_CORE_PRJ_IO_MAPS 0x0004 +#define R_CORE_PRJ_SECTIONS 0x0008 +#define R_CORE_PRJ_META 0x0010 +#define R_CORE_PRJ_XREFS 0x0020 +#define R_CORE_PRJ_FCNS 0x0040 +#define R_CORE_PRJ_ANAL_HINTS 0x0080 +#define R_CORE_PRJ_ANAL_TYPES 0x0100 +#define R_CORE_PRJ_ANAL_MACROS 0x0200 +#define R_CORE_PRJ_ANAL_SEEK 0x0400 +#define R_CORE_PRJ_DBG_BREAK 0x0800 +#define R_CORE_PRJ_ALL 0xFFFF + +typedef struct rz_core_bin_filter_t { + ut64 offset; + const char *name; +} RzCoreBinFilter; + +RZ_API int rz_core_bin_info (RzCore *core, int action, int mode, int va, RzCoreBinFilter *filter, const char *chksum); +RZ_API int rz_core_bin_set_arch_bits (RzCore *r, const char *name, const char * arch, ut16 bits); +RZ_API int rz_core_bin_update_arch_bits (RzCore *r); +RZ_API char *rz_core_bin_method_flags_str(ut64 flags, int mode); +RZ_API bool rz_core_pdb_info(RzCore *core, const char *file, int mode); + +/* rtr */ +RZ_API int rz_core_rtr_cmds (RzCore *core, const char *port); +RZ_API char *rz_core_rtr_cmds_query (RzCore *core, const char *host, const char *port, const char *cmd); +RZ_API void rz_core_rtr_help(RzCore *core); +RZ_API void rz_core_rtr_pushout(RzCore *core, const char *input); +RZ_API void rz_core_rtr_list(RzCore *core); +RZ_API void rz_core_rtr_add(RzCore *core, const char *input); +RZ_API void rz_core_rtr_remove(RzCore *core, const char *input); +RZ_API void rz_core_rtr_session(RzCore *core, const char *input); +RZ_API void rz_core_rtr_cmd(RzCore *core, const char *input); +RZ_API int rz_core_rtr_http(RzCore *core, int launch, int browse, const char *path); +RZ_API int rz_core_rtr_http_stop(RzCore *u); +RZ_API int rz_core_rtr_gdb(RzCore *core, int launch, const char *path); + +RZ_API int rz_core_visual_prevopsz(RzCore *core, ut64 addr); +RZ_API void rz_core_visual_config(RzCore *core); +RZ_API void rz_core_visual_mounts(RzCore *core); +RZ_API void rz_core_visual_anal(RzCore *core, const char *input); +RZ_API void rz_core_visual_debugtraces(RzCore *core, const char *input); +RZ_API void rz_core_seek_next(RzCore *core, const char *type); +RZ_API void rz_core_seek_previous(RzCore *core, const char *type); +RZ_API void rz_core_visual_define(RzCore *core, const char *arg, int distance); +RZ_API int rz_core_visual_trackflags(RzCore *core); +RZ_API int rz_core_visual_view_graph(RzCore *core); +RZ_API int rz_core_visual_view_zigns(RzCore *core); +RZ_API int rz_core_visual_view_rop(RzCore *core); +RZ_API int rz_core_visual_comments(RzCore *core); +RZ_API int rz_core_visual_prompt(RzCore *core); +RZ_API bool rz_core_visual_esil (RzCore *core); +RZ_API int rz_core_search_preludes(RzCore *core, bool log); +RZ_API int rz_core_search_prelude(RzCore *core, ut64 from, ut64 to, const ut8 *buf, int blen, const ut8 *mask, int mlen); +RZ_API RzList* /**/ rz_core_get_boundaries_prot (RzCore *core, int protection, const char *mode, const char *prefix); + +RZ_API int rz_core_patch (RzCore *core, const char *patch); + +RZ_API void rz_core_hack_help(const RzCore *core); +RZ_API int rz_core_hack(RzCore *core, const char *op); +RZ_API bool rz_core_dump(RzCore *core, const char *file, ut64 addr, ut64 size, int append); +RZ_API void rz_core_diff_show(RzCore *core, RzCore *core2); +RZ_API void rz_core_clippy(RzCore *core, const char *msg); + +/* watchers */ +RZ_API void rz_core_cmpwatch_free (RzCoreCmpWatcher *w); +RZ_API RzCoreCmpWatcher *rz_core_cmpwatch_get (RzCore *core, ut64 addr); +RZ_API int rz_core_cmpwatch_add (RzCore *core, ut64 addr, int size, const char *cmd); +RZ_API int rz_core_cmpwatch_del (RzCore *core, ut64 addr); +RZ_API int rz_core_cmpwatch_update (RzCore *core, ut64 addr); +RZ_API int rz_core_cmpwatch_show (RzCore *core, ut64 addr, int mode); +RZ_API int rz_core_cmpwatch_revert (RzCore *core, ut64 addr); + +/* undo */ +RZ_API RzCoreUndo *rz_core_undo_new(ut64 offset, const char *action, const char *revert); +RZ_API void rz_core_undo_print(RzCore *core, int mode, RzCoreUndoCondition *cond); +RZ_API void rz_core_undo_free(RzCoreUndo *cu); +RZ_API void rz_core_undo_push(RzCore *core, RzCoreUndo *cu); +RZ_API void rz_core_undo_pop(RzCore *core); + +/* logs */ +typedef int (*RzCoreLogCallback)(RzCore *core, int count, const char *message); +RZ_API void rz_core_log_free(RzCoreLog *log); +RZ_API void rz_core_log_init (RzCoreLog *log); +RZ_API char *rz_core_log_get(RzCore *core, int index); +RZ_API RzCoreLog *rz_core_log_new (void); +RZ_API bool rz_core_log_run(RzCore *core, const char *buf, RzCoreLogCallback cb); +RZ_API int rz_core_log_list(RzCore *core, int n, int count, char fmt); +RZ_API void rz_core_log_add(RzCore *core, const char *msg); +RZ_API void rz_core_log_del(RzCore *core, int n); + +// TODO MOVE SOMEWHERE ELSE +typedef char *(*PrintItemCallback)(void *user, void *p, bool selected); +RZ_API char *rz_str_widget_list(void *user, RzList *list, int rows, int cur, PrintItemCallback cb); +/* help */ +RZ_API void rz_core_cmd_help(const RzCore *core, const char * help[]); + +/* anal stats */ + +typedef struct { + ut32 youarehere; + ut32 flags; + ut32 comments; + ut32 functions; + ut32 blocks; + ut32 in_functions; + ut32 symbols; + ut32 strings; + ut32 perm; +} RzCoreAnalStatsItem; +typedef struct { + RzCoreAnalStatsItem *block; +} RzCoreAnalStats; + +RZ_API bool core_anal_bbs(RzCore *core, const char* input); +RZ_API bool core_anal_bbs_range (RzCore *core, const char* input); +RZ_API char *rz_core_anal_hasrefs(RzCore *core, ut64 value, bool verbose); +RZ_API char *rz_core_anal_get_comments(RzCore *core, ut64 addr); +RZ_API RzCoreAnalStats* rz_core_anal_get_stats (RzCore *a, ut64 from, ut64 to, ut64 step); +RZ_API void rz_core_anal_stats_free (RzCoreAnalStats *s); + +RZ_API void rz_core_syscmd_ls(const char *input); +RZ_API void rz_core_syscmd_cat(const char *file); +RZ_API void rz_core_syscmd_mkdir(const char *dir); + +RZ_API int rz_line_hist_offset_up(RLine *line); +RZ_API int rz_line_hist_offset_down(RLine *line); + +// TODO : move into debug or syscall++ +RZ_API char *cmd_syscall_dostr(RzCore *core, st64 num, ut64 addr); + +/* tasks */ + +typedef void (*RzCoreTaskCallback)(void *user, char *out); + +typedef enum { + R_CORE_TASK_STATE_BEFORE_START, + R_CORE_TASK_STATE_RUNNING, + R_CORE_TASK_STATE_SLEEPING, + R_CORE_TASK_STATE_DONE +} RTaskState; + +typedef struct rz_core_task_t { + int id; + RTaskState state; + bool transient; // delete when finished + int refcount; + RzThreadSemaphore *running_sem; + void *user; + RzCore *core; + bool dispatched; + RzThreadCond *dispatch_cond; + RzThreadLock *dispatch_lock; + RzThread *thread; + char *cmd; + char *res; + bool cmd_log; + RzConsContext *cons_context; + RzCoreTaskCallback cb; +} RzCoreTask; + +typedef void (*RzCoreTaskOneShot)(void *); + +RZ_API void rz_core_echo(RzCore *core, const char *msg); +RZ_API RTable *rz_core_table(RzCore *core); + +RZ_API void rz_core_task_scheduler_init (RzCoreTaskScheduler *tasks, RzCore *core); +RZ_API void rz_core_task_scheduler_fini (RzCoreTaskScheduler *tasks); +RZ_API RzCoreTask *rz_core_task_get(RzCoreTaskScheduler *scheduler, int id); +RZ_API RzCoreTask *rz_core_task_get_incref(RzCoreTaskScheduler *scheduler, int id); +RZ_API void rz_core_task_print(RzCore *core, RzCoreTask *task, int mode); +RZ_API void rz_core_task_list(RzCore *core, int mode); +RZ_API int rz_core_task_running_tasks_count(RzCoreTaskScheduler *scheduler); +RZ_API const char *rz_core_task_status(RzCoreTask *task); +RZ_API RzCoreTask *rz_core_task_new(RzCore *core, bool create_cons, const char *cmd, RzCoreTaskCallback cb, void *user); +RZ_API void rz_core_task_incref(RzCoreTask *task); +RZ_API void rz_core_task_decref(RzCoreTask *task); +RZ_API void rz_core_task_enqueue(RzCoreTaskScheduler *scheduler, RzCoreTask *task); +RZ_API void rz_core_task_enqueue_oneshot(RzCoreTaskScheduler *scheduler, RzCoreTaskOneShot func, void *user); +RZ_API int rz_core_task_run_sync(RzCoreTaskScheduler *scheduler, RzCoreTask *task); +RZ_API void rz_core_task_sync_begin(RzCoreTaskScheduler *scheduler); +RZ_API void rz_core_task_sync_end(RzCoreTaskScheduler *scheduler); +RZ_API void rz_core_task_yield(RzCoreTaskScheduler *scheduler); +RZ_API void rz_core_task_sleep_begin(RzCoreTask *task); +RZ_API void rz_core_task_sleep_end(RzCoreTask *task); +RZ_API void rz_core_task_break(RzCoreTaskScheduler *scheduler, int id); +RZ_API void rz_core_task_break_all(RzCoreTaskScheduler *scheduler); +RZ_API int rz_core_task_del(RzCoreTaskScheduler *scheduler, int id); +RZ_API void rz_core_task_del_all_done(RzCoreTaskScheduler *scheduler); +RZ_API RzCoreTask *rz_core_task_self(RzCoreTaskScheduler *scheduler); +RZ_API void rz_core_task_join(RzCoreTaskScheduler *scheduler, RzCoreTask *current, int id); +typedef void (*inRangeCb) (RzCore *core, ut64 from, ut64 to, int vsize, + int count, void *cb_user); +RZ_API int rz_core_search_value_in_range (RzCore *core, RInterval search_itv, + ut64 vmin, ut64 vmax, int vsize, inRangeCb cb, void *cb_user); + +RZ_API RzCoreAutocomplete *rz_core_autocomplete_add(RzCoreAutocomplete *parent, const char* cmd, int type, bool lock); +RZ_API void rz_core_autocomplete_free(RzCoreAutocomplete *obj); +RZ_API void rz_core_autocomplete_reload (RzCore *core); +RZ_API RzCoreAutocomplete *rz_core_autocomplete_find(RzCoreAutocomplete *parent, const char* cmd, bool exact); +RZ_API bool rz_core_autocomplete_remove(RzCoreAutocomplete *parent, const char* cmd); +RZ_API void rz_core_anal_propagate_noreturn(RzCore *core, ut64 addr); + +/* PLUGINS */ +extern RzCorePlugin rz_core_plugin_java; +extern RzCorePlugin rz_core_plugin_a2f; + +/* DECOMPILER PRINTING FUNCTIONS */ +/** + * @brief Prints the data contained in the specified RAnnotatedCode in JSON format. + * + * The function will print the output in console using the function rz_cons_printf(); + * + * @param code Pointer to a RAnnotatedCode. + */ +RZ_API void rz_core_annotated_code_print_json(RAnnotatedCode *code); +/** + * @brief Prints the decompiled code from the specified RAnnotatedCode. + * + * This function is used for printing the output of commands pdg and pdgo. + * It can print the decompiled code with or without offsets. If line_offsets is a null pointer, + * the output will be printed without offsets (pdg), otherwise, the output will be + * printed with offsets. + * This function will print the output in console using the function rz_cons_printf(); + * + * @param code Pointer to a RAnnotatedCode. + * @param line_offsets Pointer to a @ref RzVector that contains offsets for the decompiled code. + */ +RZ_API void rz_core_annotated_code_print(RAnnotatedCode *code, RzVector *line_offsets); +/** + * @brief Prints the decompiled code as comments + * + * This function is used for the output of command pdg* + * Output will be printed in console using the function rz_cons_printf(); + * + * @param code Pointer to a RAnnotatedCode. + */ +RZ_API void rz_core_annotated_code_print_comment_cmds(RAnnotatedCode *code); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_crypto.h b/librz/include/rz_crypto.h new file mode 100644 index 0000000000..d2b72c38ed --- /dev/null +++ b/librz/include/rz_crypto.h @@ -0,0 +1,114 @@ +#ifndef R2_CRYPTO_H +#define R2_CRYPTO_H + +#include "rz_types.h" +#include "rz_list.h" +#include "rz_crypto/rz_des.h" + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_crypto); + +enum { + R_CRYPTO_MODE_ECB, + R_CRYPTO_MODE_CBC, + R_CRYPTO_MODE_OFB, + R_CRYPTO_MODE_CFB, +}; + +enum { + R_CRYPTO_DIR_CIPHER, + R_CRYPTO_DIR_DECIPHER, +}; + +typedef struct rz_crypto_t { + struct rz_crypto_plugin_t* h; + ut8 *key; + ut8 *iv; + int key_len; + ut8 *output; + int output_len; + int output_size; + int dir; + void *user; + RzList *plugins; +} RzCrypto; + +typedef struct rz_crypto_plugin_t { + const char *name; + const char *license; + int (*get_key_size)(RzCrypto *cry); + bool (*set_iv)(RzCrypto *cry, const ut8 *iv, int ivlen); + bool (*set_key)(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction); + bool (*update)(RzCrypto *cry, const ut8 *buf, int len); + bool (*final)(RzCrypto *cry, const ut8 *buf, int len); + bool (*use)(const char *algo); + int (*fini)(RzCrypto *cry); +} RzCryptoPlugin; + +typedef ut64 RzCryptoSelector; + +#ifdef RZ_API +RZ_API RzCrypto *rz_crypto_init(RzCrypto *cry, int hard); +RZ_API RzCrypto *rz_crypto_as_new(RzCrypto *cry); +RZ_API int rz_crypto_add(RzCrypto *cry, RzCryptoPlugin *h); +RZ_API RzCrypto *rz_crypto_new(void); +RZ_API RzCrypto *rz_crypto_free(RzCrypto *cry); +RZ_API bool rz_crypto_use(RzCrypto *cry, const char *algo); +RZ_API bool rz_crypto_set_key(RzCrypto *cry, const ut8* key, int keylen, int mode, int direction); +RZ_API bool rz_crypto_set_iv(RzCrypto *cry, const ut8 *iv, int ivlen); +RZ_API int rz_crypto_update(RzCrypto *cry, const ut8 *buf, int len); +RZ_API int rz_crypto_final(RzCrypto *cry, const ut8 *buf, int len); +RZ_API int rz_crypto_append(RzCrypto *cry, const ut8 *buf, int len); +RZ_API ut8 *rz_crypto_get_output(RzCrypto *cry, int *size); +RZ_API const char *rz_crypto_name(const RzCryptoSelector bit); +RZ_API const char *rz_crypto_codec_name(const RzCryptoSelector bit); +#endif + +/* plugin pointers */ +extern RzCryptoPlugin rz_crypto_plugin_aes; +extern RzCryptoPlugin rz_crypto_plugin_des; +extern RzCryptoPlugin rz_crypto_plugin_rc4; +extern RzCryptoPlugin rz_crypto_plugin_xor; +extern RzCryptoPlugin rz_crypto_plugin_blowfish; +extern RzCryptoPlugin rz_crypto_plugin_rc2; +extern RzCryptoPlugin rz_crypto_plugin_rot; +extern RzCryptoPlugin rz_crypto_plugin_rol; +extern RzCryptoPlugin rz_crypto_plugin_ror; +extern RzCryptoPlugin rz_crypto_plugin_base64; +extern RzCryptoPlugin rz_crypto_plugin_base91; +extern RzCryptoPlugin rz_crypto_plugin_aes_cbc; +extern RzCryptoPlugin rz_crypto_plugin_punycode; +extern RzCryptoPlugin rz_crypto_plugin_rc6; +extern RzCryptoPlugin rz_crypto_plugin_cps2; +extern RzCryptoPlugin rz_crypto_plugin_serpent; + +#define R_CRYPTO_NONE 0ULL +#define R_CRYPTO_RC2 1ULL +#define R_CRYPTO_RC4 1ULL<<1 +#define R_CRYPTO_RC6 1ULL<<2 +#define R_CRYPTO_AES_ECB 1ULL<<3 +#define R_CRYPTO_AES_CBC 1ULL<<4 +#define R_CRYPTO_ROR 1ULL<<5 +#define R_CRYPTO_ROL 1ULL<<6 +#define R_CRYPTO_ROT 1ULL<<7 +#define R_CRYPTO_BLOWFISH 1ULL<<8 +#define R_CRYPTO_CPS2 1ULL<<9 +#define R_CRYPTO_DES_ECB 1ULL<<10 +#define R_CRYPTO_XOR 1ULL<<11 +#define R_CRYPTO_SERPENT 1ULL<<12 +#define R_CRYPTO_ALL 0xFFFF + +#define R_CODEC_NONE 0ULL +#define R_CODEC_B64 1ULL +#define R_CODEC_B91 1ULL<<1 +#define R_CODEC_PUNYCODE 1ULL<<2 +#define R_CODEC_ALL 0xFFFF + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_crypto/r_aes.h b/librz/include/rz_crypto/rz_aes.h similarity index 100% rename from libr/include/r_crypto/r_aes.h rename to librz/include/rz_crypto/rz_aes.h diff --git a/librz/include/rz_crypto/rz_des.h b/librz/include/rz_crypto/rz_des.h new file mode 100644 index 0000000000..7c153d7ab0 --- /dev/null +++ b/librz/include/rz_crypto/rz_des.h @@ -0,0 +1,27 @@ +#ifndef R_DES_H +#define R_DES_H + +#define DES_KEY_SIZE 8 +#define DES_BLOCK_SIZE 8 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct des_context_t { + ut32 round_key_lo[16]; // round key low + ut32 round_key_hi[16]; // round key hi + int round; +} RDESContext; + +RZ_API void rz_des_permute_key (ut32 *keylo, ut32 *keyhi); +RZ_API void rz_des_permute_block0 (ut32 *blocklo, ut32 *blockhi); +RZ_API void rz_des_permute_block1 (ut32 *blocklo, ut32 *blockhi); +RZ_API void rz_des_round_key (int i, ut32 *keylo, ut32 *keyhi, ut32 *deskeylo, ut32 *deskeyhi); +RZ_API void rz_des_round (ut32 *buflo, ut32 *bufhi, ut32 *roundkeylo, ut32 *roundkeyhi); + +#ifdef __cplusplus +} +#endif + +#endif // R_DES_H diff --git a/librz/include/rz_debug.h b/librz/include/rz_debug.h new file mode 100644 index 0000000000..e2ce4d02d7 --- /dev/null +++ b/librz/include/rz_debug.h @@ -0,0 +1,655 @@ +#ifndef R2_DEBUG_H +#define R2_DEBUG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "rz_bind.h" +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_debug); + +/* hack to fix compilation of debugger on BSD systems */ +/* This needs some testing (netbsd, freebsd, openbsd, kfreebsd) */ +#if __BSD__ +#include + +/* hakish hack to hack the openbsd/sparc64 hack */ +#undef reg +#undef fpreg +#undef fpstate +#undef trapframe +#undef rwindow + +#ifdef PTRACE_SYSCALL +/* on freebsd does not have the same meaning */ +#undef PTRACE_SYSCALL +#endif + +#define PTRACE_PEEKTEXT PT_READ_I +#define PTRACE_POKETEXT PT_WRITE_I +#define PTRACE_PEEKDATA PT_READ_D +#define PTRACE_POKEDATA PT_WRITE_D +#define PTRACE_ATTACH PT_ATTACH +#define PTRACE_DETACH PT_DETACH +#define PTRACE_SINGLESTEP PT_STEP +#define PTRACE_CONT PT_CONTINUE +#define PTRACE_GETREGS PT_GETREGS +#define PTRACE_SETREGS PT_SETREGS +#define PTRACE_SYSCALL PT_STEP +#endif + +#define SNAP_PAGE_SIZE 4096 +#define CHECK_POINT_LIMIT 0x100000 //TODO: take the benchmark +/* + * states that a process can be in + */ +typedef enum { + R_DBG_PROC_STOP = 's', + R_DBG_PROC_RUN = 'r', + R_DBG_PROC_SLEEP = 'S', + R_DBG_PROC_ZOMBIE = 'z', + R_DBG_PROC_DEAD = 'd', + R_DBG_PROC_RAISED = 'R' // has produced a signal, breakpoint, etc.. +} RzDebugPidState; + + +// signal handling must support application and debugger level options +typedef enum { + R_DBG_SIGNAL_IGNORE = 0, // ignore signal handler + R_DBG_SIGNAL_CONT = 1, // pass signal to chlidren and continue execution + R_DBG_SIGNAL_SKIP = 2, // + //.. +} RzDebugSignalMode; + + +/* + * when a user wants to resume from a breakpoint, we need to know how they want + * to proceed. these values indicate their intention. + */ +typedef enum { + R_DBG_RECOIL_NONE = 0, + R_DBG_RECOIL_STEP, + R_DBG_RECOIL_CONTINUE +} RzDebugRecoilMode; + +/* + * List of reasons that an inferior might have stopped + */ +typedef enum { + R_DEBUG_REASON_DEAD = -1, + R_DEBUG_REASON_NONE = 0, + R_DEBUG_REASON_SIGNAL, + R_DEBUG_REASON_SEGFAULT, + R_DEBUG_REASON_BREAKPOINT, + R_DEBUG_REASON_TRACEPOINT, + R_DEBUG_REASON_COND, + R_DEBUG_REASON_READERR, + R_DEBUG_REASON_STEP, + R_DEBUG_REASON_ABORT, + R_DEBUG_REASON_WRITERR, + R_DEBUG_REASON_DIVBYZERO, + R_DEBUG_REASON_ILLEGAL, + R_DEBUG_REASON_UNKNOWN, + R_DEBUG_REASON_ERROR, + R_DEBUG_REASON_NEW_PID, + R_DEBUG_REASON_NEW_TID, + R_DEBUG_REASON_NEW_LIB, + R_DEBUG_REASON_EXIT_PID, + R_DEBUG_REASON_EXIT_TID, + R_DEBUG_REASON_EXIT_LIB, + R_DEBUG_REASON_TRAP, + R_DEBUG_REASON_SWI, + R_DEBUG_REASON_INT, + R_DEBUG_REASON_FPU, + R_DEBUG_REASON_USERSUSP, +} RzDebugReasonType; + + +/* TODO: move to rz_anal */ +typedef struct rz_debug_frame_t { + ut64 addr; + int size; + ut64 sp; + ut64 bp; +} RzDebugFrame; + +typedef struct rz_debug_reason_t { + int /*RzDebugReasonType*/ type; + int tid; + int signum; + ut64 bp_addr; + ut64 timestamp; + ut64 addr; + ut64 ptr; +} RzDebugReason; + +typedef struct rz_debug_map_t { + char *name; + ut64 addr; + ut64 addr_end; + ut64 size; + ut64 offset; + char *file; + int perm; + int user; + bool shared; +} RzDebugMap; + +typedef struct rz_debug_signal_t { + int type; + int num; + ut64 handler; +} RzDebugSignal; + +typedef struct rz_debug_desc_t { + int fd; + char *path; + int perm; + int type; + ut64 off; +} RzDebugDesc; + +typedef struct rz_debug_snap_t { + char *name; + ut64 addr; + ut64 addr_end; + ut32 size; + ut8 *data; + int perm; + int user; + bool shared; +} RzDebugSnap; + +typedef struct { + int cnum; + ut64 data; +} RzDebugChangeReg; + +typedef struct { + int cnum; + ut8 data; +} RzDebugChangeMem; + +typedef struct rz_debug_checkpoint_t { + int cnum; + RzRegArena *arena[R_REG_TYPE_LAST]; + RzList *snaps; // +} RzDebugCheckpoint; + +typedef struct rz_debug_session_t { + ut32 cnum; + ut32 maxcnum; + RzDebugCheckpoint *cur_chkpt; + RzVector *checkpoints; /* RzVector */ + HtUP *memory; /* RzVector */ + HtUP *registers; /* RzVector */ + int reasontype /*RzDebugReasonType*/; + RBreakpointItem *bp; +} RzDebugSession; + +/* Session file format */ +typedef struct rz_session_header { + ut64 addr; + ut32 id; + ut32 difflist_len; +} RSessionHeader; + +typedef struct rz_diff_entry { + ut32 base_idx; + ut32 pages_len; +} RzDiffEntry; + +typedef struct rz_snap_entry { + ut64 addr; + ut32 size; + ut64 timestamp; + int perm; +} RSnapEntry; + +typedef struct rz_debug_trace_t { + RzList *traces; + int count; + int enabled; + //int changed; + int tag; + int dup; + char *addresses; + // TODO: add range here + HtPP *ht; +} RzDebugTrace; + +typedef struct rz_debug_tracepoint_t { + ut64 addr; + ut64 tags; // XXX + int tag; // XXX + int size; + int count; + int times; + ut64 stamp; +} RzDebugTracepoint; + +typedef struct rz_debug_t { + char *arch; + int bits; /// XXX: MUST SET /// + int hitinfo; + + int main_pid; + int pid; /* selected process id */ + int tid; /* selected thread id */ + int forked_pid; /* last pid created by fork */ + int n_threads; + RzList *threads; /* NOTE: list contents are platform-specific */ + + char *malloc; /*choose malloc parser: 0 = glibc, 1 = jemalloc*/ + + /* dbg.* config options (see e?dbg) + * NOTE: some settings are checked inline instead of tracked here. + */ + int bpsize; /* size of a breakpoint */ + char *btalgo; /* select backtrace algorithm */ + int btdepth; /* backtrace depth */ + int regcols; /* display columns */ + int swstep; /* steps with software traps */ + int stop_all_threads; /* stop all threads at any stop */ + int trace_forks; /* stop on new children */ + int trace_execs; /* stop on new execs */ + int trace_aftersyscall; /* stop after the syscall (before if disabled) */ + int trace_clone; /* stop on new threads */ + int follow_child; /* On fork, trace the child */ + char *glob_libs; /* stop on lib load */ + char *glob_unlibs; /* stop on lib unload */ + bool consbreak; /* SIGINT handle for attached processes */ + bool continue_all_threads; + + /* tracking debugger state */ + int steps; /* counter of steps done */ + RzDebugReason reason; /* stop reason */ + RzDebugRecoilMode recoil_mode; /* what did the user want to do? */ + ut64 stopaddr; /* stop address */ + + /* tracing vars */ + RzDebugTrace *trace; + Sdb *tracenodes; + RTree *tree; + RzList *call_frames; + + RzReg *reg; + RzList *q_regs; + const char *creg; // current register value + RBreakpoint *bp; + void *user; // XXX(jjd): unused?? meant for caller's use?? + char *snap_path; + + /* io */ + PrintfCallback cb_printf; + RzIOBind iob; + + struct rz_debug_plugin_t *h; + RzList *plugins; + + bool pc_at_bp; /* after a breakpoint, is the pc at the bp? */ + bool pc_at_bp_set; /* is the pc_at_bp variable set already? */ + + REvent *ev; + + RzAnal *anal; + RzList *maps; // + RzList *maps_user; // + + bool trace_continue; + RzAnalOp *cur_op; + RzDebugSession *session; + + Sdb *sgnls; + RzCoreBind corebind; + // internal use only + int _mode; + RNum *num; + RzEgg *egg; + bool verbose; + bool main_arena_resolved; /* is the main_arena resolved already? */ + int glibc_version; +} RzDebug; + +typedef struct rz_debug_desc_plugin_t { + int (*open)(const char *path); + int (*close)(int fd); + int (*read)(int fd, ut64 addr, int len); + int (*write)(int fd, ut64 addr, int len); + int (*seek)(int fd, ut64 addr); + int (*dup)(int fd, int newfd); + RzList* (*list)(int pid); +} RzDebugDescPlugin; + +typedef struct rz_debug_info_t { + int pid; + int tid; + int uid; + int gid; + char *usr; + char *exe; + char *cmdline; + char *libname; + char *cwd; + int status; // zombie, running, sleeping, ... + int signum; + void * lib; + void * thread; + char *kernel_stack; + // retrieve mem/fd/core limits? + // list of threads ? hasthreads? counter? + // environment? + // /proc/pid/syscall ??? +} RzDebugInfo; + +/* TODO: pass dbg and user data pointer everywhere */ +typedef struct rz_debug_plugin_t { + const char *name; + const char *license; + const char *author; + const char *version; + //const char **archs; // MUST BE DEPRECATED!!!! + ut32 bits; + const char *arch; + int canstep; + int keepio; + /* life */ + RzDebugInfo* (*info)(RzDebug *dbg, const char *arg); + int (*startv)(int argc, char **argv); + int (*attach)(RzDebug *dbg, int pid); + int (*detach)(RzDebug *dbg, int pid); + int (*select)(RzDebug *dbg, int pid, int tid); + RzList *(*threads)(RzDebug *dbg, int pid); + RzList *(*pids)(RzDebug *dbg, int pid); + RzList *(*tids)(RzDebug *dbg, int pid); + RFList (*backtrace)(RzDebug *dbg, int count); + /* flow */ + int (*stop)(RzDebug *dbg); + int (*step)(RzDebug *dbg); + int (*step_over)(RzDebug *dbg); + int (*cont)(RzDebug *dbg, int pid, int tid, int sig); + int (*wait)(RzDebug *dbg, int pid); + bool (*gcore)(RzDebug *dbg, RBuffer *dest); + bool (*kill)(RzDebug *dbg, int pid, int tid, int sig); + RzList* (*kill_list)(RzDebug *dbg); + int (*contsc)(RzDebug *dbg, int pid, int sc); + RzList* (*frames)(RzDebug *dbg, ut64 at); + RBreakpointCallback breakpoint; +// XXX: specify, pid, tid, or RzDebug ? + int (*reg_read)(RzDebug *dbg, int type, ut8 *buf, int size); + int (*reg_write)(RzDebug *dbg, int type, const ut8 *buf, int size); //XXX struct rz_regset_t regs); + char* (*reg_profile)(RzDebug *dbg); + int (*set_reg_profile)(const char *str); + /* memory */ + RzList *(*map_get)(RzDebug *dbg); + RzList *(*modules_get)(RzDebug *dbg); + RzDebugMap* (*map_alloc)(RzDebug *dbg, ut64 addr, int size, bool thp); + int (*map_dealloc)(RzDebug *dbg, ut64 addr, int size); + int (*map_protect)(RzDebug *dbg, ut64 addr, int size, int perms); + int (*init)(RzDebug *dbg); + int (*drx)(RzDebug *dbg, int n, ut64 addr, int size, int rwx, int g, int api_type); + RzDebugDescPlugin desc; + // TODO: use RzList here +} RzDebugPlugin; + +// TODO: rename to rz_debug_process_t ? maybe a thread too ? +typedef struct rz_debug_pid_t { + int pid; + int ppid; + char status; /* stopped, running, zombie, sleeping ,... */ + int runnable; /* when using 'run', 'continue', .. this proc will be runnable */ + bool signalled; + char *path; + int uid; + int gid; + ut64 pc; +} RzDebugPid; + +/* + * Radare's debugger has both an external and internal API. + * + * TODO(jjd): reconcile external API and extend it for better funcitonality + * when using R2 as a library. + */ +#ifdef RZ_API +RZ_API RzDebug *rz_debug_new(int hard); +RZ_API RzDebug *rz_debug_free(RzDebug *dbg); + +RZ_API int rz_debug_attach(RzDebug *dbg, int pid); +RZ_API int rz_debug_detach(RzDebug *dbg, int pid); +RZ_API int rz_debug_startv(RzDebug *dbg, int argc, char **argv); +RZ_API int rz_debug_start(RzDebug *dbg, const char *cmd); + +/* reason we stopped */ +RZ_API RzDebugReasonType rz_debug_stop_reason(RzDebug *dbg); +RZ_API const char *rz_debug_reason_to_string(int type); + +/* wait for another event */ +RZ_API RzDebugReasonType rz_debug_wait(RzDebug *dbg, RBreakpointItem **bp); + +/* continuations */ +RZ_API int rz_debug_step(RzDebug *dbg, int steps); +RZ_API int rz_debug_step_over(RzDebug *dbg, int steps); +RZ_API int rz_debug_continue_until(RzDebug *dbg, ut64 addr); +RZ_API int rz_debug_continue_until_nonblock(RzDebug *dbg, ut64 addr); +RZ_API int rz_debug_continue_until_optype(RzDebug *dbg, int type, int over); +RZ_API int rz_debug_continue_until_nontraced(RzDebug *dbg); +RZ_API int rz_debug_continue_syscall(RzDebug *dbg, int sc); +RZ_API int rz_debug_continue_syscalls(RzDebug *dbg, int *sc, int n_sc); +RZ_API int rz_debug_continue(RzDebug *dbg); +RZ_API int rz_debug_continue_kill(RzDebug *dbg, int signal); +#if __WINDOWS__ +RZ_API int rz_debug_continue_pass_exception(RzDebug *dbg); +#endif + +/* process/thread handling */ +RZ_API bool rz_debug_select(RzDebug *dbg, int pid, int tid); +//RZ_API int rz_debug_pid_add(RzDebug *dbg); +//RZ_API int rz_debug_pid_add_thread(RzDebug *dbg); +//RZ_API int rz_debug_pid_del(RzDebug *dbg); +//RZ_API int rz_debug_pid_del_thread(RzDebug *dbg); +RZ_API int rz_debug_pid_list(RzDebug *dbg, int pid, char fmt); +RZ_API RzDebugPid *rz_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc); +RZ_API RzDebugPid *rz_debug_pid_free(RzDebugPid *pid); +RZ_API RzList *rz_debug_pids(RzDebug *dbg, int pid); + +RZ_API bool rz_debug_set_arch(RzDebug *dbg, const char *arch, int bits); +RZ_API bool rz_debug_use(RzDebug *dbg, const char *str); + +RZ_API RzDebugInfo *rz_debug_info(RzDebug *dbg, const char *arg); +RZ_API void rz_debug_info_free (RzDebugInfo *rdi); + +RZ_API ut64 rz_debug_get_baddr(RzDebug *dbg, const char *file); + +/* send signals */ +RZ_API void rz_debug_signal_init(RzDebug *dbg); +RZ_API int rz_debug_signal_send(RzDebug *dbg, int num); +RZ_API int rz_debug_signal_what(RzDebug *dbg, int num); +RZ_API int rz_debug_signal_resolve(RzDebug *dbg, const char *signame); +RZ_API const char *rz_debug_signal_resolve_i(RzDebug *dbg, int signum); +RZ_API void rz_debug_signal_setup(RzDebug *dbg, int num, int opt); +RZ_API int rz_debug_signal_set(RzDebug *dbg, int num, ut64 addr); +RZ_API void rz_debug_signal_list(RzDebug *dbg, int mode); +RZ_API int rz_debug_kill(RzDebug *dbg, int pid, int tid, int sig); +RZ_API RzList *rz_debug_kill_list(RzDebug *dbg); +// XXX: must be uint64 action +RZ_API int rz_debug_kill_setup(RzDebug *dbg, int sig, int action); + +/* handle.c */ +RZ_API void rz_debug_plugin_init(RzDebug *dbg); +RZ_API int rz_debug_plugin_set(RzDebug *dbg, const char *str); +RZ_API int rz_debug_plugin_list(RzDebug *dbg, int mode); +RZ_API bool rz_debug_plugin_add(RzDebug *dbg, RzDebugPlugin *foo); +RZ_API bool rz_debug_plugin_set_reg_profile(RzDebug *dbg, const char *str); + +/* memory */ +RZ_API RzList *rz_debug_modules_list(RzDebug*); +RZ_API RzDebugMap *rz_debug_map_alloc(RzDebug *dbg, ut64 addr, int size, bool thp); +RZ_API int rz_debug_map_dealloc(RzDebug *dbg, RzDebugMap *map); +RZ_API RzList *rz_debug_map_list_new(void); +RZ_API RzDebugMap *rz_debug_map_get(RzDebug *dbg, ut64 addr); +RZ_API RzDebugMap *rz_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user); +RZ_API void rz_debug_map_free(RzDebugMap *map); +RZ_API void rz_debug_map_list(RzDebug *dbg, ut64 addr, const char *input); +RZ_API void rz_debug_map_list_visual(RzDebug *dbg, ut64 addr, const char *input, int colors); + +/* descriptors */ +RZ_API RzDebugDesc *rz_debug_desc_new (int fd, char* path, int perm, int type, int off); +RZ_API void rz_debug_desc_free (RzDebugDesc *p); +RZ_API int rz_debug_desc_open(RzDebug *dbg, const char *path); +RZ_API int rz_debug_desc_close(RzDebug *dbg, int fd); +RZ_API int rz_debug_desc_dup(RzDebug *dbg, int fd, int newfd); +RZ_API int rz_debug_desc_read(RzDebug *dbg, int fd, ut64 addr, int len); +RZ_API int rz_debug_desc_seek(RzDebug *dbg, int fd, ut64 addr); // TODO: whence? +RZ_API int rz_debug_desc_write(RzDebug *dbg, int fd, ut64 addr, int len); +RZ_API int rz_debug_desc_list(RzDebug *dbg, int rad); + +/* registers */ +RZ_API int rz_debug_reg_sync(RzDebug *dbg, int type, int write); +RZ_API bool rz_debug_reg_list(RzDebug *dbg, int type, int size, int rad, const char *use_color); +RZ_API int rz_debug_reg_set(RzDebug *dbg, const char *name, ut64 num); +RZ_API ut64 rz_debug_reg_get(RzDebug *dbg, const char *name); +RZ_API ut64 rz_debug_reg_get_err(RzDebug *dbg, const char *name, int *err, utX *value); + +RZ_API ut64 rz_debug_execute(RzDebug *dbg, const ut8 *buf, int len, int restore); +RZ_API bool rz_debug_map_sync(RzDebug *dbg); + +RZ_API int rz_debug_stop(RzDebug *dbg); + +/* backtrace */ +RZ_API RzList *rz_debug_frames(RzDebug *dbg, ut64 at); + +RZ_API bool rz_debug_is_dead(RzDebug *dbg); +RZ_API int rz_debug_map_protect(RzDebug *dbg, ut64 addr, int size, int perms); +/* args XXX: weird food */ +RZ_API ut64 rz_debug_arg_get(RzDebug *dbg, int fast, int num); +RZ_API bool rz_debug_arg_set(RzDebug *dbg, int fast, int num, ut64 value); + +/* breakpoints (most in rz_bp, this calls those) */ +RZ_API RBreakpointItem *rz_debug_bp_add(RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, char *module, st64 m_delta); +RZ_API void rz_debug_bp_rebase(RzDebug *dbg, ut64 old_base, ut64 new_base); +RZ_API void rz_debug_bp_update(RzDebug *dbg); + +/* pid */ +RZ_API int rz_debug_thread_list(RzDebug *dbg, int pid, char fmt); + +RZ_API void rz_debug_tracenodes_reset(RzDebug *dbg); + +RZ_API void rz_debug_trace_reset(RzDebug *dbg); +RZ_API int rz_debug_trace_pc(RzDebug *dbg, ut64 pc); +RZ_API void rz_debug_trace_op(RzDebug *dbg, RzAnalOp *op); +RZ_API void rz_debug_trace_at(RzDebug *dbg, const char *str); +RZ_API RzDebugTracepoint *rz_debug_trace_get(RzDebug *dbg, ut64 addr); +RZ_API void rz_debug_trace_list(RzDebug *dbg, int mode, ut64 offset); +RZ_API RzDebugTracepoint *rz_debug_trace_add(RzDebug *dbg, ut64 addr, int size); +RZ_API RzDebugTrace *rz_debug_trace_new(void); +RZ_API void rz_debug_trace_free(RzDebugTrace *dbg); +RZ_API int rz_debug_trace_tag(RzDebug *dbg, int tag); +RZ_API int rz_debug_child_fork(RzDebug *dbg); +RZ_API int rz_debug_child_clone(RzDebug *dbg); + +RZ_API void rz_debug_drx_list(RzDebug *dbg); +RZ_API int rz_debug_drx_set(RzDebug *dbg, int idx, ut64 addr, int len, int rwx, int g); +RZ_API int rz_debug_drx_unset(RzDebug *dbg, int idx); + +/* esil */ +RZ_API ut64 rz_debug_num_callback(RNum *userptr, const char *str, int *ok); +RZ_API int rz_debug_esil_stepi(RzDebug *dbg); +RZ_API ut64 rz_debug_esil_step(RzDebug *dbg, ut32 count); +RZ_API ut64 rz_debug_esil_continue(RzDebug *dbg); +RZ_API void rz_debug_esil_watch(RzDebug *dbg, int rwx, int dev, const char *expr); +RZ_API void rz_debug_esil_watch_reset(RzDebug *dbg); +RZ_API void rz_debug_esil_watch_list(RzDebug *dbg); +RZ_API int rz_debug_esil_watch_empty(RzDebug *dbg); +RZ_API void rz_debug_esil_prestep (RzDebug *d, int p); + +/* record & replay */ +// RZ_API ut8 rz_debug_get_byte(RzDebug *dbg, ut32 cnum, ut64 addr); +RZ_API bool rz_debug_add_checkpoint(RzDebug *dbg); +RZ_API bool rz_debug_session_add_reg_change(RzDebugSession *session, int arena, ut64 offset, ut64 data); +RZ_API bool rz_debug_session_add_mem_change(RzDebugSession *session, ut64 addr, ut8 data); +RZ_API void rz_debug_session_restore_reg_mem(RzDebug *dbg, ut32 cnum); +RZ_API void rz_debug_session_list_memory(RzDebug *dbg); +RZ_API void rz_debug_session_serialize(RzDebugSession *session, Sdb *db); +RZ_API void rz_debug_session_deserialize(RzDebugSession *session, Sdb *db); +RZ_API bool rz_debug_session_save(RzDebugSession *session, const char *file); +RZ_API bool rz_debug_session_load(RzDebug *dbg, const char *file); +RZ_API bool rz_debug_trace_ins_before(RzDebug *dbg); +RZ_API bool rz_debug_trace_ins_after(RzDebug *dbg); + +RZ_API RzDebugSession *rz_debug_session_new(void); +RZ_API void rz_debug_session_free(RzDebugSession *session); + +RZ_API RzDebugSnap *rz_debug_snap_map(RzDebug *dbg, RzDebugMap *map); +RZ_API bool rz_debug_snap_contains(RzDebugSnap *snap, ut64 addr); +RZ_API ut8 *rz_debug_snap_get_hash(RzDebugSnap *snap); +RZ_API bool rz_debug_snap_is_equal(RzDebugSnap *a, RzDebugSnap *b); +RZ_API void rz_debug_snap_free(RzDebugSnap *snap); + +RZ_API int rz_debug_step_back(RzDebug *dbg, int steps); +RZ_API bool rz_debug_goto_cnum(RzDebug *dbg, ut32 cnum); +RZ_API int rz_debug_step_cnum(RzDebug *dbg, int steps); +RZ_API bool rz_debug_continue_back(RzDebug *dbg); + +/* ptrace */ +#if HAVE_PTRACE +static inline long rz_debug_ptrace(RzDebug *dbg, rz_ptrace_request_t request, pid_t pid, void *addr, rz_ptrace_data_t data) { + return dbg->iob.ptrace (dbg->iob.io, request, pid, addr, data); +} + +static inline void *rz_debug_ptrace_func(RzDebug *dbg, void *(*func)(void *), void *user) { + return dbg->iob.ptrace_func (dbg->iob.io, func, user); +} +#endif + +/* plugin pointers */ +extern RzDebugPlugin rz_debug_plugin_native; +extern RzDebugPlugin rz_debug_plugin_esil; +extern RzDebugPlugin rz_debug_plugin_rap; +extern RzDebugPlugin rz_debug_plugin_gdb; +extern RzDebugPlugin rz_debug_plugin_bf; +extern RzDebugPlugin rz_debug_plugin_io; +extern RzDebugPlugin rz_debug_plugin_winkd; +extern RzDebugPlugin rz_debug_plugin_windbg; +extern RzDebugPlugin rz_debug_plugin_bochs; +extern RzDebugPlugin rz_debug_plugin_qnx; +extern RzDebugPlugin rz_debug_plugin_null; +#endif + +#ifdef __cplusplus +} +#endif + +#endif + +/* regset */ +//RZ_API struct rz_regset_t* rz_regset_diff(struct rz_regset_t *a, struct rz_regset_t *b); +//RZ_API int rz_regset_set(struct rz_regset_t *r, int idx, const char *name, ut64 value); +//RZ_API struct rz_regset_t *rz_regset_new(int size); +//RZ_API void rz_regset_free(struct rz_regset_t *r); + +#if 0 +Missing callbacks +================= + - alloc + - dealloc + - list maps (memory regions) + - change memory protections + - touchtrace + - filedescriptor set/get/mod.. + - get/set signals + - get regs, set regs + +#endif diff --git a/librz/include/rz_diff.h b/librz/include/rz_diff.h new file mode 100644 index 0000000000..c8b0d306c1 --- /dev/null +++ b/librz/include/rz_diff.h @@ -0,0 +1,86 @@ +#ifndef R2_DIFF_H +#define R2_DIFF_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_diff); + +#define Color_INSERT Color_BGREEN +#define Color_DELETE Color_BRED +#define Color_BGINSERT "\x1b[48;5;22m" +#define Color_BGDELETE "\x1b[48;5;52m" +#define Color_HLINSERT Color_BGINSERT Color_INSERT +#define Color_HLDELETE Color_BGDELETE Color_DELETE + +typedef struct rz_diff_op_t { + /* file A */ + ut64 a_off; + const ut8 *a_buf; + ut32 a_len; + + /* file B */ + ut64 b_off; + const ut8 *b_buf; + ut32 b_len; +} RzDiffOp; + +//typedef struct rz_diff_t RzDiff; + +typedef struct rz_diff_t { + ut64 off_a; + ut64 off_b; + int delta; + void *user; + bool verbose; + int type; + const char *diff_cmd; + int (*callback)(struct rz_diff_t *diff, void *user, RzDiffOp *op); +} RzDiff; + +typedef int (*RzDiffCallback)(RzDiff *diff, void *user, RzDiffOp *op); + +typedef struct rz_diffchar_t { + const ut8 *align_a; + const ut8 *align_b; + size_t len_buf; + size_t start_align; +} RzDiffChar; + +/* XXX: this api needs to be reviewed , constructor with offa+offb?? */ +#ifdef RZ_API +RZ_API RzDiff *rz_diff_new(void); +RZ_API RzDiff *rz_diff_new_from(ut64 off_a, ut64 off_b); +RZ_API RzDiff *rz_diff_free(RzDiff *d); + +RZ_API int rz_diff_buffers(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb); +RZ_API int rz_diff_buffers_static(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb); +RZ_API int rz_diff_buffers_radiff(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb); +RZ_API int rz_diff_buffers_delta(RzDiff *diff, const ut8 *sa, int la, const ut8 *sb, int lb); +RZ_API int rz_diff_buffers(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb); +RZ_API char *rz_diff_buffers_to_string(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb); +RZ_API int rz_diff_set_callback(RzDiff *d, RzDiffCallback callback, void *user); +RZ_API bool rz_diff_buffers_distance(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); +RZ_API bool rz_diff_buffers_distance_myers(RzDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); +RZ_API bool rz_diff_buffers_distance_levenstein(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity); +RZ_API char *rz_diff_buffers_unified(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb); +/* static method !??! */ +RZ_API int rz_diff_lines(const char *file1, const char *sa, int la, const char *file2, const char *sb, int lb); +RZ_API int rz_diff_set_delta(RzDiff *d, int delta); +RZ_API int rz_diff_gdiff(const char *file1, const char *file2, int rad, int va); + +RZ_API RzDiffChar *rz_diffchar_new(const ut8 *a, const ut8 *b); +RZ_API void rz_diffchar_print(RzDiffChar *diffchar); +RZ_API void rz_diffchar_free(RzDiffChar *diffchar); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_drx.h b/librz/include/rz_drx.h similarity index 100% rename from libr/include/r_drx.h rename to librz/include/rz_drx.h diff --git a/librz/include/rz_egg.h b/librz/include/rz_egg.h new file mode 100644 index 0000000000..bd5823b4b4 --- /dev/null +++ b/librz/include/rz_egg.h @@ -0,0 +1,240 @@ +#ifndef R2_EGG_H +#define R2_EGG_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_egg); + +#define R_EGG_INCDIR_ENV "EGG_INCDIR" +#define R_EGG_INCDIR_PATH "/lib/rizin/" R2_VERSION "/egg" + +// rename to RzEggShellcode +#define R_EGG_PLUGIN_SHELLCODE 0 +#define R_EGG_PLUGIN_ENCODER 1 + +typedef struct rz_egg_plugin_t { + const char *name; + const char *desc; + int type; + RBuffer* (*build) (void *egg); +} RzEggPlugin; + +typedef struct rz_egg_lang_t { + int pushargs; + int nalias; + int nsyscalls; + char *conditionstr; + char *syscallbody; + char *includefile; + char *setenviron; + char *mathline; + // used for confusing mathop + int commentmode; + int varsize; + int varxs; + int lastctxdelta; + int nargs; + int docall; + int nfunctions; + int nbrackets; + int slurpin; + int slurp; + int line; + char elem[1024]; + int attsyntax; + int elem_n; + char *callname; + char *endframe; + char *ctxpush[32]; + char *file; + char *dstvar; + char *dstval; + char *includedir; + char *ifelse_table[32][32]; + // used to solve if-else problem in a not so ugly way + int ndstval; + int skipline;// BOOL + int quoteline; + int quotelinevar; + int stackframe; + int stackfixed; + int oc; + int mode; + int inlinectr; + struct { + char *name; + char *body; + // int fastcall; /* TODO: NOT YET USED */ + } inlines[256]; + int ninlines; + struct { + char *name; + char *arg; + } syscalls[256]; + struct { + char *name; + char *content; + } aliases[256]; + char *nested[32]; + char *nested_callname[32]; + // char *nestede[32] = {0}; + // seems nestede are not used any more + // (only one place that gives nestede[] value, where could be replaced) + int nestedi[32]; +} RzEggLang; + +typedef struct rz_egg_t { + RBuffer *src; + RBuffer *buf; + RBuffer *bin; + RzList *list; + //RzList *shellcodes; // XXX is plugins nao? + RzAsm *rasm; + RzSyscall *syscall; + RzEggLang lang; + Sdb *db; + RzList *plugins; + RzList *patches; // + struct rz_egg_emit_t *remit; + int arch; + int endian; + int bits; + ut32 os; + int context; +} RzEgg; + +/* XXX: this may fail in different arches */ +#if 0 +r2 -q - <plugins +RZ_API void rz_egg_option_set (RzEgg *egg, const char *k, const char *v); +RZ_API char *rz_egg_option_get (RzEgg *egg, const char *k); +RZ_API void rz_egg_if(RzEgg *egg, const char *reg, char cmp, int v); +RZ_API void rz_egg_printf(RzEgg *egg, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API int rz_egg_compile(RzEgg *egg); +RZ_API int rz_egg_padding (RzEgg *egg, const char *pad); +RZ_API bool rz_egg_assemble(RzEgg *egg); +RZ_API bool rz_egg_assemble_asm(RzEgg *egg, char **asm_list); +RZ_API void rz_egg_pattern(RzEgg *egg, int size); +RZ_API RBuffer *rz_egg_get_bin(RzEgg *egg); +//RZ_API int rz_egg_dump (RzEgg *egg, const char *file) { } +RZ_API char *rz_egg_get_source(RzEgg *egg); +RZ_API RBuffer *rz_egg_get_bin(RzEgg *egg); +RZ_API char *rz_egg_get_assembly(RzEgg *egg); +RZ_API void rz_egg_append(RzEgg *egg, const char *src); +RZ_API int rz_egg_run(RzEgg *egg); +RZ_API int rz_egg_run_rop(RzEgg *egg); +RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *b, int l); +RZ_API void rz_egg_finalize(RzEgg *egg); + +/* rz_egg_Cfile.c */ +RZ_API char* rz_egg_Cfile_parser(const char *file, const char *arch, const char *os, int bits); + +/* lang.c */ +RZ_API char *rz_egg_mkvar(RzEgg *egg, char *out, const char *_str, int delta); +RZ_API int rz_egg_lang_parsechar(RzEgg *egg, char c); +RZ_API void rz_egg_lang_include_path (RzEgg *egg, const char *path); +RZ_API void rz_egg_lang_include_init (RzEgg *egg); + +/* plugin pointers */ +extern RzEggPlugin rz_egg_plugin_xor; +extern RzEggPlugin rz_egg_plugin_shya; +extern RzEggPlugin rz_egg_plugin_exec; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_endian.h b/librz/include/rz_endian.h new file mode 100644 index 0000000000..b394eca9c0 --- /dev/null +++ b/librz/include/rz_endian.h @@ -0,0 +1,556 @@ +#ifndef R_ENDIAN_H +#define R_ENDIAN_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Endian agnostic functions working on single byte. */ + +static inline ut8 rz_read_ble8(const void *src) { + if (!src) { + return UT8_MAX; + } + return *(const ut8 *)src; +} + +static inline ut8 rz_read_at_ble8(const void *src, size_t offset) { + return rz_read_ble8 (((const ut8*)src) + offset); +} + +static inline void rz_write_ble8(void *dest, ut8 val) { + *(ut8 *)dest = val; +} + +static inline void rz_write_at_ble8(void *dest, ut8 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_ble8 (d, val); +} + +/* Big Endian functions. */ + +static inline ut8 rz_read_be8(const void *src) { + return rz_read_ble8 (src); +} + +static inline ut8 rz_read_at_be8(const void *src, size_t offset) { + return rz_read_at_ble8 (src, offset); +} + +static inline void rz_write_be8(void *dest, ut8 val) { + rz_write_ble8 (dest, val); +} + +static inline void rz_write_at_be8(void *dest, ut8 val, size_t offset) { + rz_write_at_ble8 (dest, val, offset); +} + +static inline ut16 rz_read_be16(const void *src) { + const ut8 *s = (const ut8*)src; + return (((ut16)s[0]) << 8) | (((ut16)s[1]) << 0); +} + +static inline ut16 rz_read_at_be16(const void *src, size_t offset) { + const ut8 *s = (const ut8*)src + offset; + return rz_read_be16 (s); +} + +static inline void rz_write_be16(void *dest, ut16 val) { + rz_write_be8 (dest, val >> 8); + rz_write_at_be8 (dest, (ut8)val, sizeof (ut8)); +} + +static inline void rz_write_at_be16(void *dest, ut16 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_be16 (d, val); +} + +static inline ut32 rz_read_be32(const void *src) { + const ut8 *s = (const ut8*)src; + return (((ut32)s[0]) << 24) | (((ut32)s[1]) << 16) | + (((ut32)s[2]) << 8) | (((ut32)s[3]) << 0); +} + +static inline ut32 rz_read_at_be32(const void *src, size_t offset) { + const ut8 *s = (const ut8*)src + offset; + return rz_read_be32 (s); +} + +static inline void rz_write_be32(void *dest, ut32 val) { + rz_write_be16 (dest, val >> 16); + rz_write_at_be16 (dest, val, sizeof (ut16)); +} + +static inline void rz_write_be24(void *_dest, ut32 val) { + ut8 *dest = (ut8*)_dest; + rz_write_be8 (dest++, val >> 16); + rz_write_be8 (dest++, val >> 8); + rz_write_be8 (dest, val); +} + +static inline void rz_write_at_be32(void *dest, ut32 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_be32 (d, val); +} + +static inline ut64 rz_read_be64(const void *src) { + ut64 val = ((ut64)(rz_read_be32 (src))) << 32; + val |= rz_read_at_be32 (src, sizeof (ut32)); + return val; +} + +static inline ut64 rz_read_at_be64(const void *src, size_t offset) { + const ut8 *s = (const ut8*)src + offset; + return rz_read_be64 (s); +} + +static inline void rz_write_be64(void *dest, ut64 val) { + rz_write_be32 (dest, val >> 32); + rz_write_at_be32 (dest, (ut32)val, sizeof (ut32)); +} + +static inline void rz_write_at_be64(void *dest, ut64 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_be64 (d, val); +} + +/* Little Endian functions. */ + +static inline ut8 rz_read_le8(const void *src) { + if (!src) { + return UT8_MAX; + } + return rz_read_ble8 (src); +} + +static inline ut8 rz_read_at_le8(const void *src, size_t offset) { + return rz_read_at_ble8 (src, offset); +} + +static inline void rz_write_le8(void *dest, ut8 val) { + rz_write_ble8 (dest, val); +} + +static inline void rz_write_at_le8(void *dest, ut8 val, size_t offset) { + rz_write_at_ble8 (dest, val, offset); +} + +static inline ut16 rz_read_le16(const void *src) { + if (!src) { + return UT16_MAX; + } + const ut8 *s = (const ut8*)src; + return (((ut16)s[1]) << 8) | (((ut16)s[0]) << 0); +} + +static inline ut16 rz_read_at_le16(const void *src, size_t offset) { + if (!src) { + return UT16_MAX; + } + const ut8 *s = (const ut8*)src + offset; + return rz_read_le16 (s); +} + +static inline void rz_write_le16(void *dest, ut16 val) { + rz_write_le8 (dest, (ut8)val); + rz_write_at_le8 (dest, val >> 8, sizeof (ut8)); +} + +static inline void rz_write_at_le16(void *dest, ut16 val, size_t offset) { + ut8 *d = (ut8 *)dest + offset; + rz_write_le16 (d, val); +} + +static inline void rz_write_le24(void *_dest, ut32 val) { + ut8* dest = (ut8*)_dest; + rz_write_le8 (dest++, val); + rz_write_le8 (dest++, val >> 8); + rz_write_le8 (dest, val >> 16); +} + +static inline ut32 rz_read_le32(const void *src) { + if (!src) { + return UT32_MAX; + } + const ut8 *s = (const ut8*)src; + return (((ut32)s[3]) << 24) | (((ut32)s[2]) << 16) | + (((ut32)s[1]) << 8) | (((ut32)s[0]) << 0); +} + +static inline ut32 rz_read_at_le32(const void *src, size_t offset) { + if (!src) { + return UT32_MAX; + } + const ut8 *s = (const ut8*)src + offset; + return rz_read_le32 (s); +} + +static inline void rz_write_le32(void *dest, ut32 val) { + rz_write_le16 (dest, val); + rz_write_at_le16 (dest, val >> 16, sizeof (ut16)); +} + +static inline void rz_write_at_le32(void *dest, ut32 val, size_t offset) { + ut8 *d = ((ut8*)dest) + offset; + rz_write_le32 (d, val); +} + +static inline ut64 rz_read_le64(const void *src) { + ut64 val = ((ut64)(rz_read_at_le32 (src, sizeof (ut32)))) << 32; + val |= rz_read_le32 (src); + return val; +} + +static inline ut64 rz_read_at_le64(const void *src, size_t offset) { + const ut8 *s = ((const ut8*)src) + offset; + return rz_read_le64 (s); +} + +static inline void rz_write_le64(void *dest, ut64 val) { + rz_write_le32 (dest, (ut32)val); + rz_write_at_le32 (dest, val >> 32, sizeof (ut32)); +} + +static inline void rz_write_at_le64(void *dest, ut64 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_le64 (d, val); +} + +/* Middle Endian functions. */ + +static inline ut8 rz_read_me8(const void *src) { + return src ? rz_read_ble8 (src): UT8_MAX; +} + +static inline ut8 rz_read_at_me8(const void *src, size_t offset) { + return rz_read_at_ble8 (src, offset); +} + +static inline void rz_write_me8(void *dest, ut8 val) { + rz_write_ble8 (dest, val); +} + +static inline void rz_write_at_me8(void *dest, ut8 val, size_t offset) { + rz_write_at_ble8 (dest, val, offset); +} + +static inline ut16 rz_read_me16(const void *src) { + if (!src) { + return UT16_MAX; + } + const ut8 *s = (const ut8*)src; + return (((ut16)s[0]) << 8) | (((ut16)s[1]) << 0); +} + +static inline ut16 rz_read_at_me16(const void *src, size_t offset) { + if (!src) { + return UT16_MAX; + } + const ut8 *s = (const ut8*)src + offset; + return rz_read_me16 (s); +} + +static inline void rz_write_me16(void *dest, ut16 val) { + rz_write_me8 (dest, val >> 8); + rz_write_at_me8 (dest, (ut8)val, sizeof (ut8)); +} + +static inline void rz_write_at_me16(void *dest, ut16 val, size_t offset) { + ut8 *d = (ut8 *)dest + offset; + rz_write_me16 (d, val); +} + +static inline ut32 rz_read_me32(const void *src) { + if (!src) { + return UT32_MAX; + } + const ut8 *s = (const ut8*)src; + return (((ut32)s[2]) << 24) | (((ut32)s[1]) << 16) | + (((ut32)s[0]) << 8) | (((ut32)s[1]) << 0); +} + +static inline ut32 rz_read_at_me32(const void *src, size_t offset) { + if (!src) { + return UT32_MAX; + } + const ut8 *s = (const ut8*)src + offset; + return rz_read_me32 (s); +} + +static inline void rz_write_me32(void *dest, ut32 val) { + rz_write_me16 (dest, val); + rz_write_at_me16 (dest, val >> 16, sizeof (ut16)); +} + +static inline void rz_write_at_me32(void *dest, ut32 val, size_t offset) { + ut8 *d = ((ut8*)dest) + offset; + rz_write_me32 (d, val); +} + +static inline ut64 rz_read_me64(const void *src) { + ut64 val = ((ut64)(rz_read_at_me32 (src, sizeof (ut32)))) << 32; + val |= rz_read_me32 (src); + return val; +} + +static inline ut64 rz_read_at_me64(const void *src, size_t offset) { + const ut8 *s = ((const ut8*)src) + offset; + return rz_read_me64 (s); +} + +static inline void rz_write_me64(void *dest, ut64 val) { + rz_write_me32 (dest, (ut32)val); + rz_write_at_me32 (dest, val >> 32, sizeof (ut32)); +} + +static inline void rz_write_at_me64(void *dest, ut64 val, size_t offset) { + ut8 *d = (ut8*)dest + offset; + rz_write_me64 (d, val); +} + +/* Helper functions */ + +static inline ut16 rz_read_ble16(const void *src, bool big_endian) { + return big_endian? rz_read_be16 (src): rz_read_le16 (src); +} + +static inline ut32 rz_read_ble32(const void *src, bool big_endian) { + return big_endian? rz_read_be32 (src): rz_read_le32 (src); +} + +static inline ut64 rz_read_ble64(const void *src, bool big_endian) { + return big_endian? rz_read_be64 (src): rz_read_le64 (src); +} + +static inline ut16 rz_read_at_ble16(const void *src, size_t offset, bool big_endian) { + return big_endian ? rz_read_at_be16 (src, offset) : rz_read_at_le16 (src, offset); +} + +static inline ut32 rz_read_at_ble32(const void *src, size_t offset, bool big_endian) { + return big_endian ? rz_read_at_be32 (src, offset) : rz_read_at_le32 (src, offset); +} + +static inline ut64 rz_read_at_ble64(const void *src, size_t offset, bool big_endian) { + return big_endian ? rz_read_at_be64 (src, offset) : rz_read_at_le64 (src, offset); +} + +static inline ut64 rz_read_ble(const void *src, bool big_endian, int size) { + switch (size) { + case 8: + return (ut64) ((const ut8*)src)[0]; + case 16: + return rz_read_ble16 (src, big_endian); + case 32: + return rz_read_ble32 (src, big_endian); + case 64: + return rz_read_ble64 (src, big_endian); + default: + return UT64_MAX; + } +} + +static inline void rz_write_ble16(void *dest, ut16 val, bool big_endian) { + big_endian? rz_write_be16 (dest, val): rz_write_le16 (dest, val); +} + +static inline void rz_write_ble24(void *dest, ut32 val, bool big_endian) { + big_endian? rz_write_be24 (dest, val): rz_write_le24 (dest, val); +} + +static inline void rz_write_ble32(void *dest, ut32 val, bool big_endian) { + big_endian? rz_write_be32 (dest, val): rz_write_le32 (dest, val); +} + +static inline void rz_write_ble64(void *dest, ut64 val, bool big_endian) { + big_endian? rz_write_be64 (dest, val): rz_write_le64 (dest, val); +} + +static inline void rz_write_ble(void *dst, ut64 val, bool big_endian, int size) { + switch (size) { + case 8: + ((ut8*)dst)[0] = (ut8) val; + break; + case 16: + rz_write_ble16 (dst, (ut16) val, big_endian); + break; + case 24: + rz_write_ble24 (dst, (ut32) val, big_endian); + break; + case 32: + rz_write_ble32 (dst, (ut32) val, big_endian); + break; + case 64: + rz_write_ble64 (dst, val, big_endian); + break; + default: + break; + } +} + +// TODO: find better names and write vapis +#define ut8p_b(x) ((x)[0]) +#define ut8p_bw(x) ((x)[0]|((x)[1]<<8)) +#define ut8p_bd(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)) +#define ut8p_bq(x) ((x)[0]|((x)[1]<<8)|((x)[2]<<16)|((x)[3]<<24)|((x)[4]<<32)|((x)[5]<<40)|((x)[6]<<48)|((x)[7]<<56)) +#define ut8p_lw(x) ((x)[1]|((x)[0]<<8)) +#define ut8p_ld(x) ((x)[3]|((x)[2]<<8)|((x)[1]<<16)|((x)[0]<<24)) +#define ut8p_lq(x) ((x)[7]|((x)[6]<<8)|((x)[5]<<16)|((x)[4]<<24)|((x)[3]<<32)|((x)[2]<<40)|((x)[1]<<48)|((x)[0]<<56)) + +/*swap*/ +static inline ut16 rz_swap_ut16(ut16 val) { + return (val << 8) | (val >> 8 ); +} + +static inline st16 rz_swap_st16(st16 val) { + val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); + return (val << 16) | (val >> 16); +} + +static inline ut32 rz_swap_ut32(ut32 val) { + val = ((val << 8) & 0xFF00FF00 ) | ((val >> 8) & 0xFF00FF ); + return (val << 16) | (val >> 16); +} + +static inline st32 rz_swap_st32(st32 val) { + val = ((val << 8) & 0xFF00FF00) | ((val >> 8) & 0xFF00FF ); + return (val << 16) | ((val >> 16) & 0xFFFF); +} + +static inline ut64 rz_swap_ut64(ut64 val) { + val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); + val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); + return (val << 32) | (val >> 32); +} + +static inline st64 rz_swap_st64(st64 val) { + val = ((val << 8) & 0xFF00FF00FF00FF00ULL ) | ((val >> 8) & 0x00FF00FF00FF00FFULL ); + val = ((val << 16) & 0xFFFF0000FFFF0000ULL ) | ((val >> 16) & 0x0000FFFF0000FFFFULL ); + return (val << 32) | ((val >> 32) & 0xFFFFFFFFULL); +} + +/* Some "secured" functions, to do basic operation (mul, sub, add...) on integers */ +static inline int UT64_ADD(ut64 *r, ut64 a, ut64 b) { + if (UT64_MAX - a < b) { + return 0; + } + if (r) { + *r = a + b; + } + return 1; +} + +static inline int UT64_MUL(ut64 *r, ut64 a, ut64 b) { + if (a && UT64_MAX / a < b) { + return 0; + } + if (r) { + *r = a * b; + } + return 1; +} + +static inline int UT64_SUB(ut64 *r, ut64 a, ut64 b) { + if (b > a) { + return 0; + } + if (r) { + *r = a - b; + } + return 1; +} + +static inline int UT32_ADD(ut32 *r, ut32 a, ut32 b) { + if (UT32_MAX - a < b) { + return 0; + } + if (r) { + *r = a + b; + } + return 1; +} + +static inline int UT32_MUL(ut32 *r, ut32 a, ut32 b) { + if (a && UT32_MAX / a < b) { + return 0; + } + if (r) { + *r = a * b; + } + return 1; +} + +static inline int UT32_SUB(ut32 *r, ut32 a, ut32 b) { + if (b > a) { + return 0; + } + if (r) { + *r = a - b; + } + return 1; +} + +static inline int UT16_ADD(ut16 *r, ut16 a, ut16 b) { + if (UT16_MAX - a < b) { + return 0; + } + if (r) { + *r = a + b; + } + return 1; +} + +static inline int UT16_MUL(ut16 *r, ut16 a, ut16 b) { + if (a && UT16_MAX / a < b) { + return 0; + } + if (r) { + *r = a * b; + } + return 1; +} + +static inline int UT16_SUB(ut16 *r, ut16 a, ut16 b) { + if (b > a) { + return 0; + } + if (r) { + *r = a - b; + } + return 1; +} + +static inline int UT8_ADD(ut8 *r, ut8 a, ut8 b) { + if (UT8_MAX - a < b) { + return 0; + } + if (r) { + *r = a + b; + } + return 1; +} + +static inline int UT8_MUL(ut8 *r, ut8 a, ut8 b) { + if (a && UT8_MAX / a < b) { + return 0; + } + if (r) { + *r = a * b; + } + return 1; +} + +static inline int UT8_SUB(ut8 *r, ut8 a, ut8 b) { + if (b > a) { + return 0; + } + if (r) { + *r = a - b; + } + return 1; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_flag.h b/librz/include/rz_flag.h new file mode 100644 index 0000000000..54a802d746 --- /dev/null +++ b/librz/include/rz_flag.h @@ -0,0 +1,205 @@ +#ifndef R2_FLAGS_H +#define R2_FLAGS_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: rename to rz_flag_XXX api +R_LIB_VERSION_HEADER(rz_flag); + +#define R_FLAG_NAME_SIZE 512 + +/* zones.c */ + +#define R_FLAG_ZONE_USE_SDB 0 + +typedef struct rz_flag_zone_item_t { + ut64 from; + ut64 to; +#if R_FLAG_ZONE_USE_SDB + const char *name; +#else + char *name; +#endif +} RzFlagZoneItem; + +/* flag.c */ + +typedef struct rz_flags_at_offset_t { + ut64 off; + RzList *flags; /* list of RzFlagItem at offset */ +} RzFlagsAtOffset; + +typedef struct rz_flag_item_t { + char *name; /* unique name, escaped to avoid issues with r2 shell */ + char *realname; /* real name, without any escaping */ + bool demangled; /* real name from demangling? */ + ut64 offset; /* offset flagged by this item */ + ut64 size; /* size of the flag item */ + RSpace *space; /* flag space this item belongs to */ + char *color; /* item color */ + char *comment; /* item comment */ + char *alias; /* used to define a flag based on a math expression (e.g. foo + 3) */ +} RzFlagItem; + +typedef struct rz_flag_t { + RSpaces spaces; /* handle flag spaces */ + st64 base; /* base address for all flag items */ + bool realnames; + Sdb *tags; + RNum *num; + RzSkipList *by_off; /* flags sorted by offset, value=RzFlagsAtOffset */ + HtPP *ht_name; /* hashmap key=item name, value=RzFlagItem * */ + PrintfCallback cb_printf; +#if R_FLAG_ZONE_USE_SDB + Sdb *zones; +#else + RzList *zones; +#endif +} RzFlag; + +/* compile time dependency */ + +typedef bool (*RzFlagExistAt)(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off); +typedef RzFlagItem* (*RzFlagGet)(RzFlag *f, const char *name); +typedef RzFlagItem* (*RzFlagGetAtAddr) (RzFlag *f, ut64); +typedef RzFlagItem* (*RzFlagGetAt)(RzFlag *f, ut64 addr, bool closest); +typedef const RzList* (*RzFlagGetList)(RzFlag *f, ut64 addr); +typedef RzFlagItem* (*RzFlagSet)(RzFlag *f, const char *name, ut64 addr, ut32 size); +typedef bool (*RzFlagUnset)(RzFlag *f, RzFlagItem *item); +typedef bool (*RzFlagUnsetName)(RzFlag *f, const char *name); +typedef bool (*RzFlagUnsetOff)(RzFlag *f, ut64 addr); +typedef RSpace *(*RzFlagSetSpace)(RzFlag *f, const char *name); +typedef bool (*RzFlagPopSpace)(RzFlag *f); +typedef bool (*RzFlagPushSpace)(RzFlag *f, const char *name); + +typedef bool (*RzFlagItemCb)(RzFlagItem *fi, void *user); + +typedef struct rz_flag_bind_t { + int init; + RzFlag *f; + RzFlagExistAt exist_at; + RzFlagGet get; + RzFlagGetAt get_at; + RzFlagGetList get_list; + RzFlagSet set; + RzFlagUnset unset; + RzFlagUnsetName unset_name; + RzFlagUnsetOff unset_off; + RzFlagSetSpace set_fs; + RzFlagPushSpace push_fs; + RzFlagPopSpace pop_fs; +} RzFlagBind; + +#define rz_flag_bind_init(x) memset(&x,0,sizeof(x)) +RZ_API void rz_flag_bind(RzFlag *io, RzFlagBind *bnd); + +#ifdef RZ_API +RZ_API RzFlag * rz_flag_new(void); +RZ_API RzFlag * rz_flag_free(RzFlag *f); +RZ_API void rz_flag_list(RzFlag *f, int rad, const char *pfx); +RZ_API bool rz_flag_exist_at(RzFlag *f, const char *flag_prefix, ut16 fp_size, ut64 off); +RZ_API RzFlagItem *rz_flag_get(RzFlag *f, const char *name); +RZ_API RzFlagItem *rz_flag_get_i(RzFlag *f, ut64 off); +RZ_API RzFlagItem *rz_flag_get_by_spaces(RzFlag *f, ut64 off, ...); +RZ_API RzFlagItem *rz_flag_get_at(RzFlag *f, ut64 off, bool closest); +RZ_API RzList *rz_flag_all_list(RzFlag *f, bool by_space); +RZ_API const RzList* /**/ rz_flag_get_list(RzFlag *f, ut64 off); +RZ_API char *rz_flag_get_liststr(RzFlag *f, ut64 off); +RZ_API bool rz_flag_unset(RzFlag *f, RzFlagItem *item); +RZ_API bool rz_flag_unset_name(RzFlag *f, const char *name); +RZ_API bool rz_flag_unset_off(RzFlag *f, ut64 addr); +RZ_API void rz_flag_unset_all (RzFlag *f); +RZ_API RzFlagItem *rz_flag_set(RzFlag *fo, const char *name, ut64 addr, ut32 size); +RZ_API RzFlagItem *rz_flag_set_next(RzFlag *fo, const char *name, ut64 addr, ut32 size); +RZ_API void rz_flag_item_set_alias(RzFlagItem *item, const char *alias); +RZ_API void rz_flag_item_free (RzFlagItem *item); +RZ_API void rz_flag_item_set_comment(RzFlagItem *item, const char *comment); +RZ_API void rz_flag_item_set_realname(RzFlagItem *item, const char *realname); +RZ_API const char *rz_flag_item_set_color(RzFlagItem *item, const char *color); +RZ_API RzFlagItem *rz_flag_item_clone(RzFlagItem *item); +RZ_API int rz_flag_unset_glob(RzFlag *f, const char *name); +RZ_API int rz_flag_rename(RzFlag *f, RzFlagItem *item, const char *name); +RZ_API int rz_flag_relocate(RzFlag *f, ut64 off, ut64 off_mask, ut64 to); +RZ_API bool rz_flag_move (RzFlag *f, ut64 at, ut64 to); +RZ_API const char *rz_flag_color(RzFlag *f, RzFlagItem *it, const char *color); +RZ_API int rz_flag_count(RzFlag *f, const char *glob); +RZ_API void rz_flag_foreach(RzFlag *f, RzFlagItemCb cb, void *user); +RZ_API void rz_flag_foreach_prefix(RzFlag *f, const char *pfx, int pfx_len, RzFlagItemCb cb, void *user); +RZ_API void rz_flag_foreach_range(RzFlag *f, ut64 from, ut64 to, RzFlagItemCb cb, void *user); +RZ_API void rz_flag_foreach_glob(RzFlag *f, const char *glob, RzFlagItemCb cb, void *user); +RZ_API void rz_flag_foreach_space(RzFlag *f, const RSpace *space, RzFlagItemCb cb, void *user); +RZ_API void rz_flag_foreach_space_glob(RzFlag *f, const char *glob, const RSpace *space, RzFlagItemCb cb, void *user); + +/* spaces */ +static inline RSpace *rz_flag_space_get(RzFlag *f, const char *name) { + return rz_spaces_get (&f->spaces, name); +} + +static inline RSpace *rz_flag_space_cur(RzFlag *f) { + return rz_spaces_current (&f->spaces); +} + +static inline const char *rz_flag_space_cur_name(RzFlag *f) { + return rz_spaces_current_name (&f->spaces); +} + +static inline RSpace *rz_flag_space_set(RzFlag *f, const char *name) { + return rz_spaces_set (&f->spaces, name); +} + +static inline bool rz_flag_space_unset(RzFlag *f, const char *name) { + return rz_spaces_unset (&f->spaces, name); +} + +static inline bool rz_flag_space_rename(RzFlag *f, const char *oname, const char *nname) { + return rz_spaces_rename (&f->spaces, oname, nname); +} + +static inline bool rz_flag_space_push(RzFlag *f, const char *name) { + return rz_spaces_push (&f->spaces, name); +} + +static inline bool rz_flag_space_pop(RzFlag *f) { + return rz_spaces_pop (&f->spaces); +} + +static inline int rz_flag_space_count(RzFlag *f, const char *name) { + return rz_spaces_count (&f->spaces, name); +} + +static inline bool rz_flag_space_is_empty(RzFlag *f) { + return rz_spaces_is_empty (&f->spaces); +} + +#define rz_flag_space_foreach(f, it, s) rz_spaces_foreach (&(f)->spaces, (it), (s)) + +/* tags */ +RZ_API RzList *rz_flag_tags_list(RzFlag *f, const char *name); +RZ_API RzList *rz_flag_tags_set(RzFlag *f, const char *name, const char *words); +RZ_API void rz_flag_tags_reset(RzFlag *f, const char *name); +RZ_API RzList *rz_flag_tags_get(RzFlag *f, const char *name); + +/* zones */ + +RZ_API void rz_flag_zone_item_free(void *a); +RZ_API bool rz_flag_zone_add(RzFlag *fz, const char *name, ut64 addr); +RZ_API bool rz_flag_zone_del(RzFlag *fz, const char *name); +RZ_API bool rz_flag_zone_around(RzFlag *fz, ut64 addr, const char **prev, const char **next); +RZ_API bool rz_flag_zone_list(RzFlag *fz, int mode); +RZ_API bool rz_flag_zone_reset(RzFlag *f); +RZ_API RzList *rz_flag_zone_barlist(RzFlag *f, ut64 from, ut64 bsize, int rows); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_flist.h b/librz/include/rz_flist.h new file mode 100644 index 0000000000..0fe0464bd7 --- /dev/null +++ b/librz/include/rz_flist.h @@ -0,0 +1,88 @@ +/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */ + +#ifndef R2_FLIST_H +#define R2_FLIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +//#include + +#define rz_flist_t void** +#define RFList void** + +#ifdef RZ_API +RZ_API void **rz_flist_resize(void **it, int n); +#define rz_flist_rewind(it) while(it!=*it) it--; it++; +#define rz_flist_next(it) *it!=0 +#define rz_flist_get(it) *(it++) +#define rz_flist_unref(x) x + +#define rz_flist_iterator(x) x +/* +static inline void **rz_flist_iterator(void **it) { + rz_flist_iterator(it); + return it; +} +*/ + +static inline void **rz_flist_init(void **it, int n) { + *it = it; + memset (++it, 0, (n+1) * sizeof (void*)); + return it; +} + +static inline void **rz_flist_new(int n) { + void **it; + if (((n + 2) * sizeof(void*)) < sizeof(void*)) return NULL; + if (!(it = (void **)calloc ((n + 2), sizeof (void*)))) { + return NULL; + } + return rz_flist_init (it, n); +} + +static inline void **rz_flist_prev(void **it) { + void **p = it--; + return (it==*it)?p:it; +} + +static inline void rz_flist_set(void **it, int idx, void *data) { + rz_flist_rewind (it); + it[idx] = data; +} + +static inline void rz_flist_delete(void **it, int idx) { + rz_flist_rewind (it); + free (it[idx]); + for(it += idx; *it; it++) *it = *(it+1); +} + +#define rz_flist_foreach(it, pos) \ + rz_flist_rewind(it); \ + while (rz_flist_next (it) && (pos = rz_flist_get (it))) + +static inline void rz_flist_free(void **it) { + void *pos; + rz_flist_foreach (it, pos) + free (pos); + rz_flist_rewind (it); + free (--it); +} + +static inline int rz_flist_length (void **it) { + void *pos; + int len = 0; + rz_flist_foreach (it, pos) + len++; + return len; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_fs.h b/librz/include/rz_fs.h new file mode 100644 index 0000000000..a808bd0950 --- /dev/null +++ b/librz/include/rz_fs.h @@ -0,0 +1,181 @@ +#ifndef R2_FS_H +#define R2_FS_H + +#include +#include +#include // RzCoreBind +#include // RzIOBind +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER (rz_fs); + +struct rz_fs_plugin_t; +struct rz_fs_root_t; +struct rz_fs_t; + +typedef struct rz_fs_t { + RzIOBind iob; + RzCoreBind cob; + RzConsBind csb; + RzList /**/ *plugins; + RzList /**/ *roots; + int view; + void *ptr; +} RzFS; + +typedef struct rz_fs_partition_plugin_t { + const char *name; +} RzFSPartitionPlugin; + +typedef struct rz_fs_file_t { + char *name; + char *path; + ut64 off; + ut32 size; + ut8 *data; + void *ctx; + char type; + ut64 time; + struct rz_fs_plugin_t *p; + struct rz_fs_root_t *root; + void *ptr; // internal pointer +} RzFSFile; + +typedef struct rz_fs_root_t { + char *path; + ut64 delta; + struct rz_fs_plugin_t *p; + void *ptr; + // TODO: deprecate + RzIOBind iob; + RzCoreBind cob; +} RzFSRoot; + +typedef struct rz_fs_plugin_t { + const char *name; + const char *desc; + const char *license; + RzFSFile* (*slurp)(RzFSRoot *root, const char *path); + RzFSFile* (*open)(RzFSRoot *root, const char *path, bool create); + bool (*unlink)(RzFSRoot *root, const char *path); + bool (*write)(RzFSFile *fs, ut64 addr, const ut8 *data, int len); + bool (*read)(RzFSFile *fs, ut64 addr, int len); + void (*close)(RzFSFile *fs); + RzList *(*dir)(RzFSRoot *root, const char *path, int view); + void (*init)(void); + void (*fini)(void); + int (*mount)(RzFSRoot *root); + void (*umount)(RzFSRoot *root); +} RzFSPlugin; + +typedef struct rz_fs_partition_t { + int number; + ut64 start; + ut64 length; + int index; + int type; +} RzFSPartition; + +typedef struct rz_fs_shell_t { + char **cwd; + void (*set_prompt)(const char *prompt); + const char* (*readline)(void); + int (*hist_add)(const char *line); +} RzFSShell; + +#define R_FS_FILE_TYPE_MOUNTPOINT 'm' +#define R_FS_FILE_TYPE_DIRECTORY 'd' +#define R_FS_FILE_TYPE_REGULAR 'r' +#define R_FS_FILE_TYPE_DELETED 'x' +#define R_FS_FILE_TYPE_SPECIAL 's' +#define R_FS_FILE_TYPE_MOUNT 'm' + +typedef int (*RzFSPartitionIterator)(void *disk, void *ptr, void *user); +typedef struct rz_fs_partition_type_t { + const char *name; + void *ptr; // grub_msdos_partition_map + RzFSPartitionIterator iterate; + //RzFSPartitionIterator parhook; +} RzFSPartitionType; +#define R_FS_PARTITIONS_LENGTH (int)(sizeof (partitions)/sizeof(RzFSPartitionType)-1) + +enum { + R_FS_VIEW_NORMAL = 0, + R_FS_VIEW_DELETED = 1, + R_FS_VIEW_SPECIAL = 2, + R_FS_VIEW_ALL = 0xff, +}; + +#ifdef RZ_API +RZ_API RzFS *rz_fs_new(void); +RZ_API void rz_fs_view(RzFS* fs, int view); +RZ_API void rz_fs_free(RzFS* fs); +RZ_API void rz_fs_add(RzFS *fs, RzFSPlugin *p); +RZ_API void rz_fs_del(RzFS *fs, RzFSPlugin *p); +RZ_API RzFSRoot *rz_fs_mount(RzFS* fs, const char *fstype, const char *path, ut64 delta); +RZ_API bool rz_fs_umount(RzFS* fs, const char *path); +RZ_API RzList *rz_fs_root(RzFS *fs, const char *path); +RZ_API RzFSFile *rz_fs_open(RzFS* fs, const char *path, bool create); +RZ_API void rz_fs_close(RzFS* fs, RzFSFile *file); +RZ_API int rz_fs_read(RzFS* fs, RzFSFile *file, ut64 addr, int len); +RZ_API int rz_fs_write(RzFS* fs, RzFSFile* file, ut64 addr, const ut8 *data, int len); +RZ_API RzFSFile *rz_fs_slurp(RzFS* fs, const char *path); +RZ_API RzList *rz_fs_dir(RzFS* fs, const char *path); +RZ_API int rz_fs_dir_dump(RzFS* fs, const char *path, const char *name); +RZ_API RzList *rz_fs_find_name(RzFS* fs, const char *name, const char *glob); +RZ_API RzList *rz_fs_find_off(RzFS* fs, const char *name, ut64 off); +RZ_API RzList *rz_fs_partitions(RzFS* fs, const char *ptype, ut64 delta); +RZ_API char *rz_fs_name(RzFS *fs, ut64 offset); +RZ_API int rz_fs_prompt(RzFS *fs, const char *root); +RZ_API bool rz_fs_check(RzFS *fs, const char *p); +RZ_API int rz_fs_shell_prompt(RzFSShell *shell, RzFS *fs, const char *root); + +/* file.c */ +RZ_API RzFSFile *rz_fs_file_new(RzFSRoot *root, const char *path); +RZ_API void rz_fs_file_free(RzFSFile *file); +RZ_API char* rz_fs_file_copy_abs_path(RzFSFile* file); +RZ_API RzFSRoot *rz_fs_root_new(const char *path, ut64 delta); +RZ_API void rz_fs_root_free(RzFSRoot *root); +RZ_API RzFSPartition *rz_fs_partition_new(int num, ut64 start, ut64 length); +RZ_API void rz_fs_partition_free(RzFSPartition *p); +RZ_API const char *rz_fs_partition_type(const char *part, int type); +RZ_API const char *rz_fs_partition_type_get(int n); +RZ_API int rz_fs_partition_get_size(void); // WTF. wrong function name + +/* plugins */ +extern RzFSPlugin rz_fs_plugin_io; +extern RzFSPlugin rz_fs_plugin_rz; +extern RzFSPlugin rz_fs_plugin_ext2; +extern RzFSPlugin rz_fs_plugin_fat; +extern RzFSPlugin rz_fs_plugin_ntfs; +extern RzFSPlugin rz_fs_plugin_hfs; +extern RzFSPlugin rz_fs_plugin_hfsplus; +extern RzFSPlugin rz_fs_plugin_reiserfs; +extern RzFSPlugin rz_fs_plugin_tar; +extern RzFSPlugin rz_fs_plugin_iso9660; +extern RzFSPlugin rz_fs_plugin_udf; +extern RzFSPlugin rz_fs_plugin_ufs; +extern RzFSPlugin rz_fs_plugin_ufs2; +extern RzFSPlugin rz_fs_plugin_sfs; +extern RzFSPlugin rz_fs_plugin_tar; +extern RzFSPlugin rz_fs_plugin_btrfs; +extern RzFSPlugin rz_fs_plugin_jfs; +extern RzFSPlugin rz_fs_plugin_afs; +extern RzFSPlugin rz_fs_plugin_affs; +extern RzFSPlugin rz_fs_plugin_cpio; +extern RzFSPlugin rz_fs_plugin_xfs; +extern RzFSPlugin rz_fs_plugin_fb; +extern RzFSPlugin rz_fs_plugin_minix; +extern RzFSPlugin rz_fs_plugin_posix; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_getopt.h b/librz/include/rz_getopt.h new file mode 100644 index 0000000000..4524c769d8 --- /dev/null +++ b/librz/include/rz_getopt.h @@ -0,0 +1,21 @@ +#ifndef R_GETOPT_H +#define R_GETOPT_H 1 + +#include + +typedef struct rz_getopt_t { + int err; + int ind; + int opt; + int reset; + const char *arg; + // ... + int argc; + const char **argv; + const char *ostr; +} RzGetopt; + +RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr); +RZ_API int rz_getopt_next(RzGetopt *opt); + +#endif diff --git a/libr/include/r_hash.h b/librz/include/rz_hash.h similarity index 85% rename from libr/include/r_hash.h rename to librz/include/rz_hash.h index 4840133888..f19843967d 100644 --- a/libr/include/r_hash.h +++ b/librz/include/rz_hash.h @@ -1,14 +1,14 @@ #ifndef R2_HASH_H #define R2_HASH_H -#include "r_types.h" -#include "r_util/r_mem.h" +#include "rz_types.h" +#include "rz_util/rz_mem.h" #ifdef __cplusplus extern "C" { #endif -R_LIB_VERSION_HEADER (r_hash); +R_LIB_VERSION_HEADER (rz_hash); #if HAVE_LIB_SSL #include @@ -80,10 +80,10 @@ typedef ut32 utcrc; #endif #define UTCRC_C(x) ((utcrc)(x)) -R_API ut16 r_hash_fletcher8(const ut8 *d, size_t length); -R_API ut16 r_hash_fletcher16(const ut8 *data, size_t len); -R_API ut32 r_hash_fletcher32(const ut8 *data, size_t len); -R_API ut64 r_hash_fletcher64(const ut8 *addr, size_t len); +RZ_API ut16 rz_hash_fletcher8(const ut8 *d, size_t length); +RZ_API ut16 rz_hash_fletcher16(const ut8 *data, size_t len); +RZ_API ut32 rz_hash_fletcher32(const ut8 *data, size_t len); +RZ_API ut64 rz_hash_fletcher64(const ut8 *addr, size_t len); typedef struct { utcrc crc; @@ -170,9 +170,9 @@ enum CRC_PRESETS { }; /* Fix names conflict with ruby bindings */ -#define RHash struct r_hash_t +#define RzHash struct rz_hash_t -struct r_hash_t { +struct rz_hash_t { R_MD5_CTX md5; R_SHA_CTX sha1; R_SHA256_CTX sha256; @@ -183,11 +183,11 @@ struct r_hash_t { ut8 R_ALIGNED(8) digest[128]; }; -typedef struct r_hash_seed_t { +typedef struct rz_hash_seed_t { int prefix; ut8 *buf; int len; -} RHashSeed; +} RzHashSeed; #define R_HASH_SIZE_CRC8_SMBUS 1 #if R_HAVE_CRC8_EXTRA @@ -268,7 +268,7 @@ typedef struct r_hash_seed_t { #define R_HASH_SIZE_SHA384 48 #define R_HASH_SIZE_SHA512 64 #define R_HASH_SIZE_ADLER32 4 -/* entropy is double !! size 0 for test in r_hash_to_string */ +/* entropy is double !! size 0 for test in rz_hash_to_string */ #define R_HASH_SIZE_ENTROPY 0 #define R_HASH_SIZE_PCPRINT 1 #define R_HASH_SIZE_MOD255 1 @@ -481,51 +481,51 @@ enum HASH_INDICES { #define R_HASH_ALL ((1ULL << R_MIN(63, R_HASH_NUM_INDICES))-1) -#ifdef R_API +#ifdef RZ_API /* OO */ -R_API RHash *r_hash_new(bool rst, ut64 flags); -R_API void r_hash_free(RHash *ctx); +RZ_API RzHash *rz_hash_new(bool rst, ut64 flags); +RZ_API void rz_hash_free(RzHash *ctx); /* methods */ -R_API ut8 *r_hash_do_md4(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_md5(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_sha1(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_sha256(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_sha384(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_sha512(RHash *ctx, const ut8 *input, int len); -R_API ut8 *r_hash_do_hmac_sha256(RHash *ctx, const ut8 *input, int len, const ut8 *key, int klen); +RZ_API ut8 *rz_hash_do_md4(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_md5(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_sha1(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_sha256(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_sha384(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_sha512(RzHash *ctx, const ut8 *input, int len); +RZ_API ut8 *rz_hash_do_hmac_sha256(RzHash *ctx, const ut8 *input, int len, const ut8 *key, int klen); -R_API char *r_hash_to_string(RHash *ctx, const char *name, const ut8 *data, int len); +RZ_API char *rz_hash_to_string(RzHash *ctx, const char *name, const ut8 *data, int len); /* static methods */ -R_API const char *r_hash_name(ut64 bit); -R_API ut64 r_hash_name_to_bits(const char *name); -R_API int r_hash_size(ut64 bit); -R_API int r_hash_calculate(RHash *ctx, ut64 algobit, const ut8 *input, int len); +RZ_API const char *rz_hash_name(ut64 bit); +RZ_API ut64 rz_hash_name_to_bits(const char *name); +RZ_API int rz_hash_size(ut64 bit); +RZ_API int rz_hash_calculate(RzHash *ctx, ut64 algobit, const ut8 *input, int len); /* checksums */ /* XXX : crc16 should use 0 as arg0 by default */ /* static methods */ -R_API ut8 r_hash_deviation(const ut8 *b, ut64 len); -R_API ut32 r_hash_adler32(const ut8 *buf, int len); -R_API ut32 r_hash_xxhash(const ut8 *buf, ut64 len); -R_API ut8 r_hash_xor(const ut8 *b, ut64 len); -R_API ut16 r_hash_xorpair(const ut8 *a, ut64 len); -R_API int r_hash_parity(const ut8 *buf, ut64 len); -R_API ut8 r_hash_mod255(const ut8 *b, ut64 len); -R_API ut64 r_hash_luhn(const ut8 *buf, ut64 len); -R_API utcrc r_hash_crc_preset (const ut8 *data, ut32 size, enum CRC_PRESETS preset); +RZ_API ut8 rz_hash_deviation(const ut8 *b, ut64 len); +RZ_API ut32 rz_hash_adler32(const ut8 *buf, int len); +RZ_API ut32 rz_hash_xxhash(const ut8 *buf, ut64 len); +RZ_API ut8 rz_hash_xor(const ut8 *b, ut64 len); +RZ_API ut16 rz_hash_xorpair(const ut8 *a, ut64 len); +RZ_API int rz_hash_parity(const ut8 *buf, ut64 len); +RZ_API ut8 rz_hash_mod255(const ut8 *b, ut64 len); +RZ_API ut64 rz_hash_luhn(const ut8 *buf, ut64 len); +RZ_API utcrc rz_hash_crc_preset (const ut8 *data, ut32 size, enum CRC_PRESETS preset); /* analysis */ -R_API ut8 r_hash_hamdist(const ut8 *buf, int len); -R_API double r_hash_entropy(const ut8 *data, ut64 len); -R_API double r_hash_entropy_fraction(const ut8 *data, ut64 len); -R_API int r_hash_pcprint(const ut8 *buffer, ut64 len); +RZ_API ut8 rz_hash_hamdist(const ut8 *buf, int len); +RZ_API double rz_hash_entropy(const ut8 *data, ut64 len); +RZ_API double rz_hash_entropy_fraction(const ut8 *data, ut64 len); +RZ_API int rz_hash_pcprint(const ut8 *buffer, ut64 len); /* lifecycle */ -R_API void r_hash_do_begin(RHash *ctx, ut64 flags); -R_API void r_hash_do_end(RHash *ctx, ut64 flags); -R_API void r_hash_do_spice(RHash *ctx, ut64 algo, int loops, RHashSeed *seed); +RZ_API void rz_hash_do_begin(RzHash *ctx, ut64 flags); +RZ_API void rz_hash_do_end(RzHash *ctx, ut64 flags); +RZ_API void rz_hash_do_spice(RzHash *ctx, ut64 algo, int loops, RzHashSeed *seed); #endif #ifdef __cplusplus diff --git a/libr/include/r_heap_glibc.h b/librz/include/rz_heap_glibc.h similarity index 85% rename from libr/include/r_heap_glibc.h rename to librz/include/rz_heap_glibc.h index 9a20b158d7..6efad77a03 100644 --- a/libr/include/r_heap_glibc.h +++ b/librz/include/rz_heap_glibc.h @@ -5,19 +5,19 @@ extern "C" { #endif -R_LIB_VERSION_HEADER(r_heap_glibc); +R_LIB_VERSION_HEADER(rz_heap_glibc); -#define PRINTF_A(color, fmt , ...) r_cons_printf (color fmt Color_RESET, __VA_ARGS__) +#define PRINTF_A(color, fmt , ...) rz_cons_printf (color fmt Color_RESET, __VA_ARGS__) #define PRINTF_YA(fmt, ...) PRINTF_A ("%s", fmt, pal->offset, __VA_ARGS__) #define PRINTF_GA(fmt, ...) PRINTF_A ("%s", fmt, pal->args, __VA_ARGS__) #define PRINTF_BA(fmt, ...) PRINTF_A ("%s", fmt, pal->num, __VA_ARGS__) #define PRINTF_RA(fmt, ...) PRINTF_A ("%s", fmt, pal->invalid, __VA_ARGS__) -#define PRINT_A(color, msg) r_cons_print (color msg Color_RESET) -#define PRINT_YA(msg) r_cons_printf ("%s" msg Color_RESET, pal->offset) -#define PRINT_GA(msg) r_cons_printf ("%s" msg Color_RESET, pal->args) -#define PRINT_BA(msg) r_cons_printf ("%s" msg Color_RESET, pal->num) -#define PRINT_RA(msg) r_cons_printf ("%s" msg Color_RESET, pal->invalid) +#define PRINT_A(color, msg) rz_cons_print (color msg Color_RESET) +#define PRINT_YA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->offset) +#define PRINT_GA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->args) +#define PRINT_BA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->num) +#define PRINT_RA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->invalid) #define PREV_INUSE 0x1 #define IS_MMAPPED 0x2 @@ -83,7 +83,7 @@ R_LIB_VERSION_HEADER(r_heap_glibc); : largebin_index_32 (size)) */ -typedef struct r_malloc_chunk_64 { +typedef struct rz_malloc_chunk_64 { ut64 prev_size; /* Size of previous chunk (if free). */ ut64 size; /* Size in bytes, including overhead. */ @@ -93,9 +93,9 @@ typedef struct r_malloc_chunk_64 { /* Only used for large blocks: pointer to next larger size. */ ut64 fd_nextsize; /* double links -- used only if free. */ ut64 bk_nextsize; -} RHeapChunk_64; +} RzHeapChunk_64; -typedef struct r_malloc_chunk_32 { +typedef struct rz_malloc_chunk_32 { ut32 prev_size; /* Size of previous chunk (if free). */ ut32 size; /* Size in bytes, including overhead. */ @@ -105,17 +105,17 @@ typedef struct r_malloc_chunk_32 { /* Only used for large blocks: pointer to next larger size. */ ut32 fd_nextsize; /* double links -- used only if free. */ ut32 bk_nextsize; -} RHeapChunk_32; +} RzHeapChunk_32; /* -typedef RHeapChunk64 *mfastbinptr64; -typedef RHeapChunk64 *mchunkptr64; +typedef RzHeapChunk64 *mfastbinptr64; +typedef RzHeapChunk64 *mchunkptr64; -typedef RHeapChunk32 *mfastbinptr32; -typedef RHeapChunk32 *mchunkptr32; +typedef RzHeapChunk32 *mfastbinptr32; +typedef RzHeapChunk32 *mchunkptr32; */ -typedef struct r_malloc_state_32 { +typedef struct rz_malloc_state_32 { int mutex; /* serialized access */ int flags; /* flags */ ut32 fastbinsY[NFASTBINS]; /* array of fastchunks */ @@ -128,9 +128,9 @@ typedef struct r_malloc_state_32 { unsigned int attached_threads; /* threads attached */ ut32 system_mem; /* current allocated memory of current arena */ ut32 max_system_mem; /* maximum system memory */ -} RHeap_MallocState_32; +} RzHeap_MallocState_32; -typedef struct r_malloc_state_64 { +typedef struct rz_malloc_state_64 { int mutex; /* serialized access */ int flags; /* flags */ ut64 fastbinsY[NFASTBINS]; /* array of fastchunks */ @@ -143,47 +143,47 @@ typedef struct r_malloc_state_64 { unsigned int attached_threads; /* threads attached */ ut64 system_mem; /* current allocated memory of current arena */ ut64 max_system_mem; /* maximum system memory */ -} RHeap_MallocState_64; +} RzHeap_MallocState_64; -typedef struct r_tcache_perthread_struct_32 { +typedef struct rz_tcache_perthread_struct_32 { ut16 counts[TCACHE_MAX_BINS]; ut32 entries[TCACHE_MAX_BINS]; -} RHeapTcache_32; +} RzHeapTcache_32; -typedef struct r_tcache_perthread_struct_64 { +typedef struct rz_tcache_perthread_struct_64 { ut16 counts[TCACHE_MAX_BINS]; ut64 entries[TCACHE_MAX_BINS]; -} RHeapTcache_64; +} RzHeapTcache_64; -typedef struct r_tcache_perthread_struct_pre_230_32 { +typedef struct rz_tcache_perthread_struct_pre_230_32 { ut8 counts[TCACHE_MAX_BINS]; ut32 entries[TCACHE_MAX_BINS]; -} RHeapTcachePre230_32; +} RzHeapTcachePre230_32; -typedef struct r_tcache_perthread_struct_pre_230_64 { +typedef struct rz_tcache_perthread_struct_pre_230_64 { ut8 counts[TCACHE_MAX_BINS]; ut64 entries[TCACHE_MAX_BINS]; -} RHeapTcachePre230_64; +} RzHeapTcachePre230_64; typedef enum {NEW, OLD} tcache_type; typedef struct { tcache_type type; union { - RHeapTcache_64 *heap_tcache; - RHeapTcachePre230_64 *heap_tcache_pre_230; - } RHeapTcache; + RzHeapTcache_64 *heap_tcache; + RzHeapTcachePre230_64 *heap_tcache_pre_230; + } RzHeapTcache; } RTcache_64; typedef struct { tcache_type type; union { - RHeapTcache_32 *heap_tcache; - RHeapTcachePre230_32 *heap_tcache_pre_230; - } RHeapTcache; + RzHeapTcache_32 *heap_tcache; + RzHeapTcachePre230_32 *heap_tcache_pre_230; + } RzHeapTcache; } RTcache_32; -typedef struct r_malloc_state_tcache_32 { +typedef struct rz_malloc_state_tcache_32 { int mutex; /* serialized access */ int flags; /* flags */ int have_fast_chunks; /* have fast chunks */ @@ -197,9 +197,9 @@ typedef struct r_malloc_state_tcache_32 { unsigned int attached_threads; /* threads attached */ ut32 system_mem; /* current allocated memory of current arena */ ut32 max_system_mem; /* maximum system memory */ -} RHeap_MallocState_tcache_32; +} RzHeap_MallocState_tcache_32; -typedef struct r_malloc_state_tcache_64 { +typedef struct rz_malloc_state_tcache_64 { int mutex; /* serialized access */ int flags; /* flags */ int have_fast_chunks; /* have fast chunks */ @@ -213,9 +213,9 @@ typedef struct r_malloc_state_tcache_64 { unsigned int attached_threads; /* threads attached */ ut64 system_mem; /* current allocated memory of current arena */ ut64 max_system_mem; /* maximum system memory */ -} RHeap_MallocState_tcache_64; +} RzHeap_MallocState_tcache_64; -typedef struct r_malloc_state { +typedef struct rz_malloc_state { int mutex; /* serialized access */ int flags; /* flags */ unsigned int binmap[BINMAPSIZE]; /* bitmap of bins */ @@ -245,7 +245,7 @@ typedef struct r_malloc_state { ut64 max_system_mem_64; /* maximum system memory */ } MallocState; -typedef struct r_heap_info_32 { +typedef struct rz_heap_info_32 { ut32 ar_ptr; /* Arena for this heap. */ ut32 prev; /* Previous heap. */ ut32 size; /* Current size in bytes. */ @@ -255,9 +255,9 @@ typedef struct r_heap_info_32 { that sizeof (heap_info) + 2 * SZ is a multiple of MALLOC_ALIGNMENT. */ /* char pad[NPAD * SZ & MALLOC_ALIGN_MASK]; */ -} RHeapInfo_32; +} RzHeapInfo_32; -typedef struct r_heap_info_64 { +typedef struct rz_heap_info_64 { ut64 ar_ptr; /* Arena for this heap. */ ut64 prev; /* Previous heap. */ ut64 size; /* Current size in bytes. */ @@ -267,7 +267,7 @@ typedef struct r_heap_info_64 { that sizeof (heap_info) + 2 * SZ is a multiple of MALLOC_ALIGNMENT. */ /* char pad[NPAD * SZ & MALLOC_ALIGN_MASK]; */ -} RHeapInfo_64; +} RzHeapInfo_64; #ifdef __cplusplus } diff --git a/libr/include/r_heap_jemalloc.h b/librz/include/rz_heap_jemalloc.h similarity index 53% rename from libr/include/r_heap_jemalloc.h rename to librz/include/rz_heap_jemalloc.h index a2858982f5..229bec6798 100644 --- a/libr/include/r_heap_jemalloc.h +++ b/librz/include/rz_heap_jemalloc.h @@ -1,10 +1,10 @@ #ifndef R2_HEAP_JEMALLOC_H #define R2_HEAP_JEMALLOC_H -#include "r_jemalloc/internal/jemalloc_internal.h" +#include "rz_jemalloc/internal/jemalloc_internal.h" #define INC_HEAP32 1 -#include "r_heap_jemalloc.h" +#include "rz_heap_jemalloc.h" #undef INC_HEAP32 #endif @@ -22,14 +22,14 @@ #define GHT_MAX UT64_MAX #endif -#define PRINTF_A(color, fmt , ...) r_cons_printf (color fmt Color_RESET, __VA_ARGS__) +#define PRINTF_A(color, fmt , ...) rz_cons_printf (color fmt Color_RESET, __VA_ARGS__) #define PRINTF_YA(fmt, ...) PRINTF_A ("%s", fmt, pal->offset, __VA_ARGS__) #define PRINTF_GA(fmt, ...) PRINTF_A ("%s", fmt, pal->args, __VA_ARGS__) #define PRINTF_BA(fmt, ...) PRINTF_A ("%s", fmt, pal->num, __VA_ARGS__) #define PRINTF_RA(fmt, ...) PRINTF_A ("%s", fmt, pal->invalid, __VA_ARGS__) -#define PRINT_A(color, msg) r_cons_print (color msg Color_RESET) -#define PRINT_YA(msg) r_cons_printf ("%s" msg Color_RESET, pal->offset) -#define PRINT_GA(msg) r_cons_printf ("%s" msg Color_RESET, pal->args) -#define PRINT_BA(msg) r_cons_printf ("%s" msg Color_RESET, pal->num) -#define PRINT_RA(msg) r_cons_printf ("%s" msg Color_RESET, pal->invalid) +#define PRINT_A(color, msg) rz_cons_print (color msg Color_RESET) +#define PRINT_YA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->offset) +#define PRINT_GA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->args) +#define PRINT_BA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->num) +#define PRINT_RA(msg) rz_cons_printf ("%s" msg Color_RESET, pal->invalid) diff --git a/librz/include/rz_io.h b/librz/include/rz_io.h new file mode 100644 index 0000000000..5b501a56d3 --- /dev/null +++ b/librz/include/rz_io.h @@ -0,0 +1,513 @@ +/* rizin - LGPL - Copyright 2017-2020 - condret, pancake, alvaro */ + +#ifndef R2_IO_H +#define R2_IO_H + +#include "rz_list.h" +#include +#include "rz_socket.h" +#include "rz_vector.h" + +#define R_IO_SEEK_SET 0 +#define R_IO_SEEK_CUR 1 +#define R_IO_SEEK_END 2 + +#define R_IO_UNDOS 64 + +#if HAVE_PTRACE + +#if __sun +#include +#else +#if DEBUGGER && HAVE_PTRACE +#include +#endif +#endif + +#if (defined(__GLIBC__) && defined(__linux__)) +typedef enum __ptrace_request rz_ptrace_request_t; +typedef void * rz_ptrace_data_t; +#define R_PTRACE_NODATA NULL +#else +#if __ANDROID__ +typedef int rz_ptrace_request_t; +typedef void * rz_ptrace_data_t; +#define R_PTRACE_NODATA NULL +#else +typedef int rz_ptrace_request_t; +typedef int rz_ptrace_data_t; +#define R_PTRACE_NODATA 0 +#endif +#endif +#endif + +#if __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_io); + +typedef struct rz_io_undos_t { + ut64 off; + int cursor; +} RzIOUndos; + +typedef struct rz_io_undo_t { + int s_enable; + int w_enable; + /* write stuff */ + RzList *w_list; + int w_init; + /* seek stuff */ + int idx; + int undos; /* available undos */ + int redos; /* available redos */ + RzIOUndos seek[R_IO_UNDOS]; + /*int fd[R_IO_UNDOS]; // XXX: Must be RzIODesc* */ +} RzIOUndo; + +typedef struct rz_io_undo_w_t { + int set; + ut64 off; + ut8 *o; /* old data */ + ut8 *n; /* new data */ + int len; /* length */ +} RzIOUndoWrite; + +typedef struct rz_io_t { + struct rz_io_desc_t *desc; // XXX deprecate... we should use only the fd integer, not hold a weak pointer + ut64 off; + int bits; + int va; //all of this config stuff must be in 1 int + int ff; + int Oxff; + size_t addrbytes; + int aslr; + int autofd; + int cached; + bool cachemode; // write in cache all the read operations (EXPERIMENTAL) + int p_cache; + RIDPool *map_ids; + RPVector maps; //from tail backwards maps with higher priority are found + RPVector map_skyline; // map parts that are not covered by others + RIDStorage *files; + RCache *buffer; + RzList *cache; //sdblist? + RBNode cacheTree; + ut8 *write_mask; + int write_mask_len; + RzIOUndo undo; + SdbList *plugins; + char *runprofile; + char *envprofile; +#if USE_PTRACE_WRAP + struct ptrace_wrap_instance_t *ptrace_wrap; +#endif +#if __WINDOWS__ + struct w32dbg_wrap_instance_t *w32dbg_wrap; +#endif + char *args; + PrintfCallback cb_printf; + RzCoreBind corebind; +} RzIO; + +typedef struct rz_io_desc_t { + int fd; + int perm; + char *uri; + char *name; + char *referer; + HtUP/**/ *cache; + void *data; + struct rz_io_plugin_t *plugin; + RzIO *io; +} RzIODesc; + +typedef struct { + ut32 magic; + int pid; + int tid; + void *data; +} RzIODescData; + +// Move somewhere else? +typedef struct { + RzSocket *fd; + RzSocket *client; + bool listener; +} RzIORap; + +typedef struct rz_io_plugin_t { + const char *name; + const char *desc; + const char *version; + const char *author; + const char *license; + void *widget; + const char *uris; + int (*listener)(RzIODesc *io); + int (*init)(void); + RzIOUndo undo; + bool isdbg; + // int (*is_file_opened)(RzIO *io, RzIODesc *fd, const char *); + char *(*system)(RzIO *io, RzIODesc *fd, const char *); + RzIODesc* (*open)(RzIO *io, const char *, int perm, int mode); + RzList* /*RzIODesc* */ (*open_many)(RzIO *io, const char *, int perm, int mode); + int (*read)(RzIO *io, RzIODesc *fd, ut8 *buf, int count); + ut64 (*lseek)(RzIO *io, RzIODesc *fd, ut64 offset, int whence); + int (*write)(RzIO *io, RzIODesc *fd, const ut8 *buf, int count); + int (*close)(RzIODesc *desc); + bool (*is_blockdevice)(RzIODesc *desc); + bool (*is_chardevice)(RzIODesc *desc); + int (*getpid)(RzIODesc *desc); + int (*gettid)(RzIODesc *desc); + bool (*getbase)(RzIODesc *desc, ut64 *base); + bool (*resize)(RzIO *io, RzIODesc *fd, ut64 size); + int (*extend)(RzIO *io, RzIODesc *fd, ut64 size); + bool (*accept)(RzIO *io, RzIODesc *desc, int fd); + int (*create)(RzIO *io, const char *file, int mode, int type); + bool (*check)(RzIO *io, const char *, bool many); +} RzIOPlugin; + +typedef struct rz_io_map_t { + int fd; + int perm; + ut32 id; + RInterval itv; + ut64 delta; // paddr = itv.addr + delta + char *name; +} RzIOMap; + +typedef struct rz_io_map_skyline_t { + RzIOMap *map; + RInterval itv; +} RzIOMapSkyline; + +typedef struct rz_io_cache_t { + RInterval itv; + ut8 *data; + ut8 *odata; + int written; +} RzIOCache; + +#define R_IO_DESC_CACHE_SIZE (sizeof(ut64) * 8) +typedef struct rz_io_desc_cache_t { + ut64 cached; + ut8 cdata[R_IO_DESC_CACHE_SIZE]; +} RzIODescCache; + +struct rz_io_bind_t; + +typedef bool (*RzIODescUse) (RzIO *io, int fd); +typedef RzIODesc *(*RzIODescGet) (RzIO *io, int fd); +typedef ut64 (*RzIODescSize) (RzIODesc *desc); +typedef RzIODesc *(*RzIOOpen) (RzIO *io, const char *uri, int flags, int mode); +typedef RzIODesc *(*RzIOOpenAt) (RzIO *io, const char *uri, int flags, int mode, ut64 at); +typedef bool (*RzIOClose) (RzIO *io, int fd); +typedef bool (*RzIOReadAt) (RzIO *io, ut64 addr, ut8 *buf, int len); +typedef bool (*RzIOWriteAt) (RzIO *io, ut64 addr, const ut8 *buf, int len); +typedef char *(*RzIOSystem) (RzIO *io, const char* cmd); +typedef int (*RzIOFdOpen) (RzIO *io, const char *uri, int flags, int mode); +typedef bool (*RzIOFdClose) (RzIO *io, int fd); +typedef ut64 (*RzIOFdSeek) (RzIO *io, int fd, ut64 addr, int whence); +typedef ut64 (*RzIOFdSize) (RzIO *io, int fd); +typedef bool (*RzIOFdResize) (RzIO *io, int fd, ut64 newsize); +typedef ut64 (*RzIOP2V) (RzIO *io, ut64 pa); +typedef ut64 (*RzIOV2P) (RzIO *io, ut64 va); +typedef int (*RzIOFdRead) (RzIO *io, int fd, ut8 *buf, int len); +typedef int (*RzIOFdWrite) (RzIO *io, int fd, const ut8 *buf, int len); +typedef int (*RzIOFdReadAt) (RzIO *io, int fd, ut64 addr, ut8 *buf, int len); +typedef int (*RzIOFdWriteAt) (RzIO *io, int fd, ut64 addr, const ut8 *buf, int len); +typedef bool (*RzIOFdIsDbg) (RzIO *io, int fd); +typedef const char *(*RzIOFdGetName) (RzIO *io, int fd); +typedef RzList *(*RzIOFdGetMap) (RzIO *io, int fd); +typedef bool (*RzIOFdRemap) (RzIO *io, int fd, ut64 addr); +typedef bool (*RzIOIsValidOff) (RzIO *io, ut64 addr, int hasperm); +typedef RzIOMap *(*RzIOMapGet) (RzIO *io, ut64 addr); +typedef RzIOMap *(*RzIOMapGetPaddr) (RzIO *io, ut64 paddr); +typedef bool (*RzIOAddrIsMapped) (RzIO *io, ut64 addr); +typedef RzIOMap *(*RzIOMapAdd) (RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); +#if HAVE_PTRACE +typedef long (*RzIOPtraceFn) (RzIO *io, rz_ptrace_request_t request, pid_t pid, void *addr, rz_ptrace_data_t data); +typedef void *(*RzIOPtraceFuncFn) (RzIO *io, void *(*func)(void *), void *user); +#endif + +typedef struct rz_io_bind_t { + int init; + RzIO *io; + RzIODescUse desc_use; + RzIODescGet desc_get; + RzIODescSize desc_size; + RzIOOpen open; + RzIOOpenAt open_at; + RzIOClose close; + RzIOReadAt read_at; + RzIOWriteAt write_at; + RzIOSystem system; + RzIOFdOpen fd_open; + RzIOFdClose fd_close; + RzIOFdSeek fd_seek; //needed for esil + RzIOFdSize fd_size; + RzIOFdResize fd_resize; + RzIOFdRead fd_read; //needed for esil + RzIOFdWrite fd_write; //needed for esil + RzIOFdReadAt fd_read_at; + RzIOFdWriteAt fd_write_at; + RzIOFdIsDbg fd_is_dbg; + RzIOFdGetName fd_get_name; + RzIOFdGetMap fd_get_map; + RzIOFdRemap fd_remap; + RzIOIsValidOff is_valid_offset; + RzIOAddrIsMapped addr_is_mapped; + RzIOMapGet map_get; + RzIOMapGetPaddr map_get_paddr; + RzIOMapAdd map_add; + RzIOV2P v2p; + RzIOP2V p2v; +#if HAVE_PTRACE + RzIOPtraceFn ptrace; + RzIOPtraceFuncFn ptrace_func; +#endif +} RzIOBind; + +//map.c +RZ_API RzIOMap *rz_io_map_new(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); +RZ_API void rz_io_map_init (RzIO *io); +RZ_API bool rz_io_map_remap (RzIO *io, ut32 id, ut64 addr); +RZ_API bool rz_io_map_remap_fd (RzIO *io, int fd, ut64 addr); +RZ_API ut64 rz_io_map_location(RzIO *io, ut64 size); +RZ_API bool rz_io_map_exists (RzIO *io, RzIOMap *map); +RZ_API bool rz_io_map_exists_for_id (RzIO *io, ut32 id); +RZ_API RzIOMap *rz_io_map_resolve (RzIO *io, ut32 id); +RZ_API RzIOMap *rz_io_map_add(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); +// same as rz_io_map_add but used when many maps need to be added. Call rz_io_update when all maps have been added. +RZ_API RzIOMap *rz_io_map_add_batch(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size); +RZ_API RzIOMap *rz_io_map_get(RzIO *io, ut64 addr); //returns the map at vaddr with the highest priority +// update the internal state of RzIO after a series of _batch operations +RZ_API void rz_io_update(RzIO *io); +RZ_API bool rz_io_map_is_mapped(RzIO* io, ut64 addr); +RZ_API RzIOMap *rz_io_map_get_paddr(RzIO *io, ut64 paddr); //returns the map at paddr with the highest priority +RZ_API void rz_io_map_reset(RzIO* io); +RZ_API bool rz_io_map_del(RzIO *io, ut32 id); +RZ_API bool rz_io_map_del_for_fd(RzIO *io, int fd); +RZ_API bool rz_io_map_depriorize(RzIO* io, ut32 id); +RZ_API bool rz_io_map_priorize (RzIO *io, ut32 id); +RZ_API bool rz_io_map_priorize_for_fd (RzIO *io, int fd); +RZ_API void rz_io_map_cleanup (RzIO *io); +RZ_API void rz_io_map_fini (RzIO *io); +RZ_API bool rz_io_map_is_in_range (RzIOMap *map, ut64 from, ut64 to); +RZ_API void rz_io_map_set_name (RzIOMap *map, const char *name); +RZ_API void rz_io_map_del_name (RzIOMap *map); +RZ_API RzList* rz_io_map_get_for_fd(RzIO *io, int fd); +RZ_API bool rz_io_map_resize(RzIO *io, ut32 id, ut64 newsize); + +// next free address to place a map.. maybe just unify +RZ_API ut64 rz_io_map_next_available(RzIO* io, ut64 addr, ut64 size, ut64 load_align); +RZ_API ut64 rz_io_map_next_address(RzIO* io, ut64 addr); + +// p2v/v2p + +RZ_API ut64 rz_io_p2v(RzIO *io, ut64 pa); +RZ_API ut64 rz_io_v2p(RzIO *io, ut64 va); + +//io.c +RZ_API RzIO *rz_io_new (void); +RZ_API RzIO *rz_io_init (RzIO *io); +RZ_API RzIODesc *rz_io_open_nomap (RzIO *io, const char *uri, int flags, int mode); //should return int +RZ_API RzIODesc *rz_io_open (RzIO *io, const char *uri, int flags, int mode); +RZ_API RzIODesc *rz_io_open_at (RzIO *io, const char *uri, int flags, int mode, ut64 at); +RZ_API RzList *rz_io_open_many (RzIO *io, const char *uri, int flags, int mode); +RZ_API RzIODesc* rz_io_open_buffer (RzIO *io, RBuffer *b, int flags, int mode); +RZ_API bool rz_io_close (RzIO *io); +RZ_API bool rz_io_reopen (RzIO *io, int fd, int flags, int mode); +RZ_API int rz_io_close_all (RzIO *io); +RZ_API int rz_io_pread_at (RzIO *io, ut64 paddr, ut8 *buf, int len); +RZ_API int rz_io_pwrite_at (RzIO *io, ut64 paddr, const ut8 *buf, int len); +RZ_API bool rz_io_vread_at_mapped(RzIO* io, ut64 vaddr, ut8* buf, int len); +RZ_API bool rz_io_read_at (RzIO *io, ut64 addr, ut8 *buf, int len); +RZ_API bool rz_io_read_at_mapped(RzIO *io, ut64 addr, ut8 *buf, int len); +RZ_API int rz_io_nread_at (RzIO *io, ut64 addr, ut8 *buf, int len); +RZ_API void rz_io_alprint(RzList *ls); +RZ_API bool rz_io_write_at (RzIO *io, ut64 addr, const ut8 *buf, int len); +RZ_API bool rz_io_read (RzIO *io, ut8 *buf, int len); +RZ_API bool rz_io_write (RzIO *io, ut8 *buf, int len); +RZ_API ut64 rz_io_size (RzIO *io); +RZ_API bool rz_io_is_listener (RzIO *io); +RZ_API char *rz_io_system (RzIO *io, const char* cmd); +RZ_API bool rz_io_resize (RzIO *io, ut64 newsize); +RZ_API int rz_io_extend_at (RzIO *io, ut64 addr, ut64 size); +RZ_API bool rz_io_set_write_mask (RzIO *io, const ut8 *mask, int len); +RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd); +RZ_API bool rz_io_shift (RzIO *io, ut64 start, ut64 end, st64 move); +RZ_API ut64 rz_io_seek (RzIO *io, ut64 offset, int whence); +RZ_API int rz_io_fini (RzIO *io); +RZ_API void rz_io_free (RzIO *io); +#define rz_io_bind_init(x) memset(&x,0,sizeof(x)) + +RZ_API bool rz_io_plugin_init(RzIO *io); +RZ_API int rz_io_plugin_open(RzIO *io, int fd, RzIOPlugin *plugin); +RZ_API int rz_io_plugin_close(RzIO *io, int fd, RzIOPlugin *plugin); +RZ_API int rz_io_plugin_generate(RzIO *io); +RZ_API bool rz_io_plugin_add(RzIO *io, RzIOPlugin *plugin); +RZ_API int rz_io_plugin_list(RzIO *io); +RZ_API int rz_io_plugin_list_json(RzIO *io); +RZ_API int rz_io_plugin_read(RzIODesc *desc, ut8 *buf, int len); +RZ_API int rz_io_plugin_write(RzIODesc *desc, const ut8 *buf, int len); +RZ_API int rz_io_plugin_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len); +RZ_API int rz_io_plugin_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len); +RZ_API RzIOPlugin *rz_io_plugin_resolve(RzIO *io, const char *filename, bool many); +RZ_API RzIOPlugin *rz_io_plugin_resolve_fd(RzIO *io, int fd); +RZ_API RzIOPlugin *rz_io_plugin_get_default(RzIO *io, const char *filename, bool many); + +/* undo api */ +// track seeks and writes +// TODO: needs cleanup..kinda big? +RZ_API int rz_io_undo_init(RzIO *io); +RZ_API void rz_io_undo_enable(RzIO *io, int seek, int write); +/* seek undo */ +RZ_API RzIOUndos *rz_io_sundo(RzIO *io, ut64 offset); +RZ_API RzIOUndos *rz_io_sundo_redo(RzIO *io); +RZ_API void rz_io_sundo_push(RzIO *io, ut64 off, int cursor); +RZ_API void rz_io_sundo_reset(RzIO *io); +RZ_API RzList *rz_io_sundo_list(RzIO *io, int mode); +/* write undo */ +RZ_API void rz_io_wundo_new(RzIO *io, ut64 off, const ut8 *data, int len); +RZ_API void rz_io_wundo_apply_all(RzIO *io, int set); +RZ_API int rz_io_wundo_apply(RzIO *io, struct rz_io_undo_w_t *u, int set); +RZ_API void rz_io_wundo_clear(RzIO *io); +RZ_API int rz_io_wundo_size(RzIO *io); +RZ_API void rz_io_wundo_list(RzIO *io); +RZ_API int rz_io_wundo_set_t(RzIO *io, RzIOUndoWrite *u, int set) ; +RZ_API void rz_io_wundo_set_all(RzIO *io, int set); +RZ_API int rz_io_wundo_set(RzIO *io, int n, int set); + +//desc.c +RZ_API RzIODesc *rz_io_desc_new (RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data); +RZ_API RzIODesc *rz_io_desc_open (RzIO *io, const char *uri, int flags, int mode); +RZ_API RzIODesc *rz_io_desc_open_plugin (RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode); +RZ_API bool rz_io_desc_close (RzIODesc *desc); +RZ_API int rz_io_desc_read (RzIODesc *desc, ut8 *buf, int count); +RZ_API int rz_io_desc_write (RzIODesc *desc, const ut8 *buf, int count); +RZ_API void rz_io_desc_free (RzIODesc *desc); +RZ_API bool rz_io_desc_add (RzIO *io, RzIODesc *desc); +RZ_API bool rz_io_desc_del (RzIO *io, int fd); +RZ_API RzIODesc *rz_io_desc_get (RzIO *io, int fd); +RZ_API ut64 rz_io_desc_seek (RzIODesc *desc, ut64 offset, int whence); +RZ_API bool rz_io_desc_resize (RzIODesc *desc, ut64 newsize); +RZ_API ut64 rz_io_desc_size (RzIODesc *desc); +RZ_API bool rz_io_desc_is_blockdevice (RzIODesc *desc); +RZ_API bool rz_io_desc_is_chardevice (RzIODesc *desc); +RZ_API bool rz_io_desc_exchange (RzIO *io, int fd, int fdx); //this should get 2 descs +RZ_API bool rz_io_desc_is_dbg (RzIODesc *desc); +RZ_API int rz_io_desc_get_pid (RzIODesc *desc); +RZ_API int rz_io_desc_get_tid (RzIODesc *desc); +RZ_API bool rz_io_desc_get_base (RzIODesc *desc, ut64 *base); +RZ_API int rz_io_desc_read_at (RzIODesc *desc, ut64 addr, ut8 *buf, int len); +RZ_API int rz_io_desc_write_at (RzIODesc *desc, ut64 addr, const ut8 *buf, int len); + +/* lifecycle */ +R_IPI bool rz_io_desc_init (RzIO *io); +R_IPI bool rz_io_desc_fini (RzIO *io); + +/* io/cache.c */ +RZ_API int rz_io_cache_invalidate(RzIO *io, ut64 from, ut64 to); +RZ_API bool rz_io_cache_at(RzIO *io, ut64 addr); +RZ_API void rz_io_cache_commit(RzIO *io, ut64 from, ut64 to); +RZ_API void rz_io_cache_init(RzIO *io); +RZ_API void rz_io_cache_fini (RzIO *io); +RZ_API int rz_io_cache_list(RzIO *io, int rad); +RZ_API void rz_io_cache_reset(RzIO *io, int set); +RZ_API bool rz_io_cache_write(RzIO *io, ut64 addr, const ut8 *buf, int len); +RZ_API bool rz_io_cache_read(RzIO *io, ut64 addr, ut8 *buf, int len); + +/* io/p_cache.c */ +RZ_API bool rz_io_desc_cache_init(RzIODesc *desc); +RZ_API int rz_io_desc_cache_write(RzIODesc *desc, ut64 paddr, const ut8 *buf, int len); +RZ_API int rz_io_desc_cache_read(RzIODesc *desc, ut64 paddr, ut8 *buf, int len); +RZ_API bool rz_io_desc_cache_commit(RzIODesc *desc); +RZ_API void rz_io_desc_cache_cleanup(RzIODesc *desc); +RZ_API void rz_io_desc_cache_fini(RzIODesc *desc); +RZ_API void rz_io_desc_cache_fini_all(RzIO *io); +RZ_API RzList *rz_io_desc_cache_list(RzIODesc *desc); +RZ_API int rz_io_desc_extend(RzIODesc *desc, ut64 size); + +/* io/buffer.c */ +RZ_API int rz_io_buffer_read (RzIO* io, ut64 addr, ut8* buf, int len); +RZ_API int rz_io_buffer_load (RzIO* io, ut64 addr, int len); +RZ_API void rz_io_buffer_close (RzIO* io); + +/* io/fd.c */ +RZ_API int rz_io_fd_open (RzIO *io, const char *uri, int flags, int mode); +RZ_API bool rz_io_fd_close (RzIO *io, int fd); +RZ_API int rz_io_fd_read (RzIO *io, int fd, ut8 *buf, int len); +RZ_API int rz_io_fd_write (RzIO *io, int fd, const ut8 *buf, int len); +RZ_API ut64 rz_io_fd_seek (RzIO *io, int fd, ut64 addr, int whence); +RZ_API ut64 rz_io_fd_size (RzIO *io, int fd); +RZ_API bool rz_io_fd_resize (RzIO *io, int fd, ut64 newsize); +RZ_API bool rz_io_fd_is_blockdevice (RzIO *io, int fd); +RZ_API bool rz_io_fd_is_chardevice (RzIO *io, int fd); +RZ_API int rz_io_fd_read_at (RzIO *io, int fd, ut64 addr, ut8 *buf, int len); +RZ_API int rz_io_fd_write_at (RzIO *io, int fd, ut64 addr, const ut8 *buf, int len); +RZ_API bool rz_io_fd_is_dbg (RzIO *io, int fd); +RZ_API int rz_io_fd_get_pid (RzIO *io, int fd); +RZ_API int rz_io_fd_get_tid (RzIO *io, int fd); +RZ_API bool rz_io_fd_get_base (RzIO *io, int fd, ut64 *base); +RZ_API const char *rz_io_fd_get_name (RzIO *io, int fd); +RZ_API int rz_io_fd_get_current(RzIO *io); +RZ_API bool rz_io_use_fd (RzIO *io, int fd); + + +#define rz_io_range_new() R_NEW0(RzIORange) +#define rz_io_range_free(x) free(x) + +/* io/ioutils.c */ +RZ_API bool rz_io_is_valid_offset (RzIO *io, ut64 offset, int hasperm); +RZ_API bool rz_io_addr_is_mapped(RzIO *io, ut64 vaddr); +RZ_API bool rz_io_read_i (RzIO* io, ut64 addr, ut64 *val, int size, bool endian); +RZ_API bool rz_io_write_i (RzIO* io, ut64 addr, ut64 *val, int size, bool endian); + +#if HAVE_PTRACE +RZ_API long rz_io_ptrace(RzIO *io, rz_ptrace_request_t request, pid_t pid, void *addr, rz_ptrace_data_t data); +RZ_API pid_t rz_io_ptrace_fork(RzIO *io, void (*child_callback)(void *), void *child_callback_user); +RZ_API void *rz_io_ptrace_func(RzIO *io, void *(*func)(void *), void *user); +#endif + +extern RzIOPlugin rz_io_plugin_procpid; +extern RzIOPlugin rz_io_plugin_malloc; +extern RzIOPlugin rz_io_plugin_sparse; +extern RzIOPlugin rz_io_plugin_ptrace; +extern RzIOPlugin rz_io_plugin_w32dbg; +extern RzIOPlugin rz_io_plugin_windbg; +extern RzIOPlugin rz_io_plugin_mach; +extern RzIOPlugin rz_io_plugin_debug; +extern RzIOPlugin rz_io_plugin_shm; +extern RzIOPlugin rz_io_plugin_gdb; +extern RzIOPlugin rz_io_plugin_rap; +extern RzIOPlugin rz_io_plugin_http; +extern RzIOPlugin rz_io_plugin_bfdbg; +extern RzIOPlugin rz_io_plugin_w32; +extern RzIOPlugin rz_io_plugin_zip; +extern RzIOPlugin rz_io_plugin_mmap; +extern RzIOPlugin rz_io_plugin_default; +extern RzIOPlugin rz_io_plugin_ihex; +extern RzIOPlugin rz_io_plugin_self; +extern RzIOPlugin rz_io_plugin_gzip; +extern RzIOPlugin rz_io_plugin_winkd; +extern RzIOPlugin rz_io_plugin_rzpipe; +extern RzIOPlugin rz_io_plugin_rzweb; +extern RzIOPlugin rz_io_plugin_qnx; +extern RzIOPlugin rz_io_plugin_rzk; +extern RzIOPlugin rz_io_plugin_tcp; +extern RzIOPlugin rz_io_plugin_bochs; +extern RzIOPlugin rz_io_plugin_null; +extern RzIOPlugin rz_io_plugin_ar; +extern RzIOPlugin rz_io_plugin_rbuf; +extern RzIOPlugin rz_io_plugin_winedbg; +extern RzIOPlugin rz_io_plugin_gprobe; +extern RzIOPlugin rz_io_plugin_fd; + +#if __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_lang.h b/librz/include/rz_lang.h new file mode 100644 index 0000000000..44d5bcf4e7 --- /dev/null +++ b/librz/include/rz_lang.h @@ -0,0 +1,78 @@ +#ifndef R2_LANG_H +#define R2_LANG_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_lang); + +typedef char* (*RzCoreCmdStrCallback)(void* core, const char *s); +typedef int (*RzCoreCmdfCallback)(void* core, const char *s, ...); + +typedef struct rz_lang_t { + struct rz_lang_plugin_t *cur; + void *user; + RzList *defs; + RzList *langs; + PrintfCallback cb_printf; + RzCoreCmdStrCallback cmd_str; + RzCoreCmdfCallback cmdf; +} RzLang; + +typedef struct rz_lang_plugin_t { + const char *name; + const char *alias; + const char *desc; + const char *license; + const char **help; + const char *ext; + int (*init)(RzLang *user); + bool (*setup)(RzLang *user); + int (*fini)(RzLang *user); + int (*prompt)(RzLang *user); + int (*run)(RzLang *user, const char *code, int len); + int (*run_file)(RzLang *user, const char *file); + int (*set_argv)(RzLang *user, int argc, char **argv); +} RzLangPlugin; + +typedef struct rz_lang_def_t { + char *name; + char *type; + void *value; +} RzLangDef; + +#ifdef RZ_API +RZ_API RzLang *rz_lang_new(void); +RZ_API void rz_lang_free(RzLang *lang); +RZ_API bool rz_lang_setup(RzLang *lang); +RZ_API bool rz_lang_add(RzLang *lang, RzLangPlugin *foo); +RZ_API bool rz_lang_list(RzLang *lang); +RZ_API bool rz_lang_use(RzLang *lang, const char *name); +RZ_API int rz_lang_run(RzLang *lang, const char *code, int len); +RZ_API int rz_lang_run_string(RzLang *lang, const char *code); +/* TODO: user_ptr must be deprecated */ +RZ_API void rz_lang_set_user_ptr(RzLang *lang, void *user); +RZ_API bool rz_lang_set_argv(RzLang *lang, int argc, char **argv); +RZ_API int rz_lang_run(RzLang *lang, const char *code, int len); +RZ_API int rz_lang_run_file(RzLang *lang, const char *file); +RZ_API int rz_lang_prompt(RzLang *lang); +RZ_API void rz_lang_plugin_free(RzLangPlugin *p); // XXX +RZ_API RzLangPlugin *rz_lang_get_by_name(RzLang *lang, const char *name); +RZ_API RzLangPlugin *rz_lang_get_by_extension(RzLang *lang, const char *ext); +// TODO: rename rz_Lang_add for rz_lang_plugin_add + +RZ_API bool rz_lang_define(RzLang *lang, const char *type, const char *name, void *value); +RZ_API void rz_lang_undef(RzLang *lang, const char *name); +RZ_API void rz_lang_def_free(RzLangDef *def); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_lib.h b/librz/include/rz_lib.h new file mode 100644 index 0000000000..cc4e443865 --- /dev/null +++ b/librz/include/rz_lib.h @@ -0,0 +1,128 @@ +#ifndef R2_LIB_H +#define R2_LIB_H + +#include "rz_types.h" +#include "rz_list.h" + +#if __UNIX__ +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER (rz_lib); + +// rename to '.' ?? +#define R_LIB_SEPARATOR "." +#define R_LIB_SYMNAME "radare_plugin" +#define R_LIB_SYMFUNC "radare_plugin_function" + +#define R_LIB_ENV "R2_LIBR_PLUGINS" + +/* TODO: This must depend on HOST_OS, and maybe move into rz_types */ +#if __WINDOWS__ +#include +#define R_LIB_EXT "dll" +#elif __APPLE__ +#define R_LIB_EXT "dylib" +#else +#define R_LIB_EXT "so" +#endif + +/* store list of loaded plugins */ +typedef struct rz_lib_plugin_t { + int type; + char *file; + void *data; /* user pointer */ + struct rz_lib_handler_t *handler; + void *dl_handler; // DL HANDLER + char *author; + char *version; + void (*free)(void *data); +} RzLibPlugin; + +/* store list of initialized plugin handlers */ +typedef struct rz_lib_handler_t { + int type; + char desc[128]; // TODO: use char * + void *user; /* user pointer */ + int (*constructor)(RzLibPlugin *, void *user, void *data); + int (*destructor)(RzLibPlugin *, void *user, void *data); +} RzLibHandler; + +/* this structure should be pointed by the 'radare_plugin' symbol + found in the loaded .so */ +typedef struct rz_lib_struct_t { + int type; + void *data; /* pointer to data handled by plugin handler */ + const char *version; /* r2 version */ + void (*free)(void *data); + const char *pkgname; /* pkgname associated to this plugin */ +} RzLibStruct; + +typedef RzLibStruct* (*RzLibStructFunc) (void); + +// order matters because of librz/util/lib.c +enum { + R_LIB_TYPE_IO, /* io layer */ + R_LIB_TYPE_DBG, /* debugger */ + R_LIB_TYPE_LANG, /* language */ + R_LIB_TYPE_ASM, /* assembler */ + R_LIB_TYPE_ANAL, /* analysis */ + R_LIB_TYPE_PARSE, /* parsers */ + R_LIB_TYPE_BIN, /* bin headers */ + R_LIB_TYPE_BIN_XTR, /* bin extractors */ + R_LIB_TYPE_BIN_LDR, /* bin loaders */ + R_LIB_TYPE_BP, /* breakpoint */ + R_LIB_TYPE_SYSCALL, /* syscall */ + R_LIB_TYPE_FASTCALL,/* fastcall */ + R_LIB_TYPE_CRYPTO, /* cryptography */ + R_LIB_TYPE_CORE, /* RzCore commands */ + R_LIB_TYPE_EGG, /* rz_egg plugin */ + R_LIB_TYPE_FS, /* rz_fs plugin */ + R_LIB_TYPE_LAST +}; + +typedef struct rz_lib_t { + /* linked list with all the plugin handler */ + /* only one handler per handler-id allowed */ + /* this is checked in add_handler function */ + char *symname; + char *symnamefunc; + RzList /*RzLibPlugin*/ *plugins; + RzList /*RzLibHandler*/ *handlers; +} RzLib; + +#ifdef RZ_API +/* low level api */ +RZ_API void *rz_lib_dl_open(const char *libname); + +RZ_API void *rz_lib_dl_sym(void *handler, const char *name); +RZ_API int rz_lib_dl_close(void *handler); + +/* high level api */ +typedef int (*RzLibCallback)(RzLibPlugin *, void *, void *); +RZ_API RzLib *rz_lib_new(const char *symname, const char *symnamefunc); +RZ_API void rz_lib_free(RzLib *lib); +RZ_API int rz_lib_run_handler(RzLib *lib, RzLibPlugin *plugin, RzLibStruct *symbol); +RZ_API RzLibHandler *rz_lib_get_handler(RzLib *lib, int type); +RZ_API int rz_lib_open(RzLib *lib, const char *file); +RZ_API bool rz_lib_opendir(RzLib *lib, const char *path); +RZ_API int rz_lib_open_ptr (RzLib *lib, const char *file, void *handler, RzLibStruct *stru); +RZ_API char *rz_lib_path(const char *libname); +RZ_API void rz_lib_list(RzLib *lib); +RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, RzLibCallback ct, RzLibCallback dt, void *user); +RZ_API bool rz_lib_del_handler(RzLib *lib, int type); +RZ_API int rz_lib_close(RzLib *lib, const char *file); + +RZ_API const char *rz_lib_types_get(int idx); +RZ_API int rz_lib_types_get_i(const char *str); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_list.h b/librz/include/rz_list.h new file mode 100644 index 0000000000..21101bfa37 --- /dev/null +++ b/librz/include/rz_list.h @@ -0,0 +1,142 @@ +#ifndef R2_LIST_H +#define R2_LIST_H + +#include +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _INCLUDE_R_LIST_HEAD_H_ +#define _INCLUDE_R_LIST_HEAD_H_ +typedef void (*RzListFree)(void *ptr); + +typedef struct rz_list_iter_t { + void *data; + struct rz_list_iter_t *n, *p; +} RzListIter; + +typedef struct rz_list_t { + RzListIter *head; + RzListIter *tail; + RzListFree free; + int length; + bool sorted; +} RzList; + +typedef struct rz_list_range_t { + HtPP *h; + RzList *l; + //RzListComparator c; +} RzListRange; + +// RzListComparator should return -1, 0, 1 to indicate "ab". +typedef int (*RzListComparator)(const void *a, const void *b); + +#define ROFList_Parent RzList +typedef struct rz_oflist_t { + ROFList_Parent super; // super class + RFList *array; // statical readonly cache of linked list as a pointer array +} ROFList; +#endif + +#ifdef RZ_API +// #define R_LIST_NEW(x,y) x = rz_list_new (); x->free = (RzListFree)y +#define rz_list_foreach(list, it, pos)\ + if (list)\ + for (it = list->head; it && (pos = it->data, 1); it = it->n) +#define rz_list_foreach_iter(list, it)\ + if (list)\ + for (it = list->head; it; it = it->n) +/* Safe when calling rz_list_delete() while iterating over the list. */ +#define rz_list_foreach_safe(list, it, tmp, pos)\ + if (list)\ + for (it = list->head; it && (pos = it->data, tmp = it->n, 1); it = tmp) +#define rz_list_foreach_prev(list, it, pos)\ + if (list)\ + for (it = list->tail; it && (pos = it->data, 1); it = it->p) +#define rz_list_foreach_prev_safe(list, it, tmp, pos) \ + for (it = list->tail; it && (pos = it->data, tmp = it->p, 1); it = tmp) +#ifndef _R_LIST_C_ +#define rz_list_push(x, y) rz_list_append (x, y) +#define rz_list_iterator(x) (x)? (x)->head: NULL +// #define rz_list_empty(x) (!x || (!(x->head) && !(x->tail))) +#define rz_list_empty(x) (!(x) || !(x)->length) +#define rz_list_head(x) ((x)? (x)->head: NULL) +#define rz_list_tail(x) ((x)? (x)->tail: NULL) + +#define rz_list_iter_get(x)\ + x->data;\ + x = x->n +#define rz_list_iter_next(x) (x? 1: 0) + +#define rz_list_iter_cur(x) x->p +#define rz_list_iter_free(x) x +#endif +RZ_API RzList *rz_list_new(void); +RZ_API RzList *rz_list_newf(RzListFree f); +RZ_API RzListIter *rz_list_iter_get_next(RzListIter *list); +RZ_API int rz_list_set_n(RzList *list, int n, void *p); +RZ_API void *rz_list_iter_get_data(RzListIter *list); +RZ_API RzListIter *rz_list_append(RzList *list, void *data); +RZ_API RzListIter *rz_list_prepend(RzList *list, void *data); +RZ_API RzListIter *rz_list_insert(RzList *list, int n, void *data); +RZ_API int rz_list_length(const RzList *list); +RZ_API void *rz_list_first(const RzList *list); +RZ_API void *rz_list_last(const RzList *list); +RZ_API RzListIter *rz_list_add_sorted(RzList *list, void *data, RzListComparator cmp); +RZ_API void rz_list_sort(RzList *list, RzListComparator cmp); +RZ_API void rz_list_merge_sort(RzList *list, RzListComparator cmp); +RZ_API void rz_list_insertion_sort(RzList *list, RzListComparator cmp); +RZ_API RzList *rz_list_uniq(const RzList *list, RzListComparator cmp); +RZ_API void rz_list_init(RzList *list); +RZ_API void rz_list_delete(RzList *list, RzListIter *iter); +RZ_API bool rz_list_delete_data(RzList *list, void *ptr); +RZ_API void rz_list_iter_init(RzListIter *iter, RzList *list); +RZ_API void rz_list_purge(RzList *list); +RZ_API void rz_list_free(RzList *list); +RZ_API RzListIter *rz_list_item_new(void *data); +RZ_API void rz_list_split(RzList *list, void *ptr); +RZ_API void rz_list_split_iter(RzList *list, RzListIter *iter); +RZ_API int rz_list_join(RzList *list1, RzList *list2); +RZ_API void *rz_list_get_n(const RzList *list, int n); +RZ_API int rz_list_del_n(RzList *list, int n); +RZ_API void *rz_list_get_top(const RzList *list); +RZ_API void *rz_list_get_bottom(const RzList *list); +RZ_API void *rz_list_pop(RzList *list); +RZ_API void *rz_list_pop_head(RzList *list); +RZ_API void rz_list_reverse(RzList *list); +RZ_API RzList *rz_list_clone(const RzList *list); +RZ_API char *rz_list_to_str(RzList *list, char ch); + +/* hashlike api */ +RZ_API RzListIter *rz_list_contains(const RzList *list, const void *p); +RZ_API RzListIter *rz_list_find(const RzList *list, const void *p, RzListComparator cmp); + +/* rlistflist */ +// TODO: rename to init or so.. #define rz_oflist_new() R_NEW(ROFList);memset +#define rz_oflist_length(x, y) rz_list_length (x, y) +#define rz_oflist_destroy(x) rz_oflist_deserialize (x) +#define rz_oflist_free(x) rz_oflist_deserialize (x), rz_list_free (x) +#define rz_oflist_append(x, y) rz_oflist_deserialize (x), rz_list_append (x, y) +#define rz_oflist_prepend(x, y) rz_oflist_deserialize (x), rz_list_prepend (x, y) +#define rz_oflist_delete(x, y) rz_oflist_deserialize (x), rz_list_delete (x, y) +#define rz_oflist_array(x) x->array? x->array: (x->array = rz_oflist_serialize (x)), x->array +#define rz_oflist_deserialize(x)\ + free (x->array - 1), x->array = 0 +#define rz_oflist_serialize(x)\ + x->array = rz_flist_new (rz_list_length (x)), { \ + int idx = 0;\ + void *ptr;\ + RzListIter *iter;\ + rz_list_foreach (x, iter, ptr) rz_flist_set (x->array, idx++, ptr);\ + }\ + x->array; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_magic.h b/librz/include/rz_magic.h similarity index 91% rename from libr/include/r_magic.h rename to librz/include/rz_magic.h index b5e2a1a3e3..10201f48ec 100644 --- a/libr/include/r_magic.h +++ b/librz/include/rz_magic.h @@ -3,19 +3,19 @@ #ifndef R2_MAGIC_H #define R2_MAGIC_H -#include +#include #ifdef __cplusplus extern "C" { #endif -R_LIB_VERSION_HEADER(r_magic); +R_LIB_VERSION_HEADER(rz_magic); #ifndef MAGICFILE #define MAGICFILE "/etc/magic" #endif -#ifdef R_API +#ifdef RZ_API #ifdef __EMX__ #define PATHSEP ';' @@ -54,7 +54,7 @@ union VALUETYPE { #define FILE_CHECK 1 #define FILE_COMPILE 2 -struct r_magic { +struct rz_magic { /* Word 1 */ ut16 cont_level; /* level of ">" */ ut8 flag; @@ -202,7 +202,7 @@ struct r_magic { /* list of magic entries */ struct mlist { - struct r_magic *magic; /* array of magic entries */ + struct rz_magic *magic; /* array of magic entries */ ut32 nmagic; /* number of entries in array */ int mapped; /* allocation type: 0 => apprentice_file * 1 => apprentice_map + malloc @@ -235,7 +235,7 @@ struct mlist { #define MAGIC_NO_CHECK_FORTRAN 0x000000 /* Don't check ascii/fortran */ #define MAGIC_NO_CHECK_TROFF 0x000000 /* Don't check ascii/troff */ -struct r_magic_set { +struct rz_magic_set { struct mlist *mlist; struct cont { size_t len; @@ -271,27 +271,27 @@ struct r_magic_set { }; #if USE_LIB_MAGIC -#define RMagic struct magic_set +#define RzMagic struct magic_set #else -typedef struct r_magic_set RMagic; +typedef struct rz_magic_set RzMagic; #endif -#ifdef R_API -R_API RMagic* r_magic_new(int flags); -R_API void r_magic_free(RMagic*); +#ifdef RZ_API +RZ_API RzMagic* rz_magic_new(int flags); +RZ_API void rz_magic_free(RzMagic*); -R_API const char *r_magic_file(RMagic*, const char *); -R_API const char *r_magic_descriptor(RMagic*, int); -R_API const char *r_magic_buffer(RMagic*, const void *, size_t); +RZ_API const char *rz_magic_file(RzMagic*, const char *); +RZ_API const char *rz_magic_descriptor(RzMagic*, int); +RZ_API const char *rz_magic_buffer(RzMagic*, const void *, size_t); -R_API const char *r_magic_error(RMagic*); -R_API void r_magic_setflags(RMagic*, int); +RZ_API const char *rz_magic_error(RzMagic*); +RZ_API void rz_magic_setflags(RzMagic*, int); -R_API bool r_magic_load(RMagic*, const char *); -R_API bool r_magic_load_buffer(RMagic*, const char *); -R_API bool r_magic_compile(RMagic*, const char *); -R_API bool r_magic_check(RMagic*, const char *); -R_API int r_magic_errno(RMagic*); +RZ_API bool rz_magic_load(RzMagic*, const char *); +RZ_API bool rz_magic_load_buffer(RzMagic*, const char *); +RZ_API bool rz_magic_compile(RzMagic*, const char *); +RZ_API bool rz_magic_check(RzMagic*, const char *); +RZ_API int rz_magic_errno(RzMagic*); #endif diff --git a/librz/include/rz_main.h b/librz/include/rz_main.h new file mode 100644 index 0000000000..e9f8d2f7e8 --- /dev/null +++ b/librz/include/rz_main.h @@ -0,0 +1,36 @@ +/* radare - LGPL - Copyright 2008-2020 - pancake */ + +#ifndef R2_MAIN_H +#define R2_MAIN_H + +#include +#include + +R_LIB_VERSION_HEADER(rz_main); + +typedef struct rz_main_t { + const char *name; + int (*main)(int argc, const char **argv); + // stdin/stdout +} RzMain; + +typedef int (*RzMainCallback)(int argc, const char **argv); + +RZ_API RzMain *rz_main_new(const char *name); +RZ_API void rz_main_free(RzMain *m); +RZ_API int rz_main_run(RzMain *m, int argc, const char **argv); + +RZ_API int rz_main_version_print(const char *program); +RZ_API int rz_main_rz_ax(int argc, const char **argv); +RZ_API int rz_main_rz_run(int argc, const char **argv); +RZ_API int rz_main_rz_hash(int argc, const char **argv); +RZ_API int rz_main_rz_bin(int argc, const char **argv); +RZ_API int rz_main_rizin(int argc, const char **argv); +RZ_API int rz_main_rz_asm(int argc, const char **argv); +RZ_API int rz_main_rz_agent(int argc, const char **argv); +RZ_API int rz_main_rz_find(int argc, const char **argv); +RZ_API int rz_main_rz_diff(int argc, const char **argv); +RZ_API int rz_main_rz_gg(int argc, const char **argv); +RZ_API int rz_main_rz_sign(int argc, const char **argv); + +#endif diff --git a/librz/include/rz_parse.h b/librz/include/rz_parse.h new file mode 100644 index 0000000000..745260c312 --- /dev/null +++ b/librz/include/rz_parse.h @@ -0,0 +1,145 @@ +/* radare - LGPL - Copyright 2009-2018 - pancake, nibble */ + +#ifndef R2_PARSE_H +#define R2_PARSE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_parse); + +typedef RzList* (*RzAnalVarList)(RzAnalFunction *fcn, int kind); + +typedef struct rz_parse_t { + void *user; + RSpace *flagspace; + RSpace *notin_flagspace; + bool pseudo; + bool subreg; // replace registers with their respective alias/role name (rdi=A0, ...) + bool subrel; // replace rip relative expressions in instruction + bool subtail; // replace any immediate relative to current address with .. prefix syntax + bool localvar_only; // if true use only the local variable name (e.g. [local_10h] instead of [ebp + local10h]) + ut64 subrel_addr; + int maxflagnamelen; + int minval; + char *retleave_asm; + struct rz_parse_plugin_t *cur; + // RzAnal *anal; // weak anal ref XXX do not use. use analb.anal + RzList *parsers; + RzAnalVarList varlist; + st64 (*get_ptr_at)(RzAnalFunction *fcn, st64 delta, ut64 addr); + const char *(*get_reg_at)(RzAnalFunction *fcn, st64 delta, ut64 addr); + char* (*get_op_ireg)(void *user, ut64 addr); + RzAnalBind analb; + RzFlagGetAtAddr flag_get; // XXX + RzAnalLabelAt label_get; +} RzParse; + +typedef struct rz_parse_plugin_t { + char *name; + char *desc; + bool (*init)(RzParse *p, void *user); + int (*fini)(RzParse *p, void *user); + int (*parse)(RzParse *p, const char *data, char *str); + bool (*assemble)(RzParse *p, char *data, char *str); + int (*filter)(RzParse *p, ut64 addr, RzFlag *f, char *data, char *str, int len, bool big_endian); + bool (*subvar)(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); + int (*replace)(int argc, const char *argv[], char *newstr); +} RzParsePlugin; + +#ifdef RZ_API + +/* lifecycle */ +RZ_API struct rz_parse_t *rz_parse_new(void); +RZ_API void rz_parse_free(RzParse *p); + +/* plugins */ +RZ_API void rz_parse_set_user_ptr(RzParse *p, void *user); +RZ_API bool rz_parse_add(RzParse *p, RzParsePlugin *foo); +RZ_API bool rz_parse_use(RzParse *p, const char *name); + +/* action */ +RZ_API bool rz_parse_parse(RzParse *p, const char *data, char *str); +RZ_API bool rz_parse_assemble(RzParse *p, char *data, char *str); // XXX deprecate, unused and probably useless, related to write-hack +RZ_API bool rz_parse_filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalHint *hint, char *data, char *str, int len, bool big_endian); +RZ_API bool rz_parse_subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len); +RZ_API char *rz_parse_immtrim(char *opstr); + +/* c */ +// why we have anal scoped things in rparse +RZ_API char *rz_parse_c_string(RzAnal *anal, const char *code, char **error_msg); +RZ_API char *rz_parse_c_file(RzAnal *anal, const char *path, const char *dir, char **error_msg); +RZ_API void rz_parse_c_reset(RzParse *p); + +/* ctype */ +// Parses strings like "const char * [0x42] const * [23]" to RzParseCTypeType + +typedef struct rz_parse_ctype_t RzParseCType; + +typedef enum { + R_PARSE_CTYPE_TYPE_KIND_IDENTIFIER, + R_PARSE_CTYPE_TYPE_KIND_POINTER, + R_PARSE_CTYPE_TYPE_KIND_ARRAY +} RzParseCTypeTypeKind; + +typedef enum { + R_PARSE_CTYPE_IDENTIFIER_KIND_UNSPECIFIED, + R_PARSE_CTYPE_IDENTIFIER_KIND_STRUCT, + R_PARSE_CTYPE_IDENTIFIER_KIND_UNION, + R_PARSE_CTYPE_IDENTIFIER_KIND_ENUM +} RzParseCTypeTypeIdentifierKind; + +typedef struct rz_parse_ctype_type_t RzParseCTypeType; +struct rz_parse_ctype_type_t { + RzParseCTypeTypeKind kind; + union { + struct { + RzParseCTypeTypeIdentifierKind kind; + char *name; + bool is_const; + } identifier; + struct { + RzParseCTypeType *type; + bool is_const; + } pointer; + struct { + RzParseCTypeType *type; + ut64 count; + } array; + }; +}; + +RZ_API RzParseCType *rz_parse_ctype_new(void); +RZ_API void rz_parse_ctype_free(RzParseCType *ctype); +RZ_API RzParseCTypeType *rz_parse_ctype_parse(RzParseCType *ctype, const char *str, char **error); +RZ_API void rz_parse_ctype_type_free(RzParseCTypeType *type); + +/* plugin pointers */ +extern RzParsePlugin rz_parse_plugin_6502_pseudo; +extern RzParsePlugin rz_parse_plugin_arm_pseudo; +extern RzParsePlugin rz_parse_plugin_att2intel; +extern RzParsePlugin rz_parse_plugin_avr_pseudo; +extern RzParsePlugin rz_parse_plugin_chip8_pseudo; +extern RzParsePlugin rz_parse_plugin_dalvik_pseudo; +extern RzParsePlugin rz_parse_plugin_dummy; +extern RzParsePlugin rz_parse_plugin_m68k_pseudo; +extern RzParsePlugin rz_parse_plugin_mips_pseudo; +extern RzParsePlugin rz_parse_plugin_ppc_pseudo; +extern RzParsePlugin rz_parse_plugin_sh_pseudo; +extern RzParsePlugin rz_parse_plugin_wasm_pseudo; +extern RzParsePlugin rz_parse_plugin_x86_pseudo; +extern RzParsePlugin rz_parse_plugin_z80_pseudo; +extern RzParsePlugin rz_parse_plugin_tms320_pseudo; +extern RzParsePlugin rz_parse_plugin_v850_pseudo; +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_pdb.h b/librz/include/rz_pdb.h new file mode 100644 index 0000000000..3cca4486af --- /dev/null +++ b/librz/include/rz_pdb.h @@ -0,0 +1,39 @@ +#ifndef R2_PDB_H +#define R2_PDB_H + +#define _R_LIST_C +#include "rz_util.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define FILE_NAME_LEN 256 + +struct R_PDB7_ROOT_STREAM; + +typedef struct rz_pdb_t { + bool (*pdb_parse)(struct rz_pdb_t *pdb); + void (*finish_pdb_parse)(struct rz_pdb_t *pdb); + void (*print_types)(const struct rz_pdb_t *pdb, PJ *pj, int mode); +// FILE *fp; + PrintfCallback cb_printf; + struct R_PDB7_ROOT_STREAM *root_stream; + void *stream_map; + RzList *pdb_streams; + RzList *pdb_streams2; + RBuffer *buf; // mmap of file +// int curr; + + void (*print_gvars)(struct rz_pdb_t *pdb, ut64 img_base, PJ *pj, int format); +} RPdb; + +RZ_API bool init_pdb_parser(RPdb *pdb, const char *filename); +RZ_API bool init_pdb_parser_with_buf(RPdb *pdb, RBuffer *buf); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_qrcode.h b/librz/include/rz_qrcode.h similarity index 96% rename from libr/include/r_qrcode.h rename to librz/include/rz_qrcode.h index bb6745c853..c551189d07 100644 --- a/libr/include/r_qrcode.h +++ b/librz/include/rz_qrcode.h @@ -96,7 +96,7 @@ enum qrcodegen_Mask { * - Please consult the QR Code specification for information on * data capacities per version, ECC level, and text encoding mode. */ -R_API bool r_qrcode_text(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], +RZ_API bool rz_qrcode_text(const char *text, uint8_t tempBuffer[], uint8_t qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); @@ -118,8 +118,8 @@ R_API bool r_qrcode_text(const char *text, uint8_t tempBuffer[], uint8_t qrcode[ * - Please consult the QR Code specification for information on * data capacities per version, ECC level, and text encoding mode. */ -R_API bool r_qrcode_bin(uint8_t dataAndTemp[], int dataLen, uint8_t qrcode[], +RZ_API bool rz_qrcode_bin(uint8_t dataAndTemp[], int dataLen, uint8_t qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl); -R_API char *r_qrcode_print(const ut8* qrcode); +RZ_API char *rz_qrcode_print(const ut8* qrcode); diff --git a/librz/include/rz_reg.h b/librz/include/rz_reg.h new file mode 100644 index 0000000000..534eef293d --- /dev/null +++ b/librz/include/rz_reg.h @@ -0,0 +1,237 @@ +#ifndef R2_REG_H +#define R2_REG_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER (rz_reg); + +/* + * various CPUs have registers within various types/classes + * this enum aims to cover them all. + */ +typedef enum { + R_REG_TYPE_GPR, + R_REG_TYPE_DRX, + R_REG_TYPE_FPU, + R_REG_TYPE_MMX, + R_REG_TYPE_XMM, + R_REG_TYPE_YMM, + R_REG_TYPE_FLG, + R_REG_TYPE_SEG, + R_REG_TYPE_LAST, + R_REG_TYPE_ALL = -1, // TODO; rename to ANY +} RzRegisterType; + +/* + * pretty much all CPUs share some common registers + * this enum aims to create an abstraction to ease cross-arch handling. + */ +typedef enum { + R_REG_NAME_PC, // program counter + R_REG_NAME_SP, // stack pointer + R_REG_NAME_SR, // status register + R_REG_NAME_BP, // base pointer + R_REG_NAME_LR, // link register + /* args */ + R_REG_NAME_A0, // arguments + R_REG_NAME_A1, + R_REG_NAME_A2, + R_REG_NAME_A3, + R_REG_NAME_A4, + R_REG_NAME_A5, + R_REG_NAME_A6, + R_REG_NAME_A7, + R_REG_NAME_A8, + R_REG_NAME_A9, + /* retval */ + R_REG_NAME_R0, // return registers + R_REG_NAME_R1, + R_REG_NAME_R2, + R_REG_NAME_R3, + /* flags */ + R_REG_NAME_ZF, + R_REG_NAME_SF, + R_REG_NAME_CF, + R_REG_NAME_OF, + /* syscall number (orig_eax,rax,r0,x0) */ + R_REG_NAME_SN, + R_REG_NAME_LAST, +} RzRegisterId; + +// TODO: use enum here? +#define R_REG_COND_EQ 0 +#define R_REG_COND_NE 1 +#define R_REG_COND_CF 2 +#define R_REG_COND_CARRY 2 +#define R_REG_COND_NEG 3 +#define R_REG_COND_NEGATIVE 3 +#define R_REG_COND_OF 4 +#define R_REG_COND_OVERFLOW 4 +// unsigned +#define R_REG_COND_HI 5 +#define R_REG_COND_HE 6 +#define R_REG_COND_LO 7 +#define R_REG_COND_LOE 8 +// signed +#define R_REG_COND_GE 9 +#define R_REG_COND_GT 10 +#define R_REG_COND_LT 11 +#define R_REG_COND_LE 12 +#define R_REG_COND_LAST 13 + +typedef struct rz_reg_item_t { + char *name; + int /*RzRegisterType*/ type; + int size; /* 8,16,32,64 ... 128/256 ??? */ + int offset; /* offset in data structure */ + int packed_size; /* 0 means no packed register, 1byte pack, 2b pack... */ + bool is_float; + char *flags; + char *comment; + int index; + int arena; /* in which arena is this reg living */ +} RzRegItem; + +typedef struct rz_reg_arena_t { + ut8 *bytes; + int size; +} RzRegArena; + +typedef struct rz_reg_set_t { + RzRegArena *arena; + RzList *pool; /* RzRegArena */ + RzList *regs; /* RzRegItem */ + HtPP *ht_regs; /* name:RzRegItem */ + RzListIter *cur; + int maskregstype; /* which type of regs have this reg set (logic mask with RzRegisterType R_REG_TYPE_XXX) */ +} RzRegSet; + +typedef struct rz_reg_t { + char *profile; + char *reg_profile_cmt; + char *reg_profile_str; + char *name[R_REG_NAME_LAST]; // aliases + RzRegSet regset[R_REG_TYPE_LAST]; + RzList *allregs; + RzList *roregs; + int iters; + int arch; + int bits; + int size; + bool is_thumb; + bool big_endian; +} RzReg; + +typedef struct rz_reg_flags_t { + bool s; // sign, negative number (msb) + bool z; // zero + bool a; // half-carry adjust (if carry happens at nibble level) + bool c; // carry + bool o; // overflow + bool p; // parity (lsb) +} RzRegFlags; + +#ifdef RZ_API +RZ_API void rz_reg_free(RzReg *reg); +RZ_API void rz_reg_free_internal(RzReg *reg, bool init); +RZ_API RzReg *rz_reg_new(void); +RZ_API bool rz_reg_set_name(RzReg *reg, int role, const char *name); +RZ_API bool rz_reg_set_profile_string(RzReg *reg, const char *profile); +RZ_API char* rz_reg_profile_to_cc(RzReg *reg); +RZ_API bool rz_reg_set_profile(RzReg *reg, const char *profile); +RZ_API char *rz_reg_parse_gdb_profile(const char *profile); +RZ_API bool rz_reg_is_readonly(RzReg *reg, RzRegItem *item); + +RZ_API RzRegSet *rz_reg_regset_get(RzReg *r, int type); +RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name); +RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val); +RZ_API const char *rz_reg_32_to_64(RzReg *reg, const char *rreg32); +RZ_API const char *rz_reg_64_to_32(RzReg *reg, const char *rreg64); +RZ_API const char *rz_reg_get_name_by_type(RzReg *reg, const char *name); +RZ_API const char *rz_reg_get_type(int idx); +RZ_API const char *rz_reg_get_name(RzReg *reg, int kind); +RZ_API const char *rz_reg_get_role(int role); +RZ_API RzRegItem *rz_reg_get(RzReg *reg, const char *name, int type); +RZ_API RzList *rz_reg_get_list(RzReg *reg, int type); +RZ_API RzRegItem *rz_reg_get_at(RzReg *reg, int type, int regsize, int delta); +RZ_API RzRegItem *rz_reg_next_diff(RzReg *reg, int type, const ut8 *buf, int buflen, RzRegItem *prev_ri, int regsize); + +RZ_API void rz_reg_reindex(RzReg *reg); +RZ_API RzRegItem *rz_reg_index_get(RzReg *reg, int idx); + +/* Item */ +RZ_API void rz_reg_item_free(RzRegItem *item); + +/* XXX: dupped ?? */ +RZ_API int rz_reg_type_by_name(const char *str); +RZ_API int rz_reg_get_name_idx(const char *type); + +RZ_API RzRegItem *rz_reg_cond_get(RzReg *reg, const char *name); +RZ_API void rz_reg_cond_apply(RzReg *r, RzRegFlags *f); +RZ_API bool rz_reg_cond_set(RzReg *reg, const char *name, bool val); +RZ_API int rz_reg_cond_get_value(RzReg *r, const char *name); +RZ_API bool rz_reg_cond_bits_set(RzReg *r, int type, RzRegFlags *f, bool v); +RZ_API int rz_reg_cond_bits(RzReg *r, int type, RzRegFlags *f); +RZ_API RzRegFlags *rz_reg_cond_retrieve(RzReg *r, RzRegFlags *); +RZ_API int rz_reg_cond(RzReg *r, int type); + +/* integer value 8-64 bits */ +RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item); +RZ_API ut64 rz_reg_get_value_big(RzReg *reg, RzRegItem *item, utX *val); +RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role); +RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value); +RZ_API bool rz_reg_set_value_by_role(RzReg *reg, RzRegisterId role, ut64 value); + +/* float */ +RZ_API float rz_reg_get_float(RzReg *reg, RzRegItem *item); +RZ_API bool rz_reg_set_float(RzReg *reg, RzRegItem *item, float value); + +/* double */ +RZ_API double rz_reg_get_double(RzReg *reg, RzRegItem *item); +RZ_API bool rz_reg_set_double(RzReg *reg, RzRegItem *item, double value); + +/* long double */ +RZ_API long double rz_reg_get_longdouble(RzReg *reg, RzRegItem *item); +RZ_API bool rz_reg_set_longdouble(RzReg *reg, RzRegItem *item, long double value); + +/* boolean */ +RZ_API char *rz_reg_get_bvalue(RzReg *reg, RzRegItem *item); +RZ_API ut64 rz_reg_set_bvalue(RzReg *reg, RzRegItem *item, const char *str); + +/* packed registers */ +RZ_API int rz_reg_set_pack(RzReg *reg, RzRegItem *item, int packidx, int packbits, ut64 val); +RZ_API ut64 rz_reg_get_pack(RzReg *reg, RzRegItem *item, int packidx, int packbits); + +/* byte arena */ +RZ_API ut8 *rz_reg_get_bytes(RzReg *reg, int type, int *size); +RZ_API bool rz_reg_set_bytes(RzReg *reg, int type, const ut8 *buf, const int len); +RZ_API bool rz_reg_read_regs(RzReg *reg, ut8 *buf, const int len); +RZ_API int rz_reg_arena_set_bytes(RzReg *reg, const char *str); +RZ_API RzRegArena *rz_reg_arena_new(int size); +RZ_API void rz_reg_arena_free(RzRegArena *ra); +RZ_API int rz_reg_fit_arena(RzReg *reg); +RZ_API void rz_reg_arena_swap(RzReg *reg, int copy); +RZ_API int rz_reg_arena_push(RzReg *reg); +RZ_API void rz_reg_arena_pop(RzReg *reg); +RZ_API void rz_reg_arena_zero(RzReg *reg); + +RZ_API ut8 *rz_reg_arena_peek(RzReg *reg); +RZ_API void rz_reg_arena_poke(RzReg *reg, const ut8 *buf); +RZ_API ut8 *rz_reg_arena_dup(RzReg *reg, const ut8 *source); +RZ_API const char *rz_reg_cond_to_string(int n); +RZ_API int rz_reg_cond_from_string(const char *str); +RZ_API void rz_reg_arena_shrink(RzReg *reg); + +#ifdef __cplusplus +} +#endif + +#endif +#endif diff --git a/libr/include/r_regex.h b/librz/include/rz_regex.h similarity index 69% rename from libr/include/r_regex.h rename to librz/include/rz_regex.h index 706d4c40aa..d1aacbf22a 100644 --- a/libr/include/r_regex.h +++ b/librz/include/rz_regex.h @@ -1,21 +1,21 @@ #ifndef R2_REGEX_H #define R2_REGEX_H -#include +#include #include -typedef struct r_regex_t { +typedef struct rz_regex_t { int re_magic; size_t re_nsub; /* number of parenthesized subexpressions */ const char *re_endp; /* end pointer for R_REGEX_PEND */ struct re_guts *re_g; /* none of your business :-) */ int re_flags; -} RRegex; +} RzRegex; -typedef struct r_regmatch_t { +typedef struct rz_regmatch_t { off_t rm_so; /* start of match */ off_t rm_eo; /* end of match */ -} RRegexMatch; +} RzRegexMatch; /* regcomp() flags */ #define R_REGEX_BASIC 0000 @@ -57,19 +57,19 @@ typedef struct r_regmatch_t { #define R_REGEX_LARGE 01000 /* force large representation */ #define R_REGEX_BACKR 02000 /* force use of backref code */ -R_API RRegex *r_regex_new (const char *pattern, const char *cflags); -R_API int r_regex_run (const char *pattern, const char *flags, const char *text); -R_API int r_regex_match (const char *pattern, const char *flags, const char *text); -R_API int r_regex_flags(const char *flags); -R_API int r_regex_comp(RRegex*, const char *, int); -R_API size_t r_regex_error(int, const RRegex*, char *, size_t); +RZ_API RzRegex *rz_regex_new (const char *pattern, const char *cflags); +RZ_API int rz_regex_run (const char *pattern, const char *flags, const char *text); +RZ_API int rz_regex_match (const char *pattern, const char *flags, const char *text); +RZ_API int rz_regex_flags(const char *flags); +RZ_API int rz_regex_comp(RzRegex*, const char *, int); +RZ_API size_t rz_regex_error(int, const RzRegex*, char *, size_t); /* * gcc under c99 mode won't compile "[]" by itself. As a workaround, * a dummy argument name is added. */ -R_API bool r_regex_check(const RRegex *rr, const char *str); -R_API int r_regex_exec(const RRegex *, const char *, size_t, RRegexMatch __pmatch[], int); -R_API void r_regex_free(RRegex *); -R_API void r_regex_fini(RRegex *); +RZ_API bool rz_regex_check(const RzRegex *rr, const char *str); +RZ_API int rz_regex_exec(const RzRegex *, const char *, size_t, RzRegexMatch __pmatch[], int); +RZ_API void rz_regex_free(RzRegex *); +RZ_API void rz_regex_fini(RzRegex *); #endif /* !_REGEX_H_ */ diff --git a/librz/include/rz_search.h b/librz/include/rz_search.h new file mode 100644 index 0000000000..5d1f5b5a73 --- /dev/null +++ b/librz/include/rz_search.h @@ -0,0 +1,138 @@ +#ifndef R2_SEARCH_H +#define R2_SEARCH_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_search); + +enum { + R_SEARCH_ESIL, + R_SEARCH_KEYWORD, + R_SEARCH_REGEXP, + R_SEARCH_PATTERN, + R_SEARCH_STRING, + R_SEARCH_XREFS, + R_SEARCH_AES, + R_SEARCH_PRIV_KEY, + R_SEARCH_DELTAKEY, + R_SEARCH_MAGIC, + R_SEARCH_LAST +}; + +#define R_SEARCH_DISTANCE_MAX 10 + +#define R_SEARCH_KEYWORD_TYPE_BINARY 'i' +#define R_SEARCH_KEYWORD_TYPE_STRING 's' + +typedef struct rz_search_keyword_t { + ut8 *bin_keyword; + ut8 *bin_binmask; + ut32 keyword_length; + ut32 binmask_length; + void *data; + int count; + int kwidx; + int icase; // ignore case + int type; + ut64 last; // last hit hint +} RzSearchKeyword; + +typedef struct rz_search_hit_t { + RzSearchKeyword *kw; + ut64 addr; +} RzSearchHit; + +typedef int (*RzSearchCallback)(RzSearchKeyword *kw, void *user, ut64 where); + +typedef struct rz_search_t { + int n_kws; // hit${n_kws}_${count} + int mode; + ut32 pattern_size; + ut32 string_min; // max length of strings for R_SEARCH_STRING + ut32 string_max; // min length of strings for R_SEARCH_STRING + void *data; // data used by search algorithm + void *user; // user data passed to callback + RzSearchCallback callback; + ut64 nhits; + ut64 maxhits; // search.maxhits + RzList *hits; + int distance; + int inverse; + bool overlap; // whether two matches can overlap + int contiguous; + int align; + int (*update)(struct rz_search_t *s, ut64 from, const ut8 *buf, int len); + RzList *kws; // TODO: Use rz_search_kw_new () + RzIOBind iob; + char bckwrds; +} RzSearch; + +#ifdef RZ_API + +#define R_SEARCH_AES_BOX_SIZE 31 + +RZ_API RzSearch *rz_search_new(int mode); +RZ_API int rz_search_set_mode(RzSearch *s, int mode); +RZ_API RzSearch *rz_search_free(RzSearch *s); + +/* keyword management */ +RZ_API RzList *rz_search_find(RzSearch *s, ut64 addr, const ut8 *buf, int len); +RZ_API int rz_search_update(RzSearch *s, ut64 from, const ut8 *buf, long len); +RZ_API int rz_search_update_i(RzSearch *s, ut64 from, const ut8 *buf, long len); + +RZ_API void rz_search_keyword_free (RzSearchKeyword *kw); +RZ_API RzSearchKeyword* rz_search_keyword_new(const ut8 *kw, int kwlen, const ut8 *bm, int bmlen, const char *data); +RZ_API RzSearchKeyword* rz_search_keyword_new_str(const char *kw, const char *bm, const char *data, int icase); +RZ_API RzSearchKeyword* rz_search_keyword_new_wide(const char *kw, const char *bm, const char *data, int icase); +RZ_API RzSearchKeyword* rz_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data); +RZ_API RzSearchKeyword* rz_search_keyword_new_hexmask(const char *kwstr, const char *data); +RZ_API RzSearchKeyword *rz_search_keyword_new_regexp (const char *str, const char *data); + +RZ_API int rz_search_kw_add(RzSearch *s, RzSearchKeyword *kw); +RZ_API void rz_search_reset(RzSearch *s, int mode); +RZ_API void rz_search_kw_reset(RzSearch *s); +RZ_API void rz_search_string_prepare_backward(RzSearch *s); +RZ_API void rz_search_kw_reset(RzSearch *s); + +RZ_API int rz_search_range_add(RzSearch *s, ut64 from, ut64 to); +RZ_API int rz_search_range_set(RzSearch *s, ut64 from, ut64 to); +RZ_API int rz_search_range_reset(RzSearch *s); +RZ_API int rz_search_set_blocksize(RzSearch *s, ut32 bsize); + +RZ_API int rz_search_bmh(const RzSearchKeyword *kw, const ut64 from, const ut8 *buf, const int len, ut64 *out); + +// TODO: is this an internal API? +RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_aes_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_privkey_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_magic_update(RzSearch *_s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_strings_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_regexp_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +RZ_API int rz_search_xrefs_update(RzSearch *s, ut64 from, const ut8 *buf, int len); +// Returns 2 if search.maxhits is reached, 0 on error, otherwise 1 +RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr); +RZ_API void rz_search_set_distance(RzSearch *s, int dist); +RZ_API int rz_search_strings(RzSearch *s, ut32 min, ut32 max); +RZ_API int rz_search_set_string_limits(RzSearch *s, ut32 min, ut32 max); // WTF dupped? +//RZ_API int rz_search_set_callback(RzSearch *s, int (*callback)(struct rz_search_kw_t *, void *, ut64), void *user); +RZ_API void rz_search_set_callback(RzSearch *s, RzSearchCallback(callback), void *user); +RZ_API int rz_search_begin(RzSearch *s); + +/* pattern search */ +RZ_API void rz_search_pattern_size(RzSearch *s, int size); +RZ_API int rz_search_pattern(RzSearch *s, ut64 from, ut64 to); + +#ifdef __cplusplus +} +#endif + +#endif +#endif diff --git a/librz/include/rz_sign.h b/librz/include/rz_sign.h new file mode 100644 index 0000000000..2774edb22b --- /dev/null +++ b/librz/include/rz_sign.h @@ -0,0 +1,166 @@ +#ifndef R2_SIGN_H +#define R2_SIGN_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_sign); + +// XXX those limits should go away +#define R_SIGN_KEY_MAXSZ 1024 +#define R_SIGN_VAL_MAXSZ 10240 + +#define ZIGN_HASH "sha256" +#define R_ZIGN_HASH R_HASH_SHA256 + +typedef enum { + R_SIGN_BYTES = 'b', // bytes pattern + R_SIGN_BYTES_MASK= 'm', // bytes pattern + R_SIGN_BYTES_SIZE= 's', // bytes pattern + R_SIGN_ANAL = 'a', // bytes pattern (anal mask) // wtf ? + R_SIGN_COMMENT = 'c', // comment + R_SIGN_GRAPH = 'g', // graph metrics + R_SIGN_OFFSET = 'o', // addr + R_SIGN_NAME = 'n', // real name + R_SIGN_REFS = 'r', // references + R_SIGN_XREFS = 'x', // xrefs + R_SIGN_VARS = 'v', // variables + R_SIGN_TYPES = 't', // types + R_SIGN_BBHASH = 'h', // basic block hash +} RzSignType; + +typedef struct rz_sign_graph_t { + int cc; + int nbbs; + int edges; + int ebbs; + int bbsum; +} RzSignGraph; + +typedef struct rz_sign_bytes_t { + int size; + ut8 *bytes; + ut8 *mask; +} RzSignBytes; + +typedef struct rz_sign_hash_t { + char *bbhash; +} RzSignHash; + +typedef struct rz_sign_item_t { + char *name; + char *realname; + char *comment; + const RSpace *space; + + RzSignBytes *bytes; + RzSignGraph *graph; + ut64 addr; + RzList *refs; + RzList *xrefs; + RzList *vars; + RzList *types; + RzSignHash *hash; +} RzSignItem; + +typedef int (*RzSignForeachCallback)(RzSignItem *it, void *user); +typedef int (*RzSignSearchCallback)(RzSignItem *it, RzSearchKeyword *kw, ut64 addr, void *user); +typedef int (*RzSignGraphMatchCallback)(RzSignItem *it, RzAnalFunction *fcn, void *user); +typedef int (*RzSignOffsetMatchCallback)(RzSignItem *it, RzAnalFunction *fcn, void *user); +typedef int (*RzSignHashMatchCallback)(RzSignItem *it, RzAnalFunction *fcn, void *user); +typedef int (*RzSignRefsMatchCallback)(RzSignItem *it, RzAnalFunction *fcn, void *user); +typedef int (*RzSignVarsMatchCallback)(RzSignItem *it, RzAnalFunction *fcn, void *user); + +typedef struct rz_sign_search_t { + RzSearch *search; + RzList *items; + RzSignSearchCallback cb; + void *user; +} RzSignSearch; + +typedef struct rz_sign_options_t { + double bytes_diff_threshold; + double graph_diff_threshold; +} RzSignOptions; + +typedef struct { + double score; + double bscore; + double gscore; + RzSignItem *item; +} RzSignCloseMatch; + +#ifdef RZ_API +RZ_API bool rz_sign_add_bytes(RzAnal *a, const char *name, ut64 size, const ut8 *bytes, const ut8 *mask); +RZ_API bool rz_sign_add_anal(RzAnal *a, const char *name, ut64 size, const ut8 *bytes, ut64 at); +RZ_API bool rz_sign_add_graph(RzAnal *a, const char *name, RzSignGraph graph); +RZ_API bool rz_sign_addto_item(RzAnal *a, RzSignItem *it, RzAnalFunction *fcn, RzSignType type); +RZ_API bool rz_sign_add_addr(RzAnal *a, const char *name, ut64 addr); +RZ_API bool rz_sign_add_name(RzAnal *a, const char *name, const char *realname); +RZ_API bool rz_sign_add_comment(RzAnal *a, const char *name, const char *comment); +RZ_API bool rz_sign_add_refs(RzAnal *a, const char *name, RzList *refs); +RZ_API bool rz_sign_add_xrefs(RzAnal *a, const char *name, RzList *xrefs); +RZ_API bool rz_sign_add_vars(RzAnal *a, const char *name, RzList *vars); +RZ_API bool rz_sign_add_types(RzAnal *a, const char *name, RzList *vars); +RZ_API bool rz_sign_delete(RzAnal *a, const char *name); +RZ_API void rz_sign_list(RzAnal *a, int format); +RZ_API RzList *rz_sign_get_list(RzAnal *a); +RZ_API bool rz_sign_add_hash(RzAnal *a, const char *name, int type, const char *val, int len); +RZ_API bool rz_sign_add_bb_hash(RzAnal *a, RzAnalFunction *fcn, const char *name); +RZ_API char *rz_sign_calc_bbhash(RzAnal *a, RzAnalFunction *fcn); +RZ_API bool rz_sign_deserialize(RzAnal *a, RzSignItem *it, const char *k, const char *v); +RZ_API RzSignItem *rz_sign_get_item(RzAnal *a, const char *name); +RZ_API bool rz_sign_add_item(RzAnal *a, RzSignItem *it); + +RZ_API bool rz_sign_foreach(RzAnal *a, RzSignForeachCallback cb, void *user); + +RZ_API RzSignSearch *rz_sign_search_new(void); +RZ_API void rz_sign_search_free(RzSignSearch *ss); +RZ_API void rz_sign_search_init(RzAnal *a, RzSignSearch *ss, int minsz, RzSignSearchCallback cb, void *user); +RZ_API int rz_sign_search_update(RzAnal *a, RzSignSearch *ss, ut64 *at, const ut8 *buf, int len); +RZ_API bool rz_sign_match_graph(RzAnal *a, RzAnalFunction *fcn, int mincc, RzSignGraphMatchCallback cb, void *user); +RZ_API bool rz_sign_match_addr(RzAnal *a, RzAnalFunction *fcn, RzSignOffsetMatchCallback cb, void *user); +RZ_API bool rz_sign_match_hash(RzAnal *a, RzAnalFunction *fcn, RzSignHashMatchCallback cb, void *user); +RZ_API bool rz_sign_match_refs(RzAnal *a, RzAnalFunction *fcn, RzSignRefsMatchCallback cb, void *user); +RZ_API bool rz_sign_match_vars(RzAnal *a, RzAnalFunction *fcn, RzSignRefsMatchCallback cb, void *user); +RZ_API bool rz_sign_match_types(RzAnal *a, RzAnalFunction *fcn, RzSignRefsMatchCallback cb, void *user); + +RZ_API bool rz_sign_load(RzAnal *a, const char *file); +RZ_API bool rz_sign_load_gz(RzAnal *a, const char *filename); +RZ_API char *rz_sign_path(RzAnal *a, const char *file); +RZ_API bool rz_sign_save(RzAnal *a, const char *file); + +RZ_API RzSignItem *rz_sign_item_new(void); +RZ_API void rz_sign_item_free(RzSignItem *item); +RZ_API void rz_sign_graph_free(RzSignGraph *graph); +RZ_API void rz_sign_bytes_free(RzSignBytes *bytes); + +RZ_API RzList *rz_sign_fcn_refs(RzAnal *a, RzAnalFunction *fcn); +RZ_API RzList *rz_sign_fcn_xrefs(RzAnal *a, RzAnalFunction *fcn); +RZ_API RzList *rz_sign_fcn_vars(RzAnal *a, RzAnalFunction *fcn); +RZ_API RzList *rz_sign_fcn_types(RzAnal *a, RzAnalFunction *fcn); + +RZ_API int rz_sign_is_flirt(RBuffer *buf); +RZ_API void rz_sign_flirt_dump(const RzAnal *anal, const char *flirt_file); +RZ_API void rz_sign_flirt_scan(RzAnal *anal, const char *flirt_file); + +RZ_API RzList *rz_sign_find_closest_sig(RzAnal *a, RzSignItem *it, int count, double score_threshold); +RZ_API RzList *rz_sign_find_closest_fcn(RzAnal *a, RzSignItem *it, int count, double score_threshold); +RZ_API void rz_sign_close_match_free(RzSignCloseMatch *match); +RZ_API bool rz_sign_diff(RzAnal *a, RzSignOptions *options, const char *other_space_name); +RZ_API bool rz_sign_diff_by_name(RzAnal *a, RzSignOptions *options, const char *other_space_name, bool not_matching); + +RZ_API RzSignOptions *rz_sign_options_new(const char *bytes_thresh, const char *graph_thresh); +RZ_API void rz_sign_options_free(RzSignOptions *options); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_skiplist.h b/librz/include/rz_skiplist.h new file mode 100644 index 0000000000..c7596f7209 --- /dev/null +++ b/librz/include/rz_skiplist.h @@ -0,0 +1,57 @@ +// (c) 2016 Jeffrey Crowell +// BSD 3 Clause License +// rizin + +// Skiplists are a probabilistic datastructure than can be used as a k-v store +// with average case O(lg n) lookup time, and worst case O(n). + +// https://en.wikipedia.org/wiki/Skip_list + +#ifndef R2_SKIP_LIST_H +#define R2_SKIP_LIST_H + +#include + +typedef struct rz_skiplist_node_t { + void *data; // pointer to the value + struct rz_skiplist_node_t **forward; // forward pointer +} RzSkipListNode; + +typedef struct rz_skiplist_t { + RzSkipListNode *head; // list header + int list_level; // current level of the list. + int size; + RzListFree freefn; + RzListComparator compare; +} RzSkipList; + +RZ_API RzSkipList* rz_skiplist_new(RzListFree freefn, RzListComparator comparefn); +RZ_API void rz_skiplist_free(RzSkipList *list); +RZ_API void rz_skiplist_purge(RzSkipList *list); +RZ_API RzSkipListNode* rz_skiplist_insert(RzSkipList* list, void* data); +RZ_API bool rz_skiplist_delete(RzSkipList* list, void* data); +RZ_API bool rz_skiplist_delete_node(RzSkipList *list, RzSkipListNode *node); +RZ_API RzSkipListNode* rz_skiplist_find(RzSkipList* list, void* data); +RZ_API RzSkipListNode* rz_skiplist_find_geq(RzSkipList* list, void* data); +RZ_API RzSkipListNode* rz_skiplist_find_leq(RzSkipList* list, void* data); +RZ_API void rz_skiplist_join(RzSkipList *l1, RzSkipList *l2); +RZ_API void *rz_skiplist_get_first(RzSkipList *list); +RZ_API void *rz_skiplist_get_n(RzSkipList *list, int n); +RZ_API void* rz_skiplist_get_geq(RzSkipList* list, void* data); +RZ_API void* rz_skiplist_get_leq(RzSkipList* list, void* data); +RZ_API bool rz_skiplist_empty(RzSkipList *list); +RZ_API RzList *rz_skiplist_to_list(RzSkipList *list); + +#define rz_skiplist_islast(list, el) (el->forward[0] == list->head) + +#define rz_skiplist_length(list) (list->size) + +#define rz_skiplist_foreach(list, it, pos)\ + if (list)\ + for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1); it = it->forward[0]) + +#define rz_skiplist_foreach_safe(list, it, tmp, pos)\ + if (list)\ + for (it = list->head->forward[0]; it != list->head && ((pos = it->data) || 1) && ((tmp = it->forward[0]) || 1); it = tmp) + +#endif // R2_SKIP_LIST_H diff --git a/librz/include/rz_socket.h b/librz/include/rz_socket.h new file mode 100644 index 0000000000..a491b65b9a --- /dev/null +++ b/librz/include/rz_socket.h @@ -0,0 +1,288 @@ +#ifndef R2_SOCKET_H +#define R2_SOCKET_H + +#include "rz_types.h" +#include "rz_bind.h" +#include "rz_list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER (rz_socket); + +#if __UNIX__ +#include +#include +#include +#include +#include +#include +#include +#endif + +#if HAVE_LIB_SSL +#include +#include +#endif + +#if __UNIX__ +#include +#endif + +/* For the Mingw-W64 toolchain */ +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT 0 +#endif +#ifndef SD_BOTH +#define SD_RECEIVE 0 +#define SD_SEND 1 +#define SD_BOTH 2 +#endif + +#if _MSC_VER +#define R_INVALID_SOCKET INVALID_SOCKET +#else +#define R_INVALID_SOCKET -1 +#endif + +typedef struct { + int child; +#if __WINDOWS__ + HANDLE pipe; +#else + int input[2]; + int output[2]; +#endif + RzCoreBind coreb; +} R2Pipe; + +typedef struct rz_socket_t { +#ifdef _MSC_VER + SOCKET fd; +#else + int fd; +#endif + bool is_ssl; + int proto; + int local; // TODO: merge ssl with local -> flags/options + int port; + struct sockaddr_in sa; +#if HAVE_LIB_SSL + SSL_CTX *ctx; + SSL *sfd; + BIO *bio; +#endif +} RzSocket; + +typedef struct rz_socket_http_options { + RzList *authtokens; + bool accept_timeout; + int timeout; + bool httpauth; +} RzSocketHTTPOptions; + +#define R_SOCKET_PROTO_TCP IPPROTO_TCP +#define R_SOCKET_PROTO_UDP IPPROTO_UDP +#define R_SOCKET_PROTO_UNIX 0x1337 +#define R_SOCKET_PROTO_NONE 0 +#define R_SOCKET_PROTO_DEFAULT R_SOCKET_PROTO_TCP + +#ifdef RZ_API +RZ_API RzSocket *rz_socket_new_from_fd(int fd); +RZ_API RzSocket *rz_socket_new(bool is_ssl); +RZ_API bool rz_socket_spawn(RzSocket *s, const char *cmd, unsigned int timeout); +RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout); +RZ_API int rz_socket_connect_serial(RzSocket *sock, const char *path, int speed, int parity); +#define rz_socket_connect_tcp(a, b, c, d) rz_socket_connect (a, b, c, R_SOCKET_PROTO_TCP, d) +#define rz_socket_connect_udp(a, b, c, d) rz_socket_connect (a, b, c, R_SOCKET_PROTO_UDP, d) +#if __UNIX__ +#define rz_socket_connect_unix(a, b) rz_socket_connect (a, b, b, R_SOCKET_PROTO_UNIX, 0) +#else +#define rz_socket_connect_unix(a, b) (false) +#endif +RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile); +RZ_API int rz_socket_port_by_name(const char *name); +RZ_API int rz_socket_close_fd(RzSocket *s); +RZ_API int rz_socket_close(RzSocket *s); +RZ_API int rz_socket_free(RzSocket *s); +RZ_API RzSocket *rz_socket_accept(RzSocket *s); +RZ_API RzSocket *rz_socket_accept_timeout(RzSocket *s, unsigned int timeout); +RZ_API bool rz_socket_block_time(RzSocket *s, bool block, int sec, int usec); +RZ_API int rz_socket_flush(RzSocket *s); +RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs); +RZ_API char *rz_socket_to_string(RzSocket *s); +RZ_API int rz_socket_write(RzSocket *s, void *buf, int len); +RZ_API int rz_socket_puts(RzSocket *s, char *buf); +RZ_API void rz_socket_printf(RzSocket *s, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API int rz_socket_read(RzSocket *s, ut8 *read, int len); +RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len); +RZ_API int rz_socket_gets(RzSocket *s, char *buf, int size); +RZ_API ut8 *rz_socket_slurp(RzSocket *s, int *len); +RZ_API bool rz_socket_is_connected(RzSocket *); + +/* process */ +typedef struct rz_socket_proc_t { + int fd0[2]; + int fd1[2]; + int pid; +} RzSocketProc; + +RZ_API RzSocketProc *rz_socket_proc_open(char *const argv[]); +RZ_API int rz_socket_proc_close(RzSocketProc *sp); +RZ_API int rz_socket_proc_read(RzSocketProc *sp, unsigned char *buf, int len); +RZ_API int rz_socket_proc_gets(RzSocketProc *sp, char *buf, int size); +RZ_API int rz_socket_proc_write(RzSocketProc *sp, void *buf, int len); +RZ_API void rz_socket_proc_printf(RzSocketProc *sp, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API int rz_socket_proc_ready(RzSocketProc *sp, int secs, int usecs); + +/* HTTP */ +RZ_API char *rz_socket_http_get(const char *url, int *code, int *rlen); +RZ_API char *rz_socket_http_post(const char *url, const char *data, int *code, int *rlen); +RZ_API void rz_socket_http_server_set_breaked(bool *b); + +typedef struct rz_socket_http_request { + RzSocket *s; + char *path; + char *host; + char *agent; + char *method; + char *referer; + ut8 *data; + int data_length; + bool auth; +} RzSocketHTTPRequest; + +RZ_API RzSocketHTTPRequest *rz_socket_http_accept(RzSocket *s, RzSocketHTTPOptions *so); +RZ_API void rz_socket_http_response(RzSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers); +RZ_API void rz_socket_http_close(RzSocketHTTPRequest *rs); +RZ_API ut8 *rz_socket_http_handle_upload(const ut8 *str, int len, int *olen); + +typedef int (*rap_server_open)(void *user, const char *file, int flg, int mode); +typedef int (*rap_server_seek)(void *user, ut64 offset, int whence); +typedef int (*rap_server_read)(void *user, ut8 *buf, int len); +typedef int (*rap_server_write)(void *user, ut8 *buf, int len); +typedef char *(*rap_server_cmd)(void *user, const char *command); +typedef int (*rap_server_close)(void *user, int fd); + +enum { + RAP_PACKET_OPEN = 1, + RAP_PACKET_READ = 2, + RAP_PACKET_WRITE = 3, + RAP_PACKET_SEEK = 4, + RAP_PACKET_CLOSE = 5, + // system was deprecated in slot 6, + RAP_PACKET_CMD = 7, + RAP_PACKET_REPLY = 0x80, + RAP_PACKET_MAX = 4096 +}; + +typedef struct rz_socket_rap_server_t { + RzSocket *fd; + char *port; + ut8 buf[RAP_PACKET_MAX + 32]; // This should be used as a static buffer for everything done by the server + rap_server_open open; + rap_server_seek seek; + rap_server_read read; + rap_server_write write; + rap_server_cmd system; + rap_server_cmd cmd; + rap_server_close close; + void *user; // Always first arg for callbacks +} RzSocketRapServer; + +RZ_API RzSocketRapServer *rz_socket_rap_server_new(bool is_ssl, const char *port); +RZ_API RzSocketRapServer *rz_socket_rap_server_create(const char *pathname); +RZ_API void rz_socket_rap_server_free(RzSocketRapServer *rap_s); +RZ_API bool rz_socket_rap_server_listen(RzSocketRapServer *rap_s, const char *certfile); +RZ_API RzSocket *rz_socket_rap_server_accept(RzSocketRapServer *rap_s); +RZ_API bool rz_socket_rap_server_continue(RzSocketRapServer *rap_s); + +/* rap client */ +RZ_API int rz_socket_rap_client_open(RzSocket *s, const char *file, int rw); +RZ_API char *rz_socket_rap_client_command(RzSocket *s, const char *cmd, RzCoreBind *c); +RZ_API int rz_socket_rap_client_write(RzSocket *s, const ut8 *buf, int count); +RZ_API int rz_socket_rap_client_read(RzSocket *s, ut8 *buf, int count); +RZ_API int rz_socket_rap_client_seek(RzSocket *s, ut64 offset, int whence); + +/* run.c */ +#define R_RUN_PROFILE_NARGS 512 +typedef struct rz_run_profile_t { + char *_args[R_RUN_PROFILE_NARGS]; + int _argc; + bool _daemon; + char *_system; + char *_program; + char *_runlib; + char *_runlib_fcn; + char *_stdio; + char *_stdin; + char *_stdout; + char *_stderr; + char *_chgdir; + char *_chroot; + char *_libpath; + char *_preload; + int _bits; + int _pid; + char *_pidfile; + int _rzpreload; + int _docore; + int _dofork; + int _dodebug; + int _aslr; + int _maxstack; + int _maxproc; + int _maxfd; + int _rzsleep; + int _execve; + char *_setuid; + char *_seteuid; + char *_setgid; + char *_setegid; + char *_input; + char *_connect; + char *_listen; + int _pty; + int _timeout; + int _timeout_sig; + int _nice; +} RRunProfile; + +RZ_API RRunProfile *rz_run_new(const char *str); +RZ_API bool rz_run_parse(RRunProfile *pf, const char *profile); +RZ_API void rz_run_free(RRunProfile *r); +RZ_API bool rz_run_parseline(RRunProfile *p, const char *b); +RZ_API const char *rz_run_help(void); +RZ_API int rz_run_config_env(RRunProfile *p); +RZ_API int rz_run_start(RRunProfile *p); +RZ_API void rz_run_reset(RRunProfile *p); +RZ_API bool rz_run_parsefile(RRunProfile *p, const char *b); +RZ_API char *rz_run_get_environ_profile(char **env); + +/* rapipe */ +RZ_API R2Pipe *rap_open(const char *cmd); +RZ_API R2Pipe *rap_open_corebind(RzCoreBind *coreb); +RZ_API int rap_close(R2Pipe *rap); + +RZ_API char *rap_cmd(R2Pipe *rap, const char *str); +RZ_API char *rap_cmdf(R2Pipe *rap, const char *fmt, ...) R_PRINTF_CHECK(2, 3); + +RZ_API int rap_write(R2Pipe *rap, const char *str); +RZ_API char *rap_read(R2Pipe *rap); + +RZ_API int rzpipe_write(R2Pipe *rzpipe, const char *str); +RZ_API char *rzpipe_read(R2Pipe *rzpipe); +RZ_API int rzpipe_close(R2Pipe *rzpipe); +RZ_API R2Pipe *rzpipe_open_corebind(RzCoreBind *coreb); +RZ_API R2Pipe *rzpipe_open(const char *cmd); +RZ_API R2Pipe *rzpipe_open_dl(const char *file); +RZ_API char *rzpipe_cmd(R2Pipe *rzpipe, const char *str); +RZ_API char *rzpipe_cmdf(R2Pipe *rzpipe, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_syscall.h b/librz/include/rz_syscall.h new file mode 100644 index 0000000000..f1901d8332 --- /dev/null +++ b/librz/include/rz_syscall.h @@ -0,0 +1,108 @@ +/* radare - LGPL - Copyright 2009-2018 - pancake */ + +#ifndef R2_SYSCALL_H +#define R2_SYSCALL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +R_LIB_VERSION_HEADER (rz_syscall); + +#define R_SYSCALL_ARGS 7 + +typedef struct rz_syscall_item_t { + char *name; + int swi; + int num; + int args; + char *sargs; +} RzSyscallItem; + +typedef struct rz_syscall_port_t { + int port; + const char *name; +} RzSyscallPort; + +typedef struct rz_syscall_t { + FILE *fd; + // memoization + char *arch; + char *os; + int bits; + char *cpu; + // database + RzSyscallItem *sysptr; + RzSyscallPort *sysport; + Sdb *db; + Sdb *srdb; + int refs; +} RzSyscall; + +#if 0 +// todo: add the ability to describe particular bits +typedef struct rz_sysregs_item_t { + ut64 address; + ut64 size; + int type; + const char *name; + const char *description; +} RSysregsItem; + +typedef struct rz_sysregs_t { + FILE *fd; + char *arch; + char *cpu; + RSysregsItem *sysregs; + Sdb *db; +} RSysregs; +#endif + +/* plugin struct */ +typedef struct rz_syscall_plugin_t { + char *name; + char *arch; + char *os; + char *desc; + int bits; + int nargs; + struct rz_syscall_args_t *args; +} RzSyscallPlugin; + +typedef struct rz_syscall_arch_plugin_t { + char *name; + char *arch; + char *desc; + int *bits; + int nargs; + struct rz_syscall_args_t **args; +} RzSyscallArchPlugin; + +#ifdef RZ_API +RZ_API RzSyscallItem *rz_syscall_item_new_from_string(const char *name, const char *s); +RZ_API void rz_syscall_item_free(RzSyscallItem *si); + +RZ_API RzSyscall *rz_syscall_new(void); +RZ_API void rz_syscall_free(RzSyscall *ctx); +RZ_API RzSyscall* rz_syscall_ref(RzSyscall *sc); +RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os); +RZ_API RzSyscallItem *rz_syscall_get(RzSyscall *ctx, int num, int swi); +RZ_API int rz_syscall_get_num(RzSyscall *ctx, const char *str); +RZ_API const char *rz_syscall_get_i(RzSyscall *ctx, int num, int swi); +RZ_API const char* rz_syscall_sysreg(RzSyscall *s, const char *type, ut64 num); +RZ_API RzList *rz_syscall_list(RzSyscall *ctx); +RZ_API int rz_syscall_get_swi(RzSyscall *s); + +/* io */ +RZ_API const char *rz_syscall_get_io(RzSyscall *s, int ioport); +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_th.h b/librz/include/rz_th.h new file mode 100644 index 0000000000..61a15b3a78 --- /dev/null +++ b/librz/include/rz_th.h @@ -0,0 +1,124 @@ +#ifndef R2_TH_H +#define R2_TH_H + +#ifdef _GNU_SOURCE +#undef _GNU_SOURCE +#endif +#define _GNU_SOURCE +#include "rz_types.h" + +#define HAVE_PTHREAD 1 + +#if __WINDOWS__ +#undef HAVE_PTHREAD +#define HAVE_PTHREAD 0 +#define R_TH_TID HANDLE +#define R_TH_LOCK_T CRITICAL_SECTION +#define R_TH_COND_T CONDITION_VARIABLE +#define R_TH_SEM_T HANDLE +//HANDLE + +#elif HAVE_PTHREAD +#define __GNU +#include +#include +#if __linux__ +#include +#endif +#if __linux__ && __GLIBC_MINOR < 12 +#define HAVE_PTHREAD_NP 0 +#else +#define HAVE_PTHREAD_NP 1 +#endif +#if __APPLE__ +#include +#endif +#if __FreeBSD__ || __OpenBSD__ || __DragonFly__ +#if __FreeBSD__ +#include +#endif +#include +#endif +#define R_TH_TID pthread_t +#define R_TH_LOCK_T pthread_mutex_t +#define R_TH_COND_T pthread_cond_t +#define R_TH_SEM_T sem_t * + +#else +#error Threading library only supported for pthread and w32 +#endif + +typedef enum { R_TH_FREED = -1, R_TH_STOP = 0, R_TH_REPEAT = 1 } RzThreadFunctionRet; +#define R_TH_FUNCTION(x) RzThreadFunctionRet (*x)(struct rz_th_t *) + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_th_sem_t { + R_TH_SEM_T sem; +} RzThreadSemaphore; + +typedef struct rz_th_lock_t { + R_TH_LOCK_T lock; +} RzThreadLock; + +typedef struct rz_th_cond_t { + R_TH_COND_T cond; +} RzThreadCond; + +typedef struct rz_th_t { + R_TH_TID tid; + RzThreadLock *lock; + R_TH_FUNCTION(fun); + void *user; // user pointer + int running; + int breaked; // thread aims to be interrupted + int delay; // delay the startup of the thread N seconds + int ready; // thread is properly setup +} RzThread; + +typedef struct rz_th_pool_t { + int size; + RzThread **threads; +} RzThreadPool; + +#ifdef RZ_API +RZ_API RzThread *rz_th_new(R_TH_FUNCTION(fun), void *user, int delay); +RZ_API bool rz_th_start(RzThread *th, int enable); +RZ_API int rz_th_wait(RzThread *th); +RZ_API int rz_th_wait_async(RzThread *th); +RZ_API void rz_th_break(RzThread *th); +RZ_API void *rz_th_free(RzThread *th); +RZ_API void *rz_th_kill_free(RzThread *th); +RZ_API bool rz_th_kill(RzThread *th, bool force); +RZ_API R_TH_TID rz_th_self(void); +RZ_API bool rz_th_setname(RzThread *th, const char *name); +RZ_API bool rz_th_getname(RzThread *th, char *name, size_t len); +RZ_API bool rz_th_setaffinity(RzThread *th, int cpuid); + +RZ_API RzThreadSemaphore *rz_th_sem_new(unsigned int initial); +RZ_API void rz_th_sem_free(RzThreadSemaphore *sem); +RZ_API void rz_th_sem_post(RzThreadSemaphore *sem); +RZ_API void rz_th_sem_wait(RzThreadSemaphore *sem); + +RZ_API RzThreadLock *rz_th_lock_new(bool recursive); +RZ_API int rz_th_lock_wait(RzThreadLock *th); +RZ_API int rz_th_lock_tryenter(RzThreadLock *thl); +RZ_API int rz_th_lock_enter(RzThreadLock *thl); +RZ_API int rz_th_lock_leave(RzThreadLock *thl); +RZ_API void *rz_th_lock_free(RzThreadLock *thl); + +RZ_API RzThreadCond *rz_th_cond_new(void); +RZ_API void rz_th_cond_signal(RzThreadCond *cond); +RZ_API void rz_th_cond_signal_all(RzThreadCond *cond); +RZ_API void rz_th_cond_wait(RzThreadCond *cond, RzThreadLock *lock); +RZ_API void rz_th_cond_free(RzThreadCond *cond); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_types.h b/librz/include/rz_types.h similarity index 88% rename from libr/include/r_types.h rename to librz/include/rz_types.h index b8e28ccb40..2f6de237ea 100644 --- a/libr/include/r_types.h +++ b/librz/include/rz_types.h @@ -5,8 +5,8 @@ #define _FILE_OFFSET_BITS 64 // defines like IS_DIGIT, etc' -#include "r_util/r_str_util.h" -#include +#include "rz_util/rz_str_util.h" +#include #include #include @@ -217,7 +217,7 @@ #define R_PRINTF_CHECK(fmt, dots) #endif -#include +#include #undef _FILE_OFFSET_BITS #define _FILE_OFFSET_BITS 64 @@ -229,7 +229,7 @@ #include #include #include /* for O_RDONLY */ -#include /* needs size_t */ +#include /* needs size_t */ #ifdef __cplusplus extern "C" { @@ -281,27 +281,27 @@ typedef int (*PrintfCallback)(const char *str, ...); #endif #define R_HEAP -#ifdef R_API -#undef R_API +#ifdef RZ_API +#undef RZ_API #endif #if R_SWIG - #define R_API export + #define RZ_API export #elif R_INLINE - #define R_API inline + #define RZ_API inline #else #if defined(__GNUC__) && __GNUC__ >= 4 - #define R_API __attribute__((visibility("default"))) + #define RZ_API __attribute__((visibility("default"))) #elif defined(_MSC_VER) - #define R_API __declspec(dllexport) + #define RZ_API __declspec(dllexport) #else - #define R_API + #define RZ_API #endif #endif #define R_LIB_VERSION_HEADER(x) \ -R_API const char *x##_version(void) +RZ_API const char *x##_version(void) #define R_LIB_VERSION(x) \ -R_API const char *x##_version(void) { return "" R2_GITTAP; } +RZ_API const char *x##_version(void) { return "" R2_GITTAP; } #define BITS2BYTES(x) (((x)/8)+(((x)%8)?1:0)) #define ZERO_FILL(x) memset (&x, 0, sizeof (x)) @@ -309,9 +309,9 @@ R_API const char *x##_version(void) { return "" R2_GITTAP; } #define R_NEWS(x,y) (x*)malloc(sizeof(x)*(y)) #define R_NEW0(x) (x*)calloc(1,sizeof(x)) #define R_NEW(x) (x*)malloc(sizeof(x)) -#define R_NEWCOPY(x,y) (x*)r_new_copy(sizeof(x), y) +#define R_NEWCOPY(x,y) (x*)rz_new_copy(sizeof(x), y) -static inline void *r_new_copy(int size, void *data) { +static inline void *rz_new_copy(int size, void *data) { void *a = malloc(size); if (a) { memcpy (a, data, size); @@ -352,12 +352,12 @@ static inline void *r_new_copy(int size, void *data) { { \ char buf[256]; \ snprintf(buf,sizeof(buf),"[%s:%d %s] %s",file,line,func,str); \ - r_sys_perror_str(buf); \ + rz_sys_perror_str(buf); \ } #define perror(x) _perror(x,__FILE__,__LINE__,__func__) -#define r_sys_perror(x) _perror(x,__FILE__,__LINE__,__func__) +#define rz_sys_perror(x) _perror(x,__FILE__,__LINE__,__func__) #else -#define r_sys_perror(x) r_sys_perror_str(x); +#define rz_sys_perror(x) rz_sys_perror_str(x); #endif #if __UNIX__ @@ -384,12 +384,12 @@ static inline void *r_new_copy(int size, void *data) { #endif #if 1 -#define r_offsetof(type, member) offsetof(type, member) +#define rz_offsetof(type, member) offsetof(type, member) #else #if __SDB_WINDOWS__ -#define r_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member) +#define rz_offsetof(type, member) ((unsigned long) (ut64)&((type*)0)->member) #else -#define r_offsetof(type, member) ((unsigned long) &((type*)0)->member) +#define rz_offsetof(type, member) ((unsigned long) &((type*)0)->member) #endif #endif @@ -608,51 +608,51 @@ enum { } #endif -static inline void r_run_call1(void *fcn, void *arg1) { +static inline void rz_run_call1(void *fcn, void *arg1) { ((void (*)(void *))(fcn))(arg1); } -static inline void r_run_call2(void *fcn, void *arg1, void *arg2) { +static inline void rz_run_call2(void *fcn, void *arg1, void *arg2) { ((void (*)(void *, void *))(fcn))(arg1, arg2); } -static inline void r_run_call3(void *fcn, void *arg1, void *arg2, void *arg3) { +static inline void rz_run_call3(void *fcn, void *arg1, void *arg2, void *arg3) { ((void (*)(void *, void *, void *))(fcn))(arg1, arg2, arg3); } -static inline void r_run_call4(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4) { +static inline void rz_run_call4(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4) { ((void (*)(void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4); } -static inline void r_run_call5(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5) { +static inline void rz_run_call5(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5) { ((void (*)(void *, void *, void *, void *, void *))(fcn))(arg1, arg2, arg3, arg4, arg5); } -static inline void r_run_call6(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, +static inline void rz_run_call6(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6) { ((void (*)(void *, void *, void *, void *, void *, void *))(fcn)) (arg1, arg2, arg3, arg4, arg5, arg6); } -static inline void r_run_call7(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, +static inline void rz_run_call7(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7) { ((void (*)(void *, void *, void *, void *, void *, void *, void *))(fcn)) (arg1, arg2, arg3, arg4, arg5, arg6, arg7); } -static inline void r_run_call8(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, +static inline void rz_run_call8(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8) { ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *))(fcn)) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); } -static inline void r_run_call9(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, +static inline void rz_run_call9(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9) { ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *, void *))(fcn)) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9); } -static inline void r_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, +static inline void rz_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7, void *arg8, void *arg9, void *arg10) { ((void (*)(void *, void *, void *, void *, void *, void *, void *, void *, void *, void *))(fcn)) (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); @@ -670,13 +670,13 @@ static inline void r_run_call10(void *fcn, void *arg1, void *arg2, void *arg3, v typedef int RRef; #define R_REF_NAME refcount -#define r_ref(x) x->R_REF_NAME++; -#define r_ref_init(x) x->R_REF_NAME = 1 -#define r_unref(x,f) { assert (x->R_REF_NAME> 0); if (!--(x->R_REF_NAME)) { f(x); } } +#define rz_ref(x) x->R_REF_NAME++; +#define rz_ref_init(x) x->R_REF_NAME = 1 +#define rz_unref(x,f) { assert (x->R_REF_NAME> 0); if (!--(x->R_REF_NAME)) { f(x); } } #define R_REF_TYPE RRef R_REF_NAME #define R_REF_FUNCTIONS(s, n) \ static inline void n##_ref(s *x) { x->R_REF_NAME++; } \ -static inline void n##_unref(s *x) { r_unref (x, n##_free); } +static inline void n##_unref(s *x) { rz_unref (x, n##_free); } #endif // R2_TYPES_H diff --git a/libr/include/r_types_base.h b/librz/include/rz_types_base.h similarity index 99% rename from libr/include/r_types_base.h rename to librz/include/rz_types_base.h index d4a128dfcf..4cb610208c 100644 --- a/libr/include/r_types_base.h +++ b/librz/include/rz_types_base.h @@ -131,7 +131,7 @@ typedef struct _utX { #define R_ABS(x) (((x)<0)?-(x):(x)) #define R_BTW(x,y,z) (((x)>=(y))&&((y)<=(z)))?y:x -#include "r_types_overflow.h" +#include "rz_types_overflow.h" /* copied from bithacks.h */ #define B_IS_SET(x, n) (((x) & (1ULL << (n)))? 1: 0) diff --git a/libr/include/r_types_overflow.h b/librz/include/rz_types_overflow.h similarity index 100% rename from libr/include/r_types_overflow.h rename to librz/include/rz_types_overflow.h diff --git a/libr/include/r_userconf.h.acr b/librz/include/rz_userconf.h.acr similarity index 73% rename from libr/include/r_userconf.h.acr rename to librz/include/rz_userconf.h.acr index 9e8826f80b..75ec91d000 100644 --- a/libr/include/r_userconf.h.acr +++ b/librz/include/rz_userconf.h.acr @@ -1,7 +1,7 @@ #ifndef R2_CONFIGURE_H #define R2_CONFIGURE_H -#include "r_version.h" +#include "rz_version.h" #define R_CHECKS_LEVEL @R_CHECKS_LEVEL@ #define DEBUGGER @DEBUGGER@ @@ -32,7 +32,7 @@ #if __WINDOWS__ || _MSC_VER #define R2_PREFIX "." #define R2_LIBDIR "lib" -#define R2_INCDIR "include\\libr" +#define R2_INCDIR "include\\librz" #define R2_DATDIR "share" #define R2_WWWROOT "www" #define R2_PLUGINS "lib\\plugins" @@ -41,20 +41,20 @@ #else #define R2_PREFIX "@PREFIX@" #define R2_LIBDIR "@LIBDIR@" -#define R2_INCDIR "@INCLUDEDIR@/libr" +#define R2_INCDIR "@INCLUDEDIR@/librz" #define R2_DATDIR "@DATADIR@" -#define R2_WWWROOT R2_DATDIR "/radare2/" R2_VERSION "/www" -#define R2_PLUGINS "lib/radare2/" R2_VERSION -#define R2_EXTRAS "lib/radare2-extras/" R2_VERSION -#define R2_BINDINGS "lib/radare2-bindings/" R2_VERSION +#define R2_WWWROOT R2_DATDIR "/rizin/" R2_VERSION "/www" +#define R2_PLUGINS "lib/rizin/" R2_VERSION +#define R2_EXTRAS "lib/rizin-extras/" R2_VERSION +#define R2_BINDINGS "lib/rizin-bindings/" R2_VERSION #endif -#define R2_DATDIR_R2 R_JOIN_2_PATHS ("share", "radare2") -#define R2_SDB R_JOIN_3_PATHS ("share", "radare2", R2_VERSION) -#define R2_ZIGNS R_JOIN_4_PATHS ("share", "radare2", R2_VERSION, "zigns") -#define R2_THEMES R_JOIN_4_PATHS ("share", "radare2", R2_VERSION, "cons") -#define R2_FLAGS R_JOIN_4_PATHS ("share", "radare2", R2_VERSION, "flag") -#define R2_FORTUNES R_JOIN_3_PATHS ("share", "doc", "radare2") -#define R2_HUD R_JOIN_4_PATHS ("share", "radare2", R2_VERSION, "hud") +#define R2_DATDIR_R2 R_JOIN_2_PATHS ("share", "rizin") +#define R2_SDB R_JOIN_3_PATHS ("share", "rizin", R2_VERSION) +#define R2_ZIGNS R_JOIN_4_PATHS ("share", "rizin", R2_VERSION, "zigns") +#define R2_THEMES R_JOIN_4_PATHS ("share", "rizin", R2_VERSION, "cons") +#define R2_FLAGS R_JOIN_4_PATHS ("share", "rizin", R2_VERSION, "flag") +#define R2_FORTUNES R_JOIN_3_PATHS ("share", "doc", "rizin") +#define R2_HUD R_JOIN_4_PATHS ("share", "rizin", R2_VERSION, "hud") #endif #define R2_SDB_FCNSIGN R_JOIN_2_PATHS (R2_SDB, "fcnsign") @@ -62,9 +62,9 @@ #define R2_SDB_MAGIC R_JOIN_2_PATHS (R2_SDB, "magic") #define R2_SDB_FORMAT R_JOIN_2_PATHS (R2_SDB, "format") -#define R2_HOME_CONFIGDIR R_JOIN_2_PATHS (".config", "radare2") -#define R2_HOME_DATADIR R_JOIN_3_PATHS (".local", "share", "radare2") -#define R2_HOME_CACHEDIR R_JOIN_2_PATHS (".cache", "radare2") +#define R2_HOME_CONFIGDIR R_JOIN_2_PATHS (".config", "rizin") +#define R2_HOME_DATADIR R_JOIN_3_PATHS (".local", "share", "rizin") +#define R2_HOME_CACHEDIR R_JOIN_2_PATHS (".cache", "rizin") #define R2_HOME_THEMES R_JOIN_2_PATHS (R2_HOME_DATADIR, "cons") #define R2_HOME_PLUGINS R_JOIN_2_PATHS (R2_HOME_DATADIR, "plugins") @@ -80,9 +80,9 @@ #define R2_HOME_HISTORY R_JOIN_2_PATHS (R2_HOME_CACHEDIR, "history") -#define R2_HOME_RC R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "radare2rc") -#define R2_HOME_RC_DIR R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "radare2rc.d") -#define R2_GLOBAL_RC R_JOIN_2_PATHS (R2_DATDIR_R2, "radare2rc") +#define R2_HOME_RC R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "rizinrc") +#define R2_HOME_RC_DIR R_JOIN_2_PATHS (R2_HOME_CONFIGDIR, "rizinrc.d") +#define R2_GLOBAL_RC R_JOIN_2_PATHS (R2_DATDIR_R2, "rizinrc") #define HAVE_LIB_MAGIC @HAVE_LIB_MAGIC@ #define USE_LIB_MAGIC @USE_LIB_MAGIC@ diff --git a/librz/include/rz_util.h b/librz/include/rz_util.h new file mode 100644 index 0000000000..ca0e507cce --- /dev/null +++ b/librz/include/rz_util.h @@ -0,0 +1,92 @@ +/* radare - LGPL - Copyright 2008-2016 - pancake */ + +#ifndef R2_UTIL_H +#define R2_UTIL_H + +#include +#include +#include +#include +#include // radare linked list +#include // skiplist +#include // radare fixed pointer array iterators +#include +#include +#if !__WINDOWS__ +#include +#include +#endif +#ifdef HAVE_LIB_GMP +#include +#endif +#if HAVE_LIB_SSL +#include +#endif +#ifdef _MSC_VER +#include +int gettimeofday (struct timeval* p, void* tz); +#endif +#include "rz_util/rz_event.h" +#include "rz_util/rz_assert.h" +#include "rz_util/rz_itv.h" +#include "rz_util/rz_signal.h" +#include "rz_util/rz_alloc.h" +#include "rz_util/rz_rbtree.h" +#include "rz_util/rz_intervaltree.h" +#include "rz_util/rz_big.h" +#include "rz_util/rz_base64.h" +#include "rz_util/rz_base91.h" +#include "rz_util/rz_buf.h" +#include "rz_util/rz_bitmap.h" +#include "rz_util/rz_time.h" +#include "rz_util/rz_debruijn.h" +#include "rz_util/rz_cache.h" +#include "rz_util/rz_ctypes.h" +#include "rz_util/rz_file.h" +#include "rz_util/rz_hex.h" +#include "rz_util/rz_log.h" +#include "rz_util/rz_mem.h" +#include "rz_util/rz_name.h" +#include "rz_util/rz_num.h" +#include "rz_util/rz_table.h" +#include "rz_util/rz_graph.h" +#include "rz_util/rz_panels.h" +#include "rz_util/rz_pool.h" +#include "rz_util/rz_punycode.h" +#include "rz_util/rz_queue.h" +#include "rz_util/rz_range.h" +#include "rz_util/rz_sandbox.h" +#include "rz_util/rz_signal.h" +#include "rz_util/rz_spaces.h" +#include "rz_util/rz_stack.h" +#include "rz_util/rz_str.h" +#include "rz_util/rz_ascii_table.h" +#include "rz_util/rz_strbuf.h" +#include "rz_util/rz_strpool.h" +#include "rz_util/rz_str_constpool.h" +#include "rz_util/rz_sys.h" +#include "rz_util/rz_tree.h" +#include "rz_util/rz_uleb128.h" +#include "rz_util/rz_utf8.h" +#include "rz_util/rz_utf16.h" +#include "rz_util/rz_utf32.h" +#include "rz_util/rz_idpool.h" +#include "rz_util/rz_asn1.h" +#include "rz_util/pj.h" +#include "rz_util/rz_x509.h" +#include "rz_util/rz_pkcs7.h" +#include "rz_util/rz_protobuf.h" +#include "rz_util/rz_big.h" +// requires io, core, ... #include "rz_util/rz_print.h" + +#ifdef __cplusplus +extern "C" { +#endif + +R_LIB_VERSION_HEADER(rz_util); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_util/pj.h b/librz/include/rz_util/pj.h new file mode 100644 index 0000000000..7ce96068dd --- /dev/null +++ b/librz/include/rz_util/pj.h @@ -0,0 +1,63 @@ +#ifndef R_PJ_H +#define R_PJ_H 1 +#define R_PRINT_JSON_DEPTH_LIMIT 128 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct pj_t { + RStrBuf sb; + bool is_first; + bool is_key; + char braces[R_PRINT_JSON_DEPTH_LIMIT]; + int level; +} PJ; + +/* lifecycle */ +RZ_API PJ *pj_new(void); +RZ_API void pj_free(PJ *j); +RZ_API void pj_reset(PJ *j); // clear the pj contents, but keep the buffer allocated to re-use it +RZ_API char *pj_drain(PJ *j); +RZ_API const char *pj_string(PJ *pj); +// RZ_API void pj_print(PJ *j, PrintfCallback cb); + +/* nesting */ +//RZ_API PJ *pj_begin(char type, PrintfCallback cb); +RZ_API PJ *pj_end(PJ *j); +RZ_API char *pj_fmt(PrintfCallback p, const char *fmt, ...); +/* object, array */ +RZ_API PJ *pj_o(PJ *j); +RZ_API PJ *pj_a(PJ *j); +/* keys, values */ +RZ_API PJ *pj_k(PJ *j, const char *k); +RZ_API PJ *pj_knull(PJ *j, const char *k); +RZ_API PJ *pj_kn(PJ *j, const char *k, ut64 n); +RZ_API PJ *pj_kN(PJ *j, const char *k, st64 n); +RZ_API PJ *pj_ks(PJ *j, const char *k, const char *v); +RZ_API PJ *pj_ka(PJ *j, const char *k); +RZ_API PJ *pj_ko(PJ *j, const char *k); +RZ_API PJ *pj_ki(PJ *j, const char *k, int d); +RZ_API PJ *pj_kd(PJ *j, const char *k, double d); +RZ_API PJ *pj_kf(PJ *j, const char *k, float d); +RZ_API PJ *pj_kb(PJ *j, const char *k, bool v); +RZ_API PJ *pj_null(PJ *j); +RZ_API PJ *pj_r(PJ *j, const unsigned char *v, size_t v_len); +RZ_API PJ *pj_kr(PJ *j, const char *k, const unsigned char *v, size_t v_len); +RZ_API PJ *pj_b(PJ *j, bool v); +RZ_API PJ *pj_s(PJ *j, const char *k); +RZ_API PJ *pj_n(PJ *j, ut64 n); +RZ_API PJ *pj_N(PJ *j, st64 n); +RZ_API PJ *pj_d(PJ *j, double d); +RZ_API PJ *pj_f(PJ *j, float d); +RZ_API PJ *pj_i(PJ *j, int d); +RZ_API PJ *pj_j(PJ *j, const char *k); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/librz/include/rz_util/rz_alloc.h b/librz/include/rz_util/rz_alloc.h new file mode 100644 index 0000000000..178cf997ba --- /dev/null +++ b/librz/include/rz_util/rz_alloc.h @@ -0,0 +1,53 @@ +#ifndef _R_UTIL_ALLOC_H_ +#define _R_UTIL_ALLOC_H_ 1 + +#include +#include +#include + +#define R_MALLOC_WRAPPER 0 +#define R_MALLOC_GLOBAL 0 + +typedef void *(RMalloc)(size_t); +typedef void *(RCalloc)(size_t, size_t); +typedef void *(RRealloc)(void *, size_t); +typedef void (RFree)(void *); + +RZ_API void* rz_malloc_aligned(size_t size, size_t alignment); +RZ_API void rz_free_aligned(void *p); + +#if R_MALLOC_WRAPPER + +RZ_API void rz_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f); + +#if R_MALLOC_GLOBAL +RZ_API RMalloc *rz_malloc; +RZ_API RCalloc *rz_calloc; +RZ_API RRealloc *rz_realloc; +RZ_API RFree *rz_free; +#define _r_malloc rz_malloc +#define _r_calloc rz_calloc +#define _r_free rz_free +#define _r_realloc rz_realloc +#else +RZ_API void *rz_malloc(size_t sz); +RZ_API void *rz_calloc(size_t count, size_t sz); +RZ_API void *rz_realloc(void *p, size_t sz); +RZ_API void rz_free(void *p); +#endif + +#else + +#define rz_malloc(x) malloc((x)) +#define rz_calloc(x,y) calloc((x),(y)) +#define rz_realloc(x,y) realloc((x),(y)) +#define rz_free(x) free((x)) + +#define _r_malloc rz_malloc +#define _r_calloc rz_calloc +#define _r_free rz_free +#define _r_realloc rz_realloc + +#endif + +#endif diff --git a/libr/include/r_util/r_annotated_code.h b/librz/include/rz_util/rz_annotated_code.h similarity index 81% rename from libr/include/r_util/r_annotated_code.h rename to librz/include/rz_util/rz_annotated_code.h index e234ec44ff..00ccd9d690 100644 --- a/libr/include/r_util/r_annotated_code.h +++ b/librz/include/rz_util/rz_annotated_code.h @@ -2,15 +2,15 @@ #ifndef R_ANNOTATEDCODE_H #define R_ANNOTATEDCODE_H -// #include -#include -#include +// #include +#include +#include #ifdef __cplusplus extern "C" { #endif -typedef enum r_syntax_highlight_type_t { +typedef enum rz_syntax_highlight_type_t { R_SYNTAX_HIGHLIGHT_TYPE_KEYWORD, R_SYNTAX_HIGHLIGHT_TYPE_COMMENT, R_SYNTAX_HIGHLIGHT_TYPE_DATATYPE, @@ -22,7 +22,7 @@ typedef enum r_syntax_highlight_type_t { } RSyntaxHighlightType; /** Represents the type of annnotation. */ -typedef enum r_code_annotation_type_t { +typedef enum rz_code_annotation_type_t { R_CODE_ANNOTATION_TYPE_OFFSET, /*!< Gives the offset of the specified range in annotation. */ R_CODE_ANNOTATION_TYPE_SYNTAX_HIGHLIGHT, /*!< Represents the kind of data the specified range represents for highlighting purposes. */ R_CODE_ANNOTATION_TYPE_FUNCTION_NAME, /*!< Specified range in annotation represents a function name. */ @@ -36,7 +36,7 @@ typedef enum r_code_annotation_type_t { /** * \brief Annotations for the decompiled code are represented using this structure. */ -typedef struct r_code_annotation_t { +typedef struct rz_code_annotation_t { size_t start; /**< Start of the range in the annotation(inclusive). */ size_t end; /**< End of the range in the annotation(exclusive). */ RCodeAnnotationType type; @@ -76,9 +76,9 @@ typedef struct r_code_annotation_t { /** * \brief This structure contains the decompiled code and all the annotations for the decompiled code. */ -typedef struct r_annotated_code_t { +typedef struct rz_annotated_code_t { char *code; /**< Decompiled code. RAnnotatedCode owns this string and it must free it. */ - RVector annotations; /**< @ref RVector contains the list of annotations for the decompiled code. */ + RzVector annotations; /**< @ref RzVector contains the list of annotations for the decompiled code. */ } RAnnotatedCode; /** @@ -87,18 +87,18 @@ typedef struct r_annotated_code_t { * This function creates and initializes a new RAnnotatedCode * structure with the specified decompiled code that's passed * as an argument. Here, the argument code must be a string that can be deallocated. - * This will initialize @ref RVector annotations as well. + * This will initialize @ref RzVector annotations as well. * * @param code A deallocatable character array. * @return Pointer to the new RAnnotatedCode structure created. */ -R_API RAnnotatedCode *r_annotated_code_new(char *code); +RZ_API RAnnotatedCode *rz_annotated_code_new(char *code); /** * @brief Deallocates the dynamically allocated memory for the specified RAnnotatedCode. * * @param code Pointer to a RAnnotatedCode. */ -R_API void r_annotated_code_free(RAnnotatedCode *code); +RZ_API void rz_annotated_code_free(RAnnotatedCode *code); /** * @brief Deallocates dynamically allocated memory for the specified annotation. * @@ -106,9 +106,9 @@ R_API void r_annotated_code_free(RAnnotatedCode *code); * frees memory that is dynamically allocated for it. * * @param e Pointer to the annotation. - * @param user Always NULL for this function. Present here for this function to be of the type @ref RVectorFree. + * @param user Always NULL for this function. Present here for this function to be of the type @ref RzVectorFree. */ -R_API void r_annotation_free(void *e, void *user); +RZ_API void rz_annotation_free(void *e, void *user); /** * @brief Checks if the specified annotation is a reference. * @@ -119,7 +119,7 @@ R_API void r_annotation_free(void *e, void *user); * @param annotation Pointer to an annotation. * @return Returns true if the specified annotation is a reference. */ -R_API bool r_annotation_is_reference(RCodeAnnotation *annotation); +RZ_API bool rz_annotation_is_reference(RCodeAnnotation *annotation); /** * @brief Checks if the specified annotation is a function variable. * @@ -130,14 +130,14 @@ R_API bool r_annotation_is_reference(RCodeAnnotation *annotation); * @param annotation Pointer to an annotation. * @return Returns true if the specified annotation is a function variable. */ -R_API bool r_annotation_is_variable(RCodeAnnotation *annotation); +RZ_API bool rz_annotation_is_variable(RCodeAnnotation *annotation); /** * @brief Inserts the specified annotation into the list of annotations in the specified RAnnotatedCode. * * @param code Pointer to a RAnnotatedCode. * @param annotation Pointer to an annotation. */ -R_API void r_annotated_code_add_annotation(RAnnotatedCode *code, RCodeAnnotation *annotation); +RZ_API void rz_annotated_code_add_annotation(RAnnotatedCode *code, RCodeAnnotation *annotation); /** * @brief Returns all annotations with range that contains the given offset. * @@ -148,7 +148,7 @@ R_API void r_annotated_code_add_annotation(RAnnotatedCode *code, RCodeAnnotation * @param offset Offset. * @return Pointer to the @ref RPVector created. */ -R_API RPVector *r_annotated_code_annotations_in(RAnnotatedCode *code, size_t offset); +RZ_API RPVector *rz_annotated_code_annotations_in(RAnnotatedCode *code, size_t offset); /** * @brief Returns all annotations with range that overlap with the specified range. * @@ -160,18 +160,18 @@ R_API RPVector *r_annotated_code_annotations_in(RAnnotatedCode *code, size_t off * @param end End of the range(exclusive). * @return Pointer to the @ref RPVector created. */ -R_API RPVector *r_annotated_code_annotations_range(RAnnotatedCode *code, size_t start, size_t end); +RZ_API RPVector *rz_annotated_code_annotations_range(RAnnotatedCode *code, size_t start, size_t end); /** * @brief Returns the offset for every line of decompiled code in the specified RAnnotatedCode. * - * Creates an @ref RVector and inserts the offsets for every seperate line of decompiled code in + * Creates an @ref RzVector and inserts the offsets for every seperate line of decompiled code in * the specified RAnnotatedCode. * If a line of decompiled code doesn't have a unique offset, UT64_MAX is inserted as its offset. * * @param code Pointer to a RAnnotatedCode. - * @return Pointer to the @ref RVector created. + * @return Pointer to the @ref RzVector created. */ -R_API RVector *r_annotated_code_line_offsets(RAnnotatedCode *code); +RZ_API RzVector *rz_annotated_code_line_offsets(RAnnotatedCode *code); #ifdef __cplusplus } diff --git a/libr/include/r_util/r_ascii_table.h b/librz/include/rz_util/rz_ascii_table.h similarity index 81% rename from libr/include/r_util/r_ascii_table.h rename to librz/include/rz_util/rz_ascii_table.h index f0b46c3651..c749412579 100644 --- a/libr/include/r_util/r_ascii_table.h +++ b/librz/include/rz_util/rz_ascii_table.h @@ -7,7 +7,7 @@ extern "C" { #endif -R_API const char *ret_ascii_table(void); +RZ_API const char *ret_ascii_table(void); #ifdef __cplusplus } diff --git a/libr/include/r_util/r_asn1.h b/librz/include/rz_util/rz_asn1.h similarity index 68% rename from libr/include/r_util/r_asn1.h rename to librz/include/rz_util/rz_asn1.h index eb299d3ff5..ba045e1fb0 100644 --- a/libr/include/r_util/r_asn1.h +++ b/librz/include/rz_util/rz_asn1.h @@ -58,23 +58,23 @@ extern "C" { #define TAG_UNIVERSALSTRING 0x1C /* 28: Universal string */ #define TAG_BMPSTRING 0x1E /* 30: Basic Multilingual Plane/Unicode string */ -typedef struct r_asn1_string_t { +typedef struct rz_asn1_string_t { ut32 length; const char *string; bool allocated; } RASN1String; -typedef struct r_asn1_list_t { +typedef struct rz_asn1_list_t { ut32 length; - struct r_asn1_object_t **objects; + struct rz_asn1_object_t **objects; } ASN1List; -typedef struct r_asn1_bin_t { +typedef struct rz_asn1_bin_t { ut32 length; ut8 *binary; } RASN1Binary; -typedef struct r_asn1_object_t { +typedef struct rz_asn1_object_t { ut8 klass; /* class type */ ut8 form; /* defines if contains data or objects */ ut8 tag; /* tag type */ @@ -85,24 +85,24 @@ typedef struct r_asn1_object_t { } RASN1Object; -R_API RASN1Object *r_asn1_create_object (const ut8 *buffer, ut32 length, const ut8 *start_pointer); -R_API RASN1Binary *r_asn1_create_binary (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_create_string (const char *string, bool allocated, ut32 length); -R_API RASN1String *r_asn1_stringify_bits (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_utctime (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_time (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_integer (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_string (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_bytes (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_boolean (const ut8 *buffer, ut32 length); -R_API RASN1String *r_asn1_stringify_oid (const ut8* buffer, ut32 length); +RZ_API RASN1Object *rz_asn1_create_object (const ut8 *buffer, ut32 length, const ut8 *start_pointer); +RZ_API RASN1Binary *rz_asn1_create_binary (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_create_string (const char *string, bool allocated, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_bits (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_utctime (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_time (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_integer (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_string (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_bytes (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_boolean (const ut8 *buffer, ut32 length); +RZ_API RASN1String *rz_asn1_stringify_oid (const ut8* buffer, ut32 length); -R_API void r_asn1_free_object (RASN1Object *object); -// R_API void r_asn1_print_object (RASN1Object *object, ut32 depth); -R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb); -R_API void r_asn1_free_string (RASN1String *string); -R_API void r_asn1_free_binary (RASN1Binary *string); -R_API void asn1_setformat (int fmt); +RZ_API void rz_asn1_free_object (RASN1Object *object); +// RZ_API void rz_asn1_print_object (RASN1Object *object, ut32 depth); +RZ_API char *rz_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb); +RZ_API void rz_asn1_free_string (RASN1String *string); +RZ_API void rz_asn1_free_binary (RASN1Binary *string); +RZ_API void asn1_setformat (int fmt); #ifdef __cplusplus } diff --git a/libr/include/r_util/r_assert.h b/librz/include/rz_util/rz_assert.h similarity index 68% rename from libr/include/r_util/r_assert.h rename to librz/include/rz_util/rz_assert.h index c7cbe8ac36..143661b77c 100644 --- a/libr/include/r_util/r_assert.h +++ b/librz/include/rz_util/rz_assert.h @@ -1,7 +1,7 @@ #ifndef R_ASSERT_H #define R_ASSERT_H -#include "r_log.h" +#include "rz_log.h" #define R_STATIC_ASSERT(x)\ switch (0) {\ @@ -9,7 +9,7 @@ case (x):;\ } -R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API void rz_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, 3); #if defined (__GNUC__) && defined (__cplusplus) #define R_FUNCTION ((const char*) (__PRETTY_FUNCTION__)) @@ -22,22 +22,22 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, #define R_FUNCTION ((const char*) ("???")) #endif -#define r_warn_if_reached() \ +#define rz_warn_if_reached() \ do { \ - r_assert_log (R_LOGLVL_WARN, "(%s:%d):%s%s code should not be reached\n", \ + rz_assert_log (R_LOGLVL_WARN, "(%s:%d):%s%s code should not be reached\n", \ __FILE__, __LINE__, R_FUNCTION, R_FUNCTION[0] ? ":" : ""); \ } while (0) -#define r_warn_if_fail(expr) \ +#define rz_warn_if_fail(expr) \ do { \ if (!(expr)) { \ - r_assert_log (R_LOGLVL_WARN, "WARNING (%s:%d):%s%s runtime check failed: (%s)\n", \ + rz_assert_log (R_LOGLVL_WARN, "WARNING (%s:%d):%s%s runtime check failed: (%s)\n", \ __FILE__, __LINE__, R_FUNCTION, R_FUNCTION[0] ? ":" : "", #expr); \ } \ } while (0) /* - * R_CHECKS_LEVEL determines the behaviour of the r_return_* set of functions. + * R_CHECKS_LEVEL determines the behaviour of the rz_return_* set of functions. * * 0: completely disable every function and make them like no-operation * 1: silently enable checks. Check expressions and do return, but do not log anything @@ -50,26 +50,26 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, #if R_CHECKS_LEVEL == 0 -#define r_return_if_fail(expr) do { ; } while(0) -#define r_return_val_if_fail(expr, val) do { ; } while(0) -#define r_return_if_reached() do { ; } while(0) -#define r_return_val_if_reached(val) do { ; } while(0) +#define rz_return_if_fail(expr) do { ; } while(0) +#define rz_return_val_if_fail(expr, val) do { ; } while(0) +#define rz_return_if_reached() do { ; } while(0) +#define rz_return_val_if_reached(val) do { ; } while(0) #elif R_CHECKS_LEVEL == 1 || R_CHECKS_LEVEL == 2 // R_CHECKS_LEVEL #if R_CHECKS_LEVEL == 1 #define H_LOG_(loglevel, fmt, ...) #else -#define H_LOG_(loglevel, fmt, ...) r_assert_log (loglevel, fmt, __VA_ARGS__) +#define H_LOG_(loglevel, fmt, ...) rz_assert_log (loglevel, fmt, __VA_ARGS__) #endif /** - * r_return_if_fail: + * rz_return_if_fail: * @expr: the expression to check * * Verifies that the expression @expr, usually representing a precondition, * evaluates to `true`. If the function returns a value, use - * r_return_val_if_fail() instead. + * rz_return_val_if_fail() instead. * * If @expr evaluates to %FALSE, the current function should be considered to * have undefined behaviour (a programmer error). The only correct solution @@ -81,7 +81,7 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, * function returns. * */ -#define r_return_if_fail(expr) \ +#define rz_return_if_fail(expr) \ do { \ if (!(expr)) { \ H_LOG_ (R_LOGLVL_WARN, "%s: assertion '%s' failed (line %d)\n", R_FUNCTION, #expr, __LINE__); \ @@ -89,7 +89,7 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, } \ } while (0) -#define r_return_val_if_fail(expr, val) \ +#define rz_return_val_if_fail(expr, val) \ do { \ if (!(expr)) { \ H_LOG_ (R_LOGLVL_WARN, "%s: assertion '%s' failed (line %d)\n", R_FUNCTION, #expr, __LINE__); \ @@ -97,13 +97,13 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, } \ } while (0) -#define r_return_if_reached() \ +#define rz_return_if_reached() \ do { \ H_LOG_ (R_LOGLVL_ERROR, "file %s: line %d (%s): should not be reached\n", __FILE__, __LINE__, R_FUNCTION); \ return; \ } while (0) -#define r_return_val_if_reached(val) \ +#define rz_return_val_if_reached(val) \ do { \ H_LOG_ (R_LOGLVL_ERROR, "file %s: line %d (%s): should not be reached\n", __FILE__, __LINE__, R_FUNCTION); \ return (val); \ @@ -113,10 +113,10 @@ R_API void r_assert_log(RLogLevel level, const char *fmt, ...) R_PRINTF_CHECK(2, #include -#define r_return_if_fail(expr) do { assert (expr); } while(0) -#define r_return_val_if_fail(expr, val) do { assert (expr); } while(0) -#define r_return_if_reached() do { assert (false); } while(0) -#define r_return_val_if_reached(val) do { assert (false); } while(0) +#define rz_return_if_fail(expr) do { assert (expr); } while(0) +#define rz_return_val_if_fail(expr, val) do { assert (expr); } while(0) +#define rz_return_if_reached() do { assert (false); } while(0) +#define rz_return_val_if_reached(val) do { assert (false); } while(0) #endif // R_CHECKS_LEVEL diff --git a/librz/include/rz_util/rz_base64.h b/librz/include/rz_util/rz_base64.h new file mode 100644 index 0000000000..b7003161ad --- /dev/null +++ b/librz/include/rz_util/rz_base64.h @@ -0,0 +1,16 @@ +#ifndef R_BASE64_H +#define R_BASE64_H + +#ifdef __cplusplus +extern "C" { +#endif + +RZ_API int rz_base64_encode(char *bout, const ut8 *bin, int len); +RZ_API int rz_base64_decode(ut8 *bout, const char *bin, int len); +RZ_API ut8 *rz_base64_decode_dyn(const char *in, int len); +RZ_API char *rz_base64_encode_dyn(const char *str, int len); +#ifdef __cplusplus +} +#endif + +#endif // R_BASE64_H diff --git a/librz/include/rz_util/rz_base91.h b/librz/include/rz_util/rz_base91.h new file mode 100644 index 0000000000..a20286f67c --- /dev/null +++ b/librz/include/rz_util/rz_base91.h @@ -0,0 +1,15 @@ +#ifndef R_BASE91_H +#define R_BASE91_H + +#ifdef __cplusplus +extern "C" { +#endif + +RZ_API int rz_base91_encode(char *bout, const ut8 *bin, int len); +RZ_API int rz_base91_decode(ut8 *bout, const char *bin, int len); + +#ifdef __cplusplus +} +#endif + +#endif // R_BASE91_H diff --git a/librz/include/rz_util/rz_big.h b/librz/include/rz_util/rz_big.h new file mode 100644 index 0000000000..cd37354474 --- /dev/null +++ b/librz/include/rz_util/rz_big.h @@ -0,0 +1,73 @@ +#ifndef R_BIG_H +#define R_BIG_H + +#include "../rz_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if HAVE_LIB_GMP +/* Use GMP's data struct */ +#define RNumBig mpz_t +#elif HAVE_LIB_SSL +#define RNumBig BIGNUM +#else +/* Use default impl */ +#define R_BIG_WORD_SIZE 4 +/* Let's support 4096-bit big number */ +#define R_BIG_ARRAY_SIZE (512 / R_BIG_WORD_SIZE) +/* R_BIG_WORD_SIZE == 4, 32 bits long */ +#define R_BIG_DTYPE ut32 +#define R_BIG_DTYPE_TMP ut64 +#define R_BIG_SPRINTF_FORMAT_STR "%.08x" +#define R_BIG_FORMAT_STR_LEN 9 +#define R_BIG_SSCANF_FORMAT_STR "%8x" +#define R_BIG_MAX_VAL (R_BIG_DTYPE_TMP) UT32_MAX + +typedef struct rz_num_big_t { + R_BIG_DTYPE array[R_BIG_ARRAY_SIZE]; + int sign; +} RNumBig; +#endif + +RZ_API RNumBig *rz_big_new(void); +RZ_API void rz_big_free(RNumBig *b); +RZ_API void rz_big_init(RNumBig *b); +RZ_API void rz_big_fini(RNumBig *b); + +/* Assignment operations */ +RZ_API void rz_big_from_int(RNumBig *b, st64 v); +RZ_API st64 rz_big_to_int(RNumBig *b); +RZ_API void rz_big_from_hexstr(RNumBig *b, const char *str); +RZ_API char *rz_big_to_hexstr(RNumBig *b); +RZ_API void rz_big_assign(RNumBig *dst, RNumBig *src); + +/* Basic arithmetic operations */ +RZ_API void rz_big_add(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a + b */ +RZ_API void rz_big_sub(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a - b */ +RZ_API void rz_big_mul(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a * b */ +RZ_API void rz_big_div(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a / b */ +RZ_API void rz_big_mod(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a % b */ +RZ_API void rz_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b); /* c = a/b, d = a%b */ + +/* Bitwise operations(for >= 0) */ +RZ_API void rz_big_and(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a & b */ +RZ_API void rz_big_or(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a | b */ +RZ_API void rz_big_xor(RNumBig *c, RNumBig *a, RNumBig *b); /* c = a ^ b */ +RZ_API void rz_big_lshift(RNumBig *c, RNumBig *a, size_t nbits); /* c = a << nbits */ +RZ_API void rz_big_rshift(RNumBig *c, RNumBig *a, size_t nbits); /* c = a >> nbits */ + +/* Special operators and comparison */ +RZ_API int rz_big_cmp(RNumBig *a, RNumBig *b); /* Return 1 if a>b, -1 if a 1024 */ +RZ_API void rz_big_isqrt(RNumBig *c, RNumBig *a); /* Integer square root -- e.g. isqrt(5) => 2*/ + +#ifdef __cplusplus +} +#endif + +#endif // R_BIG_H diff --git a/librz/include/rz_util/rz_bitmap.h b/librz/include/rz_util/rz_bitmap.h new file mode 100644 index 0000000000..e4204ddca7 --- /dev/null +++ b/librz/include/rz_util/rz_bitmap.h @@ -0,0 +1,32 @@ +#ifndef R_BITMAP_H +#define R_BITMAP_H + +#if R_SYS_BITS == 4 +#define BITWORD_BITS_SHIFT 5 +#define RBitword ut32 +#else +#define BITWORD_BITS_SHIFT 6 +#define RBitword ut64 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_bitmap_t { + int length; + RBitword *bitmap; +} RBitmap; + +RZ_API RBitmap *rz_bitmap_new(size_t len); +RZ_API void rz_bitmap_set_bytes(RBitmap *b, const ut8 *buf, int len); +RZ_API void rz_bitmap_free(RBitmap *b); +RZ_API void rz_bitmap_set(RBitmap *b, size_t bit); +RZ_API void rz_bitmap_unset(RBitmap *b, size_t bit); +RZ_API int rz_bitmap_test(RBitmap *b, size_t bit); + +#ifdef __cplusplus +} +#endif + +#endif // R_BITMAP_H diff --git a/librz/include/rz_util/rz_buf.h b/librz/include/rz_util/rz_buf.h new file mode 100644 index 0000000000..74df3fe1c8 --- /dev/null +++ b/librz/include/rz_util/rz_buf.h @@ -0,0 +1,217 @@ +#ifndef R_BUF_H +#define R_BUF_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// TODO: choose whether the _at operations should preserve the current seek or not + +#define R_BUF_SET 0 +#define R_BUF_CUR 1 +#define R_BUF_END 2 + +typedef struct rz_buf_t RBuffer; + +typedef bool (*RBufferInit)(RBuffer *b, const void *user); +typedef bool (*RBufferFini)(RBuffer *b); +typedef st64 (*RBufferRead)(RBuffer *b, ut8 *buf, ut64 len); +typedef st64 (*RBufferWrite)(RBuffer *b, const ut8 *buf, ut64 len); +typedef ut64 (*RBufferGetSize)(RBuffer *b); +typedef bool (*RBufferResize)(RBuffer *b, ut64 newsize); +typedef st64 (*RBufferSeek)(RBuffer *b, st64 addr, int whence); +typedef ut8 *(*RBufferGetWholeBuf)(RBuffer *b, ut64 *sz); +typedef void (*RBufferFreeWholeBuf)(RBuffer *b); +typedef RzList *(*RBufferNonEmptyList)(RBuffer *b); + +typedef struct rz_buffer_methods_t { + RBufferInit init; + RBufferFini fini; + RBufferRead read; + RBufferWrite write; + RBufferGetSize get_size; + RBufferResize resize; + RBufferSeek seek; + RBufferGetWholeBuf get_whole_buf; + RBufferFreeWholeBuf free_whole_buf; + RBufferNonEmptyList nonempty_list; +} RBufferMethods; + +struct rz_buf_t { + const RBufferMethods *methods; + void *priv; + ut8 *whole_buf; + bool readonly; + int Oxff_priv; + int refctr; +}; + +// XXX: this should not be public +typedef struct rz_buf_cache_t { + ut64 from; + ut64 to; + int size; + ut8 *data; + int written; +} RBufferSparse; + +/* constructors */ +RZ_API RBuffer *rz_buf_new(void); +RZ_API RBuffer *rz_buf_new_with_io(void *iob, int fd); +RZ_API RBuffer *rz_buf_new_with_bytes(const ut8* bytes, ut64 len); +RZ_API RBuffer *rz_buf_new_with_string(const char *msg); +RZ_API RBuffer *rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal); +RZ_API RBuffer *rz_buf_new_file(const char *file, int perm, int mode); +RZ_API RBuffer *rz_buf_new_with_buf(RBuffer *b); +RZ_API RBuffer *rz_buf_new_slurp(const char *file); +RZ_API RBuffer *rz_buf_new_slice(RBuffer *b, ut64 offset, ut64 size); +RZ_API RBuffer *rz_buf_new_empty(ut64 len); +RZ_API RBuffer *rz_buf_new_mmap(const char *file, int flags); +RZ_API RBuffer *rz_buf_new_sparse(ut8 Oxff); + +/* methods */ +RZ_API bool rz_buf_dump(RBuffer *buf, const char *file); +RZ_API bool rz_buf_set_bytes(RBuffer *b, const ut8 *buf, ut64 length); +RZ_API st64 rz_buf_append_string(RBuffer *b, const char *str); +RZ_API bool rz_buf_append_buf(RBuffer *b, RBuffer *a); +RZ_API bool rz_buf_append_bytes(RBuffer *b, const ut8 *buf, ut64 length); +RZ_API bool rz_buf_append_nbytes(RBuffer *b, ut64 length); +RZ_API bool rz_buf_append_ut16(RBuffer *b, ut16 n); +RZ_API bool rz_buf_append_buf_slice(RBuffer *b, RBuffer *a, ut64 offset, ut64 size); +RZ_API bool rz_buf_append_ut32(RBuffer *b, ut32 n); +RZ_API bool rz_buf_append_ut64(RBuffer *b, ut64 n); +RZ_API bool rz_buf_prepend_bytes(RBuffer *b, const ut8 *buf, ut64 length); +RZ_API st64 rz_buf_insert_bytes(RBuffer *b, ut64 addr, const ut8 *buf, ut64 length); +RZ_API char *rz_buf_to_string(RBuffer *b); +RZ_API char *rz_buf_get_string(RBuffer *b, ut64 addr); +RZ_API st64 rz_buf_read(RBuffer *b, ut8 *buf, ut64 len); +RZ_API ut8 rz_buf_read8(RBuffer *b); +RZ_API st64 rz_buf_fread(RBuffer *b, ut8 *buf, const char *fmt, int n); +RZ_API st64 rz_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len); +RZ_API ut8 rz_buf_read8_at(RBuffer *b, ut64 addr); +RZ_API ut64 rz_buf_tell(RBuffer *b); +RZ_API st64 rz_buf_seek(RBuffer *b, st64 addr, int whence); +RZ_API st64 rz_buf_fread_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n); +RZ_API st64 rz_buf_write(RBuffer *b, const ut8 *buf, ut64 len); +RZ_API st64 rz_buf_fwrite(RBuffer *b, const ut8 *buf, const char *fmt, int n); +RZ_API st64 rz_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, ut64 len); +RZ_API st64 rz_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fmt, int n); +// WARNING: this function should be used with care because it may allocate the +// entire buffer in memory. Consider using the rz_buf_read* APIs instead and read +// only the chunks you need. +R_DEPRECATE RZ_API const ut8 *rz_buf_data(RBuffer *b, ut64 *size); +RZ_API ut64 rz_buf_size(RBuffer *b); +RZ_API bool rz_buf_resize(RBuffer *b, ut64 newsize); +RZ_API RBuffer *rz_buf_ref(RBuffer *b); +RZ_API void rz_buf_free(RBuffer *b); +RZ_API bool rz_buf_fini(RBuffer *b); +RZ_API RzList *rz_buf_nonempty_list(RBuffer *b); + +static inline ut16 rz_buf_read_be16(RBuffer *b) { + ut8 buf[sizeof (ut16)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be16 (buf): UT16_MAX; +} + +static inline ut16 rz_buf_read_be16_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut16)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be16 (buf): UT16_MAX; +} + +static inline ut32 rz_buf_read_be32(RBuffer *b) { + ut8 buf[sizeof (ut32)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be32 (buf): UT32_MAX; +} + +static inline ut32 rz_buf_read_be32_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut32)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be32 (buf): UT32_MAX; +} + +static inline ut64 rz_buf_read_be64(RBuffer *b) { + ut8 buf[sizeof (ut64)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be64 (buf): UT64_MAX; +} + +static inline ut64 rz_buf_read_be64_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut64)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_be64 (buf): UT64_MAX; +} + +static inline ut16 rz_buf_read_le16(RBuffer *b) { + ut8 buf[sizeof (ut16)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le16 (buf): UT16_MAX; +} + +static inline ut16 rz_buf_read_le16_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut16)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le16 (buf): UT16_MAX; +} + +static inline ut32 rz_buf_read_le32(RBuffer *b) { + ut8 buf[sizeof (ut32)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le32 (buf): UT32_MAX; +} + +static inline ut32 rz_buf_read_le32_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut32)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le32 (buf): UT32_MAX; +} + +static inline ut64 rz_buf_read_le64(RBuffer *b) { + ut8 buf[sizeof (ut64)]; + int r = (int) rz_buf_read (b, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le64 (buf): UT64_MAX; +} + +static inline ut64 rz_buf_read_le64_at(RBuffer *b, ut64 addr) { + ut8 buf[sizeof (ut64)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_le64 (buf): UT64_MAX; +} + +static inline ut16 rz_buf_read_ble16_at(RBuffer *b, ut64 addr, bool big_endian) { + ut8 buf[sizeof (ut16)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_ble16 (buf, big_endian): UT16_MAX; +} + +static inline ut32 rz_buf_read_ble32_at(RBuffer *b, ut64 addr, bool big_endian) { + ut8 buf[sizeof (ut32)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_ble32 (buf, big_endian): UT32_MAX; +} + +static inline ut64 rz_buf_read_ble64_at(RBuffer *b, ut64 addr, bool big_endian) { + ut8 buf[sizeof (ut64)]; + int r = (int) rz_buf_read_at (b, addr, buf, sizeof (buf)); + return r == sizeof (buf)? rz_read_ble64 (buf, big_endian): UT64_MAX; +} + +RZ_API st64 rz_buf_uleb128(RBuffer *b, ut64 *v); +RZ_API st64 rz_buf_sleb128(RBuffer *b, st64 *v); + +static inline st64 rz_buf_uleb128_at(RBuffer *b, ut64 addr, ut64 *v) { + rz_buf_seek (b, addr, R_BUF_SET); + return rz_buf_uleb128 (b, v); +} +static inline st64 rz_buf_sleb128_at(RBuffer *b, ut64 addr, st64 *v) { + rz_buf_seek (b, addr, R_BUF_SET); + return rz_buf_sleb128 (b, v); +} + +#ifdef __cplusplus +} +#endif + +#endif // R_BUF_H diff --git a/librz/include/rz_util/rz_cache.h b/librz/include/rz_util/rz_cache.h new file mode 100644 index 0000000000..d64756304c --- /dev/null +++ b/librz/include/rz_util/rz_cache.h @@ -0,0 +1,30 @@ +#ifndef R_CACHE_H +#define R_CACHE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_cache_t { + ut64 base; + ut8 *buf; + ut64 len; +} RCache; + +typedef struct rz_prof_t { + struct timeval begin; + double result; +} RProfile; + +RZ_API RCache* rz_cache_new(void); +RZ_API void rz_cache_free(RCache *c); +RZ_API const ut8* rz_cache_get(RCache *c, ut64 addr, int *len); +RZ_API int rz_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len); +RZ_API void rz_cache_flush(RCache *c); +RZ_API void rz_prof_start(RProfile *p); +RZ_API double rz_prof_end(RProfile *p); + +#ifdef __cplusplus +} +#endif +#endif // R_CACHE_H diff --git a/librz/include/rz_util/rz_ctypes.h b/librz/include/rz_util/rz_ctypes.h new file mode 100644 index 0000000000..8c8b2852e1 --- /dev/null +++ b/librz/include/rz_util/rz_ctypes.h @@ -0,0 +1,50 @@ +#ifndef R_CTYPES_H +#define R_CTYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_type_enum { + const char *name; + const char *val; +}RTypeEnum; + +enum RTypeKind { + R_TYPE_BASIC = 0, + R_TYPE_ENUM = 1, + R_TYPE_STRUCT = 2, + R_TYPE_UNION = 3, + R_TYPE_TYPEDEF = 4 +}; + +RZ_API int rz_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val); +RZ_API void rz_type_del(Sdb *TDB, const char *name); +RZ_API int rz_type_kind(Sdb *TDB, const char *name); +RZ_API char *rz_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val); +RZ_API char *rz_type_enum_getbitfield(Sdb *TDB, const char *name, ut64 val); +RZ_API RzList* rz_type_get_enum (Sdb *TDB, const char *name); +RZ_API ut64 rz_type_get_bitsize (Sdb *TDB, const char *type); +RZ_API RzList* rz_type_get_by_offset(Sdb *TDB, ut64 offset); +RZ_API char *rz_type_get_struct_memb(Sdb *TDB, const char *type, int offset); +RZ_API char *rz_type_link_at (Sdb *TDB, ut64 addr); +RZ_API int rz_type_set_link (Sdb *TDB, const char *val, ut64 addr); +RZ_API int rz_type_unlink(Sdb *TDB, ut64 addr); +RZ_API int rz_type_link_offset (Sdb *TDB, const char *val, ut64 addr); +RZ_API char *rz_type_format(Sdb *TDB, const char *t); + +// Function prototypes api +RZ_API int rz_type_func_exist(Sdb *TDB, const char *func_name); +RZ_API const char *rz_type_func_cc(Sdb *TDB, const char *func_name); +RZ_API const char *rz_type_func_ret(Sdb *TDB, const char *func_name); +RZ_API int rz_type_func_args_count(Sdb *TDB, R_NONNULL const char *func_name); +RZ_API R_OWN char *rz_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i); +RZ_API const char *rz_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i); +RZ_API R_OWN char *rz_type_func_guess(Sdb *TDB, R_NONNULL char *func_name); + +#ifdef __cplusplus +} +#endif + +#endif // R_CTYPES_H + diff --git a/libr/include/r_util/r_debruijn.h b/librz/include/rz_util/rz_debruijn.h similarity index 79% rename from libr/include/r_util/r_debruijn.h rename to librz/include/rz_util/rz_debruijn.h index cc7934d0ba..99098a97c0 100644 --- a/libr/include/r_util/r_debruijn.h +++ b/librz/include/rz_util/rz_debruijn.h @@ -3,7 +3,7 @@ #ifndef R_DEBRUIJN_H #define R_DEBRUIJN_H -#include +#include #ifdef __cplusplus extern "C" { @@ -16,11 +16,11 @@ extern "C" { // offset of start. // The returned string is malloced, and it is the responsibility of the caller // to free the memory. -R_API char* r_debruijn_pattern(int size, int start, const char* charset); +RZ_API char* rz_debruijn_pattern(int size, int start, const char* charset); // Finds the offset of a given value in a cyclic pattern of an integer. -R_API int r_debruijn_offset(ut64 value, bool is_big_endian); +RZ_API int rz_debruijn_offset(ut64 value, bool is_big_endian); #ifdef __cplusplus } diff --git a/libr/include/r_util/r_event.h b/librz/include/rz_util/rz_event.h similarity index 62% rename from libr/include/r_util/r_event.h rename to librz/include/rz_util/rz_event.h index f2dd52cca3..a53dcf0f18 100644 --- a/libr/include/r_util/r_event.h +++ b/librz/include/rz_util/rz_event.h @@ -8,17 +8,17 @@ extern "C" { #endif #include -#include +#include -typedef struct r_event_t { +typedef struct rz_event_t { void *user; bool incall; HtUP *callbacks; - RVector all_callbacks; + RzVector all_callbacks; int next_handle; } REvent; -typedef struct r_event_callback_handle_t { +typedef struct rz_event_callback_handle_t { int handle; int type; } REventCallbackHandle; @@ -40,46 +40,46 @@ typedef enum { R_EVENT_MAX, } REventType; -typedef struct r_event_meta_t { +typedef struct rz_event_meta_t { int type; ut64 addr; const char *string; } REventMeta; -typedef struct r_event_class_t { +typedef struct rz_event_class_t { const char *name; } REventClass; -typedef struct r_event_class_rename_t { +typedef struct rz_event_class_rename_t { const char *name_old; const char *name_new; } REventClassRename; -typedef struct r_event_class_attr_t { +typedef struct rz_event_class_attr_t { const char *class_name; - int attr_type; // RAnalClassAttrType + int attr_type; // RzAnalClassAttrType const char *attr_id; } REventClassAttr; -typedef struct r_event_class_attr_set_t { +typedef struct rz_event_class_attr_set_t { REventClassAttr attr; const char *content; } REventClassAttrSet; -typedef struct r_event_class_attr_rename_t { +typedef struct rz_event_class_attr_rename_t { REventClassAttr attr; const char *attr_id_new; } REventClassAttrRename; -typedef struct r_event_debug_process_finished_t { +typedef struct rz_event_debug_process_finished_t { int pid; } REventDebugProcessFinished; -R_API REvent *r_event_new(void *user); -R_API void r_event_free(REvent *ev); -R_API REventCallbackHandle r_event_hook(REvent *ev, int type, REventCallback cb, void *user); -R_API void r_event_unhook(REvent *ev, REventCallbackHandle handle); -R_API void r_event_send(REvent *ev, int type, void *data); +RZ_API REvent *rz_event_new(void *user); +RZ_API void rz_event_free(REvent *ev); +RZ_API REventCallbackHandle rz_event_hook(REvent *ev, int type, REventCallback cb, void *user); +RZ_API void rz_event_unhook(REvent *ev, REventCallbackHandle handle); +RZ_API void rz_event_send(REvent *ev, int type, void *data); #ifdef __cplusplus } diff --git a/librz/include/rz_util/rz_file.h b/librz/include/rz_util/rz_file.h new file mode 100644 index 0000000000..68ced8b0eb --- /dev/null +++ b/librz/include/rz_util/rz_file.h @@ -0,0 +1,59 @@ +#ifndef R_FILE_H +#define R_FILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* is */ +RZ_API bool rz_file_is_abspath(const char *file); +RZ_API bool rz_file_is_c(const char *file); +RZ_API bool rz_file_is_directory(const char *str); +RZ_API bool rz_file_is_regular(const char *str); + +RZ_API bool rz_file_truncate(const char *filename, ut64 newsize); +RZ_API ut64 rz_file_size(const char *str); +RZ_API char *rz_file_root(const char *root, const char *path); +RZ_API RMmap *rz_file_mmap(const char *file, bool rw, ut64 base); +RZ_API int rz_file_mmap_read(const char *file, ut64 addr, ut8 *buf, int len); +RZ_API int rz_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len); +RZ_API void rz_file_mmap_free(RMmap *m); +RZ_API bool rz_file_chmod(const char *file, const char *mod, int recursive); +RZ_API char *rz_file_temp(const char *prefix); +RZ_API char *rz_file_path(const char *bin); +RZ_API const char *rz_file_basename(const char *path); +RZ_API char *rz_file_dirname(const char *path); +RZ_API char *rz_file_abspath_rel(const char *cwd, const char *file); +RZ_API char *rz_file_abspath(const char *file); +RZ_API ut8 *rz_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen); +RZ_API ut8 *rz_file_gzslurp(const char *str, int *outlen, int origonfail); +RZ_API char *rz_stdin_slurp(int *sz); +RZ_API char *rz_file_slurp(const char *str, R_NULLABLE size_t *usz); +//RZ_API char *rz_file_slurp_range(const char *str, ut64 off, ut64 sz); +RZ_API char *rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz); +RZ_API char *rz_file_slurp_random_line(const char *file); +RZ_API char *rz_file_slurp_random_line_count(const char *file, int *linecount); +RZ_API ut8 *rz_file_slurp_hexpairs(const char *str, int *usz); +RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append); +RZ_API bool rz_file_touch(const char *file); +RZ_API bool rz_file_hexdump(const char *file, const ut8 *buf, int len, int append); +RZ_API bool rz_file_rm(const char *file); +RZ_API bool rz_file_exists(const char *str); +RZ_API bool rz_file_fexists(const char *fmt, ...); +RZ_API char *rz_file_slurp_line(const char *file, int line, int context); +RZ_API char *rz_file_slurp_lines(const char *file, int line, int count); +RZ_API char *rz_file_slurp_lines_from_bottom(const char *file, int line); +RZ_API int rz_file_mkstemp(const char *prefix, char **oname); +RZ_API char *rz_file_tmpdir(void); +RZ_API char *rz_file_readlink(const char *path); +RZ_API bool rz_file_copy (const char *src, const char *dst); +RZ_API RzList* rz_file_globsearch (const char *globbed_path, int maxdepth); +RZ_API RMmap *rz_file_mmap_arch (RMmap *map, const char *filename, int fd); + +#ifdef __cplusplus +} +#endif + +#endif // R_FILE_H diff --git a/librz/include/rz_util/rz_graph.h b/librz/include/rz_util/rz_graph.h new file mode 100644 index 0000000000..ee52cc382d --- /dev/null +++ b/librz/include/rz_util/rz_graph.h @@ -0,0 +1,83 @@ +#ifndef R_GRAPH_H +#define R_GRAPH_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Generic graph node info + */ +typedef struct rz_anal_graph_node_info_t { + char *title; + char *body; + ut64 offset; +} RGraphNodeInfo; + +typedef struct rz_graph_node_t { + unsigned int idx; + void *data; + RzList *out_nodes; + RzList *in_nodes; + RzList *all_neighbours; + RzListFree free; +} RGraphNode; + +typedef struct rz_graph_edge_t { + RGraphNode *from; + RGraphNode *to; + int nth; +} RGraphEdge; + +typedef struct rz_graph_t { + unsigned int n_nodes; + unsigned int n_edges; + int last_index; + RzList *nodes; /* RGraphNode */ +} RGraph; + +typedef struct rz_graph_visitor_t { + void (*discover_node)(RGraphNode *n, struct rz_graph_visitor_t *vis); + void (*finish_node)(RGraphNode *n, struct rz_graph_visitor_t *vis); + void (*tree_edge)(const RGraphEdge *e, struct rz_graph_visitor_t *vis); + void (*back_edge)(const RGraphEdge *e, struct rz_graph_visitor_t *vis); + void (*fcross_edge)(const RGraphEdge *e, struct rz_graph_visitor_t *vis); + void *data; +} RGraphVisitor; +typedef void (*RGraphNodeCallback)(RGraphNode *n, RGraphVisitor *vis); +typedef void (*RGraphEdgeCallback)(const RGraphEdge *e, RGraphVisitor *vis); + +// Contrructs a new RGraph, returns heap-allocated graph. +RZ_API RGraph *rz_graph_new(void); +// Destroys the graph and all nodes. +RZ_API void rz_graph_free(RGraph* g); +// Gets the data of a node by index. +RZ_API RGraphNode *rz_graph_get_node(const RGraph *g, unsigned int idx); +RZ_API RzListIter *rz_graph_node_iter(const RGraph *g, unsigned int idx); +RZ_API void rz_graph_reset(RGraph *g); +RZ_API RGraphNode *rz_graph_add_node(RGraph *g, void *data); +// XXX 'n' is destroyed after calling this function. +RZ_API void rz_graph_del_node(RGraph *g, RGraphNode *n); +RZ_API void rz_graph_add_edge(RGraph *g, RGraphNode *from, RGraphNode *to); +RZ_API void rz_graph_add_edge_at(RGraph *g, RGraphNode *from, RGraphNode *to, int nth); +RZ_API RGraphNode *rz_graph_node_split_forward(RGraph *g, RGraphNode *split_me, void *data); +RZ_API void rz_graph_del_edge(RGraph *g, RGraphNode *from, RGraphNode *to); +RZ_API const RzList *rz_graph_get_neighbours(const RGraph *g, const RGraphNode *n); +RZ_API RGraphNode *rz_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, int nth); +RZ_API const RzList *rz_graph_innodes(const RGraph *g, const RGraphNode *n); +RZ_API const RzList *rz_graph_all_neighbours(const RGraph *g, const RGraphNode *n); +RZ_API const RzList *rz_graph_get_nodes(const RGraph *g); +RZ_API bool rz_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to); +RZ_API void rz_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis); +RZ_API void rz_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis); +RZ_API void rz_graph_dfs(RGraph *g, RGraphVisitor *vis); +RZ_API void rz_graph_free_node_info(void *ptr); +RZ_API RGraphNodeInfo *rz_graph_create_node_info(char *title, char *body, ut64 offset); + +#ifdef __cplusplus +} +#endif + +#endif // R_GRAPH_H diff --git a/librz/include/rz_util/rz_hex.h b/librz/include/rz_util/rz_hex.h new file mode 100644 index 0000000000..a097b2bf4d --- /dev/null +++ b/librz/include/rz_util/rz_hex.h @@ -0,0 +1,28 @@ +#ifndef R_HEX_H +#define R_HEX_H + +#ifdef __cplusplus +extern "C" { +#endif + +RZ_API int rz_hex_pair2bin(const char *arg); +RZ_API int rz_hex_str2binmask(const char *in, ut8 *out, ut8 *mask); +RZ_API int rz_hex_str2bin(const char *in, ut8 *out); +RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out); +RZ_API char *rz_hex_bin2strdup(const ut8 *in, int len); +RZ_API bool rz_hex_to_byte(ut8 *val, ut8 c); +RZ_API int rz_hex_str_is_valid(const char *s); +RZ_API st64 rz_hex_bin_truncate(ut64 in, int n); +RZ_API char *rz_hex_from_c(const char *code); +RZ_API char *rz_hex_from_py(const char *code); +RZ_API char *rz_hex_from_code(const char *code); +RZ_API char *rz_hex_no_code(const char *code); +RZ_API char *rz_hex_from_py_str(char *out, const char *code); +RZ_API char *rz_hex_from_py_array(char *out, const char *code); +RZ_API char *rz_hex_from_c_str(char *out, const char **code); +RZ_API char *rz_hex_from_c_array(char *out, const char *code); +#ifdef __cplusplus +} +#endif + +#endif // R_HEX_H diff --git a/librz/include/rz_util/rz_idpool.h b/librz/include/rz_util/rz_idpool.h new file mode 100644 index 0000000000..8f07a1c708 --- /dev/null +++ b/librz/include/rz_util/rz_idpool.h @@ -0,0 +1,79 @@ +/* rizin - LGPL - Copyright 2017-2018 - condret */ + +#ifndef R_ID_STORAGE_H +#define R_ID_STORAGE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_id_pool_t { + ut32 start_id; + ut32 last_id; + ut32 next_id; + RQueue *freed_ids; +} RIDPool; + +RZ_API RIDPool *rz_id_pool_new(ut32 start_id, ut32 last_id); +RZ_API bool rz_id_pool_grab_id(RIDPool *pool, ut32 *grabber); +RZ_API bool rz_id_pool_kick_id(RIDPool *pool, ut32 kick); +RZ_API void rz_id_pool_free(RIDPool *pool); + +typedef struct rz_id_storage_t { + RIDPool *pool; + void **data; + ut32 top_id; + ut32 size; +} RIDStorage; + +typedef bool (*RIDStorageForeachCb)(void *user, void *data, ut32 id); +typedef bool (*ROIDStorageCompareCb)(void *in, void *incoming, void *user, int *cmp_res); + +RZ_API RIDStorage *rz_id_storage_new(ut32 start_id, ut32 last_id); +RZ_API bool rz_id_storage_set(RIDStorage *storage, void *data, ut32 id); +RZ_API bool rz_id_storage_add(RIDStorage *storage, void *data, ut32 *id); +RZ_API void *rz_id_storage_get(RIDStorage *storage, ut32 id); +RZ_API void rz_id_storage_delete(RIDStorage *storage, ut32 id); +RZ_API void *rz_id_storage_take(RIDStorage *storage, ut32 id); +RZ_API bool rz_id_storage_foreach(RIDStorage *storage, RIDStorageForeachCb cb, void *user); +RZ_API void rz_id_storage_free(RIDStorage *storage); +RZ_API RzList *rz_id_storage_list(RIDStorage *s); + +typedef struct rz_ordered_id_storage_t { + ut32 *permutation; + ut32 psize; + ut32 ptop; + RIDStorage *data; + ROIDStorageCompareCb cmp; +} ROIDStorage; + +RZ_API ROIDStorage *rz_oids_new(ut32 start_id, ut32 last_id); +RZ_API void *rz_oids_get(ROIDStorage *storage, ut32 id); +RZ_API void *rz_oids_oget(ROIDStorage *storage, ut32 od); +RZ_API bool rz_oids_get_id(ROIDStorage *storage, ut32 od, ut32 *id); +RZ_API bool rz_oids_get_od(ROIDStorage *storage, ut32 id, ut32 *od); +RZ_API bool rz_oids_to_front(ROIDStorage *storage, const ut32 id); +RZ_API bool rz_oids_to_rear(ROIDStorage *storage, const ut32 id); +RZ_API void rz_oids_delete(ROIDStorage *storage, ut32 id); +RZ_API void rz_oids_odelete(ROIDStorage *st, ut32 od); +RZ_API void rz_oids_free(ROIDStorage *storage); +RZ_API bool rz_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od); +RZ_API void *rz_oids_take(ROIDStorage *storage, ut32 id); +RZ_API void *rz_oids_otake(ROIDStorage *st, ut32 od); +RZ_API bool rz_oids_foreach(ROIDStorage* storage, RIDStorageForeachCb cb, void* user); +RZ_API bool rz_oids_foreach_prev(ROIDStorage* storage, RIDStorageForeachCb cb, void* user); +RZ_API bool rz_oids_insert(ROIDStorage *storage, void *data, ut32 *id, ut32 *od, void *user); +RZ_API bool rz_oids_sort(ROIDStorage *storage, void *user); +RZ_API ut32 rz_oids_find (ROIDStorage *storage, void *incoming, void *user); +RZ_API void *rz_oids_last(ROIDStorage *storage); +RZ_API void *rz_oids_first(ROIDStorage *storage); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_util/r_intervaltree.h b/librz/include/rz_util/rz_intervaltree.h similarity index 54% rename from libr/include/r_util/r_intervaltree.h rename to librz/include/rz_util/rz_intervaltree.h index 3d2f7e06b3..bf9624ca35 100644 --- a/libr/include/r_util/r_intervaltree.h +++ b/librz/include/rz_util/rz_intervaltree.h @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2019 - thestr4ng3r */ +/* rizin - LGPL - Copyright 2019 - thestr4ng3r */ #ifndef R_INTERVALTREE_H #define R_INTERVALTREE_H -#include "r_rbtree.h" -#include "../r_types.h" +#include "rz_rbtree.h" +#include "../rz_types.h" /* * RIntervalTree is a special RBTree (augmented red-black tree) @@ -19,7 +19,7 @@ * For multiple entries with the same start, the ordering is undefined. */ -typedef struct r_interval_node_t { +typedef struct rz_interval_node_t { RBNode node; ut64 start; // inclusive, key of the node ut64 end; // may be inclusive or exclusive, this is only determined by how they are queried @@ -29,69 +29,69 @@ typedef struct r_interval_node_t { typedef void (*RIntervalNodeFree)(void *data); -typedef struct r_interval_tree_t { +typedef struct rz_interval_tree_t { RIntervalNode *root; RIntervalNodeFree free; } RIntervalTree; -R_API void r_interval_tree_init(RIntervalTree *tree, RIntervalNodeFree free); -R_API void r_interval_tree_fini(RIntervalTree *tree); +RZ_API void rz_interval_tree_init(RIntervalTree *tree, RIntervalNodeFree free); +RZ_API void rz_interval_tree_fini(RIntervalTree *tree); // return false if the insertion failed. -R_API bool r_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, void *data); +RZ_API bool rz_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, void *data); // Removes a given node from the tree. The node will be freed. // If free is true, the data in the node is freed as well. // false if the removal failed // Complexity is O(log(n) + m) if there are m nodes with the same start as the given node. -R_API bool r_interval_tree_delete(RIntervalTree *tree, RIntervalNode *node, bool free); +RZ_API bool rz_interval_tree_delete(RIntervalTree *tree, RIntervalNode *node, bool free); // Change start/end of a given node. // It is more efficient if only the end changed. // The RIntervalNode pointer is INVALID after this operation! // Complexity is O(log(n) + m) if there are m nodes with the same start as the given node. -R_API bool r_interval_tree_resize(RIntervalTree *tree, RIntervalNode *node, ut64 new_start, ut64 new_end); +RZ_API bool rz_interval_tree_resize(RIntervalTree *tree, RIntervalNode *node, ut64 new_start, ut64 new_end); // Returns an iterator that starts at the leftmost node that has the given start // Iterating over it will yield all nodes with given start, then all with a higher one. -R_API RBIter r_interval_tree_first_at(RIntervalTree *tree, ut64 start); +RZ_API RBIter rz_interval_tree_first_at(RIntervalTree *tree, ut64 start); // Returns a node that starts at exactly start or NULL -R_API RIntervalNode *r_interval_tree_node_at(RIntervalTree *tree, ut64 start); +RZ_API RIntervalNode *rz_interval_tree_node_at(RIntervalTree *tree, ut64 start); // Returns a node that starts at exactly start and contains data or NULL -R_API RIntervalNode *r_interval_tree_node_at_data(RIntervalTree *tree, ut64 start, void *data); +RZ_API RIntervalNode *rz_interval_tree_node_at_data(RIntervalTree *tree, ut64 start, void *data); -// Same as r_interval_tree_node_at, but directly returns the contained value or NULL -static inline void *r_interval_tree_at(RIntervalTree *tree, ut64 start) { - RIntervalNode *node = r_interval_tree_node_at (tree, start); +// Same as rz_interval_tree_node_at, but directly returns the contained value or NULL +static inline void *rz_interval_tree_at(RIntervalTree *tree, ut64 start) { + RIntervalNode *node = rz_interval_tree_node_at (tree, start); return node ? node->data : NULL; } typedef bool (*RIntervalIterCb)(RIntervalNode *node, void *user); // Call cb for all entries starting at exactly start -R_API bool r_interval_tree_all_at(RIntervalTree *tree, ut64 start, RIntervalIterCb cb, void *user); +RZ_API bool rz_interval_tree_all_at(RIntervalTree *tree, ut64 start, RIntervalIterCb cb, void *user); // Call cb for all entries whose intervals contain value // end_inclusive if true, all start/end values are considered inclusive/inclusive, else inclusive/exclusive -R_API bool r_interval_tree_all_in(RIntervalTree *tree, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user); +RZ_API bool rz_interval_tree_all_in(RIntervalTree *tree, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user); // Call cb for all entries whose intervals intersect the given interval (might not contain it completely) // end_inclusive if true, all start/end values are considered inclusive/inclusive, else inclusive/exclusive -R_API bool r_interval_tree_all_intersect(RIntervalTree *tree, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user); +RZ_API bool rz_interval_tree_all_intersect(RIntervalTree *tree, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user); typedef RBIter RIntervalTreeIter; -static inline RIntervalNode *r_interval_tree_iter_get(RIntervalTreeIter *it) { - return r_rbtree_iter_get (it, RIntervalNode, node); +static inline RIntervalNode *rz_interval_tree_iter_get(RIntervalTreeIter *it) { + return rz_rbtree_iter_get (it, RIntervalNode, node); } -#define r_interval_tree_foreach(tree, it, dat) \ - for ((it) = r_rbtree_first (&(tree)->root->node); r_rbtree_iter_has (&it) && (dat = r_interval_tree_iter_get (&it)->data); r_rbtree_iter_next (&(it))) +#define rz_interval_tree_foreach(tree, it, dat) \ + for ((it) = rz_rbtree_first (&(tree)->root->node); rz_rbtree_iter_has (&it) && (dat = rz_interval_tree_iter_get (&it)->data); rz_rbtree_iter_next (&(it))) -#define r_interval_tree_foreach_prev(tree, it, dat) \ - for ((it) = r_rbtree_last (&(tree)->root->node); r_rbtree_iter_has (&it) && (dat = r_rbtree_iter_get (&it, RIntervalNode, node)->data); r_rbtree_iter_prev (&(it))) +#define rz_interval_tree_foreach_prev(tree, it, dat) \ + for ((it) = rz_rbtree_last (&(tree)->root->node); rz_rbtree_iter_has (&it) && (dat = rz_rbtree_iter_get (&it, RIntervalNode, node)->data); rz_rbtree_iter_prev (&(it))) #endif //R_INTERVALTREE_H diff --git a/libr/include/r_util/r_itv.h b/librz/include/rz_util/rz_itv.h similarity index 65% rename from libr/include/r_util/r_itv.h rename to librz/include/rz_util/rz_itv.h index 87f62e8cd5..bbff15eed3 100644 --- a/libr/include/r_util/r_itv.h +++ b/librz/include/rz_util/rz_itv.h @@ -1,7 +1,7 @@ #ifndef R_INTERVAL_H #define R_INTERVAL_H -#include +#include #ifdef __cplusplus extern "C" { @@ -10,15 +10,15 @@ extern "C" { // An interval in 64-bit address space which is aware of address space wraparound // Precondition: 0 <= size < 2**64 and addr + size <= 2**64 // range is [], [10, 5) => 10 <= x < (10 + 5) -typedef struct r_interval_t { +typedef struct rz_interval_t { // public: ut64 addr; ut64 size; } RInterval; -typedef RInterval r_itv_t; +typedef RInterval rz_itv_t; -static inline RInterval *r_itv_new(ut64 addr, ut64 size) { +static inline RInterval *rz_itv_new(ut64 addr, ut64 size) { RInterval *itv = R_NEW (RInterval); if (itv) { itv->addr = addr; @@ -27,53 +27,53 @@ static inline RInterval *r_itv_new(ut64 addr, ut64 size) { return itv; } -static inline void r_itv_free(RInterval *itv) { +static inline void rz_itv_free(RInterval *itv) { free (itv); } -static inline ut64 r_itv_begin(RInterval itv) { +static inline ut64 rz_itv_begin(RInterval itv) { return itv.addr; } -static inline ut64 r_itv_size(RInterval itv) { +static inline ut64 rz_itv_size(RInterval itv) { return itv.size; } -static inline ut64 r_itv_end(RInterval itv) { +static inline ut64 rz_itv_end(RInterval itv) { return itv.addr + itv.size; } // Returns true if itv equals itv2 -static inline bool r_itv_eq(RInterval itv, RInterval itv2) { +static inline bool rz_itv_eq(RInterval itv, RInterval itv2) { return itv.addr == itv2.addr && itv.size == itv2.size; } // Returns true if itv contained addr -static inline bool r_itv_contain(RInterval itv, ut64 addr) { +static inline bool rz_itv_contain(RInterval itv, ut64 addr) { const ut64 end = itv.addr + itv.size; return itv.addr <= addr && (!end || addr < end); } // Returns true if x is a subset of itv -static inline bool r_itv_include(RInterval itv, RInterval x) { +static inline bool rz_itv_include(RInterval itv, RInterval x) { const ut64 end = itv.addr + itv.size; return itv.addr <= x.addr && (!end || (x.addr + x.size && x.addr + x.size <= end)); } // Returns true if itv and x overlap (implying they are non-empty) -static inline bool r_itv_overlap(RInterval itv, RInterval x) { +static inline bool rz_itv_overlap(RInterval itv, RInterval x) { const ut64 end = itv.addr + itv.size, end1 = x.addr + x.size; return (!end1 || itv.addr < end1) && (!end || x.addr < end); } -static inline bool r_itv_overlap2(RInterval itv, ut64 addr, ut64 size) { +static inline bool rz_itv_overlap2(RInterval itv, ut64 addr, ut64 size) { RInterval rai = {addr, size}; - return r_itv_overlap (itv, rai); + return rz_itv_overlap (itv, rai); } // Precondition: itv and x overlap // Returns the intersection of itv and x -static inline RInterval r_itv_intersect(RInterval itv, RInterval x) { +static inline RInterval rz_itv_intersect(RInterval itv, RInterval x) { const ut64 addr = R_MAX (itv.addr, x.addr); const ut64 end = R_MIN (itv.addr + itv.size - 1, x.addr + x.size - 1) + 1; RInterval rai = {addr, end - addr}; diff --git a/libr/include/r_util/r_json.h b/librz/include/rz_util/rz_json.h similarity index 71% rename from libr/include/r_util/r_json.h rename to librz/include/rz_util/rz_json.h index e3b8506844..9d88923358 100644 --- a/libr/include/r_util/r_json.h +++ b/librz/include/rz_util/rz_json.h @@ -3,18 +3,18 @@ #ifndef R_JSON_H #define R_JSON_H -#include +#include #ifdef __cplusplus extern "C" { #endif /* - * r_json is a JSON parsing API, + * rz_json is a JSON parsing API, * heavily based on nxjson by Yaroslav Stavnichiy , * which is available under LGPLv3 or later. * - * r_json does NOT format json, it only parses. To format json, see pj.h instead. + * rz_json does NOT format json, it only parses. To format json, see pj.h instead. * It operates in-place, which means the parsed string will be MODIFIED. * This means all string values in RJson point directly into the input string, * removing the need to copy them. @@ -22,7 +22,7 @@ extern "C" { * It also supports both line and block style comments. */ -typedef enum r_json_type_t { +typedef enum rz_json_type_t { R_JSON_NULL, R_JSON_OBJECT, // properties can be found in child nodes R_JSON_ARRAY, // items can be found in child nodes @@ -32,7 +32,7 @@ typedef enum r_json_type_t { R_JSON_BOOLEAN // value can be found in the num.u_value field } RJsonType; -typedef struct r_json_t { +typedef struct rz_json_t { RJsonType type; // type of json node, see above const char *key; // key of the property; for object's children only union { @@ -46,19 +46,19 @@ typedef struct r_json_t { } num; struct { // children of OBJECT or ARRAY size_t count; - struct r_json_t *first; - struct r_json_t *last; + struct rz_json_t *first; + struct rz_json_t *last; } children; }; - struct r_json_t *next; // points to next child + struct rz_json_t *next; // points to next child } RJson; -R_API RJson *r_json_parse(char *text); +RZ_API RJson *rz_json_parse(char *text); -R_API void r_json_free(RJson *js); +RZ_API void rz_json_free(RJson *js); -R_API const RJson *r_json_get(const RJson *json, const char *key); // get object's property by key -R_API const RJson *r_json_item(const RJson *json, size_t idx); // get array element by index +RZ_API const RJson *rz_json_get(const RJson *json, const char *key); // get object's property by key +RZ_API const RJson *rz_json_item(const RJson *json, size_t idx); // get array element by index #ifdef __cplusplus } diff --git a/libr/include/r_util/r_log.h b/librz/include/rz_util/rz_log.h similarity index 55% rename from libr/include/r_util/r_log.h rename to librz/include/rz_util/rz_log.h index af3344353c..13f147734f 100644 --- a/libr/include/r_util/r_log.h +++ b/librz/include/rz_util/rz_log.h @@ -1,7 +1,7 @@ #ifndef R_LOG_H #define R_LOG_H -#include +#include #if (defined(_WIN32) || defined(_WIN64)) && !defined(__GNUC__) #define MACRO_LOG_FUNC __FUNCTION__ @@ -15,14 +15,14 @@ #define MACRO_WEAK_SYM __attribute__ ((weak)) #endif -typedef enum r_log_level { +typedef enum rz_log_level { R_LOGLVL_SILLY = 0, R_LOGLVL_DEBUG = 1, R_LOGLVL_VERBOSE = 2, R_LOGLVL_INFO = 3, R_LOGLVL_WARN = 4, R_LOGLVL_ERROR = 5, - R_LOGLVL_FATAL = 6, // This will call r_sys_breakpoint() and trap the process for debugging! + R_LOGLVL_FATAL = 6, // This will call rz_sys_breakpoint() and trap the process for debugging! R_LOGLVL_NONE = 0xFF } RLogLevel; @@ -35,50 +35,50 @@ typedef enum r_log_level { typedef void (*RLogCallback) (const char *output, const char *funcname, const char *filename, ut32 lineno, RLogLevel level, const char *tag, const char *fmtstr, ...); -#define R_VLOG(lvl, tag, fmtstr, args) r_vlog (MACRO_LOG_FUNC, __FILE__, \ +#define R_VLOG(lvl, tag, fmtstr, args) rz_vlog (MACRO_LOG_FUNC, __FILE__, \ __LINE__, lvl, tag, fmtstr, args); -#define R_LOG(lvl, tag, fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG(lvl, tag, fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, lvl, tag, fmtstr, ##__VA_ARGS__); -#define R_LOG_SILLY(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_SILLY(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_SILLY, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_DEBUG(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_DEBUG(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_DEBUG, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_VERBOSE(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_VERBOSE(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_VERBOSE, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_INFO(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_INFO(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_INFO, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_WARN(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_WARN(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_WARN, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_ERROR(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_ERROR(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_ERROR, NULL, fmtstr, ##__VA_ARGS__); -#define R_LOG_FATAL(fmtstr, ...) r_log (MACRO_LOG_FUNC, __FILE__, \ +#define R_LOG_FATAL(fmtstr, ...) rz_log (MACRO_LOG_FUNC, __FILE__, \ __LINE__, R_LOGLVL_FATAL, NULL, fmtstr, ##__VA_ARGS__); #ifdef __cplusplus extern "C" { #endif -// Called by r_core to set the configuration variables -R_API void r_log_set_level(RLogLevel level); -R_API void r_log_set_file(const char *filename); -R_API void r_log_set_srcinfo(bool show_info); -R_API void r_log_set_colors(bool show_colors); -R_API void r_log_set_traplevel(RLogLevel level); -// TODO: r_log_set_options(enum RLogOptions) +// Called by rz_core to set the configuration variables +RZ_API void rz_log_set_level(RLogLevel level); +RZ_API void rz_log_set_file(const char *filename); +RZ_API void rz_log_set_srcinfo(bool show_info); +RZ_API void rz_log_set_colors(bool show_colors); +RZ_API void rz_log_set_traplevel(RLogLevel level); +// TODO: rz_log_set_options(enum RLogOptions) // Functions for adding log callbacks -R_API void r_log_add_callback(RLogCallback cbfunc); -R_API void r_log_del_callback(RLogCallback cbfunc); -// TODO: r_log_get_callbacks() +RZ_API void rz_log_add_callback(RLogCallback cbfunc); +RZ_API void rz_log_del_callback(RLogCallback cbfunc); +// TODO: rz_log_get_callbacks() -/* Define r_log as weak so it can be 'overwritten' externally +/* Define rz_log as weak so it can be 'overwritten' externally This allows another method of output redirection on POSIX (Windows?) You can override this function to handle all logging logic / output yourself */ -R_API MACRO_WEAK_SYM void r_log(const char *funcname, const char *filename, +RZ_API MACRO_WEAK_SYM void rz_log(const char *funcname, const char *filename, ut32 lineno, RLogLevel level, const char *tag, const char *fmtstr, ...) R_PRINTF_CHECK(6, 7); -R_API MACRO_WEAK_SYM void r_vlog(const char *funcname, const char *filename, +RZ_API MACRO_WEAK_SYM void rz_vlog(const char *funcname, const char *filename, ut32 lineno, RLogLevel level, const char *tag, const char *fmtstr, va_list args); #ifdef __cplusplus diff --git a/librz/include/rz_util/rz_mem.h b/librz/include/rz_util/rz_mem.h new file mode 100644 index 0000000000..4f308f031e --- /dev/null +++ b/librz/include/rz_util/rz_mem.h @@ -0,0 +1,62 @@ +#ifndef R_MEM_H +#define R_MEM_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_mmap_t { + ut8 *buf; + ut64 base; + int len; + int fd; + int rw; + char *filename; +#if __WINDOWS__ + HANDLE fh; + HANDLE fm; +#endif +} RMmap; + +typedef struct rz_mem_pool_t { + ut8 **nodes; + int ncount; + int npool; + // + int nodesize; + int poolsize; + int poolcount; +} RMemoryPool; + +RZ_API ut64 rz_mem_get_num(const ut8 *b, int size); + +/* MEMORY POOL */ +RZ_API RMemoryPool* rz_mem_pool_deinit(RMemoryPool *pool); +RZ_API RMemoryPool *rz_mem_pool_new(int nodesize, int poolsize, int poolcount); +RZ_API RMemoryPool *rz_mem_pool_free(RMemoryPool *pool); +RZ_API void* rz_mem_pool_alloc(RMemoryPool *pool); +RZ_API void *rz_mem_dup(const void *s, int l); +RZ_API void *rz_mem_alloc(int sz); +RZ_API void rz_mem_free(void *); +RZ_API void rz_mem_memzero(void *, size_t); +RZ_API void rz_mem_reverse(ut8 *b, int l); +RZ_API int rz_mem_protect(void *ptr, int size, const char *prot); +RZ_API int rz_mem_set_num(ut8 *dest, int dest_size, ut64 num); +RZ_API int rz_mem_eq(ut8 *a, ut8 *b, int len); +RZ_API void rz_mem_copybits(ut8 *dst, const ut8 *src, int bits); +RZ_API void rz_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits); +RZ_API void rz_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize); +RZ_API void rz_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian); +RZ_API void rz_mem_swapendian(ut8 *dest, const ut8 *orig, int size); +RZ_API int rz_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len); +RZ_API const ut8 *rz_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int nlen); +RZ_API const ut8 *rz_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align); +RZ_API int rz_mem_count(const ut8 **addr); +RZ_API bool rz_mem_is_printable (const ut8 *a, int la); +RZ_API bool rz_mem_is_zero(const ut8 *b, int l); +RZ_API void *rz_mem_mmap_resize(RMmap *m, ut64 newsize); + +#ifdef __cplusplus +} +#endif +#endif // R_MEM_H diff --git a/librz/include/rz_util/rz_name.h b/librz/include/rz_util/rz_name.h new file mode 100644 index 0000000000..5fda3b4609 --- /dev/null +++ b/librz/include/rz_util/rz_name.h @@ -0,0 +1,17 @@ +#ifndef R_NAME_H +#define R_NAME_H + +#ifdef __cplusplus +extern "C" { +#endif + +RZ_API bool rz_name_check(const char *name); +RZ_API bool rz_name_filter(char *name, int len); +RZ_API char *rz_name_filter2(const char *name); +RZ_API bool rz_name_validate_char(const char ch); + +#ifdef __cplusplus +} +#endif + +#endif // R_NAME_H diff --git a/librz/include/rz_util/rz_num.h b/librz/include/rz_util/rz_num.h new file mode 100644 index 0000000000..5325ab1a4d --- /dev/null +++ b/librz/include/rz_util/rz_num.h @@ -0,0 +1,93 @@ +#ifndef R_NUM_H +#define R_NUM_H + +#define R_NUMCALC_STRSZ 1024 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + double d; + ut64 n; +} RNumCalcValue; + +typedef enum { + RNCNAME, RNCNUMBER, RNCEND, RNCINC, RNCDEC, + RNCPLUS='+', RNCMINUS='-', RNCMUL='*', RNCDIV='/', RNCMOD='%', + //RNCXOR='^', RNCOR='|', RNCAND='&', + RNCNEG='~', RNCAND='&', RNCORR='|', RNCXOR='^', + RNCPRINT=';', RNCASSIGN='=', RNCLEFTP='(', RNCRIGHTP=')', + RNCSHL='<', RNCSHR = '>', RNCROL = '#', RNCROR = '$' +} RNumCalcToken; + +typedef struct rz_num_calc_t { + RNumCalcToken curr_tok; + RNumCalcValue number_value; + char string_value[R_NUMCALC_STRSZ]; + int errors; + char oc; + const char *calc_err; + int calc_i; + const char *calc_buf; + int calc_len; + bool under_calc; +} RNumCalc; + +typedef struct rz_num_t { + ut64 (*callback)(struct rz_num_t *userptr, const char *str, int *ok); + const char *(*cb_from_value)(struct rz_num_t *userptr, ut64 value, int *ok); +// RNumCallback callback; + ut64 value; + double fvalue; + void *userptr; + int dbz; /// division by zero happened + RNumCalc nc; +} RNum; + +typedef ut64 (*RNumCallback)(struct rz_num_t *self, const char *str, int *ok); +typedef const char *(*RNumCallback2)(struct rz_num_t *self, ut64, int *ok); + +RZ_API RNum *rz_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr); +RZ_API void rz_num_free(RNum *num); +RZ_API char *rz_num_units(char *buf, size_t len, ut64 number); +RZ_API int rz_num_conditional(RNum *num, const char *str); +RZ_API ut64 rz_num_calc(RNum *num, const char *str, const char **err); +RZ_API const char *rz_num_calc_index(RNum *num, const char *p); +RZ_API ut64 rz_num_chs(int cylinder, int head, int sector, int sectorsize); +RZ_API int rz_num_is_valid_input(RNum *num, const char *input_value); +RZ_API ut64 rz_num_get_input_value(RNum *num, const char *input_value); +RZ_API const char *rz_num_get_name(RNum *num, ut64 n); +RZ_API char* rz_num_as_string(RNum *___, ut64 n, bool printable_only); +RZ_API ut64 rz_num_tail(RNum *num, ut64 addr, const char *hex); +RZ_API ut64 rz_num_tail_base(RNum *num, ut64 addr, ut64 off); +RZ_API void rz_num_minmax_swap(ut64 *a, ut64 *b); +RZ_API void rz_num_minmax_swap_i(int *a, int *b); // XXX this can be a cpp macro :?? +RZ_API ut64 rz_num_math(RNum *num, const char *str); +RZ_API ut64 rz_num_get(RNum *num, const char *str); +RZ_API int rz_num_to_bits(char *out, ut64 num); +RZ_API int rz_num_to_trits(char *out, ut64 num); //Rename this please +RZ_API int rz_num_rand(int max); +RZ_API void rz_num_irand(void); +RZ_API ut16 rz_num_ntohs(ut16 foo); +RZ_API ut64 rz_get_input_num_value(RNum *num, const char *input_value); +RZ_API bool rz_is_valid_input_num_value(RNum *num, const char *input_value); +RZ_API int rz_num_between(RNum *num, const char *input_value); +RZ_API bool rz_num_is_op(const char c); +RZ_API int rz_num_str_len(const char *str); +RZ_API int rz_num_str_split(char *str); +RZ_API RzList *rz_num_str_split_list(char *str); +RZ_API void *rz_num_dup(ut64 n); +RZ_API double rz_num_cos(double a); +RZ_API double rz_num_sin(double a); +RZ_API double rz_num_get_float(RNum *num, const char *str); + +static inline st64 rz_num_abs(st64 num) { + return num < 0 ? -num : num; +} + +#ifdef __cplusplus +} +#endif + +#endif // R_NUM_H diff --git a/libr/include/r_util/r_panels.h b/librz/include/rz_util/rz_panels.h similarity index 90% rename from libr/include/r_util/r_panels.h rename to librz/include/rz_util/rz_panels.h index 52e294db57..117403cd3f 100644 --- a/libr/include/r_util/r_panels.h +++ b/librz/include/rz_util/rz_panels.h @@ -27,14 +27,14 @@ typedef void (*RPanelDirectionCallback)(void *user, int direction); typedef void (*RPanelRotateCallback)(void *user, bool rev); typedef void (*RPanelPrintCallback)(void *user, void *p); -typedef struct r_panel_pos_t { +typedef struct rz_panel_pos_t { int x; int y; int w; int h; } RPanelPos; -typedef struct r_panel_model_t { +typedef struct rz_panel_model_t { RPanelDirectionCallback directionCb; RPanelRotateCallback rotateCb; RPanelPrintCallback print_cb; @@ -52,7 +52,7 @@ typedef struct r_panel_model_t { int rotate; } RPanelModel; -typedef struct r_panel_view_t { +typedef struct rz_panel_view_t { RPanelPos pos; RPanelPos prevPos; int sx; @@ -62,7 +62,7 @@ typedef struct r_panel_view_t { int edge; } RPanelView; -typedef struct r_panel_t { +typedef struct rz_panel_t { RPanelModel *model; RPanelView *view; } RPanel; diff --git a/libr/include/r_util/r_pkcs7.h b/librz/include/rz_util/rz_pkcs7.h similarity index 68% rename from libr/include/r_util/r_pkcs7.h rename to librz/include/rz_util/rz_pkcs7.h index a5ec9dbd84..7b9554c0a0 100644 --- a/libr/include/r_util/r_pkcs7.h +++ b/librz/include/rz_util/rz_pkcs7.h @@ -5,42 +5,42 @@ extern "C" { #endif -typedef struct r_pkcs7_certificaterevocationlists_t { +typedef struct rz_pkcs7_certificaterevocationlists_t { ut32 length; RX509CertificateRevocationList **elements; } RPKCS7CertificateRevocationLists; -typedef struct r_pkcs7_extendedcertificatesandcertificates_t { +typedef struct rz_pkcs7_extendedcertificatesandcertificates_t { ut32 length; RX509Certificate **elements; } RPKCS7ExtendedCertificatesAndCertificates; -typedef struct r_pkcs7_digestalgorithmidentifiers_t { +typedef struct rz_pkcs7_digestalgorithmidentifiers_t { ut32 length; RX509AlgorithmIdentifier **elements; } RPKCS7DigestAlgorithmIdentifiers; -typedef struct r_pkcs7_contentinfo_t { +typedef struct rz_pkcs7_contentinfo_t { RASN1String *contentType; //OID RASN1Binary *content; // optional. oid structure definition } RPKCS7ContentInfo; -typedef struct r_pkcs7_issuerandserialnumber_t { +typedef struct rz_pkcs7_issuerandserialnumber_t { RX509Name issuer; RASN1Binary *serialNumber; } RPKCS7IssuerAndSerialNumber; -typedef struct r_pkcs7_attribute_t { +typedef struct rz_pkcs7_attribute_t { RASN1String *oid; //OID RASN1Binary *data; // optional. oid structure definition } RPKCS7Attribute; -typedef struct r_pkcs7_attributes_t { +typedef struct rz_pkcs7_attributes_t { ut32 length; RPKCS7Attribute **elements; } RPKCS7Attributes; -typedef struct r_pkcs7_signerinfo_t { +typedef struct rz_pkcs7_signerinfo_t { ut32 version; RPKCS7IssuerAndSerialNumber issuerAndSerialNumber; RX509AlgorithmIdentifier digestAlgorithm; @@ -50,12 +50,12 @@ typedef struct r_pkcs7_signerinfo_t { RPKCS7Attributes unauthenticatedAttributes; //Optional } RPKCS7SignerInfo; -typedef struct r_pkcs7_signerinfos_t { +typedef struct rz_pkcs7_signerinfos_t { ut32 length; RPKCS7SignerInfo **elements; } RPKCS7SignerInfos; -typedef struct r_pkcs7_signeddata_t { +typedef struct rz_pkcs7_signeddata_t { ut32 version; RPKCS7DigestAlgorithmIdentifiers digestAlgorithms; RPKCS7ContentInfo contentInfo; @@ -64,7 +64,7 @@ typedef struct r_pkcs7_signeddata_t { RPKCS7SignerInfos signerinfos; } RPKCS7SignedData; -typedef struct r_pkcs7_container_t { +typedef struct rz_pkcs7_container_t { RASN1String *contentType; RPKCS7SignedData signedData; } RCMS; @@ -84,12 +84,12 @@ typedef struct { SpcDigestInfo messageDigest; } SpcIndirectDataContent; -R_API RCMS *r_pkcs7_parse_cms(const ut8 *buffer, ut32 length); -R_API void r_pkcs7_free_cms(RCMS* container); -R_API char *r_pkcs7_cms_to_string(RCMS* container); -R_API PJ *r_pkcs7_cms_json(RCMS* container); -R_API SpcIndirectDataContent *r_pkcs7_parse_spcinfo(RCMS *cms); -R_API void r_pkcs7_free_spcinfo(SpcIndirectDataContent *spcinfo); +RZ_API RCMS *rz_pkcs7_parse_cms(const ut8 *buffer, ut32 length); +RZ_API void rz_pkcs7_free_cms(RCMS* container); +RZ_API char *rz_pkcs7_cms_to_string(RCMS* container); +RZ_API PJ *rz_pkcs7_cms_json(RCMS* container); +RZ_API SpcIndirectDataContent *rz_pkcs7_parse_spcinfo(RCMS *cms); +RZ_API void rz_pkcs7_free_spcinfo(SpcIndirectDataContent *spcinfo); #ifdef __cplusplus } diff --git a/librz/include/rz_util/rz_pool.h b/librz/include/rz_util/rz_pool.h new file mode 100644 index 0000000000..6fd402efed --- /dev/null +++ b/librz/include/rz_util/rz_pool.h @@ -0,0 +1,25 @@ +#ifndef R_POOL_H +#define R_POOL_H +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_mem_pool_factory_t { + int limit; + RMemoryPool **pools; +} RPoolFactory; + +RZ_API RPoolFactory *rz_poolfactory_instance(void); +RZ_API void rz_poolfactory_init (int limit); +RZ_API RPoolFactory* rz_poolfactory_new(int limit); +RZ_API void *rz_poolfactory_alloc(RPoolFactory *pf, int nodesize); +RZ_API void rz_poolfactory_stats(RPoolFactory *pf); +RZ_API void rz_poolfactory_free(RPoolFactory *pf); + +#ifdef __cplusplus +} +#endif + +#endif // R_POOL_H diff --git a/librz/include/rz_util/rz_print.h b/librz/include/rz_util/rz_print.h new file mode 100644 index 0000000000..99fe2f88f0 --- /dev/null +++ b/librz/include/rz_util/rz_print.h @@ -0,0 +1,237 @@ +#ifndef R2_PRINT_H +#define R2_PRINT_H + +#include "rz_types.h" +#include "rz_cons.h" +#include "rz_bind.h" +#include "rz_io.h" +#include "rz_reg.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define R_PRINT_FLAGS_COLOR 0x00000001 +#define R_PRINT_FLAGS_ADDRMOD 0x00000002 +#define R_PRINT_FLAGS_CURSOR 0x00000004 +#define R_PRINT_FLAGS_HEADER 0x00000008 +#define R_PRINT_FLAGS_SPARSE 0x00000010 +#define R_PRINT_FLAGS_SEGOFF 0x00000020 +#define R_PRINT_FLAGS_OFFSET 0x00000040 +#define R_PRINT_FLAGS_REFS 0x00000080 +#define R_PRINT_FLAGS_DIFFOUT 0x00000100 /* only show different rows in `cc` hexdiffing */ +#define R_PRINT_FLAGS_ADDRDEC 0x00000200 +#define R_PRINT_FLAGS_COMMENT 0x00000400 +#define R_PRINT_FLAGS_COMPACT 0x00000800 +#define R_PRINT_FLAGS_NONHEX 0x00001000 +#define R_PRINT_FLAGS_SECSUB 0x00002000 +#define R_PRINT_FLAGS_RAINBOW 0x00004000 +#define R_PRINT_FLAGS_HDROFF 0x00008000 +#define R_PRINT_FLAGS_STYLE 0x00010000 +#define R_PRINT_FLAGS_NONASCII 0x00020000 +#define R_PRINT_FLAGS_ALIGN 0x00040000 +#define R_PRINT_FLAGS_UNALLOC 0x00080000 +#define R_PRINT_FLAGS_BGFILL 0x00100000 +#define R_PRINT_FLAGS_SECTION 0x00200000 + +typedef int (*RPrintZoomCallback)(void *user, int mode, ut64 addr, ut8 *bufz, ut64 size); +typedef const char *(*RPrintNameCallback)(void *user, ut64 addr); +typedef int (*RPrintSizeCallback)(void *user, ut64 addr); +typedef char *(*RPrintCommentCallback)(void *user, ut64 addr); +typedef const char *(*RPrintSectionGet)(void *user, ut64 addr); +typedef const char *(*RPrintColorFor)(void *user, ut64 addr, bool verbose); +typedef char *(*RPrintHasRefs)(void *user, ut64 addr, bool verbose); + +typedef struct rz_print_zoom_t { + ut8 *buf; + ut64 from; + ut64 to; + int size; + int mode; +} RPrintZoom; + +typedef struct rz_print_t { + void *user; + RzIOBind iob; + bool pava; + RzCoreBind coreb; + const char *cfmt; + char datefmt[32]; + int datezone; + int (*write)(const unsigned char *buf, int len); + PrintfCallback cb_printf; + PrintfCallback cb_eprintf; + char *(*cb_color)(int idx, int last, bool bg); + bool scr_prompt; + int (*disasm)(void *p, ut64 addr); + PrintfCallback oprintf; + int big_endian; + int width; + int limit; + int bits; + bool histblock; + // true if the cursor is enabled, false otherwise + bool cur_enabled; + // offset of the selected byte from the first displayed one + int cur; + // offset of the selected byte from the first displayed one, when a + // range of bytes is selected. -1 is used if no bytes are selected. + int ocur; + int cols; + int flags; + int seggrn; + bool use_comments; + int addrmod; + int col; + int stride; + int bytespace; + int pairs; + bool resetbg; + RPrintZoom *zoom; + RPrintNameCallback offname; + RPrintSizeCallback offsize; + RPrintColorFor colorfor; + RPrintHasRefs hasrefs; + RPrintCommentCallback get_comments; + RPrintSectionGet get_section_name; + Sdb *formats; + Sdb *sdb_types; + RzCons *cons; + RzConsBind consbind; + RNum *num; + RzReg *reg; + RzRegItem* (*get_register)(RzReg *reg, const char *name, int type); + ut64 (*get_register_value)(RzReg *reg, RzRegItem *item); + bool (*exists_var)(struct rz_print_t *print, ut64 func_addr, char *str); + ut64* lines_cache; + int lines_cache_sz; + int lines_abs; + bool esc_bslash; + bool wide_offsets; + const char *strconv_mode; + RzList *vars; + char io_unalloc_ch; + bool show_offset; + + // when true it uses row_offsets + bool calc_row_offsets; + // offset of the first byte of each printed row. + // Last elements is marked with a UT32_MAX. + ut32 *row_offsets; + // size of row_offsets + int row_offsets_sz; + // when true it makes visual mode flush the buffer to screen + bool vflush; + // represents the first not-visible offset on the screen + // (only when in visual disasm mode) + ut64 screen_bounds; +} RPrint; + +#ifdef RZ_API + +/* RzConsBreak handlers */ +typedef bool (*RPrintIsInterruptedCallback)(); + +RZ_API bool rz_print_is_interrupted(void); +RZ_API void rz_print_set_is_interrupted_cb(RPrintIsInterruptedCallback cb); + +/* ... */ +RZ_API char *rz_print_hexpair(RPrint *p, const char *str, int idx); +RZ_API void rz_print_hex_from_bin(RPrint *p, char *bin_str); +RZ_API RPrint *rz_print_new(void); +RZ_API RPrint *rz_print_free(RPrint *p); +RZ_API bool rz_print_mute(RPrint *p, int x); +RZ_API void rz_print_set_flags(RPrint *p, int _flags); +RZ_API void rz_print_unset_flags(RPrint *p, int flags); +RZ_API void rz_print_addr(RPrint *p, ut64 addr); +RZ_API void rz_print_section(RPrint *p, ut64 at); +RZ_API void rz_print_columns(RPrint *p, const ut8 *buf, int len, int height); +RZ_API void rz_print_hexii(RPrint *p, ut64 addr, const ut8 *buf, int len, int step); +RZ_API void rz_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step, size_t zoomsz); +RZ_API void rz_print_hexdump_simple(const ut8 *buf, int len); +RZ_API int rz_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize); +RZ_API void rz_print_hexpairs(RPrint *p, ut64 addr, const ut8 *buf, int len); +RZ_API void rz_print_hexdiff(RPrint *p, ut64 aa, const ut8* a, ut64 ba, const ut8 *b, int len, int scndcol); +RZ_API void rz_print_bytes(RPrint *p, const ut8* buf, int len, const char *fmt); +RZ_API void rz_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step); +RZ_API void rz_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch); +RZ_API const char *rz_print_byte_color(RPrint *p, int ch); +RZ_API void rz_print_c(RPrint *p, const ut8 *str, int len); +RZ_API void rz_print_raw(RPrint *p, ut64 addr, const ut8* buf, int len, int offlines); +RZ_API bool rz_print_have_cursor(RPrint *p, int cur, int len); +RZ_API bool rz_print_cursor_pointer(RPrint *p, int cur, int len); +RZ_API void rz_print_cursor(RPrint *p, int cur, int len, int set); +RZ_API void rz_print_cursor_range(RPrint *p, int cur, int to, int set); +RZ_API int rz_print_get_cursor(RPrint *p); +RZ_API void rz_print_set_cursor(RPrint *p, int curset, int ocursor, int cursor); +RZ_API void rz_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang); +#define SEEFLAG -2 +#define JSONOUTPUT -3 + +/* mode values for rz_print_format_* API */ +#define R_PRINT_MUSTSEE (1) // enable printing of data in specified fmt +#define R_PRINT_ISFIELD (1 << 1) +#define R_PRINT_SEEFLAGS (1 << 2) +#define R_PRINT_JSON (1 << 3) +#define R_PRINT_MUSTSET (1 << 4) +#define R_PRINT_UNIONMODE (1 << 5) +#define R_PRINT_VALUE (1 << 6) +#define R_PRINT_DOT (1 << 7) +#define R_PRINT_QUIET (1 << 8) +#define R_PRINT_STRUCT (1 << 9) +RZ_API int rz_print_format_struct_size(RPrint *p, const char *format, int mode, int n); +RZ_API int rz_print_format(RPrint *p, ut64 seek, const ut8* buf, const int len, const char *fmt, int elem, const char *setval, char *field); +RZ_API const char *rz_print_format_byname(RPrint *p, const char *name); +RZ_API void rz_print_offset(RPrint *p, ut64 off, int invert, int opt, int dec, int delta, const char *label); +RZ_API void rz_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int seggrn, int offdec, int delta, const char *label); +#define R_PRINT_STRING_WIDE 1 +#define R_PRINT_STRING_ZEROEND 2 +#define R_PRINT_STRING_URLENCODE 4 +#define R_PRINT_STRING_WRAP 8 +#define R_PRINT_STRING_WIDE32 16 +#define R_PRINT_STRING_ESC_NL 32 +RZ_API int rz_print_string(RPrint *p, ut64 seek, const ut8 *str, int len, int options); +RZ_API int rz_print_date_dos(RPrint *p, const ut8 *buf, int len); +RZ_API int rz_print_date_hfs(RPrint *p, const ut8 *buf, int len); +RZ_API int rz_print_date_w32(RPrint *p, const ut8 *buf, int len); +RZ_API int rz_print_date_unix(RPrint *p, const ut8 *buf, int len); +RZ_API int rz_print_date_get_now(RPrint *p, char *str); +RZ_API void rz_print_zoom(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen); +RZ_API void rz_print_zoom_buf(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen); +RZ_API void rz_print_progressbar(RPrint *pr, int pc, int _cols); +RZ_API void rz_print_portionbar(RPrint *p, const ut64 *portions, int n_portions); +RZ_API void rz_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 max, int cols); +RZ_API char * rz_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr); +RZ_API void rz_print_2bpp_row(RPrint *p, ut8 *buf); +RZ_API void rz_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles); +RZ_API char * rz_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr); +RZ_API const char * rz_print_color_op_type(RPrint *p, ut32 anal_type); +RZ_API void rz_print_set_interrupted(int i); +RZ_API void rz_print_init_rowoffsets(RPrint *p); +RZ_API ut32 rz_print_rowoff(RPrint *p, int i); +RZ_API void rz_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite); +RZ_API int rz_print_row_at_off(RPrint *p, ut32 offset); +RZ_API int rz_print_pie(RPrint *p, ut64 *values, int nvalues, int size); + +RZ_API const char* rz_print_rowlog(RPrint *print, const char *str); +RZ_API void rz_print_rowlog_done(RPrint *print, const char *str); + +// WIP +RZ_API int rz_print_unpack7bit(const char *src, char *dest); +RZ_API int rz_print_pack7bit(const char *src, char *dest); +RZ_API char *rz_print_stereogram_bytes(const ut8 *buf, int len); +RZ_API char *rz_print_stereogram(const char *bump, int w, int h); +RZ_API void rz_print_stereogram_print(RPrint *p, const char *buf); +RZ_API void rz_print_set_screenbounds(RPrint *p, ut64 addr); +RZ_API int rz_util_lines_getline(ut64 *lines_cache, int lines_cache_sz, ut64 off); +RZ_API char* rz_print_json_indent(const char* s, bool color, const char *tab, const char **colors); +RZ_API char* rz_print_json_human(const char* s); +RZ_API char* rz_print_json_path(const char* s, int pos); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_util/r_protobuf.h b/librz/include/rz_util/rz_protobuf.h similarity index 63% rename from libr/include/r_util/r_protobuf.h rename to librz/include/rz_util/rz_protobuf.h index 43f97a42e3..9f3682c34e 100644 --- a/libr/include/r_util/r_protobuf.h +++ b/librz/include/rz_util/rz_protobuf.h @@ -5,7 +5,7 @@ extern "C" { #endif -R_API char *r_protobuf_decode(const ut8* buffer, const ut64 size, bool debug); +RZ_API char *rz_protobuf_decode(const ut8* buffer, const ut64 size, bool debug); #ifdef __cplusplus } diff --git a/librz/include/rz_util/rz_punycode.h b/librz/include/rz_util/rz_punycode.h new file mode 100644 index 0000000000..9be3a73f71 --- /dev/null +++ b/librz/include/rz_util/rz_punycode.h @@ -0,0 +1,15 @@ +#ifndef R_PUNYCODE_H +#define R_PUNYCODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +RZ_API char *rz_punycode_encode(const ut8 *src, int srclen, int *dstlen); +RZ_API char *rz_punycode_decode(const char *src, int srclen, int *dstlen); + +#ifdef __cplusplus +} +#endif + +#endif // R_PUNYCODE_H diff --git a/librz/include/rz_util/rz_queue.h b/librz/include/rz_util/rz_queue.h new file mode 100644 index 0000000000..71124dfc96 --- /dev/null +++ b/librz/include/rz_util/rz_queue.h @@ -0,0 +1,26 @@ +#ifndef R_QUEUE_H +#define R_QUEUE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct rz_queue_t { + void **elems; + unsigned int capacity; + unsigned int front; + int rear; + unsigned int size; +} RQueue; + +RZ_API RQueue *rz_queue_new(int n); +RZ_API void rz_queue_free(RQueue *q); +RZ_API int rz_queue_enqueue(RQueue *q, void *el); +RZ_API void *rz_queue_dequeue(RQueue *q); +RZ_API int rz_queue_is_empty(RQueue *q); + +#ifdef __cplusplus +} +#endif + +#endif // R_QUEUE_H diff --git a/librz/include/rz_util/rz_range.h b/librz/include/rz_util/rz_range.h new file mode 100644 index 0000000000..295a492581 --- /dev/null +++ b/librz/include/rz_util/rz_range.h @@ -0,0 +1,44 @@ +#ifndef R_RANGE_H +#define R_RANGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* range.c */ + +typedef struct rz_range_item_t { + ut64 fr; + ut64 to; + ut8 *data; + int datalen; +} RRangeItem; + +typedef struct rz_range_t { + int count; + int changed; + RzList *ranges; +} RRange; + +RZ_API RRange *rz_range_new(void); +RZ_API RRange *rz_range_new_from_string(const char *string); +RZ_API RRange *rz_range_free(RRange *r); +RZ_API RRangeItem *rz_range_item_get(RRange *r, ut64 addr); +RZ_API ut64 rz_range_size(RRange *r); +RZ_API int rz_range_add_from_string(RRange *rgs, const char *string); +RZ_API RRangeItem *rz_range_add(RRange *rgs, ut64 from, ut64 to, int rw); +RZ_API int rz_range_sub(RRange *rgs, ut64 from, ut64 to); +RZ_API void rz_range_merge(RRange *rgs, RRange *r); +RZ_API int rz_range_contains(RRange *rgs, ut64 addr); +RZ_API int rz_range_sort(RRange *rgs); +RZ_API void rz_range_percent(RRange *rgs); +RZ_API int rz_range_list(RRange *rgs, int rad); +RZ_API int rz_range_get_n(RRange *rgs, int n, ut64 *from, ut64 *to); +RZ_API RRange *rz_range_inverse(RRange *rgs, ut64 from, ut64 to, int flags); +RZ_API int rz_range_overlap(ut64 a0, ut64 a1, ut64 b0, ut64 b1, int *d); + +#ifdef __cplusplus +} +#endif + +#endif // R_RANGE_H diff --git a/librz/include/rz_util/rz_rbtree.h b/librz/include/rz_util/rz_rbtree.h new file mode 100644 index 0000000000..186e7b49d5 --- /dev/null +++ b/librz/include/rz_util/rz_rbtree.h @@ -0,0 +1,126 @@ +#ifndef R2_RBTREE_H +#define R2_RBTREE_H + +#include +#include +#include + +#include "rz_list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// max height <= 2 * floor(log2(n + 1)) +// We use `int` for size, so <= 2 * 31 +#define R_RBTREE_MAX_HEIGHT 62 + +// Singleton can be zero initialized +typedef struct rz_rb_node_t { + struct rz_rb_node_t *child[2]; + bool red; +} RBNode; + +typedef RBNode* RBTree; + +// incoming < in_tree => return < 0 +// incoming == in_tree => return == 0 +// incoming > in_tree => return > 0 +typedef int (*RBComparator)(const void *incoming, const RBNode *in_tree, void *user); + +typedef void (*RBNodeFree)(RBNode *node, void *user); +typedef void (*RBNodeSum)(RBNode *node); + +typedef struct rz_rb_iter_t { + // current depth + // if len == 0, the iterator is at the end/empty + // else path[len-1] is the current node + int len; + + // current path from root to the current node + // excluding nodes into whose right (or left, for reverse iteration) branch the iterator has descended + // (these nodes are before the current) + RBNode *path[R_RBTREE_MAX_HEIGHT]; +} RBIter; + +typedef int (*RContRBCmp)(void *incoming, void *in, void *user); +typedef void (*RContRBFree)(void *); +typedef struct rz_containing_rb_node_t { + RBNode node; + void *data; +} RContRBNode; + +typedef struct rz_containing_rb_tree_t { + RContRBNode *root; + RContRBFree free; +} RContRBTree; + +// Routines for augmented red-black trees. The user should provide an aggregation (monoid sum) callback `sum` +// to calculate extra information such as size, sum, ... +RZ_API bool rz_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user, RBNodeSum sum); +RZ_API bool rz_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum); +RZ_API bool rz_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum); + +RZ_API bool rz_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user); +RZ_API RBNode *rz_rbtree_find(RBNode *root, void *data, RBComparator cmp, void *user); +RZ_API void rz_rbtree_free(RBNode *root, RBNodeFree freefn, void *user); +RZ_API void rz_rbtree_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *user); +// Return the smallest node that is greater than or equal to `data` +RZ_API RBNode *rz_rbtree_lower_bound(RBNode *root, void *data, RBComparator cmp, void *user); +// Return the greatest node that is less than or equal to `data` +RZ_API RBNode *rz_rbtree_upper_bound(RBNode *root, void *data, RBComparator cmp, void *user); + +// Create a forward iterator starting from the leftmost node +RZ_API RBIter rz_rbtree_first(RBNode *root); +// Create a backward iterator starting from the rightmost node +RZ_API RBIter rz_rbtree_last(RBNode *root); + +// Iterate [lower_bound, end] forward, used with rz_rbtree_iter_next +RZ_API RBIter rz_rbtree_lower_bound_forward(RBNode *root, void *data, RBComparator cmp, void *user); +// Iterate [begin, upper_bound] backward, used with rz_rbtree_iter_prev +RZ_API RBIter rz_rbtree_upper_bound_backward(RBNode *root, void *data, RBComparator cmp, void *user); + +// struct Node { int key; RBNode rb; }; +// rz_rbtree_iter_get (it, struct Node, rb) +#define rz_rbtree_iter_get(it, struc, rb) (container_of ((it)->path[(it)->len-1], struc, rb)) +// If the iterator still contains elements, including the current +#define rz_rbtree_iter_has(it) ((it)->len) +// Move forward +RZ_API void rz_rbtree_iter_next(RBIter *it); +// Move backward +RZ_API void rz_rbtree_iter_prev(RBIter *it); + +// Iterate all elements of the forward iterator +#define rz_rbtree_iter_while(it, data, struc, rb) \ + for (; rz_rbtree_iter_has(&it) && (data = rz_rbtree_iter_get (&it, struc, rb)); rz_rbtree_iter_next (&(it))) + +// Iterate all elements of the backward iterator +#define rz_rbtree_iter_while_prev(it, data, struc, rb) \ + for (; rz_rbtree_iter_has(&it) && (data = rz_rbtree_iter_get (&it, struc, rb)); rz_rbtree_iter_prev (&(it))) + +#define rz_rbtree_foreach(root, it, data, struc, rb) \ + for ((it) = rz_rbtree_first (root); rz_rbtree_iter_has(&it) && (data = rz_rbtree_iter_get (&it, struc, rb)); rz_rbtree_iter_next (&(it))) + +#define rz_rbtree_foreach_prev(root, it, data, struc, rb) \ + for ((it) = rz_rbtree_last (root); rz_rbtree_iter_has(&it) && (data = rz_rbtree_iter_get (&it, struc, rb)); rz_rbtree_iter_prev (&(it))) + + +RZ_API RContRBTree *rz_rbtree_cont_new(void); +RZ_API RContRBTree *rz_rbtree_cont_newf(RContRBFree f); +RZ_API bool rz_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); +RZ_API bool rz_rbtree_cont_delete(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); +RZ_API void *rz_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user); + +#define rz_rbtree_cont_foreach(tree, it, dat) \ + for ((it) = rz_rbtree_first (&tree->root->node); rz_rbtree_iter_has(&it) && (dat = rz_rbtree_iter_get (&it, RContRBNode, node)->data); rz_rbtree_iter_next (&(it))) + +#define rz_rbtree_cont_foreach_prev(tree, it, dat) \ + for ((it) = rz_rbtree_last (&tree->root->node); rz_rbtree_iter_has(&it) && (dat = rz_rbtree_iter_get (&it, RContRBNode, node)->data); rz_rbtree_iter_prev (&(it))) + +RZ_API void rz_rbtree_cont_free(RContRBTree *tree); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/librz/include/rz_util/rz_sandbox.h b/librz/include/rz_util/rz_sandbox.h new file mode 100644 index 0000000000..7c74f5e0c5 --- /dev/null +++ b/librz/include/rz_util/rz_sandbox.h @@ -0,0 +1,49 @@ +#ifndef R_SANDBOX_H +#define R_SANDBOX_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __FreeBSD__ +#include + +#if __FreeBSD_version >= 1000000 +#define HAVE_CAPSICUM 1 +#else +#define HAVE_CAPSICUM 0 +#endif +#else +#define HAVE_CAPSICUM 0 +#endif +/** + * This function verifies that the given path is allowed. Paths are allowed only if they don't + * contain .. components (which would indicate directory traversal) and they are relative. + * Paths pointing into the webroot are an exception: For reaching the webroot, .. and absolute + * path are ok. + */ +#if __WINDOWS__ +RZ_API HANDLE rz_sandbox_opendir(const char *path, WIN32_FIND_DATAW *entry); +#else +RZ_API DIR* rz_sandbox_opendir(const char *path); +#endif +RZ_API int rz_sandbox_truncate(int fd, ut64 length); +RZ_API int rz_sandbox_lseek(int fd, ut64 addr, int mode); +RZ_API int rz_sandbox_close(int fd); +RZ_API int rz_sandbox_read(int fd, ut8 *buf, int len); +RZ_API int rz_sandbox_write(int fd, const ut8 *buf, int len); +RZ_API bool rz_sandbox_enable(bool e); +RZ_API bool rz_sandbox_disable(bool e); +RZ_API int rz_sandbox_system(const char *x, int fork); +RZ_API bool rz_sandbox_creat(const char *path, int mode); +RZ_API int rz_sandbox_open(const char *path, int mode, int perm); +RZ_API FILE *rz_sandbox_fopen(const char *path, const char *mode); +RZ_API int rz_sandbox_chdir(const char *path); +RZ_API bool rz_sandbox_check_path(const char *path); +RZ_API int rz_sandbox_kill(int pid, int sig); + +#ifdef __cplusplus +} +#endif + +#endif // R_SANDBOX_H diff --git a/libr/include/r_util/r_signal.h b/librz/include/rz_util/rz_signal.h similarity index 66% rename from libr/include/r_util/r_signal.h rename to librz/include/rz_util/rz_signal.h index f93b6322ed..f760627bed 100644 --- a/libr/include/r_util/r_signal.h +++ b/librz/include/rz_util/rz_signal.h @@ -10,14 +10,14 @@ extern "C" { #endif /* Returns atoi(str) if signal with `str` name not found. */ -R_API int r_signal_from_string (const char *str); +RZ_API int rz_signal_from_string (const char *str); /* Return NULL if signal with `code` not found. */ -R_API const char* r_signal_to_string (int code); +RZ_API const char* rz_signal_to_string (int code); // XXX this function should be portable, not-unix specific #if __UNIX__ -R_API void r_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask); +RZ_API void rz_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask); #endif #ifdef __cplusplus diff --git a/libr/include/r_util/r_spaces.h b/librz/include/rz_util/rz_spaces.h similarity index 64% rename from libr/include/r_util/r_spaces.h rename to librz/include/rz_util/rz_spaces.h index 469c48286c..b75c6e86d1 100644 --- a/libr/include/r_util/r_spaces.h +++ b/librz/include/rz_util/rz_spaces.h @@ -3,7 +3,7 @@ #define R_SPACES_MAX 512 -#include "r_util.h" +#include "rz_util.h" #ifdef __cplusplus extern "C" { @@ -23,7 +23,7 @@ extern "C" { * R_SPACE_EVENT_UNSET: called when deleting a RSpace with a given name */ -typedef struct r_space_t { +typedef struct rz_space_t { char *name; RBNode rb; } RSpace; @@ -34,7 +34,7 @@ typedef enum { R_SPACE_EVENT_UNSET, } RSpaceEventType; -typedef struct r_space_event_t { +typedef struct rz_space_event_t { union { struct { const RSpace *space; @@ -51,57 +51,57 @@ typedef struct r_space_event_t { int res; } RSpaceEvent; -typedef struct r_spaces_t { +typedef struct rz_spaces_t { const char *name; RSpace *current; RBTree spaces; - RList *spacestack; + RzList *spacestack; REvent *event; } RSpaces; // Create a new RSpaces with the given name -R_API RSpaces *r_spaces_new(const char *name); +RZ_API RSpaces *rz_spaces_new(const char *name); // Initialize an existing RSpaces with the given name -R_API bool r_spaces_init(RSpaces *sp, const char *name); +RZ_API bool rz_spaces_init(RSpaces *sp, const char *name); // Finalize an existing RSpaces -R_API void r_spaces_fini(RSpaces *sp); +RZ_API void rz_spaces_fini(RSpaces *sp); // Finalize and free an existing RSpaces -R_API void r_spaces_free(RSpaces *sp); +RZ_API void rz_spaces_free(RSpaces *sp); // Delete all spaces -R_API void r_spaces_purge(RSpaces *sp); +RZ_API void rz_spaces_purge(RSpaces *sp); // Get the RSpace with the given name -R_API RSpace *r_spaces_get(RSpaces *sp, const char *name); +RZ_API RSpace *rz_spaces_get(RSpaces *sp, const char *name); // Add a new RSpace if one does not already exist, otherwise return the existing one -R_API RSpace *r_spaces_add(RSpaces *sp, const char *name); +RZ_API RSpace *rz_spaces_add(RSpaces *sp, const char *name); // Add and select a new RSpace if one does not already exist, otherwise return and select the existing one -R_API RSpace *r_spaces_set(RSpaces *sp, const char *name); +RZ_API RSpace *rz_spaces_set(RSpaces *sp, const char *name); // Remove the RSpace with the given name or all of them if name is NULL -R_API bool r_spaces_unset(RSpaces *sp, const char *name); +RZ_API bool rz_spaces_unset(RSpaces *sp, const char *name); // Change the name of RSpace with oname to nname -R_API bool r_spaces_rename(RSpaces *sp, const char *oname, const char *nname); +RZ_API bool rz_spaces_rename(RSpaces *sp, const char *oname, const char *nname); // Count the elements that belong to the RSpace with the given name -R_API int r_spaces_count(RSpaces *sp, const char *name); +RZ_API int rz_spaces_count(RSpaces *sp, const char *name); // Add/Select the RSpace with the given name and save the current one in the history -R_API bool r_spaces_push(RSpaces *sp, const char *name); +RZ_API bool rz_spaces_push(RSpaces *sp, const char *name); // Select the RSpace that was set before the current one -R_API bool r_spaces_pop(RSpaces *sp); +RZ_API bool rz_spaces_pop(RSpaces *sp); -static inline RSpace *r_spaces_current(RSpaces *sp) { +static inline RSpace *rz_spaces_current(RSpaces *sp) { return sp->current; } -static inline const char *r_spaces_current_name(RSpaces *sp) { +static inline const char *rz_spaces_current_name(RSpaces *sp) { return sp->current? sp->current->name: "*"; } -static inline bool r_spaces_is_empty(RSpaces *sp) { - RBIter it = r_rbtree_first (sp->spaces); +static inline bool rz_spaces_is_empty(RSpaces *sp) { + RBIter it = rz_rbtree_first (sp->spaces); return it.len == 0; } typedef RBIter RSpaceIter; -#define r_spaces_foreach(sp, it, s) \ - r_rbtree_foreach ((sp)->spaces, (it), (s), RSpace, rb) +#define rz_spaces_foreach(sp, it, s) \ + rz_rbtree_foreach ((sp)->spaces, (it), (s), RSpace, rb) #ifdef __cplusplus } diff --git a/librz/include/rz_util/rz_stack.h b/librz/include/rz_util/rz_stack.h new file mode 100644 index 0000000000..7909822ab5 --- /dev/null +++ b/librz/include/rz_util/rz_stack.h @@ -0,0 +1,30 @@ +#ifndef R_STACK_H +#define R_STACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*RStackFree)(void *ptr); + +typedef struct rz_stack_t { + void **elems; + unsigned int n_elems; + int top; + RStackFree free; +} RStack; + +RZ_API RStack *rz_stack_new(ut32 n); +RZ_API void rz_stack_free(RStack *s); +RZ_API bool rz_stack_is_empty(RStack *s); +RZ_API RStack *rz_stack_newf(ut32 n, RStackFree f); +RZ_API bool rz_stack_push(RStack *s, void *el); +RZ_API void *rz_stack_pop(RStack *s); +RZ_API size_t rz_stack_size(RStack *s); +RZ_API void *rz_stack_peek(RStack *s); + +#ifdef __cplusplus +} +#endif + +#endif // R_STACK_H diff --git a/librz/include/rz_util/rz_str.h b/librz/include/rz_util/rz_str.h new file mode 100644 index 0000000000..41db16ffb1 --- /dev/null +++ b/librz/include/rz_util/rz_str.h @@ -0,0 +1,209 @@ +#ifndef R_STR_H +#define R_STR_H + +#include +#include "rz_str_util.h" +#include "rz_list.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + R_STRING_ENC_LATIN1 = 'a', + R_STRING_ENC_UTF8 = '8', + R_STRING_ENC_UTF16LE = 'u', + R_STRING_ENC_UTF32LE = 'U', + R_STRING_ENC_UTF16BE = 'b', + R_STRING_ENC_UTF32BE = 'B', + R_STRING_ENC_GUESS = 'g', +} RStrEnc; + +typedef int (*RStrRangeCallback) (void *, int); + +#define R_STR_ISEMPTY(x) (!(x) || !*(x)) +#define R_STR_ISNOTEMPTY(x) ((x) && *(x)) +#define R_STR_DUP(x) ((x) ? strdup ((x)) : NULL) +#define rz_str_array(x,y) ((y>=0 && y<(sizeof(x)/sizeof(*x)))?x[y]:"") +RZ_API char *rz_str_repeat(const char *ch, int sz); +RZ_API const char *rz_str_pad(const char ch, int len); +RZ_API const char *rz_str_rstr(const char *base, const char *p); +RZ_API const char *rz_strstr_ansi (const char *a, const char *b); +RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch); +RZ_API const char *rz_str_closer_chr(const char *b, const char *s); +RZ_API int rz_str_bounds(const char *str, int *h); +RZ_API char *rz_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2); +RZ_API char *rz_str_scale(const char *r, int w, int h); +RZ_API bool rz_str_range_in(const char *r, ut64 addr); +RZ_API size_t rz_str_len_utf8(const char *s); +RZ_API size_t rz_str_len_utf8_ansi(const char *str); +RZ_API size_t rz_str_len_utf8char(const char *s, int left); +RZ_API size_t rz_str_utf8_charsize(const char *str); +RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len); +RZ_API size_t rz_str_utf8_charsize_last(const char *str); +RZ_API void rz_str_filter_zeroline(char *str, int len); +RZ_API size_t rz_str_utf8_codepoint(const char *s, size_t left); +RZ_API bool rz_str_char_fullwidth(const char *s, size_t left); +RZ_API int rz_str_write(int fd, const char *b); +RZ_API void rz_str_ncpy(char *dst, const char *src, size_t n); +RZ_API void rz_str_sanitize(char *c); +RZ_API char *rz_str_sanitize_sdb_key(const char *s); +RZ_API const char *rz_str_casestr(const char *a, const char *b); +RZ_API const char *rz_str_firstbut(const char *s, char ch, const char *but); +RZ_API const char *rz_str_lastbut(const char *s, char ch, const char *but); +RZ_API int rz_str_split(char *str, char ch); +RZ_API RzList *rz_str_split_list(char *str, const char *c, int n); +RZ_API RzList *rz_str_split_duplist(const char *str, const char *c, bool trim); +RZ_API size_t *rz_str_split_lines(char *str, size_t *count); +RZ_API char* rz_str_replace(char *str, const char *key, const char *val, int g); +RZ_API char *rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case); +RZ_API char *rz_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g); +#define rz_str_cpy(x,y) memmove ((x), (y), strlen (y) + 1); +#define rz_str_cat(x,y) memmove ((x) + strlen (x), (y), strlen (y) + 1); +RZ_API int rz_str_bits(char *strout, const ut8 *buf, int len, const char *bitz); +RZ_API int rz_str_bits64(char *strout, ut64 in); +RZ_API ut64 rz_str_bits_from_string(const char *buf, const char *bitz); +RZ_API int rz_str_rwx(const char *str); +RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g); +RZ_API int rz_str_replace_char(char *s, int a, int b); +RZ_API int rz_str_replace_char_once(char *s, int a, int b); +RZ_API void rz_str_remove_char(char *str, char c); +RZ_API const char *rz_str_rwx_i(int rwx); +RZ_API int rz_str_fmtargs(const char *fmt); +RZ_API char *rz_str_arg_escape(const char *arg); +RZ_API int rz_str_arg_unescape(char *arg); +RZ_API char **rz_str_argv(const char *str, int *_argc); +RZ_API void rz_str_argv_free(char **argv); +RZ_API char *rz_str_new(const char *str); +RZ_API int rz_snprintf (char *string, int len, const char *fmt, ...)R_PRINTF_CHECK(3, 4); +RZ_API bool rz_str_is_ascii(const char *str); +RZ_API char *rz_str_nextword(char *s, char ch); +RZ_API bool rz_str_is_printable(const char *str); +RZ_API bool rz_str_is_printable_limited(const char *str, int size); +RZ_API bool rz_str_is_printable_incl_newlines(const char *str); +RZ_API char *rz_str_appendlen(char *ptr, const char *string, int slen); +RZ_API char *rz_str_newf(const char *fmt, ...); +RZ_API char *rz_str_newlen(const char *str, int len); +RZ_API const char *rz_str_sysbits(const int v); +RZ_API char *rz_str_trunc_ellipsis(const char *str, int len); +RZ_API const char *rz_str_bool(int b); +RZ_API bool rz_str_is_true(const char *s); +RZ_API bool rz_str_is_false(const char *s); +RZ_API bool rz_str_is_bool(const char *val); +RZ_API const char *rz_str_ansi_chrn(const char *str, size_t n); +RZ_API size_t rz_str_ansi_len(const char *str); +RZ_API size_t rz_str_ansi_nlen(const char *str, size_t len); +RZ_API int rz_str_ansi_trim(char *str, int str_len, int n); +RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len); +RZ_API char *rz_str_ansi_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2); +RZ_API int rz_str_word_count(const char *string); +RZ_API int rz_str_char_count(const char *string, char ch); +RZ_API char *rz_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen); +RZ_API int rz_str_word_set0(char *str); +RZ_API int rz_str_word_set0_stack(char *str); +RZ_API const char *rz_str_word_get0(const char *str, int idx); +RZ_API char *rz_str_word_get_first(const char *string); +RZ_API void rz_str_trim(char *str); +RZ_API char *rz_str_trim_dup(const char *str); +RZ_API char *rz_str_trim_lines(char *str); +RZ_API void rz_str_trim_head(char *str); +RZ_API const char *rz_str_trim_head_ro(const char *str); +RZ_API const char *rz_str_trim_head_wp(const char *str); +RZ_API void rz_str_trim_tail(char *str); +RZ_API ut32 rz_str_hash(const char *str); +RZ_API ut64 rz_str_hash64(const char *str); +RZ_API char *rz_str_trim_nc(char *str); +RZ_API const char *rz_str_nstr(const char *from, const char *to, int size); +RZ_API const char *rz_str_lchr(const char *str, char chr); +RZ_API const char *rz_sub_str_lchr(const char *str, int start, int end, char chr); +RZ_API const char *rz_sub_str_rchr(const char *str, int start, int end, char chr); +RZ_API char *rz_str_ichr(char *str, char chr); +RZ_API bool rz_str_ccmp(const char *dst, const char *orig, int ch); +RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep); +RZ_API int rz_str_cmp(const char *dst, const char *orig, int len); +RZ_API int rz_str_casecmp(const char *dst, const char *orig); +RZ_API int rz_str_ncasecmp(const char *dst, const char *orig, size_t n); +RZ_API int rz_str_ccpy(char *dst, char *orig, int ch); +RZ_API const char *rz_str_get(const char *str); +RZ_API const char *rz_str_get2(const char *str); +RZ_API char *rz_str_ndup(const char *ptr, int len); +RZ_API char *rz_str_dup(char *ptr, const char *string); +RZ_API int rz_str_inject(char *begin, char *end, char *str, int maxlen); +RZ_API int rz_str_delta(char *p, char a, char b); +RZ_API void rz_str_filter(char *str, int len); +RZ_API const char * rz_str_tok(const char *str1, const char b, size_t len); +RZ_API wchar_t *rz_str_mb_to_wc(const char *buf); +RZ_API char *rz_str_wc_to_mb(const wchar_t *buf); +RZ_API wchar_t *rz_str_mb_to_wc_l(const char *buf, int len); +RZ_API char *rz_str_wc_to_mb_l(const wchar_t *buf, int len); +RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y); + +typedef void(*str_operation)(char *c); + +RZ_API int rz_str_do_until_token(str_operation op, char *str, const char tok); + +RZ_API void rz_str_reverse(char *str); +RZ_API int rz_str_re_match(const char *str, const char *reg); +RZ_API int rz_str_re_replace(const char *str, const char *reg, const char *sub); +RZ_API int rz_str_path_unescape(char *path); +RZ_API char *rz_str_path_escape(const char *path); +RZ_API int rz_str_unescape(char *buf); +RZ_API char *rz_str_escape(const char *buf); +RZ_API char *rz_str_escape_sh(const char *buf); +RZ_API char *rz_str_escape_dot(const char *buf); +RZ_API char *rz_str_escape_latin1(const char *buf, bool show_asciidot, bool esc_bslash, bool colors); +RZ_API char *rz_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bslash); +RZ_API char *rz_str_escape_utf8_keep_printable(const char *buf, bool show_asciidot, bool esc_bslash); // like escape_utf8 but leaves valid \uXXXX chars directly in utf-8 +RZ_API char *rz_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); +RZ_API char *rz_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); +RZ_API char *rz_str_escape_utf16be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); +RZ_API char *rz_str_escape_utf32be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash); +RZ_API void rz_str_byte_escape(const char *p, char **dst, int dot_nl, bool default_dot, bool esc_bslash); +RZ_API char *rz_str_format_msvc_argv(size_t argc, const char **argv); +RZ_API void rz_str_uri_decode(char *buf); +RZ_API char *rz_str_uri_encode(const char *buf); +RZ_API char *rz_str_utf16_decode(const ut8 *s, int len); +RZ_API int rz_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, int little_endian); +RZ_API char *rz_str_utf16_encode(const char *s, int len); +RZ_API char *rz_str_escape_utf8_for_json(const char *s, int len); +RZ_API char *rz_str_home(const char *str); +RZ_API char *rz_str_rz_prefix(const char *str); +RZ_API size_t rz_str_nlen(const char *s, int n); +RZ_API size_t rz_str_nlen_w(const char *s, int n); +RZ_API size_t rz_wstr_clen(const char *s); +RZ_API char *rz_str_prepend(char *ptr, const char *string); +RZ_API char *rz_str_prefix_all(const char *s, const char *pfx); +RZ_API char *rz_str_append(char *ptr, const char *string); +RZ_API char *rz_str_append_owned(char *ptr, char *string); +RZ_API char *rz_str_appendf(char *ptr, const char *fmt, ...) R_PRINTF_CHECK(2, 3); +RZ_API char *rz_str_appendch(char *x, char y); +RZ_API void rz_str_case(char *str, bool up); +RZ_API void rz_str_trim_path(char *s); +RZ_API ut8 rz_str_contains_macro(const char *input_value); +RZ_API void rz_str_truncate_cmd(char *string); +RZ_API char* rz_str_replace_thunked(char *str, char *clean, int *thunk, int clen, + const char *key, const char *val, int g); +RZ_API bool rz_str_glob(const char *str, const char *glob); +RZ_API int rz_str_binstr2bin(const char *str, ut8 *out, int outlen); +RZ_API char *rz_str_between(const char *str, const char *prefix, const char *suffix); +RZ_API bool rz_str_startswith(const char *str, const char *needle); +RZ_API bool rz_str_endswith(const char *str, const char *needle); +RZ_API bool rz_str_isnumber (const char *str); +RZ_API const char *rz_str_last (const char *in, const char *ch); +RZ_API char* rz_str_highlight(char *str, const char *word, const char *color, const char *color_reset); +RZ_API char *rz_qrcode_gen(const ut8 *text, int len, bool utf8, bool inverted); +RZ_API char *rz_str_from_ut64(ut64 val); +RZ_API void rz_str_stripLine(char *str, const char *key); +RZ_API char *rz_str_list_join(RzList *str, const char *sep); +RZ_API char *rz_str_array_join(const char **a, size_t n, const char *sep); + +RZ_API const char *rz_str_sep(const char *base, const char *sep); +RZ_API const char *rz_str_rsep(const char *base, const char *p, const char *sep); +RZ_API char *rz_str_donut(int size); +RZ_API char *rz_str_version(const char *program); + +#ifdef __cplusplus +} +#endif + +#endif // R_STR_H diff --git a/libr/include/r_util/r_str_constpool.h b/librz/include/rz_util/rz_str_constpool.h similarity index 58% rename from libr/include/r_util/r_str_constpool.h rename to librz/include/rz_util/rz_str_constpool.h index cec9a56e90..f0621f4c58 100644 --- a/libr/include/r_util/r_str_constpool.h +++ b/librz/include/rz_util/rz_str_constpool.h @@ -1,7 +1,7 @@ #ifndef R_STR_CONSTPOOL_H #define R_STR_CONSTPOOL_H -#include +#include #include #include @@ -15,13 +15,13 @@ extern "C" { * References to strings will be valid as long as the RStrConstPool is alive. */ -typedef struct r_str_constpool_t { +typedef struct rz_str_constpool_t { HtPP *ht; } RStrConstPool; -R_API bool r_str_constpool_init(RStrConstPool *pool); -R_API void r_str_constpool_fini(RStrConstPool *pool); -R_API const char *r_str_constpool_get(RStrConstPool *pool, const char *str); +RZ_API bool rz_str_constpool_init(RStrConstPool *pool); +RZ_API void rz_str_constpool_fini(RStrConstPool *pool); +RZ_API const char *rz_str_constpool_get(RStrConstPool *pool, const char *str); #ifdef __cplusplus } diff --git a/libr/include/r_util/r_str_util.h b/librz/include/rz_util/rz_str_util.h similarity index 100% rename from libr/include/r_util/r_str_util.h rename to librz/include/rz_util/rz_str_util.h diff --git a/librz/include/rz_util/rz_strbuf.h b/librz/include/rz_util/rz_strbuf.h new file mode 100644 index 0000000000..d8f1bb2fe1 --- /dev/null +++ b/librz/include/rz_util/rz_strbuf.h @@ -0,0 +1,48 @@ +#ifndef R_STRBUF_H +#define R_STRBUF_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char buf[32]; + size_t len; // string length in chars or binary buffer size + char *ptr; // ptr replacing buf in case strlen > sizeof(buf) + size_t ptrlen; // string length + 1 or binary buffer size + bool weakref; // ptr is not owned +} RStrBuf; + +#define R_STRBUF_SAFEGET(sb) (rz_strbuf_get (sb) ? rz_strbuf_get (sb) : "") +RZ_API RStrBuf *rz_strbuf_new(const char *s); +RZ_API const char *rz_strbuf_set(RStrBuf *sb, const char *s); // return = the string or NULL on fail +RZ_API bool rz_strbuf_slice(RStrBuf *sb, int from, int len); +RZ_API bool rz_strbuf_setbin(RStrBuf *sb, const ut8 *s, size_t len); +RZ_API ut8* rz_strbuf_getbin(RStrBuf *sb, int *len); +RZ_API const char *rz_strbuf_setf(RStrBuf *sb, const char *fmt, ...); // return = the string or NULL on fail +RZ_API const char *rz_strbuf_vsetf(RStrBuf *sb, const char *fmt, va_list ap); // return = the string or NULL on fail +RZ_API bool rz_strbuf_append(RStrBuf *sb, const char *s); +RZ_API bool rz_strbuf_append_n(RStrBuf *sb, const char *s, size_t l); +RZ_API bool rz_strbuf_prepend(RStrBuf *sb, const char *s); +RZ_API bool rz_strbuf_appendf(RStrBuf *sb, const char *fmt, ...); +RZ_API bool rz_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap); +RZ_API char *rz_strbuf_get(RStrBuf *sb); +RZ_API char *rz_strbuf_drain(RStrBuf *sb); +RZ_API char *rz_strbuf_drain_nofree(RStrBuf *sb); +RZ_API int rz_strbuf_length(RStrBuf *sb); +RZ_API int rz_strbuf_size(RStrBuf *sb); +RZ_API void rz_strbuf_free(RStrBuf *sb); +RZ_API void rz_strbuf_fini(RStrBuf *sb); +RZ_API void rz_strbuf_init(RStrBuf *sb); +RZ_API const char *rz_strbuf_initf(RStrBuf *sb, const char *fmt, ...); // same as init + setf for convenience +RZ_API bool rz_strbuf_copy(RStrBuf *dst, RStrBuf *src); +RZ_API bool rz_strbuf_equals(RStrBuf *sa, RStrBuf *sb); +RZ_API bool rz_strbuf_reserve(RStrBuf *sb, size_t len); +RZ_API bool rz_strbuf_is_empty(RStrBuf *sb); +RZ_API bool rz_strbuf_setptr(RStrBuf *sb, char *p, int l); + +#ifdef __cplusplus +} +#endif + +#endif // R_STRBUF_H diff --git a/librz/include/rz_util/rz_strpool.h b/librz/include/rz_util/rz_strpool.h new file mode 100644 index 0000000000..c9b8331b7f --- /dev/null +++ b/librz/include/rz_util/rz_strpool.h @@ -0,0 +1,34 @@ +#ifndef R_STRPOOL_H +#define R_STRPOOL_H + +#define R_STRPOOL_INC 1024 + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + char *str; + int len; + int size; +} RStrpool; + +RZ_API RStrpool* rz_strpool_new(int sz); +RZ_API char *rz_strpool_alloc(RStrpool *p, int l); +RZ_API int rz_strpool_memcat(RStrpool *p, const char *s, int len); +RZ_API int rz_strpool_ansi_chop(RStrpool *p, int n); +RZ_API int rz_strpool_append(RStrpool *p, const char *s); +RZ_API void rz_strpool_free(RStrpool *p); +RZ_API int rz_strpool_fit(RStrpool *p); +RZ_API char *rz_strpool_get(RStrpool *p, int index); +RZ_API char *rz_strpool_get_i(RStrpool *p, int index); +RZ_API int rz_strpool_get_index(RStrpool *p, const char *s); +RZ_API char *rz_strpool_next(RStrpool *p, int index); +RZ_API char *rz_strpool_slice(RStrpool *p, int index); +RZ_API char *rz_strpool_empty(RStrpool *p); + +#ifdef __cplusplus +} +#endif + +#endif // R_STRPOOL_H diff --git a/librz/include/rz_util/rz_sys.h b/librz/include/rz_util/rz_sys.h new file mode 100644 index 0000000000..d7a94b46fa --- /dev/null +++ b/librz/include/rz_util/rz_sys.h @@ -0,0 +1,150 @@ +#ifndef R_SYS_H +#define R_SYS_H + +#include + +#if __WINDOWS__ +#define R_SYS_DEVNULL "nul" +#else +#define R_SYS_DEVNULL "/dev/null" +#endif + + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + R_SYS_BITS_8 = 1, + R_SYS_BITS_16 = 2, + R_SYS_BITS_32 = 4, + R_SYS_BITS_64 = 8, +}; + +typedef struct { + char *sysname; + char *nodename; + char *release; + char *version; + char *machine; +} RSysInfo; + +RZ_API RSysInfo *rz_sys_info(void); +RZ_API void rz_sys_info_free(RSysInfo *si); + +RZ_API int rz_sys_sigaction(int *sig, void (*handler) (int)); +RZ_API int rz_sys_signal(int sig, void (*handler) (int)); +RZ_API void rz_sys_env_init(void); +RZ_API char **rz_sys_get_environ(void); +RZ_API void rz_sys_set_environ(char **e); + +RZ_API int rz_sys_fork(void); +// nocleanup = false => exit(); true => _exit() +RZ_API void rz_sys_exit(int status, bool nocleanup); +RZ_API bool rz_is_heap (void *p); +RZ_API bool rz_sys_stop(void); +RZ_API char *rz_sys_pid_to_path(int pid); +RZ_API int rz_sys_run(const ut8 *buf, int len); +RZ_API int rz_sys_run_rop(const ut8 *buf, int len); +RZ_API int rz_sys_getpid(void); +RZ_API int rz_sys_crash_handler(const char *cmd); +RZ_API const char *rz_sys_arch_str(int arch); +RZ_API int rz_sys_arch_id(const char *arch); +RZ_API bool rz_sys_arch_match(const char *archstr, const char *arch); +RZ_API RzList *rz_sys_dir(const char *path); +RZ_API void rz_sys_perror_str(const char *fun); +#if __WINDOWS__ +#define rz_sys_mkdir_failed() (GetLastError () != ERROR_ALREADY_EXISTS) +#else +#define rz_sys_mkdir_failed() (errno != EEXIST) +#endif +RZ_API const char *rz_sys_prefix(const char *pfx); +RZ_API bool rz_sys_mkdir(const char *dir); +RZ_API bool rz_sys_mkdirp(const char *dir); +RZ_API int rz_sys_sleep(int secs); +RZ_API int rz_sys_usleep(int usecs); +RZ_API char *rz_sys_getenv(const char *key); +RZ_API bool rz_sys_getenv_asbool(const char *key); +RZ_API int rz_sys_setenv(const char *key, const char *value); +RZ_API int rz_sys_clearenv(void); +RZ_API char *rz_sys_whoami(char *buf); +RZ_API char *rz_sys_getdir(void); +RZ_API int rz_sys_chdir(const char *s); +RZ_API bool rz_sys_aslr(int val); +RZ_API int rz_sys_thp_mode(void); +RZ_API int rz_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr); +#if __WINDOWS__ +#if UNICODE +#define W32_TCHAR_FSTR "%S" +#define W32_TCALL(name) name"W" +#define rz_sys_conv_utf8_to_win(buf) rz_utf8_to_utf16 (buf) +#define rz_sys_conv_utf8_to_win_l(buf, len) rz_utf8_to_utf16_l (buf, len) +#define rz_sys_conv_win_to_utf8(buf) rz_utf16_to_utf8 (buf) +#define rz_sys_conv_win_to_utf8_l(buf, len) rz_utf16_to_utf8_l ((wchar_t *)buf, len) +#else +#define W32_TCHAR_FSTR "%s" +#define W32_TCALL(name) name"A" +#define rz_sys_conv_utf8_to_win(buf) rz_utf8_to_acp (buf) +#define rz_sys_conv_utf8_to_win_l(buf, len) rz_utf8_to_acp_l (buf, len) +#define rz_sys_conv_win_to_utf8(buf) rz_acp_to_utf8 (buf) +#define rz_sys_conv_win_to_utf8_l(buf, len) rz_acp_to_utf8_l (buf, len) +#endif +RZ_API char *rz_sys_get_src_dir_w32(void); +RZ_API bool rz_sys_cmd_str_full_w32(const char *cmd, const char *input, char **output, int *outlen, char **sterr); +RZ_API bool rz_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE out, HANDLE err); +#endif +RZ_API int rz_sys_truncate(const char *file, int sz); +RZ_API int rz_sys_cmd(const char *cmd); +RZ_API int rz_sys_cmdbg(const char *cmd); +RZ_API int rz_sys_cmdf(const char *fmt, ...) R_PRINTF_CHECK(1, 2); +RZ_API char *rz_sys_cmd_str(const char *cmd, const char *input, int *len); +RZ_API char *rz_sys_cmd_strf(const char *cmd, ...) R_PRINTF_CHECK(1, 2); +//#define rz_sys_cmd_str(cmd, input, len) rz_sys_cmd_str_full(cmd, input, len, 0) +RZ_API void rz_sys_backtrace(void); +RZ_API bool rz_sys_tts(const char *txt, bool bg); + +#if __WINDOWS__ +# define rz_sys_breakpoint() { __debugbreak (); } +#else +#if __GNUC__ +# define rz_sys_breakpoint() __builtin_trap() +#elif __i386__ || __x86_64__ +# define rz_sys_breakpoint() __asm__ volatile ("int3"); +#elif __arm64__ || __aarch64__ +# define rz_sys_breakpoint() __asm__ volatile ("brk 0"); +// #define rz_sys_breakpoint() __asm__ volatile ("brk #1"); +#elif (__arm__ || __thumb__) +# if __ARM_ARCH > 5 +# define rz_sys_breakpoint() __asm__ volatile ("bkpt $0"); +# else +# define rz_sys_breakpoint() __asm__ volatile ("svc $1"); +# endif +#elif __mips__ +# define rz_sys_breakpoint() __asm__ volatile ("break"); +// # define rz_sys_breakpoint() __asm__ volatile ("teq $0, $0"); +#elif __EMSCRIPTEN__ +// TODO: cannot find a better way to breakpoint in wasm/asm.js +# define rz_sys_breakpoint() { char *a = NULL; *a = 0; } +#else +# warning rz_sys_breakpoint not implemented for this platform +# define rz_sys_trap() __asm__ __volatile__ (".word 0"); +# define rz_sys_breakpoint() { char *a = NULL; *a = 0; } +#endif +#endif + +/* syscmd */ +RZ_API char *rz_syscmd_ls(const char *input); +RZ_API char *rz_syscmd_cat(const char *file); +RZ_API char *rz_syscmd_mkdir(const char *dir); +RZ_API bool rz_syscmd_mv(const char *input); +RZ_API char *rz_syscmd_uniq(const char *file); +RZ_API char *rz_syscmd_head(const char *file, int count); +RZ_API char *rz_syscmd_tail(const char *file, int count); +RZ_API char *rz_syscmd_join(const char *file1, const char *file2); +RZ_API char *rz_syscmd_sort(const char *file); + +#ifdef __cplusplus +} +#endif + +#endif // R_SYS_H diff --git a/librz/include/rz_util/rz_table.h b/librz/include/rz_util/rz_table.h new file mode 100644 index 0000000000..5a93e3dde2 --- /dev/null +++ b/librz/include/rz_util/rz_table.h @@ -0,0 +1,100 @@ +#ifndef R_UTIL_TABLE_H +#define R_UTIL_TABLE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + const char *name; + RzListComparator cmp; +} RTableColumnType; + +typedef struct { + char *name; + RTableColumnType *type; + int align; // left, right, center (TODO: unused) + int width; // computed + int maxWidth; + bool forceUppercase; + int total; +} RTableColumn; + +typedef struct { + char *name; + RInterval pitv; + RInterval vitv; + int perm; + char *extra; +} RzListInfo; + +enum { + R_TABLE_ALIGN_LEFT, + R_TABLE_ALIGN_RIGHT, + R_TABLE_ALIGN_CENTER +}; + +typedef struct { + // TODO: use RzVector + RzList *items; +} RTableRow; + +typedef struct { + RzList *rows; + RzList *cols; + int totalCols; + bool showHeader; + bool showFancy; + bool showJSON; + bool showCSV; + bool showSum; + bool adjustedCols; + void *cons; +} RTable; + +typedef void (*RTableSelector)(RTableRow *acc, RTableRow *new_row, int nth); + +RZ_API void rz_table_row_free(void *_row); +RZ_API void rz_table_column_free(void *_col); +RZ_API RTableColumn *rz_table_column_clone(RTableColumn *col); +RZ_API RTableColumnType *rz_table_type(const char *name); +RZ_API RTable *rz_table_new(void); +RZ_API void rz_table_free(RTable *t); +RZ_API int rz_table_column_nth(RTable *t, const char *name); +RZ_API void rz_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxWidth); +RZ_API void rz_table_set_columnsf(RTable *t, const char *fmt, ...); +RZ_API RTableRow *rz_table_row_new(RzList *items); +RZ_API void rz_table_add_row(RTable *t, const char *name, ...); +RZ_API void rz_table_add_rowf(RTable *t, const char *fmt, ...); +RZ_API void rz_table_add_row_list(RTable *t, RzList *items); +RZ_API char *rz_table_tofancystring(RTable *t); +RZ_API char *rz_table_tosimplestring(RTable *t); +RZ_API char *rz_table_tostring(RTable *t); +RZ_API char *rz_table_tocsv(RTable *t); +RZ_API char *rz_table_tojson(RTable *t); +RZ_API void rz_table_filter(RTable *t, int nth, int op, const char *un); +RZ_API void rz_table_sort(RTable *t, int nth, bool inc); +RZ_API void rz_table_uniq(RTable *t); +RZ_API void rz_table_group(RTable *t, int nth, RTableSelector fcn); +RZ_API bool rz_table_query(RTable *t, const char *q); +RZ_API void rz_table_hide_header(RTable *t); +RZ_API bool rz_table_align(RTable *t, int nth, int align); +RZ_API void rz_table_visual_list(RTable *table, RzList* list, ut64 seek, ut64 len, int width, bool va); +RZ_API RTable *rz_table_clone(RTable *t); +RZ_API RTable *rz_table_push(RTable *t); +RZ_API RTable *rz_table_pop(RTable *t); +RZ_API void rz_table_fromjson(RTable *t, const char *csv); +RZ_API void rz_table_fromcsv(RTable *t, const char *csv); +RZ_API char *rz_table_tohtml(RTable *t); +RZ_API void rz_table_transpose(RTable *t); +RZ_API void rz_table_format(RTable *t, int nth, RTableColumnType *type); +RZ_API ut64 rz_table_reduce(RTable *t, int nth); +RZ_API void rz_table_columns(RTable *t, RzList *cols); // const char *name, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_util/r_time.h b/librz/include/rz_util/rz_time.h similarity index 51% rename from libr/include/r_util/r_time.h rename to librz/include/rz_util/rz_time.h index cf5a8890be..b7ebf26ed0 100644 --- a/libr/include/r_util/r_time.h +++ b/librz/include/rz_util/rz_time.h @@ -1,7 +1,7 @@ #ifndef R2_TIME_H #define R2_TIME_H -#include +#include #define R_NSEC_PER_SEC 1000000000 #define R_NSEC_PER_MSEC 1000000 @@ -12,24 +12,24 @@ #define ASCTIME_BUF_MINLEN (26) // wall clock time in microseconds -R_API ut64 r_time_now(void); +RZ_API ut64 rz_time_now(void); // monotonic time in microseconds -R_API ut64 r_time_now_mono(void); +RZ_API ut64 rz_time_now_mono(void); -R_API char *r_time_stamp_to_str(ut32 timeStamp); -R_API ut32 r_time_dos_time_stamp_to_posix(ut32 timeStamp); -R_API bool r_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp); -R_API const char *r_time_to_string(ut64 ts); +RZ_API char *rz_time_stamp_to_str(ut32 timeStamp); +RZ_API ut32 rz_time_dos_time_stamp_to_posix(ut32 timeStamp); +RZ_API bool rz_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp); +RZ_API const char *rz_time_to_string(ut64 ts); // Cross platform asctime_r -R_API char *r_asctime_r(const struct tm *tm, char *buf, size_t size); +RZ_API char *rz_asctime_r(const struct tm *tm, char *buf, size_t size); #define R_TIME_PROFILE_ENABLED 0 #if R_TIME_PROFILE_ENABLED -#define R_TIME_PROFILE_BEGIN ut64 __now__ = r_time_now_mono() -#define R_TIME_PROFILE_END eprintf ("%s %"PFMT64d"\n", __FUNCTION__, r_time_now_mono() - __now__) +#define R_TIME_PROFILE_BEGIN ut64 __now__ = rz_time_now_mono() +#define R_TIME_PROFILE_END eprintf ("%s %"PFMT64d"\n", __FUNCTION__, rz_time_now_mono() - __now__) #else #define R_TIME_PROFILE_BEGIN do{}while(0) #define R_TIME_PROFILE_END do{}while(0) diff --git a/librz/include/rz_util/rz_tree.h b/librz/include/rz_util/rz_tree.h new file mode 100644 index 0000000000..9e5c79282e --- /dev/null +++ b/librz/include/rz_util/rz_tree.h @@ -0,0 +1,36 @@ +#ifndef R_TREE_H +#define R_TREE_H +#include +#include + +struct rz_tree_t; + +typedef struct rz_tree_node_t { + struct rz_tree_node_t *parent; + struct rz_tree_t *tree; + RzList *children; // + unsigned int n_children; + int depth; + RzListFree free; + void *data; +} RTreeNode; + +typedef struct rz_tree_t { + RTreeNode *root; +} RTree; + +typedef struct rz_tree_visitor_t { + void (*pre_visit)(RTreeNode *, struct rz_tree_visitor_t *); + void (*post_visit)(RTreeNode *, struct rz_tree_visitor_t *); + void (*discover_child)(RTreeNode *, struct rz_tree_visitor_t *); + void *data; +} RTreeVisitor; +typedef void (*RTreeNodeVisitCb)(RTreeNode *n, RTreeVisitor *vis); + +RZ_API RTree *rz_tree_new(void); +RZ_API RTreeNode *rz_tree_add_node(RTree *t, RTreeNode *node, void *child_data); +RZ_API void rz_tree_reset(RTree *t); +RZ_API void rz_tree_free(RTree *t); +RZ_API void rz_tree_dfs(RTree *t, RTreeVisitor *vis); +RZ_API void rz_tree_bfs(RTree *t, RTreeVisitor *vis); +#endif // R_TREE_H diff --git a/librz/include/rz_util/rz_uleb128.h b/librz/include/rz_util/rz_uleb128.h new file mode 100644 index 0000000000..9edb0402ed --- /dev/null +++ b/librz/include/rz_util/rz_uleb128.h @@ -0,0 +1,18 @@ +#ifndef R_ULEB128_H +#define R_ULEB128_H + +// LEB128 or Little Endian Base 128 is a form of variable-length code +// compression used to store an arbitrarily large integer in a small number of +// bytes. LEB128 is used in the DWARF debug file format. + +RZ_API const ut8 *rz_uleb128(const ut8 *data, int datalen, ut64 *v, const char **error); +RZ_API const ut8 *rz_uleb128_decode(const ut8 *data, int *datalen, ut64 *v); +RZ_API int rz_uleb128_len(const ut8 *data, int size); +RZ_API ut8 *rz_uleb128_encode(const ut64 s, int *len); +RZ_API const ut8 *rz_leb128(const ut8 *data, int datalen, st64 *v); +RZ_API st64 rz_sleb128(const ut8 **data, const ut8 *end); +RZ_API size_t read_u32_leb128(const ut8 *p, const ut8 *max, ut32 *out_val); +RZ_API size_t read_i32_leb128(const ut8 *p, const ut8 *max, st32 *out_val); +RZ_API size_t read_u64_leb128(const ut8 *p, const ut8 *max, ut64 *out_val); +RZ_API size_t read_i64_leb128(const ut8 *p, const ut8 *max, st64 *out_val); +#endif // R_ULEB128_H diff --git a/librz/include/rz_util/rz_utf16.h b/librz/include/rz_util/rz_utf16.h new file mode 100644 index 0000000000..922987d029 --- /dev/null +++ b/librz/include/rz_util/rz_utf16.h @@ -0,0 +1,12 @@ +#ifndef R_UTF16_H +#define R_UTF16_H + +/* For RRune definition */ +#include "rz_utf8.h" + +RZ_API int rz_utf16_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian); +RZ_API int rz_utf16le_decode(const ut8 *ptr, int ptrlen, RRune *ch); +RZ_API int rz_utf16be_decode(const ut8 *ptr, int ptrlen, RRune *ch); +RZ_API int rz_utf16le_encode(ut8 *ptr, RRune ch); + +#endif // R_UTF16_H diff --git a/librz/include/rz_util/rz_utf32.h b/librz/include/rz_util/rz_utf32.h new file mode 100644 index 0000000000..6600751fc0 --- /dev/null +++ b/librz/include/rz_util/rz_utf32.h @@ -0,0 +1,11 @@ +#ifndef R_UTF32_H +#define R_UTF32_H + +/* For RRune definition */ +#include "rz_utf8.h" + +RZ_API int rz_utf32_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian); +RZ_API int rz_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch); +RZ_API int rz_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch); + +#endif // R_UTF32_H diff --git a/librz/include/rz_util/rz_utf8.h b/librz/include/rz_util/rz_utf8.h new file mode 100644 index 0000000000..49a2c2a504 --- /dev/null +++ b/librz/include/rz_util/rz_utf8.h @@ -0,0 +1,32 @@ +#ifndef R_UTF8_H +#define R_UTF8_H + +/* For RStrEnc definition */ +#include "rz_str.h" + +typedef struct { ut32 from, to; const char *name; } RUtfBlock; +// extern const RUtfBlock rz_utf_blocks[]; + +typedef ut32 RRune; +RZ_API int rz_utf8_encode(ut8 *ptr, const RRune ch); +RZ_API int rz_utf8_decode(const ut8 *ptr, int ptrlen, RRune *ch); +RZ_API int rz_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length); +RZ_API int rz_utf8_size(const ut8 *ptr); +RZ_API int rz_utf8_strlen(const ut8 *str); +RZ_API int rz_isprint(const RRune c); +RZ_API char *rz_utf16_to_utf8_l(const wchar_t *wc, int len); +RZ_API const char *rz_utf_block_name(int idx); +RZ_API wchar_t *rz_utf8_to_utf16_l(const char *cstring, int len); +RZ_API int rz_utf_block_idx (RRune ch); +RZ_API int *rz_utf_block_list (const ut8 *str, int len, int **freq_list); +RZ_API RStrEnc rz_utf_bom_encoding(const ut8 *ptr, int ptrlen); +#define rz_utf16_to_utf8(wc) rz_utf16_to_utf8_l ((wchar_t *)wc, -1) +#define rz_utf8_to_utf16(cstring) rz_utf8_to_utf16_l ((char *)cstring, -1) +#if __WINDOWS__ +RZ_API char *rz_acp_to_utf8_l(const char *str, int len); +RZ_API char *rz_utf8_to_acp_l(const char *str, int len); +#define rz_acp_to_utf8(str) rz_acp_to_utf8_l ((char *)str, -1) +#define rz_utf8_to_acp(cstring) rz_utf8_to_acp_l ((char *)cstring, -1) +#endif // __WINDOWS__ + +#endif // R_UTF8_H diff --git a/libr/include/r_util/r_x509.h b/librz/include/rz_util/rz_x509.h similarity index 61% rename from libr/include/r_util/r_x509.h rename to librz/include/rz_util/rz_x509.h index 3f365134f8..c2a2afcb99 100644 --- a/libr/include/r_util/r_x509.h +++ b/librz/include/rz_util/rz_x509.h @@ -9,18 +9,18 @@ extern "C" { * Following RFC 5280 */ -typedef struct r_x509_validity_t { +typedef struct rz_x509_validity_t { RASN1String *notBefore; RASN1String *notAfter; } RX509Validity; -typedef struct r_x509_name_t { +typedef struct rz_x509_name_t { ut32 length; RASN1String **oids; RASN1String **names; } RX509Name; -typedef struct r_x509_algorithmidentifier_t { +typedef struct rz_x509_algorithmidentifier_t { RASN1String *algorithm; // OBJECT IDENTIFIER RASN1String *parameters; // OPTIONAL } RX509AlgorithmIdentifier; @@ -28,7 +28,7 @@ typedef struct r_x509_algorithmidentifier_t { /* //SubjectKeyIdentifier OCTET STRING so it should be an ASN1Object -typedef struct r_x509_keyusage_t { +typedef struct rz_x509_keyusage_t { ut8 digitalSignature : 1; ut8 contentCommitment : 1; ut8 keyEncipherment : 1; @@ -41,13 +41,13 @@ typedef struct r_x509_keyusage_t { } X509KeyUsage; */ -typedef struct r_x509_authoritykeyidentifier_t { +typedef struct rz_x509_authoritykeyidentifier_t { RASN1Binary *keyIdentifier; RX509Name authorityCertIssuer; RASN1Binary *authorityCertSerialNumber; } RX509AuthorityKeyIdentifier; -typedef struct r_x509_subjectpublickeyinfo_t { +typedef struct rz_x509_subjectpublickeyinfo_t { RX509AlgorithmIdentifier algorithm; //This is a bit string, but it encapsulate mod + pubkey RASN1Binary *subjectPublicKey; // BIT STRING @@ -57,18 +57,18 @@ typedef struct r_x509_subjectpublickeyinfo_t { RASN1Binary *subjectPublicKeyModule; } RX509SubjectPublicKeyInfo; -typedef struct r_x509_extension_t { +typedef struct rz_x509_extension_t { RASN1String *extnID; // OBJECT IDENTIFIER bool critical; RASN1Binary *extnValue; // OCTET STRING } RX509Extension; -typedef struct r_x509_extensions_t { +typedef struct rz_x509_extensions_t { ut32 length; RX509Extension **extensions; } RX509Extensions; -typedef struct r_x509_tbscertificate_t { +typedef struct rz_x509_tbscertificate_t { ut32 version; //INTEGER RASN1String *serialNumber; // INTEGER RX509AlgorithmIdentifier signature; @@ -81,7 +81,7 @@ typedef struct r_x509_tbscertificate_t { RX509Extensions extensions; } RX509TBSCertificate; -typedef struct r_x509_certificate_t { +typedef struct rz_x509_certificate_t { RX509TBSCertificate tbsCertificate; RX509AlgorithmIdentifier algorithmIdentifier; RASN1Binary *signature; // BIT STRING @@ -90,12 +90,12 @@ typedef struct r_x509_certificate_t { // RFC 1422 -typedef struct r_x509_crlentry { +typedef struct rz_x509_crlentry { RASN1Binary *userCertificate; //INTEGER ? RASN1String *revocationDate; //UTCTime } RX509CRLEntry; -typedef struct r_x509_certificaterevocationlist { +typedef struct rz_x509_certificaterevocationlist { RX509AlgorithmIdentifier signature; RX509Name issuer; RASN1String *lastUpdate; //UTCTime @@ -104,18 +104,18 @@ typedef struct r_x509_certificaterevocationlist { RX509CRLEntry **revokedCertificates; } RX509CertificateRevocationList; -R_API RX509CertificateRevocationList* r_x509_parse_crl(RASN1Object *object); -// R_API void r_x509_free_crl(RX509CertificateRevocationList *crl); -// R_API void r_x509_crl_dump(RX509CertificateRevocationList *crl, const char* pad); -R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char* pad); -R_API void r_x509_crl_json(PJ* pj, RX509CertificateRevocationList *crl); +RZ_API RX509CertificateRevocationList* rz_x509_parse_crl(RASN1Object *object); +// RZ_API void rz_x509_free_crl(RX509CertificateRevocationList *crl); +// RZ_API void rz_x509_crl_dump(RX509CertificateRevocationList *crl, const char* pad); +RZ_API char *rz_x509_crl_to_string(RX509CertificateRevocationList *crl, const char* pad); +RZ_API void rz_x509_crl_json(PJ* pj, RX509CertificateRevocationList *crl); -R_API RX509Certificate *r_x509_parse_certificate(RASN1Object *object); -R_API RX509Certificate *r_x509_parse_certificate2(const ut8 *buffer, ut32 length); -R_API void r_x509_free_certificate(RX509Certificate* certificate); -R_API char *r_x509_certificate_to_string(RX509Certificate* certificate, const char* pad); -R_API void r_x509_certificate_json(PJ* pj, RX509Certificate *certificate); -R_API void r_x509_certificate_dump(RX509Certificate* cert, const char* pad, RStrBuf *sb); +RZ_API RX509Certificate *rz_x509_parse_certificate(RASN1Object *object); +RZ_API RX509Certificate *rz_x509_parse_certificate2(const ut8 *buffer, ut32 length); +RZ_API void rz_x509_free_certificate(RX509Certificate* certificate); +RZ_API char *rz_x509_certificate_to_string(RX509Certificate* certificate, const char* pad); +RZ_API void rz_x509_certificate_json(PJ* pj, RX509Certificate *certificate); +RZ_API void rz_x509_certificate_dump(RX509Certificate* cert, const char* pad, RStrBuf *sb); #ifdef __cplusplus diff --git a/librz/include/rz_vector.h b/librz/include/rz_vector.h new file mode 100644 index 0000000000..9d04b6f13d --- /dev/null +++ b/librz/include/rz_vector.h @@ -0,0 +1,313 @@ +#ifndef R2_VECTOR_H +#define R2_VECTOR_H + +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +/* + * RzVector can contain arbitrarily sized elements. + * RPVector uses RzVector internally and always contains void *s + * + * Thus, for storing pointers it is highly encouraged to always use RPVector + * as it is specifically made for this purpose and is more consistent with RzList, + * while RzVector can be used as, for example, a flat array of a struct. + * + * Notable differences between RzVector and RPVector: + * ------------------------------------------------- + * When RzVector expects an element to be inserted, for example in rz_vector_push(..., void *x), + * this void * value is interpreted as a pointer to the actual data for the element. + * => If you use RzVector as a dynamic replacement for (struct SomeStruct)[], you will + * pass a struct SomeStruct * to these functions. + * + * Because RPVector only handles pointers, the given void * is directly interpreted as the + * actual pointer to be inserted. + * => If you use RPVector as a dynamic replacement for (SomeType *)[], you will pass + * SomeType * directly to these functions. + * + * The same differentiation goes for the free functions: + * - The element parameter in RzVectorFree is a pointer to the element inside the array. + * - The element parameter in RPVectorFree is the actual pointer stored in the array. + * + * General Hint: + * ------------- + * remove/pop functions do not reduce the capacity. + * Call rz_(p)vector_shrink explicitly if desired. + */ + +typedef int (*RPVectorComparator)(const void *a, const void *b); +typedef void (*RzVectorFree)(void *e, void *user); +typedef void (*RPVectorFree)(void *e); + +typedef struct rz_vector_t { + void *a; + size_t len; + size_t capacity; + size_t elem_size; + RzVectorFree free; + void *free_user; +} RzVector; + +// RPVector directly wraps RzVector for type safety +typedef struct rz_pvector_t { RzVector v; } RPVector; + + +// RzVector + +RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user); + +RZ_API RzVector *rz_vector_new(size_t elem_size, RzVectorFree free, void *free_user); + +// clears the vector and calls vec->free on every element if set. +RZ_API void rz_vector_fini(RzVector *vec); + +// frees the vector and calls vec->free on every element if set. +RZ_API void rz_vector_free(RzVector *vec); + +// the returned vector will have the same capacity as vec. +RZ_API RzVector *rz_vector_clone(RzVector *vec); + +static inline bool rz_vector_empty(const RzVector *vec) { + rz_return_val_if_fail (vec, false); + return vec->len == 0; +} + +RZ_API void rz_vector_clear(RzVector *vec); + +// returns a pointer to the offset inside the array where the element of the index lies. +static inline void *rz_vector_index_ptr(RzVector *vec, size_t index) { + rz_return_val_if_fail (vec && index < vec->capacity, NULL); + return (char *)vec->a + vec->elem_size * index; +} + +// helper function to assign an element of size vec->elem_size from elem to p. +// elem is a pointer to the actual data to assign! +RZ_API void rz_vector_assign(RzVector *vec, void *p, void *elem); + +// assign the value of size vec->elem_size at elem to vec at the given index. +// elem is a pointer to the actual data to assign! +RZ_API void *rz_vector_assign_at(RzVector *vec, size_t index, void *elem); + +// remove the element at the given index and write the content to into. +// It is the caller's responsibility to free potential resources associated with the element. +RZ_API void rz_vector_remove_at(RzVector *vec, size_t index, void *into); + +// insert the value of size vec->elem_size at x at the given index. +// x is a pointer to the actual data to assign! +RZ_API void *rz_vector_insert(RzVector *vec, size_t index, void *x); + +// insert count values of size vec->elem_size into vec starting at the given index. +RZ_API void *rz_vector_insert_range(RzVector *vec, size_t index, void *first, size_t count); + +// like rz_vector_remove_at for the last element +RZ_API void rz_vector_pop(RzVector *vec, void *into); + +// like rz_vector_remove_at for the first element +RZ_API void rz_vector_pop_front(RzVector *vec, void *into); + +// like rz_vector_insert for the end of vec +RZ_API void *rz_vector_push(RzVector *vec, void *x); + +// like rz_vector_insert for the beginning of vec +RZ_API void *rz_vector_push_front(RzVector *vec, void *x); + +// make sure the capacity is at least capacity. +RZ_API void *rz_vector_reserve(RzVector *vec, size_t capacity); + +// shrink capacity to len. +RZ_API void *rz_vector_shrink(RzVector *vec); + +/* + * example: + * + * RzVector *v = ...; // + * MyStruct *it; + * rz_vector_foreach (v, it) { + * // Do something with it + * } + */ +#define rz_vector_foreach(vec, it) \ + if (!rz_vector_empty (vec)) \ + for (it = (void *)(vec)->a; (char *)it != (char *)(vec)->a + ((vec)->len * (vec)->elem_size); it = (void *)((char *)it + (vec)->elem_size)) + +#define rz_vector_foreach_prev(vec, it) \ + if (!rz_vector_empty (vec)) \ + for (it = (void *)((char *)(vec)->a + (((vec)->len - 1)* (vec)->elem_size)); (char *)it != (char *)(vec)->a; it = (void *)((char *)it - (vec)->elem_size)) + +#define rz_vector_enumerate(vec, it, i) \ + if (!rz_vector_empty (vec)) \ + for (it = (void *)(vec)->a, i = 0; i < (vec)->len; it = (void *)((char *)it + (vec)->elem_size), i++) + +/* + * example: + * + * RzVector *v = ...; // contains {(st64)0, (st64)2, (st64)4, (st64)6, (st64)8}; + * size_t l; + * #define CMP(x, y) x - (*(st64 *)y) + * rz_vector_lower_bound (v, 3, l, CMP); + * // l == 2 + */ +#define rz_vector_lower_bound(vec, x, i, cmp) \ + do { \ + size_t h = (vec)->len, m; \ + for (i = 0; i < h; ) { \ + m = i + ((h - i) >> 1); \ + if ((cmp (x, ((char *)(vec)->a + (vec)->elem_size * m))) > 0) { \ + i = m + 1; \ + } else { \ + h = m; \ + } \ + } \ + } while (0) \ + +#define rz_vector_upper_bound(vec, x, i, cmp) \ + do { \ + size_t h = (vec)->len, m; \ + for (i = 0; i < h; ) { \ + m = i + ((h - i) >> 1); \ + if ((cmp (x, ((char *)(vec)->a + (vec)->elem_size * m))) < 0) { \ + h = m; \ + } else { \ + i = m + 1; \ + } \ + } \ + } while (0) \ + +// RPVector + +RZ_API void rz_pvector_init(RPVector *vec, RPVectorFree free); +RZ_API void rz_pvector_fini(RPVector *vec); + +RZ_API RPVector *rz_pvector_new(RPVectorFree free); + +RZ_API RPVector *rz_pvector_new_with_len(RPVectorFree free, size_t length); + +// clear the vector and call vec->v.free on every element. +RZ_API void rz_pvector_clear(RPVector *vec); + +// free the vector and call vec->v.free on every element. +RZ_API void rz_pvector_free(RPVector *vec); + +static inline size_t rz_pvector_len(const RPVector *vec) { + rz_return_val_if_fail (vec, 0); + return vec->v.len; +} + +static inline void *rz_pvector_at(const RPVector *vec, size_t index) { + rz_return_val_if_fail (vec && index < vec->v.len, NULL); + return ((void **)vec->v.a)[index]; +} + +static inline void rz_pvector_set(RPVector *vec, size_t index, void *e) { + rz_return_if_fail (vec && index < vec->v.len); + ((void **)vec->v.a)[index] = e; +} + +static inline bool rz_pvector_empty(RPVector *vec) { + return rz_pvector_len (vec) == 0; +} + +// returns a pointer to the offset inside the array where the element of the index lies. +static inline void **rz_pvector_index_ptr(RPVector *vec, size_t index) { + rz_return_val_if_fail (vec && index < vec->v.capacity, NULL); + return ((void **)vec->v.a) + index; +} + +// same as rz_pvector_index_ptr(, 0) +static inline void **rz_pvector_data(RPVector *vec) { + rz_return_val_if_fail (vec, NULL); + return (void **)vec->v.a; +} + +// returns the respective pointer inside the vector if x is found or NULL otherwise. +RZ_API void **rz_pvector_contains(RPVector *vec, void *x); + +// removes and returns the pointer at the given index. Does not call free. +RZ_API void *rz_pvector_remove_at(RPVector *vec, size_t index); + +// removes the element x, if present. Does not call free. +RZ_API void rz_pvector_remove_data(RPVector *vec, void *x); + +// like rz_vector_insert, but the pointer x is the actual data to be inserted. +static inline void **rz_pvector_insert(RPVector *vec, size_t index, void *x) { + return (void **)rz_vector_insert (&vec->v, index, &x); +} + +// like rz_vector_insert_range. +static inline void **rz_pvector_insert_range(RPVector *vec, size_t index, void **first, size_t count) { + return (void **)rz_vector_insert_range (&vec->v, index, first, count); +} + +// like rz_vector_pop, but returns the pointer directly. +RZ_API void *rz_pvector_pop(RPVector *vec); + +// like rz_vector_pop_front, but returns the pointer directly. +RZ_API void *rz_pvector_pop_front(RPVector *vec); + +// like rz_vector_push, but the pointer x is the actual data to be inserted. +static inline void **rz_pvector_push(RPVector *vec, void *x) { + return (void **)rz_vector_push (&vec->v, &x); +} + +// like rz_vector_push_front, but the pointer x is the actual data to be inserted. +static inline void **rz_pvector_push_front(RPVector *vec, void *x) { + return (void **)rz_vector_push_front (&vec->v, &x); +} + +// sort vec using quick sort. +RZ_API void rz_pvector_sort(RPVector *vec, RPVectorComparator cmp); + +static inline void **rz_pvector_reserve(RPVector *vec, size_t capacity) { + return (void **)rz_vector_reserve (&vec->v, capacity); +} + +static inline void **rz_pvector_shrink(RPVector *vec) { + return (void **)rz_vector_shrink (&vec->v); +} + +/* + * example: + * + * RzVector *v = ...; + * void **it; + * rz_pvector_foreach (v, it) { + * void *p = *it; + * // Do something with p + * } + */ +#define rz_pvector_foreach(vec, it) \ + for (it = (void **)(vec)->v.a; it != (void **)(vec)->v.a + (vec)->v.len; it++) + +// like rz_pvector_foreach() but inverse +#define rz_pvector_foreach_prev(vec, it) \ + for (it = ((vec)->v.len == 0 ? NULL : (void **)(vec)->v.a + (vec)->v.len - 1); it != NULL && it != (void **)(vec)->v.a - 1; it--) + +/* + * example: + * + * RPVector *v = ...; // contains {(void*)0, (void*)2, (void*)4, (void*)6, (void*)8}; + * size_t index; + * #define CMP(x, y) x - y + * rz_pvector_lower_bound (v, (void *)3, index, CMP); + * // index == 2 + */ +#define rz_pvector_lower_bound(vec, x, i, cmp) \ + do { \ + size_t h = (vec)->v.len, m; \ + for (i = 0; i < h; ) { \ + m = i + ((h - i) >> 1); \ + if ((cmp ((x), ((void **)(vec)->v.a)[m])) > 0) { \ + i = m + 1; \ + } else { \ + h = m; \ + } \ + } \ + } while (0) \ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libr/include/r_version.h.in b/librz/include/rz_version.h.in similarity index 100% rename from libr/include/r_version.h.in rename to librz/include/rz_version.h.in diff --git a/libr/include/r2naked.h b/librz/include/rznaked.h similarity index 56% rename from libr/include/r2naked.h rename to librz/include/rznaked.h index b125bb728b..3975451d7c 100644 --- a/libr/include/r2naked.h +++ b/librz/include/rznaked.h @@ -5,9 +5,9 @@ extern "C" { #endif -void *r_core_new(void); -char *r_core_cmd_str(void *p, const char *cmd); -void r_core_free(void* core); +void *rz_core_new(void); +char *rz_core_cmd_str(void *p, const char *cmd); +void rz_core_free(void* core); void free(void*); #ifdef __cplusplus diff --git a/libr/include/sflib/common/sfsocketcall.h b/librz/include/sflib/common/sfsocketcall.h similarity index 100% rename from libr/include/sflib/common/sfsocketcall.h rename to librz/include/sflib/common/sfsocketcall.h diff --git a/libr/include/sflib/common/sftypes.h b/librz/include/sflib/common/sftypes.h similarity index 99% rename from libr/include/sflib/common/sftypes.h rename to librz/include/sflib/common/sftypes.h index ae7bee3d42..50bf367e2d 100644 --- a/libr/include/sflib/common/sftypes.h +++ b/librz/include/sflib/common/sftypes.h @@ -438,7 +438,7 @@ struct cmsghdr #define SO_KEEPALIVE 9 #define SO_OOBINLINE 10 #define SO_NO_CHECK 11 -#define SO_PRIORITY 12 +#define SO_PRzIORITY 12 #define SO_LINGER 13 #define SO_BSDCOMPAT 14 /* To add :#define SO_REUSEPORT 15 */ @@ -1468,8 +1468,8 @@ typedef struct typedef struct { - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ + Elf32_Addr rz_offset; /* Address */ + Elf32_Word rz_info; /* Relocation type and symbol index */ } Elf32_Rel; /* I have seen two different definitions of the Elf64_Rel and @@ -1479,27 +1479,27 @@ typedef struct typedef struct { - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ + Elf64_Addr rz_offset; /* Address */ + Elf64_Xword rz_info; /* Relocation type and symbol index */ } Elf64_Rel; /* Relocation table entry with addend (in section of type SHT_RELA). */ typedef struct { - Elf32_Addr r_offset; /* Address */ - Elf32_Word r_info; /* Relocation type and symbol index */ - Elf32_Sword r_addend; /* Addend */ + Elf32_Addr rz_offset; /* Address */ + Elf32_Word rz_info; /* Relocation type and symbol index */ + Elf32_Sword rz_addend; /* Addend */ } Elf32_Rela; typedef struct { - Elf64_Addr r_offset; /* Address */ - Elf64_Xword r_info; /* Relocation type and symbol index */ - Elf64_Sxword r_addend; /* Addend */ + Elf64_Addr rz_offset; /* Address */ + Elf64_Xword rz_info; /* Relocation type and symbol index */ + Elf64_Sxword rz_addend; /* Addend */ } Elf64_Rela; -/* How to extract and insert information held in the r_info field. */ +/* How to extract and insert information held in the rz_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) #define ELF32_R_TYPE(val) ((val) & 0xff) diff --git a/libr/include/sflib/darwin-arm-64/ios-syscalls.py b/librz/include/sflib/darwin-arm-64/ios-syscalls.py similarity index 90% rename from libr/include/sflib/darwin-arm-64/ios-syscalls.py rename to librz/include/sflib/darwin-arm-64/ios-syscalls.py index f19ba01ccf..01b5accb7f 100644 --- a/libr/include/sflib/darwin-arm-64/ios-syscalls.py +++ b/librz/include/sflib/darwin-arm-64/ios-syscalls.py @@ -1,4 +1,4 @@ -import r2pipe +import rzpipe import json def chk(x): @@ -9,7 +9,7 @@ def chk(x): dev_pid = "23f88587e12c30376f8ab0b05236798fdfa4e853/4903" -r2 = r2pipe.open("frida://" + dev_pid) +r2 = rzpipe.open("frida://" + dev_pid) print("Importing symbols from libSystem...") r2.cmd(".=!i*") r2.cmd(".=!ie* libSystem.B.dylib") diff --git a/libr/include/sflib/darwin-arm-64/ios-syscalls.txt b/librz/include/sflib/darwin-arm-64/ios-syscalls.txt similarity index 100% rename from libr/include/sflib/darwin-arm-64/ios-syscalls.txt rename to librz/include/sflib/darwin-arm-64/ios-syscalls.txt diff --git a/libr/include/sflib/darwin-arm-64/sflib.h b/librz/include/sflib/darwin-arm-64/sflib.h similarity index 100% rename from libr/include/sflib/darwin-arm-64/sflib.h rename to librz/include/sflib/darwin-arm-64/sflib.h diff --git a/libr/include/sflib/darwin-arm-64/sfsyscall.h b/librz/include/sflib/darwin-arm-64/sfsyscall.h similarity index 100% rename from libr/include/sflib/darwin-arm-64/sfsyscall.h rename to librz/include/sflib/darwin-arm-64/sfsyscall.h diff --git a/libr/include/sflib/darwin-arm-64/sfsysnr.h b/librz/include/sflib/darwin-arm-64/sfsysnr.h similarity index 100% rename from libr/include/sflib/darwin-arm-64/sfsysnr.h rename to librz/include/sflib/darwin-arm-64/sfsysnr.h diff --git a/libr/include/sflib/darwin-x86-32/sflib.h b/librz/include/sflib/darwin-x86-32/sflib.h similarity index 100% rename from libr/include/sflib/darwin-x86-32/sflib.h rename to librz/include/sflib/darwin-x86-32/sflib.h diff --git a/libr/include/sflib/darwin-x86-32/sfsyscall.h b/librz/include/sflib/darwin-x86-32/sfsyscall.h similarity index 100% rename from libr/include/sflib/darwin-x86-32/sfsyscall.h rename to librz/include/sflib/darwin-x86-32/sfsyscall.h diff --git a/libr/include/sflib/darwin-x86-32/sfsysnr.h b/librz/include/sflib/darwin-x86-32/sfsysnr.h similarity index 100% rename from libr/include/sflib/darwin-x86-32/sfsysnr.h rename to librz/include/sflib/darwin-x86-32/sfsysnr.h diff --git a/libr/include/sflib/darwin-x86-64/sflib.h b/librz/include/sflib/darwin-x86-64/sflib.h similarity index 100% rename from libr/include/sflib/darwin-x86-64/sflib.h rename to librz/include/sflib/darwin-x86-64/sflib.h diff --git a/libr/include/sflib/darwin-x86-64/sfsyscall.h b/librz/include/sflib/darwin-x86-64/sfsyscall.h similarity index 100% rename from libr/include/sflib/darwin-x86-64/sfsyscall.h rename to librz/include/sflib/darwin-x86-64/sfsyscall.h diff --git a/libr/include/sflib/darwin-x86-64/sfsysnr.h b/librz/include/sflib/darwin-x86-64/sfsysnr.h similarity index 100% rename from libr/include/sflib/darwin-x86-64/sfsysnr.h rename to librz/include/sflib/darwin-x86-64/sfsysnr.h diff --git a/libr/include/sflib/linux-arm-32/sflib.h b/librz/include/sflib/linux-arm-32/sflib.h similarity index 100% rename from libr/include/sflib/linux-arm-32/sflib.h rename to librz/include/sflib/linux-arm-32/sflib.h diff --git a/libr/include/sflib/linux-arm-32/sfsyscall.h b/librz/include/sflib/linux-arm-32/sfsyscall.h similarity index 100% rename from libr/include/sflib/linux-arm-32/sfsyscall.h rename to librz/include/sflib/linux-arm-32/sfsyscall.h diff --git a/libr/include/sflib/linux-arm-32/sfsysnr.h b/librz/include/sflib/linux-arm-32/sfsysnr.h similarity index 100% rename from libr/include/sflib/linux-arm-32/sfsysnr.h rename to librz/include/sflib/linux-arm-32/sfsysnr.h diff --git a/libr/include/sflib/linux-arm-64/sflib.h b/librz/include/sflib/linux-arm-64/sflib.h similarity index 100% rename from libr/include/sflib/linux-arm-64/sflib.h rename to librz/include/sflib/linux-arm-64/sflib.h diff --git a/libr/include/sflib/linux-arm-64/sfsyscall.h b/librz/include/sflib/linux-arm-64/sfsyscall.h similarity index 100% rename from libr/include/sflib/linux-arm-64/sfsyscall.h rename to librz/include/sflib/linux-arm-64/sfsyscall.h diff --git a/libr/include/sflib/linux-arm-64/sfsysnr.h b/librz/include/sflib/linux-arm-64/sfsysnr.h similarity index 100% rename from libr/include/sflib/linux-arm-64/sfsysnr.h rename to librz/include/sflib/linux-arm-64/sfsysnr.h diff --git a/libr/include/sflib/linux-x86-32/sflib.h b/librz/include/sflib/linux-x86-32/sflib.h similarity index 100% rename from libr/include/sflib/linux-x86-32/sflib.h rename to librz/include/sflib/linux-x86-32/sflib.h diff --git a/libr/include/sflib/linux-x86-32/sfsyscall.h b/librz/include/sflib/linux-x86-32/sfsyscall.h similarity index 100% rename from libr/include/sflib/linux-x86-32/sfsyscall.h rename to librz/include/sflib/linux-x86-32/sfsyscall.h diff --git a/libr/include/sflib/linux-x86-32/sfsysnr.h b/librz/include/sflib/linux-x86-32/sfsysnr.h similarity index 100% rename from libr/include/sflib/linux-x86-32/sfsysnr.h rename to librz/include/sflib/linux-x86-32/sfsysnr.h diff --git a/libr/include/sflib/linux-x86-64/sflib.h b/librz/include/sflib/linux-x86-64/sflib.h similarity index 100% rename from libr/include/sflib/linux-x86-64/sflib.h rename to librz/include/sflib/linux-x86-64/sflib.h diff --git a/libr/include/sflib/linux-x86-64/sfsyscall.h b/librz/include/sflib/linux-x86-64/sfsyscall.h similarity index 100% rename from libr/include/sflib/linux-x86-64/sfsyscall.h rename to librz/include/sflib/linux-x86-64/sfsyscall.h diff --git a/libr/include/sflib/linux-x86-64/sfsysnr.h b/librz/include/sflib/linux-x86-64/sfsysnr.h similarity index 100% rename from libr/include/sflib/linux-x86-64/sfsysnr.h rename to librz/include/sflib/linux-x86-64/sfsysnr.h diff --git a/libr/io/Makefile b/librz/io/Makefile similarity index 82% rename from libr/io/Makefile rename to librz/io/Makefile index 16fd876c1d..27da082fdd 100644 --- a/libr/io/Makefile +++ b/librz/io/Makefile @@ -1,11 +1,11 @@ include ../config.mk -NAME=r_io -R2DEPS+=r_util -R2DEPS+=r_socket -R2DEPS+=r_hash -R2DEPS+=r_cons -R2DEPS+=r_crypto +NAME=rz_io +R2DEPS+=rz_util +R2DEPS+=rz_socket +R2DEPS+=rz_hash +R2DEPS+=rz_cons +R2DEPS+=rz_crypto STATIC_OBJS=$(subst ..,p/..,$(subst io_,p/io_,$(STATIC_OBJ))) OBJS=${STATIC_OBJS} OBJS+=io.o io_plugin.o io_map.o io_desc.o io_cache.o p_cache.o undo.o ioutils.o io_fd.o @@ -33,7 +33,7 @@ ifeq (${BUILD_OS},dragonfly) endif .PHONY: pre -pre: libr_io.${EXT_SO} libr_io.${EXT_AR} +pre: librz_io.${EXT_SO} librz_io.${EXT_AR} @${MAKE} -C p include ${STATIC_IO_PLUGINS} diff --git a/libr/io/README b/librz/io/README similarity index 100% rename from libr/io/README rename to librz/io/README diff --git a/libr/io/io.c b/librz/io/io.c similarity index 51% rename from libr/io/io.c rename to librz/io/io.c index acede59c4c..0daa49dece 100644 --- a/libr/io/io.c +++ b/librz/io/io.c @@ -1,49 +1,49 @@ -/* radare2 - LGPL - Copyright 2008-2019 - condret, pancake, alvaro_fe */ +/* rizin - LGPL - Copyright 2008-2019 - condret, pancake, alvaro_fe */ -#include +#include #include #include #include "io_private.h" -R_LIB_VERSION (r_io); +R_LIB_VERSION (rz_io); -static int fd_read_at_wrap (RIO *io, int fd, ut64 addr, ut8 *buf, int len, RIOMap *map, void *user) { - return r_io_fd_read_at (io, fd, addr, buf, len); +static int fd_read_at_wrap (RzIO *io, int fd, ut64 addr, ut8 *buf, int len, RzIOMap *map, void *user) { + return rz_io_fd_read_at (io, fd, addr, buf, len); } -static int fd_write_at_wrap (RIO *io, int fd, ut64 addr, ut8 *buf, int len, RIOMap *map, void *user) { - return r_io_fd_write_at (io, fd, addr, buf, len); +static int fd_write_at_wrap (RzIO *io, int fd, ut64 addr, ut8 *buf, int len, RzIOMap *map, void *user) { + return rz_io_fd_write_at (io, fd, addr, buf, len); } -typedef int (*cbOnIterMap)(RIO *io, int fd, ut64 addr, ut8 *buf, int len, RIOMap *map, void *user); +typedef int (*cbOnIterMap)(RzIO *io, int fd, ut64 addr, ut8 *buf, int len, RzIOMap *map, void *user); // If prefix_mode is true, returns the number of bytes of operated prefix; returns < 0 on error. // If prefix_mode is false, operates in non-stop mode and returns true iff all IO operations on overlapped maps are complete. -static st64 on_map_skyline(RIO *io, ut64 vaddr, ut8 *buf, int len, int match_flg, cbOnIterMap op, bool prefix_mode) { +static st64 on_map_skyline(RzIO *io, ut64 vaddr, ut8 *buf, int len, int match_flg, cbOnIterMap op, bool prefix_mode) { const RPVector *skyline = &io->map_skyline; ut64 addr = vaddr; size_t i; bool ret = true, wrap = !prefix_mode && vaddr + len < vaddr; -#define CMP(addr, part) ((addr) < r_itv_end (((RIOMapSkyline *)(part))->itv) - 1 ? -1 : \ - (addr) > r_itv_end (((RIOMapSkyline *)(part))->itv) - 1 ? 1 : 0) +#define CMP(addr, part) ((addr) < rz_itv_end (((RzIOMapSkyline *)(part))->itv) - 1 ? -1 : \ + (addr) > rz_itv_end (((RzIOMapSkyline *)(part))->itv) - 1 ? 1 : 0) // Let i be the first skyline part whose right endpoint > addr if (!len) { - i = r_pvector_len (skyline); + i = rz_pvector_len (skyline); } else { - r_pvector_lower_bound (skyline, addr, i, CMP); - if (i == r_pvector_len (skyline) && wrap) { + rz_pvector_lower_bound (skyline, addr, i, CMP); + if (i == rz_pvector_len (skyline) && wrap) { wrap = false; i = 0; addr = 0; } } #undef CMP - while (i < r_pvector_len (skyline)) { - const RIOMapSkyline *part = r_pvector_at (skyline, i); + while (i < rz_pvector_len (skyline)) { + const RzIOMapSkyline *part = rz_pvector_at (skyline, i); // Right endpoint <= addr - if (r_itv_end (part->itv) - 1 < addr) { + if (rz_itv_end (part->itv) - 1 < addr) { i++; - if (wrap && i == r_pvector_len (skyline)) { + if (wrap && i == rz_pvector_len (skyline)) { wrap = false; i = 0; addr = 0; @@ -58,7 +58,7 @@ static st64 on_map_skyline(RIO *io, ut64 vaddr, ut8 *buf, int len, int match_flg addr = part->itv.addr; } // Now left endpoint <= addr < right endpoint - ut64 len1 = R_MIN (vaddr + len - addr, r_itv_end (part->itv) - addr); + ut64 len1 = R_MIN (vaddr + len - addr, rz_itv_end (part->itv) - addr); if (len1 < 1) { break; } @@ -98,45 +98,45 @@ static st64 on_map_skyline(RIO *io, ut64 vaddr, ut8 *buf, int len, int match_flg return prefix_mode ? addr - vaddr : ret; } -R_API RIO* r_io_new(void) { - return r_io_init (R_NEW0 (RIO)); +RZ_API RzIO* rz_io_new(void) { + return rz_io_init (R_NEW0 (RzIO)); } -R_API RIO* r_io_init(RIO* io) { - r_return_val_if_fail (io, NULL); +RZ_API RzIO* rz_io_init(RzIO* io) { + rz_return_val_if_fail (io, NULL); io->addrbytes = 1; - r_io_desc_init (io); - r_pvector_init (&io->map_skyline, free); - r_io_map_init (io); - r_io_cache_init (io); - r_io_plugin_init (io); - r_io_undo_init (io); + rz_io_desc_init (io); + rz_pvector_init (&io->map_skyline, free); + rz_io_map_init (io); + rz_io_cache_init (io); + rz_io_plugin_init (io); + rz_io_undo_init (io); return io; } -R_API void r_io_free(RIO *io) { +RZ_API void rz_io_free(RzIO *io) { if (io) { - r_io_fini (io); - r_cache_free (io->buffer); + rz_io_fini (io); + rz_cache_free (io->buffer); free (io); } } -R_API RIODesc *r_io_open_buffer(RIO *io, RBuffer *b, int perm, int mode) { - ut64 bufSize = r_buf_size (b); - char *uri = r_str_newf ("malloc://%d", bufSize); - RIODesc *desc = r_io_open_nomap (io, uri, perm, mode); +RZ_API RzIODesc *rz_io_open_buffer(RzIO *io, RBuffer *b, int perm, int mode) { + ut64 bufSize = rz_buf_size (b); + char *uri = rz_str_newf ("malloc://%d", bufSize); + RzIODesc *desc = rz_io_open_nomap (io, uri, perm, mode); if (desc) { - const ut8 *tmp = r_buf_data (b, &bufSize); - r_io_desc_write (desc, tmp, bufSize); + const ut8 *tmp = rz_buf_data (b, &bufSize); + rz_io_desc_write (desc, tmp, bufSize); } free (uri); return desc; } -R_API RIODesc *r_io_open_nomap(RIO *io, const char *uri, int perm, int mode) { - r_return_val_if_fail (io && uri, NULL); - RIODesc *desc = r_io_desc_open (io, uri, perm, mode); +RZ_API RzIODesc *rz_io_open_nomap(RzIO *io, const char *uri, int perm, int mode) { + rz_return_val_if_fail (io && uri, NULL); + RzIODesc *desc = rz_io_desc_open (io, uri, perm, mode); if ((io->autofd || !io->desc) && desc) { io->desc = desc; } @@ -145,24 +145,24 @@ R_API RIODesc *r_io_open_nomap(RIO *io, const char *uri, int perm, int mode) { } /* opens a file and maps it to 0x0 */ -R_API RIODesc* r_io_open(RIO* io, const char* uri, int perm, int mode) { - r_return_val_if_fail (io, NULL); - RIODesc* desc = r_io_open_nomap (io, uri, perm, mode); +RZ_API RzIODesc* rz_io_open(RzIO* io, const char* uri, int perm, int mode) { + rz_return_val_if_fail (io, NULL); + RzIODesc* desc = rz_io_open_nomap (io, uri, perm, mode); if (desc) { - r_io_map_new (io, desc->fd, desc->perm, 0LL, 0LL, r_io_desc_size (desc)); + rz_io_map_new (io, desc->fd, desc->perm, 0LL, 0LL, rz_io_desc_size (desc)); } return desc; } /* opens a file and maps it to an offset specified by the "at"-parameter */ -R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int perm, int mode, ut64 at) { - r_return_val_if_fail (io && uri, NULL); +RZ_API RzIODesc* rz_io_open_at(RzIO* io, const char* uri, int perm, int mode, ut64 at) { + rz_return_val_if_fail (io && uri, NULL); - RIODesc* desc = r_io_open_nomap (io, uri, perm, mode); + RzIODesc* desc = rz_io_open_nomap (io, uri, perm, mode); if (!desc) { return NULL; } - ut64 size = r_io_desc_size (desc); + ut64 size = rz_io_desc_size (desc); // second map if (size && ((UT64_MAX - size + 1) < at)) { // split map into 2 maps if only 1 big map results into interger overflow @@ -171,24 +171,24 @@ R_API RIODesc* r_io_open_at(RIO* io, const char* uri, int perm, int mode, ut64 a size = UT64_MAX - at + 1; } // skyline not updated - r_io_map_new (io, desc->fd, desc->perm, 0LL, at, size); + rz_io_map_new (io, desc->fd, desc->perm, 0LL, at, size); return desc; } /* opens many files, without mapping them. This should be discussed */ -R_API RList* r_io_open_many(RIO* io, const char* uri, int perm, int mode) { - RList* desc_list; - RListIter* iter; - RIODesc* desc; - r_return_val_if_fail (io && io->files && uri, NULL); - RIOPlugin* plugin = r_io_plugin_resolve (io, uri, 1); +RZ_API RzList* rz_io_open_many(RzIO* io, const char* uri, int perm, int mode) { + RzList* desc_list; + RzListIter* iter; + RzIODesc* desc; + rz_return_val_if_fail (io && io->files && uri, NULL); + RzIOPlugin* plugin = rz_io_plugin_resolve (io, uri, 1); if (!plugin || !plugin->open_many || !plugin->close) { return NULL; } if (!(desc_list = plugin->open_many (io, uri, perm, mode))) { return NULL; } - r_list_foreach (desc_list, iter, desc) { + rz_list_foreach (desc_list, iter, desc) { if (desc) { if (!desc->plugin) { desc->plugin = plugin; @@ -197,7 +197,7 @@ R_API RList* r_io_open_many(RIO* io, const char* uri, int perm, int mode) { desc->uri = strdup (uri); } //should autofd be honored here? - r_io_desc_add (io, desc); + rz_io_desc_add (io, desc); if (!io->desc) { io->desc = desc; } @@ -206,88 +206,88 @@ R_API RList* r_io_open_many(RIO* io, const char* uri, int perm, int mode) { return desc_list; } -R_API bool r_io_reopen(RIO* io, int fd, int perm, int mode) { - RIODesc *old, *new; +RZ_API bool rz_io_reopen(RzIO* io, int fd, int perm, int mode) { + RzIODesc *old, *new; char *uri; - if (!(old = r_io_desc_get (io, fd))) { + if (!(old = rz_io_desc_get (io, fd))) { return false; } //does this really work, or do we have to handler debuggers ugly uri = old->referer? old->referer: old->uri; -#if __WINDOWS__ //TODO: workaround, see https://github.com/radareorg/radare2/issues/8840 +#if __WINDOWS__ //TODO: workaround, see https://github.com/rizinorg/rizin/issues/8840 if (old->plugin->close && old->plugin->close (old)) { return false; // TODO: this is an unrecoverable scenario } - if (!(new = r_io_open_nomap (io, uri, perm, mode))) { + if (!(new = rz_io_open_nomap (io, uri, perm, mode))) { return false; } - r_io_desc_exchange (io, old->fd, new->fd); - r_io_desc_del (io, old->fd); + rz_io_desc_exchange (io, old->fd, new->fd); + rz_io_desc_del (io, old->fd); return true; #else - if (!(new = r_io_open_nomap (io, uri, perm, mode))) { + if (!(new = rz_io_open_nomap (io, uri, perm, mode))) { return false; } - r_io_desc_exchange (io, old->fd, new->fd); - return r_io_desc_close (old); // magic + rz_io_desc_exchange (io, old->fd, new->fd); + return rz_io_desc_close (old); // magic #endif // __WINDOWS__ } -R_API int r_io_close_all(RIO* io) { // what about undo? +RZ_API int rz_io_close_all(RzIO* io) { // what about undo? if (!io) { return false; } - r_io_desc_fini (io); - r_io_map_fini (io); + rz_io_desc_fini (io); + rz_io_map_fini (io); ls_free (io->plugins); - r_io_desc_init (io); - r_io_map_init (io); - r_io_cache_fini (io); - r_io_plugin_init (io); + rz_io_desc_init (io); + rz_io_map_init (io); + rz_io_cache_fini (io); + rz_io_plugin_init (io); return true; } -R_API int r_io_pread_at(RIO* io, ut64 paddr, ut8* buf, int len) { - r_return_val_if_fail (io && buf && len >= 0, -1); +RZ_API int rz_io_pread_at(RzIO* io, ut64 paddr, ut8* buf, int len) { + rz_return_val_if_fail (io && buf && len >= 0, -1); if (io->ff) { memset (buf, io->Oxff, len); } - return r_io_desc_read_at (io->desc, paddr, buf, len); + return rz_io_desc_read_at (io->desc, paddr, buf, len); } -R_API int r_io_pwrite_at(RIO* io, ut64 paddr, const ut8* buf, int len) { - r_return_val_if_fail (io && buf && len > 0, -1); - return r_io_desc_write_at (io->desc, paddr, buf, len); +RZ_API int rz_io_pwrite_at(RzIO* io, ut64 paddr, const ut8* buf, int len) { + rz_return_val_if_fail (io && buf && len > 0, -1); + return rz_io_desc_write_at (io->desc, paddr, buf, len); } // Returns true iff all reads on mapped regions are successful and complete. -R_API bool r_io_vread_at_mapped(RIO* io, ut64 vaddr, ut8* buf, int len) { - r_return_val_if_fail (io && buf && len > 0, false); +RZ_API bool rz_io_vread_at_mapped(RzIO* io, ut64 vaddr, ut8* buf, int len) { + rz_return_val_if_fail (io && buf && len > 0, false); if (io->ff) { memset (buf, io->Oxff, len); } return on_map_skyline (io, vaddr, buf, len, R_PERM_R, fd_read_at_wrap, false); } -static bool r_io_vwrite_at(RIO* io, ut64 vaddr, const ut8* buf, int len) { +static bool rz_io_vwrite_at(RzIO* io, ut64 vaddr, const ut8* buf, int len) { return on_map_skyline (io, vaddr, (ut8*)buf, len, R_PERM_W, fd_write_at_wrap, false); } -// Deprecated, use either r_io_read_at_mapped or r_io_nread_at instead. +// Deprecated, use either rz_io_read_at_mapped or rz_io_nread_at instead. // For virtual mode, returns true if all reads on mapped regions are successful // and complete. // For physical mode, the interface is broken because the actual read bytes are // not available. This requires fixes in all call sites. -R_API bool r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) { - r_return_val_if_fail (io && buf && len >= 0, false); +RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len) { + rz_return_val_if_fail (io && buf && len >= 0, false); if (len == 0) { return false; } bool ret = (io->va) - ? r_io_vread_at_mapped (io, addr, buf, len) - : r_io_pread_at (io, addr, buf, len) > 0; + ? rz_io_vread_at_mapped (io, addr, buf, len) + : rz_io_pread_at (io, addr, buf, len) > 0; if (io->cached & R_PERM_R) { - (void)r_io_cache_read (io, addr, buf, len); + (void)rz_io_cache_read (io, addr, buf, len); } return ret; } @@ -296,19 +296,19 @@ R_API bool r_io_read_at(RIO *io, ut64 addr, ut8 *buf, int len) { // Unmapped regions are filled with io->Oxff in both physical and virtual modes. // Use this function if you want to ignore gaps or do not care about the number // of read bytes. -R_API bool r_io_read_at_mapped(RIO *io, ut64 addr, ut8 *buf, int len) { +RZ_API bool rz_io_read_at_mapped(RzIO *io, ut64 addr, ut8 *buf, int len) { bool ret; - r_return_val_if_fail (io && buf, false); + rz_return_val_if_fail (io && buf, false); if (io->ff) { memset (buf, io->Oxff, len); } if (io->va) { ret = on_map_skyline (io, addr, buf, len, R_PERM_R, fd_read_at_wrap, false); } else { - ret = r_io_pread_at (io, addr, buf, len) > 0; + ret = rz_io_pread_at (io, addr, buf, len) > 0; } if (io->cached & R_PERM_R) { - (void)r_io_cache_read(io, addr, buf, len); + (void)rz_io_cache_read(io, addr, buf, len); } return ret; } @@ -316,9 +316,9 @@ R_API bool r_io_read_at_mapped(RIO *io, ut64 addr, ut8 *buf, int len) { // For both virtual and physical mode, returns the number of bytes of read // prefix. // Returns -1 on error. -R_API int r_io_nread_at(RIO *io, ut64 addr, ut8 *buf, int len) { +RZ_API int rz_io_nread_at(RzIO *io, ut64 addr, ut8 *buf, int len) { int ret; - r_return_val_if_fail (io && buf && len >= 0, -1); + rz_return_val_if_fail (io && buf && len >= 0, -1); if (len == 0) { return 0; } @@ -328,32 +328,32 @@ R_API int r_io_nread_at(RIO *io, ut64 addr, ut8 *buf, int len) { } ret = on_map_skyline (io, addr, buf, len, R_PERM_R, fd_read_at_wrap, true); } else { - ret = r_io_pread_at (io, addr, buf, len); + ret = rz_io_pread_at (io, addr, buf, len); } if (ret > 0 && io->cached & R_PERM_R) { - (void)r_io_cache_read (io, addr, buf, len); + (void)rz_io_cache_read (io, addr, buf, len); } return ret; } -R_API bool r_io_write_at(RIO* io, ut64 addr, const ut8* buf, int len) { +RZ_API bool rz_io_write_at(RzIO* io, ut64 addr, const ut8* buf, int len) { int i; bool ret = false; ut8 *mybuf = (ut8*)buf; - r_return_val_if_fail (io && buf && len > 0, false); + rz_return_val_if_fail (io && buf && len > 0, false); if (io->write_mask) { - mybuf = r_mem_dup ((void*)buf, len); + mybuf = rz_mem_dup ((void*)buf, len); for (i = 0; i < len; i++) { //this sucks mybuf[i] &= io->write_mask[i % io->write_mask_len]; } } if (io->cached & R_PERM_W) { - ret = r_io_cache_write (io, addr, mybuf, len); + ret = rz_io_cache_write (io, addr, mybuf, len); } else if (io->va) { - ret = r_io_vwrite_at (io, addr, mybuf, len); + ret = rz_io_vwrite_at (io, addr, mybuf, len); } else { - ret = r_io_pwrite_at (io, addr, mybuf, len) > 0; + ret = rz_io_pwrite_at (io, addr, mybuf, len) > 0; } if (buf != mybuf) { free (mybuf); @@ -361,64 +361,64 @@ R_API bool r_io_write_at(RIO* io, ut64 addr, const ut8* buf, int len) { return ret; } -R_API bool r_io_read(RIO* io, ut8* buf, int len) { - if (io && r_io_read_at (io, io->off, buf, len)) { +RZ_API bool rz_io_read(RzIO* io, ut8* buf, int len) { + if (io && rz_io_read_at (io, io->off, buf, len)) { io->off += len; return true; } return false; } -R_API bool r_io_write(RIO* io, ut8* buf, int len) { - if (io && buf && len > 0 && r_io_write_at (io, io->off, buf, len)) { +RZ_API bool rz_io_write(RzIO* io, ut8* buf, int len) { + if (io && buf && len > 0 && rz_io_write_at (io, io->off, buf, len)) { io->off += len; return true; } return false; } -R_API ut64 r_io_size(RIO* io) { +RZ_API ut64 rz_io_size(RzIO* io) { // TODO: rethink this, maybe not needed - return io? r_io_desc_size (io->desc): 0LL; + return io? rz_io_desc_size (io->desc): 0LL; } -R_API bool r_io_is_listener(RIO* io) { +RZ_API bool rz_io_is_listener(RzIO* io) { if (io && io->desc && io->desc->plugin && io->desc->plugin->listener) { return io->desc->plugin->listener (io->desc); } return false; } -R_API char *r_io_system(RIO* io, const char* cmd) { +RZ_API char *rz_io_system(RzIO* io, const char* cmd) { if (io && io->desc && io->desc->plugin && io->desc->plugin->system) { return io->desc->plugin->system (io, io->desc, cmd); } return NULL; } -R_API bool r_io_resize(RIO* io, ut64 newsize) { +RZ_API bool rz_io_resize(RzIO* io, ut64 newsize) { if (io) { - RList *maps = r_io_map_get_for_fd (io, io->desc->fd); - RIOMap *current_map; - RListIter *iter; - ut64 fd_size = r_io_fd_size (io, io->desc->fd); - r_list_foreach (maps, iter, current_map) { + RzList *maps = rz_io_map_get_for_fd (io, io->desc->fd); + RzIOMap *current_map; + RzListIter *iter; + ut64 fd_size = rz_io_fd_size (io, io->desc->fd); + rz_list_foreach (maps, iter, current_map) { // we just resize map of the same size of its fd if (current_map->itv.size == fd_size) { - r_io_map_resize (io, current_map->id, newsize); + rz_io_map_resize (io, current_map->id, newsize); } } - r_list_free (maps); - return r_io_desc_resize (io->desc, newsize); + rz_list_free (maps); + return rz_io_desc_resize (io->desc, newsize); } return false; } -R_API bool r_io_close(RIO *io) { - return io ? r_io_desc_close (io->desc) : false; +RZ_API bool rz_io_close(RzIO *io) { + return io ? rz_io_desc_close (io->desc) : false; } -R_API int r_io_extend_at(RIO* io, ut64 addr, ut64 size) { +RZ_API int rz_io_extend_at(RzIO* io, ut64 addr, ut64 size) { ut64 cur_size, tmp_size; ut8* buffer; if (!io || !io->desc || !io->desc->plugin || !size) { @@ -427,8 +427,8 @@ R_API int r_io_extend_at(RIO* io, ut64 addr, ut64 size) { if (io->desc->plugin->extend) { int ret; ut64 cur_off = io->off; - r_io_seek (io, addr, R_IO_SEEK_SET); - ret = r_io_desc_extend (io->desc, size); + rz_io_seek (io, addr, R_IO_SEEK_SET); + ret = rz_io_desc_extend (io->desc, size); //no need to seek here io->off = cur_off; return ret; @@ -436,14 +436,14 @@ R_API int r_io_extend_at(RIO* io, ut64 addr, ut64 size) { if ((io->desc->perm & R_PERM_RW) != R_PERM_RW) { return false; } - cur_size = r_io_desc_size (io->desc); + cur_size = rz_io_desc_size (io->desc); if (addr > cur_size) { return false; } if ((UT64_MAX - size) < cur_size) { return false; } - if (!r_io_resize (io, cur_size + size)) { + if (!rz_io_resize (io, cur_size + size)) { return false; } if ((tmp_size = cur_size - addr) == 0LL) { @@ -452,19 +452,19 @@ R_API int r_io_extend_at(RIO* io, ut64 addr, ut64 size) { if (!(buffer = calloc (1, (size_t) tmp_size + 1))) { return false; } - r_io_pread_at (io, addr, buffer, (int) tmp_size); + rz_io_pread_at (io, addr, buffer, (int) tmp_size); /* fill with null bytes */ ut8 *empty = calloc (1, size); if (empty) { - r_io_pwrite_at (io, addr, empty, size); + rz_io_pwrite_at (io, addr, empty, size); free (empty); } - r_io_pwrite_at (io, addr + size, buffer, (int) tmp_size); + rz_io_pwrite_at (io, addr + size, buffer, (int) tmp_size); free (buffer); return true; } -R_API bool r_io_set_write_mask(RIO* io, const ut8* mask, int len) { +RZ_API bool rz_io_set_write_mask(RzIO* io, const ut8* mask, int len) { if (!io || len < 1) { return false; } @@ -480,16 +480,16 @@ R_API bool r_io_set_write_mask(RIO* io, const ut8* mask, int len) { return true; } -R_API ut64 r_io_p2v(RIO *io, ut64 pa) { - RIOMap *map = r_io_map_get_paddr (io, pa); +RZ_API ut64 rz_io_p2v(RzIO *io, ut64 pa) { + RzIOMap *map = rz_io_map_get_paddr (io, pa); if (map) { return pa - map->delta + map->itv.addr; } return UT64_MAX; } -R_API ut64 r_io_v2p(RIO *io, ut64 va) { - RIOMap *map = r_io_map_get (io, va); +RZ_API ut64 rz_io_v2p(RzIO *io, ut64 va) { + RzIOMap *map = rz_io_map_get (io, va); if (map) { st64 delta = va - map->itv.addr; return map->itv.addr + map->delta + delta; @@ -497,52 +497,52 @@ R_API ut64 r_io_v2p(RIO *io, ut64 va) { return UT64_MAX; } -R_API void r_io_bind(RIO *io, RIOBind *bnd) { - r_return_if_fail (io && bnd); +RZ_API void rz_io_bind(RzIO *io, RzIOBind *bnd) { + rz_return_if_fail (io && bnd); bnd->io = io; bnd->init = true; - bnd->desc_use = r_io_use_fd; - bnd->desc_get = r_io_desc_get; - bnd->desc_size = r_io_desc_size; - bnd->p2v = r_io_p2v; - bnd->v2p = r_io_v2p; - bnd->open = r_io_open_nomap; - bnd->open_at = r_io_open_at; - bnd->close = r_io_fd_close; - bnd->read_at = r_io_read_at; - bnd->write_at = r_io_write_at; - bnd->system = r_io_system; - bnd->fd_open = r_io_fd_open; - bnd->fd_close = r_io_fd_close; - bnd->fd_seek = r_io_fd_seek; - bnd->fd_size = r_io_fd_size; - bnd->fd_resize = r_io_fd_resize; - bnd->fd_read = r_io_fd_read; - bnd->fd_write = r_io_fd_write; - bnd->fd_read_at = r_io_fd_read_at; - bnd->fd_write_at = r_io_fd_write_at; - bnd->fd_is_dbg = r_io_fd_is_dbg; - bnd->fd_get_name = r_io_fd_get_name; - bnd->fd_get_map = r_io_map_get_for_fd; - bnd->fd_remap = r_io_map_remap_fd; - bnd->is_valid_offset = r_io_is_valid_offset; - bnd->map_get = r_io_map_get; - bnd->map_get_paddr = r_io_map_get_paddr; - bnd->addr_is_mapped = r_io_addr_is_mapped; - bnd->map_add = r_io_map_add; + bnd->desc_use = rz_io_use_fd; + bnd->desc_get = rz_io_desc_get; + bnd->desc_size = rz_io_desc_size; + bnd->p2v = rz_io_p2v; + bnd->v2p = rz_io_v2p; + bnd->open = rz_io_open_nomap; + bnd->open_at = rz_io_open_at; + bnd->close = rz_io_fd_close; + bnd->read_at = rz_io_read_at; + bnd->write_at = rz_io_write_at; + bnd->system = rz_io_system; + bnd->fd_open = rz_io_fd_open; + bnd->fd_close = rz_io_fd_close; + bnd->fd_seek = rz_io_fd_seek; + bnd->fd_size = rz_io_fd_size; + bnd->fd_resize = rz_io_fd_resize; + bnd->fd_read = rz_io_fd_read; + bnd->fd_write = rz_io_fd_write; + bnd->fd_read_at = rz_io_fd_read_at; + bnd->fd_write_at = rz_io_fd_write_at; + bnd->fd_is_dbg = rz_io_fd_is_dbg; + bnd->fd_get_name = rz_io_fd_get_name; + bnd->fd_get_map = rz_io_map_get_for_fd; + bnd->fd_remap = rz_io_map_remap_fd; + bnd->is_valid_offset = rz_io_is_valid_offset; + bnd->map_get = rz_io_map_get; + bnd->map_get_paddr = rz_io_map_get_paddr; + bnd->addr_is_mapped = rz_io_addr_is_mapped; + bnd->map_add = rz_io_map_add; #if HAVE_PTRACE - bnd->ptrace = r_io_ptrace; - bnd->ptrace_func = r_io_ptrace_func; + bnd->ptrace = rz_io_ptrace; + bnd->ptrace_func = rz_io_ptrace_func; #endif } /* moves bytes up (+) or down (-) within the specified range */ -R_API bool r_io_shift(RIO* io, ut64 start, ut64 end, st64 move) { +RZ_API bool rz_io_shift(RzIO* io, ut64 start, ut64 end, st64 move) { ut8* buf; ut64 chunksize = 0x10000; ut64 saved_off = io->off; - ut64 src, shiftsize = r_num_abs (move); + ut64 src, shiftsize = rz_num_abs (move); if (!shiftsize || (end - start) <= shiftsize) { return false; } @@ -562,19 +562,19 @@ R_API bool r_io_shift(RIO* io, ut64 start, ut64 end, st64 move) { if (move > 0) { src -= chunksize; } - r_io_read_at (io, src, buf, chunksize); - r_io_write_at (io, src + move, buf, chunksize); + rz_io_read_at (io, src, buf, chunksize); + rz_io_write_at (io, src + move, buf, chunksize); if (move < 0) { src += chunksize; } rest -= chunksize; } free (buf); - io->off = r_io_desc_seek (io->desc, saved_off, R_IO_SEEK_SET); + io->off = rz_io_desc_seek (io->desc, saved_off, R_IO_SEEK_SET); return true; } -R_API ut64 r_io_seek(RIO* io, ut64 offset, int whence) { +RZ_API ut64 rz_io_seek(RzIO* io, ut64 offset, int whence) { if (!io) { return 0LL; } @@ -587,7 +587,7 @@ R_API ut64 r_io_seek(RIO* io, ut64 offset, int whence) { break; case R_IO_SEEK_END: default: - io->off = r_io_desc_seek (io->desc, offset, whence); + io->off = rz_io_desc_seek (io->desc, offset, whence); break; } return io->off; @@ -599,7 +599,7 @@ R_API ut64 r_io_seek(RIO* io, ut64 offset, int whence) { #include #include -static ptrace_wrap_instance *io_ptrace_wrap_instance(RIO *io) { +static ptrace_wrap_instance *io_ptrace_wrap_instance(RzIO *io) { if (!io->ptrace_wrap) { io->ptrace_wrap = R_NEW (ptrace_wrap_instance); if (!io->ptrace_wrap) { @@ -614,7 +614,7 @@ static ptrace_wrap_instance *io_ptrace_wrap_instance(RIO *io) { } #endif -R_API long r_io_ptrace(RIO *io, r_ptrace_request_t request, pid_t pid, void *addr, r_ptrace_data_t data) { +RZ_API long rz_io_ptrace(RzIO *io, rz_ptrace_request_t request, pid_t pid, void *addr, rz_ptrace_data_t data) { #if USE_PTRACE_WRAP ptrace_wrap_instance *wrap = io_ptrace_wrap_instance (io); if (!wrap) { @@ -627,7 +627,7 @@ R_API long r_io_ptrace(RIO *io, r_ptrace_request_t request, pid_t pid, void *add #endif } -R_API pid_t r_io_ptrace_fork(RIO *io, void (*child_callback)(void *), void *child_callback_user) { +RZ_API pid_t rz_io_ptrace_fork(RzIO *io, void (*child_callback)(void *), void *child_callback_user) { #if USE_PTRACE_WRAP ptrace_wrap_instance *wrap = io_ptrace_wrap_instance (io); if (!wrap) { @@ -636,7 +636,7 @@ R_API pid_t r_io_ptrace_fork(RIO *io, void (*child_callback)(void *), void *chil } return ptrace_wrap_fork (wrap, child_callback, child_callback_user); #else - pid_t r = r_sys_fork (); + pid_t r = rz_sys_fork (); if (r == 0) { child_callback (child_callback_user); } @@ -644,7 +644,7 @@ R_API pid_t r_io_ptrace_fork(RIO *io, void (*child_callback)(void *), void *chil #endif } -R_API void *r_io_ptrace_func(RIO *io, void *(*func)(void *), void *user) { +RZ_API void *rz_io_ptrace_func(RzIO *io, void *(*func)(void *), void *user) { #if USE_PTRACE_WRAP ptrace_wrap_instance *wrap = io_ptrace_wrap_instance (io); if (wrap) { @@ -657,16 +657,16 @@ R_API void *r_io_ptrace_func(RIO *io, void *(*func)(void *), void *user) { //remove all descs and maps -R_API int r_io_fini(RIO* io) { +RZ_API int rz_io_fini(RzIO* io) { if (!io) { return false; } - r_io_desc_cache_fini_all (io); - r_io_desc_fini (io); - r_io_map_fini (io); + rz_io_desc_cache_fini_all (io); + rz_io_desc_fini (io); + rz_io_map_fini (io); ls_free (io->plugins); - r_list_free (io->cache); - r_list_free (io->undo.w_list); + rz_list_free (io->cache); + rz_list_free (io->undo.w_list); if (io->runprofile) { R_FREE (io->runprofile); } diff --git a/libr/io/io_cache.c b/librz/io/io_cache.c similarity index 56% rename from libr/io/io_cache.c rename to librz/io/io_cache.c index 0e5baf8e93..7d3bfe3585 100644 --- a/libr/io/io_cache.c +++ b/librz/io/io_cache.c @@ -2,17 +2,17 @@ // TODO: implement a more intelligent way to store cached memory -#include "r_io.h" +#include "rz_io.h" #if 0 #define CACHE_CONTAINER(x) container_of ((RBNode*)x, RCache, rb) static void _fcn_tree_calc_max_addr(RBNode *node) { - RIOCache *c = CACHE_CONTAINER (node); + RzIOCache *c = CACHE_CONTAINER (node); } #endif // 0 -static void cache_item_free(RIOCache *cache) { +static void cache_item_free(RzIOCache *cache) { if (!cache) { return; } @@ -21,44 +21,44 @@ static void cache_item_free(RIOCache *cache) { free (cache); } -R_API bool r_io_cache_at(RIO *io, ut64 addr) { - RIOCache *c; - RListIter *iter; - r_list_foreach (io->cache, iter, c) { - if (r_itv_contain (c->itv, addr)) { +RZ_API bool rz_io_cache_at(RzIO *io, ut64 addr) { + RzIOCache *c; + RzListIter *iter; + rz_list_foreach (io->cache, iter, c) { + if (rz_itv_contain (c->itv, addr)) { return true; } } return false; } -R_API void r_io_cache_init(RIO *io) { - io->cache = r_list_newf ((RListFree)cache_item_free); - io->buffer = r_cache_new (); +RZ_API void rz_io_cache_init(RzIO *io) { + io->cache = rz_list_newf ((RzListFree)cache_item_free); + io->buffer = rz_cache_new (); io->cached = 0; } -R_API void r_io_cache_fini (RIO *io) { - r_list_free (io->cache); - r_cache_free (io->buffer); +RZ_API void rz_io_cache_fini (RzIO *io) { + rz_list_free (io->cache); + rz_cache_free (io->buffer); io->cache = NULL; io->buffer = NULL; io->cached = 0; } -R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) { - RListIter *iter; - RIOCache *c; +RZ_API void rz_io_cache_commit(RzIO *io, ut64 from, ut64 to) { + RzListIter *iter; + RzIOCache *c; RInterval range = (RInterval){from, to - from}; - r_list_foreach (io->cache, iter, c) { + rz_list_foreach (io->cache, iter, c) { // if (from <= c->to - 1 && c->from <= to - 1) { - if (r_itv_overlap (c->itv, range)) { + if (rz_itv_overlap (c->itv, range)) { int cached = io->cached; io->cached = 0; - if (r_io_write_at (io, r_itv_begin (c->itv), c->data, r_itv_size (c->itv))) { + if (rz_io_write_at (io, rz_itv_begin (c->itv), c->data, rz_itv_size (c->itv))) { c->written = true; } else { - eprintf ("Error writing change at 0x%08"PFMT64x"\n", r_itv_begin (c->itv)); + eprintf ("Error writing change at 0x%08"PFMT64x"\n", rz_itv_begin (c->itv)); } io->cached = cached; // break; // XXX old behavior, revisit this @@ -66,45 +66,45 @@ R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) { } } -R_API void r_io_cache_reset(RIO *io, int set) { +RZ_API void rz_io_cache_reset(RzIO *io, int set) { io->cached = set; - r_list_purge (io->cache); + rz_list_purge (io->cache); } -R_API int r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) { +RZ_API int rz_io_cache_invalidate(RzIO *io, ut64 from, ut64 to) { int invalidated = 0; - RListIter *iter, *tmp; - RIOCache *c; + RzListIter *iter, *tmp; + RzIOCache *c; RInterval range = (RInterval){from, to - from}; - r_list_foreach_prev_safe (io->cache, iter, tmp, c) { - if (r_itv_overlap (c->itv, range)) { + rz_list_foreach_prev_safe (io->cache, iter, tmp, c) { + if (rz_itv_overlap (c->itv, range)) { int cached = io->cached; io->cached = 0; - r_io_write_at (io, r_itv_begin (c->itv), c->odata, r_itv_size (c->itv)); + rz_io_write_at (io, rz_itv_begin (c->itv), c->odata, rz_itv_size (c->itv)); io->cached = cached; c->written = false; - r_list_delete (io->cache, iter); + rz_list_delete (io->cache, iter); invalidated++; } } return invalidated; } -R_API int r_io_cache_list(RIO *io, int rad) { +RZ_API int rz_io_cache_list(RzIO *io, int rad) { int i, j = 0; - RListIter *iter; - RIOCache *c; + RzListIter *iter; + RzIOCache *c; if (rad == 2) { io->cb_printf ("["); } - r_list_foreach (io->cache, iter, c) { - const int dataSize = r_itv_size (c->itv); + rz_list_foreach (io->cache, iter, c) { + const int dataSize = rz_itv_size (c->itv); if (rad == 1) { io->cb_printf ("wx "); for (i = 0; i < dataSize; i++) { io->cb_printf ("%02x", (ut8)(c->data[i] & 0xff)); } - io->cb_printf (" @ 0x%08"PFMT64x, r_itv_begin (c->itv)); + io->cb_printf (" @ 0x%08"PFMT64x, rz_itv_begin (c->itv)); io->cb_printf (" # replaces: "); for (i = 0; i < dataSize; i++) { io->cb_printf ("%02x", (ut8)(c->odata[i] & 0xff)); @@ -112,7 +112,7 @@ R_API int r_io_cache_list(RIO *io, int rad) { io->cb_printf ("\n"); } else if (rad == 2) { io->cb_printf ("{\"idx\":%"PFMT64d",\"addr\":%"PFMT64d",\"size\":%d,", - j, r_itv_begin (c->itv), dataSize); + j, rz_itv_begin (c->itv), dataSize); io->cb_printf ("\"before\":\""); for (i = 0; i < dataSize; i++) { io->cb_printf ("%02x", c->odata[i]); @@ -124,7 +124,7 @@ R_API int r_io_cache_list(RIO *io, int rad) { io->cb_printf ("\",\"written\":%s}%s", c->written ? "true": "false", iter->n? ",": ""); } else if (rad == 0) { - io->cb_printf ("idx=%d addr=0x%08"PFMT64x" size=%d ", j, r_itv_begin (c->itv), dataSize); + io->cb_printf ("idx=%d addr=0x%08"PFMT64x" size=%d ", j, rz_itv_begin (c->itv), dataSize); for (i = 0; i < dataSize; i++) { io->cb_printf ("%02x", c->odata[i]); } @@ -142,9 +142,9 @@ R_API int r_io_cache_list(RIO *io, int rad) { return false; } -R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) { - RIOCache *ch; - ch = R_NEW0 (RIOCache); +RZ_API bool rz_io_cache_write(RzIO *io, ut64 addr, const ut8 *buf, int len) { + RzIOCache *ch; + ch = R_NEW0 (RzIOCache); if (!ch) { return false; } @@ -164,27 +164,27 @@ R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) { { bool cm = io->cachemode; io->cachemode = false; - r_io_read_at (io, addr, ch->odata, len); + rz_io_read_at (io, addr, ch->odata, len); io->cachemode = cm; } memcpy (ch->data, buf, len); - r_list_append (io->cache, ch); + rz_list_append (io->cache, ch); return true; } -R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) { +RZ_API bool rz_io_cache_read(RzIO *io, ut64 addr, ut8 *buf, int len) { bool covered = false; - RListIter *iter; - RIOCache *c; + RzListIter *iter; + RzIOCache *c; RInterval range = (RInterval){ addr, len }; - r_list_foreach (io->cache, iter, c) { - if (r_itv_overlap (c->itv, range)) { - const ut64 begin = r_itv_begin (c->itv); + rz_list_foreach (io->cache, iter, c) { + if (rz_itv_overlap (c->itv, range)) { + const ut64 begin = rz_itv_begin (c->itv); if (addr < begin) { - int l = R_MIN (addr + len - begin, r_itv_size (c->itv)); + int l = R_MIN (addr + len - begin, rz_itv_size (c->itv)); memcpy (buf + begin - addr, c->data, l); } else { - int l = R_MIN (r_itv_end (c->itv) - addr, len); + int l = R_MIN (rz_itv_end (c->itv) - addr, len); memcpy (buf, c->data + addr - begin, l); } covered = true; diff --git a/librz/io/io_desc.c b/librz/io/io_desc.c new file mode 100644 index 0000000000..d1f7d164ae --- /dev/null +++ b/librz/io/io_desc.c @@ -0,0 +1,356 @@ +/* rizin - LGPL - Copyright 2017-2019 - condret, pancake, alvaro */ + +#include +#include +#include + +//shall be used by plugins for creating descs +//XXX kill mode +RZ_API RzIODesc* rz_io_desc_new(RzIO* io, RzIOPlugin* plugin, const char* uri, int perm, int mode, void* data) { + ut32 fd32 = 0; + // this is required for emscripten builds to work, but should assert + if (!io || !plugin || !uri) { + return NULL; + } + if (io->files) { + if (!rz_id_pool_grab_id (io->files->pool, &fd32)) { + return NULL; + } + } + RzIODesc* desc = R_NEW0 (RzIODesc); + if (desc) { + desc->fd = fd32; + desc->io = io; + desc->plugin = plugin; + desc->data = data; + desc->perm = perm; + //because the uri-arg may live on the stack + desc->uri = strdup (uri); + } + return desc; +} + +RZ_API void rz_io_desc_free(RzIODesc* desc) { + if (desc) { + free (desc->uri); + free (desc->referer); + free (desc->name); + rz_io_desc_cache_fini (desc); + if (desc->io && desc->io->files) { + rz_id_storage_delete (desc->io->files, desc->fd); + } +// free (desc->plugin); + } + free (desc); +} + +RZ_API bool rz_io_desc_add(RzIO* io, RzIODesc* desc) { + rz_return_val_if_fail (io && desc && desc->io, false); + if (!rz_id_storage_set (io->files, desc, desc->fd)) { + // TODO: use assert here + eprintf ("You are using this API incorrectly\n"); + eprintf ("fd %d was probably not generated by this RzIO-instance\n", desc->fd); + rz_sys_backtrace (); + return false; + } + return true; +} + +RZ_API bool rz_io_desc_del(RzIO* io, int fd) { //can we pass this a riodesc and check if it belongs to the desc->io ? + rz_return_val_if_fail (io && io->files, false); + RzIODesc* desc = rz_id_storage_get (io->files, fd); + rz_io_desc_free (desc); + if (desc == io->desc) { + io->desc = NULL; + } + // remove all dead maps + rz_io_map_cleanup (io); + return true; +} + +RZ_API RzIODesc* rz_io_desc_get(RzIO* io, int fd) { + rz_return_val_if_fail (io && io->files, NULL); + return (RzIODesc*) rz_id_storage_get (io->files, fd); +} + +RZ_API RzIODesc *rz_io_desc_open(RzIO *io, const char *uri, int perm, int mode) { + rz_return_val_if_fail (io && uri, NULL); + RzIOPlugin *plugin = rz_io_plugin_resolve (io, uri, 0); + if (!plugin || !plugin->open) { + return NULL; + } + RzIODesc *desc = plugin->open (io, uri, perm, mode); + if (!desc) { + return NULL; + } + // for none static callbacks, those that cannot use rz_io_desc_new + if (!desc->name) { + desc->name = strdup (uri); + } + if (!desc->uri) { + desc->uri = strdup (uri); + } + if (!desc->plugin) { + desc->plugin = plugin; + } + if (!rz_io_desc_add (io, desc)) { + rz_io_desc_free (desc); + return NULL; + } + return desc; +} + +RZ_API RzIODesc *rz_io_desc_open_plugin(RzIO *io, RzIOPlugin *plugin, const char *uri, int perm, int mode) { + rz_return_val_if_fail (io && io->files && uri, NULL); + if (!plugin || !plugin->open || !plugin->check || !plugin->check (io, uri, false)) { + return NULL; + } + RzIODesc *desc = plugin->open (io, uri, perm, mode); + if (!desc) { + return NULL; + } + // for none static callbacks, those that cannot use rz_io_desc_new + if (!desc->plugin) { + desc->plugin = plugin; + } + if (!desc->uri) { + desc->uri = strdup (uri); + } + if (!desc->name) { + desc->name = strdup (uri); + } + if (!rz_io_desc_add (io, desc)) { + rz_io_desc_free (desc); + return NULL; + } + return desc; +} + + +RZ_API bool rz_io_desc_close(RzIODesc *desc) { + RzIO *io; + if (!desc || !desc->io || !desc->plugin) { + return false; + } + if (desc->plugin->close && desc->plugin->close (desc)) { + return false; + } + io = desc->io; + // remove entry from idstorage and free the desc-struct + rz_io_desc_del (io, desc->fd); + // remove all dead maps + rz_io_map_cleanup (io); + return true; +} + +//returns length of written bytes +RZ_API int rz_io_desc_write(RzIODesc *desc, const ut8* buf, int len) { + rz_return_val_if_fail (desc && buf, -1); + if (len < 0) { + return -1; + } + //check pointers and pcache + if (desc->io && (desc->io->p_cache & 2)) { + return rz_io_desc_cache_write (desc, + rz_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR), buf, len); + } + return rz_io_plugin_write (desc, buf, len); +} + +// returns length of read bytes +RZ_API int rz_io_desc_read(RzIODesc *desc, ut8 *buf, int len) { + // check pointers and permissions + if (!buf || !desc || !desc->plugin || !(desc->perm & R_PERM_R)) { + return -1; + } + ut64 seek = rz_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); + if (desc->io->cachemode) { + if (seek != UT64_MAX && rz_io_cache_at (desc->io, seek)) { + return rz_io_cache_read (desc->io, seek, buf, len); + } + } + int ret = rz_io_plugin_read (desc, buf, len); + if (ret > 0 && desc->io->cachemode) { + rz_io_cache_write (desc->io, seek, buf, len); + } else if ((ret > 0) && desc->io && (desc->io->p_cache & 1)) { + ret = rz_io_desc_cache_read (desc, seek, buf, ret); + } + return ret; +} + +RZ_API ut64 rz_io_desc_seek(RzIODesc* desc, ut64 offset, int whence) { + if (!desc || !desc->plugin || !desc->plugin->lseek) { + return (ut64) -1; + } + return desc->plugin->lseek (desc->io, desc, offset, whence); +} + +RZ_API ut64 rz_io_desc_size(RzIODesc* desc) { + if (!desc || !desc->plugin || !desc->plugin->lseek) { + return 0LL; + } + ut64 off = rz_io_desc_seek (desc, 0LL, R_IO_SEEK_CUR); + ut64 ret = rz_io_desc_seek (desc, 0LL, R_IO_SEEK_END); + // what to do if that seek fails? + rz_io_desc_seek (desc, off, R_IO_SEEK_SET); + return ret; +} + +RZ_API bool rz_io_desc_resize(RzIODesc *desc, ut64 newsize) { + if (desc && desc->plugin && desc->plugin->resize) { + bool ret = desc->plugin->resize (desc->io, desc, newsize); + if (desc->io && desc->io->p_cache) { + rz_io_desc_cache_cleanup (desc); + } + return ret; + } + return false; +} + +RZ_API bool rz_io_desc_is_blockdevice(RzIODesc *desc) { + if (!desc || !desc->plugin || !desc->plugin->is_blockdevice) { + return false; + } + return desc->plugin->is_blockdevice (desc); +} + +RZ_API bool rz_io_desc_is_chardevice(RzIODesc *desc) { + if (!desc || !desc->plugin || !desc->plugin->is_chardevice) { + return false; + } + return desc->plugin->is_chardevice (desc); +} + +RZ_API bool rz_io_desc_exchange(RzIO* io, int fd, int fdx) { + RzIODesc* desc, * descx; + if (!(desc = rz_io_desc_get (io, fd)) || !(descx = rz_io_desc_get (io, fdx))) { + return false; + } + desc->fd = fdx; + descx->fd = fd; + rz_id_storage_set (io->files, desc, fdx); + rz_id_storage_set (io->files, descx, fd); + if (io->p_cache) { + Sdb* cache = desc->cache; + desc->cache = descx->cache; + descx->cache = cache; + rz_io_desc_cache_cleanup (desc); + rz_io_desc_cache_cleanup (descx); + } + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; + if (map->fd == fdx) { + map->perm &= (desc->perm | R_PERM_X); + } else if (map->fd == fd) { + map->perm &= (descx->perm | R_PERM_X); + } + } + return true; +} + +RZ_API bool rz_io_desc_is_dbg(RzIODesc *desc) { + if (desc && desc->plugin) { + return desc->plugin->isdbg; + } + return false; +} + +RZ_API int rz_io_desc_get_pid(RzIODesc *desc) { + //-1 and -2 are reserved + if (!desc) { + return -3; + } + if (!desc->plugin) { + return -4; + } + if (!desc->plugin->isdbg) { + return -5; + } + if (!desc->plugin->getpid) { + return -6; + } + return desc->plugin->getpid (desc); +} + +RZ_API int rz_io_desc_get_tid(RzIODesc *desc) { + //-1 and -2 are reserved + if (!desc) { + return -3; + } + if (!desc->plugin) { + return -4; + } + if (!desc->plugin->isdbg) { + return -5; + } + if (!desc->plugin->gettid) { + return -6; + } + return desc->plugin->gettid (desc); +} + +RZ_API bool rz_io_desc_get_base (RzIODesc *desc, ut64 *base) { + if (!base || !desc || !desc->plugin || !desc->plugin->isdbg || !desc->plugin->getbase) { + return false; + } + return desc->plugin->getbase (desc, base); +} + +RZ_API int rz_io_desc_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len) { + if (desc && buf && (rz_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { + return rz_io_desc_read (desc, buf, len); + } + return 0; +} + +RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len) { + if (desc && buf && (rz_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { + return rz_io_desc_write (desc, buf, len); + } + return 0; +} + +RZ_API int rz_io_desc_extend(RzIODesc *desc, ut64 size) { + if (desc && desc->plugin && desc->plugin->extend) { + return desc->plugin->extend (desc->io, desc, size); + } + return 0; +} + +/* lifecycle */ + +// TODO: move into io.c : rz_io_init +R_IPI bool rz_io_desc_init(RzIO* io) { + rz_return_val_if_fail (io, false); + rz_io_desc_fini (io); + // TODO: it leaks if called twice + //fd is signed + io->files = rz_id_storage_new (3, 0x80000000); + if (!io->files) { + return false; + } + return true; +} + +static bool desc_fini_cb(void* user, void* data, ut32 id) { + RzIODesc* desc = (RzIODesc*) data; + if (desc->plugin && desc->plugin->close) { + desc->plugin->close (desc); + } + rz_io_desc_free (desc); + return true; +} + +//closes all descs and frees all descs and io->files +R_IPI bool rz_io_desc_fini(RzIO* io) { + rz_return_val_if_fail (io, NULL); + if (io->files) { + rz_id_storage_foreach (io->files, desc_fini_cb, io); + rz_id_storage_free (io->files); + io->files = NULL; + } + //no map-cleanup here, to keep it modular useable + io->desc = NULL; + return true; +} diff --git a/librz/io/io_fd.c b/librz/io/io_fd.c new file mode 100644 index 0000000000..b48fa1d809 --- /dev/null +++ b/librz/io/io_fd.c @@ -0,0 +1,128 @@ +/* rizin - LGPL - Copyright 2017 - condret */ + +#include + +RZ_API int rz_io_fd_open(RzIO *io, const char *uri, int flags, int mode) { + RzIODesc *desc = rz_io_desc_open (io, uri, flags, mode); + return desc ? desc->fd : -1; +} + +RZ_API bool rz_io_fd_close(RzIO *io, int fd) { + return rz_io_desc_close (rz_io_desc_get (io, fd)); +} + +//returns length of read bytes +RZ_API int rz_io_fd_read(RzIO *io, int fd, ut8 *buf, int len) { + rz_return_val_if_fail (io && buf, -1); + if (len < 0) { + return -1; + } + RzIODesc *desc = rz_io_desc_get (io, fd); + return desc? rz_io_desc_read (desc, buf, len): -1; +} + +//returns length of written bytes +RZ_API int rz_io_fd_write(RzIO *io, int fd, const ut8 *buf, int len) { + rz_return_val_if_fail (io && buf, -1); + if (len < 0) { + return -1; + } + RzIODesc *desc = rz_io_desc_get (io, fd); + return desc? rz_io_desc_write (desc, buf, len): -1; +} + +RZ_API ut64 rz_io_fd_seek(RzIO *io, int fd, ut64 addr, int whence) { + if (!io) { + return (ut64)-2; + } + return rz_io_desc_seek (rz_io_desc_get (io, fd), addr, whence); +} + +RZ_API ut64 rz_io_fd_size(RzIO *io, int fd) { + return rz_io_desc_size (rz_io_desc_get (io, fd)); +} + +RZ_API bool rz_io_fd_resize(RzIO *io, int fd, ut64 newsize) { + return rz_io_desc_resize (rz_io_desc_get (io, fd), newsize); +} + +RZ_API bool rz_io_fd_is_blockdevice(RzIO *io, int fd) { + return rz_io_desc_is_blockdevice (rz_io_desc_get (io, fd)); +} + +RZ_API bool rz_io_fd_is_chardevice(RzIO *io, int fd) { + return rz_io_desc_is_chardevice (rz_io_desc_get (io, fd)); +} + +//returns length of read bytes +RZ_API int rz_io_fd_read_at(RzIO *io, int fd, ut64 addr, ut8 *buf, int len) { + RzIODesc *desc; + if (!io || !buf || (len < 1) || !(desc = rz_io_desc_get (io, fd))) { + return 0; + } + return rz_io_desc_read_at (desc, addr, buf, len); +} + +//returns length of written bytes +RZ_API int rz_io_fd_write_at(RzIO *io, int fd, ut64 addr, const ut8 *buf, int len) { + rz_return_val_if_fail (io && buf, false); + RzIODesc *desc = rz_io_desc_get (io, fd); + return desc? rz_io_desc_write_at (desc, addr, buf, len): -1; +} + +RZ_API bool rz_io_fd_is_dbg(RzIO *io, int fd) { + rz_return_val_if_fail (io && io->files, false); + RzIODesc *desc = rz_io_desc_get (io, fd); + return desc? rz_io_desc_is_dbg (desc): false; +} + +RZ_API int rz_io_fd_get_pid(RzIO *io, int fd) { + if (!io || !io->files) { + return -2; + } + RzIODesc *desc = rz_io_desc_get (io, fd); + return rz_io_desc_get_pid (desc); +} + +RZ_API int rz_io_fd_get_tid(RzIO *io, int fd) { + rz_return_val_if_fail (io && io->files, -2); + RzIODesc *desc = rz_io_desc_get (io, fd); + return rz_io_desc_get_tid (desc); +} + +RZ_API bool rz_io_fd_get_base (RzIO *io, int fd, ut64 *base) { + rz_return_val_if_fail (io && io->files && base, false); + RzIODesc *desc = rz_io_desc_get (io, fd); + return rz_io_desc_get_base (desc, base); +} + +RZ_API const char *rz_io_fd_get_name(RzIO *io, int fd) { + rz_return_val_if_fail (io && io->files, NULL); + RzIODesc *desc = rz_io_desc_get (io, fd); + return desc? desc->name: NULL; +} + +RZ_API bool rz_io_use_fd(RzIO* io, int fd) { + rz_return_val_if_fail (io, false); + if (!io->desc) { + io->desc = rz_io_desc_get (io, fd); + return io->desc != NULL; + } + if (io->desc->fd != fd) { + RzIODesc* desc; + //update io->desc if fd is not the same + if (!(desc = rz_io_desc_get (io, fd))) { + return false; + } + io->desc = desc; + } + return true; +} + +RZ_API int rz_io_fd_get_current(RzIO *io) { + rz_return_val_if_fail (io, -1); + if (io->desc) { + return io->desc->fd; + } + return -1; +} diff --git a/librz/io/io_map.c b/librz/io/io_map.c new file mode 100644 index 0000000000..a6832ccb56 --- /dev/null +++ b/librz/io/io_map.c @@ -0,0 +1,480 @@ +/* rizin - LGPL - Copyright 2017-2019 - condret, MaskRay */ + +#include +#include +#include +#include "rz_binheap.h" +#include "rz_util.h" +#include "rz_vector.h" + +#define END_OF_MAP_IDS UT32_MAX + +#define CMP_END_GTE(addr, itv) \ + (((addr) < rz_itv_end (*(RInterval *)(itv))) ? -1 : 1) + +#define CMP_END_GTE_PART(addr, part) \ + (((addr) < (rz_itv_end (((RzIOMapSkyline *)(part))->itv)) || !rz_itv_end (((RzIOMapSkyline *)(part))->itv)) ? -1 : 1) + +#define CMP_BEGIN_GTE_PART(addr, part) \ + (((addr) > (rz_itv_begin (((RzIOMapSkyline *)(part))->itv))) - ((addr) < (rz_itv_begin (((RzIOMapSkyline *)(part))->itv)))) + +static bool add_map_to_skyline(RzIO *io, RzIOMap *map) { + size_t slot; + RPVector *skyline = &io->map_skyline; + + RzIOMapSkyline *new_part = R_NEW (RzIOMapSkyline); + new_part->map = map; + new_part->itv = map->itv; + const ut64 new_part_end = rz_itv_end (new_part->itv); + + // `part` is the first RzIOMapSkyline with part->itv.addr >= new_part->itv.addr + rz_pvector_lower_bound (skyline, new_part->itv.addr, slot, CMP_BEGIN_GTE_PART); + RzIOMapSkyline *part = slot < rz_pvector_len (skyline) ? rz_pvector_at (skyline, slot) : NULL; + if (slot) { + RzIOMapSkyline *prev_part = rz_pvector_at (skyline, slot - 1); + const ut64 prev_part_end = rz_itv_end (prev_part->itv); + if (prev_part_end > rz_itv_begin (new_part->itv)) { + if (prev_part_end > new_part_end) { + RzIOMapSkyline *tail = R_NEW (RzIOMapSkyline); + tail->map = prev_part->map; + tail->itv.addr = new_part_end; + tail->itv.size = prev_part_end - rz_itv_begin (tail->itv); + if (slot < rz_pvector_len (skyline)) { + rz_pvector_insert (skyline, slot, tail); + } else { + rz_pvector_push (skyline, tail); + } + } + prev_part->itv.size = rz_itv_begin (new_part->itv) - rz_itv_begin (prev_part->itv); + } + } + if (part) { + while (part && rz_itv_include (new_part->itv, part->itv)) { + // Remove `part` that fits in `new_part` + rz_pvector_remove_at (skyline, slot); + part = slot < rz_pvector_len (skyline) ? rz_pvector_at (skyline, slot) : NULL; + } + if (part && rz_itv_overlap (new_part->itv, part->itv)) { + // Chop start of last `part` that intersects `new_part` + const ut64 oaddr = rz_itv_begin (part->itv); + part->itv.addr = new_part_end; + part->itv.size -= rz_itv_begin (part->itv) - oaddr; + } + } + if (slot < rz_pvector_len (skyline)) { + rz_pvector_insert (skyline, slot, new_part); + } else { + rz_pvector_push (skyline, new_part); + } + return true; +} + +// Store map parts that are not covered by others into io->map_skyline +void io_map_calculate_skyline(RzIO *io) { + rz_pvector_clear (&io->map_skyline); + // Last map has highest priority (it shadows previous maps) + void **it; + rz_pvector_foreach (&io->maps, it) { + add_map_to_skyline (io, (RzIOMap *)*it); + } +} + +RzIOMap* io_map_new(RzIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { + if (!size || !io || !io->map_ids) { + return NULL; + } + RzIOMap* map = R_NEW0 (RzIOMap); + if (!map || !io->map_ids || !rz_id_pool_grab_id (io->map_ids, &map->id)) { + free (map); + return NULL; + } + map->fd = fd; + map->delta = delta; + if ((UT64_MAX - size + 1) < addr) { + /// XXX: this is leaking a map!!! + io_map_new (io, fd, perm, delta - addr, 0LL, size + addr); + size = -(st64)addr; + } + // RzIOMap describes an interval of addresses (map->from; map->to) + map->itv = (RInterval){ addr, size }; + map->perm = perm; + map->delta = delta; + // new map lives on the top, being top the list's tail + rz_pvector_push (&io->maps, map); + add_map_to_skyline (io, map); + return map; +} + +RZ_API RzIOMap *rz_io_map_new(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { + return io_map_new (io, fd, perm, delta, addr, size); +} + +RZ_API bool rz_io_map_remap(RzIO *io, ut32 id, ut64 addr) { + RzIOMap *map = rz_io_map_resolve (io, id); + if (map) { + ut64 size = map->itv.size; + map->itv.addr = addr; + if (UT64_MAX - size + 1 < addr) { + map->itv.size = -addr; + rz_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, size + addr); + } + io_map_calculate_skyline (io); + return true; + } + return false; +} + +RZ_API bool rz_io_map_remap_fd(RzIO *io, int fd, ut64 addr) { + RzIOMap *map; + bool retval = false; + RzList *maps = rz_io_map_get_for_fd (io, fd); + if (maps) { + map = rz_list_get_n (maps, 0); + if (map) { + retval = rz_io_map_remap (io, map->id, addr); + } + rz_list_free (maps); + } + return retval; +} + +static void _map_free(void* p) { + RzIOMap* map = (RzIOMap*) p; + if (map) { + free (map->name); + free (map); + } +} + +RZ_API void rz_io_map_init(RzIO* io) { + rz_return_if_fail (io); + rz_pvector_init (&io->maps, _map_free); + if (io->map_ids) { + rz_id_pool_free (io->map_ids); + } + io->map_ids = rz_id_pool_new (1, END_OF_MAP_IDS); +} + +// check if a map with exact the same properties exists +RZ_API bool rz_io_map_exists(RzIO *io, RzIOMap *map) { + rz_return_val_if_fail (io && map, false); + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *m = *it; + if (!memcmp (m, map, sizeof (RzIOMap))) { + return true; + } + } + return false; +} + +// check if a map with specified id exists +RZ_API bool rz_io_map_exists_for_id(RzIO* io, ut32 id) { + return rz_io_map_resolve (io, id) != NULL; +} + +RZ_API RzIOMap* rz_io_map_resolve(RzIO *io, ut32 id) { + rz_return_val_if_fail (io && id, false); + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; + if (map->id == id) { + return map; + } + } + return NULL; +} + +RzIOMap* io_map_add(RzIO* io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { + //check if desc exists + RzIODesc* desc = rz_io_desc_get (io, fd); + if (desc) { + //a map cannot have higher permissions than the desc belonging to it + return io_map_new (io, fd, (perm & desc->perm) | (perm & R_PERM_X), + delta, addr, size); + } + return NULL; +} + +RZ_API RzIOMap *rz_io_map_add(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { + return io_map_add (io, fd, perm, delta, addr, size); +} + +RZ_API RzIOMap *rz_io_map_add_batch(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size) { + return io_map_add (io, fd, perm, delta, addr, size); +} + +RZ_API void rz_io_update(RzIO *io) { + io_map_calculate_skyline (io); +} + +RZ_API RzIOMap* rz_io_map_get_paddr(RzIO* io, ut64 paddr) { + rz_return_val_if_fail (io, NULL); + void **it; + rz_pvector_foreach_prev (&io->maps, it) { + RzIOMap *map = *it; + if (map->delta <= paddr && paddr <= map->delta + map->itv.size - 1) { + return map; + } + } + return NULL; +} + +// gets first map where addr fits in +RZ_API RzIOMap *rz_io_map_get(RzIO* io, ut64 addr) { + rz_return_val_if_fail (io, NULL); + const RPVector *skyline = &io->map_skyline; + size_t i, len = rz_pvector_len (skyline); + rz_pvector_lower_bound (skyline, addr, i, CMP_END_GTE_PART); + if (i == len) { + return NULL; + } + const RzIOMapSkyline *sky = rz_pvector_at (skyline, i); + return sky->itv.addr <= addr ? sky->map : NULL; +} + +RZ_API bool rz_io_map_is_mapped(RzIO* io, ut64 addr) { + rz_return_val_if_fail (io, false); + return (bool)rz_io_map_get (io, addr); +} + +RZ_API void rz_io_map_reset(RzIO* io) { + rz_io_map_fini (io); + rz_io_map_init (io); + io_map_calculate_skyline (io); +} + +RZ_API bool rz_io_map_del(RzIO *io, ut32 id) { + rz_return_val_if_fail (io, false); + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps); i++) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + if (map->id == id) { + rz_pvector_remove_at (&io->maps, i); + _map_free (map); + rz_id_pool_kick_id (io->map_ids, id); + io_map_calculate_skyline (io); + return true; + } + } + return false; +} + +//delete all maps with specified fd +RZ_API bool rz_io_map_del_for_fd(RzIO* io, int fd) { + rz_return_val_if_fail (io, false); + bool ret = false; + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps);) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + if (!map) { + rz_pvector_remove_at (&io->maps, i); + } else if (map->fd == fd) { + rz_id_pool_kick_id (io->map_ids, map->id); + //delete iter and map + rz_pvector_remove_at (&io->maps, i); + _map_free (map); + ret = true; + } else { + i++; + } + } + if (ret) { + io_map_calculate_skyline (io); + } + return ret; +} + +//brings map with specified id to the tail of of the list +//return a boolean denoting whether is was possible to priorized +RZ_API bool rz_io_map_priorize(RzIO* io, ut32 id) { + rz_return_val_if_fail (io, false); + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps); i++) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + // search for iter with the correct map + if (map->id == id) { + rz_pvector_remove_at (&io->maps, i); + rz_pvector_push (&io->maps, map); + io_map_calculate_skyline (io); + return true; + } + } + return false; +} + +RZ_API bool rz_io_map_depriorize(RzIO* io, ut32 id) { + rz_return_val_if_fail (io, false); + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps); i++) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + // search for iter with the correct map + if (map->id == id) { + rz_pvector_remove_at (&io->maps, i); + rz_pvector_push_front (&io->maps, map); + io_map_calculate_skyline (io); + return true; + } + } + return false; +} + +RZ_API bool rz_io_map_priorize_for_fd(RzIO *io, int fd) { + rz_return_val_if_fail (io, false); + //we need a clean list for this, or this becomes a segfault-field + rz_io_map_cleanup (io); + RPVector temp; + rz_pvector_init (&temp, NULL); + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps);) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + if (map->fd == fd) { + rz_pvector_push (&temp, map); + rz_pvector_remove_at (&io->maps, i); + continue; + } + i++; + } + rz_pvector_insert_range (&io->maps, rz_pvector_len (&io->maps), temp.v.a, rz_pvector_len (&temp)); + rz_pvector_clear (&temp); + io_map_calculate_skyline (io); + return true; +} + +//may fix some inconsistencies in io->maps +RZ_API void rz_io_map_cleanup(RzIO* io) { + rz_return_if_fail (io); + //remove all maps if no descs exist + if (!io->files) { + rz_io_map_fini (io); + rz_io_map_init (io); + return; + } + bool del = false; + size_t i; + for (i = 0; i < rz_pvector_len (&io->maps);) { + RzIOMap *map = rz_pvector_at (&io->maps, i); + if (!map) { + // remove iter if the map is a null-ptr, this may fix some segfaults. This should never happen. + rz_warn_if_reached (); + rz_pvector_remove_at (&io->maps, i); + del = true; + } else if (!rz_io_desc_get (io, map->fd)) { + //delete map and iter if no desc exists for map->fd in io->files + rz_id_pool_kick_id (io->map_ids, map->id); + map = rz_pvector_remove_at (&io->maps, i); + _map_free (map); + del = true; + } else { + i++; + } + } + if (del) { + io_map_calculate_skyline (io); + } +} + +RZ_API void rz_io_map_fini(RzIO* io) { + rz_return_if_fail (io); + rz_pvector_clear (&io->maps); + rz_id_pool_free (io->map_ids); + io->map_ids = NULL; + rz_pvector_clear (&io->map_skyline); +} + +RZ_API void rz_io_map_set_name(RzIOMap* map, const char* name) { + if (!map || !name) { + return; + } + free (map->name); + map->name = strdup (name); +} + +RZ_API void rz_io_map_del_name(RzIOMap* map) { + if (map) { + R_FREE (map->name); + } +} + +// TODO: very similar to rz_io_map_next_address, decide which one to use +RZ_API ut64 rz_io_map_next_available(RzIO* io, ut64 addr, ut64 size, ut64 load_align) { + if (load_align == 0) { + load_align = 1; + } + ut64 next_addr = addr, + end_addr = next_addr + size; + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; + ut64 to = rz_itv_end (map->itv); + next_addr = R_MAX (next_addr, to + (load_align - (to % load_align)) % load_align); + // XXX - This does not handle when file overflow 0xFFFFFFFF000 -> 0x00000FFF + // adding the check for the map's fd to see if this removes contention for + // memory mapping with multiple files. infinite loop ahead? + if ((map->itv.addr <= next_addr && next_addr < to) || rz_itv_contain (map->itv, end_addr)) { + next_addr = to + (load_align - (to % load_align)) % load_align; + return rz_io_map_next_available (io, next_addr, size, load_align); + } + break; + } + return next_addr; +} + +// TODO: very similar to rz_io_map_next_available. decide which one to use +RZ_API ut64 rz_io_map_next_address(RzIO* io, ut64 addr) { + ut64 lowest = UT64_MAX; + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; + ut64 from = rz_itv_begin (map->itv); + if (from > addr && addr < lowest) { + lowest = from; + } + ut64 to = rz_itv_end (map->itv); + if (to > addr && to < lowest) { + lowest = to; + } + } + return lowest; +} + +RZ_API RzList* rz_io_map_get_for_fd(RzIO* io, int fd) { + RzList* map_list = rz_list_newf (NULL); + if (!map_list) { + return NULL; + } + void **it; + rz_pvector_foreach (&io->maps, it) { + RzIOMap *map = *it; + if (map && map->fd == fd) { + rz_list_append (map_list, map); + } + } + return map_list; +} + +RZ_API bool rz_io_map_resize(RzIO *io, ut32 id, ut64 newsize) { + RzIOMap *map; + if (!newsize || !(map = rz_io_map_resolve (io, id))) { + return false; + } + ut64 addr = map->itv.addr; + if (UT64_MAX - newsize + 1 < addr) { + map->itv.size = -addr; + rz_io_map_new (io, map->fd, map->perm, map->delta - addr, 0, newsize + addr); + return true; + } + map->itv.size = newsize; + io_map_calculate_skyline (io); + return true; +} + +// find a location that can hold enough bytes without overlapping +// XXX this function is buggy and doesnt works as expected, but i need it for a PoC for now +RZ_API ut64 rz_io_map_location(RzIO *io, ut64 size) { + ut64 base = (io->bits == 64)? 0x60000000000LL: 0x60000000; + while (rz_io_map_get (io, base)) { + base += 0x200000; + } + return base; +} diff --git a/libr/io/io_plugin.c b/librz/io/io_plugin.c similarity index 63% rename from libr/io/io_plugin.c rename to librz/io/io_plugin.c index 2de4228c59..decbde1e6a 100644 --- a/libr/io/io_plugin.c +++ b/librz/io/io_plugin.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2008-2018 - pancake */ -#include "r_io.h" +#include "rz_io.h" #include "config.h" #include -static volatile RIOPlugin *default_plugin = NULL; +static volatile RzIOPlugin *default_plugin = NULL; -static RIOPlugin *io_static_plugins[] = { +static RzIOPlugin *io_static_plugins[] = { R_IO_STATIC_PLUGINS }; -R_API bool r_io_plugin_add(RIO *io, RIOPlugin *plugin) { +RZ_API bool rz_io_plugin_add(RzIO *io, RzIOPlugin *plugin) { if (!io || !io->plugins || !plugin || !plugin->name) { return false; } @@ -18,8 +18,8 @@ R_API bool r_io_plugin_add(RIO *io, RIOPlugin *plugin) { return true; } -R_API bool r_io_plugin_init(RIO *io) { - RIOPlugin *static_plugin; +RZ_API bool rz_io_plugin_init(RzIO *io) { + RzIOPlugin *static_plugin; int i; if (!io) { return false; @@ -29,26 +29,26 @@ R_API bool r_io_plugin_init(RIO *io) { if (!io_static_plugins[i]->name) { continue; } - static_plugin = R_NEW0 (RIOPlugin); + static_plugin = R_NEW0 (RzIOPlugin); if (!static_plugin) { return false; } - memcpy (static_plugin, io_static_plugins[i], sizeof (RIOPlugin)); - r_io_plugin_add (io, static_plugin); + memcpy (static_plugin, io_static_plugins[i], sizeof (RzIOPlugin)); + rz_io_plugin_add (io, static_plugin); } return true; } -R_API RIOPlugin *r_io_plugin_get_default(RIO *io, const char *filename, bool many) { +RZ_API RzIOPlugin *rz_io_plugin_get_default(RzIO *io, const char *filename, bool many) { if (!default_plugin || !default_plugin->check || !default_plugin->check (io, filename, many) ) { return NULL; } - return (RIOPlugin*) default_plugin; + return (RzIOPlugin*) default_plugin; } -R_API RIOPlugin *r_io_plugin_resolve(RIO *io, const char *filename, bool many) { +RZ_API RzIOPlugin *rz_io_plugin_resolve(RzIO *io, const char *filename, bool many) { SdbListIter *iter; - RIOPlugin *ret; + RzIOPlugin *ret; ls_foreach (io->plugins, iter, ret) { if (!ret || !ret->check) { continue; @@ -57,22 +57,22 @@ R_API RIOPlugin *r_io_plugin_resolve(RIO *io, const char *filename, bool many) { return ret; } } - return r_io_plugin_get_default (io, filename, many); + return rz_io_plugin_get_default (io, filename, many); } -R_API RIOPlugin *r_io_plugin_byname(RIO *io, const char *name) { +RZ_API RzIOPlugin *rz_io_plugin_byname(RzIO *io, const char *name) { SdbListIter *iter; - RIOPlugin *iop; + RzIOPlugin *iop; ls_foreach (io->plugins, iter, iop) { if (!strcmp (name, iop->name)) { return iop; } } - return r_io_plugin_get_default (io, name, false); + return rz_io_plugin_get_default (io, name, false); } -R_API int r_io_plugin_list(RIO *io) { - RIOPlugin *plugin; +RZ_API int rz_io_plugin_list(RzIO *io) { + RzIOPlugin *plugin; SdbListIter *iter; char str[4]; int n = 0; @@ -100,8 +100,8 @@ R_API int r_io_plugin_list(RIO *io) { return n; } -R_API int r_io_plugin_list_json(RIO *io) { - RIOPlugin *plugin; +RZ_API int rz_io_plugin_list_json(RzIO *io) { + RzIOPlugin *plugin; SdbListIter *iter; PJ *pj = pj_new (); if (!pj) { @@ -128,15 +128,15 @@ R_API int r_io_plugin_list_json(RIO *io) { if (plugin->uris) { char *uri; char *uris = strdup (plugin->uris); - RList *plist = r_str_split_list (uris, ",", 0); - RListIter *piter; + RzList *plist = rz_str_split_list (uris, ",", 0); + RzListIter *piter; pj_k (pj, "uris"); pj_a (pj); - r_list_foreach (plist, piter, uri) { + rz_list_foreach (plist, piter, uri) { pj_s (pj, uri); } pj_end (pj); - r_list_free (plist); + rz_list_free (plist); free (uris); } if (plugin->version) { @@ -155,7 +155,7 @@ R_API int r_io_plugin_list_json(RIO *io) { return n; } -R_API int r_io_plugin_read(RIODesc *desc, ut8 *buf, int len) { +RZ_API int rz_io_plugin_read(RzIODesc *desc, ut8 *buf, int len) { if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & R_PERM_R)) { return 0; } @@ -165,7 +165,7 @@ R_API int r_io_plugin_read(RIODesc *desc, ut8 *buf, int len) { return desc->plugin->read (desc->io, desc, buf, len); } -R_API int r_io_plugin_write(RIODesc *desc, const ut8 *buf, int len) { +RZ_API int rz_io_plugin_write(RzIODesc *desc, const ut8 *buf, int len) { if (!buf || !desc || !desc->plugin || len < 1 || !(desc->perm & R_PERM_W)) { return 0; } @@ -175,16 +175,16 @@ R_API int r_io_plugin_write(RIODesc *desc, const ut8 *buf, int len) { return desc->plugin->write (desc->io, desc, buf, len); } -R_API int r_io_plugin_read_at(RIODesc *desc, ut64 addr, ut8 *buf, int len) { - if (r_io_desc_is_chardevice (desc) || (r_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { - return r_io_plugin_read (desc, buf, len); +RZ_API int rz_io_plugin_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, int len) { + if (rz_io_desc_is_chardevice (desc) || (rz_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr)) { + return rz_io_plugin_read (desc, buf, len); } return 0; } -R_API int r_io_plugin_write_at(RIODesc *desc, ut64 addr, const ut8 *buf, int len) { - if (r_io_desc_is_chardevice (desc) || r_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr) { - return r_io_plugin_write (desc, buf, len); +RZ_API int rz_io_plugin_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, int len) { + if (rz_io_desc_is_chardevice (desc) || rz_io_desc_seek (desc, addr, R_IO_SEEK_SET) == addr) { + return rz_io_plugin_write (desc, buf, len); } return 0; } diff --git a/librz/io/io_private.h b/librz/io/io_private.h new file mode 100644 index 0000000000..0f754b1ccd --- /dev/null +++ b/librz/io/io_private.h @@ -0,0 +1,8 @@ +#ifndef _IO_PRIVATE_H_ +#define _IO_PRIVATE_H_ + +RzIOMap *io_map_new(RzIO *io, int fd, int perm, ut64 delta, ut64 addr, ut64 size); +RzIOMap *io_map_add(RzIO *io, int fd, int flags, ut64 delta, ut64 addr, ut64 size, bool do_skyline); +void io_map_calculate_skyline(RzIO *io); + +#endif diff --git a/libr/io/ioutils.c b/librz/io/ioutils.c similarity index 50% rename from libr/io/ioutils.c rename to librz/io/ioutils.c index 9d0ba0e802..cd0829c9a0 100644 --- a/libr/io/ioutils.c +++ b/librz/io/ioutils.c @@ -1,59 +1,59 @@ /* radare - LGPL - Copyright 2017-2019 - condret */ -#include -#include -#include +#include +#include +#include #include "io_private.h" //This helper function only check if the given vaddr is mapped, it does not account //for map perms -R_API bool r_io_addr_is_mapped(RIO *io, ut64 vaddr) { - r_return_val_if_fail (io, false); - return (io->va && r_io_map_get (io, vaddr)); +RZ_API bool rz_io_addr_is_mapped(RzIO *io, ut64 vaddr) { + rz_return_val_if_fail (io, false); + return (io->va && rz_io_map_get (io, vaddr)); } // when io.va is true this checks if the highest priorized map at this // offset has the same or high permissions set. When there is no map it // check for the current desc permissions and size. // when io.va is false it only checks for the desc -R_API bool r_io_is_valid_offset(RIO* io, ut64 offset, int hasperm) { - r_return_val_if_fail (io, false); +RZ_API bool rz_io_is_valid_offset(RzIO* io, ut64 offset, int hasperm) { + rz_return_val_if_fail (io, false); if (io->va) { if (!hasperm) { - // return r_io_map_is_mapped (io, offset); - RIOMap* map = r_io_map_get (io, offset); + // return rz_io_map_is_mapped (io, offset); + RzIOMap* map = rz_io_map_get (io, offset); return map? map->perm & R_PERM_R: false; } - RIOMap* map = r_io_map_get (io, offset); + RzIOMap* map = rz_io_map_get (io, offset); return map? (map->perm & hasperm) == hasperm: false; } if (!io->desc) { return false; } - if (offset > r_io_desc_size (io->desc)) { + if (offset > rz_io_desc_size (io->desc)) { return false; } return ((io->desc->perm & hasperm) == hasperm); } // this is wrong, there is more than big and little endian -R_API bool r_io_read_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) { +RZ_API bool rz_io_read_i(RzIO* io, ut64 addr, ut64 *val, int size, bool endian) { ut8 buf[8]; - r_return_val_if_fail (io && val, false); + rz_return_val_if_fail (io && val, false); size = R_DIM (size, 1, 8); - if (!r_io_read_at (io, addr, buf, size)) { + if (!rz_io_read_at (io, addr, buf, size)) { return false; } - //size says the number of bytes to read transform to bits for r_read_ble - *val = r_read_ble (buf, endian, size * 8); + //size says the number of bytes to read transform to bits for rz_read_ble + *val = rz_read_ble (buf, endian, size * 8); return true; } -R_API bool r_io_write_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) { +RZ_API bool rz_io_write_i(RzIO* io, ut64 addr, ut64 *val, int size, bool endian) { ut8 buf[8]; - r_return_val_if_fail (io && val, false); + rz_return_val_if_fail (io && val, false); size = R_DIM (size, 1, 8); - //size says the number of bytes to read transform to bits for r_read_ble - r_write_ble (buf, *val, endian, size * 8); - return r_io_write_at (io, addr, buf, size) == size; + //size says the number of bytes to read transform to bits for rz_read_ble + rz_write_ble (buf, *val, endian, size * 8); + return rz_io_write_at (io, addr, buf, size) == size; } diff --git a/libr/io/meson.build b/librz/io/meson.build similarity index 70% rename from libr/io/meson.build rename to librz/io/meson.build index bb37f3db85..b0b5789e80 100644 --- a/libr/io/meson.build +++ b/librz/io/meson.build @@ -1,4 +1,4 @@ -r_io_sources = [ +rz_io_sources = [ 'io.c', 'io_fd.c', 'io_map.c', @@ -26,9 +26,9 @@ r_io_sources = [ 'p/io_procpid.c', 'p/io_ptrace.c', 'p/io_qnx.c', - 'p/io_r2k.c', - 'p/io_r2pipe.c', - 'p/io_r2web.c', + 'p/io_rzk.c', + 'p/io_rzpipe.c', + 'p/io_rzweb.c', 'p/io_rap.c', 'p/io_rbuf.c', 'p/io_self.c', @@ -41,8 +41,8 @@ r_io_sources = [ ] if host_machine.system() == 'windows' - r_io_sources += [ - 'p/io_r2k_windows.c', + rz_io_sources += [ + 'p/io_rzk_windows.c', 'p/io_windbg.c', 'p/io_w32.c', 'p/io_w32dbg.c', @@ -50,9 +50,9 @@ if host_machine.system() == 'windows' endif -r_io_deps = [ - r_util_dep, - r_socket_dep, +rz_io_deps = [ + rz_util_dep, + rz_socket_dep, bochs_dep, gdb_dep, winkd_dep, @@ -63,24 +63,24 @@ r_io_deps = [ ] if host_machine.system() == 'windows' - r_io_deps += w32dbg_wrap_dep + rz_io_deps += w32dbg_wrap_dep endif if host_machine.system() == 'linux' or host_machine.system() == 'android' - r_io_sources += [ - 'p/io_r2k_linux.c', + rz_io_sources += [ + 'p/io_rzk_linux.c', ] ## only for shm_open - # r_io_deps += meson.get_compiler('c').find_library('rt') + # rz_io_deps += meson.get_compiler('c').find_library('rt') endif if use_ptrace_wrap - r_io_deps += ptrace_wrap_dep + rz_io_deps += ptrace_wrap_dep endif -r_io = library('r_io', r_io_sources, +rz_io = library('rz_io', rz_io_sources, include_directories: platform_inc, - dependencies: r_io_deps, + dependencies: rz_io_deps, c_args: library_cflags, install: true, implicit_include_directories: false, @@ -88,18 +88,18 @@ r_io = library('r_io', r_io_sources, soversion: r2_libversion ) -r_io_dep = declare_dependency(link_with: r_io, +rz_io_dep = declare_dependency(link_with: rz_io, include_directories: platform_inc) -pkgconfig_mod.generate(r_io, - subdirs: 'libr', +pkgconfig_mod.generate(rz_io, + subdirs: 'librz', version: r2_version, - name: 'r_io', - filebase: 'r_io', + name: 'rz_io', + filebase: 'rz_io', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_socket' + 'rz_util', + 'rz_socket' ], description: 'radare foundation libraries' ) diff --git a/libr/io/p/Makefile b/librz/io/p/Makefile similarity index 87% rename from libr/io/p/Makefile rename to librz/io/p/Makefile index 76ee98b786..e3806091c4 100644 --- a/libr/io/p/Makefile +++ b/librz/io/p/Makefile @@ -15,7 +15,7 @@ endif all: ${ALL_TARGETS} ALL_TARGETS= -PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk winkd.mk bochs.mk qnx.mk r2k.mk ar.mk rbuf.mk gprobe.mk +PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk shm.mk mach.mk w32dbg.mk procpid.mk winkd.mk bochs.mk qnx.mk rzk.mk ar.mk rbuf.mk gprobe.mk #zip.mk #PLUGINS=ptrace.mk debug.mk gdb.mk malloc.mk mach.mk w32dbg.mk procpid.mk include ${PLUGINS} @@ -25,7 +25,7 @@ include ${PLUGINS} BINDEPS= io_ewf.${LIB_SO}: io_ewf.o - ${CC} ${CFLAGS} ${PIC_CFLAGS} ${LDFLAGS_LIB} io_ewf.${LIB_SO} ewf.c -lr_io -L../../io ${LDFLAGS_LINKPTH}.. -lewf + ${CC} ${CFLAGS} ${PIC_CFLAGS} ${LDFLAGS_LIB} io_ewf.${LIB_SO} ewf.c -lrz_io -L../../io ${LDFLAGS_LINKPTH}.. -lewf clean: -rm -f *.so *.o *.dll *.dylib *.${EXT_SO} diff --git a/libr/io/p/ar.mk b/librz/io/p/ar.mk similarity index 63% rename from libr/io/p/ar.mk rename to librz/io/p/ar.mk index 98e8016de5..0365981cc3 100644 --- a/libr/io/p/ar.mk +++ b/librz/io/p/ar.mk @@ -6,14 +6,14 @@ ALL_TARGETS+=${TARGET_AR} LIB_PATH=$(SHLR)/ar CFLAGS+=-I$(SHLR)/ar -LDFLAGS+=$(SHLR)/ar/libr_ar.$(EXT_AR) +LDFLAGS+=$(SHLR)/ar/librz_ar.$(EXT_AR) ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_AR}: ${OBJ_AR} diff --git a/libr/io/p/bfdbg.mk b/librz/io/p/bfdbg.mk similarity index 59% rename from libr/io/p/bfdbg.mk rename to librz/io/p/bfdbg.mk index 78aac9d1d9..87612689a4 100644 --- a/libr/io/p/bfdbg.mk +++ b/librz/io/p/bfdbg.mk @@ -5,13 +5,13 @@ TARGET_BFDBG=io_bfdbg.${EXT_SO} ALL_TARGETS+=${TARGET_BFDBG} ifeq (${WITHPIC},0) -LINKFLAGS+=../../cons/libr_cons.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../cons/librz_cons.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../cons -lr_cons -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../cons -lrz_cons +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_BFDBG}: ${OBJ_BFDBG} diff --git a/libr/io/p/bochs.mk b/librz/io/p/bochs.mk similarity index 67% rename from libr/io/p/bochs.mk rename to librz/io/p/bochs.mk index c7ec7f5080..0e53b277dd 100644 --- a/libr/io/p/bochs.mk +++ b/librz/io/p/bochs.mk @@ -11,13 +11,13 @@ LDFLAGS+=$(SHLR)/bochs/lib/libbochs.$(EXT_AR) include $(LIBR)/socket/deps.mk ifeq (${WITHPIC},0) -LINKFLAGS=../../socket/libr_socket.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS=../../socket/librz_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS=-L../../socket -lr_socket -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS=-L../../socket -lrz_socket +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_BOCHS}: ${OBJ_BOCHS} diff --git a/libr/io/p/debug.mk b/librz/io/p/debug.mk similarity index 55% rename from libr/io/p/debug.mk rename to librz/io/p/debug.mk index 31de59b395..1ad9634885 100644 --- a/libr/io/p/debug.mk +++ b/librz/io/p/debug.mk @@ -7,13 +7,13 @@ ALL_TARGETS+=${TARGET_IODBG} ifeq (${WITHPIC},0) -LINKFLAGS=../../socket/libr_socket.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS=../../socket/librz_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS=-L../../socket -lr_socket -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS=-L../../socket -lrz_socket +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ifeq (${HAVE_LIB_SSL},1) CFLAGS+=${SSL_CFLAGS} @@ -22,4 +22,4 @@ endif ${TARGET_IODBG}: ${OBJ_IODBG} ${CC} $(call libname,io_debug) ${CFLAGS} ${LDFLAGS_LIB} $(LDFLAGS) \ - ${LINKFLAGS} ${LDFLAGS_LINKPATH}.. ${OBJ_IODBG} -L.. -lr_io + ${LINKFLAGS} ${LDFLAGS_LINKPATH}.. ${OBJ_IODBG} -L.. -lrz_io diff --git a/libr/io/p/default.mk b/librz/io/p/default.mk similarity index 69% rename from libr/io/p/default.mk rename to librz/io/p/default.mk index cca31674ea..2a4e92e62e 100644 --- a/libr/io/p/default.mk +++ b/librz/io/p/default.mk @@ -5,11 +5,11 @@ TARGET_DEFAULT=io_default.${EXT_SO} ALL_TARGETS+=${TARGET_DEFAULT} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_DEFAULT}: ${OBJ_DEFAULT} diff --git a/libr/io/p/fd.mk b/librz/io/p/fd.mk similarity index 64% rename from libr/io/p/fd.mk rename to librz/io/p/fd.mk index d23da22727..3abce1f864 100644 --- a/libr/io/p/fd.mk +++ b/librz/io/p/fd.mk @@ -5,11 +5,11 @@ TARGET_FD=io_fd.${EXT_SO} ALL_TARGETS+=${TARGET_FD} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_FD}: ${OBJ_FD} diff --git a/libr/io/p/gdb.mk b/librz/io/p/gdb.mk similarity index 63% rename from libr/io/p/gdb.mk rename to librz/io/p/gdb.mk index 6f5f561811..d1b752e4c3 100644 --- a/libr/io/p/gdb.mk +++ b/librz/io/p/gdb.mk @@ -11,15 +11,15 @@ LDFLAGS+=$(SHLR)/gdb/lib/libgdbr.$(EXT_AR) include $(LIBR)/socket/deps.mk ifeq (${WITHPIC},0) -LINKFLAGS=../../socket/libr_socket.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../cons/libr_cons.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS=../../socket/librz_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../cons/librz_cons.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS=-L../../socket -lr_socket -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../cons -lr_cons -LINKFLAGS+=-L.. -lr_io +LINKFLAGS=-L../../socket -lrz_socket +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../cons -lrz_cons +LINKFLAGS+=-L.. -lrz_io endif ifeq (${HAVE_LIB_SSL},1) CFLAGS+=${SSL_CFLAGS} diff --git a/libr/io/p/gprobe.mk b/librz/io/p/gprobe.mk similarity index 68% rename from libr/io/p/gprobe.mk rename to librz/io/p/gprobe.mk index 20a31b3533..d0cae9a738 100644 --- a/libr/io/p/gprobe.mk +++ b/librz/io/p/gprobe.mk @@ -5,11 +5,11 @@ TARGET_GPROBE=io_gprobe.${EXT_SO} ALL_TARGETS+=${TARGET_GPROBE} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_GPROBE}: ${OBJ_GPROBE} diff --git a/libr/io/p/gzip.mk b/librz/io/p/gzip.mk similarity index 66% rename from libr/io/p/gzip.mk rename to librz/io/p/gzip.mk index f7d9c7f38d..a22fd6f0c9 100644 --- a/libr/io/p/gzip.mk +++ b/librz/io/p/gzip.mk @@ -5,11 +5,11 @@ TARGET_GZIP=io_gzip.${EXT_SO} ALL_TARGETS+=${TARGET_GZIP} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_GZIP}: ${OBJ_GZIP} diff --git a/libr/io/p/http.mk b/librz/io/p/http.mk similarity index 56% rename from libr/io/p/http.mk rename to librz/io/p/http.mk index 8db0cae6ba..130ae0198c 100644 --- a/libr/io/p/http.mk +++ b/librz/io/p/http.mk @@ -5,13 +5,13 @@ TARGET_HTTP=io_http.${EXT_SO} ALL_TARGETS+=${TARGET_HTTP} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a -LINKFLAGS+=../../io/libr_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a +LINKFLAGS+=../../io/librz_socket.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../socket -lr_socket -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../socket -lrz_socket +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_HTTP}: ${OBJ_HTTP} diff --git a/libr/io/p/ihex.mk b/librz/io/p/ihex.mk similarity index 66% rename from libr/io/p/ihex.mk rename to librz/io/p/ihex.mk index f72671eb4e..7b635224b9 100644 --- a/libr/io/p/ihex.mk +++ b/librz/io/p/ihex.mk @@ -5,11 +5,11 @@ TARGET_IHEX=io_ihex.${EXT_SO} ALL_TARGETS+=${TARGET_IHEX} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_IHEX}: ${OBJ_IHEX} diff --git a/libr/io/p/io_ar.c b/librz/io/p/io_ar.c similarity index 50% rename from libr/io/p/io_ar.c rename to librz/io/p/io_ar.c index 35e82a01bb..248fcc4ca9 100644 --- a/libr/io/p/io_ar.c +++ b/librz/io/p/io_ar.c @@ -1,17 +1,17 @@ /* radare - LGPLv3- Copyright 2017 - xarkes */ -#include -#include -#include -#include +#include +#include +#include +#include #include "ar.h" -static bool r_io_ar_plugin_open(RIO *io, const char *file, bool many) { +static bool rz_io_ar_plugin_open(RzIO *io, const char *file, bool many) { return !strncmp ("ar://", file, 5) || !strncmp ("lib://", file, 6); } -static RIODesc *r_io_ar_open(RIO *io, const char *file, int rw, int mode) { - RIODesc *res = NULL; +static RzIODesc *rz_io_ar_open(RzIO *io, const char *file, int rw, int mode) { + RzIODesc *res = NULL; char *url = strdup (file); char *arname = strstr (url, "://") + 3; char *filename = strstr (arname, "//"); @@ -22,18 +22,18 @@ static RIODesc *r_io_ar_open(RIO *io, const char *file, int rw, int mode) { RBuffer *b = ar_open_file (arname, filename); if (b) { - res = r_io_desc_new (io, &r_io_plugin_ar, filename, rw, mode, b); + res = rz_io_desc_new (io, &rz_io_plugin_ar, filename, rw, mode, b); } free (url); return res; } -static RList *r_io_ar_open_many(RIO *io, const char *file, int rw, int mode) { +static RzList *rz_io_ar_open_many(RzIO *io, const char *file, int rw, int mode) { eprintf ("Not implemented\n"); return NULL; } -static ut64 r_io_ar_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 rz_io_ar_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { RBuffer *b; ut64 seek_val = 0; @@ -42,29 +42,29 @@ static ut64 r_io_ar_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { } b = fd->data; - seek_val = r_buf_tell (b); + seek_val = rz_buf_tell (b); switch (whence) { case SEEK_SET: - seek_val = (r_buf_size (b) < offset)? r_buf_size (b) : offset; + seek_val = (rz_buf_size (b) < offset)? rz_buf_size (b) : offset; io->off = seek_val; - r_buf_seek (b, seek_val, R_BUF_SET); + rz_buf_seek (b, seek_val, R_BUF_SET); return seek_val; case SEEK_CUR: - seek_val = (r_buf_size (b) < offset)? r_buf_size (b) : offset; + seek_val = (rz_buf_size (b) < offset)? rz_buf_size (b) : offset; io->off = seek_val; - r_buf_seek (b, seek_val, R_BUF_SET); + rz_buf_seek (b, seek_val, R_BUF_SET); return seek_val; case SEEK_END: - seek_val = r_buf_size (b); + seek_val = rz_buf_size (b); io->off = seek_val; - r_buf_seek (b, seek_val, R_BUF_SET); + rz_buf_seek (b, seek_val, R_BUF_SET); return seek_val; } return seek_val; } -static int r_io_ar_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int rz_io_ar_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { RBuffer *b; if (!fd || !fd->data || !buf) { return -1; @@ -73,7 +73,7 @@ static int r_io_ar_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return ar_read_at (b, io->off, buf, count); } -static int r_io_ar_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int rz_io_ar_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { RBuffer *b = NULL; if (!fd || !fd->data || !buf) { return -1; @@ -81,7 +81,7 @@ static int r_io_ar_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return ar_write_at (b, io->off, (void *) buf, count); } -static int r_io_ar_close(RIODesc *fd) { +static int rz_io_ar_close(RzIODesc *fd) { RBuffer *b = NULL; if (!fd || !fd->data) { return -1; @@ -90,24 +90,24 @@ static int r_io_ar_close(RIODesc *fd) { return ar_close (b); } -RIOPlugin r_io_plugin_ar = { +RzIOPlugin rz_io_plugin_ar = { .name = "ar", .desc = "Open ar/lib files", .license = "LGPL3", .uris = "ar://,lib://", - .open = r_io_ar_open, - .open_many = r_io_ar_open_many, - .write = r_io_ar_write, - .read = r_io_ar_read, - .close = r_io_ar_close, - .lseek = r_io_ar_lseek, - .check = r_io_ar_plugin_open + .open = rz_io_ar_open, + .open_many = rz_io_ar_open_many, + .write = rz_io_ar_write, + .read = rz_io_ar_read, + .close = rz_io_ar_close, + .lseek = rz_io_ar_lseek, + .check = rz_io_ar_plugin_open }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_ar, + .data = &rz_io_plugin_ar, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_bfdbg.c b/librz/io/p/io_bfdbg.c similarity index 74% rename from libr/io/p/io_bfdbg.c rename to librz/io/p/io_bfdbg.c index 92eb158b52..f33c707935 100644 --- a/libr/io/p/io_bfdbg.c +++ b/librz/io/p/io_bfdbg.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2011-2013 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include -#undef R_API -#define R_API static inline +#undef RZ_API +#define RZ_API static inline #include "../debug/p/bfvm.h" #include "../debug/p/bfvm.c" @@ -16,11 +16,11 @@ typedef struct { ut8 *buf; ut32 size; BfvmCPU *bfvm; -} RIOBfdbg; +} RzIOBfdbg; -#define RIOBFDBG_FD(x) (((RIOBfdbg*)(x)->data)->fd) -#define RIOBFDBG_SZ(x) (((RIOBfdbg*)(x)->data)->size) -#define RIOBFDBG_BUF(x) (((RIOBfdbg*)(x)->data)->buf) +#define RzIOBFDBG_FD(x) (((RzIOBfdbg*)(x)->data)->fd) +#define RzIOBFDBG_SZ(x) (((RzIOBfdbg*)(x)->data)->size) +#define RzIOBFDBG_BUF(x) (((RzIOBfdbg*)(x)->data)->buf) static inline int is_in_screen(ut64 off, BfvmCPU *c) { return (off >= c->screen && off < c->screen+c->screen_size); @@ -34,8 +34,8 @@ static inline int is_in_base(ut64 off, BfvmCPU *c) { return (off >= c->base && off < c->base+c->size); } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - RIOBfdbg *riom; +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + RzIOBfdbg *riom; int sz; if (!fd || !fd->data) { return -1; @@ -69,19 +69,19 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return count; } /* read from file */ - sz = RIOBFDBG_SZ (fd); + sz = RzIOBFDBG_SZ (fd); if (io->off + count >= sz) { count = sz - io->off; } if (io->off >= sz) { return -1; } - memcpy (RIOBFDBG_BUF (fd)+io->off, buf, count); + memcpy (RzIOBFDBG_BUF (fd)+io->off, buf, count); return count; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - RIOBfdbg *riom; +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + RzIOBfdbg *riom; int sz; if (!fd || !fd->data) { return -1; @@ -115,19 +115,19 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return count; } /* read from file */ - sz = RIOBFDBG_SZ (fd); + sz = RzIOBFDBG_SZ (fd); if (io->off + count >= sz) { count = sz - io->off; } if (io->off >= sz) { return -1; } - memcpy (buf, RIOBFDBG_BUF (fd)+io->off, count); + memcpy (buf, RzIOBFDBG_BUF (fd)+io->off, count); return count; } -static int __close(RIODesc *fd) { - RIOBfdbg *riom; +static int __close(RzIODesc *fd) { + RzIOBfdbg *riom; if (!fd || !fd->data) { return -1; } @@ -138,32 +138,32 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; - case SEEK_END: return RIOBFDBG_SZ (fd); + case SEEK_END: return RzIOBFDBG_SZ (fd); } return offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "bfdbg://", 8)); } -static inline int getmalfd (RIOBfdbg *mal) { +static inline int getmalfd (RzIOBfdbg *mal) { return 0xffff & (int)(size_t)mal->buf; } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { char *out; if (__plugin_open (io, pathname, 0)) { - RIOBind iob; - RIOBfdbg *mal = R_NEW0 (RIOBfdbg); + RzIOBind iob; + RzIOBfdbg *mal = R_NEW0 (RzIOBfdbg); if (!mal) { return NULL; } - r_io_bind (io, &iob); + rz_io_bind (io, &iob); mal->fd = getmalfd (mal); mal->bfvm = bfvm_new (&iob); if (!mal->bfvm) { @@ -171,7 +171,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } size_t rlen; - out = r_file_slurp (pathname+8, &rlen); + out = rz_file_slurp (pathname+8, &rlen); if (!out || rlen < 1) { free (mal); free (out); @@ -182,7 +182,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { if (mal->buf != NULL) { memcpy (mal->buf, out, rlen); free (out); - return r_io_desc_new (io, &r_io_plugin_bfdbg, + return rz_io_desc_new (io, &rz_io_plugin_bfdbg, pathname, rw, mode, mal); } eprintf ("Cannot allocate (%s) %"PFMT32u" byte(s)\n", @@ -193,7 +193,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_bfdbg = { +RzIOPlugin rz_io_plugin_bfdbg = { .name = "bfdbg", .desc = "Attach to brainFuck Debugger instance", .license = "LGPL3", @@ -207,9 +207,9 @@ RIOPlugin r_io_plugin_bfdbg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_bfdbg, + .data = &rz_io_plugin_bfdbg, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_bochs.c b/librz/io/p/io_bochs.c similarity index 68% rename from libr/io/p/io_bochs.c rename to librz/io/p/io_bochs.c index 93089bf0e1..e25a7fdf90 100644 --- a/libr/io/p/io_bochs.c +++ b/librz/io/p/io_bochs.c @@ -1,24 +1,24 @@ // Copyright (c) 2016-2017 - LGPL, SkUaTeR, All rights reserved. -#include -#include -#include +#include +#include +#include #include typedef struct { libbochs_t desc; -} RIOBochs; +} RzIOBochs; static libbochs_t *desc = NULL; -static RIODesc *riobochs = NULL; -extern RIOPlugin r_io_plugin_bochs; // forward declaration +static RzIODesc *riobochs = NULL; +extern RzIOPlugin rz_io_plugin_bochs; // forward declaration -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return !strncmp (file, "bochs://", strlen ("bochs://")); } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - RIOBochs *riob; +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { + RzIOBochs *riob; lprintf("io_open\n"); const char *i; char * fileBochs = NULL; @@ -27,7 +27,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { if (!__plugin_open (io, file, 0)) { return NULL; } - if (r_sandbox_enable (false)) { + if (rz_sandbox_enable (false)) { eprintf ("sandbox exit\n"); return NULL; } @@ -38,20 +38,20 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { i = strchr (file + 8, '#'); if (i) { l = i - file - 8; - fileBochs = r_str_ndup (file + 8, l); + fileBochs = rz_str_ndup (file + 8, l); fileCfg = strdup (i + 1); } else { free (fileCfg); eprintf ("Error can't find :\n"); return NULL; } - riob = R_NEW0 (RIOBochs); + riob = R_NEW0 (RzIOBochs); // Inicializamos if (bochs_open (&riob->desc, fileBochs, fileCfg) == true) { desc = &riob->desc; - riobochs = r_io_desc_new (io, &r_io_plugin_bochs, file, rw, mode, riob); - //riogdb = r_io_desc_new (&r_io_plugin_gdb, riog->desc.sock->fd, file, rw, mode, riog); + riobochs = rz_io_desc_new (io, &rz_io_plugin_bochs, file, rw, mode, riob); + //riogdb = rz_io_desc_new (&rz_io_plugin_gdb, riog->desc.sock->fd, file, rw, mode, riog); free(fileBochs); free(fileCfg); return riobochs; @@ -63,17 +63,17 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { return NULL; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { lprintf("io_write\n"); return -1; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { lprintf("io_seek %016"PFMT64x" \n",offset); return offset; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); ut64 addr = io->off; if (!desc || !desc->data) { @@ -84,13 +84,13 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return count; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { lprintf("io_close\n"); bochs_close (desc); return true; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { lprintf ("system command (%s)\n", cmd); if (!strcmp (cmd, "help")) { lprintf ("Usage: =!cmd args\n" @@ -106,7 +106,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_bochs = { +RzIOPlugin rz_io_plugin_bochs = { .name = "bochs", .desc = "Attach to a BOCHS debugger instance", .license = "LGPL3", @@ -122,9 +122,9 @@ RIOPlugin r_io_plugin_bochs = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_bochs, + .data = &rz_io_plugin_bochs, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_debug.c b/librz/io/p/io_debug.c similarity index 79% rename from libr/io/p/io_debug.c rename to librz/io/p/io_debug.c index b90a076cdd..e3034aba54 100644 --- a/libr/io/p/io_debug.c +++ b/librz/io/p/io_debug.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ #include -#include -#include -#include -#include -#include /* only used for BSD PTRACE redefinitions */ +#include +#include +#include +#include +#include /* only used for BSD PTRACE redefinitions */ #include #define USE_RARUN 0 @@ -63,7 +63,7 @@ typedef struct { HANDLE hnd; ut64 winbase; -} RIOW32; +} RzIOW32; static int setup_tokens(void) { HANDLE tok = NULL; @@ -88,7 +88,7 @@ err_enable: CloseHandle (tok); } if (err) { - r_sys_perror ("setup_tokens"); + rz_sys_perror ("setup_tokens"); } return err; } @@ -108,7 +108,7 @@ static int __createprocess_wrap(void *params) { NULL, NULL, &si, p->pi); } -static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { +static int fork_and_ptraceme(RzIO *io, int bits, const char *cmd) { PROCESS_INFORMATION pi; STARTUPINFO si = { 0 }; si.cb = sizeof (si); @@ -121,20 +121,20 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { if (!io->w32dbg_wrap) { io->w32dbg_wrap = (struct w32dbg_wrap_instance_t *)w32dbg_wrap_new (); } - char *_cmd = io->args ? r_str_appendf (strdup (cmd), " %s", io->args) : + char *_cmd = io->args ? rz_str_appendf (strdup (cmd), " %s", io->args) : strdup (cmd); - char **argv = r_str_argv (_cmd, NULL); + char **argv = rz_str_argv (_cmd, NULL); char *cmdline = NULL; // We need to build a command line with quoted argument and escaped quotes int i = 0; while (argv[i]) { - r_str_arg_unescape (argv[i]); - cmdline = r_str_appendf (cmdline, "\"%s\" ", argv[i]); + rz_str_arg_unescape (argv[i]); + cmdline = rz_str_appendf (cmdline, "\"%s\" ", argv[i]); i++; } - LPTSTR appname_ = r_sys_conv_utf8_to_win (argv[0]); - LPTSTR cmdline_ = r_sys_conv_utf8_to_win (cmdline); + LPTSTR appname_ = rz_sys_conv_utf8_to_win (argv[0]); + LPTSTR cmdline_ = rz_sys_conv_utf8_to_win (cmdline); free (cmdline); struct __createprocess_params p = {appname_, cmdline_, &pi}; W32DbgWInst *wrap = (W32DbgWInst *)io->w32dbg_wrap; @@ -144,14 +144,14 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { w32dbg_wrap_wait_ret (wrap); if (!w32dbgw_ret (wrap)) { w32dbgw_err (wrap); - r_sys_perror ("fork_and_ptraceme/CreateProcess"); + rz_sys_perror ("fork_and_ptraceme/CreateProcess"); free (appname_); free (cmdline_); return -1; } free (appname_); free (cmdline_); - r_str_argv_free (argv); + rz_str_argv_free (argv); /* get process id and thread id */ pid = pi.dwProcessId; @@ -200,20 +200,20 @@ static void inferior_abort_handler(int pid) { static void trace_me(void) { #if __APPLE__ - r_sys_signal (SIGTRAP, SIG_IGN); //NEED BY STEP + rz_sys_signal (SIGTRAP, SIG_IGN); //NEED BY STEP #endif #if __APPLE__ || __BSD__ - /* we can probably remove this #if..as long as PT_TRACE_ME is redefined for OSX in r_debug.h */ - r_sys_signal (SIGABRT, inferior_abort_handler); + /* we can probably remove this #if..as long as PT_TRACE_ME is redefined for OSX in rz_debug.h */ + rz_sys_signal (SIGABRT, inferior_abort_handler); if (ptrace (PT_TRACE_ME, 0, 0, 0) != 0) { - r_sys_perror ("ptrace-traceme"); + rz_sys_perror ("ptrace-traceme"); } #if __APPLE__ ptrace (PT_SIGEXC, getpid(), NULL, 0); #endif #else if (ptrace (PTRACE_TRACEME, 0, NULL, NULL) != 0) { - r_sys_perror ("ptrace-traceme"); + rz_sys_perror ("ptrace-traceme"); exit (MAGIC_EXIT); } #endif @@ -240,10 +240,10 @@ static void handle_posix_error(int err) { } #endif -static RRunProfile* _get_run_profile(RIO *io, int bits, char **argv) { +static RRunProfile* _get_run_profile(RzIO *io, int bits, char **argv) { char *expr = NULL; int i; - RRunProfile *rp = r_run_new (NULL); + RRunProfile *rp = rz_run_new (NULL); if (!rp) { return NULL; } @@ -252,37 +252,37 @@ static RRunProfile* _get_run_profile(RIO *io, int bits, char **argv) { } rp->_args[i] = NULL; if (!argv[0]) { - r_run_free (rp); + rz_run_free (rp); return NULL; } rp->_program = strdup (argv[0]); rp->_dodebug = true; if (io->runprofile && *io->runprofile) { - if (!r_run_parsefile (rp, io->runprofile)) { + if (!rz_run_parsefile (rp, io->runprofile)) { eprintf ("Can't find profile '%s'\n", io->runprofile); - r_run_free (rp); + rz_run_free (rp); return NULL; } - if (strstr (io->runprofile, R_SYS_DIR ".rarun2.")) { - (void)r_file_rm (io->runprofile); + if (strstr (io->runprofile, R_SYS_DIR ".rz_run.")) { + (void)rz_file_rm (io->runprofile); } } else if (io->envprofile) { - if (!r_run_parse (rp, io->envprofile)) { - eprintf ("Can't parse default rarun2 profile\n"); - r_run_free (rp); + if (!rz_run_parse (rp, io->envprofile)) { + eprintf ("Can't parse default rz_run profile\n"); + rz_run_free (rp); return NULL; } } if (bits == 64) { - r_run_parseline (rp, expr=strdup ("bits=64")); + rz_run_parseline (rp, expr=strdup ("bits=64")); } else if (bits == 32) { - r_run_parseline (rp, expr=strdup ("bits=32")); + rz_run_parseline (rp, expr=strdup ("bits=32")); } free (expr); - if (r_run_config_env (rp)) { + if (rz_run_config_env (rp)) { eprintf ("Can't config the environment.\n"); - r_run_free (rp); + rz_run_free (rp); return NULL; } return rp; @@ -304,7 +304,7 @@ static void handle_posix_redirection(RRunProfile *rp, posix_spawn_file_actions_t } // __UNIX__ (not windows) -static int fork_and_ptraceme_for_mac(RIO *io, int bits, const char *cmd) { +static int fork_and_ptraceme_for_mac(RzIO *io, int bits, const char *cmd) { pid_t p = -1; char **argv; posix_spawn_file_actions_t fileActions; @@ -330,14 +330,14 @@ static int fork_and_ptraceme_for_mac(RIO *io, int bits, const char *cmd) { ps_flags |= POSIX_SPAWN_START_SUSPENDED; #define _POSIX_SPAWN_DISABLE_ASLR 0x0100 int ret; - argv = r_str_argv (cmd, NULL); + argv = rz_str_argv (cmd, NULL); if (!argv) { posix_spawn_file_actions_destroy (&fileActions); return -1; } RRunProfile *rp = _get_run_profile (io, bits, argv); if (!rp) { - r_str_argv_free (argv); + rz_str_argv_free (argv); posix_spawn_file_actions_destroy (&fileActions); return -1; } @@ -356,8 +356,8 @@ static int fork_and_ptraceme_for_mac(RIO *io, int bits, const char *cmd) { ret = posix_spawnp (&p, rp->_args[0], &fileActions, &attr, rp->_args, NULL); handle_posix_error (ret); } - r_str_argv_free (argv); - r_run_free (rp); + rz_str_argv_free (argv); + rz_run_free (rp); posix_spawn_file_actions_destroy (&fileActions); return p; // -1 ? } @@ -365,38 +365,38 @@ static int fork_and_ptraceme_for_mac(RIO *io, int bits, const char *cmd) { #if (!(__APPLE__ && !__POWERPC__)) typedef struct fork_child_data_t { - RIO *io; + RzIO *io; int bits; const char *cmd; } fork_child_data; static void fork_child_callback(void *user) { fork_child_data *data = user; - char **argv = r_str_argv (data->cmd, NULL); + char **argv = rz_str_argv (data->cmd, NULL); if (!argv) { exit (1); } - r_sys_clearenv (); + rz_sys_clearenv (); RRunProfile *rp = _get_run_profile (data->io, data->bits, argv); if (!rp) { - r_str_argv_free (argv); + rz_str_argv_free (argv); exit (1); } trace_me (); - r_run_start (rp); - r_run_free (rp); - r_str_argv_free (argv); + rz_run_start (rp); + rz_run_free (rp); + rz_str_argv_free (argv); exit (1); } -static int fork_and_ptraceme_for_unix(RIO *io, int bits, const char *cmd) { +static int fork_and_ptraceme_for_unix(RzIO *io, int bits, const char *cmd) { int ret, status, child_pid; void *bed = NULL; fork_child_data child_data; child_data.io = io; child_data.bits = bits; child_data.cmd = cmd; - child_pid = r_io_ptrace_fork (io, fork_child_callback, &child_data); + child_pid = rz_io_ptrace_fork (io, fork_child_callback, &child_data); switch (child_pid) { case -1: perror ("fork_and_ptraceme"); @@ -411,15 +411,15 @@ static int fork_and_ptraceme_for_unix(RIO *io, int bits, const char *cmd) { perror ("waitpid"); return -1; } - bed = r_cons_sleep_begin (); + bed = rz_cons_sleep_begin (); usleep (100000); - r_cons_sleep_end (bed); - } while (ret != child_pid && !r_cons_is_breaked ()); + rz_cons_sleep_end (bed); + } while (ret != child_pid && !rz_cons_is_breaked ()); if (WIFSTOPPED (status)) { eprintf ("Process with PID %d started...\n", (int)child_pid); } else if (WEXITSTATUS (status) == MAGIC_EXIT) { child_pid = -1; - } else if (r_cons_is_breaked ()) { + } else if (rz_cons_is_breaked ()) { kill (child_pid, SIGSTOP); } else { eprintf ("Killing child process %d due to an error\n", (int)child_pid); @@ -431,7 +431,7 @@ static int fork_and_ptraceme_for_unix(RIO *io, int bits, const char *cmd) { } #endif -static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { +static int fork_and_ptraceme(RzIO *io, int bits, const char *cmd) { #if __APPLE__ # if __POWERPC__ return fork_and_ptraceme_for_unix (io, bits, cmd); @@ -444,7 +444,7 @@ static int fork_and_ptraceme(RIO *io, int bits, const char *cmd) { } #endif -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { if (!strncmp (file, "waitfor://", 10)) { return true; } @@ -454,15 +454,15 @@ static bool __plugin_open(RIO *io, const char *file, bool many) { return (!strncmp (file, "dbg://", 6) && file[6]); } -#include -static int get_pid_of(RIO *io, const char *procname) { - RCore *c = io->corebind.core; +#include +static int get_pid_of(RzIO *io, const char *procname) { + RzCore *c = io->corebind.core; if (c && c->dbg && c->dbg->h) { - RListIter *iter; - RDebugPid *proc; - RDebug *d = c->dbg; - RList *pids = d->h->pids (d, 0); - r_list_foreach (pids, iter, proc) { + RzListIter *iter; + RzDebugPid *proc; + RzDebug *d = c->dbg; + RzList *pids = d->h->pids (d, 0); + rz_list_foreach (pids, iter, proc) { if (strstr (proc->path, procname)) { eprintf ("Matching PID %d %s\n", proc->pid, proc->path); return proc->pid; @@ -474,9 +474,9 @@ static int get_pid_of(RIO *io, const char *procname) { return -1; } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - RIOPlugin *_plugin; - RIODesc *ret = NULL; +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { + RzIOPlugin *_plugin; + RzIODesc *ret = NULL; char uri[128]; if (!strncmp (file, "waitfor://", 10)) { const char *procname = file + 10; @@ -488,7 +488,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { file = uri; break; } - r_sys_usleep (100); + rz_sys_usleep (100); } } else if (!strncmp (file, "pidof://", 8)) { const char *procname = file + 8; @@ -514,18 +514,18 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { } #if __WINDOWS__ sprintf (uri, "w32dbg://%d", pid); - _plugin = r_io_plugin_resolve (io, (const char *)uri, false); + _plugin = rz_io_plugin_resolve (io, (const char *)uri, false); if (!_plugin || !_plugin->open) { return NULL; } if ((ret = _plugin->open (io, uri, rw, mode))) { - RCore *c = io->corebind.core; + RzCore *c = io->corebind.core; W32DbgWInst *wrap = (W32DbgWInst *)ret->data; c->dbg->user = wrap; } #elif __APPLE__ sprintf (uri, "smach://%d", pid); //s is for spawn - _plugin = r_io_plugin_resolve (io, (const char *)uri + 1, false); + _plugin = rz_io_plugin_resolve (io, (const char *)uri + 1, false); if (!_plugin || !_plugin->open || !_plugin->close) { return NULL; } @@ -533,7 +533,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { #else // TODO: use io_procpid here? faster or what? sprintf (uri, "ptrace://%d", pid); - _plugin = r_io_plugin_resolve (io, (const char *)uri, false); + _plugin = rz_io_plugin_resolve (io, (const char *)uri, false); if (!_plugin || !_plugin->open) { return NULL; } @@ -541,14 +541,14 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { #endif } else { sprintf (uri, "attach://%d", pid); - _plugin = r_io_plugin_resolve (io, (const char *)uri, false); + _plugin = rz_io_plugin_resolve (io, (const char *)uri, false); if (!_plugin || !_plugin->open) { return NULL; } ret = _plugin->open (io, uri, rw, mode); #if __WINDOWS__ if (ret) { - RCore *c = io->corebind.core; + RzCore *c = io->corebind.core; W32DbgWInst *wrap = (W32DbgWInst *)ret->data; c->dbg->user = wrap; } @@ -562,18 +562,18 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { return ret; } -static int __close (RIODesc *desc) { +static int __close (RzIODesc *desc) { int ret = -2; eprintf ("something went wrong\n"); if (desc) { eprintf ("trying to close %d with io_debug\n", desc->fd); ret = -1; } - r_sys_backtrace (); + rz_sys_backtrace (); return ret; } -RIOPlugin r_io_plugin_debug = { +RzIOPlugin rz_io_plugin_debug = { .name = "debug", .desc = "Attach to native debugger instance", .license = "LGPL3", @@ -586,16 +586,16 @@ RIOPlugin r_io_plugin_debug = { .isdbg = true, }; #else -RIOPlugin r_io_plugin_debug = { +RzIOPlugin rz_io_plugin_debug = { .name = "debug", .desc = "Debug a program or pid. (NOT SUPPORTED FOR THIS PLATFORM)", }; #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_debug, + .data = &rz_io_plugin_debug, .version = R2_VERSION }; #endif diff --git a/librz/io/p/io_default.c b/librz/io/p/io_default.c new file mode 100644 index 0000000000..2cb3fb5e3f --- /dev/null +++ b/librz/io/p/io_default.c @@ -0,0 +1,343 @@ +/* radare - LGPL - Copyright 2008-2020 - pancake */ + +#include +#include +#include +#include + +typedef struct rz_io_mmo_t { + char * filename; + int mode; + int perm; + int fd; + int opened; + bool nocache; + ut8 modified; + RBuffer *buf; + RzIO * io_backref; + bool rawio; +} RzIOMMapFileObj; + +static int __io_posix_open(const char *file, int perm, int mode) { + int fd; + if (rz_str_startswith (file, "file://")) { + file += strlen ("file://"); + } + if (rz_file_is_directory (file)) { + return -1; + } +#if __WINDOWS__ + // probably unnecessary to have this ifdef nowadays windows is posix enough + if (perm & R_PERM_W) { + fd = rz_sandbox_open (file, O_RDWR, 0); + if (fd == -1 && (perm & R_PERM_CREAT)) { + rz_sandbox_creat (file, 0644); + fd = rz_sandbox_open (file, O_RDWR | O_CREAT, 0); + } + } else { + fd = rz_sandbox_open (file, O_RDONLY | O_BINARY, 0); + } +#else + const size_t posixFlags = (perm & R_PERM_W) ? (perm & R_PERM_CREAT) + ? (O_RDWR | O_CREAT) : O_RDWR : O_RDONLY; + fd = rz_sandbox_open (file, posixFlags, mode); +#endif + return fd; +} + +static ut64 rz_io_def_mmap_seek(RzIO *io, RzIOMMapFileObj *mmo, ut64 offset, int whence) { + if (!mmo) { + return UT64_MAX; + } + if (mmo->rawio) { + io->off = lseek (mmo->fd, offset, whence); + return io->off; + } + if (!mmo->buf) { + return UT64_MAX; + } + io->off = rz_buf_seek (mmo->buf, offset, whence); + return io->off; +} + +static int rz_io_def_mmap_refresh_def_mmap_buf(RzIOMMapFileObj *mmo) { + RzIO* io = mmo->io_backref; + ut64 cur; + if (mmo->buf) { + cur = rz_buf_tell (mmo->buf); + rz_buf_free (mmo->buf); + mmo->buf = NULL; + } else { + cur = 0; + } + st64 sz = rz_file_size (mmo->filename); + if (sz > ST32_MAX) { + // Do not use mmap if the file is huge + mmo->rawio = true; + } + if (mmo->rawio) { + mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode); + if (mmo->nocache) { +#ifdef F_NOCACHE + fcntl (mmo->fd, F_NOCACHE, 1); +#endif + } + return mmo->fd != -1; + } + mmo->buf = rz_buf_new_mmap (mmo->filename, mmo->perm); + if (mmo->buf) { + rz_io_def_mmap_seek (io, mmo, cur, SEEK_SET); + return true; + } else { + mmo->rawio = true; + mmo->fd = __io_posix_open (mmo->filename, mmo->perm, mmo->mode); + if (mmo->nocache) { +#ifdef F_NOCACHE + fcntl (mmo->fd, F_NOCACHE, 1); +#endif + } + return mmo->fd != -1; + } + return false; +} + +static void rz_io_def_mmap_free (RzIOMMapFileObj *mmo) { + if (mmo) { + free (mmo->filename); + rz_buf_free (mmo->buf); + close (mmo->fd); + free (mmo); + } +} + +RzIOMMapFileObj *rz_io_def_mmap_create_new_file(RzIO *io, const char *filename, int perm, int mode) { + rz_return_val_if_fail (io && filename, NULL); + RzIOMMapFileObj *mmo = R_NEW0 (RzIOMMapFileObj); + if (!mmo) { + return NULL; + } + if (rz_str_startswith (filename, "file://")) { + filename += strlen ("file://"); + } + mmo->nocache = rz_str_startswith (filename, "nocache://"); + if (mmo->nocache) { + filename += strlen ("nocache://"); + } + mmo->filename = strdup (filename); + mmo->perm = perm; + mmo->mode = mode; + mmo->io_backref = io; + const int posixFlags = (perm & R_PERM_W) + ?( + (perm & R_PERM_CREAT) + ? (O_RDWR | O_CREAT) + : O_RDWR + ): O_RDONLY; + mmo->fd = rz_sandbox_open (filename, posixFlags, mode); + if (mmo->fd == -1) { + free (mmo->filename); + free (mmo); + return NULL; + } + if (!rz_io_def_mmap_refresh_def_mmap_buf (mmo)) { + mmo->rawio = true; + if (!rz_io_def_mmap_refresh_def_mmap_buf (mmo)) { + rz_io_def_mmap_free (mmo); + mmo = NULL; + } + } + return mmo; +} + +static int rz_io_def_mmap_close(RzIODesc *fd) { + rz_return_val_if_fail (fd && fd->data, -1); + rz_io_def_mmap_free ((RzIOMMapFileObj *) fd->data); + fd->data = NULL; + return 0; +} + +static bool rz_io_def_mmap_check_default (const char *filename) { + rz_return_val_if_fail (filename && *filename, false); + if (rz_str_startswith (filename, "file://")) { + filename += strlen ("file://"); + } + const char * peekaboo = (!strncmp (filename, "nocache://", 10)) + ? NULL : strstr (filename, "://"); + return (!peekaboo || (peekaboo - filename) > 10); +} + +static int rz_io_def_mmap_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + rz_return_val_if_fail (fd && fd->data && buf, -1); + if (io->off == UT64_MAX) { + memset (buf, 0xff, count); + return count; + } + // TODO : unbox magic + RzIOMMapFileObj *mmo = fd->data; + if (!mmo) { + return -1; + } + if (mmo->rawio) { + if (lseek (mmo->fd, io->off, SEEK_SET) < 0) { + return -1; + } + return read (mmo->fd, buf, count); + } + if (rz_buf_size (mmo->buf) < io->off) { + io->off = rz_buf_size (mmo->buf); + } + int r = rz_buf_read_at (mmo->buf, io->off, buf, count); + if (r < 0) { + return r; + } + rz_buf_seek (mmo->buf, r, R_BUF_CUR); + io->off += r; + return r; +} + +static int rz_io_def_mmap_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + rz_return_val_if_fail (io && fd && fd->data && buf, -1); + + int len = -1; + ut64 addr = io->off; + RzIOMMapFileObj *mmo = fd->data; + if (mmo->rawio) { + if (lseek (mmo->fd, addr, 0) < 0) { + return -1; + } + len = write (mmo->fd, buf, count); + return len; + } + + if (mmo && mmo->buf) { + if (!(mmo->perm & R_PERM_W)) { + return -1; + } + if ( (count + addr > rz_buf_size (mmo->buf)) || rz_buf_size (mmo->buf) == 0) { + ut64 sz = count + addr; + rz_file_truncate (mmo->filename, sz); + } + } + + len = rz_file_mmap_write (mmo->filename, io->off, buf, count); + if (len != count) { + // aim to hack some corner cases? + if (lseek (fd->fd, addr, 0) < 0) { + return -1; + } + len = write (fd->fd, buf, count); + } + if (!rz_io_def_mmap_refresh_def_mmap_buf (mmo) ) { + eprintf ("io_def_mmap: failed to refresh the def_mmap backed buffer.\n"); + // XXX - not sure what needs to be done here (error handling). + } + return len; +} + +static RzIODesc *rz_io_def_mmap_open(RzIO *io, const char *file, int perm, int mode) { + rz_return_val_if_fail (io && file, NULL); + RzIOMMapFileObj *mmo = rz_io_def_mmap_create_new_file (io, file, perm, mode); + if (!mmo) { + return NULL; + } + RzIODesc *d = rz_io_desc_new (io, &rz_io_plugin_default, mmo->filename, perm, mode, mmo); + if (!d->name) { + d->name = strdup (file); + } + if (rz_str_startswith (d->name, "file://")) { + char *oldname = d->name; + d->name = strdup (oldname + strlen ("file://")); + free (oldname); + } + return d; +} + +static ut64 rz_io_def_mmap_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + rz_return_val_if_fail (fd && fd->data, UT64_MAX); + return rz_io_def_mmap_seek (io, (RzIOMMapFileObj *)fd->data, offset, whence); +} + +static int rz_io_def_mmap_truncate(RzIOMMapFileObj *mmo, ut64 size) { + bool res = rz_file_truncate (mmo->filename, size); + if (res && !rz_io_def_mmap_refresh_def_mmap_buf (mmo) ) { + eprintf ("rz_io_def_mmap_truncate: Error trying to refresh the def_mmap'ed file."); + res = false; + } else if (!res) { + eprintf ("rz_io_def_mmap_truncate: Error trying to resize the file."); + } + return res; +} + +static bool __plugin_open_default(RzIO *io, const char *file, bool many) { + return rz_io_def_mmap_check_default (file); +} + +// default open should permit opening +static RzIODesc *__open_default(RzIO *io, const char *file, int perm, int mode) { + if (rz_io_def_mmap_check_default (file)) { + return rz_io_def_mmap_open (io, file, perm, mode); + } + return NULL; +} + +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { + return rz_io_def_mmap_read (io, fd, buf, len); +} + +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { + return rz_io_def_mmap_write(io, fd, buf, len); +} + +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + return rz_io_def_mmap_lseek (io, fd, offset, whence); +} + +static int __close(RzIODesc *fd) { + return rz_io_def_mmap_close (fd); +} + +static bool __resize(RzIO *io, RzIODesc *fd, ut64 size) { + rz_return_val_if_fail (io && fd && fd->data, false); + RzIOMMapFileObj *mmo = fd->data; + if (!(mmo->perm & R_PERM_W)) { + return false; + } + return rz_io_def_mmap_truncate (mmo, size); +} + +#if __UNIX__ +static bool __is_blockdevice (RzIODesc *desc) { + rz_return_val_if_fail (desc && desc->data, false); + RzIOMMapFileObj *mmo = desc->data; + struct stat buf; + if (fstat (mmo->fd, &buf) == -1) { + return false; + } + return ((buf.st_mode & S_IFBLK) == S_IFBLK); +} +#endif + +RzIOPlugin rz_io_plugin_default = { + .name = "default", + .desc = "Open local files", + .license = "LGPL3", + .uris = "file://,nocache://", + .open = __open_default, + .close = __close, + .read = __read, + .check = __plugin_open_default, + .lseek = __lseek, + .write = __write, + .resize = __resize, +#if __UNIX__ + .is_blockdevice = __is_blockdevice, +#endif +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_IO, + .data = &rz_io_plugin_default, + .version = R2_VERSION +}; +#endif diff --git a/libr/io/p/io_fd.c b/librz/io/p/io_fd.c similarity index 55% rename from libr/io/p/io_fd.c rename to librz/io/p/io_fd.c index 84abefa5f0..24a71e0959 100644 --- a/libr/io/p/io_fd.c +++ b/librz/io/p/io_fd.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2020 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include -#include +#include #include #if __WINDOWS__ @@ -15,63 +15,63 @@ typedef struct { int fd; -} RIOFdata; +} RzIOFdata; -static int __write(RIO *io, RIODesc *desc, const ut8 *buf, int count) { - RIOFdata *fdd = (RIOFdata*)desc->data; +static int __write(RzIO *io, RzIODesc *desc, const ut8 *buf, int count) { + RzIOFdata *fdd = (RzIOFdata*)desc->data; if (fdd) { return write (fdd->fd, buf, count); } return -1; } -static bool __resize(RIO *io, RIODesc *desc, ut64 count) { - RIOFdata *fdd = (RIOFdata*)desc->data; +static bool __resize(RzIO *io, RzIODesc *desc, ut64 count) { + RzIOFdata *fdd = (RzIOFdata*)desc->data; if (fdd) { return ftruncate (fdd->fd, count) == 0; } return false; } -static int __read(RIO *io, RIODesc *desc, ut8 *buf, int count) { - RIOFdata *fdd = (RIOFdata*)desc->data; +static int __read(RzIO *io, RzIODesc *desc, ut8 *buf, int count) { + RzIOFdata *fdd = (RzIOFdata*)desc->data; if (fdd) { - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); int res = read (fdd->fd, buf, count); - r_cons_break_pop (); + rz_cons_break_pop (); return res; } return -1; } -static int __close(RIODesc *desc) { +static int __close(RzIODesc *desc) { R_FREE (desc->data); return 0; } -static ut64 __lseek(RIO* io, RIODesc *desc, ut64 offset, int whence) { - RIOFdata *fdd = (RIOFdata*)desc->data; +static ut64 __lseek(RzIO* io, RzIODesc *desc, ut64 offset, int whence) { + RzIOFdata *fdd = (RzIOFdata*)desc->data; if (fdd) { return lseek (fdd->fd, offset, whence); } return 0; } -static bool __check(RIO *io, const char *pathname, bool many) { +static bool __check(RzIO *io, const char *pathname, bool many) { return !strncmp (pathname, FDURI, strlen (FDURI)); } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { - if (r_sandbox_enable (false)) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { + if (rz_sandbox_enable (false)) { eprintf ("Do not permit " FDURI " in sandbox mode.\n"); return NULL; } if (!__check (io, pathname, 0)) { return NULL; } - RIOFdata *fdd = R_NEW0 (RIOFdata); + RzIOFdata *fdd = R_NEW0 (RzIOFdata); if (fdd) { - fdd->fd = r_num_math (NULL, pathname + strlen (FDURI)); + fdd->fd = rz_num_math (NULL, pathname + strlen (FDURI)); #if __WINDOWS__ fdd->fd = _open_osfhandle (fdd->fd, 0); #endif @@ -81,10 +81,10 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } } - return r_io_desc_new (io, &r_io_plugin_fd, pathname, R_PERM_RW | rw, mode, fdd); + return rz_io_desc_new (io, &rz_io_plugin_fd, pathname, R_PERM_RW | rw, mode, fdd); } -RIOPlugin r_io_plugin_fd = { +RzIOPlugin rz_io_plugin_fd = { #if __WINDOWS__ .name = "handle", .desc = "Local process file handle IO", @@ -104,9 +104,9 @@ RIOPlugin r_io_plugin_fd = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_fd, + .data = &rz_io_plugin_fd, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_gdb.c b/librz/io/p/io_gdb.c similarity index 83% rename from libr/io/p/io_gdb.c rename to librz/io/p/io_gdb.c index 114fa33ef9..d1316f23a9 100644 --- a/libr/io/p/io_gdb.c +++ b/librz/io/p/io_gdb.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2010-2020 pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #define IRAPI static inline #include @@ -12,14 +12,14 @@ typedef struct { libgdbr_t desc; -} RIOGdb; +} RzIOGdb; -#define R_GDB_MAGIC r_str_hash ("gdb") +#define R_GDB_MAGIC rz_str_hash ("gdb") -static int __close(RIODesc *fd); +static int __close(RzIODesc *fd); static libgdbr_t *desc = NULL; -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return (!strncmp (file, "gdb://", 6)); } @@ -50,9 +50,9 @@ static int debug_gdb_write_at(const ut8 *buf, int sz, ut64 addr) { return sz; } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - RIODesc *riogdb = NULL; - RIOGdb *riog; +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { + RzIODesc *riogdb = NULL; + RzIOGdb *riog; char host[128], *port, *pid; int i_port = -1; bool isdev = false; @@ -77,7 +77,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { pid = strchr (host, ':'); } } else { - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: Cannot use network\n"); return NULL; } @@ -105,7 +105,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { i_port = atoi (port); } - if (!(riog = R_NEW0 (RIOGdb))) { + if (!(riog = R_NEW0 (RzIOGdb))) { return NULL; } gdbr_init (&riog->desc, false); @@ -114,7 +114,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { __close (NULL); // R_FREE (desc); desc = &riog->desc; - if (pid > 0) { // FIXME this is here for now because RDebug's pid and libgdbr's aren't properly synced. + if (pid > 0) { // FIXME this is here for now because RzDebug's pid and libgdbr's aren't properly synced. desc->pid = i_pid; if (gdbr_attach (desc, i_pid) < 0) { eprintf ("gdbr: Failed to attach to PID %i\n", i_pid); @@ -123,7 +123,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { } else if ((i_pid = desc->pid) < 0) { i_pid = -1; } - riogdb = r_io_desc_new (io, &r_io_plugin_gdb, file, R_PERM_RWX, mode, riog); + riogdb = rz_io_desc_new (io, &rz_io_plugin_gdb, file, R_PERM_RWX, mode, riog); } // Get name if (riogdb) { @@ -135,7 +135,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { return riogdb; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { ut64 addr = io->off; if (!desc || !desc->data) { return -1; @@ -143,7 +143,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return debug_gdb_write_at (buf, count, addr); } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: io->off = offset; @@ -157,7 +157,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { if (!io || !fd || !buf || count < 1) { return -1; } @@ -169,7 +169,7 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return debug_gdb_read_at (buf, count, addr); } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { if (fd) { R_FREE (fd->name); } @@ -179,15 +179,15 @@ static int __close(RIODesc *fd) { return -1; } -static int __getpid(RIODesc *fd) { +static int __getpid(RzIODesc *fd) { // XXX don't use globals return desc ? desc->pid : -1; #if 0 - // dupe for ? r_io_desc_get_pid (desc); + // dupe for ? rz_io_desc_get_pid (desc); if (!desc || !desc->data) { return -1; } - RIODescData *iodd = desc->data; + RzIODescData *iodd = desc->data; if (iodd) { if (iodd->magic != R_GDB_MAGIC) { return -1; @@ -198,14 +198,14 @@ static int __getpid(RIODesc *fd) { #endif } -static int __gettid(RIODesc *fd) { +static int __gettid(RzIODesc *fd) { return desc ? desc->tid : -1; } extern int send_msg(libgdbr_t *g, const char *command); extern int read_packet(libgdbr_t *instance, bool vcont); -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { if (!desc) { return NULL; } @@ -229,8 +229,8 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { " current/specified pid\n"); return NULL; } - if (r_str_startswith (cmd, "pktsz")) { - const char *ptr = r_str_trim_head_ro (cmd + 5); + if (rz_str_startswith (cmd, "pktsz")) { + const char *ptr = rz_str_trim_head_ro (cmd + 5); if (!isdigit ((ut8)*ptr)) { io->cb_printf ("packet size: %u bytes\n", desc->stub_features.pkt_sz); @@ -244,13 +244,13 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { desc->stub_features.pkt_sz = R_MAX (pktsz, 8); // min = 64 return NULL; } - if (r_str_startswith (cmd, "detach")) { + if (rz_str_startswith (cmd, "detach")) { int res; if (!isspace ((ut8)cmd[6]) || !desc->stub_features.multiprocess) { res = gdbr_detach (desc) >= 0; } else { int pid = 0; - cmd = r_str_trim_head_ro (cmd + 6); + cmd = rz_str_trim_head_ro (cmd + 6); if (!*cmd || !(pid = strtoul (cmd, NULL, 10))) { res = gdbr_detach (desc) >= 0; } else { @@ -260,7 +260,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { eprintf ("%d\n", res); return NULL; } - if (r_str_startswith (cmd, "pkt ")) { + if (rz_str_startswith (cmd, "pkt ")) { gdbr_lock_enter (desc); if (send_msg (desc, cmd + 4) >= 0) { (void)read_packet (desc, false); @@ -273,7 +273,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { gdbr_lock_leave (desc); return NULL; } - if (r_str_startswith (cmd, "rd")) { + if (rz_str_startswith (cmd, "rd")) { PJ *pj = pj_new (); pj_o (pj); pj_kb (pj, "reverse-continue", desc->stub_features.ReverseStep); @@ -283,7 +283,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { pj_free (pj); return NULL; } - if (r_str_startswith (cmd, "dsb")) { + if (rz_str_startswith (cmd, "dsb")) { if (!desc->stub_features.ReverseStep) { eprintf ("Stepping backwards is not supported in this gdbserver implementation\n"); return NULL; @@ -306,7 +306,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { gdbr_lock_leave (desc); return NULL; } - if (r_str_startswith (cmd, "dcb")) { + if (rz_str_startswith (cmd, "dcb")) { if (!desc->stub_features.ReverseContinue) { eprintf ("Continue backwards is not supported in this gdbserver implementation\n"); return NULL; @@ -329,14 +329,14 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { gdbr_lock_leave (desc); return NULL; } - if (r_str_startswith (cmd, "pid")) { + if (rz_str_startswith (cmd, "pid")) { int pid = desc ? desc->pid : -1; if (!cmd[3]) { io->cb_printf ("%d\n", pid); } - return r_str_newf ("%d", pid); + return rz_str_newf ("%d", pid); } - if (r_str_startswith (cmd, "monitor")) { + if (rz_str_startswith (cmd, "monitor")) { const char *qrcmd = cmd + 8; if (!isspace ((ut8)cmd[7])) { qrcmd = "help"; @@ -347,11 +347,11 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } return NULL; } - if (r_str_startswith (cmd, "inv.reg")) { + if (rz_str_startswith (cmd, "inv.reg")) { gdbr_invalidate_reg_cache (); return NULL; } - if (r_str_startswith (cmd, "exec_file")) { + if (rz_str_startswith (cmd, "exec_file")) { const char *ptr = cmd + strlen ("exec_file"); char *file; if (!isspace ((ut8)*ptr)) { @@ -374,7 +374,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return file; } // These are internal, not available to user directly - if (r_str_startswith (cmd, "retries")) { + if (rz_str_startswith (cmd, "retries")) { int num_retries; if (isspace ((ut8)cmd[7]) && isdigit ((ut8)cmd[8])) { if ((num_retries = atoi (cmd + 8)) >= 1) { @@ -385,7 +385,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { io->cb_printf ("num_retries: %d byte(s)\n", desc->page_size); return NULL; } - if (r_str_startswith (cmd, "page_size")) { + if (rz_str_startswith (cmd, "page_size")) { int page_size; if (isspace ((ut8)cmd[9]) && isdigit ((ut8)cmd[10])) { if ((page_size = atoi (cmd + 10)) >= 64) { @@ -405,7 +405,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_gdb = { +RzIOPlugin rz_io_plugin_gdb = { //void *plugin; .name = "gdb", .license = "LGPL3", @@ -424,9 +424,9 @@ RIOPlugin r_io_plugin_gdb = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_gdb, + .data = &rz_io_plugin_gdb, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_gprobe.c b/librz/io/p/io_gprobe.c similarity index 81% rename from libr/io/p/io_gprobe.c rename to librz/io/p/io_gprobe.c index 50b1b39393..4e20f55475 100644 --- a/libr/io/p/io_gprobe.c +++ b/librz/io/p/io_gprobe.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2018 - Dirk Eibach, Guntermann & Drunck GmbH */ -#include -#include -#include -#include +#include +#include +#include +#include #if __UNIX__ #include @@ -67,7 +67,7 @@ struct gport { typedef struct { struct gport gport; ut64 offset; -} RIOGprobe; +} RzIOGprobe; enum { GPROBE_DEBUGON = 0x09, @@ -94,17 +94,17 @@ static ut8 gprobe_checksum_i2c (const ut8 *p, unsigned int size, ut8 initial) { } static void gprobe_frame_i2c(RBuffer *frame) { - ut8 size = r_buf_size (frame) + 1; + ut8 size = rz_buf_size (frame) + 1; ut8 header[] = {0x51, 0x80 + size + 3, 0xc2, 0x00, 0x00}; - r_buf_prepend_bytes (frame, &size, 1); - r_buf_prepend_bytes (frame, header, sizeof (header)); + rz_buf_prepend_bytes (frame, &size, 1); + rz_buf_prepend_bytes (frame, header, sizeof (header)); ut64 tmpsz; - const ut8 *tmp = r_buf_data (frame, &tmpsz); + const ut8 *tmp = rz_buf_data (frame, &tmpsz); ut8 checksum = gprobe_checksum_i2c (tmp, tmpsz, GPROBE_I2C_ADDR); - r_buf_append_bytes (frame, &checksum, 1); + rz_buf_append_bytes (frame, &checksum, 1); } static int gprobe_get_reply_i2c(struct gport *port, ut8 cmd, RBuffer *reply) { @@ -114,7 +114,7 @@ static int gprobe_get_reply_i2c(struct gport *port, ut8 cmd, RBuffer *reply) { ut8 addr = 0x50; ut8 checksum; - r_sys_usleep (40000); + rz_sys_usleep (40000); count = read (port->fd, buf, sizeof (buf)); @@ -141,15 +141,15 @@ static int gprobe_get_reply_i2c(struct gport *port, ut8 cmd, RBuffer *reply) { eprintf ("gprobe rx checksum error\n"); } - r_buf_append_bytes (reply, buf + 7, buf[5] - 3); + rz_buf_append_bytes (reply, buf + 7, buf[5] - 3); return 0; } static int gprobe_send_request_i2c(struct gport *port, RBuffer *request) { ut64 tmpsz; - const ut8 *tmp = r_buf_data (request, &tmpsz); - if (write (port->fd, tmp, tmpsz) != r_buf_size (request)) { + const ut8 *tmp = rz_buf_data (request, &tmpsz); + if (write (port->fd, tmp, tmpsz) != rz_buf_size (request)) { return -1; } return 0; @@ -165,17 +165,17 @@ static int i2c_open(struct gport *port) { snprintf (filename, sizeof (filename), "/dev/i2c/%d", i2cbus); filename[sizeof (filename) - 1] = '\0'; - int file = r_sandbox_open (filename, O_RDWR, 0); + int file = rz_sandbox_open (filename, O_RDWR, 0); if (file < 0 && (errno == ENOENT || errno == ENOTDIR)) { sprintf (filename, "/dev/i2c-%d", i2cbus); - file = r_sandbox_open (filename, O_RDWR, 0); + file = rz_sandbox_open (filename, O_RDWR, 0); } if (file < 0) { return -1; } if (ioctl (file, I2C_SLAVE, GPROBE_I2C_ADDR >> 1) < 0) { - r_sandbox_close (file); + rz_sandbox_close (file); port->fd = -1; return -1; } @@ -255,7 +255,7 @@ static int sp_open (struct gport *port) { } sprintf (escaped_port_name, "\\\\.\\%s", port->name); - filename_ = r_sys_conv_utf8_to_win (escaped_port_name); + filename_ = rz_sys_conv_utf8_to_win (escaped_port_name); port->hdl = CreateFile (filename_, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, @@ -340,7 +340,7 @@ static int sp_open (struct gport *port) { #else struct termios tty = {0}; - if ((port->fd = r_sandbox_open (port->name, O_NONBLOCK | O_NOCTTY | O_RDWR, 0)) < 0) { + if ((port->fd = rz_sandbox_open (port->name, O_NONBLOCK | O_NOCTTY | O_RDWR, 0)) < 0) { return -1; } @@ -659,14 +659,14 @@ static ut8 gprobe_checksum (const ut8 *p, unsigned int size) { static void gprobe_frame_sp(RBuffer *frame) { ut64 size; - const ut8 *tmp = r_buf_data (frame, &size); + const ut8 *tmp = rz_buf_data (frame, &size); size += 2; ut8 checksum; - r_buf_prepend_bytes (frame, (const ut8 *)&size, 1); + rz_buf_prepend_bytes (frame, (const ut8 *)&size, 1); checksum = gprobe_checksum (tmp, size - 1); - r_buf_append_bytes (frame, &checksum, 1); + rz_buf_append_bytes (frame, &checksum, 1); } static int gprobe_get_reply_sp(struct gport *port, ut8 cmd, RBuffer *reply) { @@ -698,7 +698,7 @@ static int gprobe_get_reply_sp(struct gport *port, ut8 cmd, RBuffer *reply) { } #endif - r_buf_append_bytes (reply, buf + 2, count - 3); + rz_buf_append_bytes (reply, buf + 2, count - 3); return 0; } @@ -707,7 +707,7 @@ static int gprobe_send_request_sp(struct gport *port, RBuffer *request) { sp_flush (port); ut64 tmpsz; - const ut8 *tmp = r_buf_data (request, &tmpsz); + const ut8 *tmp = rz_buf_data (request, &tmpsz); if (sp_blocking_write (port, tmp, tmpsz, 100) != tmpsz) { return -1; } @@ -716,27 +716,27 @@ static int gprobe_send_request_sp(struct gport *port, RBuffer *request) { } static int gprobe_read(struct gport *port, ut32 addr, ut8 *buf, ut32 count) { - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_RAM_READ_2; ut8 addr_be[4]; ut8 count_be[4]; int res; if (!request || !reply) { - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } count = R_MIN (port->max_rx_size, count); - r_write_be32 (addr_be, addr); - r_write_be32 (count_be, count); + rz_write_be32 (addr_be, addr); + rz_write_be32 (count_be, count); - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, addr_be, 4); - r_buf_append_bytes (request, count_be, 4); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, addr_be, 4); + rz_buf_append_bytes (request, count_be, 4); port->frame (request); @@ -748,40 +748,40 @@ static int gprobe_read(struct gport *port, ut32 addr, ut8 *buf, ut32 count) { goto fail; } - res = r_buf_read_at (reply, 0, buf, r_buf_size (reply)); + res = rz_buf_read_at (reply, 0, buf, rz_buf_size (reply)); - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return res; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } static int gprobe_write (struct gport *port, ut32 addr, const ut8 *buf, ut32 count) { - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_RAM_WRITE_2; ut8 addr_be[4]; ut8 count_be[4]; if (!request || !reply) { - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } count = R_MIN (port->max_tx_size, count); - r_write_be32 (addr_be, addr); - r_write_be32 (count_be, count); + rz_write_be32 (addr_be, addr); + rz_write_be32 (count_be, count); - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, addr_be, 4); - r_buf_append_bytes (request, buf, count); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, addr_be, 4); + rz_buf_append_bytes (request, buf, count); port->frame (request); @@ -793,14 +793,14 @@ static int gprobe_write (struct gport *port, ut32 addr, const ut8 *buf, ut32 cou goto fail; } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return count; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } @@ -808,16 +808,16 @@ static int gprobe_reset (struct gport *port, ut8 code) { if (!port) { return -1; } - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_RESET; if (!request || !reply) { goto fail; } - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, &code, 1); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, &code, 1); port->frame (request); @@ -831,14 +831,14 @@ static int gprobe_reset (struct gport *port, ut8 code) { goto fail; } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } @@ -846,14 +846,14 @@ static int gprobe_debugon (struct gport *port) { if (!port) { return -1; } - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_DEBUGON; if (!request || !reply) { goto fail; } - r_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, &cmd, 1); port->frame (request); @@ -865,26 +865,26 @@ static int gprobe_debugon (struct gport *port) { goto fail; } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } static int gprobe_debugoff (struct gport *port) { - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_DEBUGOFF; if (!request || !reply) { goto fail; } - r_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, &cmd, 1); port->frame (request); if (port->send_request (port, request)) { goto fail; @@ -892,12 +892,12 @@ static int gprobe_debugoff (struct gport *port) { if (port->get_reply (port, GPROBE_ACK, reply)) { goto fail; } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } @@ -905,8 +905,8 @@ static int gprobe_runcode (struct gport *port, ut32 addr) { if (!port) { return -1; } - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_RUN_CODE_2; ut8 addr_be[4]; @@ -914,10 +914,10 @@ static int gprobe_runcode (struct gport *port, ut32 addr) { goto fail; } - r_write_be32 (addr_be, addr); + rz_write_be32 (addr_be, addr); - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, addr_be, 4); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, addr_be, 4); port->frame (request); @@ -929,14 +929,14 @@ static int gprobe_runcode (struct gport *port, ut32 addr) { goto fail; } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } @@ -944,16 +944,16 @@ static int gprobe_getdeviceid (struct gport *port, ut8 index) { if (!port) { return -1; } - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_GET_DEVICE_ID; if (!request || !reply) { goto fail; } - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, &index, 1); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, &index, 1); port->frame (request); @@ -965,20 +965,20 @@ static int gprobe_getdeviceid (struct gport *port, ut8 index) { goto fail; } - char *s = r_buf_to_string (reply); + char *s = rz_buf_to_string (reply); if (s) { printf ("%s\n", s); free (s); } - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } @@ -986,8 +986,8 @@ static int gprobe_getinformation (struct gport *port) { if (!port) { return -1; } - RBuffer *request = r_buf_new (); - RBuffer *reply = r_buf_new (); + RBuffer *request = rz_buf_new (); + RBuffer *reply = rz_buf_new (); const ut8 cmd = GPROBE_GET_INFORMATION; const ut8 index = 0; @@ -995,8 +995,8 @@ static int gprobe_getinformation (struct gport *port) { goto fail; } - r_buf_append_bytes (request, &cmd, 1); - r_buf_append_bytes (request, &index, 1); + rz_buf_append_bytes (request, &cmd, 1); + rz_buf_append_bytes (request, &index, 1); port->frame (request); @@ -1009,22 +1009,22 @@ static int gprobe_getinformation (struct gport *port) { } ut64 tmpsz; - const ut8 *tmp = r_buf_data (reply, &tmpsz); - r_print_hexdump (NULL, 0, tmp, tmpsz, 16, 1, 1); + const ut8 *tmp = rz_buf_data (reply, &tmpsz); + rz_print_hexdump (NULL, 0, tmp, tmpsz, 16, 1, 1); - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return 0; fail: - r_buf_free (request); - r_buf_free (reply); + rz_buf_free (request); + rz_buf_free (reply); return -1; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - RIOGprobe *gprobe; +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + RzIOGprobe *gprobe; int res; int has_written = 0; @@ -1032,7 +1032,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return -1; } - gprobe = (RIOGprobe *)fd->data; + gprobe = (RzIOGprobe *)fd->data; if ((gprobe->offset + count) > GPROBE_SIZE) { count = GPROBE_SIZE - gprobe->offset; @@ -1050,16 +1050,16 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return count; } -static int __read (RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count) { int res; - RIOGprobe *gprobe; + RzIOGprobe *gprobe; int has_read = 0; if (!fd || !fd->data || !buf) { return -1; } - gprobe = (RIOGprobe *)fd->data; + gprobe = (RzIOGprobe *)fd->data; if ((gprobe->offset + count) > GPROBE_SIZE) { count = GPROBE_SIZE - gprobe->offset; @@ -1077,13 +1077,13 @@ static int __read (RIO *io, RIODesc *fd, ut8 *buf, int count) { return has_read; } -static int __close (RIODesc *fd) { - RIOGprobe *gprobe; +static int __close (RzIODesc *fd) { + RzIOGprobe *gprobe; if (!fd || !fd->data) { return -1; } - gprobe = (RIOGprobe *)fd->data; + gprobe = (RzIOGprobe *)fd->data; sp_close (&gprobe->gport); R_FREE (fd->data); @@ -1091,12 +1091,12 @@ static int __close (RIODesc *fd) { return 0; } -static ut64 __lseek (RIO *io, RIODesc *fd, ut64 offset, int whence) { - RIOGprobe *gprobe; +static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + RzIOGprobe *gprobe; if (!fd || !fd->data) { return offset; } - gprobe = (RIOGprobe *)fd->data; + gprobe = (RzIOGprobe *)fd->data; switch (whence) { case SEEK_SET: if (offset >= GPROBE_SIZE) { @@ -1114,18 +1114,18 @@ static ut64 __lseek (RIO *io, RIODesc *fd, ut64 offset, int whence) { return offset; } -static bool __plugin_open (RIO *io, const char *pathname, bool many) { - return pathname && r_str_startswith (pathname, "gprobe://") && strlen (pathname + strlen ("gprobe://")); +static bool __plugin_open (RzIO *io, const char *pathname, bool many) { + return pathname && rz_str_startswith (pathname, "gprobe://") && strlen (pathname + strlen ("gprobe://")); } -static RIODesc *__open (RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open (RzIO *io, const char *pathname, int rw, int mode) { if (__plugin_open (io, pathname, 0)) { - RIOGprobe *gprobe = R_NEW0 (RIOGprobe); + RzIOGprobe *gprobe = R_NEW0 (RzIOGprobe); gprobe->offset = 0LL; gprobe->gport.name = pathname + strlen ("gprobe://"); - if (r_str_startswith (gprobe->gport.name, "i2c-")) { + if (rz_str_startswith (gprobe->gport.name, "i2c-")) { #if __UNIX__ gprobe->gport.send_request = gprobe_send_request_i2c; gprobe->gport.get_reply = gprobe_get_reply_i2c; @@ -1154,19 +1154,19 @@ static RIODesc *__open (RIO *io, const char *pathname, int rw, int mode) { } } - return r_io_desc_new (io, &r_io_plugin_gprobe, pathname, rw, mode, gprobe); + return rz_io_desc_new (io, &rz_io_plugin_gprobe, pathname, rw, mode, gprobe); } return NULL; } -static char *__system (RIO *io, RIODesc *fd, const char *cmd) { - RIOGprobe *gprobe; +static char *__system (RzIO *io, RzIODesc *fd, const char *cmd) { + RzIOGprobe *gprobe; if (!fd || !fd->data) { return NULL; } - gprobe = (RIOGprobe *)fd->data; + gprobe = (RzIOGprobe *)fd->data; if (!cmd[0] || cmd[0] == '?' || !strcmp (cmd, "help")) { printf ("Usage: =!cmd args\n" @@ -1179,7 +1179,7 @@ static char *__system (RIO *io, RIODesc *fd, const char *cmd) { return NULL; } - if (r_str_startswith (cmd, "reset") && (strlen (cmd) > 6)) { + if (rz_str_startswith (cmd, "reset") && (strlen (cmd) > 6)) { ut32 code = (ut32)strtoul (cmd + 6, NULL, 10); gprobe_reset (&gprobe->gport, code); @@ -1187,19 +1187,19 @@ static char *__system (RIO *io, RIODesc *fd, const char *cmd) { return NULL; } - if (r_str_startswith (cmd, "debugon")) { + if (rz_str_startswith (cmd, "debugon")) { gprobe_debugon (&gprobe->gport); return NULL; } - if (r_str_startswith (cmd, "debugoff")) { + if (rz_str_startswith (cmd, "debugoff")) { gprobe_debugoff (&gprobe->gport); return NULL; } - if (r_str_startswith (cmd, "runcode") && (strlen (cmd) > 8)) { + if (rz_str_startswith (cmd, "runcode") && (strlen (cmd) > 8)) { ut32 address = (ut32)strtoul (cmd + 8, NULL, 0); gprobe_runcode (&gprobe->gport, address); @@ -1207,7 +1207,7 @@ static char *__system (RIO *io, RIODesc *fd, const char *cmd) { return NULL; } - if (r_str_startswith (cmd, "getdeviceid")) { + if (rz_str_startswith (cmd, "getdeviceid")) { ut8 index = 0; while (!gprobe_getdeviceid (&gprobe->gport, index++)) { @@ -1216,7 +1216,7 @@ static char *__system (RIO *io, RIODesc *fd, const char *cmd) { return NULL; } - if (r_str_startswith (cmd, "getinformation")) { + if (rz_str_startswith (cmd, "getinformation")) { gprobe_getinformation (&gprobe->gport); return NULL; @@ -1227,7 +1227,7 @@ static char *__system (RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_gprobe = { +RzIOPlugin rz_io_plugin_gprobe = { .name = "gprobe", .desc = "Open gprobe connection", .license = "LGPL3", @@ -1242,8 +1242,8 @@ RIOPlugin r_io_plugin_gprobe = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_gprobe, + .data = &rz_io_plugin_gprobe, .version = R2_VERSION}; #endif diff --git a/libr/io/p/io_gprobe.h b/librz/io/p/io_gprobe.h similarity index 100% rename from libr/io/p/io_gprobe.h rename to librz/io/p/io_gprobe.h diff --git a/libr/io/p/io_gzip.c b/librz/io/p/io_gzip.c similarity index 61% rename from libr/io/p/io_gzip.c rename to librz/io/p/io_gzip.c index 513629650d..37bf475938 100644 --- a/libr/io/p/io_gzip.c +++ b/librz/io/p/io_gzip.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2017 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include @@ -10,60 +10,60 @@ typedef struct { ut8 *buf; ut32 size; ut64 offset; -} RIOGzip; +} RzIOGzip; -static inline ut32 _io_malloc_sz(RIODesc *desc) { +static inline ut32 _io_malloc_sz(RzIODesc *desc) { if (!desc) { return 0; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; return mal? mal->size: 0; } -static inline void _io_malloc_set_sz(RIODesc *desc, ut32 sz) { +static inline void _io_malloc_set_sz(RzIODesc *desc, ut32 sz) { if (!desc) { return; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; if (mal) { mal->size = sz; } } -static inline ut8* _io_malloc_buf(RIODesc *desc) { +static inline ut8* _io_malloc_buf(RzIODesc *desc) { if (!desc) { return NULL; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; return mal->buf; } -static inline ut8* _io_malloc_set_buf(RIODesc *desc, ut8* buf) { +static inline ut8* _io_malloc_set_buf(RzIODesc *desc, ut8* buf) { if (!desc) { return NULL; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; return mal->buf = buf; } -static inline ut64 _io_malloc_off(RIODesc *desc) { +static inline ut64 _io_malloc_off(RzIODesc *desc) { if (!desc) { return 0; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; return mal->offset; } -static inline void _io_malloc_set_off(RIODesc *desc, ut64 off) { +static inline void _io_malloc_set_off(RzIODesc *desc, ut64 off) { if (!desc) { return; } - RIOGzip *mal = (RIOGzip*)desc->data; + RzIOGzip *mal = (RzIOGzip*)desc->data; mal->offset = off; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !buf || count < 0 || !fd->data) { return -1; } @@ -81,7 +81,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return -1; } -static bool __resize(RIO *io, RIODesc *fd, ut64 count) { +static bool __resize(RzIO *io, RzIODesc *fd, ut64 count) { ut8 * new_buf = NULL; if (!fd || !fd->data || count == 0) { return false; @@ -104,7 +104,7 @@ static bool __resize(RIO *io, RIODesc *fd, ut64 count) { return true; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); if (!fd || !fd->data) { return -1; @@ -120,8 +120,8 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return count; } -static int __close(RIODesc *fd) { - RIOGzip *riom; +static int __close(RzIODesc *fd) { + RzIOGzip *riom; if (!fd || !fd->data) { return -1; } @@ -132,43 +132,43 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) { - ut64 r_offset = offset; +static ut64 __lseek(RzIO* io, RzIODesc *fd, ut64 offset, int whence) { + ut64 rz_offset = offset; if (!fd || !fd->data) { return offset; } ut32 mallocsz = _io_malloc_sz (fd); switch (whence) { case SEEK_SET: - r_offset = (offset <= mallocsz) ? offset : mallocsz; + rz_offset = (offset <= mallocsz) ? offset : mallocsz; break; case SEEK_CUR: - r_offset = (_io_malloc_off (fd) + offset <= mallocsz ) ? _io_malloc_off (fd) + offset : mallocsz; + rz_offset = (_io_malloc_off (fd) + offset <= mallocsz ) ? _io_malloc_off (fd) + offset : mallocsz; break; case SEEK_END: - r_offset = _io_malloc_sz (fd); + rz_offset = _io_malloc_sz (fd); break; } - _io_malloc_set_off (fd, r_offset); - return r_offset; + _io_malloc_set_off (fd, rz_offset); + return rz_offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "gzip://", 7)); } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { if (__plugin_open (io, pathname, 0)) { - RIOGzip *mal = R_NEW0 (RIOGzip); + RzIOGzip *mal = R_NEW0 (RzIOGzip); if (!mal) { return NULL; } size_t len; - ut8 *data = (ut8 *)r_file_slurp (pathname+7, &len); //memleak here? + ut8 *data = (ut8 *)rz_file_slurp (pathname+7, &len); //memleak here? int *size = (int*)&mal->size; - mal->buf = r_inflate (data, (int)len, NULL, size); + mal->buf = rz_inflate (data, (int)len, NULL, size); if (mal->buf) { - return r_io_desc_new (io, &r_io_plugin_gzip, pathname, rw, mode, mal); + return rz_io_desc_new (io, &rz_io_plugin_gzip, pathname, rw, mode, mal); } free (data); eprintf ("Cannot allocate (%s) %d byte(s)\n", pathname+9, mal->size); @@ -177,7 +177,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_gzip = { +RzIOPlugin rz_io_plugin_gzip = { .name = "gzip", .desc = "Read/write gzipped files", .license = "LGPL3", @@ -192,9 +192,9 @@ RIOPlugin r_io_plugin_gzip = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_gzip, + .data = &rz_io_plugin_gzip, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_http.c b/librz/io/p/io_http.c similarity index 57% rename from libr/io/p/io_http.c rename to librz/io/p/io_http.c index 9b1c5ce301..2958871636 100644 --- a/libr/io/p/io_http.c +++ b/librz/io/p/io_http.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2020 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include @@ -10,41 +10,41 @@ typedef struct { int fd; ut8 *buf; ut32 size; -} RIOMalloc; +} RzIOMalloc; -#define RIOHTTP_FD(x) (((RIOMalloc*)(x)->data)->fd) -#define RIOHTTP_SZ(x) (((RIOMalloc*)(x)->data)->size) -#define RIOHTTP_BUF(x) (((RIOMalloc*)(x)->data)->buf) +#define RzIOHTTP_FD(x) (((RzIOMalloc*)(x)->data)->fd) +#define RzIOHTTP_SZ(x) (((RzIOMalloc*)(x)->data)->size) +#define RzIOHTTP_BUF(x) (((RzIOMalloc*)(x)->data)->buf) -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !fd->data) { return -1; } - if (io->off + count > RIOHTTP_SZ (fd)) { + if (io->off + count > RzIOHTTP_SZ (fd)) { return -1; } - memcpy (RIOHTTP_BUF (fd)+io->off, buf, count); + memcpy (RzIOHTTP_BUF (fd)+io->off, buf, count); return count; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { unsigned int sz; if (!fd || !fd->data) { return -1; } - sz = RIOHTTP_SZ (fd); + sz = RzIOHTTP_SZ (fd); if (io->off >= sz) { return -1; } if (io->off + count >= sz) { count = sz - io->off; } - memcpy (buf, RIOHTTP_BUF (fd) + io->off, count); + memcpy (buf, RzIOHTTP_BUF (fd) + io->off, count); return count; } -static int __close(RIODesc *fd) { - RIOMalloc *riom; +static int __close(RzIODesc *fd) { + RzIOMalloc *riom; if (!fd || !fd->data) { return -1; } @@ -54,30 +54,30 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; - case SEEK_END: return RIOHTTP_SZ (fd); + case SEEK_END: return RzIOHTTP_SZ (fd); } return offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "http://", 7)); } -static inline int getmalfd (RIOMalloc *mal) { +static inline int getmalfd (RzIOMalloc *mal) { return (UT32_MAX >> 1) & (int)(size_t)mal->buf; } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { char *out; int rlen, code; if (__plugin_open (io, pathname, 0)) { - out = r_socket_http_get (pathname, &code, &rlen); + out = rz_socket_http_get (pathname, &code, &rlen); if (out) { - RIOMalloc *mal = R_NEW0 (RIOMalloc); + RzIOMalloc *mal = R_NEW0 (RzIOMalloc); if (!mal) { return NULL; } @@ -91,7 +91,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { mal->fd = getmalfd (mal); memcpy (mal->buf, out, mal->size); free (out); - return r_io_desc_new (io, &r_io_plugin_http, + return rz_io_desc_new (io, &rz_io_plugin_http, pathname, rw, mode, mal); } eprintf ("Cannot allocate (%s) %d byte(s)\n", pathname+9, mal->size); @@ -102,7 +102,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_http = { +RzIOPlugin rz_io_plugin_http = { .name = "http", .desc = "Make http get requests", .uris = "http://", @@ -116,9 +116,9 @@ RIOPlugin r_io_plugin_http = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_http, + .data = &rz_io_plugin_http, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_ihex.c b/librz/io/p/io_ihex.c similarity index 85% rename from libr/io/p/io_ihex.c rename to librz/io/p/io_ihex.c index 3840fd2a9e..81205517b2 100644 --- a/libr/io/p/io_ihex.c +++ b/librz/io/p/io_ihex.c @@ -25,9 +25,9 @@ KK = 0 - (sum of all bytes) */ -#include "r_io.h" -#include "r_lib.h" -#include "r_util.h" +#include "rz_io.h" +#include "rz_lib.h" +#include "rz_util.h" #include //for INT_MAX #include #include @@ -42,35 +42,35 @@ typedef struct { static int fw04b(FILE *fd, ut16 eaddr); static int fwblock(FILE *fd, ut8 *b, ut32 start_addr, ut16 size); -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { const char *pathname; FILE *out; Rihex *rih; RBufferSparse *rbs; - RListIter *iter; + RzListIter *iter; if (!fd || !fd->data || (fd->perm & R_PERM_W) == 0 || count <= 0) { return -1; } rih = fd->data; pathname = fd->name + 7; - out = r_sandbox_fopen (pathname, "w"); + out = rz_sandbox_fopen (pathname, "w"); if (!out) { eprintf ("Cannot open '%s' for writing\n", pathname); return -1; } /* mem write */ - if (r_buf_write_at (rih->rbuf, io->off, buf, count) != count) { + if (rz_buf_write_at (rih->rbuf, io->off, buf, count) != count) { eprintf ("ihex:write(): sparse write failed\n"); fclose (out); return -1; } - r_buf_seek (rih->rbuf, count, R_BUF_CUR); + rz_buf_seek (rih->rbuf, count, R_BUF_CUR); /* disk write : process each sparse chunk */ //TODO : sort addresses + check overlap? - RList *nonempty = r_buf_nonempty_list (rih->rbuf); - r_list_foreach (nonempty, iter, rbs) { + RzList *nonempty = rz_buf_nonempty_list (rih->rbuf); + rz_list_foreach (nonempty, iter, rbs) { ut16 addl0 = rbs->from & 0xffff; ut16 addh0 = rbs->from >> 16; ut16 addh1 = rbs->to >> 16; @@ -84,7 +84,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { //04 record (ext address) if (fw04b (out, addh0) < 0) { eprintf("ihex:write: file error\n"); - r_list_free (nonempty); + rz_list_free (nonempty); fclose (out); return -1; } @@ -93,7 +93,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { addl0 = 0; if (fwblock (out, rbs->data, rbs->from, tsiz)) { eprintf ("ihex:fwblock error\n"); - r_list_free (nonempty); + rz_list_free (nonempty); fclose (out); return -1; } @@ -101,20 +101,20 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { //04 record (ext address) if (fw04b (out, addh1) < 0) { eprintf ("ihex:write: file error\n"); - r_list_free (nonempty); + rz_list_free (nonempty); fclose (out); return -1; } //00 records (remaining data) if (fwblock (out, rbs->data + tsiz, (addh1 << 16) | addl0, rbs->size - tsiz)) { eprintf ("ihex:fwblock error\n"); - r_list_free (nonempty); + rz_list_free (nonempty); fclose (out); return -1; } } //list_foreach - r_list_free (nonempty); + rz_list_free (nonempty); fprintf (out, ":00000001FF\n"); fclose (out); out = NULL; @@ -184,41 +184,41 @@ static int fw04b(FILE *fd, ut16 eaddr) { } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { if (!fd || !fd->data || (count <= 0)) { return -1; } Rihex *rih = fd->data; memset (buf, io->Oxff, count); - int r = r_buf_read_at (rih->rbuf, io->off, buf, count); + int r = rz_buf_read_at (rih->rbuf, io->off, buf, count); if (r >= 0) { - r_buf_seek (rih->rbuf, r, R_BUF_CUR); + rz_buf_seek (rih->rbuf, r, R_BUF_CUR); } return r; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { if (!fd || !fd->data) { return -1; } Rihex *rih = fd->data; - r_buf_free (rih->rbuf); + rz_buf_free (rih->rbuf); free (rih); fd->data = NULL; return 0; } -static ut64 __lseek(struct r_io_t *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(struct rz_io_t *io, RzIODesc *fd, ut64 offset, int whence) { Rihex *rih; if (!fd || !fd->data) { return -1; } rih = fd->data; - io->off = r_buf_seek (rih->rbuf, offset, whence); + io->off = rz_buf_seek (rih->rbuf, offset, whence); return io->off; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "ihex://", 7)); } @@ -235,7 +235,7 @@ static bool ihex_parse(RBuffer *rbuf, char *str) { ut8 cksum; int extH, extL; int bc = 0, type, byte, i, l; - //fugly macro to prevent an overflow of r_buf_write_at() len + //fugly macro to prevent an overflow of rz_buf_write_at() len #define SEC_MAX (sec_size < INT_MAX)? sec_size: INT_MAX ut32 sec_size = 0; const int sec_count = UT16_MAX; @@ -268,7 +268,7 @@ static bool ihex_parse(RBuffer *rbuf, char *str) { //previous block is not contiguous, or //section buffer is full => write a sparse chunk if (sec_size && sec_size < UT16_MAX) { - if (r_buf_write_at (rbuf, sec_start, sec_tmp, (int) sec_size) != sec_size) { + if (rz_buf_write_at (rbuf, sec_start, sec_tmp, (int) sec_size) != sec_size) { eprintf ("sparse buffer problem, giving up\n"); goto fail; } @@ -310,7 +310,7 @@ static bool ihex_parse(RBuffer *rbuf, char *str) { break; case 1: // EOF. we don't validate checksum here if (sec_size) { - if (r_buf_write_at(rbuf, sec_start, sec_tmp, sec_size) != sec_size) { + if (rz_buf_write_at(rbuf, sec_start, sec_tmp, sec_size) != sec_size) { eprintf ("sparse buffer problem, giving up. ssiz=%X, sstart=%X\n", sec_size, sec_start); goto fail; } @@ -323,7 +323,7 @@ static bool ihex_parse(RBuffer *rbuf, char *str) { // new address = seg_reg <<4 for type 02; new address = lin_addr <<16 for type 04. //write current section if (sec_size) { - if (r_buf_write_at(rbuf, sec_start, sec_tmp, sec_size) != sec_size) { + if (rz_buf_write_at(rbuf, sec_start, sec_tmp, sec_size) != sec_size) { eprintf("sparse buffer problem, giving up\n"); goto fail; } @@ -388,11 +388,11 @@ fail: return false; } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { Rihex *mal = NULL; char *str = NULL; if (__plugin_open (io, pathname, 0)) { - str = r_file_slurp (pathname + 7, NULL); + str = rz_file_slurp (pathname + 7, NULL); if (!str) { return NULL; } @@ -401,7 +401,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { free (str); return NULL; } - mal->rbuf = r_buf_new_sparse (io->Oxff); + mal->rbuf = rz_buf_new_sparse (io->Oxff); if (!mal->rbuf) { free (str); free (mal); @@ -410,29 +410,29 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { if (!ihex_parse (mal->rbuf, str)) { eprintf ("ihex: failed to parse file\n"); free (str); - r_buf_free (mal->rbuf); + rz_buf_free (mal->rbuf); free (mal); return NULL; } free (str); - return r_io_desc_new (io, &r_io_plugin_ihex, + return rz_io_desc_new (io, &rz_io_plugin_ihex, pathname, rw, mode, mal); } return NULL; } -static bool __resize(RIO *io, RIODesc *fd, ut64 size) { +static bool __resize(RzIO *io, RzIODesc *fd, ut64 size) { if (!fd) { return false; } Rihex *rih = fd->data; if (rih) { - return r_buf_resize (rih->rbuf, size); + return rz_buf_resize (rih->rbuf, size); } return false; } -RIOPlugin r_io_plugin_ihex = { +RzIOPlugin rz_io_plugin_ihex = { .name = "ihex", .desc = "Open intel HEX file", .uris = "ihex://", @@ -447,9 +447,9 @@ RIOPlugin r_io_plugin_ihex = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_ihex, + .data = &rz_io_plugin_ihex, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_mach.c b/librz/io/p/io_mach.c similarity index 84% rename from libr/io/p/io_mach.c rename to librz/io/p/io_mach.c index fb7d74570b..79fcb23ef9 100644 --- a/libr/io/p/io_mach.c +++ b/librz/io/p/io_mach.c @@ -1,14 +1,14 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include +#include -#include -#include -#include +#include +#include +#include #if __APPLE__ && DEBUGGER -static int __get_pid (RIODesc *desc); +static int __get_pid (RzIODesc *desc); #define EXCEPTION_PORT 0 // NOTE: mach/mach_vm is not available for iOS @@ -37,17 +37,17 @@ static int __get_pid (RIODesc *desc); #define MACH_ERROR_STRING(ret) \ (mach_error_string (ret) ? mach_error_string (ret) : "(unknown)") -#define R_MACH_MAGIC r_str_hash ("mach") +#define R_MACH_MAGIC rz_str_hash ("mach") typedef struct { task_t task; -} RIOMach; +} RzIOMach; /* -#define RIOMACH_PID(x) (x ? ((RIOMach*)(x))->pid : -1) -#define RIOMACH_TASK(x) (x ? ((RIOMach*)(x))->task : -1) +#define RzIOMACH_PID(x) (x ? ((RzIOMach*)(x))->pid : -1) +#define RzIOMACH_TASK(x) (x ? ((RzIOMach*)(x))->task : -1) */ -int RIOMACH_TASK(RIODescData *x) { +int RzIOMACH_TASK(RzIODescData *x) { // TODO return -1; } @@ -104,14 +104,14 @@ static task_t task_for_pid_ios9pangu(int pid) { return task; } -static task_t pid_to_task(RIODesc *fd, int pid) { +static task_t pid_to_task(RzIODesc *fd, int pid) { task_t task = 0; static task_t old_task = 0; static int old_pid = -1; kern_return_t kr; - RIODescData *iodd = fd? (RIODescData *)fd->data: NULL; - RIOMach *riom = NULL; + RzIODescData *iodd = fd? (RzIODescData *)fd->data: NULL; + RzIOMach *riom = NULL; if (iodd) { riom = iodd->data; if (riom && riom->task) { @@ -149,7 +149,7 @@ static task_t pid_to_task(RIODesc *fd, int pid) { return task; } -static bool task_is_dead(RIODesc *fd, int pid) { +static bool task_is_dead(RzIODesc *fd, int pid) { unsigned int count = 0; kern_return_t kr = mach_port_get_refs (mach_task_self (), pid_to_task (fd, pid), MACH_PORT_RIGHT_SEND, &count); @@ -158,7 +158,7 @@ static bool task_is_dead(RIODesc *fd, int pid) { static ut64 the_lower = UT64_MAX; -static ut64 getNextValid(RIO *io, RIODesc *fd, ut64 addr) { +static ut64 getNextValid(RzIO *io, RzIODesc *fd, ut64 addr) { struct vm_region_submap_info_64 info; vm_address_t address = MACH_VM_MIN_ADDRESS; vm_size_t size = (vm_size_t) 0; @@ -209,15 +209,15 @@ static ut64 getNextValid(RIO *io, RIODesc *fd, ut64 addr) { return lower; } -static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { +static int __read(RzIO *io, RzIODesc *desc, ut8 *buf, int len) { vm_size_t size = 0; int blen, err, copied = 0; int blocksize = 32; - RIODescData *dd = (RIODescData *)desc->data; + RzIODescData *dd = (RzIODescData *)desc->data; if (!io || !desc || !buf || !dd) { return -1; } - if (dd ->magic != r_str_hash ("mach")) { + if (dd ->magic != rz_str_hash ("mach")) { return -1; } memset (buf, 0xff, len); @@ -243,7 +243,7 @@ static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { (pointer_t)buf + copied, &size); switch (err) { case KERN_PROTECTION_FAILURE: - //eprintf ("r_io_mach_read: kern protection failure.\n"); + //eprintf ("rz_io_mach_read: kern protection failure.\n"); break; case KERN_INVALID_ADDRESS: if (blocksize == 1) { @@ -272,7 +272,7 @@ static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { return len; } -static int tsk_getperm(RIO *io, task_t task, vm_address_t addr) { +static int tsk_getperm(RzIO *io, task_t task, vm_address_t addr) { kern_return_t kr; mach_port_t object; vm_size_t vmsize; @@ -283,7 +283,7 @@ static int tsk_getperm(RIO *io, task_t task, vm_address_t addr) { return (kr != KERN_SUCCESS ? 0 : info.protection); } -static int tsk_pagesize(RIODesc *desc) { +static int tsk_pagesize(RzIODesc *desc) { int tid = __get_pid (desc); task_t task = pid_to_task (desc, tid); static vm_size_t pagesize = 0; @@ -293,12 +293,12 @@ static int tsk_pagesize(RIODesc *desc) { ? pagesize : 4096; } -static vm_address_t tsk_getpagebase(RIODesc *desc, ut64 addr) { +static vm_address_t tsk_getpagebase(RzIODesc *desc, ut64 addr) { vm_address_t pagesize = tsk_pagesize (desc); return (addr & ~(pagesize - 1)); } -static bool tsk_setperm(RIO *io, task_t task, vm_address_t addr, int len, int perm) { +static bool tsk_setperm(RzIO *io, task_t task, vm_address_t addr, int len, int perm) { kern_return_t kr; kr = vm_protect (task, addr, len, 0, perm); if (kr != KERN_SUCCESS) { @@ -316,7 +316,7 @@ static bool tsk_write(task_t task, vm_address_t addr, const ut8 *buf, int len) { return true; } -static int mach_write_at(RIO *io, RIODesc *desc, const void *buf, int len, ut64 addr) { +static int mach_write_at(RzIO *io, RzIODesc *desc, const void *buf, int len, ut64 addr) { vm_address_t vaddr = addr; vm_address_t pageaddr; vm_size_t pagesize; @@ -358,17 +358,17 @@ static int mach_write_at(RIO *io, RIODesc *desc, const void *buf, int len, ut64 return len; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { return mach_write_at (io, fd, buf, len, io->off); } -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return (!strncmp (file, "attach://", 9) || !strncmp (file, "mach://", 7)); } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - RIODesc *ret = NULL; - RIOMach *riom = NULL; +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { + RzIODesc *ret = NULL; + RzIOMach *riom = NULL; const char *pidfile; char *pidpath, *endptr; int pid; @@ -414,36 +414,36 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { } return NULL; } - RIODescData *iodd = R_NEW0 (RIODescData); + RzIODescData *iodd = R_NEW0 (RzIODescData); if (iodd) { iodd->pid = pid; iodd->tid = pid; iodd->data = NULL; } - riom = R_NEW0 (RIOMach); + riom = R_NEW0 (RzIOMach); if (!riom) { R_FREE (iodd); return NULL; } riom->task = task; - iodd->magic = r_str_hash ("mach"); + iodd->magic = rz_str_hash ("mach"); iodd->data = riom; // sleep 1s to get proper path (program name instead of ls) (racy) pidpath = pid - ? r_sys_pid_to_path (pid) + ? rz_sys_pid_to_path (pid) : strdup ("kernel"); if (!strncmp (file, "smach://", 8)) { - ret = r_io_desc_new (io, &r_io_plugin_mach, &file[1], + ret = rz_io_desc_new (io, &rz_io_plugin_mach, &file[1], rw | R_PERM_X, mode, iodd); } else { - ret = r_io_desc_new (io, &r_io_plugin_mach, file, + ret = rz_io_desc_new (io, &rz_io_plugin_mach, file, rw | R_PERM_X, mode, iodd); } ret->name = pidpath; return ret; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: io->off = offset; @@ -457,11 +457,11 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { if (!fd) { return false; } - RIODescData *iodd = fd->data; + RzIODescData *iodd = fd->data; kern_return_t kr; if (!iodd) { return false; @@ -478,11 +478,11 @@ static int __close(RIODesc *fd) { return kr == KERN_SUCCESS; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { if (!io || !fd || !cmd || !fd->data) { return NULL; } - RIODescData *iodd = fd->data; + RzIODescData *iodd = fd->data; if (iodd->magic != R_MACH_MAGIC) { return NULL; } @@ -493,7 +493,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } if (!strncmp (cmd, "perm", 4)) { - int perm = r_str_rwx (cmd + 4); + int perm = rz_str_rwx (cmd + 4); if (perm) { int pagesize = tsk_pagesize (fd); tsk_setperm (io, task, io->off, pagesize, perm); @@ -503,8 +503,8 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } if (!strncmp (cmd, "pid", 3)) { - RIODescData *iodd = fd->data; - RIOMach *riom = iodd->data; + RzIODescData *iodd = fd->data; + RzIOMach *riom = iodd->data; const char *pidstr = cmd + 3; int pid = -1; if (*pidstr) { @@ -538,12 +538,12 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -static int __get_pid (RIODesc *desc) { - // dupe for ? r_io_desc_get_pid (desc); +static int __get_pid (RzIODesc *desc) { + // dupe for ? rz_io_desc_get_pid (desc); if (!desc || !desc->data) { return -1; } - RIODescData *iodd = desc->data; + RzIODescData *iodd = desc->data; if (iodd) { if (iodd->magic != R_MACH_MAGIC) { return -1; @@ -554,7 +554,7 @@ static int __get_pid (RIODesc *desc) { } // TODO: rename ptrace to io_mach .. err io.ptrace ?? -RIOPlugin r_io_plugin_mach = { +RzIOPlugin rz_io_plugin_mach = { .name = "mach", .desc = "Attach to mach debugger instance", .license = "LGPL", @@ -572,7 +572,7 @@ RIOPlugin r_io_plugin_mach = { }; #else -RIOPlugin r_io_plugin_mach = { +RzIOPlugin rz_io_plugin_mach = { .name = "mach", .desc = "mach debug io (unsupported in this platform)", .license = "LGPL" @@ -580,9 +580,9 @@ RIOPlugin r_io_plugin_mach = { #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_mach, + .data = &rz_io_plugin_mach, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_malloc.c b/librz/io/p/io_malloc.c similarity index 64% rename from libr/io/p/io_malloc.c rename to librz/io/p/io_malloc.c index ee6deb5977..f50886e4ff 100644 --- a/libr/io/p/io_malloc.c +++ b/librz/io/p/io_malloc.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2017 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include @@ -10,60 +10,60 @@ typedef struct { ut8 *buf; ut32 size; ut64 offset; -} RIOMalloc; +} RzIOMalloc; -static inline ut32 _io_malloc_sz(RIODesc *desc) { +static inline ut32 _io_malloc_sz(RzIODesc *desc) { if (!desc) { return 0; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; return mal? mal->size: 0; } -static inline void _io_malloc_set_sz(RIODesc *desc, ut32 sz) { +static inline void _io_malloc_set_sz(RzIODesc *desc, ut32 sz) { if (!desc) { return; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; if (mal) { mal->size = sz; } } -static inline ut8* _io_malloc_buf(RIODesc *desc) { +static inline ut8* _io_malloc_buf(RzIODesc *desc) { if (!desc) { return NULL; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; return mal->buf; } -static inline ut8* _io_malloc_set_buf(RIODesc *desc, ut8* buf) { +static inline ut8* _io_malloc_set_buf(RzIODesc *desc, ut8* buf) { if (!desc) { return NULL; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; return mal->buf = buf; } -static inline ut64 _io_malloc_off(RIODesc *desc) { +static inline ut64 _io_malloc_off(RzIODesc *desc) { if (!desc) { return 0; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; return mal->offset; } -static inline void _io_malloc_set_off(RIODesc *desc, ut64 off) { +static inline void _io_malloc_set_off(RzIODesc *desc, ut64 off) { if (!desc) { return; } - RIOMalloc *mal = (RIOMalloc*)desc->data; + RzIOMalloc *mal = (RzIOMalloc*)desc->data; mal->offset = off; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !buf || count < 0 || !fd->data) { return -1; } @@ -81,7 +81,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return -1; } -static bool __resize(RIO *io, RIODesc *fd, ut64 count) { +static bool __resize(RzIO *io, RzIODesc *fd, ut64 count) { ut8 * new_buf = NULL; if (!fd || !fd->data || count == 0) { return false; @@ -104,7 +104,7 @@ static bool __resize(RIO *io, RIODesc *fd, ut64 count) { return true; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); if (!fd || !fd->data) { return -1; @@ -121,8 +121,8 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return count; } -static int __close(RIODesc *fd) { - RIOMalloc *riom; +static int __close(RzIODesc *fd) { + RzIOMalloc *riom; if (!fd || !fd->data) { return -1; } @@ -132,34 +132,34 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) { - ut64 r_offset = offset; +static ut64 __lseek(RzIO* io, RzIODesc *fd, ut64 offset, int whence) { + ut64 rz_offset = offset; if (!fd || !fd->data) { return offset; } ut32 mallocsz = _io_malloc_sz (fd); switch (whence) { case SEEK_SET: - r_offset = (offset <= mallocsz) ? offset : mallocsz; + rz_offset = (offset <= mallocsz) ? offset : mallocsz; break; case SEEK_CUR: - r_offset = (_io_malloc_off (fd) + offset <= mallocsz ) ? _io_malloc_off (fd) + offset : mallocsz; + rz_offset = (_io_malloc_off (fd) + offset <= mallocsz ) ? _io_malloc_off (fd) + offset : mallocsz; break; case SEEK_END: - r_offset = _io_malloc_sz (fd); + rz_offset = _io_malloc_sz (fd); break; } - _io_malloc_set_off (fd, r_offset); - return r_offset; + _io_malloc_set_off (fd, rz_offset); + return rz_offset; } -static bool __check(RIO *io, const char *pathname, bool many) { +static bool __check(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "malloc://", 9)) || (!strncmp (pathname, "hex://", 6)); } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { if (__check (io, pathname, 0)) { - RIOMalloc *mal = R_NEW0 (RIOMalloc); + RzIOMalloc *mal = R_NEW0 (RzIOMalloc); if (!strncmp (pathname, "hex://", 6)) { mal->size = strlen (pathname); mal->buf = calloc (1, mal->size + 1); @@ -168,12 +168,12 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } mal->offset = 0; - mal->size = r_hex_str2bin (pathname + 6, mal->buf); + mal->size = rz_hex_str2bin (pathname + 6, mal->buf); if ((int)mal->size < 1) { R_FREE (mal->buf); } } else { - mal->size = r_num_math (NULL, pathname + 9); + mal->size = rz_num_math (NULL, pathname + 9); if (((int)mal->size) <= 0) { free (mal); eprintf ("Cannot allocate (%s) 0 bytes\n", pathname + 9); @@ -183,7 +183,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { mal->buf = calloc (1, mal->size + 1); } if (mal->buf) { - return r_io_desc_new (io, &r_io_plugin_malloc, pathname, R_PERM_RW | rw, mode, mal); + return rz_io_desc_new (io, &rz_io_plugin_malloc, pathname, R_PERM_RW | rw, mode, mal); } eprintf ("Cannot allocate (%s) %d byte(s)\n", pathname + 9, mal->size); free (mal); @@ -191,7 +191,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_malloc = { +RzIOPlugin rz_io_plugin_malloc = { .name = "malloc", .desc = "Memory allocation plugin", .uris = "malloc://,hex://", @@ -206,9 +206,9 @@ RIOPlugin r_io_plugin_malloc = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_malloc, + .data = &rz_io_plugin_malloc, .version = R2_VERSION }; #endif diff --git a/librz/io/p/io_mmap.c b/librz/io/p/io_mmap.c new file mode 100644 index 0000000000..e6d777139f --- /dev/null +++ b/librz/io/p/io_mmap.c @@ -0,0 +1,216 @@ +/* radare - LGPL - Copyright 2013-2016 - pancake */ + +#include +#include +#include + +typedef struct rz_io_mmo_t { + char * filename; + int mode; + int flags; + int fd; + int opened; + ut8 modified; + RBuffer *buf; + RzIO * io_backref; +} RzIOMMapFileObj; + +static ut64 rz_io_mmap_seek(RzIO *io, RzIOMMapFileObj *mmo, ut64 offset, int whence) { + ut64 seek_val = rz_buf_tell (mmo->buf); + switch (whence) { + case SEEK_SET: + seek_val = (rz_buf_size (mmo->buf) < offset)? rz_buf_size (mmo->buf): offset; + rz_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); + return seek_val; + case SEEK_CUR: + seek_val = (rz_buf_size (mmo->buf) < (offset + rz_buf_tell (mmo->buf)))? rz_buf_size (mmo->buf): offset + rz_buf_tell (mmo->buf); + rz_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); + return seek_val; + case SEEK_END: + seek_val = rz_buf_size (mmo->buf); + rz_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET); + return seek_val; + } + return seek_val; +} + +static bool rz_io_mmap_refresh_buf(RzIOMMapFileObj *mmo) { + RzIO* io = mmo->io_backref; + ut64 cur = mmo->buf? rz_buf_tell (mmo->buf): 0; + if (mmo->buf) { + rz_buf_free (mmo->buf); + mmo->buf = NULL; + } + mmo->buf = rz_buf_new_mmap (mmo->filename, mmo->flags); + if (mmo->buf) { + rz_io_mmap_seek (io, mmo, cur, SEEK_SET); + } + return mmo->buf != NULL; +} + +static void rz_io_mmap_free(RzIOMMapFileObj *mmo) { + free (mmo->filename); + rz_buf_free (mmo->buf); + memset (mmo, 0, sizeof (RzIOMMapFileObj)); + free (mmo); +} + +RzIOMMapFileObj *rz_io_mmap_create_new_file(RzIO *io, const char *filename, int mode, int flags) { + RzIOMMapFileObj *mmo; + if (!io) { + return NULL; + } + mmo = R_NEW0 (RzIOMMapFileObj); + if (!mmo) { + return NULL; + } + mmo->filename = strdup (filename); + mmo->fd = rz_num_rand (0xFFFF); // XXX: Use rz_io_fd api + mmo->mode = mode; + mmo->flags = flags; + mmo->io_backref = io; + if (!rz_io_mmap_refresh_buf (mmo)) { + rz_io_mmap_free (mmo); + mmo = NULL; + } + return mmo; +} + +static int rz_io_mmap_close(RzIODesc *fd) { + if (!fd || !fd->data) { + return -1; + } + rz_io_mmap_free ((RzIOMMapFileObj *) fd->data); + fd->data = NULL; + return 0; +} + +static int rz_io_mmap_check (const char *filename) { + return (filename && !strncmp (filename, "mmap://", 7) && *(filename + 7)); +} + +static int rz_io_mmap_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + RzIOMMapFileObj *mmo = NULL; + if (!fd || !fd->data || !buf) { + return -1; + } + mmo = fd->data; + if (rz_buf_size (mmo->buf) < io->off) { + io->off = rz_buf_size (mmo->buf); + } + int r = rz_buf_read_at (mmo->buf, io->off, buf, count); + if (r >= 0) { + rz_buf_seek (mmo->buf, r, R_BUF_CUR); + } + return r; +} + +static int rz_io_mmap_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + RzIOMMapFileObj *mmo; + int len = count; + ut64 addr; + + if (!io || !fd || !fd->data || !buf) { + return -1; + } + mmo = fd->data; + addr = io->off; + if ( !(mmo->flags & R_PERM_W)) { + return -1; + } + if ( (count + addr > rz_buf_size (mmo->buf)) || rz_buf_size (mmo->buf) == 0) { + ut64 sz = count + addr; + rz_file_truncate (mmo->filename, sz); + } + len = rz_file_mmap_write (mmo->filename, io->off, buf, len); + if (!rz_io_mmap_refresh_buf (mmo) ) { + eprintf ("io_mmap: failed to refresh the mmap backed buffer.\n"); + // XXX - not sure what needs to be done here (error handling). + } + return len; +} + +static RzIODesc *rz_io_mmap_open(RzIO *io, const char *file, int flags, int mode) { + if (!strncmp (file, "mmap://", 7)) { + file += 7; + } + RzIOMMapFileObj *mmo = rz_io_mmap_create_new_file (io, file, mode, flags); + return mmo? rz_io_desc_new (io, &rz_io_plugin_mmap, mmo->filename, flags, mode, mmo): NULL; +} + +static ut64 rz_io_mmap_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + RzIOMMapFileObj *mmo; + if (!fd || !fd->data) { + return -1; + } + mmo = fd->data; + return rz_io_mmap_seek (io, mmo, offset, whence); +} + +static bool rz_io_mmap_truncate(RzIOMMapFileObj *mmo, ut64 size) { + int res = rz_file_truncate (mmo->filename, size); + if (res && !rz_io_mmap_refresh_buf (mmo)) { + eprintf ("rz_io_mmap_truncate: Error trying to refresh the mmap'ed file."); + res = false; + } else if (res) { + eprintf ("rz_io_mmap_truncate: Error trying to resize the file."); + } + return res; +} + + +static bool __plugin_open(RzIO *io, const char *file, bool many) { + return rz_io_mmap_check (file); +} + +static RzIODesc *__open(RzIO *io, const char *file, int flags, int mode) { + if (!rz_io_mmap_check (file)) { + return NULL; + } + return rz_io_mmap_open (io, file, flags, mode); +} + +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { + return rz_io_mmap_read (io, fd, buf, len); +} + +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { + return rz_io_mmap_write(io, fd, buf, len); +} + +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + return rz_io_mmap_lseek (io, fd, offset, whence); +} + +static int __close(RzIODesc *fd) { + return rz_io_mmap_close (fd); +} + +static bool __resize(RzIO *io, RzIODesc *fd, ut64 size) { + if (!fd || !fd->data) { + return false; + } + return rz_io_mmap_truncate ((RzIOMMapFileObj*)fd->data, size); +} + +struct rz_io_plugin_t rz_io_plugin_mmap = { + .name = "mmap", + .desc = "Open files using mmap", + .uris = "mmap://", + .license = "LGPL3", + .open = __open, + .close = __close, + .read = __read, + .check = __plugin_open, + .lseek = __lseek, + .write = __write, + .resize = __resize, +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_IO, + .data = &rz_io_plugin_mmap, + .version = R2_VERSION +}; +#endif diff --git a/libr/io/p/io_null.c b/librz/io/p/io_null.c similarity index 63% rename from libr/io/p/io_null.c rename to librz/io/p/io_null.c index 1110187998..873cff5418 100644 --- a/libr/io/p/io_null.c +++ b/librz/io/p/io_null.c @@ -1,19 +1,19 @@ /* radare - LGPL - Copyright 2017 - condret, pancake */ -#include -#include +#include +#include typedef struct { ut64 size; ut64 offset; -} RIONull; +} RzIONull; -static int __write(RIO* io, RIODesc* fd, const ut8* buf, int count) { - RIONull* null; +static int __write(RzIO* io, RzIODesc* fd, const ut8* buf, int count) { + RzIONull* null; if (!fd || !fd->data || !buf) { return -1; } - null = (RIONull*) fd->data; + null = (RzIONull*) fd->data; if ((null->offset + count) > null->size) { int ret = null->size - null->offset; return ret; @@ -22,9 +22,9 @@ static int __write(RIO* io, RIODesc* fd, const ut8* buf, int count) { return count; } -static bool __resize(RIO* io, RIODesc* fd, ut64 count) { +static bool __resize(RzIO* io, RzIODesc* fd, ut64 count) { if (fd && fd->data) { - RIONull* null = (RIONull*) fd->data; + RzIONull* null = (RzIONull*) fd->data; null->size = count; if (null->offset >= count) { if (count) { @@ -38,12 +38,12 @@ static bool __resize(RIO* io, RIODesc* fd, ut64 count) { return false; } -static int __read(RIO* io, RIODesc* fd, ut8* buf, int count) { - RIONull* null; +static int __read(RzIO* io, RzIODesc* fd, ut8* buf, int count) { + RzIONull* null; if (!fd || !fd->data || !buf) { return -1; } - null = (RIONull*) fd->data; + null = (RzIONull*) fd->data; if ((null->offset + count) > null->size) { int ret = null->size - null->offset; memset (buf, 0x00, ret); @@ -55,17 +55,17 @@ static int __read(RIO* io, RIODesc* fd, ut8* buf, int count) { return count; } -static int __close(RIODesc* fd) { +static int __close(RzIODesc* fd) { R_FREE (fd->data); return 0; } -static ut64 __lseek(RIO* io, RIODesc* fd, ut64 offset, int whence) { - RIONull* null; +static ut64 __lseek(RzIO* io, RzIODesc* fd, ut64 offset, int whence) { + RzIONull* null; if (!fd || !fd->data) { return offset; } - null = (RIONull*) fd->data; + null = (RzIONull*) fd->data; switch (whence) { case SEEK_SET: if (offset >= null->size) { @@ -83,24 +83,24 @@ static ut64 __lseek(RIO* io, RIODesc* fd, ut64 offset, int whence) { return offset; } -static bool __plugin_open(RIO* io, const char* pathname, bool many) { +static bool __plugin_open(RzIO* io, const char* pathname, bool many) { return (!strncmp (pathname, "null://", 7)); } -static RIODesc* __open(RIO* io, const char* pathname, int rw, int mode) { - RIONull* null; +static RzIODesc* __open(RzIO* io, const char* pathname, int rw, int mode) { + RzIONull* null; if (__plugin_open (io, pathname,0)) { if (!strncmp (pathname, "null://", 7) && strlen (pathname + 7)) { - null = R_NEW0 (RIONull); - null->size = r_num_math (NULL, pathname + 7) + 1; //??? + null = R_NEW0 (RzIONull); + null->size = rz_num_math (NULL, pathname + 7) + 1; //??? null->offset = 0LL; - return r_io_desc_new (io, &r_io_plugin_null, pathname, rw, mode, null); + return rz_io_desc_new (io, &rz_io_plugin_null, pathname, rw, mode, null); } } return NULL; } -RIOPlugin r_io_plugin_null = { +RzIOPlugin rz_io_plugin_null = { .name = "null", .desc = "Null plugin", .license = "LGPL3", @@ -115,9 +115,9 @@ RIOPlugin r_io_plugin_null = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_null, + .data = &rz_io_plugin_null, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_procpid.c b/librz/io/p/io_procpid.c similarity index 63% rename from libr/io/p/io_procpid.c rename to librz/io/p/io_procpid.c index 6a468ae6b8..4ee2b868a5 100644 --- a/libr/io/p/io_procpid.c +++ b/librz/io/p/io_procpid.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2010-2016 - pancake */ -#include +#include -#include -#include -#include +#include +#include +#include #if __linux__ @@ -16,10 +16,10 @@ typedef struct { int fd; int pid; -} RIOProcpid; +} RzIOProcpid; -#define RIOPROCPID_PID(x) (((RIOProcpid*)(x)->data)->pid) -#define RIOPROCPID_FD(x) (((RIOProcpid*)(x)->data)->fd) +#define RzIOPROCPID_PID(x) (((RzIOProcpid*)(x)->data)->pid) +#define RzIOPROCPID_FD(x) (((RzIOProcpid*)(x)->data)->fd) static int __waitpid(int pid) { int st = 0; @@ -33,9 +33,9 @@ static int debug_os_read_at(int fdn, void *buf, int sz, ut64 addr) { return read (fdn, buf, sz); } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { memset (buf, 0xff, len); // TODO: only memset the non-readed bytes - return debug_os_read_at (RIOPROCPID_FD (fd), buf, len, io->off); + return debug_os_read_at (RzIOPROCPID_FD (fd), buf, len, io->off); } static int procpid_write_at(int fd, const ut8 *buf, int sz, ut64 addr) { @@ -45,15 +45,15 @@ static int procpid_write_at(int fd, const ut8 *buf, int sz, ut64 addr) { return write (fd, buf, sz); } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { - return procpid_write_at (RIOPROCPID_FD (fd), buf, len, io->off); +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { + return procpid_write_at (RzIOPROCPID_FD (fd), buf, len, io->off); } -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return (!strncmp (file, "procpid://", 10)); } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { char procpidpath[64]; int fd, ret = -1; if (__plugin_open (io, file, 0)) { @@ -79,19 +79,19 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { } else { ret = pid; } - fd = ret; // TODO: use r_io_fd api + fd = ret; // TODO: use rz_io_fd api snprintf (procpidpath, sizeof (procpidpath), "/proc/%d/mem", pid); - fd = r_sandbox_open (procpidpath, O_RDWR, 0); + fd = rz_sandbox_open (procpidpath, O_RDWR, 0); if (fd != -1) { - RIOProcpid *riop = R_NEW0 (RIOProcpid); + RzIOProcpid *riop = R_NEW0 (RzIOProcpid); if (!riop) { close (fd); return NULL; } riop->pid = pid; riop->fd = fd; - RIODesc *d = r_io_desc_new (io, &r_io_plugin_procpid, file, true, 0, riop); - d->name = r_sys_pid_to_path (riop->pid); + RzIODesc *d = rz_io_desc_new (io, &rz_io_plugin_procpid, file, true, 0, riop); + d->name = rz_sys_pid_to_path (riop->pid); return d; } /* kill children */ @@ -101,18 +101,18 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { return NULL; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { return offset; } -static int __close(RIODesc *fd) { - int ret = ptrace (PTRACE_DETACH, RIOPROCPID_PID (fd), 0, 0); +static int __close(RzIODesc *fd) { + int ret = ptrace (PTRACE_DETACH, RzIOPROCPID_PID (fd), 0, 0); R_FREE (fd->data); return ret; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { - RIOProcpid *iop = (RIOProcpid*)fd->data; +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { + RzIOProcpid *iop = (RzIOProcpid*)fd->data; if (!strncmp (cmd, "pid", 3)) { int pid = atoi (cmd + 3); if (pid > 0) { @@ -125,7 +125,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_procpid = { +RzIOPlugin rz_io_plugin_procpid = { .name = "procpid", .desc = "Open /proc/[pid]/mem io", .license = "LGPL3", @@ -140,15 +140,15 @@ RIOPlugin r_io_plugin_procpid = { }; #else -RIOPlugin r_io_plugin_procpid = { +RzIOPlugin rz_io_plugin_procpid = { .name = NULL }; #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_procpid, + .data = &rz_io_plugin_procpid, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_ptrace.c b/librz/io/p/io_ptrace.c similarity index 69% rename from libr/io/p/io_ptrace.c rename to librz/io/p/io_ptrace.c index 1b98b5d179..9f407d6f96 100644 --- a/libr/io/p/io_ptrace.c +++ b/librz/io/p/io_ptrace.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2008-2017 - pancake */ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #if DEBUGGER && (__linux__ || __BSD__) @@ -19,11 +19,11 @@ typedef struct { int tid; int fd; int opid; -} RIOPtrace; -#define RIOPTRACE_OPID(x) (((RIOPtrace*)(x)->data)->opid) -#define RIOPTRACE_PID(x) (((RIOPtrace*)(x)->data)->pid) -#define RIOPTRACE_FD(x) (((RIOPtrace*)(x)->data)->fd) -static void open_pidmem (RIOPtrace *iop); +} RzIOPtrace; +#define RzIOPTRACE_OPID(x) (((RzIOPtrace*)(x)->data)->opid) +#define RzIOPTRACE_PID(x) (((RzIOPtrace*)(x)->data)->pid) +#define RzIOPTRACE_FD(x) (((RzIOPtrace*)(x)->data)->fd) +static void open_pidmem (RzIOPtrace *iop); #undef R_IO_NFDS #define R_IO_NFDS 2 @@ -52,8 +52,8 @@ static int __waitpid(int pid) { return (waitpid (pid, &st, 0) != -1); } -#define debug_read_raw(io,x,y) r_io_ptrace((io), PTRACE_PEEKTEXT, (x), (void *)(y), R_PTRACE_NODATA) -#define debug_write_raw(io,x,y,z) r_io_ptrace((io), PTRACE_POKEDATA, (x), (void *)(y), (r_ptrace_data_t)(z)) +#define debug_read_raw(io,x,y) rz_io_ptrace((io), PTRACE_PEEKTEXT, (x), (void *)(y), R_PTRACE_NODATA) +#define debug_write_raw(io,x,y,z) rz_io_ptrace((io), PTRACE_POKEDATA, (x), (void *)(y), (rz_ptrace_data_t)(z)) #if __OpenBSD__ || __NetBSD__ || __KFBSD__ typedef int ptrace_word; // int ptrace(int request, pid_t pid, caddr_t addr, int data); #else @@ -62,7 +62,7 @@ typedef size_t ptrace_word; // long ptrace(enum __ptrace_request request, pid_t // XXX. using long here breaks 'w AAAABBBBCCCCDDDD' in r2 -d #endif -static int debug_os_read_at(RIO *io, int pid, ut32 *buf, int sz, ut64 addr) { +static int debug_os_read_at(RzIO *io, int pid, ut32 *buf, int sz, ut64 addr) { ut32 words = sz / sizeof (ut32); ut32 last = sz % sizeof (ut32); ut32 x, lr, *at = (ut32*)(size_t)addr; @@ -79,7 +79,7 @@ static int debug_os_read_at(RIO *io, int pid, ut32 *buf, int sz, ut64 addr) { return sz; } -static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { +static int __read(RzIO *io, RzIODesc *desc, ut8 *buf, int len) { #if USE_PROC_PID_MEM int ret, fd; #endif @@ -90,14 +90,14 @@ static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { memset (buf, '\xff', len); // TODO: only memset the non-readed bytes /* reopen procpidmem if necessary */ #if USE_PROC_PID_MEM - fd = RIOPTRACE_FD (desc); - if (RIOPTRACE_PID (desc) != RIOPTRACE_OPID (desc)) { + fd = RzIOPTRACE_FD (desc); + if (RzIOPTRACE_PID (desc) != RzIOPTRACE_OPID (desc)) { if (fd != -1) { close (fd); } - open_pidmem ((RIOPtrace*)desc->data); - fd = RIOPTRACE_FD (desc); - RIOPTRACE_OPID(desc) = RIOPTRACE_PID(desc); + open_pidmem ((RzIOPtrace*)desc->data); + fd = RzIOPTRACE_FD (desc); + RzIOPTRACE_OPID(desc) = RzIOPTRACE_PID(desc); } // /proc/pid/mem fails on latest linux if (fd != -1) { @@ -110,17 +110,17 @@ static int __read(RIO *io, RIODesc *desc, ut8 *buf, int len) { } } #endif - ut32 *aligned_buf = (ut32*)r_malloc_aligned (len, sizeof (ut32)); + ut32 *aligned_buf = (ut32*)rz_malloc_aligned (len, sizeof (ut32)); if (aligned_buf) { - int res = debug_os_read_at (io, RIOPTRACE_PID (desc), (ut32*)aligned_buf, len, addr); + int res = debug_os_read_at (io, RzIOPTRACE_PID (desc), (ut32*)aligned_buf, len, addr); memcpy (buf, aligned_buf, len); - r_free_aligned (aligned_buf); + rz_free_aligned (aligned_buf); return res; } return -1; } -static int ptrace_write_at(RIO *io, int pid, const ut8 *pbuf, int sz, ut64 addr) { +static int ptrace_write_at(RzIO *io, int pid, const ut8 *pbuf, int sz, ut64 addr) { ptrace_word *buf = (ptrace_word*)pbuf; ut32 words = sz / sizeof (ptrace_word); ut32 last = sz % sizeof (ptrace_word); @@ -145,14 +145,14 @@ static int ptrace_write_at(RIO *io, int pid, const ut8 *pbuf, int sz, ut64 addr) return sz; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { if (!fd || !fd->data) { return -1; } - return ptrace_write_at (io, RIOPTRACE_PID (fd), buf, len, io->off); + return ptrace_write_at (io, RzIOPTRACE_PID (fd), buf, len, io->off); } -static void open_pidmem (RIOPtrace *iop) { +static void open_pidmem (RzIOPtrace *iop) { #if USE_PROC_PID_MEM char pidmem[32]; snprintf (pidmem, sizeof (pidmem), "/proc/%d/mem", iop->pid); @@ -170,14 +170,14 @@ static void open_pidmem (RIOPtrace *iop) { #endif } -static void close_pidmem(RIOPtrace *iop) { +static void close_pidmem(RzIOPtrace *iop) { if (iop->fd != -1) { close (iop->fd); iop->fd = -1; } } -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { if (!strncmp (file, "ptrace://", 9)) { return true; } @@ -187,25 +187,25 @@ static bool __plugin_open(RIO *io, const char *file, bool many) { return false; } -static inline bool is_pid_already_attached(RIO *io, int pid) { +static inline bool is_pid_already_attached(RzIO *io, int pid) { #if defined(__linux__) siginfo_t sig = { 0 }; - return r_io_ptrace (io, PTRACE_GETSIGINFO, pid, NULL, &sig) != -1; + return rz_io_ptrace (io, PTRACE_GETSIGINFO, pid, NULL, &sig) != -1; #elif defined(__FreeBSD__) struct ptrace_lwpinfo info = { 0 }; int len = (int)sizeof (info); - return r_io_ptrace (io, PT_LWPINFO, pid, &info, len) != -1; + return rz_io_ptrace (io, PT_LWPINFO, pid, &info, len) != -1; #elif defined(__OpenBSD__) || defined(__NetBSD__) ptrace_state_t state = { 0 }; int len = (int)sizeof (state); - return r_io_ptrace (io, PT_GET_PROCESS_STATE, pid, &state, len) != -1; + return rz_io_ptrace (io, PT_GET_PROCESS_STATE, pid, &state, len) != -1; #else return false; #endif } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { - RIODesc *desc = NULL; +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { + RzIODesc *desc = NULL; int ret = -1; if (!__plugin_open (io, file, 0)) { @@ -217,7 +217,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { // Safely check if the PID has already been attached to avoid printing errors // and attempt attaching on failure if (!is_pid_already_attached (io, pid)) { - ret = r_io_ptrace (io, PTRACE_ATTACH, pid, 0, 0); + ret = rz_io_ptrace (io, PTRACE_ATTACH, pid, 0, 0); if (ret == -1) { #ifdef __ANDROID__ eprintf ("ptrace_attach: Operation not permitted\n"); @@ -244,20 +244,20 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { } } - RIOPtrace *riop = R_NEW0 (RIOPtrace); + RzIOPtrace *riop = R_NEW0 (RzIOPtrace); if (!riop) { return NULL; } riop->pid = riop->tid = pid; open_pidmem (riop); - desc = r_io_desc_new (io, &r_io_plugin_ptrace, file, rw | R_PERM_X, mode, riop); - desc->name = r_sys_pid_to_path (pid); + desc = rz_io_desc_new (io, &rz_io_plugin_ptrace, file, rw | R_PERM_X, mode, riop); + desc->name = rz_sys_pid_to_path (pid); return desc; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: io->off = offset; @@ -271,19 +271,19 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static int __close(RIODesc *desc) { +static int __close(RzIODesc *desc) { int pid, fd; if (!desc || !desc->data) { return -1; } - pid = RIOPTRACE_PID (desc); - fd = RIOPTRACE_FD (desc); + pid = RzIOPTRACE_PID (desc); + fd = RzIOPTRACE_FD (desc); if (fd != -1) { close (fd); } - RIOPtrace *riop = desc->data; + RzIOPtrace *riop = desc->data; desc->data = NULL; - long ret = r_io_ptrace (desc->io, PTRACE_DETACH, pid, 0, 0); + long ret = rz_io_ptrace (desc->io, PTRACE_DETACH, pid, 0, 0); if (errno == ESRCH) { // process does not exist, may have been killed earlier -- continue as normal ret = 0; @@ -292,8 +292,8 @@ static int __close(RIODesc *desc) { return ret; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { - RIOPtrace *iop = (RIOPtrace*)fd->data; +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { + RzIOPtrace *iop = (RzIOPtrace*)fd->data; //printf("ptrace io command (%s)\n", cmd); /* XXX ugly hack for testing purposes */ if (!strcmp (cmd, "")) { @@ -317,14 +317,14 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { if (cmd[3] == ' ') { int pid = atoi (cmd + 4); if (pid > 0 && pid != iop->pid) { - (void)r_io_ptrace (io, PTRACE_ATTACH, pid, 0, 0); + (void)rz_io_ptrace (io, PTRACE_ATTACH, pid, 0, 0); // TODO: do not set pid if attach fails? iop->pid = iop->tid = pid; } } else { io->cb_printf ("%d\n", iop->pid); } - return r_str_newf ("%d", iop->pid); + return rz_str_newf ("%d", iop->pid); } } else { eprintf ("Try: '=!pid'\n"); @@ -332,8 +332,8 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -static int __getpid (RIODesc *fd) { - RIOPtrace *iop = (RIOPtrace *)fd->data; +static int __getpid (RzIODesc *fd) { + RzIOPtrace *iop = (RzIOPtrace *)fd->data; if (!iop) { return -1; } @@ -341,7 +341,7 @@ static int __getpid (RIODesc *fd) { } // TODO: rename ptrace to io_ptrace .. err io.ptrace ?? -RIOPlugin r_io_plugin_ptrace = { +RzIOPlugin rz_io_plugin_ptrace = { .name = "ptrace", .desc = "Ptrace and /proc/pid/mem (if available) io plugin", .license = "LGPL3", @@ -358,15 +358,15 @@ RIOPlugin r_io_plugin_ptrace = { .isdbg = true }; #else -struct r_io_plugin_t r_io_plugin_ptrace = { +struct rz_io_plugin_t rz_io_plugin_ptrace = { .name = NULL }; #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_ptrace, + .data = &rz_io_plugin_ptrace, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_qnx.c b/librz/io/p/io_qnx.c similarity index 76% rename from libr/io/p/io_qnx.c rename to librz/io/p/io_qnx.c index 9fef6f2f6e..d3a34293f1 100644 --- a/libr/io/p/io_qnx.c +++ b/librz/io/p/io_qnx.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2010-2016 pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #define IRAPI static inline #include typedef struct { libqnxr_t desc; -} RIOQnx; +} RzIOQnx; static libqnxr_t *desc = NULL; -static RIODesc *rioqnx = NULL; +static RzIODesc *rioqnx = NULL; -static bool __plugin_open (RIO *io, const char *file, bool many) { +static bool __plugin_open (RzIO *io, const char *file, bool many) { return (!strncmp (file, "qnx://", 6)); } @@ -47,7 +47,7 @@ static int debug_qnx_read_at (ut8 *buf, int sz, ut64 addr) { c_size = sz; #if SILLY_CACHE free (c_buff); - c_buff = r_mem_dup (buf, sz); + c_buff = rz_mem_dup (buf, sz); #endif return sz; } @@ -76,15 +76,15 @@ static int debug_qnx_write_at (const ut8 *buf, int sz, ut64 addr) { return sz; } -static RIODesc *__open (RIO *io, const char *file, int rw, int mode) { - RIOQnx *rioq; +static RzIODesc *__open (RzIO *io, const char *file, int rw, int mode) { + RzIOQnx *rioq; char host[128], *port, *p; if (!__plugin_open (io, file, 0)) { return NULL; } if (rioqnx) { - // FIX: Don't allocate more than one RIODesc + // FIX: Don't allocate more than one RzIODesc return rioqnx; } strncpy (host, file + 6, sizeof(host) - 1); @@ -101,16 +101,16 @@ static RIODesc *__open (RIO *io, const char *file, int rw, int mode) { *p = 0; } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: Cannot use network\n"); return NULL; } - rioq = R_NEW0 (RIOQnx); + rioq = R_NEW0 (RzIOQnx); qnxr_init (&rioq->desc); int i_port = atoi (port); if (qnxr_connect (&rioq->desc, host, i_port) == 0) { desc = &rioq->desc; - rioqnx = r_io_desc_new (io, &r_io_plugin_qnx, file, rw, mode, rioq); + rioqnx = rz_io_desc_new (io, &rz_io_plugin_qnx, file, rw, mode, rioq); return rioqnx; } eprintf ("qnx.io.open: Cannot connect to host.\n"); @@ -118,7 +118,7 @@ static RIODesc *__open (RIO *io, const char *file, int rw, int mode) { return NULL; } -static int __write (RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { ut64 addr = io->off; if (!desc) { return -1; @@ -126,11 +126,11 @@ static int __write (RIO *io, RIODesc *fd, const ut8 *buf, int count) { return debug_qnx_write_at (buf, count, addr); } -static ut64 __lseek (RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence) { return offset; } -static int __read (RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); ut64 addr = io->off; if (!desc) { @@ -139,16 +139,16 @@ static int __read (RIO *io, RIODesc *fd, ut8 *buf, int count) { return debug_qnx_read_at (buf, count, addr); } -static int __close (RIODesc *fd) { +static int __close (RzIODesc *fd) { // TODO return -1; } -static char *__system (RIO *io, RIODesc *fd, const char *cmd) { +static char *__system (RzIO *io, RzIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_qnx = { +RzIOPlugin rz_io_plugin_qnx = { .name = "qnx", .license = "LGPL3", .desc = "Attach to QNX pdebug instance", @@ -164,9 +164,9 @@ RIOPlugin r_io_plugin_qnx = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_qnx, + .data = &rz_io_plugin_qnx, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_rap.c b/librz/io/p/io_rap.c similarity index 57% rename from libr/io/p/io_rap.c rename to librz/io/p/io_rap.c index 203f00bfce..cf9ccea1e5 100644 --- a/libr/io/p/io_rap.c +++ b/librz/io/p/io_rap.c @@ -1,65 +1,65 @@ /* radare - MIT - Copyright 2011-2020 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include -#define RIORAP_FD(x) (((x)->data)?(((RIORap*)((x)->data))->client):NULL) -#define RIORAP_IS_LISTEN(x) (((RIORap*)((x)->data))->listener) -#define RIORAP_IS_VALID(x) ((x) && ((x)->data) && ((x)->plugin == &r_io_plugin_rap)) +#define RzIORAP_FD(x) (((x)->data)?(((RzIORap*)((x)->data))->client):NULL) +#define RzIORAP_IS_LISTEN(x) (((RzIORap*)((x)->data))->listener) +#define RzIORAP_IS_VALID(x) ((x) && ((x)->data) && ((x)->plugin == &rz_io_plugin_rap)) -static int __rap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - RSocket *s = RIORAP_FD (fd); - return r_socket_rap_client_write (s, buf, count); +static int __rap_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + RzSocket *s = RzIORAP_FD (fd); + return rz_socket_rap_client_write (s, buf, count); } -static bool __rap_accept(RIO *io, RIODesc *desc, int fd) { - RIORap *rap = desc? desc->data: NULL; +static bool __rap_accept(RzIO *io, RzIODesc *desc, int fd) { + RzIORap *rap = desc? desc->data: NULL; if (rap && fd != -1) { - rap->client = r_socket_new_from_fd (fd); + rap->client = rz_socket_new_from_fd (fd); return true; } return false; } -static int __rap_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - RSocket *s = RIORAP_FD (fd); - return r_socket_rap_client_read (s, buf, count); +static int __rap_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + RzSocket *s = RzIORAP_FD (fd); + return rz_socket_rap_client_read (s, buf, count); } -static int __rap_close(RIODesc *fd) { +static int __rap_close(RzIODesc *fd) { int ret = -1; - if (RIORAP_IS_VALID (fd)) { - if (RIORAP_FD (fd) != NULL) { - RIORap *r = fd->data; + if (RzIORAP_IS_VALID (fd)) { + if (RzIORAP_FD (fd) != NULL) { + RzIORap *r = fd->data; if (r && fd->fd != -1) { if (r->fd) { - (void)r_socket_close (r->fd); + (void)rz_socket_close (r->fd); } if (r->client) { - ret = r_socket_close (r->client); + ret = rz_socket_close (r->client); } R_FREE (r); } } } else { - eprintf ("__rap_close: fdesc is not a r_io_rap plugin\n"); + eprintf ("__rap_close: fdesc is not a rz_io_rap plugin\n"); } return ret; } -static ut64 __rap_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - RSocket *s = RIORAP_FD (fd); - return r_socket_rap_client_seek (s, offset, whence); +static ut64 __rap_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + RzSocket *s = RzIORAP_FD (fd); + return rz_socket_rap_client_seek (s, offset, whence); } -static bool __rap_plugin_open(RIO *io, const char *pathname, bool many) { - return r_str_startswith (pathname, "rap://") || r_str_startswith (pathname, "raps://"); +static bool __rap_plugin_open(RzIO *io, const char *pathname, bool many) { + return rz_str_startswith (pathname, "rap://") || rz_str_startswith (pathname, "raps://"); } -static RIODesc *__rap_open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__rap_open(RzIO *io, const char *pathname, int rw, int mode) { int i, p, listenmode; char *file, *port; @@ -82,7 +82,7 @@ static RIODesc *__rap_open(RIO *io, const char *pathname, int rw, int mode) { *file = 0; file++; } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("sandbox: Cannot use network\n"); return NULL; } @@ -93,17 +93,17 @@ static RIODesc *__rap_open(RIO *io, const char *pathname, int rw, int mode) { } //TODO: Handle ^C signal (SIGINT, exit); // ??? eprintf ("rap: listening at port %s ssl %s\n", port, (is_ssl)?"on":"off"); - RIORap *rior = R_NEW0 (RIORap); + RzIORap *rior = R_NEW0 (RzIORap); rior->listener = true; - rior->client = rior->fd = r_socket_new (is_ssl); + rior->client = rior->fd = rz_socket_new (is_ssl); if (!rior->fd) { free (rior); return NULL; } if (is_ssl) { if (file && *file) { - if (!r_socket_listen (rior->fd, port, file)) { - r_socket_free (rior->fd); + if (!rz_socket_listen (rior->fd, port, file)) { + rz_socket_free (rior->fd); free (rior); return NULL; } @@ -112,39 +112,39 @@ static RIODesc *__rap_open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } } else { - if (!r_socket_listen (rior->fd, port, NULL)) { - r_socket_free (rior->fd); + if (!rz_socket_listen (rior->fd, port, NULL)) { + rz_socket_free (rior->fd); free (rior); return NULL; } } - return r_io_desc_new (io, &r_io_plugin_rap, + return rz_io_desc_new (io, &rz_io_plugin_rap, pathname, rw, mode, rior); } - RSocket *s = r_socket_new (is_ssl); + RzSocket *s = rz_socket_new (is_ssl); if (!s) { eprintf ("Cannot create new socket\n"); return NULL; } eprintf ("Connecting to %s, port %s\n", host, port); - if (!r_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { + if (!rz_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { eprintf ("Cannot connect to '%s' (%d)\n", host, p); - r_socket_free (s); + rz_socket_free (s); return NULL; } eprintf ("Connected to: %s at port %s\n", host, port); - RIORap *rior = R_NEW0 (RIORap); + RzIORap *rior = R_NEW0 (RzIORap); if (!rior) { - r_socket_free (s); + rz_socket_free (s); return NULL; } rior->listener = false; rior->client = rior->fd = s; if (file && *file) { - i = r_socket_rap_client_open (s, file, rw); + i = rz_socket_rap_client_open (s, file, rw); if (i == -1) { free (rior); - r_socket_free (s); + rz_socket_free (s); return NULL; } if (i > 0) { @@ -155,18 +155,18 @@ static RIODesc *__rap_open(RIO *io, const char *pathname, int rw, int mode) { io->corebind.cmd (io->corebind.core, ".=!om*"); } } - return r_io_desc_new (io, &r_io_plugin_rap, + return rz_io_desc_new (io, &rz_io_plugin_rap, pathname, rw, mode, rior); } -static int __rap_listener(RIODesc *fd) { - return (RIORAP_IS_VALID (fd))? RIORAP_IS_LISTEN (fd): 0; // -1 ? +static int __rap_listener(RzIODesc *fd) { + return (RzIORAP_IS_VALID (fd))? RzIORAP_IS_LISTEN (fd): 0; // -1 ? } -static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { - RSocket *s = RIORAP_FD (fd); - // TODO: bind core into RSocket instead of pass the one from io? - return r_socket_rap_client_command (s, command, &io->corebind); +static char *__rap_system(RzIO *io, RzIODesc *fd, const char *command) { + RzSocket *s = RzIORAP_FD (fd); + // TODO: bind core into RzSocket instead of pass the one from io? + return rz_socket_rap_client_command (s, command, &io->corebind); #if 0 int ret, reslen = 0, cmdlen = 0; unsigned int i; @@ -179,14 +179,14 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { eprintf ("Command too long\n"); return NULL; } - r_write_be32 (buf + 1, i); + rz_write_be32 (buf + 1, i); memcpy (buf + 5, command, i); - (void)r_socket_write (s, buf, i+5); - r_socket_flush (s); + (void)rz_socket_write (s, buf, i+5); + rz_socket_flush (s); /* read reverse cmds */ for (;;) { - ret = r_socket_read_block (s, buf, 1); + ret = rz_socket_read_block (s, buf, 1); if (ret != 1) { return NULL; } @@ -199,16 +199,16 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { // return back the string buf[0] |= RMT_REPLY; memset (buf + 1, 0, 4); - ret = r_socket_read_block (s, buf + 1, 4); + ret = rz_socket_read_block (s, buf + 1, 4); if (ret != 4) { return NULL; } - cmdlen = r_read_at_be32 (buf, 1); + cmdlen = rz_read_at_be32 (buf, 1); if (cmdlen + 1 == 0) { // check overflow cmdlen = 0; } str = calloc (1, cmdlen + 1); - ret = r_socket_read_block (s, (ut8*)str, cmdlen); + ret = rz_socket_read_block (s, (ut8*)str, cmdlen); eprintf ("RUN %d CMD(%s)\n", ret, str); if (str && *str) { res = io->cb_core_cmdstr (io->user, str); @@ -218,15 +218,15 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { eprintf ("[%s]=>(%s)\n", str, res); reslen = strlen (res); free (str); - r_write_be32 (buf + 1, reslen); + rz_write_be32 (buf + 1, reslen); memcpy (buf + 5, res, reslen); free (res); - (void)r_socket_write (s, buf, reslen + 5); - r_socket_flush (s); + (void)rz_socket_write (s, buf, reslen + 5); + rz_socket_flush (s); } // read - ret = r_socket_read_block (s, buf + 1, 4); + ret = rz_socket_read_block (s, buf + 1, 4); if (ret != 4) { return NULL; } @@ -235,7 +235,7 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { return NULL; } - i = r_read_at_be32 (buf, 1); + i = rz_read_at_be32 (buf, 1); ret = 0; if (i > ST32_MAX) { eprintf ("Invalid length\n"); @@ -245,7 +245,7 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { if (ptr) { int ir, tr = 0; do { - ir = r_socket_read_block (s, (ut8*)ptr + tr, i - tr); + ir = rz_socket_read_block (s, (ut8*)ptr + tr, i - tr); if (ir < 1) { break; } @@ -265,7 +265,7 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { #if DEAD_CODE /* Clean */ if (ret > 0) { - ret -= r_socket_read (s, (ut8*)buf, RMT_MAX); + ret -= rz_socket_read (s, (ut8*)buf, RMT_MAX); } #endif #endif @@ -273,7 +273,7 @@ static char *__rap_system(RIO *io, RIODesc *fd, const char *command) { return NULL; } -RIOPlugin r_io_plugin_rap = { +RzIOPlugin rz_io_plugin_rap = { .name = "rap", .desc = "Remote binary protocol plugin", .uris = "rap://,raps://", @@ -290,9 +290,9 @@ RIOPlugin r_io_plugin_rap = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_rap, + .data = &rz_io_plugin_rap, .version = R2_VERSION }; #endif diff --git a/librz/io/p/io_rbuf.c b/librz/io/p/io_rbuf.c new file mode 100644 index 0000000000..498ce89835 --- /dev/null +++ b/librz/io/p/io_rbuf.c @@ -0,0 +1,67 @@ +/* rizin - LGPL - Copyright 2017 - pancake, condret */ + +#include "rz_io.h" +#include "rz_lib.h" +#include +#include +#include +#include + +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + if (!fd || !buf || count < 0 || !fd->data) { + return -1; + } + RBuffer *b = fd->data; + return rz_buf_write (b, buf, count); +} + +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + RBuffer *b = fd->data; + return rz_buf_read (b, buf, count); +} + +static int __close(RzIODesc *fd) { + RBuffer *b = fd->data; + rz_buf_free (b); + return 0; +} + +static ut64 __lseek(RzIO* io, RzIODesc *fd, ut64 offset, int whence) { + RBuffer *buf = fd->data; + return rz_buf_seek (buf, offset, whence); +} + +static bool __check(RzIO *io, const char *pathname, bool many) { + return (!strncmp (pathname, "rbuf://", 7)); +} + +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { + RzIODesc *desc; + RBuffer *buf = rz_buf_new (); + if (buf && (desc = rz_io_desc_new (io, &rz_io_plugin_rbuf, pathname, 7, 0, buf))) { + return desc; + } + rz_buf_free (buf); + return NULL; +} + +RzIOPlugin rz_io_plugin_rbuf = { + .name = "rbuf", + .desc = "RBuffer IO plugin", + .uris = "rbuf://", + .license = "LGPL", + .open = __open, + .close = __close, + .read = __read, + .lseek = __lseek, + .write = __write, + .check = __check +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_IO, + .data = &rz_io_plugin_rbuf, + .version = R2_VERSION +}; +#endif diff --git a/librz/io/p/io_rzk.c b/librz/io/p/io_rzk.c new file mode 100644 index 0000000000..da40fe82d9 --- /dev/null +++ b/librz/io/p/io_rzk.c @@ -0,0 +1,156 @@ +/* io_rzk - rizin - LGPL - Copyright 2016-2018 - SkUaTeR + panda */ + +#include +#include +#include +#include +#include + +#if __WINDOWS__ +#include "io_rzk_windows.h" +#elif defined (__linux__) && !defined (__GNU__) +#include "io_rzk_linux.h" +struct io_rzk_linux rzk_struct; //TODO: move this into desc->data +#endif + +int rzk__write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { +#if __WINDOWS__ + //eprintf("writing to: 0x%"PFMT64x" len: %x\n",io->off, count); + return WriteKernelMemory (io->off, buf, count); +#elif defined (__linux__) && !defined (__GNU__) + switch (rzk_struct.beid) { + case 0: + return WriteMemory (io, fd, IOCTL_WRITE_KERNEL_MEMORY, rzk_struct.pid, io->off, buf, count); + case 1: + return WriteMemory (io, fd, IOCTL_WRITE_PROCESS_ADDR, rzk_struct.pid, io->off, buf, count); + case 2: + return WriteMemory (io, fd, IOCTL_WRITE_PHYSICAL_ADDR, rzk_struct.pid, io->off, buf, count); + default: + io->cb_printf ("ERROR: Undefined beid in rzk__write.\n"); + return -1; + } +#else + io->cb_printf ("TODO: rzk not implemented for this plataform.\n"); + return -1; +#endif +} + +static int rzk__read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { +#if __WINDOWS__ + return ReadKernelMemory (io->off, buf, count); +#elif defined (__linux__) && !defined (__GNU__) + switch (rzk_struct.beid) { + case 0: + return ReadMemory (io, fd, IOCTL_READ_KERNEL_MEMORY, rzk_struct.pid, io->off, buf, count); + case 1: + return ReadMemory (io, fd, IOCTL_READ_PROCESS_ADDR, rzk_struct.pid, io->off, buf, count); + case 2: + return ReadMemory (io, fd, IOCTL_READ_PHYSICAL_ADDR, rzk_struct.pid, io->off, buf, count); + default: + io->cb_printf ("ERROR: Undefined beid in rzk__read.\n"); + memset (buf, 0xff, count); + return count; + } +#else + io->cb_printf ("TODO: rzk not implemented for this plataform.\n"); + memset (buf, 0xff, count); + return count; +#endif +} + +static int rzk__close(RzIODesc *fd) { +#if __WINDOWS__ + if (gHandleDriver) { + CloseHandle (gHandleDriver); + StartStopService (TEXT ("rzk"),TRUE); + } +#elif defined (__linux__) && !defined (__GNU__) + if (fd) { + close ((int)(size_t)fd->data); + } +#else + eprintf ("TODO: rzk not implemented for this plataform.\n"); +#endif + return 0; +} + +static ut64 rzk__lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + return (!whence) ? offset : whence == 1 + ? io->off + offset : UT64_MAX; +} + +static bool rzk__plugin_open(RzIO *io, const char *pathname, bool many) { + return (!strncmp (pathname, "rzk://", 6)); +} + +static char *rzk__system(RzIO *io, RzIODesc *fd, const char *cmd) { + if (!strcmp (cmd, "")) { + return NULL; + } + if (!strncmp (cmd, "mod", 3)) { +#if __WINDOWS__ + GetSystemModules (io); +#endif + } else { +#if defined (__linux__) && !defined (__GNU__) + (void)run_ioctl_command (io, fd, cmd); + return NULL; +#else + eprintf ("Try: '=!mod'\n '.=!mod'\n"); +#endif + } + return NULL; +} + +static RzIODesc *rzk__open(RzIO *io, const char *pathname, int rw, int mode) { + if (!strncmp (pathname, "rzk://", 6)) { + rw |= R_PERM_WX; +#if __WINDOWS__ + RzIOW32 *w32 = R_NEW0 (RzIOW32); + if (Init (&pathname[6]) == FALSE) { + eprintf ("rzk__open: Error cant init driver: %s\n", &pathname[6]); + free (w32); + return NULL; + } + //return rz_io_desc_new (&rz_io_plugin_rzk, -1, pathname, rw, mode, w32); + return rz_io_desc_new (io, &rz_io_plugin_rzk, pathname, rw, mode, w32); +#elif defined (__linux__) && !defined (__GNU__) + int fd = open ("/dev/rzk", O_RDONLY); + if (fd == -1) { + io->cb_printf ("rzk__open: Error in opening /dev/rzk."); + return NULL; + } + + rzk_struct.beid = 0; + rzk_struct.pid = 0; + rzk_struct.wp = 1; + return rz_io_desc_new (io, &rz_io_plugin_rzk, pathname, rw, mode, (void *)(size_t)fd); +#else + io->cb_printf ("Not supported on this platform\n"); +#endif + } + return NULL; +} + +RzIOPlugin rz_io_plugin_rzk = { + .name = "rzk", + .desc = "Kernel access API io", + .uris = "rzk://", + .license = "LGPL3", + .open = rzk__open, + .close = rzk__close, + .read = rzk__read, + .check = rzk__plugin_open, + .lseek = rzk__lseek, + .system = rzk__system, + .write = rzk__write, +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_IO, + .data = &rz_io_plugin_rzk, + .version = R2_VERSION +}; +#endif + diff --git a/libr/io/p/io_r2k_linux.c b/librz/io/p/io_rzk_linux.c similarity index 90% rename from libr/io/p/io_r2k_linux.c rename to librz/io/p/io_rzk_linux.c index 2f9225578b..48aee5456e 100644 --- a/libr/io/p/io_r2k_linux.c +++ b/librz/io/p/io_rzk_linux.c @@ -1,11 +1,11 @@ #ifndef __GNU__ -#include "io_r2k_linux.h" +#include "io_rzk_linux.h" #define fset(num, shift) ((((num) & (((ut64) 1) << (shift))) == 0) ? 0 : 1) #if __i386__ || __x86_64__ -static void x86_ctrl_reg_pretty_print (RIO *io, struct r2k_control_reg ctrl) { +static void x86_ctrl_reg_pretty_print (RzIO *io, struct rzk_control_reg ctrl) { io->cb_printf ("CR0: 0x%"PFMT64x"\n", (ut64) ctrl.cr0); io->cb_printf (" [*] PG: %d\n" " [*] CD: %d\n" @@ -69,7 +69,7 @@ static void x86_ctrl_reg_pretty_print (RIO *io, struct r2k_control_reg ctrl) { } #elif __arm__ -static void arm_ctrl_reg_pretty_print (RIO *io, struct r2k_control_reg ctrl) { +static void arm_ctrl_reg_pretty_print (RzIO *io, struct rzk_control_reg ctrl) { io->cb_printf ("TTBR0: 0x%"PFMT64x"\n", (ut64) ctrl.ttbr0); io->cb_printf (" [*] Translation table base 0: 0x%"PFMT64x"\n" " [*] UNP/SBZ: 0x%"PFMT64x"\n" @@ -133,7 +133,7 @@ static void arm_ctrl_reg_pretty_print (RIO *io, struct r2k_control_reg ctrl) { #elif __arm64__ || __aarch64__ /*ARM Cortex-A57 and ARM Cortex-A72. This might show some wrong values for other processor.*/ -static void arm64_ctrl_reg_pretty_print (RIO *io, struct r2k_control_reg ctrl) { +static void arm64_ctrl_reg_pretty_print (RzIO *io, struct rzk_control_reg ctrl) { io->cb_printf ("SCTLR_EL1: 0x%"PFMT64x"\n", ctrl.sctlr_el1); io->cb_printf (" [*] UCI: %d\n" " [*] EE: %d\n" @@ -207,7 +207,7 @@ static const char* getargpos (const char *buf, int pos) { if (!buf) { break; } - buf = r_str_ichr ((char *) buf, ' '); + buf = rz_str_ichr ((char *) buf, ' '); } return buf; } @@ -223,20 +223,20 @@ static size_t getvalue (const char *buf, int pos) { return ret; } -static void print_help(RIO *io, char *cmd, int p_usage) { +static void print_help(RzIO *io, char *cmd, int p_usage) { int i = 0; int cmd_len = cmd ? strlen (cmd) : 0; const char* usage = "Usage: \\[MprRw][lpP] [args...]"; const char* help_msg[] = { - "\\dm Print kernel memory map (or process if r2k.io==1)", + "\\dm Print kernel memory map (or process if rzk.io==1)", "\\dr Print control registers", "\\dR Print control registers in detailed mode", "\\dp [pid] Print current selected pid or change it", - "\\e r2k.io=[012] Read/Write from 0: Linear, 1: Process, 2: Physical addresses" + "\\e rzk.io=[012] Read/Write from 0: Linear, 1: Process, 2: Physical addresses" }; const char *help_msg_old[] = { "\\M Print kernel memory map", - "\\b beid [pid] Change r2k backend. pid is required when beid is 1.", + "\\b beid [pid] Change rzk backend. pid is required when beid is 1.", " 0: linear address; 1: process address; 2: physical address", "\\p pid Print process information", "\\rl addr len Read from linear address", @@ -264,7 +264,7 @@ static void print_help(RIO *io, char *cmd, int p_usage) { } } -int ReadMemory(RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len) { +int ReadMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len) { int ret = -1; int pagesize, newlen; ut64 pageaddr, offset; @@ -272,7 +272,7 @@ int ReadMemory(RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, size_t address ut8 garbage; if (iodesc && iodesc->data > 0 && buf) { - struct r2k_data data; + struct rzk_data data; data.pid = pid; data.addr = address; @@ -343,17 +343,17 @@ int ReadMemory(RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, size_t address return ret; } -int WriteMemory(RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len) { +int WriteMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len) { int ret = -1; if (iodesc && iodesc->data > 0 && buf) { - struct r2k_data data; + struct rzk_data data; data.pid = pid; data.addr = address; data.len = len; data.buff = (ut8 *) calloc (len + 1, 1); - data.wp = r2k_struct.wp; + data.wp = rzk_struct.wp; if (!data.buff) { return -1; @@ -377,7 +377,7 @@ int WriteMemory(RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, return ret; } -int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { +int run_old_command(RzIO *io, RzIODesc *iodesc, const char *buf) { int ret, inphex, ioctl_n; size_t pid, addr, len; ut8 *databuf = NULL; @@ -385,7 +385,7 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { case 'W': { if (buf[1] != ' ') { - io->cb_printf ("Write Protect: %d\n", r2k_struct.wp); + io->cb_printf ("Write Protect: %d\n", rzk_struct.wp); io->cb_printf ("Usage:\n"); print_help (io, "W", 0); break; @@ -397,15 +397,15 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { print_help (io, "W", 0); break; } - r2k_struct.wp = (ut8)wp; + rzk_struct.wp = (ut8)wp; } break; case 'b': { char *cmd = NULL; if (buf[1] != ' ') { - io->cb_printf ("beid: %d\n", r2k_struct.beid); - io->cb_printf ("pid: %d\n", r2k_struct.pid); + io->cb_printf ("beid: %d\n", rzk_struct.beid); + io->cb_printf ("pid: %d\n", rzk_struct.pid); io->cb_printf ("Usage:\n"); print_help (io, "b", 0); goto end; @@ -422,12 +422,12 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { print_help (io, "b", 0); break; } - r2k_struct.beid = beid; - r2k_struct.pid = (beid == 1) ? pid : 0; + rzk_struct.beid = beid; + rzk_struct.pid = (beid == 1) ? pid : 0; cmd = (char *) malloc (27); if (!cmd) { - io->cb_printf ("io_r2k_linux : Malloc failed. Seeking to 0x0\n"); + io->cb_printf ("io_rzk_linux : Malloc failed. Seeking to 0x0\n"); io->corebind.cmd (io->corebind.core, "s 0"); } else { sprintf (cmd, "s 0x%"PFMT64x, io->off); @@ -438,7 +438,7 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { break; case 'r': { - RPrint *print = r_print_new (); + RPrint *print = rz_print_new (); switch (buf[1]) { case 'l': //read linear address @@ -493,19 +493,19 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { break; default: print_help(io, "r", 0); - r_print_free (print); + rz_print_free (print); goto end; } databuf = (ut8 *) calloc (len + 1, 1); if (databuf) { ret = ReadMemory (io, iodesc, ioctl_n, pid, addr, databuf, len); if (ret > 0) { - r_print_hexdump (print, addr, (const ut8 *) databuf, ret, 16, 1, 1); + rz_print_hexdump (print, addr, (const ut8 *) databuf, ret, 16, 1, 1); } } else { io->cb_printf ("Failed to allocate buffer\n"); } - r_print_free (print); + rz_print_free (print); } break; case 'w': @@ -574,10 +574,10 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { databuf = (ut8 *) calloc (len + 1, 1); if (databuf) { if (inphex) { - len = r_hex_str2bin (buf, databuf); + len = rz_hex_str2bin (buf, databuf); } else { memcpy (databuf, buf, strlen (buf) + 1); - len = r_str_unescape ((char *) databuf); + len = rz_str_unescape ((char *) databuf); } ret = WriteMemory (io, iodesc, ioctl_n, pid, addr, (const ut8 *) databuf, len); } else { @@ -589,8 +589,8 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { //Print kernel memory map. //=! M int i, j; - struct r2k_kernel_maps map_data; - struct r2k_kernel_map_info *info; + struct rzk_kernel_maps map_data; + struct rzk_kernel_map_info *info; long page_size = sysconf (_SC_PAGESIZE); ioctl_n = IOCTL_GET_KERNEL_MAP; @@ -609,7 +609,7 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { } for (i = 0; i < map_data.n_entries; i++) { - struct r2k_kernel_map_info *in = &info[i]; + struct rzk_kernel_map_info *in = &info[i]; io->cb_printf ("start_addr: 0x%"PFMT64x"\n", (ut64) in->start_addr); io->cb_printf ("end_addr: 0x%"PFMT64x"\n", (ut64) in->end_addr); io->cb_printf ("n_pages: %d (%ld Kbytes)\n", in->n_pages, (in->n_pages * page_size) / 1024); @@ -629,7 +629,7 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { { //Read control registers //=! R[p] - struct r2k_control_reg reg_data; + struct rzk_control_reg reg_data; ioctl_n = IOCTL_READ_CONTROL_REG; ret = ioctl ((int)(size_t)iodesc->data, ioctl_n, ®_data); @@ -683,7 +683,7 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { ut64 nextstart; ut64 buffsize; bool fflag = 0; - struct r2k_proc_info proc_data; + struct rzk_proc_info proc_data; if (*(buf + 1) == '*') { fflag = 1; @@ -774,16 +774,16 @@ int run_old_command(RIO *io, RIODesc *iodesc, const char *buf) { return 0; } -int run_new_command(RIO *io, RIODesc *iodesc, const char *buf) { - if (r_str_startswith (buf, "dm")) { +int run_new_command(RzIO *io, RzIODesc *iodesc, const char *buf) { + if (rz_str_startswith (buf, "dm")) { if (buf[2] == ' ') { // use \p pid - char *cmd = r_str_newf ("p %d", atoi (buf + 2)); + char *cmd = rz_str_newf ("p %d", atoi (buf + 2)); run_old_command (io, iodesc, cmd); free (cmd); - } else if (r2k_struct.beid == 1) { + } else if (rzk_struct.beid == 1) { // use \p pid - char *cmd = r_str_newf ("p %d", r2k_struct.pid); + char *cmd = rz_str_newf ("p %d", rzk_struct.pid); run_old_command (io, iodesc, cmd); free (cmd); } else { @@ -792,23 +792,23 @@ int run_new_command(RIO *io, RIODesc *iodesc, const char *buf) { } return 1; } - if (r_str_startswith (buf, "dr")) { + if (rz_str_startswith (buf, "dr")) { run_old_command (io, iodesc, "R"); return 1; } - if (r_str_startswith (buf, "dR")) { + if (rz_str_startswith (buf, "dR")) { run_old_command (io, iodesc, "Rp"); return 1; } - if (r_str_startswith (buf, "dp")) { + if (rz_str_startswith (buf, "dp")) { if (buf[2] == ' ') { - r2k_struct.pid = atoi (buf + 3); + rzk_struct.pid = atoi (buf + 3); } else { - io->cb_printf ("%d\n", r2k_struct.pid); + io->cb_printf ("%d\n", rzk_struct.pid); } return 1; } - if (r_str_startswith (buf, "e r2k.io")) { + if (rz_str_startswith (buf, "e rzk.io")) { if (strchr (buf, '?')) { io->cb_printf ("0: Linear memory\n"); io->cb_printf ("1: Process memory\n"); @@ -818,8 +818,8 @@ int run_new_command(RIO *io, RIODesc *iodesc, const char *buf) { const char *eq = strchr (buf, '='); if (eq) { int v = atoi (eq + 1); - int p = r2k_struct.pid; - char *cmd = r_str_newf ("b %d %d", v, p); + int p = rzk_struct.pid; + char *cmd = rz_str_newf ("b %d %d", v, p); run_old_command (io, iodesc, cmd); free (cmd); } else { @@ -827,7 +827,7 @@ int run_new_command(RIO *io, RIODesc *iodesc, const char *buf) { } return 1; } - if (r_str_startswith (buf, "e r2k.wp")) { + if (rz_str_startswith (buf, "e rzk.wp")) { if (strchr (buf, '?')) { io->cb_printf (" enable write protection (disabled by default)\n"); return 1; @@ -835,17 +835,17 @@ int run_new_command(RIO *io, RIODesc *iodesc, const char *buf) { const char *eq = strchr (buf, '='); if (eq) { int v = atoi (eq + 1); - r2k_struct.wp = (ut8)v; + rzk_struct.wp = (ut8)v; } else { - io->cb_printf ("%s", r_str_bool (r2k_struct.wp)); + io->cb_printf ("%s", rz_str_bool (rzk_struct.wp)); } return 1; } return 0; } -int run_ioctl_command(RIO *io, RIODesc *iodesc, const char *buf) { - buf = r_str_ichr ((char *) buf, ' '); +int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf) { + buf = rz_str_ichr ((char *) buf, ' '); if (!run_new_command (io, iodesc, buf)) { return run_old_command (io, iodesc, buf); diff --git a/libr/io/p/io_r2k_linux.h b/librz/io/p/io_rzk_linux.h similarity index 62% rename from libr/io/p/io_r2k_linux.h rename to librz/io/p/io_rzk_linux.h index 47e6da095f..f2fa9afb1f 100644 --- a/libr/io/p/io_r2k_linux.h +++ b/librz/io/p/io_rzk_linux.h @@ -1,11 +1,11 @@ #ifndef __IO_R2K_LINUX_H__ #define __IO_R2K_LINUX_H__ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -19,13 +19,13 @@ * 1: Process Address * 2: Physical Address */ -struct io_r2k_linux { +struct io_rzk_linux { int beid; int pid; ut8 wp; }; -struct r2k_data { +struct rzk_data { int pid; size_t addr; size_t len; @@ -33,7 +33,7 @@ struct r2k_data { ut8 wp; }; -struct r2k_kernel_map_info { +struct rzk_kernel_map_info { size_t start_addr; size_t end_addr; size_t phys_addr[MAX_PHYS_ADDR]; @@ -41,12 +41,12 @@ struct r2k_kernel_map_info { int n_phys_addr; }; -struct r2k_kernel_maps { +struct rzk_kernel_maps { int n_entries; int size; }; -struct r2k_control_reg { +struct rzk_control_reg { #if __x86_64__ || __i386__ size_t cr0; size_t cr1; @@ -70,7 +70,7 @@ struct r2k_control_reg { #endif }; -struct r2k_proc_info { +struct rzk_proc_info { int pid; char comm[16]; size_t vmareastruct[4096]; @@ -91,36 +91,36 @@ struct r2k_proc_info { #define PRINT_PROC_INFO 0x9 #ifdef _IOC_TYPECHECK -#define r2k_data_size struct r2k_data -#define r2k_kernel_maps_size struct r2k_kernel_maps -#define r2k_control_reg_size struct r2k_control_reg -#define r2k_proc_info_size struct r2k_proc_info +#define rzk_data_size struct rzk_data +#define rzk_kernel_maps_size struct rzk_kernel_maps +#define rzk_control_reg_size struct rzk_control_reg +#define rzk_proc_info_size struct rzk_proc_info #else -#define r2k_data_size sizeof (struct r2k_data) -#define r2k_kernel_maps_size sizeof (struct r2k_kernel_maps) -#define r2k_control_reg_size sizeof (struct r2k_control_reg) -#define r2k_proc_info_size sizeof (struct r2k_proc_info) +#define rzk_data_size sizeof (struct rzk_data) +#define rzk_kernel_maps_size sizeof (struct rzk_kernel_maps) +#define rzk_control_reg_size sizeof (struct rzk_control_reg) +#define rzk_proc_info_size sizeof (struct rzk_proc_info) #endif -#define IOCTL_READ_KERNEL_MEMORY _IOR (R2_TYPE, READ_KERNEL_MEMORY, r2k_data_size) -#define IOCTL_WRITE_KERNEL_MEMORY _IOR (R2_TYPE, WRITE_KERNEL_MEMORY, r2k_data_size) -#define IOCTL_READ_PROCESS_ADDR _IOR (R2_TYPE, READ_PROCESS_ADDR, r2k_data_size) -#define IOCTL_WRITE_PROCESS_ADDR _IOR (R2_TYPE, WRITE_PROCESS_ADDR, r2k_data_size) -#define IOCTL_READ_PHYSICAL_ADDR _IOR (R2_TYPE, READ_PHYSICAL_ADDR, r2k_data_size) -#define IOCTL_WRITE_PHYSICAL_ADDR _IOR (R2_TYPE, WRITE_PHYSICAL_ADDR, r2k_data_size) -#define IOCTL_GET_KERNEL_MAP _IOR (R2_TYPE, GET_KERNEL_MAP, r2k_kernel_maps_size) -#define IOCTL_READ_CONTROL_REG _IOR (R2_TYPE, READ_CONTROL_REG, r2k_control_reg_size) -#define IOCTL_PRINT_PROC_INFO _IOR (R2_TYPE, PRINT_PROC_INFO, r2k_data_size) // Bad hack. Incorrect size, but since module does not use _IOC_SIZE, it won't matter if size parameter is wrong +#define IOCTL_READ_KERNEL_MEMORY _IOR (R2_TYPE, READ_KERNEL_MEMORY, rzk_data_size) +#define IOCTL_WRITE_KERNEL_MEMORY _IOR (R2_TYPE, WRITE_KERNEL_MEMORY, rzk_data_size) +#define IOCTL_READ_PROCESS_ADDR _IOR (R2_TYPE, READ_PROCESS_ADDR, rzk_data_size) +#define IOCTL_WRITE_PROCESS_ADDR _IOR (R2_TYPE, WRITE_PROCESS_ADDR, rzk_data_size) +#define IOCTL_READ_PHYSICAL_ADDR _IOR (R2_TYPE, READ_PHYSICAL_ADDR, rzk_data_size) +#define IOCTL_WRITE_PHYSICAL_ADDR _IOR (R2_TYPE, WRITE_PHYSICAL_ADDR, rzk_data_size) +#define IOCTL_GET_KERNEL_MAP _IOR (R2_TYPE, GET_KERNEL_MAP, rzk_kernel_maps_size) +#define IOCTL_READ_CONTROL_REG _IOR (R2_TYPE, READ_CONTROL_REG, rzk_control_reg_size) +#define IOCTL_PRINT_PROC_INFO _IOR (R2_TYPE, PRINT_PROC_INFO, rzk_data_size) // Bad hack. Incorrect size, but since module does not use _IOC_SIZE, it won't matter if size parameter is wrong #define VM_READ 0x1 #define VM_WRITE 0x2 #define VM_EXEC 0x4 #define VM_MAYSHARE 0x80 -extern struct io_r2k_linux r2k_struct; +extern struct io_rzk_linux rzk_struct; -int ReadMemory (RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len); -int WriteMemory (RIO *io, RIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len); -int run_ioctl_command(RIO *io, RIODesc *iodesc, const char *buf); +int ReadMemory (RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len); +int WriteMemory (RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len); +int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf); #endif diff --git a/libr/io/p/io_r2k_windows.c b/librz/io/p/io_rzk_windows.c similarity index 86% rename from libr/io/p/io_r2k_windows.c rename to librz/io/p/io_rzk_windows.c index 59cafd5d4c..1b0c8cec4b 100644 --- a/libr/io/p/io_r2k_windows.c +++ b/librz/io/p/io_rzk_windows.c @@ -1,4 +1,4 @@ -#include "io_r2k_windows.h" +#include "io_rzk_windows.h" HANDLE gHandleDriver = NULL; @@ -7,7 +7,7 @@ static BOOL InstallService(const char * rutaDriver, LPCTSTR lpServiceName, LPCT BOOL ret = FALSE; HANDLE hSCManager = OpenSCManager (NULL, NULL, SC_MANAGER_CREATE_SERVICE); if (hSCManager) { - LPTSTR rutaDriver_ = r_sys_conv_utf8_to_win (rutaDriver); + LPTSTR rutaDriver_ = rz_sys_conv_utf8_to_win (rutaDriver); hService = CreateService (hSCManager, lpServiceName, lpDisplayName, SERVICE_START | DELETE | SERVICE_STOP, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, rutaDriver_, NULL, NULL, NULL, NULL, NULL); if (hService) { CloseServiceHandle (hService); @@ -86,14 +86,14 @@ static const char *GetFileName(const char *path) { return pfile; } -int GetSystemModules(RIO *io) { +int GetSystemModules(RzIO *io) { DWORD bRead = 0; int i; LPVOID lpBufMods = NULL; int bufmodsize = 1024 * 1024; if(gHandleDriver) { if (!(lpBufMods = malloc (bufmodsize))) { - eprintf ("[r2k] GetSystemModules: Error can't allocate %i bytes of memory.\n", bufmodsize); + eprintf ("[rzk] GetSystemModules: Error can't allocate %i bytes of memory.\n", bufmodsize); return -1; } if (DeviceIoControl (gHandleDriver, IOCTL_GET_SYSTEM_MODULES, lpBufMods, bufmodsize, lpBufMods, bufmodsize, &bRead, NULL)) { @@ -119,7 +119,7 @@ int ReadKernelMemory (ut64 address, ut8 *buf, int len) { if(gHandleDriver) { bufsize = sizeof (PA) + len; if (!(lpBuffer = malloc (bufsize))) { - eprintf ("[r2k] ReadKernelMemory: Error can't allocate %i bytes of memory.\n", bufsize); + eprintf ("[rzk] ReadKernelMemory: Error can't allocate %i bytes of memory.\n", bufsize); return -1; } p = (PPA)lpBuffer; @@ -130,7 +130,7 @@ int ReadKernelMemory (ut64 address, ut8 *buf, int len) { ret = len; } else { ret = -1; - //eprintf("[r2k] ReadKernelMemory: Error IOCTL_READ_KERNEL_MEM.\n"); + //eprintf("[rzk] ReadKernelMemory: Error IOCTL_READ_KERNEL_MEM.\n"); } free (lpBuffer); } else { @@ -147,7 +147,7 @@ int WriteKernelMemory (ut64 address, const ut8 *buf, int len) { if(gHandleDriver) { bufsize = sizeof (PA) + len; if (!(lpBuffer = malloc (bufsize))) { - eprintf ("[r2k] WriteKernelMemory: Error can't allocate %i bytes of memory.\n", bufsize); + eprintf ("[rzk] WriteKernelMemory: Error can't allocate %i bytes of memory.\n", bufsize); return -1; } p = (PPA)lpBuffer; @@ -157,7 +157,7 @@ int WriteKernelMemory (ut64 address, const ut8 *buf, int len) { if (DeviceIoControl (gHandleDriver, IOCTL_WRITE_KERNEL_MEM, lpBuffer, bufsize, lpBuffer, bufsize, &bRead, NULL)) { ret = len; } else { - eprintf ("[r2k] WriteKernelMemory: Error IOCTL_WRITE_KERNEL_MEM.\n"); + eprintf ("[rzk] WriteKernelMemory: Error IOCTL_WRITE_KERNEL_MEM.\n"); ret = -1; } free (lpBuffer); @@ -171,15 +171,15 @@ int Init (const char * driverPath) { BOOL ret = FALSE; if (InitDriver () == FALSE) { if (strlen (driverPath)) { - StartStopService (TEXT ("r2k"),TRUE); - RemoveService (TEXT ("r2k")); + StartStopService (TEXT ("rzk"),TRUE); + RemoveService (TEXT ("rzk")); eprintf ("Installing driver: %s\n", driverPath); - if (InstallService (driverPath, TEXT ("r2k"), TEXT ("r2k"))) { - StartStopService (TEXT ("r2k"),FALSE); + if (InstallService (driverPath, TEXT ("rzk"), TEXT ("rzk"))) { + StartStopService (TEXT ("rzk"),FALSE); ret = InitDriver (); } } else { - eprintf ("Error initalizating driver, try r2k://pathtodriver\nEx: radare2.exe r2k://c:\\r2k.sys"); + eprintf ("Error initalizating driver, try rzk://pathtodriver\nEx: rizin.exe rzk://c:\\rzk.sys"); } } else { eprintf ("Driver present [OK]\n"); diff --git a/libr/io/p/io_r2k_windows.h b/librz/io/p/io_rzk_windows.h similarity index 90% rename from libr/io/p/io_r2k_windows.h rename to librz/io/p/io_rzk_windows.h index 5e26ca0a27..eccd8486fb 100644 --- a/libr/io/p/io_r2k_windows.h +++ b/librz/io/p/io_rzk_windows.h @@ -1,15 +1,15 @@ #ifndef __IO_R2k_WINDOWS_H__ #define __IO_R2k_WINDOWS_H__ -#include -#include -#include -#include +#include +#include +#include +#include #include typedef struct { HANDLE hnd; -} RIOW32; +} RzIOW32; typedef struct _PPA { LARGE_INTEGER address; DWORD len; @@ -34,7 +34,7 @@ typedef struct _RTL_PROCESS_MODULES { RTL_PROCESS_MODULE_INFORMATION Modules[1]; } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES; -#define R2K_DEVICE "\\\\.\\r2k\\" +#define R2K_DEVICE "\\\\.\\rzk\\" #define IOCTL_CODE(DeviceType, Function, Method, Access) \ (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method)) @@ -54,7 +54,7 @@ FILE_WRITE_ACCESS 2 extern HANDLE gHandleDriver; BOOL StartStopService(LPCTSTR lpServiceName, BOOL bStop); -int GetSystemModules(RIO *io); +int GetSystemModules(RzIO *io); int ReadKernelMemory (ut64 address, ut8 *buf, int len); int WriteKernelMemory (ut64 address, const ut8 *buf, int len); int Init (const char * driverPath); diff --git a/libr/io/p/io_r2pipe-test.js b/librz/io/p/io_rzpipe-test.js similarity index 90% rename from libr/io/p/io_r2pipe-test.js rename to librz/io/p/io_rzpipe-test.js index c217366fed..350d2f42b1 100644 --- a/libr/io/p/io_r2pipe-test.js +++ b/librz/io/p/io_rzpipe-test.js @@ -11,7 +11,7 @@ if (!nfd_in || !nfd_out) { var fd_in = fs.createReadStream(null, {fd: nfd_in}); var fd_out = fs.createWriteStream(null, {fd: nfd_out}); -console.error ("Running r2pipe io using fds: ", nfd_in, nfd_out); +console.error ("Running rzpipe io using fds: ", nfd_in, nfd_out); fd_in.on('data', function(data) { data = data.slice(0,-1); diff --git a/libr/io/p/io_r2pipe.c b/librz/io/p/io_rzpipe.c similarity index 68% rename from libr/io/p/io_r2pipe.c rename to librz/io/p/io_rzpipe.c index 32d41b27df..da5f150e5d 100644 --- a/libr/io/p/io_r2pipe.c +++ b/librz/io/p/io_rzpipe.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2015-2019 - pancake */ -#include "r_io.h" -#include "r_lib.h" -#include "r_socket.h" +#include "rz_io.h" +#include "rz_lib.h" +#include "rz_socket.h" #include #include #include @@ -10,9 +10,9 @@ /* --------------------------------------------------------- */ #define R2P(x) ((R2Pipe*)(x)->data) -// TODO: add r2pipe_assert +// TODO: add rzpipe_assert -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { char fmt[4096]; char *bufn, bufnum[4096]; int i, rv, rescount = -1; @@ -31,15 +31,15 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { "{\"op\":\"write\",\"address\":%" PFMT64d ",\"data\":[%s]}", io->off, bufnum); if (len >= sizeof (fmt)) { - eprintf ("r2pipe_write: error, fmt string has been truncated\n"); + eprintf ("rzpipe_write: error, fmt string has been truncated\n"); return -1; } - rv = r2pipe_write (R2P (fd), fmt); + rv = rzpipe_write (R2P (fd), fmt); if (rv < 1) { - eprintf ("r2pipe_write: error\n"); + eprintf ("rzpipe_write: error\n"); return -1; } - res = r2pipe_read (R2P (fd)); + res = rzpipe_read (R2P (fd)); /* TODO: parse json back */ r = strstr (res, "result"); if (r) { @@ -49,7 +49,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return rescount; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { char fmt[4096], num[128]; int rv, rescount = -1; int bufi, numi; @@ -63,12 +63,12 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { snprintf (fmt, sizeof (fmt), "{\"op\":\"read\",\"address\":%"PFMT64d",\"count\":%d}", io->off, count); - rv = r2pipe_write (R2P (fd), fmt); + rv = rzpipe_write (R2P (fd), fmt); if (rv < 1) { - eprintf ("r2pipe_write: error\n"); + eprintf ("rzpipe_write: error\n"); return -1; } - res = r2pipe_read (R2P (fd)); + res = rzpipe_read (R2P (fd)); /* TODO: parse json back */ r = strstr (res, "result"); @@ -120,16 +120,16 @@ beach: return rescount; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { if (!fd || !fd->data) { return -1; } - r2pipe_close (fd->data); + rzpipe_close (fd->data); fd->data = NULL; return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; @@ -138,34 +138,34 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return offset; } -static bool __check(RIO *io, const char *pathname, bool many) { - return (!strncmp (pathname, "r2pipe://", 9)); +static bool __check(RzIO *io, const char *pathname, bool many) { + return (!strncmp (pathname, "rzpipe://", 9)); } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { R2Pipe *r2p = NULL; if (__check (io, pathname, 0)) { - r2p = r2pipe_open (pathname + 9); + r2p = rzpipe_open (pathname + 9); } - return r2p? r_io_desc_new (io, &r_io_plugin_r2pipe, + return r2p? rz_io_desc_new (io, &rz_io_plugin_rzpipe, pathname, rw, mode, r2p): NULL; } -static char *__system(RIO *io, RIODesc *fd, const char *msg) { - r_return_val_if_fail (io && fd && msg, NULL); +static char *__system(RzIO *io, RzIODesc *fd, const char *msg) { + rz_return_val_if_fail (io && fd && msg, NULL); PJ *pj = pj_new (); pj_o (pj); pj_ks (pj, "op", "system"); pj_ks (pj, "cmd", msg); pj_end (pj); const char *fmt = pj_string (pj); - int rv = r2pipe_write (R2P (fd), fmt); + int rv = rzpipe_write (R2P (fd), fmt); pj_free (pj); if (rv < 1) { - eprintf ("r2pipe_write: error\n"); + eprintf ("rzpipe_write: error\n"); return NULL; } - char *res = r2pipe_read (R2P (fd)); + char *res = rzpipe_read (R2P (fd)); //eprintf ("%s\n", res); /* TODO: parse json back */ char *r = strstr (res, "result"); @@ -177,11 +177,11 @@ static char *__system(RIO *io, RIODesc *fd, const char *msg) { return NULL; } -RIOPlugin r_io_plugin_r2pipe = { - .name = "r2pipe", - .desc = "r2pipe io plugin", +RzIOPlugin rz_io_plugin_rzpipe = { + .name = "rzpipe", + .desc = "rzpipe io plugin", .license = "MIT", - .uris = "r2pipe://", + .uris = "rzpipe://", .open = __open, .close = __close, .read = __read, @@ -192,9 +192,9 @@ RIOPlugin r_io_plugin_r2pipe = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_r2pipe, + .data = &rz_io_plugin_rzpipe, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_r2web.c b/librz/io/p/io_rzweb.c similarity index 59% rename from libr/io/p/io_r2web.c rename to librz/io/p/io_rzweb.c index afb49b345a..b3773cfb65 100644 --- a/libr/io/p/io_r2web.c +++ b/librz/io/p/io_rzweb.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include @@ -9,12 +9,12 @@ typedef struct { int fd; char *url; -} RIOR2Web; +} RzIOR2Web; -#define rFD(x) (((RIOR2Web*)(x)->data)->fd) -#define rURL(x) (((RIOR2Web*)(x)->data)->url) +#define rFD(x) (((RzIOR2Web*)(x)->data)->fd) +#define rURL(x) (((RzIOR2Web*)(x)->data)->url) -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { int code, rlen; char *out, *url, *hexbuf; if (!fd || !fd->data) { @@ -28,32 +28,32 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return -1; } hexbuf[0] = 0; - r_hex_bin2str (buf, count, hexbuf); - url = r_str_newf ("%s/wx%%20%s@%"PFMT64d, + rz_hex_bin2str (buf, count, hexbuf); + url = rz_str_newf ("%s/wx%%20%s@%"PFMT64d, rURL(fd), hexbuf, io->off); - out = r_socket_http_get (url, &code, &rlen); + out = rz_socket_http_get (url, &code, &rlen); free (out); free (url); free (hexbuf); return count; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { int code, rlen; char *out, *url; int ret = 0; if (!fd || !fd->data) { return -1; } - url = r_str_newf ("%s/p8%%20%d@0x%"PFMT64x, + url = rz_str_newf ("%s/p8%%20%d@0x%"PFMT64x, rURL(fd), count, io->off); - out = r_socket_http_get (url, &code, &rlen); + out = rz_socket_http_get (url, &code, &rlen); if (out && rlen > 0) { ut8 *tmp = calloc (1, rlen+1); if (!tmp) { goto beach; } - ret = r_hex_str2bin (out, tmp); + ret = rz_hex_str2bin (out, tmp); memcpy (buf, tmp, R_MIN (count, rlen)); free (tmp); if (ret < 0) { @@ -67,8 +67,8 @@ beach: return ret; } -static int __close(RIODesc *fd) { - RIOR2Web *riom; +static int __close(RzIODesc *fd) { + RzIOR2Web *riom; if (!fd || !fd->data) { return -1; } @@ -78,7 +78,7 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; @@ -87,20 +87,20 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { - const char *uri = "r2web://"; +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { + const char *uri = "rzweb://"; return (!strncmp (pathname, uri, strlen (uri))); } -static inline int getmalfd (RIOR2Web *mal) { +static inline int getmalfd (RzIOR2Web *mal) { return 0xfffffff & (int)(size_t)mal; } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { char *out; int rlen, code; if (__plugin_open (io, pathname, 0)) { - RIOR2Web *mal = R_NEW0 (RIOR2Web); + RzIOR2Web *mal = R_NEW0 (RzIOR2Web); if (!mal) { return NULL; } @@ -111,18 +111,18 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { path[path_len - 1] = 0; } } - char *url = r_str_newf ("http://%s/?V", path); + char *url = rz_str_newf ("http://%s/?V", path); //eprintf ("URL:(%s)\n", url); - out = r_socket_http_get (url, &code, &rlen); + out = rz_socket_http_get (url, &code, &rlen); //eprintf ("RES %d %d\n", code, rlen); //eprintf ("OUT(%s)\n", out); if (out && rlen > 0) { mal->fd = getmalfd (mal); - mal->url = r_str_newf ("http://%s", path); + mal->url = rz_str_newf ("http://%s", path); free (path); free (out); free (url); - return r_io_desc_new (io, &r_io_plugin_r2web, + return rz_io_desc_new (io, &rz_io_plugin_rzweb, pathname, rw, mode, mal); } free (url); @@ -134,14 +134,14 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -static char *__system(RIO *io, RIODesc *fd, const char *command) { +static char *__system(RzIO *io, RzIODesc *fd, const char *command) { if (!*command) { return NULL; } int code, rlen; - char *cmd = r_str_uri_encode (command); - char *url = r_str_newf ("%s/%s", rURL(fd), cmd); - char *out = r_socket_http_get (url, &code, &rlen); + char *cmd = rz_str_uri_encode (command); + char *url = rz_str_newf ("%s/%s", rURL(fd), cmd); + char *out = rz_socket_http_get (url, &code, &rlen); if (out && rlen > 0) { io->cb_printf ("%s", out); } @@ -151,10 +151,10 @@ static char *__system(RIO *io, RIODesc *fd, const char *command) { return NULL; } -RIOPlugin r_io_plugin_r2web = { - .name = "r2web", - .desc = "r2web io client plugin", - .uris = "r2web://", +RzIOPlugin rz_io_plugin_rzweb = { + .name = "rzweb", + .desc = "rzweb io client plugin", + .uris = "rzweb://", .license = "LGPL3", .open = __open, .close = __close, @@ -166,9 +166,9 @@ RIOPlugin r_io_plugin_r2web = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_r2web, + .data = &rz_io_plugin_rzweb, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_self.c b/librz/io/p/io_self.c similarity index 85% rename from libr/io/p/io_self.c rename to librz/io/p/io_self.c index 5363884b6d..467582d173 100644 --- a/libr/io/p/io_self.c +++ b/librz/io/p/io_self.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2014-2016 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #if DEBUGGER #if __APPLE__ @@ -17,7 +17,7 @@ #include #include #include -void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int max); +void macosx_debug_regions (RzIO *io, task_t task, mach_vm_address_t address, int max); #elif __BSD__ #if __FreeBSD__ #include @@ -32,7 +32,7 @@ void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int #include #endif #include -bool bsd_proc_vmmaps(RIO *io, int pid); +bool bsd_proc_vmmaps(RzIO *io, int pid); #endif #ifdef __HAIKU__ #include @@ -52,13 +52,13 @@ typedef struct { ut64 from; ut64 to; int perm; -} RIOSelfSection; +} RzIOSelfSection; -static RIOSelfSection self_sections[1024]; +static RzIOSelfSection self_sections[1024]; static int self_sections_count = 0; static bool mameio = false; -static int self_in_section(RIO *io, ut64 addr, int *left, int *perm) { +static int self_in_section(RzIO *io, ut64 addr, int *left, int *perm) { int i; for (i = 0; i < self_sections_count; i++) { if (addr >= self_sections[i].from && addr < self_sections[i].to) { @@ -74,7 +74,7 @@ static int self_in_section(RIO *io, ut64 addr, int *left, int *perm) { return false; } -static int update_self_regions(RIO *io, int pid) { +static int update_self_regions(RzIO *io, int pid) { self_sections_count = 0; #if __APPLE__ mach_port_t task; @@ -92,7 +92,7 @@ static int update_self_regions(RIO *io, int pid) { char path[1024], line[1024]; char region[100], region2[100], perms[5]; snprintf (path, sizeof (path) - 1, "/proc/%d/maps", pid); - FILE *fd = r_sandbox_fopen (path, "r"); + FILE *fd = rz_sandbox_fopen (path, "r"); if (!fd) { return false; } @@ -126,12 +126,12 @@ static int update_self_regions(RIO *io, int pid) { case 'x': perm |= R_PERM_X; break; } } - self_sections[self_sections_count].from = r_num_get (NULL, region); - self_sections[self_sections_count].to = r_num_get (NULL, region2); + self_sections[self_sections_count].from = rz_num_get (NULL, region); + self_sections[self_sections_count].to = rz_num_get (NULL, region2); self_sections[self_sections_count].name = strdup (path); self_sections[self_sections_count].perm = perm; self_sections_count++; - r_num_get (NULL, region2); + rz_num_get (NULL, region2); } fclose (fd); @@ -244,7 +244,7 @@ static int update_self_regions(RIO *io, int pid) { } self_sections[self_sections_count].from = (ut64) mbi.BaseAddress; self_sections[self_sections_count].to = (ut64) to; - self_sections[self_sections_count].name = r_sys_conv_win_to_utf8 (name); + self_sections[self_sections_count].name = rz_sys_conv_win_to_utf8 (name); self_sections[self_sections_count].perm = perm; self_sections_count++; name[0] = '\0'; @@ -259,25 +259,25 @@ static int update_self_regions(RIO *io, int pid) { #endif } -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return (!strncmp (file, "self://", 7)); } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { int ret, pid = getpid (); - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return NULL; } io->va = true; // nop ret = update_self_regions (io, pid); if (ret) { - return r_io_desc_new (io, &r_io_plugin_self, + return rz_io_desc_new (io, &rz_io_plugin_self, file, rw, mode, NULL); } return NULL; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { int left, perm; if (self_in_section (io, io->off, &left, &perm)) { if (perm & R_PERM_R) { @@ -290,7 +290,7 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { return 0; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { if (fd->perm & R_PERM_W) { int left, perm; if (self_in_section (io, io->off, &left, &perm)) { @@ -305,7 +305,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { return -1; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; @@ -314,7 +314,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return offset; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { return 0; } @@ -325,14 +325,14 @@ static void got_alarm(int sig) { #endif } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { if (!strcmp (cmd, "pid")) { - return r_str_newf ("%d", fd->fd); + return rz_str_newf ("%d", fd->fd); } else if (!strncmp (cmd, "pid", 3)) { /* do nothing here */ #if !defined(__WINDOWS__) } else if (!strncmp (cmd, "kill", 4)) { - if (r_sandbox_enable (false)) { + if (rz_sandbox_enable (false)) { eprintf ("This is unsafe, so disabled by the sandbox\n"); return NULL; } @@ -341,29 +341,29 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { #endif } else if (!strncmp (cmd, "call ", 5)) { size_t cbptr = 0; - if (r_sandbox_enable (false)) { + if (rz_sandbox_enable (false)) { eprintf ("This is unsafe, so disabled by the sandbox\n"); return NULL; } ut64 result = 0; char *argv = strdup (cmd + 5); - int argc = r_str_word_set0 (argv); + int argc = rz_str_word_set0 (argv); if (argc == 0) { eprintf ("Usage: =!call [fcnptr] [a0] [a1] ...\n"); free (argv); return NULL; } - const char *sym = r_str_word_get0 (argv, 0); + const char *sym = rz_str_word_get0 (argv, 0); if (sym) { const char *symbol = cmd + 6; - void *lib = r_lib_dl_open (NULL); - void *ptr = r_lib_dl_sym (lib, symbol); + void *lib = rz_lib_dl_open (NULL); + void *ptr = rz_lib_dl_sym (lib, symbol); if (ptr) { cbptr = (ut64)(size_t)ptr; } else { - cbptr = r_num_math (NULL, symbol); + cbptr = rz_num_math (NULL, symbol); } - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } if (argc == 1) { size_t (*cb)() = (size_t(*)())cbptr; @@ -375,15 +375,15 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else if (argc == 2) { size_t (*cb)(size_t a0) = (size_t(*)(size_t))cbptr; if (cb) { - ut64 a0 = r_num_math (NULL, r_str_word_get0 (argv, 1)); + ut64 a0 = rz_num_math (NULL, rz_str_word_get0 (argv, 1)); result = cb (a0); } else { eprintf ("No callback defined\n"); } } else if (argc == 3) { size_t (*cb)(size_t a0, size_t a1) = (size_t(*)(size_t,size_t))cbptr; - ut64 a0 = r_num_math (NULL, r_str_word_get0 (argv, 1)); - ut64 a1 = r_num_math (NULL, r_str_word_get0 (argv, 2)); + ut64 a0 = rz_num_math (NULL, rz_str_word_get0 (argv, 1)); + ut64 a1 = rz_num_math (NULL, rz_str_word_get0 (argv, 2)); if (cb) { result = cb (a0, a1); } else { @@ -392,9 +392,9 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else if (argc == 4) { size_t (*cb)(size_t a0, size_t a1, size_t a2) = \ (size_t(*)(size_t,size_t,size_t))cbptr; - ut64 a0 = r_num_math (NULL, r_str_word_get0 (argv, 1)); - ut64 a1 = r_num_math (NULL, r_str_word_get0 (argv, 2)); - ut64 a2 = r_num_math (NULL, r_str_word_get0 (argv, 3)); + ut64 a0 = rz_num_math (NULL, rz_str_word_get0 (argv, 1)); + ut64 a1 = rz_num_math (NULL, rz_str_word_get0 (argv, 2)); + ut64 a2 = rz_num_math (NULL, rz_str_word_get0 (argv, 3)); if (cb) { result = cb (a0, a1, a2); } else { @@ -403,10 +403,10 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else if (argc == 5) { size_t (*cb)(size_t a0, size_t a1, size_t a2, size_t a3) = \ (size_t(*)(size_t,size_t,size_t,size_t))cbptr; - ut64 a0 = r_num_math (NULL, r_str_word_get0 (argv, 1)); - ut64 a1 = r_num_math (NULL, r_str_word_get0 (argv, 2)); - ut64 a2 = r_num_math (NULL, r_str_word_get0 (argv, 3)); - ut64 a3 = r_num_math (NULL, r_str_word_get0 (argv, 4)); + ut64 a0 = rz_num_math (NULL, rz_str_word_get0 (argv, 1)); + ut64 a1 = rz_num_math (NULL, rz_str_word_get0 (argv, 2)); + ut64 a2 = rz_num_math (NULL, rz_str_word_get0 (argv, 3)); + ut64 a3 = rz_num_math (NULL, rz_str_word_get0 (argv, 4)); if (cb) { result = cb (a0, a1, a2, a3); } else { @@ -415,11 +415,11 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else if (argc == 6) { size_t (*cb)(size_t a0, size_t a1, size_t a2, size_t a3, size_t a4) = \ (size_t(*)(size_t,size_t,size_t,size_t,size_t))cbptr; - ut64 a0 = r_num_math (NULL, r_str_word_get0 (argv, 1)); - ut64 a1 = r_num_math (NULL, r_str_word_get0 (argv, 2)); - ut64 a2 = r_num_math (NULL, r_str_word_get0 (argv, 3)); - ut64 a3 = r_num_math (NULL, r_str_word_get0 (argv, 4)); - ut64 a4 = r_num_math (NULL, r_str_word_get0 (argv, 5)); + ut64 a0 = rz_num_math (NULL, rz_str_word_get0 (argv, 1)); + ut64 a1 = rz_num_math (NULL, rz_str_word_get0 (argv, 2)); + ut64 a2 = rz_num_math (NULL, rz_str_word_get0 (argv, 3)); + ut64 a3 = rz_num_math (NULL, rz_str_word_get0 (argv, 4)); + ut64 a4 = rz_num_math (NULL, rz_str_word_get0 (argv, 5)); if (cb) { result = cb (a0, a1, a2, a3, a4); } else { @@ -434,11 +434,11 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else if (!strncmp (cmd, "alarm ", 6)) { struct itimerval tmout; int secs = atoi (cmd + 6); - r_return_val_if_fail (secs >= 0, NULL); + rz_return_val_if_fail (secs >= 0, NULL); tmout.it_value.tv_sec = secs; tmout.it_value.tv_usec = 0; - r_sys_signal (SIGALRM, got_alarm); + rz_sys_signal (SIGALRM, got_alarm); setitimer (ITIMER_REAL, &tmout, NULL); #else #ifdef _MSC_VER @@ -449,13 +449,13 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { #endif } else if (!strncmp (cmd, "dlsym ", 6)) { const char *symbol = cmd + 6; - void *lib = r_lib_dl_open (NULL); - void *ptr = r_lib_dl_sym (lib, symbol); + void *lib = rz_lib_dl_open (NULL); + void *ptr = rz_lib_dl_sym (lib, symbol); eprintf ("(%s) 0x%08"PFMT64x"\n", symbol, (ut64)(size_t)ptr); - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else if (!strcmp (cmd, "mameio")) { - void *lib = r_lib_dl_open (NULL); - void *ptr = r_lib_dl_sym (lib, "_ZN12device_debug2goEj"); + void *lib = rz_lib_dl_open (NULL); + void *ptr = rz_lib_dl_sym (lib, "_ZN12device_debug2goEj"); // void *readmem = dlsym (lib, "_ZN23device_memory_interface11memory_readE16address_spacenumjiRy"); // readmem(0, ) if (ptr) { @@ -465,13 +465,13 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } else { eprintf ("This process is not a MAME!"); } - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else if (!strcmp (cmd, "maps")) { int i; for (i = 0; i < self_sections_count; i++) { eprintf ("0x%08"PFMT64x" - 0x%08"PFMT64x" %s %s\n", self_sections[i].from, self_sections[i].to, - r_str_rwx_i (self_sections[i].perm), + rz_str_rwx_i (self_sections[i].perm), self_sections[i].name); } } else { @@ -489,7 +489,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_self = { +RzIOPlugin rz_io_plugin_self = { .name = "self", .desc = "Read memory from self", .uris = "self://", @@ -504,9 +504,9 @@ RIOPlugin r_io_plugin_self = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_mach, + .data = &rz_io_plugin_mach, .version = R2_VERSION }; #endif @@ -522,7 +522,7 @@ kern_return_t mach_vm_region_recurse ( mach_msg_type_number_t *infoCnt ); // TODO: unify that implementation in a single reusable place -void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int max) { +void macosx_debug_regions (RzIO *io, task_t task, mach_vm_address_t address, int max) { kern_return_t kret; struct vm_region_submap_info_64 info; @@ -615,7 +615,7 @@ void macosx_debug_regions (RIO *io, task_t task, mach_vm_address_t address, int } } #elif __BSD__ -bool bsd_proc_vmmaps(RIO *io, int pid) { +bool bsd_proc_vmmaps(RzIO *io, int pid) { #if __FreeBSD__ size_t size; bool ret = false; @@ -661,7 +661,7 @@ bool bsd_proc_vmmaps(RIO *io, int pid) { io->cb_printf (" %p - %p %s (%s)\n", (void *)entry->kve_start, (void *)entry->kve_end, - r_str_rwx_i (perm), + rz_str_rwx_i (perm), entry->kve_path); } @@ -714,7 +714,7 @@ exit: io->cb_printf (" %p - %p %s [off. %zu]\n", (void *)entry.kve_start, (void *)entry.kve_end, - r_str_rwx_i (perm), + rz_str_rwx_i (perm), entry.kve_offset); self_sections[self_sections_count].from = entry.kve_start; @@ -770,7 +770,7 @@ exit: io->cb_printf (" %p - %p %s (%s)\n", (void *)entry->kve_start, (void *)entry->kve_end, - r_str_rwx_i (perm), + rz_str_rwx_i (perm), entry->kve_path); } @@ -829,7 +829,7 @@ exit: io->cb_printf (" %p - %p %s [off. %zu]\n", (void *)entry.ba.start, (void *)entry.ba.end, - r_str_rwx_i (perm), + rz_str_rwx_i (perm), entry.ba.offset); self_sections[self_sections_count].from = entry.ba.start; @@ -846,15 +846,15 @@ exit: #endif #else // DEBUGGER -RIOPlugin r_io_plugin_self = { +RzIOPlugin rz_io_plugin_self = { .name = "self", .desc = "read memory from myself using 'self://' (UNSUPPORTED)", }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_mach, + .data = &rz_io_plugin_mach, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_shm.c b/librz/io/p/io_shm.c similarity index 68% rename from libr/io/p/io_shm.c rename to librz/io/p/io_shm.c index 60dd8d6972..2d564832d8 100644 --- a/libr/io/p/io_shm.c +++ b/librz/io/p/io_shm.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2019 pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #if __ANDROID__ || EMSCRIPTEN @@ -24,14 +24,14 @@ typedef struct { int id; ut8 *buf; ut32 size; -} RIOShm; -#define RIOSHM_FD(x) (((RIOShm*)(x))->fd) +} RzIOShm; +#define RzIOSHM_FD(x) (((RzIOShm*)(x))->fd) #define SHMATSZ 0x9000; // 32*1024*1024; /* 32MB : XXX not used correctly? */ -static int shm__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - r_return_val_if_fail (fd && fd->data, -1); - RIOShm *shm = fd->data; +static int shm__write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + rz_return_val_if_fail (fd && fd->data, -1); + RzIOShm *shm = fd->data; if (shm->buf) { (void)memcpy (shm->buf + io->off, buf, count); return count; @@ -39,9 +39,9 @@ static int shm__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return write (shm->fd, buf, count); } -static int shm__read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - r_return_val_if_fail (fd && fd->data, -1); - RIOShm *shm = fd->data; +static int shm__read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + rz_return_val_if_fail (fd && fd->data, -1); + RzIOShm *shm = fd->data; if (io->off + count >= shm->size) { if (io->off > shm->size) { return -1; @@ -55,12 +55,12 @@ static int shm__read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return read (shm->fd, buf, count); } -static int shm__close(RIODesc *fd) { - r_return_val_if_fail (fd && fd->data, -1); +static int shm__close(RzIODesc *fd) { + rz_return_val_if_fail (fd && fd->data, -1); int ret; - RIOShm *shm = fd->data; + RzIOShm *shm = fd->data; if (shm->buf) { - ret = shmdt (((RIOShm*)(fd->data))->buf); + ret = shmdt (((RzIOShm*)(fd->data))->buf); } else { ret = close (shm->fd); } @@ -68,9 +68,9 @@ static int shm__close(RIODesc *fd) { return ret; } -static ut64 shm__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - r_return_val_if_fail (fd && fd->data, -1); - RIOShm *shm = fd->data; +static ut64 shm__lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + rz_return_val_if_fail (fd && fd->data, -1); + RzIOShm *shm = fd->data; switch (whence) { case SEEK_SET: return io->off = offset; @@ -86,24 +86,24 @@ static ut64 shm__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static bool shm__plugin_open(RIO *io, const char *pathname, bool many) { +static bool shm__plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "shm://", 6)); } -static inline int getshmfd (RIOShm *shm) { +static inline int getshmfd (RzIOShm *shm) { return (((int)(size_t)shm->buf) >> 4) & 0xfff; } -static RIODesc *shm__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *shm__open(RzIO *io, const char *pathname, int rw, int mode) { if (!strncmp (pathname, "shm://", 6)) { - RIOShm *shm = R_NEW0 (RIOShm); + RzIOShm *shm = R_NEW0 (RzIOShm); if (!shm) { return NULL; } const char *ptr = pathname + 6; shm->id = atoi (ptr); if (!shm->id) { - shm->id = r_str_hash (ptr); + shm->id = rz_str_hash (ptr); } shm->buf = shmat (shm->id, 0, 0); if (shm->buf == (void*)(size_t)-1) { @@ -120,7 +120,7 @@ static RIODesc *shm__open(RIO *io, const char *pathname, int rw, int mode) { shm->size = SHMATSZ; if (shm->fd != -1) { eprintf ("Connected to shared memory 0x%08x\n", shm->id); - return r_io_desc_new (io, &r_io_plugin_shm, pathname, rw, mode, shm); + return rz_io_desc_new (io, &rz_io_plugin_shm, pathname, rw, mode, shm); } eprintf ("Cannot connect to shared memory (%d)\n", shm->id); free (shm); @@ -128,7 +128,7 @@ static RIODesc *shm__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_shm = { +RzIOPlugin rz_io_plugin_shm = { .name = "shm", .desc = "Shared memory resources plugin", .uris = "shm://", @@ -142,16 +142,16 @@ RIOPlugin r_io_plugin_shm = { }; #else -RIOPlugin r_io_plugin_shm = { +RzIOPlugin rz_io_plugin_shm = { .name = "shm", .desc = "shared memory resources (not for w32)", }; #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_shm, + .data = &rz_io_plugin_shm, .version = R2_VERSION }; #endif diff --git a/librz/io/p/io_sparse.c b/librz/io/p/io_sparse.c new file mode 100644 index 0000000000..84a2893d95 --- /dev/null +++ b/librz/io/p/io_sparse.c @@ -0,0 +1,129 @@ +/* radare - LGPL - Copyright 2015-2016 - pancake */ + +#include "rz_io.h" +#include "rz_lib.h" +#include "rz_util.h" +#include +#include +#include + +typedef struct { + int fd; + RBuffer *buf; + ut64 offset; +} RzIOSparse; + +#define RzIOSPARSE_FD(x) (((RzIOSparse*)(x)->data)->fd) +#define RzIOSPARSE_BUF(x) (((RzIOSparse*)(x)->data)->buf) +#define RzIOSPARSE_OFF(x) (((RzIOSparse*)(x)->data)->offset) + +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + ut64 o; + RBuffer *b; + if (!fd || !fd->data) { + return -1; + } + b = RzIOSPARSE_BUF(fd); + o = RzIOSPARSE_OFF(fd); + int r = rz_buf_write_at (b, o, buf, count); + if (r >= 0) { + rz_buf_seek (b, r, R_BUF_CUR); + } + return r; +} + +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + ut64 o; + RBuffer *b; + if (!fd || !fd->data) { + return -1; + } + b = RzIOSPARSE_BUF(fd); + o = RzIOSPARSE_OFF(fd); + int r = rz_buf_read_at (b, o, buf, count); + if (r >= 0) { + rz_buf_seek (b, count, R_BUF_CUR); + } + return count; +} + +static int __close(RzIODesc *fd) { + RzIOSparse *riom; + if (!fd || !fd->data) { + return -1; + } + riom = fd->data; + R_FREE (riom->buf); + R_FREE (fd->data); + return 0; +} + +static ut64 __lseek(RzIO* io, RzIODesc *fd, ut64 offset, int whence) { + RBuffer *b; + ut64 rz_offset = offset; + if (!fd->data) { + return offset; + } + b = RzIOSPARSE_BUF(fd); + rz_offset = rz_buf_seek (b, offset, whence); + //if (rz_offset != UT64_MAX) + RzIOSPARSE_OFF (fd) = rz_offset; + return rz_offset; +} + +static bool __plugin_open(struct rz_io_t *io, const char *pathname, bool many) { + return (!strncmp (pathname, "sparse://", 9)); +} + +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { + if (__plugin_open (io, pathname,0)) { + RzIOSparse *mal = R_NEW0 (RzIOSparse); + int size = (int)rz_num_math (NULL, pathname + 9); + mal->buf = rz_buf_new_sparse (io->Oxff); + if (!mal->buf) { + free (mal); + return NULL; + } + if (size > 0) { + ut8 *data = malloc (size); + if (!data) { + eprintf ("Cannot allocate (%s) %d byte(s)\n", + pathname+9, size); + mal->offset = 0; + } else { + memset (data, 0x00, size); + rz_buf_write_at (mal->buf, 0, data, size); + free (data); + } + } + if (mal->buf) { + return rz_io_desc_new (io, &rz_io_plugin_sparse, + pathname, rw, mode, mal); + } + rz_buf_free (mal->buf); + free (mal); + } + return NULL; +} + +RzIOPlugin rz_io_plugin_sparse = { + .name = "sparse", + .desc = "Sparse buffer allocation plugin", + .uris = "sparse://", + .license = "LGPL3", + .open = __open, + .close = __close, + .read = __read, + .check = __plugin_open, + .lseek = __lseek, + .write = __write, + .resize = NULL, +}; + +#ifndef R2_PLUGIN_INCORE +RZ_API RzLibStruct radare_plugin = { + .type = R_LIB_TYPE_IO, + .data = &rz_io_plugin_sparse, + .version = R2_VERSION +}; +#endif diff --git a/libr/io/p/io_tcp.c b/librz/io/p/io_tcp.c similarity index 60% rename from libr/io/p/io_tcp.c rename to librz/io/p/io_tcp.c index 2303b5a2ec..8639484512 100644 --- a/libr/io/p/io_tcp.c +++ b/librz/io/p/io_tcp.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2016 - pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include @@ -10,41 +10,41 @@ typedef struct { int fd; ut8 *buf; ut32 size; -} RIOMalloc; +} RzIOMalloc; -#define RIOTCP_FD(x) (((RIOMalloc*)(x)->data)->fd) -#define RIOTCP_SZ(x) (((RIOMalloc*)(x)->data)->size) -#define RIOTCP_BUF(x) (((RIOMalloc*)(x)->data)->buf) +#define RzIOTCP_FD(x) (((RzIOMalloc*)(x)->data)->fd) +#define RzIOTCP_SZ(x) (((RzIOMalloc*)(x)->data)->size) +#define RzIOTCP_BUF(x) (((RzIOMalloc*)(x)->data)->buf) -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !fd->data) { return -1; } - if (io->off + count > RIOTCP_SZ (fd)) { + if (io->off + count > RzIOTCP_SZ (fd)) { return -1; } - memcpy (RIOTCP_BUF (fd)+io->off, buf, count); + memcpy (RzIOTCP_BUF (fd)+io->off, buf, count); return count; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { unsigned int sz; if (!fd || !fd->data) { return -1; } - sz = RIOTCP_SZ (fd); + sz = RzIOTCP_SZ (fd); if (io->off >= sz) { return -1; } if (io->off + count >= sz) { count = sz - io->off; } - memcpy (buf, RIOTCP_BUF (fd) + io->off, count); + memcpy (buf, RzIOTCP_BUF (fd) + io->off, count); return count; } -static int __close(RIODesc *fd) { - RIOMalloc *riom; +static int __close(RzIODesc *fd) { + RzIOMalloc *riom; if (!fd || !fd->data) { return -1; } @@ -54,20 +54,20 @@ static int __close(RIODesc *fd) { return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case SEEK_SET: return offset; case SEEK_CUR: return io->off + offset; - case SEEK_END: return RIOTCP_SZ (fd); + case SEEK_END: return RzIOTCP_SZ (fd); } return offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "tcp://", 6)); } -static inline int getmalfd (RIOMalloc *mal) { +static inline int getmalfd (RzIOMalloc *mal) { return (UT32_MAX >> 1) & (int)(size_t)mal->buf; } @@ -75,20 +75,20 @@ static ut8 *tcpme (const char *pathname, int *code, int *len) { pathname += 6; *code = 404; #if __UNIX__ - r_sys_signal (SIGINT, SIG_IGN); + rz_sys_signal (SIGINT, SIG_IGN); #endif if (*pathname == ':') { /* listen and wait for connection */ - RSocket *sl = r_socket_new (false); - if (!r_socket_listen (sl, pathname + 1, NULL)) { + RzSocket *sl = rz_socket_new (false); + if (!rz_socket_listen (sl, pathname + 1, NULL)) { eprintf ("Cannot listen\n"); - r_socket_free (sl); + rz_socket_free (sl); return NULL; } - RSocket *sc = r_socket_accept (sl); - ut8 *res = r_socket_slurp (sc, len); - r_socket_free (sc); - r_socket_free (sl); + RzSocket *sc = rz_socket_accept (sl); + ut8 *res = rz_socket_slurp (sc, len); + rz_socket_free (sc); + rz_socket_free (sl); if (res) { *code = 200; return res; @@ -102,19 +102,19 @@ static ut8 *tcpme (const char *pathname, int *code, int *len) { char *port = strchr (host, ':'); if (port) { *port++ = 0; - RSocket *s = r_socket_new (false); - if (r_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { - ut8 *res = r_socket_slurp (s, len); + RzSocket *s = rz_socket_new (false); + if (rz_socket_connect (s, host, port, R_SOCKET_PROTO_TCP, 0)) { + ut8 *res = rz_socket_slurp (s, len); if (*len < 1) { R_FREE (res); } else { *code = 200; } - r_socket_free (s); + rz_socket_free (s); free (host); return res; } - r_socket_free (s); + rz_socket_free (s); } else { eprintf ("Missing port.\n"); } @@ -123,13 +123,13 @@ static ut8 *tcpme (const char *pathname, int *code, int *len) { return NULL; } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { ut8 *out; int rlen, code; if (__plugin_open (io, pathname, 0)) { out = tcpme (pathname, &code, &rlen); if (out && rlen > 0) { - RIOMalloc *mal = R_NEW0 (RIOMalloc); + RzIOMalloc *mal = R_NEW0 (RzIOMalloc); if (!mal) { free (out); return NULL; @@ -146,7 +146,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { memcpy (mal->buf, out, mal->size); free (out); rw = 7; - return r_io_desc_new (io, &r_io_plugin_tcp, + return rz_io_desc_new (io, &rz_io_plugin_tcp, pathname, rw, mode, mal); } eprintf ("Cannot allocate (%s) %d byte(s)\n", pathname + 9, mal->size); @@ -157,7 +157,7 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { return NULL; } -RIOPlugin r_io_plugin_tcp = { +RzIOPlugin rz_io_plugin_tcp = { .name = "tcp", .desc = "Load files via TCP (listen or connect)", .uris = "tcp://", @@ -171,9 +171,9 @@ RIOPlugin r_io_plugin_tcp = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_tcp, + .data = &rz_io_plugin_tcp, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_w32.c b/librz/io/p/io_w32.c similarity index 53% rename from libr/io/p/io_w32.c rename to librz/io/p/io_w32.c index ef5140d43c..63a6e65f4a 100644 --- a/libr/io/p/io_w32.c +++ b/librz/io/p/io_w32.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2008-2011 pancake */ -#include "r_io.h" -#include "r_lib.h" +#include "rz_io.h" +#include "rz_lib.h" #if __WINDOWS__ #include @@ -9,24 +9,24 @@ typedef struct { HANDLE hnd; ut64 winbase; -} RIOW32; -#define RIOW32_HANDLE(x) (((RIOW32*)x)->hnd) +} RzIOW32; +#define RzIOW32_HANDLE(x) (((RzIOW32*)x)->hnd) -static int w32__write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int w32__write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !fd->data) return -1; - return WriteFile (RIOW32_HANDLE (fd), buf, count, NULL, NULL); + return WriteFile (RzIOW32_HANDLE (fd), buf, count, NULL, NULL); } -static int w32__read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int w32__read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { DWORD ret; - return ReadFile (RIOW32_HANDLE (fd), buf, count, &ret, NULL)?ret:-1; + return ReadFile (RzIOW32_HANDLE (fd), buf, count, &ret, NULL)?ret:-1; } -static int w32__close(RIODesc *fd) { +static int w32__close(RzIODesc *fd) { if (fd->data) { // TODO: handle return value - CloseHandle (RIOW32_HANDLE (fd)); + CloseHandle (RzIOW32_HANDLE (fd)); R_FREE (fd->data); return 0; } @@ -34,45 +34,45 @@ static int w32__close(RIODesc *fd) { } // TODO: handle filesize and so on -static ut64 w32__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - SetFilePointer (RIOW32_HANDLE (fd), offset, 0, !whence?FILE_BEGIN:whence==1?FILE_CURRENT:FILE_END); +static ut64 w32__lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + SetFilePointer (RzIOW32_HANDLE (fd), offset, 0, !whence?FILE_BEGIN:whence==1?FILE_CURRENT:FILE_END); return (!whence)?offset:whence==1?io->off+offset:ST64_MAX; } -static bool w32__plugin_open(RIO *io, const char *pathname, bool many) { +static bool w32__plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "w32://", 6)); } -static RIODesc *w32__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *w32__open(RzIO *io, const char *pathname, int rw, int mode) { if (!strncmp (pathname, "w32://", 6)) { - RIOW32 *w32 = R_NEW0 (RIOW32); + RzIOW32 *w32 = R_NEW0 (RzIOW32); if (!w32) { return NULL; } const char *filename = pathname + 6; - LPTSTR filename_ = r_sys_conv_utf8_to_win (filename); + LPTSTR filename_ = rz_sys_conv_utf8_to_win (filename); w32->hnd = CreateFile (filename_, GENERIC_READ | (rw ? GENERIC_WRITE : 0), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); free (filename_); if (w32->hnd != INVALID_HANDLE_VALUE) - return r_io_desc_new (io, &r_io_plugin_w32, + return rz_io_desc_new (io, &rz_io_plugin_w32, pathname, rw, mode, w32); free (w32); } return NULL; } -static char *w32__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *w32__system(RzIO *io, RzIODesc *fd, const char *cmd) { if (io && fd && fd->data && cmd && !strcmp (cmd, "winbase")) { - RIOW32 *w32 = (RIOW32 *)fd->data; + RzIOW32 *w32 = (RzIOW32 *)fd->data; io->cb_printf ("%"PFMT64u , w32->winbase); } return NULL; } -RIOPlugin r_io_plugin_w32 = { +RzIOPlugin rz_io_plugin_w32 = { .name = "w32", .desc = "w32 API io", .license = "LGPL3", @@ -87,15 +87,15 @@ RIOPlugin r_io_plugin_w32 = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_w32, + .data = &rz_io_plugin_w32, .version = R2_VERSION }; #endif #else -struct r_io_plugin_t r_io_plugin_w32 = { +struct rz_io_plugin_t rz_io_plugin_w32 = { .name = (void*)0 }; diff --git a/libr/io/p/io_w32dbg.c b/librz/io/p/io_w32dbg.c similarity index 84% rename from libr/io/p/io_w32dbg.c rename to librz/io/p/io_w32dbg.c index 03503275b1..4448a5f3b6 100644 --- a/libr/io/p/io_w32dbg.c +++ b/librz/io/p/io_w32dbg.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2008-2016 - pancake */ -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include #if __WINDOWS__ @@ -76,7 +76,7 @@ static int debug_os_read_at(W32DbgWInst *dbg, ut8 *buf, int len, ut64 addr) { return len; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int len) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) { return debug_os_read_at (fd->data, buf, len, io->off); } @@ -85,11 +85,11 @@ static int w32dbg_write_at(W32DbgWInst *dbg, const ut8 *buf, int len, ut64 addr) return 0 != WriteProcessMemory (dbg->pi.hProcess, (void *)(size_t)addr, buf, len, &ret)? len: 0; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) { return w32dbg_write_at (fd->data, buf, len, io->off); } -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { if (!strncmp (file, "attach://", 9)) { return true; } @@ -124,7 +124,7 @@ static int __w32_first_thread(int pid) { thid = r2_OpenThread ? r2_OpenThread (THREAD_ALL_ACCESS, 0, te32.th32ThreadID) : NULL; if (!thid) { - r_sys_perror ("__w32_first_thread/OpenThread"); + rz_sys_perror ("__w32_first_thread/OpenThread"); goto err_first_th; } CloseHandle (th); @@ -137,7 +137,7 @@ err_first_th: return pid; } -static int __open_proc(RIO *io, int pid, bool attach) { +static int __open_proc(RzIO *io, int pid, bool attach) { DEBUG_EVENT de; int ret = -1; if (!io->w32dbg_wrap) { @@ -147,7 +147,7 @@ static int __open_proc(RIO *io, int pid, bool attach) { HANDLE h_proc = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid); if (!h_proc) { - r_sys_perror ("__open_proc/OpenProcess"); + rz_sys_perror ("__open_proc/OpenProcess"); goto att_exit; } W32DbgWInst *wrap = (W32DbgWInst *)io->w32dbg_wrap; @@ -158,7 +158,7 @@ static int __open_proc(RIO *io, int pid, bool attach) { w32dbg_wrap_wait_ret (wrap); if (!w32dbgw_ret (wrap)) { w32dbgw_err (wrap); - r_sys_perror ("__open_proc/DebugActiveProcess"); + rz_sys_perror ("__open_proc/DebugActiveProcess"); goto att_exit; } /* catch create process event */ @@ -168,7 +168,7 @@ static int __open_proc(RIO *io, int pid, bool attach) { w32dbg_wrap_wait_ret (wrap); if (!w32dbgw_ret (wrap)) { w32dbgw_err (wrap); - r_sys_perror ("__open_proc/WaitForDebugEvent"); + rz_sys_perror ("__open_proc/WaitForDebugEvent"); goto att_exit; } if (de.dwDebugEventCode != CREATE_PROCESS_DEBUG_EVENT) { @@ -188,9 +188,9 @@ att_exit: return ret; } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { if (__plugin_open (io, file, 0)) { - RIODesc *ret; + RzIODesc *ret; if (__open_proc (io, atoi (file + 9), !strncmp (file, "attach://", 9)) == -1) { return NULL; } @@ -201,15 +201,15 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { if (!wrap->pi.hThread) { wrap->pi.hThread = OpenThread (THREAD_ALL_ACCESS, FALSE, wrap->pi.dwThreadId); } - ret = r_io_desc_new (io, &r_io_plugin_w32dbg, + ret = rz_io_desc_new (io, &rz_io_plugin_w32dbg, file, rw | R_PERM_X, mode, wrap); - ret->name = r_sys_pid_to_path (wrap->pi.dwProcessId); + ret->name = rz_sys_pid_to_path (wrap->pi.dwProcessId); return ret; } return NULL; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case 0: // abs io->off = offset; @@ -224,8 +224,8 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static int __close(RIODesc *fd) { - if (r_str_startswith (fd->uri, "attach://")) { +static int __close(RzIODesc *fd) { + if (rz_str_startswith (fd->uri, "attach://")) { W32DbgWInst *wrap = fd->data; wrap->params.type = W32_DETACH; w32dbg_wrap_wait_ret (wrap); @@ -233,7 +233,7 @@ static int __close(RIODesc *fd) { return false; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { W32DbgWInst *wrap = fd->data; //printf("w32dbg io command (%s)\n", cmd); /* XXX ugly hack for testing purposes */ @@ -249,14 +249,14 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { } } } - return r_str_newf ("%d", wrap->pi.dwProcessId); + return rz_str_newf ("%d", wrap->pi.dwProcessId); } else { eprintf ("Try: '=!pid'\n"); } return NULL; } -static int __getpid(RIODesc *fd) { +static int __getpid(RzIODesc *fd) { W32DbgWInst *wrap = (W32DbgWInst *)(fd ? fd->data : NULL); if (!wrap) { return -1; @@ -264,12 +264,12 @@ static int __getpid(RIODesc *fd) { return wrap->pi.dwProcessId; } -static int __gettid(RIODesc *fd) { +static int __gettid(RzIODesc *fd) { W32DbgWInst *wrap = (W32DbgWInst *)(fd ? fd->data : NULL); return wrap? wrap->pi.dwThreadId: -1; } -static bool __getbase(RIODesc *fd, ut64 *base) { +static bool __getbase(RzIODesc *fd, ut64 *base) { W32DbgWInst *wrap = (W32DbgWInst *)(fd ? fd->data : NULL); if (base && wrap) { *base = wrap->winbase; @@ -278,7 +278,7 @@ static bool __getbase(RIODesc *fd, ut64 *base) { return false; } -RIOPlugin r_io_plugin_w32dbg = { +RzIOPlugin rz_io_plugin_w32dbg = { .name = "w32dbg", .desc = "w32 debugger io plugin", .license = "LGPL3", @@ -296,15 +296,15 @@ RIOPlugin r_io_plugin_w32dbg = { .isdbg = true }; #else -RIOPlugin r_io_plugin_w32dbg = { +RzIOPlugin rz_io_plugin_w32dbg = { .name = NULL }; #endif #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_w32dbg, + .data = &rz_io_plugin_w32dbg, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_windbg.c b/librz/io/p/io_windbg.c similarity index 90% rename from libr/io/p/io_windbg.c rename to librz/io/p/io_windbg.c index 18672f3dd3..001e2af6f6 100644 --- a/libr/io/p/io_windbg.c +++ b/librz/io/p/io_windbg.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2020 - GustavoLCR */ #define INITGUID -#include +#include #include typedef HRESULT (__stdcall *DebugCreate_t)( @@ -155,9 +155,9 @@ static STDMETHODIMP __input_cb(PDEBUG_INPUT_CALLBACKS This, ULONG BufferSize) { PDEBUG_INPUT_CALLBACKS_IMPL impl = (PDEBUG_INPUT_CALLBACKS_IMPL)This; DbgEngContext *idbg = impl->m_idbg; ITHISCALL (dbgCtrl, GetPromptText, prompt, sizeof (prompt), NULL); - r_line_set_prompt (prompt); - const char *str = r_line_readline (); - char *ret = r_str_ndup (str, R_MIN (strlen (str), BufferSize)); + rz_line_set_prompt (prompt); + const char *str = rz_line_readline (); + char *ret = rz_str_ndup (str, R_MIN (strlen (str), BufferSize)); ITHISCALL (dbgCtrl, ReturnInput, ret); return S_OK; } @@ -267,7 +267,7 @@ static DbgEngContext *create_remote_context(const char *opts) { return false; } - LPWSTR wopts = (LPWSTR)r_utf8_to_utf16 (opts); + LPWSTR wopts = (LPWSTR)rz_utf8_to_utf16 (opts); // Initialize interfaces if (w32_DebugConnectWide (wopts, &IID_IDebugClient5, &idbg->dbgClient) != S_OK) { @@ -344,12 +344,12 @@ static int windbg_init(void) { if (w32_DebugCreate && w32_DebugConnectWide) { return 1; } - char *ext_path = r_sys_getenv ("_NT_DEBUGGER_EXTENSION_PATH"); + char *ext_path = rz_sys_getenv ("_NT_DEBUGGER_EXTENSION_PATH"); HANDLE h = NULL; if (R_STR_ISNOTEMPTY (ext_path)) { char *s = strtok (ext_path, ";"); do { - PWCHAR dir = r_utf8_to_utf16 (s); + PWCHAR dir = rz_utf8_to_utf16 (s); SetDllDirectoryW (dir); free (dir); h = LoadLibrary (TEXT ("dbgeng.dll")); @@ -361,26 +361,26 @@ static int windbg_init(void) { h = LoadLibrary (TEXT ("dbgeng.dll")); } if (!h) { - r_sys_perror ("LoadLibrary (\"dbgeng.dll\")"); + rz_sys_perror ("LoadLibrary (\"dbgeng.dll\")"); return 0; } w32_DebugCreate = (DebugCreate_t)GetProcAddress (h, "DebugCreate"); if (!w32_DebugCreate) { - r_sys_perror ("GetProcAddress (\"DebugCreate\")"); + rz_sys_perror ("GetProcAddress (\"DebugCreate\")"); return 0; } w32_DebugConnectWide = (DebugConnectWide_t)GetProcAddress (h, "DebugConnectWide"); if (!w32_DebugConnectWide) { - r_sys_perror ("GetProcAddress (\"DebugConnectWide\")"); + rz_sys_perror ("GetProcAddress (\"DebugConnectWide\")"); return 0; } return 1; } -static bool windbg_check(RIO *io, const char *uri, bool many) { +static bool windbg_check(RzIO *io, const char *uri, bool many) { return !strncmp (uri, WINDBGURI, strlen (WINDBGURI)); } @@ -392,7 +392,7 @@ typedef enum { TARGET_KERNEL, } DbgEngTarget; -static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { +static RzIODesc *windbg_open(RzIO *io, const char *uri, int perm, int mode) { if (!windbg_check (io, uri, 0)) { return NULL; } @@ -400,11 +400,11 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { return NULL; } HRESULT hr = E_FAIL; - RIODesc *fd = NULL; - RCore *core = io->corebind.core; + RzIODesc *fd = NULL; + RzCore *core = io->corebind.core; DbgEngContext *idbg = NULL; const char *args = uri + strlen (WINDBGURI); - if (r_str_startswith (args, "-remote")) { + if (rz_str_startswith (args, "-remote")) { args += strlen ("-remote") + 1; idbg = create_remote_context (args); if (idbg) { @@ -412,7 +412,7 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { } } else { idbg = create_context (); - if (idbg && r_str_startswith (args, "-premote")) { + if (idbg && rz_str_startswith (args, "-premote")) { args += strlen ("-premote") + 1; if (FAILED (ITHISCALL (dbgClient, ConnectProcessServer, args, &idbg->server))) { __free_context (idbg); @@ -429,12 +429,12 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { ITHISCALL (dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_ALLOW_READ_ONLY_BREAKPOINTS); ITHISCALL (dbgCtrl, SetCodeLevel, DEBUG_LEVEL_ASSEMBLY); int argc; - char **argv = r_str_argv (args, &argc); + char **argv = rz_str_argv (args, &argc); const size_t argv_sz = sizeof (char *) * ((size_t)argc + 2); char **tmp = realloc (argv, argv_sz); if (!tmp) { __free_context (idbg); - r_str_argv_free (argv); + rz_str_argv_free (argv); return NULL; } argv = tmp; @@ -448,9 +448,9 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { DWORD attach_options = DEBUG_ATTACH_DEFAULT; DWORD pid = 0; int c; - RGetopt opt; - r_getopt_init (&opt, argc, argv, "c:dgGh:i:k:op:y:z:"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "c:dgGh:i:k:op:y:z:"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'c': command = opt.arg; @@ -488,7 +488,7 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { spawn_options |= DEBUG_PROCESS; break; case 'p': - if (r_str_isnumber (opt.arg)) { + if (rz_str_isnumber (opt.arg)) { target = TARGET_LOCAL_ATTACH; pid = atoi (opt.arg); } else { @@ -517,21 +517,21 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { const char *store = io->corebind.cfgGet (core, "pdb.symstore"); const char *server = io->corebind.cfgGet (core, "pdb.server"); char *s = strdup (server); - r_str_replace_ch (s, ';', '*', true); - char *sympath = r_str_newf ("cache*;srv*%s*%s", store, s); + rz_str_replace_ch (s, ';', '*', true); + char *sympath = rz_str_newf ("cache*;srv*%s*%s", store, s); ITHISCALL (dbgSymbols, SetSymbolPath, sympath); free (s); free (sympath); } if (!image_path_set) { - char *path = r_sys_getenv ("PATH"); + char *path = rz_sys_getenv ("PATH"); ITHISCALL (dbgSymbols, AppendImagePath, path); free (path); } switch (target) { case TARGET_LOCAL_SPAWN: if (argv[opt.ind]) { - char *cmd = r_str_format_msvc_argv ((size_t)opt.argc - opt.ind, argv + opt.ind); + char *cmd = rz_str_format_msvc_argv ((size_t)opt.argc - opt.ind, argv + opt.ind); hr = ITHISCALL (dbgClient, CreateProcess, 0ULL, cmd, spawn_options); free (cmd); } else { @@ -556,7 +556,7 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { break; } if (hr != S_OK) { - r_str_argv_free (argv); + rz_str_argv_free (argv); __free_context (idbg); return NULL; } @@ -564,16 +564,16 @@ static RIODesc *windbg_open(RIO *io, const char *uri, int perm, int mode) { if (command) { ITHISCALL (dbgCtrl, Execute, DEBUG_OUTCTL_ALL_CLIENTS, command, DEBUG_EXECUTE_DEFAULT); } - r_str_argv_free (argv); + rz_str_argv_free (argv); remote_client: - fd = r_io_desc_new (io, &r_io_plugin_windbg, uri, perm | R_PERM_X, mode, idbg); + fd = rz_io_desc_new (io, &rz_io_plugin_windbg, uri, perm | R_PERM_X, mode, idbg); fd->name = strdup (args); core->dbg->user = idbg; io->corebind.cmd (io->corebind.core, "dL windbg"); return fd; } -static int windbg_close(RIODesc *fd) { +static int windbg_close(RzIODesc *fd) { DbgEngContext *idbg = fd->data; if (idbg->server) { ITHISCALL (dbgClient, EndSession, DEBUG_END_DISCONNECT); @@ -586,7 +586,7 @@ static int windbg_close(RIODesc *fd) { return 1; } -static ut64 windbg_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 windbg_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: io->off = offset; @@ -601,7 +601,7 @@ static ut64 windbg_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return io->off; } -static int windbg_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int windbg_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { DbgEngContext *idbg = fd->data; ULONG bytesRead = 0ULL; if (FAILED (ITHISCALL (dbgData, ReadVirtual, io->off, (PVOID)buf, count, &bytesRead))) { @@ -619,14 +619,14 @@ static int windbg_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return bytesRead; } -static int windbg_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int windbg_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { DbgEngContext *idbg = fd->data; ULONG bytesWritten = 0ULL; ITHISCALL (dbgData, WriteVirtual, io->off, (PVOID)buf, count, &bytesWritten); return bytesWritten; } -static int windbg_getpid(RIODesc *fd) { +static int windbg_getpid(RzIODesc *fd) { DbgEngContext *idbg = fd->data; ULONG Id = 0, Class, Qualifier; if (SUCCEEDED (ITHISCALL (dbgCtrl, GetDebuggeeType, &Class, &Qualifier))) { @@ -639,7 +639,7 @@ static int windbg_getpid(RIODesc *fd) { return Id; } -static int windbg_gettid(RIODesc *fd) { +static int windbg_gettid(RzIODesc *fd) { DbgEngContext *idbg = fd->data; ULONG Id = 0, Class, Qualifier; if (SUCCEEDED (ITHISCALL (dbgCtrl, GetDebuggeeType, &Class, &Qualifier))) { @@ -652,13 +652,13 @@ static int windbg_gettid(RIODesc *fd) { return Id; } -static bool windbg_getbase(RIODesc *fd, ut64 *base) { +static bool windbg_getbase(RzIODesc *fd, ut64 *base) { DbgEngContext *idbg = fd->data; *base = idbg->processBase; return true; } -static char *windbg_system(RIO *io, RIODesc *fd, const char *cmd) { +static char *windbg_system(RzIO *io, RzIODesc *fd, const char *cmd) { DbgEngContext *idbg = fd->data; if (R_STR_ISEMPTY (cmd) || !strncmp ("pid", cmd, 3)) { return NULL; @@ -667,7 +667,7 @@ static char *windbg_system(RIO *io, RIODesc *fd, const char *cmd) { return NULL; } -RIOPlugin r_io_plugin_windbg = { +RzIOPlugin rz_io_plugin_windbg = { .name = "windbg", .desc = "WinDBG (DbgEng.dll) based io plugin for Windows", .license = "LGPL3", @@ -687,9 +687,9 @@ RIOPlugin r_io_plugin_windbg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_windbg, + .data = &rz_io_plugin_windbg, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_winedbg.c b/librz/io/p/io_winedbg.c similarity index 81% rename from libr/io/p/io_winedbg.c rename to librz/io/p/io_winedbg.c index a72ddea125..a3065a30b4 100644 --- a/libr/io/p/io_winedbg.c +++ b/librz/io/p/io_winedbg.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2017-2019 - pancake */ -#include "r_types_base.h" -#include "r_io.h" -#include "r_lib.h" +#include "rz_types_base.h" +#include "rz_io.h" +#include "rz_lib.h" #include #include #include -static RSocket *gs = NULL; +static RzSocket *gs = NULL; R_PACKED (struct winedbg_x86_32 { ut16 cs; @@ -32,29 +32,29 @@ R_PACKED (struct winedbg_x86_32 { static char *runcmd(const char *cmd) { char buf[4096] = {0}; if (cmd) { - r_socket_printf (gs, "%s\n", cmd); + rz_socket_printf (gs, "%s\n", cmd); } int timeout = 1000000; char *str = NULL; - r_socket_block_time (gs, 1, timeout, 0); + rz_socket_block_time (gs, 1, timeout, 0); while (true) { memset (buf, 0, sizeof (buf)); - int rc = r_socket_read (gs, (ut8*)buf, sizeof (buf) - 1); // NULL-terminate the string always + int rc = rz_socket_read (gs, (ut8*)buf, sizeof (buf) - 1); // NULL-terminate the string always if (rc == -1) { break; } char *promptFound = strstr (buf, "Wine-dbg>"); if (promptFound) { *promptFound = 0; - return r_str_append (str, buf); + return rz_str_append (str, buf); } - str = r_str_append (str, buf); + str = rz_str_append (str, buf); } free (str); return NULL; } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd || !fd->data) { return -1; } @@ -64,7 +64,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { int words = count / wordSize; // XXX must pad align to 4 for (i = 0; i < words ; i++) { ut64 addr = io->off + (i * wordSize); - char *cmd = r_str_newf ("set *0x%"PFMT64x" = 0x%x", addr, w[i]); + char *cmd = rz_str_newf ("set *0x%"PFMT64x" = 0x%x", addr, w[i]); free (runcmd (cmd)); free (cmd); } @@ -74,14 +74,14 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { ut32 leftW = -1; memcpy (&leftW, w + words, left); ut64 addr = io->off + (words * wordSize); - char *cmd = r_str_newf ("set *0x%"PFMT64x" = 0x%x", addr, leftW); + char *cmd = rz_str_newf ("set *0x%"PFMT64x" = 0x%x", addr, leftW); free (runcmd (cmd)); free (cmd); } return count; } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { if (!fd || !fd->data) { return -1; } @@ -109,7 +109,7 @@ Wine-dbg> int words = count / wordSize; // XXX must pad align to 4 for (i = 0; i < words ; i++) { ut64 addr = io->off + (i * wordSize); - char *cmd = r_str_newf ("x 0x%"PFMT64x, addr); + char *cmd = rz_str_newf ("x 0x%"PFMT64x, addr); char *res = runcmd (cmd); if (res) { sscanf (res, "%x", &w[i]); @@ -123,7 +123,7 @@ Wine-dbg> ut32 n = 0xff; ut8 *wn = (ut8*)&n; ut64 addr = io->off + (i * wordSize); - char *cmd = r_str_newf ("x 0x%"PFMT64x, addr); + char *cmd = rz_str_newf ("x 0x%"PFMT64x, addr); char *res = runcmd (cmd); sscanf (res, "%x", &n); free (res); @@ -133,16 +133,16 @@ Wine-dbg> return count; } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { if (!fd || !fd->data) { return -1; } // XXX - r_sys_cmdf ("pkill rarun2"); + rz_sys_cmdf ("pkill rz_run"); return 0; } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: io->off = offset; @@ -157,18 +157,18 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { return offset; } -static bool __plugin_open(RIO *io, const char *pathname, bool many) { +static bool __plugin_open(RzIO *io, const char *pathname, bool many) { return (!strncmp (pathname, "winedbg://", 10)); } -static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *pathname, int rw, int mode) { if (__plugin_open (io, pathname, 0)) { if (gs) { return NULL; } - gs = r_socket_new (0); - char *cmd = r_str_newf ("winedbg '%s'", pathname + 10); - int res = r_socket_spawn (gs, cmd, 1000); + gs = rz_socket_new (0); + char *cmd = rz_str_newf ("winedbg '%s'", pathname + 10); + int res = rz_socket_spawn (gs, cmd, 1000); free (cmd); if (!res) { return NULL; @@ -178,14 +178,14 @@ static RIODesc *__open(RIO *io, const char *pathname, int rw, int mode) { int rw = 7; free (reply); eprintf ("Wine-dbg is ready to go!\n"); - return r_io_desc_new (io, &r_io_plugin_winedbg, pathname, rw, mode, gs); + return rz_io_desc_new (io, &rz_io_plugin_winedbg, pathname, rw, mode, gs); } eprintf ("Can't find the Wine-dbg prompt\n"); } return NULL; } -static void printcmd (RIO *io, const char *cmd) { +static void printcmd (RzIO *io, const char *cmd) { char *res = runcmd (cmd); io->cb_printf ("%s\n", res); free (res); @@ -227,7 +227,7 @@ static struct winedbg_x86_32 regState(void) { return r; } -static char *__system(RIO *io, RIODesc *fd, const char *cmd) { +static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) { if (!strcmp (cmd, "")) { return NULL; } @@ -245,7 +245,7 @@ static char *__system(RIO *io, RIODesc *fd, const char *cmd) { struct winedbg_x86_32 r = regState (); ut8 *arena = (ut8*)calloc (3, sizeof (struct winedbg_x86_32)); if (arena) { - r_hex_bin2str ((ut8*)&r, sizeof (r), (char *)arena); + rz_hex_bin2str ((ut8*)&r, sizeof (r), (char *)arena); return (char *)arena; } } else if (!strncmp (cmd, "drp", 3)) { @@ -315,7 +315,7 @@ const char *msg = } else if (!strncmp (cmd, "dr", 2)) { printcmd (io, "info reg"); } else if (!strncmp (cmd, "db ", 3)) { - free (runcmd (sdb_fmt ("break *%x", r_num_get (NULL, cmd + 3) || io->off))); + free (runcmd (sdb_fmt ("break *%x", rz_num_get (NULL, cmd + 3) || io->off))); } else if (!strncmp (cmd, "ds", 2)) { free (runcmd ("stepi")); } else if (!strncmp (cmd, "dc", 2)) { @@ -344,10 +344,10 @@ const char *msg = } sscanf (ptr, "%08"PFMT64x" %08"PFMT64x, &from, &to); } - char *row = r_str_newf ("0x%08"PFMT64x" - 0x%08" PFMT64x" %s %s\n", from, to, perm, ""); + char *row = rz_str_newf ("0x%08"PFMT64x" - 0x%08" PFMT64x" %s %s\n", from, to, perm, ""); ptr = nl; if (row) { - res = r_str_append (res, row); + res = rz_str_append (res, row); free (row); } } @@ -355,14 +355,14 @@ const char *msg = return res; } } else if (!strncmp (cmd, "pid", 3)) { - return r_str_newf ("%d", fd->fd); + return rz_str_newf ("%d", fd->fd); } else { printcmd (io, cmd); } return NULL; } -RIOPlugin r_io_plugin_winedbg = { +RzIOPlugin rz_io_plugin_winedbg = { .name = "winedbg", .desc = "Wine-dbg io and debug.io plugin", .uris = "winedbg://", @@ -378,9 +378,9 @@ RIOPlugin r_io_plugin_winedbg = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_winedbg, + .data = &rz_io_plugin_winedbg, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_winkd.c b/librz/io/p/io_winkd.c similarity index 79% rename from libr/io/p/io_winkd.c rename to librz/io/p/io_winkd.c index debbe15ac1..1a39542713 100644 --- a/libr/io/p/io_winkd.c +++ b/librz/io/p/io_winkd.c @@ -13,18 +13,18 @@ // You should have received a copy of the GNU Lesser General Public // License along with this library. -#include -#include -#include -#include +#include +#include +#include +#include #include #include -static bool __plugin_open(RIO *io, const char *file, bool many) { +static bool __plugin_open(RzIO *io, const char *file, bool many) { return (!strncmp (file, "winkd://", 8)); } -static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { +static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) { if (!__plugin_open (io, file, 0)) { return NULL; } @@ -61,10 +61,10 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) { eprintf ("Failed to initialize winkd context\n"); return NULL; } - return r_io_desc_new (io, &r_io_plugin_winkd, file, rw, mode, ctx); + return rz_io_desc_new (io, &rz_io_plugin_winkd, file, rw, mode, ctx); } -static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { +static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { if (!fd) { return -1; } @@ -74,7 +74,7 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { return winkd_write_at (fd->data, buf, io->off, count); } -static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { +static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { switch (whence) { case R_IO_SEEK_SET: return io->off = offset; @@ -87,7 +87,7 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { } } -static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { +static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { if (!fd) { return -1; } @@ -99,12 +99,12 @@ static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { return winkd_read_at (fd->data, buf, io->off, count); } -static int __close(RIODesc *fd) { +static int __close(RzIODesc *fd) { winkd_ctx_free ((WindCtx**)&fd->data); return true; } -RIOPlugin r_io_plugin_winkd = { +RzIOPlugin rz_io_plugin_winkd = { .name = "winkd", .desc = "Attach to a KD debugger", .uris = "winkd://", @@ -119,9 +119,9 @@ RIOPlugin r_io_plugin_winkd = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_winkd, + .data = &rz_io_plugin_winkd, .version = R2_VERSION }; #endif diff --git a/libr/io/p/io_zip.c b/librz/io/p/io_zip.c similarity index 63% rename from libr/io/p/io_zip.c rename to librz/io/p/io_zip.c index 55a5fcd5a1..8bb6afcf4d 100644 --- a/libr/io/p/io_zip.c +++ b/librz/io/p/io_zip.c @@ -2,12 +2,12 @@ io_zip.c rewrite: Adam Pridgen */ -// TODO: wrap with r_sandbox api +// TODO: wrap with rz_sandbox api -#include -#include -#include -#include +#include +#include +#include +#include #include @@ -20,12 +20,12 @@ typedef enum { R_IO_DELETED_FILE = 0x0020, } R_IO_ZIP_ARCHIVE_TYPE; -typedef struct r_io_zip_uri_const_t { +typedef struct rz_io_zip_uri_const_t { const char *name; ut32 len; -} RIOZipConstURI; +} RzIOZipConstURI; -static RIOZipConstURI ZIP_URIS[] = { +static RzIOZipConstURI ZIP_URIS[] = { {"zip://", 6}, {"apk://", 6}, {"ipa://", 6}, @@ -33,7 +33,7 @@ static RIOZipConstURI ZIP_URIS[] = { {NULL, 0} }; -static RIOZipConstURI ZIP_ALL_URIS[] = { +static RzIOZipConstURI ZIP_ALL_URIS[] = { {"zipall://", 9}, {"apkall://", 9}, {"ipaall://", 9}, @@ -41,7 +41,7 @@ static RIOZipConstURI ZIP_ALL_URIS[] = { {NULL, 0} }; -typedef struct r_io_zfo_t { +typedef struct rz_io_zfo_t { char * name; char * archivename; int mode; @@ -54,16 +54,16 @@ typedef struct r_io_zfo_t { RBuffer *b; char *password; ut8 encryption_value; - RIO * io_backref; -} RIOZipFileObj; + RzIO * io_backref; +} RzIOZipFileObj; -static int r_io_zip_has_uri_substr(const char *file) { +static int rz_io_zip_has_uri_substr(const char *file) { return (file && strstr (file, "://")); } -static int r_io_zip_check_uri_many(const char *file) { +static int rz_io_zip_check_uri_many(const char *file) { int i; - if (r_io_zip_has_uri_substr (file)) { + if (rz_io_zip_has_uri_substr (file)) { for (i = 0; ZIP_ALL_URIS[i].name != NULL; i++) { if (!strncmp (file, ZIP_ALL_URIS[i].name, ZIP_ALL_URIS[i].len) && file[ZIP_ALL_URIS[i].len]) { return true; @@ -73,9 +73,9 @@ static int r_io_zip_check_uri_many(const char *file) { return false; } -static int r_io_zip_check_uri(const char *file) { +static int rz_io_zip_check_uri(const char *file) { int i; - if (r_io_zip_has_uri_substr (file)) { + if (rz_io_zip_has_uri_substr (file)) { for (i = 0; ZIP_URIS[i].name != NULL; i++) { if (!strncmp (file, ZIP_URIS[i].name, ZIP_URIS[i].len) && file[ZIP_URIS[i].len]) { return true; @@ -85,17 +85,17 @@ static int r_io_zip_check_uri(const char *file) { return false; } -static bool r_io_zip_plugin_open(RIO *io, const char *file, bool many) { +static bool rz_io_zip_plugin_open(RzIO *io, const char *file, bool many) { if (io && file) { if (many) { - return r_io_zip_check_uri_many (file); + return rz_io_zip_check_uri_many (file); } - return r_io_zip_check_uri (file); + return rz_io_zip_check_uri (file); } return false; } -struct zip *r_io_zip_open_archive(const char *archivename, ut32 perm, int mode, int rw) { +struct zip *rz_io_zip_open_archive(const char *archivename, ut32 perm, int mode, int rw) { struct zip * zipArch = NULL; int zip_errorp; if (!archivename) { @@ -122,7 +122,7 @@ struct zip *r_io_zip_open_archive(const char *archivename, ut32 perm, int mode, return NULL; } -static int r_io_zip_slurp_file(RIOZipFileObj *zfo) { +static int rz_io_zip_slurp_file(RzIOZipFileObj *zfo) { struct zip_file *zFile = NULL; struct zip *zipArch; struct zip_stat sb; @@ -130,21 +130,21 @@ static int r_io_zip_slurp_file(RIOZipFileObj *zfo) { if (!zfo) { return res; } - zipArch = r_io_zip_open_archive ( + zipArch = rz_io_zip_open_archive ( zfo->archivename, zfo->perm, zfo->mode, zfo->rw); if (zipArch && zfo && zfo->entry != -1) { zFile = zip_fopen_index (zipArch, zfo->entry, 0); if (!zfo->b) { - zfo->b = r_buf_new (); + zfo->b = rz_buf_new (); } zip_stat_init (&sb); if (zFile && zfo->b && !zip_stat_index (zipArch, zfo->entry, 0, &sb)) { ut8 *buf = calloc (1, sb.size); if (buf) { zip_fread (zFile, buf, sb.size); - r_buf_set_bytes (zfo->b, buf, sb.size); + rz_buf_set_bytes (zfo->b, buf, sb.size); res = true; zfo->opened = true; free (buf); @@ -156,14 +156,14 @@ static int r_io_zip_slurp_file(RIOZipFileObj *zfo) { return res; } -RList * r_io_zip_get_files(char *archivename, ut32 perm, int mode, int rw) { - struct zip *zipArch = r_io_zip_open_archive (archivename, perm, mode, rw); +RzList * rz_io_zip_get_files(char *archivename, ut32 perm, int mode, int rw) { + struct zip *zipArch = rz_io_zip_open_archive (archivename, perm, mode, rw); ut64 num_entries = 0, i = 0; - RList *files = NULL; + RzList *files = NULL; struct zip_stat sb; char *name; if (zipArch) { - files = r_list_newf (free); + files = rz_list_newf (free); if (!files) { zip_close (zipArch); return NULL; @@ -173,7 +173,7 @@ RList * r_io_zip_get_files(char *archivename, ut32 perm, int mode, int rw) { zip_stat_init (&sb); zip_stat_index (zipArch, i, 0, &sb); if ((name = strdup (sb.name))) { - r_list_append (files, name); + rz_list_append (files, name); } } } @@ -181,7 +181,7 @@ RList * r_io_zip_get_files(char *archivename, ut32 perm, int mode, int rw) { return files; } -int r_io_zip_flush_file(RIOZipFileObj *zfo) { +int rz_io_zip_flush_file(RzIOZipFileObj *zfo) { int res = false; struct zip * zipArch; @@ -189,14 +189,14 @@ int r_io_zip_flush_file(RIOZipFileObj *zfo) { return res; } - zipArch = r_io_zip_open_archive ( + zipArch = rz_io_zip_open_archive ( zfo->archivename, zfo->perm, zfo->mode, zfo->rw); if (!zipArch) { return res; } ut64 tmpsz; - const ut8 *tmp = r_buf_data (zfo->b, &tmpsz); + const ut8 *tmp = rz_buf_data (zfo->b, &tmpsz); struct zip_source *s = zip_source_buffer (zipArch, tmp, tmpsz, 0); if (s && zfo->entry != -1) { if (zip_replace(zipArch, zfo->entry, s) == 0) { @@ -216,27 +216,27 @@ int r_io_zip_flush_file(RIOZipFileObj *zfo) { return res; } -static void r_io_zip_free_zipfileobj(RIOZipFileObj *zfo) { +static void rz_io_zip_free_zipfileobj(RzIOZipFileObj *zfo) { if (!zfo) { return; } if (zfo->modified) { - r_io_zip_flush_file (zfo); + rz_io_zip_flush_file (zfo); } free (zfo->name); free (zfo->password); - r_buf_free (zfo->b); + rz_buf_free (zfo->b); free (zfo); } -RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 perm, int mode, int rw) { - RIOZipFileObj *zfo = R_NEW0 (RIOZipFileObj); +RzIOZipFileObj *rz_io_zip_create_new_file(const char *archivename, const char *filename, struct zip_stat *sb, ut32 perm, int mode, int rw) { + RzIOZipFileObj *zfo = R_NEW0 (RzIOZipFileObj); if (zfo) { - zfo->b = r_buf_new (); + zfo->b = rz_buf_new (); zfo->archivename = strdup (archivename); zfo->name = strdup (sb? sb->name: filename); zfo->entry = !sb? -1: sb->index; - zfo->fd = r_num_rand (0xFFFF); // XXX: Use r_io_fd api + zfo->fd = rz_num_rand (0xFFFF); // XXX: Use rz_io_fd api zfo->perm = perm; zfo->mode = mode; zfo->rw = rw; @@ -245,11 +245,11 @@ RIOZipFileObj *r_io_zip_create_new_file(const char *archivename, const char *fil } /* The file can be a file in the archive or ::[num]. */ -RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw) { - RIOZipFileObj *zfo = NULL; +RzIOZipFileObj* rz_io_zip_alloc_zipfileobj(const char *archivename, const char *filename, ut32 perm, int mode, int rw) { + RzIOZipFileObj *zfo = NULL; ut64 i, num_entries; struct zip_stat sb; - struct zip *zipArch = r_io_zip_open_archive (archivename, perm, mode, rw); + struct zip *zipArch = rz_io_zip_open_archive (archivename, perm, mode, rw); if (!zipArch) { return NULL; } @@ -260,32 +260,32 @@ RIOZipFileObj* r_io_zip_alloc_zipfileobj(const char *archivename, const char *fi zip_stat_index (zipArch, i, 0, &sb); if (sb.name != NULL) { if (strcmp (sb.name, filename) == 0) { - zfo = r_io_zip_create_new_file ( + zfo = rz_io_zip_create_new_file ( archivename, filename, &sb, perm, mode, rw); - r_io_zip_slurp_file (zfo); + rz_io_zip_slurp_file (zfo); break; } } } if (!zfo) { - zfo = r_io_zip_create_new_file (archivename, + zfo = rz_io_zip_create_new_file (archivename, filename, NULL, perm, mode, rw); } zip_close (zipArch); return zfo; } -// Below this line are the r_io_zip plugin APIs -static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) { - RList *list_fds = NULL; - RListIter *iter; - RList *filenames = NULL; - RIODesc *res = NULL; - RIOZipFileObj *zfo = NULL; +// Below this line are the rz_io_zip plugin APIs +static RzList *rz_io_zip_open_many(RzIO *io, const char *file, int rw, int mode) { + RzList *list_fds = NULL; + RzListIter *iter; + RzList *filenames = NULL; + RzIODesc *res = NULL; + RzIOZipFileObj *zfo = NULL; char *filename_in_zipfile, *zip_filename = NULL, *zip_uri; - if (!r_io_zip_plugin_open (io, file, true)) { + if (!rz_io_zip_plugin_open (io, file, true)) { return NULL; } @@ -306,22 +306,22 @@ static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) { return NULL; } - filenames = r_io_zip_get_files(zip_filename, 0, mode, rw ); + filenames = rz_io_zip_get_files(zip_filename, 0, mode, rw ); if (!filenames) { free (zip_uri); return NULL; } - list_fds = r_list_new (); - r_list_foreach (filenames, iter, filename_in_zipfile) { + list_fds = rz_list_new (); + rz_list_foreach (filenames, iter, filename_in_zipfile) { size_t v = strlen (filename_in_zipfile); if (filename_in_zipfile[v - 1] == '/') { continue; } - zfo = r_io_zip_alloc_zipfileobj (zip_filename, + zfo = rz_io_zip_alloc_zipfileobj (zip_filename, filename_in_zipfile, ZIP_CREATE, mode, rw); if (zfo && zfo->entry == -1) { @@ -330,23 +330,23 @@ static RList *r_io_zip_open_many(RIO *io, const char *file, int rw, int mode) { if (zfo) { zfo->io_backref = io; - res = r_io_desc_new (io, &r_io_plugin_zip, + res = rz_io_desc_new (io, &rz_io_plugin_zip, zfo->name, rw, mode, zfo); } - r_list_append (list_fds, res); + rz_list_append (list_fds, res); } free(zip_uri); - r_list_free (filenames); + rz_list_free (filenames); return list_fds; } -char * r_io_zip_get_by_file_idx(const char * archivename, const char *idx, ut32 perm, int mode, int rw) { +char * rz_io_zip_get_by_file_idx(const char * archivename, const char *idx, ut32 perm, int mode, int rw) { char *filename = NULL; ut64 i, num_entries; ut32 file_idx = -1; struct zip_stat sb; - struct zip * zipArch = r_io_zip_open_archive (archivename, perm, mode, rw); + struct zip * zipArch = rz_io_zip_open_archive (archivename, perm, mode, rw); if (!idx || !zipArch) { zip_close (zipArch); return filename; @@ -369,13 +369,13 @@ char * r_io_zip_get_by_file_idx(const char * archivename, const char *idx, ut32 return filename; } -static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { - RIODesc *res = NULL; +static RzIODesc *rz_io_zip_open(RzIO *io, const char *file, int rw, int mode) { + RzIODesc *res = NULL; char *pikaboo, *tmp; - RIOZipFileObj *zfo = NULL; + RzIOZipFileObj *zfo = NULL; char *zip_uri = NULL, *zip_filename = NULL, *filename_in_zipfile = NULL; - if (!r_io_zip_plugin_open (io, file, false)) { + if (!rz_io_zip_plugin_open (io, file, false)) { return NULL; } zip_uri = strdup (file); @@ -389,26 +389,26 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { // 1) Tokenize to the '//' and find the base file directory ('/') if (!zip_filename) { if (!strncmp (zip_uri, "apk://", 6)) { - zip_filename = r_str_newf ("//%s//classes.dex", pikaboo + 3); + zip_filename = rz_str_newf ("//%s//classes.dex", pikaboo + 3); } else if (!strncmp (zip_uri, "ipa://", 6)) { - RList *files = NULL; - RListIter *iter; + RzList *files = NULL; + RzListIter *iter; char *name; zip_filename = strdup (pikaboo + 3); - files = r_io_zip_get_files (zip_filename, 0, mode, rw ); + files = rz_io_zip_get_files (zip_filename, 0, mode, rw ); if (files) { - r_list_foreach (files, iter, name) { + rz_list_foreach (files, iter, name) { /* Find matching file */ char *bin_name = strstr (name, ".app/"); if (bin_name) { - const char *slash = r_str_rchr (name, bin_name, '/'); + const char *slash = rz_str_rchr (name, bin_name, '/'); if (slash) { - bin_name = r_str_ndup (slash + 1, (bin_name - slash) -1); - char *chkstr = r_str_newf ("Payload/%s.app/%s", bin_name, bin_name); + bin_name = rz_str_ndup (slash + 1, (bin_name - slash) -1); + char *chkstr = rz_str_newf ("Payload/%s.app/%s", bin_name, bin_name); if (!strcmp (name, chkstr)) { free (zip_filename); - zip_filename = r_str_newf ("//%s", chkstr); + zip_filename = rz_str_newf ("//%s", chkstr); free (chkstr); free (bin_name); break; @@ -418,7 +418,7 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { } } } - r_list_free (files); + rz_list_free (files); } } else { zip_filename = strdup (pikaboo + 1); @@ -448,11 +448,11 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { // null terminating uri to filename here. *filename_in_zipfile++ = 0; *filename_in_zipfile++ = 0; - filename_in_zipfile = r_io_zip_get_by_file_idx ( + filename_in_zipfile = rz_io_zip_get_by_file_idx ( zip_filename, filename_in_zipfile, ZIP_CREATE, mode, rw); } else { - filename_in_zipfile = r_str_newf ("%s", zip_filename); + filename_in_zipfile = rz_str_newf ("%s", zip_filename); R_FREE (tmp); zip_filename = strdup (pikaboo + 3); if (!strcmp (zip_filename, filename_in_zipfile)) { @@ -472,25 +472,25 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { // Failed to find the file name the archive. if (!filename_in_zipfile) { - RList *files = NULL; - RListIter *iter; + RzList *files = NULL; + RzListIter *iter; char *name; //eprintf("usage: zip:///path/to/archive//filepath\n"); - files = r_io_zip_get_files (zip_filename, 0, mode, rw); + files = rz_io_zip_get_files (zip_filename, 0, mode, rw); if (files) { ut32 i = 0; - r_list_foreach (files, iter, name) { + rz_list_foreach (files, iter, name) { io->cb_printf ("%d %s\n", i, name); i++; } - r_list_free (files); + rz_list_free (files); } goto done; } //eprintf("After parsing the given uri: %s\n", file); //eprintf("Zip filename the given uri: %s\n", zip_filename); //eprintf("File in the zip: %s\n", filename_in_zipfile); - zfo = r_io_zip_alloc_zipfileobj (zip_filename, + zfo = rz_io_zip_alloc_zipfileobj (zip_filename, filename_in_zipfile, ZIP_CREATE, mode, rw); if (zfo) { @@ -498,15 +498,15 @@ static RIODesc *r_io_zip_open(RIO *io, const char *file, int rw, int mode) { eprintf ("Warning: File did not exist, creating a new one.\n"); } zfo->io_backref = io; - res = r_io_desc_new (io, &r_io_plugin_zip, + res = rz_io_desc_new (io, &rz_io_plugin_zip, zfo->name, rw, mode, zfo); } if (!res) { eprintf ("Failed to open the archive %s and file %s\n", zip_filename, filename_in_zipfile); - //free (zfo); zfo is already freed by r_io_desc_new //WTF - r_io_desc_free (res); + //free (zfo); zfo is already freed by rz_io_desc_new //WTF + rz_io_desc_free (res); res = NULL; } done: @@ -516,8 +516,8 @@ done: return res; } -static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { - RIOZipFileObj *zfo; +static ut64 rz_io_zip_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) { + RzIOZipFileObj *zfo; ut64 seek_val = 0; if (!fd || !fd->data) { @@ -525,68 +525,68 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) { } zfo = fd->data; - seek_val = r_buf_tell (zfo->b); + seek_val = rz_buf_tell (zfo->b); switch (whence) { case SEEK_SET: - seek_val = (r_buf_size (zfo->b) < offset)? r_buf_size (zfo->b): offset; + seek_val = (rz_buf_size (zfo->b) < offset)? rz_buf_size (zfo->b): offset; io->off = seek_val; - r_buf_seek (zfo->b, seek_val, R_BUF_SET); + rz_buf_seek (zfo->b, seek_val, R_BUF_SET); return seek_val; case SEEK_CUR: - seek_val = (r_buf_size (zfo->b) < (offset + r_buf_tell (zfo->b)))? r_buf_size (zfo->b): offset + r_buf_tell (zfo->b); + seek_val = (rz_buf_size (zfo->b) < (offset + rz_buf_tell (zfo->b)))? rz_buf_size (zfo->b): offset + rz_buf_tell (zfo->b); io->off = seek_val; - r_buf_seek (zfo->b, seek_val, R_BUF_SET); + rz_buf_seek (zfo->b, seek_val, R_BUF_SET); return seek_val; case SEEK_END: - seek_val = r_buf_size (zfo->b); + seek_val = rz_buf_size (zfo->b); io->off = seek_val; - r_buf_seek (zfo->b, seek_val, R_BUF_SET); + rz_buf_seek (zfo->b, seek_val, R_BUF_SET); return seek_val; } return seek_val; } -static int r_io_zip_read(RIO *io, RIODesc *fd, ut8 *buf, int count) { - RIOZipFileObj *zfo = NULL; +static int rz_io_zip_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) { + RzIOZipFileObj *zfo = NULL; if (!fd || !fd->data || !buf) { return -1; } zfo = fd->data; - if (r_buf_size (zfo->b) < io->off) { - io->off = r_buf_size (zfo->b); + if (rz_buf_size (zfo->b) < io->off) { + io->off = rz_buf_size (zfo->b); } - int r = r_buf_read_at (zfo->b, io->off, buf, count); + int r = rz_buf_read_at (zfo->b, io->off, buf, count); if (r >= 0) { - r_buf_seek (zfo->b, r, R_BUF_CUR); + rz_buf_seek (zfo->b, r, R_BUF_CUR); } return r; } -static int r_io_zip_realloc_buf(RIOZipFileObj *zfo, int count) { - return r_buf_resize (zfo->b, r_buf_tell (zfo->b) + count); +static int rz_io_zip_realloc_buf(RzIOZipFileObj *zfo, int count) { + return rz_buf_resize (zfo->b, rz_buf_tell (zfo->b) + count); } -static bool r_io_zip_truncate_buf(RIOZipFileObj *zfo, int size) { - return r_buf_resize (zfo->b, size > 0? size: 0); +static bool rz_io_zip_truncate_buf(RzIOZipFileObj *zfo, int size) { + return rz_buf_resize (zfo->b, size > 0? size: 0); } -static bool r_io_zip_resize(RIO *io, RIODesc *fd, ut64 size) { - RIOZipFileObj *zfo; +static bool rz_io_zip_resize(RzIO *io, RzIODesc *fd, ut64 size) { + RzIOZipFileObj *zfo; if (!fd || !fd->data) { return false; } zfo = fd->data; - if (r_io_zip_truncate_buf (zfo, size)) { + if (rz_io_zip_truncate_buf (zfo, size)) { zfo->modified = 1; - r_io_zip_flush_file (zfo); + rz_io_zip_flush_file (zfo); return true; } return false; } -static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { - RIOZipFileObj *zfo; +static int rz_io_zip_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) { + RzIOZipFileObj *zfo; int ret = 0; if (!fd || !fd->data || !buf) { return -1; @@ -595,53 +595,53 @@ static int r_io_zip_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { if (!(zfo->perm & R_PERM_W)) { return -1; } - if (r_buf_tell (zfo->b) + count >= r_buf_size (zfo->b)) { - r_io_zip_realloc_buf (zfo, count); + if (rz_buf_tell (zfo->b) + count >= rz_buf_size (zfo->b)) { + rz_io_zip_realloc_buf (zfo, count); } - if (r_buf_size (zfo->b) < io->off) { - io->off = r_buf_size (zfo->b); + if (rz_buf_size (zfo->b) < io->off) { + io->off = rz_buf_size (zfo->b); } zfo->modified = 1; - ret = r_buf_write_at (zfo->b, io->off, buf, count); + ret = rz_buf_write_at (zfo->b, io->off, buf, count); if (ret >= 0) { - r_buf_seek (zfo->b, ret, R_BUF_CUR); + rz_buf_seek (zfo->b, ret, R_BUF_CUR); } // XXX - Implement a flush of some sort, but until then, lets // just write through - r_io_zip_flush_file (zfo); + rz_io_zip_flush_file (zfo); return ret; } -static int r_io_zip_close(RIODesc *fd) { - RIOZipFileObj *zfo; +static int rz_io_zip_close(RzIODesc *fd) { + RzIOZipFileObj *zfo; if (!fd || !fd->data) { return -1; } zfo = fd->data; - r_io_zip_free_zipfileobj (zfo); + rz_io_zip_free_zipfileobj (zfo); zfo = fd->data = NULL; return 0; } -RIOPlugin r_io_plugin_zip = { +RzIOPlugin rz_io_plugin_zip = { .name = "zip", .desc = "Open zip files", .uris = "zip://,apk://,ipa://,jar://,zipall://,apkall://,ipaall://,jarall://", .license = "BSD", - .open = r_io_zip_open, - .open_many = r_io_zip_open_many, - .write = r_io_zip_write, - .read = r_io_zip_read, - .close = r_io_zip_close, - .lseek = r_io_zip_lseek, - .check = r_io_zip_plugin_open, - .resize = r_io_zip_resize, + .open = rz_io_zip_open, + .open_many = rz_io_zip_open_many, + .write = rz_io_zip_write, + .read = rz_io_zip_read, + .close = rz_io_zip_close, + .lseek = rz_io_zip_lseek, + .check = rz_io_zip_plugin_open, + .resize = rz_io_zip_resize, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_IO, - .data = &r_io_plugin_zip, + .data = &rz_io_plugin_zip, .version = R2_VERSION }; #endif diff --git a/libr/io/p/mach.mk b/librz/io/p/mach.mk similarity index 68% rename from libr/io/p/mach.mk rename to librz/io/p/mach.mk index 2018985f94..22c072a9b9 100644 --- a/libr/io/p/mach.mk +++ b/librz/io/p/mach.mk @@ -5,11 +5,11 @@ TARGET_MACH=io_mach.${EXT_SO} ALL_TARGETS+=${TARGET_MACH} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_MACH}: ${OBJ_MACH} diff --git a/libr/io/p/malloc.mk b/librz/io/p/malloc.mk similarity index 69% rename from libr/io/p/malloc.mk rename to librz/io/p/malloc.mk index 7bef883229..51716d70a5 100644 --- a/libr/io/p/malloc.mk +++ b/librz/io/p/malloc.mk @@ -5,11 +5,11 @@ TARGET_MALLOC=io_malloc.${EXT_SO} ALL_TARGETS+=${TARGET_MALLOC} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_MALLOC}: ${OBJ_MALLOC} diff --git a/libr/io/p/mmap.mk b/librz/io/p/mmap.mk similarity index 66% rename from libr/io/p/mmap.mk rename to librz/io/p/mmap.mk index 870030a91b..66d24d42d2 100644 --- a/libr/io/p/mmap.mk +++ b/librz/io/p/mmap.mk @@ -5,11 +5,11 @@ TARGET_MMAP=io_mmap.${EXT_SO} ALL_TARGETS+=${TARGET_MMAP} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_MMAP}: ${OBJ_MMAP} diff --git a/libr/io/p/null.mk b/librz/io/p/null.mk similarity index 68% rename from libr/io/p/null.mk rename to librz/io/p/null.mk index a1bd905350..60a614aabd 100644 --- a/libr/io/p/null.mk +++ b/librz/io/p/null.mk @@ -5,11 +5,11 @@ TARGET_NULL=io_null.${EXT_SO} ALL_TARGETS+=${TARGET_NULL} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_NULL}: ${OBJ_NULL} diff --git a/libr/io/p/procpid.mk b/librz/io/p/procpid.mk similarity index 67% rename from libr/io/p/procpid.mk rename to librz/io/p/procpid.mk index 435697ae95..d0adb11b33 100644 --- a/libr/io/p/procpid.mk +++ b/librz/io/p/procpid.mk @@ -7,5 +7,5 @@ ALL_TARGETS+=${TARGET_PROCPID} ${TARGET_PROCPID}: ${OBJ_PROCPID} ${CC} $(call libname,io_procpid) \ ${CFLAGS} ${LDFLAGS_LIB} $(LDFLAGS) \ - ${LDFLAGS_LINKPATH}../../util -L../../util -lr_util \ - ${LDFLAGS_LINKPATH}.. -L.. -lr_io ${OBJ_PROCPID} + ${LDFLAGS_LINKPATH}../../util -L../../util -lrz_util \ + ${LDFLAGS_LINKPATH}.. -L.. -lrz_io ${OBJ_PROCPID} diff --git a/libr/io/p/ptrace.mk b/librz/io/p/ptrace.mk similarity index 69% rename from libr/io/p/ptrace.mk rename to librz/io/p/ptrace.mk index e1f3d385a9..7d2217cc86 100644 --- a/libr/io/p/ptrace.mk +++ b/librz/io/p/ptrace.mk @@ -7,5 +7,5 @@ ALL_TARGETS+=${TARGET_PTRACE} ${TARGET_PTRACE}: ${OBJ_PTRACE} ${CC_LIB} ${CFLAGS} -o ${TARGET_PTRACE} ${LDFLAGS_LIB} \ $(call libname,io_ptrace) $(LDFLAGS) \ - ${LDFLAGS_LINKPATH}../../util -L../../util -lr_util \ - ${LDFLAGS_LINKPATH}.. -L.. -lr_io ${OBJ_PTRACE} + ${LDFLAGS_LINKPATH}../../util -L../../util -lrz_util \ + ${LDFLAGS_LINKPATH}.. -L.. -lrz_io ${OBJ_PTRACE} diff --git a/libr/io/p/qnx.mk b/librz/io/p/qnx.mk similarity index 69% rename from libr/io/p/qnx.mk rename to librz/io/p/qnx.mk index ec4c4ac8cc..30894863c8 100644 --- a/libr/io/p/qnx.mk +++ b/librz/io/p/qnx.mk @@ -11,13 +11,13 @@ LDFLAGS+=$(SHLR)/qnx/lib/libqnxr.$(EXT_AR) include $(LIBR)/socket/deps.mk ifeq (${WITHPIC},0) -LINKFLAGS=../../socket/libr_socket.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS=../../socket/librz_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS=-L../../socket -lr_socket -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS=-L../../socket -lrz_socket +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ifeq (${HAVE_LIB_SSL},1) CFLAGS+=${SSL_CFLAGS} diff --git a/librz/io/p/rap.mk b/librz/io/p/rap.mk new file mode 100644 index 0000000000..a809f2ae3d --- /dev/null +++ b/librz/io/p/rap.mk @@ -0,0 +1,13 @@ +OBJ_RAP=io_rap.o + +STATIC_OBJ+=${OBJ_RAP} +TARGET_RAP=io_rap.${EXT_SO} +ALL_TARGETS+=${TARGET_RAP} + +${TARGET_RAP}: ${OBJ_RAP} + ${CC} ${CFLAGS} -o ${TARGET_RAP} ${OBJ_RAP} \ + $(call libname,io_rap) \ + ${LDFLAGS_LINKPATH}../../socket -L../../socket -lrz_socket \ + ${LDFLAGS_LINKPATH}../../util -L../../util -lrz_util \ + ${LDFLAGS_LINKPATH}../../cons -L../../cons -lrz_cons \ + ${LDFLAGS_LINKPATH}.. -L.. -lrz_io diff --git a/libr/io/p/rbuf.mk b/librz/io/p/rbuf.mk similarity index 68% rename from libr/io/p/rbuf.mk rename to librz/io/p/rbuf.mk index 17927cc897..96d9a374bd 100644 --- a/libr/io/p/rbuf.mk +++ b/librz/io/p/rbuf.mk @@ -5,11 +5,11 @@ TARGET_RBUF=io_rbuf.${EXT_SO} ALL_TARGETS+=${TARGET_RBUF} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_RBUF}: ${OBJ_RBUF} diff --git a/librz/io/p/rzk.mk b/librz/io/p/rzk.mk new file mode 100644 index 0000000000..422022b254 --- /dev/null +++ b/librz/io/p/rzk.mk @@ -0,0 +1,22 @@ +OBJ_R2K = io_rzk.o +ifeq ($(OSTYPE),$(filter $(OSTYPE),gnulinux android)) +OBJ_R2K += io_rzk_linux.o +endif +ifeq (${OSTYPE},$(filter $(OSTYPE),windows mingw32 mingw64 cygwin)) +OBJ_R2K += io_rzk_windows.o +endif + +STATIC_OBJ+=${OBJ_R2K} +TARGET_R2K=io_rzk.${EXT_SO} +ALL_TARGETS+=${TARGET_R2K} + +ifeq (${WITHPIC},0) +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a +else +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io +endif + +${TARGET_R2K}: ${OBJ_R2K} + ${CC} $(call libname,io_rzk) ${CFLAGS} -o ${TARGET_R2K} ${OBJ_R2K} ${LINKFLAGS} diff --git a/librz/io/p/rzpipe.mk b/librz/io/p/rzpipe.mk new file mode 100644 index 0000000000..eb3646c403 --- /dev/null +++ b/librz/io/p/rzpipe.mk @@ -0,0 +1,19 @@ +OBJ_R2PIPE=io_rzpipe.o + +STATIC_OBJ+=${OBJ_R2PIPE} +TARGET_R2PIPE=io_rzpipe.${EXT_SO} +ALL_TARGETS+=${TARGET_R2PIPE} + +ifeq (${WITHPIC},0) +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a +LINKFLAGS+=../../io/librz_socket.a +else +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../socket -lrz_socket +LINKFLAGS+=-L.. -lrz_io +endif + +${TARGET_R2PIPE}: ${OBJ_R2PIPE} + ${CC_LIB} $(call libname,io_rzpipe) ${CFLAGS} \ + -o ${TARGET_R2PIPE} ${OBJ_R2PIPE} ${LINKFLAGS} diff --git a/librz/io/p/rzweb.mk b/librz/io/p/rzweb.mk new file mode 100644 index 0000000000..06b91ec0f7 --- /dev/null +++ b/librz/io/p/rzweb.mk @@ -0,0 +1,18 @@ +OBJ_R2WEB=io_rzweb.o + +STATIC_OBJ+=${OBJ_R2WEB} +TARGET_R2WEB=io_rzweb.${EXT_SO} +ALL_TARGETS+=${TARGET_R2WEB} + +ifeq (${WITHPIC},0) +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a +LINKFLAGS+=../../io/librz_socket.a +else +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../socket -lrz_socket +LINKFLAGS+=-L.. -lrz_io +endif + +${TARGET_R2WEB}: ${OBJ_R2WEB} + ${CC_LIB} $(call libname,io_rzweb) ${CFLAGS} -o ${TARGET_R2WEB} ${OBJ_R2WEB} ${LINKFLAGS} diff --git a/libr/io/p/self.mk b/librz/io/p/self.mk similarity index 67% rename from libr/io/p/self.mk rename to librz/io/p/self.mk index 04af4c2283..d3e38482f2 100644 --- a/libr/io/p/self.mk +++ b/librz/io/p/self.mk @@ -5,11 +5,11 @@ TARGET_SELF=io_self.${EXT_SO} ALL_TARGETS+=${TARGET_SELF} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_SELF}: ${OBJ_SELF} diff --git a/libr/io/p/shm.mk b/librz/io/p/shm.mk similarity index 67% rename from libr/io/p/shm.mk rename to librz/io/p/shm.mk index d8c3c34fc6..fb8d92dae2 100644 --- a/libr/io/p/shm.mk +++ b/librz/io/p/shm.mk @@ -5,11 +5,11 @@ TARGET_SHM=io_shm.${EXT_SO} ALL_TARGETS+=${TARGET_SHM} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_SHM}: ${OBJ_SHM} diff --git a/libr/io/p/sparse.mk b/librz/io/p/sparse.mk similarity index 69% rename from libr/io/p/sparse.mk rename to librz/io/p/sparse.mk index 55289abfe1..5242fa8194 100644 --- a/libr/io/p/sparse.mk +++ b/librz/io/p/sparse.mk @@ -5,11 +5,11 @@ TARGET_SPARSE=io_sparse.${EXT_SO} ALL_TARGETS+=${TARGET_SPARSE} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_SPARSE}: ${OBJ_SPARSE} diff --git a/libr/io/p/tcp.mk b/librz/io/p/tcp.mk similarity index 54% rename from libr/io/p/tcp.mk rename to librz/io/p/tcp.mk index b54bd53387..565f05ffe5 100644 --- a/libr/io/p/tcp.mk +++ b/librz/io/p/tcp.mk @@ -5,13 +5,13 @@ TARGET_TCP=io_tcp.${EXT_SO} ALL_TARGETS+=${TARGET_TCP} ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a -LINKFLAGS+=../../io/libr_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a +LINKFLAGS+=../../io/librz_socket.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L../../socket -lr_socket -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L../../socket -lrz_socket +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_TCP}: ${OBJ_TCP} diff --git a/libr/io/p/w32.mk b/librz/io/p/w32.mk similarity index 93% rename from libr/io/p/w32.mk rename to librz/io/p/w32.mk index 08caef268d..99eb4c6f4f 100644 --- a/libr/io/p/w32.mk +++ b/librz/io/p/w32.mk @@ -5,4 +5,4 @@ TARGET_W32=io_w32.${EXT_SO} ALL_TARGETS+=${TARGET_W32} ${TARGET_W32}: ${OBJ_W32} - ${CC} $(call libname,io_w32) ${CFLAGS} -o ${TARGET_W32} ${OBJ_W32} -lr_io + ${CC} $(call libname,io_w32) ${CFLAGS} -o ${TARGET_W32} ${OBJ_W32} -lrz_io diff --git a/libr/io/p/w32dbg.mk b/librz/io/p/w32dbg.mk similarity index 85% rename from libr/io/p/w32dbg.mk rename to librz/io/p/w32dbg.mk index 3b755b1cea..2b95eb83c0 100644 --- a/libr/io/p/w32dbg.mk +++ b/librz/io/p/w32dbg.mk @@ -6,5 +6,5 @@ ALL_TARGETS+=${TARGET_W32DBG} ${TARGET_W32DBG}: ${OBJ_W32DBG} # ${CC_LIB} $(call libname,io_w32dbg) ${CFLAGS} \ -# -L../../util -lr_util $(LDFLAGS) \ +# -L../../util -lrz_util $(LDFLAGS) \ # -o ${TARGET_W32DBG} ${OBJ_W32DBG} diff --git a/libr/io/p/winedbg.mk b/librz/io/p/winedbg.mk similarity index 61% rename from libr/io/p/winedbg.mk rename to librz/io/p/winedbg.mk index 7aca22476b..53cbd8bc7a 100644 --- a/libr/io/p/winedbg.mk +++ b/librz/io/p/winedbg.mk @@ -7,13 +7,13 @@ ALL_TARGETS+=${TARGET_WINEDBG} include $(LIBR)/socket/deps.mk ifeq (${WITHPIC},0) -LINKFLAGS=../../socket/libr_socket.a -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS=../../socket/librz_socket.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS=-L../../socket -lr_socket -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS=-L../../socket -lrz_socket +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif ${TARGET_WINEDBG}: ${OBJ_WINEDBG} diff --git a/librz/io/p/winkd.mk b/librz/io/p/winkd.mk new file mode 100644 index 0000000000..78e99e0496 --- /dev/null +++ b/librz/io/p/winkd.mk @@ -0,0 +1,27 @@ +OBJ_WINKD=io_winkd.o + +STATIC_OBJ+=${OBJ_WINKD} +TARGET_WINKD=io_winkd.${EXT_SO} +ALL_TARGETS+=${TARGET_WINKD} + +LIB_PATH=$(SHLR)/winkd +CFLAGS+=-I$(SHLR)/winkd +LDFLAGS+=$(SHLR)/winkd/librz_winkd.$(EXT_AR) + +ifeq (${WITHPIC},0) +LINKFLAGS=../../util/librz_util.a +LINKFLAGS+= ../../util/librz_socket.a +LINKFLAGS+= ../../util/librz_hash.a +LINKFLAGS+=../../util/librz_crypto.a +LINKFLAGS+=../../io/librz_io.a +else +LINKFLAGS=-L../../util -lrz_util +LINKFLAGS+=-L../../socket -lrz_socket +LINKFLAGS+=-L../../hash -lrz_hash +LINKFLAGS+=-L../../crypto -lrz_crypto +LINKFLAGS+=-L.. -lrz_io +endif + +${TARGET_WINKD}: ${OBJ_WINKD} + ${CC} $(call libname,io_winkd) ${OBJ_WINKD} ${CFLAGS} \ + ${LINKFLAGS} ${LDFLAGS_LIB} $(LDFLAGS) diff --git a/libr/io/p/zip.mk b/librz/io/p/zip.mk similarity index 71% rename from libr/io/p/zip.mk rename to librz/io/p/zip.mk index a3b4f54fa1..b24b8a07bd 100644 --- a/libr/io/p/zip.mk +++ b/librz/io/p/zip.mk @@ -7,11 +7,11 @@ ALL_TARGETS+=${TARGET_ZIP} CFLAGS+=-I../../shlr/zip/include ifeq (${WITHPIC},0) -LINKFLAGS+=../../util/libr_util.a -LINKFLAGS+=../../io/libr_io.a +LINKFLAGS+=../../util/librz_util.a +LINKFLAGS+=../../io/librz_io.a else -LINKFLAGS+=-L../../util -lr_util -LINKFLAGS+=-L.. -lr_io +LINKFLAGS+=-L../../util -lrz_util +LINKFLAGS+=-L.. -lrz_io endif #LINKFLAGS+=../../../shlr/zip/librz.a diff --git a/libr/io/p_cache.c b/librz/io/p_cache.c similarity index 77% rename from libr/io/p_cache.c rename to librz/io/p_cache.c index ccdb4f5ec2..c95e5b7301 100644 --- a/libr/io/p_cache.c +++ b/librz/io/p_cache.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017-2018 - condret, alvaro */ +/* rizin - LGPL - Copyright 2017-2018 - condret, alvaro */ -#include -#include +#include +#include #include const ut64 cleanup_masks[] = { @@ -74,19 +74,19 @@ static void pcache_kv_free(HtUPKv *kv) { free (kv->value); } -R_API bool r_io_desc_cache_init(RIODesc *desc) { +RZ_API bool rz_io_desc_cache_init(RzIODesc *desc) { if (!desc || desc->cache) { return false; } return (desc->cache = ht_up_new (NULL, pcache_kv_free, NULL)) ? true : false; } -R_API int r_io_desc_cache_write(RIODesc *desc, ut64 paddr, const ut8 *buf, int len) { - RIODescCache *cache; - ut64 caddr, desc_sz = r_io_desc_size (desc); +RZ_API int rz_io_desc_cache_write(RzIODesc *desc, ut64 paddr, const ut8 *buf, int len) { + RzIODescCache *cache; + ut64 caddr, desc_sz = rz_io_desc_size (desc); int cbaddr, written = 0; if ((len < 1) || !desc || (desc_sz <= paddr) || - !desc->io || (!desc->cache && !r_io_desc_cache_init (desc))) { + !desc->io || (!desc->cache && !rz_io_desc_cache_init (desc))) { return 0; } if (len > desc_sz) { @@ -99,9 +99,9 @@ R_API int r_io_desc_cache_write(RIODesc *desc, ut64 paddr, const ut8 *buf, int l cbaddr = paddr % R_IO_DESC_CACHE_SIZE; while (written < len) { //get an existing desc-cache, if it exists - if (!(cache = (RIODescCache *)ht_up_find (desc->cache, caddr, NULL))) { + if (!(cache = (RzIODescCache *)ht_up_find (desc->cache, caddr, NULL))) { //create new desc-cache - cache = R_NEW0 (RIODescCache); + cache = R_NEW0 (RzIODescCache); if (!cache) { return 0; } @@ -135,10 +135,10 @@ R_API int r_io_desc_cache_write(RIODesc *desc, ut64 paddr, const ut8 *buf, int l return written; } -R_API int r_io_desc_cache_read(RIODesc *desc, ut64 paddr, ut8 *buf, int len) { - RIODescCache *cache; +RZ_API int rz_io_desc_cache_read(RzIODesc *desc, ut64 paddr, ut8 *buf, int len) { + RzIODescCache *cache; ut8 *ptr = buf; - ut64 caddr, desc_sz = r_io_desc_size (desc); + ut64 caddr, desc_sz = rz_io_desc_size (desc); int cbaddr, amount = 0; if ((len < 1) || !desc || (desc_sz <= paddr) || !desc->io || !desc->cache) { return 0; @@ -153,7 +153,7 @@ R_API int r_io_desc_cache_read(RIODesc *desc, ut64 paddr, ut8 *buf, int len) { cbaddr = paddr % R_IO_DESC_CACHE_SIZE; while (amount < len) { // get an existing desc-cache, if it exists - if (!(cache = (RIODescCache *)ht_up_find (desc->cache, caddr, NULL))) { + if (!(cache = (RzIODescCache *)ht_up_find (desc->cache, caddr, NULL))) { amount += (R_IO_DESC_CACHE_SIZE - cbaddr); ptr += (R_IO_DESC_CACHE_SIZE - cbaddr); goto beach; @@ -184,7 +184,7 @@ beach: } static void __riocache_free(void *user) { - RIOCache *cache = (RIOCache *) user; + RzIOCache *cache = (RzIOCache *) user; if (cache) { free (cache->data); free (cache->odata); @@ -193,19 +193,19 @@ static void __riocache_free(void *user) { } static bool __desc_cache_list_cb(void *user, const ut64 k, const void *v) { - RList *writes = (RList *)user; - RIOCache *cache = NULL; + RzList *writes = (RzList *)user; + RzIOCache *cache = NULL; ut64 blockaddr; int byteaddr, i; if (!writes) { return false; } - const RIODescCache *dcache = v; + const RzIODescCache *dcache = v; blockaddr = k * R_IO_DESC_CACHE_SIZE; for (i = byteaddr = 0; byteaddr < R_IO_DESC_CACHE_SIZE; byteaddr++) { if (dcache->cached & (0x1LL << byteaddr)) { if (!cache) { - cache = R_NEW0 (RIOCache); + cache = R_NEW0 (RzIOCache); if (!cache) { return false; } @@ -227,7 +227,7 @@ static bool __desc_cache_list_cb(void *user, const ut64 k, const void *v) { cache->data = data; cache->itv.size = i; i = 0; - r_list_push (writes, cache); + rz_list_push (writes, cache); cache = NULL; } } @@ -237,34 +237,34 @@ static bool __desc_cache_list_cb(void *user, const ut64 k, const void *v) { cache->to = blockaddr + R_IO_DESC_CACHE_SIZE; #endif cache->itv.size = i; - r_list_push (writes, cache); + rz_list_push (writes, cache); } return true; } -R_API RList *r_io_desc_cache_list(RIODesc *desc) { +RZ_API RzList *rz_io_desc_cache_list(RzIODesc *desc) { if (!desc || !desc->io || !desc->io->desc || !desc->io->p_cache || !desc->cache) { return NULL; } - RList *writes = r_list_newf ((RListFree)__riocache_free); + RzList *writes = rz_list_newf ((RzListFree)__riocache_free); if (!writes) { return NULL; } ht_up_foreach (desc->cache, __desc_cache_list_cb, writes); - RIODesc *current = desc->io->desc; + RzIODesc *current = desc->io->desc; desc->io->desc = desc; desc->io->p_cache = false; - RIOCache *c; - RListIter *iter; - r_list_foreach (writes, iter, c) { - const ut64 itvSize = r_itv_size (c->itv); + RzIOCache *c; + RzListIter *iter; + rz_list_foreach (writes, iter, c) { + const ut64 itvSize = rz_itv_size (c->itv); c->odata = calloc (1, itvSize); if (!c->odata) { - r_list_free (writes); + rz_list_free (writes); return NULL; } - r_io_pread_at (desc->io, r_itv_begin (c->itv), c->odata, itvSize); + rz_io_pread_at (desc->io, rz_itv_begin (c->itv), c->odata, itvSize); } desc->io->p_cache = true; desc->io->desc = current; @@ -272,31 +272,31 @@ R_API RList *r_io_desc_cache_list(RIODesc *desc) { } static bool __desc_cache_commit_cb(void *user, const ut64 k, const void *v) { - RIODesc *desc = (RIODesc *)user; + RzIODesc *desc = (RzIODesc *)user; int byteaddr, i; ut8 buf[R_IO_DESC_CACHE_SIZE] = {0}; if (!desc || !desc->io) { return false; } - const RIODescCache *dcache = v; + const RzIODescCache *dcache = v; ut64 blockaddr = R_IO_DESC_CACHE_SIZE * k; for (i = byteaddr = 0; byteaddr < R_IO_DESC_CACHE_SIZE; byteaddr++) { if (dcache->cached & (0x1LL << byteaddr)) { buf[i] = dcache->cdata[byteaddr]; i++; } else if (i > 0) { - r_io_pwrite_at (desc->io, blockaddr + byteaddr - i, buf, i); + rz_io_pwrite_at (desc->io, blockaddr + byteaddr - i, buf, i); i = 0; } } if (i > 0) { - r_io_pwrite_at (desc->io, blockaddr + R_IO_DESC_CACHE_SIZE - i, buf, i); + rz_io_pwrite_at (desc->io, blockaddr + R_IO_DESC_CACHE_SIZE - i, buf, i); } return true; } -R_API bool r_io_desc_cache_commit(RIODesc *desc) { - RIODesc *current; +RZ_API bool rz_io_desc_cache_commit(RzIODesc *desc) { + RzIODesc *current; if (!desc || !(desc->perm & R_PERM_W) || !desc->io || !desc->io->files || !desc->io->p_cache) { return false; } @@ -315,15 +315,15 @@ R_API bool r_io_desc_cache_commit(RIODesc *desc) { } static bool __desc_cache_cleanup_cb(void *user, const ut64 k, const void *v) { - RIODesc *desc = (RIODesc *)user; + RzIODesc *desc = (RzIODesc *)user; ut64 size, blockaddr; int byteaddr; if (!desc || !desc->cache) { return false; } - RIODescCache *cache = (RIODescCache *)v; + RzIODescCache *cache = (RzIODescCache *)v; blockaddr = R_IO_DESC_CACHE_SIZE * k; - size = r_io_desc_size (desc); + size = rz_io_desc_size (desc); if (size <= blockaddr) { ht_up_delete (desc->cache, k); return true; @@ -336,14 +336,14 @@ static bool __desc_cache_cleanup_cb(void *user, const ut64 k, const void *v) { return true; } -R_API void r_io_desc_cache_cleanup(RIODesc *desc) { +RZ_API void rz_io_desc_cache_cleanup(RzIODesc *desc) { if (desc && desc->cache) { ht_up_foreach (desc->cache, __desc_cache_cleanup_cb, desc); } } static bool __desc_fini_cb (void *user, void *data, ut32 id) { - RIODesc *desc = (RIODesc *)data; + RzIODesc *desc = (RzIODesc *)data; if (desc->cache) { ht_up_free (desc->cache); desc->cache = NULL; @@ -351,12 +351,12 @@ static bool __desc_fini_cb (void *user, void *data, ut32 id) { return true; } -R_API void r_io_desc_cache_fini(RIODesc *desc) { +RZ_API void rz_io_desc_cache_fini(RzIODesc *desc) { __desc_fini_cb (NULL, (void *) desc, 0); } -R_API void r_io_desc_cache_fini_all(RIO *io) { +RZ_API void rz_io_desc_cache_fini_all(RzIO *io) { if (io && io->files) { - r_id_storage_foreach (io->files, __desc_fini_cb, NULL); + rz_id_storage_foreach (io->files, __desc_fini_cb, NULL); } } diff --git a/libr/io/undo.c b/librz/io/undo.c similarity index 71% rename from libr/io/undo.c rename to librz/io/undo.c index 88cc8dfe89..80cb6279dd 100644 --- a/libr/io/undo.c +++ b/librz/io/undo.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2007-2018 - pancake */ -#include +#include #if 0 * TODO: @@ -9,32 +9,32 @@ * - Per-fd history log #endif -R_API int r_io_undo_init(RIO *io) { +RZ_API int rz_io_undo_init(RzIO *io) { /* seek undo */ - r_io_sundo_reset (io); + rz_io_sundo_reset (io); /* write undo */ io->undo.w_init = 0; io->undo.w_enable = 0; io->undo.w_enable = 0; - io->undo.w_list = r_list_new (); + io->undo.w_list = rz_list_new (); return true; } -R_API void r_io_undo_enable(RIO *io, int s, int w) { +RZ_API void rz_io_undo_enable(RzIO *io, int s, int w) { io->undo.s_enable = s; io->undo.w_enable = w; } /* undo seekz */ -R_API RIOUndos *r_io_sundo(RIO *io, ut64 offset) { +RZ_API RzIOUndos *rz_io_sundo(RzIO *io, ut64 offset) { if (!io->undo.s_enable || !io->undo.undos) { return NULL; } - RIOUndos *undo; + RzIOUndos *undo; /* No redos yet, store the current seek so we can redo to it. */ if (!io->undo.redos) { undo = &io->undo.seek[io->undo.idx]; @@ -47,7 +47,7 @@ R_API RIOUndos *r_io_sundo(RIO *io, ut64 offset) { io->undo.redos++; undo = &io->undo.seek[io->undo.idx]; - RIOMap *map = r_io_map_get (io, undo->off); + RzIOMap *map = rz_io_map_get (io, undo->off); if (!map || (map->delta == map->itv.addr)) { io->off = undo->off; } else { @@ -56,9 +56,9 @@ R_API RIOUndos *r_io_sundo(RIO *io, ut64 offset) { return undo; } -R_API RIOUndos *r_io_sundo_redo(RIO *io) { - RIOUndos *undo; - RIOMap *map; +RZ_API RzIOUndos *rz_io_sundo_redo(RzIO *io) { + RzIOUndos *undo; + RzIOMap *map; if (!io->undo.s_enable || !io->undo.redos) { return NULL; @@ -69,7 +69,7 @@ R_API RIOUndos *r_io_sundo_redo(RIO *io) { io->undo.redos--; undo = &io->undo.seek[io->undo.idx]; - map = r_io_map_get (io, undo->off); + map = rz_io_map_get (io, undo->off); if (!map || (map->delta == map->itv.addr)) { io->off = undo->off; } else { @@ -78,8 +78,8 @@ R_API RIOUndos *r_io_sundo_redo(RIO *io) { return undo; } -R_API void r_io_sundo_push(RIO *io, ut64 off, int cursor) { - RIOUndos *undo; +RZ_API void rz_io_sundo_push(RzIO *io, ut64 off, int cursor) { + RzIOUndos *undo; if (!io->undo.s_enable) { return; } @@ -95,7 +95,7 @@ R_API void r_io_sundo_push(RIO *io, ut64 off, int cursor) { undo->off = off; undo->cursor = cursor; io->undo.idx = (io->undo.idx + 1) % R_IO_UNDOS; - /* Only R_IO_UNDOS - 1 undos can be used because r_io_sundo_undo () must + /* Only R_IO_UNDOS - 1 undos can be used because rz_io_sundo_undo () must * push the current position for redo as well, which takes one entry in * the table. */ if (io->undo.undos < R_IO_UNDOS - 1) { @@ -106,15 +106,15 @@ R_API void r_io_sundo_push(RIO *io, ut64 off, int cursor) { io->undo.redos = 0; } -R_API void r_io_sundo_reset(RIO *io) { +RZ_API void rz_io_sundo_reset(RzIO *io) { io->undo.idx = 0; io->undo.undos = 0; io->undo.redos = 0; } -R_API RList *r_io_sundo_list(RIO *io, int mode) { +RZ_API RzList *rz_io_sundo_list(RzIO *io, int mode) { int idx, undos, redos, i, j, start, end; - RList* list = NULL; + RzList* list = NULL; if (mode == '!') { mode = 0; @@ -135,12 +135,12 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) { io->cb_printf ("["); break; case 0: - list = r_list_newf (free); + list = rz_list_newf (free); break; } for (i = start;/* condition at the end of loop */; i = (i + 1) % R_IO_UNDOS) { int idx = (j < undos)? undos - j - 1: j - undos - 1; - RIOUndos *undo = &io->undo.seek[i]; + RzIOUndos *undo = &io->undo.seek[i]; ut64 addr = undo->off; bool notLast = (j + 1 < undos); switch (mode) { @@ -160,16 +160,16 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) { break; case 0: if (list) { - RIOUndos *u = R_NEW0 (RIOUndos); + RzIOUndos *u = R_NEW0 (RzIOUndos); if (u) { if (!(j == undos && redos == 0)) { // Current position gets pushed before seek, so there // is no valid offset when we are at the end of list. - memcpy (u, undo, sizeof (RIOUndos)); + memcpy (u, undo, sizeof (RzIOUndos)); } else { u->off = io->off; } - r_list_append (list, u); + rz_list_append (list, u); } } break; @@ -189,13 +189,13 @@ R_API RList *r_io_sundo_list(RIO *io, int mode) { /* undo writez */ -R_API void r_io_wundo_new(RIO *io, ut64 off, const ut8 *data, int len) { - RIOUndoWrite *uw; +RZ_API void rz_io_wundo_new(RzIO *io, ut64 off, const ut8 *data, int len) { + RzIOUndoWrite *uw; if (!io->undo.w_enable) { return; } /* undo write changes */ - uw = R_NEW0 (RIOUndoWrite); + uw = R_NEW0 (RzIOUndoWrite); if (!uw) { return; } @@ -214,29 +214,29 @@ R_API void r_io_wundo_new(RIO *io, ut64 off, const ut8 *data, int len) { return; } memset (uw->o, 0xff, len); - r_io_read_at (io, off, uw->o, len); - r_list_append (io->undo.w_list, uw); + rz_io_read_at (io, off, uw->o, len); + rz_list_append (io->undo.w_list, uw); } -R_API void r_io_wundo_clear(RIO *io) { +RZ_API void rz_io_wundo_clear(RzIO *io) { // XXX memory leak - io->undo.w_list = r_list_new (); + io->undo.w_list = rz_list_new (); } -// rename to r_io_undo_length ? -R_API int r_io_wundo_size(RIO *io) { - return r_list_length (io->undo.w_list); +// rename to rz_io_undo_length ? +RZ_API int rz_io_wundo_size(RzIO *io) { + return rz_list_length (io->undo.w_list); } // TODO: Deprecate or so? iterators must be language-wide, but helpers are useful -R_API void r_io_wundo_list(RIO *io) { +RZ_API void rz_io_wundo_list(RzIO *io) { #define BW 8 /* byte wrap */ - RListIter *iter; - RIOUndoWrite *u; + RzListIter *iter; + RzIOUndoWrite *u; int i = 0, j, len; if (io->undo.w_init) { - r_list_foreach (io->undo.w_list, iter, u) { + rz_list_foreach (io->undo.w_list, iter, u) { io->cb_printf ("%02d %c %d %08" PFMT64x ": ", i, u->set ? '+' : '-', u->len, u->off); len = (u->len > BW) ? BW : u->len; for (j = 0; j < len; j++) { @@ -258,44 +258,44 @@ R_API void r_io_wundo_list(RIO *io) { } } -R_API int r_io_wundo_apply(RIO *io, RIOUndoWrite *u, int set) { +RZ_API int rz_io_wundo_apply(RzIO *io, RzIOUndoWrite *u, int set) { int orig = io->undo.w_enable; io->undo.w_enable = 0; if (set) { - r_io_write_at (io, u->off, u->n, u->len); + rz_io_write_at (io, u->off, u->n, u->len); u->set = true; } else { - r_io_write_at (io, u->off, u->o, u->len); + rz_io_write_at (io, u->off, u->o, u->len); u->set = false; } io->undo.w_enable = orig; return 0; } -R_API void r_io_wundo_apply_all(RIO *io, int set) { - RListIter *iter; - RIOUndoWrite *u; +RZ_API void rz_io_wundo_apply_all(RzIO *io, int set) { + RzListIter *iter; + RzIOUndoWrite *u; - r_list_foreach_prev (io->undo.w_list, iter, u) { - r_io_wundo_apply (io, u, set); //UNDO_WRITE_UNSET); + rz_list_foreach_prev (io->undo.w_list, iter, u) { + rz_io_wundo_apply (io, u, set); //UNDO_WRITE_UNSET); eprintf ("%s 0x%08"PFMT64x"\n", set?"redo":"undo", u->off); } } /* sets or unsets the writes done */ /* if ( set == 0 ) unset(n) */ -R_API int r_io_wundo_set(RIO *io, int n, int set) { - RListIter *iter; - RIOUndoWrite *u = NULL; +RZ_API int rz_io_wundo_set(RzIO *io, int n, int set) { + RzListIter *iter; + RzIOUndoWrite *u = NULL; int i = 0; if (io->undo.w_init) { - r_list_foreach_prev (io->undo.w_list, iter, u) { + rz_list_foreach_prev (io->undo.w_list, iter, u) { if (i++ == n) { break; } } if (u) { // wtf? - r_io_wundo_apply (io, u, set); + rz_io_wundo_apply (io, u, set); return true; } eprintf ("invalid undo-write index\n"); diff --git a/libr/io/undo.h b/librz/io/undo.h similarity index 100% rename from libr/io/undo.h rename to librz/io/undo.h diff --git a/libr/lang/Makefile b/librz/lang/Makefile similarity index 68% rename from libr/lang/Makefile rename to librz/lang/Makefile index 90f35a30f2..7fdde3bfa6 100644 --- a/libr/lang/Makefile +++ b/librz/lang/Makefile @@ -1,8 +1,8 @@ include ../config.mk -NAME=r_lang +NAME=rz_lang OBJS=lang.o -R2DEPS=r_util r_cons +R2DEPS=rz_util rz_cons include ../rules.mk CFLAGS+=-I$(SHLR)/spp diff --git a/libr/lang/lang.c b/librz/lang/lang.c similarity index 53% rename from libr/lang/lang.c rename to librz/lang/lang.c index a368970bc0..45abcdc103 100644 --- a/libr/lang/lang.c +++ b/librz/lang/lang.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include -#include +#include +#include -R_LIB_VERSION(r_lang); +R_LIB_VERSION(rz_lang); #include "p/pipe.c" // hardcoded #include "p/vala.c" // hardcoded @@ -16,53 +16,53 @@ R_LIB_VERSION(r_lang); #include "p/cpipe.c" // hardcoded #endif -static RLang *__lang = NULL; +static RzLang *__lang = NULL; -R_API void r_lang_plugin_free (RLangPlugin *p) { +RZ_API void rz_lang_plugin_free (RzLangPlugin *p) { if (p && p->fini) { p->fini (__lang); } } -R_API RLang *r_lang_new(void) { - RLang *lang = R_NEW0 (RLang); +RZ_API RzLang *rz_lang_new(void) { + RzLang *lang = R_NEW0 (RzLang); if (!lang) { return NULL; } lang->user = NULL; - lang->langs = r_list_new (); + lang->langs = rz_list_new (); if (!lang->langs) { - r_lang_free (lang); + rz_lang_free (lang); return NULL; } - lang->langs->free = (RListFree)r_lang_plugin_free; - lang->defs = r_list_new (); + lang->langs->free = (RzListFree)rz_lang_plugin_free; + lang->defs = rz_list_new (); if (!lang->defs) { - r_lang_free (lang); + rz_lang_free (lang); return NULL; } - lang->defs->free = (RListFree)r_lang_def_free; + lang->defs->free = (RzListFree)rz_lang_def_free; lang->cb_printf = (PrintfCallback)printf; #if __UNIX__ - r_lang_add (lang, &r_lang_plugin_c); - r_lang_add (lang, &r_lang_plugin_cpipe); + rz_lang_add (lang, &rz_lang_plugin_c); + rz_lang_add (lang, &rz_lang_plugin_cpipe); #endif - r_lang_add (lang, &r_lang_plugin_vala); - r_lang_add (lang, &r_lang_plugin_rust); - r_lang_add (lang, &r_lang_plugin_zig); - r_lang_add (lang, &r_lang_plugin_spp); - r_lang_add (lang, &r_lang_plugin_pipe); - r_lang_add (lang, &r_lang_plugin_lib); + rz_lang_add (lang, &rz_lang_plugin_vala); + rz_lang_add (lang, &rz_lang_plugin_rust); + rz_lang_add (lang, &rz_lang_plugin_zig); + rz_lang_add (lang, &rz_lang_plugin_spp); + rz_lang_add (lang, &rz_lang_plugin_pipe); + rz_lang_add (lang, &rz_lang_plugin_lib); return lang; } -R_API void r_lang_free(RLang *lang) { +RZ_API void rz_lang_free(RzLang *lang) { if (lang) { __lang = NULL; - r_lang_undef (lang, NULL); - r_list_free (lang->langs); - r_list_free (lang->defs); + rz_lang_undef (lang, NULL); + rz_list_free (lang->langs); + rz_list_free (lang->defs); // TODO: remove langs plugins free (lang); } @@ -72,79 +72,79 @@ R_API void r_lang_free(RLang *lang) { // TODO: when language bindings are done we will need an api to // define symbols from C to the language namespace // XXX: Depcreate!! -R_API void r_lang_set_user_ptr(RLang *lang, void *user) { +RZ_API void rz_lang_set_user_ptr(RzLang *lang, void *user) { lang->user = user; } -R_API bool r_lang_define(RLang *lang, const char *type, const char *name, void *value) { - RLangDef *def; - RListIter *iter; - r_list_foreach (lang->defs, iter, def) { - if (!r_str_casecmp (name, def->name)) { +RZ_API bool rz_lang_define(RzLang *lang, const char *type, const char *name, void *value) { + RzLangDef *def; + RzListIter *iter; + rz_list_foreach (lang->defs, iter, def) { + if (!rz_str_casecmp (name, def->name)) { def->value = value; return true; } } - def = R_NEW0 (RLangDef); + def = R_NEW0 (RzLangDef); if (!def) { return false; } def->type = strdup (type); def->name = strdup (name); def->value = value; - r_list_append (lang->defs, def); + rz_list_append (lang->defs, def); return true; } -R_API void r_lang_def_free (RLangDef *def) { +RZ_API void rz_lang_def_free (RzLangDef *def) { free (def->name); free (def->type); free (def); } -R_API void r_lang_undef(RLang *lang, const char *name) { +RZ_API void rz_lang_undef(RzLang *lang, const char *name) { if (name && *name) { - RLangDef *def; - RListIter *iter; + RzLangDef *def; + RzListIter *iter; /* No _safe loop necessary because we return immediately after the delete. */ - r_list_foreach (lang->defs, iter, def) { - if (!name || !r_str_casecmp (name, def->name)) { - r_list_delete (lang->defs, iter); + rz_list_foreach (lang->defs, iter, def) { + if (!name || !rz_str_casecmp (name, def->name)) { + rz_list_delete (lang->defs, iter); break; } } } else { - r_list_free (lang->defs); + rz_list_free (lang->defs); lang->defs = NULL; } } -R_API bool r_lang_setup(RLang *lang) { +RZ_API bool rz_lang_setup(RzLang *lang) { if (lang && lang->cur && lang->cur->setup) { return lang->cur->setup (lang); } return false; } -R_API bool r_lang_add(RLang *lang, RLangPlugin *foo) { - if (foo && (!r_lang_get_by_name (lang, foo->name))) { +RZ_API bool rz_lang_add(RzLang *lang, RzLangPlugin *foo) { + if (foo && (!rz_lang_get_by_name (lang, foo->name))) { if (foo->init) { foo->init (lang); } - r_list_append (lang->langs, foo); + rz_list_append (lang->langs, foo); return true; } return false; } /* TODO: deprecate all list methods */ -R_API bool r_lang_list(RLang *lang) { - RListIter *iter; - RLangPlugin *h; +RZ_API bool rz_lang_list(RzLang *lang) { + RzListIter *iter; + RzLangPlugin *h; if (!lang) { return false; } - r_list_foreach (lang->langs, iter, h) { + rz_list_foreach (lang->langs, iter, h) { const char *license = h->license ? h->license : "???"; lang->cb_printf ("%s: (%s) %s\n", @@ -153,37 +153,37 @@ R_API bool r_lang_list(RLang *lang) { return true; } -R_API RLangPlugin *r_lang_get_by_extension (RLang *lang, const char *ext) { - RListIter *iter; - RLangPlugin *h; - const char *p = r_str_lchr (ext, '.'); +RZ_API RzLangPlugin *rz_lang_get_by_extension (RzLang *lang, const char *ext) { + RzListIter *iter; + RzLangPlugin *h; + const char *p = rz_str_lchr (ext, '.'); if (p) { ext = p + 1; } - r_list_foreach (lang->langs, iter, h) { - if (!r_str_casecmp (h->ext, ext)) { + rz_list_foreach (lang->langs, iter, h) { + if (!rz_str_casecmp (h->ext, ext)) { return h; } } return NULL; } -R_API RLangPlugin *r_lang_get_by_name (RLang *lang, const char *name) { - RListIter *iter; - RLangPlugin *h; - r_list_foreach (lang->langs, iter, h) { - if (!r_str_casecmp (h->name, name)) { +RZ_API RzLangPlugin *rz_lang_get_by_name (RzLang *lang, const char *name) { + RzListIter *iter; + RzLangPlugin *h; + rz_list_foreach (lang->langs, iter, h) { + if (!rz_str_casecmp (h->name, name)) { return h; } - if (h->alias && !r_str_casecmp (h->alias, name)) { + if (h->alias && !rz_str_casecmp (h->alias, name)) { return h; } } return NULL; } -R_API bool r_lang_use(RLang *lang, const char *name) { - RLangPlugin *h = r_lang_get_by_name (lang, name); +RZ_API bool rz_lang_use(RzLang *lang, const char *name) { + RzLangPlugin *h = rz_lang_get_by_name (lang, name); if (h) { lang->cur = h; return true; @@ -191,32 +191,32 @@ R_API bool r_lang_use(RLang *lang, const char *name) { return false; } -// TODO: store in r_lang and use it from the plugin? -R_API bool r_lang_set_argv(RLang *lang, int argc, char **argv) { +// TODO: store in rz_lang and use it from the plugin? +RZ_API bool rz_lang_set_argv(RzLang *lang, int argc, char **argv) { if (lang->cur && lang->cur->set_argv) { return lang->cur->set_argv (lang, argc, argv); } return false; } -R_API int r_lang_run(RLang *lang, const char *code, int len) { +RZ_API int rz_lang_run(RzLang *lang, const char *code, int len) { if (lang->cur && lang->cur->run) { return lang->cur->run (lang, code, len); } return false; } -R_API int r_lang_run_string(RLang *lang, const char *code) { - return r_lang_run (lang, code, strlen (code)); +RZ_API int rz_lang_run_string(RzLang *lang, const char *code) { + return rz_lang_run (lang, code, strlen (code)); } -R_API int r_lang_run_file(RLang *lang, const char *file) { +RZ_API int rz_lang_run_file(RzLang *lang, const char *file) { int ret = false; if (lang->cur) { if (!lang->cur->run_file) { if (lang->cur->run) { size_t len; - char *code = r_file_slurp (file, &len); + char *code = rz_file_slurp (file, &len); if (!code) { eprintf ("Could not open '%s'.\n", file); return 0; @@ -232,7 +232,7 @@ R_API int r_lang_run_file(RLang *lang, const char *file) { } /* TODO: deprecate or make it more modular .. reading from stdin in a lib?!? wtf */ -R_API int r_lang_prompt(RLang *lang) { +RZ_API int rz_lang_prompt(RzLang *lang) { char buf[1024]; const char *p; @@ -246,7 +246,7 @@ R_API int r_lang_prompt(RLang *lang) { } } /* init line */ - RLine *line = r_line_singleton (); + RLine *line = rz_line_singleton (); RLineHistory hist = line->history; RLineHistory histnull = {0}; RLineCompletion oc = line->completion; @@ -257,41 +257,41 @@ R_API int r_lang_prompt(RLang *lang) { /* foo */ for (;;) { - r_cons_flush (); + rz_cons_flush (); snprintf (buf, sizeof (buf)-1, "%s> ", lang->cur->name); - r_line_set_prompt (buf); + rz_line_set_prompt (buf); #if 0 printf ("%s> ", lang->cur->name); fflush (stdout); fgets (buf, sizeof (buf), stdin); if (feof (stdin)) break; - r_str_trim_tail (buf); + rz_str_trim_tail (buf); #endif - p = r_line_readline (); + p = rz_line_readline (); if (!p) { break; } - r_line_hist_add (p); + rz_line_hist_add (p); strncpy (buf, p, sizeof (buf) - 1); if (*buf == '!') { if (buf[1]) { - r_sandbox_system (buf + 1, 1); + rz_sandbox_system (buf + 1, 1); } else { char *foo, *code = NULL; do { - foo = r_cons_editor (NULL, code); - r_lang_run (lang, foo, 0); + foo = rz_cons_editor (NULL, code); + rz_lang_run (lang, foo, 0); free (code); code = foo; - } while (r_cons_yesno ('y', "Edit again? (Y/n)")); + } while (rz_cons_yesno ('y', "Edit again? (Y/n)")); free (foo); } continue; } if (!memcmp (buf, ". ", 2)) { - char *file = r_file_abspath (buf+2); + char *file = rz_file_abspath (buf+2); if (file) { - r_lang_run_file (lang, file); + rz_lang_run_file (lang, file); free (file); } continue; @@ -301,8 +301,8 @@ R_API int r_lang_prompt(RLang *lang) { return true; } if (!strcmp (buf, "?")) { - RLangDef *def; - RListIter *iter; + RzLangDef *def; + RzListIter *iter; eprintf(" ? - show this help message\n" " ! - run $EDITOR\n" " !command - run system command\n" @@ -312,18 +312,18 @@ R_API int r_lang_prompt(RLang *lang) { if (lang->cur->help) { eprintf ("%s", *lang->cur->help); } - if (!r_list_empty (lang->defs)) { + if (!rz_list_empty (lang->defs)) { eprintf ("variables:\n"); } - r_list_foreach (lang->defs, iter, def) { + rz_list_foreach (lang->defs, iter, def) { eprintf (" %s %s\n", def->type, def->name); } } else { - r_lang_run (lang, buf, strlen (buf)); + rz_lang_run (lang, buf, strlen (buf)); } } // XXX: leaking history - r_line_set_prompt (prompt); + rz_line_set_prompt (prompt); line->completion = oc; line->history = hist; clearerr (stdin); diff --git a/libr/lang/meson.build b/librz/lang/meson.build similarity index 67% rename from libr/lang/meson.build rename to librz/lang/meson.build index 0ca50af590..0d11af9da3 100644 --- a/libr/lang/meson.build +++ b/librz/lang/meson.build @@ -1,4 +1,4 @@ -r_lang_sources = [ +rz_lang_sources = [ 'lang.c', # included in lang.c #'p/c.c', @@ -13,28 +13,28 @@ r_lang_sources = [ spp_inc = [platform_inc, include_directories('../../shlr/spp')] -r_lang = library('r_lang', r_lang_sources, +rz_lang = library('rz_lang', rz_lang_sources, include_directories: [platform_inc, spp_inc], c_args: library_cflags, - dependencies: [r_util_dep, r_cons_dep], + dependencies: [rz_util_dep, rz_cons_dep], install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_lang_dep = declare_dependency(link_with: r_lang, +rz_lang_dep = declare_dependency(link_with: rz_lang, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_lang, - subdirs: 'libr', +pkgconfig_mod.generate(rz_lang, + subdirs: 'librz', version: r2_version, - name: 'r_lang', - filebase: 'r_lang', + name: 'rz_lang', + filebase: 'rz_lang', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_cons' + 'rz_util', + 'rz_cons' ], description: 'radare foundation libraries' ) diff --git a/libr/lang/p/Makefile b/librz/lang/p/Makefile similarity index 100% rename from libr/lang/p/Makefile rename to librz/lang/p/Makefile diff --git a/libr/lang/p/c.c b/librz/lang/p/c.c similarity index 55% rename from libr/lang/p/c.c rename to librz/lang/p/c.c index f5c786c10e..0d95ec25a1 100644 --- a/libr/lang/p/c.c +++ b/librz/lang/p/c.c @@ -1,22 +1,22 @@ /* radare - LGPL - Copyright 2011-2017 pancake */ -/* vala extension for libr (radare2) */ +/* vala extension for librz (rizin) */ // TODO: add cache directory (~/.r2/cache) -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" #if __UNIX__ static int ac = 0; static const char **av = NULL; -static bool lang_c_set_argv(RLang *lang, int argc, const char **argv) { +static bool lang_c_set_argv(RzLang *lang, int argc, const char **argv) { ac = argc; av = argv; return true; } -static int lang_c_file(RLang *lang, const char *file) { +static int lang_c_file(RzLang *lang, const char *file) { char *a, *cc, *p, name[512]; const char *libpath, *libname; void *lib; @@ -29,12 +29,12 @@ static int lang_c_file(RLang *lang, const char *file) { } else { strcpy (name, file); } - if (!r_file_exists (name)) { + if (!rz_file_exists (name)) { eprintf ("file not found (%s)\n", name); return false; } - a = (char*)r_str_lchr (name, '/'); + a = (char*)rz_str_lchr (name, '/'); if (a) { *a = 0; libpath = name; @@ -47,30 +47,30 @@ static int lang_c_file(RLang *lang, const char *file) { if (p) { *p = 0; } - cc = r_sys_getenv ("CC"); + cc = rz_sys_getenv ("CC"); if (R_STR_ISEMPTY (cc)) { cc = strdup ("gcc"); } - char *file_esc = r_str_escape_sh (file); - char *libpath_esc = r_str_escape_sh (libpath); - char *libname_esc = r_str_escape_sh (libname); - char *buf = r_str_newf ("%s -fPIC -shared \"%s\" -o \"%s/lib%s." R_LIB_EXT "\"" - " $(PKG_CONFIG_PATH=%s pkg-config --cflags --libs r_core)", + char *file_esc = rz_str_escape_sh (file); + char *libpath_esc = rz_str_escape_sh (libpath); + char *libname_esc = rz_str_escape_sh (libname); + char *buf = rz_str_newf ("%s -fPIC -shared \"%s\" -o \"%s/lib%s." R_LIB_EXT "\"" + " $(PKG_CONFIG_PATH=%s pkg-config --cflags --libs rz_core)", cc, file_esc, libpath_esc, libname_esc, R2_LIBDIR "/pkgconfig"); free (libname_esc); free (libpath_esc); free (file_esc); free (cc); - if (r_sandbox_system (buf, 1) != 0) { + if (rz_sandbox_system (buf, 1) != 0) { free (buf); return false; } free (buf); - buf = r_str_newf ("%s/lib%s."R_LIB_EXT, libpath, libname); - lib = r_lib_dl_open (buf); + buf = rz_str_newf ("%s/lib%s."R_LIB_EXT, libpath, libname); + lib = rz_lib_dl_open (buf); if (lib) { - void (*fcn)(RCore *, int argc, const char **argv); - fcn = r_lib_dl_sym (lib, "entry"); + void (*fcn)(RzCore *, int argc, const char **argv); + fcn = rz_lib_dl_sym (lib, "entry"); if (fcn) { fcn (lang->user, ac, av); ac = 0; @@ -78,11 +78,11 @@ static int lang_c_file(RLang *lang, const char *file) { } else { eprintf ("Cannot find 'entry' symbol in library\n"); } - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else { eprintf ("Cannot open library\n"); } - r_file_rm (buf); // remove lib + rz_file_rm (buf); // remove lib free (buf); return 0; } @@ -92,20 +92,20 @@ static int lang_c_init(void *user) { return true; } -static int lang_c_run(RLang *lang, const char *code, int len) { - FILE *fd = r_sandbox_fopen (".tmp.c", "w"); +static int lang_c_run(RzLang *lang, const char *code, int len) { + FILE *fd = rz_sandbox_fopen (".tmp.c", "w"); if (fd) { - fputs ("#include \n\nvoid entry(RCore *core, int argc, const char **argv) {\n", fd); + fputs ("#include \n\nvoid entry(RzCore *core, int argc, const char **argv) {\n", fd); fputs (code, fd); fputs ("\n}\n", fd); fclose (fd); lang_c_file (lang, ".tmp.c"); - r_file_rm (".tmp.c"); + rz_file_rm (".tmp.c"); } else eprintf ("Cannot open .tmp.c\n"); return true; } -static RLangPlugin r_lang_plugin_c = { +static RzLangPlugin rz_lang_plugin_c = { .name = "c", .ext = "c", .desc = "C language extension", @@ -117,8 +117,8 @@ static RLangPlugin r_lang_plugin_c = { }; #else #ifdef _MSC_VER -#pragma message("Warning: C RLangPlugin is not implemented on this platform") +#pragma message("Warning: C RzLangPlugin is not implemented on this platform") #else -#warning C RLangPlugin is not implemented on this platform +#warning C RzLangPlugin is not implemented on this platform #endif #endif diff --git a/libr/lang/p/cpipe.c b/librz/lang/p/cpipe.c similarity index 51% rename from libr/lang/p/cpipe.c rename to librz/lang/p/cpipe.c index 99db0caa34..50634a7fe5 100644 --- a/libr/lang/p/cpipe.c +++ b/librz/lang/p/cpipe.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2011-2019 pancake */ -/* vala extension for libr (radare2) */ +/* vala extension for librz (rizin) */ // TODO: add cache directory (~/.r2/cache) -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" #if __UNIX__ -static int lang_cpipe_file(RLang *lang, const char *file) { +static int lang_cpipe_file(RzLang *lang, const char *file) { char *a, *cc, *p, name[512]; const char *libpath, *libname; @@ -19,12 +19,12 @@ static int lang_cpipe_file(RLang *lang, const char *file) { } else { strcpy (name, file); } - if (!r_file_exists (name)) { + if (!rz_file_exists (name)) { eprintf ("file not found (%s)\n", name); return false; } - a = (char*)r_str_lchr (name, '/'); + a = (char*)rz_str_lchr (name, '/'); if (a) { *a = 0; libpath = name; @@ -37,28 +37,28 @@ static int lang_cpipe_file(RLang *lang, const char *file) { if (p) { *p = 0; } - cc = r_sys_getenv ("CC"); + cc = rz_sys_getenv ("CC"); if (R_STR_ISEMPTY (cc)) { free (cc); cc = strdup ("gcc"); } - char *file_esc = r_str_escape_sh (file); - char *libpath_esc = r_str_escape_sh (libpath); - char *libname_esc = r_str_escape_sh (libname); - char *buf = r_str_newf ("%s \"%s\" -o \"%s/bin%s\"" - " $(PKG_CONFIG_PATH=%s pkg-config --cflags --libs r_socket)", + char *file_esc = rz_str_escape_sh (file); + char *libpath_esc = rz_str_escape_sh (libpath); + char *libname_esc = rz_str_escape_sh (libname); + char *buf = rz_str_newf ("%s \"%s\" -o \"%s/bin%s\"" + " $(PKG_CONFIG_PATH=%s pkg-config --cflags --libs rz_socket)", cc, file_esc, libpath_esc, libname_esc, R2_LIBDIR "/pkgconfig"); free (libname_esc); free (libpath_esc); free (file_esc); free (cc); - if (r_sandbox_system (buf, 1) == 0) { - char *o_ld_path = r_sys_getenv ("LD_LIBRARY_PATH"); - r_sys_setenv ("LD_LIBRARY_PATH", R2_LIBDIR); - char *binfile = r_str_newf ("%s/bin%s", libpath, libname); + if (rz_sandbox_system (buf, 1) == 0) { + char *o_ld_path = rz_sys_getenv ("LD_LIBRARY_PATH"); + rz_sys_setenv ("LD_LIBRARY_PATH", R2_LIBDIR); + char *binfile = rz_str_newf ("%s/bin%s", libpath, libname); lang_pipe_run (lang, binfile, -1); - r_file_rm (binfile); - r_sys_setenv ("LD_LIBRARY_PATH", o_ld_path); + rz_file_rm (binfile); + rz_sys_setenv ("LD_LIBRARY_PATH", o_ld_path); free (o_ld_path); free (binfile); } @@ -71,28 +71,28 @@ static int lang_cpipe_init(void *user) { return true; } -static int lang_cpipe_run(RLang *lang, const char *code, int len) { - FILE *fd = r_sandbox_fopen (".tmp.c", "w"); +static int lang_cpipe_run(RzLang *lang, const char *code, int len) { + FILE *fd = rz_sandbox_fopen (".tmp.c", "w"); if (!fd) { eprintf ("Cannot open .tmp.c\n"); return false; } - fputs ("#include \n\n" - "#define R2P(x,y...) r2pipe_cmdf(r2p,x,##y)\n" + fputs ("#include \n\n" + "#define R2P(x,y...) rzpipe_cmdf(r2p,x,##y)\n" "int main() {\n" - " R2Pipe *r2p = r2pipe_open(NULL);", fd); + " R2Pipe *r2p = rzpipe_open(NULL);", fd); fputs (code, fd); fputs ("\n}\n", fd); fclose (fd); lang_cpipe_file (lang, ".tmp.c"); - r_file_rm (".tmp.c"); + rz_file_rm (".tmp.c"); return true; } -static RLangPlugin r_lang_plugin_cpipe = { +static RzLangPlugin rz_lang_plugin_cpipe = { .name = "cpipe", .ext = "c2", - .desc = "r2pipe scripting in C", + .desc = "rzpipe scripting in C", .license = "LGPL", .run = lang_cpipe_run, .init = (void*)lang_cpipe_init, @@ -101,8 +101,8 @@ static RLangPlugin r_lang_plugin_cpipe = { }; #else #ifdef _MSC_VER -#pragma message("Warning: cpipe RLangPlugin is not implemented on this platform") +#pragma message("Warning: cpipe RzLangPlugin is not implemented on this platform") #else -#warning cpipe RLangPlugin is not implemented on this platform +#warning cpipe RzLangPlugin is not implemented on this platform #endif #endif diff --git a/librz/lang/p/lib.c b/librz/lang/p/lib.c new file mode 100644 index 0000000000..c81ee98978 --- /dev/null +++ b/librz/lang/p/lib.c @@ -0,0 +1,52 @@ +/* radare - LPGL - Copyright 2017 condret */ + +#include +#include +#include + +static int lang_lib_init (RzLang *user) { + return true; +} + +static int lang_lib_file_run (RzLang *user, const char *file) { + char *libpath; + void *lib; + if (!(libpath = rz_str_new (file))) { + return -1; + } + if (!rz_str_startswith (libpath, "/") && !rz_str_startswith (libpath, "./")) { + libpath = rz_str_prepend (libpath, "./"); + } + if (!rz_file_exists (libpath)) { + if (!rz_str_endswith (libpath, R_LIB_EXT)) { + libpath = rz_str_appendf (libpath, ".%s", R_LIB_EXT); + } + } + if (!rz_file_exists (libpath)) { + free (libpath); + return -1; + } + + lib = rz_lib_dl_open (libpath); + if (lib) { + void (*fcn)(RzCore *); + fcn = rz_lib_dl_sym (lib, "entry"); + if (fcn) { + fcn (user->user); + } else { + eprintf ("Cannot find 'entry' symbol in library\n"); + } + rz_lib_dl_close (lib); + } + free (libpath); + return 0; +} + +static RzLangPlugin rz_lang_plugin_lib = { + .name = "lib", + .ext = R_LIB_EXT, + .desc = "Load libs directly into r2", + .license = "LGPL", + .init = lang_lib_init, + .run_file = lang_lib_file_run, +}; diff --git a/libr/lang/p/pipe-bash.sh b/librz/lang/p/pipe-bash.sh similarity index 100% rename from libr/lang/p/pipe-bash.sh rename to librz/lang/p/pipe-bash.sh diff --git a/libr/lang/p/pipe-node.js b/librz/lang/p/pipe-node.js similarity index 100% rename from libr/lang/p/pipe-node.js rename to librz/lang/p/pipe-node.js diff --git a/libr/lang/p/pipe.c b/librz/lang/p/pipe.c similarity index 74% rename from libr/lang/p/pipe.c rename to librz/lang/p/pipe.c index 3abecba2b7..5f2dacdfd7 100644 --- a/libr/lang/p/pipe.c +++ b/librz/lang/p/pipe.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2015-2019 pancake */ +/* rizin - LGPL - Copyright 2015-2019 pancake */ -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" #if __WINDOWS__ #include #endif @@ -10,8 +10,8 @@ #include #endif -static int lang_pipe_run(RLang *lang, const char *code, int len); -static int lang_pipe_file(RLang *lang, const char *file) { +static int lang_pipe_run(RzLang *lang, const char *code, int len); +static int lang_pipe_file(RzLang *lang, const char *file) { return lang_pipe_run (lang, file, -1); } @@ -26,7 +26,7 @@ static HANDLE myCreateChildProcess(const char * szCmdline) { siStartInfo.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); siStartInfo.hStdError = GetStdHandle (STD_ERROR_HANDLE); - LPTSTR cmdline_ = r_sys_conv_utf8_to_win (szCmdline); + LPTSTR cmdline_ = rz_sys_conv_utf8_to_win (szCmdline); bSuccess = CreateProcess (NULL, cmdline_, NULL, NULL, TRUE, 0, NULL, NULL, &siStartInfo, &piProcInfo); free (cmdline_); @@ -37,25 +37,25 @@ static HANDLE hPipeInOut = NULL; static HANDLE hproc = NULL; #define PIPE_BUF_SIZE 8192 -static void lang_pipe_run_win(RLang *lang) { +static void lang_pipe_run_win(RzLang *lang) { CHAR buf[PIPE_BUF_SIZE]; BOOL bSuccess = TRUE; int i, res = 0; DWORD dwRead = 0, dwWritten = 0, dwEvent; HANDLE hRead = CreateEvent (NULL, TRUE, FALSE, NULL); if (!hRead) { - r_sys_perror ("lang_pipe_run_win/CreateEvent hRead"); + rz_sys_perror ("lang_pipe_run_win/CreateEvent hRead"); return; } HANDLE hWritten = CreateEvent (NULL, TRUE, FALSE, NULL); if (!hWritten) { - r_sys_perror ("lang_pipe_run_win/CreateEvent hWritten"); + rz_sys_perror ("lang_pipe_run_win/CreateEvent hWritten"); CloseHandle (hRead); return; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); do { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { TerminateProcess (hproc, 0); break; } @@ -69,7 +69,7 @@ static void lang_pipe_run_win(RLang *lang) { if (dwEvent == WAIT_OBJECT_0 + 1) { // hproc break; } else if (dwEvent == WAIT_FAILED) { - r_sys_perror ("lang_pipe_run_win/WaitForMultipleObjects read"); + rz_sys_perror ("lang_pipe_run_win/WaitForMultipleObjects read"); break; } bSuccess = GetOverlappedResult (hPipeInOut, &oRead, &dwRead, TRUE); @@ -80,7 +80,7 @@ static void lang_pipe_run_win(RLang *lang) { buf[sizeof (buf) - 1] = 0; OVERLAPPED oWrite = { 0 }; oWrite.hEvent = hWritten; - char *res = lang->cmd_str ((RCore*)lang->user, buf); + char *res = lang->cmd_str ((RzCore*)lang->user, buf); if (res) { int res_len = strlen (res) + 1; for (i = 0; i < res_len; i++) { @@ -96,17 +96,17 @@ static void lang_pipe_run_win(RLang *lang) { if (dwEvent == WAIT_OBJECT_0 + 1) { // hproc break; } else if (dwEvent == WAIT_FAILED) { - r_sys_perror ("lang_pipe_run_win/WaitForMultipleObjects write"); + rz_sys_perror ("lang_pipe_run_win/WaitForMultipleObjects write"); } BOOL rc = GetOverlappedResult (hPipeInOut, &oWrite, &dwWritten, TRUE); if (!rc) { - r_sys_perror ("lang_pipe_run_win/WriteFile res"); + rz_sys_perror ("lang_pipe_run_win/WriteFile res"); } if (dwWritten > 0) { i += dwWritten - 1; } else { // send null termination // chop - r_sys_perror ("lang_pipe_run_win/dwWritten"); + rz_sys_perror ("lang_pipe_run_win/dwWritten"); //WriteFile (hPipeInOut, "", 1, &dwWritten, NULL); //break; } @@ -115,25 +115,25 @@ static void lang_pipe_run_win(RLang *lang) { } else { WriteFile (hPipeInOut, "", 1, NULL, &oWrite); if (!GetOverlappedResult (hPipeInOut, &oWrite, &dwWritten, TRUE)) { - r_sys_perror ("lang_pipe_run_win/WriteFile nul"); + rz_sys_perror ("lang_pipe_run_win/WriteFile nul"); } } } } while (true); - r_cons_break_pop (); + rz_cons_break_pop (); CloseHandle (hWritten); CloseHandle (hRead); } #else static void env(const char *s, int f) { - char *a = r_str_newf ("%d", f); - r_sys_setenv (s, a); + char *a = rz_str_newf ("%d", f); + rz_sys_setenv (s, a); // eprintf ("%s %s\n", s, a); free (a); } #endif -static int lang_pipe_run(RLang *lang, const char *code, int len) { +static int lang_pipe_run(RzLang *lang, const char *code, int len) { #if __UNIX__ int safe_in = dup (0); int child, ret; @@ -141,14 +141,14 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { int output[2]; if (pipe (input) != 0) { - eprintf ("r_lang_pipe: pipe failed on input\n"); + eprintf ("rz_lang_pipe: pipe failed on input\n"); if (safe_in != -1) { close (safe_in); } return false; } if (pipe (output) != 0) { - eprintf ("r_lang_pipe: pipe failed on output\n"); + eprintf ("rz_lang_pipe: pipe failed on output\n"); if (safe_in != -1) { close (safe_in); } @@ -158,13 +158,13 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { env ("R2PIPE_IN", input[0]); env ("R2PIPE_OUT", output[1]); - child = r_sys_fork (); + child = rz_sys_fork (); if (child == -1) { /* error */ perror ("pipe run"); } else if (!child) { /* children */ - r_sandbox_system (code, 1); + rz_sandbox_system (code, 1); (void) write (input[1], "", 1); close (input[0]); close (input[1]); @@ -172,7 +172,7 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { close (output[1]); fflush (stdout); fflush (stderr); - r_sys_exit (0, true); + rz_sys_exit (0, true); return false; } else { /* parent */ @@ -180,15 +180,15 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { /* Close pipe ends not required in the parent */ close (output[1]); close (input[0]); - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } memset (buf, 0, sizeof (buf)); - void *bed = r_cons_sleep_begin (); + void *bed = rz_cons_sleep_begin (); ret = read (output[0], buf, sizeof (buf) - 1); - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (ret < 1) { break; } @@ -196,17 +196,17 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { continue; } buf[sizeof (buf) - 1] = 0; - res = lang->cmd_str ((RCore*)lang->user, buf); + res = lang->cmd_str ((RzCore*)lang->user, buf); //eprintf ("%d %s\n", ret, buf); if (res) { (void) write (input[1], res, strlen (res) + 1); free (res); } else { - eprintf ("r_lang_pipe: NULL reply for (%s)\n", buf); + eprintf ("rz_lang_pipe: NULL reply for (%s)\n", buf); (void) write (input[1], "", 1); // NULL byte } } - r_cons_break_pop (); + rz_cons_break_pop (); /* workaround to avoid stdin closed */ if (safe_in != -1) { close (safe_in); @@ -234,24 +234,24 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { return true; #else #if __WINDOWS__ - char *r2pipe_var = r_str_newf ("R2PIPE_IN%x", _getpid ()); - char *r2pipe_paz = r_str_newf ("\\\\.\\pipe\\%s", r2pipe_var); - LPTSTR r2pipe_paz_ = r_sys_conv_utf8_to_win (r2pipe_paz); + char *rzpipe_var = rz_str_newf ("R2PIPE_IN%x", _getpid ()); + char *rzpipe_paz = rz_str_newf ("\\\\.\\pipe\\%s", rzpipe_var); + LPTSTR rzpipe_paz_ = rz_sys_conv_utf8_to_win (rzpipe_paz); - SetEnvironmentVariable (TEXT ("R2PIPE_PATH"), r2pipe_paz_); - hPipeInOut = CreateNamedPipe (r2pipe_paz_, + SetEnvironmentVariable (TEXT ("R2PIPE_PATH"), rzpipe_paz_); + hPipeInOut = CreateNamedPipe (rzpipe_paz_, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, PIPE_BUF_SIZE, PIPE_BUF_SIZE, 0, NULL); if (hPipeInOut == INVALID_HANDLE_VALUE) { - r_sys_perror ("lang_pipe_run/CreateNamedPipe"); + rz_sys_perror ("lang_pipe_run/CreateNamedPipe"); goto beach; } HANDLE hConnected = CreateEvent (NULL, TRUE, FALSE, NULL); if (!hConnected) { - r_sys_perror ("lang_pipe_run/CreateEvent hConnected"); + rz_sys_perror ("lang_pipe_run/CreateEvent hConnected"); goto pipe_cleanup; } OVERLAPPED oConnect = { 0 }; @@ -269,7 +269,7 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { if (dwEvent == WAIT_OBJECT_0 + 1) { // hproc goto cleanup; } else if (dwEvent == WAIT_FAILED) { - r_sys_perror ("lang_pipe_run/WaitForMultipleObjects connect"); + rz_sys_perror ("lang_pipe_run/WaitForMultipleObjects connect"); goto cleanup; } DWORD dummy; @@ -277,7 +277,7 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { err = GetLastError (); } if (!connected && err != ERROR_PIPE_CONNECTED) { - r_sys_perror ("lang_pipe_run/ConnectNamedPipe"); + rz_sys_perror ("lang_pipe_run/ConnectNamedPipe"); goto cleanup; } } @@ -286,18 +286,18 @@ static int lang_pipe_run(RLang *lang, const char *code, int len) { cleanup: CloseHandle (hConnected); pipe_cleanup: - DeleteFile (r2pipe_paz_); + DeleteFile (rzpipe_paz_); CloseHandle (hPipeInOut); beach: - free (r2pipe_var); - free (r2pipe_paz); - free (r2pipe_paz_); + free (rzpipe_var); + free (rzpipe_paz); + free (rzpipe_paz_); return hproc != NULL; #endif #endif } -static RLangPlugin r_lang_plugin_pipe = { +static RzLangPlugin rz_lang_plugin_pipe = { .name = "pipe", .ext = "pipe", .license = "LGPL", diff --git a/libr/lang/p/rust.c b/librz/lang/p/rust.c similarity index 67% rename from libr/lang/p/rust.c rename to librz/lang/p/rust.c index a6af485543..9d9c0155c4 100644 --- a/libr/lang/p/rust.c +++ b/librz/lang/p/rust.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2016-2018 pancake */ -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" -static int lang_rust_file(RLang *lang, const char *file) { +static int lang_rust_file(RzLang *lang, const char *file) { void *lib; char *a, *cc, *p, name[512]; const char *libpath, *libname; @@ -17,12 +17,12 @@ static int lang_rust_file(RLang *lang, const char *file) { } else { strcpy (name, file); } - if (!r_file_exists (name)) { + if (!rz_file_exists (name)) { eprintf ("file not found (%s)\n", name); return false; } - a = (char*)r_str_lchr (name, '/'); + a = (char*)rz_str_lchr (name, '/'); if (a) { *a = 0; libpath = name; @@ -31,36 +31,36 @@ static int lang_rust_file(RLang *lang, const char *file) { libpath = "."; libname = name; } - r_sys_setenv ("PKG_CONFIG_PATH", R2_LIBDIR"/pkgconfig"); + rz_sys_setenv ("PKG_CONFIG_PATH", R2_LIBDIR"/pkgconfig"); p = strstr (name, ".rs"); if (p) *p=0; - cc = r_sys_getenv ("RUSTC"); + cc = rz_sys_getenv ("RUSTC"); if (cc && !*cc) { R_FREE (cc); } if (!cc) { cc = strdup ("rustc"); } - char *cmd = r_str_newf ("%s --crate-type dylib %s -o %s/lib%s."R_LIB_EXT" -L native=/usr/local/lib/ -l r_core", + char *cmd = rz_str_newf ("%s --crate-type dylib %s -o %s/lib%s."R_LIB_EXT" -L native=/usr/local/lib/ -l rz_core", cc, file, libpath, libname); free (cc); - if (r_sandbox_system (cmd, 1) != 0) { + if (rz_sandbox_system (cmd, 1) != 0) { free (cmd); return false; } free (cmd); - char *path = r_str_newf ("%s/lib%s."R_LIB_EXT, libpath, libname); - lib = r_lib_dl_open (path); + char *path = rz_str_newf ("%s/lib%s."R_LIB_EXT, libpath, libname); + lib = rz_lib_dl_open (path); if (lib!= NULL) { - void (*fcn)(RCore *); - fcn = r_lib_dl_sym (lib, "entry"); + void (*fcn)(RzCore *); + fcn = rz_lib_dl_sym (lib, "entry"); if (fcn) fcn (lang->user); else eprintf ("Cannot find 'entry' symbol in library\n"); - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else { eprintf ("Cannot open library\n"); } - r_file_rm (path); // remove lib + rz_file_rm (path); // remove lib free (path); return 0; } @@ -70,13 +70,13 @@ static int lang_rust_init(void *user) { return true; } -static int lang_rust_run(RLang *lang, const char *code, int len) { - FILE *fd = r_sandbox_fopen ("_tmp.rs", "w"); +static int lang_rust_run(RzLang *lang, const char *code, int len) { + FILE *fd = rz_sandbox_fopen ("_tmp.rs", "w"); if (fd) { const char *rust_header = \ "use std::ffi::CStr;\n" \ "extern {\n" \ -" pub fn r_core_cmd_str(core: *const u8, s: *const u8) -> *const u8;\n" \ +" pub fn rz_core_cmd_str(core: *const u8, s: *const u8) -> *const u8;\n" \ " pub fn free (ptr: *const u8);\n" \ "}\n" \ "\n" \ @@ -86,7 +86,7 @@ static int lang_rust_run(RLang *lang, const char *code, int len) { "impl R2 {\n" \ " fn cmdstr(&self, c: *const u8, str: &str) -> String {\n" \ " unsafe {\n" \ -" let ptr = r_core_cmd_str(c, str.as_ptr()) as *const i8;\n" \ +" let ptr = rz_core_cmd_str(c, str.as_ptr()) as *const i8;\n" \ " let c_str = CStr::from_ptr(ptr).to_string_lossy().into_owned();\n" \ " free (ptr as *const u8);\n" \ " String::from (c_str)\n" \ @@ -108,12 +108,12 @@ static int lang_rust_run(RLang *lang, const char *code, int len) { fputs (rust_footer, fd); fclose (fd); lang_rust_file (lang, "_tmp.rs"); - r_file_rm ("_tmp.rs"); + rz_file_rm ("_tmp.rs"); } else eprintf ("Cannot open _tmp.rs\n"); return true; } -static RLangPlugin r_lang_plugin_rust = { +static RzLangPlugin rz_lang_plugin_rust = { .name = "rust", .ext = "rs", .license = "MIT", diff --git a/librz/lang/p/spp.c b/librz/lang/p/spp.c new file mode 100644 index 0000000000..cd0c173258 --- /dev/null +++ b/librz/lang/p/spp.c @@ -0,0 +1,51 @@ +/* radare - LGPL - Copyright 2020 pancake */ + +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" +#define USE_R2 1 + +static RzLang *Glang = NULL; +#include +#include "spp_rz.inc" + +static int lang_spp_init(RzLang *l) { + Glang = l; + return true; +} + +static int lang_spp_run(RzLang *lang, const char *code, int len) { + Output out; + out.fout = NULL; + out.cout = rz_strbuf_new (NULL); + rz_strbuf_init (out.cout); + spp_proc_set (&spp_rz_proc, NULL, 0); + char *c = strdup (code); + spp_eval (c, &out); + free (c); + char *data = rz_strbuf_drain (out.cout); + rz_cons_printf ("%s\n", data); + free (data); + return true; +} + +static int lang_spp_file(RzLang *lang, const char *file) { + size_t len; + char *code = rz_file_slurp (file, &len); + if (code) { + int res = lang_spp_run (lang, code, len); + free (code); + return res; + } + return 0; +} + +static RzLangPlugin rz_lang_plugin_spp = { + .name = "spp", + .ext = "spp", + .license = "MIT", + .desc = "SPP template programs", + .run = lang_spp_run, + .init = (void*)lang_spp_init, + .run_file = (void*)lang_spp_file, +}; diff --git a/libr/lang/p/spp_r2.inc b/librz/lang/p/spp_rz.inc similarity index 57% rename from libr/lang/p/spp_r2.inc rename to librz/lang/p/spp_rz.inc index a1d535c8f1..e3c585ff53 100644 --- a/libr/lang/p/spp_r2.inc +++ b/librz/lang/p/spp_rz.inc @@ -1,16 +1,16 @@ /* SPP-R2, a template programming language with r2 integration */ -#include +#include -static char *spp_r2_var_get(char *var) { - return r_sys_getenv (var); +static char *spp_rz_var_get(char *var) { + return rz_sys_getenv (var); } -static int spp_r2_var_set(const char *var, const char *val) { - return r_sys_setenv (var, val); +static int spp_rz_var_set(const char *var, const char *val) { + return rz_sys_setenv (var, val); } -static TAG_CALLBACK(spp_r2_set) { +static TAG_CALLBACK(spp_rz_set) { char *eq, *val = ""; if (!state->echo[state->ifl]) { return 0; @@ -28,39 +28,39 @@ static TAG_CALLBACK(spp_r2_set) { *eq = '\0'; val = eq + 1; } - if (spp_r2_var_set (buf, val) == -1) { + if (spp_rz_var_set (buf, val) == -1) { fprintf (stderr, "Invalid variable name '%s' at line %d\n", buf, state->lineno); } return 0; } -static TAG_CALLBACK(spp_r2_get) { +static TAG_CALLBACK(spp_rz_get) { if (!state->echo[state->ifl]) { return 0; } - char *var = spp_r2_var_get (buf); + char *var = spp_rz_var_get (buf); if (var) { - r_cons_printf ("%s", var); + rz_cons_printf ("%s", var); free (var); } return 0; } -static TAG_CALLBACK(spp_r2_getrandom) { +static TAG_CALLBACK(spp_rz_getrandom) { if (!state->echo[state->ifl]) { return 0; } // XXX srsly? this is pretty bad random - srandom (r_sys_getpid ()); // TODO: change this to be portable + srandom (rz_sys_getpid ()); // TODO: change this to be portable int max = atoi (buf); if (max > 0) { max = (int)(rand () % max); } - r_cons_printf ("%d", max); + rz_cons_printf ("%d", max); return 0; } -static TAG_CALLBACK(spp_r2_add) { +static TAG_CALLBACK(spp_rz_add) { char *eq = strchr (buf, ' '); int ret = 0; if (!state->echo[state->ifl]) { @@ -68,14 +68,14 @@ static TAG_CALLBACK(spp_r2_add) { } if (eq) { *eq = '\0'; - char *var = spp_r2_var_get (buf); + char *var = spp_rz_var_get (buf); if (var) { ret = atoi (var); } ret += atoi (eq + 1); char res[32]; snprintf (res, sizeof (res), "%d", ret); - r_sys_setenv (buf, res); + rz_sys_setenv (buf, res); free (var); } else { eprintf ("/* syntax error */\n"); @@ -83,7 +83,7 @@ static TAG_CALLBACK(spp_r2_add) { return 0; } -static TAG_CALLBACK(spp_r2_sub) { +static TAG_CALLBACK(spp_rz_sub) { char *eq = strchr (buf, ' '); char *var; int ret = 0; @@ -92,17 +92,17 @@ static TAG_CALLBACK(spp_r2_sub) { } if (eq) { *eq = '\0'; - var = spp_r2_var_get (buf); + var = spp_rz_var_get (buf); ret = var? atoi (var): 0; ret -= atoi (eq + 1); - r_sys_setenv (buf, eq + 1); + rz_sys_setenv (buf, eq + 1); } else { /* syntax error */ } return ret; } -static TAG_CALLBACK(spp_r2_trace) { +static TAG_CALLBACK(spp_rz_trace) { if (state->echo[state->ifl]) { fprintf (stderr, "%.1000s\n", buf); } @@ -110,15 +110,15 @@ static TAG_CALLBACK(spp_r2_trace) { } /* TODO: deprecate */ -static TAG_CALLBACK(spp_r2_echo) { +static TAG_CALLBACK(spp_rz_echo) { if (state->echo[state->ifl]) { - r_cons_printf ("%s", buf); + rz_cons_printf ("%s", buf); } // TODO: add variable replacement here?? not necessary, done by {{get}} return 0; } -static TAG_CALLBACK(spp_r2_error) { +static TAG_CALLBACK(spp_rz_error) { if (!state->echo[state->ifl]) { return 0; } @@ -126,7 +126,7 @@ static TAG_CALLBACK(spp_r2_error) { return -1; } -static TAG_CALLBACK(spp_r2_warning) { +static TAG_CALLBACK(spp_rz_warning) { if (!state->echo[state->ifl]) { return 0; } @@ -134,28 +134,28 @@ static TAG_CALLBACK(spp_r2_warning) { return 0; } -static TAG_CALLBACK(spp_r2_r2) { +static TAG_CALLBACK(spp_rz_rz) { char *str = Glang->cmd_str (Glang->user, buf); if (str) { - r_cons_printf ("%s", str); + rz_cons_printf ("%s", str); free (str); } return 0; } -static TAG_CALLBACK(spp_r2_system) { +static TAG_CALLBACK(spp_rz_system) { if (!state->echo[state->ifl]) { return 0; } - char *str = r_sys_cmd_str (buf, NULL, NULL); + char *str = rz_sys_cmd_str (buf, NULL, NULL); if (str) { - r_cons_printf ("%s", str); + rz_cons_printf ("%s", str); free (str); } return 0; } -static TAG_CALLBACK(spp_r2_include) { +static TAG_CALLBACK(spp_rz_include) { if (!state->echo[state->ifl]) { return 0; } @@ -179,20 +179,20 @@ static TAG_CALLBACK(spp_r2_include) { return 0; } -static TAG_CALLBACK(spp_r2_if) { - char *var = spp_r2_var_get (buf); +static TAG_CALLBACK(spp_rz_if) { + char *var = spp_rz_var_get (buf); state->echo[state->ifl + 1] = (var && *var != '0' && *var != '\0') ? 1 : 0; free (var); return 1; } /* {{ ifeq $path / }} */ -static TAG_CALLBACK(spp_r2_ifeq) { +static TAG_CALLBACK(spp_rz_ifeq) { char *value = buf; char *eq = strchr (buf, ' '); if (eq) { *eq = '\0'; - value = spp_r2_var_get (value); + value = spp_rz_var_get (value); if (value && !strcmp (value, eq + 1)) { state->echo[state->ifl + 1] = 1; } else { @@ -200,7 +200,7 @@ static TAG_CALLBACK(spp_r2_ifeq) { } free (value); } else { - value = spp_r2_var_get (buf); + value = spp_rz_var_get (buf); if (!value || !*value) { state->echo[state->ifl + 1] = 1; } else { @@ -211,14 +211,14 @@ static TAG_CALLBACK(spp_r2_ifeq) { return 1; } -static TAG_CALLBACK(spp_r2_hex) { +static TAG_CALLBACK(spp_rz_hex) { size_t i; for (i = 0; buf[i]; i++) { if (isdigit (buf[i])) { int ch, b = buf[i + 2]; buf[i + 2] = '\0'; sscanf (buf + i, "%02x", &ch); - r_cons_printf ("%c", ch & 0xff); + rz_cons_printf ("%c", ch & 0xff); buf[i + 2] = b; buf = buf + 2; } @@ -226,7 +226,7 @@ static TAG_CALLBACK(spp_r2_hex) { return 0; } -static TAG_CALLBACK(spp_r2_grepline) { +static TAG_CALLBACK(spp_rz_grepline) { FILE *fd; char b[1024]; int line; @@ -246,7 +246,7 @@ static TAG_CALLBACK(spp_r2_grepline) { } } fclose (fd); - r_cons_printf ("%s", b); + rz_cons_printf ("%s", b); } else { eprintf ("Unable to open '%s'\n", buf); } @@ -254,18 +254,18 @@ static TAG_CALLBACK(spp_r2_grepline) { return 0; } -static TAG_CALLBACK(spp_r2_else) { +static TAG_CALLBACK(spp_rz_else) { state->echo[state->ifl] = state->echo[state->ifl] ? 0 : 1; return 0; } -static TAG_CALLBACK(spp_r2_ifnot) { - spp_r2_if (state, out, buf); - spp_r2_else (state, out, buf); +static TAG_CALLBACK(spp_rz_ifnot) { + spp_rz_if (state, out, buf); + spp_rz_else (state, out, buf); return 1; } -static TAG_CALLBACK(spp_r2_ifin) { +static TAG_CALLBACK(spp_rz_ifin) { char *var, *ptr; if (!state->echo[state->ifl]) { return 1; @@ -282,11 +282,11 @@ static TAG_CALLBACK(spp_r2_ifin) { return 1; } -static TAG_CALLBACK(spp_r2_endif) { +static TAG_CALLBACK(spp_rz_endif) { return -1; } -static TAG_CALLBACK(spp_r2_default) { +static TAG_CALLBACK(spp_rz_default) { if (!state->echo[state->ifl]) { return 0; } @@ -297,41 +297,41 @@ static TAG_CALLBACK(spp_r2_default) { } #if HAVE_SYSTEM -static FILE *spp_r2_pipe_fd = NULL; +static FILE *spp_rz_pipe_fd = NULL; #endif -static TAG_CALLBACK(spp_r2_pipe) { +static TAG_CALLBACK(spp_rz_pipe) { #if HAVE_SYSTEM - spp_r2_pipe_fd = popen (buf, "w"); + spp_rz_pipe_fd = popen (buf, "w"); #endif return 0; } -static char *spp_r2_switch_str = NULL; +static char *spp_rz_switch_str = NULL; -static TAG_CALLBACK(spp_r2_switch) { - char *var = spp_r2_var_get (buf); +static TAG_CALLBACK(spp_rz_switch) { + char *var = spp_rz_var_get (buf); if (var) { - spp_r2_switch_str = var; + spp_rz_switch_str = var; } else { - spp_r2_switch_str = strdup (""); + spp_rz_switch_str = strdup (""); free (var); } return 1; } -static TAG_CALLBACK(spp_r2_case) { - state->echo[state->ifl] = strcmp (buf, spp_r2_switch_str)?0:1; +static TAG_CALLBACK(spp_rz_case) { + state->echo[state->ifl] = strcmp (buf, spp_rz_switch_str)?0:1; return 0; } -static TAG_CALLBACK(spp_r2_endswitch) { - free (spp_r2_switch_str); - spp_r2_switch_str = NULL; +static TAG_CALLBACK(spp_rz_endswitch) { + free (spp_rz_switch_str); + spp_rz_switch_str = NULL; return -1; } -static TAG_CALLBACK(spp_r2_endpipe) { +static TAG_CALLBACK(spp_rz_endpipe) { #if HAVE_SYSTEM /* TODO: Get output here */ int ret = 0, len = 0; @@ -343,7 +343,7 @@ static TAG_CALLBACK(spp_r2_endpipe) { } do { len += ret; - ret = fread (str + len, 1, 1023, spp_r2_pipe_fd); + ret = fread (str + len, 1, 1023, spp_rz_pipe_fd); if (ret + 1024 > outlen) { outlen += 4096; tstr = realloc (str, outlen); @@ -355,91 +355,91 @@ static TAG_CALLBACK(spp_r2_endpipe) { } } while (ret > 0); str[len] = '\0'; - r_cons_printf ("%s", str); - if (spp_r2_pipe_fd) { - pclose (spp_r2_pipe_fd); + rz_cons_printf ("%s", str); + if (spp_rz_pipe_fd) { + pclose (spp_rz_pipe_fd); } - spp_r2_pipe_fd = NULL; + spp_rz_pipe_fd = NULL; free (str); #endif return 0; } -static PUT_CALLBACK(spp_r2_fputs) { +static PUT_CALLBACK(spp_rz_fputs) { #if HAVE_SYSTEM - if (spp_r2_pipe_fd) { - fprintf (spp_r2_pipe_fd, "%s", buf); + if (spp_rz_pipe_fd) { + fprintf (spp_rz_pipe_fd, "%s", buf); } else #endif { - r_cons_printf ("%s", buf); + rz_cons_printf ("%s", buf); } return 0; } -static SppTag spp_r2_tags[] = { - { "get", spp_r2_get }, - { "hex", spp_r2_hex }, - { "getrandom", spp_r2_getrandom }, - { "grepline", spp_r2_grepline }, - { "set", spp_r2_set }, - { "add", spp_r2_add }, - { "sub", spp_r2_sub }, - { "switch", spp_r2_switch }, - { "case", spp_r2_case }, - { "endswitch", spp_r2_endswitch }, - { "echo", spp_r2_echo }, - { "error", spp_r2_error }, - { "warning", spp_r2_warning }, - { "trace", spp_r2_trace }, - { "ifin", spp_r2_ifin }, - { "ifnot", spp_r2_ifnot }, - { "ifeq", spp_r2_ifeq }, - { "if", spp_r2_if }, - { "else", spp_r2_else }, - { "endif", spp_r2_endif }, - { "pipe", spp_r2_pipe }, - { "endpipe", spp_r2_endpipe }, - { "include", spp_r2_include }, - { "system", spp_r2_system }, - { "r2", spp_r2_r2 }, - { NULL, spp_r2_default }, +static SppTag spp_rz_tags[] = { + { "get", spp_rz_get }, + { "hex", spp_rz_hex }, + { "getrandom", spp_rz_getrandom }, + { "grepline", spp_rz_grepline }, + { "set", spp_rz_set }, + { "add", spp_rz_add }, + { "sub", spp_rz_sub }, + { "switch", spp_rz_switch }, + { "case", spp_rz_case }, + { "endswitch", spp_rz_endswitch }, + { "echo", spp_rz_echo }, + { "error", spp_rz_error }, + { "warning", spp_rz_warning }, + { "trace", spp_rz_trace }, + { "ifin", spp_rz_ifin }, + { "ifnot", spp_rz_ifnot }, + { "ifeq", spp_rz_ifeq }, + { "if", spp_rz_if }, + { "else", spp_rz_else }, + { "endif", spp_rz_endif }, + { "pipe", spp_rz_pipe }, + { "endpipe", spp_rz_endpipe }, + { "include", spp_rz_include }, + { "system", spp_rz_system }, + { "r2", spp_rz_rz }, + { NULL, spp_rz_default }, { NULL } }; -static ARG_CALLBACK(spp_r2_arg_i) { - r_sys_setenv ("SPP_INCDIR", arg); +static ARG_CALLBACK(spp_rz_arg_i) { + rz_sys_setenv ("SPP_INCDIR", arg); return 0; } -static ARG_CALLBACK(spp_r2_arg_d) { +static ARG_CALLBACK(spp_rz_arg_d) { /* TODO: Handle error */ char *eq = strchr (arg, '='); if (eq) { *eq = '\0'; - spp_r2_var_set (arg, eq+1); + spp_rz_var_set (arg, eq+1); } else { - spp_r2_var_set (arg, ""); + spp_rz_var_set (arg, ""); } return 0; } -static struct Arg spp_r2_args[] = { - { "-I", "add include directory", 1, spp_r2_arg_i }, - { "-D", "define value of variable", 1, spp_r2_arg_d }, +static struct Arg spp_rz_args[] = { + { "-I", "add include directory", 1, spp_rz_arg_i }, + { "-D", "define value of variable", 1, spp_rz_arg_d }, { NULL } }; -DLL_LOCAL SppProc spp_r2_proc = { +DLL_LOCAL SppProc spp_rz_proc = { .name = "sppr2", - .tags = (struct Tag **)spp_r2_tags, - .args = (struct Arg **)spp_r2_args, + .tags = (struct Tag **)spp_rz_tags, + .args = (struct Arg **)spp_rz_args, .token = " ", .eof = NULL, .tag_pre = "{", .tag_post = "}", .chop = 1, - .fputs = spp_r2_fputs, + .fputs = spp_rz_fputs, .multiline = NULL, .default_echo = 1, .tag_begin = 0, diff --git a/libr/lang/p/vala.c b/librz/lang/p/vala.c similarity index 68% rename from libr/lang/p/vala.c rename to librz/lang/p/vala.c index 36e212420e..73cf53c747 100644 --- a/libr/lang/p/vala.c +++ b/librz/lang/p/vala.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2011-2017 pancake */ -/* vala extension for libr (radare2) */ +/* vala extension for librz (rizin) */ // TODO: add cache directory (~/.r2/cache) -#include "r_lib.h" -#include "r_core.h" -#include "r_lang.h" +#include "rz_lib.h" +#include "rz_core.h" +#include "rz_lang.h" -static int lang_vala_file(RLang *lang, const char *file, bool silent) { +static int lang_vala_file(RzLang *lang, const char *file, bool silent) { void *lib; char *p, name[512], buf[512]; char *vapidir, *srcdir, *libname; @@ -20,13 +20,13 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { } else { strcpy (name, file); } - if (!r_file_exists (name)) { + if (!rz_file_exists (name)) { eprintf ("file not found (%s)\n", name); return false; } srcdir = strdup (file); - p = (char*)r_str_lchr (srcdir, '/'); + p = (char*)rz_str_lchr (srcdir, '/'); if (p) { *p = 0; libname = strdup (p+1); @@ -37,10 +37,10 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { libname = strdup (file); strcpy (srcdir, "."); } - r_sys_setenv ("PKG_CONFIG_PATH", R2_LIBDIR"/pkgconfig"); - vapidir = r_sys_getenv ("VAPIDIR"); + rz_sys_setenv ("PKG_CONFIG_PATH", R2_LIBDIR"/pkgconfig"); + vapidir = rz_sys_getenv ("VAPIDIR"); char *tail = silent? " > /dev/null 2>&1": ""; - char *src = r_file_slurp (name, NULL); + char *src = rz_file_slurp (name, NULL); const char *pkgs = ""; const char *libs = ""; if (src) { @@ -53,7 +53,7 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { // const char *pkgs = ""; if (vapidir) { if (*vapidir) { - len = snprintf (buf, sizeof (buf), "valac --disable-warnings -d %s --vapidir=%s --pkg r_core %s -C %s %s", + len = snprintf (buf, sizeof (buf), "valac --disable-warnings -d %s --vapidir=%s --pkg rz_core %s -C %s %s", srcdir, vapidir, pkgs, name, tail); if (len >= sizeof (buf)) { free (vapidir); @@ -64,7 +64,7 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { } free (vapidir); } else { - len = snprintf (buf, sizeof (buf) - 1, "valac --disable-warnings -d %s %s --pkg r_core -C %s %s", srcdir, pkgs, name, tail); + len = snprintf (buf, sizeof (buf) - 1, "valac --disable-warnings -d %s %s --pkg rz_core -C %s %s", srcdir, pkgs, name, tail); if (len >= sizeof (buf)) { free (srcdir); free (libname); @@ -72,7 +72,7 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { } } free (srcdir); - if (r_sandbox_system (buf, 1) != 0) { + if (rz_sandbox_system (buf, 1) != 0) { free (libname); return false; } @@ -86,8 +86,8 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { } // TODO: use CC environ if possible len = snprintf (buf, sizeof (buf), "gcc -fPIC -shared %s.c -o lib%s." R_LIB_EXT - " $(pkg-config --cflags --libs r_core gobject-2.0 %s)", name, libname, libs); - if (len >= sizeof (buf) || r_sandbox_system (buf, 1) != 0) { + " $(pkg-config --cflags --libs rz_core gobject-2.0 %s)", name, libname, libs); + if (len >= sizeof (buf) || rz_sandbox_system (buf, 1) != 0) { free (libname); return false; } @@ -98,30 +98,30 @@ static int lang_vala_file(RLang *lang, const char *file, bool silent) { return false; } - lib = r_lib_dl_open (buf); + lib = rz_lib_dl_open (buf); if (lib) { - void (*fcn) (RCore *); - fcn = r_lib_dl_sym (lib, "entry"); + void (*fcn) (RzCore *); + fcn = rz_lib_dl_sym (lib, "entry"); if (fcn) { fcn (lang->user); } else { eprintf ("Cannot find 'entry' symbol in library\n"); } - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else { eprintf ("Cannot open library\n"); } - r_file_rm (buf); // remove lib + rz_file_rm (buf); // remove lib len = snprintf (buf, sizeof (buf), "%s.c", name); // remove .c if (len >= sizeof (buf)) { return false; } - r_file_rm (buf); + rz_file_rm (buf); return 0; } -static int vala_run_file(RLang *lang, const char *file) { +static int vala_run_file(RzLang *lang, const char *file) { return lang_vala_file(lang, file, false); } @@ -130,26 +130,26 @@ static int lang_vala_init(void *user) { return true; } -static int lang_vala_run(RLang *lang, const char *code, int len) { +static int lang_vala_run(RzLang *lang, const char *code, int len) { bool silent = !strncmp (code, "-s", 2); - FILE *fd = r_sandbox_fopen (".tmp.vala", "w"); + FILE *fd = rz_sandbox_fopen (".tmp.vala", "w"); if (fd) { if (silent) { code += 2; } - fputs ("using Radare;\n\npublic static void entry(RCore core) {\n", fd); + fputs ("using Radare;\n\npublic static void entry(RzCore core) {\n", fd); fputs (code, fd); fputs (";\n}\n", fd); fclose (fd); lang_vala_file (lang, ".tmp.vala", silent); - r_file_rm (".tmp.vala"); + rz_file_rm (".tmp.vala"); return true; } eprintf ("Cannot open .tmp.vala\n"); return false; } -static RLangPlugin r_lang_plugin_vala = { +static RzLangPlugin rz_lang_plugin_vala = { .name = "vala", .ext = "vala", .license = "LGPL", diff --git a/libr/lang/p/zig.c b/librz/lang/p/zig.c similarity index 60% rename from libr/lang/p/zig.c rename to librz/lang/p/zig.c index 84699b8c67..9453c4e78e 100644 --- a/libr/lang/p/zig.c +++ b/librz/lang/p/zig.c @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2018 pancake */ -#include -#include -#include +#include +#include +#include -static int lang_zig_file(RLang *lang, const char *file) { +static int lang_zig_file(RzLang *lang, const char *file) { void *lib; char *a, *cc, *p; const char *libpath, *libname; - if (!r_file_exists (file)) { + if (!rz_file_exists (file)) { eprintf ("file not found (%s)\n", file); return false; } char *name = strdup (file); - a = (char*)r_str_lchr (name, '/'); + a = (char*)rz_str_lchr (name, '/'); if (a) { *a = 0; libpath = name; @@ -28,15 +28,15 @@ static int lang_zig_file(RLang *lang, const char *file) { if (p) { *p = 0; } - cc = r_sys_getenv ("ZIG"); + cc = rz_sys_getenv ("ZIG"); if (cc && !*cc) { R_FREE (cc); } if (!cc) { cc = strdup ("zig"); } - char *cmd = r_str_newf ("zig build-lib --output %s.%s --release-fast %s.zig --library r_core", name, R_LIB_EXT, name); - if (r_sandbox_system (cmd, 1) != 0) { + char *cmd = rz_str_newf ("zig build-lib --output %s.%s --release-fast %s.zig --library rz_core", name, R_LIB_EXT, name); + if (rz_sandbox_system (cmd, 1) != 0) { free (name); free (cmd); free (cc); @@ -44,24 +44,24 @@ static int lang_zig_file(RLang *lang, const char *file) { } free (cmd); - char *path = r_str_newf ("%s/%s.%s", libpath, libname, R_LIB_EXT); - lib = r_lib_dl_open (path); + char *path = rz_str_newf ("%s/%s.%s", libpath, libname, R_LIB_EXT); + lib = rz_lib_dl_open (path); if (lib) { - void (*fcn)(RCore *); - fcn = r_lib_dl_sym (lib, "entry"); + void (*fcn)(RzCore *); + fcn = rz_lib_dl_sym (lib, "entry"); if (fcn) { fcn (lang->user); } else { eprintf ("Cannot find 'entry' symbol in library\n"); } - r_lib_dl_close (lib); + rz_lib_dl_close (lib); } else { eprintf ("Cannot open library\n"); free (path); free (cc); return false; } - r_file_rm (path); // remove lib + rz_file_rm (path); // remove lib free (path); free (cc); return true; @@ -72,35 +72,35 @@ static int lang_zig_init(void *user) { return true; } -static int lang_zig_run(RLang *lang, const char *code, int len) { +static int lang_zig_run(RzLang *lang, const char *code, int len) { const char *file = "_tmp.zig"; - FILE *fd = r_sandbox_fopen (file, "w"); + FILE *fd = rz_sandbox_fopen (file, "w"); if (fd) { const char *zig_header = \ "extern fn puts(&const u8) void;\n" \ -"extern fn r_core_cmd_str(&u8, &const u8) &u8;\n" \ -"extern fn r_core_new() &u8;\n" \ -"extern fn r_core_free(&u8) void;\n" \ +"extern fn rz_core_cmd_str(&u8, &const u8) &u8;\n" \ +"extern fn rz_core_new() &u8;\n" \ +"extern fn rz_core_free(&u8) void;\n" \ "\n" \ "export fn entry(core: &u8) void {\n"; const char *zig_footer = \ "\n}\n" \ "pub fn r2cmd(core: &u8, cmd: u8) &u8 {\n" \ -" return r_core_cmd_str(core, cmd);\n" \ +" return rz_core_cmd_str(core, cmd);\n" \ "}\n"; fputs (zig_header, fd); fputs (code, fd); fputs (zig_footer, fd); fclose (fd); lang_zig_file (lang, file); - r_file_rm (file); + rz_file_rm (file); } else { eprintf ("Cannot open %s\n", file); } return true; } -static RLangPlugin r_lang_plugin_zig = { +static RzLangPlugin rz_lang_plugin_zig = { .name = "zig", .ext = "zig", .license = "MIT", diff --git a/libr/lang/t/hello.vala b/librz/lang/t/hello.vala similarity index 100% rename from libr/lang/t/hello.vala rename to librz/lang/t/hello.vala diff --git a/libr/lang/t/json-test.vala b/librz/lang/t/json-test.vala similarity index 100% rename from libr/lang/t/json-test.vala rename to librz/lang/t/json-test.vala diff --git a/libr/ld.script b/librz/ld.script similarity index 100% rename from libr/ld.script rename to librz/ld.script diff --git a/libr/libr.pc.acr b/librz/librz.pc.acr similarity index 56% rename from libr/libr.pc.acr rename to librz/librz.pc.acr index cedbc439e4..d2c8efc7cc 100644 --- a/libr/libr.pc.acr +++ b/librz/librz.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include -Name: libr +Name: librz Description: radare framework libraries Version: 0.1 Requires: -Libs: -L${libdir} -lr_core -lr_lang -lr_search -lr_asm -lr_util -lr_reg -Cflags: -I${includedir}/libr +Libs: -L${libdir} -lrz_core -lrz_lang -lrz_search -lrz_asm -lrz_util -lrz_reg +Cflags: -I${includedir}/librz diff --git a/libr/libs.custom.mk.example b/librz/libs.custom.mk.example similarity index 100% rename from libr/libs.custom.mk.example rename to librz/libs.custom.mk.example diff --git a/libr/libs.mk b/librz/libs.mk similarity index 100% rename from libr/libs.mk rename to librz/libs.mk diff --git a/libr/magic/Makefile b/librz/magic/Makefile similarity index 92% rename from libr/magic/Makefile rename to librz/magic/Makefile index 9fb04dcee2..08d2146029 100644 --- a/libr/magic/Makefile +++ b/librz/magic/Makefile @@ -1,8 +1,8 @@ include ../../global.mk include $(LTOP)/config.mk -NAME=r_magic -R2DEPS=r_util +NAME=rz_magic +R2DEPS=rz_util PCLIBS=@LIBMAGIC@ CFLAGS+=-I. OBJS=apprentice.o ascmagic.o fsmagic.o funcs.o is_tar.o magic.o softmagic.o diff --git a/libr/magic/README b/librz/magic/README similarity index 100% rename from libr/magic/README rename to librz/magic/README diff --git a/libr/magic/apprentice.c b/librz/magic/apprentice.c similarity index 92% rename from libr/magic/apprentice.c rename to librz/magic/apprentice.c index 5b3dd8cf6d..1fa99491b4 100644 --- a/libr/magic/apprentice.c +++ b/librz/magic/apprentice.c @@ -29,11 +29,11 @@ /* * apprentice - make one pass through /etc/magic, learning its secrets. */ -#include +#include #if !USE_LIB_MAGIC -#include +#include #include #include "file.h" #include "patchlevel.h" @@ -60,8 +60,8 @@ # define MAP_FILE 0 #endif -struct r_magic_entry { - struct r_magic *mp; +struct rz_magic_entry { + struct rz_magic *mp; ut32 cont_count; ut32 max_count; }; @@ -71,30 +71,30 @@ static const size_t file_nformats = FILE_NAMES_SIZE; static const char *magic_file_names[FILE_NAMES_SIZE]; static const size_t file_nnames = FILE_NAMES_SIZE; -static int getvalue(RMagic *ms, struct r_magic *, const char **, int); +static int getvalue(RzMagic *ms, struct rz_magic *, const char **, int); static int hextoint(int); -static const char *getstr(RMagic *, const char *, char *, int, int *, int); -static int parse(RMagic *, struct r_magic_entry **, ut32 *, const char *, size_t, int); -static int parse_mime(RMagic *, struct r_magic_entry **, ut32 *, const char *); +static const char *getstr(RzMagic *, const char *, char *, int, int *, int); +static int parse(RzMagic *, struct rz_magic_entry **, ut32 *, const char *, size_t, int); +static int parse_mime(RzMagic *, struct rz_magic_entry **, ut32 *, const char *); static void eatsize(const char **); -static int apprentice_1(RMagic *, const char *, int, struct mlist *); -static size_t apprentice_r_magic_strength(const struct r_magic *); +static int apprentice_1(RzMagic *, const char *, int, struct mlist *); +static size_t apprentice_r_magic_strength(const struct rz_magic *); static int apprentice_sort(const void *, const void *); -static int apprentice_load(RMagic *, struct r_magic **, ut32 *, const char *, int); -static void byteswap(struct r_magic *, ut32); -static void bs1(struct r_magic *); +static int apprentice_load(RzMagic *, struct rz_magic **, ut32 *, const char *, int); +static void byteswap(struct rz_magic *, ut32); +static void bs1(struct rz_magic *); static ut16 swap2(ut16); static ut32 swap4(ut32); static ut64 swap8(ut64); static char *mkdbname(const char *, int); -static int apprentice_map(RMagic *, struct r_magic **, ut32 *, const char *); -static int apprentice_compile(RMagic *, struct r_magic **, ut32 *, const char *); +static int apprentice_map(RzMagic *, struct rz_magic **, ut32 *, const char *); +static int apprentice_compile(RzMagic *, struct rz_magic **, ut32 *, const char *); static int check_format_type(const char *, int); -static int check_format(RMagic *, struct r_magic *); +static int check_format(RzMagic *, struct rz_magic *); static int get_op(char); static size_t maxmagic = 0; -static size_t magicsize = sizeof (struct r_magic); +static size_t magicsize = sizeof (struct rz_magic); static const char usg_hdr[] = "cont\toffset\ttype\topcode\tmask\tvalue\tdesc"; static const char mime_marker[] = "!:mime"; @@ -184,8 +184,8 @@ static void init_file_tables(void) { /* * Handle one file or directory. */ -static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *mlist) { - struct r_magic *magic = NULL; +static int apprentice_1(RzMagic *ms, const char *fn, int action, struct mlist *mlist) { + struct rz_magic *magic = NULL; ut32 nmagic = 0; struct mlist *ml; int rv = -1; @@ -246,7 +246,7 @@ static int apprentice_1(RMagic *ms, const char *fn, int action, struct mlist *ml return 0; } -void file_delmagic(struct r_magic *p, int type, size_t entries) { +void file_delmagic(struct rz_magic *p, int type, size_t entries) { if (p) { switch (type) { #if QUICK @@ -268,7 +268,7 @@ void file_delmagic(struct r_magic *p, int type, size_t entries) { } /* const char *fn: list of magic files and directories */ -struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) { +struct mlist * file_apprentice(RzMagic *ms, const char *fn, int action) { char *p, *mfn; int file_err, errs = -1; struct mlist *mlist; @@ -316,7 +316,7 @@ struct mlist * file_apprentice(RMagic *ms, const char *fn, int action) { /* * Get weight of this magic entry, for sorting purposes. */ -static size_t apprentice_r_magic_strength(const struct r_magic *m) { +static size_t apprentice_r_magic_strength(const struct rz_magic *m) { #define MULT 10 size_t val = 2 * MULT; /* baseline strength */ @@ -408,8 +408,8 @@ static size_t apprentice_r_magic_strength(const struct r_magic *m) { * Sort callback for sorting entries by "strength" (basically length) */ static int apprentice_sort(const void *a, const void *b) { - const struct r_magic_entry *ma = a; - const struct r_magic_entry *mb = b; + const struct rz_magic_entry *ma = a; + const struct rz_magic_entry *mb = b; size_t sa = apprentice_r_magic_strength (ma->mp); size_t sb = apprentice_r_magic_strength (mb->mp); if (sa == sb) { @@ -421,7 +421,7 @@ static int apprentice_sort(const void *a, const void *b) { return 1; } -static void set_test_type(struct r_magic *mstart, struct r_magic *m) { +static void set_test_type(struct rz_magic *mstart, struct rz_magic *m) { switch (m->type) { case FILE_BYTE: case FILE_SHORT: @@ -490,14 +490,14 @@ static const char* bgets(char *line, size_t line_sz, const char *data) { const int nlsz = nl ? nl - data + 1 : R_MIN (line_sz, strlen (data)); - r_str_ncpy (line, data, nlsz); + rz_str_ncpy (line, data, nlsz); if (!data[nlsz]) { return NULL; } return data + nlsz; } -static void load_b(RMagic *ms, int action, const char *data, int *errs, struct r_magic_entry **marray, ut32 *marraycount) { +static void load_b(RzMagic *ms, int action, const char *data, int *errs, struct rz_magic_entry **marray, ut32 *marraycount) { char line[BUFSIZ]; size_t lineno = 0; /* read and parse this file */ @@ -533,14 +533,14 @@ static void load_b(RMagic *ms, int action, const char *data, int *errs, struct r /* * Load and parse one file. */ -static void load_1(RMagic *ms, int action, const char *file, int *errs, struct r_magic_entry **marray, ut32 *marraycount) { +static void load_1(RzMagic *ms, int action, const char *file, int *errs, struct rz_magic_entry **marray, ut32 *marraycount) { if (*file == '#') { load_b (ms, action, file, errs, marray, marraycount); return; } char line[BUFSIZ]; size_t lineno = 0; - FILE *f = r_sandbox_fopen (ms->file = file, "r"); + FILE *f = rz_sandbox_fopen (ms->file = file, "r"); if (!f) { if (errno != ENOENT) { file_error (ms, errno, "cannot read magic file `%s'", file); @@ -584,9 +584,9 @@ static void load_1(RMagic *ms, int action, const char *file, int *errs, struct r * parse a file or directory of files * const char *fn: name of magic file or directory */ -static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, const char *fn, int action) { +static int apprentice_load(RzMagic *ms, struct rz_magic **magicp, ut32 *nmagicp, const char *fn, int action) { ut32 marraycount, i, mentrycount = 0, starttest; - struct r_magic_entry *marray; + struct rz_magic_entry *marray; struct stat st; int errs = 0; #if __WINDOWS__ @@ -617,18 +617,18 @@ static int apprentice_load(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, c /* load directory or file */ if (stat (fn, &st) == 0 && S_ISDIR (st.st_mode)) { - if (r_sandbox_enable (0) && !r_sandbox_check_path (fn)) { + if (rz_sandbox_enable (0) && !rz_sandbox_check_path (fn)) { free (marray); return -1; } #if __WINDOWS__ && !defined(__CYGWIN__) - if ((wcpath = r_utf8_to_utf16 (fn))) { + if ((wcpath = rz_utf8_to_utf16 (fn))) { swprintf (dir, _countof (dir), L"%ls\\*.*", wcpath); hdir = FindFirstFileW (dir, &entry); if (!(hdir == INVALID_HANDLE_VALUE)) { do { if (wcsncmp (entry.cFileName, L".", 1) == 0) continue; - if ((cfname = r_utf16_to_utf8 (entry.cFileName))) { + if ((cfname = rz_utf16_to_utf8 (entry.cFileName))) { snprintf (subfn, sizeof (subfn), "%s/%s", fn, cfname); if (stat (subfn, &st) == 0 && S_ISREG (st.st_mode)) { load_1 (ms, action, subfn, &errs, &marray, &marraycount); @@ -751,7 +751,7 @@ out: /* * extend the sign bit if the comparison is to be signed */ -ut64 file_signextend(RMagic *ms, struct r_magic *m, ut64 v) { +ut64 file_signextend(RzMagic *ms, struct rz_magic *m, ut64 v) { if (!(m->flag & UNSIGNED)) { switch (m->type) { /* @@ -817,7 +817,7 @@ ut64 file_signextend(RMagic *ms, struct r_magic *m, ut64 v) { return v; } -static int string_modifier_check(RMagic *ms, struct r_magic *m) { +static int string_modifier_check(RzMagic *ms, struct rz_magic *m) { if ((ms->flags & R_MAGIC_CHECK) == 0) { return 0; } @@ -908,7 +908,7 @@ static int get_cond(const char *l, const char **t) { return p->cond; } -static int check_cond(RMagic *ms, int cond, ut32 cont_level) { +static int check_cond(RzMagic *ms, int cond, ut32 cont_level) { int last_cond; last_cond = ms->c.li[cont_level].last_cond; @@ -952,11 +952,11 @@ static int check_cond(RMagic *ms, int cond, ut32 cont_level) { /* * parse one line from magic file, put into magic[index++] if valid */ -static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, const char *line, size_t lineno, int action) { +static int parse(RzMagic *ms, struct rz_magic_entry **mentryp, ut32 *nmentryp, const char *line, size_t lineno, int action) { static ut32 last_cont_level = 0; size_t i; - struct r_magic_entry *me; - struct r_magic *m; + struct rz_magic_entry *me; + struct rz_magic *m; const char *l = line; char *t; int op; @@ -980,7 +980,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con } me = &(*mentryp)[*nmentryp - 1]; if (me->cont_count == me->max_count) { - struct r_magic *nm; + struct rz_magic *nm; size_t cnt = me->max_count + ALLOC_CHUNK; if (!(nm = realloc(me->mp, sizeof (*nm) * cnt))) { file_oomem(ms, sizeof (*nm) * cnt); @@ -994,7 +994,7 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con m->cont_level = cont_level; } else { if (*nmentryp == maxmagic) { - struct r_magic_entry *mp; + struct rz_magic_entry *mp; maxmagic += ALLOC_INCR; if (!(mp = realloc (*mentryp, sizeof (*mp) * maxmagic))) { @@ -1330,11 +1330,11 @@ static int parse(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, con * parse a MIME annotation line from magic file, put into magic[index - 1] * if valid */ -static int parse_mime(RMagic *ms, struct r_magic_entry **mentryp, ut32 *nmentryp, const char *line) { +static int parse_mime(RzMagic *ms, struct rz_magic_entry **mentryp, ut32 *nmentryp, const char *line) { size_t i; const char *l = line; - struct r_magic *m; - struct r_magic_entry *me; + struct rz_magic *m; + struct rz_magic_entry *me; if (*nmentryp == 0) { file_error(ms, 0, "No current entry for MIME type"); @@ -1502,7 +1502,7 @@ static int check_format_type(const char *ptr, int type) { * Check that the optional printf format in description matches * the type of the magic. */ -static int check_format(RMagic *ms, struct r_magic *m) { +static int check_format(RzMagic *ms, struct rz_magic *m) { char *ptr; for (ptr = m->desc; *ptr; ptr++) { @@ -1560,7 +1560,7 @@ static int check_format(RMagic *ms, struct r_magic *m) { * pointer, according to the magic type. Update the string pointer to point * just after the number read. Return 0 for success, non-zero for failure. */ -static int getvalue(RMagic *ms, struct r_magic *m, const char **p, int action) { +static int getvalue(RzMagic *ms, struct rz_magic *m, const char **p, int action) { int slen; switch (m->type) { @@ -1623,7 +1623,7 @@ static int getvalue(RMagic *ms, struct r_magic *m, const char **p, int action) { * Copy the converted version to "p", returning its length in *slen. * Return updated scan pointer as function result. */ -static const char * getstr(RMagic *ms, const char *s, char *p, int plen, int *slen, int action) { +static const char * getstr(RzMagic *ms, const char *s, char *p, int plen, int *slen, int action) { const char *origs = s; char *origp = p; char *pmax = p + plen - 1; @@ -1824,7 +1824,7 @@ static void eatsize(const char **p) { /* * handle a compiled file. */ -static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, const char *fn) { +static int apprentice_map(RzMagic *ms, struct rz_magic **magicp, ut32 *nmagicp, const char *fn) { int fd; struct stat st; ut32 *ptr; @@ -1838,7 +1838,7 @@ static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, co goto error2; } - if ((fd = r_sandbox_open (dbname, O_RDONLY | O_BINARY, 0)) == -1) { + if ((fd = rz_sandbox_open (dbname, O_RDONLY | O_BINARY, 0)) == -1) { goto error2; } @@ -1892,7 +1892,7 @@ static int apprentice_map(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, co VERSIONNO, dbname, version); goto error1; } - *nmagicp = (ut32)(st.st_size / sizeof (struct r_magic)); + *nmagicp = (ut32)(st.st_size / sizeof (struct rz_magic)); if (*nmagicp > 0) { (*nmagicp)--; } @@ -1929,7 +1929,7 @@ static const ut32 ar[] = { /* * handle an mmaped file. */ -static int apprentice_compile(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp, const char *fn) { +static int apprentice_compile(RzMagic *ms, struct rz_magic **magicp, ut32 *nmagicp, const char *fn) { int fd; char *dbname; int rv = -1; @@ -1940,7 +1940,7 @@ static int apprentice_compile(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp goto out; } - if ((fd = r_sandbox_open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) { + if ((fd = rz_sandbox_open(dbname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644)) == -1) { file_error(ms, errno, "cannot open `%s'", dbname); goto out; } @@ -1950,14 +1950,14 @@ static int apprentice_compile(RMagic *ms, struct r_magic **magicp, ut32 *nmagicp goto beach; } - if (lseek(fd, (off_t)sizeof (struct r_magic), SEEK_SET) - != sizeof (struct r_magic)) { + if (lseek(fd, (off_t)sizeof (struct rz_magic), SEEK_SET) + != sizeof (struct rz_magic)) { file_error(ms, errno, "error seeking `%s'", dbname); goto beach; } - if (write(fd, *magicp, (sizeof (struct r_magic) * *nmagicp)) - != (int)(sizeof (struct r_magic) * *nmagicp)) { + if (write(fd, *magicp, (sizeof (struct rz_magic) * *nmagicp)) + != (int)(sizeof (struct rz_magic) * *nmagicp)) { file_error(ms, errno, "error writing `%s'", dbname); goto beach; } @@ -2000,7 +2000,7 @@ static char *mkdbname(const char *fn, int strip) { /* * Byteswap an mmap'ed file if needed */ -static void byteswap(struct r_magic *magic, ut32 nmagic) { +static void byteswap(struct rz_magic *magic, ut32 nmagic) { ut32 i; for (i = 0; i < nmagic; i++) { bs1 (&magic[i]); @@ -2065,7 +2065,7 @@ static ut64 swap8(ut64 sv) { /* * byteswap a single magic entry */ -static void bs1(struct r_magic *m) { +static void bs1(struct rz_magic *m) { m->cont_level = swap2(m->cont_level); m->offset = swap4((ut32)m->offset); m->in_offset = swap4((ut32)m->in_offset); diff --git a/libr/magic/ascmagic.c b/librz/magic/ascmagic.c similarity index 99% rename from libr/magic/ascmagic.c rename to librz/magic/ascmagic.c index 259f5e9a12..9d77a0f2ed 100644 --- a/libr/magic/ascmagic.c +++ b/librz/magic/ascmagic.c @@ -36,7 +36,7 @@ * Joerg Wunsch wrote the original support for 8-bit * international characters, now subsumed into this file. */ -#include +#include #if !USE_LIB_MAGIC @@ -63,7 +63,7 @@ static void from_ebcdic(const ut8 *, size_t, ut8 *); static int ascmatch(const ut8 *, const unichar *, size_t); static ut8 *encode_utf8(ut8 *, size_t, unichar *, size_t); -int file_ascmagic(RMagic *ms, const ut8 *buf, size_t nbytes) { +int file_ascmagic(RzMagic *ms, const ut8 *buf, size_t nbytes) { return 0; size_t i; ut8 *nbuf = NULL, *utf8_buf = NULL, *utf8_end; diff --git a/libr/magic/d/Makefile b/librz/magic/d/Makefile similarity index 85% rename from libr/magic/d/Makefile rename to librz/magic/d/Makefile index d7ce72c0aa..7066ae599f 100644 --- a/libr/magic/d/Makefile +++ b/librz/magic/d/Makefile @@ -1,6 +1,6 @@ include ../../config.mk -MAGICDIR=${DESTDIR}${DATADIR}/radare2/${VERSION}/magic +MAGICDIR=${DESTDIR}${DATADIR}/rizin/${VERSION}/magic install: ${F_SDB} -rm -rf "$(MAGICDIR)" diff --git a/libr/magic/d/default/apple b/librz/magic/d/default/apple similarity index 99% rename from libr/magic/d/default/apple rename to librz/magic/d/default/apple index c29b7d5e11..23e3b40908 100644 --- a/libr/magic/d/default/apple +++ b/librz/magic/d/default/apple @@ -17,7 +17,7 @@ # GRR: Too weak #0 string zsys Macintosh System File (data) #0 string FNDR Macintosh Finder (data) -#0 string libr Macintosh Library (data) +#0 string librz Macintosh Library (data) #>2 string x : %s #0 string shlb Macintosh Shared Library (data) #>2 string x : %s @@ -148,7 +148,7 @@ #>65 string acf3 (Aldus FreeHand) #>65 string cdev (control panel) #>65 string dfil (Desk Acessory suitcase) -#>65 string libr (library) +#>65 string librz (library) #>65 string nX^d (WriteNow word processor) #>65 string nX^w (WriteNow dictionary) #>65 string rsrc (resource) diff --git a/libr/magic/d/default/archive b/librz/magic/d/default/archive similarity index 100% rename from libr/magic/d/default/archive rename to librz/magic/d/default/archive diff --git a/libr/magic/d/default/cafebabe b/librz/magic/d/default/cafebabe similarity index 100% rename from libr/magic/d/default/cafebabe rename to librz/magic/d/default/cafebabe diff --git a/libr/magic/d/default/code b/librz/magic/d/default/code similarity index 100% rename from libr/magic/d/default/code rename to librz/magic/d/default/code diff --git a/libr/magic/d/default/compressed b/librz/magic/d/default/compressed similarity index 100% rename from libr/magic/d/default/compressed rename to librz/magic/d/default/compressed diff --git a/libr/magic/d/default/database b/librz/magic/d/default/database similarity index 100% rename from libr/magic/d/default/database rename to librz/magic/d/default/database diff --git a/libr/magic/d/default/elf b/librz/magic/d/default/elf similarity index 100% rename from libr/magic/d/default/elf rename to librz/magic/d/default/elf diff --git a/libr/magic/d/default/filesystems b/librz/magic/d/default/filesystems similarity index 100% rename from libr/magic/d/default/filesystems rename to librz/magic/d/default/filesystems diff --git a/libr/magic/d/default/firmware b/librz/magic/d/default/firmware similarity index 100% rename from libr/magic/d/default/firmware rename to librz/magic/d/default/firmware diff --git a/libr/magic/d/default/flash b/librz/magic/d/default/flash similarity index 100% rename from libr/magic/d/default/flash rename to librz/magic/d/default/flash diff --git a/libr/magic/d/default/freebsd b/librz/magic/d/default/freebsd similarity index 100% rename from libr/magic/d/default/freebsd rename to librz/magic/d/default/freebsd diff --git a/libr/magic/d/default/gimp b/librz/magic/d/default/gimp similarity index 100% rename from libr/magic/d/default/gimp rename to librz/magic/d/default/gimp diff --git a/libr/magic/d/default/gpg b/librz/magic/d/default/gpg similarity index 100% rename from libr/magic/d/default/gpg rename to librz/magic/d/default/gpg diff --git a/libr/magic/d/default/html b/librz/magic/d/default/html similarity index 100% rename from libr/magic/d/default/html rename to librz/magic/d/default/html diff --git a/libr/magic/d/default/images b/librz/magic/d/default/images similarity index 100% rename from libr/magic/d/default/images rename to librz/magic/d/default/images diff --git a/libr/magic/d/default/java b/librz/magic/d/default/java similarity index 100% rename from libr/magic/d/default/java rename to librz/magic/d/default/java diff --git a/libr/magic/d/default/jpeg b/librz/magic/d/default/jpeg similarity index 100% rename from libr/magic/d/default/jpeg rename to librz/magic/d/default/jpeg diff --git a/libr/magic/d/default/linux b/librz/magic/d/default/linux similarity index 100% rename from libr/magic/d/default/linux rename to librz/magic/d/default/linux diff --git a/libr/magic/d/default/mach b/librz/magic/d/default/mach similarity index 100% rename from libr/magic/d/default/mach rename to librz/magic/d/default/mach diff --git a/libr/magic/d/default/mail.news b/librz/magic/d/default/mail.news similarity index 100% rename from libr/magic/d/default/mail.news rename to librz/magic/d/default/mail.news diff --git a/libr/magic/d/default/microsoft b/librz/magic/d/default/microsoft similarity index 100% rename from libr/magic/d/default/microsoft rename to librz/magic/d/default/microsoft diff --git a/libr/magic/d/default/mime b/librz/magic/d/default/mime similarity index 100% rename from libr/magic/d/default/mime rename to librz/magic/d/default/mime diff --git a/libr/magic/d/default/netbsd b/librz/magic/d/default/netbsd similarity index 100% rename from libr/magic/d/default/netbsd rename to librz/magic/d/default/netbsd diff --git a/libr/magic/d/default/network b/librz/magic/d/default/network similarity index 100% rename from libr/magic/d/default/network rename to librz/magic/d/default/network diff --git a/libr/magic/d/default/openbsd b/librz/magic/d/default/openbsd similarity index 100% rename from libr/magic/d/default/openbsd rename to librz/magic/d/default/openbsd diff --git a/libr/magic/d/default/pdf b/librz/magic/d/default/pdf similarity index 100% rename from libr/magic/d/default/pdf rename to librz/magic/d/default/pdf diff --git a/libr/magic/d/default/perl b/librz/magic/d/default/perl similarity index 100% rename from libr/magic/d/default/perl rename to librz/magic/d/default/perl diff --git a/libr/magic/d/default/python b/librz/magic/d/default/python similarity index 100% rename from libr/magic/d/default/python rename to librz/magic/d/default/python diff --git a/libr/magic/d/default/riff b/librz/magic/d/default/riff similarity index 100% rename from libr/magic/d/default/riff rename to librz/magic/d/default/riff diff --git a/libr/magic/d/default/sniffer b/librz/magic/d/default/sniffer similarity index 100% rename from libr/magic/d/default/sniffer rename to librz/magic/d/default/sniffer diff --git a/libr/magic/d/default/sql b/librz/magic/d/default/sql similarity index 100% rename from libr/magic/d/default/sql rename to librz/magic/d/default/sql diff --git a/libr/magic/d/default/ssh b/librz/magic/d/default/ssh similarity index 100% rename from libr/magic/d/default/ssh rename to librz/magic/d/default/ssh diff --git a/libr/magic/d/default/uuencode b/librz/magic/d/default/uuencode similarity index 100% rename from libr/magic/d/default/uuencode rename to librz/magic/d/default/uuencode diff --git a/libr/magic/d/default/video b/librz/magic/d/default/video similarity index 100% rename from libr/magic/d/default/video rename to librz/magic/d/default/video diff --git a/libr/magic/d/default/vim b/librz/magic/d/default/vim similarity index 100% rename from libr/magic/d/default/vim rename to librz/magic/d/default/vim diff --git a/libr/magic/d/default/vorbis b/librz/magic/d/default/vorbis similarity index 100% rename from libr/magic/d/default/vorbis rename to librz/magic/d/default/vorbis diff --git a/libr/magic/d/default/zfs b/librz/magic/d/default/zfs similarity index 100% rename from libr/magic/d/default/zfs rename to librz/magic/d/default/zfs diff --git a/libr/magic/d/meson.build b/librz/magic/d/meson.build similarity index 100% rename from libr/magic/d/meson.build rename to librz/magic/d/meson.build diff --git a/libr/magic/deps.mk b/librz/magic/deps.mk similarity index 100% rename from libr/magic/deps.mk rename to librz/magic/deps.mk diff --git a/libr/magic/file.h b/librz/magic/file.h similarity index 66% rename from libr/magic/file.h rename to librz/magic/file.h index 6094ce19cf..72106d2f99 100644 --- a/libr/magic/file.h +++ b/librz/magic/file.h @@ -35,13 +35,13 @@ #define __file_h__ #include "mconfig.h" -#include +#include #include /* Include that here, to make sure __P gets defined */ #include #include /* For open and flags */ #include // TODO: use utX -#include +#include #include /* Do this here and now, because struct stat gets re-defined on solaris */ #include @@ -55,31 +55,31 @@ typedef unsigned long unichar; struct stat; const char *file_fmttime(unsigned int, int); -int file_buffer(struct r_magic_set *, int, const char *, const void *, size_t); -int file_fsmagic(struct r_magic_set *, const char *, struct stat *); -int file_pipe2file(struct r_magic_set *, int, const void *, size_t); -int file_printf(struct r_magic_set *, const char *, ...); -int file_reset(struct r_magic_set *); -int file_tryelf(struct r_magic_set *, int, const unsigned char *, size_t); -int file_zmagic(struct r_magic_set *, int, const char *, const ut8*, size_t); -int file_ascmagic(struct r_magic_set *, const unsigned char *, size_t); -int file_is_tar(struct r_magic_set *, const unsigned char *, size_t); -int file_softmagic(struct r_magic_set *, const unsigned char *, size_t, int); -struct mlist *file_apprentice(struct r_magic_set *, const char *, int); -ut64 file_signextend(RMagic *, struct r_magic *, ut64); -void file_delmagic(struct r_magic *, int type, size_t entries); -void file_badread(struct r_magic_set *); -void file_badseek(struct r_magic_set *); -void file_oomem(struct r_magic_set *, size_t); -void file_error(struct r_magic_set *, int, const char *, ...); -void file_magerror(struct r_magic_set *, const char *, ...); -void file_magwarn(struct r_magic_set *, const char *, ...); -void file_mdump(struct r_magic *); +int file_buffer(struct rz_magic_set *, int, const char *, const void *, size_t); +int file_fsmagic(struct rz_magic_set *, const char *, struct stat *); +int file_pipe2file(struct rz_magic_set *, int, const void *, size_t); +int file_printf(struct rz_magic_set *, const char *, ...); +int file_reset(struct rz_magic_set *); +int file_tryelf(struct rz_magic_set *, int, const unsigned char *, size_t); +int file_zmagic(struct rz_magic_set *, int, const char *, const ut8*, size_t); +int file_ascmagic(struct rz_magic_set *, const unsigned char *, size_t); +int file_is_tar(struct rz_magic_set *, const unsigned char *, size_t); +int file_softmagic(struct rz_magic_set *, const unsigned char *, size_t, int); +struct mlist *file_apprentice(struct rz_magic_set *, const char *, int); +ut64 file_signextend(RzMagic *, struct rz_magic *, ut64); +void file_delmagic(struct rz_magic *, int type, size_t entries); +void file_badread(struct rz_magic_set *); +void file_badseek(struct rz_magic_set *); +void file_oomem(struct rz_magic_set *, size_t); +void file_error(struct rz_magic_set *, int, const char *, ...); +void file_magerror(struct rz_magic_set *, const char *, ...); +void file_magwarn(struct rz_magic_set *, const char *, ...); +void file_mdump(struct rz_magic *); void file_showstr(FILE *, const char *, size_t); size_t file_mbswidth(const char *); -const char *file_getbuffer(struct r_magic_set *); +const char *file_getbuffer(struct rz_magic_set *); ssize_t sread(int, void *, size_t, int); -int file_check_mem(struct r_magic_set *, unsigned int); +int file_check_mem(struct rz_magic_set *, unsigned int); int file_looks_utf8(const unsigned char *, size_t, unichar *, size_t *); #ifndef HAVE_VASPRINTF diff --git a/libr/magic/file_opts.h b/librz/magic/file_opts.h similarity index 100% rename from libr/magic/file_opts.h rename to librz/magic/file_opts.h diff --git a/libr/magic/fsmagic.c b/librz/magic/fsmagic.c similarity index 97% rename from libr/magic/fsmagic.c rename to librz/magic/fsmagic.c index 551a4dc375..81eee03026 100644 --- a/libr/magic/fsmagic.c +++ b/librz/magic/fsmagic.c @@ -30,11 +30,11 @@ * fsmagic - magic based on filesystem info - directory, special files, etc. */ -#include +#include #if !USE_LIB_MAGIC -#include +#include #include "file.h" #include #include @@ -58,7 +58,7 @@ #endif #undef HAVE_MAJOR -static int bad_link(RMagic *ms, int err, char *buf) { +static int bad_link(RzMagic *ms, int err, char *buf) { #ifdef ELOOP const char *errfmt = (err == ELOOP)? "symbolic link in a loop": @@ -75,7 +75,7 @@ static int bad_link(RMagic *ms, int err, char *buf) { return 1; } -int file_fsmagic(struct r_magic_set *ms, const char *fn, struct stat *sb) { +int file_fsmagic(struct rz_magic_set *ms, const char *fn, struct stat *sb) { int ret = 0; int mime = ms->flags & R_MAGIC_MIME; #ifdef S_IFLNK @@ -249,7 +249,7 @@ int file_fsmagic(struct r_magic_set *ms, const char *fn, struct stat *sb) { if ((ms->flags & R_MAGIC_SYMLINK) != 0) { const char *p; ms->flags &= R_MAGIC_SYMLINK; - p = r_magic_file(ms, buf); + p = rz_magic_file(ms, buf); ms->flags |= R_MAGIC_SYMLINK; return p != NULL ? 1 : -1; } else { /* just print what it points to */ diff --git a/libr/magic/funcs.c b/librz/magic/funcs.c similarity index 91% rename from libr/magic/funcs.c rename to librz/magic/funcs.c index 6abb1fbffa..40ea3de6b8 100644 --- a/libr/magic/funcs.c +++ b/librz/magic/funcs.c @@ -26,7 +26,7 @@ * SUCH DAMAGE. */ -#include +#include #if !USE_LIB_MAGIC @@ -41,7 +41,7 @@ #endif // copypasta to fix an OPENBSDBUG -static int file_vprintf(RMagic *ms, const char *fmt, va_list ap) { +static int file_vprintf(RzMagic *ms, const char *fmt, va_list ap) { va_list ap2; char cbuf[4096]; char *buf, *newstr; @@ -99,7 +99,7 @@ out: /* * Like printf, only we append to a buffer. */ -int file_printf(RMagic *ms, const char *fmt, ...) { +int file_printf(RzMagic *ms, const char *fmt, ...) { va_list ap; int ret; @@ -113,7 +113,7 @@ int file_printf(RMagic *ms, const char *fmt, ...) { * error - print best error message possible */ /*VARARGS*/ -static void file_error_core(RMagic *ms, int error, const char *f, va_list va, ut32 lineno) { +static void file_error_core(RzMagic *ms, int error, const char *f, va_list va, ut32 lineno) { /* Only the first error is ok */ if (!ms || ms->haderr) { return; @@ -133,7 +133,7 @@ static void file_error_core(RMagic *ms, int error, const char *f, va_list va, ut } /*VARARGS*/ -void file_error(RMagic *ms, int error, const char *f, ...) { +void file_error(RzMagic *ms, int error, const char *f, ...) { va_list va; va_start (va, f); file_error_core (ms, error, f, va, 0); @@ -144,26 +144,26 @@ void file_error(RMagic *ms, int error, const char *f, ...) { * Print an error with magic line number. */ /*VARARGS*/ -void file_magerror(RMagic *ms, const char *f, ...) { +void file_magerror(RzMagic *ms, const char *f, ...) { va_list va; va_start (va, f); file_error_core (ms, 0, f, va, ms->line); va_end (va); } -void file_oomem(RMagic *ms, size_t len) { +void file_oomem(RzMagic *ms, size_t len) { file_error (ms, errno, "cannot allocate %zu bytes", len); } -void file_badseek(RMagic *ms) { +void file_badseek(RzMagic *ms) { file_error (ms, errno, "error seeking"); } -void file_badread(RMagic *ms) { +void file_badread(RzMagic *ms) { file_error (ms, errno, "error reading"); } -int file_buffer(RMagic *ms, int fd, const char *inname, const void *buf, size_t nb) { +int file_buffer(RzMagic *ms, int fd, const char *inname, const void *buf, size_t nb) { int mime, m = 0; if (!ms) { return -1; @@ -213,7 +213,7 @@ int file_buffer(RMagic *ms, int fd, const char *inname, const void *buf, size_t return m; } -int file_reset(RMagic *ms) { +int file_reset(RzMagic *ms) { if (!ms) { return 0; } @@ -236,7 +236,7 @@ int file_reset(RMagic *ms) { *(n)++ = (((ut32)*(o) >> 0) & 7) + '0', \ (o)++) -const char *file_getbuffer(RMagic *ms) { +const char *file_getbuffer(RzMagic *ms) { char *pbuf, *op, *np; size_t psize, len; @@ -318,7 +318,7 @@ const char *file_getbuffer(RMagic *ms) { return ms->o.pbuf; } -int file_check_mem(RMagic *ms, unsigned int level) { +int file_check_mem(RzMagic *ms, unsigned int level) { if (level >= ms->c.len) { size_t len = (ms->c.len += 20) * sizeof (*ms->c.li); ms->c.li = (!ms->c.li) ? malloc (len) : diff --git a/libr/magic/is_tar.c b/librz/magic/is_tar.c similarity index 98% rename from libr/magic/is_tar.c rename to librz/magic/is_tar.c index 27fef8cf03..84f0234502 100644 --- a/libr/magic/is_tar.c +++ b/librz/magic/is_tar.c @@ -37,7 +37,7 @@ * Comments changed and some code/comments reformatted * for file command by Ian Darwin. */ -#include +#include #if !USE_LIB_MAGIC @@ -122,7 +122,7 @@ static int is_tar(const ut8 *buf, size_t nbytes) { return 1; /* Old fashioned tar archive */ } -int file_is_tar(RMagic *ms, const ut8 *buf, size_t nbytes) { +int file_is_tar(RzMagic *ms, const ut8 *buf, size_t nbytes) { /* * Do the tar test first, because if the first file in the tar * archive starts with a dot, we can confuse it with an nroff file. diff --git a/libr/magic/magic.c b/librz/magic/magic.c similarity index 70% rename from libr/magic/magic.c rename to librz/magic/magic.c index 6caae2ed46..a3673f9364 100644 --- a/libr/magic/magic.c +++ b/librz/magic/magic.c @@ -1,10 +1,10 @@ /* radare - Copyright 2011-2019 pancake */ /* $OpenBSD: magic.c,v 1.8 2009/10/27 23:59:37 deraadt Exp $ */ -#include -#include +#include +#include -R_LIB_VERSION (r_magic); +R_LIB_VERSION (rz_magic); #ifdef _MSC_VER # include @@ -21,20 +21,20 @@ R_LIB_VERSION (r_magic); // we keep this code just to make debian happy, but we should use // our own magic implementation for consistency reasons #include -#undef R_API -#define R_API +#undef RZ_API +#define RZ_API -R_API RMagic* r_magic_new(int flags) { return magic_open (flags); } -R_API void r_magic_free(RMagic* m) { if (m) { magic_close (m); } } -R_API const char *r_magic_file(RMagic* m, const char * f) { return magic_file (m, f); } -R_API const char *r_magic_descriptor(RMagic* m, int fd) { return magic_descriptor (m, fd); } -R_API const char *r_magic_buffer(RMagic* m, const void *b, size_t s) { return magic_buffer (m, b, s); } -R_API const char *r_magic_error(RMagic* m) { return magic_error (m); } -R_API void r_magic_setflags(RMagic* m, int f) { magic_setflags (m, f); } -R_API bool r_magic_load(RMagic* m, const char *f) { return magic_load (m, f) != -1; } -R_API bool r_magic_compile(RMagic* m, const char *x) { return magic_compile (m, x) != -1; } -R_API bool r_magic_check(RMagic* m, const char *x) { return magic_check (m, x) != -1; } -R_API int r_magic_errno(RMagic* m) { return magic_errno (m); } +RZ_API RzMagic* rz_magic_new(int flags) { return magic_open (flags); } +RZ_API void rz_magic_free(RzMagic* m) { if (m) { magic_close (m); } } +RZ_API const char *rz_magic_file(RzMagic* m, const char * f) { return magic_file (m, f); } +RZ_API const char *rz_magic_descriptor(RzMagic* m, int fd) { return magic_descriptor (m, fd); } +RZ_API const char *rz_magic_buffer(RzMagic* m, const void *b, size_t s) { return magic_buffer (m, b, s); } +RZ_API const char *rz_magic_error(RzMagic* m) { return magic_error (m); } +RZ_API void rz_magic_setflags(RzMagic* m, int f) { magic_setflags (m, f); } +RZ_API bool rz_magic_load(RzMagic* m, const char *f) { return magic_load (m, f) != -1; } +RZ_API bool rz_magic_compile(RzMagic* m, const char *x) { return magic_compile (m, x) != -1; } +RZ_API bool rz_magic_check(RzMagic* m, const char *x) { return magic_check (m, x) != -1; } +RZ_API int rz_magic_errno(RzMagic* m) { return magic_errno (m); } #else @@ -58,7 +58,7 @@ static void free_mlist(struct mlist *mlist) { } for (ml = mlist->next; ml != mlist;) { struct mlist *next = ml->next; - struct r_magic *mg = ml->magic; + struct rz_magic *mg = ml->magic; file_delmagic (mg, ml->mapped, ml->nmagic); free (ml); ml = next; @@ -66,7 +66,7 @@ static void free_mlist(struct mlist *mlist) { free (ml); } -static int info_from_stat(RMagic *ms, unsigned short md) { +static int info_from_stat(RzMagic *ms, unsigned short md) { /* We cannot open it, but we were able to stat it. */ if (md & 0222) { if (file_printf (ms, "writable, ") == -1) { @@ -89,13 +89,13 @@ static int info_from_stat(RMagic *ms, unsigned short md) { return 0; } -static void close_and_restore (const RMagic *ms, const char *name, int fd, const struct stat *sb) { +static void close_and_restore (const RzMagic *ms, const char *name, int fd, const struct stat *sb) { if (fd >= 0) { close (fd); } } -static const char *file_or_fd(RMagic *ms, const char *inname, int fd) { +static const char *file_or_fd(RzMagic *ms, const char *inname, int fd) { bool ispipe = false; int rv = -1; unsigned char *buf; @@ -199,12 +199,12 @@ done: /* API */ // TODO: reinitialize all the time -R_API RMagic* r_magic_new(int flags) { - RMagic *ms = R_NEW0 (RMagic); +RZ_API RzMagic* rz_magic_new(int flags) { + RzMagic *ms = R_NEW0 (RzMagic); if (!ms) { return NULL; } - r_magic_setflags (ms, flags); + rz_magic_setflags (ms, flags); ms->o.buf = ms->o.pbuf = NULL; ms->c.li = malloc ((ms->c.len = 10) * sizeof (*ms->c.li)); if (!ms->c.li) { @@ -218,7 +218,7 @@ R_API RMagic* r_magic_new(int flags) { return ms; } -R_API void r_magic_free(RMagic *ms) { +RZ_API void rz_magic_free(RzMagic *ms) { if (ms) { free_mlist (ms->mlist); free (ms->o.pbuf); @@ -228,7 +228,7 @@ R_API void r_magic_free(RMagic *ms) { } } -R_API bool r_magic_load_buffer(RMagic* ms, const char *magicdata) { +RZ_API bool rz_magic_load_buffer(RzMagic* ms, const char *magicdata) { if (*magicdata == '#') { struct mlist *ml = file_apprentice (ms, magicdata, FILE_LOAD); if (ml) { @@ -242,7 +242,7 @@ R_API bool r_magic_load_buffer(RMagic* ms, const char *magicdata) { return false; } -R_API bool r_magic_load(RMagic* ms, const char *magicfile) { +RZ_API bool rz_magic_load(RzMagic* ms, const char *magicfile) { struct mlist *ml = file_apprentice (ms, magicfile, FILE_LOAD); if (ml) { free_mlist (ms->mlist); @@ -252,27 +252,27 @@ R_API bool r_magic_load(RMagic* ms, const char *magicfile) { return false; } -R_API bool r_magic_compile(RMagic *ms, const char *magicfile) { +RZ_API bool rz_magic_compile(RzMagic *ms, const char *magicfile) { struct mlist *ml = file_apprentice (ms, magicfile, FILE_COMPILE); free_mlist (ml); return ml != NULL; } -R_API bool r_magic_check(RMagic *ms, const char *magicfile) { +RZ_API bool rz_magic_check(RzMagic *ms, const char *magicfile) { struct mlist *ml = file_apprentice (ms, magicfile, FILE_CHECK); free_mlist (ml); return ml != NULL; } -R_API const char* r_magic_descriptor(RMagic *ms, int fd) { +RZ_API const char* rz_magic_descriptor(RzMagic *ms, int fd) { return file_or_fd (ms, NULL, fd); } -R_API const char * r_magic_file(RMagic *ms, const char *inname) { +RZ_API const char * rz_magic_file(RzMagic *ms, const char *inname) { return file_or_fd (ms, inname, 0); // 0 = stdin } -R_API const char * r_magic_buffer(RMagic *ms, const void *buf, size_t nb) { +RZ_API const char * rz_magic_buffer(RzMagic *ms, const void *buf, size_t nb) { if (file_reset (ms) == -1) { return NULL; } @@ -282,21 +282,21 @@ R_API const char * r_magic_buffer(RMagic *ms, const void *buf, size_t nb) { return file_getbuffer (ms); } -R_API const char *r_magic_error(RMagic *ms) { +RZ_API const char *rz_magic_error(RzMagic *ms) { if (ms && ms->haderr) { return ms->o.buf; } return NULL; } -R_API int r_magic_errno(RMagic *ms) { +RZ_API int rz_magic_errno(RzMagic *ms) { if (ms && ms->haderr) { return ms->error; } return 0; } -R_API void r_magic_setflags(RMagic *ms, int flags) { +RZ_API void rz_magic_setflags(RzMagic *ms, int flags) { if (ms) { ms->flags = flags; } diff --git a/libr/magic/mconfig.h b/librz/magic/mconfig.h similarity index 100% rename from libr/magic/mconfig.h rename to librz/magic/mconfig.h diff --git a/libr/magic/mdump.c b/librz/magic/mdump.c similarity index 97% rename from libr/magic/mdump.c rename to librz/magic/mdump.c index 04a7a3a5c4..1290c3c713 100644 --- a/libr/magic/mdump.c +++ b/librz/magic/mdump.c @@ -29,7 +29,7 @@ /* * print.c - debugging printout routines */ -#include +#include #if !USE_LIB_MAGIC @@ -44,7 +44,7 @@ #define SZOF(a) (sizeof(a) / sizeof(a[0])) #ifndef COMPILE_ONLY -void file_mdump(struct r_magic *m) { +void file_mdump(struct rz_magic *m) { static const char optyp[] = { FILE_OPS }; (void) eprintf ("[%u", m->lineno); @@ -171,7 +171,7 @@ void file_mdump(struct r_magic *m) { #endif /*VARARGS*/ -void file_magwarn(struct r_magic_set *ms, const char *f, ...) { +void file_magwarn(struct rz_magic_set *ms, const char *f, ...) { va_list va; /* cuz we use stdout for most, stderr here */ diff --git a/libr/magic/meson.build b/librz/magic/meson.build similarity index 61% rename from libr/magic/meson.build rename to librz/magic/meson.build index 71e7915400..328d039c9d 100644 --- a/libr/magic/meson.build +++ b/librz/magic/meson.build @@ -1,4 +1,4 @@ -r_magic_sources = [ +rz_magic_sources = [ 'apprentice.c', 'ascmagic.c', 'fsmagic.c', @@ -9,38 +9,38 @@ r_magic_sources = [ 'softmagic.c' ] -r_magic_deps = [r_util_dep] +rz_magic_deps = [rz_util_dep] if use_syslib_magic message('Use system-provided magic library') - r_magic_deps += [sys_magic] + rz_magic_deps += [sys_magic] else message('Use bundled magic library') endif -r_magic = library('r_magic', r_magic_sources, +rz_magic = library('rz_magic', rz_magic_sources, include_directories: platform_inc, c_args: library_cflags, - dependencies: r_magic_deps, + dependencies: rz_magic_deps, install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_magic_dep = declare_dependency( - link_with: r_magic, +rz_magic_dep = declare_dependency( + link_with: rz_magic, include_directories: platform_inc ) -pkgconfig_mod.generate(r_magic, - subdirs: 'libr', +pkgconfig_mod.generate(rz_magic, + subdirs: 'librz', version: r2_version, - name: 'r_magic', - filebase: 'r_magic', + name: 'rz_magic', + filebase: 'rz_magic', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) -pkgconfig_magic_requires = ['r_magic'] +pkgconfig_magic_requires = ['rz_magic'] diff --git a/libr/magic/names.h b/librz/magic/names.h similarity index 100% rename from libr/magic/names.h rename to librz/magic/names.h diff --git a/libr/magic/patchlevel.h b/librz/magic/patchlevel.h similarity index 100% rename from libr/magic/patchlevel.h rename to librz/magic/patchlevel.h diff --git a/libr/magic/softmagic.c b/librz/magic/softmagic.c similarity index 93% rename from libr/magic/softmagic.c rename to librz/magic/softmagic.c index 67f5f19c0d..b38c7b107a 100644 --- a/libr/magic/softmagic.c +++ b/librz/magic/softmagic.c @@ -29,32 +29,32 @@ /* * softmagic - interpret variable magic from MAGIC */ -#include +#include #if !USE_LIB_MAGIC #include "file.h" -#include "r_regex.h" +#include "rz_regex.h" #include #include #include #include -static int match(RMagic *, struct r_magic *, ut32, +static int match(RzMagic *, struct rz_magic *, ut32, const ut8 *, size_t, int); -static int mget(RMagic *, const ut8 *, - struct r_magic *, size_t, unsigned int); -static int magiccheck(RMagic *, struct r_magic *); -static st32 mprint(RMagic *, struct r_magic *); +static int mget(RzMagic *, const ut8 *, + struct rz_magic *, size_t, unsigned int); +static int magiccheck(RzMagic *, struct rz_magic *); +static st32 mprint(RzMagic *, struct rz_magic *); static void mdebug(ut32, const char *, size_t); -static int mcopy(RMagic *, union VALUETYPE *, int, int, +static int mcopy(RzMagic *, union VALUETYPE *, int, int, const ut8 *, ut32, size_t, size_t); -static int mconvert(RMagic *, struct r_magic *); -static int print_sep(RMagic *, int); -static void cvt_8(union VALUETYPE *, const struct r_magic *); -static void cvt_16(union VALUETYPE *, const struct r_magic *); -static void cvt_32(union VALUETYPE *, const struct r_magic *); -static void cvt_64(union VALUETYPE *, const struct r_magic *); +static int mconvert(RzMagic *, struct rz_magic *); +static int print_sep(RzMagic *, int); +static void cvt_8(union VALUETYPE *, const struct rz_magic *); +static void cvt_16(union VALUETYPE *, const struct rz_magic *); +static void cvt_32(union VALUETYPE *, const struct rz_magic *); +static void cvt_64(union VALUETYPE *, const struct rz_magic *); /* * Macro to give description string according to whether we want plain @@ -67,7 +67,7 @@ static void cvt_64(union VALUETYPE *, const struct r_magic *); * Passed the name and FILE * of one file to be typed. */ /*ARGSUSED1*/ /* nbytes passed for regularity, maybe need later */ -int file_softmagic(RMagic *ms, const ut8 *buf, size_t nbytes, int mode) { +int file_softmagic(RzMagic *ms, const ut8 *buf, size_t nbytes, int mode) { struct mlist *ml; int rv; for (ml = ms->mlist->next; ml != ms->mlist; ml = ml->next) { @@ -105,7 +105,7 @@ int file_softmagic(RMagic *ms, const ut8 *buf, size_t nbytes, int mode) { * If a continuation matches, we bump the current continuation level * so that higher-level continuations are processed. */ -static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, size_t nbytes, int mode) { +static int match(RzMagic *ms, struct rz_magic *magic, ut32 nmagic, const ut8 *s, size_t nbytes, int mode) { ut32 magindex = 0; unsigned int cont_level = 0; int need_separator = 0; @@ -118,7 +118,7 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s } for (magindex = 0; magindex < nmagic; magindex++) { int flush; - struct r_magic *m = &magic[magindex]; + struct rz_magic *m = &magic[magindex]; if ((m->flag & BINTEST) != mode) { /* Skip sub-tests */ @@ -275,23 +275,23 @@ static int match(RMagic *ms, struct r_magic *magic, ut32 nmagic, const ut8 *s, s return returnval; /* This is hit if -k is set or there is no match */ } -static int check_fmt(RMagic *ms, struct r_magic *m) { - RRegex rx; +static int check_fmt(RzMagic *ms, struct rz_magic *m) { + RzRegex rx; int rc; if (!strchr (R_MAGIC_DESC, '%')) { return 0; } - rc = r_regex_comp (&rx, "%[-0-9\\.]*s", R_REGEX_EXTENDED|R_REGEX_NOSUB); + rc = rz_regex_comp (&rx, "%[-0-9\\.]*s", R_REGEX_EXTENDED|R_REGEX_NOSUB); if (rc) { char errmsg[512]; - r_regex_error (rc, &rx, errmsg, sizeof (errmsg) - 1); + rz_regex_error (rc, &rx, errmsg, sizeof (errmsg) - 1); file_magerror (ms, "regex error %d, (%s)", rc, errmsg); return -1; } else { - rc = r_regex_exec (&rx, R_MAGIC_DESC, 0, 0, 0); - r_regex_fini (&rx); + rc = rz_regex_exec (&rx, R_MAGIC_DESC, 0, 0, 0); + rz_regex_fini (&rx); return !rc; } } @@ -309,7 +309,7 @@ char * strdupn(const char *str, size_t n) { return copy; } -static st32 mprint(RMagic *ms, struct r_magic *m) { +static st32 mprint(RzMagic *ms, struct rz_magic *m) { ut64 v; float vf; double vd; @@ -593,19 +593,19 @@ static st32 mprint(RMagic *ms, struct r_magic *m) { if (m->mask_op & FILE_OPINVERSE) \ p->fld = ~p->fld \ -static void cvt_8(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_8(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT (b, (ut8)); } -static void cvt_16(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_16(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT (h, (ut16)); } -static void cvt_32(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_32(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT (l, (ut32)); } -static void cvt_64(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_64(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT (q, (ut64)); } @@ -626,11 +626,11 @@ static void cvt_64(union VALUETYPE *p, const struct r_magic *m) { break; \ } \ -static void cvt_float(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_float(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT2 (f, (float)); } -static void cvt_double(union VALUETYPE *p, const struct r_magic *m) { +static void cvt_double(union VALUETYPE *p, const struct rz_magic *m) { DO_CVT2 (d, (double)); } @@ -639,7 +639,7 @@ static void cvt_double(union VALUETYPE *p, const struct r_magic *m) { * While we're here, let's apply the mask operation * (unless you have a better idea) */ -static int mconvert(RMagic *ms, struct r_magic *m) { +static int mconvert(RzMagic *ms, struct rz_magic *m) { union VALUETYPE *p = &ms->ms_value; switch (m->type) { @@ -695,7 +695,7 @@ static int mconvert(RMagic *ms, struct r_magic *m) { case FILE_BELONG: case FILE_BEDATE: case FILE_BELDATE: - p->l = (st32) r_read_be32 (p->hl); + p->l = (st32) rz_read_be32 (p->hl); cvt_32(p, m); return 1; case FILE_BEQUAD: @@ -715,7 +715,7 @@ static int mconvert(RMagic *ms, struct r_magic *m) { case FILE_LELONG: case FILE_LEDATE: case FILE_LELDATE: - p->l = (st32) r_read_le32 (p->hl); + p->l = (st32) rz_read_le32 (p->hl); cvt_32(p, m); return 1; case FILE_LEQUAD: @@ -783,7 +783,7 @@ static void mdebug(ut32 offset, const char *str, size_t len) { (void) fputc('\n', stderr); } -static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8 *s, ut32 offset, size_t nbytes, size_t linecnt) { +static int mcopy(RzMagic *ms, union VALUETYPE *p, int type, int indir, const ut8 *s, ut32 offset, size_t nbytes, size_t linecnt) { /* * Note: FILE_SEARCH and FILE_REGEX do not actually copy * anything, but setup pointers into the source @@ -887,7 +887,7 @@ static int mcopy(RMagic *ms, union VALUETYPE *p, int type, int indir, const ut8 return 0; } -static int mget(RMagic *ms, const ut8 *s, struct r_magic *m, size_t nbytes, unsigned int cont_level) { +static int mget(RzMagic *ms, const ut8 *s, struct rz_magic *m, size_t nbytes, unsigned int cont_level) { ut32 offset = ms->offset; ut32 count = m->str_range; union VALUETYPE *p = &ms->ms_value; @@ -1303,7 +1303,7 @@ static ut64 file_strncmp16(const char *a, const char *b, size_t len, ut32 flags) return file_strncmp(a, b, len, flags); } -static int magiccheck(RMagic *ms, struct r_magic *m) { +static int magiccheck(RzMagic *ms, struct rz_magic *m) { ut64 l = m->value.q; ut64 v; float fl, fv; @@ -1419,7 +1419,7 @@ static int magiccheck(RMagic *ms, struct r_magic *m) { } case FILE_REGEX: { int rc; - RRegex rx; + RzRegex rx; char errmsg[512]; if (!ms->search.s) { @@ -1427,16 +1427,16 @@ static int magiccheck(RMagic *ms, struct r_magic *m) { } l = 0; - rc = r_regex_comp (&rx, m->value.s, + rc = rz_regex_comp (&rx, m->value.s, R_REGEX_EXTENDED|R_REGEX_NEWLINE| ((m->str_flags & STRING_IGNORE_CASE) ? R_REGEX_ICASE : 0)); if (rc) { - (void)r_regex_error(rc, &rx, errmsg, sizeof(errmsg) - 1); + (void)rz_regex_error(rc, &rx, errmsg, sizeof(errmsg) - 1); file_magerror(ms, "regex error %d, (%s)", rc, errmsg); v = (ut64) - 1; } else { - RRegexMatch pmatch[1]; + RzRegexMatch pmatch[1]; #ifndef R_REGEX_STARTEND #define R_REGEX_STARTEND 0 size_t l = ms->search.s_len - 1; @@ -1446,7 +1446,7 @@ static int magiccheck(RMagic *ms, struct r_magic *m) { pmatch[0].rm_so = 0; pmatch[0].rm_eo = ms->search.s_len; #endif - rc = r_regex_exec (&rx, (const char *)ms->search.s, 1, pmatch, R_REGEX_STARTEND); + rc = rz_regex_exec (&rx, (const char *)ms->search.s, 1, pmatch, R_REGEX_STARTEND); #if R_REGEX_STARTEND == 0 ((char *)(intptr_t)ms->search.s)[l] = c; #endif @@ -1461,12 +1461,12 @@ static int magiccheck(RMagic *ms, struct r_magic *m) { v = 1; break; default: - (void)r_regex_error (rc, &rx, errmsg, sizeof (errmsg) - 1); + (void)rz_regex_error (rc, &rx, errmsg, sizeof (errmsg) - 1); file_magerror (ms, "regexec error %d, (%s)", rc, errmsg); v = UT64_MAX; break; } - r_regex_fini (&rx); + rz_regex_fini (&rx); } if (v == (ut64)-1) { return -1; @@ -1543,7 +1543,7 @@ static int magiccheck(RMagic *ms, struct r_magic *m) { return matched; } -static int print_sep(RMagic *ms, int firstline) { +static int print_sep(RzMagic *ms, int firstline) { return firstline? 0: file_printf (ms, "\n- "); } #endif diff --git a/libr/magic/tar.h b/librz/magic/tar.h similarity index 100% rename from libr/magic/tar.h rename to librz/magic/tar.h diff --git a/librz/main/Makefile b/librz/main/Makefile new file mode 100644 index 0000000000..c010614dae --- /dev/null +++ b/librz/main/Makefile @@ -0,0 +1,21 @@ +include ../config.mk + +NAME=rz_main + +OBJS+=main.o +OBJS+=rz_ax.o +OBJS+=rz_asm.o +OBJS+=rz_gg.o +OBJS+=rz_run.o +OBJS+=rz_bin.o +OBJS+=rz_sign.o +OBJS+=rz_find.o +OBJS+=rz_agent.o +OBJS+=rz_diff.o +OBJS+=rizin.o +OBJS+=rz_hash.o + +# See MAIN_LINK_ALL +include deps.mk + +include ../rules.mk diff --git a/librz/main/deps.mk b/librz/main/deps.mk new file mode 100644 index 0000000000..15e1eee920 --- /dev/null +++ b/librz/main/deps.mk @@ -0,0 +1,11 @@ +MAIN_LINK_ALL=1 + +ifeq ($(MAIN_LINK_ALL),1) +R2DEPS=rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_core +R2DEPS+=rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg +R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto +else +# only works +WITH_LIBS=0 +WITH_LIBR=1 +endif diff --git a/libr/main/index.h b/librz/main/index.h similarity index 91% rename from libr/main/index.h rename to librz/main/index.h index 45a9d3c73f..8781bd6087 100644 --- a/libr/main/index.h +++ b/librz/main/index.h @@ -1,7 +1,7 @@ static const char *page_index = "" "" -"r2agent" +"rz_agent" "" "" "" -"

r2agent

" +"

rz_agent

" "
" "File
" " - open
" diff --git a/librz/main/main.c b/librz/main/main.c new file mode 100644 index 0000000000..2a816b5add --- /dev/null +++ b/librz/main/main.c @@ -0,0 +1,53 @@ +/* radare - LGPL - Copyright 2012-2020 - pancake */ + +#include +#include +#include +#include + +R_LIB_VERSION(rz_main); + +static RzMain foo[] = { + { "r2", rz_main_rizin }, + { "rz_ax", rz_main_rz_ax }, + { "rz_diff", rz_main_rz_diff }, + { "rz_find", rz_main_rz_find }, + { "rz_run", rz_main_rz_run }, + { "rz_asm", rz_main_rz_asm }, + { "rz_gg", rz_main_rz_gg }, + { "rz_bin", rz_main_rz_bin }, + { "rizin", rz_main_rizin }, + { NULL, NULL } +}; + +RZ_API RzMain *rz_main_new (const char *name) { + int i = 0; + while (foo[i].name) { + if (!strcmp (name, foo[i].name)) { + RzMain *m = R_NEW0 (RzMain); + if (m) { + m->name = strdup (foo[i].name); + m->main = foo[i].main; + } + return m; + } + i++; + } + return NULL; +} + +RZ_API void rz_main_free(RzMain *m) { + free (m); +} + +RZ_API int rz_main_run(RzMain *m, int argc, const char **argv) { + rz_return_val_if_fail (m && m->main, -1); + return m->main (argc, argv); +} + +RZ_API int rz_main_version_print(const char *progname) { + char *s = rz_str_version (progname); + printf ("%s\n", s); + free (s); + return 0; +} diff --git a/librz/main/meson.build b/librz/main/meson.build new file mode 100644 index 0000000000..1bc530280d --- /dev/null +++ b/librz/main/meson.build @@ -0,0 +1,68 @@ +rz_main_sources = [ + 'main.c', + 'rz_agent.c', + 'rz_bin.c', + 'rizin.c', + 'rz_diff.c', + 'rz_find.c', + 'rz_gg.c', + 'rz_hash.c', + 'rz_run.c', + 'rz_sign.c', + 'rz_asm.c', + 'rz_ax.c' +] + +rz_main_deps = [ + rz_config_dep, + rz_cons_dep, + rz_io_dep, + rz_util_dep, + rz_flag_dep, + rz_asm_dep, + rz_core_dep, + rz_debug_dep, + rz_hash_dep, + rz_bin_dep, + rz_lang_dep, + rz_io_dep, + rz_anal_dep, + rz_parse_dep, + rz_bp_dep, + rz_egg_dep, + rz_reg_dep, + rz_search_dep, + rz_syscall_dep, + rz_socket_dep, + rz_fs_dep, + rz_magic_dep, + rz_crypto_dep +] + +rz_main = library('rz_main', rz_main_sources, + include_directories: [platform_inc], + c_args: library_cflags, + dependencies: rz_main_deps, + install: true, + implicit_include_directories: false, + install_rpath: rpath_lib, + soversion: r2_libversion +) + +rz_main_dep = declare_dependency(link_with: rz_main, + include_directories: [platform_inc], + dependencies: rz_main_deps) + +pkgconfig_mod.generate(rz_main, + subdirs: 'librz', + version: r2_version, + name: 'rz_main', + libraries: pkgcfg_sanitize_libs, + filebase: 'rz_main', + requires: [ + 'rz_core', + 'rz_asm', + 'rz_syscall' + ], + description: 'radare foundation libraries' +) diff --git a/libr/main/radare2.c b/librz/main/rizin.c similarity index 58% rename from libr/main/radare2.c rename to librz/main/rizin.c index fd1409d9a9..454d930eff 100644 --- a/libr/main/radare2.c +++ b/librz/main/rizin.c @@ -9,22 +9,22 @@ #endif #endif -#include +#include -static bool is_valid_gdb_file(RCoreFile *fh) { - RIODesc *d = fh && fh->core ? r_io_desc_get (fh->core->io, fh->fd) : NULL; +static bool is_valid_gdb_file(RzCoreFile *fh) { + RzIODesc *d = fh && fh->core ? rz_io_desc_get (fh->core->io, fh->fd) : NULL; return d && strncmp (d->name, "gdb://", 6); } static char* get_file_in_cur_dir(const char *filepath) { - filepath = r_file_basename (filepath); - if (r_file_exists (filepath) && !r_file_is_directory (filepath)) { - return r_file_abspath (filepath); + filepath = rz_file_basename (filepath); + if (rz_file_exists (filepath) && !rz_file_is_directory (filepath)) { + return rz_file_abspath (filepath); } return NULL; } -static int r_main_version_verify(int show) { +static int rz_main_version_verify(int show) { int i, ret; typedef const char* (*vc)(); const char *base = R2_GITTAP; @@ -32,30 +32,30 @@ static int r_main_version_verify(int show) { const char *name; vc callback; } vcs[] = { - { "r_anal", r_anal_version }, - { "r_lib", r_lib_version }, - { "r_egg", r_egg_version }, - { "r_asm", r_asm_version }, - { "r_bin", r_bin_version }, - { "r_cons", r_cons_version }, - { "r_flag", r_flag_version }, - { "r_core", r_core_version }, - { "r_crypto", r_crypto_version }, - { "r_bp", r_bp_version }, - { "r_debug", r_debug_version }, - { "r_main", r_main_version }, - { "r_hash", r_hash_version }, - { "r_fs", r_fs_version }, - { "r_io", r_io_version }, + { "rz_anal", rz_anal_version }, + { "rz_lib", rz_lib_version }, + { "rz_egg", rz_egg_version }, + { "rz_asm", rz_asm_version }, + { "rz_bin", rz_bin_version }, + { "rz_cons", rz_cons_version }, + { "rz_flag", rz_flag_version }, + { "rz_core", rz_core_version }, + { "rz_crypto", rz_crypto_version }, + { "rz_bp", rz_bp_version }, + { "rz_debug", rz_debug_version }, + { "rz_main", rz_main_version }, + { "rz_hash", rz_hash_version }, + { "rz_fs", rz_fs_version }, + { "rz_io", rz_io_version }, #if !USE_LIB_MAGIC - { "r_magic", r_magic_version }, + { "rz_magic", rz_magic_version }, #endif - { "r_parse", r_parse_version }, - { "r_reg", r_reg_version }, - { "r_sign", r_sign_version }, - { "r_search", r_search_version }, - { "r_syscall", r_syscall_version }, - { "r_util", r_util_version }, + { "rz_parse", rz_parse_version }, + { "rz_reg", rz_reg_version }, + { "rz_sign", rz_sign_version }, + { "rz_search", rz_search_version }, + { "rz_syscall", rz_syscall_version }, + { "rz_util", rz_util_version }, /* ... */ {NULL,NULL} }; @@ -90,7 +90,7 @@ static int main_help(int line) { } if (line != 1) { printf ( - " -- run radare2 without opening any file\n" + " -- run rizin without opening any file\n" " - same as 'r2 malloc://512'\n" " = read file from stdin (use -i and -c to run cmds)\n" " -= perform !=! command to run all commands remotely\n" @@ -124,28 +124,28 @@ static int main_help(int line) { " -Q quiet mode (no prompt) and quit faster (quickLeak=true)\n" " -p [prj] use project, list if no arg, load if no file\n" " -P [file] apply rapatch file and quit\n" - " -r [rarun2] specify rarun2 profile to load (same as -e dbg.profile=X)\n" - " -R [rr2rule] specify custom rarun2 directive\n" + " -r [rz_run] specify rz_run profile to load (same as -e dbg.profile=X)\n" + " -R [rrz_testule] specify custom rz_run directive\n" " -s [addr] initial seek\n" " -S start r2 in sandbox mode\n" #if USE_THREADS && ALLOW_THREADED - " -t load rabin2 info in thread\n" + " -t load rz_bin info in thread\n" #endif " -T do not compute file hashes\n" " -u set bin.filter=false to get raw sym/sec/cls names\n" - " -v, -V show radare2 version (-V show lib versions)\n" + " -v, -V show rizin version (-V show lib versions)\n" " -w open file in write mode\n" " -x open without exec-flag (asm.emu will not work), See io.exec\n" " -X same as -e bin.usextr=false (useful for dyldcache)\n" " -z, -zz do not load strings or load them even in raw\n"); } if (line == 2) { - char *datahome = r_str_home (R2_HOME_DATADIR); - const char *dirPrefix = r_sys_prefix (NULL); + char *datahome = rz_str_home (R2_HOME_DATADIR); + const char *dirPrefix = rz_sys_prefix (NULL); printf ( "Scripts:\n" - " system ${R2_PREFIX}/share/radare2/radare2rc\n" - " user ~/.radare2rc " R_JOIN_2_PATHS ("~", R2_HOME_RC) " (and " R_JOIN_3_PATHS ("~", R2_HOME_RC_DIR,"") ")\n" + " system ${R2_PREFIX}/share/rizin/rizinrc\n" + " user ~/.rizinrc " R_JOIN_2_PATHS ("~", R2_HOME_RC) " (and " R_JOIN_3_PATHS ("~", R2_HOME_RC_DIR,"") ")\n" " file ${filename}.r2\n" "Plugins:\n" " binrc " R_JOIN_4_PATHS ("~", R2_HOME_BINRC, "bin-", "") " (elf, elf64, mach0, ..)\n" @@ -158,7 +158,7 @@ static int main_help(int line) { " R2_DEBUG_ASSERT=1 set a breakpoint when hitting an assert\n" " R2_MAGICPATH " R_JOIN_2_PATHS ("%s", R2_SDB_MAGIC) "\n" " R2_NOPLUGINS do not load r2 shared plugins\n" - " R2_RCFILE ~/.radare2rc (user preferences, batch script)\n" // TOO GENERIC + " R2_RCFILE ~/.rizinrc (user preferences, batch script)\n" // TOO GENERIC " R2_RDATAHOME %s\n" // TODO: rename to RHOME R2HOME? " R2_VERSION contains the current version of r2\n" "Paths:\n" @@ -175,20 +175,20 @@ static int main_help(int line) { static int main_print_var(const char *var_name) { int i = 0; #ifdef __WINDOWS__ - char *incdir = r_str_r2_prefix (R2_INCDIR); - char *libdir = r_str_r2_prefix (R2_LIBDIR); + char *incdir = rz_str_rz_prefix (R2_INCDIR); + char *libdir = rz_str_rz_prefix (R2_LIBDIR); #else char *incdir = strdup (R2_INCDIR); char *libdir = strdup (R2_LIBDIR); #endif - char *confighome = r_str_home (R2_HOME_CONFIGDIR); - char *datahome = r_str_home (R2_HOME_DATADIR); - char *cachehome = r_str_home (R2_HOME_CACHEDIR); - char *homeplugins = r_str_home (R2_HOME_PLUGINS); - char *homezigns = r_str_home (R2_HOME_ZIGNS); - char *plugins = r_str_r2_prefix (R2_PLUGINS); - char *magicpath = r_str_r2_prefix (R2_SDB_MAGIC); - struct radare2_var_t { + char *confighome = rz_str_home (R2_HOME_CONFIGDIR); + char *datahome = rz_str_home (R2_HOME_DATADIR); + char *cachehome = rz_str_home (R2_HOME_CACHEDIR); + char *homeplugins = rz_str_home (R2_HOME_PLUGINS); + char *homezigns = rz_str_home (R2_HOME_ZIGNS); + char *plugins = rz_str_rz_prefix (R2_PLUGINS); + char *magicpath = rz_str_rz_prefix (R2_SDB_MAGIC); + struct rizin_var_t { const char *name; const char *value; } r2_vars[] = { @@ -236,41 +236,41 @@ static int main_print_var(const char *var_name) { return 0; } -static bool run_commands(RCore *r, RList *cmds, RList *files, bool quiet, int do_analysis) { - RListIter *iter; +static bool run_commands(RzCore *r, RzList *cmds, RzList *files, bool quiet, int do_analysis) { + RzListIter *iter; const char *cmdn; const char *file; int ret; /* -i */ - r_list_foreach (files, iter, file) { - if (!r_file_exists (file)) { + rz_list_foreach (files, iter, file) { + if (!rz_file_exists (file)) { eprintf ("Script '%s' not found.\n", file); goto beach; } - ret = r_core_run_script (r, file); + ret = rz_core_run_script (r, file); if (ret == -2) { eprintf ("[c] Cannot open '%s'\n", file); } if (ret < 0 || (ret == 0 && quiet)) { - r_cons_flush (); + rz_cons_flush (); return false; } } /* -c */ - r_list_foreach (cmds, iter, cmdn) { - //r_core_cmd0 (r, cmdn); - r_core_cmd_lines (r, cmdn); - r_cons_flush (); + rz_list_foreach (cmds, iter, cmdn) { + //rz_core_cmd0 (r, cmdn); + rz_core_cmd_lines (r, cmdn); + rz_cons_flush (); } beach: if (quiet) { if (do_analysis) { return true; } - if (cmds && !r_list_empty (cmds)) { + if (cmds && !rz_list_empty (cmds)) { return true; } - if (!r_list_empty (files)) { + if (!rz_list_empty (files)) { return true; } } @@ -278,60 +278,60 @@ beach: } static bool mustSaveHistory(RConfig *c) { - if (!r_config_get_i (c, "scr.histsave")) { + if (!rz_config_get_i (c, "scr.histsave")) { return false; } - if (!r_cons_is_interactive ()) { + if (!rz_cons_is_interactive ()) { return false; } return true; } // Try to set the correct scr.color for the current terminal. -static void set_color_default(RCore *r) { +static void set_color_default(RzCore *r) { #ifdef __WINDOWS__ - char *alacritty = r_sys_getenv ("ALACRITTY_LOG"); + char *alacritty = rz_sys_getenv ("ALACRITTY_LOG"); if (alacritty) { // Despite the setting of env vars to the contrary, Alacritty on // Windows may not actually support >16 colors out-of-the-box // (https://github.com/jwilm/alacritty/issues/1662). // TODO: Windows 10 version check. - r_config_set_i (r->config, "scr.color", COLOR_MODE_16); + rz_config_set_i (r->config, "scr.color", COLOR_MODE_16); free (alacritty); return; } #endif - char *tmp = r_sys_getenv ("COLORTERM"); + char *tmp = rz_sys_getenv ("COLORTERM"); if (tmp) { - if ((r_str_endswith (tmp, "truecolor") || r_str_endswith (tmp, "24bit"))) { - r_config_set_i (r->config, "scr.color", COLOR_MODE_16M); + if ((rz_str_endswith (tmp, "truecolor") || rz_str_endswith (tmp, "24bit"))) { + rz_config_set_i (r->config, "scr.color", COLOR_MODE_16M); } } else { - tmp = r_sys_getenv ("TERM"); + tmp = rz_sys_getenv ("TERM"); if (!tmp) { return; } - if (r_str_endswith (tmp, "truecolor") || r_str_endswith (tmp, "24bit")) { - r_config_set_i (r->config, "scr.color", COLOR_MODE_16M); - } else if (r_str_endswith (tmp, "256color")) { - r_config_set_i (r->config, "scr.color", COLOR_MODE_256); + if (rz_str_endswith (tmp, "truecolor") || rz_str_endswith (tmp, "24bit")) { + rz_config_set_i (r->config, "scr.color", COLOR_MODE_16M); + } else if (rz_str_endswith (tmp, "256color")) { + rz_config_set_i (r->config, "scr.color", COLOR_MODE_256); } else if (!strcmp (tmp, "dumb")) { // Dumb terminals don't get color by default. - r_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); } } free (tmp); } -R_API int r_main_radare2(int argc, const char **argv) { - RCore *r; +RZ_API int rz_main_rizin(int argc, const char **argv) { + RzCore *r; bool forcequit = false; bool haveRarunProfile = false; - RListIter *iter; + RzListIter *iter; int do_analysis = 0; char *cmdn, *tmp; - RCoreFile *fh = NULL; - RIODesc *iod = NULL; + RzCoreFile *fh = NULL; + RzIODesc *iod = NULL; const char *patchfile = NULL; const char *prj = NULL; int debug = 0; @@ -362,17 +362,17 @@ R_API int r_main_radare2(int argc, const char **argv) { int is_gdb = false; const char * s_seek = NULL; bool compute_hashes = true; - RList *cmds = r_list_new (); - RList *evals = r_list_new (); - RList *files = r_list_new (); - RList *prefiles = r_list_new (); + RzList *cmds = rz_list_new (); + RzList *evals = rz_list_new (); + RzList *files = rz_list_new (); + RzList *prefiles = rz_list_new (); #define LISTS_FREE() \ { \ - r_list_free (cmds); \ - r_list_free (evals); \ - r_list_free (files); \ - r_list_free (prefiles); \ + rz_list_free (cmds); \ + rz_list_free (evals); \ + rz_list_free (files); \ + rz_list_free (prefiles); \ } bool noStderr = false; @@ -381,24 +381,24 @@ R_API int r_main_radare2(int argc, const char **argv) { sigset_t sigBlockMask; sigemptyset (&sigBlockMask); sigaddset (&sigBlockMask, SIGWINCH); - r_signal_sigmask (SIG_BLOCK, &sigBlockMask, NULL); + rz_signal_sigmask (SIG_BLOCK, &sigBlockMask, NULL); #endif - r_sys_env_init (); - // Create rarun2 profile with startup environ - char **env = r_sys_get_environ (); - char *envprofile = r_run_get_environ_profile (env); + rz_sys_env_init (); + // Create rz_run profile with startup environ + char **env = rz_sys_get_environ (); + char *envprofile = rz_run_get_environ_profile (env); - if (r_sys_getenv_asbool ("R2_DEBUG")) { - char *sysdbg = r_sys_getenv ("R2_DEBUG_TOOL"); + if (rz_sys_getenv_asbool ("R2_DEBUG")) { + char *sysdbg = rz_sys_getenv ("R2_DEBUG_TOOL"); char *fmt = (sysdbg && *sysdbg) - ? r_str_newf ("%s %%d", sysdbg) + ? rz_str_newf ("%s %%d", sysdbg) #if __APPLE__ - : r_str_newf ("lldb -p %%d"); + : rz_str_newf ("lldb -p %%d"); #else - : r_str_newf ("gdb --pid %%d"); + : rz_str_newf ("gdb --pid %%d"); #endif - r_sys_crash_handler (fmt); + rz_sys_crash_handler (fmt); free (fmt); free (sysdbg); } @@ -406,26 +406,26 @@ R_API int r_main_radare2(int argc, const char **argv) { LISTS_FREE (); return main_help (1); } - r = r_core_new (); + r = rz_core_new (); if (!r) { - eprintf ("Cannot initialize RCore\n"); + eprintf ("Cannot initialize RzCore\n"); LISTS_FREE (); return 1; } - r->r_main_radare2 = r_main_radare2; - r->r_main_radiff2 = r_main_radiff2; - r->r_main_rafind2 = r_main_rafind2; - r->r_main_rabin2 = r_main_rabin2; - r->r_main_ragg2 = r_main_ragg2; - r->r_main_rasm2 = r_main_rasm2; - r->r_main_rax2 = r_main_rax2; + r->rz_main_rizin = rz_main_rizin; + r->rz_main_rz_diff = rz_main_rz_diff; + r->rz_main_rz_find = rz_main_rz_find; + r->rz_main_rz_bin = rz_main_rz_bin; + r->rz_main_rz_gg = rz_main_rz_gg; + r->rz_main_rz_asm = rz_main_rz_asm; + r->rz_main_rz_ax = rz_main_rz_ax; r->io->envprofile = envprofile; - r_core_task_sync_begin (&r->tasks); + rz_core_task_sync_begin (&r->tasks); if (argc == 2 && !strcmp (argv[1], "-p")) { - r_core_project_list (r, 0); - r_cons_flush (); + rz_core_project_list (r, 0); + rz_cons_flush (); LISTS_FREE (); return 0; } @@ -446,9 +446,9 @@ R_API int r_main_radare2(int argc, const char **argv) { set_color_default (r); bool load_l = true; - RGetopt opt; - r_getopt_init (&opt, argc, argv, "=02AMCwxfF:H:hm:e:nk:NdqQs:p:b:B:a:Lui:I:l:P:R:r:c:D:vVSTzuXt"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "=02AMCwxfF:H:hm:e:nk:NdqQs:p:b:B:a:Lui:I:l:P:R:r:c:D:vVSTzuXt"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case '=': R_FREE (r->cmdremote); @@ -460,13 +460,13 @@ R_API int r_main_radare2(int argc, const char **argv) { case '0': zerosep = true; /* implicit -q */ - r_config_set (r->config, "scr.interactive", "false"); - r_config_set (r->config, "scr.prompt", "false"); - r_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set (r->config, "scr.interactive", "false"); + rz_config_set (r->config, "scr.prompt", "false"); + rz_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); quiet = true; break; case 'u': - r_config_set (r->config, "bin.filter", "false"); + rz_config_set (r->config, "bin.filter", "false"); break; case 'a': asmarch = opt.arg; @@ -481,13 +481,13 @@ R_API int r_main_radare2(int argc, const char **argv) { asmbits = opt.arg; break; case 'B': - baddr = r_num_math (r->num, opt.arg); + baddr = rz_num_math (r->num, opt.arg); break; case 'X': - r_config_set (r->config, "bin.usextr", "false"); + rz_config_set (r->config, "bin.usextr", "false"); break; case 'c': - r_list_append (cmds, (void*)opt.arg); + rz_list_append (cmds, (void*)opt.arg); break; case 'C': do_connect = true; @@ -502,18 +502,18 @@ R_API int r_main_radare2(int argc, const char **argv) { free (debugbackend); debugbackend = strdup (opt.arg); if (!strcmp (opt.arg, "?")) { - r_debug_plugin_list (r->dbg, 'q'); - r_cons_flush(); + rz_debug_plugin_list (r->dbg, 'q'); + rz_cons_flush(); LISTS_FREE (); return 0; } break; case 'e': if (!strcmp (opt.arg, "q")) { - r_core_cmd0 (r, "eq"); + rz_core_cmd0 (r, "eq"); } else { - r_config_eval (r->config, opt.arg, false); - r_list_append (evals, (void*)opt.arg); + rz_config_eval (r->config, opt.arg, false); + rz_list_append (evals, (void*)opt.arg); } break; case 'f': @@ -535,7 +535,7 @@ R_API int r_main_radare2(int argc, const char **argv) { ret = 1; goto beach; } - r_list_append (files, (void*)opt.arg); + rz_list_append (files, (void*)opt.arg); break; case 'I': if (R_STR_ISEMPTY (opt.arg)) { @@ -543,25 +543,25 @@ R_API int r_main_radare2(int argc, const char **argv) { ret = 1; goto beach; } - r_list_append (prefiles, (void*)opt.arg); + rz_list_append (prefiles, (void*)opt.arg); break; case 'k': asmos = opt.arg; break; case 'l': - r_lib_open (r->lib, opt.arg); + rz_lib_open (r->lib, opt.arg); break; case 'L': do_list_io_plugins = true; break; case 'm': - mapaddr = r_num_math (r->num, opt.arg); + mapaddr = rz_num_math (r->num, opt.arg); s_seek = opt.arg; - r_config_set_i (r->config, "file.offset", mapaddr); + rz_config_set_i (r->config, "file.offset", mapaddr); break; case 'M': - r_config_set (r->config, "bin.demangle", "false"); - r_config_set (r->config, "asm.demangle", "false"); + rz_config_set (r->config, "bin.demangle", "false"); + rz_config_set (r->config, "asm.demangle", "false"); break; case 'n': if (load_bin == LOAD_BIN_ALL) { // "-n" @@ -569,7 +569,7 @@ R_API int r_main_radare2(int argc, const char **argv) { } else if (load_bin == LOAD_BIN_NOTHING) { // second n => "-nn" load_bin = LOAD_BIN_STRUCTURES_ONLY; } - r_config_set (r->config, "file.info", "false"); + rz_config_set (r->config, "file.info", "false"); break; case 'N': if (run_rc) { @@ -580,12 +580,12 @@ R_API int r_main_radare2(int argc, const char **argv) { break; case 'p': if (!strcmp (opt.arg, "?")) { - r_core_project_list (r, 0); - r_cons_flush (); + rz_core_project_list (r, 0); + rz_cons_flush (); LISTS_FREE (); return 0; } - r_config_set (r->config, "prj.name", opt.arg); + rz_config_set (r->config, "prj.name", opt.arg); break; case 'P': if (R_STR_ISEMPTY (opt.arg)) { @@ -600,9 +600,9 @@ R_API int r_main_radare2(int argc, const char **argv) { quietLeak = true; break; case 'q': - r_config_set (r->config, "scr.interactive", "false"); - r_config_set (r->config, "scr.prompt", "false"); - r_config_set (r->config, "cfg.fortunes", "false"); + rz_config_set (r->config, "scr.interactive", "false"); + rz_config_set (r->config, "scr.prompt", "false"); + rz_config_set (r->config, "cfg.fortunes", "false"); if (quiet) { forcequit = true; } @@ -610,15 +610,15 @@ R_API int r_main_radare2(int argc, const char **argv) { break; case 'r': if (R_STR_ISEMPTY (opt.arg)) { - eprintf ("Cannot open empty rarun2 profile path\n"); + eprintf ("Cannot open empty rz_run profile path\n"); ret = 1; goto beach; } haveRarunProfile = true; - r_config_set (r->config, "dbg.profile", opt.arg); + rz_config_set (r->config, "dbg.profile", opt.arg); break; case 'R': - customRarunProfile = r_str_appendf (customRarunProfile, "%s\n", opt.arg); + customRarunProfile = rz_str_appendf (customRarunProfile, "%s\n", opt.arg); break; case 's': s_seek = opt.arg; @@ -645,19 +645,19 @@ R_API int r_main_radare2(int argc, const char **argv) { free (customRarunProfile); return 0; } else { - r_main_version_verify (0); + rz_main_version_verify (0); LISTS_FREE (); free (customRarunProfile); - return r_main_version_print ("radare2"); + return rz_main_version_print ("rizin"); } case 'V': - return r_main_version_verify (1); + return rz_main_version_verify (1); case 'w': perms |= R_PERM_W; break; case 'x': perms &= ~R_PERM_X; - r_config_set (r->config, "io.exec", "false"); + rz_config_set (r->config, "io.exec", "false"); break; default: help++; @@ -694,9 +694,9 @@ R_API int r_main_radare2(int argc, const char **argv) { } } { - const char *dbg_profile = r_config_get (r->config, "dbg.profile"); + const char *dbg_profile = rz_config_get (r->config, "dbg.profile"); if (dbg_profile && *dbg_profile) { - char *msg = r_file_slurp (dbg_profile, NULL); + char *msg = rz_file_slurp (dbg_profile, NULL); if (msg) { char *program = strstr (msg, "program="); if (program) { @@ -728,16 +728,16 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (do_list_io_plugins) { - if (r_config_get_i (r->config, "cfg.plugins")) { - r_core_loadlibs (r, R_CORE_LOADLIBS_ALL, NULL); + if (rz_config_get_i (r->config, "cfg.plugins")) { + rz_core_loadlibs (r, R_CORE_LOADLIBS_ALL, NULL); } run_commands (r, NULL, prefiles, false, do_analysis); run_commands (r, cmds, files, quiet, do_analysis); if (quietLeak) { exit (0); } - r_io_plugin_list (r->io); - r_cons_flush (); + rz_io_plugin_list (r->io); + rz_cons_flush (); LISTS_FREE (); free (pfile); R_FREE (debugbackend); @@ -751,15 +751,15 @@ R_API int r_main_radare2(int argc, const char **argv) { return main_help (help > 1? 2: 0); } #if __WINDOWS__ - pfile = r_acp_to_utf8 (pfile); + pfile = rz_acp_to_utf8 (pfile); #endif // __WINDOWS__ if (customRarunProfile) { - char *tfn = r_file_temp (".rarun2"); - if (!r_file_dump (tfn, (const ut8*)customRarunProfile, strlen (customRarunProfile), 0)) { + char *tfn = rz_file_temp (".rz_run"); + if (!rz_file_dump (tfn, (const ut8*)customRarunProfile, strlen (customRarunProfile), 0)) { eprintf ("Cannot create %s\n", tfn); } else { haveRarunProfile = true; - r_config_set (r->config, "dbg.profile", tfn); + rz_config_set (r->config, "dbg.profile", tfn); } free (tfn); } @@ -792,23 +792,23 @@ R_API int r_main_radare2(int argc, const char **argv) { } tmp = NULL; - if (!load_l || (tmp = r_sys_getenv ("R2_NOPLUGINS"))) { - r_config_set_i (r->config, "cfg.plugins", 0); + if (!load_l || (tmp = rz_sys_getenv ("R2_NOPLUGINS"))) { + rz_config_set_i (r->config, "cfg.plugins", 0); free (tmp); } - if (r_config_get_i (r->config, "cfg.plugins")) { - r_core_loadlibs (r, R_CORE_LOADLIBS_ALL, NULL); + if (rz_config_get_i (r->config, "cfg.plugins")) { + rz_core_loadlibs (r, R_CORE_LOADLIBS_ALL, NULL); } ret = run_commands (r, NULL, prefiles, false, do_analysis); - r_list_free (prefiles); + rz_list_free (prefiles); prefiles = NULL; - r_bin_force_plugin (r->bin, forcebin); + rz_bin_force_plugin (r->bin, forcebin); - prj = r_config_get (r->config, "prj.name"); + prj = rz_config_get (r->config, "prj.name"); if (prj && *prj) { - r_core_project_open (r, prj, false); - r_config_set (r->config, "bin.strings", "false"); + rz_core_project_open (r, prj, false); + rz_config_set (r->config, "bin.strings", "false"); } if (do_connect) { @@ -820,56 +820,56 @@ R_API int r_main_radare2(int argc, const char **argv) { return 1; } if (strstr (uri, "://")) { - r_core_cmdf (r, "=+ %s", uri); + rz_core_cmdf (r, "=+ %s", uri); } else { - argv[opt.ind] = r_str_newf ("http://%s/cmd/", argv[opt.ind]); - r_core_cmdf (r, "=+ %s", argv[opt.ind]); + argv[opt.ind] = rz_str_newf ("http://%s/cmd/", argv[opt.ind]); + rz_core_cmdf (r, "=+ %s", argv[opt.ind]); } - r_core_cmd0 (r, "=!=0"); + rz_core_cmd0 (r, "=!=0"); argv[opt.ind] = "-"; } switch (zflag) { case 1: - r_config_set (r->config, "bin.strings", "false"); + rz_config_set (r->config, "bin.strings", "false"); break; case 2: - r_config_set (r->config, "bin.rawstr", "true"); + rz_config_set (r->config, "bin.rawstr", "true"); break; } if (zflag > 3) { eprintf ("Sleeping now...\n"); - r_sys_sleep (zflag); + rz_sys_sleep (zflag); } if (run_rc) { - r_core_parse_radare2rc (r); + rz_core_parse_rizinrc (r); } else { - r_config_set (r->config, "scr.utf8", "false"); + rz_config_set (r->config, "scr.utf8", "false"); } - if (r_config_get_i (r->config, "zign.autoload")) { - char *path = r_file_abspath (r_config_get (r->config, "dir->zigns")); + if (rz_config_get_i (r->config, "zign.autoload")) { + char *path = rz_file_abspath (rz_config_get (r->config, "dir->zigns")); char *complete_path = NULL; - RList *list = r_sys_dir (path); - RListIter *iter; + RzList *list = rz_sys_dir (path); + RzListIter *iter; char *file = NULL; - r_list_foreach (list, iter, file) { + rz_list_foreach (list, iter, file) { if (file && *file && *file != '.') { - complete_path = r_str_newf ("%s"R_SYS_DIR"%s", path, file); - if (r_str_endswith (complete_path, "gz")) { - r_sign_load_gz (r->anal, complete_path); + complete_path = rz_str_newf ("%s"R_SYS_DIR"%s", path, file); + if (rz_str_endswith (complete_path, "gz")) { + rz_sign_load_gz (r->anal, complete_path); } else { - r_sign_load (r->anal, complete_path); + rz_sign_load (r->anal, complete_path); } free (complete_path); } } - r_list_free (list); + rz_list_free (list); free (path); } - if (pfile && r_file_is_directory (pfile)) { + if (pfile && rz_file_is_directory (pfile)) { if (debug) { eprintf ("Error: Cannot debug directories, yet.\n"); LISTS_FREE (); @@ -877,7 +877,7 @@ R_API int r_main_radare2(int argc, const char **argv) { R_FREE (debugbackend); return 1; } - if (r_sys_chdir (argv[opt.ind])) { + if (rz_sys_chdir (argv[opt.ind])) { eprintf ("[d] Cannot open directory\n"); LISTS_FREE (); free (pfile); @@ -887,9 +887,9 @@ R_API int r_main_radare2(int argc, const char **argv) { } else if (argv[opt.ind] && !strcmp (argv[opt.ind], "=")) { int sz; /* stdin/batch mode */ - char *buf = r_stdin_slurp (&sz); + char *buf = rz_stdin_slurp (&sz); eprintf ("^D\n"); - r_cons_set_raw (false); + rz_cons_set_raw (false); #if __UNIX__ // TODO: keep flags :? (void)freopen ("/dev/tty", "rb", stdin); @@ -901,20 +901,20 @@ R_API int r_main_radare2(int argc, const char **argv) { return 1; #endif if (buf && sz > 0) { - char *path = r_str_newf ("malloc://%d", sz); - fh = r_core_file_open (r, path, perms, mapaddr); + char *path = rz_str_newf ("malloc://%d", sz); + fh = rz_core_file_open (r, path, perms, mapaddr); if (!fh) { - r_cons_flush (); + rz_cons_flush (); free (buf); eprintf ("[=] Cannot open '%s'\n", path); LISTS_FREE (); free (path); return 1; } - r_io_map_new (r->io, fh->fd, 7, 0LL, mapaddr, - r_io_fd_size (r->io, fh->fd)); - r_io_write_at (r->io, mapaddr, (const ut8 *)buf, sz); - r_core_block_read (r); + rz_io_map_new (r->io, fh->fd, 7, 0LL, mapaddr, + rz_io_fd_size (r->io, fh->fd)); + rz_io_write_at (r->io, mapaddr, (const ut8 *)buf, sz); + rz_core_block_read (r); free (buf); free (path); // TODO: load rbin thing @@ -924,13 +924,13 @@ R_API int r_main_radare2(int argc, const char **argv) { LISTS_FREE (); return 1; } - } else if (strcmp (argv[opt.ind - 1], "--") && !(r_config_get (r->config, "prj.name") && r_config_get (r->config, "prj.name")[0]) ) { + } else if (strcmp (argv[opt.ind - 1], "--") && !(rz_config_get (r->config, "prj.name") && rz_config_get (r->config, "prj.name")[0]) ) { if (debug) { if (asmbits) { - r_config_set (r->config, "asm.bits", asmbits); + rz_config_set (r->config, "asm.bits", asmbits); } - r_config_set (r->config, "search.in", "dbg.map"); // implicit? - r_config_set (r->config, "cfg.debug", "true"); + rz_config_set (r->config, "search.in", "dbg.map"); // implicit? + rz_config_set (r->config, "cfg.debug", "true"); perms = R_PERM_RWX; if (opt.ind >= argc) { eprintf ("No program given to -d\n"); @@ -940,7 +940,7 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (debug == 2) { // autodetect backend with -D - r_config_set (r->config, "dbg.backend", debugbackend); + rz_config_set (r->config, "dbg.backend", debugbackend); if (strcmp (debugbackend, "native")) { if (!haveRarunProfile) { pfile = strdup (argv[opt.ind++]); @@ -951,35 +951,35 @@ R_API int r_main_radare2(int argc, const char **argv) { opt.ind--; // take filename } #if __WINDOWS__ - pfile = r_acp_to_utf8 (pfile); + pfile = rz_acp_to_utf8 (pfile); #endif // __WINDOWS__ - fh = r_core_file_open (r, pfile, perms, mapaddr); - iod = (r->io && fh) ? r_io_desc_get (r->io, fh->fd) : NULL; + fh = rz_core_file_open (r, pfile, perms, mapaddr); + iod = (r->io && fh) ? rz_io_desc_get (r->io, fh->fd) : NULL; if (!strcmp (debugbackend, "gdb")) { - const char *filepath = r_config_get (r->config, "dbg.exe.path"); + const char *filepath = rz_config_get (r->config, "dbg.exe.path"); ut64 addr = baddr; if (addr == UINT64_MAX) { - addr = r_config_get_i (r->config, "bin.baddr"); + addr = rz_config_get_i (r->config, "bin.baddr"); } - if (r_file_exists (filepath) && !r_file_is_directory (filepath)) { - char *newpath = r_file_abspath (filepath); + if (rz_file_exists (filepath) && !rz_file_is_directory (filepath)) { + char *newpath = rz_file_abspath (filepath); if (newpath) { if (iod) { free (iod->name); iod->name = newpath; } if (addr == UINT64_MAX) { - addr = r_debug_get_baddr (r->dbg, newpath); + addr = rz_debug_get_baddr (r->dbg, newpath); } - r_core_bin_load (r, NULL, addr); + rz_core_bin_load (r, NULL, addr); } } else if (is_valid_gdb_file (fh)) { filepath = iod->name; - if (r_file_exists (filepath) && !r_file_is_directory (filepath)) { + if (rz_file_exists (filepath) && !rz_file_is_directory (filepath)) { if (addr == UINT64_MAX) { - addr = r_debug_get_baddr (r->dbg, filepath); + addr = rz_debug_get_baddr (r->dbg, filepath); } - r_core_bin_load (r, filepath, addr); + rz_core_bin_load (r, filepath, addr); } else if ((filepath = get_file_in_cur_dir (filepath))) { // Present in local directory if (iod) { @@ -987,9 +987,9 @@ R_API int r_main_radare2(int argc, const char **argv) { iod->name = (char*) filepath; } if (addr == UINT64_MAX) { - addr = r_debug_get_baddr (r->dbg, filepath); + addr = rz_debug_get_baddr (r->dbg, filepath); } - r_core_bin_load (r, NULL, addr); + rz_core_bin_load (r, NULL, addr); } } } @@ -1009,34 +1009,34 @@ R_API int r_main_radare2(int argc, const char **argv) { path = strdup (f); } else { // f is a filename - if (r_file_exists (f)) { - path = r_str_prepend (strdup (f), "./"); + if (rz_file_exists (f)) { + path = rz_str_prepend (strdup (f), "./"); } else { - path = r_file_path (f); + path = rz_file_path (f); } } - escaped_path = r_str_arg_escape (path); - pfile = r_str_append (pfile, escaped_path); + escaped_path = rz_str_arg_escape (path); + pfile = rz_str_append (pfile, escaped_path); file = pfile; // probably leaks R_FREE (escaped_path); R_FREE (path); } #else # if __WINDOWS__ - f = r_acp_to_utf8 (f); + f = rz_acp_to_utf8 (f); # endif // __WINDOWS__ if (f) { - char *escaped_path = r_str_arg_escape (f); - pfile = r_str_append (pfile, escaped_path); + char *escaped_path = rz_str_arg_escape (f); + pfile = rz_str_append (pfile, escaped_path); free (escaped_path); - file = pfile; // r_str_append (file, escaped_path); + file = pfile; // rz_str_append (file, escaped_path); } #endif opt.ind++; while (opt.ind < argc) { - char *escaped_arg = r_str_arg_escape (argv[opt.ind]); - file = r_str_append (file, " "); - file = r_str_append (file, escaped_arg); + char *escaped_arg = rz_str_arg_escape (argv[opt.ind]); + file = rz_str_append (file, " "); + file = rz_str_append (file, escaped_arg); free (escaped_arg); opt.ind++; } @@ -1044,17 +1044,17 @@ R_API int r_main_radare2(int argc, const char **argv) { } } if (asmarch) { - r_config_set (r->config, "asm.arch", asmarch); + rz_config_set (r->config, "asm.arch", asmarch); } if (asmbits) { - r_config_set (r->config, "asm.bits", asmbits); + rz_config_set (r->config, "asm.bits", asmbits); } if (asmos) { - r_config_set (r->config, "asm.os", asmos); + rz_config_set (r->config, "asm.os", asmos); } if (!debug || debug == 2) { - const char *dbg_profile = r_config_get (r->config, "dbg.profile"); + const char *dbg_profile = rz_config_get (r->config, "dbg.profile"); if (opt.ind == argc && dbg_profile && *dbg_profile) { if (R_STR_ISEMPTY (pfile)) { eprintf ("Missing file to open\n"); @@ -1062,9 +1062,9 @@ R_API int r_main_radare2(int argc, const char **argv) { R_FREE (debugbackend); goto beach; } - fh = r_core_file_open (r, pfile, perms, mapaddr); + fh = rz_core_file_open (r, pfile, perms, mapaddr); if (fh) { - r_core_bin_load (r, pfile, baddr); + rz_core_bin_load (r, pfile, baddr); } } if (opt.ind < argc) { @@ -1072,22 +1072,22 @@ R_API int r_main_radare2(int argc, const char **argv) { while (opt.ind < argc) { pfile = strdup (argv[opt.ind++]); #if __WINDOWS__ - pfile = r_acp_to_utf8 (pfile); + pfile = rz_acp_to_utf8 (pfile); #endif - fh = r_core_file_open (r, pfile, perms, mapaddr); + fh = rz_core_file_open (r, pfile, perms, mapaddr); if (!fh && perms & R_PERM_W) { perms |= R_PERM_CREAT; - fh = r_core_file_open (r, pfile, perms, mapaddr); + fh = rz_core_file_open (r, pfile, perms, mapaddr); } if (perms & R_PERM_CREAT) { if (fh) { - r_config_set_i (r->config, "io.va", false); + rz_config_set_i (r->config, "io.va", false); } else { - eprintf ("r_io_create: Permission denied.\n"); + eprintf ("rz_io_create: Permission denied.\n"); } } if (fh) { - iod = r->io ? r_io_desc_get (r->io, fh->fd) : NULL; + iod = r->io ? rz_io_desc_get (r->io, fh->fd) : NULL; if (iod && perms & R_PERM_X) { iod->perm |= R_PERM_X; } @@ -1103,28 +1103,28 @@ R_API int r_main_radare2(int argc, const char **argv) { } /* Load rbin info from r2 dbg:// or r2 /bin/ls */ /* the baddr should be set manually here */ - (void)r_core_bin_load (r, filepath, baddr); + (void)rz_core_bin_load (r, filepath, baddr); // check if bin info is loaded and complain if -B was used - RBinFile *bi = r_bin_cur (r->bin); + RBinFile *bi = rz_bin_cur (r->bin); bool haveBinInfo = bi && bi->o && bi->o->info && bi->o->info->type; if (!haveBinInfo && baddr != UT64_MAX) { eprintf ("Warning: Don't use -B on unknown files. Consider using -m.\n"); } } else { - r_io_map_new (r->io, iod->fd, perms, 0LL, mapaddr, r_io_desc_size (iod)); + rz_io_map_new (r->io, iod->fd, perms, 0LL, mapaddr, rz_io_desc_size (iod)); if (load_bin == LOAD_BIN_STRUCTURES_ONLY) { - r_core_bin_load_structs (r, iod->name); + rz_core_bin_load_structs (r, iod->name); } } } } } else { - const char *prj = r_config_get (r->config, "prj.name"); + const char *prj = rz_config_get (r->config, "prj.name"); if (prj && *prj) { - pfile = r_core_project_info (r, prj); + pfile = rz_core_project_info (r, prj); if (pfile) { if (!fh) { - fh = r_core_file_open (r, pfile, perms, mapaddr); + fh = rz_core_file_open (r, pfile, perms, mapaddr); } // load_bin = LOAD_BIN_NOTHING; load_bin = LOAD_BIN_STRUCTURES_ONLY; @@ -1133,33 +1133,33 @@ R_API int r_main_radare2(int argc, const char **argv) { } } else { if (fh) { - iod = r->io ? r_io_desc_get (r->io, fh->fd) : NULL; + iod = r->io ? rz_io_desc_get (r->io, fh->fd) : NULL; if (iod) { perms = iod->perm; - r_io_map_new (r->io, iod->fd, perms, 0LL, 0LL, r_io_desc_size (iod)); + rz_io_map_new (r->io, iod->fd, perms, 0LL, 0LL, rz_io_desc_size (iod)); } } } } if (mapaddr) { - if (r_config_get_i (r->config, "file.info")) { + if (rz_config_get_i (r->config, "file.info")) { eprintf ("Warning: using oba to load the syminfo from different mapaddress.\n"); // load symbols when using r2 -m 0x1000 /bin/ls - r_core_cmdf (r, "oba 0 0x%"PFMT64x, mapaddr); - r_core_cmd0 (r, ".ies*"); + rz_core_cmdf (r, "oba 0 0x%"PFMT64x, mapaddr); + rz_core_cmd0 (r, ".ies*"); } } } else { - RCoreFile *f = r_core_file_open (r, pfile, perms, mapaddr); + RzCoreFile *f = rz_core_file_open (r, pfile, perms, mapaddr); if (f) { fh = f; } if (fh) { - r_debug_use (r->dbg, is_gdb ? "gdb" : debugbackend); + rz_debug_use (r->dbg, is_gdb ? "gdb" : debugbackend); } /* load symbols when doing r2 -d ls */ // NOTE: the baddr is redefined to support PIE/ASLR - baddr = r_debug_get_baddr (r->dbg, pfile); + baddr = rz_debug_get_baddr (r->dbg, pfile); if (baddr != UT64_MAX && baddr != 0 && r->dbg->verbose) { eprintf ("bin.baddr 0x%08" PFMT64x "\n", baddr); @@ -1168,33 +1168,33 @@ R_API int r_main_radare2(int argc, const char **argv) { if (baddr && baddr != UT64_MAX && r->dbg->verbose) { eprintf ("Using 0x%" PFMT64x "\n", baddr); } - if (r_core_bin_load (r, pfile, baddr)) { - RBinObject *obj = r_bin_cur_object (r->bin); + if (rz_core_bin_load (r, pfile, baddr)) { + RBinObject *obj = rz_bin_cur_object (r->bin); if (obj && obj->info) { if (r->dbg->verbose) { eprintf ("asm.bits %d\n", obj->info->bits); } #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ && __x86_64__ - ut64 bitness = r_config_get_i (r->config, "asm.bits"); + ut64 bitness = rz_config_get_i (r->config, "asm.bits"); if (bitness == 32) { eprintf ("glibc.fc_offset = 0x00148\n"); - r_config_set_i (r->config, "dbg.glibc.fc_offset", 0x00148); + rz_config_set_i (r->config, "dbg.glibc.fc_offset", 0x00148); } #endif } } } - r_core_cmd0 (r, ".dm*"); + rz_core_cmd0 (r, ".dm*"); // Set Thumb Mode if necessary - r_core_cmd0 (r, "dr? thumb;?? e asm.bits=16"); - r_cons_reset (); + rz_core_cmd0 (r, "dr? thumb;?? e asm.bits=16"); + rz_cons_reset (); } if (!pfile) { pfile = file; } if (!fh) { if (pfile && *pfile) { - r_cons_flush (); + rz_cons_flush (); if (perms & R_PERM_W) { eprintf ("[w] Cannot open '%s' for writing.\n", pfile); } else { @@ -1212,47 +1212,47 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (r->bin->cur && r->bin->cur->o && r->bin->cur->o->info && r->bin->cur->o->info->rclass && !strcmp ("fs", r->bin->cur->o->info->rclass)) { const char *fstype = r->bin->cur->o->info->bclass; - r_core_cmdf (r, "m /root %s @ 0", fstype); + rz_core_cmdf (r, "m /root %s @ 0", fstype); } - r_core_cmd0 (r, "=!"); // initalize io subsystem - iod = r->io ? r_io_desc_get (r->io, fh->fd) : NULL; + rz_core_cmd0 (r, "=!"); // initalize io subsystem + iod = r->io ? rz_io_desc_get (r->io, fh->fd) : NULL; if (mapaddr) { - r_core_seek (r, mapaddr, true); + rz_core_seek (r, mapaddr, true); } - r_list_foreach (evals, iter, cmdn) { - r_config_eval (r->config, cmdn, false); - r_cons_flush (); + rz_list_foreach (evals, iter, cmdn) { + rz_config_eval (r->config, cmdn, false); + rz_cons_flush (); } if (asmarch) { - r_config_set (r->config, "asm.arch", asmarch); + rz_config_set (r->config, "asm.arch", asmarch); } if (asmbits) { - r_config_set (r->config, "asm.bits", asmbits); + rz_config_set (r->config, "asm.bits", asmbits); } if (asmos) { - r_config_set (r->config, "asm.os", asmos); + rz_config_set (r->config, "asm.os", asmos); } debug = r->file && iod && (r->file->fd == iod->fd) && iod->plugin && \ iod->plugin->isdbg; if (debug) { - r_core_setup_debugger (r, debugbackend, baddr == UT64_MAX); + rz_core_setup_debugger (r, debugbackend, baddr == UT64_MAX); } R_FREE (debugbackend); - RBinObject *o = r_bin_cur_object (r->bin); + RBinObject *o = rz_bin_cur_object (r->bin); if (!debug && o && !o->regstate) { - RFlagItem *fi = r_flag_get (r->flags, "entry0"); + RzFlagItem *fi = rz_flag_get (r->flags, "entry0"); if (fi) { - r_core_seek (r, fi->offset, true); + rz_core_seek (r, fi->offset, true); } else { if (o) { - RList *sections = r_bin_get_sections (r->bin); - RListIter *iter; + RzList *sections = rz_bin_get_sections (r->bin); + RzListIter *iter; RBinSection *s; - r_list_foreach (sections, iter, s) { + rz_list_foreach (sections, iter, s) { if (s->perm & R_PERM_X) { ut64 addr = s->vaddr? s->vaddr: s->paddr; - r_core_seek (r, addr, true); + rz_core_seek (r, addr, true); break; } } @@ -1261,75 +1261,75 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (o && compute_hashes) { // TODO: recall with limit=0 ? - ut64 limit = r_config_get_i (r->config, "bin.hashlimit"); - r_bin_file_set_hashes (r->bin, r_bin_file_compute_hashes (r->bin, limit)); + ut64 limit = rz_config_get_i (r->config, "bin.hashlimit"); + rz_bin_file_set_hashes (r->bin, rz_bin_file_compute_hashes (r->bin, limit)); } if (s_seek) { - seek = r_num_math (r->num, s_seek); + seek = rz_num_math (r->num, s_seek); if (seek != UT64_MAX) { - r_core_seek (r, seek, true); + rz_core_seek (r, seek, true); } } if (fullfile) { - r_core_block_size (r, r_io_desc_size (iod)); + rz_core_block_size (r, rz_io_desc_size (iod)); } - r_core_seek (r, r->offset, true); // read current block + rz_core_seek (r, r->offset, true); // read current block /* check if file.path has changed */ if (iod && !strstr (iod->uri, "://")) { const char *npath; - char *path = strdup (r_config_get (r->config, "file.path")); - has_project = r_core_project_open (r, r_config_get (r->config, "prj.name"), false); - iod = r->io ? r_io_desc_get (r->io, fh->fd) : NULL; + char *path = strdup (rz_config_get (r->config, "file.path")); + has_project = rz_core_project_open (r, rz_config_get (r->config, "prj.name"), false); + iod = r->io ? rz_io_desc_get (r->io, fh->fd) : NULL; if (has_project) { - r_config_set (r->config, "bin.strings", "false"); + rz_config_set (r->config, "bin.strings", "false"); } - npath = r_config_get (r->config, "file.path"); + npath = rz_config_get (r->config, "file.path"); if (!quiet && path && *path && npath && strcmp (path, npath)) { eprintf ("WARNING: file.path change: %s => %s\n", path, npath); } free (path); } - r_list_foreach (evals, iter, cmdn) { - r_config_eval (r->config, cmdn, false); - r_cons_flush (); + rz_list_foreach (evals, iter, cmdn) { + rz_config_eval (r->config, cmdn, false); + rz_cons_flush (); } // no flagspace selected by default the beginning - r_flag_space_set (r->flags, NULL); + rz_flag_space_set (r->flags, NULL); /* load .r2 */ { - char* f = r_str_newf ("%s.r2", pfile); + char* f = rz_str_newf ("%s.r2", pfile); const char *uri_splitter = strstr (f, "://"); const char *path = uri_splitter? uri_splitter + 3: f; - if (r_file_exists (path)) { + if (rz_file_exists (path)) { // TODO: should 'q' unset the interactive bit? - bool isInteractive = r_cons_is_interactive (); - if (isInteractive && r_cons_yesno ('n', "Do you want to run the '%s' script? (y/N) ", path)) { - r_core_cmd_file (r, path); + bool isInteractive = rz_cons_is_interactive (); + if (isInteractive && rz_cons_yesno ('n', "Do you want to run the '%s' script? (y/N) ", path)) { + rz_core_cmd_file (r, path); } } free (f); } } else { - r_core_block_read (r); + rz_core_block_read (r); } { - char *global_rc = r_str_r2_prefix (R2_GLOBAL_RC); - if (r_file_exists (global_rc)) { - (void)r_core_run_script (r, global_rc); + char *global_rc = rz_str_rz_prefix (R2_GLOBAL_RC); + if (rz_file_exists (global_rc)) { + (void)rz_core_run_script (r, global_rc); } free (global_rc); } // only analyze if file contains entrypoint { - char *s = r_core_cmd_str (r, "ieq"); + char *s = rz_core_cmd_str (r, "ieq"); if (s && *s) { - int da = r_config_get_i (r->config, "file.analyze"); + int da = rz_config_get_i (r->config, "file.analyze"); if (da > do_analysis) { do_analysis = da; } @@ -1338,30 +1338,30 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (do_analysis > 0) { switch (do_analysis) { - case 1: r_core_cmd0 (r, "aa"); break; - case 2: r_core_cmd0 (r, "aaa"); break; - case 3: r_core_cmd0 (r, "aaaa"); break; - default: r_core_cmd0 (r, "aaaaa"); break; + case 1: rz_core_cmd0 (r, "aa"); break; + case 2: rz_core_cmd0 (r, "aaa"); break; + case 3: rz_core_cmd0 (r, "aaaa"); break; + default: rz_core_cmd0 (r, "aaaaa"); break; } - r_cons_flush (); + rz_cons_flush (); } #if UNCOLORIZE_NONTTY #if __UNIX__ - if (!r_cons_isatty ()) { - r_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); + if (!rz_cons_isatty ()) { + rz_config_set_i (r->config, "scr.color", COLOR_MODE_DISABLED); } #endif #endif if (fullfile) { - r_core_block_size (r, r_io_desc_size (iod)); + rz_core_block_size (r, rz_io_desc_size (iod)); } if (perms & R_PERM_W) { - r_core_cmd0 (r, "omfg+w"); + rz_core_cmd0 (r, "omfg+w"); } ret = run_commands (r, cmds, files, quiet, do_analysis); - r_list_free (cmds); - r_list_free (evals); - r_list_free (files); + rz_list_free (cmds); + rz_list_free (evals); + rz_list_free (files); cmds = evals = files = NULL; if (forcequit) { ret = 1; @@ -1370,26 +1370,26 @@ R_API int r_main_radare2(int argc, const char **argv) { ret = 0; goto beach; } - if (r_config_get_i (r->config, "scr.prompt")) { - if (run_rc && r_config_get_i (r->config, "cfg.fortunes")) { - r_core_fortune_print_random (r); - r_cons_flush (); + if (rz_config_get_i (r->config, "scr.prompt")) { + if (run_rc && rz_config_get_i (r->config, "cfg.fortunes")) { + rz_core_fortune_print_random (r); + rz_cons_flush (); } } if (sandbox) { - r_config_set (r->config, "cfg.sandbox", "true"); + rz_config_set (r->config, "cfg.sandbox", "true"); } if (quiet) { - r_config_set (r->config, "scr.wheel", "false"); - r_config_set (r->config, "scr.interactive", "false"); - r_config_set (r->config, "scr.prompt", "false"); + rz_config_set (r->config, "scr.wheel", "false"); + rz_config_set (r->config, "scr.interactive", "false"); + rz_config_set (r->config, "scr.prompt", "false"); } r->num->value = 0; if (patchfile) { - char *data = r_file_slurp (patchfile, NULL); + char *data = rz_file_slurp (patchfile, NULL); if (data) { - ret = r_core_patch (r, data); - r_core_seek (r, 0, true); + ret = rz_core_patch (r, data); + rz_core_seek (r, 0, true); free (data); } else { eprintf ("[p] Cannot open '%s'\n", patchfile); @@ -1397,34 +1397,34 @@ R_API int r_main_radare2(int argc, const char **argv) { } if ((patchfile && !quiet) || !patchfile) { if (zerosep) { - r_cons_zero (); + rz_cons_zero (); } if (seek != UT64_MAX) { - r_core_seek (r, seek, true); + rz_core_seek (r, seek, true); } // no flagspace selected by default the beginning - r_flag_space_set (r->flags, NULL); + rz_flag_space_set (r->flags, NULL); if (!debug && r->bin && r->bin->cur && r->bin->cur->o && r->bin->cur->o->info) { if (r->bin->cur->o->info->arch) { - r_core_cmd0 (r, "aeip"); + rz_core_cmd0 (r, "aeip"); } } for (;;) { - r_core_prompt_loop (r); + rz_core_prompt_loop (r); ret = r->num->value; - debug = r_config_get_i (r->config, "cfg.debug"); - if (ret != -1 && r_cons_is_interactive ()) { + debug = rz_config_get_i (r->config, "cfg.debug"); + if (ret != -1 && rz_cons_is_interactive ()) { char *question; bool no_question_debug = ret & 1; bool no_question_save = (ret & 2) >> 1; bool y_kill_debug = (ret & 4) >> 2; bool y_save_project = (ret & 8) >> 3; - if (r_core_task_running_tasks_count (&r->tasks) > 0) { - if (r_cons_yesno ('y', "There are running background tasks. Do you want to kill them? (Y/n)")) { - r_core_task_break_all (&r->tasks); - r_core_task_join (&r->tasks, r->tasks.main_task, -1); + if (rz_core_task_running_tasks_count (&r->tasks) > 0) { + if (rz_cons_yesno ('y', "There are running background tasks. Do you want to kill them? (Y/n)")) { + rz_core_task_break_all (&r->tasks); + rz_core_task_join (&r->tasks, r->tasks.main_task, -1); } else { continue; } @@ -1432,16 +1432,16 @@ R_API int r_main_radare2(int argc, const char **argv) { if (debug) { if (no_question_debug) { - if (r_config_get_i (r->config, "dbg.exitkills") && y_kill_debug){ - r_debug_kill (r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL + if (rz_config_get_i (r->config, "dbg.exitkills") && y_kill_debug){ + rz_debug_kill (r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL } } else { - if (r_cons_yesno ('y', "Do you want to quit? (Y/n)")) { - if (r_config_get_i (r->config, "dbg.exitkills") && - r_cons_yesno ('y', "Do you want to kill the process? (Y/n)")) { - r_debug_kill (r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL + if (rz_cons_yesno ('y', "Do you want to quit? (Y/n)")) { + if (rz_config_get_i (r->config, "dbg.exitkills") && + rz_cons_yesno ('y', "Do you want to kill the process? (Y/n)")) { + rz_debug_kill (r->dbg, r->dbg->pid, r->dbg->tid, 9); // KILL } else { - r_debug_detach (r->dbg, r->dbg->pid); + rz_debug_detach (r->dbg, r->dbg->pid); } } else { continue; @@ -1449,28 +1449,28 @@ R_API int r_main_radare2(int argc, const char **argv) { } } - prj = r_config_get (r->config, "prj.name"); + prj = rz_config_get (r->config, "prj.name"); if (no_question_save) { if (prj && *prj && y_save_project){ - r_core_project_save (r, prj); + rz_core_project_save (r, prj); } } else { - question = r_str_newf ("Do you want to save the '%s' project? (Y/n)", prj); - if (prj && *prj && r_cons_yesno ('y', "%s", question)) { - r_core_project_save (r, prj); + question = rz_str_newf ("Do you want to save the '%s' project? (Y/n)", prj); + if (prj && *prj && rz_cons_yesno ('y', "%s", question)) { + rz_core_project_save (r, prj); } free (question); } - if (r_config_get_i (r->config, "scr.confirmquit")) { - if (!r_cons_yesno ('n', "Do you want to quit? (Y/n)")) { + if (rz_config_get_i (r->config, "scr.confirmquit")) { + if (!rz_cons_yesno ('n', "Do you want to quit? (Y/n)")) { continue; } } } else { - // r_core_project_save (r, prj); - if (debug && r_config_get_i (r->config, "dbg.exitkills")) { - r_debug_kill (r->dbg, 0, false, 9); // KILL + // rz_core_project_save (r, prj); + if (debug && rz_config_get_i (r->config, "dbg.exitkills")) { + rz_debug_kill (r->dbg, 0, false, 9); // KILL } } @@ -1479,7 +1479,7 @@ R_API int r_main_radare2(int argc, const char **argv) { } if (mustSaveHistory (r->config)) { - r_line_hist_save (R2_HOME_HISTORY); + rz_line_hist_save (R2_HOME_HISTORY); } /* capture return value */ @@ -1490,15 +1490,15 @@ beach: return ret; } - r_core_task_sync_end (&r->tasks); + rz_core_task_sync_end (&r->tasks); - // not really needed, cause r_core_fini will close the file + // not really needed, cause rz_core_fini will close the file // and this fh may be come stale during the command // execution. - //r_core_file_close (r, fh); - r_core_free (r); - r_cons_set_raw (0); - r_cons_free (); + //rz_core_file_close (r, fh); + rz_core_free (r); + rz_cons_set_raw (0); + rz_cons_free (); LISTS_FREE (); R_FREE (pfile); return ret; diff --git a/libr/main/r2agent.c b/librz/main/rz_agent.c similarity index 71% rename from libr/main/r2agent.c rename to librz/main/rz_agent.c index e84bb28920..7dc76792fd 100644 --- a/libr/main/r2agent.c +++ b/librz/main/rz_agent.c @@ -1,8 +1,8 @@ -/* radare2 - LGPL - Copyright 2013-2020 - pancake */ +/* rizin - LGPL - Copyright 2013-2020 - pancake */ #include "index.h" -#include -#include +#include +#include #if __APPLE__ && (__arm__ || __arm64__ || __aarch64__) #define USE_IOS_JETSAM 1 @@ -15,7 +15,7 @@ extern int memorystatus_control(uint32_t command, pid_t pid, uint32_t flags, voi #endif static int usage (int v) { - printf ("Usage: r2agent [-adhs] [-p port]\n" + printf ("Usage: rz-agent [-adhs] [-p port]\n" " -a listen for everyone (localhost by default)\n" " -d run in daemon mode (background)\n" " -h show this help message\n" @@ -27,13 +27,13 @@ static int usage (int v) { } static int showversion(void) { - return r_main_version_print ("r2agent"); + return rz_main_version_print ("rz_agent"); } -R_API int r_main_r2agent(int argc, const char **argv) { - RSocket *s; - RSocketHTTPOptions so; - RSocketHTTPRequest *rs; +RZ_API int rz_main_rz_agent(int argc, const char **argv) { + RzSocket *s; + RzSocketHTTPOptions so; + RzSocketHTTPRequest *rs; int c; int dodaemon = 0; int dosandbox = 0; @@ -43,9 +43,9 @@ R_API int r_main_r2agent(int argc, const char **argv) { char *pfile = NULL; memset (&so, 0, sizeof (so)); - RGetopt opt; - r_getopt_init (&opt, argc, argv, "adhup:t:sv"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "adhup:t:sv"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'a': listenlocal = false; @@ -87,9 +87,9 @@ R_API int r_main_r2agent(int argc, const char **argv) { } size_t sz; - pfile = r_file_slurp (httpauthfile, &sz); + pfile = rz_file_slurp (httpauthfile, &sz); if (pfile) { - so.authtokens = r_str_split_list (pfile, "\n", 0); + so.authtokens = rz_str_split_list (pfile, "\n", 0); } else { eprintf ("Empty list of HTTP users\\n"); return usage (0); @@ -100,42 +100,42 @@ R_API int r_main_r2agent(int argc, const char **argv) { #endif if (dodaemon) { #if LIBC_HAVE_FORK - int pid = r_sys_fork (); + int pid = rz_sys_fork (); if (pid > 0) { printf ("%d\n", pid); return 0; } #endif } - s = r_socket_new (false); + s = rz_socket_new (false); s->local = listenlocal; - if (!r_socket_listen (s, port, NULL)) { + if (!rz_socket_listen (s, port, NULL)) { eprintf ("Cannot listen on %d\n", s->port); - r_socket_free (s); + rz_socket_free (s); return 1; } eprintf ("http://localhost:%d/\n", s->port); - if (dosandbox && !r_sandbox_enable (true)) { + if (dosandbox && !rz_sandbox_enable (true)) { eprintf ("sandbox: Cannot be enabled.\n"); free (pfile); - r_list_free (so.authtokens); - r_socket_free (s); + rz_list_free (so.authtokens); + rz_socket_free (s); return 1; } - (void)r_cons_new (); + (void)rz_cons_new (); - while (!r_cons_singleton ()->context->breaked) { + while (!rz_cons_singleton ()->context->breaked) { char *result_heap = NULL; const char *result = page_index; - rs = r_socket_http_accept (s, &so); + rs = rz_socket_http_accept (s, &so); if (!rs) { continue; } if (!rs->auth) { - r_socket_http_response (rs, 401, "", 0, NULL); + rz_socket_http_response (rs, 401, "", 0, NULL); } if (!strcmp (rs->method, "GET")) { if (!strncmp (rs->path, "/proc/kill/", 11)) { @@ -143,16 +143,16 @@ R_API int r_main_r2agent(int argc, const char **argv) { int pid = atoi (rs->path + 11); if (pid > 0) { #if __WINDOWS__ - r_sandbox_kill (pid, 0); + rz_sandbox_kill (pid, 0); #else - r_sandbox_kill (pid, SIGKILL); + rz_sandbox_kill (pid, SIGKILL); #endif } } else if (!strncmp (rs->path, "/file/open/", 11)) { int pid; - int session_port = 3000 + r_num_rand (1024); + int session_port = 3000 + rz_num_rand (1024); char *filename = rs->path + 11; - char *escaped_filename = r_str_escape (filename); + char *escaped_filename = rz_str_escape (filename); size_t escaped_len = strlen (escaped_filename); size_t cmd_len = escaped_len + 40; char *cmd; @@ -165,15 +165,15 @@ R_API int r_main_r2agent(int argc, const char **argv) { listenlocal? "": "-e http.bind=public ", session_port, escaped_filename); - // TODO: use r_sys api to get pid when running in bg - pid = r_sys_cmdbg (cmd); + // TODO: use rz_sys api to get pid when running in bg + pid = rz_sys_cmdbg (cmd); free (cmd); free (escaped_filename); result = result_heap = malloc (1024 + escaped_len); if (!result) { perror ("malloc"); free (pfile); - r_list_free (so.authtokens); + rz_list_free (so.authtokens); return 1; } sprintf (result_heap, @@ -185,14 +185,14 @@ R_API int r_main_r2agent(int argc, const char **argv) { eprintf ("\nchild pid %d\n\n", pid); } } - r_socket_http_response (rs, 200, result, 0, NULL); - r_socket_http_close (rs); + rz_socket_http_response (rs, 200, result, 0, NULL); + rz_socket_http_close (rs); free (result_heap); result_heap = NULL; } - r_cons_free (); + rz_cons_free (); free (pfile); - r_list_free (so.authtokens); - r_socket_free (s); + rz_list_free (so.authtokens); + rz_socket_free (s); return 0; } diff --git a/libr/main/rasm2.c b/librz/main/rz_asm.c similarity index 70% rename from libr/main/rasm2.c rename to librz/main/rz_asm.c index 2b52664f29..eb93e95390 100644 --- a/libr/main/rasm2.c +++ b/librz/main/rz_asm.c @@ -1,56 +1,56 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nibble, maijin */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include +#include typedef struct { - RLib *l; - RAsm *a; - RAnal *anal; + RzLib *l; + RzAsm *a; + RzAnal *anal; bool oneliner; bool coutput; bool json; bool quiet; -} RAsmState; +} RzAsmState; -static void __load_plugins(RAsmState *as); +static void __load_plugins(RzAsmState *as); -static void __as_set_archbits(RAsmState *as) { - r_asm_use (as->a, R_SYS_ARCH); - r_anal_use (as->anal, R_SYS_ARCH); +static void __as_set_archbits(RzAsmState *as) { + rz_asm_use (as->a, R_SYS_ARCH); + rz_anal_use (as->anal, R_SYS_ARCH); int sysbits = (R_SYS_BITS & R_SYS_BITS_64)? 64: 32; - r_asm_set_bits (as->a, sysbits); - r_anal_set_bits (as->anal, sysbits); + rz_asm_set_bits (as->a, sysbits); + rz_anal_set_bits (as->anal, sysbits); } -static RAsmState *__as_new(void) { - RAsmState *as = R_NEW0 (RAsmState); +static RzAsmState *__as_new(void) { + RzAsmState *as = R_NEW0 (RzAsmState); if (as) { - as->l = r_lib_new (NULL, NULL); - as->a = r_asm_new (); + as->l = rz_lib_new (NULL, NULL); + as->a = rz_asm_new (); if (as->a) { - as->a->num = r_num_new (NULL, NULL, NULL); + as->a->num = rz_num_new (NULL, NULL, NULL); } - as->anal = r_anal_new (); + as->anal = rz_anal_new (); __load_plugins (as); __as_set_archbits (as); } return as; } -static void __as_free(RAsmState *as) { +static void __as_free(RzAsmState *as) { if (as->a) { - r_num_free (as->a->num); + rz_num_free (as->a->num); } - r_asm_free (as->a); - r_anal_free (as->anal); - r_lib_free (as->l); + rz_asm_free (as->a); + rz_anal_free (as->anal); + rz_lib_free (as->l); free (as); } @@ -65,14 +65,14 @@ static char *stackop2str(int type) { return strdup ("unknown"); } -static int showanal(RAsmState *as, RAnalOp *op, ut64 offset, ut8 *buf, int len, PJ *pj) { - int ret = r_anal_op (as->anal, op, offset, buf, len, R_ANAL_OP_MASK_ESIL); +static int showanal(RzAsmState *as, RzAnalOp *op, ut64 offset, ut8 *buf, int len, PJ *pj) { + int ret = rz_anal_op (as->anal, op, offset, buf, len, R_ANAL_OP_MASK_ESIL); if (ret < 1) { return ret; } char *stackop = stackop2str (op->stackop); - const char *optype = r_anal_optype_to_string (op->type); - char *bytes = r_hex_bin2strdup (buf, ret); + const char *optype = rz_anal_optype_to_string (op->type); + char *bytes = rz_hex_bin2strdup (buf, ret); if (as->json) { pj_o (pj); pj_kn (pj, "opcode", offset); @@ -91,7 +91,7 @@ static int showanal(RAsmState *as, RAnalOp *op, ut64 offset, ut8 *buf, int len, pj_kn (pj, "ptr", op->ptr); } pj_ks (pj, "stackop", stackop); - pj_ks (pj, "esil", r_strbuf_get (&op->esil)); + pj_ks (pj, "esil", rz_strbuf_get (&op->esil)); pj_kn (pj, "stackptr", op->stackptr); pj_end (pj); } else { @@ -110,9 +110,9 @@ static int showanal(RAsmState *as, RAnalOp *op, ut64 offset, ut8 *buf, int len, printf ("value: 0x%08" PFMT64x "\n", op->val); } printf ("stackop: %s\n", stackop); - printf ("esil: %s\n", r_strbuf_get (&op->esil)); + printf ("esil: %s\n", rz_strbuf_get (&op->esil)); printf ("stackptr: %" PFMT64d "\n", op->stackptr); - // produces (null) printf ("decode str: %s\n", r_anal_op_to_string (anal, op)); + // produces (null) printf ("decode str: %s\n", rz_anal_op_to_string (anal, op)); printf ("\n"); } free (stackop); @@ -121,30 +121,30 @@ static int showanal(RAsmState *as, RAnalOp *op, ut64 offset, ut8 *buf, int len, } // TODO: add israw/len -static int show_analinfo(RAsmState *as, const char *arg, ut64 offset) { +static int show_analinfo(RzAsmState *as, const char *arg, ut64 offset) { ut8 *buf = (ut8 *)strdup ((const char *)arg); - int ret, len = r_hex_str2bin ((char *)buf, buf); + int ret, len = rz_hex_str2bin ((char *)buf, buf); PJ *pj = pj_new (); if (!pj) { free (buf); return 0; } - RAnalOp aop = { 0 }; + RzAnalOp aop = { 0 }; if (as->json) { pj_a (pj); } for (ret = 0; ret < len;) { aop.size = 0; - if (r_anal_op (as->anal, &aop, offset, buf + ret, len - ret, R_ANAL_OP_MASK_BASIC) < 1) { + if (rz_anal_op (as->anal, &aop, offset, buf + ret, len - ret, R_ANAL_OP_MASK_BASIC) < 1) { eprintf ("Error analyzing instruction at 0x%08"PFMT64x"\n", offset); break; } if (aop.size < 1) { if (as->json) { pj_o (pj); - pj_ks (pj, "bytes", r_hex_bin2strdup (buf, ret)); + pj_ks (pj, "bytes", rz_hex_bin2strdup (buf, ret)); pj_ks (pj, "type", "Invalid"); pj_end (pj); } else { @@ -154,7 +154,7 @@ static int show_analinfo(RAsmState *as, const char *arg, ut64 offset) { } showanal (as, &aop, offset, buf + ret, len - ret, pj); ret += aop.size; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } if (as->json) { pj_end (pj); @@ -165,10 +165,10 @@ static int show_analinfo(RAsmState *as, const char *arg, ut64 offset) { return ret; } -static const char *has_esil(RAsmState *as, const char *name) { - RListIter *iter; - RAnalPlugin *h; - r_list_foreach (as->anal->plugins, iter, h) { +static const char *has_esil(RzAsmState *as, const char *name) { + RzListIter *iter; + RzAnalPlugin *h; + rz_list_foreach (as->anal->plugins, iter, h) { if (h->name && !strcmp (name, h->name)) { return h->esil? "Ae": "A_"; } @@ -176,12 +176,12 @@ static const char *has_esil(RAsmState *as, const char *name) { return "__"; } -static void rasm2_list(RAsmState *as, const char *arch) { +static void rz_asm_list(RzAsmState *as, const char *arch) { int i; char bits[32]; const char *feat2, *feat; - RAsmPlugin *h; - RListIter *iter; + RzAsmPlugin *h; + RzListIter *iter; PJ *pj = pj_new (); if (!pj) { return; @@ -189,13 +189,13 @@ static void rasm2_list(RAsmState *as, const char *arch) { if (as->json) { pj_o (pj); } - r_list_foreach (as->a->plugins, iter, h) { + rz_list_foreach (as->a->plugins, iter, h) { if (arch) { if (h->cpus && !strcmp (arch, h->name)) { char *c = strdup (h->cpus); - int n = r_str_split (c, ','); + int n = rz_str_split (c, ','); for (i = 0; i < n; i++) { - printf ("%s\n", r_str_word_get0 (c, i)); + printf ("%s\n", rz_str_word_get0 (c, i)); } free (c); break; @@ -271,7 +271,7 @@ static void rasm2_list(RAsmState *as, const char *arch) { static int rasm_show_help(int v) { if (v < 2) { - printf ("Usage: rasm2 [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n" + printf ("Usage: rz-asm [-ACdDehLBvw] [-a arch] [-b bits] [-o addr] [-s syntax]\n" " [-f file] [-F fil:ter] [-i skip] [-l len] 'code'|hex|-\n"); } if (v != 1) { @@ -293,7 +293,7 @@ static int rasm_show_help(int v) { " -l [len] Input/Output length\n" " -L List Asm plugins: (a=asm, d=disasm, A=analyze, e=ESIL)\n" " -o,-@ [addr] Set start address for code (default 0)\n" - " -O [file] Output file name (rasm2 -Bf a.asm -O a)\n" + " -O [file] Output file name (rz_asm -Bf a.asm -O a)\n" " -p Run SPP over input for assembly\n" " -q quiet mode\n" " -r output in radare commands\n" @@ -305,20 +305,20 @@ static int rasm_show_help(int v) { " If the last argument is '-' reads from stdin\n"); printf ("Environment:\n" " RASM2_NOPLUGINS do not load shared plugins (speedup loading)\n" - " RASM2_ARCH same as rasm2 -a\n" - " RASM2_BITS same as rasm2 -b\n" + " RASM2_ARCH same as rz_asm -a\n" + " RASM2_BITS same as rz_asm -b\n" " R_DEBUG if defined, show error messages and crash signal\n" ""); } if (v == 2) { printf ("Supported Assembler directives:\n"); - r_asm_list_directives (); + rz_asm_list_directives (); } return 0; } -static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int bits, int bin, int hex) { - RAsmCode *acode; +static int rasm_disasm(RzAsmState *as, ut64 addr, const char *buf, int len, int bits, int bin, int hex) { + RzAsmCode *acode; ut8 *data = NULL; int ret = 0; ut64 clen = 0; @@ -332,12 +332,12 @@ static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int b clen = len; // XXX data = (ut8 *)buf; } else { - clen = r_hex_str2bin (buf, NULL); + clen = rz_hex_str2bin (buf, NULL); if ((int)clen < 1 || !(data = malloc (clen))) { ret = 0; goto beach; } - r_hex_str2bin (buf, data); + rz_hex_str2bin (buf, data); len = clen; } @@ -346,10 +346,10 @@ static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int b } if (hex == 2) { - RAnalOp aop = { 0 }; + RzAnalOp aop = { 0 }; while (ret < len) { aop.size = 0; - if (r_anal_op (as->anal, &aop, addr, data + ret, len - ret, R_ANAL_OP_MASK_ESIL) > 0) { + if (rz_anal_op (as->anal, &aop, addr, data + ret, len - ret, R_ANAL_OP_MASK_ESIL) > 0) { printf ("%s\n", R_STRBUF_SAFEGET (&aop.esil)); } if (aop.size < 1) { @@ -357,38 +357,38 @@ static int rasm_disasm(RAsmState *as, ut64 addr, const char *buf, int len, int b break; } ret += aop.size; - r_anal_op_fini (&aop); + rz_anal_op_fini (&aop); } } else if (hex) { - RAsmOp op; - r_asm_set_pc (as->a, addr); + RzAsmOp op; + rz_asm_set_pc (as->a, addr); while ((len - ret) > 0) { - int dr = r_asm_disassemble (as->a, &op, data + ret, len - ret); + int dr = rz_asm_disassemble (as->a, &op, data + ret, len - ret); if (dr == -1 || op.size < 1) { op.size = 1; - r_asm_op_set_asm (&op, "invalid"); + rz_asm_op_set_asm (&op, "invalid"); } - char *op_hex = r_asm_op_get_hex (&op); + char *op_hex = rz_asm_op_get_hex (&op); printf ("0x%08" PFMT64x " %2d %24s %s\n", as->a->pc, op.size, op_hex, - r_asm_op_get_asm (&op)); + rz_asm_op_get_asm (&op)); free (op_hex); ret += op.size; - r_asm_set_pc (as->a, addr+ ret); + rz_asm_set_pc (as->a, addr+ ret); } } else { - r_asm_set_pc (as->a, addr); - if (!(acode = r_asm_mdisassemble (as->a, data, len))) { + rz_asm_set_pc (as->a, addr); + if (!(acode = rz_asm_mdisassemble (as->a, data, len))) { goto beach; } if (as->oneliner) { - r_str_replace_char (acode->assembly, '\n', ';'); + rz_str_replace_char (acode->assembly, '\n', ';'); printf ("%s\"\n", acode->assembly); } else { printf ("%s", acode->assembly); } ret = acode->len; - r_asm_code_free (acode); + rz_asm_code_free (acode); } beach: if (data && data != (ut8 *)buf) { @@ -397,7 +397,7 @@ beach: return ret; } -static void print_buf(RAsmState *as, char *str) { +static void print_buf(RzAsmState *as, char *str) { int i; if (as->coutput) { printf ("\""); @@ -419,11 +419,11 @@ static bool print_label(void *user, const void *k, const void *v) { return true; } -static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool hexwords) { - RAsmCode *acode; +static int rasm_asm(RzAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool hexwords) { + RzAsmCode *acode; int i, j, ret = 0; - r_asm_set_pc (as->a, offset); - if (!(acode = r_asm_rasm_assemble (as->a, buf, use_spp))) { + rz_asm_set_pc (as->a, offset); + if (!(acode = rz_asm_rasm_assemble (as->a, buf, use_spp))) { return 0; } if (acode->len) { @@ -431,7 +431,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b if (bin) { if ((ret = write (1, acode->bytes, acode->len)) != acode->len) { eprintf ("Failed to write buffer\n"); - r_asm_code_free (acode); + rz_asm_code_free (acode); return 0; } } else { @@ -448,7 +448,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b if (hexwords) { size_t i = 0; for (i = 0; i < acode->len; i += sizeof (ut32)) { - ut32 dword = r_read_ble32 (acode->bytes + i, R_SYS_ENDIAN); + ut32 dword = rz_read_ble32 (acode->bytes + i, R_SYS_ENDIAN); printf ("0x%08x ", dword); if ((i/4) == 7) { printf ("\n"); @@ -456,7 +456,7 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b } printf ("\n"); } else { - char* str = r_asm_code_get_hex (acode); + char* str = rz_asm_code_get_hex (acode); if (str) { print_buf (as, str); free (str); @@ -465,27 +465,27 @@ static int rasm_asm(RAsmState *as, const char *buf, ut64 offset, ut64 len, int b } } } - r_asm_code_free (acode); + rz_asm_code_free (acode); return (ret > 0); } /* asm callback */ -static int __lib_asm_cb(RLibPlugin *pl, void *user, void *data) { - RAsmPlugin *hand = (RAsmPlugin *)data; - RAsmState *as = (RAsmState *)user; - r_asm_add (as->a, hand); +static int __lib_asm_cb(RzLibPlugin *pl, void *user, void *data) { + RzAsmPlugin *hand = (RzAsmPlugin *)data; + RzAsmState *as = (RzAsmState *)user; + rz_asm_add (as->a, hand); return true; } /* anal callback */ -static int __lib_anal_cb(RLibPlugin *pl, void *user, void *data) { - RAnalPlugin *hand = (RAnalPlugin *)data; - RAsmState *as = (RAsmState *)user; - r_anal_add (as->anal, hand); +static int __lib_anal_cb(RzLibPlugin *pl, void *user, void *data) { + RzAnalPlugin *hand = (RzAnalPlugin *)data; + RzAsmState *as = (RzAsmState *)user; + rz_anal_add (as->anal, hand); return true; } -static int print_assembly_output(RAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, +static int print_assembly_output(RzAsmState *as, const char *buf, ut64 offset, ut64 len, int bits, int bin, bool use_spp, bool rad, bool hexwords, const char *arch) { if (rad) { printf ("e asm.arch=%s\n", arch? arch: R_SYS_ARCH); @@ -504,32 +504,32 @@ static int print_assembly_output(RAsmState *as, const char *buf, ut64 offset, ut return ret; } -static void __load_plugins(RAsmState *as) { - char *tmp = r_sys_getenv ("RASM2_NOPLUGINS"); +static void __load_plugins(RzAsmState *as) { + char *tmp = rz_sys_getenv ("RASM2_NOPLUGINS"); if (tmp) { free (tmp); return; } - r_lib_add_handler (as->l, R_LIB_TYPE_ASM, "(dis)assembly plugins", &__lib_asm_cb, NULL, as); - r_lib_add_handler (as->l, R_LIB_TYPE_ANAL, "analysis/emulation plugins", &__lib_anal_cb, NULL, as); + rz_lib_add_handler (as->l, R_LIB_TYPE_ASM, "(dis)assembly plugins", &__lib_asm_cb, NULL, as); + rz_lib_add_handler (as->l, R_LIB_TYPE_ANAL, "analysis/emulation plugins", &__lib_anal_cb, NULL, as); - char *path = r_sys_getenv (R_LIB_ENV); + char *path = rz_sys_getenv (R_LIB_ENV); if (path && *path) { - r_lib_opendir (as->l, path); + rz_lib_opendir (as->l, path); } // load plugins from the home directory - char *homeplugindir = r_str_home (R2_HOME_PLUGINS); - r_lib_opendir (as->l, homeplugindir); + char *homeplugindir = rz_str_home (R2_HOME_PLUGINS); + rz_lib_opendir (as->l, homeplugindir); free (homeplugindir); // load plugins from the system directory - char *plugindir = r_str_r2_prefix (R2_PLUGINS); - char *extrasdir = r_str_r2_prefix (R2_EXTRAS); - char *bindingsdir = r_str_r2_prefix (R2_BINDINGS); - r_lib_opendir (as->l, plugindir); - r_lib_opendir (as->l, extrasdir); - r_lib_opendir (as->l, bindingsdir); + char *plugindir = rz_str_rz_prefix (R2_PLUGINS); + char *extrasdir = rz_str_rz_prefix (R2_EXTRAS); + char *bindingsdir = rz_str_rz_prefix (R2_BINDINGS); + rz_lib_opendir (as->l, plugindir); + rz_lib_opendir (as->l, extrasdir); + rz_lib_opendir (as->l, bindingsdir); free (plugindir); free (extrasdir); free (bindingsdir); @@ -538,9 +538,9 @@ static void __load_plugins(RAsmState *as) { free (path); } -R_API int r_main_rasm2(int argc, const char *argv[]) { - const char *env_arch = r_sys_getenv ("RASM2_ARCH"); - const char *env_bits = r_sys_getenv ("RASM2_BITS"); +RZ_API int rz_main_rz_asm(int argc, const char *argv[]) { + const char *env_arch = rz_sys_getenv ("RASM2_ARCH"); + const char *env_bits = rz_sys_getenv ("RASM2_BITS"); const char *arch = NULL; const char *cpu = NULL; const char *kernel = NULL; @@ -560,23 +560,23 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { return rasm_show_help (1); } - RAsmState *as = __as_new (); + RzAsmState *as = __as_new (); // TODO set addrbytes - char *r2arch = r_sys_getenv ("R2_ARCH"); + char *r2arch = rz_sys_getenv ("R2_ARCH"); if (r2arch) { arch = r2arch; } - char *r2bits = r_sys_getenv ("R2_BITS"); + char *r2bits = rz_sys_getenv ("R2_BITS"); if (r2bits) { - bits = r_num_math (NULL, r2bits); + bits = rz_num_math (NULL, r2bits); free (r2bits); } - RGetopt opt; - r_getopt_init (&opt, argc, argv, "a:Ab:Bc:CdDeEf:F:hi:jk:l:L@:o:O:pqrs:vwx"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "a:Ab:Bc:CdDeEf:F:hi:jk:l:L@:o:O:pqrs:vwx"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'a': arch = opt.arg; @@ -585,7 +585,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { analinfo = true; break; case 'b': - bits = r_num_math (NULL, opt.arg); + bits = rz_num_math (NULL, opt.arg); break; case 'B': bin = 1; @@ -617,7 +617,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { case 'h': help++; case 'i': - skip = r_num_math (NULL, opt.arg); + skip = rz_num_math (NULL, opt.arg); break; case 'j': as->json = true; @@ -626,15 +626,15 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { kernel = opt.arg; break; case 'l': - len = r_num_math (NULL, opt.arg); + len = rz_num_math (NULL, opt.arg); break; case 'L': - rasm2_list (as, opt.argv[opt.ind]); + rz_asm_list (as, opt.argv[opt.ind]); ret = 1; goto beach; case '@': case 'o': - offset = r_num_math (NULL, opt.arg); + offset = rz_num_math (NULL, opt.arg); break; case 'O': fd = open (opt.arg, O_TRUNC | O_RDWR | O_CREAT, 0644); @@ -657,19 +657,19 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { __as_free (as); return 0; } else { - int syntax = r_asm_syntax_from_string (opt.arg); + int syntax = rz_asm_syntax_from_string (opt.arg); if (syntax == -1) { __as_free (as); return 1; } - r_asm_set_syntax (as->a, syntax); + rz_asm_set_syntax (as->a, syntax); } break; case 'v': if (as->quiet) { printf ("%s\n", R2_VERSION); } else { - ret = r_main_version_print ("rasm2"); + ret = rz_main_version_print ("rz_asm"); } goto beach; case 'w': @@ -690,37 +690,37 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { } if (arch) { - if (!r_asm_use (as->a, arch)) { - eprintf ("rasm2: Unknown asm plugin '%s'\n", arch); + if (!rz_asm_use (as->a, arch)) { + eprintf ("rz_asm: Unknown asm plugin '%s'\n", arch); ret = 0; goto beach; } - r_anal_use (as->anal, arch); + rz_anal_use (as->anal, arch); } else if (env_arch) { - if (!r_asm_use (as->a, env_arch)) { - eprintf ("rasm2: Unknown asm plugin '%s'\n", env_arch); + if (!rz_asm_use (as->a, env_arch)) { + eprintf ("rz_asm: Unknown asm plugin '%s'\n", env_arch); ret = 0; goto beach; } - } else if (!r_asm_use (as->a, "x86")) { - eprintf ("rasm2: Cannot find asm.x86 plugin\n"); + } else if (!rz_asm_use (as->a, "x86")) { + eprintf ("rz_asm: Cannot find asm.x86 plugin\n"); ret = 0; goto beach; } - r_asm_set_cpu (as->a, cpu); - r_asm_set_bits (as->a, (env_bits && *env_bits)? atoi (env_bits): bits); - r_anal_set_bits (as->anal, (env_bits && *env_bits)? atoi (env_bits): bits); - as->a->syscall = r_syscall_new (); - r_syscall_setup (as->a->syscall, arch, bits, cpu, kernel); + rz_asm_set_cpu (as->a, cpu); + rz_asm_set_bits (as->a, (env_bits && *env_bits)? atoi (env_bits): bits); + rz_anal_set_bits (as->anal, (env_bits && *env_bits)? atoi (env_bits): bits); + as->a->syscall = rz_syscall_new (); + rz_syscall_setup (as->a->syscall, arch, bits, cpu, kernel); { - bool canbebig = r_asm_set_big_endian (as->a, isbig); + bool canbebig = rz_asm_set_big_endian (as->a, isbig); if (isbig && !canbebig) { eprintf ("Warning: This architecture can't swap to big endian.\n"); } - r_anal_set_big_endian (as->anal, canbebig); + rz_anal_set_big_endian (as->anal, canbebig); } if (whatsop) { - const char *s = r_asm_describe (as->a, opt.argv[opt.ind]); + const char *s = rz_asm_describe (as->a, opt.argv[opt.ind]); ret = 1; if (s) { printf ("%s\n", s); @@ -733,17 +733,17 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { if (p) { *p = 0; if (*filters) { - r_asm_filter_input (as->a, filters); + rz_asm_filter_input (as->a, filters); } if (p[1]) { - r_asm_filter_output (as->a, p + 1); + rz_asm_filter_output (as->a, p + 1); } *p = ':'; } else { if (dis) { - r_asm_filter_output (as->a, filters); + rz_asm_filter_output (as->a, filters); } else { - r_asm_filter_input (as->a, filters); + rz_asm_filter_input (as->a, filters); } } } @@ -753,7 +753,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { size_t length = 0; if (!strcmp (file, "-")) { int sz = 0; - ut8 *buf = (ut8 *)r_stdin_slurp (&sz); + ut8 *buf = (ut8 *)rz_stdin_slurp (&sz); if (!buf || sz < 1) { eprintf ("Nothing to do.\n"); goto beach; @@ -776,10 +776,10 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { ret = !ret; free (buf); } else { - content = r_file_slurp (file, &length); + content = rz_file_slurp (file, &length); if (content) { if (length > ST32_MAX) { - eprintf ("rasm2: File %s is too big\n", file); + eprintf ("rz_asm: File %s is too big\n", file); ret = 1; } else { if (len && len > 0 && len < length) { @@ -805,7 +805,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { } free (content); } else { - eprintf ("rasm2: Cannot open file %s\n", file); + eprintf ("rz_asm: Cannot open file %s\n", file); ret = 1; } } @@ -813,7 +813,7 @@ R_API int r_main_rasm2(int argc, const char *argv[]) { if (!strcmp (opt.argv[opt.ind], "-")) { int length; do { - char buf[1024]; // TODO: use(implement) r_stdin_line() or so + char buf[1024]; // TODO: use(implement) rz_stdin_line() or so length = read (0, buf, sizeof (buf) - 1); if (length < 1) { break; diff --git a/libr/main/rax2.c b/librz/main/rz_ax.c similarity index 70% rename from libr/main/rax2.c rename to librz/main/rz_ax.c index b0ad86a28b..90b001b5ec 100644 --- a/libr/main/rax2.c +++ b/librz/main/rz_ax.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include -#include -#include +#include +#include +#include // don't use fixed sized buffers #define STDIN_BUFFER_SIZE 354096 @@ -48,14 +48,14 @@ static int use_stdin(RNum *num, ut64 *flags, int *fm) { } static int format_output(RNum *num, char mode, const char *s, int force_mode, ut64 flags) { - ut64 n = r_num_math (num, s); + ut64 n = rz_num_math (num, s); char strbits[65]; if (force_mode) { mode = force_mode; } if (flags & 2) { ut64 n2 = n; - r_mem_swapendian ((ut8 *) &n, (ut8 *) &n2, (n >> 32)? 8: 4); + rz_mem_swapendian ((ut8 *) &n, (ut8 *) &n2, (n >> 32)? 8: 4); } switch (mode) { case 'I': @@ -78,7 +78,7 @@ static int format_output(RNum *num, char mode, const char *s, int force_mode, ut case 'O': printf ("0%" PFMT64o "\n", n); break; case 'B': if (n) { - r_num_to_bits (strbits, n); + rz_num_to_bits (strbits, n); printf ("%sb\n", strbits); } else { printf ("0b\n"); @@ -86,7 +86,7 @@ static int format_output(RNum *num, char mode, const char *s, int force_mode, ut break; case 'T': if (n) { - r_num_to_trits (strbits, n); + rz_num_to_trits (strbits, n); printf ("%st\n", strbits); } else { printf ("0t\n"); @@ -105,51 +105,51 @@ static void print_ascii_table(void) { static int help(void) { printf ( - " =[base] ; rax2 =10 0x46 -> output in base 10\n" - " int -> hex ; rax2 10\n" - " hex -> int ; rax2 0xa\n" - " -int -> hex ; rax2 -77\n" - " -hex -> int ; rax2 0xffffffb3\n" - " int -> bin ; rax2 b30\n" - " int -> ternary ; rax2 t42\n" - " bin -> int ; rax2 1010d\n" - " ternary -> int ; rax2 1010dt\n" - " float -> hex ; rax2 3.33f\n" - " hex -> float ; rax2 Fx40551ed8\n" - " oct -> hex ; rax2 35o\n" - " hex -> oct ; rax2 Ox12 (O is a letter)\n" - " bin -> hex ; rax2 1100011b\n" - " hex -> bin ; rax2 Bx63\n" - " ternary -> hex ; rax2 212t\n" - " hex -> ternary ; rax2 Tx23\n" - " raw -> hex ; rax2 -S < /binfile\n" - " hex -> raw ; rax2 -s 414141\n" + " =[base] ; rz_ax =10 0x46 -> output in base 10\n" + " int -> hex ; rz_ax 10\n" + " hex -> int ; rz_ax 0xa\n" + " -int -> hex ; rz_ax -77\n" + " -hex -> int ; rz_ax 0xffffffb3\n" + " int -> bin ; rz_ax b30\n" + " int -> ternary ; rz_ax t42\n" + " bin -> int ; rz_ax 1010d\n" + " ternary -> int ; rz_ax 1010dt\n" + " float -> hex ; rz_ax 3.33f\n" + " hex -> float ; rz_ax Fx40551ed8\n" + " oct -> hex ; rz_ax 35o\n" + " hex -> oct ; rz_ax Ox12 (O is a letter)\n" + " bin -> hex ; rz_ax 1100011b\n" + " hex -> bin ; rz_ax Bx63\n" + " ternary -> hex ; rz_ax 212t\n" + " hex -> ternary ; rz_ax Tx23\n" + " raw -> hex ; rz_ax -S < /binfile\n" + " hex -> raw ; rz_ax -s 414141\n" " -l ; append newline to output (for -E/-D/-r/..\n" - " -a show ascii table ; rax2 -a\n" - " -b bin -> str ; rax2 -b 01000101 01110110\n" - " -B str -> bin ; rax2 -B hello\n" - " -d force integer ; rax2 -d 3 -> 3 instead of 0x3\n" - " -e swap endianness ; rax2 -e 0x33\n" + " -a show ascii table ; rz_ax -a\n" + " -b bin -> str ; rz_ax -b 01000101 01110110\n" + " -B str -> bin ; rz_ax -B hello\n" + " -d force integer ; rz_ax -d 3 -> 3 instead of 0x3\n" + " -e swap endianness ; rz_ax -e 0x33\n" " -D base64 decode ;\n" " -E base64 encode ;\n" - " -f floating point ; rax2 -f 6.3+2.1\n" - " -F stdin slurp code hex ; rax2 -F < shellcode.[c/py/js]\n" - " -h help ; rax2 -h\n" - " -i dump as C byte array ; rax2 -i < bytes\n" - " -k keep base ; rax2 -k 33+3 -> 36\n" - " -K randomart ; rax2 -K 0x34 1020304050\n" - " -L bin -> hex(bignum) ; rax2 -L 111111111 # 0x1ff\n" - " -n binary number ; rax2 -n 0x1234 # 34120000\n" - " -o octalstr -> raw ; rax2 -o \\162 \\62 # r2\n" - " -N binary number ; rax2 -N 0x1234 # \\x34\\x12\\x00\\x00\n" - " -r r2 style output ; rax2 -r 0x1234\n" - " -s hexstr -> raw ; rax2 -s 43 4a 50\n" - " -S raw -> hexstr ; rax2 -S < /bin/ls > ls.hex\n" - " -t tstamp -> str ; rax2 -t 1234567890\n" - " -x hash string ; rax2 -x linux osx\n" - " -u units ; rax2 -u 389289238 # 317.0M\n" - " -w signed word ; rax2 -w 16 0xffff\n" - " -v version ; rax2 -v\n"); + " -f floating point ; rz_ax -f 6.3+2.1\n" + " -F stdin slurp code hex ; rz_ax -F < shellcode.[c/py/js]\n" + " -h help ; rz_ax -h\n" + " -i dump as C byte array ; rz_ax -i < bytes\n" + " -k keep base ; rz_ax -k 33+3 -> 36\n" + " -K randomart ; rz_ax -K 0x34 1020304050\n" + " -L bin -> hex(bignum) ; rz_ax -L 111111111 # 0x1ff\n" + " -n binary number ; rz_ax -n 0x1234 # 34120000\n" + " -o octalstr -> raw ; rz_ax -o \\162 \\62 # r2\n" + " -N binary number ; rz_ax -N 0x1234 # \\x34\\x12\\x00\\x00\n" + " -r r2 style output ; rz_ax -r 0x1234\n" + " -s hexstr -> raw ; rz_ax -s 43 4a 50\n" + " -S raw -> hexstr ; rz_ax -S < /bin/ls > ls.hex\n" + " -t tstamp -> str ; rz_ax -t 1234567890\n" + " -x hash string ; rz_ax -x linux osx\n" + " -u units ; rz_ax -u 389289238 # 317.0M\n" + " -w signed word ; rz_ax -w 16 0xffff\n" + " -v version ; rz_ax -v\n"); return true; } @@ -205,7 +205,7 @@ static int rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) { case 'L': flags ^= 1 << 19; break; case 'i': flags ^= 1 << 21; break; case 'o': flags ^= 1 << 22; break; - case 'v': return r_main_version_print ("rax2"); + case 'v': return rz_main_version_print ("rz_ax"); case '\0': *_flags = flags; return !use_stdin (num, _flags, fm); @@ -215,12 +215,12 @@ static int rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) { if (str[1] >= '0' && str[1] <= '9') { if (str[2] == 'x') { out_mode = 'I'; - } else if (r_str_endswith (str, "f")) { + } else if (rz_str_endswith (str, "f")) { out_mode = 'l'; } return format_output (num, out_mode, str, *fm, flags); } - printf ("Usage: rax2 [options] [expr ...]\n"); + printf ("Usage: rz-ax [options] [expr ...]\n"); return help (); } str++; @@ -232,7 +232,7 @@ static int rax(RNum *num, char *str, int len, int last, ut64 *_flags, int *fm) { return true; } *_flags = flags; - if (!flags && r_str_nlen (str, 2) == 1) { + if (!flags && rz_str_nlen (str, 2) == 1) { if (*str == 'q') { return false; } @@ -247,7 +247,7 @@ dotherax: buf = malloc (n); if (buf) { memset (buf, '\0', n); - n = r_hex_str2bin (str, (ut8 *) buf); + n = rz_hex_str2bin (str, (ut8 *) buf); if (n > 0) { fwrite (buf, n, 1, stdout); } @@ -272,13 +272,13 @@ dotherax: } else if (flags & (1 << 3)) { // -b int i; ut8 buf[4096]; - const int n = r_str_binstr2bin (str, buf, sizeof (buf)); + const int n = rz_str_binstr2bin (str, buf, sizeof (buf)); for (i = 0; i < n; i++) { printf ("%c", buf[i]); } return true; } else if (flags & (1 << 4)) { // -x - int h = r_str_hash (str); + int h = rz_str_hash (str); printf ("0x%x\n", h); return true; } else if (flags & (1 << 5)) { // -k @@ -294,21 +294,21 @@ dotherax: } ut32 *m = (ut32 *) buf; memset (buf, '\0', n); - n = r_hex_str2bin (str, (ut8 *) buf); + n = rz_hex_str2bin (str, (ut8 *) buf); if (n < 1 || !memcmp (str, "0x", 2)) { - ut64 q = r_num_math (num, str); - s = r_print_randomart ((ut8 *) &q, sizeof (q), q); + ut64 q = rz_num_math (num, str); + s = rz_print_randomart ((ut8 *) &q, sizeof (q), q); printf ("%s\n", s); free (s); } else { - s = r_print_randomart ((ut8 *) buf, n, *m); + s = rz_print_randomart ((ut8 *) buf, n, *m); printf ("%s\n", s); free (s); } free (m); return true; } else if (flags & (1 << 9)) { // -n - ut64 n = r_num_math (num, str); + ut64 n = rz_num_math (num, str); if (n >> 32) { /* is 64 bit value */ ut8 *np = (ut8 *) &n; @@ -335,7 +335,7 @@ dotherax: return true; } else if (flags & (1 << 17)) { // -B (bin -> str) int i = 0; - // TODO: move to r_util + // TODO: move to rz_util for (i = 0; i < strlen (str); i++) { ut8 ch = str[i]; printf ("%d%d%d%d" @@ -351,7 +351,7 @@ dotherax: } return true; } else if (flags & (1 << 16)) { // -w - ut64 n = r_num_math (num, str); + ut64 n = rz_num_math (num, str); if (n >> 31) { // is >32bit n = (st64) (st32) n; @@ -364,7 +364,7 @@ dotherax: fflush (stdout); return true; } else if (flags & (1 << 15)) { // -N - ut64 n = r_num_math (num, str); + ut64 n = rz_num_math (num, str); if (n >> 32) { /* is 64 bit value */ ut8 *np = (ut8 *) &n; @@ -391,31 +391,31 @@ dotherax: return true; } else if (flags & (1 << 10)) { // -u char buf[8]; - r_num_units (buf, sizeof (buf), r_num_math (NULL, str)); + rz_num_units (buf, sizeof (buf), rz_num_math (NULL, str)); printf ("%s\n", buf); return true; } else if (flags & (1 << 11)) { // -t - RList *split = r_str_split_list (str, "GMT", 0); - char *ts = r_list_head (split)->data; + RzList *split = rz_str_split_list (str, "GMT", 0); + char *ts = rz_list_head (split)->data; const char *gmt = NULL; - if (r_list_length (split) >= 2 && strlen (r_list_head (split)->n->data) > 2) { - gmt = (const char*) r_list_head (split)->n->data + 2; + if (rz_list_length (split) >= 2 && strlen (rz_list_head (split)->n->data) > 2) { + gmt = (const char*) rz_list_head (split)->n->data + 2; } - ut32 n = r_num_math (num, ts); - RPrint *p = r_print_new (); + ut32 n = rz_num_math (num, ts); + RPrint *p = rz_print_new (); if (gmt) { - p->datezone = r_num_math (num, gmt); + p->datezone = rz_num_math (num, gmt); } - r_print_date_unix (p, (const ut8 *) &n, sizeof (ut32)); - r_print_free (p); - r_list_free (split); + rz_print_date_unix (p, (const ut8 *) &n, sizeof (ut32)); + rz_print_free (p); + rz_list_free (split); return true; } else if (flags & (1 << 12)) { // -E const int n = strlen (str); /* http://stackoverflow.com/questions/4715415/base64-what-is-the-worst-possible-increase-in-space-usage */ char *out = calloc (1, (n + 2) / 3 * 4 + 1); // ceil(n/3)*4 plus 1 for NUL if (out) { - r_base64_encode (out, (const ut8 *) str, n); + rz_base64_encode (out, (const ut8 *) str, n); printf ("%s%s", out, nl); fflush (stdout); free (out); @@ -425,16 +425,16 @@ dotherax: const int n = strlen (str); ut8 *out = calloc (1, n / 4 * 3 + 1); if (out) { - r_base64_decode (out, str, n); + rz_base64_decode (out, str, n); printf ("%s%s", out, nl); fflush (stdout); free (out); } return true; } else if (flags & 1 << 14) { // -F - char *s = r_stdin_slurp (NULL); + char *s = rz_stdin_slurp (NULL); if (s) { - char *res = r_hex_from_code (s); + char *res = rz_hex_from_code (s); if (res) { printf ("%s\n", res); fflush (stdout); @@ -451,21 +451,21 @@ dotherax: ut32 n32, s, a; double d; float f; - ut64 n = r_num_math (num, str); + ut64 n = rz_num_math (num, str); if (num->dbz) { eprintf ("RNum ERROR: Division by Zero\n"); return false; } n32 = (ut32) (n & UT32_MAX); - asnum = r_num_as_string (NULL, n, false); + asnum = rz_num_as_string (NULL, n, false); memcpy (&f, &n32, sizeof (f)); memcpy (&d, &n, sizeof (d)); /* decimal, hexa, octal */ s = n >> 16 << 12; a = n & 0x0fff; - r_num_units (unit, sizeof (unit), n); + rz_num_units (unit, sizeof (unit), n); #if 0 eprintf ("%" PFMT64d " 0x%" PFMT64x " 0%" PFMT64o " %s %04x:%04x ", @@ -481,7 +481,7 @@ dotherax: free (asnum); } /* binary and floating point */ - r_str_bits (out, (const ut8 *) &n, sizeof (n), NULL); + rz_str_bits (out, (const ut8 *) &n, sizeof (n), NULL); eprintf ("%s %.01lf %ff %lf\n", out, num->fvalue, f, d); #endif @@ -499,7 +499,7 @@ dotherax: free (asnum); } /* binary and floating point */ - r_str_bits64 (out, n); + rz_str_bits64 (out, n); memcpy (&f, &n, sizeof (f)); memcpy (&d, &n, sizeof (d)); printf ("binary 0b%s\n", out); @@ -507,12 +507,12 @@ dotherax: printf ("double: %lf\n", d); /* ternary */ - r_num_to_trits (out, n); + rz_num_to_trits (out, n); printf ("trits 0t%s\n", out); return true; } else if (flags & (1 << 19)) { // -L - r_print_hex_from_bin (NULL, str); + rz_print_hex_from_bin (NULL, str); return true; } else if (flags & (1 << 21)) { // -i static const char start[] = "unsigned char buf[] = {"; @@ -541,19 +541,19 @@ dotherax: // To distinguish octal values. if (*str != '0') { - modified_str = r_str_newf ("0%s", str); + modified_str = rz_str_newf ("0%s", str); } else { - modified_str = r_str_newf (str); + modified_str = rz_str_newf (str); } - ut64 n = r_num_math (num, modified_str); + ut64 n = rz_num_math (num, modified_str); free (modified_str); if (num->dbz) { eprintf ("RNum ERROR: Division by Zero\n"); return false; } - asnum = r_num_as_string (NULL, n, false); + asnum = rz_num_as_string (NULL, n, false); if (asnum) { printf ("%s", asnum); free (asnum); @@ -565,31 +565,31 @@ dotherax: if (str[0] == '0' && (tolower (str[1]) == 'x')) { out_mode = (flags & 32)? '0': 'I'; - } else if (r_str_startswith (str, "b")) { + } else if (rz_str_startswith (str, "b")) { out_mode = 'B'; str++; - } else if (r_str_startswith (str, "t")) { + } else if (rz_str_startswith (str, "t")) { out_mode = 'T'; str++; - } else if (r_str_startswith (str, "Fx")) { + } else if (rz_str_startswith (str, "Fx")) { out_mode = 'F'; *str = '0'; - } else if (r_str_startswith (str, "Bx")) { + } else if (rz_str_startswith (str, "Bx")) { out_mode = 'B'; *str = '0'; - } else if (r_str_startswith (str, "Tx")) { + } else if (rz_str_startswith (str, "Tx")) { out_mode = 'T'; *str = '0'; - } else if (r_str_startswith (str, "Ox")) { + } else if (rz_str_startswith (str, "Ox")) { out_mode = 'O'; *str = '0'; - } else if (r_str_endswith (str, "d")) { + } else if (rz_str_endswith (str, "d")) { out_mode = 'I'; str[strlen (str) - 1] = 'b'; // TODO: Move print into format_output - } else if (r_str_endswith (str, "f")) { + } else if (rz_str_endswith (str, "f")) { out_mode = 'l'; - } else if (r_str_endswith (str, "dt")) { + } else if (rz_str_endswith (str, "dt")) { out_mode = 'I'; str[strlen (str) - 2] = 't'; str[strlen (str) - 1] = '\0'; @@ -605,20 +605,20 @@ dotherax: return true; } -R_API int r_main_rax2(int argc, const char **argv) { +RZ_API int rz_main_rz_ax(int argc, const char **argv) { int i, fm = 0; - RNum *num = r_num_new (NULL, NULL, NULL); + RNum *num = rz_num_new (NULL, NULL, NULL); if (argc == 1) { use_stdin (num, 0, &fm); } else { ut64 flags = 0; for (i = 1; i < argc; i++) { char *argv_i = strdup (argv[i]); - r_str_unescape (argv_i); + rz_str_unescape (argv_i); rax (num, argv_i, 0, i == argc - 1, &flags, &fm); } } - r_num_free (num); + rz_num_free (num); num = NULL; return 0; } diff --git a/libr/main/rabin2.c b/librz/main/rz_bin.c similarity index 70% rename from libr/main/rabin2.c rename to librz/main/rz_bin.c index b5d6f8e28e..8a21d342bd 100644 --- a/libr/main/rabin2.c +++ b/librz/main/rz_bin.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include -#include +#include +#include +#include #include #include -#include -#include "../../libr/bin/pdb/pdb_downloader.h" +#include +#include "../../librz/bin/pdb/pdb_downloader.h" static int rabin_show_help(int v) { - printf ("Usage: rabin2 [-AcdeEghHiIjlLMqrRsSUvVxzZ] [-@ at] [-a arch] [-b bits] [-B addr]\n" + printf ("Usage: rz-bin [-AcdeEghHiIjlLMqrRsSUvVxzZ] [-@ at] [-a arch] [-b bits] [-B addr]\n" " [-C F:C:D] [-f str] [-m addr] [-n str] [-N m:M] [-P[-P] pdb]\n" " [-o str] [-O str] [-k query] [-D lang symname] file\n"); if (v) { @@ -169,7 +169,7 @@ static bool extract_binobj(const RBinFile *bf, RBinXtrData *data, int idx) { eprintf ("error: BinFile buffer is empty\n"); return false; } - nb = r_buf_read_at (data->buf, 0, bytes, bin_size); + nb = rz_buf_read_at (data->buf, 0, bytes, bin_size); if (nb <= 0) { eprintf ("Couldn't read xtrdata\n"); return false; @@ -181,9 +181,9 @@ static bool extract_binobj(const RBinFile *bf, RBinXtrData *data, int idx) { if (!path) { return false; } - ptr = (char *)r_file_basename (path); - char *outpath = r_str_newf ("%s.fat", ptr); - if (!outpath || !r_sys_mkdirp (outpath)) { + ptr = (char *)rz_file_basename (path); + char *outpath = rz_str_newf ("%s.fat", ptr); + if (!outpath || !rz_sys_mkdirp (outpath)) { free (path); free (outpath); eprintf ("Error creating dir structure\n"); @@ -191,10 +191,10 @@ static bool extract_binobj(const RBinFile *bf, RBinXtrData *data, int idx) { } char *outfile = libname - ? r_str_newf ("%s/%s.%s.%s_%i.%d", outpath, ptr, arch, libname, bits, idx) - : r_str_newf ("%s/%s.%s_%i.%d", outpath, ptr, arch, bits, idx); + ? rz_str_newf ("%s/%s.%s.%s_%i.%d", outpath, ptr, arch, libname, bits, idx) + : rz_str_newf ("%s/%s.%s_%i.%d", outpath, ptr, arch, bits, idx); - if (!outfile || !r_file_dump (outfile, bytes, bin_size, 0)) { + if (!outfile || !rz_file_dump (outfile, bytes, bin_size, 0)) { eprintf ("Error extracting %s\n", outfile); res = false; } else { @@ -212,22 +212,22 @@ static bool extract_binobj(const RBinFile *bf, RBinXtrData *data, int idx) { static int rabin_extract(RBin *bin, int all) { RBinXtrData *data = NULL; int res = false; - RBinFile *bf = r_bin_cur (bin); + RBinFile *bf = rz_bin_cur (bin); if (!bf) { return res; } if (all) { int idx = 0; - RListIter *iter; - r_list_foreach (bf->xtr_data, iter, data) { + RzListIter *iter; + rz_list_foreach (bf->xtr_data, iter, data) { res = extract_binobj (bf, data, idx++); if (!res) { break; } } } else { - data = r_list_get_n (bf->xtr_data, 0); + data = rz_list_get_n (bf->xtr_data, 0); if (!data) { return res; } @@ -237,15 +237,15 @@ static int rabin_extract(RBin *bin, int all) { } static int rabin_dump_symbols(RBin *bin, int len) { - RList *symbols = r_bin_get_symbols (bin); + RzList *symbols = rz_bin_get_symbols (bin); if (!symbols) { return false; } - RListIter *iter; + RzListIter *iter; RBinSymbol *symbol; int olen = len; - r_list_foreach (symbols, iter, symbol) { + rz_list_foreach (symbols, iter, symbol) { if (symbol->size && (olen > symbol->size || !olen)) { len = symbol->size; } else if (!symbol->size && !olen) { @@ -262,8 +262,8 @@ static int rabin_dump_symbols(RBin *bin, int len) { free (buf); return false; } - if (r_buf_read_at (bin->cur->buf, symbol->paddr, buf, len) == len) { - r_hex_bin2str (buf, len, ret); + if (rz_buf_read_at (bin->cur->buf, symbol->paddr, buf, len) == len) { + rz_hex_bin2str (buf, len, ret); printf ("%s %s\n", symbol->name, ret); } else { eprintf ("Cannot read from buffer\n"); @@ -275,18 +275,18 @@ static int rabin_dump_symbols(RBin *bin, int len) { } static bool __dumpSections(RBin *bin, const char *scnname, const char *output, const char *file) { - RList *sections; - RListIter *iter; + RzList *sections; + RzListIter *iter; RBinSection *section; ut8 *buf; char *ret; int r; - if (!(sections = r_bin_get_sections (bin))) { + if (!(sections = rz_bin_get_sections (bin))) { return false; } - r_list_foreach (sections, iter, section) { + rz_list_foreach (sections, iter, section) { if (!strcmp (scnname, section->name)) { if (!(buf = malloc (section->size))) { return false; @@ -299,13 +299,13 @@ static bool __dumpSections(RBin *bin, const char *scnname, const char *output, c free (buf); return false; } - if (section->paddr > r_buf_size (bin->cur->buf) || - section->paddr + section->size > r_buf_size (bin->cur->buf)) { + if (section->paddr > rz_buf_size (bin->cur->buf) || + section->paddr + section->size > rz_buf_size (bin->cur->buf)) { free (buf); free (ret); return false; } - r = r_buf_read_at (bin->cur->buf, section->paddr, + r = rz_buf_read_at (bin->cur->buf, section->paddr, buf, section->size); if (r < 1) { free (buf); @@ -314,9 +314,9 @@ static bool __dumpSections(RBin *bin, const char *scnname, const char *output, c } //it does mean the user specified an output file if (strcmp (output, file)) { - r_file_dump (output, buf, section->size, 0); + rz_file_dump (output, buf, section->size, 0); } else { - r_hex_bin2str (buf, section->size, ret); + rz_hex_bin2str (buf, section->size, ret); printf ("%s\n", ret); } free (buf); @@ -345,18 +345,18 @@ static int rabin_do_operation(RBin *bin, const char *op, int rad, const char *ou if (!output) { output = file; } - RBinFile *bf = r_bin_cur (bin); + RBinFile *bf = rz_bin_cur (bin); if (bf) { - RBuffer *nb = r_buf_new_with_buf (bf->buf); - r_buf_free (bf->buf); + RBuffer *nb = rz_buf_new_with_buf (bf->buf); + rz_buf_free (bf->buf); bf->buf = nb; } switch (arg[0]) { case 'e': - rc = r_bin_wr_entry (bin, r_num_math (NULL, ptr)); + rc = rz_bin_wr_entry (bin, rz_num_math (NULL, ptr)); if (rc) { - rc = r_bin_wr_output (bin, output); + rc = rz_bin_wr_output (bin, output); } break; case 'd': @@ -366,7 +366,7 @@ static int rabin_do_operation(RBin *bin, const char *op, int rad, const char *ou switch (*ptr) { case 's': { - ut64 a = ptr2? r_num_math (NULL, ptr2): 0; + ut64 a = ptr2? rz_num_math (NULL, ptr2): 0; if (!rabin_dump_symbols (bin, a)) { goto error; } @@ -390,34 +390,34 @@ static int rabin_do_operation(RBin *bin, const char *op, int rad, const char *ou } switch (*ptr) { case 'l': - if (!ptr2 || !r_bin_wr_addlib (bin, ptr2)) { + if (!ptr2 || !rz_bin_wr_addlib (bin, ptr2)) { goto error; } - rc = r_bin_wr_output (bin, output); + rc = rz_bin_wr_output (bin, output); break; default: goto _rabin_do_operation_error; } break; case 'R': - r_bin_wr_rpath_del (bin); - rc = r_bin_wr_output (bin, output); + rz_bin_wr_rpath_del (bin); + rc = rz_bin_wr_output (bin, output); break; case 'C': { - RBinFile *cur = r_bin_cur (bin); - RBinPlugin *plg = r_bin_file_cur_plugin (cur); + RBinFile *cur = rz_bin_cur (bin); + RBinPlugin *plg = rz_bin_file_cur_plugin (cur); if (!plg && cur) { // are we in xtr? if (cur->xtr_data) { // load the first one - RBinXtrData *xtr_data = r_list_get_n (cur->xtr_data, 0); - if (xtr_data && !xtr_data->loaded && !r_bin_file_object_new_from_xtr_data (bin, cur, - UT64_MAX, r_bin_get_laddr (bin), xtr_data)) { + RBinXtrData *xtr_data = rz_list_get_n (cur->xtr_data, 0); + if (xtr_data && !xtr_data->loaded && !rz_bin_file_object_new_from_xtr_data (bin, cur, + UT64_MAX, rz_bin_get_laddr (bin), xtr_data)) { break; } } - plg = r_bin_file_cur_plugin (cur); + plg = rz_bin_file_cur_plugin (cur); if (!plg) { break; } @@ -425,25 +425,25 @@ static int rabin_do_operation(RBin *bin, const char *op, int rad, const char *ou if (plg && plg->signature) { char *sign = plg->signature (cur, rad == R_MODE_JSON); if (sign) { - r_cons_println (sign); - r_cons_flush (); + rz_cons_println (sign); + rz_cons_flush (); free (sign); } } } break; case 'r': - r_bin_wr_scn_resize (bin, ptr, r_num_math (NULL, ptr2)); - rc = r_bin_wr_output (bin, output); + rz_bin_wr_scn_resize (bin, ptr, rz_num_math (NULL, ptr2)); + rc = rz_bin_wr_output (bin, output); break; case 'p': { - int perms = (int)r_num_math (NULL, ptr2); + int perms = (int)rz_num_math (NULL, ptr2); if (!perms) { - perms = r_str_rwx (ptr2); + perms = rz_str_rwx (ptr2); } - r_bin_wr_scn_perms (bin, ptr, perms); - rc = r_bin_wr_output (bin, output); + rz_bin_wr_scn_perms (bin, ptr, perms); + rc = rz_bin_wr_output (bin, output); } break; default: @@ -463,7 +463,7 @@ error: static int rabin_show_srcline(RBin *bin, ut64 at) { char *srcline; - if (at != UT64_MAX && (srcline = r_bin_addr2text (bin, at, true))) { + if (at != UT64_MAX && (srcline = rz_bin_addr2text (bin, at, true))) { printf ("%s\n", srcline); free (srcline); return true; @@ -472,41 +472,41 @@ static int rabin_show_srcline(RBin *bin, ut64 at) { } /* bin callback */ -static int __lib_bin_cb(RLibPlugin *pl, void *user, void *data) { - struct r_bin_plugin_t *hand = (struct r_bin_plugin_t *)data; +static int __lib_bin_cb(RzLibPlugin *pl, void *user, void *data) { + struct rz_bin_plugin_t *hand = (struct rz_bin_plugin_t *)data; RBin *bin = user; //printf(" * Added (dis)assembly plugin\n"); - r_bin_add (bin, hand); + rz_bin_add (bin, hand); return true; } -static int __lib_bin_dt(RLibPlugin *pl, void *p, void *u) { +static int __lib_bin_dt(RzLibPlugin *pl, void *p, void *u) { return true; } /* binxtr callback */ -static int __lib_bin_xtr_cb(RLibPlugin *pl, void *user, void *data) { - struct r_bin_xtr_plugin_t *hand = (struct r_bin_xtr_plugin_t *)data; +static int __lib_bin_xtr_cb(RzLibPlugin *pl, void *user, void *data) { + struct rz_bin_xtr_plugin_t *hand = (struct rz_bin_xtr_plugin_t *)data; RBin *bin = user; //printf(" * Added (dis)assembly plugin\n"); - r_bin_xtr_add (bin, hand); + rz_bin_xtr_add (bin, hand); return true; } -static int __lib_bin_xtr_dt(RLibPlugin *pl, void *p, void *u) { +static int __lib_bin_xtr_dt(RzLibPlugin *pl, void *p, void *u) { return true; } /* binldr callback */ -static int __lib_bin_ldr_cb(RLibPlugin *pl, void *user, void *data) { - struct r_bin_ldr_plugin_t *hand = (struct r_bin_ldr_plugin_t *)data; +static int __lib_bin_ldr_cb(RzLibPlugin *pl, void *user, void *data) { + struct rz_bin_ldr_plugin_t *hand = (struct rz_bin_ldr_plugin_t *)data; RBin *bin = user; //printf(" * Added (dis)assembly plugin\n"); - r_bin_ldr_add (bin, hand); + rz_bin_ldr_add (bin, hand); return true; } -static int __lib_bin_ldr_dt(RLibPlugin *pl, void *p, void *u) { +static int __lib_bin_ldr_dt(RzLibPlugin *pl, void *p, void *u) { return true; } @@ -514,12 +514,12 @@ static char *__demangleAs(RBin *bin, int type, const char *file) { bool syscmd = bin? bin->demanglercmd: false; char *res = NULL; switch (type) { - case R_BIN_NM_CXX: res = r_bin_demangle_cxx (NULL, file, 0); break; - case R_BIN_NM_JAVA: res = r_bin_demangle_java (file); break; - case R_BIN_NM_OBJC: res = r_bin_demangle_objc (NULL, file); break; - case R_BIN_NM_SWIFT: res = r_bin_demangle_swift (file, syscmd); break; - case R_BIN_NM_MSVC: res = r_bin_demangle_msvc (file); break; - case R_BIN_NM_RUST: res = r_bin_demangle_rust (NULL, file, 0); break; + case R_BIN_NM_CXX: res = rz_bin_demangle_cxx (NULL, file, 0); break; + case R_BIN_NM_JAVA: res = rz_bin_demangle_java (file); break; + case R_BIN_NM_OBJC: res = rz_bin_demangle_objc (NULL, file); break; + case R_BIN_NM_SWIFT: res = rz_bin_demangle_swift (file, syscmd); break; + case R_BIN_NM_MSVC: res = rz_bin_demangle_msvc (file); break; + case R_BIN_NM_RUST: res = rz_bin_demangle_rust (NULL, file, 0); break; default: eprintf ("Unsupported demangler\n"); break; @@ -531,13 +531,13 @@ static void __listPlugins(RBin *bin, const char* plugin_name, int rad) { int format = (rad == R_MODE_JSON) ? 'j': rad? 'q': 0; bin->cb_printf = (PrintfCallback)printf; if (plugin_name) { - r_bin_list_plugin (bin, plugin_name, format); + rz_bin_list_plugin (bin, plugin_name, format); } else { - r_bin_list (bin, format); + rz_bin_list (bin, format); } } -R_API int r_main_rabin2(int argc, const char **argv) { +RZ_API int rz_main_rz_bin(int argc, const char **argv) { RBin *bin = NULL; const char *name = NULL; const char *file = NULL; @@ -556,39 +556,39 @@ R_API int r_main_rabin2(int argc, const char **argv) { const char *forcebin = NULL; const char *chksum = NULL; const char *op = NULL; - RCoreFile *fh = NULL; - RCoreBinFilter filter; + RzCoreFile *fh = NULL; + RzCoreBinFilter filter; int xtr_idx = 0; // load all files if extraction is necessary. int rawstr = 0; int fd = -1; - RCore core = {0}; - RLib *l = NULL; + RzCore core = {0}; + RzLib *l = NULL; ut64 at = UT64_MAX; - r_core_init (&core); + rz_core_init (&core); bin = core.bin; - if (!(tmp = r_sys_getenv ("RABIN2_NOPLUGINS"))) { - char *homeplugindir = r_str_home (R2_HOME_PLUGINS); - char *plugindir = r_str_r2_prefix (R2_PLUGINS); - char *extrasdir = r_str_r2_prefix (R2_EXTRAS); - char *bindingsdir = r_str_r2_prefix (R2_BINDINGS); - l = r_lib_new (NULL, NULL); - r_lib_add_handler (l, R_LIB_TYPE_BIN, "bin plugins", + if (!(tmp = rz_sys_getenv ("RABIN2_NOPLUGINS"))) { + char *homeplugindir = rz_str_home (R2_HOME_PLUGINS); + char *plugindir = rz_str_rz_prefix (R2_PLUGINS); + char *extrasdir = rz_str_rz_prefix (R2_EXTRAS); + char *bindingsdir = rz_str_rz_prefix (R2_BINDINGS); + l = rz_lib_new (NULL, NULL); + rz_lib_add_handler (l, R_LIB_TYPE_BIN, "bin plugins", &__lib_bin_cb, &__lib_bin_dt, bin); - r_lib_add_handler (l, R_LIB_TYPE_BIN_XTR, "bin xtr plugins", + rz_lib_add_handler (l, R_LIB_TYPE_BIN_XTR, "bin xtr plugins", &__lib_bin_xtr_cb, &__lib_bin_xtr_dt, bin); - r_lib_add_handler (l, R_LIB_TYPE_BIN_LDR, "bin ldr plugins", + rz_lib_add_handler (l, R_LIB_TYPE_BIN_LDR, "bin ldr plugins", &__lib_bin_ldr_cb, &__lib_bin_ldr_dt, bin); /* load plugins everywhere */ - char *path = r_sys_getenv (R_LIB_ENV); + char *path = rz_sys_getenv (R_LIB_ENV); if (path && *path) { - r_lib_opendir (l, path); + rz_lib_opendir (l, path); } - r_lib_opendir (l, homeplugindir); - r_lib_opendir (l, plugindir); - r_lib_opendir (l, extrasdir); - r_lib_opendir (l, bindingsdir); + rz_lib_opendir (l, homeplugindir); + rz_lib_opendir (l, plugindir); + rz_lib_opendir (l, extrasdir); + rz_lib_opendir (l, bindingsdir); free (homeplugindir); free (plugindir); free (extrasdir); @@ -597,55 +597,55 @@ R_API int r_main_rabin2(int argc, const char **argv) { } free (tmp); - if ((tmp = r_sys_getenv ("R2_CONFIG"))) { + if ((tmp = rz_sys_getenv ("R2_CONFIG"))) { Sdb *config_sdb = sdb_new (NULL, tmp, 0); if (config_sdb) { - r_config_unserialize (core.config, config_sdb, NULL); + rz_config_unserialize (core.config, config_sdb, NULL); sdb_free (config_sdb); } else { eprintf ("Cannot open file specified in R2_CONFIG\n"); } free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_DMNGLRCMD"))) { - r_config_set (core.config, "cmd.demangle", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_DMNGLRCMD"))) { + rz_config_set (core.config, "cmd.demangle", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_LANG"))) { - r_config_set (core.config, "bin.lang", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_LANG"))) { + rz_config_set (core.config, "bin.lang", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_DEMANGLE"))) { - r_config_set (core.config, "bin.demangle", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_DEMANGLE"))) { + rz_config_set (core.config, "bin.demangle", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_MAXSTRBUF"))) { - r_config_set (core.config, "bin.maxstrbuf", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_MAXSTRBUF"))) { + rz_config_set (core.config, "bin.maxstrbuf", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_STRFILTER"))) { - r_config_set (core.config, "bin.str.filter", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_STRFILTER"))) { + rz_config_set (core.config, "bin.str.filter", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_STRPURGE"))) { - r_config_set (core.config, "bin.str.purge", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_STRPURGE"))) { + rz_config_set (core.config, "bin.str.purge", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_DEBASE64"))) { - r_config_set (core.config, "bin.debase64", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_DEBASE64"))) { + rz_config_set (core.config, "bin.debase64", tmp); free (tmp); } - if ((tmp = r_sys_getenv ("RABIN2_PDBSERVER"))) { - r_config_set (core.config, "pdb.server", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_PDBSERVER"))) { + rz_config_set (core.config, "pdb.server", tmp); free (tmp); } #define is_active(x) (action & (x)) #define set_action(x) { actions++; action |= (x); } #define unset_action(x) action &= ~x - RGetopt opt; - r_getopt_init (&opt, argc, argv, "DjgAf:F:a:B:G:b:cC:k:K:dD:Mm:n:N:@:isSVIHeEUlRwO:o:pPqQrTtvLhuxXzZ"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "DjgAf:F:a:B:G:b:cC:k:K:dD:Mm:n:N:@:isSVIHeEUlRwO:o:pPqQrTtvLhuxXzZ"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'g': set_action (R_BIN_REQ_CLASSES); @@ -693,9 +693,9 @@ R_API int r_main_rabin2(int argc, const char **argv) { break; case 'f': arch_name = strdup (opt.arg); break; case 'F': forcebin = opt.arg; break; - case 'b': bits = r_num_math (NULL, opt.arg); break; + case 'b': bits = rz_num_math (NULL, opt.arg); break; case 'm': - at = r_num_math (NULL, opt.arg); + at = rz_num_math (NULL, opt.arg); set_action (R_BIN_REQ_SRCLINE); break; case 'i': @@ -744,8 +744,8 @@ R_API int r_main_rabin2(int argc, const char **argv) { case 'D': if (argv[opt.ind] && argv[opt.ind+1] && \ (!argv[opt.ind+1][0] || !strcmp (argv[opt.ind+1], "all"))) { - r_config_set (core.config, "bin.lang", argv[opt.ind]); - r_config_set (core.config, "bin.demangle", "true"); + rz_config_set (core.config, "bin.lang", argv[opt.ind]); + rz_config_set (core.config, "bin.demangle", "true"); opt.ind += 2; } else { do_demangle = argv[opt.ind]; @@ -771,7 +771,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { op = opt.arg; set_action (R_BIN_REQ_OPERATION); if (*op == 'c') { - r_sys_setenv ("RABIN2_CODESIGN_VERBOSE", "1"); + rz_sys_setenv ("RABIN2_CODESIGN_VERBOSE", "1"); } if (isBinopHelp (op)) { printf ("Usage: iO [expression]:\n" @@ -784,12 +784,12 @@ R_API int r_main_rabin2(int argc, const char **argv) { " p/.data/rwx change section permissions\n" " c show Codesign data\n" " C show LDID entitlements\n"); - r_core_fini (&core); + rz_core_fini (&core); return 0; } if (opt.ind == argc) { eprintf ("Missing filename\n"); - r_core_fini (&core); + rz_core_fini (&core); return 1; } break; @@ -797,22 +797,22 @@ R_API int r_main_rabin2(int argc, const char **argv) { case 'p': va = false; break; case 'r': rad = true; break; case 'v': - r_core_fini (&core); - return r_main_version_print ("rabin2"); + rz_core_fini (&core); + return rz_main_version_print ("rz_bin"); case 'L': set_action (R_BIN_REQ_LISTPLUGINS); break; case 'G': - laddr = r_num_math (NULL, opt.arg); + laddr = rz_num_math (NULL, opt.arg); if (laddr == UT64_MAX) { va = false; } break; case 'B': - baddr = r_num_math (NULL, opt.arg); + baddr = rz_num_math (NULL, opt.arg); break; case '@': - at = r_num_math (NULL, opt.arg); + at = rz_num_math (NULL, opt.arg); if (at == 0LL && *opt.arg != '0') { at = UT64_MAX; } @@ -822,13 +822,13 @@ R_API int r_main_rabin2(int argc, const char **argv) { break; case 'N': tmp = strchr (opt.arg, ':'); - r_config_set (core.config, "bin.minstr", opt.arg); + rz_config_set (core.config, "bin.minstr", opt.arg); if (tmp) { - r_config_set (core.config, "bin.maxstr", tmp + 1); + rz_config_set (core.config, "bin.maxstr", tmp + 1); } break; case 'h': - r_core_fini (&core); + rz_core_fini (&core); return rabin_show_help (1); default: action |= R_BIN_REQ_HELP; @@ -842,7 +842,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { plugin_name = argv[opt.ind]; } __listPlugins (bin, plugin_name, rad); - r_core_fini (&core); + rz_core_fini (&core); return 0; } @@ -850,10 +850,10 @@ R_API int r_main_rabin2(int argc, const char **argv) { char *res = NULL; int type; if ((argc - opt.ind) < 2) { - r_core_fini (&core); + rz_core_fini (&core); return rabin_show_help (0); } - type = r_bin_demangle_type (do_demangle); + type = rz_bin_demangle_type (do_demangle); file = argv[opt.ind + 1]; if (!strcmp (file, "-")) { for (;;) { @@ -864,7 +864,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { res = __demangleAs (bin, type, file); if (!res) { eprintf ("Unknown lang to demangle. Use: cxx, java, objc, swift\n"); - r_core_fini (&core); + rz_core_fini (&core); return 1; } if (res && *res) { @@ -881,7 +881,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { if (res && *res) { printf ("%s\n", res); free(res); - r_core_fini (&core); + rz_core_fini (&core); return 0; } else { printf ("%s\n", file); @@ -889,20 +889,20 @@ R_API int r_main_rabin2(int argc, const char **argv) { } free (res); //eprintf ("%s\n", file); - r_core_fini (&core); + rz_core_fini (&core); return 1; } file = argv[opt.ind]; if (file && !*file) { eprintf ("Cannot open empty path\n"); - r_core_fini (&core); + rz_core_fini (&core); return 1; } if (!query) { if (action & R_BIN_REQ_HELP || action == R_BIN_REQ_UNK || !file) { - r_core_fini (&core); + rz_core_fini (&core); return rabin_show_help (0); } } @@ -910,7 +910,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { ptr = strchr (arch, '_'); if (ptr) { *ptr = '\0'; - bits = r_num_math (NULL, ptr+1); + bits = rz_num_math (NULL, ptr+1); } } if (action & R_BIN_REQ_CREATE) { @@ -921,7 +921,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { char *p2, *p = strchr (create, ':'); if (!p) { eprintf ("Invalid format for -C flag. Use 'format:codehexpair:datahexpair'\n"); - r_core_fini (&core); + rz_core_fini (&core); return 1; } *p++ = 0; @@ -930,7 +930,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { // has data *p2++ = 0; data = malloc (strlen (p2)+1); - datalen = r_hex_str2bin (p2, data); + datalen = rz_hex_str2bin (p2, data); if (datalen < 0) { datalen = -datalen; } @@ -940,72 +940,72 @@ R_API int r_main_rabin2(int argc, const char **argv) { } code = malloc (strlen (p) + 1); if (!code) { - r_core_fini (&core); + rz_core_fini (&core); return 1; } - codelen = r_hex_str2bin (p, code); + codelen = rz_hex_str2bin (p, code); RBinArchOptions opts; - r_bin_arch_options_init (&opts, arch, bits); - b = r_bin_create (bin, create, code, codelen, data, datalen, &opts); + rz_bin_arch_options_init (&opts, arch, bits); + b = rz_bin_create (bin, create, code, codelen, data, datalen, &opts); if (b) { ut64 tmpsz; - const ut8 *tmp = r_buf_data (b, &tmpsz); - if (r_file_dump (file, tmp, tmpsz, 0)) { + const ut8 *tmp = rz_buf_data (b, &tmpsz); + if (rz_file_dump (file, tmp, tmpsz, 0)) { eprintf ("Dumped %" PFMT64d " bytes in '%s'\n", tmpsz, file); - (void)r_file_chmod (file, "+x", 0); + (void)rz_file_chmod (file, "+x", 0); } else { eprintf ("Error dumping into a.out\n"); } - r_buf_free (b); + rz_buf_free (b); } else { eprintf ("Cannot create binary for this format '%s'.\n", create); } - r_core_fini (&core); + rz_core_fini (&core); return 0; } if (rawstr == 2) { unset_action (R_BIN_REQ_STRINGS); } - r_config_set_i (core.config, "bin.rawstr", rawstr); + rz_config_set_i (core.config, "bin.rawstr", rawstr); if (!file) { eprintf ("Missing file.\n"); - r_core_fini (&core); + rz_core_fini (&core); return 1; } if (file && *file && action & R_BIN_REQ_DLOPEN) { #if __UNIX__ - int child = r_sys_fork (); + int child = rz_sys_fork (); if (child == -1) { - r_core_fini (&core); + rz_core_fini (&core); return 1; } if (child == 0) { return waitpid (child, NULL, 0); } #endif - void *addr = r_lib_dl_open (file); + void *addr = rz_lib_dl_open (file); if (addr) { eprintf ("%s is loaded at 0x%"PFMT64x"\n", file, (ut64)(size_t)(addr)); - r_lib_dl_close (addr); - r_core_fini (&core); + rz_lib_dl_close (addr); + rz_core_fini (&core); return 0; } eprintf ("Cannot open the '%s' library\n", file); - r_core_fini (&core); + rz_core_fini (&core); return 0; } if (action & R_BIN_REQ_PACKAGE) { - RList *files = r_list_newf (NULL); + RzList *files = rz_list_newf (NULL); const char *format = argv[opt.ind]; const char *file = argv[opt.ind + 1]; int i, rc = 0; if (opt.ind + 3 > argc) { - eprintf ("Usage: rabin2 -X [fat|zip] foo.zip a b c\n"); - r_core_fini (&core); + eprintf ("Usage: rz-bin -X [fat|zip] foo.zip a b c\n"); + rz_core_fini (&core); return 1; } @@ -1013,74 +1013,74 @@ R_API int r_main_rabin2(int argc, const char **argv) { eprintf ("PKG %s\n", file); for (i = opt.ind + 2; i < argc; i++) { eprintf ("ADD %s\n", argv[i]); - r_list_append (files, (void*)argv[i]); + rz_list_append (files, (void*)argv[i]); } - RBuffer *buf = r_bin_package (core.bin, format, file, files); + RBuffer *buf = rz_bin_package (core.bin, format, file, files); /* TODO: return bool or something to catch errors\n") */ if (buf) { - bool ret = r_buf_dump (buf, file); - r_buf_free (buf); + bool ret = rz_buf_dump (buf, file); + rz_buf_free (buf); if (!ret) { rc = 1; } } - r_core_fini (&core); - r_list_free (files); + rz_core_fini (&core); + rz_list_free (files); return rc; } if (file && *file) { - if ((fh = r_core_file_open (&core, file, R_PERM_R, 0))) { - fd = r_io_fd_get_current (core.io); + if ((fh = rz_core_file_open (&core, file, R_PERM_R, 0))) { + fd = rz_io_fd_get_current (core.io); if (fd == -1) { - eprintf ("r_core: Cannot open file '%s'\n", file); - r_core_file_free (fh); - r_core_fini (&core); + eprintf ("rz_core: Cannot open file '%s'\n", file); + rz_core_file_free (fh); + rz_core_fini (&core); return 1; } } else { - eprintf ("r_core: Cannot open file '%s'\n", file); - r_core_fini (&core); + eprintf ("rz_core: Cannot open file '%s'\n", file); + rz_core_fini (&core); return 1; } } - bin->minstrlen = r_config_get_i (core.config, "bin.minstr"); - bin->maxstrbuf = r_config_get_i (core.config, "bin.maxstrbuf"); + bin->minstrlen = rz_config_get_i (core.config, "bin.minstr"); + bin->maxstrbuf = rz_config_get_i (core.config, "bin.maxstrbuf"); - r_bin_force_plugin (bin, forcebin); - r_bin_load_filter (bin, action); + rz_bin_force_plugin (bin, forcebin); + rz_bin_load_filter (bin, action); RBinOptions bo; - r_bin_options_init (&bo, fd, baddr, laddr, rawstr); + rz_bin_options_init (&bo, fd, baddr, laddr, rawstr); bo.xtr_idx = xtr_idx; - if (!r_bin_open (bin, file, &bo)) { + if (!rz_bin_open (bin, file, &bo)) { //if this return false means that we did not return a valid bin object //but we have yet the chance that this file is a fat binary if (!bin->cur || !bin->cur->xtr_data) { - eprintf ("r_bin: Cannot open file\n"); - r_core_file_free (fh); - r_core_fini (&core); + eprintf ("rz_bin: Cannot open file\n"); + rz_core_file_free (fh); + rz_core_fini (&core); return 1; } } /* required to automatically select a sub-bin when not specified */ - (void)r_core_bin_update_arch_bits (&core); + (void)rz_core_bin_update_arch_bits (&core); if (baddr != UT64_MAX) { - r_bin_set_baddr (bin, baddr); + rz_bin_set_baddr (bin, baddr); } if (rawstr == 2) { - RBinFile *bf = r_bin_cur (core.bin); + RBinFile *bf = rz_bin_cur (core.bin); if (bf) { bf->strmode = rad; - r_bin_dump_strings (bf, bin->minstrlen, bf->rawstr); + rz_bin_dump_strings (bf, bin->minstrlen, bf->rawstr); } } if (query) { if (rad) { - r_core_bin_export_info (&core, R_MODE_RADARE); - r_cons_flush (); + rz_core_bin_export_info (&core, R_MODE_RADARE); + rz_cons_flush (); } else { if (!strcmp (query, "-")) { __sdb_prompt (bin->cur->sdb); @@ -1088,59 +1088,59 @@ R_API int r_main_rabin2(int argc, const char **argv) { sdb_query (bin->cur->sdb, query); } } - r_core_file_free (fh); - r_core_fini (&core); + rz_core_file_free (fh); + rz_core_fini (&core); return 0; } #define isradjson (rad==R_MODE_JSON&&actions>0) #define run_action(n,x,y) {\ if (action&(x)) {\ - if (isradjson) r_cons_printf ("%s\"%s\":",actions_done?",":"",n);\ - if (!r_core_bin_info (&core, y, rad, va, &filter, chksum)) {\ - if (isradjson) r_cons_print ("false");\ + if (isradjson) rz_cons_printf ("%s\"%s\":",actions_done?",":"",n);\ + if (!rz_core_bin_info (&core, y, rad, va, &filter, chksum)) {\ + if (isradjson) rz_cons_print ("false");\ };\ actions_done++;\ }\ } core.bin = bin; - bin->cb_printf = r_cons_printf; + bin->cb_printf = rz_cons_printf; filter.offset = at; filter.name = name; - r_cons_new ()->context->is_interactive = false; + rz_cons_new ()->context->is_interactive = false; if (isradjson) { - r_cons_print ("{"); + rz_cons_print ("{"); } // List fatmach0 sub-binaries, etc if (action & R_BIN_REQ_LISTARCHS || ((arch || bits || arch_name) && - !r_bin_select (bin, arch, bits, arch_name))) { + !rz_bin_select (bin, arch, bits, arch_name))) { if (rad == R_MODE_SIMPLEST || rad == R_MODE_SIMPLE) { - r_bin_list_archs (bin, 'q'); + rz_bin_list_archs (bin, 'q'); } else { - r_bin_list_archs (bin, (rad == R_MODE_JSON)? 'j': 1); + rz_bin_list_archs (bin, (rad == R_MODE_JSON)? 'j': 1); } actions_done++; free (arch_name); } if (action & R_BIN_REQ_PDB_DWNLD) { SPDBOptions pdbopts; - pdbopts.user_agent = (char*) r_config_get (core.config, "pdb.useragent"); - pdbopts.symbol_server = (char*) r_config_get (core.config, "pdb.server"); - pdbopts.extract = r_config_get_i (core.config, "pdb.extract"); + pdbopts.user_agent = (char*) rz_config_get (core.config, "pdb.useragent"); + pdbopts.symbol_server = (char*) rz_config_get (core.config, "pdb.server"); + pdbopts.extract = rz_config_get_i (core.config, "pdb.extract"); - if ((tmp = r_sys_getenv ("RABIN2_SYMSTORE"))) { - r_config_set (core.config, "pdb.symstore", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_SYMSTORE"))) { + rz_config_set (core.config, "pdb.symstore", tmp); R_FREE (tmp); } - pdbopts.symbol_store_path = (char *)r_config_get (core.config, "pdb.symstore"); - int r = r_bin_pdb_download (&core, isradjson, &actions_done, &pdbopts); - r_core_file_free (fh); - r_core_fini (&core); + pdbopts.symbol_store_path = (char *)rz_config_get (core.config, "pdb.symstore"); + int r = rz_bin_pdb_download (&core, isradjson, &actions_done, &pdbopts); + rz_core_file_free (fh); + rz_core_fini (&core); return r; } - if ((tmp = r_sys_getenv ("RABIN2_PREFIX"))) { - r_config_set (core.config, "bin.prefix", tmp); + if ((tmp = rz_sys_getenv ("RABIN2_PREFIX"))) { + rz_config_set (core.config, "bin.prefix", tmp); free (tmp); } @@ -1171,7 +1171,7 @@ R_API int r_main_rabin2(int argc, const char **argv) { rabin_show_srcline (bin, at); } if (action & R_BIN_REQ_EXTRACT) { - RBinFile *bf = r_bin_cur (bin); + RBinFile *bf = rz_bin_cur (bin); if (bf && bf->xtr_data) { rabin_extract (bin, (!arch && !arch_name && !bits)); } else { @@ -1184,12 +1184,12 @@ R_API int r_main_rabin2(int argc, const char **argv) { rabin_do_operation (bin, op, rad, output, file); } if (isradjson) { - r_cons_print ("}\n"); + rz_cons_print ("}\n"); } - r_cons_flush (); - r_core_file_free (fh); - r_core_fini (&core); - r_lib_free (l); + rz_cons_flush (); + rz_core_file_free (fh); + rz_core_fini (&core); + rz_lib_free (l); return 0; } diff --git a/libr/main/radiff2.c b/librz/main/rz_diff.c similarity index 71% rename from libr/main/radiff2.c rename to librz/main/rz_diff.c index 90a8cdba19..bf70c35d89 100644 --- a/libr/main/radiff2.c +++ b/librz/main/rz_diff.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include #ifdef _MSC_VER #ifndef WIN32_LEAN_AND_MEAN @@ -47,48 +47,48 @@ static int diffmode = 0; static bool disasm = false; static bool pdc = false; static bool quiet = false; -static RCore *core = NULL; +static RzCore *core = NULL; static const char *arch = NULL; const char *runcmd = NULL; static int bits = 0; static int anal_all = 0; static bool verbose = false; -static RList *evals = NULL; +static RzList *evals = NULL; -static RCore *opencore(const char *f) { - RListIter *iter; +static RzCore *opencore(const char *f) { + RzListIter *iter; const ut64 baddr = UT64_MAX; const char *e; - RCore *c = r_core_new (); + RzCore *c = rz_core_new (); if (!c) { return NULL; } - r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL); - r_config_set_i (c->config, "io.va", useva); - r_config_set_i (c->config, "scr.interactive", false); - r_list_foreach (evals, iter, e) { - r_config_eval (c->config, e, false); + rz_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL); + rz_config_set_i (c->config, "io.va", useva); + rz_config_set_i (c->config, "scr.interactive", false); + rz_list_foreach (evals, iter, e) { + rz_config_eval (c->config, e, false); } if (f) { - RCoreFile * rfile = NULL; + RzCoreFile * rfile = NULL; #if __WINDOWS__ - char *winf = r_acp_to_utf8 (f); - rfile = r_core_file_open (c, winf, 0, 0); + char *winf = rz_acp_to_utf8 (f); + rfile = rz_core_file_open (c, winf, 0, 0); free (winf); #else - rfile = r_core_file_open (c, f, 0, 0); + rfile = rz_core_file_open (c, f, 0, 0); #endif if (!rfile) { - r_core_free (c); + rz_core_free (c); return NULL; } - (void) r_core_bin_load (c, NULL, baddr); - (void) r_core_bin_update_arch_bits (c); + (void) rz_core_bin_load (c, NULL, baddr); + (void) rz_core_bin_update_arch_bits (c); // force PA mode when working with raw bins - if (r_list_empty (r_bin_get_sections (c->bin))) { - r_config_set_i (c->config, "io.va", false); + if (rz_list_empty (rz_bin_get_sections (c->bin))) { + rz_config_set_i (c->config, "io.va", false); } if (anal_all) { @@ -97,18 +97,18 @@ static RCore *opencore(const char *f) { case 1: cmd = "aaa"; break; case 2: cmd = "aaaa"; break; } - r_core_cmd0 (c, cmd); + rz_core_cmd0 (c, cmd); } if (runcmd) { - r_core_cmd0 (c, runcmd); + rz_core_cmd0 (c, runcmd); } // generate zignaturez? if (zignatures) { - r_core_cmd0 (c, "zg"); + rz_core_cmd0 (c, "zg"); } - r_cons_flush (); + rz_cons_flush (); } - // TODO: must enable io.va here if wanted .. r_config_set_i (c->config, "io.va", va); + // TODO: must enable io.va here if wanted .. rz_config_set_i (c->config, "io.va", va); return c; } @@ -125,7 +125,7 @@ static void readstr(char *s, int sz, const ut8 *buf, int len) { strncpy (s, (char *) buf, last); } -static int cb(RDiff *d, void *user, RDiffOp *op) { +static int cb(RzDiff *d, void *user, RzDiffOp *op) { int i; // , diffmode = (int)(size_t)user; char s[256] = {0}; if (showcount) { @@ -147,7 +147,7 @@ static int cb(RDiff *d, void *user, RDiffOp *op) { printf ("%02x ", op->a_buf[i]); } if (!quiet) { - char *p = r_str_escape ((const char*)op->a_buf); + char *p = rz_str_escape ((const char*)op->a_buf); printf (" \"%s\"", p); free (p); printf (Color_RESET); @@ -166,7 +166,7 @@ static int cb(RDiff *d, void *user, RDiffOp *op) { printf ("%02x ", op->b_buf[i]); } if (!quiet) { - char *p = r_str_escape((const char*)op->b_buf); + char *p = rz_str_escape((const char*)op->b_buf); printf (" \"%s\"", p); free (p); printf (Color_RESET); @@ -229,10 +229,10 @@ static int cb(RDiff *d, void *user, RDiffOp *op) { if (!core) { core = opencore (file); if (arch) { - r_config_set (core->config, "asm.arch", arch); + rz_config_set (core->config, "asm.arch", arch); } if (bits) { - r_config_set_i (core->config, "asm.bits", bits); + rz_config_set_i (core->config, "asm.bits", bits); } } for (i = 0; i < op->a_len; i++) { @@ -241,19 +241,19 @@ static int cb(RDiff *d, void *user, RDiffOp *op) { printf ("\n"); if (core) { int len = R_MAX (4, op->a_len); - RAsmCode *ac = r_asm_mdisassemble (core->rasm, op->a_buf, len); + RzAsmCode *ac = rz_asm_mdisassemble (core->rasm, op->a_buf, len); char *acbufasm = strdup (ac->assembly); if (quiet) { - char *bufasm = r_str_prefix_all (acbufasm, "- "); + char *bufasm = rz_str_prefix_all (acbufasm, "- "); printf ("%s\n", bufasm); free (bufasm); } else { - char *bufasm = r_str_prefix_all (acbufasm, Color_RED"- "); + char *bufasm = rz_str_prefix_all (acbufasm, Color_RED"- "); printf ("%s"Color_RESET, bufasm); free (bufasm); } free (acbufasm); - r_asm_code_free (ac); + rz_asm_code_free (ac); } } else { printf ("0x%08"PFMT64x " ", op->a_off); @@ -273,20 +273,20 @@ static int cb(RDiff *d, void *user, RDiffOp *op) { printf ("\n"); if (core) { int len = R_MAX (4, op->b_len); - RAsmCode *ac = r_asm_mdisassemble (core->rasm, op->b_buf, len); + RzAsmCode *ac = rz_asm_mdisassemble (core->rasm, op->b_buf, len); char *acbufasm = strdup (ac->assembly); if (quiet) { - char *bufasm = r_str_prefix_all (acbufasm, "+ "); + char *bufasm = rz_str_prefix_all (acbufasm, "+ "); printf ("%s\n", bufasm); free (bufasm); free (acbufasm); } else { - char *bufasm = r_str_prefix_all (acbufasm, Color_GREEN"+ "); + char *bufasm = rz_str_prefix_all (acbufasm, Color_GREEN"+ "); printf ("%s\n" Color_RESET, bufasm); free (bufasm); free (acbufasm); } - // r_asm_code_free (ac); + // rz_asm_code_free (ac); } } else { printf (" => "); @@ -312,7 +312,7 @@ void print_bytes(const void *p, size_t len, bool big_endian) { } } -static int bcb(RDiff *d, void *user, RDiffOp *op) { +static int bcb(RzDiff *d, void *user, RzDiffOp *op) { ut64 offset_diff = op->a_off - gdiff_start; unsigned char opcode; unsigned short USAddr = 0; @@ -426,7 +426,7 @@ static int bcb(RDiff *d, void *user, RDiffOp *op) { } static int show_help(int v) { - printf ("Usage: radiff2 [-abBcCdjrspOxuUvV] [-A[A]] [-g sym] [-m graph_mode][-t %%] [file] [file]\n"); + printf ("Usage: rz-diff [-abBcCdjrspOxuUvV] [-A[A]] [-g sym] [-m graph_mode][-t %%] [file] [file]\n"); if (v) { printf ( " -a [arch] specify architecture plugin to use (x86, arm, ..)\n" @@ -437,9 +437,9 @@ static int show_help(int v) { " -C graphdiff code (columns: off-A, match-ratio, off-B) (see -A)\n" " -d use delta diffing\n" " -D show disasm instead of hexpairs\n" - " -e [k=v] set eval config var value for all RCore instances\n" + " -e [k=v] set eval config var value for all RzCore instances\n" " -g [sym|off1,off2] graph diff of given symbol, or between two offsets\n" - " -G [cmd] run an r2 command on every RCore instance created\n" + " -G [cmd] run an r2 command on every RzCore instance created\n" " -i diff imports of target files (see -u, -U and -z)\n" " -j output in json format\n" " -n print bare addresses only (diff.bare=1)\n" @@ -485,10 +485,10 @@ static void dump_cols(ut8 *a, int as, ut8 *b, int bs, int w) { } switch (w) { case 8: - r_cons_printf (" offset 0 1 2 3 4 5 6 7 01234567 0 1 2 3 4 5 6 7 01234567\n"); + rz_cons_printf (" offset 0 1 2 3 4 5 6 7 01234567 0 1 2 3 4 5 6 7 01234567\n"); break; case 16: - r_cons_printf (" offset " + rz_cons_printf (" offset " "0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF " "0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\n"); break; @@ -496,9 +496,9 @@ static void dump_cols(ut8 *a, int as, ut8 *b, int bs, int w) { eprintf ("Invalid column width\n"); return; } - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); for (i = 0; i < sz; i += w) { - if (r_cons_is_breaked()) { + if (rz_cons_is_breaked()) { break; } if (i + w >= sz) { @@ -509,7 +509,7 @@ static void dump_cols(ut8 *a, int as, ut8 *b, int bs, int w) { if (eq) { ctx--; if (ctx == -1) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); continue; } if (ctx < 0) { @@ -519,69 +519,69 @@ static void dump_cols(ut8 *a, int as, ut8 *b, int bs, int w) { } else { ctx = DUMP_CONTEXT; } - r_cons_printf (eq? Color_GREEN: Color_RED); - r_cons_printf ("0x%08x%c ", i, eq? ' ': '!'); - r_cons_printf (Color_RESET); + rz_cons_printf (eq? Color_GREEN: Color_RED); + rz_cons_printf ("0x%08x%c ", i, eq? ' ': '!'); + rz_cons_printf (Color_RESET); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } - r_cons_printf ("%02x", a[i + j]); + rz_cons_printf ("%02x", a[i + j]); if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf (" "); + rz_cons_printf (" "); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } - r_cons_printf ("%c", IS_PRINTABLE (a[i + j])? a[i + j]: '.'); + rz_cons_printf ("%c", IS_PRINTABLE (a[i + j])? a[i + j]: '.'); if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf (" "); + rz_cons_printf (" "); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } - r_cons_printf ("%02x", b[i + j]); + rz_cons_printf ("%02x", b[i + j]); if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf (" "); + rz_cons_printf (" "); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } - r_cons_printf ("%c", IS_PRINTABLE (b[i + j])? b[i + j]: '.'); + rz_cons_printf ("%c", IS_PRINTABLE (b[i + j])? b[i + j]: '.'); if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } - r_cons_printf ("\n"); - r_cons_flush (); + rz_cons_printf ("\n"); + rz_cons_flush (); } - r_cons_break_end (); - r_cons_printf ("\n"Color_RESET); - r_cons_flush (); + rz_cons_break_end (); + rz_cons_printf ("\n"Color_RESET); + rz_cons_flush (); if (as != bs) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); } } @@ -594,10 +594,10 @@ static void dump_cols_hexii(ut8 *a, int as, ut8 *b, int bs, int w) { if (!a || !b || as < 0 || bs < 0) { return; } - PrintfCallback p = r_cons_printf; - r_cons_break_push (NULL, NULL); + PrintfCallback p = rz_cons_printf; + rz_cons_break_push (NULL, NULL); for (i = 0; i < sz; i += w) { - if (r_cons_is_breaked()) { + if (rz_cons_is_breaked()) { break; } if (i + w >= sz) { @@ -608,7 +608,7 @@ static void dump_cols_hexii(ut8 *a, int as, ut8 *b, int bs, int w) { if (eq) { ctx--; if (ctx == -1) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); continue; } if (ctx < 0) { @@ -618,13 +618,13 @@ static void dump_cols_hexii(ut8 *a, int as, ut8 *b, int bs, int w) { } else { ctx = DUMP_CONTEXT; } - r_cons_printf (eq? Color_GREEN: Color_RED); - r_cons_printf ("0x%08x%c ", i, eq? ' ': '!'); - r_cons_printf (Color_RESET); + rz_cons_printf (eq? Color_GREEN: Color_RED); + rz_cons_printf ("0x%08x%c ", i, eq? ' ': '!'); + rz_cons_printf (Color_RESET); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } ut8 ch = a[i + j]; if (spacy) { @@ -640,20 +640,20 @@ static void dump_cols_hexii(ut8 *a, int as, ut8 *b, int bs, int w) { p ("%02x", ch); } if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf (" "); + rz_cons_printf (" "); for (j = 0; j < w; j++) { bool eq2 = a[i + j] == b[i + j]; if (!eq) { - r_cons_printf (eq2? Color_GREEN: Color_RED); + rz_cons_printf (eq2? Color_GREEN: Color_RED); } ut8 ch = b[i + j]; if (spacy) { @@ -669,40 +669,40 @@ static void dump_cols_hexii(ut8 *a, int as, ut8 *b, int bs, int w) { p ("%02x", ch); } if (!eq) { - r_cons_printf (Color_RESET); + rz_cons_printf (Color_RESET); } } for (j = 0; j < pad; j++) { - r_cons_printf (" "); + rz_cons_printf (" "); } - r_cons_printf ("\n"); - r_cons_flush (); + rz_cons_printf ("\n"); + rz_cons_flush (); } - r_cons_break_end (); - r_cons_printf ("\n"Color_RESET); - r_cons_flush (); + rz_cons_break_end (); + rz_cons_printf ("\n"Color_RESET); + rz_cons_flush (); if (as != bs) { - r_cons_printf ("...\n"); + rz_cons_printf ("...\n"); } } static void handle_sha256(const ut8 *block, int len) { int i = 0; - RHash *ctx = r_hash_new (true, R_HASH_SHA256); - const ut8 *c = r_hash_do_sha256 (ctx, block, len); + RzHash *ctx = rz_hash_new (true, R_HASH_SHA256); + const ut8 *c = rz_hash_do_sha256 (ctx, block, len); if (!c) { - r_hash_free (ctx); + rz_hash_free (ctx); return; } for (i = 0; i < R_HASH_SIZE_SHA256; i++) { printf ("%02x", c[i]); } - r_hash_free (ctx); + rz_hash_free (ctx); } -static ut8 *slurp(RCore **c, const char *file, size_t *sz) { - RIODesc *d; - RIO *io; +static ut8 *slurp(RzCore **c, const char *file, size_t *sz) { + RzIODesc *d; + RzIO *io; if (c && file && strstr (file, "://")) { ut8 *data = NULL; ut64 size; @@ -714,14 +714,14 @@ static ut8 *slurp(RCore **c, const char *file, size_t *sz) { return NULL; } io = (*c)->io; - d = r_io_open (io, file, 0, 0); + d = rz_io_open (io, file, 0, 0); if (!d) { return NULL; } - size = r_io_size (io); + size = rz_io_size (io); if (size > 0 && size < ST32_MAX) { data = calloc (1, size); - if (r_io_read_at (io, 0, data, size)) { + if (rz_io_read_at (io, 0, data, size)) { if (sz) { *sz = size; } @@ -732,18 +732,18 @@ static ut8 *slurp(RCore **c, const char *file, size_t *sz) { } else { eprintf ("slurp: Invalid file size\n"); } - r_io_desc_close (d); + rz_io_desc_close (d); return data; } - return (ut8 *) r_file_slurp (file, sz); + return (ut8 *) rz_file_slurp (file, sz); } static int import_cmp(const RBinImport *a, const RBinImport *b) { return strcmp (a->name, b->name); } -static ut8 *get_imports(RCore *c, int *len) { - RListIter *iter; +static ut8 *get_imports(RzCore *c, int *len) { + RzListIter *iter; RBinImport *str, *old = NULL; ut8 *buf, *ptr; @@ -751,12 +751,12 @@ static ut8 *get_imports(RCore *c, int *len) { return NULL; } - RList *list = r_bin_get_imports (c->bin); - r_list_sort (list, (RListComparator) import_cmp); + RzList *list = rz_bin_get_imports (c->bin); + rz_list_sort (list, (RzListComparator) import_cmp); *len = 0; - r_list_foreach (list, iter, str) { + rz_list_foreach (list, iter, str) { if (!old || (old && import_cmp (old, str) != 0)) { *len += strlen (str->name) + 1; old = str; @@ -769,7 +769,7 @@ static ut8 *get_imports(RCore *c, int *len) { old = NULL; - r_list_foreach (list, iter, str) { + rz_list_foreach (list, iter, str) { if (old && !import_cmp (old, str)) { continue; } @@ -790,17 +790,17 @@ static int bs_cmp(const RBinString *a, const RBinString *b) { return diff == 0? strncmp (a->string, b->string, a->length): diff; } -static ut8 *get_strings(RCore *c, int *len) { - RList *list = r_bin_get_strings (c->bin); - RListIter *iter; +static ut8 *get_strings(RzCore *c, int *len) { + RzList *list = rz_bin_get_strings (c->bin); + RzListIter *iter; RBinString *str, *old = NULL; ut8 *buf, *ptr; - r_list_sort (list, (RListComparator) bs_cmp); + rz_list_sort (list, (RzListComparator) bs_cmp); *len = 0; - r_list_foreach (list, iter, str) { + rz_list_foreach (list, iter, str) { if (!old || (old && bs_cmp (old, str) != 0)) { *len += str->length + 1; old = str; @@ -814,7 +814,7 @@ static ut8 *get_strings(RCore *c, int *len) { old = NULL; - r_list_foreach (list, iter, str) { + rz_list_foreach (list, iter, str) { if (old && bs_cmp (old, str) == 0) { continue; } @@ -829,27 +829,27 @@ static ut8 *get_strings(RCore *c, int *len) { return buf; } -static char *get_graph_commands(RCore *c, ut64 off) { - bool tmp_html = r_cons_singleton ()->is_html; - r_cons_singleton ()->is_html = false; - r_cons_push (); - r_core_anal_graph (c, off, R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF | R_CORE_ANAL_STAR); - const char *static_str = r_cons_get_buffer (); +static char *get_graph_commands(RzCore *c, ut64 off) { + bool tmp_html = rz_cons_singleton ()->is_html; + rz_cons_singleton ()->is_html = false; + rz_cons_push (); + rz_core_anal_graph (c, off, R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF | R_CORE_ANAL_STAR); + const char *static_str = rz_cons_get_buffer (); char *retstr = strdup (static_str? static_str: ""); - r_cons_pop (); - r_cons_echo (NULL); - r_cons_singleton ()->is_html = tmp_html; + rz_cons_pop (); + rz_cons_echo (NULL); + rz_cons_singleton ()->is_html = tmp_html; return retstr; } -static void __generate_graph (RCore *c, ut64 off) { - r_return_if_fail (c); +static void __generate_graph (RzCore *c, ut64 off) { + rz_return_if_fail (c); char *ptr = get_graph_commands (c, off); char *str = ptr; - r_cons_break_push (NULL, NULL); + rz_cons_break_push (NULL, NULL); if (str) { for (;;) { - if (r_cons_is_breaked ()) { + if (rz_cons_is_breaked ()) { break; } char *eol = strchr (ptr, '\n'); @@ -862,7 +862,7 @@ static void __generate_graph (RCore *c, ut64 off) { free (str); return; } - r_core_cmd0 (c, p); + rz_core_cmd0 (c, p); free (p); } if (!eol) { @@ -872,57 +872,57 @@ static void __generate_graph (RCore *c, ut64 off) { } free (str); } - r_cons_break_pop (); + rz_cons_break_pop (); } -static void __print_diff_graph(RCore *c, ut64 off, int gmode) { +static void __print_diff_graph(RzCore *c, ut64 off, int gmode) { int opts = R_CORE_ANAL_GRAPHBODY | R_CORE_ANAL_GRAPHDIFF; - int use_utf8 = r_config_get_i (c->config, "scr.utf8"); - r_agraph_reset(c->graph); + int use_utf8 = rz_config_get_i (c->config, "scr.utf8"); + rz_agraph_reset(c->graph); switch (gmode) { case GRAPH_DOT_MODE: - r_core_anal_graph (c, off, opts); + rz_core_anal_graph (c, off, opts); break; case GRAPH_STAR_MODE: - r_core_anal_graph (c, off, opts | R_CORE_ANAL_STAR); + rz_core_anal_graph (c, off, opts | R_CORE_ANAL_STAR); break; case GRAPH_TINY_MODE: __generate_graph (c, off); - r_core_agraph_print (c, use_utf8, "t"); + rz_core_agraph_print (c, use_utf8, "t"); break; case GRAPH_INTERACTIVE_MODE: __generate_graph (c, off); - r_core_agraph_print (c, use_utf8, "v"); - r_cons_reset_colors (); + rz_core_agraph_print (c, use_utf8, "v"); + rz_cons_reset_colors (); break; case GRAPH_SDB_MODE: __generate_graph (c, off); - r_core_agraph_print (c, use_utf8, "k"); + rz_core_agraph_print (c, use_utf8, "k"); break; case GRAPH_GML_MODE: __generate_graph (c, off); - r_core_agraph_print (c, use_utf8, "g"); + rz_core_agraph_print (c, use_utf8, "g"); break; case GRAPH_JSON_MODE: - r_core_anal_graph (c, off, opts | R_CORE_ANAL_JSON); + rz_core_anal_graph (c, off, opts | R_CORE_ANAL_JSON); break; case GRAPH_JSON_DIS_MODE: - r_core_anal_graph (c, off, opts | R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); + rz_core_anal_graph (c, off, opts | R_CORE_ANAL_JSON | R_CORE_ANAL_JSON_FORMAT_DISASM); break; case GRAPH_DEFAULT_MODE: default: __generate_graph (c, off); - r_core_agraph_print (c, use_utf8, ""); - r_cons_reset_colors (); + rz_core_agraph_print (c, use_utf8, ""); + rz_cons_reset_colors (); break; } } -R_API int r_main_radiff2(int argc, const char **argv) { +RZ_API int rz_main_rz_diff(int argc, const char **argv) { const char *columnSort = NULL; const char *addr = NULL; - RCore *c = NULL, *c2 = NULL; - RDiff *d; + RzCore *c = NULL, *c2 = NULL; + RzDiff *d; ut8 *bufa = NULL, *bufb = NULL; int o, /*diffmode = 0,*/ delta = 0; ut64 sza = 0, szb = 0; @@ -931,11 +931,11 @@ R_API int r_main_radiff2(int argc, const char **argv) { int diffops = 0; int threshold = -1; double sim = 0.0; - evals = r_list_newf (NULL); + evals = rz_list_newf (NULL); - RGetopt opt; - r_getopt_init (&opt, argc, argv, "Aa:b:BCDe:npg:m:G:OijrhcdsS:uUvVxXt:zqZ"); - while ((o = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "Aa:b:BCDe:npg:m:G:OijrhcdsS:uUvVxXt:zqZ"); + while ((o = rz_getopt_next (&opt)) != -1) { switch (o) { case 'a': arch = opt.arg; @@ -950,7 +950,7 @@ R_API int r_main_radiff2(int argc, const char **argv) { diffmode = 'B'; break; case 'e': - r_list_append (evals, (void*)opt.arg); + rz_list_append (evals, (void*)opt.arg); break; case 'p': useva = false; @@ -1038,7 +1038,7 @@ R_API int r_main_radiff2(int argc, const char **argv) { diffmode = 'U'; break; case 'v': - return r_main_version_print ("radiff2"); + return rz_main_version_print ("rz_diff"); case 'q': quiet = true; break; @@ -1077,51 +1077,51 @@ R_API int r_main_radiff2(int argc, const char **argv) { case MODE_DIFF_IMPORTS: c = opencore (file); if (!c) { - eprintf ("Cannot open '%s'\n", r_str_get (file)); + eprintf ("Cannot open '%s'\n", rz_str_get (file)); } c2 = opencore (file2); if (!c || !c2) { - eprintf ("Cannot open '%s'\n", r_str_get (file2)); + eprintf ("Cannot open '%s'\n", rz_str_get (file2)); return 1; } c->c2 = c2; c2->c2 = c; - r_core_parse_radare2rc (c); + rz_core_parse_rizinrc (c); if (arch) { - r_config_set (c->config, "asm.arch", arch); - r_config_set (c2->config, "asm.arch", arch); + rz_config_set (c->config, "asm.arch", arch); + rz_config_set (c2->config, "asm.arch", arch); } if (bits) { - r_config_set_i (c->config, "asm.bits", bits); - r_config_set_i (c2->config, "asm.bits", bits); + rz_config_set_i (c->config, "asm.bits", bits); + rz_config_set_i (c2->config, "asm.bits", bits); } if (columnSort) { - r_config_set (c->config, "diff.sort", columnSort); - r_config_set (c2->config, "diff.sort", columnSort); + rz_config_set (c->config, "diff.sort", columnSort); + rz_config_set (c2->config, "diff.sort", columnSort); } - r_config_set_i (c->config, "diff.bare", showbare); - r_config_set_i (c2->config, "diff.bare", showbare); - r_anal_diff_setup_i (c->anal, diffops, threshold, threshold); - r_anal_diff_setup_i (c2->anal, diffops, threshold, threshold); + rz_config_set_i (c->config, "diff.bare", showbare); + rz_config_set_i (c2->config, "diff.bare", showbare); + rz_anal_diff_setup_i (c->anal, diffops, threshold, threshold); + rz_anal_diff_setup_i (c2->anal, diffops, threshold, threshold); if (pdc) { if (!addr) { //addr = "entry0"; addr = "main"; } /* should be in mode not in bool pdc */ - r_config_set_i (c->config, "scr.color", COLOR_MODE_DISABLED); - r_config_set_i (c2->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (c->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set_i (c2->config, "scr.color", COLOR_MODE_DISABLED); - ut64 addra = r_num_math (c->num, addr); - bufa = (ut8 *) r_core_cmd_strf (c, "af;pdc @ 0x%08"PFMT64x, addra); + ut64 addra = rz_num_math (c->num, addr); + bufa = (ut8 *) rz_core_cmd_strf (c, "af;pdc @ 0x%08"PFMT64x, addra); sza = (ut64)strlen ((const char *) bufa); - ut64 addrb = r_num_math (c2->num, addr); - bufb = (ut8 *) r_core_cmd_strf (c2, "af;pdc @ 0x%08"PFMT64x, addrb); + ut64 addrb = rz_num_math (c2->num, addr); + bufb = (ut8 *) rz_core_cmd_strf (c2, "af;pdc @ 0x%08"PFMT64x, addrb); szb = (ut64)strlen ((const char *) bufb); mode = MODE_DIFF; } else if (mode == MODE_GRAPH) { - int depth = r_config_get_i (c->config, "anal.depth"); + int depth = rz_config_get_i (c->config, "anal.depth"); if (depth < 1) { depth = 64; } @@ -1129,30 +1129,30 @@ R_API int r_main_radiff2(int argc, const char **argv) { char *second = strchr (words, ','); if (second) { *second++ = 0; - ut64 off = r_num_math (c->num, words); + ut64 off = rz_num_math (c->num, words); // define the same function at each offset - r_core_anal_fcn (c, off, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - r_core_anal_fcn (c2, r_num_math (c2->num, second), + rz_core_anal_fcn (c, off, UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); + rz_core_anal_fcn (c2, rz_num_math (c2->num, second), UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - r_core_gdiff (c, c2); + rz_core_gdiff (c, c2); __print_diff_graph (c, off, gmode); } else { - r_core_anal_fcn (c, r_num_math (c->num, words), + rz_core_anal_fcn (c, rz_num_math (c->num, words), UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - r_core_anal_fcn (c2, r_num_math (c2->num, words), + rz_core_anal_fcn (c2, rz_num_math (c2->num, words), UT64_MAX, R_ANAL_REF_TYPE_NULL, depth); - r_core_gdiff (c, c2); - __print_diff_graph (c, r_num_math (c->num, addr), gmode); + rz_core_gdiff (c, c2); + __print_diff_graph (c, rz_num_math (c->num, addr), gmode); } free (words); } else if (mode == MODE_CODE) { if (zignatures) { - r_core_cmd0 (c, "z~?"); - r_core_cmd0 (c2, "z~?"); - r_core_zdiff (c, c2); + rz_core_cmd0 (c, "z~?"); + rz_core_cmd0 (c2, "z~?"); + rz_core_zdiff (c, c2); } else { - r_core_gdiff (c, c2); - r_core_diff_show (c, c2); + rz_core_gdiff (c, c2); + rz_core_diff_show (c, c2); } } else if (mode == MODE_DIFF_IMPORTS) { int sz; @@ -1168,10 +1168,10 @@ R_API int r_main_radiff2(int argc, const char **argv) { szb = sz; } if (mode == MODE_CODE || mode == MODE_GRAPH) { - r_cons_flush (); + rz_cons_flush (); } - r_core_free (c); - r_core_free (c2); + rz_core_free (c); + rz_core_free (c2); if (mode == MODE_CODE || mode == MODE_GRAPH) { return 0; @@ -1182,13 +1182,13 @@ R_API int r_main_radiff2(int argc, const char **argv) { bufa = slurp (&c, file, &fsz); sza = fsz; if (!bufa) { - eprintf ("radiff2: Cannot open %s\n", r_str_get (file)); + eprintf ("rz_diff: Cannot open %s\n", rz_str_get (file)); return 1; } bufb = slurp (&c, file2, &fsz); szb = fsz; if (!bufb) { - eprintf ("radiff2: Cannot open: %s\n", r_str_get (file2)); + eprintf ("rz_diff: Cannot open: %s\n", rz_str_get (file2)); free (bufa); return 1; } @@ -1199,27 +1199,27 @@ R_API int r_main_radiff2(int argc, const char **argv) { } } - // initialize RCons - (void)r_cons_new (); + // initialize RzCons + (void)rz_cons_new (); switch (mode) { case MODE_COLSII: - if (!c && !r_list_empty (evals)) { + if (!c && !rz_list_empty (evals)) { c = opencore (NULL); } - dump_cols_hexii (bufa, (int)sza, bufb, (int)szb, (r_cons_get_size (NULL) > 112)? 16: 8); + dump_cols_hexii (bufa, (int)sza, bufb, (int)szb, (rz_cons_get_size (NULL) > 112)? 16: 8); break; case MODE_COLS: - if (!c && !r_list_empty (evals)) { + if (!c && !rz_list_empty (evals)) { c = opencore (NULL); } - dump_cols (bufa, (int)sza, bufb, (int)szb, (r_cons_get_size (NULL) > 112)? 16: 8); + dump_cols (bufa, (int)sza, bufb, (int)szb, (rz_cons_get_size (NULL) > 112)? 16: 8); break; case MODE_DIFF: case MODE_DIFF_STRS: case MODE_DIFF_IMPORTS: - d = r_diff_new (); - r_diff_set_delta (d, delta); + d = rz_diff_new (); + rz_diff_set_delta (d, delta); if (diffmode == 'j') { printf ("{\"files\":[{\"filename\":\"%s\", \"size\":%"PFMT64u", \"sha256\":\"", file, sza); handle_sha256 (bufa, (int)sza); @@ -1232,29 +1232,29 @@ R_API int r_main_radiff2(int argc, const char **argv) { (void) write (1, "\xd1\xff\xd1\xff\x04", 5); } if (diffmode == 'U') { - char *res = r_diff_buffers_unified (d, bufa, (int)sza, bufb, (int)szb); + char *res = rz_diff_buffers_unified (d, bufa, (int)sza, bufb, (int)szb); if (res) { printf ("%s", res); free (res); } } else if (diffmode == 'B') { - r_diff_set_callback (d, &bcb, 0); - r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb); + rz_diff_set_callback (d, &bcb, 0); + rz_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb); (void) write (1, "\x00", 1); } else { - r_diff_set_callback (d, &cb, 0); // (void *)(size_t)diffmode); - r_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb); + rz_diff_set_callback (d, &cb, 0); // (void *)(size_t)diffmode); + rz_diff_buffers (d, bufa, (ut32)sza, bufb, (ut32)szb); } if (diffmode == 'j') { printf ("]\n"); } - r_diff_free (d); + rz_diff_free (d); break; case MODE_DIST: case MODE_DIST_MYERS: case MODE_DIST_LEVENSTEIN: { - RDiff *d = r_diff_new (); + RzDiff *d = rz_diff_new (); if (d) { d->verbose = verbose; if (mode == MODE_DIST_LEVENSTEIN) { @@ -1264,15 +1264,15 @@ R_API int r_main_radiff2(int argc, const char **argv) { } else { d->type = 0; } - r_diff_buffers_distance (d, bufa, (ut32)sza, bufb, (ut32)szb, &count, &sim); - r_diff_free (d); + rz_diff_buffers_distance (d, bufa, (ut32)sza, bufb, (ut32)szb, &count, &sim); + rz_diff_free (d); } } printf ("similarity: %.3f\n", sim); printf ("distance: %d\n", count); break; } - r_cons_free (); + rz_cons_free (); if (diffmode == 'j' && showcount) { printf (",\"count\":%d}\n", count); diff --git a/libr/main/rafind2.c b/librz/main/rz_find.c similarity index 72% rename from libr/main/rafind2.c rename to librz/main/rz_find.c index e8d6ac3e58..395146d910 100644 --- a/libr/main/rafind2.c +++ b/librz/main/rz_find.c @@ -3,14 +3,14 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include // XXX kill those globals static bool showstr = false; @@ -28,12 +28,12 @@ static ut64 bsize = 4096; static ut64 from = 0LL, to = -1; static ut64 cur = 0; static RPrint *pr = NULL; -static RList *keywords; +static RzList *keywords; static const char *mask = NULL; static const char *curfile = NULL; static const char *comma = ""; -static int hit(RSearchKeyword *kw, void *user, ut64 addr) { +static int hit(RzSearchKeyword *kw, void *user, ut64 addr) { int delta = addr - cur; if (cur > addr && (cur - addr == kw->keyword_length - 1)) { // This case occurs when there is hit in search left over @@ -110,8 +110,8 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) { } else { printf ("0x%"PFMT64x"\n", addr); if (pr) { - r_print_hexdump (pr, addr, (ut8*)buf + delta, 78, 16, 1, 1); - r_cons_flush (); + rz_print_hexdump (pr, addr, (ut8*)buf + delta, 78, 16, 1, 1); + rz_cons_flush (); } } } @@ -150,8 +150,8 @@ static int show_help(const char *argv0, int line) { } static int rafind_open_file(const char *file, const ut8 *data, int datalen) { - RListIter *iter; - RSearch *rs = NULL; + RzListIter *iter; + RzSearch *rs = NULL; const char *kw; bool last = false; int ret, result = 0; @@ -162,28 +162,28 @@ static int rafind_open_file(const char *file, const ut8 *data, int datalen) { } if (identify) { - char *cmd = r_str_newf ("r2 -e search.show=false -e search.maxhits=1 -nqcpm '%s'", file); - r_sandbox_system (cmd, 1); + char *cmd = rz_str_newf ("r2 -e search.show=false -e search.maxhits=1 -nqcpm '%s'", file); + rz_sandbox_system (cmd, 1); free (cmd); return 0; } - RIO *io = r_io_new (); + RzIO *io = rz_io_new (); if (!io) { return 1; } - if (!r_io_open_nomap (io, file, R_PERM_R, 0)) { + if (!rz_io_open_nomap (io, file, R_PERM_R, 0)) { eprintf ("Cannot open file '%s'\n", file); result = 1; goto err; } if (data) { - r_io_write_at (io, 0, data, datalen); + rz_io_write_at (io, 0, data, datalen); } - rs = r_search_new (mode); + rs = rz_search_new (mode); if (!rs) { result = 1; goto err; @@ -196,73 +196,73 @@ static int rafind_open_file(const char *file, const ut8 *data, int datalen) { goto err; } rs->align = align; - r_search_set_callback (rs, &hit, buf); + rz_search_set_callback (rs, &hit, buf); if (to == -1) { - to = r_io_size (io); + to = rz_io_size (io); } - if (!r_cons_new ()) { + if (!rz_cons_new ()) { result = 1; goto err; } if (mode == R_SEARCH_STRING) { /* TODO: implement using api */ - r_sys_cmdf ("rabin2 -q%szzz '%s'", json? "j": "", file); + rz_sys_cmdf ("rz_bin -q%szzz '%s'", json? "j": "", file); goto done; } if (mode == R_SEARCH_MAGIC) { char *tostr = (to && to != UT64_MAX)? - r_str_newf ("-e search.to=%"PFMT64d, to): strdup (""); - char *cmd = r_str_newf ("r2" + rz_str_newf ("-e search.to=%"PFMT64d, to): strdup (""); + char *cmd = rz_str_newf ("r2" " -e search.in=range" " -e search.align=%d" " -e search.from=%"PFMT64d " %s -qnc/m%s '%s'", align, from, tostr, json? "j": "", file); - r_sandbox_system (cmd, 1); + rz_sandbox_system (cmd, 1); free (cmd); free (tostr); goto done; } if (mode == R_SEARCH_ESIL) { - r_list_foreach (keywords, iter, kw) { - char *cmd = r_str_newf ("r2 -qc \"/E %s\" %s", kw, file); + rz_list_foreach (keywords, iter, kw) { + char *cmd = rz_str_newf ("r2 -qc \"/E %s\" %s", kw, file); if (cmd) { - r_sandbox_system (cmd, 1); + rz_sandbox_system (cmd, 1); free (cmd); } } goto done; } if (mode == R_SEARCH_KEYWORD) { - r_list_foreach (keywords, iter, kw) { + rz_list_foreach (keywords, iter, kw) { if (hexstr) { if (mask) { - r_search_kw_add (rs, r_search_keyword_new_hex (kw, mask, NULL)); + rz_search_kw_add (rs, rz_search_keyword_new_hex (kw, mask, NULL)); } else { - r_search_kw_add (rs, r_search_keyword_new_hexmask (kw, NULL)); + rz_search_kw_add (rs, rz_search_keyword_new_hexmask (kw, NULL)); } } else if (widestr) { - r_search_kw_add (rs, r_search_keyword_new_wide (kw, mask, NULL, 0)); + rz_search_kw_add (rs, rz_search_keyword_new_wide (kw, mask, NULL, 0)); } else { - r_search_kw_add (rs, r_search_keyword_new_str (kw, mask, NULL, 0)); + rz_search_kw_add (rs, rz_search_keyword_new_str (kw, mask, NULL, 0)); } } } else if (mode == R_SEARCH_STRING) { - r_search_kw_add (rs, r_search_keyword_new_hexmask ("00", NULL)); //XXX + rz_search_kw_add (rs, rz_search_keyword_new_hexmask ("00", NULL)); //XXX } curfile = file; - r_search_begin (rs); - (void)r_io_seek (io, from, R_IO_SEEK_SET); + rz_search_begin (rs); + (void)rz_io_seek (io, from, R_IO_SEEK_SET); result = 0; for (cur = from; !last && cur < to; cur += bsize) { if ((cur + bsize) > to) { bsize = to - cur; last = true; } - ret = r_io_pread_at (io, cur, buf, bsize); + ret = rz_io_pread_at (io, cur, buf, bsize); if (ret == 0) { if (nonstop) { continue; @@ -274,17 +274,17 @@ static int rafind_open_file(const char *file, const ut8 *data, int datalen) { bsize = ret; } - if (r_search_update (rs, cur, buf, ret) == -1) { + if (rz_search_update (rs, cur, buf, ret) == -1) { eprintf ("search: update read error at 0x%08"PFMT64x"\n", cur); break; } } done: - r_cons_free (); + rz_cons_free (); err: free (buf); - r_search_free (rs); - r_io_free (io); + rz_search_free (rs); + rz_io_free (io); return result; } static int rafind_open_dir(const char *dir); @@ -292,51 +292,51 @@ static int rafind_open_dir(const char *dir); static int rafind_open(const char *file) { if (!strcmp (file, "-")) { int sz = 0; - ut8 *buf = (ut8 *)r_stdin_slurp (&sz); - char *ff = r_str_newf ("malloc://%d", sz); + ut8 *buf = (ut8 *)rz_stdin_slurp (&sz); + char *ff = rz_str_newf ("malloc://%d", sz); int res = rafind_open_file (ff, buf, sz); free (ff); free (buf); return res; } - return r_file_is_directory (file) + return rz_file_is_directory (file) ? rafind_open_dir (file) : rafind_open_file (file, NULL, -1); } static int rafind_open_dir(const char *dir) { - RListIter *iter; + RzListIter *iter; char *fullpath; char *fname = NULL; - RList *files = r_sys_dir (dir); + RzList *files = rz_sys_dir (dir); if (files) { - r_list_foreach (files, iter, fname) { + rz_list_foreach (files, iter, fname) { /* Filter-out unwanted entries */ if (*fname == '.') { continue; } - fullpath = r_str_newf ("%s"R_SYS_DIR"%s", dir, fname); + fullpath = rz_str_newf ("%s"R_SYS_DIR"%s", dir, fname); (void)rafind_open (fullpath); free (fullpath); } - r_list_free (files); + rz_list_free (files); } return 0; } -R_API int r_main_rafind2(int argc, const char **argv) { +RZ_API int rz_main_rz_find(int argc, const char **argv) { int c; const char *file = NULL; - keywords = r_list_newf (NULL); - RGetopt opt; - r_getopt_init (&opt, argc, argv, "a:ie:b:jmM:s:S:x:Xzf:F:t:E:rqnhvZ"); - while ((c = r_getopt_next (&opt)) != -1) { + keywords = rz_list_newf (NULL); + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "a:ie:b:jmM:s:S:x:Xzf:F:t:E:rqnhvZ"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'a': - align = r_num_math (NULL, opt.arg); + align = rz_num_math (NULL, opt.arg); break; case 'r': rad = true; @@ -356,69 +356,69 @@ R_API int r_main_rafind2(int argc, const char **argv) { case 'e': mode = R_SEARCH_REGEXP; hexstr = 0; - r_list_append (keywords, (void*)opt.arg); + rz_list_append (keywords, (void*)opt.arg); break; case 'E': mode = R_SEARCH_ESIL; - r_list_append (keywords, (void*)opt.arg); + rz_list_append (keywords, (void*)opt.arg); break; case 's': mode = R_SEARCH_KEYWORD; hexstr = 0; widestr = 0; - r_list_append (keywords, (void*)opt.arg); + rz_list_append (keywords, (void*)opt.arg); break; case 'S': mode = R_SEARCH_KEYWORD; hexstr = 0; widestr = 1; - r_list_append (keywords, (void*)opt.arg); + rz_list_append (keywords, (void*)opt.arg); break; case 'b': - bsize = r_num_math (NULL, opt.arg); + bsize = rz_num_math (NULL, opt.arg); break; case 'M': // XXX should be from hexbin mask = opt.arg; break; case 'f': - from = r_num_math (NULL, opt.arg); + from = rz_num_math (NULL, opt.arg); break; case 'F': { size_t data_size; - char *data = r_file_slurp (opt.arg, &data_size); + char *data = rz_file_slurp (opt.arg, &data_size); if (!data) { eprintf ("Cannot slurp '%s'\n", opt.arg); return 1; } - char *hexdata = r_hex_bin2strdup ((ut8*)data, data_size); + char *hexdata = rz_hex_bin2strdup ((ut8*)data, data_size); if (hexdata) { mode = R_SEARCH_KEYWORD; hexstr = true; widestr = false; - r_list_append (keywords, (void*)hexdata); + rz_list_append (keywords, (void*)hexdata); } free (data); } break; case 't': - to = r_num_math (NULL, opt.arg); + to = rz_num_math (NULL, opt.arg); break; case 'x': mode = R_SEARCH_KEYWORD; hexstr = 1; widestr = 0; - r_list_append (keywords, (void*)opt.arg); + rz_list_append (keywords, (void*)opt.arg); break; case 'X': - pr = r_print_new (); + pr = rz_print_new (); break; case 'q': quiet = true; break; case 'v': - return r_main_version_print ("rafind2"); + return rz_main_version_print ("rz_find"); case 'h': return show_help(argv[0], 0); case 'z': @@ -435,7 +435,7 @@ R_API int r_main_rafind2(int argc, const char **argv) { return show_help (argv[0], 1); } /* Enable quiet mode if searching just a single file */ - if (opt.ind + 1 == argc && !r_file_is_directory (argv[opt.ind])) { + if (opt.ind + 1 == argc && !rz_file_is_directory (argv[opt.ind])) { quiet = true; } if (json) { diff --git a/libr/main/ragg2.c b/librz/main/rz_gg.c similarity index 75% rename from libr/main/ragg2.c rename to librz/main/rz_gg.c index 313649564f..b2d7b63f71 100644 --- a/libr/main/ragg2.c +++ b/librz/main/rz_gg.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2011-2020 - pancake */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int usage(int v) { - printf ("Usage: ragg2 [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n" + printf ("Usage: rz-gg [-FOLsrxhvz] [-a arch] [-b bits] [-k os] [-o file] [-I path]\n" " [-i sc] [-e enc] [-B hex] [-c k=v] [-C file] [-p pad] [-q off]\n" " [-S string] [-f fmt] [-nN dword] [-dDw off:hex] file|f.asm|-\n"); if (v) { @@ -49,17 +49,17 @@ static int usage(int v) { } -static void list(REgg *egg) { - RListIter *iter; - REggPlugin *p; +static void list(RzEgg *egg) { + RzListIter *iter; + RzEggPlugin *p; printf ("shellcodes:\n"); - r_list_foreach (egg->plugins, iter, p) { + rz_list_foreach (egg->plugins, iter, p) { if (p->type == R_EGG_PLUGIN_SHELLCODE) { printf ("%10s : %s\n", p->name, p->desc); } } printf ("encoders:\n"); - r_list_foreach (egg->plugins, iter, p) { + rz_list_foreach (egg->plugins, iter, p) { if (p->type == R_EGG_PLUGIN_ENCODER) { printf ("%10s : %s\n", p->name, p->desc); } @@ -67,22 +67,22 @@ static void list(REgg *egg) { } static int create(const char *format, const char *arch, int bits, const ut8 *code, int codelen) { - RBin *bin = r_bin_new (); + RBin *bin = rz_bin_new (); RBinArchOptions opts; RBuffer *b; - r_bin_arch_options_init (&opts, arch, bits); - b = r_bin_create (bin, format, code, codelen, NULL, 0, &opts); + rz_bin_arch_options_init (&opts, arch, bits); + b = rz_bin_create (bin, format, code, codelen, NULL, 0, &opts); if (b) { ut64 blen; - const ut8 *tmp = r_buf_data (b, &blen); + const ut8 *tmp = rz_buf_data (b, &blen); if (write (1, tmp, blen) != blen) { eprintf ("Failed to write buffer\n"); } - r_buf_free (b); + rz_buf_free (b); } else { eprintf ("Cannot create binary for this format '%s'.\n", format); } - r_bin_free (bin); + rz_bin_free (bin); return 0; } @@ -113,7 +113,7 @@ static int openfile(const char *f, int x) { } #define ISEXEC (fmt!='r') -R_API int r_main_ragg2(int argc, const char **argv) { +RZ_API int rz_main_rz_gg(int argc, const char **argv) { const char *file = NULL; const char *padding = NULL; const char *pattern = NULL; @@ -140,11 +140,11 @@ R_API int r_main_ragg2(int argc, const char **argv) { int ofileauto = 0; RBuffer *b; int c, i, fd = -1; - REgg *egg = r_egg_new (); + RzEgg *egg = rz_egg_new (); - RGetopt opt; - r_getopt_init (&opt, argc, argv, "n:N:he:a:b:f:o:sxXrk:FOI:Li:c:p:P:B:C:vd:D:w:zq:S:"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "n:N:he:a:b:f:o:sxXrk:FOI:Li:c:p:P:B:C:vd:D:w:zq:S:"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'a': arch = opt.arg; @@ -160,13 +160,13 @@ R_API int r_main_ragg2(int argc, const char **argv) { bits = atoi (opt.arg); break; case 'B': - bytes = r_str_append (bytes, opt.arg); + bytes = rz_str_append (bytes, opt.arg); break; case 'C': if (R_STR_ISEMPTY (opt.arg)) { eprintf ("Cannot open empty contents path\n"); free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } contents = opt.arg; @@ -179,11 +179,11 @@ R_API int r_main_ragg2(int argc, const char **argv) { int len, off; ut8 *b; *p++ = 0; - off = r_num_math (NULL, arg); + off = rz_num_math (NULL, arg); b = malloc (strlen (opt.arg) + 1); - len = r_hex_str2bin (p, b); + len = rz_hex_str2bin (p, b); if (len > 0) { - r_egg_patch (egg, off, (const ut8*)b, len); + rz_egg_patch (egg, off, (const ut8*)b, len); } else { eprintf ("Invalid hexstr for -w\n"); } @@ -196,15 +196,15 @@ R_API int r_main_ragg2(int argc, const char **argv) { break; case 'n': { - ut32 n = r_num_math (NULL, opt.arg); + ut32 n = rz_num_math (NULL, opt.arg); append = 1; - r_egg_patch (egg, -1, (const ut8*)&n, 4); + rz_egg_patch (egg, -1, (const ut8*)&n, 4); } break; case 'N': { - ut64 n = r_num_math (NULL, opt.arg); - r_egg_patch (egg, -1, (const ut8*)&n, 8); + ut64 n = rz_num_math (NULL, opt.arg); + rz_egg_patch (egg, -1, (const ut8*)&n, 8); append = 1; } break; @@ -214,11 +214,11 @@ R_API int r_main_ragg2(int argc, const char **argv) { char *p = strchr (opt.arg, ':'); if (p) { *p = 0; - off = r_num_math (NULL, opt.arg); - n = r_num_math (NULL, p + 1); + off = rz_num_math (NULL, opt.arg); + n = rz_num_math (NULL, p + 1); *p = ':'; // TODO: honor endianness here - r_egg_patch (egg, off, (const ut8*)&n, 4); + rz_egg_patch (egg, off, (const ut8*)&n, 4); } else { eprintf ("Missing colon in -d\n"); } @@ -228,10 +228,10 @@ R_API int r_main_ragg2(int argc, const char **argv) { { char *p = strchr (opt.arg, ':'); if (p) { - ut64 n, off = r_num_math (NULL, opt.arg); - n = r_num_math (NULL, p + 1); + ut64 n, off = rz_num_math (NULL, opt.arg); + n = rz_num_math (NULL, p + 1); // TODO: honor endianness here - r_egg_patch (egg, off, (const ut8*)&n, 8); + rz_egg_patch (egg, off, (const ut8*)&n, 8); } else { eprintf ("Missing colon in -d\n"); } @@ -250,10 +250,10 @@ R_API int r_main_ragg2(int argc, const char **argv) { if (R_STR_ISEMPTY (opt.arg)) { eprintf ("Cannot open empty include path\n"); free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } - r_egg_lang_include_path (egg, opt.arg); + rz_egg_lang_include_path (egg, opt.arg); break; case 'i': shellcode = opt.arg; @@ -269,9 +269,9 @@ R_API int r_main_ragg2(int argc, const char **argv) { char *p = strchr (opt.arg, '='); if (p) { *p++ = 0; - r_egg_option_set (egg, opt.arg, p); + rz_egg_option_set (egg, opt.arg, p); } else { - r_egg_option_set (egg, opt.arg, "true"); + rz_egg_option_set (egg, opt.arg, "true"); } } break; @@ -310,17 +310,17 @@ R_API int r_main_ragg2(int argc, const char **argv) { break; case 'L': list (egg); - r_egg_free (egg); + rz_egg_free (egg); free (sequence); return 0; case 'h': - r_egg_free (egg); + rz_egg_free (egg); free (sequence); return usage (1); case 'v': free (sequence); - r_egg_free (egg); - return r_main_version_print ("ragg2"); + rz_egg_free (egg); + return rz_main_version_print ("rz_gg"); case 'z': show_str = 1; break; @@ -330,14 +330,14 @@ R_API int r_main_ragg2(int argc, const char **argv) { break; default: free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } } if (opt.ind == argc && !shellcode && !bytes && !contents && !encoder && !padding && !pattern && !append && !get_offset && !str) { free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return usage (0); } else { file = argv[opt.ind]; @@ -356,20 +356,20 @@ R_API int r_main_ragg2(int argc, const char **argv) { if (strncmp (sequence, "0x", 2)) { eprintf ("Need hex value with `0x' prefix e.g. 0x41414142\n"); free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } - get_offset = r_num_math (0, sequence); - printf ("Little endian: %d\n", r_debruijn_offset (get_offset, false)); - printf ("Big endian: %d\n", r_debruijn_offset (get_offset, true)); + get_offset = rz_num_math (0, sequence); + printf ("Little endian: %d\n", rz_debruijn_offset (get_offset, false)); + printf ("Big endian: %d\n", rz_debruijn_offset (get_offset, true)); free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 0; } // initialize egg - r_egg_setup (egg, arch, bits, 0, os); + rz_egg_setup (egg, arch, bits, 0, os); if (file) { if (R_STR_ISEMPTY (file)) { eprintf ("Cannot open empty path\n"); @@ -384,12 +384,12 @@ R_API int r_main_ragg2(int argc, const char **argv) { if (feof (stdin)) { break; } - r_egg_load (egg, buf, 0); + rz_egg_load (egg, buf, 0); } } else if (strstr (file, ".c")) { char *fileSanitized = strdup (file); - r_str_sanitize (fileSanitized); - char *textFile = r_egg_Cfile_parser (fileSanitized, arch, os, bits); + rz_str_sanitize (fileSanitized); + char *textFile = rz_egg_Cfile_parser (fileSanitized, arch, os, bits); if (!textFile) { eprintf ("Failure while parsing '%s'\n", fileSanitized); @@ -397,14 +397,14 @@ R_API int r_main_ragg2(int argc, const char **argv) { } size_t l; - char *buf = r_file_slurp (textFile, &l); + char *buf = rz_file_slurp (textFile, &l); if (buf && l > 0) { - r_egg_raw (egg, (const ut8*)buf, (int)l); + rz_egg_raw (egg, (const ut8*)buf, (int)l); } else { eprintf ("Error loading '%s'\n", textFile); } - r_file_rm (textFile); + rz_file_rm (textFile); free (fileSanitized); free (textFile); free (buf); @@ -414,7 +414,7 @@ R_API int r_main_ragg2(int argc, const char **argv) { } else { fmt = 0; } - if (!r_egg_include (egg, file, fmt)) { + if (!rz_egg_include (egg, file, fmt)) { eprintf ("Cannot open '%s'\n", file); goto fail; } @@ -422,11 +422,11 @@ R_API int r_main_ragg2(int argc, const char **argv) { } // compile source code to assembly - if (!r_egg_compile (egg)) { + if (!rz_egg_compile (egg)) { if (!fmt) { - eprintf ("r_egg_compile: fail\n"); + eprintf ("rz_egg_compile: fail\n"); free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } } @@ -435,16 +435,16 @@ R_API int r_main_ragg2(int argc, const char **argv) { if (str) { int l = strlen (str); if (l > 0) { - r_egg_raw (egg, (const ut8*)str, l); + rz_egg_raw (egg, (const ut8*)str, l); } } // add raw file if (contents) { size_t l; - char *buf = r_file_slurp (contents, &l); + char *buf = rz_file_slurp (contents, &l); if (buf && l > 0) { - r_egg_raw (egg, (const ut8*)buf, (int)l); + rz_egg_raw (egg, (const ut8*)buf, (int)l); } else { eprintf ("Error loading '%s'\n", contents); } @@ -453,7 +453,7 @@ R_API int r_main_ragg2(int argc, const char **argv) { // add shellcode if (shellcode) { - if (!r_egg_shellcode (egg, shellcode)) { + if (!rz_egg_shellcode (egg, shellcode)) { eprintf ("Unknown shellcode '%s'\n", shellcode); goto fail; } @@ -462,9 +462,9 @@ R_API int r_main_ragg2(int argc, const char **argv) { // add raw bytes if (bytes) { ut8 *b = malloc (strlen (bytes) + 1); - int len = r_hex_str2bin (bytes, b); + int len = rz_hex_str2bin (bytes, b); if (len > 0) { - if (!r_egg_raw (egg, b, len)) { + if (!rz_egg_raw (egg, b, len)) { eprintf ("Unknown '%s'\n", shellcode); free (b); goto fail; @@ -509,12 +509,12 @@ R_API int r_main_ragg2(int argc, const char **argv) { } // assemble to binary - if (!r_egg_assemble (egg)) { - eprintf ("r_egg_assemble: invalid assembly\n"); + if (!rz_egg_assemble (egg)) { + eprintf ("rz_egg_assemble: invalid assembly\n"); goto fail; } if (encoder) { - if (!r_egg_encode (egg, encoder)) { + if (!rz_egg_encode (egg, encoder)) { eprintf ("Invalid encoder '%s'\n", encoder); goto fail; } @@ -522,43 +522,43 @@ R_API int r_main_ragg2(int argc, const char **argv) { // add padding if (padding) { - r_egg_padding (egg, padding); + rz_egg_padding (egg, padding); } // add pattern if (pattern) { - r_egg_pattern (egg, r_num_math (NULL, pattern)); + rz_egg_pattern (egg, rz_num_math (NULL, pattern)); } // apply patches if (!egg->bin) { - egg->bin = r_buf_new (); + egg->bin = rz_buf_new (); } - if (!(b = r_egg_get_bin (egg))) { - eprintf ("r_egg_get_bin: invalid egg :(\n"); + if (!(b = rz_egg_get_bin (egg))) { + eprintf ("rz_egg_get_bin: invalid egg :(\n"); goto fail; } - r_egg_finalize (egg); + rz_egg_finalize (egg); if (show_asm) { - printf ("%s\n", r_egg_get_assembly (egg)); + printf ("%s\n", rz_egg_get_assembly (egg)); } if (show_raw || show_hex || show_execute) { if (show_execute) { int r; if (show_execute_rop) { - r = r_egg_run_rop (egg); + r = rz_egg_run_rop (egg); } else { - r = r_egg_run (egg); + r = rz_egg_run (egg); } - r_egg_free (egg); + rz_egg_free (egg); return r; } - b = r_egg_get_bin (egg); + b = rz_egg_get_bin (egg); if (show_raw) { ut64 blen; - const ut8 *tmp = r_buf_data (b, &blen); + const ut8 *tmp = rz_buf_data (b, &blen); if (write (1, tmp, blen) != blen) { eprintf ("Failed to write buffer\n"); goto fail; @@ -568,15 +568,15 @@ R_API int r_main_ragg2(int argc, const char **argv) { eprintf ("No format specified wtf\n"); goto fail; } - RPrint *p = r_print_new (); + RPrint *p = rz_print_new (); ut64 tmpsz; - const ut8 *tmp = r_buf_data (b, &tmpsz); + const ut8 *tmp = rz_buf_data (b, &tmpsz); switch (*format) { case 'c': - r_print_code (p, 0, tmp, tmpsz, 'c'); + rz_print_code (p, 0, tmp, tmpsz, 'c'); break; case 'j': // JavaScript - r_print_code (p, 0, tmp, tmpsz, 'j'); + rz_print_code (p, 0, tmp, tmpsz, 'j'); break; case 'r': if (show_str) { @@ -586,7 +586,7 @@ R_API int r_main_ragg2(int argc, const char **argv) { } printf ("\"\n"); } else if (show_hex) { - r_buf_seek (b, 0, R_BUF_SET); + rz_buf_seek (b, 0, R_BUF_SET); for (i = 0; i < tmpsz; i++) { printf ("%02x", tmp[i]); } @@ -595,7 +595,7 @@ R_API int r_main_ragg2(int argc, const char **argv) { break; case 'p': // PE if (strlen(format) >= 2 && format[1] == 'y') { // Python - r_print_code (p, 0, tmp, tmpsz, 'p'); + rz_print_code (p, 0, tmp, tmpsz, 'p'); } break; case 'e': // ELF @@ -606,20 +606,20 @@ R_API int r_main_ragg2(int argc, const char **argv) { eprintf ("unknown executable format (%s)\n", format); goto fail; } - r_print_free (p); + rz_print_free (p); } } if (fd != -1) { close (fd); } free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 0; fail: if (fd != -1) { close (fd); } free (sequence); - r_egg_free (egg); + rz_egg_free (egg); return 1; } diff --git a/libr/main/rahash2.c b/librz/main/rz_hash.c similarity index 75% rename from libr/main/rahash2.c rename to librz/main/rz_hash.c index d863bf8dbf..625f1ff994 100644 --- a/libr/main/rahash2.c +++ b/librz/main/rz_hash.c @@ -2,29 +2,29 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include static ut64 from = 0LL; static ut64 to = 0LL; static bool incremental = true; static int iterations = 0; static int quiet = 0; -static RHashSeed s = { +static RzHashSeed s = { 0 }, *_s = NULL; -static void compare_hashes(const RHash *ctx, const ut8 *compare, int length, int *ret) { +static void compare_hashes(const RzHash *ctx, const ut8 *compare, int length, int *ret) { if (compare) { // algobit has only 1 bit set if (!memcmp (ctx->digest, compare, length)) { - printf ("rahash2: Computed hash matches the expected one.\n"); + printf ("rz-hash: Computed hash matches the expected one.\n"); } else { - eprintf ("rahash2: Computed hash doesn't match the expected one.\n"); + eprintf ("rz-hash: Computed hash doesn't match the expected one.\n"); *ret = 1; } } @@ -38,12 +38,12 @@ static void do_hash_seed(const char *seed) { } _s = &s; if (!strcmp (seed, "-")) { - s.buf = (ut8 *)r_stdin_slurp (&s.len); + s.buf = (ut8 *)rz_stdin_slurp (&s.len); return; } if (seed[0] == '@') { size_t len; - s.buf = (ut8 *)r_file_slurp (seed + 1, &len); + s.buf = (ut8 *)rz_file_slurp (seed + 1, &len); s.len = (size_t)len; return; } @@ -62,7 +62,7 @@ static void do_hash_seed(const char *seed) { strcpy ((char *) s.buf, sptr + 2); s.len = strlen (sptr + 2); } else { - s.len = r_hex_str2bin (sptr, s.buf); + s.len = rz_hex_str2bin (sptr, s.buf); if (s.len < 1) { strcpy ((char *) s.buf, sptr); s.len = strlen (sptr); @@ -87,10 +87,10 @@ static void do_hash_hexprint(const ut8 *c, int len, int ule, int rad) { } } -static void do_hash_print(RHash *ctx, ut64 hash, int dlen, int rad, int ule) { +static void do_hash_print(RzHash *ctx, ut64 hash, int dlen, int rad, int ule) { char *o; const ut8 *c = ctx->digest; - const char *hname = r_hash_name (hash); + const char *hname = rz_hash_name (hash); switch (rad) { case 0: if (!quiet) { @@ -116,42 +116,42 @@ static void do_hash_print(RHash *ctx, ut64 hash, int dlen, int rad, int ule) { printf ("\"}"); break; default: - o = r_print_randomart (c, dlen, from); + o = rz_print_randomart (c, dlen, from); printf ("%s\n%s\n", hname, o); free (o); break; } } -static int do_hash_internal(RHash *ctx, ut64 hash, const ut8 *buf, int len, int rad, int print, int le) { +static int do_hash_internal(RzHash *ctx, ut64 hash, const ut8 *buf, int len, int rad, int print, int le) { if (len < 0) { return 0; } - int dlen = r_hash_calculate (ctx, hash, buf, len); + int dlen = rz_hash_calculate (ctx, hash, buf, len); if (!print) { return 1; } if (iterations > 0) { - r_hash_do_spice (ctx, hash, iterations, _s); + rz_hash_do_spice (ctx, hash, iterations, _s); } do_hash_print (ctx, hash, dlen, rad, le); return 1; } -static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int rad, int ule, const ut8 *compare) { - ut64 j, fsize, algobit = r_hash_name_to_bits (algo); - RHash *ctx; +static int do_hash(const char *file, const char *algo, RzIO *io, int bsize, int rad, int ule, const ut8 *compare) { + ut64 j, fsize, algobit = rz_hash_name_to_bits (algo); + RzHash *ctx; ut8 *buf; int ret = 0; ut64 i; bool first = true; if (algobit == R_HASH_NONE) { - eprintf ("rahash2: Invalid hashing algorithm specified\n"); + eprintf ("rz-hash: Invalid hashing algorithm specified\n"); return 1; } - fsize = r_io_desc_size (io->desc); + fsize = rz_io_desc_size (io->desc); if (fsize < 1) { - eprintf ("rahash2: Invalid file size\n"); + eprintf ("rz-hash: Invalid file size\n"); return 1; } if (bsize < 0) { @@ -164,18 +164,18 @@ static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int r to = fsize; } if (from > to) { - eprintf ("rahash2: Invalid -f -t range\n"); + eprintf ("rz-hash: Invalid -f -t range\n"); return 1; } if (fsize == -1LL) { - eprintf ("rahash2: Unknown file size\n"); + eprintf ("rz-hash: Unknown file size\n"); return 1; } buf = calloc (1, bsize + 1); if (!buf) { return 1; } - ctx = r_hash_new (true, algobit); + ctx = rz_hash_new (true, algobit); if (rad == 'j') { printf ("["); @@ -184,24 +184,24 @@ static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int r for (i = 1; i < R_HASH_ALL; i <<= 1) { if (algobit & i) { ut64 hashbit = i & algobit; - int dlen = r_hash_size (hashbit); - r_hash_do_begin (ctx, i); + int dlen = rz_hash_size (hashbit); + rz_hash_do_begin (ctx, i); if (s.buf && s.prefix) { do_hash_internal (ctx, hashbit, s.buf, s.len, rad, 0, ule); } for (j = from; j < to; j += bsize) { int len = ((j + bsize) > to)? (to - j): bsize; - r_io_pread_at (io, j, buf, len); + rz_io_pread_at (io, j, buf, len); do_hash_internal (ctx, hashbit, buf, len, rad, 0, ule); } if (s.buf && !s.prefix) { do_hash_internal (ctx, hashbit, s.buf, s.len, rad, 0, ule); } - r_hash_do_end (ctx, i); + rz_hash_do_end (ctx, i); if (iterations > 0) { - r_hash_do_spice (ctx, i, iterations, _s); + rz_hash_do_spice (ctx, i, iterations, _s); } - if (!*r_hash_name (i)) { + if (!*rz_hash_name (i)) { continue; } if (rad == 'j') { @@ -242,7 +242,7 @@ static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int r t = to; for (j = f; j < t; j += bsize) { int nsize = (j + bsize < fsize)? bsize: (fsize - j); - r_io_pread_at (io, j, buf, bsize); + rz_io_pread_at (io, j, buf, bsize); from = j; to = j + bsize; if (to > fsize) { @@ -260,14 +260,14 @@ static int do_hash(const char *file, const char *algo, RIO *io, int bsize, int r printf ("]\n"); } - compare_hashes (ctx, compare, r_hash_size (algobit), &ret); - r_hash_free (ctx); + compare_hashes (ctx, compare, rz_hash_size (algobit), &ret); + rz_hash_free (ctx); free (buf); return ret; } static int do_help(int line) { - printf ("Usage: rahash2 [-rBhLkv] [-b S] [-a A] [-c H] [-E A] [-s S] [-f O] [-t O] [file] ...\n"); + printf ("Usage: rz-hash [-rBhLkv] [-b S] [-a A] [-c H] [-E A] [-s S] [-f O] [-t O] [file] ...\n"); if (line) { return 0; } @@ -300,7 +300,7 @@ static void algolist(void) { ut64 i; for (i = 0; i < R_HASH_NBITS; i++) { bits = 1ULL << i; - const char *name = r_hash_name (bits); + const char *name = rz_hash_name (bits); if (name && *name) { printf ("h %s\n", name); } @@ -311,7 +311,7 @@ static void algolist(void) { printf ("e punycode\n"); for (i = 0;; i++) { bits = ((ut64) 1) << i; - const char *name = r_crypto_name (bits); + const char *name = rz_crypto_name (bits); if (!name || !*name) { break; } @@ -336,22 +336,22 @@ static bool is_power_of_two(const ut64 x) { static int encrypt_or_decrypt(const char *algo, int direction, const char *hashstr, int hashstr_len, const ut8 *iv, int ivlen, int mode) { bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo); // TODO: generalise this for all non key encoding/decoding. if (no_key_mode || s.len > 0) { - RCrypto *cry = r_crypto_new (); - if (r_crypto_use (cry, algo)) { - if (r_crypto_set_key (cry, s.buf, s.len, 0, direction)) { + RzCrypto *cry = rz_crypto_new (); + if (rz_crypto_use (cry, algo)) { + if (rz_crypto_set_key (cry, s.buf, s.len, 0, direction)) { const char *buf = hashstr; int buflen = hashstr_len; - if (iv && !r_crypto_set_iv (cry, iv, ivlen)) { + if (iv && !rz_crypto_set_iv (cry, iv, ivlen)) { eprintf ("Invalid IV.\n"); return 0; } - r_crypto_update (cry, (const ut8 *) buf, buflen); - r_crypto_final (cry, NULL, 0); + rz_crypto_update (cry, (const ut8 *) buf, buflen); + rz_crypto_final (cry, NULL, 0); int result_size = 0; - ut8 *result = r_crypto_get_output (cry, &result_size); + ut8 *result = rz_crypto_get_output (cry, &result_size); if (result) { if (write (1, result, result_size) != result_size) { eprintf ("Warning: cannot write result\n"); @@ -365,7 +365,7 @@ static int encrypt_or_decrypt(const char *algo, int direction, const char *hashs } else { eprintf ("Unknown %s algorithm '%s'\n", ((!direction)? "encryption": "decryption"), algo); } - r_crypto_free (cry); + rz_crypto_free (cry); } else { eprintf ("%s key not defined. Use -S [key]\n", ((!direction)? "Encryption": "Decryption")); } @@ -375,34 +375,34 @@ static int encrypt_or_decrypt(const char *algo, int direction, const char *hashs static int encrypt_or_decrypt_file(const char *algo, int direction, const char *filename, const ut8 *iv, int ivlen, int mode) { bool no_key_mode = !strcmp ("base64", algo) || !strcmp ("base91", algo) || !strcmp ("punycode", algo); // TODO: generalise this for all non key encoding/decoding. if (no_key_mode || s.len > 0) { - RCrypto *cry = r_crypto_new (); - if (r_crypto_use (cry, algo)) { - if (r_crypto_set_key (cry, s.buf, s.len, 0, direction)) { + RzCrypto *cry = rz_crypto_new (); + if (rz_crypto_use (cry, algo)) { + if (rz_crypto_set_key (cry, s.buf, s.len, 0, direction)) { size_t file_size; ut8 *buf; if (strcmp (filename, "-") == 0) { int sz; - buf = (ut8 *)r_stdin_slurp (&sz); + buf = (ut8 *)rz_stdin_slurp (&sz); file_size = (size_t)sz; } else { - buf = (ut8 *)r_file_slurp (filename, &file_size); + buf = (ut8 *)rz_file_slurp (filename, &file_size); } if (!buf) { - eprintf ("rahash2: Cannot open '%s'\n", filename); + eprintf ("rz-hash: Cannot open '%s'\n", filename); return -1; } - if (iv && !r_crypto_set_iv (cry, iv, ivlen)) { + if (iv && !rz_crypto_set_iv (cry, iv, ivlen)) { eprintf ("Invalid IV.\n"); free (buf); return 0; } - r_crypto_update (cry, buf, file_size); - r_crypto_final (cry, NULL, 0); + rz_crypto_update (cry, buf, file_size); + rz_crypto_final (cry, NULL, 0); int result_size = 0; - ut8 *result = r_crypto_get_output (cry, &result_size); + ut8 *result = rz_crypto_get_output (cry, &result_size); if (result) { (void)write (1, result, result_size); free (result); @@ -415,14 +415,14 @@ static int encrypt_or_decrypt_file(const char *algo, int direction, const char * } else { eprintf ("Unknown %s algorithm '%s'\n", ((!direction)? "encryption": "decryption"), algo); } - r_crypto_free (cry); + rz_crypto_free (cry); } else { eprintf ("%s key not defined. Use -S [key]\n", ((!direction)? "Encryption": "Decryption")); } return 1; } -R_API int r_main_rahash2(int argc, const char **argv) { +RZ_API int rz_main_rz_hash(int argc, const char **argv) { ut64 i; int ret, c, rad = 0, bsize = 0, numblocks = 0, ule = 0; const char *file = NULL; @@ -441,12 +441,12 @@ R_API int r_main_rahash2(int argc, const char **argv) { int hashstr_hex = 0; size_t bytes_read = 0;// bytes read from stdin ut64 algobit; - RHash *ctx; - RIO *io; + RzHash *ctx; + RzIO *io; - RGetopt opt; - r_getopt_init (&opt, argc, argv, "p:jD:rveE:a:i:I:S:s:x:b:nBhf:t:kLqc:"); - while ((c = r_getopt_next (&opt)) != -1) { + RzGetopt opt; + rz_getopt_init (&opt, argc, argv, "p:jD:rveE:a:i:I:S:s:x:b:nBhf:t:kLqc:"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'q': quiet++; break; case 'i': @@ -469,10 +469,10 @@ R_API int r_main_rahash2(int argc, const char **argv) { case 'p': ptype = opt.arg; break; case 'a': algo = opt.arg; break; case 'B': incremental = false; break; - case 'b': bsize = (int) r_num_math (NULL, opt.arg); break; - case 'f': from = r_num_math (NULL, opt.arg); break; - case 't': to = 1 + r_num_math (NULL, opt.arg); break; - case 'v': return r_main_version_print ("rahash2"); + case 'b': bsize = (int) rz_num_math (NULL, opt.arg); break; + case 'f': from = rz_num_math (NULL, opt.arg); break; + case 't': to = 1 + rz_num_math (NULL, opt.arg); break; + case 'v': return rz_main_version_print ("rz_hash"); case 'h': return do_help (0); case 's': setHashString (opt.arg, 0); break; case 'x': setHashString (opt.arg, 1); break; @@ -481,13 +481,13 @@ R_API int r_main_rahash2(int argc, const char **argv) { } } if (encrypt && decrypt) { - eprintf ("rahash2: Option -E and -D are incompatible with each other.\n"); + eprintf ("rz-hash: Option -E and -D are incompatible with each other.\n"); return 1; } if (compareStr) { int compareBin_len; if (bsize && !incremental) { - eprintf ("rahash2: Option -c incompatible with -b and -B options.\n"); + eprintf ("rz-hash: Option -c incompatible with -b and -B options.\n"); return 1; } bool flag = false; @@ -497,29 +497,29 @@ R_API int r_main_rahash2(int argc, const char **argv) { flag = !strcmp (decrypt, "base64") || !strcmp (decrypt, "base91"); } if (flag) { - eprintf ("rahash2: Option -c incompatible with -E base64, -E base91, -D base64 or -D base91 options.\n"); + eprintf ("rz-hash: Option -c incompatible with -E base64, -E base91, -D base64 or -D base91 options.\n"); return 1; } - algobit = r_hash_name_to_bits (algo); + algobit = rz_hash_name_to_bits (algo); // if algobit represents a single algorithm then it's a power of 2 if (!is_power_of_two (algobit)) { - eprintf ("rahash2: Option -c incompatible with multiple algorithms in -a.\n"); + eprintf ("rz-hash: Option -c incompatible with multiple algorithms in -a.\n"); return 1; } compareBin = malloc ((strlen (compareStr) + 1) * 2); if (!compareBin) { return 1; } - compareBin_len = r_hex_str2bin (compareStr, compareBin); + compareBin_len = rz_hex_str2bin (compareStr, compareBin); if (compareBin_len < 1) { - eprintf ("rahash2: Invalid -c hex hash\n"); + eprintf ("rz-hash: Invalid -c hex hash\n"); free (compareBin); return 1; - } else if (compareBin_len != r_hash_size (algobit)) { + } else if (compareBin_len != rz_hash_size (algobit)) { eprintf ( - "rahash2: Given -c hash has %d byte(s) but the selected algorithm returns %d byte(s).\n", + "rz-hash: Given -c hash has %d byte(s) but the selected algorithm returns %d byte(s).\n", compareBin_len, - r_hash_size (algobit)); + rz_hash_size (algobit)); free (compareBin); return 1; } @@ -539,7 +539,7 @@ R_API int r_main_rahash2(int argc, const char **argv) { // TODO: support -f and -t for (i = opt.ind; i < argc; i++) { printf ("%s:\n", argv[i]); - r_sys_cmdf ("r2 -qfnc \"p==%s 100\" \"%s\"", ptype, argv[i]); + rz_sys_cmdf ("r2 -qfnc \"p==%s 100\" \"%s\"", ptype, argv[i]); } return 0; } @@ -550,7 +550,7 @@ R_API int r_main_rahash2(int argc, const char **argv) { strcpy ((char *) iv, ivseed + 2); ivlen = strlen (ivseed + 2); } else { - ivlen = r_hex_str2bin (ivseed, iv); + ivlen = rz_hex_str2bin (ivseed, iv); if (ivlen < 1) { strcpy ((char *) iv, ivseed); ivlen = strlen (ivseed); @@ -576,7 +576,7 @@ R_API int r_main_rahash2(int argc, const char **argv) { } if (hashstr_hex) { ut8 *out = malloc ((strlen (hashstr) + 1) * 2); - hashstr_len = r_hex_str2bin (hashstr, out); + hashstr_len = rz_hex_str2bin (hashstr, out); if (hashstr_len < 1) { eprintf ("Invalid hex string\n"); free (out); @@ -609,7 +609,7 @@ R_API int r_main_rahash2(int argc, const char **argv) { hashstr_len = to - from; hashstr[hashstr_len] = '\0'; if (!bytes_read && !hashstr_hex) { - hashstr_len = r_str_unescape (hashstr); + hashstr_len = rz_str_unescape (hashstr); } if (encrypt) { return encrypt_or_decrypt (encrypt, 0, hashstr, hashstr_len, iv, ivlen, 0); @@ -631,7 +631,7 @@ R_API int r_main_rahash2(int argc, const char **argv) { strsz += s.len; str[strsz] = 0; } - algobit = r_hash_name_to_bits (algo); + algobit = rz_hash_name_to_bits (algo); if (algobit == 0) { eprintf ("Invalid algorithm. See -E, -D maybe?\n"); if (str != hashstr) { @@ -643,12 +643,12 @@ R_API int r_main_rahash2(int argc, const char **argv) { for (i = 1; i < R_HASH_ALL; i <<= 1) { if (algobit & i) { ut64 hashbit = i & algobit; - ctx = r_hash_new (true, hashbit); + ctx = rz_hash_new (true, hashbit); from = 0; to = strsz; do_hash_internal (ctx, hashbit, (const ut8 *) str, strsz, rad, 1, ule); - compare_hashes (ctx, compareBin, r_hash_size (algobit), &ret); - r_hash_free (ctx); + compare_hashes (ctx, compareBin, rz_hash_size (algobit), &ret); + rz_hash_free (ctx); } } if (_s) { @@ -667,12 +667,12 @@ R_API int r_main_rahash2(int argc, const char **argv) { if (numblocks) { bsize = -bsize; } else if (bsize < 0) { - eprintf ("rahash2: Invalid block size\n"); + eprintf ("rz-hash: Invalid block size\n"); free (iv); return 1; } - io = r_io_new (); + io = rz_io_new (); for (ret = 0, i = opt.ind; i < argc; i++) { file = argv[i]; @@ -696,41 +696,41 @@ R_API int r_main_rahash2(int argc, const char **argv) { return rt; } } else { - RIODesc *desc = NULL; + RzIODesc *desc = NULL; if (!strcmp (argv[i], "-")) { int sz = 0; - ut8 *buf = (ut8 *) r_stdin_slurp (&sz); - char *uri = r_str_newf ("malloc://%d", sz); + ut8 *buf = (ut8 *) rz_stdin_slurp (&sz); + char *uri = rz_str_newf ("malloc://%d", sz); if (sz > 0) { - desc = r_io_open_nomap (io, uri, R_PERM_R, 0); + desc = rz_io_open_nomap (io, uri, R_PERM_R, 0); if (!desc) { - eprintf ("rahash2: Cannot open malloc://1024\n"); + eprintf ("rz-hash: Cannot open malloc://1024\n"); free (iv); return 1; } - r_io_pwrite_at (io, 0, buf, sz); + rz_io_pwrite_at (io, 0, buf, sz); } free (uri); } else { - if (r_file_is_directory (argv[i])) { - eprintf ("rahash2: Cannot hash directories\n"); + if (rz_file_is_directory (argv[i])) { + eprintf ("rz-hash: Cannot hash directories\n"); free (iv); return 1; } - desc = r_io_open_nomap (io, argv[i], R_PERM_R, 0); + desc = rz_io_open_nomap (io, argv[i], R_PERM_R, 0); if (!desc) { - eprintf ("rahash2: Cannot open '%s'\n", argv[i]); + eprintf ("rz-hash: Cannot open '%s'\n", argv[i]); free (iv); return 1; } } ret |= do_hash (argv[i], algo, io, bsize, rad, ule, compareBin); to = 0; - r_io_desc_close (desc); + rz_io_desc_close (desc); } } free (hashstr); - r_io_free (io); + rz_io_free (io); free (iv); return ret; diff --git a/libr/main/rarun2.c b/librz/main/rz_run.c similarity index 58% rename from libr/main/rarun2.c rename to librz/main/rz_run.c index 1670048449..75da616ded 100644 --- a/libr/main/rarun2.c +++ b/librz/main/rz_run.c @@ -1,41 +1,41 @@ -/* radare2 - Copyleft 2011-2020 - pancake */ +/* rizin - Copyleft 2011-2020 - pancake */ -#include -#include -#include +#include +#include +#include #if __UNIX__ static void fwd(int sig) { /* do nothing? send kill signal to remote process */ } -static void rarun2_tty(void) { +static void rz_run_tty(void) { /* TODO: Implement in native code */ - r_sys_cmd ("tty"); + rz_sys_cmd ("tty"); close (1); dup2 (2, 1); - r_sys_signal (SIGINT, fwd); + rz_sys_signal (SIGINT, fwd); for (;;) { sleep (1); } } #endif -R_API int r_main_rarun2(int argc, const char **argv) { +RZ_API int rz_main_rz_run(int argc, const char **argv) { RRunProfile *p; int i, ret; if (argc == 1 || !strcmp (argv[1], "-h")) { - printf ("Usage: rarun2 -v|-t|script.rr2 [directive ..]\n"); - printf ("%s", r_run_help ()); + printf ("Usage: rz-run -v|-t|script.rr2 [directive ..]\n"); + printf ("%s", rz_run_help ()); return 1; } if (!strcmp (argv[1], "-v")) { - return r_main_version_print ("rarun2"); + return rz_main_version_print ("rz_run"); } const char *file = argv[1]; if (!strcmp (file, "-t")) { #if __UNIX__ - rarun2_tty (); + rz_run_tty (); return 0; #else eprintf ("Not supported\n"); @@ -43,11 +43,11 @@ R_API int r_main_rarun2(int argc, const char **argv) { #endif } if (*file && !strchr (file, '=')) { - p = r_run_new (file); + p = rz_run_new (file); } else { bool noMoreDirectives = false; int directiveIndex = 0; - p = r_run_new (NULL); + p = rz_run_new (NULL); for (i = *file ? 1 : 2; i < argc; i++) { if (!strcmp (argv[i], "--")) { noMoreDirectives = true; @@ -56,25 +56,25 @@ R_API int r_main_rarun2(int argc, const char **argv) { if (noMoreDirectives) { const char *word = argv[i]; char *line = directiveIndex - ? r_str_newf ("arg%d=%s", directiveIndex, word) - : r_str_newf ("program=%s", word); - r_run_parseline (p, line); + ? rz_str_newf ("arg%d=%s", directiveIndex, word) + : rz_str_newf ("program=%s", word); + rz_run_parseline (p, line); directiveIndex ++; free (line); } else { - r_run_parseline (p, argv[i]); + rz_run_parseline (p, argv[i]); } } } if (!p) { return 1; } - ret = r_run_config_env (p); + ret = rz_run_config_env (p); if (ret) { printf("error while configuring the environment.\n"); return 1; } - ret = r_run_start (p); - r_run_free (p); + ret = rz_run_start (p); + rz_run_free (p); return ret; } diff --git a/libr/main/rasign2.c b/librz/main/rz_sign.c similarity index 62% rename from libr/main/rasign2.c rename to librz/main/rz_sign.c index 7adc59344e..5800e48156 100644 --- a/libr/main/rasign2.c +++ b/librz/main/rz_sign.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include static void rasign_show_help(void) { - printf ("Usage: rasign2 [options] [file]\n" + printf ("Usage: rz-sign [options] [file]\n" " -a [-a] add extra 'a' to analysis command\n" " -f interpret the file as a FLIRT .sig file and dump signatures\n" " -h help menu\n" @@ -14,50 +14,50 @@ static void rasign_show_help(void) { " -s signspace save all signatures under this signspace\n" " -v show version information\n" "Examples:\n" - " rasign2 -o libc.sdb libc.so.6\n"); + " rz_sign -o libc.sdb libc.so.6\n"); } -static RCore *opencore(const char *fname) { - RCoreFile * rfile = NULL; - RCore *c = r_core_new (); +static RzCore *opencore(const char *fname) { + RzCoreFile * rfile = NULL; + RzCore *c = rz_core_new (); if (!c) { eprintf ("Count not get core\n"); return NULL; } - r_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL); - r_config_set_i (c->config, "scr.interactive", false); + rz_core_loadlibs (c, R_CORE_LOADLIBS_ALL, NULL); + rz_config_set_i (c->config, "scr.interactive", false); if (fname) { #if __WINDOWS__ - char *winf = r_acp_to_utf8 (fname); - rfile = r_core_file_open (c, winf, 0, 0); + char *winf = rz_acp_to_utf8 (fname); + rfile = rz_core_file_open (c, winf, 0, 0); free (winf); #else - rfile = r_core_file_open (c, fname, 0, 0); + rfile = rz_core_file_open (c, fname, 0, 0); #endif if (!rfile) { eprintf ("Could not open file %s\n", fname); - r_core_free (c); + rz_core_free (c); return NULL; } - (void)r_core_bin_load (c, NULL, UT64_MAX); - (void)r_core_bin_update_arch_bits (c); - r_cons_flush (); + (void)rz_core_bin_load (c, NULL, UT64_MAX); + (void)rz_core_bin_update_arch_bits (c); + rz_cons_flush (); } return c; } -static void find_functions(RCore *core, size_t count) { +static void find_functions(RzCore *core, size_t count) { const char *cmd = NULL; switch (count) { case 0: cmd = "aa"; break; case 1: cmd = "aaa"; break; case 2: cmd = "aaaa"; break; } - r_core_cmd0 (core, cmd); + rz_core_cmd0 (core, cmd); } -R_API int r_main_rasign2(int argc, const char **argv) { +RZ_API int rz_main_rz_sign(int argc, const char **argv) { const char *ofile = NULL; const char *space = NULL; int c; @@ -66,10 +66,10 @@ R_API int r_main_rasign2(int argc, const char **argv) { bool quiet = false; bool json = false; bool flirt = false; - RGetopt opt; + RzGetopt opt; - r_getopt_init (&opt, argc, argv, "afhjo:qrs:v"); - while ((c = r_getopt_next (&opt)) != -1) { + rz_getopt_init (&opt, argc, argv, "afhjo:qrs:v"); + while ((c = rz_getopt_next (&opt)) != -1) { switch (c) { case 'a': a_cnt++; @@ -93,7 +93,7 @@ R_API int r_main_rasign2(int argc, const char **argv) { flirt = true; break; case 'v': - return r_main_version_print ("rasign2"); + return rz_main_version_print ("rz_sign"); case 'h': rasign_show_help (); return 0; @@ -117,16 +117,16 @@ R_API int r_main_rasign2(int argc, const char **argv) { } ifile = argv[opt.ind]; - RCore *core = NULL; + RzCore *core = NULL; if (flirt) { if (rad || ofile || json) { eprintf ("Only FLIRT output is supported for FLIRT files\n"); return -1; } core = opencore (NULL); - r_sign_flirt_dump (core->anal, ifile); - r_cons_flush (); - r_core_free (core); + rz_sign_flirt_dump (core->anal, ifile); + rz_cons_flush (); + rz_core_free (core); return 0; } else { core = opencore (ifile); @@ -139,34 +139,34 @@ R_API int r_main_rasign2(int argc, const char **argv) { // quiet mode if (quiet) { - r_config_set (core->config, "scr.interactive", "false"); - r_config_set (core->config, "scr.prompt", "false"); - r_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); + rz_config_set (core->config, "scr.interactive", "false"); + rz_config_set (core->config, "scr.prompt", "false"); + rz_config_set_i (core->config, "scr.color", COLOR_MODE_DISABLED); } if (space) { - r_spaces_set (&core->anal->zign_spaces, space); + rz_spaces_set (&core->anal->zign_spaces, space); } // run analysis to find functions find_functions (core, a_cnt); // create zignatures - r_core_cmd0 (core, "zg"); + rz_core_cmd0 (core, "zg"); // write sigs to file if (ofile) { - r_core_cmdf (core, "\"zos %s\"", ofile); + rz_core_cmdf (core, "\"zos %s\"", ofile); } if (rad) { - r_core_flush (core, "z*"); + rz_core_flush (core, "z*"); } if (json) { - r_core_flush (core, "zj"); + rz_core_flush (core, "zj"); } - r_core_free (core); + rz_core_free (core); return 0; } diff --git a/libr/meson.build b/librz/meson.build similarity index 59% rename from libr/meson.build rename to librz/meson.build index f989fddfe1..ab84763c51 100644 --- a/libr/meson.build +++ b/librz/meson.build @@ -252,7 +252,7 @@ fs_plugins = [ 'minix', 'ntfs', 'posix', - 'r2', + 'rz', 'reiserfs', 'sfs', 'tar', @@ -281,9 +281,9 @@ io_plugins = [ 'procpid', 'ptrace', 'qnx', - 'r2k', - 'r2pipe', - 'r2web', + 'rzk', + 'rzpipe', + 'rzweb', 'rap', 'rbuf', 'self', @@ -337,117 +337,117 @@ parse_plugins = [ ] include_files =[ - 'include/r2naked.h', - 'include/r_agraph.h', - 'include/r_anal.h', - 'include/r_asm.h', - 'include/r_bind.h', - 'include/r_getopt.h', - 'include/r_bin_dwarf.h', - 'include/r_bin.h', - 'include/r_binheap.h', - 'include/r_bp.h', - 'include/r_cmd.h', - 'include/r_config.h', - 'include/r_cons.h', - 'include/r_core.h', - 'include/r_crypto.h', - 'include/r_debug.h', - 'include/r_diff.h', - 'include/r_egg.h', - 'include/r_main.h', - 'include/r_endian.h', - 'include/r_flag.h', - 'include/r_flist.h', - 'include/r_fs.h', - 'include/r_hash.h', - 'include/r_heap_glibc.h', - 'include/r_heap_jemalloc.h', - 'include/r_io.h', - 'include/r_lang.h', - 'include/r_lib.h', - 'include/r_list.h', - 'include/r_magic.h', - 'include/r_parse.h', - 'include/r_pdb.h', - 'include/r_qrcode.h', - 'include/r_regex.h', - 'include/r_reg.h', - 'include/r_search.h', - 'include/r_sign.h', - 'include/r_skiplist.h', - 'include/r_socket.h', - 'include/r_syscall.h', - 'include/r_th.h', - 'include/r_types_overflow.h', - 'include/r_types_base.h', - 'include/r_types.h', - 'include/r_util.h', - 'include/r_vector.h', + 'include/rznaked.h', + 'include/rz_agraph.h', + 'include/rz_anal.h', + 'include/rz_asm.h', + 'include/rz_bind.h', + 'include/rz_getopt.h', + 'include/rz_bin_dwarf.h', + 'include/rz_bin.h', + 'include/rz_binheap.h', + 'include/rz_bp.h', + 'include/rz_cmd.h', + 'include/rz_config.h', + 'include/rz_cons.h', + 'include/rz_core.h', + 'include/rz_crypto.h', + 'include/rz_debug.h', + 'include/rz_diff.h', + 'include/rz_egg.h', + 'include/rz_main.h', + 'include/rz_endian.h', + 'include/rz_flag.h', + 'include/rz_flist.h', + 'include/rz_fs.h', + 'include/rz_hash.h', + 'include/rz_heap_glibc.h', + 'include/rz_heap_jemalloc.h', + 'include/rz_io.h', + 'include/rz_lang.h', + 'include/rz_lib.h', + 'include/rz_list.h', + 'include/rz_magic.h', + 'include/rz_parse.h', + 'include/rz_pdb.h', + 'include/rz_qrcode.h', + 'include/rz_regex.h', + 'include/rz_reg.h', + 'include/rz_search.h', + 'include/rz_sign.h', + 'include/rz_skiplist.h', + 'include/rz_socket.h', + 'include/rz_syscall.h', + 'include/rz_th.h', + 'include/rz_types_overflow.h', + 'include/rz_types_base.h', + 'include/rz_types.h', + 'include/rz_util.h', + 'include/rz_vector.h', ] install_headers(include_files, install_dir: r2_incdir) -r_util_files = [ - 'include/r_util/pj.h', - 'include/r_util/r_ascii_table.h', - 'include/r_util/r_asn1.h', - 'include/r_util/r_assert.h', - 'include/r_util/r_protobuf.h', - 'include/r_util/r_base64.h', - 'include/r_util/r_base91.h', - 'include/r_util/r_big.h', - 'include/r_util/r_bitmap.h', - 'include/r_util/r_buf.h', - 'include/r_util/r_cache.h', - 'include/r_util/r_ctypes.h', - 'include/r_util/r_debruijn.h', - 'include/r_util/r_event.h', - 'include/r_util/r_file.h', - 'include/r_util/r_graph.h', - 'include/r_util/r_hex.h', - 'include/r_util/r_idpool.h', - 'include/r_util/r_itv.h', - 'include/r_util/r_json.h', - 'include/r_util/r_log.h', - 'include/r_util/r_mem.h', - 'include/r_util/r_name.h', - 'include/r_util/r_num.h', - 'include/r_util/r_panels.h', - 'include/r_util/r_table.h', - 'include/r_util/r_pkcs7.h', - 'include/r_util/r_pool.h', - 'include/r_util/r_print.h', - 'include/r_util/r_punycode.h', - 'include/r_util/r_queue.h', - 'include/r_util/r_range.h', - 'include/r_util/r_rbtree.h', - 'include/r_util/r_intervaltree.h', - 'include/r_util/r_sandbox.h', - 'include/r_util/r_signal.h', - 'include/r_util/r_spaces.h', - 'include/r_util/r_stack.h', - 'include/r_util/r_strbuf.h', - 'include/r_util/r_str.h', - 'include/r_util/r_strpool.h', - 'include/r_util/r_str_constpool.h', - 'include/r_util/r_str_util.h', - 'include/r_util/r_sys.h', - 'include/r_util/r_alloc.h', - 'include/r_util/r_time.h', - 'include/r_util/r_tree.h', - 'include/r_util/r_uleb128.h', - 'include/r_util/r_utf16.h', - 'include/r_util/r_utf32.h', - 'include/r_util/r_utf8.h', - 'include/r_util/r_x509.h', - 'include/r_util/r_annotated_code.h' +rz_util_files = [ + 'include/rz_util/pj.h', + 'include/rz_util/rz_ascii_table.h', + 'include/rz_util/rz_asn1.h', + 'include/rz_util/rz_assert.h', + 'include/rz_util/rz_protobuf.h', + 'include/rz_util/rz_base64.h', + 'include/rz_util/rz_base91.h', + 'include/rz_util/rz_big.h', + 'include/rz_util/rz_bitmap.h', + 'include/rz_util/rz_buf.h', + 'include/rz_util/rz_cache.h', + 'include/rz_util/rz_ctypes.h', + 'include/rz_util/rz_debruijn.h', + 'include/rz_util/rz_event.h', + 'include/rz_util/rz_file.h', + 'include/rz_util/rz_graph.h', + 'include/rz_util/rz_hex.h', + 'include/rz_util/rz_idpool.h', + 'include/rz_util/rz_itv.h', + 'include/rz_util/rz_json.h', + 'include/rz_util/rz_log.h', + 'include/rz_util/rz_mem.h', + 'include/rz_util/rz_name.h', + 'include/rz_util/rz_num.h', + 'include/rz_util/rz_panels.h', + 'include/rz_util/rz_table.h', + 'include/rz_util/rz_pkcs7.h', + 'include/rz_util/rz_pool.h', + 'include/rz_util/rz_print.h', + 'include/rz_util/rz_punycode.h', + 'include/rz_util/rz_queue.h', + 'include/rz_util/rz_range.h', + 'include/rz_util/rz_rbtree.h', + 'include/rz_util/rz_intervaltree.h', + 'include/rz_util/rz_sandbox.h', + 'include/rz_util/rz_signal.h', + 'include/rz_util/rz_spaces.h', + 'include/rz_util/rz_stack.h', + 'include/rz_util/rz_strbuf.h', + 'include/rz_util/rz_str.h', + 'include/rz_util/rz_strpool.h', + 'include/rz_util/rz_str_constpool.h', + 'include/rz_util/rz_str_util.h', + 'include/rz_util/rz_sys.h', + 'include/rz_util/rz_alloc.h', + 'include/rz_util/rz_time.h', + 'include/rz_util/rz_tree.h', + 'include/rz_util/rz_uleb128.h', + 'include/rz_util/rz_utf16.h', + 'include/rz_util/rz_utf32.h', + 'include/rz_util/rz_utf8.h', + 'include/rz_util/rz_x509.h', + 'include/rz_util/rz_annotated_code.h' ] -install_headers(r_util_files, install_dir: join_paths(r2_incdir, 'r_util')) +install_headers(rz_util_files, install_dir: join_paths(r2_incdir, 'rz_util')) -r_crypto_files = [ - 'include/r_crypto/r_des.h' +rz_crypto_files = [ + 'include/rz_crypto/rz_des.h' ] -install_headers(r_crypto_files, install_dir: join_paths(r2_incdir, 'r_crypto')) +install_headers(rz_crypto_files, install_dir: join_paths(r2_incdir, 'rz_crypto')) sflib_common_files = [ 'include/sflib/common/sftypes.h', diff --git a/libr/parse/Makefile b/librz/parse/Makefile similarity index 70% rename from libr/parse/Makefile rename to librz/parse/Makefile index af1eab3c2b..ac308ad63c 100644 --- a/libr/parse/Makefile +++ b/librz/parse/Makefile @@ -1,11 +1,11 @@ include ../config.mk -NAME=r_parse -R2DEPS=r_flag r_util r_syscall r_reg +NAME=rz_parse +R2DEPS=rz_flag rz_util rz_syscall rz_reg # indirect dependencies -R2DEPS+=r_cons +R2DEPS+=rz_cons -LINK+=$(STOP)/tcc/libr_tcc.a +LINK+=$(STOP)/tcc/librz_tcc.a CFLAGS+=-I$(STOP)/tcc/ LINK+=$(STOP)/mpc/libmpc.a @@ -14,8 +14,8 @@ CFLAGS+=-I$(STOP)/mpc/ include $(SHLR)/zip/deps.mk foo: - @for TARGET in pre libr_parse.${EXT_SO} \ - libr_parse.${EXT_AR} plugins bins ; do \ + @for TARGET in pre librz_parse.${EXT_SO} \ + librz_parse.${EXT_AR} plugins bins ; do \ ${MAKE} $$TARGET ; done CFLAGS+=-DR2_PLUGIN_INCORE diff --git a/libr/parse/code.c b/librz/parse/code.c similarity index 87% rename from libr/parse/code.c rename to librz/parse/code.c index 342d665f50..bdc3744e44 100644 --- a/libr/parse/code.c +++ b/librz/parse/code.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2013-2019 - pancake */ -#include "r_util.h" -#include "r_types.h" -#include "r_parse.h" -#include "libr_tcc.h" +#include "rz_util.h" +#include "rz_types.h" +#include "rz_parse.h" +#include "librz_tcc.h" /* parse C code and return it in key-value form */ @@ -28,8 +28,8 @@ static bool __typeLoad(void *p, const char *k, const char *v) { return false; } int btype = 0; - RAnal *anal = (RAnal*)p; - //r_cons_printf ("tk %s=%s\n", k, v); + RzAnal *anal = (RzAnal*)p; + //rz_cons_printf ("tk %s=%s\n", k, v); // TODO: Add unions support if (!strncmp (v, "struct", 6) && strncmp (k, "struct.", 7)) { // structure @@ -91,7 +91,7 @@ static void __errorFunc(void *opaque, const char *msg) { } } -R_API char *r_parse_c_file(RAnal *anal, const char *path, const char *dir, char **error_msg) { +RZ_API char *rz_parse_c_file(RzAnal *anal, const char *path, const char *dir, char **error_msg) { char *str = NULL; TCCState *T = tcc_new (anal->cpu, anal->bits, anal->os); if (!T) { @@ -108,7 +108,7 @@ R_API char *r_parse_c_file(RAnal *anal, const char *path, const char *dir, char return str; } -R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg) { +RZ_API char *rz_parse_c_string(RzAnal *anal, const char *code, char **error_msg) { char *str = NULL; TCCState *T = tcc_new (anal->cpu, anal->bits, anal->os); if (!T) { @@ -126,6 +126,6 @@ R_API char *r_parse_c_string(RAnal *anal, const char *code, char **error_msg) { } // XXX do not use globals -R_API void r_parse_c_reset(RParse *p) { +RZ_API void rz_parse_c_reset(RzParse *p) { anon_sym = SYM_FIRST_ANOM; } diff --git a/libr/parse/ctype.c b/librz/parse/ctype.c similarity index 85% rename from libr/parse/ctype.c rename to librz/parse/ctype.c index c31e39daa3..b501488fbd 100644 --- a/libr/parse/ctype.c +++ b/librz/parse/ctype.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2019 - thestr4ng3r */ -#include +#include #include -struct r_parse_ctype_t { +struct rz_parse_ctype_t { mpc_parser_t *integerlit; mpc_parser_t *identifier; mpc_parser_t *qualifier; @@ -25,8 +25,8 @@ static const char *lang = "type : ? ( | )*;"; -R_API RParseCType *r_parse_ctype_new(void) { - RParseCType *ctype = R_NEW (RParseCType); +RZ_API RzParseCType *rz_parse_ctype_new(void) { + RzParseCType *ctype = R_NEW (RzParseCType); if (!ctype) { return NULL; } @@ -42,14 +42,14 @@ R_API RParseCType *r_parse_ctype_new(void) { if (err) { mpc_err_print (err); mpc_err_delete (err); - r_parse_ctype_free (ctype); + rz_parse_ctype_free (ctype); return NULL; } return ctype; } -R_API void r_parse_ctype_free(RParseCType *ctype) { +RZ_API void rz_parse_ctype_free(RzParseCType *ctype) { if (!ctype) { return; } @@ -105,9 +105,9 @@ static bool is_array(mpc_ast_t *a) { && strcmp (a->children[2]->contents, "]") == 0; } -static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { +static RzParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { bool is_const = false; - RParseCTypeType *cur = NULL; + RzParseCTypeType *cur = NULL; int i; for (i = 0; i < a->children_num; i++) { mpc_ast_t *child = a->children[i]; @@ -118,12 +118,12 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { } // (struct|union|enum)? - else if (r_str_startswith (child->tag, "identifier|")) { + else if (rz_str_startswith (child->tag, "identifier|")) { if (cur) { // identifier should always be the innermost type goto beach; } - cur = R_NEW0 (RParseCTypeType); + cur = R_NEW0 (RzParseCTypeType); if (!cur) { goto beach; } @@ -156,7 +156,7 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { // identifier should always be the innermost type goto beach; } - cur = R_NEW0 (RParseCTypeType); + cur = R_NEW0 (RzParseCTypeType); if (!cur) { goto beach; } @@ -172,7 +172,7 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { // * else if (is_non_const_pointer (child)) { - RParseCTypeType *pointer = R_NEW0 (RParseCTypeType); + RzParseCTypeType *pointer = R_NEW0 (RzParseCTypeType); if (!pointer) { goto beach; } @@ -184,7 +184,7 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { // const * else if (is_const_pointer (child)) { - RParseCTypeType *pointer = R_NEW0 (RParseCTypeType); + RzParseCTypeType *pointer = R_NEW0 (RzParseCTypeType); if (!pointer) { goto beach; } @@ -196,7 +196,7 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { // else if (is_array (child)) { - RParseCTypeType *array = R_NEW0 (RParseCTypeType); + RzParseCTypeType *array = R_NEW0 (RzParseCTypeType); if (!array) { goto beach; } @@ -213,14 +213,14 @@ static RParseCTypeType *ctype_convert_ast(mpc_ast_t *a) { return cur; beach: - r_parse_ctype_type_free (cur); + rz_parse_ctype_type_free (cur); return NULL; } -R_API RParseCTypeType *r_parse_ctype_parse(RParseCType *ctype, const char *str, char **error) { +RZ_API RzParseCTypeType *rz_parse_ctype_parse(RzParseCType *ctype, const char *str, char **error) { mpc_result_t r; if (mpc_parse ("", str, ctype->type, &r)) { - RParseCTypeType *ret = ctype_convert_ast (r.output); + RzParseCTypeType *ret = ctype_convert_ast (r.output); if (error) { *error = !ret ? strdup ("internal error") : NULL; } @@ -235,7 +235,7 @@ R_API RParseCTypeType *r_parse_ctype_parse(RParseCType *ctype, const char *str, } } -R_API void r_parse_ctype_type_free(RParseCTypeType *type) { +RZ_API void rz_parse_ctype_type_free(RzParseCTypeType *type) { if (!type) { return; } @@ -244,10 +244,10 @@ R_API void r_parse_ctype_type_free(RParseCTypeType *type) { free (type->identifier.name); break; case R_PARSE_CTYPE_TYPE_KIND_POINTER: - r_parse_ctype_type_free (type->pointer.type); + rz_parse_ctype_type_free (type->pointer.type); break; case R_PARSE_CTYPE_TYPE_KIND_ARRAY: - r_parse_ctype_type_free (type->array.type); + rz_parse_ctype_type_free (type->array.type); break; } free (type); diff --git a/libr/parse/filter.c b/librz/parse/filter.c similarity index 83% rename from libr/parse/filter.c rename to librz/parse/filter.c index fe2ed640b8..a3179f5d85 100644 --- a/libr/parse/filter.c +++ b/librz/parse/filter.c @@ -1,9 +1,9 @@ -/* radare2 - LGPL - Copyright 2009-2019 - nibble, pancake, maijin */ +/* rizin - LGPL - Copyright 2009-2019 - nibble, pancake, maijin */ #include -#include -#include +#include +#include #include #define isx86separator(x) ( \ @@ -11,7 +11,7 @@ (x)==','||(x)==';'||(x)=='['||(x)==']'|| \ (x)=='('||(x)==')'||(x)=='{'||(x)=='}'||(x)=='\x1b') -static bool isvalidflag(RFlagItem *flag) { +static bool isvalidflag(RzFlagItem *flag) { if (flag) { if (strstr (flag->name, "main") || strstr (flag->name, "entry")) { return true; @@ -38,7 +38,7 @@ static void insert(char *dst, const char *src) { free (endNum); } -// TODO: move into r_util/r_str +// TODO: move into rz_util/rz_str static void replaceWords(char *s, const char *k, const char *v) { for (;;) { char *p = strstr (s, k); @@ -116,14 +116,14 @@ static char *findNextNumber(char *op) { return NULL; } -static void __replaceRegisters(RReg *reg, char *s, bool x86) { +static void __replaceRegisters(RzReg *reg, char *s, bool x86) { int i; for (i = 0; i < 64; i++) { - const char *k = r_reg_get_name (reg, i); + const char *k = rz_reg_get_name (reg, i); if (!k || i == R_REG_NAME_PC) { continue; } - const char *v = r_reg_get_role (i); + const char *v = rz_reg_get_role (i); if (!v) { break; } @@ -138,10 +138,10 @@ static void __replaceRegisters(RReg *reg, char *s, bool x86) { } } -static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) { +static bool filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalHint *hint, char *data, char *str, int len, bool big_endian) { char *ptr = data, *ptr2, *ptr_backup; - RAnalFunction *fcn; - RFlagItem *flag; + RzAnalFunction *fcn; + RzFlagItem *flag; ut64 off; bool x86 = false; bool arm = false; @@ -184,7 +184,7 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, ; } } - off = r_num_math (NULL, ptr); + off = rz_num_math (NULL, ptr); if (off >= p->minval) { fcn = p->analb.get_fcn_in (p->analb.anal, off, 0); if (fcn && fcn->addr == off) { @@ -207,8 +207,8 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, return true; } if (f) { - RFlagItem *flag2; - bool lea = x86 && r_str_startswith (data, "lea") + RzFlagItem *flag2; + bool lea = x86 && rz_str_startswith (data, "lea") && (data[3] == ' ' || data[3] == 0x1b); bool remove_brackets = false; flag = p->flag_get (f, off); @@ -220,7 +220,7 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, } } if (flag && !strncmp (flag->name, "section.", 8)) { - flag = r_flag_get_i (f, off); + flag = rz_flag_get_i (f, off); } const char *label = fcn? p->label_get (fcn, off): NULL; if (label || isvalidflag (flag)) { @@ -252,14 +252,14 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, *ptr = 0; char *flagname; if (label) { - flagname = r_str_newf (".%s", label); + flagname = rz_str_newf (".%s", label); } else { flagname = strdup (f->realnames? flag->realname : flag->name); } int maxflagname = p->maxflagnamelen; if (maxflagname > 0 && strlen (flagname) > maxflagname) { - char *doublelower = (char *)r_str_rstr (flagname, "__"); - char *doublecolon = (char *)r_str_rstr (flagname, "::"); + char *doublelower = (char *)rz_str_rstr (flagname, "__"); + char *doublecolon = (char *)rz_str_rstr (flagname, "::"); char *token = NULL; if (doublelower && doublecolon) { token = R_MAX (doublelower, doublecolon); @@ -268,16 +268,16 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, } if (token) { const char *mod = doublecolon? "(cxx)": "(...)"; - char *newstr = r_str_newf ("%s%s", mod, token); + char *newstr = rz_str_newf ("%s%s", mod, token); free (flagname); flagname = newstr; } else { - const char *lower = r_str_rstr (flagname, "_"); + const char *lower = rz_str_rstr (flagname, "_"); char *newstr; if (lower) { - newstr = r_str_newf ("..%s", lower + 1); + newstr = rz_str_newf ("..%s", lower + 1); } else { - newstr = r_str_newf ("..%s", flagname + (strlen (flagname) - maxflagname)); + newstr = rz_str_newf ("..%s", flagname + (strlen (flagname) - maxflagname)); } free (flagname); flagname = newstr; @@ -358,7 +358,7 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, if (off == addr) { insert (ptr, "$$"); } else { - ut64 tail = r_num_tail_base (NULL, addr, off); + ut64 tail = rz_num_tail_base (NULL, addr, off); if (tail != UT64_MAX) { char str[128]; snprintf (str, sizeof (str), "..%"PFMT64x, tail); @@ -456,7 +456,7 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, *pnum = '\0'; break; case 2: - r_num_to_bits (num, off); + rz_num_to_bits (num, off); strcat (num, "b"); break; case 3: @@ -466,14 +466,14 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, swap = off & 0xffff; } else { if (off >> 32) { - r_mem_swapendian ((ut8*)&swap, (const ut8*)&off, sizeof (off)); + rz_mem_swapendian ((ut8*)&swap, (const ut8*)&off, sizeof (off)); } else if (off >> 16) { ut32 port = 0; - r_mem_swapendian ((ut8*)&port, (const ut8*)&off, sizeof (port)); + rz_mem_swapendian ((ut8*)&port, (const ut8*)&off, sizeof (port)); swap = port; } else { ut16 port = 0; - r_mem_swapendian ((ut8*)&port, (const ut8*)&off, sizeof (port)); + rz_mem_swapendian ((ut8*)&port, (const ut8*)&off, sizeof (port)); swap = port; } } @@ -485,12 +485,12 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, break; case 10: { - RList *regs = r_reg_get_list (p->analb.anal->reg, R_REG_TYPE_GPR); - RRegItem *reg; - RListIter *iter; + RzList *regs = rz_reg_get_list (p->analb.anal->reg, R_REG_TYPE_GPR); + RzRegItem *reg; + RzListIter *iter; bool imm32 = false; - r_list_foreach (regs, iter, reg) { - if (reg->size == 32 && r_str_casestr (data, reg->name)) { + rz_list_foreach (regs, iter, reg) { + if (reg->size == 32 && rz_str_casestr (data, reg->name)) { imm32 = true; break; } @@ -514,8 +514,8 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, break; case 80: if (p && p->analb.anal && p->analb.anal->syscall) { - RSyscallItem *si; - si = r_syscall_get (p->analb.anal->syscall, off, -1); + RzSyscallItem *si; + si = rz_syscall_get (p->analb.anal->syscall, off, -1); if (si) { snprintf (num, sizeof (num), "%s()", si->name); } else { @@ -546,10 +546,10 @@ static bool filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, /// filter the opcode in data into str by following the flags and hints information // XXX this function have too many parameters, we need to simplify this // XXX too many arguments here -// TODO we shouhld use RCoreBind and use the hintGet/flagGet methods, but we can also have rflagbind+ranalbind, but kiss pls -// TODO: NEW SIGNATURE: R_API char *r_parse_filter(RParse *p, ut64 addr, const char *str) +// TODO we shouhld use RzCoreBind and use the hintGet/flagGet methods, but we can also have rflagbind+ranalbind, but kiss pls +// TODO: NEW SIGNATURE: RZ_API char *rz_parse_filter(RzParse *p, ut64 addr, const char *str) // DEPRECATE -R_API bool r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char *data, char *str, int len, bool big_endian) { +RZ_API bool rz_parse_filter(RzParse *p, ut64 addr, RzFlag *f, RzAnalHint *hint, char *data, char *str, int len, bool big_endian) { filter (p, addr, f, hint, data, str, len, big_endian); if (p->cur && p->cur->filter) { return p->cur->filter (p, addr, f, data, str, len, big_endian); @@ -557,12 +557,12 @@ R_API bool r_parse_filter(RParse *p, ut64 addr, RFlag *f, RAnalHint *hint, char return false; } -// easier to use, should replace r_parse_filter(), but its not using rflag, analhint, endian, etc -R_API char *r_parse_filter_dup(RParse *p, ut64 addr, const char *opstr) { +// easier to use, should replace rz_parse_filter(), but its not using rflag, analhint, endian, etc +RZ_API char *rz_parse_filter_dup(RzParse *p, ut64 addr, const char *opstr) { const size_t out_len = 256; char *in = strdup (opstr); char *out = calloc (out_len, 1); - if (!r_parse_filter (p, addr, NULL, NULL, in, out, out_len, false)) { + if (!rz_parse_filter (p, addr, NULL, NULL, in, out, out_len, false)) { free (out); return NULL; } diff --git a/libr/parse/meson.build b/librz/parse/meson.build similarity index 69% rename from libr/parse/meson.build rename to librz/parse/meson.build index bacb34eed0..7be31b715e 100644 --- a/libr/parse/meson.build +++ b/librz/parse/meson.build @@ -1,4 +1,4 @@ -r_parse_sources = [ +rz_parse_sources = [ 'code.c', 'filter.c', 'parse.c', @@ -20,15 +20,15 @@ r_parse_sources = [ 'p/parse_z80_pseudo.c' ] -r_parse = library('r_parse', r_parse_sources, +rz_parse = library('rz_parse', rz_parse_sources, include_directories: platform_inc, c_args: library_cflags, dependencies: [ - r_util_dep, - r_flag_dep, - r_syscall_dep, - r_reg_dep, - r_cons_dep, + rz_util_dep, + rz_flag_dep, + rz_syscall_dep, + rz_reg_dep, + rz_cons_dep, tcc_dep, mpc_dep ], @@ -38,21 +38,21 @@ r_parse = library('r_parse', r_parse_sources, soversion: r2_libversion ) -r_parse_dep = declare_dependency(link_with: r_parse, +rz_parse_dep = declare_dependency(link_with: rz_parse, include_directories: platform_inc) -pkgconfig_mod.generate(r_parse, - subdirs: 'libr', +pkgconfig_mod.generate(rz_parse, + subdirs: 'librz', version: r2_version, - name: 'r_parse', - filebase: 'r_parse', + name: 'rz_parse', + filebase: 'rz_parse', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util', - 'r_flag', - 'r_cons', - 'r_syscall', - 'r_reg' + 'rz_util', + 'rz_flag', + 'rz_cons', + 'rz_syscall', + 'rz_reg' ], description: 'radare foundation libraries' ) diff --git a/libr/parse/p/6502_pseudo.mk b/librz/parse/p/6502_pseudo.mk similarity index 74% rename from libr/parse/p/6502_pseudo.mk rename to librz/parse/p/6502_pseudo.mk index 80ae0bec9c..7431b13a29 100644 --- a/libr/parse/p/6502_pseudo.mk +++ b/librz/parse/p/6502_pseudo.mk @@ -3,11 +3,11 @@ OBJ_6502PSEUDO+=parse_6502_pseudo.o TARGET_6502PSEUDO=parse_6502_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_6502PSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/p/Makefile b/librz/parse/p/Makefile similarity index 100% rename from libr/parse/p/Makefile rename to librz/parse/p/Makefile diff --git a/libr/parse/p/arm_pseudo.mk b/librz/parse/p/arm_pseudo.mk similarity index 73% rename from libr/parse/p/arm_pseudo.mk rename to librz/parse/p/arm_pseudo.mk index 7624c9f6d2..a30cb4605d 100644 --- a/libr/parse/p/arm_pseudo.mk +++ b/librz/parse/p/arm_pseudo.mk @@ -3,11 +3,11 @@ OBJ_ARMPSEUDO+=parse_arm_pseudo.o TARGET_ARMPSEUDO=parse_arm_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_ARMPSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/p/att2intel.mk b/librz/parse/p/att2intel.mk similarity index 85% rename from libr/parse/p/att2intel.mk rename to librz/parse/p/att2intel.mk index b9dcaaa8c2..1271b67d19 100644 --- a/libr/parse/p/att2intel.mk +++ b/librz/parse/p/att2intel.mk @@ -7,6 +7,6 @@ ifeq ($(WITHPIC),1) ALL_TARGETS+=${TARGET_ATTINTEL} ${TARGET_ATTINTEL}: ${OBJ_ATTINTEL} ${CC} $(call libname,parse_att2intel) ${LINK} \ - -L.. -L../../util -lr_util $(LDFLAGS_SHARED) \ + -L.. -L../../util -lrz_util $(LDFLAGS_SHARED) \ ${CFLAGS} -o ${TARGET_ATTINTEL} ${OBJ_ATTINTEL} endif diff --git a/libr/parse/p/avr_pseudo.mk b/librz/parse/p/avr_pseudo.mk similarity index 72% rename from libr/parse/p/avr_pseudo.mk rename to librz/parse/p/avr_pseudo.mk index fed23a9f2a..d616b9c665 100644 --- a/libr/parse/p/avr_pseudo.mk +++ b/librz/parse/p/avr_pseudo.mk @@ -6,9 +6,9 @@ STATIC_OBJ+=${OBJ_AVRPSEUDO} ${TARGET_AVRPSEUDO}: ${OBJ_AVRPSEUDO} ifeq ($(CC),cccl) - ${CC} $(call libname,parse_avr_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_avr_pseudo) -L../../util -llibrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_AVRPSEUDO} ${OBJ_AVRPSEUDO} else - ${CC} $(call libname,parse_avr_pseudo) -L../../util -lr_util \ + ${CC} $(call libname,parse_avr_pseudo) -L../../util -lrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_AVRPSEUDO} ${OBJ_AVRPSEUDO} $(LINK) endif diff --git a/libr/parse/p/chip8_pseudo.mk b/librz/parse/p/chip8_pseudo.mk similarity index 74% rename from libr/parse/p/chip8_pseudo.mk rename to librz/parse/p/chip8_pseudo.mk index cc579a0d43..63b37cf549 100644 --- a/libr/parse/p/chip8_pseudo.mk +++ b/librz/parse/p/chip8_pseudo.mk @@ -3,11 +3,11 @@ OBJ_CHIP8PSEUDO+=parse_chip8_pseudo.o TARGET_CHIP8PSEUDO=parse_chip8_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_CHIP8PSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/p/dalvik_pseudo.mk b/librz/parse/p/dalvik_pseudo.mk similarity index 80% rename from libr/parse/p/dalvik_pseudo.mk rename to librz/parse/p/dalvik_pseudo.mk index 877005366e..2040315187 100644 --- a/libr/parse/p/dalvik_pseudo.mk +++ b/librz/parse/p/dalvik_pseudo.mk @@ -5,5 +5,5 @@ ALL_TARGETS+=${TARGET_DALVIKPSEUDO} STATIC_OBJ+=${OBJ_DALVIKPSEUDO} ${TARGET_DALVIKPSEUDO}: ${OBJ_DALVIKPSEUDO} - ${CC} $(call libname,parse_dalvik_pseudo) -L../../util -lr_util \ + ${CC} $(call libname,parse_dalvik_pseudo) -L../../util -lrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_DALVIKPSEUDO} ${OBJ_DALVIKPSEUDO} diff --git a/libr/parse/p/m68k_pseudo.mk b/librz/parse/p/m68k_pseudo.mk similarity index 74% rename from libr/parse/p/m68k_pseudo.mk rename to librz/parse/p/m68k_pseudo.mk index e5fd5c14e9..6eabfd0efe 100644 --- a/libr/parse/p/m68k_pseudo.mk +++ b/librz/parse/p/m68k_pseudo.mk @@ -4,11 +4,11 @@ TARGET_M68KPSEUDO=parse_m68k_pseudo.${EXT_SO} ALL_TARGETS+=${TARGET_M68KPSEUDO} STATIC_OBJ+=${OBJ_M68KPSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag endif include $(STOP)/zip/deps.mk diff --git a/libr/parse/p/mips_pseudo.mk b/librz/parse/p/mips_pseudo.mk similarity index 72% rename from libr/parse/p/mips_pseudo.mk rename to librz/parse/p/mips_pseudo.mk index d3b3ab37c5..9fdde3da2e 100644 --- a/libr/parse/p/mips_pseudo.mk +++ b/librz/parse/p/mips_pseudo.mk @@ -6,9 +6,9 @@ STATIC_OBJ+=${OBJ_MIPSPSEUDO} ${TARGET_MIPSPSEUDO}: ${OBJ_MIPSPSEUDO} ifeq ($(CC),cccl) - ${CC} $(call libname,parse_mips_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_mips_pseudo) -L../../util -llibrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_MIPSPSEUDO} ${OBJ_MIPSPSEUDO} else - ${CC} $(call libname,parse_mips_pseudo) -L../../util -lr_util \ + ${CC} $(call libname,parse_mips_pseudo) -L../../util -lrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_MIPSPSEUDO} ${OBJ_MIPSPSEUDO} endif diff --git a/libr/parse/p/parse_6502_pseudo.c b/librz/parse/p/parse_6502_pseudo.c similarity index 91% rename from libr/parse/p/parse_6502_pseudo.c rename to librz/parse/p/parse_6502_pseudo.c index 123ef0e875..cf5d19370a 100644 --- a/libr/parse/p/parse_6502_pseudo.c +++ b/librz/parse/p/parse_6502_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include typedef enum { IND_IDX = 0, @@ -122,7 +122,7 @@ static ADDR_TYPE addr_type(const char *str) { return NORM; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { char w0[256], w1[256], w2[256]; int i, len = strlen (data); char *buf, *ptr, *optr; @@ -139,8 +139,8 @@ static int parse(RParse *p, const char *data, char *str) { if (*buf) { atype = addr_type (buf); - r_str_replace_char (buf, '(', ' '); - r_str_replace_char (buf, ')', ' '); + rz_str_replace_char (buf, '(', ' '); + rz_str_replace_char (buf, ')', ' '); *w0 = *w1 = *w2 = '\0'; ptr = strchr (buf, ' '); if (!ptr) { @@ -182,15 +182,15 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_6502_pseudo = { +RzParsePlugin rz_parse_plugin_6502_pseudo = { .name = "6502.pseudo", .desc = "6502 pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_6502_pseudo, + .data = &rz_parse_plugin_6502_pseudo, .version = R2_VERSION}; #endif diff --git a/libr/parse/p/parse_arm_pseudo.c b/librz/parse/p/parse_arm_pseudo.c similarity index 84% rename from libr/parse/p/parse_arm_pseudo.c rename to librz/parse/p/parse_arm_pseudo.c index d0ef1c6f1d..55acbc5ad6 100644 --- a/libr/parse/p/parse_arm_pseudo.c +++ b/librz/parse/p/parse_arm_pseudo.c @@ -3,11 +3,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int replace(int argc, const char *argv[], char *newstr) { #define MAXPSEUDOOPS 10 @@ -176,8 +176,8 @@ static int replace(int argc, const char *argv[], char *newstr) { newstr[k] = '\0'; } - r_str_replace_char (newstr, '{', '('); - r_str_replace_char (newstr, '}', ')'); + rz_str_replace_char (newstr, '{', '('); + rz_str_replace_char (newstr, '}', ')'); return true; } } @@ -188,12 +188,12 @@ static int replace(int argc, const char *argv[], char *newstr) { strcat (newstr, argv[i]); strcat (newstr, (!i || i == argc - 1)? " " : ","); } - r_str_replace_char (newstr, '{', '('); - r_str_replace_char (newstr, '}', ')'); + rz_str_replace_char (newstr, '{', '('); + rz_str_replace_char (newstr, '}', ')'); return false; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { char w0[256], w1[256], w2[256], w3[256]; int i, len = strlen (data); char *buf, *ptr, *optr; @@ -268,8 +268,8 @@ static int parse(RParse *p, const char *data, char *str) { } { char *s = strdup (str); - s = r_str_replace (s, "+ -", "- ", 1); - s = r_str_replace (s, "- -", "+ ", 1); + s = rz_str_replace (s, "+ -", "- ", 1); + s = rz_str_replace (s, "- -", "+ ", 1); strcpy (str, s); free (s); } @@ -277,24 +277,24 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -static char *subs_var_string(RParse *p, RAnalVarField *var, char *tstr, const char *oldstr, const char *reg, int delta) { +static char *subs_var_string(RzParse *p, RzAnalVarField *var, char *tstr, const char *oldstr, const char *reg, int delta) { char *newstr = p->localvar_only - ? r_str_newf ("%s", var->name) - : r_str_newf ("%s %c %s", reg, delta > 0 ? '+' : '-', var->name); + ? rz_str_newf ("%s", var->name) + : rz_str_newf ("%s %c %s", reg, delta > 0 ? '+' : '-', var->name); if (IS_UPPER (*tstr)) { char *space = strrchr (newstr, ' '); if (space) { *space = 0; - r_str_case (newstr, true); + rz_str_case (newstr, true); *space = ' '; } } - char *ret = r_str_replace (tstr, oldstr, newstr, 1); + char *ret = rz_str_replace (tstr, oldstr, newstr, 1); free (newstr); return ret; } -static char *mount_oldstr(RParse* p, const char *reg, st64 delta, bool ucase) { +static char *mount_oldstr(RzParse* p, const char *reg, st64 delta, bool ucase) { const char *tmplt; char *oldstr; if (delta > -10 && delta < 10) { @@ -303,33 +303,33 @@ static char *mount_oldstr(RParse* p, const char *reg, st64 delta, bool ucase) { if (delta < 0) { sign = '-'; } - oldstr = r_str_newf ("%s %c %d", reg, sign, R_ABS (delta)); + oldstr = rz_str_newf ("%s %c %d", reg, sign, R_ABS (delta)); } else { - oldstr = r_str_newf ("%s, %d", reg, delta); + oldstr = rz_str_newf ("%s, %d", reg, delta); } } else if (delta > 0) { tmplt = p->pseudo ? "%s + 0x%x" : (ucase ? "%s, 0x%X" : "%s, 0x%x"); - oldstr = r_str_newf (tmplt, reg, delta); + oldstr = rz_str_newf (tmplt, reg, delta); } else { tmplt = p->pseudo ? "%s - 0x%x" : (ucase ? "%s, -0x%X" : "%s, -0x%x"); - oldstr = r_str_newf (tmplt, reg, -delta); + oldstr = rz_str_newf (tmplt, reg, -delta); } if (ucase) { char *comma = strchr (oldstr, ','); if (comma) { *comma = 0; - r_str_case (oldstr, true); + rz_str_case (oldstr, true); *comma = ','; } } return oldstr; } -static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { - RList *spargs = NULL; - RList *bpargs = NULL; - RListIter *iter; - RAnal *anal = p->analb.anal; +static bool subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { + RzList *spargs = NULL; + RzList *bpargs = NULL; + RzListIter *iter; + RzAnal *anal = p->analb.anal; char *oldstr; char *tstr = strdup (data); if (!tstr) { @@ -343,12 +343,12 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data if (p->subrel) { char *rip; if (p->pseudo) { - rip = (char *)r_str_casestr (tstr, "[pc +"); + rip = (char *)rz_str_casestr (tstr, "[pc +"); if (!rip) { - rip = (char *)r_str_casestr (tstr, "[pc -"); + rip = (char *)rz_str_casestr (tstr, "[pc -"); } } else { - rip = (char *)r_str_casestr (tstr, "[pc, "); + rip = (char *)rz_str_casestr (tstr, "[pc, "); } if (rip && !strchr (rip + 4, ',')) { @@ -361,13 +361,13 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data ripend = "]"; } if (neg) { - repl_num -= r_num_get (NULL, neg + 1); + repl_num -= rz_num_get (NULL, neg + 1); } else { - repl_num += r_num_get (NULL, rip); + repl_num += rz_num_get (NULL, rip); } rip -= 3; *rip = 0; - tstr_new = r_str_newf ("%s0x%08"PFMT64x"%s", tstr, repl_num, ripend); + tstr_new = rz_str_newf ("%s0x%08"PFMT64x"%s", tstr, repl_num, ripend); free (tstr); tstr = tstr_new; } @@ -376,8 +376,8 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data bpargs = p->varlist (f, 'b'); spargs = p->varlist (f, 's'); bool ucase = IS_UPPER (*tstr); - RAnalVarField *var; - r_list_foreach (bpargs, iter, var) { + RzAnalVarField *var; + rz_list_foreach (bpargs, iter, var) { st64 delta = p->get_ptr_at ? p->get_ptr_at (f, var->delta, addr) : ST64_MAX; @@ -401,7 +401,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } free (oldstr); } - r_list_foreach (spargs, iter, var) { + rz_list_foreach (spargs, iter, var) { st64 delta = p->get_ptr_at ? p->get_ptr_at (f, var->delta, addr) : ST64_MAX; @@ -425,8 +425,8 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } free (oldstr); } - r_list_free (bpargs); - r_list_free (spargs); + rz_list_free (bpargs); + rz_list_free (spargs); if (len > strlen (tstr)) { strcpy (str, tstr); } else { @@ -438,7 +438,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data return true; } -RParsePlugin r_parse_plugin_arm_pseudo = { +RzParsePlugin rz_parse_plugin_arm_pseudo = { .name = "arm.pseudo", .desc = "ARM/ARM64 pseudo syntax", .parse = parse, @@ -446,9 +446,9 @@ RParsePlugin r_parse_plugin_arm_pseudo = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_arm_pseudo, + .data = &rz_parse_plugin_arm_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_att2intel.c b/librz/parse/p/parse_att2intel.c similarity index 82% rename from libr/parse/p/parse_att2intel.c rename to librz/parse/p/parse_att2intel.c index e41cf909db..f13a609e7f 100644 --- a/libr/parse/p/parse_att2intel.c +++ b/librz/parse/p/parse_att2intel.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int replace(int argc, const char *argv[], char *newstr) { int i,j,k; @@ -67,7 +67,7 @@ static int replace(int argc, const char *argv[], char *newstr) { return false; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, n; char w0[32]; char w1[32]; @@ -80,35 +80,35 @@ static int parse(RParse *p, const char *data, char *str) { if (!buf) { return false; } - r_str_trim_head (buf); + rz_str_trim_head (buf); ptr = strchr (buf, '#'); if (ptr) { *ptr = 0; - r_str_trim (buf); + rz_str_trim (buf); } if (*buf == '.' || buf[strlen(buf)-1] == ':') { free (buf); strcpy (str, data); return true; } - r_str_replace_char (buf, '$', 0); - r_str_replace_char (buf, '%', 0); - r_str_replace_char (buf, '\t', ' '); - r_str_replace_char (buf, '(', '['); - r_str_replace_char (buf, ')', ']'); + rz_str_replace_char (buf, '$', 0); + rz_str_replace_char (buf, '%', 0); + rz_str_replace_char (buf, '\t', ' '); + rz_str_replace_char (buf, '(', '['); + rz_str_replace_char (buf, ')', ']'); ptr = strchr (buf, '['); if (ptr) { *ptr = 0; - num = (char*)r_str_lchr (buf, ' '); + num = (char*)rz_str_lchr (buf, ' '); if (!num) { - num = (char *)r_str_lchr (buf, ','); + num = (char *)rz_str_lchr (buf, ','); } if (num) { n = atoi (num+1); *ptr = '['; memmove (num+1, ptr, strlen (ptr)+1); - ptr = (char*)r_str_lchr (buf, ']'); + ptr = (char*)rz_str_lchr (buf, ']'); if (n && ptr) { char *rest = strdup (ptr+1); if (n > 0) { @@ -172,7 +172,7 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_att2intel = { +RzParsePlugin rz_parse_plugin_att2intel = { .name = "att2intel", .desc = "X86 att 2 intel plugin", .init = NULL, @@ -181,9 +181,9 @@ RParsePlugin r_parse_plugin_att2intel = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_att2intel, + .data = &rz_parse_plugin_att2intel, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_avr_pseudo.c b/librz/parse/p/parse_avr_pseudo.c similarity index 94% rename from libr/parse/p/parse_avr_pseudo.c rename to librz/parse/p/parse_avr_pseudo.c index 17776dde5a..aaab887857 100644 --- a/libr/parse/p/parse_avr_pseudo.c +++ b/librz/parse/p/parse_avr_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static bool replace(int argc, const char *argv[], char *newstr) { int i,j,k; @@ -133,7 +133,7 @@ static bool replace(int argc, const char *argv[], char *newstr) { } #define WSZ 128 -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char w0[WSZ]; char w1[WSZ]; @@ -148,7 +148,7 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len + 1); - r_str_trim (buf); + rz_str_trim (buf); if (*buf) { w0[0] = '\0'; w1[0] = '\0'; @@ -216,16 +216,16 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_avr_pseudo = { +RzParsePlugin rz_parse_plugin_avr_pseudo = { .name = "avr.pseudo", .desc = "AVR pseudo syntax", .parse = parse }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_avr_pseudo, + .data = &rz_parse_plugin_avr_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_chip8_pseudo.c b/librz/parse/p/parse_chip8_pseudo.c similarity index 91% rename from libr/parse/p/parse_chip8_pseudo.c rename to librz/parse/p/parse_chip8_pseudo.c index 82f89ed5fe..2e7e713d34 100644 --- a/libr/parse/p/parse_chip8_pseudo.c +++ b/librz/parse/p/parse_chip8_pseudo.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2019 - Vasilij Schneidermann */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define MAXARGS 4 #define BUFSIZE 64 @@ -88,7 +88,7 @@ static int tokenize(const char* in, char* out[]) { return count; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i; char *argv[MAXARGS] = { NULL, NULL, NULL, NULL }; int argc = tokenize (data, argv); @@ -104,16 +104,16 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_chip8_pseudo = { +RzParsePlugin rz_parse_plugin_chip8_pseudo = { .name = "chip8.pseudo", .desc = "chip8 pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_chip8_pseudo, + .data = &rz_parse_plugin_chip8_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_dalvik_pseudo.c b/librz/parse/p/parse_dalvik_pseudo.c similarity index 95% rename from libr/parse/p/parse_dalvik_pseudo.c rename to librz/parse/p/parse_dalvik_pseudo.c index dc2e27d6b2..3c2bff7bd6 100644 --- a/libr/parse/p/parse_dalvik_pseudo.c +++ b/librz/parse/p/parse_dalvik_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int replace(int argc, const char *argv[], char *newstr) { int i,j,k; @@ -226,7 +226,7 @@ static int replace(int argc, const char *argv[], char *newstr) { return false; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char *buf, *ptr, *optr, *ptr2; char w0[64]; @@ -248,7 +248,7 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len + 1); - r_str_trim (buf); + rz_str_trim (buf); if (*buf) { w0[0]='\0'; @@ -323,9 +323,9 @@ static int parse(RParse *p, const char *data, char *str) { replace (nw, wa, str); { char *p = strdup (str); - p = r_str_replace (p, "+ -", "- ", 0); + p = rz_str_replace (p, "+ -", "- ", 0); #if EXPERIMENTAL_ZERO - p = r_str_replace (p, "zero", "0", 0); + p = rz_str_replace (p, "zero", "0", 0); if (!memcmp (p, "0 = ", 4)) *p = 0; // nop #endif if (!strcmp (w1, w2)) { @@ -334,7 +334,7 @@ static int parse(RParse *p, const char *data, char *str) { int snprintf_len1_ = snprintf (a, 32, x, w1, w1); \ int snprintf_len2_ = snprintf (b, 32, y, w1); \ if (snprintf_len1_ < 32 && snprintf_len2_ < 32) { \ - p = r_str_replace (p, a, b, 0); \ + p = rz_str_replace (p, a, b, 0); \ } \ } while (0) @@ -356,7 +356,7 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_dalvik_pseudo = { +RzParsePlugin rz_parse_plugin_dalvik_pseudo = { .name = "dalvik.pseudo", .desc = "DALVIK pseudo syntax", .init = NULL, @@ -365,9 +365,9 @@ RParsePlugin r_parse_plugin_dalvik_pseudo = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_dalvik_pseudo, + .data = &rz_parse_plugin_dalvik_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_m68k_pseudo.c b/librz/parse/p/parse_m68k_pseudo.c similarity index 88% rename from libr/parse/p/parse_m68k_pseudo.c rename to librz/parse/p/parse_m68k_pseudo.c index 44afe268d1..48a9f0cd15 100644 --- a/libr/parse/p/parse_m68k_pseudo.c +++ b/librz/parse/p/parse_m68k_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static bool can_replace(const char *str, int idx, int max_operands) { if (str[idx] > '9' || str[idx] < '1') { @@ -99,7 +99,7 @@ static int replace(int argc, const char *argv[], char *newstr) { } #define WSZ 64 -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char w0[WSZ]; char w1[WSZ]; @@ -119,11 +119,11 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len+1); - r_str_replace_in (buf, len+1, ".l", "", 1); - r_str_replace_in (buf, len+1, ".w", "", 1); - r_str_replace_in (buf, len+1, ".d", "", 1); - r_str_replace_in (buf, len+1, ".b", "", 1); - r_str_trim (buf); + rz_str_replace_in (buf, len+1, ".l", "", 1); + rz_str_replace_in (buf, len+1, ".w", "", 1); + rz_str_replace_in (buf, len+1, ".d", "", 1); + rz_str_replace_in (buf, len+1, ".b", "", 1); + rz_str_trim (buf); if (*buf) { w0[0]='\0'; @@ -196,16 +196,16 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_m68k_pseudo = { +RzParsePlugin rz_parse_plugin_m68k_pseudo = { .name = "m68k.pseudo", .desc = "M68K pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_m68k_pseudo, + .data = &rz_parse_plugin_m68k_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_mips_pseudo.c b/librz/parse/p/parse_mips_pseudo.c similarity index 83% rename from libr/parse/p/parse_mips_pseudo.c rename to librz/parse/p/parse_mips_pseudo.c index 076806f7be..c87a5a6408 100644 --- a/libr/parse/p/parse_mips_pseudo.c +++ b/librz/parse/p/parse_mips_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int can_replace(const char *str, int idx, int max_operands) { if (str[idx] > '9' || str[idx] < '1') { @@ -127,7 +127,7 @@ static int replace(int argc, const char *argv[], char *newstr) { } #define WSZ 64 -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char w0[WSZ]; char w1[WSZ]; @@ -147,9 +147,9 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len+1); - r_str_replace_char (buf, '(', ','); - r_str_replace_char (buf, ')', ' '); - r_str_trim (buf); + rz_str_replace_char (buf, '(', ','); + rz_str_replace_char (buf, ')', ' '); + rz_str_trim (buf); if (*buf) { w0[0]='\0'; @@ -214,10 +214,10 @@ static int parse(RParse *p, const char *data, char *str) { replace (nw, wa, str); { char *p = strdup (str); - p = r_str_replace (p, "+ -", "- ", 0); - p = r_str_replace (p, " + ]", " + 0]", 0); + p = rz_str_replace (p, "+ -", "- ", 0); + p = rz_str_replace (p, " + ]", " + 0]", 0); - p = r_str_replace (p, "zero", "0", 1); + p = rz_str_replace (p, "zero", "0", 1); if (!strncmp (p, "0 = ", 4)) { *p = 0; // nop } @@ -227,7 +227,7 @@ static int parse(RParse *p, const char *data, char *str) { int snprintf_len1_ = snprintf (a, 32, x, w1, w1); \ int snprintf_len2_ = snprintf (b, 32, y, w1); \ if (snprintf_len1_ < 32 && snprintf_len2_ < 32) { \ - p = r_str_replace (p, a, b, 0); \ + p = rz_str_replace (p, a, b, 0); \ } \ } while (0) @@ -240,7 +240,7 @@ static int parse(RParse *p, const char *data, char *str) { REPLACE ("%s = %s >>", "%s >>="); REPLACE ("%s = %s <<", "%s <<="); } - p = r_str_replace (p, ":", "0000", 0); + p = rz_str_replace (p, ":", "0000", 0); strcpy (str, p); free (p); } @@ -250,21 +250,21 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { - RListIter *iter; +static bool subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { + RzListIter *iter; char *oldstr; char *tstr = strdup (data); - RAnal *anal = p->analb.anal; + RzAnal *anal = p->analb.anal; if (!p->varlist) { free (tstr); return false; } - RList *bpargs = p->varlist (f, 'b'); - RList *spargs = p->varlist (f, 's'); + RzList *bpargs = p->varlist (f, 'b'); + RzList *spargs = p->varlist (f, 's'); const bool ucase = IS_UPPER (*tstr); - RAnalVarField *var; - r_list_foreach (spargs, iter, var) { + RzAnalVarField *var; + rz_list_foreach (spargs, iter, var) { st64 delta = p->get_ptr_at ? p->get_ptr_at (f, var->delta, addr) : ST64_MAX; @@ -289,27 +289,27 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } else { tmpf = "-0x%x(%s)"; } - oldstr = r_str_newf (tmpf, R_ABS (delta), reg); + oldstr = rz_str_newf (tmpf, R_ABS (delta), reg); if (ucase) { char *comma = strchr (oldstr, ','); if (comma) { *comma = 0; - r_str_case (oldstr, true); + rz_str_case (oldstr, true); *comma = ','; } } if (strstr (tstr, oldstr)) { char *newstr = (p->localvar_only) - ? r_str_newf ("(%s)", var->name) - : r_str_newf ("%s%s(%s)", delta > 0 ? "" : "-", var->name, reg); - tstr = r_str_replace (tstr, oldstr, newstr, 1); + ? rz_str_newf ("(%s)", var->name) + : rz_str_newf ("%s%s(%s)", delta > 0 ? "" : "-", var->name, reg); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); free (newstr); free (oldstr); break; } free (oldstr); } - r_list_foreach (bpargs, iter, var) { + rz_list_foreach (bpargs, iter, var) { char *tmpf = NULL; st64 delta = p->get_ptr_at ? p->get_ptr_at (f, var->delta, addr) @@ -333,20 +333,20 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } else { tmpf = "-0x%x(%s)"; } - oldstr = r_str_newf (tmpf, R_ABS (delta), reg); + oldstr = rz_str_newf (tmpf, R_ABS (delta), reg); if (ucase) { char *comma = strchr (oldstr, ','); if (comma) { *comma = 0; - r_str_case (oldstr, true); + rz_str_case (oldstr, true); *comma = ','; } } if (strstr (tstr, oldstr)) { char *newstr = (p->localvar_only) - ? r_str_newf ("(%s)", var->name) - : r_str_newf ("%s%s(%s)", delta > 0 ? "" : "-", var->name, reg); - tstr = r_str_replace (tstr, oldstr, newstr, 1); + ? rz_str_newf ("(%s)", var->name) + : rz_str_newf ("%s%s(%s)", delta > 0 ? "" : "-", var->name, reg); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); free (newstr); free (oldstr); break; @@ -361,12 +361,12 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data ret = false; } free (tstr); - r_list_free (bpargs); - r_list_free (spargs); + rz_list_free (bpargs); + rz_list_free (spargs); return ret; } -RParsePlugin r_parse_plugin_mips_pseudo = { +RzParsePlugin rz_parse_plugin_mips_pseudo = { .name = "mips.pseudo", .desc = "MIPS pseudo syntax", .init = NULL, @@ -376,9 +376,9 @@ RParsePlugin r_parse_plugin_mips_pseudo = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_mips_pseudo, + .data = &rz_parse_plugin_mips_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_ppc_pseudo.c b/librz/parse/p/parse_ppc_pseudo.c similarity index 98% rename from libr/parse/p/parse_ppc_pseudo.c rename to librz/parse/p/parse_ppc_pseudo.c index c3606462b9..50fe231a1d 100644 --- a/libr/parse/p/parse_ppc_pseudo.c +++ b/librz/parse/p/parse_ppc_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #ifndef PFMT32x #define PFMT32x "lx" @@ -1611,7 +1611,7 @@ static int replace(int argc, const char *argv[], char *newstr) { } #define WSZ 128 -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char w0[WSZ]; char w1[WSZ]; @@ -1632,9 +1632,9 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len + 1); - r_str_replace_char (buf, '(', ','); - r_str_replace_char (buf, ')', ' '); - r_str_trim (buf); + rz_str_replace_char (buf, '(', ','); + rz_str_replace_char (buf, ')', ' '); + rz_str_trim (buf); if (*buf) { w0[0] = '\0'; w1[0] = '\0'; @@ -1709,11 +1709,11 @@ static int parse(RParse *p, const char *data, char *str) { replace (nw, wa, str); { char *p = strdup (str); - p = r_str_replace (p, "+ -", "- ", 0); - p = r_str_replace (p, " + ]", "] ", 0); - // p = r_str_replace (p, "if (r0 == r0) trap", "trap ", 0); + p = rz_str_replace (p, "+ -", "- ", 0); + p = rz_str_replace (p, " + ]", "] ", 0); + // p = rz_str_replace (p, "if (r0 == r0) trap", "trap ", 0); #if EXPERIMENTAL_ZERO - p = r_str_replace (p, "zero", "0", 0); + p = rz_str_replace (p, "zero", "0", 0); if (!memcmp (p, "0 = ", 4)) *p = 0; // nop #endif if (!strcmp (w1, w2)) { @@ -1722,7 +1722,7 @@ static int parse(RParse *p, const char *data, char *str) { int snprintf_len1_ = snprintf (a, 64, x, w1, w1); \ int snprintf_len2_ = snprintf (b, 64, y, w1); \ if (snprintf_len1_ < 64 && snprintf_len2_ < 64) { \ - p = r_str_replace (p, a, b, 0); \ + p = rz_str_replace (p, a, b, 0); \ } \ } while (0) @@ -1735,7 +1735,7 @@ static int parse(RParse *p, const char *data, char *str) { REPLACE ("%s = %s >>", "%s >>="); REPLACE ("%s = %s <<", "%s <<="); } - p = r_str_replace (p, ":", "0000", 0); + p = rz_str_replace (p, ":", "0000", 0); strcpy (str, p); free (p); } @@ -1745,16 +1745,16 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_ppc_pseudo = { +RzParsePlugin rz_parse_plugin_ppc_pseudo = { .name = "ppc.pseudo", .desc = "PowerPC pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_ppc_pseudo, + .data = &rz_parse_plugin_ppc_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_sh_pseudo.c b/librz/parse/p/parse_sh_pseudo.c similarity index 95% rename from libr/parse/p/parse_sh_pseudo.c rename to librz/parse/p/parse_sh_pseudo.c index 081cb1aadf..aebd340172 100644 --- a/libr/parse/p/parse_sh_pseudo.c +++ b/librz/parse/p/parse_sh_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int replace(int argc, const char *argv[], char *newstr) { int i,j,k; @@ -157,7 +157,7 @@ static int replace(int argc, const char *argv[], char *newstr) { } #define WSZ 128 -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { int i, len = strlen (data); char w0[WSZ]; char w1[WSZ]; @@ -172,7 +172,7 @@ static int parse(RParse *p, const char *data, char *str) { } memcpy (buf, data, len + 1); - r_str_trim (buf); + rz_str_trim (buf); if (*buf) { w0[0] = '\0'; w1[0] = '\0'; @@ -264,16 +264,16 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -RParsePlugin r_parse_plugin_sh_pseudo = { +RzParsePlugin rz_parse_plugin_sh_pseudo = { .name = "sh.pseudo", .desc = "SH-4 pseudo syntax", .parse = parse }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_sh_pseudo, + .data = &rz_parse_plugin_sh_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_tms320_pseudo.c b/librz/parse/p/parse_tms320_pseudo.c similarity index 91% rename from libr/parse/p/parse_tms320_pseudo.c rename to librz/parse/p/parse_tms320_pseudo.c index 5e700e9527..0d0cd335a9 100644 --- a/libr/parse/p/parse_tms320_pseudo.c +++ b/librz/parse/p/parse_tms320_pseudo.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2020 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include // https://www.ti.com/lit/ug/spru732j/spru732j.pdf @@ -111,7 +111,7 @@ static int replace(int argc, const char *argv[], char *newstr) { if (index >= 0 && index < argc) { const char *w = argv[index]; if (!R_STR_ISEMPTY (w)) { - r_str_cpy (newstr + k, w); + rz_str_cpy (newstr + k, w); k += strlen (w) - 1; } } @@ -137,7 +137,7 @@ static int replace(int argc, const char *argv[], char *newstr) { return false; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { if (!strncmp (data, "|| ", 3)) { data += 3; } @@ -148,17 +148,17 @@ static int parse(RParse *p, const char *data, char *str) { char *buf = strdup (data); - RListIter *iter; + RzListIter *iter; char *sp = strchr (buf, ' '); size_t nw = 1; const char *wa[5] = {0}; wa[0] = buf; - RList *list = NULL; + RzList *list = NULL; if (sp) { *sp++ = 0; - list = r_str_split_list (sp, ",", 0); + list = rz_str_split_list (sp, ",", 0); char *w; - r_list_foreach (list, iter, w) { + rz_list_foreach (list, iter, w) { wa[nw] = w; nw++; if (nw == 5) { @@ -169,20 +169,20 @@ static int parse(RParse *p, const char *data, char *str) { replace (nw, wa, str); free (buf); - r_list_free (list); + rz_list_free (list); return true; } -RParsePlugin r_parse_plugin_tms320_pseudo = { +RzParsePlugin rz_parse_plugin_tms320_pseudo = { .name = "tms320.pseudo", .desc = "tms320 pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_tms320_pseudo, + .data = &rz_parse_plugin_tms320_pseudo, .version = R2_VERSION}; #endif diff --git a/libr/parse/p/parse_v850_pseudo.c b/librz/parse/p/parse_v850_pseudo.c similarity index 85% rename from libr/parse/p/parse_v850_pseudo.c rename to librz/parse/p/parse_v850_pseudo.c index 56e0bad59b..e5597bda2d 100644 --- a/libr/parse/p/parse_v850_pseudo.c +++ b/librz/parse/p/parse_v850_pseudo.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2020 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include // https://www.renesas.com/us/en/doc/products/mpumcu/doc/v850/r01us0037ej0100_v850e2.pdf @@ -81,7 +81,7 @@ static int replace(int argc, const char *argv[], char *newstr) { if (index >= 0 && index < argc) { const char *w = argv[index]; if (!R_STR_ISEMPTY (w)) { - r_str_cpy (newstr + k, w); + rz_str_cpy (newstr + k, w); k += strlen (w) - 1; } } @@ -113,8 +113,8 @@ static int replace(int argc, const char *argv[], char *newstr) { strcat (newstr, argv[i]); strcat (newstr, (i == 0 || i == argc - 1) ? " " : ","); } - r_str_replace_in (newstr, strlen (newstr), "+= -", "-= ", true); - r_str_replace_in (newstr, strlen (newstr), " + -", " - ", true); + rz_str_replace_in (newstr, strlen (newstr), "+= -", "-= ", true); + rz_str_replace_in (newstr, strlen (newstr), " + -", " - ", true); // strcpy (newstr, a); return false; } @@ -132,8 +132,8 @@ static char *reorder(char *buf) { char arg[32], reg[32]; char *end = strchr (par + 1, ']'); if (end) { - r_str_ncpy (reg, par + 1, end - par); - r_str_ncpy (arg, arr, par - arr + 1); + rz_str_ncpy (reg, par + 1, end - par); + rz_str_ncpy (arg, arr, par - arr + 1); sprintf (buf, "%s[%s]", reg, arg); } } @@ -160,7 +160,7 @@ static void guard_braces (char *buf) { } } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { if (!strncmp (data, "|| ", 3)) { data += 3; } @@ -171,17 +171,17 @@ static int parse(RParse *p, const char *data, char *str) { char *buf = strdup (data); guard_braces (buf); - RListIter *iter; + RzListIter *iter; char *sp = strchr (buf, ' '); size_t nw = 1; const char *wa[5] = {0}; wa[0] = buf; - RList *list = NULL; + RzList *list = NULL; if (sp) { *sp++ = 0; - list = r_str_split_list (sp, ",", 0); + list = rz_str_split_list (sp, ",", 0); char *w; - r_list_foreach (list, iter, w) { + rz_list_foreach (list, iter, w) { wa[nw] = reorder(w); nw++; if (nw == 5) { @@ -192,20 +192,20 @@ static int parse(RParse *p, const char *data, char *str) { replace (nw, wa, str); free (buf); - r_list_free (list); + rz_list_free (list); return true; } -RParsePlugin r_parse_plugin_v850_pseudo = { +RzParsePlugin rz_parse_plugin_v850_pseudo = { .name = "v850.pseudo", .desc = "v850 pseudo syntax", .parse = parse, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_v850_pseudo, + .data = &rz_parse_plugin_v850_pseudo, .version = R2_VERSION}; #endif diff --git a/libr/parse/p/parse_wasm_pseudo.c b/librz/parse/p/parse_wasm_pseudo.c similarity index 59% rename from libr/parse/p/parse_wasm_pseudo.c rename to librz/parse/p/parse_wasm_pseudo.c index 4ca9ae8a82..3627e2e4ad 100644 --- a/libr/parse/p/parse_wasm_pseudo.c +++ b/librz/parse/p/parse_wasm_pseudo.c @@ -3,16 +3,16 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -static char* get_fcn_name(RAnal *anal, ut32 fcn_id) { - r_cons_push (); +static char* get_fcn_name(RzAnal *anal, ut32 fcn_id) { + rz_cons_push (); char *s = anal->coreb.cmdstrf (anal->coreb.core, "is~FUNC[6:%u]", fcn_id); - r_cons_pop (); + rz_cons_pop (); if (s) { size_t namelen = strlen (s); s[namelen - 1] = 0; @@ -20,11 +20,11 @@ static char* get_fcn_name(RAnal *anal, ut32 fcn_id) { return s; } -static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +static bool subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { char *fcn_name = NULL; str[0] = 0; if (!strncmp (data, "call ", 5)) { - ut32 fcn_id = (ut32) r_num_get (NULL, data + 5); + ut32 fcn_id = (ut32) rz_num_get (NULL, data + 5); if (!(fcn_name = get_fcn_name (p->analb.anal, fcn_id))) { return false; } @@ -35,16 +35,16 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data return false; } -RParsePlugin r_parse_plugin_wasm_pseudo = { +RzParsePlugin rz_parse_plugin_wasm_pseudo = { .name = "wasm.pseudo", .desc = "WASM pseudo syntax", .subvar = &subvar, }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_wasm_pseudo, + .data = &rz_parse_plugin_wasm_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_x86_pseudo.c b/librz/parse/p/parse_x86_pseudo.c similarity index 76% rename from libr/parse/p/parse_x86_pseudo.c rename to librz/parse/p/parse_x86_pseudo.c index e63c3f1017..70fe5523a3 100644 --- a/libr/parse/p/parse_x86_pseudo.c +++ b/librz/parse/p/parse_x86_pseudo.c @@ -4,10 +4,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include // 16 bit examples // 0x0001f3a4 9a67620eca call word 0xca0e:0x6267 // 0x0001f41c eabe76de12 jmp word 0x12de:0x76be [2] @@ -164,7 +164,7 @@ static int replace (int argc, char *argv[], char *newstr) { return false; } -static int parse(RParse *p, const char *data, char *str) { +static int parse(RzParse *p, const char *data, char *str) { char w0[256], w1[256], w2[256], w3[256]; int i; size_t len = strlen (data); @@ -193,8 +193,8 @@ static int parse(RParse *p, const char *data, char *str) { ; } } - r_str_ncpy (w0, buf, sizeof (w0)); - r_str_ncpy (w1, ptr, sizeof (w1)); + rz_str_ncpy (w0, buf, sizeof (w0)); + rz_str_ncpy (w1, ptr, sizeof (w1)); optr = ptr; ptr = strchr (ptr, ','); if (ptr) { @@ -202,8 +202,8 @@ static int parse(RParse *p, const char *data, char *str) { for (++ptr; *ptr == ' '; ptr++) { ; } - r_str_ncpy (w1, optr, sizeof (w1)); - r_str_ncpy (w2, ptr, sizeof (w2)); + rz_str_ncpy (w1, optr, sizeof (w1)); + rz_str_ncpy (w2, ptr, sizeof (w2)); optr = ptr; ptr = strchr (ptr, ','); if (ptr) { @@ -211,8 +211,8 @@ static int parse(RParse *p, const char *data, char *str) { for (++ptr; *ptr == ' '; ptr++) { ; } - r_str_ncpy (w2, optr, sizeof (w2)); - r_str_ncpy (w3, ptr, sizeof (w3)); + rz_str_ncpy (w2, optr, sizeof (w2)); + rz_str_ncpy (w3, ptr, sizeof (w3)); } } } @@ -228,56 +228,56 @@ static int parse(RParse *p, const char *data, char *str) { if (strstr (w0, "mul")) { if (nw == 2) { - r_str_ncpy (wa[3], wa[1], sizeof (w3)); + rz_str_ncpy (wa[3], wa[1], sizeof (w3)); switch (wa[3][0]) { case 'q': case 'r': //qword, r.. - r_str_ncpy (wa[1], "rax", sizeof (w1)); - r_str_ncpy (wa[2], "rax", sizeof (w2)); + rz_str_ncpy (wa[1], "rax", sizeof (w1)); + rz_str_ncpy (wa[2], "rax", sizeof (w2)); break; case 'd': case 'e': //dword, e.. if (strlen (wa[3]) > 2) { - r_str_ncpy (wa[1], "eax", sizeof (w1)); - r_str_ncpy (wa[2], "eax", sizeof (w2)); + rz_str_ncpy (wa[1], "eax", sizeof (w1)); + rz_str_ncpy (wa[2], "eax", sizeof (w2)); break; } default : // .x, .p, .i or word if (wa[3][1] == 'x' || wa[3][1] == 'p' || \ wa[3][1] == 'i' || wa[3][0] == 'w') { - r_str_ncpy (wa[1], "ax", sizeof (w1)); - r_str_ncpy (wa[2], "ax", sizeof (w2)); + rz_str_ncpy (wa[1], "ax", sizeof (w1)); + rz_str_ncpy (wa[2], "ax", sizeof (w2)); } else { // byte and lowest 8 bit registers - r_str_ncpy (wa[1], "al", sizeof (w1)); - r_str_ncpy (wa[2], "al", sizeof (w2)); + rz_str_ncpy (wa[1], "al", sizeof (w1)); + rz_str_ncpy (wa[2], "al", sizeof (w2)); } } } else if (nw == 3) { - r_str_ncpy (wa[3], wa[2], sizeof (w3)); - r_str_ncpy (wa[2], wa[1], sizeof (w2)); + rz_str_ncpy (wa[3], wa[2], sizeof (w3)); + rz_str_ncpy (wa[2], wa[1], sizeof (w2)); } replace (nw, wa, str); } else if (strstr (w0, "lea")) { - r_str_replace_char (w2, '[', 0); - r_str_replace_char (w2, ']', 0); + rz_str_replace_char (w2, '[', 0); + rz_str_replace_char (w2, ']', 0); replace (nw, wa, str); } else if ((strstr (w1, "ax") || strstr (w1, "ah") || strstr (w1, "al")) && !p->retleave_asm) { if (!(p->retleave_asm = (char *) malloc (sz))) { return false; } - r_snprintf (p->retleave_asm, sz, "return %s", w2); + rz_snprintf (p->retleave_asm, sz, "return %s", w2); replace (nw, wa, str); } else if ((strstr (w0, "leave") && p->retleave_asm) || (strstr (w0, "pop") && strstr (w1, "bp"))) { - r_str_ncpy (wa[0], " ", 2); - r_str_ncpy (wa[1], " ", 2); + rz_str_ncpy (wa[0], " ", 2); + rz_str_ncpy (wa[1], " ", 2); replace (nw, wa, str); } else if (strstr (w0, "ret") && p->retleave_asm) { - r_str_ncpy (str, p->retleave_asm, sz); + rz_str_ncpy (str, p->retleave_asm, sz); R_FREE (p->retleave_asm); } else if (p->retleave_asm) { R_FREE (p->retleave_asm); @@ -289,65 +289,65 @@ static int parse(RParse *p, const char *data, char *str) { return true; } -static void parse_localvar (RParse *p, char *newstr, size_t newstr_len, const char *var, const char *reg, char sign, char *ireg, bool att) { - RStrBuf *sb = r_strbuf_new (""); +static void parse_localvar (RzParse *p, char *newstr, size_t newstr_len, const char *var, const char *reg, char sign, char *ireg, bool att) { + RStrBuf *sb = rz_strbuf_new (""); if (att) { if (p->localvar_only) { if (ireg) { - r_strbuf_setf (sb, "(%%%s)", ireg); + rz_strbuf_setf (sb, "(%%%s)", ireg); } - snprintf (newstr, newstr_len - 1, "%s%s", var, r_strbuf_get (sb)); + snprintf (newstr, newstr_len - 1, "%s%s", var, rz_strbuf_get (sb)); } else { if (ireg) { - r_strbuf_setf (sb, ", %%%s", ireg); + rz_strbuf_setf (sb, ", %%%s", ireg); } - snprintf (newstr, newstr_len - 1, "%s(%%%s%s)", var, reg, r_strbuf_get (sb)); + snprintf (newstr, newstr_len - 1, "%s(%%%s%s)", var, reg, rz_strbuf_get (sb)); } } else { if (ireg) { - r_strbuf_setf (sb, " + %s", ireg); + rz_strbuf_setf (sb, " + %s", ireg); } if (p->localvar_only) { - snprintf (newstr, newstr_len - 1, "%s%s", var, r_strbuf_get (sb)); + snprintf (newstr, newstr_len - 1, "%s%s", var, rz_strbuf_get (sb)); } else { - snprintf (newstr, newstr_len - 1, "%s%s %c %s", reg, r_strbuf_get (sb), sign, var); + snprintf (newstr, newstr_len - 1, "%s%s %c %s", reg, rz_strbuf_get (sb), sign, var); } } - r_strbuf_free (sb); + rz_strbuf_free (sb); } static inline void mk_reg_str(const char *regname, int delta, bool sign, bool att, char *ireg, char *dest, int len) { - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); if (att) { if (ireg) { - r_strbuf_setf (sb, ", %%%s", ireg); + rz_strbuf_setf (sb, ", %%%s", ireg); } if (delta == 0) { - snprintf (dest, len - 1, "(%%%s%s)", regname, r_strbuf_get (sb)); + snprintf (dest, len - 1, "(%%%s%s)", regname, rz_strbuf_get (sb)); } else if (delta < 10) { - snprintf (dest, len - 1, "%s%d(%%%s%s)", sign ? "" : "-", delta, regname, r_strbuf_get (sb)); + snprintf (dest, len - 1, "%s%d(%%%s%s)", sign ? "" : "-", delta, regname, rz_strbuf_get (sb)); } else { - snprintf (dest, len - 1, "%s0x%x(%%%s%s)", sign ? "" : "-", delta, regname, r_strbuf_get (sb)); + snprintf (dest, len - 1, "%s0x%x(%%%s%s)", sign ? "" : "-", delta, regname, rz_strbuf_get (sb)); } } else { if (ireg) { - r_strbuf_setf (sb, " + %s", ireg); + rz_strbuf_setf (sb, " + %s", ireg); } if (delta == 0) { - snprintf (dest, len - 1, "%s%s", regname, r_strbuf_get (sb)); + snprintf (dest, len - 1, "%s%s", regname, rz_strbuf_get (sb)); } else if (delta < 10) { - snprintf (dest, len - 1, "%s%s %c %d", regname, r_strbuf_get (sb), sign ? '+':'-', delta); + snprintf (dest, len - 1, "%s%s %c %d", regname, rz_strbuf_get (sb), sign ? '+':'-', delta); } else { - snprintf (dest, len - 1, "%s%s %c 0x%x", regname, r_strbuf_get (sb), sign ? '+':'-', delta); + snprintf (dest, len - 1, "%s%s %c 0x%x", regname, rz_strbuf_get (sb), sign ? '+':'-', delta); } } - r_strbuf_free (sb); + rz_strbuf_free (sb); } -static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { - RList *bpargs, *spargs; - RAnal *anal = p->analb.anal; - RListIter *bpargiter, *spiter; +static bool subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { + RzList *bpargs, *spargs; + RzAnal *anal = p->analb.anal; + RzListIter *bpargiter, *spiter; char oldstr[64], newstr[64]; char *tstr = strdup (data); if (!tstr) { @@ -358,7 +358,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data if (p->subrel) { if (att) { - char *rip = (char *) r_str_casestr (tstr, "(%rip)"); + char *rip = (char *) rz_str_casestr (tstr, "(%rip)"); if (rip) { *rip = 0; char *pre = tstr; @@ -371,16 +371,16 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data if (word > tstr) { *word++ = 0; *rip = 0; - st64 n = r_num_math (NULL, word); + st64 n = rz_num_math (NULL, word); ut64 repl_num = oplen + addr + n; - char *tstr_new = r_str_newf ("%s 0x%08"PFMT64x"%s", pre, repl_num, pos); + char *tstr_new = rz_str_newf ("%s 0x%08"PFMT64x"%s", pre, repl_num, pos); *rip = '('; free (tstr); tstr = tstr_new; } } } else { - char *rip = (char *) r_str_casestr (tstr, "[rip"); + char *rip = (char *) rz_str_casestr (tstr, "[rip"); if (rip) { char *ripend = strchr (rip + 3, ']'); const char *plus = strchr (rip, '+'); @@ -392,14 +392,14 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data ripend = "]"; } if (plus) { - repl_num += r_num_get (NULL, plus + 1); + repl_num += rz_num_get (NULL, plus + 1); } if (neg) { - repl_num -= r_num_get (NULL, neg + 1); + repl_num -= rz_num_get (NULL, neg + 1); } rip[1] = '\0'; - tstr_new = r_str_newf ("%s0x%08"PFMT64x"%s", tstr, repl_num, ripend); + tstr_new = rz_str_newf ("%s0x%08"PFMT64x"%s", tstr, repl_num, ripend); free (tstr); tstr = tstr_new; } @@ -421,8 +421,8 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data if (p->get_op_ireg) { ireg = p->get_op_ireg(p->user, addr); } - RAnalVarField *bparg, *sparg; - r_list_foreach (spargs, spiter, sparg) { + RzAnalVarField *bparg, *sparg; + rz_list_foreach (spargs, spiter, sparg) { char sign = '+'; st64 delta = p->get_ptr_at ? p->get_ptr_at (f, sparg->delta, addr) @@ -446,7 +446,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data mk_reg_str (reg, delta, sign == '+', att, ireg, oldstr, sizeof (oldstr)); if (ucase) { - r_str_case (oldstr, true); + rz_str_case (oldstr, true); } parse_localvar (p, newstr, sizeof (newstr), sparg->name, reg, sign, ireg, att); char *ptr = strstr (tstr, oldstr); @@ -457,19 +457,19 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data continue; } } - tstr = r_str_replace (tstr, oldstr, newstr, 1); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); break; } else { - r_str_case (oldstr, false); + rz_str_case (oldstr, false); ptr = strstr (tstr, oldstr); if (ptr && (!att || *(ptr - 1) == ' ')) { - tstr = r_str_replace (tstr, oldstr, newstr, 1); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); break; } } } /* iterate over base pointer args/vars */ - r_list_foreach (bpargs, bpargiter, bparg) { + rz_list_foreach (bpargs, bpargiter, bparg) { char sign = '+'; st64 delta = p->get_ptr_at ? p->get_ptr_at (f, bparg->delta, addr) @@ -492,7 +492,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } mk_reg_str (reg, delta, sign == '+', att, ireg, oldstr, sizeof (oldstr)); if (ucase) { - r_str_case (oldstr, true); + rz_str_case (oldstr, true); } parse_localvar (p, newstr, sizeof (newstr), bparg->name, reg, sign, ireg, att); char *ptr = strstr (tstr, oldstr); @@ -503,20 +503,20 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data continue; } } - tstr = r_str_replace (tstr, oldstr, newstr, 1); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); break; } else { - r_str_case (oldstr, false); + rz_str_case (oldstr, false); ptr = strstr (tstr, oldstr); if (ptr && (!att || *(ptr - 1) == ' ')) { - tstr = r_str_replace (tstr, oldstr, newstr, 1); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); break; } } // Try with no spaces snprintf (oldstr, sizeof (oldstr) - 1, "[%s%c0x%x]", reg, sign, (int)delta); if (strstr (tstr, oldstr) != NULL) { - tstr = r_str_replace (tstr, oldstr, newstr, 1); + tstr = rz_str_replace (tstr, oldstr, newstr, 1); break; } } @@ -525,7 +525,7 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data if (anal->reg->name[R_REG_NAME_BP]) { strncpy (bp, anal->reg->name[R_REG_NAME_BP], sizeof (bp) - 1); if (isupper ((ut8)*str)) { - r_str_case (bp, true); + rz_str_case (bp, true); } bp[sizeof (bp) - 1] = 0; } else { @@ -541,12 +541,12 @@ static bool subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data } free (tstr); free (ireg); - r_list_free (spargs); - r_list_free (bpargs); + rz_list_free (spargs); + rz_list_free (bpargs); return ret; } -RParsePlugin r_parse_plugin_x86_pseudo = { +RzParsePlugin rz_parse_plugin_x86_pseudo = { .name = "x86.pseudo", .desc = "X86 pseudo syntax", .parse = &parse, @@ -554,9 +554,9 @@ RParsePlugin r_parse_plugin_x86_pseudo = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_x86_pseudo, + .data = &rz_parse_plugin_x86_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/parse_z80_pseudo.c b/librz/parse/p/parse_z80_pseudo.c similarity index 88% rename from libr/parse/p/parse_z80_pseudo.c rename to librz/parse/p/parse_z80_pseudo.c index 8092fd9d48..7e104d473e 100644 --- a/libr/parse/p/parse_z80_pseudo.c +++ b/librz/parse/p/parse_z80_pseudo.c @@ -4,11 +4,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static int replace(int argc, const char *argv[], char *newstr) { int i,j,k; @@ -74,7 +74,7 @@ static int replace(int argc, const char *argv[], char *newstr) { return false; } -RParsePlugin r_parse_plugin_z80_pseudo = { +RzParsePlugin rz_parse_plugin_z80_pseudo = { .name = "z80.pseudo", .desc = "z80 pseudo syntax", .init = NULL, @@ -83,9 +83,9 @@ RParsePlugin r_parse_plugin_z80_pseudo = { }; #ifndef R2_PLUGIN_INCORE -R_API RLibStruct radare_plugin = { +RZ_API RzLibStruct radare_plugin = { .type = R_LIB_TYPE_PARSE, - .data = &r_parse_plugin_z80_pseudo, + .data = &rz_parse_plugin_z80_pseudo, .version = R2_VERSION }; #endif diff --git a/libr/parse/p/ppc_pseudo.mk b/librz/parse/p/ppc_pseudo.mk similarity index 73% rename from libr/parse/p/ppc_pseudo.mk rename to librz/parse/p/ppc_pseudo.mk index be077d684b..f5d483814b 100644 --- a/libr/parse/p/ppc_pseudo.mk +++ b/librz/parse/p/ppc_pseudo.mk @@ -6,9 +6,9 @@ STATIC_OBJ+=${OBJ_PPCPSEUDO} ${TARGET_PPCPSEUDO}: ${OBJ_PPCPSEUDO} ifeq ($(CC),cccl) - ${CC} $(call libname,parse_ppc_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_ppc_pseudo) -L../../util -llibrz_util \ ${LDFLAGS_SHARED} ${CFLAGS} ${LDFLAGS} -o ${TARGET_PPCPSEUDO} ${OBJ_PPCPSEUDO} else - ${CC} $(call libname,parse_ppc_pseudo) -L../../util -lr_util \ + ${CC} $(call libname,parse_ppc_pseudo) -L../../util -lrz_util \ ${LDFLAGS_SHARED} ${CFLAGS} ${LDFLAGS} -o ${TARGET_PPCPSEUDO} ${OBJ_PPCPSEUDO} endif diff --git a/libr/parse/p/sh_pseudo.mk b/librz/parse/p/sh_pseudo.mk similarity index 72% rename from libr/parse/p/sh_pseudo.mk rename to librz/parse/p/sh_pseudo.mk index 3afb170a8f..6ef9fc6374 100644 --- a/libr/parse/p/sh_pseudo.mk +++ b/librz/parse/p/sh_pseudo.mk @@ -6,9 +6,9 @@ STATIC_OBJ+=${OBJ_SHPSEUDO} ${TARGET_SHPSEUDO}: ${OBJ_SHPSEUDO} ifeq ($(CC),cccl) - ${CC} $(call libname,parse_sh_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_sh_pseudo) -L../../util -llibrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_SHPSEUDO} ${OBJ_SHPSEUDO} $(LINK) else - ${CC} $(call libname,parse_sh_pseudo) -L../../util -lr_util \ + ${CC} $(call libname,parse_sh_pseudo) -L../../util -lrz_util \ $(LDFLAGS_SHARED) ${CFLAGS} -o ${TARGET_SHPSEUDO} ${OBJ_SHPSEUDO} $(LINK) endif diff --git a/libr/parse/p/tms320_pseudo.mk b/librz/parse/p/tms320_pseudo.mk similarity index 84% rename from libr/parse/p/tms320_pseudo.mk rename to librz/parse/p/tms320_pseudo.mk index 3fb50b1bab..b004b8fed1 100644 --- a/libr/parse/p/tms320_pseudo.mk +++ b/librz/parse/p/tms320_pseudo.mk @@ -11,5 +11,5 @@ TMS320_CFLAGS:=${CFLAGS} ${LINK} endif ${TARGET_TMS320PSEUDO}: ${OBJ_TMS320PSEUDO} - ${CC} $(call libname,parse_tms320_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_tms320_pseudo) -L../../util -llibrz_util \ $(LDFLAGS_SHARED) ${TMS320_CFLAGS} -o ${TARGET_TMS320PSEUDO} ${OBJ_TMS320PSEUDO} diff --git a/libr/parse/p/v850_pseudo.mk b/librz/parse/p/v850_pseudo.mk similarity index 83% rename from libr/parse/p/v850_pseudo.mk rename to librz/parse/p/v850_pseudo.mk index 22b4a16bcb..4a51b48b11 100644 --- a/libr/parse/p/v850_pseudo.mk +++ b/librz/parse/p/v850_pseudo.mk @@ -11,5 +11,5 @@ V850_CFLAGS:=${CFLAGS} ${LINK} endif ${TARGET_V850PSEUDO}: ${OBJ_V850PSEUDO} - ${CC} $(call libname,parse_v850_pseudo) -L../../util -llibr_util \ + ${CC} $(call libname,parse_v850_pseudo) -L../../util -llibrz_util \ $(LDFLAGS_SHARED) ${V850_CFLAGS} -o ${TARGET_V850PSEUDO} ${OBJ_V850PSEUDO} diff --git a/libr/parse/p/wasm_pseudo.mk b/librz/parse/p/wasm_pseudo.mk similarity index 59% rename from libr/parse/p/wasm_pseudo.mk rename to librz/parse/p/wasm_pseudo.mk index 3ddf66badc..49413998b4 100644 --- a/libr/parse/p/wasm_pseudo.mk +++ b/librz/parse/p/wasm_pseudo.mk @@ -4,15 +4,15 @@ TARGET_WASMPSEUDO=parse_wasm_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_WASMPSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag -LDFLAGS+=-L../../reg -llibr_reg -LDFLAGS+=-L../../cons -llibr_cons +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag +LDFLAGS+=-L../../reg -llibrz_reg +LDFLAGS+=-L../../cons -llibrz_cons else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag -LDFLAGS+=-L../../reg -lr_reg -LDFLAGS+=-L../../cons -lr_cons +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag +LDFLAGS+=-L../../reg -lrz_reg +LDFLAGS+=-L../../cons -lrz_cons endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/p/x86_pseudo.mk b/librz/parse/p/x86_pseudo.mk similarity index 58% rename from libr/parse/p/x86_pseudo.mk rename to librz/parse/p/x86_pseudo.mk index 16148e5797..fa58f5457c 100644 --- a/libr/parse/p/x86_pseudo.mk +++ b/librz/parse/p/x86_pseudo.mk @@ -3,15 +3,15 @@ OBJ_X86PSEUDO+=parse_x86_pseudo.o TARGET_X86PSEUDO=parse_x86_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_X86PSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag -LDFLAGS+=-L../../reg -llibr_reg -LDFLAGS+=-L../../cons -llibr_cons +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag +LDFLAGS+=-L../../reg -llibrz_reg +LDFLAGS+=-L../../cons -llibrz_cons else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag -LDFLAGS+=-L../../reg -lr_reg -LDFLAGS+=-L../../cons -lr_cons +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag +LDFLAGS+=-L../../reg -lrz_reg +LDFLAGS+=-L../../cons -lrz_cons endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/p/z80_pseudo.mk b/librz/parse/p/z80_pseudo.mk similarity index 73% rename from libr/parse/p/z80_pseudo.mk rename to librz/parse/p/z80_pseudo.mk index c72226f8e1..cab0bbeb9d 100644 --- a/libr/parse/p/z80_pseudo.mk +++ b/librz/parse/p/z80_pseudo.mk @@ -3,11 +3,11 @@ OBJ_Z80PSEUDO+=parse_z80_pseudo.o TARGET_Z80PSEUDO=parse_z80_pseudo.${EXT_SO} STATIC_OBJ+=${OBJ_Z80PSEUDO} ifeq ($(CC),cccl) -LIBDEPS=-L../../util -llibr_util -LIBDEPS+=-L../../flag -llibr_flag +LIBDEPS=-L../../util -llibrz_util +LIBDEPS+=-L../../flag -llibrz_flag else -LIBDEPS=-L../../util -lr_util -LIBDEPS+=-L../../flag -lr_flag +LIBDEPS=-L../../util -lrz_util +LIBDEPS+=-L../../flag -lrz_flag endif ifeq ($(WITHPIC),1) diff --git a/libr/parse/parse.c b/librz/parse/parse.c similarity index 58% rename from libr/parse/parse.c rename to librz/parse/parse.c index 559d14907d..15db9b16fe 100644 --- a/libr/parse/parse.c +++ b/librz/parse/parse.c @@ -1,25 +1,25 @@ -/* radare2 - LGPL - Copyright 2009-2020 - nibble, pancake, maijin */ +/* rizin - LGPL - Copyright 2009-2020 - nibble, pancake, maijin */ #include -#include -#include +#include +#include #include -R_LIB_VERSION (r_parse); +R_LIB_VERSION (rz_parse); -static RParsePlugin *parse_static_plugins[] = +static RzParsePlugin *parse_static_plugins[] = { R_PARSE_STATIC_PLUGINS }; -R_API RParse *r_parse_new(void) { +RZ_API RzParse *rz_parse_new(void) { int i; - RParse *p = R_NEW0 (RParse); + RzParse *p = R_NEW0 (RzParse); if (!p) { return NULL; } - p->parsers = r_list_newf (NULL); // memleak + p->parsers = rz_list_newf (NULL); // memleak if (!p->parsers) { - r_parse_free (p); + rz_parse_free (p); return NULL; } p->notin_flagspace = NULL; @@ -30,32 +30,32 @@ R_API RParse *r_parse_new(void) { p->minval = 0x100; p->localvar_only = false; for (i = 0; parse_static_plugins[i]; i++) { - r_parse_add (p, parse_static_plugins[i]); + rz_parse_add (p, parse_static_plugins[i]); } return p; } -R_API void r_parse_free(RParse *p) { - r_list_free (p->parsers); +RZ_API void rz_parse_free(RzParse *p) { + rz_list_free (p->parsers); free (p); } -R_API bool r_parse_add(RParse *p, RParsePlugin *foo) { +RZ_API bool rz_parse_add(RzParse *p, RzParsePlugin *foo) { bool itsFine = true; if (foo->init) { itsFine = foo->init (p, p->user); } if (itsFine) { - r_list_append (p->parsers, foo); + rz_list_append (p->parsers, foo); } return true; } -R_API bool r_parse_use(RParse *p, const char *name) { - RListIter *iter; - RParsePlugin *h; - r_return_val_if_fail (p && name, false); - r_list_foreach (p->parsers, iter, h) { +RZ_API bool rz_parse_use(RzParse *p, const char *name) { + RzListIter *iter; + RzParsePlugin *h; + rz_return_val_if_fail (p && name, false); + rz_list_foreach (p->parsers, iter, h) { if (!strcmp (h->name, name)) { p->cur = h; return true; @@ -66,7 +66,7 @@ R_API bool r_parse_use(RParse *p, const char *name) { // this function is a bit confussing, assembles C code into wat?, whehres theh input and wheres the output // and its unused. so imho it sshould be DEPRECATED this conflicts with rasm.assemble imhoh -R_API bool r_parse_assemble(RParse *p, char *data, char *str) { +RZ_API bool rz_parse_assemble(RzParse *p, char *data, char *str) { char *in = strdup (str); bool ret = false; char *s, *o; @@ -98,13 +98,13 @@ R_API bool r_parse_assemble(RParse *p, char *data, char *str) { // data is input disasm, str is output pseudo // TODO: refactooring, this should return char * instead -R_API bool r_parse_parse(RParse *p, const char *data, char *str) { - r_return_val_if_fail (p && data && str, false); +RZ_API bool rz_parse_parse(RzParse *p, const char *data, char *str) { + rz_return_val_if_fail (p && data && str, false); return (p && data && *data && p->cur && p->cur->parse) ? p->cur->parse (p, data, str) : false; } -R_API char *r_parse_immtrim(char *opstr) { +RZ_API char *rz_parse_immtrim(char *opstr) { if (!opstr || !*opstr) { return NULL; } @@ -117,24 +117,24 @@ R_API char *r_parse_immtrim(char *opstr) { memmove (n, p, strlen (p) + 1); } if (strstr (opstr, " - ]")) { - opstr = r_str_replace (opstr, " - ]", "]", 1); + opstr = rz_str_replace (opstr, " - ]", "]", 1); } if (strstr (opstr, " + ]")) { - opstr = r_str_replace (opstr, " + ]", "]", 1); + opstr = rz_str_replace (opstr, " + ]", "]", 1); } if (strstr (opstr, ", ]")) { - opstr = r_str_replace (opstr, ", ]", "]", 1); + opstr = rz_str_replace (opstr, ", ]", "]", 1); } if (strstr (opstr, " - ")) { - opstr = r_str_replace (opstr, " - ", "-", 1); + opstr = rz_str_replace (opstr, " - ", "-", 1); } if (strstr (opstr, " + ")) { - opstr = r_str_replace (opstr, " + ", "+", 1); + opstr = rz_str_replace (opstr, " + ", "+", 1); } return opstr; } -R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { +RZ_API bool rz_parse_subvar(RzParse *p, RzAnalFunction *f, ut64 addr, int oplen, char *data, char *str, int len) { if (p->cur && p->cur->subvar) { return p->cur->subvar (p, f, addr, oplen, data, str, len); } @@ -142,6 +142,6 @@ R_API bool r_parse_subvar(RParse *p, RAnalFunction *f, ut64 addr, int oplen, cha } /* setters */ -R_API void r_parse_set_user_ptr(RParse *p, void *user) { +RZ_API void rz_parse_set_user_ptr(RzParse *p, void *user) { p->user = user; } diff --git a/libr/reg/Makefile b/librz/reg/Makefile similarity index 78% rename from libr/reg/Makefile rename to librz/reg/Makefile index 25cc6568e5..f769e1f4d4 100644 --- a/libr/reg/Makefile +++ b/librz/reg/Makefile @@ -1,7 +1,7 @@ include ../config.mk -NAME=r_reg -R2DEPS=r_util +NAME=rz_reg +R2DEPS=rz_util OBJS=reg.o arena.o rvalue.o rcond.o double.o profile.o include ../rules.mk diff --git a/libr/reg/arena.c b/librz/reg/arena.c similarity index 70% rename from libr/reg/arena.c rename to librz/reg/arena.c index 453f1fb821..5831a7bbec 100644 --- a/libr/reg/arena.c +++ b/librz/reg/arena.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include /* non-endian safe - used for raw mapping with system registers */ -R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size) { - RRegArena *arena; +RZ_API ut8 *rz_reg_get_bytes(RzReg *reg, int type, int *size) { + RzRegArena *arena; int i, sz, osize; ut8 *buf, *newbuf; if (size) { @@ -53,22 +53,22 @@ R_API ut8 *r_reg_get_bytes(RReg *reg, int type, int *size) { } /* deserialize ALL register types into buffer */ -/* XXX does the same as r_reg_get_bytes? */ -R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len) { +/* XXX does the same as rz_reg_get_bytes? */ +RZ_API bool rz_reg_read_regs(RzReg *reg, ut8 *buf, const int len) { int i, off = 0; - RRegArena *arena; + RzRegArena *arena; for (i = 0; i < R_REG_TYPE_LAST; i++) { if (reg->regset[i].arena) { arena = reg->regset[i].arena; } else { - arena = reg->regset[i].arena = R_NEW0 (RRegArena); + arena = reg->regset[i].arena = R_NEW0 (RzRegArena); if (!arena) { return false; } arena->size = len; arena->bytes = calloc (1, len); if (!arena->bytes) { - r_reg_arena_free (arena); + rz_reg_arena_free (arena); return false; } } @@ -88,10 +88,10 @@ R_API bool r_reg_read_regs(RReg *reg, ut8 *buf, const int len) { } /* TODO reduce number of return statements */ -R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8 *buf, const int len) { +RZ_API bool rz_reg_set_bytes(RzReg *reg, int type, const ut8 *buf, const int len) { int maxsz, minsz; - struct r_reg_set_t *regset; - RRegArena *arena; + struct rz_reg_set_t *regset; + RzRegArena *arena; if (len < 1 || !buf) { return false; } @@ -131,10 +131,10 @@ R_API bool r_reg_set_bytes(RReg *reg, int type, const ut8 *buf, const int len) { return false; } -R_API int r_reg_fit_arena(RReg *reg) { - RRegArena *arena; - RListIter *iter; - RRegItem *r; +RZ_API int rz_reg_fit_arena(RzReg *reg) { + RzRegArena *arena; + RzListIter *iter; + RzRegItem *r; int size, i, newsize; for (i = 0; i < R_REG_TYPE_LAST; i++) { @@ -143,7 +143,7 @@ R_API int r_reg_fit_arena(RReg *reg) { continue; } newsize = 0; - r_list_foreach (reg->regset[i].regs, iter, r) { + rz_list_foreach (reg->regset[i].regs, iter, r) { // XXX: bits2bytes doesnt seems to work fine size = BITS2BYTES (r->offset + r->size); newsize = R_MAX (size, newsize); @@ -166,8 +166,8 @@ R_API int r_reg_fit_arena(RReg *reg) { return true; } -R_API RRegArena *r_reg_arena_new(int size) { - RRegArena *arena = R_NEW0 (RRegArena); +RZ_API RzRegArena *rz_reg_arena_new(int size) { + RzRegArena *arena = R_NEW0 (RzRegArena); if (arena) { if (size < 1) { size = 1; @@ -181,23 +181,23 @@ R_API RRegArena *r_reg_arena_new(int size) { return arena; } -R_API void r_reg_arena_free(RRegArena *ra) { +RZ_API void rz_reg_arena_free(RzRegArena *ra) { if (ra) { free (ra->bytes); free (ra); } } -R_API void r_reg_arena_swap(RReg *reg, int copy) { +RZ_API void rz_reg_arena_swap(RzReg *reg, int copy) { /* XXX: swap current arena to head(previous arena) */ int i; for (i = 0; i < R_REG_TYPE_LAST; i++) { if (!reg->regset[i].pool) { continue; } - if (r_list_length (reg->regset[i].pool) > 1) { - RListIter *ia = reg->regset[i].cur; - RListIter *ib = reg->regset[i].pool->head; + if (rz_list_length (reg->regset[i].pool) > 1) { + RzListIter *ia = reg->regset[i].cur; + RzListIter *ib = reg->regset[i].pool->head; void *tmp = ia->data; ia->data = ib->data; ib->data = tmp; @@ -208,18 +208,18 @@ R_API void r_reg_arena_swap(RReg *reg, int copy) { } } -R_API void r_reg_arena_pop(RReg *reg) { - RRegArena *a; +RZ_API void rz_reg_arena_pop(RzReg *reg) { + RzRegArena *a; int i; for (i = 0; i < R_REG_TYPE_LAST; i++) { if (!reg->regset[i].pool) { continue; } - if (r_list_length (reg->regset[i].pool) < 2) { + if (rz_list_length (reg->regset[i].pool) < 2) { continue; } - a = r_list_pop (reg->regset[i].pool); - r_reg_arena_free (a); + a = rz_list_pop (reg->regset[i].pool); + rz_reg_arena_free (a); a = reg->regset[i].pool->tail->data; if (a) { reg->regset[i].arena = a; @@ -228,43 +228,43 @@ R_API void r_reg_arena_pop(RReg *reg) { } } -R_API int r_reg_arena_push(RReg *reg) { +RZ_API int rz_reg_arena_push(RzReg *reg) { int i; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = reg->regset[i].arena; // current arena + RzRegArena *a = reg->regset[i].arena; // current arena if (!a) { continue; } - RRegArena *b = r_reg_arena_new (a->size); // new arena + RzRegArena *b = rz_reg_arena_new (a->size); // new arena if (!b) { continue; } - //b->size == a->size always because of how r_reg_arena_new behave + //b->size == a->size always because of how rz_reg_arena_new behave if (a->bytes) { memcpy (b->bytes, a->bytes, b->size); } - r_list_push (reg->regset[i].pool, b); + rz_list_push (reg->regset[i].pool, b); reg->regset[i].arena = b; reg->regset[i].cur = reg->regset[i].pool->tail; } if (reg->regset[0].pool) { - return r_list_length (reg->regset[0].pool); + return rz_list_length (reg->regset[0].pool); } return 0; } -R_API void r_reg_arena_zero(RReg *reg) { +RZ_API void rz_reg_arena_zero(RzReg *reg) { int i; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegArena *a = reg->regset[i].arena; + RzRegArena *a = reg->regset[i].arena; if (a->size > 0) { memset (reg->regset[i].arena->bytes, 0, a->size); } } } -R_API ut8 *r_reg_arena_peek(RReg *reg) { - RRegSet *regset = r_reg_regset_get (reg, R_REG_TYPE_GPR); +RZ_API ut8 *rz_reg_arena_peek(RzReg *reg) { + RzRegSet *regset = rz_reg_regset_get (reg, R_REG_TYPE_GPR); if (!reg || !regset || !regset->arena || (regset->arena->size < 1)) { return NULL; } @@ -276,16 +276,16 @@ R_API ut8 *r_reg_arena_peek(RReg *reg) { return ret; } -R_API void r_reg_arena_poke(RReg *reg, const ut8 *ret) { - RRegSet *regset = r_reg_regset_get (reg, R_REG_TYPE_GPR); +RZ_API void rz_reg_arena_poke(RzReg *reg, const ut8 *ret) { + RzRegSet *regset = rz_reg_regset_get (reg, R_REG_TYPE_GPR); if (!ret || !regset || !regset->arena || !regset->arena->bytes) { return; } memcpy (regset->arena->bytes, ret, regset->arena->size); } -R_API ut8 *r_reg_arena_dup(RReg *reg, const ut8 *source) { - RRegSet *regset = r_reg_regset_get (reg, R_REG_TYPE_GPR); +RZ_API ut8 *rz_reg_arena_dup(RzReg *reg, const ut8 *source) { + RzRegSet *regset = rz_reg_regset_get (reg, R_REG_TYPE_GPR); if (!reg || !regset || !regset->arena || (regset->arena->size < 1)) { return NULL; } @@ -297,9 +297,9 @@ R_API ut8 *r_reg_arena_dup(RReg *reg, const ut8 *source) { return ret; } -R_API int r_reg_arena_set_bytes(RReg *reg, const char *str) { - str = r_str_trim_head_ro (str); - int len = r_hex_str_is_valid (str); +RZ_API int rz_reg_arena_set_bytes(RzReg *reg, const char *str) { + str = rz_str_trim_head_ro (str); + int len = rz_hex_str_is_valid (str); if (len == -1) { eprintf ("Invalid input\n"); return -1; @@ -310,7 +310,7 @@ R_API int r_reg_arena_set_bytes(RReg *reg, const char *str) { eprintf ("Failed to decode hex str.\n"); return -1; } - r_hex_str2bin (str, bin_str); + rz_hex_str2bin (str, bin_str); int i, n = 0; //n - cumulative sum of arena's sizes for (i = 0; i < R_REG_TYPE_LAST; i++) { @@ -318,22 +318,22 @@ R_API int r_reg_arena_set_bytes(RReg *reg, const char *str) { int bl = bin_str_len - n; //bytes left int bln = bl - n; if (bln > 0 && bln < sz) { - r_reg_set_bytes (reg, i, bin_str + n, bln); + rz_reg_set_bytes (reg, i, bin_str + n, bln); break; } - r_reg_set_bytes (reg, i, bin_str + n, bin_str_len - n); + rz_reg_set_bytes (reg, i, bin_str + n, bin_str_len - n); n += sz; } free (bin_str); return 0; } -R_API void r_reg_arena_shrink(RReg *reg) { - RListIter *iter; - RRegArena *a; +RZ_API void rz_reg_arena_shrink(RzReg *reg) { + RzListIter *iter; + RzRegArena *a; int i; for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].pool, iter, a) { + rz_list_foreach (reg->regset[i].pool, iter, a) { free (a->bytes); /* ha ha ha */ a->bytes = calloc (1024, 1); diff --git a/libr/reg/double.c b/librz/reg/double.c similarity index 60% rename from libr/reg/double.c rename to librz/reg/double.c index aa45639989..5759d681e6 100644 --- a/libr/reg/double.c +++ b/librz/reg/double.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2015 - pancake */ -#include -#include +#include +#include #if __SDB_WINDOWS__ #define CASTLDBL (double) @@ -12,8 +12,8 @@ // TODO: add support for 80bit floating point value // long double = 128 bit -R_API double r_reg_get_double(RReg *reg, RRegItem *item) { - RRegSet *regset; +RZ_API double rz_reg_get_double(RzReg *reg, RzRegItem *item) { + RzRegSet *regset; double vld = 0.0f; int off; double ret = 0.0f; @@ -30,17 +30,17 @@ R_API double r_reg_get_double(RReg *reg, RRegItem *item) { } break; default: - eprintf ("r_reg_set_double: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_set_double: Bit size %d not supported\n", item->size); return 0.0f; } return ret; } -R_API bool r_reg_set_double(RReg *reg, RRegItem *item, double value) { +RZ_API bool rz_reg_set_double(RzReg *reg, RzRegItem *item, double value) { ut8 *src; if (!item) { - eprintf ("r_reg_set_value: item is NULL\n"); + eprintf ("rz_reg_set_value: item is NULL\n"); return false; } switch (item->size) { @@ -49,22 +49,22 @@ R_API bool r_reg_set_double(RReg *reg, RRegItem *item, double value) { src = (ut8 *)&value; break; default: - eprintf ("r_reg_set_double: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_set_double: Bit size %d not supported\n", item->size); return false; } if (reg->regset[item->arena].arena->size - BITS2BYTES (item->offset) - BITS2BYTES (item->size) >= 0) { - r_mem_copybits (reg->regset[item->arena].arena->bytes + + rz_mem_copybits (reg->regset[item->arena].arena->bytes + BITS2BYTES (item->offset), src, item->size); return true; } - eprintf ("r_reg_set_value: Cannot set %s to %lf\n", item->name, value); + eprintf ("rz_reg_set_value: Cannot set %s to %lf\n", item->name, value); return false; } // long double = 80 bit -R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item) { - RRegSet *regset; +RZ_API long double rz_reg_get_longdouble(RzReg *reg, RzRegItem *item) { + RzRegSet *regset; long double vld = 0.0f; int off; long double ret = 0.0f; @@ -84,17 +84,17 @@ R_API long double r_reg_get_longdouble(RReg *reg, RRegItem *item) { } break; default: - eprintf ("r_reg_get_longdouble: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_get_longdouble: Bit size %d not supported\n", item->size); return 0.0f; } return ret; } -R_API bool r_reg_set_longdouble(RReg *reg, RRegItem *item, long double value) { +RZ_API bool rz_reg_set_longdouble(RzReg *reg, RzRegItem *item, long double value) { ut8 *src = NULL; if (!item) { - eprintf ("r_reg_set_value: item is NULL\n"); + eprintf ("rz_reg_set_value: item is NULL\n"); return false; } switch (item->size) { @@ -105,26 +105,26 @@ R_API bool r_reg_set_longdouble(RReg *reg, RRegItem *item, long double value) { src = (ut8 *)&value; break; default: - eprintf ("r_reg_set_longdouble: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_set_longdouble: Bit size %d not supported\n", item->size); return false; } if (reg->regset[item->arena].arena->size - BITS2BYTES (item->offset) - BITS2BYTES (item->size) >= 0) { - r_mem_copybits (reg->regset[item->arena].arena->bytes + + rz_mem_copybits (reg->regset[item->arena].arena->bytes + BITS2BYTES (item->offset), src, item->size); return true; } - eprintf ("r_reg_set_value: Cannot set %s to %" LDBLFMT "\n", item->name, CASTLDBL value); + eprintf ("rz_reg_set_value: Cannot set %s to %" LDBLFMT "\n", item->name, CASTLDBL value); return false; } /* floating point . deprecate maybe? */ -R_API float r_reg_get_float(RReg *reg, RRegItem *item) { +RZ_API float rz_reg_get_float(RzReg *reg, RzRegItem *item) { // TODO return 0.0f; } -R_API bool r_reg_set_float(RReg *reg, RRegItem *item, float value) { +RZ_API bool rz_reg_set_float(RzReg *reg, RzRegItem *item, float value) { return false; } diff --git a/libr/reg/meson.build b/librz/reg/meson.build similarity index 64% rename from libr/reg/meson.build rename to librz/reg/meson.build index 66298fc81e..d7b58d8012 100644 --- a/libr/reg/meson.build +++ b/librz/reg/meson.build @@ -1,4 +1,4 @@ -r_reg_sources = [ +rz_reg_sources = [ 'arena.c', 'rcond.c', 'double.c', @@ -7,27 +7,27 @@ r_reg_sources = [ 'rvalue.c', ] -r_reg = library('r_reg', r_reg_sources, +rz_reg = library('rz_reg', rz_reg_sources, include_directories: [platform_inc], c_args: library_cflags, - dependencies: [r_util_dep], + dependencies: [rz_util_dep], install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_reg_dep = declare_dependency(link_with: r_reg, +rz_reg_dep = declare_dependency(link_with: rz_reg, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_reg, - subdirs: 'libr', +pkgconfig_mod.generate(rz_reg, + subdirs: 'librz', version: r2_version, - name: 'r_reg', - filebase: 'r_reg', + name: 'rz_reg', + filebase: 'rz_reg', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/reg/p/x86-linux.regs b/librz/reg/p/x86-linux.regs similarity index 100% rename from libr/reg/p/x86-linux.regs rename to librz/reg/p/x86-linux.regs diff --git a/libr/reg/profile.c b/librz/reg/profile.c similarity index 68% rename from libr/reg/profile.c rename to librz/reg/profile.c index e3d469da20..397faae3eb 100644 --- a/libr/reg/profile.c +++ b/librz/reg/profile.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include -#include +#include +#include +#include -static const char *parse_alias(RReg *reg, char **tok, const int n) { +static const char *parse_alias(RzReg *reg, char **tok, const int n) { if (n == 2) { - int role = r_reg_get_name_idx (tok[0] + 1); - return r_reg_set_name (reg, role, tok[1]) + int role = rz_reg_get_name_idx (tok[0] + 1); + return rz_reg_set_name (reg, role, tok[1]) ? NULL : "Invalid alias"; } @@ -31,8 +31,8 @@ static ut64 parse_size(char *s, char **end) { return strtoul (s, end, 0) << 3; } -//TODO: implement bool r_reg_set_def_string() -static const char *parse_def(RReg *reg, char **tok, const int n) { +//TODO: implement bool rz_reg_set_def_string() +static const char *parse_def(RzReg *reg, char **tok, const int n) { char *end; int type, type2; @@ -44,11 +44,11 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { char *tok0 = strdup (tok[0]); char *at = tok0 + (p - tok[0]); *at++ = 0; - type = r_reg_type_by_name (tok0); - type2 = r_reg_type_by_name (at); + type = rz_reg_type_by_name (tok0); + type2 = rz_reg_type_by_name (at); free (tok0); } else { - type2 = type = r_reg_type_by_name (tok[0]); + type2 = type = rz_reg_type_by_name (tok[0]); /* Hack to put flags in the same arena as gpr */ if (type == R_REG_TYPE_FLG) { type2 = R_REG_TYPE_GPR; @@ -58,14 +58,14 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { return "Invalid register type"; } #if 1 - if (r_reg_get (reg, tok[1], R_REG_TYPE_ALL)) { + if (rz_reg_get (reg, tok[1], R_REG_TYPE_ALL)) { eprintf ("Ignoring duplicated register definition '%s'\n", tok[1]); return NULL; //return "Duplicate register definition"; } #endif - RRegItem *item = R_NEW0 (RRegItem); + RzRegItem *item = R_NEW0 (RzRegItem); if (!item) { return "Unable to allocate memory"; } @@ -75,7 +75,7 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { // All the numeric arguments are strictly checked item->size = parse_size (tok[2], &end); if (*end != '\0' || !item->size) { - r_reg_item_free (item); + rz_reg_item_free (item); return "Invalid size"; } if (!strcmp (tok[3], "?")) { @@ -84,12 +84,12 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { item->offset = parse_size (tok[3], &end); } if (*end != '\0') { - r_reg_item_free (item); + rz_reg_item_free (item); return "Invalid offset"; } item->packed_size = parse_size (tok[4], &end); if (*end != '\0') { - r_reg_item_free (item); + rz_reg_item_free (item); return "Invalid packed size"; } @@ -108,9 +108,9 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { item->arena = type2; if (!reg->regset[type2].regs) { - reg->regset[type2].regs = r_list_newf ((RListFree)r_reg_item_free); + reg->regset[type2].regs = rz_list_newf ((RzListFree)rz_reg_item_free); } - r_list_append (reg->regset[type2].regs, item); + rz_list_append (reg->regset[type2].regs, item); if (!reg->regset[type2].ht_regs) { reg->regset[type2].ht_regs = ht_pp_new0 (); } @@ -126,13 +126,13 @@ static const char *parse_def(RReg *reg, char **tok, const int n) { } #define PARSER_MAX_TOKENS 8 -R_API bool r_reg_set_profile_string(RReg *reg, const char *str) { +RZ_API bool rz_reg_set_profile_string(RzReg *reg, const char *str) { char *tok[PARSER_MAX_TOKENS]; char tmp[128]; int i, j, l; const char *p = str; - r_return_val_if_fail (reg && str, false); + rz_return_val_if_fail (reg && str, false); // Same profile, no need to change if (reg->reg_profile_str && !strcmp (reg->reg_profile_str, str)) { @@ -140,10 +140,10 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) { } // we should reset all the arenas before setting the new reg profile - r_reg_arena_pop (reg); + rz_reg_arena_pop (reg); // Purge the old registers - r_reg_free_internal (reg, true); - r_reg_arena_shrink (reg); + rz_reg_free_internal (reg, true); + rz_reg_arena_shrink (reg); // Cache the profile string reg->reg_profile_str = strdup (str); @@ -160,7 +160,7 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) { while (*q != '\n') { q++; } - reg->reg_profile_cmt = r_str_appendlen ( + reg->reg_profile_cmt = rz_str_appendlen ( reg->reg_profile_cmt, p, (int)(q - p) + 1); p = q; continue; @@ -216,15 +216,15 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) { __FUNCTION__, l, r); //eprintf ("(%s)\n", str); // Clean up - r_reg_free_internal (reg, false); + rz_reg_free_internal (reg, false); return false; } } } while (*p++); reg->size = 0; for (i = 0; i < R_REG_TYPE_LAST; i++) { - RRegSet *rs = ®->regset[i]; - //eprintf ("* arena %s size %d\n", r_reg_get_type (i), rs->arena->size); + RzRegSet *rs = ®->regset[i]; + //eprintf ("* arena %s size %d\n", rz_reg_get_type (i), rs->arena->size); if (rs && rs->arena) { reg->size += rs->arena->size; } @@ -234,38 +234,38 @@ R_API bool r_reg_set_profile_string(RReg *reg, const char *str) { // reg->size += 8 - (reg->size & 7); //} //reg->size >>= 3; // bits to bytes (divide by 8) - r_reg_fit_arena (reg); + rz_reg_fit_arena (reg); // dup the last arena to allow regdiffing - r_reg_arena_push (reg); - r_reg_reindex (reg); + rz_reg_arena_push (reg); + rz_reg_reindex (reg); // reset arenas return true; } -R_API bool r_reg_set_profile(RReg *reg, const char *profile) { - r_return_val_if_fail (reg && profile, NULL); +RZ_API bool rz_reg_set_profile(RzReg *reg, const char *profile) { + rz_return_val_if_fail (reg && profile, NULL); char *base, *file; - char *str = r_file_slurp (profile, NULL); + char *str = rz_file_slurp (profile, NULL); if (!str) { - base = r_sys_getenv (R_LIB_ENV); + base = rz_sys_getenv (R_LIB_ENV); if (base) { - file = r_str_append (base, profile); - str = r_file_slurp (file, NULL); + file = rz_str_append (base, profile); + str = rz_file_slurp (file, NULL); free (file); } } if (!str) { - eprintf ("r_reg_set_profile: Cannot find '%s'\n", profile); + eprintf ("rz_reg_set_profile: Cannot find '%s'\n", profile); return false; } - bool ret = r_reg_set_profile_string (reg, str); + bool ret = rz_reg_set_profile_string (reg, str); free (str); return ret; } -static char *gdb_to_r2_profile(const char *gdb) { - r_return_val_if_fail (gdb, NULL); - RStrBuf *sb = r_strbuf_new (""); +static char *gdb_to_rz_profile(const char *gdb) { + rz_return_val_if_fail (gdb, NULL); + RStrBuf *sb = rz_strbuf_new (""); if (!sb) { return NULL; } @@ -276,10 +276,10 @@ static char *gdb_to_r2_profile(const char *gdb) { int number, rel, offset, size, type_bits, ret; // Every line is - // Name Number Rel Offset Size Type Groups - char *ptr = r_str_trim_head_ro (gdb); + char *ptr = rz_str_trim_head_ro (gdb); // It's possible someone includes the heading line too. Skip it - if (r_str_startswith (ptr, "Name")) { + if (rz_str_startswith (ptr, "Name")) { if (!(ptr = strchr (ptr, '\n'))) { return NULL; } @@ -308,7 +308,7 @@ static char *gdb_to_r2_profile(const char *gdb) { continue; } // If name is '', then skip - if (r_str_startswith (name, "''")) { + if (rz_str_startswith (name, "''")) { if (!ptr1) { break; } @@ -330,23 +330,23 @@ static char *gdb_to_r2_profile(const char *gdb) { if ((gptr1 = strchr (gptr, ','))) { *gptr1 = '\0'; } - if (r_str_startswith (gptr, "general")) { + if (rz_str_startswith (gptr, "general")) { type_bits |= gpr; - } else if (r_str_startswith (gptr, "all")) { + } else if (rz_str_startswith (gptr, "all")) { type_bits |= all; - } else if (r_str_startswith (gptr, "save")) { + } else if (rz_str_startswith (gptr, "save")) { type_bits |= save; - } else if (r_str_startswith (gptr, "restore")) { + } else if (rz_str_startswith (gptr, "restore")) { type_bits |= restore; - } else if (r_str_startswith (gptr, "float")) { + } else if (rz_str_startswith (gptr, "float")) { type_bits |= float_; - } else if (r_str_startswith (gptr, "sse")) { + } else if (rz_str_startswith (gptr, "sse")) { type_bits |= sse; - } else if (r_str_startswith (gptr, "mmx")) { + } else if (rz_str_startswith (gptr, "mmx")) { type_bits |= mmx; - } else if (r_str_startswith (gptr, "vector")) { + } else if (rz_str_startswith (gptr, "vector")) { type_bits |= vector; - } else if (r_str_startswith (gptr, "system")) { + } else if (rz_str_startswith (gptr, "system")) { type_bits |= system; } if (!gptr1) { @@ -367,7 +367,7 @@ static char *gdb_to_r2_profile(const char *gdb) { type_bits |= gpr; } // Print line - r_strbuf_appendf (sb, "%s\t%s\t.%d\t%d\t0\n", + rz_strbuf_appendf (sb, "%s\t%s\t.%d\t%d\t0\n", // Ref: Comment above about more register type mappings ((type_bits & mmx) || (type_bits & float_) || (type_bits & sse)) ? "fpu" : "gpr", name, size * 8, offset); @@ -378,53 +378,53 @@ static char *gdb_to_r2_profile(const char *gdb) { ptr = ptr1 + 1; continue; } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_reg_parse_gdb_profile(const char *profile_file) { +RZ_API char *rz_reg_parse_gdb_profile(const char *profile_file) { char *base, *str = NULL; - if (!(str = r_file_slurp (profile_file, NULL))) { - char *base = r_sys_getenv (R_LIB_ENV); + if (!(str = rz_file_slurp (profile_file, NULL))) { + char *base = rz_sys_getenv (R_LIB_ENV); if (base) { - char *file = r_str_appendf (base, R_SYS_DIR "%s", profile_file); + char *file = rz_str_appendf (base, R_SYS_DIR "%s", profile_file); if (file) { - str = r_file_slurp (file, NULL); + str = rz_file_slurp (file, NULL); free (file); } free (base); } } if (str) { - char *ret = gdb_to_r2_profile (str); + char *ret = gdb_to_rz_profile (str); free (str); return ret; } - eprintf ("r_reg_parse_gdb_profile: Cannot find '%s'\n", profile_file); + eprintf ("rz_reg_parse_gdb_profile: Cannot find '%s'\n", profile_file); return NULL; } -R_API char *r_reg_profile_to_cc(RReg *reg) { - const char *r0 = r_reg_get_name_by_type (reg, "R0"); - const char *a0 = r_reg_get_name_by_type (reg, "A0"); - const char *a1 = r_reg_get_name_by_type (reg, "A1"); - const char *a2 = r_reg_get_name_by_type (reg, "A2"); - const char *a3 = r_reg_get_name_by_type (reg, "A3"); +RZ_API char *rz_reg_profile_to_cc(RzReg *reg) { + const char *r0 = rz_reg_get_name_by_type (reg, "R0"); + const char *a0 = rz_reg_get_name_by_type (reg, "A0"); + const char *a1 = rz_reg_get_name_by_type (reg, "A1"); + const char *a2 = rz_reg_get_name_by_type (reg, "A2"); + const char *a3 = rz_reg_get_name_by_type (reg, "A3"); // it is mandatory to have at least =A0 defined in the reg profile // this will be enforced in reg/profile at parsing time - r_return_val_if_fail (a0, NULL); + rz_return_val_if_fail (a0, NULL); if (!r0) { r0 = a0; } if (a3 && a2 && a1) { - return r_str_newf ("%s reg(%s, %s, %s, %s)", r0, a0, a1, a2, a3); + return rz_str_newf ("%s reg(%s, %s, %s, %s)", r0, a0, a1, a2, a3); } if (a2 && a1) { - return r_str_newf ("%s reg(%s, %s, %s)", r0, a0, a1, a2); + return rz_str_newf ("%s reg(%s, %s, %s)", r0, a0, a1, a2); } if (a1) { - return r_str_newf ("%s reg(%s, %s)", r0, a0, a1); + return rz_str_newf ("%s reg(%s, %s)", r0, a0, a1); } - return r_str_newf ("%s reg(%s)", r0, a0); + return rz_str_newf ("%s reg(%s)", r0, a0); } diff --git a/libr/reg/rcond.c b/librz/reg/rcond.c similarity index 69% rename from libr/reg/rcond.c rename to librz/reg/rcond.c index 79ddded51e..bb57bd83a8 100644 --- a/libr/reg/rcond.c +++ b/librz/reg/rcond.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2014-2019 - pancake */ -#include +#include #undef Z #undef S @@ -13,13 +13,13 @@ #define O f->o #define P f->p -R_API RRegItem *r_reg_cond_get(RReg *reg, const char *name) { +RZ_API RzRegItem *rz_reg_cond_get(RzReg *reg, const char *name) { int i = R_REG_TYPE_GPR; - RListIter *iter; - RRegItem *r; - r_return_val_if_fail (reg && name, NULL); + RzListIter *iter; + RzRegItem *r; + rz_return_val_if_fail (reg && name, NULL); - r_list_foreach (reg->regset[i].regs, iter, r) { + rz_list_foreach (reg->regset[i].regs, iter, r) { if (r->flags && !strcmp (name, r->flags)) { return r; } @@ -27,21 +27,21 @@ R_API RRegItem *r_reg_cond_get(RReg *reg, const char *name) { return NULL; } -R_API int r_reg_cond_get_value(RReg *r, const char *name) { - return (int)r_reg_get_value (r, r_reg_cond_get (r, name)) ? 1 : 0; +RZ_API int rz_reg_cond_get_value(RzReg *r, const char *name) { + return (int)rz_reg_get_value (r, rz_reg_cond_get (r, name)) ? 1 : 0; } -R_API bool r_reg_cond_set(RReg *r, const char *name, bool val) { - RRegItem *item = r_reg_cond_get (r, name); +RZ_API bool rz_reg_cond_set(RzReg *r, const char *name, bool val) { + RzRegItem *item = rz_reg_cond_get (r, name); if (item) { - r_reg_set_value (r, item, val); + rz_reg_set_value (r, item, val); return true; } // eprintf ("Cannot find '%s'\n", name); return false; } -R_API const char *r_reg_cond_to_string(int n) { +RZ_API const char *rz_reg_cond_to_string(int n) { const char *cs[] = { "eq", "ne", "cf", "neg", "of", "hi", "he", "lo", "loe", "ge", "gt", "lt", "le" @@ -52,7 +52,7 @@ R_API const char *r_reg_cond_to_string(int n) { return cs[n]; } -R_API int r_reg_cond_from_string(const char *str) { +RZ_API int rz_reg_cond_from_string(const char *str) { if (!strcmp (str, "eq")) { return R_REG_COND_EQ; } @@ -112,7 +112,7 @@ R_API int r_reg_cond_from_string(const char *str) { return -1; } -R_API int r_reg_cond_bits(RReg *r, int type, RRegFlags *f) { +RZ_API int rz_reg_cond_bits(RzReg *r, int type, RzRegFlags *f) { switch (type) { case R_REG_COND_EQ: return Z; case R_REG_COND_NE: return !Z; @@ -135,7 +135,7 @@ R_API int r_reg_cond_bits(RReg *r, int type, RRegFlags *f) { return false; } -R_API bool r_reg_cond_bits_set(RReg *r, int type, RRegFlags *f, bool v) { +RZ_API bool rz_reg_cond_bits_set(RzReg *r, int type, RzRegFlags *f, bool v) { switch (type) { case R_REG_COND_EQ: Z = v; break; case R_REG_COND_NE: Z = !v; break; @@ -223,32 +223,32 @@ R_API bool r_reg_cond_bits_set(RReg *r, int type, RRegFlags *f, bool v) { return true; } -R_API int r_reg_cond(RReg *r, int type) { - RRegFlags f = { 0 }; - r_reg_cond_retrieve (r, &f); - return r_reg_cond_bits (r, type, &f); +RZ_API int rz_reg_cond(RzReg *r, int type) { + RzRegFlags f = { 0 }; + rz_reg_cond_retrieve (r, &f); + return rz_reg_cond_bits (r, type, &f); } -R_API RRegFlags *r_reg_cond_retrieve(RReg *r, RRegFlags *f) { +RZ_API RzRegFlags *rz_reg_cond_retrieve(RzReg *r, RzRegFlags *f) { if (!f) { - f = R_NEW0 (RRegFlags); + f = R_NEW0 (RzRegFlags); } if (!f) { return NULL; } - f->s = r_reg_cond_get_value (r, "sign"); // sign, negate flag, less than zero - f->z = r_reg_cond_get_value (r, "zero"); // zero flag - f->c = r_reg_cond_get_value (r, "carry"); // carry flag - f->o = r_reg_cond_get_value (r, "overflow"); // overflow flag - f->p = r_reg_cond_get_value (r, "parity"); // parity // intel only + f->s = rz_reg_cond_get_value (r, "sign"); // sign, negate flag, less than zero + f->z = rz_reg_cond_get_value (r, "zero"); // zero flag + f->c = rz_reg_cond_get_value (r, "carry"); // carry flag + f->o = rz_reg_cond_get_value (r, "overflow"); // overflow flag + f->p = rz_reg_cond_get_value (r, "parity"); // parity // intel only return f; } -R_API void r_reg_cond_apply(RReg *r, RRegFlags *f) { - r_return_if_fail (r && f); - r_reg_cond_set (r, "sign", f->s); - r_reg_cond_set (r, "zero", f->z); - r_reg_cond_set (r, "carry", f->c); - r_reg_cond_set (r, "overflow", f->o); - r_reg_cond_set (r, "parity", f->p); +RZ_API void rz_reg_cond_apply(RzReg *r, RzRegFlags *f) { + rz_return_if_fail (r && f); + rz_reg_cond_set (r, "sign", f->s); + rz_reg_cond_set (r, "zero", f->z); + rz_reg_cond_set (r, "carry", f->c); + rz_reg_cond_set (r, "overflow", f->o); + rz_reg_cond_set (r, "parity", f->p); } diff --git a/libr/reg/reg.c b/librz/reg/reg.c similarity index 57% rename from libr/reg/reg.c rename to librz/reg/reg.c index ff47c829a4..17fcee1b68 100644 --- a/libr/reg/reg.c +++ b/librz/reg/reg.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include -#include +#include +#include -R_LIB_VERSION (r_reg); +R_LIB_VERSION (rz_reg); static const char *types[R_REG_TYPE_LAST + 1] = { "gpr", "drx", "fpu", "mmx", "xmm", "ymm", "flg", "seg", NULL @@ -12,13 +12,13 @@ static const char *types[R_REG_TYPE_LAST + 1] = { // Take the 32bits name of a register, and return the 64 bit name of it. // If there is no equivalent 64 bit register return NULL. // SLOW -R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32) { +RZ_API const char *rz_reg_32_to_64(RzReg *reg, const char *rreg32) { int i, j = -1; - RListIter *iter; - RRegItem *item; + RzListIter *iter; + RzRegItem *item; for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].regs, iter, item) { - if (item->size == 32 && !r_str_casecmp (rreg32, item->name)) { + rz_list_foreach (reg->regset[i].regs, iter, item) { + if (item->size == 32 && !rz_str_casecmp (rreg32, item->name)) { j = item->offset; break; } @@ -26,7 +26,7 @@ R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32) { } if (j != -1) { for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].regs, iter, item) { + rz_list_foreach (reg->regset[i].regs, iter, item) { if (item->offset == j && item->size == 64) { return item->name; } @@ -39,13 +39,13 @@ R_API const char *r_reg_32_to_64(RReg *reg, const char *rreg32) { // Take the 64 bits name of a register, and return the 32 bit name of it. // If there is no equivalent 32 bit register return NULL. // SLOW -R_API const char *r_reg_64_to_32(RReg *reg, const char *rreg64) { +RZ_API const char *rz_reg_64_to_32(RzReg *reg, const char *rreg64) { int i, j = -1; - RListIter *iter; - RRegItem *item; + RzListIter *iter; + RzRegItem *item; for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].regs, iter, item) { - if (item->size == 64 && !r_str_casecmp (rreg64, item->name)) { + rz_list_foreach (reg->regset[i].regs, iter, item) { + if (item->size == 64 && !rz_str_casecmp (rreg64, item->name)) { j = item->offset; break; } @@ -53,7 +53,7 @@ R_API const char *r_reg_64_to_32(RReg *reg, const char *rreg64) { } if (j != -1) { for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].regs, iter, item) { + rz_list_foreach (reg->regset[i].regs, iter, item) { if (item->offset == j && item->size == 32) { return item->name; } @@ -63,17 +63,17 @@ R_API const char *r_reg_64_to_32(RReg *reg, const char *rreg64) { return NULL; } -R_API const char *r_reg_get_type(int idx) { +RZ_API const char *rz_reg_get_type(int idx) { return (idx >= 0 && idx < R_REG_TYPE_LAST) ? types[idx] : NULL; } -R_API const char *r_reg_get_name_by_type(RReg *reg, const char *alias_name) { - const int n = r_reg_get_name_idx (alias_name); - return (n != -1)? r_reg_get_name (reg, n): NULL; +RZ_API const char *rz_reg_get_name_by_type(RzReg *reg, const char *alias_name) { + const int n = rz_reg_get_name_idx (alias_name); + return (n != -1)? rz_reg_get_name (reg, n): NULL; } -R_API int r_reg_type_by_name(const char *str) { - r_return_val_if_fail (str, -1); +RZ_API int rz_reg_type_by_name(const char *str) { + rz_return_val_if_fail (str, -1); int i; for (i = 0; i < R_REG_TYPE_LAST && types[i]; i++) { if (!strcmp (types[i], str)) { @@ -86,14 +86,14 @@ R_API int r_reg_type_by_name(const char *str) { return -1; } -R_API void r_reg_item_free(RRegItem *item) { +RZ_API void rz_reg_item_free(RzRegItem *item) { free (item->name); free (item->flags); free (item); } -R_API int r_reg_get_name_idx(const char *type) { - r_return_val_if_fail (type, -1); +RZ_API int rz_reg_get_name_idx(const char *type) { + rz_return_val_if_fail (type, -1); if (type[0] && type[1] && !type[2]) switch (*type | (type[1] << 8)) { /* flags */ @@ -128,16 +128,16 @@ R_API int r_reg_get_name_idx(const char *type) { return -1; } -R_API bool r_reg_set_name(RReg *reg, int role, const char *name) { - r_return_val_if_fail (reg && name, false); +RZ_API bool rz_reg_set_name(RzReg *reg, int role, const char *name) { + rz_return_val_if_fail (reg && name, false); if (role >= 0 && role < R_REG_NAME_LAST) { - reg->name[role] = r_str_dup (reg->name[role], name); + reg->name[role] = rz_str_dup (reg->name[role], name); return true; } return false; } -R_API const char *r_reg_get_name(RReg *reg, int role) { +RZ_API const char *rz_reg_get_name(RzReg *reg, int role) { if (reg && role >= 0 && role < R_REG_NAME_LAST) { return reg->name[role]; } @@ -153,18 +153,18 @@ static const char *roles[R_REG_NAME_LAST + 1] = { NULL }; -R_API const char *r_reg_get_role(int role) { +RZ_API const char *rz_reg_get_role(int role) { if (role >= 0 && role < R_REG_NAME_LAST) { return roles[role]; } return NULL; } -R_API void r_reg_free_internal(RReg *reg, bool init) { - r_return_if_fail (reg); +RZ_API void rz_reg_free_internal(RzReg *reg, bool init) { + rz_return_if_fail (reg); ut32 i; - r_list_free (reg->roregs); + rz_list_free (reg->roregs); reg->roregs = NULL; R_FREE (reg->reg_profile_str); R_FREE (reg->reg_profile_cmt); @@ -181,62 +181,62 @@ R_API void r_reg_free_internal(RReg *reg, bool init) { continue; } if (init) { - r_list_free (reg->regset[i].regs); - reg->regset[i].regs = r_list_newf ((RListFree)r_reg_item_free); + rz_list_free (reg->regset[i].regs); + reg->regset[i].regs = rz_list_newf ((RzListFree)rz_reg_item_free); } else { - r_list_free (reg->regset[i].regs); + rz_list_free (reg->regset[i].regs); reg->regset[i].regs = NULL; // Ensure arena is freed and its registered in the pool - if (!r_list_delete_data (reg->regset[i].pool, reg->regset[i].arena)) { - r_reg_arena_free (reg->regset[i].arena); + if (!rz_list_delete_data (reg->regset[i].pool, reg->regset[i].arena)) { + rz_reg_arena_free (reg->regset[i].arena); } reg->regset[i].arena = NULL; - r_list_free (reg->regset[i].pool); + rz_list_free (reg->regset[i].pool); reg->regset[i].pool = NULL; } } if (!init) { - r_list_free (reg->allregs); + rz_list_free (reg->allregs); reg->allregs = NULL; } reg->size = 0; } -static int regcmp(RRegItem *a, RRegItem *b) { +static int regcmp(RzRegItem *a, RzRegItem *b) { int offa = (a->offset * 16) + a->size; int offb = (b->offset * 16) + b->size; return (offa > offb) - (offa < offb); } -R_API void r_reg_reindex(RReg *reg) { +RZ_API void rz_reg_reindex(RzReg *reg) { int i, index; - RListIter *iter; - RRegItem *r; - RList *all = r_list_newf (NULL); + RzListIter *iter; + RzRegItem *r; + RzList *all = rz_list_newf (NULL); for (i = 0; i < R_REG_TYPE_LAST; i++) { - r_list_foreach (reg->regset[i].regs, iter, r) { - r_list_append (all, r); + rz_list_foreach (reg->regset[i].regs, iter, r) { + rz_list_append (all, r); } } - r_list_sort (all, (RListComparator)regcmp); + rz_list_sort (all, (RzListComparator)regcmp); index = 0; - r_list_foreach (all, iter, r) { + rz_list_foreach (all, iter, r) { r->index = index++; } - r_list_free (reg->allregs); + rz_list_free (reg->allregs); reg->allregs = all; } -R_API RRegItem *r_reg_index_get(RReg *reg, int idx) { - RRegItem *r; - RListIter *iter; +RZ_API RzRegItem *rz_reg_index_get(RzReg *reg, int idx) { + RzRegItem *r; + RzListIter *iter; if (idx < 0) { return NULL; } if (!reg->allregs) { - r_reg_reindex (reg); + rz_reg_reindex (reg); } - r_list_foreach (reg->allregs, iter, r) { + rz_list_foreach (reg->allregs, iter, r) { if (r->index == idx) { return r; } @@ -244,46 +244,46 @@ R_API RRegItem *r_reg_index_get(RReg *reg, int idx) { return NULL; } -R_API void r_reg_free(RReg *reg) { +RZ_API void rz_reg_free(RzReg *reg) { if (reg) { - r_reg_free_internal (reg, false); + rz_reg_free_internal (reg, false); free (reg); } } -R_API RReg *r_reg_new(void) { - RRegArena *arena; - RReg *reg = R_NEW0 (RReg); +RZ_API RzReg *rz_reg_new(void) { + RzRegArena *arena; + RzReg *reg = R_NEW0 (RzReg); int i; if (!reg) { return NULL; } for (i = 0; i < R_REG_TYPE_LAST; i++) { - arena = r_reg_arena_new (0); + arena = rz_reg_arena_new (0); if (!arena) { free (reg); return NULL; } - reg->regset[i].pool = r_list_newf ((RListFree)r_reg_arena_free); - reg->regset[i].regs = r_list_newf ((RListFree)r_reg_item_free); - r_list_push (reg->regset[i].pool, arena); + reg->regset[i].pool = rz_list_newf ((RzListFree)rz_reg_arena_free); + reg->regset[i].regs = rz_list_newf ((RzListFree)rz_reg_item_free); + rz_list_push (reg->regset[i].pool, arena); reg->regset[i].arena = arena; } - r_reg_arena_push (reg); + rz_reg_arena_push (reg); for (i = 0; i < R_REG_TYPE_LAST; i++) { - reg->regset[i].cur = r_list_tail (reg->regset[i].pool); + reg->regset[i].cur = rz_list_tail (reg->regset[i].pool); } return reg; } -R_API bool r_reg_is_readonly(RReg *reg, RRegItem *item) { +RZ_API bool rz_reg_is_readonly(RzReg *reg, RzRegItem *item) { const char *name; - RListIter *iter; + RzListIter *iter; if (!reg->roregs) { return false; } // XXX O(n) - r_list_foreach (reg->roregs, iter, name) { + rz_list_foreach (reg->roregs, iter, name) { if (!strcmp (item->name, name)) { return true; } @@ -291,21 +291,21 @@ R_API bool r_reg_is_readonly(RReg *reg, RRegItem *item) { return false; } -R_API ut64 r_reg_setv(RReg *reg, const char *name, ut64 val) { - r_return_val_if_fail (reg && name, UT64_MAX); - RRegItem *ri = r_reg_get (reg, name, -1); - return ri? r_reg_set_value (reg, ri, val): UT64_MAX; +RZ_API ut64 rz_reg_setv(RzReg *reg, const char *name, ut64 val) { + rz_return_val_if_fail (reg && name, UT64_MAX); + RzRegItem *ri = rz_reg_get (reg, name, -1); + return ri? rz_reg_set_value (reg, ri, val): UT64_MAX; } -R_API ut64 r_reg_getv(RReg *reg, const char *name) { - r_return_val_if_fail (reg && name, UT64_MAX); - RRegItem *ri = r_reg_get (reg, name, -1); - return ri? r_reg_get_value (reg, ri): UT64_MAX; +RZ_API ut64 rz_reg_getv(RzReg *reg, const char *name) { + rz_return_val_if_fail (reg && name, UT64_MAX); + RzRegItem *ri = rz_reg_get (reg, name, -1); + return ri? rz_reg_get_value (reg, ri): UT64_MAX; } -R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type) { +RZ_API RzRegItem *rz_reg_get(RzReg *reg, const char *name, int type) { int i, e; - r_return_val_if_fail (reg && name, NULL); + rz_return_val_if_fail (reg && name, NULL); //TODO: define flag register as R_REG_TYPE_FLG if (type == R_REG_TYPE_FLG) { type = R_REG_TYPE_GPR; @@ -313,9 +313,9 @@ R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type) { if (type == -1) { i = 0; e = R_REG_TYPE_LAST; - int alias = r_reg_get_name_idx (name); + int alias = rz_reg_get_name_idx (name); if (alias != -1) { - const char *nname = r_reg_get_name (reg, alias); + const char *nname = rz_reg_get_name (reg, alias); if (nname) { name = nname; } @@ -328,7 +328,7 @@ R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type) { HtPP *pp = reg->regset[i].ht_regs; if (pp) { bool found = false; - RRegItem *item = ht_pp_find (pp, name, &found); + RzRegItem *item = ht_pp_find (pp, name, &found); if (found) { return item; } @@ -337,19 +337,19 @@ R_API RRegItem *r_reg_get(RReg *reg, const char *name, int type) { return NULL; } -R_API RList *r_reg_get_list(RReg *reg, int type) { +RZ_API RzList *rz_reg_get_list(RzReg *reg, int type) { if (type == R_REG_TYPE_ALL) { return reg->allregs; } - RList *regs; + RzList *regs; int i, mask; if (type < 0 || type > (R_REG_TYPE_LAST - 1)) { return NULL; } regs = reg->regset[type].regs; - if (r_list_length (regs) == 0) { + if (rz_list_length (regs) == 0) { mask = ((int)1 << type); for (i = 0; i < R_REG_TYPE_LAST; i++) { if (reg->regset[i].maskregstype & mask) { @@ -362,12 +362,12 @@ R_API RList *r_reg_get_list(RReg *reg, int type) { } // TODO regsize is in bits, delta in bytes, maybe we should standarize this.. -R_API RRegItem *r_reg_get_at(RReg *reg, int type, int regsize, int delta) { - r_return_val_if_fail (reg, NULL); - RList *list = r_reg_get_list (reg, type); - RRegItem *ri; - RListIter *iter; - r_list_foreach (list, iter, ri) { +RZ_API RzRegItem *rz_reg_get_at(RzReg *reg, int type, int regsize, int delta) { + rz_return_val_if_fail (reg, NULL); + RzList *list = rz_reg_get_list (reg, type); + RzRegItem *ri; + RzListIter *iter; + rz_list_foreach (list, iter, ri) { if (ri->size == regsize) { if (BITS2BYTES (ri->offset) == delta) { return ri; @@ -378,18 +378,18 @@ R_API RRegItem *r_reg_get_at(RReg *reg, int type, int regsize, int delta) { } /* return the next register in the current regset that differs from */ -R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8 *buf, int buflen, RRegItem *prev_ri, int regsize) { - r_return_val_if_fail (reg && buf, NULL); +RZ_API RzRegItem *rz_reg_next_diff(RzReg *reg, int type, const ut8 *buf, int buflen, RzRegItem *prev_ri, int regsize) { + rz_return_val_if_fail (reg && buf, NULL); if (type < 0 || type > (R_REG_TYPE_LAST - 1)) { return NULL; } - RRegArena *arena = reg->regset[type].arena; + RzRegArena *arena = reg->regset[type].arena; int prev_offset = prev_ri ? (prev_ri->offset / 8) + (prev_ri->size / 8) : 0; - RList *list = reg->regset[type].regs; - RRegItem *ri; - RListIter *iter; + RzList *list = reg->regset[type].regs; + RzRegItem *ri; + RzListIter *iter; int offset; - r_list_foreach (list, iter, ri) { + rz_list_foreach (list, iter, ri) { offset = ri->offset / 8; if (offset > prev_offset) { if (memcmp (arena->bytes + offset, buf + offset, ri->size / 8)) { @@ -400,11 +400,11 @@ R_API RRegItem *r_reg_next_diff(RReg *reg, int type, const ut8 *buf, int buflen, return NULL; } -R_API RRegSet *r_reg_regset_get(RReg *r, int type) { - r_return_val_if_fail (r, NULL); +RZ_API RzRegSet *rz_reg_regset_get(RzReg *r, int type) { + rz_return_val_if_fail (r, NULL); if (type < 0 || type >= R_REG_TYPE_LAST) { return NULL; } - RRegSet *rs = &r->regset[type]; + RzRegSet *rs = &r->regset[type]; return rs->arena ? rs : NULL; } diff --git a/libr/reg/rvalue.c b/librz/reg/rvalue.c similarity index 59% rename from libr/reg/rvalue.c rename to librz/reg/rvalue.c index 36af17bfed..89b92cc3c4 100644 --- a/libr/reg/rvalue.c +++ b/librz/reg/rvalue.c @@ -1,23 +1,23 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include -#include +#include +#include typedef ut32 ut27; -static ut27 r_read_me27(const ut8 *buf, int boff) { +static ut27 rz_read_me27(const ut8 *buf, int boff) { ut27 ret = 0; - r_mem_copybits_delta ((ut8 *)&ret, 18, buf, boff, 9); - r_mem_copybits_delta ((ut8 *)&ret, 9, buf, boff + 9, 9); - r_mem_copybits_delta ((ut8 *)&ret, 0, buf, boff + 18, 9); + rz_mem_copybits_delta ((ut8 *)&ret, 18, buf, boff, 9); + rz_mem_copybits_delta ((ut8 *)&ret, 9, buf, boff + 9, 9); + rz_mem_copybits_delta ((ut8 *)&ret, 0, buf, boff + 18, 9); return ret; } -R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { - r_return_val_if_fail (reg && item, 0); +RZ_API ut64 rz_reg_get_value_big(RzReg *reg, RzRegItem *item, utX *val) { + rz_return_val_if_fail (reg && item, 0); ut64 ret = 0LL; int off = BITS2BYTES (item->offset); - RRegSet *regset = ®->regset[item->arena]; + RzRegSet *regset = ®->regset[item->arena]; if (!regset->arena) { return 0LL; } @@ -27,7 +27,7 @@ R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { val->v80.Low = *((ut64 *)(regset->arena->bytes + off)); val->v80.High = *((ut16 *)(regset->arena->bytes + off + 8)); } else { - eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + eprintf ("rz_reg_get_value: null or oob arena for current regset\n"); } ret = val->v80.Low; break; @@ -36,7 +36,7 @@ R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { val->v96.Low = *((ut64 *)(regset->arena->bytes + off)); val->v96.High = *((ut32 *)(regset->arena->bytes + off + 8)); } else { - eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + eprintf ("rz_reg_get_value: null or oob arena for current regset\n"); } ret = val->v96.Low; break; @@ -45,7 +45,7 @@ R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { val->v128.Low = *((ut64 *)(regset->arena->bytes + off)); val->v128.High = *((ut64 *)(regset->arena->bytes + off + 8)); } else { - eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + eprintf ("rz_reg_get_value: null or oob arena for current regset\n"); } ret = val->v128.Low; break; @@ -56,24 +56,24 @@ R_API ut64 r_reg_get_value_big(RReg *reg, RRegItem *item, utX *val) { val->v256.High.Low = *((ut64 *)(regset->arena->bytes + off + 16)); val->v256.High.High = *((ut64 *)(regset->arena->bytes + off + 24)); } else { - eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + eprintf ("rz_reg_get_value: null or oob arena for current regset\n"); } ret = val->v256.Low.Low; break; default: - eprintf ("r_reg_get_value_big: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_get_value_big: Bit size %d not supported\n", item->size); break; } return ret; } -R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { - r_return_val_if_fail (reg && item, 0); +RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item) { + rz_return_val_if_fail (reg && item, 0); if (!reg || !item || item->offset == -1) { return 0LL; } int off = BITS2BYTES (item->offset); - RRegSet *regset = ®->regset[item->arena]; + RzRegSet *regset = ®->regset[item->arena]; if (!regset->arena) { return 0LL; } @@ -90,99 +90,99 @@ R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { } break; case 4: if (regset->arena->size - off - 1 >= 0) { - return (r_read_at_ble8 (regset->arena->bytes, off)) & 0xF; + return (rz_read_at_ble8 (regset->arena->bytes, off)) & 0xF; } break; case 8: if (regset->arena->size - off - 1 >= 0) { - return r_read_at_ble8 (regset->arena->bytes, off); + return rz_read_at_ble8 (regset->arena->bytes, off); } break; case 16: if (regset->arena->size - off - 2 >= 0) { - return r_read_ble16 (regset->arena->bytes + off, reg->big_endian); + return rz_read_ble16 (regset->arena->bytes + off, reg->big_endian); } break; case 27: if (off + 3 < regset->arena->size) { - return r_read_me27 (regset->arena->bytes + off, 0); + return rz_read_me27 (regset->arena->bytes + off, 0); } break; case 32: if (off + 4 <= regset->arena->size) { - return r_read_ble32 (regset->arena->bytes + off, reg->big_endian); + return rz_read_ble32 (regset->arena->bytes + off, reg->big_endian); } - eprintf ("r_reg_get_value: 32bit oob read %d\n", off); + eprintf ("rz_reg_get_value: 32bit oob read %d\n", off); break; case 64: if (regset->arena && regset->arena->bytes && (off + 8 <= regset->arena->size)) { - return r_read_ble64 (regset->arena->bytes + off, reg->big_endian); + return rz_read_ble64 (regset->arena->bytes + off, reg->big_endian); } - //eprintf ("r_reg_get_value: null or oob arena for current regset\n"); + //eprintf ("rz_reg_get_value: null or oob arena for current regset\n"); break; case 80: // long double case 96: // long floating value // FIXME: It is a precision loss, please implement me properly! - return (ut64)r_reg_get_longdouble (reg, item); + return (ut64)rz_reg_get_longdouble (reg, item); case 128: case 256: // XXX 128 & 256 bit - return (ut64)r_reg_get_longdouble (reg, item); + return (ut64)rz_reg_get_longdouble (reg, item); default: - eprintf ("r_reg_get_value: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_get_value: Bit size %d not supported\n", item->size); break; } return 0LL; } -R_API ut64 r_reg_get_value_by_role(RReg *reg, RRegisterId role) { - // TODO use mapping from RRegisterId to RRegItem (via RRegSet) - return r_reg_get_value (reg, r_reg_get (reg, r_reg_get_name (reg, role), -1)); +RZ_API ut64 rz_reg_get_value_by_role(RzReg *reg, RzRegisterId role) { + // TODO use mapping from RzRegisterId to RzRegItem (via RzRegSet) + return rz_reg_get_value (reg, rz_reg_get (reg, rz_reg_get_name (reg, role), -1)); } -R_API bool r_reg_set_value(RReg *reg, RRegItem *item, ut64 value) { +RZ_API bool rz_reg_set_value(RzReg *reg, RzRegItem *item, ut64 value) { ut8 bytes[12]; ut8 *src = bytes; - r_return_val_if_fail (reg && item, false); + rz_return_val_if_fail (reg && item, false); - if (r_reg_is_readonly (reg, item)) { + if (rz_reg_is_readonly (reg, item)) { return true; } if (item->offset < 0) { return true; } - RRegArena *arena = reg->regset[item->arena].arena; + RzRegArena *arena = reg->regset[item->arena].arena; if (!arena) { return false; } switch (item->size) { case 80: case 96: // long floating value - r_reg_set_longdouble (reg, item, (long double)value); + rz_reg_set_longdouble (reg, item, (long double)value); break; case 64: if (reg->big_endian) { - r_write_be64 (src, value); + rz_write_be64 (src, value); } else { - r_write_le64 (src, value); + rz_write_le64 (src, value); } break; case 32: if (reg->big_endian) { - r_write_be32 (src, value); + rz_write_be32 (src, value); } else { - r_write_le32 (src, value); + rz_write_le32 (src, value); } break; case 16: if (reg->big_endian) { - r_write_be16 (src, value); + rz_write_be16 (src, value); } else { - r_write_le16 (src, value); + rz_write_le16 (src, value); } break; case 8: - r_write_ble8 (src, (ut8) (value & UT8_MAX)); + rz_write_ble8 (src, (ut8) (value & UT8_MAX)); break; case 1: if (value) { @@ -193,7 +193,7 @@ R_API bool r_reg_set_value(RReg *reg, RRegItem *item, ut64 value) { } else { int idx = item->offset / 8; if (idx + item->size > arena->size) { - eprintf ("RRegSetOverflow %d vs %d\n", idx + item->size, arena->size); + eprintf ("RzRegSetOverflow %d vs %d\n", idx + item->size, arena->size); return false; } ut8 *buf = arena->bytes + idx; @@ -205,47 +205,47 @@ R_API bool r_reg_set_value(RReg *reg, RRegItem *item, ut64 value) { case 128: case 256: // XXX 128 & 256 bit - return false; // (ut64)r_reg_get_longdouble (reg, item); + return false; // (ut64)rz_reg_get_longdouble (reg, item); default: - eprintf ("r_reg_set_value: Bit size %d not supported\n", item->size); + eprintf ("rz_reg_set_value: Bit size %d not supported\n", item->size); return false; } const bool fits_in_arena = (arena->size - BITS2BYTES (item->offset) - BITS2BYTES (item->size)) >= 0; if (src && fits_in_arena) { - r_mem_copybits (reg->regset[item->arena].arena->bytes + + rz_mem_copybits (reg->regset[item->arena].arena->bytes + BITS2BYTES (item->offset), src, item->size); return true; } - eprintf ("r_reg_set_value: Cannot set %s to 0x%" PFMT64x "\n", item->name, value); + eprintf ("rz_reg_set_value: Cannot set %s to 0x%" PFMT64x "\n", item->name, value); return false; } -R_API bool r_reg_set_value_by_role(RReg *reg, RRegisterId role, ut64 val) { - // TODO use mapping from RRegisterId to RRegItem (via RRegSet) - RRegItem *r = r_reg_get (reg, r_reg_get_name (reg, role), -1); - return r_reg_set_value (reg, r, val); +RZ_API bool rz_reg_set_value_by_role(RzReg *reg, RzRegisterId role, ut64 val) { + // TODO use mapping from RzRegisterId to RzRegItem (via RzRegSet) + RzRegItem *r = rz_reg_get (reg, rz_reg_get_name (reg, role), -1); + return rz_reg_set_value (reg, r, val); } -R_API ut64 r_reg_set_bvalue(RReg *reg, RRegItem *item, const char *str) { +RZ_API ut64 rz_reg_set_bvalue(RzReg *reg, RzRegItem *item, const char *str) { ut64 num = UT64_MAX; if (item && item->flags && str) { - num = r_str_bits_from_string (str, item->flags); + num = rz_str_bits_from_string (str, item->flags); if (num == UT64_MAX) { - num = r_num_math (NULL, str); + num = rz_num_math (NULL, str); } - r_reg_set_value (reg, item, num); + rz_reg_set_value (reg, item, num); } return num; } -R_API R_HEAP char *r_reg_get_bvalue(RReg *reg, RRegItem *item) { +RZ_API R_HEAP char *rz_reg_get_bvalue(RzReg *reg, RzRegItem *item) { char *out = NULL; if (reg && item && item->flags) { out = malloc (strlen (item->flags) + 1); if (out) { - ut64 num = r_reg_get_value (reg, item); - r_str_bits (out, (ut8 *)&num, + ut64 num = rz_reg_get_value (reg, item); + rz_str_bits (out, (ut8 *)&num, strlen (item->flags) * 8, item->flags); } } @@ -256,8 +256,8 @@ R_API R_HEAP char *r_reg_get_bvalue(RReg *reg, RRegItem *item) { // packbits can be 8, 16, 32 or 64 // result value is always casted into ut64 // TODO: support packbits=128 for xmm registers -R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits) { - r_return_val_if_fail (reg && item, 0LL); +RZ_API ut64 rz_reg_get_pack(RzReg *reg, RzRegItem *item, int packidx, int packbits) { + rz_return_val_if_fail (reg && item, 0LL); if (packbits < 1) { packbits = item->packed_size; @@ -278,7 +278,7 @@ R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits) eprintf ("Packed index is beyond the register size\n"); return 0LL; } - RRegSet *regset = ®->regset[item->arena]; + RzRegSet *regset = ®->regset[item->arena]; if (!regset->arena) { return 0LL; } @@ -291,8 +291,8 @@ R_API ut64 r_reg_get_pack(RReg *reg, RRegItem *item, int packidx, int packbits) } // TODO: support packbits=128 for xmm registers -R_API int r_reg_set_pack(RReg *reg, RRegItem *item, int packidx, int packbits, ut64 val) { - r_return_val_if_fail (reg && reg->regset->arena && item, false); +RZ_API int rz_reg_set_pack(RzReg *reg, RzRegItem *item, int packidx, int packbits, ut64 val) { + rz_return_val_if_fail (reg && reg->regset->arena && item, false); if (packbits < 1) { packbits = item->packed_size; @@ -314,6 +314,6 @@ R_API int r_reg_set_pack(RReg *reg, RRegItem *item, int packidx, int packbits, u memcpy (dst, (ut8*)&val, packbytes); return true; } - eprintf ("r_reg_set_value: Cannot set %s to 0x%" PFMT64x "\n", item->name, val); + eprintf ("rz_reg_set_value: Cannot set %s to 0x%" PFMT64x "\n", item->name, val); return false; } diff --git a/libr/rules.mk b/librz/rules.mk similarity index 88% rename from libr/rules.mk rename to librz/rules.mk index 4940fbc735..966a5b57ab 100644 --- a/libr/rules.mk +++ b/librz/rules.mk @@ -13,7 +13,7 @@ LINK+=-g endif LIBR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST)))) -# /libr +# /librz ALL?= CFLAGS+=-I$(LIBR) @@ -26,7 +26,7 @@ LDFLAGS+=-fvisibility=hidden LINK+=-fvisibility=hidden # for executables (DUP) -LINK+=$(addprefix -L../,$(subst r_,,$(BINDEPS))) +LINK+=$(addprefix -L../,$(subst rz_,,$(BINDEPS))) LINK+=$(addprefix -l,$(BINDEPS)) SRC=$(subst .o,.c,$(OBJ)) @@ -114,10 +114,10 @@ pkgcfg: @echo 'Name: ${NAME}' >> ../../pkgcfg/${NAME}.pc.acr @echo 'Description: radare foundation libraries' >> ../../pkgcfg/${NAME}.pc.acr @echo 'Version: @VERSION@' >> ../../pkgcfg/${NAME}.pc.acr - @echo 'Requires: $(filter r_%,${R2DEPS})' >> ../../pkgcfg/${NAME}.pc.acr - @if [ "${NAME}" = "libr" ]; then NAME=''; else NAME=${NAME}; fi ;\ - echo 'Libs: -L$${libdir} -l${NAME} $(filter-out r_%,${R2DEPS}) ${PCLIBS}' >> ../../pkgcfg/${NAME}.pc.acr - @echo 'Cflags: -I$${includedir}/libr ${PCCFLAGS}' >> ../../pkgcfg/${NAME}.pc.acr + @echo 'Requires: $(filter rz_%,${R2DEPS})' >> ../../pkgcfg/${NAME}.pc.acr + @if [ "${NAME}" = "librz" ]; then NAME=''; else NAME=${NAME}; fi ;\ + echo 'Libs: -L$${libdir} -l${NAME} $(filter-out rz_%,${R2DEPS}) ${PCLIBS}' >> ../../pkgcfg/${NAME}.pc.acr + @echo 'Cflags: -I$${includedir}/librz ${PCCFLAGS}' >> ../../pkgcfg/${NAME}.pc.acr clean:: ${EXTRA_CLEAN} -rm -f *.${EXT_EXE} *.${EXT_SO} *.${EXT_AR} *.d */*.d */*/*.d */*/*/*.d diff --git a/libr/search/Makefile b/librz/search/Makefile similarity index 83% rename from libr/search/Makefile rename to librz/search/Makefile index 55ab75116f..c2a6e1e634 100644 --- a/libr/search/Makefile +++ b/librz/search/Makefile @@ -1,10 +1,10 @@ include ../config.mk -NAME=r_search +NAME=rz_search OBJS=search.o bytepat.o strings.o aes-find.o privkey-find.o OBJS+=regexp.o keyword.o # OBJ+=rsakey.o -R2DEPS=r_util +R2DEPS=rz_util CFLAGS+=-g include ../rules.mk diff --git a/libr/search/aes-find.c b/librz/search/aes-find.c similarity index 88% rename from libr/search/aes-find.c rename to librz/search/aes-find.c index 9257adfb1d..dcc185de55 100644 --- a/libr/search/aes-find.c +++ b/librz/search/aes-find.c @@ -9,8 +9,8 @@ * This source is public domain. Feel free to use it and distribute it. */ -#include -#include +#include +#include #define AES128_SEARCH_LENGTH 24 #define AES192_SEARCH_LENGTH 32 @@ -55,18 +55,18 @@ static bool aes128_key_test(const unsigned char *buf) { return word1 && word2; } -R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len) { +RZ_API int rz_search_aes_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { int i, t, last = len - AES128_SEARCH_LENGTH; - RListIter *iter; - RSearchKeyword *kw; + RzListIter *iter; + RzSearchKeyword *kw; const int old_nhits = s->nhits; - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { if (last >= 0) { for (i = 0; i < last; i++) { if (aes128_key_test (buf + i)) { kw->keyword_length = AES128_KEY_LENGTH; - t = r_search_hit_new (s, kw, from + i); + t = rz_search_hit_new (s, kw, from + i); if (!t) { return -1; } @@ -77,7 +77,7 @@ R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len) { } if (len - i - AES192_SEARCH_LENGTH >= 0 && aes192_key_test (buf + i)) { kw->keyword_length = AES192_KEY_LENGTH; - t = r_search_hit_new (s, kw, from + i); + t = rz_search_hit_new (s, kw, from + i); if (!t) { return -1; } @@ -88,7 +88,7 @@ R_API int r_search_aes_update(RSearch *s, ut64 from, const ut8 *buf, int len) { } if (len - i - AES256_SEARCH_LENGTH >= 0 && aes256_key_test (buf + i)) { kw->keyword_length = AES256_KEY_LENGTH; - t = r_search_hit_new (s, kw, from + i); + t = rz_search_hit_new (s, kw, from + i); if (!t) { return -1; } diff --git a/libr/search/bytepat.c b/librz/search/bytepat.c similarity index 94% rename from libr/search/bytepat.c rename to librz/search/bytepat.c index 9d1468308b..b1ea5c4210 100644 --- a/libr/search/bytepat.c +++ b/librz/search/bytepat.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2006-2019 - esteve, pancake */ -#include -#include -#include +#include +#include +#include #define CTXMINB 5 #define BSIZE (1024*1024) @@ -56,7 +56,7 @@ static int is_fi_present(fnditem* n, unsigned char* blk , int patlen) { return false; } -R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) { +RZ_API int rz_search_pattern(RzSearch *s, ut64 from, ut64 to) { ut8 block[BSIZE+MAX_PATLEN], sblk[BSIZE+MAX_PATLEN+1]; ut64 addr, bact, bytes, intaddr, rb, bproc = 0; int nr,i, moar=0, pcnt, cnt = 0, k = 0; @@ -79,7 +79,7 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) { // bproc = from2 while (bact < bytes) { addr = bact; - if (r_print_is_interrupted ()) { + if (rz_print_is_interrupted ()) { break; } diff --git a/libr/search/keyword.c b/librz/search/keyword.c similarity index 66% rename from libr/search/keyword.c rename to librz/search/keyword.c index fc729457ec..0d99964b55 100644 --- a/libr/search/keyword.c +++ b/librz/search/keyword.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2010-2015 - pancake */ -#include +#include static int ignoreMask(const ut8 *bm, int len) { int i; @@ -12,12 +12,12 @@ static int ignoreMask(const ut8 *bm, int len) { return 1; } -R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut8 *bmbuf, int bmlen, const char *data) { - RSearchKeyword *kw; +RZ_API RzSearchKeyword* rz_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut8 *bmbuf, int bmlen, const char *data) { + RzSearchKeyword *kw; if (kwlen < 1 || bmlen < 0) { return NULL; } - kw = R_NEW0 (RSearchKeyword); + kw = R_NEW0 (RzSearchKeyword); if (!kw) { return NULL; } @@ -26,14 +26,14 @@ R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut kw->keyword_length = kwlen; kw->bin_keyword = malloc (kwlen); if (!kw->bin_keyword) { - r_search_keyword_free (kw); + rz_search_keyword_free (kw); return NULL; } memcpy (kw->bin_keyword, kwbuf, kwlen); if (bmbuf && bmlen > 0 && !ignoreMask (bmbuf, bmlen)) { kw->bin_binmask = malloc (bmlen); if (!kw->bin_binmask) { - r_search_keyword_free (kw); + rz_search_keyword_free (kw); return NULL; } memcpy (kw->bin_binmask, bmbuf, bmlen); @@ -45,7 +45,7 @@ R_API RSearchKeyword* r_search_keyword_new(const ut8 *kwbuf, int kwlen, const ut return kw; } -R_API void r_search_keyword_free (RSearchKeyword *kw) { +RZ_API void rz_search_keyword_free (RzSearchKeyword *kw) { if (!kw) { return; } @@ -54,8 +54,8 @@ R_API void r_search_keyword_free (RSearchKeyword *kw) { free (kw); } -R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bmstr, const char *data, int ignore_case) { - RSearchKeyword *kw; +RZ_API RzSearchKeyword* rz_search_keyword_new_str(const char *kwbuf, const char *bmstr, const char *data, int ignore_case) { + RzSearchKeyword *kw; ut8 *bmbuf = NULL; int bmlen = 0; @@ -64,12 +64,12 @@ R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bm if (!bmbuf) { return NULL; } - bmlen = r_hex_str2bin (bmstr, bmbuf); + bmlen = rz_hex_str2bin (bmstr, bmbuf); if (bmlen < 1) { R_FREE (bmbuf); } } - kw = r_search_keyword_new ((ut8 *)kwbuf, strlen (kwbuf), bmbuf, bmlen, data); + kw = rz_search_keyword_new ((ut8 *)kwbuf, strlen (kwbuf), bmbuf, bmlen, data); if (kw) { kw->icase = ignore_case; kw->type = R_SEARCH_KEYWORD_TYPE_STRING; @@ -78,8 +78,8 @@ R_API RSearchKeyword* r_search_keyword_new_str(const char *kwbuf, const char *bm return kw; } -R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *bmstr, const char *data, int ignore_case) { - RSearchKeyword *kw; +RZ_API RzSearchKeyword* rz_search_keyword_new_wide(const char *kwbuf, const char *bmstr, const char *data, int ignore_case) { + RzSearchKeyword *kw; int len; const char *p2; char *p, *str; @@ -91,7 +91,7 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b if (!bmbuf) { return NULL; } - bmlen = r_hex_str2bin (bmstr, bmbuf); + bmlen = rz_hex_str2bin (bmstr, bmbuf); if (bmlen < 1) { R_FREE (bmbuf); } @@ -101,7 +101,7 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b str = malloc((len+1)*2); for (p2=kwbuf, p=str; *p2; ) { RRune ch; - int num_utf8_bytes = r_utf8_decode ((const ut8 *)p2, kwbuf + len - p2, &ch); + int num_utf8_bytes = rz_utf8_decode ((const ut8 *)p2, kwbuf + len - p2, &ch); if (num_utf8_bytes < 1) { eprintf ("WARNING: Malformed UTF8 at pos %td\n", p2 - kwbuf); p[0] = *p2; @@ -113,13 +113,13 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b if (ignore_case && ch <= 0xff) { ch = tolower (ch); } - int num_wide_bytes = r_utf16le_encode ((ut8 *)p, ch); - r_warn_if_fail (num_wide_bytes != 0); + int num_wide_bytes = rz_utf16le_encode ((ut8 *)p, ch); + rz_warn_if_fail (num_wide_bytes != 0); p2 += num_utf8_bytes; p += num_wide_bytes; } - kw = r_search_keyword_new ((ut8 *)str, p - str, bmbuf, bmlen, data); + kw = rz_search_keyword_new ((ut8 *)str, p - str, bmbuf, bmlen, data); free(str); if (kw) { kw->icase = ignore_case; @@ -128,8 +128,8 @@ R_API RSearchKeyword* r_search_keyword_new_wide(const char *kwbuf, const char *b return kw; } -R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data) { - RSearchKeyword *kw; +RZ_API RzSearchKeyword* rz_search_keyword_new_hex(const char *kwstr, const char *bmstr, const char *data) { + RzSearchKeyword *kw; ut8 *kwbuf, *bmbuf; int kwlen, bmlen = 0; @@ -142,7 +142,7 @@ R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bm return NULL; } - kwlen = r_hex_str2bin (kwstr, kwbuf); + kwlen = rz_hex_str2bin (kwstr, kwbuf); if (kwlen < 1) { free (kwbuf); return NULL; @@ -155,7 +155,7 @@ R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bm free (kwbuf); return NULL; } - bmlen = r_hex_str2bin (bmstr, bmbuf); + bmlen = rz_hex_str2bin (bmstr, bmbuf); if (bmlen < 1) { free (bmbuf); free (kwbuf); @@ -163,26 +163,26 @@ R_API RSearchKeyword* r_search_keyword_new_hex(const char *kwstr, const char *bm } } - kw = r_search_keyword_new (kwbuf, kwlen, bmbuf, bmlen, data); + kw = rz_search_keyword_new (kwbuf, kwlen, bmbuf, bmlen, data); free (kwbuf); free (bmbuf); return kw; } -R_API RSearchKeyword* r_search_keyword_new_hexmask(const char *kwstr, const char *data) { - RSearchKeyword *ks = NULL; +RZ_API RzSearchKeyword* rz_search_keyword_new_hexmask(const char *kwstr, const char *data) { + RzSearchKeyword *ks = NULL; ut8 *kw, *bm; if (kwstr != NULL) { int len = strlen (kwstr); kw = malloc (len + 4); bm = malloc (len + 4); if (kw != NULL && bm != NULL) { - len = r_hex_str2binmask (kwstr, (ut8*)kw, (ut8*)bm); + len = rz_hex_str2binmask (kwstr, (ut8*)kw, (ut8*)bm); if (len < 0) { len = -len - 1; } if (len > 0) { - ks = r_search_keyword_new (kw, len, bm, len, data); + ks = rz_search_keyword_new (kw, len, bm, len, data); } } free (kw); @@ -192,8 +192,8 @@ R_API RSearchKeyword* r_search_keyword_new_hexmask(const char *kwstr, const char } /* Validate a regexp in the canonical format // */ -R_API RSearchKeyword *r_search_keyword_new_regexp (const char *str, const char *data) { - RSearchKeyword *kw; +RZ_API RzSearchKeyword *rz_search_keyword_new_regexp (const char *str, const char *data) { + RzSearchKeyword *kw; int i = 0, start, length; while (isspace ((const unsigned char)str[i])) { @@ -223,14 +223,14 @@ R_API RSearchKeyword *r_search_keyword_new_regexp (const char *str, const char * return NULL; } - kw = R_NEW0(RSearchKeyword); + kw = R_NEW0(RzSearchKeyword); if (!kw) { return NULL; } kw->bin_keyword = malloc (length+1); if (!kw->bin_keyword) { - r_search_keyword_free (kw); + rz_search_keyword_free (kw); return NULL; } @@ -247,7 +247,7 @@ R_API RSearchKeyword *r_search_keyword_new_regexp (const char *str, const char * kw->icase = true; break; default: - r_search_keyword_free (kw); + rz_search_keyword_free (kw); return NULL; } } diff --git a/libr/search/meson.build b/librz/search/meson.build similarity index 63% rename from libr/search/meson.build rename to librz/search/meson.build index 2f7ced3ab9..d7e0f0e5fc 100644 --- a/libr/search/meson.build +++ b/librz/search/meson.build @@ -1,4 +1,4 @@ -r_search_sources = [ +rz_search_sources = [ 'aes-find.c', 'bytepat.c', 'keyword.c', @@ -8,27 +8,27 @@ r_search_sources = [ 'strings.c' ] -r_search = library('r_search', r_search_sources, +rz_search = library('rz_search', rz_search_sources, include_directories: [platform_inc], c_args: library_cflags, - dependencies: [r_util_dep], + dependencies: [rz_util_dep], install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_search_dep = declare_dependency(link_with: r_search, +rz_search_dep = declare_dependency(link_with: rz_search, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_search, - subdirs: 'libr', +pkgconfig_mod.generate(rz_search, + subdirs: 'librz', version: r2_version, - name: 'r_search', - filebase: 'r_search', + name: 'rz_search', + filebase: 'rz_search', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/search/privkey-find.c b/librz/search/privkey-find.c similarity index 92% rename from libr/search/privkey-find.c rename to librz/search/privkey-find.c index e346a1d2d7..57ac988846 100644 --- a/libr/search/privkey-find.c +++ b/librz/search/privkey-find.c @@ -3,7 +3,7 @@ // Contribution to r2 by @santitox // Integrated and refactored by jvoisin and spelissier -#include +#include /* The minimal length to perform a search is the sizes of the sequence tag, the minimal length of the sequence, @@ -64,10 +64,10 @@ static int check_fields(const ut8 *start) { // Finds and return index of a private key: // As defined in RFC 3447 for RSA, as defined in RFC 5915 for // elliptic curves and as defined in 7 of RFC 8410 for SafeCurves -R_API int r_search_privkey_update(RSearch *s, ut64 from, const ut8 *buf, int len) { +RZ_API int rz_search_privkey_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { int i, k, max, index, t; - RListIter *iter; - RSearchKeyword *kw; + RzListIter *iter; + RzSearchKeyword *kw; const size_t old_nhits = s->nhits; const ut8 rsa_versionmarker[] = { 0x02, 0x01, 0x00, 0x02 }; const ut8 ecc_versionmarker[] = { 0x02, 0x01, 0x01, 0x04 }; @@ -77,7 +77,7 @@ R_API int r_search_privkey_update(RSearch *s, ut64 from, const ut8 *buf, int len return -1; } - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { // Iteration until the remaining length is too small to contain a key. for (i = 2; i < len - PRIVKEY_SEARCH_MIN_LENGTH; i++) { if (memcmp (buf + i, rsa_versionmarker, sizeof (rsa_versionmarker)) && @@ -106,7 +106,7 @@ R_API int r_search_privkey_update(RSearch *s, ut64 from, const ut8 *buf, int len if (check_fields (buf + index)) { parse_next_field(buf + index, &kw->keyword_length); - t = r_search_hit_new (s, kw, from + index); + t = rz_search_hit_new (s, kw, from + index); if (t > 1) { return s->nhits - old_nhits; diff --git a/libr/search/regexp.c b/librz/search/regexp.c similarity index 54% rename from libr/search/regexp.c rename to librz/search/regexp.c index 595be71543..fb054c9b82 100644 --- a/libr/search/regexp.c +++ b/librz/search/regexp.c @@ -1,24 +1,24 @@ /* radare - LGPL - Copyright 2008-2014 - pancake, TheLemonMan */ -#include "r_search.h" -#include +#include "rz_search.h" +#include -R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len) { - RSearchKeyword *kw; - RListIter *iter; - RRegexMatch match; - RRegex compiled = {0}; +RZ_API int rz_search_regexp_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { + RzSearchKeyword *kw; + RzListIter *iter; + RzRegexMatch match; + RzRegex compiled = {0}; const int old_nhits = s->nhits; int ret = 0; - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { int reflags = R_REGEX_EXTENDED; if (kw->icase) { reflags |= R_REGEX_ICASE; } - if (r_regex_comp (&compiled, (char *)kw->bin_keyword, reflags)) { + if (rz_regex_comp (&compiled, (char *)kw->bin_keyword, reflags)) { eprintf ("Cannot compile '%s' regexp\n", kw->bin_keyword); return -1; } @@ -26,8 +26,8 @@ R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len) match.rm_so = 0; match.rm_eo = len; - while (!r_regex_exec (&compiled, (char *)buf, 1, &match, R_REGEX_STARTEND)) { - int t = r_search_hit_new (s, kw, from + match.rm_so); + while (!rz_regex_exec (&compiled, (char *)buf, 1, &match, R_REGEX_STARTEND)) { + int t = rz_search_hit_new (s, kw, from + match.rm_so); if (!t) { ret = -1; goto beach; @@ -42,7 +42,7 @@ R_API int r_search_regexp_update(RSearch *s, ut64 from, const ut8 *buf, int len) } beach: - r_regex_fini (&compiled); + rz_regex_fini (&compiled); if (!ret) { ret = s->nhits - old_nhits; } diff --git a/libr/search/search.c b/librz/search/search.c similarity index 70% rename from libr/search/search.c rename to librz/search/search.c index 6cfc8911a3..db156bdcdc 100644 --- a/libr/search/search.c +++ b/librz/search/search.c @@ -1,26 +1,26 @@ /* radare - LGPL - Copyright 2008-2016 pancake */ -#include -#include +#include +#include #include // Experimental search engine (fails, because stops at first hit of every block read #define USE_BMH 0 -R_LIB_VERSION (r_search); +R_LIB_VERSION (rz_search); typedef struct { ut64 end; int len; ut8 data[]; -} RSearchLeftover; +} RzSearchLeftover; -R_API RSearch *r_search_new(int mode) { - RSearch *s = R_NEW0 (RSearch); +RZ_API RzSearch *rz_search_new(int mode) { + RzSearch *s = R_NEW0 (RzSearch); if (!s) { return NULL; } - if (!r_search_set_mode (s, mode)) { + if (!rz_search_set_mode (s, mode)) { free (s); eprintf ("Cannot init search for mode %d\n", mode); return false; @@ -36,31 +36,31 @@ R_API RSearch *r_search_new(int mode) { s->pattern_size = 0; s->string_max = 255; s->string_min = 3; - s->hits = r_list_newf (free); + s->hits = rz_list_newf (free); s->maxhits = 0; // TODO: review those mempool sizes. ensure never gets NULL - s->kws = r_list_newf (free); + s->kws = rz_list_newf (free); if (!s->kws) { - r_search_free (s); + rz_search_free (s); return NULL; } - s->kws->free = (RListFree) r_search_keyword_free; + s->kws->free = (RzListFree) rz_search_keyword_free; return s; } -R_API RSearch *r_search_free(RSearch *s) { +RZ_API RzSearch *rz_search_free(RzSearch *s) { if (!s) { return NULL; } - r_list_free (s->hits); - r_list_free (s->kws); - //r_io_free(s->iob.io); this is supposed to be a weak reference + rz_list_free (s->hits); + rz_list_free (s->kws); + //rz_io_free(s->iob.io); this is supposed to be a weak reference free (s->data); free (s); return NULL; } -R_API int r_search_set_string_limits(RSearch *s, ut32 min, ut32 max) { +RZ_API int rz_search_set_string_limits(RzSearch *s, ut32 min, ut32 max) { if (max < min) { return false; } @@ -69,21 +69,21 @@ R_API int r_search_set_string_limits(RSearch *s, ut32 min, ut32 max) { return true; } -R_API int r_search_magic_update(RSearch *s, ut64 from, const ut8 *buf, int len) { - eprintf ("TODO: import libr/core/cmd_search.c /m implementation into rsearch\n"); +RZ_API int rz_search_magic_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { + eprintf ("TODO: import librz/core/cmd_search.c /m implementation into rsearch\n"); return false; } -R_API int r_search_set_mode(RSearch *s, int mode) { +RZ_API int rz_search_set_mode(RzSearch *s, int mode) { s->update = NULL; switch (mode) { - case R_SEARCH_KEYWORD: s->update = r_search_mybinparse_update; break; - case R_SEARCH_REGEXP: s->update = r_search_regexp_update; break; - case R_SEARCH_AES: s->update = r_search_aes_update; break; - case R_SEARCH_PRIV_KEY: s->update = r_search_privkey_update; break; - case R_SEARCH_STRING: s->update = r_search_strings_update; break; - case R_SEARCH_DELTAKEY: s->update = r_search_deltakey_update; break; - case R_SEARCH_MAGIC: s->update = r_search_magic_update; break; + case R_SEARCH_KEYWORD: s->update = rz_search_mybinparse_update; break; + case R_SEARCH_REGEXP: s->update = rz_search_regexp_update; break; + case R_SEARCH_AES: s->update = rz_search_aes_update; break; + case R_SEARCH_PRIV_KEY: s->update = rz_search_privkey_update; break; + case R_SEARCH_STRING: s->update = rz_search_strings_update; break; + case R_SEARCH_DELTAKEY: s->update = rz_search_deltakey_update; break; + case R_SEARCH_MAGIC: s->update = rz_search_magic_update; break; } if (s->update || mode == R_SEARCH_PATTERN) { s->mode = mode; @@ -92,10 +92,10 @@ R_API int r_search_set_mode(RSearch *s, int mode) { return false; } -R_API int r_search_begin(RSearch *s) { - RListIter *iter; - RSearchKeyword *kw; - r_list_foreach (s->kws, iter, kw) { +RZ_API int rz_search_begin(RzSearch *s) { + RzListIter *iter; + RzSearchKeyword *kw; + rz_list_foreach (s->kws, iter, kw) { kw->count = 0; kw->last = 0; } @@ -103,7 +103,7 @@ R_API int r_search_begin(RSearch *s) { } // Returns 2 if search.maxhits is reached, 0 on error, otherwise 1 -R_API int r_search_hit_new(RSearch *s, RSearchKeyword *kw, ut64 addr) { +RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr) { if (s->align && (addr%s->align)) { eprintf ("0x%08"PFMT64x" unaligned\n", addr); return 1; @@ -128,24 +128,24 @@ R_API int r_search_hit_new(RSearch *s, RSearchKeyword *kw, ut64 addr) { } kw->count++; s->nhits++; - RSearchHit* hit = R_NEW0 (RSearchHit); + RzSearchHit* hit = R_NEW0 (RzSearchHit); if (hit) { hit->kw = kw; hit->addr = addr; - r_list_append (s->hits, hit); + rz_list_append (s->hits, hit); } return s->maxhits && s->nhits >= s->maxhits ? 2 : 1; } // TODO support search across block boundaries // Supported search variants: backward, overlap -R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int len) { - RListIter *iter; +RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { + RzListIter *iter; int longest = 0, i, j; - RSearchKeyword *kw; - RSearchLeftover *left; + RzSearchKeyword *kw; + RzSearchLeftover *left; const int old_nhits = s->nhits; - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { longest = R_MAX (longest, kw->keyword_length + 1); } if (!longest) { @@ -157,14 +157,14 @@ R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int le left->len = 0; } } else { - left = malloc (sizeof(RSearchLeftover) + (size_t)2 * (longest - 1)); + left = malloc (sizeof(RzSearchLeftover) + (size_t)2 * (longest - 1)); if (!left) { return -1; } s->data = left; left->len = 0; if (s->bckwrds) { - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { ut8 *i = kw->bin_keyword, *j = kw->bin_keyword + kw->keyword_length; for (; i < j; i++) { *i = -*i; @@ -184,7 +184,7 @@ R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int le ut64 len1 = left->len + R_MIN (longest - 1, len); memcpy (left->data + left->len, buf, len1 - left->len); - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { ut8 *a = kw->bin_keyword; i = s->overlap || !kw->count ? 0 : s->bckwrds @@ -197,7 +197,7 @@ R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int le j++; } if (j == kw->keyword_length) { - int t = r_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i + left->len : from + i - left->len); + int t = rz_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i + left->len : from + i - left->len); kw->last += s->bckwrds ? 0 : 1; if (!t) { return -1; @@ -222,7 +222,7 @@ R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int le j++; } if (j == kw->keyword_length) { - int t = r_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i : from + i); + int t = rz_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i : from + i); kw->last += s->bckwrds ? 0 : 1; if (!t) { return -1; @@ -256,7 +256,7 @@ R_API int r_search_deltakey_update(RSearch *s, ut64 from, const ut8 *buf, int le #if 0 // Boyer-Moore-Horspool pattern matching // Supported search variants: icase, overlap -static int r_search_horspool(RSearch *s, RSearchKeyword *kw, ut64 from, const ut8 *buf, int len) { +static int rz_search_horspool(RzSearch *s, RzSearchKeyword *kw, ut64 from, const ut8 *buf, int len) { ut64 bad_char_shift[UT8_MAX + 1]; int i, j, m = kw->keyword_length - 1, count = 0; ut8 ch; @@ -279,7 +279,7 @@ static int r_search_horspool(RSearch *s, RSearchKeyword *kw, ut64 from, const ut } if (a != b) break; if (i == 0) { - if (!r_search_hit_new (s, kw, from + i)) { + if (!rz_search_hit_new (s, kw, from + i)) { return -1; } kw->count++; @@ -298,7 +298,7 @@ static int r_search_horspool(RSearch *s, RSearchKeyword *kw, ut64 from, const ut } #endif -static bool brute_force_match(RSearch *s, RSearchKeyword *kw, const ut8 *buf, int i) { +static bool brute_force_match(RzSearch *s, RzSearchKeyword *kw, const ut8 *buf, int i) { int j = 0; if (s->distance) { // slow path, more work in the loop int dist = 0; @@ -356,14 +356,14 @@ static bool brute_force_match(RSearch *s, RSearchKeyword *kw, const ut8 *buf, in } // Supported search variants: backward, binmask, icase, inverse, overlap -R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int len) { - RSearchKeyword *kw; - RListIter *iter; - RSearchLeftover *left; +RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { + RzSearchKeyword *kw; + RzListIter *iter; + RzSearchLeftover *left; int longest = 0, i; const int old_nhits = s->nhits; - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { longest = R_MAX (longest, kw->keyword_length); } if (!longest) { @@ -375,7 +375,7 @@ R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int left->len = 0; } } else { - left = malloc (sizeof(RSearchLeftover) + (size_t)2 * (longest - 1)); + left = malloc (sizeof(RzSearchLeftover) + (size_t)2 * (longest - 1)); if (!left) { return -1; } @@ -394,14 +394,14 @@ R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int ut64 len1 = left->len + R_MIN (longest - 1, len); memcpy (left->data + left->len, buf, len1 - left->len); - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { i = s->overlap || !kw->count ? 0 : s->bckwrds ? kw->last - from < left->len ? from + left->len - kw->last : 0 : from - kw->last < left->len ? kw->last + left->len - from : 0; for (; i + kw->keyword_length <= len1 && i < left->len; i++) { if (brute_force_match (s, kw, left->data, i) != s->inverse) { - int t = r_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - i + left->len : from + i - left->len); + int t = rz_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - i + left->len : from + i - left->len); if (!t) { return -1; } @@ -419,7 +419,7 @@ R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int : from < kw->last ? kw->last - from : 0; for (; i + kw->keyword_length <= len; i++) { if (brute_force_match (s, kw, buf, i) != s->inverse) { - int t = r_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - i : from + i); + int t = rz_search_hit_new (s, kw, s->bckwrds ? from - kw->keyword_length - i : from + i); if (!t) { return -1; } @@ -448,7 +448,7 @@ R_API int r_search_mybinparse_update(RSearch *s, ut64 from, const ut8 *buf, int return s->nhits - old_nhits; } -R_API void r_search_set_distance(RSearch *s, int dist) { +RZ_API void rz_search_set_distance(RzSearch *s, int dist) { if (dist>=R_SEARCH_DISTANCE_MAX) { eprintf ("Invalid distance\n"); s->distance = 0; @@ -458,18 +458,18 @@ R_API void r_search_set_distance(RSearch *s, int dist) { } // deprecate? or standarize with ->align ?? -R_API void r_search_pattern_size(RSearch *s, int size) { +RZ_API void rz_search_pattern_size(RzSearch *s, int size) { s->pattern_size = size; } -R_API void r_search_set_callback(RSearch *s, RSearchCallback(callback), void *user) { +RZ_API void rz_search_set_callback(RzSearch *s, RzSearchCallback(callback), void *user) { s->callback = callback; s->user = user; } // backward search: from points to the right endpoint // forward search: from points to the left endpoint -R_API int r_search_update(RSearch *s, ut64 from, const ut8 *buf, long len) { +RZ_API int rz_search_update(RzSearch *s, ut64 from, const ut8 *buf, long len) { int ret = -1; if (s->update) { if (s->maxhits && s->nhits >= s->maxhits) { @@ -477,49 +477,49 @@ R_API int r_search_update(RSearch *s, ut64 from, const ut8 *buf, long len) { } ret = s->update (s, from, buf, len); } else { - eprintf ("r_search_update: No search method defined\n"); + eprintf ("rz_search_update: No search method defined\n"); } return ret; } -R_API int r_search_update_i(RSearch *s, ut64 from, const ut8 *buf, long len) { - return r_search_update (s, from, buf, len); +RZ_API int rz_search_update_i(RzSearch *s, ut64 from, const ut8 *buf, long len) { + return rz_search_update (s, from, buf, len); } -static int listcb(RSearchKeyword *k, void *user, ut64 addr) { - RSearchHit *hit = R_NEW0 (RSearchHit); +static int listcb(RzSearchKeyword *k, void *user, ut64 addr) { + RzSearchHit *hit = R_NEW0 (RzSearchHit); if (!hit) { return 0; } hit->kw = k; hit->addr = addr; - r_list_append (user, hit); + rz_list_append (user, hit); return 1; } -R_API RList *r_search_find(RSearch *s, ut64 addr, const ut8 *buf, int len) { - RList *ret = r_list_new (); - r_search_set_callback (s, listcb, ret); - r_search_update (s, addr, buf, len); +RZ_API RzList *rz_search_find(RzSearch *s, ut64 addr, const ut8 *buf, int len) { + RzList *ret = rz_list_new (); + rz_search_set_callback (s, listcb, ret); + rz_search_update (s, addr, buf, len); return ret; } /* --- keywords --- */ -R_API int r_search_kw_add(RSearch *s, RSearchKeyword *kw) { +RZ_API int rz_search_kw_add(RzSearch *s, RzSearchKeyword *kw) { if (!kw || !kw->keyword_length) { return false; } kw->kwidx = s->n_kws++; - r_list_append (s->kws, kw); + rz_list_append (s->kws, kw); return true; } // Reverse bin_keyword & bin_binmask for backward search -R_API void r_search_string_prepare_backward(RSearch *s) { - RListIter *iter; - RSearchKeyword *kw; +RZ_API void rz_search_string_prepare_backward(RzSearch *s) { + RzListIter *iter; + RzSearchKeyword *kw; // Precondition: !kw->binmask_length || kw->keyword_length % kw->binmask_length == 0 - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { ut8 *i = kw->bin_keyword, *j = kw->bin_keyword + kw->keyword_length; while (i < j) { ut8 t = *i; @@ -536,15 +536,15 @@ R_API void r_search_string_prepare_backward(RSearch *s) { } } -R_API void r_search_reset(RSearch *s, int mode) { +RZ_API void rz_search_reset(RzSearch *s, int mode) { s->nhits = 0; - if (!r_search_set_mode (s, mode)) { + if (!rz_search_set_mode (s, mode)) { eprintf ("Cannot init search for mode %d\n", mode); } } -R_API void r_search_kw_reset(RSearch *s) { - r_list_purge (s->kws); - r_list_purge (s->hits); +RZ_API void rz_search_kw_reset(RzSearch *s) { + rz_list_purge (s->kws); + rz_list_purge (s->hits); R_FREE (s->data); } diff --git a/libr/search/strings.c b/librz/search/strings.c similarity index 84% rename from libr/search/strings.c rename to librz/search/strings.c index a3d65e44a1..c0ba969f02 100644 --- a/libr/search/strings.c +++ b/librz/search/strings.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2006-2018 pancake */ -#include "r_search.h" +#include "rz_search.h" // TODO: this file needs some love enum { @@ -12,7 +12,7 @@ static char *encodings[3] = { "ascii", "cp850", NULL }; //static int encoding = ENCODING_ASCII; // default //encoding = resolve_encoding(config_get("cfg.encoding")); -R_API int r_search_get_encoding(const char *name) { +RZ_API int rz_search_get_encoding(const char *name) { int i; if (!name || !*name) { return ENCODING_ASCII; @@ -20,7 +20,7 @@ R_API int r_search_get_encoding(const char *name) { ut32 lename = strlen (name); for (i = 0; encodings[i]; i++) { ut32 sz = R_MIN (strlen (encodings[i]), lename); - if (!r_str_ncasecmp (name, encodings[i], sz)) { + if (!rz_str_ncasecmp (name, encodings[i], sz)) { return i; } } @@ -58,15 +58,15 @@ static bool is_encoded(int encoding, unsigned char c) { return false; } -R_API int r_search_strings_update(RSearch *s, ut64 from, const ut8 *buf, int len) { +RZ_API int rz_search_strings_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { int i = 0; int widechar = 0; int matches = 0; char str[4096]; - RListIter *iter; - RSearchKeyword *kw; + RzListIter *iter; + RzSearchKeyword *kw; - r_list_foreach (s->kws, iter, kw) { + rz_list_foreach (s->kws, iter, kw) { for (i = 0; i < len; i++) { char ch = buf[i]; // non-cp850 encoded @@ -88,10 +88,10 @@ R_API int r_search_strings_update(RSearch *s, ut64 from, const ut8 *buf, int len if (len>2) { if (widechar) { ut64 off = (ut64)from+i-(len*2)+1; - r_search_hit_new (s, kw, off); + rz_search_hit_new (s, kw, off); } else { ut64 off = (ut64)from+i-matches; - r_search_hit_new (s, kw, off); + rz_search_hit_new (s, kw, off); } } fflush (stdout); diff --git a/libr/socket/Makefile b/librz/socket/Makefile similarity index 77% rename from libr/socket/Makefile rename to librz/socket/Makefile index 5b063c9e23..501289ac6c 100644 --- a/libr/socket/Makefile +++ b/librz/socket/Makefile @@ -1,14 +1,14 @@ include ../config.mk -NAME=r_socket +NAME=rz_socket OBJS=socket.o OBJS+=socket_proc.o OBJS+=socket_http.o # TODO: rename to socket_http_client.o OBJS+=socket_http_server.o OBJS+=socket_rap_server.o OBJS+=socket_rap_client.o -OBJS+=run.o r2pipe.o socket_serial.o -R2DEPS=r_util +OBJS+=run.o rzpipe.o socket_serial.o +R2DEPS=rz_util include deps.mk include ../rules.mk diff --git a/libr/socket/deps.mk b/librz/socket/deps.mk similarity index 100% rename from libr/socket/deps.mk rename to librz/socket/deps.mk diff --git a/libr/socket/meson.build b/librz/socket/meson.build similarity index 63% rename from libr/socket/meson.build rename to librz/socket/meson.build index 8964925b8e..cc85329c83 100644 --- a/libr/socket/meson.build +++ b/librz/socket/meson.build @@ -1,22 +1,22 @@ -r_socket_sources = [ +rz_socket_sources = [ 'socket.c', 'socket_http.c', 'socket_http_server.c', 'socket_serial.c', 'socket_proc.c', - 'r2pipe.c', + 'rzpipe.c', 'socket_rap_client.c', 'socket_rap_server.c', 'run.c', ] -dependencies = [utl, r_util_dep, platform_deps] +dependencies = [utl, rz_util_dep, platform_deps] if use_sys_openssl dependencies += [sys_openssl] endif -r_socket = library('r_socket', r_socket_sources, +rz_socket = library('rz_socket', rz_socket_sources, include_directories: [platform_inc], dependencies: dependencies, c_args: library_cflags, @@ -26,18 +26,18 @@ r_socket = library('r_socket', r_socket_sources, soversion: r2_libversion ) -r_socket_dep = declare_dependency(link_with: r_socket, - dependencies: [r_util_dep], +rz_socket_dep = declare_dependency(link_with: rz_socket, + dependencies: [rz_util_dep], include_directories: [platform_inc]) -pkgconfig_mod.generate(r_socket, - subdirs: 'libr', +pkgconfig_mod.generate(rz_socket, + subdirs: 'librz', version: r2_version, - name: 'r_socket', - filebase: 'r_socket', + name: 'rz_socket', + filebase: 'rz_socket', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/socket/run.c b/librz/socket/run.c similarity index 81% rename from libr/socket/run.c rename to librz/socket/run.c index 3f9089d374..f24f87f518 100644 --- a/libr/socket/run.c +++ b/librz/socket/run.c @@ -1,15 +1,15 @@ /* radare - LGPL - Copyright 2014-2020 - pancake */ -/* this helper api is here because it depends on r_util and r_socket */ -/* we should find a better place for it. r_io? */ +/* this helper api is here because it depends on rz_util and rz_socket */ +/* we should find a better place for it. rz_io? */ #include #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -71,55 +71,55 @@ static int (*dyn_login_tty)(int fd) = NULL; static id_t (*dyn_forkpty)(int *amaster, char *name, struct termios *termp, struct winsize *winp) = NULL; static void dyn_init(void) { if (!dyn_openpty) { - dyn_openpty = r_lib_dl_sym (NULL, "openpty"); + dyn_openpty = rz_lib_dl_sym (NULL, "openpty"); } if (!dyn_login_tty) { - dyn_openpty = r_lib_dl_sym (NULL, "login_tty"); + dyn_openpty = rz_lib_dl_sym (NULL, "login_tty"); } if (!dyn_forkpty) { - dyn_openpty = r_lib_dl_sym (NULL, "forkpty"); + dyn_openpty = rz_lib_dl_sym (NULL, "forkpty"); } } #endif -R_API RRunProfile *r_run_new(const char *str) { +RZ_API RRunProfile *rz_run_new(const char *str) { RRunProfile *p = R_NEW0 (RRunProfile); if (p) { - r_run_reset (p); + rz_run_reset (p); if (str) { - r_run_parsefile (p, str); + rz_run_parsefile (p, str); } } return p; } -R_API void r_run_reset(RRunProfile *p) { - r_return_if_fail (p); +RZ_API void rz_run_reset(RRunProfile *p) { + rz_return_if_fail (p); memset (p, 0, sizeof (RRunProfile)); p->_aslr = -1; } -R_API bool r_run_parse(RRunProfile *pf, const char *profile) { - r_return_val_if_fail (pf && profile, false); +RZ_API bool rz_run_parse(RRunProfile *pf, const char *profile) { + rz_return_val_if_fail (pf && profile, false); char *p, *o, *str = strdup (profile); if (!str) { return false; } - r_str_replace_char (str, '\r',0); + rz_str_replace_char (str, '\r',0); p = str; while (p) { if ((o = strchr (p, '\n'))) { *o++ = 0; } - r_run_parseline (pf, p); + rz_run_parseline (pf, p); p = o; } free (str); return true; } -R_API void r_run_free(RRunProfile *r) { +RZ_API void rz_run_free(RRunProfile *r) { if (r) { free (r->_system); free (r->_program); @@ -177,7 +177,7 @@ static char *getstr(const char *src) { len--; if (ret[len] == '"') { ret[len] = 0; - r_str_unescape (ret); + rz_str_unescape (ret); return ret; } eprintf ("Missing \"\n"); @@ -205,7 +205,7 @@ static char *getstr(const char *src) { } } // slurp file - return r_file_slurp (src + 1, NULL); + return rz_file_slurp (src + 1, NULL); } case '`': { @@ -213,8 +213,8 @@ static char *getstr(const char *src) { int msg_len = strlen (msg); if (msg_len > 0) { msg [msg_len - 1] = 0; - char *ret = r_sys_cmd_str (msg, NULL, NULL); - r_str_trim_tail (ret); + char *ret = rz_sys_cmd_str (msg, NULL, NULL); + rz_str_trim_tail (ret); free (msg); return ret; } @@ -223,18 +223,18 @@ static char *getstr(const char *src) { } case '!': { - char *a = r_sys_cmd_str (src + 1, NULL, NULL); - r_str_trim_tail (a); + char *a = rz_sys_cmd_str (src + 1, NULL, NULL); + rz_str_trim_tail (a); return a; } case ':': if (src[1] == '!') { - ret = r_sys_cmd_str (src + 1, NULL, NULL); - r_str_trim_tail (ret); // why no head :? + ret = rz_sys_cmd_str (src + 1, NULL, NULL); + rz_str_trim_tail (ret); // why no head :? } else { ret = strdup (src); } - len = r_hex_str2bin (src + 1, (ut8*)ret); + len = rz_hex_str2bin (src + 1, (ut8*)ret); if (len > 0) { ret[len] = 0; return ret; @@ -243,7 +243,7 @@ static char *getstr(const char *src) { free (ret); return NULL; } - r_str_unescape ((ret = strdup (src))); + rz_str_unescape ((ret = strdup (src))); return ret; } @@ -255,14 +255,14 @@ static int parseBool(const char *e) { 0: 1): 1): 1): 1); } -// TODO: move into r_util? r_run_... ? with the rest of funcs? +// TODO: move into rz_util? rz_run_... ? with the rest of funcs? static void setASLR(RRunProfile *r, int enabled) { #if __linux__ - r_sys_aslr (enabled); + rz_sys_aslr (enabled); #if HAVE_DECL_ADDR_NO_RANDOMIZE && !__ANDROID__ if (personality (ADDR_NO_RANDOMIZE) == -1) { #endif - r_sys_aslr (0); + rz_sys_aslr (0); #if HAVE_DECL_ADDR_NO_RANDOMIZE && !__ANDROID__ } #endif @@ -280,7 +280,7 @@ static void setASLR(RRunProfile *r, int enabled) { // "unset the MH_PIE bit in an already linked executable" with --no-pie flag of the script // the right way is to disable the aslr bit in the spawn call #elif __FreeBSD__ || __NetBSD__ - r_sys_aslr (enabled); + rz_sys_aslr (enabled); #else // not supported for this platform #endif @@ -352,7 +352,7 @@ static int handle_redirection_proc(const char *cmd, bool in, bool out, bool err) cfmakeraw (&t); tcsetattr (fds, TCSANOW, &t); - int code = r_sys_cmd (cmd); + int code = rz_sys_cmd (cmd); restore_saved_fd (saved_stdin, in, STDIN_FILENO); restore_saved_fd (saved_stdout, out, STDOUT_FILENO); exit (code); @@ -399,19 +399,19 @@ static int handle_redirection(const char *cmd, bool in, bool out, bool err) { if (pipe (pipes) != -1) { size_t cmdl = strlen (cmd)-2; if (write (pipes[1], cmd + 1, cmdl) != cmdl) { - eprintf ("[ERROR] rarun2: Cannot write to the pipe\n"); + eprintf ("[ERROR] rz_run: Cannot write to the pipe\n"); close (0); return 1; } if (write (pipes[1], "\n", 1) != 1) { - eprintf ("[ERROR] rarun2: Cannot write to the pipe\n"); + eprintf ("[ERROR] rz_run: Cannot write to the pipe\n"); close (0); return 1; } close (0); dup2 (pipes[0], 0); } else { - eprintf ("[ERROR] rarun2: Cannot create pipe\n"); + eprintf ("[ERROR] rz_run: Cannot create pipe\n"); } } #else @@ -437,7 +437,7 @@ static int handle_redirection(const char *cmd, bool in, bool out, bool err) { #endif f = open (cmd, flag, mode); if (f < 0) { - eprintf ("[ERROR] rarun2: Cannot open: %s\n", cmd); + eprintf ("[ERROR] rz_run: Cannot open: %s\n", cmd); return 1; } #define DUP(x) { close(x); dup2(f,x); } @@ -456,18 +456,18 @@ static int handle_redirection(const char *cmd, bool in, bool out, bool err) { #endif } -R_API bool r_run_parsefile(RRunProfile *p, const char *b) { - r_return_val_if_fail (p && b, false); - char *s = r_file_slurp (b, NULL); +RZ_API bool rz_run_parsefile(RRunProfile *p, const char *b) { + rz_return_val_if_fail (p && b, false); + char *s = rz_file_slurp (b, NULL); if (s) { - bool ret = r_run_parse (p, s); + bool ret = rz_run_parse (p, s); free (s); return ret; } return 0; } -R_API bool r_run_parseline(RRunProfile *p, const char *b) { +RZ_API bool rz_run_parseline(RRunProfile *p, const char *b) { int must_free = false; char *e = strchr (b, '='); if (!e || *b == '#') { @@ -476,7 +476,7 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { *e++ = 0; if (*e == '$') { must_free = true; - e = r_sys_getenv (e); + e = rz_sys_getenv (e); } if (!e) { return 0; @@ -526,7 +526,7 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { } else if (!strcmp (b, "fork")) { p->_dofork = parseBool (e); } else if (!strcmp (b, "sleep")) { - p->_r2sleep = atoi (e); + p->_rzsleep = atoi (e); } else if (!strcmp (b, "maxstack")) { p->_maxstack = atoi (e); } else if (!strcmp (b, "maxproc")) { @@ -542,9 +542,9 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { } else if (!strcmp (b, "preload")) { p->_preload = strdup (e); } else if (!strcmp (b, "r2preload")) { - p->_r2preload = parseBool (e); + p->_rzpreload = parseBool (e); } else if (!strcmp (b, "r2preweb")) { - r_sys_setenv ("RARUN2_WEB", "yes"); + rz_sys_setenv ("RARUN2_WEB", "yes"); } else if (!strcmp (b, "setuid")) { p->_setuid = strdup (e); } else if (!strcmp (b, "seteuid")) { @@ -558,7 +558,7 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { } else if (!strcmp (b, "timeout")) { p->_timeout = atoi (e); } else if (!strcmp (b, "timeoutsig")) { - p->_timeout_sig = r_signal_from_string (e); + p->_timeout_sig = rz_signal_from_string (e); } else if (!memcmp (b, "arg", 3)) { int n = atoi (b + 3); if (n >= 0 && n < R_RUN_PROFILE_NARGS) { @@ -570,7 +570,7 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { } else if (!strcmp (b, "envfile")) { char *p, buf[1024]; size_t len; - FILE *fd = r_sandbox_fopen (e, "r"); + FILE *fd = rz_sandbox_fopen (e, "r"); if (!fd) { eprintf ("Cannot open '%s'\n", e); if (must_free == true) { @@ -595,22 +595,22 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { if (len > 1 && p[len - 2] == '\r') { p[len - 2] = 0; } - r_sys_setenv (buf, p); + rz_sys_setenv (buf, p); } } fclose (fd); } else if (!strcmp (b, "unsetenv")) { - r_sys_setenv (e, NULL); + rz_sys_setenv (e, NULL); } else if (!strcmp (b, "setenv")) { char *V, *v = strchr (e, '='); if (v) { *v++ = 0; V = getstr (v); - r_sys_setenv (e, V); + rz_sys_setenv (e, V); free (V); } } else if (!strcmp(b, "clearenv")) { - r_sys_clearenv (); + rz_sys_clearenv (); } if (must_free == true) { free (e); @@ -618,14 +618,14 @@ R_API bool r_run_parseline(RRunProfile *p, const char *b) { return true; } -R_API const char *r_run_help(void) { +RZ_API const char *rz_run_help(void) { return "program=/bin/ls\n" "arg1=/bin\n" "# arg2=hello\n" "# arg3=\"hello\\nworld\"\n" "# arg4=:048490184058104849\n" - "# arg5=:!ragg2 -p n50 -d 10:0x8048123\n" + "# arg5=:!rz_gg -p n50 -d 10:0x8048123\n" "# arg6=@arg.txt\n" "# arg7=@300@ABCD # 300 chars filled with ABCD pattern\n" "# system=r2 -\n" @@ -698,7 +698,7 @@ static int fd_forward(int in_fd, int out_fd, char **buff) { } #endif -static int redirect_socket_to_stdio(RSocket *sock) { +static int redirect_socket_to_stdio(RzSocket *sock) { close (0); close (1); close (2); @@ -711,13 +711,13 @@ static int redirect_socket_to_stdio(RSocket *sock) { } #if __WINDOWS__ -static RThreadFunctionRet exit_process(RThread *th) { - // eprintf ("\nrarun2: Interrupted by timeout\n"); +static RzThreadFunctionRet exit_process(RzThread *th) { + // eprintf ("\nrz_run: Interrupted by timeout\n"); exit (0); } #endif -static int redirect_socket_to_pty(RSocket *sock) { +static int redirect_socket_to_pty(RzSocket *sock) { #if HAVE_PTY // directly duplicating the fds using dup2() creates problems // in case of interactive applications @@ -728,7 +728,7 @@ static int redirect_socket_to_pty(RSocket *sock) { return -1; } - pid_t child_pid = r_sys_fork (); + pid_t child_pid = rz_sys_fork (); if (child_pid == -1) { eprintf ("cannot fork\n"); @@ -771,12 +771,12 @@ static int redirect_socket_to_pty(RSocket *sock) { free (buff); close (fdm); - r_socket_free (sock); + rz_socket_free (sock); exit (0); } // parent - r_socket_close_fd (sock); + rz_socket_close_fd (sock); if (dyn_login_tty) { dyn_login_tty (fds); } @@ -795,7 +795,7 @@ static int redirect_socket_to_pty(RSocket *sock) { #endif } -R_API int r_run_config_env(RRunProfile *p) { +RZ_API int rz_run_config_env(RRunProfile *p) { int ret; #if HAVE_PTY @@ -842,16 +842,16 @@ R_API int r_run_config_env(RRunProfile *p) { if (p->_connect) { char *q = strchr (p->_connect, ':'); if (q) { - RSocket *fd = r_socket_new (0); + RzSocket *fd = rz_socket_new (0); *q = 0; - if (!r_socket_connect_tcp (fd, p->_connect, q+1, 30)) { + if (!rz_socket_connect_tcp (fd, p->_connect, q+1, 30)) { eprintf ("Cannot connect\n"); return 1; } if (p->_pty) { if (redirect_socket_to_pty (fd) != 0) { eprintf ("socket redirection failed\n"); - r_socket_free (fd); + rz_socket_free (fd); return 1; } } else { @@ -863,24 +863,24 @@ R_API int r_run_config_env(RRunProfile *p) { } } if (p->_listen) { - RSocket *child, *fd = r_socket_new (0); + RzSocket *child, *fd = rz_socket_new (0); bool is_child = false; - if (!r_socket_listen (fd, p->_listen, NULL)) { - eprintf ("rarun2: cannot listen\n"); - r_socket_free (fd); + if (!rz_socket_listen (fd, p->_listen, NULL)) { + eprintf ("rz_run: cannot listen\n"); + rz_socket_free (fd); return 1; } while (true) { - child = r_socket_accept (fd); + child = rz_socket_accept (fd); if (child) { is_child = true; if (p->_dofork && !p->_dodebug) { - pid_t child_pid = r_sys_fork (); + pid_t child_pid = rz_sys_fork (); if (child_pid == -1) { - eprintf("rarun2: cannot fork\n"); - r_socket_free (child); - r_socket_free (fd); + eprintf("rz_run: cannot fork\n"); + rz_socket_free (child); + rz_socket_free (fd); return 1; } else if (child_pid != 0){ // parent code @@ -889,13 +889,13 @@ R_API int r_run_config_env(RRunProfile *p) { } if (is_child) { - r_socket_close_fd (fd); + rz_socket_close_fd (fd); eprintf ("connected\n"); if (p->_pty) { if (redirect_socket_to_pty (child) != 0) { eprintf ("socket redirection failed\n"); - r_socket_free (child); - r_socket_free (fd); + rz_socket_free (child); + rz_socket_free (fd); return 1; } } else { @@ -903,17 +903,17 @@ R_API int r_run_config_env(RRunProfile *p) { } break; } else { - r_socket_close_fd (child); + rz_socket_close_fd (child); } } } if (!is_child) { - r_socket_free (child); + rz_socket_free (child); } - r_socket_free (fd); + rz_socket_free (fd); } - if (p->_r2sleep != 0) { - r_sys_sleep (p->_r2sleep); + if (p->_rzsleep != 0) { + rz_sys_sleep (p->_rzsleep); } #if __UNIX__ if (p->_chroot) { @@ -988,14 +988,14 @@ R_API int r_run_config_env(RRunProfile *p) { close (0); dup2 (f2[0], 0); } else { - eprintf ("[ERROR] rarun2: Cannot create pipe\n"); + eprintf ("[ERROR] rz_run: Cannot create pipe\n"); return 1; } inp = getstr (p->_input); if (inp) { size_t inpl = strlen (inp); if (write (f2[1], inp, inpl) != inpl) { - eprintf ("[ERROR] rarun2: Cannot write to the pipe\n"); + eprintf ("[ERROR] rz_run: Cannot write to the pipe\n"); } close (f2[1]); free (inp); @@ -1004,58 +1004,58 @@ R_API int r_run_config_env(RRunProfile *p) { } } #endif - if (p->_r2preload) { + if (p->_rzpreload) { if (p->_preload) { eprintf ("WARNING: Only one library can be opened at a time\n"); } #ifdef __WINDOWS__ - p->_preload = r_str_r2_prefix (R_JOIN_2_PATHS (R2_LIBDIR, "libr2."R_LIB_EXT)); + p->_preload = rz_str_rz_prefix (R_JOIN_2_PATHS (R2_LIBDIR, "librz."R_LIB_EXT)); #else - p->_preload = strdup (R2_LIBDIR"/libr2."R_LIB_EXT); + p->_preload = strdup (R2_LIBDIR"/librz."R_LIB_EXT); #endif } if (p->_libpath) { #if __WINDOWS__ - eprintf ("rarun2: libpath unsupported for this platform\n"); + eprintf ("rz_run: libpath unsupported for this platform\n"); #elif __HAIKU__ - r_sys_setenv ("LIBRARY_PATH", p->_libpath); + rz_sys_setenv ("LIBRARY_PATH", p->_libpath); #elif __APPLE__ - r_sys_setenv ("DYLD_LIBRARY_PATH", p->_libpath); + rz_sys_setenv ("DYLD_LIBRARY_PATH", p->_libpath); #else - r_sys_setenv ("LD_LIBRARY_PATH", p->_libpath); + rz_sys_setenv ("LD_LIBRARY_PATH", p->_libpath); #endif } if (p->_preload) { #if __APPLE__ // 10.6 #ifndef __MAC_10_7 - r_sys_setenv ("DYLD_PRELOAD", p->_preload); + rz_sys_setenv ("DYLD_PRELOAD", p->_preload); #endif - r_sys_setenv ("DYLD_INSERT_LIBRARIES", p->_preload); + rz_sys_setenv ("DYLD_INSERT_LIBRARIES", p->_preload); // 10.8 - r_sys_setenv ("DYLD_FORCE_FLAT_NAMESPACE", "1"); + rz_sys_setenv ("DYLD_FORCE_FLAT_NAMESPACE", "1"); #else - r_sys_setenv ("LD_PRELOAD", p->_preload); + rz_sys_setenv ("LD_PRELOAD", p->_preload); #endif } if (p->_timeout) { #if __UNIX__ int mypid = getpid (); - if (!r_sys_fork ()) { + if (!rz_sys_fork ()) { int use_signal = p->_timeout_sig; if (use_signal < 1) { use_signal = SIGKILL; } sleep (p->_timeout); if (!kill (mypid, 0)) { - // eprintf ("\nrarun2: Interrupted by timeout\n"); + // eprintf ("\nrz_run: Interrupted by timeout\n"); } kill (mypid, use_signal); exit (0); } #else if (p->_timeout_sig < 1 || p->_timeout_sig == 9) { - r_th_new (exit_process, NULL, p->_timeout); + rz_th_new (exit_process, NULL, p->_timeout); } else { eprintf ("timeout with signal not supported for this platform\n"); } @@ -1065,7 +1065,7 @@ R_API int r_run_config_env(RRunProfile *p) { } // NOTE: return value is like in unix return code (0 = ok, 1 = not ok) -R_API int r_run_start(RRunProfile *p) { +RZ_API int rz_run_start(RRunProfile *p) { #if LIBC_HAVE_FORK if (p->_execve) { exit (execv (p->_program, (char* const*)p->_args)); @@ -1077,7 +1077,7 @@ R_API int r_run_start(RRunProfile *p) { int ret; posix_spawnattr_init (&attr); if (p->_args[0]) { - char **envp = r_sys_get_environ(); + char **envp = rz_sys_get_environ(); ut32 spflags = 0; //POSIX_SPAWN_START_SUSPENDED; spflags |= POSIX_SPAWN_SETEXEC; if (p->_aslr == 0) { @@ -1126,7 +1126,7 @@ R_API int r_run_start(RRunProfile *p) { #if __WINDOWS__ // eprintf ("PID: Cannot determine pid with 'system' directive. Use 'program'.\n"); #else - pid_t child = r_sys_fork (); + pid_t child = rz_sys_fork (); if (child == -1) { perror ("fork"); exit (1); @@ -1135,7 +1135,7 @@ R_API int r_run_start(RRunProfile *p) { if (p->_pidfile) { char pidstr[32]; snprintf (pidstr, sizeof (pidstr), "%d\n", child); - r_file_dump (p->_pidfile, + rz_file_dump (p->_pidfile, (const ut8*)pidstr, strlen (pidstr), 0); } @@ -1145,14 +1145,14 @@ R_API int r_run_start(RRunProfile *p) { if (p->_timeout) { #if __UNIX__ int mypid = getpid (); - if (!r_sys_fork ()) { + if (!rz_sys_fork ()) { int use_signal = p->_timeout_sig; if (use_signal < 1) { use_signal = SIGKILL; } sleep (p->_timeout); if (!kill (mypid, 0)) { - // eprintf ("\nrarun2: Interrupted by timeout\n"); + // eprintf ("\nrz_run: Interrupted by timeout\n"); } kill (mypid, use_signal); exit (0); @@ -1167,24 +1167,24 @@ R_API int r_run_start(RRunProfile *p) { close(1); exit (execl ("/bin/sh","/bin/sh", "-c", p->_system, NULL)); #else - exit (r_sys_cmd (p->_system)); + exit (rz_sys_cmd (p->_system)); #endif } else { if (p->_pidfile) { eprintf ("Warning: pidfile doesnt work with 'system'.\n"); } - exit (r_sys_cmd (p->_system)); + exit (rz_sys_cmd (p->_system)); } } if (p->_program) { - if (!r_file_exists (p->_program)) { - char *progpath = r_file_path (p->_program); + if (!rz_file_exists (p->_program)) { + char *progpath = rz_file_path (p->_program); if (progpath && *progpath) { free (p->_program); p->_program = progpath; } else { free (progpath); - eprintf ("rarun2: %s: file not found\n", p->_program); + eprintf ("rz_run: %s: file not found\n", p->_program); return 1; } } @@ -1208,7 +1208,7 @@ R_API int r_run_start(RRunProfile *p) { if (p->_pidfile) { char pidstr[32]; snprintf (pidstr, sizeof (pidstr), "%d\n", getpid ()); - r_file_dump (p->_pidfile, + rz_file_dump (p->_pidfile, (const ut8*)pidstr, strlen (pidstr), 0); } @@ -1227,7 +1227,7 @@ R_API int r_run_start(RRunProfile *p) { #if __WINDOWS__ eprintf ("PID: Cannot determine pid with 'system' directive. Use 'program'.\n"); #else - pid_t child = r_sys_fork (); + pid_t child = rz_sys_fork (); if (child == -1) { perror ("fork"); exit (1); @@ -1236,7 +1236,7 @@ R_API int r_run_start(RRunProfile *p) { if (p->_pidfile) { char pidstr[32]; snprintf (pidstr, sizeof (pidstr), "%d\n", child); - r_file_dump (p->_pidfile, + rz_file_dump (p->_pidfile, (const ut8*)pidstr, strlen (pidstr), 0); exit (0); @@ -1258,12 +1258,12 @@ R_API int r_run_start(RRunProfile *p) { eprintf ("No function specified. Please set runlib.fcn\n"); return 1; } - void *addr = r_lib_dl_open (p->_runlib); + void *addr = rz_lib_dl_open (p->_runlib); if (!addr) { eprintf ("Could not load the library '%s'\n", p->_runlib); return 1; } - void (*fcn)(void) = r_lib_dl_sym (addr, p->_runlib_fcn); + void (*fcn)(void) = rz_lib_dl_sym (addr, p->_runlib_fcn); if (!fcn) { eprintf ("Could not find the function '%s'\n", p->_runlib_fcn); return 1; @@ -1273,68 +1273,68 @@ R_API int r_run_start(RRunProfile *p) { fcn (); break; case 1: - r_run_call1 (fcn, p->_args[1]); + rz_run_call1 (fcn, p->_args[1]); break; case 2: - r_run_call2 (fcn, p->_args[1], p->_args[2]); + rz_run_call2 (fcn, p->_args[1], p->_args[2]); break; case 3: - r_run_call3 (fcn, p->_args[1], p->_args[2], p->_args[3]); + rz_run_call3 (fcn, p->_args[1], p->_args[2], p->_args[3]); break; case 4: - r_run_call4 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4]); + rz_run_call4 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4]); break; case 5: - r_run_call5 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call5 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5]); break; case 6: - r_run_call6 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call6 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5], p->_args[6]); break; case 7: - r_run_call7 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call7 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5], p->_args[6], p->_args[7]); break; case 8: - r_run_call8 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call8 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5], p->_args[6], p->_args[7], p->_args[8]); break; case 9: - r_run_call9 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call9 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5], p->_args[6], p->_args[7], p->_args[8], p->_args[9]); break; case 10: - r_run_call10 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], + rz_run_call10 (fcn, p->_args[1], p->_args[2], p->_args[3], p->_args[4], p->_args[5], p->_args[6], p->_args[7], p->_args[8], p->_args[9], p->_args[10]); break; default: eprintf ("Too many arguments.\n"); return 1; } - r_lib_dl_close (addr); + rz_lib_dl_close (addr); } return 0; } -R_API char *r_run_get_environ_profile(char **env) { +RZ_API char *rz_run_get_environ_profile(char **env) { if (!env) { return NULL; } - RStrBuf *sb = r_strbuf_new (NULL); + RStrBuf *sb = rz_strbuf_new (NULL); while (*env) { char *k = strdup (*env); char *v = strchr (k, '='); if (v) { *v++ = 0; - v = r_str_escape_latin1 (v, false, true, true); + v = rz_str_escape_latin1 (v, false, true, true); if (v) { - r_strbuf_appendf (sb, "setenv=%s=\"%s\"\n", k, v); + rz_strbuf_appendf (sb, "setenv=%s=\"%s\"\n", k, v); free (v); } } free (k); env++; } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } diff --git a/libr/socket/r2pipe.c b/librz/socket/rzpipe.c similarity index 55% rename from libr/socket/r2pipe.c rename to librz/socket/rzpipe.c index 185b4d99bd..c2131aec1e 100644 --- a/libr/socket/r2pipe.c +++ b/librz/socket/rzpipe.c @@ -2,23 +2,23 @@ /* Usage Example: - #include + #include int main() { - RCoreBind rcb; - RCore *core = r_core_new (); - r_core_bind (core, &rcb); - r2pipe_open_corebind (&rcb); - char *clippy = r2pipe_cmd ("?E hello"); + RzCoreBind rcb; + RzCore *core = rz_core_new (); + rz_core_bind (core, &rcb); + rzpipe_open_corebind (&rcb); + char *clippy = rzpipe_cmd ("?E hello"); eprintf ("%s\n", clippy); free (clippy); - r2pipe_close (r2pipe); - r_core_free (core); + rzpipe_close (rzpipe); + rz_core_free (core); } */ -#include -#include -#include +#include +#include +#include #define R2P_PID(x) (((R2Pipe*)(x)->data)->pid) #define R2P_INPUT(x) (((R2Pipe*)(x)->data)->input[0]) @@ -26,16 +26,16 @@ Usage Example: #if !__WINDOWS__ static void env(const char *s, int f) { - char *a = r_str_newf ("%d", f); - r_sys_setenv (s, a); + char *a = rz_str_newf ("%d", f); + rz_sys_setenv (s, a); free (a); } #endif -R_API int r2pipe_write(R2Pipe *r2pipe, const char *str) { +RZ_API int rzpipe_write(R2Pipe *rzpipe, const char *str) { char *cmd; int ret, len; - if (!r2pipe || !str) { + if (!rzpipe || !str) { return -1; } len = strlen (str) + 2; /* include \n\x00 */ @@ -47,20 +47,20 @@ R_API int r2pipe_write(R2Pipe *r2pipe, const char *str) { strcpy (cmd + len - 2, "\n"); #if __WINDOWS__ DWORD dwWritten = -1; - WriteFile (r2pipe->pipe, cmd, len, &dwWritten, NULL); + WriteFile (rzpipe->pipe, cmd, len, &dwWritten, NULL); ret = (dwWritten == len); #else - ret = (write (r2pipe->input[1], cmd, len) == len); + ret = (write (rzpipe->input[1], cmd, len) == len); #endif free (cmd); return ret; } /* TODO: add timeout here ? */ -R_API char *r2pipe_read(R2Pipe *r2pipe) { +RZ_API char *rzpipe_read(R2Pipe *rzpipe) { int bufsz = 0; char *buf = NULL; - if (!r2pipe) { + if (!rzpipe) { return NULL; } bufsz = 4096; @@ -72,7 +72,7 @@ R_API char *r2pipe_read(R2Pipe *r2pipe) { BOOL bSuccess = FALSE; DWORD dwRead = 0; // TODO: handle > 4096 buffers here - bSuccess = ReadFile (r2pipe->pipe, buf, bufsz, &dwRead, NULL); + bSuccess = ReadFile (rzpipe->pipe, buf, bufsz, &dwRead, NULL); if (!bSuccess || !buf[0]) { return NULL; } @@ -84,7 +84,7 @@ R_API char *r2pipe_read(R2Pipe *r2pipe) { char *newbuf; int i, rv; for (i = 0; i < bufsz; i++) { - rv = read (r2pipe->output[0], buf + i, 1); + rv = read (rzpipe->output[0], buf + i, 1); if (i + 2 >= bufsz) { bufsz += 4096; newbuf = realloc (buf, bufsz); @@ -106,60 +106,60 @@ R_API char *r2pipe_read(R2Pipe *r2pipe) { return buf; } -R_API int r2pipe_close(R2Pipe *r2pipe) { - if (!r2pipe) { +RZ_API int rzpipe_close(R2Pipe *rzpipe) { + if (!rzpipe) { return 0; } /* - if (r2pipe->coreb.core && !r2pipe->coreb.puts) { - void (*rfre)(void *c) = r_lib_dl_sym (libr, "r_core_free"); + if (rzpipe->coreb.core && !rzpipe->coreb.puts) { + void (*rfre)(void *c) = rz_lib_dl_sym (librz, "rz_core_free"); if (rfre) { - rfre (r2pipe->coreb.core); + rfre (rzpipe->coreb.core); } } */ #if __WINDOWS__ - if (r2pipe->pipe) { - CloseHandle (r2pipe->pipe); - r2pipe->pipe = NULL; + if (rzpipe->pipe) { + CloseHandle (rzpipe->pipe); + rzpipe->pipe = NULL; } #else - if (r2pipe->input[0] != -1) { - close (r2pipe->input[0]); - r2pipe->input[0] = -1; + if (rzpipe->input[0] != -1) { + close (rzpipe->input[0]); + rzpipe->input[0] = -1; } - if (r2pipe->input[1] != -1) { - close (r2pipe->input[1]); - r2pipe->input[1] = -1; + if (rzpipe->input[1] != -1) { + close (rzpipe->input[1]); + rzpipe->input[1] = -1; } - if (r2pipe->output[0] != -1) { - close (r2pipe->output[0]); - r2pipe->output[0] = -1; + if (rzpipe->output[0] != -1) { + close (rzpipe->output[0]); + rzpipe->output[0] = -1; } - if (r2pipe->output[1] != -1) { - close (r2pipe->output[1]); - r2pipe->output[1] = -1; + if (rzpipe->output[1] != -1) { + close (rzpipe->output[1]); + rzpipe->output[1] = -1; } - if (r2pipe->child != -1) { - kill (r2pipe->child, SIGTERM); - waitpid (r2pipe->child, NULL, 0); - r2pipe->child = -1; + if (rzpipe->child != -1) { + kill (rzpipe->child, SIGTERM); + waitpid (rzpipe->child, NULL, 0); + rzpipe->child = -1; } #endif - free (r2pipe); + free (rzpipe); return 0; } #if __WINDOWS__ -static int w32_createPipe(R2Pipe *r2pipe, const char *cmd) { +static int w32_createPipe(R2Pipe *rzpipe, const char *cmd) { CHAR buf[1024]; - r2pipe->pipe = CreateNamedPipe (TEXT ("\\\\.\\pipe\\R2PIPE_IN"), + rzpipe->pipe = CreateNamedPipe (TEXT ("\\\\.\\pipe\\R2PIPE_IN"), PIPE_ACCESS_DUPLEX,PIPE_TYPE_MESSAGE | \ PIPE_READMODE_MESSAGE | \ PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof (buf), sizeof (buf), 0, NULL); - if (r_sys_create_child_proc_w32 (cmd, NULL, NULL, NULL)) { - if (ConnectNamedPipe (r2pipe->pipe, NULL)) { + if (rz_sys_create_child_proc_w32 (cmd, NULL, NULL, NULL)) { + if (ConnectNamedPipe (rzpipe->pipe, NULL)) { return true; } } @@ -168,10 +168,10 @@ static int w32_createPipe(R2Pipe *r2pipe, const char *cmd) { #endif static R2Pipe* r2p_open_spawn(R2Pipe* r2p, const char *cmd) { - r_return_val_if_fail (r2p, NULL); + rz_return_val_if_fail (r2p, NULL); #if __UNIX__ || defined(__CYGWIN__) - char *out = r_sys_getenv ("R2PIPE_IN"); - char *in = r_sys_getenv ("R2PIPE_OUT"); + char *out = rz_sys_getenv ("R2PIPE_IN"); + char *in = rz_sys_getenv ("R2PIPE_OUT"); int done = false; if (in && out) { int i_in = atoi (in); @@ -190,51 +190,51 @@ static R2Pipe* r2p_open_spawn(R2Pipe* r2p, const char *cmd) { free (out); return r2p; #else - eprintf ("r2pipe_open(NULL) not supported on windows\n"); + eprintf ("rzpipe_open(NULL) not supported on windows\n"); return NULL; #endif } -static R2Pipe *r2pipe_new(void) { - R2Pipe *r2pipe = R_NEW0 (R2Pipe); - if (r2pipe) { +static R2Pipe *rzpipe_new(void) { + R2Pipe *rzpipe = R_NEW0 (R2Pipe); + if (rzpipe) { #if __UNIX__ - r2pipe->input[0] = r2pipe->input[1] = -1; - r2pipe->output[0] = r2pipe->output[1] = -1; + rzpipe->input[0] = rzpipe->input[1] = -1; + rzpipe->output[0] = rzpipe->output[1] = -1; #endif - r2pipe->child = -1; + rzpipe->child = -1; } - return r2pipe; + return rzpipe; } -R_API R2Pipe *r2pipe_open_corebind(RCoreBind *coreb) { - R2Pipe *r2pipe = r2pipe_new (); - if (r2pipe) { - memcpy (&r2pipe->coreb, coreb, sizeof (RCoreBind)); +RZ_API R2Pipe *rzpipe_open_corebind(RzCoreBind *coreb) { + R2Pipe *rzpipe = rzpipe_new (); + if (rzpipe) { + memcpy (&rzpipe->coreb, coreb, sizeof (RzCoreBind)); } - return r2pipe; + return rzpipe; } -R_API R2Pipe *r2pipe_open_dl(const char *libr_path) { - void *libr = r_lib_dl_open (libr_path); - void* (*rnew)() = r_lib_dl_sym (libr, "r_core_new"); - char* (*rcmd)(void *c, const char *cmd) = r_lib_dl_sym (libr, "r_core_cmd_str"); +RZ_API R2Pipe *rzpipe_open_dl(const char *libr_path) { + void *librz = rz_lib_dl_open (libr_path); + void* (*rnew)() = rz_lib_dl_sym (librz, "rz_core_new"); + char* (*rcmd)(void *c, const char *cmd) = rz_lib_dl_sym (librz, "rz_core_cmd_str"); if (rnew && rcmd) { - R2Pipe *r2pipe = r2pipe_new (); - if (r2pipe) { - r2pipe->coreb.core = rnew (); - r2pipe->coreb.cmdstr = rcmd; - // r2pipe->coreb.free = rfre; + R2Pipe *rzpipe = rzpipe_new (); + if (rzpipe) { + rzpipe->coreb.core = rnew (); + rzpipe->coreb.cmdstr = rcmd; + // rzpipe->coreb.free = rfre; } - return r2pipe; + return rzpipe; } - eprintf ("Cannot resolve r_core_cmd, r_core_cmd_str, r_core_free\n"); + eprintf ("Cannot resolve rz_core_cmd, rz_core_cmd_str, rz_core_free\n"); return NULL; } -R_API R2Pipe *r2pipe_open(const char *cmd) { - R2Pipe *r2p = r2pipe_new (); +RZ_API R2Pipe *rzpipe_open(const char *cmd) { + R2Pipe *r2p = rzpipe_new (); if (!r2p) { return NULL; } @@ -249,13 +249,13 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { int r = pipe (r2p->input); if (r != 0) { eprintf ("pipe failed on input\n"); - r2pipe_close (r2p); + rzpipe_close (r2p); return NULL; } r = pipe (r2p->output); if (r != 0) { eprintf ("pipe failed on output\n"); - r2pipe_close (r2p); + rzpipe_close (r2p); return NULL; } #if LIBC_HAVE_FORK @@ -264,7 +264,7 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { r2p->child = -1; #endif if (r2p->child == -1) { - r2pipe_close (r2p); + rzpipe_close (r2p); return NULL; } env ("R2PIPE_IN", r2p->input[0]); @@ -272,15 +272,15 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { if (r2p->child) { char ch = -1; - // eprintf ("[+] r2pipeipe child is %d\n", r2pipe->child); + // eprintf ("[+] rzpipeipe child is %d\n", rzpipe->child); if (read (r2p->output[0], &ch, 1) != 1) { eprintf ("Failed to read 1 byte\n"); - r2pipe_close (r2p); + rzpipe_close (r2p); return NULL; } if (ch == -1) { - eprintf ("[+] r2pipe link error.\n"); - r2pipe_close (r2p); + eprintf ("[+] rzpipe link error.\n"); + rzpipe_close (r2p); return NULL; } // Close parent's end of pipes @@ -299,7 +299,7 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { close (r2p->output[0]); r2p->input[1] = -1; r2p->output[0] = -1; - rc = r_sandbox_system (cmd, 1); + rc = rz_sandbox_system (cmd, 1); fprintf (stderr, "return code %d for %s\n", rc, cmd); fflush (stderr); // trigger the blocking read @@ -309,7 +309,7 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { close (1); } r2p->child = -1; - r2pipe_close (r2p); + rzpipe_close (r2p); exit (rc); return NULL; } @@ -317,16 +317,16 @@ R_API R2Pipe *r2pipe_open(const char *cmd) { return r2p; } -R_API char *r2pipe_cmd(R2Pipe *r2p, const char *str) { - r_return_val_if_fail (r2p && str, NULL); - if (!*str || !r2pipe_write (r2p, str)) { - perror ("r2pipe_write"); +RZ_API char *rzpipe_cmd(R2Pipe *r2p, const char *str) { + rz_return_val_if_fail (r2p && str, NULL); + if (!*str || !rzpipe_write (r2p, str)) { + perror ("rzpipe_write"); return NULL; } - return r2pipe_read (r2p); + return rzpipe_read (r2p); } -R_API char *r2pipe_cmdf(R2Pipe *r2p, const char *fmt, ...) { +RZ_API char *rzpipe_cmdf(R2Pipe *r2p, const char *fmt, ...) { int ret, ret2; char *p, string[1024]; va_list ap, ap2; @@ -347,10 +347,10 @@ R_API char *r2pipe_cmdf(R2Pipe *r2p, const char *fmt, ...) { va_end (ap); return NULL; } - fmt = r2pipe_cmd (r2p, p); + fmt = rzpipe_cmd (r2p, p); free (p); } else { - fmt = r2pipe_cmd (r2p, string); + fmt = rzpipe_cmd (r2p, string); } va_end (ap2); va_end (ap); diff --git a/libr/socket/socket.c b/librz/socket/socket.c similarity index 73% rename from libr/socket/socket.c rename to librz/socket/socket.c index de53209d0d..5dcbe5d427 100644 --- a/libr/socket/socket.c +++ b/librz/socket/socket.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2006-2020 - pancake */ /* must be included first because of winsock2.h and windows.h */ -#include -#include -#include +#include +#include +#include #include #if EMSCRIPTEN @@ -14,78 +14,78 @@ #define D if(0) -R_LIB_VERSION(r_socket); +R_LIB_VERSION(rz_socket); #if NETWORK_DISABLED /* no network */ -R_API RSocket *r_socket_new(bool is_ssl) { +RZ_API RzSocket *rz_socket_new(bool is_ssl) { return NULL; } -R_API bool r_socket_is_connected(RSocket *s) { +RZ_API bool rz_socket_is_connected(RzSocket *s) { return false; } -R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int proto, unsigned int timeout) { +RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout) { return false; } -R_API bool r_socket_spawn(RSocket *s, const char *cmd, unsigned int timeout) { +RZ_API bool rz_socket_spawn(RzSocket *s, const char *cmd, unsigned int timeout) { return -1; } -R_API int r_socket_close_fd(RSocket *s) { +RZ_API int rz_socket_close_fd(RzSocket *s) { return -1; } -R_API int r_socket_close(RSocket *s) { +RZ_API int rz_socket_close(RzSocket *s) { return -1; } -R_API int r_socket_free(RSocket *s) { +RZ_API int rz_socket_free(RzSocket *s) { return -1; } -R_API int r_socket_port_by_name(const char *name) { +RZ_API int rz_socket_port_by_name(const char *name) { return -1; } -R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { +RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile) { return false; } -R_API RSocket *r_socket_accept(RSocket *s) { +RZ_API RzSocket *rz_socket_accept(RzSocket *s) { return NULL; } -R_API RSocket *r_socket_accept_timeout(RSocket *s, unsigned int timeout) { +RZ_API RzSocket *rz_socket_accept_timeout(RzSocket *s, unsigned int timeout) { return NULL; } -R_API bool r_socket_block_time(RSocket *s, bool block, int sec, int usec) { +RZ_API bool rz_socket_block_time(RzSocket *s, bool block, int sec, int usec) { return false; } -R_API int r_socket_flush(RSocket *s) { +RZ_API int rz_socket_flush(RzSocket *s) { return -1; } -R_API int r_socket_ready(RSocket *s, int secs, int usecs) { +RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs) { return -1; } -R_API char *r_socket_to_string(RSocket *s) { +RZ_API char *rz_socket_to_string(RzSocket *s) { return NULL; } -R_API int r_socket_write(RSocket *s, void *buf, int len) { +RZ_API int rz_socket_write(RzSocket *s, void *buf, int len) { return -1; } -R_API int r_socket_puts(RSocket *s, char *buf) { +RZ_API int rz_socket_puts(RzSocket *s, char *buf) { return -1; } -R_API void r_socket_printf(RSocket *s, const char *fmt, ...) { +RZ_API void rz_socket_printf(RzSocket *s, const char *fmt, ...) { /* nothing here */ } -R_API int r_socket_read(RSocket *s, unsigned char *buf, int len) { +RZ_API int rz_socket_read(RzSocket *s, unsigned char *buf, int len) { return -1; } -R_API int r_socket_read_block(RSocket *s, unsigned char *buf, int len) { +RZ_API int rz_socket_read_block(RzSocket *s, unsigned char *buf, int len) { return -1; } -R_API int r_socket_gets(RSocket *s, char *buf, int size) { +RZ_API int rz_socket_gets(RzSocket *s, char *buf, int size) { return -1; } -R_API RSocket *r_socket_new_from_fd (int fd) { +RZ_API RzSocket *rz_socket_new_from_fd (int fd) { return NULL; } -R_API ut8* r_socket_slurp(RSocket *s, int *len) { +RZ_API ut8* rz_socket_slurp(RzSocket *s, int *len) { return NULL; } #else @@ -98,16 +98,16 @@ WSACleanup: closes all network connections #endif #define BUFFER_SIZE 4096 -R_API bool r_socket_is_connected(RSocket *s) { +RZ_API bool rz_socket_is_connected(RzSocket *s) { #if __WINDOWS__ char buf[2]; - r_socket_block_time (s, false, 0, 0); + rz_socket_block_time (s, false, 0, 0); #ifdef _MSC_VER int ret = recv (s->fd, (char*)&buf, 1, MSG_PEEK); #else ssize_t ret = recv (s->fd, (char*)&buf, 1, MSG_PEEK); #endif - r_socket_block_time (s, true, 0, 0); + rz_socket_block_time (s, true, 0, 0); return ret == 1; #else int error = 0; @@ -122,7 +122,7 @@ R_API bool r_socket_is_connected(RSocket *s) { } #if __UNIX__ -static bool __connect_unix(RSocket *s, const char *file) { +static bool __connect_unix(RzSocket *s, const char *file) { struct sockaddr_un addr; int sock = socket (PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -143,7 +143,7 @@ static bool __connect_unix(RSocket *s, const char *file) { return true; } -static bool __listen_unix(RSocket *s, const char *file) { +static bool __listen_unix(RzSocket *s, const char *file) { struct sockaddr_un unix_name; int sock = socket (PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -160,7 +160,7 @@ static bool __listen_unix(RSocket *s, const char *file) { close (sock); return false; } - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); /* change permissions */ if (chmod (unix_name.sun_path, 0777) != 0) { @@ -176,15 +176,15 @@ static bool __listen_unix(RSocket *s, const char *file) { } #endif -R_API RSocket *r_socket_new(bool is_ssl) { - RSocket *s = R_NEW0 (RSocket); +RZ_API RzSocket *rz_socket_new(bool is_ssl) { + RzSocket *s = R_NEW0 (RzSocket); if (!s) { return NULL; } s->is_ssl = is_ssl; s->port = 0; #if __UNIX_ - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); #endif s->local = 0; s->fd = R_INVALID_SOCKET; @@ -195,7 +195,7 @@ R_API RSocket *r_socket_new(bool is_ssl) { s->bio = NULL; #if OPENSSL_VERSION_NUMBER < 0x1010000fL if (!SSL_library_init ()) { - r_socket_free (s); + rz_socket_free (s); return NULL; } SSL_load_error_strings (); @@ -205,57 +205,57 @@ R_API RSocket *r_socket_new(bool is_ssl) { return s; } -R_API bool r_socket_spawn(RSocket *s, const char *cmd, unsigned int timeout) { +RZ_API bool rz_socket_spawn(RzSocket *s, const char *cmd, unsigned int timeout) { // XXX TODO: dont use sockets, we can achieve the same with pipes - const int port = 2000 + r_num_rand (2000); - int childPid = r_sys_fork (); + const int port = 2000 + rz_num_rand (2000); + int childPid = rz_sys_fork (); if (childPid == 0) { - char *a = r_str_replace (strdup (cmd), "\\", "\\\\", true); - int res = r_sys_cmdf ("rarun2 system=\"%s\" listen=%d", a, port); + char *a = rz_str_replace (strdup (cmd), "\\", "\\\\", true); + int res = rz_sys_cmdf ("rz_run system=\"%s\" listen=%d", a, port); free (a); #if 0 // TODO: use the api - char *profile = r_str_newf ( + char *profile = rz_str_newf ( "system=%s\n" "listen=%d\n", cmd, port); - RRunProfile *rp = r_run_new (profile); - r_run_start (rp); - r_run_free (rp); + RRunProfile *rp = rz_run_new (profile); + rz_run_start (rp); + rz_run_free (rp); free (profile); #endif if (res != 0) { - eprintf ("r_socket_spawn: rarun2 failed\n"); + eprintf ("rz_socket_spawn: rz_run failed\n"); exit (1); } - eprintf ("r_socket_spawn: %s is dead\n", cmd); + eprintf ("rz_socket_spawn: %s is dead\n", cmd); exit (0); } - r_sys_sleep (1); - r_sys_usleep (timeout); + rz_sys_sleep (1); + rz_sys_usleep (timeout); char aport[32]; sprintf (aport, "%d", port); // redirect stdin/stdout/stderr - bool sock = r_socket_connect (s, "127.0.0.1", aport, R_SOCKET_PROTO_TCP, 2000); + bool sock = rz_socket_connect (s, "127.0.0.1", aport, R_SOCKET_PROTO_TCP, 2000); if (!sock) { return false; } #if __UNIX__ - r_sys_sleep (4); - r_sys_usleep (timeout); + rz_sys_sleep (4); + rz_sys_usleep (timeout); int status = 0; int ret = waitpid (childPid, &status, WNOHANG); if (ret != 0) { - r_socket_close (s); + rz_socket_close (s); return false; } #endif return true; } -R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int proto, unsigned int timeout) { - r_return_val_if_fail (s, false); +RZ_API bool rz_socket_connect(RzSocket *s, const char *host, const char *port, int proto, unsigned int timeout) { + rz_return_val_if_fail (s, false); #if __WINDOWS__ #define gai_strerror gai_strerrorA struct sockaddr_in sa; @@ -273,7 +273,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int proto = R_SOCKET_PROTO_DEFAULT; } #if __UNIX__ - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); #endif if (proto == R_SOCKET_PROTO_UNIX) { #if __UNIX__ @@ -286,7 +286,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int hints.ai_protocol = proto; int gai = getaddrinfo (host, port, &hints, &res); if (gai != 0) { - eprintf ("r_socket_connect: Error in getaddrinfo: %s (%s:%s)\n", + eprintf ("rz_socket_connect: Error in getaddrinfo: %s (%s:%s)\n", gai_strerror (gai), host, port); return false; } @@ -308,20 +308,20 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int s->fd = -1; continue; } - r_socket_block_time (s, true, 1, 0); + rz_socket_block_time (s, true, 1, 0); ret = connect (s->fd, rp->ai_addr, rp->ai_addrlen); break; case R_SOCKET_PROTO_UDP: memset (&s->sa, 0, sizeof (s->sa)); s->sa.sin_family = AF_INET; s->sa.sin_addr.s_addr = htonl (s->local? INADDR_LOOPBACK: INADDR_ANY); - s->port = r_socket_port_by_name (port); + s->port = rz_socket_port_by_name (port); if (s->port < 1) { continue; } s->sa.sin_port = htons (s->port); if (bind (s->fd, (struct sockaddr *)&s->sa, sizeof (s->sa)) < 0) { - r_sys_perror ("bind"); + rz_sys_perror ("bind"); #ifdef __WINDOWS__ closesocket (s->fd); #else @@ -332,7 +332,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int ret = connect (s->fd, rp->ai_addr, rp->ai_addrlen); break; default: - r_socket_block_time (s, true, 1, 0); + rz_socket_block_time (s, true, 1, 0); ret = connect (s->fd, rp->ai_addr, rp->ai_addrlen); break; } @@ -348,7 +348,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int FD_SET (s->fd, &wfds); if ((ret = select (s->fd + 1, NULL, &wfds, NULL, &tv)) != -1) { - if (r_socket_is_connected (s)) { + if (rz_socket_is_connected (s)) { freeaddrinfo (res); goto success; } @@ -356,7 +356,7 @@ R_API bool r_socket_connect(RSocket *s, const char *host, const char *port, int perror ("connect"); } } - r_socket_close (s); + rz_socket_close (s); } freeaddrinfo (res); if (!rp) { @@ -369,7 +369,7 @@ success: if (s->is_ssl) { s->ctx = SSL_CTX_new (SSLv23_client_method ()); if (!s->ctx) { - r_socket_close (s); + rz_socket_close (s); return false; } s->sfd = SSL_new (s->ctx); @@ -389,7 +389,7 @@ success: FD_SET (s->fd, &wfds); } if ((ret = select (s->fd + 1, &rfds, &wfds, NULL, &tv)) < 1) { - r_socket_close (s); + rz_socket_close (s); return false; } ret = SSL_connect (s->sfd); @@ -399,7 +399,7 @@ success: error = SSL_get_error (s->sfd, ret); tries--; } - r_socket_close (s); + rz_socket_close (s); return false; } } @@ -407,8 +407,8 @@ success: return true; } -/* close the file descriptor associated with the RSocket s */ -R_API int r_socket_close_fd(RSocket *s) { +/* close the file descriptor associated with the RzSocket s */ +RZ_API int rz_socket_close_fd(RzSocket *s) { #ifdef _MSC_VER return s->fd != INVALID_SOCKET ? closesocket (s->fd) : false; #else @@ -417,7 +417,7 @@ R_API int r_socket_close_fd(RSocket *s) { } /* shutdown the socket and close the file descriptor */ -R_API int r_socket_close(RSocket *s) { +RZ_API int rz_socket_close(RzSocket *s) { int ret = false; if (!s) { return false; @@ -429,7 +429,7 @@ R_API int r_socket_close(RSocket *s) { #if __WINDOWS__ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms740481(v=vs.85).aspx shutdown (s->fd, SD_SEND); - if (r_socket_ready (s, 0, 250)) { + if (rz_socket_ready (s, 0, 250)) { do { char buf = 0; ret = recv (s->fd, &buf, 1, 0); @@ -450,9 +450,9 @@ R_API int r_socket_close(RSocket *s) { return ret; } -/* shutdown the socket, close the file descriptor and free the RSocket */ -R_API int r_socket_free(RSocket *s) { - int res = r_socket_close (s); +/* shutdown the socket, close the file descriptor and free the RzSocket */ +RZ_API int rz_socket_free(RzSocket *s) { + int res = rz_socket_close (s); #if HAVE_LIB_SSL if (s && s->is_ssl) { if (s->sfd) { @@ -467,12 +467,12 @@ R_API int r_socket_free(RSocket *s) { return res; } -R_API int r_socket_port_by_name(const char *name) { +RZ_API int rz_socket_port_by_name(const char *name) { struct servent *p = getservbyname (name, "tcp"); - return (p && p->s_port) ? ntohs (p->s_port) : r_num_get (NULL, name); + return (p && p->s_port) ? ntohs (p->s_port) : rz_num_get (NULL, name); } -R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { +RZ_API bool rz_socket_listen(RzSocket *s, const char *port, const char *certfile) { int optval = 1; int ret; struct linger linger = { 0 }; @@ -484,7 +484,7 @@ R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { return false; } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return false; } #if __WINDOWS__ @@ -534,13 +534,13 @@ R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { memset (&s->sa, 0, sizeof (s->sa)); s->sa.sin_family = AF_INET; s->sa.sin_addr.s_addr = htonl (s->local? INADDR_LOOPBACK: INADDR_ANY); - s->port = r_socket_port_by_name (port); + s->port = rz_socket_port_by_name (port); if (s->port < 1) { return false; } s->sa.sin_port = htons (s->port); // TODO honor etc/services if (bind (s->fd, (struct sockaddr *)&s->sa, sizeof (s->sa)) < 0) { - r_sys_perror ("bind"); + rz_sys_perror ("bind"); #ifdef _MSC_VER closesocket (s->fd); #else @@ -549,11 +549,11 @@ R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { return false; } #if __UNIX__ - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); #endif if (s->proto == R_SOCKET_PROTO_TCP) { if (listen (s->fd, 32) < 0) { - r_sys_perror ("listen"); + rz_sys_perror ("listen"); #ifdef _MSC_VER closesocket (s->fd); #else @@ -566,15 +566,15 @@ R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { if (s->is_ssl) { s->ctx = SSL_CTX_new (SSLv23_method ()); if (!s->ctx) { - r_socket_free (s); + rz_socket_free (s); return false; } if (!SSL_CTX_use_certificate_chain_file (s->ctx, certfile)) { - r_socket_free (s); + rz_socket_free (s); return false; } if (!SSL_CTX_use_PrivateKey_file (s->ctx, certfile, SSL_FILETYPE_PEM)) { - r_socket_free (s); + rz_socket_free (s); return false; } SSL_CTX_set_verify_depth (s->ctx, 1); @@ -583,13 +583,13 @@ R_API bool r_socket_listen(RSocket *s, const char *port, const char *certfile) { return true; } -R_API RSocket *r_socket_accept(RSocket *s) { - RSocket *sock; +RZ_API RzSocket *rz_socket_accept(RzSocket *s) { + RzSocket *sock; socklen_t salen = sizeof (s->sa); if (!s) { return NULL; } - sock = R_NEW0 (RSocket); + sock = R_NEW0 (RzSocket); if (!sock) { return NULL; } @@ -598,7 +598,7 @@ R_API RSocket *r_socket_accept(RSocket *s) { if (sock->fd == R_INVALID_SOCKET) { if (errno != EWOULDBLOCK) { // not just a timeout - r_sys_perror ("accept"); + rz_sys_perror ("accept"); } free (sock); return NULL; @@ -613,7 +613,7 @@ R_API RSocket *r_socket_accept(RSocket *s) { sock->sfd = SSL_new (s->ctx); SSL_set_bio (sock->sfd, sbio, sbio); if (SSL_accept (sock->sfd) <= 0) { - r_socket_free (sock); + rz_socket_free (sock); return NULL; } sock->bio = BIO_new (BIO_f_buffer ()); @@ -627,7 +627,7 @@ R_API RSocket *r_socket_accept(RSocket *s) { return sock; } -R_API RSocket *r_socket_accept_timeout(RSocket *s, unsigned int timeout) { +RZ_API RzSocket *rz_socket_accept_timeout(RzSocket *s, unsigned int timeout) { fd_set read_fds; fd_set except_fds; @@ -643,14 +643,14 @@ R_API RSocket *r_socket_accept_timeout(RSocket *s, unsigned int timeout) { if(r < 0) { perror ("select"); } else if (r > 0 && FD_ISSET (s->fd, &read_fds)) { - return r_socket_accept (s); + return rz_socket_accept (s); } return NULL; } // Only applies to read in UNIX -R_API bool r_socket_block_time(RSocket *s, bool block, int sec, int usec) { +RZ_API bool rz_socket_block_time(RzSocket *s, bool block, int sec, int usec) { #if __UNIX__ int ret, flags; #endif @@ -680,7 +680,7 @@ R_API bool r_socket_block_time(RSocket *s, bool block, int sec, int usec) { return true; } -R_API int r_socket_flush(RSocket *s) { +RZ_API int rz_socket_flush(RzSocket *s) { #if HAVE_LIB_SSL if (s->is_ssl && s->bio) { return BIO_flush (s->bio); @@ -691,7 +691,7 @@ R_API int r_socket_flush(RSocket *s) { /* waits secs until new data is received. */ /* returns -1 on error, 0 is false, 1 is true */ -R_API int r_socket_ready(RSocket *s, int secs, int usecs) { +RZ_API int rz_socket_ready(RzSocket *s, int secs, int usecs) { fd_set rfds; struct timeval tv = {secs, usecs}; if (s->fd == R_INVALID_SOCKET) { @@ -702,9 +702,9 @@ R_API int r_socket_ready(RSocket *s, int secs, int usecs) { return select (s->fd + 1, &rfds, NULL, NULL, &tv); } -R_API char *r_socket_to_string(RSocket *s) { +RZ_API char *rz_socket_to_string(RzSocket *s) { #if __WINDOWS__ - return r_str_newf ("fd%d", (int)(size_t)s->fd); + return rz_str_newf ("fd%d", (int)(size_t)s->fd); #elif __UNIX__ char *str = NULL; struct sockaddr sa; @@ -718,7 +718,7 @@ R_API char *r_socket_to_string(RSocket *s) { a[0], a[1], a[2], a[3], ntohs (sain->sin_port)); } } else { - eprintf ("getperrname: failed\n"); //r_sys_perror ("getpeername"); + eprintf ("getperrname: failed\n"); //rz_sys_perror ("getpeername"); } return str; #else @@ -727,11 +727,11 @@ R_API char *r_socket_to_string(RSocket *s) { } /* Read/Write functions */ -R_API int r_socket_write(RSocket *s, void *buf, int len) { +RZ_API int rz_socket_write(RzSocket *s, void *buf, int len) { D { eprintf ("WRITE "); int i; ut8 *b = buf; for (i = 0; ifd != R_INVALID_SOCKET) { va_start (ap, fmt); vsnprintf (buf, BUFFER_SIZE, fmt, ap); - (void) r_socket_write (s, buf, strlen (buf)); + (void) rz_socket_write (s, buf, strlen (buf)); va_end (ap); } } -R_API int r_socket_read(RSocket *s, unsigned char *buf, int len) { +RZ_API int rz_socket_read(RzSocket *s, unsigned char *buf, int len) { if (!s) { return -1; } @@ -796,14 +796,14 @@ R_API int r_socket_read(RSocket *s, unsigned char *buf, int len) { return r; } -R_API int r_socket_read_block(RSocket *s, ut8 *buf, int len) { +RZ_API int rz_socket_read_block(RzSocket *s, ut8 *buf, int len) { int ret = 0; for (ret = 0; ret < len; ) { - int r = r_socket_read (s, buf + ret, len - ret); + int r = rz_socket_read (s, buf + ret, len - ret); if (r == -1) { #if HAVE_LIB_SSL if (s->is_ssl && SSL_get_error (s->sfd, r) == SSL_ERROR_WANT_READ) { - if (r_socket_ready (s, 1, 0) == 1) { + if (rz_socket_ready (s, 1, 0) == 1) { continue; } } @@ -818,7 +818,7 @@ R_API int r_socket_read_block(RSocket *s, ut8 *buf, int len) { return ret; } -R_API int r_socket_gets(RSocket *s, char *buf, int size) { +RZ_API int rz_socket_gets(RzSocket *s, char *buf, int size) { int i = 0; int ret = 0; @@ -826,7 +826,7 @@ R_API int r_socket_gets(RSocket *s, char *buf, int size) { return -1; } while (i < size) { - ret = r_socket_read (s, (ut8 *)buf + i, 1); + ret = rz_socket_read (s, (ut8 *)buf + i, 1); if (ret == 0) { if (i > 0) { return i; @@ -834,7 +834,7 @@ R_API int r_socket_gets(RSocket *s, char *buf, int size) { return -1; } if (ret < 0) { - r_socket_close (s); + rz_socket_close (s); return i == 0? -1: i; } if (buf[i] == '\r' || buf[i] == '\n') { @@ -847,8 +847,8 @@ R_API int r_socket_gets(RSocket *s, char *buf, int size) { return i; } -R_API RSocket *r_socket_new_from_fd(int fd) { - RSocket *s = R_NEW0 (RSocket); +RZ_API RzSocket *rz_socket_new_from_fd(int fd) { + RzSocket *s = R_NEW0 (RzSocket); if (s) { s->fd = fd; s->proto = R_SOCKET_PROTO_DEFAULT; @@ -856,7 +856,7 @@ R_API RSocket *r_socket_new_from_fd(int fd) { return s; } -R_API ut8* r_socket_slurp(RSocket *s, int *len) { +RZ_API ut8* rz_socket_slurp(RzSocket *s, int *len) { int blockSize = 4096; ut8 *ptr, *buf = malloc (blockSize); if (!buf) { @@ -867,7 +867,7 @@ R_API ut8* r_socket_slurp(RSocket *s, int *len) { *len = 0; } for (;;) { - int rc = r_socket_read (s, buf + copied, blockSize); + int rc = rz_socket_read (s, buf + copied, blockSize); if (rc > 0) { copied += rc; } diff --git a/libr/socket/socket_http.c b/librz/socket/socket_http.c similarity index 71% rename from libr/socket/socket_http.c rename to librz/socket/socket_http.c index 2f16220591..563d35c81b 100644 --- a/libr/socket/socket_http.c +++ b/librz/socket/socket_http.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2011-2020 - pancake */ -#include -#include +#include +#include #if __WINDOWS__ #include @@ -10,32 +10,32 @@ #define SOCKET_HTTP_MAX_HEADER_LENGTH 0x2000 #define SOCKET_HTTP_MAX_REDIRECTS 5 -static size_t socket_slurp(RSocket *s, RBuffer *buf) { +static size_t socket_slurp(RzSocket *s, RBuffer *buf) { size_t i; - if (r_socket_ready (s, 1, 0) != 1) { + if (rz_socket_ready (s, 1, 0) != 1) { return 0; } - r_socket_block_time (s, true, 0, 1000); + rz_socket_block_time (s, true, 0, 1000); for (i = 0; i < SOCKET_HTTP_MAX_HEADER_LENGTH; i += 1) { ut8 c; - int olen = r_socket_read_block (s, &c, 1); + int olen = rz_socket_read_block (s, &c, 1); if (olen != 1) { - r_buf_append_bytes (buf, (ut8 *)"", 1); + rz_buf_append_bytes (buf, (ut8 *)"", 1); break; } - r_buf_append_bytes (buf, &c, 1); + rz_buf_append_bytes (buf, &c, 1); } return i; } static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut32 redirections); -static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirections) { - r_return_val_if_fail (s, NULL); +static char *socket_http_answer(RzSocket *s, int *code, int *rlen, ut32 redirections) { + rz_return_val_if_fail (s, NULL); const char *p; int ret, len = 0, delta = 0; char *dn = NULL; - RBuffer *b = r_buf_new (); + RBuffer *b = rz_buf_new (); if (!b) { return NULL; } @@ -45,10 +45,10 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti if (!buf) { goto exit; } - r_buf_read_at (b, 0, (ut8 *)buf, olen); + rz_buf_read_at (b, 0, (ut8 *)buf, olen); buf[olen] = 0; - char *dnn = (char *)r_str_casestr (buf, "\n\n"); - char *drn = (char *)r_str_casestr (buf, "\r\n\r\n"); + char *dnn = (char *)rz_str_casestr (buf, "\n\n"); + char *drn = (char *)rz_str_casestr (buf, "\r\n\r\n"); if (dnn) { if (drn && (drn < dnn)) { dn = drn; @@ -69,7 +69,7 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti *dn = 0; // chop headers /* Follow redirects */ - p = r_str_casestr (buf, "Location:"); + p = rz_str_casestr (buf, "Location:"); if (p) { if (!redirections) { eprintf ("Too many redirects\n"); @@ -79,8 +79,8 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti char *end_url = strchr (p, '\n'); if (end_url) { int url_len = end_url - p; - char *url = r_str_ndup (p, url_len); - r_str_trim (url); + char *url = rz_str_ndup (p, url_len); + rz_str_trim (url); res = socket_http_get_recursive (url, code, rlen, --redirections); free (url); len = *rlen; @@ -89,7 +89,7 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti } /* Parse Len */ - p = r_str_casestr (buf, "Content-Length: "); + p = rz_str_casestr (buf, "Content-Length: "); if (p) { len = atoi (p + 16); } else { @@ -104,7 +104,7 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti olen -= dn - buf; memcpy (res, dn + delta, olen); do { - ret = r_socket_read_block (s, (ut8*) res + olen, len - olen); + ret = rz_socket_read_block (s, (ut8*) res + olen, len - olen); if (ret < 1) { break; } @@ -123,8 +123,8 @@ static char *socket_http_answer(RSocket *s, int *code, int *rlen, ut32 redirecti } exit: free (buf); - r_buf_free (b); - r_socket_close (s); + rz_buf_free (b); + rz_socket_close (s); if (rlen) { *rlen = len; } @@ -133,14 +133,14 @@ exit: #if __WINDOWS__ static char *http_get_w32(const char *url, int *code, int *rlen) { - HINTERNET hInternet = InternetOpenA ("radare2 "R2_VERSION, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); + HINTERNET hInternet = InternetOpenA ("rizin "R2_VERSION, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (!hInternet) { - r_sys_perror ("InternetOpenA"); + rz_sys_perror ("InternetOpenA"); return NULL; } HINTERNET hOpenUrl = InternetOpenUrlA (hInternet, url, NULL, 0, 0, 0); if (!hOpenUrl) { - r_sys_perror ("InternetOpenUrlA"); + rz_sys_perror ("InternetOpenUrlA"); InternetCloseHandle (hInternet); return NULL; } @@ -194,12 +194,12 @@ static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut if (rlen) { *rlen = 0; } - char *curl_env = r_sys_getenv ("R2_CURL"); + char *curl_env = rz_sys_getenv ("R2_CURL"); if (!R_STR_ISEMPTY (curl_env) && atoi (curl_env)) { int len; - char *escaped_url = r_str_escape_sh (url); - char *command = r_str_newf ("curl -sfL -o - \"%s\"", escaped_url); - char *res = r_sys_cmd_str (command, NULL, &len); + char *escaped_url = rz_str_escape_sh (url); + char *command = rz_str_newf ("curl -sfL -o - \"%s\"", escaped_url); + char *res = rz_sys_cmd_str (command, NULL, &len); free (escaped_url); free (command); free (curl_env); @@ -220,8 +220,8 @@ static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut #if __WINDOWS__ return http_get_w32 (url, code, rlen); #else - RSocket *s; - bool ssl = r_str_startswith (url, "https://"); + RzSocket *s; + bool ssl = rz_str_startswith (url, "https://"); #if !HAVE_LIB_SSL if (ssl) { eprintf ("Tried to get '%s', but SSL support is disabled, set R2_CURL=1 to use curl\n", url); @@ -236,7 +236,7 @@ static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut host = strstr (uri, "://"); if (!host) { free (uri); - eprintf ("r_socket_http_get: Invalid URI"); + eprintf ("rz_socket_http_get: Invalid URI"); return NULL; } host += 3; @@ -258,16 +258,16 @@ static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut } else { *path++ = 0; } - s = r_socket_new (ssl); + s = rz_socket_new (ssl); if (!s) { - eprintf ("r_socket_http_get: Cannot create socket\n"); + eprintf ("rz_socket_http_get: Cannot create socket\n"); free (uri); return NULL; } - if (r_socket_connect_tcp (s, host, port, 0)) { - r_socket_printf (s, + if (rz_socket_connect_tcp (s, host, port, 0)) { + rz_socket_printf (s, "GET /%s HTTP/1.1\r\n" - "User-Agent: radare2 "R2_VERSION"\r\n" + "User-Agent: rizin "R2_VERSION"\r\n" "Accept: */*\r\n" "Host: %s:%s\r\n" "\r\n", path, host, port); @@ -277,18 +277,18 @@ static char *socket_http_get_recursive(const char *url, int *code, int *rlen, ut response = NULL; } free (uri); - r_socket_free (s); + rz_socket_free (s); return response; #endif } -R_API char *r_socket_http_get(const char *url, int *code, int *rlen) { +RZ_API char *rz_socket_http_get(const char *url, int *code, int *rlen) { return socket_http_get_recursive (url, code, rlen, SOCKET_HTTP_MAX_REDIRECTS); } -R_API char *r_socket_http_post(const char *url, const char *data, int *code, int *rlen) { - RSocket *s; - bool ssl = r_str_startswith (url, "https://"); +RZ_API char *rz_socket_http_post(const char *url, const char *data, int *code, int *rlen) { + RzSocket *s; + bool ssl = rz_str_startswith (url, "https://"); char *uri = strdup (url); if (!uri) { return NULL; @@ -313,35 +313,35 @@ R_API char *r_socket_http_post(const char *url, const char *data, int *code, int } else { *path++ = 0; } - s = r_socket_new (ssl); + s = rz_socket_new (ssl); if (!s) { printf ("Cannot create socket\n"); free (uri); return NULL; } - if (!r_socket_connect_tcp (s, host, port, 0)) { + if (!rz_socket_connect_tcp (s, host, port, 0)) { eprintf ("Cannot connect to %s:%s\n", host, port); free (uri); return NULL; } /* Send */ - r_socket_printf (s, + rz_socket_printf (s, "POST /%s HTTP/1.0\r\n" - "User-Agent: radare2 "R2_VERSION"\r\n" + "User-Agent: rizin "R2_VERSION"\r\n" "Accept: */*\r\n" "Host: %s\r\n" "Content-Length: %i\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "\r\n", path, host, (int)strlen (data)); free (uri); - r_socket_write (s, (void *)data, strlen (data)); + rz_socket_write (s, (void *)data, strlen (data)); return socket_http_answer (s, code, rlen, 0); } #if TEST void main () { int ret; - char *p = r_socket_http_post ("http://www.radare.org/y/index.php", "a=b", &ret); + char *p = rz_socket_http_post ("http://www.radare.org/y/index.php", "a=b", &ret); printf ("%s\n", p); } #endif diff --git a/libr/socket/socket_http_server.c b/librz/socket/socket_http_server.c similarity index 71% rename from libr/socket/socket_http_server.c rename to librz/socket/socket_http_server.c index 851eb28269..58e8f01c45 100644 --- a/libr/socket/socket_http_server.c +++ b/librz/socket/socket_http_server.c @@ -1,45 +1,45 @@ /* radare - LGPL - Copyright 2012-2016 - pancake */ -#include -#include +#include +#include static bool *breaked = NULL; -R_API void r_socket_http_server_set_breaked(bool *b) { +RZ_API void rz_socket_http_server_set_breaked(bool *b) { breaked = b; } -R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, RSocketHTTPOptions *so) { +RZ_API RzSocketHTTPRequest *rz_socket_http_accept (RzSocket *s, RzSocketHTTPOptions *so) { int content_length = 0, xx, yy; int pxx = 1, first = 0; char buf[1500], *p, *q; - RSocketHTTPRequest *hr = R_NEW0 (RSocketHTTPRequest); + RzSocketHTTPRequest *hr = R_NEW0 (RzSocketHTTPRequest); if (!hr) { return NULL; } if (so->accept_timeout) { - hr->s = r_socket_accept_timeout (s, 1); + hr->s = rz_socket_accept_timeout (s, 1); } else { - hr->s = r_socket_accept (s); + hr->s = rz_socket_accept (s); } if (!hr->s) { free (hr); return NULL; } if (so->timeout > 0) { - r_socket_block_time (hr->s, true, so->timeout, 0); + rz_socket_block_time (hr->s, true, so->timeout, 0); } hr->auth = !so->httpauth; for (;;) { #if __WINDOWS__ if (breaked && *breaked) { - r_socket_http_close (hr); + rz_socket_http_close (hr); return NULL; } #endif memset (buf, 0, sizeof (buf)); - xx = r_socket_gets (hr->s, buf, sizeof (buf)); - yy = r_socket_ready (hr->s, 0, 20 * 1000); //this function uses usecs as argument + xx = rz_socket_gets (hr->s, buf, sizeof (buf)); + yy = rz_socket_ready (hr->s, 0, 20 * 1000); //this function uses usecs as argument // eprintf ("READ %d (%s) READY %d\n", xx, buf, yy); if (!yy || (!xx && !pxx)) { break; @@ -49,7 +49,7 @@ R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, RSocketHTTPOptions * if (first == 0) { first = 1; if (strlen (buf)<3) { - r_socket_http_close (hr); + rz_socket_http_close (hr); return NULL; } p = strchr (buf, ' '); @@ -77,17 +77,17 @@ R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, RSocketHTTPOptions * char *authtoken = buf + 21; size_t authlen = strlen (authtoken); char *curauthtoken; - RListIter *iter; + RzListIter *iter; char *decauthtoken = calloc (4, authlen + 1); if (!decauthtoken) { eprintf ("Could not allocate decoding buffer\n"); return hr; } - if (r_base64_decode ((ut8 *)decauthtoken, authtoken, authlen) == -1) { + if (rz_base64_decode ((ut8 *)decauthtoken, authtoken, authlen) == -1) { eprintf ("Could not decode authorization token\n"); } else { - r_list_foreach (so->authtokens, iter, curauthtoken) { + rz_list_foreach (so->authtokens, iter, curauthtoken) { if (!strcmp (decauthtoken, curauthtoken)) { hr->auth = true; break; @@ -104,21 +104,21 @@ R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, RSocketHTTPOptions * } } if (content_length>0) { - r_socket_read_block (hr->s, (ut8*)buf, 1); // one missing byte wtf + rz_socket_read_block (hr->s, (ut8*)buf, 1); // one missing byte wtf if (ST32_ADD_OVFCHK (content_length, 1)) { - r_socket_http_close (hr); + rz_socket_http_close (hr); eprintf ("Could not allocate hr data\n"); return NULL; } hr->data = malloc (content_length+1); hr->data_length = content_length; - r_socket_read_block (hr->s, hr->data, hr->data_length); + rz_socket_read_block (hr->s, hr->data, hr->data_length); hr->data[content_length] = 0; } return hr; } -R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char *out, int len, const char *headers) { +RZ_API void rz_socket_http_response (RzSocketHTTPRequest *rs, int code, const char *out, int len, const char *headers) { const char *strcode = \ code==200?"ok": code==301?"Moved permanently": @@ -133,15 +133,15 @@ R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char if (!headers) { headers = code == 401 ? "WWW-Authenticate: Basic realm=\"R2 Web UI Access\"\n" : ""; } - r_socket_printf (rs->s, "HTTP/1.0 %d %s\r\n%s" + rz_socket_printf (rs->s, "HTTP/1.0 %d %s\r\n%s" "Connection: close\r\nContent-Length: %d\r\n\r\n", code, strcode, headers, len); if (out && len > 0) { - r_socket_write (rs->s, (void *)out, len); + rz_socket_write (rs->s, (void *)out, len); } } -R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) { +RZ_API ut8 *rz_socket_http_handle_upload(const ut8 *str, int len, int *retlen) { if (retlen) { *retlen = 0; } @@ -188,8 +188,8 @@ R_API ut8 *r_socket_http_handle_upload(const ut8 *str, int len, int *retlen) { } /* close client socket and free struct */ -R_API void r_socket_http_close (RSocketHTTPRequest *rs) { - r_socket_free (rs->s); +RZ_API void rz_socket_http_close (RzSocketHTTPRequest *rs) { + rz_socket_free (rs->s); free (rs->path); free (rs->host); free (rs->agent); @@ -200,33 +200,33 @@ R_API void r_socket_http_close (RSocketHTTPRequest *rs) { #if MAIN int main() { - RSocket *s = r_socket_new (false); - if (!r_socket_listen (s, "8080", NULL)) { + RzSocket *s = rz_socket_new (false); + if (!rz_socket_listen (s, "8080", NULL)) { eprintf ("Cannot listen here\n"); return 1; } for (;;) { - RSocketHTTPRequest *rs = r_socket_http_accept (s, 0); + RzSocketHTTPRequest *rs = rz_socket_http_accept (s, 0); if (!rs) continue; if (!strcmp (rs->method, "GET")) { - r_socket_http_response (rs, 200, + rz_socket_http_response (rs, 200, "
" "
"); } else if (!strcmp (rs->method, "POST")) { char *buf = malloc (rs->data_length+ 50); strcpy (buf, "

XSS test

\n"); - r_str_unescape (rs->data); + rz_str_unescape (rs->data); strcat (buf, rs->data); - r_socket_http_response (rs, 200, buf); + rz_socket_http_response (rs, 200, buf); free (buf); } else if (!strcmp (rs->method, "OPTIONS")) { - r_socket_http_response (rs, 200,""); + rz_socket_http_response (rs, 200,""); } else { - r_socket_http_response (rs, 404, "Invalid protocol"); + rz_socket_http_response (rs, 404, "Invalid protocol"); } - r_socket_http_close (rs); + rz_socket_http_close (rs); } } #endif diff --git a/libr/socket/socket_proc.c b/librz/socket/socket_proc.c similarity index 61% rename from libr/socket/socket_proc.c rename to librz/socket/socket_proc.c index 1f0561b8fc..49a78f4e45 100644 --- a/libr/socket/socket_proc.c +++ b/librz/socket/socket_proc.c @@ -1,10 +1,10 @@ /* radare - LGPL - Copyright 2007-2012 - pancake */ -/* XXX : move to r_util??? rename method names.. to long? */ +/* XXX : move to rz_util??? rename method names.. to long? */ /* proc IO is not related to socket io.. this is shitty!! */ -#include -#include +#include +#include #include #if __UNIX__ @@ -13,9 +13,9 @@ #define BUFFER_SIZE 4096 -R_API struct r_socket_proc_t *r_socket_proc_open(char* const argv[]) { +RZ_API struct rz_socket_proc_t *rz_socket_proc_open(char* const argv[]) { #if __UNIX__ && LIBC_HAVE_FORK - RSocketProc *sp = R_NEW (RSocketProc); + RzSocketProc *sp = R_NEW (RzSocketProc); #ifdef O_CLOEXEC const int flags = O_CLOEXEC; //O_NONBLOCK|O_CLOEXEC; #else @@ -48,7 +48,7 @@ R_API struct r_socket_proc_t *r_socket_proc_open(char* const argv[]) { goto error; } - sp->pid = r_sys_fork (); + sp->pid = rz_sys_fork (); switch (sp->pid) { case 0: close (0); @@ -60,9 +60,9 @@ R_API struct r_socket_proc_t *r_socket_proc_open(char* const argv[]) { break; case -1: perror ("fork"); - r_socket_proc_close (sp); + rz_socket_proc_close (sp); goto error; - //r_socket_block_time (sp, false, 0); + //rz_socket_block_time (sp, false, 0); } return sp; error: @@ -73,7 +73,7 @@ error: #endif } -R_API int r_socket_proc_close(struct r_socket_proc_t *sp) { +RZ_API int rz_socket_proc_close(struct rz_socket_proc_t *sp) { #if __UNIX__ /* this is wrong */ kill (sp->pid, SIGKILL); @@ -88,29 +88,29 @@ R_API int r_socket_proc_close(struct r_socket_proc_t *sp) { return 0; } -R_API int r_socket_proc_read (RSocketProc *sp, unsigned char *buf, int len) { - RSocket s; +RZ_API int rz_socket_proc_read (RzSocketProc *sp, unsigned char *buf, int len) { + RzSocket s; s.is_ssl = false; s.fd = sp->fd1[0]; - return r_socket_read (&s, buf, len); + return rz_socket_read (&s, buf, len); } -R_API int r_socket_proc_gets (RSocketProc *sp, char *buf, int size) { - RSocket s; +RZ_API int rz_socket_proc_gets (RzSocketProc *sp, char *buf, int size) { + RzSocket s; s.is_ssl = false; s.fd = sp->fd1[0]; - return r_socket_gets (&s, buf, size); + return rz_socket_gets (&s, buf, size); } -R_API int r_socket_proc_write (RSocketProc *sp, void *buf, int len) { - RSocket s; +RZ_API int rz_socket_proc_write (RzSocketProc *sp, void *buf, int len) { + RzSocket s; s.is_ssl = false; s.fd = sp->fd0[1]; - return r_socket_write (&s, buf, len); + return rz_socket_write (&s, buf, len); } -R_API void r_socket_proc_printf (RSocketProc *sp, const char *fmt, ...) { - RSocket s; +RZ_API void rz_socket_proc_printf (RzSocketProc *sp, const char *fmt, ...) { + RzSocket s; char buf[BUFFER_SIZE]; va_list ap; s.is_ssl = false; @@ -118,14 +118,14 @@ R_API void r_socket_proc_printf (RSocketProc *sp, const char *fmt, ...) { if (s.fd != R_INVALID_SOCKET) { va_start (ap, fmt); vsnprintf (buf, BUFFER_SIZE, fmt, ap); - r_socket_write (&s, buf, strlen(buf)); + rz_socket_write (&s, buf, strlen(buf)); va_end (ap); } } -R_API int r_socket_proc_ready (RSocketProc *sp, int secs, int usecs) { - RSocket s; +RZ_API int rz_socket_proc_ready (RzSocketProc *sp, int secs, int usecs) { + RzSocket s; s.is_ssl = false; s.fd = sp->fd1[0]; - return r_socket_ready (&s, secs, usecs); + return rz_socket_ready (&s, secs, usecs); } diff --git a/libr/socket/socket_rap_client.c b/librz/socket/socket_rap_client.c similarity index 60% rename from libr/socket/socket_rap_client.c rename to librz/socket/socket_rap_client.c index f882fee5c5..e905d88806 100644 --- a/libr/socket/socket_rap_client.c +++ b/librz/socket/socket_rap_client.c @@ -1,26 +1,26 @@ /* radare - LGPL - Copyright 2011-2020 - pancake */ -#include -#include +#include +#include -static ut8 *r_rap_packet(ut8 type, ut32 len) { +static ut8 *rz_rap_packet(ut8 type, ut32 len) { ut8 *buf = malloc (len + 5); if (buf) { buf[0] = type; - r_write_be32 (buf + 1, len); + rz_write_be32 (buf + 1, len); } return buf; } -static void r_rap_packet_fill(ut8 *buf, const ut8* src, int len) { +static void rz_rap_packet_fill(ut8 *buf, const ut8* src, int len) { if (buf && src && len > 0) { - ut32 curlen = r_read_be32 (buf + 1); + ut32 curlen = rz_read_be32 (buf + 1); memcpy (buf + 5, src, R_MIN (curlen, len)); } } -R_API int r_socket_rap_client_open(RSocket *s, const char *file, int rw) { - r_socket_block_time (s, true, 1, 0); +RZ_API int rz_socket_rap_client_open(RzSocket *s, const char *file, int rw) { + rz_socket_block_time (s, true, 1, 0); size_t file_len0 = strlen (file) + 1; if (file_len0 > 255) { eprintf ("Filename too long\n"); @@ -35,15 +35,15 @@ R_API int r_socket_rap_client_open(RSocket *s, const char *file, int rw) { buf[1] = rw; buf[2] = (ut8)(file_len0 & 0xff); memcpy (buf + 3, file, file_len0); - (void)r_socket_write (s, buf, 3 + file_len0); - r_socket_flush (s); + (void)rz_socket_write (s, buf, 3 + file_len0); + rz_socket_flush (s); // << int fd = -1; memset (buf, 0, 5); - int r = r_socket_read_block (s, (ut8*)buf, 5); + int r = rz_socket_read_block (s, (ut8*)buf, 5); if (r == 5) { if (buf[0] == (char)(RAP_PACKET_OPEN | RAP_PACKET_REPLY)) { - fd = r_read_at_be32 (buf + 1, 1); + fd = rz_read_at_be32 (buf + 1, 1); } else { eprintf ("RapClientOpen: Bad packet 0x%02x\n", buf[0]); } @@ -54,7 +54,7 @@ R_API int r_socket_rap_client_open(RSocket *s, const char *file, int rw) { return fd; } -R_API char *r_socket_rap_client_command(RSocket *s, const char *cmd, RCoreBind *c) { +RZ_API char *rz_socket_rap_client_command(RzSocket *s, const char *cmd, RzCoreBind *c) { char *buf = malloc (strlen (cmd) + 8); if (!buf) { return NULL; @@ -62,27 +62,27 @@ R_API char *r_socket_rap_client_command(RSocket *s, const char *cmd, RCoreBind * /* send request */ buf[0] = RAP_PACKET_CMD; size_t i = strlen (cmd) + 1; - r_write_be32 (buf + 1, i); + rz_write_be32 (buf + 1, i); memcpy (buf + 5, cmd, i); - r_socket_write (s, buf, 5 + i); - r_socket_flush (s); + rz_socket_write (s, buf, 5 + i); + rz_socket_flush (s); free (buf); /* read response */ char bufr[8]; - r_socket_read_block (s, (ut8*)bufr, 5); + rz_socket_read_block (s, (ut8*)bufr, 5); while (bufr[0] == (char)(RAP_PACKET_CMD)) { - size_t cmd_len = r_read_at_be32 (bufr, 1); + size_t cmd_len = rz_read_at_be32 (bufr, 1); char *rcmd = calloc (1, cmd_len + 1); if (rcmd) { - r_socket_read_block (s, (ut8*)rcmd, cmd_len); - // char *res = r_core_cmd_str (core, rcmd); + rz_socket_read_block (s, (ut8*)rcmd, cmd_len); + // char *res = rz_core_cmd_str (core, rcmd); char *res = c->cmdstr (c->core, rcmd); if (res) { int res_len = strlen (res) + 1; - ut8 *pkt = r_rap_packet ((RAP_PACKET_CMD | RAP_PACKET_REPLY), res_len); - r_rap_packet_fill (pkt, (const ut8*)res, res_len); - r_socket_write (s, pkt, 5 + res_len); - r_socket_flush (s); + ut8 *pkt = rz_rap_packet ((RAP_PACKET_CMD | RAP_PACKET_REPLY), res_len); + rz_rap_packet_fill (pkt, (const ut8*)res, res_len); + rz_socket_write (s, pkt, 5 + res_len); + rz_socket_flush (s); free (res); free (pkt); } @@ -90,13 +90,13 @@ R_API char *r_socket_rap_client_command(RSocket *s, const char *cmd, RCoreBind * } /* read response */ bufr[0] = -1; - (void) r_socket_read_block (s, (ut8*)bufr, 5); + (void) rz_socket_read_block (s, (ut8*)bufr, 5); } if (bufr[0] != (char)(RAP_PACKET_CMD | RAP_PACKET_REPLY)) { eprintf ("Error: Wrong reply for command 0x%02x\n", bufr[0]); return NULL; } - size_t cmd_len = r_read_at_be32 (bufr, 1); + size_t cmd_len = rz_read_at_be32 (bufr, 1); if (cmd_len < 1 || cmd_len > 16384) { eprintf ("Error: cmd_len is wrong\n"); return NULL; @@ -106,13 +106,13 @@ R_API char *r_socket_rap_client_command(RSocket *s, const char *cmd, RCoreBind * eprintf ("Error: Allocating cmd output\n"); return NULL; } - r_socket_read_block (s, (ut8*)cmd_output, cmd_len); + rz_socket_read_block (s, (ut8*)cmd_output, cmd_len); //ensure the termination cmd_output[cmd_len] = 0; return cmd_output; } -R_API int r_socket_rap_client_write(RSocket *s, const ut8 *buf, int count) { +RZ_API int rz_socket_rap_client_write(RzSocket *s, const ut8 *buf, int count) { ut8 *tmp; int ret; if (count < 1) { @@ -127,16 +127,16 @@ R_API int r_socket_rap_client_write(RSocket *s, const ut8 *buf, int count) { return -1; } tmp[0] = RAP_PACKET_WRITE; - r_write_be32 (tmp + 1, count); + rz_write_be32 (tmp + 1, count); memcpy (tmp + 5, buf, count); - (void)r_socket_write (s, tmp, count + 5); - r_socket_flush (s); - if (r_socket_read_block (s, tmp, 5) != 5) { // TODO read_block? + (void)rz_socket_write (s, tmp, count + 5); + rz_socket_flush (s); + if (rz_socket_read_block (s, tmp, 5) != 5) { // TODO read_block? eprintf ("__rap_write: error\n"); ret = -1; } else { - ret = r_read_be32 (tmp + 1); + ret = rz_read_be32 (tmp + 1); if (!ret) { ret = -1; } @@ -145,46 +145,46 @@ R_API int r_socket_rap_client_write(RSocket *s, const ut8 *buf, int count) { return ret; } -R_API int r_socket_rap_client_read(RSocket *s, ut8 *buf, int count) { +RZ_API int rz_socket_rap_client_read(RzSocket *s, ut8 *buf, int count) { ut8 tmp[32]; if (count < 1) { return count; } - r_socket_block_time (s, 1, 1, 0); + rz_socket_block_time (s, 1, 1, 0); // XXX. if count is > RAP_PACKET_MAX, just perform multiple queries if (count > RAP_PACKET_MAX) { count = RAP_PACKET_MAX; } // send tmp[0] = RAP_PACKET_READ; - r_write_be32 (tmp + 1, count); - (void)r_socket_write (s, tmp, 5); - r_socket_flush (s); + rz_write_be32 (tmp + 1, count); + (void)rz_socket_write (s, tmp, 5); + rz_socket_flush (s); // recv - int ret = r_socket_read_block (s, tmp, 5); + int ret = rz_socket_read_block (s, tmp, 5); if (ret != 5 || tmp[0] != (RAP_PACKET_READ | RAP_PACKET_REPLY)) { eprintf ("__rap_read: Unexpected rap read reply " "(%d=0x%02x) expected (%d=0x%02x)\n", ret, tmp[0], 2, (RAP_PACKET_READ | RAP_PACKET_REPLY)); return -1; } - int i = r_read_at_be32 (tmp, 1); + int i = rz_read_at_be32 (tmp, 1); if (i > count) { eprintf ("__rap_read: Unexpected data size %d vs %d\n", i, count); return -1; } - r_socket_read_block (s, buf, i); + rz_socket_read_block (s, buf, i); return count; } -R_API int r_socket_rap_client_seek(RSocket *s, ut64 offset, int whence) { +RZ_API int rz_socket_rap_client_seek(RzSocket *s, ut64 offset, int whence) { ut8 tmp[10]; tmp[0] = RAP_PACKET_SEEK; tmp[1] = (ut8)whence; - r_write_be64 (tmp + 2, offset); - (void)r_socket_write (s, &tmp, 10); - r_socket_flush (s); - int ret = r_socket_read_block (s, (ut8*)&tmp, 9); + rz_write_be64 (tmp + 2, offset); + (void)rz_socket_write (s, &tmp, 10); + rz_socket_flush (s); + int ret = rz_socket_read_block (s, (ut8*)&tmp, 9); if (ret != 9) { eprintf ("Truncated socket read\n"); return -1; @@ -195,5 +195,5 @@ R_API int r_socket_rap_client_seek(RSocket *s, ut64 offset, int whence) { eprintf ("Unexpected seek reply (%02x -> %02x)\n", tmp[0], (RAP_PACKET_SEEK | RAP_PACKET_REPLY)); return -1; } - return r_read_at_be64 (tmp, 1); + return rz_read_at_be64 (tmp, 1); } diff --git a/librz/socket/socket_rap_server.c b/librz/socket/socket_rap_server.c new file mode 100644 index 0000000000..b4aee16248 --- /dev/null +++ b/librz/socket/socket_rap_server.c @@ -0,0 +1,140 @@ +/* radare - LGPL - Copyright 2014-2019 - pancake, condret */ + +#include +#include + +RZ_API RzSocketRapServer *rz_socket_rap_server_new(bool use_ssl, const char *port) { + rz_return_val_if_fail (port, NULL); + RzSocketRapServer *s = R_NEW0 (RzSocketRapServer); + if (s) { + s->port = strdup (port); + s->fd = rz_socket_new (use_ssl); + if (s->fd) { + return s; + } + rz_socket_free (s->fd); + free (s); + } + return NULL; +} + +RZ_API RzSocketRapServer *rz_socket_rap_server_create(const char *pathname) { + rz_return_val_if_fail (pathname, NULL); + if (strlen (pathname) < 11) { + return NULL; + } + if (strncmp (pathname, "rap", 3)) { + return NULL; + } + bool is_ssl = (pathname[3] == 's'); + const char *port = &pathname[7 + is_ssl]; + return rz_socket_rap_server_new (is_ssl, port); +} + +RZ_API void rz_socket_rap_server_free(RzSocketRapServer *s) { + if (s) { + rz_socket_free (s->fd); + free (s); + } +} + +RZ_API bool rz_socket_rap_server_listen(RzSocketRapServer *s, const char *certfile) { + rz_return_val_if_fail (s && s->port && *s->port, false); + return rz_socket_listen (s->fd, s->port, certfile); +} + +RZ_API RzSocket* rz_socket_rap_server_accept(RzSocketRapServer *s) { + rz_return_val_if_fail (s && s->fd, NULL); + return rz_socket_accept (s->fd); +} + +RZ_API bool rz_socket_rap_server_continue(RzSocketRapServer *s) { + rz_return_val_if_fail (s && s->fd, false); + + int i; + char *ptr = NULL; + + if (!rz_socket_is_connected (s->fd)) { + return false; + } + rz_socket_read_block (s->fd, s->buf, 1); + switch (s->buf[0]) { + case RAP_PACKET_OPEN: + rz_socket_read_block (s->fd, &s->buf[1], 2); + rz_socket_read_block (s->fd, &s->buf[3], (int)s->buf[2]); + { + int fd = s->open (s->user, (const char *)&s->buf[3], (int)s->buf[1], 0); + s->buf[0] = RAP_PACKET_OPEN | RAP_PACKET_REPLY; + eprintf ("REPLY BACK %d\n", fd); + rz_write_be32 (s->buf + 1, fd); + } + rz_socket_write (s->fd, s->buf, 5); + rz_socket_flush (s->fd); + break; + case RAP_PACKET_READ: + rz_socket_read_block (s->fd, &s->buf[1], 4); + i = rz_read_be32 (&s->buf[1]); + if (i > RAP_PACKET_MAX || i < 0) { + i = RAP_PACKET_MAX; + } + s->read (s->user, &s->buf[5], i); + s->buf[0] = RAP_PACKET_READ | RAP_PACKET_REPLY; + rz_socket_write (s->fd, s->buf, i + 5); + rz_socket_flush (s->fd); + break; + case RAP_PACKET_WRITE: + rz_socket_read_block (s->fd, s->buf + 1, 4); + i = rz_read_be32 (s->buf + 1); + if (i > RAP_PACKET_MAX || i < 0) { + i = RAP_PACKET_MAX; + } + rz_socket_read_block (s->fd, s->buf + 5, i); + rz_write_be32 (s->buf + 1, s->write (s->user, s->buf + 5, i)); + s->buf[0] = RAP_PACKET_WRITE | RAP_PACKET_REPLY; + rz_socket_write (s->fd, s->buf, 5); + rz_socket_flush (s->fd); + break; + case RAP_PACKET_SEEK: + { + rz_socket_read_block (s->fd, &s->buf[1], 9); + int whence = s->buf[0]; + ut64 offset = rz_read_be64 (s->buf + 1); + offset = s->seek (s->user, offset, whence); + /* prepare reply */ + s->buf[0] = RAP_PACKET_SEEK | RAP_PACKET_REPLY; + rz_write_be64 (s->buf + 1, offset); + rz_socket_write (s->fd, s->buf, 9); + rz_socket_flush (s->fd); + } + break; + case RAP_PACKET_CMD: + rz_socket_read_block (s->fd, &s->buf[1], 4); + i = rz_read_be32 (&s->buf[1]); + if (rz_socket_read_block (s->fd, &s->buf[5], i) > 0) { + ptr = s->cmd (s->user, (const char *)s->buf + 5); + i = (ptr)? strlen (ptr) + 1: 0; + rz_write_be32 (&s->buf[1], i); + s->buf[0] = RAP_PACKET_CMD | RAP_PACKET_REPLY; + rz_socket_write (s->fd, s->buf, 5); + if (i) { + rz_socket_write (s->fd, ptr, i); + } + rz_socket_flush (s->fd); + R_FREE (ptr); + } + break; + case RAP_PACKET_CLOSE: + rz_socket_read_block (s->fd, &s->buf[1], 4); + i = rz_read_be32 (&s->buf[1]); + s->close (s->user, i); + s->buf[0] = RAP_PACKET_CLOSE | RAP_PACKET_REPLY; + rz_socket_write (s->fd, s->buf, 5); + rz_socket_flush (s->fd); + break; + default: + eprintf ("unknown command 0x%02x\n", (ut8)(s->buf[0] & 0xff)); + rz_socket_close (s->fd); + return false; + } + return true; +} diff --git a/libr/socket/socket_serial.c b/librz/socket/socket_serial.c similarity index 87% rename from libr/socket/socket_serial.c rename to librz/socket/socket_serial.c index c5934b4c7a..a6d7a6a02e 100644 --- a/libr/socket/socket_serial.c +++ b/librz/socket/socket_serial.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2017 - pancake */ -#include +#include #if __UNIX__ #include @@ -44,7 +44,7 @@ static int set_interface_attribs (int fd, int speed, int parity) { return 0; } -R_API int r_socket_connect_serial(RSocket *sock, const char *path, int speed, int parity) { +RZ_API int rz_socket_connect_serial(RzSocket *sock, const char *path, int speed, int parity) { int fd = open (path, O_RDWR | O_SYNC | O_BINARY, 0); // O_NOCTY if (fd == -1) { return -1; @@ -59,7 +59,7 @@ R_API int r_socket_connect_serial(RSocket *sock, const char *path, int speed, in #else // __UNIX__ -R_API int r_socket_connect_serial(RSocket *sock, const char *path, int speed, int parity) { +RZ_API int rz_socket_connect_serial(RzSocket *sock, const char *path, int speed, int parity) { return -1; } #endif diff --git a/libr/stripsyms.sh b/librz/stripsyms.sh similarity index 89% rename from libr/stripsyms.sh rename to librz/stripsyms.sh index e2aa719452..ddac9b1d1a 100644 --- a/libr/stripsyms.sh +++ b/librz/stripsyms.sh @@ -11,7 +11,7 @@ PFX=$2 LIST=$1.list if [ "${PFX}" = "r_util" ]; then - echo "=> No stripping any symbol in libr_util O:)" + echo "=> No stripping any symbol in librz_util O:)" exit 0 PFX="r_" fi diff --git a/libr/symgraph.pl b/librz/symgraph.pl similarity index 56% rename from libr/symgraph.pl rename to librz/symgraph.pl index a881ba68d3..c365f4189f 100644 --- a/libr/symgraph.pl +++ b/librz/symgraph.pl @@ -10,20 +10,20 @@ else fi dolib() { - rabin2 -i $1/libr_$1.${SO} | grep -v mports | cut -d = -f 6 > $t/l/$1.i - rabin2 -s $1/libr_$1.${SO} | grep -v xports | cut -d = -f 6 > $t/l/$1.s + rz_bin -i $1/libr_$1.${SO} | grep -v mports | cut -d = -f 6 > $t/l/$1.i + rz_bin -s $1/libr_$1.${SO} | grep -v xports | cut -d = -f 6 > $t/l/$1.s } dobin() { - rabin2 -i ../binr/$1/$1 | grep -v mports | cut -d = -f 9 > $t/b/$1.i -# rabin2 -s ../binr/$1/$1 | cut -d = -f 8 > $t/b/$1.s + rz_bin -i ../binrz/$1/$1 | grep -v mports | cut -d = -f 9 > $t/b/$1.i +# rz_bin -s ../binrz/$1/$1 | cut -d = -f 8 > $t/b/$1.s } LIBS="anal asm bin bp config cons crypto debug diff flags hash io lang parse reg search socket syscall util core" for a in $LIBS ; do dolib ${a} done -BINS="rabin2 rasm2 radare2 rax2 ranal2 rahash2 radiff2 rafind2 r2agent" +BINS="rz_bin rz_asm rizin rz_ax ranal2 rz_hash rz_diff rz_find rz_agent" for a in $BINS ; do dobin ${a} done diff --git a/libr/syscall/Makefile b/librz/syscall/Makefile similarity index 86% rename from libr/syscall/Makefile rename to librz/syscall/Makefile index edc3f06969..3fe037b5c1 100644 --- a/libr/syscall/Makefile +++ b/librz/syscall/Makefile @@ -1,7 +1,7 @@ include ../config.mk -NAME=r_syscall -R2DEPS=r_util +NAME=rz_syscall +R2DEPS=rz_util OBJS=syscall.o ioports.o CFLAGS+=-D__UNIX__ -Wall diff --git a/libr/syscall/d/Makefile b/librz/syscall/d/Makefile similarity index 96% rename from libr/syscall/d/Makefile rename to librz/syscall/d/Makefile index 00c5833b23..31ad61c03f 100644 --- a/libr/syscall/d/Makefile +++ b/librz/syscall/d/Makefile @@ -67,7 +67,7 @@ ${SDB}: .PHONY: all clean install install-symlink symstall -SYSCALLPATH=${DESTDIR}${DATADIR}/radare2/${VERSION}/syscall +SYSCALLPATH=${DESTDIR}${DATADIR}/rizin/${VERSION}/syscall install: ${F_SDB} -rm -rf "${SYSCALLPATH}" diff --git a/libr/syscall/d/darwin-arm-32.sdb.txt b/librz/syscall/d/darwin-arm-32.sdb.txt similarity index 100% rename from libr/syscall/d/darwin-arm-32.sdb.txt rename to librz/syscall/d/darwin-arm-32.sdb.txt diff --git a/libr/syscall/d/darwin-arm-64.sdb.txt b/librz/syscall/d/darwin-arm-64.sdb.txt similarity index 100% rename from libr/syscall/d/darwin-arm-64.sdb.txt rename to librz/syscall/d/darwin-arm-64.sdb.txt diff --git a/libr/syscall/d/darwin-x86-32.sdb.txt b/librz/syscall/d/darwin-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/darwin-x86-32.sdb.txt rename to librz/syscall/d/darwin-x86-32.sdb.txt diff --git a/libr/syscall/d/darwin-x86-64.sdb.txt b/librz/syscall/d/darwin-x86-64.sdb.txt similarity index 100% rename from libr/syscall/d/darwin-x86-64.sdb.txt rename to librz/syscall/d/darwin-x86-64.sdb.txt diff --git a/libr/syscall/d/dos-x86-16.sdb.txt b/librz/syscall/d/dos-x86-16.sdb.txt similarity index 100% rename from libr/syscall/d/dos-x86-16.sdb.txt rename to librz/syscall/d/dos-x86-16.sdb.txt diff --git a/libr/syscall/d/freebsd-x86-32.sdb.txt b/librz/syscall/d/freebsd-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/freebsd-x86-32.sdb.txt rename to librz/syscall/d/freebsd-x86-32.sdb.txt diff --git a/libr/syscall/d/gen.sh b/librz/syscall/d/gen.sh similarity index 100% rename from libr/syscall/d/gen.sh rename to librz/syscall/d/gen.sh diff --git a/libr/syscall/d/ios-arm-32.sdb.txt b/librz/syscall/d/ios-arm-32.sdb.txt similarity index 100% rename from libr/syscall/d/ios-arm-32.sdb.txt rename to librz/syscall/d/ios-arm-32.sdb.txt diff --git a/libr/syscall/d/ios-arm-64.sdb.txt b/librz/syscall/d/ios-arm-64.sdb.txt similarity index 100% rename from libr/syscall/d/ios-arm-64.sdb.txt rename to librz/syscall/d/ios-arm-64.sdb.txt diff --git a/libr/syscall/d/ios-x86-32.sdb.txt b/librz/syscall/d/ios-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/ios-x86-32.sdb.txt rename to librz/syscall/d/ios-x86-32.sdb.txt diff --git a/libr/syscall/d/linux-arm-32.sdb.txt b/librz/syscall/d/linux-arm-32.sdb.txt similarity index 100% rename from libr/syscall/d/linux-arm-32.sdb.txt rename to librz/syscall/d/linux-arm-32.sdb.txt diff --git a/libr/syscall/d/linux-arm-64.sdb.txt b/librz/syscall/d/linux-arm-64.sdb.txt similarity index 100% rename from libr/syscall/d/linux-arm-64.sdb.txt rename to librz/syscall/d/linux-arm-64.sdb.txt diff --git a/libr/syscall/d/linux-mips-32.sdb.txt b/librz/syscall/d/linux-mips-32.sdb.txt similarity index 100% rename from libr/syscall/d/linux-mips-32.sdb.txt rename to librz/syscall/d/linux-mips-32.sdb.txt diff --git a/libr/syscall/d/linux-sparc-32.sdb.txt b/librz/syscall/d/linux-sparc-32.sdb.txt similarity index 100% rename from libr/syscall/d/linux-sparc-32.sdb.txt rename to librz/syscall/d/linux-sparc-32.sdb.txt diff --git a/libr/syscall/d/linux-x86-32.sdb.txt b/librz/syscall/d/linux-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/linux-x86-32.sdb.txt rename to librz/syscall/d/linux-x86-32.sdb.txt diff --git a/libr/syscall/d/linux-x86-64.sdb.txt b/librz/syscall/d/linux-x86-64.sdb.txt similarity index 100% rename from libr/syscall/d/linux-x86-64.sdb.txt rename to librz/syscall/d/linux-x86-64.sdb.txt diff --git a/libr/syscall/d/meson.build b/librz/syscall/d/meson.build similarity index 100% rename from libr/syscall/d/meson.build rename to librz/syscall/d/meson.build diff --git a/libr/syscall/d/netbsd-x86-32.sdb.txt b/librz/syscall/d/netbsd-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/netbsd-x86-32.sdb.txt rename to librz/syscall/d/netbsd-x86-32.sdb.txt diff --git a/libr/syscall/d/openbsd-x86-32.sdb.txt b/librz/syscall/d/openbsd-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/openbsd-x86-32.sdb.txt rename to librz/syscall/d/openbsd-x86-32.sdb.txt diff --git a/libr/syscall/d/openbsd-x86-64.sdb.txt b/librz/syscall/d/openbsd-x86-64.sdb.txt similarity index 100% rename from libr/syscall/d/openbsd-x86-64.sdb.txt rename to librz/syscall/d/openbsd-x86-64.sdb.txt diff --git a/libr/syscall/d/par.sh b/librz/syscall/d/par.sh similarity index 100% rename from libr/syscall/d/par.sh rename to librz/syscall/d/par.sh diff --git a/libr/syscall/d/s110-arm-16.sdb.txt b/librz/syscall/d/s110-arm-16.sdb.txt similarity index 100% rename from libr/syscall/d/s110-arm-16.sdb.txt rename to librz/syscall/d/s110-arm-16.sdb.txt diff --git a/libr/syscall/d/windows-x86-32.sdb.txt b/librz/syscall/d/windows-x86-32.sdb.txt similarity index 100% rename from libr/syscall/d/windows-x86-32.sdb.txt rename to librz/syscall/d/windows-x86-32.sdb.txt diff --git a/libr/syscall/d/windows-x86-64.sdb.txt b/librz/syscall/d/windows-x86-64.sdb.txt similarity index 100% rename from libr/syscall/d/windows-x86-64.sdb.txt rename to librz/syscall/d/windows-x86-64.sdb.txt diff --git a/libr/syscall/d2/avr-atmega16.sdb.txt b/librz/syscall/d2/avr-atmega16.sdb.txt similarity index 100% rename from libr/syscall/d2/avr-atmega16.sdb.txt rename to librz/syscall/d2/avr-atmega16.sdb.txt diff --git a/libr/syscall/d2/gen.sh b/librz/syscall/d2/gen.sh similarity index 100% rename from libr/syscall/d2/gen.sh rename to librz/syscall/d2/gen.sh diff --git a/libr/syscall/d2/x86-16.txt b/librz/syscall/d2/x86-16.txt similarity index 100% rename from libr/syscall/d2/x86-16.txt rename to librz/syscall/d2/x86-16.txt diff --git a/libr/syscall/example.syscall-file b/librz/syscall/example.syscall-file similarity index 100% rename from libr/syscall/example.syscall-file rename to librz/syscall/example.syscall-file diff --git a/libr/syscall/ioports.c b/librz/syscall/ioports.c similarity index 97% rename from libr/syscall/ioports.c rename to librz/syscall/ioports.c index ece9c99e6f..a9be587518 100644 --- a/libr/syscall/ioports.c +++ b/librz/syscall/ioports.c @@ -1,6 +1,6 @@ -#include "r_syscall.h" +#include "rz_syscall.h" -RSyscallPort sysport_x86[] = { +RzSyscallPort sysport_x86[] = { { 0x3, "HELLO WORLD" }, { 0x378, "lp1" }, { 0, NULL } @@ -8,7 +8,7 @@ RSyscallPort sysport_x86[] = { // XXX: This is for Atmega8A, check other datasheets Register Summary to be sure about your MCU: // http://www.atmel.com/Images/Atmel-2486-8-bit-AVR-microcontroller-ATmega8_L_datasheet.pdf -RSyscallPort sysport_avr[] = { +RzSyscallPort sysport_avr[] = { { 0x3f, "SREG: flags" }, { 0x3e, "SPH: Stack higher bits SP8-SP10" }, { 0x3d, "SPL: Stack lower bits SP0-SP7"}, diff --git a/libr/syscall/meson.build b/librz/syscall/meson.build similarity index 61% rename from libr/syscall/meson.build rename to librz/syscall/meson.build index a8a29c7856..1d22fce6ad 100644 --- a/libr/syscall/meson.build +++ b/librz/syscall/meson.build @@ -1,13 +1,13 @@ -r_syscall_sources = [ +rz_syscall_sources = [ 'syscall.c', 'ioports.c' ] -r_syscall = library('r_syscall', r_syscall_sources, +rz_syscall = library('rz_syscall', rz_syscall_sources, include_directories: [platform_inc], c_args: library_cflags, dependencies: [ - r_util_dep + rz_util_dep ], install: true, implicit_include_directories: false, @@ -15,17 +15,17 @@ r_syscall = library('r_syscall', r_syscall_sources, soversion: r2_libversion ) -r_syscall_dep = declare_dependency(link_with: r_syscall, +rz_syscall_dep = declare_dependency(link_with: rz_syscall, include_directories: [platform_inc]) -pkgconfig_mod.generate(r_syscall, - subdirs: 'libr', +pkgconfig_mod.generate(rz_syscall, + subdirs: 'librz', version: r2_version, - name: 'r_syscall', - filebase: 'r_syscall', + name: 'rz_syscall', + filebase: 'rz_syscall', libraries: pkgcfg_sanitize_libs, requires: [ - 'r_util' + 'rz_util' ], description: 'radare foundation libraries' ) diff --git a/libr/syscall/syscall.c b/librz/syscall/syscall.c similarity index 61% rename from libr/syscall/syscall.c rename to librz/syscall/syscall.c index aa76c237d4..561920bd67 100644 --- a/libr/syscall/syscall.c +++ b/librz/syscall/syscall.c @@ -1,24 +1,24 @@ /* radare - Copyright 2008-2020 - LGPL -- pancake */ -#include -#include -#include +#include +#include +#include #include #include -R_LIB_VERSION (r_syscall); +R_LIB_VERSION (rz_syscall); // TODO: now we use sdb -extern RSyscallPort sysport_x86[]; -extern RSyscallPort sysport_avr[]; +extern RzSyscallPort sysport_x86[]; +extern RzSyscallPort sysport_avr[]; -R_API RSyscall* r_syscall_ref(RSyscall *sc) { +RZ_API RzSyscall* rz_syscall_ref(RzSyscall *sc) { sc->refs++; return sc; } -R_API RSyscall* r_syscall_new(void) { - RSyscall *rs = R_NEW0 (RSyscall); +RZ_API RzSyscall* rz_syscall_new(void) { + RzSyscall *rs = R_NEW0 (RzSyscall); if (rs) { rs->sysport = sysport_x86; rs->srdb = sdb_new0 (); // sysregs database @@ -27,7 +27,7 @@ R_API RSyscall* r_syscall_new(void) { return rs; } -R_API void r_syscall_free(RSyscall *s) { +RZ_API void rz_syscall_free(RzSyscall *s) { if (s) { if (s->refs > 0) { s->refs--; @@ -43,9 +43,9 @@ R_API void r_syscall_free(RSyscall *s) { } static Sdb *openDatabase(Sdb *db, const char *name) { - char *file = r_str_newf ( R_JOIN_3_PATHS ("%s", R2_SDB, "%s.sdb"), - r_sys_prefix (NULL), name); - if (r_file_exists (file)) { + char *file = rz_str_newf ( R_JOIN_3_PATHS ("%s", R2_SDB, "%s.sdb"), + rz_sys_prefix (NULL), name); + if (rz_file_exists (file)) { if (db) { sdb_reset (db); sdb_open (db, file); @@ -57,7 +57,7 @@ static Sdb *openDatabase(Sdb *db, const char *name) { return db; } -static inline bool syscall_reload_needed(RSyscall *s, const char *os, const char *arch, int bits) { +static inline bool syscall_reload_needed(RzSyscall *s, const char *os, const char *arch, int bits) { if (!s->os || strcmp (s->os, os)) { return true; } @@ -67,7 +67,7 @@ static inline bool syscall_reload_needed(RSyscall *s, const char *os, const char return s->bits != bits; } -static inline bool sysregs_reload_needed(RSyscall *s, const char *arch, int bits, const char *cpu) { +static inline bool sysregs_reload_needed(RzSyscall *s, const char *arch, int bits, const char *cpu) { if (!s->arch || strcmp (s->arch, arch)) { return true; } @@ -77,8 +77,8 @@ static inline bool sysregs_reload_needed(RSyscall *s, const char *arch, int bits return !s->cpu || strcmp (s->cpu, cpu); } -// TODO: should be renamed to r_syscall_use(); -R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char *cpu, const char *os) { +// TODO: should be renamed to rz_syscall_use(); +RZ_API bool rz_syscall_setup(RzSyscall *s, const char *arch, int bits, const char *cpu, const char *os) { bool syscall_changed, sysregs_changed; if (!os || !*os) { @@ -116,7 +116,7 @@ R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char * } if (syscall_changed) { - char *dbName = r_str_newf (R_JOIN_2_PATHS ("syscall", "%s-%s-%d"), + char *dbName = rz_str_newf (R_JOIN_2_PATHS ("syscall", "%s-%s-%d"), os, arch, bits); if (dbName) { s->db = openDatabase (s->db, dbName); @@ -125,7 +125,7 @@ R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char * } if (sysregs_changed) { - char *dbName = r_str_newf (R_JOIN_2_PATHS ("sysregs", "%s-%d-%s"), + char *dbName = rz_str_newf (R_JOIN_2_PATHS ("sysregs", "%s-%d-%s"), arch, bits, cpu); if (dbName) { sdb_free (s->srdb); @@ -140,28 +140,28 @@ R_API bool r_syscall_setup(RSyscall *s, const char *arch, int bits, const char * return true; } -R_API RSyscallItem *r_syscall_item_new_from_string(const char *name, const char *s) { - RSyscallItem *si; +RZ_API RzSyscallItem *rz_syscall_item_new_from_string(const char *name, const char *s) { + RzSyscallItem *si; char *o; if (!name || !s) { return NULL; } o = strdup (s); - int cols = r_str_split (o, ','); + int cols = rz_str_split (o, ','); if (cols < 3) { free (o); return NULL; } - si = R_NEW0 (RSyscallItem); + si = R_NEW0 (RzSyscallItem); if (!si) { free (o); return NULL; } si->name = strdup (name); - si->swi = (int)r_num_get (NULL, r_str_word_get0 (o, 0)); - si->num = (int)r_num_get (NULL, r_str_word_get0 (o, 1)); - si->args = (int)r_num_get (NULL, r_str_word_get0 (o, 2)); + si->swi = (int)rz_num_get (NULL, rz_str_word_get0 (o, 0)); + si->num = (int)rz_num_get (NULL, rz_str_word_get0 (o, 1)); + si->args = (int)rz_num_get (NULL, rz_str_word_get0 (o, 2)); si->sargs = calloc (si->args + 1, sizeof (char)); if (!si->sargs) { free (si); @@ -169,13 +169,13 @@ R_API RSyscallItem *r_syscall_item_new_from_string(const char *name, const char return NULL; } if (cols > 3) { - strncpy (si->sargs, r_str_word_get0 (o, 3), si->args); + strncpy (si->sargs, rz_str_word_get0 (o, 3), si->args); } free (o); return si; } -R_API void r_syscall_item_free(RSyscallItem *si) { +RZ_API void rz_syscall_item_free(RzSyscallItem *si) { if (!si) { return; } @@ -184,19 +184,19 @@ R_API void r_syscall_item_free(RSyscallItem *si) { free (si); } -static int getswi(RSyscall *s, int swi) { +static int getswi(RzSyscall *s, int swi) { if (s && swi == -1) { - return r_syscall_get_swi (s); + return rz_syscall_get_swi (s); } return swi; } -R_API int r_syscall_get_swi(RSyscall *s) { +RZ_API int rz_syscall_get_swi(RzSyscall *s) { return (int)sdb_num_get (s->db, "_", NULL); } -R_API RSyscallItem *r_syscall_get(RSyscall *s, int num, int swi) { - r_return_val_if_fail (s && s->db, NULL); +RZ_API RzSyscallItem *rz_syscall_get(RzSyscall *s, int num, int swi) { + rz_return_val_if_fail (s && s->db, NULL); const char *ret, *ret2, *key; swi = getswi (s, swi); if (swi < 16) { @@ -220,11 +220,11 @@ R_API RSyscallItem *r_syscall_get(RSyscall *s, int num, int swi) { if (!ret2) { return NULL; } - return r_syscall_item_new_from_string (ret, ret2); + return rz_syscall_item_new_from_string (ret, ret2); } -R_API int r_syscall_get_num(RSyscall *s, const char *str) { - r_return_val_if_fail (s && str && s->db, -1); +RZ_API int rz_syscall_get_num(RzSyscall *s, const char *str) { + rz_return_val_if_fail (s && str && s->db, -1); int sn = (int)sdb_array_get_num (s->db, str, 1, NULL); if (sn == 0) { return (int)sdb_array_get_num (s->db, str, 0, NULL); @@ -232,8 +232,8 @@ R_API int r_syscall_get_num(RSyscall *s, const char *str) { return sn; } -R_API const char *r_syscall_get_i(RSyscall *s, int num, int swi) { - r_return_val_if_fail (s && s->db, NULL); +RZ_API const char *rz_syscall_get_i(RzSyscall *s, int num, int swi) { + rz_return_val_if_fail (s && s->db, NULL); char foo[32]; swi = getswi (s, swi); snprintf (foo, sizeof (foo), "0x%x.%d", swi, num); @@ -241,33 +241,33 @@ R_API const char *r_syscall_get_i(RSyscall *s, int num, int swi) { } static bool callback_list(void *u, const char *k, const char *v) { - RList *list = (RList*)u; + RzList *list = (RzList*)u; if (!strchr (k, '.')) { - RSyscallItem *si = r_syscall_item_new_from_string (k, v); + RzSyscallItem *si = rz_syscall_item_new_from_string (k, v); if (!si) { return true; } if (!strchr (si->name, '.')) { - r_list_append (list, si); + rz_list_append (list, si); } else { - r_syscall_item_free (si); + rz_syscall_item_free (si); } } return true; // continue loop } -R_API RList *r_syscall_list(RSyscall *s) { - r_return_val_if_fail (s && s->db, NULL); - RList *list = r_list_newf ((RListFree)r_syscall_item_free); +RZ_API RzList *rz_syscall_list(RzSyscall *s) { + rz_return_val_if_fail (s && s->db, NULL); + RzList *list = rz_list_newf ((RzListFree)rz_syscall_item_free); sdb_foreach (s->db, callback_list, list); return list; } /* io and sysregs */ -R_API const char *r_syscall_get_io(RSyscall *s, int ioport) { - r_return_val_if_fail (s, NULL); +RZ_API const char *rz_syscall_get_io(RzSyscall *s, int ioport) { + rz_return_val_if_fail (s, NULL); int i; - const char *name = r_syscall_sysreg (s, "io", ioport); + const char *name = rz_syscall_sysreg (s, "io", ioport); if (name) { return name; } @@ -279,8 +279,8 @@ R_API const char *r_syscall_get_io(RSyscall *s, int ioport) { return NULL; } -R_API const char* r_syscall_sysreg(RSyscall *s, const char *type, ut64 num) { - r_return_val_if_fail (s && s->db, NULL); +RZ_API const char* rz_syscall_sysreg(RzSyscall *s, const char *type, ut64 num) { + rz_return_val_if_fail (s && s->db, NULL); const char *key = sdb_fmt ("%s,%"PFMT64d, type, num); return sdb_const_get (s->db, key, 0); } diff --git a/libr/util/Makefile b/librz/util/Makefile similarity index 99% rename from libr/util/Makefile rename to librz/util/Makefile index 59a34e1094..8c159c5d07 100644 --- a/libr/util/Makefile +++ b/librz/util/Makefile @@ -1,6 +1,6 @@ include ../config.mk -NAME=r_util +NAME=rz_util CFLAGS+=-DR2_PLUGIN_INCORE -I$(TOP)/shlr PCLIBS=@LIBZIP@ @DL_LIBS@ diff --git a/librz/util/alloc.c b/librz/util/alloc.c new file mode 100644 index 0000000000..0550ae85e1 --- /dev/null +++ b/librz/util/alloc.c @@ -0,0 +1,74 @@ +/* radare - LGPL - Copyright 2019-2020 - pancake */ + +#include +#include + +RZ_API void rz_alloc_init (void) { +#if R_MALLOC_WRAPPER + rz_alloc_hooks (malloc, calloc, realloc, free); +#endif +} + +#if R_MALLOC_WRAPPER + +#if R_MALLOC_GLOBAL +RZ_API RMalloc *rz_malloc = malloc; +RZ_API RCalloc *rz_calloc = calloc; +RZ_API RRealloc *rz_realloc = realloc; +RZ_API RFree *rz_free = free; + +RZ_API void rz_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f) { + rz_return_if_fail (m && c && r && f); + rz_malloc = m; + rz_calloc = c; + rz_realloc = r; + rz_free = f; +} + +#else + +static RMalloc *_r_malloc = malloc; +static RCalloc *_r_calloc = calloc; +static RRealloc *_r_realloc = realloc; +static RFree *_r_free = free; + +RZ_API void rz_alloc_hooks(RMalloc m, RCalloc c, RRealloc r, RFree f) { + rz_return_if_fail (m && c && r && f); + _r_malloc = m; + _r_calloc = c; + _r_realloc = r; + _r_free = f; +} + +RZ_API void *rz_malloc(size_t sz) { + return _r_malloc (sz); +} + +RZ_API void *rz_calloc(size_t count, size_t sz) { + return _r_calloc (count, sz); +} + +RZ_API void *rz_realloc(void *p, size_t sz) { + return _r_realloc (p, sz); +} + +RZ_API void rz_free(void *p) { + return _r_free (p); +} +#endif +#endif + +RZ_API void* rz_malloc_aligned(size_t size, size_t alignment) { + int offset = alignment - 1 + sizeof (void*); + void* p1 = _r_malloc (size + offset); + if (!p1) { + return NULL; + } + void **p2 = (void**)(((size_t)(p1) + offset) & ~(alignment - 1)); + p2[-1] = p1; + return p2; +} + +RZ_API void rz_free_aligned(void *p) { + _r_free (((void**)p)[-1]); +} diff --git a/libr/util/annotated_code.c b/librz/util/annotated_code.c similarity index 51% rename from libr/util/annotated_code.c rename to librz/util/annotated_code.c index 35bd9fa2ed..e7b5706785 100644 --- a/libr/util/annotated_code.c +++ b/librz/util/annotated_code.c @@ -1,19 +1,19 @@ -#include -#include -#include +#include +#include +#include -R_API RAnnotatedCode *r_annotated_code_new(char *code) { +RZ_API RAnnotatedCode *rz_annotated_code_new(char *code) { RAnnotatedCode *r = R_NEW0 (RAnnotatedCode); if (!r) { return NULL; } r->code = code; - r_vector_init (&r->annotations, sizeof (RCodeAnnotation), r_annotation_free, NULL); + rz_vector_init (&r->annotations, sizeof (RCodeAnnotation), rz_annotation_free, NULL); return r; } -R_API void r_annotation_free(void *e, void *user) { +RZ_API void rz_annotation_free(void *e, void *user) { (void)user; RCodeAnnotation *annotation = e; if (annotation->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME) { @@ -23,58 +23,58 @@ R_API void r_annotation_free(void *e, void *user) { } } -R_API bool r_annotation_is_reference(RCodeAnnotation *annotation) { +RZ_API bool rz_annotation_is_reference(RCodeAnnotation *annotation) { return (annotation->type == R_CODE_ANNOTATION_TYPE_GLOBAL_VARIABLE || annotation->type == R_CODE_ANNOTATION_TYPE_CONSTANT_VARIABLE || annotation->type == R_CODE_ANNOTATION_TYPE_FUNCTION_NAME); } -R_API bool r_annotation_is_variable(RCodeAnnotation *annotation) { +RZ_API bool rz_annotation_is_variable(RCodeAnnotation *annotation) { return (annotation->type == R_CODE_ANNOTATION_TYPE_LOCAL_VARIABLE || annotation->type == R_CODE_ANNOTATION_TYPE_FUNCTION_PARAMETER); } -R_API void r_annotated_code_free(RAnnotatedCode *code) { +RZ_API void rz_annotated_code_free(RAnnotatedCode *code) { if (!code) { return; } - r_vector_clear (&code->annotations); - r_free (code->code); - r_free (code); + rz_vector_clear (&code->annotations); + rz_free (code->code); + rz_free (code); } -R_API void r_annotated_code_add_annotation(RAnnotatedCode *code, RCodeAnnotation *annotation) { - r_vector_push (&code->annotations, annotation); +RZ_API void rz_annotated_code_add_annotation(RAnnotatedCode *code, RCodeAnnotation *annotation) { + rz_vector_push (&code->annotations, annotation); } -R_API RPVector *r_annotated_code_annotations_in(RAnnotatedCode *code, size_t offset) { - RPVector *r = r_pvector_new (NULL); +RZ_API RPVector *rz_annotated_code_annotations_in(RAnnotatedCode *code, size_t offset) { + RPVector *r = rz_pvector_new (NULL); if (!r) { return NULL; } RCodeAnnotation *annotation; - r_vector_foreach (&code->annotations, annotation) { + rz_vector_foreach (&code->annotations, annotation) { if (offset >= annotation->start && offset < annotation->end) { - r_pvector_push (r, annotation); + rz_pvector_push (r, annotation); } } return r; } -R_API RPVector *r_annotated_code_annotations_range(RAnnotatedCode *code, size_t start, size_t end) { - RPVector *r = r_pvector_new (NULL); +RZ_API RPVector *rz_annotated_code_annotations_range(RAnnotatedCode *code, size_t start, size_t end) { + RPVector *r = rz_pvector_new (NULL); if (!r) { return NULL; } RCodeAnnotation *annotation; - r_vector_foreach (&code->annotations, annotation) { + rz_vector_foreach (&code->annotations, annotation) { if (start >= annotation->end || end < annotation->start) { continue; } - r_pvector_push (r, annotation); + rz_pvector_push (r, annotation); } return r; } -R_API RVector *r_annotated_code_line_offsets(RAnnotatedCode *code) { - RVector *r = r_vector_new (sizeof (ut64), NULL, NULL); +RZ_API RzVector *rz_annotated_code_line_offsets(RAnnotatedCode *code) { + RzVector *r = rz_vector_new (sizeof (ut64), NULL, NULL); if (!r) { return NULL; } @@ -83,10 +83,10 @@ R_API RVector *r_annotated_code_line_offsets(RAnnotatedCode *code) { do { char *next = strchr (code->code + cur, '\n'); size_t next_i = next? (next - code->code) + 1: len; - RPVector *annotations = r_annotated_code_annotations_range (code, cur, next_i); + RPVector *annotations = rz_annotated_code_annotations_range (code, cur, next_i); ut64 offset = UT64_MAX; void **it; - r_pvector_foreach (annotations, it) { + rz_pvector_foreach (annotations, it) { RCodeAnnotation *annotation = *it; if (annotation->type != R_CODE_ANNOTATION_TYPE_OFFSET) { continue; @@ -94,9 +94,9 @@ R_API RVector *r_annotated_code_line_offsets(RAnnotatedCode *code) { offset = annotation->offset.offset; break; } - r_vector_push (r, &offset); + rz_vector_push (r, &offset); cur = next_i; - r_pvector_free (annotations); + rz_pvector_free (annotations); } while (cur < len); return r; } diff --git a/libr/util/ascii_table.c b/librz/util/ascii_table.c similarity index 98% rename from libr/util/ascii_table.c rename to librz/util/ascii_table.c index 1be70a4073..c1f0144ee2 100644 --- a/libr/util/ascii_table.c +++ b/librz/util/ascii_table.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2018 - pancake, r00tus3r */ -#include +#include static const char *ascii_table = "The following table contains the 128 ASCII characters.\n" @@ -74,6 +74,6 @@ static const char *ascii_table = "077 63 3F ? 177 127 7F DEL\n" ; -R_API const char *ret_ascii_table(void) { +RZ_API const char *ret_ascii_table(void) { return ascii_table; } diff --git a/libr/util/asn1.c b/librz/util/asn1.c similarity index 68% rename from libr/util/asn1.c rename to librz/util/asn1.c index 98fe9797bb..f323dc321f 100644 --- a/libr/util/asn1.c +++ b/librz/util/asn1.c @@ -1,14 +1,14 @@ -/* radare2 - LGPL - Copyright 2017-2018 - wargio */ +/* rizin - LGPL - Copyright 2017-2018 - wargio */ -#include -#include +#include +#include #include #include #include static int ASN1_STD_FORMAT = 1; -R_API void asn1_setformat (int fmt) { +RZ_API void asn1_setformat (int fmt) { ASN1_STD_FORMAT = fmt; } @@ -93,7 +93,7 @@ out_error: return NULL; } -static ut32 r_asn1_count_objects (const ut8 *buffer, ut32 length) { +static ut32 rz_asn1_count_objects (const ut8 *buffer, ut32 length) { if (!buffer || !length) { return 0; } @@ -116,7 +116,7 @@ static ut32 r_asn1_count_objects (const ut8 *buffer, ut32 length) { return counter; } -R_API RASN1Object *r_asn1_create_object (const ut8 *buffer, ut32 length, const ut8 *start_pointer) { +RZ_API RASN1Object *rz_asn1_create_object (const ut8 *buffer, ut32 length, const ut8 *start_pointer) { RASN1Object *object = asn1_parse_header (buffer, length, start_pointer); if (object && (object->form == FORM_CONSTRUCTED || object->tag == TAG_BITSTRING || object->tag == TAG_OCTETSTRING)) { const ut8 *next = object->sector; @@ -125,19 +125,19 @@ R_API RASN1Object *r_asn1_create_object (const ut8 *buffer, ut32 length, const u free (object); return NULL; } - ut32 count = r_asn1_count_objects (object->sector, object->length); + ut32 count = rz_asn1_count_objects (object->sector, object->length); if (count > 0) { object->list.length = count; object->list.objects = R_NEWS0 (RASN1Object*, count); if (!object->list.objects) { - r_asn1_free_object (object); + rz_asn1_free_object (object); return NULL; } ut32 i; for (i = 0; next >= buffer && next < end && i < count; i++) { - RASN1Object *inner = r_asn1_create_object (next, end - next, start_pointer); + RASN1Object *inner = rz_asn1_create_object (next, end - next, start_pointer); if (!inner || next == inner->sector) { - r_asn1_free_object (inner); + rz_asn1_free_object (inner); break; } next = inner->sector + inner->length; @@ -148,7 +148,7 @@ R_API RASN1Object *r_asn1_create_object (const ut8 *buffer, ut32 length, const u return object; } -R_API RASN1Binary *r_asn1_create_binary (const ut8 *buffer, ut32 length) { +RZ_API RASN1Binary *rz_asn1_create_binary (const ut8 *buffer, ut32 length) { if (!buffer || !length) { return NULL; } @@ -167,7 +167,7 @@ R_API RASN1Binary *r_asn1_create_binary (const ut8 *buffer, ut32 length) { return bin; } -R_API void r_asn1_print_hex (RASN1Object *object, char* buffer, ut32 size, ut32 depth) { +RZ_API void rz_asn1_print_hex (RASN1Object *object, char* buffer, ut32 size, ut32 depth) { ut32 i; if (!object || !object->sector) { return; @@ -175,7 +175,7 @@ R_API void r_asn1_print_hex (RASN1Object *object, char* buffer, ut32 size, ut32 char* p = buffer; char* end = buffer + size; if (depth > 0 && !ASN1_STD_FORMAT) { - const char *pad = r_str_pad (' ', (depth * 2) - 2); + const char *pad = rz_str_pad (' ', (depth * 2) - 2); snprintf (p, end - p, "%s", pad); p += strlen(pad); } @@ -190,8 +190,8 @@ R_API void r_asn1_print_hex (RASN1Object *object, char* buffer, ut32 size, ut32 } #if !ASN1_STD_FORMAT -static void r_asn1_print_padded(RStrBuf *sb, RASN1Object *object, int depth, const char *k, const char *v) { - const char *pad = r_str_pad (' ', (depth * 2) - 2); +static void rz_asn1_print_padded(RStrBuf *sb, RASN1Object *object, int depth, const char *k, const char *v) { + const char *pad = rz_str_pad (' ', (depth * 2) - 2); if (object->form && !*v) { return; } @@ -201,53 +201,53 @@ static void r_asn1_print_padded(RStrBuf *sb, RASN1Object *object, int depth, con break; case TAG_INTEGER: case TAG_REAL: - if (*r_str_trim_head_ro (v)) { - r_strbuf_appendf (sb, "%s%s\n%s%s\n", pad, k, pad, v); + if (*rz_str_trim_head_ro (v)) { + rz_strbuf_appendf (sb, "%s%s\n%s%s\n", pad, k, pad, v); } break; case TAG_BITSTRING: default: - if (*r_str_trim_head_ro (v)) { - r_strbuf_appendf (sb, "%s%s\n", pad, v); + if (*rz_str_trim_head_ro (v)) { + rz_strbuf_appendf (sb, "%s%s\n", pad, v); } break; } } #endif -static RASN1String* r_asn1_print_hexdump_padded (RASN1Object *object, ut32 depth) { +static RASN1String* rz_asn1_print_hexdump_padded (RASN1Object *object, ut32 depth) { const char *pad; ut32 i, j; char readable[20] = {0}; if (!object || !object->sector || object->length < 1) { return NULL; } - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); if (ASN1_STD_FORMAT) { pad = " : "; } else { - pad = r_str_pad (' ', depth * 2); - r_strbuf_appendf (sb, " ", pad); + pad = rz_str_pad (' ', depth * 2); + rz_strbuf_appendf (sb, " ", pad); } for (i = 0, j = 0; i < object->length; i++, j++) { ut8 c = object->sector[i]; if (i > 0 && (i % 16) == 0) { - r_strbuf_appendf (sb, "|%-16s|\n%s", readable, pad); + rz_strbuf_appendf (sb, "|%-16s|\n%s", readable, pad); memset (readable, 0, sizeof (readable)); j = 0; } - r_strbuf_appendf (sb, "%02x ", c); + rz_strbuf_appendf (sb, "%02x ", c); readable[j] = IS_PRINTABLE(c) ? c : '.'; } while ((i % 16) != 0) { - r_strbuf_appendf (sb, " "); + rz_strbuf_appendf (sb, " "); i++; } - r_strbuf_appendf (sb, "|%-16s|", readable); - char* text = r_strbuf_drain (sb); - RASN1String* asn1str = r_asn1_create_string (text, true, strlen (text) + 1); + rz_strbuf_appendf (sb, "|%-16s|", readable); + char* text = rz_strbuf_drain (sb); + RASN1String* asn1str = rz_asn1_create_string (text, true, strlen (text) + 1); if (!asn1str) { /* no memory left.. */ free (text); @@ -255,14 +255,14 @@ static RASN1String* r_asn1_print_hexdump_padded (RASN1Object *object, ut32 depth return asn1str; } -R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { +RZ_API char *rz_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { ut32 i; bool root = false; if (!object) { return NULL; } if (!sb) { - sb = r_strbuf_new (""); + sb = rz_strbuf_new (""); root = true; } //this shall not be freed. it's a pointer into the buffer. @@ -286,33 +286,33 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { case TAG_INTEGER: name = "INTEGER"; if (object->length < 16) { - r_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); + rz_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); string = temp_name; } else { - asn1str = r_asn1_print_hexdump_padded (object, depth); + asn1str = rz_asn1_print_hexdump_padded (object, depth); } break; case TAG_BITSTRING: name = "BIT_STRING"; if (!object->list.objects) { if (object->length < 16) { - r_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); + rz_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); string = temp_name; } else { - asn1str = r_asn1_print_hexdump_padded (object, depth); + asn1str = rz_asn1_print_hexdump_padded (object, depth); } } break; case TAG_OCTETSTRING: name = "OCTET_STRING"; - if (r_str_is_printable_limited ((const char *)object->sector, object->length)) { - asn1str = r_asn1_stringify_string (object->sector, object->length); + if (rz_str_is_printable_limited ((const char *)object->sector, object->length)) { + asn1str = rz_asn1_stringify_string (object->sector, object->length); } else if (!object->list.objects) { if (object->length < 16) { - r_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); + rz_asn1_print_hex (object, temp_name, sizeof (temp_name), depth); string = temp_name; } else { - asn1str = r_asn1_print_hexdump_padded (object, depth); + asn1str = rz_asn1_print_hexdump_padded (object, depth); } } break; @@ -321,7 +321,7 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { break; case TAG_OID: name = "OBJECT_IDENTIFIER"; - asn1str = r_asn1_stringify_oid (object->sector, object->length); + asn1str = rz_asn1_stringify_oid (object->sector, object->length); break; case TAG_OBJDESCRIPTOR: name = "OBJECT_DESCRIPTOR"; @@ -331,7 +331,7 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { break; case TAG_REAL: name = "REAL"; - asn1str = r_asn1_print_hexdump_padded (object, depth); + asn1str = rz_asn1_print_hexdump_padded (object, depth); break; case TAG_ENUMERATED: name = "ENUMERATED"; @@ -341,7 +341,7 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { break; case TAG_UTF8STRING: name = "UTF8String"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_SEQUENCE: name = "SEQUENCE"; @@ -351,50 +351,50 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { break; case TAG_NUMERICSTRING: name = "NumericString"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_PRINTABLESTRING: name = "PrintableString"; // ASCII subset - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_T61STRING: name = "TeletexString"; // aka T61String - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_VIDEOTEXSTRING: name = "VideotexString"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_IA5STRING: name = "IA5String"; // ASCII - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_UTCTIME: name = "UTCTime"; - asn1str = r_asn1_stringify_utctime (object->sector, object->length); + asn1str = rz_asn1_stringify_utctime (object->sector, object->length); break; case TAG_GENERALIZEDTIME: name = "GeneralizedTime"; - asn1str = r_asn1_stringify_time (object->sector, object->length); + asn1str = rz_asn1_stringify_time (object->sector, object->length); break; case TAG_GRAPHICSTRING: name = "GraphicString"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_VISIBLESTRING: name = "VisibleString"; // ASCII subset - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_GENERALSTRING: name = "GeneralString"; break; case TAG_UNIVERSALSTRING: name = "UniversalString"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; case TAG_BMPSTRING: name = "BMPString"; - asn1str = r_asn1_stringify_string (object->sector, object->length); + asn1str = rz_asn1_stringify_string (object->sector, object->length); break; default: snprintf (temp_name, sizeof (temp_name), "Universal_%u", object->tag); @@ -419,29 +419,29 @@ R_API char *r_asn1_to_string (RASN1Object *object, ut32 depth, RStrBuf *sb) { string = asn1str->string; } if (ASN1_STD_FORMAT) { - r_strbuf_appendf (sb, "%4"PFMT64d" ", object->offset); - r_strbuf_appendf (sb, "%4u:%2d: %s %-20s: %s\n", object->length, + rz_strbuf_appendf (sb, "%4"PFMT64d" ", object->offset); + rz_strbuf_appendf (sb, "%4u:%2d: %s %-20s: %s\n", object->length, depth, object->form ? "cons" : "prim", name, string); - r_asn1_free_string (asn1str); + rz_asn1_free_string (asn1str); if (object->list.objects) { for (i = 0; i < object->list.length; i++) { - r_asn1_to_string (object->list.objects[i], depth + 1, sb); + rz_asn1_to_string (object->list.objects[i], depth + 1, sb); } } } else { - r_asn1_print_padded (sb, object, depth, name, string); - r_asn1_free_string (asn1str); + rz_asn1_print_padded (sb, object, depth, name, string); + rz_asn1_free_string (asn1str); if (object->list.objects) { for (i = 0; i < object->list.length; i++) { RASN1Object *obj = object->list.objects[i]; - r_asn1_to_string (obj, depth + 1, sb); + rz_asn1_to_string (obj, depth + 1, sb); } } } - return root? r_strbuf_drain (sb): NULL; + return root? rz_strbuf_drain (sb): NULL; } -R_API void r_asn1_free_object (RASN1Object *object) { +RZ_API void rz_asn1_free_object (RASN1Object *object) { ut32 i; if (!object) { return; @@ -450,7 +450,7 @@ R_API void r_asn1_free_object (RASN1Object *object) { object->sector = NULL; if (object->list.objects) { for (i = 0; i < object->list.length; i++) { - r_asn1_free_object (object->list.objects[i]); + rz_asn1_free_object (object->list.objects[i]); } R_FREE (object->list.objects); } @@ -459,7 +459,7 @@ R_API void r_asn1_free_object (RASN1Object *object) { free (object); } -R_API void r_asn1_free_binary (RASN1Binary* bin) { +RZ_API void rz_asn1_free_binary (RASN1Binary* bin) { if (bin) { free (bin->binary); free (bin); diff --git a/libr/util/asn1_oids.h b/librz/util/asn1_oids.h similarity index 99% rename from libr/util/asn1_oids.h rename to librz/util/asn1_oids.h index 07f4761388..082c357a29 100644 --- a/libr/util/asn1_oids.h +++ b/librz/util/asn1_oids.h @@ -5,7 +5,7 @@ extern "C" { #endif -struct r_oid_list_t { +struct rz_oid_list_t { const char* oid; const char* name; } X509OIDList [] = { diff --git a/libr/util/assert.c b/librz/util/assert.c similarity index 65% rename from libr/util/assert.c rename to librz/util/assert.c index aca6b3e5ed..db1dd11829 100644 --- a/libr/util/assert.c +++ b/librz/util/assert.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2018-2020 - ret2libc */ +/* rizin - LGPL - Copyright 2018-2020 - ret2libc */ -#include +#include #ifdef R2_ASSERT_STDOUT static void stdout_log(const char *output, const char *funcname, const char *filename, @@ -9,9 +9,9 @@ static void stdout_log(const char *output, const char *funcname, const char *fil } static void print_message(RLogLevel level, const char *fmt, va_list args) { - r_log_add_callback (stdout_log); + rz_log_add_callback (stdout_log); R_VLOG (level, NULL, fmt, args); - r_log_del_callback (stdout_log); + rz_log_del_callback (stdout_log); } #else static void print_message(RLogLevel level, const char *fmt, va_list args) { @@ -20,18 +20,18 @@ static void print_message(RLogLevel level, const char *fmt, va_list args) { #endif /* * It prints a message to the log and it provides a single point of entrance in - * case of debugging. All r_return_* functions call this. + * case of debugging. All rz_return_* functions call this. */ -R_API void r_assert_log(RLogLevel level, const char *fmt, ...) { +RZ_API void rz_assert_log(RLogLevel level, const char *fmt, ...) { va_list args; va_start (args, fmt); print_message (level, fmt, args); va_end (args); - char *env = r_sys_getenv ("R2_DEBUG_ASSERT"); + char *env = rz_sys_getenv ("R2_DEBUG_ASSERT"); if (env) { - r_sys_backtrace (); + rz_sys_backtrace (); if (*env && atoi (env)) { - r_sys_breakpoint (); + rz_sys_breakpoint (); } free (env); } diff --git a/libr/util/astr.c b/librz/util/astr.c similarity index 75% rename from libr/util/astr.c rename to librz/util/astr.c index add4c0622e..1b994fa97c 100644 --- a/libr/util/astr.c +++ b/librz/util/astr.c @@ -1,11 +1,11 @@ -/* radare2 - LGPL - Copyright 2017-2018 - wargio, pancake */ +/* rizin - LGPL - Copyright 2017-2018 - wargio, pancake */ -#include +#include #include "asn1_oids.h" static const char* _hex = "0123456789abcdef"; -R_API RASN1String *r_asn1_create_string (const char *string, bool allocated, ut32 length) { +RZ_API RASN1String *rz_asn1_create_string (const char *string, bool allocated, ut32 length) { if (!string || !length) { return NULL; } @@ -19,10 +19,10 @@ R_API RASN1String *r_asn1_create_string (const char *string, bool allocated, ut3 } static RASN1String *newstr(const char *string) { - return r_asn1_create_string (string, false, strlen (string) + 1); + return rz_asn1_create_string (string, false, strlen (string) + 1); } -R_API RASN1String *r_asn1_concatenate_strings (RASN1String *s0, RASN1String *s1, bool freestr) { +RZ_API RASN1String *rz_asn1_concatenate_strings (RASN1String *s0, RASN1String *s1, bool freestr) { char* str; ut32 len; if (!s0 || !s1 || s0->length == 0 || s1->length == 0) { @@ -32,37 +32,37 @@ R_API RASN1String *r_asn1_concatenate_strings (RASN1String *s0, RASN1String *s1, str = (char*) malloc (len); if (!str) { if (freestr) { - r_asn1_free_string (s0); - r_asn1_free_string (s1); + rz_asn1_free_string (s0); + rz_asn1_free_string (s1); } return NULL; } memcpy (str, s0->string, s0->length); memcpy (str + s0->length - 1, s1->string, s1->length); if (freestr) { - r_asn1_free_string (s0); - r_asn1_free_string (s1); + rz_asn1_free_string (s0); + rz_asn1_free_string (s1); } - RASN1String *res = r_asn1_create_string (str, true, len); + RASN1String *res = rz_asn1_create_string (str, true, len); if (!res) { free (str); } return res; } -R_API RASN1String *r_asn1_stringify_string (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_string (const ut8 *buffer, ut32 length) { if (!buffer || !length) { return NULL; } - char *str = r_str_ndup ((const char *)buffer, length); + char *str = rz_str_ndup ((const char *)buffer, length); if (!str) { return NULL; } - r_str_filter (str, length); - return r_asn1_create_string (str, true, length); + rz_str_filter (str, length); + return rz_asn1_create_string (str, true, length); } -R_API RASN1String *r_asn1_stringify_utctime (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_utctime (const ut8 *buffer, ut32 length) { if (!buffer || length != 13 || buffer[12] != 'Z') { return NULL; } @@ -96,14 +96,14 @@ R_API RASN1String *r_asn1_stringify_utctime (const ut8 *buffer, ut32 length) { str[22] = 'T'; str[23] = '\0'; - RASN1String* asn1str = r_asn1_create_string (str, true, str_sz); + RASN1String* asn1str = rz_asn1_create_string (str, true, str_sz); if (!asn1str) { free (str); } return asn1str; } -R_API RASN1String *r_asn1_stringify_time (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_time (const ut8 *buffer, ut32 length) { if (!buffer || length != 15 || buffer[14] != 'Z') { return NULL; } @@ -138,14 +138,14 @@ R_API RASN1String *r_asn1_stringify_time (const ut8 *buffer, ut32 length) { str[22] = 'T'; str[23] = '\0'; - RASN1String* asn1str = r_asn1_create_string (str, true, str_sz); + RASN1String* asn1str = rz_asn1_create_string (str, true, str_sz); if (!asn1str) { free (str); } return asn1str; } -R_API RASN1String *r_asn1_stringify_bits (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_bits (const ut8 *buffer, ut32 length) { ut32 i, j, k; ut64 size; ut8 c; @@ -166,21 +166,21 @@ R_API RASN1String *r_asn1_stringify_bits (const ut8 *buffer, ut32 length) { } } str[size - 1] = '\0'; - RASN1String* asn1str = r_asn1_create_string (str, true, size); + RASN1String* asn1str = rz_asn1_create_string (str, true, size); if (!asn1str) { free (str); } return asn1str; } -R_API RASN1String *r_asn1_stringify_boolean (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_boolean (const ut8 *buffer, ut32 length) { if (!buffer || length != 1 || (buffer[0] != 0 && buffer[0] != 0xFF)) { return NULL; } - return newstr (r_str_bool (buffer[0])); + return newstr (rz_str_bool (buffer[0])); } -R_API RASN1String *r_asn1_stringify_integer (const ut8 *buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_integer (const ut8 *buffer, ut32 length) { ut32 i, j; ut64 size; ut8 c; @@ -201,14 +201,14 @@ R_API RASN1String *r_asn1_stringify_integer (const ut8 *buffer, ut32 length) { str[j + 2] = ':'; } str[size - 1] = '\0'; - RASN1String* asn1str = r_asn1_create_string (str, true, size); + RASN1String* asn1str = rz_asn1_create_string (str, true, size); if (!asn1str) { free (str); } return asn1str; } -R_API RASN1String* r_asn1_stringify_bytes (const ut8 *buffer, ut32 length) { +RZ_API RASN1String* rz_asn1_stringify_bytes (const ut8 *buffer, ut32 length) { ut32 i, j, k; ut64 size; ut8 c; @@ -237,14 +237,14 @@ R_API RASN1String* r_asn1_stringify_bytes (const ut8 *buffer, ut32 length) { } } str[size - 1] = '\0'; - RASN1String* asn1str = r_asn1_create_string (str, true, size); + RASN1String* asn1str = rz_asn1_create_string (str, true, size); if (!asn1str) { free (str); } return asn1str; } -R_API RASN1String *r_asn1_stringify_oid (const ut8* buffer, ut32 length) { +RZ_API RASN1String *rz_asn1_stringify_oid (const ut8* buffer, ut32 length) { const ut8 *start, *end; char *str, *t; ut32 i, slen, bits; @@ -301,14 +301,14 @@ R_API RASN1String *r_asn1_stringify_oid (const ut8* buffer, ut32 length) { } ++i; } while (X509OIDList[i].oid && X509OIDList[i].name); - RASN1String* asn1str = r_asn1_create_string (str, true, ASN1_OID_LEN); + RASN1String* asn1str = rz_asn1_create_string (str, true, ASN1_OID_LEN); if (!asn1str) { free (str); } return asn1str; } -R_API void r_asn1_free_string (RASN1String* str) { +RZ_API void rz_asn1_free_string (RASN1String* str) { if (str) { if (str->allocated) { free ((char*) str->string); @@ -317,7 +317,7 @@ R_API void r_asn1_free_string (RASN1String* str) { } } -R_API RASN1String *asn1_stringify_tag (RASN1Object *object) { +RZ_API RASN1String *asn1_stringify_tag (RASN1Object *object) { if (!object) { return NULL; } @@ -355,7 +355,7 @@ R_API RASN1String *asn1_stringify_tag (RASN1Object *object) { return newstr (s); } -R_API RASN1String *asn1_stringify_sector (RASN1Object *object) { +RZ_API RASN1String *asn1_stringify_sector (RASN1Object *object) { if (!object) { return NULL; } @@ -363,26 +363,26 @@ R_API RASN1String *asn1_stringify_sector (RASN1Object *object) { case TAG_EOC: return NULL; case TAG_BOOLEAN: - return newstr (r_str_bool (object->sector[0])); + return newstr (rz_str_bool (object->sector[0])); case TAG_REAL: case TAG_INTEGER: if (object->length < 16) { - return r_asn1_stringify_integer (object->sector, object->length); + return rz_asn1_stringify_integer (object->sector, object->length); } else { - return r_asn1_stringify_bytes (object->sector, object->length); + return rz_asn1_stringify_bytes (object->sector, object->length); } case TAG_BITSTRING: //if (object->length < 8) { - return r_asn1_stringify_bits (object->sector, object->length); + return rz_asn1_stringify_bits (object->sector, object->length); //} else { // return asn1_stringify_bytes (object->sector, object->length); //} case TAG_OCTETSTRING: - return r_asn1_stringify_bytes (object->sector, object->length); + return rz_asn1_stringify_bytes (object->sector, object->length); case TAG_NULL: return NULL; case TAG_OID: - return r_asn1_stringify_oid (object->sector, object->length); + return rz_asn1_stringify_oid (object->sector, object->length); // case TAG_OBJDESCRIPTOR: // case TAG_EXTERNAL: // case TAG_ENUMERATED: @@ -396,11 +396,11 @@ R_API RASN1String *asn1_stringify_sector (RASN1Object *object) { // case TAG_VIDEOTEXSTRING: case TAG_IA5STRING: case TAG_VISIBLESTRING: - return r_asn1_stringify_string (object->sector, object->length); + return rz_asn1_stringify_string (object->sector, object->length); case TAG_UTCTIME: - return r_asn1_stringify_utctime (object->sector, object->length); + return rz_asn1_stringify_utctime (object->sector, object->length); case TAG_GENERALIZEDTIME: - return r_asn1_stringify_time (object->sector, object->length); + return rz_asn1_stringify_time (object->sector, object->length); // case TAG_GRAPHICSTRING: // case TAG_GENERALSTRING: // case TAG_UNIVERSALSTRING: diff --git a/libr/util/base85.c b/librz/util/base85.c similarity index 90% rename from libr/util/base85.c rename to librz/util/base85.c index a2b1d5b061..dd8e8b899e 100644 --- a/libr/util/base85.c +++ b/librz/util/base85.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include static int getc_nospace(FILE *f) { int c; @@ -68,14 +68,14 @@ static void encode_tuple(unsigned long tuple, int count, int wrap, int *plen, in } } -R_API void r_base85_decode_tuple(unsigned long tuple, int count) { +RZ_API void rz_base85_decode_tuple(unsigned long tuple, int count) { int i; for (i = 1; i < count; i++) { putchar(tuple >> ((4 - i) * 8)); } } -R_API void r_base85_encode(FILE *fp, int delims, int wrap, int y_abbr) { +RZ_API void rz_base85_encode(FILE *fp, int delims, int wrap, int y_abbr) { int c, count = 0, len = 0; unsigned long tuple = 0; if (delims) { @@ -105,7 +105,7 @@ R_API void r_base85_encode(FILE *fp, int delims, int wrap, int y_abbr) { } } -R_API bool r_base85_decode(FILE *fp, int delims, int ignore_garbage) { +RZ_API bool rz_base85_decode(FILE *fp, int delims, int ignore_garbage) { int c, count = 0, end = 0; unsigned long tuple = 0, pows[] = {85*85*85*85, 85*85*85, 85*85, 85, 1}; while (delims) { @@ -124,11 +124,11 @@ R_API bool r_base85_decode(FILE *fp, int delims, int ignore_garbage) { for (;;) { c = getc_nospace(fp); if (c == 'z' && count == 0) { - r_base85_decode_tuple (0, 5); + rz_base85_decode_tuple (0, 5); continue; } if (c == 'y' && count == 0) { - r_base85_decode_tuple (0x20202020, 5); + rz_base85_decode_tuple (0x20202020, 5); continue; } if (c == '~' && delims) { @@ -147,7 +147,7 @@ R_API bool r_base85_decode(FILE *fp, int delims, int ignore_garbage) { } if (count > 0) { tuple += pows[count-1]; - r_base85_decode_tuple(tuple, count); + rz_base85_decode_tuple(tuple, count); } break; } @@ -160,7 +160,7 @@ R_API bool r_base85_decode(FILE *fp, int delims, int ignore_garbage) { } tuple += (c - '!') * pows[count++]; if (count == 5) { - r_base85_decode_tuple(tuple, count); + rz_base85_decode_tuple(tuple, count); tuple = 0; count = 0; } diff --git a/libr/util/base91.c b/librz/util/base91.c similarity index 91% rename from libr/util/base91.c rename to librz/util/base91.c index b24134955e..49e49c18b3 100644 --- a/libr/util/base91.c +++ b/librz/util/base91.c @@ -1,6 +1,6 @@ #include -#include +#include static const char b91[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', @@ -22,7 +22,7 @@ int get_char_index(const char c) { return -1; } -R_API int r_base91_decode(ut8* bout, const char *bin, int len) { +RZ_API int rz_base91_decode(ut8* bout, const char *bin, int len) { int in, out; int v = -1; int b = 0; @@ -63,7 +63,7 @@ R_API int r_base91_decode(ut8* bout, const char *bin, int len) { return out; } -R_API int r_base91_encode(char *bout, const ut8 *bin, int len) { +RZ_API int rz_base91_encode(char *bout, const ut8 *bin, int len) { int in, out; int v = 0; int b = 0; diff --git a/libr/util/bdiff.c b/librz/util/bdiff.c similarity index 96% rename from libr/util/bdiff.c rename to librz/util/bdiff.c index 8c41c306f5..d6c3dffc11 100644 --- a/libr/util/bdiff.c +++ b/librz/util/bdiff.c @@ -11,8 +11,8 @@ Based roughly on Python difflib */ -#include -#include +#include +#include #include #include @@ -286,9 +286,9 @@ static struct hunklist diff(struct line *a, int an, struct line *b, int bn) } //-- -// TODO: implement the r_diff_lines // we need to implement r_file_line_at (file, off); -R_API int r_diff_buffers_delta(RDiff *d, const ut8 *sa, int la, const ut8 *sb, int lb) { - RDiffOp dop; +// TODO: implement the rz_diff_lines // we need to implement rz_file_line_at (file, off); +RZ_API int rz_diff_buffers_delta(RzDiff *d, const ut8 *sa, int la, const ut8 *sb, int lb) { + RzDiffOp dop; struct line *al = NULL; struct line *bl = NULL; struct hunklist l = { NULL, NULL }; diff --git a/librz/util/big-gmp.c b/librz/util/big-gmp.c new file mode 100644 index 0000000000..b47f3cb2bf --- /dev/null +++ b/librz/util/big-gmp.c @@ -0,0 +1,136 @@ +#include + +RZ_API RNumBig *rz_big_new(void) { + RNumBig *n = R_NEW (RNumBig); + if (n) { + mpz_init (*n); + } + return n; +} + +RZ_API void rz_big_free(RNumBig *b) { + mpz_clear (*b); + free (b); +} + +RZ_API void rz_big_init(RNumBig *b) { + mpz_init (*b); +} + +RZ_API void rz_big_fini(RNumBig *b) { + mpz_clear (*b); +} + +RZ_API void rz_big_from_int(RNumBig *b, st64 v) { + mpz_set_si (*b, v); +} + +RZ_API st64 rz_big_to_int(RNumBig *b) { + return mpz_get_si (*b); +} + +RZ_API void rz_big_from_hexstr(RNumBig *b, const char *str) { + if (rz_str_startswith (str, "0x")) { + str += 2; + mpz_set_str (*b, str, 16); + } else if (rz_str_startswith (str, "-0x")) { + str += 3; + mpz_set_str (*b, str, 16); + mpz_mul_si (*b, *b, -1); + } +} + +RZ_API char *rz_big_to_hexstr(RNumBig *b) { + char *tmp = mpz_get_str (NULL, 16, *b); + char *res; + if (tmp[0] == '-') { + res = rz_str_newf ("-0x%s", &tmp[1]); + } else { + res = rz_str_newf ("0x%s", tmp); + } + free (tmp); + return res; +} + +RZ_API void rz_big_assign(RNumBig *dst, RNumBig *src) { + mpz_set (*dst, *src); +} + +RZ_API void rz_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_add (*c, *a, *b); +} + +RZ_API void rz_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_sub (*c, *a, *b); +} + +RZ_API void rz_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_mul (*c, *a, *b); +} + +RZ_API void rz_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_tdiv_q (*c, *a, *b); +} + +RZ_API void rz_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_mod (*c, *a, *b); +} + +RZ_API void rz_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { + mpz_tdiv_qr (*c, *d, *a, *b); +} + +RZ_API void rz_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_and (*c, *a, *b); +} + +RZ_API void rz_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_ior (*c, *a, *b); +} + +RZ_API void rz_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { + mpz_xor (*c, *a, *b); +} + +RZ_API void rz_big_lshift(RNumBig *c, RNumBig *a, size_t nbits) { + mpz_mul_2exp (*c, *a, nbits); +} + +RZ_API void rz_big_rshift(RNumBig *c, RNumBig *a, size_t nbits) { + mpz_tdiv_q_2exp (*c, *a, nbits); +} + +RZ_API int rz_big_cmp(RNumBig *a, RNumBig *b) { + int res = mpz_cmp (*a, *b); + if (res > 0) { + return 1; + } else if (res < 0) { + return -1; + } else { + return 0; + } +} + +RZ_API int rz_big_is_zero(RNumBig *a) { + return mpz_cmp_ui (*a, 0) == 0; +} + +RZ_API void rz_big_inc(RNumBig *a) { + RNumBig tmp; + mpz_init_set_si (tmp, 1); + mpz_add (*a, *a, tmp); +} + +RZ_API void rz_big_dec(RNumBig *a) { + RNumBig tmp; + mpz_init_set_si (tmp, 1); + mpz_sub (*a, *a, tmp); +} + +RZ_API void rz_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { + mpz_powm (*c, *a, *b, *m); +} + +RZ_API void rz_big_isqrt(RNumBig *c, RNumBig *a) { + mpz_sqrt (*c, *a); +} diff --git a/librz/util/big-ssl.c b/librz/util/big-ssl.c new file mode 100644 index 0000000000..82ef0d396b --- /dev/null +++ b/librz/util/big-ssl.c @@ -0,0 +1,257 @@ +#include + +RZ_API RNumBig *rz_big_new(void) { + return BN_new (); +} + +RZ_API void rz_big_free(RNumBig *b) { + BN_free (b); +} + +RZ_API void rz_big_init(RNumBig *b) { + BN_zero (b); +} + +RZ_API void rz_big_fini(RNumBig *b) { + BN_clear (b); +} + +RZ_API void rz_big_from_int(RNumBig *b, st64 v) { + if (v < 0) { + BN_set_word (b, -v); + BN_set_negative (b, v); + } else { + BN_set_word (b, v); + } +} + +RZ_API st64 rz_big_to_int(RNumBig *b) { + BN_ULONG maxx = 0; + maxx = ~maxx; + BN_ULONG res = BN_get_word (b); + if (res == maxx) { + RNumBig *B = rz_big_new (); + rz_big_assign (B, b); + BN_mask_bits (B, BN_BYTES * 8 - 1); + res = BN_get_word (B); + rz_big_free (B); + } + res *= (BN_is_negative (b)? -1: 1); + return res; +} + +RZ_API void rz_big_from_hexstr(RNumBig *b, const char *str) { + if (rz_str_startswith (str, "0x")) { + str += 2; + BN_hex2bn (&b, str); + } else if (rz_str_startswith (str, "-0x")) { + str += 3; + BN_hex2bn (&b, str); + BN_set_negative (b, -1); + } +} + +RZ_API char *rz_big_to_hexstr(RNumBig *b) { + char *tmp = BN_bn2hex (b); + char *res; + if (tmp[0] == '-') { + res = rz_str_newf ("-0x%s", &tmp[1]); + } else { + res = rz_str_newf ("0x%s", tmp); + } + OPENSSL_free (tmp); + for (size_t i = 0; res[i]; i++) { + res[i] = tolower (res[i]); + } + return res; +} + +RZ_API void rz_big_assign(RNumBig *dst, RNumBig *src) { + BN_copy (dst, src); +} + +RZ_API void rz_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { + BN_add (c, a, b); +} + +RZ_API void rz_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { + BN_sub (c, a, b); +} + +RZ_API void rz_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { + BN_CTX *bn_ctx = BN_CTX_new (); + BN_mul (c, a, b, bn_ctx); + BN_CTX_free (bn_ctx); +} + +RZ_API void rz_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { + BN_CTX *bn_ctx = BN_CTX_new (); + BN_div (c, NULL, a, b, bn_ctx); + BN_CTX_free (bn_ctx); +} + +RZ_API void rz_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { + BN_CTX *bn_ctx = BN_CTX_new (); + BN_mod (c, a, b, bn_ctx); + BN_CTX_free (bn_ctx); +} + +RZ_API void rz_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { + BN_CTX *bn_ctx = BN_CTX_new (); + BN_div (c, d, a, b, bn_ctx); + BN_CTX_free (bn_ctx); +} + +RZ_API void rz_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { + RNumBig *A = rz_big_new (); + RNumBig *B = rz_big_new (); + RNumBig *C = rz_big_new (); + RNumBig *addition = rz_big_new (); + + size_t step = 4 * 8, move = 0; + ut32 tmp = 0; + rz_big_assign (A, a); + rz_big_assign (B, b); + + while (!rz_big_is_zero (A) || !rz_big_is_zero (B)) { + tmp = rz_big_to_int (A); + tmp &= rz_big_to_int (B); + rz_big_rshift (A, A, step); + rz_big_rshift (B, B, step); + rz_big_from_int (addition, tmp); + rz_big_lshift (addition, addition, move); + rz_big_add (C, C, addition); + + move += step; + } + + rz_big_assign (c, C); + + rz_big_free (A); + rz_big_free (B); + rz_big_free (C); + rz_big_free (addition); +} + +RZ_API void rz_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { + RNumBig *A = rz_big_new (); + RNumBig *B = rz_big_new (); + RNumBig *C = rz_big_new (); + RNumBig *addition = rz_big_new (); + + size_t step = 4 * 8, move = 0; + ut32 tmp = 0; + rz_big_assign (A, a); + rz_big_assign (B, b); + + while (!rz_big_is_zero (A) || !rz_big_is_zero (B)) { + tmp = rz_big_to_int (A); + tmp |= rz_big_to_int (B); + rz_big_rshift (A, A, step); + rz_big_rshift (B, B, step); + rz_big_from_int (addition, tmp); + rz_big_lshift (addition, addition, move); + rz_big_add (C, C, addition); + + move += step; + } + + rz_big_assign (c, C); + + rz_big_free (A); + rz_big_free (B); + rz_big_free (C); + rz_big_free (addition); +} + +RZ_API void rz_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { + RNumBig *A = rz_big_new (); + RNumBig *B = rz_big_new (); + RNumBig *C = rz_big_new (); + RNumBig *addition = rz_big_new (); + + size_t step = 4 * 8, move = 0; + ut32 tmp = 0; + rz_big_assign (A, a); + rz_big_assign (B, b); + + while (!rz_big_is_zero (A) || !rz_big_is_zero (B)) { + tmp = rz_big_to_int (A); + tmp ^= rz_big_to_int (B); + rz_big_rshift (A, A, step); + rz_big_rshift (B, B, step); + rz_big_from_int (addition, tmp); + rz_big_lshift (addition, addition, move); + rz_big_add (C, C, addition); + + move += step; + } + + rz_big_assign (c, C); + + rz_big_free (A); + rz_big_free (B); + rz_big_free (C); + rz_big_free (addition); +} + +RZ_API void rz_big_lshift(RNumBig *c, RNumBig *a, size_t nbits) { + BN_lshift (c, a, nbits); +} + +RZ_API void rz_big_rshift(RNumBig *c, RNumBig *a, size_t nbits) { + BN_rshift (c, a, nbits); +} + +RZ_API int rz_big_cmp(RNumBig *a, RNumBig *b) { + return BN_cmp (a, b); +} + +RZ_API int rz_big_is_zero(RNumBig *a) { + return BN_is_zero (a); +} + +RZ_API void rz_big_inc(RNumBig *a) { + BN_add_word (a, 1); +} + +RZ_API void rz_big_dec(RNumBig *a) { + BN_sub_word (a, 1); +} + +RZ_API void rz_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { + BN_CTX *bn_ctx = BN_CTX_new (); + BN_mod_exp (c, a, b, m, bn_ctx); + BN_CTX_free (bn_ctx); +} + +RZ_API void rz_big_isqrt(RNumBig *b, RNumBig *a) { + RNumBig *tmp = rz_big_new (); + RNumBig *low = rz_big_new (); + RNumBig *high = rz_big_new (); + RNumBig *mid = rz_big_new (); + + rz_big_assign (high, a); + rz_big_rshift (mid, high, 1); + rz_big_inc (mid); + + while (rz_big_cmp (high, low) > 0) { + rz_big_mul (tmp, mid, mid); + if (rz_big_cmp (tmp, a) > 0) { + rz_big_assign (high, mid); + rz_big_dec (high); + } else { + rz_big_assign (low, mid); + } + rz_big_sub (mid, high, low); + rz_big_rshift (mid, mid, 1); + rz_big_add (mid, mid, low); + rz_big_inc (mid); + } + rz_big_assign (b, low); + + rz_big_free (tmp); + rz_big_free (low); + rz_big_free (high); + rz_big_free (mid); +} diff --git a/libr/util/big.c b/librz/util/big.c similarity index 59% rename from libr/util/big.c rename to librz/util/big.c index e1db01bbca..0a7ef41f16 100644 --- a/libr/util/big.c +++ b/librz/util/big.c @@ -2,7 +2,7 @@ * Enjoy it --FXTi */ -#include +#include /* Functions for shifting number in-place. */ static void _lshift_one_bit(RNumBig *a); @@ -11,7 +11,7 @@ static void _lshift_word(RNumBig *a, int nwords); static void _rshift_word(RNumBig *a, int nwords); static void _r_big_zero_out(RNumBig *n); -R_API RNumBig *r_big_new(void) { +RZ_API RNumBig *rz_big_new(void) { RNumBig *n = R_NEW (RNumBig); if (n) { _r_big_zero_out (n); @@ -19,20 +19,20 @@ R_API RNumBig *r_big_new(void) { return n; } -R_API void r_big_free(RNumBig *b) { +RZ_API void rz_big_free(RNumBig *b) { free (b); } -R_API void r_big_init(RNumBig *b) { +RZ_API void rz_big_init(RNumBig *b) { _r_big_zero_out (b); } -R_API void r_big_fini(RNumBig *b) { +RZ_API void rz_big_fini(RNumBig *b) { _r_big_zero_out (b); } -R_API void r_big_from_int(RNumBig *b, st64 n) { - r_return_if_fail (b); +RZ_API void rz_big_from_int(RNumBig *b, st64 n) { + rz_return_if_fail (b); _r_big_zero_out (b); b->sign = (n < 0)? -1: 1; @@ -57,8 +57,8 @@ R_API void r_big_from_int(RNumBig *b, st64 n) { #endif } -static void r_big_from_unsigned(RNumBig *b, ut64 v) { - r_return_if_fail (b); +static void rz_big_from_unsigned(RNumBig *b, ut64 v) { + rz_return_if_fail (b); _r_big_zero_out (b); @@ -81,8 +81,8 @@ static void r_big_from_unsigned(RNumBig *b, ut64 v) { #endif } -R_API st64 r_big_to_int(RNumBig *b) { - r_return_val_if_fail (b, 0); +RZ_API st64 rz_big_to_int(RNumBig *b) { + rz_return_val_if_fail (b, 0); R_BIG_DTYPE_TMP ret = 0; @@ -107,9 +107,9 @@ R_API st64 r_big_to_int(RNumBig *b) { return ret; } -R_API void r_big_from_hexstr(RNumBig *n, const char *str) { - r_return_if_fail (n); - r_return_if_fail (str); +RZ_API void rz_big_from_hexstr(RNumBig *n, const char *str) { + rz_return_if_fail (n); + rz_return_if_fail (str); int nbytes = strlen (str); _r_big_zero_out (n); @@ -124,7 +124,7 @@ R_API void r_big_from_hexstr(RNumBig *n, const char *str) { str += 2; nbytes -= 2; } - r_return_if_fail (nbytes > 0); + rz_return_if_fail (nbytes > 0); R_BIG_DTYPE tmp; int i = nbytes - (2 * R_BIG_WORD_SIZE); /* index into string */ @@ -151,8 +151,8 @@ R_API void r_big_from_hexstr(RNumBig *n, const char *str) { } } -R_API char *r_big_to_hexstr(RNumBig *b) { - r_return_val_if_fail (b, NULL); +RZ_API char *rz_big_to_hexstr(RNumBig *b) { + rz_return_val_if_fail (b, NULL); int j = R_BIG_ARRAY_SIZE - 1; /* index into array - reading "MSB" first -> big-endian */ size_t i = 0; /* index into string representation. */ @@ -177,7 +177,7 @@ R_API char *r_big_to_hexstr(RNumBig *b) { ret_str[i++] = '0'; ret_str[i++] = 'x'; - r_snprintf (ret_str + i, R_BIG_FORMAT_STR_LEN, R_BIG_SPRINTF_FORMAT_STR, b->array[j--]); + rz_snprintf (ret_str + i, R_BIG_FORMAT_STR_LEN, R_BIG_SPRINTF_FORMAT_STR, b->array[j--]); for (; ret_str[i + k] == '0' && k < 2 * R_BIG_WORD_SIZE; k++) { } for (z = k; ret_str[i + z] && z < last_z; z++) { @@ -187,21 +187,21 @@ R_API char *r_big_to_hexstr(RNumBig *b) { ret_str[i] = '\x00'; // Truncate string for case(j < 0) for (; j >= 0; j--) { - r_snprintf (ret_str + i, R_BIG_FORMAT_STR_LEN, R_BIG_SPRINTF_FORMAT_STR, b->array[j]); + rz_snprintf (ret_str + i, R_BIG_FORMAT_STR_LEN, R_BIG_SPRINTF_FORMAT_STR, b->array[j]); i += 2 * R_BIG_WORD_SIZE; } return ret_str; } -R_API void r_big_assign(RNumBig *dst, RNumBig *src) { - r_return_if_fail (dst); - r_return_if_fail (src); +RZ_API void rz_big_assign(RNumBig *dst, RNumBig *src) { + rz_return_if_fail (dst); + rz_return_if_fail (src); memcpy (dst, src, sizeof (RNumBig)); } -static void r_big_add_inner(RNumBig *c, RNumBig *a, RNumBig *b) { +static void rz_big_add_inner(RNumBig *c, RNumBig *a, RNumBig *b) { R_BIG_DTYPE_TMP tmp; int carry = 0; int i; @@ -212,13 +212,13 @@ static void r_big_add_inner(RNumBig *c, RNumBig *a, RNumBig *b) { } } -static void r_big_sub_inner(RNumBig *c, RNumBig *a, RNumBig *b) { +static void rz_big_sub_inner(RNumBig *c, RNumBig *a, RNumBig *b) { R_BIG_DTYPE_TMP res; RNumBig *tmp; R_BIG_DTYPE_TMP tmp1; R_BIG_DTYPE_TMP tmp2; int borrow = 0; - int sign = r_big_cmp (a, b); + int sign = rz_big_cmp (a, b); c->sign = (sign >= 0? 1: -1); if (sign < 0) { tmp = a; @@ -236,64 +236,64 @@ static void r_big_sub_inner(RNumBig *c, RNumBig *a, RNumBig *b) { } } -R_API void r_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); +RZ_API void rz_big_add(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); if (a->sign >= 0 && b->sign >= 0) { - r_big_add_inner (c, a, b); + rz_big_add_inner (c, a, b); c->sign = 1; return; } if (a->sign >= 0 && b->sign < 0) { - r_big_sub_inner (c, a, b); + rz_big_sub_inner (c, a, b); return; } if (a->sign < 0 && b->sign >= 0) { - r_big_sub_inner (c, b, a); + rz_big_sub_inner (c, b, a); return; } if (a->sign < 0 && b->sign < 0) { - r_big_add_inner (c, a, b); + rz_big_add_inner (c, a, b); c->sign = -1; return; } } -R_API void r_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); +RZ_API void rz_big_sub(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); if (a->sign >= 0 && b->sign >= 0) { - r_big_sub_inner (c, a, b); + rz_big_sub_inner (c, a, b); return; } if (a->sign >= 0 && b->sign < 0) { - r_big_add_inner (c, a, b); + rz_big_add_inner (c, a, b); c->sign = 1; return; } if (a->sign < 0 && b->sign >= 0) { - r_big_add_inner (c, a, b); + rz_big_add_inner (c, a, b); c->sign = -1; return; } if (a->sign < 0 && b->sign < 0) { - r_big_sub_inner (c, b, a); + rz_big_sub_inner (c, b, a); return; } } -R_API void r_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); +RZ_API void rz_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); - RNumBig *row = r_big_new (); - RNumBig *tmp = r_big_new (); - RNumBig *res = r_big_new (); + RNumBig *row = rz_big_new (); + RNumBig *tmp = rz_big_new (); + RNumBig *res = rz_big_new (); int i, j; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { @@ -303,44 +303,44 @@ R_API void r_big_mul(RNumBig *c, RNumBig *a, RNumBig *b) { if (i + j < R_BIG_ARRAY_SIZE) { _r_big_zero_out (tmp); R_BIG_DTYPE_TMP intermediate = ((R_BIG_DTYPE_TMP)a->array[i] * (R_BIG_DTYPE_TMP)b->array[j]); - r_big_from_unsigned (tmp, intermediate); + rz_big_from_unsigned (tmp, intermediate); _lshift_word (tmp, i + j); - r_big_add (row, row, tmp); + rz_big_add (row, row, tmp); } } - r_big_add (res, row, res); + rz_big_add (res, row, res); } res->sign = a->sign * b->sign; - if (r_big_is_zero (res)) { + if (rz_big_is_zero (res)) { res->sign = 1; // For -1 * 0 case } - r_big_assign (c, res); + rz_big_assign (c, res); - r_big_free (row); - r_big_free (tmp); - r_big_free (res); + rz_big_free (row); + rz_big_free (tmp); + rz_big_free (res); } -R_API void r_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (!r_big_is_zero (b)); +RZ_API void rz_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (!rz_big_is_zero (b)); - RNumBig *current = r_big_new (); - RNumBig *denom = r_big_new (); + RNumBig *current = rz_big_new (); + RNumBig *denom = rz_big_new (); ; - RNumBig *tmp = r_big_new (); + RNumBig *tmp = rz_big_new (); int sign = a->sign * b->sign; - r_big_from_int (current, 1); // int current = 1; - r_big_assign (denom, b); // denom = b + rz_big_from_int (current, 1); // int current = 1; + rz_big_assign (denom, b); // denom = b denom->sign = 1; - r_big_assign (tmp, denom); // tmp = denom = b + rz_big_assign (tmp, denom); // tmp = denom = b _lshift_one_bit (tmp); // tmp <= 1 - while (r_big_cmp (tmp, a) != 1) { // while (tmp <= a) + while (rz_big_cmp (tmp, a) != 1) { // while (tmp <= a) if ((denom->array[R_BIG_ARRAY_SIZE - 1] >> (R_BIG_WORD_SIZE * 8 - 1)) == 1) { break; // Reach the max value } @@ -349,47 +349,47 @@ R_API void r_big_div(RNumBig *c, RNumBig *a, RNumBig *b) { _lshift_one_bit (current); // current <= 1 } - r_big_assign (tmp, a); // tmp = a + rz_big_assign (tmp, a); // tmp = a tmp->sign = 1; _r_big_zero_out (c); // int answer = 0; - while (!r_big_is_zero (current)) // while (current != 0) + while (!rz_big_is_zero (current)) // while (current != 0) { - if (r_big_cmp (tmp, denom) != -1) // if (dividend >= denom) + if (rz_big_cmp (tmp, denom) != -1) // if (dividend >= denom) { - r_big_sub (tmp, tmp, denom); // dividend -= denom; - r_big_or (c, current, c); // answer |= current; + rz_big_sub (tmp, tmp, denom); // dividend -= denom; + rz_big_or (c, current, c); // answer |= current; } _rshift_one_bit (current); // current >>= 1; _rshift_one_bit (denom); // denom >>= 1; } // return answer; c->sign = sign; - if (r_big_is_zero (c)) { + if (rz_big_is_zero (c)) { c->sign = 1; // For -1 * 0 case } - r_big_free (current); - r_big_free (denom); - r_big_free (tmp); + rz_big_free (current); + rz_big_free (denom); + rz_big_free (tmp); } -R_API void r_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { +RZ_API void rz_big_mod(RNumBig *c, RNumBig *a, RNumBig *b) { /* Take divmod and throw away div part */ - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (!r_big_is_zero (b)); + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (!rz_big_is_zero (b)); - RNumBig *tmp = r_big_new (); + RNumBig *tmp = rz_big_new (); - r_big_divmod (tmp, c, a, b); + rz_big_divmod (tmp, c, a, b); - r_big_free (tmp); + rz_big_free (tmp); } -R_API void r_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { +RZ_API void rz_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { /* Puts a%b in d and a/b in c @@ -399,31 +399,31 @@ R_API void r_big_divmod(RNumBig *c, RNumBig *d, RNumBig *a, RNumBig *b) { example: mod(8, 3) = 8 - ((8 / 3) * 3) = 2 */ - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (!r_big_is_zero (b)); + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (!rz_big_is_zero (b)); - RNumBig *tmp = r_big_new (); + RNumBig *tmp = rz_big_new (); /* c = (a / b) */ - r_big_div (c, a, b); + rz_big_div (c, a, b); /* tmp = (c * b) */ - r_big_mul (tmp, c, b); + rz_big_mul (tmp, c, b); /* d = a - tmp */ - r_big_sub (d, a, tmp); + rz_big_sub (d, a, tmp); - r_big_free (tmp); + rz_big_free (tmp); } -R_API void r_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (a->sign > 0); - r_return_if_fail (b->sign > 0); +RZ_API void rz_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (a->sign > 0); + rz_return_if_fail (b->sign > 0); int i; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { @@ -431,12 +431,12 @@ R_API void r_big_and(RNumBig *c, RNumBig *a, RNumBig *b) { } } -R_API void r_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (a->sign > 0); - r_return_if_fail (b->sign > 0); +RZ_API void rz_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (a->sign > 0); + rz_return_if_fail (b->sign > 0); int i; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { @@ -444,12 +444,12 @@ R_API void r_big_or(RNumBig *c, RNumBig *a, RNumBig *b) { } } -R_API void r_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (a->sign > 0); - r_return_if_fail (b->sign > 0); +RZ_API void rz_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (a->sign > 0); + rz_return_if_fail (b->sign > 0); int i; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { @@ -457,13 +457,13 @@ R_API void r_big_xor(RNumBig *c, RNumBig *a, RNumBig *b) { } } -R_API void r_big_lshift(RNumBig *b, RNumBig *a, size_t nbits) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (a->sign > 0); - r_return_if_fail (b->sign > 0); +RZ_API void rz_big_lshift(RNumBig *b, RNumBig *a, size_t nbits) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (a->sign > 0); + rz_return_if_fail (b->sign > 0); - r_big_assign (b, a); + rz_big_assign (b, a); /* Handle shift in multiples of word-size */ const int nbits_pr_word = (R_BIG_WORD_SIZE * 8); int nwords = nbits / nbits_pr_word; @@ -481,13 +481,13 @@ R_API void r_big_lshift(RNumBig *b, RNumBig *a, size_t nbits) { } } -R_API void r_big_rshift(RNumBig *b, RNumBig *a, size_t nbits) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (a->sign > 0); - r_return_if_fail (b->sign > 0); +RZ_API void rz_big_rshift(RNumBig *b, RNumBig *a, size_t nbits) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (a->sign > 0); + rz_return_if_fail (b->sign > 0); - r_big_assign (b, a); + rz_big_assign (b, a); /* Handle shift in multiples of word-size */ const int nbits_pr_word = (R_BIG_WORD_SIZE * 8); int nwords = nbits / nbits_pr_word; @@ -505,9 +505,9 @@ R_API void r_big_rshift(RNumBig *b, RNumBig *a, size_t nbits) { } } -R_API int r_big_cmp(RNumBig *a, RNumBig *b) { - r_return_val_if_fail (a, 0); - r_return_val_if_fail (b, 0); +RZ_API int rz_big_cmp(RNumBig *a, RNumBig *b) { + rz_return_val_if_fail (a, 0); + rz_return_val_if_fail (b, 0); if (a->sign != b->sign) return a->sign > 0? 1: -1; @@ -526,8 +526,8 @@ R_API int r_big_cmp(RNumBig *a, RNumBig *b) { return 0; } -R_API int r_big_is_zero(RNumBig *a) { - r_return_val_if_fail (a, -1); +RZ_API int rz_big_is_zero(RNumBig *a) { + rz_return_val_if_fail (a, -1); int i; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { @@ -539,93 +539,93 @@ R_API int r_big_is_zero(RNumBig *a) { return 1; } -R_API void r_big_inc(RNumBig *a) { - r_return_if_fail (a); - RNumBig *tmp = r_big_new (); +RZ_API void rz_big_inc(RNumBig *a) { + rz_return_if_fail (a); + RNumBig *tmp = rz_big_new (); - r_big_from_int (tmp, 1); - r_big_add (a, a, tmp); + rz_big_from_int (tmp, 1); + rz_big_add (a, a, tmp); - r_big_free (tmp); + rz_big_free (tmp); } -R_API void r_big_dec(RNumBig *a) { - r_return_if_fail (a); - RNumBig *tmp = r_big_new (); +RZ_API void rz_big_dec(RNumBig *a) { + rz_return_if_fail (a); + RNumBig *tmp = rz_big_new (); - r_big_from_int (tmp, 1); - r_big_sub (a, a, tmp); + rz_big_from_int (tmp, 1); + rz_big_sub (a, a, tmp); - r_big_free (tmp); + rz_big_free (tmp); } -R_API void r_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { - r_return_if_fail (a); - r_return_if_fail (b); - r_return_if_fail (c); - r_return_if_fail (m); +RZ_API void rz_big_powm(RNumBig *c, RNumBig *a, RNumBig *b, RNumBig *m) { + rz_return_if_fail (a); + rz_return_if_fail (b); + rz_return_if_fail (c); + rz_return_if_fail (m); - RNumBig *bcopy = r_big_new (); - RNumBig *acopy = r_big_new (); + RNumBig *bcopy = rz_big_new (); + RNumBig *acopy = rz_big_new (); - r_big_assign (bcopy, b); - r_big_assign (acopy, a); - r_big_mod (acopy, acopy, m); - r_big_from_int (c, 1); + rz_big_assign (bcopy, b); + rz_big_assign (acopy, a); + rz_big_mod (acopy, acopy, m); + rz_big_from_int (c, 1); - while (!r_big_is_zero (bcopy)) { - if (r_big_to_int (bcopy) % 2 == 1) { - r_big_mul (c, c, acopy); - r_big_mod (c, c, m); + while (!rz_big_is_zero (bcopy)) { + if (rz_big_to_int (bcopy) % 2 == 1) { + rz_big_mul (c, c, acopy); + rz_big_mod (c, c, m); } _rshift_one_bit (bcopy); - r_big_mul (acopy, acopy, acopy); - r_big_mod (acopy, acopy, m); + rz_big_mul (acopy, acopy, acopy); + rz_big_mod (acopy, acopy, m); } - r_big_free (bcopy); - r_big_free (acopy); + rz_big_free (bcopy); + rz_big_free (acopy); } -R_API void r_big_isqrt(RNumBig *b, RNumBig *a) { - r_return_if_fail (a); - r_return_if_fail (b); +RZ_API void rz_big_isqrt(RNumBig *b, RNumBig *a) { + rz_return_if_fail (a); + rz_return_if_fail (b); - RNumBig *tmp = r_big_new (); - RNumBig *low = r_big_new (); - RNumBig *high = r_big_new (); - RNumBig *mid = r_big_new (); + RNumBig *tmp = rz_big_new (); + RNumBig *low = rz_big_new (); + RNumBig *high = rz_big_new (); + RNumBig *mid = rz_big_new (); - r_big_assign (high, a); - r_big_rshift (mid, high, 1); - r_big_inc (mid); + rz_big_assign (high, a); + rz_big_rshift (mid, high, 1); + rz_big_inc (mid); - while (r_big_cmp (high, low) > 0) { - r_big_mul (tmp, mid, mid); - if (r_big_cmp (tmp, a) > 0) { - r_big_assign (high, mid); - r_big_dec (high); + while (rz_big_cmp (high, low) > 0) { + rz_big_mul (tmp, mid, mid); + if (rz_big_cmp (tmp, a) > 0) { + rz_big_assign (high, mid); + rz_big_dec (high); } else { - r_big_assign (low, mid); + rz_big_assign (low, mid); } - r_big_sub (mid, high, low); + rz_big_sub (mid, high, low); _rshift_one_bit (mid); - r_big_add (mid, mid, low); - r_big_inc (mid); + rz_big_add (mid, mid, low); + rz_big_inc (mid); } - r_big_assign (b, low); + rz_big_assign (b, low); - r_big_free (tmp); - r_big_free (low); - r_big_free (high); - r_big_free (mid); + rz_big_free (tmp); + rz_big_free (low); + rz_big_free (high); + rz_big_free (mid); } /* Private / Static functions. */ static void _rshift_word(RNumBig *a, int nwords) { /* Naive method: */ - r_return_if_fail (a); - r_return_if_fail (nwords >= 0); + rz_return_if_fail (a); + rz_return_if_fail (nwords >= 0); size_t i; if (nwords >= R_BIG_ARRAY_SIZE) { @@ -644,8 +644,8 @@ static void _rshift_word(RNumBig *a, int nwords) { } static void _lshift_word(RNumBig *a, int nwords) { - r_return_if_fail (a); - r_return_if_fail (nwords >= 0); + rz_return_if_fail (a); + rz_return_if_fail (nwords >= 0); int i; /* Shift whole words */ @@ -659,7 +659,7 @@ static void _lshift_word(RNumBig *a, int nwords) { } static void _lshift_one_bit(RNumBig *a) { - r_return_if_fail (a); + rz_return_if_fail (a); int i; for (i = (R_BIG_ARRAY_SIZE - 1); i > 0; i--) { @@ -669,7 +669,7 @@ static void _lshift_one_bit(RNumBig *a) { } static void _rshift_one_bit(RNumBig *a) { - r_return_if_fail (a); + rz_return_if_fail (a); int i; for (i = 0; i < (R_BIG_ARRAY_SIZE - 1); i++) { @@ -679,7 +679,7 @@ static void _rshift_one_bit(RNumBig *a) { } static void _r_big_zero_out(RNumBig *a) { - r_return_if_fail (a); + rz_return_if_fail (a); size_t i; for (i = 0; i < R_BIG_ARRAY_SIZE; i++) { diff --git a/librz/util/binheap.c b/librz/util/binheap.c new file mode 100644 index 0000000000..80b1304628 --- /dev/null +++ b/librz/util/binheap.c @@ -0,0 +1,65 @@ +/* rizin - LGPL - Copyright 2017-2018 - maskray */ + +#include "rz_binheap.h" + +static inline void _heap_down(RBinHeap *h, size_t i, void *x) { + size_t j; + for (; j = i * 2 + 1, j < h->a.v.len; i = j) { + if (j + 1 < h->a.v.len && h->cmp (rz_pvector_at (&h->a, j+1), rz_pvector_at (&h->a, j)) < 0) { + j++; + } + if (h->cmp (rz_pvector_at (&h->a, j), x) >= 0) { + break; + } + rz_pvector_set (&h->a, i, rz_pvector_at (&h->a, j)); + } + if (i < h->a.v.len) { + rz_pvector_set (&h->a, i, x); + } +} + +static inline void _heap_up(RBinHeap *h, size_t i, void *x) { + size_t j; + for (; i && (j = (i-1) >> 1, h->cmp (x, rz_pvector_at (&h->a, j)) < 0); i = j) { + rz_pvector_set (&h->a, i, rz_pvector_at (&h->a, j)); + } + rz_pvector_set (&h->a, i, x); +} + +RZ_API void rz_binheap_clear(RBinHeap *h) { + rz_pvector_clear (&h->a); +} + +RZ_API void rz_binheap_init(RBinHeap *h, RPVectorComparator cmp) { + rz_pvector_init (&h->a, NULL); + h->cmp = cmp; +} + +RZ_API void rz_binheap_free(RBinHeap *h) { + rz_binheap_clear (h); + free (h); +} + +RZ_API RBinHeap *rz_binheap_new(RPVectorComparator cmp) { + RBinHeap *h = R_NEW (RBinHeap); + if (!h) { + return NULL; + } + rz_pvector_init (&h->a, NULL); + h->cmp = cmp; + return h; +} + +RZ_API void *rz_binheap_pop(RBinHeap *h) { + void *ret = rz_pvector_at (&h->a, 0); + _heap_down (h, 0, rz_pvector_pop (&h->a)); + return ret; +} + +RZ_API bool rz_binheap_push(RBinHeap *h, void *x) { + if (!rz_pvector_push (&h->a, NULL)) { + return false; + } + _heap_up (h, h->a.v.len - 1, x); + return true; +} diff --git a/libr/util/bitmap.c b/librz/util/bitmap.c similarity index 75% rename from libr/util/bitmap.c rename to librz/util/bitmap.c index a503a3bd74..6b047136ac 100644 --- a/libr/util/bitmap.c +++ b/librz/util/bitmap.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2017-2020 - pancake, crowell */ -#include +#include #define BITMAP_TEST 0 @@ -11,7 +11,7 @@ #define BITMAP_WORD_COUNT(bit) (BITWORD_MULT(bit) >> BITWORD_BITS_SHIFT) -R_API RBitmap *r_bitmap_new(size_t len) { +RZ_API RBitmap *rz_bitmap_new(size_t len) { RBitmap *b = R_NEW0 (RBitmap); if (!b) { return NULL; @@ -21,33 +21,33 @@ R_API RBitmap *r_bitmap_new(size_t len) { return b; } -R_API void r_bitmap_set_bytes(RBitmap *b, const ut8 *buf, int len) { +RZ_API void rz_bitmap_set_bytes(RBitmap *b, const ut8 *buf, int len) { if (b->length < len) { len = b->length; } memcpy (b->bitmap, buf, len); } -R_API void r_bitmap_free(RBitmap *b) { +RZ_API void rz_bitmap_free(RBitmap *b) { free (b->bitmap); free (b); } -R_API void r_bitmap_set(RBitmap *b, size_t bit) { +RZ_API void rz_bitmap_set(RBitmap *b, size_t bit) { if (bit < b->length) { b->bitmap[(bit >> BITWORD_BITS_SHIFT)] |= ((RBitword)1 << (bit & BITWORD_BITS_MASK)); } } -R_API void r_bitmap_unset(RBitmap *b, size_t bit) { +RZ_API void rz_bitmap_unset(RBitmap *b, size_t bit) { if (bit < b->length) { b->bitmap[(bit >> BITWORD_BITS_SHIFT)] &= ~((RBitword)1 << (bit & BITWORD_BITS_MASK)); } } -R_API int r_bitmap_test(RBitmap *b, size_t bit) { +RZ_API int rz_bitmap_test(RBitmap *b, size_t bit) { if (bit < b->length) { RBitword bword = b->bitmap[ (bit >> BITWORD_BITS_SHIFT)]; return BITWORD_TEST (bword, (bit & BITWORD_BITS_MASK)); diff --git a/libr/util/buf.c b/librz/util/buf.c similarity index 51% rename from libr/util/buf.c rename to librz/util/buf.c index 806ccd9030..5595314192 100644 --- a/libr/util/buf.c +++ b/librz/util/buf.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc, pancake */ -#include -#include -#include +#include +#include +#include typedef enum { R_BUFFER_FILE, @@ -21,47 +21,47 @@ typedef enum { #include "buf_ref.c" static bool buf_init(RBuffer *b, const void *user) { - r_return_val_if_fail (b && b->methods, false); + rz_return_val_if_fail (b && b->methods, false); return b->methods->init? b->methods->init (b, user): true; } static bool buf_fini(RBuffer *b) { - r_return_val_if_fail (b && b->methods, false); + rz_return_val_if_fail (b && b->methods, false); return b->methods->fini? b->methods->fini (b): true; } static ut64 buf_get_size(RBuffer *b) { - r_return_val_if_fail (b && b->methods, UT64_MAX); + rz_return_val_if_fail (b && b->methods, UT64_MAX); return b->methods->get_size? b->methods->get_size (b): UT64_MAX; } static st64 buf_read(RBuffer *b, ut8 *buf, size_t len) { - r_return_val_if_fail (b && b->methods, -1); + rz_return_val_if_fail (b && b->methods, -1); return b->methods->read? b->methods->read (b, buf, len): -1; } static st64 buf_write(RBuffer *b, const ut8 *buf, size_t len) { - r_return_val_if_fail (b && b->methods, -1); + rz_return_val_if_fail (b && b->methods, -1); R_FREE (b->whole_buf); return b->methods->write? b->methods->write (b, buf, len): -1; } static st64 buf_seek(RBuffer *b, st64 addr, int whence) { - r_return_val_if_fail (b && b->methods, -1); + rz_return_val_if_fail (b && b->methods, -1); return b->methods->seek? b->methods->seek (b, addr, whence): -1; } static bool buf_resize(RBuffer *b, ut64 newsize) { - r_return_val_if_fail (b && b->methods, -1); + rz_return_val_if_fail (b && b->methods, -1); return b->methods->resize? b->methods->resize (b, newsize): false; } static ut8 *get_whole_buf(RBuffer *b, ut64 *sz) { - r_return_val_if_fail (b && b->methods, NULL); + rz_return_val_if_fail (b && b->methods, NULL); if (b->methods->get_whole_buf) { return b->methods->get_whole_buf (b, sz); } - ut64 bsz = r_buf_size (b); + ut64 bsz = rz_buf_size (b); // bsz = 4096; // FAKE MINIMUM SIZE TO READ THE BIN HEADER if (bsz == UT64_MAX) { return NULL; @@ -71,7 +71,7 @@ static ut8 *get_whole_buf(RBuffer *b, ut64 *sz) { if (!b->whole_buf) { return NULL; } - r_buf_read_at (b, 0, b->whole_buf, bsz); + rz_buf_read_at (b, 0, b->whole_buf, bsz); if (sz) { *sz = bsz; } @@ -103,7 +103,7 @@ static RBuffer *new_buffer(RBufferType type, const void *user) { b->methods = &buffer_ref_methods; break; default: - r_warn_if_reached (); + rz_warn_if_reached (); break; } if (!buf_init (b, user)) { @@ -116,17 +116,17 @@ static RBuffer *new_buffer(RBufferType type, const void *user) { // TODO: Optimize to use memcpy when buffers are not in range.. // check buf boundaries and offsets and use memcpy or memmove -// copied from libr/io/cache.c:r_io_cache_read +// copied from librz/io/cache.c:rz_io_cache_read // ret # of bytes copied -R_API RBuffer *r_buf_new_with_io(void *iob, int fd) { - r_return_val_if_fail (iob && fd >= 0, NULL); +RZ_API RBuffer *rz_buf_new_with_io(void *iob, int fd) { + rz_return_val_if_fail (iob && fd >= 0, NULL); struct buf_io_user u = { 0 }; - u.iob = (RIOBind *)iob; + u.iob = (RzIOBind *)iob; u.fd = fd; return new_buffer (R_BUFFER_IO, &u); } -R_API RBuffer *r_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal) { +RZ_API RBuffer *rz_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal) { struct buf_bytes_user u = { 0 }; u.data_steal = bytes; u.length = len; @@ -134,7 +134,7 @@ R_API RBuffer *r_buf_new_with_pointers(const ut8 *bytes, ut64 len, bool steal) { return new_buffer (R_BUFFER_BYTES, &u); } -R_API RBuffer *r_buf_new_empty(ut64 len) { +RZ_API RBuffer *rz_buf_new_empty(ut64 len) { ut8 *buf = R_NEWS0 (ut8, len); if (!buf) { return NULL; @@ -151,14 +151,14 @@ R_API RBuffer *r_buf_new_empty(ut64 len) { return res; } -R_API RBuffer *r_buf_new_with_bytes(const ut8 *bytes, ut64 len) { +RZ_API RBuffer *rz_buf_new_with_bytes(const ut8 *bytes, ut64 len) { struct buf_bytes_user u = { 0 }; u.data = bytes; u.length = len; return new_buffer (R_BUFFER_BYTES, &u); } -R_API RBuffer *r_buf_new_slice(RBuffer *b, ut64 offset, ut64 size) { +RZ_API RBuffer *rz_buf_new_slice(RBuffer *b, ut64 offset, ut64 size) { struct buf_ref_user u = { 0 }; u.parent = b; u.offset = offset; @@ -166,17 +166,17 @@ R_API RBuffer *r_buf_new_slice(RBuffer *b, ut64 offset, ut64 size) { return new_buffer (R_BUFFER_REF, &u); } -R_API RBuffer *r_buf_new_with_string(const char *msg) { - return r_buf_new_with_bytes ((const ut8 *)msg, (ut64)strlen (msg)); +RZ_API RBuffer *rz_buf_new_with_string(const char *msg) { + return rz_buf_new_with_bytes ((const ut8 *)msg, (ut64)strlen (msg)); } -R_API RBuffer *r_buf_new_with_buf(RBuffer *b) { +RZ_API RBuffer *rz_buf_new_with_buf(RBuffer *b) { ut64 sz = 0; - const ut8 *tmp = r_buf_data (b, &sz); - return r_buf_new_with_bytes (tmp, sz); + const ut8 *tmp = rz_buf_data (b, &sz); + return rz_buf_new_with_bytes (tmp, sz); } -R_API RBuffer *r_buf_new_sparse(ut8 Oxff) { +RZ_API RBuffer *rz_buf_new_sparse(ut8 Oxff) { RBuffer *b = new_buffer (R_BUFFER_SPARSE, NULL); if (b) { b->Oxff_priv = Oxff; @@ -184,34 +184,34 @@ R_API RBuffer *r_buf_new_sparse(ut8 Oxff) { return b; } -R_API RBuffer *r_buf_new(void) { +RZ_API RBuffer *rz_buf_new(void) { struct buf_bytes_user u = { 0 }; u.data = NULL; u.length = 0; return new_buffer (R_BUFFER_BYTES, &u); } -R_DEPRECATE R_API const ut8 *r_buf_data(RBuffer *b, ut64 *size) { - r_return_val_if_fail (b, NULL); +R_DEPRECATE RZ_API const ut8 *rz_buf_data(RBuffer *b, ut64 *size) { + rz_return_val_if_fail (b, NULL); b->whole_buf = get_whole_buf (b, size); return b->whole_buf; } -R_API ut64 r_buf_size(RBuffer *b) { - r_return_val_if_fail (b, 0); +RZ_API ut64 rz_buf_size(RBuffer *b) { + rz_return_val_if_fail (b, 0); return buf_get_size (b); } // rename to new? -R_API RBuffer *r_buf_new_mmap(const char *filename, int perm) { - r_return_val_if_fail (filename, NULL); +RZ_API RBuffer *rz_buf_new_mmap(const char *filename, int perm) { + rz_return_val_if_fail (filename, NULL); struct buf_mmap_user u = { 0 }; u.filename = filename; u.perm = perm; return new_buffer (R_BUFFER_MMAP, &u); } -R_API RBuffer *r_buf_new_file(const char *file, int perm, int mode) { +RZ_API RBuffer *rz_buf_new_file(const char *file, int perm, int mode) { struct buf_file_user u = { 0 }; u.file = file; u.perm = perm; @@ -220,9 +220,9 @@ R_API RBuffer *r_buf_new_file(const char *file, int perm, int mode) { } // TODO: rename to new_from_file ? -R_API RBuffer *r_buf_new_slurp(const char *file) { +RZ_API RBuffer *rz_buf_new_slurp(const char *file) { size_t len; - char *tmp = r_file_slurp (file, &len); + char *tmp = rz_file_slurp (file, &len); if (!tmp) { return NULL; } @@ -234,51 +234,51 @@ R_API RBuffer *r_buf_new_slurp(const char *file) { return new_buffer (R_BUFFER_BYTES, &u); } -R_API bool r_buf_dump(RBuffer *b, const char *file) { +RZ_API bool rz_buf_dump(RBuffer *b, const char *file) { // TODO: need to redo this if (!b || !file) { return false; } ut64 tmpsz = 0; - const ut8 *tmp = r_buf_data (b, &tmpsz); - return r_file_dump (file, tmp, tmpsz, 0); + const ut8 *tmp = rz_buf_data (b, &tmpsz); + return rz_file_dump (file, tmp, tmpsz, 0); } -R_API st64 r_buf_seek(RBuffer *b, st64 addr, int whence) { - r_return_val_if_fail (b, -1); +RZ_API st64 rz_buf_seek(RBuffer *b, st64 addr, int whence) { + rz_return_val_if_fail (b, -1); return buf_seek (b, addr, whence); } -R_API ut64 r_buf_tell(RBuffer *b) { - return r_buf_seek (b, 0, R_BUF_CUR); +RZ_API ut64 rz_buf_tell(RBuffer *b) { + return rz_buf_seek (b, 0, R_BUF_CUR); } -R_API bool r_buf_set_bytes(RBuffer *b, const ut8 *buf, ut64 length) { - r_return_val_if_fail (b && buf && !b->readonly, false); - if (!r_buf_resize (b, 0)) { +RZ_API bool rz_buf_set_bytes(RBuffer *b, const ut8 *buf, ut64 length) { + rz_return_val_if_fail (b && buf && !b->readonly, false); + if (!rz_buf_resize (b, 0)) { return false; } - if (r_buf_seek (b, 0, R_BUF_SET) < 0) { + if (rz_buf_seek (b, 0, R_BUF_SET) < 0) { return false; } - if (!r_buf_append_bytes (b, buf, length)) { + if (!rz_buf_append_bytes (b, buf, length)) { return false; } - return r_buf_seek (b, 0, R_BUF_SET) >= 0; + return rz_buf_seek (b, 0, R_BUF_SET) >= 0; } -R_API bool r_buf_prepend_bytes(RBuffer *b, const ut8 *buf, ut64 length) { - r_return_val_if_fail (b && buf && !b->readonly, false); - return r_buf_insert_bytes (b, 0, buf, length) >= 0; +RZ_API bool rz_buf_prepend_bytes(RBuffer *b, const ut8 *buf, ut64 length) { + rz_return_val_if_fail (b && buf && !b->readonly, false); + return rz_buf_insert_bytes (b, 0, buf, length) >= 0; } -R_API char *r_buf_to_string(RBuffer *b) { - ut64 sz = r_buf_size (b); +RZ_API char *rz_buf_to_string(RBuffer *b) { + ut64 sz = rz_buf_size (b); char *s = malloc (sz + 1); if (!s) { return NULL; } - if (r_buf_read_at (b, 0, (ut8 *)s, sz) < 0) { + if (rz_buf_read_at (b, 0, (ut8 *)s, sz) < 0) { free (s); return NULL; } @@ -286,104 +286,104 @@ R_API char *r_buf_to_string(RBuffer *b) { return s; } -R_API bool r_buf_append_bytes(RBuffer *b, const ut8 *buf, ut64 length) { - r_return_val_if_fail (b && buf && !b->readonly, false); +RZ_API bool rz_buf_append_bytes(RBuffer *b, const ut8 *buf, ut64 length) { + rz_return_val_if_fail (b && buf && !b->readonly, false); - if (r_buf_seek (b, 0, R_BUF_END) < 0) { + if (rz_buf_seek (b, 0, R_BUF_END) < 0) { return false; } - return r_buf_write (b, buf, length) >= 0; + return rz_buf_write (b, buf, length) >= 0; } -R_API bool r_buf_append_nbytes(RBuffer *b, ut64 length) { - r_return_val_if_fail (b && !b->readonly, false); +RZ_API bool rz_buf_append_nbytes(RBuffer *b, ut64 length) { + rz_return_val_if_fail (b && !b->readonly, false); ut8 *buf = R_NEWS0 (ut8, length); if (!buf) { return false; } - bool res = r_buf_append_bytes (b, buf, length); + bool res = rz_buf_append_bytes (b, buf, length); free (buf); return res; } -R_API st64 r_buf_insert_bytes(RBuffer *b, ut64 addr, const ut8 *buf, ut64 length) { - r_return_val_if_fail (b && !b->readonly, -1); - st64 pos, r = r_buf_seek (b, 0, R_BUF_CUR); +RZ_API st64 rz_buf_insert_bytes(RBuffer *b, ut64 addr, const ut8 *buf, ut64 length) { + rz_return_val_if_fail (b && !b->readonly, -1); + st64 pos, r = rz_buf_seek (b, 0, R_BUF_CUR); if (r < 0) { return r; } pos = r; - r = r_buf_seek (b, addr, R_BUF_SET); + r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { goto restore_pos; } - ut64 sz = r_buf_size (b); + ut64 sz = rz_buf_size (b); ut8 *tmp = R_NEWS (ut8, sz - addr); - r = r_buf_read (b, tmp, sz - addr); + r = rz_buf_read (b, tmp, sz - addr); if (r < 0) { goto free_tmp; } st64 tmp_length = r; - if (!r_buf_resize (b, sz + length)) { + if (!rz_buf_resize (b, sz + length)) { goto free_tmp; } - r = r_buf_seek (b, addr + length, R_BUF_SET); + r = rz_buf_seek (b, addr + length, R_BUF_SET); if (r < 0) { goto free_tmp; } - r = r_buf_write (b, tmp, tmp_length); + r = rz_buf_write (b, tmp, tmp_length); if (r < 0) { goto free_tmp; } - r = r_buf_seek (b, addr, R_BUF_SET); + r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { goto free_tmp; } - r = r_buf_write (b, buf, length); + r = rz_buf_write (b, buf, length); free_tmp: free (tmp); restore_pos: - r_buf_seek (b, pos, R_BUF_SET); + rz_buf_seek (b, pos, R_BUF_SET); return r; } -R_API bool r_buf_append_ut16(RBuffer *b, ut16 n) { - r_return_val_if_fail (b && !b->readonly, false); - return r_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); +RZ_API bool rz_buf_append_ut16(RBuffer *b, ut16 n) { + rz_return_val_if_fail (b && !b->readonly, false); + return rz_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); } -R_API bool r_buf_append_ut32(RBuffer *b, ut32 n) { - r_return_val_if_fail (b && !b->readonly, false); - return r_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); +RZ_API bool rz_buf_append_ut32(RBuffer *b, ut32 n) { + rz_return_val_if_fail (b && !b->readonly, false); + return rz_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); } -R_API bool r_buf_append_ut64(RBuffer *b, ut64 n) { - r_return_val_if_fail (b && !b->readonly, false); - return r_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); +RZ_API bool rz_buf_append_ut64(RBuffer *b, ut64 n) { + rz_return_val_if_fail (b && !b->readonly, false); + return rz_buf_append_bytes (b, (const ut8 *)&n, sizeof (n)); } -R_API bool r_buf_append_buf(RBuffer *b, RBuffer *a) { - r_return_val_if_fail (b && a && !b->readonly, false); +RZ_API bool rz_buf_append_buf(RBuffer *b, RBuffer *a) { + rz_return_val_if_fail (b && a && !b->readonly, false); ut64 sz = 0; - const ut8 *tmp = r_buf_data (a, &sz); - return r_buf_append_bytes (b, tmp, sz); + const ut8 *tmp = rz_buf_data (a, &sz); + return rz_buf_append_bytes (b, tmp, sz); } -R_API bool r_buf_append_buf_slice(RBuffer *b, RBuffer *a, ut64 offset, ut64 size) { - r_return_val_if_fail (b && a && !b->readonly, false); +RZ_API bool rz_buf_append_buf_slice(RBuffer *b, RBuffer *a, ut64 offset, ut64 size) { + rz_return_val_if_fail (b && a && !b->readonly, false); ut8 *tmp = R_NEWS (ut8, size); bool res = false; if (!tmp) { return false; } - st64 r = r_buf_read_at (a, offset, tmp, size); + st64 r = rz_buf_read_at (a, offset, tmp, size); if (r < 0) { goto err; } - res = r_buf_append_bytes (b, tmp, r); + res = rz_buf_append_bytes (b, tmp, r); err: free (tmp); return res; @@ -392,14 +392,14 @@ err: // return an heap-allocated string read from the RBuffer b at address addr. The // length depends on the first '\0' found in the buffer. If there is no '\0' in // the buffer, there is no string, thus NULL is returned. -R_API char *r_buf_get_string(RBuffer *b, ut64 addr) { +RZ_API char *rz_buf_get_string(RBuffer *b, ut64 addr) { const int MIN_RES_SZ = 64; ut8 *res = R_NEWS (ut8, MIN_RES_SZ + 1); ut64 sz = 0; - st64 r = r_buf_read_at (b, addr, res, MIN_RES_SZ); + st64 r = rz_buf_read_at (b, addr, res, MIN_RES_SZ); bool null_found = false; while (r > 0) { - const ut8 *needle = r_mem_mem (res + sz, r, (ut8 *)"\x00", 1); + const ut8 *needle = rz_mem_mem (res + sz, r, (ut8 *)"\x00", 1); if (needle) { sz += (needle - (res + sz)); null_found = true; @@ -414,7 +414,7 @@ R_API char *r_buf_get_string(RBuffer *b, ut64 addr) { return NULL; } res = restmp; - r = r_buf_read_at (b, addr, res + sz, MIN_RES_SZ); + r = rz_buf_read_at (b, addr, res + sz, MIN_RES_SZ); } if (r < 0 || !null_found) { free (res); @@ -423,8 +423,8 @@ R_API char *r_buf_get_string(RBuffer *b, ut64 addr) { return (char *)res; } -R_API st64 r_buf_read(RBuffer *b, ut8 *buf, ut64 len) { - r_return_val_if_fail (b && buf, -1); +RZ_API st64 rz_buf_read(RBuffer *b, ut8 *buf, ut64 len) { + rz_return_val_if_fail (b && buf, -1); st64 r = buf_read (b, buf, len); if (r >= 0 && r < len) { memset (buf + r, b->Oxff_priv, len - r); @@ -432,20 +432,20 @@ R_API st64 r_buf_read(RBuffer *b, ut8 *buf, ut64 len) { return r; } -R_API st64 r_buf_write(RBuffer *b, const ut8 *buf, ut64 len) { - r_return_val_if_fail (b && buf && !b->readonly, -1); +RZ_API st64 rz_buf_write(RBuffer *b, const ut8 *buf, ut64 len) { + rz_return_val_if_fail (b && buf && !b->readonly, -1); return buf_write (b, buf, len); } -R_API ut8 r_buf_read8(RBuffer *b) { +RZ_API ut8 rz_buf_read8(RBuffer *b) { ut8 res; - st64 r = r_buf_read (b, &res, sizeof (res)); + st64 r = rz_buf_read (b, &res, sizeof (res)); return r == sizeof (res)? res: b->Oxff_priv; } -R_API ut8 r_buf_read8_at(RBuffer *b, ut64 addr) { +RZ_API ut8 rz_buf_read8_at(RBuffer *b, ut64 addr) { ut8 res; - st64 r = r_buf_read_at (b, addr, &res, sizeof (res)); + st64 r = rz_buf_read_at (b, addr, &res, sizeof (res)); return r == sizeof (res)? res: b->Oxff_priv; } @@ -471,7 +471,7 @@ static st64 buf_format(RBuffer *dst, RBuffer *src, const char *fmt, int n) { case '8': case '9': if (m == 1) { - m = r_num_get (NULL, &fmt[j]); + m = rz_num_get (NULL, &fmt[j]); } continue; case 's': tsize = 2; bigendian = false; break; @@ -491,27 +491,27 @@ static st64 buf_format(RBuffer *dst, RBuffer *src, const char *fmt, int n) { ut16 d2; ut32 d3; ut64 d4; - st64 r = r_buf_read (src, tmp, tsize); + st64 r = rz_buf_read (src, tmp, tsize); if (r < tsize) { return -1; } switch (tsize) { case 1: - d1 = r_read_ble8 (tmp); - r = r_buf_write (dst, (ut8 *)&d1, 1); + d1 = rz_read_ble8 (tmp); + r = rz_buf_write (dst, (ut8 *)&d1, 1); break; case 2: - d2 = r_read_ble16 (tmp, bigendian); - r = r_buf_write (dst, (ut8 *)&d2, 2); + d2 = rz_read_ble16 (tmp, bigendian); + r = rz_buf_write (dst, (ut8 *)&d2, 2); break; case 4: - d3 = r_read_ble32 (tmp, bigendian); - r = r_buf_write (dst, (ut8 *)&d3, 4); + d3 = rz_read_ble32 (tmp, bigendian); + r = rz_buf_write (dst, (ut8 *)&d3, 4); break; case 8: - d4 = r_read_ble64 (tmp, bigendian); - r = r_buf_write (dst, (ut8 *)&d4, 8); + d4 = rz_read_ble64 (tmp, bigendian); + r = rz_buf_write (dst, (ut8 *)&d4, 8); break; } if (r < 0) { @@ -527,75 +527,75 @@ static st64 buf_format(RBuffer *dst, RBuffer *src, const char *fmt, int n) { return res; } -R_API st64 r_buf_fread(RBuffer *b, ut8 *buf, const char *fmt, int n) { - r_return_val_if_fail (b && buf && fmt, -1); +RZ_API st64 rz_buf_fread(RBuffer *b, ut8 *buf, const char *fmt, int n) { + rz_return_val_if_fail (b && buf && fmt, -1); // XXX: we assume the caller knows what he's doing - RBuffer *dst = r_buf_new_with_pointers (buf, UT64_MAX, false); + RBuffer *dst = rz_buf_new_with_pointers (buf, UT64_MAX, false); st64 res = buf_format (dst, b, fmt, n); - r_buf_free (dst); + rz_buf_free (dst); return res; } -R_API st64 r_buf_fread_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n) { - r_return_val_if_fail (b && buf && fmt, -1); - st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR); - int r = r_buf_seek (b, addr, R_BUF_SET); +RZ_API st64 rz_buf_fread_at(RBuffer *b, ut64 addr, ut8 *buf, const char *fmt, int n) { + rz_return_val_if_fail (b && buf && fmt, -1); + st64 o_addr = rz_buf_seek (b, 0, R_BUF_CUR); + int r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { return r; } - r = r_buf_fread (b, buf, fmt, n); - r_buf_seek (b, o_addr, R_BUF_SET); + r = rz_buf_fread (b, buf, fmt, n); + rz_buf_seek (b, o_addr, R_BUF_SET); return r; } -R_API st64 r_buf_fwrite(RBuffer *b, const ut8 *buf, const char *fmt, int n) { - r_return_val_if_fail (b && buf && fmt && !b->readonly, -1); +RZ_API st64 rz_buf_fwrite(RBuffer *b, const ut8 *buf, const char *fmt, int n) { + rz_return_val_if_fail (b && buf && fmt && !b->readonly, -1); // XXX: we assume the caller knows what he's doing - RBuffer *src = r_buf_new_with_pointers (buf, UT64_MAX, false); + RBuffer *src = rz_buf_new_with_pointers (buf, UT64_MAX, false); st64 res = buf_format (b, src, fmt, n); - r_buf_free (src); + rz_buf_free (src); return res; } -R_API st64 r_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fmt, int n) { - r_return_val_if_fail (b && buf && fmt && !b->readonly, -1); - st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR); - st64 r = r_buf_seek (b, addr, R_BUF_SET); +RZ_API st64 rz_buf_fwrite_at(RBuffer *b, ut64 addr, const ut8 *buf, const char *fmt, int n) { + rz_return_val_if_fail (b && buf && fmt && !b->readonly, -1); + st64 o_addr = rz_buf_seek (b, 0, R_BUF_CUR); + st64 r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { return r; } - r = r_buf_fwrite (b, buf, fmt, n); - r_buf_seek (b, o_addr, R_BUF_SET); + r = rz_buf_fwrite (b, buf, fmt, n); + rz_buf_seek (b, o_addr, R_BUF_SET); return r; } -R_API st64 r_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len) { - r_return_val_if_fail (b && buf, -1); - st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR); - st64 r = r_buf_seek (b, addr, R_BUF_SET); +RZ_API st64 rz_buf_read_at(RBuffer *b, ut64 addr, ut8 *buf, ut64 len) { + rz_return_val_if_fail (b && buf, -1); + st64 o_addr = rz_buf_seek (b, 0, R_BUF_CUR); + st64 r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { return r; } - r = r_buf_read (b, buf, len); - r_buf_seek (b, o_addr, R_BUF_SET); + r = rz_buf_read (b, buf, len); + rz_buf_seek (b, o_addr, R_BUF_SET); return r; } -R_API st64 r_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, ut64 len) { - r_return_val_if_fail (b && buf && !b->readonly, -1); - st64 o_addr = r_buf_seek (b, 0, R_BUF_CUR); - st64 r = r_buf_seek (b, addr, R_BUF_SET); +RZ_API st64 rz_buf_write_at(RBuffer *b, ut64 addr, const ut8 *buf, ut64 len) { + rz_return_val_if_fail (b && buf && !b->readonly, -1); + st64 o_addr = rz_buf_seek (b, 0, R_BUF_CUR); + st64 r = rz_buf_seek (b, addr, R_BUF_SET); if (r < 0) { return r; } - r = r_buf_write (b, buf, len); - r_buf_seek (b, o_addr, R_BUF_SET); + r = rz_buf_write (b, buf, len); + rz_buf_seek (b, o_addr, R_BUF_SET); return r; } -R_API bool r_buf_fini(RBuffer *b) { +RZ_API bool rz_buf_fini(RBuffer *b) { if (!b) { return false; } @@ -615,39 +615,39 @@ R_API bool r_buf_fini(RBuffer *b) { return buf_fini (b); } -R_API void r_buf_free(RBuffer *b) { - if (r_buf_fini (b)) { +RZ_API void rz_buf_free(RBuffer *b) { + if (rz_buf_fini (b)) { free (b); } } -R_API st64 r_buf_append_string(RBuffer *b, const char *str) { - r_return_val_if_fail (b && str && !b->readonly, false); - return r_buf_append_bytes (b, (const ut8 *)str, strlen (str)); +RZ_API st64 rz_buf_append_string(RBuffer *b, const char *str) { + rz_return_val_if_fail (b && str && !b->readonly, false); + return rz_buf_append_bytes (b, (const ut8 *)str, strlen (str)); } -R_API bool r_buf_resize(RBuffer *b, ut64 newsize) { - r_return_val_if_fail (b, false); +RZ_API bool rz_buf_resize(RBuffer *b, ut64 newsize) { + rz_return_val_if_fail (b, false); return buf_resize (b, newsize); } -R_API RBuffer *r_buf_ref(RBuffer *b) { +RZ_API RBuffer *rz_buf_ref(RBuffer *b) { if (b) { b->refctr++; } return b; } -R_API RList *r_buf_nonempty_list(RBuffer *b) { +RZ_API RzList *rz_buf_nonempty_list(RBuffer *b) { return b->methods->nonempty_list? b->methods->nonempty_list (b): NULL; } -R_API st64 r_buf_uleb128(RBuffer *b, ut64 *v) { +RZ_API st64 rz_buf_uleb128(RBuffer *b, ut64 *v) { ut8 c = 0xff; ut64 s = 0, sum = 0, l = 0; do { ut8 data; - st64 r = r_buf_read (b, &data, sizeof (data)); + st64 r = rz_buf_read (b, &data, sizeof (data)); if (r <= 0) { return -1; } @@ -666,12 +666,12 @@ R_API st64 r_buf_uleb128(RBuffer *b, ut64 *v) { return l; } -R_API st64 r_buf_sleb128(RBuffer *b, st64 *v) { +RZ_API st64 rz_buf_sleb128(RBuffer *b, st64 *v) { st64 result = 0, offset = 0; ut8 value; do { st64 chunk; - st64 r = r_buf_read (b, &value, sizeof (value)); + st64 r = rz_buf_read (b, &value, sizeof (value)); if (r != sizeof (value)) { return -1; } diff --git a/libr/util/buf_bytes.c b/librz/util/buf_bytes.c similarity index 96% rename from libr/util/buf_bytes.c rename to librz/util/buf_bytes.c index 623107c2e0..428121f47f 100644 --- a/libr/util/buf_bytes.c +++ b/librz/util/buf_bytes.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include +#include struct buf_bytes_user { const ut8 *data; @@ -18,7 +18,7 @@ struct buf_bytes_priv { static inline struct buf_bytes_priv *get_priv_bytes(RBuffer *b) { struct buf_bytes_priv *priv = (struct buf_bytes_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -83,7 +83,7 @@ static st64 buf_bytes_read(RBuffer *b, ut8 *buf, ut64 len) { static st64 buf_bytes_write(RBuffer *b, const ut8 *buf, ut64 len) { struct buf_bytes_priv *priv = get_priv_bytes (b); if (priv->offset > priv->length || priv->offset + len >= priv->length) { - bool r = r_buf_resize (b, priv->offset + len); + bool r = rz_buf_resize (b, priv->offset + len); if (!r) { return -1; } @@ -115,7 +115,7 @@ static st64 buf_bytes_seek(RBuffer *b, st64 addr, int whence) { priv->offset = priv->length + addr; break; default: - r_warn_if_reached (); + rz_warn_if_reached (); return -1; } return priv->offset; diff --git a/libr/util/buf_file.c b/librz/util/buf_file.c similarity index 77% rename from libr/util/buf_file.c rename to librz/util/buf_file.c index aa5efac2e0..c85c21a1a1 100644 --- a/libr/util/buf_file.c +++ b/librz/util/buf_file.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include -#include +#include +#include struct buf_file_user { const char *file; @@ -16,7 +16,7 @@ struct buf_file_priv { static inline struct buf_file_priv *get_priv_file(RBuffer *b) { struct buf_file_priv *priv = (struct buf_file_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -26,7 +26,7 @@ static bool buf_file_init(RBuffer *b, const void *user) { if (!priv) { return false; } - int fd = r_sandbox_open (u->file, u->perm, u->mode); + int fd = rz_sandbox_open (u->file, u->perm, u->mode); if (fd == -1) { free (priv); return false; @@ -38,27 +38,27 @@ static bool buf_file_init(RBuffer *b, const void *user) { static bool buf_file_fini(RBuffer *b) { struct buf_file_priv *priv = get_priv_file (b); - r_sandbox_close (priv->fd); + rz_sandbox_close (priv->fd); R_FREE (b->priv); return true; } static ut64 buf_file_get_size(RBuffer *b) { struct buf_file_priv *priv = get_priv_file (b); - int pos = r_sandbox_lseek (priv->fd, 0, SEEK_CUR); - int res = r_sandbox_lseek (priv->fd, 0, SEEK_END); - r_sandbox_lseek (priv->fd, pos, SEEK_SET); + int pos = rz_sandbox_lseek (priv->fd, 0, SEEK_CUR); + int res = rz_sandbox_lseek (priv->fd, 0, SEEK_END); + rz_sandbox_lseek (priv->fd, pos, SEEK_SET); return (ut64)res; } static st64 buf_file_read(RBuffer *b, ut8 *buf, ut64 len) { struct buf_file_priv *priv = get_priv_file (b); - return r_sandbox_read (priv->fd, buf, len); + return rz_sandbox_read (priv->fd, buf, len); } static st64 buf_file_write(RBuffer *b, const ut8 *buf, ut64 len) { struct buf_file_priv *priv = get_priv_file (b); - return r_sandbox_write (priv->fd, buf, len); + return rz_sandbox_write (priv->fd, buf, len); } static st64 buf_file_seek(RBuffer *b, st64 addr, int whence) { @@ -68,12 +68,12 @@ static st64 buf_file_seek(RBuffer *b, st64 addr, int whence) { case R_BUF_SET: whence = SEEK_SET; break; case R_BUF_END: whence = SEEK_END; break; } - return r_sandbox_lseek (priv->fd, addr, whence); + return rz_sandbox_lseek (priv->fd, addr, whence); } static bool buf_file_resize(RBuffer *b, ut64 newsize) { struct buf_file_priv *priv = get_priv_file (b); - return r_sandbox_truncate (priv->fd, newsize) >= 0; + return rz_sandbox_truncate (priv->fd, newsize) >= 0; } static const RBufferMethods buffer_file_methods = { diff --git a/libr/util/buf_io.c b/librz/util/buf_io.c similarity index 94% rename from libr/util/buf_io.c rename to librz/util/buf_io.c index 96a4f705f1..64cb2faff0 100644 --- a/libr/util/buf_io.c +++ b/librz/util/buf_io.c @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include -#include +#include +#include struct buf_io_user { - RIOBind *iob; + RzIOBind *iob; int fd; }; struct buf_io_priv { - RIOBind *iob; + RzIOBind *iob; int fd; }; static inline struct buf_io_priv *get_priv_io(RBuffer *b) { struct buf_io_priv *priv = (struct buf_io_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -43,7 +43,7 @@ static st64 buf_io_seek(RBuffer *b, st64 addr, int whence) { switch (whence) { default: - r_warn_if_reached (); + rz_warn_if_reached (); case R_BUF_SET: io_whence = R_IO_SEEK_SET; break; diff --git a/libr/util/buf_mmap.c b/librz/util/buf_mmap.c similarity index 88% rename from libr/util/buf_mmap.c rename to librz/util/buf_mmap.c index 90d36dcbd2..63349ee059 100644 --- a/libr/util/buf_mmap.c +++ b/librz/util/buf_mmap.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include +#include struct buf_mmap_user { const char *filename; @@ -16,7 +16,7 @@ struct buf_mmap_priv { static inline struct buf_mmap_priv *get_priv_mmap(RBuffer *b) { struct buf_mmap_priv *priv = (struct buf_mmap_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -27,7 +27,7 @@ static bool buf_mmap_init(RBuffer *b, const void *user) { return false; } - priv->mmap = r_file_mmap (u->filename, u->perm & R_PERM_W, 0); + priv->mmap = rz_file_mmap (u->filename, u->perm & R_PERM_W, 0); if (!priv->mmap) { free (priv); return false; @@ -41,7 +41,7 @@ static bool buf_mmap_init(RBuffer *b, const void *user) { static bool buf_mmap_fini(RBuffer *b) { struct buf_mmap_priv *priv = get_priv_mmap (b); - r_file_mmap_free (priv->mmap); + rz_file_mmap_free (priv->mmap); R_FREE (b->priv); return true; } @@ -49,7 +49,7 @@ static bool buf_mmap_fini(RBuffer *b) { static bool buf_mmap_resize(RBuffer *b, ut64 newsize) { struct buf_mmap_priv *priv = get_priv_mmap (b); if (newsize > priv->mmap->len) { - ut8 *t = r_mem_mmap_resize (priv->mmap, newsize); + ut8 *t = rz_mem_mmap_resize (priv->mmap, newsize); if (!t) { return false; } diff --git a/libr/util/buf_ref.c b/librz/util/buf_ref.c similarity index 87% rename from libr/util/buf_ref.c rename to librz/util/buf_ref.c index b515cde14b..7eace2ef20 100644 --- a/libr/util/buf_ref.c +++ b/librz/util/buf_ref.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include +#include struct buf_ref_user { RBuffer *parent; @@ -17,7 +17,7 @@ struct buf_ref_priv { static inline struct buf_ref_priv *get_priv_ref(RBuffer *b) { struct buf_ref_priv *priv = (struct buf_ref_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -31,9 +31,9 @@ static bool buf_ref_init(RBuffer *b, const void *user) { // NOTE: we only support readonly ref-buffers for now. Supporting // read-write would mean to choose how we want to handle writing to the // referencer. Copy-on-write? Write to the buffer underneath? - ut64 parent_sz = r_buf_size (u->parent); + ut64 parent_sz = rz_buf_size (u->parent); b->readonly = true; - priv->parent = r_buf_ref (u->parent); + priv->parent = rz_buf_ref (u->parent); priv->base = R_MIN (u->offset, parent_sz); priv->size = R_MIN (parent_sz - priv->base, u->size); b->priv = priv; @@ -42,14 +42,14 @@ static bool buf_ref_init(RBuffer *b, const void *user) { static bool buf_ref_fini(RBuffer *b) { struct buf_ref_priv *priv = get_priv_ref (b); - r_buf_free (priv->parent); + rz_buf_free (priv->parent); R_FREE (b->priv); return true; } static bool buf_ref_resize(RBuffer *b, ut64 newsize) { struct buf_ref_priv *priv = get_priv_ref (b); - ut64 parent_sz = r_buf_size (priv->parent); + ut64 parent_sz = rz_buf_size (priv->parent); priv->size = R_MIN (parent_sz - priv->base, newsize); return true; } @@ -60,7 +60,7 @@ static st64 buf_ref_read(RBuffer *b, ut8 *buf, ut64 len) { return -1; } len = R_MIN (len, priv->size - priv->cur); - st64 r = r_buf_read_at (priv->parent, priv->base + priv->cur, buf, len); + st64 r = rz_buf_read_at (priv->parent, priv->base + priv->cur, buf, len); if (r < 0) { return r; } @@ -86,7 +86,7 @@ static st64 buf_ref_seek(RBuffer *b, st64 addr, int whence) { priv->cur = priv->size + addr; break; default: - r_warn_if_reached (); + rz_warn_if_reached (); return -1; } return priv->cur; diff --git a/libr/util/buf_sparse.c b/librz/util/buf_sparse.c similarity index 81% rename from libr/util/buf_sparse.c rename to librz/util/buf_sparse.c index 9f65d0fa28..671076562a 100644 --- a/libr/util/buf_sparse.c +++ b/librz/util/buf_sparse.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2020 - ret2libc */ -#include +#include struct buf_sparse_priv { - RList *sparse; + RzList *sparse; ut64 offset; }; @@ -13,12 +13,12 @@ static void buffer_sparse_free(void *a) { free (s); } -static bool sparse_limits(RList *l, ut64 *max) { +static bool sparse_limits(RzList *l, ut64 *max) { bool set = false; RBufferSparse *s; - RListIter *iter; + RzListIter *iter; - r_list_foreach (l, iter, s) { + rz_list_foreach (l, iter, s) { if (set) { if (max && s->to > *max) { *max = s->to; @@ -33,7 +33,7 @@ static bool sparse_limits(RList *l, ut64 *max) { return set; } -static RBufferSparse *sparse_append(RList *l, ut64 addr, const ut8 *data, ut64 len) { +static RBufferSparse *sparse_append(RzList *l, ut64 addr, const ut8 *data, ut64 len) { if (l && data) { RBufferSparse *s = R_NEW0 (RBufferSparse); if (s) { @@ -43,7 +43,7 @@ static RBufferSparse *sparse_append(RList *l, ut64 addr, const ut8 *data, ut64 l s->to = addr + len; s->size = len; memcpy (s->data, data, len); - return r_list_append (l, s)? s: NULL; + return rz_list_append (l, s)? s: NULL; } free (s); } @@ -52,12 +52,12 @@ static RBufferSparse *sparse_append(RList *l, ut64 addr, const ut8 *data, ut64 l } //ret -1 if failed; # of bytes copied if success -static st64 sparse_write(RList *l, ut64 addr, const ut8 *data, ut64 len) { +static st64 sparse_write(RzList *l, ut64 addr, const ut8 *data, ut64 len) { RBufferSparse *s; - RListIter *iter; + RzListIter *iter; ut64 olen = len; - r_list_foreach (l, iter, s) { + rz_list_foreach (l, iter, s) { if (addr >= s->from && addr < s->to) { ut64 delta = addr - s->from; ut64 reallen = s->size - delta >= len? len: s->size - delta; @@ -78,7 +78,7 @@ static st64 sparse_write(RList *l, ut64 addr, const ut8 *data, ut64 len) { static inline struct buf_sparse_priv *get_priv_sparse(RBuffer *b) { struct buf_sparse_priv *priv = (struct buf_sparse_priv *)b->priv; - r_warn_if_fail (priv); + rz_warn_if_fail (priv); return priv; } @@ -87,7 +87,7 @@ static bool buf_sparse_init(RBuffer *b, const void *user) { if (!priv) { return false; } - priv->sparse = r_list_newf (buffer_sparse_free); + priv->sparse = rz_list_newf (buffer_sparse_free); priv->offset = 0; b->priv = priv; return true; @@ -95,19 +95,19 @@ static bool buf_sparse_init(RBuffer *b, const void *user) { static bool buf_sparse_fini(RBuffer *b) { struct buf_sparse_priv *priv = get_priv_sparse (b); - r_list_free (priv->sparse); + rz_list_free (priv->sparse); R_FREE (b->priv); return true; } static bool buf_sparse_resize(RBuffer *b, ut64 newsize) { struct buf_sparse_priv *priv = get_priv_sparse (b); - RListIter *iter, *tmp; + RzListIter *iter, *tmp; RBufferSparse *s; - r_list_foreach_safe (priv->sparse, iter, tmp, s) { + rz_list_foreach_safe (priv->sparse, iter, tmp, s) { if (s->from >= newsize) { - r_list_delete (priv->sparse, iter); + rz_list_delete (priv->sparse, iter); } else if (s->to >= newsize) { RBufferSparse *ns = R_NEW (RBufferSparse); ns->from = s->from; @@ -118,12 +118,12 @@ static bool buf_sparse_resize(RBuffer *b, ut64 newsize) { free (ns); return false; } - // otherwise it will be double-freed by r_list_delete + // otherwise it will be double-freed by rz_list_delete s->data = NULL; ns->data = tmp; ns->written = s->written; - r_list_append (priv->sparse, ns); - r_list_delete (priv->sparse, iter); + rz_list_append (priv->sparse, ns); + rz_list_delete (priv->sparse, iter); } } ut64 max; @@ -144,11 +144,11 @@ static ut64 buf_sparse_size(RBuffer *b) { static st64 buf_sparse_read(RBuffer *b, ut8 *buf, ut64 len) { struct buf_sparse_priv *priv = get_priv_sparse (b); RBufferSparse *c; - RListIter *iter; + RzListIter *iter; ut64 max = 0; memset (buf, b->Oxff_priv, len); - r_list_foreach (priv->sparse, iter, c) { + rz_list_foreach (priv->sparse, iter, c) { if (max < c->to) { max = c->to; } @@ -198,15 +198,15 @@ static st64 buf_sparse_seek(RBuffer *b, st64 addr, int whence) { priv->offset = max + addr; break; default: - r_warn_if_reached (); + rz_warn_if_reached (); return -1; } return priv->offset; } -static RList *buf_sparse_nonempty_list(RBuffer *b) { +static RzList *buf_sparse_nonempty_list(RBuffer *b) { struct buf_sparse_priv *priv = get_priv_sparse (b); - return r_list_clone (priv->sparse); + return rz_list_clone (priv->sparse); } static const RBufferMethods buffer_sparse_methods = { diff --git a/libr/util/cache.c b/librz/util/cache.c similarity index 81% rename from libr/util/cache.c rename to librz/util/cache.c index a85d4f1f91..cd995f355c 100644 --- a/libr/util/cache.c +++ b/librz/util/cache.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2013-2020 - pancake */ -// XXX: should use the same code as libr/io/cache.c +// XXX: should use the same code as librz/io/cache.c // one malloc per write -#include -// TODO: optimize reallocs.. store RBuffer info.. wait. extend r_buf_ for that? +#include +// TODO: optimize reallocs.. store RBuffer info.. wait. extend rz_buf_ for that? -R_API RCache *r_cache_new(void) { +RZ_API RCache *rz_cache_new(void) { RCache *c = R_NEW0 (RCache); if (!c) { return NULL; @@ -16,14 +16,14 @@ R_API RCache *r_cache_new(void) { return c; } -R_API void r_cache_free(RCache *c) { +RZ_API void rz_cache_free(RCache *c) { if (c) { free (c->buf); } free (c); } -R_API const ut8 *r_cache_get(RCache *c, ut64 addr, int *len) { +RZ_API const ut8 *rz_cache_get(RCache *c, ut64 addr, int *len) { if (!c->buf) { return NULL; } @@ -43,7 +43,7 @@ R_API const ut8 *r_cache_get(RCache *c, ut64 addr, int *len) { return c->buf + (addr - c->base); } -R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) { +RZ_API int rz_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) { if (!c) { return 0; } @@ -88,7 +88,7 @@ R_API int r_cache_set(RCache *c, ut64 addr, const ut8 *buf, int len) { return c->len; } -R_API void r_cache_flush(RCache *c) { +RZ_API void rz_cache_flush(RCache *c) { if (c) { c->base = 0; c->len = 0; diff --git a/libr/util/calc.c b/librz/util/calc.c similarity index 97% rename from libr/util/calc.c rename to librz/util/calc.c index 397b8922ae..caa504a317 100644 --- a/libr/util/calc.c +++ b/librz/util/calc.c @@ -8,8 +8,8 @@ ISBN: 0201700735 */ -#include -#include +#include +#include #include #include @@ -141,8 +141,8 @@ static RNumCalcValue prim(RNum *num, RNumCalc *nc, int get) { case RNCNAME: //fprintf (stderr, "error: unknown keyword (%s)\n", nc->string_value); //double& v = table[nc->string_value]; - r_str_trim (nc->string_value); - v = Nset (r_num_get (num, nc->string_value)); + rz_str_trim (nc->string_value); + v = Nset (rz_num_get (num, nc->string_value)); get_token (num, nc); if (nc->curr_tok == RNCASSIGN) { v = expr (num, nc, 1); @@ -196,7 +196,7 @@ static void cin_putback (RNum *num, RNumCalc *nc, char c) { nc->oc = c; } -R_API const char *r_num_calc_index(RNum *num, const char *p) { +RZ_API const char *rz_num_calc_index(RNum *num, const char *p) { if (!num) { return NULL; } @@ -242,7 +242,7 @@ static int cin_get_num(RNum *num, RNumCalc *nc, RNumCalcValue *n) { } } str[i] = 0; - *n = Nset (r_num_get (num, str)); + *n = Nset (rz_num_get (num, str)); if (IS_DIGIT (*str) && strchr (str, '.')) { if (sscanf (str, "%lf", &d) < 1) { return 0; @@ -376,7 +376,7 @@ static void load_token(RNum *num, RNumCalc *nc, const char *s) { nc->calc_err = NULL; } -R_API ut64 r_num_calc(RNum *num, const char *str, const char **err) { +RZ_API ut64 rz_num_calc(RNum *num, const char *str, const char **err) { RNumCalcValue n; RNumCalc *nc, nc_local; if (!str || !*str) { diff --git a/libr/util/chmod.c b/librz/util/chmod.c similarity index 96% rename from libr/util/chmod.c rename to librz/util/chmod.c index faf2f6f864..8d69eee672 100644 --- a/libr/util/chmod.c +++ b/librz/util/chmod.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2011-2019 - pancake */ -#include +#include #include #include #include @@ -15,7 +15,7 @@ static char oper = '='; static mode_t mode = 0; #endif -R_API bool r_file_chmod (const char *file, const char *mod, int recursive) { +RZ_API bool rz_file_chmod (const char *file, const char *mod, int recursive) { #if __UNIX__ oper = '='; mode = 0; diff --git a/libr/util/debruijn.c b/librz/util/debruijn.c similarity index 92% rename from libr/util/debruijn.c rename to librz/util/debruijn.c index a5b68b4381..36156125b7 100644 --- a/libr/util/debruijn.c +++ b/librz/util/debruijn.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2014-2016 - crowell, pancake */ -#include +#include // The following two (commented out) lines are the character set used in peda. // You may use this charset instead of the A-Za-z0-9 charset normally used. @@ -66,7 +66,7 @@ static char* de_bruijn(const char* charset, int order, int maxlen) { // offset of start. // The returned string is malloced, and it is the responsibility of the caller // to free the memory. -R_API char* r_debruijn_pattern(int size, int start, const char* charset) { +RZ_API char* rz_debruijn_pattern(int size, int start, const char* charset) { char *pat, *pat2; ut64 len; if (!charset) { @@ -105,7 +105,7 @@ R_API char* r_debruijn_pattern(int size, int start, const char* charset) { } // Finds the offset of a given value in a cyclic pattern of an integer. -R_API int r_debruijn_offset(ut64 value, bool is_big_endian) { +RZ_API int rz_debruijn_offset(ut64 value, bool is_big_endian) { char* needle, *pattern, buf[9]; int retval = -1; char* pch; @@ -119,13 +119,13 @@ R_API int r_debruijn_offset(ut64 value, bool is_big_endian) { } for (j = 0; j < 2 && retval == -1; j++) { - pattern = r_debruijn_pattern (lens[j], 0, debruijn_charset); + pattern = rz_debruijn_pattern (lens[j], 0, debruijn_charset); buf[8] = '\0'; if (is_big_endian) { - r_write_be64 (buf, value); + rz_write_be64 (buf, value); } else { - r_write_le64 (buf, value); + rz_write_le64 (buf, value); } for (needle = buf; !*needle; needle++) { /* do nothing here */ diff --git a/libr/util/deps.mk b/librz/util/deps.mk similarity index 100% rename from libr/util/deps.mk rename to librz/util/deps.mk diff --git a/libr/util/donut.c b/librz/util/donut.c similarity index 94% rename from libr/util/donut.c rename to librz/util/donut.c index f42bcb4ba7..45da137c4d 100644 --- a/libr/util/donut.c +++ b/librz/util/donut.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2019 - pancake */ +/* rizin - LGPL - Copyright 2019 - pancake */ #if 0 @@ -30,11 +30,11 @@ in(B),t=c*h*g-f* e;int x=40+30*D* #else -#include +#include #include // global iterators -R_API char *r_str_donut(int osize) { +RZ_API char *rz_str_donut(int osize) { int size = osize; static float A= 0; static float B= 0; @@ -87,7 +87,7 @@ R_API char *r_str_donut(int osize) { B += 0.01; } char *r = strdup (o); - r_str_trim_tail (r); + rz_str_trim_tail (r); return r; } diff --git a/libr/util/event.c b/librz/util/event.c similarity index 52% rename from libr/util/event.c rename to librz/util/event.c index 3059a1ac69..c02272fb78 100644 --- a/libr/util/event.c +++ b/librz/util/event.c @@ -1,19 +1,19 @@ -/* radare2 - MIT - Copyright 2018 - pancake */ +/* rizin - MIT - Copyright 2018 - pancake */ -#include -#include +#include +#include -typedef struct r_event_callback_hook_t { +typedef struct rz_event_callback_hook_t { REventCallback cb; void *user; int handle; } REventCallbackHook; static void ht_callback_free(HtUPKv *kv) { - r_vector_free ((RVector *)kv->value); + rz_vector_free ((RzVector *)kv->value); } -R_API REvent *r_event_new(void *user) { +RZ_API REvent *rz_event_new(void *user) { REvent *ev = R_NEW0 (REvent); if (!ev) { return NULL; @@ -25,26 +25,26 @@ R_API REvent *r_event_new(void *user) { if (!ev->callbacks) { goto err; } - r_vector_init (&ev->all_callbacks, sizeof (REventCallbackHook), NULL, NULL); + rz_vector_init (&ev->all_callbacks, sizeof (REventCallbackHook), NULL, NULL); return ev; err: - r_event_free (ev); + rz_event_free (ev); return NULL; } -R_API void r_event_free(REvent *ev) { +RZ_API void rz_event_free(REvent *ev) { if (!ev) { return; } ht_up_free (ev->callbacks); - r_vector_clear (&ev->all_callbacks); + rz_vector_clear (&ev->all_callbacks); free (ev); } -static RVector *get_cbs(REvent *ev, int type) { - RVector *cbs = ht_up_find (ev->callbacks, (ut64)type, NULL); +static RzVector *get_cbs(REvent *ev, int type) { + RzVector *cbs = ht_up_find (ev->callbacks, (ut64)type, NULL); if (!cbs) { - cbs = r_vector_new (sizeof (REventCallbackHook), NULL, NULL); + cbs = rz_vector_new (sizeof (REventCallbackHook), NULL, NULL); if (cbs) { ht_up_insert (ev->callbacks, (ut64)type, cbs); } @@ -52,22 +52,22 @@ static RVector *get_cbs(REvent *ev, int type) { return cbs; } -R_API REventCallbackHandle r_event_hook(REvent *ev, int type, REventCallback cb, void *user) { +RZ_API REventCallbackHandle rz_event_hook(REvent *ev, int type, REventCallback cb, void *user) { REventCallbackHandle handle = { 0 }; REventCallbackHook hook; - r_return_val_if_fail (ev, handle); + rz_return_val_if_fail (ev, handle); hook.cb = cb; hook.user = user; hook.handle = ev->next_handle++; if (type == R_EVENT_ALL) { - r_vector_push (&ev->all_callbacks, &hook); + rz_vector_push (&ev->all_callbacks, &hook); } else { - RVector *cbs = get_cbs (ev, type); + RzVector *cbs = get_cbs (ev, type); if (!cbs) { return handle; } - r_vector_push (cbs, &hook); + rz_vector_push (cbs, &hook); } handle.handle = hook.handle; handle.type = type; @@ -76,50 +76,50 @@ R_API REventCallbackHandle r_event_hook(REvent *ev, int type, REventCallback cb, static bool del_hook(void *user, const ut64 k, const void *v) { int handle = *(int *)user; - RVector *cbs = (RVector *)v; + RzVector *cbs = (RzVector *)v; REventCallbackHook *hook; size_t i; - r_return_val_if_fail (cbs, false); - r_vector_enumerate (cbs, hook, i) { + rz_return_val_if_fail (cbs, false); + rz_vector_enumerate (cbs, hook, i) { if (hook->handle == handle) { - r_vector_remove_at (cbs, i, NULL); + rz_vector_remove_at (cbs, i, NULL); break; } } return true; } -R_API void r_event_unhook(REvent *ev, REventCallbackHandle handle) { - r_return_if_fail (ev); +RZ_API void rz_event_unhook(REvent *ev, REventCallbackHandle handle) { + rz_return_if_fail (ev); if (handle.type == R_EVENT_ALL) { // try to delete it both from each list of callbacks and from // the "all_callbacks" vector ht_up_foreach (ev->callbacks, del_hook, &handle.handle); del_hook (&handle.handle, 0, &ev->all_callbacks); } else { - RVector *cbs = ht_up_find (ev->callbacks, (ut64)handle.type, NULL); - r_return_if_fail (cbs); + RzVector *cbs = ht_up_find (ev->callbacks, (ut64)handle.type, NULL); + rz_return_if_fail (cbs); del_hook (&handle.handle, 0, cbs); } } -R_API void r_event_send(REvent *ev, int type, void *data) { +RZ_API void rz_event_send(REvent *ev, int type, void *data) { REventCallbackHook *hook; - r_return_if_fail (ev && !ev->incall); + rz_return_if_fail (ev && !ev->incall); // send to both the per-type callbacks and to the all_callbacks ev->incall = true; - r_vector_foreach (&ev->all_callbacks, hook) { + rz_vector_foreach (&ev->all_callbacks, hook) { hook->cb (ev, type, hook->user, data); } ev->incall = false; - RVector *cbs = ht_up_find (ev->callbacks, (ut64)type, NULL); + RzVector *cbs = ht_up_find (ev->callbacks, (ut64)type, NULL); if (!cbs) { return; } ev->incall = true; - r_vector_foreach (cbs, hook) { + rz_vector_foreach (cbs, hook) { hook->cb (ev, type, hook->user, data); } ev->incall = false; diff --git a/libr/util/file.c b/librz/util/file.c similarity index 66% rename from libr/util/file.c rename to librz/util/file.c index c23e69847c..7d810c500b 100644 --- a/libr/util/file.c +++ b/librz/util/file.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" #include #include #include #include #include -#include +#include #if __UNIX__ #include #include @@ -28,9 +28,9 @@ #define BS 1024 static int file_stat (const char *file, struct stat* const pStat) { - r_return_val_if_fail (file && pStat, -1); + rz_return_val_if_fail (file && pStat, -1); #if __WINDOWS__ - wchar_t *wfile = r_utf8_to_utf16 (file); + wchar_t *wfile = rz_utf8_to_utf16 (file); if (!wfile) { return -1; } @@ -42,19 +42,19 @@ static int file_stat (const char *file, struct stat* const pStat) { #endif // __WINDOWS__ } -R_API bool r_file_truncate(const char *filename, ut64 newsize) { - r_return_val_if_fail (filename, false); +RZ_API bool rz_file_truncate(const char *filename, ut64 newsize) { + rz_return_val_if_fail (filename, false); int fd; - if (r_file_is_directory (filename)) { + if (rz_file_is_directory (filename)) { return false; } - if (!r_file_exists (filename) || !r_file_is_regular (filename)) { + if (!rz_file_exists (filename) || !rz_file_is_regular (filename)) { return false; } #if __WINDOWS__ - fd = r_sandbox_open (filename, O_RDWR, 0644); + fd = rz_sandbox_open (filename, O_RDWR, 0644); #else - fd = r_sandbox_open (filename, O_RDWR | O_SYNC, 0644); + fd = rz_sandbox_open (filename, O_RDWR | O_SYNC, 0644); #endif if (fd == -1) { return false; @@ -75,16 +75,16 @@ R_API bool r_file_truncate(const char *filename, ut64 newsize) { /* Example: - str = r_file_basename ("home/inisider/Downloads/user32.dll"); + str = rz_file_basename ("home/inisider/Downloads/user32.dll"); // str == user32.dll */ -R_API const char *r_file_basename(const char *path) { - r_return_val_if_fail (path, NULL); - const char *ptr = r_str_rchr (path, NULL, '/'); +RZ_API const char *rz_file_basename(const char *path) { + rz_return_val_if_fail (path, NULL); + const char *ptr = rz_str_rchr (path, NULL, '/'); if (ptr) { path = ptr + 1; } else { - if ((ptr = r_str_rchr (path, NULL, '\\'))) { + if ((ptr = rz_str_rchr (path, NULL, '\\'))) { path = ptr + 1; } } @@ -93,18 +93,18 @@ R_API const char *r_file_basename(const char *path) { /* Example: - str = r_file_basename ("home/inisider/Downloads"); + str = rz_file_basename ("home/inisider/Downloads"); // str == "home/inisider/Downloads" free (str); */ -R_API char *r_file_dirname(const char *path) { - r_return_val_if_fail (path, NULL); +RZ_API char *rz_file_dirname(const char *path) { + rz_return_val_if_fail (path, NULL); char *newpath = strdup (path); - char *ptr = (char*)r_str_rchr (newpath, NULL, '/'); + char *ptr = (char*)rz_str_rchr (newpath, NULL, '/'); if (ptr) { *ptr = 0; } else { - ptr = (char*)r_str_rchr (newpath, NULL, '\\'); + ptr = (char*)rz_str_rchr (newpath, NULL, '\\'); if (ptr) { *ptr = 0; } @@ -112,9 +112,9 @@ R_API char *r_file_dirname(const char *path) { return newpath; } -R_API bool r_file_is_c(const char *file) { - r_return_val_if_fail (file, false); - const char *ext = r_str_lchr (file, '.'); // TODO: add api in r_file_extension or r_str_ext for this +RZ_API bool rz_file_is_c(const char *file) { + rz_return_val_if_fail (file, false); + const char *ext = rz_str_lchr (file, '.'); // TODO: add api in rz_file_extension or rz_str_ext for this if (ext) { ext++; if (!strcmp (ext, "cparse") @@ -126,7 +126,7 @@ R_API bool r_file_is_c(const char *file) { return false; } -R_API bool r_file_is_regular(const char *str) { +RZ_API bool rz_file_is_regular(const char *str) { struct stat buf = {0}; if (!str || !*str || file_stat (str, &buf) == -1) { return false; @@ -134,9 +134,9 @@ R_API bool r_file_is_regular(const char *str) { return ((S_IFREG & buf.st_mode) == S_IFREG); } -R_API bool r_file_is_directory(const char *str) { +RZ_API bool rz_file_is_directory(const char *str) { struct stat buf = {0}; - r_return_val_if_fail (!R_STR_ISEMPTY (str), false); + rz_return_val_if_fail (!R_STR_ISEMPTY (str), false); if (file_stat (str, &buf) == -1) { return false; } @@ -148,21 +148,21 @@ R_API bool r_file_is_directory(const char *str) { return S_IFDIR == (S_IFDIR & buf.st_mode); } -R_API bool r_file_fexists(const char *fmt, ...) { +RZ_API bool rz_file_fexists(const char *fmt, ...) { int ret; char string[BS]; va_list ap; va_start (ap, fmt); vsnprintf (string, sizeof (string), fmt, ap); - ret = r_file_exists (string); + ret = rz_file_exists (string); va_end (ap); return ret; } -R_API bool r_file_exists(const char *str) { - char *absfile = r_file_abspath (str); +RZ_API bool rz_file_exists(const char *str) { + char *absfile = rz_file_abspath (str); struct stat buf = {0}; - r_return_val_if_fail (!R_STR_ISEMPTY (str), false); + rz_return_val_if_fail (!R_STR_ISEMPTY (str), false); if (file_stat (absfile, &buf) == -1) { free (absfile); return false; @@ -171,8 +171,8 @@ R_API bool r_file_exists(const char *str) { return S_IFREG == (S_IFREG & buf.st_mode); } -R_API ut64 r_file_size(const char *str) { - r_return_val_if_fail (!R_STR_ISEMPTY (str), 0); +RZ_API ut64 rz_file_size(const char *str) { + rz_return_val_if_fail (!R_STR_ISEMPTY (str), 0); struct stat buf = {0}; if (file_stat (str, &buf) == -1) { return 0; @@ -180,25 +180,25 @@ R_API ut64 r_file_size(const char *str) { return (ut64)buf.st_size; } -R_API bool r_file_is_abspath(const char *file) { - r_return_val_if_fail (!R_STR_ISEMPTY (file), 0); +RZ_API bool rz_file_is_abspath(const char *file) { + rz_return_val_if_fail (!R_STR_ISEMPTY (file), 0); return ((*file && file[1]==':') || *file == '/'); } -R_API char *r_file_abspath_rel(const char *cwd, const char *file) { +RZ_API char *rz_file_abspath_rel(const char *cwd, const char *file) { char *ret = NULL; if (!file || !strcmp (file, ".") || !strcmp (file, "./")) { - return r_sys_getdir (); + return rz_sys_getdir (); } if (strstr (file, "://")) { return strdup (file); } if (!strncmp (file, "~/", 2) || !strncmp (file, "~\\", 2)) { - ret = r_str_home (file + 2); + ret = rz_str_home (file + 2); } else { #if __UNIX__ if (cwd && *file != '/') { - ret = r_str_newf ("%s" R_SYS_DIR "%s", cwd, file); + ret = rz_str_newf ("%s" R_SYS_DIR "%s", cwd, file); } #elif __WINDOWS__ // Network path @@ -208,14 +208,14 @@ R_API char *r_file_abspath_rel(const char *cwd, const char *file) { if (!strchr (file, ':')) { PTCHAR abspath = malloc (MAX_PATH * sizeof (TCHAR)); if (abspath) { - PTCHAR f = r_sys_conv_utf8_to_win (file); + PTCHAR f = rz_sys_conv_utf8_to_win (file); int s = GetFullPathName (f, MAX_PATH, abspath, NULL); if (s > MAX_PATH) { - R_LOG_ERROR ("r_file_abspath/GetFullPathName: Path to file too long.\n"); + R_LOG_ERROR ("rz_file_abspath/GetFullPathName: Path to file too long.\n"); } else if (!s) { - r_sys_perror ("r_file_abspath/GetFullPathName"); + rz_sys_perror ("rz_file_abspath/GetFullPathName"); } else { - ret = r_sys_conv_win_to_utf8 (abspath); + ret = rz_sys_conv_win_to_utf8 (abspath); } free (abspath); free (f); @@ -236,30 +236,30 @@ R_API char *r_file_abspath_rel(const char *cwd, const char *file) { return ret; } -R_API char *r_file_abspath(const char *file) { - r_return_val_if_fail (file, NULL); - char *cwd = r_sys_getdir (); +RZ_API char *rz_file_abspath(const char *file) { + rz_return_val_if_fail (file, NULL); + char *cwd = rz_sys_getdir (); if (cwd) { - char *ret = r_file_abspath_rel (cwd, file); + char *ret = rz_file_abspath_rel (cwd, file); free (cwd); return ret; } return NULL; } -R_API char *r_file_path(const char *bin) { - r_return_val_if_fail (bin, NULL); +RZ_API char *rz_file_path(const char *bin) { + rz_return_val_if_fail (bin, NULL); char *file = NULL; char *path = NULL; char *str, *ptr; const char *extension = ""; if (!strncmp (bin, "./", 2)) { - return r_file_exists (bin) - ? r_file_abspath (bin): NULL; + return rz_file_exists (bin) + ? rz_file_abspath (bin): NULL; } - char *path_env = (char *)r_sys_getenv ("PATH"); + char *path_env = (char *)rz_sys_getenv ("PATH"); #if __WINDOWS__ - if (!r_str_endswith (bin, ".exe")) { + if (!rz_str_endswith (bin, ".exe")) { extension = ".exe"; } #endif @@ -269,8 +269,8 @@ R_API char *r_file_path(const char *bin) { ptr = strchr (str, R_SYS_ENVSEP[0]); if (ptr) { *ptr = '\0'; - file = r_str_newf (R_JOIN_2_PATHS ("%s", "%s%s"), str, bin, extension); - if (r_file_exists (file)) { + file = rz_str_newf (R_JOIN_2_PATHS ("%s", "%s%s"), str, bin, extension); + if (rz_file_exists (file)) { free (path); free (path_env); return file; @@ -285,7 +285,7 @@ R_API char *r_file_path(const char *bin) { return strdup (bin); } -R_API char *r_stdin_slurp (int *sz) { +RZ_API char *rz_stdin_slurp (int *sz) { #if __UNIX__ || __WINDOWS__ int i, ret, newfd; if ((newfd = dup (0)) < 0) { @@ -325,20 +325,20 @@ R_API char *r_stdin_slurp (int *sz) { } return buf; #else -#warning TODO r_stdin_slurp +#warning TODO rz_stdin_slurp return NULL; #endif } -R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) { - r_return_val_if_fail (str, NULL); +RZ_API char *rz_file_slurp(const char *str, R_NULLABLE size_t *usz) { + rz_return_val_if_fail (str, NULL); if (usz) { *usz = 0; } - if (!r_file_exists (str)) { + if (!rz_file_exists (str)) { return NULL; } - FILE *fd = r_sandbox_fopen (str, "rb"); + FILE *fd = rz_sandbox_fopen (str, "rb"); if (!fd) { return NULL; } @@ -351,7 +351,7 @@ R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) { return NULL; } if (!sz) { - if (r_file_is_regular (str)) { + if (rz_file_is_regular (str)) { char *buf = NULL; long size = 0; (void)fseek (fd, 0, SEEK_SET); @@ -393,7 +393,7 @@ R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) { } size_t rsz = fread (ret, 1, sz, fd); if (rsz != sz) { - eprintf ("Warning: r_file_slurp: fread: truncated read\n"); + eprintf ("Warning: rz_file_slurp: fread: truncated read\n"); sz = rsz; } fclose (fd); @@ -404,17 +404,17 @@ R_API char *r_file_slurp(const char *str, R_NULLABLE size_t *usz) { return ret; } -R_API ut8 *r_file_gzslurp(const char *str, int *outlen, int origonfail) { - r_return_val_if_fail (str, NULL); +RZ_API ut8 *rz_file_gzslurp(const char *str, int *outlen, int origonfail) { + rz_return_val_if_fail (str, NULL); if (outlen) { *outlen = 0; } size_t sz; - ut8 *in = (ut8*)r_file_slurp (str, &sz); + ut8 *in = (ut8*)rz_file_slurp (str, &sz); if (!in) { return NULL; } - ut8 *out = r_inflate (in, (int)sz, NULL, outlen); + ut8 *out = rz_inflate (in, (int)sz, NULL, outlen); if (!out && origonfail) { // if uncompression fails, return orig buffer ? if (outlen) { @@ -427,15 +427,15 @@ R_API ut8 *r_file_gzslurp(const char *str, int *outlen, int origonfail) { return out; } -R_API ut8 *r_file_slurp_hexpairs(const char *str, int *usz) { - r_return_val_if_fail (str, NULL); +RZ_API ut8 *rz_file_slurp_hexpairs(const char *str, int *usz) { + rz_return_val_if_fail (str, NULL); if (usz) { *usz = 0; } ut8 *ret; long sz; int c, bytes = 0; - FILE *fd = r_sandbox_fopen (str, "rb"); + FILE *fd = rz_sandbox_fopen (str, "rb"); if (!fd) { return NULL; } @@ -470,10 +470,10 @@ R_API ut8 *r_file_slurp_hexpairs(const char *str, int *usz) { return ret; } -R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz) { +RZ_API char *rz_file_slurp_range(const char *str, ut64 off, int sz, int *osz) { char *ret; size_t read_items; - FILE *fd = r_sandbox_fopen (str, "rb"); + FILE *fd = rz_sandbox_fopen (str, "rb"); if (!fd) { return NULL; } @@ -499,25 +499,25 @@ R_API char *r_file_slurp_range(const char *str, ut64 off, int sz, int *osz) { return ret; } -R_API char *r_file_slurp_random_line(const char *file) { - r_return_val_if_fail (file, NULL); +RZ_API char *rz_file_slurp_random_line(const char *file) { + rz_return_val_if_fail (file, NULL); int i = 0; - return r_file_slurp_random_line_count (file, &i); + return rz_file_slurp_random_line_count (file, &i); } -R_API char *r_file_slurp_random_line_count(const char *file, int *line) { - r_return_val_if_fail (file && line, NULL); +RZ_API char *rz_file_slurp_random_line_count(const char *file, int *line) { + rz_return_val_if_fail (file && line, NULL); /* Reservoir Sampling */ char *ptr = NULL, *str; size_t i, lines, selection = -1; int start = *line; - if ((str = r_file_slurp (file, NULL))) { - r_num_irand (); + if ((str = rz_file_slurp (file, NULL))) { + rz_num_irand (); for (i = 0; str[i]; i++) { if (str[i] == '\n') { //here rand doesn't have any security implication // https://www.securecoding.cert.org/confluence/display/c/MSC30-C.+Do+not+use+the+rand()+function+for+generating+pseudorandom+numbers - if (!(r_num_rand ((++(*line))))) { + if (!(rz_num_rand ((++(*line))))) { selection = (*line - 1); /* The line we want. */ } } @@ -548,11 +548,11 @@ R_API char *r_file_slurp_random_line_count(const char *file, int *line) { return ptr; } -R_API char *r_file_slurp_line(const char *file, int line, int context) { - r_return_val_if_fail (file, NULL); +RZ_API char *rz_file_slurp_line(const char *file, int line, int context) { + rz_return_val_if_fail (file, NULL); int i, lines = 0; size_t sz; - char *ptr = NULL, *str = r_file_slurp (file, &sz); + char *ptr = NULL, *str = rz_file_slurp (file, &sz); // TODO: Implement context if (str) { for (i = 0; str[i]; i++) { @@ -583,11 +583,11 @@ R_API char *r_file_slurp_line(const char *file, int line, int context) { return ptr; } -R_API char *r_file_slurp_lines_from_bottom(const char *file, int line) { - r_return_val_if_fail (file, NULL); +RZ_API char *rz_file_slurp_lines_from_bottom(const char *file, int line) { + rz_return_val_if_fail (file, NULL); int i, lines = 0; size_t sz; - char *ptr = NULL, *str = r_file_slurp (file, &sz); + char *ptr = NULL, *str = rz_file_slurp (file, &sz); // TODO: Implement context if (str) { for (i = 0; str[i]; i++) { @@ -611,11 +611,11 @@ R_API char *r_file_slurp_lines_from_bottom(const char *file, int line) { return ptr; } -R_API char *r_file_slurp_lines(const char *file, int line, int count) { - r_return_val_if_fail (file, NULL); +RZ_API char *rz_file_slurp_lines(const char *file, int line, int count) { + rz_return_val_if_fail (file, NULL); int i, lines = 0; size_t sz; - char *ptr = NULL, *str = r_file_slurp (file, &sz); + char *ptr = NULL, *str = rz_file_slurp (file, &sz); // TODO: Implement context if (str) { for (i = 0; str[i]; i++) { @@ -650,37 +650,37 @@ R_API char *r_file_slurp_lines(const char *file, int line, int count) { return ptr; } -R_API char *r_file_root(const char *root, const char *path) { - r_return_val_if_fail (root && path, NULL); - char *ret, *s = r_str_replace (strdup (path), "..", "", 1); +RZ_API char *rz_file_root(const char *root, const char *path) { + rz_return_val_if_fail (root && path, NULL); + char *ret, *s = rz_str_replace (strdup (path), "..", "", 1); // XXX ugly hack while (strstr (s, "..")) { - s = r_str_replace (s, "..", "", 1); + s = rz_str_replace (s, "..", "", 1); } while (strstr (s, "./")) { - s = r_str_replace (s, "./", "", 1); + s = rz_str_replace (s, "./", "", 1); } while (strstr (s, "//")) { - s = r_str_replace (s, "//", "", 1); + s = rz_str_replace (s, "//", "", 1); } - ret = r_str_append (strdup (root), R_SYS_DIR); - ret = r_str_append (ret, s); + ret = rz_str_append (strdup (root), R_SYS_DIR); + ret = rz_str_append (ret, s); free (s); return ret; } -R_API bool r_file_hexdump(const char *file, const ut8 *buf, int len, int append) { +RZ_API bool rz_file_hexdump(const char *file, const ut8 *buf, int len, int append) { FILE *fd; int i,j; if (!file || !*file || !buf || len < 0) { - eprintf ("r_file_hexdump file: %s buf: %p\n", file, buf); + eprintf ("rz_file_hexdump file: %s buf: %p\n", file, buf); return false; } if (append) { - fd = r_sandbox_fopen (file, "ab"); + fd = rz_sandbox_fopen (file, "ab"); } else { - r_sys_truncate (file, 0); - fd = r_sandbox_fopen (file, "wb"); + rz_sys_truncate (file, 0); + fd = rz_sandbox_fopen (file, "wb"); } if (!fd) { eprintf ("Cannot open '%s' for writing\n", file); @@ -708,19 +708,19 @@ R_API bool r_file_hexdump(const char *file, const ut8 *buf, int len, int append) return true; } -R_API bool r_file_touch(const char *file) { - r_return_val_if_fail (file, false); - return r_file_dump (file, NULL, 0, true); +RZ_API bool rz_file_touch(const char *file) { + rz_return_val_if_fail (file, false); + return rz_file_dump (file, NULL, 0, true); } -R_API bool r_file_dump(const char *file, const ut8 *buf, int len, bool append) { - r_return_val_if_fail (!R_STR_ISEMPTY (file), false); +RZ_API bool rz_file_dump(const char *file, const ut8 *buf, int len, bool append) { + rz_return_val_if_fail (!R_STR_ISEMPTY (file), false); FILE *fd; if (append) { - fd = r_sandbox_fopen (file, "ab"); + fd = rz_sandbox_fopen (file, "ab"); } else { - r_sys_truncate (file, 0); - fd = r_sandbox_fopen (file, "wb"); + rz_sys_truncate (file, 0); + fd = rz_sandbox_fopen (file, "wb"); } if (!fd) { eprintf ("Cannot open '%s' for writing\n", file); @@ -731,7 +731,7 @@ R_API bool r_file_dump(const char *file, const ut8 *buf, int len, bool append) { len = strlen ((const char *)buf); } if (len > 0 && fwrite (buf, len, 1, fd) != 1) { - r_sys_perror ("r_file_dump: fwrite: error\n"); + rz_sys_perror ("rz_file_dump: fwrite: error\n"); fclose (fd); return false; } @@ -740,14 +740,14 @@ R_API bool r_file_dump(const char *file, const ut8 *buf, int len, bool append) { return true; } -R_API bool r_file_rm(const char *file) { - r_return_val_if_fail (!R_STR_ISEMPTY (file), false); - if (r_sandbox_enable (0)) { +RZ_API bool rz_file_rm(const char *file) { + rz_return_val_if_fail (!R_STR_ISEMPTY (file), false); + if (rz_sandbox_enable (0)) { return false; } - if (r_file_is_directory (file)) { + if (rz_file_is_directory (file)) { #if __WINDOWS__ - LPTSTR file_ = r_sys_conv_utf8_to_win (file); + LPTSTR file_ = rz_sys_conv_utf8_to_win (file); bool ret = RemoveDirectory (file_); free (file_); @@ -757,7 +757,7 @@ R_API bool r_file_rm(const char *file) { #endif } else { #if __WINDOWS__ - LPTSTR file_ = r_sys_conv_utf8_to_win (file); + LPTSTR file_ = rz_sys_conv_utf8_to_win (file); bool ret = DeleteFile (file_); free (file_); @@ -768,9 +768,9 @@ R_API bool r_file_rm(const char *file) { } } -R_API char *r_file_readlink(const char *path) { - r_return_val_if_fail (!R_STR_ISEMPTY (path), false); - if (!r_sandbox_enable (0)) { +RZ_API char *rz_file_readlink(const char *path) { + rz_return_val_if_fail (!R_STR_ISEMPTY (path), false); + if (!rz_sandbox_enable (0)) { #if __UNIX__ int ret; char pathbuf[4096] = {0}; @@ -788,27 +788,27 @@ R_API char *r_file_readlink(const char *path) { return NULL; } -R_API int r_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len) { +RZ_API int rz_file_mmap_write(const char *file, ut64 addr, const ut8 *buf, int len) { #if __WINDOWS__ HANDLE fh = INVALID_HANDLE_VALUE; DWORD written = 0; LPTSTR file_ = NULL; int ret = -1; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return -1; } - file_ = r_sys_conv_utf8_to_win (file); + file_ = rz_sys_conv_utf8_to_win (file); fh = CreateFile (file_, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (fh == INVALID_HANDLE_VALUE) { - r_sys_perror ("r_file_mmap_write/CreateFile"); + rz_sys_perror ("rz_file_mmap_write/CreateFile"); goto err_r_file_mmap_write; } SetFilePointer (fh, addr, NULL, FILE_BEGIN); if (!WriteFile (fh, buf, (DWORD)len, &written, NULL)) { - r_sys_perror ("r_file_mmap_write/WriteFile"); + rz_sys_perror ("rz_file_mmap_write/WriteFile"); goto err_r_file_mmap_write; } ret = len; @@ -819,7 +819,7 @@ err_r_file_mmap_write: } return ret; #elif __UNIX__ - int fd = r_sandbox_open (file, O_RDWR|O_SYNC, 0644); + int fd = rz_sandbox_open (file, O_RDWR|O_SYNC, 0644); const int pagesize = getpagesize (); int mmlen = len + pagesize; int rest = addr % pagesize; @@ -844,23 +844,23 @@ err_r_file_mmap_write: #endif } -R_API int r_file_mmap_read (const char *file, ut64 addr, ut8 *buf, int len) { +RZ_API int rz_file_mmap_read (const char *file, ut64 addr, ut8 *buf, int len) { #if __WINDOWS__ HANDLE fm = NULL, fh = INVALID_HANDLE_VALUE; LPTSTR file_ = NULL; int ret = -1; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return -1; } - file_ = r_sys_conv_utf8_to_win (file); + file_ = rz_sys_conv_utf8_to_win (file); fh = CreateFile (file_, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); if (fh == INVALID_HANDLE_VALUE) { - r_sys_perror ("r_file_mmap_read/CreateFile"); + rz_sys_perror ("rz_file_mmap_read/CreateFile"); goto err_r_file_mmap_read; } fm = CreateFileMapping (fh, NULL, PAGE_READONLY, 0, 0, NULL); if (!fm) { - r_sys_perror ("CreateFileMapping"); + rz_sys_perror ("CreateFileMapping"); goto err_r_file_mmap_read; } ut8 *obuf = MapViewOfFile (fm, FILE_MAP_READ, 0, 0, len); @@ -880,7 +880,7 @@ err_r_file_mmap_read: free (file_); return ret; #elif __UNIX__ - int fd = r_sandbox_open (file, O_RDONLY, 0644); + int fd = rz_sandbox_open (file, O_RDONLY, 0644); const int pagesize = 4096; int mmlen = len+pagesize; int rest = addr%pagesize; @@ -901,7 +901,7 @@ err_r_file_mmap_read: } #if __UNIX__ -static RMmap *r_file_mmap_unix (RMmap *m, int fd) { +static RMmap *rz_file_mmap_unix (RMmap *m, int fd) { ut8 empty = m->len == 0; m->buf = mmap (NULL, (empty?BS:m->len) , m->rw?PROT_READ|PROT_WRITE:PROT_READ, @@ -912,21 +912,21 @@ static RMmap *r_file_mmap_unix (RMmap *m, int fd) { return m; } #elif __WINDOWS__ -static RMmap *r_file_mmap_windows(RMmap *m, const char *file) { - LPTSTR file_ = r_sys_conv_utf8_to_win (file); +static RMmap *rz_file_mmap_windows(RMmap *m, const char *file) { + LPTSTR file_ = rz_sys_conv_utf8_to_win (file); bool success = false; m->fh = CreateFile (file_, GENERIC_READ | (m->rw ? GENERIC_WRITE : 0), FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (m->fh == INVALID_HANDLE_VALUE) { - r_sys_perror ("CreateFile"); + rz_sys_perror ("CreateFile"); goto err_r_file_mmap_windows; } m->fm = CreateFileMapping (m->fh, NULL, PAGE_READONLY, 0, 0, NULL); //m->rw?PAGE_READWRITE:PAGE_READONLY, 0, 0, NULL); if (!m->fm) { - r_sys_perror ("CreateFileMapping"); + rz_sys_perror ("CreateFileMapping"); goto err_r_file_mmap_windows; } @@ -959,13 +959,13 @@ static RMmap *file_mmap_other (RMmap *m) { } #endif -R_API RMmap *r_file_mmap_arch(RMmap *mmap, const char *filename, int fd) { +RZ_API RMmap *rz_file_mmap_arch(RMmap *mmap, const char *filename, int fd) { #if __WINDOWS__ (void)fd; - return r_file_mmap_windows (mmap, filename); + return rz_file_mmap_windows (mmap, filename); #elif __UNIX__ (void)filename; - return r_file_mmap_unix (mmap, fd); + return rz_file_mmap_unix (mmap, fd); #else (void)filename; (void)fd; @@ -974,15 +974,15 @@ R_API RMmap *r_file_mmap_arch(RMmap *mmap, const char *filename, int fd) { } // TODO: add rwx support? -R_API RMmap *r_file_mmap(const char *file, bool rw, ut64 base) { +RZ_API RMmap *rz_file_mmap(const char *file, bool rw, ut64 base) { RMmap *m = NULL; int fd = -1; - if (!rw && !r_file_exists (file)) { + if (!rw && !rz_file_exists (file)) { return m; } - fd = r_sandbox_open (file, rw? O_RDWR: O_RDONLY, 0644); + fd = rz_sandbox_open (file, rw? O_RDWR: O_RDONLY, 0644); if (fd == -1 && !rw) { - eprintf ("r_file_mmap: file does not exis.\n"); + eprintf ("rz_file_mmap: file does not exis.\n"); //m->buf = malloc (m->len); return m; } @@ -1009,17 +1009,17 @@ R_API RMmap *r_file_mmap(const char *file, bool rw, ut64 base) { return NULL; } #if __UNIX__ - return r_file_mmap_unix (m, fd); + return rz_file_mmap_unix (m, fd); #elif __WINDOWS__ close (fd); m->fd = -1; - return r_file_mmap_windows (m, file); + return rz_file_mmap_windows (m, file); #else return file_mmap_other (m); #endif } -R_API void r_file_mmap_free(RMmap *m) { +RZ_API void rz_file_mmap_free(RMmap *m) { if (!m) { return; } @@ -1046,34 +1046,34 @@ R_API void r_file_mmap_free(RMmap *m) { free (m); } -R_API char *r_file_temp (const char *prefix) { +RZ_API char *rz_file_temp (const char *prefix) { if (!prefix) { prefix = ""; } - char *path = r_file_tmpdir (); - char *res = r_str_newf ("%s/%s.%"PFMT64x, path, prefix, r_time_now ()); + char *path = rz_file_tmpdir (); + char *res = rz_str_newf ("%s/%s.%"PFMT64x, path, prefix, rz_time_now ()); free (path); return res; } -R_API int r_file_mkstemp(R_NULLABLE const char *prefix, char **oname) { +RZ_API int rz_file_mkstemp(R_NULLABLE const char *prefix, char **oname) { int h = -1; - char *path = r_file_tmpdir (); + char *path = rz_file_tmpdir (); if (!prefix) { prefix = "r2"; } #if __WINDOWS__ LPTSTR name = NULL; - LPTSTR path_ = r_sys_conv_utf8_to_win (path); - LPTSTR prefix_ = r_sys_conv_utf8_to_win (prefix); + LPTSTR path_ = rz_sys_conv_utf8_to_win (path); + LPTSTR prefix_ = rz_sys_conv_utf8_to_win (prefix); name = (LPTSTR)malloc (sizeof (TCHAR) * (MAX_PATH + 1)); if (!name) { goto err_r_file_mkstemp; } if (GetTempFileName (path_, prefix_, 0, name)) { - char *name_ = r_sys_conv_win_to_utf8 (name); - h = r_sandbox_open (name_, O_RDWR|O_EXCL|O_BINARY, 0644); + char *name_ = rz_sys_conv_win_to_utf8 (name); + h = rz_sandbox_open (name_, O_RDWR|O_EXCL|O_BINARY, 0644); if (oname) { if (h != -1) { *oname = name_; @@ -1095,13 +1095,13 @@ err_r_file_mkstemp: if (suffix) { suffix++; - r_str_ncpy (pfxx, prefix, (size_t)(suffix - prefix)); + rz_str_ncpy (pfxx, prefix, (size_t)(suffix - prefix)); prefix = pfxx; } else { suffix = ""; } - char *name = r_str_newf ("%s/r2.%s.XXXXXX%s", path, prefix, suffix); + char *name = rz_str_newf ("%s/r2.%s.XXXXXX%s", path, prefix, suffix); mode_t mask = umask (S_IWGRP | S_IWOTH); if (suffix && *suffix) { #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) && 2 <= __GLIBC__ && 19 <= __GLIBC__MINOR__ @@ -1130,7 +1130,7 @@ err_r_file_mkstemp: return h; } -R_API char *r_file_tmpdir(void) { +RZ_API char *rz_file_tmpdir(void) { #if __WINDOWS__ LPTSTR tmpdir; char *path = NULL; @@ -1141,18 +1141,18 @@ R_API char *r_file_tmpdir(void) { return NULL; } if ((len = GetTempPath (MAX_PATH + 1, tmpdir)) == 0) { - path = r_sys_getenv ("TEMP"); + path = rz_sys_getenv ("TEMP"); if (!path) { path = strdup ("C:\\WINDOWS\\Temp\\"); } } else { tmpdir[len] = 0; - DWORD (WINAPI *glpn)(LPCTSTR, LPCTSTR, DWORD) = r_lib_dl_sym (GetModuleHandle (TEXT ("kernel32.dll")), W32_TCALL("GetLongPathName")); + DWORD (WINAPI *glpn)(LPCTSTR, LPCTSTR, DWORD) = rz_lib_dl_sym (GetModuleHandle (TEXT ("kernel32.dll")), W32_TCALL("GetLongPathName")); if (glpn) { // Windows XP sometimes returns short path name glpn (tmpdir, tmpdir, MAX_PATH + 1); } - path = r_sys_conv_win_to_utf8 (tmpdir); + path = rz_sys_conv_win_to_utf8 (tmpdir); } free (tmpdir); // Windows 7, stat() function fail if tmpdir ends with '\\' @@ -1163,109 +1163,109 @@ R_API char *r_file_tmpdir(void) { } } #else - char *path = r_sys_getenv ("TMPDIR"); + char *path = rz_sys_getenv ("TMPDIR"); if (path && !*path) { R_FREE (path); } if (!path) { #if __ANDROID__ - path = strdup ("/data/data/org.radare.radare2installer/radare2/tmp"); + path = strdup ("/data/data/org.radare.rizininstaller/rizin/tmp"); #else path = strdup ("/tmp"); #endif } #endif - if (!r_file_is_directory (path)) { + if (!rz_file_is_directory (path)) { eprintf ("Cannot find temporary directory '%s'\n", path); } return path; } -R_API bool r_file_copy (const char *src, const char *dst) { +RZ_API bool rz_file_copy (const char *src, const char *dst) { /* TODO: implement in C */ /* TODO: Use NO_CACHE for iOS dyldcache copying */ #if HAVE_COPYFILE_H return copyfile (src, dst, 0, COPYFILE_DATA | COPYFILE_XATTR) != -1; #elif __WINDOWS__ - PTCHAR s = r_sys_conv_utf8_to_win (src); - PTCHAR d = r_sys_conv_utf8_to_win (dst); + PTCHAR s = rz_sys_conv_utf8_to_win (src); + PTCHAR d = rz_sys_conv_utf8_to_win (dst); if (!s || !d) { - R_LOG_ERROR ("r_file_copy: Failed to allocate memory\n"); + R_LOG_ERROR ("rz_file_copy: Failed to allocate memory\n"); free (s); free (d); return false; } bool ret = CopyFile (s, d, 0); if (!ret) { - r_sys_perror ("r_file_copy"); + rz_sys_perror ("rz_file_copy"); } free (s); free (d); return ret; #else - char *src2 = r_str_replace (strdup (src), "'", "\\'", 1); - char *dst2 = r_str_replace (strdup (dst), "'", "\\'", 1); - int rc = r_sys_cmdf ("cp -f '%s' '%s'", src2, dst2); + char *src2 = rz_str_replace (strdup (src), "'", "\\'", 1); + char *dst2 = rz_str_replace (strdup (dst), "'", "\\'", 1); + int rc = rz_sys_cmdf ("cp -f '%s' '%s'", src2, dst2); free (src2); free (dst2); return rc == 0; #endif } -static void recursive_search_glob (const char *path, const char *glob, RList* list, int depth) { +static void recursive_search_glob (const char *path, const char *glob, RzList* list, int depth) { if (depth < 1) { return; } char* file; - RListIter *iter; - RList *dir = r_sys_dir (path); - r_list_foreach (dir, iter, file) { + RzListIter *iter; + RzList *dir = rz_sys_dir (path); + rz_list_foreach (dir, iter, file) { if (!strcmp (file, ".") || !strcmp (file, "..")) { continue; } char *filename = malloc (strlen (path) + strlen (file) + 2); strcpy (filename, path); strcat (filename, file); - if (r_file_is_directory (filename)) { + if (rz_file_is_directory (filename)) { strcat (filename, R_SYS_DIR); recursive_search_glob (filename, glob, list, depth - 1); free (filename); - } else if (r_str_glob (file, glob)) { - r_list_append (list, filename); + } else if (rz_str_glob (file, glob)) { + rz_list_append (list, filename); } else { free (filename); } } - r_list_free (dir); + rz_list_free (dir); } -R_API RList* r_file_globsearch (const char *_globbed_path, int maxdepth) { +RZ_API RzList* rz_file_globsearch (const char *_globbed_path, int maxdepth) { char *globbed_path = strdup (_globbed_path); - RList *files = r_list_newf (free); + RzList *files = rz_list_newf (free); char *glob = strchr (globbed_path, '*'); if (!glob) { - r_list_append (files, strdup (globbed_path)); + rz_list_append (files, strdup (globbed_path)); } else { *glob = '\0'; - char *last_slash = (char *)r_str_last (globbed_path, R_SYS_DIR); + char *last_slash = (char *)rz_str_last (globbed_path, R_SYS_DIR); *glob = '*'; char *path, *glob_ptr; if (last_slash) { glob_ptr = last_slash + 1; if (globbed_path[0] == '~') { - char *rpath = r_str_newlen (globbed_path + 2, last_slash - globbed_path - 1); - path = r_str_home (rpath ? rpath : ""); + char *rpath = rz_str_newlen (globbed_path + 2, last_slash - globbed_path - 1); + path = rz_str_home (rpath ? rpath : ""); free (rpath); } else { - path = r_str_newlen (globbed_path, last_slash - globbed_path + 1); + path = rz_str_newlen (globbed_path, last_slash - globbed_path + 1); } } else { glob_ptr = globbed_path; - path = r_str_newf (".%s", R_SYS_DIR); + path = rz_str_newf (".%s", R_SYS_DIR); } if (!path) { - r_list_free (files); + rz_list_free (files); free (globbed_path); return NULL; } diff --git a/librz/util/flist.c b/librz/util/flist.c new file mode 100644 index 0000000000..eb47d3856b --- /dev/null +++ b/librz/util/flist.c @@ -0,0 +1,86 @@ +/* radare - LGPL - Copyright 2010-2013 - pancake */ +// XXX. this is dupped inside the rz_flist.h for optimizations + +int rz_flist_iterator(void **x) { + return *x!=0; +} +void** rz_flist_next(void **x) { + return x; +} +void** rz_flist_get(void **x) { + return *(x++); +} +// XXX: forced free?? We need RFlist struct here +#include +//#include +// NOTE: reimplemnetation of rz_flist in C (if no RZ_API defined) + +#if 1 +#define rz_flist_t void** +#define RFList void** +#define rz_flist_rewind(it) for (; (it)!=*(it); (it)--) {} (it)++ +#define rz_flist_next(it) *(it)!=0 +#define rz_flist_get(it) *((it)++) +#define rz_flist_iterator(x) x +#define rz_flist_unref(x) x +#endif + +RZ_API void **rz_flist_new(int n) { + void **it; + if (!(it = (void **)calloc (n + 2, sizeof (void*)))) { + return NULL; + } + *it = it; + memset (++it, 0, (n + 1) * sizeof (void*)); + return it; +} + +// XXX. this is wrong :? +RZ_API void **rz_flist_resize(void **it, int n) { + rz_flist_rewind (it); + it--; + it = realloc (it, ((n+2) * sizeof (void*))); + *it = it; + return it+1; +} + +RZ_API void **rz_flist_prev(void **it) { + void **p = it--; + return (it==*it)?p:it; +} + +RZ_API void rz_flist_set(void **it, int idx, void *data) { + rz_flist_rewind (it); + it[idx] = data; +} + +RZ_API void rz_flist_delete(void **it, int idx) { + rz_flist_rewind (it); + free (it[idx]); + it[idx] = NULL; + for (it += idx; *it; it++) { + *it = *(it + 1); + } +} + +#define rz_flist_foreach(it, pos) \ + rz_flist_rewind(it); \ + while (rz_flist_next (it) && ((pos) = rz_flist_get (it))) + +RZ_API void rz_flist_free(void **it) { + void *pos; + rz_flist_foreach (it, pos) { + free (pos); + } + rz_flist_rewind (it); + free (--it); +} + +RZ_API int rz_flist_length (void **it) { + void *pos; + int len = 0; + rz_flist_foreach (it, pos) { + len++; + } + return len; +} diff --git a/libr/util/format.c b/librz/util/format.c similarity index 88% rename from libr/util/format.c rename to librz/util/format.c index b665f2a09c..88fdedea45 100644 --- a/libr/util/format.c +++ b/librz/util/format.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2007-2020 - pancake & Skia */ -#include "r_cons.h" -#include "r_util.h" -#include "r_util/r_print.h" -#include "r_reg.h" +#include "rz_cons.h" +#include "rz_util.h" +#include "rz_util/rz_print.h" +#include "rz_reg.h" #ifdef _MSC_VER #include #endif @@ -43,34 +43,34 @@ static float updateAddr(const ut8 *buf, int len, int endian, ut64 *addr, ut64 *a return 0; } if (len >= sizeof (float)) { - r_mem_swaporcopy ((ut8*)&f, buf, sizeof (float), endian); + rz_mem_swaporcopy ((ut8*)&f, buf, sizeof (float), endian); } if (addr && len > 3) { - ut32 tmpaddr = r_read_ble32 (buf, endian); + ut32 tmpaddr = rz_read_ble32 (buf, endian); *addr = (ut64)tmpaddr; } if (addr64 && len > 7) { - *addr64 = r_read_ble64 (buf, endian); + *addr64 = rz_read_ble64 (buf, endian); } return f; } -static int r_get_size(RNum *num, ut8 *buf, int endian, const char *s) { +static int rz_get_size(RNum *num, ut8 *buf, int endian, const char *s) { int size = 0, len = strlen (s); if (s[0] == '*' && len >= 4) { // value pointed by the address ut64 addr; - int offset = (int)r_num_math (num, s + 1); + int offset = (int)rz_num_math (num, s + 1); (void)updateAddr (buf + offset, 999, endian, &addr, NULL); return addr; } // flag handling doesnt seems to work here - return size = r_num_math (num, s); + return size = rz_num_math (num, s); } -static void r_print_format_u128(const RPrint* p, int endian, int mode, +static void rz_print_format_u128(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { - ut64 low = r_read_ble64 (buf, endian); - ut64 hig = r_read_ble64 (buf + 8, endian); + ut64 low = rz_read_ble64 (buf, endian); + ut64 hig = rz_read_ble64 (buf + 8, endian); if (MUSTSEEJSON) { p->cb_printf ("\""); } else if (!SEEVALUE && !ISQUIET) { @@ -89,7 +89,7 @@ static void r_print_format_u128(const RPrint* p, int endian, int mode, } } -static void r_print_format_quadword(const RPrint* p, int endian, int mode, +static void rz_print_format_quadword(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr64; int elem = -1; @@ -164,7 +164,7 @@ static void r_print_format_quadword(const RPrint* p, int endian, int mode, } } -static void r_print_format_byte(const RPrint* p, int endian, int mode, +static void rz_print_format_byte(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { int elem = -1; if (size >= ARRAYINDEX_COEF) { @@ -230,7 +230,7 @@ static void r_print_format_byte(const RPrint* p, int endian, int mode, } // Return number of consumed bytes -static int r_print_format_uleb(const RPrint* p, int endian, int mode, +static int rz_print_format_uleb(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { int elem = -1; int s = 0, offset = 0; @@ -243,12 +243,12 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode, ut8 *tmp; char *nbr; do { - r_uleb128_decode (buf+i, &s, &value); + rz_uleb128_decode (buf+i, &s, &value); i += s; offset += s; } while (elem--); - tmp = (ut8*) r_uleb128_encode (r_num_math (NULL, setval), &s); - nbr = r_hex_bin2strdup (tmp, s); + tmp = (ut8*) rz_uleb128_encode (rz_num_math (NULL, setval), &s); + nbr = rz_hex_bin2strdup (tmp, s); p->cb_printf ("\"wx %s\" @ 0x%08"PFMT64x"\n", nbr, seeki+offset-s); free (tmp); free (nbr); @@ -257,7 +257,7 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode, p->cb_printf ("0x%08" PFMT64x " = ", seeki); } if (size==-1) { - r_uleb128_decode (buf+i, &offset, &value); + rz_uleb128_decode (buf+i, &offset, &value); p->cb_printf ("%"PFMT64d, value); } else { if (!SEEVALUE) { @@ -265,7 +265,7 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode, } while (size--) { if (elem == -1 || elem == 0) { - r_uleb128_decode (buf+i, &s, &value); + rz_uleb128_decode (buf+i, &s, &value); i += s; offset += s; p->cb_printf ("%"PFMT64d, value); @@ -286,13 +286,13 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode, } } else if (MUSTSEEJSON || MUSTSEESTRUCT) { if (size==-1) { - r_uleb128_decode (buf+i, &offset, &value); + rz_uleb128_decode (buf+i, &offset, &value); p->cb_printf ("\"%"PFMT64d"\"", value); } else { p->cb_printf ("[ "); while (size--) { if (elem == -1 || elem == 0) { - r_uleb128_decode (buf+i, &s, &value); + rz_uleb128_decode (buf+i, &s, &value); i += s; offset += s; p->cb_printf ("\"%"PFMT64d"\"", value); @@ -316,7 +316,7 @@ static int r_print_format_uleb(const RPrint* p, int endian, int mode, return offset; } -static void r_print_format_char(const RPrint* p, int endian, int mode, +static void rz_print_format_char(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { int elem = -1; if (size >= ARRAYINDEX_COEF) { @@ -382,7 +382,7 @@ static void r_print_format_char(const RPrint* p, int endian, int mode, } } -static void r_print_format_decchar(const RPrint* p, int endian, int mode, +static void rz_print_format_decchar(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { int elem = -1; if (size >= ARRAYINDEX_COEF) { @@ -448,7 +448,7 @@ static void r_print_format_decchar(const RPrint* p, int endian, int mode, } } -static int r_print_format_string(const RPrint* p, ut64 seeki, ut64 addr64, ut64 addr, int is64, int mode) { +static int rz_print_format_string(const RPrint* p, ut64 seeki, ut64 addr64, ut64 addr, int is64, int mode) { ut8 buffer[255]; buffer[0] = 0; if (!p->iob.read_at) { @@ -458,13 +458,13 @@ static int r_print_format_string(const RPrint* p, ut64 seeki, ut64 addr64, ut64 const ut64 at = (is64 == 1)? addr64: (ut64)addr; int res = p->iob.read_at (p->iob.io, at, buffer, sizeof (buffer) - 8); if (MUSTSEEJSON) { - char *encstr = r_str_utf16_encode ((const char *)buffer, -1); + char *encstr = rz_str_utf16_encode ((const char *)buffer, -1); if (encstr) { p->cb_printf ("%d,\"string\":\"%s\"}", seeki, encstr); free (encstr); } } else if (MUSTSEESTRUCT) { - char *encstr = r_str_utf16_encode ((const char *)buffer, -1); + char *encstr = rz_str_utf16_encode ((const char *)buffer, -1); if (encstr) { p->cb_printf ("\"%s\"", encstr); free (encstr); @@ -493,7 +493,7 @@ static int r_print_format_string(const RPrint* p, ut64 seeki, ut64 addr64, ut64 return 0; } -static void r_print_format_time(const RPrint* p, int endian, int mode, +static void rz_print_format_time(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr; struct tm timestruct; @@ -510,7 +510,7 @@ static void r_print_format_time(const RPrint* p, int endian, int mode, if (!timestr) { return; } - r_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); + rz_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); *(timestr+24) = '\0'; if (!SEEVALUE && !ISQUIET) { p->cb_printf ("0x%08" PFMT64x " = ", seeki + ((elem >= 0) ? elem * 4 : 0)); @@ -523,7 +523,7 @@ static void r_print_format_time(const RPrint* p, int endian, int mode, } while (size--) { updateAddr (buf + i, size - i, endian, &addr, NULL); - r_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); + rz_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); *(timestr+24) = '\0'; if (elem == -1 || elem == 0) { p->cb_printf ("%s", timestr); @@ -549,7 +549,7 @@ static void r_print_format_time(const RPrint* p, int endian, int mode, if (!timestr) { return; } - r_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); + rz_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); *(timestr+24) = '\0'; if (size==-1) { p->cb_printf ("\"%s\"", timestr); @@ -557,7 +557,7 @@ static void r_print_format_time(const RPrint* p, int endian, int mode, p->cb_printf ("[ "); while (size--) { updateAddr (buf + i, size - i, endian, &addr, NULL); - r_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); + rz_asctime_r (gmtime_r ((time_t*)&addr, ×truct), timestr, ASCTIME_BUF_MINLEN); *(timestr+24) = '\0'; if (elem == -1 || elem == 0) { p->cb_printf ("\"%s\"", timestr); @@ -583,7 +583,7 @@ static void r_print_format_time(const RPrint* p, int endian, int mode, } // TODO: support unsigned int? -static void r_print_format_hex(const RPrint* p, int endian, int mode, +static void rz_print_format_hex(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr; int elem = -1; @@ -665,7 +665,7 @@ static void r_print_format_hex(const RPrint* p, int endian, int mode, } } -static void r_print_format_int(const RPrint* p, int endian, int mode, +static void rz_print_format_int(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr; int elem = -1; @@ -735,7 +735,7 @@ static void r_print_format_int(const RPrint* p, int endian, int mode, } } -static int r_print_format_disasm(const RPrint* p, ut64 seeki, int size) { +static int rz_print_format_disasm(const RPrint* p, ut64 seeki, int size) { ut64 prevseeki = seeki; if (!p->disasm || !p->user) { @@ -751,7 +751,7 @@ static int r_print_format_disasm(const RPrint* p, ut64 seeki, int size) { return seeki - prevseeki; } -static void r_print_format_octal(const RPrint* p, int endian, int mode, +static void rz_print_format_octal(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr; int elem = -1; @@ -828,7 +828,7 @@ static void r_print_format_octal(const RPrint* p, int endian, int mode, } } -static void r_print_format_hexflag(const RPrint* p, int endian, int mode, +static void rz_print_format_hexflag(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr = 0; int elem = -1; @@ -906,7 +906,7 @@ static void r_print_format_hexflag(const RPrint* p, int endian, int mode, } } -static int r_print_format_10bytes(const RPrint* p, int mode, const char *setval, +static int rz_print_format_10bytes(const RPrint* p, int mode, const char *setval, ut64 seeki, ut64 addr, ut8* buf) { ut8 buffer[255]; int j; @@ -961,7 +961,7 @@ static int r_print_format_10bytes(const RPrint* p, int mode, const char *setval, return 0; } -static int r_print_format_hexpairs(const RPrint* p, int endian, int mode, +static int rz_print_format_hexpairs(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { int j; size = (size == -1) ? 1 : size; @@ -1008,7 +1008,7 @@ static int r_print_format_hexpairs(const RPrint* p, int endian, int mode, return size; } -static void r_print_format_float(const RPrint* p, int endian, int mode, +static void rz_print_format_float(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { float val_f = 0.0f; ut64 addr = 0; @@ -1063,7 +1063,7 @@ static void r_print_format_float(const RPrint* p, int endian, int mode, } -static void r_print_format_double(const RPrint* p, int endian, int mode, +static void rz_print_format_double(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { double val_f = 0.0; ut64 addr = 0; @@ -1073,7 +1073,7 @@ static void r_print_format_double(const RPrint* p, int endian, int mode, size %= ARRAYINDEX_COEF; } updateAddr (buf + i, 999, endian, &addr, NULL); - r_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (double), endian); + rz_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (double), endian); if (MUSTSET) { p->cb_printf ("wv8 %s @ 0x%08"PFMT64x"\n", setval, seeki + ((elem >= 0) ? elem * 8 : 0)); @@ -1095,7 +1095,7 @@ static void r_print_format_double(const RPrint* p, int endian, int mode, while (size--) { // XXX this 999 is scary updateAddr (buf + i, 9999, endian, &addr, NULL); - r_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (double), endian); + rz_mem_swaporcopy ((ut8*)&val_f, buf + i, sizeof (double), endian); if (elem == -1 || elem == 0) { p->cb_printf ("%.17g", val_f); if (elem == 0) { @@ -1120,7 +1120,7 @@ static void r_print_format_double(const RPrint* p, int endian, int mode, } } -static void r_print_format_word(const RPrint* p, int endian, int mode, +static void rz_print_format_word(const RPrint* p, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { ut64 addr; int elem = -1; @@ -1216,12 +1216,12 @@ static void r_print_format_word(const RPrint* p, int endian, int mode, } } -static void r_print_byte_escape(const RPrint* p, const char *src, char **dst, int dot_nl) { - r_return_if_fail (p->strconv_mode); - r_str_byte_escape (src, dst, dot_nl, !strcmp (p->strconv_mode, "asciidot"), p->esc_bslash); +static void rz_print_byte_escape(const RPrint* p, const char *src, char **dst, int dot_nl) { + rz_return_if_fail (p->strconv_mode); + rz_str_byte_escape (src, dst, dot_nl, !strcmp (p->strconv_mode, "asciidot"), p->esc_bslash); } -static void r_print_format_nulltermstring(const RPrint* p, int len, int endian, int mode, +static void rz_print_format_nulltermstring(const RPrint* p, int len, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { if (!p->iob.is_valid_offset (p->iob.io, seeki, 1)) { ut8 ch = 0xff; @@ -1234,7 +1234,7 @@ static void r_print_format_nulltermstring(const RPrint* p, int len, int endian, if (p->flags & R_PRINT_FLAGS_UNALLOC && !(p->iob.io->cached & R_PERM_R)) { ut64 total_map_left = 0; ut64 addr = seeki; - RIOMap *map; + RzIOMap *map; while (total_map_left < len && (map = p->iob.io->va ? p->iob.map_get (p->iob.io, addr) @@ -1251,7 +1251,7 @@ static void r_print_format_nulltermstring(const RPrint* p, int len, int endian, len = total_map_left; } } - int str_len = r_str_nlen ((char *)buf + i, len - i); + int str_len = rz_str_nlen ((char *)buf + i, len - i); bool overflow = (size == -1 || size > len - i) && str_len == len - i; if (MUSTSET) { int buflen = strlen ((const char *)buf + seeki); @@ -1304,14 +1304,14 @@ static void r_print_format_nulltermstring(const RPrint* p, int len, int endian, for (; j < len && ((size == -1 || size-- > 0) && buf[j]) ; j++) { char esc_str[5] = { 0 }; char *ptr = esc_str; - r_print_byte_escape (p, (char *)&buf[j], &ptr, false); + rz_print_byte_escape (p, (char *)&buf[j], &ptr, false); p->cb_printf ("%s", esc_str); } p->cb_printf ("\""); } else if (MUSTSEEJSON) { char *utf_encoded_buf = NULL; p->cb_printf ("\""); - utf_encoded_buf = r_str_escape_utf8_for_json ( + utf_encoded_buf = rz_str_escape_utf8_for_json ( (char *)buf + i, size == -1 ? str_len : R_MIN (size, str_len)); if (utf_encoded_buf){ p->cb_printf ("%s", utf_encoded_buf); @@ -1325,7 +1325,7 @@ static void r_print_format_nulltermstring(const RPrint* p, int len, int endian, } } -static void r_print_format_nulltermwidestring(const RPrint* p, const int len, int endian, int mode, +static void rz_print_format_nulltermwidestring(const RPrint* p, const int len, int endian, int mode, const char *setval, ut64 seeki, ut8* buf, int i, int size) { if (MUSTSET) { int vallen = strlen(setval); @@ -1337,7 +1337,7 @@ static void r_print_format_nulltermwidestring(const RPrint* p, const int len, in newstring++; vallen -= 2; } - if ((size = vallen) > r_wstr_clen((char*)(buf+seeki))) { + if ((size = vallen) > rz_wstr_clen((char*)(buf+seeki))) { eprintf ("Warning: new string is longer than previous one\n"); } p->cb_printf ("ww %s @ 0x%08"PFMT64x"\n", newstring, seeki); @@ -1368,14 +1368,14 @@ static void r_print_format_nulltermwidestring(const RPrint* p, const int len, in } } -static void r_print_format_bitfield(const RPrint* p, ut64 seeki, char *fmtname, +static void rz_print_format_bitfield(const RPrint* p, ut64 seeki, char *fmtname, char *fieldname, ut64 addr, int mode, int size) { char *bitfield = NULL; addr &= (1ULL << (size * 8)) - 1; if (MUSTSEE && !SEEVALUE) { p->cb_printf ("0x%08"PFMT64x" = ", seeki); } - bitfield = r_type_enum_getbitfield (p->sdb_types, fmtname, addr); + bitfield = rz_type_enum_getbitfield (p->sdb_types, fmtname, addr); if (bitfield && *bitfield) { if (MUSTSEEJSON) { p->cb_printf ("\"%s\"}", bitfield); @@ -1393,14 +1393,14 @@ static void r_print_format_bitfield(const RPrint* p, ut64 seeki, char *fmtname, free (bitfield); } -static void r_print_format_enum(const RPrint* p, ut64 seeki, char *fmtname, +static void rz_print_format_enum(const RPrint* p, ut64 seeki, char *fmtname, char *fieldname, ut64 addr, int mode, int size) { char *enumvalue = NULL; addr &= (1ULL << (size * 8)) - 1; if (MUSTSEE && !SEEVALUE) { p->cb_printf ("0x%08"PFMT64x" = ", seeki); } - enumvalue = r_type_enum_member (p->sdb_types, fmtname, NULL, addr); + enumvalue = rz_type_enum_member (p->sdb_types, fmtname, NULL, addr); if (enumvalue && *enumvalue) { if (mode & R_PRINT_DOT) { p->cb_printf ("%s.%s", fmtname, enumvalue); @@ -1424,12 +1424,12 @@ static void r_print_format_enum(const RPrint* p, ut64 seeki, char *fmtname, free (enumvalue); } -static void r_print_format_register(const RPrint* p, int mode, +static void rz_print_format_register(const RPrint* p, int mode, const char *name, const char *setval) { if (!p || !p->get_register || !p->reg) { return; } - RRegItem *ri = p->get_register (p->reg, name, R_REG_TYPE_ALL); + RzRegItem *ri = p->get_register (p->reg, name, R_REG_TYPE_ALL); if (ri) { if (MUSTSET) { p->cb_printf ("dr %s=%s\n", name, setval); @@ -1447,7 +1447,7 @@ static void r_print_format_register(const RPrint* p, int mode, } } -static void r_print_format_num_specifier(const RPrint *p, ut64 addr, int bytes, int sign) { +static void rz_print_format_num_specifier(const RPrint *p, ut64 addr, int bytes, int sign) { #define EXT(T) (sign ? (signed T)(addr) : (unsigned T)(addr) ) const char *fs64 = sign ? "%"PFMT64d : "%"PFMT64u; const char *fs = sign ? "%d" : "%u"; @@ -1463,7 +1463,7 @@ static void r_print_format_num_specifier(const RPrint *p, ut64 addr, int bytes, #undef EXT } -static void r_print_format_num(const RPrint *p, int endian, int mode, const char *setval, ut64 seeki, ut8 *buf, int i, int bytes, int sign, int size) { +static void rz_print_format_num(const RPrint *p, int endian, int mode, const char *setval, ut64 seeki, ut8 *buf, int i, int bytes, int sign, int size) { ut64 addr = 0LL; int elem = -1; if (size >= ARRAYINDEX_COEF) { @@ -1478,13 +1478,13 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char if (MUSTSET) { p->cb_printf ("wv%d %s @ 0x%08"PFMT64x"\n", bytes, setval, seeki+((elem>=0)?elem*(bytes):0)); } else if ((mode & R_PRINT_DOT) || MUSTSEESTRUCT) { - r_print_format_num_specifier (p, addr, bytes, sign); + rz_print_format_num_specifier (p, addr, bytes, sign); } else if (MUSTSEE) { if (!SEEVALUE && !ISQUIET) { p->cb_printf ("0x%08"PFMT64x" = ", seeki + ((elem >= 0)? elem * bytes: 0)); } if (size == -1) { - r_print_format_num_specifier (p, addr, bytes, sign); + rz_print_format_num_specifier (p, addr, bytes, sign); } else { if (!SEEVALUE) { p->cb_printf ("[ "); @@ -1496,7 +1496,7 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char updateAddr (buf + i, size - i, endian, &addr, NULL); } if (elem == -1 || elem == 0) { - r_print_format_num_specifier (p, addr, bytes, sign); + rz_print_format_num_specifier (p, addr, bytes, sign); if (elem == 0) { elem = -2; } @@ -1515,7 +1515,7 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char } } else if (MUSTSEEJSON) { if (size == -1) { - r_print_format_num_specifier (p, addr, bytes, sign); + rz_print_format_num_specifier (p, addr, bytes, sign); } else { p->cb_printf ("[ "); while (size--) { @@ -1525,7 +1525,7 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char updateAddr (buf + i, size, endian, &addr, NULL); } if (elem == -1 || elem == 0) { - r_print_format_num_specifier (p, addr, bytes, sign); + rz_print_format_num_specifier (p, addr, bytes, sign); if (elem == 0) { elem = -2; } @@ -1544,12 +1544,12 @@ static void r_print_format_num(const RPrint *p, int endian, int mode, const char } } -R_API const char *r_print_format_byname(RPrint *p, const char *name) { +RZ_API const char *rz_print_format_byname(RPrint *p, const char *name) { return sdb_const_get (p->formats, name, NULL); } // XXX: this is somewhat incomplete. must be updated to handle all format chars -R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) { +RZ_API int rz_print_format_struct_size(RPrint *p, const char *f, int mode, int n) { char *end, *args, *fmt; int size = 0, tabsize = 0, i, idx = 0, biggest = 0, fmt_len = 0, times = 1; bool tabsize_set = false; @@ -1590,7 +1590,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) return -1; } *end = '\0'; - times = r_num_math (NULL, fmt + i + 1); + times = rz_num_math (NULL, fmt + i + 1); fmt = end + 1; i = 0; } @@ -1601,7 +1601,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) mode &= ~R_PRINT_UNIONMODE; } - int words = r_str_word_set0_stack (args); + int words = rz_str_word_set0_stack (args); fmt_len = strlen (fmt); for (; i < fmt_len; i++) { if (fmt[i] == '[') { @@ -1612,7 +1612,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) } *end = '\0'; tabsize_set = true; - tabsize = r_num_math (NULL, fmt + i + 1); + tabsize = rz_num_math (NULL, fmt + i + 1); *end = ']'; while (fmt[i++] != ']') { ; @@ -1681,14 +1681,14 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) if (words < idx) { eprintf ("Index out of bounds\n"); } else { - wordAtIndex = r_str_word_get0 (args, idx); + wordAtIndex = rz_str_word_get0 (args, idx); } if (!wordAtIndex) { break; } structname = strdup (wordAtIndex); if (*structname == '(') { - endname = (char*)r_str_rchr (structname, NULL, ')'); + endname = (char*)rz_str_rchr (structname, NULL, ')'); } else { free (structname); break; @@ -1711,7 +1711,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) return -1; } if (!format) { // Fetch format from types db - format = r_type_format (p->sdb_types, structname + 1); + format = rz_type_format (p->sdb_types, structname + 1); } } if (!format) { @@ -1720,7 +1720,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) free (o); return 0; } - int newsize = r_print_format_struct_size (p, format, mode, n + 1); + int newsize = rz_print_format_struct_size (p, format, mode, n + 1); if (newsize < 1) { eprintf ("Cannot find size for `%s'\n", format); free (structname); @@ -1808,7 +1808,7 @@ R_API int r_print_format_struct_size(RPrint *p, const char *f, int mode, int n) return (mode & R_PRINT_UNIONMODE)? biggest : size; } -static int r_print_format_struct(RPrint* p, ut64 seek, const ut8* b, int len, const char *name, +static int rz_print_format_struct(RPrint* p, ut64 seek, const ut8* b, int len, const char *name, int slide, int mode, const char *setval, char *field, int anon) { const char *fmt; char namefmt[128]; @@ -1822,7 +1822,7 @@ static int r_print_format_struct(RPrint* p, ut64 seek, const ut8* b, int len, co } else { fmt = sdb_get (p->formats, name, NULL); if (!fmt) { // Fetch struct info from types DB - fmt = r_type_format (p->sdb_types, name); + fmt = rz_type_format (p->sdb_types, name); } } if (!fmt || !*fmt) { @@ -1838,8 +1838,8 @@ static int r_print_format_struct(RPrint* p, ut64 seek, const ut8* b, int len, co } p->cb_printf ("<%s>\n", name); } - r_print_format (p, seek, b, len, fmt, mode, setval, field); - return r_print_format_struct_size (p, fmt, mode, 0); + rz_print_format (p, seek, b, len, fmt, mode, setval, field); + return rz_print_format_struct_size (p, fmt, mode, 0); } static char *get_args_offset(const char *arg) { @@ -1926,7 +1926,7 @@ static char *get_format_type(const char fmt, const char arg) { #define MINUSONE ((void*)(size_t)-1) #define ISSTRUCT (tmp == '?' || (tmp == '*' && *(arg+1) == '?')) -R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, +RZ_API int rz_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, const char *formatname, int mode, const char *setval, char *ofield) { int nargs, i, j, invalid, nexti, idx, times, otimes, endian, isptr = 0; const int old_bits = p->bits; @@ -1991,7 +1991,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, goto beach; } *end = '\0'; - times = r_num_math (NULL, bracket + 1); + times = rz_num_math (NULL, bracket + 1); arg = end + 1; } @@ -2010,13 +2010,13 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, tmp = *args; } args = strdup (args); - nargs = r_str_word_set0_stack (args); + nargs = rz_str_word_set0_stack (args); if (nargs == 0) { R_FREE (args); } for (i = 0; i < nargs; i++) { - const char *tmp = r_str_word_get0 (args, i); - const char *nm = r_str_rchr (tmp, NULL, ')'); + const char *tmp = rz_str_word_get0 (args, i); + const char *nm = rz_str_rchr (tmp, NULL, ')'); int len = strlen (nm ? nm + 1 : tmp); if (len > maxl) { maxl = len; @@ -2053,12 +2053,12 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, char *fmtname; if (formatname && *formatname) { if (strchr (formatname, ' ')) { - fmtname = r_str_newf ("0x%"PFMT64x, seek); + fmtname = rz_str_newf ("0x%"PFMT64x, seek); } else { fmtname = strdup (formatname); } } else { - fmtname = r_str_newf ("0x%"PFMT64x, seek); + fmtname = rz_str_newf ("0x%"PFMT64x, seek); } p->cb_printf ("digraph g { graph [ rank=same; rankdir=LR; ];\n"); p->cb_printf ("root [ rank=1; shape=record\nlabel=\"%s", fmtname); @@ -2100,13 +2100,13 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, goto beach; } *end = '\0'; - size = r_get_size (p->num, buf, endian, arg + 1); + size = rz_get_size (p->num, buf, endian, arg + 1); arg = end + 1; *end = ']'; } else { size = -1; } - int fs = r_print_format_struct_size (p, arg, 0, idx); + int fs = rz_print_format_struct_size (p, arg, 0, idx); if (fs == -2) { i = -1; goto beach; @@ -2148,11 +2148,11 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, *dot = '\0'; } free (oarg); - oarg = fieldname = strdup (r_str_word_get0 (args, idx)); + oarg = fieldname = strdup (rz_str_word_get0 (args, idx)); if (ISSTRUCT || tmp=='E' || tmp=='B' || tmp=='r') { if (*fieldname == '(') { fmtname = fieldname + 1; - fieldname = (char*)r_str_rchr (fieldname, NULL, ')'); + fieldname = (char*)rz_str_rchr (fieldname, NULL, ')'); if (fieldname) { *fieldname++ = '\0'; } else { @@ -2182,7 +2182,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, goto beach; } *end = '\0'; - elem = r_num_math (NULL, bracket + 1) + 1; // +1 to handle 0 index easily + elem = rz_num_math (NULL, bracket + 1) + 1; // +1 to handle 0 index easily for ( ; bracket < end; bracket++) { *bracket = '\0'; } @@ -2293,7 +2293,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, if (mode & R_PRINT_SEEFLAGS && isptr != NULLPTR) { char *newname = NULL; if (!fieldname) { - newname = fieldname = r_str_newf ("pf.%"PFMT64u, seeki); + newname = fieldname = rz_str_newf ("pf.%"PFMT64u, seeki); } if (mode & R_PRINT_UNIONMODE) { p->cb_printf ("f %s=0x%08"PFMT64x"\n", formatname, seeki); @@ -2383,71 +2383,71 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, // might go beyond its len and it's usually called in each of the following functions switch (tmp) { case 'u': - i += r_print_format_uleb (p, endian, mode, setval, seeki, buf, i, size); + i += rz_print_format_uleb (p, endian, mode, setval, seeki, buf, i, size); break; case 't': - r_print_format_time (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_time (p, endian, mode, setval, seeki, buf, i, size); i += (size==-1)? 4: 4 * size; break; case 'q': - r_print_format_quadword (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_quadword (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 8: 8 * size; break; case 'Q': - r_print_format_u128 (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_u128 (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 16: 16 * size; break; case 'b': - r_print_format_byte (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_byte (p, endian, mode, setval, seeki, buf, i, size); i += (size==-1)? 1: size; break; case 'C': - r_print_format_decchar (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_decchar (p, endian, mode, setval, seeki, buf, i, size); i += (size==-1)? 1: size; break; case 'c': - r_print_format_char (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_char (p, endian, mode, setval, seeki, buf, i, size); i += (size==-1)? 1: size; break; case 'X': - size = r_print_format_hexpairs (p, endian, mode, setval, seeki, buf, i, size); + size = rz_print_format_hexpairs (p, endian, mode, setval, seeki, buf, i, size); i += size; break; case 'T': - if (r_print_format_10bytes (p, mode, + if (rz_print_format_10bytes (p, mode, setval, seeki, addr, buf) == 0) { i += (size == -1)? 4: 4 * size; } break; case 'f': - r_print_format_float (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_float (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 4: 4 * size; break; case 'F': - r_print_format_double (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_double (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 8: 8 * size; break; case 'i': - r_print_format_int (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_int (p, endian, mode, setval, seeki, buf, i, size); i+= (size == -1)? 4: 4 * size; break; case 'd': //WHY?? help says: 0x%%08x hexadecimal value (4 bytes) - r_print_format_hex (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_hex (p, endian, mode, setval, seeki, buf, i, size); i+= (size == -1)? 4: 4 * size; break; case 'D': if (isptr) { if (p->bits == 64) { - i += r_print_format_disasm (p, addr64, size); + i += rz_print_format_disasm (p, addr64, size); } else { - i += r_print_format_disasm (p, addr, size); + i += rz_print_format_disasm (p, addr, size); } } else { - i += r_print_format_disasm (p, seeki, size); + i += rz_print_format_disasm (p, seeki, size); } break; case 'o': - r_print_format_octal (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_octal (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 4: 4 * size; break; case ';': @@ -2465,15 +2465,15 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, } break; case 'x': - r_print_format_hexflag (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_hexflag (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 4: 4*size; break; case 'w': - r_print_format_word (p, endian, mode, setval, seeki, buf, i, size); + rz_print_format_word (p, endian, mode, setval, seeki, buf, i, size); i += (size == -1)? 2: 2 * size; break; case 'z': // zero terminated string - r_print_format_nulltermstring (p, len, endian, mode, setval, seeki, buf, i, size); + rz_print_format_nulltermstring (p, len, endian, mode, setval, seeki, buf, i, size); if (size == -1) { i += strlen ((char*)buf + i) + 1; } else { @@ -2483,9 +2483,9 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, } break; case 'Z': // zero terminated wide string - r_print_format_nulltermwidestring (p, len, endian, mode, setval, seeki, buf, i, size); + rz_print_format_nulltermwidestring (p, len, endian, mode, setval, seeki, buf, i, size); if (size == -1) { - i += r_wstr_clen((char*)(buf+i))*2+2; + i += rz_wstr_clen((char*)(buf+i))*2+2; } else { while (size--) { i += 2; @@ -2493,12 +2493,12 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, } break; case 's': - if (r_print_format_string (p, seeki, addr64, addr, 0, mode) == 0) { + if (rz_print_format_string (p, seeki, addr64, addr, 0, mode) == 0) { i += (size==-1) ? 4 : 4*size; } break; case 'S': - if (r_print_format_string (p, seeki, addr64, addr, 1, mode) == 0) { + if (rz_print_format_string (p, seeki, addr64, addr, 1, mode) == 0) { i += (size == -1) ? 8 : 8 * size; } break; @@ -2506,19 +2506,19 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, if (size >= ARRAYINDEX_COEF) { size %= ARRAYINDEX_COEF; } - r_print_format_bitfield (p, seeki, fmtname, fieldname, addr, mode, size); + rz_print_format_bitfield (p, seeki, fmtname, fieldname, addr, mode, size); i+=(size == -1)? 1: size; break; case 'E': // resolve enum if (size >= ARRAYINDEX_COEF) { size %= ARRAYINDEX_COEF; } - r_print_format_enum (p, seeki, fmtname, fieldname, addr, mode, size); + rz_print_format_enum (p, seeki, fmtname, fieldname, addr, mode, size); i += (size == -1)? 1: size; break; case 'r': if (fmtname) { - r_print_format_register (p, mode, fmtname, setval); + rz_print_format_register (p, mode, fmtname, setval); } else { eprintf ("Unknown register\n"); } @@ -2580,7 +2580,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, //slide += (isptr) ? STRUCTPTR : NESTEDSTRUCT; slide += NESTEDSTRUCT; if (size == -1) { - s = r_print_format_struct (p, seeki, + s = rz_print_format_struct (p, seeki, buf + i, len - i, fmtname, slide, mode, setval, nxtfield, anon); i += (isptr) ? (p->bits / 8) : s; @@ -2604,7 +2604,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, } else { mode &= ~R_PRINT_MUSTSEE; } - s = r_print_format_struct (p, seek+i, + s = rz_print_format_struct (p, seek+i, buf+i, len-i, fmtname, slide, mode, setval, nxtfield, anon); if ((MUSTSEE || MUSTSEEJSON || MUSTSEESTRUCT) && size != 0 && elem == -1) { if (MUSTSEEJSON) { @@ -2654,7 +2654,7 @@ R_API int r_print_format(RPrint *p, ut64 seek, const ut8* b, const int len, break; //or goto beach;??? } - r_print_format_num (p, endian, mode, setval, seeki, buf, i, bytes, sign, size); + rz_print_format_num (p, endian, mode, setval, seeki, buf, i, bytes, sign, size); i += (size == -1)? bytes: size * bytes; arg++; break; diff --git a/libr/util/getopt.c b/librz/util/getopt.c similarity index 90% rename from libr/util/getopt.c rename to librz/util/getopt.c index 45a2747cca..ecd9492e55 100644 --- a/libr/util/getopt.c +++ b/librz/util/getopt.c @@ -5,14 +5,14 @@ * $Id: getopt.c,v 1.2 1998/01/21 22:27:05 billm Exp $ * */ -#include +#include #define BADCH (int)'?' #define BADARG (int)':' #define EMSG "" -R_API void r_getopt_init(RGetopt *opt, int argc, const char **argv, const char *ostr) { - memset (opt, 0, sizeof (RGetopt)); +RZ_API void rz_getopt_init(RzGetopt *opt, int argc, const char **argv, const char *ostr) { + memset (opt, 0, sizeof (RzGetopt)); opt->err = 1; opt->ind = 1; opt->opt = 0; @@ -23,7 +23,7 @@ R_API void r_getopt_init(RGetopt *opt, int argc, const char **argv, const char * opt->ostr = ostr; } -R_API int r_getopt_next(RGetopt *opt) { +RZ_API int rz_getopt_next(RzGetopt *opt) { static const char *place = EMSG; // option letter processing const char *oli; // option letter list index diff --git a/librz/util/graph.c b/librz/util/graph.c new file mode 100644 index 0000000000..c1b085ecf6 --- /dev/null +++ b/librz/util/graph.c @@ -0,0 +1,321 @@ +/* radare - LGPL - Copyright 2007-2020 - pancake, ret2libc */ + +#include + +enum { + WHITE_COLOR = 0, + GRAY_COLOR, + BLACK_COLOR +}; + +static RGraphNode *rz_graph_node_new (void *data) { + RGraphNode *p = R_NEW0 (RGraphNode); + if (p) { + p->data = data; + p->free = NULL; + p->out_nodes = rz_list_new (); + p->in_nodes = rz_list_new (); + p->all_neighbours = rz_list_new (); + } + return p; +} + +static void rz_graph_node_free (RGraphNode *n) { + if (!n) { + return; + } + if (n->free) { + n->free (n->data); + } + rz_list_free (n->out_nodes); + rz_list_free (n->in_nodes); + rz_list_free (n->all_neighbours); + free (n); +} + +static int node_cmp (unsigned int idx, RGraphNode *b) { + return idx == b->idx ? 0 : -1; +} + +// direction == true => forwards +static void dfs_node (RGraph *g, RGraphNode *n, RGraphVisitor *vis, int color[], const bool direction) { + if (!n) { + return; + } + RStack *s = rz_stack_new (2 * g->n_edges + 1); + if (!s) { + return; + } + RGraphEdge *edg = R_NEW0 (RGraphEdge); + if (!edg) { + rz_stack_free (s); + return; + } + edg->from = NULL; + edg->to = n; + rz_stack_push (s, edg); + while (!rz_stack_is_empty (s)) { + RGraphEdge *cur_edge = (RGraphEdge *)rz_stack_pop (s); + RGraphNode *v, *cur = cur_edge->to, *from = cur_edge->from; + RzListIter *it; + int i; + + if (from && cur) { + if (color[cur->idx] == WHITE_COLOR && vis->tree_edge) { + vis->tree_edge (cur_edge, vis); + } else if (color[cur->idx] == GRAY_COLOR && vis->back_edge) { + vis->back_edge (cur_edge, vis); + } else if (color[cur->idx] == BLACK_COLOR && vis->fcross_edge) { + vis->fcross_edge (cur_edge, vis); + } + } else if (!cur && from) { + if (color[from->idx] != BLACK_COLOR && vis->finish_node) { + vis->finish_node (from, vis); + } + color[from->idx] = BLACK_COLOR; + } + free (cur_edge); + if (!cur || color[cur->idx] != WHITE_COLOR) { + continue; + } + if (color[cur->idx] == WHITE_COLOR && vis->discover_node) { + vis->discover_node (cur, vis); + } + color[cur->idx] = GRAY_COLOR; + + edg = R_NEW0 (RGraphEdge); + if (!edg) { + break; + } + edg->from = cur; + rz_stack_push (s, edg); + + i = 0; + const RzList *neighbours = direction ? cur->out_nodes : cur->in_nodes; + rz_list_foreach (neighbours, it, v) { + edg = R_NEW (RGraphEdge); + edg->from = cur; + edg->to = v; + edg->nth = i++; + rz_stack_push (s, edg); + } + } + rz_stack_free (s); +} + +RZ_API RGraph *rz_graph_new(void) { + RGraph *t = R_NEW0 (RGraph); + if (!t) { + return NULL; + } + t->nodes = rz_list_new (); + if (!t->nodes) { + rz_graph_free(t); + return NULL; + } + t->nodes->free = (RzListFree)rz_graph_node_free; + t->n_nodes = 0; + t->last_index = 0; + return t; +} + +RZ_API void rz_graph_free(RGraph* t) { + rz_list_free (t->nodes); + free (t); +} + +RZ_API RGraphNode *rz_graph_get_node(const RGraph *t, unsigned int idx) { + RzListIter *it = rz_list_find (t->nodes, (void *)(size_t)idx, (RzListComparator)node_cmp); + if (!it) { + return NULL; + } + return (RGraphNode *)it->data; +} + +RZ_API RzListIter *rz_graph_node_iter(const RGraph *t, unsigned int idx) { + return rz_list_find (t->nodes, (void *)(size_t)idx, (RzListComparator)node_cmp); +} + +RZ_API void rz_graph_reset (RGraph *t) { + rz_list_free (t->nodes); + t->nodes = rz_list_new (); + if (!t->nodes) { + return; + } + t->nodes->free = (RzListFree)rz_graph_node_free; + t->n_nodes = 0; + t->n_edges = 0; + t->last_index = 0; +} + +RZ_API RGraphNode *rz_graph_add_node(RGraph *t, void *data) { + if (!t) { + return NULL; + } + RGraphNode *n = rz_graph_node_new (data); + if (!n) { + return NULL; + } + n->idx = t->last_index++; + rz_list_append (t->nodes, n); + t->n_nodes++; + return n; +} + +/* remove the node from the graph and free the node */ +/* users of this function should be aware they can't access n anymore */ +RZ_API void rz_graph_del_node(RGraph *t, RGraphNode *n) { + RGraphNode *gn; + RzListIter *it; + if (!n) { + return; + } + rz_list_foreach (n->in_nodes, it, gn) { + rz_list_delete_data (gn->out_nodes, n); + rz_list_delete_data (gn->all_neighbours, n); + t->n_edges--; + } + + rz_list_foreach (n->out_nodes, it, gn) { + rz_list_delete_data (gn->in_nodes, n); + rz_list_delete_data (gn->all_neighbours, n); + t->n_edges--; + } + + rz_list_delete_data (t->nodes, n); + t->n_nodes--; +} + +RZ_API void rz_graph_add_edge(RGraph *t, RGraphNode *from, RGraphNode *to) { + rz_graph_add_edge_at (t, from, to, -1); +} + +RZ_API void rz_graph_add_edge_at (RGraph *t, RGraphNode *from, RGraphNode *to, int nth) { + if (from && to) { + rz_list_insert (from->out_nodes, nth, to); + rz_list_append (from->all_neighbours, to); + rz_list_append (to->in_nodes, from); + rz_list_append (to->all_neighbours, from); + t->n_edges++; + } +} + +// splits the "split_me", so that new node has it's outnodes +RZ_API RGraphNode *rz_graph_node_split_forward(RGraph *g, RGraphNode *split_me, void *data) { + RGraphNode *front = rz_graph_add_node(g, data); + RzList *tmp = front->out_nodes; + front->out_nodes = split_me->out_nodes; + split_me->out_nodes = tmp; + RzListIter *iter; + RGraphNode *n; + rz_list_foreach (front->out_nodes, iter, n) { + rz_list_delete_data (n->in_nodes, split_me); // optimize me + rz_list_delete_data (n->all_neighbours, split_me); // boy this all_neighbours is so retarding perf here + rz_list_delete_data (split_me->all_neighbours, n); + rz_list_append (n->all_neighbours, front); + rz_list_append (n->in_nodes, front); + rz_list_append (front->all_neighbours, n); + } + return front; +} + + +RZ_API void rz_graph_del_edge(RGraph *t, RGraphNode *from, RGraphNode *to) { + if (!from || !to || !rz_graph_adjacent (t, from, to)) { + return; + } + rz_list_delete_data (from->out_nodes, to); + rz_list_delete_data (from->all_neighbours, to); + rz_list_delete_data (to->in_nodes, from); + rz_list_delete_data (to->all_neighbours, from); + t->n_edges--; +} + +// XXX remove comments and static inline all this crap +/* returns the list of nodes reachable from `n` */ +RZ_API const RzList *rz_graph_get_neighbours(const RGraph *g, const RGraphNode *n) { + return n? n->out_nodes: NULL; +} + +/* returns the n-th nodes reachable from the give node `n`. + * This, of course, depends on the order of the nodes. */ +RZ_API RGraphNode *rz_graph_nth_neighbour(const RGraph *g, const RGraphNode *n, int nth) { + return n? (RGraphNode *)rz_list_get_n (n->out_nodes, nth): NULL; +} + +/* returns the list of nodes that can reach `n` */ +RZ_API const RzList *rz_graph_innodes(const RGraph *g, const RGraphNode *n) { + return n? n->in_nodes: NULL; +} + +/* returns the list of nodes reachable from `n` and that can reach `n`. */ +RZ_API const RzList *rz_graph_all_neighbours(const RGraph *g, const RGraphNode *n) { + return n? n->all_neighbours: NULL; +} + +RZ_API const RzList *rz_graph_get_nodes(const RGraph *g) { + return g? g->nodes: NULL; +} + +/* true if there is an edge from the node `from` to the node `to` */ +RZ_API bool rz_graph_adjacent(const RGraph *g, const RGraphNode *from, const RGraphNode *to) { + if (!g || !from) { + return false; + } + return rz_list_contains (from->out_nodes, to); +} + +RZ_API void rz_graph_dfs_node(RGraph *g, RGraphNode *n, RGraphVisitor *vis) { + if (!g || !n || !vis) { + return; + } + int *color = R_NEWS0 (int, g->last_index); + if (color) { + dfs_node (g, n, vis, color, true); + free (color); + } +} + +RZ_API void rz_graph_dfs_node_reverse(RGraph *g, RGraphNode *n, RGraphVisitor *vis) { + if (!g || !n || !vis) { + return; + } + int *color = R_NEWS0 (int, g->last_index); + if (color) { + dfs_node (g, n, vis, color, false); + free (color); + } +} + +RZ_API void rz_graph_dfs(RGraph *g, RGraphVisitor *vis) { + rz_return_if_fail (g && vis); + RGraphNode *n; + RzListIter *it; + + int *color = R_NEWS0 (int, g->last_index); + if (color) { + rz_list_foreach (g->nodes, it, n) { + if (color[n->idx] == WHITE_COLOR) { + dfs_node (g, n, vis, color, true); + } + } + free (color); + } +} + +RZ_API void rz_graph_free_node_info(void *ptr) { + RGraphNodeInfo *info = ptr; + free (info->body); + free (info->title); + free (info); +} + +RZ_API RGraphNodeInfo *rz_graph_create_node_info(char *title, char *body, ut64 offset) { + RGraphNodeInfo *data = R_NEW0 (RGraphNodeInfo); + if (data) { + data->title = title; + data->body = body; + data->offset = offset; + } + return data; +} \ No newline at end of file diff --git a/libr/util/hex.c b/librz/util/hex.c similarity index 80% rename from libr/util/hex.c rename to librz/util/hex.c index a2f768084f..38bed1d580 100644 --- a/libr/util/hex.c +++ b/librz/util/hex.c @@ -1,12 +1,12 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" #include #include /* int c; ret = hex_to_byte(&c, 'c'); */ -R_API bool r_hex_to_byte(ut8 *val, ut8 c) { +RZ_API bool rz_hex_to_byte(ut8 *val, ut8 c) { if (IS_DIGIT (c)) { *val = (ut8)(*val) * 16 + (c - '0'); } else if (c >= 'A' && c <= 'F') { @@ -19,12 +19,12 @@ R_API bool r_hex_to_byte(ut8 *val, ut8 c) { return 0; } -R_API char *r_hex_from_py_str(char *out, const char *code) { +RZ_API char *rz_hex_from_py_str(char *out, const char *code) { if (!strncmp (code, "'''", 3)) { const char *s = code + 2; - return r_hex_from_c_str (out, &s); + return rz_hex_from_c_str (out, &s); } - return r_hex_from_c_str (out, &code); + return rz_hex_from_c_str (out, &code); } static const char *skip_comment_py(const char *code) { @@ -38,7 +38,7 @@ static const char *skip_comment_py(const char *code) { return code + 1; } -R_API char *r_hex_from_py_array(char *out, const char *code) { +RZ_API char *rz_hex_from_py_array(char *out, const char *code) { const char abc[] = "0123456789abcdef"; if (*code != '[' || !strchr (code, ']')) { return NULL; @@ -52,14 +52,14 @@ R_API char *r_hex_from_py_array(char *out, const char *code) { if (!comma) { break; } - char * _word = r_str_ndup (code, comma - code); + char * _word = rz_str_ndup (code, comma - code); const char *word = _word; while (*word == ' ' || *word == '\t' || *word == '\n') { word++; word = skip_comment_py (word); } if (IS_DIGIT (*word)) { - ut8 n = (ut8)r_num_math (NULL, word); + ut8 n = (ut8)rz_num_math (NULL, word); *out++ = abc[(n >> 4) & 0xf]; *out++ = abc[n & 0xf]; } @@ -72,7 +72,7 @@ R_API char *r_hex_from_py_array(char *out, const char *code) { return out; } -R_API char* r_hex_from_py(const char *code) { +RZ_API char* rz_hex_from_py(const char *code) { if (!code) { return NULL; } @@ -91,9 +91,9 @@ R_API char* r_hex_from_py(const char *code) { code = skip_comment_py (code); } if (*code == '[') { - out = r_hex_from_py_array (out, code); + out = rz_hex_from_py_array (out, code); } else if (*code == '"' || *code == '\'') { - out = r_hex_from_py_str (out, code); + out = rz_hex_from_py_str (out, code); } if (!out) { free (ret); @@ -103,7 +103,7 @@ R_API char* r_hex_from_py(const char *code) { return ret; } -R_API char *r_hex_from_c_str(char *out, const char **code) { +RZ_API char *rz_hex_from_c_str(char *out, const char **code) { const char abc[] = "0123456789abcdefABCDEF"; const char *iter = *code; if (*iter != '\'' && *iter != '"') { @@ -165,7 +165,7 @@ const char *skip_comment_c(const char *code) { return code; } -R_API char *r_hex_from_c_array(char *out, const char *code) { +RZ_API char *rz_hex_from_c_array(char *out, const char *code) { const char abc[] = "0123456789abcdef"; if (*code != '{' || !strchr(code, '}')) { return NULL; @@ -176,7 +176,7 @@ R_API char *r_hex_from_c_array(char *out, const char *code) { if (!comma) { comma = strchr (code, '}'); } - char * _word = r_str_ndup (code, comma - code); + char * _word = rz_str_ndup (code, comma - code); const char *word = _word; word = skip_comment_c (word); while (*word == ' ' || *word == '\t' || *word == '\n') { @@ -184,7 +184,7 @@ R_API char *r_hex_from_c_array(char *out, const char *code) { word = skip_comment_c (word); } if (IS_DIGIT (*word)) { - ut8 n = (ut8)r_num_math (NULL, word); + ut8 n = (ut8)rz_num_math (NULL, word); *out++ = abc[(n >> 4) & 0xf]; *out++ = abc[n & 0xf]; } @@ -202,7 +202,7 @@ R_API char *r_hex_from_c_array(char *out, const char *code) { * into: * 4123421b */ -R_API char *r_hex_from_c(const char *code) { +RZ_API char *rz_hex_from_c(const char *code) { if (!code) { return NULL; } @@ -220,13 +220,13 @@ R_API char *r_hex_from_c(const char *code) { code = skip_comment_c (code); } if (*code == '{') { - out = r_hex_from_c_array (out, code); + out = rz_hex_from_c_array (out, code); } else if (*code == '"') { const char *s1, *s2; s1 = code; do { code = s1; - out = r_hex_from_c_str (out, &code); + out = rz_hex_from_c_str (out, &code); if (!out) { break; } @@ -243,7 +243,7 @@ R_API char *r_hex_from_c(const char *code) { } -R_API char *r_hex_from_js(const char *code) { +RZ_API char *rz_hex_from_js(const char *code) { char * s1 = strchr (code, '\''); char * s2 = strchr (code, '"'); @@ -266,7 +266,7 @@ R_API char *r_hex_from_js(const char *code) { return NULL; } - char * str = r_str_ndup (start + 1, end - start - 1); + char * str = rz_str_ndup (start + 1, end - start - 1); /* assuming base64 input, output will always be shorter */ ut8 *b64d = malloc (end - start); @@ -275,14 +275,14 @@ R_API char *r_hex_from_js(const char *code) { return NULL; } - r_base64_decode (b64d, str, end - start - 1); + rz_base64_decode (b64d, str, end - start - 1); if (!b64d) { free (str); free (b64d); return NULL; } - // TODO: use r_str_bin2hex + // TODO: use rz_str_bin2hex int i, len = strlen ((const char *)b64d); char * out = malloc (len * 2 + 1); if (!out) { @@ -306,7 +306,7 @@ R_API char *r_hex_from_js(const char *code) { * into * 4123421b4123421b */ -R_API char *r_hex_no_code(const char *code) { +RZ_API char *rz_hex_no_code(const char *code) { if (!code) { return NULL; } @@ -316,7 +316,7 @@ R_API char *r_hex_no_code(const char *code) { } *ret = '\0'; char *out = ret; - out = r_hex_from_c_str (out, &code); + out = rz_hex_from_c_str (out, &code); code = strchr (code + 1, '"'); if (!out) { free (ret); @@ -325,31 +325,31 @@ R_API char *r_hex_no_code(const char *code) { *out = '\0'; while (out && code) { *out = '\0'; - out = r_hex_from_c_str (out, &code); + out = rz_hex_from_c_str (out, &code); code = strchr (code + 1, '"'); } return ret; } -R_API char *r_hex_from_code(const char *code) { +RZ_API char *rz_hex_from_code(const char *code) { if (!strchr (code, '=')) { - return r_hex_no_code (code); + return rz_hex_no_code (code); } /* C language */ if (strstr (code, "char") || strstr (code, "int")) { - return r_hex_from_c (code); + return rz_hex_from_c (code); } /* JavaScript */ if (strstr (code, "var")) { - return r_hex_from_js (code); + return rz_hex_from_js (code); } /* Python */ - return r_hex_from_py (code); + return rz_hex_from_py (code); } /* int byte = hexpair2bin("A0"); */ // (0A) => 10 || -1 (on error) -R_API int r_hex_pair2bin(const char *arg) { +RZ_API int rz_hex_pair2bin(const char *arg) { ut8 *ptr, c = 0, d = 0; ut32 j = 0; @@ -358,7 +358,7 @@ R_API int r_hex_pair2bin(const char *arg) { break; } d = c; - if (*ptr != '.' && r_hex_to_byte (&c, *ptr)) { + if (*ptr != '.' && rz_hex_to_byte (&c, *ptr)) { eprintf ("Invalid hexa string at char '%c' (%s).\n", *ptr, arg); return -1; @@ -371,7 +371,7 @@ R_API int r_hex_pair2bin(const char *arg) { return (int)c; } -R_API int r_hex_bin2str(const ut8 *in, int len, char *out) { +RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out) { int i, idx; char tmp[8]; if (len < 0) { @@ -385,7 +385,7 @@ R_API int r_hex_bin2str(const ut8 *in, int len, char *out) { return len; } -R_API char *r_hex_bin2strdup(const ut8 *in, int len) { +RZ_API char *rz_hex_bin2strdup(const ut8 *in, int len) { int i, idx; char tmp[5], *out; @@ -404,7 +404,7 @@ R_API char *r_hex_bin2strdup(const ut8 *in, int len) { return out; } -R_API int r_hex_str2bin(const char *in, ut8 *out) { +RZ_API int rz_hex_str2bin(const char *in, ut8 *out) { long nibbles = 0; while (in && *in) { @@ -414,7 +414,7 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) { in += 2; } /* read hex digits */ - while (!r_hex_to_byte (out ? &out[nibbles/2] : &tmp, *in)) { + while (!rz_hex_to_byte (out ? &out[nibbles/2] : &tmp, *in)) { nibbles++; in++; } @@ -442,7 +442,7 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) { if (nibbles % 2) { if (out) { - r_hex_to_byte (&out[nibbles / 2], '0'); + rz_hex_to_byte (&out[nibbles / 2], '0'); } return -(nibbles+1) / 2; } @@ -450,7 +450,7 @@ R_API int r_hex_str2bin(const char *in, ut8 *out) { return nibbles / 2; } -R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) { +RZ_API int rz_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) { ut8 *ptr; int len, ilen = strlen (in)+1; int has_nibble = 0; @@ -460,7 +460,7 @@ R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) { *ptr = '0'; } } - len = r_hex_str2bin ((char*)out, out); + len = rz_hex_str2bin ((char*)out, out); if (len<0) { has_nibble = 1; len = -(len+1); } if (len != -1) { memcpy (mask, in, ilen); @@ -474,7 +474,7 @@ R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) { *ptr = '0'; } } - len = r_hex_str2bin ((char*)mask, mask); + len = rz_hex_str2bin ((char*)mask, mask); if (len < 0) { len++; } @@ -482,7 +482,7 @@ R_API int r_hex_str2binmask(const char *in, ut8 *out, ut8 *mask) { return len; } -R_API st64 r_hex_bin_truncate(ut64 in, int n) { +RZ_API st64 rz_hex_bin_truncate(ut64 in, int n) { switch (n) { case 1: if ((in & UT8_GT0)) { @@ -506,7 +506,7 @@ R_API st64 r_hex_bin_truncate(ut64 in, int n) { } // Check if str contains only hexadecimal characters and return length of bytes -R_API int r_hex_str_is_valid(const char* str) { +RZ_API int rz_hex_str_is_valid(const char* str) { int i; int len = 0; if (!strncmp (str, "0x", 2)) { diff --git a/libr/util/idpool.c b/librz/util/idpool.c similarity index 70% rename from libr/util/idpool.c rename to librz/util/idpool.c index 18c36d72c9..359e86ec6a 100644 --- a/libr/util/idpool.c +++ b/librz/util/idpool.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017-2018 - condret */ +/* rizin - LGPL - Copyright 2017-2018 - condret */ -#include -#include +#include +#include #include #include #if __WINDOWS__ @@ -18,7 +18,7 @@ static ut32 get_msb(ut32 v) { return 0; } -R_API RIDPool* r_id_pool_new(ut32 start_id, ut32 last_id) { +RZ_API RIDPool* rz_id_pool_new(ut32 start_id, ut32 last_id) { RIDPool* pool = NULL; if (start_id < last_id) { pool = R_NEW0 (RIDPool); @@ -31,15 +31,15 @@ R_API RIDPool* r_id_pool_new(ut32 start_id, ut32 last_id) { return pool; } -R_API bool r_id_pool_grab_id(RIDPool* pool, ut32* grabber) { +RZ_API bool rz_id_pool_grab_id(RIDPool* pool, ut32* grabber) { if (!pool || !grabber) { return false; } if (pool->freed_ids) { - ut32 grab = (ut32) (size_t)r_queue_dequeue (pool->freed_ids); + ut32 grab = (ut32) (size_t)rz_queue_dequeue (pool->freed_ids); *grabber = (ut32) grab; - if (r_queue_is_empty (pool->freed_ids)) { - r_queue_free (pool->freed_ids); + if (rz_queue_is_empty (pool->freed_ids)) { + rz_queue_free (pool->freed_ids); pool->freed_ids = NULL; } return true; @@ -52,7 +52,7 @@ R_API bool r_id_pool_grab_id(RIDPool* pool, ut32* grabber) { return false; } -R_API bool r_id_pool_kick_id(RIDPool* pool, ut32 kick) { +RZ_API bool rz_id_pool_kick_id(RIDPool* pool, ut32 kick) { if (!pool || (kick < pool->start_id) || (pool->start_id == pool->next_id)) { return false; } @@ -61,26 +61,26 @@ R_API bool r_id_pool_kick_id(RIDPool* pool, ut32 kick) { return true; } if (!pool->freed_ids) { - pool->freed_ids = r_queue_new (2); + pool->freed_ids = rz_queue_new (2); } - r_queue_enqueue (pool->freed_ids, (void*) (size_t) kick); + rz_queue_enqueue (pool->freed_ids, (void*) (size_t) kick); return true; } -R_API void r_id_pool_free(RIDPool* pool) { +RZ_API void rz_id_pool_free(RIDPool* pool) { if (pool && pool->freed_ids) { - r_queue_free (pool->freed_ids); + rz_queue_free (pool->freed_ids); } free (pool); } -R_API RIDStorage* r_id_storage_new(ut32 start_id, ut32 last_id) { +RZ_API RIDStorage* rz_id_storage_new(ut32 start_id, ut32 last_id) { RIDPool* pool; RIDStorage* storage = NULL; - if ((start_id < 16) && (pool = r_id_pool_new (start_id, last_id))) { + if ((start_id < 16) && (pool = rz_id_pool_new (start_id, last_id))) { storage = R_NEW0 (RIDStorage); if (!storage) { - r_id_pool_free (pool); + rz_id_pool_free (pool); return NULL; } storage->pool = pool; @@ -125,7 +125,7 @@ static bool oid_storage_preallocate(ROIDStorage *st, ut32 size) { return true; } -R_API bool r_id_storage_set(RIDStorage* storage, void* data, ut32 id) { +RZ_API bool rz_id_storage_set(RIDStorage* storage, void* data, ut32 id) { ut32 n; if (!storage || !storage->pool || (id >= storage->pool->next_id)) { return false; @@ -149,21 +149,21 @@ R_API bool r_id_storage_set(RIDStorage* storage, void* data, ut32 id) { return true; } -R_API bool r_id_storage_add(RIDStorage* storage, void* data, ut32* id) { - if (!storage || !r_id_pool_grab_id (storage->pool, id)) { +RZ_API bool rz_id_storage_add(RIDStorage* storage, void* data, ut32* id) { + if (!storage || !rz_id_pool_grab_id (storage->pool, id)) { return false; } - return r_id_storage_set (storage, data, *id); + return rz_id_storage_set (storage, data, *id); } -R_API void* r_id_storage_get(RIDStorage* storage, ut32 id) { +RZ_API void* rz_id_storage_get(RIDStorage* storage, ut32 id) { if (!storage || !storage->data || (storage->size <= id)) { return NULL; } return storage->data[id]; } -R_API void r_id_storage_delete(RIDStorage* storage, ut32 id) { +RZ_API void rz_id_storage_delete(RIDStorage* storage, ut32 id) { if (!storage || !storage->data || (storage->size <= id)) { return; } @@ -176,10 +176,10 @@ R_API void r_id_storage_delete(RIDStorage* storage, ut32 id) { if (storage->data[storage->top_id]) { id_storage_reallocate (storage, 2); } else { - RIDPool* pool = r_id_pool_new (storage->pool->start_id, storage->pool->last_id); + RIDPool* pool = rz_id_pool_new (storage->pool->start_id, storage->pool->last_id); R_FREE (storage->data); storage->size = 0; - r_id_pool_free (storage->pool); + rz_id_pool_free (storage->pool); storage->pool = pool; return; } @@ -187,16 +187,16 @@ R_API void r_id_storage_delete(RIDStorage* storage, ut32 id) { id_storage_reallocate (storage, storage->size / 2); } } - r_id_pool_kick_id (storage->pool, id); + rz_id_pool_kick_id (storage->pool, id); } -R_API void* r_id_storage_take(RIDStorage* storage, ut32 id) { - void* ret = r_id_storage_get (storage, id); - r_id_storage_delete (storage, id); +RZ_API void* rz_id_storage_take(RIDStorage* storage, ut32 id) { + void* ret = rz_id_storage_get (storage, id); + rz_id_storage_delete (storage, id); return ret; } -R_API bool r_id_storage_foreach(RIDStorage* storage, RIDStorageForeachCb cb, void* user) { +RZ_API bool rz_id_storage_foreach(RIDStorage* storage, RIDStorageForeachCb cb, void* user) { ut32 i; if (!cb || !storage || !storage->data) { return false; @@ -214,53 +214,53 @@ R_API bool r_id_storage_foreach(RIDStorage* storage, RIDStorageForeachCb cb, voi return true; } -R_API void r_id_storage_free(RIDStorage* storage) { +RZ_API void rz_id_storage_free(RIDStorage* storage) { if (storage) { - r_id_pool_free (storage->pool); + rz_id_pool_free (storage->pool); free (storage->data); } free (storage); } static bool _list(void* user, void* data, ut32 id) { - r_list_append (user, data); + rz_list_append (user, data); return true; } -R_API RList *r_id_storage_list(RIDStorage *s) { //remove this pls - RList *list = r_list_newf (NULL); - r_id_storage_foreach (s, _list, list); +RZ_API RzList *rz_id_storage_list(RIDStorage *s) { //remove this pls + RzList *list = rz_list_newf (NULL); + rz_id_storage_foreach (s, _list, list); return list; } -R_API ROIDStorage * r_oids_new (ut32 start_id, ut32 last_id) { +RZ_API ROIDStorage * rz_oids_new (ut32 start_id, ut32 last_id) { ROIDStorage *storage = R_NEW0 (ROIDStorage); if (!storage) { return NULL; } - if (!(storage->data = r_id_storage_new (start_id, last_id))) { + if (!(storage->data = rz_id_storage_new (start_id, last_id))) { free (storage); return NULL; } return storage; } -R_API void *r_oids_get(ROIDStorage *storage, ut32 id) { +RZ_API void *rz_oids_get(ROIDStorage *storage, ut32 id) { if (storage) { - return r_id_storage_get (storage->data, id); + return rz_id_storage_get (storage->data, id); } return NULL; } -R_API void *r_oids_oget(ROIDStorage *storage, ut32 od) { +RZ_API void *rz_oids_oget(ROIDStorage *storage, ut32 od) { ut32 id; - if (r_oids_get_id (storage, od, &id)) { - return r_id_storage_get (storage->data, id); + if (rz_oids_get_id (storage, od, &id)) { + return rz_id_storage_get (storage->data, id); } return NULL; } -R_API bool r_oids_get_id(ROIDStorage *storage, ut32 od, ut32 *id) { +RZ_API bool rz_oids_get_id(ROIDStorage *storage, ut32 od, ut32 *id) { if (storage && storage->permutation && (storage->ptop > od)) { *id = storage->permutation[od]; return true; @@ -268,7 +268,7 @@ R_API bool r_oids_get_id(ROIDStorage *storage, ut32 od, ut32 *id) { return false; } -R_API bool r_oids_get_od(ROIDStorage *storage, ut32 id, ut32 *od) { +RZ_API bool rz_oids_get_od(ROIDStorage *storage, ut32 id, ut32 *od) { if (storage && storage->permutation && storage->data && (id < storage->data->pool->next_id)) { for (od[0] = 0; od[0] < storage->ptop; od[0]++) { @@ -280,11 +280,11 @@ R_API bool r_oids_get_od(ROIDStorage *storage, ut32 id, ut32 *od) { return false; } -R_API bool r_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od) { +RZ_API bool rz_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od) { if (!storage || !id || !od) { return false; } - if (!r_id_storage_add (storage->data, data, id)) { + if (!rz_id_storage_add (storage->data, data, id)) { return false; } if (!storage->permutation) { @@ -293,7 +293,7 @@ R_API bool r_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od) { oid_storage_preallocate (storage, storage->psize * 2); } if (storage->psize <= storage->ptop) { - r_id_storage_delete (storage->data, *id); + rz_id_storage_delete (storage->data, *id); return false; } if (!storage->permutation) { @@ -305,7 +305,7 @@ R_API bool r_oids_add(ROIDStorage *storage, void *data, ut32 *id, ut32 *od) { return true; } -R_API bool r_oids_to_front (ROIDStorage *storage, const ut32 id) { +RZ_API bool rz_oids_to_front (ROIDStorage *storage, const ut32 id) { ut32 od; if (!storage || !storage->permutation) { return false; @@ -326,7 +326,7 @@ R_API bool r_oids_to_front (ROIDStorage *storage, const ut32 id) { return true; } -R_API bool r_oids_to_rear (ROIDStorage *storage, ut32 id) { +RZ_API bool rz_oids_to_rear (ROIDStorage *storage, ut32 id) { ut32 od; if (!storage || !storage->permutation || !storage->data || (id >= storage->data->pool->next_id)) { @@ -348,11 +348,11 @@ R_API bool r_oids_to_rear (ROIDStorage *storage, ut32 id) { return true; } -R_API void r_oids_delete (ROIDStorage *storage, ut32 id) { - if (!r_oids_to_front (storage, id)) { +RZ_API void rz_oids_delete (ROIDStorage *storage, ut32 id) { + if (!rz_oids_to_front (storage, id)) { return; } - r_id_storage_delete (storage->data, id); + rz_id_storage_delete (storage->data, id); storage->ptop--; if (!storage->ptop) { R_FREE (storage->permutation); @@ -362,13 +362,13 @@ R_API void r_oids_delete (ROIDStorage *storage, ut32 id) { } } -R_API void r_oids_odelete (ROIDStorage *st, ut32 od) { +RZ_API void rz_oids_odelete (ROIDStorage *st, ut32 od) { ut32 n; if (!st || !st->permutation || od >= st->ptop) { return; } n = st->ptop - od - 1; - r_id_storage_delete (st->data, st->permutation[od]); + rz_id_storage_delete (st->data, st->permutation[od]); memmove (&st->permutation[od], &st->permutation[od + 1], n * sizeof(ut32)); st->ptop--; if (!st->ptop) { @@ -379,32 +379,32 @@ R_API void r_oids_odelete (ROIDStorage *st, ut32 od) { } } -R_API void *r_oids_take (ROIDStorage *storage, ut32 id) { +RZ_API void *rz_oids_take (ROIDStorage *storage, ut32 id) { void *ret; if (!storage) { return NULL; } - ret = r_id_storage_get (storage->data, id); - r_oids_delete (storage, id); + ret = rz_id_storage_get (storage->data, id); + rz_oids_delete (storage, id); return ret; } -R_API void *r_oids_otake (ROIDStorage *st, ut32 od) { - void *ret = r_oids_oget (st, od); - r_oids_odelete (st, od); +RZ_API void *rz_oids_otake (ROIDStorage *st, ut32 od) { + void *ret = rz_oids_oget (st, od); + rz_oids_odelete (st, od); return ret; } -R_API void r_oids_free (ROIDStorage *storage) { +RZ_API void rz_oids_free (ROIDStorage *storage) { if (storage) { free (storage->permutation); - r_id_storage_free (storage->data); + rz_id_storage_free (storage->data); } free (storage); } //returns the element with lowest order -R_API void *r_oids_last (ROIDStorage *storage) { +RZ_API void *rz_oids_last (ROIDStorage *storage) { if (storage && storage->data && storage->data->data && storage->permutation) { return storage->data->data[storage->permutation[0]]; @@ -413,7 +413,7 @@ R_API void *r_oids_last (ROIDStorage *storage) { } //return the element with highest order -R_API void *r_oids_first (ROIDStorage *storage) { +RZ_API void *rz_oids_first (ROIDStorage *storage) { if (storage && storage->data && storage->data->data && storage->permutation) { return storage->data->data[storage->permutation[storage->ptop - 1]]; @@ -421,7 +421,7 @@ R_API void *r_oids_first (ROIDStorage *storage) { return NULL; } -R_API bool r_oids_foreach (ROIDStorage *storage, RIDStorageForeachCb cb, void *user) { +RZ_API bool rz_oids_foreach (ROIDStorage *storage, RIDStorageForeachCb cb, void *user) { ut32 i; ut32 id; if (!cb || !storage || !storage->data || !storage->data->data @@ -438,7 +438,7 @@ R_API bool r_oids_foreach (ROIDStorage *storage, RIDStorageForeachCb cb, void *u return cb (user, storage->data->data[id], id); } -R_API bool r_oids_foreach_prev (ROIDStorage* storage, RIDStorageForeachCb cb, void* user) { +RZ_API bool rz_oids_foreach_prev (ROIDStorage* storage, RIDStorageForeachCb cb, void* user) { ut32 i; ut32 id; if (!cb || !storage || !storage->data || !storage->data->data @@ -469,7 +469,7 @@ bool oids_od_bfind (ROIDStorage *st, ut32 *od, void *incoming, void *user) { while (1) { if (high <= low) { od[0] = (ut32)low; - in = r_oids_oget(st, od[0]); + in = rz_oids_oget(st, od[0]); //in - incoming if (!st->cmp(in, incoming, user, &cmp_res)) { return false; @@ -481,7 +481,7 @@ bool oids_od_bfind (ROIDStorage *st, ut32 *od, void *incoming, void *user) { } od[0] = (ut32)((low + high) / 2); - in = r_oids_oget(st, od[0]); + in = rz_oids_oget(st, od[0]); if (!st->cmp(in, incoming, user, &cmp_res)) { return false; } @@ -512,14 +512,14 @@ bool oids_od_binsert (ROIDStorage *storage, ut32 id, ut32 *od, void *incoming, v return true; } -R_API bool r_oids_insert (ROIDStorage *storage, void *data, ut32 *id, ut32 *od, void *user) { +RZ_API bool rz_oids_insert (ROIDStorage *storage, void *data, ut32 *id, ut32 *od, void *user) { if (!storage || !storage->cmp || !id || !od) { return false; } if (!storage->ptop) { //empty storage - return r_oids_add(storage, data, id, od); + return rz_oids_add(storage, data, id, od); } - if (!r_id_storage_add (storage->data, data, id)) { + if (!rz_id_storage_add (storage->data, data, id)) { return false; } if (storage->ptop > (storage->psize * 3 / 4)) { @@ -528,7 +528,7 @@ R_API bool r_oids_insert (ROIDStorage *storage, void *data, ut32 *id, ut32 *od, return oids_od_binsert (storage, id[0], od, data, user); } -R_API bool r_oids_sort (ROIDStorage *storage, void *user) { +RZ_API bool rz_oids_sort (ROIDStorage *storage, void *user) { ut32 od, id, ptop, *permutation; void *incoming; @@ -549,7 +549,7 @@ R_API bool r_oids_sort (ROIDStorage *storage, void *user) { storage->ptop = 1; while (storage->ptop != ptop) { id = permutation[storage->ptop]; - incoming = r_id_storage_get (storage->data, id); + incoming = rz_id_storage_get (storage->data, id); if (!oids_od_binsert (storage, id, &od, incoming, user)) { goto beach; } @@ -564,7 +564,7 @@ beach: return false; } -R_API ut32 r_oids_find (ROIDStorage *storage, void *incoming, void *user) { +RZ_API ut32 rz_oids_find (ROIDStorage *storage, void *incoming, void *user) { ut32 ret; return oids_od_bfind(storage, &ret, incoming, user) ? ret : storage->ptop; diff --git a/libr/util/intervaltree.c b/librz/util/intervaltree.c similarity index 64% rename from libr/util/intervaltree.c rename to librz/util/intervaltree.c index 1a0e1731e4..1de1fc20e8 100644 --- a/libr/util/intervaltree.c +++ b/librz/util/intervaltree.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2019 - thestr4ng3r */ +/* rizin - LGPL - Copyright 2019 - thestr4ng3r */ -#include -#include +#include +#include #define unwrap(rbnode) container_of (rbnode, RIntervalNode, node) @@ -62,12 +62,12 @@ static int cmp_exact_node(const void *incoming, const RBNode *in_tree, void *use // iterate through all children with the same start and stop when the pointer is identical // The RBIter works a bit different than normal here. We store each node in the path, including right-descended ones // because we want to get the full path in the end. - while (r_rbtree_iter_has (path_cache)) { - RIntervalNode *intervalnode = r_rbtree_iter_get (path_cache, RIntervalNode, node); + while (rz_rbtree_iter_has (path_cache)) { + RIntervalNode *intervalnode = rz_rbtree_iter_get (path_cache, RIntervalNode, node); if (intervalnode == incoming_node || intervalnode->start > incoming_node->start) { break; } - // r_rbtree_iter_next does not work here + // rz_rbtree_iter_next does not work here RBNode *rbnode = &intervalnode->node; if (rbnode->child[1]) { // next node after the current is always the leftmost in the right branch @@ -97,7 +97,7 @@ static int cmp_exact_node(const void *incoming, const RBNode *in_tree, void *use return (next_child && node->node.child[0] == next_child) ? -1 : 1; } -R_API void r_interval_tree_init(RIntervalTree *tree, RIntervalNodeFree free) { +RZ_API void rz_interval_tree_init(RIntervalTree *tree, RIntervalNodeFree free) { tree->root = NULL; tree->free = free; } @@ -110,15 +110,15 @@ static void interval_node_free(RBNode *node, void *user) { free (ragenode); } -R_API void r_interval_tree_fini(RIntervalTree *tree) { +RZ_API void rz_interval_tree_fini(RIntervalTree *tree) { if (!tree || !tree->root) { return; } - r_rbtree_free (&tree->root->node, interval_node_free, tree->free); + rz_rbtree_free (&tree->root->node, interval_node_free, tree->free); } -R_API bool r_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, void *data) { - r_return_val_if_fail (end >= start, false); +RZ_API bool rz_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, void *data) { + rz_return_val_if_fail (end >= start, false); RIntervalNode *node = R_NEW0 (RIntervalNode); if (!node) { return false; @@ -127,7 +127,7 @@ R_API bool r_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, voi node->end = end; node->data = data; RBNode *root = tree->root ? &tree->root->node : NULL; - bool r = r_rbtree_aug_insert (&root, &start, &node->node, cmp, NULL, node_max); + bool r = rz_rbtree_aug_insert (&root, &start, &node->node, cmp, NULL, node_max); tree->root = unwrap (root); if (!r) { free (node); @@ -135,37 +135,37 @@ R_API bool r_interval_tree_insert(RIntervalTree *tree, ut64 start, ut64 end, voi return r; } -R_API bool r_interval_tree_delete(RIntervalTree *tree, RIntervalNode *node, bool free) { +RZ_API bool rz_interval_tree_delete(RIntervalTree *tree, RIntervalNode *node, bool free) { RBNode *root = &tree->root->node; RBIter path_cache = { 0 }; - bool r = r_rbtree_aug_delete (&root, node, cmp_exact_node, &path_cache, interval_node_free, free ? tree->free : NULL, node_max); + bool r = rz_rbtree_aug_delete (&root, node, cmp_exact_node, &path_cache, interval_node_free, free ? tree->free : NULL, node_max); tree->root = root ? unwrap (root) : NULL; return r; } -R_API bool r_interval_tree_resize(RIntervalTree *tree, RIntervalNode *node, ut64 new_start, ut64 new_end) { - r_return_val_if_fail (new_end >= new_start, false); +RZ_API bool rz_interval_tree_resize(RIntervalTree *tree, RIntervalNode *node, ut64 new_start, ut64 new_end) { + rz_return_val_if_fail (new_end >= new_start, false); if (node->start != new_start) { // Start change means the tree needs a different structure void *data = node->data; - if (!r_interval_tree_delete (tree, node, false)) { + if (!rz_interval_tree_delete (tree, node, false)) { return false; } - return r_interval_tree_insert (tree, new_start, new_end, data); + return rz_interval_tree_insert (tree, new_start, new_end, data); } if (node->end != new_end) { // Only end change just needs the updated augmented max value to be propagated upwards node->end = new_end; RBIter path_cache = { 0 }; - return r_rbtree_aug_update_sum (&tree->root->node, node, &node->node, cmp_exact_node, &path_cache, node_max); + return rz_rbtree_aug_update_sum (&tree->root->node, node, &node->node, cmp_exact_node, &path_cache, node_max); } // no change return true; } // This must always return the topmost node that matches start! -// Otherwise r_interval_tree_first_at will break!!! -R_API RIntervalNode *r_interval_tree_node_at(RIntervalTree *tree, ut64 start) { +// Otherwise rz_interval_tree_first_at will break!!! +RZ_API RIntervalNode *rz_interval_tree_node_at(RIntervalTree *tree, ut64 start) { RIntervalNode *node = tree->root; while (node) { if (start < node->start) { @@ -179,11 +179,11 @@ R_API RIntervalNode *r_interval_tree_node_at(RIntervalTree *tree, ut64 start) { return NULL; } -R_API RBIter r_interval_tree_first_at(RIntervalTree *tree, ut64 start) { +RZ_API RBIter rz_interval_tree_first_at(RIntervalTree *tree, ut64 start) { RBIter it = { 0 }; // Find the topmost node matching start so we have a sub-tree with all entries that we want to find. - RIntervalNode *top_intervalnode = r_interval_tree_node_at (tree, start); + RIntervalNode *top_intervalnode = rz_interval_tree_node_at (tree, start); if (!top_intervalnode) { return it; } @@ -202,26 +202,26 @@ R_API RBIter r_interval_tree_first_at(RIntervalTree *tree, ut64 start) { return it; } -R_API RIntervalNode *r_interval_tree_node_at_data(RIntervalTree *tree, ut64 start, void *data) { - RBIter it = r_interval_tree_first_at (tree, start); - while (r_rbtree_iter_has (&it)) { - RIntervalNode *intervalnode = r_rbtree_iter_get (&it, RIntervalNode, node); +RZ_API RIntervalNode *rz_interval_tree_node_at_data(RIntervalTree *tree, ut64 start, void *data) { + RBIter it = rz_interval_tree_first_at (tree, start); + while (rz_rbtree_iter_has (&it)) { + RIntervalNode *intervalnode = rz_rbtree_iter_get (&it, RIntervalNode, node); if (intervalnode->start != start) { break; } if (intervalnode->data == data) { return intervalnode; } - r_rbtree_iter_next (&it); + rz_rbtree_iter_next (&it); } return NULL; } -R_API bool r_interval_tree_all_at(RIntervalTree *tree, ut64 start, RIntervalIterCb cb, void *user) { - RBIter it = r_interval_tree_first_at (tree, start); +RZ_API bool rz_interval_tree_all_at(RIntervalTree *tree, ut64 start, RIntervalIterCb cb, void *user) { + RBIter it = rz_interval_tree_first_at (tree, start); bool ret = true; - while (r_rbtree_iter_has (&it)) { - RIntervalNode *intervalnode = r_rbtree_iter_get (&it, RIntervalNode, node); + while (rz_rbtree_iter_has (&it)) { + RIntervalNode *intervalnode = rz_rbtree_iter_get (&it, RIntervalNode, node); if (intervalnode->start != start) { break; } @@ -229,12 +229,12 @@ R_API bool r_interval_tree_all_at(RIntervalTree *tree, ut64 start, RIntervalIter if (!ret) { break; } - r_rbtree_iter_next (&it); + rz_rbtree_iter_next (&it); } return ret; } -R_API bool r_interval_node_all_in(RIntervalNode *node, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user) { +RZ_API bool rz_interval_node_all_in(RIntervalNode *node, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user) { while (node && value < node->start) { // less than the current node, but might still be contained further down node = unwrap (node->node.child[0]); @@ -251,20 +251,20 @@ R_API bool r_interval_node_all_in(RIntervalNode *node, ut64 value, bool end_incl } } // This can be done more efficiently by building the stack manually - bool ret = r_interval_node_all_in (unwrap (node->node.child[0]), value, end_inclusive, cb, user); + bool ret = rz_interval_node_all_in (unwrap (node->node.child[0]), value, end_inclusive, cb, user); if (!ret) { return false; } - return r_interval_node_all_in (unwrap (node->node.child[1]), value, end_inclusive, cb, user); + return rz_interval_node_all_in (unwrap (node->node.child[1]), value, end_inclusive, cb, user); } -R_API bool r_interval_tree_all_in(RIntervalTree *tree, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user) { +RZ_API bool rz_interval_tree_all_in(RIntervalTree *tree, ut64 value, bool end_inclusive, RIntervalIterCb cb, void *user) { // all in! 🂡 - return r_interval_node_all_in (tree->root, value, end_inclusive, cb, user); + return rz_interval_node_all_in (tree->root, value, end_inclusive, cb, user); } -static bool r_interval_node_all_intersect(RIntervalNode *node, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user) { - r_return_val_if_fail (end >= start, true); +static bool rz_interval_node_all_intersect(RIntervalNode *node, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user) { + rz_return_val_if_fail (end >= start, true); while (node && (end_inclusive ? end < node->start : end <= node->start)) { // less than the current node, but might still be contained further down node = unwrap (node->node.child[0]); @@ -281,12 +281,12 @@ static bool r_interval_node_all_intersect(RIntervalNode *node, ut64 start, ut64 } } // This can be done more efficiently by building the stack manually - if (!r_interval_node_all_intersect (unwrap (node->node.child[0]), start, end, end_inclusive, cb, user)) { + if (!rz_interval_node_all_intersect (unwrap (node->node.child[0]), start, end, end_inclusive, cb, user)) { return false; } - return r_interval_node_all_intersect (unwrap (node->node.child[1]), start, end, end_inclusive, cb, user); + return rz_interval_node_all_intersect (unwrap (node->node.child[1]), start, end, end_inclusive, cb, user); } -R_API bool r_interval_tree_all_intersect(RIntervalTree *tree, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user) { - return r_interval_node_all_intersect (tree->root, start, end, end_inclusive, cb, user); +RZ_API bool rz_interval_tree_all_intersect(RIntervalTree *tree, ut64 start, ut64 end, bool end_inclusive, RIntervalIterCb cb, void *user) { + return rz_interval_node_all_intersect (tree->root, start, end, end_inclusive, cb, user); } diff --git a/libr/util/json_indent.c b/librz/util/json_indent.c similarity index 94% rename from libr/util/json_indent.c rename to librz/util/json_indent.c index 5a02b3cf65..d5d3cef5b8 100644 --- a/libr/util/json_indent.c +++ b/librz/util/json_indent.c @@ -1,6 +1,6 @@ -/* radare2 (from sdb) - MIT - Copyright 2012-2017 - pancake */ +/* rizin (from sdb) - MIT - Copyright 2012-2017 - pancake */ -#include +#include static void doIndent(int idt, char** o, const char *tab) { @@ -39,7 +39,7 @@ static const char *origColors[] = { }; // static const char colors -R_API char* r_print_json_path(const char* s, int pos) { +RZ_API char* rz_print_json_path(const char* s, int pos) { int indent = 0; #define DSZ 128 const char *words[DSZ] = { NULL }; @@ -130,7 +130,7 @@ R_API char* r_print_json_path(const char* s, int pos) { } eprintf ("0x%08"PFMT64x" %d [%d]\n", cur, i, indexs[i]); } else { - char *a = r_str_ndup (words[i], lengths[i]); + char *a = rz_str_ndup (words[i], lengths[i]); ut64 cur = words[i] - os - 1; if (cur < opos) { continue; @@ -151,7 +151,7 @@ R_API char* r_print_json_path(const char* s, int pos) { return NULL; } -R_API char* r_print_json_human(const char* s) { +RZ_API char* rz_print_json_human(const char* s) { int indent = 0; const char *tab = " "; const int indentSize = strlen (tab); @@ -250,7 +250,7 @@ R_API char* r_print_json_human(const char* s) { return O; } -R_API char* r_print_json_indent(const char* s, bool color, const char* tab, const char **palette) { +RZ_API char* rz_print_json_indent(const char* s, bool color, const char* tab, const char **palette) { int indent = 0; const int indentSize = strlen (tab); int instr = 0; @@ -326,7 +326,7 @@ R_API char* r_print_json_indent(const char* s, bool color, const char* tab, cons case ':': *o++ = *s; *o++ = ' '; - s = r_str_trim_head_ro (s + 1); + s = rz_str_trim_head_ro (s + 1); if (!strncmp (s, "true", 4)) { EMIT_ESC (o, colors[JC_TRUE]); } else if (!strncmp (s, "false", 5)) { diff --git a/libr/util/json_parser.c b/librz/util/json_parser.c similarity index 91% rename from libr/util/json_parser.c rename to librz/util/json_parser.c index 56c0be170d..5407549228 100644 --- a/libr/util/json_parser.c +++ b/librz/util/json_parser.c @@ -2,9 +2,9 @@ #include -#include -#include -#include +#include +#include +#include #if 0 // optional error printing @@ -34,7 +34,7 @@ static RJson *create_json(RJsonType type, const char *key, RJson *parent) { return js; } -R_API void r_json_free(RJson *js) { +RZ_API void rz_json_free(RJson *js) { if (!js) { return; } @@ -43,7 +43,7 @@ R_API void r_json_free(RJson *js) { RJson *p1; while (p) { p1 = p->next; - r_json_free (p); + rz_json_free (p); p = p1; } } @@ -90,8 +90,8 @@ static char *unescape_string(char *s, char **end) { case 'u': { // unicode char *ps = p - 1; ut8 high = 0, low = 0; - if (r_hex_to_byte (&high, p[1]) || r_hex_to_byte (&high, p[2]) - || r_hex_to_byte (&low, p[3]) || r_hex_to_byte (&low, p[4])) { + if (rz_hex_to_byte (&high, p[1]) || rz_hex_to_byte (&high, p[2]) + || rz_hex_to_byte (&low, p[3]) || rz_hex_to_byte (&low, p[4])) { R_JSON_REPORT_ERROR ("invalid unicode escape", p - 1); return NULL; } @@ -100,8 +100,8 @@ static char *unescape_string(char *s, char **end) { p += 6; high = low = 0; if (p[-1] != '\\' || *p != 'u' - || r_hex_to_byte (&high, p[1]) || r_hex_to_byte (&high, p[2]) - || r_hex_to_byte (&low, p[3]) || r_hex_to_byte (&low, p[4])) { + || rz_hex_to_byte (&high, p[1]) || rz_hex_to_byte (&high, p[2]) + || rz_hex_to_byte (&low, p[3]) || rz_hex_to_byte (&low, p[4])) { R_JSON_REPORT_ERROR ("invalid unicode surrogate", ps); return NULL; } @@ -112,7 +112,7 @@ static char *unescape_string(char *s, char **end) { } codepoint = 0x10000 + ((codepoint - 0xd800) << 10) + (codepoint2 - 0xdc00); } - int sz = r_utf8_encode ((ut8 *)d, codepoint); + int sz = rz_utf8_encode ((ut8 *)d, codepoint); if (!s) { R_JSON_REPORT_ERROR ("invalid codepoint", ps); return NULL; @@ -374,18 +374,18 @@ static char *parse_value(RJson *parent, const char *key, char *p) { return NULL; } -R_API RJson *r_json_parse(char *text) { +RZ_API RJson *rz_json_parse(char *text) { RJson js = {0}; if (!parse_value (&js, 0, text)) { if (js.children.first) { - r_json_free (js.children.first); + rz_json_free (js.children.first); } return 0; } return js.children.first; } -R_API const RJson *r_json_get(const RJson *json, const char *key) { +RZ_API const RJson *rz_json_get(const RJson *json, const char *key) { RJson *js; for (js = json->children.first; js; js = js->next) { if (js->key && !strcmp (js->key, key)) { @@ -395,7 +395,7 @@ R_API const RJson *r_json_get(const RJson *json, const char *key) { return NULL; } -R_API const RJson *r_json_item(const RJson *json, size_t idx) { +RZ_API const RJson *rz_json_item(const RJson *json, size_t idx) { RJson *js; for (js = json->children.first; js; js = js->next) { if (!idx--) { diff --git a/libr/util/lib.c b/librz/util/lib.c similarity index 63% rename from libr/util/lib.c rename to librz/util/lib.c index ab6e470462..50cbdaa178 100644 --- a/libr/util/lib.c +++ b/librz/util/lib.c @@ -1,16 +1,16 @@ /* radare - LGPL - Copyright 2008-2020 - pancake */ -#include -#include +#include +#include -R_LIB_VERSION(r_lib); +R_LIB_VERSION(rz_lib); /* TODO: avoid globals */ #define IFDBG if(__has_debug) static bool __has_debug = false; /* XXX : this must be registered in runtime */ -static const char *r_lib_types[] = { +static const char *rz_lib_types[] = { "io", "dbg", "lang", "asm", "anal", "parse", "bin", "bin_xtr", "bp", "syscall", "fastcall", "crypto", "core", "egg", "fs", NULL }; @@ -19,20 +19,20 @@ static const char *__lib_types_get(int idx) { if (idx < 0 || idx > R_LIB_TYPE_LAST - 1) { return "unk"; } - return r_lib_types[idx]; + return rz_lib_types[idx]; } -R_API int r_lib_types_get_i(const char *str) { +RZ_API int rz_lib_types_get_i(const char *str) { int i; - for (i = 0; r_lib_types[i]; i++) { - if (!strcmp (str, r_lib_types[i])) { + for (i = 0; rz_lib_types[i]; i++) { + if (!strcmp (str, rz_lib_types[i])) { return i; } } return -1; } -R_API void *r_lib_dl_open(const char *libname) { +RZ_API void *rz_lib_dl_open(const char *libname) { void *ret = NULL; #if WANT_DYLINK #if __UNIX__ @@ -42,16 +42,16 @@ R_API void *r_lib_dl_open(const char *libname) { ret = dlopen (NULL, RTLD_NOW); } if (!ret && __has_debug) { - eprintf ("r_lib_dl_open: error: %s (%s)\n", libname, dlerror ()); + eprintf ("rz_lib_dl_open: error: %s (%s)\n", libname, dlerror ()); } #elif __WINDOWS__ LPTSTR libname_; if (libname && *libname) { - libname_ = r_sys_conv_utf8_to_win (libname); + libname_ = rz_sys_conv_utf8_to_win (libname); } else { libname_ = calloc (MAX_PATH, sizeof (TCHAR)); if (!libname_) { - R_LOG_ERROR ("lib/r_lib_dl_open: Failed to allocate memory.\n"); + R_LOG_ERROR ("lib/rz_lib_dl_open: Failed to allocate memory.\n"); return NULL; } if (!GetModuleFileName (NULL, libname_, MAX_PATH)) { @@ -61,14 +61,14 @@ R_API void *r_lib_dl_open(const char *libname) { ret = LoadLibrary (libname_); free (libname_); if (!ret && __has_debug) { - eprintf ("r_lib_dl_open: error: %s\n", libname); + eprintf ("rz_lib_dl_open: error: %s\n", libname); } #endif #endif return ret; } -R_API void *r_lib_dl_sym(void *handler, const char *name) { +RZ_API void *rz_lib_dl_sym(void *handler, const char *name) { #if WANT_DYLINK #if __UNIX__ return dlsym (handler, name); @@ -82,7 +82,7 @@ R_API void *r_lib_dl_sym(void *handler, const char *name) { #endif } -R_API int r_lib_dl_close(void *handler) { +RZ_API int rz_lib_dl_close(void *handler) { #if __UNIX__ return dlclose (handler); #else @@ -90,13 +90,13 @@ R_API int r_lib_dl_close(void *handler) { #endif } -R_API char *r_lib_path(const char *libname) { +RZ_API char *rz_lib_path(const char *libname) { #if __WINDOWS__ - char *tmp = r_str_newf ("%s." R_LIB_EXT, libname); + char *tmp = rz_str_newf ("%s." R_LIB_EXT, libname); if (!tmp) { return NULL; } - WCHAR *name = r_utf8_to_utf16 (tmp); + WCHAR *name = rz_utf8_to_utf16 (tmp); free (tmp); WCHAR *path = NULL; if (!name) { @@ -105,7 +105,7 @@ R_API char *r_lib_path(const char *libname) { int count; if (!(count = SearchPathW (NULL, name, NULL, 0, NULL, NULL))) { - r_sys_perror ("SearchPath"); + rz_sys_perror ("SearchPath"); goto err; } path = malloc (count * sizeof (WCHAR)); @@ -114,10 +114,10 @@ R_API char *r_lib_path(const char *libname) { } if (!(count = SearchPathW (NULL, name, NULL, count, path, NULL))) { R_FREE (path); - r_sys_perror ("SearchPath"); + rz_sys_perror ("SearchPath"); goto err; } - tmp = r_utf16_to_utf8 (path); + tmp = rz_utf16_to_utf8 (path); free (name); free (path); return tmp; @@ -126,11 +126,11 @@ err: return NULL; #else #if __APPLE__ - char *env = r_sys_getenv ("DYLD_LIBRARY_PATH"); - env = r_str_append (env, ":/lib:/usr/lib:/usr/local/lib"); + char *env = rz_sys_getenv ("DYLD_LIBRARY_PATH"); + env = rz_str_append (env, ":/lib:/usr/lib:/usr/local/lib"); #elif __UNIX__ - char *env = r_sys_getenv ("LD_LIBRARY_PATH"); - env = r_str_append (env, ":/lib:/usr/lib:/usr/local/lib"); + char *env = rz_sys_getenv ("LD_LIBRARY_PATH"); + env = rz_str_append (env, ":/lib:/usr/lib:/usr/local/lib"); #endif if (!env) { env = strdup ("."); @@ -141,8 +141,8 @@ err: if (next) { *next = 0; } - char *libpath = r_str_newf ("%s/%s." R_LIB_EXT, path0, libname); - if (r_file_exists (libpath)) { + char *libpath = rz_str_newf ("%s/%s." R_LIB_EXT, path0, libname); + if (rz_file_exists (libpath)) { free (env); return libpath; } @@ -154,23 +154,23 @@ err: #endif } -R_API RLib *r_lib_new(const char *symname, const char *symnamefunc) { - RLib *lib = R_NEW (RLib); +RZ_API RzLib *rz_lib_new(const char *symname, const char *symnamefunc) { + RzLib *lib = R_NEW (RzLib); if (lib) { - __has_debug = r_sys_getenv_asbool ("R2_DEBUG"); - lib->handlers = r_list_newf (free); - lib->plugins = r_list_newf (free); + __has_debug = rz_sys_getenv_asbool ("R2_DEBUG"); + lib->handlers = rz_list_newf (free); + lib->plugins = rz_list_newf (free); lib->symname = strdup (symname? symname: R_LIB_SYMNAME); lib->symnamefunc = strdup (symnamefunc? symnamefunc: R_LIB_SYMFUNC); } return lib; } -R_API void r_lib_free(RLib *lib) { +RZ_API void rz_lib_free(RzLib *lib) { if (lib) { - r_lib_close (lib, NULL); - r_list_free (lib->handlers); - r_list_free (lib->plugins); + rz_lib_close (lib, NULL); + rz_list_free (lib->handlers); + rz_list_free (lib->plugins); free (lib->symname); free (lib->symnamefunc); free (lib); @@ -178,11 +178,11 @@ R_API void r_lib_free(RLib *lib) { } static bool __lib_dl_check_filename(const char *file) { - return r_str_endswith (file, "." R_LIB_EXT); + return rz_str_endswith (file, "." R_LIB_EXT); } -R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol) { - RLibHandler *h = plugin->handler; +RZ_API int rz_lib_run_handler(RzLib *lib, RzLibPlugin *plugin, RzLibStruct *symbol) { + RzLibHandler *h = plugin->handler; if (h && h->constructor) { IFDBG eprintf ("PLUGIN LOADED %p fcn %p\n", h, h->constructor); return h->constructor (plugin, h->user, symbol->data); @@ -191,10 +191,10 @@ R_API int r_lib_run_handler(RLib *lib, RLibPlugin *plugin, RLibStruct *symbol) { return -1; } -R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) { - RLibHandler *h; - RListIter *iter; - r_list_foreach (lib->handlers, iter, h) { +RZ_API RzLibHandler *rz_lib_get_handler(RzLib *lib, int type) { + RzLibHandler *h; + RzListIter *iter; + rz_list_foreach (lib->handlers, iter, h) { if (h->type == type) { return h; } @@ -202,10 +202,10 @@ R_API RLibHandler *r_lib_get_handler(RLib *lib, int type) { return NULL; } -R_API int r_lib_close(RLib *lib, const char *file) { - RLibPlugin *p; - RListIter *iter, *iter2; - r_list_foreach_safe (lib->plugins, iter, iter2, p) { +RZ_API int rz_lib_close(RzLib *lib, const char *file) { + RzLibPlugin *p; + RzListIter *iter, *iter2; + rz_list_foreach_safe (lib->plugins, iter, iter2, p) { if ((!file || !strcmp (file, p->file))) { int ret = 0; if (p->handler && p->handler->destructor) { @@ -215,7 +215,7 @@ R_API int r_lib_close(RLib *lib, const char *file) { p->free (p->data); } free (p->file); - r_list_delete (lib->plugins, iter); + rz_list_delete (lib->plugins, iter); if (file != NULL) { return ret; } @@ -225,7 +225,7 @@ R_API int r_lib_close(RLib *lib, const char *file) { return 0; } // delete similar plugin name - r_list_foreach (lib->plugins, iter, p) { + rz_list_foreach (lib->plugins, iter, p) { if (strstr (p->file, file)) { int ret = 0; if (p->handler && p->handler->destructor) { @@ -234,20 +234,20 @@ R_API int r_lib_close(RLib *lib, const char *file) { } eprintf ("Unloaded %s\n", p->file); free (p->file); - r_list_delete (lib->plugins, iter); + rz_list_delete (lib->plugins, iter); return ret; } } return -1; } -static bool __already_loaded(RLib *lib, const char *file) { - const char *fileName = r_str_rstr (file, R_SYS_DIR); - RLibPlugin *p; - RListIter *iter; +static bool __already_loaded(RzLib *lib, const char *file) { + const char *fileName = rz_str_rstr (file, R_SYS_DIR); + RzLibPlugin *p; + RzListIter *iter; if (fileName) { - r_list_foreach (lib->plugins, iter, p) { - const char *pFileName = r_str_rstr (p->file, R_SYS_DIR); + rz_list_foreach (lib->plugins, iter, p) { + const char *pFileName = rz_str_rstr (p->file, R_SYS_DIR); if (pFileName && !strcmp (fileName, pFileName)) { return true; } @@ -256,7 +256,7 @@ static bool __already_loaded(RLib *lib, const char *file) { return false; } -R_API int r_lib_open(RLib *lib, const char *file) { +RZ_API int rz_lib_open(RzLib *lib, const char *file) { /* ignored by filename */ if (!__lib_dl_check_filename (file)) { eprintf ("Invalid library extension: %s\n", file); @@ -268,28 +268,28 @@ R_API int r_lib_open(RLib *lib, const char *file) { return -1; } - void *handler = r_lib_dl_open (file); + void *handler = rz_lib_dl_open (file); if (!handler) { IFDBG eprintf ("Cannot open library: '%s'\n", file); return -1; } - RLibStructFunc strf = (RLibStructFunc) r_lib_dl_sym (handler, lib->symnamefunc); - RLibStruct *stru = NULL; + RzLibStructFunc strf = (RzLibStructFunc) rz_lib_dl_sym (handler, lib->symnamefunc); + RzLibStruct *stru = NULL; if (strf) { stru = strf (); } if (!stru) { - stru = (RLibStruct *) r_lib_dl_sym (handler, lib->symname); + stru = (RzLibStruct *) rz_lib_dl_sym (handler, lib->symname); } if (!stru) { IFDBG eprintf ("Cannot find symbol '%s' in library '%s'\n", lib->symname, file); - r_lib_dl_close (handler); + rz_lib_dl_close (handler); return -1; } - int res = r_lib_open_ptr (lib, file, handler, stru); + int res = rz_lib_open_ptr (lib, file, handler, stru); if (strf) { free (stru); } @@ -308,8 +308,8 @@ static char *major_minor(const char *s) { return a; } -R_API int r_lib_open_ptr(RLib *lib, const char *file, void *handler, RLibStruct *stru) { - r_return_val_if_fail (lib && file && stru, -1); +RZ_API int rz_lib_open_ptr(RzLib *lib, const char *file, void *handler, RzLibStruct *stru) { + rz_return_val_if_fail (lib && file && stru, -1); if (stru->version) { char *mm0 = major_minor (stru->version); char *mm1 = major_minor (R2_VERSION); @@ -325,36 +325,36 @@ R_API int r_lib_open_ptr(RLib *lib, const char *file, void *handler, RLibStruct int minor = dot ? atoi (dot + 1) : 0; // The pkgname member was introduced in 4.2.0 if (major > 4 || (major == 4 && minor >= 2)) { - printf ("r2pm -ci %s\n", stru->pkgname); + printf ("rz_pm -ci %s\n", stru->pkgname); } } return -1; } } - RLibPlugin *p = R_NEW0 (RLibPlugin); + RzLibPlugin *p = R_NEW0 (RzLibPlugin); p->type = stru->type; p->data = stru->data; p->file = strdup (file); p->dl_handler = handler; - p->handler = r_lib_get_handler (lib, p->type); + p->handler = rz_lib_get_handler (lib, p->type); p->free = stru->free; - int ret = r_lib_run_handler (lib, p, stru); + int ret = rz_lib_run_handler (lib, p, stru); if (ret == -1) { IFDBG eprintf ("Library handler has failed for '%s'\n", file); free (p->file); free (p); - r_lib_dl_close (handler); + rz_lib_dl_close (handler); } else { - r_list_append (lib->plugins, p); + rz_list_append (lib->plugins, p); } return ret; } -R_API bool r_lib_opendir(RLib *lib, const char *path) { +RZ_API bool rz_lib_opendir(RzLib *lib, const char *path) { #if WANT_DYLINK - r_return_val_if_fail (lib && path, false); + rz_return_val_if_fail (lib && path, false); #if __WINDOWS__ wchar_t file[1024]; WIN32_FIND_DATAW dir; @@ -376,7 +376,7 @@ R_API bool r_lib_opendir(RLib *lib, const char *path) { return false; } #if __WINDOWS__ - wcpath = r_utf8_to_utf16 (path); + wcpath = rz_utf8_to_utf16 (path); if (!wcpath) { return false; @@ -390,10 +390,10 @@ R_API bool r_lib_opendir(RLib *lib, const char *path) { } do { swprintf (file, _countof (file), L"%ls/%ls", wcpath, dir.cFileName); - wctocbuff = r_utf16_to_utf8 (file); + wctocbuff = rz_utf16_to_utf8 (file); if (wctocbuff) { if (__lib_dl_check_filename (wctocbuff)) { - r_lib_open (lib, wctocbuff); + rz_lib_open (lib, wctocbuff); } else { IFDBG eprintf ("Cannot open %ls\n", dir.cFileName); } @@ -415,7 +415,7 @@ R_API bool r_lib_opendir(RLib *lib, const char *path) { snprintf (file, sizeof (file), "%s/%s", path, de->d_name); if (__lib_dl_check_filename (file)) { IFDBG eprintf ("Loading %s\n", file); - r_lib_open (lib, file); + rz_lib_open (lib, file); } else { IFDBG eprintf ("Cannot open %s\n", file); } @@ -426,17 +426,17 @@ R_API bool r_lib_opendir(RLib *lib, const char *path) { return true; } -R_API bool r_lib_add_handler(RLib *lib, +RZ_API bool rz_lib_add_handler(RzLib *lib, int type, const char *desc, - int (*cb)(RLibPlugin *, void *, void *), /* constructor */ - int (*dt)(RLibPlugin *, void *, void *), /* destructor */ + int (*cb)(RzLibPlugin *, void *, void *), /* constructor */ + int (*dt)(RzLibPlugin *, void *, void *), /* destructor */ void *user) { - RLibHandler *h; - RListIter *iter; - RLibHandler *handler = NULL; + RzLibHandler *h; + RzListIter *iter; + RzLibHandler *handler = NULL; - r_list_foreach (lib->handlers, iter, h) { + rz_list_foreach (lib->handlers, iter, h) { if (type == h->type) { IFDBG eprintf ("Redefining library handler constructor for %d\n", type); handler = h; @@ -444,12 +444,12 @@ R_API bool r_lib_add_handler(RLib *lib, } } if (!handler) { - handler = R_NEW (RLibHandler); + handler = R_NEW (RzLibHandler); if (!handler) { return false; } handler->type = type; - r_list_append (lib->handlers, handler); + rz_list_append (lib->handlers, handler); } strncpy (handler->desc, desc, sizeof (handler->desc)-1); handler->user = user; @@ -459,25 +459,25 @@ R_API bool r_lib_add_handler(RLib *lib, return true; } -R_API bool r_lib_del_handler(RLib *lib, int type) { - RLibHandler *h; - RListIter *iter; +RZ_API bool rz_lib_del_handler(RzLib *lib, int type) { + RzLibHandler *h; + RzListIter *iter; // TODO: remove all handlers for that type? or only one? /* No _safe loop necessary because we return immediately after the delete. */ - r_list_foreach (lib->handlers, iter, h) { + rz_list_foreach (lib->handlers, iter, h) { if (type == h->type) { - r_list_delete (lib->handlers, iter); + rz_list_delete (lib->handlers, iter); return true; } } return false; } -// TODO _list methods should not exist.. only used in ../core/cmd_log.c: r_lib_list (core->lib); -R_API void r_lib_list(RLib *lib) { - RListIter *iter; - RLibPlugin *p; - r_list_foreach (lib->plugins, iter, p) { +// TODO _list methods should not exist.. only used in ../core/cmd_log.c: rz_lib_list (core->lib); +RZ_API void rz_lib_list(RzLib *lib) { + RzListIter *iter; + RzLibPlugin *p; + rz_list_foreach (lib->plugins, iter, p) { printf (" %5s %p %s \n", __lib_types_get (p->type), p->dl_handler, p->file); } diff --git a/libr/util/list.c b/librz/util/list.c similarity index 54% rename from libr/util/list.c rename to librz/util/list.c index a5a2189787..27cc28a2e3 100644 --- a/libr/util/list.c +++ b/librz/util/list.c @@ -4,52 +4,52 @@ #include #define _R_LIST_C_ -#include "r_util.h" +#include "rz_util.h" -inline RListIter *r_list_iter_new(void) { - return calloc (1, sizeof (RListIter)); +inline RzListIter *rz_list_iter_new(void) { + return calloc (1, sizeof (RzListIter)); } -R_API void r_list_iter_free(RListIter *list) { +RZ_API void rz_list_iter_free(RzListIter *list) { /* do nothing? */ } -R_API RListIter *r_list_iter_get_next(RListIter *list) { - r_return_val_if_fail (list, NULL); +RZ_API RzListIter *rz_list_iter_get_next(RzListIter *list) { + rz_return_val_if_fail (list, NULL); return list->n; } -R_API void *r_list_iter_get_data(RListIter *list) { - r_return_val_if_fail (list, NULL); +RZ_API void *rz_list_iter_get_data(RzListIter *list) { + rz_return_val_if_fail (list, NULL); return list->data; } -R_API RListIter *r_list_iterator(const RList *list) { - r_return_val_if_fail (list, NULL); +RZ_API RzListIter *rz_list_iterator(const RzList *list) { + rz_return_val_if_fail (list, NULL); return list->head; } -R_API RListIter *r_list_push(RList *list, void *item) { - return r_list_append (list, item); +RZ_API RzListIter *rz_list_push(RzList *list, void *item) { + return rz_list_append (list, item); } -R_API RListIter *r_list_get_next(RListIter *list) { - r_return_val_if_fail (list, NULL); +RZ_API RzListIter *rz_list_get_next(RzListIter *list) { + rz_return_val_if_fail (list, NULL); return list->n; } // rename to head/last -R_API void *r_list_first(const RList *list) { - r_return_val_if_fail (list, NULL); +RZ_API void *rz_list_first(const RzList *list) { + rz_return_val_if_fail (list, NULL); return list->head ? list->head->data : NULL; } -R_API void *r_list_last(const RList *list) { - r_return_val_if_fail (list, NULL); +RZ_API void *rz_list_last(const RzList *list) { + rz_return_val_if_fail (list, NULL); return list->tail ? list->tail->data : NULL; } -R_API void r_list_init(RList *list) { +RZ_API void rz_list_init(RzList *list) { list->head = NULL; list->tail = NULL; list->free = NULL; @@ -57,19 +57,19 @@ R_API void r_list_init(RList *list) { list->sorted = false; } -R_API int r_list_length(const RList *list) { - r_return_val_if_fail (list, 0); +RZ_API int rz_list_length(const RzList *list) { + rz_return_val_if_fail (list, 0); return list->length; } /* remove all elements of a list */ -R_API void r_list_purge(RList *list) { - r_return_if_fail (list); +RZ_API void rz_list_purge(RzList *list) { + rz_return_if_fail (list); - RListIter *it = list->head; + RzListIter *it = list->head; while (it) { - RListIter *next = it->n; - r_list_delete (list, it); + RzListIter *next = it->n; + rz_list_delete (list, it); it = next; } list->length = 0; @@ -77,31 +77,31 @@ R_API void r_list_purge(RList *list) { } /* free the list */ -R_API void r_list_free(RList *list) { +RZ_API void rz_list_free(RzList *list) { if (list) { - r_list_purge (list); + rz_list_purge (list); free (list); } } -R_API bool r_list_delete_data(RList *list, void *ptr) { +RZ_API bool rz_list_delete_data(RzList *list, void *ptr) { void *p; - RListIter *iter; + RzListIter *iter; - r_return_val_if_fail (list, false); + rz_return_val_if_fail (list, false); - r_list_foreach (list, iter, p) { + rz_list_foreach (list, iter, p) { if (ptr == p) { - r_list_delete (list, iter); + rz_list_delete (list, iter); return true; } } return false; } -R_API void r_list_delete(RList *list, RListIter *iter) { - r_return_if_fail (list && iter); - r_list_split_iter (list, iter); +RZ_API void rz_list_delete(RzList *list, RzListIter *iter) { + rz_return_if_fail (list && iter); + rz_list_split_iter (list, iter); if (list->free && iter->data) { list->free (iter->data); } @@ -109,14 +109,14 @@ R_API void r_list_delete(RList *list, RListIter *iter) { free (iter); } -R_API void r_list_split(RList *list, void *ptr) { - r_return_if_fail (list); +RZ_API void rz_list_split(RzList *list, void *ptr) { + rz_return_if_fail (list); - RListIter *iter = r_list_iterator (list); + RzListIter *iter = rz_list_iterator (list); while (iter) { void *item = iter->data; if (ptr == item) { - r_list_split_iter (list, iter); + rz_list_split_iter (list, iter); free (iter); break; } @@ -124,8 +124,8 @@ R_API void r_list_split(RList *list, void *ptr) { } } -R_API void r_list_split_iter(RList *list, RListIter *iter) { - r_return_if_fail (list); +RZ_API void rz_list_split_iter(RzList *list, RzListIter *iter) { + rz_return_if_fail (list); if (list->head == iter) { list->head = iter->n; @@ -143,8 +143,8 @@ R_API void r_list_split_iter(RList *list, RListIter *iter) { } //Warning: free functions must be compatible -R_API int r_list_join(RList *list1, RList *list2) { - r_return_val_if_fail (list1 && list2, 0); +RZ_API int rz_list_join(RzList *list1, RzList *list2) { + rz_return_val_if_fail (list1 && list2, 0); if (!(list2->length)) { return 0; @@ -165,37 +165,37 @@ R_API int r_list_join(RList *list1, RList *list2) { return 1; } -R_API RList *r_list_new(void) { - RList *list = R_NEW0 (RList); +RZ_API RzList *rz_list_new(void) { + RzList *list = R_NEW0 (RzList); if (!list) { return NULL; } - r_list_init (list); + rz_list_init (list); return list; } -R_API RList *r_list_newf(RListFree f) { - RList *l = r_list_new (); +RZ_API RzList *rz_list_newf(RzListFree f) { + RzList *l = rz_list_new (); if (l) { l->free = f; } return l; } -R_API RListIter *r_list_item_new(void *data) { - RListIter *item = R_NEW0 (RListIter); +RZ_API RzListIter *rz_list_item_new(void *data) { + RzListIter *item = R_NEW0 (RzListIter); if (item) { item->data = data; } return item; } -R_API RListIter *r_list_append(RList *list, void *data) { - RListIter *item = NULL; +RZ_API RzListIter *rz_list_append(RzList *list, void *data) { + RzListIter *item = NULL; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); - item = R_NEW (RListIter); + item = R_NEW (RzListIter); if (!item) { return item; } @@ -214,10 +214,10 @@ R_API RListIter *r_list_append(RList *list, void *data) { return item; } -R_API RListIter *r_list_prepend(RList *list, void *data) { - r_return_val_if_fail (list, NULL); +RZ_API RzListIter *rz_list_prepend(RzList *list, void *data) { + rz_return_val_if_fail (list, NULL); - RListIter *item = R_NEW0 (RListIter); + RzListIter *item = R_NEW0 (RzListIter); if (!item) { return NULL; } @@ -236,18 +236,18 @@ R_API RListIter *r_list_prepend(RList *list, void *data) { return item; } -R_API RListIter *r_list_insert(RList *list, int n, void *data) { - RListIter *it, *item; +RZ_API RzListIter *rz_list_insert(RzList *list, int n, void *data) { + RzListIter *it, *item; int i; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); if (!list->head || !n) { - return r_list_prepend (list, data); + return rz_list_prepend (list, data); } for (it = list->head, i = 0; it && it->data; it = it->n, i++) { if (i == n) { - item = R_NEW (RListIter); + item = R_NEW (RzListIter); if (!item) { return NULL; } @@ -263,14 +263,14 @@ R_API RListIter *r_list_insert(RList *list, int n, void *data) { return item; } } - return r_list_append (list, data); + return rz_list_append (list, data); } -R_API void *r_list_pop(RList *list) { +RZ_API void *rz_list_pop(RzList *list) { void *data = NULL; - RListIter *iter; + RzListIter *iter; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); if (list->tail) { iter = list->tail; @@ -287,13 +287,13 @@ R_API void *r_list_pop(RList *list) { return data; } -R_API void *r_list_pop_head(RList *list) { +RZ_API void *rz_list_pop_head(RzList *list) { void *data = NULL; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); if (list->head) { - RListIter *iter = list->head; + RzListIter *iter = list->head; if (list->head == list->tail) { list->head = list->tail = NULL; } else { @@ -307,11 +307,11 @@ R_API void *r_list_pop_head(RList *list) { return data; } -R_API int r_list_del_n(RList *list, int n) { - RListIter *it; +RZ_API int rz_list_del_n(RzList *list, int n) { + RzListIter *it; int i; - r_return_val_if_fail (list, false); + rz_return_val_if_fail (list, false); for (it = list->head, i = 0; it && it->data; it = it->n, i++) { if (i == n) { @@ -335,22 +335,22 @@ R_API int r_list_del_n(RList *list, int n) { return false; } -R_API void *r_list_get_top(const RList *list) { - r_return_val_if_fail (list, NULL); +RZ_API void *rz_list_get_top(const RzList *list) { + rz_return_val_if_fail (list, NULL); return list->tail ? list->tail->data : NULL; } -R_API void *r_list_get_bottom(const RList *list) { - r_return_val_if_fail (list, NULL); +RZ_API void *rz_list_get_bottom(const RzList *list) { + rz_return_val_if_fail (list, NULL); return list->head ? list->head->data : NULL; } -R_API void r_list_reverse(RList *list) { - RListIter *it, *tmp; +RZ_API void rz_list_reverse(RzList *list) { + RzListIter *it, *tmp; - r_return_if_fail (list); + rz_return_if_fail (list); for (it = list->head; it && it->data; it = it->p) { tmp = it->p; @@ -362,34 +362,34 @@ R_API void r_list_reverse(RList *list) { list->tail = tmp; } -R_API RList *r_list_clone(const RList *list) { - RListIter *iter; +RZ_API RzList *rz_list_clone(const RzList *list) { + RzListIter *iter; void *data; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); - RList *l = r_list_new (); + RzList *l = rz_list_new (); if (!l) { return NULL; } l->free = NULL; - r_list_foreach (list, iter, data) { - r_list_append (l, data); + rz_list_foreach (list, iter, data) { + rz_list_append (l, data); } l->sorted = list->sorted; return l; } -R_API RListIter *r_list_add_sorted(RList *list, void *data, RListComparator cmp) { - RListIter *it, *item = NULL; +RZ_API RzListIter *rz_list_add_sorted(RzList *list, void *data, RzListComparator cmp) { + RzListIter *it, *item = NULL; - r_return_val_if_fail (list && data && cmp, NULL); + rz_return_val_if_fail (list && data && cmp, NULL); for (it = list->head; it && it->data && cmp (data, it->data) > 0; it = it->n) { ; } if (it) { - item = R_NEW0 (RListIter); + item = R_NEW0 (RzListIter); if (!item) { return NULL; } @@ -404,17 +404,17 @@ R_API RListIter *r_list_add_sorted(RList *list, void *data, RListComparator cmp) } list->length++; } else { - r_list_append (list, data); + rz_list_append (list, data); } list->sorted = true; return item; } -R_API int r_list_set_n(RList *list, int n, void *p) { - RListIter *it; +RZ_API int rz_list_set_n(RzList *list, int n, void *p) { + RzListIter *it; int i; - r_return_val_if_fail (list, false); + rz_return_val_if_fail (list, false); for (it = list->head, i = 0; it ; it = it->n, i++) { if (i == n) { if (list->free) { @@ -428,11 +428,11 @@ R_API int r_list_set_n(RList *list, int n, void *p) { return false; } -R_API void *r_list_get_n(const RList *list, int n) { - RListIter *it; +RZ_API void *rz_list_get_n(const RzList *list, int n) { + RzListIter *it; int i; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); for (it = list->head, i = 0; it && it->data; it = it->n, i++) { if (i == n) { @@ -442,13 +442,13 @@ R_API void *r_list_get_n(const RList *list, int n) { return NULL; } -R_API RListIter *r_list_contains(const RList *list, const void *p) { +RZ_API RzListIter *rz_list_contains(const RzList *list, const void *p) { void *q; - RListIter *iter; + RzListIter *iter; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); - r_list_foreach (list, iter, q) { + rz_list_foreach (list, iter, q) { if (p == q) { return iter; } @@ -456,13 +456,13 @@ R_API RListIter *r_list_contains(const RList *list, const void *p) { return NULL; } -R_API RListIter *r_list_find(const RList *list, const void *p, RListComparator cmp) { +RZ_API RzListIter *rz_list_find(const RzList *list, const void *p, RzListComparator cmp) { void *q; - RListIter *iter; + RzListIter *iter; - r_return_val_if_fail (list, NULL); + rz_return_val_if_fail (list, NULL); - r_list_foreach (list, iter, q) { + rz_list_foreach (list, iter, q) { if (!cmp (p, q)) { return iter; } @@ -470,8 +470,8 @@ R_API RListIter *r_list_find(const RList *list, const void *p, RListComparator c return NULL; } -static RListIter *_merge(RListIter *first, RListIter *second, RListComparator cmp) { - RListIter *next = NULL, *result = NULL, *head = NULL; +static RzListIter *_merge(RzListIter *first, RzListIter *second, RzListComparator cmp) { + RzListIter *next = NULL, *result = NULL, *head = NULL; while (first || second) { if (!second) { next = first; @@ -501,10 +501,10 @@ static RListIter *_merge(RListIter *first, RListIter *second, RListComparator cm return head; } -static RListIter * _r_list_half_split(RListIter *head) { - RListIter *tmp; - RListIter *fast; - RListIter *slow; +static RzListIter * _r_list_half_split(RzListIter *head) { + RzListIter *tmp; + RzListIter *fast; + RzListIter *slow; if (!head || !head->n) { return head; } @@ -519,8 +519,8 @@ static RListIter * _r_list_half_split(RListIter *head) { return tmp; } -static RListIter * _merge_sort(RListIter *head, RListComparator cmp) { - RListIter *second; +static RzListIter * _merge_sort(RzListIter *head, RzListComparator cmp) { + RzListIter *second; if (!head || !head->n) { return head; } @@ -530,11 +530,11 @@ static RListIter * _merge_sort(RListIter *head, RListComparator cmp) { return _merge (head, second, cmp); } -R_API void r_list_merge_sort(RList *list, RListComparator cmp) { - r_return_if_fail (list); +RZ_API void rz_list_merge_sort(RzList *list, RzListComparator cmp) { + rz_return_if_fail (list); if (!list->sorted && list->head && cmp) { - RListIter *iter; + RzListIter *iter; list->head = _merge_sort (list->head, cmp); //update tail reference iter = list->head; @@ -546,12 +546,12 @@ R_API void r_list_merge_sort(RList *list, RListComparator cmp) { list->sorted = true; } -R_API void r_list_insertion_sort(RList *list, RListComparator cmp) { - r_return_if_fail (list); +RZ_API void rz_list_insertion_sort(RzList *list, RzListComparator cmp) { + rz_return_if_fail (list); if (!list->sorted) { - RListIter *it; - RListIter *it2; + RzListIter *it; + RzListIter *it2; if (cmp) { for (it = list->head; it && it->data; it = it->n) { for (it2 = it->n; it2 && it2->data; it2 = it2->n) { @@ -568,48 +568,48 @@ R_API void r_list_insertion_sort(RList *list, RListComparator cmp) { } //chose wisely based on length -R_API void r_list_sort(RList *list, RListComparator cmp) { - r_return_if_fail (list); +RZ_API void rz_list_sort(RzList *list, RzListComparator cmp) { + rz_return_if_fail (list); if (list->length > 43) { - r_list_merge_sort (list, cmp); + rz_list_merge_sort (list, cmp); } else { - r_list_insertion_sort (list, cmp); + rz_list_insertion_sort (list, cmp); } } -R_API RList *r_list_uniq(const RList *list, RListComparator cmp) { - RListIter *iter, *iter2; +RZ_API RzList *rz_list_uniq(const RzList *list, RzListComparator cmp) { + RzListIter *iter, *iter2; void *item, *item2; - r_return_val_if_fail (list && cmp, NULL); + rz_return_val_if_fail (list && cmp, NULL); - RList *nl = r_list_newf (NULL); + RzList *nl = rz_list_newf (NULL); if (!nl) { return NULL; } - r_list_foreach (list, iter, item) { + rz_list_foreach (list, iter, item) { bool found = false; - r_list_foreach (nl, iter2, item2) { + rz_list_foreach (nl, iter2, item2) { if (cmp (item, item2) == 0) { found = true; break; } } if (!found) { - r_list_append (nl, item); + rz_list_append (nl, item); } } return nl; } -R_API char *r_list_to_str(RList *list, char ch) { - RListIter *iter; - RStrBuf *buf = r_strbuf_new (""); +RZ_API char *rz_list_to_str(RzList *list, char ch) { + RzListIter *iter; + RStrBuf *buf = rz_strbuf_new (""); if (!buf) { return NULL; } char *item; - r_list_foreach (list, iter, item) { - r_strbuf_appendf (buf, "%s%c", item, ch); + rz_list_foreach (list, iter, item) { + rz_strbuf_appendf (buf, "%s%c", item, ch); } - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } diff --git a/libr/util/log.c b/librz/util/log.c similarity index 73% rename from libr/util/log.c rename to librz/util/log.c index 7dc5ed041d..bf31ea482b 100644 --- a/libr/util/log.c +++ b/librz/util/log.c @@ -3,11 +3,11 @@ #define LOG_CONFIGSTR_SIZE 512 #define LOG_OUTPUTBUF_SIZE 512 -#include +#include #include // TODO: Use thread-local storage to make these variables thread-safe -static RList *log_cbs = NULL; // Functions to call when outputting log string +static RzList *log_cbs = NULL; // Functions to call when outputting log string static int cfg_loglvl = R_LOGLVL_ERROR; // Log level output static int cfg_logtraplvl = R_LOGLVL_FATAL; // Log trap level static bool cfg_logsrcinfo = false; // Print out debug source info with the output @@ -24,24 +24,24 @@ static const char *level_tags[] = { // Log level to tag string lookup array }; // cconfig.c configuration callback functions below -R_API void r_log_set_level(RLogLevel level) { +RZ_API void rz_log_set_level(RLogLevel level) { cfg_loglvl = level; } -R_API void r_log_set_traplevel(RLogLevel level) { +RZ_API void rz_log_set_traplevel(RLogLevel level) { cfg_logtraplvl = level; } -R_API void r_log_set_file(const char *filename) { - int value_len = r_str_nlen (filename, LOG_CONFIGSTR_SIZE) + 1; +RZ_API void rz_log_set_file(const char *filename) { + int value_len = rz_str_nlen (filename, LOG_CONFIGSTR_SIZE) + 1; strncpy (cfg_logfile, filename, value_len); } -R_API void r_log_set_srcinfo(bool show_info) { +RZ_API void rz_log_set_srcinfo(bool show_info) { cfg_logsrcinfo = show_info; } -R_API void r_log_set_colors(bool show_info) { +RZ_API void rz_log_set_colors(bool show_info) { cfg_logcolors = show_info; } @@ -49,12 +49,12 @@ R_API void r_log_set_colors(bool show_info) { * \brief Add a logging callback * \param cbfunc RLogCallback style function to be called */ -R_API void r_log_add_callback(RLogCallback cbfunc) { +RZ_API void rz_log_add_callback(RLogCallback cbfunc) { if (!log_cbs) { - log_cbs = r_list_new (); + log_cbs = rz_list_new (); } - if (!r_list_contains (log_cbs, cbfunc)) { - r_list_append (log_cbs, cbfunc); + if (!rz_list_contains (log_cbs, cbfunc)) { + rz_list_append (log_cbs, cbfunc); } } @@ -62,13 +62,13 @@ R_API void r_log_add_callback(RLogCallback cbfunc) { * \brief Remove a logging callback * \param cbfunc RLogCallback style function to be called */ -R_API void r_log_del_callback(RLogCallback cbfunc) { +RZ_API void rz_log_del_callback(RLogCallback cbfunc) { if (log_cbs) { - r_list_delete_data (log_cbs, cbfunc); + rz_list_delete_data (log_cbs, cbfunc); } } -R_API void r_vlog(const char *funcname, const char *filename, +RZ_API void rz_vlog(const char *funcname, const char *filename, ut32 lineno, RLogLevel level, const char *tag, const char *fmtstr, va_list args) { va_list args_copy; va_copy (args_copy, args); @@ -94,11 +94,11 @@ R_API void r_vlog(const char *funcname, const char *filename, vsnprintf (output_buf + offset, LOG_OUTPUTBUF_SIZE - offset, fmtstr, args); // Actually print out the string with our callbacks - if (log_cbs && r_list_length (log_cbs) > 0) { - RListIter *it; + if (log_cbs && rz_list_length (log_cbs) > 0) { + RzListIter *it; RLogCallback cb; - r_list_foreach (log_cbs, it, cb) { + rz_list_foreach (log_cbs, it, cb) { cb (output_buf, funcname, filename, lineno, level, NULL, fmtstr, args_copy); } } else { @@ -108,9 +108,9 @@ R_API void r_vlog(const char *funcname, const char *filename, // Log to file if enabled if (cfg_logfile[0] != 0x00) { - FILE *file = r_sandbox_fopen (cfg_logfile, "a+"); // TODO: Optimize (static? Needs to remake on cfg change though) + FILE *file = rz_sandbox_fopen (cfg_logfile, "a+"); // TODO: Optimize (static? Needs to remake on cfg change though) if (!file) { - file = r_sandbox_fopen (cfg_logfile, "w+"); + file = rz_sandbox_fopen (cfg_logfile, "w+"); } if (file) { fprintf (file, "%s", output_buf); @@ -123,8 +123,8 @@ R_API void r_vlog(const char *funcname, const char *filename, if (level >= cfg_logtraplvl && level != R_LOGLVL_NONE) { fflush (stdout); // We're about to exit HARD, flush buffers before dying fflush (stderr); - // TODO: call r_cons_flush if libr_cons is being used - r_sys_breakpoint (); // *oof* + // TODO: call rz_cons_flush if librz_cons is being used + rz_sys_breakpoint (); // *oof* } } @@ -138,11 +138,11 @@ R_API void r_vlog(const char *funcname, const char *filename, This function is used by the R_LOG_* preprocessor macros for logging */ -R_API void r_log(const char *funcname, const char *filename, +RZ_API void rz_log(const char *funcname, const char *filename, ut32 lineno, RLogLevel level, const char *tag, const char *fmtstr, ...) { va_list args; va_start (args, fmtstr); - r_vlog (funcname, filename, lineno, level, tag, fmtstr, args); + rz_vlog (funcname, filename, lineno, level, tag, fmtstr, args); va_end (args); } diff --git a/libr/util/mem.c b/librz/util/mem.c similarity index 72% rename from libr/util/mem.c rename to librz/util/mem.c index be8c97ea0a..1edbff2192 100644 --- a/libr/util/mem.c +++ b/librz/util/mem.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include +#include #if __UNIX__ #include #endif @@ -8,8 +8,8 @@ #define SET_BIT(p,n) ((p) |= (1 << (n))) #define CLR_BIT(p,n) ((p) &= (~(1) << (n))) -// TODO: find better name (r_mem_length()); is this used somewhere? -R_API int r_mem_count(const ut8 **addr) { +// TODO: find better name (rz_mem_length()); is this used somewhere? +RZ_API int rz_mem_count(const ut8 **addr) { int i = 0; while (*addr++) { i++; @@ -17,7 +17,7 @@ R_API int r_mem_count(const ut8 **addr) { return i; } -R_API int r_mem_eq(ut8 *a, ut8 *b, int len) { +RZ_API int rz_mem_eq(ut8 *a, ut8 *b, int len) { register int i; for (i = 0; i < len; i++) { if (a[i] != b[i]) { @@ -27,7 +27,7 @@ R_API int r_mem_eq(ut8 *a, ut8 *b, int len) { return true; } -R_API void r_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize) { +RZ_API void rz_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize) { int i = 0, j; while (i < dsize) { for (j = 0; j < osize && i < dsize; j++) { @@ -36,7 +36,7 @@ R_API void r_mem_copyloop(ut8 *dest, const ut8 *orig, int dsize, int osize) { } } -R_API int r_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len) { +RZ_API int rz_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int len) { ut8 *mdest = malloc (len); if (!mdest) { return -1; @@ -57,7 +57,7 @@ R_API int r_mem_cmp_mask(const ut8 *dest, const ut8 *orig, const ut8 *mask, int return ret; } -R_API void r_mem_copybits(ut8 *dst, const ut8 *src, int bits) { +RZ_API void rz_mem_copybits(ut8 *dst, const ut8 *src, int bits) { ut8 srcmask, dstmask; int bytes = (int) (bits / 8); bits = bits % 8; @@ -98,7 +98,7 @@ static inline void writebit (ut8 *dst, int i, bool c) { } } -R_API void r_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits) { +RZ_API void rz_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, int bits) { int i; if (doff < 0 || soff < 0 || !dst || !src) { return; @@ -109,36 +109,36 @@ R_API void r_mem_copybits_delta(ut8 *dst, int doff, const ut8 *src, int soff, in } } -R_API ut64 r_mem_get_num(const ut8 *b, int size) { +RZ_API ut64 rz_mem_get_num(const ut8 *b, int size) { // LITTLE ENDIAN is the default for streams switch (size) { case 1: - return r_read_le8 (b); + return rz_read_le8 (b); case 2: - return r_read_le16 (b); + return rz_read_le16 (b); case 4: - return r_read_le32 (b); + return rz_read_le32 (b); case 8: - return r_read_le64 (b); + return rz_read_le64 (b); } return 0LL; } -// TODO: SEE: R_API ut64 r_reg_get_value(RReg *reg, RRegItem *item) { .. dupped code? -R_API int r_mem_set_num(ut8 *dest, int dest_size, ut64 num) { +// TODO: SEE: RZ_API ut64 rz_reg_get_value(RzReg *reg, RzRegItem *item) { .. dupped code? +RZ_API int rz_mem_set_num(ut8 *dest, int dest_size, ut64 num) { // LITTLE ENDIAN is the default for streams switch (dest_size) { case 1: - r_write_le8 (dest, (ut8) (num & UT8_MAX)); + rz_write_le8 (dest, (ut8) (num & UT8_MAX)); break; case 2: - r_write_le16 (dest, (ut16) (num & UT16_MAX)); + rz_write_le16 (dest, (ut16) (num & UT16_MAX)); break; case 4: - r_write_le32 (dest, (ut32) (num & UT32_MAX)); + rz_write_le32 (dest, (ut32) (num & UT32_MAX)); break; case 8: - r_write_le64 (dest, num); + rz_write_le64 (dest, num); break; default: return false; @@ -149,9 +149,9 @@ R_API int r_mem_set_num(ut8 *dest, int dest_size, ut64 num) { // The default endian is LE for streams. // This function either swaps or copies len bytes depending on bool big_endian // TODO: Remove completely -R_API void r_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian) { +RZ_API void rz_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian) { if (big_endian) { - r_mem_swapendian (dest, src, len); + rz_mem_swapendian (dest, src, len); } else { memcpy (dest, src, len); } @@ -159,7 +159,7 @@ R_API void r_mem_swaporcopy(ut8 *dest, const ut8 *src, int len, bool big_endian) // This function unconditionally swaps endian of size bytes of orig -> dest // TODO: Remove completely -R_API void r_mem_swapendian(ut8 *dest, const ut8 *orig, int size) { +RZ_API void rz_mem_swapendian(ut8 *dest, const ut8 *orig, int size) { ut8 buffer[8]; switch (size) { case 1: @@ -201,9 +201,9 @@ R_API void r_mem_swapendian(ut8 *dest, const ut8 *orig, int size) { } } -// R_DOC r_mem_mem: Finds the needle of nlen size into the haystack of hlen size -// R_UNIT printf("%s\n", r_mem_mem("food is pure lame", 20, "is", 2)); -R_API const ut8 *r_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int nlen) { +// R_DOC rz_mem_mem: Finds the needle of nlen size into the haystack of hlen size +// R_UNIT printf("%s\n", rz_mem_mem("food is pure lame", 20, "is", 2)); +RZ_API const ut8 *rz_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int nlen) { int i, until = hlen - nlen + 1; if (hlen < 1 || nlen < 1) { return NULL; @@ -216,8 +216,8 @@ R_API const ut8 *r_mem_mem(const ut8 *haystack, int hlen, const ut8 *needle, int return NULL; } -// TODO: rename to r_mem_mem and refactor all calls to this function -R_API const ut8 *r_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align) { +// TODO: rename to rz_mem_mem and refactor all calls to this function +RZ_API const ut8 *rz_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *needle, int nlen, int align) { int i, until = hlen - nlen + 1; if (align < 1) { align = 1; @@ -236,7 +236,7 @@ R_API const ut8 *r_mem_mem_aligned(const ut8 *haystack, int hlen, const ut8 *nee return NULL; } -R_API int r_mem_protect(void *ptr, int size, const char *prot) { +RZ_API int rz_mem_protect(void *ptr, int size, const char *prot) { #if __UNIX__ int p = 0; if (strchr (prot, 'x')) { @@ -276,7 +276,7 @@ R_API int r_mem_protect(void *ptr, int size, const char *prot) { return true; } -R_API void *r_mem_dup(const void *s, int l) { +RZ_API void *rz_mem_dup(const void *s, int l) { void *d = malloc (l); if (d) { memcpy (d, s, l); @@ -284,7 +284,7 @@ R_API void *r_mem_dup(const void *s, int l) { return d; } -R_API void r_mem_reverse(ut8 *b, int l) { +RZ_API void rz_mem_reverse(ut8 *b, int l) { ut8 tmp; int i, end = l / 2; for (i = 0; i < end; i++) { @@ -294,7 +294,7 @@ R_API void r_mem_reverse(ut8 *b, int l) { } } -R_API bool r_mem_is_printable(const ut8 *a, int la) { +RZ_API bool rz_mem_is_printable(const ut8 *a, int la) { int i; for (i = 0; i < la; i++) { if (a[i] != '\n' && a[i] != '\t' && !IS_PRINTABLE (a[i])) { @@ -304,7 +304,7 @@ R_API bool r_mem_is_printable(const ut8 *a, int la) { return true; } -R_API bool r_mem_is_zero(const ut8 *b, int l) { +RZ_API bool rz_mem_is_zero(const ut8 *b, int l) { int i; for (i = 0; i < l; i++) { if (b[i]) { @@ -314,15 +314,15 @@ R_API bool r_mem_is_zero(const ut8 *b, int l) { return true; } -R_API void *r_mem_alloc(int sz) { +RZ_API void *rz_mem_alloc(int sz) { return calloc (sz, 1); } -R_API void r_mem_free(void *p) { +RZ_API void rz_mem_free(void *p) { free (p); } -R_API void r_mem_memzero(void *dst, size_t l) { +RZ_API void rz_mem_memzero(void *dst, size_t l) { #ifdef _MSC_VER RtlSecureZeroMemory (dst, l); #else @@ -337,7 +337,7 @@ R_API void r_mem_memzero(void *dst, size_t l) { #endif } -R_API void *r_mem_mmap_resize(RMmap *m, ut64 newsize) { +RZ_API void *rz_mem_mmap_resize(RMmap *m, ut64 newsize) { #if __WINDOWS__ if (m->fm != INVALID_HANDLE_VALUE) { CloseHandle (m->fm); @@ -353,10 +353,10 @@ R_API void *r_mem_mmap_resize(RMmap *m, ut64 newsize) { return NULL; } #endif - if (!r_sys_truncate (m->filename, newsize)) { + if (!rz_sys_truncate (m->filename, newsize)) { return NULL; } m->len = newsize; - r_file_mmap_arch (m, m->filename, m->fd); + rz_file_mmap_arch (m, m->filename, m->fd); return m->buf; } diff --git a/libr/util/meson.build b/librz/util/meson.build similarity index 76% rename from libr/util/meson.build rename to librz/util/meson.build index 1f31c3ed30..3e9b3d9038 100644 --- a/libr/util/meson.build +++ b/librz/util/meson.build @@ -1,5 +1,5 @@ -r_util_sources = [ +rz_util_sources = [ 'ascii_table.c', 'assert.c', 'alloc.c', @@ -84,38 +84,38 @@ r_util_sources = [ 'annotated_code.c' ] -r_util_deps = [ldl, mth, spp_dep, pth, utl, sdb_dep, zlib_dep, platform_deps] +rz_util_deps = [ldl, mth, spp_dep, pth, utl, sdb_dep, zlib_dep, platform_deps] if host_machine.system().startswith('freebsd') or host_machine.system().startswith('netbsd') or host_machine.system().startswith('haiku') # backtrace_symbols_fd requires -lexecinfo - r_util_deps += [cc.find_library('execinfo')] + rz_util_deps += [cc.find_library('execinfo')] endif if use_sys_openssl - r_util_deps += [sys_openssl] - r_util_sources += ['big-ssl.c'] + rz_util_deps += [sys_openssl] + rz_util_sources += ['big-ssl.c'] else - r_util_sources += ['big.c'] + rz_util_sources += ['big.c'] endif -r_util = library('r_util', r_util_sources, +rz_util = library('rz_util', rz_util_sources, include_directories: platform_inc, c_args: library_cflags, - dependencies: r_util_deps, + dependencies: rz_util_deps, install: true, implicit_include_directories: false, install_rpath: rpath_lib, soversion: r2_libversion ) -r_util_dep = declare_dependency(link_with: r_util, +rz_util_dep = declare_dependency(link_with: rz_util, include_directories: platform_inc, - dependencies: r_util_deps) + dependencies: rz_util_deps) -pkgconfig_mod.generate(r_util, - subdirs: ['libr', 'libr/sdb'], +pkgconfig_mod.generate(rz_util, + subdirs: ['librz', 'librz/sdb'], version: r2_version, libraries: pkgcfg_sanitize_libs, - name: 'r_util', - filebase: 'r_util', + name: 'rz_util', + filebase: 'rz_util', description: 'radare foundation libraries' ) diff --git a/libr/util/name.c b/librz/util/name.c similarity index 76% rename from libr/util/name.c rename to librz/util/name.c index b1295600cf..4753a3c18f 100644 --- a/libr/util/name.c +++ b/librz/util/name.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include +#include -R_API bool r_name_validate_char(const char ch) { +RZ_API bool rz_name_validate_char(const char ch) { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (IS_DIGIT(ch))) { return true; } @@ -15,14 +15,14 @@ R_API bool r_name_validate_char(const char ch) { return false; } -R_API bool r_name_check(const char *name) { +RZ_API bool rz_name_check(const char *name) { /* Cannot start by number */ if (!name || !*name || IS_DIGIT (*name)) { return false; } /* Cannot contain non-alphanumeric chars + [:._] */ for (; *name != '\0'; name++) { - if (!r_name_validate_char (*name)) { + if (!rz_name_validate_char (*name)) { return false; } } @@ -34,7 +34,7 @@ static inline bool is_special_char (char *name) { return (n == 'b' || n == 'f' || n == 'n' || n == 'r' || n == 't' || n == 'v' || n == 'a'); } -R_API bool r_name_filter(char *name, int maxlen) { +RZ_API bool rz_name_filter(char *name, int maxlen) { size_t i, len; if (!name) { return false; @@ -42,16 +42,16 @@ R_API bool r_name_filter(char *name, int maxlen) { if (maxlen < 0) { maxlen = strlen (name); } - r_str_trim (name); + rz_str_trim (name); char *oname = name; for (i = 0; *name; name++, i++) { if (maxlen && i > maxlen) { *name = '\0'; break; } - if (!r_name_validate_char (*name) && *name != '\\') { + if (!rz_name_validate_char (*name) && *name != '\\') { *name = '_'; - // r_str_ccpy (name, name+1, 0); + // rz_str_ccpy (name, name+1, 0); //name--; } } @@ -75,24 +75,24 @@ R_API bool r_name_filter(char *name, int maxlen) { ; } if (!len) { // name consists only of underscores - return r_name_check (oname); + return rz_name_check (oname); } for (i = 0; *(name + i) == '_'; i++, len--) { ; } memmove (name, name + i, len); *(name + len) = '\0'; - return r_name_check (oname); + return rz_name_check (oname); } -R_API char *r_name_filter2(const char *name) { +RZ_API char *rz_name_filter2(const char *name) { size_t i; while (!IS_PRINTABLE (*name)) { name++; } char *res = strdup (name); for (i = 0; res[i]; i++) { - if (!r_name_validate_char (res[i])) { + if (!rz_name_validate_char (res[i])) { res[i] = '_'; } } diff --git a/libr/util/pie.c b/librz/util/pie.c similarity index 89% rename from libr/util/pie.c rename to librz/util/pie.c index 761d75a7f4..d8fd43c2ab 100644 --- a/libr/util/pie.c +++ b/librz/util/pie.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2018 - pancake */ +/* rizin - LGPL - Copyright 2018 - pancake */ -#include -#include +#include +#include #include #define PI 3.1415 #define O out[x + (y * size)] @@ -24,7 +24,7 @@ static void drawSectorLine(char *out, int size, int percent) { } } -R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size) { +RZ_API int rz_print_pie(RPrint *p, ut64 *values, int nvalues, int size) { ut8 *nv = calloc (nvalues, sizeof (ut8)); char *out = calloc (size, size); int i, x, y; @@ -88,6 +88,6 @@ R_API int r_print_pie(RPrint *p, ut64 *values, int nvalues, int size) { #if 0 main() { ut64 v[] = { 10, 20, 30, 40 }; - r_print_pie (NULL, &v, 4, 20); + rz_print_pie (NULL, &v, 4, 20); } #endif diff --git a/libr/util/pj.c b/librz/util/pj.c similarity index 57% rename from libr/util/pj.c rename to librz/util/pj.c index 459f2862df..238c1b8dcd 100644 --- a/libr/util/pj.c +++ b/librz/util/pj.c @@ -1,17 +1,17 @@ /* radare - LGPL - Copyright 2018-2019 - pancake */ -#include -#include +#include +#include static void pj_raw(PJ *j, const char *msg) { - r_return_if_fail (j && msg); + rz_return_if_fail (j && msg); if (*msg) { - r_strbuf_append (&j->sb, msg); + rz_strbuf_append (&j->sb, msg); } } static void pj_comma(PJ *j) { - r_return_if_fail (j); + rz_return_if_fail (j); if (!j->is_key) { if (!j->is_first) { pj_raw (j, ","); @@ -21,39 +21,39 @@ static void pj_comma(PJ *j) { j->is_key = false; } -R_API PJ *pj_new(void) { +RZ_API PJ *pj_new(void) { PJ *j = R_NEW0 (PJ); if (j) { - r_strbuf_init (&j->sb); + rz_strbuf_init (&j->sb); j->is_first = true; } return j; } -R_API void pj_free(PJ *pj) { +RZ_API void pj_free(PJ *pj) { if (pj) { - r_strbuf_fini (&pj->sb); + rz_strbuf_fini (&pj->sb); free (pj); } } -R_API void pj_reset(PJ *j) { - r_return_if_fail (j); - r_strbuf_set (&j->sb, ""); +RZ_API void pj_reset(PJ *j) { + rz_return_if_fail (j); + rz_strbuf_set (&j->sb, ""); j->level = 0; j->is_first = true; j->is_key = false; } -R_API char *pj_drain(PJ *pj) { - r_return_val_if_fail (pj && pj->level == 0, NULL); - char *res = r_strbuf_drain_nofree (&pj->sb); +RZ_API char *pj_drain(PJ *pj) { + rz_return_val_if_fail (pj && pj->level == 0, NULL); + char *res = rz_strbuf_drain_nofree (&pj->sb); free (pj); return res; } -R_API const char *pj_string(PJ *j) { - return j? r_strbuf_get (&j->sb): NULL; +RZ_API const char *pj_string(PJ *j) { + return j? rz_strbuf_get (&j->sb): NULL; } static PJ *pj_begin(PJ *j, char type) { @@ -70,20 +70,20 @@ static PJ *pj_begin(PJ *j, char type) { return j; } -R_API PJ *pj_o(PJ *j) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_o(PJ *j) { + rz_return_val_if_fail (j, j); pj_comma (j); return pj_begin (j, '{'); } -R_API PJ *pj_a(PJ *j) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_a(PJ *j) { + rz_return_val_if_fail (j, j); pj_comma (j); return pj_begin (j, '['); } -R_API PJ *pj_end(PJ *j) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_end(PJ *j) { + rz_return_val_if_fail (j, j); if (j->level < 1) { return j; } @@ -99,8 +99,8 @@ R_API PJ *pj_end(PJ *j) { return j; } -R_API PJ *pj_k(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_k(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); j->is_key = false; pj_s (j, k); pj_raw (j, ":"); @@ -109,21 +109,21 @@ R_API PJ *pj_k(PJ *j, const char *k) { return j; } -R_API PJ *pj_knull(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_knull(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_null (j); return j; } -R_API PJ *pj_kn(PJ *j, const char *k, ut64 n) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_kn(PJ *j, const char *k, ut64 n) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_n (j, n); return j; } -R_API PJ *pj_kN(PJ *j, const char *k, st64 n) { +RZ_API PJ *pj_kN(PJ *j, const char *k, st64 n) { if (j && k) { pj_k (j, k); pj_N (j, n); @@ -131,72 +131,72 @@ R_API PJ *pj_kN(PJ *j, const char *k, st64 n) { return j; } -R_API PJ *pj_kd(PJ *j, const char *k, double d) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_kd(PJ *j, const char *k, double d) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_d (j, d); return j; } -R_API PJ *pj_kf(PJ *j, const char *k, float d) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_kf(PJ *j, const char *k, float d) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_f (j, d); return j; } -R_API PJ *pj_ki(PJ *j, const char *k, int i) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_ki(PJ *j, const char *k, int i) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_i (j, i); return j; } -R_API PJ *pj_ko(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_ko(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_o (j); return j; } -R_API PJ *pj_ka(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_ka(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_a (j); return j; } -R_API PJ *pj_ks(PJ *j, const char *k, const char *v) { - r_return_val_if_fail (j && k && v, j); +RZ_API PJ *pj_ks(PJ *j, const char *k, const char *v) { + rz_return_val_if_fail (j && k && v, j); pj_k (j, k); pj_s (j, v); return j; } -R_API PJ *pj_kb(PJ *j, const char *k, bool v) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_kb(PJ *j, const char *k, bool v) { + rz_return_val_if_fail (j && k, j); pj_k (j, k); pj_b (j, v); return j; } -R_API PJ *pj_null(PJ *j) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_null(PJ *j) { + rz_return_val_if_fail (j, j); pj_raw (j, "null"); return j; } -R_API PJ *pj_b(PJ *j, bool v) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_b(PJ *j, bool v) { + rz_return_val_if_fail (j, j); pj_comma (j); - pj_raw (j, r_str_bool (v)); + pj_raw (j, rz_str_bool (v)); return j; } -R_API PJ *pj_s(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_s(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); pj_comma (j); pj_raw (j, "\""); - char *ek = r_str_escape_utf8_for_json (k, -1); + char *ek = rz_str_escape_utf8_for_json (k, -1); if (ek) { pj_raw (j, ek); free (ek); @@ -207,8 +207,8 @@ R_API PJ *pj_s(PJ *j, const char *k) { return j; } -R_API PJ *pj_r(PJ *j, const unsigned char *v, size_t v_len) { - r_return_val_if_fail (j && v, j); +RZ_API PJ *pj_r(PJ *j, const unsigned char *v, size_t v_len) { + rz_return_val_if_fail (j && v, j); size_t i; pj_a (j); for (i = 0; i < v_len; i++) { @@ -218,15 +218,15 @@ R_API PJ *pj_r(PJ *j, const unsigned char *v, size_t v_len) { return j; } -R_API PJ *pj_kr(PJ *j, const char *k, const unsigned char *v, size_t v_len) { - r_return_val_if_fail (j && k && v, j); +RZ_API PJ *pj_kr(PJ *j, const char *k, const unsigned char *v, size_t v_len) { + rz_return_val_if_fail (j && k && v, j); pj_k (j, k); pj_r (j, v, v_len); return j; } -R_API PJ *pj_j(PJ *j, const char *k) { - r_return_val_if_fail (j && k, j); +RZ_API PJ *pj_j(PJ *j, const char *k) { + rz_return_val_if_fail (j && k, j); if (*k) { pj_comma (j); pj_raw (j, k); @@ -234,35 +234,35 @@ R_API PJ *pj_j(PJ *j, const char *k) { return j; } -R_API PJ *pj_n(PJ *j, ut64 n) { - r_return_val_if_fail (j, j); +RZ_API PJ *pj_n(PJ *j, ut64 n) { + rz_return_val_if_fail (j, j); pj_comma (j); pj_raw (j, sdb_fmt ("%" PFMT64u, n)); return j; } -R_API PJ *pj_N(PJ *j, st64 n) { - r_return_val_if_fail (j, NULL); +RZ_API PJ *pj_N(PJ *j, st64 n) { + rz_return_val_if_fail (j, NULL); pj_comma (j); pj_raw (j, sdb_fmt ("%"PFMT64d, n)); return j; } -R_API PJ *pj_f(PJ *j, float f) { - r_return_val_if_fail (j, NULL); +RZ_API PJ *pj_f(PJ *j, float f) { + rz_return_val_if_fail (j, NULL); pj_comma (j); pj_raw (j, sdb_fmt ("%f", f)); return j; } -R_API PJ *pj_d(PJ *j, double d) { - r_return_val_if_fail (j, NULL); +RZ_API PJ *pj_d(PJ *j, double d) { + rz_return_val_if_fail (j, NULL); pj_comma (j); pj_raw (j, sdb_fmt ("%lf", d)); return j; } -R_API PJ *pj_i(PJ *j, int i) { +RZ_API PJ *pj_i(PJ *j, int i) { if (j) { pj_comma (j); pj_raw (j, sdb_fmt ("%d", i)); @@ -270,7 +270,7 @@ R_API PJ *pj_i(PJ *j, int i) { return j; } -R_API char *pj_fmt(PrintfCallback p, const char *fmt, ...) { +RZ_API char *pj_fmt(PrintfCallback p, const char *fmt, ...) { va_list ap; va_start (ap, fmt); @@ -312,7 +312,7 @@ R_API char *pj_fmt(PrintfCallback p, const char *fmt, ...) { break; case 'S': { const char *s = va_arg (ap, const char *); - char *es = r_base64_encode_dyn (s, -1); + char *es = rz_base64_encode_dyn (s, -1); pj_s (j, es); free (es); } break; @@ -339,7 +339,7 @@ R_API char *pj_fmt(PrintfCallback p, const char *fmt, ...) { } char *ret = NULL; if (p) { - p ("%s", r_strbuf_get (&j->sb)); + p ("%s", rz_strbuf_get (&j->sb)); pj_free (j); } else { ret = pj_drain (j); diff --git a/libr/util/pkcs7.c b/librz/util/pkcs7.c similarity index 55% rename from libr/util/pkcs7.c rename to librz/util/pkcs7.c index 7722e05538..0614996cbf 100644 --- a/libr/util/pkcs7.c +++ b/librz/util/pkcs7.c @@ -1,30 +1,30 @@ -/* radare2 - LGPL - Copyright 2017-2018 - wargio */ +/* rizin - LGPL - Copyright 2017-2018 - wargio */ #include #include -#include +#include #include "./x509.h" -extern void r_x509_name_json (PJ *pj, RX509Name *name); -extern void r_x509_free_crl (RX509CertificateRevocationList *crl); -extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb); -static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object); +extern void rz_x509_name_json (PJ *pj, RX509Name *name); +extern void rz_x509_free_crl (RX509CertificateRevocationList *crl); +extern void rz_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb); +static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object); -static bool r_pkcs7_parse_contentinfo(RPKCS7ContentInfo *ci, RASN1Object *object) { +static bool rz_pkcs7_parse_contentinfo(RPKCS7ContentInfo *ci, RASN1Object *object) { if (!ci || !object || object->list.length < 1 || !object->list.objects[0]) { return false; } - ci->contentType = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); + ci->contentType = rz_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); if (object->list.length > 1) { RASN1Object *obj1 = object->list.objects[1]; if (obj1) { - ci->content = r_asn1_create_binary (obj1->sector, obj1->length); + ci->content = rz_asn1_create_binary (obj1->sector, obj1->length); } } return true; } -static bool r_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls, RASN1Object *object) { +static bool rz_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls, RASN1Object *object) { ut32 i; if (!crls || !object) { return false; @@ -36,17 +36,17 @@ static bool r_pkcs7_parse_certificaterevocationlists(RPKCS7CertificateRevocation } crls->length = object->list.length; for (i = 0; i < crls->length; i++) { - crls->elements[i] = r_x509_parse_crl (object->list.objects[i]); + crls->elements[i] = rz_x509_parse_crl (object->list.objects[i]); } } return true; } -static void r_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls) { +static void rz_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationLists *crls) { ut32 i; if (crls) { for (i = 0; i < crls->length; i++) { - r_x509_free_crl (crls->elements[i]); + rz_x509_free_crl (crls->elements[i]); crls->elements[i] = NULL; } R_FREE (crls->elements); @@ -54,7 +54,7 @@ static void r_pkcs7_free_certificaterevocationlists(RPKCS7CertificateRevocationL } } -static bool r_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object) { +static bool rz_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac, RASN1Object *object) { ut32 i; if (!ecac || !object) { return false; @@ -66,18 +66,18 @@ static bool r_pkcs7_parse_extendedcertificatesandcertificates(RPKCS7ExtendedCert } ecac->length = object->list.length; for (i = 0; i < ecac->length; i++) { - ecac->elements[i] = r_x509_parse_certificate (object->list.objects[i]); + ecac->elements[i] = rz_x509_parse_certificate (object->list.objects[i]); object->list.objects[i] = NULL; } } return true; } -static void r_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac) { +static void rz_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCertificatesAndCertificates *ecac) { ut32 i; if (ecac) { for (i = 0; i < ecac->length; i++) { - r_x509_free_certificate (ecac->elements[i]); + rz_x509_free_certificate (ecac->elements[i]); ecac->elements[i] = NULL; } R_FREE (ecac->elements); @@ -85,7 +85,7 @@ static void r_pkcs7_free_extendedcertificatesandcertificates(RPKCS7ExtendedCerti } } -static bool r_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object) { +static bool rz_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai, RASN1Object *object) { ut32 i; if (!dai || !object) { return false; @@ -97,7 +97,7 @@ static bool r_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentif } dai->length = object->list.length; for (i = 0; i < dai->length; i++) { - // r_x509_parse_algorithmidentifier returns bool, + // rz_x509_parse_algorithmidentifier returns bool, // so i have to allocate before calling the function dai->elements[i] = (RX509AlgorithmIdentifier *)malloc (sizeof (RX509AlgorithmIdentifier)); //should i handle invalid memory? the function checks the pointer @@ -105,20 +105,20 @@ static bool r_pkcs7_parse_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentif if (dai->elements[i]) { //Memset is needed to initialize to 0 the structure and avoid garbage. memset (dai->elements[i], 0, sizeof (RX509AlgorithmIdentifier)); - r_x509_parse_algorithmidentifier (dai->elements[i], object->list.objects[i]); + rz_x509_parse_algorithmidentifier (dai->elements[i], object->list.objects[i]); } } } return true; } -static void r_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai) { +static void rz_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifiers *dai) { ut32 i; if (dai) { for (i = 0; i < dai->length; i++) { if (dai->elements[i]) { - r_x509_free_algorithmidentifier (dai->elements[i]); - // r_x509_free_algorithmidentifier doesn't free the pointer + rz_x509_free_algorithmidentifier (dai->elements[i]); + // rz_x509_free_algorithmidentifier doesn't free the pointer // because on x509 the original use was internal. R_FREE (dai->elements[i]); } @@ -128,30 +128,30 @@ static void r_pkcs7_free_digestalgorithmidentifier(RPKCS7DigestAlgorithmIdentifi } } -static void r_pkcs7_free_contentinfo(RPKCS7ContentInfo *ci) { +static void rz_pkcs7_free_contentinfo(RPKCS7ContentInfo *ci) { if (ci) { - r_asn1_free_binary (ci->content); - r_asn1_free_string (ci->contentType); + rz_asn1_free_binary (ci->content); + rz_asn1_free_string (ci->contentType); // Used internally pkcs #7, so it shouldn't free ci. } } -static bool r_pkcs7_parse_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object) { +static bool rz_pkcs7_parse_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu, RASN1Object *object) { if (!iasu || !object || object->list.length != 2) { return false; } - r_x509_parse_name (&iasu->issuer, object->list.objects[0]); + rz_x509_parse_name (&iasu->issuer, object->list.objects[0]); RASN1Object *obj1 = object->list.objects[1]; if (obj1) { - iasu->serialNumber = r_asn1_create_binary (obj1->sector, obj1->length); + iasu->serialNumber = rz_asn1_create_binary (obj1->sector, obj1->length); } return true; } -static void r_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu) { +static void rz_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu) { if (iasu) { - r_x509_free_name (&iasu->issuer); - r_asn1_free_binary (iasu->serialNumber); + rz_x509_free_name (&iasu->issuer); + rz_asn1_free_binary (iasu->serialNumber); // Used internally pkcs #7, so it shouldn't free iasu. } } @@ -163,7 +163,7 @@ static void r_pkcs7_free_issuerandserialnumber(RPKCS7IssuerAndSerialNumber *iasu } RPKCS7SignerInfo; */ -static bool r_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object) { +static bool rz_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object) { RASN1Object **elems; ut32 shift = 3; if (!si || !object || object->list.length < 5) { @@ -172,64 +172,64 @@ static bool r_pkcs7_parse_signerinfo(RPKCS7SignerInfo *si, RASN1Object *object) elems = object->list.objects; //Following RFC si->version = (ut32)elems[0]->sector[0]; - r_pkcs7_parse_issuerandserialnumber (&si->issuerAndSerialNumber, elems[1]); - r_x509_parse_algorithmidentifier (&si->digestAlgorithm, elems[2]); + rz_pkcs7_parse_issuerandserialnumber (&si->issuerAndSerialNumber, elems[1]); + rz_x509_parse_algorithmidentifier (&si->digestAlgorithm, elems[2]); if (shift < object->list.length && elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 0) { - r_pkcs7_parse_attributes (&si->authenticatedAttributes, elems[shift]); + rz_pkcs7_parse_attributes (&si->authenticatedAttributes, elems[shift]); shift++; } if (shift < object->list.length) { - r_x509_parse_algorithmidentifier (&si->digestEncryptionAlgorithm, elems[shift]); + rz_x509_parse_algorithmidentifier (&si->digestEncryptionAlgorithm, elems[shift]); shift++; } if (shift < object->list.length) { RASN1Object *obj1 = object->list.objects[shift]; if (obj1) { - si->encryptedDigest = r_asn1_create_binary (obj1->sector, obj1->length); + si->encryptedDigest = rz_asn1_create_binary (obj1->sector, obj1->length); shift++; } } if (shift < object->list.length) { RASN1Object *elem = elems[shift]; if (elem && elem->klass == CLASS_CONTEXT && elem->tag == 1) { - r_pkcs7_parse_attributes (&si->unauthenticatedAttributes, elems[shift]); + rz_pkcs7_parse_attributes (&si->unauthenticatedAttributes, elems[shift]); } } return true; } -static void r_pkcs7_free_attribute(RPKCS7Attribute *attribute) { +static void rz_pkcs7_free_attribute(RPKCS7Attribute *attribute) { if (attribute) { - r_asn1_free_binary (attribute->data); - r_asn1_free_string (attribute->oid); + rz_asn1_free_binary (attribute->data); + rz_asn1_free_string (attribute->oid); free (attribute); } } -static void r_pkcs7_free_attributes(RPKCS7Attributes *attributes) { +static void rz_pkcs7_free_attributes(RPKCS7Attributes *attributes) { ut32 i; if (attributes) { for (i = 0; i < attributes->length; i++) { - r_pkcs7_free_attribute (attributes->elements[i]); + rz_pkcs7_free_attribute (attributes->elements[i]); } R_FREE (attributes->elements); // Used internally pkcs #7, so it shouldn't free attributes. } } -static void r_pkcs7_free_signerinfo(RPKCS7SignerInfo *si) { +static void rz_pkcs7_free_signerinfo(RPKCS7SignerInfo *si) { if (si) { - r_pkcs7_free_issuerandserialnumber (&si->issuerAndSerialNumber); - r_x509_free_algorithmidentifier (&si->digestAlgorithm); - r_pkcs7_free_attributes (&si->authenticatedAttributes); - r_x509_free_algorithmidentifier (&si->digestEncryptionAlgorithm); - r_asn1_free_binary (si->encryptedDigest); - r_pkcs7_free_attributes (&si->unauthenticatedAttributes); + rz_pkcs7_free_issuerandserialnumber (&si->issuerAndSerialNumber); + rz_x509_free_algorithmidentifier (&si->digestAlgorithm); + rz_pkcs7_free_attributes (&si->authenticatedAttributes); + rz_x509_free_algorithmidentifier (&si->digestEncryptionAlgorithm); + rz_asn1_free_binary (si->encryptedDigest); + rz_pkcs7_free_attributes (&si->unauthenticatedAttributes); free (si); } } -static bool r_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object) { +static bool rz_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object) { ut32 i; if (!ss || !object) { return false; @@ -241,22 +241,22 @@ static bool r_pkcs7_parse_signerinfos(RPKCS7SignerInfos *ss, RASN1Object *object } ss->length = object->list.length; for (i = 0; i < ss->length; i++) { - // r_pkcs7_parse_signerinfo returns bool, + // rz_pkcs7_parse_signerinfo returns bool, // so i have to allocate before calling the function ss->elements[i] = R_NEW0 (RPKCS7SignerInfo); //should i handle invalid memory? the function checks the pointer //or it should return if si->elements[i] == NULL ? - r_pkcs7_parse_signerinfo (ss->elements[i], object->list.objects[i]); + rz_pkcs7_parse_signerinfo (ss->elements[i], object->list.objects[i]); } } return true; } -static void r_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss) { +static void rz_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss) { ut32 i; if (ss) { for (i = 0; i < ss->length; i++) { - r_pkcs7_free_signerinfo (ss->elements[i]); + rz_pkcs7_free_signerinfo (ss->elements[i]); ss->elements[i] = NULL; } R_FREE (ss->elements); @@ -264,7 +264,7 @@ static void r_pkcs7_free_signerinfos(RPKCS7SignerInfos *ss) { } } -static bool r_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object) { +static bool rz_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object) { ut32 shift = 3; if (!sd || !object || object->list.length < 4) { return false; @@ -273,38 +273,38 @@ static bool r_pkcs7_parse_signeddata(RPKCS7SignedData *sd, RASN1Object *object) RASN1Object **elems = object->list.objects; //Following RFC sd->version = (ut32)elems[0]->sector[0]; - r_pkcs7_parse_digestalgorithmidentifier (&sd->digestAlgorithms, elems[1]); - r_pkcs7_parse_contentinfo (&sd->contentInfo, elems[2]); + rz_pkcs7_parse_digestalgorithmidentifier (&sd->digestAlgorithms, elems[1]); + rz_pkcs7_parse_contentinfo (&sd->contentInfo, elems[2]); //Optional if (object->list.length > 3 && shift < object->list.length && elems[shift] && elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 0) { - r_pkcs7_parse_extendedcertificatesandcertificates (&sd->certificates, elems[shift]); + rz_pkcs7_parse_extendedcertificatesandcertificates (&sd->certificates, elems[shift]); shift++; } //Optional if (object->list.length > 3 && shift < object->list.length && elems[shift] && elems[shift]->klass == CLASS_CONTEXT && elems[shift]->tag == 1) { - r_pkcs7_parse_certificaterevocationlists (&sd->crls, elems[shift]); + rz_pkcs7_parse_certificaterevocationlists (&sd->crls, elems[shift]); shift++; } if (shift < object->list.length) { - r_pkcs7_parse_signerinfos (&sd->signerinfos, elems[shift]); + rz_pkcs7_parse_signerinfos (&sd->signerinfos, elems[shift]); } return true; } -static void r_pkcs7_free_signeddata(RPKCS7SignedData *sd) { +static void rz_pkcs7_free_signeddata(RPKCS7SignedData *sd) { if (sd) { - r_pkcs7_free_digestalgorithmidentifier (&sd->digestAlgorithms); - r_pkcs7_free_contentinfo (&sd->contentInfo); - r_pkcs7_free_extendedcertificatesandcertificates (&sd->certificates); - r_pkcs7_free_certificaterevocationlists (&sd->crls); - r_pkcs7_free_signerinfos (&sd->signerinfos); + rz_pkcs7_free_digestalgorithmidentifier (&sd->digestAlgorithms); + rz_pkcs7_free_contentinfo (&sd->contentInfo); + rz_pkcs7_free_extendedcertificatesandcertificates (&sd->certificates); + rz_pkcs7_free_certificaterevocationlists (&sd->crls); + rz_pkcs7_free_signerinfos (&sd->signerinfos); // Used internally pkcs #7, so it shouldn't free sd. } } -R_API RCMS *r_pkcs7_parse_cms(const ut8 *buffer, ut32 length) { +RZ_API RCMS *rz_pkcs7_parse_cms(const ut8 *buffer, ut32 length) { RASN1Object *object; RCMS *container; if (!buffer || !length) { @@ -314,37 +314,37 @@ R_API RCMS *r_pkcs7_parse_cms(const ut8 *buffer, ut32 length) { if (!container) { return NULL; } - object = r_asn1_create_object (buffer, length, buffer); + object = rz_asn1_create_object (buffer, length, buffer); if (!object || object->list.length < 2 || !object->list.objects || !object->list.objects[0] || !object->list.objects[1] || object->list.objects[1]->list.length < 1) { - r_asn1_free_object (object); + rz_asn1_free_object (object); free (container); return NULL; } if (object->list.objects[0]) { - container->contentType = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); + container->contentType = rz_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); if (!container->contentType) { - r_asn1_free_object (object); + rz_asn1_free_object (object); return NULL; } } if (object->list.objects[1]) { - r_pkcs7_parse_signeddata (&container->signedData, object->list.objects[1]->list.objects[0]); + rz_pkcs7_parse_signeddata (&container->signedData, object->list.objects[1]->list.objects[0]); } - r_asn1_free_object (object); + rz_asn1_free_object (object); return container; } -R_API void r_pkcs7_free_cms(RCMS *container) { +RZ_API void rz_pkcs7_free_cms(RCMS *container) { if (container) { - r_asn1_free_string (container->contentType); - r_pkcs7_free_signeddata (&container->signedData); + rz_asn1_free_string (container->contentType); + rz_pkcs7_free_signeddata (&container->signedData); free (container); } } -static RPKCS7Attribute *r_pkcs7_parse_attribute(RASN1Object *object) { +static RPKCS7Attribute *rz_pkcs7_parse_attribute(RASN1Object *object) { RPKCS7Attribute *attribute; if (!object || object->list.length < 1) { return NULL; @@ -354,18 +354,18 @@ static RPKCS7Attribute *r_pkcs7_parse_attribute(RASN1Object *object) { return NULL; } if (object->list.objects[0]) { - attribute->oid = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); + attribute->oid = rz_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); } if (object->list.length == 2) { RASN1Object *obj1 = object->list.objects[1]; if (obj1) { - attribute->data = r_asn1_create_binary (obj1->sector, obj1->length); + attribute->data = rz_asn1_create_binary (obj1->sector, obj1->length); } } return attribute; } -static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object *object) { +static bool rz_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object *object) { ut32 i; if (!attributes || !object || !object->list.length) { return false; @@ -379,7 +379,7 @@ static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object * return false; } for (i = 0; i < object->list.length; i++) { - attributes->elements[i] = r_pkcs7_parse_attribute (object->list.objects[i]); + attributes->elements[i] = rz_pkcs7_parse_attribute (object->list.objects[i]); } } return true; @@ -387,7 +387,7 @@ static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attributes, RASN1Object * #if 0 // XXX: unused -static void r_pkcs7_signerinfos_dump(RX509CertificateRevocationList *crl, const char* pad, RStrBuf *sb) { +static void rz_pkcs7_signerinfos_dump(RX509CertificateRevocationList *crl, const char* pad, RStrBuf *sb) { RASN1String *algo = NULL, *last = NULL, *next = NULL; ut32 i; char *pad2, *pad3; @@ -397,26 +397,26 @@ static void r_pkcs7_signerinfos_dump(RX509CertificateRevocationList *crl, const if (!pad) { pad = ""; } - pad3 = r_str_newf ("%s ", pad); + pad3 = rz_str_newf ("%s ", pad); if (!pad3) return; pad2 = pad3 + 2; algo = crl->signature.algorithm; last = crl->lastUpdate; next = crl->nextUpdate; - r_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3, algo ? algo->string : "", pad2); - r_x509_name_dump (&crl->issuer, pad3, sb); - r_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n", + rz_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3, algo ? algo->string : "", pad2); + rz_x509_name_dump (&crl->issuer, pad3, sb); + rz_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n", pad2, last ? last->string : "Missing", pad2, next ? next->string : "Missing", pad2); for (i = 0; i < crl->length; i++) { - r_x509_crlentry_dump (crl->revokedCertificates[i], pad3, sb); + rz_x509_crlentry_dump (crl->revokedCertificates[i], pad3, sb); } free (pad3); } #endif -static void r_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBuf *sb) { +static void rz_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBuf *sb) { RASN1String *s = NULL; RASN1Binary *o = NULL; ut32 i; @@ -427,22 +427,22 @@ static void r_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBu if (!pad) { pad = ""; } - pad3 = r_str_newf ("%s ", pad); + pad3 = rz_str_newf ("%s ", pad); if (!pad3) { return; } pad2 = pad3 + 2; - r_strbuf_appendf (sb, "%sSignerInfo:\n%sVersion: v%u\n%sIssuer\n", pad, pad2, si->version + 1, pad2); - r_x509_name_dump (&si->issuerAndSerialNumber.issuer, pad3, sb); + rz_strbuf_appendf (sb, "%sSignerInfo:\n%sVersion: v%u\n%sIssuer\n", pad, pad2, si->version + 1, pad2); + rz_x509_name_dump (&si->issuerAndSerialNumber.issuer, pad3, sb); if ((o = si->issuerAndSerialNumber.serialNumber)) { - s = r_asn1_stringify_integer (o->binary, o->length); + s = rz_asn1_stringify_integer (o->binary, o->length); } - r_strbuf_appendf (sb, "%sSerial Number:\n%s%s\n", pad2, pad3, s ? s->string : "Missing"); - r_asn1_free_string (s); + rz_strbuf_appendf (sb, "%sSerial Number:\n%s%s\n", pad2, pad3, s ? s->string : "Missing"); + rz_asn1_free_string (s); s = si->digestAlgorithm.algorithm; - r_strbuf_appendf (sb, "%sDigest Algorithm:\n%s%s\n%sAuthenticated Attributes:\n", + rz_strbuf_appendf (sb, "%sDigest Algorithm:\n%s%s\n%sAuthenticated Attributes:\n", pad2, pad3, s ? s->string : "Missing", pad2); for (i = 0; i < si->authenticatedAttributes.length; i++) { @@ -450,18 +450,18 @@ static void r_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBu if (!attr) { continue; } - r_strbuf_appendf (sb, "%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing", + rz_strbuf_appendf (sb, "%s%s: %u bytes\n", pad3, attr->oid ? attr->oid->string : "Missing", attr->data ? attr->data->length : 0); } s = si->digestEncryptionAlgorithm.algorithm; - r_strbuf_appendf (sb, "%sDigest Encryption Algorithm\n%s%s\n", pad2, pad3, s ? s->string : "Missing"); + rz_strbuf_appendf (sb, "%sDigest Encryption Algorithm\n%s%s\n", pad2, pad3, s ? s->string : "Missing"); - // if ((o = si->encryptedDigest)) s = r_asn1_stringify_bytes (o->binary, o->length); + // if ((o = si->encryptedDigest)) s = rz_asn1_stringify_bytes (o->binary, o->length); // else s = NULL; // eprintf ("%sEncrypted Digest: %u bytes\n%s\n", pad2, o ? o->length : 0, s ? s->string : "Missing"); - // r_asn1_free_string (s); - r_strbuf_appendf (sb, "%sEncrypted Digest: %u bytes\n", pad2, o ? o->length : 0); - r_strbuf_appendf (sb, "%sUnauthenticated Attributes:\n", pad2); + // rz_asn1_free_string (s); + rz_strbuf_appendf (sb, "%sEncrypted Digest: %u bytes\n", pad2, o ? o->length : 0); + rz_strbuf_appendf (sb, "%sUnauthenticated Attributes:\n", pad2); for (i = 0; i < si->unauthenticatedAttributes.length; i++) { RPKCS7Attribute *attr = si->unauthenticatedAttributes.elements[i]; if (!attr) { @@ -474,63 +474,63 @@ static void r_x509_signedinfo_dump(RPKCS7SignerInfo *si, const char *pad, RStrBu free (pad3); } -R_API char *r_pkcs7_cms_to_string(RCMS *container) { +RZ_API char *rz_pkcs7_cms_to_string(RCMS *container) { ut32 i; if (!container) { return NULL; } RPKCS7SignedData *sd = &container->signedData; - RStrBuf *sb = r_strbuf_new (""); - r_strbuf_appendf (sb, "signedData\n Version: v%u\n Digest Algorithms:\n", sd->version); + RStrBuf *sb = rz_strbuf_new (""); + rz_strbuf_appendf (sb, "signedData\n Version: v%u\n Digest Algorithms:\n", sd->version); if (container->signedData.digestAlgorithms.elements) { for (i = 0; i < container->signedData.digestAlgorithms.length; i++) { if (container->signedData.digestAlgorithms.elements[i]) { RASN1String *s = container->signedData.digestAlgorithms.elements[i]->algorithm; - r_strbuf_appendf (sb, " %s\n", s ? s->string : "Missing"); + rz_strbuf_appendf (sb, " %s\n", s ? s->string : "Missing"); } } } - r_strbuf_appendf (sb, " Certificates: %u\n", container->signedData.certificates.length); + rz_strbuf_appendf (sb, " Certificates: %u\n", container->signedData.certificates.length); for (i = 0; i < container->signedData.certificates.length; i++) { - r_x509_certificate_dump (container->signedData.certificates.elements[i], " ", sb); + rz_x509_certificate_dump (container->signedData.certificates.elements[i], " ", sb); } for (i = 0; i < container->signedData.crls.length; i++) { - char *res = r_x509_crl_to_string (container->signedData.crls.elements[i], " "); + char *res = rz_x509_crl_to_string (container->signedData.crls.elements[i], " "); if (res) { - r_strbuf_append (sb, res); + rz_strbuf_append (sb, res); free (res); } } - r_strbuf_appendf (sb, " SignerInfos:\n"); + rz_strbuf_appendf (sb, " SignerInfos:\n"); if (container->signedData.signerinfos.elements) { for (i = 0; i < container->signedData.signerinfos.length; i++) { - r_x509_signedinfo_dump (container->signedData.signerinfos.elements[i], " ", sb); + rz_x509_signedinfo_dump (container->signedData.signerinfos.elements[i], " ", sb); } } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API void r_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si) { +RZ_API void rz_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si) { ut32 i; if (si) { pj_o (pj); pj_ki (pj, "Version", si->version + 1); pj_k (pj, "Issuer"); pj_o (pj); - r_x509_name_json (pj, &si->issuerAndSerialNumber.issuer); + rz_x509_name_json (pj, &si->issuerAndSerialNumber.issuer); pj_end (pj); if (si->issuerAndSerialNumber.serialNumber) { RASN1Binary *o = si->issuerAndSerialNumber.serialNumber; - RASN1String *s = r_asn1_stringify_integer (o->binary, o->length); + RASN1String *s = rz_asn1_stringify_integer (o->binary, o->length); if (s) { pj_ks (pj, "SerialNumber", s->string); } - r_asn1_free_string (s); + rz_asn1_free_string (s); } if (si->digestAlgorithm.algorithm) { @@ -559,11 +559,11 @@ R_API void r_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si) { if (si->encryptedDigest) { RASN1Binary *o = si->encryptedDigest; - RASN1String *s = r_asn1_stringify_integer (o->binary, o->length); + RASN1String *s = rz_asn1_stringify_integer (o->binary, o->length); if (s) { pj_ks (pj, "EncryptedDigest", s->string); } - r_asn1_free_string (s); + rz_asn1_free_string (s); } pj_k (pj, "UnauthenticatedAttributes"); @@ -587,7 +587,7 @@ R_API void r_x509_signedinfo_json(PJ *pj, RPKCS7SignerInfo *si) { } } -R_API PJ *r_pkcs7_cms_json (RCMS *container) { +RZ_API PJ *rz_pkcs7_cms_json (RCMS *container) { PJ *pj = NULL; if (container) { ut32 i; @@ -614,14 +614,14 @@ R_API PJ *r_pkcs7_cms_json (RCMS *container) { pj_k (pj, "Certificates"); pj_a (pj); for (i = 0; i < container->signedData.certificates.length; i++) { - r_x509_certificate_json (pj, container->signedData.certificates.elements[i]); + rz_x509_certificate_json (pj, container->signedData.certificates.elements[i]); } pj_end (pj); pj_k (pj, "CRL"); pj_a (pj); for (i = 0; i < container->signedData.crls.length; i++) { - r_x509_crl_json (pj, container->signedData.crls.elements[i]); + rz_x509_crl_json (pj, container->signedData.crls.elements[i]); } pj_end (pj); @@ -629,7 +629,7 @@ R_API PJ *r_pkcs7_cms_json (RCMS *container) { pj_a (pj); if (container->signedData.signerinfos.elements) { for (i = 0; i < container->signedData.signerinfos.length; i++) { - r_x509_signedinfo_json (pj, container->signedData.signerinfos.elements[i]); + rz_x509_signedinfo_json (pj, container->signedData.signerinfos.elements[i]); } } pj_end (pj); @@ -638,39 +638,39 @@ R_API PJ *r_pkcs7_cms_json (RCMS *container) { return pj; } -static bool r_pkcs7_parse_spcdata(SpcAttributeTypeAndOptionalValue *data, RASN1Object *object) { +static bool rz_pkcs7_parse_spcdata(SpcAttributeTypeAndOptionalValue *data, RASN1Object *object) { if (!data || !object || object->list.length < 1 || !object->list.objects[0]) { return false; } - data->type = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); + data->type = rz_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); if (!data->type) { return false; } RASN1Object *obj1 = object->list.objects[1]; if (object->list.length > 1) { if (obj1) { - data->data = r_asn1_create_binary (obj1->sector, obj1->length); + data->data = rz_asn1_create_binary (obj1->sector, obj1->length); } } return true; } -static bool r_pkcs7_parse_spcmessagedigest(SpcDigestInfo *messageDigest, RASN1Object *object) { +static bool rz_pkcs7_parse_spcmessagedigest(SpcDigestInfo *messageDigest, RASN1Object *object) { if (!messageDigest || !object || object->list.length < 2 || !object->list.objects[0] || !object->list.objects[1]) { return false; } - if (!r_x509_parse_algorithmidentifier (&messageDigest->digestAlgorithm, object->list.objects[0])) { + if (!rz_x509_parse_algorithmidentifier (&messageDigest->digestAlgorithm, object->list.objects[0])) { return false; } RASN1Object *obj1 = object->list.objects[1]; - messageDigest->digest = r_asn1_create_binary (obj1->sector, obj1->length); + messageDigest->digest = rz_asn1_create_binary (obj1->sector, obj1->length); return true; } -R_API SpcIndirectDataContent *r_pkcs7_parse_spcinfo(RCMS *cms) { - r_return_val_if_fail (cms, NULL); +RZ_API SpcIndirectDataContent *rz_pkcs7_parse_spcinfo(RCMS *cms) { + rz_return_val_if_fail (cms, NULL); RASN1String *type = cms->signedData.contentInfo.contentType; if (type && strcmp (type->string, "spcIndirectDataContext")) { @@ -687,46 +687,46 @@ R_API SpcIndirectDataContent *r_pkcs7_parse_spcinfo(RCMS *cms) { free (spcinfo); return NULL; } - RASN1Object *object = r_asn1_create_object (content->binary, content->length, content->binary); + RASN1Object *object = rz_asn1_create_object (content->binary, content->length, content->binary); if (!object || object->list.length < 2 || !object->list.objects || !object->list.objects[0] || !object->list.objects[1]) { R_FREE (spcinfo); goto beach; } if (object->list.objects[0]) { - if (!r_pkcs7_parse_spcdata (&spcinfo->data, object->list.objects[0])) { + if (!rz_pkcs7_parse_spcdata (&spcinfo->data, object->list.objects[0])) { R_FREE (spcinfo); goto beach; } } if (object->list.objects[1]) { - if (!r_pkcs7_parse_spcmessagedigest (&spcinfo->messageDigest, object->list.objects[1])) { + if (!rz_pkcs7_parse_spcmessagedigest (&spcinfo->messageDigest, object->list.objects[1])) { R_FREE (spcinfo); goto beach; } } beach: - r_asn1_free_object (object); + rz_asn1_free_object (object); return spcinfo; } -static void r_pkcs7_free_spcdata(SpcAttributeTypeAndOptionalValue *data) { +static void rz_pkcs7_free_spcdata(SpcAttributeTypeAndOptionalValue *data) { if (data) { - r_asn1_free_string (data->type); - r_asn1_free_binary (data->data); + rz_asn1_free_string (data->type); + rz_asn1_free_binary (data->data); } } -static void r_pkcs7_free_spcmessagedigest(SpcDigestInfo *messageDigest) { +static void rz_pkcs7_free_spcmessagedigest(SpcDigestInfo *messageDigest) { if (messageDigest) { - r_asn1_free_binary (messageDigest->digest); - r_x509_free_algorithmidentifier (&messageDigest->digestAlgorithm); + rz_asn1_free_binary (messageDigest->digest); + rz_x509_free_algorithmidentifier (&messageDigest->digestAlgorithm); } } -R_API void r_pkcs7_free_spcinfo(SpcIndirectDataContent *spcinfo) { +RZ_API void rz_pkcs7_free_spcinfo(SpcIndirectDataContent *spcinfo) { if (spcinfo) { - r_pkcs7_free_spcdata (&spcinfo->data); - r_pkcs7_free_spcmessagedigest (&spcinfo->messageDigest); + rz_pkcs7_free_spcdata (&spcinfo->data); + rz_pkcs7_free_spcmessagedigest (&spcinfo->messageDigest); } } diff --git a/libr/util/print.c b/librz/util/print.c similarity index 86% rename from libr/util/print.c rename to librz/util/print.c index 25f37394c0..0918518689 100644 --- a/libr/util/print.c +++ b/librz/util/print.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include -#include +#include +#include #define DFLT_ROWS 16 @@ -29,7 +29,7 @@ static int libc_eprintf(const char *format, ...) { static RPrintIsInterruptedCallback is_interrupted_cb = NULL; -R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions) { +RZ_API void rz_print_portionbar(RPrint *p, const ut64 *portions, int n_portions) { const int use_color = p->flags & R_PRINT_FLAGS_COLOR; int i, j; ut64 total = 0LL; @@ -65,13 +65,13 @@ R_API void r_print_portionbar(RPrint *p, const ut64 *portions, int n_portions) { p->cb_printf ("]\n"); } -R_API void r_print_columns(RPrint *p, const ut8 *buf, int len, int height) { +RZ_API void rz_print_columns(RPrint *p, const ut8 *buf, int len, int height) { size_t i, j; int cols = 78; // TODO: do not hardcode this value, columns should be defined by the user int rows = height > 0 ? height : 10; // int realrows = rows * 2; bool colors = p->flags & R_PRINT_FLAGS_COLOR; - RConsPrintablePalette *pal = &p->cons->context->pal; + RzConsPrintablePalette *pal = &p->cons->context->pal; const char *vline = p->cons->use_utf8 ? RUNE_LINE_VERT : "|"; const char *block = p->cons->use_utf8 ? UTF_BLOCK : "#"; const char *kol[5]; @@ -121,7 +121,7 @@ R_API void r_print_columns(RPrint *p, const ut8 *buf, int len, int height) { } } -R_API int r_util_lines_getline(ut64 *lines_cache, int lines_cache_sz, ut64 off) { +RZ_API int rz_util_lines_getline(ut64 *lines_cache, int lines_cache_sz, ut64 off) { int imax = lines_cache_sz; int imin = 0; int imid = 0; @@ -140,18 +140,18 @@ R_API int r_util_lines_getline(ut64 *lines_cache, int lines_cache_sz, ut64 off) return imin; } -R_API bool r_print_is_interrupted(void) { +RZ_API bool rz_print_is_interrupted(void) { if (is_interrupted_cb) { return is_interrupted_cb (); } return false; } -R_API void r_print_set_is_interrupted_cb(RPrintIsInterruptedCallback cb) { +RZ_API void rz_print_set_is_interrupted_cb(RPrintIsInterruptedCallback cb) { is_interrupted_cb = cb; } -R_API bool r_print_mute(RPrint *p, int x) { +RZ_API bool rz_print_mute(RPrint *p, int x) { if (x) { if (p->cb_printf == &nullprinter) { return false; @@ -167,7 +167,7 @@ R_API bool r_print_mute(RPrint *p, int x) { return false; } -static int r_print_stereogram_private(const char *bump, int w, int h, char *out, int size) { +static int rz_print_stereogram_private(const char *bump, int w, int h, char *out, int size) { static char data[32768]; // ??? const char *string = "Az+|.-=/^@_pT"; const int string_len = strlen (string); @@ -234,7 +234,7 @@ static int r_print_stereogram_private(const char *bump, int w, int h, char *out, return 1; } -R_API char* r_print_stereogram(const char *bump, int w, int h) { +RZ_API char* rz_print_stereogram(const char *bump, int w, int h) { if (w < 1 || h < 1) { return NULL; } @@ -247,19 +247,19 @@ R_API char* r_print_stereogram(const char *bump, int w, int h) { return NULL; } //eprintf ("%s\n", bump); - (void) r_print_stereogram_private (bump, w, h, out, size); + (void) rz_print_stereogram_private (bump, w, h, out, size); return out; } #define STEREOGRAM_IN_COLOR 1 -R_API char* r_print_stereogram_bytes(const ut8 *buf, int len) { +RZ_API char* rz_print_stereogram_bytes(const ut8 *buf, int len) { int i, bumpi; char *ret; int scr_width = 80; if (!buf || len < 1) { return NULL; } - //scr_width = r_cons_get_size (NULL) -10; + //scr_width = rz_cons_get_size (NULL) -10; int cols = scr_width; int rows = len / cols; @@ -276,12 +276,12 @@ R_API char* r_print_stereogram_bytes(const ut8 *buf, int len) { bump[bumpi++] = '0' + v; } bump[bumpi] = 0; - ret = r_print_stereogram (bump, cols, rows); + ret = rz_print_stereogram (bump, cols, rows); free (bump); return ret; } -R_API void r_print_stereogram_print(RPrint *p, const char *ret) { +RZ_API void rz_print_stereogram_print(RPrint *p, const char *ret) { int i; const int use_color = p->flags & R_PRINT_FLAGS_COLOR; if (!ret) { @@ -297,13 +297,13 @@ R_API void r_print_stereogram_print(RPrint *p, const char *ret) { } } -R_API RPrint* r_print_new(void) { +RZ_API RPrint* rz_print_new(void) { RPrint *p = R_NEW0 (RPrint); if (!p) { return NULL; } strcpy (p->datefmt, "%Y-%m-%d %H:%M:%S %z"); - r_io_bind_init (p->iob); + rz_io_bind_init (p->iob); p->pairs = true; p->resetbg = true; p->cb_printf = libc_printf; @@ -344,7 +344,7 @@ R_API RPrint* r_print_new(void) { return p; } -R_API RPrint* r_print_free(RPrint *p) { +RZ_API RPrint* rz_print_free(RPrint *p) { if (!p) { return NULL; } @@ -363,15 +363,15 @@ R_API RPrint* r_print_free(RPrint *p) { } // dummy setter can be removed -R_API void r_print_set_flags(RPrint *p, int _flags) { +RZ_API void rz_print_set_flags(RPrint *p, int _flags) { p->flags = _flags; } -R_API void r_print_unset_flags(RPrint *p, int flags) { +RZ_API void rz_print_unset_flags(RPrint *p, int flags) { p->flags = p->flags & (p->flags ^ flags); } -R_API void r_print_set_cursor(RPrint *p, int enable, int ocursor, int cursor) { +RZ_API void rz_print_set_cursor(RPrint *p, int enable, int ocursor, int cursor) { if (!p) { return; } @@ -383,14 +383,14 @@ R_API void r_print_set_cursor(RPrint *p, int enable, int ocursor, int cursor) { p->cur = cursor; } -R_API bool r_print_have_cursor(RPrint *p, int cur, int len) { +RZ_API bool rz_print_have_cursor(RPrint *p, int cur, int len) { if (!p || !p->cur_enabled) { return false; } if (p->ocur != -1) { int from = p->ocur; int to = p->cur; - r_num_minmax_swap_i (&from, &to); + rz_num_minmax_swap_i (&from, &to); do { if (cur + len - 1 >= from && cur + len - 1 <= to) { return true; @@ -402,8 +402,8 @@ R_API bool r_print_have_cursor(RPrint *p, int cur, int len) { return false; } -R_API bool r_print_cursor_pointer(RPrint *p, int cur, int len) { - r_return_val_if_fail (p, false); +RZ_API bool rz_print_cursor_pointer(RPrint *p, int cur, int len) { + rz_return_val_if_fail (p, false); if (!p->cur_enabled) { return false; } @@ -416,13 +416,13 @@ R_API bool r_print_cursor_pointer(RPrint *p, int cur, int len) { return false; } -R_API void r_print_cursor(RPrint *p, int cur, int len, int set) { - if (r_print_have_cursor (p, cur, len)) { +RZ_API void rz_print_cursor(RPrint *p, int cur, int len, int set) { + if (rz_print_have_cursor (p, cur, len)) { p->cb_printf ("%s", R_CONS_INVERT (set, 1)); } } -R_API void r_print_addr(RPrint *p, ut64 addr) { +RZ_API void rz_print_addr(RPrint *p, ut64 addr) { char space[32] = { 0 }; @@ -449,7 +449,7 @@ R_API void r_print_addr(RPrint *p, ut64 addr) { s = (addr - a) >> (p? p->seggrn: 0); if (dec) { snprintf (space, sizeof (space), "%d:%d", s & 0xffff, a & 0xffff); - white = r_str_pad (' ', 9 - strlen (space)); + white = rz_str_pad (' ', 9 - strlen (space)); } if (use_color) { const char *pre = PREOFF (offset): Color_GREEN; @@ -470,13 +470,13 @@ R_API void r_print_addr(RPrint *p, ut64 addr) { if (dec) { snprintf (space, sizeof (space), "%" PFMT64d, addr); int w = R_MAX (10 - strlen (space), 0); - white = r_str_pad (' ', w); + white = rz_str_pad (' ', w); } if (use_color) { const char *pre = PREOFF (offset): Color_GREEN; const char *fin = Color_RESET; if (p && p->flags & R_PRINT_FLAGS_RAINBOW) { - // pre = r_cons_rgb_str_off (rgbstr, addr); + // pre = rz_cons_rgb_str_off (rgbstr, addr); if (p->cons && p->cons->rgbstr) { static char rgbstr[32]; pre = p->cons->rgbstr (rgbstr, sizeof (rgbstr), addr); @@ -507,7 +507,7 @@ R_API void r_print_addr(RPrint *p, ut64 addr) { } } -R_API char* r_print_hexpair(RPrint *p, const char *str, int n) { +RZ_API char* rz_print_hexpair(RPrint *p, const char *str, int n) { const char *s, *lastcol = Color_WHITE; char *d, *dst = (char *) calloc ((strlen (str) + 2), 32); int colors = p->flags & R_PRINT_FLAGS_COLOR; @@ -518,7 +518,7 @@ R_API char* r_print_hexpair(RPrint *p, const char *str, int n) { const char *color_other = ""; int bs = p->bytespace; /* XXX That's hacky as shit.. but partially works O:) */ - /* TODO: Use r_print_set_cursor for win support */ + /* TODO: Use rz_print_set_cursor for win support */ int cur = R_MIN (p->cur, p->ocur); int ocur = R_MAX (p->cur, p->ocur); int ch, i; @@ -537,7 +537,7 @@ R_API char* r_print_hexpair(RPrint *p, const char *str, int n) { ocur++; d = dst; // XXX: overflow here -// TODO: Use r_cons primitives here +// TODO: Use rz_cons primitives here #define memcat(x, y)\ { \ memcpy (x, y, strlen (y));\ @@ -564,7 +564,7 @@ R_API char* r_print_hexpair(RPrint *p, const char *str, int n) { } else if (s[0] == 'f' && s[1] == 'f') { lastcol = color_0xff; } else { - ch = r_hex_pair2bin (s); + ch = rz_hex_pair2bin (s); if (ch == -1) { break; } @@ -599,7 +599,7 @@ R_API char* r_print_hexpair(RPrint *p, const char *str, int n) { static char colorbuffer[64]; #define P(x) (p->cons && p->cons->context->pal.x)? p->cons->context->pal.x -R_API const char *r_print_byte_color(RPrint *p, int ch) { +RZ_API const char *rz_print_byte_color(RPrint *p, int ch) { if (p->flags & R_PRINT_FLAGS_RAINBOW) { // EXPERIMENTAL int bg = (p->flags & R_PRINT_FLAGS_NONHEX)? 48: 38; @@ -619,15 +619,15 @@ R_API const char *r_print_byte_color(RPrint *p, int ch) { return NULL; } -R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) { +RZ_API void rz_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) { PrintfCallback printfmt = (PrintfCallback) (p? p->cb_printf: libc_printf); ut8 rch = ch; if (!IS_PRINTABLE (ch) && fmt[0] == '%' && fmt[1] == 'c') { rch = '.'; } - r_print_cursor (p, idx, 1, 1); + rz_print_cursor (p, idx, 1, 1); if (p && p->flags & R_PRINT_FLAGS_COLOR) { - const char *bytecolor = r_print_byte_color (p, ch); + const char *bytecolor = rz_print_byte_color (p, ch); if (bytecolor) { printfmt (bytecolor); } @@ -638,10 +638,10 @@ R_API void r_print_byte(RPrint *p, const char *fmt, int idx, ut8 ch) { } else { printfmt (fmt, rch); } - r_print_cursor (p, idx, 1, 0); + rz_print_cursor (p, idx, 1, 0); } -R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int options) { +RZ_API int rz_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int options) { int i; bool wide = (options & R_PRINT_STRING_WIDE); bool wide32 = (options & R_PRINT_STRING_WIDE32); @@ -651,7 +651,7 @@ R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int opti bool esc_nl = (options & R_PRINT_STRING_ESC_NL); int col = 0; i = 0; - for (; !r_print_is_interrupted () && i < len; i++) { + for (; !rz_print_is_interrupted () && i < len; i++) { if (wide32) { int j = i; while (buf[j] == '\0' && j < (i + 3)) { @@ -662,7 +662,7 @@ R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int opti if (zeroend && buf[i] == '\0') { break; } - r_print_cursor (p, i, 1, 1); + rz_print_cursor (p, i, 1, 1); ut8 b = buf[i]; if (b == '\n') { col = 0; @@ -680,7 +680,7 @@ R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int opti p->cb_printf ("\\x%02x", b); } } - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); if (wrap && col + 1 >= p->width) { p->cb_printf ("\n"); col = 0; @@ -693,7 +693,7 @@ R_API int r_print_string(RPrint *p, ut64 seek, const ut8 *buf, int len, int opti return i; } -R_API void r_print_hexpairs(RPrint *p, ut64 addr, const ut8 *buf, int len) { +RZ_API void rz_print_hexpairs(RPrint *p, ut64 addr, const ut8 *buf, int len) { int i; for (i = 0; i < len; i++) { p->cb_printf ("%02x ", buf[i]); @@ -725,7 +725,7 @@ static bool isAllZeros(const ut8 *buf, int len) { } #define Pal(x,y) (x->cons && x->cons->context->pal.y)? x->cons->context->pal.y -R_API void r_print_hexii(RPrint *rp, ut64 addr, const ut8 *buf, int len, int step) { +RZ_API void rz_print_hexii(RPrint *rp, ut64 addr, const ut8 *buf, int len, int step) { PrintfCallback p = (PrintfCallback) rp->cb_printf; bool c = rp->flags & R_PRINT_FLAGS_COLOR; const char *color_0xff = c? (Pal (rp, b0xff): Color_RED): ""; @@ -770,10 +770,10 @@ R_API void r_print_hexii(RPrint *rp, ut64 addr, const ut8 *buf, int len, int ste /* set screen_bounds to addr if the cursor is not visible on the screen anymore. * Note: screen_bounds is set only the first time this happens. */ -R_API void r_print_set_screenbounds(RPrint *p, ut64 addr) { +RZ_API void rz_print_set_screenbounds(RPrint *p, ut64 addr) { int r, rc; - r_return_if_fail (p); + rz_return_if_fail (p); if (!p->screen_bounds) { return; @@ -795,20 +795,20 @@ R_API void r_print_set_screenbounds(RPrint *p, ut64 addr) { } } -R_API void r_print_section(RPrint *p, ut64 at) { +RZ_API void rz_print_section(RPrint *p, ut64 at) { bool use_section = p && p->flags & R_PRINT_FLAGS_SECTION; if (use_section) { const char *s = p->get_section_name (p->user, at); if (!s) { s = ""; } - char *tail = r_str_ndup (s, 19); + char *tail = rz_str_ndup (s, 19); p->cb_printf ("%20s ", tail); free (tail); } } -R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step, size_t zoomsz) { +RZ_API void rz_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int base, int step, size_t zoomsz) { PrintfCallback printfmt = (PrintfCallback)printf; bool c = p? (p->flags & R_PRINT_FLAGS_COLOR): false; const char *color_title = c? (Pal (p, offset): Color_MAGENTA): ""; @@ -915,7 +915,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } if (base < 32) { ut32 opad = (ut32) (addr >> 32); - { // XXX: use r_print_addr_header + { // XXX: use rz_print_addr_header int i, delta; char soff[32]; if (hex_style) { @@ -1011,7 +1011,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } // is this necessary? - r_print_set_screenbounds (p, addr); + rz_print_set_screenbounds (p, addr); int rows = 0; int bytes = 0; bool printValue = true; @@ -1052,8 +1052,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } ut64 at = addr + (j * zoomsz); if (use_offset && !isPxr) { - r_print_section (p, at); - r_print_addr (p, at); + rz_print_section (p, at); + rz_print_addr (p, at); } int row_have_cursor = -1; ut64 row_have_addr = UT64_MAX; @@ -1069,7 +1069,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } } if (row_have_cursor == -1) { - if (r_print_cursor_pointer (p, j, 1)) { + if (rz_print_cursor_pointer (p, j, 1)) { row_have_cursor = j - i; row_have_addr = addr + j; } @@ -1110,8 +1110,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba j += sz_n; continue; } - r_mem_swaporcopy ((ut8 *) &n, buf + j, sz_n, p && p->big_endian); - r_print_cursor (p, j, sz_n, 1); + rz_mem_swaporcopy ((ut8 *) &n, buf + j, sz_n, p && p->big_endian); + rz_print_cursor (p, j, sz_n, 1); // stub for colors if (p && p->colorfor) { if (!p->iob.addr_is_mapped (p->iob.io, addr + j)) { @@ -1139,8 +1139,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } if (printValue) { if (use_offset && !hasNull && isPxr) { - r_print_section (p, at); - r_print_addr (p, addr + j * zoomsz); + rz_print_section (p, at); + rz_print_addr (p, addr + j * zoomsz); } if (base == 64) { printfmt ("%s0x%016" PFMT64x "%s ", a, (ut64) n, b); @@ -1152,39 +1152,39 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } else { if (hasNull) { const char *n = p->offname (p->user, addr + j); - r_print_section (p, at); - r_print_addr (p, addr + j * zoomsz); + rz_print_section (p, at); + rz_print_addr (p, addr + j * zoomsz); printfmt ("..[ null bytes ].. 00000000 %s\n", n? n: ""); } } - r_print_cursor (p, j, sz_n, 0); + rz_print_cursor (p, j, sz_n, 0); oPrintValue = printValue; j += step - 1; } else if (base == -8) { - long long w = r_read_ble64 (buf + j, p && p->big_endian); - r_print_cursor (p, j, 8, 1); + long long w = rz_read_ble64 (buf + j, p && p->big_endian); + rz_print_cursor (p, j, 8, 1); printfmt ("%23" PFMT64d " ", w); - r_print_cursor (p, j, 8, 0); + rz_print_cursor (p, j, 8, 0); j += 7; } else if (base == -1) { - st8 w = r_read_ble8 (buf + j); - r_print_cursor (p, j, 1, 1); + st8 w = rz_read_ble8 (buf + j); + rz_print_cursor (p, j, 1, 1); printfmt ("%4d ", w); - r_print_cursor (p, j, 1, 0); + rz_print_cursor (p, j, 1, 0); } else if (base == -10) { if (j + 1 < len) { - st16 w = r_read_ble16 (buf + j, p && p->big_endian); - r_print_cursor (p, j, 2, 1); + st16 w = rz_read_ble16 (buf + j, p && p->big_endian); + rz_print_cursor (p, j, 2, 1); printfmt ("%7d ", w); - r_print_cursor (p, j, 2, 0); + rz_print_cursor (p, j, 2, 0); } j += 1; } else if (base == 10) { // "pxd" if (j + 3 < len) { - int w = r_read_ble32 (buf + j, p && p->big_endian); - r_print_cursor (p, j, 4, 1); + int w = rz_read_ble32 (buf + j, p && p->big_endian); + rz_print_cursor (p, j, 4, 1); printfmt ("%13d ", w); - r_print_cursor (p, j, 4, 0); + rz_print_cursor (p, j, 4, 0); } j += 3; } else { @@ -1196,7 +1196,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba char dbl_ch_str[] = { ch, ch, 0 }; p->cb_printf (dbl_ch_str); } else { - r_print_byte (p, bytefmt, j, buf[j]); + rz_print_byte (p, bytefmt, j, buf[j]); } if (pairs && !compact && (inc & 1)) { bool mustspace = (rows % 2) ? !(j&1) : (j&1); @@ -1252,7 +1252,7 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } ut8 ch = (use_unalloc && p && !p->iob.is_valid_offset (p->iob.io, addr + j, false)) ? ' ' : buf[j]; - r_print_byte (p, "%c", j, ch); + rz_print_byte (p, "%c", j, ch); bytes++; } } @@ -1346,8 +1346,8 @@ R_API void r_print_hexdump(RPrint *p, ut64 addr, const ut8 *buf, int len, int ba } } -R_API void r_print_hexdump_simple(const ut8 *buf, int len) { - r_print_hexdump (NULL, 0, buf, len, 16, 16, 0); +RZ_API void rz_print_hexdump_simple(const ut8 *buf, int len) { + rz_print_hexdump (NULL, 0, buf, len, 16, 16, 0); } static const char* getbytediff(RPrint *p, char *fmt, ut8 a, ut8 b) { @@ -1391,7 +1391,7 @@ static ut8* M(const ut8 *b, int len) { } // TODO: add support for cursor -R_API void r_print_hexdiff(RPrint *p, ut64 aa, const ut8 *_a, ut64 ba, const ut8 *_b, int len, int scndcol) { +RZ_API void rz_print_hexdiff(RPrint *p, ut64 aa, const ut8 *_a, ut64 ba, const ut8 *_b, int len, int scndcol) { ut8 *a, *b; char linediff, fmt[64]; int color = p->flags & R_PRINT_FLAGS_COLOR; @@ -1413,31 +1413,31 @@ R_API void r_print_hexdiff(RPrint *p, ut64 aa, const ut8 *_a, ut64 ba, const ut8 p->cb_printf ("0x%08" PFMT64x " ", aa + i); for (j = 0; j < min; j++) { *fmt = color; - r_print_cursor (p, i + j, 1, 1); + rz_print_cursor (p, i + j, 1, 1); p->cb_printf (BD (a, b)); - r_print_cursor (p, i + j, 1, 0); + rz_print_cursor (p, i + j, 1, 0); } p->cb_printf (" "); for (j = 0; j < min; j++) { *fmt = color; - r_print_cursor (p, i + j, 1, 1); + rz_print_cursor (p, i + j, 1, 1); p->cb_printf ("%s", CD (a, b)); - r_print_cursor (p, i + j, 1, 0); + rz_print_cursor (p, i + j, 1, 0); } if (scndcol) { p->cb_printf (" %c 0x%08" PFMT64x " ", linediff, ba + i); for (j = 0; j < min; j++) { *fmt = color; - r_print_cursor (p, i + j, 1, 1); + rz_print_cursor (p, i + j, 1, 1); p->cb_printf (BD (b, a)); - r_print_cursor (p, i + j, 1, 0); + rz_print_cursor (p, i + j, 1, 0); } p->cb_printf (" "); for (j = 0; j < min; j++) { *fmt = color; - r_print_cursor (p, i + j, 1, 1); + rz_print_cursor (p, i + j, 1, 1); p->cb_printf ("%s", CD (b, a)); - r_print_cursor (p, i + j, 1, 0); + rz_print_cursor (p, i + j, 1, 0); } p->cb_printf ("\n"); } else { @@ -1448,7 +1448,7 @@ R_API void r_print_hexdiff(RPrint *p, ut64 aa, const ut8 *_a, ut64 ba, const ut8 free (b); } -R_API void r_print_bytes(RPrint *p, const ut8 *buf, int len, const char *fmt) { +RZ_API void rz_print_bytes(RPrint *p, const ut8 *buf, int len, const char *fmt) { int i; if (p) { for (i = 0; i < len; i++) { @@ -1463,7 +1463,7 @@ R_API void r_print_bytes(RPrint *p, const ut8 *buf, int len, const char *fmt) { } } -R_API void r_print_raw(RPrint *p, ut64 addr, const ut8 *buf, int len, int offlines) { +RZ_API void rz_print_raw(RPrint *p, ut64 addr, const ut8 *buf, int len, int offlines) { if (offlines == 2) { int i, j, cols = p->cols * 4; char ch; @@ -1475,9 +1475,9 @@ R_API void r_print_raw(RPrint *p, ut64 addr, const ut8 *buf, int len, int offlin } ch = buf[i + j]; if (p->cur_enabled) { - r_print_cursor (p, i + j, 1, 1); + rz_print_cursor (p, i + j, 1, 1); p->cb_printf ("%c", IS_PRINTABLE (ch)? ch: ' '); - r_print_cursor (p, i + j, 1, 0); + rz_print_cursor (p, i + j, 1, 0); } else { p->cb_printf ("%c", IS_PRINTABLE (ch)? ch: ' '); } @@ -1492,7 +1492,7 @@ R_API void r_print_raw(RPrint *p, ut64 addr, const ut8 *buf, int len, int offlin i = 0; do { off = addr + (int) (size_t) (q - buf); - linenum_abs = r_util_lines_getline (p->lines_cache, p->lines_cache_sz, off); + linenum_abs = rz_util_lines_getline (p->lines_cache, p->lines_cache_sz, off); if (p->lines_cache_sz > 0 && p->lines_abs) { p->cb_printf ("%d 0x%08" PFMT64x " ", linenum_abs, off); } else { @@ -1517,13 +1517,13 @@ R_API void r_print_raw(RPrint *p, ut64 addr, const ut8 *buf, int len, int offlin } } -R_API void r_print_c(RPrint *p, const ut8 *str, int len) { +RZ_API void rz_print_c(RPrint *p, const ut8 *str, int len) { int i, inc = p->width / 6; p->cb_printf ("#define _BUFFER_SIZE %d\n" "unsigned char buffer[_BUFFER_SIZE] = {\n", len); - for (i = 0; !r_print_is_interrupted () && i < len;) { - r_print_byte (p, "0x%02x", i, str[i]); + for (i = 0; !rz_print_is_interrupted () && i < len;) { + rz_print_byte (p, "0x%02x", i, str[i]); if (++i < len) { p->cb_printf (", "); } @@ -1540,7 +1540,7 @@ static RPrint staticp = { }; /* TODO: handle screen width */ -R_API void r_print_progressbar(RPrint *p, int pc, int _cols) { +RZ_API void rz_print_progressbar(RPrint *p, int pc, int _cols) { // TODO: add support for colors int i, cols = (_cols == -1)? 78: _cols; if (!p) { @@ -1564,7 +1564,7 @@ R_API void r_print_progressbar(RPrint *p, int pc, int _cols) { p->cb_printf ("]"); } -R_API void r_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 max, int cols) { +RZ_API void rz_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 max, int cols) { const char *h_line = p->cons->use_utf8 ? RUNE_LONG_LINE_HORIZ : "-"; const char *block = p->cons->use_utf8 ? UTF_BLOCK : "#"; const bool show_colors = p->flags & R_PRINT_FLAGS_COLOR; @@ -1594,7 +1594,7 @@ R_API void r_print_rangebar(RPrint *p, ut64 startA, ut64 endA, ut64 min, ut64 ma p->cb_printf ("|"); } -R_API void r_print_zoom_buf(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen) { +RZ_API void rz_print_zoom_buf(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen) { static int mode = -1; ut8 *bufz = NULL, *bufz2 = NULL; int i, j = 0; @@ -1649,17 +1649,17 @@ R_API void r_print_zoom_buf(RPrint *p, void *user, RPrintZoomCallback cb, ut64 f } } -R_API void r_print_zoom(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen) { +RZ_API void rz_print_zoom(RPrint *p, void *user, RPrintZoomCallback cb, ut64 from, ut64 to, int len, int maxlen) { ut64 size = (to - from); - r_print_zoom_buf (p, user, cb, from, to, len, maxlen); + rz_print_zoom_buf (p, user, cb, from, to, len, maxlen); size = len? size / len: 0; p->flags &= ~R_PRINT_FLAGS_HEADER; - r_print_hexdump (p, from, p->zoom->buf, p->zoom->size, 16, 1, size); + rz_print_hexdump (p, from, p->zoom->buf, p->zoom->size, 16, 1, size); p->flags |= R_PRINT_FLAGS_HEADER; } static inline void printHistBlock (RPrint *p, int k, int cols) { - RConsPrintablePalette *pal = &p->cons->context->pal; + RzConsPrintablePalette *pal = &p->cons->context->pal; const char *h_line = p->cons->use_utf8 ? RUNE_LONG_LINE_HORIZ : "-"; const char *block = p->cons->use_utf8 ? UTF_BLOCK : "#"; const char *kol[5]; @@ -1689,8 +1689,8 @@ static inline void printHistBlock (RPrint *p, int k, int cols) { } } -R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step) { - r_return_if_fail (p && arr); +RZ_API void rz_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step) { + rz_return_if_fail (p && arr); const bool show_colors = (p && (p->flags & R_PRINT_FLAGS_COLOR)); const bool show_offset = (p && (p->flags & R_PRINT_FLAGS_OFFSET)); bool useUtf8 = p->cons->use_utf8; @@ -1777,7 +1777,7 @@ R_API void r_print_fill(RPrint *p, const ut8 *arr, int size, ut64 addr, int step } } -R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) { +RZ_API void rz_print_2bpp_row(RPrint *p, ut8 *buf) { const bool useColor = p? (p->flags & R_PRINT_FLAGS_COLOR): false; int i, c = 0; for (i = 0; i < 8; i++) { @@ -1821,12 +1821,12 @@ R_API void r_print_2bpp_row(RPrint *p, ut8 *buf) { } } -R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles) { +RZ_API void rz_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles) { int i, r; const bool useColor = p? (p->flags & R_PRINT_FLAGS_COLOR): false; for (i = 0; i < 8; i++) { for (r = 0; r < tiles; r++) { - r_print_2bpp_row (p, buf + 2 * i + r * 16); + rz_print_2bpp_row (p, buf + 2 * i + r * 16); } if (p) { if (useColor) { @@ -1841,8 +1841,8 @@ R_API void r_print_2bpp_tiles(RPrint *p, ut8 *buf, ut32 tiles) { } // probably move somewhere else. RPrint doesnt needs to know about the R_ANAL_ enums -R_API const char* r_print_color_op_type(RPrint *p, ut32 anal_type) { - RConsPrintablePalette *pal = &p->cons->context->pal; +RZ_API const char* rz_print_color_op_type(RPrint *p, ut32 anal_type) { + RzConsPrintablePalette *pal = &p->cons->context->pal; switch (anal_type & R_ANAL_OP_TYPE_MASK) { case R_ANAL_OP_TYPE_NOP: return pal->nop; @@ -1969,7 +1969,7 @@ static bool ishexprefix(char *p) { return (p[0] == '0' && p[1] == 'x'); } -R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr) { +RZ_API char* rz_print_colorize_opcode(RPrint *print, char *p, const char *reg, const char *num, bool partial_reset, ut64 func_addr) { int i, j, k, is_mod, is_float = 0, is_arg = 0; char *reset = partial_reset ? Color_RESET_NOBG : Color_RESET; ut32 c_reset = strlen (reset); @@ -1984,7 +1984,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con if (is_jmp) { return strdup (p); } - r_str_trim (p); + rz_str_trim (p); if (opcode_sz > COLORIZE_BUFSIZE) { /* return same string in case of error */ return strdup (p); @@ -1996,7 +1996,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con if ((ishexprefix (&p[i]) && previous != ':') \ || (isdigit ((ut8)p[i]) && issymbol (previous))) { const char *num2 = num; - ut64 n = r_num_get (NULL, p + i); + ut64 n = rz_num_get (NULL, p + i); const char *name = print->offname (print->user, n)? color_flag: NULL; if (name) { num2 = name; @@ -2011,7 +2011,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con } previous = p[i]; if (j + 100 >= COLORIZE_BUFSIZE) { - eprintf ("r_print_colorize_opcode(): buffer overflow!\n"); + eprintf ("rz_print_colorize_opcode(): buffer overflow!\n"); return strdup (p); } switch (p[i]) { @@ -2051,7 +2051,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con is_float = 0; } else if (is_arg) { if (c_reset + j + 10 >= COLORIZE_BUFSIZE) { - eprintf ("r_print_colorize_opcode(): buffer overflow!\n"); + eprintf ("rz_print_colorize_opcode(): buffer overflow!\n"); return strdup (p); } @@ -2063,7 +2063,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con const char *color = found_var ? print->cons->context->pal.func_var_type : reg; ut32 color_len = strlen (color); if (color_len + j + 10 >= COLORIZE_BUFSIZE) { - eprintf ("r_print_colorize_opcode(): buffer overflow!\n"); + eprintf ("rz_print_colorize_opcode(): buffer overflow!\n"); return strdup (p); } strcpy (o + j + 1, color); @@ -2102,7 +2102,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con ut32 reg_len = strlen (reg); /* if (reg_len+j+10 >= opcode_sz) o = realloc_color_buffer (o, &opcode_sz, reg_len+100); */ if (reg_len + j + 10 >= COLORIZE_BUFSIZE) { - eprintf ("r_print_colorize_opcode(): buffer overflow!\n"); + eprintf ("rz_print_colorize_opcode(): buffer overflow!\n"); return strdup (p); } strcpy (o + j, reg); @@ -2112,7 +2112,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con case '0': /* address */ if (p[i + 1] == 'x') { if (print->flags & R_PRINT_FLAGS_SECSUB) { - RIOMap *map = print->iob.map_get (print->iob.io, r_num_get (NULL, p + i)); + RzIOMap *map = print->iob.map_get (print->iob.io, rz_num_get (NULL, p + i)); if (map && map->name) { if (strlen (map->name) + j + 1 >= COLORIZE_BUFSIZE) { eprintf ("stop before overflow\n"); @@ -2142,7 +2142,7 @@ R_API char* r_print_colorize_opcode(RPrint *print, char *p, const char *reg, con } // reset the status of row_offsets -R_API void r_print_init_rowoffsets(RPrint *p) { +RZ_API void rz_print_init_rowoffsets(RPrint *p) { if (p->calc_row_offsets) { R_FREE (p->row_offsets); p->row_offsets_sz = 0; @@ -2150,7 +2150,7 @@ R_API void r_print_init_rowoffsets(RPrint *p) { } // set the offset, from the start of the printing, of the i-th row -R_API void r_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite) { +RZ_API void rz_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite) { if (!overwrite) { return; } @@ -2176,7 +2176,7 @@ R_API void r_print_set_rowoff(RPrint *p, int i, ut32 offset, bool overwrite) { // return the offset, from the start of the printing, of the i-th row. // if the line index is not valid, UT32_MAX is returned. -R_API ut32 r_print_rowoff(RPrint *p, int i) { +RZ_API ut32 rz_print_rowoff(RPrint *p, int i) { if (i < 0 || i >= p->row_offsets_sz) { return UT32_MAX; } @@ -2185,20 +2185,20 @@ R_API ut32 r_print_rowoff(RPrint *p, int i) { // return the index of the row that contains the given offset or -1 if // that row doesn't exist. -R_API int r_print_row_at_off(RPrint *p, ut32 offset) { +RZ_API int rz_print_row_at_off(RPrint *p, ut32 offset) { int i = 0; ut32 tt; - while ((tt = r_print_rowoff (p, i)) != UT32_MAX && tt <= offset) { + while ((tt = rz_print_rowoff (p, i)) != UT32_MAX && tt <= offset) { i++; } return tt != UT32_MAX? i - 1: -1; } -R_API int r_print_get_cursor(RPrint *p) { +RZ_API int rz_print_get_cursor(RPrint *p) { return p->cur_enabled? p->cur: 0; } -R_API int r_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize) { +RZ_API int rz_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize) { ut16 *buf16 = (ut16*) buf; ut32 *buf32 = (ut32*) buf; ut64 *buf64 = (ut64*) buf; @@ -2219,17 +2219,17 @@ R_API int r_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize) { break; } case 16: { - ut16 w16 = r_read_ble16 (&buf16[i], p->big_endian); + ut16 w16 = rz_read_ble16 (&buf16[i], p->big_endian); p->cb_printf ("%s%hd", i ? "," : "", w16); break; } case 32: { - ut32 w32 = r_read_ble32 (&buf32[i], p->big_endian); + ut32 w32 = rz_read_ble32 (&buf32[i], p->big_endian); p->cb_printf ("%s%d", i ? "," : "", w32); break; } case 64: { - ut64 w64 = r_read_ble64 (&buf64[i], p->big_endian); + ut64 w64 = rz_read_ble64 (&buf64[i], p->big_endian); p->cb_printf ("%s%"PFMT64d, i ? "," : "", w64); break; } @@ -2239,7 +2239,7 @@ R_API int r_print_jsondump(RPrint *p, const ut8 *buf, int len, int wordsize) { return words; } -R_API void r_print_hex_from_bin (RPrint *p, char *bin_str) { +RZ_API void rz_print_hex_from_bin (RPrint *p, char *bin_str) { int i, j, index; RPrint myp = {.cb_printf = libc_printf}; const int len = strlen (bin_str); @@ -2275,10 +2275,10 @@ R_API void r_print_hex_from_bin (RPrint *p, char *bin_str) { free (buf); } -R_API const char* r_print_rowlog(RPrint *print, const char *str) { +RZ_API const char* rz_print_rowlog(RPrint *print, const char *str) { int use_color = print->flags & R_PRINT_FLAGS_COLOR; bool verbose = print->scr_prompt; - r_return_val_if_fail (print->cb_eprintf, NULL); + rz_return_val_if_fail (print->cb_eprintf, NULL); if (!verbose) { return NULL; } @@ -2290,10 +2290,10 @@ R_API const char* r_print_rowlog(RPrint *print, const char *str) { return str; } -R_API void r_print_rowlog_done(RPrint *print, const char *str) { +RZ_API void rz_print_rowlog_done(RPrint *print, const char *str) { int use_color = print->flags & R_PRINT_FLAGS_COLOR; bool verbose = print->scr_prompt; - r_return_if_fail (print->cb_eprintf); + rz_return_if_fail (print->cb_eprintf); if (verbose) { if (use_color) { print->cb_eprintf ("\r"Color_GREEN"[x]"Color_RESET" %s\n", str); diff --git a/libr/util/print_code.c b/librz/util/print_code.c similarity index 73% rename from libr/util/print_code.c rename to librz/util/print_code.c index 26e0b3554a..d56bd2c568 100644 --- a/libr/util/print_code.c +++ b/librz/util/print_code.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include -#include +#include +#include static const char* bits_to_c_code_fmtstr(int bits) { switch (bits) { @@ -31,7 +31,7 @@ static void print_c_instructions(RPrint *p, ut64 addr, const ut8 *buf, int len) const int orig_align = p->coreb.cfggeti (p->coreb.core, "asm.cmt.col") - 40; size_t k, i = 0; - while (!r_print_is_interrupted () && i < len) { + while (!rz_print_is_interrupted () && i < len) { ut64 at = addr + i; int inst_size = get_instruction_size (p, at); if (inst_size <= 0) { @@ -42,9 +42,9 @@ static void print_c_instructions(RPrint *p, ut64 addr, const ut8 *buf, int len) p->cb_printf (" "); size_t limit = R_MIN (i + inst_size, len); for (k = i; k < limit; k++) { - r_print_cursor (p, k, 1, true); - p->cb_printf (fmtstr, r_read_ble (buf++, p->big_endian, 8)); - r_print_cursor (p, k, 1, false); + rz_print_cursor (p, k, 1, true); + p->cb_printf (fmtstr, rz_read_ble (buf++, p->big_endian, 8)); + rz_print_cursor (p, k, 1, false); p->cb_printf (", "); } size_t j = k - i; @@ -53,7 +53,7 @@ static void print_c_instructions(RPrint *p, ut64 addr, const ut8 *buf, int len) if (j == inst_size) { char *instr = p->coreb.cmdstrf (p->coreb.core, "pi 1 @ 0x%08" PFMT64x, at); - r_str_trim (instr); + rz_str_trim (instr); p->cb_printf (" /* %s */\n", instr); free (instr); } else { @@ -75,12 +75,12 @@ static void print_c_code(RPrint *p, ut64 addr, const ut8 *buf, int len, int ws, p->cb_printf ("#define _BUFFER_SIZE %d\n", len); p->cb_printf ("const uint%d_t buffer[_BUFFER_SIZE] = {", bits); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { if (!(i % w)) { p->cb_printf ("\n "); } - r_print_cursor (p, i, 1, 1); - p->cb_printf (fmtstr, r_read_ble (buf, p->big_endian, bits)); + rz_print_cursor (p, i, 1, 1); + p->cb_printf (fmtstr, rz_read_ble (buf, p->big_endian, bits)); if ((i + 1) < len) { p->cb_printf (","); @@ -88,13 +88,13 @@ static void print_c_code(RPrint *p, ut64 addr, const ut8 *buf, int len, int ws, p->cb_printf (" "); } } - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); buf += ws; } p->cb_printf ("\n};\n"); } -R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang) { +RZ_API void rz_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang) { int i, w = (int)(p->cols * 0.7); if (w < 1) { w = 1; @@ -102,7 +102,7 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang switch (lang) { case '*': p->cb_printf ("wx "); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { if (i && !(i % 16)) { p->cb_printf (";s+16\nwx "); } @@ -120,7 +120,7 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang break; case 'a': // "pca" p->cb_printf ("shellcode:"); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { if (!(i % 8)) { p->cb_printf ("\n.byte "); } else { @@ -132,7 +132,7 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang break; case 's': // "pcs" p->cb_printf ("\""); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { p->cb_printf ("\\x%02x", buf[i]); } p->cb_printf ("\"\n"); @@ -140,7 +140,7 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang case 'S': // "pcS" { const int trunksize = 16; - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { if (!(i % trunksize)) { p->cb_printf ("printf \""); } @@ -157,63 +157,63 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang char *out = malloc (len * 3); p->cb_printf ("var buffer = new Buffer(\""); out[0] = 0; - r_base64_encode (out, buf, len); + rz_base64_encode (out, buf, len); p->cb_printf ("%s", out); p->cb_printf ("\", 'base64');\n"); free (out); } break; case 'k': // "pck" kotlin p->cb_printf ("val arr = byteArrayOfInts("); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("0x%x%s", buf[i], (i + 1 < len)? ",": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf (")\n"); break; case 'z': // "pcz" // swift p->cb_printf ("let byteArray : [UInt8] = ["); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("0x%x%s", buf[i], (i + 1 < len)? ", ": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("]\n"); break; case 'r': // "pcr" // Rust p->cb_printf ("let _: [u8; %d] = [\n", len); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("0x%x%s", buf[i], (i + 1 < len)? ",": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("];\n"); break; case 'o': // "pco" // Objective-C p->cb_printf ("NSData *endMarker = [[NSData alloc] initWithBytes:{\n"); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("0x%x%s", buf[i], (i + 1 < len)? ",": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("}];\n"); break; case 'v': // "pcv" // JaVa p->cb_printf ("byte[] ba = {"); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("%d%s", buf[i], (i + 1 < len)? ",": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("};\n"); break; case 'V': // "pcV" // vlang.io p->cb_printf ("data := [ byte(%d),\n ", buf[0]); - for (i = 1; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 1; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("%d%s", buf[i], (i + 1 < len)? ", ": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); if ((i %10) == 0) { p->cb_printf ("\n "); } @@ -222,32 +222,32 @@ R_API void r_print_code(RPrint *p, ut64 addr, const ut8 *buf, int len, char lang break; case 'y': // "pcy" p->cb_printf ("$hex_%"PFMT64x" = {"); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf (" %02x", buf[i] & 0xff); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf (" }\n"); break; case 'j': // "pcj" p->cb_printf ("["); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { - r_print_cursor (p, i, 1, 1); + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { + rz_print_cursor (p, i, 1, 1); p->cb_printf ("%d%s", buf[i], (i + 1 < len)? ",": ""); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("]\n"); break; case 'P': case 'p': // "pcp" "pcP" p->cb_printf ("import struct\nbuf = struct.pack (\"%dB\", *[", len); - for (i = 0; !r_print_is_interrupted () && i < len; i++) { + for (i = 0; !rz_print_is_interrupted () && i < len; i++) { if (!(i % w)) { p->cb_printf ("\n"); } - r_print_cursor (p, i, 1, 1); + rz_print_cursor (p, i, 1, 1); p->cb_printf ("0x%02x%s", buf[i], (i + 1 < len)? ",": "])"); - r_print_cursor (p, i, 1, 0); + rz_print_cursor (p, i, 1, 0); } p->cb_printf ("\n"); break; diff --git a/libr/util/prof.c b/librz/util/prof.c similarity index 91% rename from libr/util/prof.c rename to librz/util/prof.c index 3095217648..421eb48f0c 100644 --- a/libr/util/prof.c +++ b/librz/util/prof.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2019 - pancake */ -#include "r_util.h" +#include "rz_util.h" typedef struct timeval tv; @@ -27,13 +27,13 @@ static int timeval_subtract(tv *result, tv *end, tv *begin) { return end->tv_sec < begin->tv_sec; } -R_API void r_prof_start(struct r_prof_t *p) { +RZ_API void rz_prof_start(struct rz_prof_t *p) { tv *begin = &p->begin; p->result = 0.0; gettimeofday(begin, NULL); } -R_API double r_prof_end(struct r_prof_t *p) { +RZ_API double rz_prof_end(struct rz_prof_t *p) { tv end, diff, *begin = &p->begin; int sign; gettimeofday (&end, NULL); diff --git a/libr/util/protobuf.c b/librz/util/protobuf.c similarity index 77% rename from libr/util/protobuf.c rename to librz/util/protobuf.c index e20edd282b..d58688ad03 100644 --- a/libr/util/protobuf.c +++ b/librz/util/protobuf.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2017-2019 - wargio */ +/* rizin - LGPL - Copyright 2017-2019 - wargio */ -#include -#include +#include +#include typedef float ft32; typedef double ft64; @@ -35,7 +35,7 @@ static const char* s_wire(const ut8 byte) { static void pad(RStrBuf *sb, ut32 count) { ut32 i; for (i = 0; i < count; i++) { - r_strbuf_appendf (sb, " "); + rz_strbuf_appendf (sb, " "); } } @@ -52,10 +52,10 @@ static bool is_string(const ut8* start, const ut8* end) { static void decode_array(RStrBuf *sb, const ut8* start, const ut8* end) { while (start < end) { - r_strbuf_appendf (sb, "%02x ", *start); + rz_strbuf_appendf (sb, "%02x ", *start); start++; } - r_strbuf_appendf (sb, "\n"); + rz_strbuf_appendf (sb, "\n"); } static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 padcnt, bool debug) { @@ -81,9 +81,9 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa if (wire != WIRE_END_GRP) { pad (sb, padcnt); if (debug) { - r_strbuf_appendf (sb, "%u %-13s", number, s_wire(wire)); + rz_strbuf_appendf (sb, "%u %-13s", number, s_wire(wire)); } else { - r_strbuf_appendf (sb, "%u", number); + rz_strbuf_appendf (sb, "%u", number); } } switch (wire) { @@ -91,7 +91,7 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa { st64* i = (st64*) &var64; bytes_read = read_u64_leb128 (buffer, end, &var64); - r_strbuf_appendf (sb, ": %"PFMT64u" | %"PFMT64d"\n", var64, *i); + rz_strbuf_appendf (sb, ": %"PFMT64u" | %"PFMT64d"\n", var64, *i); } break; case WIRE_64_BIT: @@ -99,7 +99,7 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa ft64* f = (ft64*) &var64; st64* i = (st64*) &var64; bytes_read = read_u64_leb128 (buffer, end, &var64); - r_strbuf_appendf (sb, ": %"PFMT64u" | %"PFMT64d" | %f\n", var64, *i, *f); + rz_strbuf_appendf (sb, ": %"PFMT64u" | %"PFMT64d" | %f\n", var64, *i, *f); } break; case WIRE_LEN_DELIM: @@ -109,12 +109,12 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa const ut8* pe = ps + var64; if (ps > buffer && pe <= end) { if (is_string (ps, pe)) { - r_strbuf_appendf (sb, ": \"%.*s\"\n", (int)var64, (const char*) ps); + rz_strbuf_appendf (sb, ": \"%.*s\"\n", (int)var64, (const char*) ps); } else { - r_strbuf_appendf (sb, " {\n"); + rz_strbuf_appendf (sb, " {\n"); decode_buffer (sb, ps, pe, padcnt + 1, debug); pad (sb, padcnt); - r_strbuf_appendf (sb, "}\n"); + rz_strbuf_appendf (sb, "}\n"); } bytes_read += var64; } else { @@ -124,7 +124,7 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa } break; case WIRE_START_GRP: - r_strbuf_appendf (sb, " {\n"); + rz_strbuf_appendf (sb, " {\n"); padcnt++; break; case WIRE_END_GRP: @@ -132,14 +132,14 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa padcnt--; } pad (sb, padcnt); - r_strbuf_appendf (sb, "}\n"); + rz_strbuf_appendf (sb, "}\n"); break; case WIRE_32_BIT: { ft32* f = (ft32*) &var32; st32* i = (st32*) &var32; bytes_read = read_u32_leb128 (buffer, end, &var32); - r_strbuf_appendf (sb, ": %u | %d | %f\n", var32, *i, *f); + rz_strbuf_appendf (sb, ": %u | %d | %f\n", var32, *i, *f); } break; default: @@ -150,13 +150,13 @@ static void decode_buffer(RStrBuf *sb, const ut8* start, const ut8* end, ut32 pa } } -R_API char *r_protobuf_decode(const ut8* start, const ut64 size, bool debug) { +RZ_API char *rz_protobuf_decode(const ut8* start, const ut64 size, bool debug) { if (!start || !size) { eprintf ("Invalid buffer pointer or size.\n"); return NULL; } const ut8* end = start + size; - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); decode_buffer (sb, start, end, 0u, debug); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } diff --git a/libr/util/punycode.c b/librz/util/punycode.c similarity index 96% rename from libr/util/punycode.c rename to librz/util/punycode.c index 26ece8363e..69060edf35 100644 --- a/libr/util/punycode.c +++ b/librz/util/punycode.c @@ -1,7 +1,7 @@ /* Rakholiya Jenish - 2017 */ -#include -#include +#include +#include #define BASE 36 #define TMIN 1 @@ -177,7 +177,7 @@ static ut32 decode_digit(ut32 v) { return UT32_MAX; } -R_API char *r_punycode_encode(const ut8 *src, int srclen, int *dstlen) { +RZ_API char *rz_punycode_encode(const ut8 *src, int srclen, int *dstlen) { ut32 m, n; ut32 b, h; ut32 si, di; @@ -256,7 +256,7 @@ R_API char *r_punycode_encode(const ut8 *src, int srclen, int *dstlen) { return dst; } -R_API char *r_punycode_decode(const char *src, int srclen, int *dstlen) { +RZ_API char *rz_punycode_decode(const char *src, int srclen, int *dstlen) { const char *p; ut32 si, di; ut32 b, n, t, i, k, w; diff --git a/libr/util/qrcode.c b/librz/util/qrcode.c similarity index 98% rename from libr/util/qrcode.c rename to librz/util/qrcode.c index 32556d7c95..2f205151f0 100644 --- a/libr/util/qrcode.c +++ b/librz/util/qrcode.c @@ -22,11 +22,11 @@ * Software. */ -#include +#include #include #include #include -#include "r_qrcode.h" +#include "rz_qrcode.h" /*---- Forward declarations for private functions ----*/ // this is an antipattern in r2land. must be fixed @@ -129,7 +129,7 @@ static const int PENALTY_N4 = 10; /*---- High-level QR Code encoding functions ----*/ // Public function - see documentation comment in header file. -R_API bool r_qrcode_text(const char *text, ut8 tempBuffer[], ut8 qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { +RZ_API bool rz_qrcode_text(const char *text, ut8 tempBuffer[], ut8 qrcode[], enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { if (!text || !tempBuffer || !qrcode) { return false; } @@ -165,7 +165,7 @@ R_API bool r_qrcode_text(const char *text, ut8 tempBuffer[], ut8 qrcode[], enum for (i = 0; i < textLen; i++) { tempBuffer[i] = (ut8) text[i]; } - return r_qrcode_bin (tempBuffer, (size_t) textLen, qrcode, ecl, minVersion, maxVersion, mask, boostEcl); + return rz_qrcode_bin (tempBuffer, (size_t) textLen, qrcode, ecl, minVersion, maxVersion, mask, boostEcl); } int version = fitVersionToData (minVersion, maxVersion, ecl, textLen, (int) textBits, @@ -225,7 +225,7 @@ R_API bool r_qrcode_text(const char *text, ut8 tempBuffer[], ut8 qrcode[], enum // Public function - see documentation comment in header file. -R_API bool r_qrcode_bin(ut8 *dataAndTemp, int dataLen, ut8 *qrcode, +RZ_API bool rz_qrcode_bin(ut8 *dataAndTemp, int dataLen, ut8 *qrcode, enum qrcodegen_Ecc ecl, int minVersion, int maxVersion, enum qrcodegen_Mask mask, bool boostEcl) { if (!dataAndTemp || !qrcode || dataLen < 1) { return false; @@ -998,7 +998,7 @@ static char qrcode_utf8_expansions[16][7] = { " ","▀ "," ▀","▀▀", " ▄","▀▄"," █","▀█", "▄▄","█▄","▄█","██"}; -R_API char *r_qrcode_gen(const ut8 *text, int len, bool utf8, bool inverted) { +RZ_API char *rz_qrcode_gen(const ut8 *text, int len, bool utf8, bool inverted) { uint8_t qrcode[qrcodegen_BUFFER_LEN_MAX] = { 0 }; @@ -1009,7 +1009,7 @@ R_API char *r_qrcode_gen(const ut8 *text, int len, bool utf8, bool inverted) { // Make and print the QR Code symbol ut8 *buf = calloc ((128 + len), 32); memcpy (buf, text, len); - bool ok = r_qrcode_bin (buf, len, qrcode, errCorLvl, + bool ok = rz_qrcode_bin (buf, len, qrcode, errCorLvl, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, true); if (!ok) { diff --git a/libr/util/queue.c b/librz/util/queue.c similarity index 82% rename from libr/util/queue.c rename to librz/util/queue.c index e7ad59893e..c870f420bc 100644 --- a/libr/util/queue.c +++ b/librz/util/queue.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2007-2015 - ret2libc */ -#include +#include -R_API RQueue *r_queue_new (int n) { +RZ_API RQueue *rz_queue_new (int n) { if (n <= 0) { return NULL; } @@ -22,7 +22,7 @@ R_API RQueue *r_queue_new (int n) { return q; } -R_API void r_queue_free(RQueue *q) { +RZ_API void rz_queue_free(RQueue *q) { free (q->elems); free (q); } @@ -57,7 +57,7 @@ static int increase_capacity(RQueue *q) { return true; } -R_API int r_queue_enqueue(RQueue *q, void *el) { +RZ_API int rz_queue_enqueue(RQueue *q, void *el) { if (is_full(q)) { int res = increase_capacity (q); if (!res) { @@ -71,10 +71,10 @@ R_API int r_queue_enqueue(RQueue *q, void *el) { return true; } -R_API void *r_queue_dequeue(RQueue *q) { +RZ_API void *rz_queue_dequeue(RQueue *q) { void *res; - if (r_queue_is_empty (q)) { + if (rz_queue_is_empty (q)) { return NULL; } res = q->elems[q->front]; @@ -83,6 +83,6 @@ R_API void *r_queue_dequeue(RQueue *q) { return res; } -R_API int r_queue_is_empty(RQueue *q) { +RZ_API int rz_queue_is_empty(RQueue *q) { return q->size == 0; } diff --git a/libr/util/randomart.c b/librz/util/randomart.c similarity index 97% rename from libr/util/randomart.c rename to librz/util/randomart.c index d2881d8bcc..0d8b43ea4b 100644 --- a/libr/util/randomart.c +++ b/librz/util/randomart.c @@ -33,14 +33,14 @@ * Else pictures would be too dense, and drawing the frame would * fail, too, because the key type would not fit in anymore. */ -#include +#include #define FLDBASE 8 #define FLDSIZE_Y (FLDBASE + 1) #define FLDSIZE_X (FLDBASE * 2 + 1) //static char * key_fingerprint_randomart(ut8 *dgst_raw, ut32 dgst_raw_len) { -R_API char *r_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr) { +RZ_API char *rz_print_randomart(const ut8 *dgst_raw, ut32 dgst_raw_len, ut64 addr) { /* * Chars to be used after each other every time the worm * intersects with itself. Matter of taste. diff --git a/libr/util/range.c b/librz/util/range.c similarity index 68% rename from libr/util/range.c rename to librz/util/range.c index 1ebd5958d0..b9451b6036 100644 --- a/libr/util/range.c +++ b/librz/util/range.c @@ -1,20 +1,20 @@ /* radare - LGPL - Copyright 2008-2020 pancake */ -#include +#include -// TODO: use r_list instead of list.h +// TODO: use rz_list instead of list.h // TODO: redesign this api.. why? :) // TODO: add tags to ranges //void (*ranges_new_callback)(struct range_t *r) = NULL; -R_API RRange *r_range_new(void) { +RZ_API RRange *rz_range_new(void) { RRange *r = R_NEW0 (RRange); if (r) { r->count = r->changed = 0; - r->ranges = r_list_new (); + r->ranges = rz_list_new (); if (!r->ranges) { - r_range_free (r); + rz_range_free (r); return NULL; } r->ranges->free = free; @@ -22,15 +22,15 @@ R_API RRange *r_range_new(void) { return r; } -R_API RRange *r_range_free(RRange *r) { - r_list_purge (r->ranges); +RZ_API RRange *rz_range_free(RRange *r) { + rz_list_purge (r->ranges); free (r); return NULL; } // TODO: optimize by just returning the pointers to the internal foo? -R_API int r_range_get_data(RRange *rgs, ut64 addr, ut8 *buf, int len) { - RRangeItem *r = r_range_item_get (rgs, addr); +RZ_API int rz_range_get_data(RRange *rgs, ut64 addr, ut8 *buf, int len) { + RRangeItem *r = rz_range_item_get (rgs, addr); if (!r) { return 0; } @@ -41,8 +41,8 @@ R_API int r_range_get_data(RRange *rgs, ut64 addr, ut8 *buf, int len) { return len; } -R_API int r_range_set_data(RRange *rgs, ut64 addr, const ut8 *buf, int len) { - RRangeItem *r = r_range_item_get (rgs, addr); +RZ_API int rz_range_set_data(RRange *rgs, ut64 addr, const ut8 *buf, int len) { + RRangeItem *r = rz_range_item_get (rgs, addr); if (!r) { return 0; } @@ -55,10 +55,10 @@ R_API int r_range_set_data(RRange *rgs, ut64 addr, const ut8 *buf, int len) { return 1; } -RRangeItem *r_range_item_get(RRange *rgs, ut64 addr) { +RRangeItem *rz_range_item_get(RRange *rgs, ut64 addr) { RRangeItem *r; - RListIter *iter; - r_list_foreach (rgs->ranges, iter, r) { + RzListIter *iter; + rz_list_foreach (rgs->ranges, iter, r) { if (addr >= r->fr && addr < r->to) { return r; } @@ -68,23 +68,23 @@ RRangeItem *r_range_item_get(RRange *rgs, ut64 addr) { /* returns the sum of all the ranges contained */ // XXX: can be caught while adding/removing elements -R_API ut64 r_range_size(RRange *rgs) { +RZ_API ut64 rz_range_size(RRange *rgs) { ut64 sum = 0; - RListIter *iter; + RzListIter *iter; RRangeItem *r; - r_list_foreach (rgs->ranges, iter, r) { + rz_list_foreach (rgs->ranges, iter, r) { sum += r->to - r->fr; } return sum; } -R_API RRange *r_range_new_from_string(const char *string) { - RRange *rgs = r_range_new (); - r_range_add_from_string (rgs, string); +RZ_API RRange *rz_range_new_from_string(const char *string) { + RRange *rgs = rz_range_new (); + rz_range_add_from_string (rgs, string); return rgs; } -R_API int r_range_add_from_string(RRange *rgs, const char *string) { +RZ_API int rz_range_add_from_string(RRange *rgs, const char *string) { ut64 addr, addr2; int i, len = strlen (string) + 1; char *str, *ostr = malloc (len); @@ -105,13 +105,13 @@ R_API int r_range_add_from_string(RRange *rgs, const char *string) { case ',': str[i] = '\0'; if (p2) { - addr = r_num_get (NULL, p); - addr2 = r_num_get (NULL, p2); - r_range_add(rgs, addr, addr2, 1); + addr = rz_num_get (NULL, p); + addr2 = rz_num_get (NULL, p2); + rz_range_add(rgs, addr, addr2, 1); p2 = NULL; } else { - addr = r_num_get (NULL, p); - r_range_add (rgs, addr, addr + 1, 1); + addr = rz_num_get (NULL, p); + rz_range_add (rgs, addr, addr + 1, 1); } p = str + i + 1; str[i] = ','; @@ -119,13 +119,13 @@ R_API int r_range_add_from_string(RRange *rgs, const char *string) { } } if (p2) { - addr = r_num_get (NULL, p); - addr2 = r_num_get (NULL, p2); - r_range_add (rgs, addr, addr2, 1); + addr = rz_num_get (NULL, p); + addr2 = rz_num_get (NULL, p2); + rz_range_add (rgs, addr, addr2, 1); } else if (p) { - addr = r_num_get (NULL, p); - r_range_add (rgs, addr, addr + 1, 1); + addr = rz_num_get (NULL, p); + rz_range_add (rgs, addr, addr + 1, 1); } free (ostr); return rgs? rgs->changed: 0; @@ -140,13 +140,13 @@ R_API int r_range_add_from_string(RRange *rgs, const char *string) { = |_________| = |___||__| = |_______| = |_________| |_______| result #endif -RRangeItem *r_range_add(RRange *rgs, ut64 fr, ut64 to, int rw) { - RListIter *iter; +RRangeItem *rz_range_add(RRange *rgs, ut64 fr, ut64 to, int rw) { + RzListIter *iter; RRangeItem *r, *ret = NULL; int add = 1; - r_num_minmax_swap (&fr, &to); - r_list_foreach (rgs->ranges, iter, r) { + rz_num_minmax_swap (&fr, &to); + rz_list_foreach (rgs->ranges, iter, r) { if (r->fr == fr && r->to == to) { add = 0; } else if (r->fr <= fr && r->fr <= to && r->to >= fr && r->to <= to) { @@ -174,7 +174,7 @@ RRangeItem *r_range_add(RRange *rgs, ut64 fr, ut64 to, int rw) { ret->to = to; ret->datalen = 0; ret->data = NULL; - r_list_append (rgs->ranges, ret); + rz_list_append (rgs->ranges, ret); rgs->changed = 1; } @@ -190,14 +190,14 @@ RRangeItem *r_range_add(RRange *rgs, ut64 fr, ut64 to, int rw) { = |__| = = |___| = |__| |__| result #endif -R_API int r_range_sub(RRange *rgs, ut64 fr, ut64 to) { +RZ_API int rz_range_sub(RRange *rgs, ut64 fr, ut64 to) { RRangeItem *r; - RListIter *iter; + RzListIter *iter; - r_num_minmax_swap (&fr, &to); + rz_num_minmax_swap (&fr, &to); __reloop: - r_list_foreach (rgs->ranges, iter, r) { + rz_list_foreach (rgs->ranges, iter, r) { /* update to */ if (r->fr < fr && r->fr < to && r->to > fr && r->to < to) { r->to = fr; @@ -208,14 +208,14 @@ R_API int r_range_sub(RRange *rgs, ut64 fr, ut64 to) { /* delete */ if (r->fr > fr && r->fr < to && r->to > fr && r->to < to) { /* delete */ - r_list_delete (rgs->ranges, iter); + rz_list_delete (rgs->ranges, iter); rgs->changed = 1; goto __reloop; } /* split */ if (r->fr < fr && r->fr < to && r->to > fr && r->to > to) { r->to = fr; - r_range_add (rgs, to, r->to, 1); + rz_range_add (rgs, to, r->to, 1); //ranges_add(rang, to, r->to, 1); goto __reloop; } @@ -225,19 +225,19 @@ R_API int r_range_sub(RRange *rgs, ut64 fr, ut64 to) { #if 0 /* TODO: should remove some of them right? */ -R_API void r_range_merge(RRange *rgs, RRange *r) { - RListIter *iter; +RZ_API void rz_range_merge(RRange *rgs, RRange *r) { + RzListIter *iter; RRangeItem *r; - r_list_foreach (rgs->ranges, iter, r) - r_range_add (rgs, r->fr, r->to, 0); + rz_list_foreach (rgs->ranges, iter, r) + rz_range_add (rgs, r->fr, r->to, 0); } #endif //int ranges_is_used(ut64 addr) -R_API int r_range_contains(RRange *rgs, ut64 addr) { +RZ_API int rz_range_contains(RRange *rgs, ut64 addr) { RRangeItem *r; - RListIter *iter; - r_list_foreach (rgs->ranges, iter, r) { + RzListIter *iter; + rz_list_foreach (rgs->ranges, iter, r) { if (addr >= r->fr && addr <= r->to) { return true; } @@ -251,27 +251,27 @@ static int cmp_ranges(void *a, void *b) { return (first->fr > second->fr) - (first->fr < second->fr); } -R_API int r_range_sort(RRange *rgs) { +RZ_API int rz_range_sort(RRange *rgs) { bool ch = rgs->ranges->sorted; if (!rgs->changed) { return false; } rgs->changed = false; - r_list_sort (rgs->ranges, (RListComparator)cmp_ranges); + rz_list_sort (rgs->ranges, (RzListComparator)cmp_ranges); if (ch != rgs->ranges->sorted) { rgs->changed = true; } return rgs->changed; } -R_API void r_range_percent(RRange *rgs) { - RListIter *iter; +RZ_API void rz_range_percent(RRange *rgs) { + RzListIter *iter; RRangeItem *r; int w, i; ut64 seek, step; ut64 dif, fr = -1, to = -1; - r_list_foreach (rgs->ranges, iter, r) { + rz_list_foreach (rgs->ranges, iter, r) { if (fr == -1) { /* init */ fr = r->fr; @@ -300,7 +300,7 @@ R_API void r_range_percent(RRange *rgs) { // XXX do not use printf here! printf ("0x%08"PFMT64x" [", fr); for (i = 0; i < w; i++) { - if (r_range_contains (rgs, seek)) { + if (rz_range_contains (rgs, seek)) { printf ("#"); } else { printf ("."); @@ -311,12 +311,12 @@ R_API void r_range_percent(RRange *rgs) { } // TODO: total can be cached in rgs!! -int r_range_list(RRange *rgs, int rad) { +int rz_range_list(RRange *rgs, int rad) { ut64 total = 0; RRangeItem *r; - RListIter *iter; - r_range_sort (rgs); - r_list_foreach (rgs->ranges, iter, r) { + RzListIter *iter; + rz_range_sort (rgs); + rz_list_foreach (rgs->ranges, iter, r) { if (rad) { printf ("ar+ 0x%08"PFMT64x" 0x%08"PFMT64x"\n", r->fr, r->to); } else { @@ -328,12 +328,12 @@ int r_range_list(RRange *rgs, int rad) { return 0; } -int r_range_get_n(RRange *rgs, int n, ut64 *fr, ut64 *to) { +int rz_range_get_n(RRange *rgs, int n, ut64 *fr, ut64 *to) { int count = 0; RRangeItem *r; - RListIter *iter; - r_range_sort (rgs); - r_list_foreach (rgs->ranges, iter, r) { + RzListIter *iter; + rz_range_sort (rgs); + rz_list_foreach (rgs->ranges, iter, r) { if (count == n) { *fr = r->fr; *to = r->to; @@ -350,17 +350,17 @@ int r_range_get_n(RRange *rgs, int n, ut64 *fr, ut64 *to) { --------------------------------- |__| |__| |_| #endif -RRange *r_range_inverse(RRange *rgs, ut64 fr, ut64 to, int flags) { +RRange *rz_range_inverse(RRange *rgs, ut64 fr, ut64 to, int flags) { ut64 total = 0; - RListIter *iter; + RzListIter *iter; RRangeItem *r = NULL; - RRange *newrgs = r_range_new(); + RRange *newrgs = rz_range_new(); - r_range_sort(rgs); + rz_range_sort(rgs); - r_list_foreach (rgs->ranges, iter, r) { + rz_list_foreach (rgs->ranges, iter, r) { if (r->fr > fr && r->fr < to) { - r_range_add (newrgs, fr, r->fr, 1); + rz_range_add (newrgs, fr, r->fr, 1); //eprintf("0x%08"PFMT64x" .. 0x%08"PFMT64x"\n", fr, r->fr); total += (r->fr - fr); fr = r->to; @@ -368,7 +368,7 @@ RRange *r_range_inverse(RRange *rgs, ut64 fr, ut64 to, int flags) { } if (fr < to) { //eprintf("0x%08"PFMT64x" .. 0x%08"PFMT64x"\n", fr, to); - r_range_add (newrgs, fr, to, 1); + rz_range_add (newrgs, fr, to, 1); total += (to - fr); } // eprintf("Total bytes: %"PFMT64d"\n", total); @@ -381,10 +381,10 @@ RRange *r_range_inverse(RRange *rgs, ut64 fr, ut64 to, int flags) { */ // TODO: make it a macro // TODO: move to num.c ? -R_API int r_range_overlap(ut64 a0, ut64 a1, ut64 b0, ut64 b1, int *d) { +RZ_API int rz_range_overlap(ut64 a0, ut64 a1, ut64 b0, ut64 b1, int *d) { // TODO: ensure ranges minmax .. innecesary at runtime? - //r_num_minmax_swap (&a0, &a1); - //r_num_minmax_swap (&b0, &b1); + //rz_num_minmax_swap (&a0, &a1); + //rz_num_minmax_swap (&b0, &b1); return *d = (b0 - a0), !(a1 < b0 || a0 > b1); #if 0 // does not overlap diff --git a/libr/util/rbtree.c b/librz/util/rbtree.c similarity index 78% rename from libr/util/rbtree.c rename to librz/util/rbtree.c index 2540af22a6..42f1726736 100644 --- a/libr/util/rbtree.c +++ b/librz/util/rbtree.c @@ -2,8 +2,8 @@ #include -#include -#include +#include +#include static inline bool red(RBNode *x) { return x && x->red; @@ -86,7 +86,7 @@ static void _check(RBNode *x) { */ // Returns true if a node with an equal key is deleted -R_API bool r_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user, RBNodeSum sum) { +RZ_API bool rz_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user, RBNodeSum sum) { RBNode head, *del = NULL, **del_link = NULL, *g = NULL, *p = NULL, *q = &head, *path[R_RBTREE_MAX_HEIGHT]; int d = 1, d2, dep = 0; head.child[0] = NULL; @@ -182,7 +182,7 @@ R_API bool r_rbtree_aug_delete(RBNode **root, void *data, RBComparator cmp, void } // Returns true if stuff got inserted, else false -R_API bool r_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum) { +RZ_API bool rz_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum) { node->child[0] = node->child[1] = NULL; if (!*root) { *root = node; @@ -254,7 +254,7 @@ R_API bool r_rbtree_aug_insert(RBNode **root, void *data, RBNode *node, RBCompar } // returns true if the sum has been updated, false if node has not been found -R_API bool r_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum) { +RZ_API bool rz_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBComparator cmp, void *cmp_user, RBNodeSum sum) { size_t dep = 0; RBNode *path[R_RBTREE_MAX_HEIGHT]; RBNode *cur = root; @@ -281,11 +281,11 @@ R_API bool r_rbtree_aug_update_sum(RBNode *root, void *data, RBNode *node, RBCom return true; } -R_API bool r_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user) { - return r_rbtree_aug_delete (root, data, cmp, cmp_user, freefn, free_user, NULL); +RZ_API bool rz_rbtree_delete(RBNode **root, void *data, RBComparator cmp, void *cmp_user, RBNodeFree freefn, void *free_user) { + return rz_rbtree_aug_delete (root, data, cmp, cmp_user, freefn, free_user, NULL); } -R_API RBNode *r_rbtree_find(RBNode *x, void *data, RBComparator cmp, void *user) { +RZ_API RBNode *rz_rbtree_find(RBNode *x, void *data, RBComparator cmp, void *user) { while (x) { int d = cmp (data, x, user); if (d < 0) { @@ -299,19 +299,19 @@ R_API RBNode *r_rbtree_find(RBNode *x, void *data, RBComparator cmp, void *user) return NULL; } -R_API void r_rbtree_free(RBNode *x, RBNodeFree freefn, void *user) { +RZ_API void rz_rbtree_free(RBNode *x, RBNodeFree freefn, void *user) { if (x) { - r_rbtree_free (x->child[0], freefn, user); - r_rbtree_free (x->child[1], freefn, user); + rz_rbtree_free (x->child[0], freefn, user); + rz_rbtree_free (x->child[1], freefn, user); freefn (x, user); } } -R_API void r_rbtree_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *user) { - r_rbtree_aug_insert (root, data, node, cmp, user, NULL); +RZ_API void rz_rbtree_insert(RBNode **root, void *data, RBNode *node, RBComparator cmp, void *user) { + rz_rbtree_aug_insert (root, data, node, cmp, user, NULL); } -R_API RBNode *r_rbtree_lower_bound(RBNode *x, void *data, RBComparator cmp, void *user) { +RZ_API RBNode *rz_rbtree_lower_bound(RBNode *x, void *data, RBComparator cmp, void *user) { RBNode *ret = NULL; while (x) { int d = cmp (data, x, user); @@ -325,11 +325,11 @@ R_API RBNode *r_rbtree_lower_bound(RBNode *x, void *data, RBComparator cmp, void return ret; } -R_API RBIter r_rbtree_lower_bound_forward(RBNode *root, void *data, RBComparator cmp, void *user) { +RZ_API RBIter rz_rbtree_lower_bound_forward(RBNode *root, void *data, RBComparator cmp, void *user) { return bound_iter (root, data, cmp, false, user); } -R_API RBNode *r_rbtree_upper_bound(RBNode *x, void *data, RBComparator cmp, void *user) { +RZ_API RBNode *rz_rbtree_upper_bound(RBNode *x, void *data, RBComparator cmp, void *user) { void *ret = NULL; while (x) { int d = cmp (data, x, user); @@ -343,7 +343,7 @@ R_API RBNode *r_rbtree_upper_bound(RBNode *x, void *data, RBComparator cmp, void return ret; } -R_API RBIter r_rbtree_upper_bound_backward(RBNode *root, void *data, RBComparator cmp, void *user) { +RZ_API RBIter rz_rbtree_upper_bound_backward(RBNode *root, void *data, RBComparator cmp, void *user) { return bound_iter (root, data, cmp, true, user); } @@ -356,11 +356,11 @@ static RBIter _first(RBNode *x, int dir) { return it; } -R_API RBIter r_rbtree_first(RBNode *tree) { +RZ_API RBIter rz_rbtree_first(RBNode *tree) { return _first (tree, 0); } -R_API RBIter r_rbtree_last(RBNode *tree) { +RZ_API RBIter rz_rbtree_last(RBNode *tree) { return _first (tree, 1); } @@ -371,20 +371,20 @@ static inline void _next(RBIter *it, int dir) { } } -R_API void r_rbtree_iter_next(RBIter *it) { +RZ_API void rz_rbtree_iter_next(RBIter *it) { _next (it, 0); } -R_API void r_rbtree_iter_prev(RBIter *it) { +RZ_API void rz_rbtree_iter_prev(RBIter *it) { _next (it, 1); } -R_API RContRBTree *r_rbtree_cont_new(void) { +RZ_API RContRBTree *rz_rbtree_cont_new(void) { return R_NEW0 (RContRBTree); } -R_API RContRBTree *r_rbtree_cont_newf(RContRBFree f) { - RContRBTree *tree = r_rbtree_cont_new (); +RZ_API RContRBTree *rz_rbtree_cont_newf(RContRBFree f) { + RContRBTree *tree = rz_rbtree_cont_new (); if (tree) { tree->free = f; } @@ -420,8 +420,8 @@ static int cont_rbtree_free_cmp_wrapper(const void *data, const RBNode *in_tree, return ret; } -R_API bool r_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { - r_return_val_if_fail (tree && cmp, false); +RZ_API bool rz_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { + rz_return_val_if_fail (tree && cmp, false); if (!tree->root) { tree->root = R_NEW0 (RContRBNode); if (tree->root) { @@ -440,7 +440,7 @@ R_API bool r_rbtree_cont_insert(RContRBTree *tree, void *data, RContRBCmp cmp, v incoming_node->data = data; RCRBCmpWrap cmp_wrap = { cmp, NULL, user }; RBNode *root_node = &tree->root->node; - const bool ret = r_rbtree_aug_insert (&root_node, incoming_node, + const bool ret = rz_rbtree_aug_insert (&root_node, incoming_node, &incoming_node->node, cont_rbtree_cmp_wrapper, &cmp_wrap, NULL); if (root_node != (&tree->root->node)) { tree->root = container_of (root_node, RContRBNode, node); //cursed augmentation garbage @@ -460,37 +460,37 @@ static void cont_node_free(RBNode *node, void *user) { free (contnode); } -R_API bool r_rbtree_cont_delete(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { +RZ_API bool rz_rbtree_cont_delete(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { if (!(tree && cmp && tree->root)) { return false; } RCRBCmpWrap cmp_wrap = { cmp, tree->free, user }; RContRBNode data_wrap = { { { NULL, NULL }, false }, data }; RBNode *root_node = &tree->root->node; - const bool ret = r_rbtree_aug_delete (&root_node, &data_wrap, cont_rbtree_free_cmp_wrapper, &cmp_wrap, cont_node_free, NULL, NULL); + const bool ret = rz_rbtree_aug_delete (&root_node, &data_wrap, cont_rbtree_free_cmp_wrapper, &cmp_wrap, cont_node_free, NULL, NULL); if (root_node != (&tree->root->node)) { //can this crash? tree->root = container_of (root_node, RContRBNode, node); //cursed augmentation garbage } return ret; } -R_API void *r_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { - r_return_val_if_fail (tree && cmp, NULL); +RZ_API void *rz_rbtree_cont_find(RContRBTree *tree, void *data, RContRBCmp cmp, void *user) { + rz_return_val_if_fail (tree && cmp, NULL); if (!tree->root) { return NULL; } RCRBCmpWrap cmp_wrap = { cmp, NULL, user }; // RBNode search_node = tree->root->node; - RBNode *result_node = r_rbtree_find (&tree->root->node, data, cont_rbtree_search_cmp_wrapper, &cmp_wrap); + RBNode *result_node = rz_rbtree_find (&tree->root->node, data, cont_rbtree_search_cmp_wrapper, &cmp_wrap); if (result_node) { return (container_of (result_node, RContRBNode, node))->data; } return NULL; } -R_API void r_rbtree_cont_free(RContRBTree *tree) { +RZ_API void rz_rbtree_cont_free(RContRBTree *tree) { if (tree && tree->root) { - r_rbtree_free (&tree->root->node, cont_node_free, tree->free); + rz_rbtree_free (&tree->root->node, cont_node_free, tree->free); } free (tree); } diff --git a/libr/util/regex/COPYRIGHT b/librz/util/regex/COPYRIGHT similarity index 100% rename from libr/util/regex/COPYRIGHT rename to librz/util/regex/COPYRIGHT diff --git a/libr/util/regex/Makefile b/librz/util/regex/Makefile similarity index 80% rename from libr/util/regex/Makefile rename to librz/util/regex/Makefile index 3b818763a3..f4fa2a3251 100644 --- a/libr/util/regex/Makefile +++ b/librz/util/regex/Makefile @@ -3,7 +3,7 @@ SRC= regcomp.c regerror.c regexec.c CFLAGS+=-I. -Wall CFLAGS+=-I../../include #CFLAGS+=-Wall -#CFLAGS+=`pkg-config --cflags --libs r_util` +#CFLAGS+=`pkg-config --cflags --libs rz_util` # implicit engine.c all: diff --git a/libr/util/regex/README b/librz/util/regex/README similarity index 100% rename from libr/util/regex/README rename to librz/util/regex/README diff --git a/libr/util/regex/cclass.h b/librz/util/regex/cclass.h similarity index 100% rename from libr/util/regex/cclass.h rename to librz/util/regex/cclass.h diff --git a/libr/util/regex/cname.h b/librz/util/regex/cname.h similarity index 100% rename from libr/util/regex/cname.h rename to librz/util/regex/cname.h diff --git a/libr/util/regex/engine.c b/librz/util/regex/engine.c similarity index 98% rename from libr/util/regex/engine.c rename to librz/util/regex/engine.c index c4e3e094b6..536bae7ef0 100644 --- a/libr/util/regex/engine.c +++ b/librz/util/regex/engine.c @@ -71,7 +71,7 @@ struct match { struct re_guts *g; int eflags; - RRegexMatch *pmatch; /* [nsub+1] (0 element unused) */ + RzRegexMatch *pmatch; /* [nsub+1] (0 element unused) */ char *offp; /* offsets work from here */ char *beginp; /* start of string -- virtual NUL precedes */ char *endp; /* end of string -- virtual NUL here */ @@ -84,7 +84,7 @@ struct match { states empty; /* empty set of states */ }; -static int matcher(struct re_guts *, char *, size_t, RRegexMatch[], int); +static int matcher(struct re_guts *, char *, size_t, RzRegexMatch[], int); static char *dissect(struct match *, char *, char *, sopno, sopno); static char *backref(struct match *, char *, char *, sopno, sopno, sopno, int); static char *fast(struct match *, char *, char *, sopno, sopno); @@ -125,7 +125,7 @@ static int nope = 0; - matcher - the actual matching engine */ static int /* 0 success, R_REGEX_NOMATCH failure */ -matcher(struct re_guts *g, char *string, size_t nmatch, RRegexMatch pmatch[], +matcher(struct re_guts *g, char *string, size_t nmatch, RzRegexMatch pmatch[], int eflags) { char *endp; @@ -208,11 +208,11 @@ matcher(struct re_guts *g, char *string, size_t nmatch, RRegexMatch pmatch[], /* oh my, he wants the subexpressions... */ if (!m->pmatch) { - if ((m->g->nsub + 1) * sizeof(RRegexMatch) < m->g->nsub) { + if ((m->g->nsub + 1) * sizeof(RzRegexMatch) < m->g->nsub) { return R_REGEX_ESPACE; } - m->pmatch = (RRegexMatch *)malloc((m->g->nsub + 1) * - sizeof(RRegexMatch)); + m->pmatch = (RzRegexMatch *)malloc((m->g->nsub + 1) * + sizeof(RzRegexMatch)); } if (!m->pmatch) { STATETEARDOWN(m); diff --git a/libr/util/regex/re_format.7 b/librz/util/regex/re_format.7 similarity index 100% rename from libr/util/regex/re_format.7 rename to librz/util/regex/re_format.7 diff --git a/libr/util/regex/regcomp.c b/librz/util/regex/regcomp.c similarity index 98% rename from libr/util/regex/regcomp.c rename to librz/util/regex/regcomp.c index 4123c44d01..2e417a464a 100644 --- a/libr/util/regex/regcomp.c +++ b/librz/util/regex/regcomp.c @@ -40,7 +40,7 @@ #include #include #include -#include "r_regex.h" +#include "rz_regex.h" #include "utils.h" #include "regex2.h" @@ -138,16 +138,16 @@ static char nuls[10]; /* place to point scanner in event of error */ #define DROP(n) (p->slen -= (n)) -R_API int r_regex_match (const char *pattern, const char *flags, const char *text) { +RZ_API int rz_regex_match (const char *pattern, const char *flags, const char *text) { int ret; - RRegex rx; - int re_flags = r_regex_flags (flags); - if (r_regex_comp (&rx, pattern, re_flags)) { + RzRegex rx; + int re_flags = rz_regex_flags (flags); + if (rz_regex_comp (&rx, pattern, re_flags)) { eprintf ("FAIL TO COMPILE %s\n", pattern); return 0; } - ret = r_regex_exec (&rx, text, 0, 0, re_flags); - r_regex_fini (&rx); + ret = rz_regex_exec (&rx, text, 0, 0, re_flags); + rz_regex_fini (&rx); return ret? 0: 1; #if 0 regex_t preg; @@ -158,20 +158,20 @@ R_API int r_regex_match (const char *pattern, const char *flags, const char *tex #endif } -R_API RRegex *r_regex_new(const char *pattern, const char *flags) { - RRegex *r, rx = {0}; - if (r_regex_comp (&rx, pattern, r_regex_flags (flags))) { +RZ_API RzRegex *rz_regex_new(const char *pattern, const char *flags) { + RzRegex *r, rx = {0}; + if (rz_regex_comp (&rx, pattern, rz_regex_flags (flags))) { return NULL; } - r = R_NEW (RRegex); + r = R_NEW (RzRegex); if (!r) { return NULL; } - memcpy (r, &rx, sizeof (RRegex)); + memcpy (r, &rx, sizeof (RzRegex)); return r; } -R_API int r_regex_flags(const char *f) { +RZ_API int rz_regex_flags(const char *f) { int flags = 0; if (!f || !*f) { return 0; @@ -200,7 +200,7 @@ R_API int r_regex_flags(const char *f) { return flags; } -R_API void r_regex_fini(RRegex *preg) { +RZ_API void rz_regex_fini(RzRegex *preg) { struct re_guts *g; if (!preg) { return; @@ -223,8 +223,8 @@ R_API void r_regex_fini(RRegex *preg) { free (g); } -R_API void r_regex_free(RRegex *preg) { - r_regex_fini (preg); +RZ_API void rz_regex_free(RzRegex *preg) { + rz_regex_fini (preg); free (preg); } @@ -232,7 +232,7 @@ R_API void r_regex_free(RRegex *preg) { - regcomp - interface for parser and compilation - 0 success, otherwise R_REGEX_something */ -R_API int r_regex_comp(RRegex *preg, const char *pattern, int cflags) { +RZ_API int rz_regex_comp(RzRegex *preg, const char *pattern, int cflags) { struct parse pa; struct re_guts *g; struct parse *p = &pa; @@ -347,7 +347,7 @@ R_API int r_regex_comp(RRegex *preg, const char *pattern, int cflags) { } #endif if (p->error) { - r_regex_fini (preg); + rz_regex_fini (preg); } return p->error; } diff --git a/libr/util/regex/regerror.c b/librz/util/regex/regerror.c similarity index 95% rename from libr/util/regex/regerror.c rename to librz/util/regex/regerror.c index f8385365f0..038b5a85e3 100644 --- a/libr/util/regex/regerror.c +++ b/librz/util/regex/regerror.c @@ -40,11 +40,11 @@ #include #include #include -#include "r_regex.h" +#include "rz_regex.h" #include "utils.h" -static char *regatoi(const RRegex*, char *, int); +static char *regatoi(const RzRegex*, char *, int); static struct rerr { int code; @@ -76,7 +76,7 @@ static struct rerr { */ /* ARGSUSED */ size_t -r_regex_error(int errcode, const RRegex *preg, char *errbuf, size_t errbuf_size) +rz_regex_error(int errcode, const RzRegex *preg, char *errbuf, size_t errbuf_size) { struct rerr *r; size_t len; @@ -117,7 +117,7 @@ r_regex_error(int errcode, const RRegex *preg, char *errbuf, size_t errbuf_size) - regatoi - internal routine to implement R_REGEX_ATOI */ static char * -regatoi(const RRegex *preg, char *localbuf, int localbufsize) +regatoi(const RzRegex *preg, char *localbuf, int localbufsize) { struct rerr *r; diff --git a/libr/util/regex/regex.3 b/librz/util/regex/regex.3 similarity index 100% rename from libr/util/regex/regex.3 rename to librz/util/regex/regex.3 diff --git a/libr/util/regex/regex2.h b/librz/util/regex/regex2.h similarity index 100% rename from libr/util/regex/regex2.h rename to librz/util/regex/regex2.h diff --git a/libr/util/regex/regexec.c b/librz/util/regex/regexec.c similarity index 95% rename from libr/util/regex/regexec.c rename to librz/util/regex/regexec.c index 28b0e56389..cea1ea159e 100644 --- a/libr/util/regex/regexec.c +++ b/librz/util/regex/regexec.c @@ -47,7 +47,7 @@ #include #include #include -#include +#include #include "utils.h" #include "regex2.h" @@ -129,8 +129,8 @@ #include "engine.c" -R_API bool r_regex_check(const RRegex *rr, const char *str) { - return r_regex_exec (rr, str, 0, NULL, rr->re_flags); +RZ_API bool rz_regex_check(const RzRegex *rr, const char *str) { + return rz_regex_exec (rr, str, 0, NULL, rr->re_flags); } /* - regexec - interface for matching @@ -140,8 +140,8 @@ R_API bool r_regex_check(const RRegex *rr, const char *str) { * have been prototyped. */ int /* 0 success, R_REGEX_NOMATCH failure */ -r_regex_exec(const RRegex *preg, const char *string, size_t nmatch, - RRegexMatch pmatch[], int eflags) +rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, + RzRegexMatch pmatch[], int eflags) { struct re_guts *g; #ifdef REDEBUG diff --git a/librz/util/regex/test.c b/librz/util/regex/test.c new file mode 100644 index 0000000000..abf0a742bc --- /dev/null +++ b/librz/util/regex/test.c @@ -0,0 +1,53 @@ +#include +#include + +int _main(void) { + RzRegex rx; + int rc = rz_regex_comp (&rx, "^hi", R_REGEX_NOSUB); + if (rc) { + printf ("error\n"); + + } else { + rc = rz_regex_exec (&rx, "patata", 0, 0, 0); + printf ("out = %d\n", rc); + + rc = rz_regex_exec (&rx, "hillow", 0, 0, 0); + printf ("out = %d\n", rc); + } + rz_regex_free (&rx); + return 0; +} + +static void test_or(void) { + RzRegex *rx = rz_regex_new ("(eax|ebx)", "e"); + printf ("result (%s) = %d\n", "mov eax", rz_regex_match("(eax|ebx)", "e", "mov eax")); + printf ("result (%s) = %d\n", "mov ebx", rz_regex_match("(eax|ebx)", "e", "mov ebx")); + printf ("result (%s) = %d\n", "mov eax", rz_regex_match("(eax|ebx)", "e", "mov ecx")); + printf ("result (%s) = %d\n", "mov ebx", rz_regex_match("(eax|ecx)", "e", "mov ebx")); + printf ("result (%s) = %d\n", "mov eax", rz_regex_check(rx, "mov eax")); + printf ("result (%s) = %d\n", "mov ebx", rz_regex_check(rx, "mov ebx")); + printf ("result (%s) = %d\n", "mov eax", rz_regex_exec(rx, "mov eax", 0, 0, 1)); + printf ("result (%s) = %d\n", "mov ebx", rz_regex_exec(rx, "mov ebx", 0, 0, 1)); + rz_regex_free (rx); +} + +int main(int argc, char **argv) { + const char *needle = "^hi"; + const char *haystack_1 = "patata"; + const char *haystack_2 = "hillow"; + if (argc>3) { + needle = argv[1]; + haystack_1 = argv[2]; + haystack_2 = argv[3]; + } else printf ("Using default values\n"); + RzRegex *rx = rz_regex_new (needle, ""); + if (rx) { + int res = rz_regex_exec (rx, haystack_1, 0, 0, 0); + printf ("result (%s) = %d\n", haystack_1, res); + res = rz_regex_exec (rx, haystack_2, 0, 0, 0); + printf ("result (%s) = %d\n", haystack_2, res); + rz_regex_free (rx); + } else printf ("oops, cannot compile regexp\n"); + test_or(); + return 0; +} diff --git a/libr/util/regex/utils.h b/librz/util/regex/utils.h similarity index 100% rename from libr/util/regex/utils.h rename to librz/util/regex/utils.h diff --git a/libr/util/sandbox.c b/librz/util/sandbox.c similarity index 79% rename from libr/util/sandbox.c rename to librz/util/sandbox.c index 12e0b5d204..0182dc684d 100644 --- a/libr/util/sandbox.c +++ b/librz/util/sandbox.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2012-2020 - pancake */ -#include +#include #include #if _MSC_VER #include // to compile execl under msvc windows @@ -19,9 +19,9 @@ static bool enabled = false; static bool disabled = false; static bool inHomeWww(const char *path) { - r_return_val_if_fail (path, false); + rz_return_val_if_fail (path, false); bool ret = false; - char *homeWww = r_str_home (R2_HOME_WWWROOT R_SYS_DIR); + char *homeWww = rz_str_home (R2_HOME_WWWROOT R_SYS_DIR); if (homeWww) { if (!strncmp (path, homeWww, strlen (homeWww))) { ret = true; @@ -37,17 +37,17 @@ static bool inHomeWww(const char *path) { * Paths pointing into the webroot are an exception: For reaching the webroot, .. and absolute * path are ok. */ -R_API bool r_sandbox_check_path (const char *path) { - r_return_val_if_fail (path, false); +RZ_API bool rz_sandbox_check_path (const char *path) { + rz_return_val_if_fail (path, false); size_t root_len; char *p; /* XXX: the sandbox can be bypassed if a directory is symlink */ - root_len = strlen (R2_LIBDIR"/radare2"); - if (!strncmp (path, R2_LIBDIR"/radare2", root_len)) { + root_len = strlen (R2_LIBDIR"/rizin"); + if (!strncmp (path, R2_LIBDIR"/rizin", root_len)) { return true; } - root_len = strlen (R2_DATDIR"/radare2"); - if (!strncmp (path, R2_DATDIR"/radare2", root_len)) { + root_len = strlen (R2_DATDIR"/rizin"); + if (!strncmp (path, R2_DATDIR"/rizin", root_len)) { return true; } if (inHomeWww (path)) { @@ -91,7 +91,7 @@ R_API bool r_sandbox_check_path (const char *path) { return true; } -R_API bool r_sandbox_disable (bool e) { +RZ_API bool rz_sandbox_disable (bool e) { if (e) { #if LIBC_HAVE_PLEDGE if (enabled) { @@ -120,7 +120,7 @@ R_API bool r_sandbox_disable (bool e) { return enabled; } -R_API bool r_sandbox_enable (bool e) { +RZ_API bool rz_sandbox_enable (bool e) { if (enabled) { if (!e) { // eprintf ("Can't disable sandbox\n"); @@ -204,8 +204,8 @@ R_API bool r_sandbox_enable (bool e) { return enabled; } -R_API int r_sandbox_system(const char *x, int n) { - r_return_val_if_fail (x, -1); +RZ_API int rz_sandbox_system(const char *x, int n) { + rz_return_val_if_fail (x, -1); if (enabled) { eprintf ("sandbox: system call disabled\n"); return -1; @@ -217,9 +217,9 @@ R_API int r_sandbox_system(const char *x, int n) { #include int argc; char *cmd = strdup (x); - char **argv = r_str_argv (cmd, &argc); + char **argv = rz_str_argv (cmd, &argc); if (argv) { - char *argv0 = r_file_path (argv[0]); + char *argv0 = rz_file_path (argv[0]); pid_t pid = 0; int r = posix_spawn (&pid, argv0, NULL, NULL, argv, NULL); int status; @@ -241,9 +241,9 @@ R_API int r_sandbox_system(const char *x, int n) { if (isbg) { *isbg = 0; } - argv = r_str_argv (cmd, &argc); + argv = rz_str_argv (cmd, &argc); if (argv) { - char *argv0 = r_file_path (argv[0]); + char *argv0 = rz_file_path (argv[0]); if (!argv0) { eprintf ("Cannot find '%s'\n", argv[0]); return -1; @@ -256,7 +256,7 @@ R_API int r_sandbox_system(const char *x, int n) { } else { rc = waitpid (pid, NULL, 0); } - r_str_argv_free (argv); + rz_str_argv_free (argv); free (argv0); return rc; } @@ -279,13 +279,13 @@ R_API int r_sandbox_system(const char *x, int n) { return -1; } -R_API bool r_sandbox_creat (const char *path, int mode) { +RZ_API bool rz_sandbox_creat (const char *path, int mode) { if (enabled) { return false; #if 0 if (mode & O_CREAT) return -1; if (mode & O_RDWR) return -1; - if (!r_sandbox_check_path (path)) + if (!rz_sandbox_check_path (path)) return -1; #endif } @@ -298,17 +298,17 @@ R_API bool r_sandbox_creat (const char *path, int mode) { } static inline char *expand_home(const char *p) { - return (*p == '~')? r_str_home (p): strdup (p); + return (*p == '~')? rz_str_home (p): strdup (p); } -R_API int r_sandbox_lseek(int fd, ut64 addr, int whence) { +RZ_API int rz_sandbox_lseek(int fd, ut64 addr, int whence) { if (enabled) { return -1; } return lseek (fd, (off_t)addr, whence); } -R_API int r_sandbox_truncate(int fd, ut64 length) { +RZ_API int rz_sandbox_truncate(int fd, ut64 length) { if (enabled) { return -1; } @@ -319,21 +319,21 @@ R_API int r_sandbox_truncate(int fd, ut64 length) { #endif } -R_API int r_sandbox_read(int fd, ut8 *buf, int len) { +RZ_API int rz_sandbox_read(int fd, ut8 *buf, int len) { return enabled? -1: read (fd, buf, len); } -R_API int r_sandbox_write(int fd, const ut8* buf, int len) { +RZ_API int rz_sandbox_write(int fd, const ut8* buf, int len) { return enabled? -1: write (fd, buf, len); } -R_API int r_sandbox_close(int fd) { +RZ_API int rz_sandbox_close(int fd) { return enabled? -1: close (fd); } /* perm <-> mode */ -R_API int r_sandbox_open(const char *path, int perm, int mode) { - r_return_val_if_fail (path, -1); +RZ_API int rz_sandbox_open(const char *path, int perm, int mode) { + rz_return_val_if_fail (path, -1); char *epath = expand_home (path); int ret = -1; #if __WINDOWS__ @@ -343,7 +343,7 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) { #endif if (enabled) { if ((perm & O_CREAT) || (perm & O_RDWR) - || (!r_sandbox_check_path (epath))) { + || (!rz_sandbox_check_path (epath))) { free (epath); return -1; } @@ -393,7 +393,7 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) { permission |= FILE_APPEND_DATA; } - wchar_t *wepath = r_utf8_to_utf16 (epath); + wchar_t *wepath = rz_utf8_to_utf16 (epath); if (!wepath) { free (epath); return -1; @@ -411,8 +411,8 @@ R_API int r_sandbox_open(const char *path, int perm, int mode) { return ret; } -R_API FILE *r_sandbox_fopen (const char *path, const char *mode) { - r_return_val_if_fail (path && mode, NULL); +RZ_API FILE *rz_sandbox_fopen (const char *path, const char *mode) { + rz_return_val_if_fail (path && mode, NULL); FILE *ret = NULL; char *epath = NULL; if (enabled) { @@ -420,7 +420,7 @@ R_API FILE *r_sandbox_fopen (const char *path, const char *mode) { return NULL; } epath = expand_home (path); - if (!r_sandbox_check_path (epath)) { + if (!rz_sandbox_check_path (epath)) { free (epath); return NULL; } @@ -428,14 +428,14 @@ R_API FILE *r_sandbox_fopen (const char *path, const char *mode) { if (!epath) { epath = expand_home (path); } - if ((strchr (mode, 'w') || strchr (mode, 'a') || r_file_is_regular (epath))) { + if ((strchr (mode, 'w') || strchr (mode, 'a') || rz_file_is_regular (epath))) { #if __WINDOWS__ - wchar_t *wepath = r_utf8_to_utf16 (epath); + wchar_t *wepath = rz_utf8_to_utf16 (epath); if (!wepath) { free (epath); return ret; } - wchar_t *wmode = r_utf8_to_utf16 (mode); + wchar_t *wmode = rz_utf8_to_utf16 (mode); if (!wmode) { free (wepath); free (epath); @@ -452,8 +452,8 @@ R_API FILE *r_sandbox_fopen (const char *path, const char *mode) { return ret; } -R_API int r_sandbox_chdir(const char *path) { - r_return_val_if_fail (path, -1); +RZ_API int rz_sandbox_chdir(const char *path) { + rz_return_val_if_fail (path, -1); if (enabled) { // TODO: check path if (strstr (path, "../")) { @@ -467,8 +467,8 @@ R_API int r_sandbox_chdir(const char *path) { return chdir (path); } -R_API int r_sandbox_kill(int pid, int sig) { - r_return_val_if_fail (pid != -1, -1); +RZ_API int rz_sandbox_kill(int pid, int sig) { + rz_return_val_if_fail (pid != -1, -1); // XXX: fine-tune. maybe we want to enable kill for child? if (enabled) { return -1; @@ -479,16 +479,16 @@ R_API int r_sandbox_kill(int pid, int sig) { return -1; } #if __WINDOWS__ -R_API HANDLE r_sandbox_opendir (const char *path, WIN32_FIND_DATAW *entry) { - r_return_val_if_fail (path, NULL); +RZ_API HANDLE rz_sandbox_opendir (const char *path, WIN32_FIND_DATAW *entry) { + rz_return_val_if_fail (path, NULL); wchar_t dir[MAX_PATH]; wchar_t *wcpath = 0; - if (r_sandbox_enable (0)) { - if (path && !r_sandbox_check_path (path)) { + if (rz_sandbox_enable (0)) { + if (path && !rz_sandbox_check_path (path)) { return NULL; } } - if (!(wcpath = r_utf8_to_utf16 (path))) { + if (!(wcpath = rz_utf8_to_utf16 (path))) { return NULL; } swprintf (dir, MAX_PATH, L"%ls\\*.*", wcpath); @@ -496,22 +496,22 @@ R_API HANDLE r_sandbox_opendir (const char *path, WIN32_FIND_DATAW *entry) { return FindFirstFileW (dir, entry); } #else -R_API DIR* r_sandbox_opendir (const char *path) { - r_return_val_if_fail (path, NULL); - if (r_sandbox_enable (0)) { - if (path && !r_sandbox_check_path (path)) { +RZ_API DIR* rz_sandbox_opendir (const char *path) { + rz_return_val_if_fail (path, NULL); + if (rz_sandbox_enable (0)) { + if (path && !rz_sandbox_check_path (path)) { return NULL; } } return opendir (path); } #endif -R_API bool r_sys_stop (void) { +RZ_API bool rz_sys_stop (void) { if (enabled) { return false; } #if __UNIX__ - return !r_sandbox_kill (0, SIGTSTP); + return !rz_sandbox_kill (0, SIGTSTP); #else return false; #endif diff --git a/libr/util/sdb.mk b/librz/util/sdb.mk similarity index 100% rename from libr/util/sdb.mk rename to librz/util/sdb.mk diff --git a/libr/util/seven.c b/librz/util/seven.c similarity index 87% rename from libr/util/seven.c rename to librz/util/seven.c index 6ad4f6ef7f..ff3cba21af 100644 --- a/libr/util/seven.c +++ b/librz/util/seven.c @@ -1,5 +1,5 @@ /* radare - LGPL - Copyright 2012-2013 - pancake */ -#include +#include #if 0 for(i=0; i +#include #include #include @@ -48,7 +48,7 @@ static struct { { NULL } }; -R_API int r_signal_from_string (const char *e) { +RZ_API int rz_signal_from_string (const char *e) { int i; for (i = 1; signals[i].name; i++) { const char *str = signals[i].name; @@ -59,7 +59,7 @@ R_API int r_signal_from_string (const char *e) { return atoi (e); } -R_API const char* r_signal_to_string (int code) { +RZ_API const char* rz_signal_to_string (int code) { int i; for (i = 1; signals[i].name; i++) { if (signals[i].code == code) { @@ -70,7 +70,7 @@ R_API const char* r_signal_to_string (int code) { } #if HAVE_PTHREAD -R_API void r_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask) { +RZ_API void rz_signal_sigmask(int how, const sigset_t *newmask, sigset_t *oldmask) { pthread_sigmask (how, newmask, oldmask); } #endif diff --git a/libr/util/skiplist.c b/librz/util/skiplist.c similarity index 64% rename from libr/util/skiplist.c rename to librz/util/skiplist.c index ba37a7daca..12a86d40a9 100644 --- a/libr/util/skiplist.c +++ b/librz/util/skiplist.c @@ -1,22 +1,22 @@ // (c) 2016 Jeffrey Crowell, Riccardo Schirone(ret2libc) // BSD 3 Clause License -// radare2 +// rizin // Skiplists are a probabilistic datastructure than can be used as a k-v store // with average case O(lg n) lookup time, and worst case O(n). // https://en.wikipedia.org/wiki/Skip_list -#include +#include #define SKIPLIST_MAX_DEPTH 31 -static RSkipListNode *r_skiplist_node_new (void *data, int level) { - RSkipListNode *res = R_NEW0 (RSkipListNode); +static RzSkipListNode *rz_skiplist_node_new (void *data, int level) { + RzSkipListNode *res = R_NEW0 (RzSkipListNode); if (!res) { return NULL; } - res->forward = R_NEWS0 (RSkipListNode *, level + 1); + res->forward = R_NEWS0 (RzSkipListNode *, level + 1); if (!res->forward) { free (res); return NULL; @@ -25,7 +25,7 @@ static RSkipListNode *r_skiplist_node_new (void *data, int level) { return res; } -static void r_skiplist_node_free (RSkipList *list, RSkipListNode *node) { +static void rz_skiplist_node_free (RzSkipList *list, RzSkipListNode *node) { if (node) { if (list->freefn && node->data) { list->freefn (node->data); @@ -35,7 +35,7 @@ static void r_skiplist_node_free (RSkipList *list, RSkipListNode *node) { } } -static void init_head (RSkipListNode *head) { +static void init_head (RzSkipListNode *head) { int i; for (i = 0; i <= SKIPLIST_MAX_DEPTH; i++) { head->forward[i] = head; @@ -48,8 +48,8 @@ static void init_head (RSkipListNode *head) { // // NOTE: `updates` should be big enough to contain `list->list_level + 1` // elements, when provided. -static RSkipListNode *find_insertpoint(RSkipList *list, void *data, RSkipListNode **updates, bool by_data) { - RSkipListNode *x = list->head; +static RzSkipListNode *find_insertpoint(RzSkipList *list, void *data, RzSkipListNode **updates, bool by_data) { + RzSkipListNode *x = list->head; int i; for (i = list->list_level; i >= 0; i--) { @@ -71,9 +71,9 @@ static RSkipListNode *find_insertpoint(RSkipList *list, void *data, RSkipListNod return x; } -static bool delete_element(RSkipList* list, void* data, bool by_data) { +static bool delete_element(RzSkipList* list, void* data, bool by_data) { int i; - RSkipListNode *update[SKIPLIST_MAX_DEPTH + 1], *x; + RzSkipListNode *update[SKIPLIST_MAX_DEPTH + 1], *x; // locate delete points in the lists of all levels x = find_insertpoint (list, data, update, by_data); @@ -90,7 +90,7 @@ static bool delete_element(RSkipList* list, void* data, bool by_data) { } update[i]->forward[i] = x->forward[i]; } - r_skiplist_node_free (list, x); + rz_skiplist_node_free (list, x); // update the level of the list while ((list->list_level > 0) && @@ -105,13 +105,13 @@ static bool delete_element(RSkipList* list, void* data, bool by_data) { // a function that returns 0 on equality between two elements, and -1 or 1 // when unequal (for sorting). // Returns a new heap-allocated skiplist. -R_API RSkipList* r_skiplist_new(RListFree freefn, RListComparator comparefn) { - RSkipList *list = R_NEW0 (RSkipList); +RZ_API RzSkipList* rz_skiplist_new(RzListFree freefn, RzListComparator comparefn) { + RzSkipList *list = R_NEW0 (RzSkipList); if (!list) { return NULL; } - list->head = r_skiplist_node_new (NULL, SKIPLIST_MAX_DEPTH); + list->head = rz_skiplist_node_new (NULL, SKIPLIST_MAX_DEPTH); if (!list->head) { free (list); return NULL; @@ -126,16 +126,16 @@ R_API RSkipList* r_skiplist_new(RListFree freefn, RListComparator comparefn) { } // Remove all elements from the list -R_API void r_skiplist_purge(RSkipList *list) { - RSkipListNode *n; +RZ_API void rz_skiplist_purge(RzSkipList *list) { + RzSkipListNode *n; if (!list) { return; } n = list->head->forward[0]; while (n != list->head) { - RSkipListNode *x = n; + RzSkipListNode *x = n; n = n->forward[0]; - r_skiplist_node_free (list, x); + rz_skiplist_node_free (list, x); } init_head (list->head); list->size = 0; @@ -143,20 +143,20 @@ R_API void r_skiplist_purge(RSkipList *list) { } // Free the entire list and it's element (if freefn is specified) -R_API void r_skiplist_free(RSkipList *list) { +RZ_API void rz_skiplist_free(RzSkipList *list) { if (!list) { return; } - r_skiplist_purge (list); - r_skiplist_node_free (list, list->head); + rz_skiplist_purge (list); + rz_skiplist_node_free (list, list->head); free (list); } // Inserts an element to the skiplist, and returns a pointer to the element's // node. -R_API RSkipListNode* r_skiplist_insert(RSkipList* list, void* data) { - RSkipListNode *update[SKIPLIST_MAX_DEPTH + 1]; - RSkipListNode *x; +RZ_API RzSkipListNode* rz_skiplist_insert(RzSkipList* list, void* data) { + RzSkipListNode *update[SKIPLIST_MAX_DEPTH + 1]; + RzSkipListNode *x; int i, x_level, new_level; // locate insertion points in the lists of all levels @@ -181,7 +181,7 @@ R_API RSkipListNode* r_skiplist_insert(RSkipList* list, void* data) { new_level = x_level; } - x = r_skiplist_node_new (data, x_level); + x = rz_skiplist_node_new (data, x_level); if (!x) { return NULL; } @@ -199,30 +199,30 @@ R_API RSkipListNode* r_skiplist_insert(RSkipList* list, void* data) { } // Delete node with data as it's payload. -R_API bool r_skiplist_delete(RSkipList* list, void* data) { +RZ_API bool rz_skiplist_delete(RzSkipList* list, void* data) { return delete_element (list, data, true); } -// Delete the given RSkipListNode from the skiplist -R_API bool r_skiplist_delete_node(RSkipList *list, RSkipListNode *node) { +// Delete the given RzSkipListNode from the skiplist +RZ_API bool rz_skiplist_delete_node(RzSkipList *list, RzSkipListNode *node) { return delete_element (list, node, false); } -R_API RSkipListNode* r_skiplist_find(RSkipList* list, void* data) { - RSkipListNode* x = find_insertpoint (list, data, NULL, true); +RZ_API RzSkipListNode* rz_skiplist_find(RzSkipList* list, void* data) { + RzSkipListNode* x = find_insertpoint (list, data, NULL, true); if (x != list->head && list->compare (x->data, data) == 0) { return x; } return NULL; } -R_API RSkipListNode* r_skiplist_find_geq(RSkipList* list, void* data) { - RSkipListNode* x = find_insertpoint (list, data, NULL, true); +RZ_API RzSkipListNode* rz_skiplist_find_geq(RzSkipList* list, void* data) { + RzSkipListNode* x = find_insertpoint (list, data, NULL, true); return x != list->head ? x : NULL; } -R_API RSkipListNode* r_skiplist_find_leq(RSkipList* list, void* data) { - RSkipListNode *x = list->head; +RZ_API RzSkipListNode* rz_skiplist_find_leq(RzSkipList* list, void* data) { + RzSkipListNode *x = list->head; int i; for (i = list->list_level; i >= 0; i--) { @@ -235,35 +235,35 @@ R_API RSkipListNode* r_skiplist_find_leq(RSkipList* list, void* data) { } // Move all the elements of `l2` in `l1`. -R_API void r_skiplist_join(RSkipList *l1, RSkipList *l2) { - RSkipListNode *it; +RZ_API void rz_skiplist_join(RzSkipList *l1, RzSkipList *l2) { + RzSkipListNode *it; void *data; - r_skiplist_foreach (l2, it, data) { - r_skiplist_insert (l1, data); + rz_skiplist_foreach (l2, it, data) { + rz_skiplist_insert (l1, data); } - r_skiplist_purge (l2); + rz_skiplist_purge (l2); } // Returns the first data element in the list, if present, NULL otherwise -R_API void *r_skiplist_get_first(RSkipList *list) { +RZ_API void *rz_skiplist_get_first(RzSkipList *list) { if (!list) { return NULL; } - RSkipListNode *res = list->head->forward[0]; + RzSkipListNode *res = list->head->forward[0]; return res == list->head ? NULL : res->data; } // Returns the nth data element in the list, if present, NULL otherwise -R_API void *r_skiplist_get_n(RSkipList *list, int n) { +RZ_API void *rz_skiplist_get_n(RzSkipList *list, int n) { int count = 0; - RSkipListNode *node; + RzSkipListNode *node; void *data; if (!list || n < 0) { return NULL; } - r_skiplist_foreach (list, node, data) { + rz_skiplist_foreach (list, node, data) { if (count == n) { return data; } @@ -273,32 +273,32 @@ R_API void *r_skiplist_get_n(RSkipList *list, int n) { } -R_API void* r_skiplist_get_geq(RSkipList* list, void* data) { - RSkipListNode *x = r_skiplist_find_geq (list, data); +RZ_API void* rz_skiplist_get_geq(RzSkipList* list, void* data) { + RzSkipListNode *x = rz_skiplist_find_geq (list, data); return x ? x->data : NULL; } -R_API void* r_skiplist_get_leq(RSkipList* list, void* data) { - RSkipListNode *x = r_skiplist_find_leq (list, data); +RZ_API void* rz_skiplist_get_leq(RzSkipList* list, void* data) { + RzSkipListNode *x = rz_skiplist_find_leq (list, data); return x ? x->data : NULL; } // Return true if the list is empty -R_API bool r_skiplist_empty(RSkipList *list) { +RZ_API bool rz_skiplist_empty(RzSkipList *list) { return list->size == 0; } -// Return a new allocated RList representing the given `list` +// Return a new allocated RzList representing the given `list` // // NOTE: the data will be shared between the two lists. The user of this // function should choose which list will "own" the data pointers. -R_API RList *r_skiplist_to_list(RSkipList *list) { - RList *res = r_list_new (); - RSkipListNode *n; +RZ_API RzList *rz_skiplist_to_list(RzSkipList *list) { + RzList *res = rz_list_new (); + RzSkipListNode *n; void *data; - r_skiplist_foreach (list, n, data) { - r_list_append (res, data); + rz_skiplist_foreach (list, n, data) { + rz_list_append (res, data); } return res; diff --git a/librz/util/spaces.c b/librz/util/spaces.c new file mode 100644 index 0000000000..37c0be6654 --- /dev/null +++ b/librz/util/spaces.c @@ -0,0 +1,227 @@ +/* radare - LGPL - Copyright 2019 - pancake, ret2libc */ + +#include "rz_util/rz_spaces.h" + +RZ_API RSpaces *rz_spaces_new(const char *name) { + RSpaces *sp = R_NEW0 (RSpaces); + if (!sp || !rz_spaces_init (sp, name)) { + free (sp); + return NULL; + } + return sp; +} + +RZ_API bool rz_spaces_init(RSpaces *sp, const char *name) { + rz_return_val_if_fail (sp && name, false); + sp->name = strdup (name); + if (!sp->name) { + goto fail; + } + + sp->spaces = NULL; + sp->current = NULL; + sp->spacestack = rz_list_new (); + if (!sp->spacestack) { + goto fail; + } + + sp->event = rz_event_new (sp); + if (!sp->event) { + goto fail; + } + + return true; + +fail: + rz_spaces_fini (sp); + return false; +} + +RZ_API void rz_spaces_free(RSpaces *sp) { + rz_spaces_fini (sp); + free (sp); +} + +static inline void space_free(RSpace *s) { + if (s) { + free (s->name); + free (s); + } +} + +static void space_node_free(RBNode *n, void *user) { + RSpace *s = container_of (n, RSpace, rb); + space_free (s); +} + +RZ_API void rz_spaces_fini(RSpaces *sp) { + rz_list_free (sp->spacestack); + sp->spacestack = NULL; + rz_rbtree_free (sp->spaces, space_node_free, NULL); + sp->spaces = NULL; + rz_event_free (sp->event); + sp->event = NULL; + sp->current = NULL; + R_FREE (sp->name); +} + +RZ_API void rz_spaces_purge(RSpaces *sp) { + sp->current = NULL; + rz_list_purge (sp->spacestack); + rz_rbtree_free (sp->spaces, space_node_free, NULL); + sp->spaces = NULL; +} + +static int name_space_cmp(const void *incoming, const RBNode *rb, void *user) { + const RSpace *s = container_of (rb, const RSpace, rb); + return strcmp (incoming, s->name); +} + +RZ_API RSpace *rz_spaces_get(RSpaces *sp, const char *name) { + if (!name) { + return NULL; + } + RBNode *n = rz_rbtree_find (sp->spaces, (void *)name, name_space_cmp, NULL); + return n? container_of (n, RSpace, rb): NULL; +} + +static int space_cmp(const void *incoming, const RBNode *rb, void *user) { + const RSpace *a = (const RSpace *)incoming; + const RSpace *b = container_of (rb, const RSpace, rb); + return strcmp (a->name, b->name); +} + +RZ_API RSpace *rz_spaces_add(RSpaces *sp, const char *name) { + rz_return_val_if_fail (sp, NULL); + if (!name || !*name || *name == '*') { + return NULL; + } + + RSpace *s = rz_spaces_get (sp, name); + if (s) { + return s; + } + + s = R_NEW0 (RSpace); + if (!s) { + return NULL; + } + + s->name = strdup (name); + if (!s->name) { + free (s); + return NULL; + } + + rz_rbtree_insert (&sp->spaces, s, &s->rb, space_cmp, NULL); + return s; +} + +RZ_API RSpace *rz_spaces_set(RSpaces *sp, const char *name) { + sp->current = rz_spaces_add (sp, name); + return sp->current; +} + +static inline bool spaces_unset_single(RSpaces *sp, const char *name) { + RSpace *space = rz_spaces_get (sp, name); + if (!space) { + return false; + } + + RSpaceEvent ev = { .data.unset.space = space }; + rz_event_send (sp->event, R_SPACE_EVENT_UNSET, &ev); + if (sp->current == space) { + sp->current = NULL; + } + return rz_rbtree_delete (&sp->spaces, (void *)name, name_space_cmp, NULL, space_node_free, NULL); +} + +RZ_API bool rz_spaces_unset(RSpaces *sp, const char *name) { + if (name) { + return spaces_unset_single (sp, name); + } + + RzList *names = rz_list_newf ((RzListFree)free); + if (!names) { + return false; + } + + RBIter it; + RSpace *s; + rz_spaces_foreach (sp, it, s) { + rz_list_append (names, strdup (s->name)); + } + + RzListIter *lit; + const char *n; + bool res = false; + rz_list_foreach (names, lit, n) { + res |= spaces_unset_single (sp, n); + } + rz_list_free (names); + return res; +} + +RZ_API int rz_spaces_count(RSpaces *sp, const char *name) { + RSpace *s = rz_spaces_get (sp, name); + if (!s) { + return 0; + } + RSpaceEvent ev = { .data.count.space = s, .res = 0 }; + rz_event_send (sp->event, R_SPACE_EVENT_COUNT, &ev); + return ev.res; +} + +RZ_API bool rz_spaces_push(RSpaces *sp, const char *name) { + rz_return_val_if_fail (sp, false); + + rz_list_push (sp->spacestack, sp->current? sp->current->name: "*"); + rz_spaces_set (sp, name); + return true; +} + +RZ_API bool rz_spaces_pop(RSpaces *sp) { + char *name = rz_list_pop (sp->spacestack); + if (!name) { + return false; + } + + RSpace *s = rz_spaces_get (sp, name); + rz_spaces_set (sp, s? s->name: NULL); + return true; +} + +RZ_API bool rz_spaces_rename(RSpaces *sp, const char *oname, const char *nname) { + if (!oname && !sp->current) { + return false; + } + + RSpace *s; + if (oname) { + s = rz_spaces_get (sp, oname); + if (!s) { + return false; + } + } else { + s = sp->current; + } + + RSpace *sn = rz_spaces_get (sp, nname); + if (sn) { + return false; + } + + RSpaceEvent ev = { + .data.rename.oldname = s->name, + .data.rename.newname = nname, + .data.rename.space = s + }; + rz_event_send (sp->event, R_SPACE_EVENT_RENAME, &ev); + + rz_rbtree_delete (&sp->spaces, (void *)s->name, name_space_cmp, NULL, NULL, NULL); + free (s->name); + s->name = strdup (nname); + rz_rbtree_insert (&sp->spaces, s, &s->rb, space_cmp, NULL); + + return true; +} diff --git a/libr/util/spp.mk b/librz/util/spp.mk similarity index 100% rename from libr/util/spp.mk rename to librz/util/spp.mk diff --git a/libr/util/stack.c b/librz/util/stack.c similarity index 66% rename from libr/util/stack.c rename to librz/util/stack.c index 2e77a60a94..cd64e1d4b8 100644 --- a/libr/util/stack.c +++ b/librz/util/stack.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2007-2020 - ret2libc */ -#include +#include -R_API RStack *r_stack_new(ut32 n) { +RZ_API RStack *rz_stack_new(ut32 n) { RStack *s = R_NEW0 (RStack); if (!s) { return NULL; @@ -17,15 +17,15 @@ R_API RStack *r_stack_new(ut32 n) { return s; } -R_API RStack *r_stack_newf(ut32 n, RStackFree f) { - RStack *s = r_stack_new (n); +RZ_API RStack *rz_stack_newf(ut32 n, RStackFree f) { + RStack *s = rz_stack_new (n); if (s) { s->free = f; } return s; } -R_API void r_stack_free(RStack *s) { +RZ_API void rz_stack_free(RStack *s) { if (s) { if (s->free) { int i; @@ -38,7 +38,7 @@ R_API void r_stack_free(RStack *s) { } } -R_API bool r_stack_push(RStack *s, void *el) { +RZ_API bool rz_stack_push(RStack *s, void *el) { if (s->top == s->n_elems - 1) { /* reallocate the stack */ s->n_elems *= 2; @@ -55,7 +55,7 @@ R_API bool r_stack_push(RStack *s, void *el) { } //the caller should be take care of the object returned -R_API void *r_stack_pop(RStack *s) { +RZ_API void *rz_stack_pop(RStack *s) { if (s->top == -1) { return NULL; } @@ -64,14 +64,14 @@ R_API void *r_stack_pop(RStack *s) { return res; } -R_API bool r_stack_is_empty(RStack *s) { +RZ_API bool rz_stack_is_empty(RStack *s) { return s->top == -1; } -R_API size_t r_stack_size(RStack *s) { +RZ_API size_t rz_stack_size(RStack *s) { return (size_t)(s->top + 1); } -R_API void *r_stack_peek(RStack *s) { - return r_stack_is_empty (s)? NULL: s->elems[s->top]; +RZ_API void *rz_stack_peek(RStack *s) { + return rz_stack_is_empty (s)? NULL: s->elems[s->top]; } diff --git a/libr/util/str.c b/librz/util/str.c similarity index 77% rename from libr/util/str.c rename to librz/util/str.c index 08641c98dd..688252a097 100644 --- a/libr/util/str.c +++ b/librz/util/str.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2007-2019 - pancake */ -#include "r_types.h" -#include "r_util.h" -#include "r_cons.h" -#include "r_bin.h" +#include "rz_types.h" +#include "rz_util.h" +#include "rz_cons.h" +#include "rz_bin.h" #include #include #include @@ -33,7 +33,7 @@ static const char *rwxstr[] = { [15] = "rwx", }; -R_API int r_str_casecmp(const char *s1, const char *s2) { +RZ_API int rz_str_casecmp(const char *s1, const char *s2) { #ifdef _MSC_VER return stricmp (s1, s2); #else @@ -41,7 +41,7 @@ R_API int r_str_casecmp(const char *s1, const char *s2) { #endif } -R_API int r_str_ncasecmp(const char *s1, const char *s2, size_t n) { +RZ_API int rz_str_ncasecmp(const char *s1, const char *s2, size_t n) { #ifdef _MSC_VER return _strnicmp (s1, s2, n); #else @@ -51,7 +51,7 @@ R_API int r_str_ncasecmp(const char *s1, const char *s2, size_t n) { // GOOD // In-place replace the first instance of the character a, with the character b. -R_API int r_str_replace_ch(char *s, char a, char b, bool global) { +RZ_API int rz_str_replace_ch(char *s, char a, char b, bool global) { int ret = 0; char *o = s; if (!s || a == b) { @@ -77,15 +77,15 @@ R_API int r_str_replace_ch(char *s, char a, char b, bool global) { return ret; } -R_API int r_str_replace_char_once(char *s, int a, int b) { - return r_str_replace_ch (s, a, b, false); +RZ_API int rz_str_replace_char_once(char *s, int a, int b) { + return rz_str_replace_ch (s, a, b, false); } -R_API int r_str_replace_char(char *s, int a, int b) { - return r_str_replace_ch (s, a, b, true); +RZ_API int rz_str_replace_char(char *s, int a, int b) { + return rz_str_replace_ch (s, a, b, true); } -R_API void r_str_remove_char(char *str, char c) { +RZ_API void rz_str_remove_char(char *str, char c) { while (*str) { if (*str == c) { memmove (str, str + 1, strlen (str + 1) + 1); @@ -95,7 +95,7 @@ R_API void r_str_remove_char(char *str, char c) { } } -R_API void r_str_reverse(char *str) { +RZ_API void rz_str_reverse(char *str) { int i, len = strlen (str); int half = len / 2; for (i = 0; i < half; i++) { @@ -107,7 +107,7 @@ R_API void r_str_reverse(char *str) { // TODO: do not use toupper.. must support modes to also append lowercase chars like in r1 // TODO: this functions needs some stabilization -R_API int r_str_bits(char *strout, const ut8 *buf, int len, const char *bitz) { +RZ_API int rz_str_bits(char *strout, const ut8 *buf, int len, const char *bitz) { int i, j, idx; if (bitz) { for (i = j = 0; i= 0; i--) { @@ -175,10 +175,10 @@ R_API int r_str_bits64(char* strout, ut64 in) { } /** - * function: r_str_bits_from_num + * function: rz_str_bits_from_num * */ -R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz) { +RZ_API ut64 rz_str_bits_from_string(const char *buf, const char *bitz) { ut64 out = 0LL; /* return the numeric value associated to a string (rflags) */ for (; *buf; buf++) { @@ -196,7 +196,7 @@ R_API ut64 r_str_bits_from_string(const char *buf, const char *bitz) { return out; } -R_API int r_str_binstr2bin(const char *str, ut8 *out, int outlen) { +RZ_API int rz_str_binstr2bin(const char *str, ut8 *out, int outlen) { int n, i, j, k, ret, len; len = strlen (str); for (n = i = 0; i < len; i += 8) { @@ -230,7 +230,7 @@ R_API int r_str_binstr2bin(const char *str, ut8 *out, int outlen) { // Returns the permissions as in integer given an input in the form of rwx, rx, // etc. -R_API int r_str_rwx(const char *str) { +RZ_API int rz_str_rwx(const char *str) { int ret = atoi (str); if (!ret) { ret |= strchr (str, 'm') ? 16 : 0; @@ -244,7 +244,7 @@ R_API int r_str_rwx(const char *str) { } // Returns the string representation of the permission of the inputted integer. -R_API const char *r_str_rwx_i(int rwx) { +RZ_API const char *rz_str_rwx_i(int rwx) { if (rwx < 0 || rwx >= R_ARRAY_SIZE (rwxstr)) { rwx = 0; } @@ -253,7 +253,7 @@ R_API const char *r_str_rwx_i(int rwx) { // If up is true, upcase all characters in the string, otherwise downcase all // characters in the string. -R_API void r_str_case(char *str, bool up) { +RZ_API void rz_str_case(char *str, bool up) { if (up) { char oc = 0; for (; *str; oc = *str++) { @@ -266,11 +266,11 @@ R_API void r_str_case(char *str, bool up) { } } -R_API char *r_str_home(const char *str) { - char *dst, *home = r_sys_getenv (R_SYS_HOME); +RZ_API char *rz_str_home(const char *str) { + char *dst, *home = rz_sys_getenv (R_SYS_HOME); size_t length; if (!home) { - home = r_file_tmpdir (); + home = rz_file_tmpdir (); if (!home) { return NULL; } @@ -294,12 +294,12 @@ fail: return dst; } -R_API char *r_str_r2_prefix(const char *str) { - return r_str_newf ("%s%s%s", r_sys_prefix (NULL), R_SYS_DIR, str); +RZ_API char *rz_str_rz_prefix(const char *str) { + return rz_str_newf ("%s%s%s", rz_sys_prefix (NULL), R_SYS_DIR, str); } // Compute a 64 bit DJB hash of a string. -R_API ut64 r_str_hash64(const char *s) { +RZ_API ut64 rz_str_hash64(const char *s) { ut64 len, h = 5381; if (!s) { return 0; @@ -311,11 +311,11 @@ R_API ut64 r_str_hash64(const char *s) { } // Compute a 32bit DJB hash of a string. -R_API ut32 r_str_hash(const char *s) { - return (ut32) r_str_hash64 (s); +RZ_API ut32 rz_str_hash(const char *s) { + return (ut32) rz_str_hash64 (s); } -R_API int r_str_delta(char *p, char a, char b) { +RZ_API int rz_str_delta(char *p, char a, char b) { char *_a = strchr (p, a); char *_b = strchr (p, b); return (!_a || !_b)? 0 : (_a - _b); @@ -323,9 +323,9 @@ R_API int r_str_delta(char *p, char a, char b) { // In-place split string using ch as a delimiter. Replaces all instances of ch // with a null byte. Returns the number of split strings. For example -// r_str_split("hello world", ' ') will replace the space with '\0' and +// rz_str_split("hello world", ' ') will replace the space with '\0' and // return 2. -R_API int r_str_split(char *str, char ch) { +RZ_API int rz_str_split(char *str, char ch) { int i; char *p; if (!str || !*str) { @@ -345,7 +345,7 @@ R_API int r_str_split(char *str, char ch) { // And the last by \0\0 // Separates by words and skip spaces. // Returns the number of tokens that the string is tokenized into. -R_API int r_str_word_set0(char *str) { +RZ_API int rz_str_word_set0(char *str) { int i, quote = 0; char *p; if (!str || !*str) { @@ -393,7 +393,7 @@ R_API int r_str_word_set0(char *str) { return i; } -R_API int r_str_word_set0_stack(char *str) { +RZ_API int rz_str_word_set0_stack(char *str) { int i; char *p, *q; RStack *s; @@ -413,7 +413,7 @@ R_API int r_str_word_set0_stack(char *str) { if (str[i] == ' ') { str[i] = 0; } - s = r_stack_new (5); //Some random number + s = rz_stack_new (5); //Some random number for (i = 1, p = str; *p; p++) { q = p - 1; if (p > str && (*q == '\\')) { @@ -425,22 +425,22 @@ R_API int r_str_word_set0_stack(char *str) { case '(': case '{': case '[': - r_stack_push (s, (void *)p); + rz_stack_push (s, (void *)p); continue; case '\'': case '"': - pop = r_stack_pop (s); + pop = rz_stack_pop (s); if (pop && *(char *)pop != *p) { - r_stack_push (s, pop); - r_stack_push (s, (void *)p); + rz_stack_push (s, pop); + rz_stack_push (s, (void *)p); } else if (!pop) { - r_stack_push (s, (void *)p); + rz_stack_push (s, (void *)p); } continue; case ')': case '}': case ']': - pop = r_stack_pop (s); + pop = rz_stack_pop (s); if (pop) { if ((*(char *)pop == '(' && *p == ')') || (*(char *)pop == '{' && *p == '}') || @@ -458,7 +458,7 @@ R_API int r_str_word_set0_stack(char *str) { } p--; } - if (r_stack_is_empty (s)) { + if (rz_stack_is_empty (s)) { i++; *p = '\0'; } @@ -466,11 +466,11 @@ R_API int r_str_word_set0_stack(char *str) { break; } } - r_stack_free (s); + rz_stack_free (s); return i; } -R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen) { +RZ_API char *rz_str_word_get0set(char *stra, int stralen, int idx, const char *newstr, int *newlen) { char *p = NULL; char *out; int alen, blen, nlen; @@ -478,7 +478,7 @@ R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *new return NULL; } if (stra) { - p = (char *)r_str_word_get0 (stra, idx); + p = (char *)rz_str_word_get0 (stra, idx); } if (!p) { int nslen = strlen (newstr); @@ -520,7 +520,7 @@ R_API char *r_str_word_get0set(char *stra, int stralen, int idx, const char *new // Get the idx'th entry of a tokenized string. // XXX: Warning! this function is UNSAFE, check that the string has, at least, // idx+1 tokens. -R_API const char *r_str_word_get0(const char *str, int idx) { +RZ_API const char *rz_str_word_get0(const char *str, int idx) { int i; const char *ptr = str; if (!ptr || idx < 0 /* prevent crashes with negative index */) { @@ -533,7 +533,7 @@ R_API const char *r_str_word_get0(const char *str, int idx) { } // Return the number of times that the character ch appears in the string. -R_API int r_str_char_count(const char *string, char ch) { +RZ_API int rz_str_char_count(const char *string, char ch) { int i, count = 0; for (i = 0; string[i]; i++) { if (string[i] == ch) { @@ -544,8 +544,8 @@ R_API int r_str_char_count(const char *string, char ch) { } // Counts the number of words (separated by separator characters: newlines, tabs, -// return, space). See r_util.h for more details of the IS_SEPARATOR macro. -R_API int r_str_word_count(const char *string) { +// return, space). See rz_util.h for more details of the IS_SEPARATOR macro. +RZ_API int rz_str_word_count(const char *string) { const char *text, *tmp; int word; @@ -568,7 +568,7 @@ R_API int r_str_word_count(const char *string) { // TODO: make this const-correct. // XXX if the string is only made up of chr, then the pointer will just point to // a null byte! -R_API char *r_str_ichr(char *str, char chr) { +RZ_API char *rz_str_ichr(char *str, char chr) { while (*str == chr) { str++; } @@ -577,7 +577,7 @@ R_API char *r_str_ichr(char *str, char chr) { // Returns a pointer to the last instance of the character chr in the input // string. -R_API const char *r_str_lchr(const char *str, char chr) { +RZ_API const char *rz_str_lchr(const char *str, char chr) { if (str) { int len = strlen (str); for (; len >= 0; len--) { @@ -590,7 +590,7 @@ R_API const char *r_str_lchr(const char *str, char chr) { } /* find the last char chr in the substring str[start:end] with end not included */ -R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr) { +RZ_API const char *rz_sub_str_lchr(const char *str, int start, int end, char chr) { do { end--; } while (str[end] != chr && end >= start); @@ -598,14 +598,14 @@ R_API const char *r_sub_str_lchr(const char *str, int start, int end, char chr) } /* find the first char chr in the substring str[start:end] with end not included */ -R_API const char *r_sub_str_rchr(const char *str, int start, int end, char chr) { +RZ_API const char *rz_sub_str_rchr(const char *str, int start, int end, char chr) { while (str[start] != chr && start < end) { start++; } return str[start] == chr ? str + start : NULL; } -R_API const char *r_str_sep(const char *base, const char *sep) { +RZ_API const char *rz_str_sep(const char *base, const char *sep) { int i; while (*base) { for (i = 0; sep[i]; i++) { @@ -618,7 +618,7 @@ R_API const char *r_str_sep(const char *base, const char *sep) { return NULL; } -R_API const char *r_str_rsep(const char *base, const char *p, const char *sep) { +RZ_API const char *rz_str_rsep(const char *base, const char *p, const char *sep) { int i; while (p >= base) { for (i = 0; sep[i]; i++) { @@ -631,11 +631,11 @@ R_API const char *r_str_rsep(const char *base, const char *p, const char *sep) { return NULL; } -R_API const char *r_str_rstr(const char *base, const char *p) { +RZ_API const char *rz_str_rstr(const char *base, const char *p) { char *s = strdup (base); char *k = strdup (p); - r_str_reverse (s); - r_str_reverse (k); + rz_str_reverse (s); + rz_str_reverse (k); char *q = strstr (s, k); const char *r = NULL; if (q) { @@ -646,8 +646,8 @@ R_API const char *r_str_rstr(const char *base, const char *p) { return r; } -R_API const char *r_str_rchr(const char *base, const char *p, int ch) { - r_return_val_if_fail (base, NULL); +RZ_API const char *rz_str_rchr(const char *base, const char *p, int ch) { + rz_return_val_if_fail (base, NULL); if (!p) { return strrchr (base, ch); } @@ -659,7 +659,7 @@ R_API const char *r_str_rchr(const char *base, const char *p, int ch) { return (p >= base) ? p: NULL; } -R_API const char *r_str_nstr(const char *s, const char *find, int slen) { +RZ_API const char *rz_str_nstr(const char *s, const char *find, int slen) { char c, sc; size_t len; @@ -681,14 +681,14 @@ R_API const char *r_str_nstr(const char *s, const char *find, int slen) { } // Returns a new heap-allocated copy of str. -// XXX what's the diff with r_str_dup ? -R_API char *r_str_new(const char *str) { +// XXX what's the diff with rz_str_dup ? +RZ_API char *rz_str_new(const char *str) { return str? strdup (str): NULL; } // Returns a new heap-allocated copy of str, sets str[len] to '\0'. // If the input str is longer than len, it will be truncated. -R_API char *r_str_newlen(const char *str, int len) { +RZ_API char *rz_str_newlen(const char *str, int len) { if (len < 1) { return NULL; } @@ -700,21 +700,21 @@ R_API char *r_str_newlen(const char *str, int len) { return buf; } -R_API char *r_str_trunc_ellipsis(const char *str, int len) { +RZ_API char *rz_str_trunc_ellipsis(const char *str, int len) { if (!str) { return NULL; } if (strlen (str) < len) { return strdup (str); } - char *buf = r_str_newlen (str, len); + char *buf = rz_str_newlen (str, len); if (buf && len > 4) { strcpy (buf + len - 4, "..."); } return buf; } -R_API char *r_str_newf(const char *fmt, ...) { +RZ_API char *rz_str_newf(const char *fmt, ...) { va_list ap, ap2; va_start (ap, fmt); @@ -735,7 +735,7 @@ R_API char *r_str_newf(const char *fmt, ...) { } // Secure string copy with null terminator (like strlcpy or strscpy but ours -R_API void r_str_ncpy(char *dst, const char *src, size_t n) { +RZ_API void rz_str_ncpy(char *dst, const char *src, size_t n) { int i; // do not do anything if n is 0 @@ -752,7 +752,7 @@ R_API void r_str_ncpy(char *dst, const char *src, size_t n) { /* memccmp("foo.bar", "foo.cow, '.') == 0 */ // Returns 1 if src and dst are equal up until the first instance of ch in src. -R_API bool r_str_ccmp(const char *dst, const char *src, int ch) { +RZ_API bool rz_str_ccmp(const char *dst, const char *src, int ch) { int i; for (i = 0; src[i] && src[i] != ch; i++) { if (dst[i] != src[i]) { @@ -763,7 +763,7 @@ R_API bool r_str_ccmp(const char *dst, const char *src, int ch) { } // Returns true if item is in sep-separated list -R_API bool r_str_cmp_list(const char *list, const char *item, char sep) { +RZ_API bool rz_str_cmp_list(const char *list, const char *item, char sep) { if (!list || !item) { return false; } @@ -784,7 +784,7 @@ R_API bool r_str_cmp_list(const char *list, const char *item, char sep) { } // like strncmp, but checking for null pointers -R_API int r_str_cmp(const char *a, const char *b, int len) { +RZ_API int rz_str_cmp(const char *a, const char *b, int len) { if ((a == b) || (!a && !b)) { return 0; } @@ -801,7 +801,7 @@ R_API int r_str_cmp(const char *a, const char *b, int len) { } // Copies all characters from src to dst up until the character 'ch'. -R_API int r_str_ccpy(char *dst, char *src, int ch) { +RZ_API int rz_str_ccpy(char *dst, char *src, int ch) { int i; for (i = 0; src[i] && src[i] != ch; i++) { dst[i] = src[i]; @@ -810,22 +810,22 @@ R_API int r_str_ccpy(char *dst, char *src, int ch) { return i; } -R_API char *r_str_word_get_first(const char *text) { +RZ_API char *rz_str_word_get_first(const char *text) { for (; *text && IS_SEPARATOR (*text); text++) { ; } return strdup (text); } -R_API const char *r_str_get(const char *str) { +RZ_API const char *rz_str_get(const char *str) { return str? str: nullstr_c; } -R_API const char *r_str_get2(const char *str) { +RZ_API const char *rz_str_get2(const char *str) { return str? str: nullstr; } -R_API char *r_str_ndup(const char *ptr, int len) { +RZ_API char *rz_str_ndup(const char *ptr, int len) { if (len < 0) { return NULL; } @@ -839,12 +839,12 @@ R_API char *r_str_ndup(const char *ptr, int len) { } // TODO: deprecate? -R_API char *r_str_dup(char *ptr, const char *string) { +RZ_API char *rz_str_dup(char *ptr, const char *string) { free (ptr); - return r_str_new (string); + return rz_str_new (string); } -R_API char *r_str_prepend(char *ptr, const char *string) { +RZ_API char *rz_str_prepend(char *ptr, const char *string) { int slen, plen; if (!ptr) { return strdup (string); @@ -860,18 +860,18 @@ R_API char *r_str_prepend(char *ptr, const char *string) { return ptr; } -R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { - char *msg = r_str_newlen (string, slen); - char *ret = r_str_append (ptr, msg); +RZ_API char *rz_str_appendlen(char *ptr, const char *string, int slen) { + char *msg = rz_str_newlen (string, slen); + char *ret = rz_str_append (ptr, msg); free (msg); return ret; } -R_API char *r_str_append_owned(char *ptr, char *string) { +RZ_API char *rz_str_append_owned(char *ptr, char *string) { if (!ptr) { return string; } - char *r = r_str_append(ptr, string); + char *r = rz_str_append(ptr, string); free (string); return r; } @@ -879,7 +879,7 @@ R_API char *r_str_append_owned(char *ptr, char *string) { * first argument must be allocated * return: the pointer ptr resized to string size. */ -R_API char *r_str_append(char *ptr, const char *string) { +RZ_API char *rz_str_append(char *ptr, const char *string) { if (string && !ptr) { return strdup (string); } @@ -898,13 +898,13 @@ R_API char *r_str_append(char *ptr, const char *string) { return ptr; } -R_API char *r_str_appendf(char *ptr, const char *fmt, ...) { +RZ_API char *rz_str_appendf(char *ptr, const char *fmt, ...) { va_list ap, ap2; va_start (ap, fmt); if (!strchr (fmt, '%')) { va_end (ap); - return r_str_append (ptr, fmt); + return rz_str_append (ptr, fmt); } va_copy (ap2, ap); int ret = vsnprintf (NULL, 0, fmt, ap2); @@ -912,7 +912,7 @@ R_API char *r_str_appendf(char *ptr, const char *fmt, ...) { char *p = calloc (1, ret); if (p) { (void)vsnprintf (p, ret, fmt, ap); - ptr = r_str_append (ptr, p); + ptr = rz_str_append (ptr, p); free (p); } va_end (ap2); @@ -920,23 +920,23 @@ R_API char *r_str_appendf(char *ptr, const char *fmt, ...) { return ptr; } -R_API char *r_str_appendch(char *x, char y) { +RZ_API char *rz_str_appendch(char *x, char y) { char b[2] = { y, 0 }; - return r_str_append (x, b); + return rz_str_append (x, b); } -R_API char* r_str_replace(char *str, const char *key, const char *val, int g) { +RZ_API char* rz_str_replace(char *str, const char *key, const char *val, int g) { if (g == 'i') { - return r_str_replace_icase (str, key, val, g, true); + return rz_str_replace_icase (str, key, val, g, true); } - r_return_val_if_fail (str && key && val, NULL); + rz_return_val_if_fail (str && key && val, NULL); int off, i, slen; char *newstr, *p = str; int klen = strlen (key); int vlen = strlen (val); if (klen == 1 && vlen < 2) { - r_str_replace_char (str, *key, *val); + rz_str_replace_char (str, *key, *val); return str; } if (klen == vlen && !strcmp (key, val)) { @@ -975,8 +975,8 @@ R_API char* r_str_replace(char *str, const char *key, const char *val, int g) { return str; } -R_API char *r_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case) { - r_return_val_if_fail (str && key && val, NULL); +RZ_API char *rz_str_replace_icase(char *str, const char *key, const char *val, int g, int keep_case) { + rz_return_val_if_fail (str && key && val, NULL); int off, i, klen, vlen, slen; char *newstr, *p = str; @@ -985,7 +985,7 @@ R_API char *r_str_replace_icase(char *str, const char *key, const char *val, int slen = strlen (str); for (i = 0; i < slen;) { - p = (char *)r_str_casestr (str + i, key); + p = (char *)rz_str_casestr (str + i, key); if (!p) { break; } @@ -1006,13 +1006,13 @@ R_API char *r_str_replace_icase(char *str, const char *key, const char *val, int if (keep_case) { char *tmp_val = strdup (val); - char *str_case = r_str_ndup (p, klen); + char *str_case = rz_str_ndup (p, klen); if (!tmp_val || !str_case) { free (tmp_val); free (str_case); goto alloc_fail; } - tmp_val = r_str_replace_icase (tmp_val, key, str_case, 0, 0); + tmp_val = rz_str_replace_icase (tmp_val, key, str_case, 0, 0); free (str_case); if (!tmp_val) { goto alloc_fail; @@ -1048,7 +1048,7 @@ alloc_fail: * g - if true, replace all occurrences of key * * It returns a pointer to the modified string */ -R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, +RZ_API char* rz_str_replace_thunked(char *str, char *clean, int *thunk, int clen, const char *key, const char *val, int g) { int i, klen, vlen, slen, delta = 0, bias; char *newstr, *scnd, *p = clean, *str_p; @@ -1064,7 +1064,7 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, slen = strlen (str) + 1; for (i = 0; i < clen; ) { - p = (char *)r_mem_mem ( + p = (char *)rz_mem_mem ( (const ut8*)clean + i, clen - i, (const ut8*)key, klen); if (!p) { @@ -1076,7 +1076,7 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, str_p = str + thunk[i] + delta; int newo = thunk[i + klen] - thunk[i]; - r_str_ansi_filter (str_p, NULL, NULL, newo); + rz_str_ansi_filter (str_p, NULL, NULL, newo); scnd = strdup (str_p + newo); bias = vlen - newo; @@ -1103,11 +1103,11 @@ R_API char* r_str_replace_thunked(char *str, char *clean, int *thunk, int clen, return str; } -R_API char *r_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g) { +RZ_API char *rz_str_replace_in(char *str, ut32 sz, const char *key, const char *val, int g) { if (!str || !key || !val) { return NULL; } - char *heaped = r_str_replace (strdup (str), key, val, g); + char *heaped = rz_str_replace (strdup (str), key, val, g); if (heaped) { strncpy (str, heaped, sz); free (heaped); @@ -1115,7 +1115,7 @@ R_API char *r_str_replace_in(char *str, ut32 sz, const char *key, const char *va return str; } -R_API int r_str_unescape(char *buf) { +RZ_API int rz_str_unescape(char *buf) { unsigned char ch = 0, ch2 = 0; int err = 0; int i; @@ -1159,8 +1159,8 @@ R_API int r_str_unescape(char *buf) { eprintf ("Unexpected end of string.\n"); return 0; } - err |= r_hex_to_byte (&ch, buf[i + 2]); - err |= r_hex_to_byte (&ch2, buf[i + 3]); + err |= rz_hex_to_byte (&ch, buf[i + 2]); + err |= rz_hex_to_byte (&ch2, buf[i + 3]); if (err) { eprintf ("Error: Non-hexadecimal chars in input.\n"); return 0; // -1? @@ -1194,7 +1194,7 @@ R_API int r_str_unescape(char *buf) { return i; } -R_API void r_str_sanitize(char *c) { +RZ_API void rz_str_sanitize(char *c) { char *d = c; if (d) { for (; *d; c++, d++) { @@ -1218,7 +1218,7 @@ R_API void r_str_sanitize(char *c) { } } -R_API char *r_str_sanitize_sdb_key(const char *s) { +RZ_API char *rz_str_sanitize_sdb_key(const char *s) { if (!s || !*s) { return NULL; } @@ -1243,7 +1243,7 @@ R_API char *r_str_sanitize_sdb_key(const char *s) { return ret; } -R_API void r_str_byte_escape(const char *p, char **dst, int dot_nl, bool default_dot, bool esc_bslash) { +RZ_API void rz_str_byte_escape(const char *p, char **dst, int dot_nl, bool default_dot, bool esc_bslash) { char *q = *dst; switch (*p) { case '\n': @@ -1304,8 +1304,8 @@ R_API void r_str_byte_escape(const char *p, char **dst, int dot_nl, bool default /* Internal function. dot_nl specifies whether to convert \n into the * graphiz-compatible newline \l */ -static char *r_str_escape_(const char *buf, int dot_nl, bool parse_esc_seq, bool ign_esc_seq, bool show_asciidot, bool esc_bslash) { - r_return_val_if_fail (buf, NULL); +static char *rz_str_escape_(const char *buf, int dot_nl, bool parse_esc_seq, bool ign_esc_seq, bool show_asciidot, bool esc_bslash) { + rz_return_val_if_fail (buf, NULL); /* Worst case scenario, we convert every byte to a single-char escape * (e.g. \n) if show_asciidot, or \xhh if !show_asciidot */ @@ -1341,7 +1341,7 @@ static char *r_str_escape_(const char *buf, int dot_nl, bool parse_esc_seq, bool } /* fallthrough */ default: - r_str_byte_escape (p, &q, dot_nl, show_asciidot, esc_bslash); + rz_str_byte_escape (p, &q, dot_nl, show_asciidot, esc_bslash); } p++; } @@ -1350,13 +1350,13 @@ out: return new_buf; } -R_API char *r_str_escape(const char *buf) { - return r_str_escape_ (buf, false, true, true, false, true); +RZ_API char *rz_str_escape(const char *buf) { + return rz_str_escape_ (buf, false, true, true, false, true); } // Return MUST BE surrounded by double-quotes -R_API char *r_str_escape_sh(const char *buf) { - r_return_val_if_fail (buf, NULL); +RZ_API char *rz_str_escape_sh(const char *buf) { + rz_return_val_if_fail (buf, NULL); char *new_buf = malloc (1 + strlen (buf) * 2); if (!new_buf) { return NULL; @@ -1382,15 +1382,15 @@ R_API char *r_str_escape_sh(const char *buf) { return new_buf; } -R_API char *r_str_escape_dot(const char *buf) { - return r_str_escape_ (buf, true, true, true, false, true); +RZ_API char *rz_str_escape_dot(const char *buf) { + return rz_str_escape_ (buf, true, true, true, false, true); } -R_API char *r_str_escape_latin1(const char *buf, bool show_asciidot, bool esc_bslash, bool colors) { - return r_str_escape_ (buf, false, colors, !colors, show_asciidot, esc_bslash); +RZ_API char *rz_str_escape_latin1(const char *buf, bool show_asciidot, bool esc_bslash, bool colors) { + return rz_str_escape_ (buf, false, colors, !colors, show_asciidot, esc_bslash); } -static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool show_asciidot, bool esc_bslash, bool keep_printable) { +static char *rz_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool show_asciidot, bool esc_bslash, bool keep_printable) { char *new_buf, *q; const char *p, *end; RRune ch; @@ -1408,9 +1408,9 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s return NULL; } if (enc == R_STRING_ENC_UTF16LE || enc == R_STRING_ENC_UTF16BE) { - end = (char *)r_mem_mem_aligned ((ut8 *)buf, buf_size, (ut8 *)"\0\0", 2, 2); + end = (char *)rz_mem_mem_aligned ((ut8 *)buf, buf_size, (ut8 *)"\0\0", 2, 2); } else { - end = (char *)r_mem_mem_aligned ((ut8 *)buf, buf_size, (ut8 *)"\0\0\0\0", 4, 4); + end = (char *)rz_mem_mem_aligned ((ut8 *)buf, buf_size, (ut8 *)"\0\0\0\0", 4, 4); } if (!end) { end = buf + buf_size - 1; /* TODO: handle overlong strings properly */ @@ -1435,9 +1435,9 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s case R_STRING_ENC_UTF32LE: case R_STRING_ENC_UTF32BE: if (enc == R_STRING_ENC_UTF16LE || enc == R_STRING_ENC_UTF16BE) { - ch_bytes = r_utf16_decode ((ut8 *)p, end - p, &ch, enc == R_STRING_ENC_UTF16BE); + ch_bytes = rz_utf16_decode ((ut8 *)p, end - p, &ch, enc == R_STRING_ENC_UTF16BE); } else { - ch_bytes = r_utf32_decode ((ut8 *)p, end - p, &ch, enc == R_STRING_ENC_UTF32BE); + ch_bytes = rz_utf32_decode ((ut8 *)p, end - p, &ch, enc == R_STRING_ENC_UTF32BE); } if (ch_bytes == 0) { p++; @@ -1445,7 +1445,7 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s } break; default: - ch_bytes = r_utf8_decode ((ut8 *)p, end - p, &ch); + ch_bytes = rz_utf8_decode ((ut8 *)p, end - p, &ch); if (ch_bytes == 0) { ch_bytes = 1; } @@ -1454,7 +1454,7 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s *q++ = '.'; } else if (ch_bytes > 1) { if (keep_printable) { - q += r_utf8_encode ((ut8 *)q, ch); + q += rz_utf8_encode ((ut8 *)q, ch); } else { *q++ = '\\'; *q++ = ch_bytes == 4 ? 'U' : 'u'; @@ -1465,7 +1465,7 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s } } else { int offset = enc == R_STRING_ENC_UTF16BE ? 1 : enc == R_STRING_ENC_UTF32BE ? 3 : 0; - r_str_byte_escape (p + offset, &q, false, false, esc_bslash); + rz_str_byte_escape (p + offset, &q, false, false, esc_bslash); } switch (enc) { case R_STRING_ENC_UTF16LE: @@ -1484,33 +1484,33 @@ static char *r_str_escape_utf(const char *buf, int buf_size, RStrEnc enc, bool s return new_buf; } -R_API char *r_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, -1, R_STRING_ENC_UTF8, show_asciidot, esc_bslash, false); +RZ_API char *rz_str_escape_utf8(const char *buf, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, -1, R_STRING_ENC_UTF8, show_asciidot, esc_bslash, false); } -R_API char *r_str_escape_utf8_keep_printable(const char *buf, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, -1, R_STRING_ENC_UTF8, show_asciidot, esc_bslash, true); +RZ_API char *rz_str_escape_utf8_keep_printable(const char *buf, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, -1, R_STRING_ENC_UTF8, show_asciidot, esc_bslash, true); } -R_API char *r_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16LE, show_asciidot, esc_bslash, false); +RZ_API char *rz_str_escape_utf16le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16LE, show_asciidot, esc_bslash, false); } -R_API char *r_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32LE, show_asciidot, esc_bslash, false); +RZ_API char *rz_str_escape_utf32le(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32LE, show_asciidot, esc_bslash, false); } -R_API char *r_str_escape_utf16be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16BE, show_asciidot, esc_bslash, false); +RZ_API char *rz_str_escape_utf16be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF16BE, show_asciidot, esc_bslash, false); } -R_API char *r_str_escape_utf32be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { - return r_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32BE, show_asciidot, esc_bslash, false); +RZ_API char *rz_str_escape_utf32be(const char *buf, int buf_size, bool show_asciidot, bool esc_bslash) { + return rz_str_escape_utf (buf, buf_size, R_STRING_ENC_UTF32BE, show_asciidot, esc_bslash, false); } // JSON has special escaping requirements -// TODO: merge with r_str_escape_utf() and r_str_byte_escape() using RStrEsc -R_API char *r_str_escape_utf8_for_json(const char *buf, int buf_size) { +// TODO: merge with rz_str_escape_utf() and rz_str_byte_escape() using RStrEsc +RZ_API char *rz_str_escape_utf8_for_json(const char *buf, int buf_size) { char *new_buf, *q; const char *p, *end; RRune ch; @@ -1529,7 +1529,7 @@ R_API char *r_str_escape_utf8_for_json(const char *buf, int buf_size) { p = buf; q = new_buf; while (p < end) { - ch_bytes = r_utf8_decode ((ut8 *)p, end - p, &ch); + ch_bytes = rz_utf8_decode ((ut8 *)p, end - p, &ch); if (ch_bytes == 1) { switch (*p) { case '\n': @@ -1579,7 +1579,7 @@ R_API char *r_str_escape_utf8_for_json(const char *buf, int buf_size) { } } } else if (ch_bytes == 4) { - if (r_isprint (ch)) { + if (rz_isprint (ch)) { // Assumes buf is UTF8-encoded for (i = 0; i < ch_bytes; i++) { *q++ = *(p + i); @@ -1603,7 +1603,7 @@ R_API char *r_str_escape_utf8_for_json(const char *buf, int buf_size) { } } } else if (ch_bytes > 1) { - if (r_isprint (ch)) { + if (rz_isprint (ch)) { // Assumes buf is UTF8-encoded for (i = 0; i < ch_bytes; i++) { *q++ = *(p + i); @@ -1633,14 +1633,14 @@ R_API char *r_str_escape_utf8_for_json(const char *buf, int buf_size) { // http://daviddeley.com/autohotkey/parameters/parameters.htm#WINCRULES // https://docs.microsoft.com/en-us/cpp/cpp/main-function-command-line-args?redirectedfrom=MSDN&view=vs-2019#parsing-c-command-line-arguments -R_API char *r_str_format_msvc_argv(size_t argc, const char **argv) { +RZ_API char *rz_str_format_msvc_argv(size_t argc, const char **argv) { RStrBuf sb; - r_strbuf_init (&sb); + rz_strbuf_init (&sb); size_t i; for (i = 0; i < argc; i++) { if (i > 0) { - r_strbuf_append (&sb, " "); + rz_strbuf_append (&sb, " "); } const char *arg = argv[i]; bool must_escape = strchr (arg, '\"') != NULL; @@ -1650,7 +1650,7 @@ R_API char *r_str_format_msvc_argv(size_t argc, const char **argv) { must_escape = true; } if (must_quote) { - r_strbuf_append (&sb, "\""); + rz_strbuf_append (&sb, "\""); } if (must_escape) { size_t bs_count = 0; // bullshit counter @@ -1660,35 +1660,35 @@ R_API char *r_str_format_msvc_argv(size_t argc, const char **argv) { for (; bs_count; bs_count--) { // backslashes must be escaped iff they precede a " // so just duplicate the number of backslashes already printed - r_strbuf_append (&sb, "\\"); + rz_strbuf_append (&sb, "\\"); } - r_strbuf_append (&sb, "\\\""); + rz_strbuf_append (&sb, "\\\""); break; case '\\': bs_count++; - r_strbuf_append (&sb, "\\"); + rz_strbuf_append (&sb, "\\"); break; default: bs_count = 0; - r_strbuf_append_n (&sb, arg, 1); + rz_strbuf_append_n (&sb, arg, 1); break; } } if (must_quote) { // there will be a quote after this so we have to escape bs here as well for (; bs_count; bs_count--) { - r_strbuf_append (&sb, "\\"); + rz_strbuf_append (&sb, "\\"); } } } else { - r_strbuf_append (&sb, arg); + rz_strbuf_append (&sb, arg); } if (must_quote) { - r_strbuf_append (&sb, "\""); + rz_strbuf_append (&sb, "\""); } } - return r_strbuf_drain_nofree (&sb); + return rz_strbuf_drain_nofree (&sb); } static size_t __str_ansi_length(char const *str) { @@ -1712,7 +1712,7 @@ static size_t __str_ansi_length(char const *str) { } /* ansi helpers */ -R_API size_t r_str_ansi_nlen(const char *str, size_t slen) { +RZ_API size_t rz_str_ansi_nlen(const char *str, size_t slen) { size_t i = 0, len = 0; if (slen > 0) { while (str[i] && i < slen) { @@ -1734,11 +1734,11 @@ R_API size_t r_str_ansi_nlen(const char *str, size_t slen) { return len > 0 ? len: 1; } -R_API size_t r_str_ansi_len(const char *str) { - return r_str_ansi_nlen (str, 0); +RZ_API size_t rz_str_ansi_len(const char *str) { + return rz_str_ansi_nlen (str, 0); } -R_API size_t r_str_nlen(const char *str, int n) { +RZ_API size_t rz_str_nlen(const char *str, int n) { size_t len = 0; if (str) { while (*str && n > 0) { @@ -1752,7 +1752,7 @@ R_API size_t r_str_nlen(const char *str, int n) { //to handle wide string as well //XXX can be error prone -R_API size_t r_str_nlen_w(const char *str, int n) { +RZ_API size_t rz_str_nlen_w(const char *str, int n) { size_t len = 0; if (str) { while (*str && n > 0) { @@ -1774,7 +1774,7 @@ R_API size_t r_str_nlen_w(const char *str, int n) { return len; } -R_API bool r_str_is_ascii(const char *str) { +RZ_API bool rz_str_is_ascii(const char *str) { const ut8 *ptr; for (ptr = (const ut8 *)str; *ptr; ptr++) { if (*ptr > 0x7f) { @@ -1784,9 +1784,9 @@ R_API bool r_str_is_ascii(const char *str) { return true; } -R_API bool r_str_is_printable(const char *str) { +RZ_API bool rz_str_is_printable(const char *str) { while (*str) { - int ulen = r_utf8_decode ((const ut8*)str, strlen (str), NULL); + int ulen = rz_utf8_decode ((const ut8*)str, strlen (str), NULL); if (ulen > 1) { str += ulen; continue; @@ -1799,9 +1799,9 @@ R_API bool r_str_is_printable(const char *str) { return true; } -R_API bool r_str_is_printable_limited(const char *str, int size) { +RZ_API bool rz_str_is_printable_limited(const char *str, int size) { while (size > 0 && *str) { - int ulen = r_utf8_decode ((const ut8*)str, strlen (str), NULL); + int ulen = rz_utf8_decode ((const ut8*)str, strlen (str), NULL); if (ulen > 1) { str += ulen; continue; @@ -1815,9 +1815,9 @@ R_API bool r_str_is_printable_limited(const char *str, int size) { return true; } -R_API bool r_str_is_printable_incl_newlines(const char *str) { +RZ_API bool rz_str_is_printable_incl_newlines(const char *str) { while (*str) { - int ulen = r_utf8_decode ((const ut8*)str, strlen (str), NULL); + int ulen = rz_utf8_decode ((const ut8*)str, strlen (str), NULL); if (ulen > 1) { str += ulen; continue; @@ -1833,7 +1833,7 @@ R_API bool r_str_is_printable_incl_newlines(const char *str) { } // Length in chars of a wide string (find better name?) -R_API size_t r_wstr_clen(const char *s) { +RZ_API size_t rz_wstr_clen(const char *s) { size_t len = 0; if (!*s++) { return 0; @@ -1844,7 +1844,7 @@ R_API size_t r_wstr_clen(const char *s) { return len + 1; } -R_API const char *r_str_ansi_chrn(const char *str, size_t n) { +RZ_API const char *rz_str_ansi_chrn(const char *str, size_t n) { int len, i, li; for (li = i = len = 0; str[i] && (n != len); i++) { size_t chlen = __str_ansi_length (str + i); @@ -1870,7 +1870,7 @@ R_API const char *r_str_ansi_chrn(const char *str, size_t n) { * * it returns the number of normal characters found in str */ -R_API int r_str_ansi_filter(char *str, char **out, int **cposs, int len) { +RZ_API int rz_str_ansi_filter(char *str, char **out, int **cposs, int len) { int i, j, *cps; if (len == 0) { @@ -1920,10 +1920,10 @@ R_API int r_str_ansi_filter(char *str, char **out, int **cposs, int len) { return j; } -R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { - char *r, *r_end, *ret; +RZ_API char *rz_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { + char *r, *rz_end, *ret; const char *s, *s_start; - size_t r_len, str_len = 0, nr_of_lines = 0; + size_t rz_len, str_len = 0, nr_of_lines = 0; ut32 ch = 0, cw = 0; if (x2 <= x || y2 <= y || !str) { return strdup (""); @@ -1936,12 +1936,12 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { } s++; } - r_len = str_len + nr_of_lines * strlen (Color_RESET) + 1; - r = ret = malloc (r_len); + rz_len = str_len + nr_of_lines * strlen (Color_RESET) + 1; + r = ret = malloc (rz_len); if (!r) { return NULL; } - r_end = r + r_len; + rz_end = r + rz_len; while (*str) { /* crop height */ if (ch >= y2) { @@ -1951,7 +1951,7 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { if (*str == '\n') { if (ch >= y && ch < y2) { const char *reset = Color_RESET "\n"; - if (strlen (reset) < (r_end - r)) { + if (strlen (reset) < (rz_end - r)) { const int reset_length = strlen (reset); memcpy (r, reset, reset_length + 1); r += reset_length; @@ -1970,7 +1970,7 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { } continue; } - if (r_str_char_fullwidth (str, str_len - (str - s_start))) { + if (rz_str_char_fullwidth (str, str_len - (str - s_start))) { cw++; if (cw == x) { *r++ = ' '; @@ -1980,7 +1980,7 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { } if (*str == 0x1b && *(str + 1) == '[') { const char *ptr = str; - if ((r_end - r) > 2) { + if ((rz_end - r) > 2) { /* copy 0x1b and [ */ *r++ = *str++; *r++ = *str++; @@ -2010,7 +2010,7 @@ R_API char *r_str_ansi_crop(const char *str, ut32 x, ut32 y, ut32 x2, ut32 y2) { return ret; } -R_API size_t r_str_utf8_codepoint(const char* s, size_t left) { +RZ_API size_t rz_str_utf8_codepoint(const char* s, size_t left) { if ((*s & 0x80) != 0x80) { return 0; } else if ((*s & 0xe0) == 0xc0 && left >= 1) { @@ -2023,8 +2023,8 @@ R_API size_t r_str_utf8_codepoint(const char* s, size_t left) { return 0; } -R_API bool r_str_char_fullwidth (const char* s, size_t left) { - size_t codepoint = r_str_utf8_codepoint (s, left); +RZ_API bool rz_str_char_fullwidth (const char* s, size_t left) { + size_t codepoint = rz_str_utf8_codepoint (s, left); return (codepoint >= 0x1100 && (codepoint <= 0x115f || /* Hangul Jamo init. consonants */ codepoint == 0x2329 || codepoint == 0x232a || @@ -2046,8 +2046,8 @@ R_API bool r_str_char_fullwidth (const char* s, size_t left) { * Returns 1 in case of ASCII * str - Pointer to buffer */ -R_API size_t r_str_utf8_charsize(const char *str) { - r_return_val_if_fail (str, 0); +RZ_API size_t rz_str_utf8_charsize(const char *str) { + rz_return_val_if_fail (str, 0); size_t size = 0; size_t length = strlen (str); while (size < length && size < 5) { @@ -2065,8 +2065,8 @@ R_API size_t r_str_utf8_charsize(const char *str) { * str - Pointer to leading utf8 char * prev_len - Length in bytes of the buffer until str */ -R_API size_t r_str_utf8_charsize_prev(const char *str, int prev_len) { - r_return_val_if_fail (str, 0); +RZ_API size_t rz_str_utf8_charsize_prev(const char *str, int prev_len) { + rz_return_val_if_fail (str, 0); int pos = 0; size_t size = 0, minsize = R_MIN (5, prev_len); while (size < minsize) { @@ -2083,13 +2083,13 @@ R_API size_t r_str_utf8_charsize_prev(const char *str, int prev_len) { * Returns 1 in case of ASCII * str - Pointer to buffer */ -R_API size_t r_str_utf8_charsize_last(const char *str) { - r_return_val_if_fail (str, 0); +RZ_API size_t rz_str_utf8_charsize_last(const char *str) { + rz_return_val_if_fail (str, 0); size_t len = strlen (str); - return r_str_utf8_charsize_prev (str + len, len); + return rz_str_utf8_charsize_prev (str + len, len); } -R_API void r_str_filter_zeroline(char *str, int len) { +RZ_API void rz_str_filter_zeroline(char *str, int len) { int i; for (i = 0; i < len && str[i]; i++) { if (str[i] == '\n' || str[i] == '\r') { @@ -2102,7 +2102,7 @@ R_API void r_str_filter_zeroline(char *str, int len) { str[i] = 0; } -R_API void r_str_filter(char *str, int len) { +RZ_API void rz_str_filter(char *str, int len) { size_t i; if (len < 1) { len = strlen (str); @@ -2114,7 +2114,7 @@ R_API void r_str_filter(char *str, int len) { } } -R_API bool r_str_glob(const char* str, const char *glob) { +RZ_API bool rz_str_glob(const char* str, const char *glob) { const char* cp = NULL, *mp = NULL; if (!glob || !strcmp (glob, "*")) { return true; @@ -2166,8 +2166,8 @@ R_API bool r_str_glob(const char* str, const char *glob) { return (*glob == '\x00'); } -// Escape the string arg so that it is parsed as a single argument by r_str_argv -R_API char *r_str_arg_escape(const char *arg) { +// Escape the string arg so that it is parsed as a single argument by rz_str_argv +RZ_API char *rz_str_arg_escape(const char *arg) { char *str; int dest_i = 0, src_i = 0; if (!arg) { @@ -2197,7 +2197,7 @@ R_API char *r_str_arg_escape(const char *arg) { } // Unescape the string arg to its original format -R_API int r_str_arg_unescape(char *arg) { +RZ_API int rz_str_arg_unescape(char *arg) { int dest_i = 0, src_i = 0; if (!arg) { return 0; @@ -2217,7 +2217,7 @@ R_API int r_str_arg_unescape(char *arg) { return dest_i; } -R_API char *r_str_path_escape(const char *path) { +RZ_API char *rz_str_path_escape(const char *path) { char *str; int dest_i = 0, src_i = 0; @@ -2247,7 +2247,7 @@ R_API char *r_str_path_escape(const char *path) { return realloc (str, (strlen (str) + 1) * sizeof (char)); } -R_API int r_str_path_unescape(char *path) { +RZ_API int rz_str_path_unescape(char *path) { int i; for (i = 0; path[i]; i++) { @@ -2263,7 +2263,7 @@ R_API int r_str_path_unescape(char *path) { return i; } -R_API char **r_str_argv(const char *cmdline, int *_argc) { +RZ_API char **rz_str_argv(const char *cmdline, int *_argc) { int argc = 0; int argv_len = 128; // Begin with that, argv will reallocated if necessary char *args; // Working buffer for writing unescaped args @@ -2387,7 +2387,7 @@ R_API char **r_str_argv(const char *cmdline, int *_argc) { return argv; } -R_API void r_str_argv_free(char **argv) { +RZ_API void rz_str_argv_free(char **argv) { int argc = 0; if (!argv) { return; @@ -2398,7 +2398,7 @@ R_API void r_str_argv_free(char **argv) { free (argv); } -R_API const char *r_str_firstbut(const char *s, char ch, const char *but) { +RZ_API const char *rz_str_firstbut(const char *s, char ch, const char *but) { int idx, _b = 0; ut8 *b = (ut8*)&_b; const char *isbut, *p; @@ -2407,7 +2407,7 @@ R_API const char *r_str_firstbut(const char *s, char ch, const char *but) { return strchr (s, ch); } if (strlen (but) >= bsz) { - eprintf ("r_str_firstbut: but string too long\n"); + eprintf ("rz_str_firstbut: but string too long\n"); return NULL; } for (p = s; *p; p++) { @@ -2424,16 +2424,16 @@ R_API const char *r_str_firstbut(const char *s, char ch, const char *but) { return NULL; } -R_API const char *r_str_lastbut(const char *s, char ch, const char *but) { +RZ_API const char *rz_str_lastbut(const char *s, char ch, const char *but) { int idx, _b = 0; ut8 *b = (ut8*)&_b; const char *isbut, *p, *lp = NULL; const int bsz = sizeof (_b) * 8; if (!but) { - return r_str_lchr (s, ch); + return rz_str_lchr (s, ch); } if (strlen (but) >= bsz) { - eprintf ("r_str_lastbut: but string too long\n"); + eprintf ("rz_str_lastbut: but string too long\n"); return NULL; } for (p = s; *p; p++) { @@ -2451,7 +2451,7 @@ R_API const char *r_str_lastbut(const char *s, char ch, const char *but) { } // Must be merged inside strlen -R_API size_t r_str_len_utf8char(const char *s, int left) { +RZ_API size_t rz_str_len_utf8char(const char *s, int left) { size_t i = 1; while (s[i] && (!left || i= needle_len) { - if (!r_str_ncasecmp (a, b, needle_len)) { + if (!rz_str_ncasecmp (a, b, needle_len)) { return (const char *) a; } a++; @@ -2529,11 +2529,11 @@ R_API const char *r_str_casestr(const char *a, const char *b) { return NULL; } -R_API int r_str_write(int fd, const char *b) { +RZ_API int rz_str_write(int fd, const char *b) { return write (fd, b, strlen (b)); } -R_API void r_str_range_foreach(const char *r, RStrRangeCallback cb, void *u) { +RZ_API void rz_str_range_foreach(const char *r, RStrRangeCallback cb, void *u) { const char *p = r; for (; *r; r++) { if (*r == ',') { @@ -2561,7 +2561,7 @@ R_API void r_str_range_foreach(const char *r, RStrRangeCallback cb, void *u) { } } -R_API bool r_str_range_in(const char *r, ut64 addr) { +RZ_API bool rz_str_range_in(const char *r, ut64 addr) { const char *p = r; ut64 min = UT64_MAX; ut64 max = 0; @@ -2571,11 +2571,11 @@ R_API bool r_str_range_in(const char *r, ut64 addr) { for (; *r; r++) { if (*r == ',') { if (max == 0) { - if (addr == r_num_get (NULL, p)) { + if (addr == rz_num_get (NULL, p)) { return true; } } else { - if (addr >= min && addr <= r_num_get (NULL, p)) { + if (addr >= min && addr <= rz_num_get (NULL, p)) { return true; } } @@ -2583,8 +2583,8 @@ R_API bool r_str_range_in(const char *r, ut64 addr) { } if (*r == '-') { if (p != r) { - ut64 from = r_num_get (NULL, p); - ut64 to = r_num_get (NULL, r + 1); + ut64 from = rz_num_get (NULL, p); + ut64 to = rz_num_get (NULL, r + 1); if (addr >= from && addr <= to) { return true; } @@ -2598,7 +2598,7 @@ R_API bool r_str_range_in(const char *r, ut64 addr) { } } if (*p) { - if (addr == r_num_get (NULL, p)) { + if (addr == rz_num_get (NULL, p)) { return true; } } @@ -2607,7 +2607,7 @@ R_API bool r_str_range_in(const char *r, ut64 addr) { // convert from html escaped sequence "foo%20bar" to "foo bar" // TODO: find better name.. unencode? decode -R_API void r_str_uri_decode(char *s) { +RZ_API void rz_str_uri_decode(char *s) { int n; char *d; for (d = s; *s; s++, d++) { @@ -2622,7 +2622,7 @@ R_API void r_str_uri_decode(char *s) { *d = 0; } -R_API char *r_str_uri_encode(const char *s) { +RZ_API char *rz_str_uri_encode(const char *s) { char ch[4], *d, *od; if (!s) { return NULL; @@ -2648,7 +2648,7 @@ R_API char *r_str_uri_encode(const char *s) { return trimDown? trimDown: od; } -R_API int r_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, int little_endian) { +RZ_API int rz_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src, int little_endian) { ut8 *outstart = dst; ut8 *outend = dst + len_dst; ut16 *in = (ut16*)src; @@ -2724,7 +2724,7 @@ R_API int r_str_utf16_to_utf8(ut8 *dst, int len_dst, const ut8 *src, int len_src return len_dst; } -R_API char *r_str_utf16_decode(const ut8 *s, int len) { +RZ_API char *rz_str_utf16_decode(const ut8 *s, int len) { int i = 0; int j = 0; char *result = NULL; @@ -2756,7 +2756,7 @@ R_API char *r_str_utf16_decode(const ut8 *s, int len) { } // TODO: kill this completely, it makes no sense: -R_API char *r_str_utf16_encode(const char *s, int len) { +RZ_API char *rz_str_utf16_encode(const char *s, int len) { int i; char ch[4], *d, *od, *tmp; if (!s) { @@ -2801,7 +2801,7 @@ R_API char *r_str_utf16_encode(const char *s, int len) { return tmp; } -R_API char *r_str_prefix_all(const char *s, const char *pfx) { +RZ_API char *rz_str_prefix_all(const char *s, const char *pfx) { const char *os = s; char *p; int newlines = 1; @@ -2839,7 +2839,7 @@ R_API char *r_str_prefix_all(const char *s, const char *pfx) { #define HASCH(x) strchr (input_value,x) #define CAST (void*)(size_t) -R_API ut8 r_str_contains_macro(const char *input_value) { +RZ_API ut8 rz_str_contains_macro(const char *input_value) { char *has_tilde = input_value ? HASCH('~') : NULL, *has_bang = input_value ? HASCH('!') : NULL, *has_brace = input_value ? CAST(HASCH('[') || HASCH(']')) : NULL, @@ -2853,7 +2853,7 @@ R_API ut8 r_str_contains_macro(const char *input_value) { || has_paren || has_colon || has_at; } -R_API void r_str_truncate_cmd(char *string) { +RZ_API void rz_str_truncate_cmd(char *string) { ut32 pos = 0; if (string && *string) { ut32 sz = strlen (string); @@ -2875,7 +2875,7 @@ R_API void r_str_truncate_cmd(char *string) { } } -R_API const char *r_str_closer_chr(const char *b, const char *s) { +RZ_API const char *rz_str_closer_chr(const char *b, const char *s) { const char *a; while (*b) { for (a = s; *a; a++) { @@ -2888,7 +2888,7 @@ R_API const char *r_str_closer_chr(const char *b, const char *s) { return NULL; } -R_API int r_str_bounds(const char *_str, int *h) { +RZ_API int rz_str_bounds(const char *_str, int *h) { const char *str, *ptr; int W = 0, H = 0; int cw = 0; @@ -2898,7 +2898,7 @@ R_API int r_str_bounds(const char *_str, int *h) { while (*str) { if (*str == '\n') { H++; - cw = r_str_ansi_nlen (ptr, (size_t)(str - ptr)); + cw = rz_str_ansi_nlen (ptr, (size_t)(str - ptr)); if (cw > W) { W = cw; } @@ -2921,7 +2921,7 @@ R_API int r_str_bounds(const char *_str, int *h) { /* crop a string like it is in a rectangle with the upper-left corner at (x, y) * coordinates and the bottom-right corner at (x2, y2) coordinates. The result * is a newly allocated string, that should be deallocated by the user */ -R_API char *r_str_crop(const char *str, unsigned int x, unsigned int y, +RZ_API char *rz_str_crop(const char *str, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2) { char *r, *ret; unsigned int ch = 0, cw = 0; @@ -2963,7 +2963,7 @@ R_API char *r_str_crop(const char *str, unsigned int x, unsigned int y, return ret; } -R_API const char * r_str_tok(const char *str1, const char b, size_t len) { +RZ_API const char * rz_str_tok(const char *str1, const char b, size_t len) { const char *p = str1; size_t i = 0; if (!p || !*p) { @@ -2983,7 +2983,7 @@ R_API const char * r_str_tok(const char *str1, const char b, size_t len) { return p; } -R_API int r_str_do_until_token(str_operation op, char *str, const char tok) { +RZ_API int rz_str_do_until_token(str_operation op, char *str, const char tok) { int ret; if (!str) { return -1; @@ -3000,7 +3000,7 @@ R_API int r_str_do_until_token(str_operation op, char *str, const char tok) { return ret; } -R_API const char *r_str_pad(const char ch, int sz) { +RZ_API const char *rz_str_pad(const char ch, int sz) { static char pad[1024]; if (sz < 0) { sz = 0; @@ -3013,7 +3013,7 @@ R_API const char *r_str_pad(const char ch, int sz) { return pad; } -R_API char *r_str_repeat(const char *ch, int sz) { +RZ_API char *rz_str_repeat(const char *ch, int sz) { int i; if (sz < 0) { sz = 0; @@ -3021,14 +3021,14 @@ R_API char *r_str_repeat(const char *ch, int sz) { if (sz == 0) { return strdup (""); } - RStrBuf *buf = r_strbuf_new (ch); + RStrBuf *buf = rz_strbuf_new (ch); for (i = 1; i < sz; i++) { - r_strbuf_append (buf, ch); + rz_strbuf_append (buf, ch); } - return r_strbuf_drain (buf); + return rz_strbuf_drain (buf); } -R_API char *r_str_between(const char *cmt, const char *prefix, const char *suffix) { +RZ_API char *rz_str_between(const char *cmt, const char *prefix, const char *suffix) { char *c0, *c1; if (!cmt || !prefix || !suffix || !*cmt) { return NULL; @@ -3037,22 +3037,22 @@ R_API char *r_str_between(const char *cmt, const char *prefix, const char *suffi if (c0) { c1 = strstr (c0 + strlen (prefix), suffix); if (c1) { - return r_str_ndup (c0 + strlen (prefix), (c1 - c0 - strlen (prefix))); + return rz_str_ndup (c0 + strlen (prefix), (c1 - c0 - strlen (prefix))); } } return NULL; } -R_API bool r_str_startswith(const char *str, const char *needle) { - r_return_val_if_fail (str && needle, false); +RZ_API bool rz_str_startswith(const char *str, const char *needle) { + rz_return_val_if_fail (str && needle, false); if (str == needle) { return true; } return !strncmp (str, needle, strlen (needle)); } -R_API bool r_str_endswith(const char *str, const char *needle) { - r_return_val_if_fail (str && needle, false); +RZ_API bool rz_str_endswith(const char *str, const char *needle) { + rz_return_val_if_fail (str && needle, false); if (!*needle) { return true; } @@ -3065,9 +3065,9 @@ R_API bool r_str_endswith(const char *str, const char *needle) { } // Splits the string by string and returns the result in a list. -R_API RList *r_str_split_list(char *str, const char *c, int n) { - r_return_val_if_fail (str && c, NULL); - RList *lst = r_list_newf (NULL); +RZ_API RzList *rz_str_split_list(char *str, const char *c, int n) { + rz_return_val_if_fail (str && c, NULL); + RzList *lst = rz_list_newf (NULL); char *aux = str; int i = 0; char *e = aux; @@ -3075,23 +3075,23 @@ R_API RList *r_str_split_list(char *str, const char *c, int n) { e = strstr (aux, c); if (n > 0) { if (++i > n) { - r_list_append (lst, aux); + rz_list_append (lst, aux); break; } } if (e) { *e++ = 0; } - r_str_trim (aux); - r_list_append (lst, aux); + rz_str_trim (aux); + rz_list_append (lst, aux); aux = e; } return lst; } -R_API RList *r_str_split_duplist(const char *_str, const char *c, bool trim) { - r_return_val_if_fail (_str && c, NULL); - RList *lst = r_list_newf (free); +RZ_API RzList *rz_str_split_duplist(const char *_str, const char *c, bool trim) { + rz_return_val_if_fail (_str && c, NULL); + RzList *lst = rz_list_newf (free); char *str = strdup (_str); char *aux = str; size_t clen = strlen (c); @@ -3102,16 +3102,16 @@ R_API RList *r_str_split_duplist(const char *_str, const char *c, bool trim) { next += clen; } if (trim) { - r_str_trim (aux); + rz_str_trim (aux); } - r_list_append (lst, strdup (aux)); + rz_list_append (lst, strdup (aux)); aux = next; } free (str); return lst; } -R_API size_t *r_str_split_lines(char *str, size_t *count) { +RZ_API size_t *rz_str_split_lines(char *str, size_t *count) { int i; size_t lines = 0; if (!str) { @@ -3143,7 +3143,7 @@ R_API size_t *r_str_split_lines(char *str, size_t *count) { return indexes; } -R_API bool r_str_isnumber(const char *str) { +RZ_API bool rz_str_isnumber(const char *str) { if (!str || !*str) { return false; } @@ -3157,7 +3157,7 @@ R_API bool r_str_isnumber(const char *str) { } /* TODO: optimize to start searching by the end of the string */ -R_API const char *r_str_last(const char *str, const char *ch) { +RZ_API const char *rz_str_last(const char *str, const char *ch) { char *ptr, *end = NULL; if (!str || !ch) { return NULL; @@ -3249,7 +3249,7 @@ static char *strchr_skip_color_codes(const char *s, int c) { // Global buffer to speed up colorizing performance -R_API char* r_str_highlight(char *str, const char *word, const char *color, const char *color_reset) { +RZ_API char* rz_str_highlight(char *str, const char *word, const char *color, const char *color_reset) { if (!str || !*str) { return NULL; } @@ -3262,7 +3262,7 @@ R_API char* r_str_highlight(char *str, const char *word, const char *color, cons return strdup (str); } if (!word || !*word) { - return r_str_newf ("%s%s%s", color, str, color_reset); + return rz_str_newf ("%s%s%s", color, str, color_reset); } ut32 l_word = strlen (word); // XXX don't use static buffers @@ -3314,7 +3314,7 @@ R_API char* r_str_highlight(char *str, const char *word, const char *color, cons return strdup (o); } -R_API wchar_t* r_str_mb_to_wc_l(const char *buf, int len) { +RZ_API wchar_t* rz_str_mb_to_wc_l(const char *buf, int len) { wchar_t *res_buf = NULL; size_t sz; bool fail = true; @@ -3342,7 +3342,7 @@ err_r_str_mb_to_wc: return res_buf; } -R_API char* r_str_wc_to_mb_l(const wchar_t *buf, int len) { +RZ_API char* rz_str_wc_to_mb_l(const wchar_t *buf, int len) { char *res_buf = NULL; bool fail = true; size_t sz; @@ -3370,21 +3370,21 @@ err_r_str_wc_to_mb: return res_buf; } -R_API char* r_str_wc_to_mb(const wchar_t *buf) { +RZ_API char* rz_str_wc_to_mb(const wchar_t *buf) { if (!buf) { return NULL; } - return r_str_wc_to_mb_l (buf, wcslen (buf)); + return rz_str_wc_to_mb_l (buf, wcslen (buf)); } -R_API wchar_t* r_str_mb_to_wc(const char *buf) { +RZ_API wchar_t* rz_str_mb_to_wc(const char *buf) { if (!buf) { return NULL; } - return r_str_mb_to_wc_l (buf, strlen (buf)); + return rz_str_mb_to_wc_l (buf, strlen (buf)); } -R_API char *r_str_from_ut64(ut64 val) { +RZ_API char *rz_str_from_ut64(ut64 val) { int i = 0; char *v = (char *)&val; char *str = (char *)calloc(1, 9); @@ -3397,7 +3397,7 @@ R_API char *r_str_from_ut64(ut64 val) { return str; } -R_API int r_snprintf(char *string, int len, const char *fmt, ...) { +RZ_API int rz_snprintf(char *string, int len, const char *fmt, ...) { va_list ap; va_start (ap, fmt); int ret = vsnprintf (string, len, fmt, ap); @@ -3407,7 +3407,7 @@ R_API int r_snprintf(char *string, int len, const char *fmt, ...) { } // Strips all the lines in str that contain key -R_API void r_str_stripLine(char *str, const char *key) { +RZ_API void rz_str_stripLine(char *str, const char *key) { size_t i, j, klen, slen, off; const char *ptr; @@ -3418,9 +3418,9 @@ R_API void r_str_stripLine(char *str, const char *key) { slen = strlen (str); for (i = 0; i < slen; ) { - ptr = (char*) r_mem_mem ((ut8*) str + i, slen - i, (ut8*) "\n", 1); + ptr = (char*) rz_mem_mem ((ut8*) str + i, slen - i, (ut8*) "\n", 1); if (!ptr) { - ptr = (char*) r_mem_mem ((ut8*) str + i, slen - i, (ut8*) key, klen); + ptr = (char*) rz_mem_mem ((ut8*) str + i, slen - i, (ut8*) key, klen); if (ptr) { str[i] = '\0'; break; @@ -3430,7 +3430,7 @@ R_API void r_str_stripLine(char *str, const char *key) { off = (size_t) (ptr - (str + i)) + 1; - ptr = (char*) r_mem_mem ((ut8*) str + i, off, (ut8*) key, klen); + ptr = (char*) rz_mem_mem ((ut8*) str + i, off, (ut8*) key, klen); if (ptr) { for (j = i; j < slen - off + 1; j++) { str[j] = str[j + off]; @@ -3442,35 +3442,35 @@ R_API void r_str_stripLine(char *str, const char *key) { } } -R_API char *r_str_list_join(RList *str, const char *sep) { - RStrBuf *sb = r_strbuf_new (""); +RZ_API char *rz_str_list_join(RzList *str, const char *sep) { + RStrBuf *sb = rz_strbuf_new (""); const char *p; - while ((p = r_list_pop_head (str))) { - if (r_strbuf_length (sb) != 0) { - r_strbuf_append (sb, sep); + while ((p = rz_list_pop_head (str))) { + if (rz_strbuf_length (sb) != 0) { + rz_strbuf_append (sb, sep); } - r_strbuf_append (sb, p); + rz_strbuf_append (sb, p); } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_str_array_join(const char **a, size_t n, const char *sep) { - RStrBuf *sb = r_strbuf_new (""); +RZ_API char *rz_str_array_join(const char **a, size_t n, const char *sep) { + RStrBuf *sb = rz_strbuf_new (""); size_t i; if (n > 0) { - r_strbuf_append (sb, a[0]); + rz_strbuf_append (sb, a[0]); } for (i = 1; i < n; i++) { - r_strbuf_append (sb, sep); - r_strbuf_append (sb, a[i]); + rz_strbuf_append (sb, sep); + rz_strbuf_append (sb, a[i]); } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } /* return the number of arguments expected as extra arguments */ -R_API int r_str_fmtargs(const char *fmt) { +RZ_API int rz_str_fmtargs(const char *fmt) { int n = 0; while (*fmt) { if (*fmt == '%') { @@ -3489,30 +3489,30 @@ R_API int r_str_fmtargs(const char *fmt) { // Returns "true" or "false" as a string given an input integer. The returned // value is consistent with C's definition of 0 is false, and all other values // are true. -R_API const char *r_str_bool(int b) { +RZ_API const char *rz_str_bool(int b) { return b? "true": "false"; } -R_API bool r_str_is_true(const char *s) { - return !r_str_casecmp ("yes", s) - || !r_str_casecmp ("on", s) - || !r_str_casecmp ("true", s) - || !r_str_casecmp ("1", s); +RZ_API bool rz_str_is_true(const char *s) { + return !rz_str_casecmp ("yes", s) + || !rz_str_casecmp ("on", s) + || !rz_str_casecmp ("true", s) + || !rz_str_casecmp ("1", s); } -R_API bool r_str_is_false(const char *s) { - return !r_str_casecmp ("no", s) - || !r_str_casecmp ("off", s) - || !r_str_casecmp ("false", s) - || !r_str_casecmp ("0", s) +RZ_API bool rz_str_is_false(const char *s) { + return !rz_str_casecmp ("no", s) + || !rz_str_casecmp ("off", s) + || !rz_str_casecmp ("false", s) + || !rz_str_casecmp ("0", s) || !*s; } -R_API bool r_str_is_bool(const char *val) { - return r_str_is_true (val) || r_str_is_false (val); +RZ_API bool rz_str_is_bool(const char *val) { + return rz_str_is_true (val) || rz_str_is_false (val); } -R_API char *r_str_nextword(char *s, char ch) { +RZ_API char *rz_str_nextword(char *s, char ch) { char *p = strchr (s, ch); if (!p) { return NULL; @@ -3521,49 +3521,49 @@ R_API char *r_str_nextword(char *s, char ch) { return p; } -R_API char *r_str_scale(const char *s, int w, int h) { +RZ_API char *rz_str_scale(const char *s, int w, int h) { // count lines and rows in (s) string // compute how many lines we should remove or combine // return a string containing // for now this function is ascii only (no utf8 or ansi escapes) - RListIter *iter; + RzListIter *iter; char *line; char *str = strdup (s); - RList *lines = r_str_split_list (str, "\n", 0); + RzList *lines = rz_str_split_list (str, "\n", 0); int i, j; int rows = 0; int maxcol = 0; - rows = r_list_length (lines); - r_list_foreach (lines, iter, line) { + rows = rz_list_length (lines); + rz_list_foreach (lines, iter, line) { maxcol = R_MAX (strlen (line), maxcol); } - RList *out = r_list_newf (free); + RzList *out = rz_list_newf (free); int curline = -1; - char *linetext = (char*)r_str_pad (' ', w); + char *linetext = (char*)rz_str_pad (' ', w); for (i = 0; i < h; i++) { int zoomedline = i * ((float)rows / h); - const char *srcline = r_list_get_n (lines, zoomedline); + const char *srcline = rz_list_get_n (lines, zoomedline); int cols = strlen (srcline); for (j = 0; j < w; j++) { int zoomedcol = j * ( (float)cols / w); linetext[j] = srcline[zoomedcol]; } if (curline != zoomedline) { - r_list_append (out, strdup (linetext)); + rz_list_append (out, strdup (linetext)); curline = zoomedline; } memset (linetext, ' ', w); } free (str); - return r_str_list_join (out, "\n"); + return rz_str_list_join (out, "\n"); } -R_API const char *r_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y) { - r_return_val_if_fail (s && word && x && y, NULL); - r_return_val_if_fail (word[0] != '\0' && word[0] != '\n', NULL); +RZ_API const char *rz_str_str_xy(const char *s, const char *word, const char *prev, int *x, int *y) { + rz_return_val_if_fail (s && word && x && y, NULL); + rz_return_val_if_fail (word[0] != '\0' && word[0] != '\n', NULL); const char *src = prev ? prev + 1 : s; const char *d = strstr (src, word); if (!d) { @@ -3583,8 +3583,8 @@ R_API const char *r_str_str_xy(const char *s, const char *word, const char *prev } // version.c -#include -#include +#include +#include #ifndef R2_GITTAP #define R2_GITTAP "" @@ -3598,15 +3598,15 @@ R_API const char *r_str_str_xy(const char *s, const char *word, const char *prev #define R2_BIRTH "unknown" #endif -R_API char *r_str_version(const char *program) { - char *s = r_str_newf ("%s "R2_VERSION" %d @ " +RZ_API char *rz_str_version(const char *program) { + char *s = rz_str_newf ("%s "R2_VERSION" %d @ " R_SYS_OS"-" R_SYS_ARCH"-%d git.%s\n", program, R2_VERSION_COMMIT, (R_SYS_BITS & 8)? 64: 32, *R2_GITTAP ? R2_GITTAP: ""); if (*R2_GITTIP) { - s = r_str_appendf (s, "commit: "R2_GITTIP" build: "R2_BIRTH); + s = rz_str_appendf (s, "commit: "R2_GITTIP" build: "R2_BIRTH); } return s; } diff --git a/libr/util/str_constpool.c b/librz/util/str_constpool.c similarity index 65% rename from libr/util/str_constpool.c rename to librz/util/str_constpool.c index 15ab681b7f..d979fc69c9 100644 --- a/libr/util/str_constpool.c +++ b/librz/util/str_constpool.c @@ -1,21 +1,21 @@ /* radare - LGPL - Copyright 2019 thestr4ng3r */ -#include "r_util/r_str_constpool.h" +#include "rz_util/rz_str_constpool.h" static void kv_fini(HtPPKv *kv) { free (kv->key); } -R_API bool r_str_constpool_init(RStrConstPool *pool) { +RZ_API bool rz_str_constpool_init(RStrConstPool *pool) { pool->ht = ht_pp_new (NULL, kv_fini, NULL); return pool->ht != NULL; } -R_API void r_str_constpool_fini(RStrConstPool *pool) { +RZ_API void rz_str_constpool_fini(RStrConstPool *pool) { ht_pp_free (pool->ht); } -R_API const char *r_str_constpool_get(RStrConstPool *pool, const char *str) { +RZ_API const char *rz_str_constpool_get(RStrConstPool *pool, const char *str) { if (!str) { return NULL; } diff --git a/libr/util/str_trim.c b/librz/util/str_trim.c similarity index 67% rename from libr/util/str_trim.c rename to librz/util/str_trim.c index 52d97c6abf..60b75df48c 100644 --- a/libr/util/str_trim.c +++ b/librz/util/str_trim.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2007-2020 - pancake */ -#include "r_types.h" -#include "r_util.h" -#include "r_cons.h" -#include "r_bin.h" +#include "rz_types.h" +#include "rz_util.h" +#include "rz_cons.h" +#include "rz_bin.h" #include #include #include @@ -11,7 +11,7 @@ #include // TODO: simplify this horrible loop -R_API void r_str_trim_path(char *s) { +RZ_API void rz_str_trim_path(char *s) { char *src, *dst, *p; int i = 0; if (!s || !*s) { @@ -56,34 +56,34 @@ R_API void r_str_trim_path(char *s) { } } -R_API char* r_str_trim_lines(char *str) { - RList *list = r_str_split_list (str, "\n", 0); +RZ_API char* rz_str_trim_lines(char *str) { + RzList *list = rz_str_split_list (str, "\n", 0); char *s; - RListIter *iter; - RStrBuf *sb = r_strbuf_new (""); - r_list_foreach (list, iter, s) { - //r_str_ansi_trim (s, -1, 99999); - r_str_ansi_filter (s, NULL, NULL, -1); - r_str_trim (s); + RzListIter *iter; + RStrBuf *sb = rz_strbuf_new (""); + rz_list_foreach (list, iter, s) { + //rz_str_ansi_trim (s, -1, 99999); + rz_str_ansi_filter (s, NULL, NULL, -1); + rz_str_trim (s); if (*s) { - r_strbuf_appendf (sb, "%s\n", s); + rz_strbuf_appendf (sb, "%s\n", s); } } - r_list_free (list); + rz_list_free (list); free (str); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_str_trim_dup(const char *str) { +RZ_API char *rz_str_trim_dup(const char *str) { char *a = strdup (str); - r_str_trim (a); + rz_str_trim (a); return a; } // Returns a pointer to the first non-whitespace character of str. -// TODO: Find a better name: to r_str_trim_head_ro(), r_str_skip_head or so -R_API const char *r_str_trim_head_ro(const char *str) { - r_return_val_if_fail (str, NULL); +// TODO: Find a better name: to rz_str_trim_head_ro(), rz_str_skip_head or so +RZ_API const char *rz_str_trim_head_ro(const char *str) { + rz_return_val_if_fail (str, NULL); for (; *str && IS_WHITECHAR (*str); str++) { ; } @@ -91,8 +91,8 @@ R_API const char *r_str_trim_head_ro(const char *str) { } // TODO: find better name -R_API const char *r_str_trim_head_wp(const char *str) { - r_return_val_if_fail (str, NULL); +RZ_API const char *rz_str_trim_head_wp(const char *str) { + rz_return_val_if_fail (str, NULL); for (; *str && !IS_WHITESPACE (*str); str++) { ; } @@ -101,8 +101,8 @@ R_API const char *r_str_trim_head_wp(const char *str) { /* remove spaces from the head of the string. * the string is changed in place */ -R_API void r_str_trim_head(char *str) { - char *p = (char *)r_str_trim_head_ro (str); +RZ_API void rz_str_trim_head(char *str) { + char *p = (char *)rz_str_trim_head_ro (str); if (p) { memmove (str, p, strlen (p) + 1); } @@ -110,8 +110,8 @@ R_API void r_str_trim_head(char *str) { // Remove whitespace chars from the tail of the string, replacing them with // null bytes. The string is changed in-place. -R_API void r_str_trim_tail(char *str) { - r_return_if_fail (str); +RZ_API void rz_str_trim_tail(char *str) { + rz_return_if_fail (str); size_t length = strlen (str); while (length-- > 0) { if (IS_WHITECHAR (str[length])) { @@ -124,22 +124,22 @@ R_API void r_str_trim_tail(char *str) { // Removes spaces from the head of the string, and zeros out whitespaces from // the tail of the string. The string is changed in place. -R_API void r_str_trim(char *str) { - r_str_trim_head (str); - r_str_trim_tail (str); +RZ_API void rz_str_trim(char *str) { + rz_str_trim_head (str); + rz_str_trim_tail (str); } // no copy, like trim_head+tail but with trim_head_ro, beware heap issues -// TODO: rename to r_str_trim_weak() ? -R_API char *r_str_trim_nc(char *str) { - char *s = (char *)r_str_trim_head_ro (str); - r_str_trim_tail (s); +// TODO: rename to rz_str_trim_weak() ? +RZ_API char *rz_str_trim_nc(char *str) { + char *s = (char *)rz_str_trim_head_ro (str); + rz_str_trim_tail (s); return s; } /* supposed to chop a string with ansi controls to max length of n. */ -R_API int r_str_ansi_trim(char *str, int str_len, int n) { - r_return_val_if_fail (str, 0); +RZ_API int rz_str_ansi_trim(char *str, int str_len, int n) { + rz_return_val_if_fail (str, 0); char ch, ch2; int back = 0, i = 0, len = 0; /* simple case - no need to cut */ diff --git a/libr/util/strbuf.c b/librz/util/strbuf.c similarity index 56% rename from libr/util/strbuf.c rename to librz/util/strbuf.c index ceb25711ef..390070adab 100644 --- a/libr/util/strbuf.c +++ b/librz/util/strbuf.c @@ -1,51 +1,51 @@ /* radare - LGPL - Copyright 2013-2020 - pancake */ -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" #include -R_API RStrBuf *r_strbuf_new(const char *str) { +RZ_API RStrBuf *rz_strbuf_new(const char *str) { RStrBuf *s = R_NEW0 (RStrBuf); if (str) { - r_strbuf_set (s, str); + rz_strbuf_set (s, str); } return s; } -R_API bool r_strbuf_equals(RStrBuf *sa, RStrBuf *sb) { - r_return_val_if_fail (sa && sb, false); +RZ_API bool rz_strbuf_equals(RStrBuf *sa, RStrBuf *sb) { + rz_return_val_if_fail (sa && sb, false); if (sa->len != sb->len) { return false; } - return strcmp (r_strbuf_get (sa), r_strbuf_get (sb)) == 0; + return strcmp (rz_strbuf_get (sa), rz_strbuf_get (sb)) == 0; } -R_API bool r_strbuf_is_empty(RStrBuf *sb) { +RZ_API bool rz_strbuf_is_empty(RStrBuf *sb) { return sb->len == 0; } -R_API int r_strbuf_length(RStrBuf *sb) { - r_return_val_if_fail (sb, 0); +RZ_API int rz_strbuf_length(RStrBuf *sb) { + rz_return_val_if_fail (sb, 0); return sb->len; } -R_API void r_strbuf_init(RStrBuf *sb) { - r_return_if_fail (sb); +RZ_API void rz_strbuf_init(RStrBuf *sb) { + rz_return_if_fail (sb); memset (sb, 0, sizeof (RStrBuf)); } -R_API const char *r_strbuf_initf(RStrBuf *sb, const char *fmt, ...) { - r_return_val_if_fail (sb && fmt, NULL); - r_strbuf_init (sb); +RZ_API const char *rz_strbuf_initf(RStrBuf *sb, const char *fmt, ...) { + rz_return_val_if_fail (sb && fmt, NULL); + rz_strbuf_init (sb); va_list ap; va_start (ap, fmt); - const char *r = r_strbuf_vsetf (sb, fmt, ap); + const char *r = rz_strbuf_vsetf (sb, fmt, ap); va_end (ap); return r; } -R_API bool r_strbuf_copy(RStrBuf *dst, RStrBuf *src) { - r_return_val_if_fail (dst && src, false); +RZ_API bool rz_strbuf_copy(RStrBuf *dst, RStrBuf *src) { + rz_return_val_if_fail (dst && src, false); if (src->ptr) { char *p = malloc (src->ptrlen); if (!p) { @@ -63,8 +63,8 @@ R_API bool r_strbuf_copy(RStrBuf *dst, RStrBuf *src) { return true; } -R_API bool r_strbuf_reserve(RStrBuf *sb, size_t len) { - r_return_val_if_fail (sb, false); +RZ_API bool rz_strbuf_reserve(RStrBuf *sb, size_t len) { + rz_return_val_if_fail (sb, false); if ((sb->ptr && len < sb->ptrlen) || (!sb->ptr && len < sizeof (sb->buf))) { return true; @@ -81,8 +81,8 @@ R_API bool r_strbuf_reserve(RStrBuf *sb, size_t len) { return true; } -R_API bool r_strbuf_setbin(RStrBuf *sb, const ut8 *s, size_t l) { - r_return_val_if_fail (sb && s, false); +RZ_API bool rz_strbuf_setbin(RStrBuf *sb, const ut8 *s, size_t l) { + rz_return_val_if_fail (sb && s, false); if (l >= sizeof (sb->buf)) { char *ptr = sb->ptr; if (!ptr || l + 1 > sb->ptrlen) { @@ -107,29 +107,29 @@ R_API bool r_strbuf_setbin(RStrBuf *sb, const ut8 *s, size_t l) { } // TODO: there's room for optimizations here -R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len) { - r_return_val_if_fail (sb && from >= 0 && len >= 0, false); +RZ_API bool rz_strbuf_slice(RStrBuf *sb, int from, int len) { + rz_return_val_if_fail (sb && from >= 0 && len >= 0, false); if (from < 1 && len >= sb->len) { return false; } - const char *s = r_strbuf_get (sb); - const char *fr = r_str_ansi_chrn (s, from + 1); - const char *to = r_str_ansi_chrn (s, from + len + 1); - char *r = r_str_newlen (fr, to - fr); - r_strbuf_fini (sb); - r_strbuf_init (sb); + const char *s = rz_strbuf_get (sb); + const char *fr = rz_str_ansi_chrn (s, from + 1); + const char *to = rz_str_ansi_chrn (s, from + len + 1); + char *r = rz_str_newlen (fr, to - fr); + rz_strbuf_fini (sb); + rz_strbuf_init (sb); if (from >= len) { - r_strbuf_set (sb, ""); + rz_strbuf_set (sb, ""); free (r); return false; } - r_strbuf_set (sb, r); + rz_strbuf_set (sb, r); free (r); return true; } -R_API bool r_strbuf_setptr(RStrBuf *sb, char *s, int len) { - r_return_val_if_fail (sb, false); +RZ_API bool rz_strbuf_setptr(RStrBuf *sb, char *s, int len) { + rz_return_val_if_fail (sb, false); if (len < 0) { sb->len = strlen (s); sb->ptrlen = sb->len + 1; @@ -142,32 +142,32 @@ R_API bool r_strbuf_setptr(RStrBuf *sb, char *s, int len) { return true; } -R_API const char *r_strbuf_set(RStrBuf *sb, const char *s) { - r_return_val_if_fail (sb, NULL); +RZ_API const char *rz_strbuf_set(RStrBuf *sb, const char *s) { + rz_return_val_if_fail (sb, NULL); if (!s) { - r_strbuf_init (sb); - return r_strbuf_get (sb); + rz_strbuf_init (sb); + return rz_strbuf_get (sb); } size_t len = strlen (s); - if (!r_strbuf_setbin (sb, (const ut8*)s, len)) { + if (!rz_strbuf_setbin (sb, (const ut8*)s, len)) { return NULL; } sb->len = len; - return r_strbuf_get (sb); + return rz_strbuf_get (sb); } -R_API const char *r_strbuf_setf(RStrBuf *sb, const char *fmt, ...) { - r_return_val_if_fail (sb && fmt, false); +RZ_API const char *rz_strbuf_setf(RStrBuf *sb, const char *fmt, ...) { + rz_return_val_if_fail (sb && fmt, false); va_list ap; va_start (ap, fmt); - const char *ret = r_strbuf_vsetf (sb, fmt, ap); + const char *ret = rz_strbuf_vsetf (sb, fmt, ap); va_end (ap); return ret; } -R_API const char *r_strbuf_vsetf(RStrBuf *sb, const char *fmt, va_list ap) { - r_return_val_if_fail (sb && fmt, false); +RZ_API const char *rz_strbuf_vsetf(RStrBuf *sb, const char *fmt, va_list ap) { + rz_return_val_if_fail (sb && fmt, false); const char *ret = NULL; va_list ap2; @@ -180,18 +180,18 @@ R_API const char *r_strbuf_vsetf(RStrBuf *sb, const char *fmt, va_list ap) { goto done; } vsnprintf (p, rc + 1, fmt, ap2); - ret = r_strbuf_set (sb, p); + ret = rz_strbuf_set (sb, p); free (p); } else if (rc >= 0) { - ret = r_strbuf_set (sb, string); + ret = rz_strbuf_set (sb, string); } done: va_end (ap2); return ret; } -R_API bool r_strbuf_prepend(RStrBuf *sb, const char *s) { - r_return_val_if_fail (sb && s, false); +RZ_API bool rz_strbuf_prepend(RStrBuf *sb, const char *s) { + rz_return_val_if_fail (sb && s, false); int l = strlen (s); // fast path if no chars to append if (l == 0) { @@ -205,21 +205,21 @@ R_API bool r_strbuf_prepend(RStrBuf *sb, const char *s) { char *s = sb->ptr ? sb->ptr: sb->buf; memcpy (ns + l, s, sb->len); ns[newlen] = 0; - ret = r_strbuf_set (sb, ns); + ret = rz_strbuf_set (sb, ns); free (ns); } return ret; } -R_API bool r_strbuf_append(RStrBuf *sb, const char *s) { - r_return_val_if_fail (sb && s, false); +RZ_API bool rz_strbuf_append(RStrBuf *sb, const char *s) { + rz_return_val_if_fail (sb && s, false); int l = strlen (s); - return r_strbuf_append_n (sb, s, l); + return rz_strbuf_append_n (sb, s, l); } -R_API bool r_strbuf_append_n(RStrBuf *sb, const char *s, size_t l) { - r_return_val_if_fail (sb && s, false); +RZ_API bool rz_strbuf_append_n(RStrBuf *sb, const char *s, size_t l) { + rz_return_val_if_fail (sb && s, false); if (sb->weakref) { return false; @@ -264,23 +264,23 @@ R_API bool r_strbuf_append_n(RStrBuf *sb, const char *s, size_t l) { return true; } -R_API bool r_strbuf_appendf(RStrBuf *sb, const char *fmt, ...) { +RZ_API bool rz_strbuf_appendf(RStrBuf *sb, const char *fmt, ...) { va_list ap; - r_return_val_if_fail (sb && fmt, -1); + rz_return_val_if_fail (sb && fmt, -1); va_start (ap, fmt); - bool ret = r_strbuf_vappendf (sb, fmt, ap); + bool ret = rz_strbuf_vappendf (sb, fmt, ap); va_end (ap); return ret; } -R_API bool r_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap) { +RZ_API bool rz_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap) { int ret; va_list ap2; char string[1024]; - r_return_val_if_fail (sb && fmt, -1); + rz_return_val_if_fail (sb && fmt, -1); if (sb->weakref) { return false; @@ -295,10 +295,10 @@ R_API bool r_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap) { } *p = 0; vsnprintf (p, ret + 1, fmt, ap2); - ret = r_strbuf_append (sb, p); + ret = rz_strbuf_append (sb, p); free (p); } else if (ret >= 0) { - ret = r_strbuf_append (sb, string); + ret = rz_strbuf_append (sb, string); } else { ret = false; } @@ -306,13 +306,13 @@ R_API bool r_strbuf_vappendf(RStrBuf *sb, const char *fmt, va_list ap) { return ret; } -R_API char *r_strbuf_get(RStrBuf *sb) { - r_return_val_if_fail (sb, NULL); +RZ_API char *rz_strbuf_get(RStrBuf *sb) { + rz_return_val_if_fail (sb, NULL); return sb->ptr ? sb->ptr : sb->buf; } -R_API ut8 *r_strbuf_getbin(RStrBuf *sb, int *len) { - r_return_val_if_fail (sb, NULL); +RZ_API ut8 *rz_strbuf_getbin(RStrBuf *sb, int *len) { + rz_return_val_if_fail (sb, NULL); if (len) { *len = sb->len; } @@ -322,20 +322,20 @@ R_API ut8 *r_strbuf_getbin(RStrBuf *sb, int *len) { static inline char *drain(RStrBuf *sb) { return sb->ptr ? sb->weakref - ? r_mem_dup (sb->ptr, sb->ptrlen) + ? rz_mem_dup (sb->ptr, sb->ptrlen) : sb->ptr : strdup (sb->buf); } -R_API char *r_strbuf_drain(RStrBuf *sb) { - r_return_val_if_fail (sb, NULL); +RZ_API char *rz_strbuf_drain(RStrBuf *sb) { + rz_return_val_if_fail (sb, NULL); char *ret = drain (sb); free (sb); return ret; } -R_API char *r_strbuf_drain_nofree(RStrBuf *sb) { - r_return_val_if_fail (sb, NULL); +RZ_API char *rz_strbuf_drain_nofree(RStrBuf *sb) { + rz_return_val_if_fail (sb, NULL); char *ret = drain (sb); sb->ptr = NULL; sb->len = 0; @@ -343,14 +343,14 @@ R_API char *r_strbuf_drain_nofree(RStrBuf *sb) { return ret; } -R_API void r_strbuf_free(RStrBuf *sb) { +RZ_API void rz_strbuf_free(RStrBuf *sb) { if (sb) { - r_strbuf_fini (sb); + rz_strbuf_fini (sb); free (sb); } } -R_API void r_strbuf_fini(RStrBuf *sb) { +RZ_API void rz_strbuf_fini(RStrBuf *sb) { if (sb && !sb->weakref) { R_FREE (sb->ptr); sb->len = 0; diff --git a/libr/util/strpool.c b/librz/util/strpool.c similarity index 62% rename from libr/util/strpool.c rename to librz/util/strpool.c index f6a8a0f7b3..9afd99ea3c 100644 --- a/libr/util/strpool.c +++ b/librz/util/strpool.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2012 - pancake */ -#include +#include -R_API RStrpool* r_strpool_new (int sz) { +RZ_API RStrpool* rz_strpool_new (int sz) { RStrpool *p = R_NEW (RStrpool); if (!p) { eprintf ("Malloc failed!\n"); @@ -23,14 +23,14 @@ R_API RStrpool* r_strpool_new (int sz) { return p; } -R_API char *r_strpool_empty (RStrpool *p) { +RZ_API char *rz_strpool_empty (RStrpool *p) { p->len = 0; p->str[0] = 0; p->str[1] = 0; return p->str; } -R_API char *r_strpool_alloc (RStrpool *p, int l) { +RZ_API char *rz_strpool_alloc (RStrpool *p, int l) { char *ret = p->str + p->len; if ((p->len + l) >= p->size) { ut64 osize = p->size; @@ -57,8 +57,8 @@ R_API char *r_strpool_alloc (RStrpool *p, int l) { return ret; } -R_API int r_strpool_memcat(RStrpool *p, const char *s, int len) { - char *ptr = r_strpool_alloc (p, len); +RZ_API int rz_strpool_memcat(RStrpool *p, const char *s, int len) { + char *ptr = rz_strpool_alloc (p, len); if (!ptr) { return -1; } @@ -66,24 +66,24 @@ R_API int r_strpool_memcat(RStrpool *p, const char *s, int len) { return (size_t)(ptr - p->str); } -R_API int r_strpool_append(RStrpool *p, const char *s) { +RZ_API int rz_strpool_append(RStrpool *p, const char *s) { int l = strlen (s) + 1; - return r_strpool_memcat (p, s, l); + return rz_strpool_memcat (p, s, l); } -R_API int r_strpool_ansi_chop(RStrpool *p, int n){ +RZ_API int rz_strpool_ansi_chop(RStrpool *p, int n){ /* p->str need not be a c-string */ - int i = r_str_ansi_trim (p->str, p->len, n); + int i = rz_str_ansi_trim (p->str, p->len, n); p->len = i; return i; } -R_API void r_strpool_free (RStrpool *p) { +RZ_API void rz_strpool_free (RStrpool *p) { free (p->str); free (p); } -R_API int r_strpool_fit(RStrpool *p) { +RZ_API int rz_strpool_fit(RStrpool *p) { char *s; if (p->len == p->size) { return false; @@ -100,32 +100,32 @@ R_API int r_strpool_fit(RStrpool *p) { return true; } -R_API char *r_strpool_get(RStrpool *p, int index) { +RZ_API char *rz_strpool_get(RStrpool *p, int index) { if (!p || !p->str || index < 0 || index >= p->len) { return NULL; } return p->str + index; } -R_API char *r_strpool_get_i(RStrpool *p, int index) { +RZ_API char *rz_strpool_get_i(RStrpool *p, int index) { int i, n = 0; if (index < 0 || index >= p->len) { return NULL; } for (i = 0; i < index; i++) { - char *s = r_strpool_next (p, n); - n = r_strpool_get_index (p, s); + char *s = rz_strpool_next (p, n); + n = rz_strpool_get_index (p, s); } return p->str + n; } -R_API int r_strpool_get_index(RStrpool *p, const char *s) { +RZ_API int rz_strpool_get_index(RStrpool *p, const char *s) { int ret = (size_t)(s - p->str); return (ret > 0) ? ret : 0; } -R_API char *r_strpool_next(RStrpool *p, int index) { - char *ptr = r_strpool_get (p, index); +RZ_API char *rz_strpool_next(RStrpool *p, int index) { + char *ptr = rz_strpool_get (p, index); if (ptr) { char *q = ptr + strlen (ptr) + 1; if (q >= (p->str + p->len)) { @@ -139,9 +139,9 @@ R_API char *r_strpool_next(RStrpool *p, int index) { return ptr; } -R_API char *r_strpool_slice (RStrpool *p, int index) { +RZ_API char *rz_strpool_slice (RStrpool *p, int index) { int idx, len; - char *o, *x = r_strpool_get_i (p, index + 1); + char *o, *x = rz_strpool_get_i (p, index + 1); if (!x || !*x) { return NULL; } @@ -161,12 +161,12 @@ R_API char *r_strpool_slice (RStrpool *p, int index) { #if TEST int main() { - RStrpool *p = r_strpool_new (1024); - printf ("%d\n", r_strpool_append (p, "Hello World")); - printf ("%d\n", r_strpool_append (p, "Patata Barata")); - printf ("%s\n", r_strpool_get (p, 12)); - r_strpool_fit (p); - r_strpool_free (p); + RStrpool *p = rz_strpool_new (1024); + printf ("%d\n", rz_strpool_append (p, "Hello World")); + printf ("%d\n", rz_strpool_append (p, "Patata Barata")); + printf ("%s\n", rz_strpool_get (p, 12)); + rz_strpool_fit (p); + rz_strpool_free (p); return 0; } #endif diff --git a/libr/util/sys.c b/librz/util/sys.c similarity index 76% rename from libr/util/sys.c rename to librz/util/sys.c index da22e0455a..4471b99411 100644 --- a/libr/util/sys.c +++ b/librz/util/sys.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2009-2020 - pancake */ -#include +#include #include #include #if defined(__NetBSD__) @@ -22,9 +22,9 @@ # include #endif #include -#include -#include -#include +#include +#include +#include static char** env = NULL; @@ -76,12 +76,12 @@ extern char **environ; #endif #endif -R_LIB_VERSION(r_util); +R_LIB_VERSION(rz_util); #ifdef __x86_64__ # ifdef _MSC_VER # define R_SYS_ASM_START_ROP() \ - eprintf ("r_sys_run_rop: Unsupported arch\n"); + eprintf ("rz_sys_run_rop: Unsupported arch\n"); # else # define R_SYS_ASM_START_ROP() \ __asm__ __volatile__ ("leaq %0, %%rsp; ret" \ @@ -104,7 +104,7 @@ R_LIB_VERSION(r_util); # endif #else # define R_SYS_ASM_START_ROP() \ - eprintf ("r_sys_run_rop: Unsupported arch\n"); + eprintf ("rz_sys_run_rop: Unsupported arch\n"); #endif static const struct {const char* name; ut64 bit;} arch_bit_array[] = { @@ -132,7 +132,7 @@ static const struct {const char* name; ut64 bit;} arch_bit_array[] = { {NULL, 0} }; -R_API int r_sys_fork(void) { +RZ_API int rz_sys_fork(void) { #if HAVE_FORK #if __WINDOWS__ return -1; @@ -145,7 +145,7 @@ R_API int r_sys_fork(void) { } #if HAVE_SIGACTION -R_API int r_sys_sigaction(int *sig, void (*handler) (int)) { +RZ_API int rz_sys_sigaction(int *sig, void (*handler) (int)) { struct sigaction sigact = { }; int ret, i; @@ -171,7 +171,7 @@ R_API int r_sys_sigaction(int *sig, void (*handler) (int)) { return 0; } #else -R_API int r_sys_sigaction(int *sig, void (*handler)(int)) { +RZ_API int rz_sys_sigaction(int *sig, void (*handler)(int)) { if (!sig) { return -EINVAL; } @@ -187,12 +187,12 @@ R_API int r_sys_sigaction(int *sig, void (*handler)(int)) { } #endif -R_API int r_sys_signal(int sig, void (*handler) (int)) { +RZ_API int rz_sys_signal(int sig, void (*handler) (int)) { int s[2] = { sig, 0 }; - return r_sys_sigaction (s, handler); + return rz_sys_sigaction (s, handler); } -R_API void r_sys_exit(int status, bool nocleanup) { +RZ_API void rz_sys_exit(int status, bool nocleanup) { if (nocleanup) { _exit (status); } else { @@ -200,9 +200,9 @@ R_API void r_sys_exit(int status, bool nocleanup) { } } -R_API int r_sys_truncate(const char *file, int sz) { +RZ_API int rz_sys_truncate(const char *file, int sz) { #if __WINDOWS__ - int fd = r_sandbox_open (file, O_RDWR, 0644); + int fd = rz_sandbox_open (file, O_RDWR, 0644); if (fd == -1) { return false; } @@ -219,28 +219,28 @@ R_API int r_sys_truncate(const char *file, int sz) { close (fd); return true; #else - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return false; } return truncate (file, sz) == 0; #endif } -R_API RList *r_sys_dir(const char *path) { - RList *list = NULL; +RZ_API RzList *rz_sys_dir(const char *path) { + RzList *list = NULL; #if __WINDOWS__ WIN32_FIND_DATAW entry; char *cfname; - HANDLE fh = r_sandbox_opendir (path, &entry); + HANDLE fh = rz_sandbox_opendir (path, &entry); if (fh == INVALID_HANDLE_VALUE) { //IFDGB eprintf ("Cannot open directory %ls\n", wcpath); return list; } - list = r_list_newf (free); + list = rz_list_newf (free); if (list) { do { - if ((cfname = r_utf16_to_utf8 (entry.cFileName))) { - r_list_append (list, strdup (cfname)); + if ((cfname = rz_utf16_to_utf8 (entry.cFileName))) { + rz_list_append (list, strdup (cfname)); free (cfname); } } while (FindNextFileW (fh, &entry)); @@ -248,13 +248,13 @@ R_API RList *r_sys_dir(const char *path) { FindClose (fh); #else struct dirent *entry; - DIR *dir = r_sandbox_opendir (path); + DIR *dir = rz_sandbox_opendir (path); if (dir) { - list = r_list_new (); + list = rz_list_new (); if (list) { list->free = free; while ((entry = readdir (dir))) { - r_list_append (list, strdup (entry->d_name)); + rz_list_append (list, strdup (entry->d_name)); } } closedir (dir); @@ -263,12 +263,12 @@ R_API RList *r_sys_dir(const char *path) { return list; } -R_API char *r_sys_cmd_strf(const char *fmt, ...) { +RZ_API char *rz_sys_cmd_strf(const char *fmt, ...) { char *ret, cmd[4096]; va_list ap; va_start (ap, fmt); vsnprintf (cmd, sizeof (cmd), fmt, ap); - ret = r_sys_cmd_str (cmd, NULL, NULL); + ret = rz_sys_cmd_str (cmd, NULL, NULL); va_end (ap); return ret; } @@ -286,7 +286,7 @@ R_API char *r_sys_cmd_strf(const char *fmt, ...) { #define HAVE_BACKTRACE 1 #endif -R_API void r_sys_backtrace(void) { +RZ_API void rz_sys_backtrace(void) { #ifdef HAVE_BACKTRACE void *array[10]; size_t size = backtrace (array, 10); @@ -311,14 +311,14 @@ R_API void r_sys_backtrace(void) { } #else #ifdef _MSC_VER -#pragma message ("TODO: r_sys_bt : unimplemented") +#pragma message ("TODO: rz_sys_bt : unimplemented") #else -#warning TODO: r_sys_bt : unimplemented +#warning TODO: rz_sys_bt : unimplemented #endif #endif } -R_API int r_sys_sleep(int secs) { +RZ_API int rz_sys_sleep(int secs) { #if HAS_CLOCK_NANOSLEEP struct timespec rqtp; rqtp.tv_sec = secs; @@ -332,7 +332,7 @@ R_API int r_sys_sleep(int secs) { #endif } -R_API int r_sys_usleep(int usecs) { +RZ_API int rz_sys_usleep(int usecs) { #if HAS_CLOCK_NANOSLEEP struct timespec rqtp; rqtp.tv_sec = usecs / 1000000; @@ -354,12 +354,12 @@ R_API int r_sys_usleep(int usecs) { #endif } -R_API int r_sys_clearenv(void) { +RZ_API int rz_sys_clearenv(void) { #if __UNIX__ #if __APPLE__ && !HAVE_ENVIRON /* do nothing */ if (!env) { - r_sys_env_init (); + rz_sys_env_init (); return 0; } char **e = env; @@ -377,15 +377,15 @@ R_API int r_sys_clearenv(void) { return 0; #else #ifdef _MSC_VER -#pragma message ("r_sys_clearenv : unimplemented for this platform") +#pragma message ("rz_sys_clearenv : unimplemented for this platform") #else -#warning r_sys_clearenv : unimplemented for this platform +#warning rz_sys_clearenv : unimplemented for this platform #endif return 0; #endif } -R_API int r_sys_setenv(const char *key, const char *value) { +RZ_API int rz_sys_setenv(const char *key, const char *value) { if (!key) { return 0; } @@ -396,17 +396,17 @@ R_API int r_sys_setenv(const char *key, const char *value) { } return setenv (key, value, 1); #elif __WINDOWS__ - LPTSTR key_ = r_sys_conv_utf8_to_win (key); - LPTSTR value_ = r_sys_conv_utf8_to_win (value); + LPTSTR key_ = rz_sys_conv_utf8_to_win (key); + LPTSTR value_ = rz_sys_conv_utf8_to_win (value); int ret = SetEnvironmentVariable (key_, value_); if (!ret) { - r_sys_perror ("r_sys_setenv/SetEnvironmentVariable"); + rz_sys_perror ("rz_sys_setenv/SetEnvironmentVariable"); } free (key_); free (value_); return ret ? 0 : -1; #else -#warning r_sys_setenv : unimplemented for this platform +#warning rz_sys_setenv : unimplemented for this platform return 0; #endif } @@ -420,8 +420,8 @@ static void signal_handler(int signum) { return; } snprintf (cmd, sizeof(cmd) - 1, crash_handler_cmd, getpid ()); - r_sys_backtrace (); - exit (r_sys_cmd (cmd)); + rz_sys_backtrace (); + exit (rz_sys_cmd (cmd)); } static int checkcmd(const char *c) { @@ -438,7 +438,7 @@ static int checkcmd(const char *c) { } #endif -R_API int r_sys_crash_handler(const char *cmd) { +RZ_API int rz_sys_crash_handler(const char *cmd) { #ifndef __WINDOWS__ int sig[] = { SIGINT, SIGSEGV, SIGBUS, SIGQUIT, SIGHUP, 0 }; @@ -454,14 +454,14 @@ R_API int r_sys_crash_handler(const char *cmd) { free (crash_handler_cmd); crash_handler_cmd = strdup (cmd); - r_sys_sigaction (sig, signal_handler); + rz_sys_sigaction (sig, signal_handler); #else -#pragma message ("r_sys_crash_handler : unimplemented for this platform") +#pragma message ("rz_sys_crash_handler : unimplemented for this platform") #endif return true; } -R_API char *r_sys_getenv(const char *key) { +RZ_API char *rz_sys_getenv(const char *key) { #if __WINDOWS__ DWORD dwRet; LPTSTR envbuf = NULL, key_ = NULL, tmp_ptr; @@ -474,7 +474,7 @@ R_API char *r_sys_getenv(const char *key) { if (!envbuf) { goto err_r_sys_get_env; } - key_ = r_sys_conv_utf8_to_win (key); + key_ = rz_sys_conv_utf8_to_win (key); dwRet = GetEnvironmentVariable (key_, envbuf, TMP_BUFSIZE); if (dwRet == 0) { if (GetLastError () == ERROR_ENVVAR_NOT_FOUND) { @@ -491,7 +491,7 @@ R_API char *r_sys_getenv(const char *key) { goto err_r_sys_get_env; } } - val = r_sys_conv_win_to_utf8_l (envbuf, (int)dwRet); + val = rz_sys_conv_win_to_utf8_l (envbuf, (int)dwRet); err_r_sys_get_env: free (key_); free (envbuf); @@ -506,14 +506,14 @@ err_r_sys_get_env: #endif } -R_API bool r_sys_getenv_asbool(const char *key) { - char *env = r_sys_getenv (key); +RZ_API bool rz_sys_getenv_asbool(const char *key) { + char *env = rz_sys_getenv (key); const bool res = (env && *env == '1'); free (env); return res; } -R_API char *r_sys_getdir(void) { +RZ_API char *rz_sys_getdir(void) { #if __WINDOWS__ return _getcwd (NULL, 0); #else @@ -521,19 +521,19 @@ R_API char *r_sys_getdir(void) { #endif } -R_API int r_sys_chdir(const char *s) { - return r_sandbox_chdir (s)==0; +RZ_API int rz_sys_chdir(const char *s) { + return rz_sandbox_chdir (s)==0; } -R_API bool r_sys_aslr(int val) { +RZ_API bool rz_sys_aslr(int val) { bool ret = true; #if __linux__ const char *rva = "/proc/sys/kernel/randomize_va_space"; char buf[3] = {0}; snprintf(buf, sizeof (buf), "%d\n", val != 0 ? 2 : 0); - int fd = r_sandbox_open (rva, O_WRONLY, 0644); + int fd = rz_sandbox_open (rva, O_WRONLY, 0644); if (fd != -1) { - if (r_sandbox_write (fd, (ut8 *)buf, sizeof (buf)) != sizeof (buf)) { + if (rz_sandbox_write (fd, (ut8 *)buf, sizeof (buf)) != sizeof (buf)) { eprintf ("Failed to set RVA\n"); ret = false; } @@ -562,11 +562,11 @@ R_API bool r_sys_aslr(int val) { return ret; } -R_API int r_sys_thp_mode(void) { +RZ_API int rz_sys_thp_mode(void) { #if __linux__ const char *thp = "/sys/kernel/mm/transparent_hugepage/enabled"; int ret = 0; - char *val = r_file_slurp (thp, NULL); + char *val = rz_file_slurp (thp, NULL); if (val) { if (strstr (val, "[madvise]")) { ret = 1; @@ -583,7 +583,7 @@ R_API int r_sys_thp_mode(void) { } #if __UNIX__ -R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { +RZ_API int rz_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { char *mysterr = NULL; if (!sterr) { sterr = &mysterr; @@ -614,7 +614,7 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, return false; } - switch ((pid = r_sys_fork ())) { + switch ((pid = rz_sys_fork ())) { case -1: return false; case 0: @@ -633,7 +633,7 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, } close (sh_err[0]); close (sh_err[1]); - exit (r_sandbox_system (cmd, 0)); + exit (rz_sandbox_system (cmd, 0)); default: outputptr = strdup (""); if (!outputptr) { @@ -655,7 +655,7 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, close (sh_in[1]); } // we should handle broken pipes somehow better - r_sys_signal (SIGPIPE, SIG_IGN); + rz_sys_signal (SIGPIPE, SIG_IGN); size_t err_len = 0, out_len = 0; for (;;) { fd_set rfds, wfds; @@ -725,7 +725,7 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, waitpid (pid, &status, 0); bool ret = true; if (status) { - // char *escmd = r_str_escape (cmd); + // char *escmd = rz_str_escape (cmd); // eprintf ("error code %d (%s): %s\n", WEXITSTATUS (status), escmd, *sterr); // eprintf ("(%s)\n", output); // eprintf ("%s: failed command '%s'\n", __func__, escmd); @@ -752,74 +752,74 @@ R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, return false; } #elif __WINDOWS__ -R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { - return r_sys_cmd_str_full_w32 (cmd, input, output, len, sterr); +RZ_API int rz_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { + return rz_sys_cmd_str_full_w32 (cmd, input, output, len, sterr); } #else -R_API int r_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { - eprintf ("r_sys_cmd_str: not yet implemented for this platform\n"); +RZ_API int rz_sys_cmd_str_full(const char *cmd, const char *input, char **output, int *len, char **sterr) { + eprintf ("rz_sys_cmd_str: not yet implemented for this platform\n"); return false; } #endif -R_API int r_sys_cmdf(const char *fmt, ...) { +RZ_API int rz_sys_cmdf(const char *fmt, ...) { int ret; char cmd[4096]; va_list ap; va_start(ap, fmt); vsnprintf (cmd, sizeof (cmd), fmt, ap); - ret = r_sys_cmd (cmd); + ret = rz_sys_cmd (cmd); va_end (ap); return ret; } -R_API int r_sys_cmdbg (const char *str) { +RZ_API int rz_sys_cmdbg (const char *str) { #if __UNIX__ - int ret, pid = r_sys_fork (); + int ret, pid = rz_sys_fork (); if (pid == -1) { return -1; } if (pid) { return pid; } - ret = r_sandbox_system (str, 0); + ret = rz_sandbox_system (str, 0); eprintf ("{exit: %d, pid: %d, cmd: \"%s\"}", ret, pid, str); exit (0); return -1; #else #ifdef _MSC_VER -#pragma message ("r_sys_cmdbg is not implemented for this platform") +#pragma message ("rz_sys_cmdbg is not implemented for this platform") #else -#warning r_sys_cmdbg is not implemented for this platform +#warning rz_sys_cmdbg is not implemented for this platform #endif return -1; #endif } -R_API int r_sys_cmd(const char *str) { - if (r_sandbox_enable (0)) { +RZ_API int rz_sys_cmd(const char *str) { + if (rz_sandbox_enable (0)) { return false; } - return r_sandbox_system (str, 1); + return rz_sandbox_system (str, 1); } -R_API char *r_sys_cmd_str(const char *cmd, const char *input, int *len) { +RZ_API char *rz_sys_cmd_str(const char *cmd, const char *input, int *len) { char *output = NULL; - if (r_sys_cmd_str_full (cmd, input, &output, len, NULL)) { + if (rz_sys_cmd_str_full (cmd, input, &output, len, NULL)) { return output; } free (output); return NULL; } -R_API bool r_sys_mkdir(const char *dir) { +RZ_API bool rz_sys_mkdir(const char *dir) { bool ret; - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { return false; } #if __WINDOWS__ - LPTSTR dir_ = r_sys_conv_utf8_to_win (dir); + LPTSTR dir_ = rz_sys_conv_utf8_to_win (dir); ret = CreateDirectory (dir_, NULL) != 0; free (dir_); @@ -829,12 +829,12 @@ R_API bool r_sys_mkdir(const char *dir) { return ret; } -R_API bool r_sys_mkdirp(const char *dir) { +RZ_API bool rz_sys_mkdirp(const char *dir) { bool ret = true; char slash = R_SYS_DIR[0]; char *path = strdup (dir), *ptr = path; if (!path) { - eprintf ("r_sys_mkdirp: Unable to allocate memory\n"); + eprintf ("rz_sys_mkdirp: Unable to allocate memory\n"); return false; } if (*ptr == slash) { @@ -860,22 +860,22 @@ R_API bool r_sys_mkdirp(const char *dir) { break; } *ptr = 0; - if (!r_sys_mkdir (path) && r_sys_mkdir_failed ()) { - eprintf ("r_sys_mkdirp: fail '%s' of '%s'\n", path, dir); + if (!rz_sys_mkdir (path) && rz_sys_mkdir_failed ()) { + eprintf ("rz_sys_mkdirp: fail '%s' of '%s'\n", path, dir); free (path); return false; } *ptr = slash; ptr++; } - if (!r_sys_mkdir (path) && r_sys_mkdir_failed ()) { + if (!rz_sys_mkdir (path) && rz_sys_mkdir_failed ()) { ret = false; } free (path); return ret; } -R_API void r_sys_perror_str(const char *fun) { +RZ_API void rz_sys_perror_str(const char *fun) { #if __UNIX__ #pragma push_macro("perror") #undef perror @@ -893,10 +893,10 @@ R_API void r_sys_perror_str(const char *fun) { MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL )) { - char *err = r_sys_conv_win_to_utf8 (lpMsgBuf); + char *err = rz_sys_conv_win_to_utf8 (lpMsgBuf); if (err) { eprintf ("%s: (%#x) %s%s", fun, dw, err, - r_str_endswith (err, "\n") ? "" : "\n"); + rz_str_endswith (err, "\n") ? "" : "\n"); free (err); } LocalFree (lpMsgBuf); @@ -906,7 +906,7 @@ R_API void r_sys_perror_str(const char *fun) { #endif } -R_API bool r_sys_arch_match(const char *archstr, const char *arch) { +RZ_API bool rz_sys_arch_match(const char *archstr, const char *arch) { char *ptr; if (!archstr || !arch || !*archstr || !*arch) { return true; @@ -926,7 +926,7 @@ R_API bool r_sys_arch_match(const char *archstr, const char *arch) { return false; } -R_API int r_sys_arch_id(const char *arch) { +RZ_API int rz_sys_arch_id(const char *arch) { int i; for (i = 0; arch_bit_array[i].name; i++) { if (!strcmp (arch, arch_bit_array[i].name)) { @@ -936,7 +936,7 @@ R_API int r_sys_arch_id(const char *arch) { return 0; } -R_API const char *r_sys_arch_str(int arch) { +RZ_API const char *rz_sys_arch_str(int arch) { int i; for (i = 0; arch_bit_array[i].name; i++) { if (arch & arch_bit_array[i].bit) { @@ -947,13 +947,13 @@ R_API const char *r_sys_arch_str(int arch) { } #define USE_FORK 0 -R_API int r_sys_run(const ut8 *buf, int len) { +RZ_API int rz_sys_run(const ut8 *buf, int len) { const int sz = 4096; int pdelta, ret, (*cb)(); #if USE_FORK int st, pid; #endif -// TODO: define R_SYS_ALIGN_FORWARD in r_util.h +// TODO: define R_SYS_ALIGN_FORWARD in rz_util.h ut8 *ptr, *p = malloc ((sz + len) << 1); ptr = p; pdelta = ((size_t)(p)) & (4096 - 1); @@ -961,17 +961,17 @@ R_API int r_sys_run(const ut8 *buf, int len) { ptr += (4096 - pdelta); } if (!ptr || !buf) { - eprintf ("r_sys_run: Cannot run empty buffer\n"); + eprintf ("rz_sys_run: Cannot run empty buffer\n"); free (p); return false; } memcpy (ptr, buf, len); - r_mem_protect (ptr, sz, "rx"); - //r_mem_protect (ptr, sz, "rwx"); // try, ignore if fail + rz_mem_protect (ptr, sz, "rx"); + //rz_mem_protect (ptr, sz, "rwx"); // try, ignore if fail cb = (int (*)())ptr; #if USE_FORK #if __UNIX__ - pid = r_sys_fork (); + pid = rz_sys_fork (); #else pid = -1; #endif @@ -999,26 +999,26 @@ R_API int r_sys_run(const ut8 *buf, int len) { return ret; } -R_API int r_sys_run_rop(const ut8 *buf, int len) { +RZ_API int rz_sys_run_rop(const ut8 *buf, int len) { #if USE_FORK int st; #endif - // TODO: define R_SYS_ALIGN_FORWARD in r_util.h + // TODO: define R_SYS_ALIGN_FORWARD in rz_util.h ut8 *bufptr = malloc (len); if (!bufptr) { - eprintf ("r_sys_run_rop: Cannot allocate buffer\n"); + eprintf ("rz_sys_run_rop: Cannot allocate buffer\n"); return false; } if (!buf) { - eprintf ("r_sys_run_rop: Cannot execute empty rop chain\n"); + eprintf ("rz_sys_run_rop: Cannot execute empty rop chain\n"); free (bufptr); return false; } memcpy (bufptr, buf, len); #if USE_FORK #if __UNIX__ - pid_t pid = r_sys_fork (); + pid_t pid = rz_sys_fork (); #else pid = -1; #endif @@ -1031,7 +1031,7 @@ R_API int r_sys_run_rop(const ut8 *buf, int len) { } st = 0; if (waitpid (pid, &st, 0) == -1) { - eprintf ("r_sys_run_rop: waitpid failed\n"); + eprintf ("rz_sys_run_rop: waitpid failed\n"); free (bufptr); return -1; } @@ -1049,7 +1049,7 @@ R_API int r_sys_run_rop(const ut8 *buf, int len) { return 0; } -R_API bool r_is_heap (void *p) { +RZ_API bool rz_is_heap (void *p) { void *q = malloc (8); ut64 mask = UT64_MAX; ut64 addr = (ut64)(size_t)q; @@ -1061,7 +1061,7 @@ R_API bool r_is_heap (void *p) { return (((ut64)(size_t)p) == mask); } -R_API char *r_sys_pid_to_path(int pid) { +RZ_API char *rz_sys_pid_to_path(int pid) { #if __WINDOWS__ // TODO: add maximum path length support HANDLE processHandle; @@ -1071,7 +1071,7 @@ R_API char *r_sys_pid_to_path(int pid) { processHandle = OpenProcess (PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); if (!processHandle) { - eprintf ("r_sys_pid_to_path: Cannot open process.\n"); + eprintf ("rz_sys_pid_to_path: Cannot open process.\n"); return NULL; } DWORD length = GetModuleFileNameEx (processHandle, NULL, filename, maxlength); @@ -1080,32 +1080,32 @@ R_API char *r_sys_pid_to_path(int pid) { length = GetProcessImageFileName (processHandle, filename, maxlength); CloseHandle (processHandle); if (length == 0) { - eprintf ("r_sys_pid_to_path: Error calling GetProcessImageFileName\n"); + eprintf ("rz_sys_pid_to_path: Error calling GetProcessImageFileName\n"); return NULL; } // Convert NT path to win32 path - char *name = r_sys_conv_win_to_utf8 (filename); + char *name = rz_sys_conv_win_to_utf8 (filename); if (!name) { - eprintf ("r_sys_pid_to_path: Error converting to utf8\n"); + eprintf ("rz_sys_pid_to_path: Error converting to utf8\n"); return NULL; } char *tmp = strchr (name + 1, '\\'); if (!tmp) { free (name); - eprintf ("r_sys_pid_to_path: Malformed NT path\n"); + eprintf ("rz_sys_pid_to_path: Malformed NT path\n"); return NULL; } tmp = strchr (tmp + 1, '\\'); if (!tmp) { free (name); - eprintf ("r_sys_pid_to_path: Malformed NT path\n"); + eprintf ("rz_sys_pid_to_path: Malformed NT path\n"); return NULL; } length = tmp - name; tmp = malloc (length + 1); if (!tmp) { free (name); - eprintf ("r_sys_pid_to_path: Error allocating memory\n"); + eprintf ("rz_sys_pid_to_path: Error allocating memory\n"); return NULL; } strncpy (tmp, name, length); @@ -1113,27 +1113,27 @@ R_API char *r_sys_pid_to_path(int pid) { TCHAR device[MAX_PATH]; for (TCHAR drv[] = TEXT("A:"); drv[0] <= TEXT('Z'); drv[0]++) { if (QueryDosDevice (drv, device, maxlength) > 0) { - char *dvc = r_sys_conv_win_to_utf8 (device); + char *dvc = rz_sys_conv_win_to_utf8 (device); if (!dvc) { free (name); free (tmp); - eprintf ("r_sys_pid_to_path: Error converting to utf8\n"); + eprintf ("rz_sys_pid_to_path: Error converting to utf8\n"); return NULL; } if (!strcmp (tmp, dvc)) { free (tmp); free (dvc); - char *d = r_sys_conv_win_to_utf8 (drv); + char *d = rz_sys_conv_win_to_utf8 (drv); if (!d) { free (name); - eprintf ("r_sys_pid_to_path: Error converting to utf8\n"); + eprintf ("rz_sys_pid_to_path: Error converting to utf8\n"); return NULL; } - tmp = r_str_newf ("%s%s", d, &name[length]); + tmp = rz_str_newf ("%s%s", d, &name[length]); free (d); if (!tmp) { free (name); - eprintf ("r_sys_pid_to_path: Error calling r_str_newf\n"); + eprintf ("rz_sys_pid_to_path: Error calling rz_str_newf\n"); return NULL; } result = strdup (tmp); @@ -1146,7 +1146,7 @@ R_API char *r_sys_pid_to_path(int pid) { free (tmp); } else { CloseHandle (processHandle); - result = r_sys_conv_win_to_utf8 (filename); + result = rz_sys_conv_win_to_utf8 (filename); } return result; #elif __APPLE__ @@ -1184,7 +1184,7 @@ R_API char *r_sys_pid_to_path(int pid) { } if (ii.type == B_APP_IMAGE) { - r_str_ncpy (pathbuf, ii.name, MAXPATHLEN); + rz_str_ncpy (pathbuf, ii.name, MAXPATHLEN); } else { pathbuf[0] = '\0'; } @@ -1201,14 +1201,14 @@ R_API char *r_sys_pid_to_path(int pid) { #endif } -R_API void r_sys_env_init(void) { - char **envp = r_sys_get_environ (); +RZ_API void rz_sys_env_init(void) { + char **envp = rz_sys_get_environ (); if (envp) { - r_sys_set_environ (envp); + rz_sys_set_environ (envp); } } -R_API char **r_sys_get_environ(void) { +RZ_API char **rz_sys_get_environ(void) { #if __APPLE__ && !HAVE_ENVIRON env = *_NSGetEnviron(); #else @@ -1216,16 +1216,16 @@ R_API char **r_sys_get_environ(void) { #endif // return environ if available?? if (!env) { - env = r_lib_dl_sym (NULL, "environ"); + env = rz_lib_dl_sym (NULL, "environ"); } return env; } -R_API void r_sys_set_environ(char **e) { +RZ_API void rz_sys_set_environ(char **e) { env = e; } -R_API char *r_sys_whoami (char *buf) { +RZ_API char *rz_sys_whoami (char *buf) { char _buf[32]; int pid = getpid (); int hasbuf = (buf)? 1: 0; @@ -1236,28 +1236,28 @@ R_API char *r_sys_whoami (char *buf) { return hasbuf? buf: strdup (buf); } -R_API int r_sys_getpid(void) { +RZ_API int rz_sys_getpid(void) { #if __UNIX__ return getpid (); #elif __WINDOWS__ return GetCurrentProcessId(); #else -#warning r_sys_getpid not implemented for this platform +#warning rz_sys_getpid not implemented for this platform return -1; #endif } -R_API bool r_sys_tts(const char *txt, bool bg) { +RZ_API bool rz_sys_tts(const char *txt, bool bg) { int i; - r_return_val_if_fail (txt, false); + rz_return_val_if_fail (txt, false); const char *says[] = { "say", "termux-tts-speak", NULL }; for (i = 0; says[i]; i++) { - char *sayPath = r_file_path (says[i]); + char *sayPath = rz_file_path (says[i]); if (sayPath) { - char *line = r_str_replace (strdup (txt), "'", "\"", 1); - r_sys_cmdf ("\"%s\" '%s'%s", sayPath, line, bg? " &": ""); + char *line = rz_str_replace (strdup (txt), "'", "\"", 1); + rz_sys_cmdf ("\"%s\" '%s'%s", sayPath, line, bg? " &": ""); free (line); free (sayPath); return true; @@ -1266,11 +1266,11 @@ R_API bool r_sys_tts(const char *txt, bool bg) { return false; } -R_API const char *r_sys_prefix(const char *pfx) { +RZ_API const char *rz_sys_prefix(const char *pfx) { static char *prefix = NULL; if (!prefix) { #if __WINDOWS__ - prefix = r_sys_get_src_dir_w32 (); + prefix = rz_sys_get_src_dir_w32 (); if (!prefix) { prefix = strdup (R2_PREFIX); } @@ -1285,7 +1285,7 @@ R_API const char *r_sys_prefix(const char *pfx) { return prefix; } -R_API RSysInfo *r_sys_info(void) { +RZ_API RSysInfo *rz_sys_info(void) { #if __UNIX__ struct utsname un = {{0}}; if (uname (&un) != -1) { @@ -1313,8 +1313,8 @@ R_API RSysInfo *r_sys_info(void) { if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS) { - r_sys_perror ("r_sys_info/RegOpenKeyExA"); - r_sys_info_free (si); + rz_sys_perror ("rz_sys_info/RegOpenKeyExA"); + rz_sys_info_free (si); return NULL; } @@ -1345,7 +1345,7 @@ R_API RSysInfo *r_sys_info(void) { || type != REG_SZ) { goto beach; } - si->version = r_str_newf ("%d.%d.%s", major, minor, tmp); + si->version = rz_str_newf ("%d.%d.%s", major, minor, tmp); size = sizeof (tmp); if (RegQueryValueExA (key, "ReleaseId", NULL, &type, @@ -1361,7 +1361,7 @@ beach: return NULL; } -R_API void r_sys_info_free(RSysInfo *si) { +RZ_API void rz_sys_info_free(RSysInfo *si) { free (si->sysname); free (si->nodename); free (si->release); diff --git a/libr/util/syscmd.c b/librz/util/syscmd.c similarity index 65% rename from libr/util/syscmd.c rename to librz/util/syscmd.c index b291ee9a98..f6d2c4b0b2 100644 --- a/libr/util/syscmd.c +++ b/librz/util/syscmd.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2013-2018 - pancake */ -#include +#include #include #define FMT_NONE 0 @@ -15,15 +15,15 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n #endif const char *n = fpath; char *nn, *u_rwx = NULL; - int sz = r_file_size (n); + int sz = rz_file_size (n); int perm, uid = 0, gid = 0; int fch = '-'; if (!strncmp (fpath, "./", 2)) { fpath = fpath + 2; } - const bool isdir = r_file_is_directory (n); + const bool isdir = rz_file_is_directory (n); if (isdir) { - nn = r_str_append (strdup (fpath), "/"); + nn = rz_str_append (strdup (fpath), "/"); } else { nn = strdup (fpath); } @@ -34,7 +34,7 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n perm = isdir? 0755: 0644; if (!printfmt) { needs_newline = ((nth + 1) % 4)? 1: 0; - res = r_str_appendf (res, "%18s%s", nn, needs_newline? " ": "\n"); + res = rz_str_appendf (res, "%18s%s", nn, needs_newline? " ": "\n"); free (nn); return res; } @@ -47,7 +47,7 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n uid = sb.st_uid; gid = sb.st_gid; perm = sb.st_mode & 0777; - if (!(u_rwx = strdup (r_str_rwx_i (perm >> 6)))) { + if (!(u_rwx = strdup (rz_str_rwx_i (perm >> 6)))) { free (nn); return res; } @@ -73,7 +73,7 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n fch = isdir? 'd': '-'; #endif if (printfmt == 'q') { - res = r_str_appendf (res, "%s\n", nn); + res = rz_str_appendf (res, "%s\n", nn); } else if (printfmt == 'e') { const char *eDIR = "📁"; const char *eLNK = "📎"; @@ -91,24 +91,24 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n } else if (sb.st_mode & S_ISUID) { icon = eUID; #endif - } else if (r_str_casestr (nn, ".jpg") || r_str_casestr (nn, ".png") || r_str_casestr (nn, ".gif")) { + } else if (rz_str_casestr (nn, ".jpg") || rz_str_casestr (nn, ".png") || rz_str_casestr (nn, ".gif")) { icon = eIMG; } else if (*nn == '.') { icon = eHID; } - res = r_str_appendf (res, "%s %s\n", icon, nn); + res = rz_str_appendf (res, "%s %s\n", icon, nn); } else if (printfmt == FMT_RAW) { - res = r_str_appendf (res, "%c%s%s%s 1 %4d:%-4d %-10d %s\n", + res = rz_str_appendf (res, "%c%s%s%s 1 %4d:%-4d %-10d %s\n", isdir?'d': fch, u_rwx? u_rwx: "-", - r_str_rwx_i ((perm >> 3) & 7), - r_str_rwx_i (perm & 7), + rz_str_rwx_i ((perm >> 3) & 7), + rz_str_rwx_i (perm & 7), uid, gid, sz, nn); } else if (printfmt == FMT_JSON) { if (nth > 0) { - res = r_str_append (res, ","); + res = rz_str_append (res, ","); } - res = r_str_appendf (res, "{\"name\":\"%s\",\"size\":%d,\"uid\":%d," + res = rz_str_appendf (res, "{\"name\":\"%s\",\"size\":%d,\"uid\":%d," "\"gid\":%d,\"perm\":%d,\"isdir\":%s}", name, sz, uid, gid, perm, isdir? "true": "false"); } @@ -117,8 +117,8 @@ static char *showfile(char *res, const int nth, const char *fpath, const char *n return res; } -// TODO: Move into r_util .. r_print maybe? r_cons dep is annoying -R_API char *r_syscmd_ls(const char *input) { +// TODO: Move into rz_util .. rz_print maybe? rz_cons dep is annoying +RZ_API char *rz_syscmd_ls(const char *input) { char *res = NULL; const char *path = "."; char *d = NULL; @@ -126,8 +126,8 @@ R_API char *r_syscmd_ls(const char *input) { char *homepath = NULL; char *pattern = NULL; int printfmt = 0; - RListIter *iter; - RList *files; + RzListIter *iter; + RzList *files; char *name; char *dir; int off; @@ -139,7 +139,7 @@ R_API char *r_syscmd_ls(const char *input) { printfmt = 'q'; input++; } - if (r_sandbox_enable (0)) { + if (rz_sandbox_enable (0)) { eprintf ("Sandbox forbids listing directories\n"); return NULL; } @@ -151,15 +151,15 @@ R_API char *r_syscmd_ls(const char *input) { eprintf ("Usage: ls ([-e,-l,-j,-q]) ([path]) # long, json, quiet\n"); } else if ((!strncmp (input, "-e", 2))) { printfmt = 'e'; - path = r_str_trim_head_ro (path + 1); + path = rz_str_trim_head_ro (path + 1); } else if ((!strncmp (input, "-q", 2))) { printfmt = 'q'; - path = r_str_trim_head_ro (path + 1); + path = rz_str_trim_head_ro (path + 1); } else if ((!strncmp (input, "-l", 2)) || (!strncmp (input, "-j", 2))) { // mode = 'l'; if (input[2]) { printfmt = (input[2] == 'j') ? FMT_JSON : FMT_RAW; - path = r_str_trim_head_ro (input + 2); + path = rz_str_trim_head_ro (input + 2); if (!*path) { path = "."; } @@ -173,19 +173,19 @@ R_API char *r_syscmd_ls(const char *input) { if (!path || !*path) { path = "."; } else if (!strncmp (path, "~/", 2)) { - homepath = r_str_home (path + 2); + homepath = rz_str_home (path + 2); if (homepath) { path = (const char *)homepath; } } else if (*path == '$') { if (!strncmp (path + 1, "home", 4) || !strncmp (path + 1, "HOME", 4)) { - homepath = r_str_home ((strlen (path) > 5)? path + 6: NULL); + homepath = rz_str_home ((strlen (path) > 5)? path + 6: NULL); if (homepath) { path = (const char *)homepath; } } } - if (!r_file_is_directory (path)) { + if (!rz_file_is_directory (path)) { p = strrchr (path, '/'); if (p) { off = p - path; @@ -204,31 +204,31 @@ R_API char *r_syscmd_ls(const char *input) { } else { pattern = strdup ("*"); } - if (r_file_is_regular (path)) { + if (rz_file_is_regular (path)) { res = showfile (res, 0, path, path, printfmt); free (homepath); free (pattern); free (d); return res; } - files = r_sys_dir (path); + files = rz_sys_dir (path); if (path[strlen (path) - 1] == '/') { dir = strdup (path); } else { - dir = r_str_append (strdup (path), "/"); + dir = rz_str_append (strdup (path), "/"); } int nth = 0; if (printfmt == FMT_JSON) { res = strdup ("["); } needs_newline = 0; - r_list_foreach (files, iter, name) { - char *n = r_str_append (strdup (dir), name); + rz_list_foreach (files, iter, name) { + char *n = rz_str_append (strdup (dir), name); if (!n) { break; } - if (r_str_glob (name, pattern)) { + if (rz_str_glob (name, pattern)) { if (*n) { res = showfile (res, nth, n, name, printfmt); } @@ -237,16 +237,16 @@ R_API char *r_syscmd_ls(const char *input) { free (n); } if (printfmt == FMT_JSON) { - res = r_str_append (res, "]"); + res = rz_str_append (res, "]"); } if (needs_newline) { - res = r_str_append (res, "\n"); + res = rz_str_append (res, "\n"); } free (dir); free (d); free (homepath); free (pattern); - r_list_free (files); + rz_list_free (files); return res; } @@ -255,9 +255,9 @@ static int cmpstr (const void *_a, const void *_b) { return (int)strcmp (a, b); } -R_API char *r_syscmd_sort(const char *file) { +RZ_API char *rz_syscmd_sort(const char *file) { const char *p = NULL; - RList *list = NULL; + RzList *list = NULL; if (file) { if ((p = strchr (file, ' '))) { p = p + 1; @@ -267,15 +267,15 @@ R_API char *r_syscmd_sort(const char *file) { } if (p && *p) { char *filename = strdup (p); - r_str_trim (filename); - char *data = r_file_slurp (filename, NULL); + rz_str_trim (filename); + char *data = rz_file_slurp (filename, NULL); if (!data) { eprintf ("No such file or directory\n"); } else { - list = r_str_split_list (data, "\n", 0); - r_list_sort (list, cmpstr); - data = r_list_to_str (list, '\n'); - r_list_free (list); + list = rz_str_split_list (data, "\n", 0); + rz_list_sort (list, cmpstr); + data = rz_list_to_str (list, '\n'); + rz_list_free (list); } free (filename); return data; @@ -285,7 +285,7 @@ R_API char *r_syscmd_sort(const char *file) { return NULL; } -R_API char *r_syscmd_head(const char *file, int count) { +RZ_API char *rz_syscmd_head(const char *file, int count) { const char *p = NULL; if (file) { if ((p = strchr (file, ' '))) { @@ -296,8 +296,8 @@ R_API char *r_syscmd_head(const char *file, int count) { } if (p && *p) { char *filename = strdup (p); - r_str_trim (filename); - char *data = r_file_slurp_lines (filename, 1, count); + rz_str_trim (filename); + char *data = rz_file_slurp_lines (filename, 1, count); if (!data) { eprintf ("No such file or directory\n"); } @@ -309,7 +309,7 @@ R_API char *r_syscmd_head(const char *file, int count) { return NULL; } -R_API char *r_syscmd_tail(const char *file, int count) { +RZ_API char *rz_syscmd_tail(const char *file, int count) { const char *p = NULL; if (file) { if ((p = strchr (file, ' '))) { @@ -320,8 +320,8 @@ R_API char *r_syscmd_tail(const char *file, int count) { } if (p && *p) { char *filename = strdup (p); - r_str_trim (filename); - char *data = r_file_slurp_lines_from_bottom (filename, count); + rz_str_trim (filename); + char *data = rz_file_slurp_lines_from_bottom (filename, count); if (!data) { eprintf ("No such file or directory\n"); } @@ -333,9 +333,9 @@ R_API char *r_syscmd_tail(const char *file, int count) { return NULL; } -R_API char *r_syscmd_uniq(const char *file) { +RZ_API char *rz_syscmd_uniq(const char *file) { const char *p = NULL; - RList *list = NULL; + RzList *list = NULL; if (file) { if ((p = strchr (file, ' '))) { p = p + 1; @@ -345,16 +345,16 @@ R_API char *r_syscmd_uniq(const char *file) { } if (p && *p) { char *filename = strdup (p); - r_str_trim (filename); - char *data = r_file_slurp (filename, NULL); + rz_str_trim (filename); + char *data = rz_file_slurp (filename, NULL); if (!data) { eprintf ("No such file or directory\n"); } else { - list = r_str_split_list (data, "\n", 0); - RList *uniq_list = r_list_uniq (list, cmpstr); - data = r_list_to_str (uniq_list, '\n'); - r_list_free (uniq_list); - r_list_free (list); + list = rz_str_split_list (data, "\n", 0); + RzList *uniq_list = rz_list_uniq (list, cmpstr); + data = rz_list_to_str (uniq_list, '\n'); + rz_list_free (uniq_list); + rz_list_free (list); } free (filename); return data; @@ -364,9 +364,9 @@ R_API char *r_syscmd_uniq(const char *file) { return NULL; } -R_API char *r_syscmd_join(const char *file1, const char *file2) { +RZ_API char *rz_syscmd_join(const char *file1, const char *file2) { const char *p1 = NULL, *p2 = NULL; - RList *list1, *list2, *list = r_list_newf (NULL); + RzList *list1, *list2, *list = rz_list_newf (NULL); if (!list) { return NULL; } @@ -387,20 +387,20 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) { if (p1 && *p1 && p2 && *p2 ) { char *filename1 = strdup (p1); char *filename2 = strdup (p2); - r_str_trim (filename1); - r_str_trim (filename2); - char *data1 = r_file_slurp (filename1, NULL); - char *data2 = r_file_slurp (filename2, NULL); + rz_str_trim (filename1); + rz_str_trim (filename2); + char *data1 = rz_file_slurp (filename1, NULL); + char *data2 = rz_file_slurp (filename2, NULL); char *data = NULL; - RListIter *iter1, *iter2; + RzListIter *iter1, *iter2; if (!data1 && !data2) { eprintf ("No such files or directory\n"); } else { - list1 = r_str_split_list (data1, "\n", 0); - list2 = r_str_split_list (data2, "\n", 0); + list1 = rz_str_split_list (data1, "\n", 0); + list2 = rz_str_split_list (data2, "\n", 0); char *str1, *str2; - r_list_foreach (list1, iter1, str1) { + rz_list_foreach (list1, iter1, str1) { char *field = strdup (str1); // extract comman field char *end = strchr (field, ' '); if (end) { @@ -409,22 +409,22 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) { free (field); continue; } - r_list_foreach (list2, iter2, str2) { - if (r_str_startswith (str2, field)) { - char *out = r_str_new (field); + rz_list_foreach (list2, iter2, str2) { + if (rz_str_startswith (str2, field)) { + char *out = rz_str_new (field); char *first = strchr (str1, ' '); char *second = strchr (str2, ' '); - r_str_append (out, first ? first : " "); - r_str_append (out, second ? second : " "); - r_list_append (list, out); + rz_str_append (out, first ? first : " "); + rz_str_append (out, second ? second : " "); + rz_list_append (list, out); } } free (field); } - data = r_list_to_str (list, '\n'); - r_list_free (list); - r_list_free (list1); - r_list_free (list2); + data = rz_list_to_str (list, '\n'); + rz_list_free (list); + rz_list_free (list1); + rz_list_free (list2); } free (filename1); free (filename2); @@ -435,7 +435,7 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) { return NULL; } -R_API char *r_syscmd_cat(const char *file) { +RZ_API char *rz_syscmd_cat(const char *file) { const char *p = NULL; if (file) { if ((p = strchr (file, ' '))) { @@ -446,8 +446,8 @@ R_API char *r_syscmd_cat(const char *file) { } if (p && *p) { char *filename = strdup (p); - r_str_trim (filename); - char *data = r_file_slurp (filename, NULL); + rz_str_trim (filename); + char *data = rz_file_slurp (filename, NULL); if (!data) { eprintf ("No such file or directory\n"); } @@ -459,19 +459,19 @@ R_API char *r_syscmd_cat(const char *file) { return NULL; } -R_API char *r_syscmd_mkdir(const char *dir) { - const char *suffix = r_str_trim_head_ro (strchr (dir, ' ')); +RZ_API char *rz_syscmd_mkdir(const char *dir) { + const char *suffix = rz_str_trim_head_ro (strchr (dir, ' ')); if (!suffix || !strncmp (suffix, "-p", 3)) { - return r_str_dup (NULL, "Usage: mkdir [-p] [directory]\n"); + return rz_str_dup (NULL, "Usage: mkdir [-p] [directory]\n"); } int ret; char *dirname = (!strncmp (suffix, "-p ", 3)) ? strdup (suffix + 3): strdup (suffix); - r_str_trim (dirname); - ret = r_sys_mkdirp (dirname); + rz_str_trim (dirname); + ret = rz_sys_mkdirp (dirname); if (!ret) { - if (r_sys_mkdir_failed ()) { - char *res = r_str_newf ("Cannot create \"%s\"\n", dirname); + if (rz_sys_mkdir_failed ()) { + char *res = rz_str_newf ("Cannot create \"%s\"\n", dirname); free (dirname); return res; } @@ -480,17 +480,17 @@ R_API char *r_syscmd_mkdir(const char *dir) { return NULL; } -R_API bool r_syscmd_mv(const char *input) { +RZ_API bool rz_syscmd_mv(const char *input) { if (strlen (input) < 3) { eprintf ("Usage: mv src dst\n"); return false; } input = input + 2; - if (!r_sandbox_enable (0)) { + if (!rz_sandbox_enable (0)) { #if __WINDOWS__ - r_sys_cmdf ("move %s", input); + rz_sys_cmdf ("move %s", input); #else - r_sys_cmdf ("mv %s", input); + rz_sys_cmdf ("mv %s", input); #endif } return false; diff --git a/libr/util/table.c b/librz/util/table.c similarity index 55% rename from libr/util/table.c rename to librz/util/table.c index 3b69a2db23..029b7ac4ab 100644 --- a/libr/util/table.c +++ b/librz/util/table.c @@ -1,56 +1,56 @@ /* radare - LGPL - Copyright 2019-2020 - pancake */ -#include -#include "r_cons.h" +#include +#include "rz_cons.h" -// cant do that without globals because RList doesnt have void *user :( +// cant do that without globals because RzList doesnt have void *user :( static int Gnth = 0; -static RListComparator Gcmp = NULL; +static RzListComparator Gcmp = NULL; static int sortString(const void *a, const void *b) { return strcmp (a, b); } static int sortNumber(const void *a, const void *b) { - return r_num_get (NULL, a) - r_num_get (NULL, b); + return rz_num_get (NULL, a) - rz_num_get (NULL, b); } // maybe just index by name instead of exposing those symbols as global -static RTableColumnType r_table_type_string = { "string", sortString }; -static RTableColumnType r_table_type_number = { "number", sortNumber }; -static RTableColumnType r_table_type_bool = { "bool", sortNumber }; +static RTableColumnType rz_table_type_string = { "string", sortString }; +static RTableColumnType rz_table_type_number = { "number", sortNumber }; +static RTableColumnType rz_table_type_bool = { "bool", sortNumber }; -R_API RTableColumnType *r_table_type (const char *name) { +RZ_API RTableColumnType *rz_table_type (const char *name) { if (!strcmp (name, "bool")) { - return &r_table_type_bool; + return &rz_table_type_bool; } if (!strcmp (name, "boolean")) { - return &r_table_type_bool; + return &rz_table_type_bool; } if (!strcmp (name, "string")) { - return &r_table_type_string; + return &rz_table_type_string; } if (!strcmp (name, "number")) { - return &r_table_type_number; + return &rz_table_type_number; } return NULL; } // TODO: unused for now, maybe good to call after filter :? static void __table_adjust(RTable *t) { - RListIter *iter, *iter2; + RzListIter *iter, *iter2; RTableColumn *col; RTableRow *row; - r_list_foreach (t->cols, iter, col) { - int itemLength = r_str_len_utf8_ansi (col->name) + 1; + rz_list_foreach (t->cols, iter, col) { + int itemLength = rz_str_len_utf8_ansi (col->name) + 1; col->width = itemLength; } - r_list_foreach (t->rows, iter, row) { + rz_list_foreach (t->rows, iter, row) { const char *item; int ncol = 0; - r_list_foreach (row->items, iter2, item) { - int itemLength = r_str_len_utf8_ansi (item) + 1; - RTableColumn *c = r_list_get_n (t->cols, ncol); + rz_list_foreach (row->items, iter2, item) { + int itemLength = rz_str_len_utf8_ansi (item) + 1; + RTableColumn *c = rz_list_get_n (t->cols, ncol); if (c) { c->width = R_MAX (c->width, itemLength); } @@ -59,19 +59,19 @@ static void __table_adjust(RTable *t) { } } -R_API void r_table_row_free(void *_row) { +RZ_API void rz_table_row_free(void *_row) { RTableRow *row = _row; - r_list_free (row->items); + rz_list_free (row->items); free (row); } -R_API void r_table_column_free(void *_col) { +RZ_API void rz_table_column_free(void *_col) { RTableColumn *col = _col; free (col->name); free (col); } -R_API RTableColumn *r_table_column_clone(RTableColumn *col) { +RZ_API RTableColumn *rz_table_column_clone(RTableColumn *col) { RTableColumn *c = R_NEW0 (RTableColumn); if (!c) { return NULL; @@ -81,69 +81,69 @@ R_API RTableColumn *r_table_column_clone(RTableColumn *col) { return c; } -R_API RTable *r_table_new(void) { +RZ_API RTable *rz_table_new(void) { RTable *t = R_NEW0 (RTable); if (t) { t->showHeader = true; - t->cols = r_list_newf (r_table_column_free); - t->rows = r_list_newf (r_table_row_free); + t->cols = rz_list_newf (rz_table_column_free); + t->rows = rz_list_newf (rz_table_row_free); t->showSum = false; } return t; } -R_API void r_table_free(RTable *t) { +RZ_API void rz_table_free(RTable *t) { if (!t) { return; } - r_list_free (t->cols); - r_list_free (t->rows); + rz_list_free (t->cols); + rz_list_free (t->rows); free (t); } -R_API void r_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxWidth) { +RZ_API void rz_table_add_column(RTable *t, RTableColumnType *type, const char *name, int maxWidth) { RTableColumn *c = R_NEW0 (RTableColumn); if (c) { c->name = strdup (name); c->maxWidth = maxWidth; c->type = type; - int itemLength = r_str_len_utf8_ansi (name) + 1; + int itemLength = rz_str_len_utf8_ansi (name) + 1; c->width = itemLength; - r_list_append (t->cols, c); + rz_list_append (t->cols, c); c->total = -1; } } -R_API RTableRow *r_table_row_new(RList *items) { +RZ_API RTableRow *rz_table_row_new(RzList *items) { RTableRow *row = R_NEW (RTableRow); row->items = items; return row; } -static bool __addRow(RTable *t, RList *items, const char *arg, int col) { - int itemLength = r_str_len_utf8_ansi (arg) + 1; - RTableColumn *c = r_list_get_n (t->cols, col); +static bool __addRow(RTable *t, RzList *items, const char *arg, int col) { + int itemLength = rz_str_len_utf8_ansi (arg) + 1; + RTableColumn *c = rz_list_get_n (t->cols, col); if (c) { c->width = R_MAX (c->width, itemLength); - r_list_append (items, strdup (arg)); + rz_list_append (items, strdup (arg)); return true; } return false; } -R_API void r_table_add_row_list(RTable *t, RList *items) { - RTableRow *row = r_table_row_new (items); - r_list_append (t->rows, row); +RZ_API void rz_table_add_row_list(RTable *t, RzList *items) { + RTableRow *row = rz_table_row_new (items); + rz_list_append (t->rows, row); // throw warning if not enough columns defined in header - t->totalCols = R_MAX (t->totalCols, r_list_length (items)); + t->totalCols = R_MAX (t->totalCols, rz_list_length (items)); } -R_API void r_table_set_columnsf(RTable *t, const char *fmt, ...) { +RZ_API void rz_table_set_columnsf(RTable *t, const char *fmt, ...) { va_list ap; va_start (ap, fmt); - RTableColumnType *typeString = r_table_type ("string"); - RTableColumnType *typeNumber = r_table_type ("number"); - RTableColumnType *typeBool = r_table_type ("bool"); + RTableColumnType *typeString = rz_table_type ("string"); + RTableColumnType *typeNumber = rz_table_type ("number"); + RTableColumnType *typeBool = rz_table_type ("bool"); const char *name; const char *f = fmt; for (;*f;f++) { @@ -153,18 +153,18 @@ R_API void r_table_set_columnsf(RTable *t, const char *fmt, ...) { } switch (*f) { case 'b': - r_table_add_column (t, typeBool, name, 0); + rz_table_add_column (t, typeBool, name, 0); break; case 's': case 'z': - r_table_add_column (t, typeString, name, 0); + rz_table_add_column (t, typeString, name, 0); break; case 'i': case 'd': case 'n': case 'x': case 'X': - r_table_add_column (t, typeNumber, name, 0); + rz_table_add_column (t, typeNumber, name, 0); break; default: eprintf ("Invalid format string char '%c', use 's' or 'n'\n", *f); @@ -174,10 +174,10 @@ R_API void r_table_set_columnsf(RTable *t, const char *fmt, ...) { va_end(ap); } -R_API void r_table_add_rowf(RTable *t, const char *fmt, ...) { +RZ_API void rz_table_add_rowf(RTable *t, const char *fmt, ...) { va_list ap; va_start (ap, fmt); - RList *list = r_list_newf (free); + RzList *list = rz_list_newf (free); const char *f = fmt; const char *arg = NULL; for (; *f; f++) { @@ -185,32 +185,32 @@ R_API void r_table_add_rowf(RTable *t, const char *fmt, ...) { case 's': case 'z': arg = va_arg (ap, const char *); - r_list_append (list, strdup (arg? arg: "")); + rz_list_append (list, strdup (arg? arg: "")); break; case 'b': - r_list_append (list, r_str_new (r_str_bool (va_arg (ap, int)))); + rz_list_append (list, rz_str_new (rz_str_bool (va_arg (ap, int)))); break; case 'i': case 'd': - r_list_append (list, r_str_newf ("%d", va_arg (ap, int))); + rz_list_append (list, rz_str_newf ("%d", va_arg (ap, int))); break; case 'n': - r_list_append (list, r_str_newf ("%"PFMT64d, va_arg (ap, ut64))); + rz_list_append (list, rz_str_newf ("%"PFMT64d, va_arg (ap, ut64))); break; case 'u': - r_list_append (list, r_num_units (NULL, 32, va_arg (ap, ut64))); + rz_list_append (list, rz_num_units (NULL, 32, va_arg (ap, ut64))); break; case 'x': case 'X': { ut64 n = va_arg (ap, ut64); if (n == UT64_MAX) { - r_list_append (list, strdup ("-1")); + rz_list_append (list, strdup ("-1")); } else { if (*f == 'X') { - r_list_append (list, r_str_newf ("0x%08"PFMT64x, n)); + rz_list_append (list, rz_str_newf ("0x%08"PFMT64x, n)); } else { - r_list_append (list, r_str_newf ("0x%"PFMT64x, n)); + rz_list_append (list, rz_str_newf ("0x%"PFMT64x, n)); } } } @@ -221,14 +221,14 @@ R_API void r_table_add_rowf(RTable *t, const char *fmt, ...) { } } va_end(ap); - r_table_add_row_list (t, list); + rz_table_add_row_list (t, list); } -R_API void r_table_add_row(RTable *t, const char *name, ...) { +RZ_API void rz_table_add_row(RTable *t, const char *name, ...) { va_list ap; va_start (ap, name); int col = 0; - RList *items = r_list_newf (free); + RzList *items = rz_list_newf (free); __addRow (t, items, name, col++); for (;;) { const char *arg = va_arg (ap, const char *); @@ -240,47 +240,47 @@ R_API void r_table_add_row(RTable *t, const char *name, ...) { col++; } va_end (ap); - RTableRow *row = r_table_row_new (items); - r_list_append (t->rows, row); + RTableRow *row = rz_table_row_new (items); + rz_list_append (t->rows, row); // throw warning if not enough columns defined in header - t->totalCols = R_MAX (t->totalCols, r_list_length (items)); + t->totalCols = R_MAX (t->totalCols, rz_list_length (items)); } // import / export static int __strbuf_append_col_aligned_fancy(RTable *t, RStrBuf *sb, RTableColumn *col, char *str) { - RCons *cons = (RCons *) t->cons; + RzCons *cons = (RzCons *) t->cons; const char *v_line = (cons && (cons->use_utf8 || cons->use_utf8_curvy)) ? RUNE_LINE_VERT : "|"; - int ll = r_strbuf_length (sb); + int ll = rz_strbuf_length (sb); switch (col->align) { case R_TABLE_ALIGN_LEFT: - r_strbuf_appendf (sb, "%s %-*s ", v_line, col->width, str); + rz_strbuf_appendf (sb, "%s %-*s ", v_line, col->width, str); break; case R_TABLE_ALIGN_RIGHT: - r_strbuf_appendf (sb, "%s %*s ", v_line, col->width, str); + rz_strbuf_appendf (sb, "%s %*s ", v_line, col->width, str); break; case R_TABLE_ALIGN_CENTER: { - int len = r_str_len_utf8 (str); + int len = rz_str_len_utf8 (str); int pad = (col->width - len) / 2; int left = col->width - (pad * 2 + len); - r_strbuf_appendf (sb, "%s %-*s ", v_line, pad, " "); - r_strbuf_appendf (sb, "%-*s ", pad + left, str); + rz_strbuf_appendf (sb, "%s %-*s ", v_line, pad, " "); + rz_strbuf_appendf (sb, "%-*s ", pad + left, str); break; } } - return r_strbuf_length (sb) - ll; + return rz_strbuf_length (sb) - ll; } static void __computeTotal(RTable *t) { RTableRow *row; - RListIter *iter, *iter2; - r_list_foreach (t->rows, iter, row) { + RzListIter *iter, *iter2; + rz_list_foreach (t->rows, iter, row) { char *item; int c = 0; - r_list_foreach (row->items, iter2, item) { - RTableColumn *col = r_list_get_n (t->cols, c); - if (!r_str_cmp (col->type->name, "number", r_str_ansi_len ("number")) && r_str_isnumber (item)) { + rz_list_foreach (row->items, iter2, item) { + RTableColumn *col = rz_list_get_n (t->cols, c); + if (!rz_str_cmp (col->type->name, "number", rz_str_ansi_len ("number")) && rz_str_isnumber (item)) { if (col->total < 0) { col->total = 0; } @@ -291,79 +291,79 @@ static void __computeTotal(RTable *t) { } } -R_API char *r_table_tofancystring(RTable *t) { - if (r_list_length (t->cols) == 0) { +RZ_API char *rz_table_tofancystring(RTable *t) { + if (rz_list_length (t->cols) == 0) { return strdup (""); } - RStrBuf *sb = r_strbuf_new (""); + RStrBuf *sb = rz_strbuf_new (""); RTableRow *row; RTableColumn *col; - RCons *cons = (RCons *)t->cons; - RListIter *iter, *iter2; + RzCons *cons = (RzCons *)t->cons; + RzListIter *iter, *iter2; bool useUtf8 = (cons && cons->use_utf8); bool useUtf8Curvy = (cons && cons->use_utf8_curvy); const char *v_line = useUtf8 || useUtf8Curvy ? RUNE_LINE_VERT : "|"; const char *h_line = useUtf8 || useUtf8Curvy ? RUNE_LINE_HORIZ : "-"; const char *l_intersect = useUtf8 || useUtf8Curvy ? RUNE_LINE_VERT : ")"; - const char *r_intersect = useUtf8 || useUtf8Curvy ? RUNE_LINE_VERT : "("; + const char *rz_intersect = useUtf8 || useUtf8Curvy ? RUNE_LINE_VERT : "("; const char *tl_corner = useUtf8 ? (useUtf8Curvy ? RUNE_CURVE_CORNER_TL : RUNE_CORNER_TL) : "."; const char *tr_corner = useUtf8 ? (useUtf8Curvy ? RUNE_CURVE_CORNER_TR : RUNE_CORNER_TR) : "."; const char *bl_corner = useUtf8 ? (useUtf8Curvy ? RUNE_CURVE_CORNER_BL : RUNE_CORNER_BL) : "`"; const char *br_corner = useUtf8 ? (useUtf8Curvy ? RUNE_CURVE_CORNER_BR : RUNE_CORNER_BR) : "'"; __table_adjust (t); - r_list_foreach (t->cols, iter, col) { + rz_list_foreach (t->cols, iter, col) { __strbuf_append_col_aligned_fancy (t, sb, col, col->name); } - int len = r_str_len_utf8_ansi (r_strbuf_get (sb)) - 1; + int len = rz_str_len_utf8_ansi (rz_strbuf_get (sb)) - 1; int maxlen = len; - char *h_line_str = r_str_repeat (h_line, maxlen); + char *h_line_str = rz_str_repeat (h_line, maxlen); { - char *s = r_str_newf ("%s%s%s\n", tl_corner, h_line_str, tr_corner); - r_strbuf_prepend (sb, s); + char *s = rz_str_newf ("%s%s%s\n", tl_corner, h_line_str, tr_corner); + rz_strbuf_prepend (sb, s); free (s); } - r_strbuf_appendf (sb, "%s\n%s%s%s\n", v_line, l_intersect, h_line_str, r_intersect); - r_list_foreach (t->rows, iter, row) { + rz_strbuf_appendf (sb, "%s\n%s%s%s\n", v_line, l_intersect, h_line_str, rz_intersect); + rz_list_foreach (t->rows, iter, row) { char *item; int c = 0; - r_list_foreach (row->items, iter2, item) { - RTableColumn *col = r_list_get_n (t->cols, c); + rz_list_foreach (row->items, iter2, item) { + RTableColumn *col = rz_list_get_n (t->cols, c); if (col) { int l = __strbuf_append_col_aligned_fancy (t, sb, col, item); len = R_MAX (len, l); } c++; } - r_strbuf_appendf (sb, "%s\n", v_line); + rz_strbuf_appendf (sb, "%s\n", v_line); } if (t->showSum) { char tmp[64]; __computeTotal (t); - r_strbuf_appendf (sb, "%s%s%s\n", l_intersect, h_line_str, r_intersect); - r_list_foreach (t->cols, iter, col) { + rz_strbuf_appendf (sb, "%s%s%s\n", l_intersect, h_line_str, rz_intersect); + rz_list_foreach (t->cols, iter, col) { char *num = col->total == -1 ? "" : sdb_itoa (col->total, tmp, 10); int l = __strbuf_append_col_aligned_fancy (t, sb, col, num); len = R_MAX (len, l); } - r_strbuf_appendf (sb, "%s\n", v_line); + rz_strbuf_appendf (sb, "%s\n", v_line); } - r_strbuf_appendf (sb, "%s%s%s\n", bl_corner, h_line_str, br_corner); + rz_strbuf_appendf (sb, "%s%s%s\n", bl_corner, h_line_str, br_corner); free (h_line_str); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } static int __strbuf_append_col_aligned(RStrBuf *sb, RTableColumn *col, const char *str, bool nopad) { - int ll = r_strbuf_length (sb); + int ll = rz_strbuf_length (sb); if (nopad) { - r_strbuf_appendf (sb, "%s", str); + rz_strbuf_appendf (sb, "%s", str); } else { char *pad = ""; int padlen = 0; - int len1 = r_str_len_utf8 (str); - int len2 = r_str_len_utf8_ansi (str); + int len1 = rz_str_len_utf8 (str); + int len2 = rz_str_len_utf8_ansi (str); if (len1 > len2) { if (len2 < col->width) { padlen = col->width - len2; @@ -371,150 +371,150 @@ static int __strbuf_append_col_aligned(RStrBuf *sb, RTableColumn *col, const cha } switch (col->align) { case R_TABLE_ALIGN_LEFT: - pad = r_str_repeat (" ", padlen); - r_strbuf_appendf (sb, "%-*s%s", col->width, str, pad); + pad = rz_str_repeat (" ", padlen); + rz_strbuf_appendf (sb, "%-*s%s", col->width, str, pad); free (pad); break; case R_TABLE_ALIGN_RIGHT: - pad = r_str_repeat (" ", padlen); - r_strbuf_appendf (sb, "%s%*s ", pad, col->width, str); + pad = rz_str_repeat (" ", padlen); + rz_strbuf_appendf (sb, "%s%*s ", pad, col->width, str); free (pad); break; case R_TABLE_ALIGN_CENTER: { int pad = (col->width - len2) / 2; int left = col->width - (pad * 2 + len2); - r_strbuf_appendf (sb, "%-*s", pad, " "); - r_strbuf_appendf (sb, "%-*s ", pad + left, str); + rz_strbuf_appendf (sb, "%-*s", pad, " "); + rz_strbuf_appendf (sb, "%-*s ", pad + left, str); break; } } } - return r_strbuf_length (sb) - ll; + return rz_strbuf_length (sb) - ll; } -R_API char *r_table_tostring(RTable *t) { +RZ_API char *rz_table_tostring(RTable *t) { if (t->showCSV) { - return r_table_tocsv (t); + return rz_table_tocsv (t); } if (t->showJSON) { - char *s = r_table_tojson (t); - char *q = r_str_newf ("%s\n", s);; + char *s = rz_table_tojson (t); + char *q = rz_str_newf ("%s\n", s);; free (s); return q; } if (t->showFancy) { - return r_table_tofancystring (t); + return rz_table_tofancystring (t); } - return r_table_tosimplestring (t); + return rz_table_tosimplestring (t); } -R_API char *r_table_tosimplestring(RTable *t) { - RStrBuf *sb = r_strbuf_new (""); +RZ_API char *rz_table_tosimplestring(RTable *t) { + RStrBuf *sb = rz_strbuf_new (""); RTableRow *row; RTableColumn *col; - RListIter *iter, *iter2; - RCons *cons = (RCons *) t->cons; + RzListIter *iter, *iter2; + RzCons *cons = (RzCons *) t->cons; const char *h_line = (cons && (cons->use_utf8 || cons->use_utf8_curvy)) ? RUNE_LONG_LINE_HORIZ : "-"; __table_adjust (t); int maxlen = 0; if (t->showHeader) { - r_list_foreach (t->cols, iter, col) { + rz_list_foreach (t->cols, iter, col) { bool nopad = !iter->n; int ll = __strbuf_append_col_aligned (sb, col, col->name, nopad); maxlen = R_MAX (maxlen, ll); } - int len = r_str_len_utf8_ansi (r_strbuf_get (sb)); - char *l = r_str_repeat (h_line, R_MAX (maxlen, len)); + int len = rz_str_len_utf8_ansi (rz_strbuf_get (sb)); + char *l = rz_str_repeat (h_line, R_MAX (maxlen, len)); if (l) { - r_strbuf_appendf (sb, "\n%s\n", l); + rz_strbuf_appendf (sb, "\n%s\n", l); free (l); } } - r_list_foreach (t->rows, iter, row) { + rz_list_foreach (t->rows, iter, row) { char *item; int c = 0; - r_list_foreach (row->items, iter2, item) { + rz_list_foreach (row->items, iter2, item) { bool nopad = !iter2->n; - RTableColumn *col = r_list_get_n (t->cols, c); + RTableColumn *col = rz_list_get_n (t->cols, c); if (col) { (void)__strbuf_append_col_aligned (sb, col, item, nopad); } c++; } - r_strbuf_append (sb, "\n"); + rz_strbuf_append (sb, "\n"); } if (t->showSum) { char tmp[64]; __computeTotal (t); if (maxlen > 0) { - char *l = r_str_repeat (h_line, maxlen); + char *l = rz_str_repeat (h_line, maxlen); if (l) { - r_strbuf_appendf (sb, "\n%s\n", l); + rz_strbuf_appendf (sb, "\n%s\n", l); free (l); } } - r_list_foreach (t->cols, iter, col) { + rz_list_foreach (t->cols, iter, col) { bool nopad = !iter->n; (void)__strbuf_append_col_aligned (sb, col, sdb_itoa (col->total, tmp, 10), nopad); } } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_table_tocsv(RTable *t) { - RStrBuf *sb = r_strbuf_new (""); +RZ_API char *rz_table_tocsv(RTable *t) { + RStrBuf *sb = rz_strbuf_new (""); RTableRow *row; RTableColumn *col; - RListIter *iter, *iter2; + RzListIter *iter, *iter2; if (t->showHeader) { const char *comma = ""; - r_list_foreach (t->cols, iter, col) { + rz_list_foreach (t->cols, iter, col) { if (strchr (col->name, ',')) { // TODO. escaped string? - r_strbuf_appendf (sb, "%s\"%s\"", comma, col->name); + rz_strbuf_appendf (sb, "%s\"%s\"", comma, col->name); } else { - r_strbuf_appendf (sb, "%s%s", comma, col->name); + rz_strbuf_appendf (sb, "%s%s", comma, col->name); } comma = ","; } - r_strbuf_append (sb, "\n"); + rz_strbuf_append (sb, "\n"); } - r_list_foreach (t->rows, iter, row) { + rz_list_foreach (t->rows, iter, row) { char *item; int c = 0; const char *comma = ""; - r_list_foreach (row->items, iter2, item) { - RTableColumn *col = r_list_get_n (t->cols, c); + rz_list_foreach (row->items, iter2, item) { + RTableColumn *col = rz_list_get_n (t->cols, c); if (col) { if (strchr (col->name, ',')) { - r_strbuf_appendf (sb, "%s\"%s\"", comma, col->name); + rz_strbuf_appendf (sb, "%s\"%s\"", comma, col->name); } else { - r_strbuf_appendf (sb, "%s%s", comma, item); + rz_strbuf_appendf (sb, "%s%s", comma, item); } comma = ","; } c++; } - r_strbuf_append (sb, "\n"); + rz_strbuf_append (sb, "\n"); } - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API char *r_table_tojson(RTable *t) { +RZ_API char *rz_table_tojson(RTable *t) { PJ *pj = pj_new (); RTableRow *row; - RListIter *iter, *iter2; + RzListIter *iter, *iter2; pj_a (pj); - r_list_foreach (t->rows, iter, row) { + rz_list_foreach (t->rows, iter, row) { char *item; int c = 0; pj_o (pj); - r_list_foreach (row->items, iter2, item) { - RTableColumn *col = r_list_get_n (t->cols, c); + rz_list_foreach (row->items, iter2, item) { + RTableColumn *col = rz_list_get_n (t->cols, c); if (col) { - if (col->type == &r_table_type_number) { - ut64 n = r_num_get (NULL, item); + if (col->type == &rz_table_type_number) { + ut64 n = rz_num_get (NULL, item); if (n) { pj_kn (pj, col->name, n); } else if (*item && *item != '0') { @@ -534,16 +534,16 @@ R_API char *r_table_tojson(RTable *t) { return pj_drain (pj); } -R_API void r_table_filter(RTable *t, int nth, int op, const char *un) { - r_return_if_fail (t && un); +RZ_API void rz_table_filter(RTable *t, int nth, int op, const char *un) { + rz_return_if_fail (t && un); RTableRow *row; - RListIter *iter, *iter2; - ut64 uv = r_num_math (NULL, un); + RzListIter *iter, *iter2; + ut64 uv = rz_num_math (NULL, un); ut64 sum = 0; int page = 0, page_items = 0; size_t lrow = 0; if (op == 't') { - size_t ll = r_list_length (t->rows); + size_t ll = rz_list_length (t->rows); if (ll > uv) { uv = ll - uv; } @@ -559,9 +559,9 @@ R_API void r_table_filter(RTable *t, int nth, int op, const char *un) { } } size_t nrow = 0; - r_list_foreach_safe (t->rows, iter, iter2, row) { - const char *nn = r_list_get_n (row->items, nth); - ut64 nv = r_num_math (NULL, nn); + rz_list_foreach_safe (t->rows, iter, iter2, row) { + const char *nn = rz_list_get_n (row->items, nth); + ut64 nv = rz_num_math (NULL, nn); bool match = true; switch (op) { case 'p': @@ -626,33 +626,33 @@ R_API void r_table_filter(RTable *t, int nth, int op, const char *un) { break; } if (!match) { - r_list_delete (t->rows, iter); + rz_list_delete (t->rows, iter); } } if (op == '+') { - r_table_add_rowf (t, "u", sum); + rz_table_add_rowf (t, "u", sum); } } static int cmp(const void *_a, const void *_b) { RTableRow *a = (RTableRow*)_a; RTableRow *b = (RTableRow*)_b; - const char *wa = r_list_get_n (a->items, Gnth); - const char *wb = r_list_get_n (b->items, Gnth); + const char *wa = rz_list_get_n (a->items, Gnth); + const char *wb = rz_list_get_n (b->items, Gnth); int res = Gcmp (wa, wb); return res; } -R_API void r_table_sort(RTable *t, int nth, bool dec) { - RTableColumn *col = r_list_get_n (t->cols, nth); +RZ_API void rz_table_sort(RTable *t, int nth, bool dec) { + RTableColumn *col = rz_list_get_n (t->cols, nth); if (col) { Gnth = nth; if (col->type && col->type->cmp) { Gcmp = col->type->cmp; t->rows->sorted = false; //force sorting - r_list_sort (t->rows, cmp); + rz_list_sort (t->rows, cmp); if (dec) { - r_list_reverse (t->rows); + rz_list_reverse (t->rows); } } Gnth = 0; @@ -663,29 +663,29 @@ R_API void r_table_sort(RTable *t, int nth, bool dec) { static int cmplen(const void *_a, const void *_b) { RTableRow *a = (RTableRow*)_a; RTableRow *b = (RTableRow*)_b; - const char *wa = r_list_get_n (a->items, Gnth); - const char *wb = r_list_get_n (b->items, Gnth); + const char *wa = rz_list_get_n (a->items, Gnth); + const char *wb = rz_list_get_n (b->items, Gnth); int res = strlen (wa) - strlen (wb); return res; } -R_API void r_table_sortlen(RTable *t, int nth, bool dec) { - RTableColumn *col = r_list_get_n (t->cols, nth); +RZ_API void rz_table_sortlen(RTable *t, int nth, bool dec) { + RTableColumn *col = rz_list_get_n (t->cols, nth); if (col) { Gnth = nth; t->rows->sorted = false; //force sorting - r_list_sort (t->rows, cmplen); + rz_list_sort (t->rows, cmplen); if (dec) { - r_list_reverse (t->rows); + rz_list_reverse (t->rows); } Gnth = 0; } } -static int r_rows_cmp(RList *lhs, RList *rhs, RList *cols, int nth) { - RListIter *iter_lhs; - RListIter *iter_rhs; - RListIter *iter_col; +static int rz_rows_cmp(RzList *lhs, RzList *rhs, RzList *cols, int nth) { + RzListIter *iter_lhs; + RzListIter *iter_rhs; + RzListIter *iter_col; RTableColumn *item_col; void *item_lhs; @@ -723,43 +723,43 @@ static int r_rows_cmp(RList *lhs, RList *rhs, RList *cols, int nth) { return 0; } -R_API void r_table_uniq(RTable *t) { - r_table_group (t, -1, NULL); +RZ_API void rz_table_uniq(RTable *t) { + rz_table_group (t, -1, NULL); } -R_API void r_table_group(RTable *t, int nth, RTableSelector fcn) { - RListIter *iter; - RListIter *tmp; +RZ_API void rz_table_group(RTable *t, int nth, RTableSelector fcn) { + RzListIter *iter; + RzListIter *tmp; RTableRow *row; - RListIter *iter_inner; + RzListIter *iter_inner; RTableRow *uniq_row; - RList *rows = t->rows; + RzList *rows = t->rows; - r_list_foreach_safe (rows, iter, tmp, row) { + rz_list_foreach_safe (rows, iter, tmp, row) { for (iter_inner = rows->head; iter_inner && iter_inner != iter; iter_inner = iter_inner->n) { uniq_row = iter_inner->data; - if (!r_rows_cmp (uniq_row->items, row->items, t->cols, nth)) { + if (!rz_rows_cmp (uniq_row->items, row->items, t->cols, nth)) { if (fcn) { fcn (uniq_row, row, nth); } - r_list_delete (rows, iter); + rz_list_delete (rows, iter); break; } } } } -R_API int r_table_column_nth(RTable *t, const char *name) { - RListIter *iter; +RZ_API int rz_table_column_nth(RTable *t, const char *name) { + RzListIter *iter; RTableColumn *col; int n = 0; - r_list_foreach (t->cols, iter, col) { + rz_list_foreach (t->cols, iter, col) { if (!strcmp (name, col->name)) { return n; } @@ -789,14 +789,14 @@ static void __table_column_free(void *_col) { free (col); } -R_API void r_table_columns(RTable *t, RList *col_names) { +RZ_API void rz_table_columns(RTable *t, RzList *col_names) { // 1 bool per OLD column to indicate whether it should be freed (masked out) - bool *free_cols = malloc (sizeof (bool) * r_list_length (t->cols)); + bool *free_cols = malloc (sizeof (bool) * rz_list_length (t->cols)); if (!free_cols) { return; } size_t i; - for (i = 0; i < r_list_length (t->cols); i++) { + for (i = 0; i < rz_list_length (t->cols); i++) { free_cols[i] = true; } @@ -804,18 +804,18 @@ R_API void r_table_columns(RTable *t, RList *col_names) { struct col_source { int oldcol; bool dup; - } *col_sources = calloc (r_list_length (col_names), sizeof (struct col_source)); + } *col_sources = calloc (rz_list_length (col_names), sizeof (struct col_source)); if (!col_sources) { free (free_cols); return; } // First create the plan which new columns to take from which old, which ones to dup or free. - RListIter *it; + RzListIter *it; const char *col_name; size_t new_count = 0; - r_list_foreach (col_names, it, col_name) { - int fc = r_table_column_nth (t, col_name); + rz_list_foreach (col_names, it, col_name) { + int fc = rz_table_column_nth (t, col_name); if (fc < 0) { continue; } @@ -826,76 +826,76 @@ R_API void r_table_columns(RTable *t, RList *col_names) { } RTableRow *row; - r_list_foreach (t->rows, it, row) { - RList *old_items = row->items; - RList *new_items = r_list_newf (free); + rz_list_foreach (t->rows, it, row) { + RzList *old_items = row->items; + RzList *new_items = rz_list_newf (free); for (i = 0; i < new_count; i++) { - char *item = r_list_get_n (old_items, col_sources[i].oldcol); + char *item = rz_list_get_n (old_items, col_sources[i].oldcol); if (!item) { continue; } if (col_sources[i].dup) { item = strdup (item); } - r_list_append (new_items, item); + rz_list_append (new_items, item); } row->items = new_items; // Free dropped items char *item; i = 0; - RListIter *fit; - r_list_foreach (old_items, fit, item) { + RzListIter *fit; + rz_list_foreach (old_items, fit, item) { if (free_cols[i]) { free (item); } i++; } old_items->free = NULL; - r_list_free (old_items); + rz_list_free (old_items); } - RList *old_cols = t->cols; - RList *new_cols = r_list_newf (r_table_column_free); + RzList *old_cols = t->cols; + RzList *new_cols = rz_list_newf (rz_table_column_free); for (i = 0; i < new_count; i++) { - RTableColumn *col = r_list_get_n (old_cols, col_sources[i].oldcol); + RTableColumn *col = rz_list_get_n (old_cols, col_sources[i].oldcol); if (!col) { continue; } if (col_sources[i].dup) { - col = r_table_column_clone (col); + col = rz_table_column_clone (col); } - r_list_append (new_cols, col); + rz_list_append (new_cols, col); } t->cols = new_cols; // Free dropped columns RTableColumn *col; i = 0; - r_list_foreach (old_cols, it, col) { + rz_list_foreach (old_cols, it, col) { if (free_cols[i]) { - r_table_column_free (col); + rz_table_column_free (col); } i++; } old_cols->free = NULL; - r_list_free (old_cols); + rz_list_free (old_cols); free (col_sources); free (free_cols); } -R_API void r_table_filter_columns(RTable *t, RList *list) { +RZ_API void rz_table_filter_columns(RTable *t, RzList *list) { const char *col; - RListIter *iter; - RList *cols = t->cols; - t->cols = r_list_newf (__table_column_free); - r_list_foreach (list, iter, col) { - int ncol = r_table_column_nth (t, col); + RzListIter *iter; + RzList *cols = t->cols; + t->cols = rz_list_newf (__table_column_free); + rz_list_foreach (list, iter, col) { + int ncol = rz_table_column_nth (t, col); if (ncol != -1) { - RTableColumn *c = r_list_get_n (cols, ncol); + RTableColumn *c = rz_list_get_n (cols, ncol); if (c) { - r_table_add_column (t, c->type, col, 0); + rz_table_add_column (t, c->type, col, 0); } } } @@ -921,9 +921,9 @@ static bool __table_special(RTable *t, const char *columnName) { return true; } -R_API bool r_table_query(RTable *t, const char *q) { - r_return_val_if_fail (t, false); - q = r_str_trim_head_ro (q); +RZ_API bool rz_table_query(RTable *t, const char *q) { + rz_return_val_if_fail (t, false); + q = rz_str_trim_head_ro (q); // TODO support parenthesis and (or)|| // split by "&&" (or comma) -> run .filter on each // addr/gt/200,addr/lt/400,addr/sort/dec,offset/sort/inc @@ -956,19 +956,19 @@ R_API bool r_table_query(RTable *t, const char *q) { return false; } - RListIter *iter; + RzListIter *iter; char *qq = strdup (q); - RList *queries = r_str_split_list (qq, ",", 0); + RzList *queries = rz_str_split_list (qq, ",", 0); char *query; - r_list_foreach (queries, iter, query) { - RList *q = r_str_split_list (query, "/", 2); - const char *columnName = r_list_get_n (q, 0); - const char *operation = r_list_get_n (q, 1); - const char *operand = r_list_get_n (q, 2); + rz_list_foreach (queries, iter, query) { + RzList *q = rz_str_split_list (query, "/", 2); + const char *columnName = rz_list_get_n (q, 0); + const char *operation = rz_list_get_n (q, 1); + const char *operand = rz_list_get_n (q, 2); if (__table_special (t, columnName)) { continue; } - int col = r_table_column_nth (t, columnName); + int col = rz_table_column_nth (t, columnName); if (col == -1) { if (columnName == NULL && strcmp (operation, "uniq")) { eprintf ("Invalid column name (%s) for (%s)\n", columnName, query); @@ -982,75 +982,75 @@ R_API bool r_table_query(RTable *t, const char *q) { break; } if (!strcmp (operation, "sort")) { - r_table_sort (t, col, operand && !strcmp (operand, "dec")); + rz_table_sort (t, col, operand && !strcmp (operand, "dec")); } else if (!strcmp (operation, "uniq")) { - r_table_group (t, col, NULL); + rz_table_group (t, col, NULL); } else if (!strcmp (operation, "sortlen")) { - r_table_sortlen (t, col, operand && !strcmp (operand, "dec")); + rz_table_sortlen (t, col, operand && !strcmp (operand, "dec")); } else if (!strcmp (operation, "join")) { // TODO: implement join operation with other command's tables } else if (!strcmp (operation, "sum")) { char *op = strdup (operand?operand: ""); - RList *list = r_str_split_list (op, "/", 0); - r_list_prepend (list, strdup (columnName)); - r_table_columns (t, list); // select/reorder columns - r_list_free (list); - r_table_filter (t, 0, '+', op); + RzList *list = rz_str_split_list (op, "/", 0); + rz_list_prepend (list, strdup (columnName)); + rz_table_columns (t, list); // select/reorder columns + rz_list_free (list); + rz_table_filter (t, 0, '+', op); free (op); } else if (!strcmp (operation, "strlen")) { if (operand) { - r_table_filter (t, col, 's', operand); + rz_table_filter (t, col, 's', operand); } } else if (!strcmp (operation, "minlen")) { if (operand) { - r_table_filter (t, col, 'l', operand); + rz_table_filter (t, col, 'l', operand); } } else if (!strcmp (operation, "maxlen")) { if (operand) { - r_table_filter (t, col, 'L', operand); + rz_table_filter (t, col, 'L', operand); } } else if (!strcmp (operation, "page")) { if (operand) { - r_table_filter (t, col, 'p', operand); + rz_table_filter (t, col, 'p', operand); } } else if (!strcmp (operation, "tail")) { if (operand) { - r_table_filter (t, col, 't', operand); + rz_table_filter (t, col, 't', operand); } } else if (!strcmp (operation, "head")) { if (operand) { - r_table_filter (t, col, 'h', operand); + rz_table_filter (t, col, 'h', operand); } } else if (!strcmp (operation, "str")) { if (operand) { - r_table_filter (t, col, '~', operand); + rz_table_filter (t, col, '~', operand); } } else if (!strcmp (operation, "cols")) { char *op = strdup (operand?operand: ""); - RList *list = r_str_split_list (op, "/", 0); - r_list_prepend (list, strdup (columnName)); - r_table_columns (t, list); // select/reorder columns - r_list_free (list); + RzList *list = rz_str_split_list (op, "/", 0); + rz_list_prepend (list, strdup (columnName)); + rz_table_columns (t, list); // select/reorder columns + rz_list_free (list); free (op); - // TODO r_table_filter_columns (t, q); + // TODO rz_table_filter_columns (t, q); } else { int op = __resolveOperation (operation); if (op == -1) { eprintf ("Invalid operation (%s)\n", operation); } else { - r_table_filter (t, col, op, operand); + rz_table_filter (t, col, op, operand); } } - r_list_free (q); + rz_list_free (q); } - r_list_free (queries); + rz_list_free (queries); free (qq); __table_adjust (t); return true; } -R_API bool r_table_align(RTable *t, int nth, int align) { - RTableColumn *col = r_list_get_n (t->cols, nth); +RZ_API bool rz_table_align(RTable *t, int nth, int align) { + RTableColumn *col = rz_list_get_n (t->cols, nth); if (col) { col->align = align; return true; @@ -1058,15 +1058,15 @@ R_API bool r_table_align(RTable *t, int nth, int align) { return false; } -R_API void r_table_hide_header (RTable *t) { +RZ_API void rz_table_hide_header (RTable *t) { t->showHeader = false; } -R_API void r_table_visual_list(RTable *table, RList *list, ut64 seek, ut64 len, int width, bool va) { +RZ_API void rz_table_visual_list(RTable *table, RzList *list, ut64 seek, ut64 len, int width, bool va) { ut64 mul, min = -1, max = -1; - RListIter *iter; - RListInfo *info; - RCons *cons = (RCons *) table->cons; + RzListIter *iter; + RzListInfo *info; + RzCons *cons = (RzCons *) table->cons; table->showHeader = false; const char *h_line = cons->use_utf8 ? RUNE_LONG_LINE_HORIZ : "-"; const char *block = cons->use_utf8 ? UTF_BLOCK : "#"; @@ -1076,8 +1076,8 @@ R_API void r_table_visual_list(RTable *table, RList *list, ut64 seek, ut64 len, width = 30; } - r_table_set_columnsf (table, "sssssss", "No.", "offset", "blocks", "offset", "perms", "extra", "name"); - r_list_foreach (list, iter, info) { + rz_table_set_columnsf (table, "sssssss", "No.", "offset", "blocks", "offset", "perms", "extra", "name"); + rz_list_foreach (list, iter, info) { if (min == -1 || info->pitv.addr < min) { min = info->pitv.addr; } @@ -1088,93 +1088,93 @@ R_API void r_table_visual_list(RTable *table, RList *list, ut64 seek, ut64 len, mul = (max - min) / width; if (min != -1 && mul > 0) { i = 0; - r_list_foreach (list, iter, info) { - RStrBuf *buf = r_strbuf_new (""); + rz_list_foreach (list, iter, info) { + RStrBuf *buf = rz_strbuf_new (""); for (j = 0; j < width; j++) { ut64 pos = min + j * mul; ut64 npos = min + (j + 1) * mul; const char *arg = (info->pitv.addr < npos && (info->pitv.addr + info->pitv.size) > pos) ? block: h_line; - r_strbuf_append (buf, arg); + rz_strbuf_append (buf, arg); } - char *b = r_strbuf_drain (buf); + char *b = rz_strbuf_drain (buf); if (va) { - r_table_add_rowf (table, "sssssss", - sdb_fmt ("%d%c", i, r_itv_contain (info->vitv, seek) ? '*' : ' '), + rz_table_add_rowf (table, "sssssss", + sdb_fmt ("%d%c", i, rz_itv_contain (info->vitv, seek) ? '*' : ' '), sdb_fmt ("0x%"PFMT64x, info->vitv.addr), b, - sdb_fmt ("0x%"PFMT64x, r_itv_end (info->vitv)), - (info->perm != -1)? r_str_rwx_i (info->perm) : "", + sdb_fmt ("0x%"PFMT64x, rz_itv_end (info->vitv)), + (info->perm != -1)? rz_str_rwx_i (info->perm) : "", (info->extra)?info->extra : "", (info->name)?info->name :""); } else { - r_table_add_rowf (table, "sssssss", sdb_fmt ("%d%c", i, r_itv_contain (info->pitv, seek) ? '*' : ' '), + rz_table_add_rowf (table, "sssssss", sdb_fmt ("%d%c", i, rz_itv_contain (info->pitv, seek) ? '*' : ' '), sdb_fmt ("0x%"PFMT64x, info->pitv.addr), b, - sdb_fmt ("0x%"PFMT64x, r_itv_end (info->pitv)), - (info->perm != -1)? r_str_rwx_i (info->perm) : "",(info->extra)?info->extra : "", (info->name)?info->name :""); + sdb_fmt ("0x%"PFMT64x, rz_itv_end (info->pitv)), + (info->perm != -1)? rz_str_rwx_i (info->perm) : "",(info->extra)?info->extra : "", (info->name)?info->name :""); } free (b); i++; } - RStrBuf *buf = r_strbuf_new (""); + RStrBuf *buf = rz_strbuf_new (""); /* current seek */ if (i > 0 && len != 0) { if (seek == UT64_MAX) { seek = 0; } for (j = 0; j < width; j++) { - r_strbuf_append (buf,((j * mul) + min >= seek && + rz_strbuf_append (buf,((j * mul) + min >= seek && (j * mul) + min <= seek + len) ? "^" : h_line); } - r_table_add_rowf (table, "sssssss", "=>", sdb_fmt ("0x%08"PFMT64x, seek), - r_strbuf_drain (buf), sdb_fmt ("0x%08"PFMT64x, seek + len), "", "", ""); + rz_table_add_rowf (table, "sssssss", "=>", sdb_fmt ("0x%08"PFMT64x, seek), + rz_strbuf_drain (buf), sdb_fmt ("0x%08"PFMT64x, seek + len), "", "", ""); } else { - r_strbuf_free (buf); + rz_strbuf_free (buf); } } } #if 0 // TODO: to be implemented -R_API RTable *r_table_clone(RTable *t) { +RZ_API RTable *rz_table_clone(RTable *t) { // TODO: implement return NULL; } -R_API RTable *r_table_push(RTable *t) { +RZ_API RTable *rz_table_push(RTable *t) { // TODO: implement return NULL; } -R_API RTable *r_table_pop(RTable *t) { +RZ_API RTable *rz_table_pop(RTable *t) { // TODO: implement return NULL; } -R_API void r_table_fromjson(RTable *t, const char *csv) { +RZ_API void rz_table_fromjson(RTable *t, const char *csv) { // TODO } -R_API void r_table_fromcsv(RTable *t, const char *csv) { +RZ_API void rz_table_fromcsv(RTable *t, const char *csv) { // TODO } -R_API char *r_table_tohtml(RTable *t) { +RZ_API char *rz_table_tohtml(RTable *t) { // TODO return NULL; } -R_API void r_table_transpose(RTable *t) { +RZ_API void rz_table_transpose(RTable *t) { // When the music stops rows will be cols and cols... rows! } -R_API void r_table_format(RTable *t, int nth, RTableColumnType *type) { +RZ_API void rz_table_format(RTable *t, int nth, RTableColumnType *type) { // change the format of a specific column // change imm base, decimal precission, ... } // to compute sum result of all the elements in a column -R_API ut64 r_table_reduce(RTable *t, int nth) { +RZ_API ut64 rz_table_reduce(RTable *t, int nth) { // When the music stops rows will be cols and cols... rows! return 0; } diff --git a/libr/util/thread.c b/librz/util/thread.c similarity index 75% rename from libr/util/thread.c rename to librz/util/thread.c index d9116dadea..f0615a8b1f 100644 --- a/libr/util/thread.c +++ b/librz/util/thread.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2009-2018 - pancake */ -#include -#include +#include +#include #if __APPLE__ // Here to avoid polluting mach types macro redefinitions... @@ -23,16 +23,16 @@ static DWORD WINAPI _r_th_launcher(void *_th) { static void *_r_th_launcher(void *_th) { #endif int ret; - RThread *th = _th; + RzThread *th = _th; th->ready = true; if (th->delay > 0) { - r_sys_sleep (th->delay); + rz_sys_sleep (th->delay); } else if (th->delay < 0) { - r_th_lock_wait (th->lock); + rz_th_lock_wait (th->lock); } - r_th_lock_enter (th->lock); + rz_th_lock_enter (th->lock); do { - r_th_lock_leave (th->lock); + rz_th_lock_leave (th->lock); th->running = true; ret = th->fun (th); if (ret < 0) { @@ -40,23 +40,23 @@ static void *_r_th_launcher(void *_th) { return 0; } th->running = false; - r_th_lock_enter (th->lock); + rz_th_lock_enter (th->lock); } while (ret); - r_th_lock_leave (th->lock); + rz_th_lock_leave (th->lock); #if HAVE_PTHREAD pthread_exit (&ret); #endif return 0; } -R_API int r_th_push_task(struct r_th_t *th, void *user) { +RZ_API int rz_th_push_task(struct rz_th_t *th, void *user) { int ret = true; th->user = user; - r_th_lock_leave (th->lock); + rz_th_lock_leave (th->lock); return ret; } -R_API R_TH_TID r_th_self(void) { +RZ_API R_TH_TID rz_th_self(void) { #if HAVE_PTHREAD return pthread_self (); #elif __WINDOWS__ @@ -67,7 +67,7 @@ R_API R_TH_TID r_th_self(void) { #endif } -R_API bool r_th_setname(RThread *th, const char *name) { +RZ_API bool rz_th_setname(RzThread *th, const char *name) { #if defined(HAVE_PTHREAD_NP) && HAVE_PTHREAD_NP #if __linux__ || __sun if (pthread_setname_np (th->tid, name) != 0) { @@ -92,13 +92,13 @@ R_API bool r_th_setname(RThread *th, const char *name) { return false; } #else -#pragma message("warning r_th_setname not implemented") +#pragma message("warning rz_th_setname not implemented") #endif #endif return true; } -R_API bool r_th_getname(RThread *th, char *name, size_t len) { +RZ_API bool rz_th_getname(RzThread *th, char *name, size_t len) { #if defined(HAVE_PTHREAD_NP) && HAVE_PTHREAD_NP #if __linux__ || __NetBSD__ || __APPLE__ || __sun if (pthread_getname_np (th->tid, name, len) != 0) { @@ -116,19 +116,19 @@ R_API bool r_th_getname(RThread *th, char *name, size_t len) { return false; } - r_str_ncpy (name, ti.name, flen); + rz_str_ncpy (name, ti.name, flen); #else -#pragma message("warning r_th_getname not implemented") +#pragma message("warning rz_th_getname not implemented") #endif #endif return true; } -R_API bool r_th_setaffinity(RThread *th, int cpuid) { +RZ_API bool rz_th_setaffinity(RzThread *th, int cpuid) { #if __linux__ #if defined(__GLIBC__) && defined (__GLIBC_MINOR__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2) // Old versions of GNU libc don't have this feature -#pragma message("warning r_th_setaffinity not implemented") +#pragma message("warning rz_th_setaffinity not implemented") #else cpu_set_t c; CPU_ZERO(&c); @@ -185,15 +185,15 @@ R_API bool r_th_setaffinity(RThread *th, int cpuid) { pset_destroy (c); #else -#pragma message("warning r_th_setaffinity not implemented") +#pragma message("warning rz_th_setaffinity not implemented") #endif return true; } -R_API RThread *r_th_new(R_TH_FUNCTION(fun), void *user, int delay) { - RThread *th = R_NEW0 (RThread); +RZ_API RzThread *rz_th_new(R_TH_FUNCTION(fun), void *user, int delay) { + RzThread *th = R_NEW0 (RzThread); if (th) { - th->lock = r_th_lock_new (false); + th->lock = rz_th_lock_new (false); th->running = false; th->fun = fun; th->user = user; @@ -209,17 +209,17 @@ R_API RThread *r_th_new(R_TH_FUNCTION(fun), void *user, int delay) { return th; } -R_API void r_th_break(RThread *th) { +RZ_API void rz_th_break(RzThread *th) { th->breaked = true; } -R_API bool r_th_kill(RThread *th, bool force) { +RZ_API bool rz_th_kill(RzThread *th, bool force) { if (!th || !th->tid) { return false; } th->breaked = true; - r_th_break (th); - r_th_wait (th); + rz_th_break (th); + rz_th_wait (th); #if HAVE_PTHREAD #ifdef __ANDROID__ pthread_kill (th->tid, 9); @@ -232,7 +232,7 @@ R_API bool r_th_kill(RThread *th, bool force) { return 0; } -R_API bool r_th_start(RThread *th, int enable) { +RZ_API bool rz_th_start(RzThread *th, int enable) { bool ret = true; if (enable) { if (!th->running) { @@ -240,20 +240,20 @@ R_API bool r_th_start(RThread *th, int enable) { while (!th->ready) { /* spinlock */ } - r_th_lock_leave (th->lock); + rz_th_lock_leave (th->lock); } } else { if (th->running) { // stop thread - //r_th_kill (th, 0); - r_th_lock_enter (th->lock); // deadlock? + //rz_th_kill (th, 0); + rz_th_lock_enter (th->lock); // deadlock? } } th->running = enable; return ret; } -R_API int r_th_wait(struct r_th_t *th) { +RZ_API int rz_th_wait(struct rz_th_t *th) { int ret = false; void *thret; if (th) { @@ -267,41 +267,41 @@ R_API int r_th_wait(struct r_th_t *th) { return ret; } -R_API int r_th_wait_async(struct r_th_t *th) { +RZ_API int rz_th_wait_async(struct rz_th_t *th) { return th->running; } -R_API void *r_th_free(struct r_th_t *th) { +RZ_API void *rz_th_free(struct rz_th_t *th) { if (!th) { return NULL; } #if __WINDOWS__ CloseHandle (th->tid); #endif - r_th_lock_free (th->lock); + rz_th_lock_free (th->lock); free (th); return NULL; } -R_API void *r_th_kill_free(struct r_th_t *th) { +RZ_API void *rz_th_kill_free(struct rz_th_t *th) { if (!th) { return NULL; } - r_th_kill (th, true); - r_th_free (th); + rz_th_kill (th, true); + rz_th_free (th); return NULL; } #if 0 // Thread Pipes -typedef struct r_th_pipe_t { - RList *msglist; - RThread *th; - //RThreadLock *lock; -} RThreadPipe; +typedef struct rz_th_pipe_t { + RzList *msglist; + RzThread *th; + //RzThreadLock *lock; +} RzThreadPipe; -r_th_pipe_new(); +rz_th_pipe_new(); #endif diff --git a/libr/util/thread_cond.c b/librz/util/thread_cond.c similarity index 69% rename from libr/util/thread_cond.c rename to librz/util/thread_cond.c index 209fc5e0fe..c31c60fb37 100644 --- a/libr/util/thread_cond.c +++ b/librz/util/thread_cond.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2009-2020 - thestr4ng3r */ -#include +#include -R_API RThreadCond *r_th_cond_new(void) { - RThreadCond *cond = R_NEW0 (RThreadCond); +RZ_API RzThreadCond *rz_th_cond_new(void) { + RzThreadCond *cond = R_NEW0 (RzThreadCond); if (!cond) { return NULL; } @@ -18,7 +18,7 @@ R_API RThreadCond *r_th_cond_new(void) { return cond; } -R_API void r_th_cond_signal(RThreadCond *cond) { +RZ_API void rz_th_cond_signal(RzThreadCond *cond) { #if HAVE_PTHREAD pthread_cond_signal (&cond->cond); #elif __WINDOWS__ @@ -26,7 +26,7 @@ R_API void r_th_cond_signal(RThreadCond *cond) { #endif } -R_API void r_th_cond_signal_all(RThreadCond *cond) { +RZ_API void rz_th_cond_signal_all(RzThreadCond *cond) { #if HAVE_PTHREAD pthread_cond_broadcast (&cond->cond); #elif __WINDOWS__ @@ -34,7 +34,7 @@ R_API void r_th_cond_signal_all(RThreadCond *cond) { #endif } -R_API void r_th_cond_wait(RThreadCond *cond, RThreadLock *lock) { +RZ_API void rz_th_cond_wait(RzThreadCond *cond, RzThreadLock *lock) { #if HAVE_PTHREAD pthread_cond_wait (&cond->cond, &lock->lock); #elif __WINDOWS__ @@ -42,7 +42,7 @@ R_API void r_th_cond_wait(RThreadCond *cond, RThreadLock *lock) { #endif } -R_API void r_th_cond_free(RThreadCond *cond) { +RZ_API void rz_th_cond_free(RzThreadCond *cond) { if (!cond) { return; } diff --git a/libr/util/thread_lock.c b/librz/util/thread_lock.c similarity index 72% rename from libr/util/thread_lock.c rename to librz/util/thread_lock.c index 0a286bc54a..85f3478fb1 100644 --- a/libr/util/thread_lock.c +++ b/librz/util/thread_lock.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2009-2017 - pancake */ -#include +#include /* locks/mutex/sems */ -R_API RThreadLock *r_th_lock_new(bool recursive) { - RThreadLock *thl = R_NEW0 (RThreadLock); +RZ_API RzThreadLock *rz_th_lock_new(bool recursive) { + RzThreadLock *thl = R_NEW0 (RzThreadLock); if (thl) { #if HAVE_PTHREAD if (recursive) { @@ -28,13 +28,13 @@ R_API RThreadLock *r_th_lock_new(bool recursive) { return thl; } -R_API int r_th_lock_wait(RThreadLock *thl) { - r_th_lock_enter (thl); // locks here - r_th_lock_leave (thl); // releases previous mutex +RZ_API int rz_th_lock_wait(RzThreadLock *thl) { + rz_th_lock_enter (thl); // locks here + rz_th_lock_leave (thl); // releases previous mutex return 0; } -R_API int r_th_lock_enter(RThreadLock *thl) { +RZ_API int rz_th_lock_enter(RzThreadLock *thl) { #if HAVE_PTHREAD return pthread_mutex_lock (&thl->lock); #elif __WINDOWS__ @@ -43,7 +43,7 @@ R_API int r_th_lock_enter(RThreadLock *thl) { #endif } -R_API int r_th_lock_tryenter(RThreadLock *thl) { +RZ_API int rz_th_lock_tryenter(RzThreadLock *thl) { #if HAVE_PTHREAD return !pthread_mutex_trylock (&thl->lock); #elif __WINDOWS__ @@ -51,7 +51,7 @@ R_API int r_th_lock_tryenter(RThreadLock *thl) { #endif } -R_API int r_th_lock_leave(RThreadLock *thl) { +RZ_API int rz_th_lock_leave(RzThreadLock *thl) { #if HAVE_PTHREAD return pthread_mutex_unlock (&thl->lock); #elif __WINDOWS__ @@ -60,7 +60,7 @@ R_API int r_th_lock_leave(RThreadLock *thl) { #endif } -R_API void *r_th_lock_free(RThreadLock *thl) { +RZ_API void *rz_th_lock_free(RzThreadLock *thl) { if (thl) { #if HAVE_PTHREAD pthread_mutex_destroy (&thl->lock); diff --git a/libr/util/thread_pipe.c b/librz/util/thread_pipe.c similarity index 100% rename from libr/util/thread_pipe.c rename to librz/util/thread_pipe.c diff --git a/libr/util/thread_sem.c b/librz/util/thread_sem.c similarity index 80% rename from libr/util/thread_sem.c rename to librz/util/thread_sem.c index 5d81cfa34e..5cbf90a3e3 100644 --- a/libr/util/thread_sem.c +++ b/librz/util/thread_sem.c @@ -1,6 +1,6 @@ -/* radare2 - LGPL - Copyright 2018 - thestr4ng3r */ +/* rizin - LGPL - Copyright 2018 - thestr4ng3r */ -#include +#include #ifdef __APPLE__ #define R_SEM_NAMED_ONLY 1 @@ -14,8 +14,8 @@ #include #endif -R_API RThreadSemaphore *r_th_sem_new(unsigned int initial) { - RThreadSemaphore *sem = R_NEW (RThreadSemaphore); +RZ_API RzThreadSemaphore *rz_th_sem_new(unsigned int initial) { + RzThreadSemaphore *sem = R_NEW (RzThreadSemaphore); if (!sem) { return NULL; } @@ -56,7 +56,7 @@ R_API RThreadSemaphore *r_th_sem_new(unsigned int initial) { return sem; } -R_API void r_th_sem_free(RThreadSemaphore *sem) { +RZ_API void rz_th_sem_free(RzThreadSemaphore *sem) { if (!sem) { return; } @@ -75,7 +75,7 @@ R_API void r_th_sem_free(RThreadSemaphore *sem) { free (sem); } -R_API void r_th_sem_post(RThreadSemaphore *sem) { +RZ_API void rz_th_sem_post(RzThreadSemaphore *sem) { #if HAVE_PTHREAD sem_post (sem->sem); #elif __WINDOWS__ @@ -83,7 +83,7 @@ R_API void r_th_sem_post(RThreadSemaphore *sem) { #endif } -R_API void r_th_sem_wait(RThreadSemaphore *sem) { +RZ_API void rz_th_sem_wait(RzThreadSemaphore *sem) { #if HAVE_PTHREAD sem_wait (sem->sem); #elif __WINDOWS__ diff --git a/libr/util/time.c b/librz/util/time.c similarity index 72% rename from libr/util/time.c rename to librz/util/time.c index ed5b306bec..671fe24659 100644 --- a/libr/util/time.c +++ b/librz/util/time.c @@ -1,7 +1,7 @@ /* radare - LGPL - Copyright 2007-2020 - pancake, thestr4ng3r */ -#include -#include +#include +#include #if __linux__ #include @@ -9,7 +9,7 @@ #include #endif -R_API ut64 r_time_now(void) { +RZ_API ut64 rz_time_now(void) { ut64 ret; struct timeval now; gettimeofday (&now, NULL); @@ -18,7 +18,7 @@ R_API ut64 r_time_now(void) { return ret; } -R_API ut64 r_time_now_mono(void) { +RZ_API ut64 rz_time_now_mono(void) { #if __WINDOWS__ LARGE_INTEGER f; if (!QueryPerformanceFrequency (&f)) { @@ -44,14 +44,14 @@ R_API ut64 r_time_now_mono(void) { #endif } -R_API char *r_time_stamp_to_str(ut32 timeStamp) { +RZ_API char *rz_time_stamp_to_str(ut32 timeStamp) { #ifdef _MSC_VER time_t rawtime; struct tm *tminfo; rawtime = (time_t)timeStamp; tminfo = localtime (&rawtime); //tminfo = gmtime (&rawtime); - return r_str_trim_dup (asctime (tminfo)); + return rz_str_trim_dup (asctime (tminfo)); #else struct my_timezone { int tz_minuteswest; /* minutes west of Greenwich */ @@ -65,13 +65,13 @@ R_API char *r_time_stamp_to_str(ut32 timeStamp) { ts += (time_t)gmtoff; char *res = strdup (ctime (&ts)); if (res) { - r_str_trim (res); // XXX we probably need an r_str_trim_dup() + rz_str_trim (res); // XXX we probably need an rz_str_trim_dup() } return res; #endif } -R_API ut32 r_time_dos_time_stamp_to_posix(ut32 timeStamp) { +RZ_API ut32 rz_time_dos_time_stamp_to_posix(ut32 timeStamp) { ut16 date = timeStamp >> 16; ut16 time = timeStamp & 0xFFFF; @@ -99,7 +99,7 @@ R_API ut32 r_time_dos_time_stamp_to_posix(ut32 timeStamp) { return (ut32) epochTime; } -R_API bool r_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp) { +RZ_API bool rz_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut32 possiblePosixOrDosTimeStamp) { /* We assume they're both POSIX timestamp and thus the higher bits would be equal if they're close to each other */ if ((certainPosixTimeStamp >> 16) == (possiblePosixOrDosTimeStamp >> 16)) { return false; @@ -108,13 +108,13 @@ R_API bool r_time_stamp_is_dos_format(const ut32 certainPosixTimeStamp, const ut } -R_API int r_print_date_dos(RPrint *p, const ut8 *buf, int len) { +RZ_API int rz_print_date_dos(RPrint *p, const ut8 *buf, int len) { if(len < 4) { return 0; } ut32 dt = buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]; - char *s = r_time_stamp_to_str (r_time_dos_time_stamp_to_posix (dt)); + char *s = rz_time_stamp_to_str (rz_time_dos_time_stamp_to_posix (dt)); if (!s) { return 0; } @@ -123,33 +123,33 @@ R_API int r_print_date_dos(RPrint *p, const ut8 *buf, int len) { return 4; } -R_API int r_print_date_hfs(RPrint *p, const ut8 *buf, int len) { +RZ_API int rz_print_date_hfs(RPrint *p, const ut8 *buf, int len) { const int hfs_unix_delta = 2082844800; time_t t = 0; int ret = 0; if (p && len >= sizeof (ut32)) { - t = r_read_ble32 (buf, p->big_endian); + t = rz_read_ble32 (buf, p->big_endian); if (p->datefmt[0]) { t += p->datezone * (60*60); t += hfs_unix_delta; - p->cb_printf ("%s\n", r_time_stamp_to_str (t)); + p->cb_printf ("%s\n", rz_time_stamp_to_str (t)); ret = sizeof (time_t); } } return ret; } -R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len) { +RZ_API int rz_print_date_unix(RPrint *p, const ut8 *buf, int len) { time_t t = 0; int ret = 0; if (p && len >= sizeof (ut32)) { - t = r_read_ble32 (buf, p->big_endian); + t = rz_read_ble32 (buf, p->big_endian); if (p->datefmt[0]) { t += p->datezone * (60*60); - char *datestr = r_time_stamp_to_str (t); + char *datestr = rz_time_stamp_to_str (t); if (datestr) { p->cb_printf ("%s\n", datestr); free (datestr); @@ -160,31 +160,31 @@ R_API int r_print_date_unix(RPrint *p, const ut8 *buf, int len) { return ret; } -R_API int r_print_date_get_now(RPrint *p, char *str) { +RZ_API int rz_print_date_get_now(RPrint *p, char *str) { int ret = 0; time_t l; *str = 0; l = time(0); - str = r_time_stamp_to_str (l); + str = rz_time_stamp_to_str (l); p->cb_printf ("%s\n", str); ret = sizeof (time_t); return ret; } -R_API int r_print_date_w32(RPrint *p, const ut8 *buf, int len) { +RZ_API int rz_print_date_w32(RPrint *p, const ut8 *buf, int len) { ut64 l, L = 0x2b6109100LL; time_t t; int ret = 0; if (p && len >= sizeof (ut64)) { - l = r_read_ble64 (buf, p->big_endian); + l = rz_read_ble64 (buf, p->big_endian); l /= 10000000; // 100ns to s l = (l > L ? l-L : 0); // isValidUnixTime? t = (time_t) l; // TODO limit above! if (p->datefmt[0]) { - p->cb_printf ("%s\n", r_time_stamp_to_str (t)); + p->cb_printf ("%s\n", rz_time_stamp_to_str (t)); ret = sizeof (time_t); } } @@ -192,13 +192,13 @@ R_API int r_print_date_w32(RPrint *p, const ut8 *buf, int len) { return ret; } -R_API const char *r_time_to_string (ut64 ts) { +RZ_API const char *rz_time_to_string (ut64 ts) { time_t l; l = ts >> 20; - return r_time_stamp_to_str (l); + return rz_time_stamp_to_str (l); } -R_API char *r_asctime_r(const struct tm *tm, char *buf, size_t size) { +RZ_API char *rz_asctime_r(const struct tm *tm, char *buf, size_t size) { #if __WINDOWS__ errno_t err = asctime_s (buf, size, tm); return err? NULL: buf; diff --git a/libr/util/tree.c b/librz/util/tree.c similarity index 67% rename from libr/util/tree.c rename to librz/util/tree.c index c408e1ca4e..72d225fb3f 100644 --- a/libr/util/tree.c +++ b/librz/util/tree.c @@ -1,29 +1,29 @@ /* radare - LGPL - Copyright 2007-2015 - ret2libc */ -#include +#include static void tree_dfs_node (RTreeNode *r, RTreeVisitor *vis) { RStack *s; - RListIter *it; + RzListIter *it; RTreeNode *n; - s = r_stack_new (16); + s = rz_stack_new (16); if (!s) { return; } - r_stack_push (s, r); - while (!r_stack_is_empty (s)) { - RTreeNode *el = (RTreeNode *)r_stack_pop (s); + rz_stack_push (s, r); + while (!rz_stack_is_empty (s)) { + RTreeNode *el = (RTreeNode *)rz_stack_pop (s); if (vis->pre_visit) { vis->pre_visit (el, vis); } - r_list_foreach_prev (el->children, it, n) { + rz_list_foreach_prev (el->children, it, n) { if (vis->discover_child) { vis->discover_child (n, vis); } - r_stack_push (s, n); + rz_stack_push (s, n); } if (vis->post_visit) { @@ -31,11 +31,11 @@ static void tree_dfs_node (RTreeNode *r, RTreeVisitor *vis) { } } - r_stack_free (s); + rz_stack_free (s); } -static void r_tree_node_free (RTreeNode *n) { - r_list_free (n->children); +static void rz_tree_node_free (RTreeNode *n) { + rz_list_free (n->children); if (n->free) { n->free (n->data); } @@ -43,13 +43,13 @@ static void r_tree_node_free (RTreeNode *n) { } static void node_free (RTreeNode *n, RTreeVisitor *vis) { - r_tree_node_free (n); + rz_tree_node_free (n); } static void free_all_children (RTree *t) { RTreeVisitor vis = { 0 }; vis.post_visit = (RTreeNodeVisitCb)node_free; - r_tree_bfs (t, &vis); + rz_tree_bfs (t, &vis); } static void update_depth (RTreeNode *n, RTreeVisitor *vis) { @@ -61,17 +61,17 @@ static RTreeNode *node_new (RTree *t, void *data) { if (!n) { return NULL; } - n->children = r_list_new (); + n->children = rz_list_new (); n->data = data; n->tree = t; return n; } -R_API RTree *r_tree_new (void) { +RZ_API RTree *rz_tree_new (void) { return R_NEW0 (RTree); } -R_API void r_tree_free (RTree* t) { +RZ_API void rz_tree_free (RTree* t) { if (!t) { return; } @@ -80,7 +80,7 @@ R_API void r_tree_free (RTree* t) { free (t); } -R_API void r_tree_reset (RTree *t) { +RZ_API void rz_tree_reset (RTree *t) { if (!t) { return; } @@ -94,7 +94,7 @@ R_API void r_tree_reset (RTree *t) { * of the tree so the node will be NULL. */ /* TODO: allow to replace the root of the tree and make it a child of the new * node */ -R_API RTreeNode *r_tree_add_node (RTree *t, RTreeNode *node, void *child_data) { +RZ_API RTreeNode *rz_tree_add_node (RTree *t, RTreeNode *node, void *child_data) { RTreeNode *child; RTreeVisitor vis = { 0 }; @@ -107,7 +107,7 @@ R_API RTreeNode *r_tree_add_node (RTree *t, RTreeNode *node, void *child_data) { if (!node && !t->root) { t->root = child; } else if (node) { - r_list_append (node->children, child); + rz_list_append (node->children, child); node->n_children++; } child->parent = node; @@ -119,7 +119,7 @@ R_API RTreeNode *r_tree_add_node (RTree *t, RTreeNode *node, void *child_data) { return child; } -R_API void r_tree_dfs (RTree *t, RTreeVisitor *vis) { +RZ_API void rz_tree_dfs (RTree *t, RTreeVisitor *vis) { if (!t || !t->root) { return; } @@ -127,36 +127,36 @@ R_API void r_tree_dfs (RTree *t, RTreeVisitor *vis) { tree_dfs_node (t->root, vis); } -R_API void r_tree_bfs (RTree *t, RTreeVisitor *vis) { +RZ_API void rz_tree_bfs (RTree *t, RTreeVisitor *vis) { RQueue *q; if (!t || !t->root) { return; } - q = r_queue_new (16); + q = rz_queue_new (16); if (!q) { return; } - r_queue_enqueue (q, t->root); - while (!r_queue_is_empty (q)) { - RTreeNode *el = (RTreeNode *)r_queue_dequeue (q); + rz_queue_enqueue (q, t->root); + while (!rz_queue_is_empty (q)) { + RTreeNode *el = (RTreeNode *)rz_queue_dequeue (q); if (!el) { - r_queue_free (q); + rz_queue_free (q); return; } RTreeNode *n; - RListIter *it; + RzListIter *it; if (vis->pre_visit) { vis->pre_visit (el, vis); } - r_list_foreach (el->children, it, n) { + rz_list_foreach (el->children, it, n) { if (vis->discover_child) { vis->discover_child (n, vis); } - r_queue_enqueue (q, n); + rz_queue_enqueue (q, n); } if (vis->post_visit) { @@ -164,5 +164,5 @@ R_API void r_tree_bfs (RTree *t, RTreeVisitor *vis) { } } - r_queue_free (q); + rz_queue_free (q); } diff --git a/libr/util/ubase64.c b/librz/util/ubase64.c similarity index 87% rename from libr/util/ubase64.c rename to librz/util/ubase64.c index 936e4219e1..0edbd8e93f 100644 --- a/libr/util/ubase64.c +++ b/librz/util/ubase64.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #define SZ 1024 static const char cb64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; @@ -42,7 +42,7 @@ static int local_b64_decode(const char in[4], ut8 out[3]) { return len; } -R_API int r_base64_decode(ut8 *bout, const char *bin, int len) { +RZ_API int rz_base64_decode(ut8 *bout, const char *bin, int len) { int in, out; if (len < 0) { len = strlen (bin); @@ -59,7 +59,7 @@ R_API int r_base64_decode(ut8 *bout, const char *bin, int len) { return (in != out)? out: -1; } -R_API ut8 *r_base64_decode_dyn(const char *in, int len) { +RZ_API ut8 *rz_base64_decode_dyn(const char *in, int len) { ut8 *bout; if (!in) { return NULL; @@ -68,14 +68,14 @@ R_API ut8 *r_base64_decode_dyn(const char *in, int len) { len = strlen (in) + 1; } bout = calloc (4, len + 1); - if (r_base64_decode (bout, in, len) == -1) { + if (rz_base64_decode (bout, in, len) == -1) { free (bout); return NULL; } return bout; } -R_API int r_base64_encode(char *bout, const ut8 *bin, int len) { +RZ_API int rz_base64_encode(char *bout, const ut8 *bin, int len) { int in, out; if (len < 0) { len = strlen ((const char *)bin); @@ -88,7 +88,7 @@ R_API int r_base64_encode(char *bout, const ut8 *bin, int len) { return out; } -R_API char *r_base64_encode_dyn(const char *str, int len) { +RZ_API char *rz_base64_encode_dyn(const char *str, int len) { char *bout; int in, out; if (!str) { diff --git a/libr/util/udiff.c b/librz/util/udiff.c similarity index 84% rename from libr/util/udiff.c rename to librz/util/udiff.c index 0a78dfc35d..3a1a91e5d9 100644 --- a/libr/util/udiff.c +++ b/librz/util/udiff.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2009-2020 - pancake, nikolai */ -#include +#include // the non-system-diff doesnt work well #define USE_SYSTEM_DIFF 1 -R_API RDiff *r_diff_new_from(ut64 off_a, ut64 off_b) { - RDiff *d = R_NEW0 (RDiff); +RZ_API RzDiff *rz_diff_new_from(ut64 off_a, ut64 off_b) { + RzDiff *d = R_NEW0 (RzDiff); if (d) { d->delta = 1; d->user = NULL; @@ -18,78 +18,78 @@ R_API RDiff *r_diff_new_from(ut64 off_a, ut64 off_b) { return d; } -R_API RDiff *r_diff_new(void) { - return r_diff_new_from (0, 0); +RZ_API RzDiff *rz_diff_new(void) { + return rz_diff_new_from (0, 0); } -R_API RDiff *r_diff_free(RDiff *d) { +RZ_API RzDiff *rz_diff_free(RzDiff *d) { free (d); return NULL; } -R_API int r_diff_set_callback(RDiff *d, RDiffCallback callback, void *user) { +RZ_API int rz_diff_set_callback(RzDiff *d, RzDiffCallback callback, void *user) { d->callback = callback; d->user = user; return 1; } -R_API int r_diff_set_delta(RDiff *d, int delta) { +RZ_API int rz_diff_set_delta(RzDiff *d, int delta) { d->delta = delta; return 1; } typedef struct { - RDiff *d; + RzDiff *d; char *str; -} RDiffUser; +} RzDiffUser; #if USE_SYSTEM_DIFF -R_API char *r_diff_buffers_to_string(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { - return r_diff_buffers_unified (d, a, la, b, lb); +RZ_API char *rz_diff_buffers_to_string(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { + return rz_diff_buffers_unified (d, a, la, b, lb); } #else // XXX buffers_static doesnt constructs the correct string in this callback -static int tostring(RDiff *d, void *user, RDiffOp *op) { - RDiffUser *u = (RDiffUser*)user; +static int tostring(RzDiff *d, void *user, RzDiffOp *op) { + RzDiffUser *u = (RzDiffUser*)user; if (op->a_len > 0) { - char *a_str = r_str_ndup ((const char *)op->a_buf + op->a_off, op->a_len); - u->str = r_str_appendf (u->str, "+(%s)", a_str); + char *a_str = rz_str_ndup ((const char *)op->a_buf + op->a_off, op->a_len); + u->str = rz_str_appendf (u->str, "+(%s)", a_str); #if 0 - char *bufasm = r_str_prefix_all (a_str, "- "); - u->str = r_str_appendf (u->str, "-(%s)", bufasm); + char *bufasm = rz_str_prefix_all (a_str, "- "); + u->str = rz_str_appendf (u->str, "-(%s)", bufasm); free (bufasm); #endif free (a_str); } if (op->b_len > 0) { - char *b_str = r_str_ndup ((const char *)op->b_buf + op->b_off, op->b_len); - u->str = r_str_appendf (u->str, "+(%s)", b_str); + char *b_str = rz_str_ndup ((const char *)op->b_buf + op->b_off, op->b_len); + u->str = rz_str_appendf (u->str, "+(%s)", b_str); #if 0 - char *bufasm = r_str_prefix_all (b_str, "+ "); - u->str = r_str_appendf (u->str, "+(%s)", bufasm); + char *bufasm = rz_str_prefix_all (b_str, "+ "); + u->str = rz_str_appendf (u->str, "+(%s)", bufasm); free (bufasm); #endif free (b_str); } if (op->a_len == op->b_len) { - char *b_str = r_str_ndup ((const char *)op->a_buf + op->a_off, op->a_len); - // char *bufasm = r_str_prefix_all (b_str, " "); - u->str = r_str_appendf (u->str, "%s", b_str); + char *b_str = rz_str_ndup ((const char *)op->a_buf + op->a_off, op->a_len); + // char *bufasm = rz_str_prefix_all (b_str, " "); + u->str = rz_str_appendf (u->str, "%s", b_str); // free (bufasm); free (b_str); } return 1; } -R_API char *r_diff_buffers_to_string(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { +RZ_API char *rz_diff_buffers_to_string(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { // XXX buffers_static doesnt constructs the correct string in this callback void *c = d->callback; void *u = d->user; - RDiffUser du = {d, strdup ("")}; + RzDiffUser du = {d, strdup ("")}; d->callback = &tostring; d->user = &du; - r_diff_buffers_static (d, a, la, b, lb); + rz_diff_buffers_static (d, a, la, b, lb); d->callback = c; d->user = u; return du.str; @@ -100,14 +100,14 @@ R_API char *r_diff_buffers_to_string(RDiff *d, const ut8 *a, int la, const ut8 * const size_t i_hit = i - hit;\ int ra = la - i_hit;\ int rb = lb - i_hit;\ - struct r_diff_op_t o = {\ + struct rz_diff_op_t o = {\ .a_off = d->off_a+i-hit, .a_buf = a+i-hit, .a_len = R_MIN (hit, ra),\ .b_off = d->off_b+i-hit, .b_buf = b+i-hit, .b_len = R_MIN (hit, rb)\ };\ d->callback (d, d->user, &o);\ } -R_API int r_diff_buffers_static(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { +RZ_API int rz_diff_buffers_static(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { int i, len; int hit = 0; la = R_ABS (la); @@ -135,40 +135,40 @@ R_API int r_diff_buffers_static(RDiff *d, const ut8 *a, int la, const ut8 *b, in } // XXX: temporary files are -R_API char *r_diff_buffers_unified(RDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { - r_file_dump (".a", a, la, 0); - r_file_dump (".b", b, lb, 0); +RZ_API char *rz_diff_buffers_unified(RzDiff *d, const ut8 *a, int la, const ut8 *b, int lb) { + rz_file_dump (".a", a, la, 0); + rz_file_dump (".b", b, lb, 0); #if 0 - if (r_mem_is_printable (a, R_MIN (5, la))) { - r_file_dump (".a", a, la, 0); - r_file_dump (".b", b, lb, 0); + if (rz_mem_is_printable (a, R_MIN (5, la))) { + rz_file_dump (".a", a, la, 0); + rz_file_dump (".b", b, lb, 0); } else { - r_file_hexdump (".a", a, la, 0); - r_file_hexdump (".b", b, lb, 0); + rz_file_hexdump (".a", a, la, 0); + rz_file_hexdump (".b", b, lb, 0); } #endif char* err = NULL; char* out = NULL; int out_len; - char* diff_cmdline = r_str_newf ("%s .a .b", d->diff_cmd); + char* diff_cmdline = rz_str_newf ("%s .a .b", d->diff_cmd); if (diff_cmdline) { - (void)r_sys_cmd_str_full (diff_cmdline, NULL, &out, &out_len, &err); + (void)rz_sys_cmd_str_full (diff_cmdline, NULL, &out, &out_len, &err); free (diff_cmdline); } - r_file_rm (".a"); - r_file_rm (".b"); + rz_file_rm (".a"); + rz_file_rm (".b"); free (err); return out; } -R_API int r_diff_buffers(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb) { +RZ_API int rz_diff_buffers(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb) { return d->delta - ? r_diff_buffers_delta (d, a, la, b, lb) - : r_diff_buffers_static (d, a, la, b, lb); + ? rz_diff_buffers_delta (d, a, la, b, lb) + : rz_diff_buffers_static (d, a, la, b, lb); } -R_API bool r_diff_buffers_distance_levenstein(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { - r_return_val_if_fail (a && b, false); +RZ_API bool rz_diff_buffers_distance_levenstein(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { + rz_return_val_if_fail (a && b, false); const bool verbose = d? d->verbose: false; /* More memory efficient version on Levenshtein Distance from: @@ -178,7 +178,7 @@ R_API bool r_diff_buffers_distance_levenstein(RDiff *d, const ut8 *a, ut32 la, c 8/July/2016 - More time efficient Levenshtein Distance. Now runs in about O(N*sum(MDistance)) instead of O(NM) In real world testing the speedups for similar files are immense. Processing of - radiff2 -sV routerA/firmware_extract/bin/httpd routerB/firmware_extract/bin/httpd + rz_diff -sV routerA/firmware_extract/bin/httpd routerB/firmware_extract/bin/httpd reduced from 28 hours to about 13 minutes. */ int i, j; @@ -382,7 +382,7 @@ R_API bool r_diff_buffers_distance_levenstein(RDiff *d, const ut8 *a, ut32 la, c // Eugene W. Myers' O(ND) diff algorithm // Returns edit distance with costs: insertion=1, deletion=1, no substitution -R_API bool r_diff_buffers_distance_myers(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { +RZ_API bool rz_diff_buffers_distance_myers(RzDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { const bool verbose = diff ? diff->verbose: false; if (!a || !b) { return false; @@ -437,7 +437,7 @@ out: return true; } -R_API bool r_diff_buffers_distance_original(RDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { +RZ_API bool rz_diff_buffers_distance_original(RzDiff *diff, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { if (!a || !b) { return false; } @@ -493,27 +493,27 @@ R_API bool r_diff_buffers_distance_original(RDiff *diff, const ut8 *a, ut32 la, return true; } -R_API bool r_diff_buffers_distance(RDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { +RZ_API bool rz_diff_buffers_distance(RzDiff *d, const ut8 *a, ut32 la, const ut8 *b, ut32 lb, ut32 *distance, double *similarity) { if (d) { switch (d->type) { case 'm': - return r_diff_buffers_distance_myers (d, a, la, b, lb, distance, similarity); + return rz_diff_buffers_distance_myers (d, a, la, b, lb, distance, similarity); case 'l': - return r_diff_buffers_distance_levenstein (d, a, la, b, lb, distance, similarity); + return rz_diff_buffers_distance_levenstein (d, a, la, b, lb, distance, similarity); default: break; } } - return r_diff_buffers_distance_original (d, a, la, b, lb, distance, similarity); + return rz_diff_buffers_distance_original (d, a, la, b, lb, distance, similarity); } // Use Needleman–Wunsch to diffchar. // This is an O(mn) algo in both space and time. // Note that 64KB * 64KB * 2 = 8GB. // TODO Discard common prefix and suffix -R_API RDiffChar *r_diffchar_new(const ut8 *a, const ut8 *b) { - r_return_val_if_fail (a && b, NULL); - RDiffChar *diffchar = R_NEW0 (RDiffChar); +RZ_API RzDiffChar *rz_diffchar_new(const ut8 *a, const ut8 *b) { + rz_return_val_if_fail (a && b, NULL); + RzDiffChar *diffchar = R_NEW0 (RzDiffChar); if (!diffchar) { return NULL; } @@ -695,8 +695,8 @@ typedef enum { R2R_DIFF_MATCH, R2R_DIFF_DELETE, R2R_DIFF_INSERT } R2RPrintDiffMode; -R_API void r_diffchar_print(RDiffChar *diffchar) { - r_return_if_fail (diffchar); +RZ_API void rz_diffchar_print(RzDiffChar *diffchar) { + rz_return_if_fail (diffchar); R2RPrintDiffMode cur_mode = R2R_DIFF_MATCH; R2RCharAlignment cur_align; size_t idx_align = diffchar->start_align; @@ -769,7 +769,7 @@ R_API void r_diffchar_print(RDiffChar *diffchar) { printf (Color_RESET"\n"); } -R_API void r_diffchar_free(RDiffChar *diffchar) { +RZ_API void rz_diffchar_free(RzDiffChar *diffchar) { if (diffchar) { free ((ut8 *)diffchar->align_a); free ((ut8 *)diffchar->align_b); diff --git a/libr/util/uleb128.c b/librz/util/uleb128.c similarity index 89% rename from libr/util/uleb128.c rename to librz/util/uleb128.c index 824a67987b..9280e13117 100644 --- a/libr/util/uleb128.c +++ b/librz/util/uleb128.c @@ -1,11 +1,11 @@ /* radare - LGPL - Copyright 2014-2015 - pancake */ -#include "r_util/r_str.h" -#include +#include "rz_util/rz_str.h" +#include /* dex/dwarf uleb128 implementation */ -R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v, const char **error) { +RZ_API const ut8 *rz_uleb128(const ut8 *data, int datalen, ut64 *v, const char **error) { ut8 c; ut64 s, sum = 0; const ut8 *data_end; @@ -27,7 +27,7 @@ R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v, const char **e c = *(data++) & 0xff; if (s > 63) { if (error) { - *error = r_str_newf ("r_uleb128: undefined behaviour in %d shift on ut32\n", (int)s); + *error = rz_str_newf ("rz_uleb128: undefined behaviour in %d shift on ut32\n", (int)s); } break; } else { @@ -40,7 +40,7 @@ R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v, const char **e } if (malformed_uleb) { if (error) { - *error = r_str_newf ("malformed uleb128\n"); + *error = rz_str_newf ("malformed uleb128\n"); } } } else { @@ -53,7 +53,7 @@ R_API const ut8 *r_uleb128(const ut8 *data, int datalen, ut64 *v, const char **e return data; } -R_API int r_uleb128_len (const ut8 *data, int size) { +RZ_API int rz_uleb128_len (const ut8 *data, int size) { int i = 1; ut8 c = *(data++); while (c > 0x7f && i < size) { @@ -67,7 +67,7 @@ R_API int r_uleb128_len (const ut8 *data, int size) { * datalen will point (if not NULL) to the length of the uleb number * v (if not NULL) will point to the data's value (if fitting the size of an ut64) */ -R_API const ut8 *r_uleb128_decode(const ut8 *data, int *datalen, ut64 *v) { +RZ_API const ut8 *rz_uleb128_decode(const ut8 *data, int *datalen, ut64 *v) { ut8 c = 0xff; ut64 s = 0, sum = 0, l = 0; do { @@ -85,7 +85,7 @@ R_API const ut8 *r_uleb128_decode(const ut8 *data, int *datalen, ut64 *v) { return data; } -R_API ut8 *r_uleb128_encode(const ut64 s, int *len) { +RZ_API ut8 *rz_uleb128_encode(const ut64 s, int *len) { ut8 c = 0; int l = 0; ut8 *otarget = NULL, *target = NULL, *tmptarget = NULL; @@ -113,7 +113,7 @@ R_API ut8 *r_uleb128_encode(const ut64 s, int *len) { return otarget; } -R_API const ut8 *r_leb128(const ut8 *data, int datalen, st64 *v) { +RZ_API const ut8 *rz_leb128(const ut8 *data, int datalen, st64 *v) { ut8 c = 0; st64 s = 0, sum = 0; const ut8 *data_end = data + datalen; @@ -142,7 +142,7 @@ beach: } -R_API st64 r_sleb128(const ut8 **data, const ut8 *end) { +RZ_API st64 rz_sleb128(const ut8 **data, const ut8 *end) { const ut8 *p = *data; st64 result = 0; int offset = 0; @@ -183,7 +183,7 @@ R_API st64 r_sleb128(const ut8 **data, const ut8 *end) { ((type)((value) << SHIFT_AMOUNT (type, sign_bit)) >> \ SHIFT_AMOUNT (type, sign_bit)) -R_API size_t read_u32_leb128 (const ut8* p, const ut8* max, ut32* out_value) { +RZ_API size_t read_u32_leb128 (const ut8* p, const ut8* max, ut32* out_value) { if (p < max && !(p[0] & 0x80)) { *out_value = LEB128_1 (ut32); return 1; @@ -208,7 +208,7 @@ R_API size_t read_u32_leb128 (const ut8* p, const ut8* max, ut32* out_value) { } } -R_API size_t read_i32_leb128 (const ut8* p, const ut8* max, st32* out_value) { +RZ_API size_t read_i32_leb128 (const ut8* p, const ut8* max, st32* out_value) { if (p < max && !(p[0] & 0x80)) { ut32 result = LEB128_1 (ut32); *out_value = SIGN_EXTEND (ut32, result, 6); @@ -241,7 +241,7 @@ R_API size_t read_i32_leb128 (const ut8* p, const ut8* max, st32* out_value) { } } -R_API size_t read_u64_leb128 (const ut8* p, const ut8* max, ut64* out_value) { +RZ_API size_t read_u64_leb128 (const ut8* p, const ut8* max, ut64* out_value) { if (p < max && !(p[0] & 0x80)) { *out_value = LEB128_1 (ut64); return 1; @@ -279,7 +279,7 @@ R_API size_t read_u64_leb128 (const ut8* p, const ut8* max, ut64* out_value) { } } -R_API size_t read_i64_leb128 (const ut8* p, const ut8* max, st64* out_value) { +RZ_API size_t read_i64_leb128 (const ut8* p, const ut8* max, st64* out_value) { if (p < max && !(p[0] & 0x80)) { ut64 result = LEB128_1 (ut64); *out_value = SIGN_EXTEND (ut64, result, 6); @@ -350,7 +350,7 @@ R_API size_t read_i64_leb128 (const ut8* p, const ut8* max, st64* out_value) { main() { ut32 n; ut8 *buf = "\x10\x02\x90\x88"; - r_uleb128 (buf, &n); + rz_uleb128 (buf, &n); printf ("n = %d\n", n); } #endif diff --git a/libr/util/unum.c b/librz/util/unum.c similarity index 78% rename from libr/util/unum.c rename to librz/util/unum.c index 9622529fe3..1d7b3a094d 100644 --- a/libr/util/unum.c +++ b/librz/util/unum.c @@ -6,13 +6,13 @@ #include #include /* for ceill */ -#include +#include #define R_NUM_USE_CALC 1 -static ut64 r_num_tailff(RNum *num, const char *hex); +static ut64 rz_num_tailff(RNum *num, const char *hex); -// TODO: rename to r_num_srand() -static void r_srand(int seed) { +// TODO: rename to rz_num_srand() +static void rz_srand(int seed) { #if HAVE_ARC4RANDOM_UNIFORM // no-op (void)seed; @@ -21,7 +21,7 @@ static void r_srand(int seed) { #endif } -static int r_rand(int mod) { +static int rz_rand(int mod) { #if HAVE_ARC4RANDOM_UNIFORM return (int)arc4random_uniform (mod); #else @@ -29,23 +29,23 @@ static int r_rand(int mod) { #endif } -R_API void r_num_irand(void) { - r_srand (r_time_now ()); +RZ_API void rz_num_irand(void) { + rz_srand (rz_time_now ()); } -R_API int r_num_rand(int max) { +RZ_API int rz_num_rand(int max) { static bool rand_initialized = false; if (!rand_initialized) { - r_num_irand (); + rz_num_irand (); rand_initialized = true; } if (!max) { max = 1; } - return r_rand (max); + return rz_rand (max); } -R_API void r_num_minmax_swap(ut64 *a, ut64 *b) { +RZ_API void rz_num_minmax_swap(ut64 *a, ut64 *b) { if (*a > *b) { ut64 tmp = *a; *a = *b; @@ -53,7 +53,7 @@ R_API void r_num_minmax_swap(ut64 *a, ut64 *b) { } } -R_API void r_num_minmax_swap_i(int *a, int *b) { +RZ_API void rz_num_minmax_swap_i(int *a, int *b) { if (*a > *b) { ut64 tmp = *a; *a = *b; @@ -61,7 +61,7 @@ R_API void r_num_minmax_swap_i(int *a, int *b) { } } -R_API RNum *r_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr) { +RZ_API RNum *rz_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr) { RNum *num = R_NEW0 (RNum); if (!num) { return NULL; @@ -73,7 +73,7 @@ R_API RNum *r_num_new(RNumCallback cb, RNumCallback2 cb2, void *ptr) { return num; } -R_API void r_num_free(RNum *num) { +RZ_API void rz_num_free(RNum *num) { free (num); } @@ -94,7 +94,7 @@ R_API void r_num_free(RNum *num) { * On success, returns a pointer to buf. It returns NULL if * insufficient memory was available. */ -R_API char *r_num_units(char *buf, size_t len, ut64 num) { +RZ_API char *rz_num_units(char *buf, size_t len, ut64 num) { long double fnum; char unit; const char *fmt_str; @@ -120,7 +120,7 @@ R_API char *r_num_units(char *buf, size_t len, ut64 num) { return buf; } -R_API const char *r_num_get_name(RNum *num, ut64 n) { +RZ_API const char *rz_num_get_name(RNum *num, ut64 n) { if (num->cb_from_value) { int ok = 0; const char *msg = num->cb_from_value (num, n, &ok); @@ -145,7 +145,7 @@ static void error(RNum *num, const char *err_str) { // TODO: try to avoid the use of sscanf /* old get_offset */ -R_API ut64 r_num_get(RNum *num, const char *str) { +RZ_API ut64 rz_num_get(RNum *num, const char *str) { int i, j, ok; char lch, len; ut64 ret = 0LL; @@ -218,14 +218,14 @@ R_API ut64 r_num_get(RNum *num, const char *str) { ret = str[1] & 0xff; // ugly as hell } else if (!strncmp (str, "0xff..", 6) || !strncmp (str, "0xFF..", 6)) { - ret = r_num_tailff (num, str + 6); + ret = rz_num_tailff (num, str + 6); // ugly as hell } else if (!strncmp (str, "0o", 2)) { if (sscanf (str + 2, "%"PFMT64o, &ret) != 1) { error (num, "invalid octal number"); } } else if (!strncmp (str, "0xf..", 5) || !strncmp (str, "0xF..", 5)) { - ret = r_num_tailff (num, str + 5); + ret = rz_num_tailff (num, str + 5); } else if (str[0] == '0' && tolower (str[1]) == 'x') { const char *lodash = strchr (str + 2, '_'); if (lodash) { @@ -233,7 +233,7 @@ R_API ut64 r_num_get(RNum *num, const char *str) { // TODO: Only take underscores separated every 4 chars starting at the end char *s = strdup (str + 2); if (s) { - r_str_replace_char (s, '_', 0); + rz_str_replace_char (s, '_', 0); errno = 0; ret = strtoull (s, NULL, 16); free (s); @@ -389,7 +389,7 @@ R_API ut64 r_num_get(RNum *num, const char *str) { } #if !R_NUM_USE_CALC -static ut64 r_num_op(RNum *num, char op, ut64 a, ut64 b) { +static ut64 rz_num_op(RNum *num, char op, ut64 a, ut64 b) { switch (op) { case '+': return a + b; case '-': return a - b; @@ -404,23 +404,23 @@ static ut64 r_num_op(RNum *num, char op, ut64 a, ut64 b) { return b; } -R_API static ut64 r_num_math_internal(RNum *num, char *s) { +RZ_API static ut64 rz_num_math_internal(RNum *num, char *s) { ut64 ret = 0LL; char *p = s; int i, nop, op = 0; for (i=0; s[i]; i++) { - if (r_num_is_op (s[i])) { + if (rz_num_is_op (s[i])) { nop = s[i]; s[i] = '\0'; - ret = r_num_op (num, op, ret, r_num_get (num, p)); + ret = rz_num_op (num, op, ret, rz_num_get (num, p)); op = s[i] = nop; p = s + i + 1; break; } } - return r_num_op (op, ret, r_num_get (num, p)); + return rz_num_op (op, ret, rz_num_get (num, p)); } #endif /* !R_NUM_USE_CALC */ -R_API ut64 r_num_math(RNum *num, const char *str) { +RZ_API ut64 rz_num_math(RNum *num, const char *str) { #if R_NUM_USE_CALC ut64 ret; const char *err = NULL; @@ -431,9 +431,9 @@ R_API ut64 r_num_math(RNum *num, const char *str) { if (num) { num->dbz = 0; } - ret = r_num_calc (num, str, &err); + ret = rz_num_calc (num, str, &err); if (err) { - eprintf ("r_num_calc error: (%s) in (%s)\n", err, str); + eprintf ("rz_num_calc error: (%s) in (%s)\n", err, str); } if (num) { num->value = ret; @@ -459,30 +459,30 @@ R_API ut64 r_num_math(RNum *num, const char *str) { group = strchr (p, '('); if (group) { group[0] = '\0'; - ret = r_num_op (op, ret, r_num_math_internal (num, p)); + ret = rz_num_op (op, ret, rz_num_math_internal (num, p)); for (; p> 32) { @@ -540,7 +540,7 @@ R_API int r_num_to_bits(char *out, ut64 num) { return size; } -R_API int r_num_to_trits(char *out, ut64 num) { +RZ_API int rz_num_to_trits(char *out, ut64 num) { if (out == NULL) { return false; } @@ -554,18 +554,18 @@ R_API int r_num_to_trits(char *out, ut64 num) { } out[i] = '\0'; - r_str_reverse (out); + rz_str_reverse (out); return true; } -R_API ut64 r_num_chs(int cylinder, int head, int sector, int sectorsize) { +RZ_API ut64 rz_num_chs(int cylinder, int head, int sector, int sectorsize) { if (sectorsize < 1) { sectorsize = 512; } return (ut64)cylinder * (ut64)head * (ut64)sector * (ut64)sectorsize; } -R_API int r_num_conditional(RNum *num, const char *str) { +RZ_API int rz_num_conditional(RNum *num, const char *str) { char *lgt, *t, *p, *s = strdup (str); int res = 0; ut64 n, a, b; @@ -578,14 +578,14 @@ R_API int r_num_conditional(RNum *num, const char *str) { lgt = strchr (p, '<'); if (lgt) { *lgt = 0; - a = r_num_math (num, p); + a = rz_num_math (num, p); if (lgt[1] == '=') { - b = r_num_math (num, lgt + 2); + b = rz_num_math (num, lgt + 2); if (a > b) { goto fail; } } else { - b = r_num_math (num, lgt + 1); + b = rz_num_math (num, lgt + 1); if (a >= b) { goto fail; } @@ -594,14 +594,14 @@ R_API int r_num_conditional(RNum *num, const char *str) { lgt = strchr (p, '>'); if (lgt) { *lgt = 0; - a = r_num_math (num, p); + a = rz_num_math (num, p); if (lgt[1] == '=') { - b = r_num_math (num, lgt + 2); + b = rz_num_math (num, lgt + 2); if (a < b) { goto fail; } } else { - b = r_num_math (num, lgt + 1); + b = rz_num_math (num, lgt + 1); if (a <= b) { goto fail; } @@ -611,9 +611,9 @@ R_API int r_num_conditional(RNum *num, const char *str) { if (lgt && lgt > p) { lgt--; if (*lgt == '!') { - r_str_replace_char (p, '!', ' '); - r_str_replace_char (p, '=', '-'); - n = r_num_math (num, p); + rz_str_replace_char (p, '!', ' '); + rz_str_replace_char (p, '=', '-'); + n = rz_num_math (num, p); if (!n) { goto fail; } @@ -623,8 +623,8 @@ R_API int r_num_conditional(RNum *num, const char *str) { if (lgt) { *lgt = ' '; } - r_str_replace_char (p, '=', '-'); - n = r_num_math (num, p); + rz_str_replace_char (p, '=', '-'); + n = rz_num_math (num, p); if (n) { goto fail; } @@ -638,13 +638,13 @@ fail: return res; } -R_API int r_num_is_valid_input(RNum *num, const char *input_value) { - ut64 value = input_value ? r_num_math (num, input_value) : 0; +RZ_API int rz_num_is_valid_input(RNum *num, const char *input_value) { + ut64 value = input_value ? rz_num_math (num, input_value) : 0; return !(value == 0 && input_value && *input_value != '0') || !(value == 0 && input_value && *input_value != '@'); } -R_API ut64 r_num_get_input_value(RNum *num, const char *input_value) { - ut64 value = input_value ? r_num_math (num, input_value) : 0; +RZ_API ut64 rz_num_get_input_value(RNum *num, const char *input_value) { + ut64 value = input_value ? rz_num_math (num, input_value) : 0; return value; } @@ -667,7 +667,7 @@ static int escape_char(char* dst, char byte) { return 0; } -R_API char* r_num_as_string(RNum *___, ut64 n, bool printable_only) { +RZ_API char* rz_num_as_string(RNum *___, ut64 n, bool printable_only) { char str[34]; // 8 byte * 4 chars in \x?? format int stri, ret = 0, off = 0; int len = sizeof (ut64); @@ -697,17 +697,17 @@ R_API char* r_num_as_string(RNum *___, ut64 n, bool printable_only) { return NULL; } -R_API bool r_is_valid_input_num_value(RNum *num, const char *input_value) { +RZ_API bool rz_is_valid_input_num_value(RNum *num, const char *input_value) { if (!input_value) { return false; } - ut64 value = r_num_math (num, input_value); + ut64 value = rz_num_math (num, input_value); return !(value == 0 && *input_value != '0'); } // SHITTY API -R_API ut64 r_get_input_num_value(RNum *num, const char *str) { - return (str && *str)? r_num_math (num, str) : 0; +RZ_API ut64 rz_get_input_num_value(RNum *num, const char *str) { + return (str && *str)? rz_num_math (num, str) : 0; } // SHITTY API @@ -717,7 +717,7 @@ static inline ut64 __nth_nibble(ut64 n, ut32 i) { return (n >> s) & 0xf; } -R_API ut64 r_num_tail_base(RNum *num, ut64 addr, ut64 off) { +RZ_API ut64 rz_num_tail_base(RNum *num, ut64 addr, ut64 off) { int i; bool ready = false; ut64 res = 0; @@ -739,7 +739,7 @@ R_API ut64 r_num_tail_base(RNum *num, ut64 addr, ut64 off) { return res; } -R_API ut64 r_num_tail(RNum *num, ut64 addr, const char *hex) { +RZ_API ut64 rz_num_tail(RNum *num, ut64 addr, const char *hex) { ut64 mask = 0LL; ut64 n = 0; char *p; @@ -754,7 +754,7 @@ R_API ut64 r_num_tail(RNum *num, ut64 addr, const char *hex) { strcpy (p, "0x"); strcpy (p + 2, hex); if (isxdigit ((ut8)hex[0])) { - n = r_num_math (num, p); + n = rz_num_math (num, p); } else { eprintf ("Invalid argument\n"); free (p); @@ -766,7 +766,7 @@ R_API ut64 r_num_tail(RNum *num, ut64 addr, const char *hex) { return (addr & mask) | n; } -static ut64 r_num_tailff(RNum *num, const char *hex) { +static ut64 rz_num_tailff(RNum *num, const char *hex) { ut64 n = 0; while (*hex && (*hex == ' ' || *hex == '.')) { @@ -778,7 +778,7 @@ static ut64 r_num_tailff(RNum *num, const char *hex) { strcpy (p, "0x"); strcpy (p + 2, hex); if (isxdigit ((ut8)hex[0])) { - n = r_num_get (num, p); + n = rz_num_get (num, p); } else { eprintf ("Invalid argument\n"); free (p); @@ -790,35 +790,35 @@ static ut64 r_num_tailff(RNum *num, const char *hex) { return left | n; } -R_API int r_num_between(RNum *num, const char *input_value) { +RZ_API int rz_num_between(RNum *num, const char *input_value) { int i; ut64 ns[3]; char * const str = strdup (input_value); - RList *nums = r_num_str_split_list (str); - int len = r_list_length (nums); + RzList *nums = rz_num_str_split_list (str); + int len = rz_list_length (nums); if (len < 3) { free (str); - r_list_free (nums); + rz_list_free (nums); return -1; } if (len > 3) { len = 3; } for (i = 0; i < len; i++) { - ns[i] = r_num_math (num, r_list_pop_head (nums)); + ns[i] = rz_num_math (num, rz_list_pop_head (nums)); } free (str); - r_list_free (nums); + rz_list_free (nums); return num->value = R_BETWEEN (ns[0], ns[1], ns[2]); } -R_API bool r_num_is_op(const char c) { +RZ_API bool rz_num_is_op(const char c) { return c == '/' || c == '+' || c == '-' || c == '*' || c == '%' || c == '&' || c == '^' || c == '|'; } // Assumed *str is parsed as an expression correctly -R_API int r_num_str_len(const char *str) { +RZ_API int rz_num_str_len(const char *str) { int i = 0, len = 0, st; st = 0; // 0: number, 1: op if (str[0] == '(') { @@ -827,11 +827,11 @@ R_API int r_num_str_len(const char *str) { while (str[i] != '\0') { switch (st) { case 0: // number - while (!r_num_is_op (str[i]) && str[i] != ' ' + while (!rz_num_is_op (str[i]) && str[i] != ' ' && str[i] != '\0') { i++; if (str[i] == '(') { - i += r_num_str_len (str+i); + i += rz_num_str_len (str+i); } } len = i; @@ -841,7 +841,7 @@ R_API int r_num_str_len(const char *str) { while (str[i] != '\0' && str[i] == ' ') { i++; } - if (!r_num_is_op (str[i])) { + if (!rz_num_is_op (str[i])) { return len; } if (str[i] == ')') { @@ -858,11 +858,11 @@ R_API int r_num_str_len(const char *str) { return len; } -R_API int r_num_str_split(char *str) { +RZ_API int rz_num_str_split(char *str) { int i = 0, count = 0; const int len = strlen (str); while (i < len) { - i += r_num_str_len (str + i); + i += rz_num_str_len (str + i); str[i] = '\0'; i++; count++; @@ -870,17 +870,17 @@ R_API int r_num_str_split(char *str) { return count; } -R_API RList *r_num_str_split_list(char *str) { - int i, count = r_num_str_split (str); - RList *list = r_list_new (); +RZ_API RzList *rz_num_str_split_list(char *str) { + int i, count = rz_num_str_split (str); + RzList *list = rz_list_new (); for (i = 0; i < count; i++) { - r_list_append (list, str); + rz_list_append (list, str); str += strlen (str) + 1; } return list; } -R_API void *r_num_dup(ut64 n) { +RZ_API void *rz_num_dup(ut64 n) { ut64 *hn = malloc (sizeof (ut64)); if (!hn) { return NULL; @@ -889,10 +889,10 @@ R_API void *r_num_dup(ut64 n) { return (void*)hn; } -R_API double r_num_cos(double a) { +RZ_API double rz_num_cos(double a) { return cos (a); } -R_API double r_num_sin(double a) { +RZ_API double rz_num_sin(double a) { return sin (a); } diff --git a/libr/util/utf16.c b/librz/util/utf16.c similarity index 69% rename from libr/util/utf16.c rename to librz/util/utf16.c index 21f0953fb0..6cb241a436 100644 --- a/libr/util/utf16.c +++ b/librz/util/utf16.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2017 - kazarmy */ +/* rizin - LGPL - Copyright 2017 - kazarmy */ -#include -#include +#include +#include /* Convert an UTF-16 buf into a unicode RRune */ -R_API int r_utf16_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) { +RZ_API int rz_utf16_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) { if (ptrlen < 1) { return 0; } @@ -33,17 +33,17 @@ R_API int r_utf16_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) } /* Convert an UTF-16LE buf into a unicode RRune */ -R_API int r_utf16le_decode(const ut8 *ptr, int ptrlen, RRune *ch) { - return r_utf16_decode (ptr, ptrlen, ch, false); +RZ_API int rz_utf16le_decode(const ut8 *ptr, int ptrlen, RRune *ch) { + return rz_utf16_decode (ptr, ptrlen, ch, false); } /* Convert an UTF-16BE buf into a unicode RRune */ -R_API int r_utf16be_decode(const ut8 *ptr, int ptrlen, RRune *ch) { - return r_utf16_decode (ptr, ptrlen, ch, true); +RZ_API int rz_utf16be_decode(const ut8 *ptr, int ptrlen, RRune *ch) { + return rz_utf16_decode (ptr, ptrlen, ch, true); } /* Convert a unicode RRune into a UTF-16LE buf */ -R_API int r_utf16le_encode(ut8 *ptr, RRune ch) { +RZ_API int rz_utf16le_encode(ut8 *ptr, RRune ch) { if (ch < 0x10000) { ptr[0] = ch & 0xff; ptr[1] = ch >> 8 & 0xff; diff --git a/libr/util/utf32.c b/librz/util/utf32.c similarity index 58% rename from libr/util/utf32.c rename to librz/util/utf32.c index ff0ca1bd49..22b878a421 100644 --- a/libr/util/utf32.c +++ b/librz/util/utf32.c @@ -1,10 +1,10 @@ -/* radare2 - LGPL - Copyright 2017 - kazarmy */ +/* rizin - LGPL - Copyright 2017 - kazarmy */ -#include -#include +#include +#include /* Convert an UTF-32 buf into a unicode RRune */ -R_API int r_utf32_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) { +RZ_API int rz_utf32_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) { if (ptrlen < 1) { return 0; } @@ -35,11 +35,11 @@ R_API int r_utf32_decode(const ut8 *ptr, int ptrlen, RRune *ch, bool bigendian) } /* Convert an UTF-32LE buf into a unicode RRune */ -R_API int r_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch) { - return r_utf32_decode (ptr, ptrlen, ch, false); +RZ_API int rz_utf32le_decode(const ut8 *ptr, int ptrlen, RRune *ch) { + return rz_utf32_decode (ptr, ptrlen, ch, false); } /* Convert an UTF-32BE buf into a unicode RRune */ -R_API int r_utf32be_decode(const ut8 *ptr, int ptrlen, RRune *ch) { - return r_utf32_decode (ptr, ptrlen, ch, true); +RZ_API int rz_utf32be_decode(const ut8 *ptr, int ptrlen, RRune *ch) { + return rz_utf32_decode (ptr, ptrlen, ch, true); } diff --git a/libr/util/utf8.c b/librz/util/utf8.c similarity index 94% rename from libr/util/utf8.c rename to librz/util/utf8.c index c308efd3e3..777c01f12d 100644 --- a/libr/util/utf8.c +++ b/librz/util/utf8.c @@ -1,7 +1,7 @@ -/* radare2 - LGPL - Copyright 2014-2018 - thelemon, kazarmy, pancake */ +/* rizin - LGPL - Copyright 2014-2018 - thelemon, kazarmy, pancake */ -#include -#include +#include +#include static const struct { ut32 from, to; } nonprintable_ranges[] = { { 0x0000, 0x001F }, { 0x007F, 0x009F }, { 0x034F, 0x034F }, @@ -192,7 +192,7 @@ static const int nonprintable_ranges_count = sizeof (nonprintable_ranges) / size static const int lastUtfBlock = 281; -const RUtfBlock r_utf_blocks[] = { +const RUtfBlock rz_utf_blocks[] = { { 0x0000, 0x007F, "Basic Latin" }, { 0x0080, 0x00FF, "Latin-1 Supplement" }, { 0x0100, 0x017F, "Latin Extended-A" }, @@ -476,17 +476,17 @@ const RUtfBlock r_utf_blocks[] = { { 0x110000, 0xFFFFFFFF, "No_Block" } }; -R_API const char *r_utf_block_name(int idx) { +RZ_API const char *rz_utf_block_name(int idx) { if (idx < 0 || idx >= lastUtfBlock) { return NULL; } - return r_utf_blocks[idx].name; + return rz_utf_blocks[idx].name; } -#define r_utf_blocks_count (sizeof (r_utf_blocks) / sizeof (r_utf_blocks[0])) +#define rz_utf_blocks_count (sizeof (rz_utf_blocks) / sizeof (rz_utf_blocks[0])) /* Convert an UTF-8 buf into a unicode RRune */ -R_API int r_utf8_decode(const ut8 *ptr, int ptrlen, RRune *ch) { +RZ_API int rz_utf8_decode(const ut8 *ptr, int ptrlen, RRune *ch) { if (ptrlen < 1) { return 0; } @@ -515,7 +515,7 @@ R_API int r_utf8_decode(const ut8 *ptr, int ptrlen, RRune *ch) { } /* Convert a unicode RRune into an UTF-8 buf */ -R_API int r_utf8_encode(ut8 *ptr, const RRune ch) { +RZ_API int rz_utf8_encode(ut8 *ptr, const RRune ch) { if (ch < 0x80) { ptr[0] = (ut8)ch; return 1; @@ -542,7 +542,7 @@ R_API int r_utf8_encode(ut8 *ptr, const RRune ch) { } /* Convert a unicode RRune string into an utf-8 one */ -R_API int r_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length) { +RZ_API int rz_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length) { int i, pos = 0; if (!str || !dst) { @@ -550,7 +550,7 @@ R_API int r_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length) { } for (i = 0; i < sizeof (str) - 1 && str[i] && pos < dst_length - 1; i++) { - pos += r_utf8_encode (&dst[pos], str[i]); + pos += rz_utf8_encode (&dst[pos], str[i]); } dst[pos++] = '\0'; @@ -558,7 +558,7 @@ R_API int r_utf8_encode_str(const RRune *str, ut8 *dst, const int dst_length) { } /* Returns the size in bytes of the utf-8 encoded char */ -R_API int r_utf8_size(const ut8 *ptr) { +RZ_API int rz_utf8_size(const ut8 *ptr) { const int utf8_size[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -572,7 +572,7 @@ R_API int r_utf8_size(const ut8 *ptr) { return (ptr[0]&0x80) ? utf8_size[ptr[0]^0x80] : 1; } -R_API int r_utf8_strlen(const ut8 *str) { +RZ_API int rz_utf8_strlen(const ut8 *str) { int i, len = 0; for (i = 0; str[i]; i++) { @@ -584,7 +584,7 @@ R_API int r_utf8_strlen(const ut8 *str) { return len; } -R_API int r_isprint(const RRune c) { +RZ_API int rz_isprint(const RRune c) { // RRunes are most commonly single byte... We can early out with this common case. if (c < 0x34F) { /* @@ -617,7 +617,7 @@ R_API int r_isprint(const RRune c) { } #if __WINDOWS__ -R_API char *r_utf16_to_utf8_l(const wchar_t *wc, int len) { +RZ_API char *rz_utf16_to_utf8_l(const wchar_t *wc, int len) { if (!wc || !len || len < -1) { return NULL; } @@ -636,7 +636,7 @@ R_API char *r_utf16_to_utf8_l(const wchar_t *wc, int len) { return rutf8; } -R_API wchar_t *r_utf8_to_utf16_l(const char *cstring, int len) { +RZ_API wchar_t *rz_utf8_to_utf16_l(const char *cstring, int len) { if (!cstring || !len || len < -1) { return NULL; } @@ -655,7 +655,7 @@ R_API wchar_t *r_utf8_to_utf16_l(const char *cstring, int len) { return rutf16; } -R_API char *r_utf8_to_acp_l(const char *str, int len) { +RZ_API char *rz_utf8_to_acp_l(const char *str, int len) { if (!str || !len || len < -1) { return NULL; } @@ -684,7 +684,7 @@ R_API char *r_utf8_to_acp_l(const char *str, int len) { return acp; } -R_API char *r_acp_to_utf8_l(const char *str, int len) { +RZ_API char *rz_acp_to_utf8_l(const char *str, int len) { if (!str || !len || len < -1) { return NULL; } @@ -697,7 +697,7 @@ R_API char *r_acp_to_utf8_l(const char *str, int len) { if (len != -1) { rutf16[wcsize - 1] = L'\0'; } - char *ret = r_utf16_to_utf8_l (rutf16, wcsize); + char *ret = rz_utf16_to_utf8_l (rutf16, wcsize); free (rutf16); return ret; } @@ -707,8 +707,8 @@ R_API char *r_acp_to_utf8_l(const char *str, int len) { #endif // __WINDOWS__ -R_API int r_utf_block_idx(RRune ch) { - const int last = r_utf_blocks_count; +RZ_API int rz_utf_block_idx(RRune ch) { + const int last = rz_utf_blocks_count; int low, hi, mid; low = 0; @@ -716,29 +716,29 @@ R_API int r_utf_block_idx(RRune ch) { do { mid = (low + hi) >> 1; - if (ch >= r_utf_blocks[mid].from && ch <= r_utf_blocks[mid].to) { + if (ch >= rz_utf_blocks[mid].from && ch <= rz_utf_blocks[mid].to) { return mid; } - if (mid < last && ch > r_utf_blocks[mid].to) { + if (mid < last && ch > rz_utf_blocks[mid].to) { low = mid + 1; } - if (mid < last && ch < r_utf_blocks[mid].from) { + if (mid < last && ch < rz_utf_blocks[mid].from) { hi = mid - 1; } } while (low <= hi); - return r_utf_blocks_count - 1; /* index for "No_Block" */ + return rz_utf_blocks_count - 1; /* index for "No_Block" */ } /* str must be UTF8-encoded */ -R_API int *r_utf_block_list(const ut8 *str, int len, int **freq_list) { +RZ_API int *rz_utf_block_list(const ut8 *str, int len, int **freq_list) { if (!str) { return NULL; } if (len < 0) { len = strlen ((const char *)str); } - static int block_freq[r_utf_blocks_count] = {0}; + static int block_freq[rz_utf_blocks_count] = {0}; int *list = R_NEWS (int, len + 1); if (!list) { return NULL; @@ -758,12 +758,12 @@ R_API int *r_utf_block_list(const ut8 *str, int len, int **freq_list) { RRune ch; while (str_ptr < str_end) { int block_idx; - int ch_bytes = r_utf8_decode (str_ptr, str_end - str_ptr, &ch); + int ch_bytes = rz_utf8_decode (str_ptr, str_end - str_ptr, &ch); if (!ch_bytes) { - block_idx = r_utf_blocks_count - 1; + block_idx = rz_utf_blocks_count - 1; ch_bytes = 1; } else { - block_idx = r_utf_block_idx (ch); + block_idx = rz_utf_block_idx (ch); } if (!block_freq[block_idx]) { *list_ptr = block_idx; @@ -786,7 +786,7 @@ R_API int *r_utf_block_list(const ut8 *str, int len, int **freq_list) { return list; } -R_API RStrEnc r_utf_bom_encoding(const ut8 *ptr, int ptrlen) { +RZ_API RStrEnc rz_utf_bom_encoding(const ut8 *ptr, int ptrlen) { if (ptrlen > 3) { if (ptr[0] == 0xff && ptr[1] == 0xfe && !ptr[2] && !ptr[3]) { return R_STRING_ENC_UTF32LE; diff --git a/libr/util/utype.c b/librz/util/utype.c similarity index 72% rename from libr/util/utype.c rename to librz/util/utype.c index a133ac58c8..cdc32e2eb9 100644 --- a/libr/util/utype.c +++ b/librz/util/utype.c @@ -1,8 +1,8 @@ /* radare - LGPL - Copyright 2013-2020 - pancake, oddcoder, sivaramaaa */ -#include +#include -R_API int r_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val) { +RZ_API int rz_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val) { const char *kind; char var[128]; sprintf (var, "link.%08"PFMT64x, at); @@ -21,7 +21,7 @@ R_API int r_type_set(Sdb *TDB, ut64 at, const char *field, ut64 val) { return false; } -R_API int r_type_kind(Sdb *TDB, const char *name) { +RZ_API int rz_type_kind(Sdb *TDB, const char *name) { if (!name) { return -1; } @@ -47,25 +47,25 @@ R_API int r_type_kind(Sdb *TDB, const char *name) { return -1; } -R_API RList* r_type_get_enum (Sdb *TDB, const char *name) { +RZ_API RzList* rz_type_get_enum (Sdb *TDB, const char *name) { char *p, var[130]; int n; - if (r_type_kind (TDB, name) != R_TYPE_ENUM) { + if (rz_type_kind (TDB, name) != R_TYPE_ENUM) { return NULL; } - RList *res = r_list_new (); + RzList *res = rz_list_new (); snprintf (var, sizeof (var), "enum.%s", name); for (n = 0; (p = sdb_array_get (TDB, var, n, NULL)); n++) { RTypeEnum *member = R_NEW0 (RTypeEnum); if (member) { - char *var2 = r_str_newf ("%s.%s", var, p); + char *var2 = rz_str_newf ("%s.%s", var, p); if (var2) { char *val = sdb_array_get (TDB, var2, 0, NULL); if (val) { member->name = p; member->val = val; - r_list_append (res, member); + rz_list_append (res, member); } else { free (member); free (var2); @@ -78,8 +78,8 @@ R_API RList* r_type_get_enum (Sdb *TDB, const char *name) { return res; } -R_API char *r_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val) { - if (r_type_kind (TDB, name) != R_TYPE_ENUM) { +RZ_API char *rz_type_enum_member(Sdb *TDB, const char *name, const char *member, ut64 val) { + if (rz_type_kind (TDB, name) != R_TYPE_ENUM) { return NULL; } const char *q = member @@ -88,16 +88,16 @@ R_API char *r_type_enum_member(Sdb *TDB, const char *name, const char *member, u return sdb_get (TDB, q, 0); } -R_API char *r_type_enum_getbitfield(Sdb *TDB, const char *name, ut64 val) { +RZ_API char *rz_type_enum_getbitfield(Sdb *TDB, const char *name, ut64 val) { char *q, *ret = NULL; const char *res; int i; - if (r_type_kind (TDB, name) != R_TYPE_ENUM) { + if (rz_type_kind (TDB, name) != R_TYPE_ENUM) { return NULL; } bool isFirst = true; - ret = r_str_appendf (ret, "0x%08"PFMT64x" : ", val); + ret = rz_str_appendf (ret, "0x%08"PFMT64x" : ", val); for (i = 0; i < 32; i++) { ut32 n = 1ULL << i; if (!(val & n)) { @@ -108,18 +108,18 @@ R_API char *r_type_enum_getbitfield(Sdb *TDB, const char *name, ut64 val) { if (isFirst) { isFirst = false; } else { - ret = r_str_append (ret, " | "); + ret = rz_str_append (ret, " | "); } if (res) { - ret = r_str_append (ret, res); + ret = rz_str_append (ret, res); } else { - ret = r_str_appendf (ret, "0x%x", n); + ret = rz_str_appendf (ret, "0x%x", n); } } return ret; } -R_API ut64 r_type_get_bitsize(Sdb *TDB, const char *type) { +RZ_API ut64 rz_type_get_bitsize(Sdb *TDB, const char *type) { char *query; /* Filter out the structure keyword if type looks like "struct mystruc" */ const char *tmptype; @@ -142,13 +142,13 @@ R_API ut64 r_type_get_bitsize(Sdb *TDB, const char *type) { return 0; } if (!strcmp (t, "type")){ - query = r_str_newf ("type.%s.size", tmptype); + query = rz_str_newf ("type.%s.size", tmptype); ut64 r = sdb_num_get (TDB, query, 0); // returns size in bits free (query); return r; } if (!strcmp (t, "struct") || !strcmp (t, "union")) { - query = r_str_newf ("%s.%s", t, tmptype); + query = rz_str_newf ("%s.%s", t, tmptype); char *members = sdb_get (TDB, query, 0); char *next, *ptr = members; ut64 ret = 0; @@ -159,7 +159,7 @@ R_API ut64 r_type_get_bitsize(Sdb *TDB, const char *type) { break; } free (query); - query = r_str_newf ("%s.%s.%s", t, tmptype, name); + query = rz_str_newf ("%s.%s.%s", t, tmptype, name); char *subtype = sdb_get (TDB, query, 0); R_FREE (query); if (!subtype) { @@ -172,14 +172,14 @@ R_API ut64 r_type_get_bitsize(Sdb *TDB, const char *type) { if (tmp) { *tmp++ = 0; } - int elements = r_num_math (NULL, tmp); + int elements = rz_num_math (NULL, tmp); if (elements == 0) { elements = 1; } if (!strcmp (t, "struct")) { - ret += r_type_get_bitsize (TDB, subtype) * elements; + ret += rz_type_get_bitsize (TDB, subtype) * elements; } else { - ut64 sz = r_type_get_bitsize (TDB, subtype) * elements; + ut64 sz = rz_type_get_bitsize (TDB, subtype) * elements; ret = sz > ret ? sz : ret; } } @@ -194,7 +194,7 @@ R_API ut64 r_type_get_bitsize(Sdb *TDB, const char *type) { return 0; } -R_API char *r_type_get_struct_memb(Sdb *TDB, const char *type, int offset) { +RZ_API char *rz_type_get_struct_memb(Sdb *TDB, const char *type, int offset) { int i, prev_typesize, typesize = 0; char *res = NULL; @@ -207,9 +207,9 @@ R_API char *r_type_get_struct_memb(Sdb *TDB, const char *type, int offset) { //eprintf ("%s is not a struct\n", type); return NULL; } - int nargs = r_str_split (members, ','); + int nargs = rz_str_split (members, ','); for (i = 0; i < nargs ; i++) { - const char *name = r_str_word_get0 (members, i); + const char *name = rz_str_word_get0 (members, i); if (!name) { break; } @@ -218,34 +218,34 @@ R_API char *r_type_get_struct_memb(Sdb *TDB, const char *type, int offset) { if (!subtype) { break; } - int len = r_str_split (subtype, ','); + int len = rz_str_split (subtype, ','); if (len < 3) { free (subtype); break; } - int val = r_num_math (NULL, r_str_word_get0 (subtype, len - 1)); + int val = rz_num_math (NULL, rz_str_word_get0 (subtype, len - 1)); int arrsz = val ? val : 1; if ((typesize / 8) == offset) { - res = r_str_newf ("%s.%s", type, name); + res = rz_str_newf ("%s.%s", type, name); free (subtype); break; } prev_typesize = typesize; - typesize += r_type_get_bitsize (TDB, subtype) * arrsz; + typesize += rz_type_get_bitsize (TDB, subtype) * arrsz; // Handle nested structs if (offset < (typesize / 8)) { - char *nested_type = (char *)r_str_word_get0 (subtype, 0); - if (r_str_startswith (nested_type, "struct ") && !r_str_endswith (nested_type, " *")) { - len = r_str_split (nested_type, ' '); + char *nested_type = (char *)rz_str_word_get0 (subtype, 0); + if (rz_str_startswith (nested_type, "struct ") && !rz_str_endswith (nested_type, " *")) { + len = rz_str_split (nested_type, ' '); if (len < 2) { free (subtype); break; } - nested_type = (char *)r_str_word_get0 (nested_type, 1); - char *nested_res = r_type_get_struct_memb (TDB, nested_type, offset - (prev_typesize / 8)); + nested_type = (char *)rz_str_word_get0 (nested_type, 1); + char *nested_res = rz_type_get_struct_memb (TDB, nested_type, offset - (prev_typesize / 8)); if (nested_res) { - len = r_str_split(nested_res, '.'); - res = r_str_newf ("%s.%s.%s", type, name, r_str_word_get0 (nested_res, len - 1)); + len = rz_str_split(nested_res, '.'); + res = rz_str_newf ("%s.%s.%s", type, name, rz_str_word_get0 (nested_res, len - 1)); free (nested_res); free (subtype); break; @@ -259,17 +259,17 @@ R_API char *r_type_get_struct_memb(Sdb *TDB, const char *type, int offset) { } // XXX this function is slow! -R_API RList* r_type_get_by_offset(Sdb *TDB, ut64 offset) { - RList *offtypes = r_list_new (); +RZ_API RzList* rz_type_get_by_offset(Sdb *TDB, ut64 offset) { + RzList *offtypes = rz_list_new (); SdbList *ls = sdb_foreach_list (TDB, true); SdbListIter *lsi; SdbKv *kv; ls_foreach (ls, lsi, kv) { // TODO: Add unions support if (!strncmp (sdbkv_value (kv), "struct", 6) && strncmp (sdbkv_key (kv), "struct.", 7)) { - char *res = r_type_get_struct_memb (TDB, sdbkv_key (kv), offset); + char *res = rz_type_get_struct_memb (TDB, sdbkv_key (kv), offset); if (res) { - r_list_append (offtypes, res); + rz_list_append (offtypes, res); } } } @@ -280,14 +280,14 @@ R_API RList* r_type_get_by_offset(Sdb *TDB, ut64 offset) { // XXX 12 is the maxstructsizedelta #define TYPE_RANGE_BASE(x) ((x)>>16) -static RList *types_range_list(Sdb *db, ut64 addr) { - RList *list = NULL; +static RzList *types_range_list(Sdb *db, ut64 addr) { + RzList *list = NULL; ut64 base = TYPE_RANGE_BASE (addr); - char *s = r_str_newf ("range.%"PFMT64x, base); + char *s = rz_str_newf ("range.%"PFMT64x, base); if (s) { char *r = sdb_get (db, s, 0); if (r) { - list = r_str_split_list (r, " ", -1); + list = rz_str_split_list (r, " ", -1); } free (s); } @@ -308,23 +308,23 @@ static void types_range_add(Sdb *db, ut64 addr) { (void)sdb_array_add_num (db, k, addr, 0); } -R_API char *r_type_link_at(Sdb *TDB, ut64 addr) { +RZ_API char *rz_type_link_at(Sdb *TDB, ut64 addr) { if (addr == UT64_MAX) { return NULL; } const char *query = sdb_fmt ("link.%08"PFMT64x, addr); char *res = sdb_get (TDB, query, 0); if (!res) { // resolve struct memb if possible for given addr - RList *list = types_range_list (TDB, addr); - RListIter *iter; + RzList *list = types_range_list (TDB, addr); + RzListIter *iter; const char *s; - r_list_foreach (list, iter, s) { - ut64 laddr = r_num_get (NULL, s); + rz_list_foreach (list, iter, s) { + ut64 laddr = rz_num_get (NULL, s); if (addr > laddr) { int delta = addr - laddr; const char *lk = sdb_fmt ("link.%08"PFMT64x, laddr); char *k = sdb_get (TDB, lk, 0); - res = r_type_get_struct_memb (TDB, k, delta); + res = rz_type_get_struct_memb (TDB, k, delta); if (res) { break; } @@ -335,9 +335,9 @@ R_API char *r_type_link_at(Sdb *TDB, ut64 addr) { return res; } -R_API int r_type_set_link(Sdb *TDB, const char *type, ut64 addr) { +RZ_API int rz_type_set_link(Sdb *TDB, const char *type, ut64 addr) { if (sdb_const_get (TDB, type, 0)) { - char *laddr = r_str_newf ("link.%08"PFMT64x, addr); + char *laddr = rz_str_newf ("link.%08"PFMT64x, addr); sdb_set (TDB, laddr, type, 0); types_range_add (TDB, addr); free (laddr); @@ -346,9 +346,9 @@ R_API int r_type_set_link(Sdb *TDB, const char *type, ut64 addr) { return false; } -R_API int r_type_link_offset(Sdb *TDB, const char *type, ut64 addr) { +RZ_API int rz_type_link_offset(Sdb *TDB, const char *type, ut64 addr) { if (sdb_const_get (TDB, type, 0)) { - char *laddr = r_str_newf ("offset.%08"PFMT64x, addr); + char *laddr = rz_str_newf ("offset.%08"PFMT64x, addr); sdb_set (TDB, laddr, type, 0); free (laddr); return true; @@ -356,7 +356,7 @@ R_API int r_type_link_offset(Sdb *TDB, const char *type, ut64 addr) { return false; } -R_API int r_type_unlink(Sdb *TDB, ut64 addr) { +RZ_API int rz_type_unlink(Sdb *TDB, ut64 addr) { char *laddr = sdb_fmt ("link.%08"PFMT64x, addr); sdb_unset (TDB, laddr, 0); types_range_del (TDB, addr); @@ -367,7 +367,7 @@ static char *fmt_struct_union(Sdb *TDB, char *var, bool is_typedef) { // assumes var list is sorted by offset.. should do more checks here char *p = NULL, *vars = NULL, var2[132], *fmt = NULL; size_t n; - char *fields = r_str_newf ("%s.fields", var); + char *fields = rz_str_newf ("%s.fields", var); char *nfields = (is_typedef) ? fields : var; for (n = 0; (p = sdb_array_get (TDB, nfields, n, NULL)); n++) { char *struct_name; @@ -384,7 +384,7 @@ static char *fmt_struct_union(Sdb *TDB, char *var, bool is_typedef) { // Handle general pointers except for char * if ((strstr (type, "*(") || strstr (type, " *")) && strncmp (type, "char *", 7)) { isfp = true; - } else if (r_str_startswith (type, "struct ")) { + } else if (rz_str_startswith (type, "struct ")) { struct_name = type + 7; // TODO: iterate over all the struct fields, and format the format and vars snprintf (var3, sizeof (var3), "struct.%s", struct_name); @@ -398,7 +398,7 @@ static char *fmt_struct_union(Sdb *TDB, char *var, bool is_typedef) { tfmt++; } } else { - if (r_str_startswith (type, "enum ")) { + if (rz_str_startswith (type, "enum ")) { snprintf (var3, sizeof (var3), "%s", type + 5); isEnum = true; } else { @@ -410,26 +410,26 @@ static char *fmt_struct_union(Sdb *TDB, char *var, bool is_typedef) { } if (isfp) { // consider function pointer as void * for printing - fmt = r_str_append (fmt, "p"); - vars = r_str_append (vars, p); - vars = r_str_append (vars, " "); + fmt = rz_str_append (fmt, "p"); + vars = rz_str_append (vars, p); + vars = rz_str_append (vars, " "); } else if (tfmt) { - (void) r_str_replace_ch (type, ' ', '_', true); + (void) rz_str_replace_ch (type, ' ', '_', true); if (elements > 0) { - fmt = r_str_appendf (fmt, "[%d]", elements); + fmt = rz_str_appendf (fmt, "[%d]", elements); } if (isStruct) { - fmt = r_str_append (fmt, "?"); - vars = r_str_appendf (vars, "(%s)%s", struct_name, p); - vars = r_str_append (vars, " "); + fmt = rz_str_append (fmt, "?"); + vars = rz_str_appendf (vars, "(%s)%s", struct_name, p); + vars = rz_str_append (vars, " "); } else if (isEnum) { - fmt = r_str_append (fmt, "E"); - vars = r_str_appendf (vars, "(%s)%s", type + 5, p); - vars = r_str_append (vars, " "); + fmt = rz_str_append (fmt, "E"); + vars = rz_str_appendf (vars, "(%s)%s", type + 5, p); + vars = rz_str_append (vars, " "); } else { - fmt = r_str_append (fmt, tfmt); - vars = r_str_append (vars, p); - vars = r_str_append (vars, " "); + fmt = rz_str_append (fmt, tfmt); + vars = rz_str_append (vars, p); + vars = rz_str_append (vars, " "); } } else { eprintf ("Cannot resolve type '%s'\n", var3); @@ -439,13 +439,13 @@ static char *fmt_struct_union(Sdb *TDB, char *var, bool is_typedef) { free (p); } free (fields); - fmt = r_str_append (fmt, " "); - fmt = r_str_append (fmt, vars); + fmt = rz_str_append (fmt, " "); + fmt = rz_str_append (fmt, vars); free (vars); return fmt; } -R_API char *r_type_format(Sdb *TDB, const char *t) { +RZ_API char *rz_type_format(Sdb *TDB, const char *t) { char var[130], var2[132]; const char *kind = sdb_const_get (TDB, t, NULL); if (!kind) { @@ -472,7 +472,7 @@ R_API char *r_type_format(Sdb *TDB, const char *t) { return NULL; } -R_API void r_type_del(Sdb *TDB, const char *name) { +RZ_API void rz_type_del(Sdb *TDB, const char *name) { const char *kind = sdb_const_get (TDB, name, 0); if (!kind) { return; @@ -484,7 +484,7 @@ R_API void r_type_del(Sdb *TDB, const char *name) { sdb_unset (TDB, name, 0); } else if (!strcmp (kind, "struct") || !strcmp (kind, "union")) { int i, n = sdb_array_length(TDB, sdb_fmt ("%s.%s", kind, name)); - char *elements_key = r_str_newf ("%s.%s", kind, name); + char *elements_key = rz_str_newf ("%s.%s", kind, name); for (i = 0; i< n; i++) { char *p = sdb_array_get (TDB, elements_key, i, NULL); sdb_unset (TDB, sdb_fmt ("%s.%s", elements_key, p), 0); @@ -504,21 +504,21 @@ R_API void r_type_del(Sdb *TDB, const char *name) { sdb_unset (TDB, sdb_fmt ("func.%s.args", name), 0); sdb_unset (TDB, name, 0); } else if (!strcmp (kind, "enum")) { - RList *list = r_type_get_enum (TDB, name); + RzList *list = rz_type_get_enum (TDB, name); RTypeEnum *member; - RListIter *iter; - r_list_foreach (list, iter, member) { + RzListIter *iter; + rz_list_foreach (list, iter, member) { sdb_unset (TDB, sdb_fmt ("enum.%s.%s", name, member->name), 0); sdb_unset (TDB, sdb_fmt ("enum.%s.%s", name, member->val), 0); } sdb_unset (TDB, name, 0); - r_list_free (list); + rz_list_free (list); } else if (!strcmp (kind, "typedef")) { RStrBuf buf; - r_strbuf_init (&buf); - r_strbuf_setf (&buf, "typedef.%s", name); - sdb_unset (TDB, r_strbuf_get (&buf), 0); - r_strbuf_fini (&buf); + rz_strbuf_init (&buf); + rz_strbuf_setf (&buf, "typedef.%s", name); + sdb_unset (TDB, rz_strbuf_get (&buf), 0); + rz_strbuf_fini (&buf); sdb_unset (TDB, name, 0); } else { eprintf ("Unrecognized type kind \"%s\"\n", kind); @@ -526,22 +526,22 @@ R_API void r_type_del(Sdb *TDB, const char *name) { } // Function prototypes api -R_API int r_type_func_exist(Sdb *TDB, const char *func_name) { +RZ_API int rz_type_func_exist(Sdb *TDB, const char *func_name) { const char *fcn = sdb_const_get (TDB, func_name, 0); return fcn && !strcmp (fcn, "func"); } -R_API const char *r_type_func_ret(Sdb *TDB, const char *func_name){ +RZ_API const char *rz_type_func_ret(Sdb *TDB, const char *func_name){ const char *query = sdb_fmt ("func.%s.ret", func_name); return sdb_const_get (TDB, query, 0); } -R_API int r_type_func_args_count(Sdb *TDB, const char *func_name) { +RZ_API int rz_type_func_args_count(Sdb *TDB, const char *func_name) { const char *query = sdb_fmt ("func.%s.args", func_name); return sdb_num_get (TDB, query, 0); } -R_API R_OWN char *r_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i) { +RZ_API R_OWN char *rz_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_name, int i) { const char *query = sdb_fmt ("func.%s.arg.%d", func_name, i); char *ret = sdb_get (TDB, query, 0); if (ret) { @@ -555,7 +555,7 @@ R_API R_OWN char *r_type_func_args_type(Sdb *TDB, R_NONNULL const char *func_nam return NULL; } -R_API const char *r_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i) { +RZ_API const char *rz_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_name, int i) { const char *query = sdb_fmt ("func.%s.arg.%d", func_name, i); const char *get = sdb_const_get (TDB, query, 0); if (get) { @@ -569,7 +569,7 @@ R_API const char *r_type_func_args_name(Sdb *TDB, R_NONNULL const char *func_nam static R_OWN char *type_func_try_guess(Sdb *TDB, R_NONNULL char *name) { const char *res; - if (r_str_nlen (name, MIN_MATCH_LEN) < MIN_MATCH_LEN) { + if (rz_str_nlen (name, MIN_MATCH_LEN) < MIN_MATCH_LEN) { return NULL; } if ((res = sdb_const_get (TDB, name, NULL))) { @@ -584,13 +584,13 @@ static R_OWN char *type_func_try_guess(Sdb *TDB, R_NONNULL char *name) { // TODO: // - symbol names are long and noisy, some of them might not be matched due // to additional information added around name -R_API R_OWN char *r_type_func_guess(Sdb *TDB, R_NONNULL char *func_name) { +RZ_API R_OWN char *rz_type_func_guess(Sdb *TDB, R_NONNULL char *func_name) { int offset = 0; char *str = func_name; char *result = NULL; char *first; - r_return_val_if_fail (TDB, false); - r_return_val_if_fail (func_name, false); + rz_return_val_if_fail (TDB, false); + rz_return_val_if_fail (func_name, false); size_t slen = strlen (str); if (slen < MIN_MATCH_LEN) { @@ -626,7 +626,7 @@ R_API R_OWN char *r_type_func_guess(Sdb *TDB, R_NONNULL char *func_name) { str = strdup (str); // Remove func-number from module_func-number // sym._ExitProcess_4 ==> ExitProcess - char *l = (char *)r_str_lchr (str, '_'); + char *l = (char *)rz_str_lchr (str, '_'); if (l) { char *tmp = l + 1; char *first = strchr (str, '_'); diff --git a/librz/util/vector.c b/librz/util/vector.c new file mode 100644 index 0000000000..6272bef0ea --- /dev/null +++ b/librz/util/vector.c @@ -0,0 +1,336 @@ +/* radare - LGPL - Copyright 2017-2020 - maskray, thestr4ng3r */ + +#include "rz_vector.h" + +// Optimize memory usage on glibc +#if __WORDSIZE == 32 +// Chunk size 24, minus 4 (chunk header), minus 8 for capacity and len, 12 bytes remaining for 3 void * +#define INITIAL_VECTOR_LEN 3 +#else +// For __WORDSIZE == 64 +// Chunk size 48, minus 8 (chunk header), minus 8 for capacity and len, 32 bytes remaining for 4 void * +#define INITIAL_VECTOR_LEN 4 +#endif + +#define NEXT_VECTOR_CAPACITY (vec->capacity < INITIAL_VECTOR_LEN \ + ? INITIAL_VECTOR_LEN \ + : vec->capacity <= 12 ? vec->capacity * 2 \ + : vec->capacity + (vec->capacity >> 1)) + +#define RESIZE_OR_RETURN_NULL(next_capacity) do { \ + size_t new_capacity = next_capacity; \ + void **new_a = realloc (vec->a, vec->elem_size * new_capacity); \ + if (!new_a) { \ + return NULL; \ + } \ + vec->a = new_a; \ + vec->capacity = new_capacity; \ + } while (0) + +RZ_API void rz_vector_init(RzVector *vec, size_t elem_size, RzVectorFree free, void *free_user) { + rz_return_if_fail (vec); + vec->a = NULL; + vec->capacity = vec->len = 0; + vec->elem_size = elem_size; + vec->free = free; + vec->free_user = free_user; +} + +RZ_API RzVector *rz_vector_new(size_t elem_size, RzVectorFree free, void *free_user) { + RzVector *vec = R_NEW (RzVector); + if (!vec) { + return NULL; + } + rz_vector_init (vec, elem_size, free, free_user); + return vec; +} + +static void vector_free_elems(RzVector *vec) { + if (vec->free) { + while (vec->len > 0) { + vec->free (rz_vector_index_ptr (vec, --vec->len), vec->free_user); + } + } else { + vec->len = 0; + } +} + +RZ_API void rz_vector_fini(RzVector *vec) { + rz_return_if_fail (vec); + rz_vector_clear (vec); + vec->free = NULL; + vec->free_user = NULL; +} + +RZ_API void rz_vector_clear(RzVector *vec) { + rz_return_if_fail (vec); + vector_free_elems (vec); + R_FREE (vec->a); + vec->capacity = 0; +} + +RZ_API void rz_vector_free(RzVector *vec) { + if (vec) { + rz_vector_fini (vec); + free (vec); + } +} + +static bool vector_clone(RzVector *dst, RzVector *src) { + rz_return_val_if_fail (dst && src, false); + dst->capacity = src->capacity; + dst->len = src->len; + dst->elem_size = src->elem_size; + dst->free = src->free; + dst->free_user = src->free_user; + if (!dst->len) { + dst->a = NULL; + } else { + dst->a = malloc (src->elem_size * src->capacity); + if (!dst->a) { + return false; + } + memcpy (dst->a, src->a, src->elem_size * src->len); + } + return true; +} + +RZ_API RzVector *rz_vector_clone(RzVector *vec) { + rz_return_val_if_fail (vec, NULL); + RzVector *ret = R_NEW (RzVector); + if (!ret) { + return NULL; + } + if (!vector_clone (ret, vec)) { + free (ret); + return NULL; + } + return ret; +} + +RZ_API void rz_vector_assign(RzVector *vec, void *p, void *elem) { + rz_return_if_fail (vec && p && elem); + memcpy (p, elem, vec->elem_size); +} + +RZ_API void *rz_vector_assign_at(RzVector *vec, size_t index, void *elem) { + void *p = rz_vector_index_ptr (vec, index); + if (elem) { + rz_vector_assign (vec, p, elem); + } + return p; +} + +RZ_API void rz_vector_remove_at(RzVector *vec, size_t index, void *into) { + rz_return_if_fail (vec); + void *p = rz_vector_index_ptr (vec, index); + if (into) { + rz_vector_assign (vec, into, p); + } + vec->len--; + if (index < vec->len) { + memmove (p, (char *)p + vec->elem_size, vec->elem_size * (vec->len - index)); + } +} + +RZ_API void *rz_vector_insert(RzVector *vec, size_t index, void *x) { + rz_return_val_if_fail (vec && index <= vec->len, NULL); + if (vec->len >= vec->capacity) { + RESIZE_OR_RETURN_NULL (NEXT_VECTOR_CAPACITY); + } + void *p = rz_vector_index_ptr (vec, index); + if (index < vec->len) { + memmove ((char *)p + vec->elem_size, p, vec->elem_size * (vec->len - index)); + } + vec->len++; + if (x) { + rz_vector_assign (vec, p, x); + } + return p; +} + +RZ_API void *rz_vector_insert_range(RzVector *vec, size_t index, void *first, size_t count) { + rz_return_val_if_fail (vec && index <= vec->len, NULL); + if (vec->len + count > vec->capacity) { + RESIZE_OR_RETURN_NULL (R_MAX (NEXT_VECTOR_CAPACITY, vec->len + count)); + } + size_t sz = count * vec->elem_size; + void *p = rz_vector_index_ptr (vec, index); + if (index < vec->len) { + memmove ((char *)p + sz, p, vec->elem_size * (vec->len - index)); + } + vec->len += count; + if (first) { + memcpy (p, first, sz); + } + return p; +} + +RZ_API void rz_vector_pop(RzVector *vec, void *into) { + rz_return_if_fail (vec); + if (into) { + rz_vector_assign (vec, into, rz_vector_index_ptr (vec, vec->len - 1)); + } + vec->len--; +} + +RZ_API void rz_vector_pop_front(RzVector *vec, void *into) { + rz_return_if_fail (vec); + rz_vector_remove_at (vec, 0, into); +} + +RZ_API void *rz_vector_push(RzVector *vec, void *x) { + rz_return_val_if_fail (vec, NULL); + if (vec->len >= vec->capacity) { + RESIZE_OR_RETURN_NULL (NEXT_VECTOR_CAPACITY); + } + void *p = rz_vector_index_ptr (vec, vec->len++); + if (x) { + rz_vector_assign (vec, p, x); + } + return p; +} + +RZ_API void *rz_vector_push_front(RzVector *vec, void *x) { + rz_return_val_if_fail (vec, NULL); + return rz_vector_insert (vec, 0, x); +} + +RZ_API void *rz_vector_reserve(RzVector *vec, size_t capacity) { + rz_return_val_if_fail (vec, NULL); + if (vec->capacity < capacity) { + RESIZE_OR_RETURN_NULL (capacity); + } + return vec->a; +} + +RZ_API void *rz_vector_shrink(RzVector *vec) { + rz_return_val_if_fail (vec, NULL); + if (vec->len < vec->capacity) { + RESIZE_OR_RETURN_NULL (vec->len); + } + return vec->a; +} + +// pvector + +static void pvector_free_elem(void *e, void *user) { + void *p = *((void **)e); + RPVectorFree elem_free = (RPVectorFree)user; + elem_free (p); +} + +RZ_API void rz_pvector_init(RPVector *vec, RPVectorFree free) { + rz_vector_init (&vec->v, sizeof (void *), free ? pvector_free_elem : NULL, free); +} + +RZ_API RPVector *rz_pvector_new(RPVectorFree free) { + RPVector *v = R_NEW (RPVector); + if (!v) { + return NULL; + } + rz_pvector_init (v, free); + return v; +} + +RZ_API RPVector *rz_pvector_new_with_len(RPVectorFree free, size_t length) { + RPVector *v = rz_pvector_new (free); + if (!v) { + return NULL; + } + void** p = rz_pvector_reserve (v, length); + if (!p) { + rz_pvector_free (v); + return NULL; + } + memset (p, 0, v->v.elem_size * v->v.capacity); + v->v.len = length; + return v; +} + +RZ_API void rz_pvector_clear(RPVector *vec) { + rz_return_if_fail (vec); + rz_vector_clear (&vec->v); +} + +RZ_API void rz_pvector_fini(RPVector *vec) { + rz_return_if_fail (vec); + rz_vector_fini (&vec->v); +} + +RZ_API void rz_pvector_free(RPVector *vec) { + if (!vec) { + return; + } + rz_vector_fini (&vec->v); + free (vec); +} + +RZ_API void **rz_pvector_contains(RPVector *vec, void *x) { + rz_return_val_if_fail (vec, NULL); + size_t i; + for (i = 0; i < vec->v.len; i++) { + if (((void **)vec->v.a)[i] == x) { + return &((void **)vec->v.a)[i]; + } + } + return NULL; +} + +RZ_API void *rz_pvector_remove_at(RPVector *vec, size_t index) { + rz_return_val_if_fail (vec, NULL); + void *r = rz_pvector_at (vec, index); + rz_vector_remove_at (&vec->v, index, NULL); + return r; +} + +RZ_API void rz_pvector_remove_data(RPVector *vec, void *x) { + void **el = rz_pvector_contains (vec, x); + if (!el) { + return; + } + + size_t index = el - (void **)vec->v.a; + rz_vector_remove_at (&vec->v, index, NULL); +} + +RZ_API void *rz_pvector_pop(RPVector *vec) { + rz_return_val_if_fail (vec, NULL); + void *r = rz_pvector_at (vec, vec->v.len - 1); + rz_vector_pop (&vec->v, NULL); + return r; +} + +RZ_API void *rz_pvector_pop_front(RPVector *vec) { + rz_return_val_if_fail (vec, NULL); + void *r = rz_pvector_at (vec, 0); + rz_vector_pop_front (&vec->v, NULL); + return r; +} + +// CLRS Quicksort. It is slow, but simple. +static void quick_sort(void **a, size_t n, RPVectorComparator cmp) { + if (n <= 1) { + return; + } + size_t i = rand() % n, j = 0; + void *t, *pivot = a[i]; + a[i] = a[n - 1]; + for (i = 0; i < n - 1; i++) { + if (cmp (a[i], pivot) < 0) { + t = a[i]; + a[i] = a[j]; + a[j] = t; + j++; + } + } + a[n - 1] = a[j]; + a[j] = pivot; + quick_sort (a, j, cmp); + quick_sort (a + j + 1, n - j - 1, cmp); +} + +RZ_API void rz_pvector_sort(RPVector *vec, RPVectorComparator cmp) { + rz_return_if_fail (vec && cmp); + quick_sort (vec->v.a, vec->v.len, cmp); +} diff --git a/libr/util/w32-sys.c b/librz/util/w32-sys.c similarity index 85% rename from libr/util/w32-sys.c rename to librz/util/w32-sys.c index 842b9cbefc..c84af28079 100644 --- a/libr/util/w32-sys.c +++ b/librz/util/w32-sys.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #if __WINDOWS__ #include @@ -7,12 +7,12 @@ #include #define BUFSIZE 1024 -void r_sys_perror_str(const char *fun); +void rz_sys_perror_str(const char *fun); -#define ErrorExit(x) { r_sys_perror(x); return false; } +#define ErrorExit(x) { rz_sys_perror(x); return false; } char *ReadFromPipe(HANDLE fh, int *outlen); -R_API char *r_sys_get_src_dir_w32(void) { +RZ_API char *rz_sys_get_src_dir_w32(void) { TCHAR fullpath[MAX_PATH + 1]; TCHAR shortpath[MAX_PATH + 1]; @@ -20,17 +20,17 @@ R_API char *r_sys_get_src_dir_w32(void) { !GetShortPathName (fullpath, shortpath, MAX_PATH + 1)) { return NULL; } - char *path = r_sys_conv_win_to_utf8 (shortpath); - char *dir = r_file_dirname (path); - if (!r_sys_getenv_asbool ("R_ALT_SRC_DIR")) { + char *path = rz_sys_conv_win_to_utf8 (shortpath); + char *dir = rz_file_dirname (path); + if (!rz_sys_getenv_asbool ("R_ALT_SRC_DIR")) { char *tmp = dir; - dir = r_file_dirname (tmp); + dir = rz_file_dirname (tmp); free (tmp); } return dir; } -R_API bool r_sys_cmd_str_full_w32(const char *cmd, const char *input, char **output, int *outlen, char **sterr) { +RZ_API bool rz_sys_cmd_str_full_w32(const char *cmd, const char *input, char **output, int *outlen, char **sterr) { HANDLE in = NULL; HANDLE out = NULL; HANDLE err = NULL; @@ -73,7 +73,7 @@ R_API bool r_sys_cmd_str_full_w32(const char *cmd, const char *input, char **out } } - if (!r_sys_create_child_proc_w32 (cmd, fi, out, err)) { + if (!rz_sys_create_child_proc_w32 (cmd, fi, out, err)) { return false; } @@ -112,7 +112,7 @@ R_API bool r_sys_cmd_str_full_w32(const char *cmd, const char *input, char **out return true; } -R_API bool r_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) { +RZ_API bool rz_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE out, HANDLE err) { PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {0}; LPTSTR cmdline_; @@ -132,7 +132,7 @@ R_API bool r_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE ou si.hStdOutput = out; si.hStdInput = in; si.dwFlags |= STARTF_USESTDHANDLES; - cmdline_ = r_sys_conv_utf8_to_win (cmdline); + cmdline_ = rz_sys_conv_utf8_to_win (cmdline); ExpandEnvironmentStrings (cmdline_, _cmdline_, max_length - 1); if ((ret = CreateProcess (NULL, _cmdline_, // command line @@ -148,7 +148,7 @@ R_API bool r_sys_create_child_proc_w32(const char *cmdline, HANDLE in, HANDLE ou CloseHandle (pi.hProcess); CloseHandle (pi.hThread); } else { - r_sys_perror ("CreateProcess"); + rz_sys_perror ("CreateProcess"); } free (cmdline_); free (_cmdline_); diff --git a/libr/util/x509.c b/librz/util/x509.c similarity index 54% rename from libr/util/x509.c rename to librz/util/x509.c index d0d09d7a89..51f40328a5 100644 --- a/libr/util/x509.c +++ b/librz/util/x509.c @@ -1,12 +1,12 @@ -/* radare2 - LGPL - Copyright 2017-2018 - wargio */ +/* rizin - LGPL - Copyright 2017-2018 - wargio */ -#include -#include +#include +#include #include #include #include "./x509.h" -static bool r_x509_parse_validity(RX509Validity *validity, RASN1Object *object) { +static bool rz_x509_parse_validity(RX509Validity *validity, RASN1Object *object) { RASN1Object *o; if (!validity || !object || object->list.length != 2) { return false; @@ -17,17 +17,17 @@ static bool r_x509_parse_validity(RX509Validity *validity, RASN1Object *object) o = object->list.objects[0]; if (o->klass == CLASS_UNIVERSAL && o->form == FORM_PRIMITIVE) { if (o->tag == TAG_UTCTIME) { - validity->notBefore = r_asn1_stringify_utctime (o->sector, o->length); + validity->notBefore = rz_asn1_stringify_utctime (o->sector, o->length); } else if (o->tag == TAG_GENERALIZEDTIME) { - validity->notBefore = r_asn1_stringify_time (o->sector, o->length); + validity->notBefore = rz_asn1_stringify_time (o->sector, o->length); } } o = object->list.objects[1]; if (o->klass == CLASS_UNIVERSAL && o->form == FORM_PRIMITIVE) { if (o->tag == TAG_UTCTIME) { - validity->notAfter = r_asn1_stringify_utctime (o->sector, o->length); + validity->notAfter = rz_asn1_stringify_utctime (o->sector, o->length); } else if (o->tag == TAG_GENERALIZEDTIME) { - validity->notAfter = r_asn1_stringify_time (o->sector, o->length); + validity->notAfter = rz_asn1_stringify_time (o->sector, o->length); } } } @@ -40,42 +40,42 @@ static inline bool is_oid_object (RASN1Object *object) { object->list.objects[0]->tag == TAG_OID; } -bool r_x509_parse_algorithmidentifier (RX509AlgorithmIdentifier *ai, RASN1Object *object) { - r_return_val_if_fail (ai && object, false); +bool rz_x509_parse_algorithmidentifier (RX509AlgorithmIdentifier *ai, RASN1Object *object) { + rz_return_val_if_fail (ai && object, false); if (object->list.length < 1 || !object->list.objects || !is_oid_object (object)) { return false; } - ai->algorithm = r_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); + ai->algorithm = rz_asn1_stringify_oid (object->list.objects[0]->sector, object->list.objects[0]->length); ai->parameters = NULL; // TODO //ai->parameters = asn1_stringify_sector (object->list.objects[1]); return true; } -bool r_x509_parse_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki, RASN1Object *object) { +bool rz_x509_parse_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki, RASN1Object *object) { RASN1Object *o; if (!spki || !object || object->list.length != 2) { return false; } - r_x509_parse_algorithmidentifier (&spki->algorithm, object->list.objects[0]); + rz_x509_parse_algorithmidentifier (&spki->algorithm, object->list.objects[0]); if (object->list.objects[1]) { o = object->list.objects[1]; - spki->subjectPublicKey = r_asn1_create_binary (o->sector, o->length); + spki->subjectPublicKey = rz_asn1_create_binary (o->sector, o->length); if (o->list.length == 1 && o->list.objects[0] && o->list.objects[0]->list.length == 2) { o = o->list.objects[0]; if (o->list.objects[0]) { - spki->subjectPublicKeyExponent = r_asn1_create_binary (o->list.objects[0]->sector, o->list.objects[0]->length); + spki->subjectPublicKeyExponent = rz_asn1_create_binary (o->list.objects[0]->sector, o->list.objects[0]->length); } if (o->list.objects[1]) { - spki->subjectPublicKeyModule = r_asn1_create_binary (o->list.objects[1]->sector, o->list.objects[1]->length); + spki->subjectPublicKeyModule = rz_asn1_create_binary (o->list.objects[1]->sector, o->list.objects[1]->length); } } } return true; } -bool r_x509_parse_name (RX509Name *name, RASN1Object *object) { +bool rz_x509_parse_name (RX509Name *name, RASN1Object *object) { ut32 i; if (!name || !object || !object->list.length) { return false; @@ -105,11 +105,11 @@ bool r_x509_parse_name (RX509Name *name, RASN1Object *object) { o->tag == TAG_SEQUENCE) { if (o->list.objects[0]->klass == CLASS_UNIVERSAL && o->list.objects[0]->tag == TAG_OID) { - name->oids[i] = r_asn1_stringify_oid (o->list.objects[0]->sector, o->list.objects[0]->length); + name->oids[i] = rz_asn1_stringify_oid (o->list.objects[0]->sector, o->list.objects[0]->length); } RASN1Object *obj1 = o->list.objects[1]; if (obj1 && obj1->klass == CLASS_UNIVERSAL) { - name->names[i] = r_asn1_stringify_string (obj1->sector, obj1->length); + name->names[i] = rz_asn1_stringify_string (obj1->sector, obj1->length); } } } @@ -118,14 +118,14 @@ bool r_x509_parse_name (RX509Name *name, RASN1Object *object) { return true; } -bool r_x509_parse_extension (RX509Extension *ext, RASN1Object *object) { +bool rz_x509_parse_extension (RX509Extension *ext, RASN1Object *object) { RASN1Object *o; if (!ext || !object || object->list.length < 2) { return false; } o = object->list.objects[0]; if (o && o->tag == TAG_OID) { - ext->extnID = r_asn1_stringify_oid (o->sector, o->length); + ext->extnID = rz_asn1_stringify_oid (o->sector, o->length); o = object->list.objects[1]; if (o->tag == TAG_BOOLEAN && object->list.length > 2) { //This field is optional (so len must be 3) @@ -133,13 +133,13 @@ bool r_x509_parse_extension (RX509Extension *ext, RASN1Object *object) { o = object->list.objects[2]; } if (o->tag == TAG_OCTETSTRING) { - ext->extnValue = r_asn1_create_binary (o->sector, o->length); + ext->extnValue = rz_asn1_create_binary (o->sector, o->length); } } return true; } -bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object *object) { +bool rz_x509_parse_extensions (RX509Extensions *ext, RASN1Object *object) { ut32 i; if (!ext || !object || object->list.length != 1 || !object->list.objects[0]->length) { return false; @@ -152,15 +152,15 @@ bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object *object) { ext->length = object->list.length; for (i = 0; i < object->list.length; i++) { ext->extensions[i] = R_NEW0 (RX509Extension); - if (!r_x509_parse_extension (ext->extensions[i], object->list.objects[i])) { - r_x509_free_extension (ext->extensions[i]); + if (!rz_x509_parse_extension (ext->extensions[i], object->list.objects[i])) { + rz_x509_free_extension (ext->extensions[i]); ext->extensions[i] = NULL; } } return true; } -bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object *object) { +bool rz_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object *object) { RASN1Object **elems; ut32 i; ut32 shift = 0; @@ -181,39 +181,39 @@ bool r_x509_parse_tbscertificate (RX509TBSCertificate *tbsc, RASN1Object *object tbsc->version = 0; } if (shift < object->list.length && elems[shift]->klass == CLASS_UNIVERSAL && elems[shift]->tag == TAG_INTEGER) { - tbsc->serialNumber = r_asn1_stringify_integer (elems[shift]->sector, elems[shift]->length); + tbsc->serialNumber = rz_asn1_stringify_integer (elems[shift]->sector, elems[shift]->length); } - r_x509_parse_algorithmidentifier (&tbsc->signature, elems[shift + 1]); - r_x509_parse_name (&tbsc->issuer, elems[shift + 2]); - r_x509_parse_validity (&tbsc->validity, elems[shift + 3]); - r_x509_parse_name (&tbsc->subject, elems[shift + 4]); - r_x509_parse_subjectpublickeyinfo (&tbsc->subjectPublicKeyInfo, elems[shift + 5]); + rz_x509_parse_algorithmidentifier (&tbsc->signature, elems[shift + 1]); + rz_x509_parse_name (&tbsc->issuer, elems[shift + 2]); + rz_x509_parse_validity (&tbsc->validity, elems[shift + 3]); + rz_x509_parse_name (&tbsc->subject, elems[shift + 4]); + rz_x509_parse_subjectpublickeyinfo (&tbsc->subjectPublicKeyInfo, elems[shift + 5]); if (tbsc->version > 0) { for (i = shift + 6; i < object->list.length; i++) { if (!elems[i] || elems[i]->klass != CLASS_CONTEXT) { continue; } if (elems[i]->tag == 1) { - tbsc->issuerUniqueID = r_asn1_create_binary (object->list.objects[i]->sector, object->list.objects[i]->length); + tbsc->issuerUniqueID = rz_asn1_create_binary (object->list.objects[i]->sector, object->list.objects[i]->length); } if (!elems[i]) { continue; } if (elems[i]->tag == 2) { - tbsc->subjectUniqueID = r_asn1_create_binary (object->list.objects[i]->sector, object->list.objects[i]->length); + tbsc->subjectUniqueID = rz_asn1_create_binary (object->list.objects[i]->sector, object->list.objects[i]->length); } if (!elems[i]) { continue; } if (tbsc->version == 2 && elems[i]->tag == 3 && elems[i]->form == FORM_CONSTRUCTED) { - r_x509_parse_extensions (&tbsc->extensions, elems[i]); + rz_x509_parse_extensions (&tbsc->extensions, elems[i]); } } } return true; } -RX509Certificate *r_x509_parse_certificate (RASN1Object *object) { +RX509Certificate *rz_x509_parse_certificate (RASN1Object *object) { if (!object) { return NULL; } @@ -234,30 +234,30 @@ RX509Certificate *r_x509_parse_certificate (RASN1Object *object) { R_FREE (cert); goto fail; } - cert->signature = r_asn1_create_binary (object->list.objects[2]->sector, object->list.objects[2]->length); - r_x509_parse_tbscertificate (&cert->tbsCertificate, object->list.objects[0]); + cert->signature = rz_asn1_create_binary (object->list.objects[2]->sector, object->list.objects[2]->length); + rz_x509_parse_tbscertificate (&cert->tbsCertificate, object->list.objects[0]); - if (!r_x509_parse_algorithmidentifier (&cert->algorithmIdentifier, object->list.objects[1])) { + if (!rz_x509_parse_algorithmidentifier (&cert->algorithmIdentifier, object->list.objects[1])) { R_FREE (cert); } fail: - r_asn1_free_object (object); + rz_asn1_free_object (object); return cert; } -RX509Certificate *r_x509_parse_certificate2 (const ut8 *buffer, ut32 length) { +RX509Certificate *rz_x509_parse_certificate2 (const ut8 *buffer, ut32 length) { RX509Certificate *certificate; RASN1Object *object; if (!buffer || !length) { return NULL; } - object = r_asn1_create_object (buffer, length, buffer); - certificate = r_x509_parse_certificate (object); - //object freed by r_x509_parse_certificate + object = rz_asn1_create_object (buffer, length, buffer); + certificate = rz_x509_parse_certificate (object); + //object freed by rz_x509_parse_certificate return certificate; } -RX509CRLEntry *r_x509_parse_crlentry (RASN1Object *object) { +RX509CRLEntry *rz_x509_parse_crlentry (RASN1Object *object) { RX509CRLEntry *entry; if (!object || object->list.length != 2) { return NULL; @@ -266,12 +266,12 @@ RX509CRLEntry *r_x509_parse_crlentry (RASN1Object *object) { if (!entry) { return NULL; } - entry->userCertificate = r_asn1_create_binary (object->list.objects[0]->sector, object->list.objects[0]->length); - entry->revocationDate = r_asn1_stringify_utctime (object->list.objects[1]->sector, object->list.objects[1]->length); + entry->userCertificate = rz_asn1_create_binary (object->list.objects[0]->sector, object->list.objects[0]->length); + entry->revocationDate = rz_asn1_stringify_utctime (object->list.objects[1]->sector, object->list.objects[1]->length); return entry; } -R_API RX509CertificateRevocationList *r_x509_parse_crl(RASN1Object *object) { +RZ_API RX509CertificateRevocationList *rz_x509_parse_crl(RASN1Object *object) { RX509CertificateRevocationList *crl; RASN1Object **elems; if (!object || object->list.length < 4) { @@ -283,10 +283,10 @@ R_API RX509CertificateRevocationList *r_x509_parse_crl(RASN1Object *object) { } memset (crl, 0, sizeof (RX509CertificateRevocationList)); elems = object->list.objects; - r_x509_parse_algorithmidentifier (&crl->signature, elems[0]); - r_x509_parse_name (&crl->issuer, elems[1]); - crl->lastUpdate = r_asn1_stringify_utctime (elems[2]->sector, elems[2]->length); - crl->nextUpdate = r_asn1_stringify_utctime (elems[3]->sector, elems[3]->length); + rz_x509_parse_algorithmidentifier (&crl->signature, elems[0]); + rz_x509_parse_name (&crl->issuer, elems[1]); + crl->lastUpdate = rz_asn1_stringify_utctime (elems[2]->sector, elems[2]->length); + crl->nextUpdate = rz_asn1_stringify_utctime (elems[3]->sector, elems[3]->length); if (object->list.length > 4 && object->list.objects[4]) { ut32 i; crl->revokedCertificates = calloc (object->list.objects[4]->list.length, sizeof (RX509CRLEntry *)); @@ -296,37 +296,37 @@ R_API RX509CertificateRevocationList *r_x509_parse_crl(RASN1Object *object) { } crl->length = object->list.objects[4]->list.length; for (i = 0; i < object->list.objects[4]->list.length; i++) { - crl->revokedCertificates[i] = r_x509_parse_crlentry (object->list.objects[4]->list.objects[i]); + crl->revokedCertificates[i] = rz_x509_parse_crlentry (object->list.objects[4]->list.objects[i]); } } return crl; } -void r_x509_free_algorithmidentifier (RX509AlgorithmIdentifier *ai) { +void rz_x509_free_algorithmidentifier (RX509AlgorithmIdentifier *ai) { if (ai) { // no need to free ai, since this functions is used internally - r_asn1_free_string (ai->algorithm); - r_asn1_free_string (ai->parameters); + rz_asn1_free_string (ai->algorithm); + rz_asn1_free_string (ai->parameters); } } -static void r_x509_free_validity(RX509Validity *validity) { +static void rz_x509_free_validity(RX509Validity *validity) { if (validity) { // not freeing validity since it's not allocated dinamically - r_asn1_free_string (validity->notAfter); - r_asn1_free_string (validity->notBefore); + rz_asn1_free_string (validity->notAfter); + rz_asn1_free_string (validity->notBefore); } } -void r_x509_free_name (RX509Name *name) { +void rz_x509_free_name (RX509Name *name) { ut32 i; if (!name) { return; } if (name->names) { for (i = 0; i < name->length; i++) { - r_asn1_free_string (name->oids[i]); - r_asn1_free_string (name->names[i]); + rz_asn1_free_string (name->oids[i]); + rz_asn1_free_string (name->names[i]); } R_FREE (name->names); R_FREE (name->oids); @@ -334,82 +334,82 @@ void r_x509_free_name (RX509Name *name) { // not freeing name since it's not allocated dinamically } -void r_x509_free_extension (RX509Extension *ex) { +void rz_x509_free_extension (RX509Extension *ex) { if (ex) { - r_asn1_free_string (ex->extnID); - r_asn1_free_binary (ex->extnValue); + rz_asn1_free_string (ex->extnID); + rz_asn1_free_binary (ex->extnValue); //this is allocated dinamically so, i'll free free (ex); } } -void r_x509_free_extensions (RX509Extensions *ex) { +void rz_x509_free_extensions (RX509Extensions *ex) { ut32 i; if (!ex) { return; } if (ex->extensions) { for (i = 0; i < ex->length; i++) { - r_x509_free_extension (ex->extensions[i]); + rz_x509_free_extension (ex->extensions[i]); } free (ex->extensions); } //no need to free ex, since this functions is used internally } -void r_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki) { +void rz_x509_free_subjectpublickeyinfo (RX509SubjectPublicKeyInfo *spki) { if (spki) { - r_x509_free_algorithmidentifier (&spki->algorithm); - r_asn1_free_binary (spki->subjectPublicKey); - r_asn1_free_binary (spki->subjectPublicKeyExponent); - r_asn1_free_binary (spki->subjectPublicKeyModule); + rz_x509_free_algorithmidentifier (&spki->algorithm); + rz_asn1_free_binary (spki->subjectPublicKey); + rz_asn1_free_binary (spki->subjectPublicKeyExponent); + rz_asn1_free_binary (spki->subjectPublicKeyModule); // No need to free spki, since it's a static variable. } } -void r_x509_free_tbscertificate (RX509TBSCertificate *tbsc) { +void rz_x509_free_tbscertificate (RX509TBSCertificate *tbsc) { if (tbsc) { // version is ut32 - r_asn1_free_string (tbsc->serialNumber); - r_x509_free_algorithmidentifier (&tbsc->signature); - r_x509_free_name (&tbsc->issuer); - r_x509_free_validity (&tbsc->validity); - r_x509_free_name (&tbsc->subject); - r_x509_free_subjectpublickeyinfo (&tbsc->subjectPublicKeyInfo); - r_asn1_free_binary (tbsc->subjectUniqueID); - r_asn1_free_binary (tbsc->issuerUniqueID); - r_x509_free_extensions (&tbsc->extensions); + rz_asn1_free_string (tbsc->serialNumber); + rz_x509_free_algorithmidentifier (&tbsc->signature); + rz_x509_free_name (&tbsc->issuer); + rz_x509_free_validity (&tbsc->validity); + rz_x509_free_name (&tbsc->subject); + rz_x509_free_subjectpublickeyinfo (&tbsc->subjectPublicKeyInfo); + rz_asn1_free_binary (tbsc->subjectUniqueID); + rz_asn1_free_binary (tbsc->issuerUniqueID); + rz_x509_free_extensions (&tbsc->extensions); //no need to free tbsc, since this functions is used internally } } -void r_x509_free_certificate (RX509Certificate *certificate) { +void rz_x509_free_certificate (RX509Certificate *certificate) { if (certificate) { - r_asn1_free_binary (certificate->signature); - r_x509_free_algorithmidentifier (&certificate->algorithmIdentifier); - r_x509_free_tbscertificate (&certificate->tbsCertificate); + rz_asn1_free_binary (certificate->signature); + rz_x509_free_algorithmidentifier (&certificate->algorithmIdentifier); + rz_x509_free_tbscertificate (&certificate->tbsCertificate); free (certificate); } } -static void r_x509_free_crlentry(RX509CRLEntry *entry) { +static void rz_x509_free_crlentry(RX509CRLEntry *entry) { if (entry) { - r_asn1_free_binary (entry->userCertificate); - r_asn1_free_string (entry->revocationDate); + rz_asn1_free_binary (entry->userCertificate); + rz_asn1_free_string (entry->revocationDate); free (entry); } } -void r_x509_free_crl (RX509CertificateRevocationList *crl) { +void rz_x509_free_crl (RX509CertificateRevocationList *crl) { ut32 i; if (crl) { - r_x509_free_algorithmidentifier (&crl->signature); - r_x509_free_name (&crl->issuer); - r_asn1_free_string (crl->nextUpdate); - r_asn1_free_string (crl->lastUpdate); + rz_x509_free_algorithmidentifier (&crl->signature); + rz_x509_free_name (&crl->issuer); + rz_asn1_free_string (crl->nextUpdate); + rz_asn1_free_string (crl->lastUpdate); if (crl->revokedCertificates) { for (i = 0; i < crl->length; i++) { - r_x509_free_crlentry (crl->revokedCertificates[i]); + rz_x509_free_crlentry (crl->revokedCertificates[i]); crl->revokedCertificates[i] = NULL; } R_FREE (crl->revokedCertificates); @@ -418,7 +418,7 @@ void r_x509_free_crl (RX509CertificateRevocationList *crl) { } } -static void r_x509_validity_dump(RX509Validity *validity, const char *pad, RStrBuf *sb) { +static void rz_x509_validity_dump(RX509Validity *validity, const char *pad, RStrBuf *sb) { if (!validity) { return; } @@ -427,10 +427,10 @@ static void r_x509_validity_dump(RX509Validity *validity, const char *pad, RStrB } const char *b = validity->notBefore ? validity->notBefore->string : "Missing"; const char *a = validity->notAfter ? validity->notAfter->string : "Missing"; - r_strbuf_appendf (sb, "%sNot Before: %s\n%sNot After: %s\n", pad, b, pad, a); + rz_strbuf_appendf (sb, "%sNot Before: %s\n%sNot After: %s\n", pad, b, pad, a); } -void r_x509_name_dump (RX509Name *name, const char *pad, RStrBuf *sb) { +void rz_x509_name_dump (RX509Name *name, const char *pad, RStrBuf *sb) { ut32 i; if (!name) { return; @@ -442,11 +442,11 @@ void r_x509_name_dump (RX509Name *name, const char *pad, RStrBuf *sb) { if (!name->oids[i] || !name->names[i]) { continue; } - r_strbuf_appendf (sb, "%s%s: %s\n", pad, name->oids[i]->string, name->names[i]->string); + rz_strbuf_appendf (sb, "%s%s: %s\n", pad, name->oids[i]->string, name->names[i]->string); } } -static void r_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, const char *pad, RStrBuf *sb) { +static void rz_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, const char *pad, RStrBuf *sb) { const char *a; if (!spki) { return; @@ -457,18 +457,18 @@ static void r_x509_subjectpublickeyinfo_dump(RX509SubjectPublicKeyInfo *spki, co a = spki->algorithm.algorithm ? spki->algorithm.algorithm->string : "Missing"; RASN1String *m = NULL; if (spki->subjectPublicKeyModule) { - m = r_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length); + m = rz_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length); } - // RASN1String* e = r_asn1_stringify_bytes (spki->subjectPublicKeyExponent->sector, spki->subjectPublicKeyExponent->length); + // RASN1String* e = rz_asn1_stringify_bytes (spki->subjectPublicKeyExponent->sector, spki->subjectPublicKeyExponent->length); // r = snprintf (buffer, length, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n%s\n", pad, a, pad, m->string, // pad, spki->subjectPublicKeyExponent->length - 1, e->string); - r_strbuf_appendf (sb, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n", pad, a, pad, m ? m->string : "Missing", + rz_strbuf_appendf (sb, "%sAlgorithm: %s\n%sModule: %s\n%sExponent: %u bytes\n", pad, a, pad, m ? m->string : "Missing", pad, spki->subjectPublicKeyExponent ? spki->subjectPublicKeyExponent->length - 1 : 0); - r_asn1_free_string (m); - // r_asn1_free_string (e); + rz_asn1_free_string (m); + // rz_asn1_free_string (e); } -static void r_x509_extensions_dump(RX509Extensions *exts, const char *pad, RStrBuf *sb) { +static void rz_x509_extensions_dump(RX509Extensions *exts, const char *pad, RStrBuf *sb) { ut32 i; if (!exts) { return; @@ -482,16 +482,16 @@ static void r_x509_extensions_dump(RX509Extensions *exts, const char *pad, RStrB continue; } //TODO handle extensions.. - //s = r_asn1_stringify_bytes (e->extnValue->sector, e->extnValue->length); - r_strbuf_appendf (sb, "%s%s: %s\n%s%u bytes\n", pad, + //s = rz_asn1_stringify_bytes (e->extnValue->sector, e->extnValue->length); + rz_strbuf_appendf (sb, "%s%s: %s\n%s%u bytes\n", pad, e->extnID ? e->extnID->string : "Missing", e->critical ? "critical" : "", pad, e->extnValue ? e->extnValue->length : 0); - //r_asn1_free_string (s); + //rz_asn1_free_string (s); } } -static void r_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RStrBuf *sb) { +static void rz_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pad, RStrBuf *sb) { RASN1String *sid = NULL, *iid = NULL; if (!tbsc) { return; @@ -499,11 +499,11 @@ static void r_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pa if (!pad) { pad = ""; } - char *pad2 = r_str_newf ("%s ", pad); + char *pad2 = rz_str_newf ("%s ", pad); if (!pad2) { return; } - r_strbuf_appendf (sb, "%sVersion: v%u\n" + rz_strbuf_appendf (sb, "%sVersion: v%u\n" "%sSerial Number:\n%s %s\n" "%sSignature Algorithm:\n%s %s\n" "%sIssuer:\n", @@ -511,38 +511,38 @@ static void r_x509_tbscertificate_dump(RX509TBSCertificate *tbsc, const char *pa pad, pad, tbsc->serialNumber ? tbsc->serialNumber->string : "Missing", pad, pad, tbsc->signature.algorithm ? tbsc->signature.algorithm->string : "Missing", pad); - r_x509_name_dump (&tbsc->issuer, pad2, sb); + rz_x509_name_dump (&tbsc->issuer, pad2, sb); - r_strbuf_appendf (sb, "%sValidity:\n", pad); - r_x509_validity_dump (&tbsc->validity, pad2, sb); + rz_strbuf_appendf (sb, "%sValidity:\n", pad); + rz_x509_validity_dump (&tbsc->validity, pad2, sb); - r_strbuf_appendf (sb, "%sSubject:\n", pad); - r_x509_name_dump (&tbsc->subject, pad2, sb); + rz_strbuf_appendf (sb, "%sSubject:\n", pad); + rz_x509_name_dump (&tbsc->subject, pad2, sb); - r_strbuf_appendf (sb, "%sSubject Public Key Info:\n", pad); - r_x509_subjectpublickeyinfo_dump (&tbsc->subjectPublicKeyInfo, pad2, sb); + rz_strbuf_appendf (sb, "%sSubject Public Key Info:\n", pad); + rz_x509_subjectpublickeyinfo_dump (&tbsc->subjectPublicKeyInfo, pad2, sb); if (tbsc->issuerUniqueID) { - iid = r_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length); + iid = rz_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length); if (iid) { - r_strbuf_appendf (sb, "%sIssuer Unique ID:\n%s %s", pad, pad, iid->string); - r_asn1_free_string (iid); + rz_strbuf_appendf (sb, "%sIssuer Unique ID:\n%s %s", pad, pad, iid->string); + rz_asn1_free_string (iid); } } if (tbsc->subjectUniqueID) { - sid = r_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length); + sid = rz_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length); if (sid) { - r_strbuf_appendf (sb, "%sSubject Unique ID:\n%s %s", pad, pad, sid->string); - r_asn1_free_string (sid); + rz_strbuf_appendf (sb, "%sSubject Unique ID:\n%s %s", pad, pad, sid->string); + rz_asn1_free_string (sid); } } - r_strbuf_appendf (sb, "%sExtensions:\n", pad); - r_x509_extensions_dump (&tbsc->extensions, pad2, sb); + rz_strbuf_appendf (sb, "%sExtensions:\n", pad); + rz_x509_extensions_dump (&tbsc->extensions, pad2, sb); free (pad2); } -void r_x509_certificate_dump (RX509Certificate *cert, const char *pad, RStrBuf *sb) { +void rz_x509_certificate_dump (RX509Certificate *cert, const char *pad, RStrBuf *sb) { RASN1String *algo = NULL; char *pad2; if (!cert) { @@ -551,25 +551,25 @@ void r_x509_certificate_dump (RX509Certificate *cert, const char *pad, RStrBuf * if (!pad) { pad = ""; } - pad2 = r_str_newf ("%s ", pad); + pad2 = rz_str_newf ("%s ", pad); if (!pad2) { return; } - r_strbuf_appendf (sb, "%sTBSCertificate:\n", pad); - r_x509_tbscertificate_dump (&cert->tbsCertificate, pad2, sb); + rz_strbuf_appendf (sb, "%sTBSCertificate:\n", pad); + rz_x509_tbscertificate_dump (&cert->tbsCertificate, pad2, sb); algo = cert->algorithmIdentifier.algorithm; - // signature = r_asn1_stringify_bytes (certificate->signature->binary, certificate->signature->length); + // signature = rz_asn1_stringify_bytes (certificate->signature->binary, certificate->signature->length); // eprintf ("%sAlgorithm:\n%s%s\n%sSignature: %u bytes\n%s\n", // pad, pad2, algo ? algo->string : "", // pad, certificate->signature->length, signature ? signature->string : ""); - r_strbuf_appendf (sb, "%sAlgorithm:\n%s%s\n%sSignature: %u bytes\n", + rz_strbuf_appendf (sb, "%sAlgorithm:\n%s%s\n%sSignature: %u bytes\n", pad, pad2, algo ? algo->string : "", pad, cert->signature->length); free (pad2); - // r_asn1_free_string (signature); + // rz_asn1_free_string (signature); } -void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb) { +void rz_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb) { RASN1String *id = NULL, *utc = NULL; if (!crle) { return; @@ -579,16 +579,16 @@ void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb) { } utc = crle->revocationDate; if (crle->userCertificate) { - id = r_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length); + id = rz_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length); } - r_strbuf_appendf (sb, "%sUser Certificate:\n%s %s\n" + rz_strbuf_appendf (sb, "%sUser Certificate:\n%s %s\n" "%sRevocation Date:\n%s %s\n", pad, pad, id ? id->string : "Missing", pad, pad, utc ? utc->string : "Missing"); - r_asn1_free_string (id); + rz_asn1_free_string (id); } -R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char *pad) { +RZ_API char *rz_x509_crl_to_string(RX509CertificateRevocationList *crl, const char *pad) { RASN1String *algo = NULL, *last = NULL, *next = NULL; ut32 i; char *pad2, *pad3; @@ -598,7 +598,7 @@ R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char if (!pad) { pad = ""; } - pad3 = r_str_newf ("%s ", pad); + pad3 = rz_str_newf ("%s ", pad); if (!pad3) { return NULL; } @@ -606,24 +606,24 @@ R_API char *r_x509_crl_to_string(RX509CertificateRevocationList *crl, const char algo = crl->signature.algorithm; last = crl->lastUpdate; next = crl->nextUpdate; - RStrBuf *sb = r_strbuf_new (""); - r_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3, + RStrBuf *sb = rz_strbuf_new (""); + rz_strbuf_appendf (sb, "%sCRL:\n%sSignature:\n%s%s\n%sIssuer\n", pad, pad2, pad3, algo ? algo->string : "", pad2); - r_x509_name_dump (&crl->issuer, pad3, sb); + rz_x509_name_dump (&crl->issuer, pad3, sb); - r_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n", + rz_strbuf_appendf (sb, "%sLast Update: %s\n%sNext Update: %s\n%sRevoked Certificates:\n", pad2, last ? last->string : "Missing", pad2, next ? next->string : "Missing", pad2); for (i = 0; i < crl->length; i++) { - r_x509_crlentry_dump (crl->revokedCertificates[i], pad3, sb); + rz_x509_crlentry_dump (crl->revokedCertificates[i], pad3, sb); } free (pad3); - return r_strbuf_drain (sb); + return rz_strbuf_drain (sb); } -R_API void r_x509_validity_json(PJ *pj, RX509Validity *validity) { +RZ_API void rz_x509_validity_json(PJ *pj, RX509Validity *validity) { if (validity) { if (validity->notBefore) { pj_ks (pj, "NotBefore", validity->notBefore->string); @@ -634,7 +634,7 @@ R_API void r_x509_validity_json(PJ *pj, RX509Validity *validity) { } } -R_API void r_x509_name_json(PJ *pj, RX509Name *name) { +RZ_API void rz_x509_name_json(PJ *pj, RX509Name *name) { ut32 i; for (i = 0; i < name->length; i++) { if (!name->oids[i] || !name->names[i]) { @@ -644,30 +644,30 @@ R_API void r_x509_name_json(PJ *pj, RX509Name *name) { } } -R_API void r_x509_subjectpublickeyinfo_json(PJ *pj, RX509SubjectPublicKeyInfo *spki) { +RZ_API void rz_x509_subjectpublickeyinfo_json(PJ *pj, RX509SubjectPublicKeyInfo *spki) { RASN1String *m = NULL; if (spki) { if (spki->algorithm.algorithm) { pj_ks (pj, "Algorithm", spki->algorithm.algorithm->string); } if (spki->subjectPublicKeyModule) { - m = r_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length); + m = rz_asn1_stringify_integer (spki->subjectPublicKeyModule->binary, spki->subjectPublicKeyModule->length); if (m) { pj_ks (pj, "Module", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } if (spki->subjectPublicKeyExponent) { - m = r_asn1_stringify_integer (spki->subjectPublicKeyExponent->binary, spki->subjectPublicKeyExponent->length); + m = rz_asn1_stringify_integer (spki->subjectPublicKeyExponent->binary, spki->subjectPublicKeyExponent->length); if (m) { pj_ks (pj, "Exponent", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } } } -R_API void r_x509_extensions_json(PJ *pj, RX509Extensions *exts) { +RZ_API void rz_x509_extensions_json(PJ *pj, RX509Extensions *exts) { if (exts) { RASN1String *m = NULL; ut32 i; @@ -686,11 +686,11 @@ R_API void r_x509_extensions_json(PJ *pj, RX509Extensions *exts) { } //TODO handle extensions correctly.. if (e->extnValue) { - m = r_asn1_stringify_integer (e->extnValue->binary, e->extnValue->length); + m = rz_asn1_stringify_integer (e->extnValue->binary, e->extnValue->length); if (m) { pj_ks (pj, "Value", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } pj_end (pj); } @@ -699,15 +699,15 @@ R_API void r_x509_extensions_json(PJ *pj, RX509Extensions *exts) { } } -R_API void r_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle) { +RZ_API void rz_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle) { RASN1String *m = NULL; if (crle) { if (crle->userCertificate) { - m = r_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length); + m = rz_asn1_stringify_integer (crle->userCertificate->binary, crle->userCertificate->length); if (m) { pj_ks (pj, "UserCertificate", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } if (crle->revocationDate) { pj_ks (pj, "RevocationDate", crle->revocationDate->string); @@ -715,7 +715,7 @@ R_API void r_x509_crlentry_json(PJ *pj, RX509CRLEntry *crle) { } } -R_API void r_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl) { +RZ_API void rz_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl) { ut32 i; if (crl) { if (crl->signature.algorithm) { @@ -723,7 +723,7 @@ R_API void r_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl) { } pj_k (pj, "Issuer"); pj_o (pj); - r_x509_name_json (pj, &crl->issuer); + rz_x509_name_json (pj, &crl->issuer); pj_end (pj); if (crl->lastUpdate) { pj_ks (pj, "LastUpdate", crl->lastUpdate->string); @@ -734,13 +734,13 @@ R_API void r_x509_crl_json(PJ *pj, RX509CertificateRevocationList *crl) { pj_k (pj, "RevokedCertificates"); pj_a (pj); for (i = 0; i < crl->length; i++) { - r_x509_crlentry_json (pj, crl->revokedCertificates[i]); + rz_x509_crlentry_json (pj, crl->revokedCertificates[i]); } pj_end (pj); } } -R_API void r_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc) { +RZ_API void rz_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc) { pj_o (pj); RASN1String *m = NULL; if (tbsc) { @@ -753,56 +753,56 @@ R_API void r_x509_tbscertificate_json(PJ *pj, RX509TBSCertificate *tbsc) { } pj_k (pj, "Issuer"); pj_o (pj); - r_x509_name_json (pj, &tbsc->issuer); + rz_x509_name_json (pj, &tbsc->issuer); pj_end (pj); pj_k (pj, "Validity"); pj_o (pj); - r_x509_validity_json (pj, &tbsc->validity); + rz_x509_validity_json (pj, &tbsc->validity); pj_end (pj); pj_k (pj, "Subject"); pj_o (pj); - r_x509_name_json (pj, &tbsc->subject); + rz_x509_name_json (pj, &tbsc->subject); pj_end (pj); pj_k (pj, "SubjectPublicKeyInfo"); pj_o (pj); - r_x509_subjectpublickeyinfo_json (pj, &tbsc->subjectPublicKeyInfo); + rz_x509_subjectpublickeyinfo_json (pj, &tbsc->subjectPublicKeyInfo); pj_end (pj); if (tbsc->issuerUniqueID) { - m = r_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length); + m = rz_asn1_stringify_integer (tbsc->issuerUniqueID->binary, tbsc->issuerUniqueID->length); if (m) { pj_ks (pj, "IssuerUniqueID", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } if (tbsc->subjectUniqueID) { - m = r_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length); + m = rz_asn1_stringify_integer (tbsc->subjectUniqueID->binary, tbsc->subjectUniqueID->length); if (m) { pj_ks (pj, "SubjectUniqueID", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } pj_k (pj, "Extensions"); - r_x509_extensions_json (pj, &tbsc->extensions); + rz_x509_extensions_json (pj, &tbsc->extensions); } } -R_API void r_x509_certificate_json(PJ *pj, RX509Certificate *certificate) { +RZ_API void rz_x509_certificate_json(PJ *pj, RX509Certificate *certificate) { if (!certificate) { return; } RASN1String *m = NULL; pj_o (pj); pj_k (pj, "TBSCertificate"); - r_x509_tbscertificate_json (pj, &certificate->tbsCertificate); + rz_x509_tbscertificate_json (pj, &certificate->tbsCertificate); if (certificate->algorithmIdentifier.algorithm) { pj_ks (pj, "Algorithm", certificate->algorithmIdentifier.algorithm->string); } if (certificate->signature) { - m = r_asn1_stringify_integer (certificate->signature->binary, certificate->signature->length); + m = rz_asn1_stringify_integer (certificate->signature->binary, certificate->signature->length); if (m) { pj_ks (pj, "Signature", m->string); } - r_asn1_free_string (m); + rz_asn1_free_string (m); } pj_end (pj); } diff --git a/librz/util/x509.h b/librz/util/x509.h new file mode 100644 index 0000000000..86dca9bcae --- /dev/null +++ b/librz/util/x509.h @@ -0,0 +1,26 @@ +#ifndef R_X509_INTERNAL_H +#define R_X509_INTERNAL_H + +RZ_API bool rz_x509_parse_algorithmidentifier(RX509AlgorithmIdentifier *ai, RASN1Object * object); +RZ_API void rz_x509_free_algorithmidentifier(RX509AlgorithmIdentifier * ai); + +RZ_API bool rz_x509_parse_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki, RASN1Object *object); +RZ_API void rz_x509_free_subjectpublickeyinfo(RX509SubjectPublicKeyInfo * spki); + +RZ_API bool rz_x509_parse_name(RX509Name *name, RASN1Object * object); +RZ_API void rz_x509_free_name(RX509Name * name); + +RZ_API bool rz_x509_parse_extension(RX509Extension *ext, RASN1Object * object); +RZ_API void rz_x509_free_extension(RX509Extension * ex); + +RZ_API bool rz_x509_parse_extensions(RX509Extensions *ext, RASN1Object * object); +RZ_API void rz_x509_free_extensions(RX509Extensions* ex); + +RZ_API bool rz_x509_parse_tbscertificate(RX509TBSCertificate *tbsc, RASN1Object * object); +RZ_API void rz_x509_free_tbscertificate(RX509TBSCertificate * tbsc); + +RZ_API RX509CRLEntry *rz_x509_parse_crlentry(RASN1Object *object); +RZ_API void rz_x509_name_dump(RX509Name* name, const char* pad, RStrBuf *sb); + +#endif /* R_X509_INTERNAL_H */ + diff --git a/libr/util/zip.c b/librz/util/zip.c similarity index 94% rename from libr/util/zip.c rename to librz/util/zip.c index 27cb1b96ce..4ebb405f5c 100644 --- a/libr/util/zip.c +++ b/librz/util/zip.c @@ -1,6 +1,6 @@ /* radare - LGPL - Copyright 2014-2015 - pancake */ -#include +#include #include @@ -23,7 +23,7 @@ static const char *gzerr(int n) { return errors[n]; } -R_API ut8 *r_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen) { +RZ_API ut8 *rz_inflate(const ut8 *src, int srcLen, int *srcConsumed, int *dstLen) { int err = 0; int out_size = 0; ut8 *dst = NULL; diff --git a/man/esil.7 b/man/esil.7 index 0881ffa6a7..fc24fa6b99 100644 --- a/man/esil.7 +++ b/man/esil.7 @@ -33,4 +33,4 @@ divides the value of source1 by the value of source0 .IP "jmp eax -> eax,eip,=" .SH "SEE ALSO" -.BR radare2 (1) +.BR rizin (1) diff --git a/man/radare2.1 b/man/rizin.1 similarity index 80% rename from man/radare2.1 rename to man/rizin.1 index c568106ad1..e8add4313c 100644 --- a/man/radare2.1 +++ b/man/rizin.1 @@ -1,10 +1,10 @@ .Dd May 17, 2020 .Dt RADARE2 1 .Sh NAME -.Nm radare2 +.Nm rizin .Nd Advanced commandline hexadecimal editor, disassembler and debugger .Sh SYNOPSIS -.Nm radare2 +.Nm rizin .Op Fl a Ar arch .Op Fl b Ar bits .Op Fl B Ar baddr @@ -16,22 +16,22 @@ .Op Fl m Ar addr .Op Fl p Ar project .Op Fl P Ar patch -.Op Fl r Ar rarun2 -.Op Fl R Ar rr2rule +.Op Fl r Ar rz_run +.Op Fl R Ar rrz_testule .Op Fl s Ar addr .Op Fl 0AdDwntLquvVxX .Ar -|--|=|file .Sh DESCRIPTION -radare2 is a commandline hexadecimal editor. +rizin is a commandline hexadecimal editor. .Pp -"r2" is the alias program name for radare2. +"r2" is the alias program name for rizin. .Pp This manpage is not updated yet. Feel free to contribute. .Pp The options are: .Bl -tag -width Fl .It Fl Fl -Open radare2 on an empty file +Open rizin on an empty file .It Fl Equivalent of 'r2 malloc://512' .It Fl 0 @@ -75,7 +75,7 @@ Do not perform any analysis (r_bin). Just load the raw file .It Fl nn Only load the rbin structures (elf, mach0, ...) .It Fl N -Do not load user settings/projects from ~/.radare2rc, ~/.config/radare2/radare2rc and the scripts inside .../radare2rc.d/ directory. +Do not load user settings/projects from ~/.rizinrc, ~/.config/rizin/rizinrc and the scripts inside .../rizinrc.d/ directory. .It Fl NN Same as -N but also disables the automatic loading of plugins on startup time .It Fl q @@ -88,10 +88,10 @@ Same as q, but exiting without freeing RCore, this produces leaks at exit time, Set project file .It Fl P Ar file Apply rapatch file and quit (see doc/rapatch.md for more details) -.It Fl r Ar rarun2 -Specify dbg.profile rarun2 profile to use when spawning a program for debugging -.It Fl R Ar rarun2-directive -Specify custom rarun2 directives without having to create a rarun2 profile +.It Fl r Ar rz_run +Specify dbg.profile rz_run profile to use when spawning a program for debugging +.It Fl R Ar rz_run-directive +Specify custom rz_run directives without having to create a rz_run profile .It Fl s Ar addr Start seeking at this address .It Fl S @@ -105,7 +105,7 @@ Set bin.filter=false to load rbin info without filtering names .It Fl v Show version information and exit (Use -qv to get just the version number) .It Fl V -Show radare2 library versions +Show rizin library versions .It Fl w Open in write mode .It Fl h @@ -128,23 +128,23 @@ In r2 the debugger commands are implemented under the 'd' command. Type 'd?' for R2_CFG_NEWSHELL sets cfg.newshell=true R2_DEBUG if defined, show error messages and crash signal R2_DEBUG_ASSERT=1 set a breakpoint when hitting an assert - R2_MAGICPATH /Users/pancake/.local/share/radare2/share/radare2/4.5.0-git/magic + R2_MAGICPATH /Users/pancake/.local/share/rizin/share/rizin/4.5.0-git/magic R2_NOPLUGINS do not load r2 shared plugins - R2_RCFILE ~/.radare2rc (user preferences, batch script) + R2_RCFILE ~/.rizinrc (user preferences, batch script) R2_RDATAHOME /usr/local .Ar FILE path to the current working file. .Sh SEE ALSO .Pp -.Xr r2r(1) , -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , -.Xr rax2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , +.Xr rz_test(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , +.Xr rz_ax(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , .Sh AUTHORS .Pp pancake diff --git a/man/r2-docker.1 b/man/rz-docker.1 similarity index 64% rename from man/r2-docker.1 rename to man/rz-docker.1 index 90519f3cf9..8f149db772 100644 --- a/man/r2-docker.1 +++ b/man/rz-docker.1 @@ -1,10 +1,10 @@ .Dd Mar 10, 2017 .Dt R2-DOCKER 1 .Sh NAME -.Nm r2-docker +.Nm rz-docker .Nd Open files within an r2 contained in a Docker image .Sh SYNOPSIS -.Nm r2-docker +.Nm rz-docker .Op Fl s .Op Fl u .Op Fl l @@ -12,7 +12,7 @@ .Op Fl d .Ar file .Sh DESCRIPTION -radare2 is a commandline hexadecimal editor, and this tool allows you to create a contained version inside a Docker image to open your files safely. +rizin is a commandline hexadecimal editor, and this tool allows you to create a contained version inside a Docker image to open your files safely. .Pp The options are: .Bl -tag -width Fl @@ -23,12 +23,12 @@ debug program (only for linux-x86-32/64) .It Fl u update or create the docker image with r2 inside .It Fl l -List all docker images with radare2 +List all docker images with rizin .It Fl r -Remove the radare2 docker image +Remove the rizin docker image .Sh SEE ALSO .Pp -.Xr radare2(1) +.Xr rizin(1) .Sh AUTHORS .Pp pancake diff --git a/man/r2agent.1 b/man/rz_agent.1 similarity index 90% rename from man/r2agent.1 rename to man/rz_agent.1 index 1b4e4b930d..0c1417daaf 100644 --- a/man/r2agent.1 +++ b/man/rz_agent.1 @@ -2,9 +2,9 @@ .Dt R2AGENT 1 .Sh NAME .Nm R2AGENT -.Nd radare2 remoting manager TODO +.Nd rizin remoting manager TODO .Sh SYNOPSIS -.Nm r2agent +.Nm rz_agent .Op Fl adhs .Op Fl p Ar PORT .Sh DESCRIPTION @@ -32,4 +32,4 @@ Show version information TODO .Sh SEE ALSO .Pp -.Xr radare2(1) +.Xr rizin(1) diff --git a/man/rasm2.1 b/man/rz_asm.1 similarity index 87% rename from man/rasm2.1 rename to man/rz_asm.1 index 208d23806b..d8e23f37a8 100644 --- a/man/rasm2.1 +++ b/man/rz_asm.1 @@ -1,10 +1,10 @@ .Dd Oct 30, 2018 .Dt RASM2 1 .Sh NAME -.Nm rasm2 -.Nd radare2 assembler and disassembler tool +.Nm rz_asm +.Nd rizin assembler and disassembler tool .Sh SYNOPSIS -.Nm rasm2 +.Nm rz_asm .Op Fl ABdDeEfCLvwrqx .Op Fl a Ar arch .Op Fl b Ar bits @@ -34,7 +34,7 @@ Select specific CPU (depends on \-a arch) .It Fl C Output in C format .It Fl d -Disassemble hexpair bytes. rasm2 \-d 9090 +Disassemble hexpair bytes. rz_asm \-d 9090 .It Fl D Disassemble showing hexpair and opcode .It Fl e @@ -60,7 +60,7 @@ Offset of the opcode to assemble (default is 0) .It Fl @ Ar offset Alias for -o .It Fl O Ar ofile -output to file, for example 'rasm2 \-BF a a.asm' +output to file, for example 'rz_asm \-BF a a.asm' .It Fl r Show output in r2 script .It Fl s Ar syntax @@ -107,21 +107,21 @@ dentify the region fof aslerrger .Pp Assemble opcode: .Pp - $ rasm2 \-a x86 \-b 32 'mov eax, 33' + $ rz_asm \-a x86 \-b 32 'mov eax, 33' .Pp Disassemble opcode: .Pp - $ rasm2 \-d 90 + $ rz_asm \-d 90 .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rafind2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rax2(1) , +.Xr rizin(1) , +.Xr rz_find(1) , +.Xr rz_hash(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_ax(1) , .Sh AUTHORS .Pp pancake diff --git a/man/rax2.1 b/man/rz_ax.1 similarity index 62% rename from man/rax2.1 rename to man/rz_ax.1 index 1003a397be..8381fdf284 100644 --- a/man/rax2.1 +++ b/man/rz_ax.1 @@ -1,10 +1,10 @@ .Dd Jul 28, 2017 .Dt RAX2 1 .Sh NAME -.Nm rax2 +.Nm rz_ax .Nd radare base converter .Sh SYNOPSIS -.Nm rax2 +.Nm rz_ax .Op Fl ebBsSvxkKh .Op [expr] ... .Sh DESCRIPTION @@ -14,7 +14,7 @@ This command allows you to convert values between positive and negative integer, .Sh OPTIONS .Bl -tag -width Fl .It Fl b -Convert from binary string to character (rax2 \-b 01000101) +Convert from binary string to character (rz_ax \-b 01000101) .It Fl k Keep the same base as the input data .It Fl e @@ -26,9 +26,9 @@ Append newline to the decoded output for human friendly-ness .It Fl K Show randomart key asciiart for values or hexpairs .It Fl s -Convert from hex string to character (rax2 \-s 43 4a 50) +Convert from hex string to character (rz_ax \-s 43 4a 50) .It Fl S -Convert from character to hex string (rax2 \-S C J P) +Convert from character to hex string (rz_ax \-S C J P) .It Fl n Show hexpairs from integer value .It Fl N @@ -42,7 +42,7 @@ Convert a string into a hash .It Fl h Show usage help message .It Fl o -Convert from octal string to char (rax2 -o 162 62) +Convert from octal string to char (rz_ax -o 162 62) .El .Sh USAGE .Pp @@ -57,35 +57,35 @@ Force output mode (numeric base) .Pp Available variable types are: .Pp - int \-> hex rax2 10 - hex \-> int rax2 0xa - \-int \-> hex rax2 \-77 - \-hex \-> int rax2 0xffffffb3 - int \-> bin rax2 b30 - bin \-> int rax2 1010d - float \-> hex rax2 3.33f - hex \-> float rax2 Fx40551ed8 - oct \-> hex rax2 35o - hex \-> oct rax2 Ox12 (O is a letter) - bin \-> hex rax2 1100011b - hex \-> bin rax2 Bx63 + int \-> hex rz_ax 10 + hex \-> int rz_ax 0xa + \-int \-> hex rz_ax \-77 + \-hex \-> int rz_ax 0xffffffb3 + int \-> bin rz_ax b30 + bin \-> int rz_ax 1010d + float \-> hex rz_ax 3.33f + hex \-> float rz_ax Fx40551ed8 + oct \-> hex rz_ax 35o + hex \-> oct rz_ax Ox12 (O is a letter) + bin \-> hex rz_ax 1100011b + hex \-> bin rz_ax Bx63 .Pp -With no arguments, rax2 reads values from stdin. You can pass one or more values +With no arguments, rz_ax reads values from stdin. You can pass one or more values as arguments. .Pp - $ rax2 33 0x41 0101b + $ rz_ax 33 0x41 0101b 0x21 65 0x5 .Pp You can do 'unpack' hexpair encoded strings easily. .Pp - $ rax2 \-s 41 42 43 + $ rz_ax \-s 41 42 43 ABC .Pp And it supports some math operations. .Pp - $ rax2 + $ rz_ax 0x5*101b+5 30 .Pp @@ -93,14 +93,14 @@ It is a very useful tool for scripting, so you can read floating point values, o .Pp .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rasm2(1) +.Xr rizin(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_asm(1) .Sh AUTHORS .Pp Written by pancake . diff --git a/man/rabin2.1 b/man/rz_bin.1 similarity index 85% rename from man/rabin2.1 rename to man/rz_bin.1 index bb917c8299..e727545509 100644 --- a/man/rabin2.1 +++ b/man/rz_bin.1 @@ -4,7 +4,7 @@ .Nm RABIN2 .Nd Binary program info extractor .Sh SYNOPSIS -.Nm rabin2 +.Nm rz_bin .Op Fl AceghHiIsSMzlpRrLxvhqQTuUwV .Op Fl a Ar arch .Op Fl b Ar bits @@ -24,7 +24,7 @@ .Sh DESCRIPTION This program allows you to get information about ELF/PE/MZ and CLASS files in a simple way. .Pp -All those commandline flags are also available under the i command in radare2. Type i? for help. +All those commandline flags are also available under the i command in rizin. Type i? for help. .Bl -tag -width Fl .It Fl @ Ar addr Show information (symbol, section, import) of the given address @@ -71,7 +71,7 @@ Output in json .It Fl k Ar query Perform SDB query on loaded file .It Fl K Ar algo -Select a rahash2 checksum algorithm to be performed on sections listing (and maybe others in the future) i.e 'rabin2 -K md5 -S /bin/ls' +Select a rz_hash checksum algorithm to be performed on sections listing (and maybe others in the future) i.e 'rz_bin -K md5 -S /bin/ls' .It Fl l List linked libraries to the binary .It Fl L @@ -139,46 +139,46 @@ Dump raw strings to stdout (for huge files) .El .Sh ENVIRONMENT .Pp -RABIN2_LANG same as r2 -e bin.lang for rabin2 +RABIN2_LANG same as r2 -e bin.lang for rz_bin .Pp RABIN2_DEMANGLE demangle symbols .Pp -RABIN2_MAXSTRBUF same as r2 -e bin.maxstrbuf for rabin2 +RABIN2_MAXSTRBUF same as r2 -e bin.maxstrbuf for rz_bin .Pp RABIN2_DEBASE64 try to decode all strings as base64 if possible .Pp -RABIN2_STRFILTER same as r2 -e bin.str.filter for rabin2 +RABIN2_STRFILTER same as r2 -e bin.str.filter for rz_bin .Pp -RABIN2_STRPURGE same as r2 -e bin.str.purge for rabin2 +RABIN2_STRPURGE same as r2 -e bin.str.purge for rz_bin .Sh EXAMPLES .Pp List symbols of a program .Pp - $ rabin2 \-s a.out + $ rz_bin \-s a.out .Pp Get offset of symbol .Pp - $ rabin2 \-n _main a.out + $ rz_bin \-n _main a.out .Pp Get entrypoint .Pp - $ rabin2 \-e a.out + $ rz_bin \-e a.out .Pp -Load symbols and imports from radare2 +Load symbols and imports from rizin .Pp $ r2 -n /bin/ls - [0x00000000]> .!rabin2 \-prsi $FILE + [0x00000000]> .!rz_bin \-prsi $FILE .Sh SEE ALSO .Pp -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr radare2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , -.Xr rax2(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rizin(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , +.Xr rz_ax(1) , .Xr rsc2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , .Sh AUTHORS .Pp Written by pancake . diff --git a/man/radiff2.1 b/man/rz_diff.1 similarity index 91% rename from man/radiff2.1 rename to man/rz_diff.1 index c65c328adc..4d3757d095 100644 --- a/man/radiff2.1 +++ b/man/rz_diff.1 @@ -4,7 +4,7 @@ .Nm RADIFF2 .Nd unified binary diffing utility .Sh SYNOPSIS -.Nm radiff2 +.Nm rz_diff .Op Fl AabcCdDhOrspxXvzZ .Op Fl t Ar 0-100 .Op Fl g Ar sym @@ -12,7 +12,7 @@ .Ar file1 .Ar file2 .Sh DESCRIPTION -radiff2 implements many binary diffing algorithms for data and code. +rz_diff implements many binary diffing algorithms for data and code. .Pp .Bl -tag -width Fl .It Fl A @@ -76,14 +76,14 @@ Perform diff using zignatures instead of function list (NEW) .El .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rafind2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr rasm2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rax2(1) , +.Xr rizin(1) , +.Xr rz_find(1) , +.Xr rz_hash(1) , +.Xr rz_bin(1) , +.Xr rz_asm(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_ax(1) , .Sh AUTHORS .Pp pancake diff --git a/man/rafind2.1 b/man/rz_find.1 similarity index 87% rename from man/rafind2.1 rename to man/rz_find.1 index 3aa365d2a4..55ee2db0e0 100644 --- a/man/rafind2.1 +++ b/man/rz_find.1 @@ -1,10 +1,10 @@ .Dd Jun 24, 2020 .Dt RAFIND2 1 .Sh NAME -.Nm rafind2 +.Nm rz_find .Nd Advanced commandline hexadecimal editor .Sh SYNOPSIS -.Nm rafind2 +.Nm rz_find .Op Fl ijzZXnrhqv .Op Fl b Ar size .Op Fl f Ar from @@ -14,7 +14,7 @@ .Op Fl x Ar hex .Ar file|dir .Sh DESCRIPTION -rafind2 is a program to find byte patterns into files +rz_find is a program to find byte patterns into files .Pp The options are: .Bl -tag -width Fl @@ -63,14 +63,14 @@ Print version and exit .El .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rax2(1) , +.Xr rizin(1) , +.Xr rz_hash(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_ax(1) , .Sh AUTHORS .Pp pancake diff --git a/man/ragg2.1 b/man/rz_gg.1 similarity index 85% rename from man/ragg2.1 rename to man/rz_gg.1 index 067e2b106b..8551e869a1 100644 --- a/man/ragg2.1 +++ b/man/rz_gg.1 @@ -1,10 +1,10 @@ .Dd Sep 30, 2014 .Dt RAGG2 1 .Sh NAME -.Nm ragg2 -.Nd radare2 frontend for r_egg, compile programs into tiny binaries for x86-32/64 and arm. +.Nm rz_gg +.Nd rizin frontend for r_egg, compile programs into tiny binaries for x86-32/64 and arm. .Sh SYNOPSIS -.Nm ragg2 +.Nm rz_gg .Op Fl a Ar arch .Op Fl b Ar bits .Op Fl k Ar kernel @@ -26,16 +26,16 @@ .Op Fl q Ar fragment .Op Fl FOLsrxvhz .Sh DESCRIPTION -ragg2 is a frontend for r_egg, compile programs into tiny binaries for x86-32/64 and arm. +rz_gg is a frontend for r_egg, compile programs into tiny binaries for x86-32/64 and arm. .Pp This tool is experimental and it is a rewrite of the old rarc2 and rarc2-tool programs as a library and integrated with r_asm and r_bin. .Pp Programs generated by r_egg are relocatable and can be injected in a running process or on-disk binary file. .Pp -Since the ragg2-cc merge, ragg2 can now generate shellcodes from C code. The final code can be linked with rabin2 and it is relocatable, so it can be used to inject it on any remote process. This feature is conceptually based on shellforge4, but only linux/osx x86-32/64 platforms are supported. +Since the rz_gg-cc merge, rz_gg can now generate shellcodes from C code. The final code can be linked with rz_bin and it is relocatable, so it can be used to inject it on any remote process. This feature is conceptually based on shellforge4, but only linux/osx x86-32/64 platforms are supported. .Sh DIRECTIVES .Pp -The rr2 (ragg2) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'. +The rr2 (rz_gg) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'. .Bl -tag -width Fl .It Fl a Ar arch set architecture x86, arm @@ -110,7 +110,7 @@ show version write(1,.var0, 4); exit(0); } - $ ragg2 \-O \-F hi.r + $ rz_gg \-O \-F hi.r $ ./hi hi! .Pp @@ -120,7 +120,7 @@ show version write(1, "Hello\\n", 6); exit(0); } - $ ragg2 -O -F hi.c + $ rz_gg -O -F hi.c .Pp $ ./hi Hello @@ -130,24 +130,24 @@ show version 165 .Pp # The compiled shellcode has zeroes - $ ragg2 hi.c | tail -1 + $ rz_gg hi.c | tail -1 eb0748656c6c6f0a00bf01000000488d35edffffffba06000000b8010 000000f0531ffb83c0000000f0531c0c3 .Pp # Use a xor encoder with key 64 to bypass - $ ragg2 \-e xor \-c key=64 \-B $(ragg2 hi.c | tail -1) + $ rz_gg \-e xor \-c key=64 \-B $(rz_gg hi.c | tail -1) 6a2d596a405be8ffffffffc15e4883c60d301e48ffc6e2f9ab4708252 c2c2f4a40ff4140404008cd75adbfbfbffa46404040f8414040404f45 71bff87c4040404f45718083 .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr rabin2(1) , -.Xr rafind2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , +.Xr rizin(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rz_bin(1) , +.Xr rz_find(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , .Sh AUTHORS .Pp Written by pancake . diff --git a/man/rahash2.1 b/man/rz_hash.1 similarity index 94% rename from man/rahash2.1 rename to man/rz_hash.1 index 078c5f2b21..96f1eb55f9 100644 --- a/man/rahash2.1 +++ b/man/rz_hash.1 @@ -1,10 +1,10 @@ .Dd Feb 6, 2015 .Dt RAHASH2 1 .Sh NAME -.Nm rahash2 +.Nm rz_hash .Nd block based hashing utility .Sh SYNOPSIS -.Nm rahash2 +.Nm rz_hash .Op Fl BbdDehjrknvq .Op Fl a Ar algorithm .Op Fl b Ar size @@ -33,7 +33,7 @@ This command can be used to calculate hashes of a certain part of a file or a co This is the command used by the 'ph' command of radare. .Bl -tag -width Fl .It Fl a Ar algo -Select an algorithm for the hashing. Valid values are listed in: rahash2 -L +Select an algorithm for the hashing. Valid values are listed in: rz_hash -L .It Fl b Ar blocksize Define the block size .It Fl c Ar hash @@ -83,15 +83,15 @@ Show usage help message. When -c is used, exit status 0 indicates a match between the expected and computed hashes. .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rafind2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rax2(1) , +.Xr rizin(1) , +.Xr rz_find(1) , +.Xr rz_hash(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_ax(1) , .Sh AUTHORS .Pp pancake diff --git a/man/r2pm.1 b/man/rz_pm.1 similarity index 78% rename from man/r2pm.1 rename to man/rz_pm.1 index eb25d4074b..2e27dfbf3d 100644 --- a/man/r2pm.1 +++ b/man/rz_pm.1 @@ -2,16 +2,16 @@ .Dt R2PM 1 .Sh NAME .Nm R2PM -.Nd radare2 package manager +.Nd rizin package manager .Sh SYNOPSIS -.Nm r2pm +.Nm rz_pm .Op init|update|cmd .Op ... .Sh DESCRIPTION -Allows to install, update, uninstall and discover plugins and tools that can be used with radare2. +Allows to install, update, uninstall and discover plugins and tools that can be used with rizin. .Bl -tag -width Fl .It Fl a, Cm repo -Adds an external r2pm repository, no arguments to -a will list all the registered repos, use '-a - repo' to unregister/remove those repos. +Adds an external rz_pm repository, no arguments to -a will list all the registered repos, use '-a - repo' to unregister/remove those repos. .It Fl I, Cm info Show information about repository and installed packages .It Fl i, Cm install Ar pkgname @@ -43,24 +43,24 @@ Show when a package was installed or exit 1 if pkg does not exist .Pp Initialize and update the package database .Pp - $ r2pm init - $ r2pm update + $ rz_pm init + $ rz_pm update .Pp Install a package .Pp - $ r2pm install yara3 + $ rz_pm install yara3 .Pp Uninstall a package .Pp - $ r2pm uninstall yara3 + $ rz_pm uninstall yara3 .Pp Search a package .Pp - $ r2pm search yara + $ rz_pm search yara .Pp List available packages .Pp - $ r2pm -s + $ rz_pm -s .Sh SEE ALSO .Pp -.Xr radare2(1) +.Xr rizin(1) diff --git a/man/rarun2.1 b/man/rz_run.1 similarity index 86% rename from man/rarun2.1 rename to man/rz_run.1 index 2d91a0767b..67ae22e54f 100644 --- a/man/rarun2.1 +++ b/man/rz_run.1 @@ -1,24 +1,24 @@ .Dd Feb 3, 2017 .Dt RARUN2 1 .Sh NAME -.Nm rarun2 -.Nd radare2 utility to run programs in exotic environments +.Nm rz_run +.Nd rizin utility to run programs in exotic environments .Sh SYNOPSIS -.Nm rarun2 +.Nm rz_run .Op [directives] .Op [script.rr2] .Op [--] [program] [args] .Sh DESCRIPTION This program is used as a launcher for running programs with different environment, arguments, permissions, directories and overridden default filedescriptors. .Pp -rarun2 -t will show the terminal name and wait for a connection from another process. try rarun2 stdio= program=/bin/sh +rz_run -t will show the terminal name and wait for a connection from another process. try rz_run stdio= program=/bin/sh .Pp The program just accepts a single argument which is the filename of the configuration file to run the program. .Pp It is useful when you have to run a program using long arguments or pass long data to stdin or things like that usually required for exploiting crackmes :) .Sh DIRECTIVES .Pp -The rr2 (rarun2) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'. +The rr2 (rz_run) configuration file accepts the following directives, described as key=value entries and comments defined as lines starting with '#'. .Bl -tag -width Fl .It Ar arg[0-N] set value for argument N passed to the program @@ -69,7 +69,7 @@ path to the library to be executed .It Ar runlib.fcn function name to call from runlib library .It Ar r2preload -preload with libr2, kill -USR1 to get an r2 shell or -USR2 to spawn a webserver in a thread +preload with librz, kill -USR1 to get an r2 shell or -USR2 to spawn a webserver in a thread .It Ar r2preweb run the webserver in a thread just at starting the r2preload .It Ar setenv @@ -117,10 +117,10 @@ Parse hexpair string from output of command and store it in the variable Parses the input string and returns it as integer .El .Sh EXAMPLES -Sample rarun2 script +Sample rz_run script .Pp $ cat foo.rr2 - #!/usr/bin/rarun2 + #!/usr/bin/rz_run program=./pp400 arg0=10 stdin=foo.txt @@ -136,7 +136,7 @@ Sample rarun2 script Connecting a program to a socket .Pp $ nc \-l 9999 - $ rarun2 program=/bin/ls connect=localhost:9999 + $ rz_run program=/bin/ls connect=localhost:9999 .Pp Debugging a program redirecting io to another terminal .Pp @@ -146,27 +146,27 @@ Debugging a program redirecting io to another terminal ## in another terminal run r2 $ r2 \-r foo.rr2 -d ls $ cat foo.rr2 - #!/usr/bin/rarun2 + #!/usr/bin/rz_run stdio=/dev/ttys010 ## Or you can use -R to set a key=value r2 \-R stdio=/dev/ttys010 -d ls .Pp You can also use the -- flag to specify program and arguments in a more natural way: .Pp - $ rarun2 timeout=2 -- sleep 4 + $ rz_run timeout=2 -- sleep 4 .Pp Run a library function .Pp - $ rarun2 runlib=/lib/libc-2.25.so runlib.fcn=system arg1="ls /" + $ rz_run runlib=/lib/libc-2.25.so runlib.fcn=system arg1="ls /" .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr rabin2(1) , -.Xr radiff2(1) , -.Xr ragg2(1) , -.Xr rasm2(1) , +.Xr rizin(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rz_bin(1) , +.Xr rz_diff(1) , +.Xr rz_gg(1) , +.Xr rz_asm(1) , .Sh AUTHORS .Pp Written by pancake diff --git a/man/rasign2.1 b/man/rz_sign.1 similarity index 73% rename from man/rasign2.1 rename to man/rz_sign.1 index 6f6292e405..e5c1b167db 100644 --- a/man/rasign2.1 +++ b/man/rz_sign.1 @@ -2,15 +2,15 @@ .Dt RASIGN2 1 .Sh NAME .Nm RASIGN2 -.Nd radare2 zignature utility +.Nd rizin zignature utility .Sh SYNOPSIS -.Nm rasign2 +.Nm rz_sign .Op Fl afhjqrv .Op Fl s Ar space .Op Fl o Ar outfile .Ar file .Sh DESCRIPTION -radiff2 implements many binary diffing algorithms for data and code. +rz_diff implements many binary diffing algorithms for data and code. .Pp .Bl -tag -width Fl .It Fl a @@ -34,12 +34,12 @@ Show version information. .El .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rafind2(1) , -.Xr rahash2(1) , -.Xr rabin2(1) , -.Xr rasm2(1) , -.Xr ragg2(1) , -.Xr rarun2(1) , -.Xr rax2(1) , -.Xr radiff2(1) , +.Xr rizin(1) , +.Xr rz_find(1) , +.Xr rz_hash(1) , +.Xr rz_bin(1) , +.Xr rz_asm(1) , +.Xr rz_gg(1) , +.Xr rz_run(1) , +.Xr rz_ax(1) , +.Xr rz_diff(1) , diff --git a/man/r2r.1 b/man/rz_test.1 similarity index 61% rename from man/r2r.1 rename to man/rz_test.1 index 23ba44f34a..f233038d0d 100644 --- a/man/r2r.1 +++ b/man/rz_test.1 @@ -1,10 +1,10 @@ .Dd Mar 31, 2020 .Dt R2R 1 .Sh NAME -.Nm r2r -.Nd radare2 regression testsuite +.Nm rz_test +.Nd rizin regression testsuite .Sh SYNOPSIS -.Nm r2r +.Nm rz_test .Op Fl h .Op Fl n .Op Fl q @@ -12,16 +12,16 @@ .Op Fl V .Op Fl j Ar threads .Op Fl r Ar r2-path -.Op Fl m Ar rasm2-pth +.Op Fl m Ar rz_asm-pth .Op Fl f Ar bin-for-json-tests .Op Fl C Ar chdir .Op [test-(dir|file) ...] .Sh DESCRIPTION -Run all the radare2-regressions tests matching a specific word in the name. +Run all the rizin-regressions tests matching a specific word in the name. .Pp TODO: this manpage is work-in-progress .Pp -You need radare2 to be available in $PATH. +You need rizin to be available in $PATH. .Sh OPTIONS .Bl -tag -width Fl .It Fl h @@ -29,7 +29,7 @@ Show the help/usage message .It Fl n Do not run any test, just load/parse them .It Fl q -Quiet mode (use like this: r2r -qv) +Quiet mode (use like this: rz_test -qv) .It Fl v Show version number .It Fl V @@ -37,11 +37,11 @@ Be verbose .It Fl j Ar threads Specify the number of tasks to run in parallel .It Fl r Ar r2-path -Set path to radare2 executable -.It Fl n Ar rasm2-path -Set path to rasm2executable -.It Fl m Ar rasm2-path -Set path to rasm2executable +Set path to rizin executable +.It Fl n Ar rz_asm-path +Set path to rz_asmexecutable +.It Fl m Ar rz_asm-path +Set path to rz_asmexecutable .It Fl f Ar bin-for-json-tests Load the given binary when running the JSON tests .It Fl C Ar directory @@ -51,18 +51,18 @@ Early chdir before running any test .Pp Use the -n flag to dont run any test. Just load them. .Pp - $ r2r -n - [r2r] Loading tests... + $ rz_test -n + [rz_test] Loading tests... .Pp .Sh SEE ALSO .Pp -.Xr radare2(1) , -.Xr rahash2(1) , -.Xr rafind2(1) , -.Xr rabin2(1) , -.Xr rafind2(1) , -.Xr radiff2(1) , -.Xr rasm2(1) , +.Xr rizin(1) , +.Xr rz_hash(1) , +.Xr rz_find(1) , +.Xr rz_bin(1) , +.Xr rz_find(1) , +.Xr rz_diff(1) , +.Xr rz_asm(1) , .Sh AUTHORS .Pp Written by pancake . diff --git a/meson.build b/meson.build index b534b8ce22..6bede3b878 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('radare2', 'c', license: 'LGPL3', meson_version: '>=0.50.1') +project('rizin', 'c', license: 'LGPL3', meson_version: '>=0.50.1') py3_exe = import('python').find_installation('python3') git_exe = find_program('git', required: false) @@ -71,7 +71,7 @@ endif if get_option('r2_gittap') != '' gittap = get_option('r2_gittap') endif -# gittap is used for the version of each r_ library +# gittap is used for the version of each rz_ library # in case it has not been set (e.g. a release tarball) set it if gittap == '' gittap = r2_version @@ -110,7 +110,7 @@ else endif platform_deps = [] -platform_inc = ['.', 'libr/include'] +platform_inc = ['.', 'librz/include'] if host_machine.system() == 'windows' platform_deps = [cc.find_library('ws2_32'), cc.find_library('wininet'), cc.find_library('psapi')] endif @@ -140,7 +140,7 @@ library_cflags = ['-DR2_PLUGIN_INCORE=1'] if host_machine.system() == 'windows' r2_prefix = '.' r2_libdir = 'lib' - r2_incdir = join_paths('include', 'libr') + r2_incdir = join_paths('include', 'librz') r2_datdir = 'share' opts1 = [ @@ -196,43 +196,43 @@ if host_machine.system() == 'windows' else r2_prefix = get_option('prefix') r2_libdir = get_option('libdir') - r2_incdir = join_paths(get_option('includedir'), 'libr') + r2_incdir = join_paths(get_option('includedir'), 'librz') r2_datdir = get_option('datadir') - r2_datdir_r2 = join_paths(r2_datdir, 'radare2') - r2_wwwroot = join_paths(r2_datdir_r2, r2_version, 'www') - r2_sdb = join_paths(r2_datdir_r2, r2_version) - r2_zigns = join_paths(r2_datdir_r2, r2_version, 'zigns') - r2_themes = join_paths(r2_datdir_r2, r2_version, 'cons') - r2_fortunes = join_paths(r2_datdir, 'doc', 'radare2') - r2_flags = join_paths(r2_datdir_r2, r2_version, 'flag') - r2_hud = join_paths(r2_datdir_r2, r2_version, 'hud') - r2_plugins = join_paths(r2_libdir, 'radare2', r2_version) - r2_extras = join_paths(r2_libdir, 'radare2-extras', r2_version) - r2_bindings = join_paths(r2_libdir, 'radare2-bindings', r2_version) + r2_datdir_rz = join_paths(r2_datdir, 'rizin') + r2_wwwroot = join_paths(r2_datdir_rz, r2_version, 'www') + r2_sdb = join_paths(r2_datdir_rz, r2_version) + r2_zigns = join_paths(r2_datdir_rz, r2_version, 'zigns') + r2_themes = join_paths(r2_datdir_rz, r2_version, 'cons') + r2_fortunes = join_paths(r2_datdir, 'doc', 'rizin') + r2_flags = join_paths(r2_datdir_rz, r2_version, 'flag') + r2_hud = join_paths(r2_datdir_rz, r2_version, 'hud') + r2_plugins = join_paths(r2_libdir, 'rizin', r2_version) + r2_extras = join_paths(r2_libdir, 'rizin-extras', r2_version) + r2_bindings = join_paths(r2_libdir, 'rizin-bindings', r2_version) endif r2_zsh_compdir = join_paths(r2_datdir, 'zsh', 'site-functions') # load plugin configuration -subdir('libr') +subdir('librz') conf_data = configuration_data() -conf_data.set('plugins_core', '&r_core_plugin_' + ', &r_core_plugin_'.join(core_plugins) + ', 0') -conf_data.set('plugins_anal', '&r_anal_plugin_' + ', &r_anal_plugin_'.join(anal_plugins) + ', 0') -conf_data.set('plugins_asm', '&r_asm_plugin_' + ', &r_asm_plugin_'.join(asm_plugins) + ', 0') -conf_data.set('plugins_bp', '&r_bp_plugin_' + ', &r_bp_plugin_'.join(bp_plugins) + ', 0') -conf_data.set('plugins_bin', '&r_bin_plugin_' + ', &r_bin_plugin_'.join(bin_plugins) + ', 0') -conf_data.set('plugins_bin_ldr', '&r_bin_ldr_plugin_' + ', &r_bin_ldr_plugin_'.join(bin_ldr_plugins) + ', 0') -conf_data.set('plugins_bin_xtr', '&r_bin_xtr_plugin_' + ', &r_bin_xtr_plugin_'.join(bin_xtr_plugins) + ', 0') -conf_data.set('plugins_crypto', '&r_crypto_plugin_' + ', &r_crypto_plugin_'.join(crypto_plugins) + ', 0') -conf_data.set('plugins_io', '&r_io_plugin_' + ', &r_io_plugin_'.join(io_plugins) + ', 0') -conf_data.set('plugins_fs', '&r_fs_plugin_' + ', &r_fs_plugin_'.join(fs_plugins) + ', 0') -conf_data.set('plugins_debug', '&r_debug_plugin_' + ', &r_debug_plugin_'.join(debug_plugins) + ', 0') -conf_data.set('plugins_egg', '&r_egg_plugin_' + ', &r_egg_plugin_'.join(egg_plugins) + ', 0') -conf_data.set('plugins_lang', '&r_lang_plugin_' + ', &r_lang_plugin_'.join(lang_plugins) + ', 0') -conf_data.set('plugins_parse', '&r_parse_plugin_' + ', &r_parse_plugin_'.join(parse_plugins) + ', 0') +conf_data.set('plugins_core', '&rz_core_plugin_' + ', &rz_core_plugin_'.join(core_plugins) + ', 0') +conf_data.set('plugins_anal', '&rz_anal_plugin_' + ', &rz_anal_plugin_'.join(anal_plugins) + ', 0') +conf_data.set('plugins_asm', '&rz_asm_plugin_' + ', &rz_asm_plugin_'.join(asm_plugins) + ', 0') +conf_data.set('plugins_bp', '&rz_bp_plugin_' + ', &rz_bp_plugin_'.join(bp_plugins) + ', 0') +conf_data.set('plugins_bin', '&rz_bin_plugin_' + ', &rz_bin_plugin_'.join(bin_plugins) + ', 0') +conf_data.set('plugins_bin_ldr', '&rz_bin_ldr_plugin_' + ', &rz_bin_ldr_plugin_'.join(bin_ldr_plugins) + ', 0') +conf_data.set('plugins_bin_xtr', '&rz_bin_xtr_plugin_' + ', &rz_bin_xtr_plugin_'.join(bin_xtr_plugins) + ', 0') +conf_data.set('plugins_crypto', '&rz_crypto_plugin_' + ', &rz_crypto_plugin_'.join(crypto_plugins) + ', 0') +conf_data.set('plugins_io', '&rz_io_plugin_' + ', &rz_io_plugin_'.join(io_plugins) + ', 0') +conf_data.set('plugins_fs', '&rz_fs_plugin_' + ', &rz_fs_plugin_'.join(fs_plugins) + ', 0') +conf_data.set('plugins_debug', '&rz_debug_plugin_' + ', &rz_debug_plugin_'.join(debug_plugins) + ', 0') +conf_data.set('plugins_egg', '&rz_egg_plugin_' + ', &rz_egg_plugin_'.join(egg_plugins) + ', 0') +conf_data.set('plugins_lang', '&rz_lang_plugin_' + ', &rz_lang_plugin_'.join(lang_plugins) + ', 0') +conf_data.set('plugins_parse', '&rz_parse_plugin_' + ', &rz_parse_plugin_'.join(parse_plugins) + ', 0') config_h = configure_file( - input: 'libr/config.h.in', + input: 'librz/config.h.in', output: 'config.h', configuration: conf_data ) @@ -323,7 +323,7 @@ if host_machine.system() == 'windows' else userconf.set('LIBDIR', join_paths(r2_prefix, r2_libdir)) userconf.set('INCLUDEDIR', join_paths(r2_prefix, r2_incdir)) - userconf.set('DATADIR_R2', r2_datdir_r2) + userconf.set('DATADIR_R2', r2_datdir_rz) userconf.set10('HAVE_JEMALLOC', true) endif userconf.set('DATADIR', join_paths(r2_prefix, r2_datdir)) @@ -365,9 +365,9 @@ foreach item : [ userconf.set10('HAVE_@0@'.format(func.to_upper()), ok) endforeach -r_userconf_h = configure_file( - input: 'libr/include/r_userconf.h.acr', - output: 'r_userconf.h', +rz_userconf_h = configure_file( + input: 'librz/include/rz_userconf.h.acr', + output: 'rz_userconf.h', configuration: userconf, install_dir: join_paths(r2_incdir) ) @@ -383,9 +383,9 @@ versionconf.set('R2_VERSION', r2_version) versionconf.set('R2_GITTAP', gittap) versionconf.set('R2_GITTIP', gittip) versionconf.set('R2_BIRTH', r2birth) -r_version_h = configure_file( - input: 'libr/include/r_version.h.in', - output: 'r_version.h', +rz_version_h = configure_file( + input: 'librz/include/rz_version.h.in', + output: 'rz_version.h', configuration: versionconf, install_dir: join_paths(r2_incdir) ) @@ -398,8 +398,8 @@ pcconf.set('PREFIX', get_option('prefix')) pcconf.set('LIBDIR', join_paths(get_option('prefix'), get_option('libdir'))) pcconf.set('VERSION', r2_version) libr_pc = configure_file( - input: 'libr/libr.pc.acr', - output: 'libr.pc', + input: 'librz/librz.pc.acr', + output: 'librz.pc', configuration: pcconf, install_dir: join_paths(get_option('libdir'), 'pkgconfig') ) @@ -429,13 +429,13 @@ if not zlib_dep.found() or not get_option('use_sys_zlib') zlib_inc = [platform_inc, include_directories('shlr/zip/zlib')] - libr2zlib = static_library('r2zlib', zlib_files, + librzzlib = static_library('r2zlib', zlib_files, include_directories: zlib_inc, implicit_include_directories: false ) zlib_dep = declare_dependency( - link_with: libr2zlib, + link_with: librzzlib, include_directories: zlib_inc ) else @@ -503,14 +503,14 @@ sdb_inc_files = [ ] install_headers(sdb_inc_files, install_dir: join_paths(r2_incdir, 'sdb')) -libr2sdb = static_library('r2sdb', sdb_files, +librzsdb = static_library('r2sdb', sdb_files, include_directories: sdb_inc, implicit_include_directories: false, c_args: host_machine.system() == 'windows' ? '-DSDB_API=__declspec(dllexport)' : [], ) sdb_dep = declare_dependency( - link_whole: libr2sdb, + link_whole: librzsdb, include_directories: sdb_inc ) @@ -536,7 +536,7 @@ spp_files = [ spp_inc = [platform_inc, include_directories('shlr/spp')] -libr2spp = static_library('r2spp', spp_files, +librzspp = static_library('r2spp', spp_files, dependencies: sdb_dep, include_directories: spp_inc, c_args: ['-DHAVE_R_UTIL', '-DUSE_R2=1'], @@ -544,7 +544,7 @@ libr2spp = static_library('r2spp', spp_files, ) spp_dep = declare_dependency( - link_with: libr2spp, + link_with: librzspp, include_directories: spp_inc ) @@ -563,40 +563,40 @@ if get_option('local') and get_option('default_library') == 'shared' rpath_lib = '$ORIGIN' endif -subdir('libr/util') -subdir('libr/socket') -subdir('libr/hash') -subdir('libr/crypto') +subdir('librz/util') +subdir('librz/socket') +subdir('librz/hash') +subdir('librz/crypto') subdir('shlr') -subdir('libr/cons') +subdir('librz/cons') subdir('shlr/gdb') -subdir('libr/io') -subdir('libr/bp') -subdir('libr/syscall') -subdir('libr/search') -subdir('libr/magic') -subdir('libr/flag') -subdir('libr/reg') -subdir('libr/bin') -subdir('libr/config') -subdir('libr/parse') -subdir('libr/lang') -subdir('libr/asm') -subdir('libr/anal') -subdir('libr/egg') -subdir('libr/fs') -subdir('libr/debug') -subdir('libr/core') +subdir('librz/io') +subdir('librz/bp') +subdir('librz/syscall') +subdir('librz/search') +subdir('librz/magic') +subdir('librz/flag') +subdir('librz/reg') +subdir('librz/bin') +subdir('librz/config') +subdir('librz/parse') +subdir('librz/lang') +subdir('librz/asm') +subdir('librz/anal') +subdir('librz/egg') +subdir('librz/fs') +subdir('librz/debug') +subdir('librz/core') -subdir('libr/anal/d') -subdir('libr/asm/d') -subdir('libr/bin/d') -subdir('libr/syscall/d') -subdir('libr/cons/d') -subdir('libr/magic/d') -subdir('libr/flag/d') -subdir('libr/main') +subdir('librz/anal/d') +subdir('librz/asm/d') +subdir('librz/bin/d') +subdir('librz/syscall/d') +subdir('librz/cons/d') +subdir('librz/magic/d') +subdir('librz/flag/d') +subdir('librz/main') cli_option = get_option('cli') if cli_option.auto() @@ -606,52 +606,52 @@ else endif if cli_enabled if get_option('blob') - subdir('binr/blob') + subdir('binrz/blob') else - subdir('binr/rahash2') - subdir('binr/rarun2') - subdir('binr/rasm2') - subdir('binr/rabin2') - subdir('binr/radare2') - subdir('binr/ragg2') - subdir('binr/r2agent') - subdir('binr/radiff2') - subdir('binr/rafind2') - subdir('binr/rasign2') - subdir('binr/rax2') + subdir('binrz/rz-hash') + subdir('binrz/rz-run') + subdir('binrz/rz-asm') + subdir('binrz/rz-bin') + subdir('binrz/rizin') + subdir('binrz/rz-gg') + subdir('binrz/rz-agent') + subdir('binrz/rz-diff') + subdir('binrz/rz-find') + subdir('binrz/rz-sign') + subdir('binrz/rz-ax') endif - subdir('binr/r2pm') - subdir('binr/r2r') + subdir('binrz/rz-pm') + subdir('binrz/rz-test') endif if meson.is_subproject() - libr2_dep = declare_dependency( + librz_dep = declare_dependency( dependencies: [ - r_anal_dep, - r_asm_dep, - r_bin_dep, - r_bp_dep, - r_config_dep, - r_cons_dep, - r_core_dep, - r_main_dep, - r_crypto_dep, - r_debug_dep, - r_egg_dep, - r_flag_dep, - r_fs_dep, - r_hash_dep, - r_io_dep, - r_lang_dep, - r_magic_dep, - r_parse_dep, - r_reg_dep, - r_search_dep, - r_socket_dep, - r_syscall_dep, - r_util_dep + rz_anal_dep, + rz_asm_dep, + rz_bin_dep, + rz_bp_dep, + rz_config_dep, + rz_cons_dep, + rz_core_dep, + rz_main_dep, + rz_crypto_dep, + rz_debug_dep, + rz_egg_dep, + rz_flag_dep, + rz_fs_dep, + rz_hash_dep, + rz_io_dep, + rz_lang_dep, + rz_magic_dep, + rz_parse_dep, + rz_reg_dep, + rz_search_dep, + rz_socket_dep, + rz_syscall_dep, + rz_util_dep ], - include_directories: include_directories('.', 'libr/include'), + include_directories: include_directories('.', 'librz/include'), version: r2_version ) endif @@ -675,18 +675,18 @@ install_data( if cli_enabled install_man( - 'man/r2agent.1', - 'man/r2-docker.1', - 'man/r2pm.1', - 'man/rabin2.1', - 'man/radare2.1', - 'man/radiff2.1', - 'man/rafind2.1', - 'man/ragg2.1', - 'man/rahash2.1', - 'man/rarun2.1', - 'man/rasm2.1', - 'man/rax2.1', + 'man/rz_agent.1', + 'man/rz-docker.1', + 'man/rz_pm.1', + 'man/rz_bin.1', + 'man/rizin.1', + 'man/rz_diff.1', + 'man/rz_find.1', + 'man/rz_gg.1', + 'man/rz_hash.1', + 'man/rz_run.1', + 'man/rz_asm.1', + 'man/rz_ax.1', 'man/esil.7' ) @@ -696,16 +696,16 @@ if cli_enabled ) install_data( - 'doc/zsh/_r2', - 'doc/zsh/_rabin2', - 'doc/zsh/_radiff2', - 'doc/zsh/_rafind2', - 'doc/zsh/_ragg2', - 'doc/zsh/_rahash2', - 'doc/zsh/_rasm2', - 'doc/zsh/_rax2', + 'doc/zsh/_rz', + 'doc/zsh/_rz_bin', + 'doc/zsh/_rz_diff', + 'doc/zsh/_rz_find', + 'doc/zsh/_rz_gg', + 'doc/zsh/_rz_hash', + 'doc/zsh/_rz_asm', + 'doc/zsh/_rz_ax', install_dir: r2_zsh_compdir ) - meson.add_install_script(host_machine.system() == 'windows' ? 'sys/create_r2.bat' : 'sys/create_r2.sh') + meson.add_install_script(host_machine.system() == 'windows' ? 'sys/create_rz.bat' : 'sys/create_rz.sh') endif diff --git a/meson_options.txt b/meson_options.txt index 46546259be..8dc4ea4fec 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -33,9 +33,9 @@ option('use_sys_tree_sitter', type: 'boolean', value: false) option('use_libuv', type: 'boolean', value: true) option('debugger', type: 'boolean', value: true) -option('use_webui', type: 'boolean', value: false, description: 'install different WebUIs for radare2') +option('use_webui', type: 'boolean', value: false, description: 'install different WebUIs for rizin') option('enable_tests', type: 'boolean', value: true, description: 'Build unit tests in test/unit') -option('enable_r2r', type: 'boolean', value: true, description: 'Build r2r executable for regression testing') +option('enable_rz_test', type: 'boolean', value: true, description: 'Build rz_test executable for regression testing') option('tree-sitter-sync', type: 'boolean', value: false, description: 'Force a sync of shlr/tree-sitter before building') diff --git a/mk/graph-int-per-line.pl b/mk/graph-int-per-line.pl index b99a3da555..2a9339299b 100644 --- a/mk/graph-int-per-line.pl +++ b/mk/graph-int-per-line.pl @@ -49,7 +49,7 @@ print "$sys\n"; get_graph("r2cdg.jpg", "r2 commit locdiff graph", 0); get_graph("r2clg.jpg", "r2 commit lines of code graph", 1); -system("scp r2cdg.jpg radare.org:/srv/http/radareorg/get"); -system("scp r2clg.jpg radare.org:/srv/http/radareorg/get"); +system("scp r2cdg.jpg radare.org:/srv/http/rizinorg/get"); +system("scp r2clg.jpg radare.org:/srv/http/rizinorg/get"); print ("http://radare.org/get/r2cdg.jpg\n"); print ("http://radare.org/get/r2clg.jpg\n"); diff --git a/mk/rapi-list b/mk/rapi-list index f5811bd8c9..ccea36c129 100755 --- a/mk/rapi-list +++ b/mk/rapi-list @@ -5,7 +5,7 @@ if [ -z "$1" ]; then fi MOD=$1 -cat libr/include/${MOD}.h | \ +cat librz/include/${MOD}.h | \ grep ^R_API | \ sed -e 's,const ,,g' | \ sed -e 's,struct ,,g' | \ diff --git a/mk/stat.mk b/mk/stat.mk index f8c059a695..69f6a193ac 100644 --- a/mk/stat.mk +++ b/mk/stat.mk @@ -1,6 +1,6 @@ stat-todo: @printf "XXX\tTODO\tName\n" - @for a in libr/* ; do \ + @for a in librz/* ; do \ if [ -d "$$a" ]; then \ xxx=`grep -e XXX $$a/*.c $$a/p/*.c $$a/t/*.c 2>/dev/null | wc -l` ; \ todo=`grep -e TODO $$a/*.c $$a/p/*.c $$a/t/*.c 2>/dev/null | wc -l` ; \ diff --git a/package.json b/package.json index 6165b7d045..2d977808fa 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,28 @@ { "author": "pancake", "bin": { - "radare2": "binr/radare2/radare2" + "rizin": "binrz/rizin/rizin" }, "scripts": { "test": "make run tests", "build": "sys/install.sh" }, - "description": "radare2 from git", + "description": "rizin from git", "homepage": "https://www.radare.org", "repository": { "type": "git", - "url": "git+https://github.com/radareorg/radare2.git" + "url": "git+https://github.com/rizinorg/rizin.git" }, "keywords": [ - "radare2" + "rizin" ], - "main": "binr/radare2/radare2", + "main": "binrz/rizin/rizin", "maintainers": [ "pancake " ], - "name": "radare2-git", + "name": "rizin-git", "version": "1.6.0-git", "bugs": { - "url": "https://github.com/radareorg/radare2/issues" + "url": "https://github.com/rizinorg/rizin/issues" } } diff --git a/pkgcfg/r_core.pc.acr b/pkgcfg/r_core.pc.acr deleted file mode 100644 index 5d4f4c68e3..0000000000 --- a/pkgcfg/r_core.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_core -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_config r_cons r_io r_util r_flag r_asm r_debug r_hash r_bin r_lang r_io r_anal r_parse r_bp r_egg r_reg r_search r_syscall r_socket r_fs r_magic r_crypto -Libs: -L${libdir} -lr_core @SSL_LDFLAGS@ @CAPSTONE_LDFLAGS@ -Cflags: -I${includedir}/libr @SSL_CFLAGS@ @CAPSTONE_CFLAGS@ diff --git a/pkgcfg/r_crypto.pc.acr b/pkgcfg/r_crypto.pc.acr deleted file mode 100644 index d3d7d36b52..0000000000 --- a/pkgcfg/r_crypto.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_crypto -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_hash r_util r_util r_util -Libs: -L${libdir} -lr_crypto -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_debug.pc.acr b/pkgcfg/r_debug.pc.acr deleted file mode 100644 index f949798a9a..0000000000 --- a/pkgcfg/r_debug.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_debug -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_reg r_anal r_bp r_io r_parse r_cons r_syscall r_hash r_flag r_util r_egg r_socket -Libs: -L${libdir} -lr_debug -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_egg.pc.acr b/pkgcfg/r_egg.pc.acr deleted file mode 100644 index a0e5813554..0000000000 --- a/pkgcfg/r_egg.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_egg -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_asm r_syscall r_util r_parse r_reg r_flag r_cons -Libs: -L${libdir} -lr_egg -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_fs.pc.acr b/pkgcfg/r_fs.pc.acr deleted file mode 100644 index d13579c521..0000000000 --- a/pkgcfg/r_fs.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_fs -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util r_io -Libs: -L${libdir} -lr_fs -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_hash.pc.acr b/pkgcfg/r_hash.pc.acr deleted file mode 100644 index 271516f9fa..0000000000 --- a/pkgcfg/r_hash.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_hash -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_hash @LIBXXHASH@ -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_io.pc.acr b/pkgcfg/r_io.pc.acr deleted file mode 100644 index bd3a3dfdc8..0000000000 --- a/pkgcfg/r_io.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_io -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util r_socket r_hash r_cons r_crypto -Libs: -L${libdir} -lr_io -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_lang.pc.acr b/pkgcfg/r_lang.pc.acr deleted file mode 100644 index 04b7aaffa3..0000000000 --- a/pkgcfg/r_lang.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_lang -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util r_cons -Libs: -L${libdir} -lr_lang -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_magic.pc.acr b/pkgcfg/r_magic.pc.acr deleted file mode 100644 index e16925f251..0000000000 --- a/pkgcfg/r_magic.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_magic -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_magic @LIBMAGIC@ -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_parse.pc.acr b/pkgcfg/r_parse.pc.acr deleted file mode 100644 index 93dd3e3804..0000000000 --- a/pkgcfg/r_parse.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_parse -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_flag r_util r_syscall r_reg r_cons -Libs: -L${libdir} -lr_parse -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_reg.pc.acr b/pkgcfg/r_reg.pc.acr deleted file mode 100644 index a5923e55ea..0000000000 --- a/pkgcfg/r_reg.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_reg -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_reg -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_search.pc.acr b/pkgcfg/r_search.pc.acr deleted file mode 100644 index db06aa5afa..0000000000 --- a/pkgcfg/r_search.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_search -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_search -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_socket.pc.acr b/pkgcfg/r_socket.pc.acr deleted file mode 100644 index 3d1babab3b..0000000000 --- a/pkgcfg/r_socket.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_socket -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_socket -Cflags: -I${includedir}/libr diff --git a/pkgcfg/r_syscall.pc.acr b/pkgcfg/r_syscall.pc.acr deleted file mode 100644 index cd0f11165d..0000000000 --- a/pkgcfg/r_syscall.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_syscall -Description: radare foundation libraries -Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_syscall -Cflags: -I${includedir}/libr diff --git a/pkgcfg/rz_anal.pc.acr b/pkgcfg/rz_anal.pc.acr new file mode 100644 index 0000000000..33f496052f --- /dev/null +++ b/pkgcfg/rz_anal.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_anal +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util rz_reg rz_syscall rz_search rz_cons rz_flag rz_crypto +Libs: -L${libdir} -lrz_anal +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_asm.pc.acr b/pkgcfg/rz_asm.pc.acr similarity index 50% rename from pkgcfg/r_asm.pc.acr rename to pkgcfg/rz_asm.pc.acr index 3af88b7ee7..453d8076fc 100644 --- a/pkgcfg/r_asm.pc.acr +++ b/pkgcfg/rz_asm.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_asm +Name: rz_asm Description: radare foundation libraries Version: @VERSION@ -Requires: r_syscall r_lang r_util r_parse r_flag r_cons r_reg -Libs: -L${libdir} -lr_asm -Cflags: -I${includedir}/libr +Requires: rz_syscall rz_lang rz_util rz_parse rz_flag rz_cons rz_reg +Libs: -L${libdir} -lrz_asm +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_bin.pc.acr b/pkgcfg/rz_bin.pc.acr similarity index 55% rename from pkgcfg/r_bin.pc.acr rename to pkgcfg/rz_bin.pc.acr index 9a7c5d0453..a8e2024838 100644 --- a/pkgcfg/r_bin.pc.acr +++ b/pkgcfg/rz_bin.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_bin +Name: rz_bin Description: radare foundation libraries Version: @VERSION@ -Requires: r_util r_io r_socket r_magic -Libs: -L${libdir} -lr_bin -Cflags: -I${includedir}/libr +Requires: rz_util rz_io rz_socket rz_magic +Libs: -L${libdir} -lrz_bin +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_bp.pc.acr b/pkgcfg/rz_bp.pc.acr similarity index 61% rename from pkgcfg/r_bp.pc.acr rename to pkgcfg/rz_bp.pc.acr index 0bfd0c7dd8..cec5598a7c 100644 --- a/pkgcfg/r_bp.pc.acr +++ b/pkgcfg/rz_bp.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_bp +Name: rz_bp Description: radare foundation libraries Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_bp -Cflags: -I${includedir}/libr +Requires: rz_util +Libs: -L${libdir} -lrz_bp +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_config.pc.acr b/pkgcfg/rz_config.pc.acr new file mode 100644 index 0000000000..a56ef3517c --- /dev/null +++ b/pkgcfg/rz_config.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_config +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_config +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_config.pc.acr b/pkgcfg/rz_cons.pc.acr similarity index 60% rename from pkgcfg/r_config.pc.acr rename to pkgcfg/rz_cons.pc.acr index a7b756e7be..c6dd92e576 100644 --- a/pkgcfg/r_config.pc.acr +++ b/pkgcfg/rz_cons.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_config +Name: rz_cons Description: radare foundation libraries Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_config -Cflags: -I${includedir}/libr +Requires: rz_util +Libs: -L${libdir} -lrz_cons +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_core.pc.acr b/pkgcfg/rz_core.pc.acr new file mode 100644 index 0000000000..a5176a625d --- /dev/null +++ b/pkgcfg/rz_core.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_core +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto +Libs: -L${libdir} -lrz_core @SSL_LDFLAGS@ @CAPSTONE_LDFLAGS@ +Cflags: -I${includedir}/librz @SSL_CFLAGS@ @CAPSTONE_CFLAGS@ diff --git a/pkgcfg/rz_crypto.pc.acr b/pkgcfg/rz_crypto.pc.acr new file mode 100644 index 0000000000..c7a22d8fb4 --- /dev/null +++ b/pkgcfg/rz_crypto.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_crypto +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_hash rz_util rz_util rz_util +Libs: -L${libdir} -lrz_crypto +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_debug.pc.acr b/pkgcfg/rz_debug.pc.acr new file mode 100644 index 0000000000..bd81af6cf0 --- /dev/null +++ b/pkgcfg/rz_debug.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_debug +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_reg rz_anal rz_bp rz_io rz_parse rz_cons rz_syscall rz_hash rz_flag rz_util rz_egg rz_socket +Libs: -L${libdir} -lrz_debug +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_anal.pc.acr b/pkgcfg/rz_egg.pc.acr similarity index 50% rename from pkgcfg/r_anal.pc.acr rename to pkgcfg/rz_egg.pc.acr index 433373099a..d2c6ad460f 100644 --- a/pkgcfg/r_anal.pc.acr +++ b/pkgcfg/rz_egg.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_anal +Name: rz_egg Description: radare foundation libraries Version: @VERSION@ -Requires: r_util r_reg r_syscall r_search r_cons r_flag r_crypto -Libs: -L${libdir} -lr_anal -Cflags: -I${includedir}/libr +Requires: rz_asm rz_syscall rz_util rz_parse rz_reg rz_flag rz_cons +Libs: -L${libdir} -lrz_egg +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_cons.pc.acr b/pkgcfg/rz_flag.pc.acr similarity index 60% rename from pkgcfg/r_cons.pc.acr rename to pkgcfg/rz_flag.pc.acr index 363c1410fa..938822e83f 100644 --- a/pkgcfg/r_cons.pc.acr +++ b/pkgcfg/rz_flag.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_cons +Name: rz_flag Description: radare foundation libraries Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_cons -Cflags: -I${includedir}/libr +Requires: rz_util +Libs: -L${libdir} -lrz_flag +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_fs.pc.acr b/pkgcfg/rz_fs.pc.acr new file mode 100644 index 0000000000..19de9c350a --- /dev/null +++ b/pkgcfg/rz_fs.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_fs +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util rz_io +Libs: -L${libdir} -lrz_fs +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_hash.pc.acr b/pkgcfg/rz_hash.pc.acr new file mode 100644 index 0000000000..4fd2fca382 --- /dev/null +++ b/pkgcfg/rz_hash.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_hash +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_hash @LIBXXHASH@ +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_io.pc.acr b/pkgcfg/rz_io.pc.acr new file mode 100644 index 0000000000..55eece23c0 --- /dev/null +++ b/pkgcfg/rz_io.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_io +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util rz_socket rz_hash rz_cons rz_crypto +Libs: -L${libdir} -lrz_io +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_lang.pc.acr b/pkgcfg/rz_lang.pc.acr new file mode 100644 index 0000000000..91cc381e20 --- /dev/null +++ b/pkgcfg/rz_lang.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_lang +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util rz_cons +Libs: -L${libdir} -lrz_lang +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_magic.pc.acr b/pkgcfg/rz_magic.pc.acr new file mode 100644 index 0000000000..43a664a93c --- /dev/null +++ b/pkgcfg/rz_magic.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_magic +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_magic @LIBMAGIC@ +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_parse.pc.acr b/pkgcfg/rz_parse.pc.acr new file mode 100644 index 0000000000..fcdfeb46e9 --- /dev/null +++ b/pkgcfg/rz_parse.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_parse +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_flag rz_util rz_syscall rz_reg rz_cons +Libs: -L${libdir} -lrz_parse +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_flag.pc.acr b/pkgcfg/rz_reg.pc.acr similarity index 61% rename from pkgcfg/r_flag.pc.acr rename to pkgcfg/rz_reg.pc.acr index a22cbbd923..07d39e2119 100644 --- a/pkgcfg/r_flag.pc.acr +++ b/pkgcfg/rz_reg.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_flag +Name: rz_reg Description: radare foundation libraries Version: @VERSION@ -Requires: r_util -Libs: -L${libdir} -lr_flag -Cflags: -I${includedir}/libr +Requires: rz_util +Libs: -L${libdir} -lrz_reg +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_search.pc.acr b/pkgcfg/rz_search.pc.acr new file mode 100644 index 0000000000..070465efc3 --- /dev/null +++ b/pkgcfg/rz_search.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_search +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_search +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_socket.pc.acr b/pkgcfg/rz_socket.pc.acr new file mode 100644 index 0000000000..1479df254a --- /dev/null +++ b/pkgcfg/rz_socket.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_socket +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_socket +Cflags: -I${includedir}/librz diff --git a/pkgcfg/rz_syscall.pc.acr b/pkgcfg/rz_syscall.pc.acr new file mode 100644 index 0000000000..b880e73ff1 --- /dev/null +++ b/pkgcfg/rz_syscall.pc.acr @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=${prefix} +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: rz_syscall +Description: radare foundation libraries +Version: @VERSION@ +Requires: rz_util +Libs: -L${libdir} -lrz_syscall +Cflags: -I${includedir}/librz diff --git a/pkgcfg/r_util.pc.acr b/pkgcfg/rz_util.pc.acr similarity index 56% rename from pkgcfg/r_util.pc.acr rename to pkgcfg/rz_util.pc.acr index 387d4677ee..a23d9f3c6f 100644 --- a/pkgcfg/r_util.pc.acr +++ b/pkgcfg/rz_util.pc.acr @@ -3,9 +3,9 @@ exec_prefix=${prefix} libdir=@LIBDIR@ includedir=${prefix}/include -Name: r_util +Name: rz_util Description: radare foundation libraries Version: @VERSION@ Requires: -Libs: -L${libdir} -lr_util @LIBZIP@ @DL_LIBS@ -Cflags: -I${includedir}/libr -I${includedir}/libr/sdb +Libs: -L${libdir} -lrz_util @LIBZIP@ @DL_LIBS@ +Cflags: -I${includedir}/librz -I${includedir}/librz/sdb diff --git a/plugins.android.cfg b/plugins.android.cfg index 7b9b298041..35b3eea9be 100644 --- a/plugins.android.cfg +++ b/plugins.android.cfg @@ -80,9 +80,9 @@ io.sparse io.ihex io.ptrace io.procpid -io.r2k -io.r2web -io.r2pipe +io.rzk +io.rzweb +io.rzpipe io.zip lang.vala parse.att2intel diff --git a/plugins.def.cfg b/plugins.def.cfg index 04f36e9e15..ca15900038 100644 --- a/plugins.def.cfg +++ b/plugins.def.cfg @@ -213,7 +213,7 @@ debug.null egg.exec egg.xor fs.io -fs.r2 +fs.rz fs.ext2 fs.fat fs.fb @@ -238,11 +238,11 @@ io.default io.gprobe io.gdb io.qnx -io.r2pipe +io.rzpipe io.gzip io.http io.tcp -io.r2web +io.rzweb io.ihex io.mach io.malloc @@ -258,7 +258,7 @@ io.w32dbg io.winkd io.winedbg io.zip -io.r2k +io.rzk io.ar io.fd io.rbuf diff --git a/plugins.ios-store.cfg b/plugins.ios-store.cfg index 696230c829..abce4658ec 100644 --- a/plugins.ios-store.cfg +++ b/plugins.ios-store.cfg @@ -54,15 +54,15 @@ debug.bf egg.exec egg.xor fs.io -fs.r2 +fs.rz fs.posix io.rap io.gzip io.http io.bfdbg io.mmap -io.r2pipe -io.r2web +io.rzpipe +io.rzweb io.default io.self io.malloc diff --git a/plugins.ios.cfg b/plugins.ios.cfg index b827e7a89e..9122739906 100644 --- a/plugins.ios.cfg +++ b/plugins.ios.cfg @@ -85,8 +85,8 @@ io.sparse io.ihex io.ptrace io.procpid -io.r2web -io.r2pipe +io.rzweb +io.rzpipe io.zip lang.vala parse.att2intel diff --git a/plugins.static.cfg b/plugins.static.cfg index 2c13e5a3a3..81810333c1 100644 --- a/plugins.static.cfg +++ b/plugins.static.cfg @@ -168,7 +168,7 @@ debug.null egg.exec egg.xor fs.io -fs.r2 +fs.rz fs.ext2 fs.fat fs.fb @@ -192,11 +192,11 @@ io.debug io.default io.gdb io.qnx -io.r2pipe +io.rzpipe io.gzip io.http io.tcp -io.r2web +io.rzweb io.ihex io.mach io.malloc @@ -211,7 +211,7 @@ io.w32 io.w32dbg io.winkd io.zip -io.r2k +io.rzk io.ar io.rbuf lang.vala diff --git a/plugins.static.nogpl.cfg b/plugins.static.nogpl.cfg index 43da199f90..a3f75129f9 100644 --- a/plugins.static.nogpl.cfg +++ b/plugins.static.nogpl.cfg @@ -165,7 +165,7 @@ debug.null egg.exec egg.xor fs.io -fs.r2 +fs.rz fs.posix io.null io.bfdbg @@ -174,11 +174,11 @@ io.debug io.default io.gdb io.qnx -io.r2pipe +io.rzpipe io.gzip io.http io.tcp -io.r2web +io.rzweb io.ihex io.mach io.malloc @@ -193,7 +193,7 @@ io.w32 io.w32dbg io.winkd io.zip -io.r2k +io.rzk io.ar io.rbuf lang.vala diff --git a/radare2.spec b/rizin.spec similarity index 94% rename from radare2.spec rename to rizin.spec index c9de1f3a2c..8568422f46 100644 --- a/radare2.spec +++ b/rizin.spec @@ -1,10 +1,10 @@ %global gituser radare -%global gitname radare2 +%global gitname rizin #global commit a093958b6d24015d82782eb20a2e10d8f4afcd85 %global commit 5a3dab0a86e1452c0bb0c13d869f95b41f50b9a9 %global shortcommit %(c=%{commit}; echo ${c:0:7}) -Name: radare2 +Name: rizin Version: 0.10.0 Release: 1%{?dist} Summary: The %{name} reverse engineering framework @@ -68,7 +68,7 @@ cp shlr/sdb/src/libsdb.a %{buildroot}/%{_libdir}/libsdb.a %doc AUTHORS.md CONTRIBUTING.md DEVELOPERS.md README.md TODO.md %license COPYING %{_bindir}/r* -%{_libdir}/libr* +%{_libdir}/librz* %dir %{_libdir}/%{name} %dir %{_libdir}/%{name}/%{version}-git %{_libdir}/%{name}/last @@ -90,14 +90,14 @@ cp shlr/sdb/src/libsdb.a %{buildroot}/%{_libdir}/libsdb.a %{_datadir}/%{name}/%{version}-git/cons/* %dir %{_datadir}/%{name}/%{version}-git/format %{_datadir}/%{name}/%{version}-git/format/* -%dir %{_prefix}/%{name}/%{version}-git/r2pm -%{_prefix}/%{name}/%{version}-git/r2pm/* +%dir %{_prefix}/%{name}/%{version}-git/rz-pm +%{_prefix}/%{name}/%{version}-git/rz-pm/* %dir %{_datadir}/%{name}/%{version}-git/www %{_datadir}/%{name}/%{version}-git/www/* %files devel -%{_includedir}/libr +%{_includedir}/librz %{_libdir}/libsdb.a %{_libdir}/pkgconfig/*.pc diff --git a/shlr/Makefile b/shlr/Makefile index c267762b55..808499ea2a 100644 --- a/shlr/Makefile +++ b/shlr/Makefile @@ -1,7 +1,7 @@ include ../config-user.mk include ../global.mk # for EXT_EXE -include ../libr/config.mk +include ../librz/config.mk include ../mk/platform.mk _INCLUDE_MK_GCC_= include ../mk/${COMPILER}.mk @@ -79,7 +79,7 @@ endif ifeq (1,$(USE_PTRACE_WRAP)) MODS+=ptrace-wrap endif -SDB_URL=git://github.com/radareorg/sdb +SDB_URL=git://github.com/rizinorg/sdb #SDB_URL=/Users/pancake/prg/sdb SPP_URL=git://github.com/radare/spp PTRACE_WRAP_URL=git://github.com/thestr4ng3r/ptrace-wrap @@ -94,7 +94,7 @@ all: exit 1 endif -preall: libwinkd capstone-build tree-sitter-build radare2-shell-parser-build bochs +preall: libwinkd capstone-build tree-sitter-build rizin-shell-parser-build bochs @for MOD in ${MODS} ; do \ echo $(MAKE) -C $$MOD ; \ $(MAKE) -C $$MOD HAVE_VALA= ROOT="${PWD}/../" CC="${CC}" ; \ @@ -149,7 +149,7 @@ sdb-target: .PHONY: sdb-sync sync-sdb sdbclean sdb-native sdb-target SDB_F=README.md config.mk src Makefile meson.build SDB_SYNCFILES=$(addprefix sdb.vc/,${SDB_F}) -I=../libr/include +I=../librz/include libgdbr: $(MAKE) -C gdb all @@ -189,7 +189,7 @@ ptrace-wrap-sync sync-ptrace-wrap: mkdir -p ptrace-wrap cp -rf ${PTRACE_WRAP_SYNCFILES} ptrace-wrap sed -e "s, library(, static_library(," -e "s,project(,# project(," -e "s,subdir(,# subdir(," ptrace-wrap.vc/meson.build > ptrace-wrap/meson.build - printf "include ../../libr/config.mk\ninclude ../../mk/platform.mk\ninclude ../../mk/${COMPILER}.mk\n\n" | cat - ptrace-wrap.vc/Makefile > ptrace-wrap/Makefile + printf "include ../../librz/config.mk\ninclude ../../mk/platform.mk\ninclude ../../mk/${COMPILER}.mk\n\n" | cat - ptrace-wrap.vc/Makefile > ptrace-wrap/Makefile rm -rf ptrace-wrap.vc printf "CFLAGS+=-I\$$(STOP)/ptrace-wrap/include\nLINK+=\$$(STOP)/ptrace-wrap/libptrace_wrap.\$$(EXT_AR)\nPTRACEWRAP_OBJS=\$$(STOP)/ptrace-wrap/src/ptrace_wrap.o\n" > ptrace-wrap/deps.mk @@ -199,11 +199,11 @@ ptrace-wrap: ptrace-wrap-clean clean-ptrace-wrap: $(MAKE) -C ptrace-wrap clean -$(TCCLIB) libr_tcc/libr_tcc.${EXT_AR}: - cd libr_tcc ; $(MAKE) +$(TCCLIB) librz_tcc/librz_tcc.${EXT_AR}: + cd librz_tcc ; $(MAKE) tcc-clean tccclean: - cd libr_tcc ; $(MAKE) clean + cd librz_tcc ; $(MAKE) clean CFILES=i386-asm.c i386-gen.c libtcc.c tccasm.c tccelf.c tccgen.c tccpp.c HFILES=tcc.h i386-asm.h tcclib.h tcctok.h stab.h @@ -222,17 +222,17 @@ tcc-sync sync-tcc: $(GIT) add tcc rm -rf _ -install: libr_shlr.${EXT_AR} +install: librz_shlr.${EXT_AR} mkdir -p ${DESTDIR}/${LIBDIR} - cp -f libr_shlr.${EXT_AR} ${DESTDIR}/${LIBDIR} + cp -f librz_shlr.${EXT_AR} ${DESTDIR}/${LIBDIR} install-symlink symstall: mkdir -p "${DESTDIR}${LIBDIR}" - #cd tcc ; for FILE in libr_tcc* ; do \ + #cd tcc ; for FILE in librz_tcc* ; do \ # ln -fs `pwd`/$$FILE ${DESTDIR}${LIBDIR}/$$FILE ; done uninstall deinstall: - rm -f ${DESTDIR}${LIBDIR}/libr_shlr.${EXT_AR} + rm -f ${DESTDIR}${LIBDIR}/librz_shlr.${EXT_AR} ifeq ($(USE_CAPSTONE),1) # Do nothing here @@ -292,14 +292,14 @@ ifneq (${EXT_AR},a) -cp -f capstone/libcapstone.a capstone/libcapstone.${EXT_AR} endif endif -../../radare2-webui: - cd ../.. ; git clone --depth 1 https://github.com/radareorg/radare2-webui +../../rizin-webui: + cd ../.. ; git clone --depth 1 https://github.com/rizinorg/rizin-webui -../../radare2-webui/dist/m: ../../radare2-webui +../../rizin-webui/dist/m: ../../rizin-webui ifeq ($(WITHOUT_PULL),1) - cd ../../radare2-webui/www/m && npm i ; $(MAKE) release + cd ../../rizin-webui/www/m && npm i ; $(MAKE) release else - cd ../../radare2-webui/www/m && git pull ; npm i ; $(MAKE) release + cd ../../rizin-webui/www/m && git pull ; npm i ; $(MAKE) release endif tree-sitter-build: tree-sitter/libtree-sitter.$(EXT_AR) @@ -319,35 +319,35 @@ tree-sitter-sync: cp -rf ./tree-sitter.vc/lib/include ./tree-sitter/lib rm -rf tree-sitter.vc -radare2-shell-parser-build: radare2-shell-parser/libshell-parser.$(EXT_AR) +rizin-shell-parser-build: rizin-shell-parser/libshell-parser.$(EXT_AR) -radare2-shell-parser/libshell-parser.$(EXT_AR): radare2-shell-parser/src/parser.o radare2-shell-parser/src/scanner.o - $(AR) rvs $@ radare2-shell-parser/src/parser.o radare2-shell-parser/src/scanner.o +rizin-shell-parser/libshell-parser.$(EXT_AR): rizin-shell-parser/src/parser.o rizin-shell-parser/src/scanner.o + $(AR) rvs $@ rizin-shell-parser/src/parser.o rizin-shell-parser/src/scanner.o $(RANLIB) $@ -radare2-shell-parser/src/parser.o: radare2-shell-parser/src/parser.c - $(CC) $(NEWSHELL_CFLAGS) -c radare2-shell-parser/src/parser.c -o $@ -Iradare2-shell-parser/src/tree_sitter -Itree-sitter/lib/include $(CFLAGS) +rizin-shell-parser/src/parser.o: rizin-shell-parser/src/parser.c + $(CC) $(NEWSHELL_CFLAGS) -c rizin-shell-parser/src/parser.c -o $@ -Irizin-shell-parser/src/tree_sitter -Itree-sitter/lib/include $(CFLAGS) -radare2-shell-parser/src/scanner.o: radare2-shell-parser/src/scanner.c - $(CC) -c radare2-shell-parser/src/scanner.c -o $@ -Iradare2-shell-parser/src/tree_sitter -Itree-sitter/lib/include $(CFLAGS) +rizin-shell-parser/src/scanner.o: rizin-shell-parser/src/scanner.c + $(CC) -c rizin-shell-parser/src/scanner.c -o $@ -Irizin-shell-parser/src/tree_sitter -Itree-sitter/lib/include $(CFLAGS) SHLRS+=tree-sitter/libtree-sitter.a -SHLRS+=radare2-shell-parser/libshell-parser.a +SHLRS+=rizin-shell-parser/libshell-parser.a -www-sync-m sync-www-m: ../../radare2-webui/dist/m - cp -rf ../../radare2-webui/dist/m www/m.tmp +www-sync-m sync-www-m: ../../rizin-webui/dist/m + cp -rf ../../rizin-webui/dist/m www/m.tmp rm -rf www/m mv www/m.tmp www/m git add www/m www-sync-p sync-www-p: - cp -rf ../../radare2-webui/dist/p www/p.tmp + cp -rf ../../rizin-webui/dist/p www/p.tmp rm -rf www/p mv www/p.tmp www/p git add www/p www-sync-t sync-www-t: - cp -rf ../../radare2-webui/dist/t www/t.tmp + cp -rf ../../rizin-webui/dist/t www/t.tmp rm -rf www/t mv www/t.tmp www/t git add www/p @@ -364,34 +364,34 @@ spp-sync sync-spp: git add spp spp: spp-sync - CFLAGS="-DUSE_R2=1 -I../../libr/include -DHAVE_FORK=${HAVE_FORK} -fPIC" $(MAKE) -C spp r2lib + CFLAGS="-DUSE_R2=1 -I../../librz/include -DHAVE_FORK=${HAVE_FORK} -fPIC" $(MAKE) -C spp r2lib -SHLRS+=ar/libr_ar.a +SHLRS+=ar/librz_ar.a SHLRS+=bochs/lib/libbochs.a SHLRS+=capstone/libcapstone.a SHLRS+=gdb/lib/libgdbr.a SHLRS+=grub/libgrubfs.a -SHLRS+=java/libr_java.a +SHLRS+=java/librz_java.a SHLRS+=lz4/liblz4.a SHLRS+=qnx/lib/libqnxr.a SHLRS+=yxml/libyxml.a -SHLRS+=winkd/libr_winkd.a +SHLRS+=winkd/librz_winkd.a SHLRS+=zip/librz.a -libr_shlr.${EXT_AR}: - rm -rf .libr - mkdir .libr +librz_shlr.${EXT_AR}: + rm -rf .librz + mkdir .librz ifeq ($(CC),emcc) for LIB in ${SHLRS} ; do \ - if [ -f "$${LIB}" ]; then emcc -emit-llvm -nostdlib -Wl,--whole-archive -o .libr/$$(basename $${LIB}.a).o $${LIB} ; fi ; \ + if [ -f "$${LIB}" ]; then emcc -emit-llvm -nostdlib -Wl,--whole-archive -o .librz/$$(basename $${LIB}.a).o $${LIB} ; fi ; \ done - ${AR} rs $@ .libr/*.o + ${AR} rs $@ .librz/*.o $(RANLIB) $@ else for LIB in ${SHLRS} ; do \ - if [ -f "$${LIB}" ]; then ${PARTIALLD} -o .libr/$$(basename $${LIB}.a).o $${LIB} ; fi ; \ + if [ -f "$${LIB}" ]; then ${PARTIALLD} -o .librz/$$(basename $${LIB}.a).o $${LIB} ; fi ; \ done - ${AR} rs $@ .libr/*.o + ${AR} rs $@ .librz/*.o $(RANLIB) $@ endif diff --git a/shlr/ar/Makefile b/shlr/ar/Makefile index 33312db62d..a61703aa67 100644 --- a/shlr/ar/Makefile +++ b/shlr/ar/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../config-user.mk include ../../mk/platform.mk include ../../mk/${COMPILER}.mk @@ -26,10 +26,10 @@ endif endif endif -CFLAGS+=-I../../libr/include -LIBAR=libr_ar.${EXT_AR} -LDFLAGS+=-L../../libr/util -LIBS=-lr_util +CFLAGS+=-I../../librz/include +LIBAR=librz_ar.${EXT_AR} +LDFLAGS+=-L../../librz/util +LIBS=-lrz_util include ../../shlr/sdb.mk diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 973d27bc48..564c79e1fc 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -1,6 +1,6 @@ /* radare - LGPLv3 - Copyright 2017 - xarkes */ #include -#include +#include #include "ar.h" #define BUF_SIZE 512 @@ -15,12 +15,12 @@ static int index_filename = -2; /** * Open an ar/lib file. If filename is NULL, list archive files */ -R_API RBuffer *ar_open_file(const char *arname, const char *filename) { +RZ_API RBuffer *ar_open_file(const char *arname, const char *filename) { int r; - RList *files = NULL; - RBuffer *b = r_buf_new_file (arname, O_RDWR, 0); + RzList *files = NULL; + RBuffer *b = rz_buf_new_file (arname, O_RDWR, 0); if (!b) { - r_sys_perror (__FUNCTION__); + rz_sys_perror (__FUNCTION__); return NULL; } @@ -33,7 +33,7 @@ R_API RBuffer *ar_open_file(const char *arname, const char *filename) { if (!r) { goto fail; } - files = r_list_new (); + files = rz_list_new (); /* Parse archive */ ar_read_file (b, buffer, true, NULL, NULL); ar_read_filename_table (b, buffer, files, filename); @@ -44,9 +44,9 @@ R_API RBuffer *ar_open_file(const char *arname, const char *filename) { } if (!filename) { - RListIter *iter; + RzListIter *iter; char *name; - r_list_foreach (files, iter, name) { + rz_list_foreach (files, iter, name) { printf ("%s\n", name); } goto fail; @@ -57,34 +57,34 @@ R_API RBuffer *ar_open_file(const char *arname, const char *filename) { } free (buffer); - r_list_free (files); + rz_list_free (files); return b; fail: - r_list_free (files); + rz_list_free (files); free (buffer); ar_close (b); return NULL; } -R_API int ar_close(RBuffer *b) { - r_buf_free (b); +RZ_API int ar_close(RBuffer *b) { + rz_buf_free (b); return 0; } -R_API int ar_read_at(RBuffer *b, ut64 off, void *buf, int count) { - return r_buf_read_at (b, off, buf, count); +RZ_API int ar_read_at(RBuffer *b, ut64 off, void *buf, int count) { + return rz_buf_read_at (b, off, buf, count); } -R_API int ar_write_at(RBuffer *b, ut64 off, void *buf, int count) { - return r_buf_write_at (b, off, buf, count); +RZ_API int ar_write_at(RBuffer *b, ut64 off, void *buf, int count) { + return rz_buf_write_at (b, off, buf, count); } int ar_read(RBuffer *b, void *dest, int len) { - int r = r_buf_read (b, dest, len); + int r = rz_buf_read (b, dest, len); if (!r) { return 0; } - r_buf_seek (b, r, R_BUF_CUR); + rz_buf_seek (b, r, R_BUF_CUR); return r; } @@ -114,7 +114,7 @@ int ar_read_header(RBuffer *b, char *buffer) { return r; } -int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char *filename) { +int ar_read_file(RBuffer *b, char *buffer, bool lookup, RzList *files, const char *filename) { ut64 filesize = 0; char *tmp = NULL; char *curfile = NULL; @@ -129,7 +129,7 @@ int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char /* Fix padding issues */ if (*buffer == '\n') { buffer[0] = buffer[1]; - r_buf_seek (b, -1, R_BUF_CUR); + rz_buf_seek (b, -1, R_BUF_CUR); ar_read (b, buffer, 2); } ar_read (b, buffer + 2, AR_FILENAME_LEN - 2); @@ -138,14 +138,14 @@ int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char /* Fix some padding issues */ if (buffer[AR_FILENAME_LEN - 1] != '/' && buffer[AR_FILENAME_LEN - 1] != ' ') { // Find padding offset - tmp = (char *)r_str_lchr (buffer, ' '); + tmp = (char *)rz_str_lchr (buffer, ' '); if (!tmp) { goto fail; } int dif = (int) (tmp - buffer); dif = 31 - dif; // Re-read the whole filename - r_buf_seek (b, -dif, R_BUF_CUR); + rz_buf_seek (b, -dif, R_BUF_CUR); r = ar_read (b, buffer, AR_FILENAME_LEN); if (r != AR_FILENAME_LEN) { goto fail; @@ -167,7 +167,7 @@ int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char } *tmp = '\0'; if (files) { - r_list_append (files, strdup (curfile)); + rz_list_append (files, strdup (curfile)); } } /* Timestamp 12 @@ -192,14 +192,14 @@ int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char if (!lookup && filename) { /* Check filename */ if (index == index_filename || !strcmp (curfile, filename)) { - r_buf_resize(b, filesize); + rz_buf_resize(b, filesize); free (curfile); - return r_buf_size (b); + return rz_buf_size (b); } } (void)ar_read (b, buffer, 1); - r_buf_seek (b, filesize - 1, R_BUF_CUR); + rz_buf_seek (b, filesize - 1, R_BUF_CUR); free (curfile); return filesize; fail: @@ -207,19 +207,19 @@ fail: return 0; } -int ar_read_filename_table(RBuffer *b, char *buffer, RList *files, const char *filename) { +int ar_read_filename_table(RBuffer *b, char *buffer, RzList *files, const char *filename) { int r = ar_read (b, buffer, AR_FILENAME_LEN); if (r != AR_FILENAME_LEN) { return 0; } if (strncmp (buffer, "//", 2)) { // What we read was not a filename table, just go back - r_buf_seek (b, -AR_FILENAME_LEN, R_BUF_CUR); + rz_buf_seek (b, -AR_FILENAME_LEN, R_BUF_CUR); return 0; } /* Read table size */ - r_buf_seek (b, 32, R_BUF_CUR); + rz_buf_seek (b, 32, R_BUF_CUR); r = ar_read (b, buffer, 10); if (r != 10) { return 0; @@ -243,11 +243,11 @@ int ar_read_filename_table(RBuffer *b, char *buffer, RList *files, const char *f if (*(char *) buffer == '\n') { break; } - r_list_append (files, strdup ((char *) buffer)); + rz_list_append (files, strdup ((char *) buffer)); /* End slash plus separation character ("/\n") */ len += r + 2; /* Separation character (not always '\n') */ - r_buf_seek (b, 1, R_BUF_CUR); + rz_buf_seek (b, 1, R_BUF_CUR); index++; } return len; diff --git a/shlr/ar/ar.h b/shlr/ar/ar.h index 6f4f2067c3..e7946f66fc 100644 --- a/shlr/ar/ar.h +++ b/shlr/ar/ar.h @@ -4,14 +4,14 @@ /* Offset passed is always the real io->off of the inspected file, * the functions automatically translate it to relative offset within the archive */ -R_API RBuffer *ar_open_file(const char *arname, const char *filename); -R_API int ar_close(RBuffer *b); -R_API int ar_read_at(RBuffer *b, ut64 off, void *buf, int count); -R_API int ar_write_at(RBuffer *b, ut64 off, void *buf, int count); +RZ_API RBuffer *ar_open_file(const char *arname, const char *filename); +RZ_API int ar_close(RBuffer *b); +RZ_API int ar_read_at(RBuffer *b, ut64 off, void *buf, int count); +RZ_API int ar_write_at(RBuffer *b, ut64 off, void *buf, int count); int ar_read(RBuffer *b, void *dest, int len); int ar_read_until_slash(RBuffer *b, char *buffer, int limit); int ar_read_header(RBuffer *b, char *buffer); -int ar_read_file(RBuffer *b, char *buffer, bool lookup, RList *files, const char *filename); -int ar_read_filename_table(RBuffer *b, char *buffer, RList *files, const char *filename); +int ar_read_file(RBuffer *b, char *buffer, bool lookup, RzList *files, const char *filename); +int ar_read_filename_table(RBuffer *b, char *buffer, RzList *files, const char *filename); #endif // _AR_H diff --git a/shlr/ar/deps.mk b/shlr/ar/deps.mk index 4a33b0b9fb..2eeb2b7d7b 100644 --- a/shlr/ar/deps.mk +++ b/shlr/ar/deps.mk @@ -1 +1 @@ -LINK+=$(STOP)/ar/libr_ar.$(EXT_AR) +LINK+=$(STOP)/ar/librz_ar.$(EXT_AR) diff --git a/shlr/bochs/Makefile b/shlr/bochs/Makefile index 702dd311a2..b2040acb43 100644 --- a/shlr/bochs/Makefile +++ b/shlr/bochs/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/platform.mk EDITOR?=vim CC?=gcc @@ -12,11 +12,11 @@ MAJOR=0 MINOR=1 LD=$(CC) ifeq ($(LD),cccl) -LDFLAGS+=-L${LIBR}/socket -llibr_socket -LDFLAGS+=-L${LIBR}/util -llibr_util +LDFLAGS+=-L${LIBR}/socket -llibrz_socket +LDFLAGS+=-L${LIBR}/util -llibrz_util else -LDFLAGS+=-L${LIBR}/socket -lr_socket -LDFLAGS+=-L${LIBR}/util -lr_util +LDFLAGS+=-L${LIBR}/socket -lrz_socket +LDFLAGS+=-L${LIBR}/util -lrz_util endif ifeq ($(OSTYPE),darwin) LDFLAGS_SHARED=-dynamiclib @@ -24,7 +24,7 @@ else LDFLAGS_SHARED=-shared endif #OSTYPE=windows -include ../../libr/socket/deps.mk +include ../../librz/socket/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/sdb.mk diff --git a/shlr/bochs/include/libbochs.h b/shlr/bochs/include/libbochs.h index 83f6bfb09c..d5997faf82 100644 --- a/shlr/bochs/include/libbochs.h +++ b/shlr/bochs/include/libbochs.h @@ -2,7 +2,7 @@ #ifndef LIBBOCHS_H #define LIBBOCHS_H -#include +#include #if __WINDOWS__ #include diff --git a/shlr/bochs/src/libbochs.c b/shlr/bochs/src/libbochs.c index a6377871e8..4da18855ce 100644 --- a/shlr/bochs/src/libbochs.c +++ b/shlr/bochs/src/libbochs.c @@ -1,4 +1,4 @@ -/* libbochs - radare2 - LGPL - Copyright 2016 - SkUaTeR */ +/* libbochs - rizin - LGPL - Copyright 2016 - SkUaTeR */ #include "libbochs.h" @@ -116,7 +116,7 @@ bool bochs_wait(libbochs_t *b) { } void bochs_send_cmd(libbochs_t* b, const char *cmd, bool bWait) { - char *cmdbuff = r_str_newf ("%s\n", cmd); + char *cmdbuff = rz_str_newf ("%s\n", cmd); bochs_reset_buffer (b); size_t cmdlen = strlen (cmdbuff); #if __WINDOWS__ @@ -159,7 +159,7 @@ int bochs_read(libbochs_t* b, ut64 addr, int count, ut8 * buf) { data[fin] = 0; if (data[i] == '<') break; - pbuf += r_hex_str2bin (&data[ini], &buf[pbuf]); + pbuf += rz_hex_str2bin (&data[ini], &buf[pbuf]); i++; // next line } while (data[i] != '<' && i < lenRec); } @@ -219,7 +219,7 @@ bool bochs_open(libbochs_t* b, const char * pathBochs, const char * pathConfig) b->info.dwFlags |= STARTF_USESTDHANDLES; snprintf (commandline, sizeof (commandline), "\"%s\" -f \"%s\" -q ", pathBochs, pathConfig); lprintf ("*** Creating process: %s\n", commandline); - commandline_ = r_sys_conv_utf8_to_win (commandline); + commandline_ = rz_sys_conv_utf8_to_win (commandline); if (CreateProcess (NULL, commandline_, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &b->info, &b->processInfo)) { lprintf ("Process created\n"); diff --git a/shlr/gdb/Makefile b/shlr/gdb/Makefile index c68ad1042a..283c69102a 100644 --- a/shlr/gdb/Makefile +++ b/shlr/gdb/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/platform.mk include ../../mk/$(COMPILER).mk include ../../shlr/zip/deps.mk @@ -15,12 +15,12 @@ MAJOR=0 MINOR=1 LD=$(CC) ifeq ($(LD),cccl) -LDFLAGS+=-L${LIBR}/socket -llibr_socket -LDFLAGS+=-L${LIBR}/util -llibr_util +LDFLAGS+=-L${LIBR}/socket -llibrz_socket +LDFLAGS+=-L${LIBR}/util -llibrz_util EXT_AR?=lib else -LDFLAGS+=-L${LIBR}/socket -lr_socket -LDFLAGS+=-L${LIBR}/util -lr_util +LDFLAGS+=-L${LIBR}/socket -lrz_socket +LDFLAGS+=-L${LIBR}/util -lrz_util EXT_AR?=a endif @@ -31,7 +31,7 @@ LDFLAGS_SHARED=-shared endif #OSTYPE=windows -include ../../libr/socket/deps.mk +include ../../librz/socket/deps.mk include ../../shlr/sdb.mk # Test variables @@ -88,13 +88,13 @@ client: lib $(LD) $(TEST_D)/client.o -o $(TEST_D)/client -L$(LIB) -lgdbr run_test: client - rarun2 libpath=./lib program=./test/client + rz_run libpath=./lib program=./test/client gdb_test: client - rarun2 libpath=./lib system="gdb ./test/client" + rz_run libpath=./lib system="gdb ./test/client" valgrind_test: client - rarun2 libpath=./lib system="valgrind --track-origins=yes -v --leak-check=full ./test/client" + rz_run libpath=./lib system="valgrind --track-origins=yes -v --leak-check=full ./test/client" edit: $(EDITOR) -c "args **/*.h **/*.c" diff --git a/shlr/gdb/deps.mk b/shlr/gdb/deps.mk index f57a778513..1de32bd713 100644 --- a/shlr/gdb/deps.mk +++ b/shlr/gdb/deps.mk @@ -1,3 +1,3 @@ LINK+=$(STOP)/gdb/lib/libgdbr.$(EXT_AR) -LDFLAGS+=-lr_cons +LDFLAGS+=-lrz_cons include $(LIBR)/socket/deps.mk diff --git a/shlr/gdb/include/gdbclient/commands.h b/shlr/gdb/include/gdbclient/commands.h index cf67f7f67a..2eda0b6b92 100644 --- a/shlr/gdb/include/gdbclient/commands.h +++ b/shlr/gdb/include/gdbclient/commands.h @@ -2,8 +2,8 @@ #define CLIENT_COMMANDS_H #include "../libgdbr.h" -#include "r_types_base.h" -#include +#include "rz_types_base.h" +#include /*! * \brief Acquires the gdbr lock and sets up breaking @@ -129,12 +129,12 @@ int gdbr_close_file(libgdbr_t *g); /*! * \brief get list of threads for given pid */ -RList* gdbr_threads_list(libgdbr_t *g, int pid); +RzList* gdbr_threads_list(libgdbr_t *g, int pid); /*! * \brief get a list of the child processes of the given pid */ -RList* gdbr_pids_list(libgdbr_t *g, int pid); +RzList* gdbr_pids_list(libgdbr_t *g, int pid); /*! * Get absolute name of file executed to create a process diff --git a/shlr/gdb/include/gdbclient/core.h b/shlr/gdb/include/gdbclient/core.h index 9fa03e4b27..f29d90f3be 100644 --- a/shlr/gdb/include/gdbclient/core.h +++ b/shlr/gdb/include/gdbclient/core.h @@ -2,7 +2,7 @@ #ifndef GDB_CLIENT_CORE_H #define GDB_CLIENT_CORE_H -#include "r_types.h" +#include "rz_types.h" #include #include diff --git a/shlr/gdb/include/gdbclient/xml.h b/shlr/gdb/include/gdbclient/xml.h index f6aea2853d..c65295d20b 100644 --- a/shlr/gdb/include/gdbclient/xml.h +++ b/shlr/gdb/include/gdbclient/xml.h @@ -6,6 +6,6 @@ #include "libgdbr.h" int gdbr_read_target_xml(libgdbr_t *g); -int gdbr_read_processes_xml(libgdbr_t *g, int pid, RList* list); +int gdbr_read_processes_xml(libgdbr_t *g, int pid, RzList* list); #endif // GDBCLIENT_XML_H diff --git a/shlr/gdb/include/gdbserver/core.h b/shlr/gdb/include/gdbserver/core.h index 54eca69aab..a4b1f1b362 100644 --- a/shlr/gdb/include/gdbserver/core.h +++ b/shlr/gdb/include/gdbserver/core.h @@ -1,7 +1,7 @@ #ifndef GDB_SERVER_CORE_H #define GDB_SERVER_CORE_H -#include +#include #include "../libgdbr.h" typedef int (*gdbr_server_cmd_cb) (libgdbr_t*, void*, const char*, char*, size_t); diff --git a/shlr/gdb/include/libgdbr.h b/shlr/gdb/include/libgdbr.h index e5e1092949..3ca9d8a760 100644 --- a/shlr/gdb/include/libgdbr.h +++ b/shlr/gdb/include/libgdbr.h @@ -8,9 +8,9 @@ typedef unsigned int ssize_t; #endif #include "arch.h" -#include "r_types_base.h" -#include "r_socket.h" -#include "r_th.h" +#include "rz_types_base.h" +#include "rz_socket.h" +#include "rz_th.h" #define MSG_OK 0 #define MSG_NOT_SUPPORTED -1 @@ -164,7 +164,7 @@ typedef struct libgdbr_t { ssize_t read_len; // len of read_buff (if read_buff not fully consumed) // is already handled (i.e. already send or ...) - RSocket *sock; + RzSocket *sock; int connected; int acks; char *data; @@ -188,7 +188,7 @@ typedef struct libgdbr_t { bool get_baddr; libgdbr_stop_reason_t stop_reason; - RThreadLock *gdbr_lock; + RzThreadLock *gdbr_lock; int gdbr_lock_depth; // current depth inside the recursive lock // parsed from target @@ -223,7 +223,7 @@ const char *gdbr_get_reg_profile(int arch, int bits); /*! * \brief Function set the gdbr internal registers profile - * \param registers profile string which shares the same format as RReg API + * \param registers profile string which shares the same format as RzReg API * \returns a failure code */ int gdbr_set_reg_profile(libgdbr_t *g, const char *str); diff --git a/shlr/gdb/meson.build b/shlr/gdb/meson.build index c13a11da76..51d0bb0c46 100644 --- a/shlr/gdb/meson.build +++ b/shlr/gdb/meson.build @@ -22,13 +22,13 @@ gdb_inc = [ ) ] -libr2gdb = static_library('r2gdb', gdb_files, +librzgdb = static_library('r2gdb', gdb_files, include_directories: gdb_inc, - dependencies: [r_util_dep, r_cons_dep], + dependencies: [rz_util_dep, rz_cons_dep], implicit_include_directories: false ) gdb_dep = declare_dependency( - link_with: libr2gdb, + link_with: librzgdb, include_directories: gdb_inc ) diff --git a/shlr/gdb/src/arch.c b/shlr/gdb/src/arch.c index 314defbdae..f6ae063aa6 100644 --- a/shlr/gdb/src/arch.c +++ b/shlr/gdb/src/arch.c @@ -1,4 +1,4 @@ -#include +#include #include "arch.h" static ut64 parse_size(char *s, char **end) { @@ -43,8 +43,8 @@ gdb_reg_t *arch_parse_reg_profile(const char * reg_profile) { char tmp[128]; int i, j, l; const char *p = reg_profile; - RList *gdb_regs_list = r_list_newf (free); - RListIter *iter; + RzList *gdb_regs_list = rz_list_newf (free); + RzListIter *iter; gdb_reg_t *reg; // Line number @@ -109,10 +109,10 @@ gdb_reg_t *arch_parse_reg_profile(const char * reg_profile) { free (tok[i]); } // Clean up - r_list_free (gdb_regs_list); + rz_list_free (gdb_regs_list); return NULL; } - r_list_append (gdb_regs_list, reg); + rz_list_append (gdb_regs_list, reg); } // Clean up for (i = 0; i < j; i++) { @@ -121,17 +121,17 @@ gdb_reg_t *arch_parse_reg_profile(const char * reg_profile) { } } while (*p++); - gdb_reg_t *gdb_regs = malloc ((r_list_length (gdb_regs_list) + 1) * sizeof (gdb_reg_t)); + gdb_reg_t *gdb_regs = malloc ((rz_list_length (gdb_regs_list) + 1) * sizeof (gdb_reg_t)); if (!gdb_regs) { return NULL; } i = 0; - r_list_foreach (gdb_regs_list, iter, reg) { + rz_list_foreach (gdb_regs_list, iter, reg) { memcpy (reg, gdb_regs + i, sizeof (gdb_reg_t)); i++; } memset (gdb_regs + i, 0, sizeof (gdb_reg_t)); - r_list_free (gdb_regs_list); + rz_list_free (gdb_regs_list); return gdb_regs; } diff --git a/shlr/gdb/src/common.c b/shlr/gdb/src/common.c index 65bc121020..aa1349e886 100644 --- a/shlr/gdb/src/common.c +++ b/shlr/gdb/src/common.c @@ -4,7 +4,7 @@ #include "gdbr_common.h" #include "packet.h" #include "utils.h" -#include "r_util/r_str.h" +#include "rz_util/rz_str.h" int handle_qSupported(libgdbr_t *g) { char *tok = NULL; @@ -15,107 +15,107 @@ int handle_qSupported(libgdbr_t *g) { // TODO handle the message correct and set all infos like packetsize, thread stuff and features tok = strtok (g->data, ";"); while (tok) { - if (r_str_startswith (tok, "PacketSize=")) { + if (rz_str_startswith (tok, "PacketSize=")) { // Largest packet size we support is 2048 g->stub_features.pkt_sz = R_MIN (strtoul (tok + strlen ("PacketSize="), NULL, 16), 2048); // Shouldn't be smaller than 64 (Erroneous 0 etc.) g->stub_features.pkt_sz = R_MAX (g->stub_features.pkt_sz, 64); - } else if (r_str_startswith (tok, "qXfer:")) { + } else if (rz_str_startswith (tok, "qXfer:")) { if (!tok[6]) { tok = strtok (NULL, ";"); continue; } char *p = tok + 6; - if (r_str_startswith (p, "btrace:read")) { + if (rz_str_startswith (p, "btrace:read")) { g->stub_features.qXfer_btrace_read = (p[strlen ("btrace:read")] == '+'); - } else if (r_str_startswith (p, "btrace-conf:read")) { + } else if (rz_str_startswith (p, "btrace-conf:read")) { g->stub_features.qXfer_btrace_conf_read = (p[strlen ("btrace-conf:read")] == '+'); - } else if (r_str_startswith (p, "spu:read")) { + } else if (rz_str_startswith (p, "spu:read")) { g->stub_features.qXfer_spu_read = (p[strlen ("spu:read")] == '+'); - } else if (r_str_startswith (p, "spu:write")) { + } else if (rz_str_startswith (p, "spu:write")) { g->stub_features.qXfer_spu_write = (p[strlen ("spu:write")] == '+'); - } else if (r_str_startswith (p, "libraries:read")) { + } else if (rz_str_startswith (p, "libraries:read")) { g->stub_features.qXfer_libraries_read = (p[strlen ("libraries:read")] == '+'); - } else if (r_str_startswith (p, "libraries-svr4:read")) { + } else if (rz_str_startswith (p, "libraries-svr4:read")) { g->stub_features.qXfer_libraries_svr4_read = (p[strlen ("libraries-svr4:read")] == '+'); - } else if (r_str_startswith (p, "memory-map:read")) { + } else if (rz_str_startswith (p, "memory-map:read")) { g->stub_features.qXfer_memory_map_read = (p[strlen ("memory-map:read")] == '+'); - } else if (r_str_startswith (p, "auxv:read")) { + } else if (rz_str_startswith (p, "auxv:read")) { g->stub_features.qXfer_auxv_read = (p[strlen ("auxv:read")] == '+'); - } else if (r_str_startswith (p, "exec-file:read")) { + } else if (rz_str_startswith (p, "exec-file:read")) { g->stub_features.qXfer_exec_file_read = (p[strlen ("exec-file:read")] == '+'); - } else if (r_str_startswith (p, "features:read")) { + } else if (rz_str_startswith (p, "features:read")) { g->stub_features.qXfer_features_read = (p[strlen ("features:read")] == '+'); - } else if (r_str_startswith (p, "sdata:read")) { + } else if (rz_str_startswith (p, "sdata:read")) { g->stub_features.qXfer_sdata_read = (p[strlen ("sdata:read")] == '+'); - } else if (r_str_startswith (p, "siginfo:read")) { + } else if (rz_str_startswith (p, "siginfo:read")) { g->stub_features.qXfer_siginfo_read = (p[strlen ("siginfo:read")] == '+'); - } else if (r_str_startswith (p, "siginfo:write")) { + } else if (rz_str_startswith (p, "siginfo:write")) { g->stub_features.qXfer_siginfo_write = (p[strlen ("siginfo:write")] == '+'); - } else if (r_str_startswith (p, "threads:read")) { + } else if (rz_str_startswith (p, "threads:read")) { g->stub_features.qXfer_threads_read = (p[strlen ("threads:read")] == '+'); - } else if (r_str_startswith (p, "traceframe-info:read")) { + } else if (rz_str_startswith (p, "traceframe-info:read")) { g->stub_features.qXfer_traceframe_info_read = (p[strlen ("traceframe-info:read")] == '+'); - } else if (r_str_startswith (p, "uib:read")) { + } else if (rz_str_startswith (p, "uib:read")) { g->stub_features.qXfer_uib_read = (p[strlen ("uib:read")] == '+'); - } else if (r_str_startswith (p, "fdpic:read")) { + } else if (rz_str_startswith (p, "fdpic:read")) { g->stub_features.qXfer_fdpic_read = (p[strlen ("fdpic:read")] == '+'); - } else if (r_str_startswith (p, "osdata:read")) { + } else if (rz_str_startswith (p, "osdata:read")) { g->stub_features.qXfer_osdata_read = (p[strlen ("osdata:read")] == '+'); } } else if (tok[0] == 'Q') { - if (r_str_startswith (tok, "Qbtrace")) { + if (rz_str_startswith (tok, "Qbtrace")) { if (!tok[strlen ("Qbtrace")]) { tok = strtok (NULL, ";"); continue; } char *p = tok + 7; - if (r_str_startswith (p, ":off")) { + if (rz_str_startswith (p, ":off")) { g->stub_features.Qbtrace_off = (p[4] == '+'); - } else if (r_str_startswith (p, ":bts")) { + } else if (rz_str_startswith (p, ":bts")) { g->stub_features.Qbtrace_bts = (p[4] == '+'); - } else if (r_str_startswith (p, ":pt")) { + } else if (rz_str_startswith (p, ":pt")) { g->stub_features.Qbtrace_pt = (p[3] == '+'); - } else if (r_str_startswith (p, "-conf:bts:size")) { + } else if (rz_str_startswith (p, "-conf:bts:size")) { g->stub_features.Qbtrace_conf_bts_size = (p[strlen ("-conf:bts:size")] == '+'); - } else if (r_str_startswith (p, ":-conf:pt:size")) { + } else if (rz_str_startswith (p, ":-conf:pt:size")) { g->stub_features.Qbtrace_conf_pt_size = (p[strlen ("-conf:pt:size")] == '+'); } - } else if (r_str_startswith (tok, "QNonStop")) { + } else if (rz_str_startswith (tok, "QNonStop")) { g->stub_features.QNonStop = (tok[strlen ("QNonStop")] == '+'); - } else if (r_str_startswith (tok, "QCatchSyscalls")) { + } else if (rz_str_startswith (tok, "QCatchSyscalls")) { g->stub_features.QCatchSyscalls = (tok[strlen ("QCatchSyscalls")] == '+'); - } else if (r_str_startswith (tok, "QPassSignals")) { + } else if (rz_str_startswith (tok, "QPassSignals")) { g->stub_features.QPassSignals = (tok[strlen ("QPassSignals")] == '+'); - } else if (r_str_startswith (tok, "QStartNoAckMode")) { + } else if (rz_str_startswith (tok, "QStartNoAckMode")) { g->stub_features.QStartNoAckMode = (tok[strlen ("QStartNoAckMode")] == '+'); - } else if (r_str_startswith (tok, "QAgent")) { + } else if (rz_str_startswith (tok, "QAgent")) { g->stub_features.QAgent = (tok[strlen ("QAgent")] == '+'); - } else if (r_str_startswith (tok, "QAllow")) { + } else if (rz_str_startswith (tok, "QAllow")) { g->stub_features.QAllow = (tok[strlen ("QAllow")] == '+'); - } else if (r_str_startswith (tok, "QDisableRandomization")) { + } else if (rz_str_startswith (tok, "QDisableRandomization")) { g->stub_features.QDisableRandomization = (tok[strlen ("QDisableRandomization")] == '+'); - } else if (r_str_startswith (tok, "QTBuffer:size")) { + } else if (rz_str_startswith (tok, "QTBuffer:size")) { g->stub_features.QTBuffer_size = (tok[strlen ("QTBuffer:size")] == '+'); - } else if (r_str_startswith (tok, "QThreadEvents")) { + } else if (rz_str_startswith (tok, "QThreadEvents")) { g->stub_features.QThreadEvents = (tok[strlen ("QThreadEvents")] == '+'); - } else if (r_str_startswith (tok, "QThreadSuffixSupported")) { + } else if (rz_str_startswith (tok, "QThreadSuffixSupported")) { g->remote_type = GDB_REMOTE_TYPE_LLDB; g->stub_features.lldb.QThreadSuffixSupported = (tok[strlen ("QThreadSuffixSupported")] == '+'); - } else if (r_str_startswith (tok, "QListThreadsInStopReply")) { + } else if (rz_str_startswith (tok, "QListThreadsInStopReply")) { g->remote_type = GDB_REMOTE_TYPE_LLDB; g->stub_features.lldb.QListThreadsInStopReply = (tok[strlen ("QListThreadsInStopReply")] == '+'); } - } else if (r_str_startswith (tok, "multiprocess")) { + } else if (rz_str_startswith (tok, "multiprocess")) { g->stub_features.multiprocess = (tok[strlen ("multiprocess")] == '+'); - } else if (r_str_startswith (tok, "qEcho")) { + } else if (rz_str_startswith (tok, "qEcho")) { g->remote_type = GDB_REMOTE_TYPE_LLDB; g->stub_features.lldb.qEcho = (tok[strlen ("qEcho")] == '+'); - } else if (r_str_startswith (tok, "ReverseStep")) { + } else if (rz_str_startswith (tok, "ReverseStep")) { g->stub_features.ReverseStep = (tok[strlen ("ReverseStep")] == '+'); - } else if (r_str_startswith (tok, "ReverseContinue")) { + } else if (rz_str_startswith (tok, "ReverseContinue")) { g->stub_features.ReverseContinue = (tok[strlen ("ReverseContinue")] == '+'); } // TODO @@ -132,7 +132,7 @@ int send_ack(libgdbr_t *g) { if (g->no_ack) { return 0; } - if (r_socket_write (g->sock, "+", 1) < 0) { + if (rz_socket_write (g->sock, "+", 1) < 0) { return -1; } if (g->server_debug) { diff --git a/shlr/gdb/src/gdbclient/core.c b/shlr/gdb/src/gdbclient/core.c index cfbfac7977..cf6c563b58 100644 --- a/shlr/gdb/src/gdbclient/core.c +++ b/shlr/gdb/src/gdbclient/core.c @@ -8,9 +8,9 @@ #include "libgdbr.h" #include "gdbr_common.h" #include "packet.h" -#include "r_util/r_strbuf.h" -#include "r_cons.h" -#include "r_debug.h" +#include "rz_util/rz_strbuf.h" +#include "rz_cons.h" +#include "rz_debug.h" #if __UNIX__ #include @@ -93,20 +93,20 @@ static void gdbr_break_process(void *arg) { } bool gdbr_lock_tryenter(libgdbr_t *g) { - if (!r_th_lock_tryenter (g->gdbr_lock)) { + if (!rz_th_lock_tryenter (g->gdbr_lock)) { return false; } g->gdbr_lock_depth++; - r_cons_break_push (gdbr_break_process, g); + rz_cons_break_push (gdbr_break_process, g); return true; } bool gdbr_lock_enter(libgdbr_t *g) { - r_cons_break_push (gdbr_break_process, g); - void *bed = r_cons_sleep_begin (); - r_th_lock_enter (g->gdbr_lock); + rz_cons_break_push (gdbr_break_process, g); + void *bed = rz_cons_sleep_begin (); + rz_th_lock_enter (g->gdbr_lock); g->gdbr_lock_depth++; - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (g->isbreaked) { return false; } @@ -114,11 +114,11 @@ bool gdbr_lock_enter(libgdbr_t *g) { } void gdbr_lock_leave(libgdbr_t *g) { - r_cons_break_pop (); + rz_cons_break_pop (); assert (g->gdbr_lock_depth > 0); bool last_leave = g->gdbr_lock_depth == 1; g->gdbr_lock_depth--; - r_th_lock_leave (g->gdbr_lock); + rz_th_lock_leave (g->gdbr_lock); // if this is the last lock this thread holds make sure that we disable the break if (last_leave) { g->isbreaked = false; @@ -167,21 +167,21 @@ int gdbr_connect(libgdbr_t *g, const char *host, int port) { g->stub_features.pkt_sz = 64; char *env_pktsz_str; ut32 env_pktsz = 0; - if ((env_pktsz_str = r_sys_getenv ("R2_GDB_PKTSZ"))) { + if ((env_pktsz_str = rz_sys_getenv ("R2_GDB_PKTSZ"))) { if ((env_pktsz = (ut32)strtoul (env_pktsz_str, NULL, 10))) { g->stub_features.pkt_sz = R_MAX (env_pktsz, GDB_MAX_PKTSZ); } } - // Use the default break handler for r_socket_connect to send a signal - r_cons_break_pop (); - bed = r_cons_sleep_begin (); + // Use the default break handler for rz_socket_connect to send a signal + rz_cons_break_pop (); + bed = rz_cons_sleep_begin (); if (*host == '/') { - ret = r_socket_connect_serial (g->sock, host, port, 1); + ret = rz_socket_connect_serial (g->sock, host, port, 1); } else { - ret = r_socket_connect_tcp (g->sock, host, sdb_fmt ("%d", port), 1); + ret = rz_socket_connect_tcp (g->sock, host, sdb_fmt ("%d", port), 1); } - r_cons_sleep_end (bed); - r_cons_break_push (gdbr_break_process, g); + rz_cons_sleep_end (bed); + rz_cons_break_push (gdbr_break_process, g); if (!ret) { ret = -1; goto end; @@ -191,7 +191,7 @@ int gdbr_connect(libgdbr_t *g, const char *host, int port) { } read_packet (g, true); // vcont=true lets us skip if we get no reply g->connected = 1; - bed = r_cons_sleep_begin (); + bed = rz_cons_sleep_begin (); // TODO add config possibility here for (i = 0; i < QSUPPORTED_MAX_RETRIES && !g->isbreaked; i++) { ret = send_msg (g, message); @@ -208,7 +208,7 @@ int gdbr_connect(libgdbr_t *g, const char *host, int port) { } break; } - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); if (g->isbreaked) { g->isbreaked = false; ret = -1; @@ -272,7 +272,7 @@ int gdbr_connect(libgdbr_t *g, const char *host, int port) { ret = 0; end: if (ret != 0) { - r_socket_close (g->sock); + rz_socket_close (g->sock); } gdbr_lock_leave (g); return ret; @@ -280,7 +280,7 @@ end: int gdbr_disconnect(libgdbr_t *g) { // TODO Disconnect maybe send something to gdbserver - if (!g || !r_socket_close (g->sock)) { + if (!g || !rz_socket_close (g->sock)) { return -1; } if (!gdbr_lock_enter (g)) { @@ -1278,12 +1278,12 @@ int send_vcont(libgdbr_t *g, const char *command, const char *thread_id) { goto end; } - bed = r_cons_sleep_begin (); - while ((ret = read_packet (g, true)) < 0 && !g->isbreaked && r_socket_is_connected (g->sock)); + bed = rz_cons_sleep_begin (); + while ((ret = read_packet (g, true)) < 0 && !g->isbreaked && rz_socket_is_connected (g->sock)); if (g->isbreaked) { g->isbreaked = false; // Stop target - r_socket_write (g->sock, "\x03", 1); + rz_socket_write (g->sock, "\x03", 1); // Read the stop reason if (read_packet (g, false) < 0) { ret = -1; @@ -1293,7 +1293,7 @@ int send_vcont(libgdbr_t *g, const char *command, const char *thread_id) { ret = handle_cont (g); end: - r_cons_sleep_end (bed); + rz_cons_sleep_end (bed); gdbr_lock_leave (g); return ret; } @@ -1669,7 +1669,7 @@ char* gdbr_exec_file_read(libgdbr_t *g, int pid) { if (g->data_len == 1) { break; } - path = r_str_append (path, g->data + 1); + path = rz_str_append (path, g->data + 1); break; } if (g->data[0] != 'm') { @@ -1677,7 +1677,7 @@ char* gdbr_exec_file_read(libgdbr_t *g, int pid) { goto end; } off += strlen (g->data + 1); - if (!(path = r_str_append (path, g->data + 1))) { + if (!(path = rz_str_append (path, g->data + 1))) { ret = -1; goto end; } @@ -1730,13 +1730,13 @@ end: return ret; } -RList* gdbr_pids_list(libgdbr_t *g, int pid) { +RzList* gdbr_pids_list(libgdbr_t *g, int pid) { int ret = -1; - RList *list = NULL; + RzList *list = NULL; int tpid = -1, ttid = -1; char *ptr, *ptr2, *exec_file; - RDebugPid *dpid = NULL; - RListIter *iter = NULL; + RzDebugPid *dpid = NULL; + RzListIter *iter = NULL; if (!g) { return NULL; @@ -1745,7 +1745,7 @@ RList* gdbr_pids_list(libgdbr_t *g, int pid) { if (!gdbr_lock_enter (g)) { goto end; } - if (!(list = r_list_new ())) { + if (!(list = rz_list_new ())) { ret = -1; goto end; } @@ -1783,12 +1783,12 @@ RList* gdbr_pids_list(libgdbr_t *g, int pid) { continue; } // Avoid adding the same pid twice(could show more than once if it has threads) - r_list_foreach (list, iter, dpid) { + rz_list_foreach (list, iter, dpid) { if (tpid == dpid->pid) { continue; } } - if (!(dpid = R_NEW0 (RDebugPid)) || !(dpid->path = strdup (exec_file))) { + if (!(dpid = R_NEW0 (RzDebugPid)) || !(dpid->path = strdup (exec_file))) { ret = -1; goto end; } @@ -1800,7 +1800,7 @@ RList* gdbr_pids_list(libgdbr_t *g, int pid) { dpid->uid = dpid->gid = -1; dpid->runnable = true; dpid->status = R_DBG_PROC_STOP; - r_list_append (list, dpid); + rz_list_append (list, dpid); ptr = ptr2; } if (send_msg (g, "qsThreadInfo") < 0 || read_packet (g, false) < 0 @@ -1821,28 +1821,28 @@ end: if (dpid) { free (dpid); } - // We can't use r_debug_pid_free here + // We can't use rz_debug_pid_free here if (list) { - r_list_foreach (list, iter, dpid) { + rz_list_foreach (list, iter, dpid) { if (dpid->path) { free (dpid->path); } free (dpid); } - r_list_free (list); + rz_list_free (list); } return NULL; } return list; } -RList* gdbr_threads_list(libgdbr_t *g, int pid) { +RzList* gdbr_threads_list(libgdbr_t *g, int pid) { int ret = -1; - RList *list = NULL; + RzList *list = NULL; int tpid = -1, ttid = -1; char *ptr, *ptr2, *exec_file; - RDebugPid *dpid = NULL; - RListIter *iter = NULL; + RzDebugPid *dpid = NULL; + RzListIter *iter = NULL; if (!g) { return NULL; @@ -1864,7 +1864,7 @@ RList* gdbr_threads_list(libgdbr_t *g, int pid) { ret = -1; goto end; } - if (!(list = r_list_new ())) { + if (!(list = rz_list_new ())) { ret = -1; goto end; } @@ -1885,7 +1885,7 @@ RList* gdbr_threads_list(libgdbr_t *g, int pid) { ptr = ptr2; continue; } - if (!(dpid = R_NEW0 (RDebugPid)) || !(dpid->path = strdup (exec_file))) { + if (!(dpid = R_NEW0 (RzDebugPid)) || !(dpid->path = strdup (exec_file))) { ret = -1; goto end; } @@ -1896,7 +1896,7 @@ RList* gdbr_threads_list(libgdbr_t *g, int pid) { // probably not correct. // TODO: Implement getting correct thread status from GDB dpid->status = R_DBG_PROC_STOP; - r_list_append (list, dpid); + rz_list_append (list, dpid); ptr = ptr2; } if (send_msg (g, "qsThreadInfo") < 0 || read_packet (g, false) < 0 @@ -1910,7 +1910,7 @@ RList* gdbr_threads_list(libgdbr_t *g, int pid) { } } // This is the all I've been able to extract from gdb so far - r_list_foreach (list, iter, dpid) { + rz_list_foreach (list, iter, dpid) { if (gdbr_is_thread_dead (g, pid, dpid->pid)) { dpid->status = R_DBG_PROC_DEAD; } @@ -1923,15 +1923,15 @@ end: if (dpid) { free (dpid); } - // We can't use r_debug_pid_free here + // We can't use rz_debug_pid_free here if (list) { - r_list_foreach (list, iter, dpid) { + rz_list_foreach (list, iter, dpid) { if (dpid->path) { free (dpid->path); } free (dpid); } - r_list_free (list); + rz_list_free (list); } return NULL; } @@ -1953,7 +1953,7 @@ ut64 gdbr_get_baddr(libgdbr_t *g) { min = UINT64_MAX; goto end; } - if (r_str_startswith (g->data, "TextSeg=")) { + if (rz_str_startswith (g->data, "TextSeg=")) { ptr = g->data + strlen ("TextSeg="); if (!isxdigit (*ptr)) { goto end; @@ -1966,7 +1966,7 @@ ut64 gdbr_get_baddr(libgdbr_t *g) { goto end; } ptr++; - if (*ptr && r_str_startswith (ptr, "DataSeg=")) { + if (*ptr && rz_str_startswith (ptr, "DataSeg=")) { ptr += strlen ("DataSeg="); if (!isxdigit (*ptr)) { goto end; @@ -1978,7 +1978,7 @@ ut64 gdbr_get_baddr(libgdbr_t *g) { } goto end; } - if (!r_str_startswith (g->data, "Text=")) { + if (!rz_str_startswith (g->data, "Text=")) { goto end; } ptr = g->data + strlen ("Text="); @@ -1989,7 +1989,7 @@ ut64 gdbr_get_baddr(libgdbr_t *g) { if (off < min) { min = off; } - if (!(ptr = strchr (ptr, ';')) || !r_str_startswith (ptr + 1, "Data=")) { + if (!(ptr = strchr (ptr, ';')) || !rz_str_startswith (ptr + 1, "Data=")) { min = UINT64_MAX; goto end; } @@ -2006,7 +2006,7 @@ ut64 gdbr_get_baddr(libgdbr_t *g) { goto end; } ptr++; - if (r_str_startswith (ptr, "Bss=")) { + if (rz_str_startswith (ptr, "Bss=")) { ptr += strlen ("Bss="); if (!isxdigit (*ptr)) { goto end; diff --git a/shlr/gdb/src/gdbclient/responses.c b/shlr/gdb/src/gdbclient/responses.c index b07e01b098..897a13d3a5 100644 --- a/shlr/gdb/src/gdbclient/responses.c +++ b/shlr/gdb/src/gdbclient/responses.c @@ -5,7 +5,7 @@ #include "gdbclient/core.h" #include "gdbr_common.h" #include "utils.h" -#include "r_util/r_str.h" +#include "rz_util/rz_str.h" int handle_g(libgdbr_t *g) { @@ -184,7 +184,7 @@ int handle_vFile_close(libgdbr_t *g) { return send_ack (g); } -#include +#include #include static int stop_reason_exit(libgdbr_t *g) { @@ -279,7 +279,7 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.is_valid = true; g->stop_reason.reason = R_DEBUG_REASON_SIGNAL; for (ptr1 = strtok (g->data + 3, ";"); ptr1; ptr1 = strtok (NULL, ";")) { - if (r_str_startswith (ptr1, "thread") && !g->stop_reason.thread.present) { + if (rz_str_startswith (ptr1, "thread") && !g->stop_reason.thread.present) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -292,7 +292,7 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.thread.present = true; continue; } - if (r_str_startswith (ptr1, "core")) { + if (rz_str_startswith (ptr1, "core")) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -304,9 +304,9 @@ int handle_stop_reason(libgdbr_t *g) { continue; } if (g->stop_reason.signum == 5) { - if (r_str_startswith (ptr1, "watch") - || r_str_startswith (ptr1, "rwatch") - || r_str_startswith (ptr1, "awatch")) { + if (rz_str_startswith (ptr1, "watch") + || rz_str_startswith (ptr1, "rwatch") + || rz_str_startswith (ptr1, "awatch")) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -318,7 +318,7 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.watchpoint.present = true; continue; } - if (r_str_startswith (ptr1, "exec") && !g->stop_reason.exec.present) { + if (rz_str_startswith (ptr1, "exec") && !g->stop_reason.exec.present) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -330,7 +330,7 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.exec.present = true; continue; } - if (r_str_startswith (ptr1, "fork") && !g->stop_reason.fork.present) { + if (rz_str_startswith (ptr1, "fork") && !g->stop_reason.fork.present) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -343,7 +343,7 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.fork.present = true; continue; } - if (r_str_startswith (ptr1, "vfork") && !g->stop_reason.vfork.present) { + if (rz_str_startswith (ptr1, "vfork") && !g->stop_reason.vfork.present) { if (!(ptr2 = strchr (ptr1, ':'))) { continue; } @@ -356,23 +356,23 @@ int handle_stop_reason(libgdbr_t *g) { g->stop_reason.vfork.present = true; continue; } - if (r_str_startswith (ptr1, "vforkdone")) { + if (rz_str_startswith (ptr1, "vforkdone")) { g->stop_reason.vforkdone = true; continue; } - if (r_str_startswith (ptr1, "library")) { + if (rz_str_startswith (ptr1, "library")) { g->stop_reason.library = true; continue; } - if (r_str_startswith (ptr1, "swbreak")) { + if (rz_str_startswith (ptr1, "swbreak")) { g->stop_reason.swbreak = true; continue; } - if (r_str_startswith (ptr1, "hwbreak")) { + if (rz_str_startswith (ptr1, "hwbreak")) { g->stop_reason.hwbreak = true; continue; } - if (r_str_startswith (ptr1, "create")) { + if (rz_str_startswith (ptr1, "create")) { g->stop_reason.create = true; continue; } diff --git a/shlr/gdb/src/gdbclient/xml.c b/shlr/gdb/src/gdbclient/xml.c index 1fb3fd5ca9..98c2fef396 100644 --- a/shlr/gdb/src/gdbclient/xml.c +++ b/shlr/gdb/src/gdbclient/xml.c @@ -6,8 +6,8 @@ #include "arch.h" #include "gdbr_common.h" #include "packet.h" -#include -#include +#include +#include #define MAX_PID_CHARS (5) @@ -169,14 +169,14 @@ typedef struct { static void _write_flag_bits(char *buf, const gdbr_xml_flags_t *flags); static int _resolve_arch(libgdbr_t *g, char *xml_data); -static RList *_extract_flags(char *flagstr); -static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias); -static RDebugPid *_extract_pid_info(const char *info, const char *path, int tid); +static RzList *_extract_flags(char *flagstr); +static RzList *_extract_regs(char *regstr, RzList *flags, char *pc_alias); +static RzDebugPid *_extract_pid_info(const char *info, const char *path, int tid); static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { char *regstr, *flagstr, *tmp, *profile = NULL, pc_alias[64], flag_bits[65]; - RList *flags, *regs; - RListIter *iter; + RzList *flags, *regs; + RzListIter *iter; gdbr_xml_flags_t *tmpflag; gdbr_xml_reg_t *tmpreg; int packed_size = 0; @@ -194,18 +194,18 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { return -1; } if (!(regs = _extract_regs (regstr, flags, pc_alias))) { - r_list_free (flags); + rz_list_free (flags); return -1; } - if (!(arch_regs = malloc (sizeof (gdb_reg_t) * (r_list_length (regs) + 1)))) { + if (!(arch_regs = malloc (sizeof (gdb_reg_t) * (rz_list_length (regs) + 1)))) { goto exit_err; } // approximate per-reg size estimates - profile_max_len = r_list_length (regs) * 128 + r_list_length (flags) * 128; + profile_max_len = rz_list_length (regs) * 128 + rz_list_length (flags) * 128; if (!(profile = malloc (profile_max_len))) { goto exit_err; } - r_list_foreach (regs, iter, tmpreg) { + rz_list_foreach (regs, iter, tmpreg) { if (!tmpreg) { continue; } @@ -221,8 +221,8 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { } flag_bits[0] = '\0'; tmpflag = NULL; - if (tmpreg->flagnum < r_list_length (flags)) { - tmpflag = r_list_get_n (flags, tmpreg->flagnum); + if (tmpreg->flagnum < rz_list_length (flags)) { + tmpflag = rz_list_get_n (flags, tmpreg->flagnum); _write_flag_bits (flag_bits, tmpflag); } packed_size = 0; @@ -262,7 +262,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { case R_SYS_ARCH_ARM: switch (g->target.bits) { case 32: - if (!(profile = r_str_prepend (profile, + if (!(profile = rz_str_prepend (profile, "=PC pc\n" "=SP sp\n" // XXX "=A0 r0\n" @@ -274,7 +274,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { } break; case 64: - if (!(profile = r_str_prepend (profile, + if (!(profile = rz_str_prepend (profile, "=PC pc\n" "=SP sp\n" "=BP x29\n" @@ -295,7 +295,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { case R_SYS_ARCH_X86: switch (g->target.bits) { case 32: - if (!(profile = r_str_prepend (profile, + if (!(profile = rz_str_prepend (profile, "=PC eip\n" "=SP esp\n" "=BP ebp\n"))) { @@ -303,7 +303,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { } break; case 64: - if (!(profile = r_str_prepend (profile, + if (!(profile = rz_str_prepend (profile, "=PC rip\n" "=SP rsp\n" "=BP rbp\n"))) { @@ -312,7 +312,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { } break; case R_SYS_ARCH_MIPS: - if (!(profile = r_str_prepend (profile, + if (!(profile = rz_str_prepend (profile, "=PC pc\n" "=SP r29\n"))) { goto exit_err; @@ -321,7 +321,7 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { default: // TODO others if (*pc_alias) { - if (!(profile = r_str_prepend (profile, pc_alias))) { + if (!(profile = rz_str_prepend (profile, pc_alias))) { goto exit_err; } } @@ -332,8 +332,8 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { g->target.bits = 64; } } - r_list_free (flags); - r_list_free (regs); + rz_list_free (flags); + rz_list_free (regs); free (g->target.regprofile); if (profile) { g->target.regprofile = strdup (profile); @@ -344,8 +344,8 @@ static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len) { return 0; exit_err: - r_list_free (flags); - r_list_free (regs); + rz_list_free (flags); + rz_list_free (regs); free (profile); free (arch_regs); return -1; @@ -361,14 +361,14 @@ exit_err: */ -static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int pid, RList *list) { +static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int pid, RzList *list) { char pidstr[MAX_PID_CHARS + 1], status[1024], cmdline[1024]; char *itemstr, *itemstr_end, *column, *column_end, *proc_filename; int ret = -1, ipid, column_data_len; - RDebugPid *pid_info = NULL; + RzDebugPid *pid_info = NULL; // Make sure the given xml is valid - if (!r_str_startswith (xml_data, "")) { + if (!rz_str_startswith (xml_data, "")) { ret = -1; goto end; } @@ -415,7 +415,7 @@ static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int // Attempt to read the pid's info from /proc. Non UNIX systems will have the // correct pid and cmdline from the xml with everything else set to default - proc_filename = r_str_newf ("/proc/%d/status", ipid); + proc_filename = rz_str_newf ("/proc/%d/status", ipid); if (gdbr_open_file (g, proc_filename, O_RDONLY, 0) == 0) { if (gdbr_read_file (g, (unsigned char *)status, sizeof (status)) != -1) { pid_info = _extract_pid_info (status, cmdline, ipid); @@ -427,7 +427,7 @@ static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int } } else { eprintf ("Failed to open procfs file of pid (%d)\n", ipid); - if (!(pid_info = R_NEW0 (RDebugPid)) || !(pid_info->path = strdup (cmdline))) { + if (!(pid_info = R_NEW0 (RzDebugPid)) || !(pid_info->path = strdup (cmdline))) { ret = -1; goto end; } @@ -439,7 +439,7 @@ static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int } // Unless pid 0 is requested, only add the requested pid and it's child processes if (0 == pid || ipid == pid || pid_info->ppid == pid) { - r_list_append (list, pid_info); + rz_list_append (list, pid_info); } else { if (pid_info) { free (pid_info); @@ -473,7 +473,7 @@ int gdbr_read_target_xml(libgdbr_t *g) { return 0; } -int gdbr_read_processes_xml(libgdbr_t *g, int pid, RList *list) { +int gdbr_read_processes_xml(libgdbr_t *g, int pid, RzList *list) { if (!g->stub_features.qXfer_features_read) { return -1; } @@ -531,20 +531,20 @@ static int _resolve_arch(libgdbr_t *g, char *xml_data) { return -1; } arch++; - if (r_str_startswith (arch, "i386")) { + if (rz_str_startswith (arch, "i386")) { g->target.arch = R_SYS_ARCH_X86; g->target.bits = 32; arch += 4; - if (r_str_startswith (arch, ":x86-64")) { + if (rz_str_startswith (arch, ":x86-64")) { g->target.bits = 64; } - } else if (r_str_startswith (arch, "aarch64")) { + } else if (rz_str_startswith (arch, "aarch64")) { g->target.arch = R_SYS_ARCH_ARM; g->target.bits = 64; - } else if (r_str_startswith (arch, "arm")) { + } else if (rz_str_startswith (arch, "arm")) { g->target.arch = R_SYS_ARCH_ARM; g->target.bits = 32; - } else if (r_str_startswith (arch, "mips")) { + } else if (rz_str_startswith (arch, "mips")) { g->target.arch = R_SYS_ARCH_MIPS; g->target.bits = 32; } @@ -568,12 +568,12 @@ static int _resolve_arch(libgdbr_t *g, char *xml_data) { return 0; } -static RList *_extract_flags(char *flagstr) { +static RzList *_extract_flags(char *flagstr) { char *tmp1, *tmp2, *flagsend, *field_start, *field_end; ut64 num_fields, type_sz, name_sz; gdbr_xml_flags_t *tmpflag = NULL; - RList *flags; - if (!(flags = r_list_new ())) { + RzList *flags; + if (!(flags = rz_list_new ())) { return NULL; } flags->free = free; @@ -662,21 +662,21 @@ static RList *_extract_flags(char *flagstr) { field_start = field_end + 1; } tmpflag->num_fields = num_fields; - r_list_push (flags, tmpflag); + rz_list_push (flags, tmpflag); *flagsend = '<'; flagstr = flagsend + 1; } return flags; exit_err: if (flags) { - r_list_free (flags); + rz_list_free (flags); } free (tmpflag); return NULL; } -static RDebugPid *_extract_pid_info(const char *info, const char *path, int tid) { - RDebugPid *pid_info = R_NEW0 (RDebugPid); +static RzDebugPid *_extract_pid_info(const char *info, const char *path, int tid) { + RzDebugPid *pid_info = R_NEW0 (RzDebugPid); if (!pid_info) { return NULL; } @@ -723,14 +723,14 @@ static RDebugPid *_extract_pid_info(const char *info, const char *path, int tid) return pid_info; } -static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) { +static RzList *_extract_regs(char *regstr, RzList *flags, char *pc_alias) { char *regstr_end, *regname, *regtype, *tmp1, *tmpregstr, *feature_end, *typegroup; ut32 flagnum, regname_len, regsize, regnum; - RList *regs; - RListIter *iter; + RzList *regs; + RzListIter *iter; gdbr_xml_reg_t *tmpreg; gdbr_xml_flags_t *tmpflag; - if (!(regs = r_list_new ())) { + if (!(regs = rz_list_new ())) { return NULL; } // Set gpr as the default register type for all of the following registers until `feature` is found @@ -742,7 +742,7 @@ static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) { // Most regs don't have group/type params, attempt to get the type from `feature`. // Multiple registers can be wrapped with a certain feature so this typegroup // applies on all of the following registers until - if (r_str_startswith (regstr, "'); // To parse features of other architectures refer to: @@ -808,38 +808,38 @@ static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) { } regnum = strtoul (tmp1, NULL, 10); } - flagnum = r_list_length (flags); + flagnum = rz_list_length (flags); if ((tmp1 = strstr (regstr, "group="))) { tmp1 += 7; - if (r_str_startswith (tmp1, "float")) { + if (rz_str_startswith (tmp1, "float")) { regtype = "fpu"; - } else if (r_str_startswith (tmp1, "mmx")) { + } else if (rz_str_startswith (tmp1, "mmx")) { regtype = "mmx"; - } else if (r_str_startswith (tmp1, "sse")) { + } else if (rz_str_startswith (tmp1, "sse")) { regtype = "xmm"; - } else if (r_str_startswith (tmp1, "vector")) { + } else if (rz_str_startswith (tmp1, "vector")) { regtype = "ymm"; - } else if (r_str_startswith (tmp1, "system")) { + } else if (rz_str_startswith (tmp1, "system")) { regtype = "seg"; } // We need type information in r2 register profiles } if ((tmp1 = strstr (regstr, "type="))) { tmp1 += 6; - if (r_str_startswith (tmp1, "vec") - || r_str_startswith (tmp1, "i387_ext") - || r_str_startswith (tmp1, "ieee_single") - || r_str_startswith (tmp1, "ieee_double")) { + if (rz_str_startswith (tmp1, "vec") + || rz_str_startswith (tmp1, "i387_ext") + || rz_str_startswith (tmp1, "ieee_single") + || rz_str_startswith (tmp1, "ieee_double")) { regtype = "fpu"; - } else if (r_str_startswith (tmp1, "code_ptr")) { + } else if (rz_str_startswith (tmp1, "code_ptr")) { strcpy (pc_alias, "=PC "); strncpy (pc_alias + 4, regname, regname_len); strcpy (pc_alias + 4 + regname_len, "\n"); } else { // Check all flags. If reg is a flag, write flag data flagnum = 0; - r_list_foreach (flags, iter, tmpflag) { - if (r_str_startswith (tmp1, tmpflag->type)) { + rz_list_foreach (flags, iter, tmpflag) { + if (rz_str_startswith (tmp1, tmpflag->type)) { // Max 64-bit :/ if (tmpflag->num_bits <= 64) { break; @@ -875,22 +875,22 @@ static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) { tmpreg->size = regsize; tmpreg->flagnum = flagnum; if (regnum == UINT32_MAX) { - r_list_push (regs, tmpreg); - } else if (regnum >= r_list_length (regs)) { + rz_list_push (regs, tmpreg); + } else if (regnum >= rz_list_length (regs)) { int i; - for (i = regnum - r_list_length (regs); i > 0; i--) { + for (i = regnum - rz_list_length (regs); i > 0; i--) { // temporary placeholder reg. we trust the xml is correct and this will be replaced. - r_list_push (regs, tmpreg); - r_list_tail (regs)->data = NULL; + rz_list_push (regs, tmpreg); + rz_list_tail (regs)->data = NULL; } - r_list_push (regs, tmpreg); + rz_list_push (regs, tmpreg); } else { // this is where we replace those placeholder regs - r_list_set_n (regs, regnum, tmpreg); + rz_list_set_n (regs, regnum, tmpreg); } *regstr_end = '/'; regstr = regstr_end + 3; - if (r_str_startswith (regstr, "")) { + if (rz_str_startswith (regstr, "")) { regstr += sizeof (""); // Revert to default typegroup = "gpr"; @@ -901,7 +901,7 @@ static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) { exit_err: if (regs) { regs->free = free; - r_list_free (regs); + rz_list_free (regs); } return NULL; } diff --git a/shlr/gdb/src/gdbserver/core.c b/shlr/gdb/src/gdbserver/core.c index f92f57489b..2cd5545a99 100644 --- a/shlr/gdb/src/gdbserver/core.c +++ b/shlr/gdb/src/gdbserver/core.c @@ -9,7 +9,7 @@ #include "libgdbr.h" #include "packet.h" #include "utils.h" -#include "r_util/r_str.h" +#include "rz_util/rz_str.h" static int _server_handle_qSupported(libgdbr_t *g) { int ret; @@ -503,91 +503,91 @@ int gdbr_server_serve(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr) { if (g->data_len == 0) { continue; } - if (r_str_startswith (g->data, "k")) { + if (rz_str_startswith (g->data, "k")) { return _server_handle_k (g, cmd_cb, core_ptr); } - if (r_str_startswith (g->data, "vKill")) { + if (rz_str_startswith (g->data, "vKill")) { return _server_handle_vKill (g, cmd_cb, core_ptr); } - if (r_str_startswith (g->data, "qSupported")) { + if (rz_str_startswith (g->data, "qSupported")) { if ((ret = _server_handle_qSupported (g)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qTStatus")) { + if (rz_str_startswith (g->data, "qTStatus")) { if ((ret = _server_handle_qTStatus (g)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qC") && g->data_len == 2) { + if (rz_str_startswith (g->data, "qC") && g->data_len == 2) { if ((ret = _server_handle_qC (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qAttached")) { + if (rz_str_startswith (g->data, "qAttached")) { if ((ret = _server_handle_qAttached (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "vMustReplyEmpty")) { + if (rz_str_startswith (g->data, "vMustReplyEmpty")) { if ((ret = _server_handle_vMustReplyEmpty (g)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qTfV")) { + if (rz_str_startswith (g->data, "qTfV")) { if ((ret = _server_handle_qTfV (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qfThreadInfo")) { + if (rz_str_startswith (g->data, "qfThreadInfo")) { if ((ret = _server_handle_qfThreadInfo (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qsThreadInfo")) { + if (rz_str_startswith (g->data, "qsThreadInfo")) { if ((ret = _server_handle_qsThreadInfo (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "Hg")) { + if (rz_str_startswith (g->data, "Hg")) { if ((ret = _server_handle_Hg (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "Hc")) { + if (rz_str_startswith (g->data, "Hc")) { if ((ret = _server_handle_Hc (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "?")) { + if (rz_str_startswith (g->data, "?")) { if ((ret = _server_handle_ques (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "g") && g->data_len == 1) { + if (rz_str_startswith (g->data, "g") && g->data_len == 1) { if ((ret = _server_handle_g (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "vCont")) { + if (rz_str_startswith (g->data, "vCont")) { if ((ret = _server_handle_vCont (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qOffsets")) { + if (rz_str_startswith (g->data, "qOffsets")) { if ((ret = _server_handle_qOffsets (g, cmd_cb, core_ptr)) < 0) { return ret; } @@ -611,37 +611,37 @@ int gdbr_server_serve(libgdbr_t *g, gdbr_server_cmd_cb cmd_cb, void *core_ptr) { } continue; } - if (r_str_startswith (g->data, "m")) { + if (rz_str_startswith (g->data, "m")) { if ((ret = _server_handle_m (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "M")) { + if (rz_str_startswith (g->data, "M")) { if ((ret = _server_handle_M (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "P")) { + if (rz_str_startswith (g->data, "P")) { if ((ret = _server_handle_P (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "p")) { + if (rz_str_startswith (g->data, "p")) { if ((ret = _server_handle_p (g, cmd_cb, core_ptr)) < 0) { return ret; } continue; } - if (r_str_startswith (g->data, "qXfer:exec-file:read:")) { + if (rz_str_startswith (g->data, "qXfer:exec-file:read:")) { if ((ret = _server_handle_exec_file_read (g, cmd_cb, core_ptr)) < 0 ) { return ret; } continue; } - if (r_str_startswith (g->data, "QStartNoAckMode")) { + if (rz_str_startswith (g->data, "QStartNoAckMode")) { if (send_ack (g) < 0) { return -1; } diff --git a/shlr/gdb/src/libgdbr.c b/shlr/gdb/src/libgdbr.c index 423efbc879..1e07d65d7b 100644 --- a/shlr/gdb/src/libgdbr.c +++ b/shlr/gdb/src/libgdbr.c @@ -30,8 +30,8 @@ int gdbr_init(libgdbr_t *g, bool is_server) { R_FREE (g->send_buff); return -1; } - g->sock = r_socket_new (0); - g->gdbr_lock = r_th_lock_new (true); + g->sock = rz_socket_new (0); + g->gdbr_lock = rz_th_lock_new (true); g->gdbr_lock_depth = 0; g->last_code = MSG_OK; g->connected = 0; @@ -141,7 +141,7 @@ int gdbr_cleanup(libgdbr_t *g) { g->send_len = 0; R_FREE (g->send_buff); R_FREE (g->read_buff); - r_socket_free (g->sock); - r_th_lock_free (g->gdbr_lock); + rz_socket_free (g->sock); + rz_th_lock_free (g->gdbr_lock); return 0; } diff --git a/shlr/gdb/src/packet.c b/shlr/gdb/src/packet.c index c77ee322ac..3c20ad6d4a 100644 --- a/shlr/gdb/src/packet.c +++ b/shlr/gdb/src/packet.c @@ -160,14 +160,14 @@ int read_packet(libgdbr_t *g, bool vcont) { } g->data_len = 0; for (i = 0; i < g->num_retries && !g->isbreaked; vcont ? 0 : i++) { - ret = r_socket_ready (g->sock, 0, READ_TIMEOUT); + ret = rz_socket_ready (g->sock, 0, READ_TIMEOUT); if (ret == 0 && !vcont) { continue; } if (ret <= 0) { return -1; } - int sz = r_socket_read (g->sock, (void *)g->read_buff, g->read_max - 1); + int sz = rz_socket_read (g->sock, (void *)g->read_buff, g->read_max - 1); if (sz <= 0) { eprintf ("%s: read failed\n", __func__); return -1; @@ -199,7 +199,7 @@ int send_packet(libgdbr_t *g) { eprintf ("putpkt (\"%s\"); %s\n", g->send_buff, g->no_ack ? "[noack mode]" : "[looking for ack]"); } - return r_socket_write (g->sock, g->send_buff, g->send_len); + return rz_socket_write (g->sock, g->send_buff, g->send_len); } int pack(libgdbr_t *g, const char *msg) { diff --git a/shlr/gdb/src/utils.c b/shlr/gdb/src/utils.c index 1418bdd05a..e53c0bb071 100644 --- a/shlr/gdb/src/utils.c +++ b/shlr/gdb/src/utils.c @@ -1,10 +1,10 @@ /* libgdbr - LGPL - Copyright 2014 - defragger */ -#include "r_types.h" -#include "r_util.h" +#include "rz_types.h" +#include "rz_util.h" #include "utils.h" -// XXX: most of those functions are already implemented in r_util. reuse! +// XXX: most of those functions are already implemented in rz_util. reuse! /** * Function creates the checksum @@ -161,8 +161,8 @@ int read_thread_id(const char *src, int *pid, int *tid, bool multiprocess) { return -1; } ptr1++; - if (r_str_startswith (src, "-1")) { - if (r_str_startswith (ptr1, "-1")) { + if (rz_str_startswith (src, "-1")) { + if (rz_str_startswith (ptr1, "-1")) { *pid = *tid = -1; return 0; } @@ -171,7 +171,7 @@ int read_thread_id(const char *src, int *pid, int *tid, bool multiprocess) { if (!isxdigit (*src)) { return -1; } - if (r_str_startswith (ptr1, "-1")) { + if (rz_str_startswith (ptr1, "-1")) { *pid = (int) strtol (src, NULL, 16); *tid = -1; return 0; @@ -183,7 +183,7 @@ int read_thread_id(const char *src, int *pid, int *tid, bool multiprocess) { *tid = (int) strtol (ptr1, NULL, 16); return 0; } - if (r_str_startswith (src, "-1")) { + if (rz_str_startswith (src, "-1")) { *tid = -1; return 0; } diff --git a/shlr/grub/Makefile b/shlr/grub/Makefile index ae121e8243..bdfcbc4b1c 100644 --- a/shlr/grub/Makefile +++ b/shlr/grub/Makefile @@ -5,7 +5,7 @@ include ../../global.mk include ../../mk/platform.mk NAME=grubfs _INCLUDE_MK_GCC_= -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/${COMPILER}.mk EXT_AR?=a @@ -61,7 +61,7 @@ KERNFILES+=partmap/sunpc.c KERNOBJS=$(subst .c,.o,${KERNFILES}) CFLAGS+=-Iinclude -CFLAGS+=-I../../libr/include -DGRUB_TARGET_NO_MODULES +CFLAGS+=-I../../librz/include -DGRUB_TARGET_NO_MODULES CFLAGS+=-g ifneq (,$(findstring cygwin,${OSTYPE})) diff --git a/shlr/grub/fs/affs.c b/shlr/grub/fs/affs.c index b717ad5d50..8614d7282e 100644 --- a/shlr/grub/fs/affs.c +++ b/shlr/grub/fs/affs.c @@ -24,7 +24,7 @@ #include #include #include -#include "r_types.h" +#include "rz_types.h" /* The affs bootblock. */ R_PACKED( struct grub_affs_bblock diff --git a/shlr/grub/fs/btrfs.c b/shlr/grub/fs/btrfs.c index dc4da311a4..d2ea629b50 100644 --- a/shlr/grub/fs/btrfs.c +++ b/shlr/grub/fs/btrfs.c @@ -23,15 +23,15 @@ #include #include #include -#include -#define BTRFS_SIGNATURE "_BHRfS_M" +#include +#define BTRzFS_SIGNATURE "_BHRfS_M" R_PACKED( struct btrfs_superblock { grub_uint8_t dummy1[32]; grub_uint16_t uuid[8]; grub_uint8_t dummy2[16]; - grub_uint8_t signature[sizeof (BTRFS_SIGNATURE) - 1]; + grub_uint8_t signature[sizeof (BTRzFS_SIGNATURE) - 1]; }); struct grub_btrfs_data @@ -50,7 +50,7 @@ grub_btrfs_mount (grub_disk_t disk) &data->sblock) != GRUB_ERR_NONE) goto fail; - if (grub_memcmp ((char *) data->sblock.signature, BTRFS_SIGNATURE, sizeof (BTRFS_SIGNATURE) - 1)) + if (grub_memcmp ((char *) data->sblock.signature, BTRzFS_SIGNATURE, sizeof (BTRzFS_SIGNATURE) - 1)) { grub_error (GRUB_ERR_BAD_FS, "not a Btrfs filesystem"); goto fail; diff --git a/shlr/grub/fs/cpio.c b/shlr/grub/fs/cpio.c index 14ae9ee10b..2a9aeac3f3 100644 --- a/shlr/grub/fs/cpio.c +++ b/shlr/grub/fs/cpio.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #ifndef MODE_USTAR /* cpio support */ diff --git a/shlr/grub/fs/fat.c b/shlr/grub/fs/fat.c index 3c5f043b4b..851b07fc10 100644 --- a/shlr/grub/fs/fat.c +++ b/shlr/grub/fs/fat.c @@ -17,7 +17,7 @@ * along with GRUB. If not, see . */ -#include +#include #include #include #include diff --git a/shlr/grub/fs/hfs.c b/shlr/grub/fs/hfs.c index cb0122a3fa..548ddd2ba8 100644 --- a/shlr/grub/fs/hfs.c +++ b/shlr/grub/fs/hfs.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #define GRUB_HFS_SBLOCK 2 #define GRUB_HFS_EMBED_HFSPLUS_SIG 0x482B diff --git a/shlr/grub/fs/hfsplus.c b/shlr/grub/fs/hfsplus.c index dcfc9cf439..92f3987db9 100644 --- a/shlr/grub/fs/hfsplus.c +++ b/shlr/grub/fs/hfsplus.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #define GRUB_HFSPLUS_MAGIC 0x482B #define GRUB_HFSPLUSX_MAGIC 0x4858 diff --git a/shlr/grub/fs/iso9660.c b/shlr/grub/fs/iso9660.c index 997e611871..07923fcbd8 100644 --- a/shlr/grub/fs/iso9660.c +++ b/shlr/grub/fs/iso9660.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #define GRUB_ISO9660_FSTYPE_DIR 0040000 #define GRUB_ISO9660_FSTYPE_REG 0100000 diff --git a/shlr/grub/fs/jfs.c b/shlr/grub/fs/jfs.c index 8ab7b0b1dd..17a74d56fa 100644 --- a/shlr/grub/fs/jfs.c +++ b/shlr/grub/fs/jfs.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define GRUB_JFS_MAX_SYMLNK_CNT 8 #define GRUB_JFS_FILETYPE_MASK 0170000 diff --git a/shlr/grub/fs/nilfs2.c b/shlr/grub/fs/nilfs2.c index 417fe8b53f..690f2cc5fd 100644 --- a/shlr/grub/fs/nilfs2.c +++ b/shlr/grub/fs/nilfs2.c @@ -33,7 +33,7 @@ #include #include #include -#include +#include #define NILFS_INODE_BMAP_SIZE 7 diff --git a/shlr/grub/fs/reiserfs.c b/shlr/grub/fs/reiserfs.c index c2b714ffc2..446e43413e 100644 --- a/shlr/grub/fs/reiserfs.c +++ b/shlr/grub/fs/reiserfs.c @@ -25,8 +25,8 @@ */ #if 0 -# define GRUB_REISERFS_DEBUG -# define GRUB_REISERFS_JOURNALING +# define GRUB_REISERzFS_DEBUG +# define GRUB_REISERzFS_JOURNALING # define GRUB_HEXDUMP #endif @@ -37,35 +37,35 @@ #include #include #include -#include -#include +#include +#include #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif -#define REISERFS_SUPER_BLOCK_OFFSET 0x10000 -#define REISERFS_MAGIC_LEN 12 -#define REISERFS_MAGIC_STRING "ReIsEr" -#define REISERFS_MAGIC_DESC_BLOCK "ReIsErLB" +#define REISERzFS_SUPER_BLOCK_OFFSET 0x10000 +#define REISERzFS_MAGIC_LEN 12 +#define REISERzFS_MAGIC_STRING "ReIsEr" +#define REISERzFS_MAGIC_DESC_BLOCK "ReIsErLB" /* If the 3rd bit of an item state is set, then it's visible. */ -#define GRUB_REISERFS_VISIBLE_MASK ((grub_uint16_t) 0x04) -#define REISERFS_MAX_LABEL_LENGTH 16 -#define REISERFS_LABEL_OFFSET 0x64 +#define GRUB_REISERzFS_VISIBLE_MASK ((grub_uint16_t) 0x04) +#define REISERzFS_MAX_LABEL_LENGTH 16 +#define REISERzFS_LABEL_OFFSET 0x64 #undef S_IFLNK #define S_IFLNK 0xA000 enum grub_reiserfs_item_type { - GRUB_REISERFS_STAT, - GRUB_REISERFS_DIRECTORY, - GRUB_REISERFS_DIRECT, - GRUB_REISERFS_INDIRECT, + GRUB_REISERzFS_STAT, + GRUB_REISERzFS_DIRECTORY, + GRUB_REISERzFS_DIRECT, + GRUB_REISERzFS_INDIRECT, /* Matches both _DIRECT and _INDIRECT when searching. */ - GRUB_REISERFS_ANY, - GRUB_REISERFS_UNKNOWN + GRUB_REISERzFS_ANY, + GRUB_REISERzFS_UNKNOWN }; R_PACKED ( struct grub_reiserfs_superblock @@ -85,7 +85,7 @@ struct grub_reiserfs_superblock grub_uint16_t oid_max_size; grub_uint16_t oid_current_size; grub_uint16_t state; - grub_uint8_t magic_string[REISERFS_MAGIC_LEN]; + grub_uint8_t magic_string[REISERzFS_MAGIC_LEN]; grub_uint32_t function_hash_code; grub_uint16_t tree_height; grub_uint16_t bitmap_number; @@ -243,17 +243,17 @@ grub_reiserfs_get_key_v2_type (const struct grub_reiserfs_key *key) switch ((int)(o>>60)) { case 0: - return GRUB_REISERFS_STAT; + return GRUB_REISERzFS_STAT; case 15: - return GRUB_REISERFS_ANY; + return GRUB_REISERzFS_ANY; case 3: - return GRUB_REISERFS_DIRECTORY; + return GRUB_REISERzFS_DIRECTORY; case 2: - return GRUB_REISERFS_DIRECT; + return GRUB_REISERzFS_DIRECT; case 1: - return GRUB_REISERFS_INDIRECT; + return GRUB_REISERzFS_INDIRECT; } - return GRUB_REISERFS_UNKNOWN; + return GRUB_REISERzFS_UNKNOWN; } /* Return the type of given v1 key. */ @@ -263,26 +263,26 @@ grub_reiserfs_get_key_v1_type (const struct grub_reiserfs_key *key) switch (grub_le_to_cpu32 (key->u.v1.type)) { case 0: - return GRUB_REISERFS_STAT; + return GRUB_REISERzFS_STAT; case 555: - return GRUB_REISERFS_ANY; + return GRUB_REISERzFS_ANY; case 500: - return GRUB_REISERFS_DIRECTORY; + return GRUB_REISERzFS_DIRECTORY; case 0x20000000: case 0xFFFFFFFF: - return GRUB_REISERFS_DIRECT; + return GRUB_REISERzFS_DIRECT; case 0x10000000: case 0xFFFFFFFE: - return GRUB_REISERFS_INDIRECT; + return GRUB_REISERzFS_INDIRECT; } - return GRUB_REISERFS_UNKNOWN; + return GRUB_REISERzFS_UNKNOWN; } /* Return 1 if the given key is version 1 key, 2 otherwise. */ static int grub_reiserfs_get_key_version (const struct grub_reiserfs_key *key) { - return grub_reiserfs_get_key_v1_type (key) == GRUB_REISERFS_UNKNOWN ? 2 : 1; + return grub_reiserfs_get_key_v1_type (key) == GRUB_REISERzFS_UNKNOWN ? 2 : 1; } #ifdef GRUB_HEXDUMP @@ -301,7 +301,7 @@ grub_hexdump (char *buffer, grub_size_t len) } #endif -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG static grub_uint64_t grub_reiserfs_get_key_offset (const struct grub_reiserfs_key *key); @@ -380,19 +380,19 @@ grub_reiserfs_set_key_type (struct grub_reiserfs_key *key, switch (grub_type) { - case GRUB_REISERFS_STAT: + case GRUB_REISERzFS_STAT: type = 0; break; - case GRUB_REISERFS_ANY: + case GRUB_REISERzFS_ANY: type = (version == 1) ? 555 : 15; break; - case GRUB_REISERFS_DIRECTORY: + case GRUB_REISERzFS_DIRECTORY: type = (version == 1) ? 500 : 3; break; - case GRUB_REISERFS_DIRECT: + case GRUB_REISERzFS_DIRECT: type = (version == 1) ? 0xFFFFFFFF : 2; break; - case GRUB_REISERFS_INDIRECT: + case GRUB_REISERzFS_INDIRECT: type = (version == 1) ? 0xFFFFFFFE : 1; break; default: @@ -406,7 +406,7 @@ grub_reiserfs_set_key_type (struct grub_reiserfs_key *key, = ((key->u.v2.offset_type & grub_cpu_to_le64 (~0ULL >> 4)) | grub_cpu_to_le64 ((grub_uint64_t) type << 60)); - r_warn_if_fail (grub_reiserfs_get_key_type (key) == grub_type); + rz_warn_if_fail (grub_reiserfs_get_key_type (key) == grub_type); } /* -1 if key 1 if lower than key 2. @@ -446,12 +446,12 @@ grub_reiserfs_compare_keys (const struct grub_reiserfs_key *key1, type1 = grub_reiserfs_get_key_type (key1); type2 = grub_reiserfs_get_key_type (key2); - if ((type1 == GRUB_REISERFS_ANY - && (type2 == GRUB_REISERFS_DIRECT - || type2 == GRUB_REISERFS_INDIRECT)) - || (type2 == GRUB_REISERFS_ANY - && (type1 == GRUB_REISERFS_DIRECT - || type1 == GRUB_REISERFS_INDIRECT))) + if ((type1 == GRUB_REISERzFS_ANY + && (type2 == GRUB_REISERzFS_DIRECT + || type2 == GRUB_REISERzFS_INDIRECT)) + || (type2 == GRUB_REISERzFS_ANY + && (type1 == GRUB_REISERzFS_DIRECT + || type1 == GRUB_REISERzFS_INDIRECT))) return 0; if (type1 < type2) return -1; @@ -496,7 +496,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, block_size = grub_le_to_cpu16 (data->superblock.block_size); block_number = grub_le_to_cpu32 (data->superblock.root_block); -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG grub_printf("Searching for "); grub_reiserfs_print_key (key); #endif @@ -541,7 +541,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, && grub_reiserfs_compare_keys (key, &(keys[i])) >= 0; i++) { -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG grub_printf("i %03d/%03d ", i + 1, item_count + 1); grub_reiserfs_print_key (&(keys[i])); #endif @@ -550,7 +550,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, if ((i < item_count) && (key->directory_id == keys[i].directory_id) && (key->object_id == keys[i].object_id)) item->next_offset = grub_reiserfs_get_key_offset(&(keys[i])); -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG if (i == item_count || grub_reiserfs_compare_keys (key, &(keys[i])) == 0) grub_printf(">"); @@ -582,7 +582,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, != 0); i++) { -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG if (key->directory_id == item_headers[i].key.directory_id && \ key->object_id == item_headers[i].key.object_id) grub_printf("C"); @@ -604,8 +604,8 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, { item->block_number = 0; item->block_position = 0; - item->type = GRUB_REISERFS_UNKNOWN; -#ifdef GRUB_REISERFS_DEBUG + item->type = GRUB_REISERzFS_UNKNOWN; +#ifdef GRUB_REISERzFS_DEBUG grub_printf("Not found.\n"); #endif } @@ -616,20 +616,20 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, item->type = grub_reiserfs_get_key_type (block_key); grub_memcpy (&(item->header), &(item_headers[i]), sizeof (struct grub_reiserfs_item_header)); -#ifdef GRUB_REISERFS_DEBUG +#ifdef GRUB_REISERzFS_DEBUG grub_printf ("F %03d/%03d ", i + 1, item_count); grub_reiserfs_print_key (block_key); #endif } - r_warn_if_fail (grub_errno == GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno == GRUB_ERR_NONE); grub_free (block_header); return GRUB_ERR_NONE; fail: - r_warn_if_fail (grub_errno != GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno != GRUB_ERR_NONE); grub_free (block_header); - r_warn_if_fail (grub_errno != GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno != GRUB_ERR_NONE); return grub_errno; } @@ -647,7 +647,7 @@ grub_reiserfs_read_symlink (grub_fshelp_node_t node) grub_memcpy (&key, &(node->header.key), sizeof (key)); grub_reiserfs_set_key_offset (&key, 1); - grub_reiserfs_set_key_type (&key, GRUB_REISERFS_DIRECT, + grub_reiserfs_set_key_type (&key, GRUB_REISERzFS_DIRECT, grub_reiserfs_get_key_version (&key)); if (grub_reiserfs_get_item (node->data, &key, &found) != GRUB_ERR_NONE) @@ -686,12 +686,12 @@ grub_reiserfs_mount (grub_disk_t disk) data = grub_malloc (sizeof (*data)); if (! data) goto fail; - grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE, + grub_disk_read (disk, REISERzFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE, 0, sizeof (data->superblock), &(data->superblock)); if (grub_errno) goto fail; if (grub_memcmp (data->superblock.magic_string, - REISERFS_MAGIC_STRING, sizeof (REISERFS_MAGIC_STRING) - 1)) + REISERzFS_MAGIC_STRING, sizeof (REISERzFS_MAGIC_STRING) - 1)) { grub_error (GRUB_ERR_BAD_FS, "not a ReiserFS filesystem"); goto fail; @@ -724,7 +724,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, grub_uint64_t next_offset = item->next_offset; int ret = 0; - if (item->type != GRUB_REISERFS_DIRECTORY) + if (item->type != GRUB_REISERzFS_DIRECTORY) { grub_error (GRUB_ERR_BAD_FILE_TYPE, "grub_reiserfs_iterate_dir called on a non-directory item"); @@ -778,7 +778,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, grub_uint16_t entry_state = grub_le_to_cpu16 (directory_header->state); - if (entry_state & GRUB_REISERFS_VISIBLE_MASK) + if (entry_state & GRUB_REISERzFS_VISIBLE_MASK) { grub_fshelp_node_t entry_item; struct grub_reiserfs_key entry_key; @@ -790,7 +790,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, entry_key.directory_id = directory_header->directory_id; entry_key.object_id = directory_header->object_id; entry_key.u.v2.offset_type = 0; - grub_reiserfs_set_key_type (&entry_key, GRUB_REISERFS_DIRECTORY, + grub_reiserfs_set_key_type (&entry_key, GRUB_REISERzFS_DIRECTORY, 2); grub_reiserfs_set_key_offset (&entry_key, 1); @@ -805,7 +805,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, goto fail; } - if (entry_item->type == GRUB_REISERFS_DIRECTORY) + if (entry_item->type == GRUB_REISERzFS_DIRECTORY) entry_type = GRUB_FSHELP_DIR; else { @@ -815,7 +815,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, Then change the key type, which affects key version detection. */ grub_reiserfs_set_key_offset (&entry_key, 0); - grub_reiserfs_set_key_type (&entry_key, GRUB_REISERFS_STAT, + grub_reiserfs_set_key_type (&entry_key, GRUB_REISERzFS_STAT, 2); if (grub_reiserfs_get_item (data, &entry_key, entry_item) != GRUB_ERR_NONE) @@ -966,11 +966,11 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, while (block_number); found: - r_warn_if_fail (grub_errno == GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno == GRUB_ERR_NONE); grub_free (block_header); return ret; fail: - r_warn_if_fail (grub_errno != GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno != GRUB_ERR_NONE); grub_free (block_header); return 0; } @@ -996,7 +996,7 @@ grub_reiserfs_open (struct grub_file *file, const char *name) key.directory_id = grub_cpu_to_le32 (1); key.object_id = grub_cpu_to_le32 (2); key.u.v2.offset_type = 0; - grub_reiserfs_set_key_type (&key, GRUB_REISERFS_DIRECTORY, 2); + grub_reiserfs_set_key_type (&key, GRUB_REISERzFS_DIRECTORY, 2); grub_reiserfs_set_key_offset (&key, 1); if (grub_reiserfs_get_item (data, &key, &root) != GRUB_ERR_NONE) goto fail; @@ -1012,7 +1012,7 @@ grub_reiserfs_open (struct grub_file *file, const char *name) goto fail; key.directory_id = found->header.key.directory_id; key.object_id = found->header.key.object_id; - grub_reiserfs_set_key_type (&key, GRUB_REISERFS_STAT, 2); + grub_reiserfs_set_key_type (&key, GRUB_REISERzFS_STAT, 2); grub_reiserfs_set_key_offset (&key, 0); if (grub_reiserfs_get_item (data, &key, &info) != GRUB_ERR_NONE) goto fail; @@ -1058,7 +1058,7 @@ grub_reiserfs_open (struct grub_file *file, const char *name) return GRUB_ERR_NONE; fail: - r_warn_if_fail (grub_errno != GRUB_ERR_NONE); + rz_warn_if_fail (grub_errno != GRUB_ERR_NONE); grub_free (found); grub_free (data); return grub_errno; @@ -1083,7 +1083,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) key.directory_id = node->header.key.directory_id; key.object_id = node->header.key.object_id; key.u.v2.offset_type = 0; - grub_reiserfs_set_key_type (&key, GRUB_REISERFS_ANY, 2); + grub_reiserfs_set_key_type (&key, GRUB_REISERzFS_ANY, 2); initial_position = file->offset; current_position = 0; final_position = MIN (len + initial_position, file->size); @@ -1104,7 +1104,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) item_size = grub_le_to_cpu16 (found.header.item_size); switch (found.type) { - case GRUB_REISERFS_DIRECT: + case GRUB_REISERzFS_DIRECT: block = (grub_disk_addr_t)found.block_number \ * ((grub_disk_addr_t)block_size >> GRUB_DISK_SECTOR_BITS); grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block); @@ -1133,7 +1133,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) else current_position += item_size; break; - case GRUB_REISERFS_INDIRECT: + case GRUB_REISERzFS_INDIRECT: indirect_block_count = item_size / sizeof (*indirect_block_ptr); indirect_block_ptr = grub_malloc (item_size); if (! indirect_block_ptr) @@ -1198,7 +1198,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) #if 0 switch (found.type) { - case GRUB_REISERFS_DIRECT: + case GRUB_REISERzFS_DIRECT: read_length = MIN (len, item_size - file->offset); grub_disk_read (found.data->disk, (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE, @@ -1207,7 +1207,7 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) if (grub_errno) goto fail; break; - case GRUB_REISERFS_INDIRECT: + case GRUB_REISERzFS_INDIRECT: indirect_block_count = item_size / sizeof (*indirect_block_ptr); indirect_block_ptr = grub_malloc (item_size); if (!indirect_block_ptr) @@ -1299,7 +1299,7 @@ grub_reiserfs_dir (grub_device_t device, const char *path, root_key.directory_id = grub_cpu_to_le32 (1); root_key.object_id = grub_cpu_to_le32 (2); root_key.u.v2.offset_type = 0; - grub_reiserfs_set_key_type (&root_key, GRUB_REISERFS_DIRECTORY, 2); + grub_reiserfs_set_key_type (&root_key, GRUB_REISERzFS_DIRECTORY, 2); grub_reiserfs_set_key_offset (&root_key, 1); if (grub_reiserfs_get_item (data, &root_key, &root) != GRUB_ERR_NONE) goto fail; @@ -1329,12 +1329,12 @@ grub_reiserfs_dir (grub_device_t device, const char *path, static grub_err_t grub_reiserfs_label (grub_device_t device, char **label) { - *label = grub_malloc (REISERFS_MAX_LABEL_LENGTH); + *label = grub_malloc (REISERzFS_MAX_LABEL_LENGTH); if (*label) { grub_disk_read (device->disk, - REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE, - REISERFS_LABEL_OFFSET, REISERFS_MAX_LABEL_LENGTH, + REISERzFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE, + REISERzFS_LABEL_OFFSET, REISERzFS_MAX_LABEL_LENGTH, *label); } return grub_errno; diff --git a/shlr/grub/fs/sfs.c b/shlr/grub/fs/sfs.c index adc03e0754..4d01ac3e86 100644 --- a/shlr/grub/fs/sfs.c +++ b/shlr/grub/fs/sfs.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include /* The common header for a block. */ R_PACKED ( struct grub_sfs_bheader diff --git a/shlr/grub/fs/udf.c b/shlr/grub/fs/udf.c index cf583b0fb3..f6c728d471 100644 --- a/shlr/grub/fs/udf.c +++ b/shlr/grub/fs/udf.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #define GRUB_UDF_MAX_PDS 2 #define GRUB_UDF_MAX_PMS 6 diff --git a/shlr/grub/fs/ufs.c b/shlr/grub/fs/ufs.c index bdd91a8b7b..0cbd3b0aff 100644 --- a/shlr/grub/fs/ufs.c +++ b/shlr/grub/fs/ufs.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #ifdef MODE_UFS2 #define GRUB_UFS_MAGIC 0x19540119 diff --git a/shlr/grub/fs/xfs.c b/shlr/grub/fs/xfs.c index d7b3a2a3df..ba9655c09e 100644 --- a/shlr/grub/fs/xfs.c +++ b/shlr/grub/fs/xfs.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define XFS_INODE_EXTENTS 9 diff --git a/shlr/grub/grubfs.c b/shlr/grub/grubfs.c index 90844371e3..aa4fd348c7 100644 --- a/shlr/grub/grubfs.c +++ b/shlr/grub/grubfs.c @@ -1,13 +1,13 @@ /* radare - LGPL - Copyright 2011-2017 pancake */ -#include -#include +#include +#include #include "grubfs.h" #include #include -static RIOBind *bio = NULL; +static RzIOBind *bio = NULL; static ut64 delta = 0; static void* empty (int sz) { @@ -22,7 +22,7 @@ static grub_err_t read_foo (struct grub_disk *disk, grub_disk_addr_t sector, gru return 1; } const int blocksize = 512; // TODO unhardcode 512 - RIOBind *iob = disk->data; + RzIOBind *iob = disk->data; if (bio) { iob = bio; } @@ -64,7 +64,7 @@ void grubfs_free (GrubFS *gf) { } } -void grubfs_bind_io (RIOBind *iob, ut64 _delta) { +void grubfs_bind_io (RzIOBind *iob, ut64 _delta) { bio = iob; delta = _delta; } diff --git a/shlr/grub/include/grub/bsdlabel.h b/shlr/grub/include/grub/bsdlabel.h index bdd03f7958..31f6309ea1 100644 --- a/shlr/grub/include/grub/bsdlabel.h +++ b/shlr/grub/include/grub/bsdlabel.h @@ -62,7 +62,7 @@ #define GRUB_PC_PARTITION_OPENBSD_TYPE_EXT2FS 17 #define GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS 18 #define GRUB_PC_PARTITION_OPENBSD_TYPE_RAID 19 -#include +#include /* The BSD partition entry. */ R_PACKED( struct grub_partition_bsd_entry diff --git a/shlr/grub/include/grub/fbfs.h b/shlr/grub/include/grub/fbfs.h index 60eb319f33..bce4736c38 100644 --- a/shlr/grub/include/grub/fbfs.h +++ b/shlr/grub/include/grub/fbfs.h @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with BURG. If not, see . */ -#include +#include #ifndef GRUB_FBFS_H #define GRUB_FBFS_H 1 diff --git a/shlr/grub/include/grub/hfs.h b/shlr/grub/include/grub/hfs.h index 4ee30dccbe..04510d9fde 100644 --- a/shlr/grub/include/grub/hfs.h +++ b/shlr/grub/include/grub/hfs.h @@ -20,7 +20,7 @@ #define GRUB_HFS_HEADER 1 #include -#include +#include #define GRUB_HFS_MAGIC 0x4244 diff --git a/shlr/grub/include/grub/list.h b/shlr/grub/include/grub/list.h index 23b86edab0..0b759f89a8 100644 --- a/shlr/grub/include/grub/list.h +++ b/shlr/grub/include/grub/list.h @@ -87,8 +87,8 @@ void * grub_named_list_find (grub_named_list_t head, GRUB_FIELD_MATCH (*pptr, grub_named_list_t, name))? \ (grub_named_list_t *) (void *) pptr : grub_bad_type_cast ()) -#define GRUB_PRIO_LIST_PRIO_MASK 0xff -#define GRUB_PRIO_LIST_FLAG_ACTIVE 0x100 +#define GRUB_PRzIO_LIST_PRzIO_MASK 0xff +#define GRUB_PRzIO_LIST_FLAG_ACTIVE 0x100 struct grub_prio_list { @@ -104,18 +104,18 @@ void grub_prio_list_insert (grub_prio_list_t *head, static inline void grub_prio_list_remove (grub_prio_list_t *head, grub_prio_list_t item) { - if ((item->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (item->next)) - item->next->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE; + if ((item->prio & GRUB_PRzIO_LIST_FLAG_ACTIVE) && (item->next)) + item->next->prio |= GRUB_PRzIO_LIST_FLAG_ACTIVE; grub_list_remove (GRUB_AS_LIST_P (head), GRUB_AS_LIST (item)); } -#define GRUB_AS_PRIO_LIST(ptr) \ +#define GRUB_AS_PRzIO_LIST(ptr) \ ((GRUB_FIELD_MATCH (ptr, grub_prio_list_t, next) && \ GRUB_FIELD_MATCH (ptr, grub_prio_list_t, name) && \ GRUB_FIELD_MATCH (ptr, grub_prio_list_t, prio))? \ (grub_prio_list_t) ptr : grub_bad_type_cast ()) -#define GRUB_AS_PRIO_LIST_P(pptr) \ +#define GRUB_AS_PRzIO_LIST_P(pptr) \ ((GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, next) && \ GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, name) && \ GRUB_FIELD_MATCH (*pptr, grub_prio_list_t, prio))? \ diff --git a/shlr/grub/include/grub/loader.h b/shlr/grub/include/grub/loader.h index 319f3c551f..c985a87bd6 100644 --- a/shlr/grub/include/grub/loader.h +++ b/shlr/grub/include/grub/loader.h @@ -45,14 +45,14 @@ grub_err_t grub_loader_boot (void); values even if external modules use them. */ typedef enum { /* A preboot hook which can use everything and turns nothing off. */ - GRUB_LOADER_PREBOOT_HOOK_PRIO_NORMAL = 400, + GRUB_LOADER_PREBOOT_HOOK_PRzIO_NORMAL = 400, /* A preboot hook which can't use disks and may stop disks. */ - GRUB_LOADER_PREBOOT_HOOK_PRIO_DISK = 300, + GRUB_LOADER_PREBOOT_HOOK_PRzIO_DISK = 300, /* A preboot hook which can't use disks or console and may stop console. */ - GRUB_LOADER_PREBOOT_HOOK_PRIO_CONSOLE = 200, + GRUB_LOADER_PREBOOT_HOOK_PRzIO_CONSOLE = 200, /* A preboot hook which can't use disks or console, can't modify memory map and may stop memory services or finalize memory map. */ - GRUB_LOADER_PREBOOT_HOOK_PRIO_MEMORY = 100, + GRUB_LOADER_PREBOOT_HOOK_PRzIO_MEMORY = 100, } grub_loader_preboot_hook_prio_t; /* Register a preboot hook. */ diff --git a/shlr/grub/include/grub/msdos_partition.h b/shlr/grub/include/grub/msdos_partition.h index 37a6203ae7..b58fd33c1b 100644 --- a/shlr/grub/include/grub/msdos_partition.h +++ b/shlr/grub/include/grub/msdos_partition.h @@ -22,7 +22,7 @@ #include #include #include -#include "r_types.h" +#include "rz_types.h" /* The signature. */ #define GRUB_PC_PARTITION_SIGNATURE 0xaa55 diff --git a/shlr/grub/include/grub/ntfs.h b/shlr/grub/include/grub/ntfs.h index d8872fd23b..70f129c0b3 100644 --- a/shlr/grub/include/grub/ntfs.h +++ b/shlr/grub/include/grub/ntfs.h @@ -18,7 +18,7 @@ */ #ifndef GRUB_NTFS_H -#include +#include #define GRUB_NTFS_H 1 #define FILE_MFT 0 diff --git a/shlr/grub/include/grubfs.h b/shlr/grub/include/grubfs.h index 96671785d4..e1741e33f8 100644 --- a/shlr/grub/include/grubfs.h +++ b/shlr/grub/include/grubfs.h @@ -2,7 +2,7 @@ #define _INCLUDE_GRUBFS_H_ extern unsigned long long grub_hack_lastoff; -#include +#include #include #include #include @@ -13,7 +13,7 @@ typedef struct grubfs { GrubFS *grubfs_new (struct grub_fs *myfs, void *data); void grubfs_free (GrubFS *gf); -void grubfs_bind_io (RIOBind *iob, ut64 _delta); +void grubfs_bind_io (RzIOBind *iob, ut64 _delta); grub_disk_t grubfs_disk (void *data); void grubfs_disk_free (struct grub_disk *gd); diff --git a/shlr/grub/kern/list.c b/shlr/grub/kern/list.c index b9e274e549..f863d8d31b 100644 --- a/shlr/grub/kern/list.c +++ b/shlr/grub/kern/list.c @@ -117,9 +117,9 @@ grub_prio_list_insert_test (grub_prio_list_t new_item, grub_prio_list_t item, if (r) return (r < 0); - if (new_item->prio >= (item->prio & GRUB_PRIO_LIST_PRIO_MASK)) + if (new_item->prio >= (item->prio & GRUB_PRzIO_LIST_PRzIO_MASK)) { - item->prio &= ~GRUB_PRIO_LIST_FLAG_ACTIVE; + item->prio &= ~GRUB_PRzIO_LIST_FLAG_ACTIVE; return 1; } @@ -136,5 +136,5 @@ grub_prio_list_insert (grub_prio_list_t *head, grub_prio_list_t nitem) grub_list_insert (GRUB_AS_LIST_P (head), GRUB_AS_LIST (nitem), (grub_list_test_t) grub_prio_list_insert_test, &c); if (! c.inactive) - nitem->prio |= GRUB_PRIO_LIST_FLAG_ACTIVE; + nitem->prio |= GRUB_PRzIO_LIST_FLAG_ACTIVE; } diff --git a/shlr/grub/partmap/amiga.c b/shlr/grub/partmap/amiga.c index 3e36c98e8e..1da3bcec5c 100644 --- a/shlr/grub/partmap/amiga.c +++ b/shlr/grub/partmap/amiga.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include R_PACKED( struct grub_amiga_rdsk { diff --git a/shlr/grub/partmap/gpt.c b/shlr/grub/partmap/gpt.c index cf9f031d32..e8f9569097 100644 --- a/shlr/grub/partmap/gpt.c +++ b/shlr/grub/partmap/gpt.c @@ -17,7 +17,7 @@ * along with GRUB. If not, see . */ -#include +#include #include #include #include diff --git a/shlr/grub/partmap/msdos.c b/shlr/grub/partmap/msdos.c index a94067912a..bf520c5e47 100644 --- a/shlr/grub/partmap/msdos.c +++ b/shlr/grub/partmap/msdos.c @@ -17,7 +17,7 @@ * along with GRUB. If not, see . */ -#include +#include #include #include #include diff --git a/shlr/grub/partmap/sun.c b/shlr/grub/partmap/sun.c index f4d137634d..e13ef54720 100644 --- a/shlr/grub/partmap/sun.c +++ b/shlr/grub/partmap/sun.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define GRUB_PARTMAP_SUN_MAGIC 0xDABE #define GRUB_PARTMAP_SUN_MAX_PARTS 8 diff --git a/shlr/grub/partmap/sunpc.c b/shlr/grub/partmap/sunpc.c index 5ae34d0655..07d76741e6 100644 --- a/shlr/grub/partmap/sunpc.c +++ b/shlr/grub/partmap/sunpc.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #define GRUB_PARTMAP_SUN_PC_MAGIC 0xDABE #define GRUB_PARTMAP_SUN_PC_MAX_PARTS 16 diff --git a/shlr/heap/README.md b/shlr/heap/README.md index 5eab5bfa7b..05152f59a7 100644 --- a/shlr/heap/README.md +++ b/shlr/heap/README.md @@ -1,4 +1,4 @@ -Trying to escape from the libr/core mess, we should put all the heap stuff into a separate place and use it from anal/heap.c +Trying to escape from the librz/core mess, we should put all the heap stuff into a separate place and use it from anal/heap.c TODO diff --git a/shlr/heap/include/r_jemalloc/internal/arena.h b/shlr/heap/include/rz_jemalloc/internal/arena.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/arena.h rename to shlr/heap/include/rz_jemalloc/internal/arena.h diff --git a/shlr/heap/include/r_jemalloc/internal/assert.h b/shlr/heap/include/rz_jemalloc/internal/assert.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/assert.h rename to shlr/heap/include/rz_jemalloc/internal/assert.h diff --git a/shlr/heap/include/r_jemalloc/internal/atomic.h b/shlr/heap/include/rz_jemalloc/internal/atomic.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/atomic.h rename to shlr/heap/include/rz_jemalloc/internal/atomic.h diff --git a/shlr/heap/include/r_jemalloc/internal/base.h b/shlr/heap/include/rz_jemalloc/internal/base.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/base.h rename to shlr/heap/include/rz_jemalloc/internal/base.h diff --git a/shlr/heap/include/r_jemalloc/internal/bitmap.h b/shlr/heap/include/rz_jemalloc/internal/bitmap.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/bitmap.h rename to shlr/heap/include/rz_jemalloc/internal/bitmap.h diff --git a/shlr/heap/include/r_jemalloc/internal/chunk.h b/shlr/heap/include/rz_jemalloc/internal/chunk.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/chunk.h rename to shlr/heap/include/rz_jemalloc/internal/chunk.h diff --git a/shlr/heap/include/r_jemalloc/internal/chunk_dss.h b/shlr/heap/include/rz_jemalloc/internal/chunk_dss.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/chunk_dss.h rename to shlr/heap/include/rz_jemalloc/internal/chunk_dss.h diff --git a/shlr/heap/include/r_jemalloc/internal/chunk_mmap.h b/shlr/heap/include/rz_jemalloc/internal/chunk_mmap.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/chunk_mmap.h rename to shlr/heap/include/rz_jemalloc/internal/chunk_mmap.h diff --git a/shlr/heap/include/r_jemalloc/internal/ckh.h b/shlr/heap/include/rz_jemalloc/internal/ckh.h similarity index 95% rename from shlr/heap/include/r_jemalloc/internal/ckh.h rename to shlr/heap/include/rz_jemalloc/internal/ckh.h index f75ad90b73..441069a592 100644 --- a/shlr/heap/include/r_jemalloc/internal/ckh.h +++ b/shlr/heap/include/rz_jemalloc/internal/ckh.h @@ -73,9 +73,9 @@ bool ckh_insert(tsd_t *tsd, ckh_t *ckh, const void *key, const void *data); bool ckh_remove(tsd_t *tsd, ckh_t *ckh, const void *searchkey, void **key, void **data); bool ckh_search(ckh_t *ckh, const void *searchkey, void **key, void **data); -void ckh_string_hash(const void *key, size_t r_hash[2]); +void ckh_string_hash(const void *key, size_t rz_hash[2]); bool ckh_string_keycomp(const void *k1, const void *k2); -void ckh_pointer_hash(const void *key, size_t r_hash[2]); +void ckh_pointer_hash(const void *key, size_t rz_hash[2]); bool ckh_pointer_keycomp(const void *k1, const void *k2); #endif /* JEMALLOC_H_EXTERNS */ diff --git a/shlr/heap/include/r_jemalloc/internal/ctl.h b/shlr/heap/include/rz_jemalloc/internal/ctl.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/ctl.h rename to shlr/heap/include/rz_jemalloc/internal/ctl.h diff --git a/shlr/heap/include/r_jemalloc/internal/extent.h b/shlr/heap/include/rz_jemalloc/internal/extent.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/extent.h rename to shlr/heap/include/rz_jemalloc/internal/extent.h diff --git a/shlr/heap/include/r_jemalloc/internal/hash.h b/shlr/heap/include/rz_jemalloc/internal/hash.h similarity index 94% rename from shlr/heap/include/r_jemalloc/internal/hash.h rename to shlr/heap/include/rz_jemalloc/internal/hash.h index 1ff2d9a05f..8bd7f324c6 100644 --- a/shlr/heap/include/r_jemalloc/internal/hash.h +++ b/shlr/heap/include/rz_jemalloc/internal/hash.h @@ -21,11 +21,11 @@ #ifndef JEMALLOC_ENABLE_INLINE uint32_t hash_x86_32(const void *key, int len, uint32_t seed); void hash_x86_128(const void *key, const int len, uint32_t seed, - uint64_t r_out[2]); + uint64_t rz_out[2]); void hash_x64_128(const void *key, const int len, const uint32_t seed, - uint64_t r_out[2]); + uint64_t rz_out[2]); void hash(const void *key, size_t len, const uint32_t seed, - size_t r_hash[2]); + size_t rz_hash[2]); #endif #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_HASH_C_)) @@ -154,7 +154,7 @@ hash_x86_32(const void *key, int len, uint32_t seed) UNUSED JEMALLOC_INLINE void hash_x86_128(const void *key, const int len, uint32_t seed, - uint64_t r_out[2]) + uint64_t rz_out[2]) { const uint8_t * data = (const uint8_t *) key; const int nblocks = len / 16; @@ -250,13 +250,13 @@ hash_x86_128(const void *key, const int len, uint32_t seed, h1 += h2; h1 += h3; h1 += h4; h2 += h1; h3 += h1; h4 += h1; - r_out[0] = (((uint64_t) h2) << 32) | h1; - r_out[1] = (((uint64_t) h4) << 32) | h3; + rz_out[0] = (((uint64_t) h2) << 32) | h1; + rz_out[1] = (((uint64_t) h4) << 32) | h3; } UNUSED JEMALLOC_INLINE void hash_x64_128(const void *key, const int len, const uint32_t seed, - uint64_t r_out[2]) + uint64_t rz_out[2]) { const uint8_t *data = (const uint8_t *) key; const int nblocks = len / 16; @@ -328,26 +328,26 @@ hash_x64_128(const void *key, const int len, const uint32_t seed, h1 += h2; h2 += h1; - r_out[0] = h1; - r_out[1] = h2; + rz_out[0] = h1; + rz_out[1] = h2; } /******************************************************************************/ /* API. */ JEMALLOC_INLINE void -hash(const void *key, size_t len, const uint32_t seed, size_t r_hash[2]) +hash(const void *key, size_t len, const uint32_t seed, size_t rz_hash[2]) { assert(len <= INT_MAX); /* Unfortunate implementation limitation. */ #if (LG_SIZEOF_PTR == 3 && !defined(JEMALLOC_BIG_ENDIAN)) - hash_x64_128(key, (int)len, seed, (uint64_t *)r_hash); + hash_x64_128(key, (int)len, seed, (uint64_t *)rz_hash); #else { uint64_t hashes[2]; hash_x86_128(key, (int)len, seed, hashes); - r_hash[0] = (size_t)hashes[0]; - r_hash[1] = (size_t)hashes[1]; + rz_hash[0] = (size_t)hashes[0]; + rz_hash[1] = (size_t)hashes[1]; } #endif } diff --git a/shlr/heap/include/r_jemalloc/internal/huge.h b/shlr/heap/include/rz_jemalloc/internal/huge.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/huge.h rename to shlr/heap/include/rz_jemalloc/internal/huge.h diff --git a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal.h b/shlr/heap/include/rz_jemalloc/internal/jemalloc_internal.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/jemalloc_internal.h rename to shlr/heap/include/rz_jemalloc/internal/jemalloc_internal.h diff --git a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h b/shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_decls.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/jemalloc_internal_decls.h rename to shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_decls.h diff --git a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_defs.h b/shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_defs.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/jemalloc_internal_defs.h rename to shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_defs.h diff --git a/shlr/heap/include/r_jemalloc/internal/jemalloc_internal_macros.h b/shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_macros.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/jemalloc_internal_macros.h rename to shlr/heap/include/rz_jemalloc/internal/jemalloc_internal_macros.h diff --git a/shlr/heap/include/r_jemalloc/internal/mb.h b/shlr/heap/include/rz_jemalloc/internal/mb.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/mb.h rename to shlr/heap/include/rz_jemalloc/internal/mb.h diff --git a/shlr/heap/include/r_jemalloc/internal/msvc_compat/windows_extra.h b/shlr/heap/include/rz_jemalloc/internal/msvc_compat/windows_extra.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/msvc_compat/windows_extra.h rename to shlr/heap/include/rz_jemalloc/internal/msvc_compat/windows_extra.h diff --git a/shlr/heap/include/r_jemalloc/internal/mutex.h b/shlr/heap/include/rz_jemalloc/internal/mutex.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/mutex.h rename to shlr/heap/include/rz_jemalloc/internal/mutex.h diff --git a/shlr/heap/include/r_jemalloc/internal/nstime.h b/shlr/heap/include/rz_jemalloc/internal/nstime.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/nstime.h rename to shlr/heap/include/rz_jemalloc/internal/nstime.h diff --git a/shlr/heap/include/r_jemalloc/internal/pages.h b/shlr/heap/include/rz_jemalloc/internal/pages.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/pages.h rename to shlr/heap/include/rz_jemalloc/internal/pages.h diff --git a/shlr/heap/include/r_jemalloc/internal/ph.h b/shlr/heap/include/rz_jemalloc/internal/ph.h similarity index 96% rename from shlr/heap/include/r_jemalloc/internal/ph.h rename to shlr/heap/include/rz_jemalloc/internal/ph.h index 4f91c333fd..ad419f9c1e 100644 --- a/shlr/heap/include/r_jemalloc/internal/ph.h +++ b/shlr/heap/include/rz_jemalloc/internal/ph.h @@ -63,23 +63,23 @@ struct { \ phn_lchild_set(a_type, a_field, a_phn0, a_phn1); \ } while (0) -#define phn_merge(a_type, a_field, a_phn0, a_phn1, a_cmp, r_phn) do { \ +#define phn_merge(a_type, a_field, a_phn0, a_phn1, a_cmp, rz_phn) do { \ if (a_phn0 == NULL) \ - r_phn = a_phn1; \ + rz_phn = a_phn1; \ else if (a_phn1 == NULL) \ - r_phn = a_phn0; \ + rz_phn = a_phn0; \ else if (a_cmp(a_phn0, a_phn1) < 0) { \ phn_merge_ordered(a_type, a_field, a_phn0, a_phn1, \ a_cmp); \ - r_phn = a_phn0; \ + rz_phn = a_phn0; \ } else { \ phn_merge_ordered(a_type, a_field, a_phn1, a_phn0, \ a_cmp); \ - r_phn = a_phn1; \ + rz_phn = a_phn1; \ } \ } while (0) -#define ph_merge_siblings(a_type, a_field, a_phn, a_cmp, r_phn) do { \ +#define ph_merge_siblings(a_type, a_field, a_phn, a_cmp, rz_phn) do { \ a_type *head = NULL; \ a_type *tail = NULL; \ a_type *phn0 = a_phn; \ @@ -161,7 +161,7 @@ struct { \ } \ } \ } \ - r_phn = phn0; \ + rz_phn = phn0; \ } while (0) #define ph_merge_aux(a_type, a_field, a_ph, a_cmp) do { \ @@ -177,13 +177,13 @@ struct { \ } \ } while (0) -#define ph_merge_children(a_type, a_field, a_phn, a_cmp, r_phn) do { \ +#define ph_merge_children(a_type, a_field, a_phn, a_cmp, rz_phn) do { \ a_type *lchild = phn_lchild_get(a_type, a_field, a_phn); \ if (lchild == NULL) \ - r_phn = NULL; \ + rz_phn = NULL; \ else { \ ph_merge_siblings(a_type, a_field, lchild, a_cmp, \ - r_phn); \ + rz_phn); \ } \ } while (0) diff --git a/shlr/heap/include/r_jemalloc/internal/private_namespace.h b/shlr/heap/include/rz_jemalloc/internal/private_namespace.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/private_namespace.h rename to shlr/heap/include/rz_jemalloc/internal/private_namespace.h diff --git a/shlr/heap/include/r_jemalloc/internal/private_unnamespace.h b/shlr/heap/include/rz_jemalloc/internal/private_unnamespace.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/private_unnamespace.h rename to shlr/heap/include/rz_jemalloc/internal/private_unnamespace.h diff --git a/shlr/heap/include/r_jemalloc/internal/prng.h b/shlr/heap/include/rz_jemalloc/internal/prng.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/prng.h rename to shlr/heap/include/rz_jemalloc/internal/prng.h diff --git a/shlr/heap/include/r_jemalloc/internal/prof.h b/shlr/heap/include/rz_jemalloc/internal/prof.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/prof.h rename to shlr/heap/include/rz_jemalloc/internal/prof.h diff --git a/shlr/heap/include/r_jemalloc/internal/public_namespace.h b/shlr/heap/include/rz_jemalloc/internal/public_namespace.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/public_namespace.h rename to shlr/heap/include/rz_jemalloc/internal/public_namespace.h diff --git a/shlr/heap/include/r_jemalloc/internal/public_unnamespace.h b/shlr/heap/include/rz_jemalloc/internal/public_unnamespace.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/public_unnamespace.h rename to shlr/heap/include/rz_jemalloc/internal/public_unnamespace.h diff --git a/shlr/heap/include/r_jemalloc/internal/ql.h b/shlr/heap/include/rz_jemalloc/internal/ql.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/ql.h rename to shlr/heap/include/rz_jemalloc/internal/ql.h diff --git a/shlr/heap/include/r_jemalloc/internal/qr.h b/shlr/heap/include/rz_jemalloc/internal/qr.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/qr.h rename to shlr/heap/include/rz_jemalloc/internal/qr.h diff --git a/shlr/heap/include/r_jemalloc/internal/quarantine.h b/shlr/heap/include/rz_jemalloc/internal/quarantine.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/quarantine.h rename to shlr/heap/include/rz_jemalloc/internal/quarantine.h diff --git a/shlr/heap/include/r_jemalloc/internal/rb.h b/shlr/heap/include/rz_jemalloc/internal/rb.h similarity index 97% rename from shlr/heap/include/r_jemalloc/internal/rb.h rename to shlr/heap/include/rz_jemalloc/internal/rb.h index 8631bb5e36..5a79adaf8a 100644 --- a/shlr/heap/include/r_jemalloc/internal/rb.h +++ b/shlr/heap/include/rz_jemalloc/internal/rb.h @@ -122,37 +122,37 @@ struct { \ } while (0) /* Internal utility macros. */ -#define rbtn_first(a_type, a_field, a_rbt, a_root, r_node) do { \ - (r_node) = (a_root); \ - if ((r_node) != NULL) { \ +#define rbtn_first(a_type, a_field, a_rbt, a_root, rz_node) do { \ + (rz_node) = (a_root); \ + if ((rz_node) != NULL) { \ for (; \ - rbtn_left_get(a_type, a_field, (r_node)) != NULL; \ - (r_node) = rbtn_left_get(a_type, a_field, (r_node))) { \ + rbtn_left_get(a_type, a_field, (rz_node)) != NULL; \ + (rz_node) = rbtn_left_get(a_type, a_field, (rz_node))) { \ } \ } \ } while (0) -#define rbtn_last(a_type, a_field, a_rbt, a_root, r_node) do { \ - (r_node) = (a_root); \ - if ((r_node) != NULL) { \ - for (; rbtn_right_get(a_type, a_field, (r_node)) != NULL; \ - (r_node) = rbtn_right_get(a_type, a_field, (r_node))) { \ +#define rbtn_last(a_type, a_field, a_rbt, a_root, rz_node) do { \ + (rz_node) = (a_root); \ + if ((rz_node) != NULL) { \ + for (; rbtn_right_get(a_type, a_field, (rz_node)) != NULL; \ + (rz_node) = rbtn_right_get(a_type, a_field, (rz_node))) { \ } \ } \ } while (0) -#define rbtn_rotate_left(a_type, a_field, a_node, r_node) do { \ - (r_node) = rbtn_right_get(a_type, a_field, (a_node)); \ +#define rbtn_rotate_left(a_type, a_field, a_node, rz_node) do { \ + (rz_node) = rbtn_right_get(a_type, a_field, (a_node)); \ rbtn_right_set(a_type, a_field, (a_node), \ - rbtn_left_get(a_type, a_field, (r_node))); \ - rbtn_left_set(a_type, a_field, (r_node), (a_node)); \ + rbtn_left_get(a_type, a_field, (rz_node))); \ + rbtn_left_set(a_type, a_field, (rz_node), (a_node)); \ } while (0) -#define rbtn_rotate_right(a_type, a_field, a_node, r_node) do { \ - (r_node) = rbtn_left_get(a_type, a_field, (a_node)); \ +#define rbtn_rotate_right(a_type, a_field, a_node, rz_node) do { \ + (rz_node) = rbtn_left_get(a_type, a_field, (a_node)); \ rbtn_left_set(a_type, a_field, (a_node), \ - rbtn_right_get(a_type, a_field, (r_node))); \ - rbtn_right_set(a_type, a_field, (r_node), (a_node)); \ + rbtn_right_get(a_type, a_field, (rz_node))); \ + rbtn_right_set(a_type, a_field, (rz_node), (a_node)); \ } while (0) /* diff --git a/shlr/heap/include/r_jemalloc/internal/rtree.h b/shlr/heap/include/rz_jemalloc/internal/rtree.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/rtree.h rename to shlr/heap/include/rz_jemalloc/internal/rtree.h diff --git a/shlr/heap/include/r_jemalloc/internal/size_classes.h b/shlr/heap/include/rz_jemalloc/internal/size_classes.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/size_classes.h rename to shlr/heap/include/rz_jemalloc/internal/size_classes.h diff --git a/shlr/heap/include/r_jemalloc/internal/smoothstep.h b/shlr/heap/include/rz_jemalloc/internal/smoothstep.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/smoothstep.h rename to shlr/heap/include/rz_jemalloc/internal/smoothstep.h diff --git a/shlr/heap/include/r_jemalloc/internal/spin.h b/shlr/heap/include/rz_jemalloc/internal/spin.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/spin.h rename to shlr/heap/include/rz_jemalloc/internal/spin.h diff --git a/shlr/heap/include/r_jemalloc/internal/stats.h b/shlr/heap/include/rz_jemalloc/internal/stats.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/stats.h rename to shlr/heap/include/rz_jemalloc/internal/stats.h diff --git a/shlr/heap/include/r_jemalloc/internal/tcache.h b/shlr/heap/include/rz_jemalloc/internal/tcache.h similarity index 99% rename from shlr/heap/include/r_jemalloc/internal/tcache.h rename to shlr/heap/include/rz_jemalloc/internal/tcache.h index 37805a92eb..1a2bf23a28 100644 --- a/shlr/heap/include/r_jemalloc/internal/tcache.h +++ b/shlr/heap/include/rz_jemalloc/internal/tcache.h @@ -145,7 +145,7 @@ tcache_t *tcache_create(tsdn_t *tsdn, arena_t *arena); void tcache_cleanup(tsd_t *tsd); void tcache_enabled_cleanup(tsd_t *tsd); void tcache_stats_merge(tsdn_t *tsdn, tcache_t *tcache, arena_t *arena); -bool tcaches_create(tsd_t *tsd, unsigned *r_ind); +bool tcaches_create(tsd_t *tsd, unsigned *rz_ind); void tcaches_flush(tsd_t *tsd, unsigned ind); void tcaches_destroy(tsd_t *tsd, unsigned ind); bool tcache_boot(tsdn_t *tsdn); diff --git a/shlr/heap/include/r_jemalloc/internal/ticker.h b/shlr/heap/include/rz_jemalloc/internal/ticker.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/ticker.h rename to shlr/heap/include/rz_jemalloc/internal/ticker.h diff --git a/shlr/heap/include/r_jemalloc/internal/tsd.h b/shlr/heap/include/rz_jemalloc/internal/tsd.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/tsd.h rename to shlr/heap/include/rz_jemalloc/internal/tsd.h diff --git a/shlr/heap/include/r_jemalloc/internal/util.h b/shlr/heap/include/rz_jemalloc/internal/util.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/util.h rename to shlr/heap/include/rz_jemalloc/internal/util.h diff --git a/shlr/heap/include/r_jemalloc/internal/valgrind.h b/shlr/heap/include/rz_jemalloc/internal/valgrind.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/valgrind.h rename to shlr/heap/include/rz_jemalloc/internal/valgrind.h diff --git a/shlr/heap/include/r_jemalloc/internal/witness.h b/shlr/heap/include/rz_jemalloc/internal/witness.h similarity index 100% rename from shlr/heap/include/r_jemalloc/internal/witness.h rename to shlr/heap/include/rz_jemalloc/internal/witness.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc.h b/shlr/heap/include/rz_jemalloc/jemalloc.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc.h rename to shlr/heap/include/rz_jemalloc/jemalloc.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_defs.h b/shlr/heap/include/rz_jemalloc/jemalloc_defs.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_defs.h rename to shlr/heap/include/rz_jemalloc/jemalloc_defs.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_macros.h b/shlr/heap/include/rz_jemalloc/jemalloc_macros.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_macros.h rename to shlr/heap/include/rz_jemalloc/jemalloc_macros.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_macros.h.in b/shlr/heap/include/rz_jemalloc/jemalloc_macros.h.in similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_macros.h.in rename to shlr/heap/include/rz_jemalloc/jemalloc_macros.h.in diff --git a/shlr/heap/include/r_jemalloc/jemalloc_mangle.h b/shlr/heap/include/rz_jemalloc/jemalloc_mangle.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_mangle.h rename to shlr/heap/include/rz_jemalloc/jemalloc_mangle.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_mangle_jet.h b/shlr/heap/include/rz_jemalloc/jemalloc_mangle_jet.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_mangle_jet.h rename to shlr/heap/include/rz_jemalloc/jemalloc_mangle_jet.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_protos.h b/shlr/heap/include/rz_jemalloc/jemalloc_protos.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_protos.h rename to shlr/heap/include/rz_jemalloc/jemalloc_protos.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_protos.h.in b/shlr/heap/include/rz_jemalloc/jemalloc_protos.h.in similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_protos.h.in rename to shlr/heap/include/rz_jemalloc/jemalloc_protos.h.in diff --git a/shlr/heap/include/r_jemalloc/jemalloc_protos_jet.h b/shlr/heap/include/rz_jemalloc/jemalloc_protos_jet.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_protos_jet.h rename to shlr/heap/include/rz_jemalloc/jemalloc_protos_jet.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_rename.h b/shlr/heap/include/rz_jemalloc/jemalloc_rename.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_rename.h rename to shlr/heap/include/rz_jemalloc/jemalloc_rename.h diff --git a/shlr/heap/include/r_jemalloc/jemalloc_typedefs.h b/shlr/heap/include/rz_jemalloc/jemalloc_typedefs.h similarity index 100% rename from shlr/heap/include/r_jemalloc/jemalloc_typedefs.h rename to shlr/heap/include/rz_jemalloc/jemalloc_typedefs.h diff --git a/shlr/heap/include/r_windows/windows_heap.h b/shlr/heap/include/rz_windows/windows_heap.h similarity index 99% rename from shlr/heap/include/r_windows/windows_heap.h rename to shlr/heap/include/rz_windows/windows_heap.h index 31bed7e867..6861e76076 100644 --- a/shlr/heap/include/r_windows/windows_heap.h +++ b/shlr/heap/include/rz_windows/windows_heap.h @@ -700,7 +700,7 @@ typedef struct _HEAP { UINT8 _PADDING2_[4]; #endif PHEAP_TAG_ENTRY TagEntries; - LIST_ENTRY UCRList; + LIST_ENTRY UCRzList; WPARAM AlignRound; WPARAM AlignMask; LIST_ENTRY VirtualAllocdBlocks; diff --git a/shlr/java/Makefile b/shlr/java/Makefile index 79831d1a58..984e9b513c 100644 --- a/shlr/java/Makefile +++ b/shlr/java/Makefile @@ -1,13 +1,13 @@ -NAME=r_java +NAME=rz_java ifeq ($(CC),cccl) EXT_AR=lib else EXT_AR=a endif -LIBAR?=libr_java.$(EXT_AR) +LIBAR?=librz_java.$(EXT_AR) include ../../config-user.mk -include ../../libr/config.mk +include ../../librz/config.mk include ../../global.mk include ../../mk/platform.mk _INCLUDE_MK_GCC_= @@ -28,25 +28,25 @@ CFLAGS+=-DMINGW32=1 endif CFLAGS+=-g -CFLAGS+=-I../../libr/include -LDFLAGS+=-L../../libr/util +CFLAGS+=-I../../librz/include +LDFLAGS+=-L../../librz/util OBJS=code.o class.o ops.o dsojson.o include ../../shlr/sdb.mk -all: libr_java.$(EXT_AR) +all: librz_java.$(EXT_AR) RANLIB?=ranlib -libr_java.$(EXT_AR): ${OBJS} - rm -f libr_java.$(EXT_AR) +librz_java.$(EXT_AR): ${OBJS} + rm -f librz_java.$(EXT_AR) ${CC_AR} ${OBJS} - ${RANLIB} libr_java.$(EXT_AR) + ${RANLIB} librz_java.$(EXT_AR) out: ${OBJS} main.o echo "COMPILER: ${COMPILER} ${CC}" ${CC} ${LDFLAGS} ${CFLAGS} -I. ${OBJS} main.o \ - -lr_util ../sdb/src/libsdb.$(EXT_AR) ${LINK} -o out + -lrz_util ../sdb/src/libsdb.$(EXT_AR) ${LINK} -o out clean: - rm -f ${OBJS} main.o a.out libr_java.$(EXT_AR) out + rm -f ${OBJS} main.o a.out librz_java.$(EXT_AR) out diff --git a/shlr/java/class.c b/shlr/java/class.c index 0b025569b2..78387e5d7e 100644 --- a/shlr/java/class.c +++ b/shlr/java/class.c @@ -5,9 +5,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include "class.h" @@ -23,247 +23,247 @@ static PrintfCallback Eprintf =(PrintfCallback) printf; #define MAX_CPITEMS 8192 -R_API char *U(r_bin_java_unmangle_method)(const char *flags, const char *name, const char *params, const char *r_value); -R_API int r_bin_java_is_fm_type_private(RBinJavaField *fm_type); -R_API int r_bin_java_is_fm_type_protected(RBinJavaField *fm_type); -R_API ut32 U(r_bin_java_swap_uint)(ut32 x); +RZ_API char *U(rz_bin_java_unmangle_method)(const char *flags, const char *name, const char *params, const char *rz_value); +RZ_API int rz_bin_java_is_fm_type_private(RBinJavaField *fm_type); +RZ_API int rz_bin_java_is_fm_type_protected(RBinJavaField *fm_type); +RZ_API ut32 U(rz_bin_java_swap_uint)(ut32 x); -// R_API const char * r_bin_java_get_this_class_name(RBinJavaObj *bin); -R_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin); -R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin); -R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin); -R_API RList *retrieve_all_access_string_and_value(RBinJavaAccessFlags *access_flags); -R_API char *retrieve_access_string(ut16 flags, RBinJavaAccessFlags *access_flags); -R_API ut16 calculate_access_value(const char *access_flags_str, RBinJavaAccessFlags *access_flags); -R_API int r_bin_java_new_bin(RBinJavaObj *bin, ut64 loadaddr, Sdb *kv, const ut8 *buf, ut64 len); -R_API int extract_type_value(const char *arg_str, char **output); -R_API int r_bin_java_check_reset_cp_obj(RBinJavaCPTypeObj *cp_obj, ut8 tag); -R_API ut8 *r_bin_java_cp_get_4bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); -R_API ut8 *r_bin_java_cp_get_8bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); -R_API ut8 *r_bin_java_cp_get_utf8(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); +// RZ_API const char * rz_bin_java_get_this_class_name(RBinJavaObj *bin); +RZ_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin); +RZ_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin); +RZ_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin); +RZ_API RzList *retrieve_all_access_string_and_value(RBinJavaAccessFlags *access_flags); +RZ_API char *retrieve_access_string(ut16 flags, RBinJavaAccessFlags *access_flags); +RZ_API ut16 calculate_access_value(const char *access_flags_str, RBinJavaAccessFlags *access_flags); +RZ_API int rz_bin_java_new_bin(RBinJavaObj *bin, ut64 loadaddr, Sdb *kv, const ut8 *buf, ut64 len); +RZ_API int extract_type_value(const char *arg_str, char **output); +RZ_API int rz_bin_java_check_reset_cp_obj(RBinJavaCPTypeObj *cp_obj, ut8 tag); +RZ_API ut8 *rz_bin_java_cp_get_4bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); +RZ_API ut8 *rz_bin_java_cp_get_8bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); +RZ_API ut8 *rz_bin_java_cp_get_utf8(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); -R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_cp_item_list(RList *cp_list, ut64 idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_item_from_cp_item_list(RzList *cp_list, ut64 idx); // Allocs for objects -R_API RBinJavaCPTypeObj *r_bin_java_class_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_fieldref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_methodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_string_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_float_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_double_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); -R_API RBinJavaCPTypeObj *r_bin_java_do_nothing_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); -R_API RBinJavaCPTypeObj *r_bin_java_clone_cp_item(RBinJavaCPTypeObj *obj); -R_API RBinJavaCPTypeObj *r_bin_java_clone_cp_idx(RBinJavaObj *bin, ut32 idx); -R_API RBinJavaCPTypeObj *r_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); -R_API RBinJavaCPTypeObj *r_bin_java_methodtype_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); -R_API RBinJavaCPTypeObj *r_bin_java_invokedynamic_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); +RZ_API RBinJavaCPTypeObj *rz_bin_java_class_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_fieldref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_string_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_float_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_double_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 offset); +RZ_API RBinJavaCPTypeObj *rz_bin_java_do_nothing_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); +RZ_API RBinJavaCPTypeObj *rz_bin_java_clone_cp_item(RBinJavaCPTypeObj *obj); +RZ_API RBinJavaCPTypeObj *rz_bin_java_clone_cp_idx(RBinJavaObj *bin, ut32 idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodtype_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); +RZ_API RBinJavaCPTypeObj *rz_bin_java_invokedynamic_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); // Deallocs for type objects -R_API void r_bin_java_default_free(void /*RBinJavaCPTypeObj*/ *obj); -R_API void r_bin_java_obj_free(void /*RBinJavaCPTypeObj*/ *obj); -R_API void r_bin_java_utf8_info_free(void /*RBinJavaCPTypeObj*/ *obj); -R_API void r_bin_java_do_nothing_free(void /*RBinJavaCPTypeObj*/ *obj); -R_API void r_bin_java_fmtype_free(void /*RBinJavaField*/ *fm_type); +RZ_API void rz_bin_java_default_free(void /*RBinJavaCPTypeObj*/ *obj); +RZ_API void rz_bin_java_obj_free(void /*RBinJavaCPTypeObj*/ *obj); +RZ_API void rz_bin_java_utf8_info_free(void /*RBinJavaCPTypeObj*/ *obj); +RZ_API void rz_bin_java_do_nothing_free(void /*RBinJavaCPTypeObj*/ *obj); +RZ_API void rz_bin_java_fmtype_free(void /*RBinJavaField*/ *fm_type); // handle freeing the lists // handle the reading of the various field -R_API RBinJavaAttrInfo *r_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len); -R_API RBinJavaCPTypeObj *r_bin_java_read_next_constant_pool_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); -R_API RBinJavaAttrMetas *r_bin_java_get_attr_type_by_name(const char *name); -R_API RBinJavaCPTypeObj *r_bin_java_get_java_null_cp(void); -R_API ut64 r_bin_java_read_class_file2(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); -R_API RBinJavaAttrInfo *r_bin_java_get_attr_from_field(RBinJavaField *field, R_BIN_JAVA_ATTR_TYPE attr_type, ut32 pos); -R_API RBinJavaField *r_bin_java_read_next_field(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len); -R_API RBinJavaField *r_bin_java_read_next_method(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len); -R_API void r_bin_java_print_utf8_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_name_and_type_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_double_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_long_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_float_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_integer_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_string_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_classref_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_fieldref_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_methodref_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_interfacemethodref_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_unknown_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_null_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_unknown_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_methodhandle_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_methodtype_cp_summary(RBinJavaCPTypeObj *obj); -R_API void r_bin_java_print_invokedynamic_cp_summary(RBinJavaCPTypeObj *obj); -R_API RBinJavaCPTypeObj *r_bin_java_unknown_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); -R_API RBinJavaInterfaceInfo *r_bin_java_interface_new(RBinJavaObj *bin, const ut8 *buf, ut64 sz); -R_API RBinJavaInterfaceInfo *r_bin_java_read_next_interface_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); -R_API void r_bin_java_interface_free(void /*RBinJavaInterfaceInfo*/ *obj); -R_API void r_bin_java_stack_frame_free(void /*RBinJavaStackMapFrame*/ *obj); -R_API void r_bin_java_stack_map_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_verification_info_free(void /*RBinJavaVerificationObj*/ *obj); -R_API void r_bin_java_print_stack_map_table_attr_summary(RBinJavaAttrInfo *obj); -R_API void r_bin_java_print_stack_map_frame_summary(RBinJavaStackMapFrame *obj); -R_API void r_bin_java_print_verification_info_summary(RBinJavaVerificationObj *obj); -R_API RBinJavaStackMapFrame *r_bin_java_build_stack_frame_from_local_variable_table(RBinJavaObj *bin, RBinJavaAttrInfo *attr); -R_API void U(r_bin_java_print_stack_map_append_frame_summary)(RBinJavaStackMapFrame * obj); -R_API void U(r_bin_java_stack_frame_default_free)(void /*RBinJavaStackMapFrame*/ *stack_frame); -R_API void U(r_bin_java_stack_frame_do_nothing_free)(void /*RBinJavaStackMapFrame*/ *stack_frame); -R_API void U(r_bin_java_stack_frame_do_nothing_new)(RBinJavaObj * bin, RBinJavaStackMapFrame * stack_frame, ut64 offset); -R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz, RBinJavaStackMapFrame *p_frame, ut64 buf_offset); -// R_API RBinJavaStackMapFrame* r_bin_java_stack_map_frame_new (ut8* buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -// R_API RBinJavaVerificationObj* r_bin_java_read_next_verification_info_new(ut8* buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaAnnotation *r_bin_java_annotation_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaElementValuePair *r_bin_java_element_pair_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -// R_API RBinJavaBootStrapArgument* r_bin_java_bootstrap_method_argument_new(ut8* buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaBootStrapMethod *r_bin_java_bootstrap_method_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaAnnotationsArray *r_bin_java_annotation_array_new(ut8 *buffer, ut64 sz, ut64 buf_offset); -R_API RBinJavaElementValueMetas *r_bin_java_get_ev_meta_from_tag(ut8 tag); -R_API RBinJavaCPTypeMetas *U(r_bin_java_get_cp_meta_from_tag)(ut8 tag); -R_API void r_bin_java_inner_classes_attr_entry_free(void /*RBinJavaClassesAttribute*/ *attr); -R_API void r_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_enclosing_methods_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_local_variable_type_table_attr_entry_free(void /*RBinJavaLocalVariableTypeAttribute*/ *lvattr); -R_API void r_bin_java_local_variable_type_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_signature_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_source_debug_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_element_value_free(void /*RBinJavaElementValue*/ *element_value); -R_API void r_bin_java_element_pair_free(void /*RBinJavaElementValuePair*/ *evp); -R_API void r_bin_java_annotation_free(void /*RBinJavaAnnotation*/ *annotation); -R_API void r_bin_java_rtv_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_rti_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_annotation_array_free(void /*RBinJavaAnnotationsArray*/ *annotation_array); -R_API void r_bin_java_bootstrap_methods_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_bootstrap_method_free(void /*RBinJavaBootStrapMethod*/ *bsm); -R_API void r_bin_java_bootstrap_method_argument_free(void /*RBinJavaBootStrapArgument*/ *bsm_arg); -R_API void r_bin_java_rtvp_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_rtip_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_unknown_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_code_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_constant_value_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_deprecated_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_exceptions_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_inner_classes_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_line_number_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_local_variable_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_source_code_file_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_synthetic_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API RBinJavaAttrInfo *rz_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len); +RZ_API RBinJavaCPTypeObj *rz_bin_java_read_next_constant_pool_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); +RZ_API RBinJavaAttrMetas *rz_bin_java_get_attr_type_by_name(const char *name); +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_java_null_cp(void); +RZ_API ut64 rz_bin_java_read_class_file2(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); +RZ_API RBinJavaAttrInfo *rz_bin_java_get_attr_from_field(RBinJavaField *field, R_BIN_JAVA_ATTR_TYPE attr_type, ut32 pos); +RZ_API RBinJavaField *rz_bin_java_read_next_field(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len); +RZ_API RBinJavaField *rz_bin_java_read_next_method(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len); +RZ_API void rz_bin_java_print_utf8_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_name_and_type_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_double_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_long_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_float_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_integer_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_string_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_classref_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_fieldref_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_methodref_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_interfacemethodref_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_unknown_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_null_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_unknown_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_methodhandle_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_methodtype_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API void rz_bin_java_print_invokedynamic_cp_summary(RBinJavaCPTypeObj *obj); +RZ_API RBinJavaCPTypeObj *rz_bin_java_unknown_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz); +RZ_API RBinJavaInterfaceInfo *rz_bin_java_interface_new(RBinJavaObj *bin, const ut8 *buf, ut64 sz); +RZ_API RBinJavaInterfaceInfo *rz_bin_java_read_next_interface_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len); +RZ_API void rz_bin_java_interface_free(void /*RBinJavaInterfaceInfo*/ *obj); +RZ_API void rz_bin_java_stack_frame_free(void /*RBinJavaStackMapFrame*/ *obj); +RZ_API void rz_bin_java_stack_map_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_verification_info_free(void /*RBinJavaVerificationObj*/ *obj); +RZ_API void rz_bin_java_print_stack_map_table_attr_summary(RBinJavaAttrInfo *obj); +RZ_API void rz_bin_java_print_stack_map_frame_summary(RBinJavaStackMapFrame *obj); +RZ_API void rz_bin_java_print_verification_info_summary(RBinJavaVerificationObj *obj); +RZ_API RBinJavaStackMapFrame *rz_bin_java_build_stack_frame_from_local_variable_table(RBinJavaObj *bin, RBinJavaAttrInfo *attr); +RZ_API void U(rz_bin_java_print_stack_map_append_frame_summary)(RBinJavaStackMapFrame * obj); +RZ_API void U(rz_bin_java_stack_frame_default_free)(void /*RBinJavaStackMapFrame*/ *stack_frame); +RZ_API void U(rz_bin_java_stack_frame_do_nothing_free)(void /*RBinJavaStackMapFrame*/ *stack_frame); +RZ_API void U(rz_bin_java_stack_frame_do_nothing_new)(RBinJavaObj * bin, RBinJavaStackMapFrame * stack_frame, ut64 offset); +RZ_API RBinJavaStackMapFrame *rz_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz, RBinJavaStackMapFrame *p_frame, ut64 buf_offset); +// RZ_API RBinJavaStackMapFrame* rz_bin_java_stack_map_frame_new (ut8* buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaElementValue *rz_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +// RZ_API RBinJavaVerificationObj* rz_bin_java_read_next_verification_info_new(ut8* buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAnnotation *rz_bin_java_annotation_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaElementValuePair *rz_bin_java_element_pair_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaElementValue *rz_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +// RZ_API RBinJavaBootStrapArgument* rz_bin_java_bootstrap_method_argument_new(ut8* buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaBootStrapMethod *rz_bin_java_bootstrap_method_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAnnotationsArray *rz_bin_java_annotation_array_new(ut8 *buffer, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaElementValueMetas *rz_bin_java_get_ev_meta_from_tag(ut8 tag); +RZ_API RBinJavaCPTypeMetas *U(rz_bin_java_get_cp_meta_from_tag)(ut8 tag); +RZ_API void rz_bin_java_inner_classes_attr_entry_free(void /*RBinJavaClassesAttribute*/ *attr); +RZ_API void rz_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_enclosing_methods_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_local_variable_type_table_attr_entry_free(void /*RBinJavaLocalVariableTypeAttribute*/ *lvattr); +RZ_API void rz_bin_java_local_variable_type_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_signature_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_source_debug_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_element_value_free(void /*RBinJavaElementValue*/ *element_value); +RZ_API void rz_bin_java_element_pair_free(void /*RBinJavaElementValuePair*/ *evp); +RZ_API void rz_bin_java_annotation_free(void /*RBinJavaAnnotation*/ *annotation); +RZ_API void rz_bin_java_rtv_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_rti_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_annotation_array_free(void /*RBinJavaAnnotationsArray*/ *annotation_array); +RZ_API void rz_bin_java_bootstrap_methods_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_bootstrap_method_free(void /*RBinJavaBootStrapMethod*/ *bsm); +RZ_API void rz_bin_java_bootstrap_method_argument_free(void /*RBinJavaBootStrapArgument*/ *bsm_arg); +RZ_API void rz_bin_java_rtvp_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_rtip_annotations_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_unknown_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_code_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_constant_value_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_deprecated_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_exceptions_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_inner_classes_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_line_number_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_local_variable_table_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_source_code_file_attr_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_synthetic_attr_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_print_annotation_default_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_enclosing_methods_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_local_variable_type_attr_summary(RBinJavaLocalVariableTypeAttribute *lvattr); -R_API void r_bin_java_print_local_variable_type_table_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_signature_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_source_debug_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_element_value_summary(RBinJavaElementValue *element_value); -R_API void r_bin_java_print_annotation_summary(RBinJavaAnnotation *annotation); -R_API void r_bin_java_print_element_pair_summary(RBinJavaElementValuePair *evp); -R_API void r_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *attr); -// R_API void r_bin_java_bootstrap_method_summary(RBinJavaBootStrapMethod *bsm); -// R_API void r_bin_java_bootstrap_method_argument_summary(RBinJavaBootStrapArgument *bsm_arg); -R_API void r_bin_java_print_rtv_annotations_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_rti_annotations_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_annotation_array_summary(RBinJavaAnnotationsArray *annotation_array); -R_API void r_bin_java_print_rtvp_annotations_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_rtip_annotations_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_attribute_free(void /*RBinJavaAttrInfo*/ *attr); -R_API void r_bin_java_constant_pool(void /*RBinJavaCPTypeObj*/ *obj); -R_API void r_bin_java_print_field_summary(RBinJavaField *field); -// R_API void r_bin_java_print_interface_summary(RBinJavaField *field); -R_API void r_bin_java_print_method_summary(RBinJavaField *field); -R_API void r_bin_java_print_code_exceptions_attr_summary(RBinJavaExceptionEntry *exc_entry); -R_API void r_bin_java_print_code_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_constant_value_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_deprecated_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_exceptions_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_classes_attr_summary(RBinJavaClassesAttribute *icattr); -R_API void r_bin_java_print_inner_classes_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_line_number_table_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_local_variable_attr_summary(RBinJavaLocalVariableAttribute *lvattr); -R_API void r_bin_java_print_local_variable_table_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_source_code_file_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_synthetic_attr_summary(RBinJavaAttrInfo *attr); -R_API void r_bin_java_print_attr_summary(RBinJavaAttrInfo *attr); -R_API RBinJavaAttrInfo *r_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, ut8 *buffer, st64 sz, st64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_unknown_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_annotation_default_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_local_variable_type_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_signature_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_source_debug_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_bootstrap_methods_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_rtv_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_rti_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_rtvp_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_rtip_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_constant_value_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_deprecated_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_exceptions_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_local_variable_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_source_code_file_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API RBinJavaAttrInfo *r_bin_java_synthetic_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); -R_API ut64 r_bin_java_unknown_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_annotation_default_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_enclosing_methods_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_local_variable_type_table_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_signature_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_source_debug_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_bootstrap_methods_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_rtv_annotations_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_rti_annotations_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_rtvp_annotations_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_rtip_annotations_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_constant_value_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_deprecated_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_exceptions_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_inner_classes_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_line_number_table_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_source_code_file_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_stack_map_table_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_synthetic_attr_calc_size(RBinJavaAttrInfo *attr); -R_API ut64 r_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm); -R_API ut64 r_bin_java_element_pair_calc_size(RBinJavaElementValuePair *evp); -R_API ut64 r_bin_java_element_value_calc_size(RBinJavaElementValue *element_value); +RZ_API void rz_bin_java_print_annotation_default_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_enclosing_methods_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_local_variable_type_attr_summary(RBinJavaLocalVariableTypeAttribute *lvattr); +RZ_API void rz_bin_java_print_local_variable_type_table_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_signature_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_source_debug_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_element_value_summary(RBinJavaElementValue *element_value); +RZ_API void rz_bin_java_print_annotation_summary(RBinJavaAnnotation *annotation); +RZ_API void rz_bin_java_print_element_pair_summary(RBinJavaElementValuePair *evp); +RZ_API void rz_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *attr); +// RZ_API void rz_bin_java_bootstrap_method_summary(RBinJavaBootStrapMethod *bsm); +// RZ_API void rz_bin_java_bootstrap_method_argument_summary(RBinJavaBootStrapArgument *bsm_arg); +RZ_API void rz_bin_java_print_rtv_annotations_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_rti_annotations_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_annotation_array_summary(RBinJavaAnnotationsArray *annotation_array); +RZ_API void rz_bin_java_print_rtvp_annotations_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_rtip_annotations_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_attribute_free(void /*RBinJavaAttrInfo*/ *attr); +RZ_API void rz_bin_java_constant_pool(void /*RBinJavaCPTypeObj*/ *obj); +RZ_API void rz_bin_java_print_field_summary(RBinJavaField *field); +// RZ_API void rz_bin_java_print_interface_summary(RBinJavaField *field); +RZ_API void rz_bin_java_print_method_summary(RBinJavaField *field); +RZ_API void rz_bin_java_print_code_exceptions_attr_summary(RBinJavaExceptionEntry *exc_entry); +RZ_API void rz_bin_java_print_code_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_constant_value_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_deprecated_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_exceptions_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_classes_attr_summary(RBinJavaClassesAttribute *icattr); +RZ_API void rz_bin_java_print_inner_classes_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_line_number_table_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_local_variable_attr_summary(RBinJavaLocalVariableAttribute *lvattr); +RZ_API void rz_bin_java_print_local_variable_table_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_source_code_file_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_synthetic_attr_summary(RBinJavaAttrInfo *attr); +RZ_API void rz_bin_java_print_attr_summary(RBinJavaAttrInfo *attr); +RZ_API RBinJavaAttrInfo *rz_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, ut8 *buffer, st64 sz, st64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_unknown_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_annotation_default_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_local_variable_type_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_signature_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_source_debug_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_bootstrap_methods_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_rtv_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_rti_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_rtvp_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_rtip_annotations_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_constant_value_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_deprecated_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_exceptions_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_line_number_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_local_variable_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_source_code_file_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_synthetic_attr_new(RBinJavaObj *bin, ut8 *buf, ut64 sz, ut64 buf_offset); +RZ_API ut64 rz_bin_java_unknown_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_annotation_default_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_enclosing_methods_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_local_variable_type_table_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_signature_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_source_debug_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_bootstrap_methods_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_rtv_annotations_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_rti_annotations_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_rtvp_annotations_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_rtip_annotations_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_constant_value_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_deprecated_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_exceptions_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_inner_classes_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_line_number_table_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_source_code_file_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_stack_map_table_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_synthetic_attr_calc_size(RBinJavaAttrInfo *attr); +RZ_API ut64 rz_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm); +RZ_API ut64 rz_bin_java_element_pair_calc_size(RBinJavaElementValuePair *evp); +RZ_API ut64 rz_bin_java_element_value_calc_size(RBinJavaElementValue *element_value); -R_API ut64 r_bin_java_unknown_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_class_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_fieldref_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_methodref_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_interfacemethodref_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_name_and_type_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_string_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_integer_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_float_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_long_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_double_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_utf8_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_do_nothing_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_methodhandle_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_methodtype_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API ut64 r_bin_java_invokedynamic_cp_calc_size(RBinJavaCPTypeObj *obj); -R_API RBinJavaStackMapFrame *r_bin_java_default_stack_frame(void); +RZ_API ut64 rz_bin_java_unknown_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_class_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_fieldref_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_methodref_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_interfacemethodref_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_name_and_type_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_string_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_integer_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_float_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_long_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_double_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_utf8_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_do_nothing_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_methodhandle_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_methodtype_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API ut64 rz_bin_java_invokedynamic_cp_calc_size(RBinJavaCPTypeObj *obj); +RZ_API RBinJavaStackMapFrame *rz_bin_java_default_stack_frame(void); -R_API RList *r_bin_java_find_cp_const_by_val_float(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); -R_API RList *r_bin_java_find_cp_const_by_val_double(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); -R_API RList *r_bin_java_find_cp_const_by_val_int(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); -R_API RList *r_bin_java_find_cp_const_by_val_long(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); -R_API RList *r_bin_java_find_cp_const_by_val_utf8(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); -R_API ut8 *r_bin_java_cp_append_classref_and_name(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len); -R_API ut8 *U(r_bin_java_cp_append_ref_cname_fname_ftype)(RBinJavaObj * bin, ut32 * out_sz, ut8 tag, const char *cname, const ut32 c_len, const char *fname, const ut32 f_len, const char *tname, const ut32 t_len); -R_API ut8 *r_bin_java_cp_get_classref(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len, const ut16 name_idx); -R_API ut8 *U(r_bin_java_cp_get_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx); -R_API ut8 *U(r_bin_java_cp_get_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx); -R_API ut8 *r_bin_java_cp_get_fm_ref(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 class_idx, ut16 name_and_type_idx); -R_API ut8 *r_bin_java_cp_get_2_ut16(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 ut16_one, ut16 ut16_two); -R_API ut8 *r_bin_java_cp_get_name_type(RBinJavaObj *bin, ut32 *out_sz, ut16 name_idx, ut16 type_idx); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_float(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_double(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_int(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_long(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_utf8(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len); +RZ_API ut8 *rz_bin_java_cp_append_classref_and_name(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len); +RZ_API ut8 *U(rz_bin_java_cp_append_ref_cname_fname_ftype)(RBinJavaObj * bin, ut32 * out_sz, ut8 tag, const char *cname, const ut32 c_len, const char *fname, const ut32 f_len, const char *tname, const ut32 t_len); +RZ_API ut8 *rz_bin_java_cp_get_classref(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len, const ut16 name_idx); +RZ_API ut8 *U(rz_bin_java_cp_get_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx); +RZ_API ut8 *U(rz_bin_java_cp_get_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx); +RZ_API ut8 *rz_bin_java_cp_get_fm_ref(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 class_idx, ut16 name_and_type_idx); +RZ_API ut8 *rz_bin_java_cp_get_2_ut16(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 ut16_one, ut16 ut16_two); +RZ_API ut8 *rz_bin_java_cp_get_name_type(RBinJavaObj *bin, ut32 *out_sz, ut16 name_idx, ut16 type_idx); static char *convert_string(const char *bytes, ut32 len) { ut32 idx = 0, pos = 0; @@ -292,8 +292,8 @@ static char *convert_string(const char *bytes, ut32 len) { } // taken from LLVM Code Byte Swap -// TODO: move into r_util -R_API ut32 U(r_bin_java_swap_uint)(ut32 x) { +// TODO: move into rz_util +RZ_API ut32 U(rz_bin_java_swap_uint)(ut32 x) { const ut32 Byte0 = x & 0x000000FF; const ut32 Byte1 = x & 0x0000FF00; const ut32 Byte2 = x & 0x00FF0000; @@ -416,25 +416,25 @@ static RBinJavaStackMapFrameMetas R_BIN_JAVA_STACK_MAP_FRAME_METAS[] = { }; static RBinJavaCPTypeObjectAllocs R_BIN_ALLOCS_CONSTANTS[] = { - { r_bin_java_do_nothing_new, r_bin_java_do_nothing_free, r_bin_java_print_null_cp_summary, r_bin_java_do_nothing_calc_size, r_bin_java_print_null_cp_stringify }, - { r_bin_java_utf8_cp_new, r_bin_java_utf8_info_free, r_bin_java_print_utf8_cp_summary, r_bin_java_utf8_cp_calc_size, r_bin_java_print_utf8_cp_stringify }, - { r_bin_java_unknown_cp_new, r_bin_java_default_free, r_bin_java_print_unknown_cp_summary, r_bin_java_unknown_cp_calc_size, r_bin_java_print_unknown_cp_stringify }, - { r_bin_java_integer_cp_new, r_bin_java_default_free, r_bin_java_print_integer_cp_summary, r_bin_java_integer_cp_calc_size, r_bin_java_print_integer_cp_stringify }, - { r_bin_java_float_cp_new, r_bin_java_default_free, r_bin_java_print_float_cp_summary, r_bin_java_float_cp_calc_size, r_bin_java_print_float_cp_stringify }, - { r_bin_java_long_cp_new, r_bin_java_default_free, r_bin_java_print_long_cp_summary, r_bin_java_long_cp_calc_size, r_bin_java_print_long_cp_stringify }, - { r_bin_java_double_cp_new, r_bin_java_default_free, r_bin_java_print_double_cp_summary, r_bin_java_double_cp_calc_size, r_bin_java_print_double_cp_stringify }, - { r_bin_java_class_cp_new, r_bin_java_default_free, r_bin_java_print_classref_cp_summary, r_bin_java_class_cp_calc_size, r_bin_java_print_classref_cp_stringify }, - { r_bin_java_string_cp_new, r_bin_java_default_free, r_bin_java_print_string_cp_summary, r_bin_java_string_cp_calc_size, r_bin_java_print_string_cp_stringify }, - { r_bin_java_fieldref_cp_new, r_bin_java_default_free, r_bin_java_print_fieldref_cp_summary, r_bin_java_fieldref_cp_calc_size, r_bin_java_print_fieldref_cp_stringify }, - { r_bin_java_methodref_cp_new, r_bin_java_default_free, r_bin_java_print_methodref_cp_summary, r_bin_java_methodref_cp_calc_size, r_bin_java_print_methodref_cp_stringify }, - { r_bin_java_interfacemethodref_cp_new, r_bin_java_default_free, r_bin_java_print_interfacemethodref_cp_summary, r_bin_java_interfacemethodref_cp_calc_size, r_bin_java_print_interfacemethodref_cp_stringify }, - { r_bin_java_name_and_type_cp_new, r_bin_java_default_free, r_bin_java_print_name_and_type_cp_summary, r_bin_java_name_and_type_cp_calc_size, r_bin_java_print_name_and_type_cp_stringify }, + { rz_bin_java_do_nothing_new, rz_bin_java_do_nothing_free, rz_bin_java_print_null_cp_summary, rz_bin_java_do_nothing_calc_size, rz_bin_java_print_null_cp_stringify }, + { rz_bin_java_utf8_cp_new, rz_bin_java_utf8_info_free, rz_bin_java_print_utf8_cp_summary, rz_bin_java_utf8_cp_calc_size, rz_bin_java_print_utf8_cp_stringify }, + { rz_bin_java_unknown_cp_new, rz_bin_java_default_free, rz_bin_java_print_unknown_cp_summary, rz_bin_java_unknown_cp_calc_size, rz_bin_java_print_unknown_cp_stringify }, + { rz_bin_java_integer_cp_new, rz_bin_java_default_free, rz_bin_java_print_integer_cp_summary, rz_bin_java_integer_cp_calc_size, rz_bin_java_print_integer_cp_stringify }, + { rz_bin_java_float_cp_new, rz_bin_java_default_free, rz_bin_java_print_float_cp_summary, rz_bin_java_float_cp_calc_size, rz_bin_java_print_float_cp_stringify }, + { rz_bin_java_long_cp_new, rz_bin_java_default_free, rz_bin_java_print_long_cp_summary, rz_bin_java_long_cp_calc_size, rz_bin_java_print_long_cp_stringify }, + { rz_bin_java_double_cp_new, rz_bin_java_default_free, rz_bin_java_print_double_cp_summary, rz_bin_java_double_cp_calc_size, rz_bin_java_print_double_cp_stringify }, + { rz_bin_java_class_cp_new, rz_bin_java_default_free, rz_bin_java_print_classref_cp_summary, rz_bin_java_class_cp_calc_size, rz_bin_java_print_classref_cp_stringify }, + { rz_bin_java_string_cp_new, rz_bin_java_default_free, rz_bin_java_print_string_cp_summary, rz_bin_java_string_cp_calc_size, rz_bin_java_print_string_cp_stringify }, + { rz_bin_java_fieldref_cp_new, rz_bin_java_default_free, rz_bin_java_print_fieldref_cp_summary, rz_bin_java_fieldref_cp_calc_size, rz_bin_java_print_fieldref_cp_stringify }, + { rz_bin_java_methodref_cp_new, rz_bin_java_default_free, rz_bin_java_print_methodref_cp_summary, rz_bin_java_methodref_cp_calc_size, rz_bin_java_print_methodref_cp_stringify }, + { rz_bin_java_interfacemethodref_cp_new, rz_bin_java_default_free, rz_bin_java_print_interfacemethodref_cp_summary, rz_bin_java_interfacemethodref_cp_calc_size, rz_bin_java_print_interfacemethodref_cp_stringify }, + { rz_bin_java_name_and_type_cp_new, rz_bin_java_default_free, rz_bin_java_print_name_and_type_cp_summary, rz_bin_java_name_and_type_cp_calc_size, rz_bin_java_print_name_and_type_cp_stringify }, { NULL, NULL, NULL, NULL, NULL }, { NULL, NULL, NULL, NULL, NULL }, - { r_bin_java_methodhandle_cp_new, r_bin_java_default_free, r_bin_java_print_methodhandle_cp_summary, r_bin_java_methodhandle_cp_calc_size, r_bin_java_print_methodhandle_cp_stringify }, - { r_bin_java_methodtype_cp_new, r_bin_java_default_free, r_bin_java_print_methodtype_cp_summary, r_bin_java_methodtype_cp_calc_size, r_bin_java_print_methodtype_cp_stringify }, + { rz_bin_java_methodhandle_cp_new, rz_bin_java_default_free, rz_bin_java_print_methodhandle_cp_summary, rz_bin_java_methodhandle_cp_calc_size, rz_bin_java_print_methodhandle_cp_stringify }, + { rz_bin_java_methodtype_cp_new, rz_bin_java_default_free, rz_bin_java_print_methodtype_cp_summary, rz_bin_java_methodtype_cp_calc_size, rz_bin_java_print_methodtype_cp_stringify }, { NULL, NULL, NULL, NULL, NULL }, - { r_bin_java_invokedynamic_cp_new, r_bin_java_default_free, r_bin_java_print_invokedynamic_cp_summary, r_bin_java_invokedynamic_cp_calc_size, r_bin_java_print_invokedynamic_cp_stringify }, + { rz_bin_java_invokedynamic_cp_new, rz_bin_java_default_free, rz_bin_java_print_invokedynamic_cp_summary, rz_bin_java_invokedynamic_cp_calc_size, rz_bin_java_print_invokedynamic_cp_stringify }, }; static RBinJavaCPTypeObj R_BIN_JAVA_NULL_TYPE; static ut8 R_BIN_JAVA_CP_METAS_SZ = 12; @@ -461,29 +461,29 @@ static RBinJavaCPTypeMetas R_BIN_JAVA_CP_METAS[] = { { "InvokeDynamic", R_BIN_JAVA_CP_INVOKEDYNAMIC, 5, &R_BIN_ALLOCS_CONSTANTS[18] }, // 4 high 4 low }; static RBinJavaAttrInfoObjectAllocs RBIN_JAVA_ATTRS_ALLOCS[] = { - { r_bin_java_annotation_default_attr_new, r_bin_java_annotation_default_attr_free, r_bin_java_print_annotation_default_attr_summary, r_bin_java_annotation_default_attr_calc_size }, - { r_bin_java_bootstrap_methods_attr_new, r_bin_java_bootstrap_methods_attr_free, r_bin_java_print_bootstrap_methods_attr_summary, r_bin_java_bootstrap_methods_attr_calc_size }, - { r_bin_java_code_attr_new, r_bin_java_code_attr_free, r_bin_java_print_code_attr_summary, r_bin_java_code_attr_calc_size }, - { r_bin_java_constant_value_attr_new, r_bin_java_constant_value_attr_free, r_bin_java_print_constant_value_attr_summary, r_bin_java_constant_value_attr_calc_size }, - { r_bin_java_deprecated_attr_new, r_bin_java_deprecated_attr_free, r_bin_java_print_deprecated_attr_summary, r_bin_java_deprecated_attr_calc_size }, - { r_bin_java_enclosing_methods_attr_new, r_bin_java_enclosing_methods_attr_free, r_bin_java_print_enclosing_methods_attr_summary, r_bin_java_enclosing_methods_attr_calc_size }, - { r_bin_java_exceptions_attr_new, r_bin_java_exceptions_attr_free, r_bin_java_print_exceptions_attr_summary, r_bin_java_exceptions_attr_calc_size }, - { r_bin_java_inner_classes_attr_new, r_bin_java_inner_classes_attr_free, r_bin_java_print_inner_classes_attr_summary, r_bin_java_inner_classes_attr_calc_size }, - { r_bin_java_line_number_table_attr_new, r_bin_java_line_number_table_attr_free, r_bin_java_print_line_number_table_attr_summary, r_bin_java_line_number_table_attr_calc_size }, - { r_bin_java_local_variable_table_attr_new, r_bin_java_local_variable_table_attr_free, r_bin_java_print_local_variable_table_attr_summary, r_bin_java_local_variable_table_attr_calc_size }, - { r_bin_java_local_variable_type_table_attr_new, r_bin_java_local_variable_type_table_attr_free, r_bin_java_print_local_variable_type_table_attr_summary, r_bin_java_local_variable_type_table_attr_calc_size }, - { r_bin_java_rti_annotations_attr_new, r_bin_java_rti_annotations_attr_free, r_bin_java_print_rti_annotations_attr_summary, r_bin_java_rti_annotations_attr_calc_size }, - { r_bin_java_rtip_annotations_attr_new, r_bin_java_rtip_annotations_attr_free, r_bin_java_print_rtip_annotations_attr_summary, r_bin_java_rtip_annotations_attr_calc_size }, - { r_bin_java_rtv_annotations_attr_new, r_bin_java_rtv_annotations_attr_free, r_bin_java_print_rtv_annotations_attr_summary, r_bin_java_rtv_annotations_attr_calc_size }, - { r_bin_java_rtvp_annotations_attr_new, r_bin_java_rtvp_annotations_attr_free, r_bin_java_print_rtvp_annotations_attr_summary, r_bin_java_rtvp_annotations_attr_calc_size }, - { r_bin_java_signature_attr_new, r_bin_java_signature_attr_free, r_bin_java_print_signature_attr_summary, r_bin_java_signature_attr_calc_size }, - { r_bin_java_source_debug_attr_new, r_bin_java_source_debug_attr_free, r_bin_java_print_source_debug_attr_summary, r_bin_java_source_debug_attr_calc_size }, - { r_bin_java_source_code_file_attr_new, r_bin_java_source_code_file_attr_free, r_bin_java_print_source_code_file_attr_summary, r_bin_java_source_code_file_attr_calc_size }, - { r_bin_java_stack_map_table_attr_new, r_bin_java_stack_map_table_attr_free, r_bin_java_print_stack_map_table_attr_summary, r_bin_java_stack_map_table_attr_calc_size }, - { r_bin_java_synthetic_attr_new, r_bin_java_synthetic_attr_free, r_bin_java_print_synthetic_attr_summary, r_bin_java_synthetic_attr_calc_size }, - { r_bin_java_unknown_attr_new, r_bin_java_unknown_attr_free, r_bin_java_print_unknown_attr_summary, r_bin_java_unknown_attr_calc_size } + { rz_bin_java_annotation_default_attr_new, rz_bin_java_annotation_default_attr_free, rz_bin_java_print_annotation_default_attr_summary, rz_bin_java_annotation_default_attr_calc_size }, + { rz_bin_java_bootstrap_methods_attr_new, rz_bin_java_bootstrap_methods_attr_free, rz_bin_java_print_bootstrap_methods_attr_summary, rz_bin_java_bootstrap_methods_attr_calc_size }, + { rz_bin_java_code_attr_new, rz_bin_java_code_attr_free, rz_bin_java_print_code_attr_summary, rz_bin_java_code_attr_calc_size }, + { rz_bin_java_constant_value_attr_new, rz_bin_java_constant_value_attr_free, rz_bin_java_print_constant_value_attr_summary, rz_bin_java_constant_value_attr_calc_size }, + { rz_bin_java_deprecated_attr_new, rz_bin_java_deprecated_attr_free, rz_bin_java_print_deprecated_attr_summary, rz_bin_java_deprecated_attr_calc_size }, + { rz_bin_java_enclosing_methods_attr_new, rz_bin_java_enclosing_methods_attr_free, rz_bin_java_print_enclosing_methods_attr_summary, rz_bin_java_enclosing_methods_attr_calc_size }, + { rz_bin_java_exceptions_attr_new, rz_bin_java_exceptions_attr_free, rz_bin_java_print_exceptions_attr_summary, rz_bin_java_exceptions_attr_calc_size }, + { rz_bin_java_inner_classes_attr_new, rz_bin_java_inner_classes_attr_free, rz_bin_java_print_inner_classes_attr_summary, rz_bin_java_inner_classes_attr_calc_size }, + { rz_bin_java_line_number_table_attr_new, rz_bin_java_line_number_table_attr_free, rz_bin_java_print_line_number_table_attr_summary, rz_bin_java_line_number_table_attr_calc_size }, + { rz_bin_java_local_variable_table_attr_new, rz_bin_java_local_variable_table_attr_free, rz_bin_java_print_local_variable_table_attr_summary, rz_bin_java_local_variable_table_attr_calc_size }, + { rz_bin_java_local_variable_type_table_attr_new, rz_bin_java_local_variable_type_table_attr_free, rz_bin_java_print_local_variable_type_table_attr_summary, rz_bin_java_local_variable_type_table_attr_calc_size }, + { rz_bin_java_rti_annotations_attr_new, rz_bin_java_rti_annotations_attr_free, rz_bin_java_print_rti_annotations_attr_summary, rz_bin_java_rti_annotations_attr_calc_size }, + { rz_bin_java_rtip_annotations_attr_new, rz_bin_java_rtip_annotations_attr_free, rz_bin_java_print_rtip_annotations_attr_summary, rz_bin_java_rtip_annotations_attr_calc_size }, + { rz_bin_java_rtv_annotations_attr_new, rz_bin_java_rtv_annotations_attr_free, rz_bin_java_print_rtv_annotations_attr_summary, rz_bin_java_rtv_annotations_attr_calc_size }, + { rz_bin_java_rtvp_annotations_attr_new, rz_bin_java_rtvp_annotations_attr_free, rz_bin_java_print_rtvp_annotations_attr_summary, rz_bin_java_rtvp_annotations_attr_calc_size }, + { rz_bin_java_signature_attr_new, rz_bin_java_signature_attr_free, rz_bin_java_print_signature_attr_summary, rz_bin_java_signature_attr_calc_size }, + { rz_bin_java_source_debug_attr_new, rz_bin_java_source_debug_attr_free, rz_bin_java_print_source_debug_attr_summary, rz_bin_java_source_debug_attr_calc_size }, + { rz_bin_java_source_code_file_attr_new, rz_bin_java_source_code_file_attr_free, rz_bin_java_print_source_code_file_attr_summary, rz_bin_java_source_code_file_attr_calc_size }, + { rz_bin_java_stack_map_table_attr_new, rz_bin_java_stack_map_table_attr_free, rz_bin_java_print_stack_map_table_attr_summary, rz_bin_java_stack_map_table_attr_calc_size }, + { rz_bin_java_synthetic_attr_new, rz_bin_java_synthetic_attr_free, rz_bin_java_print_synthetic_attr_summary, rz_bin_java_synthetic_attr_calc_size }, + { rz_bin_java_unknown_attr_new, rz_bin_java_unknown_attr_free, rz_bin_java_print_unknown_attr_summary, rz_bin_java_unknown_attr_calc_size } }; -// R_API ut32 RBIN_JAVA_ATTRS_METAS_SZ = 21; +// RZ_API ut32 RBIN_JAVA_ATTRS_METAS_SZ = 21; static ut32 RBIN_JAVA_ATTRS_METAS_SZ = 20; static RBinJavaAttrMetas RBIN_JAVA_ATTRS_METAS[] = { { "AnnotationDefault", R_BIN_JAVA_ATTR_TYPE_ANNOTATION_DEFAULT_ATTR, &RBIN_JAVA_ATTRS_ALLOCS[0] }, @@ -510,48 +510,48 @@ static RBinJavaAttrMetas RBIN_JAVA_ATTRS_METAS[] = { { "Unknown", R_BIN_JAVA_ATTR_TYPE_UNKNOWN_ATTR, &RBIN_JAVA_ATTRS_ALLOCS[20] } }; -R_API bool r_bin_java_is_old_format(RBinJavaObj *bin) { +RZ_API bool rz_bin_java_is_old_format(RBinJavaObj *bin) { return bin->cf.major[1] == 45 && bin->cf.minor[1] <= 2; } -R_API void r_bin_java_reset_bin_info(RBinJavaObj *bin) { +RZ_API void rz_bin_java_reset_bin_info(RBinJavaObj *bin) { free (bin->cf2.flags_str); free (bin->cf2.this_class_name); - r_list_free (bin->imports_list); - r_list_free (bin->methods_list); - r_list_free (bin->fields_list); - r_list_free (bin->attrs_list); - r_list_free (bin->cp_list); - r_list_free (bin->interfaces_list); - r_str_constpool_fini (&bin->constpool); + rz_list_free (bin->imports_list); + rz_list_free (bin->methods_list); + rz_list_free (bin->fields_list); + rz_list_free (bin->attrs_list); + rz_list_free (bin->cp_list); + rz_list_free (bin->interfaces_list); + rz_str_constpool_fini (&bin->constpool); memset (bin, 0, sizeof (RBinJavaObj)); - r_str_constpool_init (&bin->constpool); + rz_str_constpool_init (&bin->constpool); bin->cf2.flags_str = strdup ("unknown"); bin->cf2.this_class_name = strdup ("unknown"); - bin->imports_list = r_list_newf (free); - bin->methods_list = r_list_newf (r_bin_java_fmtype_free); - bin->fields_list = r_list_newf (r_bin_java_fmtype_free); - bin->attrs_list = r_list_newf (r_bin_java_attribute_free); - bin->cp_list = r_list_newf (r_bin_java_constant_pool); - bin->interfaces_list = r_list_newf (r_bin_java_interface_free); + bin->imports_list = rz_list_newf (free); + bin->methods_list = rz_list_newf (rz_bin_java_fmtype_free); + bin->fields_list = rz_list_newf (rz_bin_java_fmtype_free); + bin->attrs_list = rz_list_newf (rz_bin_java_attribute_free); + bin->cp_list = rz_list_newf (rz_bin_java_constant_pool); + bin->interfaces_list = rz_list_newf (rz_bin_java_interface_free); } -R_API char *r_bin_java_unmangle_method(const char *flags, const char *name, const char *params, const char *r_value) { - RList *the_list = params ? r_bin_java_extract_type_values (params) : r_list_new (); - RListIter *iter = NULL; +RZ_API char *rz_bin_java_unmangle_method(const char *flags, const char *name, const char *params, const char *rz_value) { + RzList *the_list = params ? rz_bin_java_extract_type_values (params) : rz_list_new (); + RzListIter *iter = NULL; // second case removes leading space if no flags are given const char *fmt = flags ? "%s %s %s (%s)" : "%s%s %s (%s)"; - char *str = NULL, *f_val_str = NULL, *r_val_str = NULL, *prototype = NULL, *p_val_str = NULL; + char *str = NULL, *f_val_str = NULL, *rz_val_str = NULL, *prototype = NULL, *p_val_str = NULL; ut32 params_idx = 0, params_len = 0, prototype_len = 0; - if (!extract_type_value (r_value, &r_val_str)) { - r_list_free (the_list); + if (!extract_type_value (rz_value, &rz_val_str)) { + rz_list_free (the_list); return NULL; } - if (!r_val_str) { - r_val_str = strdup ("UNKNOWN"); + if (!rz_val_str) { + rz_val_str = strdup ("UNKNOWN"); } f_val_str = strdup (flags ? flags : ""); - r_list_foreach (the_list, iter, str) { + rz_list_foreach (the_list, iter, str) { params_len += strlen (str); if (params_idx > 0) { params_len += 2; @@ -562,7 +562,7 @@ R_API char *r_bin_java_unmangle_method(const char *flags, const char *name, cons ut32 offset = 0; params_len += 1; p_val_str = malloc (params_len); - r_list_foreach (the_list, iter, str) { + rz_list_foreach (the_list, iter, str) { if (offset != 0) { offset += snprintf (p_val_str + offset, params_len - offset, ", %s", str); } else { @@ -575,21 +575,21 @@ R_API char *r_bin_java_unmangle_method(const char *flags, const char *name, cons prototype_len += (flags ? strlen (flags) + 1 : 0); // space vs no space prototype_len += strlen (name) + 1; // name + space - prototype_len += strlen (r_val_str) + 1; // r_value + space - prototype_len += strlen (p_val_str) + 3; // space + l_paren + params + r_paren + prototype_len += strlen (rz_val_str) + 1; // rz_value + space + prototype_len += strlen (p_val_str) + 3; // space + l_paren + params + rz_paren prototype_len += 1; // null prototype = malloc (prototype_len); /// TODO enable this function and start using it to demangle strings - snprintf (prototype, prototype_len, fmt, f_val_str, r_val_str, name, p_val_str); + snprintf (prototype, prototype_len, fmt, f_val_str, rz_val_str, name, p_val_str); free (f_val_str); - free (r_val_str); + free (rz_val_str); free (p_val_str); - r_list_free (the_list); + rz_list_free (the_list); return prototype; } -R_API char *r_bin_java_unmangle(const char *flags, const char *name, const char *descriptor) { - ut32 l_paren_pos = -1, r_paren_pos = -1; +RZ_API char *rz_bin_java_unmangle(const char *flags, const char *name, const char *descriptor) { + ut32 l_paren_pos = -1, rz_paren_pos = -1; char *result = NULL; ut32 desc_len = descriptor && *descriptor ? strlen (descriptor) : 0, name_len = name && *name ? strlen (name) : 0, @@ -602,12 +602,12 @@ R_API char *r_bin_java_unmangle(const char *flags, const char *name, const char if (descriptor[i] == '(') { l_paren_pos = i; } else if (l_paren_pos != (ut32) - 1 && descriptor[i] == ')') { - r_paren_pos = i; + rz_paren_pos = i; break; } } // handle field case; - if (l_paren_pos == (ut32) - 1 && r_paren_pos == (ut32) - 1) { + if (l_paren_pos == (ut32) - 1 && rz_paren_pos == (ut32) - 1) { char *unmangle_field_desc = NULL; ut32 len = extract_type_value (descriptor, &unmangle_field_desc); if (len == 0) { @@ -626,27 +626,27 @@ R_API char *r_bin_java_unmangle(const char *flags, const char *name, const char } free (unmangle_field_desc); } else if (l_paren_pos != (ut32) - 1 && - r_paren_pos != (ut32) - 1 && - l_paren_pos < r_paren_pos) { + rz_paren_pos != (ut32) - 1 && + l_paren_pos < rz_paren_pos) { // params_len account for l_paren + 1 and null - ut32 params_len = r_paren_pos - (l_paren_pos + 1) != 0 ? r_paren_pos - (l_paren_pos + 1) + 1 : 0; + ut32 params_len = rz_paren_pos - (l_paren_pos + 1) != 0 ? rz_paren_pos - (l_paren_pos + 1) + 1 : 0; char *params = params_len ? malloc (params_len) : NULL; - const char *rvalue = descriptor + r_paren_pos + 1; + const char *rvalue = descriptor + rz_paren_pos + 1; if (params) { snprintf (params, params_len, "%s", descriptor + l_paren_pos + 1); } - result = r_bin_java_unmangle_method (flags, name, params, rvalue); + result = rz_bin_java_unmangle_method (flags, name, params, rvalue); free (params); } return result; } -R_API DsoJsonObj *r_bin_java_get_bin_obj_json(RBinJavaObj *bin) { - DsoJsonObj *imports_list = r_bin_java_get_import_json_definitions (bin); - DsoJsonObj *fields_list = r_bin_java_get_field_json_definitions (bin); - DsoJsonObj *methods_list = r_bin_java_get_method_json_definitions (bin); - // interfaces_list = r_bin_java_get_interface_json_definitions (bin); - DsoJsonObj *class_dict = r_bin_java_get_class_info_json (bin); +RZ_API DsoJsonObj *rz_bin_java_get_bin_obj_json(RBinJavaObj *bin) { + DsoJsonObj *imports_list = rz_bin_java_get_import_json_definitions (bin); + DsoJsonObj *fields_list = rz_bin_java_get_field_json_definitions (bin); + DsoJsonObj *methods_list = rz_bin_java_get_method_json_definitions (bin); + // interfaces_list = rz_bin_java_get_interface_json_definitions (bin); + DsoJsonObj *class_dict = rz_bin_java_get_class_info_json (bin); char *res = dso_json_obj_to_str (methods_list); // eprintf ("Resulting methods json: \n%s\n", res); free (res); @@ -680,17 +680,17 @@ R_API DsoJsonObj *r_bin_java_get_bin_obj_json(RBinJavaObj *bin) { return class_dict; } -R_API DsoJsonObj *r_bin_java_get_import_json_definitions(RBinJavaObj *bin) { - RList *the_list; +RZ_API DsoJsonObj *rz_bin_java_get_import_json_definitions(RBinJavaObj *bin) { + RzList *the_list; DsoJsonObj *json_list = dso_json_list_new (); - RListIter *iter = NULL; + RzListIter *iter = NULL; char *new_str; - if (!bin || !(the_list = r_bin_java_get_lib_names (bin))) { + if (!bin || !(the_list = rz_bin_java_get_lib_names (bin))) { return json_list; } - r_list_foreach (the_list, iter, new_str) { + rz_list_foreach (the_list, iter, new_str) { char *tmp = new_str; // eprintf ("Processing string: %s\n", new_str); while (*tmp) { @@ -702,19 +702,19 @@ R_API DsoJsonObj *r_bin_java_get_import_json_definitions(RBinJavaObj *bin) { // eprintf ("adding string: %s\n", new_str); dso_json_list_append_str (json_list, new_str); } - r_list_free (the_list); + rz_list_free (the_list); return json_list; } -R_API DsoJsonObj *r_bin_java_get_class_info_json(RBinJavaObj *bin) { - RList *classes = r_bin_java_get_classes (bin); +RZ_API DsoJsonObj *rz_bin_java_get_class_info_json(RBinJavaObj *bin) { + RzList *classes = rz_bin_java_get_classes (bin); DsoJsonObj *interfaces_list = dso_json_list_new (); DsoJsonObj *class_info_dict = dso_json_dict_new (); - RBinClass *class_ = r_list_get_n (classes, 0); + RBinClass *class_ = rz_list_get_n (classes, 0); if (class_) { int dummy = 0; - RListIter *iter; + RzListIter *iter; RBinClass *class_v = NULL; // add access flags like in methods bool is_public = ((class_->visibility & R_BIN_JAVA_CLASS_ACC_PUBLIC) != 0); @@ -745,7 +745,7 @@ R_API DsoJsonObj *r_bin_java_get_class_info_json(RBinJavaObj *bin) { dso_json_dict_insert_str_key_str (class_info_dict, "super", class_->super); } - r_list_foreach (classes, iter, class_v) { + rz_list_foreach (classes, iter, class_v) { if (!dummy) { dummy++; continue; @@ -757,23 +757,23 @@ R_API DsoJsonObj *r_bin_java_get_class_info_json(RBinJavaObj *bin) { } } dso_json_dict_insert_str_key_obj (class_info_dict, "interfaces", interfaces_list); - r_list_free (classes); + rz_list_free (classes); // dso_json_list_free (interfaces_list); dso_json_obj_del (interfaces_list); return class_info_dict; } -R_API DsoJsonObj *r_bin_java_get_interface_json_definitions(RBinJavaObj *bin) { - RList *the_list; +RZ_API DsoJsonObj *rz_bin_java_get_interface_json_definitions(RBinJavaObj *bin) { + RzList *the_list; DsoJsonObj *json_list = dso_json_list_new (); - RListIter *iter = NULL; + RzListIter *iter = NULL; char *new_str; - if (!bin || !(the_list = r_bin_java_get_interface_names (bin))) { + if (!bin || !(the_list = rz_bin_java_get_interface_names (bin))) { return json_list; } - r_list_foreach (the_list, iter, new_str) { + rz_list_foreach (the_list, iter, new_str) { char *tmp = new_str; // eprintf ("Processing string: %s\n", new_str); while (*tmp) { @@ -785,41 +785,41 @@ R_API DsoJsonObj *r_bin_java_get_interface_json_definitions(RBinJavaObj *bin) { // eprintf ("adding string: %s\n", new_str); dso_json_list_append_str (json_list, new_str); } - r_list_free (the_list); + rz_list_free (the_list); return json_list; } -R_API DsoJsonObj *r_bin_java_get_method_json_definitions(RBinJavaObj *bin) { +RZ_API DsoJsonObj *rz_bin_java_get_method_json_definitions(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RListIter *iter = NULL; + RzListIter *iter = NULL; DsoJsonObj *json_list = dso_json_list_new (); if (!bin) { return json_list; } - r_list_foreach (bin->methods_list, iter, fm_type) { - DsoJsonObj *method_proto = r_bin_java_get_method_json_definition (bin, fm_type); + rz_list_foreach (bin->methods_list, iter, fm_type) { + DsoJsonObj *method_proto = rz_bin_java_get_method_json_definition (bin, fm_type); // eprintf ("Method json: %s\n", method_proto); dso_json_list_append (json_list, method_proto); } return json_list; } -R_API DsoJsonObj *r_bin_java_get_field_json_definitions(RBinJavaObj *bin) { +RZ_API DsoJsonObj *rz_bin_java_get_field_json_definitions(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RListIter *iter = NULL; + RzListIter *iter = NULL; DsoJsonObj *json_list = dso_json_list_new (); if (!bin) { return json_list; } - r_list_foreach (bin->fields_list, iter, fm_type) { - DsoJsonObj *field_proto = r_bin_java_get_field_json_definition (bin, fm_type); + rz_list_foreach (bin->fields_list, iter, fm_type) { + DsoJsonObj *field_proto = rz_bin_java_get_field_json_definition (bin, fm_type); // eprintf ("Field json: %s\n", field_proto); dso_json_list_append (json_list, field_proto); } return json_list; } -R_API char *r_bin_java_create_method_fq_str(const char *klass, const char *name, const char *signature) { +RZ_API char *rz_bin_java_create_method_fq_str(const char *klass, const char *name, const char *signature) { if (!klass) { klass = "null_class"; } @@ -829,10 +829,10 @@ R_API char *r_bin_java_create_method_fq_str(const char *klass, const char *name, if (!signature) { signature = "null_signature"; } - return r_str_newf ("%s.%s.%s", klass, name, signature); + return rz_str_newf ("%s.%s.%s", klass, name, signature); } -R_API char *r_bin_java_create_field_fq_str(const char *klass, const char *name, const char *signature) { +RZ_API char *rz_bin_java_create_field_fq_str(const char *klass, const char *name, const char *signature) { if (!klass) { klass = "null_class"; } @@ -842,10 +842,10 @@ R_API char *r_bin_java_create_field_fq_str(const char *klass, const char *name, if (!signature) { signature = "null_signature"; } - return r_str_newf ("%s %s.%s", signature, klass, name); + return rz_str_newf ("%s %s.%s", signature, klass, name); } -R_API DsoJsonObj *r_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJavaField *fm_type, int is_method) { +RZ_API DsoJsonObj *rz_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJavaField *fm_type, int is_method) { ut64 addr = UT64_MAX; char *prototype = NULL, *fq_name = NULL; bool is_native = ((fm_type->flags & R_BIN_JAVA_METHOD_ACC_NATIVE) != 0); @@ -867,7 +867,7 @@ R_API DsoJsonObj *r_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJ dso_json_dict_insert_str_key_num (fm_type_dict, "is_protected", is_protected); dso_json_dict_insert_str_key_num (fm_type_dict, "is_super", is_super); - addr = r_bin_java_get_method_code_offset (fm_type); + addr = rz_bin_java_get_method_code_offset (fm_type); if (addr == 0) { addr = fm_type->file_offset; } @@ -880,36 +880,36 @@ R_API DsoJsonObj *r_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJ dso_json_dict_insert_str_key_str (fm_type_dict, "name", fm_type->name); if (is_method) { - fq_name = r_bin_java_create_method_fq_str (fm_type->class_name, fm_type->name, fm_type->descriptor); + fq_name = rz_bin_java_create_method_fq_str (fm_type->class_name, fm_type->name, fm_type->descriptor); } else { - fq_name = r_bin_java_create_field_fq_str (fm_type->class_name, fm_type->name, fm_type->descriptor); + fq_name = rz_bin_java_create_field_fq_str (fm_type->class_name, fm_type->name, fm_type->descriptor); } dso_json_dict_insert_str_key_str (fm_type_dict, "fq_name", fq_name); - prototype = r_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); + prototype = rz_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); dso_json_dict_insert_str_key_str (fm_type_dict, "prototype", prototype); free (prototype); free (fq_name); return fm_type_dict; } -R_API char *r_bin_java_get_method_definition(RBinJavaField *fm_type) { - return r_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); +RZ_API char *rz_bin_java_get_method_definition(RBinJavaField *fm_type) { + return rz_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); } -R_API char *r_bin_java_get_field_definition(RBinJavaField *fm_type) { - return r_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); +RZ_API char *rz_bin_java_get_field_definition(RBinJavaField *fm_type) { + return rz_bin_java_unmangle (fm_type->flags_str, fm_type->name, fm_type->descriptor); } -R_API DsoJsonObj *r_bin_java_get_method_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type) { - return r_bin_java_get_fm_type_definition_json (bin, fm_type, 1); +RZ_API DsoJsonObj *rz_bin_java_get_method_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type) { + return rz_bin_java_get_fm_type_definition_json (bin, fm_type, 1); } -R_API DsoJsonObj *r_bin_java_get_field_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type) { - return r_bin_java_get_fm_type_definition_json (bin, fm_type, 0); +RZ_API DsoJsonObj *rz_bin_java_get_field_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type) { + return rz_bin_java_get_fm_type_definition_json (bin, fm_type, 0); } -R_API int r_bin_java_extract_reference_name(const char *input_str, char **ref_str, ut8 array_cnt) { +RZ_API int rz_bin_java_extract_reference_name(const char *input_str, char **ref_str, ut8 array_cnt) { char *new_str = NULL; ut32 str_len = array_cnt ? (array_cnt + 1) * 2 : 0; const char *str_pos = input_str; @@ -940,17 +940,17 @@ R_API int r_bin_java_extract_reference_name(const char *input_str, char **ref_st return len + 2; } -R_API void UNUSED_FUNCTION(r_bin_java_print_prototypes)(RBinJavaObj * bin) { - RList *the_list = r_bin_java_get_method_definitions (bin); - RListIter *iter; +RZ_API void UNUSED_FUNCTION(rz_bin_java_print_prototypes)(RBinJavaObj * bin) { + RzList *the_list = rz_bin_java_get_method_definitions (bin); + RzListIter *iter; char *str; - r_list_foreach (the_list, iter, str) { + rz_list_foreach (the_list, iter, str) { eprintf ("%s;\n", str); } - r_list_free (the_list); + rz_list_free (the_list); } -R_API char *get_type_value_str(const char *arg_str, ut8 array_cnt) { +RZ_API char *get_type_value_str(const char *arg_str, ut8 array_cnt) { ut32 str_len = array_cnt ? (array_cnt + 1) * 2 + strlen (arg_str) : strlen (arg_str); char *str = malloc (str_len + 1); ut32 bytes_written = snprintf (str, str_len + 1, "%s", arg_str); @@ -962,7 +962,7 @@ R_API char *get_type_value_str(const char *arg_str, ut8 array_cnt) { return str; } -R_API int extract_type_value(const char *arg_str, char **output) { +RZ_API int extract_type_value(const char *arg_str, char **output) { ut8 found_one = 0, array_cnt = 0; ut32 len = 0, consumed = 0; char *str = NULL; @@ -1015,7 +1015,7 @@ R_API int extract_type_value(const char *arg_str, char **output) { array_cnt++; break; case 'L': - len = r_bin_java_extract_reference_name (arg_str, &str, array_cnt); + len = rz_bin_java_extract_reference_name (arg_str, &str, array_cnt); array_cnt = 0; break; case '(': @@ -1040,8 +1040,8 @@ R_API int extract_type_value(const char *arg_str, char **output) { return consumed; } -R_API RList *r_bin_java_extract_type_values(const char *arg_str) { - RList *list_args = r_list_new (); +RZ_API RzList *rz_bin_java_extract_type_values(const char *arg_str) { + RzList *list_args = rz_list_new (); if (!list_args) { return NULL; } @@ -1057,17 +1057,17 @@ R_API RList *r_bin_java_extract_type_values(const char *arg_str) { // handle the end of an object len = extract_type_value (str_cur_pos, &str); if (len < 1) { - r_list_free (list_args); + rz_list_free (list_args); return NULL; } str_cur_pos += len; - r_list_append (list_args, str); + rz_list_append (list_args, str); str = NULL; } return list_args; } -R_API int r_bin_java_is_fm_type_private(RBinJavaField *fm_type) { +RZ_API int rz_bin_java_is_fm_type_private(RBinJavaField *fm_type) { if (fm_type && fm_type->type == R_BIN_JAVA_FIELD_TYPE_METHOD) { return fm_type->flags & R_BIN_JAVA_METHOD_ACC_PRIVATE; } @@ -1077,7 +1077,7 @@ R_API int r_bin_java_is_fm_type_private(RBinJavaField *fm_type) { return 0; } -R_API int r_bin_java_is_fm_type_protected(RBinJavaField *fm_type) { +RZ_API int rz_bin_java_is_fm_type_protected(RBinJavaField *fm_type) { if (fm_type && fm_type->type == R_BIN_JAVA_FIELD_TYPE_METHOD) { return fm_type->flags & R_BIN_JAVA_METHOD_ACC_PROTECTED; } @@ -1087,13 +1087,13 @@ R_API int r_bin_java_is_fm_type_protected(RBinJavaField *fm_type) { return 0; } -R_API RList *r_bin_java_get_args(RBinJavaField *fm_type) { - RList *the_list = r_bin_java_extract_type_values (fm_type->descriptor); - RList *arg_list = r_list_new (); +RZ_API RzList *rz_bin_java_get_args(RBinJavaField *fm_type) { + RzList *the_list = rz_bin_java_extract_type_values (fm_type->descriptor); + RzList *arg_list = rz_list_new (); ut8 in_args = 0; - RListIter *desc_iter; + RzListIter *desc_iter; char *str; - r_list_foreach (the_list, desc_iter, str) { + rz_list_foreach (the_list, desc_iter, str) { if (str && *str == '(') { in_args = 1; continue; @@ -1102,36 +1102,36 @@ R_API RList *r_bin_java_get_args(RBinJavaField *fm_type) { break; } if (in_args && str) { - r_list_append (arg_list, strdup (str)); + rz_list_append (arg_list, strdup (str)); } } - r_list_free (the_list); + rz_list_free (the_list); return arg_list; } -R_API RList *r_bin_java_get_ret(RBinJavaField *fm_type) { - RList *the_list = r_bin_java_extract_type_values (fm_type->descriptor); - RList *ret_list = r_list_new (); +RZ_API RzList *rz_bin_java_get_ret(RBinJavaField *fm_type) { + RzList *the_list = rz_bin_java_extract_type_values (fm_type->descriptor); + RzList *ret_list = rz_list_new (); ut8 in_ret = 0; - RListIter *desc_iter; + RzListIter *desc_iter; char *str; - r_list_foreach (the_list, desc_iter, str) { + rz_list_foreach (the_list, desc_iter, str) { if (str && *str != ')') { in_ret = 0; } if (in_ret) { - r_list_append (ret_list, strdup (str)); + rz_list_append (ret_list, strdup (str)); } } - r_list_free (the_list); + rz_list_free (the_list); return ret_list; } -R_API char *r_bin_java_get_this_class_name(RBinJavaObj *bin) { +RZ_API char *rz_bin_java_get_this_class_name(RBinJavaObj *bin) { return (bin->cf2.this_class_name ? strdup (bin->cf2.this_class_name) : strdup ("unknown")); } -R_API ut16 calculate_access_value(const char *access_flags_str, RBinJavaAccessFlags *access_flags) { +RZ_API ut16 calculate_access_value(const char *access_flags_str, RBinJavaAccessFlags *access_flags) { ut16 result = 0; ut16 size = strlen (access_flags_str) + 1; char *p_flags, *my_flags = malloc (size); @@ -1162,9 +1162,9 @@ R_API ut16 calculate_access_value(const char *access_flags_str, RBinJavaAccessFl return result; } -R_API RList *retrieve_all_access_string_and_value(RBinJavaAccessFlags *access_flags) { +RZ_API RzList *retrieve_all_access_string_and_value(RBinJavaAccessFlags *access_flags) { const char *fmt = "%s = 0x%04x"; - RList *result = r_list_new (); + RzList *result = rz_list_new (); if (!result) { return NULL; } @@ -1173,16 +1173,16 @@ R_API RList *retrieve_all_access_string_and_value(RBinJavaAccessFlags *access_fl for (i = 0; access_flags[i].str != NULL; i++) { char *str = malloc (50); if (!str) { - r_list_free (result); + rz_list_free (result); return NULL; } snprintf (str, 49, fmt, access_flags[i].str, access_flags[i].value); - r_list_append (result, str); + rz_list_append (result, str); } return result; } -R_API char *retrieve_access_string(ut16 flags, RBinJavaAccessFlags *access_flags) { +RZ_API char *retrieve_access_string(ut16 flags, RBinJavaAccessFlags *access_flags) { char *outbuffer = NULL, *cur_pos = NULL; ut16 i; ut16 max_str_len = 0; @@ -1215,21 +1215,21 @@ R_API char *retrieve_access_string(ut16 flags, RBinJavaAccessFlags *access_flags return outbuffer; } -R_API char *retrieve_method_access_string(ut16 flags) { +RZ_API char *retrieve_method_access_string(ut16 flags) { return retrieve_access_string (flags, METHOD_ACCESS_FLAGS); } -R_API char *retrieve_field_access_string(ut16 flags) { +RZ_API char *retrieve_field_access_string(ut16 flags) { return retrieve_access_string (flags, FIELD_ACCESS_FLAGS); } -R_API char *retrieve_class_method_access_string(ut16 flags) { +RZ_API char *retrieve_class_method_access_string(ut16 flags) { return retrieve_access_string (flags, CLASS_ACCESS_FLAGS); } -R_API char *r_bin_java_build_obj_key(RBinJavaObj *bin) { +RZ_API char *rz_bin_java_build_obj_key(RBinJavaObj *bin) { char *jvcname = NULL; - char *cname = r_bin_java_get_this_class_name (bin); + char *cname = rz_bin_java_get_this_class_name (bin); ut32 class_name_len = cname ? strlen (cname) : strlen ("_unknown_"); jvcname = malloc (class_name_len + 8 + 30); if (cname) { @@ -1241,19 +1241,19 @@ R_API char *r_bin_java_build_obj_key(RBinJavaObj *bin) { return jvcname; } -R_API bool sdb_iterate_build_list(void *user, const char *k, const char *v) { - RList *bin_objs_list = (RList *) user; +RZ_API bool sdb_iterate_build_list(void *user, const char *k, const char *v) { + RzList *bin_objs_list = (RzList *) user; size_t value = (size_t) sdb_atoi (v); RBinJavaObj *bin_obj = NULL; IFDBG eprintf("Found %s == %"PFMT64x " bin_objs db\n", k, (ut64) value); if (value != 0 && value != (size_t) -1) { bin_obj = (RBinJavaObj *) value; - r_list_append (bin_objs_list, bin_obj); + rz_list_append (bin_objs_list, bin_obj); } return true; } -R_API RBinJavaCPTypeObj *r_bin_java_get_java_null_cp(void) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_java_null_cp(void) { if (R_BIN_JAVA_NULL_TYPE_INITTED) { return &R_BIN_JAVA_NULL_TYPE; } @@ -1270,7 +1270,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_get_java_null_cp(void) { return &R_BIN_JAVA_NULL_TYPE; } -R_API RBinJavaElementValueMetas *r_bin_java_get_ev_meta_from_tag(ut8 tag) { +RZ_API RBinJavaElementValueMetas *rz_bin_java_get_ev_meta_from_tag(ut8 tag) { ut16 i = 0; RBinJavaElementValueMetas *res = &R_BIN_JAVA_ELEMENT_VALUE_METAS[13]; for (i = 0; i < R_BIN_JAVA_ELEMENT_VALUE_METAS_SZ; i++) { @@ -1282,7 +1282,7 @@ R_API RBinJavaElementValueMetas *r_bin_java_get_ev_meta_from_tag(ut8 tag) { return res; } -R_API ut8 r_bin_java_quick_check(ut8 expected_tag, ut8 actual_tag, ut32 actual_len, const char *name) { +RZ_API ut8 rz_bin_java_quick_check(ut8 expected_tag, ut8 actual_tag, ut32 actual_len, const char *name) { ut8 res = 0; if (expected_tag > R_BIN_JAVA_CP_METAS_SZ) { eprintf ("Invalid tag '%d' expected 0x%02x for %s.\n", actual_tag, expected_tag, name); @@ -1298,13 +1298,13 @@ R_API ut8 r_bin_java_quick_check(ut8 expected_tag, ut8 actual_tag, ut32 actual_l return res; } -R_API ut64 r_bin_java_raw_to_long(const ut8 *raw, ut64 offset) { +RZ_API ut64 rz_bin_java_raw_to_long(const ut8 *raw, ut64 offset) { return R_BIN_JAVA_LONG (raw, offset); } // yanked from careercup, because i am lazy: // 1) dont want to figure out how make radare use math library // 2) dont feel like figuring it out when google does it in O(1). -R_API double my_pow(ut64 base, int exp) { +RZ_API double my_pow(ut64 base, int exp) { ut8 flag = 0; ut64 res = 1; if (exp < 0) { @@ -1325,7 +1325,7 @@ R_API double my_pow(ut64 base, int exp) { return (1.0 / res); } -R_API double r_bin_java_raw_to_double(const ut8 *raw, ut64 offset) { +RZ_API double rz_bin_java_raw_to_double(const ut8 *raw, ut64 offset) { ut64 bits = R_BIN_JAVA_LONG (raw, offset); int s = ((bits >> 63) == 0) ? 1 : -1; int e = (int) ((bits >> 52) & 0x7ffL); @@ -1353,7 +1353,7 @@ R_API double r_bin_java_raw_to_double(const ut8 *raw, ut64 offset) { return res; } -R_API RBinJavaField *r_bin_java_read_next_method(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API RBinJavaField *rz_bin_java_read_next_method(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { ut32 i, idx; const ut8 *f_buf = buf + offset; ut64 adv = 0; @@ -1379,55 +1379,55 @@ R_API RBinJavaField *r_bin_java_read_next_method(RBinJavaObj *bin, const ut64 of method->name_idx = R_BIN_JAVA_USHORT (f_buf, 2); method->descriptor_idx = R_BIN_JAVA_USHORT (f_buf, 4); method->attr_count = R_BIN_JAVA_USHORT (f_buf, 6); - method->attributes = r_list_newf (r_bin_java_attribute_free); + method->attributes = rz_list_newf (rz_bin_java_attribute_free); method->type = R_BIN_JAVA_FIELD_TYPE_METHOD; method->metas->ord = bin->method_idx; adv += 8; idx = method->name_idx; - item = r_bin_java_get_item_from_bin_cp_list (bin, idx); - method->name = r_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) (method->name_idx)); + item = rz_bin_java_get_item_from_bin_cp_list (bin, idx); + method->name = rz_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) (method->name_idx)); IFDBG eprintf("Method name_idx: %d, which is: ord: %d, name: %s, value: %s\n", idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name, method->name); if (!method->name) { method->name = (char *) malloc (21); snprintf ((char *) method->name, 20, "sym.method_%08x", method->metas->ord); - IFDBG eprintf("r_bin_java_read_next_method: Unable to find the name for 0x%02x index.\n", method->name_idx); + IFDBG eprintf("rz_bin_java_read_next_method: Unable to find the name for 0x%02x index.\n", method->name_idx); } idx = method->descriptor_idx; - item = r_bin_java_get_item_from_bin_cp_list (bin, idx); - method->descriptor = r_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) method->descriptor_idx); + item = rz_bin_java_get_item_from_bin_cp_list (bin, idx); + method->descriptor = rz_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) method->descriptor_idx); IFDBG eprintf("Method descriptor_idx: %d, which is: ord: %d, name: %s, value: %s\n", idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name, method->descriptor); if (!method->descriptor) { - method->descriptor = r_str_dup (NULL, "NULL"); - IFDBG eprintf("r_bin_java_read_next_method: Unable to find the descriptor for 0x%02x index.\n", method->descriptor_idx); + method->descriptor = rz_str_dup (NULL, "NULL"); + IFDBG eprintf("rz_bin_java_read_next_method: Unable to find the descriptor for 0x%02x index.\n", method->descriptor_idx); } IFDBG eprintf("Looking for a NameAndType CP with name_idx: %d descriptor_idx: %d\n", method->name_idx, method->descriptor_idx); - method->field_ref_cp_obj = r_bin_java_find_cp_ref_info_from_name_and_type (bin, method->name_idx, method->descriptor_idx); + method->field_ref_cp_obj = rz_bin_java_find_cp_ref_info_from_name_and_type (bin, method->name_idx, method->descriptor_idx); if (method->field_ref_cp_obj) { IFDBG eprintf("Found the obj.\n"); - item = r_bin_java_get_item_from_bin_cp_list (bin, method->field_ref_cp_obj->info.cp_method.class_idx); + item = rz_bin_java_get_item_from_bin_cp_list (bin, method->field_ref_cp_obj->info.cp_method.class_idx); IFDBG eprintf("Method class reference value: %d, which is: ord: %d, name: %s\n", method->field_ref_cp_obj->info.cp_method.class_idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name); - method->class_name = r_bin_java_get_item_name_from_bin_cp_list (bin, item); + method->class_name = rz_bin_java_get_item_name_from_bin_cp_list (bin, item); IFDBG eprintf("Method requesting ref_cp_obj the following which is: ord: %d, name: %s\n", method->field_ref_cp_obj->metas->ord, ((RBinJavaCPTypeMetas *)method->field_ref_cp_obj->metas->type_info)->name); IFDBG eprintf("MethodRef class name resolves to: %s\n", method->class_name); if (!method->class_name) { - method->class_name = r_str_dup (NULL, "NULL"); + method->class_name = rz_str_dup (NULL, "NULL"); } } else { // XXX - default to this class? - method->field_ref_cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); - method->class_name = r_bin_java_get_item_name_from_bin_cp_list (bin, method->field_ref_cp_obj); + method->field_ref_cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); + method->class_name = rz_bin_java_get_item_name_from_bin_cp_list (bin, method->field_ref_cp_obj); } IFDBG eprintf("Parsing %s(%s)\n", method->name, method->descriptor); if (method->attr_count > 0) { method->attr_offset = adv + offset; RBinJavaAttrInfo *attr = NULL; for (i = 0; i < method->attr_count; i++) { - attr = r_bin_java_read_next_attr (bin, adv + offset, buf, len); + attr = rz_bin_java_read_next_attr (bin, adv + offset, buf, len); if (!attr) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Method Attribute: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Method Attribute: %d.\n", i); break; } - if ((r_bin_java_get_attr_type_by_name (attr->name))->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { + if ((rz_bin_java_get_attr_type_by_name (attr->name))->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { // This is necessary for determing the appropriate number of bytes when readin // uoffset, ustack, ulocalvar values bin->cur_method_code_length = attr->info.code_attr.code_length; @@ -1436,10 +1436,10 @@ R_API RBinJavaField *r_bin_java_read_next_method(RBinJavaObj *bin, const ut64 of bin->ulocalvar_sz = 2;// (attr->info.code_attr.max_locals > 65535) ? 4 : 2; } IFDBG eprintf("Parsing @ 0x%"PFMT64x " (%s) = 0x%"PFMT64x " bytes\n", attr->file_offset, attr->name, attr->size); - r_list_append (method->attributes, attr); + rz_list_append (method->attributes, attr); adv += attr->size; if (adv + offset >= len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Method Attribute: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Method Attribute: %d.\n", i); break; } } @@ -1450,7 +1450,7 @@ R_API RBinJavaField *r_bin_java_read_next_method(RBinJavaObj *bin, const ut64 of return method; } -R_API RBinJavaField *r_bin_java_read_next_field(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len) { +RZ_API RBinJavaField *rz_bin_java_read_next_field(RBinJavaObj *bin, const ut64 offset, const ut8 *buffer, const ut64 len) { RBinJavaAttrInfo *attr; ut32 i, idx; ut8 buf[8]; @@ -1478,57 +1478,57 @@ R_API RBinJavaField *r_bin_java_read_next_field(RBinJavaObj *bin, const ut64 off field->name_idx = R_BIN_JAVA_USHORT (buf, 2); field->descriptor_idx = R_BIN_JAVA_USHORT (buf, 4); field->attr_count = R_BIN_JAVA_USHORT (buf, 6); - field->attributes = r_list_newf (r_bin_java_attribute_free); + field->attributes = rz_list_newf (rz_bin_java_attribute_free); field->type = R_BIN_JAVA_FIELD_TYPE_FIELD; adv += 8; field->metas->ord = bin->field_idx; idx = field->name_idx; - item = r_bin_java_get_item_from_bin_cp_list (bin, idx); - field->name = r_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) (field->name_idx)); + item = rz_bin_java_get_item_from_bin_cp_list (bin, idx); + field->name = rz_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) (field->name_idx)); IFDBG eprintf("Field name_idx: %d, which is: ord: %d, name: %s, value: %s\n", idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name, field->name); if (!field->name) { field->name = (char *) malloc (21); snprintf ((char *) field->name, 20, "sym.field_%08x", field->metas->ord); - IFDBG eprintf("r_bin_java_read_next_field: Unable to find the name for 0x%02x index.\n", field->name_idx); + IFDBG eprintf("rz_bin_java_read_next_field: Unable to find the name for 0x%02x index.\n", field->name_idx); } idx = field->descriptor_idx; - item = r_bin_java_get_item_from_bin_cp_list (bin, idx); - field->descriptor = r_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) field->descriptor_idx); + item = rz_bin_java_get_item_from_bin_cp_list (bin, idx); + field->descriptor = rz_bin_java_get_utf8_from_bin_cp_list (bin, (ut32) field->descriptor_idx); IFDBG eprintf("Field descriptor_idx: %d, which is: ord: %d, name: %s, value: %s\n", idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name, field->descriptor); if (!field->descriptor) { - field->descriptor = r_str_dup (NULL, "NULL"); - IFDBG eprintf("r_bin_java_read_next_field: Unable to find the descriptor for 0x%02x index.\n", field->descriptor_idx); + field->descriptor = rz_str_dup (NULL, "NULL"); + IFDBG eprintf("rz_bin_java_read_next_field: Unable to find the descriptor for 0x%02x index.\n", field->descriptor_idx); } IFDBG eprintf("Looking for a NameAndType CP with name_idx: %d descriptor_idx: %d\n", field->name_idx, field->descriptor_idx); - field->field_ref_cp_obj = r_bin_java_find_cp_ref_info_from_name_and_type (bin, field->name_idx, field->descriptor_idx); + field->field_ref_cp_obj = rz_bin_java_find_cp_ref_info_from_name_and_type (bin, field->name_idx, field->descriptor_idx); if (field->field_ref_cp_obj) { IFDBG eprintf("Found the obj.\n"); - item = r_bin_java_get_item_from_bin_cp_list (bin, field->field_ref_cp_obj->info.cp_field.class_idx); + item = rz_bin_java_get_item_from_bin_cp_list (bin, field->field_ref_cp_obj->info.cp_field.class_idx); IFDBG eprintf("Field class reference value: %d, which is: ord: %d, name: %s\n", field->field_ref_cp_obj->info.cp_field.class_idx, item->metas->ord, ((RBinJavaCPTypeMetas *)item->metas->type_info)->name); - field->class_name = r_bin_java_get_item_name_from_bin_cp_list (bin, item); + field->class_name = rz_bin_java_get_item_name_from_bin_cp_list (bin, item); IFDBG eprintf("Field requesting ref_cp_obj the following which is: ord: %d, name: %s\n", field->field_ref_cp_obj->metas->ord, ((RBinJavaCPTypeMetas *)field->field_ref_cp_obj->metas->type_info)->name); IFDBG eprintf("FieldRef class name resolves to: %s\n", field->class_name); if (!field->class_name) { - field->class_name = r_str_dup (NULL, "NULL"); + field->class_name = rz_str_dup (NULL, "NULL"); } } else { // XXX - default to this class? - field->field_ref_cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); - field->class_name = r_bin_java_get_item_name_from_bin_cp_list (bin, field->field_ref_cp_obj); + field->field_ref_cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); + field->class_name = rz_bin_java_get_item_name_from_bin_cp_list (bin, field->field_ref_cp_obj); } IFDBG eprintf("Parsing %s(%s)", field->name, field->descriptor); if (field->attr_count > 0) { field->attr_offset = adv + offset; for (i = 0; i < field->attr_count && offset + adv < len; i++) { - attr = r_bin_java_read_next_attr (bin, offset + adv, buffer, len); + attr = rz_bin_java_read_next_attr (bin, offset + adv, buffer, len); if (!attr) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Field Attribute: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Field Attribute: %d.\n", i); free (field->metas); free (field); return NULL; } - if ((r_bin_java_get_attr_type_by_name (attr->name))->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { + if ((rz_bin_java_get_attr_type_by_name (attr->name))->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { // This is necessary for determing the appropriate number of bytes when readin // uoffset, ustack, ulocalvar values bin->cur_method_code_length = attr->info.code_attr.code_length; @@ -1536,11 +1536,11 @@ R_API RBinJavaField *r_bin_java_read_next_field(RBinJavaObj *bin, const ut64 off bin->ustack_sz = 2;// (attr->info.code_attr.max_stack > 65535) ? 4 : 2; bin->ulocalvar_sz = 2;// (attr->info.code_attr.max_locals > 65535) ? 4 : 2; } - r_list_append (field->attributes, attr); + rz_list_append (field->attributes, attr); adv += attr->size; if (adv + offset >= len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Field Attribute: %d.\n", i); - r_bin_java_fmtype_free (field); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Field Attribute: %d.\n", i); + rz_bin_java_fmtype_free (field); return NULL; } } @@ -1549,15 +1549,15 @@ R_API RBinJavaField *r_bin_java_read_next_field(RBinJavaObj *bin, const ut64 off return field; } -R_API RBinJavaCPTypeObj *r_bin_java_clone_cp_idx(RBinJavaObj *bin, ut32 idx) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_clone_cp_idx(RBinJavaObj *bin, ut32 idx) { RBinJavaCPTypeObj *obj = NULL; if (bin) { - obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); + obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); } - return r_bin_java_clone_cp_item (obj); + return rz_bin_java_clone_cp_item (obj); } -R_API RBinJavaCPTypeObj *r_bin_java_clone_cp_item(RBinJavaCPTypeObj *obj) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_clone_cp_item(RBinJavaCPTypeObj *obj) { RBinJavaCPTypeObj *clone_obj = NULL; if (obj == NULL) { return clone_obj; @@ -1580,7 +1580,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_clone_cp_item(RBinJavaCPTypeObj *obj) { return clone_obj; } -R_API RBinJavaCPTypeObj *r_bin_java_read_next_constant_pool_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_read_next_constant_pool_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, ut64 len) { RBinJavaCPTypeMetas *java_constant_info = NULL; ut8 tag = 0; ut64 buf_sz = 0; @@ -1592,7 +1592,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_read_next_constant_pool_item(RBinJavaObj *bi eprintf ("Invalid tag '%d' at offset 0x%08"PFMT64x "\n", tag, (ut64) offset); return NULL; #if 0 - java_obj = r_bin_java_unknown_cp_new (bin, &tag, 1); + java_obj = rz_bin_java_unknown_cp_new (bin, &tag, 1); if (java_obj != NULL && java_obj->metas != NULL) { java_obj->file_offset = offset; java_obj->loadaddr = bin->loadaddr; @@ -1637,7 +1637,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_read_next_constant_pool_item(RBinJavaObj *bi return java_obj; } -R_API RBinJavaInterfaceInfo *r_bin_java_read_next_interface_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API RBinJavaInterfaceInfo *rz_bin_java_read_next_interface_item(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { ut8 idx[2] = { 0 }; @@ -1647,13 +1647,13 @@ R_API RBinJavaInterfaceInfo *r_bin_java_read_next_interface_item(RBinJavaObj *bi return NULL; } memcpy (&idx, if_buf, 2); - ifobj = r_bin_java_interface_new (bin, if_buf, len - offset); + ifobj = rz_bin_java_interface_new (bin, if_buf, len - offset); if (ifobj) { ifobj->file_offset = offset; } return ifobj; } -// R_API void addrow (RBinJavaObj *bin, int addr, int line) { +// RZ_API void addrow (RBinJavaObj *bin, int addr, int line) { // int n = bin->lines.count++; //// XXX. possible memleak // bin->lines.addr = realloc (bin->lines.addr, sizeof (int)*n+1); @@ -1661,11 +1661,11 @@ R_API RBinJavaInterfaceInfo *r_bin_java_read_next_interface_item(RBinJavaObj *bi // bin->lines.line = realloc (bin->lines.line, sizeof (int)*n+1); // bin->lines.line[n] = line; // } -// R_API struct r_bin_java_cp_item_t* r_bin_java_get_item_from_cp_CP(RBinJavaObj *bin, int i) { +// RZ_API struct rz_bin_java_cp_item_t* rz_bin_java_get_item_from_cp_CP(RBinJavaObj *bin, int i) { // return (i<0||i>bin->cf.cp_count)? &cp_null_item: &bin->cp_items[i]; // } -R_API char *r_bin_java_get_utf8_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { +RZ_API char *rz_bin_java_get_utf8_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1675,10 +1675,10 @@ R_API char *r_bin_java_get_utf8_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { if (bin == NULL) { return NULL; } - return r_bin_java_get_utf8_from_cp_item_list (bin->cp_list, idx); + return rz_bin_java_get_utf8_from_cp_item_list (bin->cp_list, idx); } -R_API ut32 r_bin_java_get_utf8_len_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { +RZ_API ut32 rz_bin_java_get_utf8_len_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1688,10 +1688,10 @@ R_API ut32 r_bin_java_get_utf8_len_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) if (bin == NULL) { return 0; } - return r_bin_java_get_utf8_len_from_cp_item_list (bin->cp_list, idx); + return rz_bin_java_get_utf8_len_from_cp_item_list (bin->cp_list, idx); } -R_API char *r_bin_java_get_name_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { +RZ_API char *rz_bin_java_get_name_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1701,10 +1701,10 @@ R_API char *r_bin_java_get_name_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { if (bin == NULL) { return NULL; } - return r_bin_java_get_name_from_cp_item_list (bin->cp_list, idx); + return rz_bin_java_get_name_from_cp_item_list (bin->cp_list, idx); } -R_API char *r_bin_java_get_desc_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { +RZ_API char *rz_bin_java_get_desc_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1714,10 +1714,10 @@ R_API char *r_bin_java_get_desc_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { if (bin == NULL) { return NULL; } - return r_bin_java_get_desc_from_cp_item_list (bin->cp_list, idx); + return rz_bin_java_get_desc_from_cp_item_list (bin->cp_list, idx); } -R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1728,39 +1728,39 @@ R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, return NULL; } if (idx > bin->cp_count || idx == 0) { - return r_bin_java_get_java_null_cp (); + return rz_bin_java_get_java_null_cp (); } - return r_bin_java_get_item_from_cp_item_list (bin->cp_list, idx); + return rz_bin_java_get_item_from_cp_item_list (bin->cp_list, idx); } -R_API char *r_bin_java_get_item_name_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_get_item_name_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj) { char *res = NULL; /* Given a constant poool object Class, FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. - @param cp_list: RList of RBinJavaCPTypeObj * + @param cp_list: RzList of RBinJavaCPTypeObj * @param obj object to look up the name for @rvalue char* (user frees) or NULL */ if (bin && obj) { - res = r_bin_java_get_item_name_from_cp_item_list ( + res = rz_bin_java_get_item_name_from_cp_item_list ( bin->cp_list, obj, MAX_CPITEMS); } return res; } -R_API char *r_bin_java_get_item_desc_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_get_item_desc_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj) { /* Given a constant poool object Class, FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. - @param cp_list: RList of RBinJavaCPTypeObj * + @param cp_list: RzList of RBinJavaCPTypeObj * @param obj object to look up the name for @rvalue char* (user frees) or NULL */ - return bin? r_bin_java_get_item_desc_from_cp_item_list (bin->cp_list, obj, MAX_CPITEMS): NULL; + return bin? rz_bin_java_get_item_desc_from_cp_item_list (bin->cp_list, obj, MAX_CPITEMS): NULL; } -R_API char *r_bin_java_get_utf8_from_cp_item_list(RList *cp_list, ut64 idx) { +RZ_API char *rz_bin_java_get_utf8_from_cp_item_list(RzList *cp_list, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1768,16 +1768,16 @@ R_API char *r_bin_java_get_utf8_from_cp_item_list(RList *cp_list, ut64 idx) { rvalue: new char* for caller to free. */ char *value = NULL; - RListIter *iter; + RzListIter *iter; if (!cp_list) { return NULL; } - RBinJavaCPTypeObj *item = (RBinJavaCPTypeObj *) r_list_get_n (cp_list, idx); + RBinJavaCPTypeObj *item = (RBinJavaCPTypeObj *) rz_list_get_n (cp_list, idx); if (item && item->tag == R_BIN_JAVA_CP_UTF8 && item->metas->ord == idx) { value = convert_string ((const char *) item->info.cp_utf8.bytes, item->info.cp_utf8.length); } if (!value) { - r_list_foreach (cp_list, iter, item) { + rz_list_foreach (cp_list, iter, item) { if (item && (item->tag == R_BIN_JAVA_CP_UTF8) && item->metas->ord == idx) { value = convert_string ((const char *) item->info.cp_utf8.bytes, item->info.cp_utf8.length); break; @@ -1787,7 +1787,7 @@ R_API char *r_bin_java_get_utf8_from_cp_item_list(RList *cp_list, ut64 idx) { return value; } -R_API ut32 r_bin_java_get_utf8_len_from_cp_item_list(RList *cp_list, ut64 idx) { +RZ_API ut32 rz_bin_java_get_utf8_len_from_cp_item_list(RzList *cp_list, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. If the idx not found by directly going to the list index, @@ -1795,16 +1795,16 @@ R_API ut32 r_bin_java_get_utf8_len_from_cp_item_list(RList *cp_list, ut64 idx) { rvalue: new ut32 . */ ut32 value = -1; - RListIter *iter; + RzListIter *iter; if (!cp_list) { return 0; } - RBinJavaCPTypeObj *item = (RBinJavaCPTypeObj *) r_list_get_n (cp_list, idx); + RBinJavaCPTypeObj *item = (RBinJavaCPTypeObj *) rz_list_get_n (cp_list, idx); if (item && (item->tag == R_BIN_JAVA_CP_UTF8) && item->metas->ord == idx) { value = item->info.cp_utf8.length; } if (value == -1) { - r_list_foreach (cp_list, iter, item) { + rz_list_foreach (cp_list, iter, item) { if (item && (item->tag == R_BIN_JAVA_CP_UTF8) && item->metas->ord == idx) { value = item->info.cp_utf8.length; break; @@ -1814,7 +1814,7 @@ R_API ut32 r_bin_java_get_utf8_len_from_cp_item_list(RList *cp_list, ut64 idx) { return value; } -R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_cp_item_list(RList *cp_list, ut64 idx) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_item_from_cp_item_list(RzList *cp_list, ut64 idx) { /* Search through the Constant Pool list for the given CP Index. rvalue: RBinJavaObj * @@ -1823,15 +1823,15 @@ R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_cp_item_list(RList *cp_list, u if (cp_list == NULL) { return NULL; } - item = (RBinJavaCPTypeObj *) r_list_get_n (cp_list, idx); + item = (RBinJavaCPTypeObj *) rz_list_get_n (cp_list, idx); return item; } -R_API char *r_bin_java_get_item_name_from_cp_item_list(RList *cp_list, RBinJavaCPTypeObj *obj, int depth) { +RZ_API char *rz_bin_java_get_item_name_from_cp_item_list(RzList *cp_list, RBinJavaCPTypeObj *obj, int depth) { /* Given a constant poool object Class, FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. - @param cp_list: RList of RBinJavaCPTypeObj * + @param cp_list: RzList of RBinJavaCPTypeObj * @param obj object to look up the name for @rvalue ut8* (user frees) or NULL */ @@ -1840,18 +1840,18 @@ R_API char *r_bin_java_get_item_name_from_cp_item_list(RList *cp_list, RBinJavaC } switch (obj->tag) { case R_BIN_JAVA_CP_NAMEANDTYPE: - return r_bin_java_get_utf8_from_cp_item_list ( + return rz_bin_java_get_utf8_from_cp_item_list ( cp_list, obj->info.cp_name_and_type.name_idx); case R_BIN_JAVA_CP_CLASS: - return r_bin_java_get_utf8_from_cp_item_list ( + return rz_bin_java_get_utf8_from_cp_item_list ( cp_list, obj->info.cp_class.name_idx); // XXX - Probably not good form, but they are the same memory structure case R_BIN_JAVA_CP_FIELDREF: case R_BIN_JAVA_CP_INTERFACEMETHOD_REF: case R_BIN_JAVA_CP_METHODREF: - obj = r_bin_java_get_item_from_cp_item_list ( + obj = rz_bin_java_get_item_from_cp_item_list ( cp_list, obj->info.cp_method.name_and_type_idx); - return r_bin_java_get_item_name_from_cp_item_list ( + return rz_bin_java_get_item_name_from_cp_item_list ( cp_list, obj, depth - 1); default: return NULL; @@ -1862,24 +1862,24 @@ R_API char *r_bin_java_get_item_name_from_cp_item_list(RList *cp_list, RBinJavaC return NULL; } -R_API char *r_bin_java_get_name_from_cp_item_list(RList *cp_list, ut64 idx) { +RZ_API char *rz_bin_java_get_name_from_cp_item_list(RzList *cp_list, ut64 idx) { /* Given a constant poool object Class, FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. - @param cp_list: RList of RBinJavaCPTypeObj * + @param cp_list: RzList of RBinJavaCPTypeObj * @param obj object to look up the name for @rvalue ut8* (user frees) or NULL */ - RBinJavaCPTypeObj *obj = r_bin_java_get_item_from_cp_item_list ( + RBinJavaCPTypeObj *obj = rz_bin_java_get_item_from_cp_item_list ( cp_list, idx); if (obj && cp_list) { - return r_bin_java_get_item_name_from_cp_item_list ( + return rz_bin_java_get_item_name_from_cp_item_list ( cp_list, obj, MAX_CPITEMS); } return NULL; } -R_API char *r_bin_java_get_item_desc_from_cp_item_list(RList *cp_list, RBinJavaCPTypeObj *obj, int depth) { +RZ_API char *rz_bin_java_get_item_desc_from_cp_item_list(RzList *cp_list, RBinJavaCPTypeObj *obj, int depth) { /* Given a constant poool object FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. @@ -1890,15 +1890,15 @@ R_API char *r_bin_java_get_item_desc_from_cp_item_list(RList *cp_list, RBinJavaC } switch (obj->tag) { case R_BIN_JAVA_CP_NAMEANDTYPE: - return r_bin_java_get_utf8_from_cp_item_list (cp_list, + return rz_bin_java_get_utf8_from_cp_item_list (cp_list, obj->info.cp_name_and_type.descriptor_idx); // XXX - Probably not good form, but they are the same memory structure case R_BIN_JAVA_CP_FIELDREF: case R_BIN_JAVA_CP_INTERFACEMETHOD_REF: case R_BIN_JAVA_CP_METHODREF: - obj = r_bin_java_get_item_from_cp_item_list (cp_list, + obj = rz_bin_java_get_item_from_cp_item_list (cp_list, obj->info.cp_method.name_and_type_idx); - return r_bin_java_get_item_desc_from_cp_item_list ( + return rz_bin_java_get_item_desc_from_cp_item_list ( cp_list, obj, depth - 1); default: return NULL; @@ -1906,28 +1906,28 @@ R_API char *r_bin_java_get_item_desc_from_cp_item_list(RList *cp_list, RBinJavaC return NULL; } -R_API char *r_bin_java_get_desc_from_cp_item_list(RList *cp_list, ut64 idx) { +RZ_API char *rz_bin_java_get_desc_from_cp_item_list(RzList *cp_list, ut64 idx) { /* Given a constant poool object FieldRef, MethodRef, or InterfaceMethodRef return the actual descriptor string. @rvalue ut8* (user frees) or NULL */ - RBinJavaCPTypeObj *obj = r_bin_java_get_item_from_cp_item_list (cp_list, idx); + RBinJavaCPTypeObj *obj = rz_bin_java_get_item_from_cp_item_list (cp_list, idx); if (cp_list == NULL) { return NULL; } - return r_bin_java_get_item_desc_from_cp_item_list (cp_list, obj, MAX_CPITEMS); + return rz_bin_java_get_item_desc_from_cp_item_list (cp_list, obj, MAX_CPITEMS); } -R_API RBinJavaAttrInfo *r_bin_java_get_method_code_attribute(const RBinJavaField *method) { +RZ_API RBinJavaAttrInfo *rz_bin_java_get_method_code_attribute(const RBinJavaField *method) { /* Search through a methods attributes and return the code attr. rvalue: RBinJavaAttrInfo* if found otherwise NULL. */ RBinJavaAttrInfo *res = NULL, *attr = NULL; - RListIter *iter; + RzListIter *iter; if (method) { - r_list_foreach (method->attributes, iter, attr) { + rz_list_foreach (method->attributes, iter, attr) { if (attr && (attr->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR)) { res = attr; break; @@ -1937,16 +1937,16 @@ R_API RBinJavaAttrInfo *r_bin_java_get_method_code_attribute(const RBinJavaField return res; } -R_API RBinJavaAttrInfo *r_bin_java_get_attr_from_field(RBinJavaField *field, R_BIN_JAVA_ATTR_TYPE attr_type, ut32 pos) { +RZ_API RBinJavaAttrInfo *rz_bin_java_get_attr_from_field(RBinJavaField *field, R_BIN_JAVA_ATTR_TYPE attr_type, ut32 pos) { /* Search through the Attribute list for the given type starting at position pos. rvalue: NULL or the first occurrence of attr_type after pos */ RBinJavaAttrInfo *attr = NULL, *item; - RListIter *iter; + RzListIter *iter; ut32 i = 0; if (field) { - r_list_foreach (field->attributes, iter, item) { + rz_list_foreach (field->attributes, iter, item) { // Note the increment happens after the comparison if ((i++) >= pos) { if (item && (item->type == attr_type)) { @@ -1959,7 +1959,7 @@ R_API RBinJavaAttrInfo *r_bin_java_get_attr_from_field(RBinJavaField *field, R_B return attr; } -R_API ut8 *r_bin_java_get_attr_buf(RBinJavaObj *bin, ut64 sz, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut8 *rz_bin_java_get_attr_buf(RBinJavaObj *bin, ut64 sz, const ut64 offset, const ut8 *buf, const ut64 len) { ut8 *attr_buf = NULL; int pending = len - offset; const ut8 *a_buf = offset + buf; @@ -1973,7 +1973,7 @@ R_API ut8 *r_bin_java_get_attr_buf(RBinJavaObj *bin, ut64 sz, const ut64 offset, return attr_buf; } -R_API RBinJavaAttrInfo *r_bin_java_default_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_default_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { // NOTE: this function receives the buffer offset in the original buffer, // but the buffer is already point to that particular offset. // XXX - all the code that relies on this function should probably be modified @@ -1989,25 +1989,25 @@ R_API RBinJavaAttrInfo *r_bin_java_default_attr_new(RBinJavaObj *bin, ut8 *buffe free (attr); return NULL; } - attr->is_attr_in_old_format = r_bin_java_is_old_format(bin); + attr->is_attr_in_old_format = rz_bin_java_is_old_format(bin); attr->file_offset = buf_offset; attr->name_idx = R_BIN_JAVA_USHORT (buffer, 0); attr->length = R_BIN_JAVA_UINT (buffer, 2); attr->size = R_BIN_JAVA_UINT (buffer, 2) + 6; - attr->name = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->name_idx); + attr->name = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->name_idx); if (attr->name == NULL) { // Something bad has happened - attr->name = r_str_dup (NULL, "NULL"); - eprintf ("r_bin_java_default_attr_new: Unable to find the name for %d index.\n", attr->name_idx); + attr->name = rz_str_dup (NULL, "NULL"); + eprintf ("rz_bin_java_default_attr_new: Unable to find the name for %d index.\n", attr->name_idx); } - type_info = r_bin_java_get_attr_type_by_name (attr->name); + type_info = rz_bin_java_get_attr_type_by_name (attr->name); attr->metas->ord = (R_BIN_JAVA_GLOBAL_BIN->attr_idx++); attr->metas->type_info = (void *) type_info; // IFDBG eprintf (" Addrs for type_info [tag=%d]: 0x%08"PFMT64x"\n", type_val, &attr->metas->type_info); return attr; } -R_API RBinJavaAttrMetas *r_bin_java_get_attr_type_by_name(const char *name) { +RZ_API RBinJavaAttrMetas *rz_bin_java_get_attr_type_by_name(const char *name) { // TODO: use sdb/hashtable here int i; for (i = 0; i < RBIN_JAVA_ATTRS_METAS_SZ; i++) { @@ -2018,21 +2018,21 @@ R_API RBinJavaAttrMetas *r_bin_java_get_attr_type_by_name(const char *name) { return &RBIN_JAVA_ATTRS_METAS[R_BIN_JAVA_ATTR_TYPE_UNKNOWN_ATTR]; } -R_API RBinJavaAttrInfo *r_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 buf_len) { +RZ_API RBinJavaAttrInfo *rz_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 buf_len) { RBinJavaAttrInfo *attr = NULL; ut32 sz = 0; ut8 *buffer = NULL; const ut8 *a_buf = offset + buf; ut8 attr_idx_len = 6; if (offset + 6 > buf_len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile in Attribute offset " + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile in Attribute offset " "(0x%"PFMT64x ") > len of remaining bytes (0x%"PFMT64x ").\n", offset, buf_len); return NULL; } // ut16 attr_idx, ut32 length of attr. - sz = R_BIN_JAVA_UINT (a_buf, 2) + attr_idx_len; // r_bin_java_read_int (bin, buf_offset+2) + attr_idx_len; + sz = R_BIN_JAVA_UINT (a_buf, 2) + attr_idx_len; // rz_bin_java_read_int (bin, buf_offset+2) + attr_idx_len; if (sz + offset > buf_len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile in Attribute len " + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile in Attribute len " "(0x%x) + offset (0x%"PFMT64x ") exceeds length of buffer (0x%"PFMT64x ").\n", sz, offset, buf_len); return NULL; @@ -2042,10 +2042,10 @@ R_API RBinJavaAttrInfo *r_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 o // are not included in the attribute length // , // sz, buf_offset, buf_offset+sz); - buffer = r_bin_java_get_attr_buf (bin, sz, offset, buf, buf_len); + buffer = rz_bin_java_get_attr_buf (bin, sz, offset, buf, buf_len); // printf ("%d %d %d\n", sz, buf_len, offset); if (offset < buf_len) { - attr = r_bin_java_read_next_attr_from_buffer (bin, buffer, buf_len - offset, offset); + attr = rz_bin_java_read_next_attr_from_buffer (bin, buffer, buf_len - offset, offset); free (buffer); if (!attr) { @@ -2059,14 +2059,14 @@ R_API RBinJavaAttrInfo *r_bin_java_read_next_attr(RBinJavaObj *bin, const ut64 o return attr; } -R_API RBinJavaAttrInfo *r_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, ut8 *buffer, st64 sz, st64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, ut8 *buffer, st64 sz, st64 buf_offset) { RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; ut16 name_idx; st64 nsz; if (!buffer || ((int) sz) < 4 || buf_offset < 0) { - eprintf ("r_bin_Java_read_next_attr_from_buffer: invalid buffer size %d\n", (int) sz); + eprintf ("rz_bin_Java_read_next_attr_from_buffer: invalid buffer size %d\n", (int) sz); return NULL; } name_idx = R_BIN_JAVA_USHORT (buffer, offset); @@ -2074,12 +2074,12 @@ R_API RBinJavaAttrInfo *r_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, nsz = R_BIN_JAVA_UINT (buffer, offset); offset += 4; - char *name = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, name_idx); + char *name = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, name_idx); if (!name) { name = strdup ("unknown"); } - IFDBG eprintf("r_bin_java_read_next_attr: name_idx = %d is %s\n", name_idx, name); - RBinJavaAttrMetas *type_info = r_bin_java_get_attr_type_by_name (name); + IFDBG eprintf("rz_bin_java_read_next_attr: name_idx = %d is %s\n", name_idx, name); + RBinJavaAttrMetas *type_info = rz_bin_java_get_attr_type_by_name (name); if (type_info) { IFDBG eprintf("Typeinfo: %s, was %s\n", type_info->name, name); // printf ("SZ %d %d %d\n", nsz, sz, buf_offset); @@ -2091,13 +2091,13 @@ R_API RBinJavaAttrInfo *r_bin_java_read_next_attr_from_buffer(RBinJavaObj *bin, attr->metas->ord = (R_BIN_JAVA_GLOBAL_BIN->attr_idx++); } } else { - eprintf ("r_bin_java_read_next_attr_from_buffer: Cannot find type_info for %s\n", name); + eprintf ("rz_bin_java_read_next_attr_from_buffer: Cannot find type_info for %s\n", name); } free (name); return attr; } -R_API ut64 r_bin_java_read_class_file2(RBinJavaObj *bin, const ut64 offset, const ut8 *obuf, ut64 len) { +RZ_API ut64 rz_bin_java_read_class_file2(RBinJavaObj *bin, const ut64 offset, const ut8 *obuf, ut64 len) { const ut8 *cf2_buf = obuf + offset; RBinJavaCPTypeObj *this_class_cp_obj = NULL; IFDBG eprintf("\n0x%"PFMT64x " Offset before reading the cf2 structure\n", offset); @@ -2117,43 +2117,43 @@ R_API ut64 r_bin_java_read_class_file2(RBinJavaObj *bin, const ut64 offset, cons free (bin->cf2.flags_str); free (bin->cf2.this_class_name); bin->cf2.flags_str = retrieve_class_method_access_string (bin->cf2.access_flags); - this_class_cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); - bin->cf2.this_class_name = r_bin_java_get_item_name_from_bin_cp_list (bin, this_class_cp_obj); + this_class_cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); + bin->cf2.this_class_name = rz_bin_java_get_item_name_from_bin_cp_list (bin, this_class_cp_obj); IFDBG eprintf("This class flags are: %s\n", bin->cf2.flags_str); return bin->cf2.cf2_size; } -R_API ut64 r_bin_java_parse_cp_pool(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut64 rz_bin_java_parse_cp_pool(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { int ord = 0; ut64 adv = 0; RBinJavaCPTypeObj *obj = NULL; const ut8 *cp_buf = buf + offset; - r_list_free (bin->cp_list); - bin->cp_list = r_list_newf (r_bin_java_constant_pool); + rz_list_free (bin->cp_list); + bin->cp_list = rz_list_newf (rz_bin_java_constant_pool); bin->cp_offset = offset; memcpy ((char *) &bin->cp_count, cp_buf, 2); bin->cp_count = R_BIN_JAVA_USHORT (cp_buf, 0) - 1; adv += 2; IFDBG eprintf("ConstantPoolCount %d\n", bin->cp_count); - r_list_append (bin->cp_list, r_bin_java_get_java_null_cp ()); + rz_list_append (bin->cp_list, rz_bin_java_get_java_null_cp ()); for (ord = 1, bin->cp_idx = 0; bin->cp_idx < bin->cp_count && adv < len; ord++, bin->cp_idx++) { - obj = r_bin_java_read_next_constant_pool_item (bin, offset + adv, buf, len); + obj = rz_bin_java_read_next_constant_pool_item (bin, offset + adv, buf, len); if (obj) { // IFDBG eprintf ("SUCCESS Read ConstantPoolItem %d\n", i); obj->metas->ord = ord; obj->idx = ord; - r_list_append (bin->cp_list, obj); + rz_list_append (bin->cp_list, obj); if (obj->tag == R_BIN_JAVA_CP_LONG || obj->tag == R_BIN_JAVA_CP_DOUBLE) { // i++; ord++; bin->cp_idx++; - r_list_append (bin->cp_list, &R_BIN_JAVA_NULL_TYPE); + rz_list_append (bin->cp_list, &R_BIN_JAVA_NULL_TYPE); } IFDBG ((RBinJavaCPTypeMetas *) obj->metas->type_info)->allocs->print_summary (obj); adv += ((RBinJavaCPTypeMetas *) obj->metas->type_info)->allocs->calc_size (obj); if (offset + adv > len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Constant Pool Object: %d.\n", ord); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Constant Pool Object: %d.\n", ord); break; } } else { @@ -2162,20 +2162,20 @@ R_API ut64 r_bin_java_parse_cp_pool(RBinJavaObj *bin, const ut64 offset, const u } } // Update the imports - r_bin_java_set_imports (bin); + rz_bin_java_set_imports (bin); bin->cp_size = adv; return bin->cp_size; } -R_API ut64 r_bin_java_parse_interfaces(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut64 rz_bin_java_parse_interfaces(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { int i = 0; ut64 adv = 0; RBinJavaInterfaceInfo *interfaces_obj; const ut8 *if_buf = buf + offset; bin->cp_offset = offset; bin->interfaces_offset = offset; - r_list_free (bin->interfaces_list); - bin->interfaces_list = r_list_newf (r_bin_java_interface_free); + rz_list_free (bin->interfaces_list); + bin->interfaces_list = rz_list_newf (rz_bin_java_interface_free); if (offset + 2 > len) { bin->interfaces_size = 0; return 0; @@ -2185,12 +2185,12 @@ R_API ut64 r_bin_java_parse_interfaces(RBinJavaObj *bin, const ut64 offset, cons IFDBG eprintf("Interfaces count: %d\n", bin->interfaces_count); if (bin->interfaces_count > 0) { for (i = 0; i < bin->interfaces_count; i++) { - interfaces_obj = r_bin_java_read_next_interface_item (bin, offset + adv, buf, len); + interfaces_obj = rz_bin_java_read_next_interface_item (bin, offset + adv, buf, len); if (interfaces_obj) { - r_list_append (bin->interfaces_list, interfaces_obj); + rz_list_append (bin->interfaces_list, interfaces_obj); adv += interfaces_obj->size; if (offset + adv > len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Interface: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Interface: %d.\n", i); break; } } else { @@ -2202,13 +2202,13 @@ R_API ut64 r_bin_java_parse_interfaces(RBinJavaObj *bin, const ut64 offset, cons return adv; } -R_API ut64 r_bin_java_parse_fields(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut64 rz_bin_java_parse_fields(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { int i = 0; ut64 adv = 0; RBinJavaField *field; const ut8 *fm_buf = buf + offset; - r_list_free (bin->fields_list); - bin->fields_list = r_list_newf (r_bin_java_fmtype_free); + rz_list_free (bin->fields_list); + bin->fields_list = rz_list_newf (rz_bin_java_fmtype_free); bin->fields_offset = offset; if (offset + 2 >= len) { return UT64_MAX; @@ -2218,13 +2218,13 @@ R_API ut64 r_bin_java_parse_fields(RBinJavaObj *bin, const ut64 offset, const ut IFDBG eprintf("Fields count: %d 0x%"PFMT64x "\n", bin->fields_count, bin->fields_offset); if (bin->fields_count > 0) { for (i = 0; i < bin->fields_count; i++, bin->field_idx++) { - field = r_bin_java_read_next_field (bin, offset + adv, buf, len); + field = rz_bin_java_read_next_field (bin, offset + adv, buf, len); if (field) { adv += field->size; - r_list_append (bin->fields_list, field); - IFDBG r_bin_java_print_field_summary(field); + rz_list_append (bin->fields_list, field); + IFDBG rz_bin_java_print_field_summary(field); if (adv + offset > len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Field: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Field: %d.\n", i); break; } } else { @@ -2237,7 +2237,7 @@ R_API ut64 r_bin_java_parse_fields(RBinJavaObj *bin, const ut64 offset, const ut return adv; } -R_API ut64 r_bin_java_parse_attrs(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut64 rz_bin_java_parse_attrs(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { int i = 0; ut64 adv = 0; const ut8 *a_buf = buf + offset; @@ -2245,22 +2245,22 @@ R_API ut64 r_bin_java_parse_attrs(RBinJavaObj *bin, const ut64 offset, const ut8 // Check if we can read that USHORT return UT64_MAX; } - r_list_free (bin->attrs_list); - bin->attrs_list = r_list_newf (r_bin_java_attribute_free); + rz_list_free (bin->attrs_list); + bin->attrs_list = rz_list_newf (rz_bin_java_attribute_free); bin->attrs_offset = offset; bin->attrs_count = R_BIN_JAVA_USHORT (a_buf, adv); adv += 2; if (bin->attrs_count > 0) { for (i = 0; i < bin->attrs_count; i++, bin->attr_idx++) { - RBinJavaAttrInfo *attr = r_bin_java_read_next_attr (bin, offset + adv, buf, len); + RBinJavaAttrInfo *attr = rz_bin_java_read_next_attr (bin, offset + adv, buf, len); if (!attr) { - // eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", i); + // eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", i); break; } - r_list_append (bin->attrs_list, attr); + rz_list_append (bin->attrs_list, attr); adv += attr->size; if (adv + offset >= len) { - // eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", i); + // eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", i); break; } } @@ -2269,13 +2269,13 @@ R_API ut64 r_bin_java_parse_attrs(RBinJavaObj *bin, const ut64 offset, const ut8 return adv; } -R_API ut64 r_bin_java_parse_methods(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { +RZ_API ut64 rz_bin_java_parse_methods(RBinJavaObj *bin, const ut64 offset, const ut8 *buf, const ut64 len) { int i = 0; ut64 adv = 0; RBinJavaField *method; const ut8 *fm_buf = buf + offset; - r_list_free (bin->methods_list); - bin->methods_list = r_list_newf (r_bin_java_fmtype_free); + rz_list_free (bin->methods_list); + bin->methods_list = rz_list_newf (rz_bin_java_fmtype_free); if (offset + 2 >= len) { return 0LL; @@ -2289,58 +2289,58 @@ R_API ut64 r_bin_java_parse_methods(RBinJavaObj *bin, const ut64 offset, const u bin->main_code_attr = NULL; bin->entrypoint_code_attr = NULL; for (i = 0; i < bin->methods_count; i++, bin->method_idx++) { - method = r_bin_java_read_next_method (bin, offset + adv, buf, len); + method = rz_bin_java_read_next_method (bin, offset + adv, buf, len); if (method) { adv += method->size; - r_list_append (bin->methods_list, method); + rz_list_append (bin->methods_list, method); } // Update Main, Init, or Class Init if (method && !strcmp ((const char *) method->name, "main")) { bin->main = method; // get main code attr - bin->main_code_attr = r_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); + bin->main_code_attr = rz_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); } else if (method && (!strcmp ((const char *) method->name, "") || !strcmp ((const char *) method->name, "init"))) { IFDBG eprintf("Found an init function.\n"); bin->entrypoint = method; - bin->entrypoint_code_attr = r_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); + bin->entrypoint_code_attr = rz_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); } else if (method && (!strcmp ((const char *) method->name, "") || !strcmp ((const char *) method->name, "cinit"))) { bin->cf2.this_class_entrypoint = method; - bin->cf2.this_class_entrypoint_code_attr = r_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); + bin->cf2.this_class_entrypoint_code_attr = rz_bin_java_get_attr_from_field (method, R_BIN_JAVA_ATTR_TYPE_CODE_ATTR, 0); } if (adv + offset > len) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Method: %d.\n", i); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Method: %d.\n", i); break; } - IFDBG r_bin_java_print_field_summary(method); + IFDBG rz_bin_java_print_field_summary(method); } bin->methods_size = adv; return adv; } -R_API int r_bin_java_new_bin(RBinJavaObj *bin, ut64 loadaddr, Sdb *kv, const ut8 *buf, ut64 len) { +RZ_API int rz_bin_java_new_bin(RBinJavaObj *bin, ut64 loadaddr, Sdb *kv, const ut8 *buf, ut64 len) { R_BIN_JAVA_GLOBAL_BIN = bin; - if (!r_str_constpool_init (&bin->constpool)) { + if (!rz_str_constpool_init (&bin->constpool)) { return false; } bin->lines.count = 0; bin->loadaddr = loadaddr; - r_bin_java_get_java_null_cp (); - bin->id = r_num_rand (UT32_MAX); + rz_bin_java_get_java_null_cp (); + bin->id = rz_num_rand (UT32_MAX); bin->kv = kv ? kv : sdb_new (NULL, NULL, 0); bin->AllJavaBinObjs = NULL; - return r_bin_java_load_bin (bin, buf, len); + return rz_bin_java_load_bin (bin, buf, len); } -R_API int r_bin_java_load_bin(RBinJavaObj *bin, const ut8 *buf, ut64 buf_sz) { +RZ_API int rz_bin_java_load_bin(RBinJavaObj *bin, const ut8 *buf, ut64 buf_sz) { ut64 adv = 0; R_BIN_JAVA_GLOBAL_BIN = bin; if (!bin) { return false; } - r_bin_java_reset_bin_info (bin); + rz_bin_java_reset_bin_info (bin); memcpy ((ut8 *) &bin->cf, buf, 10); if (memcmp (bin->cf.cafebabe, "\xCA\xFE\xBA\xBE", 4)) { - eprintf ("r_bin_java_new_bin: Invalid header (%02x %02x %02x %02x)\n", + eprintf ("rz_bin_java_new_bin: Invalid header (%02x %02x %02x %02x)\n", bin->cf.cafebabe[0], bin->cf.cafebabe[1], bin->cf.cafebabe[2], bin->cf.cafebabe[3]); return false; @@ -2351,37 +2351,37 @@ R_API int r_bin_java_load_bin(RBinJavaObj *bin, const ut8 *buf, ut64 buf_sz) { } adv += 8; // -2 so that the cp_count will be parsed - adv += r_bin_java_parse_cp_pool (bin, adv, buf, buf_sz); + adv += rz_bin_java_parse_cp_pool (bin, adv, buf, buf_sz); if (adv > buf_sz) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Constant Pool.\n"); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Constant Pool.\n"); return true; } - adv += r_bin_java_read_class_file2 (bin, adv, buf, buf_sz); + adv += rz_bin_java_read_class_file2 (bin, adv, buf, buf_sz); if (adv > buf_sz) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after class file info.\n"); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after class file info.\n"); return true; } IFDBG eprintf("This class: %d %s\n", bin->cf2.this_class, bin->cf2.this_class_name); IFDBG eprintf("0x%"PFMT64x " Access flags: 0x%04x\n", adv, bin->cf2.access_flags); - adv += r_bin_java_parse_interfaces (bin, adv, buf, buf_sz); + adv += rz_bin_java_parse_interfaces (bin, adv, buf, buf_sz); if (adv > buf_sz) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Interfaces.\n"); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Interfaces.\n"); return true; } - adv += r_bin_java_parse_fields (bin, adv, buf, buf_sz); + adv += rz_bin_java_parse_fields (bin, adv, buf, buf_sz); if (adv > buf_sz) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Fields.\n"); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Fields.\n"); return true; } - adv += r_bin_java_parse_methods (bin, adv, buf, buf_sz); + adv += rz_bin_java_parse_methods (bin, adv, buf, buf_sz); if (adv > buf_sz) { - eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Methods.\n"); + eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Methods.\n"); return true; } - adv += r_bin_java_parse_attrs (bin, adv, buf, buf_sz); + adv += rz_bin_java_parse_attrs (bin, adv, buf, buf_sz); bin->calc_size = adv; // if (adv > buf_sz) { - // eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Attributes.\n"); + // eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Attributes.\n"); // return true; // } @@ -2391,20 +2391,20 @@ R_API int r_bin_java_load_bin(RBinJavaObj *bin, const ut8 *buf, ut64 buf_sz) { return true; } -R_API char *r_bin_java_get_version(RBinJavaObj *bin) { - return r_str_newf ("0x%02x%02x 0x%02x%02x", +RZ_API char *rz_bin_java_get_version(RBinJavaObj *bin) { + return rz_str_newf ("0x%02x%02x 0x%02x%02x", bin->cf.major[1], bin->cf.major[0], bin->cf.minor[1], bin->cf.minor[0]); } -R_API RList *r_bin_java_get_entrypoints(RBinJavaObj *bin) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API RzList *rz_bin_java_get_entrypoints(RBinJavaObj *bin) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaField *fm_type; - RList *ret = r_list_newf (free); + RzList *ret = rz_list_newf (free); if (!ret) { return NULL; } - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { if (!strcmp (fm_type->name, "main") || !strcmp (fm_type->name, "") || !strcmp (fm_type->name, "") @@ -2412,17 +2412,17 @@ R_API RList *r_bin_java_get_entrypoints(RBinJavaObj *bin) { RBinAddr *addr = R_NEW0 (RBinAddr); if (addr) { addr->vaddr = addr->paddr = \ - r_bin_java_get_method_code_offset (fm_type) + bin->loadaddr; + rz_bin_java_get_method_code_offset (fm_type) + bin->loadaddr; addr->hpaddr = fm_type->file_offset; - r_list_append (ret, addr); + rz_list_append (ret, addr); } } } return ret; } -R_API RBinJavaField *r_bin_java_get_method_code_attribute_with_addr(RBinJavaObj *bin, ut64 addr) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API RBinJavaField *rz_bin_java_get_method_code_attribute_with_addr(RBinJavaObj *bin, ut64 addr) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaField *fm_type, *res = NULL; if (bin == NULL && R_BIN_JAVA_GLOBAL_BIN) { bin = R_BIN_JAVA_GLOBAL_BIN; @@ -2430,9 +2430,9 @@ R_API RBinJavaField *r_bin_java_get_method_code_attribute_with_addr(RBinJavaObj eprintf ("Attempting to analyse function when the R_BIN_JAVA_GLOBAL_BIN has not been set.\n"); return NULL; } - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { - ut64 offset = r_bin_java_get_method_code_offset (fm_type) + bin->loadaddr, - size = r_bin_java_get_method_code_size (fm_type); + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + ut64 offset = rz_bin_java_get_method_code_offset (fm_type) + bin->loadaddr, + size = rz_bin_java_get_method_code_size (fm_type); if (addr >= offset && addr <= size + offset) { res = fm_type; } @@ -2440,7 +2440,7 @@ R_API RBinJavaField *r_bin_java_get_method_code_attribute_with_addr(RBinJavaObj return res; } -R_API RBinAddr *r_bin_java_get_entrypoint(RBinJavaObj *bin, int sym) { +RZ_API RBinAddr *rz_bin_java_get_entrypoint(RBinJavaObj *bin, int sym) { RBinAddr *ret = NULL; ret = R_NEW0 (RBinAddr); if (!ret) { @@ -2450,16 +2450,16 @@ R_API RBinAddr *r_bin_java_get_entrypoint(RBinJavaObj *bin, int sym) { switch (sym) { case R_BIN_SYM_ENTRY: case R_BIN_SYM_INIT: - ret->paddr = r_bin_java_find_method_offset (bin, ""); + ret->paddr = rz_bin_java_find_method_offset (bin, ""); if (ret->paddr == UT64_MAX) { - ret->paddr = r_bin_java_find_method_offset (bin, ""); + ret->paddr = rz_bin_java_find_method_offset (bin, ""); } break; case R_BIN_SYM_FINI: ret->paddr = UT64_MAX; break; case R_BIN_SYM_MAIN: - ret->paddr = r_bin_java_find_method_offset (bin, "main"); + ret->paddr = rz_bin_java_find_method_offset (bin, "main"); break; default: ret->paddr = -1; @@ -2470,11 +2470,11 @@ R_API RBinAddr *r_bin_java_get_entrypoint(RBinJavaObj *bin, int sym) { return ret; } -R_API ut64 r_bin_java_get_method_code_size(RBinJavaField *fm_type) { - RListIter *attr_iter = NULL, *attr_iter_tmp = NULL; +RZ_API ut64 rz_bin_java_get_method_code_size(RBinJavaField *fm_type) { + RzListIter *attr_iter = NULL, *attr_iter_tmp = NULL; RBinJavaAttrInfo *attr = NULL; ut64 sz = 0; - r_list_foreach_safe (fm_type->attributes, attr_iter, attr_iter_tmp, attr) { + rz_list_foreach_safe (fm_type->attributes, attr_iter, attr_iter_tmp, attr) { if (attr->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { sz = attr->info.code_attr.code_length; break; @@ -2483,24 +2483,24 @@ R_API ut64 r_bin_java_get_method_code_size(RBinJavaField *fm_type) { return sz; } -R_API ut64 r_bin_java_find_method_offset(RBinJavaObj *bin, const char *method_name) { - RListIter *attr_iter = NULL, *attr_iter_tmp = NULL; +RZ_API ut64 rz_bin_java_find_method_offset(RBinJavaObj *bin, const char *method_name) { + RzListIter *attr_iter = NULL, *attr_iter_tmp = NULL; RBinJavaField *method = NULL; ut64 offset = -1; - r_list_foreach_safe (bin->methods_list, attr_iter, attr_iter_tmp, method) { + rz_list_foreach_safe (bin->methods_list, attr_iter, attr_iter_tmp, method) { if (method && !strcmp ((const char *) method->name, method_name)) { - offset = r_bin_java_get_method_code_offset (method) + bin->loadaddr; + offset = rz_bin_java_get_method_code_offset (method) + bin->loadaddr; break; } } return offset; } -R_API ut64 r_bin_java_get_method_code_offset(RBinJavaField *fm_type) { - RListIter *attr_iter = NULL, *attr_iter_tmp = NULL; +RZ_API ut64 rz_bin_java_get_method_code_offset(RBinJavaField *fm_type) { + RzListIter *attr_iter = NULL, *attr_iter_tmp = NULL; RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - r_list_foreach_safe (fm_type->attributes, attr_iter, attr_iter_tmp, attr) { + rz_list_foreach_safe (fm_type->attributes, attr_iter, attr_iter_tmp, attr) { if (attr->type == R_BIN_JAVA_ATTR_TYPE_CODE_ATTR) { offset = attr->info.code_attr.code_offset; break; @@ -2509,7 +2509,7 @@ R_API ut64 r_bin_java_get_method_code_offset(RBinJavaField *fm_type) { return offset; } -R_API RBinField *r_bin_java_allocate_rbinfield(void) { +RZ_API RBinField *rz_bin_java_allocate_rbinfield(void) { RBinField *t = (RBinField *) malloc (sizeof (RBinField)); if (t) { memset (t, 0, sizeof (RBinField)); @@ -2517,8 +2517,8 @@ R_API RBinField *r_bin_java_allocate_rbinfield(void) { return t; } -R_API RBinField *r_bin_java_create_new_rbinfield_from_field(RBinJavaField *fm_type, ut64 baddr) { - RBinField *field = r_bin_java_allocate_rbinfield (); +RZ_API RBinField *rz_bin_java_create_new_rbinfield_from_field(RBinJavaField *fm_type, ut64 baddr) { + RBinField *field = rz_bin_java_allocate_rbinfield (); if (field) { field->name = strdup (fm_type->name); field->paddr = fm_type->file_offset + baddr; @@ -2527,7 +2527,7 @@ R_API RBinField *r_bin_java_create_new_rbinfield_from_field(RBinJavaField *fm_ty return field; } -R_API RBinSymbol *r_bin_java_create_new_symbol_from_field(RBinJavaField *fm_type, ut64 baddr) { +RZ_API RBinSymbol *rz_bin_java_create_new_symbol_from_field(RBinJavaField *fm_type, ut64 baddr) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (fm_type == NULL || fm_type->field_ref_cp_obj == NULL || fm_type->field_ref_cp_obj == &R_BIN_JAVA_NULL_TYPE) { R_FREE (sym); @@ -2537,20 +2537,20 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_field(RBinJavaField *fm_type // strncpy (sym->type, fm_type->descriptor, R_BIN_SIZEOF_STRINGS); if (fm_type->type == R_BIN_JAVA_FIELD_TYPE_METHOD) { sym->type = R_BIN_TYPE_FUNC_STR; - sym->paddr = r_bin_java_get_method_code_offset (fm_type); - sym->vaddr = r_bin_java_get_method_code_offset (fm_type) + baddr; - sym->size = r_bin_java_get_method_code_size (fm_type); + sym->paddr = rz_bin_java_get_method_code_offset (fm_type); + sym->vaddr = rz_bin_java_get_method_code_offset (fm_type) + baddr; + sym->size = rz_bin_java_get_method_code_size (fm_type); } else { sym->type = "FIELD"; - sym->paddr = fm_type->file_offset;// r_bin_java_get_method_code_offset (fm_type); + sym->paddr = fm_type->file_offset;// rz_bin_java_get_method_code_offset (fm_type); sym->vaddr = fm_type->file_offset + baddr; sym->size = fm_type->size; } - if (r_bin_java_is_fm_type_protected (fm_type)) { + if (rz_bin_java_is_fm_type_protected (fm_type)) { sym->bind = R_BIN_BIND_LOCAL_STR; - } else if (r_bin_java_is_fm_type_private (fm_type)) { + } else if (rz_bin_java_is_fm_type_private (fm_type)) { sym->bind = R_BIN_BIND_LOCAL_STR; - } else if (r_bin_java_is_fm_type_protected (fm_type)) { + } else if (rz_bin_java_is_fm_type_protected (fm_type)) { sym->bind = R_BIN_BIND_GLOBAL_STR; } sym->forwarder = "NONE"; @@ -2568,7 +2568,7 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_field(RBinJavaField *fm_type return sym; } -R_API RBinSymbol *r_bin_java_create_new_symbol_from_fm_type_meta(RBinJavaField *fm_type, ut64 baddr) { +RZ_API RBinSymbol *rz_bin_java_create_new_symbol_from_fm_type_meta(RBinJavaField *fm_type, ut64 baddr) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym || !fm_type || !fm_type->field_ref_cp_obj || fm_type->field_ref_cp_obj == &R_BIN_JAVA_NULL_TYPE) { free (sym); @@ -2576,17 +2576,17 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_fm_type_meta(RBinJavaField * } // ut32 new_name_len = strlen (fm_type->name) + strlen ("_meta") + 1; // char *new_name = malloc (new_name_len); - sym->name = r_str_newf ("meta_%s", fm_type->name); + sym->name = rz_str_newf ("meta_%s", fm_type->name); if (fm_type->type == R_BIN_JAVA_FIELD_TYPE_METHOD) { sym->type = "FUNC_META"; } else { sym->type = "FIELD_META"; } - if (r_bin_java_is_fm_type_protected (fm_type)) { + if (rz_bin_java_is_fm_type_protected (fm_type)) { sym->bind = R_BIN_BIND_LOCAL_STR; - } else if (r_bin_java_is_fm_type_private (fm_type)) { + } else if (rz_bin_java_is_fm_type_private (fm_type)) { sym->bind = R_BIN_BIND_LOCAL_STR; - } else if (r_bin_java_is_fm_type_protected (fm_type)) { + } else if (rz_bin_java_is_fm_type_protected (fm_type)) { sym->bind = R_BIN_BIND_GLOBAL_STR; } sym->forwarder = "NONE"; @@ -2595,7 +2595,7 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_fm_type_meta(RBinJavaField * } else { sym->classname = strdup ("UNKNOWN"); } - sym->paddr = fm_type->file_offset;// r_bin_java_get_method_code_offset (fm_type); + sym->paddr = fm_type->file_offset;// rz_bin_java_get_method_code_offset (fm_type); sym->vaddr = fm_type->file_offset + baddr; sym->ordinal = fm_type->metas->ord; sym->size = fm_type->size; @@ -2606,7 +2606,7 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_fm_type_meta(RBinJavaField * return sym; } -R_API RBinSymbol *r_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, ut64 baddr) { +RZ_API RBinSymbol *rz_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, ut64 baddr) { RBinSymbol *sym = R_NEW0 (RBinSymbol); if (!sym) { return NULL; @@ -2619,18 +2619,18 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJa return sym; } if (sym) { - class_name = r_bin_java_get_name_from_bin_cp_list (bin, + class_name = rz_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.class_idx); - name = r_bin_java_get_name_from_bin_cp_list (bin, + name = rz_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); - type_name = r_bin_java_get_name_from_bin_cp_list (bin, + type_name = rz_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); if (name) { sym->name = name; name = NULL; } if (type_name) { - sym->type = r_str_constpool_get (&bin->constpool, type_name); + sym->type = rz_str_constpool_get (&bin->constpool, type_name); R_FREE (type_name); } if (class_name) { @@ -2645,12 +2645,12 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJa } // TODO: vaddr+vsize break things if set -R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { +RZ_API RzList *rz_bin_java_get_sections(RBinJavaObj *bin) { RBinSection *section = NULL; - RList *sections = r_list_newf (free); + RzList *sections = rz_list_newf (free); ut64 baddr = bin->loadaddr; RBinJavaField *fm_type; - RListIter *iter = NULL; + RzListIter *iter = NULL; if (bin->cp_count > 0) { section = R_NEW0 (RBinSection); if (section) { @@ -2666,7 +2666,7 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { // section->vsize = section->size; section->perm = R_PERM_R; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); } section = NULL; } @@ -2682,15 +2682,15 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { #endif section->perm = R_PERM_R; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); section = NULL; - r_list_foreach (bin->fields_list, iter, fm_type) { + rz_list_foreach (bin->fields_list, iter, fm_type) { if (fm_type->attr_offset == 0) { continue; } section = R_NEW0 (RBinSection); if (section) { - section->name = r_str_newf ("attrs.%s", fm_type->name); + section->name = rz_str_newf ("attrs.%s", fm_type->name); section->size = fm_type->size - (fm_type->file_offset - fm_type->attr_offset); #if 0 section->vsize = section->size; @@ -2699,7 +2699,7 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { section->paddr = fm_type->attr_offset + baddr; section->perm = R_PERM_R; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); } } } @@ -2714,22 +2714,22 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { // section->vsize = section->size; section->perm = R_PERM_RX; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); section = NULL; - r_list_foreach (bin->methods_list, iter, fm_type) { + rz_list_foreach (bin->methods_list, iter, fm_type) { if (fm_type->attr_offset == 0) { continue; } section = R_NEW0 (RBinSection); if (section) { - section->name = r_str_newf ("attrs.%s", fm_type->name); + section->name = rz_str_newf ("attrs.%s", fm_type->name); section->size = fm_type->size - (fm_type->file_offset - fm_type->attr_offset); // section->vsize = section->size; // section->vaddr = section->paddr; section->paddr = fm_type->attr_offset + baddr; section->perm = R_PERM_R | R_PERM_X; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); } } } @@ -2744,7 +2744,7 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { // section->vsize = section->size; section->perm = R_PERM_R; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); } section = NULL; } @@ -2759,24 +2759,24 @@ R_API RList *r_bin_java_get_sections(RBinJavaObj *bin) { section->perm = R_PERM_R; section->perm = R_PERM_R; section->add = true; - r_list_append (sections, section); + rz_list_append (sections, section); } section = NULL; } return sections; } -R_API RList *r_bin_java_enum_class_methods(RBinJavaObj *bin, ut16 class_idx) { - RList *methods = r_list_newf (free); - RListIter *iter; +RZ_API RzList *rz_bin_java_enum_class_methods(RBinJavaObj *bin, ut16 class_idx) { + RzList *methods = rz_list_newf (free); + RzListIter *iter; RBinJavaField *field; - r_list_foreach (bin->methods_list, iter, field) { + rz_list_foreach (bin->methods_list, iter, field) { if (field->field_ref_cp_obj && 0) { if ((field && field->field_ref_cp_obj->metas->ord == class_idx)) { - RBinSymbol *sym = r_bin_java_create_new_symbol_from_ref ( + RBinSymbol *sym = rz_bin_java_create_new_symbol_from_ref ( bin, field->field_ref_cp_obj, bin->loadaddr); if (sym) { - r_list_append (methods, sym); + rz_list_append (methods, sym); } } } else { @@ -2785,26 +2785,26 @@ R_API RList *r_bin_java_enum_class_methods(RBinJavaObj *bin, ut16 class_idx) { // func defintion // sym->paddr = field->file_offset + bin->loadaddr; // code implementation - sym->paddr = r_bin_java_get_method_code_offset (field); + sym->paddr = rz_bin_java_get_method_code_offset (field); sym->vaddr = sym->paddr; // + bin->loadaddr; - r_list_append (methods, sym); + rz_list_append (methods, sym); } } return methods; } -R_API RList *r_bin_java_enum_class_fields(RBinJavaObj *bin, ut16 class_idx) { - RList *fields = r_list_newf (free); - RListIter *iter; +RZ_API RzList *rz_bin_java_enum_class_fields(RBinJavaObj *bin, ut16 class_idx) { + RzList *fields = rz_list_newf (free); + RzListIter *iter; RBinJavaField *fm_type; RBinField *field = NULL; - r_list_foreach (bin->fields_list, iter, fm_type) { + rz_list_foreach (bin->fields_list, iter, fm_type) { if (fm_type) { if (fm_type && fm_type->field_ref_cp_obj && fm_type->field_ref_cp_obj->metas->ord == class_idx) { - field = r_bin_java_create_new_rbinfield_from_field (fm_type, bin->loadaddr); + field = rz_bin_java_create_new_rbinfield_from_field (fm_type, bin->loadaddr); if (field) { - r_list_append (fields, field); + rz_list_append (fields, field); } } } @@ -2812,11 +2812,11 @@ R_API RList *r_bin_java_enum_class_fields(RBinJavaObj *bin, ut16 class_idx) { return fields; } -R_API int is_class_interface(RBinJavaObj *bin, RBinJavaCPTypeObj *cp_obj) { +RZ_API int is_class_interface(RBinJavaObj *bin, RBinJavaCPTypeObj *cp_obj) { RBinJavaInterfaceInfo *ifobj; - RListIter *iter; + RzListIter *iter; int res = false; - r_list_foreach (bin->interfaces_list, iter, ifobj) { + rz_list_foreach (bin->interfaces_list, iter, ifobj) { if (ifobj) { res = cp_obj == ifobj->cp_class; if (res) { @@ -2827,46 +2827,46 @@ R_API int is_class_interface(RBinJavaObj *bin, RBinJavaCPTypeObj *cp_obj) { return res; } /* - R_API RList * r_bin_java_get_interface_classes(RBinJavaObj * bin) { - RList *interfaces_names = r_list_new (); - RListIter *iter; + RZ_API RzList * rz_bin_java_get_interface_classes(RBinJavaObj * bin) { + RzList *interfaces_names = rz_list_new (); + RzListIter *iter; RBinJavaInterfaceInfo *ifobj; - r_list_foreach(bin->interfaces_list, iter, iinfo) { + rz_list_foreach(bin->interfaces_list, iter, iinfo) { RBinClass *class_ = R_NEW0 (RBinClass); RBinJavaCPTypeObj *cp_obj = ; if (ifobj && ifobj->name) { ut8 * name = strdup(ifobj->name); - r_list_append(interfaces_names, name); + rz_list_append(interfaces_names, name); } } return interfaces_names; } */ -R_API RList *r_bin_java_get_lib_names(RBinJavaObj *bin) { - RList *lib_names = r_list_newf (free); - RListIter *iter; +RZ_API RzList *rz_bin_java_get_lib_names(RBinJavaObj *bin) { + RzList *lib_names = rz_list_newf (free); + RzListIter *iter; RBinJavaCPTypeObj *cp_obj = NULL; if (!bin) { return lib_names; } - r_list_foreach (bin->cp_list, iter, cp_obj) { + rz_list_foreach (bin->cp_list, iter, cp_obj) { if (cp_obj && cp_obj->tag == R_BIN_JAVA_CP_CLASS && (bin->cf2.this_class != cp_obj->info.cp_class.name_idx || !is_class_interface (bin, cp_obj))) { - char *name = r_bin_java_get_item_name_from_bin_cp_list (bin, cp_obj); + char *name = rz_bin_java_get_item_name_from_bin_cp_list (bin, cp_obj); if (name) { - r_list_append (lib_names, name); + rz_list_append (lib_names, name); } } } return lib_names; } -R_API void r_bin_java_classes_free(void /*RBinClass*/ *k) { +RZ_API void rz_bin_java_classes_free(void /*RBinClass*/ *k) { RBinClass *klass = k; if (klass) { - r_list_free (klass->methods); - r_list_free (klass->fields); + rz_list_free (klass->methods); + rz_list_free (klass->fields); free (klass->name); free (klass->super); free (klass->visibility_str); @@ -2874,65 +2874,65 @@ R_API void r_bin_java_classes_free(void /*RBinClass*/ *k) { } } -R_API RList *r_bin_java_get_classes(RBinJavaObj *bin) { - RList *classes = r_list_newf (r_bin_java_classes_free); - RListIter *iter; +RZ_API RzList *rz_bin_java_get_classes(RBinJavaObj *bin) { + RzList *classes = rz_list_newf (rz_bin_java_classes_free); + RzListIter *iter; RBinJavaCPTypeObj *cp_obj = NULL; - RBinJavaCPTypeObj *this_class_cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); + RBinJavaCPTypeObj *this_class_cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, bin->cf2.this_class); ut32 idx = 0; RBinClass *k = R_NEW0 (RBinClass); if (!k) { - r_list_free (classes); + rz_list_free (classes); return NULL; } k->visibility = bin->cf2.access_flags; if (bin->cf2.flags_str) { k->visibility_str = strdup (bin->cf2.flags_str); } - k->methods = r_bin_java_enum_class_methods (bin, bin->cf2.this_class); - k->fields = r_bin_java_enum_class_fields (bin, bin->cf2.this_class); - k->name = r_bin_java_get_this_class_name (bin); - k->super = r_bin_java_get_name_from_bin_cp_list (bin, bin->cf2.super_class); + k->methods = rz_bin_java_enum_class_methods (bin, bin->cf2.this_class); + k->fields = rz_bin_java_enum_class_fields (bin, bin->cf2.this_class); + k->name = rz_bin_java_get_this_class_name (bin); + k->super = rz_bin_java_get_name_from_bin_cp_list (bin, bin->cf2.super_class); k->index = (idx++); - r_list_append (classes, k); - r_list_foreach (bin->cp_list, iter, cp_obj) { + rz_list_append (classes, k); + rz_list_foreach (bin->cp_list, iter, cp_obj) { if (cp_obj && cp_obj->tag == R_BIN_JAVA_CP_CLASS && (this_class_cp_obj != cp_obj && is_class_interface (bin, cp_obj))) { k = R_NEW0 (RBinClass); if (!k) { break; } - k->methods = r_bin_java_enum_class_methods (bin, cp_obj->info.cp_class.name_idx); - k->fields = r_bin_java_enum_class_fields (bin, cp_obj->info.cp_class.name_idx); + k->methods = rz_bin_java_enum_class_methods (bin, cp_obj->info.cp_class.name_idx); + k->fields = rz_bin_java_enum_class_fields (bin, cp_obj->info.cp_class.name_idx); k->index = idx; - k->name = r_bin_java_get_item_name_from_bin_cp_list (bin, cp_obj); - r_list_append (classes, k); + k->name = rz_bin_java_get_item_name_from_bin_cp_list (bin, cp_obj); + rz_list_append (classes, k); idx++; } } return classes; } -R_API RBinSymbol *r_bin_java_create_new_symbol_from_invoke_dynamic(RBinJavaCPTypeObj *obj, ut64 baddr) { +RZ_API RBinSymbol *rz_bin_java_create_new_symbol_from_invoke_dynamic(RBinJavaCPTypeObj *obj, ut64 baddr) { if (!obj || (obj->tag != R_BIN_JAVA_CP_INVOKEDYNAMIC)) { return NULL; } - return r_bin_java_create_new_symbol_from_cp_idx (obj->info.cp_invoke_dynamic.name_and_type_index, baddr); + return rz_bin_java_create_new_symbol_from_cp_idx (obj->info.cp_invoke_dynamic.name_and_type_index, baddr); } -R_API RBinSymbol *r_bin_java_create_new_symbol_from_cp_idx(ut32 cp_idx, ut64 baddr) { +RZ_API RBinSymbol *rz_bin_java_create_new_symbol_from_cp_idx(ut32 cp_idx, ut64 baddr) { RBinSymbol *sym = NULL; - RBinJavaCPTypeObj *obj = r_bin_java_get_item_from_bin_cp_list ( + RBinJavaCPTypeObj *obj = rz_bin_java_get_item_from_bin_cp_list ( R_BIN_JAVA_GLOBAL_BIN, cp_idx); if (obj) { switch (obj->tag) { case R_BIN_JAVA_CP_METHODREF: case R_BIN_JAVA_CP_FIELDREF: case R_BIN_JAVA_CP_INTERFACEMETHOD_REF: - sym = r_bin_java_create_new_symbol_from_ref (R_BIN_JAVA_GLOBAL_BIN, obj, baddr); + sym = rz_bin_java_create_new_symbol_from_ref (R_BIN_JAVA_GLOBAL_BIN, obj, baddr); break; case R_BIN_JAVA_CP_INVOKEDYNAMIC: - sym = r_bin_java_create_new_symbol_from_invoke_dynamic (obj, baddr); + sym = rz_bin_java_create_new_symbol_from_invoke_dynamic (obj, baddr); break; default: break; @@ -2941,43 +2941,43 @@ R_API RBinSymbol *r_bin_java_create_new_symbol_from_cp_idx(ut32 cp_idx, ut64 bad return sym; } -R_API RList *U(r_bin_java_get_fields)(RBinJavaObj * bin) { - RListIter *iter = NULL, *iter_tmp = NULL; - RList *fields = r_list_new (); +RZ_API RzList *U(rz_bin_java_get_fields)(RBinJavaObj * bin) { + RzListIter *iter = NULL, *iter_tmp = NULL; + RzList *fields = rz_list_new (); RBinJavaField *fm_type; RBinField *field; - r_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { - field = r_bin_java_create_new_rbinfield_from_field (fm_type, bin->loadaddr); + rz_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { + field = rz_bin_java_create_new_rbinfield_from_field (fm_type, bin->loadaddr); if (field) { - r_list_append (fields, field); + rz_list_append (fields, field); } } return fields; } -R_API void r_bin_add_import(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, const char *type) { +RZ_API void rz_bin_add_import(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, const char *type) { RBinImport *imp = R_NEW0 (RBinImport); - char *class_name = r_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.class_idx); - char *name = r_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); - char *descriptor = r_bin_java_get_desc_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); + char *class_name = rz_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.class_idx); + char *name = rz_bin_java_get_name_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); + char *descriptor = rz_bin_java_get_desc_from_bin_cp_list (bin, obj->info.cp_method.name_and_type_idx); class_name = class_name ? class_name : strdup ("INVALID CLASS NAME INDEX"); name = name ? name : strdup ("InvalidNameIndex"); descriptor = descriptor ? descriptor : strdup ("INVALID DESCRIPTOR INDEX"); imp->classname = class_name; imp->name = name; imp->bind = "NONE"; - imp->type = r_str_constpool_get (&bin->constpool, type); + imp->type = rz_str_constpool_get (&bin->constpool, type); imp->descriptor = descriptor; imp->ordinal = obj->idx; - r_list_append (bin->imports_list, imp); + rz_list_append (bin->imports_list, imp); } -R_API void r_bin_java_set_imports(RBinJavaObj *bin) { - RListIter *iter = NULL; +RZ_API void rz_bin_java_set_imports(RBinJavaObj *bin) { + RzListIter *iter = NULL; RBinJavaCPTypeObj *obj = NULL; - r_list_free (bin->imports_list); - bin->imports_list = r_list_newf (free); - r_list_foreach (bin->cp_list, iter, obj) { + rz_list_free (bin->imports_list); + bin->imports_list = rz_list_newf (free); + rz_list_foreach (bin->cp_list, iter, obj) { const char *type = NULL; switch (obj->tag) { case R_BIN_JAVA_CP_METHODREF: type = "METHOD"; break; @@ -2986,51 +2986,51 @@ R_API void r_bin_java_set_imports(RBinJavaObj *bin) { default: type = NULL; break; } if (type) { - r_bin_add_import (bin, obj, type); + rz_bin_add_import (bin, obj, type); } } } -R_API RList *r_bin_java_get_imports(RBinJavaObj *bin) { - RList *ret = r_list_newf (free); +RZ_API RzList *rz_bin_java_get_imports(RBinJavaObj *bin) { + RzList *ret = rz_list_newf (free); RBinImport *import = NULL; - RListIter *iter; - r_list_foreach (bin->imports_list, iter, import) { + RzListIter *iter; + rz_list_foreach (bin->imports_list, iter, import) { RBinImport *n_import = R_NEW0 (RBinImport); if (!n_import) { - r_list_free (ret); + rz_list_free (ret); return NULL; } memcpy (n_import, import, sizeof (RBinImport)); - r_list_append (ret, n_import); + rz_list_append (ret, n_import); } return ret; } -R_API RList *r_bin_java_get_symbols(RBinJavaObj *bin) { - RListIter *iter = NULL, *iter_tmp = NULL; - RList *imports, *symbols = r_list_newf (free); +RZ_API RzList *rz_bin_java_get_symbols(RBinJavaObj *bin) { + RzListIter *iter = NULL, *iter_tmp = NULL; + RzList *imports, *symbols = rz_list_newf (free); RBinSymbol *sym = NULL; RBinImport *imp; RBinJavaField *fm_type; - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { - sym = r_bin_java_create_new_symbol_from_field (fm_type, bin->loadaddr); + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + sym = rz_bin_java_create_new_symbol_from_field (fm_type, bin->loadaddr); if (sym) { - r_list_append (symbols, (void *) sym); + rz_list_append (symbols, (void *) sym); } - sym = r_bin_java_create_new_symbol_from_fm_type_meta (fm_type, bin->loadaddr); + sym = rz_bin_java_create_new_symbol_from_fm_type_meta (fm_type, bin->loadaddr); if (sym) { - r_list_append (symbols, (void *) sym); + rz_list_append (symbols, (void *) sym); } } - r_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { - sym = r_bin_java_create_new_symbol_from_field (fm_type, bin->loadaddr); + rz_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { + sym = rz_bin_java_create_new_symbol_from_field (fm_type, bin->loadaddr); if (sym) { - r_list_append (symbols, (void *) sym); + rz_list_append (symbols, (void *) sym); } - sym = r_bin_java_create_new_symbol_from_fm_type_meta (fm_type, bin->loadaddr); + sym = rz_bin_java_create_new_symbol_from_fm_type_meta (fm_type, bin->loadaddr); if (sym) { - r_list_append (symbols, (void *) sym); + rz_list_append (symbols, (void *) sym); } } bin->lang = "java"; @@ -3051,8 +3051,8 @@ R_API RList *r_bin_java_get_symbols(RBinJavaObj *bin) { bin->lang = lang; } } - imports = r_bin_java_get_imports (bin); - r_list_foreach (imports, iter, imp) { + imports = rz_bin_java_get_imports (bin); + rz_list_foreach (imports, iter, imp) { sym = R_NEW0 (RBinSymbol); if (!sym) { break; @@ -3073,18 +3073,18 @@ R_API RList *r_bin_java_get_symbols(RBinJavaObj *bin) { } sym->vaddr = sym->paddr = imp->ordinal; sym->ordinal = imp->ordinal; - r_list_append (symbols, (void *) sym); + rz_list_append (symbols, (void *) sym); } - r_list_free (imports); + rz_list_free (imports); return symbols; } -R_API RList *r_bin_java_get_strings(RBinJavaObj *bin) { - RList *strings = r_list_newf (free); +RZ_API RzList *rz_bin_java_get_strings(RBinJavaObj *bin) { + RzList *strings = rz_list_newf (free); RBinString *str = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaCPTypeObj *cp_obj = NULL; - r_list_foreach_safe (bin->cp_list, iter, iter_tmp, cp_obj) { + rz_list_foreach_safe (bin->cp_list, iter, iter_tmp, cp_obj) { if (cp_obj && cp_obj->tag == R_BIN_JAVA_CP_UTF8) { str = (RBinString *) R_NEW0 (RBinString); if (str) { @@ -3093,42 +3093,42 @@ R_API RList *r_bin_java_get_strings(RBinJavaObj *bin) { str->size = cp_obj->info.cp_utf8.length + 3; str->length = cp_obj->info.cp_utf8.length; if (str->size > 0) { - str->string = r_str_ndup ((const char *) + str->string = rz_str_ndup ((const char *) cp_obj->info.cp_utf8.bytes, R_BIN_JAVA_MAXSTR); } - r_list_append (strings, (void *) str); + rz_list_append (strings, (void *) str); } } } return strings; } -R_API void *r_bin_java_free(RBinJavaObj *bin) { +RZ_API void *rz_bin_java_free(RBinJavaObj *bin) { char *bin_obj_key = NULL; if (!bin) { return NULL; } // Delete the bin object from the data base. - bin_obj_key = r_bin_java_build_obj_key (bin); + bin_obj_key = rz_bin_java_build_obj_key (bin); // if (bin->AllJavaBinObjs && sdb_exists (bin->AllJavaBinObjs, bin_obj_key)) { // sdb_unset (bin->AllJavaBinObjs, bin_obj_key, 0); // } free (bin_obj_key); - r_list_free (bin->imports_list); + rz_list_free (bin->imports_list); // XXX - Need to remove all keys belonging to this class from // the share meta information sdb. // TODO e.g. iterate over bin->kv and delete all obj, func, etc. keys // sdb_free (bin->kv); // free up the constant pool list - r_list_free (bin->cp_list); + rz_list_free (bin->cp_list); // free up the fields list - r_list_free (bin->fields_list); + rz_list_free (bin->fields_list); // free up methods list - r_list_free (bin->methods_list); + rz_list_free (bin->methods_list); // free up interfaces list - r_list_free (bin->interfaces_list); - r_list_free (bin->attrs_list); + rz_list_free (bin->interfaces_list); + rz_list_free (bin->attrs_list); // TODO: XXX if a class list of all inner classes // are formed then this will need to be updated free (bin->cf2.flags_str); @@ -3137,25 +3137,25 @@ R_API void *r_bin_java_free(RBinJavaObj *bin) { R_BIN_JAVA_GLOBAL_BIN = NULL; } free (bin->file); - r_str_constpool_fini (&bin->constpool); + rz_str_constpool_fini (&bin->constpool); free (bin); return NULL; } -R_API RBinJavaObj *r_bin_java_new_buf(RBuffer *buf, ut64 loadaddr, Sdb *kv) { +RZ_API RBinJavaObj *rz_bin_java_new_buf(RBuffer *buf, ut64 loadaddr, Sdb *kv) { RBinJavaObj *bin = R_NEW0 (RBinJavaObj); if (!bin) { return NULL; } ut64 tmpsz; - const ut8 *tmp = r_buf_data (buf, &tmpsz); - if (!r_bin_java_new_bin (bin, loadaddr, kv, tmp, tmpsz)) { - return r_bin_java_free (bin); + const ut8 *tmp = rz_buf_data (buf, &tmpsz); + if (!rz_bin_java_new_bin (bin, loadaddr, kv, tmp, tmpsz)) { + return rz_bin_java_free (bin); } return bin; } -R_API void r_bin_java_attribute_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_attribute_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { IFDBG eprintf("Deleting attr %s, %p\n", attr->name, attr); @@ -3170,14 +3170,14 @@ R_API void r_bin_java_attribute_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_constant_pool(void /*RBinJavaCPTypeObj*/ *o) { +RZ_API void rz_bin_java_constant_pool(void /*RBinJavaCPTypeObj*/ *o) { RBinJavaCPTypeObj *obj = o; if (obj != &R_BIN_JAVA_NULL_TYPE) { ((RBinJavaCPTypeMetas *) obj->metas->type_info)->allocs->delete_obj (obj); } } -R_API void r_bin_java_fmtype_free(void /*RBinJavaField*/ *f) { +RZ_API void rz_bin_java_fmtype_free(void /*RBinJavaField*/ *f) { RBinJavaField *fm_type = f; if (!fm_type) { return; @@ -3187,11 +3187,11 @@ R_API void r_bin_java_fmtype_free(void /*RBinJavaField*/ *f) { free (fm_type->flags_str); free (fm_type->class_name); free (fm_type->metas); - r_list_free (fm_type->attributes); + rz_list_free (fm_type->attributes); free (fm_type); } // Start Free the various attribute types -R_API void r_bin_java_unknown_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_unknown_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3200,7 +3200,7 @@ R_API void r_bin_java_unknown_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_local_variable_table_attr_entry_free(void /*RBinJavaLocalVariableAttribute*/ *a) { +RZ_API void rz_bin_java_local_variable_table_attr_entry_free(void /*RBinJavaLocalVariableAttribute*/ *a) { RBinJavaLocalVariableAttribute *lvattr = a; if (lvattr) { free (lvattr->descriptor); @@ -3209,17 +3209,17 @@ R_API void r_bin_java_local_variable_table_attr_entry_free(void /*RBinJavaLocalV } } -R_API void r_bin_java_local_variable_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_local_variable_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); free (attr->metas); - r_list_free (attr->info.local_variable_table_attr.local_variable_table); + rz_list_free (attr->info.local_variable_table_attr.local_variable_table); free (attr); } } -R_API void r_bin_java_local_variable_type_table_attr_entry_free(void /*RBinJavaLocalVariableTypeAttribute*/ *a) { +RZ_API void rz_bin_java_local_variable_type_table_attr_entry_free(void /*RBinJavaLocalVariableTypeAttribute*/ *a) { RBinJavaLocalVariableTypeAttribute *attr = a; if (attr) { free (attr->name); @@ -3228,17 +3228,17 @@ R_API void r_bin_java_local_variable_type_table_attr_entry_free(void /*RBinJavaL } } -R_API void r_bin_java_local_variable_type_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_local_variable_type_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); free (attr->metas); - r_list_free (attr->info.local_variable_type_table_attr.local_variable_table); + rz_list_free (attr->info.local_variable_type_table_attr.local_variable_table); free (attr); } } -R_API void r_bin_java_deprecated_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_deprecated_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3247,7 +3247,7 @@ R_API void r_bin_java_deprecated_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_enclosing_methods_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_enclosing_methods_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3259,7 +3259,7 @@ R_API void r_bin_java_enclosing_methods_attr_free(void /*RBinJavaAttrInfo*/ *a) } } -R_API void r_bin_java_synthetic_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_synthetic_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3268,7 +3268,7 @@ R_API void r_bin_java_synthetic_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_constant_value_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_constant_value_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3277,33 +3277,33 @@ R_API void r_bin_java_constant_value_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_line_number_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_line_number_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); free (attr->metas); - r_list_free (attr->info.line_number_table_attr.line_number_table); + rz_list_free (attr->info.line_number_table_attr.line_number_table); free (attr); } } -R_API void r_bin_java_code_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_code_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { // XXX - Intentional memory leak here. When one of the - // Code attributes is parsed, the code (the r_bin_java) + // Code attributes is parsed, the code (the rz_bin_java) // is not properly parsing the class file - r_bin_java_stack_frame_free (attr->info.code_attr.implicit_frame); - r_list_free (attr->info.code_attr.attributes); + rz_bin_java_stack_frame_free (attr->info.code_attr.implicit_frame); + rz_list_free (attr->info.code_attr.attributes); free (attr->info.code_attr.code); - r_list_free (attr->info.code_attr.exception_table); + rz_list_free (attr->info.code_attr.exception_table); free (attr->name); free (attr->metas); free (attr); } } -R_API void r_bin_java_exceptions_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_exceptions_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3313,7 +3313,7 @@ R_API void r_bin_java_exceptions_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_inner_classes_attr_entry_free(void /*RBinJavaClassesAttribute*/ *a) { +RZ_API void rz_bin_java_inner_classes_attr_entry_free(void /*RBinJavaClassesAttribute*/ *a) { RBinJavaClassesAttribute *attr = a; if (attr) { free (attr->name); @@ -3322,17 +3322,17 @@ R_API void r_bin_java_inner_classes_attr_entry_free(void /*RBinJavaClassesAttrib } } -R_API void r_bin_java_inner_classes_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_inner_classes_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); free (attr->metas); - r_list_free (attr->info.inner_classes_attr.classes); + rz_list_free (attr->info.inner_classes_attr.classes); free (attr); } } -R_API void r_bin_java_signature_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_signature_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3342,7 +3342,7 @@ R_API void r_bin_java_signature_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_source_debug_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_source_debug_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3352,7 +3352,7 @@ R_API void r_bin_java_source_debug_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_source_code_file_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_source_code_file_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); @@ -3361,27 +3361,27 @@ R_API void r_bin_java_source_code_file_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_stack_map_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_stack_map_table_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { free (attr->name); free (attr->metas); - r_list_free (attr->info.stack_map_table_attr.stack_map_frame_entries); + rz_list_free (attr->info.stack_map_table_attr.stack_map_frame_entries); free (attr); } } -R_API void r_bin_java_stack_frame_free(void /*RBinJavaStackMapFrame*/ *o) { +RZ_API void rz_bin_java_stack_frame_free(void /*RBinJavaStackMapFrame*/ *o) { RBinJavaStackMapFrame *obj = o; if (obj) { - r_list_free (obj->local_items); - r_list_free (obj->stack_items); + rz_list_free (obj->local_items); + rz_list_free (obj->stack_items); free (obj->metas); free (obj); } } -R_API void r_bin_java_verification_info_free(void /*RBinJavaVerificationObj*/ *o) { +RZ_API void rz_bin_java_verification_info_free(void /*RBinJavaVerificationObj*/ *o) { RBinJavaVerificationObj *obj = o; // eprintf ("Freeing verification object\n"); if (obj) { @@ -3390,7 +3390,7 @@ R_API void r_bin_java_verification_info_free(void /*RBinJavaVerificationObj*/ *o } } -R_API void r_bin_java_interface_free(void /*RBinJavaInterfaceInfo*/ *o) { +RZ_API void rz_bin_java_interface_free(void /*RBinJavaInterfaceInfo*/ *o) { RBinJavaInterfaceInfo *obj = o; if (obj) { free (obj->name); @@ -3399,25 +3399,25 @@ R_API void r_bin_java_interface_free(void /*RBinJavaInterfaceInfo*/ *o) { } // End Free the various attribute types // Start the various attibute types new -R_API ut64 r_bin_java_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? ((RBinJavaAttrMetas *) attr->metas->type_info)->allocs->calc_size (attr) : 0; } -R_API ut64 r_bin_java_unknown_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_unknown_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? 6 : 0; } -R_API RBinJavaAttrInfo *r_bin_java_unknown_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { - return r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); +RZ_API RBinJavaAttrInfo *rz_bin_java_unknown_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { + return rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); } -R_API ut64 r_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr) { - RListIter *iter; - // RListIter *iter_tmp; +RZ_API ut64 rz_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr) { + RzListIter *iter; + // RzListIter *iter_tmp; ut64 size = 0; bool is_attr_in_old_format = attr->is_attr_in_old_format; if (attr) { - // attr = r_bin_java_default_attr_new (buffer, sz, buf_offset); + // attr = rz_bin_java_default_attr_new (buffer, sz, buf_offset); size += is_attr_in_old_format ? 4 : 6; // attr->info.code_attr.max_stack = R_BIN_JAVA_USHORT (buffer, 0); size += is_attr_in_old_format ? 1 : 2; @@ -3431,8 +3431,8 @@ R_API ut64 r_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr) { // attr->info.code_attr.exception_table_length = R_BIN_JAVA_USHORT (buffer, offset); size += 2; // RBinJavaExceptionEntry *exc_entry; - // r_list_foreach_safe (attr->info.code_attr.exception_table, iter, iter_tmp, exc_entry) { - r_list_foreach_iter (attr->info.code_attr.exception_table, iter) { + // rz_list_foreach_safe (attr->info.code_attr.exception_table, iter, iter_tmp, exc_entry) { + rz_list_foreach_iter (attr->info.code_attr.exception_table, iter) { // exc_entry->start_pc = R_BIN_JAVA_USHORT (buffer,offset); size += 2; // exc_entry->end_pc = R_BIN_JAVA_USHORT (buffer,offset); @@ -3446,20 +3446,20 @@ R_API ut64 r_bin_java_code_attr_calc_size(RBinJavaAttrInfo *attr) { size += 2; // RBinJavaAttrInfo *_attr; if (attr->info.code_attr.attributes_count > 0) { - // r_list_foreach_safe (attr->info.code_attr.attributes, iter, iter_tmp, _attr) { - r_list_foreach_iter (attr->info.code_attr.attributes, iter) { - size += r_bin_java_attr_calc_size (attr); + // rz_list_foreach_safe (attr->info.code_attr.attributes, iter, iter_tmp, _attr) { + rz_list_foreach_iter (attr->info.code_attr.attributes, iter) { + size += rz_bin_java_attr_calc_size (attr); } } } return size; } -R_API RBinJavaAttrInfo *r_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaAttrInfo *attr = NULL, *_attr = NULL; ut32 k = 0, curpos; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } @@ -3495,7 +3495,7 @@ R_API RBinJavaAttrInfo *r_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buffer, } attr->info.code_attr.exception_table_length = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.code_attr.exception_table = r_list_newf (free); + attr->info.code_attr.exception_table = rz_list_newf (free); for (k = 0; k < attr->info.code_attr.exception_table_length; k++) { curpos = buf_offset + offset; if (curpos + 8 > sz) { @@ -3515,38 +3515,38 @@ R_API RBinJavaAttrInfo *r_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buffer, offset += 2; e->catch_type = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - r_list_append (attr->info.code_attr.exception_table, e); + rz_list_append (attr->info.code_attr.exception_table, e); e->size = 8; } attr->info.code_attr.attributes_count = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; // IFDBG eprintf (" code Attributes_count: %d\n", attr->info.code_attr.attributes_count); // XXX - attr->info.code_attr.attributes is not freed because one of the code attributes is improperly parsed. - attr->info.code_attr.attributes = r_list_newf (r_bin_java_attribute_free); + attr->info.code_attr.attributes = rz_list_newf (rz_bin_java_attribute_free); if (attr->info.code_attr.attributes_count > 0) { for (k = 0; k < attr->info.code_attr.attributes_count; k++) { int size = (offset < sz) ? sz - offset : 0; if (size > sz || size <= 0) { break; } - _attr = r_bin_java_read_next_attr_from_buffer (bin, buffer + offset, size, buf_offset + offset); + _attr = rz_bin_java_read_next_attr_from_buffer (bin, buffer + offset, size, buf_offset + offset); if (!_attr) { - eprintf ("[X] r_bin_java_code_attr_new: Error unable to parse remainder of classfile after Method's Code Attribute: %d.\n", k); + eprintf ("[X] rz_bin_java_code_attr_new: Error unable to parse remainder of classfile after Method's Code Attribute: %d.\n", k); break; } IFDBG eprintf("Parsing @ 0x%"PFMT64x " (%s) = 0x%"PFMT64x " bytes, %p\n", _attr->file_offset, _attr->name, _attr->size, _attr); offset += _attr->size; - r_list_append (attr->info.code_attr.attributes, _attr); + rz_list_append (attr->info.code_attr.attributes, _attr); if (_attr->type == R_BIN_JAVA_ATTR_TYPE_LOCAL_VARIABLE_TABLE_ATTR) { IFDBG eprintf("Parsed the LocalVariableTable, preparing the implicit mthod frame.\n"); - // r_bin_java_print_attr_summary(_attr); - attr->info.code_attr.implicit_frame = r_bin_java_build_stack_frame_from_local_variable_table (R_BIN_JAVA_GLOBAL_BIN, _attr); + // rz_bin_java_print_attr_summary(_attr); + attr->info.code_attr.implicit_frame = rz_bin_java_build_stack_frame_from_local_variable_table (R_BIN_JAVA_GLOBAL_BIN, _attr); attr->info.code_attr.implicit_frame->file_offset = buf_offset; - IFDBG r_bin_java_print_stack_map_frame_summary(attr->info.code_attr.implicit_frame); - // r_list_append (attr->info.code_attr.attributes, attr->info.code_attr.implicit_frame); + IFDBG rz_bin_java_print_stack_map_frame_summary(attr->info.code_attr.implicit_frame); + // rz_list_append (attr->info.code_attr.attributes, attr->info.code_attr.implicit_frame); } // if (offset > sz) { - // eprintf ("[X] r_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", k); + // eprintf ("[X] rz_bin_java: Error unable to parse remainder of classfile after Attribute: %d.\n", k); // break; // } @@ -3554,50 +3554,50 @@ R_API RBinJavaAttrInfo *r_bin_java_code_attr_new(RBinJavaObj *bin, ut8 *buffer, } if (attr->info.code_attr.implicit_frame == NULL) { // build a default implicit_frame - attr->info.code_attr.implicit_frame = r_bin_java_default_stack_frame (); - // r_list_append (attr->info.code_attr.attributes, attr->info.code_attr.implicit_frame); + attr->info.code_attr.implicit_frame = rz_bin_java_default_stack_frame (); + // rz_list_append (attr->info.code_attr.attributes, attr->info.code_attr.implicit_frame); } attr->size = offset; return attr; } -R_API RBinJavaAttrInfo *r_bin_java_constant_value_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_constant_value_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 6; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_CONST_VALUE_ATTR; attr->info.constant_value_attr.constantvalue_idx = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; attr->size = offset; } - // IFDBG r_bin_java_print_constant_value_attr_summary(attr); + // IFDBG rz_bin_java_print_constant_value_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_constant_value_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_constant_value_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? 8 : 0; } -R_API RBinJavaAttrInfo *r_bin_java_deprecated_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_deprecated_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_DEPRECATED_ATTR; attr->size = offset; } - // IFDBG r_bin_java_print_deprecated_attr_summary(attr); + // IFDBG rz_bin_java_print_deprecated_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_deprecated_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_deprecated_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? 6 : 0; } -R_API RBinJavaAttrInfo *r_bin_java_signature_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_signature_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 6; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } @@ -3606,18 +3606,18 @@ R_API RBinJavaAttrInfo *r_bin_java_signature_attr_new(RBinJavaObj *bin, ut8 *buf // offset += 2; attr->info.signature_attr.signature_idx = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.signature_attr.signature = r_bin_java_get_utf8_from_bin_cp_list ( + attr->info.signature_attr.signature = rz_bin_java_get_utf8_from_bin_cp_list ( R_BIN_JAVA_GLOBAL_BIN, attr->info.signature_attr.signature_idx); if (!attr->info.signature_attr.signature) { - eprintf ("r_bin_java_signature_attr_new: Unable to resolve the " + eprintf ("rz_bin_java_signature_attr_new: Unable to resolve the " "Signature UTF8 String Index: 0x%02x\n", attr->info.signature_attr.signature_idx); } attr->size = offset; - // IFDBG r_bin_java_print_source_code_file_attr_summary(attr); + // IFDBG rz_bin_java_print_source_code_file_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_signature_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_signature_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; if (attr == NULL) { // TODO eprintf allocation fail @@ -3631,9 +3631,9 @@ R_API ut64 r_bin_java_signature_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API RBinJavaAttrInfo *r_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 6; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr || sz < 10) { free (attr); return NULL; @@ -3643,15 +3643,15 @@ R_API RBinJavaAttrInfo *r_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, offset += 2; attr->info.enclosing_method_attr.method_idx = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.enclosing_method_attr.class_name = r_bin_java_get_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.class_idx); + attr->info.enclosing_method_attr.class_name = rz_bin_java_get_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.class_idx); if (attr->info.enclosing_method_attr.class_name == NULL) { eprintf ("Could not resolve enclosing class name for the enclosed method.\n"); } - attr->info.enclosing_method_attr.method_name = r_bin_java_get_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.method_idx); + attr->info.enclosing_method_attr.method_name = rz_bin_java_get_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.method_idx); if (attr->info.enclosing_method_attr.class_name == NULL) { eprintf ("Could not resolve method descriptor for the enclosed method.\n"); } - attr->info.enclosing_method_attr.method_descriptor = r_bin_java_get_desc_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.method_idx); + attr->info.enclosing_method_attr.method_descriptor = rz_bin_java_get_desc_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, attr->info.enclosing_method_attr.method_idx); if (attr->info.enclosing_method_attr.method_name == NULL) { eprintf ("Could not resolve method name for the enclosed method.\n"); } @@ -3659,7 +3659,7 @@ R_API RBinJavaAttrInfo *r_bin_java_enclosing_methods_attr_new(RBinJavaObj *bin, return attr; } -R_API ut64 r_bin_java_enclosing_methods_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_enclosing_methods_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; if (attr) { size += 6; @@ -3671,14 +3671,14 @@ R_API ut64 r_bin_java_enclosing_methods_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API RBinJavaAttrInfo *r_bin_java_exceptions_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_exceptions_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0, offset = 0; ut64 size; RBinJavaAttrInfo *attr = NULL; if (sz < 8) { return NULL; } - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (!attr) { return attr; @@ -3704,11 +3704,11 @@ R_API RBinJavaAttrInfo *r_bin_java_exceptions_attr_new(RBinJavaObj *bin, ut8 *bu offset += 2; } attr->size = offset; - // IFDBG r_bin_java_print_exceptions_attr_summary(attr); + // IFDBG rz_bin_java_print_exceptions_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_exceptions_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_exceptions_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0, i = 0; if (attr) { size += 6; @@ -3720,13 +3720,13 @@ R_API ut64 r_bin_java_exceptions_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API RBinJavaAttrInfo *r_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaClassesAttribute *icattr; RBinJavaAttrInfo *attr = NULL; RBinJavaCPTypeObj *obj; ut32 i = 0; ut64 offset = 0, curpos; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr == NULL) { // TODO eprintf @@ -3735,7 +3735,7 @@ R_API RBinJavaAttrInfo *r_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 attr->type = R_BIN_JAVA_ATTR_TYPE_INNER_CLASSES_ATTR; attr->info.inner_classes_attr.number_of_classes = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.inner_classes_attr.classes = r_list_newf (r_bin_java_inner_classes_attr_entry_free); + attr->info.inner_classes_attr.classes = rz_list_newf (rz_bin_java_inner_classes_attr_entry_free); for (i = 0; i < attr->info.inner_classes_attr.number_of_classes; i++) { curpos = buf_offset + offset; if (offset + 8 > sz) { @@ -3758,34 +3758,34 @@ R_API RBinJavaAttrInfo *r_bin_java_inner_classes_attr_new(RBinJavaObj *bin, ut8 icattr->file_offset = curpos; icattr->size = 8; - obj = r_bin_java_get_item_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, icattr->inner_name_idx); + obj = rz_bin_java_get_item_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, icattr->inner_name_idx); if (obj == NULL) { eprintf ("BINCPLIS IS HULL %d\n", icattr->inner_name_idx); } - icattr->name = r_bin_java_get_item_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, obj); + icattr->name = rz_bin_java_get_item_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, obj); if (!icattr->name) { - obj = r_bin_java_get_item_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, icattr->inner_class_info_idx); + obj = rz_bin_java_get_item_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, icattr->inner_class_info_idx); if (!obj) { eprintf ("BINCPLIST IS NULL %d\n", icattr->inner_class_info_idx); } - icattr->name = r_bin_java_get_item_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, obj); + icattr->name = rz_bin_java_get_item_name_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, obj); if (!icattr->name) { - icattr->name = r_str_dup (NULL, "NULL"); - eprintf ("r_bin_java_inner_classes_attr: Unable to find the name for %d index.\n", icattr->inner_name_idx); + icattr->name = rz_str_dup (NULL, "NULL"); + eprintf ("rz_bin_java_inner_classes_attr: Unable to find the name for %d index.\n", icattr->inner_name_idx); free (icattr); break; } } - IFDBG eprintf("r_bin_java_inner_classes_attr: Inner class name %d is %s.\n", icattr->inner_name_idx, icattr->name); - r_list_append (attr->info.inner_classes_attr.classes, (void *) icattr); + IFDBG eprintf("rz_bin_java_inner_classes_attr: Inner class name %d is %s.\n", icattr->inner_name_idx, icattr->name); + rz_list_append (attr->info.inner_classes_attr.classes, (void *) icattr); } attr->size = offset; - // IFDBG r_bin_java_print_inner_classes_attr_summary(attr); + // IFDBG rz_bin_java_print_inner_classes_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_inner_class_attr_calc_size(RBinJavaClassesAttribute *icattr) { +RZ_API ut64 rz_bin_java_inner_class_attr_calc_size(RBinJavaClassesAttribute *icattr) { ut64 size = 0; if (icattr) { // icattr->inner_class_info_idx = R_BIN_JAVA_USHORT (buffer, offset); @@ -3800,27 +3800,27 @@ R_API ut64 r_bin_java_inner_class_attr_calc_size(RBinJavaClassesAttribute *icatt return size; } -R_API ut64 r_bin_java_inner_classes_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_inner_classes_attr_calc_size(RBinJavaAttrInfo *attr) { RBinJavaClassesAttribute *icattr = NULL; - RListIter *iter; + RzListIter *iter; ut64 size = 6; if (!attr) { return 0; } - r_list_foreach (attr->info.inner_classes_attr.classes, iter, icattr) { - size += r_bin_java_inner_class_attr_calc_size (icattr); + rz_list_foreach (attr->info.inner_classes_attr.classes, iter, icattr) { + size += rz_bin_java_inner_class_attr_calc_size (icattr); } return size; } -R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_line_number_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; ut64 curpos, offset = 0; RBinJavaLineNumberAttribute *lnattr; if (sz < 6) { return NULL; } - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } @@ -3828,10 +3828,10 @@ R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(RBinJavaObj *bin, attr->type = R_BIN_JAVA_ATTR_TYPE_LINE_NUMBER_TABLE_ATTR; attr->info.line_number_table_attr.line_number_table_length = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.line_number_table_attr.line_number_table = r_list_newf (free); + attr->info.line_number_table_attr.line_number_table = rz_list_newf (free); ut32 linenum_len = attr->info.line_number_table_attr.line_number_table_length; - RList *linenum_list = attr->info.line_number_table_attr.line_number_table; + RzList *linenum_list = attr->info.line_number_table_attr.line_number_table; for (i = 0; i < linenum_len; i++) { curpos = buf_offset + offset; // printf ("%llx %llx \n", curpos, sz); @@ -3851,22 +3851,22 @@ R_API RBinJavaAttrInfo *r_bin_java_line_number_table_attr_new(RBinJavaObj *bin, offset += 2; lnattr->file_offset = curpos; lnattr->size = 4; - r_list_append (linenum_list, lnattr); + rz_list_append (linenum_list, lnattr); } attr->size = offset; return attr; } -R_API ut64 r_bin_java_line_number_table_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_line_number_table_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 6; // RBinJavaLineNumberAttribute *lnattr; - RListIter *iter; - // RListIter *iter_tmp; + RzListIter *iter; + // RzListIter *iter_tmp; if (!attr) { return 0LL; } - // r_list_foreach_safe (attr->info.line_number_table_attr.line_number_table, iter, iter_tmp, lnattr) { - r_list_foreach_iter (attr->info.line_number_table_attr.line_number_table, iter) { + // rz_list_foreach_safe (attr->info.line_number_table_attr.line_number_table, iter, iter_tmp, lnattr) { + rz_list_foreach_iter (attr->info.line_number_table_attr.line_number_table, iter) { // lnattr->start_pc = R_BIN_JAVA_USHORT (buffer, offset); size += 2; // lnattr->line_number = R_BIN_JAVA_USHORT (buffer, offset); @@ -3875,19 +3875,19 @@ R_API ut64 r_bin_java_line_number_table_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API RBinJavaAttrInfo *r_bin_java_source_debug_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_source_debug_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 6; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } attr->type = R_BIN_JAVA_ATTR_TYPE_SOURCE_DEBUG_EXTENTSION_ATTR; if (attr->length == 0) { - eprintf ("r_bin_java_source_debug_attr_new: Attempting to allocate 0 bytes for debug_extension.\n"); + eprintf ("rz_bin_java_source_debug_attr_new: Attempting to allocate 0 bytes for debug_extension.\n"); attr->info.debug_extensions.debug_extension = NULL; return attr; } else if ((attr->length + offset) > sz) { - eprintf ("r_bin_java_source_debug_attr_new: Expected %d byte(s) got %" + eprintf ("rz_bin_java_source_debug_attr_new: Expected %d byte(s) got %" PFMT64d " bytes for debug_extension.\n", attr->length, (offset + sz)); } attr->info.debug_extensions.debug_extension = (ut8 *) malloc (attr->length); @@ -3896,14 +3896,14 @@ R_API RBinJavaAttrInfo *r_bin_java_source_debug_attr_new(RBinJavaObj *bin, ut8 * } else if (attr->info.debug_extensions.debug_extension) { memcpy (attr->info.debug_extensions.debug_extension, buffer + offset, attr->length); } else { - eprintf ("r_bin_java_source_debug_attr_new: Unable to allocate the data for the debug_extension.\n"); + eprintf ("rz_bin_java_source_debug_attr_new: Unable to allocate the data for the debug_extension.\n"); } offset += attr->length; attr->size = offset; return attr; } -R_API ut64 r_bin_java_source_debug_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_source_debug_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 6; if (!attr) { return 0LL; @@ -3914,10 +3914,10 @@ R_API ut64 r_bin_java_source_debug_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API ut64 r_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; // ut64 offset = 0; - RListIter *iter; + RzListIter *iter; // RBinJavaLocalVariableAttribute *lvattr; if (!attr) { return 0LL; @@ -3925,8 +3925,8 @@ R_API ut64 r_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr size += 6; // attr->info.local_variable_table_attr.table_length = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - // r_list_foreach (attr->info.local_variable_table_attr.local_variable_table, iter, lvattr) { - r_list_foreach_iter (attr->info.local_variable_table_attr.local_variable_table, iter) { + // rz_list_foreach (attr->info.local_variable_table_attr.local_variable_table, iter, lvattr) { + rz_list_foreach_iter (attr->info.local_variable_table_attr.local_variable_table, iter) { // lvattr->start_pc = R_BIN_JAVA_USHORT (buffer, offset); size += 2; // lvattr->length = R_BIN_JAVA_USHORT (buffer, offset); @@ -3941,7 +3941,7 @@ R_API ut64 r_bin_java_local_variable_table_attr_calc_size(RBinJavaAttrInfo *attr return size; } -R_API RBinJavaAttrInfo *r_bin_java_local_variable_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_local_variable_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaLocalVariableAttribute *lvattr; ut64 curpos = 0, offset = 6; RBinJavaAttrInfo *attr; @@ -3949,7 +3949,7 @@ R_API RBinJavaAttrInfo *r_bin_java_local_variable_table_attr_new(RBinJavaObj *bi if (!buffer || sz < 1) { return NULL; } - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } @@ -3957,7 +3957,7 @@ R_API RBinJavaAttrInfo *r_bin_java_local_variable_table_attr_new(RBinJavaObj *bi attr->info.local_variable_table_attr.table_length = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; attr->info.local_variable_table_attr.local_variable_table =\ - r_list_newf (r_bin_java_local_variable_table_attr_entry_free); + rz_list_newf (rz_bin_java_local_variable_table_attr_entry_free); for (i = 0; i < attr->info.local_variable_table_attr.table_length; i++) { if (offset + 10 > sz) { break; @@ -3975,35 +3975,35 @@ R_API RBinJavaAttrInfo *r_bin_java_local_variable_table_attr_new(RBinJavaObj *bi lvattr->index = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; lvattr->file_offset = curpos; - lvattr->name = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->name_idx); + lvattr->name = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->name_idx); lvattr->size = 10; if (!lvattr->name) { lvattr->name = strdup ("NULL"); - eprintf ("r_bin_java_local_variable_table_attr_new: Unable to find the name for %d index.\n", lvattr->name_idx); + eprintf ("rz_bin_java_local_variable_table_attr_new: Unable to find the name for %d index.\n", lvattr->name_idx); } - lvattr->descriptor = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->descriptor_idx); + lvattr->descriptor = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->descriptor_idx); if (!lvattr->descriptor) { lvattr->descriptor = strdup ("NULL"); - eprintf ("r_bin_java_local_variable_table_attr_new: Unable to find the descriptor for %d index.\n", lvattr->descriptor_idx); + eprintf ("rz_bin_java_local_variable_table_attr_new: Unable to find the descriptor for %d index.\n", lvattr->descriptor_idx); } - r_list_append (attr->info.local_variable_table_attr.local_variable_table, lvattr); + rz_list_append (attr->info.local_variable_table_attr.local_variable_table, lvattr); } attr->size = offset; - // IFDBG r_bin_java_print_local_variable_table_attr_summary(attr); + // IFDBG rz_bin_java_print_local_variable_table_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_local_variable_type_table_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_local_variable_type_table_attr_calc_size(RBinJavaAttrInfo *attr) { // RBinJavaLocalVariableTypeAttribute *lvattr; - RListIter *iter; + RzListIter *iter; ut64 size = 0; if (attr) { - RList *list = attr->info.local_variable_type_table_attr.local_variable_table; + RzList *list = attr->info.local_variable_type_table_attr.local_variable_table; size += 6; // attr->info.local_variable_type_table_attr.table_length = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - // r_list_foreach (list, iter, lvattr) { - r_list_foreach_iter (list, iter) { + // rz_list_foreach (list, iter, lvattr) { + rz_list_foreach_iter (list, iter) { // lvattr->start_pc = R_BIN_JAVA_USHORT (buffer, offset); size += 2; // lvattr->length = R_BIN_JAVA_USHORT (buffer, offset); @@ -4019,18 +4019,18 @@ R_API ut64 r_bin_java_local_variable_type_table_attr_calc_size(RBinJavaAttrInfo return size; } -R_API RBinJavaAttrInfo *r_bin_java_local_variable_type_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_local_variable_type_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaLocalVariableTypeAttribute *lvattr; ut64 offset = 6; ut32 i = 0; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, 0); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, 0); if (!attr) { return NULL; } attr->type = R_BIN_JAVA_ATTR_TYPE_LOCAL_VARIABLE_TYPE_TABLE_ATTR; attr->info.local_variable_type_table_attr.table_length = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.local_variable_type_table_attr.local_variable_table = r_list_newf (r_bin_java_local_variable_type_table_attr_entry_free); + attr->info.local_variable_type_table_attr.local_variable_table = rz_list_newf (rz_bin_java_local_variable_type_table_attr_entry_free); for (i = 0; i < attr->info.local_variable_type_table_attr.table_length; i++) { ut64 curpos = buf_offset + offset; lvattr = R_NEW0 (RBinJavaLocalVariableTypeAttribute); @@ -4054,30 +4054,30 @@ R_API RBinJavaAttrInfo *r_bin_java_local_variable_type_table_attr_new(RBinJavaOb lvattr->index = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; lvattr->file_offset = curpos; - lvattr->name = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->name_idx); + lvattr->name = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->name_idx); lvattr->size = 10; if (!lvattr->name) { lvattr->name = strdup ("NULL"); - eprintf ("r_bin_java_local_variable_type_table_attr_new: Unable to find the name for %d index.\n", lvattr->name_idx); + eprintf ("rz_bin_java_local_variable_type_table_attr_new: Unable to find the name for %d index.\n", lvattr->name_idx); } - lvattr->signature = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->signature_idx); + lvattr->signature = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, lvattr->signature_idx); if (!lvattr->signature) { lvattr->signature = strdup ("NULL"); - eprintf ("r_bin_java_local_variable_type_table_attr_new: Unable to find the descriptor for %d index.\n", lvattr->signature_idx); + eprintf ("rz_bin_java_local_variable_type_table_attr_new: Unable to find the descriptor for %d index.\n", lvattr->signature_idx); } - r_list_append (attr->info.local_variable_type_table_attr.local_variable_table, lvattr); + rz_list_append (attr->info.local_variable_type_table_attr.local_variable_table, lvattr); } - // IFDBG r_bin_java_print_local_variable_type_table_attr_summary(attr); + // IFDBG rz_bin_java_print_local_variable_type_table_attr_summary(attr); attr->size = offset; return attr; } -R_API RBinJavaAttrInfo *r_bin_java_source_code_file_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_source_code_file_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { if (!sz) { return NULL; } ut64 offset = 0; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (!attr) { return NULL; @@ -4087,17 +4087,17 @@ R_API RBinJavaAttrInfo *r_bin_java_source_code_file_attr_new(RBinJavaObj *bin, u attr->info.source_file_attr.sourcefile_idx = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; attr->size = offset; - // IFDBG r_bin_java_print_source_code_file_attr_summary(attr); + // IFDBG rz_bin_java_print_source_code_file_attr_summary(attr); return attr; } -R_API ut64 r_bin_java_source_code_file_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_source_code_file_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? 8 : 0; } -R_API RBinJavaAttrInfo *r_bin_java_synthetic_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_synthetic_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 0; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); if (!attr) { return NULL; } @@ -4107,33 +4107,33 @@ R_API RBinJavaAttrInfo *r_bin_java_synthetic_attr_new(RBinJavaObj *bin, ut8 *buf return attr; } -R_API ut64 r_bin_java_synthetic_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_synthetic_attr_calc_size(RBinJavaAttrInfo *attr) { return attr ? 12 : 6; } -R_API RBinJavaInterfaceInfo *r_bin_java_interface_new(RBinJavaObj *bin, const ut8 *buffer, ut64 sz) { +RZ_API RBinJavaInterfaceInfo *rz_bin_java_interface_new(RBinJavaObj *bin, const ut8 *buffer, ut64 sz) { RBinJavaInterfaceInfo *ifobj = NULL; ifobj = R_NEW0 (RBinJavaInterfaceInfo); IFDBG eprintf("Parsing RBinJavaInterfaceInfo\n"); if (ifobj) { if (buffer) { ifobj->class_info_idx = R_BIN_JAVA_USHORT (buffer, 0); - ifobj->cp_class = r_bin_java_get_item_from_bin_cp_list (bin, ifobj->class_info_idx); + ifobj->cp_class = rz_bin_java_get_item_from_bin_cp_list (bin, ifobj->class_info_idx); if (ifobj->cp_class) { - ifobj->name = r_bin_java_get_item_name_from_bin_cp_list (bin, ifobj->cp_class); + ifobj->name = rz_bin_java_get_item_name_from_bin_cp_list (bin, ifobj->cp_class); } else { - ifobj->name = r_str_dup (NULL, "NULL"); + ifobj->name = rz_str_dup (NULL, "NULL"); } ifobj->size = 2; } else { ifobj->class_info_idx = 0; - ifobj->name = r_str_dup (NULL, "NULL"); + ifobj->name = rz_str_dup (NULL, "NULL"); } } return ifobj; } -R_API RBinJavaVerificationObj *r_bin_java_verification_info_from_type(RBinJavaObj *bin, R_BIN_JAVA_STACKMAP_TYPE type, ut32 value) { +RZ_API RBinJavaVerificationObj *rz_bin_java_verification_info_from_type(RBinJavaObj *bin, R_BIN_JAVA_STACKMAP_TYPE type, ut32 value) { RBinJavaVerificationObj *se = R_NEW0 (RBinJavaVerificationObj); if (!se) { return NULL; @@ -4152,7 +4152,7 @@ R_API RBinJavaVerificationObj *r_bin_java_verification_info_from_type(RBinJavaOb return se; } -R_API RBinJavaVerificationObj *r_bin_java_read_from_buffer_verification_info_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaVerificationObj *rz_bin_java_read_from_buffer_verification_info_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 0; RBinJavaVerificationObj *se = R_NEW0 (RBinJavaVerificationObj); if (!se) { @@ -4169,33 +4169,33 @@ R_API RBinJavaVerificationObj *r_bin_java_read_from_buffer_verification_info_new offset += 2; } if (R_BIN_JAVA_STACKMAP_UNINIT < se->tag) { - r_bin_java_verification_info_free (se); + rz_bin_java_verification_info_free (se); return NULL; } se->size = offset; return se; } -R_API ut64 rbin_java_verification_info_calc_size(RBinJavaVerificationObj *se) { +RZ_API ut64 rbin_java_verification_info_calc_size(RBinJavaVerificationObj *se) { ut64 sz = 1; if (!se) { return 0; } - // r_buf_read_at (bin->b, offset, (ut8*)(&se->tag), 1) + // rz_buf_read_at (bin->b, offset, (ut8*)(&se->tag), 1) switch (se->tag) { case R_BIN_JAVA_STACKMAP_OBJECT: - // r_buf_read_at (bin->b, offset+1, (ut8*)buf, 2) + // rz_buf_read_at (bin->b, offset+1, (ut8*)buf, 2) sz += 2; break; case R_BIN_JAVA_STACKMAP_UNINIT: - // r_buf_read_at (bin->b, offset+1, (ut8*)buf, 2) + // rz_buf_read_at (bin->b, offset+1, (ut8*)buf, 2) sz += 2; break; } return sz; } -R_API RBinJavaStackMapFrameMetas *r_bin_java_determine_stack_frame_type(ut8 tag) { +RZ_API RBinJavaStackMapFrameMetas *rz_bin_java_determine_stack_frame_type(ut8 tag) { ut8 type_value = 0; if (tag < 64) { type_value = R_BIN_JAVA_STACK_FRAME_SAME; @@ -4215,9 +4215,9 @@ R_API RBinJavaStackMapFrameMetas *r_bin_java_determine_stack_frame_type(ut8 tag) return &R_BIN_JAVA_STACK_MAP_FRAME_METAS[type_value]; } -R_API ut64 r_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { +RZ_API ut64 rz_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { ut64 size = 0; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; RBinJavaVerificationObj *se; if (sf) { // sf->tag = buffer[offset]; @@ -4227,7 +4227,7 @@ R_API ut64 r_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { // Nothing to read break; case R_BIN_JAVA_STACK_FRAME_SAME_LOCALS_1: - r_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { + rz_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { size += rbin_java_verification_info_calc_size (se); } break; @@ -4238,14 +4238,14 @@ R_API ut64 r_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { case R_BIN_JAVA_STACK_FRAME_SAME_FRAME_EXTENDED: // sf->offset_delta = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { + rz_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { size += rbin_java_verification_info_calc_size (se); } break; case R_BIN_JAVA_STACK_FRAME_APPEND: // sf->offset_delta = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { + rz_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { size += rbin_java_verification_info_calc_size (se); } break; @@ -4254,12 +4254,12 @@ R_API ut64 r_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { size += 2; // sf->number_of_locals = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (sf->local_items, iter, iter_tmp, se) { + rz_list_foreach_safe (sf->local_items, iter, iter_tmp, se) { size += rbin_java_verification_info_calc_size (se); } // sf->number_of_stack_items = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { + rz_list_foreach_safe (sf->stack_items, iter, iter_tmp, se) { size += rbin_java_verification_info_calc_size (se); } break; @@ -4271,8 +4271,8 @@ R_API ut64 r_bin_java_stack_map_frame_calc_size(RBinJavaStackMapFrame *sf) { return size; } -R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz, RBinJavaStackMapFrame *p_frame, ut64 buf_offset) { - RBinJavaStackMapFrame *stack_frame = r_bin_java_default_stack_frame (); +RZ_API RBinJavaStackMapFrame *rz_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz, RBinJavaStackMapFrame *p_frame, ut64 buf_offset) { + RBinJavaStackMapFrame *stack_frame = rz_bin_java_default_stack_frame (); RBinJavaVerificationObj *se = NULL; ut64 offset = 0; if (!stack_frame) { @@ -4280,7 +4280,7 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz } stack_frame->tag = buffer[offset]; offset += 1; - stack_frame->metas->type_info = (void *) r_bin_java_determine_stack_frame_type (stack_frame->tag); + stack_frame->metas->type_info = (void *) rz_bin_java_determine_stack_frame_type (stack_frame->tag); stack_frame->type = ((RBinJavaStackMapFrameMetas *) stack_frame->metas->type_info)->type; stack_frame->file_offset = buf_offset; stack_frame->p_stack_frame = p_frame; @@ -4294,25 +4294,25 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz IFINT eprintf("><\n"); IFDBG eprintf("Unable to set previous stackframe with the number of locals (current info.code_attr.implicit_frame was probably not set :/)"); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Condition is untested, so there may be issues.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Condition is untested, so there may be issues.\n"); break; case R_BIN_JAVA_STACK_FRAME_SAME_LOCALS_1: // 1. Read the stack type stack_frame->number_of_stack_items = 1; if (offset > sz) { - r_bin_java_stack_frame_free (stack_frame); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - se = r_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsed R_BIN_JAVA_STACK_FRAME_SAME_LOCALS_1.\n"); + se = rz_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsed R_BIN_JAVA_STACK_FRAME_SAME_LOCALS_1.\n"); if (se) { offset += se->size; } else { - eprintf ("r_bin_java_stack_map_frame_new: Unable to parse the Stack Items for the stack frame.\n"); - r_bin_java_stack_frame_free (stack_frame); + eprintf ("rz_bin_java_stack_map_frame_new: Unable to parse the Stack Items for the stack frame.\n"); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - r_list_append (stack_frame->stack_items, (void *) se); + rz_list_append (stack_frame->stack_items, (void *) se); // Maybe? 3. Copy the previous frames locals and set the locals count. // copy_type_info_to_stack_frame_list_up_to_idx (p_frame->local_items, stack_frame->local_items, idx); if (p_frame) { @@ -4320,12 +4320,12 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz } else { IFDBG eprintf("Unable to set previous stackframe with the number of locals (current info.code_attr.implicit_frame was probably not set :/)"); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals 1 Stack Element Condition is untested, so there may be issues.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals 1 Stack Element Condition is untested, so there may be issues.\n"); break; case R_BIN_JAVA_STACK_FRAME_CHOP: // 1. Calculate the max index we want to copy from the list of the // previous frames locals - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_CHOP.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_CHOP.\n"); // ut16 k = 251 - stack_frame->tag; /*, idx = p_frame->number_of_locals - k; @@ -4341,24 +4341,24 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz IFINT eprintf("><\n"); IFDBG eprintf("Unable to set previous stackframe with the number of locals (current info.code_attr.implicit_frame was probably not set :/)"); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: TODO Stack Frame Chop Condition is untested, so there may be issues.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: TODO Stack Frame Chop Condition is untested, so there may be issues.\n"); break; case R_BIN_JAVA_STACK_FRAME_SAME_FRAME_EXTENDED: - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_SAME_FRAME_EXTENDED.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_SAME_FRAME_EXTENDED.\n"); // 1. Read the uoffset stack_frame->offset_delta = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; // 2. Read the stack element type stack_frame->number_of_stack_items = 1; - se = r_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); + se = rz_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); if (se) { offset += se->size; } else { - eprintf ("r_bin_java_stack_map_frame_new: Unable to parse the Stack Items for the stack frame.\n"); - r_bin_java_stack_frame_free (stack_frame); + eprintf ("rz_bin_java_stack_map_frame_new: Unable to parse the Stack Items for the stack frame.\n"); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - r_list_append (stack_frame->stack_items, (void *) se); + rz_list_append (stack_frame->stack_items, (void *) se); // Maybe? 3. Copy the previous frames locals to the current locals // copy_type_info_to_stack_frame_list_up_to_idx (p_frame->local_items, stack_frame->local_items, idx); if (p_frame) { @@ -4367,10 +4367,10 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz IFINT eprintf("><\n"); IFDBG eprintf("Unable to set previous stackframe with the number of locals (current info.code_attr.implicit_frame was probably not set :/)"); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Frame Stack 1 Extended Condition is untested, so there may be issues.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Frame Stack 1 Extended Condition is untested, so there may be issues.\n"); break; case R_BIN_JAVA_STACK_FRAME_APPEND: - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_APPEND.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_APPEND.\n"); // 1. Calculate the max index we want to copy from the list of the // previous frames locals ut16 k = stack_frame->tag - 251; @@ -4385,19 +4385,19 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz if (offset >= sz) { break; } - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsing verifying the k'th frame: %d of %d.\n", i, k); - se = r_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); - IFDBG eprintf("r_bin_java_stack_map_frame_new: Completed Parsing\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsing verifying the k'th frame: %d of %d.\n", i, k); + se = rz_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Completed Parsing\n"); if (se) { offset += se->size; } else { - eprintf ("r_bin_java_stack_map_frame_new: Unable to parse the locals for the stack frame.\n"); - r_bin_java_stack_frame_free (stack_frame); + eprintf ("rz_bin_java_stack_map_frame_new: Unable to parse the locals for the stack frame.\n"); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - r_list_append (stack_frame->local_items, (void *) se); + rz_list_append (stack_frame->local_items, (void *) se); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: Breaking out of loop"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Breaking out of loop"); IFDBG eprintf("p_frame: %p\n", p_frame); if (p_frame) { stack_frame->number_of_locals = p_frame->number_of_locals + k; @@ -4405,70 +4405,70 @@ R_API RBinJavaStackMapFrame *r_bin_java_stack_map_frame_new(ut8 *buffer, ut64 sz IFINT eprintf("><\n"); IFDBG eprintf("Unable to set previous stackframe with the number of locals (current info.code_attr.implicit_frame was probably not set :/)"); } - IFDBG eprintf("r_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Frame Stack 1 Extended Condition is untested, so there may be issues.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: TODO Stack Frame Same Locals Frame Stack 1 Extended Condition is untested, so there may be issues.\n"); break; case R_BIN_JAVA_STACK_FRAME_FULL_FRAME: - IFDBG eprintf("r_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_FULL_FRAME.\n"); + IFDBG eprintf("rz_bin_java_stack_map_frame_new: Parsing R_BIN_JAVA_STACK_FRAME_FULL_FRAME.\n"); stack_frame->offset_delta = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - // IFDBG eprintf ("r_bin_java_stack_map_frame_new: Code Size > 65535, read(%d byte(s)), offset = 0x%08x.\n", var_sz, stack_frame->offset_delta); + // IFDBG eprintf ("rz_bin_java_stack_map_frame_new: Code Size > 65535, read(%d byte(s)), offset = 0x%08x.\n", var_sz, stack_frame->offset_delta); // Read the number of variables based on the max # local variable stack_frame->number_of_locals = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - // IFDBG eprintf ("r_bin_java_stack_map_frame_new: Max ulocalvar > 65535, read(%d byte(s)), number_of_locals = 0x%08x.\n", var_sz, stack_frame->number_of_locals); - IFDBG r_bin_java_print_stack_map_frame_summary(stack_frame); + // IFDBG eprintf ("rz_bin_java_stack_map_frame_new: Max ulocalvar > 65535, read(%d byte(s)), number_of_locals = 0x%08x.\n", var_sz, stack_frame->number_of_locals); + IFDBG rz_bin_java_print_stack_map_frame_summary(stack_frame); // read the number of locals off the stack for (i = 0; i < stack_frame->number_of_locals; i++) { if (offset >= sz) { break; } - se = r_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); + se = rz_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); if (se) { offset += se->size; - // r_list_append (stack_frame->local_items, (void *) se); + // rz_list_append (stack_frame->local_items, (void *) se); } else { - eprintf ("r_bin_java_stack_map_frame_new: Unable to parse the locals for the stack frame.\n"); - r_bin_java_stack_frame_free (stack_frame); + eprintf ("rz_bin_java_stack_map_frame_new: Unable to parse the locals for the stack frame.\n"); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - r_list_append (stack_frame->local_items, (void *) se); + rz_list_append (stack_frame->local_items, (void *) se); } // Read the number of stack items based on the max size of stack stack_frame->number_of_stack_items = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - // IFDBG eprintf ("r_bin_java_stack_map_frame_new: Max ustack items > 65535, read(%d byte(s)), number_of_locals = 0x%08x.\n", var_sz, stack_frame->number_of_stack_items); + // IFDBG eprintf ("rz_bin_java_stack_map_frame_new: Max ustack items > 65535, read(%d byte(s)), number_of_locals = 0x%08x.\n", var_sz, stack_frame->number_of_stack_items); // read the stack items for (i = 0; i < stack_frame->number_of_stack_items; i++) { if (offset >= sz) { break; } - se = r_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); + se = rz_bin_java_read_from_buffer_verification_info_new (buffer + offset, sz - offset, buf_offset + offset); if (se) { offset += se->size; - // r_list_append (stack_frame->stack_items, (void *) se); + // rz_list_append (stack_frame->stack_items, (void *) se); } else { - eprintf ("r_bin_java_stack_map_frame_new: Unable to parse the stack items for the stack frame.\n"); - r_bin_java_stack_frame_free (stack_frame); + eprintf ("rz_bin_java_stack_map_frame_new: Unable to parse the stack items for the stack frame.\n"); + rz_bin_java_stack_frame_free (stack_frame); return NULL; } - r_list_append (stack_frame->local_items, (void *) se); + rz_list_append (stack_frame->local_items, (void *) se); } break; default: eprintf ("java: Unknown type\n"); break; } - // IFDBG eprintf ("Created a stack frame at offset(0x%08"PFMT64x") of size: %d\n", buf_offset, stack_frame->size);//r_bin_java_print_stack_map_frame_summary(stack_frame); + // IFDBG eprintf ("Created a stack frame at offset(0x%08"PFMT64x") of size: %d\n", buf_offset, stack_frame->size);//rz_bin_java_print_stack_map_frame_summary(stack_frame); stack_frame->size = offset; - // IFDBG r_bin_java_print_stack_map_frame_summary(stack_frame); + // IFDBG rz_bin_java_print_stack_map_frame_summary(stack_frame); return stack_frame; } -R_API ut16 r_bin_java_find_cp_class_ref_from_name_idx(RBinJavaObj *bin, ut16 name_idx) { - ut16 pos, len = (ut16) r_list_length (bin->cp_list); +RZ_API ut16 rz_bin_java_find_cp_class_ref_from_name_idx(RBinJavaObj *bin, ut16 name_idx) { + ut16 pos, len = (ut16) rz_list_length (bin->cp_list); RBinJavaCPTypeObj *item; for (pos = 0; pos < len; pos++) { - item = (RBinJavaCPTypeObj *) r_list_get_n (bin->cp_list, pos); + item = (RBinJavaCPTypeObj *) rz_list_get_n (bin->cp_list, pos); if (item && item->tag == R_BIN_JAVA_CP_CLASS && item->info.cp_class.name_idx == name_idx) { break; } @@ -4476,7 +4476,7 @@ R_API ut16 r_bin_java_find_cp_class_ref_from_name_idx(RBinJavaObj *bin, ut16 nam return (pos != len) ? pos : 0; } -R_API RBinJavaStackMapFrame *r_bin_java_default_stack_frame(void) { +RZ_API RBinJavaStackMapFrame *rz_bin_java_default_stack_frame(void) { RBinJavaStackMapFrame *sf = R_NEW0 (RBinJavaStackMapFrame); if (!sf) { return NULL; @@ -4488,18 +4488,18 @@ R_API RBinJavaStackMapFrame *r_bin_java_default_stack_frame(void) { } sf->metas->type_info = (void *) &R_BIN_JAVA_STACK_MAP_FRAME_METAS[R_BIN_JAVA_STACK_FRAME_IMPLICIT]; sf->type = ((RBinJavaStackMapFrameMetas *) sf->metas->type_info)->type; - sf->local_items = r_list_newf (r_bin_java_verification_info_free); - sf->stack_items = r_list_newf (r_bin_java_verification_info_free); + sf->local_items = rz_list_newf (rz_bin_java_verification_info_free); + sf->stack_items = rz_list_newf (rz_bin_java_verification_info_free); sf->number_of_stack_items = 0; sf->number_of_locals = 0; return sf; } -R_API RBinJavaStackMapFrame *r_bin_java_build_stack_frame_from_local_variable_table(RBinJavaObj *bin, RBinJavaAttrInfo *attr) { - RBinJavaStackMapFrame *sf = r_bin_java_default_stack_frame (); +RZ_API RBinJavaStackMapFrame *rz_bin_java_build_stack_frame_from_local_variable_table(RBinJavaObj *bin, RBinJavaAttrInfo *attr) { + RBinJavaStackMapFrame *sf = rz_bin_java_default_stack_frame (); RBinJavaLocalVariableAttribute *lvattr = NULL; RBinJavaVerificationObj *type_item; - RListIter *iter = NULL; + RzListIter *iter = NULL; ut32 value_cnt = 0; ut8 value; if (!sf || !bin || !attr || attr->type != R_BIN_JAVA_ATTR_TYPE_LOCAL_VARIABLE_TABLE_ATTR) { @@ -4507,7 +4507,7 @@ R_API RBinJavaStackMapFrame *r_bin_java_build_stack_frame_from_local_variable_ta return sf; } sf->number_of_locals = attr->info.local_variable_table_attr.table_length; - r_list_foreach (attr->info.local_variable_table_attr.local_variable_table, iter, lvattr) { + rz_list_foreach (attr->info.local_variable_table_attr.local_variable_table, iter, lvattr) { ut32 pos = 0; // knock the array Types while (lvattr->descriptor[pos] == '[') { @@ -4521,81 +4521,81 @@ R_API RBinJavaStackMapFrame *r_bin_java_build_stack_frame_from_local_variable_ta case 'S': case 'B': case 'C': - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_INTEGER, 0); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_INTEGER, 0); break; case 'F': - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_FLOAT, 0); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_FLOAT, 0); break; case 'D': - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_DOUBLE, 0); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_DOUBLE, 0); break; case 'J': - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_LONG, 0); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_LONG, 0); break; case 'L': // TODO: FIXME write something that will iterate over the CP Pool and find the // CONSTANT_Class_info referencing this { - ut16 idx = r_bin_java_find_cp_class_ref_from_name_idx (bin, lvattr->name_idx); - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_OBJECT, idx); + ut16 idx = rz_bin_java_find_cp_class_ref_from_name_idx (bin, lvattr->name_idx); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_OBJECT, idx); } break; default: - eprintf ("r_bin_java_build_stack_frame_from_local_variable_table: " + eprintf ("rz_bin_java_build_stack_frame_from_local_variable_table: " "not sure how to handle: name: %s, type: %s\n", lvattr->name, lvattr->descriptor); - type_item = r_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_NULL, 0); + type_item = rz_bin_java_verification_info_from_type (bin, R_BIN_JAVA_STACKMAP_NULL, 0); } if (type_item) { - r_list_append (sf->local_items, (void *) type_item); + rz_list_append (sf->local_items, (void *) type_item); } value_cnt++; } if (value_cnt != attr->info.local_variable_table_attr.table_length) { - IFDBG eprintf("r_bin_java_build_stack_frame_from_local_variable_table: " + IFDBG eprintf("rz_bin_java_build_stack_frame_from_local_variable_table: " "Number of locals not accurate. Expected %d but got %d", attr->info.local_variable_table_attr.table_length, value_cnt); } return sf; } -R_API ut64 r_bin_java_stack_map_table_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_stack_map_table_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; RBinJavaStackMapFrame *sf; if (attr) { - // attr = r_bin_java_default_attr_new (buffer, sz, buf_offset); + // attr = rz_bin_java_default_attr_new (buffer, sz, buf_offset); size += 6; - // IFDBG r_bin_java_print_source_code_file_attr_summary(attr); + // IFDBG rz_bin_java_print_source_code_file_attr_summary(attr); // Current spec does not call for variable sizes. // attr->info.stack_map_table_attr.number_of_entries = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (attr->info.stack_map_table_attr.stack_map_frame_entries, iter, iter_tmp, sf) { - size += r_bin_java_stack_map_frame_calc_size (sf); + rz_list_foreach_safe (attr->info.stack_map_table_attr.stack_map_frame_entries, iter, iter_tmp, sf) { + size += rz_bin_java_stack_map_frame_calc_size (sf); } } return size; } -R_API RBinJavaAttrInfo *r_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; ut64 offset = 0; RBinJavaStackMapFrame *stack_frame = NULL, *new_stack_frame = NULL; if (sz < 10) { return NULL; } - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; - IFDBG eprintf("r_bin_java_stack_map_table_attr_new: New stack map allocated.\n"); + IFDBG eprintf("rz_bin_java_stack_map_table_attr_new: New stack map allocated.\n"); if (!attr) { return NULL; } - attr->info.stack_map_table_attr.stack_map_frame_entries = r_list_newf (r_bin_java_stack_frame_free); - // IFDBG r_bin_java_print_source_code_file_attr_summary(attr); + attr->info.stack_map_table_attr.stack_map_frame_entries = rz_list_newf (rz_bin_java_stack_frame_free); + // IFDBG rz_bin_java_print_source_code_file_attr_summary(attr); // Current spec does not call for variable sizes. attr->info.stack_map_table_attr.number_of_entries = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - IFDBG eprintf("r_bin_java_stack_map_table_attr_new: Processing stack map, summary is:\n"); - IFDBG r_bin_java_print_stack_map_table_attr_summary(attr); + IFDBG eprintf("rz_bin_java_stack_map_table_attr_new: Processing stack map, summary is:\n"); + IFDBG rz_bin_java_print_stack_map_table_attr_summary(attr); for (i = 0; i < attr->info.stack_map_table_attr.number_of_entries; i++) { // read next stack frame IFDBG eprintf("Reading StackMap Entry #%d @ 0x%08"PFMT64x "\n", i, buf_offset + offset); @@ -4605,18 +4605,18 @@ R_API RBinJavaAttrInfo *r_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut } IFDBG eprintf("Reading StackMap Entry #%d @ 0x%08"PFMT64x ", current stack_frame: %p\n", i, buf_offset + offset, stack_frame); if (offset >= sz) { - r_bin_java_stack_map_table_attr_free (attr); + rz_bin_java_stack_map_table_attr_free (attr); return NULL; } - new_stack_frame = r_bin_java_stack_map_frame_new (buffer + offset, sz - offset, stack_frame, buf_offset + offset); + new_stack_frame = rz_bin_java_stack_map_frame_new (buffer + offset, sz - offset, stack_frame, buf_offset + offset); if (new_stack_frame) { offset += new_stack_frame->size; // append stack frame to the list - r_list_append (attr->info.stack_map_table_attr.stack_map_frame_entries, (void *) new_stack_frame); + rz_list_append (attr->info.stack_map_table_attr.stack_map_frame_entries, (void *) new_stack_frame); stack_frame = new_stack_frame; } else { - eprintf ("r_bin_java_stack_map_table_attr_new: Unable to parse the stack frame for the stack map table.\n"); - r_bin_java_stack_map_table_attr_free (attr); + eprintf ("rz_bin_java_stack_map_table_attr_new: Unable to parse the stack frame for the stack map table.\n"); + rz_bin_java_stack_map_table_attr_free (attr); attr = NULL; break; } @@ -4628,19 +4628,19 @@ R_API RBinJavaAttrInfo *r_bin_java_stack_map_table_attr_new(RBinJavaObj *bin, ut } // End attribute types new // Start new Constant Pool Types -R_API RBinJavaCPTypeObj *r_bin_java_do_nothing_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_do_nothing_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { return (RBinJavaCPTypeObj *) NULL; } -R_API ut64 r_bin_java_do_nothing_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_do_nothing_calc_size(RBinJavaCPTypeObj *obj) { return 0; } -R_API void r_bin_java_do_nothing_free(void /*RBinJavaCPTypeObj*/ *obj) { +RZ_API void rz_bin_java_do_nothing_free(void /*RBinJavaCPTypeObj*/ *obj) { return; } -R_API RBinJavaCPTypeObj *r_bin_java_unknown_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_unknown_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; obj = (RBinJavaCPTypeObj *) malloc (sizeof (RBinJavaCPTypeObj)); @@ -4653,13 +4653,13 @@ R_API RBinJavaCPTypeObj *r_bin_java_unknown_cp_new(RBinJavaObj *bin, ut8 *buffer return obj; } -R_API ut64 r_bin_java_unknown_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_unknown_cp_calc_size(RBinJavaCPTypeObj *obj) { return 1LL; } -R_API RBinJavaCPTypeObj *r_bin_java_class_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_class_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_CLASS, tag, sz, "Class"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_CLASS, tag, sz, "Class"); if (quick_check > 0) { return NULL; } @@ -4673,7 +4673,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_class_cp_new(RBinJavaObj *bin, ut8 *buffer, return obj; } -R_API ut64 r_bin_java_class_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_class_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // ut8 tag = buffer[0]; size += 1; @@ -4682,11 +4682,11 @@ R_API ut64 r_bin_java_class_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_fieldref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_fieldref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_FIELDREF, tag, sz, "FieldRef"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_FIELDREF, tag, sz, "FieldRef"); if (quick_check > 0) { return obj; } @@ -4703,7 +4703,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_fieldref_cp_new(RBinJavaObj *bin, ut8 *buffe return (RBinJavaCPTypeObj *) obj; } -R_API ut64 r_bin_java_fieldref_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_fieldref_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4714,11 +4714,11 @@ R_API ut64 r_bin_java_fieldref_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_methodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_METHODREF, tag, sz, "MethodRef"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_METHODREF, tag, sz, "MethodRef"); if (quick_check > 0) { return obj; } @@ -4734,7 +4734,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_methodref_cp_new(RBinJavaObj *bin, ut8 *buff return obj; } -R_API ut64 r_bin_java_methodref_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_methodref_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4745,9 +4745,9 @@ R_API ut64 r_bin_java_methodref_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_INTERFACEMETHOD_REF, tag, sz, "InterfaceMethodRef"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_INTERFACEMETHOD_REF, tag, sz, "InterfaceMethodRef"); if (quick_check > 0) { return NULL; } @@ -4756,7 +4756,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); obj->info.cp_interface.class_idx = R_BIN_JAVA_USHORT (buffer, 1); obj->info.cp_interface.name_and_type_idx = R_BIN_JAVA_USHORT (buffer, 3); @@ -4764,7 +4764,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_interfacemethodref_cp_new(RBinJavaObj *bin, return obj; } -R_API ut64 r_bin_java_interfacemethodref_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_interfacemethodref_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4775,9 +4775,9 @@ R_API ut64 r_bin_java_interfacemethodref_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_string_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_string_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_STRING, tag, sz, "String"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_STRING, tag, sz, "String"); if (quick_check > 0) { return NULL; } @@ -4786,13 +4786,13 @@ R_API RBinJavaCPTypeObj *r_bin_java_string_cp_new(RBinJavaObj *bin, ut8 *buffer, obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); obj->info.cp_string.string_idx = R_BIN_JAVA_USHORT (buffer, 1); } return obj; } -R_API ut64 r_bin_java_string_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_string_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4801,11 +4801,11 @@ R_API ut64 r_bin_java_string_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_INTEGER, tag, sz, "Integer"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_INTEGER, tag, sz, "Integer"); if (quick_check > 0) { return obj; } @@ -4814,7 +4814,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); memset (&obj->info.cp_integer.bytes, 0, sizeof (obj->info.cp_integer.bytes)); memcpy (&obj->info.cp_integer.bytes.raw, buffer + 1, 4); @@ -4822,7 +4822,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_integer_cp_new(RBinJavaObj *bin, ut8 *buffer return obj; } -R_API ut64 r_bin_java_integer_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_integer_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4831,11 +4831,11 @@ R_API ut64 r_bin_java_integer_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_float_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_float_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_FLOAT, tag, sz, "Float"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_FLOAT, tag, sz, "Float"); if (quick_check > 0) { return obj; } @@ -4844,14 +4844,14 @@ R_API RBinJavaCPTypeObj *r_bin_java_float_cp_new(RBinJavaObj *bin, ut8 *buffer, obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); memset (&obj->info.cp_float.bytes, 0, sizeof (obj->info.cp_float.bytes)); memcpy (&obj->info.cp_float.bytes.raw, buffer, 4); } return (RBinJavaCPTypeObj *) obj; } -R_API ut64 r_bin_java_float_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_float_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4860,11 +4860,11 @@ R_API ut64 r_bin_java_float_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_LONG, tag, sz, "Long"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_LONG, tag, sz, "Long"); if (quick_check > 0) { return obj; } @@ -4874,7 +4874,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, u obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); memset (&obj->info.cp_long.bytes, 0, sizeof (obj->info.cp_long.bytes)); memcpy (&(obj->info.cp_long.bytes), buffer + 1, 8); @@ -4882,7 +4882,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_long_cp_new(RBinJavaObj *bin, ut8 *buffer, u return obj; } -R_API ut64 r_bin_java_long_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_long_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4891,11 +4891,11 @@ R_API ut64 r_bin_java_long_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_double_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_double_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_DOUBLE, tag, sz, "Double"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_DOUBLE, tag, sz, "Double"); if (quick_check > 0) { return (RBinJavaCPTypeObj *) obj; } @@ -4905,14 +4905,14 @@ R_API RBinJavaCPTypeObj *r_bin_java_double_cp_new(RBinJavaObj *bin, ut8 *buffer, obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); memset (&obj->info.cp_double.bytes, 0, sizeof (obj->info.cp_double.bytes)); memcpy (&obj->info.cp_double.bytes, buffer + 1, 8); } return obj; } -R_API ut64 r_bin_java_double_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_double_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; // tag size += 1; @@ -4921,10 +4921,10 @@ R_API ut64 r_bin_java_double_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_UTF8, tag, sz, "Utf8"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_UTF8, tag, sz, "Utf8"); if (quick_check > 0) { return NULL; } @@ -4932,7 +4932,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, u obj->tag = tag; obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name); obj->info.cp_utf8.length = R_BIN_JAVA_USHORT (buffer, 1); obj->info.cp_utf8.bytes = (ut8 *) malloc (obj->info.cp_utf8.length + 1); if (obj->info.cp_utf8.bytes) { @@ -4945,14 +4945,14 @@ R_API RBinJavaCPTypeObj *r_bin_java_utf8_cp_new(RBinJavaObj *bin, ut8 *buffer, u } obj->value = obj->info.cp_utf8.bytes; } else { - r_bin_java_obj_free (obj); + rz_bin_java_obj_free (obj); obj = NULL; } } return obj; } -R_API ut64 r_bin_java_utf8_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_utf8_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; size += 1; if (obj && R_BIN_JAVA_CP_UTF8 == obj->tag) { @@ -4962,11 +4962,11 @@ R_API ut64 r_bin_java_utf8_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj = NULL; int quick_check = 0; - quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_NAMEANDTYPE, tag, sz, "RBinJavaCPTypeNameAndType"); + quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_NAMEANDTYPE, tag, sz, "RBinJavaCPTypeNameAndType"); if (quick_check > 0) { return obj; } @@ -4974,7 +4974,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 * if (obj) { obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; obj->tag = tag; obj->info.cp_name_and_type.name_idx = R_BIN_JAVA_USHORT (buffer, 1); obj->info.cp_name_and_type.descriptor_idx = R_BIN_JAVA_USHORT (buffer, 3); @@ -4982,7 +4982,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_name_and_type_cp_new(RBinJavaObj *bin, ut8 * return obj; } -R_API ut64 r_bin_java_name_and_type_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_name_and_type_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; if (obj) { size += 1; @@ -4994,9 +4994,9 @@ R_API ut64 r_bin_java_name_and_type_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_methodtype_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodtype_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_METHODTYPE, tag, sz, "RBinJavaCPTypeMethodType"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_METHODTYPE, tag, sz, "RBinJavaCPTypeMethodType"); if (quick_check > 0) { return NULL; } @@ -5004,14 +5004,14 @@ R_API RBinJavaCPTypeObj *r_bin_java_methodtype_cp_new(RBinJavaObj *bin, ut8 *buf if (obj) { obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; obj->tag = tag; obj->info.cp_method_type.descriptor_index = R_BIN_JAVA_USHORT (buffer, 1); } return obj; } -R_API ut64 r_bin_java_methodtype_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_methodtype_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; size += 1; // obj->info.cp_method_type.descriptor_index = R_BIN_JAVA_USHORT (buffer, 1); @@ -5019,9 +5019,9 @@ R_API ut64 r_bin_java_methodtype_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_METHODHANDLE, tag, sz, "RBinJavaCPTypeMethodHandle"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_METHODHANDLE, tag, sz, "RBinJavaCPTypeMethodHandle"); if (quick_check > 0) { return NULL; } @@ -5029,7 +5029,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *b if (obj) { obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; obj->tag = tag; obj->info.cp_method_handle.reference_kind = buffer[1]; obj->info.cp_method_handle.reference_index = R_BIN_JAVA_USHORT (buffer, 2); @@ -5037,7 +5037,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_methodhandle_cp_new(RBinJavaObj *bin, ut8 *b return obj; } -R_API ut64 r_bin_java_methodhandle_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_methodhandle_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; size += 1; // obj->info.cp_method_handle.reference_index = R_BIN_JAVA_USHORT (buffer, 2); @@ -5045,17 +5045,17 @@ R_API ut64 r_bin_java_methodhandle_cp_calc_size(RBinJavaCPTypeObj *obj) { return size; } -R_API RBinJavaCPTypeObj *r_bin_java_invokedynamic_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_invokedynamic_cp_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz) { ut8 tag = buffer[0]; RBinJavaCPTypeObj *obj; - int quick_check = r_bin_java_quick_check (R_BIN_JAVA_CP_INVOKEDYNAMIC, tag, sz, "RBinJavaCPTypeMethodHandle"); + int quick_check = rz_bin_java_quick_check (R_BIN_JAVA_CP_INVOKEDYNAMIC, tag, sz, "RBinJavaCPTypeMethodHandle"); if (quick_check > 0) { return NULL; } if ((obj = R_NEW0 (RBinJavaCPTypeObj))) { obj->metas = R_NEW0 (RBinJavaMetaInfo); obj->metas->type_info = (void *) &R_BIN_JAVA_CP_METAS[tag]; - obj->name = r_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; + obj->name = rz_str_dup (NULL, (const char *) R_BIN_JAVA_CP_METAS[tag].name);; obj->tag = tag; obj->info.cp_invoke_dynamic.bootstrap_method_attr_index = R_BIN_JAVA_USHORT (buffer, 1); obj->info.cp_invoke_dynamic.name_and_type_index = R_BIN_JAVA_USHORT (buffer, 3); @@ -5063,7 +5063,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_invokedynamic_cp_new(RBinJavaObj *bin, ut8 * return obj; } -R_API int r_bin_java_check_reset_cp_obj(RBinJavaCPTypeObj *cp_obj, ut8 tag) { +RZ_API int rz_bin_java_check_reset_cp_obj(RBinJavaCPTypeObj *cp_obj, ut8 tag) { bool res = false; if (tag < R_BIN_JAVA_CP_METAS_SZ) { if (tag != cp_obj->tag) { @@ -5085,7 +5085,7 @@ R_API int r_bin_java_check_reset_cp_obj(RBinJavaCPTypeObj *cp_obj, ut8 tag) { return res; } -R_API ut8 *r_bin_java_cp_get_4bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { +RZ_API ut8 *rz_bin_java_cp_get_4bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { ut8 *buffer = malloc (5); if (!buffer) { return NULL; @@ -5105,7 +5105,7 @@ R_API ut8 *r_bin_java_cp_get_4bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const return buffer; } -R_API ut8 *r_bin_java_cp_get_8bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { +RZ_API ut8 *rz_bin_java_cp_get_8bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { ut8 *buffer = malloc (10); if (!buffer) { return NULL; @@ -5117,16 +5117,16 @@ R_API ut8 *r_bin_java_cp_get_8bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const return NULL; } buffer[0] = tag; - val = r_bin_java_raw_to_long (buf, 0); + val = rz_bin_java_raw_to_long (buf, 0); memcpy (buffer + 1, (const char *) &val, 8); *out_sz = 9; return buffer; } -R_API ut8 *r_bin_java_cp_append_classref_and_name(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len) { +RZ_API ut8 *rz_bin_java_cp_append_classref_and_name(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len) { ut16 use_name_idx = bin->cp_idx + 1; ut8 *bytes = NULL, *name_bytes = NULL; - name_bytes = r_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, out_sz, (const ut8 *) classname, classname_len); + name_bytes = rz_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, out_sz, (const ut8 *) classname, classname_len); if (*out_sz > 0 && name_bytes) { ut8 *idx_addr = (ut8 *) &use_name_idx; bytes = malloc (*out_sz + 3); @@ -5140,28 +5140,28 @@ R_API ut8 *r_bin_java_cp_append_classref_and_name(RBinJavaObj *bin, ut32 *out_sz return bytes; } -R_API ut8 *r_bin_java_cp_get_fref_bytes(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { +RZ_API ut8 *rz_bin_java_cp_get_fref_bytes(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { ut8 *bytes = NULL, *fnt_bytes = NULL; RBinJavaCPTypeObj *ref_cp_obj = NULL; ut16 fnt_idx = 0, cref_idx = 0; ut32 fnt_len = 0; - ut16 ref_cp_obj_idx = r_bin_java_find_cp_class_ref_from_name_idx (bin, cn_idx); + ut16 ref_cp_obj_idx = rz_bin_java_find_cp_class_ref_from_name_idx (bin, cn_idx); if (!ref_cp_obj_idx) { return NULL; } - ref_cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, ref_cp_obj_idx); + ref_cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, ref_cp_obj_idx); if (ref_cp_obj) { cref_idx = ref_cp_obj->idx; } - ref_cp_obj = r_bin_java_find_cp_name_and_type_info (bin, fn_idx, ft_idx); + ref_cp_obj = rz_bin_java_find_cp_name_and_type_info (bin, fn_idx, ft_idx); if (ref_cp_obj) { fnt_idx = ref_cp_obj->idx; } else { - fnt_bytes = r_bin_java_cp_get_name_type (bin, &fnt_len, fn_idx, ft_idx); + fnt_bytes = rz_bin_java_cp_get_name_type (bin, &fnt_len, fn_idx, ft_idx); fnt_idx = bin->cp_idx + 1; } if (cref_idx && fnt_idx) { - bytes = r_bin_java_cp_get_fm_ref (bin, out_sz, tag, cref_idx, fnt_idx); + bytes = rz_bin_java_cp_get_fm_ref (bin, out_sz, tag, cref_idx, fnt_idx); if (fnt_bytes) { ut8 *tbuf = malloc (fnt_len + *out_sz); if (!tbuf) { @@ -5182,21 +5182,21 @@ R_API ut8 *r_bin_java_cp_get_fref_bytes(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, return bytes; } -R_API ut8 *r_bin_java_cp_get_classref(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len, const ut16 name_idx) { +RZ_API ut8 *rz_bin_java_cp_get_classref(RBinJavaObj *bin, ut32 *out_sz, const char *classname, const ut32 classname_len, const ut16 name_idx) { ut16 use_name_idx = -1; ut8 *bytes = NULL; if (name_idx == (ut16) - 1 && classname && *classname && classname_len > 0) { // find class_name_idx by class name - RList *results = r_bin_java_find_cp_const_by_val_utf8 (bin, (const ut8 *) classname, classname_len); - if (r_list_length (results) == 1) { - use_name_idx = (ut16) * ((ut32 *) r_list_get_n (results, 0)); + RzList *results = rz_bin_java_find_cp_const_by_val_utf8 (bin, (const ut8 *) classname, classname_len); + if (rz_list_length (results) == 1) { + use_name_idx = (ut16) * ((ut32 *) rz_list_get_n (results, 0)); } - r_list_free (results); + rz_list_free (results); } else if (name_idx != (ut16) - 1 && name_idx != 0) { use_name_idx = name_idx; } if (use_name_idx == (ut16) - 1 && classname && *classname && classname_len > 0) { - bytes = r_bin_java_cp_append_classref_and_name (bin, out_sz, classname, classname_len); + bytes = rz_bin_java_cp_append_classref_and_name (bin, out_sz, classname, classname_len); } else if (use_name_idx != (ut16) - 1) { ut8 *idx_addr = (ut8 *) &use_name_idx; bytes = malloc (3); @@ -5211,11 +5211,11 @@ R_API ut8 *r_bin_java_cp_get_classref(RBinJavaObj *bin, ut32 *out_sz, const char return bytes; } -R_API ut8 *r_bin_java_cp_get_fm_ref(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 class_idx, ut16 name_and_type_idx) { - return r_bin_java_cp_get_2_ut16 (bin, out_sz, tag, class_idx, name_and_type_idx); +RZ_API ut8 *rz_bin_java_cp_get_fm_ref(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 class_idx, ut16 name_and_type_idx) { + return rz_bin_java_cp_get_2_ut16 (bin, out_sz, tag, class_idx, name_and_type_idx); } -R_API ut8 *r_bin_java_cp_get_2_ut16(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 ut16_one, ut16 ut16_two) { +RZ_API ut8 *rz_bin_java_cp_get_2_ut16(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 ut16_one, ut16 ut16_two) { ut8 *bytes = malloc (7); if (!bytes) { return NULL; @@ -5234,11 +5234,11 @@ R_API ut8 *r_bin_java_cp_get_2_ut16(RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut1 return bytes; } -R_API ut8 *r_bin_java_cp_get_name_type(RBinJavaObj *bin, ut32 *out_sz, ut16 name_idx, ut16 type_idx) { - return r_bin_java_cp_get_2_ut16 (bin, out_sz, R_BIN_JAVA_CP_NAMEANDTYPE, name_idx, type_idx); +RZ_API ut8 *rz_bin_java_cp_get_name_type(RBinJavaObj *bin, ut32 *out_sz, ut16 name_idx, ut16 type_idx) { + return rz_bin_java_cp_get_2_ut16 (bin, out_sz, R_BIN_JAVA_CP_NAMEANDTYPE, name_idx, type_idx); } -R_API ut8 *r_bin_java_cp_get_utf8(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { +RZ_API ut8 *rz_bin_java_cp_get_utf8(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { ut8 *buffer = NULL; ut16 sz = 0; ut16 t = (ut16) len; @@ -5260,7 +5260,7 @@ R_API ut8 *r_bin_java_cp_get_utf8(ut8 tag, ut32 *out_sz, const ut8 *buf, const u return buffer; } -R_API ut64 r_bin_java_invokedynamic_cp_calc_size(RBinJavaCPTypeObj *obj) { +RZ_API ut64 rz_bin_java_invokedynamic_cp_calc_size(RBinJavaCPTypeObj *obj) { ut64 size = 0; size += 1; // obj->info.cp_invoke_dynamic.bootstrap_method_attr_index = R_BIN_JAVA_USHORT (buffer, 1); @@ -5271,7 +5271,7 @@ R_API ut64 r_bin_java_invokedynamic_cp_calc_size(RBinJavaCPTypeObj *obj) { } // End new Constant Pool types // Start free Constant Pool types -R_API void r_bin_java_default_free(void /* RBinJavaCPTypeObj*/ *o) { +RZ_API void rz_bin_java_default_free(void /* RBinJavaCPTypeObj*/ *o) { RBinJavaCPTypeObj *obj = o; if (obj) { free (obj->metas); @@ -5281,7 +5281,7 @@ R_API void r_bin_java_default_free(void /* RBinJavaCPTypeObj*/ *o) { } } -R_API void r_bin_java_utf8_info_free(void /* RBinJavaCPTypeObj*/ *o) { +RZ_API void rz_bin_java_utf8_info_free(void /* RBinJavaCPTypeObj*/ *o) { RBinJavaCPTypeObj *obj = o; if (obj) { free (obj->name); @@ -5291,12 +5291,12 @@ R_API void r_bin_java_utf8_info_free(void /* RBinJavaCPTypeObj*/ *o) { } } // Deallocs for type objects -R_API void r_bin_java_obj_free(void /*RBinJavaCPTypeObj*/ *o) { +RZ_API void rz_bin_java_obj_free(void /*RBinJavaCPTypeObj*/ *o) { RBinJavaCPTypeObj *obj = o; ((RBinJavaCPTypeMetas *) obj->metas->type_info)->allocs->delete_obj (obj); } -R_API void r_bin_java_print_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_attr_summary(RBinJavaAttrInfo *attr) { if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *.\n"); return; @@ -5304,7 +5304,7 @@ R_API void r_bin_java_print_attr_summary(RBinJavaAttrInfo *attr) { ((RBinJavaAttrMetas *) attr->metas->type_info)->allocs->print_summary (attr); } -R_API void r_bin_java_print_source_debug_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_source_debug_attr_summary(RBinJavaAttrInfo *attr) { ut32 i = 0; if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaSourceDebugExtensionAttr *.\n"); @@ -5321,7 +5321,7 @@ R_API void r_bin_java_print_source_debug_attr_summary(RBinJavaAttrInfo *attr) { Eprintf ("\n Source Debug Extension End\n"); } -R_API void r_bin_java_print_unknown_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_unknown_attr_summary(RBinJavaAttrInfo *attr) { if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *Unknown.\n"); return; @@ -5332,7 +5332,7 @@ R_API void r_bin_java_print_unknown_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Attribute Length: %d\n", attr->length); } -R_API void r_bin_java_print_code_exceptions_attr_summary(RBinJavaExceptionEntry *exc_entry) { +RZ_API void rz_bin_java_print_code_exceptions_attr_summary(RBinJavaExceptionEntry *exc_entry) { if (exc_entry == NULL) { eprintf ("Attempting to print an invalid RBinJavaExceptionEntry *.\n"); return; @@ -5345,8 +5345,8 @@ R_API void r_bin_java_print_code_exceptions_attr_summary(RBinJavaExceptionEntry Eprintf (" handler_pc: 0x%04x\n", exc_entry->handler_pc); } // End free Constant Pool types -R_API void r_bin_java_print_code_attr_summary(RBinJavaAttrInfo *attr) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API void rz_bin_java_print_code_attr_summary(RBinJavaAttrInfo *attr) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaExceptionEntry *exc_entry = NULL; RBinJavaAttrInfo *_attr = NULL; if (!attr) { @@ -5365,22 +5365,22 @@ R_API void r_bin_java_print_code_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Exception Table Length: %d\n", attr->info.code_attr.exception_table_length); if (attr->info.code_attr.exception_table) { // Delete the attr entries - r_list_foreach_safe (attr->info.code_attr.exception_table, iter, iter_tmp, exc_entry) { - r_bin_java_print_code_exceptions_attr_summary (exc_entry); + rz_list_foreach_safe (attr->info.code_attr.exception_table, iter, iter_tmp, exc_entry) { + rz_bin_java_print_code_exceptions_attr_summary (exc_entry); } } Eprintf (" Implicit Method Stack Frame:\n"); - r_bin_java_print_stack_map_frame_summary (attr->info.code_attr.implicit_frame); + rz_bin_java_print_stack_map_frame_summary (attr->info.code_attr.implicit_frame); Eprintf ("Code Attribute Attributes Information:\n"); if (attr->info.code_attr.attributes && attr->info.code_attr.attributes_count > 0) { Eprintf (" Code Attribute Attributes Count: %d\n", attr->info.code_attr.attributes_count); - r_list_foreach_safe (attr->info.code_attr.attributes, iter, iter_tmp, _attr) { - r_bin_java_print_attr_summary (_attr); + rz_list_foreach_safe (attr->info.code_attr.attributes, iter, iter_tmp, _attr) { + rz_bin_java_print_attr_summary (_attr); } } } -R_API void r_bin_java_print_constant_value_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_constant_value_attr_summary(RBinJavaAttrInfo *attr) { if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *ConstantValue.\n"); return; @@ -5392,7 +5392,7 @@ R_API void r_bin_java_print_constant_value_attr_summary(RBinJavaAttrInfo *attr) Eprintf (" ConstantValue Index: %d\n", attr->info.constant_value_attr.constantvalue_idx); } -R_API void r_bin_java_print_deprecated_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_deprecated_attr_summary(RBinJavaAttrInfo *attr) { if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *Deperecated.\n"); return; @@ -5403,7 +5403,7 @@ R_API void r_bin_java_print_deprecated_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Attribute Length: %d\n", attr->length); } -R_API void r_bin_java_print_enclosing_methods_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_enclosing_methods_attr_summary(RBinJavaAttrInfo *attr) { if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *Deperecated.\n"); return; @@ -5418,7 +5418,7 @@ R_API void r_bin_java_print_enclosing_methods_attr_summary(RBinJavaAttrInfo *att Eprintf (" Method Name and Desc : %s %s\n", attr->info.enclosing_method_attr.method_name, attr->info.enclosing_method_attr.method_descriptor); } -R_API void r_bin_java_print_exceptions_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_exceptions_attr_summary(RBinJavaAttrInfo *attr) { ut32 i = 0; if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *Exceptions.\n"); @@ -5433,7 +5433,7 @@ R_API void r_bin_java_print_exceptions_attr_summary(RBinJavaAttrInfo *attr) { } } -R_API void r_bin_java_print_classes_attr_summary(RBinJavaClassesAttribute *icattr) { +RZ_API void rz_bin_java_print_classes_attr_summary(RBinJavaClassesAttribute *icattr) { if (!icattr) { eprintf ("Attempting to print an invalid RBinJavaClassesAttribute* (InnerClasses element).\n"); return; @@ -5444,16 +5444,16 @@ R_API void r_bin_java_print_classes_attr_summary(RBinJavaClassesAttribute *icatt eprintf (" Inner Classes Class Attribute Class inner_class_access_flags: 0x%02x %s\n", icattr->inner_class_access_flags, icattr->flags_str); eprintf (" Inner Classes Class Attribute Class outer_class_info_idx: %d\n", icattr->outer_class_info_idx); eprintf (" Inner Classes Class Field Information:\n"); - r_bin_java_print_field_summary (icattr->clint_field); + rz_bin_java_print_field_summary (icattr->clint_field); eprintf (" Inner Classes Class Field Information:\n"); - r_bin_java_print_field_summary (icattr->clint_field); + rz_bin_java_print_field_summary (icattr->clint_field); eprintf (" Inner Classes Class Attr Info Information:\n"); - r_bin_java_print_attr_summary (icattr->clint_attr); + rz_bin_java_print_attr_summary (icattr->clint_attr); } -R_API void r_bin_java_print_inner_classes_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_inner_classes_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaClassesAttribute *icattr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *InnerClasses.\n"); return; @@ -5462,12 +5462,12 @@ R_API void r_bin_java_print_inner_classes_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); Eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); Eprintf (" Attribute Length: %d\n", attr->length); - r_list_foreach_safe (attr->info.inner_classes_attr.classes, iter, iter_tmp, icattr) { - r_bin_java_print_classes_attr_summary (icattr); + rz_list_foreach_safe (attr->info.inner_classes_attr.classes, iter, iter_tmp, icattr) { + rz_bin_java_print_classes_attr_summary (icattr); } } -R_API void r_bin_java_print_line_number_attr_summary(RBinJavaLineNumberAttribute *lnattr) { +RZ_API void rz_bin_java_print_line_number_attr_summary(RBinJavaLineNumberAttribute *lnattr) { if (!lnattr) { eprintf ("Attempting to print an invalid RBinJavaLineNumberAttribute *.\n"); return; @@ -5477,9 +5477,9 @@ R_API void r_bin_java_print_line_number_attr_summary(RBinJavaLineNumberAttribute Eprintf (" Line Number Attribute LineNumber: %d\n", lnattr->line_number); } -R_API void r_bin_java_print_line_number_table_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_line_number_table_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaLineNumberAttribute *lnattr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *LineNumberTable.\n"); return; @@ -5488,12 +5488,12 @@ R_API void r_bin_java_print_line_number_table_attr_summary(RBinJavaAttrInfo *att Eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); Eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); Eprintf (" Attribute Length: %d\n", attr->length); - r_list_foreach_safe (attr->info.line_number_table_attr.line_number_table, iter, iter_tmp, lnattr) { - r_bin_java_print_line_number_attr_summary (lnattr); + rz_list_foreach_safe (attr->info.line_number_table_attr.line_number_table, iter, iter_tmp, lnattr) { + rz_bin_java_print_line_number_attr_summary (lnattr); } } -R_API void r_bin_java_print_local_variable_attr_summary(RBinJavaLocalVariableAttribute *lvattr) { +RZ_API void rz_bin_java_print_local_variable_attr_summary(RBinJavaLocalVariableAttribute *lvattr) { if (!lvattr) { eprintf ("Attempting to print an invalid RBinJavaLocalVariableAttribute *.\n"); return; @@ -5508,9 +5508,9 @@ R_API void r_bin_java_print_local_variable_attr_summary(RBinJavaLocalVariableAtt Eprintf (" Local Variable Attribute index: %d\n", lvattr->index); } -R_API void r_bin_java_print_local_variable_table_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_local_variable_table_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaLocalVariableAttribute *lvattr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *LocalVariableTable.\n"); return; @@ -5519,12 +5519,12 @@ R_API void r_bin_java_print_local_variable_table_attr_summary(RBinJavaAttrInfo * Eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); Eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); Eprintf (" Attribute Length: %d\n", attr->length); - r_list_foreach_safe (attr->info.local_variable_table_attr.local_variable_table, iter, iter_tmp, lvattr) { - r_bin_java_print_local_variable_attr_summary (lvattr); + rz_list_foreach_safe (attr->info.local_variable_table_attr.local_variable_table, iter, iter_tmp, lvattr) { + rz_bin_java_print_local_variable_attr_summary (lvattr); } } -R_API void r_bin_java_print_local_variable_type_attr_summary(RBinJavaLocalVariableTypeAttribute *lvattr) { +RZ_API void rz_bin_java_print_local_variable_type_attr_summary(RBinJavaLocalVariableTypeAttribute *lvattr) { if (!lvattr) { eprintf ("Attempting to print an invalid RBinJavaLocalVariableTypeAttribute *.\n"); return; @@ -5539,9 +5539,9 @@ R_API void r_bin_java_print_local_variable_type_attr_summary(RBinJavaLocalVariab eprintf (" Local Variable Type Attribute index: %d\n", lvattr->index); } -R_API void r_bin_java_print_local_variable_type_table_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_local_variable_type_table_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaLocalVariableTypeAttribute *lvtattr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *LocalVariableTable.\n"); return; @@ -5550,12 +5550,12 @@ R_API void r_bin_java_print_local_variable_type_table_attr_summary(RBinJavaAttrI eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); eprintf (" Attribute Length: %d\n", attr->length); - r_list_foreach_safe (attr->info.local_variable_type_table_attr.local_variable_table, iter, iter_tmp, lvtattr) { - r_bin_java_print_local_variable_type_attr_summary (lvtattr); + rz_list_foreach_safe (attr->info.local_variable_type_table_attr.local_variable_table, iter, iter_tmp, lvtattr) { + rz_bin_java_print_local_variable_type_attr_summary (lvtattr); } } -R_API void r_bin_java_print_signature_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_signature_attr_summary(RBinJavaAttrInfo *attr) { if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *SignatureAttr.\n"); return; @@ -5568,7 +5568,7 @@ R_API void r_bin_java_print_signature_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Signature string: %s\n", attr->info.signature_attr.signature); } -R_API void r_bin_java_print_source_code_file_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_source_code_file_attr_summary(RBinJavaAttrInfo *attr) { if (!attr) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *SourceFile.\n"); return; @@ -5580,7 +5580,7 @@ R_API void r_bin_java_print_source_code_file_attr_summary(RBinJavaAttrInfo *attr Eprintf (" Source File Index: %d\n", attr->info.source_file_attr.sourcefile_idx); } -R_API void r_bin_java_print_synthetic_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_synthetic_attr_summary(RBinJavaAttrInfo *attr) { if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaAttrInfo *Synthetic.\n"); return; @@ -5592,9 +5592,9 @@ R_API void r_bin_java_print_synthetic_attr_summary(RBinJavaAttrInfo *attr) { Eprintf (" Attribute Index: %d\n", attr->info.source_file_attr.sourcefile_idx); } -R_API void r_bin_java_print_stack_map_table_attr_summary(RBinJavaAttrInfo *attr) { - RListIter *iter, *iter_tmp; - RList *ptrList; +RZ_API void rz_bin_java_print_stack_map_table_attr_summary(RBinJavaAttrInfo *attr) { + RzListIter *iter, *iter_tmp; + RzList *ptrList; RBinJavaStackMapFrame *frame; if (attr == NULL) { eprintf ("Attempting to print an invalid RBinJavaStackMapTableAttr* .\n"); @@ -5609,15 +5609,15 @@ R_API void r_bin_java_print_stack_map_table_attr_summary(RBinJavaAttrInfo *attr) Eprintf (" StackMapTable Frames:\n"); ptrList = attr->info.stack_map_table_attr.stack_map_frame_entries; if (ptrList) { - r_list_foreach_safe (ptrList, iter, iter_tmp, frame) { - r_bin_java_print_stack_map_frame_summary (frame); + rz_list_foreach_safe (ptrList, iter, iter_tmp, frame) { + rz_bin_java_print_stack_map_frame_summary (frame); } } } -R_API void r_bin_java_print_stack_map_frame_summary(RBinJavaStackMapFrame *obj) { - RListIter *iter, *iter_tmp; - RList *ptrList; +RZ_API void rz_bin_java_print_stack_map_frame_summary(RBinJavaStackMapFrame *obj) { + RzListIter *iter, *iter_tmp; + RzList *ptrList; RBinJavaVerificationObj *ver_obj; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaStackMapFrame* .\n"); @@ -5630,17 +5630,17 @@ R_API void r_bin_java_print_stack_map_frame_summary(RBinJavaStackMapFrame *obj) Eprintf (" Stack Items Count = 0x%04x\n", obj->number_of_stack_items); Eprintf (" Local Variables:\n"); ptrList = obj->local_items; - r_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { - r_bin_java_print_verification_info_summary (ver_obj); + rz_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { + rz_bin_java_print_verification_info_summary (ver_obj); } Eprintf (" Stack Items:\n"); ptrList = obj->stack_items; - r_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { - r_bin_java_print_verification_info_summary (ver_obj); + rz_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { + rz_bin_java_print_verification_info_summary (ver_obj); } } -R_API void r_bin_java_print_verification_info_summary(RBinJavaVerificationObj *obj) { +RZ_API void rz_bin_java_print_verification_info_summary(RBinJavaVerificationObj *obj) { ut8 tag_value = R_BIN_JAVA_STACKMAP_UNKNOWN; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaVerificationObj* .\n"); @@ -5660,15 +5660,15 @@ R_API void r_bin_java_print_verification_info_summary(RBinJavaVerificationObj *o } } -R_API void r_bin_java_print_field_summary(RBinJavaField *field) { +RZ_API void rz_bin_java_print_field_summary(RBinJavaField *field) { RBinJavaAttrInfo *attr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (field) { if (field->type == R_BIN_JAVA_FIELD_TYPE_METHOD) { - r_bin_java_print_method_summary (field); + rz_bin_java_print_method_summary (field); } else { #if 0 - r_bin_java_print_interface_summary (field); + rz_bin_java_print_interface_summary (field); return; } * / #endif @@ -5679,8 +5679,8 @@ R_API void r_bin_java_print_field_summary(RBinJavaField *field) { Eprintf (" Access Flags: 0x%02x (%s)\n", field->flags, field->flags_str); Eprintf (" Field Attributes Count: %d\n", field->attr_count); Eprintf (" Field Attributes:\n"); - r_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { - r_bin_java_print_attr_summary (attr); + rz_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { + rz_bin_java_print_attr_summary (attr); } } } else { @@ -5688,9 +5688,9 @@ R_API void r_bin_java_print_field_summary(RBinJavaField *field) { } } -R_API void r_bin_java_print_method_summary(RBinJavaField *field) { +RZ_API void rz_bin_java_print_method_summary(RBinJavaField *field) { RBinJavaAttrInfo *attr; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (field == NULL) { eprintf ("Attempting to print an invalid RBinJavaField* Method.\n"); return; @@ -5702,15 +5702,15 @@ R_API void r_bin_java_print_method_summary(RBinJavaField *field) { Eprintf (" Access Flags: 0x%02x (%s)\n", field->flags, field->flags_str); Eprintf (" Method Attributes Count: %d\n", field->attr_count); Eprintf (" Method Attributes:\n"); - r_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { - r_bin_java_print_attr_summary (attr); + rz_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { + rz_bin_java_print_attr_summary (attr); } } /* - R_API void r_bin_java_print_interface_summary(ut16 idx) {//RBinJavaField *field) { + RZ_API void rz_bin_java_print_interface_summary(ut16 idx) {//RBinJavaField *field) { RBinJavaAttrInfo *attr; RBinJavaCPTypeObj *class_info; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; if (field == NULL) { eprintf ("Attempting to print an invalid RBinJavaField* Interface.\n"); return; @@ -5722,12 +5722,12 @@ R_API void r_bin_java_print_method_summary(RBinJavaField *field) { eprintf (" Descriptor Index: %d (%s)\n", field->descriptor_idx, field->descriptor); eprintf (" Interface Attributes Count: %d\n", field->attr_count); eprintf (" Interface Attributes:\n"); - r_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { - r_bin_java_print_attr_summary(attr); + rz_list_foreach_safe (field->attributes, iter, iter_tmp, attr) { + rz_bin_java_print_attr_summary(attr); } } */ -R_API void r_bin_java_print_interfacemethodref_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_interfacemethodref_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* InterfaceMethodRef.\n"); return; @@ -5738,7 +5738,7 @@ R_API void r_bin_java_print_interfacemethodref_cp_summary(RBinJavaCPTypeObj *obj eprintf (" Name and type Index = %d\n", obj->info.cp_interface.name_and_type_idx); } -R_API char *r_bin_java_print_interfacemethodref_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_interfacemethodref_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5761,7 +5761,7 @@ R_API char *r_bin_java_print_interfacemethodref_cp_stringify(RBinJavaCPTypeObj * return value; } -R_API void r_bin_java_print_methodhandle_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_methodhandle_cp_summary(RBinJavaCPTypeObj *obj) { ut8 ref_kind; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* RBinJavaCPTypeMethodHandle.\n"); @@ -5774,7 +5774,7 @@ R_API void r_bin_java_print_methodhandle_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" Reference Index = %d\n", obj->info.cp_method_handle.reference_index); } -R_API char *r_bin_java_print_methodhandle_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_methodhandle_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); ut8 ref_kind = obj->info.cp_method_handle.reference_kind; @@ -5798,7 +5798,7 @@ R_API char *r_bin_java_print_methodhandle_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_methodtype_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_methodtype_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* RBinJavaCPTypeMethodType.\n"); return; @@ -5808,7 +5808,7 @@ R_API void r_bin_java_print_methodtype_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" Descriptor Index = 0x%02x\n", obj->info.cp_method_type.descriptor_index); } -R_API char *r_bin_java_print_methodtype_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_methodtype_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5831,7 +5831,7 @@ R_API char *r_bin_java_print_methodtype_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_invokedynamic_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_invokedynamic_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* RBinJavaCPTypeInvokeDynamic.\n"); return; @@ -5842,7 +5842,7 @@ R_API void r_bin_java_print_invokedynamic_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" Bootstrap Name and Type Index = (0x%02x)\n", obj->info.cp_invoke_dynamic.name_and_type_index); } -R_API char *r_bin_java_print_invokedynamic_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_invokedynamic_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5867,7 +5867,7 @@ R_API char *r_bin_java_print_invokedynamic_cp_stringify(RBinJavaCPTypeObj *obj) return value; } -R_API void r_bin_java_print_methodref_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_methodref_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* MethodRef.\n"); return; @@ -5878,7 +5878,7 @@ R_API void r_bin_java_print_methodref_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" Name and type Index = %d\n", obj->info.cp_method.name_and_type_idx); } -R_API char *r_bin_java_print_methodref_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_methodref_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5903,7 +5903,7 @@ R_API char *r_bin_java_print_methodref_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_fieldref_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_fieldref_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* FieldRef.\n"); return; @@ -5914,7 +5914,7 @@ R_API void r_bin_java_print_fieldref_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" Name and type Index = %d\n", obj->info.cp_field.name_and_type_idx); } -R_API char *r_bin_java_print_fieldref_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_fieldref_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5939,7 +5939,7 @@ R_API char *r_bin_java_print_fieldref_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_classref_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_classref_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* ClassRef.\n"); return; @@ -5949,7 +5949,7 @@ R_API void r_bin_java_print_classref_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" Name Index = %d\n", obj->info.cp_class.name_idx); } -R_API char *r_bin_java_print_classref_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_classref_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -5972,7 +5972,7 @@ R_API char *r_bin_java_print_classref_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_string_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_string_cp_summary(RBinJavaCPTypeObj *obj) { if (!obj) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* String.\n"); return; @@ -5982,7 +5982,7 @@ R_API void r_bin_java_print_string_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" String Index = %d\n", obj->info.cp_string.string_idx); } -R_API char *r_bin_java_print_string_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_string_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6006,7 +6006,7 @@ R_API char *r_bin_java_print_string_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_integer_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_integer_cp_summary(RBinJavaCPTypeObj *obj) { ut8 *b = NULL; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Integer.\n"); @@ -6019,7 +6019,7 @@ R_API void r_bin_java_print_integer_cp_summary(RBinJavaCPTypeObj *obj) { eprintf (" integer = %d\n", R_BIN_JAVA_UINT (obj->info.cp_integer.bytes.raw, 0)); } -R_API char *r_bin_java_print_integer_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_integer_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6042,7 +6042,7 @@ R_API char *r_bin_java_print_integer_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_float_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_float_cp_summary(RBinJavaCPTypeObj *obj) { ut8 *b = NULL; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Double.\n"); @@ -6055,7 +6055,7 @@ R_API void r_bin_java_print_float_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" Float = %f\n", R_BIN_JAVA_FLOAT (obj->info.cp_float.bytes.raw, 0)); } -R_API char *r_bin_java_print_float_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_float_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6078,7 +6078,7 @@ R_API char *r_bin_java_print_float_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_long_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_long_cp_summary(RBinJavaCPTypeObj *obj) { ut8 *b = NULL; if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Long.\n"); @@ -6089,10 +6089,10 @@ R_API void r_bin_java_print_long_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" Offset: 0x%08"PFMT64x "", obj->file_offset); Eprintf (" High-Bytes = %02x %02x %02x %02x\n", b[0], b[1], b[2], b[3]); Eprintf (" Low-Bytes = %02x %02x %02x %02x\n", b[4], b[5], b[6], b[7]); - Eprintf (" Long = %08"PFMT64x "\n", r_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); + Eprintf (" Long = %08"PFMT64x "\n", rz_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); } -R_API char *r_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6101,7 +6101,7 @@ R_API char *r_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj *obj) { obj->metas->ord, obj->file_offset, ((RBinJavaCPTypeMetas *) obj->metas->type_info)->name, - r_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); + rz_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); if (consumed >= size - 1) { free (value); size += size >> 1; @@ -6112,14 +6112,14 @@ R_API char *r_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj *obj) { obj->metas->ord, obj->file_offset, ((RBinJavaCPTypeMetas *) obj->metas->type_info)->name, - r_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); + rz_bin_java_raw_to_long (obj->info.cp_long.bytes.raw, 0)); } } } return value; } -R_API void r_bin_java_print_double_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_double_cp_summary(RBinJavaCPTypeObj *obj) { ut8 *b = NULL; if (!obj) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Double.\n"); @@ -6130,10 +6130,10 @@ R_API void r_bin_java_print_double_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" Offset: 0x%08"PFMT64x "", obj->file_offset); Eprintf (" High-Bytes = %02x %02x %02x %02x\n", b[0], b[1], b[2], b[3]); Eprintf (" Low-Bytes = %02x %02x %02x %02x\n", b[4], b[5], b[6], b[7]); - Eprintf (" Double = %f\n", r_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); + Eprintf (" Double = %f\n", rz_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); } -R_API char *r_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6142,7 +6142,7 @@ R_API char *r_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj *obj) { obj->metas->ord, obj->file_offset, ((RBinJavaCPTypeMetas *) obj->metas->type_info)->name, - r_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); + rz_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); if (consumed >= size - 1) { free (value); size += size >> 1; @@ -6153,14 +6153,14 @@ R_API char *r_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj *obj) { obj->metas->ord, obj->file_offset, ((RBinJavaCPTypeMetas *) obj->metas->type_info)->name, - r_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); + rz_bin_java_raw_to_double (obj->info.cp_double.bytes.raw, 0)); } } } return value; } -R_API void r_bin_java_print_name_and_type_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_name_and_type_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Name_And_Type.\n"); return; @@ -6171,7 +6171,7 @@ R_API void r_bin_java_print_name_and_type_cp_summary(RBinJavaCPTypeObj *obj) { Eprintf (" descriptor_idx = (%d)\n", obj->info.cp_name_and_type.descriptor_idx); } -R_API char *r_bin_java_print_name_and_type_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_name_and_type_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6196,7 +6196,7 @@ R_API char *r_bin_java_print_name_and_type_cp_stringify(RBinJavaCPTypeObj *obj) return value; } -R_API void r_bin_java_print_utf8_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_utf8_cp_summary(RBinJavaCPTypeObj *obj) { if (obj == NULL) { eprintf ("Attempting to print an invalid RBinJavaCPTypeObj* Utf8.\n"); return; @@ -6209,9 +6209,9 @@ R_API void r_bin_java_print_utf8_cp_summary(RBinJavaCPTypeObj *obj) { free (str); } -R_API char *r_bin_java_print_utf8_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_utf8_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; - char *utf8_str = r_hex_bin2strdup (obj->info.cp_utf8.bytes, obj->info.cp_utf8.length); + char *utf8_str = rz_hex_bin2strdup (obj->info.cp_utf8.bytes, obj->info.cp_utf8.length); char *value = malloc (size + strlen (utf8_str)); if (value) { memset (value, 0, size); @@ -6236,11 +6236,11 @@ R_API char *r_bin_java_print_utf8_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_null_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_null_cp_summary(RBinJavaCPTypeObj *obj) { eprintf ("Unknown ConstantPool Type Tag: 0x%04x .\n", obj->tag); } -R_API char *r_bin_java_print_null_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_null_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255, consumed = 0; char *value = malloc (size); if (value) { @@ -6262,11 +6262,11 @@ R_API char *r_bin_java_print_null_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API void r_bin_java_print_unknown_cp_summary(RBinJavaCPTypeObj *obj) { +RZ_API void rz_bin_java_print_unknown_cp_summary(RBinJavaCPTypeObj *obj) { eprintf ("NULL ConstantPool Type.\n"); } -R_API char *r_bin_java_print_unknown_cp_stringify(RBinJavaCPTypeObj *obj) { +RZ_API char *rz_bin_java_print_unknown_cp_stringify(RBinJavaCPTypeObj *obj) { ut32 size = 255; char *value = malloc (size); if (value) { @@ -6277,7 +6277,7 @@ R_API char *r_bin_java_print_unknown_cp_stringify(RBinJavaCPTypeObj *obj) { return value; } -R_API RBinJavaElementValuePair *r_bin_java_element_pair_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaElementValuePair *rz_bin_java_element_pair_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { if (!buffer || sz < 4) { return NULL; } @@ -6289,7 +6289,7 @@ R_API RBinJavaElementValuePair *r_bin_java_element_pair_new(ut8 *buffer, ut64 sz evp->element_name_idx = R_BIN_JAVA_USHORT (buffer, 0); ut64 offset = 2; evp->file_offset = buf_offset; - evp->name = r_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, evp->element_name_idx); + evp->name = rz_bin_java_get_utf8_from_bin_cp_list (R_BIN_JAVA_GLOBAL_BIN, evp->element_name_idx); if (!evp->name) { // TODO: eprintf unable to find the name for the given index eprintf ("ElementValue Name is invalid.\n"); @@ -6299,7 +6299,7 @@ R_API RBinJavaElementValuePair *r_bin_java_element_pair_new(ut8 *buffer, ut64 sz free (evp); return NULL; } - evp->value = r_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); + evp->value = rz_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); offset += evp->value->size; if (offset >= sz) { free (evp->value); @@ -6310,7 +6310,7 @@ R_API RBinJavaElementValuePair *r_bin_java_element_pair_new(ut8 *buffer, ut64 sz return evp; } -R_API void r_bin_java_print_element_pair_summary(RBinJavaElementValuePair *evp) { +RZ_API void rz_bin_java_print_element_pair_summary(RBinJavaElementValuePair *evp) { if (!evp) { eprintf ("Attempting to print an invalid RBinJavaElementValuePair *pair.\n"); return; @@ -6320,13 +6320,13 @@ R_API void r_bin_java_print_element_pair_summary(RBinJavaElementValuePair *evp) Eprintf (" EV Pair Element Name index: 0x%02x\n", evp->element_name_idx); Eprintf (" EV Pair Element Name: %s\n", evp->name); Eprintf (" EV Pair Element Value:\n"); - r_bin_java_print_element_value_summary (evp->value); + rz_bin_java_print_element_value_summary (evp->value); } -R_API void r_bin_java_print_element_value_summary(RBinJavaElementValue *element_value) { +RZ_API void rz_bin_java_print_element_value_summary(RBinJavaElementValue *element_value) { RBinJavaCPTypeObj *obj; RBinJavaElementValue *ev_element = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; char *name; if (!element_value) { eprintf ("Attempting to print an invalid RBinJavaElementValuePair *pair.\n"); @@ -6378,13 +6378,13 @@ R_API void r_bin_java_print_element_value_summary(RBinJavaElementValue *element_ case R_BIN_JAVA_EV_TAG_ARRAY: eprintf (" EV Value Array Value Number of Values: 0x%04x\n", element_value->value.array_value.num_values); eprintf (" EV Value Array Values\n"); - r_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { - r_bin_java_print_element_value_summary (ev_element); + rz_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { + rz_bin_java_print_element_value_summary (ev_element); } break; case R_BIN_JAVA_EV_TAG_ANNOTATION: eprintf (" EV Annotation Information:\n"); - r_bin_java_print_annotation_summary (&element_value->value.annotation_value); + rz_bin_java_print_annotation_summary (&element_value->value.annotation_value); break; default: // eprintf unable to handle tag @@ -6392,19 +6392,19 @@ R_API void r_bin_java_print_element_value_summary(RBinJavaElementValue *element_ } } -R_API void r_bin_java_element_pair_free(void /*RBinJavaElementValuePair*/ *e) { +RZ_API void rz_bin_java_element_pair_free(void /*RBinJavaElementValuePair*/ *e) { RBinJavaElementValuePair *evp = e; if (evp) { free (evp->name); - r_bin_java_element_value_free (evp->value); + rz_bin_java_element_value_free (evp->value); free (evp); } evp = NULL; } -R_API void r_bin_java_element_value_free(void /*RBinJavaElementValue*/ *e) { +RZ_API void rz_bin_java_element_value_free(void /*RBinJavaElementValue*/ *e) { RBinJavaElementValue *element_value = e; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaCPTypeObj *obj = NULL; RBinJavaElementValue *ev_element = NULL; if (element_value) { @@ -6451,20 +6451,20 @@ R_API void r_bin_java_element_value_free(void /*RBinJavaElementValue*/ *e) { break; case R_BIN_JAVA_EV_TAG_ARRAY: // Delete the Element Value array List - r_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { + rz_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { if (ev_element) { - r_bin_java_element_value_free (ev_element); + rz_bin_java_element_value_free (ev_element); } else { // TODO eprintf evps value was NULL } - // r_list_delete (element_value->value.array_value.values, iter); + // rz_list_delete (element_value->value.array_value.values, iter); ev_element = NULL; } - r_list_free (element_value->value.array_value.values); + rz_list_free (element_value->value.array_value.values); break; case R_BIN_JAVA_EV_TAG_ANNOTATION: // Delete the Annotations List - r_list_free (element_value->value.annotation_value.element_value_pairs); + rz_list_free (element_value->value.annotation_value.element_value_pairs); break; default: // eprintf unable to free the tag @@ -6474,30 +6474,30 @@ R_API void r_bin_java_element_value_free(void /*RBinJavaElementValue*/ *e) { } } -R_API ut64 r_bin_java_annotation_default_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_annotation_default_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; if (attr) { - // attr = r_bin_java_default_attr_new (buffer, sz, buf_offset); + // attr = rz_bin_java_default_attr_new (buffer, sz, buf_offset); size += 6; - // attr->info.annotation_default_attr.default_value = r_bin_java_element_value_new (buffer+offset, sz-offset, buf_offset+offset); - size += r_bin_java_element_value_calc_size (attr->info.annotation_default_attr.default_value); + // attr->info.annotation_default_attr.default_value = rz_bin_java_element_value_new (buffer+offset, sz-offset, buf_offset+offset); + size += rz_bin_java_element_value_calc_size (attr->info.annotation_default_attr.default_value); } return size; } -R_API RBinJavaAttrInfo *r_bin_java_annotation_default_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_annotation_default_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 0; RBinJavaAttrInfo *attr = NULL; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr && sz >= offset) { attr->type = R_BIN_JAVA_ATTR_TYPE_ANNOTATION_DEFAULT_ATTR; - attr->info.annotation_default_attr.default_value = r_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); + attr->info.annotation_default_attr.default_value = rz_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); if (attr->info.annotation_default_attr.default_value) { offset += attr->info.annotation_default_attr.default_value->size; } } - r_bin_java_print_annotation_default_attr_summary (attr); + rz_bin_java_print_annotation_default_attr_summary (attr); return attr; } @@ -6510,10 +6510,10 @@ static void delete_obj(RBinJavaCPTypeObj *obj) { } } -R_API void r_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; RBinJavaElementValue *ev_element = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; if (!attr || attr->type != R_BIN_JAVA_ATTR_TYPE_ANNOTATION_DEFAULT_ATTR) { return; } @@ -6544,16 +6544,16 @@ R_API void r_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *a) break; case R_BIN_JAVA_EV_TAG_ARRAY: // Delete the Element Value array List - r_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { - r_bin_java_element_value_free (ev_element); - // r_list_delete (element_value->value.array_value.values, iter); + rz_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { + rz_bin_java_element_value_free (ev_element); + // rz_list_delete (element_value->value.array_value.values, iter); ev_element = NULL; } - r_list_free (element_value->value.array_value.values); + rz_list_free (element_value->value.array_value.values); break; case R_BIN_JAVA_EV_TAG_ANNOTATION: // Delete the Annotations List - r_list_free (element_value->value.annotation_value.element_value_pairs); + rz_list_free (element_value->value.annotation_value.element_value_pairs); break; default: // eprintf unable to free the tag @@ -6566,7 +6566,7 @@ R_API void r_bin_java_annotation_default_attr_free(void /*RBinJavaAttrInfo*/ *a) } } -R_API RBinJavaAnnotation *r_bin_java_annotation_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAnnotation *rz_bin_java_annotation_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaAnnotation *annotation = NULL; RBinJavaElementValuePair *evps = NULL; @@ -6581,25 +6581,25 @@ R_API RBinJavaAnnotation *r_bin_java_annotation_new(ut8 *buffer, ut64 sz, ut64 b // (ut16) read and set annotation_value.num_element_value_pairs; annotation->num_element_value_pairs = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - annotation->element_value_pairs = r_list_newf (r_bin_java_element_pair_free); + annotation->element_value_pairs = rz_list_newf (rz_bin_java_element_pair_free); // read annotation_value.num_element_value_pairs, and append to annotation_value.element_value_pairs for (i = 0; i < annotation->num_element_value_pairs; i++) { if (offset > sz) { break; } - evps = r_bin_java_element_pair_new (buffer + offset, sz - offset, buf_offset + offset); + evps = rz_bin_java_element_pair_new (buffer + offset, sz - offset, buf_offset + offset); if (evps) { offset += evps->size; - r_list_append (annotation->element_value_pairs, (void *) evps); + rz_list_append (annotation->element_value_pairs, (void *) evps); } } annotation->size = offset; return annotation; } -R_API ut64 r_bin_java_annotation_calc_size(RBinJavaAnnotation *annotation) { +RZ_API ut64 rz_bin_java_annotation_calc_size(RBinJavaAnnotation *annotation) { ut64 sz = 0; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; RBinJavaElementValuePair *evps = NULL; if (!annotation) { // TODO eprintf allocation fail @@ -6609,24 +6609,24 @@ R_API ut64 r_bin_java_annotation_calc_size(RBinJavaAnnotation *annotation) { sz += 2; // annotation->num_element_value_pairs = R_BIN_JAVA_USHORT (buffer, offset); sz += 2; - r_list_foreach_safe (annotation->element_value_pairs, iter, iter_tmp, evps) { + rz_list_foreach_safe (annotation->element_value_pairs, iter, iter_tmp, evps) { if (evps) { - sz += r_bin_java_element_pair_calc_size (evps); + sz += rz_bin_java_element_pair_calc_size (evps); } } return sz; } -R_API void r_bin_java_annotation_free(void /*RBinJavaAnnotation*/ *a) { +RZ_API void rz_bin_java_annotation_free(void /*RBinJavaAnnotation*/ *a) { RBinJavaAnnotation *annotation = a; if (annotation) { - r_list_free (annotation->element_value_pairs); + rz_list_free (annotation->element_value_pairs); free (annotation); } } -R_API void r_bin_java_print_annotation_summary(RBinJavaAnnotation *annotation) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API void rz_bin_java_print_annotation_summary(RBinJavaAnnotation *annotation) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaElementValuePair *evp = NULL; if (!annotation) { // TODO eprintf invalid annotation @@ -6636,28 +6636,28 @@ R_API void r_bin_java_print_annotation_summary(RBinJavaAnnotation *annotation) { Eprintf (" Annotation Number of EV Pairs: 0x%04x\n", annotation->num_element_value_pairs); Eprintf (" Annotation EV Pair Values:\n"); if (annotation->element_value_pairs) { - r_list_foreach_safe (annotation->element_value_pairs, iter, iter_tmp, evp) { - r_bin_java_print_element_pair_summary (evp); + rz_list_foreach_safe (annotation->element_value_pairs, iter, iter_tmp, evp) { + rz_bin_java_print_element_pair_summary (evp); } } } -R_API ut64 r_bin_java_element_pair_calc_size(RBinJavaElementValuePair *evp) { +RZ_API ut64 rz_bin_java_element_pair_calc_size(RBinJavaElementValuePair *evp) { ut64 sz = 0; if (evp == NULL) { return sz; } - // evp->element_name_idx = r_bin_java_read_short(bin, bin->b->cur); + // evp->element_name_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; - // evp->value = r_bin_java_element_value_new (bin, offset+2); + // evp->value = rz_bin_java_element_value_new (bin, offset+2); if (evp->value) { - sz += r_bin_java_element_value_calc_size (evp->value); + sz += rz_bin_java_element_value_calc_size (evp->value); } return sz; } -R_API ut64 r_bin_java_element_value_calc_size(RBinJavaElementValue *element_value) { - RListIter *iter, *iter_tmp; +RZ_API ut64 rz_bin_java_element_value_calc_size(RBinJavaElementValue *element_value) { + RzListIter *iter, *iter_tmp; RBinJavaElementValue *ev_element; RBinJavaElementValuePair *evps; ut64 sz = 0; @@ -6678,44 +6678,44 @@ R_API ut64 r_bin_java_element_value_calc_size(RBinJavaElementValue *element_valu case R_BIN_JAVA_EV_TAG_STRING: // look up value in bin->cp_list // (ut16) read and set const_value.const_value_idx - // element_value->value.const_value.const_value_idx = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.const_value.const_value_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; break; case R_BIN_JAVA_EV_TAG_ENUM: // (ut16) read and set enum_const_value.type_name_idx - // element_value->value.enum_const_value.type_name_idx = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.enum_const_value.type_name_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; // (ut16) read and set enum_const_value.const_name_idx - // element_value->value.enum_const_value.const_name_idx = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.enum_const_value.const_name_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; break; case R_BIN_JAVA_EV_TAG_CLASS: // (ut16) read and set class_value.class_info_idx - // element_value->value.class_value.class_info_idx = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.class_value.class_info_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; break; case R_BIN_JAVA_EV_TAG_ARRAY: // (ut16) read and set array_value.num_values - // element_value->value.array_value.num_values = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.array_value.num_values = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; - r_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { + rz_list_foreach_safe (element_value->value.array_value.values, iter, iter_tmp, ev_element) { if (ev_element) { - sz += r_bin_java_element_value_calc_size (ev_element); + sz += rz_bin_java_element_value_calc_size (ev_element); } } break; case R_BIN_JAVA_EV_TAG_ANNOTATION: // annotation new is not used here. // (ut16) read and set annotation_value.type_idx; - // element_value->value.annotation_value.type_idx = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.annotation_value.type_idx = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; // (ut16) read and set annotation_value.num_element_value_pairs; - // element_value->value.annotation_value.num_element_value_pairs = r_bin_java_read_short(bin, bin->b->cur); + // element_value->value.annotation_value.num_element_value_pairs = rz_bin_java_read_short(bin, bin->b->cur); sz += 2; - element_value->value.annotation_value.element_value_pairs = r_list_newf (r_bin_java_element_pair_free); - r_list_foreach_safe (element_value->value.annotation_value.element_value_pairs, iter, iter_tmp, evps) { + element_value->value.annotation_value.element_value_pairs = rz_list_newf (rz_bin_java_element_pair_free); + rz_list_foreach_safe (element_value->value.annotation_value.element_value_pairs, iter, iter_tmp, evps) { if (evps) { - sz += r_bin_java_element_pair_calc_size (evps); + sz += rz_bin_java_element_pair_calc_size (evps); } } break; @@ -6726,7 +6726,7 @@ R_API ut64 r_bin_java_element_value_calc_size(RBinJavaElementValue *element_valu return sz; } -R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaElementValue *rz_bin_java_element_value_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; ut64 offset = 0; RBinJavaElementValue *element_value = R_NEW0 (RBinJavaElementValue); @@ -6743,7 +6743,7 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u element_value->tag = buffer[offset]; element_value->size += 1; offset += 1; - element_value->metas->type_info = (void *) r_bin_java_get_ev_meta_from_tag (element_value->tag); + element_value->metas->type_info = (void *) rz_bin_java_get_ev_meta_from_tag (element_value->tag); switch (element_value->tag) { case R_BIN_JAVA_EV_TAG_BYTE: case R_BIN_JAVA_EV_TAG_CHAR: @@ -6759,7 +6759,7 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u element_value->value.const_value.const_value_idx = R_BIN_JAVA_USHORT (buffer, offset); element_value->size += 2; // look-up, deep copy, and set const_value.const_value_cp_obj - element_value->value.const_value.const_value_cp_obj = r_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.const_value.const_value_idx); + element_value->value.const_value.const_value_cp_obj = rz_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.const_value.const_value_idx); break; case R_BIN_JAVA_EV_TAG_ENUM: // (ut16) read and set enum_const_value.type_name_idx @@ -6772,9 +6772,9 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u offset += 2; // look up type_name_index in bin->cp_list // look-up, deep copy, and set enum_const_value.const_name_cp_obj - element_value->value.enum_const_value.const_name_cp_obj = r_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.enum_const_value.const_name_idx); + element_value->value.enum_const_value.const_name_cp_obj = rz_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.enum_const_value.const_name_idx); // look-up, deep copy, and set enum_const_value.type_name_cp_obj - element_value->value.enum_const_value.type_name_cp_obj = r_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.enum_const_value.type_name_idx); + element_value->value.enum_const_value.type_name_cp_obj = rz_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.enum_const_value.type_name_idx); break; case R_BIN_JAVA_EV_TAG_CLASS: // (ut16) read and set class_value.class_info_idx @@ -6783,24 +6783,24 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u offset += 2; // look up type_name_index in bin->cp_list // look-up, deep copy, and set class_value.class_info_cp_obj - element_value->value.class_value.class_info_cp_obj = r_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.class_value.class_info_idx); + element_value->value.class_value.class_info_cp_obj = rz_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, element_value->value.class_value.class_info_idx); break; case R_BIN_JAVA_EV_TAG_ARRAY: // (ut16) read and set array_value.num_values element_value->value.array_value.num_values = R_BIN_JAVA_USHORT (buffer, offset); element_value->size += 2; offset += 2; - element_value->value.array_value.values = r_list_new (); + element_value->value.array_value.values = rz_list_new (); for (i = 0; i < element_value->value.array_value.num_values; i++) { if (offset >= sz) { break; } - RBinJavaElementValue *ev_element = r_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); + RBinJavaElementValue *ev_element = rz_bin_java_element_value_new (buffer + offset, sz - offset, buf_offset + offset); if (ev_element) { element_value->size += ev_element->size; offset += ev_element->size; // read array_value.num_values, and append to array_value.values - r_list_append (element_value->value.array_value.values, (void *) ev_element); + rz_list_append (element_value->value.array_value.values, (void *) ev_element); } } break; @@ -6816,13 +6816,13 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u element_value->size += 2; offset += 2; } - element_value->value.annotation_value.element_value_pairs = r_list_newf (r_bin_java_element_pair_free); + element_value->value.annotation_value.element_value_pairs = rz_list_newf (rz_bin_java_element_pair_free); // read annotation_value.num_element_value_pairs, and append to annotation_value.element_value_pairs for (i = 0; i < element_value->value.annotation_value.num_element_value_pairs; i++) { if (offset > sz) { break; } - evps = r_bin_java_element_pair_new (buffer + offset, sz - offset, buf_offset + offset); + evps = rz_bin_java_element_pair_new (buffer + offset, sz - offset, buf_offset + offset); if (evps) { element_value->size += evps->size; offset += evps->size; @@ -6830,7 +6830,7 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u if (evps == NULL) { // TODO: eprintf error when reading element pair } - r_list_append (element_value->value.annotation_value.element_value_pairs, (void *) evps); + rz_list_append (element_value->value.annotation_value.element_value_pairs, (void *) evps); } break; default: @@ -6840,7 +6840,7 @@ R_API RBinJavaElementValue *r_bin_java_element_value_new(ut8 *buffer, ut64 sz, u return element_value; } -R_API void r_bin_java_bootstrap_method_argument_free(void /*RBinJavaBootStrapArgument*/ *b) { +RZ_API void rz_bin_java_bootstrap_method_argument_free(void /*RBinJavaBootStrapArgument*/ *b) { RBinJavaBootStrapArgument *bsm_arg = b; if (bsm_arg) { RBinJavaCPTypeMetas *tm = (RBinJavaCPTypeMetas*)bsm_arg->argument_info_cp_obj; @@ -6854,7 +6854,7 @@ R_API void r_bin_java_bootstrap_method_argument_free(void /*RBinJavaBootStrapArg } } -R_API void r_bin_java_print_bootstrap_method_argument_summary(RBinJavaBootStrapArgument *bsm_arg) { +RZ_API void rz_bin_java_print_bootstrap_method_argument_summary(RBinJavaBootStrapArgument *bsm_arg) { if (!bsm_arg) { eprintf ("Attempting to print an invalid RBinJavaBootStrapArgument *.\n"); return; @@ -6870,9 +6870,9 @@ R_API void r_bin_java_print_bootstrap_method_argument_summary(RBinJavaBootStrapA } } -R_API void r_bin_java_print_bootstrap_method_summary(RBinJavaBootStrapMethod *bsm) { +RZ_API void rz_bin_java_print_bootstrap_method_summary(RBinJavaBootStrapMethod *bsm) { RBinJavaBootStrapArgument *bsm_arg = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; if (!bsm) { eprintf ("Attempting to print an invalid RBinJavaBootStrapArgument *.\n"); return; @@ -6882,9 +6882,9 @@ R_API void r_bin_java_print_bootstrap_method_summary(RBinJavaBootStrapMethod *bs eprintf (" Method Reference Index = (0x%02x)\n", bsm->bootstrap_method_ref); eprintf (" Number of Method Arguments = (0x%02x)\n", bsm->num_bootstrap_arguments); if (bsm->bootstrap_arguments) { - r_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, bsm_arg) { + rz_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, bsm_arg) { if (bsm_arg) { - r_bin_java_print_bootstrap_method_argument_summary (bsm_arg); + rz_bin_java_print_bootstrap_method_argument_summary (bsm_arg); } } } else { @@ -6892,7 +6892,7 @@ R_API void r_bin_java_print_bootstrap_method_summary(RBinJavaBootStrapMethod *bs } } -R_API RBinJavaBootStrapArgument *r_bin_java_bootstrap_method_argument_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaBootStrapArgument *rz_bin_java_bootstrap_method_argument_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { ut64 offset = 0; RBinJavaBootStrapArgument *bsm_arg = (RBinJavaBootStrapArgument *) malloc (sizeof (RBinJavaBootStrapArgument)); if (!bsm_arg) { @@ -6903,31 +6903,31 @@ R_API RBinJavaBootStrapArgument *r_bin_java_bootstrap_method_argument_new(ut8 *b bsm_arg->file_offset = buf_offset; bsm_arg->argument_info_idx = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - bsm_arg->argument_info_cp_obj = r_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, bsm_arg->argument_info_idx); + bsm_arg->argument_info_cp_obj = rz_bin_java_clone_cp_idx (R_BIN_JAVA_GLOBAL_BIN, bsm_arg->argument_info_idx); bsm_arg->size = offset; return bsm_arg; } -R_API void r_bin_java_bootstrap_method_free(void /*/RBinJavaBootStrapMethod*/ *b) { +RZ_API void rz_bin_java_bootstrap_method_free(void /*/RBinJavaBootStrapMethod*/ *b) { RBinJavaBootStrapMethod *bsm = b; - RListIter *iter, *iter_tmp; + RzListIter *iter, *iter_tmp; RBinJavaBootStrapArgument *obj = NULL; if (bsm) { if (bsm->bootstrap_arguments) { - r_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, obj) { + rz_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, obj) { if (obj) { - r_bin_java_bootstrap_method_argument_free (obj); + rz_bin_java_bootstrap_method_argument_free (obj); } - // r_list_delete (bsm->bootstrap_arguments, iter); + // rz_list_delete (bsm->bootstrap_arguments, iter); } - r_list_free (bsm->bootstrap_arguments); + rz_list_free (bsm->bootstrap_arguments); bsm->bootstrap_arguments = NULL; } free (bsm); } } -R_API RBinJavaBootStrapMethod *r_bin_java_bootstrap_method_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaBootStrapMethod *rz_bin_java_bootstrap_method_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaBootStrapArgument *bsm_arg = NULL; ut32 i = 0; ut64 offset = 0; @@ -6942,16 +6942,16 @@ R_API RBinJavaBootStrapMethod *r_bin_java_bootstrap_method_new(ut8 *buffer, ut64 offset += 2; bsm->num_bootstrap_arguments = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - bsm->bootstrap_arguments = r_list_new (); + bsm->bootstrap_arguments = rz_list_new (); for (i = 0; i < bsm->num_bootstrap_arguments; i++) { if (offset >= sz) { break; } - // bsm_arg = r_bin_java_bootstrap_method_argument_new (bin, bin->b->cur); - bsm_arg = r_bin_java_bootstrap_method_argument_new (buffer + offset, sz - offset, buf_offset + offset); + // bsm_arg = rz_bin_java_bootstrap_method_argument_new (bin, bin->b->cur); + bsm_arg = rz_bin_java_bootstrap_method_argument_new (buffer + offset, sz - offset, buf_offset + offset); if (bsm_arg) { offset += bsm_arg->size; - r_list_append (bsm->bootstrap_arguments, (void *) bsm_arg); + rz_list_append (bsm->bootstrap_arguments, (void *) bsm_arg); } else { // TODO eprintf Failed to read the %d boot strap method. } @@ -6960,8 +6960,8 @@ R_API RBinJavaBootStrapMethod *r_bin_java_bootstrap_method_new(ut8 *buffer, ut64 return bsm; } -R_API void r_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *attr) { - RListIter *iter, *iter_tmp; +RZ_API void rz_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *attr) { + RzListIter *iter, *iter_tmp; RBinJavaBootStrapMethod *obj = NULL; if (!attr || attr->type == R_BIN_JAVA_ATTR_TYPE_BOOTSTRAP_METHODS_ATTR) { eprintf ("Unable to print attribue summary for RBinJavaAttrInfo *RBinJavaBootstrapMethodsAttr"); @@ -6972,9 +6972,9 @@ R_API void r_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *att eprintf (" Length: 0x%08x", attr->length); eprintf (" Number of Method Arguments = (0x%02x)\n", attr->info.bootstrap_methods_attr.num_bootstrap_methods); if (attr->info.bootstrap_methods_attr.bootstrap_methods) { - r_list_foreach_safe (attr->info.bootstrap_methods_attr.bootstrap_methods, iter, iter_tmp, obj) { + rz_list_foreach_safe (attr->info.bootstrap_methods_attr.bootstrap_methods, iter, iter_tmp, obj) { if (obj) { - r_bin_java_print_bootstrap_method_summary (obj); + rz_bin_java_print_bootstrap_method_summary (obj); } } } else { @@ -6982,27 +6982,27 @@ R_API void r_bin_java_print_bootstrap_methods_attr_summary(RBinJavaAttrInfo *att } } -R_API void r_bin_java_bootstrap_methods_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_bootstrap_methods_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_BOOTSTRAP_METHODS_ATTR) { free (attr->name); free (attr->metas); - r_list_free (attr->info.bootstrap_methods_attr.bootstrap_methods); + rz_list_free (attr->info.bootstrap_methods_attr.bootstrap_methods); free (attr); } } -R_API ut64 r_bin_java_bootstrap_methods_attr_calc_size(RBinJavaAttrInfo *attr) { - RListIter *iter, *iter_tmp; +RZ_API ut64 rz_bin_java_bootstrap_methods_attr_calc_size(RBinJavaAttrInfo *attr) { + RzListIter *iter, *iter_tmp; RBinJavaBootStrapMethod *bsm = NULL; ut64 size = 0; if (attr) { size += 6; // attr->info.bootstrap_methods_attr.num_bootstrap_methods = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (attr->info.bootstrap_methods_attr.bootstrap_methods, iter, iter_tmp, bsm) { + rz_list_foreach_safe (attr->info.bootstrap_methods_attr.bootstrap_methods, iter, iter_tmp, bsm) { if (bsm) { - size += r_bin_java_bootstrap_method_calc_size (bsm); + size += rz_bin_java_bootstrap_method_calc_size (bsm); } else { // TODO eprintf Failed to read the %d boot strap method. } @@ -7011,7 +7011,7 @@ R_API ut64 r_bin_java_bootstrap_methods_attr_calc_size(RBinJavaAttrInfo *attr) { return size; } -R_API ut64 r_bin_java_bootstrap_arg_calc_size(RBinJavaBootStrapArgument *bsm_arg) { +RZ_API ut64 rz_bin_java_bootstrap_arg_calc_size(RBinJavaBootStrapArgument *bsm_arg) { ut64 size = 0; if (bsm_arg) { // bsm_arg->argument_info_idx = R_BIN_JAVA_USHORT (buffer, offset); @@ -7020,8 +7020,8 @@ R_API ut64 r_bin_java_bootstrap_arg_calc_size(RBinJavaBootStrapArgument *bsm_arg return size; } -R_API ut64 r_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm) { - RListIter *iter, *iter_tmp; +RZ_API ut64 rz_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm) { + RzListIter *iter, *iter_tmp; RBinJavaBootStrapArgument *bsm_arg = NULL; ut64 size = 0; if (bsm) { @@ -7030,9 +7030,9 @@ R_API ut64 r_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm) { size += 2; // bsm->num_bootstrap_arguments = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, bsm_arg) { + rz_list_foreach_safe (bsm->bootstrap_arguments, iter, iter_tmp, bsm_arg) { if (bsm_arg) { - size += r_bin_java_bootstrap_arg_calc_size (bsm_arg); + size += rz_bin_java_bootstrap_arg_calc_size (bsm_arg); } else { // TODO eprintf Failed to read the %d boot strap method. } @@ -7041,26 +7041,26 @@ R_API ut64 r_bin_java_bootstrap_method_calc_size(RBinJavaBootStrapMethod *bsm) { return size; } -R_API RBinJavaAttrInfo *r_bin_java_bootstrap_methods_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_bootstrap_methods_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaBootStrapMethod *bsm = NULL; ut64 offset = 0; - RBinJavaAttrInfo *attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + RBinJavaAttrInfo *attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_BOOTSTRAP_METHODS_ATTR; attr->info.bootstrap_methods_attr.num_bootstrap_methods = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.bootstrap_methods_attr.bootstrap_methods = r_list_newf (r_bin_java_bootstrap_method_free); + attr->info.bootstrap_methods_attr.bootstrap_methods = rz_list_newf (rz_bin_java_bootstrap_method_free); for (i = 0; i < attr->info.bootstrap_methods_attr.num_bootstrap_methods; i++) { - // bsm = r_bin_java_bootstrap_method_new (bin, bin->b->cur); + // bsm = rz_bin_java_bootstrap_method_new (bin, bin->b->cur); if (offset >= sz) { break; } - bsm = r_bin_java_bootstrap_method_new (buffer + offset, sz - offset, buf_offset + offset); + bsm = rz_bin_java_bootstrap_method_new (buffer + offset, sz - offset, buf_offset + offset); if (bsm) { offset += bsm->size; - r_list_append (attr->info.bootstrap_methods_attr.bootstrap_methods, (void *) bsm); + rz_list_append (attr->info.bootstrap_methods_attr.bootstrap_methods, (void *) bsm); } else { // TODO eprintf Failed to read the %d boot strap method. } @@ -7070,38 +7070,38 @@ R_API RBinJavaAttrInfo *r_bin_java_bootstrap_methods_attr_new(RBinJavaObj *bin, return attr; } -R_API void r_bin_java_print_annotation_default_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_annotation_default_attr_summary(RBinJavaAttrInfo *attr) { if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_ANNOTATION_DEFAULT_ATTR) { eprintf ("Annotation Default Attribute Information:\n"); eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); eprintf (" Attribute Length: %d\n", attr->length); - r_bin_java_print_element_value_summary ((attr->info.annotation_default_attr.default_value)); + rz_bin_java_print_element_value_summary ((attr->info.annotation_default_attr.default_value)); } else { // TODO: eprintf attr is invalid } } -R_API void r_bin_java_annotation_array_free(void /*RBinJavaAnnotationsArray*/ *a) { +RZ_API void rz_bin_java_annotation_array_free(void /*RBinJavaAnnotationsArray*/ *a) { RBinJavaAnnotationsArray *annotation_array = a; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaAnnotation *annotation; if (!annotation_array->annotations) { // TODO eprintf return; } - r_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { + rz_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { if (annotation) { - r_bin_java_annotation_free (annotation); + rz_bin_java_annotation_free (annotation); } - // r_list_delete (annotation_array->annotations, iter); + // rz_list_delete (annotation_array->annotations, iter); } - r_list_free (annotation_array->annotations); + rz_list_free (annotation_array->annotations); free (annotation_array); } -R_API void r_bin_java_print_annotation_array_summary(RBinJavaAnnotationsArray *annotation_array) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API void rz_bin_java_print_annotation_array_summary(RBinJavaAnnotationsArray *annotation_array) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaAnnotation *annotation; if (!annotation_array->annotations) { // TODO eprintf @@ -7109,12 +7109,12 @@ R_API void r_bin_java_print_annotation_array_summary(RBinJavaAnnotationsArray *a } eprintf (" Annotation Array Information:\n"); eprintf (" Number of Annotation Array Elements: %d\n", annotation_array->num_annotations); - r_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { - r_bin_java_print_annotation_summary (annotation); + rz_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { + rz_bin_java_print_annotation_summary (annotation); } } -R_API RBinJavaAnnotationsArray *r_bin_java_annotation_array_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAnnotationsArray *rz_bin_java_annotation_array_new(ut8 *buffer, ut64 sz, ut64 buf_offset) { RBinJavaAnnotation *annotation; RBinJavaAnnotationsArray *annotation_array; ut32 i; @@ -7126,40 +7126,40 @@ R_API RBinJavaAnnotationsArray *r_bin_java_annotation_array_new(ut8 *buffer, ut6 } annotation_array->num_annotations = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - annotation_array->annotations = r_list_new (); + annotation_array->annotations = rz_list_new (); for (i = 0; i < annotation_array->num_annotations; i++) { if (offset > sz) { break; } - annotation = r_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); + annotation = rz_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); if (annotation) { offset += annotation->size; - r_list_append (annotation_array->annotations, (void *) annotation); + rz_list_append (annotation_array->annotations, (void *) annotation); } } annotation_array->size = offset; return annotation_array; } -R_API RBinJavaAttrInfo *r_bin_java_rtv_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_rtv_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_ANNOTATION_ATTR; attr->info.annotation_array.num_annotations = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.annotation_array.annotations = r_list_newf (r_bin_java_annotation_free); + attr->info.annotation_array.annotations = rz_list_newf (rz_bin_java_annotation_free); for (i = 0; i < attr->info.annotation_array.num_annotations; i++) { if (offset >= sz) { break; } - RBinJavaAnnotation *annotation = r_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); + RBinJavaAnnotation *annotation = rz_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); if (annotation) { offset += annotation->size; - r_list_append (attr->info.annotation_array.annotations, (void *) annotation); + rz_list_append (attr->info.annotation_array.annotations, (void *) annotation); } } attr->size = offset; @@ -7167,9 +7167,9 @@ R_API RBinJavaAttrInfo *r_bin_java_rtv_annotations_attr_new(RBinJavaObj *bin, ut return attr; } -R_API ut64 r_bin_java_annotation_array_calc_size(RBinJavaAnnotationsArray *annotation_array) { +RZ_API ut64 rz_bin_java_annotation_array_calc_size(RBinJavaAnnotationsArray *annotation_array) { ut64 size = 0; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaAnnotation *annotation; if (!annotation_array->annotations) { // TODO eprintf @@ -7177,101 +7177,101 @@ R_API ut64 r_bin_java_annotation_array_calc_size(RBinJavaAnnotationsArray *annot } // annotation_array->num_annotations = R_BIN_JAVA_USHORT (buffer, offset); size += 2; - r_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { - size += r_bin_java_annotation_calc_size (annotation); + rz_list_foreach_safe (annotation_array->annotations, iter, iter_tmp, annotation) { + size += rz_bin_java_annotation_calc_size (annotation); } return size; } -R_API ut64 r_bin_java_rtv_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_rtv_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; if (!attr) { // TODO eprintf allocation fail return size; } - size += (6 + r_bin_java_annotation_array_calc_size (&(attr->info.annotation_array))); + size += (6 + rz_bin_java_annotation_array_calc_size (&(attr->info.annotation_array))); return size; } -R_API RBinJavaAttrInfo *r_bin_java_rti_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_rti_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_ANNOTATION_ATTR; attr->info.annotation_array.num_annotations = R_BIN_JAVA_USHORT (buffer, offset); offset += 2; - attr->info.annotation_array.annotations = r_list_newf (r_bin_java_annotation_free); + attr->info.annotation_array.annotations = rz_list_newf (rz_bin_java_annotation_free); for (i = 0; i < attr->info.rtv_annotations_attr.num_annotations; i++) { if (offset >= sz) { break; } - RBinJavaAnnotation *annotation = r_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); + RBinJavaAnnotation *annotation = rz_bin_java_annotation_new (buffer + offset, sz - offset, buf_offset + offset); if (annotation) { offset += annotation->size; } - r_list_append (attr->info.annotation_array.annotations, (void *) annotation); + rz_list_append (attr->info.annotation_array.annotations, (void *) annotation); } attr->size = offset; } return attr; } -R_API ut64 r_bin_java_rti_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_rti_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; if (!attr) { // TODO eprintf allocation fail return size; } - size += (6 + r_bin_java_annotation_array_calc_size (&(attr->info.annotation_array))); + size += (6 + rz_bin_java_annotation_array_calc_size (&(attr->info.annotation_array))); return size; } -R_API void r_bin_java_rtv_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_rtv_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_ANNOTATION_ATTR) { - r_list_free (attr->info.annotation_array.annotations); + rz_list_free (attr->info.annotation_array.annotations); free (attr->metas); free (attr->name); free (attr); } } -R_API void r_bin_java_rti_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_rti_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_ANNOTATION_ATTR) { - r_list_free (attr->info.annotation_array.annotations); + rz_list_free (attr->info.annotation_array.annotations); free (attr->metas); free (attr->name); free (attr); } } -R_API void r_bin_java_print_rtv_annotations_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_rtv_annotations_attr_summary(RBinJavaAttrInfo *attr) { if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_ANNOTATION_ATTR) { Eprintf ("Runtime Visible Annotations Attribute Information:\n"); Eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); Eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); Eprintf (" Attribute Length: %d\n", attr->length); - r_bin_java_print_annotation_array_summary (&attr->info.annotation_array); + rz_bin_java_print_annotation_array_summary (&attr->info.annotation_array); } } -R_API void r_bin_java_print_rti_annotations_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_rti_annotations_attr_summary(RBinJavaAttrInfo *attr) { if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_ANNOTATION_ATTR) { Eprintf ("Runtime Invisible Annotations Attribute Information:\n"); Eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); Eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); Eprintf (" Attribute Length: %d\n", attr->length); - r_bin_java_print_annotation_array_summary (&attr->info.annotation_array); + rz_bin_java_print_annotation_array_summary (&attr->info.annotation_array); } } -R_API ut64 r_bin_java_rtip_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_rtip_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaAnnotationsArray *annotation_array; if (!attr) { // TODO eprintf allocation fail @@ -7279,34 +7279,34 @@ R_API ut64 r_bin_java_rtip_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { } // attr->info.rtip_annotations_attr.num_parameters = buffer[offset]; size += (6 + 1); - r_list_foreach_safe (attr->info.rtip_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { + rz_list_foreach_safe (attr->info.rtip_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { if (annotation_array) { - size += r_bin_java_annotation_array_calc_size (annotation_array); + size += rz_bin_java_annotation_array_calc_size (annotation_array); } } return size; } -R_API RBinJavaAttrInfo *r_bin_java_rtip_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_rtip_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATION_ATTR; attr->info.rtip_annotations_attr.num_parameters = buffer[offset]; offset += 1; - attr->info.rtip_annotations_attr.parameter_annotations = r_list_newf (r_bin_java_annotation_array_free); + attr->info.rtip_annotations_attr.parameter_annotations = rz_list_newf (rz_bin_java_annotation_array_free); for (i = 0; i < attr->info.rtip_annotations_attr.num_parameters; i++) { if (offset >= sz) { break; } - RBinJavaAnnotationsArray *annotation_array = r_bin_java_annotation_array_new ( + RBinJavaAnnotationsArray *annotation_array = rz_bin_java_annotation_array_new ( buffer + offset, sz - offset, buf_offset + offset); if (annotation_array) { offset += annotation_array->size; - r_list_append (attr->info.rtip_annotations_attr.parameter_annotations, (void *) annotation_array); + rz_list_append (attr->info.rtip_annotations_attr.parameter_annotations, (void *) annotation_array); } } attr->size = offset; @@ -7314,56 +7314,56 @@ R_API RBinJavaAttrInfo *r_bin_java_rtip_annotations_attr_new(RBinJavaObj *bin, u return attr; } -R_API RBinJavaAttrInfo *r_bin_java_rtvp_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { +RZ_API RBinJavaAttrInfo *rz_bin_java_rtvp_annotations_attr_new(RBinJavaObj *bin, ut8 *buffer, ut64 sz, ut64 buf_offset) { ut32 i = 0; RBinJavaAttrInfo *attr = NULL; ut64 offset = 0; - attr = r_bin_java_default_attr_new (bin, buffer, sz, buf_offset); + attr = rz_bin_java_default_attr_new (bin, buffer, sz, buf_offset); offset += 6; RBinJavaAnnotationsArray *annotation_array; if (attr) { attr->type = R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_PARAMETER_ANNOTATION_ATTR; attr->info.rtvp_annotations_attr.num_parameters = buffer[offset]; offset += 1; - attr->info.rtvp_annotations_attr.parameter_annotations = r_list_newf (r_bin_java_annotation_array_free); + attr->info.rtvp_annotations_attr.parameter_annotations = rz_list_newf (rz_bin_java_annotation_array_free); for (i = 0; i < attr->info.rtvp_annotations_attr.num_parameters; i++) { if (offset > sz) { break; } - annotation_array = r_bin_java_annotation_array_new (buffer + offset, sz - offset, buf_offset + offset); + annotation_array = rz_bin_java_annotation_array_new (buffer + offset, sz - offset, buf_offset + offset); if (annotation_array) { offset += annotation_array->size; } - r_list_append (attr->info.rtvp_annotations_attr.parameter_annotations, (void *) annotation_array); + rz_list_append (attr->info.rtvp_annotations_attr.parameter_annotations, (void *) annotation_array); } attr->size = offset; } return attr; } -R_API ut64 r_bin_java_rtvp_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { +RZ_API ut64 rz_bin_java_rtvp_annotations_attr_calc_size(RBinJavaAttrInfo *attr) { ut64 size = 0; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaAnnotationsArray *annotation_array; if (!attr) { return size; } size += (6 + 1); - r_list_foreach_safe (attr->info.rtvp_annotations_attr.parameter_annotations, + rz_list_foreach_safe (attr->info.rtvp_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { if (annotation_array) { - size += r_bin_java_annotation_array_calc_size ( + size += rz_bin_java_annotation_array_calc_size ( annotation_array); } } return size; } -R_API void r_bin_java_rtvp_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_rtvp_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { if (attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_PARAMETER_ANNOTATION_ATTR) { - r_list_free (attr->info.rtvp_annotations_attr.parameter_annotations); + rz_list_free (attr->info.rtvp_annotations_attr.parameter_annotations); } free (attr->name); free (attr->metas); @@ -7371,51 +7371,51 @@ R_API void r_bin_java_rtvp_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { } } -R_API void r_bin_java_rtip_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { +RZ_API void rz_bin_java_rtip_annotations_attr_free(void /*RBinJavaAttrInfo*/ *a) { RBinJavaAttrInfo *attr = a; if (attr) { // && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATION_ATTR) { - r_list_free (attr->info.rtip_annotations_attr.parameter_annotations); + rz_list_free (attr->info.rtip_annotations_attr.parameter_annotations); free (attr->metas); free (attr->name); free (attr); } } -R_API void r_bin_java_print_rtvp_annotations_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_rtvp_annotations_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaAnnotationsArray *annotation_array = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_VISIBLE_PARAMETER_ANNOTATION_ATTR) { eprintf ("Runtime Visible Parameter Annotations Attribute Information:\n"); eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); eprintf (" Attribute Length: %d\n", attr->length); eprintf (" Number of Runtime Invisible Parameters: %d\n", attr->info.rtvp_annotations_attr.num_parameters); - r_list_foreach_safe (attr->info.rtvp_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { - r_bin_java_print_annotation_array_summary (annotation_array); + rz_list_foreach_safe (attr->info.rtvp_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { + rz_bin_java_print_annotation_array_summary (annotation_array); } } } -R_API void r_bin_java_print_rtip_annotations_attr_summary(RBinJavaAttrInfo *attr) { +RZ_API void rz_bin_java_print_rtip_annotations_attr_summary(RBinJavaAttrInfo *attr) { RBinJavaAnnotationsArray *annotation_array = NULL; - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; if (attr && attr->type == R_BIN_JAVA_ATTR_TYPE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATION_ATTR) { eprintf ("Runtime Invisible Parameter Annotations Attribute Information:\n"); eprintf (" Attribute Offset: 0x%08"PFMT64x "\n", attr->file_offset); eprintf (" Attribute Name Index: %d (%s)\n", attr->name_idx, attr->name); eprintf (" Attribute Length: %d\n", attr->length); eprintf (" Number of Runtime Invisible Parameters: %d\n", attr->info.rtip_annotations_attr.num_parameters); - r_list_foreach_safe (attr->info.rtip_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { - r_bin_java_print_annotation_array_summary (annotation_array); + rz_list_foreach_safe (attr->info.rtip_annotations_attr.parameter_annotations, iter, iter_tmp, annotation_array) { + rz_bin_java_print_annotation_array_summary (annotation_array); } } } -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_name_and_type_info(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx) { - RListIter *iter, *iter_tmp; +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_name_and_type_info(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx) { + RzListIter *iter, *iter_tmp; RBinJavaCPTypeObj *res = NULL, *obj = NULL; IFDBG eprintf("Looking for name_idx: %d and descriptor_idx: %d\n", name_idx, descriptor_idx); - r_list_foreach_safe (bin->cp_list, iter, iter_tmp, obj) { + rz_list_foreach_safe (bin->cp_list, iter, iter_tmp, obj) { if (obj && obj->tag == R_BIN_JAVA_CP_NAMEANDTYPE) { IFDBG eprintf("RBinJavaCPTypeNameAndType has name_idx: %d and descriptor_idx: %d\n", obj->info.cp_name_and_type.name_idx, obj->info.cp_name_and_type.descriptor_idx); @@ -7429,14 +7429,14 @@ R_API RBinJavaCPTypeObj *r_bin_java_find_cp_name_and_type_info(RBinJavaObj *bin, return res; } -R_API char *r_bin_java_resolve_cp_idx_type(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API char *rz_bin_java_resolve_cp_idx_type(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaCPTypeObj *item = NULL; char *str = NULL; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { - // r_bin_java_new_bin(BIN_OBJ); + // rz_bin_java_new_bin(BIN_OBJ); return NULL; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { str = strdup (((RBinJavaCPTypeMetas *) item->metas->type_info)->name); } else { @@ -7445,18 +7445,18 @@ R_API char *r_bin_java_resolve_cp_idx_type(RBinJavaObj *BIN_OBJ, int idx) { return str; } -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_ref_info_from_name_and_type(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx) { - RBinJavaCPTypeObj *obj = r_bin_java_find_cp_name_and_type_info (bin, name_idx, descriptor_idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_ref_info_from_name_and_type(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx) { + RBinJavaCPTypeObj *obj = rz_bin_java_find_cp_name_and_type_info (bin, name_idx, descriptor_idx); if (obj) { - return r_bin_java_find_cp_ref_info (bin, obj->metas->ord); + return rz_bin_java_find_cp_ref_info (bin, obj->metas->ord); } return NULL; } -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_ref_info(RBinJavaObj *bin, ut16 name_and_type_idx) { - RListIter *iter, *iter_tmp; +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_ref_info(RBinJavaObj *bin, ut16 name_and_type_idx) { + RzListIter *iter, *iter_tmp; RBinJavaCPTypeObj *res = NULL, *obj = NULL; - r_list_foreach_safe (bin->cp_list, iter, iter_tmp, obj) { + rz_list_foreach_safe (bin->cp_list, iter, iter_tmp, obj) { if (obj->tag == R_BIN_JAVA_CP_FIELDREF && obj->info.cp_field.name_and_type_idx == name_and_type_idx) { res = obj; @@ -7470,7 +7470,7 @@ R_API RBinJavaCPTypeObj *r_bin_java_find_cp_ref_info(RBinJavaObj *bin, ut16 name return res; } -R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_type) { +RZ_API char *rz_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_type) { // TODO XXX FIXME add a size parameter to the str when it is passed in RBinJavaCPTypeObj *item = NULL, *item2 = NULL; char *class_str = NULL, @@ -7481,10 +7481,10 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ *cp_name = NULL, *str = NULL; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { - // r_bin_java_new_bin(BIN_OBJ); + // rz_bin_java_new_bin(BIN_OBJ); return NULL; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { cp_name = ((RBinJavaCPTypeMetas *) item->metas->type_info)->name; IFDBG eprintf("java_resolve Resolved: (%d) %s\n", idx, cp_name); @@ -7496,21 +7496,21 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ return str; } if (strcmp (cp_name, "Class") == 0) { - item2 = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); - // str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); - class_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + item2 = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + // str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); + class_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); if (!desc_str) { desc_str = empty; } - str = r_str_newf ("%s%s%s", name_str, + str = rz_str_newf ("%s%s%s", name_str, space_bn_name_type ? " " : "", desc_str); if (class_str != empty) { free (class_str); @@ -7527,19 +7527,19 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ /* * The MethodRef, FieldRef, and InterfaceMethodRef structures */ - class_str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); + class_str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } - str = r_str_newf ("%s/%s%s%s", class_str, name_str, + str = rz_str_newf ("%s/%s%s%s", class_str, name_str, space_bn_name_type ? " " : "", desc_str); if (class_str != empty) { free (class_str); @@ -7551,13 +7551,13 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ free (desc_str); } } else if (!strcmp (cp_name, "String")) { - string_str = r_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); + string_str = rz_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); str = NULL; IFDBG eprintf("java_resolve String got: (%d) %s\n", item->info.cp_string.string_idx, string_str); if (!string_str) { string_str = empty; } - str = r_str_newf ("\"%s\"", string_str); + str = rz_str_newf ("\"%s\"", string_str); IFDBG eprintf("java_resolve String return: %s\n", str); if (string_str != empty) { free (string_str); @@ -7572,23 +7572,23 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ } free (tmp_str); } else if (!strcmp (cp_name, "Long")) { - str = r_str_newf ("0x%"PFMT64x, r_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0)); + str = rz_str_newf ("0x%"PFMT64x, rz_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0)); } else if (!strcmp (cp_name, "Double")) { - str = r_str_newf ("%f", r_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0)); + str = rz_str_newf ("%f", rz_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0)); } else if (!strcmp (cp_name, "Integer")) { - str = r_str_newf ("0x%08x", R_BIN_JAVA_UINT (item->info.cp_integer.bytes.raw, 0)); + str = rz_str_newf ("0x%08x", R_BIN_JAVA_UINT (item->info.cp_integer.bytes.raw, 0)); } else if (!strcmp (cp_name, "Float")) { - str = r_str_newf ("%f", R_BIN_JAVA_FLOAT (item->info.cp_float.bytes.raw, 0)); + str = rz_str_newf ("%f", R_BIN_JAVA_FLOAT (item->info.cp_float.bytes.raw, 0)); } else if (!strcmp (cp_name, "NameAndType")) { - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } - str = r_str_newf ("%s%s%s", name_str, space_bn_name_type ? " " : "", desc_str); + str = rz_str_newf ("%s%s%s", name_str, space_bn_name_type ? " " : "", desc_str); if (name_str != empty) { free (name_str); } @@ -7601,11 +7601,11 @@ R_API char *r_bin_java_resolve(RBinJavaObj *BIN_OBJ, int idx, ut8 space_bn_name_ return str; } -R_API ut8 r_bin_java_does_cp_idx_ref_method(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API ut8 rz_bin_java_does_cp_idx_ref_method(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaField *fm_type = NULL; - RListIter *iter; + RzListIter *iter; ut8 res = 0; - r_list_foreach (BIN_OBJ->methods_list, iter, fm_type) { + rz_list_foreach (BIN_OBJ->methods_list, iter, fm_type) { if (fm_type->field_ref_cp_obj->metas->ord == idx) { res = 1; break; @@ -7614,11 +7614,11 @@ R_API ut8 r_bin_java_does_cp_idx_ref_method(RBinJavaObj *BIN_OBJ, int idx) { return res; } -R_API ut8 r_bin_java_does_cp_idx_ref_field(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API ut8 rz_bin_java_does_cp_idx_ref_field(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaField *fm_type = NULL; - RListIter *iter; + RzListIter *iter; ut8 res = 0; - r_list_foreach (BIN_OBJ->fields_list, iter, fm_type) { + rz_list_foreach (BIN_OBJ->fields_list, iter, fm_type) { if (fm_type->field_ref_cp_obj->metas->ord == idx) { res = 1; break; @@ -7627,32 +7627,32 @@ R_API ut8 r_bin_java_does_cp_idx_ref_field(RBinJavaObj *BIN_OBJ, int idx) { return res; } -R_API char *r_bin_java_get_method_name(RBinJavaObj *bin_obj, ut32 idx) { +RZ_API char *rz_bin_java_get_method_name(RBinJavaObj *bin_obj, ut32 idx) { char *name = NULL; - if (idx < r_list_length (bin_obj->methods_list)) { - RBinJavaField *fm_type = r_list_get_n (bin_obj->methods_list, idx); + if (idx < rz_list_length (bin_obj->methods_list)) { + RBinJavaField *fm_type = rz_list_get_n (bin_obj->methods_list, idx); name = strdup (fm_type->name); } return name; } -R_API RList *r_bin_java_get_method_num_name(RBinJavaObj *bin_obj) { +RZ_API RzList *rz_bin_java_get_method_num_name(RBinJavaObj *bin_obj) { ut32 i = 0; - RListIter *iter = NULL; + RzListIter *iter = NULL; RBinJavaField *fm_type; - RList *res = r_list_newf (free); - r_list_foreach (bin_obj->methods_list, iter, fm_type) { + RzList *res = rz_list_newf (free); + rz_list_foreach (bin_obj->methods_list, iter, fm_type) { ut32 len = strlen (fm_type->name) + 30; char *str = malloc (len); snprintf (str, len, "%d %s", i, fm_type->name); ++i; - r_list_append (res, str); + rz_list_append (res, str); } return res; } /* - R_API int r_bin_java_does_cp_obj_ref_idx (RBinJavaObj *bin_obj, RBinJavaCPTypeObj *cp_obj, ut16 idx) { + RZ_API int rz_bin_java_does_cp_obj_ref_idx (RBinJavaObj *bin_obj, RBinJavaCPTypeObj *cp_obj, ut16 idx) { int res = false; RBinJavaCPTypeObj *t_obj = NULL; if (cp_obj) { @@ -7673,11 +7673,11 @@ R_API RList *r_bin_java_get_method_num_name(RBinJavaObj *bin_obj) { case R_BIN_JAVA_CP_METHODREF: break;// check if idx is referenced here case R_BIN_JAVA_CP_INTERFACEMETHOD_REF: break; // check if idx is referenced here case R_BIN_JAVA_CP_FIELDREF: - t_obj = r_bin_java_get_item_from_cp (bin_obj, cp_obj->info.cp_method.class_idx); - res = r_bin_java_does_cp_obj_ref_idx (bin_obj, t_obj, idx); + t_obj = rz_bin_java_get_item_from_cp (bin_obj, cp_obj->info.cp_method.class_idx); + res = rz_bin_java_does_cp_obj_ref_idx (bin_obj, t_obj, idx); if (res == true) break; - t_obj = r_bin_java_get_item_from_cp (bin_obj, cp_obj->info.cp_method.name_and_type_idx); - res = r_bin_java_does_cp_obj_ref_idx (bin_obj, t_obj, idx); + t_obj = rz_bin_java_get_item_from_cp (bin_obj, cp_obj->info.cp_method.name_and_type_idx); + res = rz_bin_java_does_cp_obj_ref_idx (bin_obj, t_obj, idx); break; case R_BIN_JAVA_CP_NAMEANDTYPE: break;// check if idx is referenced here obj->info.cp_name_and_type.name_idx @@ -7688,84 +7688,84 @@ R_API RList *r_bin_java_get_method_num_name(RBinJavaObj *bin_obj) { } } */ -R_API RList *r_bin_java_find_cp_const_by_val_long(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { - RList *res = r_list_newf (free); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_long(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { + RzList *res = rz_list_newf (free); ut32 *v = NULL; - RListIter *iter; + RzListIter *iter; RBinJavaCPTypeObj *cp_obj; eprintf ("Looking for 0x%08x\n", R_BIN_JAVA_UINT (bytes, 0)); - r_list_foreach (bin_obj->cp_list, iter, cp_obj) { + rz_list_foreach (bin_obj->cp_list, iter, cp_obj) { if (cp_obj->tag == R_BIN_JAVA_CP_LONG) { - if (len == 8 && r_bin_java_raw_to_long (cp_obj->info.cp_long.bytes.raw, 0) == r_bin_java_raw_to_long (bytes, 0)) { + if (len == 8 && rz_bin_java_raw_to_long (cp_obj->info.cp_long.bytes.raw, 0) == rz_bin_java_raw_to_long (bytes, 0)) { // TODO: we can safely store a ut32 inside the list without having to allocate it v = malloc (sizeof (ut32)); if (!v) { - r_list_free (res); + rz_list_free (res); return NULL; } *v = cp_obj->idx; - r_list_append (res, v); + rz_list_append (res, v); } } } return res; } -R_API RList *r_bin_java_find_cp_const_by_val_double(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { - RList *res = r_list_newf (free); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_double(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { + RzList *res = rz_list_newf (free); ut32 *v = NULL; - RListIter *iter; + RzListIter *iter; RBinJavaCPTypeObj *cp_obj; - eprintf ("Looking for %f\n", r_bin_java_raw_to_double (bytes, 0)); - r_list_foreach (bin_obj->cp_list, iter, cp_obj) { + eprintf ("Looking for %f\n", rz_bin_java_raw_to_double (bytes, 0)); + rz_list_foreach (bin_obj->cp_list, iter, cp_obj) { if (cp_obj->tag == R_BIN_JAVA_CP_DOUBLE) { - if (len == 8 && r_bin_java_raw_to_double (cp_obj->info.cp_long.bytes.raw, 0) == r_bin_java_raw_to_double (bytes, 0)) { + if (len == 8 && rz_bin_java_raw_to_double (cp_obj->info.cp_long.bytes.raw, 0) == rz_bin_java_raw_to_double (bytes, 0)) { v = malloc (sizeof (ut32)); if (!v) { - r_list_free (res); + rz_list_free (res); return NULL; } *v = cp_obj->idx; - r_list_append (res, v); + rz_list_append (res, v); } } } return res; } -R_API RList *r_bin_java_find_cp_const_by_val_float(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { - RList *res = r_list_newf (free); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_float(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { + RzList *res = rz_list_newf (free); ut32 *v = NULL; - RListIter *iter; + RzListIter *iter; RBinJavaCPTypeObj *cp_obj; eprintf ("Looking for %f\n", R_BIN_JAVA_FLOAT (bytes, 0)); - r_list_foreach (bin_obj->cp_list, iter, cp_obj) { + rz_list_foreach (bin_obj->cp_list, iter, cp_obj) { if (cp_obj->tag == R_BIN_JAVA_CP_FLOAT) { if (len == 4 && R_BIN_JAVA_FLOAT (cp_obj->info.cp_long.bytes.raw, 0) == R_BIN_JAVA_FLOAT (bytes, 0)) { v = malloc (sizeof (ut32)); if (!v) { - r_list_free (res); + rz_list_free (res); return NULL; } *v = cp_obj->idx; - r_list_append (res, v); + rz_list_append (res, v); } } } return res; } -R_API RList *r_bin_java_find_cp_const_by_val(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len, const char t) { +RZ_API RzList *rz_bin_java_find_cp_const_by_val(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len, const char t) { switch (t) { - case R_BIN_JAVA_CP_UTF8: return r_bin_java_find_cp_const_by_val_utf8 (bin_obj, bytes, len); - case R_BIN_JAVA_CP_INTEGER: return r_bin_java_find_cp_const_by_val_int (bin_obj, bytes, len); - case R_BIN_JAVA_CP_FLOAT: return r_bin_java_find_cp_const_by_val_float (bin_obj, bytes, len); - case R_BIN_JAVA_CP_LONG: return r_bin_java_find_cp_const_by_val_long (bin_obj, bytes, len); - case R_BIN_JAVA_CP_DOUBLE: return r_bin_java_find_cp_const_by_val_double (bin_obj, bytes, len); + case R_BIN_JAVA_CP_UTF8: return rz_bin_java_find_cp_const_by_val_utf8 (bin_obj, bytes, len); + case R_BIN_JAVA_CP_INTEGER: return rz_bin_java_find_cp_const_by_val_int (bin_obj, bytes, len); + case R_BIN_JAVA_CP_FLOAT: return rz_bin_java_find_cp_const_by_val_float (bin_obj, bytes, len); + case R_BIN_JAVA_CP_LONG: return rz_bin_java_find_cp_const_by_val_long (bin_obj, bytes, len); + case R_BIN_JAVA_CP_DOUBLE: return rz_bin_java_find_cp_const_by_val_double (bin_obj, bytes, len); case R_BIN_JAVA_CP_UNKNOWN: default: eprintf ("Failed to perform the search for: %s\n", bytes); - return r_list_new (); + return rz_list_new (); } } @@ -7773,7 +7773,7 @@ R_API RList *r_bin_java_find_cp_const_by_val(RBinJavaObj *bin_obj, const ut8 *by // Attempted to clean up these functions and remove them since they are "unused" but without // them there are some compile time warnings, because other projects actually depend on these // for some form of information. -R_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin) { +RZ_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin) { /* Add Constant Pool Serialized Object to an Array the key for this info is: @@ -7793,7 +7793,7 @@ R_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin) { char *key = NULL, *value = NULL; char str_cnt[40]; - char *class_name = r_bin_java_get_this_class_name (bin); + char *class_name = rz_bin_java_get_this_class_name (bin); ut32 key_buf_size = 0; if (!class_name) { class_name = "unknown"; @@ -7817,7 +7817,7 @@ R_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin) { for (idx = 0; idx < bin->cp_count; idx++) { snprintf (key, key_buf_size - 1, "%s.cp.%d", class_name, idx); key[key_buf_size - 1] = 0; - cp_obj = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (bin, idx); + cp_obj = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (bin, idx); IFDBG eprintf("Adding %s to the sdb.\n", key); if (cp_obj) { value = ((RBinJavaCPTypeMetas *) @@ -7833,7 +7833,7 @@ R_API void U(add_cp_objs_to_sdb)(RBinJavaObj * bin) { free (key); } -R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { +RZ_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { /* *** Experimental and May Change *** Add field information to an Array @@ -7845,7 +7845,7 @@ R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { key 4, method meta .meta = [, ?] */ - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaField *fm_type; ut32 key_size = 255, value_buffer_size = 1024, @@ -7853,7 +7853,7 @@ R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { char *field_key = NULL, *field_key_value = NULL, *value_buffer = NULL; - char *class_name = r_bin_java_get_this_class_name (bin); + char *class_name = rz_bin_java_get_this_class_name (bin); if (!class_name) { class_name = "unknown"; class_name_inheap = 0; @@ -7865,14 +7865,14 @@ R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { field_key_value = malloc (key_size); snprintf (field_key, key_size, "%s.methods", class_name); field_key[key_size - 1] = 0; - r_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { + rz_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { char number_buffer[80]; ut64 file_offset = fm_type->file_offset + bin->loadaddr; snprintf (number_buffer, sizeof (number_buffer), "0x%04"PFMT64x, file_offset); IFDBG eprintf("Inserting: []%s = %s\n", field_key, number_buffer); sdb_array_push (bin->kv, field_key, number_buffer, 0); } - r_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { + rz_list_foreach_safe (bin->fields_list, iter, iter_tmp, fm_type) { ut64 field_offset = fm_type->file_offset + bin->loadaddr; // generate method specific key & value snprintf (field_key, key_size, "%s.0x%04"PFMT64x, class_name, field_offset); @@ -7909,7 +7909,7 @@ R_API void U(add_field_infos_to_sdb)(RBinJavaObj * bin) { } } -R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { +RZ_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { /* *** Experimental and May Change *** Add Mehtod information to an Array @@ -7928,7 +7928,7 @@ R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { also take note that code offset and the method offset are not the same values. */ - RListIter *iter = NULL, *iter_tmp = NULL; + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaField *fm_type; ut32 key_size = 255, value_buffer_size = 1024, @@ -7936,7 +7936,7 @@ R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { char *method_key = NULL, *method_key_value = NULL, *value_buffer = NULL; - char *class_name = r_bin_java_get_this_class_name (bin); + char *class_name = rz_bin_java_get_this_class_name (bin); ut64 baddr = bin->loadaddr; if (!class_name) { class_name = "unknown"; @@ -7949,15 +7949,15 @@ R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { method_key_value = malloc (key_size); snprintf (method_key, key_size, "%s.methods", class_name); method_key[key_size - 1] = 0; - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { char number_buffer[80]; ut64 file_offset = fm_type->file_offset + baddr; snprintf (number_buffer, sizeof (number_buffer), "0x%04"PFMT64x, file_offset); sdb_array_push (bin->kv, method_key, number_buffer, 0); } - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { - ut64 code_offset = r_bin_java_get_method_code_offset (fm_type) + baddr, - code_size = r_bin_java_get_method_code_size (fm_type), + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + ut64 code_offset = rz_bin_java_get_method_code_offset (fm_type) + baddr, + code_size = rz_bin_java_get_method_code_size (fm_type), method_offset = fm_type->file_offset + baddr; // generate method specific key & value snprintf (method_key, key_size, "%s.0x%04"PFMT64x, class_name, code_offset); @@ -8003,97 +8003,97 @@ R_API void U(add_method_infos_to_sdb)(RBinJavaObj * bin) { } } -R_API RList *U(r_bin_java_get_args_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { - RBinJavaField *fm_type = r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); - return fm_type ? r_bin_java_get_args (fm_type) : NULL; +RZ_API RzList *U(rz_bin_java_get_args_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { + RBinJavaField *fm_type = rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); + return fm_type ? rz_bin_java_get_args (fm_type) : NULL; } -R_API RList *U(r_bin_java_get_ret_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { - RBinJavaField *fm_type = r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); - return fm_type ? r_bin_java_get_ret (fm_type) : NULL; +RZ_API RzList *U(rz_bin_java_get_ret_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { + RBinJavaField *fm_type = rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); + return fm_type ? rz_bin_java_get_ret (fm_type) : NULL; } -R_API char *U(r_bin_java_get_fcn_name_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { - RBinJavaField *fm_type = r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); +RZ_API char *U(rz_bin_java_get_fcn_name_from_bin)(RBinJavaObj * bin_obj, ut64 addr) { + RBinJavaField *fm_type = rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); return fm_type && fm_type->name ? strdup (fm_type->name) : NULL; } -R_API int U(r_bin_java_is_method_static)(RBinJavaObj * bin_obj, ut64 addr) { - RBinJavaField *fm_type = r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); +RZ_API int U(rz_bin_java_is_method_static)(RBinJavaObj * bin_obj, ut64 addr) { + RBinJavaField *fm_type = rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr); return fm_type && fm_type->flags & R_BIN_JAVA_METHOD_ACC_STATIC; } -R_API int U(r_bin_java_is_method_private)(RBinJavaObj * bin_obj, ut64 addr) { - return r_bin_java_is_fm_type_private (r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr)); +RZ_API int U(rz_bin_java_is_method_private)(RBinJavaObj * bin_obj, ut64 addr) { + return rz_bin_java_is_fm_type_private (rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr)); } -R_API int U(r_bin_java_is_method_protected)(RBinJavaObj * bin_obj, ut64 addr) { - return r_bin_java_is_fm_type_protected ( - r_bin_java_get_method_code_attribute_with_addr (bin_obj, addr)); +RZ_API int U(rz_bin_java_is_method_protected)(RBinJavaObj * bin_obj, ut64 addr) { + return rz_bin_java_is_fm_type_protected ( + rz_bin_java_get_method_code_attribute_with_addr (bin_obj, addr)); } -R_API int r_bin_java_print_method_idx_summary(RBinJavaObj *bin_obj, ut32 idx) { +RZ_API int rz_bin_java_print_method_idx_summary(RBinJavaObj *bin_obj, ut32 idx) { int res = false; - if (idx < r_list_length (bin_obj->methods_list)) { - RBinJavaField *fm_type = r_list_get_n (bin_obj->methods_list, idx); - r_bin_java_print_method_summary (fm_type); + if (idx < rz_list_length (bin_obj->methods_list)) { + RBinJavaField *fm_type = rz_list_get_n (bin_obj->methods_list, idx); + rz_bin_java_print_method_summary (fm_type); res = true; } return res; } -R_API ut32 r_bin_java_get_method_count(RBinJavaObj *bin_obj) { - return r_list_length (bin_obj->methods_list); +RZ_API ut32 rz_bin_java_get_method_count(RBinJavaObj *bin_obj) { + return rz_list_length (bin_obj->methods_list); } -R_API RList *r_bin_java_get_interface_names(RBinJavaObj *bin) { - RList *interfaces_names = r_list_new (); - RListIter *iter; +RZ_API RzList *rz_bin_java_get_interface_names(RBinJavaObj *bin) { + RzList *interfaces_names = rz_list_new (); + RzListIter *iter; RBinJavaInterfaceInfo *ifobj; - r_list_foreach (bin->interfaces_list, iter, ifobj) { + rz_list_foreach (bin->interfaces_list, iter, ifobj) { if (ifobj && ifobj->name) { - r_list_append (interfaces_names, strdup (ifobj->name)); + rz_list_append (interfaces_names, strdup (ifobj->name)); } } return interfaces_names; } -R_API ut64 r_bin_java_get_main(RBinJavaObj *bin) { +RZ_API ut64 rz_bin_java_get_main(RBinJavaObj *bin) { if (bin->main_code_attr) { return bin->main_code_attr->info.code_attr.code_offset + bin->loadaddr; } return 0; } -R_API RBinJavaObj *r_bin_java_new(const char *file, ut64 loadaddr, Sdb *kv) { +RZ_API RBinJavaObj *rz_bin_java_new(const char *file, ut64 loadaddr, Sdb *kv) { RBinJavaObj *bin = R_NEW0 (RBinJavaObj); if (!bin) { return NULL; } bin->file = strdup (file); size_t sz; - ut8 *buf = (ut8 *)r_file_slurp (file, &sz); + ut8 *buf = (ut8 *)rz_file_slurp (file, &sz); bin->size = sz; if (!buf) { - return r_bin_java_free (bin); + return rz_bin_java_free (bin); } - if (!r_bin_java_new_bin (bin, loadaddr, kv, buf, bin->size)) { - r_bin_java_free (bin); + if (!rz_bin_java_new_bin (bin, loadaddr, kv, buf, bin->size)) { + rz_bin_java_free (bin); bin = NULL; } free (buf); return bin; } -R_API ut64 r_bin_java_get_class_entrypoint(RBinJavaObj *bin) { +RZ_API ut64 rz_bin_java_get_class_entrypoint(RBinJavaObj *bin) { if (bin->cf2.this_class_entrypoint_code_attr) { return bin->cf2.this_class_entrypoint_code_attr->info.code_attr.code_offset; } return 0; } -R_API RList *r_bin_java_get_method_exception_table_with_addr(RBinJavaObj *bin, ut64 addr) { - RListIter *iter = NULL, *iter_tmp = NULL; +RZ_API RzList *rz_bin_java_get_method_exception_table_with_addr(RBinJavaObj *bin, ut64 addr) { + RzListIter *iter = NULL, *iter_tmp = NULL; RBinJavaField *fm_type, *res = NULL; if (!bin && R_BIN_JAVA_GLOBAL_BIN) { bin = R_BIN_JAVA_GLOBAL_BIN; @@ -8102,21 +8102,21 @@ R_API RList *r_bin_java_get_method_exception_table_with_addr(RBinJavaObj *bin, u eprintf ("Attempting to analyse function when the R_BIN_JAVA_GLOBAL_BIN has not been set.\n"); return NULL; } - r_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { - ut64 offset = r_bin_java_get_method_code_offset (fm_type) + bin->loadaddr, - size = r_bin_java_get_method_code_size (fm_type); + rz_list_foreach_safe (bin->methods_list, iter, iter_tmp, fm_type) { + ut64 offset = rz_bin_java_get_method_code_offset (fm_type) + bin->loadaddr, + size = rz_bin_java_get_method_code_size (fm_type); if (addr >= offset && addr <= size + offset) { res = fm_type; } } if (res) { - RBinJavaAttrInfo *code_attr = r_bin_java_get_method_code_attribute (res); + RBinJavaAttrInfo *code_attr = rz_bin_java_get_method_code_attribute (res); return code_attr->info.code_attr.exception_table; } return NULL; } -R_API const RList *r_bin_java_get_methods_list(RBinJavaObj *bin) { +RZ_API const RzList *rz_bin_java_get_methods_list(RBinJavaObj *bin) { if (bin) { return bin->methods_list; } @@ -8126,8 +8126,8 @@ R_API const RList *r_bin_java_get_methods_list(RBinJavaObj *bin) { return NULL; } -R_API RList *r_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj) { - RList *the_list; +RZ_API RzList *rz_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj) { + RzList *the_list; Sdb *sdb; if (!bin_obj) { return NULL; @@ -8136,7 +8136,7 @@ R_API RList *r_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj) { if (!sdb) { return NULL; } - the_list = r_list_new (); + the_list = rz_list_new (); if (!the_list) { return NULL; } @@ -8144,79 +8144,79 @@ R_API RList *r_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj) { return the_list; } -R_API RList *r_bin_java_extract_all_bin_type_values(RBinJavaObj *bin_obj) { - RListIter *fm_type_iter; - RList *all_types = r_list_new (); +RZ_API RzList *rz_bin_java_extract_all_bin_type_values(RBinJavaObj *bin_obj) { + RzListIter *fm_type_iter; + RzList *all_types = rz_list_new (); RBinJavaField *fm_type; // get all field types - r_list_foreach (bin_obj->fields_list, fm_type_iter, fm_type) { + rz_list_foreach (bin_obj->fields_list, fm_type_iter, fm_type) { char *desc = NULL; if (!extract_type_value (fm_type->descriptor, &desc)) { return NULL; } IFDBG eprintf("Adding field type: %s\n", desc); - r_list_append (all_types, desc); + rz_list_append (all_types, desc); } // get all method types - r_list_foreach (bin_obj->methods_list, fm_type_iter, fm_type) { - RList *the_list = r_bin_java_extract_type_values (fm_type->descriptor); - RListIter *desc_iter; + rz_list_foreach (bin_obj->methods_list, fm_type_iter, fm_type) { + RzList *the_list = rz_bin_java_extract_type_values (fm_type->descriptor); + RzListIter *desc_iter; char *str; - r_list_foreach (the_list, desc_iter, str) { + rz_list_foreach (the_list, desc_iter, str) { if (str && *str != '(' && *str != ')') { - r_list_append (all_types, strdup (str)); + rz_list_append (all_types, strdup (str)); IFDBG eprintf("Adding method type: %s\n", str); } } - r_list_free (the_list); + rz_list_free (the_list); } return all_types; } -R_API RList *r_bin_java_get_method_definitions(RBinJavaObj *bin) { +RZ_API RzList *rz_bin_java_get_method_definitions(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RList *the_list = r_list_new (); + RzList *the_list = rz_list_new (); if (!the_list) { return NULL; } - RListIter *iter = NULL; + RzListIter *iter = NULL; if (!bin) { return the_list; } - r_list_foreach (bin->methods_list, iter, fm_type) { - char *method_proto = r_bin_java_get_method_definition (fm_type); + rz_list_foreach (bin->methods_list, iter, fm_type) { + char *method_proto = rz_bin_java_get_method_definition (fm_type); // eprintf ("Method prototype: %s\n", method_proto); - r_list_append (the_list, method_proto); + rz_list_append (the_list, method_proto); } return the_list; } -R_API RList *r_bin_java_get_field_definitions(RBinJavaObj *bin) { +RZ_API RzList *rz_bin_java_get_field_definitions(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RList *the_list = r_list_new (); + RzList *the_list = rz_list_new (); if (!the_list) { return NULL; } - RListIter *iter = NULL; + RzListIter *iter = NULL; if (!bin) { return the_list; } - r_list_foreach (bin->fields_list, iter, fm_type) { - char *field_def = r_bin_java_get_field_definition (fm_type); + rz_list_foreach (bin->fields_list, iter, fm_type) { + char *field_def = rz_bin_java_get_field_definition (fm_type); // eprintf ("Field def: %s, %s, %s, %s\n", fm_type->name, fm_type->descriptor, fm_type->flags_str, field_def); - r_list_append (the_list, field_def); + rz_list_append (the_list, field_def); } return the_list; } -R_API RList *r_bin_java_get_import_definitions(RBinJavaObj *bin) { - RList *the_list = r_bin_java_get_lib_names (bin); - RListIter *iter = NULL; +RZ_API RzList *rz_bin_java_get_import_definitions(RBinJavaObj *bin) { + RzList *the_list = rz_bin_java_get_lib_names (bin); + RzListIter *iter = NULL; char *new_str; if (!bin || !the_list) { return the_list; } - r_list_foreach (the_list, iter, new_str) { + rz_list_foreach (the_list, iter, new_str) { while (*new_str) { if (*new_str == '/') { *new_str = '.'; @@ -8227,81 +8227,81 @@ R_API RList *r_bin_java_get_import_definitions(RBinJavaObj *bin) { return the_list; } -R_API RList *r_bin_java_get_field_offsets(RBinJavaObj *bin) { +RZ_API RzList *rz_bin_java_get_field_offsets(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RList *the_list = r_list_new (); + RzList *the_list = rz_list_new (); if (!the_list) { return NULL; } - RListIter *iter = NULL; + RzListIter *iter = NULL; ut64 *paddr = NULL; if (!bin) { return the_list; } the_list->free = free; - r_list_foreach (bin->fields_list, iter, fm_type) { + rz_list_foreach (bin->fields_list, iter, fm_type) { paddr = malloc (sizeof(ut64)); if (!paddr) { - r_list_free (the_list); + rz_list_free (the_list); return NULL; } *paddr = fm_type->file_offset + bin->loadaddr; // eprintf ("Field def: %s, %s, %s, %s\n", fm_type->name, fm_type->descriptor, fm_type->flags_str, field_def); - r_list_append (the_list, paddr); + rz_list_append (the_list, paddr); } return the_list; } -R_API RList *r_bin_java_get_method_offsets(RBinJavaObj *bin) { +RZ_API RzList *rz_bin_java_get_method_offsets(RBinJavaObj *bin) { RBinJavaField *fm_type = NULL; - RList *the_list = r_list_new (); - RListIter *iter = NULL; + RzList *the_list = rz_list_new (); + RzListIter *iter = NULL; ut64 *paddr = NULL; if (!bin) { return the_list; } the_list->free = free; - r_list_foreach (bin->methods_list, iter, fm_type) { + rz_list_foreach (bin->methods_list, iter, fm_type) { paddr = R_NEW0 (ut64); *paddr = fm_type->file_offset + bin->loadaddr; - r_list_append (the_list, paddr); + rz_list_append (the_list, paddr); } return the_list; } -R_API ut16 r_bin_java_calculate_field_access_value(const char *access_flags_str) { +RZ_API ut16 rz_bin_java_calculate_field_access_value(const char *access_flags_str) { return calculate_access_value (access_flags_str, FIELD_ACCESS_FLAGS); } -R_API ut16 r_bin_java_calculate_class_access_value(const char *access_flags_str) { +RZ_API ut16 rz_bin_java_calculate_class_access_value(const char *access_flags_str) { return calculate_access_value (access_flags_str, CLASS_ACCESS_FLAGS); } -R_API ut16 r_bin_java_calculate_method_access_value(const char *access_flags_str) { +RZ_API ut16 rz_bin_java_calculate_method_access_value(const char *access_flags_str) { return calculate_access_value (access_flags_str, METHOD_ACCESS_FLAGS); } -R_API RList *retrieve_all_method_access_string_and_value(void) { +RZ_API RzList *retrieve_all_method_access_string_and_value(void) { return retrieve_all_access_string_and_value (METHOD_ACCESS_FLAGS); } -R_API RList *retrieve_all_field_access_string_and_value(void) { +RZ_API RzList *retrieve_all_field_access_string_and_value(void) { return retrieve_all_access_string_and_value (FIELD_ACCESS_FLAGS); } -R_API RList *retrieve_all_class_access_string_and_value(void) { +RZ_API RzList *retrieve_all_class_access_string_and_value(void) { return retrieve_all_access_string_and_value (CLASS_ACCESS_FLAGS); } -R_API char *r_bin_java_resolve_with_space(RBinJavaObj *obj, int idx) { - return r_bin_java_resolve (obj, idx, 1); +RZ_API char *rz_bin_java_resolve_with_space(RBinJavaObj *obj, int idx) { + return rz_bin_java_resolve (obj, idx, 1); } -R_API char *r_bin_java_resolve_without_space(RBinJavaObj *obj, int idx) { - return r_bin_java_resolve (obj, idx, 0); +RZ_API char *rz_bin_java_resolve_without_space(RBinJavaObj *obj, int idx) { + return rz_bin_java_resolve (obj, idx, 0); } -R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { +RZ_API char *rz_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { RBinJavaCPTypeObj *item = NULL, *item2 = NULL; char *class_str = NULL, *name_str = NULL, @@ -8312,10 +8312,10 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { *str = NULL, *out = NULL; int memory_alloc = 0; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { - // r_bin_java_new_bin(BIN_OBJ); + // rz_bin_java_new_bin(BIN_OBJ); return NULL; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { cp_name = ((RBinJavaCPTypeMetas *) item->metas->type_info)->name; IFDBG eprintf("java_resolve Resolved: (%d) %s\n", idx, cp_name); @@ -8323,17 +8323,17 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { return NULL; } if (!strcmp (cp_name, "Class")) { - item2 = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); - // str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); - class_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + item2 = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + // str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); + class_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); if (!desc_str) { desc_str = empty; } @@ -8342,7 +8342,7 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (memory_alloc); if (str) { snprintf (str, memory_alloc, "%s%s", name_str, desc_str); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8362,15 +8362,15 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { /* * The MethodRef, FieldRef, and InterfaceMethodRef structures */ - class_str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); + class_str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } @@ -8379,7 +8379,7 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (memory_alloc); if (str) { snprintf (str, memory_alloc, "%s/%s%s", class_str, name_str, desc_str); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8394,8 +8394,8 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { free (desc_str); } } else if (strcmp (cp_name, "String") == 0) { - ut32 length = r_bin_java_get_utf8_len_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); - string_str = r_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); + ut32 length = rz_bin_java_get_utf8_len_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); + string_str = rz_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); str = NULL; IFDBG eprintf("java_resolve String got: (%d) %s\n", item->info.cp_string.string_idx, string_str); if (!string_str) { @@ -8407,7 +8407,7 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (memory_alloc); if (str) { snprintf (str, memory_alloc, "\"%s\"", string_str); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8421,21 +8421,21 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (sz); memset (str, 0, sz); if (sz > 10) { - r_base64_encode (str, item->info.cp_utf8.bytes, item->info.cp_utf8.length); + rz_base64_encode (str, item->info.cp_utf8.bytes, item->info.cp_utf8.length); } } else if (strcmp (cp_name, "Long") == 0) { str = malloc (34); if (str) { - snprintf (str, 34, "0x%"PFMT64x, r_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0)); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + snprintf (str, 34, "0x%"PFMT64x, rz_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } } else if (strcmp (cp_name, "Double") == 0) { str = malloc (1000); if (str) { - snprintf (str, 1000, "%f", r_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0)); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + snprintf (str, 1000, "%f", rz_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8443,7 +8443,7 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = calloc (34, 1); if (str) { snprintf (str, 34, "0x%08x", R_BIN_JAVA_UINT (item->info.cp_integer.bytes.raw, 0)); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8451,16 +8451,16 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (34); if (str) { snprintf (str, 34, "%f", R_BIN_JAVA_FLOAT (item->info.cp_float.bytes.raw, 0)); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } } else if (!strcmp (cp_name, "NameAndType")) { - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } @@ -8469,7 +8469,7 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { str = malloc (memory_alloc); if (str) { snprintf (str, memory_alloc, "%s %s", name_str, desc_str); - out = r_base64_encode_dyn ((const char *) str, strlen (str)); + out = rz_base64_encode_dyn ((const char *) str, strlen (str)); free (str); str = out; } @@ -8481,31 +8481,31 @@ R_API char *r_bin_java_resolve_b64_encode(RBinJavaObj *BIN_OBJ, ut16 idx) { free (desc_str); } } else { - str = r_base64_encode_dyn ((const char *) "(null)", 6); + str = rz_base64_encode_dyn ((const char *) "(null)", 6); } return str; } -R_API ut64 r_bin_java_resolve_cp_idx_address(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API ut64 rz_bin_java_resolve_cp_idx_address(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaCPTypeObj *item = NULL; ut64 addr = -1; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { return -1; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { addr = item->file_offset + item->loadaddr; } return addr; } -R_API char *r_bin_java_resolve_cp_idx_to_string(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API char *rz_bin_java_resolve_cp_idx_to_string(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaCPTypeObj *item = NULL; char *value = NULL; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { return NULL; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { value = ((RBinJavaCPTypeMetas *) item->metas->type_info)-> @@ -8514,12 +8514,12 @@ R_API char *r_bin_java_resolve_cp_idx_to_string(RBinJavaObj *BIN_OBJ, int idx) { return value; } -R_API int r_bin_java_resolve_cp_idx_print_summary(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API int rz_bin_java_resolve_cp_idx_print_summary(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaCPTypeObj *item = NULL; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { return false; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { ((RBinJavaCPTypeMetas *) item->metas->type_info)-> @@ -8530,7 +8530,7 @@ R_API int r_bin_java_resolve_cp_idx_print_summary(RBinJavaObj *BIN_OBJ, int idx) return item ? true : false; } -R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ, int idx) { +RZ_API ConstJavaValue *U(rz_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ, int idx) { // TODO XXX FIXME add a size parameter to the str when it is passed in RBinJavaCPTypeObj *item = NULL, *item2 = NULL; ConstJavaValue *result = R_NEW0 (ConstJavaValue); @@ -8545,27 +8545,27 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ *cp_name = NULL; result->type = "unknown"; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { - // r_bin_java_new_bin(BIN_OBJ); + // rz_bin_java_new_bin(BIN_OBJ); return result; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (!item) { return result; } cp_name = ((RBinJavaCPTypeMetas *) item->metas->type_info)->name; IFDBG eprintf("java_resolve Resolved: (%d) %s\n", idx, cp_name); if (strcmp (cp_name, "Class") == 0) { - item2 = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); - // str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); - class_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + item2 = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + // str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, idx-1); + class_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item2); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item2); if (!desc_str) { desc_str = empty; } @@ -8589,15 +8589,15 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ /* * The MethodRef, FieldRef, and InterfaceMethodRef structures */ - class_str = r_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); + class_str = rz_bin_java_get_name_from_bin_cp_list (BIN_OBJ, item->info.cp_method.class_idx); if (!class_str) { class_str = empty; } - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } @@ -8616,8 +8616,8 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ free (desc_str); } } else if (strcmp (cp_name, "String") == 0) { - ut32 length = r_bin_java_get_utf8_len_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); - string_str = r_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); + ut32 length = rz_bin_java_get_utf8_len_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); + string_str = rz_bin_java_get_utf8_from_bin_cp_list (BIN_OBJ, item->info.cp_string.string_idx); IFDBG eprintf("java_resolve String got: (%d) %s\n", item->info.cp_string.string_idx, string_str); if (!string_str) { string_str = empty; @@ -8627,7 +8627,7 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ result->value._str = R_NEW0 (struct java_const_value_str_t); result->value._str->len = length; if (length > 0) { - result->value._str->str = r_str_ndup (string_str, length); + result->value._str->str = rz_str_ndup (string_str, length); } else { result->value._str->str = strdup (""); } @@ -8642,10 +8642,10 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ memcpy (result->value._str->str, item->info.cp_utf8.bytes, item->info.cp_utf8.length); } else if (strcmp (cp_name, "Long") == 0) { result->type = "long"; - result->value._long = r_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0); + result->value._long = rz_bin_java_raw_to_long (item->info.cp_long.bytes.raw, 0); } else if (strcmp (cp_name, "Double") == 0) { result->type = "double"; - result->value._double = r_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0); + result->value._double = rz_bin_java_raw_to_double (item->info.cp_double.bytes.raw, 0); } else if (strcmp (cp_name, "Integer") == 0) { result->type = "int"; result->value._int = R_BIN_JAVA_UINT (item->info.cp_integer.bytes.raw, 0); @@ -8655,11 +8655,11 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ } else if (strcmp (cp_name, "NameAndType") == 0) { result->value._ref = R_NEW0 (struct java_const_value_ref_t); result->type = "ref"; - name_str = r_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); + name_str = rz_bin_java_get_item_name_from_bin_cp_list (BIN_OBJ, item); if (!name_str) { name_str = empty; } - desc_str = r_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); + desc_str = rz_bin_java_get_item_desc_from_bin_cp_list (BIN_OBJ, item); if (!desc_str) { desc_str = empty; } @@ -8672,13 +8672,13 @@ R_API ConstJavaValue *U(r_bin_java_resolve_to_const_value)(RBinJavaObj * BIN_OBJ if (desc_str != empty) { free (desc_str); } - result->value._ref->is_method = r_bin_java_does_cp_idx_ref_method (BIN_OBJ, idx); - result->value._ref->is_field = r_bin_java_does_cp_idx_ref_field (BIN_OBJ, idx); + result->value._ref->is_method = rz_bin_java_does_cp_idx_ref_method (BIN_OBJ, idx); + result->value._ref->is_field = rz_bin_java_does_cp_idx_ref_field (BIN_OBJ, idx); } return result; } -R_API void U(r_bin_java_free_const_value)(ConstJavaValue * cp_value) { +RZ_API void U(rz_bin_java_free_const_value)(ConstJavaValue * cp_value) { char first_char = cp_value && cp_value->type ? *cp_value->type : 0, second_char = cp_value && cp_value->type ? *(cp_value->type + 1) : 0; switch (first_char) { @@ -8698,108 +8698,108 @@ R_API void U(r_bin_java_free_const_value)(ConstJavaValue * cp_value) { free (cp_value); } -R_API char *r_bin_java_get_field_name(RBinJavaObj *bin_obj, ut32 idx) { +RZ_API char *rz_bin_java_get_field_name(RBinJavaObj *bin_obj, ut32 idx) { char *name = NULL; - if (idx < r_list_length (bin_obj->fields_list)) { - RBinJavaField *fm_type = r_list_get_n (bin_obj->fields_list, idx); + if (idx < rz_list_length (bin_obj->fields_list)) { + RBinJavaField *fm_type = rz_list_get_n (bin_obj->fields_list, idx); name = strdup (fm_type->name); } return name; } -R_API int r_bin_java_print_field_idx_summary(RBinJavaObj *bin_obj, ut32 idx) { +RZ_API int rz_bin_java_print_field_idx_summary(RBinJavaObj *bin_obj, ut32 idx) { int res = false; - if (idx < r_list_length (bin_obj->fields_list)) { - RBinJavaField *fm_type = r_list_get_n (bin_obj->fields_list, idx); - r_bin_java_print_field_summary (fm_type); + if (idx < rz_list_length (bin_obj->fields_list)) { + RBinJavaField *fm_type = rz_list_get_n (bin_obj->fields_list, idx); + rz_bin_java_print_field_summary (fm_type); res = true; } return res; } -R_API ut32 r_bin_java_get_field_count(RBinJavaObj *bin_obj) { - return r_list_length (bin_obj->fields_list); +RZ_API ut32 rz_bin_java_get_field_count(RBinJavaObj *bin_obj) { + return rz_list_length (bin_obj->fields_list); } -R_API RList *r_bin_java_get_field_num_name(RBinJavaObj *bin_obj) { +RZ_API RzList *rz_bin_java_get_field_num_name(RBinJavaObj *bin_obj) { ut32 i = 0; RBinJavaField *fm_type; - RListIter *iter = NULL; - RList *res = r_list_newf (free); - r_list_foreach (bin_obj->fields_list, iter, fm_type) { + RzListIter *iter = NULL; + RzList *res = rz_list_newf (free); + rz_list_foreach (bin_obj->fields_list, iter, fm_type) { ut32 len = strlen (fm_type->name) + 30; char *str = malloc (len); if (!str) { - r_list_free (res); + rz_list_free (res); return NULL; } snprintf (str, len, "%d %s", i, fm_type->name); ++i; - r_list_append (res, str); + rz_list_append (res, str); } return res; } -R_API RList *r_bin_java_find_cp_const_by_val_utf8(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { - RList *res = r_list_newf (free); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_utf8(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { + RzList *res = rz_list_newf (free); ut32 *v = NULL; - RListIter *iter; + RzListIter *iter; RBinJavaCPTypeObj *cp_obj; IFDBG eprintf("In UTF-8 Looking for %s\n", bytes); - r_list_foreach (bin_obj->cp_list, iter, cp_obj) { + rz_list_foreach (bin_obj->cp_list, iter, cp_obj) { if (cp_obj->tag == R_BIN_JAVA_CP_UTF8) { IFDBG eprintf("In UTF-8 Looking @ %s\n", cp_obj->info.cp_utf8.bytes); IFDBG eprintf("UTF-8 len = %d and memcmp = %d\n", cp_obj->info.cp_utf8.length, memcmp (bytes, cp_obj->info.cp_utf8.bytes, len)); if (len == cp_obj->info.cp_utf8.length && !memcmp (bytes, cp_obj->info.cp_utf8.bytes, len)) { v = malloc (sizeof (ut32)); if (!v) { - r_list_free (res); + rz_list_free (res); return NULL; } *v = cp_obj->metas->ord; IFDBG eprintf("Found a match adding idx: %d\n", *v); - r_list_append (res, v); + rz_list_append (res, v); } } } return res; } -R_API RList *r_bin_java_find_cp_const_by_val_int(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { - RList *res = r_list_newf (free); +RZ_API RzList *rz_bin_java_find_cp_const_by_val_int(RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len) { + RzList *res = rz_list_newf (free); ut32 *v = NULL; - RListIter *iter; + RzListIter *iter; RBinJavaCPTypeObj *cp_obj; eprintf ("Looking for 0x%08x\n", (ut32) R_BIN_JAVA_UINT (bytes, 0)); - r_list_foreach (bin_obj->cp_list, iter, cp_obj) { + rz_list_foreach (bin_obj->cp_list, iter, cp_obj) { if (cp_obj->tag == R_BIN_JAVA_CP_INTEGER) { if (len == 4 && R_BIN_JAVA_UINT (bytes, 0) == R_BIN_JAVA_UINT (cp_obj->info.cp_integer.bytes.raw, 0)) { v = malloc (sizeof (ut32)); if (!v) { - r_list_free (res); + rz_list_free (res); return NULL; } *v = cp_obj->idx; - r_list_append (res, v); + rz_list_append (res, v); } } } return res; } -R_API char r_bin_java_resolve_cp_idx_tag(RBinJavaObj *BIN_OBJ, int idx) { +RZ_API char rz_bin_java_resolve_cp_idx_tag(RBinJavaObj *BIN_OBJ, int idx) { RBinJavaCPTypeObj *item = NULL; if (BIN_OBJ && BIN_OBJ->cp_count < 1) { - // r_bin_java_new_bin(BIN_OBJ); + // rz_bin_java_new_bin(BIN_OBJ); return R_BIN_JAVA_CP_UNKNOWN; } - item = (RBinJavaCPTypeObj *) r_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); + item = (RBinJavaCPTypeObj *) rz_bin_java_get_item_from_bin_cp_list (BIN_OBJ, idx); if (item) { return item->tag; } return R_BIN_JAVA_CP_UNKNOWN; } -R_API int U(r_bin_java_integer_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API int U(rz_bin_java_integer_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj) { return false; } @@ -8810,7 +8810,7 @@ R_API int U(r_bin_java_integer_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { eprintf ("Not supporting the overwrite of CP Objects with one of a different size.\n"); return false; } - r_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_INTEGER); + rz_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_INTEGER); cp_obj->tag = R_BIN_JAVA_CP_INTEGER; memcpy (bytes, (const char *) &val, 4); val = R_BIN_JAVA_UINT (bytes, 0); @@ -8818,8 +8818,8 @@ R_API int U(r_bin_java_integer_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { return true; } -R_API int U(r_bin_java_float_cp_set)(RBinJavaObj * bin, ut16 idx, float val) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API int U(rz_bin_java_float_cp_set)(RBinJavaObj * bin, ut16 idx, float val) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj) { return false; } @@ -8830,7 +8830,7 @@ R_API int U(r_bin_java_float_cp_set)(RBinJavaObj * bin, ut16 idx, float val) { eprintf ("Not supporting the overwrite of CP Objects with one of a different size.\n"); return false; } - r_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_FLOAT); + rz_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_FLOAT); cp_obj->tag = R_BIN_JAVA_CP_FLOAT; memcpy (bytes, (const char *) &val, 4); float *foo = (float*) bytes; @@ -8839,8 +8839,8 @@ R_API int U(r_bin_java_float_cp_set)(RBinJavaObj * bin, ut16 idx, float val) { return true; } -R_API int U(r_bin_java_long_cp_set)(RBinJavaObj * bin, ut16 idx, ut64 val) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API int U(rz_bin_java_long_cp_set)(RBinJavaObj * bin, ut16 idx, ut64 val) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj) { return false; } @@ -8851,16 +8851,16 @@ R_API int U(r_bin_java_long_cp_set)(RBinJavaObj * bin, ut16 idx, ut64 val) { eprintf ("Not supporting the overwrite of CP Objects with one of a different size.\n"); return false; } - r_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_LONG); + rz_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_LONG); cp_obj->tag = R_BIN_JAVA_CP_LONG; memcpy (bytes, (const char *) &val, 8); - val = r_bin_java_raw_to_long (bytes, 0); + val = rz_bin_java_raw_to_long (bytes, 0); memcpy (&cp_obj->info.cp_long.bytes.raw, (const char *) &val, 8); return true; } -R_API int U(r_bin_java_double_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API int U(rz_bin_java_double_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj) { return false; } @@ -8871,22 +8871,22 @@ R_API int U(r_bin_java_double_cp_set)(RBinJavaObj * bin, ut16 idx, ut32 val) { eprintf ("Not supporting the overwrite of CP Objects with one of a different size.\n"); return false; } - r_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_DOUBLE); + rz_bin_java_check_reset_cp_obj (cp_obj, R_BIN_JAVA_CP_DOUBLE); cp_obj->tag = R_BIN_JAVA_CP_DOUBLE; ut64 val64 = val; memcpy (bytes, (const char *) &val64, 8); - val64 = r_bin_java_raw_to_long (bytes, 0); + val64 = rz_bin_java_raw_to_long (bytes, 0); memcpy (&cp_obj->info.cp_double.bytes.raw, (const char *) &val64, 8); return true; } -R_API int U(r_bin_java_utf8_cp_set)(RBinJavaObj * bin, ut16 idx, const ut8 * buffer, ut32 len) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API int U(rz_bin_java_utf8_cp_set)(RBinJavaObj * bin, ut16 idx, const ut8 * buffer, ut32 len) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj) { return false; } eprintf ("Writing %d byte(s) (%s)\n", len, buffer); - // r_bin_java_check_reset_cp_obj(cp_obj, R_BIN_JAVA_CP_INTEGER); + // rz_bin_java_check_reset_cp_obj(cp_obj, R_BIN_JAVA_CP_INTEGER); if (cp_obj->tag != R_BIN_JAVA_CP_UTF8) { eprintf ("Not supporting the overwrite of CP Objects with one of a different size.\n"); return false; @@ -8904,7 +8904,7 @@ R_API int U(r_bin_java_utf8_cp_set)(RBinJavaObj * bin, ut16 idx, const ut8 * buf return true; } -R_API ut8 *r_bin_java_cp_get_bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { +RZ_API ut8 *rz_bin_java_cp_get_bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len) { if (!out_sz) { return NULL; } @@ -8914,18 +8914,18 @@ R_API ut8 *r_bin_java_cp_get_bytes(ut8 tag, ut32 *out_sz, const ut8 *buf, const switch (tag) { case R_BIN_JAVA_CP_INTEGER: case R_BIN_JAVA_CP_FLOAT: - return r_bin_java_cp_get_4bytes (tag, out_sz, buf, len); + return rz_bin_java_cp_get_4bytes (tag, out_sz, buf, len); case R_BIN_JAVA_CP_LONG: case R_BIN_JAVA_CP_DOUBLE: - return r_bin_java_cp_get_8bytes (tag, out_sz, buf, len); + return rz_bin_java_cp_get_8bytes (tag, out_sz, buf, len); case R_BIN_JAVA_CP_UTF8: - return r_bin_java_cp_get_utf8 (tag, out_sz, buf, len); + return rz_bin_java_cp_get_utf8 (tag, out_sz, buf, len); } return NULL; } -R_API ut32 r_bin_java_cp_get_size(RBinJavaObj *bin, ut16 idx) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API ut32 rz_bin_java_cp_get_size(RBinJavaObj *bin, ut16 idx) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); switch (cp_obj->tag) { case R_BIN_JAVA_CP_INTEGER: case R_BIN_JAVA_CP_FLOAT: @@ -8939,30 +8939,30 @@ R_API ut32 r_bin_java_cp_get_size(RBinJavaObj *bin, ut16 idx) { return 0; } -R_API ut64 r_bin_java_get_method_start(RBinJavaObj *bin, RBinJavaField *fm_type) { - return r_bin_java_get_method_code_offset (fm_type) + bin->loadaddr; +RZ_API ut64 rz_bin_java_get_method_start(RBinJavaObj *bin, RBinJavaField *fm_type) { + return rz_bin_java_get_method_code_offset (fm_type) + bin->loadaddr; } -R_API ut64 r_bin_java_get_method_end(RBinJavaObj *bin, RBinJavaField *fm_type) { - return r_bin_java_get_method_code_offset (fm_type) + bin->loadaddr + - +r_bin_java_get_method_code_size (fm_type); +RZ_API ut64 rz_bin_java_get_method_end(RBinJavaObj *bin, RBinJavaField *fm_type) { + return rz_bin_java_get_method_code_offset (fm_type) + bin->loadaddr + + +rz_bin_java_get_method_code_size (fm_type); } -R_API ut8 *U(r_bin_java_cp_append_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { - return r_bin_java_cp_get_fref_bytes (bin, out_sz, R_BIN_JAVA_CP_METHODREF, cn_idx, fn_idx, ft_idx); +RZ_API ut8 *U(rz_bin_java_cp_append_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { + return rz_bin_java_cp_get_fref_bytes (bin, out_sz, R_BIN_JAVA_CP_METHODREF, cn_idx, fn_idx, ft_idx); } -R_API ut8 *U(r_bin_java_cp_append_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { - return r_bin_java_cp_get_fref_bytes (bin, out_sz, R_BIN_JAVA_CP_FIELDREF, cn_idx, fn_idx, ft_idx); +RZ_API ut8 *U(rz_bin_java_cp_append_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx) { + return rz_bin_java_cp_get_fref_bytes (bin, out_sz, R_BIN_JAVA_CP_FIELDREF, cn_idx, fn_idx, ft_idx); } -R_API char *r_bin_java_unmangle_without_flags(const char *name, const char *descriptor) { - return r_bin_java_unmangle (NULL, name, descriptor); +RZ_API char *rz_bin_java_unmangle_without_flags(const char *name, const char *descriptor) { + return rz_bin_java_unmangle (NULL, name, descriptor); } -R_API void U(r_bin_java_print_stack_map_append_frame_summary)(RBinJavaStackMapFrame * obj) { - RListIter *iter, *iter_tmp; - RList *ptrList; +RZ_API void U(rz_bin_java_print_stack_map_append_frame_summary)(RBinJavaStackMapFrame * obj) { + RzListIter *iter, *iter_tmp; + RzList *ptrList; RBinJavaVerificationObj *ver_obj; Eprintf ("Stack Map Frame Information\n"); Eprintf (" Tag Value = 0x%02x Name: %s\n", obj->tag, ((RBinJavaStackMapFrameMetas *) obj->metas->type_info)->name); @@ -8970,27 +8970,27 @@ R_API void U(r_bin_java_print_stack_map_append_frame_summary)(RBinJavaStackMapFr Eprintf (" Local Variable Count = 0x%04x\n", obj->number_of_locals); Eprintf (" Local Variables:\n"); ptrList = obj->local_items; - r_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { - r_bin_java_print_verification_info_summary (ver_obj); + rz_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { + rz_bin_java_print_verification_info_summary (ver_obj); } Eprintf (" Stack Items Count = 0x%04x\n", obj->number_of_stack_items); Eprintf (" Stack Items:\n"); ptrList = obj->stack_items; - r_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { - r_bin_java_print_verification_info_summary (ver_obj); + rz_list_foreach_safe (ptrList, iter, iter_tmp, ver_obj) { + rz_bin_java_print_verification_info_summary (ver_obj); } } -R_API void U(r_bin_java_stack_frame_default_free)(void *s) { +RZ_API void U(rz_bin_java_stack_frame_default_free)(void *s) { RBinJavaStackMapFrame *stack_frame = s; if (stack_frame) { free (stack_frame->metas); free (stack_frame); } } -R_API void U(r_bin_java_stack_frame_do_nothing_free)(void /*RBinJavaStackMapFrame*/ *stack_frame) {} -R_API void U(r_bin_java_stack_frame_do_nothing_new)(RBinJavaObj * bin, RBinJavaStackMapFrame * stack_frame, ut64 offset) {} -R_API RBinJavaCPTypeMetas *U(r_bin_java_get_cp_meta_from_tag)(ut8 tag) { +RZ_API void U(rz_bin_java_stack_frame_do_nothing_free)(void /*RBinJavaStackMapFrame*/ *stack_frame) {} +RZ_API void U(rz_bin_java_stack_frame_do_nothing_new)(RBinJavaObj * bin, RBinJavaStackMapFrame * stack_frame, ut64 offset) {} +RZ_API RBinJavaCPTypeMetas *U(rz_bin_java_get_cp_meta_from_tag)(ut8 tag) { ut16 i = 0; // set default to unknown. RBinJavaCPTypeMetas *res = &R_BIN_JAVA_CP_METAS[2]; @@ -9003,29 +9003,29 @@ R_API RBinJavaCPTypeMetas *U(r_bin_java_get_cp_meta_from_tag)(ut8 tag) { return res; } -R_API ut8 *U(r_bin_java_cp_append_ref_cname_fname_ftype)(RBinJavaObj * bin, ut32 * out_sz, ut8 tag, const char *cname, const ut32 c_len, const char *fname, const ut32 f_len, const char *tname, const ut32 t_len) { +RZ_API ut8 *U(rz_bin_java_cp_append_ref_cname_fname_ftype)(RBinJavaObj * bin, ut32 * out_sz, ut8 tag, const char *cname, const ut32 c_len, const char *fname, const ut32 f_len, const char *tname, const ut32 t_len) { ut32 cn_len = 0, fn_len = 0, ft_len = 0, total_len; ut16 cn_idx = 0, fn_idx = 0, ft_idx = 0; ut8 *bytes = NULL, *cn_bytes = NULL, *fn_bytes = NULL, *ft_bytes = NULL, *cref_bytes = NULL, *fref_bytes = NULL, *fnt_bytes = NULL; *out_sz = 0; - cn_bytes = r_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &cn_len, (const ut8 *) cname, c_len); + cn_bytes = rz_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &cn_len, (const ut8 *) cname, c_len); cn_idx = bin->cp_idx + 1; if (cn_bytes) { - fn_bytes = r_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &fn_len, (const ut8 *) fname, f_len); + fn_bytes = rz_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &fn_len, (const ut8 *) fname, f_len); fn_idx = bin->cp_idx + 2; } if (fn_bytes) { - ft_bytes = r_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &ft_len, (const ut8 *) tname, t_len); + ft_bytes = rz_bin_java_cp_get_utf8 (R_BIN_JAVA_CP_UTF8, &ft_len, (const ut8 *) tname, t_len); ft_idx = bin->cp_idx + 3; } if (cn_bytes && fn_bytes && ft_bytes) { ut32 cref_len = 0, fnt_len = 0, fref_len = 0; ut32 cref_idx = 0, fnt_idx = 0; - cref_bytes = r_bin_java_cp_get_classref (bin, &cref_len, NULL, 0, cn_idx); + cref_bytes = rz_bin_java_cp_get_classref (bin, &cref_len, NULL, 0, cn_idx); cref_idx = bin->cp_idx + 3; - fnt_bytes = r_bin_java_cp_get_name_type (bin, &fnt_len, fn_idx, ft_idx); + fnt_bytes = rz_bin_java_cp_get_name_type (bin, &fnt_len, fn_idx, ft_idx); fnt_idx = bin->cp_idx + 4; - fref_bytes = r_bin_java_cp_get_2_ut16 (bin, &fref_len, tag, cref_idx, fnt_idx); + fref_bytes = rz_bin_java_cp_get_2_ut16 (bin, &fref_len, tag, cref_idx, fnt_idx); if (cref_bytes && fref_bytes && fnt_bytes) { total_len = cn_len + fn_len + ft_len + cref_len + fnt_len + fref_len + 2; if (total_len < cn_len) { @@ -9079,37 +9079,37 @@ beach: free (cref_bytes); return bytes; } -R_API ut8 *U(r_bin_java_cp_get_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx) { - return r_bin_java_cp_get_fm_ref (bin, out_sz, R_BIN_JAVA_CP_METHODREF, class_idx, name_and_type_idx); +RZ_API ut8 *U(rz_bin_java_cp_get_method_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx) { + return rz_bin_java_cp_get_fm_ref (bin, out_sz, R_BIN_JAVA_CP_METHODREF, class_idx, name_and_type_idx); } -R_API ut8 *U(r_bin_java_cp_get_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx) { - return r_bin_java_cp_get_fm_ref (bin, out_sz, R_BIN_JAVA_CP_FIELDREF, class_idx, name_and_type_idx); +RZ_API ut8 *U(rz_bin_java_cp_get_field_ref)(RBinJavaObj * bin, ut32 * out_sz, ut16 class_idx, ut16 name_and_type_idx) { + return rz_bin_java_cp_get_fm_ref (bin, out_sz, R_BIN_JAVA_CP_FIELDREF, class_idx, name_and_type_idx); } -R_API void U(deinit_java_type_null)(void) { +RZ_API void U(deinit_java_type_null)(void) { free (R_BIN_JAVA_NULL_TYPE.metas); } -R_API RBinJavaCPTypeObj *r_bin_java_get_item_from_cp(RBinJavaObj *bin, int i) { +RZ_API RBinJavaCPTypeObj *rz_bin_java_get_item_from_cp(RBinJavaObj *bin, int i) { if (i < 1 || i > bin->cf.cp_count) { return &R_BIN_JAVA_NULL_TYPE; } - RBinJavaCPTypeObj *obj = (RBinJavaCPTypeObj *) r_list_get_n (bin->cp_list, i); + RBinJavaCPTypeObj *obj = (RBinJavaCPTypeObj *) rz_list_get_n (bin->cp_list, i); return obj ? obj : &R_BIN_JAVA_NULL_TYPE; } -R_API void U(copy_type_info_to_stack_frame_list)(RList * type_list, RList * sf_list) { - RListIter *iter, *iter_tmp; +RZ_API void U(copy_type_info_to_stack_frame_list)(RzList * type_list, RzList * sf_list) { + RzListIter *iter, *iter_tmp; RBinJavaVerificationObj *ver_obj, *new_ver_obj; if (!type_list || !sf_list) { return; } - r_list_foreach_safe (type_list, iter, iter_tmp, ver_obj) { + rz_list_foreach_safe (type_list, iter, iter_tmp, ver_obj) { new_ver_obj = (RBinJavaVerificationObj *) malloc (sizeof (RBinJavaVerificationObj)); // FIXME: how to handle failed memory allocation? if (new_ver_obj && ver_obj) { memcpy (new_ver_obj, ver_obj, sizeof (RBinJavaVerificationObj)); - if (!r_list_append (sf_list, (void *) new_ver_obj)) { + if (!rz_list_append (sf_list, (void *) new_ver_obj)) { R_FREE (new_ver_obj); } } else { @@ -9118,19 +9118,19 @@ R_API void U(copy_type_info_to_stack_frame_list)(RList * type_list, RList * sf_l } } -R_API void U(copy_type_info_to_stack_frame_list_up_to_idx)(RList * type_list, RList * sf_list, ut64 idx) { - RListIter *iter, *iter_tmp; +RZ_API void U(copy_type_info_to_stack_frame_list_up_to_idx)(RzList * type_list, RzList * sf_list, ut64 idx) { + RzListIter *iter, *iter_tmp; RBinJavaVerificationObj *ver_obj, *new_ver_obj; ut32 pos = 0; if (!type_list || !sf_list) { return; } - r_list_foreach_safe (type_list, iter, iter_tmp, ver_obj) { + rz_list_foreach_safe (type_list, iter, iter_tmp, ver_obj) { new_ver_obj = (RBinJavaVerificationObj *) malloc (sizeof (RBinJavaVerificationObj)); // FIXME: how to handle failed memory allocation? if (new_ver_obj && ver_obj) { memcpy (new_ver_obj, ver_obj, sizeof (RBinJavaVerificationObj)); - if (!r_list_append (sf_list, (void *) new_ver_obj)) { + if (!rz_list_append (sf_list, (void *) new_ver_obj)) { R_FREE (new_ver_obj); } } else { @@ -9143,8 +9143,8 @@ R_API void U(copy_type_info_to_stack_frame_list_up_to_idx)(RList * type_list, RL } } -R_API ut8 *r_bin_java_cp_get_idx_bytes(RBinJavaObj *bin, ut16 idx, ut32 *out_sz) { - RBinJavaCPTypeObj *cp_obj = r_bin_java_get_item_from_bin_cp_list (bin, idx); +RZ_API ut8 *rz_bin_java_cp_get_idx_bytes(RBinJavaObj *bin, ut16 idx, ut32 *out_sz) { + RBinJavaCPTypeObj *cp_obj = rz_bin_java_get_item_from_bin_cp_list (bin, idx); if (!cp_obj || !out_sz) { return NULL; } @@ -9154,35 +9154,35 @@ R_API ut8 *r_bin_java_cp_get_idx_bytes(RBinJavaObj *bin, ut16 idx, ut32 *out_sz) switch (cp_obj->tag) { case R_BIN_JAVA_CP_INTEGER: case R_BIN_JAVA_CP_FLOAT: - return r_bin_java_cp_get_4bytes (cp_obj->tag, out_sz, cp_obj->info.cp_integer.bytes.raw, 5); + return rz_bin_java_cp_get_4bytes (cp_obj->tag, out_sz, cp_obj->info.cp_integer.bytes.raw, 5); case R_BIN_JAVA_CP_LONG: case R_BIN_JAVA_CP_DOUBLE: - return r_bin_java_cp_get_4bytes (cp_obj->tag, out_sz, cp_obj->info.cp_long.bytes.raw, 9); + return rz_bin_java_cp_get_4bytes (cp_obj->tag, out_sz, cp_obj->info.cp_long.bytes.raw, 9); case R_BIN_JAVA_CP_UTF8: // eprintf ("Getting idx: %d = %p (3+0x%"PFMT64x")\n", idx, cp_obj, cp_obj->info.cp_utf8.length); if (cp_obj->info.cp_utf8.length > 0) { - return r_bin_java_cp_get_utf8 (cp_obj->tag, out_sz, + return rz_bin_java_cp_get_utf8 (cp_obj->tag, out_sz, cp_obj->info.cp_utf8.bytes, cp_obj->info.cp_utf8.length); } } return NULL; } -R_API int r_bin_java_valid_class(const ut8 *buf, ut64 buf_sz) { +RZ_API int rz_bin_java_valid_class(const ut8 *buf, ut64 buf_sz) { RBinJavaObj *bin = R_NEW0 (RBinJavaObj), *cur_bin = R_BIN_JAVA_GLOBAL_BIN; if (!bin) { return false; } - int res = r_bin_java_load_bin (bin, buf, buf_sz); + int res = rz_bin_java_load_bin (bin, buf, buf_sz); if (bin->calc_size == buf_sz) { res = true; } - r_bin_java_free (bin); + rz_bin_java_free (bin); R_BIN_JAVA_GLOBAL_BIN = cur_bin; return res; } -R_API ut64 r_bin_java_calc_class_size(ut8 *bytes, ut64 size) { +RZ_API ut64 rz_bin_java_calc_class_size(ut8 *bytes, ut64 size) { RBinJavaObj *bin = R_NEW0 (RBinJavaObj); if (!bin) { return false; @@ -9190,19 +9190,19 @@ R_API ut64 r_bin_java_calc_class_size(ut8 *bytes, ut64 size) { RBinJavaObj *cur_bin = R_BIN_JAVA_GLOBAL_BIN; ut64 bin_size = UT64_MAX; if (bin) { - if (r_bin_java_load_bin (bin, bytes, size)) { + if (rz_bin_java_load_bin (bin, bytes, size)) { bin_size = bin->calc_size; } - r_bin_java_free (bin); + rz_bin_java_free (bin); R_BIN_JAVA_GLOBAL_BIN = cur_bin; } return bin_size; } -R_API int U(r_bin_java_get_cp_idx_with_name)(RBinJavaObj * bin_obj, const char *name, ut32 len) { - RListIter *iter; +RZ_API int U(rz_bin_java_get_cp_idx_with_name)(RBinJavaObj * bin_obj, const char *name, ut32 len) { + RzListIter *iter; RBinJavaCPTypeObj *obj; - r_list_foreach (bin_obj->cp_list, iter, obj) { + rz_list_foreach (bin_obj->cp_list, iter, obj) { if (obj->tag == R_BIN_JAVA_CP_UTF8) { if (!strncmp (name, (const char *) obj->info.cp_utf8.bytes, len)) { return obj->metas->ord; @@ -9212,6 +9212,6 @@ R_API int U(r_bin_java_get_cp_idx_with_name)(RBinJavaObj * bin_obj, const char * return 0; } -R_API void r_bin_java_external_printf(PrintfCallback cb) { +RZ_API void rz_bin_java_external_printf(PrintfCallback cb) { Eprintf = cb ? cb : (PrintfCallback) printf; } diff --git a/shlr/java/class.h b/shlr/java/class.h index 2edd59a774..d95fd82c98 100644 --- a/shlr/java/class.h +++ b/shlr/java/class.h @@ -5,17 +5,17 @@ #ifndef _INCLUDE_JAVA_CLASS_H_ #define _INCLUDE_JAVA_CLASS_H_ -#include +#include #undef U #define U(x) x -#include -#include +#include +#include #include #include "dsojson.h" -#if defined(_MSC_VER) && !defined(R_API_BIN_ONLY) -#undef R_API -#define R_API +#if defined(_MSC_VER) && !defined(RZ_API_BIN_ONLY) +#undef RZ_API +#define RZ_API #endif #define USHORT(x,y) ((ut16)(x[y+1]|(x[y]<<8))) @@ -202,7 +202,7 @@ typedef enum { R_BIN_JAVA_FIELD_TYPE_INTERFACE } R_BIN_JAVA_FIELD_TYPE; -typedef struct r_bin_java_meta{ +typedef struct rz_bin_java_meta{ ut64 file_offset; void *type_info; ut32 ord; @@ -210,49 +210,49 @@ typedef struct r_bin_java_meta{ /* Class Reference Informations */ -//struct r_bin_R_BIN_JAVA_CP_ant_t; +//struct rz_bin_R_BIN_JAVA_CP_ant_t; -typedef struct r_bin_java_class_info_t { +typedef struct rz_bin_java_class_info_t { ut16 name_idx; } RBinJavaCPTypeClass; -typedef struct r_bin_java_fieldref_info_t { +typedef struct rz_bin_java_fieldref_info_t { ut16 class_idx; ut16 name_and_type_idx; } RBinJavaCPTypeFieldRef; -typedef struct r_bin_java_methodref_info_t { +typedef struct rz_bin_java_methodref_info_t { ut16 class_idx; ut16 name_and_type_idx; } RBinJavaCPTypeMethodRef; -typedef struct r_bin_java_interfacemethodref_info_t { +typedef struct rz_bin_java_interfacemethodref_info_t { ut16 class_idx; ut16 name_and_type_idx; } RBinJavaCPTypeInterfaceMethodRef; -typedef struct r_bin_java_methodhandle_info_t { +typedef struct rz_bin_java_methodhandle_info_t { ut8 reference_kind; ut16 reference_index; } RBinJavaCPTypeMethodHandle; -typedef struct r_bin_java_methodtype_info_t { +typedef struct rz_bin_java_methodtype_info_t { ut16 descriptor_index; } RBinJavaCPTypeMethodType; -typedef struct r_bin_java_invokedynamic_info_t { +typedef struct rz_bin_java_invokedynamic_info_t { ut16 bootstrap_method_attr_index; ut16 name_and_type_index; } RBinJavaCPTypeInvokeDynamic; /* Primitive Type Informations */ -typedef struct r_bin_java_string_info_t { +typedef struct rz_bin_java_string_info_t { ut16 string_idx; } RBinJavaCPTypeString; -typedef struct r_bin_java_integer_info_t { +typedef struct rz_bin_java_integer_info_t { union { ut8 raw[4]; ut32 dword; @@ -260,7 +260,7 @@ typedef struct r_bin_java_integer_info_t { } RBinJavaCPTypeInteger; -typedef struct r_bin_java_float_info_t { +typedef struct rz_bin_java_float_info_t { union { ut8 raw[4]; ut32 dword; @@ -268,7 +268,7 @@ typedef struct r_bin_java_float_info_t { } RBinJavaCPTypeFloat; -typedef struct r_bin_java_long_info_t { +typedef struct rz_bin_java_long_info_t { union { ut8 raw[8]; ut64 qword; @@ -279,7 +279,7 @@ typedef struct r_bin_java_long_info_t { } bytes; } RBinJavaCPTypeLong; -typedef struct r_bin_java_double_info_t { +typedef struct rz_bin_java_double_info_t { union { ut8 raw[8]; struct{ @@ -292,17 +292,17 @@ typedef struct r_bin_java_double_info_t { /* Meta-data Info */ -typedef struct r_bin_java_name_and_type_info_t { +typedef struct rz_bin_java_name_and_type_info_t { ut16 name_idx; ut16 descriptor_idx; } RBinJavaCPTypeNameAndType; -typedef struct r_bin_java_utf8_info_t { +typedef struct rz_bin_java_utf8_info_t { ut16 length; ut8 *bytes; } RBinJavaCPTypeUtf8; -typedef struct r_bin_java_cp_object_t { +typedef struct rz_bin_java_cp_object_t { RBinJavaMetaInfo *metas; ut64 file_offset; ut8 tag; @@ -330,31 +330,31 @@ typedef struct r_bin_java_cp_object_t { ut16 idx; } RBinJavaCPTypeObj; -typedef struct r_bin_java_stack_map_frame_t { // attribute StackMap +typedef struct rz_bin_java_stack_map_frame_t { // attribute StackMap ut64 file_offset; ut64 size; ut32 code_offset; ut8 tag; ut8 type; - struct r_bin_java_stack_map_frame_t *p_stack_frame; + struct rz_bin_java_stack_map_frame_t *p_stack_frame; RBinJavaMetaInfo *metas; ut32 offset_delta; ut32 number_of_locals; // list of verification objects; - RList* local_items; + RzList* local_items; ut32 number_of_stack_items; // list of verification objects; - RList* stack_items; + RzList* stack_items; } RBinJavaStackMapFrame; -typedef struct r_bin_java_source_debugging_extension_attr_t { +typedef struct rz_bin_java_source_debugging_extension_attr_t { ut8* debug_extension; } RBinJavaSourceDebugExtensionAttr; -typedef struct r_bin_java_enclosing_method_attr_t { +typedef struct rz_bin_java_enclosing_method_attr_t { ut16 class_idx; ut16 method_idx; char *class_name; @@ -362,7 +362,7 @@ typedef struct r_bin_java_enclosing_method_attr_t { char *method_descriptor; } RBinJavaEnclosingMethodAttr; -typedef struct r_bin_java_boot_strap_arg_t{ +typedef struct rz_bin_java_boot_strap_arg_t{ ut64 file_offset; ut64 size; ut16 argument_info_idx; @@ -370,19 +370,19 @@ typedef struct r_bin_java_boot_strap_arg_t{ RBinJavaCPTypeObj *argument_info_cp_obj; } RBinJavaBootStrapArgument; -typedef struct r_bin_java_boot_strap_method_t{ +typedef struct rz_bin_java_boot_strap_method_t{ ut64 file_offset; ut64 size; ut16 bootstrap_method_ref; ut16 num_bootstrap_arguments; // List of RBinJavaCodeAttribute - RList *bootstrap_arguments; + RzList *bootstrap_arguments; } RBinJavaBootStrapMethod; -typedef struct r_bin_java_boot_strap_methods_t{ +typedef struct rz_bin_java_boot_strap_methods_t{ ut16 num_bootstrap_methods; - RList *bootstrap_methods; + RzList *bootstrap_methods; } RBinJavaBootstrapMethodsAttr; @@ -403,19 +403,19 @@ typedef struct { RBinJavaCPTypeObj *class_info_cp_obj; } RBinJavaClassInfoValue; -typedef struct r_bin_java_element_value_ary_t{ +typedef struct rz_bin_java_element_value_ary_t{ ut64 size; ut32 num_values; - RList *values; + RzList *values; } RBinJavaElementValueArray; -typedef struct r_bin_java_annotation_t{ +typedef struct rz_bin_java_annotation_t{ ut64 size; ut16 type_idx; ut16 num_element_value_pairs; - RList *element_value_pairs; + RzList *element_value_pairs; } RBinJavaAnnotation; typedef enum { @@ -438,7 +438,7 @@ typedef enum { R_BIN_JAVA_EV_TAG_UNKNOWN = 0xff, } R_BIN_JAVA_EV_TAG; -typedef struct r_bin_java_element_value_t { +typedef struct rz_bin_java_element_value_t { RBinJavaMetaInfo *metas; ut64 size; ut8 tag; @@ -452,7 +452,7 @@ typedef struct r_bin_java_element_value_t { } value; } RBinJavaElementValue; -typedef struct r_bin_java_element_value_pair_t{ +typedef struct rz_bin_java_element_value_pair_t{ ut64 file_offset; ut64 size; ut16 element_name_idx; @@ -462,41 +462,41 @@ typedef struct r_bin_java_element_value_pair_t{ -typedef struct r_bin_java_annotations_attr_t { +typedef struct rz_bin_java_annotations_attr_t { ut64 size; ut16 num_annotations; - RList *annotations; + RzList *annotations; } RBinJavaAnnotationsArray; typedef RBinJavaAnnotationsArray RBinJavaRuntimeVisibleAnnotationsAttr; typedef RBinJavaAnnotationsArray RBinJavaRuntimeInvisibleAnnotationsAttr; typedef RBinJavaAnnotationsArray RBinJavaRuntimeParameterAnnotationsArray; -typedef struct r_bin_java_parameter_annotation_attr_t { +typedef struct rz_bin_java_parameter_annotation_attr_t { ut8 num_parameters; // RBinJavaRuntimeParameterAnnotationsArray - RList *parameter_annotations; + RzList *parameter_annotations; } RBinJavaRuntimeVisibleParameterAnnotationsAttr; typedef RBinJavaRuntimeVisibleParameterAnnotationsAttr RBinJavaRuntimeInvisibleParameterAnnotationsAttr; -typedef struct r_bin_java_parameter_annotations_attr_t { +typedef struct rz_bin_java_parameter_annotations_attr_t { RBinJavaElementValue *default_value; } RBinJavaAnnotationDefaultAttr; -typedef struct r_bin_java_stack_map_table_attr_t { // attribute StackMap +typedef struct rz_bin_java_stack_map_table_attr_t { // attribute StackMap ut32 code_size; ut32 number_of_entries; - RList* stack_map_frame_entries; + RzList* stack_map_frame_entries; } RBinJavaStackMapTableAttr; -typedef struct r_bin_java_signature_attr_t { +typedef struct rz_bin_java_signature_attr_t { ut16 signature_idx; char *signature; } RBinJavaSignatureAttr; -typedef struct r_bin_java_stack_verification_t{ +typedef struct rz_bin_java_stack_verification_t{ ut64 file_offset; ut64 size; ut8 tag; @@ -507,7 +507,7 @@ typedef struct r_bin_java_stack_verification_t{ } info; } RBinJavaVerificationObj; -typedef struct r_bin_java_fm_t { +typedef struct rz_bin_java_fm_t { RBinJavaMetaInfo *metas; ut64 size; char *name; @@ -524,11 +524,11 @@ typedef struct r_bin_java_fm_t { RBinJavaCPTypeObj *field_ref_cp_obj; ut64 attr_offset; ut16 attr_count; - RList *attributes; + RzList *attributes; ut64 method_number; } RBinJavaField; -typedef struct r_bin_java_interface_info_desc_t{ +typedef struct rz_bin_java_interface_info_desc_t{ char *name; ut64 size; ut64 file_offset; @@ -536,16 +536,16 @@ typedef struct r_bin_java_interface_info_desc_t{ RBinJavaCPTypeObj *cp_class; } RBinJavaInterfaceInfo; -typedef struct r_bin_java_attr_constant_t { +typedef struct rz_bin_java_attr_constant_t { ut16 constantvalue_idx; } RBinJavaConstantValueAttr; -typedef struct r_bin_java_attr_exceptions_t { +typedef struct rz_bin_java_attr_exceptions_t { ut16 number_of_exceptions; ut16* exception_idx_table; } RBinJavaExceptionsAttr; -typedef struct r_bin_java_attr_exception_table_entry_t { +typedef struct rz_bin_java_attr_exception_table_entry_t { ut64 file_offset; ut16 start_pc; ut16 end_pc; @@ -554,7 +554,7 @@ typedef struct r_bin_java_attr_exception_table_entry_t { ut64 size; } RBinJavaExceptionEntry; -typedef struct r_bin_java_attr_code_t { +typedef struct rz_bin_java_attr_code_t { ut64 file_offset; ut32 code_offset; ut16 max_stack; @@ -563,36 +563,36 @@ typedef struct r_bin_java_attr_code_t { ut8 *code; ut32 exception_table_length; - RList *exception_table; // RBinJavaExceptionTableEntry * + RzList *exception_table; // RBinJavaExceptionTableEntry * ut16 attributes_count; - RList *attributes; + RzList *attributes; RBinJavaStackMapFrame *implicit_frame; } RBinJavaCodeAttr; -typedef struct r_bin_java_attr_inner_classes_t { +typedef struct rz_bin_java_attr_inner_classes_t { ut16 number_of_classes; - RList* classes; + RzList* classes; } RBinJavaInnerClassesAttribute; -typedef struct r_bin_java_attr_source_file_t{ +typedef struct rz_bin_java_attr_source_file_t{ ut16 sourcefile_idx; } RBinJavaSourceFileAttribute; -typedef struct r_bin_java_line_number_table_t{ +typedef struct rz_bin_java_line_number_table_t{ ut64 file_offset; ut16 start_pc; ut16 line_number; ut64 size; } RBinJavaLineNumberAttribute; -typedef struct r_bin_java_attr_linenum_t { +typedef struct rz_bin_java_attr_linenum_t { ut64 file_offset; ut16 line_number_table_length; - RList* line_number_table; // RBinJavaLineNumberTable* + RzList* line_number_table; // RBinJavaLineNumberTable* } RBinJavaLineNumberTableAttribute; -typedef struct r_bin_java_attr_localvariabletype_t{ +typedef struct rz_bin_java_attr_localvariabletype_t{ char *name; char *signature; @@ -605,12 +605,12 @@ typedef struct r_bin_java_attr_localvariabletype_t{ ut64 size; } RBinJavaLocalVariableTypeAttribute; -typedef struct r_bin_java_attr_localvariable_type_table_t { +typedef struct rz_bin_java_attr_localvariable_type_table_t { ut16 table_length; - RList* local_variable_table; // RBinJavaLocalVariable + RzList* local_variable_table; // RBinJavaLocalVariable } RBinJavaLocalVariableTypeTableAttribute; -typedef struct r_bin_java_attr_localvariable_t{ +typedef struct rz_bin_java_attr_localvariable_t{ char *name; char *descriptor; @@ -624,12 +624,12 @@ typedef struct r_bin_java_attr_localvariable_t{ } RBinJavaLocalVariableAttribute; -typedef struct r_bin_java_attr_localvariable_table_t { +typedef struct rz_bin_java_attr_localvariable_table_t { ut16 table_length; - RList* local_variable_table; // RBinJavaLocalVariable + RzList* local_variable_table; // RBinJavaLocalVariable } RBinJavaLocalVariableTableAttribute; -typedef struct r_bin_java_attr_t { +typedef struct rz_bin_java_attr_t { ut8 *bytes; ut64 pos; ut64 size; @@ -668,7 +668,7 @@ typedef struct r_bin_java_attr_t { } RBinJavaAttrInfo; -typedef struct r_bin_java_attr_classes_t { +typedef struct rz_bin_java_attr_classes_t { char *name; char *flags_str; ut64 file_offset; @@ -681,14 +681,14 @@ typedef struct r_bin_java_attr_classes_t { ut64 size; } RBinJavaClassesAttribute; -typedef struct r_bin_java_classfile_t { +typedef struct rz_bin_java_classfile_t { ut8 cafebabe[4]; ut8 minor[2]; ut8 major[2]; ut16 cp_count; } RBinJavaClass; -typedef struct r_bin_java_classfile2_t { +typedef struct rz_bin_java_classfile2_t { ut16 access_flags; char *flags_str; char *this_class_name; @@ -699,14 +699,14 @@ typedef struct r_bin_java_classfile2_t { RBinJavaAttrInfo *this_class_entrypoint_code_attr; } RBinJavaClass2; -typedef struct r_bin_java_lines_t { +typedef struct rz_bin_java_lines_t { int count; int *addr; int *line; } RBinJavaLines; -typedef struct r_bin_java_obj_t { - struct r_bin_java_classfile_t cf; +typedef struct rz_bin_java_obj_t { + struct rz_bin_java_classfile_t cf; RBinJavaClass2 cf2; const char *lang; @@ -752,16 +752,16 @@ typedef struct r_bin_java_obj_t { RBinJavaField *entrypoint; RBinJavaAttrInfo *entrypoint_code_attr; - //RList* classes_list; // TODO: Not sure if this is necessary. it would be the inner classes info. - RList* fields_list; - RList* methods_list; - RList* cp_list; - RList* interfaces_list; - RList* attrs_list; - RList* imports_list; + //RzList* classes_list; // TODO: Not sure if this is necessary. it would be the inner classes info. + RzList* fields_list; + RzList* methods_list; + RzList* cp_list; + RzList* interfaces_list; + RzList* attrs_list; + RzList* imports_list; - RList* functions; - RList* disassembly; + RzList* functions; + RzList* disassembly; Sdb *kv; Sdb *AllJavaBinObjs; @@ -770,26 +770,26 @@ typedef struct r_bin_java_obj_t { RStrConstPool constpool; } RBinJavaObj; -R_API RList * U(r_bin_java_get_interface_names)(RBinJavaObj * bin); -R_API RBinJavaCPTypeObj* U(r_bin_java_get_item_from_cp)(RBinJavaObj *bin, int i); -R_API RBinJavaCPTypeObj* r_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API ut8 * r_bin_java_cp_get_idx_bytes(RBinJavaObj *bin, ut16 idx, ut32 *out_sz); -R_API RList * r_bin_java_get_lib_names(RBinJavaObj * bin); -R_API RList* r_bin_java_get_sections(RBinJavaObj *bin); -R_API RList* r_bin_java_get_fields(RBinJavaObj *bin); -R_API char* r_bin_java_get_version(RBinJavaObj* bin); -R_API RBinAddr * r_bin_java_get_entrypoint(RBinJavaObj* bin, int sym); -R_API RList* r_bin_java_get_entrypoints(RBinJavaObj* bin); -R_API ut64 r_bin_java_get_main(RBinJavaObj* bin); -R_API RList* r_bin_java_get_symbols(RBinJavaObj* bin); -R_API RList* r_bin_java_get_strings(RBinJavaObj* bin); -R_API void* r_bin_java_free(RBinJavaObj* bin); -R_API RBinJavaObj* r_bin_java_new(const char* file, ut64 baddr, Sdb * kv); -R_API RBinJavaObj* r_bin_java_new_buf(RBuffer* buf, ut64 baddr, Sdb * kv); -R_API int r_bin_java_valid_class(const ut8 *buf, ut64 buf_sz); +RZ_API RzList * U(rz_bin_java_get_interface_names)(RBinJavaObj * bin); +RZ_API RBinJavaCPTypeObj* U(rz_bin_java_get_item_from_cp)(RBinJavaObj *bin, int i); +RZ_API RBinJavaCPTypeObj* rz_bin_java_get_item_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API ut8 * rz_bin_java_cp_get_idx_bytes(RBinJavaObj *bin, ut16 idx, ut32 *out_sz); +RZ_API RzList * rz_bin_java_get_lib_names(RBinJavaObj * bin); +RZ_API RzList* rz_bin_java_get_sections(RBinJavaObj *bin); +RZ_API RzList* rz_bin_java_get_fields(RBinJavaObj *bin); +RZ_API char* rz_bin_java_get_version(RBinJavaObj* bin); +RZ_API RBinAddr * rz_bin_java_get_entrypoint(RBinJavaObj* bin, int sym); +RZ_API RzList* rz_bin_java_get_entrypoints(RBinJavaObj* bin); +RZ_API ut64 rz_bin_java_get_main(RBinJavaObj* bin); +RZ_API RzList* rz_bin_java_get_symbols(RBinJavaObj* bin); +RZ_API RzList* rz_bin_java_get_strings(RBinJavaObj* bin); +RZ_API void* rz_bin_java_free(RBinJavaObj* bin); +RZ_API RBinJavaObj* rz_bin_java_new(const char* file, ut64 baddr, Sdb * kv); +RZ_API RBinJavaObj* rz_bin_java_new_buf(RBuffer* buf, ut64 baddr, Sdb * kv); +RZ_API int rz_bin_java_valid_class(const ut8 *buf, ut64 buf_sz); // Stuff used to manage Java Class File Constant Information -typedef struct r_bin_java_object_allocs_t { +typedef struct rz_bin_java_object_allocs_t { RBinJavaCPTypeObj *(*new_obj) (RBinJavaObj *bin, ut8* buffer, ut64 offset) ; void (*delete_obj) (void /*RBinJavaCPTypeObj*/ *obj); void (*print_summary) (RBinJavaCPTypeObj *obj); @@ -797,7 +797,7 @@ typedef struct r_bin_java_object_allocs_t { char* (*stringify_obj) (RBinJavaCPTypeObj *obj); } RBinJavaCPTypeObjectAllocs; -typedef struct r_bin_java_attr_allocs_t { +typedef struct rz_bin_java_attr_allocs_t { //void (*new_obj) (RBinJavaObj *bin, RBinJavaAttrInfo *obj, ut64 offset) ; RBinJavaAttrInfo* (*new_obj)(RBinJavaObj *bin, ut8* buffer, ut64 sz, ut64 buf_offset); void (*delete_obj) (void /*RBinJavaAttrInfo*/ *obj); @@ -805,13 +805,13 @@ typedef struct r_bin_java_attr_allocs_t { ut64 (*calc_size)(RBinJavaAttrInfo *obj); } RBinJavaAttrInfoObjectAllocs; -typedef struct r_bin_java_ver_allocs_t { +typedef struct rz_bin_java_ver_allocs_t { void (*new_obj) (RBinJavaObj *bin, ut32 code_length, ut64 offset) ; void (*delete_obj) (void /*RBinJavaAttrInfo*/ *obj); void (*print_summary) (RBinJavaAttrInfo *obj); } RBinJavaVerInfoObjectAllocs; -typedef struct r_bin_java_stack_frame_allocs_t { +typedef struct rz_bin_java_stack_frame_allocs_t { RBinJavaStackMapFrame* (*new_obj) (RBinJavaObj *bin, ut64 offset) ; void (*delete_obj) (void /* RBinJavaStackMapFrame*/ *obj); void (*print_summary) (RBinJavaStackMapFrame *obj); @@ -823,25 +823,25 @@ typedef struct { void (*print_summary) (RBinJavaElementValue *obj); } RBinJavaElementValueObjectAllocs; -typedef struct r_bin_R_BIN_JAVA_CP_ant_meta_t { +typedef struct rz_bin_R_BIN_JAVA_CP_ant_meta_t { char *name; ut8 tag; ut32 len; RBinJavaCPTypeObjectAllocs *allocs; } RBinJavaCPTypeMetas; -typedef struct r_bin_java_attr_meta_t { +typedef struct rz_bin_java_attr_meta_t { char *name; ut8 type; RBinJavaAttrInfoObjectAllocs *allocs; } RBinJavaAttrMetas; -typedef struct r_bin_java_ver_meta_t { +typedef struct rz_bin_java_ver_meta_t { char *name; ut8 type; } RBinJavaVerificationMetas; -typedef struct r_bin_java_stack_frame_meta_t { +typedef struct rz_bin_java_stack_frame_meta_t { char *name; ut8 type; RBinJavaStackMapFrameObjectAllocs *allocs; @@ -890,180 +890,180 @@ typedef struct java_const_value_t { } value; } ConstJavaValue; -R_API ut8* r_bin_java_get_attr_buf(RBinJavaObj *bin, ut64 sz, const ut64 offset, const ut8 *buf, const ut64 len); -R_API char* r_bin_java_get_name_from_cp_item_list(RList *cp_list, ut64 idx); -R_API char* r_bin_java_get_utf8_from_cp_item_list(RList *cp_list, ut64 idx); -R_API ut32 r_bin_java_get_utf8_len_from_cp_item_list(RList *cp_list, ut64 idx); -R_API char* r_bin_java_get_desc_from_cp_item_list(RList *cp_list, ut64 idx); -R_API char* r_bin_java_get_item_name_from_cp_item_list(RList *cp_list, RBinJavaCPTypeObj *obj, int depth); -R_API char* r_bin_java_get_item_desc_from_cp_item_list(RList *cp_list, RBinJavaCPTypeObj *obj, int depth); +RZ_API ut8* rz_bin_java_get_attr_buf(RBinJavaObj *bin, ut64 sz, const ut64 offset, const ut8 *buf, const ut64 len); +RZ_API char* rz_bin_java_get_name_from_cp_item_list(RzList *cp_list, ut64 idx); +RZ_API char* rz_bin_java_get_utf8_from_cp_item_list(RzList *cp_list, ut64 idx); +RZ_API ut32 rz_bin_java_get_utf8_len_from_cp_item_list(RzList *cp_list, ut64 idx); +RZ_API char* rz_bin_java_get_desc_from_cp_item_list(RzList *cp_list, ut64 idx); +RZ_API char* rz_bin_java_get_item_name_from_cp_item_list(RzList *cp_list, RBinJavaCPTypeObj *obj, int depth); +RZ_API char* rz_bin_java_get_item_desc_from_cp_item_list(RzList *cp_list, RBinJavaCPTypeObj *obj, int depth); -R_API char* r_bin_java_get_name_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API char* r_bin_java_get_utf8_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API ut32 r_bin_java_get_utf8_len_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API char* r_bin_java_get_desc_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); -R_API char* r_bin_java_get_item_name_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj); -R_API char* r_bin_java_get_item_desc_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj); +RZ_API char* rz_bin_java_get_name_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API char* rz_bin_java_get_utf8_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API ut32 rz_bin_java_get_utf8_len_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API char* rz_bin_java_get_desc_from_bin_cp_list(RBinJavaObj *bin, ut64 idx); +RZ_API char* rz_bin_java_get_item_name_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj); +RZ_API char* rz_bin_java_get_item_desc_from_bin_cp_list(RBinJavaObj *bin, RBinJavaCPTypeObj *obj); // free bin lists -R_API char * r_bin_java_print_utf8_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_name_and_type_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_float_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_integer_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_string_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_classref_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_fieldref_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_methodref_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_interfacemethodref_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_unknown_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_null_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_methodtype_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_invokedynamic_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_methodhandle_cp_stringify(RBinJavaCPTypeObj* obj); -R_API char * r_bin_java_print_class_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_utf8_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_name_and_type_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_double_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_long_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_float_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_integer_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_string_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_classref_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_fieldref_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_methodref_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_interfacemethodref_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_unknown_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_null_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_methodtype_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_invokedynamic_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_methodhandle_cp_stringify(RBinJavaCPTypeObj* obj); +RZ_API char * rz_bin_java_print_class_cp_stringify(RBinJavaCPTypeObj* obj); -R_API RBinSymbol* r_bin_java_create_new_symbol_from_field_with_access_flags(RBinJavaField *fm_type); -R_API RBinSymbol* r_bin_java_create_new_symbol_from_cp_idx(ut32 cp_idx, ut64 baddr); -R_API RBinSymbol* r_bin_java_create_new_symbol_from_invoke_dynamic(RBinJavaCPTypeObj *obj, ut64 baddr); -R_API RBinSymbol* r_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, ut64 baddr); -R_API RBinSymbol* r_bin_java_create_new_symbol_from_method(RBinJavaField *fm_type); +RZ_API RBinSymbol* rz_bin_java_create_new_symbol_from_field_with_access_flags(RBinJavaField *fm_type); +RZ_API RBinSymbol* rz_bin_java_create_new_symbol_from_cp_idx(ut32 cp_idx, ut64 baddr); +RZ_API RBinSymbol* rz_bin_java_create_new_symbol_from_invoke_dynamic(RBinJavaCPTypeObj *obj, ut64 baddr); +RZ_API RBinSymbol* rz_bin_java_create_new_symbol_from_ref(RBinJavaObj *bin, RBinJavaCPTypeObj *obj, ut64 baddr); +RZ_API RBinSymbol* rz_bin_java_create_new_symbol_from_method(RBinJavaField *fm_type); -R_API ut64 r_bin_java_get_method_code_offset(RBinJavaField *fm_type); -R_API ut64 r_bin_java_get_method_code_size(RBinJavaField *fm_type); -R_API ut64 r_bin_java_get_class_entrypoint(RBinJavaObj* bin); +RZ_API ut64 rz_bin_java_get_method_code_offset(RBinJavaField *fm_type); +RZ_API ut64 rz_bin_java_get_method_code_size(RBinJavaField *fm_type); +RZ_API ut64 rz_bin_java_get_class_entrypoint(RBinJavaObj* bin); -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_ref_info(RBinJavaObj *bin, ut16 name_and_typeidx); -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_ref_info_from_name_and_type(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx); -R_API RBinJavaCPTypeObj *r_bin_java_find_cp_name_and_type_info(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_ref_info(RBinJavaObj *bin, ut16 name_and_typeidx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_ref_info_from_name_and_type(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx); +RZ_API RBinJavaCPTypeObj *rz_bin_java_find_cp_name_and_type_info(RBinJavaObj *bin, ut16 name_idx, ut16 descriptor_idx); -R_API RBinClass* r_bin_java_allocate_r_bin_class(void); -R_API RList *r_bin_java_get_classes(RBinJavaObj *bin); -R_API RList *r_bin_java_enum_class_methods(RBinJavaObj *bin, ut16 class_idx); -R_API RList *r_bin_java_enum_class_fields(RBinJavaObj *bin, ut16 class_idx); -R_API ut64 r_bin_java_find_method_offset(RBinJavaObj *bin, const char* method_name); +RZ_API RBinClass* rz_bin_java_allocate_r_bin_class(void); +RZ_API RzList *rz_bin_java_get_classes(RBinJavaObj *bin); +RZ_API RzList *rz_bin_java_enum_class_methods(RBinJavaObj *bin, ut16 class_idx); +RZ_API RzList *rz_bin_java_enum_class_fields(RBinJavaObj *bin, ut16 class_idx); +RZ_API ut64 rz_bin_java_find_method_offset(RBinJavaObj *bin, const char* method_name); -R_API RBinJavaField * r_bin_java_get_method_code_attribute_with_addr(RBinJavaObj *bin, ut64 addr); -R_API RList * r_bin_java_get_method_exception_table_with_addr(RBinJavaObj *bin, ut64 addr); +RZ_API RBinJavaField * rz_bin_java_get_method_code_attribute_with_addr(RBinJavaObj *bin, ut64 addr); +RZ_API RzList * rz_bin_java_get_method_exception_table_with_addr(RBinJavaObj *bin, ut64 addr); -R_API const RList* r_bin_java_get_methods_list(RBinJavaObj* bin); -R_API const RBinJavaObj* r_bin_java_get_bin_obj(const char *name); -R_API int r_bin_java_update_file (const char *key, RBinJavaObj *bin_obj); -R_API RBinJavaObj * r_bin_java_get_sdb_bin_obj(const char * filename); -R_API RList * r_bin_java_get_bin_obj_list(void); -R_API RList* r_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj); -R_API char * r_bin_java_get_this_class_name(RBinJavaObj *bin_obj); -R_API char * r_bin_java_build_obj_key (RBinJavaObj *bin); +RZ_API const RzList* rz_bin_java_get_methods_list(RBinJavaObj* bin); +RZ_API const RBinJavaObj* rz_bin_java_get_bin_obj(const char *name); +RZ_API int rz_bin_java_update_file (const char *key, RBinJavaObj *bin_obj); +RZ_API RBinJavaObj * rz_bin_java_get_sdb_bin_obj(const char * filename); +RZ_API RzList * rz_bin_java_get_bin_obj_list(void); +RZ_API RzList* rz_bin_java_get_bin_obj_list_thru_obj(RBinJavaObj *bin_obj); +RZ_API char * rz_bin_java_get_this_class_name(RBinJavaObj *bin_obj); +RZ_API char * rz_bin_java_build_obj_key (RBinJavaObj *bin); -R_API RList * r_bin_java_extract_type_values(const char *arg_str); -R_API int r_bin_java_extract_reference_name(const char * input_str, char ** ref_str, ut8 array_cnt); -R_API RList * r_bin_java_extract_all_bin_type_values( RBinJavaObj * bin_obj); +RZ_API RzList * rz_bin_java_extract_type_values(const char *arg_str); +RZ_API int rz_bin_java_extract_reference_name(const char * input_str, char ** ref_str, ut8 array_cnt); +RZ_API RzList * rz_bin_java_extract_all_bin_type_values( RBinJavaObj * bin_obj); -R_API RList * r_bin_java_get_method_definitions(RBinJavaObj *bin); -R_API char * r_bin_java_get_method_definition(RBinJavaField *fm_type); -R_API RList * r_bin_java_get_field_definitions(RBinJavaObj *bin); -R_API char * r_bin_java_get_field_definition(RBinJavaField *fm_type); -R_API RList * r_bin_java_get_import_definitions(RBinJavaObj *bin); -R_API RList * r_bin_java_get_field_offsets(RBinJavaObj *bin); -R_API RList * U(r_bin_java_get_method_offsets)(RBinJavaObj *bin); +RZ_API RzList * rz_bin_java_get_method_definitions(RBinJavaObj *bin); +RZ_API char * rz_bin_java_get_method_definition(RBinJavaField *fm_type); +RZ_API RzList * rz_bin_java_get_field_definitions(RBinJavaObj *bin); +RZ_API char * rz_bin_java_get_field_definition(RBinJavaField *fm_type); +RZ_API RzList * rz_bin_java_get_import_definitions(RBinJavaObj *bin); +RZ_API RzList * rz_bin_java_get_field_offsets(RBinJavaObj *bin); +RZ_API RzList * U(rz_bin_java_get_method_offsets)(RBinJavaObj *bin); -R_API ut16 U(r_bin_java_calculate_method_access_value)(const char * access_flags_str); -R_API ut16 U(r_bin_java_calculate_field_access_value)(const char * access_flags_str); -R_API ut16 U(r_bin_java_calculate_class_access_value)(const char * access_flags_str); +RZ_API ut16 U(rz_bin_java_calculate_method_access_value)(const char * access_flags_str); +RZ_API ut16 U(rz_bin_java_calculate_field_access_value)(const char * access_flags_str); +RZ_API ut16 U(rz_bin_java_calculate_class_access_value)(const char * access_flags_str); -R_API RList * U(retrieve_all_method_access_string_and_value)(void); -R_API RList * U(retrieve_all_field_access_string_and_value)(void); -R_API RList * U(retrieve_all_class_access_string_and_value)(void); -R_API char * retrieve_method_access_string(ut16 flags); -R_API char * retrieve_field_access_string(ut16 flags); -R_API char * retrieve_class_method_access_string(ut16 flags); +RZ_API RzList * U(retrieve_all_method_access_string_and_value)(void); +RZ_API RzList * U(retrieve_all_field_access_string_and_value)(void); +RZ_API RzList * U(retrieve_all_class_access_string_and_value)(void); +RZ_API char * retrieve_method_access_string(ut16 flags); +RZ_API char * retrieve_field_access_string(ut16 flags); +RZ_API char * retrieve_class_method_access_string(ut16 flags); -R_API char * U(r_bin_java_resolve)(RBinJavaObj *obj, int idx, ut8 space_bn_name_type); -R_API char * r_bin_java_resolve_with_space(RBinJavaObj *obj, int idx); -R_API char * r_bin_java_resolve_without_space(RBinJavaObj *BIN_OBJ, int idx); -R_API char * U(r_bin_java_resolve_cp_idx_type)(RBinJavaObj *BIN_OBJ, int idx); -R_API char * U(r_bin_java_resolve_b64_encode)(RBinJavaObj *BIN_OBJ, ut16 idx); -R_API ut64 U(r_bin_java_resolve_cp_idx_address)(RBinJavaObj *BIN_OBJ, int idx); -R_API char * U(r_bin_java_resolve_cp_idx_to_string)(RBinJavaObj *BIN_OBJ, int idx); -R_API int U(r_bin_java_resolve_cp_idx_print_summary)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API char * U(rz_bin_java_resolve)(RBinJavaObj *obj, int idx, ut8 space_bn_name_type); +RZ_API char * rz_bin_java_resolve_with_space(RBinJavaObj *obj, int idx); +RZ_API char * rz_bin_java_resolve_without_space(RBinJavaObj *BIN_OBJ, int idx); +RZ_API char * U(rz_bin_java_resolve_cp_idx_type)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API char * U(rz_bin_java_resolve_b64_encode)(RBinJavaObj *BIN_OBJ, ut16 idx); +RZ_API ut64 U(rz_bin_java_resolve_cp_idx_address)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API char * U(rz_bin_java_resolve_cp_idx_to_string)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API int U(rz_bin_java_resolve_cp_idx_print_summary)(RBinJavaObj *BIN_OBJ, int idx); -R_API struct java_const_value_t * U(r_bin_java_resolve_to_const_value)(RBinJavaObj *BIN_OBJ, int idx); -R_API void U(r_bin_java_free_const_value)(struct java_const_value_t * cp_value); +RZ_API struct java_const_value_t * U(rz_bin_java_resolve_to_const_value)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API void U(rz_bin_java_free_const_value)(struct java_const_value_t * cp_value); -R_API char * U(r_bin_java_get_fcn_name) ( RBinJavaField *fm_type); -R_API RList * r_bin_java_get_args ( RBinJavaField *fm_type); -R_API RList * r_bin_java_get_ret ( RBinJavaField *fm_type); +RZ_API char * U(rz_bin_java_get_fcn_name) ( RBinJavaField *fm_type); +RZ_API RzList * rz_bin_java_get_args ( RBinJavaField *fm_type); +RZ_API RzList * rz_bin_java_get_ret ( RBinJavaField *fm_type); -R_API RList * U(r_bin_java_get_args_from_bin)(RBinJavaObj *bin_obj, ut64 addr); -R_API RList * U(r_bin_java_get_ret_from_bin)(RBinJavaObj *bin_obj, ut64 addr); -R_API char * U(r_bin_java_get_fcn_name_from_bin)( RBinJavaObj *bin_obj, ut64 addr); -R_API int U(r_bin_java_is_method_static)(RBinJavaObj *bin_obj, ut64 addr); +RZ_API RzList * U(rz_bin_java_get_args_from_bin)(RBinJavaObj *bin_obj, ut64 addr); +RZ_API RzList * U(rz_bin_java_get_ret_from_bin)(RBinJavaObj *bin_obj, ut64 addr); +RZ_API char * U(rz_bin_java_get_fcn_name_from_bin)( RBinJavaObj *bin_obj, ut64 addr); +RZ_API int U(rz_bin_java_is_method_static)(RBinJavaObj *bin_obj, ut64 addr); -R_API ut8 r_bin_java_does_cp_idx_ref_method(RBinJavaObj *BIN_OBJ, int idx); -R_API ut8 r_bin_java_does_cp_idx_ref_field(RBinJavaObj *BIN_OBJ, int idx); -R_API int U(r_bin_java_is_method_protected)(RBinJavaObj *bin_obj, ut64 addr); -R_API int U(r_bin_java_is_method_private)(RBinJavaObj *bin_obj, ut64 addr); -R_API RBinJavaAttrInfo* r_bin_java_get_method_code_attribute(const RBinJavaField *method); +RZ_API ut8 rz_bin_java_does_cp_idx_ref_method(RBinJavaObj *BIN_OBJ, int idx); +RZ_API ut8 rz_bin_java_does_cp_idx_ref_field(RBinJavaObj *BIN_OBJ, int idx); +RZ_API int U(rz_bin_java_is_method_protected)(RBinJavaObj *bin_obj, ut64 addr); +RZ_API int U(rz_bin_java_is_method_private)(RBinJavaObj *bin_obj, ut64 addr); +RZ_API RBinJavaAttrInfo* rz_bin_java_get_method_code_attribute(const RBinJavaField *method); -R_API char * U(r_bin_java_get_method_name)(RBinJavaObj *bin_obj, ut32 idx); -R_API int U(r_bin_java_print_method_idx_summary) (RBinJavaObj *bin_obj, ut32 idx); -R_API ut32 U(r_bin_java_get_method_count)(RBinJavaObj *bin_obj); -R_API RList * U(r_bin_java_get_method_num_name) ( RBinJavaObj *bin_obj); +RZ_API char * U(rz_bin_java_get_method_name)(RBinJavaObj *bin_obj, ut32 idx); +RZ_API int U(rz_bin_java_print_method_idx_summary) (RBinJavaObj *bin_obj, ut32 idx); +RZ_API ut32 U(rz_bin_java_get_method_count)(RBinJavaObj *bin_obj); +RZ_API RzList * U(rz_bin_java_get_method_num_name) ( RBinJavaObj *bin_obj); -R_API char * U(r_bin_java_get_field_name) ( RBinJavaObj *bin_obj, ut32 idx); -R_API int U(r_bin_java_print_field_idx_summary) (RBinJavaObj *bin_obj, ut32 idx); -R_API ut32 U(r_bin_java_get_field_count) (RBinJavaObj *bin_obj); -R_API RList * U(r_bin_java_get_field_num_name) (RBinJavaObj *bin_obj); +RZ_API char * U(rz_bin_java_get_field_name) ( RBinJavaObj *bin_obj, ut32 idx); +RZ_API int U(rz_bin_java_print_field_idx_summary) (RBinJavaObj *bin_obj, ut32 idx); +RZ_API ut32 U(rz_bin_java_get_field_count) (RBinJavaObj *bin_obj); +RZ_API RzList * U(rz_bin_java_get_field_num_name) (RBinJavaObj *bin_obj); -R_API RList * U(r_bin_java_find_cp_const_by_val) ( RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len, const char t); -R_API char U(r_bin_java_resolve_cp_idx_tag)(RBinJavaObj *BIN_OBJ, int idx); +RZ_API RzList * U(rz_bin_java_find_cp_const_by_val) ( RBinJavaObj *bin_obj, const ut8 *bytes, ut32 len, const char t); +RZ_API char U(rz_bin_java_resolve_cp_idx_tag)(RBinJavaObj *BIN_OBJ, int idx); -R_API int U(r_bin_java_integer_cp_set)(RBinJavaObj *bin, ut16 idx, ut32 val ); -R_API int U(r_bin_java_float_cp_set)(RBinJavaObj *bin, ut16 idx, float val ); -R_API int U(r_bin_java_long_cp_set)(RBinJavaObj *bin, ut16 idx, ut64 val ); -R_API int U(r_bin_java_double_cp_set)(RBinJavaObj *bin, ut16 idx, ut32 val ); -R_API int U(r_bin_java_utf8_cp_set)(RBinJavaObj *bin, ut16 idx, const ut8* buffer, ut32 len); -R_API ut8 * U(r_bin_java_cp_get_bytes)(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); -R_API ut8 * U(r_bin_java_cp_idx_get_bytes)(RBinJavaObj *bin, ut16 idx, ut32 *out_sz); -R_API ut32 U(r_bin_java_cp_get_size)(RBinJavaObj *bin, ut16 idx); +RZ_API int U(rz_bin_java_integer_cp_set)(RBinJavaObj *bin, ut16 idx, ut32 val ); +RZ_API int U(rz_bin_java_float_cp_set)(RBinJavaObj *bin, ut16 idx, float val ); +RZ_API int U(rz_bin_java_long_cp_set)(RBinJavaObj *bin, ut16 idx, ut64 val ); +RZ_API int U(rz_bin_java_double_cp_set)(RBinJavaObj *bin, ut16 idx, ut32 val ); +RZ_API int U(rz_bin_java_utf8_cp_set)(RBinJavaObj *bin, ut16 idx, const ut8* buffer, ut32 len); +RZ_API ut8 * U(rz_bin_java_cp_get_bytes)(ut8 tag, ut32 *out_sz, const ut8 *buf, const ut64 len); +RZ_API ut8 * U(rz_bin_java_cp_idx_get_bytes)(RBinJavaObj *bin, ut16 idx, ut32 *out_sz); +RZ_API ut32 U(rz_bin_java_cp_get_size)(RBinJavaObj *bin, ut16 idx); -R_API ut64 r_bin_java_parse_cp_pool (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); -R_API ut64 r_bin_java_parse_interfaces (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); -R_API ut64 r_bin_java_parse_fields (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); -R_API ut64 r_bin_java_parse_methods (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); -R_API ut64 r_bin_java_parse_attrs (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); -R_API int r_bin_java_load_bin (RBinJavaObj *bin, const ut8 * buf, ut64 len); -R_API void r_bin_add_import (RBinJavaObj * bin, RBinJavaCPTypeObj *cp_obj, const char * type); -R_API void r_bin_java_set_imports(RBinJavaObj* bin); -R_API RList* r_bin_java_get_imports(RBinJavaObj* bin); +RZ_API ut64 rz_bin_java_parse_cp_pool (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); +RZ_API ut64 rz_bin_java_parse_interfaces (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); +RZ_API ut64 rz_bin_java_parse_fields (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); +RZ_API ut64 rz_bin_java_parse_methods (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); +RZ_API ut64 rz_bin_java_parse_attrs (RBinJavaObj *bin, const ut64 offset, const ut8 * buf, const ut64 len); +RZ_API int rz_bin_java_load_bin (RBinJavaObj *bin, const ut8 * buf, ut64 len); +RZ_API void rz_bin_add_import (RBinJavaObj * bin, RBinJavaCPTypeObj *cp_obj, const char * type); +RZ_API void rz_bin_java_set_imports(RBinJavaObj* bin); +RZ_API RzList* rz_bin_java_get_imports(RBinJavaObj* bin); -R_API ut64 U(r_bin_java_get_method_start)(RBinJavaObj *bin, RBinJavaField *method); -R_API ut64 U(r_bin_java_get_method_end)(RBinJavaObj *bin, RBinJavaField *method); +RZ_API ut64 U(rz_bin_java_get_method_start)(RBinJavaObj *bin, RBinJavaField *method); +RZ_API ut64 U(rz_bin_java_get_method_end)(RBinJavaObj *bin, RBinJavaField *method); -R_API ut8 * r_bin_java_cp_get_fref_bytes (RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); -R_API ut8 * U(r_bin_java_cp_append_method_ref) (RBinJavaObj *bin, ut32 *out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); -R_API ut8 * U(r_bin_java_cp_append_field_ref)(RBinJavaObj *bin, ut32 *out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); -R_API char * U(r_bin_java_unmangle_without_flags) (const char *name, const char *descriptor); -R_API char * r_bin_java_unmangle (const char *flags, const char *name, const char *descriptor); +RZ_API ut8 * rz_bin_java_cp_get_fref_bytes (RBinJavaObj *bin, ut32 *out_sz, ut8 tag, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); +RZ_API ut8 * U(rz_bin_java_cp_append_method_ref) (RBinJavaObj *bin, ut32 *out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); +RZ_API ut8 * U(rz_bin_java_cp_append_field_ref)(RBinJavaObj *bin, ut32 *out_sz, ut16 cn_idx, ut16 fn_idx, ut16 ft_idx ); +RZ_API char * U(rz_bin_java_unmangle_without_flags) (const char *name, const char *descriptor); +RZ_API char * rz_bin_java_unmangle (const char *flags, const char *name, const char *descriptor); -R_API DsoJsonObj * r_bin_java_get_field_json_definitions(RBinJavaObj *bin); -R_API DsoJsonObj * r_bin_java_get_method_json_definitions(RBinJavaObj *bin); -R_API DsoJsonObj * r_bin_java_get_import_json_definitions(RBinJavaObj *bin); -R_API DsoJsonObj * r_bin_java_get_interface_json_definitions(RBinJavaObj *bin); +RZ_API DsoJsonObj * rz_bin_java_get_field_json_definitions(RBinJavaObj *bin); +RZ_API DsoJsonObj * rz_bin_java_get_method_json_definitions(RBinJavaObj *bin); +RZ_API DsoJsonObj * rz_bin_java_get_import_json_definitions(RBinJavaObj *bin); +RZ_API DsoJsonObj * rz_bin_java_get_interface_json_definitions(RBinJavaObj *bin); -R_API DsoJsonObj * r_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJavaField *fm_type, int is_method); -R_API DsoJsonObj * r_bin_java_get_field_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type); -R_API DsoJsonObj * r_bin_java_get_method_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type); -R_API DsoJsonObj * r_bin_java_get_class_info_json(RBinJavaObj *bin); +RZ_API DsoJsonObj * rz_bin_java_get_fm_type_definition_json(RBinJavaObj *bin, RBinJavaField *fm_type, int is_method); +RZ_API DsoJsonObj * rz_bin_java_get_field_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type); +RZ_API DsoJsonObj * rz_bin_java_get_method_json_definition(RBinJavaObj *bin, RBinJavaField *fm_type); +RZ_API DsoJsonObj * rz_bin_java_get_class_info_json(RBinJavaObj *bin); -R_API DsoJsonObj * r_bin_java_get_bin_obj_json (RBinJavaObj *bin); -R_API ut64 r_bin_java_calc_class_size(ut8* bytes, ut64 size); -R_API int r_bin_java_valid_class (const ut8 * buf, ut64 buf_sz); +RZ_API DsoJsonObj * rz_bin_java_get_bin_obj_json (RBinJavaObj *bin); +RZ_API ut64 rz_bin_java_calc_class_size(ut8* bytes, ut64 size); +RZ_API int rz_bin_java_valid_class (const ut8 * buf, ut64 buf_sz); #endif diff --git a/shlr/java/code.c b/shlr/java/code.c index a48ec008fc..ad8c624d5f 100644 --- a/shlr/java/code.c +++ b/shlr/java/code.c @@ -1,9 +1,9 @@ /* radare - LGPL - Copyright 2007-2016 - pancake */ -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -18,8 +18,8 @@ #define DO_THE_DBG 0 #define IFDBG if(DO_THE_DBG) -#ifndef R_API -#define R_API +#ifndef RZ_API +#define RZ_API #endif static void init_switch_op(void); @@ -107,7 +107,7 @@ static int handle_switch_op (ut64 addr, const ut8 * bytes, char *output, int out return update_bytes_consumed (sz); } -R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *bytes, int len, char *output, int outlen) { +RZ_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *bytes, int len, char *output, int outlen) { char *arg = NULL; //(char *) malloc (1024); int sz = 0; ut32 val_one = 0; @@ -146,7 +146,7 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt return update_bytes_consumed (JAVA_OPS[idx].size); case 0x12: // ldc - arg = r_bin_java_resolve_without_space (obj, (ut16)bytes[1]); + arg = rz_bin_java_resolve_without_space (obj, (ut16)bytes[1]); if (arg) { snprintf (output, outlen, "%s %s", JAVA_OPS[idx].name, arg); free (arg); @@ -157,7 +157,7 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt return update_bytes_consumed (JAVA_OPS[idx].size); case 0x13: case 0x14: - arg = r_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); + arg = rz_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); if (arg) { snprintf (output, outlen, "%s %s", JAVA_OPS[idx].name, arg); free (arg); @@ -205,7 +205,7 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt case 0xb8: // invokestatic case 0xb9: // invokeinterface case 0xba: // invokedynamic - arg = r_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); + arg = rz_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); if (arg) { snprintf (output, outlen, "%s %s", JAVA_OPS[idx].name, arg); free (arg); @@ -218,7 +218,7 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt case 0xbd: // anewarray case 0xc0: // checkcast case 0xc1: // instance of - arg = r_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); + arg = rz_bin_java_resolve_without_space (obj, (int)USHORT (bytes, 1)); if (arg) { snprintf (output, outlen, "%s %s", JAVA_OPS[idx].name, arg); free (arg); @@ -231,7 +231,7 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt case 0xb3: // putstatic case 0xb4: // getfield case 0xb5: // putfield - arg = r_bin_java_resolve_with_space (obj, (int)USHORT (bytes, 1)); + arg = rz_bin_java_resolve_with_space (obj, (int)USHORT (bytes, 1)); if (arg) { snprintf (output, outlen, "%s %s", JAVA_OPS[idx].name, arg); free (arg); @@ -256,20 +256,20 @@ R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *byt return update_bytes_consumed (JAVA_OPS[idx].size); } -R_API void r_java_new_method (void) { +RZ_API void rz_java_new_method (void) { IFDBG eprintf ("Reseting the bytes consumed, they were: 0x%04"PFMT64x".\n", BYTES_CONSUMED); init_switch_op (); IN_SWITCH_OP = 0; BYTES_CONSUMED = 0; } -R_API void U(r_java_set_obj)(RBinJavaObj *obj) { +RZ_API void U(rz_java_set_obj)(RBinJavaObj *obj) { // eprintf ("SET CP (%p) %d\n", cp, n); //BIN_OBJ = obj; } -R_API int r_java_disasm(RBinJavaObj *obj, ut64 addr, const ut8 *bytes, int len, char *output, int outlen) { - //r_cons_printf ("r_java_disasm (allowed %d): 0x%02x, 0x%0x.\n", outlen, bytes[0], addr); +RZ_API int rz_java_disasm(RBinJavaObj *obj, ut64 addr, const ut8 *bytes, int len, char *output, int outlen) { + //rz_cons_printf ("rz_java_disasm (allowed %d): 0x%02x, 0x%0x.\n", outlen, bytes[0], addr); return java_print_opcode (obj, addr, bytes[0], bytes, len, output, outlen); } @@ -285,7 +285,7 @@ static int parseJavaArgs(char *str, ut64 *args, int args_sz) { if (q) { *q++ = 0; } - args[i] = r_num_math (NULL, p); + args[i] = rz_num_math (NULL, p); if (q) { p = q; } else { @@ -296,7 +296,7 @@ static int parseJavaArgs(char *str, ut64 *args, int args_sz) { return nargs; } -R_API int r_java_assemble(ut64 addr, ut8 *bytes, const char *string) { +RZ_API int rz_java_assemble(ut64 addr, ut8 *bytes, const char *string) { ut64 args[4] = {0}; int i, a, b, c, d; char name[128]; diff --git a/shlr/java/code.h b/shlr/java/code.h index 6e38c55259..2f88e73f13 100644 --- a/shlr/java/code.h +++ b/shlr/java/code.h @@ -1,7 +1,7 @@ #ifndef _INCLUDE_R_JAVA_H_ #define _INCLUDE_R_JAVA_H_ -#include +#include #include "class.h" typedef struct java_op { @@ -13,10 +13,10 @@ typedef struct java_op { #define JAVA_OPS_COUNT 297 extern struct java_op JAVA_OPS[JAVA_OPS_COUNT]; -R_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *bytes, int len, char *output, int outlen); -R_API int r_java_disasm(RBinJavaObj *obj, ut64 addr, const ut8 *bytes, int len, char *output, int outlen); -R_API int r_java_assemble(ut64 addr, ut8 *bytes, const char *string); -//R_API void r_java_set_obj(RBinJavaObj *obj); -R_API void r_java_new_method(void); +RZ_API int java_print_opcode(RBinJavaObj *obj, ut64 addr, int idx, const ut8 *bytes, int len, char *output, int outlen); +RZ_API int rz_java_disasm(RBinJavaObj *obj, ut64 addr, const ut8 *bytes, int len, char *output, int outlen); +RZ_API int rz_java_assemble(ut64 addr, ut8 *bytes, const char *string); +//RZ_API void rz_java_set_obj(RBinJavaObj *obj); +RZ_API void rz_java_new_method(void); #endif diff --git a/shlr/java/deps.mk b/shlr/java/deps.mk index ff075d5c23..09311518c8 100644 --- a/shlr/java/deps.mk +++ b/shlr/java/deps.mk @@ -1 +1 @@ -LINK+=$(STOP)/java/libr_java.$(EXT_AR) +LINK+=$(STOP)/java/librz_java.$(EXT_AR) diff --git a/shlr/java/dsojson.c b/shlr/java/dsojson.c index fae48ec979..a968dae9bf 100644 --- a/shlr/java/dsojson.c +++ b/shlr/java/dsojson.c @@ -2,8 +2,8 @@ #include "dsojson.h" #include "class.h" -#include -#include +#include +#include #include char * dso_json_dict_entry_to_str (DsoJsonDictEntry * entry); @@ -27,14 +27,14 @@ static DsoJsonInfo DSO_JSON_INFOS []= { {DSO_JSON_END},//, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, }; -static RList * build_str_list_from_iterable (RList *the_list) { - RList * res = r_list_newf (free); +static RzList * build_str_list_from_iterable (RzList *the_list) { + RzList * res = rz_list_newf (free); DsoJsonObj *json_obj; - RListIter *iter; - r_list_foreach (the_list, iter, json_obj) { + RzListIter *iter; + rz_list_foreach (the_list, iter, json_obj) { char *str = dso_json_obj_to_str (json_obj); if (str && *str) { - r_list_append (res, str); + rz_list_append (res, str); } else { free (str); } @@ -42,13 +42,13 @@ static RList * build_str_list_from_iterable (RList *the_list) { return res; } -static char * build_str_from_str_list_for_iterable (RList *the_list, int is_array) { +static char * build_str_from_str_list_for_iterable (RzList *the_list, int is_array) { char *res = NULL, *str; int len = 3, pos = 1; - RListIter *iter = NULL; - RList *str_list = build_str_list_from_iterable (the_list); + RzListIter *iter = NULL; + RzList *str_list = build_str_list_from_iterable (the_list); - r_list_foreach (str_list, iter, str) { + rz_list_foreach (str_list, iter, str) { len += strlen (str) + 1; } @@ -56,13 +56,13 @@ static char * build_str_from_str_list_for_iterable (RList *the_list, int is_arra // TODO: use [ if needed if (res) { strcpy (res, is_array? "[": "{"); - r_list_foreach (str_list, iter, str) { + rz_list_foreach (str_list, iter, str) { pos += snprintf (res+pos, len - pos, "%s%s", str, iter->n? ",": ""); } strcat (res, is_array?"]": "}"); } - r_list_free (str_list); + rz_list_free (str_list); return res; } @@ -151,8 +151,8 @@ static void allocDsoStr (DsoJsonStr *dsoStr, unsigned int sz) { dsoStr->len = sz; } -static RList * dso_json_get_list (DsoJsonObj *dso_obj) { - RList *the_list = NULL; +static RzList * dso_json_get_list (DsoJsonObj *dso_obj) { + RzList *the_list = NULL; if (dso_obj) { switch (dso_obj->info->type) { case DSO_JSON_LIST: the_list = dso_obj->val._list->json_list; break; @@ -422,7 +422,7 @@ DsoJsonObj * dso_json_list_new () { x->info = get_type_info (DSO_JSON_LIST); x->val._list = calloc (sizeof (DsoJsonList), 1); if (x->val._list) { - x->val._list->json_list = r_list_newf ((RListFree)dso_json_obj_del); + x->val._list->json_list = rz_list_newf ((RzListFree)dso_json_obj_del); } else { R_FREE (x); } @@ -433,7 +433,7 @@ DsoJsonObj * dso_json_list_new () { void dso_json_list_free (DsoJsonObj *x) { if (!x) return; if (x->val._list && x->val._list->json_list) { - r_list_free (x->val._list->json_list); + rz_list_free (x->val._list->json_list); x->val._list->json_list = NULL; } } @@ -448,7 +448,7 @@ char * dso_json_list_to_str (DsoJsonList *list) { int dso_json_list_append (DsoJsonObj *list_obj, DsoJsonObj *y) { if (get_type (list_obj) == DSO_JSON_LIST) { DsoJsonList * list = list_obj->val._list; - r_list_append (list->json_list, y); + rz_list_append (list->json_list, y); return true; } return false; @@ -483,7 +483,7 @@ DsoJsonObj * dso_json_dict_new () { dso_json_null_free (x); return NULL; } - x->val._dict->json_dict = r_list_newf ((RListFree)dso_json_obj_del); + x->val._dict->json_dict = rz_list_newf ((RzListFree)dso_json_obj_del); } return x; } @@ -491,7 +491,7 @@ DsoJsonObj * dso_json_dict_new () { void dso_json_dict_free (void *y) { DsoJsonDict *x = (DsoJsonDict *)y; if (x && x->json_dict) { - r_list_free (x->json_dict); + rz_list_free (x->json_dict); x->json_dict = NULL; } free (x); @@ -567,18 +567,18 @@ int dso_json_dict_insert_num_key_str (DsoJsonObj *dict, int key, char *val) { // TODO inserting the dicts. int dso_json_dict_insert_key_obj (DsoJsonObj *dict, DsoJsonObj *key, DsoJsonObj *value) { int res = false; - RList* the_list = dso_json_get_list (dict); + RzList* the_list = dso_json_get_list (dict); if (!the_list) return false; if (get_type (key) != DSO_JSON_STR) return false; if (!value) value = dso_json_null_new (); if (value && key && !dso_json_dict_contains_key_obj (dict, key)) { DsoJsonObj *entry = dso_json_dict_entry_new_from_key_obj_val_obj (key, value); - r_list_append (the_list, entry); + rz_list_append (the_list, entry); res = true; //TODO implement the remove key } else if (value && key && !dso_json_dict_remove_key_obj (dict, key)) { DsoJsonObj *entry = dso_json_dict_entry_new_from_key_obj_val_obj (key, value); - r_list_append (the_list, entry); + rz_list_append (the_list, entry); res = true; } else { dso_json_obj_del (value); @@ -592,17 +592,17 @@ int dso_json_dict_remove_key_obj (DsoJsonObj *dict, DsoJsonObj *key) { } int dso_json_dict_remove_key_str (DsoJsonObj *dict, char *key) { - RListIter *iter; + RzListIter *iter; DsoJsonObj *dso_obj; int res = false; - RList* the_list = dso_json_get_list (dict); + RzList* the_list = dso_json_get_list (dict); if (the_list) { - r_list_foreach (the_list, iter, dso_obj) { + rz_list_foreach (the_list, iter, dso_obj) { if (get_type (dso_obj) == DSO_JSON_DICT_ENTRY && get_type (dso_obj->val._dict_entry->key) == DSO_JSON_STR) { if (!cmpDsoStr_to_str (dso_json_get_str (dso_obj), key)) { res = true; - r_list_delete (the_list, iter); + rz_list_delete (the_list, iter); break; } } @@ -616,11 +616,11 @@ int dso_json_dict_contains_key_obj (DsoJsonObj *dict, DsoJsonObj *key) { } int dso_json_dict_contains_key_str (DsoJsonObj *dict, char *key) { - RListIter *iter; + RzListIter *iter; DsoJsonObj *dso_obj; - RList* the_list = dso_json_get_list (dict); + RzList* the_list = dso_json_get_list (dict); if (the_list) { - r_list_foreach (the_list, iter, dso_obj) { + rz_list_foreach (the_list, iter, dso_obj) { if (get_type (dso_obj) == DSO_JSON_DICT_ENTRY && get_type (dso_obj->val._dict_entry->key) == DSO_JSON_STR) { if (!cmpDsoStr_to_str (dso_json_get_str (dso_obj), key)) { @@ -648,7 +648,7 @@ void dso_json_num_free (void *y) { } char * dso_json_num_to_str (DsoJsonNum * num) { - return r_str_newf ("%"PFMT64d, num->value); + return rz_str_newf ("%"PFMT64d, num->value); } DsoJsonObj * dso_json_num_new_from_num (ut64 num) { diff --git a/shlr/java/dsojson.h b/shlr/java/dsojson.h index 74ae07eb3b..83178a7b12 100644 --- a/shlr/java/dsojson.h +++ b/shlr/java/dsojson.h @@ -3,8 +3,8 @@ #ifndef _INCLUDE_DOSJSON_H_ #define _INCLUDE_DOSJSON_H_ -#include -#include +#include +#include struct basic_json_t; typedef struct dso_json_info_t { @@ -37,12 +37,12 @@ typedef struct basic_json_dict_entry_t { typedef struct basic_json_dict_t { // TODO finish this - RList /*DsoJsonDictEntry*/ *json_dict; + RzList /*DsoJsonDictEntry*/ *json_dict; } DsoJsonDict; typedef struct basic_json_list_t { // TODO finish this - RList *json_list; + RzList *json_list; } DsoJsonList; diff --git a/shlr/java/main.c b/shlr/java/main.c index 8b19acf7a9..3831b4b8d7 100644 --- a/shlr/java/main.c +++ b/shlr/java/main.c @@ -4,7 +4,7 @@ int main() { Sdb *kv = sdb_new(NULL, NULL, 0); - RBinJavaObj *o = r_bin_java_new ("/tmp/CON.class", 0, kv); + RBinJavaObj *o = rz_bin_java_new ("/tmp/CON.class", 0, kv); printf ("Hello World %p\n", o); return 0; } diff --git a/shlr/java/ops.c b/shlr/java/ops.c index 3e51f0cdcf..7db99a7918 100644 --- a/shlr/java/ops.c +++ b/shlr/java/ops.c @@ -4,7 +4,7 @@ #include "code.h" #include "ops.h" -R_API struct java_op JAVA_OPS[JAVA_OPS_COUNT] = { +RZ_API struct java_op JAVA_OPS[JAVA_OPS_COUNT] = { { "nop" , 0x00, 1, R_ANAL_JAVA_NOP }, { "aconst_null" , 0x01, 1, R_ANAL_JAVA_LDST_LOAD_FROM_CONST_REF_TO_STACK }, { "iconst_m1" , 0x02, 1, R_ANAL_JAVA_LDST_LOAD_FROM_CONST_TO_STACK }, diff --git a/shlr/java/ops.h b/shlr/java/ops.h index ba5622e0ac..f4939d2010 100644 --- a/shlr/java/ops.h +++ b/shlr/java/ops.h @@ -1,5 +1,5 @@ /* radare - Apache 2.0 - Copyright 2013 - Adam Pridgen */ -#include +#include #ifndef R2_JAVA_OPS_H #define R2_JAVA_OPS_H diff --git a/shlr/lz4/Makefile b/shlr/lz4/Makefile index 2393690703..1798f6f372 100644 --- a/shlr/lz4/Makefile +++ b/shlr/lz4/Makefile @@ -1,5 +1,5 @@ -include ../../libr/config.mk -CFLAGS+=-I../../libr/include +include ../../librz/config.mk +CFLAGS+=-I../../librz/include # ################################################################ # LZ4 library - Makefile # Copyright (C) Yann Collet 2011-2016 diff --git a/shlr/meson.build b/shlr/meson.build index 62142da41f..0a82fa45d8 100644 --- a/shlr/meson.build +++ b/shlr/meson.build @@ -150,7 +150,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') capstone_includes += [include_directories('capstone/include/capstone')] endif - libr2capstone = static_library('r2capstone', cs_files, + librzcapstone = static_library('r2capstone', cs_files, c_args: [ '-DCAPSTONE_X86_ATT_DISABLE_NO', '-DCAPSTONE_X86_REDUCE_NO', @@ -173,7 +173,7 @@ if not capstone_dep.found() or not get_option('use_sys_capstone') ) capstone_dep = declare_dependency( - link_with: libr2capstone, + link_with: librzcapstone, include_directories: capstone_includes ) else @@ -248,14 +248,14 @@ else endif -# new radare2 shell parser -shell_parser_path = 'radare2-shell-parser' +# new rizin shell parser +shell_parser_path = 'rizin-shell-parser' shell_parser_files = [ join_paths(shell_parser_path, 'src/parser.c'), join_paths(shell_parser_path, 'src/scanner.c'), ] -shell_parser_inc = [platform_inc, include_directories('radare2-shell-parser/src/tree_sitter')] +shell_parser_inc = [platform_inc, include_directories('rizin-shell-parser/src/tree_sitter')] libshell_parser = static_library('shell_parser', shell_parser_files, include_directories: shell_parser_inc, @@ -277,14 +277,14 @@ bochs_files = [ bochs_inc = [platform_inc, include_directories('bochs/include')] -libr2bochs = static_library('r2bochs', bochs_files, - dependencies: [r_util_dep], +librzbochs = static_library('r2bochs', bochs_files, + dependencies: [rz_util_dep], include_directories: bochs_inc, implicit_include_directories: false ) bochs_dep = declare_dependency( - link_with: libr2bochs, + link_with: librzbochs, include_directories: bochs_inc ) @@ -300,14 +300,14 @@ java_files = [ java_inc = [platform_inc, include_directories('java')] -libr2java = static_library('r2java', java_files, - dependencies: [r_util_dep], +librzjava = static_library('r2java', java_files, + dependencies: [rz_util_dep], include_directories: java_inc, implicit_include_directories: false ) java_dep = declare_dependency( - link_with: libr2java, + link_with: librzjava, include_directories: java_inc ) @@ -323,14 +323,14 @@ qnx_files = [ qnx_inc = [platform_inc, include_directories('qnx/include')] -libr2qnx = static_library('r2qnx', qnx_files, - dependencies: [r_socket_dep], +librzqnx = static_library('r2qnx', qnx_files, + dependencies: [rz_socket_dep], include_directories: qnx_inc, implicit_include_directories: false ) qnx_dep = declare_dependency( - link_with: libr2qnx, + link_with: librzqnx, include_directories: qnx_inc ) @@ -344,14 +344,14 @@ tcc_files = [ tcc_inc = [platform_inc, include_directories('tcc')] -libr2tcc = static_library('r2tcc', tcc_files, - dependencies: [r_util_dep], +librztcc = static_library('r2tcc', tcc_files, + dependencies: [rz_util_dep], include_directories: tcc_inc, implicit_include_directories: false ) tcc_dep = declare_dependency( - link_with: libr2tcc, + link_with: librztcc, include_directories: tcc_inc ) @@ -366,13 +366,13 @@ if not lz4_dep.found() or not get_option('use_sys_lz4') lz4_inc = [platform_inc, include_directories('lz4')] - libr2lz4 = static_library('r2lz4', lz4_files, + librzlz4 = static_library('r2lz4', lz4_files, include_directories: lz4_inc, implicit_include_directories: false ) lz4_dep = declare_dependency( - link_with: libr2lz4, + link_with: librzlz4, include_directories: lz4_inc ) else @@ -472,14 +472,14 @@ if not zip_dep.found() or not get_option('use_sys_zip') zip_inc = [platform_inc, include_directories('zip/include')] - libr2zip = static_library('r2zip', zip_files, + librzzip = static_library('r2zip', zip_files, include_directories: zip_inc, implicit_include_directories: false, dependencies: zlib_dep ) zip_dep = declare_dependency( - link_with: libr2zip, + link_with: librzzip, include_directories: zip_inc ) else @@ -542,14 +542,14 @@ grub_files = [ grub_inc = [platform_inc, include_directories('grub', 'grub/include')] -libr2grub = static_library('r2grub', grub_files, - dependencies: [r_util_dep], +librzgrub = static_library('r2grub', grub_files, + dependencies: [rz_util_dep], include_directories: grub_inc, implicit_include_directories: false ) grub_dep = declare_dependency( - link_with: libr2grub, + link_with: librzgrub, include_directories: grub_inc ) @@ -564,14 +564,14 @@ winkd_files = [ winkd_inc = [platform_inc, include_directories('winkd')] -libr2winkd = static_library('r2winkd', winkd_files, - dependencies: [r_hash_dep, r_crypto_dep, r_socket_dep, r_util_dep], +librzwinkd = static_library('r2winkd', winkd_files, + dependencies: [rz_hash_dep, rz_crypto_dep, rz_socket_dep, rz_util_dep], include_directories: winkd_inc, implicit_include_directories: false ) winkd_dep = declare_dependency( - link_with: libr2winkd, + link_with: librzwinkd, include_directories: winkd_inc ) @@ -583,14 +583,14 @@ ar_files = [ ar_inc = [platform_inc, include_directories(['ar'])] -libr2ar = static_library('r2ar', ar_files, - dependencies: [r_util_dep], +librzar = static_library('r2ar', ar_files, + dependencies: [rz_util_dep], include_directories: ar_inc, implicit_include_directories: false ) ar_dep = declare_dependency( - link_with: libr2ar, + link_with: librzar, include_directories: ar_inc ) diff --git a/shlr/mpc/Makefile b/shlr/mpc/Makefile index d91440a202..234eba6d8b 100644 --- a/shlr/mpc/Makefile +++ b/shlr/mpc/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/platform.mk CFLAGS+=-I. diff --git a/shlr/ptrace-wrap/Makefile b/shlr/ptrace-wrap/Makefile index 417a6ac25d..4a37e45a5c 100644 --- a/shlr/ptrace-wrap/Makefile +++ b/shlr/ptrace-wrap/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/platform.mk CC ?= gcc diff --git a/shlr/ptrace-wrap/README.md b/shlr/ptrace-wrap/README.md index 5ecb8752d9..ce4db76a54 100644 --- a/shlr/ptrace-wrap/README.md +++ b/shlr/ptrace-wrap/README.md @@ -65,7 +65,7 @@ If you need thread-safety, you must synchronize the access yourself. ## About -Created by Florian Märkl for [radare2](https://github.com/radareorg/radare2) and [Cutter](https://github.com/radareorg/cutter/). +Created by Florian Märkl for [rizin](https://github.com/rizinorg/rizin) and [Cutter](https://github.com/rizinorg/cutter/). ``` ptrace-wrap is free software: you can redistribute it and/or modify diff --git a/shlr/qnx/Makefile b/shlr/qnx/Makefile index 669b31f01a..4f4ddeb2db 100644 --- a/shlr/qnx/Makefile +++ b/shlr/qnx/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../mk/platform.mk include ../../shlr/zip/deps.mk EDITOR?=vim @@ -13,11 +13,11 @@ MAJOR=0 MINOR=1 LD=$(CC) ifeq ($(LD),cccl) -LDFLAGS+=-L${LIBR}/socket -llibr_socket -LDFLAGS+=-L${LIBR}/util -llibr_util +LDFLAGS+=-L${LIBR}/socket -llibrz_socket +LDFLAGS+=-L${LIBR}/util -llibrz_util else -LDFLAGS+=-L${LIBR}/socket -lr_socket -LDFLAGS+=-L${LIBR}/util -lr_util +LDFLAGS+=-L${LIBR}/socket -lrz_socket +LDFLAGS+=-L${LIBR}/util -lrz_util endif ifeq ($(OSTYPE),darwin) LDFLAGS_SHARED=-dynamiclib @@ -25,7 +25,7 @@ else LDFLAGS_SHARED=-shared endif #OSTYPE=windows -include ../../libr/socket/deps.mk +include ../../librz/socket/deps.mk include ../../shlr/sdb.mk # Test variables @@ -83,13 +83,13 @@ client: lib $(LD) $(TEST_D)/client.o -o $(TEST_D)/client -L$(LIB) -lqnxr run_test: client - rarun2 libpath=./lib program=./test/client + rz_run libpath=./lib program=./test/client gdb_test: client - rarun2 libpath=./lib system="gdb ./test/client" + rz_run libpath=./lib system="gdb ./test/client" valgrind_test: client - rarun2 libpath=./lib system="valgrind --track-origins=yes -v --leak-check=full ./test/client" + rz_run libpath=./lib system="valgrind --track-origins=yes -v --leak-check=full ./test/client" edit: $(EDITOR) -c "args **/*.h **/*.c" diff --git a/shlr/qnx/include/arch.h b/shlr/qnx/include/arch.h index 404e5a6abe..a99462d3bd 100644 --- a/shlr/qnx/include/arch.h +++ b/shlr/qnx/include/arch.h @@ -2,7 +2,7 @@ #ifndef ARCH_H #define ARCH_H -#include "r_types.h" +#include "rz_types.h" #define ARCH_X86_64 0 #define ARCH_X86_32 1 diff --git a/shlr/qnx/include/core.h b/shlr/qnx/include/core.h index 4aee53a22e..d4418b3618 100644 --- a/shlr/qnx/include/core.h +++ b/shlr/qnx/include/core.h @@ -2,7 +2,7 @@ #ifndef QNX_CORE_H #define QNX_CORE_H -#include "r_types.h" +#include "rz_types.h" #include #include diff --git a/shlr/qnx/include/gdb_signals.h b/shlr/qnx/include/gdb_signals.h index cfce047866..d21b29a619 100644 --- a/shlr/qnx/include/gdb_signals.h +++ b/shlr/qnx/include/gdb_signals.h @@ -97,7 +97,7 @@ enum target_signal { TARGET_SIGNAL_MSG = 41, TARGET_SIGNAL_SOUND = 42, TARGET_SIGNAL_SAK = 43, - TARGET_SIGNAL_PRIO = 44, + TARGET_SIGNAL_PRzIO = 44, TARGET_SIGNAL_REALTIME_33 = 45, TARGET_SIGNAL_REALTIME_34 = 46, TARGET_SIGNAL_REALTIME_35 = 47, diff --git a/shlr/qnx/include/libqnxr.h b/shlr/qnx/include/libqnxr.h index 312444d15f..df6728f976 100644 --- a/shlr/qnx/include/libqnxr.h +++ b/shlr/qnx/include/libqnxr.h @@ -11,8 +11,8 @@ typedef int pid_t; #endif #include "arch.h" -#include "r_types_base.h" -#include "r_socket.h" +#include "rz_types_base.h" +#include "rz_socket.h" #include "dsmsgs.h" #define MSG_OK 0 @@ -40,7 +40,7 @@ typedef struct libqnxr_t { ssize_t send_len; ssize_t read_len; ssize_t read_ptr; - RSocket *sock; + RzSocket *sock; char host[256]; int port; int connected; diff --git a/shlr/qnx/src/core.c b/shlr/qnx/src/core.c index 06145796b0..af19557319 100644 --- a/shlr/qnx/src/core.c +++ b/shlr/qnx/src/core.c @@ -1,7 +1,7 @@ /* libqnxr - GPL - Copyright 2016 - defragger, madprogrammer, FSF Inc */ #include -#include +#include #include "libqnxr.h" #include "core.h" #include "signal.h" @@ -144,7 +144,7 @@ int qnxr_connect (libqnxr_t *g, const char *host, int port) { g->data_len = 0; g->read_len = 0; g->read_ptr = 0; - g->sock = r_socket_new (0); + g->sock = rz_socket_new (0); g->connected = 0; g->mid = 0; @@ -154,7 +154,7 @@ int qnxr_connect (libqnxr_t *g, const char *host, int port) { ret = snprintf (tmp, sizeof (tmp) - 1, "%d", port); if (!ret) return -1; - ret = r_socket_connect_tcp (g->sock, host, tmp, 200); + ret = rz_socket_connect_tcp (g->sock, host, tmp, 200); if (!ret) return -1; g->connected = 1; @@ -202,7 +202,7 @@ int qnxr_disconnect (libqnxr_t *g) { g->connected = 0; g->inferior_ptid = null_ptid; - if (!r_socket_close (g->sock)) + if (!rz_socket_close (g->sock)) return -1; } @@ -213,7 +213,7 @@ ptid_t qnxr_attach (libqnxr_t *g, pid_t pid) { if (g->inferior_ptid.pid != pid) { qnxr_disconnect (g); - r_sys_sleep (1); + rz_sys_sleep (1); qnxr_connect (g, g->host, g->port); } diff --git a/shlr/qnx/src/packet.c b/shlr/qnx/src/packet.c index b68a3754cc..f0763d843c 100644 --- a/shlr/qnx/src/packet.c +++ b/shlr/qnx/src/packet.c @@ -77,7 +77,7 @@ int qnxr_read_packet (libqnxr_t *g) { // or the buffer is empty if (g->read_len == 0 || g->read_ptr == g->read_len) { while (true) { - int ret = r_socket_ready (g->sock, 0, READ_TIMEOUT); + int ret = rz_socket_ready (g->sock, 0, READ_TIMEOUT); if (ret < 0) { if (errno == EINTR) continue; @@ -86,7 +86,7 @@ int qnxr_read_packet (libqnxr_t *g) { } g->read_ptr = 0; - g->read_len = r_socket_read (g->sock, (void *)g->read_buff, + g->read_len = rz_socket_read (g->sock, (void *)g->read_buff, DS_DATA_MAX_SIZE * 2); if (g->read_len <= 0) { @@ -127,19 +127,19 @@ int qnxr_read_packet (libqnxr_t *g) { } int qnxr_send_nak (libqnxr_t *g) { - return r_socket_write (g->sock, nak_packet, sizeof (nak_packet)); + return rz_socket_write (g->sock, nak_packet, sizeof (nak_packet)); } int qnxr_send_ch_reset (libqnxr_t *g) { - return r_socket_write (g->sock, ch_reset_packet, sizeof (ch_reset_packet)); + return rz_socket_write (g->sock, ch_reset_packet, sizeof (ch_reset_packet)); } int qnxr_send_ch_debug (libqnxr_t *g) { - return r_socket_write (g->sock, ch_debug_packet, sizeof (ch_debug_packet)); + return rz_socket_write (g->sock, ch_debug_packet, sizeof (ch_debug_packet)); } int qnxr_send_ch_text (libqnxr_t *g) { - return r_socket_write (g->sock, ch_text_packet, sizeof (ch_text_packet)); + return rz_socket_write (g->sock, ch_text_packet, sizeof (ch_text_packet)); } int qnxr_send_packet (libqnxr_t *g) { @@ -192,5 +192,5 @@ int qnxr_send_packet (libqnxr_t *g) { g->channelwr = g->tran.pkt.hdr.channel; } - return r_socket_write (g->sock, g->send_buff, p - g->send_buff); + return rz_socket_write (g->sock, g->send_buff, p - g->send_buff); } diff --git a/shlr/qnx/src/sigutil.c b/shlr/qnx/src/sigutil.c index b0221f24e1..d12051d12a 100644 --- a/shlr/qnx/src/sigutil.c +++ b/shlr/qnx/src/sigutil.c @@ -271,9 +271,9 @@ target_signal_from_host (int hostsig) { if (hostsig == SIGSAK) return TARGET_SIGNAL_SAK; #endif -#if defined(SIGPRIO) - if (hostsig == SIGPRIO) - return TARGET_SIGNAL_PRIO; +#if defined(SIGPRzIO) + if (hostsig == SIGPRzIO) + return TARGET_SIGNAL_PRzIO; #endif /* Mach exceptions. Assumes that the values for EXC_ are positive! */ @@ -517,9 +517,9 @@ do_target_signal_to_host (enum target_signal oursig, case TARGET_SIGNAL_SAK: return SIGSAK; #endif -#if defined(SIGPRIO) - case TARGET_SIGNAL_PRIO: - return SIGPRIO; +#if defined(SIGPRzIO) + case TARGET_SIGNAL_PRzIO: + return SIGPRzIO; #endif /* Mach exceptions. Assumes that the values for EXC_ are positive! */ diff --git a/shlr/qnx/src/utils.c b/shlr/qnx/src/utils.c index f53d524f30..ff560b3792 100644 --- a/shlr/qnx/src/utils.c +++ b/shlr/qnx/src/utils.c @@ -1,7 +1,7 @@ /* libqnxr - GPL - Copyright 2016 - madprogrammer, FSF Inc */ #include -#include +#include #include "utils.h" #define I386_NUM_GREGS 16 diff --git a/shlr/radare2-shell-parser-deps.mk b/shlr/radare2-shell-parser-deps.mk deleted file mode 100644 index 8893abdc25..0000000000 --- a/shlr/radare2-shell-parser-deps.mk +++ /dev/null @@ -1,2 +0,0 @@ -LINK+=$(STOP)/radare2-shell-parser/libshell-parser.$(EXT_AR) -LINK+=$(STOP)/tree-sitter/libtree-sitter.$(EXT_AR) diff --git a/shlr/rizin-shell-parser-deps.mk b/shlr/rizin-shell-parser-deps.mk new file mode 100644 index 0000000000..f4f27bd9d7 --- /dev/null +++ b/shlr/rizin-shell-parser-deps.mk @@ -0,0 +1,2 @@ +LINK+=$(STOP)/rizin-shell-parser/libshell-parser.$(EXT_AR) +LINK+=$(STOP)/tree-sitter/libtree-sitter.$(EXT_AR) diff --git a/shlr/radare2-shell-parser/.gitignore b/shlr/rizin-shell-parser/.gitignore similarity index 100% rename from shlr/radare2-shell-parser/.gitignore rename to shlr/rizin-shell-parser/.gitignore diff --git a/shlr/radare2-shell-parser/README.md b/shlr/rizin-shell-parser/README.md similarity index 88% rename from shlr/radare2-shell-parser/README.md rename to shlr/rizin-shell-parser/README.md index 3c5367aa04..54117cfc94 100644 --- a/shlr/radare2-shell-parser/README.md +++ b/shlr/rizin-shell-parser/README.md @@ -1,6 +1,6 @@ -# radare2-shell-parser +# rizin-shell-parser -This is the parser for radare2 shell language. +This is the parser for rizin shell language. See https://tree-sitter.github.io/tree-sitter/creating-parsers for more info on how to create a parser with tree-sitter. @@ -17,7 +17,7 @@ When you update something in grammar.js or src/scanner.c you have to re-generate the parser. The process works as follows: 1. Do changes as needed to grammar.js and/or src/scanner.c -2. Install npm dependencies with: `cd shlr/radare2-shell-parser ; npm install` +2. Install npm dependencies with: `cd shlr/rizin-shell-parser ; npm install` 3. Make sure tree-sitter is in PATH: `export PATH=$PATH:./node_modules/.bin` 4. Re-generate the parser files: `tree-sitter generate` 5. Check tests still pass: `tree-sitter test`. Use `tree-sitter parse diff --git a/shlr/radare2-shell-parser/binding.gyp b/shlr/rizin-shell-parser/binding.gyp similarity index 85% rename from shlr/radare2-shell-parser/binding.gyp rename to shlr/rizin-shell-parser/binding.gyp index 01e1e31138..eebdd2c5c9 100644 --- a/shlr/radare2-shell-parser/binding.gyp +++ b/shlr/rizin-shell-parser/binding.gyp @@ -1,7 +1,7 @@ { "targets": [ { - "target_name": "tree_sitter_r2cmd_binding", + "target_name": "tree_sitter_rzcmd_binding", "include_dirs": [ " prec.right(1, seq($._simple_command, '@', $.args)), tmp_blksz_command: $ => prec.right(1, seq($._simple_command, '@!', $.args)), - // NOTE: need to use special arg_brace here because of https://github.com/radareorg/radare2/commit/c3dee9332c19f874ac2cc9294a9ffe17575d8141 + // NOTE: need to use special arg_brace here because of https://github.com/rizinorg/rizin/commit/c3dee9332c19f874ac2cc9294a9ffe17575d8141 tmp_fromto_command: $ => prec.right(1, seq( $._simple_command, '@{', diff --git a/shlr/radare2-shell-parser/index.js b/shlr/rizin-shell-parser/index.js similarity index 57% rename from shlr/radare2-shell-parser/index.js rename to shlr/rizin-shell-parser/index.js index 7fd9a6d5ff..e0548d808c 100644 --- a/shlr/radare2-shell-parser/index.js +++ b/shlr/rizin-shell-parser/index.js @@ -1,8 +1,8 @@ try { - module.exports = require("./build/Release/tree_sitter_r2cmd_binding"); + module.exports = require("./build/Release/tree_sitter_rzcmd_binding"); } catch (error) { try { - module.exports = require("./build/Debug/tree_sitter_r2cmd_binding"); + module.exports = require("./build/Debug/tree_sitter_rzcmd_binding"); } catch (_) { throw error } diff --git a/shlr/radare2-shell-parser/package-lock.json b/shlr/rizin-shell-parser/package-lock.json similarity index 100% rename from shlr/radare2-shell-parser/package-lock.json rename to shlr/rizin-shell-parser/package-lock.json diff --git a/shlr/radare2-shell-parser/package.json b/shlr/rizin-shell-parser/package.json similarity index 82% rename from shlr/radare2-shell-parser/package.json rename to shlr/rizin-shell-parser/package.json index 299e061d38..537f2e76d0 100644 --- a/shlr/radare2-shell-parser/package.json +++ b/shlr/rizin-shell-parser/package.json @@ -1,7 +1,7 @@ { "name": "tree-sitter-r2cmd", "version": "1.0.0", - "description": "Tree-Sitter grammar for parsing radare2 commands", + "description": "Tree-Sitter grammar for parsing rizin commands", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/shlr/radare2-shell-parser/src/binding.cc b/shlr/rizin-shell-parser/src/binding.cc similarity index 82% rename from shlr/radare2-shell-parser/src/binding.cc rename to shlr/rizin-shell-parser/src/binding.cc index 5127b29a92..1a9e1c12c5 100644 --- a/shlr/radare2-shell-parser/src/binding.cc +++ b/shlr/rizin-shell-parser/src/binding.cc @@ -4,7 +4,7 @@ using namespace v8; -extern "C" TSLanguage * tree_sitter_r2cmd(); +extern "C" TSLanguage * tree_sitter_rzcmd(); namespace { @@ -17,12 +17,12 @@ void Init(Local exports, Local module) { Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_r2cmd()); + Nan::SetInternalFieldPointer(instance, 0, tree_sitter_rzcmd()); Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("r2cmd").ToLocalChecked()); Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); } -NODE_MODULE(tree_sitter_r2cmd_binding, Init) +NODE_MODULE(tree_sitter_rzcmd_binding, Init) } // namespace diff --git a/shlr/radare2-shell-parser/src/grammar.json b/shlr/rizin-shell-parser/src/grammar.json similarity index 100% rename from shlr/radare2-shell-parser/src/grammar.json rename to shlr/rizin-shell-parser/src/grammar.json diff --git a/shlr/radare2-shell-parser/src/node-types.json b/shlr/rizin-shell-parser/src/node-types.json similarity index 100% rename from shlr/radare2-shell-parser/src/node-types.json rename to shlr/rizin-shell-parser/src/node-types.json diff --git a/shlr/radare2-shell-parser/src/parser.c b/shlr/rizin-shell-parser/src/parser.c similarity index 99% rename from shlr/radare2-shell-parser/src/parser.c rename to shlr/rizin-shell-parser/src/parser.c index f50ed7bd03..e51a2db284 100644 --- a/shlr/radare2-shell-parser/src/parser.c +++ b/shlr/rizin-shell-parser/src/parser.c @@ -35571,17 +35571,17 @@ static TSParseActionEntry ts_parse_actions[] = { #ifdef __cplusplus extern "C" { #endif -void *tree_sitter_r2cmd_external_scanner_create(void); -void tree_sitter_r2cmd_external_scanner_destroy(void *); -bool tree_sitter_r2cmd_external_scanner_scan(void *, TSLexer *, const bool *); -unsigned tree_sitter_r2cmd_external_scanner_serialize(void *, char *); -void tree_sitter_r2cmd_external_scanner_deserialize(void *, const char *, unsigned); +void *tree_sitter_rzcmd_external_scanner_create(void); +void tree_sitter_rzcmd_external_scanner_destroy(void *); +bool tree_sitter_rzcmd_external_scanner_scan(void *, TSLexer *, const bool *); +unsigned tree_sitter_rzcmd_external_scanner_serialize(void *, char *); +void tree_sitter_rzcmd_external_scanner_deserialize(void *, const char *, unsigned); #ifdef _WIN32 #define extern __declspec(dllexport) #endif -extern const TSLanguage *tree_sitter_r2cmd(void) { +extern const TSLanguage *tree_sitter_rzcmd(void) { static TSLanguage language = { .version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, @@ -35607,11 +35607,11 @@ extern const TSLanguage *tree_sitter_r2cmd(void) { .external_scanner = { (const bool *)ts_external_scanner_states, ts_external_scanner_symbol_map, - tree_sitter_r2cmd_external_scanner_create, - tree_sitter_r2cmd_external_scanner_destroy, - tree_sitter_r2cmd_external_scanner_scan, - tree_sitter_r2cmd_external_scanner_serialize, - tree_sitter_r2cmd_external_scanner_deserialize, + tree_sitter_rzcmd_external_scanner_create, + tree_sitter_rzcmd_external_scanner_destroy, + tree_sitter_rzcmd_external_scanner_scan, + tree_sitter_rzcmd_external_scanner_serialize, + tree_sitter_rzcmd_external_scanner_deserialize, }, }; return &language; diff --git a/shlr/radare2-shell-parser/src/scanner.c b/shlr/rizin-shell-parser/src/scanner.c similarity index 93% rename from shlr/radare2-shell-parser/src/scanner.c rename to shlr/rizin-shell-parser/src/scanner.c index 7f13098a84..416124e7fb 100644 --- a/shlr/radare2-shell-parser/src/scanner.c +++ b/shlr/rizin-shell-parser/src/scanner.c @@ -15,18 +15,18 @@ enum TokenType { CONCAT_PF_DOT, }; -void *tree_sitter_r2cmd_external_scanner_create() { +void *tree_sitter_rzcmd_external_scanner_create() { return NULL; } -void tree_sitter_r2cmd_external_scanner_destroy(void *payload) { +void tree_sitter_rzcmd_external_scanner_destroy(void *payload) { } -unsigned tree_sitter_r2cmd_external_scanner_serialize(void *payload, char *buffer) { +unsigned tree_sitter_rzcmd_external_scanner_serialize(void *payload, char *buffer) { return 0; } -void tree_sitter_r2cmd_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { +void tree_sitter_rzcmd_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) { } static bool is_pf_cmd(const char *s) { @@ -120,7 +120,7 @@ static bool scan_number(TSLexer *lexer, const bool *valid_symbols) { return false; } -bool tree_sitter_r2cmd_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { +bool tree_sitter_rzcmd_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) { // FIXME: /* in the shell should become a multiline comment if (valid_symbols[CONCAT] && is_concat (lexer->lookahead)) { lexer->result_symbol = CONCAT; diff --git a/shlr/radare2-shell-parser/src/tree_sitter/parser.h b/shlr/rizin-shell-parser/src/tree_sitter/parser.h similarity index 99% rename from shlr/radare2-shell-parser/src/tree_sitter/parser.h rename to shlr/rizin-shell-parser/src/tree_sitter/parser.h index 11bf4fc42a..037671c2b1 100644 --- a/shlr/radare2-shell-parser/src/tree_sitter/parser.h +++ b/shlr/rizin-shell-parser/src/tree_sitter/parser.h @@ -13,7 +13,7 @@ extern "C" { #define ts_builtin_sym_end 0 #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 -#ifndef TREE_SITTER_API_H_ +#ifndef TREE_SITTERZ_API_H_ typedef uint16_t TSSymbol; typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; diff --git a/shlr/sdb/README.md b/shlr/sdb/README.md index 129baeee96..3c78a4757c 100644 --- a/shlr/sdb/README.md +++ b/shlr/sdb/README.md @@ -10,7 +10,7 @@ It is distributed as a standalone binary and a library. There's also the sdbtypes: a vala library that implements several data structures on top of an sdb or a memcache instance. -[![Travis](https://api.travis-ci.org/radareorg/sdb.svg)](https://travis-ci.org/radareorg/sdb) +[![Travis](https://api.travis-ci.org/rizinorg/sdb.svg)](https://travis-ci.org/rizinorg/sdb) [![Appveyor](https://ci.appveyor.com/api/projects/status/github/radare/sdb?branch=master&svg=true)](https://ci.appveyor.com/project/radare/sdb) diff --git a/shlr/sdb/meson.build b/shlr/sdb/meson.build index cb50d570be..c945d815d6 100644 --- a/shlr/sdb/meson.build +++ b/shlr/sdb/meson.build @@ -120,7 +120,7 @@ pkgconfig_mod.generate( description: 'Simple DataBase', subdirs: ['sdb'], version: sdb_version, - url: 'https://github.com/radareorg/sdb' + url: 'https://github.com/rizinorg/sdb' ) if not meson.is_subproject() diff --git a/shlr/sdb/src/disk.c b/shlr/sdb/src/disk.c index af035413cf..736f47f8f5 100644 --- a/shlr/sdb/src/disk.c +++ b/shlr/sdb/src/disk.c @@ -12,7 +12,7 @@ #if UNICODE -static wchar_t *r_utf8_to_utf16_l (const char *cstring, int len) { +static wchar_t *rz_utf8_to_utf16_l (const char *cstring, int len) { if (!cstring || !len || len < -1) { return NULL; } @@ -31,29 +31,29 @@ static wchar_t *r_utf8_to_utf16_l (const char *cstring, int len) { return rutf16; } -#define r_sys_conv_utf8_to_utf16(buf) r_utf8_to_utf16_l ((buf), -1) +#define rz_sys_conv_utf8_to_utf16(buf) rz_utf8_to_utf16_l ((buf), -1) -static bool r_sys_mkdir(const char *path) { - LPTSTR path_ = r_sys_conv_utf8_to_utf16 (path); +static bool rz_sys_mkdir(const char *path) { + LPTSTR path_ = rz_sys_conv_utf8_to_utf16 (path); bool ret = CreateDirectory (path_, NULL); free (path_); return ret; } #else -#define r_sys_conv_utf8_to_utf16(buf) strdup (buf) -#define r_sys_mkdir(x) CreateDirectory (x, NULL) +#define rz_sys_conv_utf8_to_utf16(buf) strdup (buf) +#define rz_sys_mkdir(x) CreateDirectory (x, NULL) #endif #ifndef ERROR_ALREADY_EXISTS #define ERROR_ALREADY_EXISTS 183 #endif -#define r_sys_mkdir_failed() (GetLastError () != 183) +#define rz_sys_mkdir_failed() (GetLastError () != 183) #else -#define r_sys_mkdir(x) (mkdir (x,0755)!=-1) -#define r_sys_mkdir_failed() (errno != EEXIST) +#define rz_sys_mkdir(x) (mkdir (x,0755)!=-1) +#define rz_sys_mkdir_failed() (errno != EEXIST) #endif -static inline int r_sys_mkdirp(char *dir) { +static inline int rz_sys_mkdirp(char *dir) { int ret = 1; const char slash = DIRSEP; char *path = dir; @@ -69,8 +69,8 @@ static inline int r_sys_mkdirp(char *dir) { #endif while ((ptr = strchr (ptr, slash))) { *ptr = 0; - if (!r_sys_mkdir (path) && r_sys_mkdir_failed ()) { - eprintf ("r_sys_mkdirp: fail '%s' of '%s'\n", path, dir); + if (!rz_sys_mkdir (path) && rz_sys_mkdir_failed ()) { + eprintf ("rz_sys_mkdirp: fail '%s' of '%s'\n", path, dir); *ptr = slash; return 0; } @@ -98,13 +98,13 @@ SDB_API bool sdb_disk_create(Sdb* s) { return false; } memcpy (str, dir, nlen + 1); - r_sys_mkdirp (str); + rz_sys_mkdirp (str); memcpy (str + nlen, ".tmp", 5); if (s->fdump != -1) { close (s->fdump); } #if __SDB_WINDOWS__ && UNICODE - wchar_t *wstr = r_sys_conv_utf8_to_utf16 (str); + wchar_t *wstr = rz_sys_conv_utf8_to_utf16 (str); if (wstr) { s->fdump = _wopen (wstr, O_BINARY | O_RDWR | O_CREAT | O_TRUNC, SDB_MODE); free (wstr); @@ -149,8 +149,8 @@ SDB_API bool sdb_disk_finish (Sdb* s) { reopen = true; } #if __SDB_WINDOWS__ - LPTSTR ndump_ = r_sys_conv_utf8_to_utf16 (s->ndump); - LPTSTR dir_ = r_sys_conv_utf8_to_utf16 (s->dir); + LPTSTR ndump_ = rz_sys_conv_utf8_to_utf16 (s->ndump); + LPTSTR dir_ = rz_sys_conv_utf8_to_utf16 (s->dir); if (MoveFileEx (ndump_, dir_, MOVEFILE_REPLACE_EXISTING)) { //eprintf ("Error 0x%02x\n", GetLastError ()); diff --git a/shlr/sdb/src/ht_inc.c b/shlr/sdb/src/ht_inc.c index baaad41a33..7d65623b36 100644 --- a/shlr/sdb/src/ht_inc.c +++ b/shlr/sdb/src/ht_inc.c @@ -1,4 +1,4 @@ -/* radare2 - BSD 3 Clause License - crowell, pancake, ret2libc 2016-2018 */ +/* rizin - BSD 3 Clause License - crowell, pancake, ret2libc 2016-2018 */ #define LOAD_FACTOR 1 #define S_ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0])) diff --git a/shlr/sdb/src/ht_inc.h b/shlr/sdb/src/ht_inc.h index 892f4977f4..ed08f0a9c9 100644 --- a/shlr/sdb/src/ht_inc.h +++ b/shlr/sdb/src/ht_inc.h @@ -1,4 +1,4 @@ -/* radare2 - BSD 3 Clause License - 2016 - crowell */ +/* rizin - BSD 3 Clause License - 2016 - crowell */ #ifndef HT_TYPE #error HT_TYPE should be defined before including this header diff --git a/shlr/spp/Makefile b/shlr/spp/Makefile index dbe9177565..061d0a4a59 100644 --- a/shlr/spp/Makefile +++ b/shlr/spp/Makefile @@ -4,13 +4,13 @@ PWD=$(shell pwd) PREFIX?=/usr BINDIR=${DESTDIR}${PREFIX}/bin OBJ=spp.o bin/main.o -# r_api.o +# rz_api.o ODF=$(subst .o,.d,$(OBJ)) BIN=spp ifeq ($(SPP_USE_R2),1) -CFLAGS+=$(shell pkg-config --cflags r_util) -LDFLAGS+=$(shell pkg-config --libs r_util) +CFLAGS+=$(shell pkg-config --cflags rz_util) +LDFLAGS+=$(shell pkg-config --libs rz_util) endif CFLAGS?=-Wall -O2 diff --git a/shlr/spp/bin/main.c b/shlr/spp/bin/main.c index 7995abae4c..104b847e8b 100644 --- a/shlr/spp/bin/main.c +++ b/shlr/spp/bin/main.c @@ -1,7 +1,7 @@ /* MIT pancake (C) 2009-2020 */ #include "../spp.h" -#include "../r_api.h" +#include "../rz_api.h" extern struct Proc *procs[]; extern struct Proc *proc; @@ -65,8 +65,8 @@ int main(int argc, char **argv) { if (arg != NULL) { if (!strcmp (arg, "buff")) { out.fout = NULL; - out.cout = r_strbuf_new (""); - r_strbuf_init (out.cout); + out.cout = rz_strbuf_new (""); + rz_strbuf_init (out.cout); } else { out.cout = NULL; out.fout = fopen (arg, "w"); @@ -119,8 +119,8 @@ int main(int argc, char **argv) { dostdin = 0; if (!out.fout) { - D printf ("%s\n", r_strbuf_get (out.cout)); - r_strbuf_free (out.cout); + D printf ("%s\n", rz_strbuf_get (out.cout)); + rz_strbuf_free (out.cout); } } } diff --git a/shlr/spp/configure b/shlr/spp/configure index 3402a14c24..b46b0013e7 100755 --- a/shlr/spp/configure +++ b/shlr/spp/configure @@ -314,7 +314,7 @@ if [ "$WANT_R2" = "1" ]; then if [ ! "$R2_CFLAGS" = "" ]; then USE_R2="1" else -case "$undefined_variable" in 0|"") echo ; echo "ERROR: Cannot find -lr_util using pkg-config" >&2 ; echo ; exit 1 ;; esac; fi; fi +case "$undefined_variable" in 0|"") echo ; echo "ERROR: Cannot find -lrz_util using pkg-config" >&2 ; echo ; exit 1 ;; esac; fi; fi SEDFLAGS=" -e '" COUNT=0 for A in ${ENVWORDS} ; do diff --git a/shlr/spp/configure.acr b/shlr/spp/configure.acr index e970780a55..37ad920697 100644 --- a/shlr/spp/configure.acr +++ b/shlr/spp/configure.acr @@ -3,11 +3,11 @@ VERSION 1.2.0 CONTACT pancake ; pancake@nopcode.org ARG_WITHOUT HAVE_FORK fork build without depending on fork syscall ; -ARG_ENABLE WANT_R2 r2 compile against r2 r_util ; +ARG_ENABLE WANT_R2 r2 compile against r2 rz_util ; CHKPRG PKGCONFIG pkg-config -PKGCFG R2_CFLAGS R2_LDFLAGS r_util +PKGCFG R2_CFLAGS R2_LDFLAGS rz_util USE_R2 = 0 ; @@ -15,7 +15,7 @@ IF WANT_R2 { IFNOTNULL R2_CFLAGS { USE_R2 = 1 ; }{ - DIENOW Cannot find -lr_util using pkg-config ; + DIENOW Cannot find -lrz_util using pkg-config ; } } diff --git a/shlr/spp/p/cpp.h b/shlr/spp/p/cpp.h index a19e781ae2..7b087eb24b 100644 --- a/shlr/spp/p/cpp.h +++ b/shlr/spp/p/cpp.h @@ -105,8 +105,8 @@ static TAG_CALLBACK(cpp_define) { cpp_macro_add(buf,macro,ptr+1); /* TODO: Name is "BUF(". for funny strstr */ } - r_sys_setenv (buf, ptr); - } else r_sys_setenv (buf, ""); + rz_sys_setenv (buf, ptr); + } else rz_sys_setenv (buf, ""); return 0; } @@ -143,13 +143,13 @@ static ARG_CALLBACK(cpp_arg_i) { } static ARG_CALLBACK(cpp_arg_d) { - // TODO: handle r_sys_setenv==-1 + // TODO: handle rz_sys_setenv==-1 char *eq = strchr (arg, '='); if (eq) { *eq = '\0'; - r_sys_setenv (arg, eq + 1); + rz_sys_setenv (arg, eq + 1); } else { - r_sys_setenv (arg, ""); + rz_sys_setenv (arg, ""); } return 0; } diff --git a/shlr/spp/p/spp.h b/shlr/spp/p/spp.h index 56ac376b2f..3d3425fc6c 100644 --- a/shlr/spp/p/spp.h +++ b/shlr/spp/p/spp.h @@ -8,11 +8,11 @@ #endif static char *spp_var_get(char *var) { - return r_sys_getenv (var); + return rz_sys_getenv (var); } static int spp_var_set(const char *var, const char *val) { - return r_sys_setenv (var, val); + return rz_sys_setenv (var, val); } #if HAVE_SYSTEM @@ -90,7 +90,7 @@ static TAG_CALLBACK(spp_getrandom) { return 0; } // XXX srsly? this is pretty bad random - srandom (r_sys_getpid ()); // TODO: change this to be portable + srandom (rz_sys_getpid ()); // TODO: change this to be portable max = atoi (buf); if (max > 0) { max = (int)(rand () % max); @@ -114,7 +114,7 @@ static TAG_CALLBACK(spp_add) { } ret += atoi (eq + 1); snprintf (res, sizeof (res), "%d", ret); - r_sys_setenv (buf, res); + rz_sys_setenv (buf, res); } else { /* syntax error */ } @@ -133,7 +133,7 @@ static TAG_CALLBACK(spp_sub) { var = spp_var_get (buf); ret = var? atoi (var): 0; ret -= atoi (eq + 1); - r_sys_setenv (buf, eq + 1); + rz_sys_setenv (buf, eq + 1); } else { /* syntax error */ } @@ -426,7 +426,7 @@ static struct Tag spp_tags[] = { }; static ARG_CALLBACK(spp_arg_i) { - r_sys_setenv ("SPP_INCDIR", arg); + rz_sys_setenv ("SPP_INCDIR", arg); return 0; } diff --git a/shlr/spp/r_api.h b/shlr/spp/r_api.h deleted file mode 100644 index ea288b2cd0..0000000000 --- a/shlr/spp/r_api.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef S_STRBUF_H -#define S_STRBUF_H - -#ifndef R_FREE -#define R_FREE(x) { free(x); x = NULL; } -#endif -#ifndef R_NEW0 -#define R_NEW0(x) (x*)calloc(1,sizeof(x)) -#endif - -#ifdef _MSC_VER -void out_printf(Output *out, char *str, ...); -#else -void out_printf(Output *out, char *str, ...) __attribute__ ((format (printf, 2, 3))); -#endif - -#if USE_R2 -#include -#else -SStrBuf *r_strbuf_new(const char *s); -bool r_strbuf_set(SStrBuf *sb, const char *s); -bool r_strbuf_append(SStrBuf *sb, const char *s); -char *r_strbuf_get(SStrBuf *sb); -char *r_strbuf_drain(SStrBuf *sb); -void r_strbuf_free(SStrBuf *sb); -void r_strbuf_fini(SStrBuf *sb); -void r_strbuf_init(SStrBuf *sb); -int r_sys_setenv(const char *key, const char *value); -char *r_sys_getenv(const char *key); -int r_sys_getpid(void); -#endif - -#endif diff --git a/shlr/spp/r_api.c b/shlr/spp/rz_api.c similarity index 78% rename from shlr/spp/r_api.c rename to shlr/spp/rz_api.c index 09ed3ba612..49f34ec706 100644 --- a/shlr/spp/r_api.c +++ b/shlr/spp/rz_api.c @@ -1,4 +1,4 @@ -/* radare2 - LGPL - Copyright 2013-2020 - pancake */ +/* rizin - LGPL - Copyright 2013-2020 - pancake */ #if __UNIX__ #include @@ -6,23 +6,23 @@ #include #endif #include "spp.h" -#include "r_api.h" +#include "rz_api.h" -SStrBuf *r_strbuf_new(const char *str) { +SStrBuf *rz_strbuf_new(const char *str) { SStrBuf *s = R_NEW0 (SStrBuf); - if (str) r_strbuf_set (s, str); + if (str) rz_strbuf_set (s, str); return s; } -void r_strbuf_init(SStrBuf *sb) { +void rz_strbuf_init(SStrBuf *sb) { memset (sb, 0, sizeof (SStrBuf)); } -bool r_strbuf_set(SStrBuf *sb, const char *s) { +bool rz_strbuf_set(SStrBuf *sb, const char *s) { int l; if (!sb) return false; if (!s) { - r_strbuf_init (sb); + rz_strbuf_init (sb); return true; } l = strlen (s); @@ -43,7 +43,7 @@ bool r_strbuf_set(SStrBuf *sb, const char *s) { return true; } -bool r_strbuf_append(SStrBuf *sb, const char *s) { +bool rz_strbuf_append(SStrBuf *sb, const char *s) { int l = strlen (s); if (l < 1) { return false; @@ -76,30 +76,30 @@ bool r_strbuf_append(SStrBuf *sb, const char *s) { return true; } -char *r_strbuf_get(SStrBuf *sb) { +char *rz_strbuf_get(SStrBuf *sb) { return sb? (sb->ptr? sb->ptr: sb->buf) : NULL; } -char *r_strbuf_drain(SStrBuf *sb) { +char *rz_strbuf_drain(SStrBuf *sb) { char *res = sb->ptr? sb->ptr: strdup (sb->buf); sb->ptr = NULL; - r_strbuf_fini (sb); + rz_strbuf_fini (sb); free (sb); return res; } -void r_strbuf_free(SStrBuf *sb) { - r_strbuf_fini (sb); +void rz_strbuf_free(SStrBuf *sb) { + rz_strbuf_fini (sb); free (sb); } -void r_strbuf_fini(SStrBuf *sb) { +void rz_strbuf_fini(SStrBuf *sb) { if (sb && sb->ptr) R_FREE (sb->ptr); } /* --------- */ -int r_sys_setenv(const char *key, const char *value) { +int rz_sys_setenv(const char *key, const char *value) { if (!key) { return 0; } @@ -113,12 +113,12 @@ int r_sys_setenv(const char *key, const char *value) { int ret = SetEnvironmentVariableA (key, value); return ret ? 0 : -1; #else -#warning r_sys_setenv : unimplemented for this platform +#warning rz_sys_setenv : unimplemented for this platform return 0; #endif } -char *r_sys_getenv(const char *key) { +char *rz_sys_getenv(const char *key) { #if __WINDOWS__ DWORD dwRet; char *envbuf = NULL, *tmp_ptr; @@ -161,13 +161,13 @@ err_r_sys_get_env: #endif } -int r_sys_getpid() { +int rz_sys_getpid() { #if __UNIX__ return getpid(); #elif __WINDOWS__ return GetCurrentProcessId(); #else -#warning r_sys_getpid not implemented for this platform +#warning rz_sys_getpid not implemented for this platform return -1; #endif } diff --git a/shlr/spp/rz_api.h b/shlr/spp/rz_api.h new file mode 100644 index 0000000000..e8201f74b7 --- /dev/null +++ b/shlr/spp/rz_api.h @@ -0,0 +1,33 @@ +#ifndef S_STRBUF_H +#define S_STRBUF_H + +#ifndef R_FREE +#define R_FREE(x) { free(x); x = NULL; } +#endif +#ifndef R_NEW0 +#define R_NEW0(x) (x*)calloc(1,sizeof(x)) +#endif + +#ifdef _MSC_VER +void out_printf(Output *out, char *str, ...); +#else +void out_printf(Output *out, char *str, ...) __attribute__ ((format (printf, 2, 3))); +#endif + +#if USE_R2 +#include +#else +SStrBuf *rz_strbuf_new(const char *s); +bool rz_strbuf_set(SStrBuf *sb, const char *s); +bool rz_strbuf_append(SStrBuf *sb, const char *s); +char *rz_strbuf_get(SStrBuf *sb); +char *rz_strbuf_drain(SStrBuf *sb); +void rz_strbuf_free(SStrBuf *sb); +void rz_strbuf_fini(SStrBuf *sb); +void rz_strbuf_init(SStrBuf *sb); +int rz_sys_setenv(const char *key, const char *value); +char *rz_sys_getenv(const char *key); +int rz_sys_getpid(void); +#endif + +#endif diff --git a/shlr/spp/spp.1 b/shlr/spp/spp.1 index bded921524..08bec21ebe 100644 --- a/shlr/spp/spp.1 +++ b/shlr/spp/spp.1 @@ -21,7 +21,7 @@ ease to be embedded and used from the commandline or the API. .Pp TODO: this manpage is work-in-progress .Pp -You need radare2 to be available in $PATH. +You need rizin to be available in $PATH. .Sh OPTIONS .Bl -tag -width Fl .It Fl h diff --git a/shlr/spp/spp.c b/shlr/spp/spp.c index edae7ec1b1..a6330b97e1 100644 --- a/shlr/spp/spp.c +++ b/shlr/spp/spp.c @@ -1,11 +1,11 @@ /* MIT pancake (C) 2009-2020 */ #include "spp.h" -#include "r_api.h" +#include "rz_api.h" #include "config.h" #if !USE_R2 -#include "r_api.c" +#include "rz_api.c" #endif S_API int spp_run(char *buf, Output *out) { @@ -60,10 +60,10 @@ static char *spp_run_str(char *buf, int *rv) { char *b; Output tmp; tmp.fout = NULL; - tmp.cout = r_strbuf_new (""); + tmp.cout = rz_strbuf_new (""); int rc = spp_run (buf, &tmp); - b = strdup (r_strbuf_get (tmp.cout)); - r_strbuf_free (tmp.cout); + b = strdup (rz_strbuf_get (tmp.cout)); + rz_strbuf_free (tmp.cout); if (rv) { *rv = rc; } @@ -343,7 +343,7 @@ void out_printf(Output *out, char *str, ...) { char tmp[4096]; vsnprintf (tmp, sizeof (tmp), str, ap); tmp[sizeof (tmp) - 1] = 0; - r_strbuf_append (out->cout, tmp); + rz_strbuf_append (out->cout, tmp); } va_end (ap); } @@ -363,12 +363,12 @@ S_API char *spp_eval_str(SppProc *p, const char *code) { } Output out; out.fout = NULL; - out.cout = r_strbuf_new (NULL); - r_strbuf_init (out.cout); + out.cout = rz_strbuf_new (NULL); + rz_strbuf_init (out.cout); char *c = strdup (code); if (c) { spp_proc_eval (p, c, &out); free (c); } - return r_strbuf_drain (out.cout); + return rz_strbuf_drain (out.cout); } diff --git a/shlr/spp/spp.h b/shlr/spp/spp.h index ef15913fd7..42b68a496f 100644 --- a/shlr/spp/spp.h +++ b/shlr/spp/spp.h @@ -78,7 +78,7 @@ struct Arg *args = (struct Arg *)&x##_args; \ struct Proc *proc = &x##_proc; #if USE_R2 -#include +#include #define SStrBuf RStrBuf #else typedef struct s_strbuf_t { diff --git a/shlr/tcc/Makefile b/shlr/tcc/Makefile index e461392c89..d6b29315e3 100644 --- a/shlr/tcc/Makefile +++ b/shlr/tcc/Makefile @@ -1,4 +1,4 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../config-user.mk include ../../mk/platform.mk include ../../mk/${COMPILER}.mk @@ -6,12 +6,12 @@ OFILES=libtcc.o tccgen.o tccpp.o CFLAGS+=${PIC_CFLAGS} -LDFLAGS+=-L../../libr/util -LIBS+=-lr_util -CFLAGS+=-I../../libr/include +LDFLAGS+=-L../../librz/util +LIBS+=-lrz_util +CFLAGS+=-I../../librz/include CFLAGS+=-fstrict-aliasing -CFLAGS+=-I../../libr/include +CFLAGS+=-I../../librz/include CFLAGS+=-Wall -g LDFLAGS+=-shared ifeq (${OSNAME},darwin) @@ -25,19 +25,19 @@ EXT_AR=a SOEXT?=so endif endif -LIBNAME=libr_tcc.${SOEXT} +LIBNAME=librz_tcc.${SOEXT} include ../../shlr/sdb.mk -all: ${LIBNAME} libr_tcc.$(EXT_AR) +all: ${LIBNAME} librz_tcc.$(EXT_AR) ${LIBNAME}: ${OFILES} ${CC} $(CFLAGS) -o ${LIBNAME} ${LDFLAGS} ${LIBS} ${OFILES} -libr_tcc.$(EXT_AR): ${OFILES} - rm -f libr_tcc.$(EXT_AR) - ${AR} q libr_tcc.$(EXT_AR) ${OFILES} - ${RANLIB} libr_tcc.$(EXT_AR) +librz_tcc.$(EXT_AR): ${OFILES} + rm -f librz_tcc.$(EXT_AR) + ${AR} q librz_tcc.$(EXT_AR) ${OFILES} + ${RANLIB} librz_tcc.$(EXT_AR) clean: rm -f ${LIBNAME} *.o *.$(EXT_AR) diff --git a/shlr/tcc/libr_tcc.h b/shlr/tcc/librz_tcc.h similarity index 100% rename from shlr/tcc/libr_tcc.h rename to shlr/tcc/librz_tcc.h diff --git a/shlr/tcc/libtcc.c b/shlr/tcc/libtcc.c index 77af1951ed..92e3eac229 100644 --- a/shlr/tcc/libtcc.c +++ b/shlr/tcc/libtcc.c @@ -17,7 +17,7 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include +#include #include "tcc.h" /********************************************************/ @@ -805,13 +805,13 @@ PUB_FUNC void tcc_appendf(const char *fmt, ...) { PUB_FUNC void tcc_typedef_appendf(const char *fmt, ...) { if (!tcc_typedefs) { - tcc_typedefs = r_pvector_new ((RPVectorFree) free); + tcc_typedefs = rz_pvector_new ((RPVectorFree) free); } char typedefs_tail[1024]; va_list ap; va_start (ap, fmt); if (vsnprintf (typedefs_tail, sizeof (typedefs_tail), fmt, ap) > 0) { - r_pvector_push (tcc_typedefs, strdup (typedefs_tail)); + rz_pvector_push (tcc_typedefs, strdup (typedefs_tail)); } // XXX else? how this should behave if sizeof (typedefs_tail) is not enough? va_end (ap); } @@ -819,10 +819,10 @@ PUB_FUNC void tcc_typedef_appendf(const char *fmt, ...) { PUB_FUNC void tcc_typedef_alias_fields(const char *alias) { if (tcc_typedefs) { void **it; - r_pvector_foreach (tcc_typedefs, it) { + rz_pvector_foreach (tcc_typedefs, it) { tcc_appendf (*it, alias); } - r_pvector_free (tcc_typedefs); + rz_pvector_free (tcc_typedefs); tcc_typedefs = NULL; } } diff --git a/shlr/tcc/tcc.h b/shlr/tcc/tcc.h index bfcc5cb4e8..0dc0bc26a3 100644 --- a/shlr/tcc/tcc.h +++ b/shlr/tcc/tcc.h @@ -21,7 +21,7 @@ #ifndef _TCC_H #define _TCC_H -#include "r_types.h" +#include "rz_types.h" #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/shlr/winkd/Makefile b/shlr/winkd/Makefile index 3468dfb5ba..7bb2f8bed0 100644 --- a/shlr/winkd/Makefile +++ b/shlr/winkd/Makefile @@ -1,16 +1,16 @@ -include ../../libr/config.mk +include ../../librz/config.mk include ../../config-user.mk include ../../mk/platform.mk include ../../mk/${COMPILER}.mk CFLAGS+=${PIC_CFLAGS} -CFLAGS+=-I../../libr/include -LIBAR=libr_winkd.${EXT_AR} -LDFLAGS+=-L../../libr/crypto -lr_crypto -LDFLAGS+=-L../../libr/hash -lr_hash -LDFLAGS+=-L../../libr/socket -lr_socket -LDFLAGS+=-L../../libr/util -lr_util +CFLAGS+=-I../../librz/include +LIBAR=librz_winkd.${EXT_AR} +LDFLAGS+=-L../../librz/crypto -lrz_crypto +LDFLAGS+=-L../../librz/hash -lrz_hash +LDFLAGS+=-L../../librz/socket -lrz_socket +LDFLAGS+=-L../../librz/util -lrz_util include ../../shlr/sdb.mk diff --git a/shlr/winkd/deps.mk b/shlr/winkd/deps.mk index d271c9b357..dfe662d31e 100644 --- a/shlr/winkd/deps.mk +++ b/shlr/winkd/deps.mk @@ -1,3 +1,3 @@ -LINK+=$(STOP)/winkd/libr_winkd.${EXT_AR} -LDFLAGS+=-lr_crypto -lr_hash +LINK+=$(STOP)/winkd/librz_winkd.${EXT_AR} +LDFLAGS+=-lrz_crypto -lrz_hash include $(LIBR)/socket/deps.mk diff --git a/shlr/winkd/iob_net.c b/shlr/winkd/iob_net.c index cde5a10840..8424c5a44f 100644 --- a/shlr/winkd/iob_net.c +++ b/shlr/winkd/iob_net.c @@ -1,16 +1,16 @@ // Copyright (c) 2014-2020, abcSup, All rights reserved. LGPLv3 #include -#include -#include -#include -#include +#include +#include +#include +#include #include "kd.h" #include "transport.h" typedef struct iobnet_t { - RSocket *sock; + RzSocket *sock; bool hasDatakey; // Internal buffer @@ -76,18 +76,18 @@ static ut64 base36_decode(const char *str) { * @param resbuf, the buffer that contains the KDNet Data of a Response packet. */ static bool _initializeDatakey(iobnet_t *obj, ut8 *resbuf, int size) { - RHash *ctx = r_hash_new (true, R_HASH_SHA256); + RzHash *ctx = rz_hash_new (true, R_HASH_SHA256); if (!ctx) { return false; } // Data Key = SHA256 (Key || resbuf) - r_hash_do_begin (ctx, R_HASH_SHA256); - r_hash_do_sha256 (ctx, obj->key, R_HASH_SIZE_SHA256); - r_hash_do_sha256 (ctx, resbuf, size); - r_hash_do_end (ctx, R_HASH_SHA256); + rz_hash_do_begin (ctx, R_HASH_SHA256); + rz_hash_do_sha256 (ctx, obj->key, R_HASH_SIZE_SHA256); + rz_hash_do_sha256 (ctx, resbuf, size); + rz_hash_do_end (ctx, R_HASH_SHA256); memcpy (obj->datakey, ctx->digest, R_HASH_SIZE_SHA256); - r_hash_free (ctx); + rz_hash_free (ctx); return true; } @@ -122,7 +122,7 @@ static void *iob_net_open(const char *path) { if (nkey) { *nkey++ = 0; } - r_write_le64 (obj->key + i * 8, base36_decode (key)); + rz_write_le64 (obj->key + i * 8, base36_decode (key)); } // HMAC Key is the negation of AES-256 Control Key bytes @@ -130,8 +130,8 @@ static void *iob_net_open(const char *path) { obj->hmackey[i] = ~(obj->key[i]); } - RSocket *sock = r_socket_new (0); - if (!r_socket_connect_udp (sock, host, port, 1)) { + RzSocket *sock = rz_socket_new (0); + if (!rz_socket_connect_udp (sock, host, port, 1)) { free (host); free (obj); return NULL; @@ -146,34 +146,34 @@ static bool iob_net_close(void *p) { int ret = true; iobnet_t *obj = (iobnet_t *)p; - if (r_socket_close (obj->sock)) { + if (rz_socket_close (obj->sock)) { ret = false; } - r_socket_free (obj->sock); + rz_socket_free (obj->sock); free (obj); return ret; } static bool _encrypt(iobnet_t *obj, ut8 *buf, int size, int type) { bool ret = false; - RCrypto *cry = r_crypto_new (); + RzCrypto *cry = rz_crypto_new (); if (!cry) { return false; } - if (!r_crypto_use (cry, "aes-cbc")) { + if (!rz_crypto_use (cry, "aes-cbc")) { goto end; } // Set AES-256 Key based on the KDNet packet type switch (type) { case KDNET_PACKET_TYPE_DATA: - if (!r_crypto_set_key (cry, obj->datakey, sizeof (obj->datakey), 0, 0)) { + if (!rz_crypto_set_key (cry, obj->datakey, sizeof (obj->datakey), 0, 0)) { goto end; } break; case KDNET_PACKET_TYPE_CONTROL: // Control Channel - if (!r_crypto_set_key (cry, obj->key, sizeof (obj->key), 0, 0)) { + if (!rz_crypto_set_key (cry, obj->key, sizeof (obj->key), 0, 0)) { goto end; } break; @@ -182,17 +182,17 @@ static bool _encrypt(iobnet_t *obj, ut8 *buf, int size, int type) { } // Set IV to the 16 bytes HMAC at the end of KDNet packet - if (!r_crypto_set_iv (cry, buf + size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE)) { + if (!rz_crypto_set_iv (cry, buf + size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE)) { goto end; } // Encrypt the buffer except HMAC - if (r_crypto_final (cry, buf, size - KDNET_HMAC_SIZE) == 0) { + if (rz_crypto_final (cry, buf, size - KDNET_HMAC_SIZE) == 0) { goto end; } // Overwrite the buffer with encrypted data int sz; - ut8 *encbuf = r_crypto_get_output (cry, &sz); + ut8 *encbuf = rz_crypto_get_output (cry, &sz); if (!encbuf) { goto end; } @@ -201,7 +201,7 @@ static bool _encrypt(iobnet_t *obj, ut8 *buf, int size, int type) { free (encbuf); ret = true; end: - r_crypto_free (cry); + rz_crypto_free (cry); return ret; } @@ -227,29 +227,29 @@ static ut8 *_createKDNetPacket(iobnet_t *obj, const ut8 *buf, int size, int *osi } // Write KDNet Header - r_write_at_be32 (encbuf, KDNET_MAGIC, 0); // Magic - r_write_at_be8 (encbuf, obj->version, 4); // Protocol Number - r_write_at_be8 (encbuf, type, 5); // Channel Type + rz_write_at_be32 (encbuf, KDNET_MAGIC, 0); // Magic + rz_write_at_be8 (encbuf, obj->version, 4); // Protocol Number + rz_write_at_be8 (encbuf, type, 5); // Channel Type // Write KDNet Data (8 bytes) // seqno (7 bytes) | direction (4 bits) | padsize (4 bits) // seqno - sequence number // direction - 0x0 Debuggee -> Debugger, 0x8 Debugger -> Debuggee - r_write_at_be64 (encbuf, ((seqno << 8) | 0x8 << 4 | padsize), 6); + rz_write_at_be64 (encbuf, ((seqno << 8) | 0x8 << 4 | padsize), 6); // Copy KD Packet from buffer memcpy (encbuf + sizeof (kdnet_packet_t) + KDNET_DATA_SIZE, buf, size); // Generate HMAC from KDNet Data to KD packet int off = sizeof (kdnet_packet_t) + KDNET_DATA_SIZE + size + padsize; - RHash *ctx = r_hash_new (true, R_HASH_SHA256); + RzHash *ctx = rz_hash_new (true, R_HASH_SHA256); if (!ctx) { free (encbuf); return NULL; } - r_hash_do_hmac_sha256 (ctx, encbuf, off, obj->hmackey, KDNET_HMACKEY_SIZE); + rz_hash_do_hmac_sha256 (ctx, encbuf, off, obj->hmackey, KDNET_HMACKEY_SIZE); // Append KDNet HMAC at the end of encbuf memcpy (encbuf + off, ctx->digest, KDNET_HMAC_SIZE); - r_hash_free (ctx); + rz_hash_free (ctx); // Encrypt the KDNet Data, KD Packet and padding if (!_encrypt (obj, encbuf + sizeof (kdnet_packet_t), encsize - sizeof (kdnet_packet_t), type)) { @@ -265,23 +265,23 @@ static ut8 *_createKDNetPacket(iobnet_t *obj, const ut8 *buf, int size, int *osi static bool _decrypt(iobnet_t *obj, ut8 *buf, int size, int type) { bool ret = false; - RCrypto *cry = r_crypto_new (); + RzCrypto *cry = rz_crypto_new (); if (!cry) { return false; } - if (!r_crypto_use (cry, "aes-cbc")) { + if (!rz_crypto_use (cry, "aes-cbc")) { goto end; } // Set AES-256 Key based on the KDNet packet type switch (type) { case KDNET_PACKET_TYPE_DATA: - if (!r_crypto_set_key (cry, obj->datakey, sizeof (obj->datakey), 0, 1)) { + if (!rz_crypto_set_key (cry, obj->datakey, sizeof (obj->datakey), 0, 1)) { goto end; } break; case KDNET_PACKET_TYPE_CONTROL: - if (!r_crypto_set_key (cry, obj->key, sizeof (obj->key), 0, 1)) { + if (!rz_crypto_set_key (cry, obj->key, sizeof (obj->key), 0, 1)) { goto end; } break; @@ -290,17 +290,17 @@ static bool _decrypt(iobnet_t *obj, ut8 *buf, int size, int type) { } // Set IV to the 16 bytes HMAC at the end of KDNet packet - if (!r_crypto_set_iv (cry, buf + size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE)) { + if (!rz_crypto_set_iv (cry, buf + size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE)) { goto end; } // Decrypt the buffer except HMAC - if (r_crypto_final (cry, buf, size - KDNET_HMAC_SIZE) == 0) { + if (rz_crypto_final (cry, buf, size - KDNET_HMAC_SIZE) == 0) { goto end; } // Overwrite it with decrypted data int sz; - ut8 *decbuf = r_crypto_get_output (cry, &sz); + ut8 *decbuf = rz_crypto_get_output (cry, &sz); if (!decbuf) { goto end; } @@ -309,7 +309,7 @@ static bool _decrypt(iobnet_t *obj, ut8 *buf, int size, int type) { free (decbuf); end: - r_crypto_free (cry); + rz_crypto_free (cry); return ret; } @@ -339,18 +339,18 @@ static bool _sendResponsePacket(iobnet_t *obj, const ut8 *pokedata) { memcpy (resbuf + 2, pokedata + 10, 32); // Generate 32 bytes random Host Key for (i = 0; i < 32; i++) { - int rand = r_num_rand (0xFF); + int rand = rz_num_rand (0xFF); resbuf[i + 34] = rand & 0xFF; } // Set seqno to the same seqno in Poke packet - ut64 seqno = r_read_be64 (pokedata) >> 8; + ut64 seqno = rz_read_be64 (pokedata) >> 8; ut8 *pkt = _createKDNetPacket (obj, resbuf, 322, &size, seqno, 1); if (!pkt) { free (resbuf); } - if (r_socket_write (obj->sock, (void *)pkt, size) < 0) { + if (rz_socket_write (obj->sock, (void *)pkt, size) < 0) { free (pkt); free (resbuf); return false; @@ -369,7 +369,7 @@ static bool _processControlPacket(iobnet_t *obj, const ut8 *ctrlbuf, int size) { return true; } // Read KDNet Data to verify direction flag - ut64 kdnetdata = r_read_be64 (ctrlbuf); + ut64 kdnetdata = rz_read_be64 (ctrlbuf); if ((kdnetdata & 0x80) != 0) { eprintf ("Error: KdNet wrong direction flag\n"); return false; @@ -385,14 +385,14 @@ static bool _processControlPacket(iobnet_t *obj, const ut8 *ctrlbuf, int size) { } bool _verifyhmac(iobnet_t *obj) { - RHash *ctx = r_hash_new (true, R_HASH_SHA256); + RzHash *ctx = rz_hash_new (true, R_HASH_SHA256); if (!ctx) { return false; } - r_hash_do_hmac_sha256 (ctx, obj->buf, obj->size - KDNET_HMAC_SIZE, obj->hmackey, KDNET_HMACKEY_SIZE); + rz_hash_do_hmac_sha256 (ctx, obj->buf, obj->size - KDNET_HMAC_SIZE, obj->hmackey, KDNET_HMACKEY_SIZE); int ret = memcmp (ctx->digest, obj->buf + obj->size - KDNET_HMAC_SIZE, KDNET_HMAC_SIZE); - r_hash_free (ctx); + rz_hash_free (ctx); return ret == 0; } @@ -402,9 +402,9 @@ static int iob_net_read(void *p, uint8_t *obuf, const uint64_t count, const int if (obj->size == 0) { do { - obj->size = r_socket_read (obj->sock, obj->buf, 4096); + obj->size = rz_socket_read (obj->sock, obj->buf, 4096); if (obj->size < 0) { - // Continue if RCons breaks + // Continue if RzCons breaks if (errno == EINTR) { continue; } @@ -414,7 +414,7 @@ static int iob_net_read(void *p, uint8_t *obuf, const uint64_t count, const int memcpy (&pkt, obj->buf, sizeof (kdnet_packet_t)); // Verify the KDNet Header magic - if (r_read_be32 (obj->buf) != KDNET_MAGIC) { + if (rz_read_be32 (obj->buf) != KDNET_MAGIC) { eprintf ("Error: KdNet bad magic\n"); obj->size = 0; return -1; @@ -446,7 +446,7 @@ static int iob_net_read(void *p, uint8_t *obuf, const uint64_t count, const int } while (pkt.type == KDNET_PACKET_TYPE_CONTROL); // Remove padding from the buffer - ut8 padsize = r_read_at_be64 (obj->buf, sizeof (kdnet_packet_t)) & 0xF; + ut8 padsize = rz_read_at_be64 (obj->buf, sizeof (kdnet_packet_t)) & 0xF; obj->size -= KDNET_HMAC_SIZE + padsize; // Seek to KD packet @@ -454,7 +454,7 @@ static int iob_net_read(void *p, uint8_t *obuf, const uint64_t count, const int // KD_PACKET_TYPE_UNUSED KD packet does not have a checksum, // but kd_read_packet always read for the 4-byte checksum - if (r_read_at_be16 (obj->buf, obj->off + 4) == KD_PACKET_TYPE_UNUSED) { + if (rz_read_at_be16 (obj->buf, obj->off + 4) == KD_PACKET_TYPE_UNUSED) { obj->size += 4; } } @@ -506,7 +506,7 @@ static int iob_net_write(void *p, const uint8_t *buf, const uint64_t count, cons if (!pkt) { return -1; } - if (r_socket_write (obj->sock, (void *)pkt, size) < 0) { + if (rz_socket_write (obj->sock, (void *)pkt, size) < 0) { free (pkt); return -1; } diff --git a/shlr/winkd/iob_pipe.c b/shlr/winkd/iob_pipe.c index 74caa6cd12..1efba6b36e 100644 --- a/shlr/winkd/iob_pipe.c +++ b/shlr/winkd/iob_pipe.c @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #include "transport.h" #if __WINDOWS__ @@ -11,7 +11,7 @@ static void *iob_pipe_open(const char *path) { HANDLE hPipe; - LPTSTR path_ = r_sys_conv_utf8_to_win (path); + LPTSTR path_ = rz_sys_conv_utf8_to_win (path); hPipe = CreateFile (path_, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); free (path_); @@ -31,7 +31,7 @@ static int iob_pipe_read(void *p, uint8_t *buf, const uint64_t count, const int } if (!ReadFile (p, buf, count, NULL, &ov) && GetLastError () != ERROR_IO_PENDING) { - r_sys_perror ("ReadFile"); + rz_sys_perror ("ReadFile"); return -1; } if (WaitForSingleObject (ov.hEvent, timeout) == WAIT_TIMEOUT) { @@ -47,7 +47,7 @@ static int iob_pipe_write(void *p, const uint8_t *buf, const uint64_t count, con OVERLAPPED ov = {0}; if (!WriteFile (p, buf, count, NULL, &ov) && GetLastError () != ERROR_IO_PENDING) { - r_sys_perror ("WriteFile"); + rz_sys_perror ("WriteFile"); return -1; } GetOverlappedResult (p, &ov, &cbWrited, TRUE); @@ -117,7 +117,7 @@ static int iob_pipe_read(void *p, uint8_t *buf, const uint64_t count, const int static int iob_pipe_write(void *p, const uint8_t *buf, const uint64_t count, const int timeout) { int ret = send ((int) (size_t) p, buf, count, 0); if (ret < 1) { - r_sys_perror ("iob_pipe_write, send"); + rz_sys_perror ("iob_pipe_write, send"); if (errno == EPIPE) { exit (1); } diff --git a/shlr/winkd/kd.h b/shlr/winkd/kd.h index 1c930ebaf7..7b83d31441 100644 --- a/shlr/winkd/kd.h +++ b/shlr/winkd/kd.h @@ -1,7 +1,7 @@ // Copyright (c) 2014-2017, The Lemon Man, All rights reserved. LGPLv3 #ifndef KD_H #define KD_H -#include +#include #include "transport.h" enum { @@ -115,7 +115,7 @@ typedef struct kd_req_t { uint64_t addr; uint32_t length; uint32_t read; - }) r_mem; + }) rz_mem; R_PACKED ( struct { uint16_t major; @@ -128,39 +128,39 @@ typedef struct kd_req_t { uint64_t kernel_base; uint64_t mod_addr; uint64_t dbg_addr; - }) r_ver; + }) rz_ver; struct { uint32_t reason; uint32_t tf; uint32_t dr7; uint32_t css; uint32_t cse; - } r_cont; + } rz_cont; struct { uint64_t addr; uint32_t handle; - } r_set_bp; + } rz_set_bp; struct { uint32_t handle; - } r_del_bp; + } rz_del_bp; struct { uint64_t addr; uint32_t flags; - } r_set_ibp; + } rz_set_ibp; struct { uint64_t addr; uint32_t flags; uint32_t calls; - } r_get_ibp; + } rz_get_ibp; struct { uint32_t flags; - } r_ctx; + } rz_ctx; struct { uint64_t addr; uint64_t reserved; uint32_t address_space; uint32_t flags; - } r_query_mem; + } rz_query_mem; // Pad the struct to 56 bytes uint8_t raw[40]; diff --git a/shlr/winkd/transport.c b/shlr/winkd/transport.c index 12ef8de612..063113609a 100644 --- a/shlr/winkd/transport.c +++ b/shlr/winkd/transport.c @@ -1,5 +1,5 @@ // Copyright (c) 2014-2017, The Lemon Man, All rights reserved. LGPLv3 -#include +#include #include "transport.h" io_desc_t *io_desc_new(io_backend_t *iob, void *fp) { @@ -13,14 +13,14 @@ io_desc_t *io_desc_new(io_backend_t *iob, void *fp) { int iob_write(io_desc_t *desc, const uint8_t *buf, const uint32_t buf_len) { uint32_t done; - static RThreadLock *lock = NULL; + static RzThreadLock *lock = NULL; if (!lock) { - lock = r_th_lock_new (true); + lock = rz_th_lock_new (true); } if (!desc || !desc->iob || !desc->fp) { return E_NOIF; } - r_th_lock_enter (lock); + rz_th_lock_enter (lock); for (done = 0; done < buf_len;) { int ret = desc->iob->write (desc->fp, buf + done, buf_len - done, 100); if (ret < 1) { @@ -28,20 +28,20 @@ int iob_write(io_desc_t *desc, const uint8_t *buf, const uint32_t buf_len) { } done += ret; } - r_th_lock_leave (lock); + rz_th_lock_leave (lock); return done; } int iob_read(io_desc_t *desc, uint8_t *buf, const uint32_t buf_len) { uint32_t done; - static RThreadLock *lock = NULL; + static RzThreadLock *lock = NULL; if (!lock) { - lock = r_th_lock_new (true); + lock = rz_th_lock_new (true); } if (!desc || !desc->iob || !desc->fp) { return E_NOIF; } - r_th_lock_enter (lock); + rz_th_lock_enter (lock); for (done = 0; done < buf_len;) { int ret = desc->iob->read (desc->fp, buf + done, buf_len - done, 100); if (ret < 0) { @@ -49,6 +49,6 @@ int iob_read(io_desc_t *desc, uint8_t *buf, const uint32_t buf_len) { } done += ret; } - r_th_lock_leave (lock); + rz_th_lock_leave (lock); return done; } diff --git a/shlr/winkd/transport.h b/shlr/winkd/transport.h index bfda028925..550ed240e2 100644 --- a/shlr/winkd/transport.h +++ b/shlr/winkd/transport.h @@ -1,7 +1,7 @@ #ifndef _TRANSPORT_H_ #define _TRANSPORT_H_ -#include +#include #include #ifndef HAVE_EPRINTF diff --git a/shlr/winkd/winkd.c b/shlr/winkd/winkd.c index 27e5debbd1..c79c8c200a 100644 --- a/shlr/winkd/winkd.c +++ b/shlr/winkd/winkd.c @@ -4,9 +4,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "transport.h" #include "winkd.h" #include "kd.h" @@ -78,30 +78,30 @@ struct _WindCtx { int pae; int is_x64; Profile *os_profile; - RList *plist_cache; - RList *tlist_cache; + RzList *plist_cache; + RzList *tlist_cache; ut64 dbg_addr; WindProc *target; - RThreadLock *dontmix; + RzThreadLock *dontmix; }; bool winkd_lock_enter(WindCtx *ctx) { - r_cons_break_push (winkd_break, ctx); - r_th_lock_enter (ctx->dontmix); + rz_cons_break_push (winkd_break, ctx); + rz_th_lock_enter (ctx->dontmix); return true; } bool winkd_lock_tryenter(WindCtx *ctx) { - if (!r_th_lock_tryenter (ctx->dontmix)) { + if (!rz_th_lock_tryenter (ctx->dontmix)) { return false; } - r_cons_break_push (winkd_break, ctx); + rz_cons_break_push (winkd_break, ctx); return true; } bool winkd_lock_leave(WindCtx *ctx) { - r_cons_break_pop (); - r_th_lock_leave (ctx->dontmix); + rz_cons_break_pop (); + rz_th_lock_leave (ctx->dontmix); return true; } @@ -133,10 +133,10 @@ int winkd_get_cpu(WindCtx *ctx) { bool winkd_set_target(WindCtx *ctx, uint32_t pid) { WindProc *p; - RListIter *it; + RzListIter *it; if (pid) { - RList *l = winkd_list_process (ctx); - r_list_foreach (l, it, p) { + RzList *l = winkd_list_process (ctx); + rz_list_foreach (l, it, p) { if (p->uniqueid == pid) { ctx->target = p; return true; @@ -175,7 +175,7 @@ WindCtx *winkd_ctx_new(io_desc_t *desc) { if (!ctx) { return NULL; } - ctx->dontmix = r_th_lock_new (true); + ctx->dontmix = rz_th_lock_new (true); ctx->desc = desc; return ctx; } @@ -184,12 +184,12 @@ void winkd_ctx_free(WindCtx **ctx) { if (!ctx || !*ctx) { return; } - r_list_free ((*ctx)->plist_cache); - r_list_free ((*ctx)->tlist_cache); + rz_list_free ((*ctx)->plist_cache); + rz_list_free ((*ctx)->tlist_cache); io_desc_t *desc = (*ctx)->desc; desc->iob->close (desc->fp); R_FREE (desc); - r_th_lock_free ((*ctx)->dontmix); + rz_th_lock_free ((*ctx)->dontmix); R_FREE (*ctx); } @@ -284,7 +284,7 @@ int winkd_wait_packet(WindCtx *ctx, const uint32_t type, kd_packet_t **p) { // Check for RESEND // The host didn't like our request if (pkt->leader == KD_PACKET_CTRL && pkt->type == KD_PACKET_TYPE_RESEND) { - r_sys_backtrace (); + rz_sys_backtrace (); WIND_DBG eprintf ("Waoh. You probably sent a malformed packet !\n"); ret = KD_E_MALFORMED; break; @@ -349,8 +349,8 @@ int winkd_walk_vadtree(WindCtx *ctx, ut64 address, ut64 parent) { return 1; } -RList *winkd_list_process(WindCtx *ctx) { - RList *ret; +RzList *winkd_list_process(WindCtx *ctx) { + RzList *ret; ut64 ptr, base; if (!ctx || !ctx->desc || !ctx->syncd) { @@ -376,7 +376,7 @@ RList *winkd_list_process(WindCtx *ctx) { if (ptr == 0) { return NULL; } - ret = r_list_newf (free); + ret = rz_list_newf (free); do { uint8_t buf[17]; @@ -413,7 +413,7 @@ RList *winkd_list_process(WindCtx *ctx) { proc->dir_base_table = dir_base_table; proc->peb = peb; - r_list_append (ret, proc); + rz_list_append (ret, proc); // winkd_walk_vadtree(ctx, vadroot, -1); ptr = next; @@ -460,8 +460,8 @@ int winkd_read_at_uva(WindCtx *ctx, uint8_t *buf, ut64 offset, int count) { return totread; } -RList *winkd_list_modules(WindCtx *ctx) { - RList *ret; +RzList *winkd_list_modules(WindCtx *ctx) { + RzList *ret; ut64 ptr, base; if (!ctx || !ctx->desc || !ctx->syncd) { @@ -495,7 +495,7 @@ RList *winkd_list_modules(WindCtx *ctx) { WIND_DBG eprintf ("InMemoryOrderModuleList : 0x%016"PFMT64x "\n", ptr); - ret = r_list_newf (free); + ret = rz_list_newf (free); const ut64 baseoff = ctx->is_x64 ? 0x30 : 0x18; const ut64 sizeoff = ctx->is_x64 ? 0x40 : 0x20; @@ -542,15 +542,15 @@ RList *winkd_list_modules(WindCtx *ctx) { free (unname); ptr = next; - r_list_append (ret, mod); + rz_list_append (ret, mod); } while (ptr != base); return ret; } -RList *winkd_list_threads(WindCtx *ctx) { - RList *ret; +RzList *winkd_list_threads(WindCtx *ctx) { + RzList *ret; ut64 ptr, base; if (!ctx || !ctx->desc || !ctx->syncd) { @@ -580,7 +580,7 @@ RList *winkd_list_threads(WindCtx *ctx) { base = ptr; - ret = r_list_newf (free); + ret = rz_list_newf (free); do { ut64 next = 0; @@ -607,7 +607,7 @@ RList *winkd_list_threads(WindCtx *ctx) { thread->ethread = ptr; thread->entrypoint = entrypoint; - r_list_append (ret, thread); + rz_list_append (ret, thread); } ptr = next; @@ -760,30 +760,30 @@ bool winkd_read_ver(WindCtx *ctx) { } WIND_DBG { - eprintf ("Major : %i Minor %i\n", rr->r_ver.major, rr->r_ver.minor); - eprintf ("Protocol version : %i.%i\n", rr->r_ver.proto_major, rr->r_ver.proto_minor); - eprintf ("Flags : %08x\n", rr->r_ver.flags); - eprintf ("Machine : %08x\n", rr->r_ver.machine); - eprintf ("Module list : %016"PFMT64x "\n", (ut64) rr->r_ver.mod_addr); - eprintf ("Debug block : %016"PFMT64x "\n", (ut64) rr->r_ver.dbg_addr); + eprintf ("Major : %i Minor %i\n", rr->rz_ver.major, rr->rz_ver.minor); + eprintf ("Protocol version : %i.%i\n", rr->rz_ver.proto_major, rr->rz_ver.proto_minor); + eprintf ("Flags : %08x\n", rr->rz_ver.flags); + eprintf ("Machine : %08x\n", rr->rz_ver.machine); + eprintf ("Module list : %016"PFMT64x "\n", (ut64) rr->rz_ver.mod_addr); + eprintf ("Debug block : %016"PFMT64x "\n", (ut64) rr->rz_ver.dbg_addr); } - if (rr->r_ver.machine != KD_MACH_I386 && rr->r_ver.machine != KD_MACH_AMD64) { + if (rr->rz_ver.machine != KD_MACH_I386 && rr->rz_ver.machine != KD_MACH_AMD64) { eprintf ("Unsupported target host\n"); free (pkt); return 0; } - if (!(rr->r_ver.flags & DBGKD_VERS_FLAG_DATA)) { + if (!(rr->rz_ver.flags & DBGKD_VERS_FLAG_DATA)) { eprintf ("No _KDDEBUGGER_DATA64 pointer has been supplied by the debugee!\n"); free (pkt); return 0; } - ctx->is_x64 = (rr->r_ver.machine == KD_MACH_AMD64); + ctx->is_x64 = (rr->rz_ver.machine == KD_MACH_AMD64); ut64 ptr = 0; - if (!winkd_read_at (ctx, (uint8_t *) &ptr, rr->r_ver.dbg_addr, 4 << ctx->is_x64)) { + if (!winkd_read_at (ctx, (uint8_t *) &ptr, rr->rz_ver.dbg_addr, 4 << ctx->is_x64)) { free (pkt); return false; } @@ -804,7 +804,7 @@ bool winkd_read_ver(WindCtx *ctx) { winkd_read_at (ctx, (uint8_t *) &ptr, ptr, 4 << ctx->is_x64); ctx->pae = pae_enabled & 1; - ctx->os_profile = winkd_get_profile (32 << ctx->is_x64, rr->r_ver.minor, (ptr >> 8) & 0xff); + ctx->os_profile = winkd_get_profile (32 << ctx->is_x64, rr->rz_ver.minor, (ptr >> 8) & 0xff); if (!ctx->os_profile) { eprintf ("Could not find a suitable profile for the target OS\n"); free (pkt); @@ -877,9 +877,9 @@ int winkd_sync(WindCtx *ctx) { ctx->cpu = stc64->cpu; ctx->cpu_count = stc64->cpu_count; ctx->target = NULL; - r_list_free (ctx->plist_cache); + rz_list_free (ctx->plist_cache); ctx->plist_cache = NULL; - r_list_free (ctx->tlist_cache); + rz_list_free (ctx->tlist_cache); ctx->tlist_cache = NULL; ctx->pae = 0; // We're ready to go @@ -905,10 +905,10 @@ int winkd_continue(WindCtx *ctx) { } req.req = DbgKdContinueApi; req.cpu = ctx->cpu; - req.r_cont.reason = 0x10001; + req.rz_cont.reason = 0x10001; // The meaning of 0x400 is unknown, but Windows doesn't // behave like suggested by ReactOS source - req.r_cont.tf = 0x400; + req.rz_cont.tf = 0x400; winkd_lock_enter (ctx); @@ -917,7 +917,7 @@ int winkd_continue(WindCtx *ctx) { if (ret == KD_E_OK) { ret = winkd_wait_packet (ctx, KD_PACKET_TYPE_ACKNOWLEDGE, NULL); if (ret == KD_E_OK) { - r_list_free (ctx->plist_cache); + rz_list_free (ctx->plist_cache); ctx->plist_cache = NULL; ret = true; goto end; @@ -942,7 +942,7 @@ bool winkd_write_reg(WindCtx *ctx, const uint8_t *buf, int size) { } req.req = DbgKdSetContextApi; req.cpu = ctx->cpu; - req.r_ctx.flags = 0x1003F; + req.rz_ctx.flags = 0x1003F; WIND_DBG eprintf("Regwrite() size: %x\n", size); @@ -996,7 +996,7 @@ int winkd_read_reg(WindCtx *ctx, uint8_t *buf, int size) { req.req = DbgKdGetContextApi; req.cpu = ctx->cpu; - req.r_ctx.flags = 0x1003F; + req.rz_ctx.flags = 0x1003F; // Don't wait on the lock in read_reg since it's frequently called. Otherwise the user // will be forced to interrupt exit read_reg constantly while another task is in progress @@ -1054,8 +1054,8 @@ int winkd_query_mem(WindCtx *ctx, const ut64 addr, int *address_space, int *flag req.req = DbgKdQueryMemoryApi; req.cpu = ctx->cpu; - req.r_query_mem.addr = addr; - req.r_query_mem.address_space = 0; // Tells the kernel that 'addr' is a virtual address + req.rz_query_mem.addr = addr; + req.rz_query_mem.address_space = 0; // Tells the kernel that 'addr' is a virtual address winkd_lock_enter (ctx); @@ -1085,10 +1085,10 @@ int winkd_query_mem(WindCtx *ctx, const ut64 addr, int *address_space, int *flag } if (address_space) { - *address_space = rr->r_query_mem.address_space; + *address_space = rr->rz_query_mem.address_space; } if (flags) { - *flags = rr->r_query_mem.flags; + *flags = rr->rz_query_mem.flags; } free (pkt); @@ -1115,9 +1115,9 @@ int winkd_bkpt(WindCtx *ctx, const ut64 addr, const int set, const int hw, int * req.cpu = ctx->cpu; if (set) { - req.r_set_bp.addr = addr; + req.rz_set_bp.addr = addr; } else { - req.r_del_bp.handle = *handle; + req.rz_del_bp.handle = *handle; } winkd_lock_enter (ctx); @@ -1146,7 +1146,7 @@ int winkd_bkpt(WindCtx *ctx, const ut64 addr, const int set, const int hw, int * free (pkt); return 0; } - *handle = rr->r_set_bp.handle; + *handle = rr->rz_set_bp.handle; ret = !!rr->ret; free (pkt); return ret; @@ -1167,9 +1167,9 @@ int winkd_read_at_phys(WindCtx *ctx, uint8_t *buf, const ut64 offset, const int } req.req = DbgKdReadPhysicalMemoryApi; req.cpu = ctx->cpu; - req.r_mem.addr = offset; - req.r_mem.length = R_MIN (count, KD_MAX_PAYLOAD); - req.r_mem.read = 0; // Default caching option + req.rz_mem.addr = offset; + req.rz_mem.length = R_MIN (count, KD_MAX_PAYLOAD); + req.rz_mem.read = 0; // Default caching option // Don't wait on the lock in read_reg since it's frequently called. Otherwise the user // will be forced to interrupt exit read_at_phys constantly while another task is in progress @@ -1202,8 +1202,8 @@ int winkd_read_at_phys(WindCtx *ctx, uint8_t *buf, const ut64 offset, const int return 0; } - memcpy (buf, rr->data, rr->r_mem.read); - ret = rr->r_mem.read; + memcpy (buf, rr->data, rr->rz_mem.read); + ret = rr->rz_mem.read; free (pkt); return ret; error: @@ -1223,8 +1223,8 @@ int winkd_read_at(WindCtx *ctx, uint8_t *buf, const ut64 offset, const int count } req.req = DbgKdReadVirtualMemoryApi; req.cpu = ctx->cpu; - req.r_mem.addr = offset; - req.r_mem.length = R_MIN (count, KD_MAX_PAYLOAD); + req.rz_mem.addr = offset; + req.rz_mem.length = R_MIN (count, KD_MAX_PAYLOAD); // Don't wait on the lock in read_at since it's frequently called, including each // time "enter" is pressed. Otherwise the user will be forced to interrupt exit @@ -1257,8 +1257,8 @@ int winkd_read_at(WindCtx *ctx, uint8_t *buf, const ut64 offset, const int count return 0; } - memcpy (buf, rr->data, rr->r_mem.read); - ret = rr->r_mem.read; + memcpy (buf, rr->data, rr->rz_mem.read); + ret = rr->rz_mem.read; free (pkt); return ret; error: @@ -1280,8 +1280,8 @@ int winkd_write_at(WindCtx *ctx, const uint8_t *buf, const ut64 offset, const in payload = R_MIN (count, KD_MAX_PAYLOAD - sizeof(kd_req_t)); req.req = DbgKdWriteVirtualMemoryApi; req.cpu = ctx->cpu; - req.r_mem.addr = offset; - req.r_mem.length = payload; + req.rz_mem.addr = offset; + req.rz_mem.length = payload; winkd_lock_enter (ctx); @@ -1311,7 +1311,7 @@ int winkd_write_at(WindCtx *ctx, const uint8_t *buf, const ut64 offset, const in return 0; } - ret = rr->r_mem.read; + ret = rr->rz_mem.read; free (pkt); return ret; error: @@ -1336,9 +1336,9 @@ int winkd_write_at_phys(WindCtx *ctx, const uint8_t *buf, const ut64 offset, con req.req = DbgKdWritePhysicalMemoryApi; req.cpu = ctx->cpu; - req.r_mem.addr = offset; - req.r_mem.length = payload; - req.r_mem.read = 0; // Default caching option + req.rz_mem.addr = offset; + req.rz_mem.length = payload; + req.rz_mem.read = 0; // Default caching option winkd_lock_enter (ctx); @@ -1366,7 +1366,7 @@ int winkd_write_at_phys(WindCtx *ctx, const uint8_t *buf, const ut64 offset, con free (pkt); return 0; } - ret = rr->r_mem.read; + ret = rr->rz_mem.read; free (pkt); return ret; error: diff --git a/shlr/winkd/winkd.h b/shlr/winkd/winkd.h index 966f5d6aac..762d89d678 100644 --- a/shlr/winkd/winkd.h +++ b/shlr/winkd/winkd.h @@ -82,9 +82,9 @@ int winkd_get_bits(WindCtx *ctx); ut64 winkd_get_target_base(WindCtx *ctx); ut32 winkd_get_target(WindCtx *ctx); bool winkd_set_target(WindCtx *ctx, ut32 pid); -RList *winkd_list_process(WindCtx *ctx); -RList *winkd_list_threads(WindCtx *ctx); -RList *winkd_list_modules(WindCtx *ctx); +RzList *winkd_list_process(WindCtx *ctx); +RzList *winkd_list_threads(WindCtx *ctx); +RzList *winkd_list_modules(WindCtx *ctx); int winkd_get_cpus(WindCtx *ctx); bool winkd_set_cpu(WindCtx *ctx, int cpu); int winkd_get_cpu(WindCtx *ctx); diff --git a/shlr/www/enyo/r2app.js b/shlr/www/enyo/rzapp.js similarity index 98% rename from shlr/www/enyo/r2app.js rename to shlr/www/enyo/rzapp.js index c27fc18573..ecdaa0f712 100644 --- a/shlr/www/enyo/r2app.js +++ b/shlr/www/enyo/rzapp.js @@ -1,4 +1,4 @@ -enyo.kind({name:"About",kind:"Scroller",style:"background-color:#303030",components:[{tag:"center",components:[{tag:"h1",style:"color:#f0f0f0",content:"r2wui"},{kind:"Image",src:"icon.png"},{tag:"h3",style:"color:#707070;margin-bottom:50px",content:"the web frontend for radare2"},{tag:"h2",style:"color:#a0a0a0",content:"author: pancake 2013-2014"},{tag:"h2",style:"color:#a0a0a0",content:"version: ???",name:"vertext"},{tag:"h2",style:"color:#a0a0a0",content:"revision: ???",name:"revtext"}]}],create:function(){this.inherited(arguments),function(t){setTimeout(function(){r2.cmd("?V",function(e){var n=e.split(" ")[0],o=e.split(" ")[2];t.$.vertext.setContent("version: "+n),t.$.revtext.setContent("revision: "+o)})},1e3)}(this)}}); +enyo.kind({name:"About",kind:"Scroller",style:"background-color:#303030",components:[{tag:"center",components:[{tag:"h1",style:"color:#f0f0f0",content:"r2wui"},{kind:"Image",src:"icon.png"},{tag:"h3",style:"color:#707070;margin-bottom:50px",content:"the web frontend for rizin"},{tag:"h2",style:"color:#a0a0a0",content:"author: pancake 2013-2014"},{tag:"h2",style:"color:#a0a0a0",content:"version: ???",name:"vertext"},{tag:"h2",style:"color:#a0a0a0",content:"revision: ???",name:"revtext"}]}],create:function(){this.inherited(arguments),function(t){setTimeout(function(){r2.cmd("?V",function(e){var n=e.split(" ")[0],o=e.split(" ")[2];t.$.vertext.setContent("version: "+n),t.$.revtext.setContent("revision: "+o)})},1e3)}(this)}}); enyo.kind({name:"Assembler",kind:"Scroller",classes:"r2panel",style:"background-color:#c0c0c0;",components:[{tag:"form",style:"margin-top:8px;margin-left:8px",attributes:{action:"javascript:#"},components:[{kind:"FittableRows",fit:!0,components:[{kind:"onyx.InputDecorator",classes:"r2ui-input",components:[{tag:"font",content:"opcode",classes:"r2ui-input",style:"width:64px;font-weight:bold"},{kind:"Input",value:"",style:"width:60%",onkeydown:"assembleOpcode",attributes:{autocapitalize:"off"},name:"opcode"}]},{kind:"onyx.InputDecorator",classes:"r2ui-input",components:[{tag:"font",content:"bytes",classes:"r2ui-input",style:"width:64px;font-weight:bold"},{kind:"Input",value:"",style:"width:120px",onkeydown:"assembleOpcode",attributes:{autocapitalize:"off"},name:"bytes"}]},{kind:"onyx.InputDecorator",classes:"r2ui-input",components:[{tag:"font",content:"offset",classes:"r2ui-input",style:"width:64px;font-weight:bold"},{kind:"Input",value:"entry0",style:"width:120px",onkeydown:"assembleOpcode",attributes:{autocapitalize:"off"},name:"offset"}]}]}]},{tag:"form",style:"margin-top:8px;margin-left:8px",attributes:{action:"javascript:#"},components:[{tag:"h2",content:"Calculator"},{kind:"onyx.InputDecorator",classes:"r2ui-input",components:[{tag:"font",name:"value",content:"0",classes:"r2ui-input",style:"width:200px;font-weight:bold"},{kind:"Input",name:"ivalue",value:"0",style:"width:300",onkeydown:"calculateValue",attributes:{autocapitalize:"off"}}]}]}],calculateValue:function(t,e){if(13===e.keyCode){var n=this.$.value,o=t.getValue();n.setContent("..."),r2.cmd("?v "+o,function(t){n.setContent(t)})}},assembleOpcode:function(t,e){if(13===e.keyCode){var n=t.getValue(),o=this.$.offset.getValue();switch(t.name){case"opcode":var a=this.$.bytes;r2.assemble(o,n,function(t){a.setValue(t)});break;case"bytes":var s=this.$.opcode;r2.disassemble(o,n,function(t){s.setValue(t)});break;case"offset":}}}}); var Config={keys:{1:"this.setIndex(0)",2:"this.setIndex(1)",3:"this.setIndex(2)"}}; enyo.kind({name:"Console",kind:"Scroller",classes:"r2panel",style:"background-color:#c0c0c0;padding-left:7px",components:[{tag:"form",attributes:{action:"javascript:#"},components:[{kind:"FittableRows",fit:!0,classes:"fittable-sample-shadow",components:[{kind:"onyx.InputDecorator",style:"margin-top:8px;background-color:#404040;width: 90%;display:inline-block",components:[{kind:"Input",style:"width:100%;color:white",value:"",onkeydown:"runCommand",attributes:{autocapitalize:"off"},name:"input"}]},{tag:"pre",classes:"r2ui-terminal",style:"width:90%;",fit:!0,allowHtml:!0,name:"output"}]}]}],runCommand:function(t,n){if(13===n.keyCode){var o=this.$.input.getValue();this.$.input.setValue(""),function(t){r2.cmd(o,function(n){t.setContent(n)})}(this.$.output)}}}); diff --git a/shlr/www/enyo/r2core.css b/shlr/www/enyo/rzcore.css similarity index 100% rename from shlr/www/enyo/r2core.css rename to shlr/www/enyo/rzcore.css diff --git a/shlr/www/enyo/r2core.js b/shlr/www/enyo/rzcore.js similarity index 100% rename from shlr/www/enyo/r2core.js rename to shlr/www/enyo/rzcore.js diff --git a/shlr/www/f/r2.js b/shlr/www/f/rz.js similarity index 100% rename from shlr/www/f/r2.js rename to shlr/www/f/rz.js diff --git a/shlr/www/index.html b/shlr/www/index.html index 42d5dc53c4..53f5135d0f 100644 --- a/shlr/www/index.html +++ b/shlr/www/index.html @@ -5,7 +5,7 @@ - radare2 webui + rizin webui @@ -50,7 +50,7 @@
- +

diff --git a/shlr/www/m/app.js b/shlr/www/m/app.js index b3ecca1378..adb728d1a2 100644 --- a/shlr/www/m/app.js +++ b/shlr/www/m/app.js @@ -1,4 +1,4 @@ -!function e(t,n,i){function r(a,s){if(!n[a]){if(!t[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(o)return o(a,!0);var l=new Error("Cannot find module '"+a+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[a]={exports:{}};t[a][0].call(u.exports,function(e){var n=t[a][1][e];return r(n||e)},u,u.exports,e,t,n,i)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a=0&&n=t}}]),e}()},{"./ChunkStatus":3,"./NavigatorDirection":4}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});n.ChunkStatus={LAUNCHED:0,COMPLETED:1}},{}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});n.NavigatorDirection={BEFORE:-1,CURRENT:0,AFTER:1}},{}],5:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.r2Settings=n.r2Wrapper=n.R2Actions=void 0;var r=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:null,i=e;void 0===e?i=prompt("address"):"number"==typeof e&&(i="0x"+e.toString(16)),i&&""!==i.trim()&&r2.cmd("s "+i,function(){n&&a.uiContext.navigateTo(n),t.notifyAction(s.SEEK)})}},{key:"registerListener",value:function(e,t){this.listeners[e].push(t)}},{key:"notifyAction",value:function(e){this.listeners[e].forEach(function(e){return e()})}}]),e}(),l=(n.r2Wrapper=new c,{PLATFORM:"platform",BITS:"bits",UTF8:"utf8",UCASE:"ucase",DESCRIBE:"describe",BYTES:"bytes",OS:"os",SIZE:"size",DECODING:"decoding",MODE:"mode",ANAL_HAS_NEXT:"analHasNext",ANAL_SKIP_NOPS:"analSkipNops",ANAL_NON_CODE:"analNonCode",COLORS:"colors",USE_TTS:"useTTS",THEME:"theme",ASMEMU:"asmemu",ASMEMUSTR:"asmemustr"}),u={};u[l.PLATFORM]={name:"platform",defVal:"x86",apply:function(e){r2.cmd("e asm.arch="+e)}},u[l.BITS]={name:"bits",defVal:"32",apply:function(e){r2.cmd("e asm.bits="+e)}},u[l.UTF8]={name:"utf8",defVal:"true",apply:function(e){r2.cmd("e scr.utf8="+e)}},u[l.UCASE]={name:"ucase",defVal:"false",apply:function(e){r2.cmd("e asm.ucase="+e)}},u[l.DESCRIBE]={name:"describe",defVal:"false",apply:function(e){r2.cmd("e asm.describe="+e)}},u[l.BYTES]={name:"bytes",defVal:"false",apply:function(e){r2.cmd("e asm.bytes="+e)}},u[l.OS]={name:"os",defVal:"Linux",apply:function(e){console.log("OS is now: "+e)}},u[l.ASMEMU]={name:"asmemu",defVal:"false",apply:function(e){r2.cmd("e asm.emu="+e)}},u[l.ASMEMUSTR]={name:"asmemustr",defVal:"false",apply:function(e){r2.cmd("e emu.str="+e)}},u[l.SIZE]={name:"size",defVal:"S",apply:function(e){switch(e){case"S":r2.cmd("e asm.bytes=false"),r2.cmd("e asm.lines=false"),r2.cmd("e asm.cmt.right=false");break;case"M":r2.cmd("e asm.bytes=false"),r2.cmd("e asm.lines=true"),r2.cmd("e asm.lines.width=8"),r2.cmd("e asm.cmt.right=false");break;case"L":r2.cmd("e asm.bytes=true"),r2.cmd("e asm.lines=true"),r2.cmd("e asm.lines.width=12"),r2.cmd("e asm.cmt.right=true")}}},u[l.DECODING]={name:"decoding",defVal:"Pseudo",apply:function(e){switch(e){case"Pseudo":r2.cmd("e asm.pseudo=1"),r2.cmd("e asm.syntax=intel");break;case"Opcodes":r2.cmd("e asm.pseudo=0"),r2.cmd("e asm.syntax=intel");break;case"ATT":r2.cmd("e asm.pseudo=0"),r2.cmd("e asm.syntax=att")}}},u[l.MODE]={name:"mode",defVal:"PA",apply:function(e){switch(e){case"PA":r2.cmd("e io.va=false"),r2.cmd("e io.pava=false");break;case"VA":r2.cmd("e io.va=true"),r2.cmd("e io.pava=false");break;case"PAVA":r2.cmd("e io.pava=true");break;case"Debug":r2.cmd("e io.va=true"),r2.cmd("e io.debug=true"),r2.cmd("e io.pava=false")}}},u[l.ANAL_HAS_NEXT]={name:"analHasNext",defVal:!0,apply:function(e){console.log("analHasNext is "+e)}},u[l.ANAL_SKIP_NOPS]={name:"analSkipNops",defVal:!0,apply:function(e){console.log("analSkipNops is "+e)}},u[l.ANAL_NON_CODE]={name:"analNonCode",defVal:!1,apply:function(e){console.log("analNonCode is "+e)}},u[l.COLORS]={name:"colors",defVal:!0,apply:function(e){inColor=e,r2.cmd("e scr.color="+e)}},u[l.THEME]={name:"theme",defVal:"none",apply:function(e){r2.cmd("eco "+e)}},u[l.USE_TTS]={name:"tts",defVal:!0,apply:function(){}};n.r2Settings=new o.SettingsManager(l,u)},{"./SettingsManager":6,"./UIContext":7}],6:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]&&arguments[0];for(var t in this.conf){var n=this.getItem(t),i=this.getItemDefaultValue(t);(!e&&n!==i||e)&&this.conf[t].apply(n)}}},{key:"resetAll",value:function(){for(var e in this.conf)localStorage.removeItem(e);this.loadAll(!0)}},{key:"getItem",value:function(e){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");var t=localStorage.getItem(e);return null!==t?("false"===t?t=!1:"true"===t&&(t=!0),t):this.getItemDefaultValue(e)}},{key:"setItem",value:function(e,t){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");localStorage.setItem(e,t),this.conf[e].apply(t)}},{key:"getItemDefaultValue",value:function(e){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");return this.conf[e].defVal}},{key:"keyExists",value:function(e){return void 0!==this.conf[e]}}]),e}()},{}],7:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.uiContext=void 0;var r=function(){function e(e,t){for(var n=0;n1?i-1:0),o=1;o0&&void 0!==arguments[0]?arguments[0]:" & ";this.titleNode.innerHTML="";for(var n=0;n1,o=document.createElement(r?"strong":"span");o.textContent=e.widgetFactory.get(i).name,o.addEventListener("click",function(){return e.setFocusAt(n)}),0!==n&&e.titleNode.appendChild(document.createTextNode(t)),e.titleNode.appendChild(o)}(n)}},{key:"applyLayout",value:function(e){this.currentLayout===o.Layouts.VERTICAL&&e.classList.add("vertical")}},{key:"resizeTo",value:function(e){this.isSplitted&&(this.contentNode.children[0].style.width=100*(e-.001)+"%",this.contentNode.children[1].style.width=100*(1-e-.001)+"%")}},{key:"split",value:function(e){if(!this.isSplitted){e!==o.Layouts.VERTICAL&&console.error("Not supported layout."),this.currentLayout=e,this.ruler.show();var t=!0,n=!1,i=void 0;try{for(var r,a=this.contentNode.children[Symbol.iterator]();!(t=(r=a.next()).done);t=!0){var s=r.value;this.applyLayout(s)}}catch(e){n=!0,i=e}finally{try{!t&&a.return&&a.return()}finally{if(n)throw i}}}}},{key:"merge",value:function(){if(this.isSplitted){this.ruler.reset(),this.ruler.hide(),this.currentLayout=o.Layouts.FULL;var e=this.isFirstWidgetFocused?this.contentNode.children[0]:this.contentNode.children[1],t=this.isFirstWidgetFocused?this.contentNode.children[1]:this.contentNode.children[0];t.className="rwidget",e.classList.remove("vertical"),e.classList.remove("horizontal"),e.classList.add("full"),e!==this.contentNode.children[0]&&e.parentNode.insertBefore(t,e)}}}]),e}();n.uiContext=new s},{"../layout/Layouts":17,"../layout/Ruler":19}],8:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.Autocompletion=void 0;var r=function(){function e(e,t){for(var n=0;n=t.minChar_&&t.show()}),this.form_.addEventListener("blur",function(){t.hide()}),this.flags_,this.activeChoice_=0,this.prevLength_=0,this.list_,this.completions_,this.populate_()}},{key:"populate_",value:function(){var e=this;r2.cmdj(this.cmd_,function(t){e.flags_=t})}},{key:"process_",value:function(e){for(var t=[],n=0,i=0;i0&&(console.log("UP"),this.setActiveChoice(this.activeChoice_-1)),e===s.DOWN&&this.activeChoice_=2){if(this.show(),this.completions_=this.process_(t),this.prevLength_!==t.length&&(this.activeChoice_=0),0===this.completions_.length)this.addNode_(c.EMPTY,!1);else for(var n in this.completions_)this.addNode_(this.completions_[n],n===this.activeChoice_);this.prevLength_=t.length}else this.hide()}},{key:"setPrepareView",value:function(e){this.preparationCallback=e}},{key:"prepareView",value:function(){void 0!==this.preparationCallback&&this.preparationCallback()}}]),e}()},{"../core/R2Wrapper":5,"../widgets/Widgets":52}],9:[function(e,t,n){"use strict";function i(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=e.split(s),i=document.createElement("span"),o=!0,a=!1,c=void 0;try{for(var l,u=n[Symbol.iterator]();!(o=(l=u.next()).done);o=!0){var d=l.value;i.appendChild(r(d,t))}}catch(e){a=!0,c=e}finally{try{!o&&u.return&&u.return()}finally{if(a)throw c}}return i}function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=void 0;return s.test(e)?(n=document.createElement("a"),n.innerHTML=e,o(n,e,t)):(n=document.createElement("span"),n.innerHTML=e),n}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t=t||e.textContent,e.addEventListener("click",function(){return a.r2Wrapper.seek(t,n)}),e.title="Seek "+t,e.href="#"+t}Object.defineProperty(n,"__esModule",{value:!0}),n.formatOffsets=i,n.formatOffset=r,n.applySeek=o;var a=e("../core/R2Wrapper"),s=new RegExp(/(0x[a-zA-Z0-9]+|(?:sym|fcn|str)\.[\.a-zA-Z0-9_]+)/,"g")},{"../core/R2Wrapper":5}],10:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;ni){this.pauseScrollEvent=!0;var r=Math.floor((this.limit+(i-this.limit)+this.screenProportion)*n);this.ontop(r,function(e){t.pauseScrollEvent=!1})}if(i>1-this.limit&&this.prevScroll2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("a");i.className="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",i.style.margin=s;var r=document.createElement("i");return r.className="material-icons",r.innerHTML=e,i.appendChild(r),i.appendChild(document.createTextNode(t)),null!==n&&i.addEventListener("click",n),i}function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=document.createElement("a");return n.className="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",n.style.margin=s,n.textContent=e,null!==t&&n.addEventListener("click",t),n}function o(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("button");i.className="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect",i.style.margin=s,i.title=t;var r=document.createElement("i");return r.className="material-icons",r.textContent=e,i.appendChild(r),null!==n&&i.addEventListener("click",n),i}function a(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("button");i.className="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect",i.style.margin=s,i.title=t;var r=document.createElement("i");return r.className="material-icons md-dark",r.innerHTML=e,i.appendChild(r),null!==n&&i.addEventListener("click",n),i}Object.defineProperty(n,"__esModule",{value:!0});var s="3px";n.Inputs={button:r,imgButton:o,iconButton:a,pictogramInputButton:i}},{}],12:[function(e,t,n){"use strict";function i(e,t){if(r.r2Settings.getItem(r.r2Settings.keys.USE_TTS)&&"undefined"!=typeof SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance;n.text=e,n.lang="en-US",n.onend=function(){t&&t()},n.onerror=function(e){t&&t(e)},speechSynthesis.speak(n)}}Object.defineProperty(n,"__esModule",{value:!0}),n.speak=i;var r=e("../core/R2Wrapper")},{"../core/R2Wrapper":5}],13:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.Table=void 0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:null;i(this,e),this.cols=t,this.nonum=n,this.clickableOffset=new Array(t.length),this.clickableOffset.fill(!1),this.contentEditable=new Array(t.length),this.contentEditable.fill(!1),this.onChange=o,this.seekNavigation=a,this.id=r||!1,this.init()}return o(e,[{key:"init",value:function(){this.root=document.createElement("table"),this.root.className="mdl-data-table mdl-data-table--selectable mdl-shadow--2dp",!1!==this.root.id&&(this.root.id=this.id),this.thead=document.createElement("thead"),this.root.appendChild(this.thead),this.tbody=document.createElement("tbody"),this.root.appendChild(this.tbody);var e=document.createElement("tr");this.thead.appendChild(e);for(var t in this.cols){"+"==this.cols[t][0]?(this.clickableOffset[t]=!0,this.cols[t]=this.cols[t].substr(1)):"~"==this.cols[t][0]&&(this.contentEditable[t]=!0);var n=document.createElement("th");n.appendChild(document.createTextNode(this.cols[t])),this.nonum[t]&&(n.className="mdl-data-table__cell--non-numeric"),e.appendChild(n)}}},{key:"getRows",value:function(){return Array.prototype.slice.call(this.tbody.children)}},{key:"addRow",value:function(e){var t=document.createElement("tr");this.tbody.appendChild(t);for(var n=0;nReady !

'),s.add(e)},this.updateManagers={},this.updateManagers.updates=new o.UpdateManager,this.updateManagers.lastViews=new o.UpdateManager,this.addFocusListener(this.updateManagers.updates),this.addFocusListener(this.updateManagers.lastViews)}return r(e,[{key:"fallbackWidget",value:function(e){this.fallback=e}},{key:"initRuler",value:function(){var e={},t=this;this.rulerProp={gap:.005,pos:.5};var n=function(n){e={startX:n.clientX,startWidth:parseInt(document.defaultView.getComputedStyle(t.ruler).width,10),interval:n.clientX-t.ruler.offsetLeft},document.documentElement.addEventListener("mousemove",i,!1),document.documentElement.addEventListener("mouseup",r,!1),n.preventDefault()},i=function(n){var i=(n.clientX-e.interval)/t.container.offsetWidth;t.rulerProp.pos=i,t.container.children[0].style.width=100*(i-t.rulerProp.gap)+"%",t.container.children[1].style.width=100*(1-i-t.rulerProp.gap)+"%",t.ruler.style.marginLeft=100*i+"%"},r=function e(){document.documentElement.removeEventListener("mousemove",i,!1),document.documentElement.removeEventListener("mouseup",e,!1)};this.ruler.addEventListener("mousedown",n)}},{key:"setFocus",value:function(e){this.focus_=e;for(var t=0;t=0&&n=t}}]),e}()},{"./ChunkStatus":3,"./NavigatorDirection":4}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});n.ChunkStatus={LAUNCHED:0,COMPLETED:1}},{}],4:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});n.NavigatorDirection={BEFORE:-1,CURRENT:0,AFTER:1}},{}],5:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.r2Settings=n.r2Wrapper=n.R2Actions=void 0;var r=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:null,i=e;void 0===e?i=prompt("address"):"number"==typeof e&&(i="0x"+e.toString(16)),i&&""!==i.trim()&&r2.cmd("s "+i,function(){n&&a.uiContext.navigateTo(n),t.notifyAction(s.SEEK)})}},{key:"registerListener",value:function(e,t){this.listeners[e].push(t)}},{key:"notifyAction",value:function(e){this.listeners[e].forEach(function(e){return e()})}}]),e}(),l=(n.r2Wrapper=new c,{PLATFORM:"platform",BITS:"bits",UTF8:"utf8",UCASE:"ucase",DESCRIBE:"describe",BYTES:"bytes",OS:"os",SIZE:"size",DECODING:"decoding",MODE:"mode",ANAL_HAS_NEXT:"analHasNext",ANAL_SKIP_NOPS:"analSkipNops",ANAL_NON_CODE:"analNonCode",COLORS:"colors",USE_TTS:"useTTS",THEME:"theme",ASMEMU:"asmemu",ASMEMUSTR:"asmemustr"}),u={};u[l.PLATFORM]={name:"platform",defVal:"x86",apply:function(e){r2.cmd("e asm.arch="+e)}},u[l.BITS]={name:"bits",defVal:"32",apply:function(e){r2.cmd("e asm.bits="+e)}},u[l.UTF8]={name:"utf8",defVal:"true",apply:function(e){r2.cmd("e scr.utf8="+e)}},u[l.UCASE]={name:"ucase",defVal:"false",apply:function(e){r2.cmd("e asm.ucase="+e)}},u[l.DESCRIBE]={name:"describe",defVal:"false",apply:function(e){r2.cmd("e asm.describe="+e)}},u[l.BYTES]={name:"bytes",defVal:"false",apply:function(e){r2.cmd("e asm.bytes="+e)}},u[l.OS]={name:"os",defVal:"Linux",apply:function(e){console.log("OS is now: "+e)}},u[l.ASMEMU]={name:"asmemu",defVal:"false",apply:function(e){r2.cmd("e asm.emu="+e)}},u[l.ASMEMUSTR]={name:"asmemustr",defVal:"false",apply:function(e){r2.cmd("e emu.str="+e)}},u[l.SIZE]={name:"size",defVal:"S",apply:function(e){switch(e){case"S":r2.cmd("e asm.bytes=false"),r2.cmd("e asm.lines=false"),r2.cmd("e asm.cmt.right=false");break;case"M":r2.cmd("e asm.bytes=false"),r2.cmd("e asm.lines=true"),r2.cmd("e asm.lines.width=8"),r2.cmd("e asm.cmt.right=false");break;case"L":r2.cmd("e asm.bytes=true"),r2.cmd("e asm.lines=true"),r2.cmd("e asm.lines.width=12"),r2.cmd("e asm.cmt.right=true")}}},u[l.DECODING]={name:"decoding",defVal:"Pseudo",apply:function(e){switch(e){case"Pseudo":r2.cmd("e asm.pseudo=1"),r2.cmd("e asm.syntax=intel");break;case"Opcodes":r2.cmd("e asm.pseudo=0"),r2.cmd("e asm.syntax=intel");break;case"ATT":r2.cmd("e asm.pseudo=0"),r2.cmd("e asm.syntax=att")}}},u[l.MODE]={name:"mode",defVal:"PA",apply:function(e){switch(e){case"PA":r2.cmd("e io.va=false"),r2.cmd("e io.pava=false");break;case"VA":r2.cmd("e io.va=true"),r2.cmd("e io.pava=false");break;case"PAVA":r2.cmd("e io.pava=true");break;case"Debug":r2.cmd("e io.va=true"),r2.cmd("e io.debug=true"),r2.cmd("e io.pava=false")}}},u[l.ANAL_HAS_NEXT]={name:"analHasNext",defVal:!0,apply:function(e){console.log("analHasNext is "+e)}},u[l.ANAL_SKIP_NOPS]={name:"analSkipNops",defVal:!0,apply:function(e){console.log("analSkipNops is "+e)}},u[l.ANAL_NON_CODE]={name:"analNonCode",defVal:!1,apply:function(e){console.log("analNonCode is "+e)}},u[l.COLORS]={name:"colors",defVal:!0,apply:function(e){inColor=e,r2.cmd("e scr.color="+e)}},u[l.THEME]={name:"theme",defVal:"none",apply:function(e){r2.cmd("eco "+e)}},u[l.USE_TTS]={name:"tts",defVal:!0,apply:function(){}};n.r2Settings=new o.SettingsManager(l,u)},{"./SettingsManager":6,"./UIContext":7}],6:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]&&arguments[0];for(var t in this.conf){var n=this.getItem(t),i=this.getItemDefaultValue(t);(!e&&n!==i||e)&&this.conf[t].apply(n)}}},{key:"resetAll",value:function(){for(var e in this.conf)localStorage.removeItem(e);this.loadAll(!0)}},{key:"getItem",value:function(e){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");var t=localStorage.getItem(e);return null!==t?("false"===t?t=!1:"true"===t&&(t=!0),t):this.getItemDefaultValue(e)}},{key:"setItem",value:function(e,t){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");localStorage.setItem(e,t),this.conf[e].apply(t)}},{key:"getItemDefaultValue",value:function(e){if(!this.keyExists(e))throw new Error("ConfKey "+e+" doesn't exist!");return this.conf[e].defVal}},{key:"keyExists",value:function(e){return void 0!==this.conf[e]}}]),e}()},{}],7:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.uiContext=void 0;var r=function(){function e(e,t){for(var n=0;n1?i-1:0),o=1;o0&&void 0!==arguments[0]?arguments[0]:" & ";this.titleNode.innerHTML="";for(var n=0;n1,o=document.createElement(r?"strong":"span");o.textContent=e.widgetFactory.get(i).name,o.addEventListener("click",function(){return e.setFocusAt(n)}),0!==n&&e.titleNode.appendChild(document.createTextNode(t)),e.titleNode.appendChild(o)}(n)}},{key:"applyLayout",value:function(e){this.currentLayout===o.Layouts.VERTICAL&&e.classList.add("vertical")}},{key:"resizeTo",value:function(e){this.isSplitted&&(this.contentNode.children[0].style.width=100*(e-.001)+"%",this.contentNode.children[1].style.width=100*(1-e-.001)+"%")}},{key:"split",value:function(e){if(!this.isSplitted){e!==o.Layouts.VERTICAL&&console.error("Not supported layout."),this.currentLayout=e,this.ruler.show();var t=!0,n=!1,i=void 0;try{for(var r,a=this.contentNode.children[Symbol.iterator]();!(t=(r=a.next()).done);t=!0){var s=r.value;this.applyLayout(s)}}catch(e){n=!0,i=e}finally{try{!t&&a.return&&a.return()}finally{if(n)throw i}}}}},{key:"merge",value:function(){if(this.isSplitted){this.ruler.reset(),this.ruler.hide(),this.currentLayout=o.Layouts.FULL;var e=this.isFirstWidgetFocused?this.contentNode.children[0]:this.contentNode.children[1],t=this.isFirstWidgetFocused?this.contentNode.children[1]:this.contentNode.children[0];t.className="rwidget",e.classList.remove("vertical"),e.classList.remove("horizontal"),e.classList.add("full"),e!==this.contentNode.children[0]&&e.parentNode.insertBefore(t,e)}}}]),e}();n.uiContext=new s},{"../layout/Layouts":17,"../layout/Ruler":19}],8:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.Autocompletion=void 0;var r=function(){function e(e,t){for(var n=0;n=t.minChar_&&t.show()}),this.form_.addEventListener("blur",function(){t.hide()}),this.flags_,this.activeChoice_=0,this.prevLength_=0,this.list_,this.completions_,this.populate_()}},{key:"populate_",value:function(){var e=this;r2.cmdj(this.cmd_,function(t){e.flags_=t})}},{key:"process_",value:function(e){for(var t=[],n=0,i=0;i0&&(console.log("UP"),this.setActiveChoice(this.activeChoice_-1)),e===s.DOWN&&this.activeChoice_=2){if(this.show(),this.completions_=this.process_(t),this.prevLength_!==t.length&&(this.activeChoice_=0),0===this.completions_.length)this.addNode_(c.EMPTY,!1);else for(var n in this.completions_)this.addNode_(this.completions_[n],n===this.activeChoice_);this.prevLength_=t.length}else this.hide()}},{key:"setPrepareView",value:function(e){this.preparationCallback=e}},{key:"prepareView",value:function(){void 0!==this.preparationCallback&&this.preparationCallback()}}]),e}()},{"../core/R2Wrapper":5,"../widgets/Widgets":52}],9:[function(e,t,n){"use strict";function i(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=e.split(s),i=document.createElement("span"),o=!0,a=!1,c=void 0;try{for(var l,u=n[Symbol.iterator]();!(o=(l=u.next()).done);o=!0){var d=l.value;i.appendChild(r(d,t))}}catch(e){a=!0,c=e}finally{try{!o&&u.return&&u.return()}finally{if(a)throw c}}return i}function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=void 0;return s.test(e)?(n=document.createElement("a"),n.innerHTML=e,o(n,e,t)):(n=document.createElement("span"),n.innerHTML=e),n}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;t=t||e.textContent,e.addEventListener("click",function(){return a.r2Wrapper.seek(t,n)}),e.title="Seek "+t,e.href="#"+t}Object.defineProperty(n,"__esModule",{value:!0}),n.formatOffsets=i,n.formatOffset=r,n.applySeek=o;var a=e("../core/R2Wrapper"),s=new RegExp(/(0x[a-zA-Z0-9]+|(?:sym|fcn|str)\.[\.a-zA-Z0-9_]+)/,"g")},{"../core/R2Wrapper":5}],10:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;ni){this.pauseScrollEvent=!0;var r=Math.floor((this.limit+(i-this.limit)+this.screenProportion)*n);this.ontop(r,function(e){t.pauseScrollEvent=!1})}if(i>1-this.limit&&this.prevScroll2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("a");i.className="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",i.style.margin=s;var r=document.createElement("i");return r.className="material-icons",r.innerHTML=e,i.appendChild(r),i.appendChild(document.createTextNode(t)),null!==n&&i.addEventListener("click",n),i}function r(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=document.createElement("a");return n.className="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect",n.style.margin=s,n.textContent=e,null!==t&&n.addEventListener("click",t),n}function o(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("button");i.className="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect",i.style.margin=s,i.title=t;var r=document.createElement("i");return r.className="material-icons",r.textContent=e,i.appendChild(r),null!==n&&i.addEventListener("click",n),i}function a(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=document.createElement("button");i.className="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect",i.style.margin=s,i.title=t;var r=document.createElement("i");return r.className="material-icons md-dark",r.innerHTML=e,i.appendChild(r),null!==n&&i.addEventListener("click",n),i}Object.defineProperty(n,"__esModule",{value:!0});var s="3px";n.Inputs={button:r,imgButton:o,iconButton:a,pictogramInputButton:i}},{}],12:[function(e,t,n){"use strict";function i(e,t){if(r.r2Settings.getItem(r.r2Settings.keys.USE_TTS)&&"undefined"!=typeof SpeechSynthesisUtterance){var n=new SpeechSynthesisUtterance;n.text=e,n.lang="en-US",n.onend=function(){t&&t()},n.onerror=function(e){t&&t(e)},speechSynthesis.speak(n)}}Object.defineProperty(n,"__esModule",{value:!0}),n.speak=i;var r=e("../core/R2Wrapper")},{"../core/R2Wrapper":5}],13:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.Table=void 0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o=function(){function e(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:null;i(this,e),this.cols=t,this.nonum=n,this.clickableOffset=new Array(t.length),this.clickableOffset.fill(!1),this.contentEditable=new Array(t.length),this.contentEditable.fill(!1),this.onChange=o,this.seekNavigation=a,this.id=r||!1,this.init()}return o(e,[{key:"init",value:function(){this.root=document.createElement("table"),this.root.className="mdl-data-table mdl-data-table--selectable mdl-shadow--2dp",!1!==this.root.id&&(this.root.id=this.id),this.thead=document.createElement("thead"),this.root.appendChild(this.thead),this.tbody=document.createElement("tbody"),this.root.appendChild(this.tbody);var e=document.createElement("tr");this.thead.appendChild(e);for(var t in this.cols){"+"==this.cols[t][0]?(this.clickableOffset[t]=!0,this.cols[t]=this.cols[t].substr(1)):"~"==this.cols[t][0]&&(this.contentEditable[t]=!0);var n=document.createElement("th");n.appendChild(document.createTextNode(this.cols[t])),this.nonum[t]&&(n.className="mdl-data-table__cell--non-numeric"),e.appendChild(n)}}},{key:"getRows",value:function(){return Array.prototype.slice.call(this.tbody.children)}},{key:"addRow",value:function(e){var t=document.createElement("tr");this.tbody.appendChild(t);for(var n=0;nReady !

'),s.add(e)},this.updateManagers={},this.updateManagers.updates=new o.UpdateManager,this.updateManagers.lastViews=new o.UpdateManager,this.addFocusListener(this.updateManagers.updates),this.addFocusListener(this.updateManagers.lastViews)}return r(e,[{key:"fallbackWidget",value:function(e){this.fallback=e}},{key:"initRuler",value:function(){var e={},t=this;this.rulerProp={gap:.005,pos:.5};var n=function(n){e={startX:n.clientX,startWidth:parseInt(document.defaultView.getComputedStyle(t.ruler).width,10),interval:n.clientX-t.ruler.offsetLeft},document.documentElement.addEventListener("mousemove",i,!1),document.documentElement.addEventListener("mouseup",r,!1),n.preventDefault()},i=function(n){var i=(n.clientX-e.interval)/t.container.offsetWidth;t.rulerProp.pos=i,t.container.children[0].style.width=100*(i-t.rulerProp.gap)+"%",t.container.children[1].style.width=100*(1-i-t.rulerProp.gap)+"%",t.ruler.style.marginLeft=100*i+"%"},r=function e(){document.documentElement.removeEventListener("mousemove",i,!1),document.documentElement.removeEventListener("mouseup",e,!1)};this.ruler.addEventListener("mousedown",n)}},{key:"setFocus",value:function(e){this.focus_=e;for(var t=0;t=2;n&&(this.container.removeChild(this.container.children[this.getFocus()]),this.populatedWidgets.splice(this.getFocus(),1)),0===this.getFocus()&&n?(this.populatedWidgets.unshift(e),e.isAlreadyThere()||(this.container.insertBefore(t,this.container.children[0]),this.container.children[0].style.width=100*(this.rulerProp.pos-this.rulerProp.gap)+"%")):(this.populatedWidgets.push(e),e.isAlreadyThere()||(this.container.appendChild(t),this.container.children[1].style.width=100*(1-this.rulerProp.pos-this.rulerProp.gap)+"%"))}else this.populatedWidgets.length>=1&&this.container.removeChild(this.container.children[this.getFocus()]),this.populatedWidgets=[e],e.isAlreadyThere()||(this.container.appendChild(t),this.container.children[0].style.width="auto");this.moveFocusOnWidget(e),this.applyFocusEvent_(e),e.setOffset(this.getFocus()),this.drawTitle()}}},{key:"moveFocusOnWidget",value:function(e){this.setFocus(this.populatedWidgets.indexOf(e)),this.container.children[this.getFocus()].classList.add("focus"),this.isSplitted()&&this.container.children[(this.getFocus()+1)%2].classList.remove("focus"),this.drawTitle()}},{key:"drawTitle",value:function(){if(this.currentLayout===a.Layouts.FULL||1===this.populatedWidgets.length)this.title.innerHTML=this.populatedWidgets[0].getName();else{for(var e=[],t=0;t"+this.populatedWidgets[t].getName()+""):e.push(this.populatedWidgets[t].getName());this.title.innerHTML=e.join(" & ")}}},{key:"applyFocusEvent_",value:function(e){var t=this;this.getWidgetDOMWrapper(e).addEventListener("mousedown",function(){t.moveFocusOnWidget(e)})}},{key:"addFocusListener",value:function(e){this.focusListeners.push(e)}}]),e}()},{"../helpers/UpdateManager":14,"./Layouts":17}],16:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:s;i(this,e),this.heightProvisioning=t}return r(e,[{key:"getCurChunk",value:function(){return this.curChunk}},{key:"getFirstElement",value:function(){return this.firstElement}},{key:"refreshInitialOffset",value:function(){var e=this;r2.cmd("s",function(t){e.initialOffset=parseInt(t,16)})}},{key:"defineInfiniteParams",value:function(e){var t=this,n=0===this.container.getBody().offsetHeight?800:this.container.getBody().offsetHeight;this.howManyLines=Math.floor(n/this.lineHeight*this.heightProvisioning);var i=new a.InfiniteScrolling(this.container.getBody(),3,void 0!==e?e:.2);i.setTopEvent(function(e,n){t.nav.go(o.NavigatorDirection.BEFORE),t.infiniteDrawingContent(o.NavigatorDirection.BEFORE,e,n)}),i.setBottomEvent(function(e,n){t.nav.go(o.NavigatorDirection.AFTER),t.infiniteDrawingContent(o.NavigatorDirection.AFTER,e,n)})}}]),e}()},{"../core/NavigatorDirection":4,"../helpers/InfiniteScrolling":10}],19:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;ne){t-=o;break}i=n[r]}var a=t-e,s=i.getBoundingClientRect().height-a;return this.extractOffset_(i.children[0].id)+Math.ceil(s/this.lineHeight)}}},{key:"replaceScrollPosition",value:function(e){if(void 0!==e){var t=this.nav.getChunkPositionFor(e);if(-1===t)return void console.log("Chunk position from offset not found");for(var n=this.container.getBody().children[t],i=0;void 0===n.children[i].id;)i++;var r=this.extractOffset_(n.children[i].id),o=n.offsetTop,a=n.getBoundingClientRect().height,s=(e-r)/this.nav.getSize(r),c=Math.floor(s*a),l=o+c;this.container.getBody().scrollTop=l}}},{key:"drawContextualMenu",value:function(e){var t=this,n=function(e,n){var i,r=n+" @"+e;if(r2.cmdj(r,function(e){i=e}),null===i||i.constructor!==Array)return void alert("No available ouput!");t.addLongListDialog(i)},i=function(e,n,i){var r="";void 0!==i&&""===(r=prompt(i+"?"))||(""!==r&&(n+=" "+r),r2.cmd(n+" @"+e),t.nav.cleanOldData(),t.draw())},r=[{aoj:!1,name:"view graph",shortcut:"G",fct:function(){return d.uiContext.navigateTo(f.Widgets.DISASSEMBLY_GRAPH)}},{aoj:!1,name:"analyze function",shortcut:"F",fct:function(e,t){return i(t,"af")}},{aoj:!0,name:"immediate base...",shortcut:"i",expand:[{name:"binary",fct:function(e,t){return i(t,"ahi b")}},{name:"octal",fct:function(e,t){return i(t,"ahi o")}},{name:"decimal",fct:function(e,t){return i(t,"ahi d")}},{name:"hexadecimal",fct:function(e,t){return i(t,"ahi h")}},{name:"string",fct:function(e,t){return i(t,"ahi s")}}]},{aoj:!1,name:"add comment",shortcut:";",fct:function(e,t){return i(t,"CC","Name")}},{aoj:!1,name:"set flag",shortcut:"f",fct:function(e,t){return i(t,"f","Name")}},{aoj:!0,name:"rename flag",shortcut:"n",fct:function(e,t){return i(t,"fr","Name")}},{aoj:!0,name:"set string",shortcut:"s",fct:function(e,t){return i(t,"Cs")}},{aoj:!1,name:"find xrefs",shortcut:"x",fct:function(e,t){return n(t,"axtj")}},{aoj:!1,name:"as data",shortcut:"D",fct:function(e,t){return i(t,"Cd ","Size")}},{aoj:!1,name:"as code",shortcut:"F",fct:function(e,t){return i(t,"C-")}},{aoj:!1,name:"as string",shortcut:"S",fct:function(e,t){return i(t,"Cs")}}],o=document.getElementById("contextmenuDisasm");if(null===o){var o=document.createElement("nav");o.id="contextmenuDisasm",o.classList.add("context-menu")}else o.innerHTML="";var a=document.createElement("ul");o.appendChild(a);for(var t=this,s=function(e,n){e.addEventListener("mousedown",function(e){return function(n){e(n,t.getCurrentOffset())}}(n))},c=0;c=t||r<=e&&o>=e||r<=t&&o>=t||r>=e&&o<=t)&&n.push(i)}return n}},{key:"populateFirst",value:function(){return this.populateFrom(this.currentOffset)}},{key:"fillGap",value:function(e,t,n){var i=t-e;return[{offset:e,size:i,artifical:n}]}},{key:"populateFrom",value:function(e){for(var t=e-a(this.howManyLines),n=t+3*a(this.howManyLines),i=this.getOverlappingIntervals(t,n),r=[],o=0;o0){r[0].offset!==t&&(r=r.concat(this.fillGap(t,r[0].offset)));var u=r[r.length-1],d=u.offset+u.size;d!==n&&(r=r.concat(this.fillGap(d+1,n)));for(var o=0;o1&&(r=r.concat(this.fillGap(s+1,c)))}}else r=this.fillGap(t,n,!0);this.currentlyShown=r}},{key:"getShownOffset",value:function(){return this.currentlyShown}},{key:"getSize",value:function(e){for(var t=0;t=this.currentlyShown[t].offset&&e-1}},{key:"getFlags",value:function(e,t){var n=function(t){for(var n=[],i=0;i=e&&n.push({name:t[i].name,start:t[i].offset,end:t[i].offset+t[i].size});return n.sort(function(e,t){return e.size>t.size?-1:1}),n},i=[],r=0,o=function(){ ++r<3||t(n(i))};this.get(c.NavigatorDirection.CURRENT,function(e){i=i.concat(e.flags),o()}),this.get(c.NavigatorDirection.BEFORE,function(e){i=i.concat(e.flags),o()}),this.get(c.NavigatorDirection.AFTER,function(e){i=i.concat(e.flags),o()})}},{key:"getBytes",value:function(e){var t;return r2.cmdj("p8j "+(e.to-e.from+1)+" @"+e.from,function(e){t=e}),t}},{key:"refreshChunk",value:function(e,t){var n=[],i=this;this.get(e,function(r){r.callback=[],n=r.modified,i.get(e,function(e){e.modified.concat(n),t(e)},!0)})}},{key:"refreshCurrent",value:function(e){var t=0,n=function(){++t<3||e()};this.refreshChunk(c.NavigatorDirection.CURRENT,function(){n()}),this.refreshChunk(c.NavigatorDirection.BEFORE,function(){n()}),this.refreshChunk(c.NavigatorDirection.AFTER,function(){n()})}}]),t}(s.BlockNavigator)},{"../../core/BlockNavigator":2,"../../core/NavigatorDirection":4}],23:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0}),n.Hexdump=void 0;var a=function(){function e(e,t){for(var n=0;n0)}},{key:"processSelection",value:function(e){e&&this.cleanSelection(!0),this.selectionFirst===this.selectionEnd&&(this.selectionFirst.classList.add("selected"),this.currentSelection={from:this.selectionFirst.offset,to:this.selectionFirst.offset});var t=this.selectionFirst.offset0&&(i.isTopMax=!1)}),0!==r.offset||0!==r.hex.length){var o;o=e===c.NavigatorDirection.BEFORE?i.listContent.lastChild.className:i.listContent.firstChild.className;for(var a=Array.prototype.slice.call(document.getElementsByClassName(o)),s=0;s0?8*d.WordSizes[u]+" bits":"pairs",d.WordSizes[u]===this.hexLength&&(f.selected=!0),l.appendChild(f)}l.addEventListener("change",function(e){t.hexLength=parseInt(e.target.value),t.draw()},!1);var h=document.createElement("input");h.className="mdl-textfield__input",h.style.width="26px",h.style.display="inline",h.pattern="[0-9]+",h.value=this.nbColumns;var p=function(e){t.nbColumns=h,t.nav.changeNbCols(h),t.draw(),e.value=h},m=document.createElement("span");m.title="Number of columns per line";var g=document.createElement("button");g.className="mdl-button mdl-js-button mdl-button--icon",g.appendChild(document.createTextNode("-")),g.addEventListener("click",function(){return p(t.nbColumns-1)});var v=document.createElement("button");v.className="mdl-button mdl-js-button mdl-button--icon",v.appendChild(document.createTextNode("+")),v.addEventListener("click",function(){return p(t.nbColumns+1)}),h.addEventListener("change",function(e){var t=parseInt(e.target.value);p(t)}),m.appendChild(g),m.appendChild(document.createTextNode(" ")),m.appendChild(h),m.appendChild(document.createTextNode(" ")),m.appendChild(v);var y=document.createElement("input");y.classList.add("mdl-checkbox__input"),y.type="checkbox",y.checked=this.bigEndian;var b=document.createElement("span");b.classList.add("mdl-checkbox__label"),b.appendChild(document.createTextNode("bigEndian"));var C=document.createElement("label");C.classList.add("mdl-checkbox"),C.classList.add("mdl-js-checkbox"),C.classList.add("mdl-js-ripple-effect"),C.appendChild(y),C.appendChild(b),y.addEventListener("change",function(){t.bigEndian=!t.bigEndian,t.draw()});var w=document.createElement("input");w.classList.add("mdl-checkbox__input"),w.type="checkbox",w.checked=this.isWritable();var E=document.createElement("span");E.classList.add("mdl-checkbox__label"),E.appendChild(document.createTextNode("isEditable"));var k=document.createElement("label");k.classList.add("mdl-checkbox"),k.classList.add("mdl-js-checkbox"),k.classList.add("mdl-js-ripple-effect"),k.appendChild(w),k.appendChild(E),this.writable||(w.disabled=!0),w.addEventListener("change",function(){t.selectionMode=!t.selectionMode,t.draw()});var S=document.createElement("input");S.classList.add("mdl-checkbox__input"),S.type="checkbox",S.checked=this.showFlags;var _=document.createElement("span");_.classList.add("mdl-checkbox__label"),_.appendChild(document.createTextNode("showFlags"));var O=document.createElement("label");O.classList.add("mdl-checkbox"),O.classList.add("mdl-js-checkbox"),O.classList.add("mdl-js-ripple-effect"),O.appendChild(S),O.appendChild(_),S.addEventListener("change",function(){t.showFlags=!t.showFlags,t.draw()}),i.appendChild(c),r.appendChild(m),o.appendChild(C),a.appendChild(k),s.appendChild(O),componentHandler.upgradeDom()}},{key:"getFlagColor",value:function(e){for(var t=0;t=a.offset){o=e[s];break}if(void 0===o)return"continue";var c=document.createElement("li"),l=int2fixedHex(a.offset,8);c.classList.add("block"+t),c.classList.add("flag"),c.offset=l,c.appendChild(document.createTextNode("["+l+"] "+a.name)),c.title="Go to Disassembly",c.style.cursor="pointer",c.addEventListener("click",function(){return p.r2Wrapper.seek(l,f.Widgets.DISASSEMBLY)}),c.title="("+a.size+" bytes) Seek "+l+" on disassembly widget",c.style.color=i.getFlagColor(a.name),i.listContent.insertBefore(c,o)})()}}}},{key:"indexOfLine_",value:function(e){for(var t=[].slice.call(this.listContent.children),n=0;n=e)return n;return-1}},{key:"colorizeFlag",value:function(e){var t=this;if(this.showFlags){void 0===e&&(e=!1);var n=[].slice.call(this.listContent.children);if(e)for(var i=0;it.value?e:t}).value,r=this.width/t,c=this.height;this.svg.innerHTML="";for(var l in this.entropy)!function(t){var l=e.entropy[t],u=.1+(l.value-n)/(i-n)*.9,d=document.createElementNS(s,"g");d.addEventListener("click",function(){o.r2Wrapper.seek(l.addr,a.Widgets.DISASSEMBLY)}),e.svg.appendChild(d);var f=document.createElementNS(s,"title");f.textContent="0x"+l.addr.toString(16),d.appendChild(f);var h=document.createElementNS(s,"rect");h.setAttribute("x",r*t),h.setAttribute("y",0),h.setAttribute("width",r),h.setAttribute("height",c),h.setAttribute("fill","#000"),h.setAttribute("fill-opacity",u);var p=document.createElementNS(s,"text"),m=u>.4?"#EEEEEE":"black";p.setAttribute("x",r*t+2),p.setAttribute("y",c+10),p.setAttribute("fill",m),p.setAttribute("font-family","Roboto"),p.setAttribute("font-size",12),p.setAttribute("transform","rotate(-90, "+r*t+", "+c+")"),p.textContent="0x"+l.addr.toString(16),d.appendChild(h),d.appendChild(p)}(l)}}},{key:"refresh",value:function(){this.refreshEntropy(),this.draw()}}]),e}()},{"../../core/R2Wrapper":5,"../../widgets/Widgets":52}],27:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.FortunesCard=void 0;var r=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:1;i(this,e),this.headersCmd=[{name:"HDR",title:"Headers",format:this.formatAsKeyValue,cmd:"i|",grep:null,ready:!1},{name:"SYM",title:"Symbols",format:this.fromatAsCode,cmd:"isq",grep:"!imp",ready:!1},{name:"IMP",title:"Imports",format:this.fromatAsCode,cmd:"isq",grep:"imp.",ready:!1},{name:"REL",title:"Relocations",format:this.fromatAsCode,cmd:"ir",grep:null,ready:!1},{name:"SEC",title:"Sections",format:this.fromatAsCode,cmd:"iSq",grep:null,ready:!1},{name:"STR",title:"Strings",format:this.fromatAsCode,cmd:"izq",grep:null,ready:!1},{name:"SDB",title:"Sdb",format:this.fromatAsCode,cmd:"k bin/cur/***",grep:null,ready:!1}],this.build(),this.preloadTabs(t)}return r(e,[{key:"DOM",get:function(){return this.card}},{key:"nbTabs",get:function(){return this.headersCmd.length}}]),r(e,[{key:"build",value:function(){this.card=document.createElement("div"),this.card.className="demo-graphs mdl-shadow--2dp mdl-color--white mdl-cell mdl-cell--8-col";var e=document.createElement("div");e.className="mdl-tabs mdl-js-tabs",this.card.appendChild(e),this.tabs=document.createElement("div"),this.tabs.className="mdl-tabs__tab-bar overview-tabs",this.content=document.createElement("div"),e.appendChild(this.tabs),e.appendChild(this.content),this.createTabs(this.headersCmd,this.tabs,this.content)}},{key:"createTabs",value:function(e,t,n){var i=this,r=!0;for(var o in e)!function(o){var a=e[o],s="tab-"+a.name,c=document.createElement("a");c.classList.add("mdl-tabs__tab"),c.href="#"+s,c.title=a.title,c.innerHTML=a.name;var l=document.createElement("div");l.classList.add("mdl-tabs__panel"),l.id=s,r&&(l.classList.add("is-active"),c.classList.add("is-active"),r=!1),c.addEventListener("click",function(){return i.loadTab(l,a)}),t.appendChild(c),n.appendChild(l)}(o)}},{key:"fixHeight",value:function(e){this.content.style.height="0px";var t=this.card.getBoundingClientRect().height,n=this.tabs.getBoundingClientRect().height,i=t-n-32;this.content.style.height=(ithis.nbTabs?this.nbTabs:e;for(var t=0;t1&&(e.style["-webkit-column-count"]=t.cols,e.style["-moz-column-count"]=t.cols,e.style["column-count"]=t.cols),t.ready=!0}}},{key:"refresh",value:function(){for(var e in this.headersCmd)this.headersCmd[e].ready=!1;var t=[].slice.call(this.content.children);for(var n in t)if(t[n].className.indexOf("is-active")>-1){this.loadTab(t[n],this.headersCmd[n]);break}}},{key:"fromatAsCode",value:function(e){var t=document.createElement("pre");return t.style.marge="1.2em",t.appendChild((0,o.formatOffsets)(e,a.Widgets.DISASSEMBLY)),t}},{key:"formatAsKeyValue",value:function(e){var t=document.createElement("dl");t.classList.add("infocard");var n=e.split(/\n/g);for(var i in n){var r=n[i].split(/ (.+)?/);if(r.length>=2){var o=document.createElement("dt");o.textContent=r[0],t.appendChild(o);var a=document.createElement("dd");a.textContent=r[1],t.appendChild(a)}}return t}}]),e}()},{"../../helpers/Format":9,"../../widgets/Widgets":52}],30:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0}),n.Overview=void 0;var r=function(){function e(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:null;i(this,t);var s=r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,"dark"));return s.formatFunc=n,s.r2cmd=o,null!==a&&(s.backButton=a),s}return o(t,e),a(t,[{key:"init",value:function(){var e=this;void 0!==this.backButton&&(this.backButton.style.position="absolute",this.backButton.style.top="1em",this.backButton.style.left="1em",c.r2Wrapper.registerListener(c.R2Actions.SEEK,function(){e.displayed&&e.draw()}))}},{key:"draw",value:function(){void 0!==this.backButton&&this.node.appendChild(this.backButton),this.node.appendChild(this.getPre())}},{key:"getPre",value:function(){var e=this,t=document.createElement("pre");return r2.cmd(this.r2cmd,function(n){t.appendChild(e.formatFunc(n))}),t}}]),t}(s.BaseWidget)},{"../core/R2Wrapper":5,"../helpers/Inputs":11,"./BaseWidget":32}],32:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n1?n-1:0),o=1;o1?n-1:0),r=1;r=2&&n.addRow([a[0],a[1]])}n.insertInto(i)}),t}}]),t}(s.BaseWidget)},{"../core/R2Wrapper":5,"../core/UIContext":7,"../helpers/Inputs":11,"../helpers/Table":13,"./BaseWidget":32,"./Widgets":52}],34:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0}),n.DebuggerWidget=void 0;var a=function(){function e(e,t){for(var n=0;n=4&&function(){var t=a[3],i=-1===a[2].indexOf("."),r=document.createElement("a");r.innerHTML=t,i&&(r.style.color="red"),r.addEventListener("click",function(){r2.cmd("fs "+t),e.draw()});var o=n.addRow([a[1],r]);o.addEventListener("click",function(){n.getRows().forEach(function(e){e.classList.remove("active")}),o.classList.add("active"),e.current=t})}()}n.insertInto(i)}),t}},{key:"setFlagspace",value:function(){var e=this,t=this.current;t||(t=prompt("name")),t&&r2.cmd("fs "+t,function(){e.draw()})}},{key:"renameFlagspace",value:function(){var e=this,t=this.current;t||(t=prompt("name")),t&&r2.cmd("fsr "+t,function(){e.draw()})}},{key:"delFlagspace",value:function(){var e=this,t=this.current;t||(t="."),t&&r2.cmd("fs-"+t,function(){e.draw()})}}]),t}(s.BaseWidget)},{"../core/R2Wrapper":5,"../core/UIContext":7,"../helpers/Inputs":11,"../helpers/Table":13,"./BaseWidget":32,"./Widgets":52}],43:[function(e,t,n){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0}),n.FlagsWidget=void 0;var a=function(){function e(e,t){for(var n=0;nRadare2 Material Design